@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,42 @@
|
|
|
1
|
+
import type ts from "typescript";
|
|
2
|
+
import { findSealCallsInSource, type SealViolation } from "./seal-aad-invariant.js";
|
|
3
|
+
/** Real-repo scan: every non-test `.ts`/`.tsx` file under `scanRoot`, reported paths relative to
|
|
4
|
+
* the repo root. Defaults to `the host website app/src` — the only surface `SecretSealerPort.seal()` is
|
|
5
|
+
* called from today. */
|
|
6
|
+
export declare function findSealCallsWithoutAad({ repoRoot, scanRoot, fs, ast, isExempt }: {
|
|
7
|
+
repoRoot: string;
|
|
8
|
+
scanRoot: string;
|
|
9
|
+
fs: {
|
|
10
|
+
readdirSync(dir: string, options: {
|
|
11
|
+
withFileTypes: true;
|
|
12
|
+
}): readonly {
|
|
13
|
+
name: string;
|
|
14
|
+
isDirectory(): boolean;
|
|
15
|
+
}[];
|
|
16
|
+
readFileSync(file: string, encoding: "utf8"): string;
|
|
17
|
+
};
|
|
18
|
+
ast: typeof ts;
|
|
19
|
+
isExempt: Parameters<typeof findSealCallsInSource>[0]["isExempt"];
|
|
20
|
+
}, _optional?: Record<string, never>): SealViolation[];
|
|
21
|
+
/** The host's exact exemption: one path AND one whitespace-collapsed call text, never the text alone. */
|
|
22
|
+
export declare function createNonSecretSealCallPredicate({ exemptions }: {
|
|
23
|
+
exemptions: Readonly<Record<string, string>>;
|
|
24
|
+
}, _optional?: {}): ({ displayPath, text }: {
|
|
25
|
+
displayPath: string;
|
|
26
|
+
text: string;
|
|
27
|
+
}) => boolean;
|
|
28
|
+
export declare function runSealAadCheck({ repoRoot, scanRoot, fs, ast, exemptions, stdout, stderr, copy }: {
|
|
29
|
+
repoRoot: string;
|
|
30
|
+
scanRoot: string;
|
|
31
|
+
fs: Parameters<typeof findSealCallsWithoutAad>[0]["fs"];
|
|
32
|
+
ast: typeof ts;
|
|
33
|
+
exemptions: Readonly<Record<string, string>>;
|
|
34
|
+
stdout: (text: string) => void;
|
|
35
|
+
stderr: (text: string) => void;
|
|
36
|
+
copy: {
|
|
37
|
+
clean: string;
|
|
38
|
+
findings: (count: number) => string;
|
|
39
|
+
guidance: string;
|
|
40
|
+
};
|
|
41
|
+
}, _optional?: {}): 0 | 1;
|
|
42
|
+
//# sourceMappingURL=seal-aad-invariant.node.d.ts.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { findSealCallsInSource } from "./seal-aad-invariant.js";
|
|
3
|
+
function isTestFile({ file }, _optional = {}) {
|
|
4
|
+
return /__tests__|\.test\.|\.spec\./.test(file);
|
|
5
|
+
}
|
|
6
|
+
function collectTsFiles({ dir, fs }, _optional = {}) {
|
|
7
|
+
const out = [];
|
|
8
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
9
|
+
if (entry.name === "node_modules" || entry.name === "dist")
|
|
10
|
+
continue;
|
|
11
|
+
const full = path.join(dir, entry.name);
|
|
12
|
+
if (entry.isDirectory()) {
|
|
13
|
+
out.push(...collectTsFiles({ dir: full, fs }));
|
|
14
|
+
}
|
|
15
|
+
else if (/\.tsx?$/.test(entry.name) && !isTestFile({ file: full })) {
|
|
16
|
+
out.push(full);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
// Non-source entries are outside the seal invariant.
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return out;
|
|
23
|
+
}
|
|
24
|
+
/** Real-repo scan: every non-test `.ts`/`.tsx` file under `scanRoot`, reported paths relative to
|
|
25
|
+
* the repo root. Defaults to `the host website app/src` — the only surface `SecretSealerPort.seal()` is
|
|
26
|
+
* called from today. */
|
|
27
|
+
export function findSealCallsWithoutAad({ repoRoot, scanRoot, fs, ast, isExempt }, _optional = {}) {
|
|
28
|
+
const violations = [];
|
|
29
|
+
for (const file of collectTsFiles({ dir: scanRoot, fs })) {
|
|
30
|
+
const sourceText = fs.readFileSync(file, "utf8");
|
|
31
|
+
violations.push(...findSealCallsInSource({ sourceText, displayPath: path.relative(repoRoot, file), ast, isExempt }));
|
|
32
|
+
}
|
|
33
|
+
return violations;
|
|
34
|
+
}
|
|
35
|
+
/** The host's exact exemption: one path AND one whitespace-collapsed call text, never the text alone. */
|
|
36
|
+
export function createNonSecretSealCallPredicate({ exemptions }, _optional = {}) {
|
|
37
|
+
return ({ displayPath, text }) => exemptions[displayPath] === text;
|
|
38
|
+
}
|
|
39
|
+
export function runSealAadCheck({ repoRoot, scanRoot, fs, ast, exemptions, stdout, stderr, copy }, _optional = {}) {
|
|
40
|
+
const violations = findSealCallsWithoutAad({ repoRoot, scanRoot, fs, ast, isExempt: createNonSecretSealCallPredicate({ exemptions }) });
|
|
41
|
+
if (violations.length === 0) {
|
|
42
|
+
stdout(copy.clean);
|
|
43
|
+
return 0;
|
|
44
|
+
}
|
|
45
|
+
stderr(copy.findings(violations.length));
|
|
46
|
+
for (const v of violations) {
|
|
47
|
+
stderr(` - ${v.file}:${v.line} [${v.reason}] ${v.text}`);
|
|
48
|
+
}
|
|
49
|
+
stderr(copy.guidance);
|
|
50
|
+
return 1;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=seal-aad-invariant.node.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** Bind the host signature header's t/v1 vocabulary and host clock to canonical HMAC signing/verification.
|
|
2
|
+
* The worker must send the exact signed bytes. Fixed secret maps are dev/test fixtures;
|
|
3
|
+
* production signing derives bytes through KeyringPort instead of persisting signing secrets.
|
|
4
|
+
*/
|
|
5
|
+
import { type SignPayloadInput as JiniSignPayloadInput, type VerifySignatureInput as JiniVerifySignatureInput, type WebhookSigner } from "../index.js";
|
|
6
|
+
export type { WebhookSigner } from "../index.js";
|
|
7
|
+
export { DEFAULT_SIGNATURE_TOLERANCE_SECONDS } from "../index.js";
|
|
8
|
+
export declare const SIGNATURE_VOCABULARY: {
|
|
9
|
+
readonly timestampField: "t";
|
|
10
|
+
readonly signatureField: "v1";
|
|
11
|
+
};
|
|
12
|
+
export interface SignPayloadInput extends Omit<JiniSignPayloadInput, "vocabulary" | "timestampSeconds"> {
|
|
13
|
+
timestampSeconds?: number;
|
|
14
|
+
}
|
|
15
|
+
export type VerifySignatureInput = Omit<JiniVerifySignatureInput, "vocabulary" | "nowSeconds">;
|
|
16
|
+
/** Supply the t/v1 protocol and wall-clock default for existing host callers.
|
|
17
|
+
* @complexity O(raw body bytes), delegated to Jini HMAC-SHA256.
|
|
18
|
+
*/
|
|
19
|
+
export declare function signPayload(input: SignPayloadInput, _optional?: Record<string, never>): string;
|
|
20
|
+
/** Keep the receiver's host vocabulary and current replay-window clock.
|
|
21
|
+
* @complexity O(raw body bytes + signature entries).
|
|
22
|
+
*/
|
|
23
|
+
export declare function verifySignature(input: VerifySignatureInput, _optional?: Record<string, never>): boolean;
|
|
24
|
+
/** Fixed-map host signer supplies protocol policy; production uses a keyring-backed signer. */
|
|
25
|
+
export declare function createFixedSecretSigner({ secrets }: {
|
|
26
|
+
secrets: ReadonlyMap<string, Buffer>;
|
|
27
|
+
}, _optional?: Record<string, never>): WebhookSigner;
|
|
28
|
+
//# sourceMappingURL=signing.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Signing, replay-window and rotation rationale: ../signing.ts.
|
|
2
|
+
/** Bind the host signature header's t/v1 vocabulary and host clock to canonical HMAC signing/verification.
|
|
3
|
+
* The worker must send the exact signed bytes. Fixed secret maps are dev/test fixtures;
|
|
4
|
+
* production signing derives bytes through KeyringPort instead of persisting signing secrets.
|
|
5
|
+
*/
|
|
6
|
+
import { signPayload as signWebhookPayload, verifySignature as verifyWebhookSignature, createFixedSecretSigner as createWebhookFixedSigner, } from "../index.js";
|
|
7
|
+
export { DEFAULT_SIGNATURE_TOLERANCE_SECONDS } from "../index.js";
|
|
8
|
+
export const SIGNATURE_VOCABULARY = { timestampField: "t", signatureField: "v1" };
|
|
9
|
+
/** Supply the t/v1 protocol and wall-clock default for existing host callers.
|
|
10
|
+
* @complexity O(raw body bytes), delegated to Jini HMAC-SHA256.
|
|
11
|
+
*/
|
|
12
|
+
export function signPayload(input, _optional = {}) {
|
|
13
|
+
return signWebhookPayload({ ...input, vocabulary: SIGNATURE_VOCABULARY,
|
|
14
|
+
timestampSeconds: input.timestampSeconds ?? Math.floor(Date.now() / 1000),
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
/** Keep the receiver's host vocabulary and current replay-window clock.
|
|
18
|
+
* @complexity O(raw body bytes + signature entries).
|
|
19
|
+
*/
|
|
20
|
+
export function verifySignature(input, _optional = {}) {
|
|
21
|
+
return verifyWebhookSignature({ ...input, vocabulary: SIGNATURE_VOCABULARY, nowSeconds: Math.floor(Date.now() / 1000) });
|
|
22
|
+
}
|
|
23
|
+
/** Fixed-map host signer supplies protocol policy; production uses a keyring-backed signer. */
|
|
24
|
+
export function createFixedSecretSigner({ secrets }, _optional = {}) {
|
|
25
|
+
return createWebhookFixedSigner({ secrets, vocabulary: SIGNATURE_VOCABULARY });
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=signing.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type WebhookSigner } from "../index.js";
|
|
2
|
+
import type { KeyringPort } from "../../secrets/ports.js";
|
|
3
|
+
/** Supply the host's signature field vocabulary without storing or caching signing material.
|
|
4
|
+
*
|
|
5
|
+
* Contract rationale for the Jini implementation and this host boundary:
|
|
6
|
+
*
|
|
7
|
+
* @file `WebhookSigner` backed by a real `KeyringPort` (ADR-PIPE-015 Phase 1, GAP-02).
|
|
8
|
+
*
|
|
9
|
+
* Purpose:
|
|
10
|
+
* Replaces `createFixedSecretSigner`'s dev-only fixed-map stand-in with the production signing
|
|
11
|
+
* path ADR-036 §5 specifies: `HKDF(siteKey, info) via KeyringPort.deriveSigningSecret`. No secret
|
|
12
|
+
* is ever cached or persisted here — every delivery attempt re-derives it from the keyring.
|
|
13
|
+
*
|
|
14
|
+
* How it relates to the project:
|
|
15
|
+
* - `signing.ts`'s `signPayload`/`verifySignature` are unchanged — this only supplies the secret
|
|
16
|
+
* bytes those functions already expect.
|
|
17
|
+
* - `./delivery.ts`'s `processDueDeliveries` depends on the `WebhookSigner` interface, not on
|
|
18
|
+
* this adapter directly, so swapping it in is a pure DI change (no call-site edits needed).
|
|
19
|
+
*
|
|
20
|
+
* Constructs a `WebhookSigner` that derives each subscription's signing secret from `keyring`
|
|
21
|
+
* at sign time rather than reading it from an in-memory map.
|
|
22
|
+
*
|
|
23
|
+
* @complexity O(rawBody length) per call — one HKDF derivation plus one HMAC pass.
|
|
24
|
+
* @overallScore 100
|
|
25
|
+
*/
|
|
26
|
+
export declare function createKeyringBackedSigner({ keyring }: {
|
|
27
|
+
keyring: KeyringPort;
|
|
28
|
+
}, _optional?: Record<string, never>): WebhookSigner;
|
|
29
|
+
//# sourceMappingURL=signing.keyring.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { createKeyringBackedSigner as createWebhookSigner } from "../index.js";
|
|
2
|
+
import { SIGNATURE_VOCABULARY } from "./signing.js";
|
|
3
|
+
// Per-attempt keyring derivation rationale: ../signing.keyring.ts (ADR-036 §5).
|
|
4
|
+
/** Supply the host's signature field vocabulary without storing or caching signing material.
|
|
5
|
+
*
|
|
6
|
+
* Contract rationale for the Jini implementation and this host boundary:
|
|
7
|
+
*
|
|
8
|
+
* @file `WebhookSigner` backed by a real `KeyringPort` (ADR-PIPE-015 Phase 1, GAP-02).
|
|
9
|
+
*
|
|
10
|
+
* Purpose:
|
|
11
|
+
* Replaces `createFixedSecretSigner`'s dev-only fixed-map stand-in with the production signing
|
|
12
|
+
* path ADR-036 §5 specifies: `HKDF(siteKey, info) via KeyringPort.deriveSigningSecret`. No secret
|
|
13
|
+
* is ever cached or persisted here — every delivery attempt re-derives it from the keyring.
|
|
14
|
+
*
|
|
15
|
+
* How it relates to the project:
|
|
16
|
+
* - `signing.ts`'s `signPayload`/`verifySignature` are unchanged — this only supplies the secret
|
|
17
|
+
* bytes those functions already expect.
|
|
18
|
+
* - `./delivery.ts`'s `processDueDeliveries` depends on the `WebhookSigner` interface, not on
|
|
19
|
+
* this adapter directly, so swapping it in is a pure DI change (no call-site edits needed).
|
|
20
|
+
*
|
|
21
|
+
* Constructs a `WebhookSigner` that derives each subscription's signing secret from `keyring`
|
|
22
|
+
* at sign time rather than reading it from an in-memory map.
|
|
23
|
+
*
|
|
24
|
+
* @complexity O(rawBody length) per call — one HKDF derivation plus one HMAC pass.
|
|
25
|
+
* @overallScore 100
|
|
26
|
+
*/
|
|
27
|
+
export function createKeyringBackedSigner({ keyring }, _optional = {}) {
|
|
28
|
+
return createWebhookSigner({ keyring, vocabulary: SIGNATURE_VOCABULARY });
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=signing.keyring.js.map
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/** Host callback and actor-attribution adapter; Jini owns subscription validation and lifecycle.
|
|
2
|
+
*
|
|
3
|
+
* Contract rationale for the Jini implementation and this host boundary:
|
|
4
|
+
*
|
|
5
|
+
* @file Webhook subscription CRUD (ADR-036 §2/§6) — the write-service behind the admin/AI
|
|
6
|
+
* gateway handlers.
|
|
7
|
+
*
|
|
8
|
+
* Purpose:
|
|
9
|
+
* `createSubscription` / `updateSubscription` / `pauseSubscription` / `deleteSubscription`.
|
|
10
|
+
* Mirrors `src/features/post/post.ts`'s `updatePost` shape (required `{ deps, input }` +
|
|
11
|
+
* optional second param), since these functions play the same "feature write-service" role.
|
|
12
|
+
*
|
|
13
|
+
* How it relates to the project:
|
|
14
|
+
* - Every mutation here is the thing the ADR-036 §6 gateway/`authorize()` chokepoint calls —
|
|
15
|
+
* this file itself does no authorization; that lives in the (out-of-scope) route handler.
|
|
16
|
+
* - `target_url` validation reuses `EgressPolicy`'s intent (only `https://`, only allowed
|
|
17
|
+
* hosts) but does NOT import `src/origin` directly — that module may not exist yet or be
|
|
18
|
+
* mid-build by another agent. Callers inject `isAllowedTarget`; production wiring plugs in
|
|
19
|
+
* the real SSRF/egress check once that module lands (see `WebhookSubscriptionDeps` doc).
|
|
20
|
+
* - `deleteSubscription` never row-deletes (ADR-036 §2 / `WebhookSubscriptionRecord.disabledAt`
|
|
21
|
+
* doc: "Set (never row-deleted) when disabled, for audit durability") — it soft-disables via
|
|
22
|
+
* `repo.save`, matching that `WebhookSubscriptionRepoPort` has no `delete` method at all.
|
|
23
|
+
*
|
|
24
|
+
* Architectural role:
|
|
25
|
+
* Jini owns the feature-level business rules. Repositories stay behind `WebhookSubscriptionRepoPort`; Express
|
|
26
|
+
* routes and admin/AI tool surfaces call these functions, never the repo directly.
|
|
27
|
+
*
|
|
28
|
+
* Egress allowlist check for a candidate `target_url` (beyond the flat `https://` scheme
|
|
29
|
+
* requirement enforced here). Injected rather than importing `Jini packages/http-kit/src/verified-origin/origin.ts` directly — see the
|
|
30
|
+
* file header. Production wiring: `core/origin`'s `isAllowedEgressTarget` (ADR-040).
|
|
31
|
+
*
|
|
32
|
+
* Create a new webhook subscription. Starts `active` with `secretVersion: 1` and no rotation in
|
|
33
|
+
* progress (`previousSecretVersion: null`) — the signing secret itself is derived at delivery
|
|
34
|
+
* time (ADR-036 §5), never generated or stored here.
|
|
35
|
+
*
|
|
36
|
+
* @complexity O(topics) for de-duplication; one repo write.
|
|
37
|
+
* @overallScore 100
|
|
38
|
+
*
|
|
39
|
+
* Update a subscription's label/target/topics. Does not touch `status` or secret versioning —
|
|
40
|
+
* those are `pauseSubscription`'s and (deferred) rotation's job respectively.
|
|
41
|
+
*
|
|
42
|
+
* @complexity O(topics); one repo read + one repo write.
|
|
43
|
+
* @overallScore 100
|
|
44
|
+
*
|
|
45
|
+
* `true` (default) pauses; `false` resumes back to `active`. One function, both directions —
|
|
46
|
+
* matches the CRUD list this library owes (no separate `resumeSubscription` was asked for).
|
|
47
|
+
*
|
|
48
|
+
* Pause or resume an active/paused subscription. A `disabled` (soft-deleted) subscription is a
|
|
49
|
+
* terminal state — it cannot be paused or resumed back to life; delete-then-recreate instead.
|
|
50
|
+
*
|
|
51
|
+
* @complexity O(1); one repo read + one repo write.
|
|
52
|
+
* @overallScore 100
|
|
53
|
+
*
|
|
54
|
+
* Soft-delete: sets `status: "disabled"` + stamps `disabledAt`. Never row-deletes (audit
|
|
55
|
+
* durability, ADR-036 §2) — `WebhookSubscriptionRepoPort` has no `delete` method for exactly
|
|
56
|
+
* this reason.
|
|
57
|
+
*
|
|
58
|
+
* @complexity O(1); one repo read + one repo write.
|
|
59
|
+
* @overallScore 100
|
|
60
|
+
*
|
|
61
|
+
* Enforce `https://` (ADR-036 §4 SSRF/egress posture starts here) and defer to the injected
|
|
62
|
+
* allowlist check. Returns the trimmed URL so callers store a normalized value.
|
|
63
|
+
*
|
|
64
|
+
* Trim, drop blanks, and de-duplicate topics while preserving first-seen order.
|
|
65
|
+
*/
|
|
66
|
+
import { type WebhookSubscriptionDeps as JiniSubscriptionDeps, type CreateSubscriptionInput as JiniCreateInput, type UpdateSubscriptionInput, type PauseSubscriptionInput, type PauseSubscriptionOptional, type DeleteSubscriptionInput, type WebhookSubscriptionOptional } from "../index.js";
|
|
67
|
+
export { WebhookSubscriptionNotFoundError, WebhookSubscriptionValidationError } from "../index.js";
|
|
68
|
+
export type { UpdateSubscriptionInput, PauseSubscriptionInput, PauseSubscriptionOptional, DeleteSubscriptionInput, WebhookSubscriptionOptional } from "../index.js";
|
|
69
|
+
export interface WebhookSubscriptionDeps extends Omit<JiniSubscriptionDeps, "isAllowedTarget" | "clock"> {
|
|
70
|
+
clock: {
|
|
71
|
+
nowIso(): string;
|
|
72
|
+
};
|
|
73
|
+
isAllowedTarget: (required: {
|
|
74
|
+
url: string;
|
|
75
|
+
}, optional?: Record<string, never>) => Promise<boolean>;
|
|
76
|
+
}
|
|
77
|
+
export interface CreateSubscriptionInput extends JiniCreateInput {
|
|
78
|
+
createdByPluginId?: string | null;
|
|
79
|
+
}
|
|
80
|
+
export interface CreateSubscriptionRequired {
|
|
81
|
+
deps: WebhookSubscriptionDeps;
|
|
82
|
+
input: CreateSubscriptionInput;
|
|
83
|
+
}
|
|
84
|
+
export interface UpdateSubscriptionRequired {
|
|
85
|
+
deps: WebhookSubscriptionDeps;
|
|
86
|
+
input: UpdateSubscriptionInput;
|
|
87
|
+
}
|
|
88
|
+
export interface PauseSubscriptionRequired {
|
|
89
|
+
deps: WebhookSubscriptionDeps;
|
|
90
|
+
input: PauseSubscriptionInput;
|
|
91
|
+
}
|
|
92
|
+
export interface DeleteSubscriptionRequired {
|
|
93
|
+
deps: WebhookSubscriptionDeps;
|
|
94
|
+
input: DeleteSubscriptionInput;
|
|
95
|
+
}
|
|
96
|
+
/** Keep existing actor attribution while moving it into Jini's optional object.
|
|
97
|
+
* @complexity O(topics), with one guarded target check and one repo write.
|
|
98
|
+
*/
|
|
99
|
+
export declare function createSubscription({ deps, input }: CreateSubscriptionRequired, optional?: WebhookSubscriptionOptional): Promise<{
|
|
100
|
+
subscription: import("../types.js").WebhookSubscriptionRecord;
|
|
101
|
+
}>;
|
|
102
|
+
/** Translate the target-policy callback; validation completes before the replacement is saved. */
|
|
103
|
+
export declare function updateSubscription({ deps, input }: UpdateSubscriptionRequired, optional?: WebhookSubscriptionOptional & {
|
|
104
|
+
expectedVersion?: number;
|
|
105
|
+
}): Promise<{
|
|
106
|
+
subscription: import("../types.js").WebhookSubscriptionRecord;
|
|
107
|
+
}>;
|
|
108
|
+
/** Translate the host callback without changing the paused/disabled lifecycle. */
|
|
109
|
+
export declare function pauseSubscription({ deps, input }: PauseSubscriptionRequired, optional?: PauseSubscriptionOptional): Promise<{
|
|
110
|
+
subscription: import("../types.js").WebhookSubscriptionRecord;
|
|
111
|
+
}>;
|
|
112
|
+
/** Translate the host callback while retaining soft-delete audit history. */
|
|
113
|
+
export declare function deleteSubscription({ deps, input }: DeleteSubscriptionRequired, optional?: WebhookSubscriptionOptional & {
|
|
114
|
+
expectedVersion?: number;
|
|
115
|
+
}): Promise<{
|
|
116
|
+
subscription: import("../types.js").WebhookSubscriptionRecord;
|
|
117
|
+
}>;
|
|
118
|
+
//# sourceMappingURL=subscriptions.d.ts.map
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/** Host callback and actor-attribution adapter; Jini owns subscription validation and lifecycle.
|
|
2
|
+
*
|
|
3
|
+
* Contract rationale for the Jini implementation and this host boundary:
|
|
4
|
+
*
|
|
5
|
+
* @file Webhook subscription CRUD (ADR-036 §2/§6) — the write-service behind the admin/AI
|
|
6
|
+
* gateway handlers.
|
|
7
|
+
*
|
|
8
|
+
* Purpose:
|
|
9
|
+
* `createSubscription` / `updateSubscription` / `pauseSubscription` / `deleteSubscription`.
|
|
10
|
+
* Mirrors `src/features/post/post.ts`'s `updatePost` shape (required `{ deps, input }` +
|
|
11
|
+
* optional second param), since these functions play the same "feature write-service" role.
|
|
12
|
+
*
|
|
13
|
+
* How it relates to the project:
|
|
14
|
+
* - Every mutation here is the thing the ADR-036 §6 gateway/`authorize()` chokepoint calls —
|
|
15
|
+
* this file itself does no authorization; that lives in the (out-of-scope) route handler.
|
|
16
|
+
* - `target_url` validation reuses `EgressPolicy`'s intent (only `https://`, only allowed
|
|
17
|
+
* hosts) but does NOT import `src/origin` directly — that module may not exist yet or be
|
|
18
|
+
* mid-build by another agent. Callers inject `isAllowedTarget`; production wiring plugs in
|
|
19
|
+
* the real SSRF/egress check once that module lands (see `WebhookSubscriptionDeps` doc).
|
|
20
|
+
* - `deleteSubscription` never row-deletes (ADR-036 §2 / `WebhookSubscriptionRecord.disabledAt`
|
|
21
|
+
* doc: "Set (never row-deleted) when disabled, for audit durability") — it soft-disables via
|
|
22
|
+
* `repo.save`, matching that `WebhookSubscriptionRepoPort` has no `delete` method at all.
|
|
23
|
+
*
|
|
24
|
+
* Architectural role:
|
|
25
|
+
* Jini owns the feature-level business rules. Repositories stay behind `WebhookSubscriptionRepoPort`; Express
|
|
26
|
+
* routes and admin/AI tool surfaces call these functions, never the repo directly.
|
|
27
|
+
*
|
|
28
|
+
* Egress allowlist check for a candidate `target_url` (beyond the flat `https://` scheme
|
|
29
|
+
* requirement enforced here). Injected rather than importing `Jini packages/http-kit/src/verified-origin/origin.ts` directly — see the
|
|
30
|
+
* file header. Production wiring: `core/origin`'s `isAllowedEgressTarget` (ADR-040).
|
|
31
|
+
*
|
|
32
|
+
* Create a new webhook subscription. Starts `active` with `secretVersion: 1` and no rotation in
|
|
33
|
+
* progress (`previousSecretVersion: null`) — the signing secret itself is derived at delivery
|
|
34
|
+
* time (ADR-036 §5), never generated or stored here.
|
|
35
|
+
*
|
|
36
|
+
* @complexity O(topics) for de-duplication; one repo write.
|
|
37
|
+
* @overallScore 100
|
|
38
|
+
*
|
|
39
|
+
* Update a subscription's label/target/topics. Does not touch `status` or secret versioning —
|
|
40
|
+
* those are `pauseSubscription`'s and (deferred) rotation's job respectively.
|
|
41
|
+
*
|
|
42
|
+
* @complexity O(topics); one repo read + one repo write.
|
|
43
|
+
* @overallScore 100
|
|
44
|
+
*
|
|
45
|
+
* `true` (default) pauses; `false` resumes back to `active`. One function, both directions —
|
|
46
|
+
* matches the CRUD list this library owes (no separate `resumeSubscription` was asked for).
|
|
47
|
+
*
|
|
48
|
+
* Pause or resume an active/paused subscription. A `disabled` (soft-deleted) subscription is a
|
|
49
|
+
* terminal state — it cannot be paused or resumed back to life; delete-then-recreate instead.
|
|
50
|
+
*
|
|
51
|
+
* @complexity O(1); one repo read + one repo write.
|
|
52
|
+
* @overallScore 100
|
|
53
|
+
*
|
|
54
|
+
* Soft-delete: sets `status: "disabled"` + stamps `disabledAt`. Never row-deletes (audit
|
|
55
|
+
* durability, ADR-036 §2) — `WebhookSubscriptionRepoPort` has no `delete` method for exactly
|
|
56
|
+
* this reason.
|
|
57
|
+
*
|
|
58
|
+
* @complexity O(1); one repo read + one repo write.
|
|
59
|
+
* @overallScore 100
|
|
60
|
+
*
|
|
61
|
+
* Enforce `https://` (ADR-036 §4 SSRF/egress posture starts here) and defer to the injected
|
|
62
|
+
* allowlist check. Returns the trimmed URL so callers store a normalized value.
|
|
63
|
+
*
|
|
64
|
+
* Trim, drop blanks, and de-duplicate topics while preserving first-seen order.
|
|
65
|
+
*/
|
|
66
|
+
import { createSubscription as createWebhookSubscription, updateSubscription as updateWebhookSubscription, pauseSubscription as pauseWebhookSubscription, deleteSubscription as deleteWebhookSubscription, } from "../index.js";
|
|
67
|
+
export { WebhookSubscriptionNotFoundError, WebhookSubscriptionValidationError } from "../index.js";
|
|
68
|
+
/** Adapts the ISO clock contract to Jini's `nowMs` clock. */
|
|
69
|
+
function adaptSubscriptionDeps(deps) {
|
|
70
|
+
return {
|
|
71
|
+
...deps,
|
|
72
|
+
// Existing routes and excluded durable adapters keep their ISO clock contract.
|
|
73
|
+
clock: { nowMs: () => Date.parse(deps.clock.nowIso()) },
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/** Keep existing actor attribution while moving it into Jini's optional object.
|
|
77
|
+
* @complexity O(topics), with one guarded target check and one repo write.
|
|
78
|
+
*/
|
|
79
|
+
export function createSubscription({ deps, input }, optional = {}) {
|
|
80
|
+
const { createdByPluginId, ...requiredInput } = input;
|
|
81
|
+
return createWebhookSubscription({ deps: adaptSubscriptionDeps(deps), input: requiredInput }, {
|
|
82
|
+
...(createdByPluginId !== undefined ? { createdByPluginId } : {}), ...optional,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/** Translate the target-policy callback; validation completes before the replacement is saved. */
|
|
86
|
+
export function updateSubscription({ deps, input }, optional = {}) {
|
|
87
|
+
return updateWebhookSubscription({ deps: adaptSubscriptionDeps(deps), input }, optional);
|
|
88
|
+
}
|
|
89
|
+
/** Translate the host callback without changing the paused/disabled lifecycle. */
|
|
90
|
+
export function pauseSubscription({ deps, input }, optional = {}) {
|
|
91
|
+
return pauseWebhookSubscription({ deps: adaptSubscriptionDeps(deps), input }, optional);
|
|
92
|
+
}
|
|
93
|
+
/** Translate the host callback while retaining soft-delete audit history. */
|
|
94
|
+
export function deleteSubscription({ deps, input }, optional = {}) {
|
|
95
|
+
return deleteWebhookSubscription({ deps: adaptSubscriptionDeps(deps), input }, optional);
|
|
96
|
+
}
|
|
97
|
+
// Lifecycle/egress rationale: ../subscriptions.ts (ADR-036).
|
|
98
|
+
//# sourceMappingURL=subscriptions.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { SqlWebhookDeliveryRepo, SqlWebhookSubscriptionRepo } from "./webhook-repo.js";
|
|
2
|
+
export type { WebhookSqlRequired, WebhookSubscriptionSqlRequired, WebhookTables } from "./webhook-repo.js";
|
|
3
|
+
export type { WebhookDeliveriesTable, WebhookSubscriptionsTable } from "./repo.rows.js";
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { Generated } from "kysely";
|
|
2
|
+
/**
|
|
3
|
+
* @file Stored column shapes of the two webhook tables, copied without schema changes in the
|
|
4
|
+
* generated key order of the host's content database types. The table names are host-owned (see
|
|
5
|
+
* `WebhookTables`).
|
|
6
|
+
*/
|
|
7
|
+
export interface WebhookDeliveriesTable {
|
|
8
|
+
id: string;
|
|
9
|
+
workspace_id: string;
|
|
10
|
+
subscription_id: string;
|
|
11
|
+
event_id: string;
|
|
12
|
+
topic: string;
|
|
13
|
+
payload_json: string | null;
|
|
14
|
+
status: string;
|
|
15
|
+
attempts: number;
|
|
16
|
+
next_attempt_at: string;
|
|
17
|
+
last_response_status: number | null;
|
|
18
|
+
last_error: string | null;
|
|
19
|
+
signed_with_version: number | null;
|
|
20
|
+
created_at: string;
|
|
21
|
+
delivered_at: string | null;
|
|
22
|
+
dead_at: string | null;
|
|
23
|
+
}
|
|
24
|
+
export interface WebhookSubscriptionsTable {
|
|
25
|
+
id: string;
|
|
26
|
+
workspace_id: string;
|
|
27
|
+
owner_principal_id: string;
|
|
28
|
+
label: string;
|
|
29
|
+
target_url: string;
|
|
30
|
+
topics_json: string;
|
|
31
|
+
secret_version: number;
|
|
32
|
+
previous_secret_version: number | null;
|
|
33
|
+
status: string;
|
|
34
|
+
created_by_principal_id: string;
|
|
35
|
+
created_by_plugin_id: string | null;
|
|
36
|
+
/**
|
|
37
|
+
* `agent` | `person`; null on rows written before attribution existed (read as person-made). The
|
|
38
|
+
* host schema must add this nullable column before it wires the agent switch, or a restart would
|
|
39
|
+
* forget which subscriptions an agent created.
|
|
40
|
+
*/
|
|
41
|
+
created_by_kind: string | null;
|
|
42
|
+
created_at: string;
|
|
43
|
+
updated_at: string;
|
|
44
|
+
version: Generated<number>;
|
|
45
|
+
disabled_at: string | null;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=repo.rows.d.ts.map
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import type { AssertVersionedWritePort } from "@jini-ai/core/optimistic-concurrency";
|
|
2
|
+
import type { Kysely } from "kysely";
|
|
3
|
+
import type { StorageKernel } from "@jini-ai/core/contracts/storage";
|
|
4
|
+
/** Host type boundary for durable repositories (ADR-036).
|
|
5
|
+
* Webhook tables are core-owned, not third-party plugin data modules; writes use the host mutation
|
|
6
|
+
* chokepoint and composite workspace isolation. API keys remain owned by identity.
|
|
7
|
+
* Host rows use stable ULIDs. Delivery/signature/envelope contracts belong to the Jini owner.
|
|
8
|
+
*/
|
|
9
|
+
import type { DeliveryEnvelopeStorePort as DeliveryEnvelopeStore } from "../ports.js";
|
|
10
|
+
import type { WebhookDeliveryRepoPort, WebhookSubscriptionRepoPort } from "../ports.js";
|
|
11
|
+
import type { IntegrationId, WebhookDeliveryRecord, WebhookDeliveryStatus, WebhookEventEnvelope, WebhookSubscriptionRecord, WebhookTopic } from "../types.js";
|
|
12
|
+
/**
|
|
13
|
+
* @file THE adapters for the `integrations` webhook repo ports (ADR-036 §2, ADR-PIPE-015 Phase 2,
|
|
14
|
+
* GAP-05 + GAP-12): one Kysely query body each for every dialect (storage plan §4, ADR-066).
|
|
15
|
+
* The host's SQLite binding holds the thin subclasses built from its content db handle, passing
|
|
16
|
+
* its table names ({@link WebhookTables}).
|
|
17
|
+
*
|
|
18
|
+
* Purpose:
|
|
19
|
+
* The other half of each ADR-006 rule-of-two, mirroring `repo.memory.ts`'s in-memory shape
|
|
20
|
+
* exactly (same claim/mark lifecycle, same `topicMatches` semantics). `SqlWebhookDeliveryRepo`
|
|
21
|
+
* additionally implements `DeliveryEnvelopeStore` against the SAME `webhook_deliveries` row (its
|
|
22
|
+
* `payload_json` column) rather than a separate table — GAP-05 (no durable storage) and GAP-12
|
|
23
|
+
* (no envelope re-hydration path) are the same underlying gap, per the ADR's own Rationale.
|
|
24
|
+
*
|
|
25
|
+
* How it relates to the project:
|
|
26
|
+
* - `enqueueDelivery` (`../delivery.ts`) calls `deliveryRepo.enqueue()` then
|
|
27
|
+
* `envelopeStore.save()` as two sequential calls (see that file) — both land on the same row
|
|
28
|
+
* here, `save()` updating the `payload_json` column `enqueue()` left `NULL`.
|
|
29
|
+
* - The unique index on `(workspace_id, subscription_id, event_id)` (the host schema) makes `enqueue`
|
|
30
|
+
* idempotent at the storage layer: a duplicate insert is `ON CONFLICT DO NOTHING` (any unique
|
|
31
|
+
* index, the primary key included — not a caught error, which would abort an enclosing
|
|
32
|
+
* Postgres transaction), closing the race `delivery.ts`'s scan-based pre-check alone can't (two
|
|
33
|
+
* concurrent enqueues could both pass the scan before either commits).
|
|
34
|
+
*
|
|
35
|
+
* `claimPending` selects and marks rows `delivering` in one kernel transaction under
|
|
36
|
+
* `lockKey("webhook_deliveries:claim")`, so two claimers never take the same row on any dialect;
|
|
37
|
+
* each mark is guarded on the status and attempt count it read, so an outcome settled between the
|
|
38
|
+
* read and the mark is never reopened.
|
|
39
|
+
*/
|
|
40
|
+
/** Host-owned table names. No schema or product table defaults live in the adapter. */
|
|
41
|
+
export interface WebhookTables {
|
|
42
|
+
webhookSubscriptions: string;
|
|
43
|
+
webhookDeliveries: string;
|
|
44
|
+
}
|
|
45
|
+
export interface WebhookSqlRequired {
|
|
46
|
+
kernel: StorageKernel<Kysely<unknown>, unknown>;
|
|
47
|
+
tables: WebhookTables;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The subscription adapter's constructor object: the shared SQL deps plus its versioned-write
|
|
51
|
+
* collaborator. Changed rows mean done; none means re-read the live version and throw the host's
|
|
52
|
+
* conflict error. The host binds its optimistic-concurrency implementation (normally
|
|
53
|
+
* `@jini-ai/core/optimistic-concurrency`'s `assertVersionedWrite`).
|
|
54
|
+
*/
|
|
55
|
+
export interface WebhookSubscriptionSqlRequired extends WebhookSqlRequired {
|
|
56
|
+
assertVersionedWrite: AssertVersionedWritePort;
|
|
57
|
+
}
|
|
58
|
+
export declare class SqlWebhookSubscriptionRepo implements WebhookSubscriptionRepoPort {
|
|
59
|
+
protected readonly kernel: StorageKernel<Kysely<unknown>, unknown>;
|
|
60
|
+
protected readonly tables: WebhookTables;
|
|
61
|
+
private readonly assertVersionedWrite;
|
|
62
|
+
constructor({ kernel, tables, assertVersionedWrite }: WebhookSubscriptionSqlRequired, _optional?: Record<string, never>);
|
|
63
|
+
/** Host-owned table name needs an explicit column schema, as in the outbox adapter. */
|
|
64
|
+
private table;
|
|
65
|
+
insert(record: WebhookSubscriptionRecord): Promise<void>;
|
|
66
|
+
save(record: WebhookSubscriptionRecord, optional?: {
|
|
67
|
+
expectedVersion?: number;
|
|
68
|
+
}): Promise<void>;
|
|
69
|
+
findById(required: {
|
|
70
|
+
workspaceId: string;
|
|
71
|
+
id: IntegrationId;
|
|
72
|
+
}): Promise<WebhookSubscriptionRecord | null>;
|
|
73
|
+
listByWorkspace(required: {
|
|
74
|
+
workspaceId: string;
|
|
75
|
+
}): Promise<WebhookSubscriptionRecord[]>;
|
|
76
|
+
findMatching(required: {
|
|
77
|
+
workspaceId: string;
|
|
78
|
+
topic: WebhookTopic;
|
|
79
|
+
}): Promise<WebhookSubscriptionRecord[]>;
|
|
80
|
+
}
|
|
81
|
+
export declare class SqlWebhookDeliveryRepo implements WebhookDeliveryRepoPort, DeliveryEnvelopeStore {
|
|
82
|
+
protected readonly kernel: StorageKernel<Kysely<unknown>, unknown>;
|
|
83
|
+
protected readonly tables: WebhookTables;
|
|
84
|
+
constructor({ kernel, tables }: WebhookSqlRequired, _optional?: Record<string, never>);
|
|
85
|
+
/** Host-owned table name needs an explicit column schema, as in the outbox adapter. */
|
|
86
|
+
private table;
|
|
87
|
+
/** ADR-046 fold-in item 5 (GAP-05/GAP-12): when `envelope` is supplied, it's written in this
|
|
88
|
+
* SAME `INSERT` — never left `NULL` for a later `.update()` to fill in — so a durable claimable
|
|
89
|
+
* delivery row can never exist with a missing envelope. A row that collides with any unique
|
|
90
|
+
* index (`(workspace_id, subscription_id, event_id)` or the id) is already enqueued: idempotent
|
|
91
|
+
* by design (INV-P4), a silent no-op. */
|
|
92
|
+
enqueue({ record }: {
|
|
93
|
+
record: WebhookDeliveryRecord;
|
|
94
|
+
}, { envelope }?: {
|
|
95
|
+
envelope?: WebhookEventEnvelope;
|
|
96
|
+
}): Promise<void>;
|
|
97
|
+
/** With `claimLeaseMs`, a `delivering` row whose lease (`next_attempt_at`, no new column) has
|
|
98
|
+
* expired is claimable again, and each claim writes nowIso + claimLeaseMs as its lease: a claimer
|
|
99
|
+
* that crashed or was abandoned at shutdown no longer strands its rows in `delivering`. */
|
|
100
|
+
claimPending(required: {
|
|
101
|
+
batchSize: number;
|
|
102
|
+
nowIso: string;
|
|
103
|
+
}, optional?: {
|
|
104
|
+
claimLeaseMs?: number;
|
|
105
|
+
}): Promise<WebhookDeliveryRecord[]>;
|
|
106
|
+
/** Returns a never-attempted claim to `pending` with its attempt undone. Fenced on the claim's
|
|
107
|
+
* attempts and on `delivering`, so a row reclaimed or settled since is left alone. */
|
|
108
|
+
releaseClaim(required: {
|
|
109
|
+
workspaceId: string;
|
|
110
|
+
id: IntegrationId;
|
|
111
|
+
claimedAttempts: number;
|
|
112
|
+
nextAttemptAt: string;
|
|
113
|
+
}, _optional?: Record<string, never>): Promise<void>;
|
|
114
|
+
markDelivered(required: {
|
|
115
|
+
workspaceId: string;
|
|
116
|
+
id: IntegrationId;
|
|
117
|
+
responseStatus: number;
|
|
118
|
+
deliveredAtIso: string;
|
|
119
|
+
}, optional?: {
|
|
120
|
+
claimedAttempts?: number;
|
|
121
|
+
}): Promise<void>;
|
|
122
|
+
/** One UPDATE: `dead_at` is only written when the row goes dead with a stamp; otherwise it keeps
|
|
123
|
+
* its stored value. A missing row is a no-op. */
|
|
124
|
+
markFailed(required: {
|
|
125
|
+
workspaceId: string;
|
|
126
|
+
id: IntegrationId;
|
|
127
|
+
error: string;
|
|
128
|
+
responseStatus: number | null;
|
|
129
|
+
nextStatus: Extract<WebhookDeliveryStatus, "failed" | "dead">;
|
|
130
|
+
nextAttemptAt: string;
|
|
131
|
+
}, optional?: {
|
|
132
|
+
deadAtIso?: string;
|
|
133
|
+
claimedAttempts?: number;
|
|
134
|
+
}): Promise<void>;
|
|
135
|
+
findById(required: {
|
|
136
|
+
workspaceId: string;
|
|
137
|
+
id: IntegrationId;
|
|
138
|
+
}): Promise<WebhookDeliveryRecord | null>;
|
|
139
|
+
listBySubscription(required: {
|
|
140
|
+
workspaceId: string;
|
|
141
|
+
subscriptionId: IntegrationId;
|
|
142
|
+
limit: number;
|
|
143
|
+
}, _optional?: Record<string, never>): Promise<WebhookDeliveryRecord[]>;
|
|
144
|
+
save(input: {
|
|
145
|
+
deliveryId: IntegrationId;
|
|
146
|
+
envelope: WebhookEventEnvelope;
|
|
147
|
+
}): Promise<void>;
|
|
148
|
+
find(input: {
|
|
149
|
+
deliveryId: IntegrationId;
|
|
150
|
+
}): Promise<WebhookEventEnvelope | null>;
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=webhook-repo.d.ts.map
|