@authhero/cloudflare-adapter 3.3.0 → 3.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/tsconfig.types.tsbuildinfo +1 -1
- package/dist/types/wfp/dispatch-detach.d.ts +31 -0
- package/dist/types/wfp/dispatch-tenant-member-requests.d.ts +23 -0
- package/dist/types/wfp/index.d.ts +2 -0
- package/dist/types/wfp/tenant-app.d.ts +17 -1
- package/dist/types/workflows/detach-operation.d.ts +31 -0
- package/dist/types/workflows/entrypoint.example.d.ts +23 -0
- package/dist/types/workflows/index.d.ts +1 -0
- package/dist/types/workflows/types.d.ts +1 -1
- package/dist/wfp.cjs +1 -1
- package/dist/wfp.d.ts +70 -3
- package/dist/wfp.mjs +251 -69
- package/dist/workflows.cjs +1 -1
- package/dist/workflows.d.ts +34 -4
- package/dist/workflows.mjs +82 -31
- package/package.json +5 -5
package/dist/workflows.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { r as e, t } from "./sync-defaults-errors-CKdx0nzD.mjs";
|
|
2
|
-
import { buildEngineInstanceId as n, createOperationRecorder as r, isTerminalStatus as i,
|
|
2
|
+
import { buildEngineInstanceId as n, createOperationRecorder as r, isTerminalStatus as i, runDetachStep as a, runSyncDefaultsStep as o } from "@authhero/multi-tenancy";
|
|
3
3
|
//#region src/workflows/provision-operation.ts
|
|
4
|
-
var
|
|
4
|
+
var s = {
|
|
5
5
|
retries: {
|
|
6
6
|
limit: 5,
|
|
7
7
|
delay: "5 seconds",
|
|
8
8
|
backoff: "exponential"
|
|
9
9
|
},
|
|
10
10
|
timeout: "2 minutes"
|
|
11
|
-
},
|
|
11
|
+
}, c = {
|
|
12
12
|
retries: {
|
|
13
13
|
limit: 8,
|
|
14
14
|
delay: "10 seconds",
|
|
@@ -16,13 +16,13 @@ var o = {
|
|
|
16
16
|
},
|
|
17
17
|
timeout: "1 minute"
|
|
18
18
|
};
|
|
19
|
-
function
|
|
19
|
+
function l(e) {
|
|
20
20
|
return e instanceof Error ? e.message : String(e);
|
|
21
21
|
}
|
|
22
|
-
async function
|
|
23
|
-
let a = r(e.stores),
|
|
22
|
+
async function u(e, n, i) {
|
|
23
|
+
let a = r(e.stores), o = e.shouldProvision ?? ((e) => e.deployment_type === "wfp"), u = (t) => e.stepConfig?.[t] ?? (t === "verify" ? c : s), d = n.operation_id, f = n.tenant_id, p = await i.do("mark-running", u("mark-running"), async () => {
|
|
24
24
|
let t = await e.tenants.get(f);
|
|
25
|
-
if (!t || !
|
|
25
|
+
if (!t || !o(t)) return await a.appendEvent(d, {
|
|
26
26
|
step: "mark-running",
|
|
27
27
|
outcome: "skipped",
|
|
28
28
|
detail: { reason: t ? "tenant is not WFP-provisioned" : "tenant row missing (rolled back?)" }
|
|
@@ -115,7 +115,7 @@ async function l(e, n, i) {
|
|
|
115
115
|
});
|
|
116
116
|
} catch (t) {
|
|
117
117
|
throw await i.do("mark-failed", u("mark-failed"), async () => {
|
|
118
|
-
let n =
|
|
118
|
+
let n = l(t);
|
|
119
119
|
try {
|
|
120
120
|
await e.tenants.update(f, {
|
|
121
121
|
...m,
|
|
@@ -136,7 +136,7 @@ async function l(e, n, i) {
|
|
|
136
136
|
}
|
|
137
137
|
//#endregion
|
|
138
138
|
//#region src/workflows/sync-defaults-operation.ts
|
|
139
|
-
var
|
|
139
|
+
var d = {
|
|
140
140
|
retries: {
|
|
141
141
|
limit: 3,
|
|
142
142
|
delay: "5 seconds",
|
|
@@ -144,19 +144,19 @@ var u = {
|
|
|
144
144
|
},
|
|
145
145
|
timeout: "2 minutes"
|
|
146
146
|
};
|
|
147
|
-
function
|
|
147
|
+
function f(e) {
|
|
148
148
|
return e instanceof Error ? e.message : String(e);
|
|
149
149
|
}
|
|
150
|
-
async function
|
|
151
|
-
let i = r(e.stores),
|
|
150
|
+
async function p(e, t, n) {
|
|
151
|
+
let i = r(e.stores), a = (t) => e.stepConfig?.[t] ?? d, s = t.operation_id;
|
|
152
152
|
try {
|
|
153
|
-
await n.do("mark-running",
|
|
153
|
+
await n.do("mark-running", a("mark-running"), async () => {
|
|
154
154
|
await i.markRunning(s, "sync-defaults");
|
|
155
|
-
}), await n.do("sync-defaults",
|
|
155
|
+
}), await n.do("sync-defaults", a("sync-defaults"), async () => {
|
|
156
156
|
await i.setCurrentStep(s, "sync-defaults");
|
|
157
157
|
let t = await e.stores.tenantOperations.get(s);
|
|
158
158
|
if (!t) throw Error(`Operation "${s}" not found`);
|
|
159
|
-
let n = await
|
|
159
|
+
let n = await o({
|
|
160
160
|
operation: t,
|
|
161
161
|
syncConfig: e.syncConfig,
|
|
162
162
|
recorder: i
|
|
@@ -166,6 +166,57 @@ async function f(e, t, n) {
|
|
|
166
166
|
outcome: "succeeded",
|
|
167
167
|
detail: n
|
|
168
168
|
});
|
|
169
|
+
}), await n.do("mark-succeeded", a("mark-succeeded"), async () => {
|
|
170
|
+
await i.markSucceeded(s);
|
|
171
|
+
});
|
|
172
|
+
} catch (e) {
|
|
173
|
+
throw await n.do("mark-failed", a("mark-failed"), async () => {
|
|
174
|
+
await i.appendEvent(s, {
|
|
175
|
+
step: "mark-failed",
|
|
176
|
+
outcome: "failed",
|
|
177
|
+
detail: { message: f(e) }
|
|
178
|
+
}), await i.markFailed(s, e);
|
|
179
|
+
}), e;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
//#endregion
|
|
183
|
+
//#region src/workflows/detach-operation.ts
|
|
184
|
+
var m = {
|
|
185
|
+
retries: {
|
|
186
|
+
limit: 3,
|
|
187
|
+
delay: "5 seconds",
|
|
188
|
+
backoff: "exponential"
|
|
189
|
+
},
|
|
190
|
+
timeout: "2 minutes"
|
|
191
|
+
}, h = {
|
|
192
|
+
retries: {
|
|
193
|
+
limit: 0,
|
|
194
|
+
delay: "5 seconds"
|
|
195
|
+
},
|
|
196
|
+
timeout: "5 minutes"
|
|
197
|
+
};
|
|
198
|
+
function g(e) {
|
|
199
|
+
return e instanceof Error ? e.message : String(e);
|
|
200
|
+
}
|
|
201
|
+
async function _(e, t, n) {
|
|
202
|
+
let i = r(e.stores), o = (t) => e.stepConfig?.[t] ?? (t === "detach" ? h : m), s = t.operation_id;
|
|
203
|
+
try {
|
|
204
|
+
await n.do("mark-running", o("mark-running"), async () => {
|
|
205
|
+
await i.markRunning(s, "detach");
|
|
206
|
+
}), await n.do("detach", o("detach"), async () => {
|
|
207
|
+
await i.setCurrentStep(s, "detach");
|
|
208
|
+
let t = await e.stores.tenantOperations.get(s);
|
|
209
|
+
if (!t) throw Error(`Operation "${s}" not found`);
|
|
210
|
+
let n = await a({
|
|
211
|
+
operation: t,
|
|
212
|
+
detachTenant: e.detachTenant,
|
|
213
|
+
recorder: i
|
|
214
|
+
});
|
|
215
|
+
await i.appendEvent(s, {
|
|
216
|
+
step: "detach",
|
|
217
|
+
outcome: "succeeded",
|
|
218
|
+
detail: n
|
|
219
|
+
});
|
|
169
220
|
}), await n.do("mark-succeeded", o("mark-succeeded"), async () => {
|
|
170
221
|
await i.markSucceeded(s);
|
|
171
222
|
});
|
|
@@ -174,20 +225,20 @@ async function f(e, t, n) {
|
|
|
174
225
|
await i.appendEvent(s, {
|
|
175
226
|
step: "mark-failed",
|
|
176
227
|
outcome: "failed",
|
|
177
|
-
detail: { message:
|
|
228
|
+
detail: { message: g(e) }
|
|
178
229
|
}), await i.markFailed(s, e);
|
|
179
230
|
}), e;
|
|
180
231
|
}
|
|
181
232
|
}
|
|
182
233
|
//#endregion
|
|
183
234
|
//#region src/workflows/verify.ts
|
|
184
|
-
var
|
|
235
|
+
var v = class extends Error {
|
|
185
236
|
checks;
|
|
186
237
|
constructor(e, t) {
|
|
187
238
|
super(e), this.name = "TenantProvisionVerificationError", this.checks = t;
|
|
188
239
|
}
|
|
189
240
|
};
|
|
190
|
-
function
|
|
241
|
+
function y(e, t) {
|
|
191
242
|
for (let n of e) for (let e of n.results ?? []) if (!(!e || typeof e != "object")) {
|
|
192
243
|
for (let [n, r] of Object.entries(e)) if (n === t) {
|
|
193
244
|
if (typeof r == "number") return r;
|
|
@@ -196,11 +247,11 @@ function m(e, t) {
|
|
|
196
247
|
}
|
|
197
248
|
return 0;
|
|
198
249
|
}
|
|
199
|
-
function
|
|
250
|
+
function b(t) {
|
|
200
251
|
let n = t.minKeys ?? 1;
|
|
201
252
|
return async (r, i) => {
|
|
202
|
-
let a = await t.client.execD1(r, `SELECT (SELECT COUNT(*) FROM keys) AS key_count, (SELECT COUNT(*) FROM tenants WHERE id = '${e(i)}') AS tenant_count;`), o =
|
|
203
|
-
if (o < n && c.push(`expected at least ${n} signing key(s) in "keys", found ${o}`), s < 1 && c.push(`tenant row "${i}" missing from "tenants"`), c.length > 0) throw new
|
|
253
|
+
let a = await t.client.execD1(r, `SELECT (SELECT COUNT(*) FROM keys) AS key_count, (SELECT COUNT(*) FROM tenants WHERE id = '${e(i)}') AS tenant_count;`), o = y(a, "key_count"), s = y(a, "tenant_count"), c = [];
|
|
254
|
+
if (o < n && c.push(`expected at least ${n} signing key(s) in "keys", found ${o}`), s < 1 && c.push(`tenant row "${i}" missing from "tenants"`), c.length > 0) throw new v(`Tenant D1 verification failed for "${i}": ${c.join("; ")}`, {
|
|
204
255
|
keyCount: o,
|
|
205
256
|
tenantRowCount: s
|
|
206
257
|
});
|
|
@@ -208,15 +259,15 @@ function h(t) {
|
|
|
208
259
|
}
|
|
209
260
|
//#endregion
|
|
210
261
|
//#region src/workflows/executor.ts
|
|
211
|
-
function
|
|
262
|
+
function x(e) {
|
|
212
263
|
let t = e instanceof Error ? e.message : String(e ?? "");
|
|
213
264
|
return /already exists|already been created|duplicate/i.test(t);
|
|
214
265
|
}
|
|
215
|
-
function
|
|
266
|
+
function S(e) {
|
|
216
267
|
return {
|
|
217
268
|
engine: "cloudflare-workflows",
|
|
218
269
|
async start(t) {
|
|
219
|
-
if (t.kind !== "provision" && t.kind !== "sync-defaults") throw Error(`The Cloudflare Workflows executor does not support "${t.kind}" operations yet (it runs provision
|
|
270
|
+
if (t.kind !== "provision" && t.kind !== "sync-defaults" && t.kind !== "detach") throw Error(`The Cloudflare Workflows executor does not support "${t.kind}" operations yet (it runs provision, sync-defaults and detach)`);
|
|
220
271
|
if (!t.tenant_id) throw Error(`${t.kind} operations require a tenant_id`);
|
|
221
272
|
let r = t.engine_instance_id ?? n(t);
|
|
222
273
|
try {
|
|
@@ -229,20 +280,20 @@ function _(e) {
|
|
|
229
280
|
}
|
|
230
281
|
});
|
|
231
282
|
} catch (e) {
|
|
232
|
-
if (!
|
|
283
|
+
if (!x(e)) throw e;
|
|
233
284
|
}
|
|
234
285
|
}
|
|
235
286
|
};
|
|
236
287
|
}
|
|
237
288
|
//#endregion
|
|
238
289
|
//#region src/workflows/types.ts
|
|
239
|
-
var
|
|
290
|
+
var C = "cloudflare-workflows";
|
|
240
291
|
//#endregion
|
|
241
292
|
//#region src/workflows/reconcile.ts
|
|
242
|
-
async function
|
|
293
|
+
async function w(e) {
|
|
243
294
|
let { stores: t, tenants: a, binding: o } = e, s = r(t), c = e.minAgeMs ?? 600 * 1e3, l = e.limit ?? 100, u = new Date(Date.now() - c).toISOString(), { operations: d } = await t.tenantOperations.list({
|
|
244
295
|
status: ["pending", "running"],
|
|
245
|
-
engine:
|
|
296
|
+
engine: C,
|
|
246
297
|
updated_before: u,
|
|
247
298
|
per_page: l
|
|
248
299
|
}), f = {
|
|
@@ -290,7 +341,7 @@ async function y(e) {
|
|
|
290
341
|
return;
|
|
291
342
|
}
|
|
292
343
|
if (u.status === "complete") {
|
|
293
|
-
if (r.kind === "sync-defaults") {
|
|
344
|
+
if (r.kind === "sync-defaults" || r.kind === "detach") {
|
|
294
345
|
f.markedSucceeded++, await s.appendEvent(r.id, {
|
|
295
346
|
step: r.current_step ?? "reconcile",
|
|
296
347
|
outcome: "reconciled",
|
|
@@ -310,7 +361,7 @@ async function y(e) {
|
|
|
310
361
|
}
|
|
311
362
|
//#endregion
|
|
312
363
|
//#region src/workflows/enqueue-hook.ts
|
|
313
|
-
function
|
|
364
|
+
function T(e) {
|
|
314
365
|
let t = e.shouldProvision ?? ((e) => e.deployment_type === "wfp");
|
|
315
366
|
return {
|
|
316
367
|
async onProvision(n, r) {
|
|
@@ -329,4 +380,4 @@ function b(e) {
|
|
|
329
380
|
};
|
|
330
381
|
}
|
|
331
382
|
//#endregion
|
|
332
|
-
export {
|
|
383
|
+
export { C as TENANT_OPERATION_ENGINE, v as TenantProvisionVerificationError, S as createCloudflareWorkflowsExecutor, b as createProvisionVerifier, T as createWfpWorkflowProvisioningHook, w as reconcileTenantOperations, _ as runDetachOperation, u as runProvisionOperation, p as runSyncDefaultsOperation };
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"type": "git",
|
|
12
12
|
"url": "https://github.com/sesamyab/authhero"
|
|
13
13
|
},
|
|
14
|
-
"version": "3.
|
|
14
|
+
"version": "3.4.0",
|
|
15
15
|
"files": [
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
"typescript": "^5.9.3",
|
|
48
48
|
"vite": "^8.0.14",
|
|
49
49
|
"vitest": "^4.1.7",
|
|
50
|
-
"@authhero/multi-tenancy": "15.
|
|
51
|
-
"authhero": "9.
|
|
50
|
+
"@authhero/multi-tenancy": "15.4.0",
|
|
51
|
+
"authhero": "9.27.0"
|
|
52
52
|
},
|
|
53
53
|
"peerDependencies": {
|
|
54
54
|
"@authhero/multi-tenancy": "^14.0.0",
|
|
@@ -67,8 +67,8 @@
|
|
|
67
67
|
"dependencies": {
|
|
68
68
|
"nanoid": "^5.1.11",
|
|
69
69
|
"wretch": "^3.0.8",
|
|
70
|
-
"@authhero/
|
|
71
|
-
"@authhero/adapter
|
|
70
|
+
"@authhero/adapter-interfaces": "4.24.0",
|
|
71
|
+
"@authhero/kysely-adapter": "12.18.0"
|
|
72
72
|
},
|
|
73
73
|
"license": "AGPL-3.0-only",
|
|
74
74
|
"scripts": {
|