@sanoma-ai/workflows 0.9.1 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +167 -50
- package/dist/apply-steps.js +5 -2
- package/dist/apply-steps.js.map +1 -1
- package/dist/apply.d.ts +3 -0
- package/dist/apply.js +27 -13
- package/dist/apply.js.map +1 -1
- package/dist/approvals.d.ts +1 -0
- package/dist/approvals.js +6 -1
- package/dist/approvals.js.map +1 -1
- package/dist/apps.d.ts +7 -24
- package/dist/apps.js +51 -67
- package/dist/apps.js.map +1 -1
- package/dist/ast.d.ts +9 -7
- package/dist/ast.js +2 -0
- package/dist/ast.js.map +1 -1
- package/dist/authentication.d.ts +24 -0
- package/dist/authentication.js +68 -0
- package/dist/authentication.js.map +1 -0
- package/dist/call-workflow.d.ts +5 -0
- package/dist/call-workflow.js +4 -3
- package/dist/call-workflow.js.map +1 -1
- package/dist/call.d.ts +3 -2
- package/dist/call.js +34 -7
- package/dist/call.js.map +1 -1
- package/dist/cedar.js +14 -1
- package/dist/cedar.js.map +1 -1
- package/dist/change-steps.js +7 -5
- package/dist/change-steps.js.map +1 -1
- package/dist/change.d.ts +7 -0
- package/dist/change.js +7 -0
- package/dist/change.js.map +1 -1
- package/dist/client.d.ts +10 -6
- package/dist/client.js +96 -43
- package/dist/client.js.map +1 -1
- package/dist/collection.d.ts +7 -0
- package/dist/collection.js +5 -2
- package/dist/collection.js.map +1 -1
- package/dist/config.d.ts +9 -0
- package/dist/config.js +45 -9
- package/dist/config.js.map +1 -1
- package/dist/connection.d.ts +168 -0
- package/dist/connection.js +327 -0
- package/dist/connection.js.map +1 -0
- package/dist/credentials.d.ts +7 -53
- package/dist/credentials.js +84 -247
- package/dist/credentials.js.map +1 -1
- package/dist/db.js +21 -2
- package/dist/db.js.map +1 -1
- package/dist/define.d.ts +9 -2
- package/dist/define.js.map +1 -1
- package/dist/definitions.d.ts +20 -0
- package/dist/definitions.js +16 -0
- package/dist/definitions.js.map +1 -0
- package/dist/deployment-key.d.ts +2 -0
- package/dist/deployment-key.js +22 -0
- package/dist/deployment-key.js.map +1 -0
- package/dist/describe.d.ts +9 -177
- package/dist/describe.js +71 -34
- package/dist/describe.js.map +1 -1
- package/dist/description.d.ts +532 -0
- package/dist/description.js +381 -0
- package/dist/description.js.map +1 -0
- package/dist/direct.js +3 -0
- package/dist/direct.js.map +1 -1
- package/dist/drift.d.ts +1 -1
- package/dist/drift.js +1 -1
- package/dist/drift.js.map +1 -1
- package/dist/env.d.ts +2 -0
- package/dist/env.js +2 -2
- package/dist/env.js.map +1 -1
- package/dist/index.d.ts +10 -2
- package/dist/index.js +10 -2
- package/dist/index.js.map +1 -1
- package/dist/ledger.d.ts +2 -0
- package/dist/ledger.js +1 -1
- package/dist/ledger.js.map +1 -1
- package/dist/lint.d.ts +0 -9
- package/dist/lint.js +1 -16
- package/dist/lint.js.map +1 -1
- package/dist/load.d.ts +74 -0
- package/dist/load.js +357 -0
- package/dist/load.js.map +1 -0
- package/dist/lockfile.d.ts +2 -0
- package/dist/lockfile.js +8 -3
- package/dist/lockfile.js.map +1 -1
- package/dist/op.d.ts +10 -1
- package/dist/op.js +1 -1
- package/dist/op.js.map +1 -1
- package/dist/outline.js +13 -4
- package/dist/outline.js.map +1 -1
- package/dist/paths.d.ts +18 -0
- package/dist/paths.js +21 -3
- package/dist/paths.js.map +1 -1
- package/dist/plugin.d.ts +0 -11
- package/dist/plugin.js +3 -18
- package/dist/plugin.js.map +1 -1
- package/dist/policy.d.ts +2 -0
- package/dist/policy.js.map +1 -1
- package/dist/resource.d.ts +10 -4
- package/dist/resource.js +11 -4
- package/dist/resource.js.map +1 -1
- package/dist/resources.d.ts +33 -76
- package/dist/resources.js +219 -227
- package/dist/resources.js.map +1 -1
- package/dist/run.d.ts +2 -0
- package/dist/run.js.map +1 -1
- package/dist/sandbox.d.ts +1 -1
- package/dist/sandbox.js +5 -2
- package/dist/sandbox.js.map +1 -1
- package/dist/scenarios.js +7 -1
- package/dist/scenarios.js.map +1 -1
- package/dist/schema.js +8 -0
- package/dist/schema.js.map +1 -1
- package/dist/secret-store-check.d.ts +11 -0
- package/dist/secret-store-check.js +76 -0
- package/dist/secret-store-check.js.map +1 -0
- package/dist/secret-store.d.ts +106 -0
- package/dist/secret-store.js +228 -0
- package/dist/secret-store.js.map +1 -0
- package/dist/shared.d.ts +17 -11
- package/dist/shared.js +34 -7
- package/dist/shared.js.map +1 -1
- package/dist/sites.d.ts +4 -93
- package/dist/sites.js +61 -84
- package/dist/sites.js.map +1 -1
- package/dist/version.d.ts +2 -1
- package/dist/version.js +2 -1
- package/dist/version.js.map +1 -1
- package/dist/wakeup-driver.js +15 -6
- package/dist/wakeup-driver.js.map +1 -1
- package/dist/worker.js +12 -8
- package/dist/worker.js.map +1 -1
- package/dist/writer.d.ts +53 -14
- package/dist/writer.js +113 -43
- package/dist/writer.js.map +1 -1
- package/oxlint.json +0 -5
- package/package.json +5 -1
- package/src/apply-steps.ts +5 -2
- package/src/apply.ts +54 -21
- package/src/approvals.ts +7 -1
- package/src/apps.ts +54 -85
- package/src/ast.ts +6 -6
- package/src/authentication.ts +74 -0
- package/src/call-workflow.ts +5 -4
- package/src/call.ts +53 -9
- package/src/cedar.ts +14 -1
- package/src/change-steps.ts +7 -4
- package/src/change.ts +10 -0
- package/src/client.ts +108 -41
- package/src/collection.ts +10 -2
- package/src/config.ts +62 -8
- package/src/connection.ts +446 -0
- package/src/credentials.ts +94 -281
- package/src/db.ts +21 -2
- package/src/define.ts +7 -2
- package/src/definitions.ts +31 -0
- package/src/deployment-key.ts +23 -0
- package/src/describe.ts +102 -230
- package/src/description.ts +426 -0
- package/src/direct.ts +3 -0
- package/src/drift.ts +10 -2
- package/src/env.ts +4 -2
- package/src/index.ts +42 -1
- package/src/ledger.ts +3 -1
- package/src/lint.ts +1 -16
- package/src/load.ts +437 -0
- package/src/lockfile.ts +10 -3
- package/src/op.ts +10 -1
- package/src/outline.ts +18 -5
- package/src/paths.ts +24 -2
- package/src/plugin.ts +3 -24
- package/src/policy.ts +2 -0
- package/src/resource.ts +24 -6
- package/src/resources.ts +246 -301
- package/src/run.ts +2 -0
- package/src/sandbox.ts +6 -2
- package/src/scenarios.ts +7 -1
- package/src/schema.ts +10 -0
- package/src/secret-store-check.ts +93 -0
- package/src/secret-store.ts +314 -0
- package/src/shared.ts +35 -10
- package/src/sites.ts +70 -180
- package/src/version.ts +2 -1
- package/src/wakeup-driver.ts +22 -6
- package/src/worker.ts +12 -8
- package/src/writer.ts +145 -56
- package/dist/datafile.d.ts +0 -97
- package/dist/datafile.js +0 -479
- package/dist/datafile.js.map +0 -1
- package/src/datafile.ts +0 -601
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { checkAuthenticationStore, defineAuthentication } from "./authentication.js";
|
|
4
|
+
import { setupOf, VENDOR, defineConnector, defineDriver } from "./op.js";
|
|
5
|
+
import { isSecret } from "./secret.js";
|
|
6
|
+
import { SanomaError } from "./errors.js";
|
|
7
|
+
const idPart = /^[a-z][a-z0-9-]{0,63}$/;
|
|
8
|
+
function refuse(message) {
|
|
9
|
+
throw new SanomaError("invalid_input", message);
|
|
10
|
+
}
|
|
11
|
+
export const connectionRefSchema = z.object({
|
|
12
|
+
$connection: z.string().min(1),
|
|
13
|
+
vendor: z.string().min(1),
|
|
14
|
+
revision: z.string().optional(),
|
|
15
|
+
});
|
|
16
|
+
const snapshotSchema = z.object({
|
|
17
|
+
id: z.string(),
|
|
18
|
+
vendor: z.string(),
|
|
19
|
+
method: z.string(),
|
|
20
|
+
account: z.string(),
|
|
21
|
+
scopes: z.array(z.string()),
|
|
22
|
+
revision: z.string(),
|
|
23
|
+
definition: z.string(),
|
|
24
|
+
credentials: z.object({ $secret: z.string() }).optional(),
|
|
25
|
+
});
|
|
26
|
+
export function defineConnection(connector, options) {
|
|
27
|
+
if (!idPart.test(options.name))
|
|
28
|
+
refuse("A connection needs a stable lowercase name");
|
|
29
|
+
const vendor = connector[VENDOR].id;
|
|
30
|
+
const auth = setupOf(connector).authentication?.[options.method];
|
|
31
|
+
if (!auth)
|
|
32
|
+
refuse("The connector does not declare this authentication method");
|
|
33
|
+
if (auth.kind === "workload-identity" ? options.credentials !== undefined : !isSecret(options.credentials))
|
|
34
|
+
refuse("Credentials must match the authentication method");
|
|
35
|
+
return Object.freeze({
|
|
36
|
+
$connection: `${vendor}/${options.name}`,
|
|
37
|
+
vendor,
|
|
38
|
+
name: options.name,
|
|
39
|
+
method: options.method,
|
|
40
|
+
...(options.credentials && { credentials: Object.freeze({ $secret: options.credentials.$secret }) }),
|
|
41
|
+
scopes: Object.freeze([...(options.scopes ?? [])]),
|
|
42
|
+
...(options.account && { account: options.account }),
|
|
43
|
+
default: options.default ?? false,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
export function defineConnectionRule(connector, options) {
|
|
47
|
+
if (!idPart.test(options.name) ||
|
|
48
|
+
!options.createBy.length ||
|
|
49
|
+
options.createBy.some((x) => typeof x === "string" ? !x.trim() : !x || typeof x.group !== "string" || !x.group.trim()))
|
|
50
|
+
refuse("A connection rule needs a name and allowed creators");
|
|
51
|
+
if (!setupOf(connector).authentication?.[options.method])
|
|
52
|
+
refuse("The connector does not declare this authentication method");
|
|
53
|
+
return Object.freeze({
|
|
54
|
+
name: options.name,
|
|
55
|
+
vendor: connector[VENDOR].id,
|
|
56
|
+
method: options.method,
|
|
57
|
+
createBy: Object.freeze(options.createBy.map((x) => (typeof x === "string" ? x : Object.freeze({ ...x })))),
|
|
58
|
+
scopes: Object.freeze([...(options.scopes ?? [])]),
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/** Reconstitutes a dynamic reference; authority is checked from the persisted record on every call. */
|
|
62
|
+
export function connectionRef(rule, id) {
|
|
63
|
+
if (!id.startsWith(`${rule.vendor}/${rule.name}/`))
|
|
64
|
+
refuse("The connection is outside this rule");
|
|
65
|
+
return Object.freeze({ $connection: id, vendor: rule.vendor });
|
|
66
|
+
}
|
|
67
|
+
export function connectionCatalog(connectors, definitions = [], rules = []) {
|
|
68
|
+
const methods = new Map();
|
|
69
|
+
for (const connector of connectors) {
|
|
70
|
+
const vendor = connector[VENDOR].id;
|
|
71
|
+
const entries = methods.get(vendor) ?? {};
|
|
72
|
+
for (const [name, method] of Object.entries(setupOf(connector).authentication ?? {})) {
|
|
73
|
+
if (entries[name] && entries[name] !== method)
|
|
74
|
+
refuse("Conflicting authentication methods for a connector");
|
|
75
|
+
defineAuthentication(method);
|
|
76
|
+
entries[name] = method;
|
|
77
|
+
}
|
|
78
|
+
methods.set(vendor, entries);
|
|
79
|
+
}
|
|
80
|
+
const defined = new Map();
|
|
81
|
+
const defaults = new Set();
|
|
82
|
+
for (const d of definitions) {
|
|
83
|
+
if (!d ||
|
|
84
|
+
!idPart.test(d.name) ||
|
|
85
|
+
d.$connection !== `${d.vendor}/${d.name}` ||
|
|
86
|
+
!methods.get(d.vendor)?.[d.method] ||
|
|
87
|
+
defined.has(d.$connection))
|
|
88
|
+
refuse("Invalid or duplicate connection declaration");
|
|
89
|
+
const auth = methods.get(d.vendor)[d.method];
|
|
90
|
+
if (auth.kind === "workload-identity" ? d.credentials !== undefined : !isSecret(d.credentials))
|
|
91
|
+
refuse("Credentials must match the authentication method");
|
|
92
|
+
if (d.default && defaults.has(d.vendor))
|
|
93
|
+
refuse("A connector can have only one explicit default connection");
|
|
94
|
+
if (d.default)
|
|
95
|
+
defaults.add(d.vendor);
|
|
96
|
+
defined.set(d.$connection, d);
|
|
97
|
+
}
|
|
98
|
+
const dynamic = new Map();
|
|
99
|
+
for (const r of rules) {
|
|
100
|
+
const id = `${r.vendor}/${r.name}`;
|
|
101
|
+
if (!idPart.test(r.name) ||
|
|
102
|
+
!methods.get(r.vendor)?.[r.method] ||
|
|
103
|
+
dynamic.has(id) ||
|
|
104
|
+
defined.has(id) ||
|
|
105
|
+
!r.createBy.length)
|
|
106
|
+
refuse("Invalid or duplicate connection rule");
|
|
107
|
+
dynamic.set(id, r);
|
|
108
|
+
}
|
|
109
|
+
return { definitions: defined, rules: dynamic, methods };
|
|
110
|
+
}
|
|
111
|
+
const snapshot = (r) => ({
|
|
112
|
+
id: r.id,
|
|
113
|
+
vendor: r.vendor,
|
|
114
|
+
method: r.method,
|
|
115
|
+
account: r.account,
|
|
116
|
+
scopes: r.scopes,
|
|
117
|
+
revision: r.revision,
|
|
118
|
+
definition: r.definition,
|
|
119
|
+
...(r.credential && { credentials: { $secret: r.credential } }),
|
|
120
|
+
});
|
|
121
|
+
const fingerprint = (declaration, method) => createHash("sha256")
|
|
122
|
+
.update(JSON.stringify({ declaration, kind: method.kind, version: method.version, storage: method.storage }))
|
|
123
|
+
.digest("hex");
|
|
124
|
+
/** Persists account metadata only. Secret values are handled outside these operations. */
|
|
125
|
+
export class ConnectionRegistry {
|
|
126
|
+
catalog;
|
|
127
|
+
db;
|
|
128
|
+
secrets;
|
|
129
|
+
constructor(catalog, db, secrets) {
|
|
130
|
+
this.catalog = catalog;
|
|
131
|
+
this.db = db;
|
|
132
|
+
this.secrets = secrets;
|
|
133
|
+
}
|
|
134
|
+
/** A direct metadata write uses the same transaction as its default ledger record. */
|
|
135
|
+
onDatabase(db) {
|
|
136
|
+
return new ConnectionRegistry(this.catalog, async () => db, this.secrets);
|
|
137
|
+
}
|
|
138
|
+
bindingFingerprint(declaration, method, credential) {
|
|
139
|
+
const name = credential ?? ("credentials" in declaration ? declaration.credentials?.$secret : undefined);
|
|
140
|
+
const location = name ? this.secrets?.location(name) : undefined;
|
|
141
|
+
return createHash("sha256")
|
|
142
|
+
.update(JSON.stringify({ contract: fingerprint(declaration, method), location }))
|
|
143
|
+
.digest("hex");
|
|
144
|
+
}
|
|
145
|
+
checkStore(method, credential) {
|
|
146
|
+
if (!this.secrets || !credential)
|
|
147
|
+
return;
|
|
148
|
+
const location = this.secrets.location(credential);
|
|
149
|
+
const caps = location.namespace === ""
|
|
150
|
+
? {
|
|
151
|
+
writable: false,
|
|
152
|
+
maxBytes: Number.MAX_SAFE_INTEGER,
|
|
153
|
+
conditionalWrites: "none",
|
|
154
|
+
deletion: "unsupported",
|
|
155
|
+
changeDetection: "read",
|
|
156
|
+
}
|
|
157
|
+
: this.secrets.store.capabilities;
|
|
158
|
+
checkAuthenticationStore(method, caps, location.management);
|
|
159
|
+
}
|
|
160
|
+
async row(id) {
|
|
161
|
+
return (await (await this.db()).query("SELECT * FROM sanoma_connections WHERE id=$1", [id])).rows[0];
|
|
162
|
+
}
|
|
163
|
+
async select(vendor, ref, actor) {
|
|
164
|
+
if (!ref) {
|
|
165
|
+
const defaults = [...this.catalog.definitions.values()].filter((d) => d.vendor === vendor && d.default);
|
|
166
|
+
if (defaults[0])
|
|
167
|
+
ref = defaults[0];
|
|
168
|
+
else if (Object.keys(this.catalog.methods.get(vendor) ?? {}).length ||
|
|
169
|
+
[...this.catalog.definitions.values()].some((d) => d.vendor === vendor))
|
|
170
|
+
refuse("Select a named connection or declare an explicit default");
|
|
171
|
+
else
|
|
172
|
+
return undefined; // Operations without an authentication method need no connection.
|
|
173
|
+
}
|
|
174
|
+
if (!ref || ref.vendor !== vendor)
|
|
175
|
+
refuse("The selected connection belongs to another connector");
|
|
176
|
+
const row = await this.row(ref.$connection);
|
|
177
|
+
if (!row || row.vendor !== vendor || row.status !== "connected")
|
|
178
|
+
refuse("The connection is missing or disconnected");
|
|
179
|
+
if (ref.revision !== undefined && ref.revision !== row.revision)
|
|
180
|
+
refuse("The connection changed after authorization; start a new call");
|
|
181
|
+
const declaration = row.rule ? this.catalog.rules.get(row.rule) : this.catalog.definitions.get(row.id);
|
|
182
|
+
if (!declaration || declaration.vendor !== vendor || declaration.method !== row.method)
|
|
183
|
+
refuse("The connection is not declared");
|
|
184
|
+
if (row.rule && row.owner !== actor)
|
|
185
|
+
throw new SanomaError("policy_denied", "The connection belongs to another principal");
|
|
186
|
+
const method = this.catalog.methods.get(vendor)?.[row.method];
|
|
187
|
+
if (!method || row.definition !== this.bindingFingerprint(declaration, method, row.credential))
|
|
188
|
+
refuse("The connection declaration changed; reconnect before use");
|
|
189
|
+
this.checkStore(method, row.credential);
|
|
190
|
+
return snapshot(row);
|
|
191
|
+
}
|
|
192
|
+
async assertCurrent(selected, actor) {
|
|
193
|
+
if (!selected)
|
|
194
|
+
return;
|
|
195
|
+
const current = await this.select(selected.vendor, { vendor: selected.vendor, $connection: selected.id }, actor);
|
|
196
|
+
if (!current || current.revision !== selected.revision || current.definition !== selected.definition)
|
|
197
|
+
refuse("The connection changed after authorization; start a new call");
|
|
198
|
+
}
|
|
199
|
+
async bind(ref, account, scopes, expectedRevision, actor) {
|
|
200
|
+
const declaration = this.catalog.definitions.get(ref.$connection);
|
|
201
|
+
if (!declaration || declaration.vendor !== ref.vendor)
|
|
202
|
+
refuse("The connection is not declared");
|
|
203
|
+
if (declaration.account && account !== declaration.account)
|
|
204
|
+
refuse("The account does not match the connection requirement");
|
|
205
|
+
if (declaration.scopes.some((s) => !scopes.includes(s)))
|
|
206
|
+
refuse("The account has not granted the required scopes");
|
|
207
|
+
const method = this.catalog.methods.get(ref.vendor)[declaration.method];
|
|
208
|
+
const row = {
|
|
209
|
+
id: ref.$connection,
|
|
210
|
+
vendor: ref.vendor,
|
|
211
|
+
method: declaration.method,
|
|
212
|
+
owner: null,
|
|
213
|
+
rule: null,
|
|
214
|
+
account,
|
|
215
|
+
scopes,
|
|
216
|
+
revision: randomUUID(),
|
|
217
|
+
definition: this.bindingFingerprint(declaration, method),
|
|
218
|
+
credential: declaration.credentials?.$secret ?? null,
|
|
219
|
+
status: "connected",
|
|
220
|
+
};
|
|
221
|
+
this.checkStore(method, row.credential);
|
|
222
|
+
await this.save(row, expectedRevision, actor);
|
|
223
|
+
return snapshot(row);
|
|
224
|
+
}
|
|
225
|
+
async create(ruleId, account, scopes, actor) {
|
|
226
|
+
const rule = this.catalog.rules.get(ruleId);
|
|
227
|
+
const person = typeof actor === "string" ? { id: actor } : actor;
|
|
228
|
+
if (!rule ||
|
|
229
|
+
!rule.createBy.some((by) => (typeof by === "string" ? by === person.id : person.groups?.includes(by.group))))
|
|
230
|
+
throw new SanomaError("policy_denied", "This principal cannot create connections under this rule");
|
|
231
|
+
if (rule.scopes.some((s) => !scopes.includes(s)))
|
|
232
|
+
refuse("The account has not granted the required scopes");
|
|
233
|
+
const method = this.catalog.methods.get(rule.vendor)[rule.method];
|
|
234
|
+
const id = `${ruleId}/${randomUUID()}`;
|
|
235
|
+
const credential = method.kind === "workload-identity" ? null : `CONNECTION_${randomUUID().replaceAll("-", "").toUpperCase()}`;
|
|
236
|
+
const row = {
|
|
237
|
+
id,
|
|
238
|
+
vendor: rule.vendor,
|
|
239
|
+
method: rule.method,
|
|
240
|
+
owner: person.id,
|
|
241
|
+
rule: ruleId,
|
|
242
|
+
account,
|
|
243
|
+
scopes,
|
|
244
|
+
revision: randomUUID(),
|
|
245
|
+
definition: this.bindingFingerprint(rule, method, credential),
|
|
246
|
+
credential,
|
|
247
|
+
status: "connected",
|
|
248
|
+
};
|
|
249
|
+
this.checkStore(method, row.credential);
|
|
250
|
+
await this.save(row, null, person.id);
|
|
251
|
+
return snapshot(row);
|
|
252
|
+
}
|
|
253
|
+
async disconnect(ref, expectedRevision, actor) {
|
|
254
|
+
const row = await this.row(ref.$connection);
|
|
255
|
+
if (!row ||
|
|
256
|
+
row.vendor !== ref.vendor ||
|
|
257
|
+
(row.rule ? !this.catalog.rules.has(row.rule) : !this.catalog.definitions.has(row.id)))
|
|
258
|
+
refuse("The connection is not declared");
|
|
259
|
+
if (row.rule && row.owner !== actor)
|
|
260
|
+
throw new SanomaError("policy_denied", "The connection belongs to another principal");
|
|
261
|
+
const revision = randomUUID();
|
|
262
|
+
const changed = await (await this.db()).query("UPDATE sanoma_connections SET status='disconnected',revision=$2,updated_by=$3,updated_at=now() WHERE id=$1 AND revision=$4 RETURNING id", [row.id, revision, actor, expectedRevision]);
|
|
263
|
+
if (!changed.rowCount)
|
|
264
|
+
refuse("The connection changed; reload before disconnecting it");
|
|
265
|
+
return { id: row.id, revision, status: "disconnected" };
|
|
266
|
+
}
|
|
267
|
+
async save(row, expected, actor) {
|
|
268
|
+
const values = [
|
|
269
|
+
row.id,
|
|
270
|
+
row.vendor,
|
|
271
|
+
row.method,
|
|
272
|
+
row.owner,
|
|
273
|
+
row.rule,
|
|
274
|
+
row.account,
|
|
275
|
+
JSON.stringify(row.scopes),
|
|
276
|
+
row.revision,
|
|
277
|
+
row.definition,
|
|
278
|
+
row.credential,
|
|
279
|
+
actor,
|
|
280
|
+
];
|
|
281
|
+
const query = expected === null
|
|
282
|
+
? "INSERT INTO sanoma_connections (id,vendor,method,owner,rule,account,scopes,revision,definition,credential,updated_by) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11) ON CONFLICT(id) DO NOTHING RETURNING id"
|
|
283
|
+
: "UPDATE sanoma_connections SET vendor=$2,method=$3,owner=$4,rule=$5,account=$6,scopes=$7,revision=$8,definition=$9,credential=$10,updated_by=$11,updated_at=now(),status='connected' WHERE id=$1 AND revision=$12 RETURNING id";
|
|
284
|
+
const result = await (await this.db()).query(query, [...values, ...(expected === null ? [] : [expected])]);
|
|
285
|
+
if (!result.rowCount)
|
|
286
|
+
refuse("The connection changed; reload before binding it");
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
/** Metadata mutations are access operations, so they are policy-reviewed and audited like other effects. */
|
|
290
|
+
export const connectionOps = defineConnector("sanoma", {
|
|
291
|
+
connection: {
|
|
292
|
+
disconnect: {
|
|
293
|
+
effect: "access",
|
|
294
|
+
input: z.object({ connection: connectionRefSchema, expectedRevision: z.string() }),
|
|
295
|
+
output: z.object({ id: z.string(), revision: z.string(), status: z.literal("disconnected") }),
|
|
296
|
+
target: (input) => input.connection.$connection,
|
|
297
|
+
},
|
|
298
|
+
bind: {
|
|
299
|
+
effect: "access",
|
|
300
|
+
input: z.object({
|
|
301
|
+
connection: connectionRefSchema,
|
|
302
|
+
account: z.string().min(1),
|
|
303
|
+
scopes: z.array(z.string()),
|
|
304
|
+
expectedRevision: z.string().nullable(),
|
|
305
|
+
}),
|
|
306
|
+
output: snapshotSchema,
|
|
307
|
+
target: (input) => input.connection.$connection,
|
|
308
|
+
},
|
|
309
|
+
create: {
|
|
310
|
+
effect: "access",
|
|
311
|
+
input: z.object({ rule: z.string(), account: z.string().min(1), scopes: z.array(z.string()) }),
|
|
312
|
+
output: snapshotSchema,
|
|
313
|
+
target: (input) => input.rule,
|
|
314
|
+
},
|
|
315
|
+
},
|
|
316
|
+
});
|
|
317
|
+
const actor = (call) => call.principal ?? refuse("Connection mutation needs an authenticated principal");
|
|
318
|
+
export function connectionDriver(registry) {
|
|
319
|
+
return defineDriver(connectionOps, {
|
|
320
|
+
connection: {
|
|
321
|
+
disconnect: (input, call) => registry.disconnect(input.connection, input.expectedRevision, actor(call).id),
|
|
322
|
+
bind: (input, call) => registry.bind(input.connection, input.account, input.scopes, input.expectedRevision, actor(call).id),
|
|
323
|
+
create: (input, call) => registry.create(input.rule, input.account, input.scopes, actor(call)),
|
|
324
|
+
},
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
//# sourceMappingURL=connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,wBAAwB,EAAE,oBAAoB,EAAuB,MAAM,qBAAqB,CAAC;AAC1G,OAAO,EAAkB,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,YAAY,EAAoB,MAAM,SAAS,CAAC;AAC3G,OAAO,EAAE,QAAQ,EAAe,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAoC1C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|
|
1
1
|
import { type Db } from "./db.ts";
|
|
2
|
-
import type
|
|
3
|
-
import type { Secrets } from "./secret.ts";
|
|
4
|
-
/** The variable holding the key the stored values are encrypted with: 32 bytes, base64. */
|
|
2
|
+
import { SecretAccess, type SecretConfiguration, type SecretStore } from "./secret-store.ts";
|
|
5
3
|
export declare const SECRETS_KEY = "SANOMA_SECRETS_KEY";
|
|
6
|
-
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*/
|
|
10
|
-
export declare function
|
|
11
|
-
|
|
12
|
-
export declare function decrypt(name: string, stored: string): string;
|
|
13
|
-
/** The stored rows of these names, values included: for loading into an environment or checking, never for showing. */
|
|
14
|
-
export declare function storedCredentials(db: Db, names: readonly string[]): Promise<Map<string, {
|
|
15
|
-
value: string;
|
|
16
|
-
setBy: string;
|
|
17
|
-
setAt: string;
|
|
18
|
-
}>>;
|
|
19
|
-
/** Upserts the value and announces it, in one statement, so a worker never hears of a change it cannot read. */
|
|
20
|
-
export declare function storeCredential(db: Db, { name, value, setBy }: {
|
|
21
|
-
name: string;
|
|
22
|
-
value: string;
|
|
23
|
-
setBy: string;
|
|
24
|
-
}): Promise<void>;
|
|
25
|
-
/**
|
|
26
|
-
* The stored value of `name`; when there is none, `make()`'s, stored first and announced. Of two
|
|
27
|
-
* at once, the first stored wins, and both return it.
|
|
28
|
-
*/
|
|
29
|
-
export declare function ensureCredential(db: Db, { name, make, setBy }: {
|
|
30
|
-
name: string;
|
|
31
|
-
make: () => string;
|
|
32
|
-
setBy: string;
|
|
33
|
-
}): Promise<string>;
|
|
34
|
-
/**
|
|
35
|
-
* The secrets store a live driver is given (`CallContext.secrets`): a variable the environment
|
|
36
|
-
* sets wins, as it does for a driver's `env`; else the stored value. `ensure` stores what it
|
|
37
|
-
* makes as `setBy`.
|
|
38
|
-
*/
|
|
39
|
-
export declare function storedSecrets(db: () => Promise<Db>, setBy: string): Secrets;
|
|
40
|
-
/** Deletes the row, announcing it when there was one. */
|
|
41
|
-
export declare function deleteCredential(db: Db, name: string): Promise<void>;
|
|
42
|
-
/** Stops a worker's credentials listener. */
|
|
43
|
-
export interface CredentialsWatch {
|
|
44
|
-
close(): Promise<void>;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Loads the stored values of the declared variables the environment does not set into
|
|
48
|
-
* `process.env`, then keeps them current: on each change announced, and on reconnecting, it
|
|
49
|
-
* loads them again, so a value set replaces the one before and a value cleared is deleted. A
|
|
50
|
-
* name the environment set when this started is never touched, and the names it did set are
|
|
51
|
-
* deleted on `close`. Logs, per vendor, how many variables each load changed, never a value, and
|
|
52
|
-
* warns of a reloaded value its schema refuses. A listener that drops reconnects, waiting longer
|
|
53
|
-
* after each failure, up to 30 s, until it is closed. With no such variable, it connects to nothing.
|
|
54
|
-
*/
|
|
55
|
-
export declare function watchCredentials(databaseUrl: string, drivers: ReadonlyMap<string, Driver>): Promise<CredentialsWatch>;
|
|
4
|
+
/** AES-256-GCM authenticated to the complete namespace/path identity. No plaintext format. */
|
|
5
|
+
export declare function encrypt(identity: string, value: string): string;
|
|
6
|
+
export declare function decrypt(identity: string, stored: string): string;
|
|
7
|
+
/** One company's database connection supplies authority; namespace separates deployments within it. */
|
|
8
|
+
export declare function postgresSecretStore(db: () => Promise<Db>): SecretStore;
|
|
9
|
+
export declare const configuredSecrets: (config: SecretConfiguration, db: () => Promise<Db>) => SecretAccess;
|