@abgov/adsp-service-sdk

中文文档
2.34.1发布于 2026/11/07Apache-2.0TypeScriptCommonJS构建来源已验证近 30 天下载 3087

Government of Alberta - SDK for ADSP platform and tenant services.

原始使用文档
文档目录3 节
  1. Getting started
  2. Audit action classifications
  3. Audit service client

adsp-service-sdk

SDK for Alberta Digital Service Platform (ADSP).

Use this library to build Node based platform and tenant services for ADSP.

Getting started

Initialize the SDK for either platform or tenant service.

  import { AdspId, initializePlatform } from '@abgov/adsp-service-sdk';

  const serviceId = AdspId.parse(environment.CLIENT_ID);
  const {
    coreStrategy,
    tenantStrategy,
    ...sdkCapabilities,
  } = await initializePlatform(
    {
      displayName: 'My platform service',
      description: 'Example of a platform service.',
      serviceId,
      accessServiceUrl: new URL(environment.KEYCLOAK_ROOT_URL),
      clientSecret: environment.CLIENT_SECRET,
      directoryUrl: new URL(environment.DIRECTORY_URL),
      configurationSchema,
      events: [],
      roles: [],
      notifications: [],
    },
    { logger }
  );

See ADSP Development Guide for details.

Audit action classifications

Use the shared constants when defining audit actions:

import {
  AuditAction,
  AuditCategories,
  AuditSeverities,
  BuiltInRetentionClasses,
} from '@abgov/adsp-service-sdk';

const UPDATE_CASE: AuditAction = {
  name: 'case.update',
  version: 1,
  category: AuditCategories.Administrative,
  severity: AuditSeverities.Info,
  retentionClass: BuiltInRetentionClasses.Compliance,
};

AuditCategory and AuditSeverity are string unions derived from the constants, so existing string literals and serialized catalog values remain compatible. retentionClass remains a string: applications may use custom class names such as case-history when a corresponding retention period is configured. Built-in class constants specify names, not retention periods.

Audit service client

Register actions with auditActions and record events with the returned auditService:

const { auditService } = await initializeService(
  { serviceId, displayName: 'Case service', description: 'Case management', auditActions: [UPDATE_CASE] },
  { logger },
);

const outcome = await auditService.record(UPDATE_CASE, { actor: { id: user.id, type: 'user' } });
if (outcome.status !== 'recorded') {
  logger.warn(`Audit event ${outcome.eventId} was not recorded: ${outcome.reason}`);
}

By default, each event is sent immediately in its own HTTP request. Await record() and check its outcome: it never rejects, and recorded means the service confirmed storage or an idempotent duplicate, not just receipt in an in-memory queue. Once all calls have settled, no separate audit flush() is needed. Normal application shutdown must still wait for in-flight requests and tasks. Sending immediately does not make fire-and-forget calls safe against process termination.

For high-throughput workloads, opt into client-side batching through the audit option on either initializeService or initializePlatform:

const { auditService } = await initializeService(
  {
    ...serviceOptions,
    auditActions: [UPDATE_CASE],
    audit: { batchSize: 100, batchIntervalMs: 500 },
  },
  { logger },
);

Batching is enabled by setting batchSize greater than 1; partial batches wait up to batchIntervalMs (500 ms by default). Before shutdown, call await auditService.flush() if batches or unawaited records remain. This configuration preserves the previous 100-event / 500-ms behavior; the new default increases HTTP request volume. Audit Service still batches database writes on the server, independently of client batching.

Both modes retain bounded in-flight/retry memory, transient retries with the same eventId, and the audit.client.dropped_events metric. A failed delivery may already have been stored if its response was lost; resend with the same eventId. AuditClientOptions is exported for typed configuration, including request timeouts and retry delays. See the Audit service documentation.

版本与发布记录

@abgov/adsp-service-sdk 共发布 66 个版本,首次发布于 2022/09/09;过去 12 个月发布了 41 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.34.1latest2026/11/071 天前
2.34.02026/11/052 天前
2.33.02026/11/034 天前
2.32.02026/11/035 天前
2.31.02026/10/308 天前
2.30.02026/10/309 天前

关于 @abgov/adsp-service-sdk 的常见问题

@abgov/adsp-service-sdk 是什么?

Government of Alberta - SDK for ADSP platform and tenant services.

如何安装 @abgov/adsp-service-sdk?

在项目目录运行 npm install @abgov/adsp-service-sdk,或使用 pnpm add / yarn add / bun add。

@abgov/adsp-service-sdk 支持 TypeScript 吗?

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

@abgov/adsp-service-sdk 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@abgov/adsp-service-sdk 可以商用吗?

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

@abgov/adsp-service-sdk 的下载量有多少?

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

@abgov/adsp-service-sdk 还在维护吗?

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