@cowliss/sdk

中文文档
0.40.0发布于 2026/11/08MITTypeScriptES Module零依赖近 30 天下载 3232

TypeScript client for the Cowliss ingestion API: identify, track and batch.

原始使用文档
文档目录4 节
  1. Install
  2. Use it
  3. Docs
  4. License

@cowliss/sdk

The TypeScript client for the Cowliss ingestion API. Send identify and track from your app, and Cowliss keeps the profiles, the events, the segments, and the automations that follow from them.

Runs anywhere fetch does: Node 22 and up, Bun, Deno, edge runtimes and browsers. Zero dependencies, ESM only, fully typed.

Install

npm install @cowliss/sdk

Use it

import { Cow } from "@cowliss/sdk";

const cow = new Cow({
  apiKey: process.env.COW_API_KEY!,
  sourceId: process.env.COW_SOURCE_ID!,
  baseUrl: "https://api.cowliss.com",
});

await cow.identify({
  identifiers: { userId: "u_1", email: "[email protected]" },
  traits: { plan: "pro" },
});

await cow.track({
  identifiers: { userId: "u_1" },
  event: "checkout.completed",
  properties: { amount: 4900, currency: "usd" },
});

Send a message from your own code, with a template you pushed or a body written inline. Address an email address for mail nobody can turn off, such as a receipt, or a profile for mail its recipient can, such as a weekly report:

await cow.emails.send({
  to: "[email protected]",
  from: "Acme <[email protected]>",
  template: { key: "receipt", props: { orderId: "A-2291" } },
});

await cow.emails.send({
  to: { userId: "shop_1" },
  from: "Acme <[email protected]>",
  template: { key: "weekly-report", props: { visits: 120 } },
});

It resolves once the message has been handed over, and answers with the delivery id. A message to a profile goes to its email trait, skips anyone who turned that purpose off, and carries an unsubscribe link. Mail that follows a rule or a wait belongs in an automation.

Render a pushed template with your own props, exactly as a send to an address would, without sending it:

const { subject, html } = await cow.templates.preview({ key: "receipt", props: { name: "Ada" } });

Send someone to their hosted email preferences page from your own "Manage email preferences" button. The link works for an hour, so ask for it on the click:

const { url, expiresAt } = await cow.preferences.link({ to: { userId: "shop_1" } });

Every call carries identifiers, a map from kind to value. Cowliss generates the profile id and resolves the map to it, so a call that carries two identifiers is what links two profiles. There is no alias call.

identify returns the profile, track returns the stored event, and batch imports many of both in one request for backfills. Each call names the source it arrives through: set sourceId once on the client, or pass one per call when a single process writes into more than one app.

Retries are handled for you. A call that fails to reach Cowliss, or that Cowliss could not complete, backs off and tries twice more; a generated messageId travels with every track, so a retry after a lost response never writes the event twice. Each attempt has a deadline of its own (timeoutMs, ten seconds by default, thirty for a batch), so a stalled Cowliss cannot hold up your code. A call Cowliss rejected is not retried: it throws a CowError carrying the reason.

You do not have to wait for a call. await cow.track(...) throws on failure, as it always has; cow.track(...) on its own returns immediately and can never take your process down with an unhandled rejection. Pass onError to see the failures a call you did not await would otherwise swallow.

Docs

docs.cowliss.com

License

MIT

版本与发布记录

@cowliss/sdk 共发布 46 个版本,首次发布于 2026/09/08;过去 12 个月发布了 46 个版本。

版本发布日期距今
0.40.0latest2026/11/082 天前
0.39.02026/11/082 天前
0.38.02026/11/083 天前
0.37.02026/11/074 天前
0.36.02026/11/074 天前
0.35.02026/11/038 天前

关于 @cowliss/sdk 的常见问题

@cowliss/sdk 是什么?

TypeScript client for the Cowliss ingestion API: identify, track and batch.

如何安装 @cowliss/sdk?

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

@cowliss/sdk 支持 TypeScript 吗?

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

@cowliss/sdk 支持 ESM 还是 CommonJS?

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

@cowliss/sdk 需要什么版本的 Node.js?

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

@cowliss/sdk 可以商用吗?

@cowliss/sdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@cowliss/sdk 的下载量有多少?

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

@cowliss/sdk 还在维护吗?

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