@hogsend/client 0.7.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -22,7 +22,8 @@ var index_exports = {};
22
22
  __export(index_exports, {
23
23
  Hogsend: () => Hogsend,
24
24
  HogsendAPIError: () => HogsendAPIError,
25
- RateLimitError: () => RateLimitError
25
+ RateLimitError: () => RateLimitError,
26
+ verifyHogsendWebhook: () => verifyHogsendWebhook
26
27
  });
27
28
  module.exports = __toCommonJS(index_exports);
28
29
 
@@ -144,6 +145,7 @@ function createHttpClient(config) {
144
145
  get: (path, query) => request("GET", path, { query }),
145
146
  post: (path, body, extras) => request("POST", path, { body, extras }),
146
147
  put: (path, body, extras) => request("PUT", path, { body, extras }),
148
+ patch: (path, body, extras) => request("PATCH", path, { body, extras }),
147
149
  del: (path, body) => request("DELETE", path, { body })
148
150
  };
149
151
  }
@@ -335,6 +337,93 @@ var ListsResource = class {
335
337
  }
336
338
  };
337
339
 
340
+ // src/resources/webhooks.ts
341
+ var BASE = "/v1/admin/webhooks";
342
+ var WebhooksResource = class {
343
+ constructor(http) {
344
+ this.http = http;
345
+ }
346
+ http;
347
+ /**
348
+ * Register a new endpoint subscribed to one or more outbound event types.
349
+ * For the default kind="webhook", returns the endpoint INCLUDING the full
350
+ * signing `secret` — the only time (besides rotate) it is returned; store it
351
+ * now. For a keyed destination (e.g. `{ kind: "posthog", config: { apiKey } }`)
352
+ * no secret is returned (it authenticates via `config`).
353
+ */
354
+ create(input) {
355
+ return this.http.post(BASE, {
356
+ url: input.url,
357
+ eventTypes: input.eventTypes,
358
+ description: input.description,
359
+ disabled: input.disabled,
360
+ kind: input.kind,
361
+ config: input.config
362
+ });
363
+ }
364
+ /**
365
+ * List endpoints (newest first). Disabled endpoints are hidden unless
366
+ * `includeDisabled` is set. Returns the endpoints array (unwrapped from the
367
+ * `{ endpoints, total, limit, offset }` envelope).
368
+ */
369
+ async list(opts) {
370
+ const res = await this.http.get(BASE, {
371
+ limit: opts?.limit,
372
+ offset: opts?.offset,
373
+ includeDisabled: opts?.includeDisabled === void 0 ? void 0 : String(opts.includeDisabled)
374
+ });
375
+ return res.endpoints;
376
+ }
377
+ /** Fetch one endpoint by id (404 → {@link HogsendAPIError}). */
378
+ get(id) {
379
+ return this.http.get(`${BASE}/${encodeURIComponent(id)}`);
380
+ }
381
+ /**
382
+ * Patch an endpoint. Only the provided fields change; `description: null`
383
+ * clears the description. Does NOT return or rotate the secret.
384
+ */
385
+ update(id, input) {
386
+ return this.http.patch(
387
+ `${BASE}/${encodeURIComponent(id)}`,
388
+ {
389
+ url: input.url,
390
+ eventTypes: input.eventTypes,
391
+ description: input.description,
392
+ disabled: input.disabled,
393
+ kind: input.kind,
394
+ config: input.config
395
+ }
396
+ );
397
+ }
398
+ /** Hard-delete an endpoint (cascade drops its deliveries). */
399
+ delete(id) {
400
+ return this.http.del(
401
+ `${BASE}/${encodeURIComponent(id)}`
402
+ );
403
+ }
404
+ /**
405
+ * Rotate the signing secret. The OLD secret is invalidated immediately (hard
406
+ * cutover) — update every subscriber with the returned new `secret` (returned
407
+ * ONCE).
408
+ */
409
+ rotateSecret(id) {
410
+ return this.http.post(
411
+ `${BASE}/${encodeURIComponent(id)}/rotate-secret`,
412
+ {}
413
+ );
414
+ }
415
+ /**
416
+ * Enqueue an out-of-band `webhook.test` delivery to the endpoint, delivered
417
+ * regardless of its subscribed `eventTypes`. Returns the 202 enqueue ack.
418
+ */
419
+ sendTest(id) {
420
+ return this.http.post(
421
+ `${BASE}/${encodeURIComponent(id)}/test`,
422
+ {}
423
+ );
424
+ }
425
+ };
426
+
338
427
  // src/hogsend.ts
339
428
  var Hogsend = class {
340
429
  contacts;
@@ -342,6 +431,13 @@ var Hogsend = class {
342
431
  emails;
343
432
  lists;
344
433
  campaigns;
434
+ /**
435
+ * Manage outbound webhook endpoints (the signed event stream Hogsend emits to
436
+ * subscriber URLs). REQUIRES a full-admin `apiKey` — this resource hits the
437
+ * admin plane (`/v1/admin/webhooks`), NOT the ingest data plane the other
438
+ * resources use. See {@link WebhooksResource}.
439
+ */
440
+ webhooks;
345
441
  constructor(opts) {
346
442
  if (!opts.baseUrl) {
347
443
  throw new TypeError("Hogsend: `baseUrl` is required.");
@@ -361,12 +457,76 @@ var Hogsend = class {
361
457
  this.emails = new EmailsResource(http);
362
458
  this.lists = new ListsResource(http);
363
459
  this.campaigns = new CampaignsResource(http);
460
+ this.webhooks = new WebhooksResource(http);
364
461
  }
365
462
  };
463
+
464
+ // src/internal/verify.ts
465
+ var import_node_crypto = require("crypto");
466
+ var import_svix = require("svix");
467
+ var TOLERANCE_SECONDS = 5 * 60;
468
+ function normalizeHeaders(headers) {
469
+ const out = {};
470
+ for (const [key, value] of Object.entries(headers)) {
471
+ out[key.toLowerCase()] = value;
472
+ }
473
+ return out;
474
+ }
475
+ function verifyHogsendWebhook(opts) {
476
+ const headers = normalizeHeaders(opts.headers);
477
+ const id = headers["webhook-id"] ?? headers["svix-id"];
478
+ const timestamp = headers["webhook-timestamp"] ?? headers["svix-timestamp"];
479
+ const signature = headers["webhook-signature"] ?? headers["svix-signature"];
480
+ if (!id || !timestamp || !signature) {
481
+ throw new Error(
482
+ "verifyHogsendWebhook: missing Webhook-Id / Webhook-Timestamp / Webhook-Signature header"
483
+ );
484
+ }
485
+ try {
486
+ const wh = new import_svix.Webhook(opts.secret);
487
+ return wh.verify(opts.payload, {
488
+ "svix-id": id,
489
+ "svix-timestamp": timestamp,
490
+ "svix-signature": signature
491
+ });
492
+ } catch {
493
+ return verifyWithNodeCrypto({
494
+ payload: opts.payload,
495
+ secret: opts.secret,
496
+ id,
497
+ timestamp,
498
+ signature
499
+ });
500
+ }
501
+ }
502
+ function verifyWithNodeCrypto(opts) {
503
+ const ts = Number.parseInt(opts.timestamp, 10);
504
+ if (!Number.isFinite(ts)) {
505
+ throw new Error("verifyHogsendWebhook: invalid Webhook-Timestamp");
506
+ }
507
+ const now = Math.floor(Date.now() / 1e3);
508
+ if (Math.abs(now - ts) > TOLERANCE_SECONDS) {
509
+ throw new Error("verifyHogsendWebhook: timestamp outside tolerance window");
510
+ }
511
+ const key = opts.secret.startsWith("whsec_") ? Buffer.from(opts.secret.slice(6), "base64") : Buffer.from(opts.secret, "base64");
512
+ const signedContent = `${opts.id}.${opts.timestamp}.${opts.payload}`;
513
+ const expected = (0, import_node_crypto.createHmac)("sha256", key).update(signedContent).digest("base64");
514
+ const expectedBuf = Buffer.from(expected);
515
+ const matched = opts.signature.split(" ").some((part) => {
516
+ const sig = part.startsWith("v1,") ? part.slice(3) : part;
517
+ const candidate = Buffer.from(sig);
518
+ return candidate.length === expectedBuf.length && (0, import_node_crypto.timingSafeEqual)(candidate, expectedBuf);
519
+ });
520
+ if (!matched) {
521
+ throw new Error("verifyHogsendWebhook: signature verification failed");
522
+ }
523
+ return JSON.parse(opts.payload);
524
+ }
366
525
  // Annotate the CommonJS export names for ESM import in node:
367
526
  0 && (module.exports = {
368
527
  Hogsend,
369
528
  HogsendAPIError,
370
- RateLimitError
529
+ RateLimitError,
530
+ verifyHogsendWebhook
371
531
  });
372
532
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/internal/http.ts","../src/resources/campaigns.ts","../src/internal/identity.ts","../src/resources/contacts.ts","../src/resources/emails.ts","../src/resources/events.ts","../src/resources/lists.ts","../src/hogsend.ts"],"sourcesContent":["export { HogsendAPIError, RateLimitError } from \"./errors.js\";\nexport { Hogsend } from \"./hogsend.js\";\nexport type {\n Campaign,\n CampaignAudienceKind,\n CampaignStatus,\n Contact,\n DeleteContactInput,\n DeleteContactResult,\n ExitResult,\n FindContactsInput,\n HogsendOptions,\n Identity,\n IngestResult,\n ListSummary,\n SendCampaignInput,\n SendCampaignResult,\n SendEmailInput,\n SendEmailResult,\n SendEventInput,\n SubscribeInput,\n SubscribeResult,\n UnsubscribeResult,\n UpsertContactInput,\n UpsertContactResult,\n} from \"./types.js\";\n","/**\n * A non-2xx response — or a transport-level failure — from the Hogsend data\n * plane. `status` is the HTTP status code, or `0` when the request never\n * reached the server (DNS/connect/timeout). `body` is the parsed JSON body when\n * available, else the raw text, else `undefined`.\n */\nexport class HogsendAPIError extends Error {\n readonly status: number;\n readonly body: unknown;\n\n constructor(message: string, status: number, body: unknown) {\n super(message);\n this.name = \"HogsendAPIError\";\n this.status = status;\n this.body = body;\n // Restore prototype chain for instanceof across transpile targets.\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/**\n * A `429 Too Many Requests` response. `retryAfter` is the parsed `Retry-After`\n * header in seconds when present (the server sends it on 429 for `/v1/emails`).\n */\nexport class RateLimitError extends HogsendAPIError {\n readonly retryAfter?: number;\n\n constructor(message: string, body: unknown, retryAfter?: number) {\n super(message, 429, body);\n this.name = \"RateLimitError\";\n this.retryAfter = retryAfter;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n","import { HogsendAPIError, RateLimitError } from \"../errors.js\";\n\n/** Query params accepted by `get` — undefined values are dropped. */\nexport type Query = Record<string, string | number | undefined>;\n\n/** Per-request extras (currently just an idempotency header passthrough). */\nexport interface RequestExtras {\n /** Sent as the `Idempotency-Key` header when set. */\n idempotencyKey?: string;\n}\n\nexport interface HttpClientConfig {\n baseUrl: string;\n apiKey: string;\n fetch?: typeof fetch;\n timeoutMs?: number;\n headers?: Record<string, string>;\n}\n\n/** A minimal, self-contained data-plane HTTP client over native fetch. */\nexport interface HttpClient {\n get<T = unknown>(path: string, query?: Query): Promise<T>;\n post<T = unknown>(\n path: string,\n body: unknown,\n extras?: RequestExtras,\n ): Promise<T>;\n put<T = unknown>(\n path: string,\n body: unknown,\n extras?: RequestExtras,\n ): Promise<T>;\n del<T = unknown>(path: string, body?: unknown): Promise<T>;\n}\n\nconst DEFAULT_TIMEOUT_MS = 30_000;\n\nfunction buildUrl(baseUrl: string, path: string, query?: Query): string {\n const url = new URL(path.startsWith(\"/\") ? path : `/${path}`, `${baseUrl}/`);\n if (query) {\n for (const [key, value] of Object.entries(query)) {\n if (value === undefined) continue;\n url.searchParams.set(key, String(value));\n }\n }\n return url.toString();\n}\n\nfunction bodyMessage(status: number, body: unknown): string {\n if (body && typeof body === \"object\") {\n // Application-handler envelope: `{ error: \"human message\" }`.\n const errField = (body as { error?: unknown }).error;\n if (typeof errField === \"string\") {\n return `${status}: ${errField}`;\n }\n // @hono/zod-openapi default-hook validation envelope:\n // `{ success: false, error: <ZodError> }` (no defaultHook configured). The\n // structured ZodError is preserved on `err.body`; surface a short, readable\n // summary for `err.message` instead of the generic fallback.\n if (\n (body as { success?: unknown }).success === false &&\n errField &&\n typeof errField === \"object\"\n ) {\n const summary = JSON.stringify(errField).slice(0, 200);\n return `${status}: validation failed ${summary}`;\n }\n }\n return `request failed with status ${status}`;\n}\n\n/** Parse a `Retry-After` header (seconds form) into a number, else undefined. */\nfunction parseRetryAfter(value: string | null): number | undefined {\n if (!value) return undefined;\n const seconds = Number.parseInt(value, 10);\n return Number.isFinite(seconds) ? seconds : undefined;\n}\n\n/**\n * Builds an {@link HttpClient} bound to a config. Native `fetch`, JSON in/out,\n * `Authorization: Bearer <apiKey>`. Throws typed errors:\n * - {@link RateLimitError} on 429 (with parsed `Retry-After`),\n * - {@link HogsendAPIError} on any other non-2xx,\n * - {@link HogsendAPIError} with `status === 0` on a transport failure\n * (DNS/connect/abort/timeout).\n */\nexport function createHttpClient(config: HttpClientConfig): HttpClient {\n const doFetch = config.fetch ?? fetch;\n const timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n const extraHeaders = config.headers ?? {};\n\n async function request<T>(\n method: string,\n path: string,\n opts: { query?: Query; body?: unknown; extras?: RequestExtras },\n ): Promise<T> {\n const headers: Record<string, string> = {\n Accept: \"application/json\",\n Authorization: `Bearer ${config.apiKey}`,\n ...extraHeaders,\n };\n if (opts.body !== undefined) {\n headers[\"Content-Type\"] = \"application/json\";\n }\n if (opts.extras?.idempotencyKey) {\n headers[\"Idempotency-Key\"] = opts.extras.idempotencyKey;\n }\n\n const url = buildUrl(config.baseUrl, path, opts.query);\n\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), timeoutMs);\n\n let res: Response;\n try {\n res = await doFetch(url, {\n method,\n headers,\n body: opts.body !== undefined ? JSON.stringify(opts.body) : undefined,\n signal: controller.signal,\n });\n } catch (cause) {\n const msg = cause instanceof Error ? cause.message : String(cause);\n throw new HogsendAPIError(\n `cannot reach ${config.baseUrl} (${msg})`,\n 0,\n undefined,\n );\n } finally {\n clearTimeout(timer);\n }\n\n const text = await res.text();\n let parsed: unknown;\n if (text.length > 0) {\n try {\n parsed = JSON.parse(text);\n } catch {\n parsed = text;\n }\n }\n\n if (!res.ok) {\n if (res.status === 429) {\n throw new RateLimitError(\n bodyMessage(res.status, parsed),\n parsed,\n parseRetryAfter(res.headers.get(\"Retry-After\")),\n );\n }\n throw new HogsendAPIError(\n bodyMessage(res.status, parsed),\n res.status,\n parsed,\n );\n }\n\n return parsed as T;\n }\n\n return {\n get: <T>(path: string, query?: Query) => request<T>(\"GET\", path, { query }),\n post: <T>(path: string, body: unknown, extras?: RequestExtras) =>\n request<T>(\"POST\", path, { body, extras }),\n put: <T>(path: string, body: unknown, extras?: RequestExtras) =>\n request<T>(\"PUT\", path, { body, extras }),\n del: <T>(path: string, body?: unknown) =>\n request<T>(\"DELETE\", path, { body }),\n };\n}\n","import type { HttpClient } from \"../internal/http.js\";\nimport type {\n Campaign,\n SendCampaignInput,\n SendCampaignResult,\n} from \"../types.js\";\n\n/** The `campaigns.*` resource bound to an {@link HttpClient}. */\nexport class CampaignsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Queue a broadcast: durably send one template to every subscribed member of\n * a `list` (or every active member of a `bucket`). Exactly one of `list` /\n * `bucket` must be set; `template`/`props` are type-checked against the\n * augmented `TemplateRegistryMap` when `@hogsend/email` is installed, else\n * degrade to `{ template: string; props? }`.\n *\n * Returns the 202 enqueue ack (`{ campaignId, status }`); the actual sends run\n * asynchronously in the worker. Poll {@link CampaignsResource.get} for counts.\n */\n send(input: SendCampaignInput): Promise<SendCampaignResult> {\n // The discriminated union narrows `template`/`props` and the audience; index\n // into the input via a permissive view to build the wire body without\n // re-discriminating.\n const body = input as SendCampaignInput & {\n list?: string;\n bucket?: string;\n props?: Record<string, unknown>;\n };\n return this.http.post<SendCampaignResult>(\"/v1/campaigns\", {\n name: body.name,\n list: body.list,\n bucket: body.bucket,\n template: body.template,\n props: body.props,\n from: body.from,\n subject: body.subject,\n });\n }\n\n /** Fetch a campaign's current status + send counts. */\n get(id: string): Promise<Campaign> {\n return this.http.get<Campaign>(`/v1/campaigns/${encodeURIComponent(id)}`);\n }\n}\n","/**\n * Runtime guard mirroring the `Identity` union: at least one of `email` /\n * `userId` must be a non-empty string. The type system enforces this at the\n * call site, but runtime callers (plain JS, untyped data) can still violate it,\n * so we fail fast with a clear message before issuing the request.\n */\nexport function assertIdentity(input: {\n email?: string;\n userId?: string;\n}): void {\n const hasEmail = typeof input.email === \"string\" && input.email.length > 0;\n const hasUserId = typeof input.userId === \"string\" && input.userId.length > 0;\n if (!hasEmail && !hasUserId) {\n throw new TypeError(\n \"Hogsend: an identity is required — pass `email`, `userId`, or both.\",\n );\n }\n}\n","import type { HttpClient } from \"../internal/http.js\";\nimport { assertIdentity } from \"../internal/identity.js\";\nimport type {\n Contact,\n DeleteContactInput,\n DeleteContactResult,\n FindContactsInput,\n UpsertContactInput,\n UpsertContactResult,\n} from \"../types.js\";\n\n/** The `contacts.*` resource bound to an {@link HttpClient}. */\nexport class ContactsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Upsert a contact by identity. Resolves/merges server-side and optionally\n * applies list membership. Returns `{ id, created, linked }`.\n */\n async upsert(input: UpsertContactInput): Promise<UpsertContactResult> {\n assertIdentity(input);\n return this.http.put<UpsertContactResult>(\"/v1/contacts\", {\n email: input.email,\n userId: input.userId,\n properties: input.properties,\n lists: input.lists,\n });\n }\n\n /** Find non-deleted contacts by `email` or `userId`. */\n async find(input: FindContactsInput): Promise<Contact[]> {\n const query: Record<string, string | undefined> = {\n email: \"email\" in input ? input.email : undefined,\n userId: \"userId\" in input ? input.userId : undefined,\n };\n const res = await this.http.get<{ contacts: Contact[] }>(\n \"/v1/contacts/find\",\n query,\n );\n return res.contacts;\n }\n\n /** Soft-delete a contact by identity. */\n async delete(input: DeleteContactInput): Promise<DeleteContactResult> {\n assertIdentity(input);\n return this.http.del<DeleteContactResult>(\"/v1/contacts\", {\n email: input.email,\n userId: input.userId,\n });\n }\n}\n","import type { HttpClient } from \"../internal/http.js\";\nimport type { SendEmailInput, SendEmailResult } from \"../types.js\";\n\n/** The `emails.*` resource bound to an {@link HttpClient}. */\nexport class EmailsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Send a transactional email by template. Recipient is `to` (raw address) or\n * `userId` (resolved server-side). `template`/`props` are type-checked against\n * the augmented `TemplateRegistryMap` when `@hogsend/email` is installed,\n * else degrade to `{ template: string; props? }`.\n */\n send(input: SendEmailInput): Promise<SendEmailResult> {\n // The discriminated union narrows `template`/`props`; index into the input\n // via a permissive view to build the wire body without re-discriminating.\n const body = input as SendEmailInput & {\n props?: Record<string, unknown>;\n };\n return this.http.post<SendEmailResult>(\n \"/v1/emails\",\n {\n to: body.to,\n userId: body.userId,\n template: body.template,\n props: body.props,\n from: body.from,\n subject: body.subject,\n replyTo: body.replyTo,\n category: body.category,\n skipPreferenceCheck: body.skipPreferenceCheck,\n idempotencyKey: body.idempotencyKey,\n },\n body.idempotencyKey ? { idempotencyKey: body.idempotencyKey } : undefined,\n );\n }\n}\n","import type { HttpClient } from \"../internal/http.js\";\nimport { assertIdentity } from \"../internal/identity.js\";\nimport type { IngestResult, SendEventInput } from \"../types.js\";\n\n/** The `events.*` resource bound to an {@link HttpClient}. */\nexport class EventsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Send an event through the ingestion pipeline. The two property bags are\n * kept distinct: `eventProperties` feed `trigger.where`/`exitOn`,\n * `contactProperties` merge onto the contact. Optionally apply list\n * membership. Returns the ingest result (stored + exit evaluations).\n *\n * `idempotencyKey` is sent both as the `Idempotency-Key` header (which wins\n * server-side) and in the body, matching `POST /v1/events`.\n */\n send(input: SendEventInput): Promise<IngestResult> {\n assertIdentity(input);\n return this.http.post<IngestResult>(\n \"/v1/events\",\n {\n name: input.name,\n email: input.email,\n userId: input.userId,\n eventProperties: input.eventProperties,\n contactProperties: input.contactProperties,\n lists: input.lists,\n idempotencyKey: input.idempotencyKey,\n },\n input.idempotencyKey\n ? { idempotencyKey: input.idempotencyKey }\n : undefined,\n );\n }\n\n /** Alias of {@link EventsResource.send}. */\n track(input: SendEventInput): Promise<IngestResult> {\n return this.send(input);\n }\n}\n","import type { HttpClient } from \"../internal/http.js\";\nimport { assertIdentity } from \"../internal/identity.js\";\nimport type {\n ListSummary,\n SubscribeInput,\n SubscribeResult,\n UnsubscribeResult,\n} from \"../types.js\";\n\n/** The `lists.*` resource bound to an {@link HttpClient}. */\nexport class ListsResource {\n constructor(private readonly http: HttpClient) {}\n\n /** List all code-defined lists. */\n async list(): Promise<ListSummary[]> {\n const res = await this.http.get<{ lists: ListSummary[] }>(\"/v1/lists\");\n return res.lists;\n }\n\n /** Subscribe an identity to a list. */\n async subscribe(input: SubscribeInput): Promise<SubscribeResult> {\n assertIdentity(input);\n const res = await this.http.post<{ list: string; subscribed: boolean }>(\n `/v1/lists/${encodeURIComponent(input.list)}/subscribe`,\n { email: input.email, userId: input.userId },\n );\n return { subscribed: res.subscribed };\n }\n\n /** Unsubscribe an identity from a list. */\n async unsubscribe(input: SubscribeInput): Promise<UnsubscribeResult> {\n assertIdentity(input);\n const res = await this.http.post<{ list: string; subscribed: boolean }>(\n `/v1/lists/${encodeURIComponent(input.list)}/unsubscribe`,\n { email: input.email, userId: input.userId },\n );\n return { unsubscribed: res.subscribed === false };\n }\n}\n","import { createHttpClient } from \"./internal/http.js\";\nimport { CampaignsResource } from \"./resources/campaigns.js\";\nimport { ContactsResource } from \"./resources/contacts.js\";\nimport { EmailsResource } from \"./resources/emails.js\";\nimport { EventsResource } from \"./resources/events.js\";\nimport { ListsResource } from \"./resources/lists.js\";\nimport type { HogsendOptions } from \"./types.js\";\n\n/**\n * Typed HTTP client for the Hogsend data plane.\n *\n * ```ts\n * const hs = new Hogsend({ baseUrl: \"https://api.example.com\", apiKey: \"hsk_…\" });\n * await hs.contacts.upsert({ email: \"a@b.com\", properties: { plan: \"pro\" } });\n * await hs.events.send({ userId: \"u_1\", name: \"signup\" });\n * ```\n */\nexport class Hogsend {\n readonly contacts: ContactsResource;\n readonly events: EventsResource;\n readonly emails: EmailsResource;\n readonly lists: ListsResource;\n readonly campaigns: CampaignsResource;\n\n constructor(opts: HogsendOptions) {\n if (!opts.baseUrl) {\n throw new TypeError(\"Hogsend: `baseUrl` is required.\");\n }\n if (!opts.apiKey) {\n throw new TypeError(\"Hogsend: `apiKey` is required.\");\n }\n\n const http = createHttpClient({\n baseUrl: opts.baseUrl.replace(/\\/+$/, \"\"),\n apiKey: opts.apiKey,\n fetch: opts.fetch,\n timeoutMs: opts.timeoutMs,\n headers: opts.headers,\n });\n\n this.contacts = new ContactsResource(http);\n this.events = new EventsResource(http);\n this.emails = new EmailsResource(http);\n this.lists = new ListsResource(http);\n this.campaigns = new CampaignsResource(http);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMO,IAAM,kBAAN,cAA8B,MAAM;AAAA,EAChC;AAAA,EACA;AAAA,EAET,YAAY,SAAiB,QAAgB,MAAe;AAC1D,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,OAAO;AAEZ,WAAO,eAAe,MAAM,WAAW,SAAS;AAAA,EAClD;AACF;AAMO,IAAM,iBAAN,cAA6B,gBAAgB;AAAA,EACzC;AAAA,EAET,YAAY,SAAiB,MAAe,YAAq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AM,OAAO;AAAA,IAC7C;AACA,WAAO,EAAE,cAAc,IAAI,eAAe,MAAM;AAAA,EAClD;AACF;;;ACrBO,IAAM,UAAN,MAAc;AAAA,EACV;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY,MAAsB;AAChC,QAAI,CAAC,KAAK,SAAS;AACjB,YAAM,IAAI,UAAU,iCAAiC;AAAA,IACvD;AACA,QAAI,CAAC,KAAK,QAAQ;AAChB,YAAM,IAAI,UAAU,gCAAgC;AAAA,IACtD;AAEA,UAAM,OAAO,iBAAiB;AAAA,MAC5B,SAAS,KAAK,QAAQ,QAAQ,QAAQ,EAAE;AAAA,MACxC,QAAQ,KAAK;AAAA,MACb,OAAO,KAAK;AAAA,MACZ,WAAW,KAAK;AAAA,MAChB,SAAS,KAAK;AAAA,IAChB,CAAC;AAED,SAAK,WAAW,IAAI,iBAAiB,IAAI;AACzC,SAAK,SAAS,IAAI,eAAe,IAAI;AACrC,SAAK,SAAS,IAAI,eAAe,IAAI;AACrC,SAAK,QAAQ,IAAI,cAAc,IAAI;AACnC,SAAK,YAAY,IAAI,kBAAkB,IAAI;AAAA,EAC7C;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/internal/http.ts","../src/resources/campaigns.ts","../src/internal/identity.ts","../src/resources/contacts.ts","../src/resources/emails.ts","../src/resources/events.ts","../src/resources/lists.ts","../src/resources/webhooks.ts","../src/hogsend.ts","../src/internal/verify.ts"],"sourcesContent":["export { HogsendAPIError, RateLimitError } from \"./errors.js\";\nexport { Hogsend } from \"./hogsend.js\";\nexport { verifyHogsendWebhook } from \"./internal/verify.js\";\nexport type {\n Campaign,\n CampaignAudienceKind,\n CampaignStatus,\n Contact,\n CreatedWebhookEndpoint,\n CreateWebhookInput,\n DeleteContactInput,\n DeleteContactResult,\n ExitResult,\n FindContactsInput,\n HogsendOptions,\n Identity,\n IngestResult,\n ListSummary,\n OutboundEventType,\n RotateWebhookSecretResult,\n SendCampaignInput,\n SendCampaignResult,\n SendEmailInput,\n SendEmailResult,\n SendEventInput,\n SubscribeInput,\n SubscribeResult,\n UnsubscribeResult,\n UpdateWebhookInput,\n UpsertContactInput,\n UpsertContactResult,\n WebhookEndpoint,\n} from \"./types.js\";\n","/**\n * A non-2xx response — or a transport-level failure — from the Hogsend data\n * plane. `status` is the HTTP status code, or `0` when the request never\n * reached the server (DNS/connect/timeout). `body` is the parsed JSON body when\n * available, else the raw text, else `undefined`.\n */\nexport class HogsendAPIError extends Error {\n readonly status: number;\n readonly body: unknown;\n\n constructor(message: string, status: number, body: unknown) {\n super(message);\n this.name = \"HogsendAPIError\";\n this.status = status;\n this.body = body;\n // Restore prototype chain for instanceof across transpile targets.\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/**\n * A `429 Too Many Requests` response. `retryAfter` is the parsed `Retry-After`\n * header in seconds when present (the server sends it on 429 for `/v1/emails`).\n */\nexport class RateLimitError extends HogsendAPIError {\n readonly retryAfter?: number;\n\n constructor(message: string, body: unknown, retryAfter?: number) {\n super(message, 429, body);\n this.name = \"RateLimitError\";\n this.retryAfter = retryAfter;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n","import { HogsendAPIError, RateLimitError } from \"../errors.js\";\n\n/** Query params accepted by `get` — undefined values are dropped. */\nexport type Query = Record<string, string | number | undefined>;\n\n/** Per-request extras (currently just an idempotency header passthrough). */\nexport interface RequestExtras {\n /** Sent as the `Idempotency-Key` header when set. */\n idempotencyKey?: string;\n}\n\nexport interface HttpClientConfig {\n baseUrl: string;\n apiKey: string;\n fetch?: typeof fetch;\n timeoutMs?: number;\n headers?: Record<string, string>;\n}\n\n/** A minimal, self-contained data-plane HTTP client over native fetch. */\nexport interface HttpClient {\n get<T = unknown>(path: string, query?: Query): Promise<T>;\n post<T = unknown>(\n path: string,\n body: unknown,\n extras?: RequestExtras,\n ): Promise<T>;\n put<T = unknown>(\n path: string,\n body: unknown,\n extras?: RequestExtras,\n ): Promise<T>;\n patch<T = unknown>(\n path: string,\n body: unknown,\n extras?: RequestExtras,\n ): Promise<T>;\n del<T = unknown>(path: string, body?: unknown): Promise<T>;\n}\n\nconst DEFAULT_TIMEOUT_MS = 30_000;\n\nfunction buildUrl(baseUrl: string, path: string, query?: Query): string {\n const url = new URL(path.startsWith(\"/\") ? path : `/${path}`, `${baseUrl}/`);\n if (query) {\n for (const [key, value] of Object.entries(query)) {\n if (value === undefined) continue;\n url.searchParams.set(key, String(value));\n }\n }\n return url.toString();\n}\n\nfunction bodyMessage(status: number, body: unknown): string {\n if (body && typeof body === \"object\") {\n // Application-handler envelope: `{ error: \"human message\" }`.\n const errField = (body as { error?: unknown }).error;\n if (typeof errField === \"string\") {\n return `${status}: ${errField}`;\n }\n // @hono/zod-openapi default-hook validation envelope:\n // `{ success: false, error: <ZodError> }` (no defaultHook configured). The\n // structured ZodError is preserved on `err.body`; surface a short, readable\n // summary for `err.message` instead of the generic fallback.\n if (\n (body as { success?: unknown }).success === false &&\n errField &&\n typeof errField === \"object\"\n ) {\n const summary = JSON.stringify(errField).slice(0, 200);\n return `${status}: validation failed ${summary}`;\n }\n }\n return `request failed with status ${status}`;\n}\n\n/** Parse a `Retry-After` header (seconds form) into a number, else undefined. */\nfunction parseRetryAfter(value: string | null): number | undefined {\n if (!value) return undefined;\n const seconds = Number.parseInt(value, 10);\n return Number.isFinite(seconds) ? seconds : undefined;\n}\n\n/**\n * Builds an {@link HttpClient} bound to a config. Native `fetch`, JSON in/out,\n * `Authorization: Bearer <apiKey>`. Throws typed errors:\n * - {@link RateLimitError} on 429 (with parsed `Retry-After`),\n * - {@link HogsendAPIError} on any other non-2xx,\n * - {@link HogsendAPIError} with `status === 0` on a transport failure\n * (DNS/connect/abort/timeout).\n */\nexport function createHttpClient(config: HttpClientConfig): HttpClient {\n const doFetch = config.fetch ?? fetch;\n const timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n const extraHeaders = config.headers ?? {};\n\n async function request<T>(\n method: string,\n path: string,\n opts: { query?: Query; body?: unknown; extras?: RequestExtras },\n ): Promise<T> {\n const headers: Record<string, string> = {\n Accept: \"application/json\",\n Authorization: `Bearer ${config.apiKey}`,\n ...extraHeaders,\n };\n if (opts.body !== undefined) {\n headers[\"Content-Type\"] = \"application/json\";\n }\n if (opts.extras?.idempotencyKey) {\n headers[\"Idempotency-Key\"] = opts.extras.idempotencyKey;\n }\n\n const url = buildUrl(config.baseUrl, path, opts.query);\n\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), timeoutMs);\n\n let res: Response;\n try {\n res = await doFetch(url, {\n method,\n headers,\n body: opts.body !== undefined ? JSON.stringify(opts.body) : undefined,\n signal: controller.signal,\n });\n } catch (cause) {\n const msg = cause instanceof Error ? cause.message : String(cause);\n throw new HogsendAPIError(\n `cannot reach ${config.baseUrl} (${msg})`,\n 0,\n undefined,\n );\n } finally {\n clearTimeout(timer);\n }\n\n const text = await res.text();\n let parsed: unknown;\n if (text.length > 0) {\n try {\n parsed = JSON.parse(text);\n } catch {\n parsed = text;\n }\n }\n\n if (!res.ok) {\n if (res.status === 429) {\n throw new RateLimitError(\n bodyMessage(res.status, parsed),\n parsed,\n parseRetryAfter(res.headers.get(\"Retry-After\")),\n );\n }\n throw new HogsendAPIError(\n bodyMessage(res.status, parsed),\n res.status,\n parsed,\n );\n }\n\n return parsed as T;\n }\n\n return {\n get: <T>(path: string, query?: Query) => request<T>(\"GET\", path, { query }),\n post: <T>(path: string, body: unknown, extras?: RequestExtras) =>\n request<T>(\"POST\", path, { body, extras }),\n put: <T>(path: string, body: unknown, extras?: RequestExtras) =>\n request<T>(\"PUT\", path, { body, extras }),\n patch: <T>(path: string, body: unknown, extras?: RequestExtras) =>\n request<T>(\"PATCH\", path, { body, extras }),\n del: <T>(path: string, body?: unknown) =>\n request<T>(\"DELETE\", path, { body }),\n };\n}\n","import type { HttpClient } from \"../internal/http.js\";\nimport type {\n Campaign,\n SendCampaignInput,\n SendCampaignResult,\n} from \"../types.js\";\n\n/** The `campaigns.*` resource bound to an {@link HttpClient}. */\nexport class CampaignsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Queue a broadcast: durably send one template to every subscribed member of\n * a `list` (or every active member of a `bucket`). Exactly one of `list` /\n * `bucket` must be set; `template`/`props` are type-checked against the\n * augmented `TemplateRegistryMap` when `@hogsend/email` is installed, else\n * degrade to `{ template: string; props? }`.\n *\n * Returns the 202 enqueue ack (`{ campaignId, status }`); the actual sends run\n * asynchronously in the worker. Poll {@link CampaignsResource.get} for counts.\n */\n send(input: SendCampaignInput): Promise<SendCampaignResult> {\n // The discriminated union narrows `template`/`props` and the audience; index\n // into the input via a permissive view to build the wire body without\n // re-discriminating.\n const body = input as SendCampaignInput & {\n list?: string;\n bucket?: string;\n props?: Record<string, unknown>;\n };\n return this.http.post<SendCampaignResult>(\"/v1/campaigns\", {\n name: body.name,\n list: body.list,\n bucket: body.bucket,\n template: body.template,\n props: body.props,\n from: body.from,\n subject: body.subject,\n });\n }\n\n /** Fetch a campaign's current status + send counts. */\n get(id: string): Promise<Campaign> {\n return this.http.get<Campaign>(`/v1/campaigns/${encodeURIComponent(id)}`);\n }\n}\n","/**\n * Runtime guard mirroring the `Identity` union: at least one of `email` /\n * `userId` must be a non-empty string. The type system enforces this at the\n * call site, but runtime callers (plain JS, untyped data) can still violate it,\n * so we fail fast with a clear message before issuing the request.\n */\nexport function assertIdentity(input: {\n email?: string;\n userId?: string;\n}): void {\n const hasEmail = typeof input.email === \"string\" && input.email.length > 0;\n const hasUserId = typeof input.userId === \"string\" && input.userId.length > 0;\n if (!hasEmail && !hasUserId) {\n throw new TypeError(\n \"Hogsend: an identity is required — pass `email`, `userId`, or both.\",\n );\n }\n}\n","import type { HttpClient } from \"../internal/http.js\";\nimport { assertIdentity } from \"../internal/identity.js\";\nimport type {\n Contact,\n DeleteContactInput,\n DeleteContactResult,\n FindContactsInput,\n UpsertContactInput,\n UpsertContactResult,\n} from \"../types.js\";\n\n/** The `contacts.*` resource bound to an {@link HttpClient}. */\nexport class ContactsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Upsert a contact by identity. Resolves/merges server-side and optionally\n * applies list membership. Returns `{ id, created, linked }`.\n */\n async upsert(input: UpsertContactInput): Promise<UpsertContactResult> {\n assertIdentity(input);\n return this.http.put<UpsertContactResult>(\"/v1/contacts\", {\n email: input.email,\n userId: input.userId,\n properties: input.properties,\n lists: input.lists,\n });\n }\n\n /** Find non-deleted contacts by `email` or `userId`. */\n async find(input: FindContactsInput): Promise<Contact[]> {\n const query: Record<string, string | undefined> = {\n email: \"email\" in input ? input.email : undefined,\n userId: \"userId\" in input ? input.userId : undefined,\n };\n const res = await this.http.get<{ contacts: Contact[] }>(\n \"/v1/contacts/find\",\n query,\n );\n return res.contacts;\n }\n\n /** Soft-delete a contact by identity. */\n async delete(input: DeleteContactInput): Promise<DeleteContactResult> {\n assertIdentity(input);\n return this.http.del<DeleteContactResult>(\"/v1/contacts\", {\n email: input.email,\n userId: input.userId,\n });\n }\n}\n","import type { HttpClient } from \"../internal/http.js\";\nimport type { SendEmailInput, SendEmailResult } from \"../types.js\";\n\n/** The `emails.*` resource bound to an {@link HttpClient}. */\nexport class EmailsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Send a transactional email by template. Recipient is `to` (raw address) or\n * `userId` (resolved server-side). `template`/`props` are type-checked against\n * the augmented `TemplateRegistryMap` when `@hogsend/email` is installed,\n * else degrade to `{ template: string; props? }`.\n */\n send(input: SendEmailInput): Promise<SendEmailResult> {\n // The discriminated union narrows `template`/`props`; index into the input\n // via a permissive view to build the wire body without re-discriminating.\n const body = input as SendEmailInput & {\n props?: Record<string, unknown>;\n };\n return this.http.post<SendEmailResult>(\n \"/v1/emails\",\n {\n to: body.to,\n userId: body.userId,\n template: body.template,\n props: body.props,\n from: body.from,\n subject: body.subject,\n replyTo: body.replyTo,\n category: body.category,\n skipPreferenceCheck: body.skipPreferenceCheck,\n idempotencyKey: body.idempotencyKey,\n },\n body.idempotencyKey ? { idempotencyKey: body.idempotencyKey } : undefined,\n );\n }\n}\n","import type { HttpClient } from \"../internal/http.js\";\nimport { assertIdentity } from \"../internal/identity.js\";\nimport type { IngestResult, SendEventInput } from \"../types.js\";\n\n/** The `events.*` resource bound to an {@link HttpClient}. */\nexport class EventsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Send an event through the ingestion pipeline. The two property bags are\n * kept distinct: `eventProperties` feed `trigger.where`/`exitOn`,\n * `contactProperties` merge onto the contact. Optionally apply list\n * membership. Returns the ingest result (stored + exit evaluations).\n *\n * `idempotencyKey` is sent both as the `Idempotency-Key` header (which wins\n * server-side) and in the body, matching `POST /v1/events`.\n */\n send(input: SendEventInput): Promise<IngestResult> {\n assertIdentity(input);\n return this.http.post<IngestResult>(\n \"/v1/events\",\n {\n name: input.name,\n email: input.email,\n userId: input.userId,\n eventProperties: input.eventProperties,\n contactProperties: input.contactProperties,\n lists: input.lists,\n idempotencyKey: input.idempotencyKey,\n },\n input.idempotencyKey\n ? { idempotencyKey: input.idempotencyKey }\n : undefined,\n );\n }\n\n /** Alias of {@link EventsResource.send}. */\n track(input: SendEventInput): Promise<IngestResult> {\n return this.send(input);\n }\n}\n","import type { HttpClient } from \"../internal/http.js\";\nimport { assertIdentity } from \"../internal/identity.js\";\nimport type {\n ListSummary,\n SubscribeInput,\n SubscribeResult,\n UnsubscribeResult,\n} from \"../types.js\";\n\n/** The `lists.*` resource bound to an {@link HttpClient}. */\nexport class ListsResource {\n constructor(private readonly http: HttpClient) {}\n\n /** List all code-defined lists. */\n async list(): Promise<ListSummary[]> {\n const res = await this.http.get<{ lists: ListSummary[] }>(\"/v1/lists\");\n return res.lists;\n }\n\n /** Subscribe an identity to a list. */\n async subscribe(input: SubscribeInput): Promise<SubscribeResult> {\n assertIdentity(input);\n const res = await this.http.post<{ list: string; subscribed: boolean }>(\n `/v1/lists/${encodeURIComponent(input.list)}/subscribe`,\n { email: input.email, userId: input.userId },\n );\n return { subscribed: res.subscribed };\n }\n\n /** Unsubscribe an identity from a list. */\n async unsubscribe(input: SubscribeInput): Promise<UnsubscribeResult> {\n assertIdentity(input);\n const res = await this.http.post<{ list: string; subscribed: boolean }>(\n `/v1/lists/${encodeURIComponent(input.list)}/unsubscribe`,\n { email: input.email, userId: input.userId },\n );\n return { unsubscribed: res.subscribed === false };\n }\n}\n","import type { HttpClient } from \"../internal/http.js\";\nimport type {\n CreatedWebhookEndpoint,\n CreateWebhookInput,\n RotateWebhookSecretResult,\n UpdateWebhookInput,\n WebhookEndpoint,\n} from \"../types.js\";\n\nconst BASE = \"/v1/admin/webhooks\";\n\n/**\n * The `webhooks.*` resource — manage outbound webhook endpoints (the\n * Svix-style signed event stream Hogsend emits to subscriber URLs).\n *\n * IMPORTANT: unlike the rest of the client (which uses an `ingest`-scoped data\n * key), this resource targets the ADMIN plane (`/v1/admin/webhooks`) and\n * REQUIRES a full-admin key. Signing-secret management is the same trust class\n * as API-key management — a leaked ingest key must never register an\n * exfiltration endpoint. Construct the client with an admin `apiKey`.\n *\n * The full signing `secret` (`whsec_…`) is returned ONCE — on\n * {@link WebhooksResource.create} and {@link WebhooksResource.rotateSecret}.\n * `list`/`get` only ever expose the display `secretPrefix`. Store it on create.\n */\nexport class WebhooksResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Register a new endpoint subscribed to one or more outbound event types.\n * For the default kind=\"webhook\", returns the endpoint INCLUDING the full\n * signing `secret` — the only time (besides rotate) it is returned; store it\n * now. For a keyed destination (e.g. `{ kind: \"posthog\", config: { apiKey } }`)\n * no secret is returned (it authenticates via `config`).\n */\n create(input: CreateWebhookInput): Promise<CreatedWebhookEndpoint> {\n return this.http.post<CreatedWebhookEndpoint>(BASE, {\n url: input.url,\n eventTypes: input.eventTypes,\n description: input.description,\n disabled: input.disabled,\n kind: input.kind,\n config: input.config,\n });\n }\n\n /**\n * List endpoints (newest first). Disabled endpoints are hidden unless\n * `includeDisabled` is set. Returns the endpoints array (unwrapped from the\n * `{ endpoints, total, limit, offset }` envelope).\n */\n async list(opts?: {\n limit?: number;\n offset?: number;\n includeDisabled?: boolean;\n }): Promise<WebhookEndpoint[]> {\n const res = await this.http.get<{ endpoints: WebhookEndpoint[] }>(BASE, {\n limit: opts?.limit,\n offset: opts?.offset,\n includeDisabled:\n opts?.includeDisabled === undefined\n ? undefined\n : String(opts.includeDisabled),\n });\n return res.endpoints;\n }\n\n /** Fetch one endpoint by id (404 → {@link HogsendAPIError}). */\n get(id: string): Promise<WebhookEndpoint> {\n return this.http.get<WebhookEndpoint>(`${BASE}/${encodeURIComponent(id)}`);\n }\n\n /**\n * Patch an endpoint. Only the provided fields change; `description: null`\n * clears the description. Does NOT return or rotate the secret.\n */\n update(id: string, input: UpdateWebhookInput): Promise<WebhookEndpoint> {\n return this.http.patch<WebhookEndpoint>(\n `${BASE}/${encodeURIComponent(id)}`,\n {\n url: input.url,\n eventTypes: input.eventTypes,\n description: input.description,\n disabled: input.disabled,\n kind: input.kind,\n config: input.config,\n },\n );\n }\n\n /** Hard-delete an endpoint (cascade drops its deliveries). */\n delete(id: string): Promise<{ deleted: boolean }> {\n return this.http.del<{ deleted: boolean }>(\n `${BASE}/${encodeURIComponent(id)}`,\n );\n }\n\n /**\n * Rotate the signing secret. The OLD secret is invalidated immediately (hard\n * cutover) — update every subscriber with the returned new `secret` (returned\n * ONCE).\n */\n rotateSecret(id: string): Promise<RotateWebhookSecretResult> {\n return this.http.post<RotateWebhookSecretResult>(\n `${BASE}/${encodeURIComponent(id)}/rotate-secret`,\n {},\n );\n }\n\n /**\n * Enqueue an out-of-band `webhook.test` delivery to the endpoint, delivered\n * regardless of its subscribed `eventTypes`. Returns the 202 enqueue ack.\n */\n sendTest(\n id: string,\n ): Promise<{ enqueued: boolean; eventType: \"webhook.test\" }> {\n return this.http.post<{ enqueued: boolean; eventType: \"webhook.test\" }>(\n `${BASE}/${encodeURIComponent(id)}/test`,\n {},\n );\n }\n}\n","import { createHttpClient } from \"./internal/http.js\";\nimport { CampaignsResource } from \"./resources/campaigns.js\";\nimport { ContactsResource } from \"./resources/contacts.js\";\nimport { EmailsResource } from \"./resources/emails.js\";\nimport { EventsResource } from \"./resources/events.js\";\nimport { ListsResource } from \"./resources/lists.js\";\nimport { WebhooksResource } from \"./resources/webhooks.js\";\nimport type { HogsendOptions } from \"./types.js\";\n\n/**\n * Typed HTTP client for the Hogsend data plane.\n *\n * ```ts\n * const hs = new Hogsend({ baseUrl: \"https://api.example.com\", apiKey: \"hsk_…\" });\n * await hs.contacts.upsert({ email: \"a@b.com\", properties: { plan: \"pro\" } });\n * await hs.events.send({ userId: \"u_1\", name: \"signup\" });\n * ```\n */\nexport class Hogsend {\n readonly contacts: ContactsResource;\n readonly events: EventsResource;\n readonly emails: EmailsResource;\n readonly lists: ListsResource;\n readonly campaigns: CampaignsResource;\n /**\n * Manage outbound webhook endpoints (the signed event stream Hogsend emits to\n * subscriber URLs). REQUIRES a full-admin `apiKey` — this resource hits the\n * admin plane (`/v1/admin/webhooks`), NOT the ingest data plane the other\n * resources use. See {@link WebhooksResource}.\n */\n readonly webhooks: WebhooksResource;\n\n constructor(opts: HogsendOptions) {\n if (!opts.baseUrl) {\n throw new TypeError(\"Hogsend: `baseUrl` is required.\");\n }\n if (!opts.apiKey) {\n throw new TypeError(\"Hogsend: `apiKey` is required.\");\n }\n\n const http = createHttpClient({\n baseUrl: opts.baseUrl.replace(/\\/+$/, \"\"),\n apiKey: opts.apiKey,\n fetch: opts.fetch,\n timeoutMs: opts.timeoutMs,\n headers: opts.headers,\n });\n\n this.contacts = new ContactsResource(http);\n this.events = new EventsResource(http);\n this.emails = new EmailsResource(http);\n this.lists = new ListsResource(http);\n this.campaigns = new CampaignsResource(http);\n this.webhooks = new WebhooksResource(http);\n }\n}\n","import { createHmac, timingSafeEqual } from \"node:crypto\";\nimport { Webhook } from \"svix\";\n\n/** Default tolerance (seconds) for the timestamp freshness check. */\nconst TOLERANCE_SECONDS = 5 * 60;\n\n/**\n * Lowercase every header key so callers can pass the Title-Case headers Hogsend\n * sends (`Webhook-Id`/`Webhook-Timestamp`/`Webhook-Signature`) OR the lowercase\n * form a framework may hand back. Svix expects lowercase `svix-*`/`webhook-*`.\n */\nfunction normalizeHeaders(\n headers: Record<string, string>,\n): Record<string, string> {\n const out: Record<string, string> = {};\n for (const [key, value] of Object.entries(headers)) {\n out[key.toLowerCase()] = value;\n }\n return out;\n}\n\n/**\n * Verify and parse an INBOUND Hogsend outbound-webhook delivery, the\n * subscriber-side counterpart of the engine's signing. Use this in a handler\n * that receives Hogsend's signed POSTs to confirm authenticity before trusting\n * the body.\n *\n * Pass the RAW request body bytes (the exact string Hogsend signed — never a\n * re-stringified object), the request headers, and the endpoint's `whsec_…`\n * signing secret (from create / rotate-secret). Returns the parsed event\n * envelope (`{ id, type, timestamp, data }`) on success.\n *\n * Throws on a bad signature, a missing signature header, or a timestamp outside\n * the 5-minute tolerance window.\n *\n * Implementation: wraps svix's `Webhook.verify` (constant-time, tolerance-\n * checked); if svix cannot run for any reason it falls back to a pure\n * `node:crypto` HMAC-SHA256 check over `${id}.${timestamp}.${body}` with a\n * `timingSafeEqual` compare against the `v1,<base64>` signature(s).\n *\n * @example\n * ```ts\n * import { verifyHogsendWebhook } from \"@hogsend/client\";\n *\n * app.post(\"/webhooks/hogsend\", async (req, res) => {\n * const body = await readRawBody(req); // the exact bytes\n * try {\n * const event = verifyHogsendWebhook({\n * payload: body,\n * headers: req.headers,\n * secret: process.env.HOGSEND_WEBHOOK_SECRET!,\n * });\n * // handle event.type ...\n * res.sendStatus(200);\n * } catch {\n * res.sendStatus(401);\n * }\n * });\n * ```\n */\nexport function verifyHogsendWebhook(opts: {\n payload: string;\n headers: Record<string, string>;\n secret: string;\n}): unknown {\n const headers = normalizeHeaders(opts.headers);\n const id = headers[\"webhook-id\"] ?? headers[\"svix-id\"];\n const timestamp = headers[\"webhook-timestamp\"] ?? headers[\"svix-timestamp\"];\n const signature = headers[\"webhook-signature\"] ?? headers[\"svix-signature\"];\n\n if (!id || !timestamp || !signature) {\n throw new Error(\n \"verifyHogsendWebhook: missing Webhook-Id / Webhook-Timestamp / Webhook-Signature header\",\n );\n }\n\n try {\n const wh = new Webhook(opts.secret);\n return wh.verify(opts.payload, {\n \"svix-id\": id,\n \"svix-timestamp\": timestamp,\n \"svix-signature\": signature,\n });\n } catch {\n // svix unavailable (tree-shaken) or threw — fall back to node:crypto. We\n // re-run the SAME canonical check so a genuine signature/timestamp failure\n // still throws; only a svix-internal/import failure is \"rescued\".\n return verifyWithNodeCrypto({\n payload: opts.payload,\n secret: opts.secret,\n id,\n timestamp,\n signature,\n });\n }\n}\n\n/**\n * Pure `node:crypto` verification of the Svix signature scheme. Mirrors the\n * documented fallback in the engine's webhook-signing lib:\n * `HMAC_SHA256(base64-decoded secret, `${id}.${ts}.${body}`)` → `v1,<base64>`,\n * `timingSafeEqual` against each space-separated signature in the header.\n */\nfunction verifyWithNodeCrypto(opts: {\n payload: string;\n secret: string;\n id: string;\n timestamp: string;\n signature: string;\n}): unknown {\n const ts = Number.parseInt(opts.timestamp, 10);\n if (!Number.isFinite(ts)) {\n throw new Error(\"verifyHogsendWebhook: invalid Webhook-Timestamp\");\n }\n const now = Math.floor(Date.now() / 1000);\n if (Math.abs(now - ts) > TOLERANCE_SECONDS) {\n throw new Error(\"verifyHogsendWebhook: timestamp outside tolerance window\");\n }\n\n // The secret is `whsec_<base64>`; the signing key is the base64-decoded body.\n const key = opts.secret.startsWith(\"whsec_\")\n ? Buffer.from(opts.secret.slice(6), \"base64\")\n : Buffer.from(opts.secret, \"base64\");\n const signedContent = `${opts.id}.${opts.timestamp}.${opts.payload}`;\n const expected = createHmac(\"sha256\", key)\n .update(signedContent)\n .digest(\"base64\");\n const expectedBuf = Buffer.from(expected);\n\n // The header is space-separated `v1,<sig>` pairs; accept if ANY matches.\n const matched = opts.signature.split(\" \").some((part) => {\n const sig = part.startsWith(\"v1,\") ? part.slice(3) : part;\n const candidate = Buffer.from(sig);\n return (\n candidate.length === expectedBuf.length &&\n timingSafeEqual(candidate, expectedBuf)\n );\n });\n\n if (!matched) {\n throw new Error(\"verifyHogsendWebhook: signature verification failed\");\n }\n\n return JSON.parse(opts.payload);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACMO,IAAM,kBAAN,cAA8B,MAAM;AAAA,EAChC;AAAA,EACA;AAAA,EAET,YAAY,SAAiB,QAAgB,MAAe;AAC1D,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,OAAO;AAEZ,WAAO,eAAe,MAAM,WAAW,SAAS;AAAA,EAClD;AACF;AAMO,IAAM,iBAAN,cAA6B,gBAAgB;AAAA,EACzC;AAAA,EAET,YAAY,SAAiB,MAAe,YAAqB;AAC/D,UAAM,SAAS,KAAK,IAAI;AACxB,SAAK,OAAO;AACZ,SAAK,aAAa;AAClB,WAAO,eAAe,MAAM,WAAW,SAAS;AAAA,EAClD;AACF;;;ACOA,IAAM,qBAAqB;AAE3B,SAAS,SAAS,SAAiB,MAAc,OAAuB;AACtE,QAAM,MAAM,IAAI,IAAI,KAAK,WAAW,GAAG,IAAI,OAAO,IAAI,IAAI,IAAI,GAAG,OAAO,GAAG;AAC3E,MAAI,OAAO;AACT,eAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,KAAK,GAAG;AAChD,UAAI,UAAU,OAAW;AACzB,UAAI,aAAa,IAAI,KAAK,OAAO,KAAK,CAAC;AAAA,IACzC;AAAA,EACF;AACA,SAAO,IAAI,SAAS;AACtB;AAEA,SAAS,YAAY,QAAgB,MAAuB;AAC1D,MAAI,QAAQ,OAAO,SAAS,UAAU;AAEpC,UAAM,WAAY,KAA6B;AAC/C,QAAI,OAAO,aAAa,UAAU;AAChC,aAAO,GAAG,MAAM,KAAK,QAAQ;AAAA,IAC/B;AAKA,QACG,KAA+B,YAAY,SAC5C,YACA,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ttpClient {
32
32
  get<T = unknown>(path: string, query?: Query): Promise<T>;
33
33
  post<T = unknown>(path: string, body: unknown, extras?: RequestExtras): Promise<T>;
34
34
  put<T = unknown>(path: string, body: unknown, extras?: RequestExtras): Promise<T>;
35
+ patch<T = unknown>(path: string, body: unknown, extras?: RequestExtras): Promise<T>;
35
36
  del<T = unknown>(path: string, body?: unknown): Promise<T>;
36
37
  }
37
38
 
@@ -161,6 +162,99 @@ interface SubscribeResult {
161
162
  interface UnsubscribeResult {
162
163
  unsubscribed: boolean;
163
164
  }
165
+ /**
166
+ * The 13-event outbound catalog. MIRRORS the engine's `WEBHOOK_EVENT_TYPES`
167
+ * (`@hogsend/engine` lib/webhook-signing.ts) — the client cannot import the
168
+ * engine, so the union is re-declared here and MUST be kept in sync BY HAND
169
+ * when the engine catalog changes (there is no automated drift check today).
170
+ * The `webhook.test` sentinel is NOT a member (out-of-band).
171
+ */
172
+ type OutboundEventType = "contact.created" | "contact.updated" | "contact.deleted" | "contact.unsubscribed" | "email.sent" | "email.delivered" | "email.opened" | "email.clicked" | "email.bounced" | "email.complained" | "journey.completed" | "bucket.entered" | "bucket.left";
173
+ /**
174
+ * The delivery `kind` of a managed endpoint. `"webhook"` (default) is the signed
175
+ * Standard-Webhooks POST; any other value (e.g. `"posthog"`, `"segment"`,
176
+ * `"slack"`) is a keyed destination delivered via a server-side transform
177
+ * adapter. The named members mirror the engine's SHIPPED destination presets
178
+ * (`PRESET_DESTINATIONS`) — the same set the admin API now accepts as `kind` —
179
+ * for editor autocomplete; the `(string & {})` arm keeps the union open to
180
+ * consumer-defined kinds (`defineDestination`) and future presets.
181
+ */
182
+ type WebhookKind = "webhook" | "posthog" | "segment" | "slack" | (string & {});
183
+ /**
184
+ * A managed outbound webhook endpoint as returned by `/v1/admin/webhooks` list
185
+ * + get. NEVER carries the full signing `secret` — only its display
186
+ * `secretPrefix`. The full secret is returned exactly once, on create and
187
+ * rotate-secret, as {@link CreatedWebhookEndpoint} / {@link RotateWebhookSecretResult}.
188
+ */
189
+ interface WebhookEndpoint {
190
+ id: string;
191
+ url: string;
192
+ description: string | null;
193
+ eventTypes: OutboundEventType[];
194
+ /**
195
+ * Safe-to-display prefix, e.g. `whsec_AbCd`. The full secret is never here.
196
+ * Null for keyed destinations (kind !== "webhook"), which carry no secret.
197
+ */
198
+ secretPrefix: string | null;
199
+ /** Delivery kind — "webhook" (signed POST) or a keyed destination. */
200
+ kind: WebhookKind;
201
+ /**
202
+ * Per-destination config for keyed adapters, with credentials REDACTED by the
203
+ * server (e.g. `config.apiKey` → "***"). Null for kind="webhook".
204
+ */
205
+ config: Record<string, unknown> | null;
206
+ status: "enabled" | "disabled";
207
+ organizationId: string | null;
208
+ /** ISO string of the last delivery attempt, or null if never delivered. */
209
+ lastDeliveryAt: string | null;
210
+ createdAt: string;
211
+ updatedAt: string;
212
+ }
213
+ /**
214
+ * The create / rotate response: a {@link WebhookEndpoint} PLUS the full signing
215
+ * `secret` (`whsec_…`). Returned ONCE — store it now, it is never recoverable
216
+ * from list/get. `secret` is present ONLY for kind="webhook" (keyed
217
+ * destinations carry no secret), hence optional.
218
+ */
219
+ type CreatedWebhookEndpoint = WebhookEndpoint & {
220
+ secret?: string;
221
+ };
222
+ /** Body for `hs.webhooks.create`. At least one event type is required. */
223
+ interface CreateWebhookInput {
224
+ url: string;
225
+ eventTypes: OutboundEventType[];
226
+ description?: string;
227
+ disabled?: boolean;
228
+ /**
229
+ * Delivery kind. Defaults to "webhook" (the signed POST). Set to a keyed
230
+ * destination (e.g. "posthog") to fan out via a server-side transform.
231
+ */
232
+ kind?: WebhookKind;
233
+ /**
234
+ * Per-destination config for keyed adapters, e.g. PostHog's
235
+ * `{ apiKey, host }`. Ignored for kind="webhook".
236
+ */
237
+ config?: Record<string, unknown>;
238
+ }
239
+ /**
240
+ * Body for `hs.webhooks.update` (PATCH semantics — only provided fields change).
241
+ * `description: null` clears the description.
242
+ */
243
+ interface UpdateWebhookInput {
244
+ url?: string;
245
+ eventTypes?: OutboundEventType[];
246
+ description?: string | null;
247
+ disabled?: boolean;
248
+ kind?: WebhookKind;
249
+ /** Replace the keyed-destination config; `null` clears it. */
250
+ config?: Record<string, unknown> | null;
251
+ }
252
+ /** Result of `hs.webhooks.rotateSecret` — the NEW full secret, returned once. */
253
+ interface RotateWebhookSecretResult {
254
+ id: string;
255
+ secret: string;
256
+ secretPrefix: string;
257
+ }
164
258
  /**
165
259
  * `true` when `TemplateRegistryMap` carries no augmented keys (consumer has not
166
260
  * declared their templates). `[keyof TemplateRegistryMap] extends [never]` is
@@ -314,6 +408,68 @@ declare class ListsResource {
314
408
  unsubscribe(input: SubscribeInput): Promise<UnsubscribeResult>;
315
409
  }
316
410
 
411
+ /**
412
+ * The `webhooks.*` resource — manage outbound webhook endpoints (the
413
+ * Svix-style signed event stream Hogsend emits to subscriber URLs).
414
+ *
415
+ * IMPORTANT: unlike the rest of the client (which uses an `ingest`-scoped data
416
+ * key), this resource targets the ADMIN plane (`/v1/admin/webhooks`) and
417
+ * REQUIRES a full-admin key. Signing-secret management is the same trust class
418
+ * as API-key management — a leaked ingest key must never register an
419
+ * exfiltration endpoint. Construct the client with an admin `apiKey`.
420
+ *
421
+ * The full signing `secret` (`whsec_…`) is returned ONCE — on
422
+ * {@link WebhooksResource.create} and {@link WebhooksResource.rotateSecret}.
423
+ * `list`/`get` only ever expose the display `secretPrefix`. Store it on create.
424
+ */
425
+ declare class WebhooksResource {
426
+ private readonly http;
427
+ constructor(http: HttpClient);
428
+ /**
429
+ * Register a new endpoint subscribed to one or more outbound event types.
430
+ * For the default kind="webhook", returns the endpoint INCLUDING the full
431
+ * signing `secret` — the only time (besides rotate) it is returned; store it
432
+ * now. For a keyed destination (e.g. `{ kind: "posthog", config: { apiKey } }`)
433
+ * no secret is returned (it authenticates via `config`).
434
+ */
435
+ create(input: CreateWebhookInput): Promise<CreatedWebhookEndpoint>;
436
+ /**
437
+ * List endpoints (newest first). Disabled endpoints are hidden unless
438
+ * `includeDisabled` is set. Returns the endpoints array (unwrapped from the
439
+ * `{ endpoints, total, limit, offset }` envelope).
440
+ */
441
+ list(opts?: {
442
+ limit?: number;
443
+ offset?: number;
444
+ includeDisabled?: boolean;
445
+ }): Promise<WebhookEndpoint[]>;
446
+ /** Fetch one endpoint by id (404 → {@link HogsendAPIError}). */
447
+ get(id: string): Promise<WebhookEndpoint>;
448
+ /**
449
+ * Patch an endpoint. Only the provided fields change; `description: null`
450
+ * clears the description. Does NOT return or rotate the secret.
451
+ */
452
+ update(id: string, input: UpdateWebhookInput): Promise<WebhookEndpoint>;
453
+ /** Hard-delete an endpoint (cascade drops its deliveries). */
454
+ delete(id: string): Promise<{
455
+ deleted: boolean;
456
+ }>;
457
+ /**
458
+ * Rotate the signing secret. The OLD secret is invalidated immediately (hard
459
+ * cutover) — update every subscriber with the returned new `secret` (returned
460
+ * ONCE).
461
+ */
462
+ rotateSecret(id: string): Promise<RotateWebhookSecretResult>;
463
+ /**
464
+ * Enqueue an out-of-band `webhook.test` delivery to the endpoint, delivered
465
+ * regardless of its subscribed `eventTypes`. Returns the 202 enqueue ack.
466
+ */
467
+ sendTest(id: string): Promise<{
468
+ enqueued: boolean;
469
+ eventType: "webhook.test";
470
+ }>;
471
+ }
472
+
317
473
  /**
318
474
  * Typed HTTP client for the Hogsend data plane.
319
475
  *
@@ -329,7 +485,59 @@ declare class Hogsend {
329
485
  readonly emails: EmailsResource;
330
486
  readonly lists: ListsResource;
331
487
  readonly campaigns: CampaignsResource;
488
+ /**
489
+ * Manage outbound webhook endpoints (the signed event stream Hogsend emits to
490
+ * subscriber URLs). REQUIRES a full-admin `apiKey` — this resource hits the
491
+ * admin plane (`/v1/admin/webhooks`), NOT the ingest data plane the other
492
+ * resources use. See {@link WebhooksResource}.
493
+ */
494
+ readonly webhooks: WebhooksResource;
332
495
  constructor(opts: HogsendOptions);
333
496
  }
334
497
 
335
- export { type Campaign, type CampaignAudienceKind, type CampaignStatus, type Contact, type DeleteContactInput, type DeleteContactResult, type ExitResult, type FindContactsInput, Hogsend, HogsendAPIError, type HogsendOptions, type Identity, type IngestResult, type ListSummary, RateLimitError, type SendCampaignInput, type SendCampaignResult, type SendEmailInput, type SendEmailResult, type SendEventInput, type SubscribeInput, type SubscribeResult, type UnsubscribeResult, type UpsertContactInput, type UpsertContactResult };
498
+ /**
499
+ * Verify and parse an INBOUND Hogsend outbound-webhook delivery, the
500
+ * subscriber-side counterpart of the engine's signing. Use this in a handler
501
+ * that receives Hogsend's signed POSTs to confirm authenticity before trusting
502
+ * the body.
503
+ *
504
+ * Pass the RAW request body bytes (the exact string Hogsend signed — never a
505
+ * re-stringified object), the request headers, and the endpoint's `whsec_…`
506
+ * signing secret (from create / rotate-secret). Returns the parsed event
507
+ * envelope (`{ id, type, timestamp, data }`) on success.
508
+ *
509
+ * Throws on a bad signature, a missing signature header, or a timestamp outside
510
+ * the 5-minute tolerance window.
511
+ *
512
+ * Implementation: wraps svix's `Webhook.verify` (constant-time, tolerance-
513
+ * checked); if svix cannot run for any reason it falls back to a pure
514
+ * `node:crypto` HMAC-SHA256 check over `${id}.${timestamp}.${body}` with a
515
+ * `timingSafeEqual` compare against the `v1,<base64>` signature(s).
516
+ *
517
+ * @example
518
+ * ```ts
519
+ * import { verifyHogsendWebhook } from "@hogsend/client";
520
+ *
521
+ * app.post("/webhooks/hogsend", async (req, res) => {
522
+ * const body = await readRawBody(req); // the exact bytes
523
+ * try {
524
+ * const event = verifyHogsendWebhook({
525
+ * payload: body,
526
+ * headers: req.headers,
527
+ * secret: process.env.HOGSEND_WEBHOOK_SECRET!,
528
+ * });
529
+ * // handle event.type ...
530
+ * res.sendStatus(200);
531
+ * } catch {
532
+ * res.sendStatus(401);
533
+ * }
534
+ * });
535
+ * ```
536
+ */
537
+ declare function verifyHogsendWebhook(opts: {
538
+ payload: string;
539
+ headers: Record<string, string>;
540
+ secret: string;
541
+ }): unknown;
542
+
543
+ export { type Campaign, type CampaignAudienceKind, type CampaignStatus, type Contact, type CreateWebhookInput, type CreatedWebhookEndpoint, type DeleteContactInput, type DeleteContactResult, type ExitResult, type FindContactsInput, Hogsend, HogsendAPIError, type HogsendOptions, type Identity, type IngestResult, type ListSummary, type OutboundEventType, RateLimitError, type RotateWebhookSecretResult, type SendCampaignInput, type SendCampaignResult, type SendEmailInput, type SendEmailResult, type SendEventInput, type SubscribeInput, type SubscribeResult, type UnsubscribeResult, type UpdateWebhookInput, type UpsertContactInput, type UpsertContactResult, type WebhookEndpoint, verifyHogsendWebhook };
package/dist/index.d.ts CHANGED
@@ -32,6 +32,7 @@ interface HttpClient {
32
32
  get<T = unknown>(path: string, query?: Query): Promise<T>;
33
33
  post<T = unknown>(path: string, body: unknown, extras?: RequestExtras): Promise<T>;
34
34
  put<T = unknown>(path: string, body: unknown, extras?: RequestExtras): Promise<T>;
35
+ patch<T = unknown>(path: string, body: unknown, extras?: RequestExtras): Promise<T>;
35
36
  del<T = unknown>(path: string, body?: unknown): Promise<T>;
36
37
  }
37
38
 
@@ -161,6 +162,99 @@ interface SubscribeResult {
161
162
  interface UnsubscribeResult {
162
163
  unsubscribed: boolean;
163
164
  }
165
+ /**
166
+ * The 13-event outbound catalog. MIRRORS the engine's `WEBHOOK_EVENT_TYPES`
167
+ * (`@hogsend/engine` lib/webhook-signing.ts) — the client cannot import the
168
+ * engine, so the union is re-declared here and MUST be kept in sync BY HAND
169
+ * when the engine catalog changes (there is no automated drift check today).
170
+ * The `webhook.test` sentinel is NOT a member (out-of-band).
171
+ */
172
+ type OutboundEventType = "contact.created" | "contact.updated" | "contact.deleted" | "contact.unsubscribed" | "email.sent" | "email.delivered" | "email.opened" | "email.clicked" | "email.bounced" | "email.complained" | "journey.completed" | "bucket.entered" | "bucket.left";
173
+ /**
174
+ * The delivery `kind` of a managed endpoint. `"webhook"` (default) is the signed
175
+ * Standard-Webhooks POST; any other value (e.g. `"posthog"`, `"segment"`,
176
+ * `"slack"`) is a keyed destination delivered via a server-side transform
177
+ * adapter. The named members mirror the engine's SHIPPED destination presets
178
+ * (`PRESET_DESTINATIONS`) — the same set the admin API now accepts as `kind` —
179
+ * for editor autocomplete; the `(string & {})` arm keeps the union open to
180
+ * consumer-defined kinds (`defineDestination`) and future presets.
181
+ */
182
+ type WebhookKind = "webhook" | "posthog" | "segment" | "slack" | (string & {});
183
+ /**
184
+ * A managed outbound webhook endpoint as returned by `/v1/admin/webhooks` list
185
+ * + get. NEVER carries the full signing `secret` — only its display
186
+ * `secretPrefix`. The full secret is returned exactly once, on create and
187
+ * rotate-secret, as {@link CreatedWebhookEndpoint} / {@link RotateWebhookSecretResult}.
188
+ */
189
+ interface WebhookEndpoint {
190
+ id: string;
191
+ url: string;
192
+ description: string | null;
193
+ eventTypes: OutboundEventType[];
194
+ /**
195
+ * Safe-to-display prefix, e.g. `whsec_AbCd`. The full secret is never here.
196
+ * Null for keyed destinations (kind !== "webhook"), which carry no secret.
197
+ */
198
+ secretPrefix: string | null;
199
+ /** Delivery kind — "webhook" (signed POST) or a keyed destination. */
200
+ kind: WebhookKind;
201
+ /**
202
+ * Per-destination config for keyed adapters, with credentials REDACTED by the
203
+ * server (e.g. `config.apiKey` → "***"). Null for kind="webhook".
204
+ */
205
+ config: Record<string, unknown> | null;
206
+ status: "enabled" | "disabled";
207
+ organizationId: string | null;
208
+ /** ISO string of the last delivery attempt, or null if never delivered. */
209
+ lastDeliveryAt: string | null;
210
+ createdAt: string;
211
+ updatedAt: string;
212
+ }
213
+ /**
214
+ * The create / rotate response: a {@link WebhookEndpoint} PLUS the full signing
215
+ * `secret` (`whsec_…`). Returned ONCE — store it now, it is never recoverable
216
+ * from list/get. `secret` is present ONLY for kind="webhook" (keyed
217
+ * destinations carry no secret), hence optional.
218
+ */
219
+ type CreatedWebhookEndpoint = WebhookEndpoint & {
220
+ secret?: string;
221
+ };
222
+ /** Body for `hs.webhooks.create`. At least one event type is required. */
223
+ interface CreateWebhookInput {
224
+ url: string;
225
+ eventTypes: OutboundEventType[];
226
+ description?: string;
227
+ disabled?: boolean;
228
+ /**
229
+ * Delivery kind. Defaults to "webhook" (the signed POST). Set to a keyed
230
+ * destination (e.g. "posthog") to fan out via a server-side transform.
231
+ */
232
+ kind?: WebhookKind;
233
+ /**
234
+ * Per-destination config for keyed adapters, e.g. PostHog's
235
+ * `{ apiKey, host }`. Ignored for kind="webhook".
236
+ */
237
+ config?: Record<string, unknown>;
238
+ }
239
+ /**
240
+ * Body for `hs.webhooks.update` (PATCH semantics — only provided fields change).
241
+ * `description: null` clears the description.
242
+ */
243
+ interface UpdateWebhookInput {
244
+ url?: string;
245
+ eventTypes?: OutboundEventType[];
246
+ description?: string | null;
247
+ disabled?: boolean;
248
+ kind?: WebhookKind;
249
+ /** Replace the keyed-destination config; `null` clears it. */
250
+ config?: Record<string, unknown> | null;
251
+ }
252
+ /** Result of `hs.webhooks.rotateSecret` — the NEW full secret, returned once. */
253
+ interface RotateWebhookSecretResult {
254
+ id: string;
255
+ secret: string;
256
+ secretPrefix: string;
257
+ }
164
258
  /**
165
259
  * `true` when `TemplateRegistryMap` carries no augmented keys (consumer has not
166
260
  * declared their templates). `[keyof TemplateRegistryMap] extends [never]` is
@@ -314,6 +408,68 @@ declare class ListsResource {
314
408
  unsubscribe(input: SubscribeInput): Promise<UnsubscribeResult>;
315
409
  }
316
410
 
411
+ /**
412
+ * The `webhooks.*` resource — manage outbound webhook endpoints (the
413
+ * Svix-style signed event stream Hogsend emits to subscriber URLs).
414
+ *
415
+ * IMPORTANT: unlike the rest of the client (which uses an `ingest`-scoped data
416
+ * key), this resource targets the ADMIN plane (`/v1/admin/webhooks`) and
417
+ * REQUIRES a full-admin key. Signing-secret management is the same trust class
418
+ * as API-key management — a leaked ingest key must never register an
419
+ * exfiltration endpoint. Construct the client with an admin `apiKey`.
420
+ *
421
+ * The full signing `secret` (`whsec_…`) is returned ONCE — on
422
+ * {@link WebhooksResource.create} and {@link WebhooksResource.rotateSecret}.
423
+ * `list`/`get` only ever expose the display `secretPrefix`. Store it on create.
424
+ */
425
+ declare class WebhooksResource {
426
+ private readonly http;
427
+ constructor(http: HttpClient);
428
+ /**
429
+ * Register a new endpoint subscribed to one or more outbound event types.
430
+ * For the default kind="webhook", returns the endpoint INCLUDING the full
431
+ * signing `secret` — the only time (besides rotate) it is returned; store it
432
+ * now. For a keyed destination (e.g. `{ kind: "posthog", config: { apiKey } }`)
433
+ * no secret is returned (it authenticates via `config`).
434
+ */
435
+ create(input: CreateWebhookInput): Promise<CreatedWebhookEndpoint>;
436
+ /**
437
+ * List endpoints (newest first). Disabled endpoints are hidden unless
438
+ * `includeDisabled` is set. Returns the endpoints array (unwrapped from the
439
+ * `{ endpoints, total, limit, offset }` envelope).
440
+ */
441
+ list(opts?: {
442
+ limit?: number;
443
+ offset?: number;
444
+ includeDisabled?: boolean;
445
+ }): Promise<WebhookEndpoint[]>;
446
+ /** Fetch one endpoint by id (404 → {@link HogsendAPIError}). */
447
+ get(id: string): Promise<WebhookEndpoint>;
448
+ /**
449
+ * Patch an endpoint. Only the provided fields change; `description: null`
450
+ * clears the description. Does NOT return or rotate the secret.
451
+ */
452
+ update(id: string, input: UpdateWebhookInput): Promise<WebhookEndpoint>;
453
+ /** Hard-delete an endpoint (cascade drops its deliveries). */
454
+ delete(id: string): Promise<{
455
+ deleted: boolean;
456
+ }>;
457
+ /**
458
+ * Rotate the signing secret. The OLD secret is invalidated immediately (hard
459
+ * cutover) — update every subscriber with the returned new `secret` (returned
460
+ * ONCE).
461
+ */
462
+ rotateSecret(id: string): Promise<RotateWebhookSecretResult>;
463
+ /**
464
+ * Enqueue an out-of-band `webhook.test` delivery to the endpoint, delivered
465
+ * regardless of its subscribed `eventTypes`. Returns the 202 enqueue ack.
466
+ */
467
+ sendTest(id: string): Promise<{
468
+ enqueued: boolean;
469
+ eventType: "webhook.test";
470
+ }>;
471
+ }
472
+
317
473
  /**
318
474
  * Typed HTTP client for the Hogsend data plane.
319
475
  *
@@ -329,7 +485,59 @@ declare class Hogsend {
329
485
  readonly emails: EmailsResource;
330
486
  readonly lists: ListsResource;
331
487
  readonly campaigns: CampaignsResource;
488
+ /**
489
+ * Manage outbound webhook endpoints (the signed event stream Hogsend emits to
490
+ * subscriber URLs). REQUIRES a full-admin `apiKey` — this resource hits the
491
+ * admin plane (`/v1/admin/webhooks`), NOT the ingest data plane the other
492
+ * resources use. See {@link WebhooksResource}.
493
+ */
494
+ readonly webhooks: WebhooksResource;
332
495
  constructor(opts: HogsendOptions);
333
496
  }
334
497
 
335
- export { type Campaign, type CampaignAudienceKind, type CampaignStatus, type Contact, type DeleteContactInput, type DeleteContactResult, type ExitResult, type FindContactsInput, Hogsend, HogsendAPIError, type HogsendOptions, type Identity, type IngestResult, type ListSummary, RateLimitError, type SendCampaignInput, type SendCampaignResult, type SendEmailInput, type SendEmailResult, type SendEventInput, type SubscribeInput, type SubscribeResult, type UnsubscribeResult, type UpsertContactInput, type UpsertContactResult };
498
+ /**
499
+ * Verify and parse an INBOUND Hogsend outbound-webhook delivery, the
500
+ * subscriber-side counterpart of the engine's signing. Use this in a handler
501
+ * that receives Hogsend's signed POSTs to confirm authenticity before trusting
502
+ * the body.
503
+ *
504
+ * Pass the RAW request body bytes (the exact string Hogsend signed — never a
505
+ * re-stringified object), the request headers, and the endpoint's `whsec_…`
506
+ * signing secret (from create / rotate-secret). Returns the parsed event
507
+ * envelope (`{ id, type, timestamp, data }`) on success.
508
+ *
509
+ * Throws on a bad signature, a missing signature header, or a timestamp outside
510
+ * the 5-minute tolerance window.
511
+ *
512
+ * Implementation: wraps svix's `Webhook.verify` (constant-time, tolerance-
513
+ * checked); if svix cannot run for any reason it falls back to a pure
514
+ * `node:crypto` HMAC-SHA256 check over `${id}.${timestamp}.${body}` with a
515
+ * `timingSafeEqual` compare against the `v1,<base64>` signature(s).
516
+ *
517
+ * @example
518
+ * ```ts
519
+ * import { verifyHogsendWebhook } from "@hogsend/client";
520
+ *
521
+ * app.post("/webhooks/hogsend", async (req, res) => {
522
+ * const body = await readRawBody(req); // the exact bytes
523
+ * try {
524
+ * const event = verifyHogsendWebhook({
525
+ * payload: body,
526
+ * headers: req.headers,
527
+ * secret: process.env.HOGSEND_WEBHOOK_SECRET!,
528
+ * });
529
+ * // handle event.type ...
530
+ * res.sendStatus(200);
531
+ * } catch {
532
+ * res.sendStatus(401);
533
+ * }
534
+ * });
535
+ * ```
536
+ */
537
+ declare function verifyHogsendWebhook(opts: {
538
+ payload: string;
539
+ headers: Record<string, string>;
540
+ secret: string;
541
+ }): unknown;
542
+
543
+ export { type Campaign, type CampaignAudienceKind, type CampaignStatus, type Contact, type CreateWebhookInput, type CreatedWebhookEndpoint, type DeleteContactInput, type DeleteContactResult, type ExitResult, type FindContactsInput, Hogsend, HogsendAPIError, type HogsendOptions, type Identity, type IngestResult, type ListSummary, type OutboundEventType, RateLimitError, type RotateWebhookSecretResult, type SendCampaignInput, type SendCampaignResult, type SendEmailInput, type SendEmailResult, type SendEventInput, type SubscribeInput, type SubscribeResult, type UnsubscribeResult, type UpdateWebhookInput, type UpsertContactInput, type UpsertContactResult, type WebhookEndpoint, verifyHogsendWebhook };
package/dist/index.js CHANGED
@@ -116,6 +116,7 @@ function createHttpClient(config) {
116
116
  get: (path, query) => request("GET", path, { query }),
117
117
  post: (path, body, extras) => request("POST", path, { body, extras }),
118
118
  put: (path, body, extras) => request("PUT", path, { body, extras }),
119
+ patch: (path, body, extras) => request("PATCH", path, { body, extras }),
119
120
  del: (path, body) => request("DELETE", path, { body })
120
121
  };
121
122
  }
@@ -307,6 +308,93 @@ var ListsResource = class {
307
308
  }
308
309
  };
309
310
 
311
+ // src/resources/webhooks.ts
312
+ var BASE = "/v1/admin/webhooks";
313
+ var WebhooksResource = class {
314
+ constructor(http) {
315
+ this.http = http;
316
+ }
317
+ http;
318
+ /**
319
+ * Register a new endpoint subscribed to one or more outbound event types.
320
+ * For the default kind="webhook", returns the endpoint INCLUDING the full
321
+ * signing `secret` — the only time (besides rotate) it is returned; store it
322
+ * now. For a keyed destination (e.g. `{ kind: "posthog", config: { apiKey } }`)
323
+ * no secret is returned (it authenticates via `config`).
324
+ */
325
+ create(input) {
326
+ return this.http.post(BASE, {
327
+ url: input.url,
328
+ eventTypes: input.eventTypes,
329
+ description: input.description,
330
+ disabled: input.disabled,
331
+ kind: input.kind,
332
+ config: input.config
333
+ });
334
+ }
335
+ /**
336
+ * List endpoints (newest first). Disabled endpoints are hidden unless
337
+ * `includeDisabled` is set. Returns the endpoints array (unwrapped from the
338
+ * `{ endpoints, total, limit, offset }` envelope).
339
+ */
340
+ async list(opts) {
341
+ const res = await this.http.get(BASE, {
342
+ limit: opts?.limit,
343
+ offset: opts?.offset,
344
+ includeDisabled: opts?.includeDisabled === void 0 ? void 0 : String(opts.includeDisabled)
345
+ });
346
+ return res.endpoints;
347
+ }
348
+ /** Fetch one endpoint by id (404 → {@link HogsendAPIError}). */
349
+ get(id) {
350
+ return this.http.get(`${BASE}/${encodeURIComponent(id)}`);
351
+ }
352
+ /**
353
+ * Patch an endpoint. Only the provided fields change; `description: null`
354
+ * clears the description. Does NOT return or rotate the secret.
355
+ */
356
+ update(id, input) {
357
+ return this.http.patch(
358
+ `${BASE}/${encodeURIComponent(id)}`,
359
+ {
360
+ url: input.url,
361
+ eventTypes: input.eventTypes,
362
+ description: input.description,
363
+ disabled: input.disabled,
364
+ kind: input.kind,
365
+ config: input.config
366
+ }
367
+ );
368
+ }
369
+ /** Hard-delete an endpoint (cascade drops its deliveries). */
370
+ delete(id) {
371
+ return this.http.del(
372
+ `${BASE}/${encodeURIComponent(id)}`
373
+ );
374
+ }
375
+ /**
376
+ * Rotate the signing secret. The OLD secret is invalidated immediately (hard
377
+ * cutover) — update every subscriber with the returned new `secret` (returned
378
+ * ONCE).
379
+ */
380
+ rotateSecret(id) {
381
+ return this.http.post(
382
+ `${BASE}/${encodeURIComponent(id)}/rotate-secret`,
383
+ {}
384
+ );
385
+ }
386
+ /**
387
+ * Enqueue an out-of-band `webhook.test` delivery to the endpoint, delivered
388
+ * regardless of its subscribed `eventTypes`. Returns the 202 enqueue ack.
389
+ */
390
+ sendTest(id) {
391
+ return this.http.post(
392
+ `${BASE}/${encodeURIComponent(id)}/test`,
393
+ {}
394
+ );
395
+ }
396
+ };
397
+
310
398
  // src/hogsend.ts
311
399
  var Hogsend = class {
312
400
  contacts;
@@ -314,6 +402,13 @@ var Hogsend = class {
314
402
  emails;
315
403
  lists;
316
404
  campaigns;
405
+ /**
406
+ * Manage outbound webhook endpoints (the signed event stream Hogsend emits to
407
+ * subscriber URLs). REQUIRES a full-admin `apiKey` — this resource hits the
408
+ * admin plane (`/v1/admin/webhooks`), NOT the ingest data plane the other
409
+ * resources use. See {@link WebhooksResource}.
410
+ */
411
+ webhooks;
317
412
  constructor(opts) {
318
413
  if (!opts.baseUrl) {
319
414
  throw new TypeError("Hogsend: `baseUrl` is required.");
@@ -333,11 +428,75 @@ var Hogsend = class {
333
428
  this.emails = new EmailsResource(http);
334
429
  this.lists = new ListsResource(http);
335
430
  this.campaigns = new CampaignsResource(http);
431
+ this.webhooks = new WebhooksResource(http);
336
432
  }
337
433
  };
434
+
435
+ // src/internal/verify.ts
436
+ import { createHmac, timingSafeEqual } from "crypto";
437
+ import { Webhook } from "svix";
438
+ var TOLERANCE_SECONDS = 5 * 60;
439
+ function normalizeHeaders(headers) {
440
+ const out = {};
441
+ for (const [key, value] of Object.entries(headers)) {
442
+ out[key.toLowerCase()] = value;
443
+ }
444
+ return out;
445
+ }
446
+ function verifyHogsendWebhook(opts) {
447
+ const headers = normalizeHeaders(opts.headers);
448
+ const id = headers["webhook-id"] ?? headers["svix-id"];
449
+ const timestamp = headers["webhook-timestamp"] ?? headers["svix-timestamp"];
450
+ const signature = headers["webhook-signature"] ?? headers["svix-signature"];
451
+ if (!id || !timestamp || !signature) {
452
+ throw new Error(
453
+ "verifyHogsendWebhook: missing Webhook-Id / Webhook-Timestamp / Webhook-Signature header"
454
+ );
455
+ }
456
+ try {
457
+ const wh = new Webhook(opts.secret);
458
+ return wh.verify(opts.payload, {
459
+ "svix-id": id,
460
+ "svix-timestamp": timestamp,
461
+ "svix-signature": signature
462
+ });
463
+ } catch {
464
+ return verifyWithNodeCrypto({
465
+ payload: opts.payload,
466
+ secret: opts.secret,
467
+ id,
468
+ timestamp,
469
+ signature
470
+ });
471
+ }
472
+ }
473
+ function verifyWithNodeCrypto(opts) {
474
+ const ts = Number.parseInt(opts.timestamp, 10);
475
+ if (!Number.isFinite(ts)) {
476
+ throw new Error("verifyHogsendWebhook: invalid Webhook-Timestamp");
477
+ }
478
+ const now = Math.floor(Date.now() / 1e3);
479
+ if (Math.abs(now - ts) > TOLERANCE_SECONDS) {
480
+ throw new Error("verifyHogsendWebhook: timestamp outside tolerance window");
481
+ }
482
+ const key = opts.secret.startsWith("whsec_") ? Buffer.from(opts.secret.slice(6), "base64") : Buffer.from(opts.secret, "base64");
483
+ const signedContent = `${opts.id}.${opts.timestamp}.${opts.payload}`;
484
+ const expected = createHmac("sha256", key).update(signedContent).digest("base64");
485
+ const expectedBuf = Buffer.from(expected);
486
+ const matched = opts.signature.split(" ").some((part) => {
487
+ const sig = part.startsWith("v1,") ? part.slice(3) : part;
488
+ const candidate = Buffer.from(sig);
489
+ return candidate.length === expectedBuf.length && timingSafeEqual(candidate, expectedBuf);
490
+ });
491
+ if (!matched) {
492
+ throw new Error("verifyHogsendWebhook: signature verification failed");
493
+ }
494
+ return JSON.parse(opts.payload);
495
+ }
338
496
  export {
339
497
  Hogsend,
340
498
  HogsendAPIError,
341
- RateLimitError
499
+ RateLimitError,
500
+ verifyHogsendWebhook
342
501
  };
343
502
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/errors.ts","../src/internal/http.ts","../src/resources/campaigns.ts","../src/internal/identity.ts","../src/resources/contacts.ts","../src/resources/emails.ts","../src/resources/events.ts","../src/resources/lists.ts","../src/hogsend.ts"],"sourcesContent":["/**\n * A non-2xx response — or a transport-level failure — from the Hogsend data\n * plane. `status` is the HTTP status code, or `0` when the request never\n * reached the server (DNS/connect/timeout). `body` is the parsed JSON body when\n * available, else the raw text, else `undefined`.\n */\nexport class HogsendAPIError extends Error {\n readonly status: number;\n readonly body: unknown;\n\n constructor(message: string, status: number, body: unknown) {\n super(message);\n this.name = \"HogsendAPIError\";\n this.status = status;\n this.body = body;\n // Restore prototype chain for instanceof across transpile targets.\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/**\n * A `429 Too Many Requests` response. `retryAfter` is the parsed `Retry-After`\n * header in seconds when present (the server sends it on 429 for `/v1/emails`).\n */\nexport class RateLimitError extends HogsendAPIError {\n readonly retryAfter?: number;\n\n constructor(message: string, body: unknown, retryAfter?: number) {\n super(message, 429, body);\n this.name = \"RateLimitError\";\n this.retryAfter = retryAfter;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n","import { HogsendAPIError, RateLimitError } from \"../errors.js\";\n\n/** Query params accepted by `get` — undefined values are dropped. */\nexport type Query = Record<string, string | number | undefined>;\n\n/** Per-request extras (currently just an idempotency header passthrough). */\nexport interface RequestExtras {\n /** Sent as the `Idempotency-Key` header when set. */\n idempotencyKey?: string;\n}\n\nexport interface HttpClientConfig {\n baseUrl: string;\n apiKey: string;\n fetch?: typeof fetch;\n timeoutMs?: number;\n headers?: Record<string, string>;\n}\n\n/** A minimal, self-contained data-plane HTTP client over native fetch. */\nexport interface HttpClient {\n get<T = unknown>(path: string, query?: Query): Promise<T>;\n post<T = unknown>(\n path: string,\n body: unknown,\n extras?: RequestExtras,\n ): Promise<T>;\n put<T = unknown>(\n path: string,\n body: unknown,\n extras?: RequestExtras,\n ): Promise<T>;\n del<T = unknown>(path: string, body?: unknown): Promise<T>;\n}\n\nconst DEFAULT_TIMEOUT_MS = 30_000;\n\nfunction buildUrl(baseUrl: string, path: string, query?: Query): string {\n const url = new URL(path.startsWith(\"/\") ? path : `/${path}`, `${baseUrl}/`);\n if (query) {\n for (const [key, value] of Object.entries(query)) {\n if (value === undefined) continue;\n url.searchParams.set(key, String(value));\n }\n }\n return url.toString();\n}\n\nfunction bodyMessage(status: number, body: unknown): string {\n if (body && typeof body === \"object\") {\n // Application-handler envelope: `{ error: \"human message\" }`.\n const errField = (body as { error?: unknown }).error;\n if (typeof errField === \"string\") {\n return `${status}: ${errField}`;\n }\n // @hono/zod-openapi default-hook validation envelope:\n // `{ success: false, error: <ZodError> }` (no defaultHook configured). The\n // structured ZodError is preserved on `err.body`; surface a short, readable\n // summary for `err.message` instead of the generic fallback.\n if (\n (body as { success?: unknown }).success === false &&\n errField &&\n typeof errField === \"object\"\n ) {\n const summary = JSON.stringify(errField).slice(0, 200);\n return `${status}: validation failed ${summary}`;\n }\n }\n return `request failed with status ${status}`;\n}\n\n/** Parse a `Retry-After` header (seconds form) into a number, else undefined. */\nfunction parseRetryAfter(value: string | null): number | undefined {\n if (!value) return undefined;\n const seconds = Number.parseInt(value, 10);\n return Number.isFinite(seconds) ? seconds : undefined;\n}\n\n/**\n * Builds an {@link HttpClient} bound to a config. Native `fetch`, JSON in/out,\n * `Authorization: Bearer <apiKey>`. Throws typed errors:\n * - {@link RateLimitError} on 429 (with parsed `Retry-After`),\n * - {@link HogsendAPIError} on any other non-2xx,\n * - {@link HogsendAPIError} with `status === 0` on a transport failure\n * (DNS/connect/abort/timeout).\n */\nexport function createHttpClient(config: HttpClientConfig): HttpClient {\n const doFetch = config.fetch ?? fetch;\n const timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n const extraHeaders = config.headers ?? {};\n\n async function request<T>(\n method: string,\n path: string,\n opts: { query?: Query; body?: unknown; extras?: RequestExtras },\n ): Promise<T> {\n const headers: Record<string, string> = {\n Accept: \"application/json\",\n Authorization: `Bearer ${config.apiKey}`,\n ...extraHeaders,\n };\n if (opts.body !== undefined) {\n headers[\"Content-Type\"] = \"application/json\";\n }\n if (opts.extras?.idempotencyKey) {\n headers[\"Idempotency-Key\"] = opts.extras.idempotencyKey;\n }\n\n const url = buildUrl(config.baseUrl, path, opts.query);\n\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), timeoutMs);\n\n let res: Response;\n try {\n res = await doFetch(url, {\n method,\n headers,\n body: opts.body !== undefined ? JSON.stringify(opts.body) : undefined,\n signal: controller.signal,\n });\n } catch (cause) {\n const msg = cause instanceof Error ? cause.message : String(cause);\n throw new HogsendAPIError(\n `cannot reach ${config.baseUrl} (${msg})`,\n 0,\n undefined,\n );\n } finally {\n clearTimeout(timer);\n }\n\n const text = await res.text();\n let parsed: unknown;\n if (text.length > 0) {\n try {\n parsed = JSON.parse(text);\n } catch {\n parsed = text;\n }\n }\n\n if (!res.ok) {\n if (res.status === 429) {\n throw new RateLimitError(\n bodyMessage(res.status, parsed),\n parsed,\n parseRetryAfter(res.headers.get(\"Retry-After\")),\n );\n }\n throw new HogsendAPIError(\n bodyMessage(res.status, parsed),\n res.status,\n parsed,\n );\n }\n\n return parsed as T;\n }\n\n return {\n get: <T>(path: string, query?: Query) => request<T>(\"GET\", path, { query }),\n post: <T>(path: string, body: unknown, extras?: RequestExtras) =>\n request<T>(\"POST\", path, { body, extras }),\n put: <T>(path: string, body: unknown, extras?: RequestExtras) =>\n request<T>(\"PUT\", path, { body, extras }),\n del: <T>(path: string, body?: unknown) =>\n request<T>(\"DELETE\", path, { body }),\n };\n}\n","import type { HttpClient } from \"../internal/http.js\";\nimport type {\n Campaign,\n SendCampaignInput,\n SendCampaignResult,\n} from \"../types.js\";\n\n/** The `campaigns.*` resource bound to an {@link HttpClient}. */\nexport class CampaignsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Queue a broadcast: durably send one template to every subscribed member of\n * a `list` (or every active member of a `bucket`). Exactly one of `list` /\n * `bucket` must be set; `template`/`props` are type-checked against the\n * augmented `TemplateRegistryMap` when `@hogsend/email` is installed, else\n * degrade to `{ template: string; props? }`.\n *\n * Returns the 202 enqueue ack (`{ campaignId, status }`); the actual sends run\n * asynchronously in the worker. Poll {@link CampaignsResource.get} for counts.\n */\n send(input: SendCampaignInput): Promise<SendCampaignResult> {\n // The discriminated union narrows `template`/`props` and the audience; index\n // into the input via a permissive view to build the wire body without\n // re-discriminating.\n const body = input as SendCampaignInput & {\n list?: string;\n bucket?: string;\n props?: Record<string, unknown>;\n };\n return this.http.post<SendCampaignResult>(\"/v1/campaigns\", {\n name: body.name,\n list: body.list,\n bucket: body.bucket,\n template: body.template,\n props: body.props,\n from: body.from,\n subject: body.subject,\n });\n }\n\n /** Fetch a campaign's current status + send counts. */\n get(id: string): Promise<Campaign> {\n return this.http.get<Campaign>(`/v1/campaigns/${encodeURIComponent(id)}`);\n }\n}\n","/**\n * Runtime guard mirroring the `Identity` union: at least one of `email` /\n * `userId` must be a non-empty string. The type system enforces this at the\n * call site, but runtime callers (plain JS, untyped data) can still violate it,\n * so we fail fast with a clear message before issuing the request.\n */\nexport function assertIdentity(input: {\n email?: string;\n userId?: string;\n}): void {\n const hasEmail = typeof input.email === \"string\" && input.email.length > 0;\n const hasUserId = typeof input.userId === \"string\" && input.userId.length > 0;\n if (!hasEmail && !hasUserId) {\n throw new TypeError(\n \"Hogsend: an identity is required — pass `email`, `userId`, or both.\",\n );\n }\n}\n","import type { HttpClient } from \"../internal/http.js\";\nimport { assertIdentity } from \"../internal/identity.js\";\nimport type {\n Contact,\n DeleteContactInput,\n DeleteContactResult,\n FindContactsInput,\n UpsertContactInput,\n UpsertContactResult,\n} from \"../types.js\";\n\n/** The `contacts.*` resource bound to an {@link HttpClient}. */\nexport class ContactsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Upsert a contact by identity. Resolves/merges server-side and optionally\n * applies list membership. Returns `{ id, created, linked }`.\n */\n async upsert(input: UpsertContactInput): Promise<UpsertContactResult> {\n assertIdentity(input);\n return this.http.put<UpsertContactResult>(\"/v1/contacts\", {\n email: input.email,\n userId: input.userId,\n properties: input.properties,\n lists: input.lists,\n });\n }\n\n /** Find non-deleted contacts by `email` or `userId`. */\n async find(input: FindContactsInput): Promise<Contact[]> {\n const query: Record<string, string | undefined> = {\n email: \"email\" in input ? input.email : undefined,\n userId: \"userId\" in input ? input.userId : undefined,\n };\n const res = await this.http.get<{ contacts: Contact[] }>(\n \"/v1/contacts/find\",\n query,\n );\n return res.contacts;\n }\n\n /** Soft-delete a contact by identity. */\n async delete(input: DeleteContactInput): Promise<DeleteContactResult> {\n assertIdentity(input);\n return this.http.del<DeleteContactResult>(\"/v1/contacts\", {\n email: input.email,\n userId: input.userId,\n });\n }\n}\n","import type { HttpClient } from \"../internal/http.js\";\nimport type { SendEmailInput, SendEmailResult } from \"../types.js\";\n\n/** The `emails.*` resource bound to an {@link HttpClient}. */\nexport class EmailsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Send a transactional email by template. Recipient is `to` (raw address) or\n * `userId` (resolved server-side). `template`/`props` are type-checked against\n * the augmented `TemplateRegistryMap` when `@hogsend/email` is installed,\n * else degrade to `{ template: string; props? }`.\n */\n send(input: SendEmailInput): Promise<SendEmailResult> {\n // The discriminated union narrows `template`/`props`; index into the input\n // via a permissive view to build the wire body without re-discriminating.\n const body = input as SendEmailInput & {\n props?: Record<string, unknown>;\n };\n return this.http.post<SendEmailResult>(\n \"/v1/emails\",\n {\n to: body.to,\n userId: body.userId,\n template: body.template,\n props: body.props,\n from: body.from,\n subject: body.subject,\n replyTo: body.replyTo,\n category: body.category,\n skipPreferenceCheck: body.skipPreferenceCheck,\n idempotencyKey: body.idempotencyKey,\n },\n body.idempotencyKey ? { idempotencyKey: body.idempotencyKey } : undefined,\n );\n }\n}\n","import type { HttpClient } from \"../internal/http.js\";\nimport { assertIdentity } from \"../internal/identity.js\";\nimport type { IngestResult, SendEventInput } from \"../types.js\";\n\n/** The `events.*` resource bound to an {@link HttpClient}. */\nexport class EventsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Send an event through the ingestion pipeline. The two property bags are\n * kept distinct: `eventProperties` feed `trigger.where`/`exitOn`,\n * `contactProperties` merge onto the contact. Optionally apply list\n * membership. Returns the ingest result (stored + exit evaluations).\n *\n * `idempotencyKey` is sent both as the `Idempotency-Key` header (which wins\n * server-side) and in the body, matching `POST /v1/events`.\n */\n send(input: SendEventInput): Promise<IngestResult> {\n assertIdentity(input);\n return this.http.post<IngestResult>(\n \"/v1/events\",\n {\n name: input.name,\n email: input.email,\n userId: input.userId,\n eventProperties: input.eventProperties,\n contactProperties: input.contactProperties,\n lists: input.lists,\n idempotencyKey: input.idempotencyKey,\n },\n input.idempotencyKey\n ? { idempotencyKey: input.idempotencyKey }\n : undefined,\n );\n }\n\n /** Alias of {@link EventsResource.send}. */\n track(input: SendEventInput): Promise<IngestResult> {\n return this.send(input);\n }\n}\n","import type { HttpClient } from \"../internal/http.js\";\nimport { assertIdentity } from \"../internal/identity.js\";\nimport type {\n ListSummary,\n SubscribeInput,\n SubscribeResult,\n UnsubscribeResult,\n} from \"../types.js\";\n\n/** The `lists.*` resource bound to an {@link HttpClient}. */\nexport class ListsResource {\n constructor(private readonly http: HttpClient) {}\n\n /** List all code-defined lists. */\n async list(): Promise<ListSummary[]> {\n const res = await this.http.get<{ lists: ListSummary[] }>(\"/v1/lists\");\n return res.lists;\n }\n\n /** Subscribe an identity to a list. */\n async subscribe(input: SubscribeInput): Promise<SubscribeResult> {\n assertIdentity(input);\n const res = await this.http.post<{ list: string; subscribed: boolean }>(\n `/v1/lists/${encodeURIComponent(input.list)}/subscribe`,\n { email: input.email, userId: input.userId },\n );\n return { subscribed: res.subscribed };\n }\n\n /** Unsubscribe an identity from a list. */\n async unsubscribe(input: SubscribeInput): Promise<UnsubscribeResult> {\n assertIdentity(input);\n const res = await this.http.post<{ list: string; subscribed: boolean }>(\n `/v1/lists/${encodeURIComponent(input.list)}/unsubscribe`,\n { email: input.email, userId: input.userId },\n );\n return { unsubscribed: res.subscribed === false };\n }\n}\n","import { createHttpClient } from \"./internal/http.js\";\nimport { CampaignsResource } from \"./resources/campaigns.js\";\nimport { ContactsResource } from \"./resources/contacts.js\";\nimport { EmailsResource } from \"./resources/emails.js\";\nimport { EventsResource } from \"./resources/events.js\";\nimport { ListsResource } from \"./resources/lists.js\";\nimport type { HogsendOptions } from \"./types.js\";\n\n/**\n * Typed HTTP client for the Hogsend data plane.\n *\n * ```ts\n * const hs = new Hogsend({ baseUrl: \"https://api.example.com\", apiKey: \"hsk_…\" });\n * await hs.contacts.upsert({ email: \"a@b.com\", properties: { plan: \"pro\" } });\n * await hs.events.send({ userId: \"u_1\", name: \"signup\" });\n * ```\n */\nexport class Hogsend {\n readonly contacts: ContactsResource;\n readonly events: EventsResource;\n readonly emails: EmailsResource;\n readonly lists: ListsResource;\n readonly campaigns: CampaignsResource;\n\n constructor(opts: HogsendOptions) {\n if (!opts.baseUrl) {\n throw new TypeError(\"Hogsend: `baseUrl` is required.\");\n }\n if (!opts.apiKey) {\n throw new TypeError(\"Hogsend: `apiKey` is required.\");\n }\n\n const http = createHttpClient({\n baseUrl: opts.baseUrl.replace(/\\/+$/, \"\"),\n apiKey: opts.apiKey,\n fetch: opts.fetch,\n timeoutMs: opts.timeoutMs,\n headers: opts.headers,\n });\n\n this.contacts = new ContactsResource(http);\n this.events = new EventsResource(http);\n this.emails = new EmailsResource(http);\n this.lists = new ListsResource(http);\n this.campaigns = new CampaignsResource(http);\n }\n}\n"],"mappings":";AAMO,IAAM,kBAAN,cAA8B,MAAM;AAAA,EAChC;AAAA,EACA;AAAA,EAET,YAAY,SAAiB,QAAgB,MAAe;AAC1D,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,OAAO;AAEZ,WAAO,eAAe,MAAM,WAAW,SAAS;AAAA,EAClD;AACF;AAMO,IAAM,iBAAN,cAA6B,gBAAgB;AAAA,EACzC;AAAA,EAET,YAAY,SAAiB,MAAe,YAAqB;AAC/D,UAAM,SAAS,KAAK,IAAI;AACxB,SAAK,OAAO;AACZ,SAAK,aAAa;AAClB,WAAO,eAAe,MAAM,WAAW,SAAS;AAAA,EAClD;AACF;;;ACEA,IAAM,qBAAqB;AAE3B,SAAS,SAA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AAAA,EAET,YAAY,MAAsB;AAChC,QAAI,CAAC,KAAK,SAAS;AACjB,YAAM,IAAI,UAAU,iCAAiC;AAAA,IACvD;AACA,QAAI,CAAC,KAAK,QAAQ;AAChB,YAAM,IAAI,UAAU,gCAAgC;AAAA,IACtD;AAEA,UAAM,OAAO,iBAAiB;AAAA,MAC5B,SAAS,KAAK,QAAQ,QAAQ,QAAQ,EAAE;AAAA,MACxC,QAAQ,KAAK;AAAA,MACb,OAAO,KAAK;AAAA,MACZ,WAAW,KAAK;AAAA,MAChB,SAAS,KAAK;AAAA,IAChB,CAAC;AAED,SAAK,WAAW,IAAI,iBAAiB,IAAI;AACzC,SAAK,SAAS,IAAI,eAAe,IAAI;AACrC,SAAK,SAAS,IAAI,eAAe,IAAI;AACrC,SAAK,QAAQ,IAAI,cAAc,IAAI;AACnC,SAAK,YAAY,IAAI,kBAAkB,IAAI;AAAA,EAC7C;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/errors.ts","../src/internal/http.ts","../src/resources/campaigns.ts","../src/internal/identity.ts","../src/resources/contacts.ts","../src/resources/emails.ts","../src/resources/events.ts","../src/resources/lists.ts","../src/resources/webhooks.ts","../src/hogsend.ts","../src/internal/verify.ts"],"sourcesContent":["/**\n * A non-2xx response — or a transport-level failure — from the Hogsend data\n * plane. `status` is the HTTP status code, or `0` when the request never\n * reached the server (DNS/connect/timeout). `body` is the parsed JSON body when\n * available, else the raw text, else `undefined`.\n */\nexport class HogsendAPIError extends Error {\n readonly status: number;\n readonly body: unknown;\n\n constructor(message: string, status: number, body: unknown) {\n super(message);\n this.name = \"HogsendAPIError\";\n this.status = status;\n this.body = body;\n // Restore prototype chain for instanceof across transpile targets.\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/**\n * A `429 Too Many Requests` response. `retryAfter` is the parsed `Retry-After`\n * header in seconds when present (the server sends it on 429 for `/v1/emails`).\n */\nexport class RateLimitError extends HogsendAPIError {\n readonly retryAfter?: number;\n\n constructor(message: string, body: unknown, retryAfter?: number) {\n super(message, 429, body);\n this.name = \"RateLimitError\";\n this.retryAfter = retryAfter;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n","import { HogsendAPIError, RateLimitError } from \"../errors.js\";\n\n/** Query params accepted by `get` — undefined values are dropped. */\nexport type Query = Record<string, string | number | undefined>;\n\n/** Per-request extras (currently just an idempotency header passthrough). */\nexport interface RequestExtras {\n /** Sent as the `Idempotency-Key` header when set. */\n idempotencyKey?: string;\n}\n\nexport interface HttpClientConfig {\n baseUrl: string;\n apiKey: string;\n fetch?: typeof fetch;\n timeoutMs?: number;\n headers?: Record<string, string>;\n}\n\n/** A minimal, self-contained data-plane HTTP client over native fetch. */\nexport interface HttpClient {\n get<T = unknown>(path: string, query?: Query): Promise<T>;\n post<T = unknown>(\n path: string,\n body: unknown,\n extras?: RequestExtras,\n ): Promise<T>;\n put<T = unknown>(\n path: string,\n body: unknown,\n extras?: RequestExtras,\n ): Promise<T>;\n patch<T = unknown>(\n path: string,\n body: unknown,\n extras?: RequestExtras,\n ): Promise<T>;\n del<T = unknown>(path: string, body?: unknown): Promise<T>;\n}\n\nconst DEFAULT_TIMEOUT_MS = 30_000;\n\nfunction buildUrl(baseUrl: string, path: string, query?: Query): string {\n const url = new URL(path.startsWith(\"/\") ? path : `/${path}`, `${baseUrl}/`);\n if (query) {\n for (const [key, value] of Object.entries(query)) {\n if (value === undefined) continue;\n url.searchParams.set(key, String(value));\n }\n }\n return url.toString();\n}\n\nfunction bodyMessage(status: number, body: unknown): string {\n if (body && typeof body === \"object\") {\n // Application-handler envelope: `{ error: \"human message\" }`.\n const errField = (body as { error?: unknown }).error;\n if (typeof errField === \"string\") {\n return `${status}: ${errField}`;\n }\n // @hono/zod-openapi default-hook validation envelope:\n // `{ success: false, error: <ZodError> }` (no defaultHook configured). The\n // structured ZodError is preserved on `err.body`; surface a short, readable\n // summary for `err.message` instead of the generic fallback.\n if (\n (body as { success?: unknown }).success === false &&\n errField &&\n typeof errField === \"object\"\n ) {\n const summary = JSON.stringify(errField).slice(0, 200);\n return `${status}: validation failed ${summary}`;\n }\n }\n return `request failed with status ${status}`;\n}\n\n/** Parse a `Retry-After` header (seconds form) into a number, else undefined. */\nfunction parseRetryAfter(value: string | null): number | undefined {\n if (!value) return undefined;\n const seconds = Number.parseInt(value, 10);\n return Number.isFinite(seconds) ? seconds : undefined;\n}\n\n/**\n * Builds an {@link HttpClient} bound to a config. Native `fetch`, JSON in/out,\n * `Authorization: Bearer <apiKey>`. Throws typed errors:\n * - {@link RateLimitError} on 429 (with parsed `Retry-After`),\n * - {@link HogsendAPIError} on any other non-2xx,\n * - {@link HogsendAPIError} with `status === 0` on a transport failure\n * (DNS/connect/abort/timeout).\n */\nexport function createHttpClient(config: HttpClientConfig): HttpClient {\n const doFetch = config.fetch ?? fetch;\n const timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;\n const extraHeaders = config.headers ?? {};\n\n async function request<T>(\n method: string,\n path: string,\n opts: { query?: Query; body?: unknown; extras?: RequestExtras },\n ): Promise<T> {\n const headers: Record<string, string> = {\n Accept: \"application/json\",\n Authorization: `Bearer ${config.apiKey}`,\n ...extraHeaders,\n };\n if (opts.body !== undefined) {\n headers[\"Content-Type\"] = \"application/json\";\n }\n if (opts.extras?.idempotencyKey) {\n headers[\"Idempotency-Key\"] = opts.extras.idempotencyKey;\n }\n\n const url = buildUrl(config.baseUrl, path, opts.query);\n\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), timeoutMs);\n\n let res: Response;\n try {\n res = await doFetch(url, {\n method,\n headers,\n body: opts.body !== undefined ? JSON.stringify(opts.body) : undefined,\n signal: controller.signal,\n });\n } catch (cause) {\n const msg = cause instanceof Error ? cause.message : String(cause);\n throw new HogsendAPIError(\n `cannot reach ${config.baseUrl} (${msg})`,\n 0,\n undefined,\n );\n } finally {\n clearTimeout(timer);\n }\n\n const text = await res.text();\n let parsed: unknown;\n if (text.length > 0) {\n try {\n parsed = JSON.parse(text);\n } catch {\n parsed = text;\n }\n }\n\n if (!res.ok) {\n if (res.status === 429) {\n throw new RateLimitError(\n bodyMessage(res.status, parsed),\n parsed,\n parseRetryAfter(res.headers.get(\"Retry-After\")),\n );\n }\n throw new HogsendAPIError(\n bodyMessage(res.status, parsed),\n res.status,\n parsed,\n );\n }\n\n return parsed as T;\n }\n\n return {\n get: <T>(path: string, query?: Query) => request<T>(\"GET\", path, { query }),\n post: <T>(path: string, body: unknown, extras?: RequestExtras) =>\n request<T>(\"POST\", path, { body, extras }),\n put: <T>(path: string, body: unknown, extras?: RequestExtras) =>\n request<T>(\"PUT\", path, { body, extras }),\n patch: <T>(path: string, body: unknown, extras?: RequestExtras) =>\n request<T>(\"PATCH\", path, { body, extras }),\n del: <T>(path: string, body?: unknown) =>\n request<T>(\"DELETE\", path, { body }),\n };\n}\n","import type { HttpClient } from \"../internal/http.js\";\nimport type {\n Campaign,\n SendCampaignInput,\n SendCampaignResult,\n} from \"../types.js\";\n\n/** The `campaigns.*` resource bound to an {@link HttpClient}. */\nexport class CampaignsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Queue a broadcast: durably send one template to every subscribed member of\n * a `list` (or every active member of a `bucket`). Exactly one of `list` /\n * `bucket` must be set; `template`/`props` are type-checked against the\n * augmented `TemplateRegistryMap` when `@hogsend/email` is installed, else\n * degrade to `{ template: string; props? }`.\n *\n * Returns the 202 enqueue ack (`{ campaignId, status }`); the actual sends run\n * asynchronously in the worker. Poll {@link CampaignsResource.get} for counts.\n */\n send(input: SendCampaignInput): Promise<SendCampaignResult> {\n // The discriminated union narrows `template`/`props` and the audience; index\n // into the input via a permissive view to build the wire body without\n // re-discriminating.\n const body = input as SendCampaignInput & {\n list?: string;\n bucket?: string;\n props?: Record<string, unknown>;\n };\n return this.http.post<SendCampaignResult>(\"/v1/campaigns\", {\n name: body.name,\n list: body.list,\n bucket: body.bucket,\n template: body.template,\n props: body.props,\n from: body.from,\n subject: body.subject,\n });\n }\n\n /** Fetch a campaign's current status + send counts. */\n get(id: string): Promise<Campaign> {\n return this.http.get<Campaign>(`/v1/campaigns/${encodeURIComponent(id)}`);\n }\n}\n","/**\n * Runtime guard mirroring the `Identity` union: at least one of `email` /\n * `userId` must be a non-empty string. The type system enforces this at the\n * call site, but runtime callers (plain JS, untyped data) can still violate it,\n * so we fail fast with a clear message before issuing the request.\n */\nexport function assertIdentity(input: {\n email?: string;\n userId?: string;\n}): void {\n const hasEmail = typeof input.email === \"string\" && input.email.length > 0;\n const hasUserId = typeof input.userId === \"string\" && input.userId.length > 0;\n if (!hasEmail && !hasUserId) {\n throw new TypeError(\n \"Hogsend: an identity is required — pass `email`, `userId`, or both.\",\n );\n }\n}\n","import type { HttpClient } from \"../internal/http.js\";\nimport { assertIdentity } from \"../internal/identity.js\";\nimport type {\n Contact,\n DeleteContactInput,\n DeleteContactResult,\n FindContactsInput,\n UpsertContactInput,\n UpsertContactResult,\n} from \"../types.js\";\n\n/** The `contacts.*` resource bound to an {@link HttpClient}. */\nexport class ContactsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Upsert a contact by identity. Resolves/merges server-side and optionally\n * applies list membership. Returns `{ id, created, linked }`.\n */\n async upsert(input: UpsertContactInput): Promise<UpsertContactResult> {\n assertIdentity(input);\n return this.http.put<UpsertContactResult>(\"/v1/contacts\", {\n email: input.email,\n userId: input.userId,\n properties: input.properties,\n lists: input.lists,\n });\n }\n\n /** Find non-deleted contacts by `email` or `userId`. */\n async find(input: FindContactsInput): Promise<Contact[]> {\n const query: Record<string, string | undefined> = {\n email: \"email\" in input ? input.email : undefined,\n userId: \"userId\" in input ? input.userId : undefined,\n };\n const res = await this.http.get<{ contacts: Contact[] }>(\n \"/v1/contacts/find\",\n query,\n );\n return res.contacts;\n }\n\n /** Soft-delete a contact by identity. */\n async delete(input: DeleteContactInput): Promise<DeleteContactResult> {\n assertIdentity(input);\n return this.http.del<DeleteContactResult>(\"/v1/contacts\", {\n email: input.email,\n userId: input.userId,\n });\n }\n}\n","import type { HttpClient } from \"../internal/http.js\";\nimport type { SendEmailInput, SendEmailResult } from \"../types.js\";\n\n/** The `emails.*` resource bound to an {@link HttpClient}. */\nexport class EmailsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Send a transactional email by template. Recipient is `to` (raw address) or\n * `userId` (resolved server-side). `template`/`props` are type-checked against\n * the augmented `TemplateRegistryMap` when `@hogsend/email` is installed,\n * else degrade to `{ template: string; props? }`.\n */\n send(input: SendEmailInput): Promise<SendEmailResult> {\n // The discriminated union narrows `template`/`props`; index into the input\n // via a permissive view to build the wire body without re-discriminating.\n const body = input as SendEmailInput & {\n props?: Record<string, unknown>;\n };\n return this.http.post<SendEmailResult>(\n \"/v1/emails\",\n {\n to: body.to,\n userId: body.userId,\n template: body.template,\n props: body.props,\n from: body.from,\n subject: body.subject,\n replyTo: body.replyTo,\n category: body.category,\n skipPreferenceCheck: body.skipPreferenceCheck,\n idempotencyKey: body.idempotencyKey,\n },\n body.idempotencyKey ? { idempotencyKey: body.idempotencyKey } : undefined,\n );\n }\n}\n","import type { HttpClient } from \"../internal/http.js\";\nimport { assertIdentity } from \"../internal/identity.js\";\nimport type { IngestResult, SendEventInput } from \"../types.js\";\n\n/** The `events.*` resource bound to an {@link HttpClient}. */\nexport class EventsResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Send an event through the ingestion pipeline. The two property bags are\n * kept distinct: `eventProperties` feed `trigger.where`/`exitOn`,\n * `contactProperties` merge onto the contact. Optionally apply list\n * membership. Returns the ingest result (stored + exit evaluations).\n *\n * `idempotencyKey` is sent both as the `Idempotency-Key` header (which wins\n * server-side) and in the body, matching `POST /v1/events`.\n */\n send(input: SendEventInput): Promise<IngestResult> {\n assertIdentity(input);\n return this.http.post<IngestResult>(\n \"/v1/events\",\n {\n name: input.name,\n email: input.email,\n userId: input.userId,\n eventProperties: input.eventProperties,\n contactProperties: input.contactProperties,\n lists: input.lists,\n idempotencyKey: input.idempotencyKey,\n },\n input.idempotencyKey\n ? { idempotencyKey: input.idempotencyKey }\n : undefined,\n );\n }\n\n /** Alias of {@link EventsResource.send}. */\n track(input: SendEventInput): Promise<IngestResult> {\n return this.send(input);\n }\n}\n","import type { HttpClient } from \"../internal/http.js\";\nimport { assertIdentity } from \"../internal/identity.js\";\nimport type {\n ListSummary,\n SubscribeInput,\n SubscribeResult,\n UnsubscribeResult,\n} from \"../types.js\";\n\n/** The `lists.*` resource bound to an {@link HttpClient}. */\nexport class ListsResource {\n constructor(private readonly http: HttpClient) {}\n\n /** List all code-defined lists. */\n async list(): Promise<ListSummary[]> {\n const res = await this.http.get<{ lists: ListSummary[] }>(\"/v1/lists\");\n return res.lists;\n }\n\n /** Subscribe an identity to a list. */\n async subscribe(input: SubscribeInput): Promise<SubscribeResult> {\n assertIdentity(input);\n const res = await this.http.post<{ list: string; subscribed: boolean }>(\n `/v1/lists/${encodeURIComponent(input.list)}/subscribe`,\n { email: input.email, userId: input.userId },\n );\n return { subscribed: res.subscribed };\n }\n\n /** Unsubscribe an identity from a list. */\n async unsubscribe(input: SubscribeInput): Promise<UnsubscribeResult> {\n assertIdentity(input);\n const res = await this.http.post<{ list: string; subscribed: boolean }>(\n `/v1/lists/${encodeURIComponent(input.list)}/unsubscribe`,\n { email: input.email, userId: input.userId },\n );\n return { unsubscribed: res.subscribed === false };\n }\n}\n","import type { HttpClient } from \"../internal/http.js\";\nimport type {\n CreatedWebhookEndpoint,\n CreateWebhookInput,\n RotateWebhookSecretResult,\n UpdateWebhookInput,\n WebhookEndpoint,\n} from \"../types.js\";\n\nconst BASE = \"/v1/admin/webhooks\";\n\n/**\n * The `webhooks.*` resource — manage outbound webhook endpoints (the\n * Svix-style signed event stream Hogsend emits to subscriber URLs).\n *\n * IMPORTANT: unlike the rest of the client (which uses an `ingest`-scoped data\n * key), this resource targets the ADMIN plane (`/v1/admin/webhooks`) and\n * REQUIRES a full-admin key. Signing-secret management is the same trust class\n * as API-key management — a leaked ingest key must never register an\n * exfiltration endpoint. Construct the client with an admin `apiKey`.\n *\n * The full signing `secret` (`whsec_…`) is returned ONCE — on\n * {@link WebhooksResource.create} and {@link WebhooksResource.rotateSecret}.\n * `list`/`get` only ever expose the display `secretPrefix`. Store it on create.\n */\nexport class WebhooksResource {\n constructor(private readonly http: HttpClient) {}\n\n /**\n * Register a new endpoint subscribed to one or more outbound event types.\n * For the default kind=\"webhook\", returns the endpoint INCLUDING the full\n * signing `secret` — the only time (besides rotate) it is returned; store it\n * now. For a keyed destination (e.g. `{ kind: \"posthog\", config: { apiKey } }`)\n * no secret is returned (it authenticates via `config`).\n */\n create(input: CreateWebhookInput): Promise<CreatedWebhookEndpoint> {\n return this.http.post<CreatedWebhookEndpoint>(BASE, {\n url: input.url,\n eventTypes: input.eventTypes,\n description: input.description,\n disabled: input.disabled,\n kind: input.kind,\n config: input.config,\n });\n }\n\n /**\n * List endpoints (newest first). Disabled endpoints are hidden unless\n * `includeDisabled` is set. Returns the endpoints array (unwrapped from the\n * `{ endpoints, total, limit, offset }` envelope).\n */\n async list(opts?: {\n limit?: number;\n offset?: number;\n includeDisabled?: boolean;\n }): Promise<WebhookEndpoint[]> {\n const res = await this.http.get<{ endpoints: WebhookEndpoint[] }>(BASE, {\n limit: opts?.limit,\n offset: opts?.offset,\n includeDisabled:\n opts?.includeDisabled === undefined\n ? undefined\n : String(opts.includeDisabled),\n });\n return res.endpoints;\n }\n\n /** Fetch one endpoint by id (404 → {@link HogsendAPIError}). */\n get(id: string): Promise<WebhookEndpoint> {\n return this.http.get<WebhookEndpoint>(`${BASE}/${encodeURIComponent(id)}`);\n }\n\n /**\n * Patch an endpoint. Only the provided fields change; `description: null`\n * clears the description. Does NOT return or rotate the secret.\n */\n update(id: string, input: UpdateWebhookInput): Promise<WebhookEndpoint> {\n return this.http.patch<WebhookEndpoint>(\n `${BASE}/${encodeURIComponent(id)}`,\n {\n url: input.url,\n eventTypes: input.eventTypes,\n description: input.description,\n disabled: input.disabled,\n kind: input.kind,\n config: input.config,\n },\n );\n }\n\n /** Hard-delete an endpoint (cascade drops its deliveries). */\n delete(id: string): Promise<{ deleted: boolean }> {\n return this.http.del<{ deleted: boolean }>(\n `${BASE}/${encodeURIComponent(id)}`,\n );\n }\n\n /**\n * Rotate the signing secret. The OLD secret is invalidated immediately (hard\n * cutover) — update every subscriber with the returned new `secret` (returned\n * ONCE).\n */\n rotateSecret(id: string): Promise<RotateWebhookSecretResult> {\n return this.http.post<RotateWebhookSecretResult>(\n `${BASE}/${encodeURIComponent(id)}/rotate-secret`,\n {},\n );\n }\n\n /**\n * Enqueue an out-of-band `webhook.test` delivery to the endpoint, delivered\n * regardless of its subscribed `eventTypes`. Returns the 202 enqueue ack.\n */\n sendTest(\n id: string,\n ): Promise<{ enqueued: boolean; eventType: \"webhook.test\" }> {\n return this.http.post<{ enqueued: boolean; eventType: \"webhook.test\" }>(\n `${BASE}/${encodeURIComponent(id)}/test`,\n {},\n );\n }\n}\n","import { createHttpClient } from \"./internal/http.js\";\nimport { CampaignsResource } from \"./resources/campaigns.js\";\nimport { ContactsResource } from \"./resources/contacts.js\";\nimport { EmailsResource } from \"./resources/emails.js\";\nimport { EventsResource } from \"./resources/events.js\";\nimport { ListsResource } from \"./resources/lists.js\";\nimport { WebhooksResource } from \"./resources/webhooks.js\";\nimport type { HogsendOptions } from \"./types.js\";\n\n/**\n * Typed HTTP client for the Hogsend data plane.\n *\n * ```ts\n * const hs = new Hogsend({ baseUrl: \"https://api.example.com\", apiKey: \"hsk_…\" });\n * await hs.contacts.upsert({ email: \"a@b.com\", properties: { plan: \"pro\" } });\n * await hs.events.send({ userId: \"u_1\", name: \"signup\" });\n * ```\n */\nexport class Hogsend {\n readonly contacts: ContactsResource;\n readonly events: EventsResource;\n readonly emails: EmailsResource;\n readonly lists: ListsResource;\n readonly campaigns: CampaignsResource;\n /**\n * Manage outbound webhook endpoints (the signed event stream Hogsend emits to\n * subscriber URLs). REQUIRES a full-admin `apiKey` — this resource hits the\n * admin plane (`/v1/admin/webhooks`), NOT the ingest data plane the other\n * resources use. See {@link WebhooksResource}.\n */\n readonly webhooks: WebhooksResource;\n\n constructor(opts: HogsendOptions) {\n if (!opts.baseUrl) {\n throw new TypeError(\"Hogsend: `baseUrl` is required.\");\n }\n if (!opts.apiKey) {\n throw new TypeError(\"Hogsend: `apiKey` is required.\");\n }\n\n const http = createHttpClient({\n baseUrl: opts.baseUrl.replace(/\\/+$/, \"\"),\n apiKey: opts.apiKey,\n fetch: opts.fetch,\n timeoutMs: opts.timeoutMs,\n headers: opts.headers,\n });\n\n this.contacts = new ContactsResource(http);\n this.events = new EventsResource(http);\n this.emails = new EmailsResource(http);\n this.lists = new ListsResource(http);\n this.campaigns = new CampaignsResource(http);\n this.webhooks = new WebhooksResource(http);\n }\n}\n","import { createHmac, timingSafeEqual } from \"node:crypto\";\nimport { Webhook } from \"svix\";\n\n/** Default tolerance (seconds) for the timestamp freshness check. */\nconst TOLERANCE_SECONDS = 5 * 60;\n\n/**\n * Lowercase every header key so callers can pass the Title-Case headers Hogsend\n * sends (`Webhook-Id`/`Webhook-Timestamp`/`Webhook-Signature`) OR the lowercase\n * form a framework may hand back. Svix expects lowercase `svix-*`/`webhook-*`.\n */\nfunction normalizeHeaders(\n headers: Record<string, string>,\n): Record<string, string> {\n const out: Record<string, string> = {};\n for (const [key, value] of Object.entries(headers)) {\n out[key.toLowerCase()] = value;\n }\n return out;\n}\n\n/**\n * Verify and parse an INBOUND Hogsend outbound-webhook delivery, the\n * subscriber-side counterpart of the engine's signing. Use this in a handler\n * that receives Hogsend's signed POSTs to confirm authenticity before trusting\n * the body.\n *\n * Pass the RAW request body bytes (the exact string Hogsend signed — never a\n * re-stringified object), the request headers, and the endpoint's `whsec_…`\n * signing secret (from create / rotate-secret). Returns the parsed event\n * envelope (`{ id, type, timestamp, data }`) on success.\n *\n * Throws on a bad signature, a missing signature header, or a timestamp outside\n * the 5-minute tolerance window.\n *\n * Implementation: wraps svix's `Webhook.verify` (constant-time, tolerance-\n * checked); if svix cannot run for any reason it falls back to a pure\n * `node:crypto` HMAC-SHA256 check over `${id}.${timestamp}.${body}` with a\n * `timingSafeEqual` compare against the `v1,<base64>` signature(s).\n *\n * @example\n * ```ts\n * import { verifyHogsendWebhook } from \"@hogsend/client\";\n *\n * app.post(\"/webhooks/hogsend\", async (req, res) => {\n * const body = await readRawBody(req); // the exact bytes\n * try {\n * const event = verifyHogsendWebhook({\n * payload: body,\n * headers: req.headers,\n * secret: process.env.HOGSEND_WEBHOOK_SECRET!,\n * });\n * // handle event.type ...\n * res.sendStatus(200);\n * } catch {\n * res.sendStatus(401);\n * }\n * });\n * ```\n */\nexport function verifyHogsendWebhook(opts: {\n payload: string;\n headers: Record<string, string>;\n secret: string;\n}): unknown {\n const headers = normalizeHeaders(opts.headers);\n const id = headers[\"webhook-id\"] ?? headers[\"svix-id\"];\n const timestamp = headers[\"webhook-timestamp\"] ?? headers[\"svix-timestamp\"];\n const signature = headers[\"webhook-signature\"] ?? headers[\"svix-signature\"];\n\n if (!id || !timestamp || !signature) {\n throw new Error(\n \"verifyHogsendWebhook: missing Webhook-Id / Webhook-Timestamp / Webhook-Signature header\",\n );\n }\n\n try {\n const wh = new Webhook(opts.secret);\n return wh.verify(opts.payload, {\n \"svix-id\": id,\n \"svix-timestamp\": timestamp,\n \"svix-signature\": signature,\n });\n } catch {\n // svix unavailable (tree-shaken) or threw — fall back to node:crypto. We\n // re-run the SAME canonical check so a genuine signature/timestamp failure\n // still throws; only a svix-internal/import failure is \"rescued\".\n return verifyWithNodeCrypto({\n payload: opts.payload,\n secret: opts.secret,\n id,\n timestamp,\n signature,\n });\n }\n}\n\n/**\n * Pure `node:crypto` verification of the Svix signature scheme. Mirrors the\n * documented fallback in the engine's webhook-signing lib:\n * `HMAC_SHA256(base64-decoded secret, `${id}.${ts}.${body}`)` → `v1,<base64>`,\n * `timingSafeEqual` against each space-separated signature in the header.\n */\nfunction verifyWithNodeCrypto(opts: {\n payload: string;\n secret: string;\n id: string;\n timestamp: string;\n signature: string;\n}): unknown {\n const ts = Number.parseInt(opts.timestamp, 10);\n if (!Number.isFinite(ts)) {\n throw new Error(\"verifyHogsendWebhook: invalid Webhook-Timestamp\");\n }\n const now = Math.floor(Date.now() / 1000);\n if (Math.abs(now - ts) > TOLERANCE_SECONDS) {\n throw new Error(\"verifyHogsendWebhook: timestamp outside tolerance window\");\n }\n\n // The secret is `whsec_<base64>`; the signing key is the base64-decoded body.\n const key = opts.secret.startsWith(\"whsec_\")\n ? Buffer.from(opts.secret.slice(6), \"base64\")\n : Buffer.from(opts.secret, \"base64\");\n const signedContent = `${opts.id}.${opts.timestamp}.${opts.payload}`;\n const expected = createHmac(\"sha256\", key)\n .update(signedContent)\n .digest(\"base64\");\n const expectedBuf = Buffer.from(expected);\n\n // The header is space-separated `v1,<sig>` pairs; accept if ANY matches.\n const matched = opts.signature.split(\" \").some((part) => {\n const sig = part.startsWith(\"v1,\") ? part.slice(3) : part;\n const candidate = Buffer.from(sig);\n return (\n candidate.length === expectedBuf.length &&\n timingSafeEqual(candidate, expectedBuf)\n );\n });\n\n if (!matched) {\n throw new Error(\"verifyHogsendWebhook: signature verification failed\");\n }\n\n return JSON.parse(opts.payload);\n}\n"],"mappings":";AAMO,IAAM,kBAAN,cAA8B,MAAM;AAAA,EAChC;AAAA,EACA;AAAA,EAET,YAAY,SAAiB,QAAgB,MAAe;AAC1D,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,OAAO;AAEZ,WAAO,eAAe,MAAM,WAAW,SAAS;AAAA,EAClD;AACF;AAMO,IAAM,iBAAN,cAA6B,gBAAgB;AAAA,EACzC;AAAA,EAET,YAAY,SAAiB,MAAe,YAAqB;AAC/D,UAAM,SAAS,KAAK,IAAI;AACxB,SAAK,OAAO;AACZ,SAAK,aAAa;AAClB,WAAO,eAAe,MAAM,WAAW,SAAS;AAAA,EAClD;AACF;;;ACOA,IAAM,qBAAqB;AAE3B,SAAS,SAAS,SAAiB,MAAc,OAAuB;A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AAK,OAAO;AAClE,QAAM,WAAW,WAAW,UAAU,GAAG,EACtC,OAAO,aAAa,EACpB,OAAO,QAAQ;AAClB,QAAM,cAAc,OAAO,KAAK,QAAQ;AAGxC,QAAM,UAAU,KAAK,UAAU,MAAM,GAAG,EAAE,KAAK,CAAC,SAAS;AACvD,UAAM,MAAM,KAAK,WAAW,KAAK,IAAI,KAAK,MAAM,CAAC,IAAI;AACrD,UAAM,YAAY,OAAO,KAAK,GAAG;AACjC,WACE,UAAU,WAAW,YAAY,UACjC,gBAAgB,WAAW,WAAW;AAAA,EAE1C,CAAC;AAED,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,qDAAqD;AAAA,EACvE;AAEA,SAAO,KAAK,MAAM,KAAK,OAAO;AAChC;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hogsend/client",
3
- "version": "0.7.0",
3
+ "version": "0.9.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Typed HTTP client for the Hogsend data plane (contacts, events, emails, lists).",
@@ -27,24 +27,19 @@
27
27
  "publishConfig": {
28
28
  "access": "public"
29
29
  },
30
- "peerDependencies": {
31
- "@hogsend/email": "^0.7.0"
32
- },
33
- "peerDependenciesMeta": {
34
- "@hogsend/email": {
35
- "optional": true
36
- }
37
- },
38
30
  "devDependencies": {
39
31
  "@types/node": "^22.15.3",
40
32
  "tsup": "^8.5.1",
41
33
  "vitest": "^4.1.7",
42
- "@hogsend/email": "^0.7.0",
34
+ "@hogsend/email": "^0.9.0",
43
35
  "@repo/typescript-config": "0.0.0"
44
36
  },
45
37
  "engines": {
46
38
  "node": ">=22"
47
39
  },
40
+ "dependencies": {
41
+ "svix": "^1.95.1"
42
+ },
48
43
  "scripts": {
49
44
  "build": "tsup",
50
45
  "check-types": "tsc --noEmit",