1.0.1 • Published 3 years ago

@adobe/aem-headless-client v1.0.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
3 years ago

Version Downloads/week Build Status License

AEM Headless SDK Client

Installation

$ npm install @adobe/aem-headless-client

Usage

Create AEMHeadless client

const AEMHeadless = require('@adobe/aem-headless-client');

Configure SDK with Host and Auth data (if needed)

const aemHeadlessClient = new AEMHeadless('<graphql_endpoint>', '<aem_host>', '<aem_token>' || ['<aem_user>', '<aem_pass>'])
// Eg:
const aemHeadlessClient = new AEMHeadless('content/graphql/endpoint.gql', AEM_HOST_URI, AEM_TOKEN || [AEM_USER, AEM_PASS])

Use AEMHeadless client

Promise syntax:

aemHeadlessClient.postQuery(queryString)
  .then(data => console.log(data))
  .catch(e => console.error(e.toJSON()))

aemHeadlessClient.listQueries()
   .then(data => console.log(data))
   .catch(e => console.error(e.toJSON()))

aemHeadlessClient.saveQuery(queryString, 'wknd/persist-query-name')
   .then(data => console.log(data))
   .catch(e => console.error(e.toJSON()))

aemHeadlessClient.getQuery('wknd/persist-query-name')
   .then(data => console.log(data))
   .catch(e => console.error(e.toJSON()))

Within async/await:

(async () => {
    let postData
    try {
        postData = aemHeadlessClient.postQuery(queryString)
    } catch (e) {
        console.error(e.toJSON())
    }
    
    let list
    try {
        list = aemHeadlessClient.listQueries()
    } catch (e) {
        console.error(e.toJSON())
    }

    try {
        aemHeadlessClient.saveQuery(queryString, 'wknd/persist-query-name')
    } catch (e) {
        console.error(e.toJSON())
    }
    
    let getData
    try {
        getData = aemHeadlessClient.getQuery('wknd/persist-query-name')
    } catch (e) {
        console.error(e.toJSON())
    }
})()    

Authorization

If auth param is a string, it's treated as a Bearer token

If auth param is an array, expected data is 'user', 'pass' pair, and Basic Authorization will be ued

If auth is not defined, Authorization header will not be set

DEV token and service credentials

SDK contains helper function to get Auth token from credentials config file

const { getToken } = require('@adobe/aem-headless-sdk')
(async () => {
    const { accessToken, type, expires } = await getToken('path/to/service-config.json')
    const sdkNode = new AEMHeadless('content/graphql/endpoint.gql', AEM_HOST_URI, accessToken)
    const data = sdkNode.postQuery(queryString)
})()

API Reference

See generated API Reference

Contributing

Contributions are welcome! Read the Contributing Guide for more information.

Licensing

This project is licensed under the Apache V2 License. See LICENSE for more information.

1.0.1

3 years ago

0.0.2

3 years ago