@authhero/cloudflare-adapter 3.1.4 → 3.1.6
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.
|
@@ -1,82 +1,82 @@
|
|
|
1
1
|
import { a as e, i as t, n, t as r } from "./sync-defaults-errors-BlLZh6Gt.mjs";
|
|
2
|
-
import { TRIGGER_API_SHAPES as i,
|
|
3
|
-
import { z as
|
|
4
|
-
import { HTTPException as
|
|
5
|
-
import
|
|
6
|
-
import { dedupe as
|
|
2
|
+
import { TRIGGER_API_SHAPES as i, TRIGGER_FUNCTION_NAMES as a, actionExecutionStatusSchema as o, tokenizeLuceneQuery as s, unescapeLuceneValue as c, verificationMethodsSchema as l } from "@authhero/adapter-interfaces";
|
|
3
|
+
import { z as u } from "@hono/zod-openapi";
|
|
4
|
+
import { HTTPException as d } from "hono/http-exception";
|
|
5
|
+
import f from "wretch";
|
|
6
|
+
import { dedupe as p, retry as m } from "wretch/middlewares";
|
|
7
7
|
//#region src/types/CustomDomain.ts
|
|
8
|
-
var
|
|
9
|
-
code:
|
|
10
|
-
message:
|
|
11
|
-
}),
|
|
12
|
-
emails:
|
|
13
|
-
http_body:
|
|
14
|
-
http_url:
|
|
15
|
-
txt_name:
|
|
16
|
-
txt_value:
|
|
17
|
-
}),
|
|
18
|
-
ciphers:
|
|
19
|
-
early_hints:
|
|
20
|
-
http2:
|
|
21
|
-
min_tls_version:
|
|
22
|
-
tls_1_3:
|
|
23
|
-
}),
|
|
24
|
-
id:
|
|
25
|
-
bundle_method:
|
|
26
|
-
certificate_authority:
|
|
27
|
-
custom_certificate:
|
|
28
|
-
custom_csr_id:
|
|
29
|
-
custom_key:
|
|
30
|
-
expires_on:
|
|
31
|
-
hosts:
|
|
32
|
-
issuer:
|
|
33
|
-
method:
|
|
34
|
-
serial_number:
|
|
35
|
-
settings:
|
|
36
|
-
signature:
|
|
37
|
-
type:
|
|
38
|
-
uploaded_on:
|
|
39
|
-
validation_errors:
|
|
40
|
-
validation_records:
|
|
41
|
-
wildcard:
|
|
42
|
-
}),
|
|
43
|
-
name:
|
|
44
|
-
type:
|
|
45
|
-
value:
|
|
46
|
-
}),
|
|
47
|
-
http_body:
|
|
48
|
-
http_url:
|
|
49
|
-
}), v =
|
|
50
|
-
id:
|
|
51
|
-
ssl:
|
|
52
|
-
hostname:
|
|
53
|
-
custom_metadata:
|
|
54
|
-
custom_origin_server:
|
|
55
|
-
custom_origin_sni:
|
|
56
|
-
ownership_verification:
|
|
57
|
-
ownership_verification_http:
|
|
58
|
-
status:
|
|
59
|
-
verification_errors:
|
|
60
|
-
created_at:
|
|
61
|
-
}), y =
|
|
62
|
-
errors:
|
|
63
|
-
messages:
|
|
64
|
-
success:
|
|
8
|
+
var h = u.object({
|
|
9
|
+
code: u.number(),
|
|
10
|
+
message: u.string()
|
|
11
|
+
}), g = u.object({ message: u.string() }), _ = u.object({
|
|
12
|
+
emails: u.array(u.string()).optional(),
|
|
13
|
+
http_body: u.string().optional(),
|
|
14
|
+
http_url: u.string().optional(),
|
|
15
|
+
txt_name: u.string().optional(),
|
|
16
|
+
txt_value: u.string().optional()
|
|
17
|
+
}), ee = u.object({
|
|
18
|
+
ciphers: u.array(u.string()).optional(),
|
|
19
|
+
early_hints: u.string().optional(),
|
|
20
|
+
http2: u.string().optional(),
|
|
21
|
+
min_tls_version: u.string().optional(),
|
|
22
|
+
tls_1_3: u.string().optional()
|
|
23
|
+
}), te = u.object({
|
|
24
|
+
id: u.string(),
|
|
25
|
+
bundle_method: u.string().optional(),
|
|
26
|
+
certificate_authority: u.string(),
|
|
27
|
+
custom_certificate: u.string().optional(),
|
|
28
|
+
custom_csr_id: u.string().optional(),
|
|
29
|
+
custom_key: u.string().optional(),
|
|
30
|
+
expires_on: u.string().optional(),
|
|
31
|
+
hosts: u.array(u.string()).optional(),
|
|
32
|
+
issuer: u.string().optional(),
|
|
33
|
+
method: u.string(),
|
|
34
|
+
serial_number: u.string().optional(),
|
|
35
|
+
settings: ee.optional(),
|
|
36
|
+
signature: u.string().optional(),
|
|
37
|
+
type: u.string(),
|
|
38
|
+
uploaded_on: u.string().optional(),
|
|
39
|
+
validation_errors: u.array(g).optional(),
|
|
40
|
+
validation_records: u.array(_).optional(),
|
|
41
|
+
wildcard: u.boolean()
|
|
42
|
+
}), ne = u.object({
|
|
43
|
+
name: u.string(),
|
|
44
|
+
type: u.string(),
|
|
45
|
+
value: u.string()
|
|
46
|
+
}), re = u.object({
|
|
47
|
+
http_body: u.string().optional(),
|
|
48
|
+
http_url: u.string().optional()
|
|
49
|
+
}), v = u.object({
|
|
50
|
+
id: u.string(),
|
|
51
|
+
ssl: te,
|
|
52
|
+
hostname: u.string(),
|
|
53
|
+
custom_metadata: u.record(u.string(), u.string()).optional(),
|
|
54
|
+
custom_origin_server: u.string().optional(),
|
|
55
|
+
custom_origin_sni: u.string().optional(),
|
|
56
|
+
ownership_verification: ne.optional(),
|
|
57
|
+
ownership_verification_http: re.optional(),
|
|
58
|
+
status: u.string(),
|
|
59
|
+
verification_errors: u.array(u.string()).optional(),
|
|
60
|
+
created_at: u.string()
|
|
61
|
+
}), y = u.object({
|
|
62
|
+
errors: u.array(h),
|
|
63
|
+
messages: u.array(h),
|
|
64
|
+
success: u.boolean(),
|
|
65
65
|
result: v
|
|
66
|
-
}), b =
|
|
67
|
-
errors:
|
|
68
|
-
messages:
|
|
69
|
-
success:
|
|
70
|
-
result:
|
|
66
|
+
}), b = u.object({
|
|
67
|
+
errors: u.array(h),
|
|
68
|
+
messages: u.array(h),
|
|
69
|
+
success: u.boolean(),
|
|
70
|
+
result: u.array(v)
|
|
71
71
|
});
|
|
72
72
|
//#endregion
|
|
73
73
|
//#region src/customDomains/index.ts
|
|
74
74
|
function x(e) {
|
|
75
|
-
return
|
|
75
|
+
return f(`https://api.cloudflare.com/client/v4/zones/${e.zoneId}`).headers({
|
|
76
76
|
"X-Auth-Email": e.authEmail,
|
|
77
77
|
"X-Auth-Key": e.authKey,
|
|
78
78
|
"Content-Type": "application/json"
|
|
79
|
-
}).middlewares([
|
|
79
|
+
}).middlewares([m(), p()]);
|
|
80
80
|
}
|
|
81
81
|
function S(e) {
|
|
82
82
|
let t = {}, n = {};
|
|
@@ -122,15 +122,15 @@ function C(e) {
|
|
|
122
122
|
primary: e.primary,
|
|
123
123
|
status: e.status === "active" ? "ready" : "pending",
|
|
124
124
|
type: e.type ?? "auth0_managed_certs",
|
|
125
|
-
verification: { methods:
|
|
125
|
+
verification: { methods: u.array(l).parse(t) },
|
|
126
126
|
domain_metadata: n
|
|
127
127
|
};
|
|
128
128
|
}
|
|
129
|
-
function
|
|
129
|
+
function ie(e) {
|
|
130
130
|
let t = e instanceof Error ? e.message : String(e);
|
|
131
131
|
return /duplicate/i.test(t);
|
|
132
132
|
}
|
|
133
|
-
async function
|
|
133
|
+
async function ae(e, t, n) {
|
|
134
134
|
let r;
|
|
135
135
|
try {
|
|
136
136
|
r = await x(e).get(`/custom_hostnames?hostname=${encodeURIComponent(n)}`).json();
|
|
@@ -142,7 +142,7 @@ async function ie(e, t, n) {
|
|
|
142
142
|
let a = i.data.result.find((e) => e.hostname.toLowerCase() === n.toLowerCase());
|
|
143
143
|
return !a || e.enterprise && a.custom_metadata?.tenant_id !== t ? null : a;
|
|
144
144
|
}
|
|
145
|
-
async function
|
|
145
|
+
async function w(e, t, n, r) {
|
|
146
146
|
let i = n.custom_domain_id, a;
|
|
147
147
|
try {
|
|
148
148
|
a = C({
|
|
@@ -179,7 +179,7 @@ function oe(e) {
|
|
|
179
179
|
return {
|
|
180
180
|
create: async (t, n) => {
|
|
181
181
|
let { sslOverrides: r, rest: i } = S(n.domain_metadata);
|
|
182
|
-
if (await e.customDomainAdapter.getByDomain(n.domain)) throw new
|
|
182
|
+
if (await e.customDomainAdapter.getByDomain(n.domain)) throw new d(409, { message: `The domain ${n.domain} is already registered` });
|
|
183
183
|
let a;
|
|
184
184
|
try {
|
|
185
185
|
let i = y.parse(await x(e).post({
|
|
@@ -194,8 +194,8 @@ function oe(e) {
|
|
|
194
194
|
if (!i.success) throw Error(JSON.stringify(i.errors));
|
|
195
195
|
a = i.result;
|
|
196
196
|
} catch (r) {
|
|
197
|
-
if (!
|
|
198
|
-
let i = await
|
|
197
|
+
if (!ie(r)) throw r;
|
|
198
|
+
let i = await ae(e, t, n.domain);
|
|
199
199
|
if (!i) throw r;
|
|
200
200
|
a = i;
|
|
201
201
|
}
|
|
@@ -218,7 +218,7 @@ function oe(e) {
|
|
|
218
218
|
},
|
|
219
219
|
get: async (t, n) => {
|
|
220
220
|
let r = await e.customDomainAdapter.get(t, n);
|
|
221
|
-
if (!r) throw new
|
|
221
|
+
if (!r) throw new d(404);
|
|
222
222
|
let i;
|
|
223
223
|
try {
|
|
224
224
|
i = await x(e).get(`/custom_hostnames/${encodeURIComponent(n)}`).json();
|
|
@@ -231,8 +231,8 @@ function oe(e) {
|
|
|
231
231
|
body: i
|
|
232
232
|
}), r;
|
|
233
233
|
let { result: o } = a.data;
|
|
234
|
-
if (e.enterprise && o.custom_metadata?.tenant_id !== t) throw new
|
|
235
|
-
let { domain: s } = await
|
|
234
|
+
if (e.enterprise && o.custom_metadata?.tenant_id !== t) throw new d(404);
|
|
235
|
+
let { domain: s } = await w(e, t, r, o);
|
|
236
236
|
return s;
|
|
237
237
|
},
|
|
238
238
|
getByDomain: async (t) => e.customDomainAdapter.getByDomain(t),
|
|
@@ -240,7 +240,7 @@ function oe(e) {
|
|
|
240
240
|
remove: async (t, n) => {
|
|
241
241
|
if (e.enterprise) {
|
|
242
242
|
let { result: r, success: i } = y.parse(await x(e).get(`/custom_hostnames/${encodeURIComponent(n)}`).json());
|
|
243
|
-
if (!i || r.custom_metadata?.tenant_id !== t) throw new
|
|
243
|
+
if (!i || r.custom_metadata?.tenant_id !== t) throw new d(404);
|
|
244
244
|
}
|
|
245
245
|
let r = await x(e).delete(`/custom_hostnames/${encodeURIComponent(n)}`).res();
|
|
246
246
|
return r.ok && await e.customDomainAdapter.remove(t, n), r.ok;
|
|
@@ -252,10 +252,10 @@ function oe(e) {
|
|
|
252
252
|
try {
|
|
253
253
|
t = await x(e).get(`/custom_hostnames/${encodeURIComponent(n)}`).json();
|
|
254
254
|
} catch (e) {
|
|
255
|
-
throw new
|
|
255
|
+
throw new d(503, { message: `Failed to fetch current custom hostname state: ${e instanceof Error ? e.message : String(e)}` });
|
|
256
256
|
}
|
|
257
257
|
let r = y.safeParse(t);
|
|
258
|
-
if (!r.success || !r.data.success) throw new
|
|
258
|
+
if (!r.success || !r.data.success) throw new d(503, { message: `Failed to parse current custom hostname state: ${JSON.stringify(r.success ? r.data.errors : r.error.issues)}` });
|
|
259
259
|
a.ssl = {
|
|
260
260
|
method: r.data.result.ssl.method,
|
|
261
261
|
type: r.data.result.ssl.type,
|
|
@@ -265,20 +265,20 @@ function oe(e) {
|
|
|
265
265
|
}
|
|
266
266
|
if (Object.keys(a).length > 0) {
|
|
267
267
|
let t = await x(e).patch(a, `/custom_hostnames/${encodeURIComponent(n)}`).res().catch((e) => {
|
|
268
|
-
throw new
|
|
268
|
+
throw new d(503, { message: `Failed to update custom hostname: ${e instanceof Error ? e.message : String(e)}` });
|
|
269
269
|
});
|
|
270
|
-
if (!t.ok) throw new
|
|
270
|
+
if (!t.ok) throw new d(503, { message: await t.text() });
|
|
271
271
|
}
|
|
272
272
|
return e.customDomainAdapter.update(t, n, r);
|
|
273
273
|
},
|
|
274
274
|
uploadCertificate: async (t, n, r) => {
|
|
275
275
|
let i = await e.customDomainAdapter.get(t, n);
|
|
276
|
-
if (!i) throw new
|
|
276
|
+
if (!i) throw new d(404);
|
|
277
277
|
let a = await x(e).patch({ ssl: {
|
|
278
278
|
custom_certificate: r.certificate,
|
|
279
279
|
custom_key: r.private_key
|
|
280
280
|
} }, `/custom_hostnames/${encodeURIComponent(n)}`).json(), { result: o, errors: s, success: c } = y.parse(a);
|
|
281
|
-
if (!c) throw new
|
|
281
|
+
if (!c) throw new d(503, { message: JSON.stringify(s) });
|
|
282
282
|
let l = C({
|
|
283
283
|
...i,
|
|
284
284
|
...o
|
|
@@ -376,14 +376,14 @@ function ce(e = {}) {
|
|
|
376
376
|
}
|
|
377
377
|
//#endregion
|
|
378
378
|
//#region ../../node_modules/.pnpm/nanoid@5.1.11/node_modules/nanoid/url-alphabet/index.js
|
|
379
|
-
var le = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",
|
|
379
|
+
var le = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict", T = (e = 21) => {
|
|
380
380
|
let t = "", n = crypto.getRandomValues(new Uint8Array(e |= 0));
|
|
381
381
|
for (; e--;) t += le[n[e] & 63];
|
|
382
382
|
return t;
|
|
383
383
|
};
|
|
384
384
|
//#endregion
|
|
385
385
|
//#region src/r2-sql-logs/query.ts
|
|
386
|
-
async function
|
|
386
|
+
async function E(e, t) {
|
|
387
387
|
let n = e.timeout || 3e4, r = new AbortController(), i = setTimeout(() => r.abort(), n);
|
|
388
388
|
try {
|
|
389
389
|
let n = `https://api.sql.cloudflarestorage.com/api/v1/accounts/${e.accountId}/r2-sql/query/${e.warehouseName}`, i = await fetch(n, {
|
|
@@ -403,15 +403,15 @@ async function T(e, t) {
|
|
|
403
403
|
clearTimeout(i);
|
|
404
404
|
}
|
|
405
405
|
}
|
|
406
|
-
function
|
|
406
|
+
function D(e) {
|
|
407
407
|
return `'${e.replace(/'/g, "''")}'`;
|
|
408
408
|
}
|
|
409
|
-
function
|
|
409
|
+
function O(e) {
|
|
410
410
|
return `"${e.replace(/"/g, "\"\"")}"`;
|
|
411
411
|
}
|
|
412
412
|
//#endregion
|
|
413
413
|
//#region src/r2-sql-logs/logs.ts
|
|
414
|
-
function
|
|
414
|
+
function k(e) {
|
|
415
415
|
let t = (e) => {
|
|
416
416
|
if (!e) return "";
|
|
417
417
|
try {
|
|
@@ -453,7 +453,7 @@ function O(e) {
|
|
|
453
453
|
}
|
|
454
454
|
function ue(e) {
|
|
455
455
|
return async (t, n) => {
|
|
456
|
-
let r = n.log_id ||
|
|
456
|
+
let r = n.log_id || T(), i = {
|
|
457
457
|
...n,
|
|
458
458
|
log_id: r
|
|
459
459
|
};
|
|
@@ -513,15 +513,15 @@ async function de(e, t, n) {
|
|
|
513
513
|
}
|
|
514
514
|
function fe(e) {
|
|
515
515
|
return async (t, n) => {
|
|
516
|
-
let r = e.namespace || "default", i = e.tableName || "logs", a = await
|
|
517
|
-
SELECT * FROM ${
|
|
518
|
-
WHERE tenant_id = ${
|
|
519
|
-
AND id = ${
|
|
516
|
+
let r = e.namespace || "default", i = e.tableName || "logs", a = await E(e, `
|
|
517
|
+
SELECT * FROM ${O(r)}.${O(i)}
|
|
518
|
+
WHERE tenant_id = ${D(t)}
|
|
519
|
+
AND id = ${D(n)}
|
|
520
520
|
LIMIT 1
|
|
521
521
|
`);
|
|
522
522
|
if (a.length === 0) return null;
|
|
523
523
|
let o = a[0];
|
|
524
|
-
return o ?
|
|
524
|
+
return o ? k(o) : null;
|
|
525
525
|
};
|
|
526
526
|
}
|
|
527
527
|
//#endregion
|
|
@@ -538,13 +538,13 @@ function me(e) {
|
|
|
538
538
|
let t = [];
|
|
539
539
|
for (let [n, r] of Object.entries(e)) {
|
|
540
540
|
let e = n.replace(/[^a-zA-Z0-9_]/g, "");
|
|
541
|
-
e && r && t.push(`${
|
|
541
|
+
e && r && t.push(`${O(e)} = ${D(r)}`);
|
|
542
542
|
}
|
|
543
543
|
return t;
|
|
544
544
|
}
|
|
545
545
|
function he(e) {
|
|
546
546
|
return async (t, n = {}) => {
|
|
547
|
-
let { page: r = 0, per_page: i = 50, include_totals: a = !1, sort: o, q: s } = n, c = e.namespace || "default", l = e.tableName || "logs", u = [`tenant_id = ${
|
|
547
|
+
let { page: r = 0, per_page: i = 50, include_totals: a = !1, sort: o, q: s } = n, c = e.namespace || "default", l = e.tableName || "logs", u = [`tenant_id = ${D(t)}`];
|
|
548
548
|
if (s) {
|
|
549
549
|
let e = pe(s);
|
|
550
550
|
u.push(...me(e));
|
|
@@ -552,22 +552,22 @@ function he(e) {
|
|
|
552
552
|
let d = u.join(" AND "), f = "ORDER BY date DESC";
|
|
553
553
|
if (o && o.sort_by) {
|
|
554
554
|
let e = o.sort_by.replace(/[^a-zA-Z0-9_]/g, ""), t = o.sort_order === "asc" ? "ASC" : "DESC";
|
|
555
|
-
f = `ORDER BY ${
|
|
555
|
+
f = `ORDER BY ${O(e)} ${t}`;
|
|
556
556
|
}
|
|
557
|
-
let p = r * i, m = `LIMIT ${i} OFFSET ${p}`, h = (await
|
|
558
|
-
SELECT * FROM ${
|
|
557
|
+
let p = r * i, m = `LIMIT ${i} OFFSET ${p}`, h = (await E(e, `
|
|
558
|
+
SELECT * FROM ${O(c)}.${O(l)}
|
|
559
559
|
WHERE ${d}
|
|
560
560
|
${f}
|
|
561
561
|
${m}
|
|
562
|
-
`)).map(
|
|
562
|
+
`)).map(k);
|
|
563
563
|
if (!a) return {
|
|
564
564
|
logs: h,
|
|
565
565
|
start: 0,
|
|
566
566
|
limit: 0,
|
|
567
567
|
length: 0
|
|
568
568
|
};
|
|
569
|
-
let g = (await
|
|
570
|
-
SELECT COUNT(*) as count FROM ${
|
|
569
|
+
let g = (await E(e, `
|
|
570
|
+
SELECT COUNT(*) as count FROM ${O(c)}.${O(l)}
|
|
571
571
|
WHERE ${d}
|
|
572
572
|
`))[0]?.count || 0;
|
|
573
573
|
return {
|
|
@@ -592,7 +592,7 @@ function ge() {
|
|
|
592
592
|
}
|
|
593
593
|
//#endregion
|
|
594
594
|
//#region src/r2-sql-logs/index.ts
|
|
595
|
-
function
|
|
595
|
+
function A(e) {
|
|
596
596
|
let t = !!e.pipelineEndpoint, n = !!e.pipelineBinding;
|
|
597
597
|
if (!t && !n) throw Error("R2 SQL logs adapter requires one of: \"pipelineEndpoint\" or \"pipelineBinding\"");
|
|
598
598
|
if (!e.authToken) throw Error("R2 SQL logs adapter requires \"authToken\" configuration");
|
|
@@ -605,7 +605,7 @@ function _e(e) {
|
|
|
605
605
|
}
|
|
606
606
|
//#endregion
|
|
607
607
|
//#region src/analytics-engine-logs/query.ts
|
|
608
|
-
async function
|
|
608
|
+
async function j(e, t) {
|
|
609
609
|
let n = e.timeout || 3e4, r = new AbortController(), i = setTimeout(() => r.abort(), n);
|
|
610
610
|
try {
|
|
611
611
|
let n = `https://api.cloudflare.com/client/v4/accounts/${e.accountId}/analytics_engine/sql`, i = await fetch(n, {
|
|
@@ -628,15 +628,15 @@ async function k(e, t) {
|
|
|
628
628
|
clearTimeout(i);
|
|
629
629
|
}
|
|
630
630
|
}
|
|
631
|
-
function
|
|
631
|
+
function M(e) {
|
|
632
632
|
return `'${e.replace(/'/g, "''").replace(/\\/g, "\\\\")}'`;
|
|
633
633
|
}
|
|
634
|
-
function
|
|
634
|
+
function N(e) {
|
|
635
635
|
return `"${e.replace(/"/g, "\"\"")}"`;
|
|
636
636
|
}
|
|
637
637
|
//#endregion
|
|
638
638
|
//#region src/analytics-engine-logs/logs.ts
|
|
639
|
-
function
|
|
639
|
+
function P(e) {
|
|
640
640
|
let t = (e) => {
|
|
641
641
|
if (e) try {
|
|
642
642
|
return JSON.parse(e);
|
|
@@ -668,16 +668,16 @@ function M(e) {
|
|
|
668
668
|
isMobile: e.double1 === 1
|
|
669
669
|
};
|
|
670
670
|
}
|
|
671
|
-
function
|
|
671
|
+
function _e(e) {
|
|
672
672
|
return async (t, n) => {
|
|
673
|
-
let r = n.log_id ||
|
|
673
|
+
let r = n.log_id || T(), i = {
|
|
674
674
|
...n,
|
|
675
675
|
log_id: r
|
|
676
676
|
};
|
|
677
|
-
return
|
|
677
|
+
return ve(e, t, i), i;
|
|
678
678
|
};
|
|
679
679
|
}
|
|
680
|
-
function
|
|
680
|
+
function ve(e, t, n) {
|
|
681
681
|
if (!e.analyticsEngineBinding) {
|
|
682
682
|
console.error("Analytics Engine binding not configured");
|
|
683
683
|
return;
|
|
@@ -714,34 +714,34 @@ function ye(e, t, n) {
|
|
|
714
714
|
console.error("Failed to write log to Analytics Engine:", e);
|
|
715
715
|
}
|
|
716
716
|
}
|
|
717
|
-
function
|
|
717
|
+
function ye(e) {
|
|
718
718
|
return async (t, n) => {
|
|
719
|
-
let r = await
|
|
719
|
+
let r = await j(e, `
|
|
720
720
|
SELECT *
|
|
721
|
-
FROM ${
|
|
722
|
-
WHERE index1 = ${
|
|
723
|
-
AND blob1 = ${
|
|
721
|
+
FROM ${N(e.dataset || "authhero_logs")}
|
|
722
|
+
WHERE index1 = ${M(t)}
|
|
723
|
+
AND blob1 = ${M(n)}
|
|
724
724
|
LIMIT 1
|
|
725
725
|
`);
|
|
726
|
-
return r.length === 0 || !r[0] ? null :
|
|
726
|
+
return r.length === 0 || !r[0] ? null : P(r[0]);
|
|
727
727
|
};
|
|
728
728
|
}
|
|
729
729
|
//#endregion
|
|
730
730
|
//#region src/analytics-engine-logs/list.ts
|
|
731
|
-
function
|
|
731
|
+
function F(e) {
|
|
732
732
|
let t = e;
|
|
733
|
-
return t.startsWith("\"") && t.endsWith("\"") && t.length > 1 && (t = t.slice(1, -1)),
|
|
733
|
+
return t.startsWith("\"") && t.endsWith("\"") && t.length > 1 && (t = t.slice(1, -1)), c(t);
|
|
734
734
|
}
|
|
735
|
-
function
|
|
735
|
+
function be(e) {
|
|
736
736
|
let t = {}, n = [];
|
|
737
|
-
for (let r of
|
|
737
|
+
for (let r of s(e)) {
|
|
738
738
|
if (r === "OR" || r === "AND") continue;
|
|
739
739
|
let e = r.match(/^(\w+):([\s\S]*)$/);
|
|
740
740
|
if (e) {
|
|
741
|
-
let n = e[1], r =
|
|
741
|
+
let n = e[1], r = F(e[2]);
|
|
742
742
|
t[n] || (t[n] = []), t[n].push(r);
|
|
743
743
|
} else {
|
|
744
|
-
let e =
|
|
744
|
+
let e = F(r);
|
|
745
745
|
e && n.push(e);
|
|
746
746
|
}
|
|
747
747
|
}
|
|
@@ -750,7 +750,7 @@ function xe(e) {
|
|
|
750
750
|
terms: n
|
|
751
751
|
};
|
|
752
752
|
}
|
|
753
|
-
function
|
|
753
|
+
function I(e) {
|
|
754
754
|
return {
|
|
755
755
|
log_id: "blob1",
|
|
756
756
|
tenant_id: "blob2",
|
|
@@ -771,7 +771,7 @@ function P(e) {
|
|
|
771
771
|
hostname: "blob17"
|
|
772
772
|
}[e] || null;
|
|
773
773
|
}
|
|
774
|
-
function
|
|
774
|
+
function xe(e) {
|
|
775
775
|
let t = [];
|
|
776
776
|
for (let [n, r] of Object.entries(e)) {
|
|
777
777
|
let e = r.filter((e) => e !== "");
|
|
@@ -782,41 +782,41 @@ function Se(e) {
|
|
|
782
782
|
n.length > 0 && t.push(`(${n.join(" OR ")})`);
|
|
783
783
|
continue;
|
|
784
784
|
}
|
|
785
|
-
let i =
|
|
786
|
-
if (i) if (e.length === 1) t.push(`${i} = ${
|
|
785
|
+
let i = I(n);
|
|
786
|
+
if (i) if (e.length === 1) t.push(`${i} = ${M(e[0])}`);
|
|
787
787
|
else {
|
|
788
|
-
let n = e.map((e) =>
|
|
788
|
+
let n = e.map((e) => M(e)).join(", ");
|
|
789
789
|
t.push(`${i} IN (${n})`);
|
|
790
790
|
}
|
|
791
791
|
}
|
|
792
792
|
return t;
|
|
793
793
|
}
|
|
794
|
-
function
|
|
794
|
+
function Se(e) {
|
|
795
795
|
return e.filter((e) => e !== "").map((e) => {
|
|
796
|
-
let t =
|
|
796
|
+
let t = M(e), n = M(`%${e}%`);
|
|
797
797
|
return `(blob7 = ${t} OR blob5 LIKE ${n} OR blob4 LIKE ${n})`;
|
|
798
798
|
});
|
|
799
799
|
}
|
|
800
|
-
function
|
|
801
|
-
return e === "date" ? "double2" :
|
|
800
|
+
function Ce(e) {
|
|
801
|
+
return e === "date" ? "double2" : I(e) || "timestamp";
|
|
802
802
|
}
|
|
803
|
-
function
|
|
803
|
+
function we(e) {
|
|
804
804
|
return async (t, n = {}) => {
|
|
805
|
-
let { page: r = 0, per_page: i = 50, include_totals: a = !1, sort: o, q: s, from_date: c, to_date: l } = n, u = e.dataset || "authhero_logs", d = [`index1 = ${
|
|
805
|
+
let { page: r = 0, per_page: i = 50, include_totals: a = !1, sort: o, q: s, from_date: c, to_date: l } = n, u = e.dataset || "authhero_logs", d = [`index1 = ${M(t)}`];
|
|
806
806
|
if (s) {
|
|
807
|
-
let { fields: e, terms: t } =
|
|
808
|
-
d.push(...
|
|
807
|
+
let { fields: e, terms: t } = be(s);
|
|
808
|
+
d.push(...xe(e)), d.push(...Se(t));
|
|
809
809
|
}
|
|
810
810
|
typeof c == "number" && Number.isFinite(c) && d.push(`double2 >= ${Math.floor(c) * 1e3}`), typeof l == "number" && Number.isFinite(l) && d.push(`double2 <= ${Math.floor(l) * 1e3}`);
|
|
811
811
|
let f = d.join(" AND "), p = "ORDER BY timestamp DESC";
|
|
812
|
-
o && o.sort_by && (p = `ORDER BY ${
|
|
813
|
-
let m = r * i, h = `LIMIT ${i} OFFSET ${m}`, g = (await
|
|
812
|
+
o && o.sort_by && (p = `ORDER BY ${Ce(o.sort_by)} ${o.sort_order === "asc" ? "ASC" : "DESC"}`);
|
|
813
|
+
let m = r * i, h = `LIMIT ${i} OFFSET ${m}`, g = (await j(e, `
|
|
814
814
|
SELECT *
|
|
815
|
-
FROM ${
|
|
815
|
+
FROM ${N(u)}
|
|
816
816
|
WHERE ${f}
|
|
817
817
|
${p}
|
|
818
818
|
${h}
|
|
819
|
-
`)).map(
|
|
819
|
+
`)).map(P);
|
|
820
820
|
if (!a) return {
|
|
821
821
|
logs: g,
|
|
822
822
|
start: 0,
|
|
@@ -825,11 +825,11 @@ function Te(e) {
|
|
|
825
825
|
};
|
|
826
826
|
let _ = `
|
|
827
827
|
SELECT count() as count
|
|
828
|
-
FROM ${
|
|
828
|
+
FROM ${N(u)}
|
|
829
829
|
WHERE ${f}
|
|
830
830
|
`;
|
|
831
831
|
try {
|
|
832
|
-
let t = (await
|
|
832
|
+
let t = (await j(e, _))[0]?.count || 0;
|
|
833
833
|
return {
|
|
834
834
|
logs: g,
|
|
835
835
|
start: m,
|
|
@@ -848,14 +848,14 @@ function Te(e) {
|
|
|
848
848
|
}
|
|
849
849
|
//#endregion
|
|
850
850
|
//#region src/analytics-engine-logs/stats.ts
|
|
851
|
-
var
|
|
852
|
-
function
|
|
851
|
+
var L = ["s"], Te = ["pwd_leak"];
|
|
852
|
+
function R(e) {
|
|
853
853
|
return /^\d{8}$/.test(e) ? `${e.slice(0, 4)}-${e.slice(4, 6)}-${e.slice(6, 8)}` : e;
|
|
854
854
|
}
|
|
855
|
-
function
|
|
855
|
+
function z(e) {
|
|
856
856
|
return e.toISOString().split("T")[0];
|
|
857
857
|
}
|
|
858
|
-
function
|
|
858
|
+
function B(e, t) {
|
|
859
859
|
let n = (/* @__PURE__ */ new Date(`${e}T${t === "end" ? "23:59:59.999" : "00:00:00.000"}Z`)).getTime();
|
|
860
860
|
if (Number.isNaN(n)) return NaN;
|
|
861
861
|
let r = /^(\d{4})-(\d{2})-(\d{2})$/.exec(e);
|
|
@@ -863,24 +863,24 @@ function R(e, t) {
|
|
|
863
863
|
let i = new Date(n);
|
|
864
864
|
return i.getUTCFullYear() !== Number(r[1]) || i.getUTCMonth() + 1 !== Number(r[2]) || i.getUTCDate() !== Number(r[3]) ? NaN : n;
|
|
865
865
|
}
|
|
866
|
-
function
|
|
866
|
+
function V(e) {
|
|
867
867
|
let t = e.dataset || "authhero_logs";
|
|
868
868
|
return {
|
|
869
869
|
async getDaily(n, r = {}) {
|
|
870
870
|
let { from: i, to: a } = r, o = /* @__PURE__ */ new Date(), s = new Date(o);
|
|
871
871
|
s.setDate(s.getDate() - 30);
|
|
872
|
-
let c = i ?
|
|
872
|
+
let c = i ? R(i) : z(s), l = a ? R(a) : z(o), u = B(c, "start"), d = B(l, "end");
|
|
873
873
|
if (Number.isNaN(u) || Number.isNaN(d)) throw Error(`Invalid stats date range: from='${c}' to='${l}'`);
|
|
874
|
-
return (await
|
|
874
|
+
return (await j(e, `
|
|
875
875
|
SELECT
|
|
876
876
|
toDate(toDateTime(double2 / 1000)) AS date,
|
|
877
|
-
SUM(CASE WHEN blob3 IN (${
|
|
877
|
+
SUM(CASE WHEN blob3 IN (${L.map((e) => M(e)).join(", ")}) THEN 1 ELSE 0 END) AS logins,
|
|
878
878
|
SUM(CASE WHEN blob3 = 'ss' THEN 1 ELSE 0 END) AS signups,
|
|
879
|
-
SUM(CASE WHEN blob3 IN (${
|
|
879
|
+
SUM(CASE WHEN blob3 IN (${Te.map((e) => M(e)).join(", ")}) THEN 1 ELSE 0 END) AS leaked_passwords,
|
|
880
880
|
MIN(double2) AS first_event,
|
|
881
881
|
MAX(double2) AS last_event
|
|
882
882
|
FROM "${t}"
|
|
883
|
-
WHERE index1 = ${
|
|
883
|
+
WHERE index1 = ${M(n)}
|
|
884
884
|
AND double2 >= ${u}
|
|
885
885
|
AND double2 <= ${d}
|
|
886
886
|
GROUP BY date
|
|
@@ -897,10 +897,10 @@ function z(e) {
|
|
|
897
897
|
async getActiveUsers(n) {
|
|
898
898
|
let r = /* @__PURE__ */ new Date();
|
|
899
899
|
r.setDate(r.getDate() - 30);
|
|
900
|
-
let i = r.getTime(), a =
|
|
900
|
+
let i = r.getTime(), a = L.map((e) => M(e)).join(", "), o = (await j(e, `
|
|
901
901
|
SELECT COUNT(DISTINCT blob7) AS count
|
|
902
902
|
FROM "${t}"
|
|
903
|
-
WHERE index1 = ${
|
|
903
|
+
WHERE index1 = ${M(n)}
|
|
904
904
|
AND double2 >= ${i}
|
|
905
905
|
AND blob3 IN (${a})
|
|
906
906
|
AND blob7 IS NOT NULL
|
|
@@ -912,7 +912,7 @@ function z(e) {
|
|
|
912
912
|
}
|
|
913
913
|
//#endregion
|
|
914
914
|
//#region src/analytics-engine-logs/analytics.ts
|
|
915
|
-
var
|
|
915
|
+
var Ee = {
|
|
916
916
|
"active-users": ["s", "seacft"],
|
|
917
917
|
logins: [
|
|
918
918
|
"s",
|
|
@@ -942,17 +942,17 @@ var De = {
|
|
|
942
942
|
"fvr"
|
|
943
943
|
],
|
|
944
944
|
"codes-sent": ["cls", "cs"]
|
|
945
|
-
},
|
|
945
|
+
}, De = {
|
|
946
946
|
connection: "blob9",
|
|
947
947
|
client_id: "blob11",
|
|
948
948
|
user_type: "blob16",
|
|
949
949
|
event: "blob3"
|
|
950
|
-
},
|
|
950
|
+
}, Oe = {
|
|
951
951
|
connection: "blob9",
|
|
952
952
|
client_id: "blob11",
|
|
953
953
|
user_type: "blob16",
|
|
954
954
|
user_id: "blob7"
|
|
955
|
-
},
|
|
955
|
+
}, ke = {
|
|
956
956
|
"active-users": {
|
|
957
957
|
expr: "count(DISTINCT blob7)",
|
|
958
958
|
alias: "active_users",
|
|
@@ -1009,8 +1009,8 @@ var De = {
|
|
|
1009
1009
|
type: "UInt64"
|
|
1010
1010
|
}
|
|
1011
1011
|
};
|
|
1012
|
-
function
|
|
1013
|
-
let n = `toDateTime(intDiv(double2, 1000), ${
|
|
1012
|
+
function Ae(e, t) {
|
|
1013
|
+
let n = `toDateTime(intDiv(double2, 1000), ${M(t)})`;
|
|
1014
1014
|
switch (e) {
|
|
1015
1015
|
case "hour": return `toStartOfHour(${n})`;
|
|
1016
1016
|
case "week": return `toStartOfWeek(${n})`;
|
|
@@ -1018,45 +1018,45 @@ function je(e, t) {
|
|
|
1018
1018
|
default: return `toStartOfDay(${n})`;
|
|
1019
1019
|
}
|
|
1020
1020
|
}
|
|
1021
|
-
function
|
|
1021
|
+
function je(e) {
|
|
1022
1022
|
return e === "hour" ? "DateTime" : "Date";
|
|
1023
1023
|
}
|
|
1024
|
-
function
|
|
1025
|
-
let r = new Date(e.from).getTime(), i = new Date(e.to).getTime(), a = n.map((e) =>
|
|
1026
|
-
`index1 = ${
|
|
1024
|
+
function Me(e, t, n) {
|
|
1025
|
+
let r = new Date(e.from).getTime(), i = new Date(e.to).getTime(), a = n.map((e) => M(e)).join(", "), o = [
|
|
1026
|
+
`index1 = ${M(t)}`,
|
|
1027
1027
|
`double2 >= ${r}`,
|
|
1028
1028
|
`double2 < ${i}`,
|
|
1029
1029
|
`blob3 IN (${a})`
|
|
1030
1030
|
];
|
|
1031
|
-
for (let [t, n] of Object.entries(
|
|
1031
|
+
for (let [t, n] of Object.entries(Oe)) {
|
|
1032
1032
|
let r = e.filters[t];
|
|
1033
1033
|
if (r && r.length > 0) {
|
|
1034
|
-
let e = r.map((e) =>
|
|
1034
|
+
let e = r.map((e) => M(e)).join(", ");
|
|
1035
1035
|
o.push(`${n} IN (${e})`);
|
|
1036
1036
|
}
|
|
1037
1037
|
}
|
|
1038
1038
|
return o.join(" AND ");
|
|
1039
1039
|
}
|
|
1040
|
-
function
|
|
1040
|
+
function Ne(e, t, n) {
|
|
1041
1041
|
if (e.order_by) {
|
|
1042
1042
|
let t = e.order_by.startsWith("-");
|
|
1043
|
-
return `${
|
|
1043
|
+
return `${N(t ? e.order_by.slice(1) : e.order_by)} ${t ? "DESC" : "ASC"}`;
|
|
1044
1044
|
}
|
|
1045
|
-
return t.length > 0 && t[0] === "time" ? `${
|
|
1045
|
+
return t.length > 0 && t[0] === "time" ? `${N("time")} ASC` : `${N(n)} DESC`;
|
|
1046
1046
|
}
|
|
1047
|
-
function
|
|
1047
|
+
function H(e) {
|
|
1048
1048
|
let t = e.dataset || "authhero_logs";
|
|
1049
1049
|
return { async query(n, r, i) {
|
|
1050
|
-
let a =
|
|
1050
|
+
let a = Ee[r], o = ke[r], s = [], c = [];
|
|
1051
1051
|
for (let e of i.group_by) if (e === "time") {
|
|
1052
|
-
let e =
|
|
1053
|
-
s.push(`${e} AS ${
|
|
1052
|
+
let e = Ae(i.interval, i.tz);
|
|
1053
|
+
s.push(`${e} AS ${N("time")}`), c.push({
|
|
1054
1054
|
name: "time",
|
|
1055
|
-
type:
|
|
1055
|
+
type: je(i.interval)
|
|
1056
1056
|
});
|
|
1057
1057
|
} else {
|
|
1058
|
-
let t =
|
|
1059
|
-
s.push(`${t} AS ${
|
|
1058
|
+
let t = De[e];
|
|
1059
|
+
s.push(`${t} AS ${N(e)}`), c.push({
|
|
1060
1060
|
name: e,
|
|
1061
1061
|
type: "String"
|
|
1062
1062
|
});
|
|
@@ -1065,10 +1065,10 @@ function B(e) {
|
|
|
1065
1065
|
name: o.alias,
|
|
1066
1066
|
type: o.type
|
|
1067
1067
|
});
|
|
1068
|
-
let l = [...s, `${o.expr} AS ${
|
|
1068
|
+
let l = [...s, `${o.expr} AS ${N(o.alias)}`], u = i.group_by.length ? `GROUP BY ${i.group_by.map((e) => N(e === "time" ? "time" : e)).join(", ")}` : "", d = Ne(i, i.group_by.map((e) => e === "time" ? "time" : e), o.alias), f = `
|
|
1069
1069
|
SELECT ${l.join(", ")}
|
|
1070
|
-
FROM ${
|
|
1071
|
-
WHERE ${
|
|
1070
|
+
FROM ${N(t)}
|
|
1071
|
+
WHERE ${Me(i, n, a)}
|
|
1072
1072
|
${u}
|
|
1073
1073
|
ORDER BY ${d}
|
|
1074
1074
|
LIMIT ${Math.max(0, i.limit)} OFFSET ${Math.max(0, i.offset)}
|
|
@@ -1105,47 +1105,47 @@ function B(e) {
|
|
|
1105
1105
|
}
|
|
1106
1106
|
//#endregion
|
|
1107
1107
|
//#region src/analytics-engine-logs/index.ts
|
|
1108
|
-
function
|
|
1108
|
+
function U(e) {
|
|
1109
1109
|
return e.analyticsEngineBinding || console.warn("Analytics Engine: No binding configured. Logs will not be written to Analytics Engine."), (!e.accountId || !e.apiToken) && console.warn("Analytics Engine: accountId and apiToken are required for querying logs via SQL API."), {
|
|
1110
|
-
create:
|
|
1111
|
-
list:
|
|
1112
|
-
get:
|
|
1110
|
+
create: _e(e),
|
|
1111
|
+
list: we(e),
|
|
1112
|
+
get: ye(e)
|
|
1113
1113
|
};
|
|
1114
1114
|
}
|
|
1115
1115
|
//#endregion
|
|
1116
1116
|
//#region src/analytics-engine-action-executions/actionExecutions.ts
|
|
1117
|
-
var
|
|
1118
|
-
function
|
|
1117
|
+
var Pe = "authhero_action_executions", Fe = 1024, Ie = "[truncated]";
|
|
1118
|
+
function W(e) {
|
|
1119
1119
|
if (!(typeof e != "string" || e.length === 0)) try {
|
|
1120
1120
|
return JSON.parse(e);
|
|
1121
1121
|
} catch {
|
|
1122
1122
|
return;
|
|
1123
1123
|
}
|
|
1124
1124
|
}
|
|
1125
|
-
function
|
|
1126
|
-
let t =
|
|
1125
|
+
function Le(e) {
|
|
1126
|
+
let t = o.safeParse(e);
|
|
1127
1127
|
return t.success ? t.data : "unspecified";
|
|
1128
1128
|
}
|
|
1129
|
-
function
|
|
1130
|
-
return e.length <= t ? e : `${e.substring(0, t - 11)}${
|
|
1129
|
+
function G(e, t = Fe) {
|
|
1130
|
+
return e.length <= t ? e : `${e.substring(0, t - 11)}${Ie}`;
|
|
1131
1131
|
}
|
|
1132
|
-
function
|
|
1132
|
+
function K(e) {
|
|
1133
1133
|
return e == null ? "" : JSON.stringify(e);
|
|
1134
1134
|
}
|
|
1135
|
-
function
|
|
1135
|
+
function Re(e) {
|
|
1136
1136
|
let t = typeof e.blob6 == "string" && e.blob6.length > 0 ? e.blob6 : typeof e.double1 == "number" ? new Date(e.double1).toISOString() : "", n = typeof e.blob7 == "string" && e.blob7.length > 0 ? e.blob7 : t;
|
|
1137
1137
|
return {
|
|
1138
1138
|
id: typeof e.blob1 == "string" ? e.blob1 : "",
|
|
1139
1139
|
tenant_id: typeof e.index1 == "string" ? e.index1 : "",
|
|
1140
1140
|
trigger_id: typeof e.blob2 == "string" ? e.blob2 : "",
|
|
1141
|
-
status:
|
|
1142
|
-
results:
|
|
1143
|
-
logs:
|
|
1141
|
+
status: Le(e.blob3),
|
|
1142
|
+
results: W(e.blob4) ?? [],
|
|
1143
|
+
logs: W(e.blob5),
|
|
1144
1144
|
created_at: t,
|
|
1145
1145
|
updated_at: n
|
|
1146
1146
|
};
|
|
1147
1147
|
}
|
|
1148
|
-
function
|
|
1148
|
+
function ze(e) {
|
|
1149
1149
|
return async (t, n) => {
|
|
1150
1150
|
let r = Date.now(), i = new Date(r).toISOString(), a = {
|
|
1151
1151
|
id: n.id,
|
|
@@ -1157,10 +1157,10 @@ function Be(e) {
|
|
|
1157
1157
|
created_at: i,
|
|
1158
1158
|
updated_at: i
|
|
1159
1159
|
};
|
|
1160
|
-
return
|
|
1160
|
+
return Be(e, t, a, r), a;
|
|
1161
1161
|
};
|
|
1162
1162
|
}
|
|
1163
|
-
function
|
|
1163
|
+
function Be(e, t, n, r) {
|
|
1164
1164
|
if (!e.analyticsEngineBinding) {
|
|
1165
1165
|
console.error("Analytics Engine action_executions binding not configured; skipping write");
|
|
1166
1166
|
return;
|
|
@@ -1168,13 +1168,13 @@ function Ve(e, t, n, r) {
|
|
|
1168
1168
|
try {
|
|
1169
1169
|
e.analyticsEngineBinding.writeDataPoint({
|
|
1170
1170
|
blobs: [
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1171
|
+
G(n.id),
|
|
1172
|
+
G(n.trigger_id),
|
|
1173
|
+
G(n.status),
|
|
1174
|
+
G(K(n.results)),
|
|
1175
|
+
G(K(n.logs)),
|
|
1176
|
+
G(n.created_at),
|
|
1177
|
+
G(n.updated_at)
|
|
1178
1178
|
],
|
|
1179
1179
|
doubles: [r],
|
|
1180
1180
|
indexes: [t.substring(0, 96)]
|
|
@@ -1183,29 +1183,29 @@ function Ve(e, t, n, r) {
|
|
|
1183
1183
|
console.error("Failed to write action_execution to Analytics Engine:", e);
|
|
1184
1184
|
}
|
|
1185
1185
|
}
|
|
1186
|
-
function
|
|
1186
|
+
function Ve(e) {
|
|
1187
1187
|
return async (t, n) => {
|
|
1188
|
-
let r = await
|
|
1188
|
+
let r = await j(e, `
|
|
1189
1189
|
SELECT *
|
|
1190
|
-
FROM ${
|
|
1191
|
-
WHERE index1 = ${
|
|
1192
|
-
AND blob1 = ${
|
|
1190
|
+
FROM ${N(e.dataset || Pe)}
|
|
1191
|
+
WHERE index1 = ${M(t)}
|
|
1192
|
+
AND blob1 = ${M(n)}
|
|
1193
1193
|
LIMIT 1
|
|
1194
1194
|
`);
|
|
1195
|
-
return r.length === 0 || !r[0] ? null :
|
|
1195
|
+
return r.length === 0 || !r[0] ? null : Re(r[0]);
|
|
1196
1196
|
};
|
|
1197
1197
|
}
|
|
1198
1198
|
//#endregion
|
|
1199
1199
|
//#region src/analytics-engine-action-executions/index.ts
|
|
1200
|
-
function
|
|
1200
|
+
function q(e) {
|
|
1201
1201
|
return e.analyticsEngineBinding || console.warn("Analytics Engine: No action_executions binding configured. Executions will not be written."), (!e.accountId || !e.apiToken) && console.warn("Analytics Engine: accountId and apiToken are required to read action_executions via the SQL API."), {
|
|
1202
|
-
create:
|
|
1203
|
-
get:
|
|
1202
|
+
create: ze(e),
|
|
1203
|
+
get: Ve(e)
|
|
1204
1204
|
};
|
|
1205
1205
|
}
|
|
1206
1206
|
//#endregion
|
|
1207
1207
|
//#region src/geo/index.ts
|
|
1208
|
-
function
|
|
1208
|
+
function He() {
|
|
1209
1209
|
return { async getGeoInfo(e) {
|
|
1210
1210
|
try {
|
|
1211
1211
|
let t = e["cf-ipcountry"], n = e["cf-ipcity"], r = e["cf-iplatitude"], i = e["cf-iplongitude"], a = e["cf-timezone"], o = e["cf-ipcontinent"];
|
|
@@ -1224,7 +1224,7 @@ function Ue() {
|
|
|
1224
1224
|
}
|
|
1225
1225
|
//#endregion
|
|
1226
1226
|
//#region src/rate-limit/index.ts
|
|
1227
|
-
var
|
|
1227
|
+
var Ue = class {
|
|
1228
1228
|
bindings;
|
|
1229
1229
|
constructor(e) {
|
|
1230
1230
|
this.bindings = e;
|
|
@@ -1240,14 +1240,14 @@ var We = class {
|
|
|
1240
1240
|
}
|
|
1241
1241
|
}
|
|
1242
1242
|
};
|
|
1243
|
-
function
|
|
1244
|
-
if (e && Object.keys(e).some((t) => e[t])) return new
|
|
1243
|
+
function J(e) {
|
|
1244
|
+
if (e && Object.keys(e).some((t) => e[t])) return new Ue(e);
|
|
1245
1245
|
}
|
|
1246
1246
|
//#endregion
|
|
1247
1247
|
//#region src/customDomains/sync.ts
|
|
1248
|
-
var
|
|
1249
|
-
async function
|
|
1250
|
-
let n = Math.trunc(t.perPage ??
|
|
1248
|
+
var We = 5, Ge = 1e3, Y = 50;
|
|
1249
|
+
async function Ke(e, t = {}) {
|
|
1250
|
+
let n = Math.trunc(t.perPage ?? Y), r = Number.isFinite(n) ? Math.min(Ge, Math.max(We, n)) : Y, i = t.maxPages ?? 200, a = {
|
|
1251
1251
|
scanned: 0,
|
|
1252
1252
|
matched: 0,
|
|
1253
1253
|
updated: 0,
|
|
@@ -1282,7 +1282,7 @@ async function qe(e, t = {}) {
|
|
|
1282
1282
|
continue;
|
|
1283
1283
|
}
|
|
1284
1284
|
a.matched++;
|
|
1285
|
-
let { outcome: r } = await
|
|
1285
|
+
let { outcome: r } = await w(e, n.tenant_id, n, t);
|
|
1286
1286
|
r === "updated" ? a.updated++ : r === "failed" && a.errors++;
|
|
1287
1287
|
} catch (e) {
|
|
1288
1288
|
console.warn(`[custom-domains] sync failed for ${t.hostname}:`, e instanceof Error ? e.message : e), a.errors++;
|
|
@@ -1294,15 +1294,10 @@ async function qe(e, t = {}) {
|
|
|
1294
1294
|
}
|
|
1295
1295
|
//#endregion
|
|
1296
1296
|
//#region src/code-executor/worker-template.ts
|
|
1297
|
-
function
|
|
1297
|
+
function X(e) {
|
|
1298
1298
|
return `// Auto-generated AuthHero code hook worker
|
|
1299
1299
|
|
|
1300
|
-
const fnNames = {
|
|
1301
|
-
"post-user-login": "onExecutePostLogin",
|
|
1302
|
-
"credentials-exchange": "onExecuteCredentialsExchange",
|
|
1303
|
-
"pre-user-registration": "onExecutePreUserRegistration",
|
|
1304
|
-
"post-user-registration": "onExecutePostUserRegistration",
|
|
1305
|
-
};
|
|
1300
|
+
const fnNames = ${JSON.stringify(a)};
|
|
1306
1301
|
|
|
1307
1302
|
// Shared source of truth for the per-trigger API allowlist — see
|
|
1308
1303
|
// TRIGGER_API_SHAPES in @authhero/adapter-interfaces.
|
|
@@ -1386,7 +1381,7 @@ export default {
|
|
|
1386
1381
|
}
|
|
1387
1382
|
//#endregion
|
|
1388
1383
|
//#region src/code-executor/index.ts
|
|
1389
|
-
var
|
|
1384
|
+
var qe = class {
|
|
1390
1385
|
config;
|
|
1391
1386
|
constructor(e) {
|
|
1392
1387
|
this.config = e;
|
|
@@ -1447,7 +1442,7 @@ var Y = class {
|
|
|
1447
1442
|
}
|
|
1448
1443
|
}
|
|
1449
1444
|
async deploy(e, t) {
|
|
1450
|
-
let n = `hook-${e}`, r =
|
|
1445
|
+
let n = `hook-${e}`, r = X(t), i = `https://api.cloudflare.com/client/v4/accounts/${this.config.accountId}/workers/dispatch/namespaces/${this.config.dispatchNamespace}/scripts/${n}`, a = JSON.stringify({
|
|
1451
1446
|
main_module: "index.js",
|
|
1452
1447
|
compatibility_date: this.config.compatibilityDate ?? "2024-11-20"
|
|
1453
1448
|
}), o = new FormData();
|
|
@@ -1472,12 +1467,7 @@ var Y = class {
|
|
|
1472
1467
|
throw Error(`Failed to remove hook worker ${t}: ${r.status} ${e}`);
|
|
1473
1468
|
}
|
|
1474
1469
|
}
|
|
1475
|
-
}, Je =
|
|
1476
|
-
"post-user-login": "onExecutePostLogin",
|
|
1477
|
-
"credentials-exchange": "onExecuteCredentialsExchange",
|
|
1478
|
-
"pre-user-registration": "onExecutePreUserRegistration",
|
|
1479
|
-
"post-user-registration": "onExecutePostUserRegistration"
|
|
1480
|
-
}, Xe = i;
|
|
1470
|
+
}, Je = qe, Ye = a, Xe = i;
|
|
1481
1471
|
async function Ze(e) {
|
|
1482
1472
|
let t = new TextEncoder().encode(e), n = await crypto.subtle.digest("SHA-256", t), r = new Uint8Array(n), i = "";
|
|
1483
1473
|
for (let e of r) i += e.toString(16).padStart(2, "0");
|
|
@@ -1617,19 +1607,19 @@ var $e = class {
|
|
|
1617
1607
|
};
|
|
1618
1608
|
}
|
|
1619
1609
|
}
|
|
1620
|
-
},
|
|
1621
|
-
function
|
|
1622
|
-
if (
|
|
1610
|
+
}, Z = new TextEncoder();
|
|
1611
|
+
function et(e, t) {
|
|
1612
|
+
if (Z.encode(e).length <= t) return e;
|
|
1623
1613
|
let n = 0, r = "";
|
|
1624
1614
|
for (let i of e) {
|
|
1625
|
-
let e =
|
|
1615
|
+
let e = Z.encode(i).length;
|
|
1626
1616
|
if (n + e > t) break;
|
|
1627
1617
|
n += e, r += i;
|
|
1628
1618
|
}
|
|
1629
1619
|
return r;
|
|
1630
1620
|
}
|
|
1631
|
-
var Q = (e, t = 1024) =>
|
|
1632
|
-
function
|
|
1621
|
+
var Q = (e, t = 1024) => et(e, t);
|
|
1622
|
+
function tt(e) {
|
|
1633
1623
|
let t = e.analyticsEngineBinding;
|
|
1634
1624
|
return (e) => {
|
|
1635
1625
|
if (t) try {
|
|
@@ -1647,7 +1637,7 @@ function et(e) {
|
|
|
1647
1637
|
e.retryCount ?? 0,
|
|
1648
1638
|
Date.now()
|
|
1649
1639
|
],
|
|
1650
|
-
indexes: [
|
|
1640
|
+
indexes: [et(e.tenantId, 96)]
|
|
1651
1641
|
});
|
|
1652
1642
|
} catch (e) {
|
|
1653
1643
|
console.error("Failed to write outbox metric to Analytics Engine:", e);
|
|
@@ -1656,7 +1646,7 @@ function et(e) {
|
|
|
1656
1646
|
}
|
|
1657
1647
|
//#endregion
|
|
1658
1648
|
//#region src/wfp-provisioner/provisioner.ts
|
|
1659
|
-
function
|
|
1649
|
+
function nt(e) {
|
|
1660
1650
|
let t = n(e);
|
|
1661
1651
|
return {
|
|
1662
1652
|
async onProvision(e) {
|
|
@@ -1677,10 +1667,10 @@ function tt(e) {
|
|
|
1677
1667
|
}
|
|
1678
1668
|
//#endregion
|
|
1679
1669
|
//#region src/wfp-provisioner/tenant-hook.ts
|
|
1680
|
-
function
|
|
1670
|
+
function rt(e) {
|
|
1681
1671
|
return e.deployment_type === "wfp";
|
|
1682
1672
|
}
|
|
1683
|
-
var
|
|
1673
|
+
var it = 2048;
|
|
1684
1674
|
function $(e) {
|
|
1685
1675
|
let t;
|
|
1686
1676
|
if (e instanceof Error) t = e.message;
|
|
@@ -1689,10 +1679,10 @@ function $(e) {
|
|
|
1689
1679
|
} catch {
|
|
1690
1680
|
t = Object.prototype.toString.call(e);
|
|
1691
1681
|
}
|
|
1692
|
-
return t.slice(0,
|
|
1682
|
+
return t.slice(0, it);
|
|
1693
1683
|
}
|
|
1694
|
-
function
|
|
1695
|
-
let { provisioner: t, tenants: n, syncDefaults: i } = e, a = e.shouldProvision ??
|
|
1684
|
+
function at(e) {
|
|
1685
|
+
let { provisioner: t, tenants: n, syncDefaults: i } = e, a = e.shouldProvision ?? rt, o = e.logger;
|
|
1696
1686
|
async function s(e, t) {
|
|
1697
1687
|
try {
|
|
1698
1688
|
await n.update(e, {
|
|
@@ -1786,15 +1776,15 @@ function it(e) {
|
|
|
1786
1776
|
}
|
|
1787
1777
|
//#endregion
|
|
1788
1778
|
//#region src/wfp-provisioner/wfp-forward.ts
|
|
1789
|
-
var
|
|
1790
|
-
function
|
|
1779
|
+
var ot = "DISPATCHER", st = "tenant-{tenant_id}-auth", ct = ["/u/widget/"];
|
|
1780
|
+
function lt(e) {
|
|
1791
1781
|
return typeof e == "object" && !!e && "get" in e && typeof Reflect.get(e, "get") == "function";
|
|
1792
1782
|
}
|
|
1793
|
-
function
|
|
1783
|
+
function ut(e, t) {
|
|
1794
1784
|
return e.replace(/\{tenant_id\}/g, t);
|
|
1795
1785
|
}
|
|
1796
|
-
function
|
|
1797
|
-
let { tenants: t, controlPlaneTenantId: n, dispatcherBinding: r =
|
|
1786
|
+
function dt(e) {
|
|
1787
|
+
let { tenants: t, controlPlaneTenantId: n, dispatcherBinding: r = ot, scriptNameTemplate: i = st, resolveTenantId: a = (e) => e.req.header("tenant-id"), localPaths: o = ct } = e;
|
|
1798
1788
|
return async (e, s) => {
|
|
1799
1789
|
if (o.length > 0) {
|
|
1800
1790
|
let t = e.req.path;
|
|
@@ -1805,8 +1795,8 @@ function ut(e) {
|
|
|
1805
1795
|
let l = await t.get(c);
|
|
1806
1796
|
if (!l || l.deployment_type !== "wfp" || l.provisioning_state && l.provisioning_state !== "ready") return s();
|
|
1807
1797
|
let u = Reflect.get(e.env ?? {}, r);
|
|
1808
|
-
if (!
|
|
1809
|
-
let d =
|
|
1798
|
+
if (!lt(u)) return s();
|
|
1799
|
+
let d = ut(i, c), f;
|
|
1810
1800
|
try {
|
|
1811
1801
|
f = await u.get(d).fetch(e.req.raw);
|
|
1812
1802
|
} catch (t) {
|
|
@@ -1829,7 +1819,7 @@ function ut(e) {
|
|
|
1829
1819
|
}
|
|
1830
1820
|
//#endregion
|
|
1831
1821
|
//#region src/index.ts
|
|
1832
|
-
function
|
|
1822
|
+
function ft(e) {
|
|
1833
1823
|
let t = {
|
|
1834
1824
|
customDomains: oe(e),
|
|
1835
1825
|
cache: ce({
|
|
@@ -1837,11 +1827,11 @@ function dt(e) {
|
|
|
1837
1827
|
...e.defaultTtlSeconds !== void 0 && { defaultTtlSeconds: e.defaultTtlSeconds },
|
|
1838
1828
|
...e.keyPrefix && { keyPrefix: e.keyPrefix }
|
|
1839
1829
|
}),
|
|
1840
|
-
geo:
|
|
1830
|
+
geo: He()
|
|
1841
1831
|
};
|
|
1842
|
-
e.r2SqlLogs ? t.logs =
|
|
1843
|
-
let n =
|
|
1832
|
+
e.r2SqlLogs ? t.logs = A(e.r2SqlLogs) : e.analyticsEngineLogs && (t.logs = U(e.analyticsEngineLogs)), e.analyticsEngineLogs && (t.analytics = H(e.analyticsEngineLogs), t.stats = V(e.analyticsEngineLogs)), e.analyticsEngineActionExecutions && (t.actionExecutions = q(e.analyticsEngineActionExecutions));
|
|
1833
|
+
let n = J(e.rateLimitBindings);
|
|
1844
1834
|
return n && (t.rateLimit = n), t;
|
|
1845
1835
|
}
|
|
1846
1836
|
//#endregion
|
|
1847
|
-
export { t as CloudflareApiClient, e as CloudflareApiError, Je as CloudflareCodeExecutor,
|
|
1837
|
+
export { t as CloudflareApiClient, e as CloudflareApiError, Je as CloudflareCodeExecutor, qe as DispatchNamespaceCodeExecutor, $e as WorkerLoaderCodeExecutor, q as createAnalyticsEngineActionExecutionsAdapter, H as createAnalyticsEngineAnalyticsAdapter, U as createAnalyticsEngineLogsAdapter, tt as createAnalyticsEngineOutboxMetricsSink, V as createAnalyticsEngineStatsAdapter, J as createCloudflareRateLimitAdapter, nt as createCloudflareWfpD1Provisioner, A as createR2SQLLogsAdapter, ge as createR2SQLStatsAdapter, dt as createWfpForwardMiddleware, n as createWfpProvisionerSteps, at as createWfpTenantProvisioningHook, ft as default, X as generateWorkerScript, Ke as syncCustomDomains };
|