1.0.5 • Published 2 years ago

dha-cms-client v1.0.5

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

DHA CMS

Table of Contents

Introduction

Welcome to the DHA CMS API module. This module is used to reach out and grab content from the DHA CMS system in order to use it within an application. This API contains several ways to accomplish this. See below for more details.

Quick Start

const client = CMSClient.getCMSClient('CMS endpoint', 'CMS key');

These values obtained by DHA WMT leadership/senior development staff or your own Azure Cosmos DB endpoint and key can go there. If the ladder then the database and container structure must match the data dictionary or else the API won't work.

Data Dictionary

The Data Dictionary is maintained in the DHA CMS System Design Document Check the GitHub Wiki.

API Definitions

  • getFullProjectData (async)

    • Retrieves full project data for the given project
    • @param projectId (string) Identifier for the CMS project
    • @returns the complete project data if found
    • @example usage
    const results = await client.getFullProjectData('testApp');
    for (const contentItem of results) {
      if (contentItem.id === 'homePageTitle') {
        setTitle(contentItem.contentValue);
      } else if (contentItem.id === 'homePageContent') {
        setContent(contentItem.contentValue);
      } else {
        console.error('Unknown content id:' + contentItem.id, contentItem);
      }
    }
  • getContentForProjectByContentId (async)

    • Retrieves the specified content for the given project
    • @param projectId (string) Identifier for the CMS project
    • @param contentId (string) Identifier for the project's content
    • @returns the content if found
    • @example usage
    const result = await client.getContentForProjectByContentId('testApp', 'homePageImageTester');
    setContent(result[0].contentValue);
  • getContentForProjectByContentGroupId (async)

    • Retrieves the specified content for the given project and content group
    • @param projectId (string) Identifier for the CMS project
    • @param contentGroupId (string) Identifier for the content's contentGroup
    • @returns the content if found
    • @example usage
    const results = await client.getContentForProjectByContentGroupId('testApp', 'homePage');
    for (const contentItem of results) {
      if (contentItem.id === 'homePageTitle') {
        setTitle(contentItem.contentValue);
      } else if (contentItem.id === 'homePageContent') {
        setContent(contentItem.contentValue);
      } else {
        console.error('Unknown content id:' + contentItem.id, contentItem);
      }
    }
  • getRequestForProject

    • Generates the needed information for sending off a REST API request to the CMS
    • @param databaseId The identifier for the database
    • @param containerId The identifier for the container
    • @param projectId The identifier for the project
    • @returns The CMSRestRequest object containing the url and options needed for firing off the request
    • @example usage

      const request = client.getRequestForProject('DHA_CMS', 'Projects', 'testApp');
      https
        .get(request.options, (res) => {
          res.on('data', (d: string | Uint8Array) => {
            const t = new String(d);
            const results = JSON.parse(t.toString()) as ProjectItem;
      
            for (const contentItem of results.content) {
              if (contentItem.id === 'homePageTitle') {
                setTitle(contentItem.contentValue);
              } else if (contentItem.id === 'homePageContent') {
                setContent(contentItem.contentValue);
              } else {
                console.error('Unknown content id:' + contentItem.id, contentItem);
              }
            }
          });
        })
        .on('error', (e: any) => {
          console.error(e);
        });
1.0.2

2 years ago

1.0.1

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.0

2 years ago