@gathertown/webhook-object-sdk

中文文档
0.3.0发布于 2026/09/04MIT OR Apache-2.0TypeScriptCommonJS近 30 天下载 3.7万

Typed client for emitting events to Gather webhook objects (Smart Objects): Standard Webhooks signing, retries, and a fully-inferred send API.

原始使用文档
文档目录3 节
  1. Usage
  2. Object catalog
  3. Wire behavior

@gathertown/webhook-object-sdk

Typed client for emitting events to Gather webhook objects (Smart Objects). Handles the fiddly parts of the wire protocol (Standard Webhooks v1 signing, retries, rate limits, and error decoding) behind a fully type-safe send.

Event types and payload shapes come from @gathertown/webhook-object-types, generated from the same definitions the Gather server enforces. When new capabilities ship, this SDK picks them up via a types-package bump, no SDK release needed.

Usage

Each Smart Object is one (url, secret) pair, copied from the object's ⋮ menu in Gather. Secrets are per-object: a key for one object never authenticates another.

import { createWebhookObjectClient, secretFromEnv } from "@gathertown/webhook-object-sdk"

const counter = createWebhookObjectClient({
  url: process.env.GATHER_COUNTER_URL!,
  secret: secretFromEnv("GATHER_COUNTER_SECRET"), // whsec_…, read from the environment
})

await counter.send("counter.increment", { by: 2 }) // data type inferred from the event type
await counter.send("counter.reset") // empty-payload events take no data argument
await counter.ping() // verify url + secret; returns the object's declared capabilities

secret accepts the raw whsec_… string, so it plugs straight into whatever secret management you already have. The opaque handles are the recommended hardening on top: secretFromEnv(name) reads the variable itself, and a handle redacts itself if it ever reaches a log or JSON.stringify, a bare string can't. For values from elsewhere (a secret manager, a non-Node runtime), unsafeSecretLiteral(value) wraps them; the name makes hardcoded secrets easy to catch in review.

Every event is also available as capability-namespaced sugar with the same typing; snake_case wire names become camelCase methods:

await counter.counter.increment({ by: 2 })
await counter.counter.reset()
await lamp.switch.setState({ on: true }) // → switch.set_state

The fluent surface is derived from the generated event union and backed by a Proxy, so new capabilities appear via a types-package bump with zero SDK changes.

Object catalog

To keep several objects at hand (inboxes, lamps, counters, …), build a named catalog. An entry's optional preset narrows its send at compile time to the events that preset declares, so wiring the lamp's events to the inbox is a type error, not a runtime 404.

import { createWebhookObjectCatalog } from "@gathertown/webhook-object-sdk"

const office = createWebhookObjectCatalog({
  supportInbox: { url: INBOX_URL, secret: secretFromEnv("GATHER_INBOX_SECRET"), preset: "inbox" },
  buildLamp: { url: LAMP_URL, secret: secretFromEnv("GATHER_LAMP_SECRET"), preset: "switch" },
})

await office.supportInbox.send("activity.add", { id: "pr-142", text: "PR #142 merged" })
await office.buildLamp.send("switch.toggle")

Wire behavior

  • Signs with the standardwebhooks reference library: HMAC-SHA256 over ${webhook-id}.${webhook-timestamp}.${body}, sent as the webhook-id / webhook-timestamp / webhook-signature headers. The exact serialized body is signed and sent unchanged.
  • One webhook-id (UUID) per event, reused across retries; the server dedups the last 10 ids per object, so retries are idempotent. Each retry is re-signed with a fresh timestamp.
  • Retries transient failures only (429, 5xx, network errors), honoring RateLimit-Reset / Retry-After, with exponential backoff + jitter otherwise. 4xx failures never retry.
  • Cancelable via a signal (AbortSignal) in config: aborting cancels the in-flight request and any pending backoff, rejecting with an aborted error.
  • Rejects payloads over the server's 4 KB body cap client-side, with a clear error instead of the receiver's uniform 404.
  • Refuses non-https URLs at construction (signing authenticates but does not encrypt), with an http carve-out for localhost so local development keeps working.
  • Never exposes the secret: error messages never contain it, and the opaque-handle form additionally redacts itself when logged or serialized.
  • Failures throw WebhookObjectError with a code mirroring the server's error bodies (not_found, capability_not_declared, token_revoked, …) plus client-side codes (payload_too_large, invalid_secret, invalid_url, network_error, aborted, unexpected_response).

Uses global fetch and crypto.randomUUID by default (Node 19+, modern browsers, Deno, workers). Both are overridable via config. Inject fetch and/or newWebhookId for other runtimes, proxies, or deterministic tests.

版本与发布记录

@gathertown/webhook-object-sdk 共发布 4 个版本,首次发布于 2026/07/20;过去 12 个月发布了 4 个版本。

版本发布日期距今
0.3.0latest2026/09/042 个月前
0.2.02026/07/293 个月前
0.1.12026/07/203 个月前
0.1.02026/07/203 个月前

关于 @gathertown/webhook-object-sdk 的常见问题

@gathertown/webhook-object-sdk 是什么?

Typed client for emitting events to Gather webhook objects (Smart Objects): Standard Webhooks signing, retries, and a fully-inferred send API.

如何安装 @gathertown/webhook-object-sdk?

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

@gathertown/webhook-object-sdk 支持 TypeScript 吗?

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

@gathertown/webhook-object-sdk 支持 ESM 还是 CommonJS?

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

@gathertown/webhook-object-sdk 需要什么版本的 Node.js?

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

@gathertown/webhook-object-sdk 可以商用吗?

@gathertown/webhook-object-sdk 使用 MIT OR Apache-2.0 许可。可在 MIT、Apache-2.0 中任选其一遵守。选择 MIT 时,宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@gathertown/webhook-object-sdk 的下载量有多少?

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

@gathertown/webhook-object-sdk 还在维护吗?

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