@jini-ai/integrations 0.7.3-next.2 → 0.7.4
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 +7 -0
- package/README.md +1 -0
- package/dist/api-connections/bundled-client-namespace.d.ts +24 -0
- package/dist/api-connections/bundled-client-namespace.js +22 -0
- package/dist/api-connections/connect.d.ts +2 -10
- package/dist/api-connections/connect.js +1 -1
- package/dist/api-connections/contribution.d.ts +71 -0
- package/dist/api-connections/contribution.js +69 -0
- package/dist/api-connections/form-delivery-connection.d.ts +68 -0
- package/dist/api-connections/form-delivery-connection.js +73 -0
- package/dist/api-connections/hosted-mcp/contracts.d.ts +4 -171
- package/dist/api-connections/hosted-mcp/index.d.ts +2 -0
- package/dist/api-connections/hosted-mcp/oauth-row-writes.d.ts +3 -1
- package/dist/api-connections/hosted-mcp/oauth-row-writes.js +6 -3
- package/dist/api-connections/hosted-mcp/shared-sign-in.d.ts +2 -1
- package/dist/api-connections/hosted-mcp/sign-in-configuration.js +1 -1
- package/dist/api-connections/hosted-mcp/sign-in-discovery.js +1 -1
- package/dist/api-connections/hosted-mcp/sign-in-flow.d.ts +9 -3
- package/dist/api-connections/hosted-mcp/sign-in-flow.js +6 -6
- package/dist/api-connections/hosted-mcp/sign-in-provider.d.ts +16 -4
- package/dist/api-connections/hosted-mcp/sign-in-provider.js +3 -3
- package/dist/api-connections/hosted-mcp/sign-in-status.d.ts +13 -2
- package/dist/api-connections/hosted-mcp/sign-in-status.js +17 -4
- package/dist/api-connections/hosted-mcp/sign-in.d.ts +1 -1
- package/dist/api-connections/hosted-mcp/sign-in.js +28 -30
- package/dist/api-connections/shared-api.d.ts +87 -0
- package/dist/api-connections/shared-api.js +135 -0
- package/dist/api-connections/shared-oauth-disconnect.d.ts +73 -0
- package/dist/api-connections/shared-oauth-disconnect.js +41 -0
- package/dist/api-connections/shared-owner.d.ts +107 -0
- package/dist/api-connections/shared-owner.js +79 -0
- package/dist/api-connections/vault-stores.d.ts +110 -0
- package/dist/api-connections/vault-stores.js +202 -0
- package/dist/credentialed-http/auth-schemes.d.ts +2 -9
- package/dist/credentialed-http/tools/index.d.ts +30 -0
- package/dist/credentialed-http/tools/index.js +19 -0
- package/dist/credentialed-http/tools/tool-registrations.js +0 -1
- package/dist/custom-credentials/agent-tools.d.ts +79 -0
- package/dist/custom-credentials/agent-tools.js +98 -0
- package/dist/custom-credentials/card-token.d.ts +15 -0
- package/dist/custom-credentials/card-token.js +35 -0
- package/dist/custom-credentials/credential-ports.d.ts +70 -0
- package/dist/custom-credentials/credential-ports.js +41 -0
- package/dist/custom-credentials/credential-recovery.d.ts +20 -0
- package/dist/custom-credentials/credential-recovery.js +22 -0
- package/dist/custom-credentials/credentialed-request.d.ts +83 -0
- package/dist/custom-credentials/credentialed-request.js +93 -0
- package/dist/custom-credentials/custom-credential-create-ui.d.ts +106 -0
- package/dist/custom-credentials/custom-credential-create-ui.js +136 -0
- package/dist/custom-credentials/custom-credential-set-token-ui.d.ts +84 -0
- package/dist/custom-credentials/custom-credential-set-token-ui.js +104 -0
- package/dist/custom-credentials/delete-request-confirmation-ui.d.ts +33 -0
- package/dist/custom-credentials/delete-request-confirmation-ui.js +35 -0
- package/dist/custom-credentials/provider-settings-card.d.ts +109 -0
- package/dist/custom-credentials/provider-settings-card.js +166 -0
- package/dist/custom-credentials/write-files-validation.d.ts +102 -0
- package/dist/custom-credentials/write-files-validation.js +202 -0
- package/dist/media-providers/catalog-projection.d.ts +29 -0
- package/dist/media-providers/catalog-projection.js +45 -0
- package/dist/media-providers/catalog.d.ts +6 -3
- package/dist/media-providers/catalog.js +4 -3
- package/dist/media-providers/configurable-catalog.d.ts +9 -0
- package/dist/media-providers/configurable-catalog.js +70 -0
- package/dist/media-providers/dispatch/builtin-vendors.js +0 -2
- package/dist/media-providers/dispatch/credentials.d.ts +4 -1
- package/dist/media-providers/dispatch/credentials.js +3 -2
- package/dist/media-providers/dispatch/engine.d.ts +1 -1
- package/dist/media-providers/dispatch/engine.js +17 -5
- package/dist/media-providers/dispatch/index.d.ts +3 -2
- package/dist/media-providers/dispatch/index.js +2 -2
- package/dist/media-providers/dispatch/media-provider-registry.d.ts +23 -4
- package/dist/media-providers/dispatch/media-provider-registry.js +26 -11
- package/dist/media-providers/dispatch/media-wire.d.ts +14 -0
- package/dist/media-providers/dispatch/media-wire.js +22 -0
- package/dist/media-providers/dispatch/node.d.ts +5 -0
- package/dist/media-providers/dispatch/node.js +5 -1
- package/dist/media-providers/dispatch/openai-compatible.d.ts +3 -1
- package/dist/media-providers/dispatch/openai-compatible.js +1 -1
- package/dist/media-providers/dispatch/operation-runtime.js +5 -4
- package/dist/media-providers/dispatch/outbound.d.ts +28 -3
- package/dist/media-providers/dispatch/outbound.js +10 -3
- package/dist/media-providers/dispatch/providers/custom-image.js +1 -1
- package/dist/media-providers/dispatch/providers/imagerouter.js +1 -1
- package/dist/media-providers/dispatch/providers/nanobanana.js +1 -1
- package/dist/media-providers/dispatch/providers/openrouter.js +1 -1
- package/dist/media-providers/dispatch/ssrf-guard.js +2 -2
- package/dist/media-providers/dispatch/types.d.ts +13 -4
- package/dist/media-providers/dispatch/vendor-adapter.js +2 -2
- package/dist/media-providers/index.d.ts +2 -0
- package/dist/media-providers/providers.d.ts +9 -5
- package/dist/media-providers/providers.js +9 -12
- package/dist/media-providers/sqlite-task-store.d.ts +4 -4
- package/dist/media-providers/task-store.d.ts +1 -1
- package/dist/media-providers/task-store.js +1 -1
- package/dist/media-providers/types.d.ts +0 -36
- package/dist/media-providers/ui-defaults.js +0 -4
- package/dist/react/admin-credentials/AdminByokKeyPanel.d.ts +130 -0
- package/dist/react/admin-credentials/AdminByokKeyPanel.js +115 -0
- package/dist/react/admin-credentials/byok-footer-status.d.ts +37 -0
- package/dist/react/admin-credentials/byok-footer-status.js +25 -0
- package/dist/react/credentials/OtherCredentialsSection.d.ts +36 -0
- package/dist/react/credentials/OtherCredentialsSection.hooks.d.ts +55 -0
- package/dist/react/credentials/OtherCredentialsSection.hooks.js +26 -0
- package/dist/react/credentials/OtherCredentialsSection.js +120 -0
- package/dist/react/credentials/access-token-forms.d.ts +219 -0
- package/dist/react/credentials/access-token-forms.js +114 -0
- package/dist/react/credentials/credential-copy.d.ts +17 -0
- package/dist/react/credentials/credential-copy.js +7 -0
- package/dist/react/credentials/other-credential-stores.d.ts +115 -0
- package/dist/react/credentials/other-credential-stores.js +76 -0
- package/dist/react/site-key/SiteKeyRecoveryCard.d.ts +16 -0
- package/dist/react/site-key/SiteKeyRecoveryCard.js +36 -0
- package/dist/react/site-key/SiteKeyTab.d.ts +100 -0
- package/dist/react/site-key/SiteKeyTab.js +127 -0
- package/dist/react/site-key/hooks/use-site-key-recovery.hooks.d.ts +77 -0
- package/dist/react/site-key/hooks/use-site-key-recovery.hooks.js +126 -0
- package/dist/react/site-key/hooks/use-site-key.hooks.d.ts +120 -0
- package/dist/react/site-key/hooks/use-site-key.hooks.js +95 -0
- package/dist/react/webhooks/IntegrationDeliveries.d.ts +41 -0
- package/dist/react/webhooks/IntegrationDeliveries.js +24 -0
- package/dist/react/webhooks/Integrations.d.ts +73 -0
- package/dist/react/webhooks/Integrations.js +97 -0
- package/dist/react/webhooks/hooks/use-integration-deliveries.hooks.d.ts +59 -0
- package/dist/react/webhooks/hooks/use-integration-deliveries.hooks.js +11 -0
- package/dist/react/webhooks/hooks/use-integrations.hooks.d.ts +119 -0
- package/dist/react/webhooks/hooks/use-integrations.hooks.js +129 -0
- package/dist/react/webhooks/rules.d.ts +118 -0
- package/dist/react/webhooks/rules.js +103 -0
- package/dist/saved-requests/execute.js +2 -3
- package/dist/saved-requests/types.d.ts +4 -1
- package/dist/secrets/index.d.ts +3 -0
- package/dist/secrets/index.js +3 -0
- package/dist/secrets/ports.d.ts +25 -0
- package/dist/secrets/ports.js +2 -0
- package/dist/secrets/types.d.ts +10 -0
- package/dist/secrets/types.js +2 -0
- package/dist/vendor-credentials/abort-guarded-repo.d.ts +14 -0
- package/dist/vendor-credentials/abort-guarded-repo.js +41 -0
- package/dist/vendor-credentials/project-scope.d.ts +43 -0
- package/dist/vendor-credentials/project-scope.js +32 -0
- package/dist/vendor-credentials/vault-adapter.d.ts +157 -0
- package/dist/vendor-credentials/vault-adapter.js +220 -0
- package/dist/web-screenshot/capture-files.d.ts +44 -0
- package/dist/web-screenshot/capture-files.js +62 -0
- package/dist/web-screenshot/capture-retention.d.ts +157 -0
- package/dist/web-screenshot/capture-retention.js +134 -0
- package/dist/web-screenshot/capture-root-file-lock.d.ts +20 -0
- package/dist/web-screenshot/capture-root-file-lock.js +15 -0
- package/dist/web-screenshot/desktop-page-capture.d.ts +37 -0
- package/dist/web-screenshot/desktop-page-capture.js +62 -0
- package/dist/web-screenshot/own-site-opener.d.ts +40 -0
- package/dist/web-screenshot/own-site-opener.js +27 -0
- package/dist/web-screenshot/screenshot-image.d.ts +11 -0
- package/dist/web-screenshot/screenshot-image.js +12 -0
- package/dist/web-screenshot/web-screenshot.d.ts +188 -0
- package/dist/web-screenshot/web-screenshot.js +329 -0
- package/dist/webhooks/delivery.d.ts +16 -0
- package/dist/webhooks/delivery.js +41 -1
- package/dist/webhooks/ports.d.ts +1 -29
- package/dist/webhooks/signing.keyring.d.ts +1 -1
- package/dist/webhooks/site/delivery.d.ts +60 -0
- package/dist/webhooks/site/delivery.js +45 -0
- package/dist/webhooks/site/http.memory.d.ts +51 -0
- package/dist/webhooks/site/http.memory.js +28 -0
- package/dist/webhooks/site/repo.memory.d.ts +136 -0
- package/dist/webhooks/site/repo.memory.js +215 -0
- package/dist/webhooks/site/seal-aad-invariant.d.ts +26 -0
- package/dist/webhooks/site/seal-aad-invariant.js +61 -0
- package/dist/webhooks/site/seal-aad-invariant.node.d.ts +42 -0
- package/dist/webhooks/site/seal-aad-invariant.node.js +52 -0
- package/dist/webhooks/site/signing.d.ts +28 -0
- package/dist/webhooks/site/signing.js +27 -0
- package/dist/webhooks/site/signing.keyring.d.ts +29 -0
- package/dist/webhooks/site/signing.keyring.js +30 -0
- package/dist/webhooks/site/subscriptions.d.ts +118 -0
- package/dist/webhooks/site/subscriptions.js +98 -0
- package/dist/webhooks/sql/index.d.ts +4 -0
- package/dist/webhooks/sql/index.js +2 -0
- package/dist/webhooks/sql/repo.rows.d.ts +47 -0
- package/dist/webhooks/sql/repo.rows.js +2 -0
- package/dist/webhooks/sql/webhook-repo.d.ts +152 -0
- package/dist/webhooks/sql/webhook-repo.js +308 -0
- package/dist/webhooks/subscriptions.d.ts +3 -1
- package/dist/webhooks/subscriptions.js +4 -1
- package/dist/webhooks/tools/tool-handlers.js +2 -1
- package/dist/webhooks/types.d.ts +6 -10
- package/package.json +517 -12
- package/dist/media-providers/dispatch/providers/grok.d.ts +0 -55
- package/dist/media-providers/dispatch/providers/grok.js +0 -116
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/** Bind the canonical delivery worker to the host's wire headers, ISO clock and outbound HTTP policy.
|
|
2
|
+
* Hook throws/vetoes must fail the attempt before unfiltered data can be sent; they follow the
|
|
3
|
+
* ordinary backoff/dead path because the delivery port has no separate veto terminal state.
|
|
4
|
+
*/
|
|
5
|
+
import { type EnqueueDeliveryDeps as JiniEnqueueDeps, type ProcessDueDeliveriesDeps as JiniProcessDeps, type EnqueueDeliveryOptional, type ProcessDueDeliveriesOptional, type ProcessDueDeliveriesResult, type WebhookSourceEvent } from "../delivery.js";
|
|
6
|
+
import type { WebhookDeliveryRepoPort } from "../ports.js";
|
|
7
|
+
import type { HttpRequest, HttpResponse } from "@jini-ai/core/primitives";
|
|
8
|
+
/** The host's positional outbound HTTP client, structurally: one `send(request)` per call. Its
|
|
9
|
+
* redirect policy is fixed by host composition (see {@link adaptWebhookHttpClient}). */
|
|
10
|
+
export interface HttpClientPort {
|
|
11
|
+
send(request: HttpRequest): Promise<HttpResponse>;
|
|
12
|
+
}
|
|
13
|
+
export interface EnqueueDeliveryDeps extends Omit<JiniEnqueueDeps, "deliveryRepo" | "clock"> {
|
|
14
|
+
deliveryRepo: WebhookDeliveryRepoPort;
|
|
15
|
+
clock: {
|
|
16
|
+
nowIso(): string;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export interface EnqueueDeliveryRequired {
|
|
20
|
+
deps: EnqueueDeliveryDeps;
|
|
21
|
+
input: {
|
|
22
|
+
event: WebhookSourceEvent;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export interface ProcessDueDeliveriesDeps extends Omit<JiniProcessDeps, "deliveryRepo" | "httpClient" | "clock"> {
|
|
26
|
+
deliveryRepo: WebhookDeliveryRepoPort;
|
|
27
|
+
httpClient: HttpClientPort;
|
|
28
|
+
clock: {
|
|
29
|
+
nowIso(): string;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export interface ProcessDueDeliveriesRequired {
|
|
33
|
+
deps: ProcessDueDeliveriesDeps;
|
|
34
|
+
}
|
|
35
|
+
/** Retain atomic durable enqueue({ record }, { envelope }) and optional dead-letter timestamps.
|
|
36
|
+
* ADR-046 fold-in item 5 (GAP-05/GAP-12): the durable adapter writes the envelope in the SAME
|
|
37
|
+
* INSERT as the delivery row, closing the crash gap. Jini's following envelopeStore.save remains
|
|
38
|
+
* the actual write for memory adapters and a harmless repeated write for co-persisting adapters.
|
|
39
|
+
*/
|
|
40
|
+
/** Delegate fan-out without changing durable deduplication or envelope co-persistence.
|
|
41
|
+
* @complexity O(matching subscriptions × delivery history), as defined by the existing repo port.
|
|
42
|
+
*/
|
|
43
|
+
export declare function enqueueDelivery({ deps, input }: EnqueueDeliveryRequired, optional?: EnqueueDeliveryOptional): Promise<{
|
|
44
|
+
enqueued: import("../types.js").WebhookDeliveryRecord[];
|
|
45
|
+
}>;
|
|
46
|
+
/** Adapt the host's outbound HTTP port to the canonical delivery worker's `send({ request }, options)`.
|
|
47
|
+
* Preserve the signed body bytes; only unwrap the canonical HTTP request object.
|
|
48
|
+
* Redirect policy comes from host composition; unsupported per-call controls fail closed.
|
|
49
|
+
* @throws {Error} When a caller asks for a per-request redirect control.
|
|
50
|
+
* @complexity O(1) per send, plus the wrapped client's own cost.
|
|
51
|
+
*/
|
|
52
|
+
export declare function adaptWebhookHttpClient({ httpClient }: {
|
|
53
|
+
httpClient: HttpClientPort;
|
|
54
|
+
}, _optional?: Record<string, never>): JiniProcessDeps["httpClient"];
|
|
55
|
+
/** Jini owns claim/retry/hooks/sign/send; host adapters preserve transport and signature headers.
|
|
56
|
+
* Delivery is at least once. Receivers can deduplicate by the host's delivery-id header (`deps.headers.deliveryId`) within the subscription.
|
|
57
|
+
* @complexity O(batch size × bounded envelope bytes), with one bounded HTTP request per delivery.
|
|
58
|
+
*/
|
|
59
|
+
export declare function processDueDeliveries({ deps }: ProcessDueDeliveriesRequired, optional?: ProcessDueDeliveriesOptional): Promise<ProcessDueDeliveriesResult>;
|
|
60
|
+
//# sourceMappingURL=delivery.d.ts.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Delivery, deduplication, jitter and hook rationale: ../delivery.ts.
|
|
2
|
+
/** Bind the canonical delivery worker to the host's wire headers, ISO clock and outbound HTTP policy.
|
|
3
|
+
* Hook throws/vetoes must fail the attempt before unfiltered data can be sent; they follow the
|
|
4
|
+
* ordinary backoff/dead path because the delivery port has no separate veto terminal state.
|
|
5
|
+
*/
|
|
6
|
+
import { enqueueDelivery as enqueueWebhookDelivery, processDueDeliveries as processWebhookDeliveries, } from "../delivery.js";
|
|
7
|
+
/** Retain atomic durable enqueue({ record }, { envelope }) and optional dead-letter timestamps.
|
|
8
|
+
* ADR-046 fold-in item 5 (GAP-05/GAP-12): the durable adapter writes the envelope in the SAME
|
|
9
|
+
* INSERT as the delivery row, closing the crash gap. Jini's following envelopeStore.save remains
|
|
10
|
+
* the actual write for memory adapters and a harmless repeated write for co-persisting adapters.
|
|
11
|
+
*/
|
|
12
|
+
/** Delegate fan-out without changing durable deduplication or envelope co-persistence.
|
|
13
|
+
* @complexity O(matching subscriptions × delivery history), as defined by the existing repo port.
|
|
14
|
+
*/
|
|
15
|
+
export function enqueueDelivery({ deps, input }, optional = {}) {
|
|
16
|
+
return enqueueWebhookDelivery({ deps: {
|
|
17
|
+
...deps,
|
|
18
|
+
clock: { nowMs: () => Date.parse(deps.clock.nowIso()) },
|
|
19
|
+
}, input }, optional);
|
|
20
|
+
}
|
|
21
|
+
/** Adapt the host's outbound HTTP port to the canonical delivery worker's `send({ request }, options)`.
|
|
22
|
+
* Preserve the signed body bytes; only unwrap the canonical HTTP request object.
|
|
23
|
+
* Redirect policy comes from host composition; unsupported per-call controls fail closed.
|
|
24
|
+
* @throws {Error} When a caller asks for a per-request redirect control.
|
|
25
|
+
* @complexity O(1) per send, plus the wrapped client's own cost.
|
|
26
|
+
*/
|
|
27
|
+
export function adaptWebhookHttpClient({ httpClient }, _optional = {}) {
|
|
28
|
+
return { send: ({ request }, options = {}) => {
|
|
29
|
+
if (options.redirect !== undefined)
|
|
30
|
+
throw new Error("webhook HTTP adapter does not support per-request redirect controls");
|
|
31
|
+
return httpClient.send(request);
|
|
32
|
+
} };
|
|
33
|
+
}
|
|
34
|
+
/** Jini owns claim/retry/hooks/sign/send; host adapters preserve transport and signature headers.
|
|
35
|
+
* Delivery is at least once. Receivers can deduplicate by the host's delivery-id header (`deps.headers.deliveryId`) within the subscription.
|
|
36
|
+
* @complexity O(batch size × bounded envelope bytes), with one bounded HTTP request per delivery.
|
|
37
|
+
*/
|
|
38
|
+
export function processDueDeliveries({ deps }, optional = {}) {
|
|
39
|
+
return processWebhookDeliveries({ deps: {
|
|
40
|
+
...deps,
|
|
41
|
+
httpClient: adaptWebhookHttpClient({ httpClient: deps.httpClient }),
|
|
42
|
+
clock: { nowMs: () => Date.parse(deps.clock.nowIso()) },
|
|
43
|
+
} }, optional);
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=delivery.js.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { HttpClientPort } from "./delivery.js";
|
|
2
|
+
import type { HttpRequest, HttpResponse } from "@jini-ai/core/primitives";
|
|
3
|
+
/**
|
|
4
|
+
* @file A recording, scriptable `HttpClientPort` test double for the delivery worker.
|
|
5
|
+
*
|
|
6
|
+
* Purpose:
|
|
7
|
+
* `processDueDeliveries` (./delivery.ts) depends on `HttpClientPort` (imported from `./delivery.ts`,
|
|
8
|
+
* ADR-038) to POST signed deliveries. This is NOT the real guarded transport — building that is
|
|
9
|
+
* the host transport's job (out of scope here). This is a recording double: every `send()` call is
|
|
10
|
+
* captured for assertions, and responses (or thrown transport errors) are scripted per-call so
|
|
11
|
+
* tests can exercise success, non-2xx failure, and repeated-failure-to-exhaustion paths without
|
|
12
|
+
* a network.
|
|
13
|
+
*
|
|
14
|
+
* How it relates to the project:
|
|
15
|
+
* - Satisfies the same `HttpClientPort` interface `./delivery.ts` declares, so it drops in
|
|
16
|
+
* wherever the real client would.
|
|
17
|
+
* - Used by `./__tests__/delivery.test.ts`.
|
|
18
|
+
*
|
|
19
|
+
* Architectural role:
|
|
20
|
+
* Test infrastructure only. Never wired into production composition.
|
|
21
|
+
*/
|
|
22
|
+
export interface RecordedHttpCall {
|
|
23
|
+
readonly request: HttpRequest;
|
|
24
|
+
}
|
|
25
|
+
/** One scripted response: a literal response, or a thunk that can return or throw (to simulate
|
|
26
|
+
* a transport-level failure rather than a non-2xx HTTP response). */
|
|
27
|
+
export type ScriptedHttpResponse = HttpResponse | (() => HttpResponse);
|
|
28
|
+
export interface RecordingHttpClientOptions {
|
|
29
|
+
/**
|
|
30
|
+
* Responses returned in call order. When calls exceed the list length, the last entry repeats
|
|
31
|
+
* (so a short "always fails" script doesn't need one entry per retry attempt). Defaults to a
|
|
32
|
+
* single always-200 response.
|
|
33
|
+
*/
|
|
34
|
+
responses?: readonly ScriptedHttpResponse[];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Records every `send()` call and returns scripted responses in order (see
|
|
38
|
+
* `RecordingHttpClientOptions.responses`).
|
|
39
|
+
*
|
|
40
|
+
* @overallScore 100
|
|
41
|
+
* Purity/effect: `send` is the one effectful method (records + returns/throws per script); no
|
|
42
|
+
* other state mutation. No findings.
|
|
43
|
+
*/
|
|
44
|
+
export declare class RecordingHttpClient implements HttpClientPort {
|
|
45
|
+
readonly calls: RecordedHttpCall[];
|
|
46
|
+
private readonly responses;
|
|
47
|
+
private cursor;
|
|
48
|
+
constructor(options?: RecordingHttpClientOptions);
|
|
49
|
+
send(request: HttpRequest): Promise<HttpResponse>;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=http.memory.d.ts.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Records every `send()` call and returns scripted responses in order (see
|
|
3
|
+
* `RecordingHttpClientOptions.responses`).
|
|
4
|
+
*
|
|
5
|
+
* @overallScore 100
|
|
6
|
+
* Purity/effect: `send` is the one effectful method (records + returns/throws per script); no
|
|
7
|
+
* other state mutation. No findings.
|
|
8
|
+
*/
|
|
9
|
+
export class RecordingHttpClient {
|
|
10
|
+
calls = [];
|
|
11
|
+
responses;
|
|
12
|
+
cursor = 0;
|
|
13
|
+
constructor(options = {}) {
|
|
14
|
+
this.responses = options.responses ?? [{ status: 200, headers: {}, bodyText: "" }];
|
|
15
|
+
}
|
|
16
|
+
async send(request) {
|
|
17
|
+
this.calls.push({ request });
|
|
18
|
+
const index = Math.min(this.cursor, this.responses.length - 1);
|
|
19
|
+
const entry = this.responses[index];
|
|
20
|
+
this.cursor += 1;
|
|
21
|
+
// Jini compiles with noUncheckedIndexedAccess: an explicitly empty `responses` script has no
|
|
22
|
+
// entry to replay, so fail loudly instead of resolving `undefined` as an HttpResponse.
|
|
23
|
+
if (entry === undefined)
|
|
24
|
+
throw new Error("RecordingHttpClient: no scripted responses");
|
|
25
|
+
return typeof entry === "function" ? entry() : entry;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=http.memory.js.map
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import type { DeliveryEnvelopeStorePort, WebhookDeliveryRepoPort, WebhookSubscriptionRepoPort } from "../ports.js";
|
|
2
|
+
import type { AssertVersionedWritePort } from "@jini-ai/core/optimistic-concurrency";
|
|
3
|
+
import type { IntegrationId, WebhookDeliveryRecord, WebhookEventEnvelope, WebhookSubscriptionRecord, WebhookTopic } from "../types.js";
|
|
4
|
+
/** The memory subscription adapter's constructor object: the host binds its optimistic-concurrency
|
|
5
|
+
* implementation, as for `SqlWebhookSubscriptionRepo` (see `../sql/webhook-repo.ts`). */
|
|
6
|
+
export interface InMemoryWebhookSubscriptionRequired {
|
|
7
|
+
assertVersionedWrite: AssertVersionedWritePort;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* In-memory `WebhookSubscriptionRepoPort` adapter (ADR-036 §2 `webhook_subscriptions`).
|
|
11
|
+
*
|
|
12
|
+
* @overallScore 100
|
|
13
|
+
* Purity/effect: all methods mutate the private `Map`; no I/O beyond memory. No findings.
|
|
14
|
+
*/
|
|
15
|
+
export declare class InMemoryWebhookSubscriptionRepo implements WebhookSubscriptionRepoPort {
|
|
16
|
+
private rows;
|
|
17
|
+
private readonly assertVersionedWrite;
|
|
18
|
+
constructor({ assertVersionedWrite }: InMemoryWebhookSubscriptionRequired, { initialRows }?: {
|
|
19
|
+
initialRows?: WebhookSubscriptionRecord[];
|
|
20
|
+
});
|
|
21
|
+
insert(record: WebhookSubscriptionRecord): Promise<void>;
|
|
22
|
+
save(record: WebhookSubscriptionRecord, optional?: {
|
|
23
|
+
expectedVersion?: number;
|
|
24
|
+
}): Promise<void>;
|
|
25
|
+
findById(required: {
|
|
26
|
+
workspaceId: string;
|
|
27
|
+
id: IntegrationId;
|
|
28
|
+
}): Promise<WebhookSubscriptionRecord | null>;
|
|
29
|
+
listByWorkspace(required: {
|
|
30
|
+
workspaceId: string;
|
|
31
|
+
}): Promise<WebhookSubscriptionRecord[]>;
|
|
32
|
+
findMatching(required: {
|
|
33
|
+
workspaceId: string;
|
|
34
|
+
topic: WebhookTopic;
|
|
35
|
+
}): Promise<WebhookSubscriptionRecord[]>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* In-memory `WebhookDeliveryRepoPort` adapter (ADR-036 §2 `webhook_deliveries`), mirroring
|
|
39
|
+
* `InMemoryOutbox`'s claim/mark lifecycle. `attempts` is incremented at claim time (same
|
|
40
|
+
* convention as `InMemoryOutbox.claimPending`); a `markFailed` call with `nextStatus: "failed"`
|
|
41
|
+
* re-enters `"pending"` immediately (per the `WebhookDeliveryStatus` doc: "`failed` re-enters
|
|
42
|
+
* `pending` until attempts are exhausted, then `dead`") so the row is reclaimed once
|
|
43
|
+
* `nextAttemptAt` passes — the caller (`./delivery.ts`) owns the backoff/attempts-exhausted
|
|
44
|
+
* decision, this repo only persists the outcome it's told.
|
|
45
|
+
*
|
|
46
|
+
* @overallScore 100
|
|
47
|
+
* Purity/effect: all methods mutate the private `Map`; no I/O beyond memory. No findings.
|
|
48
|
+
*/
|
|
49
|
+
export declare class InMemoryWebhookDeliveryRepo implements WebhookDeliveryRepoPort {
|
|
50
|
+
private rows;
|
|
51
|
+
constructor(_required?: Record<string, never>, { initialRows }?: {
|
|
52
|
+
initialRows?: WebhookDeliveryRecord[];
|
|
53
|
+
});
|
|
54
|
+
enqueue({ record }: {
|
|
55
|
+
record: WebhookDeliveryRecord;
|
|
56
|
+
}, _optional?: {
|
|
57
|
+
envelope?: WebhookEventEnvelope;
|
|
58
|
+
}): Promise<void>;
|
|
59
|
+
/** With `claimLeaseMs`, an expired `delivering` lease (its `nextAttemptAt`) is claimable again
|
|
60
|
+
* and each claim persists nowIso + claimLeaseMs as its lease (port doc: Jini `webhooks/ports.ts`). */
|
|
61
|
+
claimPending(required: {
|
|
62
|
+
batchSize: number;
|
|
63
|
+
nowIso: string;
|
|
64
|
+
}, optional?: {
|
|
65
|
+
claimLeaseMs?: number;
|
|
66
|
+
}): Promise<WebhookDeliveryRecord[]>;
|
|
67
|
+
/** The row, unless a `claimedAttempts` fence names an older claim than the row's current one. */
|
|
68
|
+
private fenced;
|
|
69
|
+
/** Returns a never-attempted `delivering` claim to `pending`, undoing its attempt; fenced. */
|
|
70
|
+
releaseClaim(required: {
|
|
71
|
+
workspaceId: string;
|
|
72
|
+
id: IntegrationId;
|
|
73
|
+
claimedAttempts: number;
|
|
74
|
+
nextAttemptAt: string;
|
|
75
|
+
}, _optional?: Record<string, never>): Promise<void>;
|
|
76
|
+
markDelivered(required: {
|
|
77
|
+
workspaceId: string;
|
|
78
|
+
id: IntegrationId;
|
|
79
|
+
responseStatus: number;
|
|
80
|
+
deliveredAtIso: string;
|
|
81
|
+
}, optional?: {
|
|
82
|
+
claimedAttempts?: number;
|
|
83
|
+
}): Promise<void>;
|
|
84
|
+
markFailed(required: {
|
|
85
|
+
workspaceId: string;
|
|
86
|
+
id: IntegrationId;
|
|
87
|
+
error: string;
|
|
88
|
+
responseStatus: number | null;
|
|
89
|
+
nextStatus: "failed" | "dead";
|
|
90
|
+
nextAttemptAt: string;
|
|
91
|
+
}, optional?: {
|
|
92
|
+
deadAtIso?: string;
|
|
93
|
+
claimedAttempts?: number;
|
|
94
|
+
}): Promise<void>;
|
|
95
|
+
findById(required: {
|
|
96
|
+
workspaceId: string;
|
|
97
|
+
id: IntegrationId;
|
|
98
|
+
}): Promise<WebhookDeliveryRecord | null>;
|
|
99
|
+
listBySubscription(required: {
|
|
100
|
+
workspaceId: string;
|
|
101
|
+
subscriptionId: IntegrationId;
|
|
102
|
+
limit: number;
|
|
103
|
+
}, _optional?: Record<string, never>): Promise<WebhookDeliveryRecord[]>;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Non-port side-channel carrying one delivery's outbound envelope (topic/data) from Stage A
|
|
107
|
+
* (fan-out, `enqueueDelivery`) to Stage B (the delivery worker, `processDueDeliveries`).
|
|
108
|
+
*
|
|
109
|
+
* Why this exists (scope gap, flagged for the Architect): ADR-036 §2's `webhook_deliveries` DDL
|
|
110
|
+
* sketch carries only retry/state columns (`subscription_id`, `event_id`, `topic`, `status`,
|
|
111
|
+
* `attempts`, …) — no payload column, and `WebhookDeliveryRecord` (types.ts) matches that
|
|
112
|
+
* sketch exactly. A real delivery worker running in a later process/tick still needs the
|
|
113
|
+
* original event's `data` to build the `WebhookEventEnvelope` it signs and POSTs. The ADR
|
|
114
|
+
* doesn't say where that re-hydration comes from (most likely: re-reading the core event
|
|
115
|
+
* outbox row by `event_id`, since `OutboxRecord.event` already retains the full `DomainEvent`
|
|
116
|
+
* payload — but core/events exposes no by-id lookup port today, and wiring one is out of this
|
|
117
|
+
* task's scope). This in-memory store is a stand-in seam so `enqueueDelivery` and
|
|
118
|
+
* `processDueDeliveries` are independently testable now; swap it for the real re-hydration path
|
|
119
|
+
* (or fold `data` into `webhook_deliveries` directly) once that's decided upstream.
|
|
120
|
+
*/
|
|
121
|
+
/**
|
|
122
|
+
* In-memory `DeliveryEnvelopeStorePort`. See the doc above for why this seam exists.
|
|
123
|
+
*
|
|
124
|
+
* @overallScore 100
|
|
125
|
+
*/
|
|
126
|
+
export declare class InMemoryDeliveryEnvelopeStore implements DeliveryEnvelopeStorePort {
|
|
127
|
+
private envelopes;
|
|
128
|
+
save(input: {
|
|
129
|
+
deliveryId: IntegrationId;
|
|
130
|
+
envelope: WebhookEventEnvelope;
|
|
131
|
+
}): Promise<void>;
|
|
132
|
+
find(input: {
|
|
133
|
+
deliveryId: IntegrationId;
|
|
134
|
+
}): Promise<WebhookEventEnvelope | null>;
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=repo.memory.d.ts.map
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file In-memory adapters for the `integrations` repo ports (ADR-036) + a small local
|
|
3
|
+
* envelope side-channel the delivery worker needs (see {@link DeliveryEnvelopeStorePort} below).
|
|
4
|
+
*
|
|
5
|
+
* Purpose:
|
|
6
|
+
* Zero-infrastructure test/dev doubles for `WebhookSubscriptionRepoPort` and
|
|
7
|
+
* `WebhookDeliveryRepoPort`, mirroring the core event bus's in-memory `InMemoryOutbox` shape
|
|
8
|
+
* (claim-then-mark lifecycle, `attempts` incremented at claim time, "failed" re-enters "pending"
|
|
9
|
+
* per {@link import("../types.js").WebhookDeliveryStatus}'s own doc comment).
|
|
10
|
+
*
|
|
11
|
+
* How it relates to the project:
|
|
12
|
+
* - Implements the ports declared in `../ports.ts` — read those first; this file matches them
|
|
13
|
+
* precisely rather than redesigning the contract.
|
|
14
|
+
* - Used directly by `./__tests__/*.test.ts` and available for local dev wiring the same way
|
|
15
|
+
* other features' in-memory repos are.
|
|
16
|
+
*
|
|
17
|
+
* Architectural role:
|
|
18
|
+
* Local adapter implementations only. The SQLite adapters (the other half of each ADR-006
|
|
19
|
+
* rule-of-two) are out of scope for this task.
|
|
20
|
+
*/
|
|
21
|
+
/** Composite `(workspaceId, id)` key, mirroring the tables' composite FK isolation (ADR-007). */
|
|
22
|
+
function rowKey({ workspaceId, id }, _optional = {}) {
|
|
23
|
+
return `${workspaceId}:${id}`;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Does a subscription's topic set match a delivered event's topic? Trailing `.*` matches every
|
|
27
|
+
* action for an entity; a bare `*` is the owner-scoped "all topics" wildcard (ADR-036 §4,
|
|
28
|
+
* `WebhookTopic` doc comment). Empty topic sets never match (fail-closed, per `types.ts`).
|
|
29
|
+
*
|
|
30
|
+
* @complexity O(subscribedTopics) string comparisons; subscriptions carry a handful of topics.
|
|
31
|
+
*/
|
|
32
|
+
function topicMatches(subscribedTopics, topic) {
|
|
33
|
+
return subscribedTopics.some((pattern) => {
|
|
34
|
+
if (pattern === "*")
|
|
35
|
+
return true;
|
|
36
|
+
if (pattern === topic)
|
|
37
|
+
return true;
|
|
38
|
+
if (pattern.endsWith(".*")) {
|
|
39
|
+
const entityPrefix = pattern.slice(0, -1); // keep the trailing "."
|
|
40
|
+
return topic.startsWith(entityPrefix);
|
|
41
|
+
}
|
|
42
|
+
return false;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* In-memory `WebhookSubscriptionRepoPort` adapter (ADR-036 §2 `webhook_subscriptions`).
|
|
47
|
+
*
|
|
48
|
+
* @overallScore 100
|
|
49
|
+
* Purity/effect: all methods mutate the private `Map`; no I/O beyond memory. No findings.
|
|
50
|
+
*/
|
|
51
|
+
export class InMemoryWebhookSubscriptionRepo {
|
|
52
|
+
rows = new Map();
|
|
53
|
+
assertVersionedWrite;
|
|
54
|
+
constructor({ assertVersionedWrite }, { initialRows = [] } = {}) {
|
|
55
|
+
this.assertVersionedWrite = assertVersionedWrite;
|
|
56
|
+
this.rows = new Map(initialRows.map(row => [rowKey({ workspaceId: row.workspaceId, id: row.id }), row]));
|
|
57
|
+
}
|
|
58
|
+
async insert(record) {
|
|
59
|
+
const key = rowKey({ workspaceId: record.workspaceId, id: record.id });
|
|
60
|
+
if (this.rows.has(key)) {
|
|
61
|
+
throw new Error(`webhook subscription '${record.id}' already exists`);
|
|
62
|
+
}
|
|
63
|
+
this.rows.set(key, record);
|
|
64
|
+
}
|
|
65
|
+
async save(record, optional = {}) {
|
|
66
|
+
const current = this.rows.get(rowKey({ workspaceId: record.workspaceId, id: record.id }));
|
|
67
|
+
if (optional.expectedVersion !== undefined && current?.version !== optional.expectedVersion) {
|
|
68
|
+
await this.assertVersionedWrite({ changedRows: 0, recordKind: "webhook subscription", recordId: record.id,
|
|
69
|
+
expectedVersion: optional.expectedVersion, readCurrentVersion: async () => current?.version ?? null });
|
|
70
|
+
}
|
|
71
|
+
// The successful compare and write are synchronous for concurrent memory callers.
|
|
72
|
+
this.rows.set(rowKey({ workspaceId: record.workspaceId, id: record.id }), record);
|
|
73
|
+
}
|
|
74
|
+
async findById(required) {
|
|
75
|
+
return this.rows.get(rowKey({ workspaceId: required.workspaceId, id: required.id })) ?? null;
|
|
76
|
+
}
|
|
77
|
+
async listByWorkspace(required) {
|
|
78
|
+
return [...this.rows.values()].filter((row) => row.workspaceId === required.workspaceId);
|
|
79
|
+
}
|
|
80
|
+
async findMatching(required) {
|
|
81
|
+
return [...this.rows.values()].filter((row) => row.workspaceId === required.workspaceId &&
|
|
82
|
+
row.status === "active" &&
|
|
83
|
+
topicMatches(row.topics, required.topic));
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* In-memory `WebhookDeliveryRepoPort` adapter (ADR-036 §2 `webhook_deliveries`), mirroring
|
|
88
|
+
* `InMemoryOutbox`'s claim/mark lifecycle. `attempts` is incremented at claim time (same
|
|
89
|
+
* convention as `InMemoryOutbox.claimPending`); a `markFailed` call with `nextStatus: "failed"`
|
|
90
|
+
* re-enters `"pending"` immediately (per the `WebhookDeliveryStatus` doc: "`failed` re-enters
|
|
91
|
+
* `pending` until attempts are exhausted, then `dead`") so the row is reclaimed once
|
|
92
|
+
* `nextAttemptAt` passes — the caller (`./delivery.ts`) owns the backoff/attempts-exhausted
|
|
93
|
+
* decision, this repo only persists the outcome it's told.
|
|
94
|
+
*
|
|
95
|
+
* @overallScore 100
|
|
96
|
+
* Purity/effect: all methods mutate the private `Map`; no I/O beyond memory. No findings.
|
|
97
|
+
*/
|
|
98
|
+
export class InMemoryWebhookDeliveryRepo {
|
|
99
|
+
rows = new Map();
|
|
100
|
+
constructor(_required = {}, { initialRows = [] } = {}) {
|
|
101
|
+
this.rows = new Map(initialRows.map(row => [rowKey({ workspaceId: row.workspaceId, id: row.id }), row]));
|
|
102
|
+
}
|
|
103
|
+
async enqueue({ record }, _optional = {}) {
|
|
104
|
+
if ([...this.rows.values()].some((row) => row.workspaceId === record.workspaceId && row.subscriptionId === record.subscriptionId && row.eventId === record.eventId))
|
|
105
|
+
return;
|
|
106
|
+
this.rows.set(rowKey({ workspaceId: record.workspaceId, id: record.id }), record);
|
|
107
|
+
}
|
|
108
|
+
/** With `claimLeaseMs`, an expired `delivering` lease (its `nextAttemptAt`) is claimable again
|
|
109
|
+
* and each claim persists nowIso + claimLeaseMs as its lease (port doc: Jini `webhooks/ports.ts`). */
|
|
110
|
+
async claimPending(required, optional = {}) {
|
|
111
|
+
const { claimLeaseMs } = optional;
|
|
112
|
+
const claimable = (row) => (row.status === "pending" || (claimLeaseMs !== undefined && row.status === "delivering")) && row.nextAttemptAt <= required.nowIso;
|
|
113
|
+
const due = [...this.rows.values()]
|
|
114
|
+
.filter(claimable)
|
|
115
|
+
.sort((a, b) => a.nextAttemptAt.localeCompare(b.nextAttemptAt))
|
|
116
|
+
.slice(0, required.batchSize);
|
|
117
|
+
for (const row of due) {
|
|
118
|
+
row.status = "delivering";
|
|
119
|
+
row.attempts += 1;
|
|
120
|
+
if (claimLeaseMs !== undefined)
|
|
121
|
+
row.nextAttemptAt = new Date(Date.parse(required.nowIso) + claimLeaseMs).toISOString();
|
|
122
|
+
}
|
|
123
|
+
// Return copies so a caller can't mutate claimed state without going through markDelivered/
|
|
124
|
+
// markFailed — matches the SQLite adapter's row-per-claim semantics.
|
|
125
|
+
return due.map((row) => ({ ...row }));
|
|
126
|
+
}
|
|
127
|
+
/** The row, unless a `claimedAttempts` fence names an older claim than the row's current one. */
|
|
128
|
+
fenced({ required, claimedAttempts }, _optional = {}) {
|
|
129
|
+
const row = this.rows.get(rowKey({ workspaceId: required.workspaceId, id: required.id }));
|
|
130
|
+
if (!row || (claimedAttempts !== undefined && row.attempts !== claimedAttempts))
|
|
131
|
+
return undefined;
|
|
132
|
+
return row;
|
|
133
|
+
}
|
|
134
|
+
/** Returns a never-attempted `delivering` claim to `pending`, undoing its attempt; fenced. */
|
|
135
|
+
async releaseClaim(required, _optional = {}) {
|
|
136
|
+
const row = this.fenced({ required, claimedAttempts: required.claimedAttempts });
|
|
137
|
+
if (!row || row.status !== "delivering")
|
|
138
|
+
return;
|
|
139
|
+
row.status = "pending";
|
|
140
|
+
row.attempts -= 1;
|
|
141
|
+
row.nextAttemptAt = required.nextAttemptAt;
|
|
142
|
+
}
|
|
143
|
+
async markDelivered(required, optional = {}) {
|
|
144
|
+
const row = this.fenced({ required, claimedAttempts: optional.claimedAttempts });
|
|
145
|
+
if (!row)
|
|
146
|
+
return;
|
|
147
|
+
row.status = "delivered";
|
|
148
|
+
row.lastResponseStatus = required.responseStatus;
|
|
149
|
+
row.deliveredAt = required.deliveredAtIso;
|
|
150
|
+
row.lastError = null;
|
|
151
|
+
}
|
|
152
|
+
async markFailed(required, optional = {}) {
|
|
153
|
+
const row = this.fenced({ required, claimedAttempts: optional.claimedAttempts });
|
|
154
|
+
if (!row)
|
|
155
|
+
return;
|
|
156
|
+
row.lastError = required.error;
|
|
157
|
+
row.lastResponseStatus = required.responseStatus;
|
|
158
|
+
row.nextAttemptAt = required.nextAttemptAt;
|
|
159
|
+
if (required.nextStatus === "dead") {
|
|
160
|
+
row.status = "dead";
|
|
161
|
+
row.deadAt = optional.deadAtIso ?? row.deadAt;
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
// "failed" re-enters "pending" immediately (WebhookDeliveryStatus doc comment) — the row
|
|
165
|
+
// becomes reclaimable once nextAttemptAt passes.
|
|
166
|
+
row.status = "pending";
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
async findById(required) {
|
|
170
|
+
return this.rows.get(rowKey({ workspaceId: required.workspaceId, id: required.id })) ?? null;
|
|
171
|
+
}
|
|
172
|
+
async listBySubscription(required, _optional = {}) {
|
|
173
|
+
return [...this.rows.values()]
|
|
174
|
+
.filter((row) => row.workspaceId === required.workspaceId && row.subscriptionId === required.subscriptionId)
|
|
175
|
+
.sort((a, b) => {
|
|
176
|
+
if (a.createdAt !== b.createdAt)
|
|
177
|
+
return a.createdAt < b.createdAt ? 1 : -1;
|
|
178
|
+
// Rows are keyed by (workspaceId, id) and filtered to one workspace, so two compared rows
|
|
179
|
+
// never share an id: the tie-break is strictly descending and needs no equal-id arm.
|
|
180
|
+
return a.id < b.id ? 1 : -1;
|
|
181
|
+
})
|
|
182
|
+
.slice(0, required.limit);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Non-port side-channel carrying one delivery's outbound envelope (topic/data) from Stage A
|
|
187
|
+
* (fan-out, `enqueueDelivery`) to Stage B (the delivery worker, `processDueDeliveries`).
|
|
188
|
+
*
|
|
189
|
+
* Why this exists (scope gap, flagged for the Architect): ADR-036 §2's `webhook_deliveries` DDL
|
|
190
|
+
* sketch carries only retry/state columns (`subscription_id`, `event_id`, `topic`, `status`,
|
|
191
|
+
* `attempts`, …) — no payload column, and `WebhookDeliveryRecord` (types.ts) matches that
|
|
192
|
+
* sketch exactly. A real delivery worker running in a later process/tick still needs the
|
|
193
|
+
* original event's `data` to build the `WebhookEventEnvelope` it signs and POSTs. The ADR
|
|
194
|
+
* doesn't say where that re-hydration comes from (most likely: re-reading the core event
|
|
195
|
+
* outbox row by `event_id`, since `OutboxRecord.event` already retains the full `DomainEvent`
|
|
196
|
+
* payload — but core/events exposes no by-id lookup port today, and wiring one is out of this
|
|
197
|
+
* task's scope). This in-memory store is a stand-in seam so `enqueueDelivery` and
|
|
198
|
+
* `processDueDeliveries` are independently testable now; swap it for the real re-hydration path
|
|
199
|
+
* (or fold `data` into `webhook_deliveries` directly) once that's decided upstream.
|
|
200
|
+
*/
|
|
201
|
+
/**
|
|
202
|
+
* In-memory `DeliveryEnvelopeStorePort`. See the doc above for why this seam exists.
|
|
203
|
+
*
|
|
204
|
+
* @overallScore 100
|
|
205
|
+
*/
|
|
206
|
+
export class InMemoryDeliveryEnvelopeStore {
|
|
207
|
+
envelopes = new Map();
|
|
208
|
+
async save(input) {
|
|
209
|
+
this.envelopes.set(input.deliveryId, input.envelope);
|
|
210
|
+
}
|
|
211
|
+
async find(input) {
|
|
212
|
+
return this.envelopes.get(input.deliveryId) ?? null;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
//# sourceMappingURL=repo.memory.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type ts from "typescript";
|
|
2
|
+
export interface SealViolation {
|
|
3
|
+
/** Repo-root-relative path (real-scan mode) or the caller-supplied display path (unit-test mode). */
|
|
4
|
+
file: string;
|
|
5
|
+
/** 1-based line number of the call expression's start. */
|
|
6
|
+
line: number;
|
|
7
|
+
/** The call expression's source text, whitespace-collapsed to one line for reporting. */
|
|
8
|
+
text: string;
|
|
9
|
+
reason: "missing-aad" | "aad-literally-undefined" | "unresolved-argument-shape";
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Core per-file scanner, unit-testable directly against synthetic source text (no filesystem, no
|
|
13
|
+
* `ts.Program`). Finds every `<expr>.seal(...)` call and checks its argument shape.
|
|
14
|
+
*
|
|
15
|
+
* @complexity O(n) single AST walk, n = node count in the parsed file.
|
|
16
|
+
*/
|
|
17
|
+
export declare function findSealCallsInSource({ sourceText, displayPath, ast, isExempt }: {
|
|
18
|
+
sourceText: string;
|
|
19
|
+
displayPath: string;
|
|
20
|
+
ast: typeof ts;
|
|
21
|
+
isExempt: (required: {
|
|
22
|
+
displayPath: string;
|
|
23
|
+
text: string;
|
|
24
|
+
}, optional?: Record<string, never>) => boolean;
|
|
25
|
+
}, _optional?: Record<string, never>): SealViolation[];
|
|
26
|
+
//# sourceMappingURL=seal-aad-invariant.d.ts.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core per-file scanner, unit-testable directly against synthetic source text (no filesystem, no
|
|
3
|
+
* `ts.Program`). Finds every `<expr>.seal(...)` call and checks its argument shape.
|
|
4
|
+
*
|
|
5
|
+
* @complexity O(n) single AST walk, n = node count in the parsed file.
|
|
6
|
+
*/
|
|
7
|
+
export function findSealCallsInSource({ sourceText, displayPath, ast, isExempt }, _optional = {}) {
|
|
8
|
+
const scriptKind = displayPath.endsWith(".tsx") ? ast.ScriptKind.TSX : ast.ScriptKind.TS;
|
|
9
|
+
const source = ast.createSourceFile(displayPath, sourceText, ast.ScriptTarget.Latest, true, scriptKind);
|
|
10
|
+
const violations = [];
|
|
11
|
+
function lineOf({ pos }, _optional = {}) {
|
|
12
|
+
return source.getLineAndCharacterOfPosition(pos).line + 1;
|
|
13
|
+
}
|
|
14
|
+
function visit(node) {
|
|
15
|
+
if (ast.isCallExpression(node) && ast.isPropertyAccessExpression(node.expression) && node.expression.name.text === "seal") {
|
|
16
|
+
const violation = checkSealCallArguments({ call: node, source, displayPath, lineOf, ast, isExempt });
|
|
17
|
+
if (violation)
|
|
18
|
+
violations.push(violation);
|
|
19
|
+
}
|
|
20
|
+
ast.forEachChild(node, visit);
|
|
21
|
+
}
|
|
22
|
+
visit(source);
|
|
23
|
+
return violations;
|
|
24
|
+
}
|
|
25
|
+
function buildSealViolation({ reason, displayPath, line, text }, _optional = {}) {
|
|
26
|
+
return { file: displayPath, line, text, reason };
|
|
27
|
+
}
|
|
28
|
+
/** Finds the `aad` property among a `.seal()` call's object-literal properties. Returns
|
|
29
|
+
* `"unresolved"` when a spread makes it impossible to statically know whether `aad` is
|
|
30
|
+
* included (fail-closed — see file header), or `null` when no `aad` property is present. */
|
|
31
|
+
function findAadProperty({ properties, ast }) {
|
|
32
|
+
for (const prop of properties) {
|
|
33
|
+
if (ast.isSpreadAssignment(prop))
|
|
34
|
+
return "unresolved";
|
|
35
|
+
if (prop.name && ast.isIdentifier(prop.name) && prop.name.text === "aad")
|
|
36
|
+
return prop;
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
function isLiterallyUndefined({ prop, ast }) {
|
|
41
|
+
return (ast.isPropertyAssignment(prop) && ast.isIdentifier(prop.initializer) && prop.initializer.text === "undefined");
|
|
42
|
+
}
|
|
43
|
+
function checkSealCallArguments({ call, source, displayPath, lineOf, ast, isExempt, }, _optional = {}) {
|
|
44
|
+
const line = lineOf({ pos: call.getStart(source) });
|
|
45
|
+
const text = call.getText(source).replace(/\s+/g, " ").trim();
|
|
46
|
+
if (isExempt({ displayPath, text }))
|
|
47
|
+
return null;
|
|
48
|
+
const first = call.arguments[0];
|
|
49
|
+
if (call.arguments.length !== 1 || first === undefined || !ast.isObjectLiteralExpression(first)) {
|
|
50
|
+
return buildSealViolation({ reason: "unresolved-argument-shape", displayPath, line, text });
|
|
51
|
+
}
|
|
52
|
+
const aadProp = findAadProperty({ properties: first.properties, ast });
|
|
53
|
+
if (aadProp === "unresolved")
|
|
54
|
+
return buildSealViolation({ reason: "unresolved-argument-shape", displayPath, line, text });
|
|
55
|
+
if (aadProp === null)
|
|
56
|
+
return buildSealViolation({ reason: "missing-aad", displayPath, line, text });
|
|
57
|
+
if (isLiterallyUndefined({ prop: aadProp, ast }))
|
|
58
|
+
return buildSealViolation({ reason: "aad-literally-undefined", displayPath, line, text });
|
|
59
|
+
return null; // `aad` present with a real value, or shorthand `{ aad }` — compliant.
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=seal-aad-invariant.js.map
|