@proofoftech/flowsafe 0.3.0 → 0.6.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/CHANGELOG.md +336 -0
- package/dist/agent-runner/approval-shapes.d.ts +36 -0
- package/dist/agent-runner/approval-shapes.d.ts.map +1 -0
- package/dist/agent-runner/approval-shapes.js +101 -0
- package/dist/agent-runner/approval-shapes.js.map +1 -0
- package/dist/agent-runner/durable-agent-runner.d.ts +154 -0
- package/dist/agent-runner/durable-agent-runner.d.ts.map +1 -0
- package/dist/agent-runner/durable-agent-runner.js +291 -0
- package/dist/agent-runner/durable-agent-runner.js.map +1 -0
- package/dist/agent-runner/index.d.ts +3 -0
- package/dist/agent-runner/index.d.ts.map +1 -0
- package/dist/agent-runner/index.js +10 -0
- package/dist/agent-runner/index.js.map +1 -0
- package/dist/approval-api/contract.d.ts +29 -0
- package/dist/approval-api/contract.d.ts.map +1 -1
- package/dist/approval-api/d1-store.d.ts.map +1 -1
- package/dist/approval-api/d1-store.js +112 -18
- package/dist/approval-api/d1-store.js.map +1 -1
- package/dist/approval-api/grants.d.ts +1 -1
- package/dist/approval-api/grants.d.ts.map +1 -1
- package/dist/approval-api/grants.js +8 -32
- package/dist/approval-api/grants.js.map +1 -1
- package/dist/approval-api/index.d.ts +2 -2
- package/dist/approval-api/index.d.ts.map +1 -1
- package/dist/approval-api/index.js.map +1 -1
- package/dist/approval-api/router.d.ts +1 -1
- package/dist/approval-api/router.d.ts.map +1 -1
- package/dist/approval-api/router.js +1 -0
- package/dist/approval-api/router.js.map +1 -1
- package/dist/approval-api/service.d.ts +24 -3
- package/dist/approval-api/service.d.ts.map +1 -1
- package/dist/approval-api/service.js +116 -1
- package/dist/approval-api/service.js.map +1 -1
- package/dist/approval-api/store.d.ts +29 -6
- package/dist/approval-api/store.d.ts.map +1 -1
- package/dist/approval-api/store.js +62 -2
- package/dist/approval-api/store.js.map +1 -1
- package/dist/approval-api/tenant-context.d.ts.map +1 -1
- package/dist/approval-api/tenant-context.js +17 -1
- package/dist/approval-api/tenant-context.js.map +1 -1
- package/dist/approval-api/tenant-store.d.ts.map +1 -1
- package/dist/approval-api/tenant-store.js +8 -2
- package/dist/approval-api/tenant-store.js.map +1 -1
- package/dist/approval-api/types.d.ts +19 -0
- package/dist/approval-api/types.d.ts.map +1 -1
- package/dist/approval-api/types.js +16 -0
- package/dist/approval-api/types.js.map +1 -1
- package/dist/approval-ui/App.d.ts +9 -1
- package/dist/approval-ui/App.d.ts.map +1 -1
- package/dist/approval-ui/App.js +10 -5
- package/dist/approval-ui/App.js.map +1 -1
- package/dist/approval-ui/DetailView.d.ts +4 -1
- package/dist/approval-ui/DetailView.d.ts.map +1 -1
- package/dist/approval-ui/DetailView.js +2 -2
- package/dist/approval-ui/DetailView.js.map +1 -1
- package/dist/approval-ui/QueueView.d.ts +7 -1
- package/dist/approval-ui/QueueView.d.ts.map +1 -1
- package/dist/approval-ui/QueueView.js +8 -3
- package/dist/approval-ui/QueueView.js.map +1 -1
- package/dist/approval-ui/client.d.ts +19 -0
- package/dist/approval-ui/client.d.ts.map +1 -1
- package/dist/approval-ui/client.js +29 -1
- package/dist/approval-ui/client.js.map +1 -1
- package/dist/approval-ui/components.d.ts +20 -0
- package/dist/approval-ui/components.d.ts.map +1 -1
- package/dist/approval-ui/components.js +2 -0
- package/dist/approval-ui/components.js.map +1 -1
- package/dist/approval-ui/index.d.ts +4 -2
- package/dist/approval-ui/index.d.ts.map +1 -1
- package/dist/approval-ui/index.js +3 -0
- package/dist/approval-ui/index.js.map +1 -1
- package/dist/approval-ui/stream.d.ts +142 -0
- package/dist/approval-ui/stream.d.ts.map +1 -0
- package/dist/approval-ui/stream.js +136 -0
- package/dist/approval-ui/stream.js.map +1 -0
- package/dist/approval-ui/use-approval-dashboard.d.ts +74 -1
- package/dist/approval-ui/use-approval-dashboard.d.ts.map +1 -1
- package/dist/approval-ui/use-approval-dashboard.js +307 -7
- package/dist/approval-ui/use-approval-dashboard.js.map +1 -1
- package/dist/approval-ui/use-web-socket-transport.d.ts +10 -0
- package/dist/approval-ui/use-web-socket-transport.d.ts.map +1 -0
- package/dist/approval-ui/use-web-socket-transport.js +46 -0
- package/dist/approval-ui/use-web-socket-transport.js.map +1 -0
- package/dist/background-tasks/d1-storage.d.ts +66 -0
- package/dist/background-tasks/d1-storage.d.ts.map +1 -0
- package/dist/background-tasks/d1-storage.js +196 -0
- package/dist/background-tasks/d1-storage.js.map +1 -0
- package/dist/background-tasks/host.d.ts +82 -0
- package/dist/background-tasks/host.d.ts.map +1 -0
- package/dist/background-tasks/host.js +275 -0
- package/dist/background-tasks/host.js.map +1 -0
- package/dist/background-tasks/index.d.ts +7 -0
- package/dist/background-tasks/index.d.ts.map +1 -0
- package/dist/background-tasks/index.js +10 -0
- package/dist/background-tasks/index.js.map +1 -0
- package/dist/background-tasks/routes.d.ts +15 -0
- package/dist/background-tasks/routes.d.ts.map +1 -0
- package/dist/background-tasks/routes.js +144 -0
- package/dist/background-tasks/routes.js.map +1 -0
- package/dist/do-runner/cf-types.d.ts +70 -2
- package/dist/do-runner/cf-types.d.ts.map +1 -1
- package/dist/do-runner/cf-types.js +30 -1
- package/dist/do-runner/cf-types.js.map +1 -1
- package/dist/do-runner/d1-storage.d.ts +343 -2
- package/dist/do-runner/d1-storage.d.ts.map +1 -1
- package/dist/do-runner/d1-storage.js +566 -13
- package/dist/do-runner/d1-storage.js.map +1 -1
- package/dist/do-runner/do-error-response.d.ts +29 -0
- package/dist/do-runner/do-error-response.d.ts.map +1 -0
- package/dist/do-runner/do-error-response.js +73 -0
- package/dist/do-runner/do-error-response.js.map +1 -0
- package/dist/do-runner/durable-object.d.ts +5 -2
- package/dist/do-runner/durable-object.d.ts.map +1 -1
- package/dist/do-runner/durable-object.js +87 -20
- package/dist/do-runner/durable-object.js.map +1 -1
- package/dist/do-runner/hub-do.d.ts +55 -0
- package/dist/do-runner/hub-do.d.ts.map +1 -0
- package/dist/do-runner/hub-do.js +197 -0
- package/dist/do-runner/hub-do.js.map +1 -0
- package/dist/do-runner/index.d.ts +12 -4
- package/dist/do-runner/index.d.ts.map +1 -1
- package/dist/do-runner/index.js +9 -2
- package/dist/do-runner/index.js.map +1 -1
- package/dist/do-runner/init.d.ts +20 -0
- package/dist/do-runner/init.d.ts.map +1 -1
- package/dist/do-runner/init.js +12 -1
- package/dist/do-runner/init.js.map +1 -1
- package/dist/do-runner/path-safe-id.js +1 -1
- package/dist/do-runner/path-safe-id.js.map +1 -1
- package/dist/do-runner/pubsub.d.ts +18 -0
- package/dist/do-runner/pubsub.d.ts.map +1 -0
- package/dist/do-runner/pubsub.js +42 -0
- package/dist/do-runner/pubsub.js.map +1 -0
- package/dist/do-runner/runtime.d.ts +24 -0
- package/dist/do-runner/runtime.d.ts.map +1 -1
- package/dist/do-runner/runtime.js +29 -2
- package/dist/do-runner/runtime.js.map +1 -1
- package/dist/do-runner/thread-do.d.ts +74 -0
- package/dist/do-runner/thread-do.d.ts.map +1 -0
- package/dist/do-runner/thread-do.js +156 -0
- package/dist/do-runner/thread-do.js.map +1 -0
- package/dist/do-runner/thread-header.d.ts +16 -0
- package/dist/do-runner/thread-header.d.ts.map +1 -0
- package/dist/do-runner/thread-header.js +24 -0
- package/dist/do-runner/thread-header.js.map +1 -0
- package/dist/goals/index.d.ts +2 -0
- package/dist/goals/index.d.ts.map +1 -0
- package/dist/goals/index.js +7 -0
- package/dist/goals/index.js.map +1 -0
- package/dist/goals/objective-routes.d.ts +87 -0
- package/dist/goals/objective-routes.d.ts.map +1 -0
- package/dist/goals/objective-routes.js +375 -0
- package/dist/goals/objective-routes.js.map +1 -0
- package/dist/host-kit/approval-bridge.d.ts +24 -4
- package/dist/host-kit/approval-bridge.d.ts.map +1 -1
- package/dist/host-kit/approval-bridge.js +32 -10
- package/dist/host-kit/approval-bridge.js.map +1 -1
- package/dist/host-kit/env-vars.d.ts +20 -0
- package/dist/host-kit/env-vars.d.ts.map +1 -1
- package/dist/host-kit/env-vars.js +30 -0
- package/dist/host-kit/env-vars.js.map +1 -1
- package/dist/host-kit/flowsafe-worker.d.ts +134 -5
- package/dist/host-kit/flowsafe-worker.d.ts.map +1 -1
- package/dist/host-kit/flowsafe-worker.js +283 -47
- package/dist/host-kit/flowsafe-worker.js.map +1 -1
- package/dist/host-kit/host-approval-service.d.ts +20 -1
- package/dist/host-kit/host-approval-service.d.ts.map +1 -1
- package/dist/host-kit/host-approval-service.js +15 -0
- package/dist/host-kit/host-approval-service.js.map +1 -1
- package/dist/host-kit/hub-topology.d.ts +35 -0
- package/dist/host-kit/hub-topology.d.ts.map +1 -0
- package/dist/host-kit/hub-topology.js +32 -0
- package/dist/host-kit/hub-topology.js.map +1 -0
- package/dist/host-kit/index.d.ts +8 -1
- package/dist/host-kit/index.d.ts.map +1 -1
- package/dist/host-kit/index.js +10 -0
- package/dist/host-kit/index.js.map +1 -1
- package/dist/host-kit/memory-boundary.d.ts +64 -0
- package/dist/host-kit/memory-boundary.d.ts.map +1 -0
- package/dist/host-kit/memory-boundary.js +109 -0
- package/dist/host-kit/memory-boundary.js.map +1 -0
- package/dist/host-kit/route-path.d.ts +17 -0
- package/dist/host-kit/route-path.d.ts.map +1 -0
- package/dist/host-kit/route-path.js +35 -0
- package/dist/host-kit/route-path.js.map +1 -0
- package/dist/host-kit/stream-router.d.ts +22 -0
- package/dist/host-kit/stream-router.d.ts.map +1 -0
- package/dist/host-kit/stream-router.js +191 -0
- package/dist/host-kit/stream-router.js.map +1 -0
- package/dist/host-kit/stream-ticket.d.ts +55 -0
- package/dist/host-kit/stream-ticket.d.ts.map +1 -0
- package/dist/host-kit/stream-ticket.js +156 -0
- package/dist/host-kit/stream-ticket.js.map +1 -0
- package/dist/host-kit/tenant-registry.js +1 -1
- package/dist/host-kit/tenant-registry.js.map +1 -1
- package/dist/host-kit/thread-topology.d.ts +44 -0
- package/dist/host-kit/thread-topology.d.ts.map +1 -0
- package/dist/host-kit/thread-topology.js +76 -0
- package/dist/host-kit/thread-topology.js.map +1 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/internal-error-response.d.ts +3 -0
- package/dist/internal-error-response.d.ts.map +1 -0
- package/dist/internal-error-response.js +20 -0
- package/dist/internal-error-response.js.map +1 -0
- package/dist/numeric-config.d.ts +4 -0
- package/dist/numeric-config.d.ts.map +1 -0
- package/dist/numeric-config.js +23 -0
- package/dist/numeric-config.js.map +1 -0
- package/dist/schedules/index.d.ts +5 -0
- package/dist/schedules/index.d.ts.map +1 -0
- package/dist/schedules/index.js +13 -0
- package/dist/schedules/index.js.map +1 -0
- package/dist/schedules/router.d.ts +66 -0
- package/dist/schedules/router.d.ts.map +1 -0
- package/dist/schedules/router.js +827 -0
- package/dist/schedules/router.js.map +1 -0
- package/dist/schedules/schedules-d1.d.ts +30 -0
- package/dist/schedules/schedules-d1.d.ts.map +1 -0
- package/dist/schedules/schedules-d1.js +374 -0
- package/dist/schedules/schedules-d1.js.map +1 -0
- package/dist/schedules/storage.d.ts +11 -0
- package/dist/schedules/storage.d.ts.map +1 -0
- package/dist/schedules/storage.js +34 -0
- package/dist/schedules/storage.js.map +1 -0
- package/dist/schedules/tick.d.ts +131 -0
- package/dist/schedules/tick.d.ts.map +1 -0
- package/dist/schedules/tick.js +598 -0
- package/dist/schedules/tick.js.map +1 -0
- package/dist/signal-providers/delivery.d.ts +24 -0
- package/dist/signal-providers/delivery.d.ts.map +1 -0
- package/dist/signal-providers/delivery.js +62 -0
- package/dist/signal-providers/delivery.js.map +1 -0
- package/dist/signal-providers/github-provider.d.ts +33 -0
- package/dist/signal-providers/github-provider.d.ts.map +1 -0
- package/dist/signal-providers/github-provider.js +116 -0
- package/dist/signal-providers/github-provider.js.map +1 -0
- package/dist/signal-providers/host-do.d.ts +79 -0
- package/dist/signal-providers/host-do.d.ts.map +1 -0
- package/dist/signal-providers/host-do.js +216 -0
- package/dist/signal-providers/host-do.js.map +1 -0
- package/dist/signal-providers/index.d.ts +7 -0
- package/dist/signal-providers/index.d.ts.map +1 -0
- package/dist/signal-providers/index.js +19 -0
- package/dist/signal-providers/index.js.map +1 -0
- package/dist/signal-providers/provider.d.ts +92 -0
- package/dist/signal-providers/provider.d.ts.map +1 -0
- package/dist/signal-providers/provider.js +87 -0
- package/dist/signal-providers/provider.js.map +1 -0
- package/dist/signal-providers/subscription-d1.d.ts +88 -0
- package/dist/signal-providers/subscription-d1.d.ts.map +1 -0
- package/dist/signal-providers/subscription-d1.js +259 -0
- package/dist/signal-providers/subscription-d1.js.map +1 -0
- package/dist/signal-providers/webhook-route.d.ts +88 -0
- package/dist/signal-providers/webhook-route.d.ts.map +1 -0
- package/dist/signal-providers/webhook-route.js +391 -0
- package/dist/signal-providers/webhook-route.js.map +1 -0
- package/dist/signals/client.d.ts +72 -0
- package/dist/signals/client.d.ts.map +1 -0
- package/dist/signals/client.js +87 -0
- package/dist/signals/client.js.map +1 -0
- package/dist/signals/d1-shared.d.ts +43 -0
- package/dist/signals/d1-shared.d.ts.map +1 -0
- package/dist/signals/d1-shared.js +46 -0
- package/dist/signals/d1-shared.js.map +1 -0
- package/dist/signals/index.d.ts +9 -0
- package/dist/signals/index.d.ts.map +1 -0
- package/dist/signals/index.js +15 -0
- package/dist/signals/index.js.map +1 -0
- package/dist/signals/notification-dispatch.d.ts +52 -0
- package/dist/signals/notification-dispatch.d.ts.map +1 -0
- package/dist/signals/notification-dispatch.js +198 -0
- package/dist/signals/notification-dispatch.js.map +1 -0
- package/dist/signals/notifications-d1.d.ts +28 -0
- package/dist/signals/notifications-d1.d.ts.map +1 -0
- package/dist/signals/notifications-d1.js +704 -0
- package/dist/signals/notifications-d1.js.map +1 -0
- package/dist/signals/router.d.ts +73 -0
- package/dist/signals/router.d.ts.map +1 -0
- package/dist/signals/router.js +240 -0
- package/dist/signals/router.js.map +1 -0
- package/dist/signals/storage.d.ts +11 -0
- package/dist/signals/storage.d.ts.map +1 -0
- package/dist/signals/storage.js +27 -0
- package/dist/signals/storage.js.map +1 -0
- package/dist/signals/thread-do-routes.d.ts +82 -0
- package/dist/signals/thread-do-routes.d.ts.map +1 -0
- package/dist/signals/thread-do-routes.js +660 -0
- package/dist/signals/thread-do-routes.js.map +1 -0
- package/dist/signals/thread-state-d1.d.ts +22 -0
- package/dist/signals/thread-state-d1.d.ts.map +1 -0
- package/dist/signals/thread-state-d1.js +83 -0
- package/dist/signals/thread-state-d1.js.map +1 -0
- package/package.json +11 -2
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Track E (M-007) — the delivery seam: a matched subscription's notification is
|
|
3
|
+
// routed into its thread through host-kit's `createThreadTopology.send`, the
|
|
4
|
+
// SANCTIONED reach into a per-thread DO (DL-002). NEVER the raw namespace: the
|
|
5
|
+
// topology ownership-404s the threadId against the tenant BEFORE the DO is
|
|
6
|
+
// addressed AND stamps the `x-flowsafe-tenant` header the thread DO
|
|
7
|
+
// authenticates on — a forged tenant can never ride in (thread-topology.ts).
|
|
8
|
+
//
|
|
9
|
+
// The ROW is the tenant authority. A subscription carries its own `tenantId`
|
|
10
|
+
// (server-stamped at subscribe, never from a webhook payload), so delivery binds
|
|
11
|
+
// to `deliveryTenantContext(subscription.tenantId)`. If a row were tampered so
|
|
12
|
+
// its `threadId` belonged to another tenant, the topology's `ownsMemoryId` check
|
|
13
|
+
// fails and the send 404s — fail closed, no cross-tenant delivery (the cross-
|
|
14
|
+
// tenant probe).
|
|
15
|
+
import { assertMintableTenantId, mintResourceId, mintSaltedId, mintThreadId, tenantOwnsSaltedId, } from '../do-runner/index.js';
|
|
16
|
+
/**
|
|
17
|
+
* A TenantContext for the SERVER-DERIVED delivery path — built from a trusted,
|
|
18
|
+
* INV-3 tenantId recovered from a subscription row, never from client input. The
|
|
19
|
+
* topology reads only `.tenantId` and `.ownsMemoryId`; the pure id helpers are
|
|
20
|
+
* provided for completeness, and the request-scoped `service()` throws (a
|
|
21
|
+
* delivery has no request, no store) so a misuse is loud rather than silent.
|
|
22
|
+
*/
|
|
23
|
+
export function deliveryTenantContext(tenantId) {
|
|
24
|
+
assertMintableTenantId(tenantId, 'deliveryTenantContext');
|
|
25
|
+
const actor = {
|
|
26
|
+
id: 'signal-provider-delivery',
|
|
27
|
+
role: 'operator',
|
|
28
|
+
tenantId,
|
|
29
|
+
};
|
|
30
|
+
return {
|
|
31
|
+
actor,
|
|
32
|
+
tenantId,
|
|
33
|
+
service: () => {
|
|
34
|
+
throw new Error('deliveryTenantContext: no approval service on the signal-provider delivery path');
|
|
35
|
+
},
|
|
36
|
+
newRunId: () => mintSaltedId(tenantId, () => crypto.randomUUID(), 'deliveryTenantContext'),
|
|
37
|
+
ownsRun: (runId) => tenantOwnsSaltedId(tenantId, runId),
|
|
38
|
+
newThreadId: () => mintThreadId(tenantId, () => crypto.randomUUID()),
|
|
39
|
+
newResourceId: (resourceKey) => mintResourceId(tenantId, resourceKey),
|
|
40
|
+
ownsMemoryId: (id) => tenantOwnsSaltedId(tenantId, id),
|
|
41
|
+
// A delivery decides nothing; the display hint is irrelevant on this path.
|
|
42
|
+
canSelfDecide: () => false,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Deliver ONE notification to a matched subscription's thread through the
|
|
47
|
+
* topology. Returns the thread DO's Response (a 404 when the row's threadId is
|
|
48
|
+
* not owned by its tenant — the fail-closed cross-tenant case). The whole
|
|
49
|
+
* `SendNotificationSignalInput` is forwarded; the thread-DO `/signal/notification`
|
|
50
|
+
* route reads what it needs (source/kind/summary/priority/payload/dedupeKey/
|
|
51
|
+
* coalesceKey/attributes) and derives the resourceId from ITS own scope (a thread
|
|
52
|
+
* has one owner — the row's resourceId — so delivery keys the inbox identically
|
|
53
|
+
* whether the signal arrived from a client ingest or a provider webhook).
|
|
54
|
+
*/
|
|
55
|
+
export async function deliverNotification(topology, subscription, notification) {
|
|
56
|
+
return topology.send(deliveryTenantContext(subscription.tenantId), subscription.threadId, '/signal/notification', {
|
|
57
|
+
method: 'POST',
|
|
58
|
+
headers: { 'content-type': 'application/json' },
|
|
59
|
+
body: JSON.stringify(notification),
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=delivery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delivery.js","sourceRoot":"","sources":["../../src/signal-providers/delivery.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,gFAAgF;AAChF,6EAA6E;AAC7E,+EAA+E;AAC/E,2EAA2E;AAC3E,oEAAoE;AACpE,6EAA6E;AAC7E,EAAE;AACF,6EAA6E;AAC7E,iFAAiF;AACjF,+EAA+E;AAC/E,iFAAiF;AACjF,8EAA8E;AAC9E,iBAAiB;AAKjB,OAAO,EACL,sBAAsB,EACtB,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,kBAAkB,GACnB,MAAM,uBAAuB,CAAC;AAI/B;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CAAC,QAAgB;IACpD,sBAAsB,CAAC,QAAQ,EAAE,uBAAuB,CAAC,CAAC;IAC1D,MAAM,KAAK,GAAkB;QAC3B,EAAE,EAAE,0BAA0B;QAC9B,IAAI,EAAE,UAAU;QAChB,QAAQ;KACT,CAAC;IACF,OAAO;QACL,KAAK;QACL,QAAQ;QACR,OAAO,EAAE,GAAG,EAAE;YACZ,MAAM,IAAI,KAAK,CACb,iFAAiF,CAClF,CAAC;QACJ,CAAC;QACD,QAAQ,EAAE,GAAG,EAAE,CACb,YAAY,CACV,QAAQ,EACR,GAAG,EAAE,CAAC,MAAM,CAAC,UAAU,EAAE,EACzB,uBAAuB,CACxB;QACH,OAAO,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,kBAAkB,CAAC,QAAQ,EAAE,KAAK,CAAC;QAC/D,WAAW,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;QACpE,aAAa,EAAE,CAAC,WAAmB,EAAE,EAAE,CACrC,cAAc,CAAC,QAAQ,EAAE,WAAW,CAAC;QACvC,YAAY,EAAE,CAAC,EAAU,EAAE,EAAE,CAAC,kBAAkB,CAAC,QAAQ,EAAE,EAAE,CAAC;QAC9D,2EAA2E;QAC3E,aAAa,EAAE,GAAG,EAAE,CAAC,KAAK;KAC3B,CAAC;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,QAAwB,EACxB,YAAgC,EAChC,YAAyC;IAEzC,OAAO,QAAQ,CAAC,IAAI,CAClB,qBAAqB,CAAC,YAAY,CAAC,QAAQ,CAAC,EAC5C,YAAY,CAAC,QAAQ,EACrB,sBAAsB,EACtB;QACE,MAAM,EAAE,MAAM;QACd,OAAO,EAAE,EAAE,cAAc,EAAE,kBAAkB,EAAE;QAC/C,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC;KACnC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { SendNotificationSignalInput } from '@mastra/core/notifications';
|
|
2
|
+
import type { SignalSubscription } from '@mastra/core/signals';
|
|
3
|
+
import { type SignalProviderAdapter, type WebhookHeaders } from './provider.js';
|
|
4
|
+
/**
|
|
5
|
+
* Verify GitHub's `X-Hub-Signature-256` over the RAW bytes, constant-time.
|
|
6
|
+
* `crypto.subtle.verify` is the constant-time comparison (never a string ===),
|
|
7
|
+
* so a valid-length forged signature reveals nothing through timing. A missing
|
|
8
|
+
* header, wrong prefix, non-hex, or wrong-length signature all fail closed.
|
|
9
|
+
*/
|
|
10
|
+
export declare function verifyGithubSignature(rawBody: Uint8Array, headers: WebhookHeaders, secret: string): Promise<boolean>;
|
|
11
|
+
/**
|
|
12
|
+
* The external-resource key(s) a GitHub payload concerns — matched against a
|
|
13
|
+
* subscription's `externalResourceId`. A repo event yields `github:<full_name>`;
|
|
14
|
+
* an issue / PR event ALSO yields `github:<full_name>#<number>`, so a
|
|
15
|
+
* subscription may watch the whole repo OR one issue/PR. Nothing usable ⇒ [].
|
|
16
|
+
*/
|
|
17
|
+
export declare function extractGithubResourceIds(payload: unknown): string[];
|
|
18
|
+
/** Build the notification a matched GitHub subscription receives. */
|
|
19
|
+
export declare function buildGithubNotification(payload: unknown, subscription: SignalSubscription): SendNotificationSignalInput;
|
|
20
|
+
export interface GithubSignalProviderOptions {
|
|
21
|
+
/** Provider id (default 'github'); must be a lowercase slug with no '_'. */
|
|
22
|
+
id?: string;
|
|
23
|
+
name?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The GitHub reference provider: `X-Hub-Signature-256` verification + repo/issue
|
|
27
|
+
* resource extraction + a GitHub notification shape, over the generic webhook
|
|
28
|
+
* provider. The signing secret is NOT held here — the webhook route supplies it
|
|
29
|
+
* per request from the host binding, so an unconfigured deployment simply never
|
|
30
|
+
* registers this provider.
|
|
31
|
+
*/
|
|
32
|
+
export declare function githubSignalProvider(options?: GithubSignalProviderOptions): SignalProviderAdapter;
|
|
33
|
+
//# sourceMappingURL=github-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"github-provider.d.ts","sourceRoot":"","sources":["../../src/signal-providers/github-provider.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAC;AAC9E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE/D,OAAO,EAEL,KAAK,qBAAqB,EAC1B,KAAK,cAAc,EACpB,MAAM,eAAe,CAAC;AAuBvB;;;;;GAKG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,UAAU,EACnB,OAAO,EAAE,cAAc,EACvB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,OAAO,CAAC,CAyBlB;AAaD;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,EAAE,CAWnE;AAED,qEAAqE;AACrE,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,OAAO,EAChB,YAAY,EAAE,kBAAkB,GAC/B,2BAA2B,CAsB7B;AAED,MAAM,WAAW,2BAA2B;IAC1C,4EAA4E;IAC5E,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,GAAE,2BAAgC,GACxC,qBAAqB,CAQvB"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Track E (M-007) — the binding-gated GitHub signal provider, the DL-017
|
|
3
|
+
// showcase reference connector. Webhook-only: GitHub pushes events, so there is
|
|
4
|
+
// no poll seam. Its signature scheme is GitHub's `X-Hub-Signature-256`
|
|
5
|
+
// (`sha256=<hex HMAC-SHA256(secret, rawBody)>`), verified over the RAW request
|
|
6
|
+
// bytes BEFORE any parse and CONSTANT-TIME via `crypto.subtle.verify` (the same
|
|
7
|
+
// WebCrypto primitive host-kit's verifier uses — never a hand-rolled compare).
|
|
8
|
+
//
|
|
9
|
+
// It mints NO capability (P8): a GitHub event is untrusted context that lands in
|
|
10
|
+
// a thread's inbox as a notification, never an approval. The secret is a
|
|
11
|
+
// per-deployment binding/env value; unconfigured ⇒ the host never registers this
|
|
12
|
+
// provider ⇒ its webhook route 404s ⇒ byte-identical.
|
|
13
|
+
import { createWebhookSignalProvider, } from './provider.js';
|
|
14
|
+
const encoder = new TextEncoder();
|
|
15
|
+
/** The GitHub delivery-signature header (lowercased; `Headers.get` is case-insensitive). */
|
|
16
|
+
const SIGNATURE_HEADER = 'x-hub-signature-256';
|
|
17
|
+
const SIGNATURE_PREFIX = 'sha256=';
|
|
18
|
+
/** SHA-256 digest length in bytes — a signature of any other length is malformed. */
|
|
19
|
+
const SHA256_BYTES = 32;
|
|
20
|
+
/** Decode a lowercase/uppercase hex string to bytes, or undefined if malformed. */
|
|
21
|
+
function hexToBytes(hex) {
|
|
22
|
+
if (hex.length === 0 || hex.length % 2 !== 0)
|
|
23
|
+
return undefined;
|
|
24
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
25
|
+
for (let index = 0; index < bytes.length; index += 1) {
|
|
26
|
+
const byte = Number.parseInt(hex.slice(index * 2, index * 2 + 2), 16);
|
|
27
|
+
// parseInt tolerates trailing garbage; Number.isNaN catches non-hex.
|
|
28
|
+
if (Number.isNaN(byte))
|
|
29
|
+
return undefined;
|
|
30
|
+
bytes[index] = byte;
|
|
31
|
+
}
|
|
32
|
+
return bytes;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Verify GitHub's `X-Hub-Signature-256` over the RAW bytes, constant-time.
|
|
36
|
+
* `crypto.subtle.verify` is the constant-time comparison (never a string ===),
|
|
37
|
+
* so a valid-length forged signature reveals nothing through timing. A missing
|
|
38
|
+
* header, wrong prefix, non-hex, or wrong-length signature all fail closed.
|
|
39
|
+
*/
|
|
40
|
+
export async function verifyGithubSignature(rawBody, headers, secret) {
|
|
41
|
+
const header = headers.get(SIGNATURE_HEADER);
|
|
42
|
+
if (header === null || !header.startsWith(SIGNATURE_PREFIX))
|
|
43
|
+
return false;
|
|
44
|
+
const signature = hexToBytes(header.slice(SIGNATURE_PREFIX.length));
|
|
45
|
+
if (signature === undefined || signature.length !== SHA256_BYTES)
|
|
46
|
+
return false;
|
|
47
|
+
// Fail closed on an empty secret rather than importing a zero-length HMAC key:
|
|
48
|
+
// Node's WebCrypto THROWS on it, and a runtime that ACCEPTS one would verify
|
|
49
|
+
// against a known (empty) key — a trivial forgery. The webhook route already
|
|
50
|
+
// treats '' as unconfigured; this is the defense-in-depth at the crypto seam.
|
|
51
|
+
if (secret.length === 0)
|
|
52
|
+
return false;
|
|
53
|
+
const key = await crypto.subtle.importKey('raw', encoder.encode(secret), { name: 'HMAC', hash: 'SHA-256' }, false, ['verify']);
|
|
54
|
+
// BufferSource args: a Uint8Array over the exact bytes GitHub signed.
|
|
55
|
+
return crypto.subtle.verify('HMAC', key, signature, rawBody);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The external-resource key(s) a GitHub payload concerns — matched against a
|
|
59
|
+
* subscription's `externalResourceId`. A repo event yields `github:<full_name>`;
|
|
60
|
+
* an issue / PR event ALSO yields `github:<full_name>#<number>`, so a
|
|
61
|
+
* subscription may watch the whole repo OR one issue/PR. Nothing usable ⇒ [].
|
|
62
|
+
*/
|
|
63
|
+
export function extractGithubResourceIds(payload) {
|
|
64
|
+
if (typeof payload !== 'object' || payload === null)
|
|
65
|
+
return [];
|
|
66
|
+
const event = payload;
|
|
67
|
+
const fullName = event.repository?.full_name;
|
|
68
|
+
if (typeof fullName !== 'string' || fullName.length === 0)
|
|
69
|
+
return [];
|
|
70
|
+
const keys = [`github:${fullName}`];
|
|
71
|
+
const number = event.issue?.number ?? event.pull_request?.number;
|
|
72
|
+
if (typeof number === 'number') {
|
|
73
|
+
keys.push(`github:${fullName}#${number}`);
|
|
74
|
+
}
|
|
75
|
+
return keys;
|
|
76
|
+
}
|
|
77
|
+
/** Build the notification a matched GitHub subscription receives. */
|
|
78
|
+
export function buildGithubNotification(payload, subscription) {
|
|
79
|
+
const event = typeof payload === 'object' && payload !== null
|
|
80
|
+
? payload
|
|
81
|
+
: {};
|
|
82
|
+
const action = typeof event.action === 'string' ? event.action : undefined;
|
|
83
|
+
// Kind: the action for issue/PR events, 'push' for a ref-bearing push, else a
|
|
84
|
+
// generic 'event'. GitHub's X-GitHub-Event header is the richer source, but
|
|
85
|
+
// the adapter's buildNotification sees only the payload — the action/ref shape
|
|
86
|
+
// is enough for a reference notification.
|
|
87
|
+
const kind = action ?? (typeof event.ref === 'string' ? 'push' : 'event');
|
|
88
|
+
return {
|
|
89
|
+
source: 'github',
|
|
90
|
+
kind,
|
|
91
|
+
summary: `GitHub ${subscription.externalResourceId}: ${kind}`,
|
|
92
|
+
priority: 'medium',
|
|
93
|
+
payload,
|
|
94
|
+
attributes: {
|
|
95
|
+
resource: subscription.externalResourceId,
|
|
96
|
+
...(action !== undefined ? { action } : {}),
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The GitHub reference provider: `X-Hub-Signature-256` verification + repo/issue
|
|
102
|
+
* resource extraction + a GitHub notification shape, over the generic webhook
|
|
103
|
+
* provider. The signing secret is NOT held here — the webhook route supplies it
|
|
104
|
+
* per request from the host binding, so an unconfigured deployment simply never
|
|
105
|
+
* registers this provider.
|
|
106
|
+
*/
|
|
107
|
+
export function githubSignalProvider(options = {}) {
|
|
108
|
+
return createWebhookSignalProvider({
|
|
109
|
+
id: options.id ?? 'github',
|
|
110
|
+
name: options.name ?? 'GitHub',
|
|
111
|
+
verifyWebhookSignature: verifyGithubSignature,
|
|
112
|
+
extractResourceIds: extractGithubResourceIds,
|
|
113
|
+
buildNotification: buildGithubNotification,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=github-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"github-provider.js","sourceRoot":"","sources":["../../src/signal-providers/github-provider.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,yEAAyE;AACzE,gFAAgF;AAChF,uEAAuE;AACvE,+EAA+E;AAC/E,gFAAgF;AAChF,+EAA+E;AAC/E,EAAE;AACF,iFAAiF;AACjF,yEAAyE;AACzE,iFAAiF;AACjF,sDAAsD;AAKtD,OAAO,EACL,2BAA2B,GAG5B,MAAM,eAAe,CAAC;AAEvB,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAElC,4FAA4F;AAC5F,MAAM,gBAAgB,GAAG,qBAAqB,CAAC;AAC/C,MAAM,gBAAgB,GAAG,SAAS,CAAC;AACnC,qFAAqF;AACrF,MAAM,YAAY,GAAG,EAAE,CAAC;AAEx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,CAAC,CAAC,EAAE,CAAC;IACT,MAAM,MAAM,GAAG,OAAO,KAAK,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3E,8EAA8E;IAC9E,4EAA4E;IAC5E,+EAA+E;IAC/E,0CAA0C;IAC1C,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,OAAO,KAAK,CAAC,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;IAC1E,OAAO;QACL,MAAM,EAAE,QAAQ;QAChB,IAAI;QACJ,OAAO,EAAE,UAAU,YAAY,CAAC,kBAAkB,KAAK,IAAI,EAAE;QAC7D,QAAQ,EAAE,QAAQ;QAClB,OAAO;QACP,UAAU,EAAE;YACV,QAAQ,EAAE,YAAY,CAAC,kBAAkB;YACzC,GAAG,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC5C;KACF,CAAC;AACJ,CAAC;AAQD;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAClC,UAAuC,EAAE;IAEzC,OAAO,2BAA2B,CAAC;QACjC,EAAE,EAAE,OAAO,CAAC,EAAE,IAAI,QAAQ;QAC1B,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,QAAQ;QAC9B,sBAAsB,EAAE,qBAAqB;QAC7C,kBAAkB,EAAE,wBAAwB;QAC5C,iBAAiB,EAAE,uBAAuB;KAC3C,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { DoStatusError } from '../do-runner/index.js';
|
|
2
|
+
import type { ThreadTopology } from '../host-kit/index.js';
|
|
3
|
+
import type { SignalProviderAdapter } from './provider.js';
|
|
4
|
+
import type { TenantBoundSubscriptionStore } from './subscription-d1.js';
|
|
5
|
+
/** The `ctx.storage` alarm subset the host DO arms itself through. */
|
|
6
|
+
export interface AlarmStorage {
|
|
7
|
+
setAlarm(scheduledTime: number): void | Promise<void>;
|
|
8
|
+
deleteAlarm(): void | Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* The DO-state subset the host reads: its own `id.name` (the tenant) and the
|
|
12
|
+
* alarm storage. `storage` is OPTIONAL so a node/vitest stub that sets only
|
|
13
|
+
* `id.name` satisfies it and drives `poll()` directly (no alarm off workerd).
|
|
14
|
+
*/
|
|
15
|
+
export interface SignalProviderHostState {
|
|
16
|
+
readonly id: {
|
|
17
|
+
readonly name?: string;
|
|
18
|
+
};
|
|
19
|
+
readonly storage?: AlarmStorage;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A host DO whose name carries no INV-3 tenant. 403 — this boundary is internal
|
|
23
|
+
* (not client-reachable), so there is no oracle to protect and a distinct status
|
|
24
|
+
* keeps a routing bug from reading as a 500. Extends DoStatusError so
|
|
25
|
+
* doErrorResponse recognizes it.
|
|
26
|
+
*/
|
|
27
|
+
export declare class SignalProviderHostIdentityError extends DoStatusError {
|
|
28
|
+
readonly status = 403;
|
|
29
|
+
constructor(message: string);
|
|
30
|
+
}
|
|
31
|
+
/** The per-instance wiring a subclass supplies, memoized by the base. */
|
|
32
|
+
export interface SignalProviderHostWiring {
|
|
33
|
+
/** Subscription store BOUND to this host's tenant (the rehydration source). */
|
|
34
|
+
store: TenantBoundSubscriptionStore;
|
|
35
|
+
/** The sanctioned reach into a thread DO (delivery). */
|
|
36
|
+
topology: ThreadTopology;
|
|
37
|
+
/** Every provider this tenant hosts. */
|
|
38
|
+
providers: readonly SignalProviderAdapter[];
|
|
39
|
+
}
|
|
40
|
+
export interface PollResult {
|
|
41
|
+
providersPolled: number;
|
|
42
|
+
delivered: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The provider host DO base. Subclass it, supply `build()` (the tenant-bound
|
|
46
|
+
* subscription store + thread topology + provider list from env), and bind the
|
|
47
|
+
* subclass under a wrangler namespace addressed `idFromName(tenantId)`.
|
|
48
|
+
*
|
|
49
|
+
* Routes: `POST /arm` (boot + arm the alarm), `POST /poll` (run one poll cycle —
|
|
50
|
+
* the deterministic probe the spike drives so E-S3 does not depend on wrangler's
|
|
51
|
+
* alarm timer). `alarm()` polls then re-arms.
|
|
52
|
+
*/
|
|
53
|
+
export declare abstract class SignalProviderHost<TEnv = unknown> {
|
|
54
|
+
#private;
|
|
55
|
+
protected readonly env: TEnv;
|
|
56
|
+
protected readonly state?: SignalProviderHostState;
|
|
57
|
+
constructor(state: SignalProviderHostState | undefined, env: TEnv);
|
|
58
|
+
/** Build the tenant-bound wiring from env + the asserted tenant. Memoized. */
|
|
59
|
+
protected abstract build(env: TEnv, tenantId: string): SignalProviderHostWiring;
|
|
60
|
+
/**
|
|
61
|
+
* The tenant this host serves, recovered from its OWN idFromName identity —
|
|
62
|
+
* `id.name` IS the bare tenantId (the hub DO posture). Validated INV-3 and
|
|
63
|
+
* fail-closed: a name carrying no valid tenant cannot scope a store.
|
|
64
|
+
*/
|
|
65
|
+
protected get tenantId(): string;
|
|
66
|
+
fetch(request: Request): Promise<Response>;
|
|
67
|
+
/** DO alarm: poll, then re-arm regardless (availability — a failed poll must not stop polling). */
|
|
68
|
+
alarm(): Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* Run one poll cycle across this tenant's poll-capable providers, rehydrating
|
|
71
|
+
* each provider's subscriptions from D1 first (the eviction-survivable path).
|
|
72
|
+
* PER-PROVIDER isolation: a provider whose poll throws is logged and skipped,
|
|
73
|
+
* the rest still run; PER-DELIVERY isolation: a failing/tampered delivery is
|
|
74
|
+
* logged and skipped, the batch continues. Public so a host/test drives it
|
|
75
|
+
* directly (the E-S3 probe).
|
|
76
|
+
*/
|
|
77
|
+
poll(): Promise<PollResult>;
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=host-do.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{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AC,KAAK,CAAC,EAAE,uBAAuB,CAAC;gBAGvC,KAAK,EAAE,uBAAuB,GAAG,SAAS,EAAE,GAAG,EAAE,IAAI;IAKjE,8EAA8E;IAC9E,SAAS,CAAC,QAAQ,CAAC,KAAK,CACtB,GAAG,EAAE,IAAI,EACT,QAAQ,EAAE,MAAM,GACf,wBAAwB;IAE3B;;;;OAIG;IACH,SAAS,KAAK,QAAQ,IAAI,MAAM,CAQ/B;IASK,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC;IAgBhD,mGAAmG;IAC7F,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAyB5B;;;;;;;OAOG;IACG,IAAI,IAAI,OAAO,CAAC,UAAU,CAAC;CAuFlC"}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Track E (M-007), CI-M-007-001 — the provider host Durable Object (DL-017).
|
|
3
|
+
//
|
|
4
|
+
// WHY a DO + alarm: core's SignalProvider expects a long-lived process — a
|
|
5
|
+
// `startPolling` setInterval loop over an in-memory subscription registry
|
|
6
|
+
// (signal-provider.d.ts). Workers has neither. So the DO ALARM drives polling
|
|
7
|
+
// (it wakes an evicted DO with no live request) and D1 holds the subscriptions
|
|
8
|
+
// (core's registry is lost on eviction) — the host rehydrates them from D1 at
|
|
9
|
+
// each boot/poll (the E-S3 in-memory-lost, D1-restored proof).
|
|
10
|
+
//
|
|
11
|
+
// ADDRESSING — per TENANT (`idFromName(tenantId)`, the HubDurableObject pattern):
|
|
12
|
+
// id.name IS the bare tenantId, so the instance is tenant-disjoint by
|
|
13
|
+
// construction (like the hub DO) and its subscription store binds to exactly that
|
|
14
|
+
// tenant (INV-2). It hosts ALL of the tenant's providers on one alarm, each
|
|
15
|
+
// provider's poll+delivery wrapped in its OWN try/catch — PER-PROVIDER FAILURE
|
|
16
|
+
// ISOLATION: a provider whose poll throws never starves its siblings, and one
|
|
17
|
+
// tampered/failing delivery never aborts the rest of the batch. (Per-tenant, not
|
|
18
|
+
// per-tenant×provider: a per-provider DO would make cross-provider isolation an
|
|
19
|
+
// untestable DO boundary and multiply instances; per-tenant keeps the isolation
|
|
20
|
+
// inside one alarm where it is exercised, and matches the hub DO's
|
|
21
|
+
// id.name===tenantId house pattern.)
|
|
22
|
+
//
|
|
23
|
+
// The host is reached ONLY internally — the subscribe route arms it, the alarm
|
|
24
|
+
// polls it — never by a client, so (like the hub DO) it needs no tenant-header
|
|
25
|
+
// assertion: id.name === the addressing tenant by construction, validated INV-3.
|
|
26
|
+
// Classic ctor(state, env) + fetch (+ alarm), NOT `extends DurableObject` — so it
|
|
27
|
+
// and its graph load in node/vitest, the ThreadDurableObject/HubDurableObject
|
|
28
|
+
// posture.
|
|
29
|
+
import { DoStatusError, doErrorResponse, TENANT_ID_PATTERN, } from '../do-runner/index.js';
|
|
30
|
+
import { deliverNotification } from './delivery.js';
|
|
31
|
+
/**
|
|
32
|
+
* A host DO whose name carries no INV-3 tenant. 403 — this boundary is internal
|
|
33
|
+
* (not client-reachable), so there is no oracle to protect and a distinct status
|
|
34
|
+
* keeps a routing bug from reading as a 500. Extends DoStatusError so
|
|
35
|
+
* doErrorResponse recognizes it.
|
|
36
|
+
*/
|
|
37
|
+
export class SignalProviderHostIdentityError extends DoStatusError {
|
|
38
|
+
status = 403;
|
|
39
|
+
constructor(message) {
|
|
40
|
+
super(message);
|
|
41
|
+
this.name = 'SignalProviderHostIdentityError';
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function json(payload, status = 200) {
|
|
45
|
+
return new Response(JSON.stringify(payload), {
|
|
46
|
+
status,
|
|
47
|
+
headers: { 'content-type': 'application/json' },
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The provider host DO base. Subclass it, supply `build()` (the tenant-bound
|
|
52
|
+
* subscription store + thread topology + provider list from env), and bind the
|
|
53
|
+
* subclass under a wrangler namespace addressed `idFromName(tenantId)`.
|
|
54
|
+
*
|
|
55
|
+
* Routes: `POST /arm` (boot + arm the alarm), `POST /poll` (run one poll cycle —
|
|
56
|
+
* the deterministic probe the spike drives so E-S3 does not depend on wrangler's
|
|
57
|
+
* alarm timer). `alarm()` polls then re-arms.
|
|
58
|
+
*/
|
|
59
|
+
export class SignalProviderHost {
|
|
60
|
+
env;
|
|
61
|
+
state;
|
|
62
|
+
#wiring;
|
|
63
|
+
constructor(state, env) {
|
|
64
|
+
this.state = state;
|
|
65
|
+
this.env = env;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* The tenant this host serves, recovered from its OWN idFromName identity —
|
|
69
|
+
* `id.name` IS the bare tenantId (the hub DO posture). Validated INV-3 and
|
|
70
|
+
* fail-closed: a name carrying no valid tenant cannot scope a store.
|
|
71
|
+
*/
|
|
72
|
+
get tenantId() {
|
|
73
|
+
const name = this.state?.id?.name;
|
|
74
|
+
if (name === undefined || !TENANT_ID_PATTERN.test(name)) {
|
|
75
|
+
throw new SignalProviderHostIdentityError(`SignalProviderHost: id.name '${name ?? '<none>'}' is not an INV-3 tenantId — the host is addressed idFromName(tenantId); refusing to serve`);
|
|
76
|
+
}
|
|
77
|
+
return name;
|
|
78
|
+
}
|
|
79
|
+
#ensureWiring() {
|
|
80
|
+
if (!this.#wiring) {
|
|
81
|
+
this.#wiring = this.build(this.env, this.tenantId);
|
|
82
|
+
}
|
|
83
|
+
return this.#wiring;
|
|
84
|
+
}
|
|
85
|
+
async fetch(request) {
|
|
86
|
+
try {
|
|
87
|
+
const path = new URL(request.url).pathname;
|
|
88
|
+
if (request.method === 'POST' && path === '/arm') {
|
|
89
|
+
await this.#arm();
|
|
90
|
+
return json({ armed: true });
|
|
91
|
+
}
|
|
92
|
+
if (request.method === 'POST' && path === '/poll') {
|
|
93
|
+
return json(await this.poll());
|
|
94
|
+
}
|
|
95
|
+
return json({ error: 'not found' }, 404);
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
return doErrorResponse(error);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/** DO alarm: poll, then re-arm regardless (availability — a failed poll must not stop polling). */
|
|
102
|
+
async alarm() {
|
|
103
|
+
try {
|
|
104
|
+
await this.poll();
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
console.error(JSON.stringify({
|
|
108
|
+
type: 'signal-provider.alarm-error',
|
|
109
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
110
|
+
}));
|
|
111
|
+
}
|
|
112
|
+
// Re-arm in its OWN guard: #arm re-invokes build() via #ensureWiring, so a
|
|
113
|
+
// persistently broken wiring must not throw uncaught out of the alarm handler.
|
|
114
|
+
try {
|
|
115
|
+
await this.#arm();
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
console.error(JSON.stringify({
|
|
119
|
+
type: 'signal-provider.arm-error',
|
|
120
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
121
|
+
}));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Run one poll cycle across this tenant's poll-capable providers, rehydrating
|
|
126
|
+
* each provider's subscriptions from D1 first (the eviction-survivable path).
|
|
127
|
+
* PER-PROVIDER isolation: a provider whose poll throws is logged and skipped,
|
|
128
|
+
* the rest still run; PER-DELIVERY isolation: a failing/tampered delivery is
|
|
129
|
+
* logged and skipped, the batch continues. Public so a host/test drives it
|
|
130
|
+
* directly (the E-S3 probe).
|
|
131
|
+
*/
|
|
132
|
+
async poll() {
|
|
133
|
+
const { store, topology, providers } = this.#ensureWiring();
|
|
134
|
+
const tenantId = this.tenantId;
|
|
135
|
+
let providersPolled = 0;
|
|
136
|
+
let delivered = 0;
|
|
137
|
+
for (const provider of providers) {
|
|
138
|
+
if (!provider.pollForDeliveries)
|
|
139
|
+
continue;
|
|
140
|
+
try {
|
|
141
|
+
const subscriptions = await store.listForProvider(provider.id);
|
|
142
|
+
const deliveries = await provider.pollForDeliveries(subscriptions);
|
|
143
|
+
providersPolled += 1;
|
|
144
|
+
for (const delivery of deliveries) {
|
|
145
|
+
try {
|
|
146
|
+
// This host's tenant is authoritative for the poll path (the store
|
|
147
|
+
// was bound to it); attach it so delivery binds to the right tenant,
|
|
148
|
+
// and the topology re-checks ownership (a foreign threadId 404s).
|
|
149
|
+
const subscription = {
|
|
150
|
+
...delivery.subscription,
|
|
151
|
+
tenantId,
|
|
152
|
+
};
|
|
153
|
+
const response = await deliverNotification(topology, subscription, delivery.notification);
|
|
154
|
+
if (response.ok) {
|
|
155
|
+
delivered += 1;
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
// A matched delivery the thread DO rejected for content (not an
|
|
159
|
+
// ownership 404 — that throws): log so it is not silently dropped.
|
|
160
|
+
console.error(JSON.stringify({
|
|
161
|
+
type: 'signal-provider.delivery-rejected',
|
|
162
|
+
providerId: provider.id,
|
|
163
|
+
status: response.status,
|
|
164
|
+
}));
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
console.error(JSON.stringify({
|
|
169
|
+
type: 'signal-provider.delivery-error',
|
|
170
|
+
providerId: provider.id,
|
|
171
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
172
|
+
}));
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
console.error(JSON.stringify({
|
|
178
|
+
type: 'signal-provider.poll-error',
|
|
179
|
+
providerId: provider.id,
|
|
180
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
181
|
+
}));
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return { providersPolled, delivered };
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Arm the alarm at the MIN pollInterval of providers that both poll AND have
|
|
188
|
+
* subscriptions. Nothing to poll ⇒ delete the alarm (self-terminating: a
|
|
189
|
+
* tenant with no live subscriptions costs no wakeups). No storage (node/vitest)
|
|
190
|
+
* ⇒ no-op, and tests drive `poll()` directly.
|
|
191
|
+
*/
|
|
192
|
+
async #arm() {
|
|
193
|
+
const storage = this.state?.storage;
|
|
194
|
+
if (!storage)
|
|
195
|
+
return;
|
|
196
|
+
const { store, providers } = this.#ensureWiring();
|
|
197
|
+
let interval;
|
|
198
|
+
for (const provider of providers) {
|
|
199
|
+
if (!provider.pollForDeliveries || !provider.pollInterval)
|
|
200
|
+
continue;
|
|
201
|
+
const subscriptions = await store.listForProvider(provider.id);
|
|
202
|
+
if (subscriptions.length === 0)
|
|
203
|
+
continue;
|
|
204
|
+
interval =
|
|
205
|
+
interval === undefined
|
|
206
|
+
? provider.pollInterval
|
|
207
|
+
: Math.min(interval, provider.pollInterval);
|
|
208
|
+
}
|
|
209
|
+
if (interval === undefined) {
|
|
210
|
+
await storage.deleteAlarm();
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
await storage.setAlarm(Date.now() + interval);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
//# sourceMappingURL=host-do.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host-do.js","sourceRoot":"","sources":["../../src/signal-providers/host-do.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,6EAA6E;AAC7E,EAAE;AACF,2EAA2E;AAC3E,0EAA0E;AAC1E,8EAA8E;AAC9E,+EAA+E;AAC/E,8EAA8E;AAC9E,+DAA+D;AAC/D,EAAE;AACF,kFAAkF;AAClF,sEAAsE;AACtE,kFAAkF;AAClF,4EAA4E;AAC5E,+EAA+E;AAC/E,8EAA8E;AAC9E,iFAAiF;AACjF,gFAAgF;AAChF,gFAAgF;AAChF,mEAAmE;AACnE,qCAAqC;AACrC,EAAE;AACF,+EAA+E;AAC/E,+EAA+E;AAC/E,iFAAiF;AACjF,kFAAkF;AAClF,8EAA8E;AAC9E,WAAW;AAMX,OAAO,EACL,aAAa,EACb,eAAe,EACf,iBAAiB,GAClB,MAAM,uBAAuB,CAAC;AAE/B,OAAO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C,YAAY;gBAAE,SAAS;YACpE,MAAM,aAAa,GAAG,MAAM,KAAK,CAAC,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;YAC/D,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC;gBAAE,SAAS;YACzC,QAAQ;gBACN,QAAQ,KAAK,SAAS;oBACpB,CAAC,CAAC,QAAQ,CAAC,YAAY;oBACvB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC,YAAY,CAAC,CAAC;QAClD,CAAC;QACD,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;YAC3B,MAAM,OAAO,CAAC,WAAW,EAAE,CAAC;YAC5B,OAAO;QACT,CAAC;QACD,MAAM,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,QAAQ,CAAC,CAAC;IAChD,CAAC;CACF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { deliverNotification, deliveryTenantContext } from './delivery.js';
|
|
2
|
+
export { buildGithubNotification, extractGithubResourceIds, type GithubSignalProviderOptions, githubSignalProvider, verifyGithubSignature, } from './github-provider.js';
|
|
3
|
+
export { type AlarmStorage, type PollResult, SignalProviderHost, SignalProviderHostIdentityError, type SignalProviderHostState, type SignalProviderHostWiring, } from './host-do.js';
|
|
4
|
+
export { createWebhookSignalProvider, normalizeResourceIds, PROVIDER_ID_PATTERN, type ProviderDelivery, type SendNotificationSignalInput, type SignalProviderAdapter, type SignalSubscription, type WebhookHeaders, type WebhookSignalProviderConfig, } from './provider.js';
|
|
5
|
+
export { D1SubscriptionStoreFactory, InMemorySubscriptionStoreFactory, SIGNAL_SUBSCRIPTIONS_TABLE, type StoredSubscription, SUBSCRIPTION_TENANT_BOUND, type SubscribeInput, type SubscriptionStoreFactory, type SystemSubscriptionStore, type TenantBoundSubscriptionStore, } from './subscription-d1.js';
|
|
6
|
+
export { createSubscriptionRouter, createWebhookRouter, type SignalProviderAuditEvent, type SignalProviderAuditSink, type SubscriptionAuditEvent, type SubscriptionRouter, type SubscriptionRouterOptions, type WebhookAuditEvent, type WebhookRateLimiter, type WebhookRouter, type WebhookRouterOptions, } from './webhook-route.js';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/signal-providers/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAE3E,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,KAAK,2BAA2B,EAChC,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,UAAU,EACf,kBAAkB,EAClB,+BAA+B,EAC/B,KAAK,uBAAuB,EAC5B,KAAK,wBAAwB,GAC9B,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,2BAA2B,EAC3B,oBAAoB,EACpB,mBAAmB,EACnB,KAAK,gBAAgB,EACrB,KAAK,2BAA2B,EAChC,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,2BAA2B,GACjC,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,0BAA0B,EAC1B,gCAAgC,EAChC,0BAA0B,EAC1B,KAAK,kBAAkB,EACvB,yBAAyB,EACzB,KAAK,cAAc,EACnB,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAC5B,KAAK,4BAA4B,GAClC,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EACnB,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAC5B,KAAK,sBAAsB,EAC3B,KAAK,kBAAkB,EACvB,KAAK,yBAAyB,EAC9B,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,oBAAoB,GAC1B,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Track E (M-007) — signal providers: host providers on a DO with alarm-driven
|
|
3
|
+
// polling, terminate provider webhooks on the Worker, persist subscriptions in a
|
|
4
|
+
// flowsafe-owned D1 table. Subpath-only (`@proofoftech/flowsafe/signal-providers`),
|
|
5
|
+
// like agent-runner/background-tasks/signals/schedules/goals: host-side wiring a
|
|
6
|
+
// consumer opts into, never the root barrel.
|
|
7
|
+
// The delivery seam (into a thread via the topology).
|
|
8
|
+
export { deliverNotification, deliveryTenantContext } from './delivery.js';
|
|
9
|
+
// The GitHub reference provider (binding-gated showcase connector).
|
|
10
|
+
export { buildGithubNotification, extractGithubResourceIds, githubSignalProvider, verifyGithubSignature, } from './github-provider.js';
|
|
11
|
+
// The provider host DO (CI-M-007-001).
|
|
12
|
+
export { SignalProviderHost, SignalProviderHostIdentityError, } from './host-do.js';
|
|
13
|
+
// The provider contract (CI-M-007-001).
|
|
14
|
+
export { createWebhookSignalProvider, normalizeResourceIds, PROVIDER_ID_PATTERN, } from './provider.js';
|
|
15
|
+
// The D1 subscription store (CI-M-007-002).
|
|
16
|
+
export { D1SubscriptionStoreFactory, InMemorySubscriptionStoreFactory, SIGNAL_SUBSCRIPTIONS_TABLE, SUBSCRIPTION_TENANT_BOUND, } from './subscription-d1.js';
|
|
17
|
+
// The webhook ingress + human-only subscription CRUD (CI-M-007-003).
|
|
18
|
+
export { createSubscriptionRouter, createWebhookRouter, } from './webhook-route.js';
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/signal-providers/index.ts"],"names":[],"mappings":"AAAA,sCAAsC;AACtC,+EAA+E;AAC/E,iFAAiF;AACjF,oFAAoF;AACpF,iFAAiF;AACjF,6CAA6C;AAE7C,sDAAsD;AACtD,OAAO,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAC3E,oEAAoE;AACpE,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EAExB,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,sBAAsB,CAAC;AAC9B,uCAAuC;AACvC,OAAO,EAGL,kBAAkB,EAClB,+BAA+B,GAGhC,MAAM,cAAc,CAAC;AACtB,wCAAwC;AACxC,OAAO,EACL,2BAA2B,EAC3B,oBAAoB,EACpB,mBAAmB,GAOpB,MAAM,eAAe,CAAC;AACvB,4CAA4C;AAC5C,OAAO,EACL,0BAA0B,EAC1B,gCAAgC,EAChC,0BAA0B,EAE1B,yBAAyB,GAK1B,MAAM,sBAAsB,CAAC;AAC9B,qEAAqE;AACrE,OAAO,EACL,wBAAwB,EACxB,mBAAmB,GAUpB,MAAM,oBAAoB,CAAC"}
|