3.0.2 • Published 3 months ago

@adobe/aio-lib-templates v3.0.2

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

Adobe App Builder Templates Library

This is a helper library that is to be used in the Adobe I/O CLI and SDKs to communicate with Adobe App Builder Template Registry through its REST APIs.

Installing

$ npm install @adobe/aio-lib-templates

Usage

Search Adobe App Builder templates

Search Adobe App Builder templates in Adobe App Builder Template Registry and paginate through results.

const sdk = require('@adobe/aio-lib-templates');

async function sdkTest() {
    const templateRegistryClient = sdk.init();
    // an optional Search Criteria object
    // without Search Criteria the following code will paginate through all Adobe App Builder templates
    const searchCriteria = {
        [sdk.SEARCH_CRITERIA_CATEGORIES]: ['action', sdk.SEARCH_CRITERIA_FILTER_NOT + 'ui', sdk.SEARCH_CRITERIA_FILTER_OR + 'runtime'],
        [sdk.SEARCH_CRITERIA_STATUSES]: [sdk.TEMPLATE_STATUS_APPROVED],
        [sdk.SEARCH_CRITERIA_ADOBE_RECOMMENDED]: true
    };
    // an optional OrderBy Criteria object
    const orderByCriteria = {
        [sdk.ORDER_BY_CRITERIA_NAMES]: sdk.ORDER_BY_CRITERIA_SORT_DESC
    };
    for await (const templates of templateRegistryClient.getTemplates(searchCriteria, orderByCriteria)) {
        for (const template of templates) {
            console.log(template);
        }
    }
}
Supported Search Criteria properties
KeyValueSDK ConstantDescription
nameslist of stringsSEARCH_CRITERIA_NAMESFilter by template names.
categorieslist of stringsSEARCH_CRITERIA_CATEGORIESFilter by template categories.
statuseslist of stringsSEARCH_CRITERIA_STATUSESFilter by template statuses (TEMPLATE_STATUS_IN_VERIFICATION, TEMPLATE_STATUS_APPROVED, TEMPLATE_STATUS_REJECTED).
apislist of stringsSEARCH_CRITERIA_APISFilter by template APIs. Supports EMPTY and ANY filters.
extensionslist of stringsSEARCH_CRITERIA_EXTENSIONSFilter by template extension points. Supports EMPTY and ANY filters.
eventsEMPTY and ANY filters onlySEARCH_CRITERIA_EVENTSFilter by template events. For now supports EMPTY and ANY filters only.
runtimebooleanSEARCH_CRITERIA_RUNTIMEIs Adobe I/O Runtime required or not? Supports EMPTY and ANY filters.
adobeRecommendedbooleanSEARCH_CRITERIA_ADOBE_RECOMMENDEDIndicates templates featured by Adobe.
Filter Operators
Filter TypeValueSDK ConstantDescription
EMPTY (NONE)'', an empty stringSEARCH_CRITERIA_FILTER_NONEReturns all templates that don't have a property set.
ANY*, an asterisk symbolSEARCH_CRITERIA_FILTER_ANYReturns all templates that have a property set.
NOT!, an exclamation point symbolSEARCH_CRITERIA_FILTER_NOTExcludes all templates which contain the negated query parameter value.
OR|, a pipe symbolSEARCH_CRITERIA_FILTER_ORArray filters, e.g.: categories, default to returning the intersection (AND) of all matching templates. This filter operator adds the ability to specify a logical "OR" for individual values.
Supported OrderBy Criteria properties
KeyValueSDK ConstantDescription
namesstring, desc or ascORDER_BY_CRITERIA_NAMESSort by template names.
statusesstring, desc or ascORDER_BY_CRITERIA_STATUSESSort by template statuses.
adobeRecommendedstring, desc or ascORDER_BY_CRITERIA_ADOBE_RECOMMENDEDSort by the "Adobe Recommended" flag.
publishDatestring, desc or ascORDER_BY_CRITERIA_PUBLISH_DATESort by a publish date.

Get a template from Adobe App Builder Template Registry

Get a template from Adobe App Builder Template Registry.

const sdk = require('@adobe/aio-lib-templates');

async function sdkTest() {
    const templateRegistryClient = sdk.init();
    const templateName = '@author/app-builder-template';
    try {
        const template = await templateRegistryClient.getTemplate(templateName);
        console.log(template);
    } catch (error) {
        console.log(error.toString());
    }
}

Add a new template to Adobe App Builder Template Registry

Add a new template to Adobe App Builder Template Registry.

const sdk = require('@adobe/aio-lib-templates');

async function sdkTest() {
    const templateRegistryClient = sdk.init({
        'auth': {
            'token': '<IMS_ACCESS_TOKEN>'
        }
    });
    const templateName = '@author/app-builder-template';
    const githubRepoUrl = 'https://github.com/author/app-builder-template';
    try {
        const template = await templateRegistryClient.addTemplate(templateName, githubRepoUrl);
        console.log(`A new template "${template.name}" has been successfully added to Adobe App Builder Template Registry.`);
        console.log(`Its status is "${sdk.TEMPLATE_STATUS_IN_VERIFICATION}". Please use the "${template.reviewLink}" link to check the verification status.`);
    } catch (error) {
        console.log(error.toString());
    }
}

Delete a template from Adobe App Builder Template Registry

Delete a template from Adobe App Builder Template Registry.

const sdk = require('@adobe/aio-lib-templates');

async function sdkTest() {
    const templateRegistryClient = sdk.init({
        'auth': {
            'token': '<IMS_ACCESS_TOKEN>'
        }
    });
    const templateName = '@author/app-builder-template';
    try {
        await templateRegistryClient.deleteTemplate(templateName);
        console.log(`"${templateName}" has been successfully deleted from Adobe App Builder Template Registry.`);
    } catch (error) {
        console.log(error.toString());
    }
}

Explore

goto API

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.