@axway/amplify-cli-utils

中文文档
7.0.0发布于 2026/11/17Apache-2.0ES Module近 30 天下载 8747

Axway CLI 套件的常见使用费

中文使用文档
文档目录16 节
  1. 安装
  2. API 密码
  3. buildAuthParams(opts, config)
  4. createNPMRequestArgs(opts, config)
  5. createRequestClient(opts, config)
  6. createRequestOptions(opts, config)
  7. createTable(heading1, heading2, heading3, ...)
  8. environments.resolve(env)
  9. locations
  10. initSDK(opts, config)
  11. 通过 id 查找账户
  12. 获取所有认证账户
  13. loadConfig()
  14. 遥测
  15. 从1.x版本升级
  16. 法律

Axway CLI 用户

Axway CLI 和相关软件包常用的 utils 库.

安装

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

API 密码

buildAuthParams(opts, config)

基于所供应的 Amplify SDK 或 Amplify SDK Auth 构造器选项对象 opts 和 Axway CLI 数据 config 对象。 若为 config 未定义,配置是从磁盘上加载的.

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

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

createNPMRequestArgs(opts, config)

如果你正在产卵 npm,则以下内容可能有用:

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

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

createRequestClient(opts, config)

创建一个 got 配置 Axway CLI 网络设置的 HTTP 客户端 .

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

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

createRequestOptions(opts, config)

装入 Axway 的 CLI 配置文件并构建各种节点.js HTTP 客户端的选项 包括 pacote, (中文(简体) ), npm-registry-fetch, (中文(简体) ), make-fetch-happen,以及 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, ...)

创建一个 cli-table3 使用普通桌垫和样式.

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)

返回环境特定设置.

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

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

locations

包含 axwayHome 财务报告和审定财务报表 configFile 路径.

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)

装入 Axway CLI 配置并初始化一个 Amplify SDK 实例 .

需要时获取默认账户或登录 :

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

通过登录参数查找账户

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

通过 id 查找账户

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

获取所有认证账户

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

loadConfig()

使用懒惰装入的 Amplify 配置包装入 Axway CLI 配置文件.

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

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

遥测

如果您想要在 Axway CLI 扩展名中添加遥测功能, 您需要创建一个应用程序 用于生成 app guid 的平台。 然后需要复制并粘贴以下锅炉板. API的设计是灵活的,其代价是做更多的工作来整合.

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'
});

从1.x版本升级

在v2,整个 auth API被移除是为了利用新的Amplified SDK,它现在 包含认证 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();

此工程在 : Apache 公共许可证 v2 开发者 阿克斯韦公司 与社区。 请读一下 LICENSE 包含文件 在此分发更多信息.

版本与发布记录

@axway/amplify-cli-utils 共发布 87 个版本,首次发布于 2018/06/27;过去 12 个月发布了 3 个版本。

版本发布日期距今
7.0.0latest2026/11/17今天
6.1.02026/03/058 个月前
6.0.62026/01/239 个月前
6.0.52025/07/291.3 年前
6.0.42025/07/291.3 年前
6.0.32025/06/271.4 年前

其他发布通道:next → 5.0.3,alpha.1 → 6.0.0-alpha.1,alpha.2 → 6.0.0-alpha.2,alpha.4 → 6.0.0-alpha.4,alpha.5 → 6.0.0-alpha.5。

关于 @axway/amplify-cli-utils 的常见问题

@axway/amplify-cli-utils 是什么?

Axway CLI 套件的常见使用费

如何安装 @axway/amplify-cli-utils?

在项目目录运行 npm install @axway/amplify-cli-utils,或使用 pnpm add / yarn add / bun add。

@axway/amplify-cli-utils 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/axway__amplify-cli-utils 是否存在。

@axway/amplify-cli-utils 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@axway/amplify-cli-utils 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.22.2。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@axway/amplify-cli-utils 可以商用吗?

@axway/amplify-cli-utils 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@axway/amplify-cli-utils 的下载量有多少?

根据 npm 官方下载统计,@axway/amplify-cli-utils 在 2026/10/08 – 2026/11/06 这 30 天内被下载 8,747 次,日均约 292 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@axway/amplify-cli-utils 还在维护吗?

最新版本 7.0.0 发布于 2026/11/17(今天);至今共发布 87 个版本,其中过去 12 个月发布了 3 个;首次发布于 2018/06/27。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。