@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
package/README.md
CHANGED
|
@@ -79,6 +79,32 @@ Agent, Workflow, and Schedule send the event when a run fails with no retry left
|
|
|
79
79
|
|
|
80
80
|
Errors and stored fields never hold the URL, its query, or the secret. A delivery is one of `pending`, `sending`, `sent`, `dead`, or `cancelled`.
|
|
81
81
|
|
|
82
|
+
## Member endpoints
|
|
83
|
+
|
|
84
|
+
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, such as Send in Comments, or a Vite plugin with `vitehub.webhooks: { memberEndpoints: true, reason }`. They need `database`, not `queue`.
|
|
85
|
+
|
|
86
|
+
```ts [server/utils/send-comments.ts]
|
|
87
|
+
import { createMemberEndpoint, sendToMemberEndpoint } from "vite-hub/webhooks"
|
|
88
|
+
|
|
89
|
+
export async function connectAndSend(userId: string, url: string, secret: string) {
|
|
90
|
+
const [connectError] = await createMemberEndpoint({ owner: userId, name: "Launch plan thread", agent: "t3", kind: "url", url, secret })
|
|
91
|
+
if (connectError) return connectError.code
|
|
92
|
+
const [error, sent] = await sendToMemberEndpoint(userId, { threads: ["thr_1"] }, { event: "comments.send", key: "thr_1:msg_8" })
|
|
93
|
+
return error ? error.code : sent.status
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
| Function | Does |
|
|
98
|
+
| --- | --- |
|
|
99
|
+
| `createMemberEndpoint({ owner, ownerName?, ownerEmail?, name, kind, url?, secret?, agent?, address?, hosts? })` | Stores a member's receiver. `kind` is `"url"` or `"inbox"`. The URL must pass `checkWebhookUrl()` with `hosts`, which defaults to `relay.t3.codes`. `address` says where the agent can be reached, such as its T3 thread URL: a member has one endpoint per address, and a new one replaces the one with the same address. |
|
|
100
|
+
| `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. Returns `[error, { id, status }]`, where `status` is `"sent"`, `"inbox"`, `"pending"` (the Queue retries), or `"failed"`. |
|
|
101
|
+
| `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. |
|
|
102
|
+
| `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. Comments Send pairs this way. |
|
|
103
|
+
| `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. |
|
|
104
|
+
| `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. |
|
|
105
|
+
|
|
106
|
+
The URL and secret are sealed with AES-GCM and `VITEHUB_WEBHOOKS_KEY` (32 bytes in base64, from `openssl rand -base64 32`). `vite dev` generates one in `.vitehub/data/webhooks-key`. Without it in production, the functions return `WEBHOOKS_KEY_UNSET`. Each send is a delivery with `webhook: "@<endpoint id>"`. Only its owner can redeliver it or send it now: an app user whose id is `owner`, or a ViteHub Console account whose verified email matches `ownerEmail` and still resolves to `owner` in the app's Auth. Anyone else gets `WEBHOOKS_DELIVERY_NOT_OWNER` (403).
|
|
107
|
+
|
|
82
108
|
## Inspect and operate
|
|
83
109
|
|
|
84
110
|
`@vite-hub/webhooks/runtime` reads and changes deliveries in server code. Each function returns `[error, data]`.
|
|
@@ -89,9 +115,9 @@ Errors and stored fields never hold the URL, its query, or the secret. A deliver
|
|
|
89
115
|
| `listWebhookDeliveries({ webhook?, state?, limit?, before? })` | Deliveries, newest first |
|
|
90
116
|
| `listPendingWebhookDeliveries({ webhook?, limit? })` | Pending deliveries, the soonest due first |
|
|
91
117
|
| `getWebhookDelivery(id)` | One delivery |
|
|
92
|
-
| `flushWebhookDelivery(id)` | Delivers a pending delivery now |
|
|
118
|
+
| `flushWebhookDelivery(id, { caller? })` | Delivers a pending delivery now |
|
|
93
119
|
| `cancelWebhookDelivery(id)` | Cancels a pending delivery |
|
|
94
|
-
| `redeliverWebhookDelivery(id)` | Sends a sent, dead, or cancelled delivery again as a new delivery |
|
|
120
|
+
| `redeliverWebhookDelivery(id, { caller? })` | Sends a sent, dead, or cancelled delivery again as a new delivery. A member delivery needs its owner as `caller`, such as `{ id: user.id }`. |
|
|
95
121
|
| `testWebhook(name, { body? })` | Sends a test delivery now, without the debounce, with the event `webhooks.test` |
|
|
96
122
|
|
|
97
123
|
The same actions run from the terminal, the Console, and MCP as the `webhooks.*` operations on the app's operation RPC. `vitehub webhooks` reaches `vite dev`, or a deployed app with `--url`, and prints JSON:
|
|
@@ -105,20 +131,24 @@ vitehub webhooks test t3 --body '{"thread":"thr_1"}'
|
|
|
105
131
|
vitehub webhooks flush whd_...
|
|
106
132
|
vitehub webhooks cancel whd_...
|
|
107
133
|
vitehub webhooks redeliver whd_...
|
|
134
|
+
vitehub webhooks endpoints
|
|
135
|
+
vitehub webhooks deliveries --owner user_ana
|
|
136
|
+
vitehub webhooks disable-endpoint whe_...
|
|
137
|
+
vitehub webhooks enable-endpoint whe_...
|
|
108
138
|
```
|
|
109
139
|
|
|
110
|
-
`list`, `deliveries`, `pending`, and `
|
|
140
|
+
`list`, `deliveries`, `pending`, `get`, and `endpoints` only read, so MCP marks them read-only. The output shows the host of a URL, never its path, query, or the secret.
|
|
111
141
|
|
|
112
|
-
The Webhooks section of the Console shows each webhook with its host, signature, debounce, and the names of its URL and secret variables, then the pending timers with a countdown and the delivery log. Its buttons run Send test, Send now, Cancel, and Redeliver through the same operations. Set the variables in the Env section.
|
|
142
|
+
The Webhooks section of the Console shows each webhook with its host, signature, debounce, and the names of its URL and secret variables, then the pending timers with a countdown and the delivery log. Its buttons run Send test, Send now, Cancel, and Redeliver through the same operations. Set the variables in the Env section. With member endpoints on, it lists them first, read-only, with Disable and Enable, and the log filters by owner and endpoint.
|
|
113
143
|
|
|
114
144
|
## Public imports
|
|
115
145
|
|
|
116
146
|
| Import | Purpose |
|
|
117
147
|
| --- | --- |
|
|
118
|
-
| `@vite-hub/webhooks` | `defineWebhook()`, `sendWebhook()`, and the types |
|
|
148
|
+
| `@vite-hub/webhooks` | `defineWebhook()`, `sendWebhook()`, the member endpoint functions, `checkWebhookUrl()`, and the types |
|
|
119
149
|
| `@vite-hub/webhooks/runtime` | The delivery functions above, `installWebhooks()` for tests, and the Queue handler |
|
|
120
150
|
| `@vite-hub/webhooks/operations` | `webhooksOperations`, the operations of the Console, `vitehub webhooks`, and MCP |
|
|
121
|
-
| `@vite-hub/webhooks/database` | The
|
|
151
|
+
| `@vite-hub/webhooks/database` | The tables as `webhooksSchema` and `webhookEndpointsSchema`, as SQL in `webhooksTables`, `createDrizzleWebhookStore(db)`, and `createDrizzleWebhookEndpointStore(db)` |
|
|
122
152
|
| `@vite-hub/webhooks/vite` | `hubWebhooks()`, which `vite-hub` adds for you, and `webhooksConsoleSection` |
|
|
123
153
|
|
|
124
154
|
In a ViteHub app, import the same functions from `vite-hub/webhooks`.
|