Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@axway/amplify-cli-utils

appcelerator10.2kApache-2.06.0.2

Common utils for Axway CLI packages

axway, amplify

readme

Axway CLI Utils

A common utils library for Axway CLI and related packages.

Installation

npm i @axway/amplify-cli-utils --save

API

buildAuthParams(opts, config)

Creates an Amplify SDK or Amplify SDK Auth constructor options object based on the supplied opts and Axway CLI config object. If config is not defined, the config is loaded from disk.

import { buildAuthParams } from '@axway/amplify-cli-utils';

const opts = buildAuthParams({
    baseUrl: 'foo',
    clientId: 'bar'
});

createNPMRequestArgs(opts, config)

If you are spawning npm, then the following may be useful:

import { createNPMRequestArgs } from '@axway/amplify-cli-utils';
import { spawnSync } from 'child_process';

spawnSync('npm', [ 'view', 'axway', ...createNPMRequestArgs() ]);

createRequestClient(opts, config)

Creates a got HTTP client with the Axway CLI network settings configured.

import { createRequestClient } from '@axway/amplify-cli-utils';

const got = createRequestClient();
const response = await got('https://www.axway.com/');

createRequestOptions(opts, config)

Loads the Axway CLI config file and construct the options for the various Node.js HTTP clients including pacote, npm-registry-fetch, make-fetch-happen, and request.

import { createRequestOptions } from '@axway/amplify-cli-utils';

const opts = createRequestOptions();
console.log({
    ca:        opts.ca,
    cert:      opts.cert,
    key:       opts.key,
    proxy:     opts.proxy,
    strictSSL: opts.strictSSL
});

createTable(heading1, heading2, heading3, ...)

Creates a cli-table3 instance with common table padding and styling.

import { createTable } from '@axway/amplify-cli-utils';

const table = createTable('Name', 'Version');
table.push([ 'foo', '1.0.0' ]);
table.push([ 'bar', '2.0.0' ]);
console.log(table.toString());

environments.resolve(env)

Returns environment specific settings.

import { environments } from '@axway/amplify-cli-utils';

console.log(environments.resolve());
console.log(environments.resolve('prod'));
console.log(environments.resolve('production'));

locations

An object containing the axwayHome and configFile paths.

import { locations } from '@axway/amplify-cli-utils';

console.log('Axway Home Directory:', locations.axwayHome);
console.log('Axway CLI Config Path:', locations.configFile);

initSDK(opts, config)

Loads the Axway CLI config and initializes an Amplify SDK instance.

Get the default account or login if needed:

import { initSDK } from '@axway/amplify-cli-utils';

async function getAccount(opts) {
    try {
        return await initSDK(opts).sdk.auth.login();
    } catch (err) {
        if (err.code === 'EAUTHENTICATED') {
            return err.account;
        }
        throw err;
    }
}

(async () => {
    const account = await getAccount({ clientId: 'foo' });
    if (!account) {
        console.error('Please login in by running: amplify auth login');
        process.exit(1);
    }
}());

Find account by login parameters

import { initSDK } from '@axway/amplify-cli-utils';

(async () => {
    const { sdk, config } = initSDK({
        baseUrl:      '',
        clientId:     '',
        clientSecret: '',
        env:          '',
        password:     '',
        realm:        '',
        secretFile:   '',
        username:     ''
    });

    const account = await sdk.auth.find('foo');

    if (account && !account.expired) {
        console.log('Found a valid access token!');
        console.log(account);
        return;
    }

    console.error('No valid authentication token found. Please login in again by running:');
    console.error('  amplify auth login');
    process.exit(1);
}());

Find account by id

const accountName = '<client_id>:<email_address>';
const account = await sdk.auth.getAccount(accountName);

Get all credentialed accounts

const accounts = await sdk.auth.list();
console.log(accounts);

loadConfig()

Loads the Axway CLI config file using the lazy loaded Amplify Config package.

import { loadConfig } from '@axway/amplify-cli-utils';

const config = loadConfig();
console.log(config);

Telemetry

If you'd like to add telemetry to an Axway CLI extension, then you will need to create an app in the platform to generate an app guid. Then you'll need to copy and paste the following boilerplate. The API is designed to be flexible at the cost of being more work to integrate.

import {
    createRequestOptions,
    environments,
    loadConfig,
    locations,
    Telemetry
} from '@axway/amplify-cli-utils';

const appGuid = '<GUID>';
const appVersion = 'x.y.z';
const telemetryCacheDir = path.join(locations.axwayHome, '<PRODUCT_NAME>', 'telemetry');

function initTelemetry(opts = {}) {
    const config = opts.config || loadConfig();
    if (!config.get('telemetry.enabled')) {
        return;
    }

    const env = environments.resolve(opts.env || config.get('env'));

    const telemetryInst = new Telemetry({
        appGuid,
        appVersion,
        cacheDir,
        environment: env === 'preprod' ? 'preproduction' : 'production',
        requestOptions: createRequestOptions(opts, config)
    });

    process.on('exit', () => {
        try {
            telemetryInst.send();
        } catch (err) {
            warn(err);
        }
    });

    return telemetryInst;
}

const telemetry = initTelemetry();
telemetry.addEvent({
    event: 'my.event',
    some: 'data'
});

Upgrading from version 1.x

In v2, the entire auth API was removed to take advantage of the new Amplify SDK, which now contains the auth API.

// Find account by login parameters

// v1
import { auth } from '@axway/amplify-cli-utils';
const { account, client, config } = await auth.getAccount({ /* auth options */ });

// v2
import { initSDK } from '@axway/amplify-cli-utils';
const { config, sdk } = initSDK({ /* auth options */ });
const account = await sdk.auth.find();
// Find account by id

// v1
import { auth } from '@axway/amplify-cli-utils';
const { account, client, config } = await auth.getAccount('<CLIENT_ID>:<EMAIL>');

// v2
import { initSDK } from '@axway/amplify-cli-utils';
const { config, sdk } = initSDK({ /* auth options */ });
const account = await sdk.auth.find('<CLIENT_ID>:<EMAIL>');
// Get all credentialed accounts

// v1
import { auth } from '@axway/amplify-cli-utils';
const accounts = await auth.list();

// v2
import { initSDK } from '@axway/amplify-cli-utils';
const { config, sdk } = initSDK({ /* auth options */ });
const accounts = await sdk.auth.list();

This project is open source under the Apache Public License v2 and is developed by Axway, Inc and the community. Please read the LICENSE file included in this distribution for more information.

changelog

v6.0.2 (May 16, 2025)

  • BREAKING CHANGE: Node.js version upgrade to 20.18.2 (minimum) and conversion to ES Modules. (APIGOV-27923)

v6.0.1 (May 16, 2025)

  • BREAKING CHANGE: Node.js version upgrade to 20.18.2 (minimum) and conversion to ES Modules. (APIGOV-27923)

v6.0.0 (May 16, 2025)

  • BREAKING CHANGE: Node.js version upgrade to 20.18.2 (minimum) and conversion to ES Modules. (APIGOV-27923)

v5.0.20 (Jan 16, 2025)

  • fix: Added a fix for listing teams with a service account (APIGOV-27713)

v5.0.19 (Nov 21, 2024)

  • chore: Updated dependencies.

v5.0.18 (July 3, 2024)

  • chore: Updated dependencies.

v5.0.17 (May 31, 2024)

  • chore: Updated dependencies.

v5.0.16 (Jan 23, 2024)

  • chore: Updated dependencies.

v5.0.15 (Nov 8, 2023)

  • chore: Updated dependencies.

v5.0.14 (Nov 8, 2023)

  • chore: Updated dependencies.

v5.0.13 (Nov 8, 2023)

  • chore: Updated dependencies.

v5.0.12 (Nov 8, 2023)

  • chore: Updated dependencies.

v5.0.11 (Jul 7, 2022)

  • chore: Updated dependencies.

v5.0.10 (Jun 30, 2022)

  • chore: Updated dependencies.

v5.0.9 (May 11, 2022)

  • chore: Updated dependencies.

v5.0.8 (Mar 28, 2022)

  • chore: Updated dependencies.

v5.0.7 (Feb 16, 2022)

  • chore: Updated dependencies.

v5.0.6 (Feb 2, 2022)

  • fix: Use "staging" name instead of "preprod".
  • chore: Updated dependencies.

v5.0.5 (Jan 14, 2022)

  • chore: Updated dependencies.

v5.0.4 (Dec 21, 2021)

  • fix: Initialize default token refresh threshold to 15 minutes. (APIGOV-20729)
  • fix: Fixed bug where falsey config values were being overwritten by config file values.
  • chore: Updated dependencies.

v5.0.3 (Dec 2, 2021)

  • chore: Updated dependencies.

v5.0.2 (Nov 5, 2021)

  • chore: Updated dependencies.

v5.0.1 (Oct 18, 2021)

  • chore: Updated dependencies.

v5.0.0 (Sep 24, 2021)

  • BREAKING CHANGE: Require Node.js 12.13.0 LTS or newer. (APIGOV-19220)
  • refactor: Added initPlatformAccount() from @axway/axway-cli-oum.
  • refactor: Replaced appcd-* libraries with @axway/amplify-utils. (APIGOV-20264)
  • feat: Added telemetry to help improve Axway products. (APIGOV-19209)
  • feat: Added environment titles.
  • feat: Added helper function to resolve the environment specific auth config key.
  • feat: Added environment argument to platform account initialization.
  • chore: Updated dependencies.

v4.4.0 (Jul 30, 2021)

  • feat: Added hlVer() function to render version difference.
  • chore: Updated dependencies.

v4.3.4 (May 11, 2021)

  • fix: Prevent table padding from being styled despite there being no border.
  • chore: Updated dependencies.

v4.3.3 (Apr 29, 2021)

  • chore: Updated dependencies.

v4.3.2 (Apr 28, 2021)

  • chore: Updated dependencies.

v4.3.1 (Apr 27, 2021)

  • chore: Updated dependencies.

v4.3.0 (Apr 21, 2021)

  • feat: Added isHeadless() helper function.
  • feat: Autodetect if headless and force token store type to file. (CLI-116)
  • chore: Updated dependencies.

v4.2.5 (Jan 22, 2021)

  • chore: Updated dependencies.

v4.2.4 (Jan 20, 2021)

  • chore: Updated dependencies.

v4.2.3 (Jan 11, 2021)

  • chore: Updated dependencies.

v4.2.2 (Jan 11, 2021)

  • chore: Updated dependencies.

v4.2.1 (Jan 5, 2021)

  • chore: Updated dependencies.

v4.2.0 (Dec 1, 2020)

  • fix: Bumped minimum Node.js requirement to 10.19.0 to prevent warnings on install.
  • chore: Updated dependencies.

v4.1.4 (Nov 18, 2020)

  • chore: Updated dependencies.

v4.1.3 (Nov 13, 2020)

  • chore: Updated dependencies.

v4.1.2 (Nov 12, 2020)

  • chore: Updated dependencies.

v4.1.1 (Nov 12, 2020)

  • chore: Updated dependencies.

v4.1.0 (Nov 10, 2020)

  • feat: Added API for checking if update is available. (CLI-22)
  • chore: Updated dependencies.

v4.0.0 (Oct 21, 2020)

  • BREAKING CHANGE: Updated AMPLIFY CLI references to Axway CLI. The config file was moved from ~/.axway/amplify-cli/amplify-cli.json to ~/.axway/axway-cli/config.json. (CLI-100)
  • chore: Updated dependencies.

v3.2.0 (Oct 1, 2020)

  • feat: Added HTTP request helpers for preparing proxy config and creating a got instance. (CLI-98)
  • fix: Removed preferGlobal package setting.
  • refactor: Renamed buildParams() to buildAuthParams() to be more clear on purpose.
  • chore: Updated dependencies.

v3.1.1 (Aug 27, 2020)

  • style: Update table style.
  • chore: Updated dependencies.

v3.1.0 (Aug 6, 2020)

  • refactor: Moved AMPLIFY CLI config file from ~/.axway to ~/.axway/amplify-cli.

v3.0.6 (Jul 24, 2020)

  • chore: Updated dependencies.

v3.0.5 (Jul 2, 2020)

  • chore: Updated dependencies.

v3.0.4 (Jun 12, 2020)

  • chore: Updated dependencies.

v3.0.3 (Jun 9, 2020)

  • chore: Updated dependencies.

v3.0.2 (May 19, 2020)

  • chore: Updated dependencies.

v3.0.1 (May 5, 2020)

  • fix: Added missing AMPLIFY SDK dependency.

v3.0.0 (May 5, 2020)

  • BREAKING CHANGE: Dropped support for Node.js 10.12.0 and older. (CLI-89)
  • BREAKING CHANGE: Removed auth APIs. Use initSDK() and the resulting sdk.auth.* methods.
  • BREAKING CHANGE: Added @appcd/amplify-sdk for authentication and platform integration. (DAEMON-324)
  • BREAKING CHANGE: AMPLIFY Auth SDK v2 (via AMPLIFY SDK) changed structure of account info by moving auth-related info into an auth property.
  • feat: Added initSDK() helper that loads the AMPLIFY CLI config and initializes an AMPLIFY SDK instance.
  • feat: Added support for environment synonyms such as "production" for "prod". (CLI-87)
  • chore: Removed unused appcd-config dependency.
  • chore: Updated dependencies.