@vite-hub/webhooks 0.6.1 → 0.7.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.
@@ -1,66 +1,8 @@
1
- import { C as WebhookDeliveryErrorCode, S as SendWebhookErrorCode, a as SendToMemberEndpointResult, w as webhooksErrors } from "./members-Cn93y6gO.js";
2
- import { f as WebhookDeliveryStore, g as WebhooksDatabase, n as ListWebhookDeliveriesOptions, p as WebhookEndpointStore, r as MemberEndpoint, u as WebhookDelivery } from "./database-C5cwO1an.js";
3
- import { RunFailedEvent, RunFailedEventName } from "@vite-hub/runtime/internal/run-failed";
1
+ import { C as WebhookDeliveryErrorCode, S as SendWebhookErrorCode, a as SendToMemberEndpointResult, w as webhooksErrors } from "./members-D5P9ts4J.js";
2
+ import { i as WebhookEvent, n as ResolvedWebhooksRetention, o as WebhookSignature, r as WebhookDefinition, s as WebhooksRetention } from "./queue-name-CWPhsc2U.js";
3
+ import { f as WebhookDeliveryStore, g as WebhooksDatabase, n as ListWebhookDeliveriesOptions, p as WebhookEndpointStore, r as MemberEndpoint, u as WebhookDelivery } from "./database-CQ0i7hWU.js";
4
+ import { RunFailedEvent } from "@vite-hub/runtime/internal/run-failed";
4
5
  import { Duration, Result } from "@vite-hub/runtime";
5
- /** How a delivery is signed. Both use HMAC-SHA256 of the raw body with the secret. */
6
- type WebhookSignature = "github" | "stripe";
7
- /**
8
- * An event that ViteHub sends by itself, with no `sendWebhook()` call: an Agent Invocation, a Workflow run, or a Schedule
9
- * run that ended in failure with no retry left.
10
- */
11
- type WebhookEvent = RunFailedEventName;
12
- /** What `defineWebhook()` accepts. */
13
- interface WebhookOptions {
14
- /**
15
- * The name of the server variable that holds the receiver URL, such as `"T3_WEBHOOK_URL"`. It is a name, not the URL,
16
- * because a URL often holds a token.
17
- */
18
- url: string;
19
- /** The name of the server variable that holds the signing secret, such as `"T3_WEBHOOK_SECRET"`. */
20
- secret: string;
21
- /**
22
- * `"github"` (default) sends `x-hub-signature-256: sha256=<hex>`. `"stripe"` sends
23
- * `stripe-signature: t=<time>,v1=<hex>`. `verifyWebhook()` from `@vite-hub/env` checks both.
24
- */
25
- signature?: WebhookSignature;
26
- /**
27
- * Wait this long after the last send before one delivery, such as `"30m"`. Each send in the window replaces the body
28
- * and restarts the wait. Sends with the same `key` collapse, and the key defaults to the webhook name. At most `"1d"`.
29
- * Without it, each send is delivered at once.
30
- */
31
- debounce?: Duration;
32
- /**
33
- * Events that ViteHub sends to this webhook by itself: `"invocation.failed"`, `"workflow.failed"`, and
34
- * `"schedule.failed"`. Each is sent once, when the run ends in failure with no retry left.
35
- */
36
- events?: readonly WebhookEvent[];
37
- }
38
- /** A webhook of `server/webhooks/<name>.ts`. */
39
- interface WebhookDefinition {
40
- readonly url: string;
41
- readonly secret: string;
42
- readonly signature: WebhookSignature;
43
- /** The debounce in milliseconds. `0` delivers each send at once. */
44
- readonly debounceMs: number;
45
- /** The events that ViteHub sends to this webhook by itself. */
46
- readonly events: readonly WebhookEvent[];
47
- }
48
- /**
49
- * Defines a webhook: where ViteHub sends events, how it signs them, and how long it waits to collapse them. Default-export
50
- * it from `server/webhooks/<name>.ts`, then call `sendWebhook("<name>", body)` from server code, or list `events` that
51
- * ViteHub sends by itself.
52
- *
53
- * ```ts [server/webhooks/t3.ts]
54
- * import { defineWebhook } from "@vite-hub/webhooks"
55
- *
56
- * export default defineWebhook({
57
- * url: "T3_WEBHOOK_URL",
58
- * secret: "T3_WEBHOOK_SECRET",
59
- * debounce: "30m",
60
- * })
61
- * ```
62
- */
63
- declare function defineWebhook(options: WebhookOptions): WebhookDefinition;
64
6
  /** The URL and secret of a member endpoint, as the sealed text holds them. */
65
7
  interface EndpointTarget {
66
8
  url: string;
@@ -103,6 +45,8 @@ interface InstallWebhooksOptions {
103
45
  endpoints?: WebhookEndpointStore;
104
46
  /** The project-local key that the generated development registry reads. */
105
47
  developmentKey?: string;
48
+ /** How long finished deliveries stay. Default: sent and cancelled ones 7 days, dead ones 30 days. */
49
+ retention?: WebhooksRetention;
106
50
  }
107
51
  /** The webhooks of the running app. */
108
52
  interface InstalledWebhooks {
@@ -112,6 +56,7 @@ interface InstalledWebhooks {
112
56
  endpoints: WebhookEndpointStore | undefined;
113
57
  developmentKey: string | undefined;
114
58
  resolveVerifiedOwner: InstallWebhooksOptions["resolveVerifiedOwner"];
59
+ retention: ResolvedWebhooksRetention;
115
60
  }
116
61
  /** One webhook, as the CLI and the Console list it. It names the variables, never their values. */
117
62
  interface WebhookInfo {
@@ -182,6 +127,20 @@ type MemberCaller = {
182
127
  * Whether `caller` has the app user id of the owner. Console callers must also match the email set at connect time.
183
128
  */
184
129
  declare function ownsMemberEndpoint(endpoint: Pick<MemberEndpoint, "owner" | "ownerEmail">, caller: MemberCaller | undefined): boolean;
130
+ /**
131
+ * Claims a member delivery and posts it now, or keeps it for the inbox when `target` is `undefined`. When the app has a
132
+ * Queue, the delivery also gets a wake, as `sendWebhook()` does. So a delivery that a stopped server left in `sending`
133
+ * is posted again once its claim ends, and a failed post is tried again: its status is `"pending"`. Without Queue, a
134
+ * failed post is `"failed"`. A new delivery gets its wake before the claim, so a stop at any later point leaves one.
135
+ * With `takeOver`, it claims a `sending` delivery only when a stopped server left it, and wakes only after it wins.
136
+ */
137
+ declare function deliverMemberDelivery(installed: InstalledWebhooks, delivery: {
138
+ id: string;
139
+ revision: number;
140
+ webhook: string;
141
+ }, target: EndpointTarget | undefined, options?: {
142
+ takeOver?: boolean;
143
+ }): Promise<[WakeError, undefined] | [undefined, SendToMemberEndpointResult]>;
185
144
  /**
186
145
  * Posts a claimed member delivery now, or keeps it for the inbox when `target` is `undefined`. A failed post is tried
187
146
  * again through the Queue when the app has one, so its status is `"pending"`; without Queue it is `"failed"`.
@@ -208,6 +167,14 @@ declare const webhookTestEvent = "webhooks.test";
208
167
  declare function testWebhook(name: string, options?: {
209
168
  body?: unknown;
210
169
  }): Promise<Result<SendWebhookResult, SendWebhookErrorCode>>;
170
+ /** How many finished deliveries one wake or one member send deletes at most. */
171
+ declare const webhookPruneBatch = 100;
172
+ /**
173
+ * Deletes one batch of finished deliveries that are older than the retention. Each wake of the Queue and each member
174
+ * send runs it, so the table stops growing: every delivery gets at least one wake or send, and each deletes up to
175
+ * `webhookPruneBatch` old rows. A failure is logged and does not stop the delivery.
176
+ */
177
+ declare function pruneWebhookDeliveries(installed: InstalledWebhooks, now?: number): Promise<number>;
211
178
  /**
212
179
  * The Queue handler of `vitehub-webhooks`. It posts the delivery of a wake when the wake carries the latest revision and
213
180
  * the delivery is pending. A 2xx answer marks it `sent`. Any other answer throws, so the Queue tries again, until the
@@ -258,4 +225,4 @@ declare function cancelWebhookDelivery(id: string): Promise<Result<WebhookDelive
258
225
  * `WEBHOOKS_DELIVERY_NOT_OWNER`. It posts in the request, as `sendToMemberEndpoint()` does, and returns its status.
259
226
  */
260
227
  declare function redeliverWebhookDelivery(id: string, options?: WebhookDeliveryActionOptions): Promise<Result<SendWebhookResult | SendToMemberEndpointResult, WebhookDeliveryErrorCode>>;
261
- export { testWebhook as A, WebhookSignature as B, memberWebhookPrefix as C, requireMemberEndpoints as D, redeliverWebhookDelivery as E, sealWebhooksText as F, unsealWebhooksText as I, WebhookDefinition as L, webhookMaxAttempts as M, webhookTestEvent as N, selectDefaultDatabase as O, webhookTimeoutMs as P, WebhookEvent as R, listWebhooks as S, postDelivery as T, defineWebhook as V, inspectDelivery as _, SendWebhookResult as a, listPendingWebhookDeliveries as b, WebhookInfo as c, cancelWebhookDelivery as d, createDeliveryId as f, getWebhookDelivery as g, flushWebhookDelivery as h, PostResult as i, wake as j, sendDynamicWebhook as k, WebhookWake as l, deliverWebhookWake as m, InstalledWebhooks as n, WebhookDeliveryActionOptions as o, deliverMemberClaim as p, MemberCaller as r, WebhookEventBody as s, InstallWebhooksOptions as t, WebhookWakeSender as u, installWebhooks as v, ownsMemberEndpoint as w, listWebhookDeliveries as x, installedWebhooks as y, WebhookOptions as z };
228
+ export { selectDefaultDatabase as A, listWebhooks as C, pruneWebhookDeliveries as D, postDelivery as E, webhookPruneBatch as F, webhookTestEvent as I, webhookTimeoutMs as L, testWebhook as M, wake as N, redeliverWebhookDelivery as O, webhookMaxAttempts as P, sealWebhooksText as R, listWebhookDeliveries as S, ownsMemberEndpoint as T, getWebhookDelivery as _, SendWebhookResult as a, installedWebhooks as b, WebhookInfo as c, cancelWebhookDelivery as d, createDeliveryId as f, flushWebhookDelivery as g, deliverWebhookWake as h, PostResult as i, sendDynamicWebhook as j, requireMemberEndpoints as k, WebhookWake as l, deliverMemberDelivery as m, InstalledWebhooks as n, WebhookDeliveryActionOptions as o, deliverMemberClaim as p, MemberCaller as r, WebhookEventBody as s, InstallWebhooksOptions as t, WebhookWakeSender as u, inspectDelivery as v, memberWebhookPrefix as w, listPendingWebhookDeliveries as x, installWebhooks as y, unsealWebhooksText as z };
@@ -1,61 +1,9 @@
1
- import { t as webhooksErrors } from "./errors-DT8uyCh7.js";
1
+ import { i as resolveWebhooksRetention, r as isWebhookDefinition } from "./queue-name-BL96iCCH.js";
2
+ import { t as webhooksErrors } from "./errors-8u_DGHUd.js";
2
3
  import { signWebhook } from "@vite-hub/env";
3
- import { onRunFailed, runFailedEventNames } from "@vite-hub/runtime/internal/run-failed";
4
- import { parseDuration } from "@vite-hub/runtime";
4
+ import { onRunFailed } from "@vite-hub/runtime/internal/run-failed";
5
5
  import { importSealKey, sealWithKey, unsealWithKey } from "@vite-hub/env/seal";
6
6
  import { getViteHubTestMode } from "@vite-hub/runtime/internal/test-mode";
7
- // src/define.ts
8
- const definitionBrand = Symbol.for("vitehub.webhooks.definition");
9
- const variableName = /^[A-Z_][A-Z0-9_]*$/i;
10
- function isWebhookEvent(value) {
11
- return runFailedEventNames.some((name) => name === value);
12
- }
13
- function invalid(message) {
14
- return webhooksErrors.WEBHOOKS_DEFINITION_INVALID({ message: `[vitehub] ${message}` });
15
- }
16
- /**
17
- * Defines a webhook: where ViteHub sends events, how it signs them, and how long it waits to collapse them. Default-export
18
- * it from `server/webhooks/<name>.ts`, then call `sendWebhook("<name>", body)` from server code, or list `events` that
19
- * ViteHub sends by itself.
20
- *
21
- * ```ts [server/webhooks/t3.ts]
22
- * import { defineWebhook } from "@vite-hub/webhooks"
23
- *
24
- * export default defineWebhook({
25
- * url: "T3_WEBHOOK_URL",
26
- * secret: "T3_WEBHOOK_SECRET",
27
- * debounce: "30m",
28
- * })
29
- * ```
30
- */
31
- function defineWebhook(options) {
32
- for (const key of ["url", "secret"]) {
33
- const value = options?.[key];
34
- if (typeof value !== "string" || !variableName.test(value)) throw invalid(`\`${key}\` must be the name of a server variable, such as ${key === "url" ? "\"T3_WEBHOOK_URL\"" : "\"T3_WEBHOOK_SECRET\""}, not ${JSON.stringify(value)}.`);
35
- }
36
- const signature = options.signature ?? "github";
37
- if (signature !== "github" && signature !== "stripe") throw invalid(`\`signature\` must be "github" or "stripe", not ${JSON.stringify(signature)}.`);
38
- const debounceMs = options.debounce === void 0 ? 0 : parseDuration(options.debounce, "debounce");
39
- if (debounceMs > 864e5) throw webhooksErrors.WEBHOOKS_DEBOUNCE_TOO_LONG({ debounce: JSON.stringify(options.debounce) });
40
- const listed = options.events ?? [];
41
- if (!Array.isArray(listed)) throw invalid(`\`events\` must be a list such as ["workflow.failed"], not ${JSON.stringify(listed)}.`);
42
- const items = listed;
43
- const events = /* @__PURE__ */ new Set();
44
- for (const event of items) {
45
- if (!isWebhookEvent(event)) throw invalid(`\`events\` lists ${JSON.stringify(event)}. Use ${runFailedEventNames.map((name) => JSON.stringify(name)).join(", ")}.`);
46
- events.add(event);
47
- }
48
- return Object.defineProperty({
49
- url: options.url,
50
- secret: options.secret,
51
- signature,
52
- debounceMs,
53
- events: [...events]
54
- }, definitionBrand, { value: true });
55
- }
56
- function isWebhookDefinition(value) {
57
- return typeof value === "object" && value !== null && Reflect.get(value, definitionBrand) === true;
58
- }
59
7
  // ../internal/src/runtime/cloudflare-env-lookup.ts
60
8
  /** The key of the AsyncLocalStorage store on `globalThis`. Every bundled copy of this module shares the store. */
61
9
  const activeEnvStorageKey = Symbol.for("vitehub.cloudflare.env-storage");
@@ -326,13 +274,15 @@ function installWebhooks(options) {
326
274
  if (!isWebhookDefinition(definition)) throw webhooksErrors.WEBHOOKS_DEFINITION_INVALID({ message: `[vitehub] server/webhooks/${name} must default-export defineWebhook({ url, secret }).` });
327
275
  webhooks.set(name, definition);
328
276
  }
277
+ const retention = resolveWebhooksRetention(options.retention);
329
278
  const installed = {
330
279
  webhooks,
331
280
  store: options.store,
332
281
  wake: options.wake,
333
282
  endpoints: options.endpoints,
334
283
  developmentKey: options.developmentKey,
335
- resolveVerifiedOwner: options.resolveVerifiedOwner
284
+ resolveVerifiedOwner: options.resolveVerifiedOwner,
285
+ retention
336
286
  };
337
287
  Reflect.set(globalThis, installedKey, installed);
338
288
  if (!Reflect.get(globalThis, listenerKey)) Reflect.set(globalThis, listenerKey, onRunFailed(sendRunFailed));
@@ -438,10 +388,33 @@ function ownsMemberEndpoint(endpoint, caller) {
438
388
  return caller?.id === endpoint.owner && (caller.verifiedConsoleEmail === void 0 || caller.verifiedConsoleEmail === endpoint.ownerEmail);
439
389
  }
440
390
  /**
391
+ * Claims a member delivery and posts it now, or keeps it for the inbox when `target` is `undefined`. When the app has a
392
+ * Queue, the delivery also gets a wake, as `sendWebhook()` does. So a delivery that a stopped server left in `sending`
393
+ * is posted again once its claim ends, and a failed post is tried again: its status is `"pending"`. Without Queue, a
394
+ * failed post is `"failed"`. A new delivery gets its wake before the claim, so a stop at any later point leaves one.
395
+ * With `takeOver`, it claims a `sending` delivery only when a stopped server left it, and wakes only after it wins.
396
+ */
397
+ async function deliverMemberDelivery(installed, delivery, target, options = {}) {
398
+ const { store } = installed;
399
+ const wakeQueue = async () => target && installed.wake ? await wake(installed, delivery, webhookTimeoutMs) : void 0;
400
+ let wakeError = options.takeOver ? void 0 : await wakeQueue();
401
+ const now = Date.now();
402
+ const claim = options.takeOver ? await store.claimExpired?.(delivery.id, delivery.revision, now, now - claimLeaseMs) : await store.claim(delivery.id, delivery.revision, now, 0);
403
+ if (!claim) return [void 0, {
404
+ id: delivery.id,
405
+ status: "pending"
406
+ }];
407
+ if (options.takeOver) wakeError = await wakeQueue();
408
+ return postMemberClaim(installed, claim, target, async () => wakeError);
409
+ }
410
+ /**
441
411
  * Posts a claimed member delivery now, or keeps it for the inbox when `target` is `undefined`. A failed post is tried
442
412
  * again through the Queue when the app has one, so its status is `"pending"`; without Queue it is `"failed"`.
443
413
  */
444
414
  async function deliverMemberClaim(installed, claim, target) {
415
+ return postMemberClaim(installed, claim, target, () => wake(installed, claim, webhookTimeoutMs));
416
+ }
417
+ async function postMemberClaim(installed, claim, target, wakeRetry) {
445
418
  const { store } = installed;
446
419
  if (!target) {
447
420
  await store.sent(claim, {
@@ -469,7 +442,7 @@ async function deliverMemberClaim(installed, claim, target) {
469
442
  }];
470
443
  }
471
444
  const retry = installed.wake !== void 0 && !result.final;
472
- const wakeError = retry ? await wake(installed, claim, webhookTimeoutMs) : void 0;
445
+ const wakeError = retry ? await wakeRetry() : void 0;
473
446
  const state = await store.failed(claim, {
474
447
  status: result.status,
475
448
  error: result.failure
@@ -569,6 +542,27 @@ async function testWebhook(name, options = {}) {
569
542
  delayMs: 0
570
543
  });
571
544
  }
545
+ /** How many finished deliveries one wake or one member send deletes at most. */
546
+ const webhookPruneBatch = 100;
547
+ /**
548
+ * Deletes one batch of finished deliveries that are older than the retention. Each wake of the Queue and each member
549
+ * send runs it, so the table stops growing: every delivery gets at least one wake or send, and each deletes up to
550
+ * `webhookPruneBatch` old rows. A failure is logged and does not stop the delivery.
551
+ */
552
+ async function pruneWebhookDeliveries(installed, now = Date.now()) {
553
+ const { sentMs, deadMs } = installed.retention;
554
+ if (sentMs === null && deadMs === null) return 0;
555
+ try {
556
+ return await installed.store.prune({
557
+ sentBefore: sentMs === null ? null : now - sentMs,
558
+ deadBefore: deadMs === null ? null : now - deadMs,
559
+ limit: 100
560
+ });
561
+ } catch (error) {
562
+ console.error("[vitehub] Webhooks did not delete old deliveries.", error);
563
+ return 0;
564
+ }
565
+ }
572
566
  function isWake(value) {
573
567
  return typeof value === "object" && value !== null && typeof Reflect.get(value, "id") === "string" && Number.isInteger(Reflect.get(value, "revision"));
574
568
  }
@@ -591,11 +585,12 @@ async function deliverWebhookWake(payload) {
591
585
  const installed = requireInstalled();
592
586
  const { store } = installed;
593
587
  const now = Date.now();
588
+ await pruneWebhookDeliveries(installed, now);
594
589
  const claim = await store.claim(payload.id, payload.revision, now, now - claimLeaseMs);
595
590
  if (!claim) {
596
591
  const current = await store.get(payload.id);
597
- if (current?.revision === payload.revision && current.state === "sending") {
598
- const error = await wake(installed, current, current.updatedAt + claimLeaseMs + 1 - Date.now());
592
+ if (current?.revision === payload.revision && (current.state === "sending" || current.state === "pending")) {
593
+ const error = await wake(installed, current, (current.state === "sending" ? current.updatedAt + claimLeaseMs + 1 : current.dueAt) - Date.now());
599
594
  if (error) throw error;
600
595
  }
601
596
  return;
@@ -891,24 +886,21 @@ async function redeliverToMember(installed, source, endpoint) {
891
886
  target = opened;
892
887
  }
893
888
  const now = Date.now();
894
- const recorded = await installed.store.record({
895
- id: createDeliveryId(),
896
- webhook: source.webhook,
897
- owner: endpoint.owner,
898
- key: null,
899
- event: source.event,
900
- body: JSON.stringify(source.body),
901
- count: source.count,
902
- dueAt: now,
903
- now
904
- });
905
- const claim = await installed.store.claim(recorded.id, recorded.revision, now, 0);
906
- if (!claim) return {
907
- id: recorded.id,
908
- status: "pending"
909
- };
910
- const [wakeError, result] = await deliverMemberClaim(installed, claim, target);
889
+ const [wakeError, result] = await deliverMemberDelivery(installed, {
890
+ ...await installed.store.record({
891
+ id: createDeliveryId(),
892
+ webhook: source.webhook,
893
+ owner: endpoint.owner,
894
+ key: null,
895
+ event: source.event,
896
+ body: JSON.stringify(source.body),
897
+ count: source.count,
898
+ dueAt: now,
899
+ now
900
+ }),
901
+ webhook: source.webhook
902
+ }, target);
911
903
  if (wakeError) throw wakeError;
912
904
  return result;
913
905
  }
914
- export { sealedMemberBodyPrefix as A, webhookTestEvent as C, memberBodyLabel as D, outsideHosts as E, unsealWebhooksText as M, defineWebhook as N, sealEndpoint as O, webhookMaxAttempts as S, checkWebhookUrl as T, requireMemberEndpoints as _, flushWebhookDelivery as a, testWebhook as b, installWebhooks as c, listWebhookDeliveries as d, listWebhooks as f, redeliverWebhookDelivery as g, postDelivery as h, deliverWebhookWake as i, unsealEndpoint as j, sealWebhooksText as k, installedWebhooks as l, ownsMemberEndpoint as m, createDeliveryId as n, getWebhookDelivery as o, memberWebhookPrefix as p, deliverMemberClaim as r, inspectDelivery as s, cancelWebhookDelivery as t, listPendingWebhookDeliveries as u, selectDefaultDatabase as v, webhookTimeoutMs as w, wake as x, sendDynamicWebhook as y };
906
+ export { memberBodyLabel as A, wake as C, webhookTimeoutMs as D, webhookTestEvent as E, unsealWebhooksText as F, sealWebhooksText as M, sealedMemberBodyPrefix as N, checkWebhookUrl as O, unsealEndpoint as P, testWebhook as S, webhookPruneBatch as T, pruneWebhookDeliveries as _, deliverWebhookWake as a, selectDefaultDatabase as b, inspectDelivery as c, listPendingWebhookDeliveries as d, listWebhookDeliveries as f, postDelivery as g, ownsMemberEndpoint as h, deliverMemberDelivery as i, sealEndpoint as j, outsideHosts as k, installWebhooks as l, memberWebhookPrefix as m, createDeliveryId as n, flushWebhookDelivery as o, listWebhooks as p, deliverMemberClaim as r, getWebhookDelivery as s, cancelWebhookDelivery as t, installedWebhooks as u, redeliverWebhookDelivery as v, webhookMaxAttempts as w, sendDynamicWebhook as x, requireMemberEndpoints as y };
package/dist/runtime.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { A as testWebhook, C as memberWebhookPrefix, D as requireMemberEndpoints, E as redeliverWebhookDelivery, M as webhookMaxAttempts, N as webhookTestEvent, O as selectDefaultDatabase, P as webhookTimeoutMs, S as listWebhooks, T as postDelivery, _ as inspectDelivery, a as SendWebhookResult, b as listPendingWebhookDeliveries, c as WebhookInfo, d as cancelWebhookDelivery, f as createDeliveryId, g as getWebhookDelivery, h as flushWebhookDelivery, i as PostResult, j as wake, k as sendDynamicWebhook, l as WebhookWake, m as deliverWebhookWake, n as InstalledWebhooks, o as WebhookDeliveryActionOptions, p as deliverMemberClaim, r as MemberCaller, s as WebhookEventBody, t as InstallWebhooksOptions, u as WebhookWakeSender, v as installWebhooks, w as ownsMemberEndpoint, x as listWebhookDeliveries, y as installedWebhooks } from "./runtime-BYILR6Zc.js";
2
- import { t as webhooksQueueName } from "./queue-name-CLdaJFPZ.js";
3
- export { InstallWebhooksOptions, InstalledWebhooks, MemberCaller, PostResult, SendWebhookResult, WebhookDeliveryActionOptions, WebhookEventBody, WebhookInfo, WebhookWake, WebhookWakeSender, cancelWebhookDelivery, createDeliveryId, deliverMemberClaim, deliverWebhookWake, flushWebhookDelivery, getWebhookDelivery, inspectDelivery, installWebhooks, installedWebhooks, listPendingWebhookDeliveries, listWebhookDeliveries, listWebhooks, memberWebhookPrefix, ownsMemberEndpoint, postDelivery, redeliverWebhookDelivery, requireMemberEndpoints, selectDefaultDatabase, sendDynamicWebhook, testWebhook, wake, webhookMaxAttempts, webhookTestEvent, webhookTimeoutMs, webhooksQueueName };
1
+ import { t as webhooksQueueName } from "./queue-name-CWPhsc2U.js";
2
+ import { A as selectDefaultDatabase, C as listWebhooks, D as pruneWebhookDeliveries, E as postDelivery, F as webhookPruneBatch, I as webhookTestEvent, L as webhookTimeoutMs, M as testWebhook, N as wake, O as redeliverWebhookDelivery, P as webhookMaxAttempts, S as listWebhookDeliveries, T as ownsMemberEndpoint, _ as getWebhookDelivery, a as SendWebhookResult, b as installedWebhooks, c as WebhookInfo, d as cancelWebhookDelivery, f as createDeliveryId, g as flushWebhookDelivery, h as deliverWebhookWake, i as PostResult, j as sendDynamicWebhook, k as requireMemberEndpoints, l as WebhookWake, m as deliverMemberDelivery, n as InstalledWebhooks, o as WebhookDeliveryActionOptions, p as deliverMemberClaim, r as MemberCaller, s as WebhookEventBody, t as InstallWebhooksOptions, u as WebhookWakeSender, v as inspectDelivery, w as memberWebhookPrefix, x as listPendingWebhookDeliveries, y as installWebhooks } from "./runtime-2igB0GrL.js";
3
+ export { InstallWebhooksOptions, InstalledWebhooks, MemberCaller, PostResult, SendWebhookResult, WebhookDeliveryActionOptions, WebhookEventBody, WebhookInfo, WebhookWake, WebhookWakeSender, cancelWebhookDelivery, createDeliveryId, deliverMemberClaim, deliverMemberDelivery, deliverWebhookWake, flushWebhookDelivery, getWebhookDelivery, inspectDelivery, installWebhooks, installedWebhooks, listPendingWebhookDeliveries, listWebhookDeliveries, listWebhooks, memberWebhookPrefix, ownsMemberEndpoint, postDelivery, pruneWebhookDeliveries, redeliverWebhookDelivery, requireMemberEndpoints, selectDefaultDatabase, sendDynamicWebhook, testWebhook, wake, webhookMaxAttempts, webhookPruneBatch, webhookTestEvent, webhookTimeoutMs, webhooksQueueName };
package/dist/runtime.js CHANGED
@@ -1,3 +1,3 @@
1
- import { C as webhookTestEvent, S as webhookMaxAttempts, _ as requireMemberEndpoints, a as flushWebhookDelivery, b as testWebhook, c as installWebhooks, d as listWebhookDeliveries, f as listWebhooks, g as redeliverWebhookDelivery, h as postDelivery, i as deliverWebhookWake, l as installedWebhooks, m as ownsMemberEndpoint, n as createDeliveryId, o as getWebhookDelivery, p as memberWebhookPrefix, r as deliverMemberClaim, s as inspectDelivery, t as cancelWebhookDelivery, u as listPendingWebhookDeliveries, v as selectDefaultDatabase, w as webhookTimeoutMs, x as wake, y as sendDynamicWebhook } from "./runtime-BFiCJOMB.js";
2
- import { t as webhooksQueueName } from "./queue-name-jmgeppja.js";
3
- export { cancelWebhookDelivery, createDeliveryId, deliverMemberClaim, deliverWebhookWake, flushWebhookDelivery, getWebhookDelivery, inspectDelivery, installWebhooks, installedWebhooks, listPendingWebhookDeliveries, listWebhookDeliveries, listWebhooks, memberWebhookPrefix, ownsMemberEndpoint, postDelivery, redeliverWebhookDelivery, requireMemberEndpoints, selectDefaultDatabase, sendDynamicWebhook, testWebhook, wake, webhookMaxAttempts, webhookTestEvent, webhookTimeoutMs, webhooksQueueName };
1
+ import { t as webhooksQueueName } from "./queue-name-BL96iCCH.js";
2
+ import { C as wake, D as webhookTimeoutMs, E as webhookTestEvent, S as testWebhook, T as webhookPruneBatch, _ as pruneWebhookDeliveries, a as deliverWebhookWake, b as selectDefaultDatabase, c as inspectDelivery, d as listPendingWebhookDeliveries, f as listWebhookDeliveries, g as postDelivery, h as ownsMemberEndpoint, i as deliverMemberDelivery, l as installWebhooks, m as memberWebhookPrefix, n as createDeliveryId, o as flushWebhookDelivery, p as listWebhooks, r as deliverMemberClaim, s as getWebhookDelivery, t as cancelWebhookDelivery, u as installedWebhooks, v as redeliverWebhookDelivery, w as webhookMaxAttempts, x as sendDynamicWebhook, y as requireMemberEndpoints } from "./runtime-DhvHbH0D.js";
3
+ export { cancelWebhookDelivery, createDeliveryId, deliverMemberClaim, deliverMemberDelivery, deliverWebhookWake, flushWebhookDelivery, getWebhookDelivery, inspectDelivery, installWebhooks, installedWebhooks, listPendingWebhookDeliveries, listWebhookDeliveries, listWebhooks, memberWebhookPrefix, ownsMemberEndpoint, postDelivery, pruneWebhookDeliveries, redeliverWebhookDelivery, requireMemberEndpoints, selectDefaultDatabase, sendDynamicWebhook, testWebhook, wake, webhookMaxAttempts, webhookPruneBatch, webhookTestEvent, webhookTimeoutMs, webhooksQueueName };
package/dist/vite.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import { t as webhooksQueueName } from "./queue-name-CLdaJFPZ.js";
1
+ import { s as WebhooksRetention, t as webhooksQueueName } from "./queue-name-CWPhsc2U.js";
2
2
  import { n as OperationContributions } from "./operations-8hqTi0DH.js";
3
+ import { EnvRuntimeConfigOptions } from "@vite-hub/env";
3
4
  import { Plugin } from "vite";
4
5
  /** The host that ViteHub builds for: the `host` option of `vitehub()` and the value of `VITEHUB_HOST`. */
5
6
  type ViteHubHost = "cloudflare" | "deno" | "netlify" | "node" | "vercel";
@@ -268,6 +269,20 @@ export interface DiscoveredWebhook {
268
269
  }
269
270
  /** The webhooks of `<serverDir>/webhooks/<name>.ts`. A name is lowercase letters, digits, and dashes. */
270
271
  export declare function discoverWebhooks(projectRoot: string, serverDirs?: readonly string[]): DiscoveredWebhook[];
272
+ /**
273
+ * The variable names that a webhook file passes to `defineWebhook()` as string literals: `{ url?: "NAME", secret?: "NAME" }`.
274
+ * A name that the build cannot read, such as one from a constant, is omitted.
275
+ */
276
+ export declare function readWebhookVariableNames(source: string, file?: string): {
277
+ url?: string;
278
+ secret?: string;
279
+ };
280
+ /**
281
+ * Server Env declarations for the variables of each webhook, as `env.server.webhooks.<name>.url` and `.secret`. They read
282
+ * only the names in the webhook file, so the Console Env section, `describeServerEnv()`, `inspectServerEnv()`, and
283
+ * `vitehub env push` know them without a second declaration in the app.
284
+ */
285
+ export declare function webhooksServerEnv(webhooks: readonly DiscoveredWebhook[]): EnvRuntimeConfigOptions | undefined;
271
286
  /** Whether the app has a webhook. */
272
287
  export declare function usesWebhooks(options: {
273
288
  projectRoot: string;
@@ -314,6 +329,11 @@ export interface HubWebhooksOptions {
314
329
  database?: boolean;
315
330
  /** The app has ViteHub Queue. Webhooks delivers through its `vitehub-webhooks` Queue. */
316
331
  queue?: boolean;
332
+ /**
333
+ * How long finished deliveries stay in the Database. Default: `{ sent: "7 days", dead: "30 days" }`. `sent` also
334
+ * covers cancelled and inbox deliveries. `false` keeps that kind. Pending and sending deliveries always stay.
335
+ */
336
+ retention?: WebhooksRetention;
317
337
  }
318
338
  /** The files that `hubWebhooks()` writes in `<projectRoot>/.vitehub`. */
319
339
  export declare function webhooksGeneratedFiles(projectRoot: string): {
@@ -331,6 +351,8 @@ export interface WebhooksRegistryFeatures {
331
351
  memberEndpoints: boolean;
332
352
  /** Read the generated key only in the project's development server. */
333
353
  developmentKeyFile?: string;
354
+ /** `retention` of `hubWebhooks()`, when the app sets it. */
355
+ retention?: WebhooksRetention;
334
356
  }
335
357
  /** The generated module that installs the webhooks. The Queue handler and the Nitro plugin import it. */
336
358
  export declare function renderWebhooksRegistry(webhooks: readonly DiscoveredWebhook[], imports: WebhooksImports, features?: WebhooksRegistryFeatures): string;
@@ -371,4 +393,4 @@ export declare function hubWebhooks(options?: HubWebhooksOptions): Plugin & {
371
393
  operations: OperationContributions;
372
394
  };
373
395
  };
374
- export { webhooksQueueName };
396
+ export { type WebhooksRetention, webhooksQueueName };