npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@axway/amplify-cli-utils

v5.0.19

Published

Common utils for Axway CLI packages

Downloads

10,139

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();

Legal

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.