@authhero/cloudflare-adapter 3.2.5 → 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/cloudflare-adapter.cjs +1 -1
- package/dist/cloudflare-adapter.mjs +1 -1
- package/dist/{sync-defaults-errors-BlLZh6Gt.mjs → sync-defaults-errors-CKdx0nzD.mjs} +4 -2
- package/dist/{sync-defaults-errors-Htp1NWTq.js → sync-defaults-errors-pnzkP88r.js} +1 -1
- package/dist/tsconfig.types.tsbuildinfo +1 -1
- package/dist/types/wfp/dispatch-detach.d.ts +31 -0
- package/dist/types/wfp/dispatch-sync-config.d.ts +37 -0
- package/dist/types/wfp/dispatch-tenant-member-requests.d.ts +23 -0
- package/dist/types/wfp/index.d.ts +3 -0
- package/dist/types/wfp/tenant-app.d.ts +26 -1
- package/dist/types/workflows/detach-operation.d.ts +31 -0
- package/dist/types/workflows/entrypoint.example.d.ts +63 -3
- package/dist/types/workflows/index.d.ts +2 -0
- package/dist/types/workflows/sync-defaults-operation.d.ts +28 -0
- package/dist/types/workflows/types.d.ts +2 -2
- package/dist/wfp.cjs +1 -1
- package/dist/wfp.d.ts +114 -3
- package/dist/wfp.mjs +303 -61
- package/dist/workflows.cjs +1 -1
- package/dist/workflows.d.ts +62 -5
- package/dist/workflows.mjs +145 -41
- package/package.json +5 -5
package/dist/workflows.mjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { r as e, t } from "./sync-defaults-errors-
|
|
2
|
-
import { buildEngineInstanceId as n, createOperationRecorder as r, isTerminalStatus as i } from "@authhero/multi-tenancy";
|
|
1
|
+
import { r as e, t } from "./sync-defaults-errors-CKdx0nzD.mjs";
|
|
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,23 +16,23 @@ var a = {
|
|
|
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
|
|
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?)" }
|
|
29
|
-
}), await
|
|
29
|
+
}), await a.markSucceeded(d), {
|
|
30
30
|
skipped: !0,
|
|
31
31
|
scriptName: "",
|
|
32
32
|
databaseName: ""
|
|
33
33
|
};
|
|
34
34
|
let n = e.steps.validate(), r = e.steps.names(f);
|
|
35
|
-
return await
|
|
35
|
+
return await a.markRunning(d, "mark-running"), await a.appendEvent(d, {
|
|
36
36
|
step: "mark-running",
|
|
37
37
|
outcome: "succeeded"
|
|
38
38
|
}), {
|
|
@@ -50,9 +50,9 @@ async function c(e, n, i) {
|
|
|
50
50
|
};
|
|
51
51
|
try {
|
|
52
52
|
let n = await i.do("create-database", u("create-database"), async () => {
|
|
53
|
-
await
|
|
53
|
+
await a.setCurrentStep(d, "create-database");
|
|
54
54
|
let { id: t, created: n } = await e.steps.findOrCreateDatabase(p.databaseName);
|
|
55
|
-
return await
|
|
55
|
+
return await a.appendEvent(d, {
|
|
56
56
|
step: "create-database",
|
|
57
57
|
outcome: "succeeded",
|
|
58
58
|
detail: {
|
|
@@ -65,29 +65,29 @@ async function c(e, n, i) {
|
|
|
65
65
|
};
|
|
66
66
|
});
|
|
67
67
|
if (m.d1_database_id = n.databaseId, await i.do("apply-migrations", u("apply-migrations"), async () => {
|
|
68
|
-
await
|
|
68
|
+
await a.setCurrentStep(d, "apply-migrations"), await e.steps.applyMigrations(n.databaseId, n.created), await a.appendEvent(d, {
|
|
69
69
|
step: "apply-migrations",
|
|
70
70
|
outcome: "succeeded",
|
|
71
71
|
detail: { database_version: p.databaseVersion }
|
|
72
72
|
});
|
|
73
73
|
}), await i.do("upload-script", u("upload-script"), async () => {
|
|
74
|
-
await
|
|
74
|
+
await a.setCurrentStep(d, "upload-script"), await e.steps.uploadScript(p.scriptName, n.databaseId), await a.appendEvent(d, {
|
|
75
75
|
step: "upload-script",
|
|
76
76
|
outcome: "succeeded",
|
|
77
77
|
detail: { worker_version: p.workerVersion }
|
|
78
78
|
});
|
|
79
79
|
}), await i.do("upload-secrets", u("upload-secrets"), async () => {
|
|
80
|
-
await
|
|
80
|
+
await a.setCurrentStep(d, "upload-secrets"), await e.steps.uploadSecrets(p.scriptName, f), await a.appendEvent(d, {
|
|
81
81
|
step: "upload-secrets",
|
|
82
82
|
outcome: "succeeded"
|
|
83
83
|
});
|
|
84
84
|
}), e.syncDefaults) {
|
|
85
85
|
let n = e.syncDefaults;
|
|
86
86
|
await i.do("seed-defaults", u("seed-defaults"), async () => {
|
|
87
|
-
await
|
|
87
|
+
await a.setCurrentStep(d, "seed-defaults");
|
|
88
88
|
let e = t(await n(f));
|
|
89
89
|
if (e.length > 0) throw Error(`sync-defaults seed reported ${e.length} error(s): ${e.join("; ")}`);
|
|
90
|
-
await
|
|
90
|
+
await a.appendEvent(d, {
|
|
91
91
|
step: "seed-defaults",
|
|
92
92
|
outcome: "succeeded"
|
|
93
93
|
});
|
|
@@ -96,26 +96,26 @@ async function c(e, n, i) {
|
|
|
96
96
|
if (e.verify) {
|
|
97
97
|
let t = e.verify;
|
|
98
98
|
await i.do("verify", u("verify"), async () => {
|
|
99
|
-
await
|
|
99
|
+
await a.setCurrentStep(d, "verify"), await t(n.databaseId, f), await a.appendEvent(d, {
|
|
100
100
|
step: "verify",
|
|
101
101
|
outcome: "succeeded"
|
|
102
102
|
});
|
|
103
103
|
});
|
|
104
104
|
}
|
|
105
105
|
await i.do("mark-ready", u("mark-ready"), async () => {
|
|
106
|
-
await
|
|
106
|
+
await a.setCurrentStep(d, "mark-ready"), await e.tenants.update(f, {
|
|
107
107
|
...m,
|
|
108
108
|
provisioning_state: "ready",
|
|
109
109
|
provisioning_error: void 0,
|
|
110
110
|
provisioning_state_changed_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
111
|
-
}), await
|
|
111
|
+
}), await a.appendEvent(d, {
|
|
112
112
|
step: "mark-ready",
|
|
113
113
|
outcome: "succeeded"
|
|
114
|
-
}), await
|
|
114
|
+
}), await a.markSucceeded(d);
|
|
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,
|
|
@@ -126,23 +126,119 @@ async function c(e, n, i) {
|
|
|
126
126
|
} catch (t) {
|
|
127
127
|
e.logger?.warn(`Failed to write provisioning_state="failed" for tenant ${f}:`, t);
|
|
128
128
|
}
|
|
129
|
-
await
|
|
129
|
+
await a.appendEvent(d, {
|
|
130
130
|
step: "mark-failed",
|
|
131
131
|
outcome: "failed",
|
|
132
132
|
detail: { message: n }
|
|
133
|
-
}), await
|
|
133
|
+
}), await a.markFailed(d, t);
|
|
134
134
|
}), t;
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
137
|
//#endregion
|
|
138
|
+
//#region src/workflows/sync-defaults-operation.ts
|
|
139
|
+
var d = {
|
|
140
|
+
retries: {
|
|
141
|
+
limit: 3,
|
|
142
|
+
delay: "5 seconds",
|
|
143
|
+
backoff: "exponential"
|
|
144
|
+
},
|
|
145
|
+
timeout: "2 minutes"
|
|
146
|
+
};
|
|
147
|
+
function f(e) {
|
|
148
|
+
return e instanceof Error ? e.message : String(e);
|
|
149
|
+
}
|
|
150
|
+
async function p(e, t, n) {
|
|
151
|
+
let i = r(e.stores), a = (t) => e.stepConfig?.[t] ?? d, s = t.operation_id;
|
|
152
|
+
try {
|
|
153
|
+
await n.do("mark-running", a("mark-running"), async () => {
|
|
154
|
+
await i.markRunning(s, "sync-defaults");
|
|
155
|
+
}), await n.do("sync-defaults", a("sync-defaults"), async () => {
|
|
156
|
+
await i.setCurrentStep(s, "sync-defaults");
|
|
157
|
+
let t = await e.stores.tenantOperations.get(s);
|
|
158
|
+
if (!t) throw Error(`Operation "${s}" not found`);
|
|
159
|
+
let n = await o({
|
|
160
|
+
operation: t,
|
|
161
|
+
syncConfig: e.syncConfig,
|
|
162
|
+
recorder: i
|
|
163
|
+
});
|
|
164
|
+
await i.appendEvent(s, {
|
|
165
|
+
step: "sync-defaults",
|
|
166
|
+
outcome: "succeeded",
|
|
167
|
+
detail: n
|
|
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
|
+
});
|
|
220
|
+
}), await n.do("mark-succeeded", o("mark-succeeded"), async () => {
|
|
221
|
+
await i.markSucceeded(s);
|
|
222
|
+
});
|
|
223
|
+
} catch (e) {
|
|
224
|
+
throw await n.do("mark-failed", o("mark-failed"), async () => {
|
|
225
|
+
await i.appendEvent(s, {
|
|
226
|
+
step: "mark-failed",
|
|
227
|
+
outcome: "failed",
|
|
228
|
+
detail: { message: g(e) }
|
|
229
|
+
}), await i.markFailed(s, e);
|
|
230
|
+
}), e;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
//#endregion
|
|
138
234
|
//#region src/workflows/verify.ts
|
|
139
|
-
var
|
|
235
|
+
var v = class extends Error {
|
|
140
236
|
checks;
|
|
141
237
|
constructor(e, t) {
|
|
142
238
|
super(e), this.name = "TenantProvisionVerificationError", this.checks = t;
|
|
143
239
|
}
|
|
144
240
|
};
|
|
145
|
-
function
|
|
241
|
+
function y(e, t) {
|
|
146
242
|
for (let n of e) for (let e of n.results ?? []) if (!(!e || typeof e != "object")) {
|
|
147
243
|
for (let [n, r] of Object.entries(e)) if (n === t) {
|
|
148
244
|
if (typeof r == "number") return r;
|
|
@@ -151,11 +247,11 @@ function u(e, t) {
|
|
|
151
247
|
}
|
|
152
248
|
return 0;
|
|
153
249
|
}
|
|
154
|
-
function
|
|
250
|
+
function b(t) {
|
|
155
251
|
let n = t.minKeys ?? 1;
|
|
156
252
|
return async (r, i) => {
|
|
157
|
-
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 =
|
|
158
|
-
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("; ")}`, {
|
|
159
255
|
keyCount: o,
|
|
160
256
|
tenantRowCount: s
|
|
161
257
|
});
|
|
@@ -163,16 +259,16 @@ function d(t) {
|
|
|
163
259
|
}
|
|
164
260
|
//#endregion
|
|
165
261
|
//#region src/workflows/executor.ts
|
|
166
|
-
function
|
|
262
|
+
function x(e) {
|
|
167
263
|
let t = e instanceof Error ? e.message : String(e ?? "");
|
|
168
264
|
return /already exists|already been created|duplicate/i.test(t);
|
|
169
265
|
}
|
|
170
|
-
function
|
|
266
|
+
function S(e) {
|
|
171
267
|
return {
|
|
172
268
|
engine: "cloudflare-workflows",
|
|
173
269
|
async start(t) {
|
|
174
|
-
if (t.kind !== "provision") throw Error(`The Cloudflare Workflows executor does not support "${t.kind}" operations yet (
|
|
175
|
-
if (!t.tenant_id) throw Error(
|
|
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)`);
|
|
271
|
+
if (!t.tenant_id) throw Error(`${t.kind} operations require a tenant_id`);
|
|
176
272
|
let r = t.engine_instance_id ?? n(t);
|
|
177
273
|
try {
|
|
178
274
|
await e.binding.create({
|
|
@@ -184,20 +280,20 @@ function p(e) {
|
|
|
184
280
|
}
|
|
185
281
|
});
|
|
186
282
|
} catch (e) {
|
|
187
|
-
if (!
|
|
283
|
+
if (!x(e)) throw e;
|
|
188
284
|
}
|
|
189
285
|
}
|
|
190
286
|
};
|
|
191
287
|
}
|
|
192
288
|
//#endregion
|
|
193
289
|
//#region src/workflows/types.ts
|
|
194
|
-
var
|
|
290
|
+
var C = "cloudflare-workflows";
|
|
195
291
|
//#endregion
|
|
196
292
|
//#region src/workflows/reconcile.ts
|
|
197
|
-
async function
|
|
293
|
+
async function w(e) {
|
|
198
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({
|
|
199
295
|
status: ["pending", "running"],
|
|
200
|
-
engine:
|
|
296
|
+
engine: C,
|
|
201
297
|
updated_before: u,
|
|
202
298
|
per_page: l
|
|
203
299
|
}), f = {
|
|
@@ -209,7 +305,7 @@ async function h(e) {
|
|
|
209
305
|
errors: 0
|
|
210
306
|
};
|
|
211
307
|
for (let t of d) try {
|
|
212
|
-
await
|
|
308
|
+
await m(t);
|
|
213
309
|
} catch (n) {
|
|
214
310
|
f.errors++, e.logger?.warn(`Failed to reconcile tenant operation ${t.id}:`, n);
|
|
215
311
|
}
|
|
@@ -228,7 +324,7 @@ async function h(e) {
|
|
|
228
324
|
provisioning_state_changed_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
229
325
|
});
|
|
230
326
|
}
|
|
231
|
-
async function
|
|
327
|
+
async function m(e) {
|
|
232
328
|
let r = await t.tenantOperations.get(e.id);
|
|
233
329
|
if (!r || i(r.status)) return;
|
|
234
330
|
let c = r.engine_instance_id ?? n(r), l;
|
|
@@ -245,6 +341,14 @@ async function h(e) {
|
|
|
245
341
|
return;
|
|
246
342
|
}
|
|
247
343
|
if (u.status === "complete") {
|
|
344
|
+
if (r.kind === "sync-defaults" || r.kind === "detach") {
|
|
345
|
+
f.markedSucceeded++, await s.appendEvent(r.id, {
|
|
346
|
+
step: r.current_step ?? "reconcile",
|
|
347
|
+
outcome: "reconciled",
|
|
348
|
+
detail: { resolution: "succeeded" }
|
|
349
|
+
}), await s.markSucceeded(r.id);
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
248
352
|
(r.tenant_id ? await a.get(r.tenant_id) : null)?.provisioning_state === "ready" ? (f.markedSucceeded++, await s.appendEvent(r.id, {
|
|
249
353
|
step: r.current_step ?? "reconcile",
|
|
250
354
|
outcome: "reconciled",
|
|
@@ -257,7 +361,7 @@ async function h(e) {
|
|
|
257
361
|
}
|
|
258
362
|
//#endregion
|
|
259
363
|
//#region src/workflows/enqueue-hook.ts
|
|
260
|
-
function
|
|
364
|
+
function T(e) {
|
|
261
365
|
let t = e.shouldProvision ?? ((e) => e.deployment_type === "wfp");
|
|
262
366
|
return {
|
|
263
367
|
async onProvision(n, r) {
|
|
@@ -276,4 +380,4 @@ function g(e) {
|
|
|
276
380
|
};
|
|
277
381
|
}
|
|
278
382
|
//#endregion
|
|
279
|
-
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/adapter-interfaces": "4.
|
|
71
|
-
"@authhero/kysely-adapter": "12.
|
|
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": {
|