@adobe/spacecat-shared-ims-client

中文文档
1.16.0发布于 2026/08/12Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 2750

Shared modules of the Spacecat Services - IMS Client

原始使用文档
文档目录13 节
  1. Overview
  2. Environment Setup
  3. Installation
  4. Usage
  5. Creating an ImsClient Instance
  6. Retrieving Service Access Token
  7. Getting IMS Organization Details
  8. Error Handling
  9. Development
  10. Testing
  11. Linting
  12. Cleaning
  13. Additional Information

Spacecat Shared - IMS Client

Overview

The ImsClient library is designed to interact with the IMS (Identity Management System) API, facilitating the retrieval of organization details, user information, and service access tokens. This document outlines the necessary steps for setting up the environment and provides usage examples for integrating the ImsClient into your projects.

Environment Setup

Before using the ImsClient, ensure your environment is correctly configured with the necessary credentials and endpoints. The following environment variables are required:

  • IMS_HOST: The hostname of the IMS API.
  • IMS_CLIENT_ID: Your IMS client ID.
  • IMS_CLIENT_CODE: Your IMS client code, used for authentication.
  • IMS_CLIENT_SECRET: Your IMS client secret, used for authentication.

Installation

Include the ImsClient in your project by importing it from its source file. Ensure that dependencies such as @adobe/fetch and @adobe/spacecat-shared-utils are also installed in your project.

import ImsClient from 'path/to/ImsClient';

Usage

Creating an ImsClient Instance

To create an instance of the ImsClient, you need to provide a context object containing the necessary environment configurations and an optional log.

const context = {
  env: {
    IMS_HOST: 'ims.example.com',
    IMS_CLIENT_ID: 'yourClientId',
    IMS_CLIENT_CODE: 'yourClientCode',
    IMS_CLIENT_SECRET: 'yourClientSecret',
  },
  log: console, // Optional: Custom log can be provided
};

const imsClient = ImsClient.createFrom(context);

Retrieving Service Access Token

To fetch a service access token, use the getServiceAccessToken method. This token is required for authenticating subsequent API requests.

async function fetchServiceAccessToken() {
  try {
    const token = await imsClient.getServiceAccessToken();
    console.log('Service Access Token:', token);
  } catch (error) {
    console.error('Error fetching service access token:', error);
  }
}

fetchServiceAccessToken();

Getting IMS Organization Details

Retrieve details about an IMS organization by its ID using the getImsOrganizationDetails method.

async function fetchImsOrganizationDetails(imsOrgId) {
  try {
    const details = await imsClient.getImsOrganizationDetails(imsOrgId);
    console.log('Organization Details:', details);
  } catch (error) {
    console.error('Error fetching organization details:', error);
  }
}

const imsOrgId = 'yourImsOrgId';
fetchImsOrganizationDetails(imsOrgId);

Error Handling

All methods return promises. It's important to handle errors using try/catch blocks in async functions to manage API request failures or invalid responses gracefully.

Development

Testing

To run tests:

npm test

Linting

Lint your code:

npm run lint

Cleaning

To remove node_modules and package-lock.json:

npm run clean

Additional Information

版本与发布记录

@adobe/spacecat-shared-ims-client 共发布 107 个版本,首次发布于 2024/02/16;过去 12 个月发布了 32 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.16.0latest2026/08/122 个月前
1.15.02026/08/122 个月前
1.14.02026/06/194 个月前
1.13.32026/05/305 个月前
1.13.22026/05/295 个月前
1.13.12026/05/235 个月前

关于 @adobe/spacecat-shared-ims-client 的常见问题

@adobe/spacecat-shared-ims-client 是什么?

Shared modules of the Spacecat Services - IMS Client

如何安装 @adobe/spacecat-shared-ims-client?

在项目目录运行 npm install @adobe/spacecat-shared-ims-client,或使用 pnpm add / yarn add / bun add。

@adobe/spacecat-shared-ims-client 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@adobe/spacecat-shared-ims-client 支持 ESM 还是 CommonJS?

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

@adobe/spacecat-shared-ims-client 需要什么版本的 Node.js?

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

@adobe/spacecat-shared-ims-client 可以商用吗?

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

@adobe/spacecat-shared-ims-client 的下载量有多少?

根据 npm 官方下载统计,@adobe/spacecat-shared-ims-client 在 2026/10/05 – 2026/11/03 这 30 天内被下载 2,750 次,日均约 92 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@adobe/spacecat-shared-ims-client 还在维护吗?

最新版本 1.16.0 发布于 2026/08/12(2 个月前);至今共发布 107 个版本,其中过去 12 个月发布了 32 个;首次发布于 2024/02/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。