@jini-ai/integrations 0.3.5 → 0.4.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 +84 -0
- package/README.md +72 -24
- package/dist/args.d.ts +8 -0
- package/dist/args.js +10 -0
- package/dist/argument-error.d.ts +9 -0
- package/dist/argument-error.js +7 -0
- package/dist/credentialed-http/auth-schemes.d.ts +29 -0
- package/dist/credentialed-http/auth-schemes.js +60 -0
- package/dist/credentialed-http/credentialed-request.d.ts +132 -0
- package/dist/credentialed-http/credentialed-request.js +365 -0
- package/dist/credentialed-http/index.d.ts +4 -0
- package/dist/credentialed-http/index.js +4 -0
- package/dist/credentialed-http/ports.d.ts +42 -0
- package/dist/credentialed-http/ports.js +2 -0
- package/dist/media-providers/capability-registry.d.ts +12 -4
- package/dist/media-providers/capability-registry.js +6 -6
- package/dist/media-providers/dispatch/async-operation-store.d.ts +33 -8
- package/dist/media-providers/dispatch/async-operation-store.js +20 -32
- package/dist/media-providers/dispatch/context.d.ts +7 -2
- package/dist/media-providers/dispatch/context.js +1 -1
- package/dist/media-providers/dispatch/credentials.d.ts +4 -1
- package/dist/media-providers/dispatch/credentials.js +1 -1
- package/dist/media-providers/dispatch/engine.d.ts +5 -2
- package/dist/media-providers/dispatch/engine.js +23 -15
- package/dist/media-providers/dispatch/index.d.ts +4 -1
- package/dist/media-providers/dispatch/index.js +4 -2
- package/dist/media-providers/dispatch/openai-compatible.d.ts +12 -2
- package/dist/media-providers/dispatch/openai-compatible.js +9 -5
- package/dist/media-providers/dispatch/operation-runtime.d.ts +16 -8
- package/dist/media-providers/dispatch/operation-runtime.js +93 -76
- package/dist/media-providers/dispatch/outbound.d.ts +31 -0
- package/dist/media-providers/dispatch/outbound.js +54 -0
- package/dist/media-providers/dispatch/polling-adapter.d.ts +26 -8
- package/dist/media-providers/dispatch/polling-adapter.js +2 -2
- package/dist/media-providers/dispatch/providers/aihubmix-shared.d.ts +2 -2
- package/dist/media-providers/dispatch/providers/aihubmix-shared.js +2 -2
- package/dist/media-providers/dispatch/providers/aihubmix.d.ts +8 -2
- package/dist/media-providers/dispatch/providers/aihubmix.js +15 -15
- package/dist/media-providers/dispatch/providers/custom-image.d.ts +11 -2
- package/dist/media-providers/dispatch/providers/custom-image.js +9 -8
- package/dist/media-providers/dispatch/providers/elevenlabs.d.ts +8 -2
- package/dist/media-providers/dispatch/providers/elevenlabs.js +13 -13
- package/dist/media-providers/dispatch/providers/fishaudio.d.ts +4 -1
- package/dist/media-providers/dispatch/providers/fishaudio.js +7 -7
- package/dist/media-providers/dispatch/providers/grok.d.ts +11 -3
- package/dist/media-providers/dispatch/providers/grok.js +16 -16
- package/dist/media-providers/dispatch/providers/imagerouter-video-async.d.ts +1 -1
- package/dist/media-providers/dispatch/providers/imagerouter-video-async.js +23 -22
- package/dist/media-providers/dispatch/providers/imagerouter.d.ts +12 -3
- package/dist/media-providers/dispatch/providers/imagerouter.js +18 -18
- package/dist/media-providers/dispatch/providers/minimax.d.ts +4 -1
- package/dist/media-providers/dispatch/providers/minimax.js +6 -6
- package/dist/media-providers/dispatch/providers/nanobanana.d.ts +4 -1
- package/dist/media-providers/dispatch/providers/nanobanana.js +7 -7
- package/dist/media-providers/dispatch/providers/openai.d.ts +8 -2
- package/dist/media-providers/dispatch/providers/openai.js +20 -27
- package/dist/media-providers/dispatch/providers/openrouter.d.ts +7 -2
- package/dist/media-providers/dispatch/providers/openrouter.js +11 -11
- package/dist/media-providers/dispatch/providers/senseaudio.d.ts +8 -2
- package/dist/media-providers/dispatch/providers/senseaudio.js +13 -13
- package/dist/media-providers/dispatch/providers/volcengine.d.ts +4 -1
- package/dist/media-providers/dispatch/providers/volcengine.js +8 -8
- package/dist/media-providers/dispatch/response-parsers.d.ts +21 -7
- package/dist/media-providers/dispatch/response-parsers.js +15 -11
- package/dist/media-providers/dispatch/sqlite-async-operation-store.d.ts +3 -1
- package/dist/media-providers/dispatch/sqlite-async-operation-store.js +53 -39
- package/dist/media-providers/dispatch/ssrf-guard.d.ts +27 -14
- package/dist/media-providers/dispatch/ssrf-guard.js +46 -105
- package/dist/media-providers/dispatch/stub.d.ts +7 -2
- package/dist/media-providers/dispatch/stub.js +4 -3
- package/dist/media-providers/dispatch/types.d.ts +17 -13
- package/dist/media-providers/dispatch/vendor-adapter.d.ts +22 -5
- package/dist/media-providers/dispatch/vendor-adapter.js +13 -10
- package/dist/media-providers/dispatch/vendor-registry.d.ts +14 -4
- package/dist/media-providers/dispatch/vendor-registry.js +3 -3
- package/dist/media-providers/index.d.ts +1 -1
- package/dist/media-providers/index.js +1 -1
- package/dist/media-providers/policy.d.ts +3 -2
- package/dist/media-providers/policy.js +4 -2
- package/dist/media-providers/providers.d.ts +12 -4
- package/dist/media-providers/providers.js +3 -3
- package/dist/media-providers/staging.d.ts +8 -2
- package/dist/media-providers/staging.js +13 -4
- package/dist/media-providers/task-store.d.ts +2 -2
- package/dist/media-providers/task-store.js +2 -2
- package/dist/media-providers/tokens.js +3 -3
- package/dist/media-providers/types.d.ts +4 -4
- package/dist/media-providers/types.js +1 -1
- package/dist/media-providers/video-request.d.ts +32 -9
- package/dist/media-providers/video-request.js +15 -15
- package/dist/webhooks/delivery.d.ts +76 -0
- package/dist/webhooks/delivery.js +222 -0
- package/dist/webhooks/index.d.ts +7 -0
- package/dist/webhooks/index.js +7 -0
- package/dist/webhooks/ports.d.ts +113 -0
- package/dist/webhooks/ports.js +2 -0
- package/dist/webhooks/signing.d.ts +38 -0
- package/dist/webhooks/signing.js +83 -0
- package/dist/webhooks/signing.keyring.d.ts +8 -0
- package/dist/webhooks/signing.keyring.js +18 -0
- package/dist/webhooks/subscriptions.d.ts +78 -0
- package/dist/webhooks/subscriptions.js +139 -0
- package/dist/webhooks/types.d.ts +103 -0
- package/dist/webhooks/types.js +2 -0
- package/package.json +29 -18
- package/dist/composio/bounded-data.d.ts.map +0 -1
- package/dist/composio/bounded-data.js.map +0 -1
- package/dist/composio/catalog.d.ts.map +0 -1
- package/dist/composio/catalog.js.map +0 -1
- package/dist/composio/composio-config.d.ts.map +0 -1
- package/dist/composio/composio-config.js.map +0 -1
- package/dist/composio/composio-descriptions.d.ts.map +0 -1
- package/dist/composio/composio-descriptions.js.map +0 -1
- package/dist/composio/composio.d.ts.map +0 -1
- package/dist/composio/composio.js.map +0 -1
- package/dist/composio/errors.d.ts.map +0 -1
- package/dist/composio/errors.js.map +0 -1
- package/dist/composio/file-lock.d.ts.map +0 -1
- package/dist/composio/file-lock.js.map +0 -1
- package/dist/composio/index.d.ts.map +0 -1
- package/dist/composio/index.js.map +0 -1
- package/dist/composio/json-schema.d.ts.map +0 -1
- package/dist/composio/json-schema.js.map +0 -1
- package/dist/composio/output-protection.d.ts.map +0 -1
- package/dist/composio/output-protection.js.map +0 -1
- package/dist/composio/service.d.ts.map +0 -1
- package/dist/composio/service.js.map +0 -1
- package/dist/media-providers/capability-registry.d.ts.map +0 -1
- package/dist/media-providers/capability-registry.js.map +0 -1
- package/dist/media-providers/catalog.d.ts.map +0 -1
- package/dist/media-providers/catalog.js.map +0 -1
- package/dist/media-providers/dispatch/async-operation-store.d.ts.map +0 -1
- package/dist/media-providers/dispatch/async-operation-store.js.map +0 -1
- package/dist/media-providers/dispatch/context.d.ts.map +0 -1
- package/dist/media-providers/dispatch/context.js.map +0 -1
- package/dist/media-providers/dispatch/credentials.d.ts.map +0 -1
- package/dist/media-providers/dispatch/credentials.js.map +0 -1
- package/dist/media-providers/dispatch/engine.d.ts.map +0 -1
- package/dist/media-providers/dispatch/engine.js.map +0 -1
- package/dist/media-providers/dispatch/index.d.ts.map +0 -1
- package/dist/media-providers/dispatch/index.js.map +0 -1
- package/dist/media-providers/dispatch/openai-compatible.d.ts.map +0 -1
- package/dist/media-providers/dispatch/openai-compatible.js.map +0 -1
- package/dist/media-providers/dispatch/operation-runtime.d.ts.map +0 -1
- package/dist/media-providers/dispatch/operation-runtime.js.map +0 -1
- package/dist/media-providers/dispatch/polling-adapter.d.ts.map +0 -1
- package/dist/media-providers/dispatch/polling-adapter.js.map +0 -1
- package/dist/media-providers/dispatch/providers/aihubmix-shared.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/aihubmix-shared.js.map +0 -1
- package/dist/media-providers/dispatch/providers/aihubmix.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/aihubmix.js.map +0 -1
- package/dist/media-providers/dispatch/providers/custom-image.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/custom-image.js.map +0 -1
- package/dist/media-providers/dispatch/providers/elevenlabs.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/elevenlabs.js.map +0 -1
- package/dist/media-providers/dispatch/providers/fishaudio.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/fishaudio.js.map +0 -1
- package/dist/media-providers/dispatch/providers/grok.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/grok.js.map +0 -1
- package/dist/media-providers/dispatch/providers/imagerouter-video-async.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/imagerouter-video-async.js.map +0 -1
- package/dist/media-providers/dispatch/providers/imagerouter.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/imagerouter.js.map +0 -1
- package/dist/media-providers/dispatch/providers/minimax.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/minimax.js.map +0 -1
- package/dist/media-providers/dispatch/providers/nanobanana.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/nanobanana.js.map +0 -1
- package/dist/media-providers/dispatch/providers/openai.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/openai.js.map +0 -1
- package/dist/media-providers/dispatch/providers/openrouter.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/openrouter.js.map +0 -1
- package/dist/media-providers/dispatch/providers/senseaudio.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/senseaudio.js.map +0 -1
- package/dist/media-providers/dispatch/providers/volcengine.d.ts.map +0 -1
- package/dist/media-providers/dispatch/providers/volcengine.js.map +0 -1
- package/dist/media-providers/dispatch/response-parsers.d.ts.map +0 -1
- package/dist/media-providers/dispatch/response-parsers.js.map +0 -1
- package/dist/media-providers/dispatch/sqlite-async-operation-store.d.ts.map +0 -1
- package/dist/media-providers/dispatch/sqlite-async-operation-store.js.map +0 -1
- package/dist/media-providers/dispatch/ssrf-guard.d.ts.map +0 -1
- package/dist/media-providers/dispatch/ssrf-guard.js.map +0 -1
- package/dist/media-providers/dispatch/stub.d.ts.map +0 -1
- package/dist/media-providers/dispatch/stub.js.map +0 -1
- package/dist/media-providers/dispatch/types.d.ts.map +0 -1
- package/dist/media-providers/dispatch/types.js.map +0 -1
- package/dist/media-providers/dispatch/vendor-adapter.d.ts.map +0 -1
- package/dist/media-providers/dispatch/vendor-adapter.js.map +0 -1
- package/dist/media-providers/dispatch/vendor-registry.d.ts.map +0 -1
- package/dist/media-providers/dispatch/vendor-registry.js.map +0 -1
- package/dist/media-providers/index.d.ts.map +0 -1
- package/dist/media-providers/index.js.map +0 -1
- package/dist/media-providers/policy.d.ts.map +0 -1
- package/dist/media-providers/policy.js.map +0 -1
- package/dist/media-providers/providers.d.ts.map +0 -1
- package/dist/media-providers/providers.js.map +0 -1
- package/dist/media-providers/seed.d.ts.map +0 -1
- package/dist/media-providers/seed.js.map +0 -1
- package/dist/media-providers/sqlite-task-store.d.ts.map +0 -1
- package/dist/media-providers/sqlite-task-store.js.map +0 -1
- package/dist/media-providers/staging.d.ts.map +0 -1
- package/dist/media-providers/staging.js.map +0 -1
- package/dist/media-providers/task-store.d.ts.map +0 -1
- package/dist/media-providers/task-store.js.map +0 -1
- package/dist/media-providers/tokens.d.ts.map +0 -1
- package/dist/media-providers/tokens.js.map +0 -1
- package/dist/media-providers/types.d.ts.map +0 -1
- package/dist/media-providers/types.js.map +0 -1
- package/dist/media-providers/video-request.d.ts.map +0 -1
- package/dist/media-providers/video-request.js.map +0 -1
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { IntegrationError } from "../argument-error.js";
|
|
2
|
+
import type { Clock, IdGenerator, ISODateTime, JsonObject, UUID } from "@jini-ai/core/primitives";
|
|
3
|
+
import type { DeliveryEnvelopeStorePort, WebhookHeaderVocabulary } from "./ports.js";
|
|
4
|
+
import type { HttpClientPort } from "@jini-ai/core/primitives";
|
|
5
|
+
import type { WebhookDeliveryRepoPort, WebhookSubscriptionRepoPort } from "./ports.js";
|
|
6
|
+
import type { WebhookSigner } from "./signing.js";
|
|
7
|
+
import type { WebhookBeforeDispatchHook, WebhookDeliveryRecord, WebhookTopic } from "./types.js";
|
|
8
|
+
export declare const MAX_DELIVERY_ATTEMPTS = 8;
|
|
9
|
+
/**
|
|
10
|
+
* attempts is one-based after the failing attempt. Equal jitter stays between half and all of
|
|
11
|
+
* min(6 hours, 5 minutes * 2^(attempts-1)), preventing zero-delay retry herds while staying inside
|
|
12
|
+
* the exponential envelope. For attempts 1..8, the half-step lower bounds are approximately
|
|
13
|
+
* 2.5, 5, 10, 20, 40, 80, 160 and 180 minutes. Inject random for deterministic decisions.
|
|
14
|
+
*/
|
|
15
|
+
/** Compute equal-jitter backoff capped at six hours; the optional random port controls jitter. */
|
|
16
|
+
export declare function computeBackoffMs(required: {
|
|
17
|
+
attempts: number;
|
|
18
|
+
}, optional?: {
|
|
19
|
+
random?: (() => number) | undefined;
|
|
20
|
+
}): number;
|
|
21
|
+
export declare class WebhookDeliveryVetoedError extends IntegrationError {
|
|
22
|
+
}
|
|
23
|
+
export interface WebhookSourceEvent {
|
|
24
|
+
id: UUID;
|
|
25
|
+
name: WebhookTopic;
|
|
26
|
+
workspaceId: UUID;
|
|
27
|
+
occurredAt: ISODateTime;
|
|
28
|
+
payload: JsonObject;
|
|
29
|
+
}
|
|
30
|
+
export interface EnqueueDeliveryDeps {
|
|
31
|
+
subscriptionRepo: WebhookSubscriptionRepoPort;
|
|
32
|
+
deliveryRepo: WebhookDeliveryRepoPort;
|
|
33
|
+
envelopeStore: DeliveryEnvelopeStorePort;
|
|
34
|
+
idGenerator: IdGenerator;
|
|
35
|
+
clock: Clock;
|
|
36
|
+
}
|
|
37
|
+
export interface EnqueueDeliveryRequired {
|
|
38
|
+
deps: EnqueueDeliveryDeps;
|
|
39
|
+
input: {
|
|
40
|
+
event: WebhookSourceEvent;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export interface EnqueueDeliveryOptional {
|
|
44
|
+
}
|
|
45
|
+
/** Fan out an event to active matching subscriptions, preserving existing event/subscription deduplication. Durable adapters must enforce uniqueness atomically. */
|
|
46
|
+
export declare function enqueueDelivery(required: EnqueueDeliveryRequired, _optional?: EnqueueDeliveryOptional): Promise<{
|
|
47
|
+
enqueued: WebhookDeliveryRecord[];
|
|
48
|
+
}>;
|
|
49
|
+
export interface ProcessDueDeliveriesDeps {
|
|
50
|
+
deliveryRepo: WebhookDeliveryRepoPort;
|
|
51
|
+
subscriptionRepo: WebhookSubscriptionRepoPort;
|
|
52
|
+
envelopeStore: DeliveryEnvelopeStorePort;
|
|
53
|
+
httpClient: HttpClientPort;
|
|
54
|
+
signer: WebhookSigner;
|
|
55
|
+
headers: WebhookHeaderVocabulary;
|
|
56
|
+
clock: Clock;
|
|
57
|
+
}
|
|
58
|
+
export interface ProcessDueDeliveriesRequired {
|
|
59
|
+
deps: ProcessDueDeliveriesDeps;
|
|
60
|
+
}
|
|
61
|
+
export interface ProcessDueDeliveriesOptional {
|
|
62
|
+
batchSize?: number;
|
|
63
|
+
hooks?: readonly WebhookBeforeDispatchHook[];
|
|
64
|
+
requestTimeoutMs?: number;
|
|
65
|
+
maxAttempts?: number;
|
|
66
|
+
random?: (() => number) | undefined;
|
|
67
|
+
}
|
|
68
|
+
export interface ProcessDueDeliveriesResult {
|
|
69
|
+
processed: number;
|
|
70
|
+
delivered: number;
|
|
71
|
+
failed: number;
|
|
72
|
+
dead: number;
|
|
73
|
+
}
|
|
74
|
+
/** Claim and process a bounded batch; hooks fail closed and unsuccessful attempts back off or dead-letter. */
|
|
75
|
+
export declare function processDueDeliveries(required: ProcessDueDeliveriesRequired, optional?: ProcessDueDeliveriesOptional): Promise<ProcessDueDeliveriesResult>;
|
|
76
|
+
//# sourceMappingURL=delivery.d.ts.map
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { nowIso } from "@jini-ai/core/primitives";
|
|
2
|
+
// Keep transport, signing and persistence behind injected ports: this module owns the
|
|
3
|
+
// enqueue/retry/filter state machine, so its decisions can be inspected independently of I/O adapters.
|
|
4
|
+
import { IntegrationError } from "../argument-error.js";
|
|
5
|
+
// Default eight-attempt budget: dead-letter instead of retrying an endpoint indefinitely.
|
|
6
|
+
export const MAX_DELIVERY_ATTEMPTS = 8;
|
|
7
|
+
const BASE_BACKOFF_MS = 5 * 60 * 1000; // 5 minutes
|
|
8
|
+
const MAX_BACKOFF_STEP_MS = 6 * 60 * 60 * 1000; // 6 hours
|
|
9
|
+
/**
|
|
10
|
+
* attempts is one-based after the failing attempt. Equal jitter stays between half and all of
|
|
11
|
+
* min(6 hours, 5 minutes * 2^(attempts-1)), preventing zero-delay retry herds while staying inside
|
|
12
|
+
* the exponential envelope. For attempts 1..8, the half-step lower bounds are approximately
|
|
13
|
+
* 2.5, 5, 10, 20, 40, 80, 160 and 180 minutes. Inject random for deterministic decisions.
|
|
14
|
+
*/
|
|
15
|
+
/** Compute equal-jitter backoff capped at six hours; the optional random port controls jitter. */
|
|
16
|
+
export function computeBackoffMs(required, optional = {}) {
|
|
17
|
+
const { attempts } = required;
|
|
18
|
+
const { random = Math.random } = optional;
|
|
19
|
+
const exponentialStep = Math.min(MAX_BACKOFF_STEP_MS, BASE_BACKOFF_MS * 2 ** (attempts - 1));
|
|
20
|
+
const half = exponentialStep / 2;
|
|
21
|
+
return Math.round(half + random() * half);
|
|
22
|
+
}
|
|
23
|
+
function addMsToIso(iso, ms) {
|
|
24
|
+
return new Date(Date.parse(iso) + ms).toISOString();
|
|
25
|
+
}
|
|
26
|
+
export class WebhookDeliveryVetoedError extends IntegrationError {
|
|
27
|
+
}
|
|
28
|
+
/** Fan out an event to active matching subscriptions, preserving existing event/subscription deduplication. Durable adapters must enforce uniqueness atomically. */
|
|
29
|
+
export async function enqueueDelivery(required, _optional = {}) {
|
|
30
|
+
const { deps, input } = required;
|
|
31
|
+
const { event } = input;
|
|
32
|
+
const matches = await deps.subscriptionRepo.findMatching({
|
|
33
|
+
workspaceId: event.workspaceId,
|
|
34
|
+
topic: event.name,
|
|
35
|
+
});
|
|
36
|
+
const enqueued = [];
|
|
37
|
+
for (const subscription of matches) {
|
|
38
|
+
const duplicate = await isAlreadyEnqueued({
|
|
39
|
+
deliveryRepo: deps.deliveryRepo,
|
|
40
|
+
workspaceId: event.workspaceId,
|
|
41
|
+
subscriptionId: subscription.id,
|
|
42
|
+
eventId: event.id,
|
|
43
|
+
});
|
|
44
|
+
if (duplicate)
|
|
45
|
+
continue;
|
|
46
|
+
const now = nowIso({ clock: deps.clock });
|
|
47
|
+
const record = {
|
|
48
|
+
id: deps.idGenerator.newId(),
|
|
49
|
+
workspaceId: event.workspaceId,
|
|
50
|
+
subscriptionId: subscription.id,
|
|
51
|
+
eventId: event.id,
|
|
52
|
+
topic: event.name,
|
|
53
|
+
status: "pending",
|
|
54
|
+
attempts: 0,
|
|
55
|
+
nextAttemptAt: now,
|
|
56
|
+
lastResponseStatus: null,
|
|
57
|
+
lastError: null,
|
|
58
|
+
signedWithVersion: null,
|
|
59
|
+
createdAt: now,
|
|
60
|
+
deliveredAt: null,
|
|
61
|
+
deadAt: null,
|
|
62
|
+
};
|
|
63
|
+
const envelope = {
|
|
64
|
+
deliveryId: record.id,
|
|
65
|
+
eventId: event.id,
|
|
66
|
+
topic: event.name,
|
|
67
|
+
workspaceId: event.workspaceId,
|
|
68
|
+
occurredAt: event.occurredAt,
|
|
69
|
+
data: event.payload,
|
|
70
|
+
};
|
|
71
|
+
// A durable adapter must co-persist the envelope in the same insert as the row, closing the
|
|
72
|
+
// crash gap before the following save. That save remains the real write for memory adapters;
|
|
73
|
+
// for an adapter with co-persistence it only repeats the same envelope harmlessly.
|
|
74
|
+
await deps.deliveryRepo.enqueue({ record }, { envelope });
|
|
75
|
+
await deps.envelopeStore.save({ deliveryId: record.id, envelope });
|
|
76
|
+
enqueued.push(record);
|
|
77
|
+
}
|
|
78
|
+
return { enqueued };
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The port has no event-specific lookup, so this guard scans prior subscription deliveries:
|
|
82
|
+
* O(matching subscriptions * their delivery history). Production storage needs an atomic unique
|
|
83
|
+
* (workspaceId, subscriptionId, eventId) constraint; a check-before-insert scan alone cannot
|
|
84
|
+
* prevent simultaneous outbox redeliveries from double-enqueuing.
|
|
85
|
+
*/
|
|
86
|
+
async function isAlreadyEnqueued(params) {
|
|
87
|
+
const existing = await params.deliveryRepo.listBySubscription({
|
|
88
|
+
workspaceId: params.workspaceId,
|
|
89
|
+
subscriptionId: params.subscriptionId,
|
|
90
|
+
limit: Number.MAX_SAFE_INTEGER,
|
|
91
|
+
});
|
|
92
|
+
return existing.some((delivery) => delivery.eventId === params.eventId);
|
|
93
|
+
}
|
|
94
|
+
// Throwing/rejecting redaction hooks and explicit vetoes fail this attempt before signing/sending;
|
|
95
|
+
// an unfiltered envelope must never fall through. Retry with normal backoff, then dead-letter.
|
|
96
|
+
/** Claim and process a bounded batch; hooks fail closed and unsuccessful attempts back off or dead-letter. */
|
|
97
|
+
export async function processDueDeliveries(required, optional = {}) {
|
|
98
|
+
const { deliveryRepo, subscriptionRepo, envelopeStore, httpClient, signer, clock, headers } = required.deps;
|
|
99
|
+
const { batchSize, hooks, requestTimeoutMs, maxAttempts, random } = resolveProcessDueDeliveriesOptions(optional);
|
|
100
|
+
const claimedAt = nowIso({ clock });
|
|
101
|
+
const claimed = await deliveryRepo.claimPending({ batchSize, nowIso: claimedAt });
|
|
102
|
+
const result = { processed: claimed.length, delivered: 0, failed: 0, dead: 0 };
|
|
103
|
+
for (const row of claimed) {
|
|
104
|
+
const outcome = await attemptOneDelivery(row, {
|
|
105
|
+
subscriptionRepo,
|
|
106
|
+
envelopeStore,
|
|
107
|
+
httpClient,
|
|
108
|
+
signer,
|
|
109
|
+
headers,
|
|
110
|
+
clock,
|
|
111
|
+
hooks,
|
|
112
|
+
requestTimeoutMs,
|
|
113
|
+
});
|
|
114
|
+
const disposition = await recordDeliveryOutcome(row, outcome, { deliveryRepo, clock, maxAttempts, random });
|
|
115
|
+
result[disposition] += 1;
|
|
116
|
+
}
|
|
117
|
+
return result;
|
|
118
|
+
}
|
|
119
|
+
function resolveProcessDueDeliveriesOptions(optional) {
|
|
120
|
+
const { batchSize = 20, hooks = [], requestTimeoutMs = 10_000, maxAttempts = MAX_DELIVERY_ATTEMPTS, random, } = optional;
|
|
121
|
+
return { batchSize, hooks, requestTimeoutMs, maxAttempts, random };
|
|
122
|
+
}
|
|
123
|
+
async function recordDeliveryOutcome(row, outcome, deps) {
|
|
124
|
+
if (outcome.ok) {
|
|
125
|
+
await deps.deliveryRepo.markDelivered({
|
|
126
|
+
workspaceId: row.workspaceId,
|
|
127
|
+
id: row.id,
|
|
128
|
+
responseStatus: outcome.responseStatus,
|
|
129
|
+
deliveredAtIso: nowIso({ clock: deps.clock }),
|
|
130
|
+
});
|
|
131
|
+
return "delivered";
|
|
132
|
+
}
|
|
133
|
+
const isExhausted = row.attempts >= deps.maxAttempts;
|
|
134
|
+
const nextStatus = isExhausted ? "dead" : "failed";
|
|
135
|
+
const failedAtIso = nowIso({ clock: deps.clock });
|
|
136
|
+
const nextAttemptAt = isExhausted
|
|
137
|
+
? failedAtIso
|
|
138
|
+
: addMsToIso(failedAtIso, computeBackoffMs({ attempts: row.attempts }, { random: deps.random }));
|
|
139
|
+
await deps.deliveryRepo.markFailed({
|
|
140
|
+
workspaceId: row.workspaceId,
|
|
141
|
+
id: row.id,
|
|
142
|
+
error: outcome.error,
|
|
143
|
+
responseStatus: outcome.responseStatus,
|
|
144
|
+
nextStatus,
|
|
145
|
+
nextAttemptAt,
|
|
146
|
+
}, isExhausted ? { deadAtIso: failedAtIso } : {});
|
|
147
|
+
return isExhausted ? "dead" : "failed";
|
|
148
|
+
}
|
|
149
|
+
// Missing/inactive subscriptions, missing envelopes, hook failures, transport failures and
|
|
150
|
+
// non-2xx responses all use one failed-attempt outcome so retry/dead-letter policy cannot drift.
|
|
151
|
+
async function attemptOneDelivery(row, deps) {
|
|
152
|
+
try {
|
|
153
|
+
const subscription = await deps.subscriptionRepo.findById({
|
|
154
|
+
workspaceId: row.workspaceId,
|
|
155
|
+
id: row.subscriptionId,
|
|
156
|
+
});
|
|
157
|
+
if (!subscription) {
|
|
158
|
+
return { ok: false, error: `subscription '${row.subscriptionId}' was not found`, responseStatus: null };
|
|
159
|
+
}
|
|
160
|
+
if (subscription.status !== "active") {
|
|
161
|
+
return {
|
|
162
|
+
ok: false,
|
|
163
|
+
error: `subscription '${row.subscriptionId}' is '${subscription.status}', not active`,
|
|
164
|
+
responseStatus: null,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
const storedEnvelope = await deps.envelopeStore.find({ deliveryId: row.id });
|
|
168
|
+
if (!storedEnvelope) {
|
|
169
|
+
return { ok: false, error: `no envelope recorded for delivery '${row.id}'`, responseStatus: null };
|
|
170
|
+
}
|
|
171
|
+
const envelope = await runBeforeDispatchHooks(deps.hooks, { subscription, envelope: storedEnvelope });
|
|
172
|
+
const rawBody = JSON.stringify(envelope);
|
|
173
|
+
const timestampSeconds = Math.floor(Date.parse(nowIso({ clock: deps.clock })) / 1000);
|
|
174
|
+
const signatureHeader = await deps.signer.signForSubscription({
|
|
175
|
+
subscription,
|
|
176
|
+
rawBody,
|
|
177
|
+
timestampSeconds,
|
|
178
|
+
});
|
|
179
|
+
const response = await deps.httpClient.send({ request: {
|
|
180
|
+
method: "POST",
|
|
181
|
+
url: subscription.targetUrl,
|
|
182
|
+
headers: {
|
|
183
|
+
"content-type": "application/json",
|
|
184
|
+
[deps.headers.signature]: signatureHeader,
|
|
185
|
+
[deps.headers.deliveryId]: row.id,
|
|
186
|
+
[deps.headers.eventId]: row.eventId,
|
|
187
|
+
},
|
|
188
|
+
timeoutMs: deps.requestTimeoutMs,
|
|
189
|
+
body: rawBody,
|
|
190
|
+
} });
|
|
191
|
+
if (response.status >= 200 && response.status < 300) {
|
|
192
|
+
return { ok: true, responseStatus: response.status };
|
|
193
|
+
}
|
|
194
|
+
return {
|
|
195
|
+
ok: false,
|
|
196
|
+
error: `non-2xx response: ${response.status}`,
|
|
197
|
+
responseStatus: response.status,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
catch (err) {
|
|
201
|
+
const message = err instanceof Error ? err.message : "unknown webhook delivery error";
|
|
202
|
+
return { ok: false, error: message, responseStatus: null };
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Thread replacements through lower-priority-first hooks. A veto throws, as does a failing hook;
|
|
207
|
+
* the delivery port has no separate veto terminal state, so both follow normal retry -> dead.
|
|
208
|
+
*/
|
|
209
|
+
async function runBeforeDispatchHooks(hooks, input) {
|
|
210
|
+
const ordered = [...hooks].sort((a, b) => a.priority - b.priority);
|
|
211
|
+
let envelope = input.envelope;
|
|
212
|
+
for (const hook of ordered) {
|
|
213
|
+
const result = await hook.handle({ subscription: input.subscription, envelope });
|
|
214
|
+
if (!result.send) {
|
|
215
|
+
throw new WebhookDeliveryVetoedError({ message: `webhooks.beforeDispatch hook vetoed delivery for subscription '${input.subscription.id}'` });
|
|
216
|
+
}
|
|
217
|
+
if (result.envelope)
|
|
218
|
+
envelope = result.envelope;
|
|
219
|
+
}
|
|
220
|
+
return envelope;
|
|
221
|
+
}
|
|
222
|
+
//# sourceMappingURL=delivery.js.map
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/** Repository adapters own durable claims, deduplication and workspace isolation. */
|
|
2
|
+
import type { ISODateTime, UUID } from "@jini-ai/core/primitives";
|
|
3
|
+
import type { IntegrationId, IntegrationSecretRecord, SealedSecret, WebhookDeliveryRecord, WebhookDeliveryStatus, WebhookEventEnvelope, WebhookSubscriptionRecord, WebhookTopic } from "./types.js";
|
|
4
|
+
export interface RootKeyHandle {
|
|
5
|
+
readonly keyId: string;
|
|
6
|
+
}
|
|
7
|
+
export interface KeyringPort {
|
|
8
|
+
activeKey(): Promise<RootKeyHandle>;
|
|
9
|
+
deriveSigningSecret(input: {
|
|
10
|
+
workspaceId: UUID;
|
|
11
|
+
subscriptionId: IntegrationId;
|
|
12
|
+
version: number;
|
|
13
|
+
}): Promise<Uint8Array>;
|
|
14
|
+
derive(input: {
|
|
15
|
+
workspaceId: UUID;
|
|
16
|
+
purpose: string;
|
|
17
|
+
info: string;
|
|
18
|
+
}): Promise<Uint8Array>;
|
|
19
|
+
}
|
|
20
|
+
export interface SecretSealerPort {
|
|
21
|
+
seal(input: {
|
|
22
|
+
plaintext: string;
|
|
23
|
+
key: RootKeyHandle;
|
|
24
|
+
aad: string;
|
|
25
|
+
}): Promise<SealedSecret>;
|
|
26
|
+
open(input: {
|
|
27
|
+
sealed: SealedSecret;
|
|
28
|
+
}, optional?: {
|
|
29
|
+
aad?: string;
|
|
30
|
+
}): Promise<string>;
|
|
31
|
+
}
|
|
32
|
+
export interface WebhookSubscriptionRepoPort {
|
|
33
|
+
insert(record: WebhookSubscriptionRecord): Promise<void>;
|
|
34
|
+
save(record: WebhookSubscriptionRecord): Promise<void>;
|
|
35
|
+
findById(required: {
|
|
36
|
+
workspaceId: UUID;
|
|
37
|
+
id: IntegrationId;
|
|
38
|
+
}): Promise<WebhookSubscriptionRecord | null>;
|
|
39
|
+
listByWorkspace(required: {
|
|
40
|
+
workspaceId: UUID;
|
|
41
|
+
}): Promise<WebhookSubscriptionRecord[]>;
|
|
42
|
+
findMatching(required: {
|
|
43
|
+
workspaceId: UUID;
|
|
44
|
+
topic: WebhookTopic;
|
|
45
|
+
}): Promise<WebhookSubscriptionRecord[]>;
|
|
46
|
+
}
|
|
47
|
+
export interface WebhookDeliveryRepoPort {
|
|
48
|
+
enqueue(required: {
|
|
49
|
+
record: WebhookDeliveryRecord;
|
|
50
|
+
}, optional?: {
|
|
51
|
+
envelope?: WebhookEventEnvelope;
|
|
52
|
+
}): Promise<void>;
|
|
53
|
+
claimPending(required: {
|
|
54
|
+
batchSize: number;
|
|
55
|
+
nowIso: ISODateTime;
|
|
56
|
+
}): Promise<WebhookDeliveryRecord[]>;
|
|
57
|
+
markDelivered(required: {
|
|
58
|
+
workspaceId: UUID;
|
|
59
|
+
id: IntegrationId;
|
|
60
|
+
responseStatus: number;
|
|
61
|
+
deliveredAtIso: ISODateTime;
|
|
62
|
+
}): Promise<void>;
|
|
63
|
+
markFailed(required: {
|
|
64
|
+
workspaceId: UUID;
|
|
65
|
+
id: IntegrationId;
|
|
66
|
+
error: string;
|
|
67
|
+
responseStatus: number | null;
|
|
68
|
+
nextStatus: Extract<WebhookDeliveryStatus, "failed" | "dead">;
|
|
69
|
+
nextAttemptAt: ISODateTime;
|
|
70
|
+
}, optional?: {
|
|
71
|
+
deadAtIso?: ISODateTime;
|
|
72
|
+
}): Promise<void>;
|
|
73
|
+
findById(required: {
|
|
74
|
+
workspaceId: UUID;
|
|
75
|
+
id: IntegrationId;
|
|
76
|
+
}): Promise<WebhookDeliveryRecord | null>;
|
|
77
|
+
listBySubscription(required: {
|
|
78
|
+
workspaceId: UUID;
|
|
79
|
+
subscriptionId: IntegrationId;
|
|
80
|
+
limit: number;
|
|
81
|
+
}): Promise<WebhookDeliveryRecord[]>;
|
|
82
|
+
}
|
|
83
|
+
export interface IntegrationSecretRepoPort {
|
|
84
|
+
insert(record: IntegrationSecretRecord): Promise<void>;
|
|
85
|
+
findById(required: {
|
|
86
|
+
workspaceId: UUID;
|
|
87
|
+
id: IntegrationId;
|
|
88
|
+
}): Promise<IntegrationSecretRecord | null>;
|
|
89
|
+
listByWorkspace(required: {
|
|
90
|
+
workspaceId: UUID;
|
|
91
|
+
}): Promise<IntegrationSecretRecord[]>;
|
|
92
|
+
delete(required: {
|
|
93
|
+
workspaceId: UUID;
|
|
94
|
+
id: IntegrationId;
|
|
95
|
+
}): Promise<void>;
|
|
96
|
+
}
|
|
97
|
+
/** Structural mapping to platform/secrets ports; no runtime import or key custody here. */
|
|
98
|
+
export interface DeliveryEnvelopeStorePort {
|
|
99
|
+
save(required: {
|
|
100
|
+
deliveryId: IntegrationId;
|
|
101
|
+
envelope: WebhookEventEnvelope;
|
|
102
|
+
}): Promise<void>;
|
|
103
|
+
find(required: {
|
|
104
|
+
deliveryId: IntegrationId;
|
|
105
|
+
}): Promise<WebhookEventEnvelope | null>;
|
|
106
|
+
}
|
|
107
|
+
/** Required host-specific HTTP header vocabulary. */
|
|
108
|
+
export interface WebhookHeaderVocabulary {
|
|
109
|
+
signature: string;
|
|
110
|
+
deliveryId: string;
|
|
111
|
+
eventId: string;
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=ports.d.ts.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { WebhookSubscriptionRecord } from "./types.js";
|
|
2
|
+
export declare const DEFAULT_SIGNATURE_TOLERANCE_SECONDS = 300;
|
|
3
|
+
/** Required wire field names, supplied by the host to preserve its existing protocol. */
|
|
4
|
+
export interface SignatureVocabulary {
|
|
5
|
+
timestampField: string;
|
|
6
|
+
signatureField: string;
|
|
7
|
+
}
|
|
8
|
+
export interface SignPayloadInput {
|
|
9
|
+
vocabulary: SignatureVocabulary;
|
|
10
|
+
secret: Buffer;
|
|
11
|
+
rawBody: string;
|
|
12
|
+
timestampSeconds: number;
|
|
13
|
+
}
|
|
14
|
+
/** Sign exact body bytes with timestamp-prefixed HMAC-SHA256 using the required wire vocabulary. */
|
|
15
|
+
export declare function signPayload(input: SignPayloadInput): string;
|
|
16
|
+
export interface VerifySignatureInput {
|
|
17
|
+
vocabulary: SignatureVocabulary;
|
|
18
|
+
nowSeconds: number;
|
|
19
|
+
secret: Buffer;
|
|
20
|
+
rawBody: string;
|
|
21
|
+
header: string;
|
|
22
|
+
toleranceSeconds: number;
|
|
23
|
+
}
|
|
24
|
+
/** Verify the raw body and replay window using caller-supplied time; malformed signatures return false. */
|
|
25
|
+
export declare function verifySignature(input: VerifySignatureInput): boolean;
|
|
26
|
+
export interface WebhookSigner {
|
|
27
|
+
signForSubscription(input: {
|
|
28
|
+
subscription: WebhookSubscriptionRecord;
|
|
29
|
+
rawBody: string;
|
|
30
|
+
timestampSeconds: number;
|
|
31
|
+
}): Promise<string>;
|
|
32
|
+
}
|
|
33
|
+
/** Create a signer from host-supplied subscription secrets; missing secrets throw. */
|
|
34
|
+
export declare function createFixedSecretSigner(required: {
|
|
35
|
+
secrets: ReadonlyMap<string, Buffer>;
|
|
36
|
+
vocabulary: SignatureVocabulary;
|
|
37
|
+
}): WebhookSigner;
|
|
38
|
+
//# sourceMappingURL=signing.d.ts.map
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { createHmac, timingSafeEqual } from "node:crypto";
|
|
2
|
+
export const DEFAULT_SIGNATURE_TOLERANCE_SECONDS = 300;
|
|
3
|
+
/** Sign exact body bytes with timestamp-prefixed HMAC-SHA256 using the required wire vocabulary. */
|
|
4
|
+
export function signPayload(input) {
|
|
5
|
+
// Sign exactly what will be sent; re-serializing afterward invalidates the timestamp/body HMAC.
|
|
6
|
+
const timestamp = input.timestampSeconds;
|
|
7
|
+
const signedContent = `${timestamp}.${input.rawBody}`;
|
|
8
|
+
const digest = createHmac("sha256", input.secret).update(signedContent).digest("hex");
|
|
9
|
+
return `${input.vocabulary.timestampField}=${timestamp},${input.vocabulary.signatureField}=${digest}`;
|
|
10
|
+
}
|
|
11
|
+
/** Verify the raw body and replay window using caller-supplied time; malformed signatures return false. */
|
|
12
|
+
export function verifySignature(input) {
|
|
13
|
+
const parsed = parseSignatureHeader(input.header, input.vocabulary);
|
|
14
|
+
if (!parsed)
|
|
15
|
+
return false;
|
|
16
|
+
const nowSeconds = input.nowSeconds;
|
|
17
|
+
if (!Number.isFinite(nowSeconds) || !Number.isFinite(input.toleranceSeconds) || input.toleranceSeconds < 0)
|
|
18
|
+
return false;
|
|
19
|
+
if (Math.abs(nowSeconds - parsed.timestamp) > input.toleranceSeconds)
|
|
20
|
+
return false;
|
|
21
|
+
const expectedHex = createHmac("sha256", input.secret)
|
|
22
|
+
.update(`${parsed.timestamp}.${input.rawBody}`)
|
|
23
|
+
.digest("hex");
|
|
24
|
+
const expected = Buffer.from(expectedHex, "hex");
|
|
25
|
+
return parsed.signatures.some((candidateHex) => {
|
|
26
|
+
// Multiple signatures allow secret-generation overlap during rotation; any matching one wins.
|
|
27
|
+
// Validate hex/length before timingSafeEqual, which throws rather than returning false on mismatch.
|
|
28
|
+
if (!/^[0-9a-f]+$/i.test(candidateHex))
|
|
29
|
+
return false;
|
|
30
|
+
const candidate = Buffer.from(candidateHex, "hex");
|
|
31
|
+
return candidate.length === expected.length && timingSafeEqual(candidate, expected);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
function parseHeaderParts(header) {
|
|
35
|
+
const parts = [];
|
|
36
|
+
for (const rawPart of header.split(",")) {
|
|
37
|
+
const part = rawPart.trim();
|
|
38
|
+
const eq = part.indexOf("=");
|
|
39
|
+
if (eq === -1)
|
|
40
|
+
continue;
|
|
41
|
+
parts.push({ key: part.slice(0, eq).trim(), value: part.slice(eq + 1).trim() });
|
|
42
|
+
}
|
|
43
|
+
return parts;
|
|
44
|
+
}
|
|
45
|
+
function applyHeaderPart(acc, part, vocabulary) {
|
|
46
|
+
// A malformed timestamp fails immediately, regardless of part order; repeated valid timestamps
|
|
47
|
+
// intentionally let the last one win to preserve the receiver's parsing contract.
|
|
48
|
+
if (part.key === vocabulary.timestampField) {
|
|
49
|
+
const parsedTimestamp = Number(part.value);
|
|
50
|
+
if (!Number.isFinite(parsedTimestamp))
|
|
51
|
+
return false;
|
|
52
|
+
acc.timestamp = parsedTimestamp;
|
|
53
|
+
}
|
|
54
|
+
else if (part.key === vocabulary.signatureField) {
|
|
55
|
+
acc.signatures.push(part.value);
|
|
56
|
+
}
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
function parseSignatureHeader(header, vocabulary) {
|
|
60
|
+
const acc = { signatures: [] };
|
|
61
|
+
for (const part of parseHeaderParts(header)) {
|
|
62
|
+
if (!applyHeaderPart(acc, part, vocabulary))
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
if (acc.timestamp === undefined || acc.signatures.length === 0)
|
|
66
|
+
return null;
|
|
67
|
+
return { timestamp: acc.timestamp, signatures: acc.signatures };
|
|
68
|
+
}
|
|
69
|
+
/** Create a signer from host-supplied subscription secrets; missing secrets throw. */
|
|
70
|
+
export function createFixedSecretSigner(required) {
|
|
71
|
+
// A fixed map is a local/dev fixture. Production should derive signing bytes behind a keyring
|
|
72
|
+
// boundary rather than persist raw secrets; this pure primitive does not own root-key access.
|
|
73
|
+
return {
|
|
74
|
+
async signForSubscription({ subscription, rawBody, timestampSeconds }) {
|
|
75
|
+
const secret = required.secrets.get(subscription.id);
|
|
76
|
+
if (!secret) {
|
|
77
|
+
throw new Error(`no signing secret configured for subscription '${subscription.id}'`);
|
|
78
|
+
}
|
|
79
|
+
return signPayload({ secret, rawBody, timestampSeconds, vocabulary: required.vocabulary });
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=signing.js.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Derive signing material through a local structural platform/secrets port; raw root keys stay in the adapter. */
|
|
2
|
+
import { type SignatureVocabulary, type WebhookSigner } from "./signing.js";
|
|
3
|
+
import type { KeyringPort } from "./ports.js";
|
|
4
|
+
export declare function createKeyringBackedSigner(required: {
|
|
5
|
+
keyring: Pick<KeyringPort, "deriveSigningSecret">;
|
|
6
|
+
vocabulary: SignatureVocabulary;
|
|
7
|
+
}): WebhookSigner;
|
|
8
|
+
//# sourceMappingURL=signing.keyring.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** Derive signing material through a local structural platform/secrets port; raw root keys stay in the adapter. */
|
|
2
|
+
import { signPayload } from "./signing.js";
|
|
3
|
+
// Re-derive each subscription's secret for every delivery attempt; never cache or persist signing
|
|
4
|
+
// material here. The keyring owns root-key derivation, while delivery depends on WebhookSigner
|
|
5
|
+
// so replacing a fixed-secret development signer requires only dependency injection.
|
|
6
|
+
export function createKeyringBackedSigner(required) {
|
|
7
|
+
return {
|
|
8
|
+
async signForSubscription({ subscription, rawBody, timestampSeconds }) {
|
|
9
|
+
const secret = await required.keyring.deriveSigningSecret({
|
|
10
|
+
workspaceId: subscription.workspaceId,
|
|
11
|
+
subscriptionId: subscription.id,
|
|
12
|
+
version: subscription.secretVersion,
|
|
13
|
+
});
|
|
14
|
+
return signPayload({ secret: Buffer.from(secret), rawBody, timestampSeconds, vocabulary: required.vocabulary });
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=signing.keyring.js.map
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { IntegrationError } from "../argument-error.js";
|
|
2
|
+
import type { Clock, IdGenerator, UUID } from "@jini-ai/core/primitives";
|
|
3
|
+
import type { WebhookSubscriptionRepoPort } from "./ports.js";
|
|
4
|
+
import type { WebhookSubscriptionRecord, WebhookTopic } from "./types.js";
|
|
5
|
+
export declare class WebhookSubscriptionNotFoundError extends IntegrationError {
|
|
6
|
+
}
|
|
7
|
+
export declare class WebhookSubscriptionValidationError extends IntegrationError {
|
|
8
|
+
}
|
|
9
|
+
export interface WebhookSubscriptionDeps {
|
|
10
|
+
clock: Clock;
|
|
11
|
+
repo: WebhookSubscriptionRepoPort;
|
|
12
|
+
idGenerator: IdGenerator;
|
|
13
|
+
isAllowedTarget: (required: {
|
|
14
|
+
url: string;
|
|
15
|
+
}) => Promise<boolean>;
|
|
16
|
+
}
|
|
17
|
+
export interface CreateSubscriptionInput {
|
|
18
|
+
workspaceId: UUID;
|
|
19
|
+
ownerPrincipalId: UUID;
|
|
20
|
+
label: string;
|
|
21
|
+
targetUrl: string;
|
|
22
|
+
topics: readonly WebhookTopic[];
|
|
23
|
+
createdByPrincipalId: UUID;
|
|
24
|
+
}
|
|
25
|
+
export interface CreateSubscriptionRequired {
|
|
26
|
+
deps: WebhookSubscriptionDeps;
|
|
27
|
+
input: CreateSubscriptionInput;
|
|
28
|
+
}
|
|
29
|
+
export interface WebhookSubscriptionOptional {
|
|
30
|
+
createdByPluginId?: string | null;
|
|
31
|
+
}
|
|
32
|
+
/** Validate then insert an active subscription; no write occurs on validation failure. */
|
|
33
|
+
export declare function createSubscription(required: CreateSubscriptionRequired, optional?: WebhookSubscriptionOptional): Promise<{
|
|
34
|
+
subscription: WebhookSubscriptionRecord;
|
|
35
|
+
}>;
|
|
36
|
+
export interface UpdateSubscriptionInput {
|
|
37
|
+
workspaceId: UUID;
|
|
38
|
+
id: UUID;
|
|
39
|
+
label: string;
|
|
40
|
+
targetUrl: string;
|
|
41
|
+
topics: readonly WebhookTopic[];
|
|
42
|
+
}
|
|
43
|
+
export interface UpdateSubscriptionRequired {
|
|
44
|
+
deps: WebhookSubscriptionDeps;
|
|
45
|
+
input: UpdateSubscriptionInput;
|
|
46
|
+
}
|
|
47
|
+
/** Validate a replacement before saving; missing workspace-scoped rows throw. */
|
|
48
|
+
export declare function updateSubscription(required: UpdateSubscriptionRequired, _optional?: WebhookSubscriptionOptional): Promise<{
|
|
49
|
+
subscription: WebhookSubscriptionRecord;
|
|
50
|
+
}>;
|
|
51
|
+
export interface PauseSubscriptionInput {
|
|
52
|
+
workspaceId: UUID;
|
|
53
|
+
id: UUID;
|
|
54
|
+
}
|
|
55
|
+
export interface PauseSubscriptionRequired {
|
|
56
|
+
deps: WebhookSubscriptionDeps;
|
|
57
|
+
input: PauseSubscriptionInput;
|
|
58
|
+
}
|
|
59
|
+
export interface PauseSubscriptionOptional {
|
|
60
|
+
paused?: boolean;
|
|
61
|
+
}
|
|
62
|
+
/** Pause or resume a subscription; disabled subscriptions cannot resume. */
|
|
63
|
+
export declare function pauseSubscription(required: PauseSubscriptionRequired, optional?: PauseSubscriptionOptional): Promise<{
|
|
64
|
+
subscription: WebhookSubscriptionRecord;
|
|
65
|
+
}>;
|
|
66
|
+
export interface DeleteSubscriptionInput {
|
|
67
|
+
workspaceId: UUID;
|
|
68
|
+
id: UUID;
|
|
69
|
+
}
|
|
70
|
+
export interface DeleteSubscriptionRequired {
|
|
71
|
+
deps: WebhookSubscriptionDeps;
|
|
72
|
+
input: DeleteSubscriptionInput;
|
|
73
|
+
}
|
|
74
|
+
/** Soft-disable a subscription while retaining its audit history. */
|
|
75
|
+
export declare function deleteSubscription(required: DeleteSubscriptionRequired, _optional?: WebhookSubscriptionOptional): Promise<{
|
|
76
|
+
subscription: WebhookSubscriptionRecord;
|
|
77
|
+
}>;
|
|
78
|
+
//# sourceMappingURL=subscriptions.d.ts.map
|