@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,308 @@
|
|
|
1
|
+
import { CREATOR_KINDS } from "@jini-ai/core/primitives";
|
|
2
|
+
function topicsToJson(topics) {
|
|
3
|
+
return JSON.stringify(topics);
|
|
4
|
+
}
|
|
5
|
+
function topicsFromJson({ json }, _optional = {}) {
|
|
6
|
+
return JSON.parse(json);
|
|
7
|
+
}
|
|
8
|
+
/** A stored creator kind, or undefined for a legacy/unknown value so the record stays unattributed (person). */
|
|
9
|
+
function creatorKindFromColumn(value) {
|
|
10
|
+
return CREATOR_KINDS.includes(value ?? "") ? value : undefined;
|
|
11
|
+
}
|
|
12
|
+
function toSubscriptionRecord(row) {
|
|
13
|
+
const createdByKind = creatorKindFromColumn(row.created_by_kind);
|
|
14
|
+
return {
|
|
15
|
+
id: row.id,
|
|
16
|
+
workspaceId: row.workspace_id,
|
|
17
|
+
ownerPrincipalId: row.owner_principal_id,
|
|
18
|
+
label: row.label,
|
|
19
|
+
targetUrl: row.target_url,
|
|
20
|
+
topics: topicsFromJson({ json: row.topics_json }),
|
|
21
|
+
secretVersion: row.secret_version,
|
|
22
|
+
previousSecretVersion: row.previous_secret_version,
|
|
23
|
+
status: row.status,
|
|
24
|
+
createdByPrincipalId: row.created_by_principal_id,
|
|
25
|
+
createdByPluginId: row.created_by_plugin_id,
|
|
26
|
+
// Omitted rather than undefined when absent, so unattributed records compare equal to the input.
|
|
27
|
+
...(createdByKind ? { createdByKind } : {}),
|
|
28
|
+
createdAt: row.created_at,
|
|
29
|
+
updatedAt: row.updated_at,
|
|
30
|
+
disabledAt: row.disabled_at,
|
|
31
|
+
version: row.version,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function toSubscriptionRow(record) {
|
|
35
|
+
return {
|
|
36
|
+
id: record.id,
|
|
37
|
+
workspace_id: record.workspaceId,
|
|
38
|
+
owner_principal_id: record.ownerPrincipalId,
|
|
39
|
+
label: record.label,
|
|
40
|
+
target_url: record.targetUrl,
|
|
41
|
+
topics_json: topicsToJson(record.topics),
|
|
42
|
+
secret_version: record.secretVersion,
|
|
43
|
+
previous_secret_version: record.previousSecretVersion,
|
|
44
|
+
status: record.status,
|
|
45
|
+
created_by_principal_id: record.createdByPrincipalId,
|
|
46
|
+
created_by_plugin_id: record.createdByPluginId,
|
|
47
|
+
created_by_kind: record.createdByKind ?? null,
|
|
48
|
+
created_at: record.createdAt,
|
|
49
|
+
updated_at: record.updatedAt,
|
|
50
|
+
disabled_at: record.disabledAt,
|
|
51
|
+
version: record.version,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Does a subscription's topic set match a delivered event's topic? Mirrors
|
|
56
|
+
* `repo.memory.ts`'s `topicMatches` exactly — kept as a private duplicate rather than a shared
|
|
57
|
+
* import so each adapter stays independently readable (same rationale the settings adapters use).
|
|
58
|
+
*/
|
|
59
|
+
function topicMatches(subscribedTopics, topic) {
|
|
60
|
+
return subscribedTopics.some((pattern) => {
|
|
61
|
+
if (pattern === "*")
|
|
62
|
+
return true;
|
|
63
|
+
if (pattern === topic)
|
|
64
|
+
return true;
|
|
65
|
+
if (pattern.endsWith(".*")) {
|
|
66
|
+
const entityPrefix = pattern.slice(0, -1);
|
|
67
|
+
return topic.startsWith(entityPrefix);
|
|
68
|
+
}
|
|
69
|
+
return false;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
export class SqlWebhookSubscriptionRepo {
|
|
73
|
+
kernel;
|
|
74
|
+
tables;
|
|
75
|
+
assertVersionedWrite;
|
|
76
|
+
constructor({ kernel, tables, assertVersionedWrite }, _optional = {}) {
|
|
77
|
+
this.kernel = kernel;
|
|
78
|
+
this.tables = tables;
|
|
79
|
+
this.assertVersionedWrite = assertVersionedWrite;
|
|
80
|
+
}
|
|
81
|
+
/** Host-owned table name needs an explicit column schema, as in the outbox adapter. */
|
|
82
|
+
table(db) {
|
|
83
|
+
return db.withTables();
|
|
84
|
+
}
|
|
85
|
+
async insert(record) {
|
|
86
|
+
await this.kernel.run((db) => this.table(db).insertInto(this.tables.webhookSubscriptions).values(toSubscriptionRow(record)).execute());
|
|
87
|
+
}
|
|
88
|
+
async save(record, optional = {}) {
|
|
89
|
+
const row = toSubscriptionRow(record);
|
|
90
|
+
const { expectedVersion } = optional;
|
|
91
|
+
if (expectedVersion !== undefined) {
|
|
92
|
+
const { id: _id, workspace_id: _workspaceId, ...values } = row;
|
|
93
|
+
// A single conditional UPDATE rejects stale editors without re-creating missing rows.
|
|
94
|
+
const result = await this.kernel.run((db) => this.table(db).updateTable(this.tables.webhookSubscriptions).set(values)
|
|
95
|
+
.where("workspace_id", "=", record.workspaceId).where("id", "=", record.id)
|
|
96
|
+
.where("version", "=", expectedVersion).executeTakeFirst());
|
|
97
|
+
await this.assertVersionedWrite({ changedRows: result.numUpdatedRows, recordKind: "webhook subscription", recordId: record.id,
|
|
98
|
+
expectedVersion, readCurrentVersion: async () => (await this.findById({ workspaceId: record.workspaceId, id: record.id }))?.version ?? null });
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
await this.kernel.run((db) => this.table(db)
|
|
102
|
+
.insertInto(this.tables.webhookSubscriptions)
|
|
103
|
+
.values(row)
|
|
104
|
+
.onConflict((oc) => oc.column("id").doUpdateSet(row))
|
|
105
|
+
.execute());
|
|
106
|
+
}
|
|
107
|
+
async findById(required) {
|
|
108
|
+
const row = await this.kernel.run((db) => this.table(db)
|
|
109
|
+
.selectFrom(this.tables.webhookSubscriptions)
|
|
110
|
+
.selectAll()
|
|
111
|
+
.where("workspace_id", "=", required.workspaceId)
|
|
112
|
+
.where("id", "=", required.id)
|
|
113
|
+
.limit(1)
|
|
114
|
+
.executeTakeFirst());
|
|
115
|
+
return row ? toSubscriptionRecord(row) : null;
|
|
116
|
+
}
|
|
117
|
+
async listByWorkspace(required) {
|
|
118
|
+
const rows = await this.kernel.run((db) => this.table(db).selectFrom(this.tables.webhookSubscriptions).selectAll().where("workspace_id", "=", required.workspaceId).execute());
|
|
119
|
+
return rows.map(toSubscriptionRecord);
|
|
120
|
+
}
|
|
121
|
+
async findMatching(required) {
|
|
122
|
+
const rows = await this.kernel.run((db) => this.table(db)
|
|
123
|
+
.selectFrom(this.tables.webhookSubscriptions)
|
|
124
|
+
.selectAll()
|
|
125
|
+
.where("workspace_id", "=", required.workspaceId)
|
|
126
|
+
.where("status", "=", "active")
|
|
127
|
+
.execute());
|
|
128
|
+
return rows.map(toSubscriptionRecord).filter((row) => topicMatches(row.topics, required.topic));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function toDeliveryRecord(row) {
|
|
132
|
+
return {
|
|
133
|
+
id: row.id,
|
|
134
|
+
workspaceId: row.workspace_id,
|
|
135
|
+
subscriptionId: row.subscription_id,
|
|
136
|
+
eventId: row.event_id,
|
|
137
|
+
topic: row.topic,
|
|
138
|
+
status: row.status,
|
|
139
|
+
attempts: row.attempts,
|
|
140
|
+
nextAttemptAt: row.next_attempt_at,
|
|
141
|
+
lastResponseStatus: row.last_response_status,
|
|
142
|
+
lastError: row.last_error,
|
|
143
|
+
signedWithVersion: row.signed_with_version,
|
|
144
|
+
createdAt: row.created_at,
|
|
145
|
+
deliveredAt: row.delivered_at,
|
|
146
|
+
deadAt: row.dead_at,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
export class SqlWebhookDeliveryRepo {
|
|
150
|
+
kernel;
|
|
151
|
+
tables;
|
|
152
|
+
constructor({ kernel, tables }, _optional = {}) {
|
|
153
|
+
this.kernel = kernel;
|
|
154
|
+
this.tables = tables;
|
|
155
|
+
}
|
|
156
|
+
/** Host-owned table name needs an explicit column schema, as in the outbox adapter. */
|
|
157
|
+
table(db) {
|
|
158
|
+
return db.withTables();
|
|
159
|
+
}
|
|
160
|
+
/** ADR-046 fold-in item 5 (GAP-05/GAP-12): when `envelope` is supplied, it's written in this
|
|
161
|
+
* SAME `INSERT` — never left `NULL` for a later `.update()` to fill in — so a durable claimable
|
|
162
|
+
* delivery row can never exist with a missing envelope. A row that collides with any unique
|
|
163
|
+
* index (`(workspace_id, subscription_id, event_id)` or the id) is already enqueued: idempotent
|
|
164
|
+
* by design (INV-P4), a silent no-op. */
|
|
165
|
+
async enqueue({ record }, { envelope } = {}) {
|
|
166
|
+
await this.kernel.run((db) => this.table(db)
|
|
167
|
+
.insertInto(this.tables.webhookDeliveries)
|
|
168
|
+
.values({
|
|
169
|
+
id: record.id,
|
|
170
|
+
workspace_id: record.workspaceId,
|
|
171
|
+
subscription_id: record.subscriptionId,
|
|
172
|
+
event_id: record.eventId,
|
|
173
|
+
topic: record.topic,
|
|
174
|
+
payload_json: envelope ? JSON.stringify(envelope) : null,
|
|
175
|
+
status: record.status,
|
|
176
|
+
attempts: record.attempts,
|
|
177
|
+
next_attempt_at: record.nextAttemptAt,
|
|
178
|
+
last_response_status: record.lastResponseStatus,
|
|
179
|
+
last_error: record.lastError,
|
|
180
|
+
signed_with_version: record.signedWithVersion,
|
|
181
|
+
created_at: record.createdAt,
|
|
182
|
+
delivered_at: record.deliveredAt,
|
|
183
|
+
dead_at: record.deadAt,
|
|
184
|
+
})
|
|
185
|
+
.onConflict((oc) => oc.doNothing())
|
|
186
|
+
.execute());
|
|
187
|
+
}
|
|
188
|
+
/** With `claimLeaseMs`, a `delivering` row whose lease (`next_attempt_at`, no new column) has
|
|
189
|
+
* expired is claimable again, and each claim writes nowIso + claimLeaseMs as its lease: a claimer
|
|
190
|
+
* that crashed or was abandoned at shutdown no longer strands its rows in `delivering`. */
|
|
191
|
+
async claimPending(required, optional = {}) {
|
|
192
|
+
const { claimLeaseMs } = optional;
|
|
193
|
+
const statuses = claimLeaseMs === undefined ? ["pending"] : ["pending", "delivering"];
|
|
194
|
+
const lease = claimLeaseMs === undefined ? {} : { next_attempt_at: new Date(Date.parse(required.nowIso) + claimLeaseMs).toISOString() };
|
|
195
|
+
return this.kernel.transaction(async () => {
|
|
196
|
+
await this.kernel.lockKey("webhook_deliveries:claim");
|
|
197
|
+
const due = await this.kernel.run((db) => this.table(db)
|
|
198
|
+
.selectFrom(this.tables.webhookDeliveries)
|
|
199
|
+
.selectAll()
|
|
200
|
+
.where("status", "in", statuses)
|
|
201
|
+
.where("next_attempt_at", "<=", required.nowIso)
|
|
202
|
+
.orderBy("next_attempt_at", "asc")
|
|
203
|
+
.limit(required.batchSize)
|
|
204
|
+
.execute());
|
|
205
|
+
const claimed = [];
|
|
206
|
+
for (const row of due) {
|
|
207
|
+
// Guarded on what the read saw: the claim lock does not exclude a worker settling this
|
|
208
|
+
// row in between, and a settled row must not be reopened.
|
|
209
|
+
const result = await this.kernel.run((db) => this.table(db)
|
|
210
|
+
.updateTable(this.tables.webhookDeliveries)
|
|
211
|
+
.set({ status: "delivering", attempts: row.attempts + 1, ...lease })
|
|
212
|
+
.where("id", "=", row.id)
|
|
213
|
+
.where("status", "=", row.status)
|
|
214
|
+
.where("attempts", "=", row.attempts)
|
|
215
|
+
.where("next_attempt_at", "<=", required.nowIso)
|
|
216
|
+
.executeTakeFirst());
|
|
217
|
+
if (Number(result.numUpdatedRows) > 0)
|
|
218
|
+
claimed.push(row);
|
|
219
|
+
}
|
|
220
|
+
return claimed.map((row) => toDeliveryRecord({ ...row, status: "delivering", attempts: row.attempts + 1, ...lease }));
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
/** Returns a never-attempted claim to `pending` with its attempt undone. Fenced on the claim's
|
|
224
|
+
* attempts and on `delivering`, so a row reclaimed or settled since is left alone. */
|
|
225
|
+
async releaseClaim(required, _optional = {}) {
|
|
226
|
+
await this.kernel.run((db) => this.table(db)
|
|
227
|
+
.updateTable(this.tables.webhookDeliveries)
|
|
228
|
+
.set({ status: "pending", attempts: required.claimedAttempts - 1, next_attempt_at: required.nextAttemptAt })
|
|
229
|
+
.where("workspace_id", "=", required.workspaceId)
|
|
230
|
+
.where("id", "=", required.id)
|
|
231
|
+
.where("status", "=", "delivering")
|
|
232
|
+
.where("attempts", "=", required.claimedAttempts)
|
|
233
|
+
.execute());
|
|
234
|
+
}
|
|
235
|
+
async markDelivered(required, optional = {}) {
|
|
236
|
+
const { claimedAttempts } = optional;
|
|
237
|
+
await this.kernel.run((db) => this.table(db)
|
|
238
|
+
.updateTable(this.tables.webhookDeliveries)
|
|
239
|
+
.set({
|
|
240
|
+
status: "delivered",
|
|
241
|
+
last_response_status: required.responseStatus,
|
|
242
|
+
delivered_at: required.deliveredAtIso,
|
|
243
|
+
last_error: null,
|
|
244
|
+
})
|
|
245
|
+
.where("workspace_id", "=", required.workspaceId)
|
|
246
|
+
.where("id", "=", required.id)
|
|
247
|
+
// Ownership fence: a stale claimer's outcome must not overwrite a newer claim.
|
|
248
|
+
.$if(claimedAttempts !== undefined, (qb) => qb.where("attempts", "=", claimedAttempts))
|
|
249
|
+
.execute());
|
|
250
|
+
}
|
|
251
|
+
/** One UPDATE: `dead_at` is only written when the row goes dead with a stamp; otherwise it keeps
|
|
252
|
+
* its stored value. A missing row is a no-op. */
|
|
253
|
+
async markFailed(required, optional = {}) {
|
|
254
|
+
const dead = required.nextStatus === "dead";
|
|
255
|
+
const { claimedAttempts } = optional;
|
|
256
|
+
await this.kernel.run((db) => this.table(db)
|
|
257
|
+
.updateTable(this.tables.webhookDeliveries)
|
|
258
|
+
.set({
|
|
259
|
+
// "failed" re-enters "pending" immediately (WebhookDeliveryStatus doc); "dead" terminal.
|
|
260
|
+
status: dead ? "dead" : "pending",
|
|
261
|
+
last_error: required.error,
|
|
262
|
+
last_response_status: required.responseStatus,
|
|
263
|
+
next_attempt_at: required.nextAttemptAt,
|
|
264
|
+
...(dead && optional.deadAtIso !== undefined ? { dead_at: optional.deadAtIso } : {}),
|
|
265
|
+
})
|
|
266
|
+
.where("workspace_id", "=", required.workspaceId)
|
|
267
|
+
.where("id", "=", required.id)
|
|
268
|
+
.$if(claimedAttempts !== undefined, (qb) => qb.where("attempts", "=", claimedAttempts))
|
|
269
|
+
.execute());
|
|
270
|
+
}
|
|
271
|
+
async findById(required) {
|
|
272
|
+
const row = await this.kernel.run((db) => this.table(db)
|
|
273
|
+
.selectFrom(this.tables.webhookDeliveries)
|
|
274
|
+
.selectAll()
|
|
275
|
+
.where("workspace_id", "=", required.workspaceId)
|
|
276
|
+
.where("id", "=", required.id)
|
|
277
|
+
.limit(1)
|
|
278
|
+
.executeTakeFirst());
|
|
279
|
+
return row ? toDeliveryRecord(row) : null;
|
|
280
|
+
}
|
|
281
|
+
async listBySubscription(required, _optional = {}) {
|
|
282
|
+
const rows = await this.kernel.run((db) => this.table(db)
|
|
283
|
+
.selectFrom(this.tables.webhookDeliveries)
|
|
284
|
+
.selectAll()
|
|
285
|
+
.where("workspace_id", "=", required.workspaceId)
|
|
286
|
+
.where("subscription_id", "=", required.subscriptionId)
|
|
287
|
+
.orderBy("created_at", "desc")
|
|
288
|
+
.orderBy("id", "desc")
|
|
289
|
+
.limit(required.limit)
|
|
290
|
+
.execute());
|
|
291
|
+
return rows.map(toDeliveryRecord);
|
|
292
|
+
}
|
|
293
|
+
// --- DeliveryEnvelopeStore (GAP-12: same row, `payload_json` column) ---
|
|
294
|
+
async save(input) {
|
|
295
|
+
await this.kernel.run((db) => this.table(db)
|
|
296
|
+
.updateTable(this.tables.webhookDeliveries)
|
|
297
|
+
.set({ payload_json: JSON.stringify(input.envelope) })
|
|
298
|
+
.where("id", "=", input.deliveryId)
|
|
299
|
+
.execute());
|
|
300
|
+
}
|
|
301
|
+
async find(input) {
|
|
302
|
+
const row = await this.kernel.run((db) => this.table(db).selectFrom(this.tables.webhookDeliveries).select("payload_json").where("id", "=", input.deliveryId).limit(1).executeTakeFirst());
|
|
303
|
+
if (!row || !row.payload_json)
|
|
304
|
+
return null;
|
|
305
|
+
return JSON.parse(row.payload_json);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
//# sourceMappingURL=webhook-repo.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IntegrationError } from "../argument-error.js";
|
|
2
|
-
import type { Clock, IdGenerator, UUID } from "@jini-ai/core/primitives";
|
|
2
|
+
import type { Clock, CreatorKind, IdGenerator, UUID } from "@jini-ai/core/primitives";
|
|
3
3
|
import type { WebhookSubscriptionRepoPort } from "./ports.js";
|
|
4
4
|
import type { WebhookSubscriptionRecord, WebhookTopic } from "./types.js";
|
|
5
5
|
export declare class WebhookSubscriptionNotFoundError extends IntegrationError {
|
|
@@ -28,6 +28,8 @@ export interface CreateSubscriptionRequired {
|
|
|
28
28
|
}
|
|
29
29
|
export interface WebhookSubscriptionOptional {
|
|
30
30
|
createdByPluginId?: string | null;
|
|
31
|
+
/** Who is creating it; agent tool paths pass `"agent"`. Defaults to `"person"`. Ignored on edits. */
|
|
32
|
+
createdByKind?: CreatorKind;
|
|
31
33
|
}
|
|
32
34
|
/** Validate then insert an active subscription; no write occurs on validation failure. */
|
|
33
35
|
export declare function createSubscription(required: CreateSubscriptionRequired, optional?: WebhookSubscriptionOptional): Promise<{
|
|
@@ -40,6 +40,7 @@ export async function createSubscription(required, optional = {}) {
|
|
|
40
40
|
status: "active",
|
|
41
41
|
createdByPrincipalId: input.createdByPrincipalId,
|
|
42
42
|
createdByPluginId: optional.createdByPluginId ?? null,
|
|
43
|
+
createdByKind: optional.createdByKind ?? "person",
|
|
43
44
|
createdAt: now,
|
|
44
45
|
updatedAt: now,
|
|
45
46
|
version: 1,
|
|
@@ -65,7 +66,9 @@ export async function updateSubscription(required, optional = {}) {
|
|
|
65
66
|
updatedAt: nowIso({ clock: deps.clock }),
|
|
66
67
|
version: existing.version + 1,
|
|
67
68
|
};
|
|
68
|
-
|
|
69
|
+
// Default to the version just read (like pause/delete): without it, an edit could silently overwrite
|
|
70
|
+
// a pause or delete that committed between requireSubscription() and this save (B146).
|
|
71
|
+
await deps.repo.save(subscription, { expectedVersion: optional.expectedVersion ?? existing.version });
|
|
69
72
|
return { subscription };
|
|
70
73
|
}
|
|
71
74
|
/** Pause or resume a subscription; disabled subscriptions cannot resume. */
|
|
@@ -75,7 +75,8 @@ export const webhooksCreateSubscriptionHandler = ({ deps }, _optional = {}) => a
|
|
|
75
75
|
targetUrl: requireString({ input, key: "targetUrl" }),
|
|
76
76
|
topics: Array.isArray(rawTopics) ? rawTopics.map(String) : [],
|
|
77
77
|
},
|
|
78
|
-
|
|
78
|
+
// An agent tool call made this one: the host's agent switch pauses its deliveries when off.
|
|
79
|
+
}, { createdByKind: "agent" });
|
|
79
80
|
return { subscription: toSubscriptionToolView({ subscription, lastDelivery: null }) };
|
|
80
81
|
};
|
|
81
82
|
/** Uses the existing validation/egress owner and never exposes signing material. */
|
package/dist/webhooks/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/** Workspace-scoped subscription/delivery records and serializable wire envelopes. */
|
|
2
|
-
import type { UUID, ISODateTime, JsonObject } from "@jini-ai/core/primitives";
|
|
2
|
+
import type { CreatorKind, UUID, ISODateTime, JsonObject } from "@jini-ai/core/primitives";
|
|
3
|
+
import type { SealedSecret } from "../secrets/types.js";
|
|
3
4
|
/** Topic names share the domain-event catalog ({entity}.{action}); an entity's trailing .*
|
|
4
5
|
* subscribes to all its actions, while all-topic * requires the host's owner authorization. */
|
|
5
6
|
export type WebhookTopic = string;
|
|
@@ -23,6 +24,10 @@ export interface WebhookSubscriptionRecord {
|
|
|
23
24
|
status: WebhookSubscriptionStatus;
|
|
24
25
|
createdByPrincipalId: UUID;
|
|
25
26
|
createdByPluginId: string | null;
|
|
27
|
+
/** Person or agent. Optional because rows stored before attribution existed carry none; read
|
|
28
|
+
* it through `resolveCreatorKind`, which treats a missing value as `"person"` so the agent
|
|
29
|
+
* switch never pauses something an owner made. */
|
|
30
|
+
createdByKind?: CreatorKind | undefined;
|
|
26
31
|
createdAt: ISODateTime;
|
|
27
32
|
updatedAt: ISODateTime;
|
|
28
33
|
/** Optimistic concurrency counter for subscription edits. */
|
|
@@ -79,15 +84,6 @@ export interface IntegrationSecretRecord {
|
|
|
79
84
|
createdAt: ISODateTime;
|
|
80
85
|
updatedAt: ISODateTime;
|
|
81
86
|
}
|
|
82
|
-
/** keyId identifies the wrapping-key generation so export adapters can rewrap or strip a secret
|
|
83
|
-
* explicitly instead of silently transporting it with ordinary content. Ciphertext/nonce are
|
|
84
|
-
* base64 AEAD data; alg identifies the authenticated cipher. */
|
|
85
|
-
export interface SealedSecret {
|
|
86
|
-
keyId: string;
|
|
87
|
-
ciphertext: string;
|
|
88
|
-
nonce: string;
|
|
89
|
-
alg: string;
|
|
90
|
-
}
|
|
91
87
|
/** Async filters operate only on serializable envelope data before signing. They can redact,
|
|
92
88
|
* replace or veto; lower priority runs first rather than relying on registration order. */
|
|
93
89
|
export interface WebhookBeforeDispatchHook {
|