anypoint-utils

1.0.23 • Public • Published

anypoint-utils

npm downloads Build Status

This npm package provides utility methods that can be used within your CI/CD environment and MuleSoft API release management strategy. MuleSoft provides REST API resources for managing your Mule products and hostings on Cloudhub or On-Premise.

Installation

$ npm install anypoint-utils --save

Example Code (with use of corp proxy)

// tmp.js
 
const AnypointUtils = require('./main');
require('console-stamp')(console, { pattern: 'dd/mm/yyyy HH:MM:ss.l' });
 
const s = new AnypointUtils('user', 'password', 'http://corp.proxy.int:8080');
 
async function main() {
  const authtoken = await s.getToken();
  console.info(`token: ${authtoken}`);
 
  const orgId = await AnypointUtils.getOrganizationId(authtoken);
  console.info(`orgId: ${orgId}`);
 
  const stuff = await AnypointUtils.createApiManagerInstance(authtoken, 'emp-xapi', '1.0.0', orgId, 'Sandbox2');
  console.info(`This id is used for API auto-discovery. Id:${stuff}`);
}
 
main();

Note: if proxy not used, send 'null'

Functions

These are the current functions that have been coded so far. A listing is given here with comments for your reference.

getOrganizationId(token)

This function takes an active bearer token and returns an organization id in the same form/syntax of the token.

getDefaultEnvironmentId(token)

This function returns the environment id that is set as default by the user that supplied the credentials for the bearer token (authenticated).

getEnvironments(token)

This function returns a JSON array of environments that are associated to the authenticated user.

getApplications(token)

This function returns a JSON array of client applications that are associated to the authenticated user.

getApis(token)

This function returns a JSON array of APIs (needs closer review).

getEnvApis(token)

This function returns a JSON array of "instanced" APIs that are associated to the authenticated user.

getExchangeGroups(token)

This function returns the organization id and business group ids from Exchange that are associated to the authenticated user.

getExchangeAssetById(token, groupId, assetId)

This function returns an Exchange asset by giving the group id and the asset id (name).

getExchangeAssets(token)

This function returns all Exchange assets visible to the authenticated user. This function is not very useful. Needs a filter.

createClientApplication(token, clientName)

This function creates a new client application. This client application is a representational object of either an API or an external API consumer. The client application will be requesting access to registered (running) APIs. These API's should already be in Exchange as managed assets.

deleteApplication(token, appId)

This function will delete a client application (remember it's a representational object only) using a bearer token (authorization) and the client application's application id or primary key.

getApplicationIdByName(token, applicationName)

This function gets the application id for client application name given, along with the bearer token (authorization) of course.

getApiIdByName(token, apiName)

This function gets the API id for the API name or artifact id given.

getApi(token, apiId)

This function returns a JSON object representing the API for the API id given.

getVersionId(token, apiId, productVersion)

This function returns a version id for the API id and productVersion (e.g. v1) given.

createApiManagerInstance(token, assetId, version, groupId)

This function creates an unregistered API instance in API Manager. The function returns an API id for use with runtime API auto-discovery.

createContractWithAsset(token, clientAppName, primeArtifactName)

This function creates a contract between a client application and a registered API to be consumed. Refactoring is needed because this calls another function that really does the work.

isClientApplicationByName(token, clientApplicationName)

This function returns true if the named client application exists that's related to the authenticated user sending the bearer token (authorization) also.

promoteApiCreatingNewInstance(token, organizationId, environmentId, originalApiId)

This function essentially promotes an existing (registered) API into a new environment, specified by the environment id, and using the original API id. A new API id for runtime auto-discovery is returned by the function.

getEnvironmentIdByName(token, environmentName)

This function returns the id for the environment name given.

Notes

As of version 1.0.18 there are still many additions needed to this, however they will be added as work requires them. The createContractWithAssetfunction requires refactoring. Updates will be noted with future releases of this package.

Readme

Keywords

none

Package Sidebar

Install

npm i anypoint-utils

Weekly Downloads

0

Version

1.0.23

License

Apache-2.0

Unpacked Size

85.7 kB

Total Files

18

Last publish

Collaborators

  • dlwhitehurst