@vite-hub/webhooks 0.4.1 → 0.5.1
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/README.md +36 -6
- package/dist/database-C5cwO1an.d.ts +1517 -0
- package/dist/database.d.ts +2 -2
- package/dist/database.js +196 -14
- package/dist/{errors-1y5fWGlX.js → errors-DT8uyCh7.js} +39 -4
- package/dist/index.d.ts +128 -4
- package/dist/index.js +246 -4
- package/dist/members-BjDcAAhY.d.ts +343 -0
- package/dist/members-Cr_Nlyg4.js +308 -0
- package/dist/object-CAK6UYR5.js +10 -0
- package/dist/{operations-7ycAhDCw.d.ts → operations-8hqTi0DH.d.ts} +8 -4
- package/dist/operations.d.ts +13 -4
- package/dist/operations.js +189 -99
- package/dist/{queue-name-CGeTSHId.d.ts → queue-name-CLdaJFPZ.d.ts} +0 -2
- package/dist/{queue-name-RURp9SQf.js → queue-name-jmgeppja.js} +1 -2
- package/dist/runtime-BFiCJOMB.js +914 -0
- package/dist/{runtime-mqwMGfyX.d.ts → runtime-BdILDcW1.d.ts} +94 -17
- package/dist/runtime.d.ts +3 -3
- package/dist/runtime.js +3 -3
- package/dist/table-names-DAUip4v2.js +12 -0
- package/dist/vite.d.ts +91 -16
- package/dist/vite.js +192 -55
- package/package.json +9 -9
- package/dist/database-COdjz9Vi.d.ts +0 -608
- package/dist/object-BJb1W_q5.js +0 -7
- package/dist/runtime-DVBMk9vu.js +0 -486
- package/dist/table-names-DVvicXhh.js +0 -8
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as webhooksErrors, S as WebhookDeliveryErrorCode, a as SendToMemberEndpointResult, x as SendWebhookErrorCode } from "./members-BjDcAAhY.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";
|
|
2
3
|
import { RunFailedEvent, RunFailedEventName } from "@vite-hub/runtime/internal/run-failed";
|
|
3
4
|
import { Duration, Result } from "@vite-hub/runtime";
|
|
4
|
-
//#region src/errors.d.ts
|
|
5
|
-
/** The codes that `sendWebhook()` returns. Definition errors throw instead. */
|
|
6
|
-
type SendWebhookErrorCode = "WEBHOOKS_BODY_INVALID" | "WEBHOOKS_DATABASE_MISSING" | "WEBHOOKS_SECRET_UNSET" | "WEBHOOKS_STORE_FAILED" | "WEBHOOKS_URL_INVALID" | "WEBHOOKS_URL_UNSET" | "WEBHOOKS_WAKE_FAILED";
|
|
7
|
-
/** The codes that the delivery functions of `@vite-hub/webhooks/runtime` return. */
|
|
8
|
-
type WebhookDeliveryErrorCode = "WEBHOOKS_DATABASE_MISSING" | "WEBHOOKS_DELIVERY_ACTIVE" | "WEBHOOKS_DELIVERY_NOT_FOUND" | "WEBHOOKS_DELIVERY_NOT_PENDING" | "WEBHOOKS_STORE_FAILED" | "WEBHOOKS_WAKE_FAILED";
|
|
9
|
-
//#endregion
|
|
10
|
-
//#region src/define.d.ts
|
|
11
5
|
/** How a delivery is signed. Both use HMAC-SHA256 of the raw body with the secret. */
|
|
12
6
|
type WebhookSignature = "github" | "stripe";
|
|
13
7
|
/**
|
|
@@ -67,8 +61,19 @@ interface WebhookDefinition {
|
|
|
67
61
|
* ```
|
|
68
62
|
*/
|
|
69
63
|
declare function defineWebhook(options: WebhookOptions): WebhookDefinition;
|
|
70
|
-
|
|
71
|
-
|
|
64
|
+
/** The URL and secret of a member endpoint, as the sealed text holds them. */
|
|
65
|
+
interface EndpointTarget {
|
|
66
|
+
url: string;
|
|
67
|
+
secret: string;
|
|
68
|
+
}
|
|
69
|
+
type KeyError = ReturnType<typeof webhooksErrors.WEBHOOKS_KEY_UNSET | typeof webhooksErrors.WEBHOOKS_KEY_INVALID>;
|
|
70
|
+
/**
|
|
71
|
+
* Seals `text` with `VITEHUB_WEBHOOKS_KEY` for another package that keeps a receiver's secret before it becomes a member
|
|
72
|
+
* endpoint, such as the setup code of Comments Send. `label` binds the sealed text to one row: open it with the same one.
|
|
73
|
+
*/
|
|
74
|
+
declare function sealWebhooksText(label: string, text: string, developmentKey?: string): Promise<[KeyError, undefined] | [undefined, string]>;
|
|
75
|
+
/** Opens the text that `sealWebhooksText()` sealed with the same `label`. */
|
|
76
|
+
declare function unsealWebhooksText(label: string, sealed: string, developmentKey?: string): Promise<[KeyError, undefined] | [undefined, string]>;
|
|
72
77
|
/** Attempts of one delivery before it is `dead`: one delivery and three retries, as Cloudflare Queues does by default. */
|
|
73
78
|
declare const webhookMaxAttempts = 4;
|
|
74
79
|
/** How long a receiver has to answer. */
|
|
@@ -88,13 +93,25 @@ interface InstallWebhooksOptions {
|
|
|
88
93
|
webhooks: Record<string, unknown>;
|
|
89
94
|
/** Where deliveries live: `createDrizzleWebhookStore()` from `@vite-hub/webhooks/database`. */
|
|
90
95
|
store: WebhookDeliveryStore;
|
|
91
|
-
|
|
96
|
+
resolveVerifiedOwner?: (email: string, request: Request) => Promise<string | undefined>;
|
|
97
|
+
/**
|
|
98
|
+
* Sends a wake to the Queue. Without it, which is fine for an app with only member endpoints, a member delivery that
|
|
99
|
+
* fails is not tried again.
|
|
100
|
+
*/
|
|
101
|
+
wake?: WebhookWakeSender;
|
|
102
|
+
/** Where member endpoints live: `createDrizzleWebhookEndpointStore()`. Without it, member endpoints are off. */
|
|
103
|
+
endpoints?: WebhookEndpointStore;
|
|
104
|
+
/** The project-local key that the generated development registry reads. */
|
|
105
|
+
developmentKey?: string;
|
|
92
106
|
}
|
|
93
107
|
/** The webhooks of the running app. */
|
|
94
108
|
interface InstalledWebhooks {
|
|
95
109
|
webhooks: ReadonlyMap<string, WebhookDefinition>;
|
|
96
110
|
store: WebhookDeliveryStore;
|
|
97
|
-
wake: WebhookWakeSender;
|
|
111
|
+
wake: WebhookWakeSender | undefined;
|
|
112
|
+
endpoints: WebhookEndpointStore | undefined;
|
|
113
|
+
developmentKey: string | undefined;
|
|
114
|
+
resolveVerifiedOwner: InstallWebhooksOptions["resolveVerifiedOwner"];
|
|
98
115
|
}
|
|
99
116
|
/** One webhook, as the CLI and the Console list it. It names the variables, never their values. */
|
|
100
117
|
interface WebhookInfo {
|
|
@@ -132,6 +149,10 @@ declare function installWebhooks(options: InstallWebhooksOptions): InstalledWebh
|
|
|
132
149
|
type WebhookEventBody = RunFailedEvent & {
|
|
133
150
|
text: string;
|
|
134
151
|
};
|
|
152
|
+
/** The installed webhooks with member endpoints on. */
|
|
153
|
+
declare function requireMemberEndpoints(): InstalledWebhooks & {
|
|
154
|
+
endpoints: WebhookEndpointStore;
|
|
155
|
+
};
|
|
135
156
|
/**
|
|
136
157
|
* The Database that keeps the deliveries: the one that `useDatabase()` of `@vite-hub/database/runtime/registry` returns
|
|
137
158
|
* without a name. That is the Database that `vitehub database generate` adds the table to: `default`, else the only one.
|
|
@@ -140,6 +161,38 @@ type WebhookEventBody = RunFailedEvent & {
|
|
|
140
161
|
declare function selectDefaultDatabase(useDatabase: () => {
|
|
141
162
|
db: WebhooksDatabase;
|
|
142
163
|
}): WebhooksDatabase;
|
|
164
|
+
type Target = {
|
|
165
|
+
url: string;
|
|
166
|
+
secret: string;
|
|
167
|
+
signature: WebhookSignature;
|
|
168
|
+
guard?: boolean;
|
|
169
|
+
};
|
|
170
|
+
type WakeError = ReturnType<typeof webhooksErrors.WEBHOOKS_WAKE_FAILED>;
|
|
171
|
+
/** A member delivery names its endpoint as `@<endpoint id>` in the `webhook` column. */
|
|
172
|
+
declare const memberWebhookPrefix = "@";
|
|
173
|
+
/**
|
|
174
|
+
* Who asks for an action on a member delivery, such as Redeliver. `id` is an app user. A ViteHub Console account is
|
|
175
|
+
* not an app user, so the operation first resolves its verified email to a current app user id.
|
|
176
|
+
*/
|
|
177
|
+
type MemberCaller = {
|
|
178
|
+
id: string;
|
|
179
|
+
verifiedConsoleEmail?: string;
|
|
180
|
+
};
|
|
181
|
+
/**
|
|
182
|
+
* Whether `caller` has the app user id of the owner. Console callers must also match the email set at connect time.
|
|
183
|
+
*/
|
|
184
|
+
declare function ownsMemberEndpoint(endpoint: Pick<MemberEndpoint, "owner" | "ownerEmail">, caller: MemberCaller | undefined): boolean;
|
|
185
|
+
/**
|
|
186
|
+
* Posts a claimed member delivery now, or keeps it for the inbox when `target` is `undefined`. A failed post is tried
|
|
187
|
+
* again through the Queue when the app has one, so its status is `"pending"`; without Queue it is `"failed"`.
|
|
188
|
+
*/
|
|
189
|
+
declare function deliverMemberClaim(installed: InstalledWebhooks, claim: WebhookDelivery, target: EndpointTarget | undefined): Promise<[WakeError, undefined] | [undefined, SendToMemberEndpointResult]>;
|
|
190
|
+
declare function createDeliveryId(): string;
|
|
191
|
+
declare function wake(installed: InstalledWebhooks, delivery: {
|
|
192
|
+
id: string;
|
|
193
|
+
revision: number;
|
|
194
|
+
webhook: string;
|
|
195
|
+
}, delayMs: number): Promise<WakeError | undefined>;
|
|
143
196
|
/** Sends a body to a webhook. `sendWebhook()` of `@vite-hub/webhooks` calls it with a typed name. */
|
|
144
197
|
declare function sendDynamicWebhook(name: string, body: unknown, options: {
|
|
145
198
|
event: string;
|
|
@@ -161,6 +214,18 @@ declare function testWebhook(name: string, options?: {
|
|
|
161
214
|
* last attempt marks it `dead`. A wake that is out of date does nothing.
|
|
162
215
|
*/
|
|
163
216
|
declare function deliverWebhookWake(payload: unknown): Promise<void>;
|
|
217
|
+
/** One attempt. `final` means a retry cannot help, such as a URL that the guard refuses. */
|
|
218
|
+
type PostResult = {
|
|
219
|
+
ok: true;
|
|
220
|
+
status: number;
|
|
221
|
+
} | {
|
|
222
|
+
ok: false;
|
|
223
|
+
status: number | null;
|
|
224
|
+
failure: string;
|
|
225
|
+
final: boolean;
|
|
226
|
+
};
|
|
227
|
+
/** Posts a claimed delivery once, signed, with a 10 second timeout and no redirects. */
|
|
228
|
+
declare function postDelivery(claim: WebhookDelivery, target: Target, developmentKey?: string): Promise<PostResult>;
|
|
164
229
|
/** Every webhook of the app, with the names of its variables and whether they are set. */
|
|
165
230
|
declare function listWebhooks(): WebhookInfo[];
|
|
166
231
|
/** Deliveries, newest first. */
|
|
@@ -171,14 +236,26 @@ declare function listPendingWebhookDeliveries(options?: {
|
|
|
171
236
|
limit?: number;
|
|
172
237
|
}): Promise<Result<WebhookDelivery[], WebhookDeliveryErrorCode>>;
|
|
173
238
|
declare function getWebhookDelivery(id: string): Promise<Result<WebhookDelivery, WebhookDeliveryErrorCode>>;
|
|
174
|
-
|
|
175
|
-
|
|
239
|
+
declare function inspectDelivery(delivery: WebhookDelivery): WebhookDelivery;
|
|
240
|
+
/** What the delivery functions that send take. */
|
|
241
|
+
interface WebhookDeliveryActionOptions {
|
|
242
|
+
/** Who asks. A delivery to a member endpoint goes out again only for its owner: see `ownsMemberEndpoint()`. */
|
|
243
|
+
caller?: MemberCaller;
|
|
244
|
+
resolveCaller?: () => Promise<MemberCaller | undefined>;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Delivers a pending delivery now, without the rest of its debounce. A pending member delivery, which waits for a
|
|
248
|
+
* Queue retry, goes out only for its owner, so pass `caller`.
|
|
249
|
+
*/
|
|
250
|
+
declare function flushWebhookDelivery(id: string, options?: WebhookDeliveryActionOptions): Promise<Result<WebhookDelivery, WebhookDeliveryErrorCode>>;
|
|
176
251
|
/** Cancels a pending delivery. Its wake then does nothing. */
|
|
177
252
|
declare function cancelWebhookDelivery(id: string): Promise<Result<WebhookDelivery, WebhookDeliveryErrorCode>>;
|
|
178
253
|
/**
|
|
179
254
|
* Sends a sent, dead, or cancelled delivery again, now, as a new delivery with a new id. It keeps the body, the event,
|
|
180
255
|
* and the count. The webhook must still exist.
|
|
256
|
+
*
|
|
257
|
+
* A delivery to a member endpoint goes out again only for the owner of the endpoint, so pass `caller`. Anyone else gets
|
|
258
|
+
* `WEBHOOKS_DELIVERY_NOT_OWNER`. It posts in the request, as `sendToMemberEndpoint()` does, and returns its status.
|
|
181
259
|
*/
|
|
182
|
-
declare function redeliverWebhookDelivery(id: string): Promise<Result<SendWebhookResult, WebhookDeliveryErrorCode>>;
|
|
183
|
-
|
|
184
|
-
export { WebhookDeliveryErrorCode as A, webhookTimeoutMs as C, WebhookSignature as D, WebhookOptions as E, defineWebhook as O, webhookTestEvent as S, WebhookEvent as T, redeliverWebhookDelivery as _, WebhookInfo as a, testWebhook as b, cancelWebhookDelivery as c, getWebhookDelivery as d, installWebhooks as f, listWebhooks as g, listWebhookDeliveries as h, WebhookEventBody as i, SendWebhookErrorCode as k, deliverWebhookWake as l, listPendingWebhookDeliveries as m, InstalledWebhooks as n, WebhookWake as o, installedWebhooks as p, SendWebhookResult as r, WebhookWakeSender as s, InstallWebhooksOptions as t, flushWebhookDelivery as u, selectDefaultDatabase as v, WebhookDefinition as w, webhookMaxAttempts as x, sendDynamicWebhook as y };
|
|
260
|
+
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 };
|
package/dist/runtime.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { C as webhookTimeoutMs, S as
|
|
2
|
-
import { t as webhooksQueueName } from "./queue-name-
|
|
3
|
-
export { InstallWebhooksOptions, InstalledWebhooks, SendWebhookResult, WebhookEventBody, WebhookInfo, WebhookWake, WebhookWakeSender, cancelWebhookDelivery, deliverWebhookWake, flushWebhookDelivery, getWebhookDelivery, installWebhooks, installedWebhooks, listPendingWebhookDeliveries, listWebhookDeliveries, listWebhooks, redeliverWebhookDelivery, selectDefaultDatabase, sendDynamicWebhook, testWebhook, webhookMaxAttempts, webhookTestEvent, webhookTimeoutMs, webhooksQueueName };
|
|
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-BdILDcW1.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 };
|
package/dist/runtime.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
import { t as webhooksQueueName } from "./queue-name-
|
|
3
|
-
export { cancelWebhookDelivery, deliverWebhookWake, flushWebhookDelivery, getWebhookDelivery, installWebhooks, installedWebhooks, listPendingWebhookDeliveries, listWebhookDeliveries, listWebhooks, redeliverWebhookDelivery, selectDefaultDatabase, sendDynamicWebhook, testWebhook, webhookMaxAttempts, webhookTestEvent, webhookTimeoutMs, webhooksQueueName };
|
|
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 };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// src/table-names.ts
|
|
2
|
+
/**
|
|
3
|
+
* The schema keys of `webhooksSchema` and their SQL names. Its own module, so the Vite plugin lists the table without
|
|
4
|
+
* loading Drizzle during config resolution.
|
|
5
|
+
*/
|
|
6
|
+
const webhooksTableNames = { webhookDeliveries: "vitehub_webhook_deliveries" };
|
|
7
|
+
/** The schema keys of `webhookEndpointsSchema` and their SQL names. */
|
|
8
|
+
const webhookEndpointsTableNames = {
|
|
9
|
+
webhookEndpoints: "vitehub_webhook_endpoints",
|
|
10
|
+
webhookPairings: "vitehub_webhook_pairings"
|
|
11
|
+
};
|
|
12
|
+
export { webhooksTableNames as n, webhookEndpointsTableNames as t };
|
package/dist/vite.d.ts
CHANGED
|
@@ -1,7 +1,48 @@
|
|
|
1
|
-
import { t as webhooksQueueName } from "./queue-name-
|
|
2
|
-
import { n as OperationContributions } from "./operations-
|
|
1
|
+
import { t as webhooksQueueName } from "./queue-name-CLdaJFPZ.js";
|
|
2
|
+
import { n as OperationContributions } from "./operations-8hqTi0DH.js";
|
|
3
3
|
import { Plugin } from "vite";
|
|
4
|
-
|
|
4
|
+
/** The host that ViteHub builds for: the `host` option of `vitehub()` and the value of `VITEHUB_HOST`. */
|
|
5
|
+
type ViteHubHost = "cloudflare" | "deno" | "netlify" | "node" | "vercel";
|
|
6
|
+
/**
|
|
7
|
+
* One set of host variables that the deployed app reads, as `deployment.json` lists it: a Server Env declaration, or
|
|
8
|
+
* a variable that a primitive reads itself, such as `VITEHUB_SECRET` or `BLOB_READ_WRITE_TOKEN`.
|
|
9
|
+
* It holds names only, so `vitehub deploy` can check the host without booting Vite. It never holds a value.
|
|
10
|
+
*/
|
|
11
|
+
interface DeploymentEnvEntry {
|
|
12
|
+
/** The declaration path, such as `env.server.github.token`, when it is safe to show. Primitive entries have none. */
|
|
13
|
+
path?: string;
|
|
14
|
+
/** The host variable names, in read order. The first name that is set supplies the value. */
|
|
15
|
+
names: readonly string[];
|
|
16
|
+
/** Any variable whose name starts with this prefix supplies the value, such as `VITEHUB_CONSOLE_KEY_`. */
|
|
17
|
+
prefix?: string;
|
|
18
|
+
required: boolean;
|
|
19
|
+
secret: boolean;
|
|
20
|
+
/** A default supplies the value when no name is set. */
|
|
21
|
+
hasDefault: boolean;
|
|
22
|
+
/** The primitives that read these names, such as `blob`. Server Env declarations have none. */
|
|
23
|
+
owners?: readonly string[];
|
|
24
|
+
}
|
|
25
|
+
/** What a primitive needs to know to name the variables it reads in the deployed app. */
|
|
26
|
+
interface DeploymentEnvContext {
|
|
27
|
+
host: ViteHubHost;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The host variables that a primitive reads itself, outside the Server Env registry, for one host and its resolved
|
|
31
|
+
* config. A Vite plugin exposes it as `api.deploymentEnv`, and the build writes the result to `deployment.json`.
|
|
32
|
+
* Return names only, never values.
|
|
33
|
+
*/
|
|
34
|
+
type DeploymentEnvContribution = (context: DeploymentEnvContext) => readonly DeploymentEnvEntry[];
|
|
35
|
+
/** Roots that ViteHub passes to every contribution factory. */
|
|
36
|
+
interface ContributionContext {
|
|
37
|
+
/** Vite root. */
|
|
38
|
+
root: string;
|
|
39
|
+
/** ViteHub project root. It can differ from the Vite root, for example in a Nuxt app with a `srcDir`. */
|
|
40
|
+
projectRoot: string;
|
|
41
|
+
/** Server directories that the host forwards, for example Nuxt's `serverDir` and the server directories of layers. */
|
|
42
|
+
serverDirs?: readonly string[];
|
|
43
|
+
/** The flat list of Vite plugins, so a factory can read what sibling plugins declare. */
|
|
44
|
+
plugins?: readonly unknown[];
|
|
45
|
+
}
|
|
5
46
|
/** Lists discovered Definitions in a sidebar and shows the selected Definition's fields. */
|
|
6
47
|
interface ViteHubConsoleDefinitionCatalogView {
|
|
7
48
|
kind: "definition-catalog";
|
|
@@ -213,15 +254,12 @@ interface ViteHubConsoleSectionDescriptor<TView extends ViteHubConsoleSectionVie
|
|
|
213
254
|
/** Pages next to the main view, in sidebar order. Only document editor sections render pages today. */
|
|
214
255
|
pages?: readonly ViteHubConsoleSectionPage[];
|
|
215
256
|
}
|
|
216
|
-
//#endregion
|
|
217
|
-
//#region src/console.d.ts
|
|
218
257
|
/**
|
|
219
|
-
* Console section for the webhooks of `server/webhooks
|
|
220
|
-
* log, with Send test, Send now, Cancel,
|
|
258
|
+
* Console section for the webhooks of `server/webhooks/` and the member endpoints: each endpoint, the pending debounce
|
|
259
|
+
* timers, and the delivery log, with Send test, Send now, Cancel, Redeliver, and Disable or Enable for a member
|
|
260
|
+
* endpoint. It calls the `webhooks.*` operations with the Console user.
|
|
221
261
|
*/
|
|
222
262
|
export declare const webhooksConsoleSection: ViteHubConsoleWebhooksSection;
|
|
223
|
-
//#endregion
|
|
224
|
-
//#region src/vite.d.ts
|
|
225
263
|
export declare const WEBHOOKS_VITE_PLUGIN_NAME = "@vite-hub/webhooks/vite";
|
|
226
264
|
/** One file of `server/webhooks/`. */
|
|
227
265
|
export interface DiscoveredWebhook {
|
|
@@ -235,13 +273,33 @@ export declare function usesWebhooks(options: {
|
|
|
235
273
|
projectRoot: string;
|
|
236
274
|
serverDirs?: readonly string[];
|
|
237
275
|
}): boolean;
|
|
276
|
+
/**
|
|
277
|
+
* What another package's Vite plugin puts in `vitehub.webhooks` to use Webhooks with no `server/webhooks/` files, such
|
|
278
|
+
* as Comments with `send: true`. A function gets the project roots and the sibling plugins, and returns `undefined` when
|
|
279
|
+
* its feature is off.
|
|
280
|
+
*
|
|
281
|
+
* ```ts
|
|
282
|
+
* const plugin = { name: "my-feature", vitehub: { webhooks: { memberEndpoints: true, reason: "Sends to each member's agent." } } }
|
|
283
|
+
* ```
|
|
284
|
+
*/
|
|
285
|
+
export interface WebhooksUse {
|
|
286
|
+
/** Turns on member endpoints: their table, `createMemberEndpoint()`, and `sendToMemberEndpoint()`. No Queue needed. */
|
|
287
|
+
memberEndpoints: true;
|
|
288
|
+
/** Why the plugin uses them. Build errors name it. */
|
|
289
|
+
reason: string;
|
|
290
|
+
}
|
|
291
|
+
/** The `vitehub.webhooks` field of a plugin. */
|
|
292
|
+
export type WebhooksUseSource = WebhooksUse | ((context: ContributionContext) => WebhooksUse | undefined | Promise<WebhooksUse | undefined>);
|
|
293
|
+
/** The plugins that use member endpoints, as `<plugin>: <reason>`. An entry of the wrong shape throws. */
|
|
294
|
+
export declare function collectWebhooksUses(plugins: readonly unknown[] | undefined, context: ContributionContext): Promise<string[]>;
|
|
238
295
|
/** The module specifiers that the generated code imports. `vite-hub` passes its own subpaths. */
|
|
239
296
|
export interface WebhooksImports {
|
|
297
|
+
auth?: string;
|
|
240
298
|
/** `installWebhooks` and `deliverWebhookWake`. */
|
|
241
299
|
runtime: string;
|
|
242
300
|
/** `webhooksOperations`: the operations of the Console, `vitehub webhooks`, and MCP. */
|
|
243
301
|
operations: string;
|
|
244
|
-
/** `createDrizzleWebhookStore` and
|
|
302
|
+
/** `createDrizzleWebhookStore`, `createDrizzleWebhookEndpointStore`, and the schemas. */
|
|
245
303
|
database: string;
|
|
246
304
|
/** The Database registry of the app, with `useDatabase()`. */
|
|
247
305
|
databases: string;
|
|
@@ -265,35 +323,52 @@ export declare function webhooksGeneratedFiles(projectRoot: string): {
|
|
|
265
323
|
plugin: string;
|
|
266
324
|
types: string;
|
|
267
325
|
};
|
|
326
|
+
/** What the generated registry installs besides the webhooks of `server/webhooks/`. */
|
|
327
|
+
export interface WebhooksRegistryFeatures {
|
|
328
|
+
/** Wake the `vitehub-webhooks` Queue. Off for an app with member endpoints and no Queue. */
|
|
329
|
+
queue: boolean;
|
|
330
|
+
/** Install the member endpoint store. */
|
|
331
|
+
memberEndpoints: boolean;
|
|
332
|
+
/** Read the generated key only in the project's development server. */
|
|
333
|
+
developmentKeyFile?: string;
|
|
334
|
+
}
|
|
268
335
|
/** The generated module that installs the webhooks. The Queue handler and the Nitro plugin import it. */
|
|
269
|
-
export declare function renderWebhooksRegistry(webhooks: readonly DiscoveredWebhook[], imports: WebhooksImports): string;
|
|
336
|
+
export declare function renderWebhooksRegistry(webhooks: readonly DiscoveredWebhook[], imports: WebhooksImports, features?: WebhooksRegistryFeatures): string;
|
|
270
337
|
/** The Queue Definition of `vitehub-webhooks`, which Webhooks contributes to the Queue. */
|
|
271
338
|
export declare function renderWebhooksQueue(imports: WebhooksImports): string;
|
|
272
339
|
/** The webhook names for `sendWebhook()`, from the files of `server/webhooks/`. */
|
|
273
340
|
export declare function renderWebhooksTypes(file: string, webhooks: readonly DiscoveredWebhook[], typesImport: string): string;
|
|
274
|
-
|
|
341
|
+
/** The path of the key that `vite dev` generates when the app sets no `VITEHUB_WEBHOOKS_KEY`. */
|
|
342
|
+
export declare function webhooksDevelopmentKeyFile(projectRoot: string): string;
|
|
343
|
+
interface PluginContext {
|
|
275
344
|
projectRoot?: string;
|
|
276
345
|
root?: string;
|
|
277
346
|
rootDir?: string;
|
|
278
347
|
serverDirs?: readonly string[];
|
|
348
|
+
plugins?: readonly unknown[];
|
|
279
349
|
}
|
|
280
350
|
/**
|
|
281
351
|
* Webhooks in a ViteHub app: each `server/webhooks/<name>.ts` that default-exports `defineWebhook()` gets a name for
|
|
282
352
|
* `sendWebhook()`. Deliveries go to the `vitehub_webhook_deliveries` table of the Default Database and out through the
|
|
283
353
|
* `vitehub-webhooks` Queue, which this plugin contributes. Both features must be on.
|
|
354
|
+
*
|
|
355
|
+
* A sibling plugin that sets `vitehub.webhooks` (see `WebhooksUse`) turns on member endpoints, with no files. They need
|
|
356
|
+
* the Database. With Queue, failed member deliveries are tried again through it.
|
|
284
357
|
*/
|
|
285
358
|
export declare function hubWebhooks(options?: HubWebhooksOptions): Plugin & {
|
|
359
|
+
api: {
|
|
360
|
+
deploymentEnv: DeploymentEnvContribution;
|
|
361
|
+
};
|
|
286
362
|
vitehub: {
|
|
287
|
-
databases: (context:
|
|
288
|
-
queues: (context:
|
|
363
|
+
databases: (context: PluginContext) => Promise<unknown[]>;
|
|
364
|
+
queues: (context: PluginContext) => Promise<Array<{
|
|
289
365
|
name: string;
|
|
290
366
|
definition: {
|
|
291
367
|
module: string;
|
|
292
368
|
};
|
|
293
369
|
reason: string;
|
|
294
|
-
}
|
|
370
|
+
}>>;
|
|
295
371
|
operations: OperationContributions;
|
|
296
372
|
};
|
|
297
373
|
};
|
|
298
|
-
//#endregion
|
|
299
374
|
export { webhooksQueueName };
|