@vite-hub/webhooks 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/README.md +2 -2
- package/dist/database.js +3 -6
- package/dist/{errors-8u_DGHUd.js → errors-Dx-ml10b.js} +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +4 -4
- package/dist/{members-CD76JOUv.js → members-D2BRslXn.js} +2 -2
- package/dist/{members-D5P9ts4J.d.ts → members-wi2GgyaN.d.ts} +1 -1
- package/dist/operations.d.ts +1 -1
- package/dist/operations.js +2 -11
- package/dist/{queue-name-BL96iCCH.js → queue-name-0OM5djKH.js} +1 -1
- package/dist/{runtime-2igB0GrL.d.ts → runtime-CjUMIHjQ.d.ts} +1 -1
- package/dist/{runtime-DhvHbH0D.js → runtime-DOmUU6zG.js} +8 -9
- package/dist/runtime.d.ts +1 -1
- package/dist/runtime.js +2 -2
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +2 -7
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -108,7 +108,7 @@ Webhooks prunes finished deliveries after a time: `sent`, `cancelled`, and inbox
|
|
|
108
108
|
|
|
109
109
|
## Member endpoints
|
|
110
110
|
|
|
111
|
-
A member endpoint is a receiver that belongs to one member of the app, such as their T3 Code thread. A feature that sends to members turns them on,
|
|
111
|
+
A member endpoint is a receiver that belongs to one member of the app, such as their T3 Code thread. A feature that sends to members turns them on, with a Vite plugin that sets `vitehub.webhooks: { memberEndpoints: true, reason }`. They need `database`, not `queue`.
|
|
112
112
|
|
|
113
113
|
```ts [server/utils/send-comments.ts]
|
|
114
114
|
import { createMemberEndpoint, sendToMemberEndpoint } from "vite-hub/webhooks"
|
|
@@ -127,7 +127,7 @@ export async function connectAndSend(userId: string, url: string, secret: string
|
|
|
127
127
|
| `sendToMemberEndpoint(owner, body, { event, key, address?, endpointId? })` | Posts to the member's endpoint with `address`, else to their newest. Pass `endpointId` to send only to that endpoint with no fallback. Posts in the request with a 10 second timeout and the usual signature. The same `key` posts once per endpoint, and takes over a delivery that a stopped server left in `sending` for more than 70 seconds. With Queue, each send also gets a wake that recovers it. Returns `[error, { id, status }]`, where `status` is `"sent"`, `"inbox"`, `"pending"` (the Queue retries), or `"failed"`. |
|
|
128
128
|
| `listMemberDeliveries(owner, { address?, endpointId?, limit?, before? })` | The selected endpoint and its deliveries, newest first, or `null`. Inbox agents should pass the `endpointId` from pairing so their reads never switch to another endpoint. An empty `address` prefers the unaddressed endpoint. |
|
|
129
129
|
| `getMemberDelivery(id)` | The `state` of a member delivery and `inbox`, true when it waits in an inbox, or `undefined`. It never returns the body. `inbox` stays true after the member removes the endpoint. |
|
|
130
|
-
| `startMemberPairing(owner)`, `pairMemberEndpoint(input, { hosts? })`, `allowMemberPairing(owner, code, { name, ownerName?, ownerEmail?, hosts? })` | Pair a member's agent with a one-use code that works for 10 minutes. Give the agent the `code` and `secret` that start returns. A route passes its post, `{ code, url, thread? }` or `{ code, inbox }`, to `pairMemberEndpoint`, and the member's Allow creates the endpoint, with the agent's T3 thread link as its address. `getMemberPairing`, `cancelMemberPairing`, and `refuseMemberPairing` poll, close, and use up a code.
|
|
130
|
+
| `startMemberPairing(owner)`, `pairMemberEndpoint(input, { hosts? })`, `allowMemberPairing(owner, code, { name, ownerName?, ownerEmail?, hosts? })` | Pair a member's agent with a one-use code that works for 10 minutes. Give the agent the `code` and `secret` that start returns. A route passes its post, `{ code, url, thread? }` or `{ code, inbox }`, to `pairMemberEndpoint`, and the member's Allow creates the endpoint, with the agent's T3 thread link as its address. `getMemberPairing`, `cancelMemberPairing`, and `refuseMemberPairing` poll, close, and use up a code. |
|
|
131
131
|
| `getMemberEndpoint(owner, { endpointId?, address? })`, `listMemberEndpoints({ limit?, after? })`, `removeMemberEndpoint(owner, id)`, `removeMemberEndpoints(owner)`, `disableMemberEndpoint(id, { by? })`, `enableMemberEndpoint(id)` | Read, list a page with the newest delivery to each endpoint, remove, disable, or enable an endpoint. None returns the receiver URL or the secret. |
|
|
132
132
|
| `checkWebhookUrl(url, { hosts? })` | Refuses a URL that is not `https`, holds credentials, uses a host outside `hosts`, or names or resolves to a loopback, private, link-local, or metadata address. Cloudflare Workers cannot resolve names, so there `hosts` alone decides. |
|
|
133
133
|
|
package/dist/database.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as webhooksErrors } from "./errors-
|
|
1
|
+
import { t as webhooksErrors } from "./errors-Dx-ml10b.js";
|
|
2
2
|
import { n as webhooksTableNames, t as webhookEndpointsTableNames } from "./table-names-DAUip4v2.js";
|
|
3
3
|
import { and, asc, desc, eq, gt, gte, inArray, lt, ne, not, or, sql } from "drizzle-orm";
|
|
4
4
|
import { index, integer, sqliteTable, text, uniqueIndex } from "drizzle-orm/sqlite-core";
|
|
@@ -42,9 +42,7 @@ const webhookDeliveries = sqliteTable("vitehub_webhook_deliveries", {
|
|
|
42
42
|
const webhookEndpoints = sqliteTable("vitehub_webhook_endpoints", {
|
|
43
43
|
id: text("id").primaryKey(),
|
|
44
44
|
owner: text("owner").notNull(),
|
|
45
|
-
/** The name of the owner that people read, such as `Ana Ruiz`. */
|
|
46
45
|
ownerName: text("owner_name"),
|
|
47
|
-
/** The verified email of the owner at connect time, not proof of their current identity. */
|
|
48
46
|
ownerEmail: text("owner_email"),
|
|
49
47
|
name: text("name").notNull(),
|
|
50
48
|
address: text("address").notNull().default(""),
|
|
@@ -53,7 +51,6 @@ const webhookEndpoints = sqliteTable("vitehub_webhook_endpoints", {
|
|
|
53
51
|
host: text("host"),
|
|
54
52
|
sealed: text("sealed"),
|
|
55
53
|
disabledAt: integer("disabled_at"),
|
|
56
|
-
/** Who disabled it, such as the name of an admin. */
|
|
57
54
|
disabledBy: text("disabled_by"),
|
|
58
55
|
createdAt: integer("created_at").notNull(),
|
|
59
56
|
updatedAt: integer("updated_at").notNull()
|
|
@@ -231,7 +228,7 @@ function createDrizzleWebhookStore(database) {
|
|
|
231
228
|
lastError: null,
|
|
232
229
|
sentAt: now,
|
|
233
230
|
updatedAt: now
|
|
234
|
-
}).where(and(eq(t.id, claim.id), eq(t.state, "sending"), eq(t.attempts, claim.attempts)));
|
|
231
|
+
}).where(and(eq(t.id, claim.id), eq(t.revision, claim.revision), eq(t.state, "sending"), eq(t.attempts, claim.attempts)));
|
|
235
232
|
}),
|
|
236
233
|
failed: (claim, result, now, dead) => guarded("mark a failed attempt", async () => {
|
|
237
234
|
const next = dead ? sql`'dead'` : sql`CASE WHEN ${t.key} IS NOT NULL AND EXISTS (SELECT 1 FROM vitehub_webhook_deliveries AS newer WHERE newer.webhook = ${t.webhook} AND newer.key = ${t.key} AND newer.state = 'pending') THEN 'cancelled' ELSE 'pending' END`;
|
|
@@ -240,7 +237,7 @@ function createDrizzleWebhookStore(database) {
|
|
|
240
237
|
lastStatus: result.status,
|
|
241
238
|
lastError: result.error,
|
|
242
239
|
updatedAt: now
|
|
243
|
-
}).where(and(eq(t.id, claim.id), eq(t.state, "sending"), eq(t.attempts, claim.attempts))).returning({ state: t.state });
|
|
240
|
+
}).where(and(eq(t.id, claim.id), eq(t.revision, claim.revision), eq(t.state, "sending"), eq(t.attempts, claim.attempts))).returning({ state: t.state });
|
|
244
241
|
if (row?.state === "cancelled") await db().update(t).set({ count: sql`${t.count} + ${claim.count}` }).where(and(eq(t.webhook, claim.webhook), eq(t.key, claim.key ?? ""), eq(t.state, "pending")));
|
|
245
242
|
return row?.state;
|
|
246
243
|
}),
|
|
@@ -21,7 +21,7 @@ const webhooksErrors = /*#__PURE__*/ defineErrors({
|
|
|
21
21
|
},
|
|
22
22
|
WEBHOOKS_ENDPOINTS_OFF: {
|
|
23
23
|
why: "Member endpoints are not on in this server. No feature of the app uses them, or the code runs outside the ViteHub server.",
|
|
24
|
-
fix: "Turn on
|
|
24
|
+
fix: "Turn on member endpoints from a Vite plugin with `vitehub.webhooks: { memberEndpoints: true, reason }`. In a test, call `installWebhooks({ webhooks: {}, store, endpoints })` from `@vite-hub/webhooks/runtime` first."
|
|
25
25
|
},
|
|
26
26
|
WEBHOOKS_FILE_INVALID: {
|
|
27
27
|
why: ({ message }) => message,
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as WebhookDeliveryErrorCode, S as SendWebhookErrorCode, _ as sendToMemberEndpoint, a as SendToMemberEndpointResult, b as MemberPairingErrorCode, c as enableMemberEndpoint, d as getMemberEndpoint, f as listMemberDeliveries, g as removeMemberEndpoints, h as removeMemberEndpoint, i as SendToMemberEndpointOptions, l as getMemberDelivery, m as memberEndpointHosts, n as MemberDeliveries, o as createMemberEndpoint, p as listMemberEndpoints, r as MemberEndpointWithLastDelivery, s as disableMemberEndpoint, t as CreateMemberEndpointOptions, u as getMemberDeliveryState, v as CreateMemberEndpointErrorCode, x as SendToMemberEndpointErrorCode, y as MemberEndpointErrorCode } from "./members-
|
|
2
|
-
import { R as sealWebhooksText, a as SendWebhookResult, s as WebhookEventBody, z as unsealWebhooksText } from "./runtime-
|
|
1
|
+
import { C as WebhookDeliveryErrorCode, S as SendWebhookErrorCode, _ as sendToMemberEndpoint, a as SendToMemberEndpointResult, b as MemberPairingErrorCode, c as enableMemberEndpoint, d as getMemberEndpoint, f as listMemberDeliveries, g as removeMemberEndpoints, h as removeMemberEndpoint, i as SendToMemberEndpointOptions, l as getMemberDelivery, m as memberEndpointHosts, n as MemberDeliveries, o as createMemberEndpoint, p as listMemberEndpoints, r as MemberEndpointWithLastDelivery, s as disableMemberEndpoint, t as CreateMemberEndpointOptions, u as getMemberDeliveryState, v as CreateMemberEndpointErrorCode, x as SendToMemberEndpointErrorCode, y as MemberEndpointErrorCode } from "./members-wi2GgyaN.js";
|
|
2
|
+
import { R as sealWebhooksText, a as SendWebhookResult, s as WebhookEventBody, z as unsealWebhooksText } from "./runtime-CjUMIHjQ.js";
|
|
3
3
|
import { a as WebhookOptions, c as defineWebhook, i as WebhookEvent, o as WebhookSignature, r as WebhookDefinition, s as WebhooksRetention } from "./queue-name-CWPhsc2U.js";
|
|
4
4
|
import { a as MemberLastDelivery, i as MemberEndpointKind, o as MemberPairingState, r as MemberEndpoint } from "./database-CQ0i7hWU.js";
|
|
5
5
|
import { Result } from "@vite-hub/runtime";
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { F as unsealWebhooksText, M as sealWebhooksText, O as checkWebhookUrl, x as sendDynamicWebhook, y as requireMemberEndpoints } from "./runtime-
|
|
2
|
-
import { n as defineWebhook } from "./queue-name-
|
|
3
|
-
import { a as getMemberDeliveryState, c as listMemberEndpoints, d as removeMemberEndpoint, f as removeMemberEndpoints, i as getMemberDelivery, l as memberEndpointHosts, n as disableMemberEndpoint, o as getMemberEndpoint, p as sendToMemberEndpoint, r as enableMemberEndpoint, s as listMemberDeliveries, t as createMemberEndpoint } from "./members-
|
|
4
|
-
import { t as webhooksErrors } from "./errors-
|
|
1
|
+
import { F as unsealWebhooksText, M as sealWebhooksText, O as checkWebhookUrl, x as sendDynamicWebhook, y as requireMemberEndpoints } from "./runtime-DOmUU6zG.js";
|
|
2
|
+
import { n as defineWebhook } from "./queue-name-0OM5djKH.js";
|
|
3
|
+
import { a as getMemberDeliveryState, c as listMemberEndpoints, d as removeMemberEndpoint, f as removeMemberEndpoints, i as getMemberDelivery, l as memberEndpointHosts, n as disableMemberEndpoint, o as getMemberEndpoint, p as sendToMemberEndpoint, r as enableMemberEndpoint, s as listMemberDeliveries, t as createMemberEndpoint } from "./members-D2BRslXn.js";
|
|
4
|
+
import { t as webhooksErrors } from "./errors-Dx-ml10b.js";
|
|
5
5
|
// src/pairing.ts
|
|
6
6
|
/** How long a pairing code works: 10 minutes. */
|
|
7
7
|
const memberPairingLifetime = 6e5;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as webhooksErrors } from "./errors-
|
|
2
|
-
import { A as memberBodyLabel, M as sealWebhooksText, N as sealedMemberBodyPrefix, O as checkWebhookUrl, P as unsealEndpoint, _ as pruneWebhookDeliveries, c as inspectDelivery, i as deliverMemberDelivery, j as sealEndpoint, k as outsideHosts, n as createDeliveryId, y as requireMemberEndpoints } from "./runtime-
|
|
1
|
+
import { t as webhooksErrors } from "./errors-Dx-ml10b.js";
|
|
2
|
+
import { A as memberBodyLabel, M as sealWebhooksText, N as sealedMemberBodyPrefix, O as checkWebhookUrl, P as unsealEndpoint, _ as pruneWebhookDeliveries, c as inspectDelivery, i as deliverMemberDelivery, j as sealEndpoint, k as outsideHosts, n as createDeliveryId, y as requireMemberEndpoints } from "./runtime-DOmUU6zG.js";
|
|
3
3
|
// \0rolldown/runtime.js
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __exportAll = (all, no_symbols) => {
|
|
@@ -27,7 +27,7 @@ declare const webhooksErrors: import("@vite-hub/runtime").ErrorCatalog<{
|
|
|
27
27
|
};
|
|
28
28
|
readonly WEBHOOKS_ENDPOINTS_OFF: {
|
|
29
29
|
readonly why: "Member endpoints are not on in this server. No feature of the app uses them, or the code runs outside the ViteHub server.";
|
|
30
|
-
readonly fix: "Turn on
|
|
30
|
+
readonly fix: "Turn on member endpoints from a Vite plugin with `vitehub.webhooks: { memberEndpoints: true, reason }`. In a test, call `installWebhooks({ webhooks: {}, store, endpoints })` from `@vite-hub/webhooks/runtime` first.";
|
|
31
31
|
};
|
|
32
32
|
readonly WEBHOOKS_FILE_INVALID: {
|
|
33
33
|
readonly why: ({ message }: {
|
package/dist/operations.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as AnyOperation } from "./operations-8hqTi0DH.js";
|
|
2
2
|
import { r as MemberEndpoint } from "./database-CQ0i7hWU.js";
|
|
3
|
-
import { r as MemberEndpointWithLastDelivery } from "./members-
|
|
3
|
+
import { r as MemberEndpointWithLastDelivery } from "./members-wi2GgyaN.js";
|
|
4
4
|
/**
|
|
5
5
|
* One member endpoint, as `webhooks.endpoints` lists it for admins: no URL, no secret, and no email. `mine` is true
|
|
6
6
|
* when the caller owns it, so the Console shows Redeliver only on the caller's own deliveries.
|
package/dist/operations.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as isRecordOrFunction } from "./object-CAK6UYR5.js";
|
|
2
|
-
import { t as webhooksErrors } from "./errors-
|
|
2
|
+
import { t as webhooksErrors } from "./errors-Dx-ml10b.js";
|
|
3
3
|
import { toJsonSchema } from "@valibot/to-json-schema";
|
|
4
4
|
import * as v from "valibot";
|
|
5
5
|
// ../../node_modules/.pnpm/nostics@1.4.0/node_modules/nostics/dist/index.mjs
|
|
@@ -511,7 +511,7 @@ function operationInputJsonSchema(operation) {
|
|
|
511
511
|
}
|
|
512
512
|
// src/operations.ts
|
|
513
513
|
const runtime = () => import("./runtime.js");
|
|
514
|
-
const members = () => import("./members-
|
|
514
|
+
const members = () => import("./members-D2BRslXn.js").then((n) => n.u);
|
|
515
515
|
const statuses = {
|
|
516
516
|
WEBHOOKS_BODY_INVALID: 400,
|
|
517
517
|
WEBHOOKS_DATABASE_MISSING: 409,
|
|
@@ -545,10 +545,6 @@ async function unwrap(run) {
|
|
|
545
545
|
if (result[0]) throw failure(result[0]);
|
|
546
546
|
return result[1];
|
|
547
547
|
}
|
|
548
|
-
/**
|
|
549
|
-
* Access to the Webhooks section of the Console decides. Most operations never read the signed-in user. Those with
|
|
550
|
-
* `user: true` do: a member delivery goes out again only for the member who owns its endpoint.
|
|
551
|
-
*/
|
|
552
548
|
function defineWebhooksOperation(definition, options = {}) {
|
|
553
549
|
return defineOperation({
|
|
554
550
|
...definition,
|
|
@@ -560,10 +556,6 @@ function defineWebhooksOperation(definition, options = {}) {
|
|
|
560
556
|
...options.user ? {} : { user: false }
|
|
561
557
|
});
|
|
562
558
|
}
|
|
563
|
-
/**
|
|
564
|
-
* The caller of a member action. A call that the ViteHub Console signs names a Console account, which is not an app
|
|
565
|
-
* user, so only its email can match the owner. Any other call names an app user by id.
|
|
566
|
-
*/
|
|
567
559
|
async function memberCaller(context) {
|
|
568
560
|
const { request, user } = context;
|
|
569
561
|
if (!user || context.access.via === "cli" || context.surface === "cli") return void 0;
|
|
@@ -584,7 +576,6 @@ function endpointChange(endpoint) {
|
|
|
584
576
|
disabledBy: endpoint.disabledBy
|
|
585
577
|
};
|
|
586
578
|
}
|
|
587
|
-
/** The name that the Console shows for the person who disabled an endpoint. */
|
|
588
579
|
function personLabel(context) {
|
|
589
580
|
const { user } = context;
|
|
590
581
|
if (!user) return context.surface === "cli" ? "the CLI" : "an admin";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as webhooksErrors } from "./errors-
|
|
1
|
+
import { t as webhooksErrors } from "./errors-Dx-ml10b.js";
|
|
2
2
|
import { runFailedEventNames } from "@vite-hub/runtime/internal/run-failed";
|
|
3
3
|
import { parseDuration } from "@vite-hub/runtime";
|
|
4
4
|
// src/define.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as WebhookDeliveryErrorCode, S as SendWebhookErrorCode, a as SendToMemberEndpointResult, w as webhooksErrors } from "./members-
|
|
1
|
+
import { C as WebhookDeliveryErrorCode, S as SendWebhookErrorCode, a as SendToMemberEndpointResult, w as webhooksErrors } from "./members-wi2GgyaN.js";
|
|
2
2
|
import { i as WebhookEvent, n as ResolvedWebhooksRetention, o as WebhookSignature, r as WebhookDefinition, s as WebhooksRetention } from "./queue-name-CWPhsc2U.js";
|
|
3
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
4
|
import { RunFailedEvent } from "@vite-hub/runtime/internal/run-failed";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as resolveWebhooksRetention, r as isWebhookDefinition } from "./queue-name-
|
|
2
|
-
import { t as webhooksErrors } from "./errors-
|
|
1
|
+
import { i as resolveWebhooksRetention, r as isWebhookDefinition } from "./queue-name-0OM5djKH.js";
|
|
2
|
+
import { t as webhooksErrors } from "./errors-Dx-ml10b.js";
|
|
3
3
|
import { signWebhook } from "@vite-hub/env";
|
|
4
4
|
import { onRunFailed } from "@vite-hub/runtime/internal/run-failed";
|
|
5
5
|
import { importSealKey, sealWithKey, unsealWithKey } from "@vite-hub/env/seal";
|
|
@@ -40,7 +40,7 @@ function serverEnv() {
|
|
|
40
40
|
...getViteHubTestMode()?.env
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
|
-
function
|
|
43
|
+
function readTrimmedString(env, name) {
|
|
44
44
|
const value = env[name];
|
|
45
45
|
return typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
46
46
|
}
|
|
@@ -49,7 +49,7 @@ function testKey() {
|
|
|
49
49
|
return getViteHubTestMode()?.backend("webhooks:key", () => btoa(String.fromCharCode(...crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(32)))));
|
|
50
50
|
}
|
|
51
51
|
async function endpointKey(developmentKey) {
|
|
52
|
-
const value =
|
|
52
|
+
const value = readTrimmedString(serverEnv(), "VITEHUB_WEBHOOKS_KEY") ?? testKey() ?? developmentKey;
|
|
53
53
|
if (!value) return [webhooksErrors.WEBHOOKS_KEY_UNSET(), void 0];
|
|
54
54
|
if (cached?.value !== value) {
|
|
55
55
|
const raw = decodeViteHubBase64Key(value);
|
|
@@ -343,7 +343,7 @@ function selectDefaultDatabase(useDatabase) {
|
|
|
343
343
|
}
|
|
344
344
|
function resolveTarget(name, definition) {
|
|
345
345
|
const env = serverEnv();
|
|
346
|
-
const url =
|
|
346
|
+
const url = readTrimmedString(env, definition.url);
|
|
347
347
|
if (!url) return [webhooksErrors.WEBHOOKS_URL_UNSET({
|
|
348
348
|
name: definition.url,
|
|
349
349
|
webhook: name
|
|
@@ -352,7 +352,7 @@ function resolveTarget(name, definition) {
|
|
|
352
352
|
name: definition.url,
|
|
353
353
|
webhook: name
|
|
354
354
|
}), void 0];
|
|
355
|
-
const secret =
|
|
355
|
+
const secret = readTrimmedString(env, definition.secret);
|
|
356
356
|
if (!secret) return [webhooksErrors.WEBHOOKS_SECRET_UNSET({
|
|
357
357
|
name: definition.secret,
|
|
358
358
|
webhook: name
|
|
@@ -752,7 +752,7 @@ function listWebhooks() {
|
|
|
752
752
|
const installed = requireInstalled();
|
|
753
753
|
const env = serverEnv();
|
|
754
754
|
return [...installed.webhooks].sort(([left], [right]) => left.localeCompare(right)).map(([name, definition]) => {
|
|
755
|
-
const url =
|
|
755
|
+
const url = readTrimmedString(env, definition.url);
|
|
756
756
|
return {
|
|
757
757
|
name,
|
|
758
758
|
url: definition.url,
|
|
@@ -761,7 +761,7 @@ function listWebhooks() {
|
|
|
761
761
|
debounceMs: definition.debounceMs,
|
|
762
762
|
events: definition.events,
|
|
763
763
|
urlSet: url !== void 0,
|
|
764
|
-
secretSet:
|
|
764
|
+
secretSet: readTrimmedString(env, definition.secret) !== void 0,
|
|
765
765
|
host: url !== void 0 && URL.canParse(url) ? new URL(url).host || null : null
|
|
766
766
|
};
|
|
767
767
|
});
|
|
@@ -791,7 +791,6 @@ function inspectDelivery(delivery) {
|
|
|
791
791
|
body: null
|
|
792
792
|
};
|
|
793
793
|
}
|
|
794
|
-
/** The member endpoint of a member delivery, when `caller` owns it. Throws the error that the action returns. */
|
|
795
794
|
async function ownedMemberEndpoint(installed, delivery, options) {
|
|
796
795
|
const id = delivery.webhook.slice(1);
|
|
797
796
|
const endpoint = await installed.endpoints?.find(id);
|
package/dist/runtime.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
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-
|
|
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-CjUMIHjQ.js";
|
|
3
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 { t as webhooksQueueName } from "./queue-name-
|
|
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-
|
|
1
|
+
import { t as webhooksQueueName } from "./queue-name-0OM5djKH.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-DOmUU6zG.js";
|
|
3
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
|
@@ -290,7 +290,7 @@ export declare function usesWebhooks(options: {
|
|
|
290
290
|
}): boolean;
|
|
291
291
|
/**
|
|
292
292
|
* What another package's Vite plugin puts in `vitehub.webhooks` to use Webhooks with no `server/webhooks/` files, such
|
|
293
|
-
* as
|
|
293
|
+
* as a package that sends to members. A function gets the project roots and the sibling plugins, and returns `undefined` when
|
|
294
294
|
* its feature is off.
|
|
295
295
|
*
|
|
296
296
|
* ```ts
|
package/dist/vite.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as isRecordOrFunction, t as isRecord } from "./object-CAK6UYR5.js";
|
|
2
|
-
import { i as resolveWebhooksRetention, t as webhooksQueueName } from "./queue-name-
|
|
3
|
-
import { t as webhooksErrors } from "./errors-
|
|
2
|
+
import { i as resolveWebhooksRetention, t as webhooksQueueName } from "./queue-name-0OM5djKH.js";
|
|
3
|
+
import { t as webhooksErrors } from "./errors-Dx-ml10b.js";
|
|
4
4
|
import { n as webhooksTableNames, t as webhookEndpointsTableNames } from "./table-names-DAUip4v2.js";
|
|
5
5
|
import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
6
6
|
import { tmpdir } from "node:os";
|
|
@@ -184,16 +184,11 @@ function objectProperties(object) {
|
|
|
184
184
|
value: unwrapExpression(node.value)
|
|
185
185
|
});
|
|
186
186
|
}
|
|
187
|
-
/** The value of a template literal without substitutions. */
|
|
188
187
|
function staticTemplate(node) {
|
|
189
188
|
if (node.expressions.length) return dynamic;
|
|
190
189
|
return node.quasis[0]?.value.cooked ?? dynamic;
|
|
191
190
|
}
|
|
192
191
|
const escapePattern = /\\(u\{[^}]*\}?|u[\s\S]{0,4}|x[\s\S]{0,2}|0\d|[\s\S])/g;
|
|
193
|
-
/**
|
|
194
|
-
* True when a string literal has an escape that strict mode code rejects. The parser recovers from some bad escapes
|
|
195
|
-
* and accepts legacy octal escapes, so the scanner checks them again.
|
|
196
|
-
*/
|
|
197
192
|
function hasInvalidEscape(raw) {
|
|
198
193
|
for (const [, escape = ""] of raw.matchAll(escapePattern)) if (escape.startsWith("u{")) {
|
|
199
194
|
const code = escape.slice(2, -1);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vite-hub/webhooks",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Send ViteHub events to an outside URL: signed, retried, and debounced on every host.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"debounce",
|
|
@@ -56,8 +56,8 @@
|
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"@standard-schema/spec": "^1.1.0",
|
|
58
58
|
"@valibot/to-json-schema": "^1.8.0",
|
|
59
|
-
"@vite-hub/env": "0.
|
|
60
|
-
"@vite-hub/runtime": "0.
|
|
59
|
+
"@vite-hub/env": "0.9.0",
|
|
60
|
+
"@vite-hub/runtime": "0.9.0",
|
|
61
61
|
"valibot": "^1.5.0"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
@@ -65,6 +65,7 @@
|
|
|
65
65
|
"@types/node": "^24.19.2",
|
|
66
66
|
"@vite-hub/internal": "0.0.1",
|
|
67
67
|
"drizzle-orm": "1.0.0-rc.6",
|
|
68
|
+
"fast-check": "^4.11.0",
|
|
68
69
|
"nitro": "^3.0.261103-rc",
|
|
69
70
|
"publint": "^0.3.25",
|
|
70
71
|
"typescript": "^6.0.3",
|