@gathertown/webhook-object-types
v0.3.0
Published
Generated TypeScript types for Gather webhook-object (Smart Object) events. Types-only, zero runtime.
Keywords
Readme
@gathertown/webhook-object-types
Generated TypeScript types for Gather webhook-object (Smart Object) events: every wire
type (e.g. counter.increment) and its data payload shape, plus preset → capability
groupings. Types-only, zero runtime code, zero dependencies.
Usage
npm install --save-dev @gathertown/webhook-object-typesimport type {
DataFor,
EventTypeForPreset,
WebhookEventEnvelope,
WebhookEventType,
WebhookWireErrorCode,
} from "@gathertown/webhook-object-types"
// The HTTP request body for any event, fully typed per event type:
const event: WebhookEventEnvelope<"counter.increment"> = {
type: "counter.increment",
timestamp: new Date().toISOString(),
data: { by: 1 }, // DataFor<"counter.increment">
}
// What a given preset accepts:
type InboxEvent = EventTypeForPreset<"inbox"> // "activity.add" | "counter.set" | …
// Error codes the receiver returns in `{ "error": "<code>" }` bodies:
const code: WebhookWireErrorCode = "token_revoked"Most integrators want
@gathertown/webhook-object-sdk
instead, which wraps these types in a signed, retrying client.
schemas/: the language-neutral contract
schemas/*.json holds one JSON Schema (draft-07) per event's data payload, named by wire
type (counter.increment.json). The TypeScript in src/ is generated from these same
schemas via quicktype, and integrators on other languages can do the exact same thing:
npx quicktype -s schema schemas/*.json --lang go --just-types
npx quicktype -s schema schemas/*.json --lang python(Pass the files explicitly, as pointing quicktype at the directory makes it treat them as JSON samples and generate types of the schema documents themselves.)
The schemas also work with any JSON Schema validator (ajv etc.) for runtime validation of dynamically-built payloads, and are importable directly:
import counterIncrement from "@gathertown/webhook-object-types/schemas/counter.increment.json"Everything here is generated from the same schemas that validate events server-side, so these types can never drift from the implementation.
