@drttix/drt-sdk

中文文档
2.1.3发布于 2026/11/12TypeScriptESM + CJS近 30 天下载 2616

DRT SDK

原始使用文档
文档目录5 节
  1. 📦 Installation
  2. 📦 Usage
  3. Backend serving many shoppers/accounts
  4. The API key
  5. 🛠️ Local Development (Developer Only)

DRT Public API

A unified NPM package for typed API clients generated from OpenAPI specs. This package provides typed access to public services via fetch.


📦 Installation

npm install @drttix/drt-sdk

📦 Usage

import { DRT } from "@drttix/drt-sdk";

DRT.init({
  shopperGuid: "your-shopper-guid",
  accountId: "your-account-id",
  apiKey: "your-api-key",
});

const theme = await DRT.shopper.account.getTheme();

Backend serving many shoppers/accounts

By default the SDK is a singleton: one shopperGuid/accountId for the whole process, set once via DRT.init(). A backend that proxies calls on behalf of many different shoppers can opt into shopperScope: 'per-request' instead, and pass { shopperGuid, accountId } as the last argument to each shopper call:

import { DRT } from "@drttix/drt-sdk";

DRT.init({ apiKey: "your-api-key", shopperScope: "per-request" });

await DRT.shopper.product.addProduct(productBody, {
  shopperGuid: req.shopperGuid,
  accountId: req.accountId,
});

apiKey is still set once at init — it identifies your backend, not the shopper. shopperGuid/accountId are the only values that become per-request. Portal and scanner are unaffected and remain singleton-scoped.

The API key

DRT.init({ apiKey }) is mandatory (2.0.0). Every service call — shopper, portal and scanner alike — throws DRT SDK not initialized until it has run; there is no keyless mode. Portal-only and scanner-only consumers pass shopperScope: 'per-request' so no shopper credentials are needed at init.

The shopper API refuses every request that does not carry a live key in the apikey header, and only honours a key from the domains it was issued for (recital_ticketing.dbo.shopper_api_key). Keys look like drt_shopper_de1ab347f47c…. The convention across DRT services is to read it from the DRT_API_KEY environment variable (in Azure DevOps: the SDK variable group) and pass it to DRT.init:

DRT.init({ apiKey: process.env.DRT_API_KEY, shopperScope: "per-request" });

Browsers need nothing more: the browser sets the Origin header itself, and that is what the API matches against the key's allowed domains.

Servers (a Node backend, a script) send no Origin, so they must declare the domain they act as, which the SDK sends as x-drt-domain:

DRT.init({
  apiKey: process.env.DRT_API_KEY,
  domain: "tap-to-pay.drttix.com",
  shopperScope: "per-request",
});

A missing key, an unknown or deactivated key, or a domain the key does not allow all answer 401 with errorCode INVALID_API_KEY or API_KEY_DOMAIN_NOT_ALLOWED.


🛠️ Local Development (Developer Only)

For SDK contributors testing against a local API server:

// Option 1: Use localhost:3000
process.env.DRT_API_LOCAL = "true";

// Option 2: Use a custom base URL
process.env.DRT_API_BASE_URL = "http://localhost:8080";

import { DRT } from "@drttix/drt-sdk";

Or via command line:

# Use localhost:3000
DRT_API_LOCAL=true npx tsx test.ts

# Use custom base URL
DRT_API_BASE_URL=http://localhost:8080 npx tsx test.ts

Npm run generate Npm login Increment package.lock version Npm publish

版本与发布记录

@drttix/drt-sdk 共发布 110 个版本,首次发布于 2026/01/07;过去 12 个月发布了 110 个版本。

版本发布日期距今
2.1.3latest2026/11/121 天前
2.1.22026/11/103 天前
2.1.12026/11/058 天前
2.1.02026/11/058 天前
2.0.112026/11/049 天前
2.0.92026/11/0310 天前

关于 @drttix/drt-sdk 的常见问题

@drttix/drt-sdk 是什么?

DRT SDK

如何安装 @drttix/drt-sdk?

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

@drttix/drt-sdk 支持 TypeScript 吗?

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

@drttix/drt-sdk 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@drttix/drt-sdk 可以商用吗?

@drttix/drt-sdk 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@drttix/drt-sdk 的下载量有多少?

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

@drttix/drt-sdk 还在维护吗?

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