@authhero/drizzle 1.6.2 → 1.7.1
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/drizzle-adapter.cjs +2 -2
- package/dist/drizzle-adapter.mjs +1182 -999
- package/drizzle/0008_client_grants_unique_audience.sql +18 -0
- package/drizzle/meta/0008_snapshot.json +6652 -0
- package/drizzle/meta/_journal.json +7 -0
- package/drizzle-control-plane/0001_tenant_operation_rows.sql +20 -0
- package/drizzle-control-plane/meta/0001_snapshot.json +473 -0
- package/drizzle-control-plane/meta/_journal.json +7 -0
- package/package.json +3 -3
- package/src/schema/control-plane/tenantOperations.ts +42 -0
- package/src/schema/sqlite/clients.ts +7 -0
package/dist/drizzle-adapter.mjs
CHANGED
|
@@ -2,16 +2,16 @@ import { Column as e, and as t, asc as n, count as r, desc as i, eq as a, getTab
|
|
|
2
2
|
import { customAlphabet as ee, nanoid as b } from "nanoid";
|
|
3
3
|
import { SQLiteTable as te, foreignKey as ne, index as x, integer as S, primaryKey as C, sqliteTable as w, text as T, uniqueIndex as re } from "drizzle-orm/sqlite-core";
|
|
4
4
|
import { booleanToInt as ie, convertDatesToAdapter as ae, dbDateToIsoRequired as oe, getCountAsInt as se, isoToDbDate as E, removeNullProperties as D, removeUndefinedAndNull as ce, stringifyProperties as le } from "@authhero/adapter-interfaces/sql";
|
|
5
|
-
import { MONDAY_EPOCH_SHIFT_MS as ue, WEEK_MS as de, buildRefreshTokenRetention as fe, buildSessionRetention as pe, clientRegistrationTokenTypeSchema as me, decodeCursor as he, encodeCursor as ge, handlerConfigSchema as _e, isEmailSearchTerm as ve, isPlainObject as ye, matchSchema as be, parseUserId as xe, rolloutInsertSchema as Se, rolloutSchema as Ce, sanitizeLuceneQuery as we, scimMappingEntrySchema as Te, sessionRetentionWindow as Ee, splitLuceneOrGroups as De, tenantOperationEventInsertSchema as Oe, tenantOperationEventSchema as ke, tenantOperationInsertSchema as Ae,
|
|
6
|
-
import { HTTPException as
|
|
5
|
+
import { MONDAY_EPOCH_SHIFT_MS as ue, WEEK_MS as de, buildRefreshTokenRetention as fe, buildSessionRetention as pe, clientRegistrationTokenTypeSchema as me, decodeCursor as he, encodeCursor as ge, handlerConfigSchema as _e, isEmailSearchTerm as ve, isPlainObject as ye, matchSchema as be, parseUserId as xe, rolloutInsertSchema as Se, rolloutSchema as Ce, sanitizeLuceneQuery as we, scimMappingEntrySchema as Te, sessionRetentionWindow as Ee, splitLuceneOrGroups as De, tenantOperationEventInsertSchema as Oe, tenantOperationEventSchema as ke, tenantOperationInsertSchema as Ae, tenantOperationRowInsertSchema as je, tenantOperationRowSchema as Me, tenantOperationSchema as Ne, unescapeLuceneValue as Pe } from "@authhero/adapter-interfaces";
|
|
6
|
+
import { HTTPException as Fe } from "hono/http-exception";
|
|
7
7
|
//#region \0rolldown/runtime.js
|
|
8
|
-
var
|
|
8
|
+
var Ie = Object.defineProperty, Le = (e, t) => {
|
|
9
9
|
let n = {};
|
|
10
|
-
for (var r in e)
|
|
10
|
+
for (var r in e) Ie(n, r, {
|
|
11
11
|
get: e[r],
|
|
12
12
|
enumerable: !0
|
|
13
13
|
});
|
|
14
|
-
return t ||
|
|
14
|
+
return t || Ie(n, Symbol.toStringTag, { value: "Module" }), n;
|
|
15
15
|
}, O = w("tenants", {
|
|
16
16
|
id: T("id", { length: 191 }).primaryKey(),
|
|
17
17
|
name: T("name", { length: 255 }),
|
|
@@ -67,7 +67,7 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
67
67
|
worker_script_name: T("worker_script_name", { length: 255 }),
|
|
68
68
|
storage_kind: T("storage_kind", { length: 32 }),
|
|
69
69
|
d1_database_id: T("d1_database_id", { length: 64 })
|
|
70
|
-
}),
|
|
70
|
+
}), Re = w("actions", {
|
|
71
71
|
id: T("id", { length: 255 }).notNull(),
|
|
72
72
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => O.id, { onDelete: "cascade" }),
|
|
73
73
|
name: T("name", { length: 255 }).notNull(),
|
|
@@ -89,7 +89,7 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
89
89
|
}),
|
|
90
90
|
x("idx_actions_tenant_id").on(e.tenant_id),
|
|
91
91
|
x("idx_actions_name").on(e.tenant_id, e.name)
|
|
92
|
-
]),
|
|
92
|
+
]), k = w("action_versions", {
|
|
93
93
|
id: T("id", { length: 255 }).notNull(),
|
|
94
94
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => O.id, { onDelete: "cascade" }),
|
|
95
95
|
action_id: T("action_id", { length: 255 }).notNull(),
|
|
@@ -109,7 +109,7 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
109
109
|
}),
|
|
110
110
|
re("uq_action_versions_number").on(e.tenant_id, e.action_id, e.number),
|
|
111
111
|
x("idx_action_versions_action_id").on(e.tenant_id, e.action_id)
|
|
112
|
-
]),
|
|
112
|
+
]), ze = w("action_executions", {
|
|
113
113
|
id: T("id", { length: 255 }).notNull(),
|
|
114
114
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => O.id, { onDelete: "cascade" }),
|
|
115
115
|
trigger_id: T("trigger_id", { length: 255 }).notNull(),
|
|
@@ -121,7 +121,7 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
121
121
|
}, (e) => [C({
|
|
122
122
|
columns: [e.tenant_id, e.id],
|
|
123
123
|
name: "action_executions_pk"
|
|
124
|
-
}), x("action_executions_created_at_ts_index").on(e.created_at_ts)]),
|
|
124
|
+
}), x("action_executions_created_at_ts_index").on(e.created_at_ts)]), A = w("users", {
|
|
125
125
|
user_id: T("user_id", { length: 255 }).notNull(),
|
|
126
126
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => O.id, { onDelete: "cascade" }),
|
|
127
127
|
email: T("email", { length: 255 }),
|
|
@@ -166,7 +166,7 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
166
166
|
x("users_linked_to_index").on(e.linked_to),
|
|
167
167
|
x("users_name_index").on(e.name),
|
|
168
168
|
x("users_phone_tenant_provider_index").on(e.tenant_id, e.phone_number, e.provider)
|
|
169
|
-
]),
|
|
169
|
+
]), j = w("passwords", {
|
|
170
170
|
id: T("id", { length: 21 }).primaryKey(),
|
|
171
171
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => O.id, { onDelete: "cascade" }),
|
|
172
172
|
user_id: T("user_id", { length: 255 }).notNull(),
|
|
@@ -175,7 +175,7 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
175
175
|
password: T("password", { length: 255 }).notNull(),
|
|
176
176
|
algorithm: T("algorithm", { length: 16 }).notNull().default("bcrypt"),
|
|
177
177
|
is_current: S("is_current").notNull().default(1)
|
|
178
|
-
}),
|
|
178
|
+
}), Be = w("user_activity", {
|
|
179
179
|
tenant_id: T("tenant_id", { length: 255 }).notNull(),
|
|
180
180
|
user_id: T("user_id", { length: 255 }).notNull(),
|
|
181
181
|
last_login: T("last_login", { length: 35 }),
|
|
@@ -188,9 +188,9 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
188
188
|
name: "user_activity_pkey"
|
|
189
189
|
}), ne({
|
|
190
190
|
columns: [e.user_id, e.tenant_id],
|
|
191
|
-
foreignColumns: [
|
|
191
|
+
foreignColumns: [A.user_id, A.tenant_id],
|
|
192
192
|
name: "user_activity_user_id_constraint"
|
|
193
|
-
}).onDelete("cascade")]),
|
|
193
|
+
}).onDelete("cascade")]), M = w("sessions", {
|
|
194
194
|
id: T("id", { length: 21 }).notNull(),
|
|
195
195
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => O.id, { onDelete: "cascade" }),
|
|
196
196
|
user_id: T("user_id", { length: 255 }),
|
|
@@ -213,7 +213,7 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
213
213
|
x("IDX_sessions_login_session_id").on(e.login_session_id),
|
|
214
214
|
x("idx_sessions_user_id").on(e.tenant_id, e.user_id),
|
|
215
215
|
x("idx_sessions_expires_at_ts").on(e.expires_at_ts)
|
|
216
|
-
]),
|
|
216
|
+
]), N = w("refresh_tokens", {
|
|
217
217
|
id: T("id", { length: 26 }).notNull(),
|
|
218
218
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => O.id, { onDelete: "cascade" }),
|
|
219
219
|
client_id: T("client_id", { length: 191 }).notNull(),
|
|
@@ -248,7 +248,7 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
248
248
|
x("idx_refresh_tokens_token_lookup").on(e.tenant_id, e.token_lookup),
|
|
249
249
|
x("idx_refresh_tokens_family_id").on(e.tenant_id, e.family_id),
|
|
250
250
|
x("idx_refresh_tokens_session_id").on(e.tenant_id, e.session_id)
|
|
251
|
-
]),
|
|
251
|
+
]), P = w("login_sessions", {
|
|
252
252
|
id: T("id", { length: 21 }).notNull(),
|
|
253
253
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => O.id, { onDelete: "cascade" }),
|
|
254
254
|
session_id: T("session_id", { length: 21 }),
|
|
@@ -279,7 +279,7 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
279
279
|
x("login_sessions_state_updated_idx").on(e.state, e.updated_at_ts),
|
|
280
280
|
x("login_sessions_tenant_user_idx").on(e.tenant_id, e.user_id),
|
|
281
281
|
x("idx_login_sessions_expires_at_ts").on(e.expires_at_ts)
|
|
282
|
-
]),
|
|
282
|
+
]), F = w("codes", {
|
|
283
283
|
code_id: T("code_id", { length: 191 }).notNull(),
|
|
284
284
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => O.id, { onDelete: "cascade" }),
|
|
285
285
|
user_id: T("user_id", { length: 255 }),
|
|
@@ -298,7 +298,7 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
298
298
|
}, (e) => [C({
|
|
299
299
|
columns: [e.code_id, e.code_type],
|
|
300
300
|
name: "PK_codes_code_id_code_type"
|
|
301
|
-
}), x("codes_expires_at_index").on(e.expires_at)]),
|
|
301
|
+
}), x("codes_expires_at_index").on(e.expires_at)]), Ve = w("authentication_codes", {
|
|
302
302
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => O.id, { onDelete: "cascade" }),
|
|
303
303
|
code: T("code", { length: 255 }).primaryKey(),
|
|
304
304
|
client_id: T("client_id", { length: 255 }).notNull(),
|
|
@@ -312,7 +312,7 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
312
312
|
created_at: T("created_at", { length: 35 }).notNull(),
|
|
313
313
|
expires_at: T("expires_at", { length: 35 }).notNull(),
|
|
314
314
|
used_at: T("used_at", { length: 35 })
|
|
315
|
-
}),
|
|
315
|
+
}), He = w("otps", {
|
|
316
316
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => O.id, { onDelete: "cascade" }),
|
|
317
317
|
id: T("id", { length: 255 }).primaryKey(),
|
|
318
318
|
client_id: T("client_id", { length: 255 }).notNull(),
|
|
@@ -331,7 +331,7 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
331
331
|
used_at: T("used_at", { length: 35 }),
|
|
332
332
|
audience: T("audience", { length: 255 }),
|
|
333
333
|
ip: T("ip", { length: 64 })
|
|
334
|
-
}, (e) => [x("otps_email_index").on(e.email), x("otps_expires_at_index").on(e.expires_at)]),
|
|
334
|
+
}, (e) => [x("otps_email_index").on(e.email), x("otps_expires_at_index").on(e.expires_at)]), Ue = w("tickets", {
|
|
335
335
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => O.id, { onDelete: "cascade" }),
|
|
336
336
|
id: T("id", { length: 255 }).primaryKey(),
|
|
337
337
|
client_id: T("client_id", { length: 255 }).notNull(),
|
|
@@ -345,7 +345,7 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
345
345
|
created_at: T("created_at", { length: 35 }).notNull(),
|
|
346
346
|
expires_at: T("expires_at", { length: 35 }).notNull(),
|
|
347
347
|
used_at: T("used_at", { length: 35 })
|
|
348
|
-
}),
|
|
348
|
+
}), I = w("clients", {
|
|
349
349
|
client_id: T("client_id", { length: 191 }).notNull(),
|
|
350
350
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => O.id, { onDelete: "cascade" }),
|
|
351
351
|
name: T("name", { length: 255 }).notNull(),
|
|
@@ -405,7 +405,7 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
405
405
|
}, (e) => [C({
|
|
406
406
|
columns: [e.tenant_id, e.client_id],
|
|
407
407
|
name: "clients_tenant_id_client_id"
|
|
408
|
-
}), x("idx_clients_owner_user_id").on(e.tenant_id, e.owner_user_id)]),
|
|
408
|
+
}), x("idx_clients_owner_user_id").on(e.tenant_id, e.owner_user_id)]), L = w("client_registration_tokens", {
|
|
409
409
|
id: T("id", { length: 255 }).primaryKey(),
|
|
410
410
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => O.id, { onDelete: "cascade" }),
|
|
411
411
|
token_hash: T("token_hash", { length: 64 }).notNull(),
|
|
@@ -418,7 +418,7 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
418
418
|
expires_at_ts: S("expires_at_ts"),
|
|
419
419
|
created_at_ts: S("created_at_ts").notNull(),
|
|
420
420
|
revoked_at_ts: S("revoked_at_ts")
|
|
421
|
-
}, (e) => [re("idx_client_registration_tokens_hash").on(e.tenant_id, e.token_hash), x("idx_client_registration_tokens_client").on(e.tenant_id, e.client_id)]),
|
|
421
|
+
}, (e) => [re("idx_client_registration_tokens_hash").on(e.tenant_id, e.token_hash), x("idx_client_registration_tokens_client").on(e.tenant_id, e.client_id)]), R = w("client_grants", {
|
|
422
422
|
id: T("id", { length: 21 }).notNull(),
|
|
423
423
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => O.id, { onDelete: "cascade" }),
|
|
424
424
|
client_id: T("client_id", { length: 191 }).notNull(),
|
|
@@ -431,10 +431,14 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
431
431
|
authorization_details_types: T("authorization_details_types").default("[]"),
|
|
432
432
|
created_at: T("created_at", { length: 35 }).notNull(),
|
|
433
433
|
updated_at: T("updated_at", { length: 35 }).notNull()
|
|
434
|
-
}, (e) => [
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
434
|
+
}, (e) => [
|
|
435
|
+
C({
|
|
436
|
+
columns: [e.tenant_id, e.id],
|
|
437
|
+
name: "pk_client_grants"
|
|
438
|
+
}),
|
|
439
|
+
x("idx_client_grants_audience").on(e.audience),
|
|
440
|
+
re("uq_client_grants_tenant_client_audience").on(e.tenant_id, e.client_id, e.audience)
|
|
441
|
+
]), z = w("grants", {
|
|
438
442
|
id: T("id", { length: 21 }).primaryKey(),
|
|
439
443
|
tenant_id: T("tenant_id", { length: 255 }).notNull().references(() => O.id, { onDelete: "cascade" }),
|
|
440
444
|
user_id: T("user_id", { length: 255 }).notNull(),
|
|
@@ -446,12 +450,12 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
446
450
|
}, (e) => [
|
|
447
451
|
ne({
|
|
448
452
|
columns: [e.user_id, e.tenant_id],
|
|
449
|
-
foreignColumns: [
|
|
453
|
+
foreignColumns: [A.user_id, A.tenant_id],
|
|
450
454
|
name: "grants_user_id_constraint"
|
|
451
455
|
}).onDelete("cascade"),
|
|
452
456
|
re("grants_natural_key_idx").on(e.tenant_id, e.user_id, e.client_id, e.audience),
|
|
453
457
|
x("grants_tenant_user_idx").on(e.tenant_id, e.user_id)
|
|
454
|
-
]),
|
|
458
|
+
]), B = w("connections", {
|
|
455
459
|
id: T("id", { length: 255 }).notNull(),
|
|
456
460
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => O.id, { onDelete: "cascade" }),
|
|
457
461
|
name: T("name", { length: 255 }).notNull(),
|
|
@@ -470,7 +474,7 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
470
474
|
C({ columns: [e.tenant_id, e.id] }),
|
|
471
475
|
x("connections_tenant_id_index").on(e.tenant_id),
|
|
472
476
|
re("connections_id_unique").on(e.id)
|
|
473
|
-
]),
|
|
477
|
+
]), We = w("custom_domains", {
|
|
474
478
|
custom_domain_id: T("custom_domain_id", { length: 256 }).primaryKey(),
|
|
475
479
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => O.id, { onDelete: "cascade" }),
|
|
476
480
|
domain: T("domain", { length: 255 }).notNull(),
|
|
@@ -484,7 +488,7 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
484
488
|
domain_metadata: T("domain_metadata", { length: 2048 }),
|
|
485
489
|
created_at: T("created_at", { length: 35 }).notNull(),
|
|
486
490
|
updated_at: T("updated_at", { length: 35 }).notNull()
|
|
487
|
-
}, (e) => [re("custom_domains_domain_unique").on(e.domain)]),
|
|
491
|
+
}, (e) => [re("custom_domains_domain_unique").on(e.domain)]), Ge = w("domains", {
|
|
488
492
|
id: T("id", { length: 255 }).primaryKey(),
|
|
489
493
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => O.id, { onDelete: "cascade" }),
|
|
490
494
|
domain: T("domain", { length: 255 }).notNull(),
|
|
@@ -494,7 +498,7 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
494
498
|
dkim_public_key: T("dkim_public_key", { length: 2048 }),
|
|
495
499
|
created_at: T("created_at", { length: 35 }).notNull(),
|
|
496
500
|
updated_at: T("updated_at", { length: 35 }).notNull()
|
|
497
|
-
}),
|
|
501
|
+
}), V = w("organizations", {
|
|
498
502
|
id: T("id", { length: 21 }).primaryKey(),
|
|
499
503
|
tenant_id: T("tenant_id", { length: 191 }).notNull(),
|
|
500
504
|
name: T("name", { length: 256 }).notNull(),
|
|
@@ -505,7 +509,7 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
505
509
|
token_quota: T("token_quota"),
|
|
506
510
|
created_at: T("created_at", { length: 35 }).notNull(),
|
|
507
511
|
updated_at: T("updated_at", { length: 35 }).notNull()
|
|
508
|
-
}, (e) => [x("idx_organizations_tenant_id").on(e.tenant_id)]),
|
|
512
|
+
}, (e) => [x("idx_organizations_tenant_id").on(e.tenant_id)]), H = w("user_organizations", {
|
|
509
513
|
id: T("id", { length: 21 }).primaryKey(),
|
|
510
514
|
tenant_id: T("tenant_id", { length: 191 }).notNull(),
|
|
511
515
|
user_id: T("user_id", { length: 191 }).notNull(),
|
|
@@ -517,7 +521,7 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
517
521
|
x("idx_user_organizations_tenant_id").on(e.tenant_id),
|
|
518
522
|
x("idx_user_organizations_user_id").on(e.user_id),
|
|
519
523
|
x("idx_user_organizations_organization_id").on(e.organization_id)
|
|
520
|
-
]),
|
|
524
|
+
]), Ke = w("invites", {
|
|
521
525
|
id: T("id", { length: 21 }).primaryKey(),
|
|
522
526
|
tenant_id: T("tenant_id", { length: 191 }).notNull(),
|
|
523
527
|
organization_id: T("organization_id", { length: 21 }).notNull(),
|
|
@@ -539,7 +543,7 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
539
543
|
x("idx_invites_organization_id").on(e.organization_id),
|
|
540
544
|
x("idx_invites_expires_at").on(e.expires_at),
|
|
541
545
|
x("idx_invites_tenant_created").on(e.tenant_id, e.created_at)
|
|
542
|
-
]),
|
|
546
|
+
]), U = w("roles", {
|
|
543
547
|
id: T("id", { length: 21 }).notNull(),
|
|
544
548
|
tenant_id: T("tenant_id", { length: 191 }).notNull(),
|
|
545
549
|
name: T("name", { length: 50 }).notNull(),
|
|
@@ -551,7 +555,7 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
551
555
|
}, (e) => [C({
|
|
552
556
|
columns: [e.tenant_id, e.id],
|
|
553
557
|
name: "roles_pk"
|
|
554
|
-
})]),
|
|
558
|
+
})]), qe = w("role_permissions", {
|
|
555
559
|
tenant_id: T("tenant_id", { length: 191 }).notNull(),
|
|
556
560
|
role_id: T("role_id", { length: 21 }).notNull(),
|
|
557
561
|
resource_server_identifier: T("resource_server_identifier", { length: 191 }).notNull(),
|
|
@@ -569,7 +573,7 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
569
573
|
}),
|
|
570
574
|
x("role_permissions_role_fk").on(e.tenant_id, e.role_id),
|
|
571
575
|
x("role_permissions_permission_fk").on(e.tenant_id, e.resource_server_identifier, e.permission_name)
|
|
572
|
-
]),
|
|
576
|
+
]), Je = w("user_permissions", {
|
|
573
577
|
tenant_id: T("tenant_id", { length: 191 }).notNull(),
|
|
574
578
|
user_id: T("user_id", { length: 191 }).notNull(),
|
|
575
579
|
resource_server_identifier: T("resource_server_identifier", { length: 191 }).notNull(),
|
|
@@ -590,7 +594,7 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
590
594
|
x("user_permissions_user_fk").on(e.tenant_id, e.user_id),
|
|
591
595
|
x("user_permissions_permission_fk").on(e.tenant_id, e.resource_server_identifier, e.permission_name),
|
|
592
596
|
x("user_permissions_organization_fk").on(e.organization_id)
|
|
593
|
-
]),
|
|
597
|
+
]), W = w("user_roles", {
|
|
594
598
|
tenant_id: T("tenant_id", { length: 191 }).notNull(),
|
|
595
599
|
user_id: T("user_id", { length: 191 }).notNull(),
|
|
596
600
|
role_id: T("role_id", { length: 21 }).notNull(),
|
|
@@ -609,7 +613,7 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
609
613
|
x("user_roles_user_fk").on(e.tenant_id, e.user_id),
|
|
610
614
|
x("user_roles_role_fk").on(e.tenant_id, e.role_id),
|
|
611
615
|
x("user_roles_organization_fk").on(e.organization_id)
|
|
612
|
-
]),
|
|
616
|
+
]), G = w("resource_servers", {
|
|
613
617
|
id: T("id", { length: 21 }).notNull(),
|
|
614
618
|
tenant_id: T("tenant_id", { length: 191 }).notNull(),
|
|
615
619
|
identifier: T("identifier", { length: 191 }).notNull(),
|
|
@@ -630,7 +634,7 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
630
634
|
}, (e) => [C({
|
|
631
635
|
columns: [e.tenant_id, e.id],
|
|
632
636
|
name: "resource_servers_pk"
|
|
633
|
-
})]),
|
|
637
|
+
})]), Ye = w("branding", {
|
|
634
638
|
tenant_id: T("tenant_id", { length: 191 }).primaryKey().references(() => O.id, { onDelete: "cascade" }),
|
|
635
639
|
logo_url: T("logo_url", { length: 512 }),
|
|
636
640
|
favicon_url: T("favicon_url", { length: 512 }),
|
|
@@ -641,12 +645,12 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
641
645
|
colors_page_background_end: T("colors_page_background_end", { length: 8 }),
|
|
642
646
|
colors_page_background_angle_dev: S("colors_page_background_angle_dev"),
|
|
643
647
|
dark_mode: T("dark_mode", { length: 8 })
|
|
644
|
-
}),
|
|
648
|
+
}), Xe = w("universal_login_templates", {
|
|
645
649
|
tenant_id: T("tenant_id", { length: 191 }).primaryKey().references(() => O.id, { onDelete: "cascade" }),
|
|
646
650
|
body: T("body").notNull(),
|
|
647
651
|
created_at_ts: S("created_at_ts").notNull(),
|
|
648
652
|
updated_at_ts: S("updated_at_ts").notNull()
|
|
649
|
-
}),
|
|
653
|
+
}), Ze = w("themes", {
|
|
650
654
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => O.id, { onDelete: "cascade" }),
|
|
651
655
|
themeId: T("themeId", { length: 255 }).notNull(),
|
|
652
656
|
displayName: T("displayName", { length: 255 }).notNull(),
|
|
@@ -706,7 +710,7 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
706
710
|
}, (e) => [C({
|
|
707
711
|
columns: [e.tenant_id, e.themeId],
|
|
708
712
|
name: "themes_pkey"
|
|
709
|
-
}), x("themes_tenant_id_idx").on(e.tenant_id)]),
|
|
713
|
+
}), x("themes_tenant_id_idx").on(e.tenant_id)]), Qe = w("forms", {
|
|
710
714
|
id: T("id", { length: 255 }).primaryKey(),
|
|
711
715
|
name: T("name", { length: 255 }).notNull(),
|
|
712
716
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => O.id, { onDelete: "cascade" }),
|
|
@@ -719,21 +723,21 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
719
723
|
style: T("style", { length: 1042 }),
|
|
720
724
|
created_at: T("created_at", { length: 35 }).notNull(),
|
|
721
725
|
updated_at: T("updated_at", { length: 35 }).notNull()
|
|
722
|
-
}, (e) => [x("forms_tenant_id_idx").on(e.tenant_id)]),
|
|
726
|
+
}, (e) => [x("forms_tenant_id_idx").on(e.tenant_id)]), $e = w("flows", {
|
|
723
727
|
id: T("id", { length: 24 }).primaryKey(),
|
|
724
728
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => O.id, { onDelete: "cascade" }),
|
|
725
729
|
name: T("name", { length: 150 }).notNull(),
|
|
726
730
|
actions: T("actions"),
|
|
727
731
|
created_at: T("created_at", { length: 35 }).notNull(),
|
|
728
732
|
updated_at: T("updated_at", { length: 35 }).notNull()
|
|
729
|
-
}, (e) => [x("flows_tenant_id_idx").on(e.tenant_id)]),
|
|
733
|
+
}, (e) => [x("flows_tenant_id_idx").on(e.tenant_id)]), et = w("prompt_settings", {
|
|
730
734
|
tenant_id: T("tenant_id", { length: 191 }).primaryKey(),
|
|
731
735
|
universal_login_experience: T("universal_login_experience", { length: 16 }).notNull().default("new"),
|
|
732
736
|
identifier_first: S("identifier_first", { mode: "boolean" }).notNull().default(!0),
|
|
733
737
|
password_first: S("password_first", { mode: "boolean" }).notNull().default(!1),
|
|
734
738
|
webauthn_platform_first_factor: S("webauthn_platform_first_factor", { mode: "boolean" }).notNull().default(!1),
|
|
735
739
|
show_last_used_connection: S("show_last_used_connection", { mode: "boolean" }).notNull().default(!1)
|
|
736
|
-
}),
|
|
740
|
+
}), tt = w("email_providers", {
|
|
737
741
|
tenant_id: T("tenant_id", { length: 191 }).primaryKey(),
|
|
738
742
|
name: T("name", { length: 255 }).notNull(),
|
|
739
743
|
enabled: S("enabled", { mode: "boolean" }).notNull(),
|
|
@@ -742,7 +746,7 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
742
746
|
settings: T("settings", { length: 2048 }).notNull().default("{}"),
|
|
743
747
|
created_at: T("created_at", { length: 35 }).notNull(),
|
|
744
748
|
updated_at: T("updated_at", { length: 35 }).notNull()
|
|
745
|
-
}),
|
|
749
|
+
}), nt = w("email_templates", {
|
|
746
750
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => O.id, { onDelete: "cascade" }),
|
|
747
751
|
template: T("template", { length: 64 }).notNull(),
|
|
748
752
|
body: T("body").notNull(),
|
|
@@ -755,7 +759,7 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
755
759
|
enabled: S("enabled", { mode: "boolean" }).notNull().default(!0),
|
|
756
760
|
created_at: T("created_at", { length: 35 }).notNull(),
|
|
757
761
|
updated_at: T("updated_at", { length: 35 }).notNull()
|
|
758
|
-
}, (e) => [C({ columns: [e.tenant_id, e.template] })]),
|
|
762
|
+
}, (e) => [C({ columns: [e.tenant_id, e.template] })]), rt = w("hooks", {
|
|
759
763
|
hook_id: T("hook_id", { length: 21 }).primaryKey(),
|
|
760
764
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => O.id, { onDelete: "cascade" }),
|
|
761
765
|
url: T("url", { length: 512 }),
|
|
@@ -771,14 +775,14 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
771
775
|
page_id: T("page_id", { length: 64 }),
|
|
772
776
|
permission_required: T("permission_required", { length: 255 }),
|
|
773
777
|
metadata: T("metadata")
|
|
774
|
-
}, (e) => [x("hooks_tenant_id_idx").on(e.tenant_id)]),
|
|
778
|
+
}, (e) => [x("hooks_tenant_id_idx").on(e.tenant_id)]), it = w("hook_code", {
|
|
775
779
|
id: T("id", { length: 21 }).primaryKey(),
|
|
776
780
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => O.id, { onDelete: "cascade" }),
|
|
777
781
|
code: T("code").notNull(),
|
|
778
782
|
secrets: T("secrets"),
|
|
779
783
|
created_at_ts: S("created_at_ts").notNull(),
|
|
780
784
|
updated_at_ts: S("updated_at_ts").notNull()
|
|
781
|
-
}, (e) => [x("hook_code_tenant_id_idx").on(e.tenant_id)]),
|
|
785
|
+
}, (e) => [x("hook_code_tenant_id_idx").on(e.tenant_id)]), at = w("keys", {
|
|
782
786
|
kid: T("kid", { length: 255 }).primaryKey(),
|
|
783
787
|
tenant_id: T("tenant_id", { length: 191 }).references(() => O.id, { onDelete: "cascade" }),
|
|
784
788
|
created_at: T("created_at", { length: 35 }).notNull(),
|
|
@@ -790,8 +794,8 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
790
794
|
current_since: T("current_since", { length: 35 }),
|
|
791
795
|
current_until: T("current_until", { length: 35 }),
|
|
792
796
|
type: T("type", { length: 50 }).notNull().default("jwt_signing"),
|
|
793
|
-
connection: T("connection", { length: 255 }).references(() =>
|
|
794
|
-
}),
|
|
797
|
+
connection: T("connection", { length: 255 }).references(() => B.id, { onDelete: "cascade" })
|
|
798
|
+
}), ot = w("custom_text", {
|
|
795
799
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => O.id, { onDelete: "cascade" }),
|
|
796
800
|
prompt: T("prompt", { length: 64 }).notNull(),
|
|
797
801
|
language: T("language", { length: 16 }).notNull(),
|
|
@@ -802,7 +806,7 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
802
806
|
e.tenant_id,
|
|
803
807
|
e.prompt,
|
|
804
808
|
e.language
|
|
805
|
-
] })]),
|
|
809
|
+
] })]), K = w("authentication_methods", {
|
|
806
810
|
id: T("id", { length: 26 }).primaryKey(),
|
|
807
811
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => O.id, { onDelete: "cascade" }),
|
|
808
812
|
user_id: T("user_id", { length: 255 }).notNull(),
|
|
@@ -818,7 +822,7 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
818
822
|
confirmed: S("confirmed").notNull().default(0),
|
|
819
823
|
created_at_ts: S("created_at_ts").notNull(),
|
|
820
824
|
updated_at_ts: S("updated_at_ts").notNull()
|
|
821
|
-
}, (e) => [x("authentication_methods_tenant_user_idx").on(e.tenant_id, e.user_id), x("authentication_methods_credential_id_idx").on(e.credential_id)]),
|
|
825
|
+
}, (e) => [x("authentication_methods_tenant_user_idx").on(e.tenant_id, e.user_id), x("authentication_methods_credential_id_idx").on(e.credential_id)]), q = w("logs", {
|
|
822
826
|
log_id: T("log_id", { length: 21 }).primaryKey(),
|
|
823
827
|
category: T("category", { length: 255 }),
|
|
824
828
|
tenant_id: T("tenant_id", { length: 64 }),
|
|
@@ -853,7 +857,7 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
853
857
|
x("logs_tenant_id").on(e.tenant_id),
|
|
854
858
|
x("logs_date").on(e.date),
|
|
855
859
|
x("IDX_logs_tenant_date_type_user").on(e.tenant_id, e.date, e.type, e.user_id)
|
|
856
|
-
]),
|
|
860
|
+
]), J = w("outbox_events", {
|
|
857
861
|
id: T("id", { length: 26 }).primaryKey(),
|
|
858
862
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => O.id, { onDelete: "cascade" }),
|
|
859
863
|
event_type: T("event_type", { length: 64 }).notNull(),
|
|
@@ -875,7 +879,7 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
875
879
|
x("idx_outbox_events_processed_at").on(e.processed_at),
|
|
876
880
|
x("idx_outbox_events_claimed_by").on(e.claimed_by),
|
|
877
881
|
x("idx_outbox_events_tenant_dead_lettered").on(e.tenant_id, e.dead_lettered_at)
|
|
878
|
-
]),
|
|
882
|
+
]), Y = w("proxy_routes", {
|
|
879
883
|
id: T("id", { length: 64 }).primaryKey(),
|
|
880
884
|
tenant_id: T("tenant_id", { length: 255 }).notNull(),
|
|
881
885
|
custom_domain_id: T("custom_domain_id", { length: 256 }).notNull(),
|
|
@@ -884,14 +888,14 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
884
888
|
handlers: T("handlers", { length: 16384 }).notNull().default("[]"),
|
|
885
889
|
created_at: T("created_at", { length: 35 }).notNull(),
|
|
886
890
|
updated_at: T("updated_at", { length: 35 }).notNull()
|
|
887
|
-
}, (e) => [x("proxy_routes_tenant_id_idx").on(e.tenant_id), x("proxy_routes_custom_domain_id_idx").on(e.custom_domain_id)]),
|
|
891
|
+
}, (e) => [x("proxy_routes_tenant_id_idx").on(e.tenant_id), x("proxy_routes_custom_domain_id_idx").on(e.custom_domain_id)]), st = w("scim_configurations", {
|
|
888
892
|
connection_id: T("connection_id", { length: 255 }).notNull(),
|
|
889
893
|
tenant_id: T("tenant_id", { length: 255 }).notNull(),
|
|
890
894
|
user_id_attribute: T("user_id_attribute", { length: 255 }).notNull().default("externalId"),
|
|
891
895
|
mapping: T("mapping", { length: 16384 }).notNull().default("[]"),
|
|
892
896
|
created_at: T("created_at", { length: 35 }).notNull(),
|
|
893
897
|
updated_at: T("updated_at", { length: 35 }).notNull()
|
|
894
|
-
}, (e) => [C({ columns: [e.tenant_id, e.connection_id] })]),
|
|
898
|
+
}, (e) => [C({ columns: [e.tenant_id, e.connection_id] })]), X = w("scim_tokens", {
|
|
895
899
|
token_id: T("token_id", { length: 64 }).notNull(),
|
|
896
900
|
tenant_id: T("tenant_id", { length: 255 }).notNull(),
|
|
897
901
|
connection_id: T("connection_id", { length: 255 }).notNull(),
|
|
@@ -904,7 +908,7 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
904
908
|
C({ columns: [e.tenant_id, e.token_id] }),
|
|
905
909
|
x("scim_tokens_tenant_connection_idx").on(e.tenant_id, e.connection_id),
|
|
906
910
|
re("scim_tokens_tenant_hash_idx").on(e.tenant_id, e.token_hash)
|
|
907
|
-
]),
|
|
911
|
+
]), ct = w("scim_external_ids", {
|
|
908
912
|
tenant_id: T("tenant_id", { length: 255 }).notNull(),
|
|
909
913
|
connection_id: T("connection_id", { length: 255 }).notNull(),
|
|
910
914
|
external_id: T("external_id", { length: 255 }).notNull(),
|
|
@@ -914,59 +918,59 @@ var Pe = Object.defineProperty, Fe = (e, t) => {
|
|
|
914
918
|
e.tenant_id,
|
|
915
919
|
e.connection_id,
|
|
916
920
|
e.user_id
|
|
917
|
-
] }), re("scim_external_ids_connection_external_idx").on(e.tenant_id, e.connection_id, e.external_id)]),
|
|
918
|
-
actionExecutions: () =>
|
|
919
|
-
actionVersions: () =>
|
|
920
|
-
actions: () =>
|
|
921
|
-
authenticationCodes: () =>
|
|
922
|
-
authenticationMethods: () =>
|
|
923
|
-
branding: () =>
|
|
924
|
-
clientGrants: () =>
|
|
925
|
-
clientRegistrationTokens: () =>
|
|
926
|
-
clients: () =>
|
|
927
|
-
codes: () =>
|
|
928
|
-
connections: () =>
|
|
929
|
-
customDomains: () =>
|
|
930
|
-
customText: () =>
|
|
931
|
-
domains: () =>
|
|
932
|
-
emailProviders: () =>
|
|
933
|
-
emailTemplates: () =>
|
|
934
|
-
flows: () =>
|
|
935
|
-
forms: () =>
|
|
936
|
-
grants: () =>
|
|
937
|
-
hookCode: () =>
|
|
938
|
-
hooks: () =>
|
|
939
|
-
invites: () =>
|
|
940
|
-
keys: () =>
|
|
941
|
-
loginSessions: () =>
|
|
942
|
-
logs: () =>
|
|
943
|
-
organizations: () =>
|
|
944
|
-
otps: () =>
|
|
945
|
-
outboxEvents: () =>
|
|
946
|
-
passwords: () =>
|
|
947
|
-
promptSettings: () =>
|
|
948
|
-
proxyRoutes: () =>
|
|
949
|
-
refreshTokens: () =>
|
|
950
|
-
resourceServers: () =>
|
|
951
|
-
rolePermissions: () =>
|
|
952
|
-
roles: () =>
|
|
953
|
-
scimConfigurations: () =>
|
|
954
|
-
scimExternalIds: () =>
|
|
955
|
-
scimTokens: () =>
|
|
956
|
-
sessions: () =>
|
|
921
|
+
] }), re("scim_external_ids_connection_external_idx").on(e.tenant_id, e.connection_id, e.external_id)]), lt = /* @__PURE__ */ Le({
|
|
922
|
+
actionExecutions: () => ze,
|
|
923
|
+
actionVersions: () => k,
|
|
924
|
+
actions: () => Re,
|
|
925
|
+
authenticationCodes: () => Ve,
|
|
926
|
+
authenticationMethods: () => K,
|
|
927
|
+
branding: () => Ye,
|
|
928
|
+
clientGrants: () => R,
|
|
929
|
+
clientRegistrationTokens: () => L,
|
|
930
|
+
clients: () => I,
|
|
931
|
+
codes: () => F,
|
|
932
|
+
connections: () => B,
|
|
933
|
+
customDomains: () => We,
|
|
934
|
+
customText: () => ot,
|
|
935
|
+
domains: () => Ge,
|
|
936
|
+
emailProviders: () => tt,
|
|
937
|
+
emailTemplates: () => nt,
|
|
938
|
+
flows: () => $e,
|
|
939
|
+
forms: () => Qe,
|
|
940
|
+
grants: () => z,
|
|
941
|
+
hookCode: () => it,
|
|
942
|
+
hooks: () => rt,
|
|
943
|
+
invites: () => Ke,
|
|
944
|
+
keys: () => at,
|
|
945
|
+
loginSessions: () => P,
|
|
946
|
+
logs: () => q,
|
|
947
|
+
organizations: () => V,
|
|
948
|
+
otps: () => He,
|
|
949
|
+
outboxEvents: () => J,
|
|
950
|
+
passwords: () => j,
|
|
951
|
+
promptSettings: () => et,
|
|
952
|
+
proxyRoutes: () => Y,
|
|
953
|
+
refreshTokens: () => N,
|
|
954
|
+
resourceServers: () => G,
|
|
955
|
+
rolePermissions: () => qe,
|
|
956
|
+
roles: () => U,
|
|
957
|
+
scimConfigurations: () => st,
|
|
958
|
+
scimExternalIds: () => ct,
|
|
959
|
+
scimTokens: () => X,
|
|
960
|
+
sessions: () => M,
|
|
957
961
|
tenants: () => O,
|
|
958
|
-
themes: () =>
|
|
959
|
-
tickets: () =>
|
|
960
|
-
universalLoginTemplates: () =>
|
|
961
|
-
userActivity: () =>
|
|
962
|
-
userOrganizations: () =>
|
|
963
|
-
userPermissions: () =>
|
|
964
|
-
userRoles: () =>
|
|
965
|
-
users: () =>
|
|
962
|
+
themes: () => Ze,
|
|
963
|
+
tickets: () => Ue,
|
|
964
|
+
universalLoginTemplates: () => Xe,
|
|
965
|
+
userActivity: () => Be,
|
|
966
|
+
userOrganizations: () => H,
|
|
967
|
+
userPermissions: () => Je,
|
|
968
|
+
userRoles: () => W,
|
|
969
|
+
users: () => A
|
|
966
970
|
});
|
|
967
971
|
//#endregion
|
|
968
972
|
//#region src/helpers/transform.ts
|
|
969
|
-
function
|
|
973
|
+
function Z(e, t) {
|
|
970
974
|
if (e == null) return t;
|
|
971
975
|
if (typeof e == "string") try {
|
|
972
976
|
return JSON.parse(e);
|
|
@@ -975,14 +979,14 @@ function Q(e, t) {
|
|
|
975
979
|
}
|
|
976
980
|
return e;
|
|
977
981
|
}
|
|
978
|
-
function
|
|
982
|
+
function ut(e, t = "", n = {}) {
|
|
979
983
|
for (let r in e) if (Object.prototype.hasOwnProperty.call(e, r)) {
|
|
980
984
|
let i = t ? `${t}_${r}` : r, a = e[r];
|
|
981
|
-
typeof a == "object" && a && !Array.isArray(a) ?
|
|
985
|
+
typeof a == "object" && a && !Array.isArray(a) ? ut(a, i, n) : typeof a == "boolean" ? n[i] = +!!a : n[i] = a;
|
|
982
986
|
}
|
|
983
987
|
return n;
|
|
984
988
|
}
|
|
985
|
-
function
|
|
989
|
+
function dt(e, t) {
|
|
986
990
|
let n = {};
|
|
987
991
|
for (let [r, i] of Object.entries(e)) {
|
|
988
992
|
let e = t.find((e) => r.startsWith(`${e}_`));
|
|
@@ -999,13 +1003,13 @@ function ct(e, t) {
|
|
|
999
1003
|
}
|
|
1000
1004
|
//#endregion
|
|
1001
1005
|
//#region src/helpers/filter.ts
|
|
1002
|
-
function
|
|
1006
|
+
function ft(e) {
|
|
1003
1007
|
return typeof e == "object" && !!e && "coalesce" in e && "defaultValue" in e;
|
|
1004
1008
|
}
|
|
1005
|
-
function
|
|
1009
|
+
function pt(e) {
|
|
1006
1010
|
return y`coalesce(${e.coalesce}, ${e.defaultValue})`;
|
|
1007
1011
|
}
|
|
1008
|
-
function
|
|
1012
|
+
function mt(n, r, i, l = []) {
|
|
1009
1013
|
let ee = u(n, te) ? o(n) : n, b = new Set(l), ne = (e) => {
|
|
1010
1014
|
let t = Number(e);
|
|
1011
1015
|
return Number.isFinite(t) ? t : e;
|
|
@@ -1017,8 +1021,8 @@ function dt(n, r, i, l = []) {
|
|
|
1017
1021
|
if (!n) return null;
|
|
1018
1022
|
let [, r, i] = n;
|
|
1019
1023
|
if (!r || !i) return null;
|
|
1020
|
-
let o = r.trim(), s =
|
|
1021
|
-
return
|
|
1024
|
+
let o = r.trim(), s = Pe(i.replace(/^"(.*)"$/, "$1").trim()), c = ee[o];
|
|
1025
|
+
return ft(c) ? a(pt(c), ne(s)) : u(c, e) ? b.has(o) ? p(c, `%${s}%`) : a(c, s) : null;
|
|
1022
1026
|
}).filter((e) => e !== null);
|
|
1023
1027
|
return r.length === 0 ? null : r.length === 1 ? r[0] : t(...r) ?? null;
|
|
1024
1028
|
}).filter((e) => e !== null);
|
|
@@ -1030,8 +1034,8 @@ function dt(n, r, i, l = []) {
|
|
|
1030
1034
|
else if (e.startsWith("_exists_:")) n = e.substring(9), i = !0, t = !1;
|
|
1031
1035
|
else if (e.includes(":")) {
|
|
1032
1036
|
let o = t ? e.substring(1) : e, s = o.indexOf(":");
|
|
1033
|
-
n = o.substring(0, s), r = o.substring(s + 1), i = !1, r.startsWith(">=") ? (a = ">=", r = r.substring(2)) : r.startsWith(">") ? (a = ">", r = r.substring(1)) : r.startsWith("<=") ? (a = "<=", r = r.substring(2)) : r.startsWith("<") ? (a = "<", r = r.substring(1)) : a = "=", r.startsWith("\"") && r.endsWith("\"") && r.length > 1 && (r = r.slice(1, -1)), r =
|
|
1034
|
-
} else n = null, r =
|
|
1037
|
+
n = o.substring(0, s), r = o.substring(s + 1), i = !1, r.startsWith(">=") ? (a = ">=", r = r.substring(2)) : r.startsWith(">") ? (a = ">", r = r.substring(1)) : r.startsWith("<=") ? (a = "<=", r = r.substring(2)) : r.startsWith("<") ? (a = "<", r = r.substring(1)) : a = "=", r.startsWith("\"") && r.endsWith("\"") && r.length > 1 && (r = r.slice(1, -1)), r = Pe(r);
|
|
1038
|
+
} else n = null, r = Pe(e), i = !1;
|
|
1035
1039
|
return {
|
|
1036
1040
|
key: n,
|
|
1037
1041
|
value: r,
|
|
@@ -1041,12 +1045,12 @@ function dt(n, r, i, l = []) {
|
|
|
1041
1045
|
};
|
|
1042
1046
|
}), C = [];
|
|
1043
1047
|
for (let { key: t, value: n, isNegation: r, isExistsQuery: o, operator: l } of S) if (t) {
|
|
1044
|
-
let i = ee[t], v =
|
|
1048
|
+
let i = ee[t], v = ft(i), te = v ? i.coalesce : u(i, e) ? i : void 0, x = v ? ne(n) : n;
|
|
1045
1049
|
if (!te) {
|
|
1046
1050
|
o ? C.push(r ? y`${y.identifier(t)} IS NULL` : y`${y.identifier(t)} IS NOT NULL`) : C.push(y`${y.identifier(t)} ${y.raw(r ? "!=" : l ?? "=")} ${n}`);
|
|
1047
1051
|
continue;
|
|
1048
1052
|
}
|
|
1049
|
-
let S = v ?
|
|
1053
|
+
let S = v ? pt(i) : y`${te}`;
|
|
1050
1054
|
if (o) C.push(r ? f(te) : d(te));
|
|
1051
1055
|
else if (b.has(t) && l === "=") C.push(r ? _(te, `%${n}%`) : p(te, `%${n}%`));
|
|
1052
1056
|
else if (r) switch (l) {
|
|
@@ -1095,11 +1099,11 @@ function dt(n, r, i, l = []) {
|
|
|
1095
1099
|
}
|
|
1096
1100
|
//#endregion
|
|
1097
1101
|
//#region src/adapters/actions.ts
|
|
1098
|
-
function
|
|
1099
|
-
let t =
|
|
1102
|
+
function ht(e) {
|
|
1103
|
+
let t = Z(e);
|
|
1100
1104
|
return Array.isArray(t) ? t : [];
|
|
1101
1105
|
}
|
|
1102
|
-
function
|
|
1106
|
+
function gt(e) {
|
|
1103
1107
|
let { created_at_ts: t, updated_at_ts: n, deployed_at_ts: r, secrets: i, dependencies: a, supported_triggers: o, is_system: s, inherit: c, tenant_id: l, runtime: u, status: d, ...f } = e;
|
|
1104
1108
|
return {
|
|
1105
1109
|
...f,
|
|
@@ -1107,20 +1111,20 @@ function pt(e) {
|
|
|
1107
1111
|
runtime: u ?? void 0,
|
|
1108
1112
|
status: d || "built",
|
|
1109
1113
|
deployed_at: r ? new Date(Number(r)).toISOString() : void 0,
|
|
1110
|
-
secrets:
|
|
1111
|
-
dependencies:
|
|
1112
|
-
supported_triggers:
|
|
1114
|
+
secrets: Z(i),
|
|
1115
|
+
dependencies: Z(a),
|
|
1116
|
+
supported_triggers: Z(o),
|
|
1113
1117
|
is_system: !!s,
|
|
1114
1118
|
inherit: !!c,
|
|
1115
1119
|
created_at: new Date(Number(t)).toISOString(),
|
|
1116
1120
|
updated_at: new Date(Number(n)).toISOString()
|
|
1117
1121
|
};
|
|
1118
1122
|
}
|
|
1119
|
-
function
|
|
1123
|
+
function _t(e) {
|
|
1120
1124
|
return {
|
|
1121
1125
|
async create(t, n) {
|
|
1122
1126
|
let r = Date.now(), i = `act_${b()}`;
|
|
1123
|
-
return await e.insert(
|
|
1127
|
+
return await e.insert(Re).values({
|
|
1124
1128
|
id: i,
|
|
1125
1129
|
tenant_id: t,
|
|
1126
1130
|
name: n.name,
|
|
@@ -1151,28 +1155,28 @@ function mt(e) {
|
|
|
1151
1155
|
};
|
|
1152
1156
|
},
|
|
1153
1157
|
async get(n, r) {
|
|
1154
|
-
let i = await e.select().from(
|
|
1155
|
-
return i ?
|
|
1158
|
+
let i = await e.select().from(Re).where(t(a(Re.tenant_id, n), a(Re.id, r))).get();
|
|
1159
|
+
return i ? gt(i) : null;
|
|
1156
1160
|
},
|
|
1157
1161
|
async list(o, s = {}) {
|
|
1158
|
-
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s, p = [a(
|
|
1162
|
+
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s, p = [a(Re.tenant_id, o)];
|
|
1159
1163
|
if (f) {
|
|
1160
|
-
let e =
|
|
1164
|
+
let e = mt(Re, f, ["name"]);
|
|
1161
1165
|
e && p.push(e);
|
|
1162
1166
|
}
|
|
1163
|
-
let m = t(...p), h = e.select().from(
|
|
1167
|
+
let m = t(...p), h = e.select().from(Re).where(m).$dynamic();
|
|
1164
1168
|
if (d?.sort_by) {
|
|
1165
|
-
let e =
|
|
1169
|
+
let e = Re[d.sort_by];
|
|
1166
1170
|
e && (h = h.orderBy(d.sort_order === "desc" ? i(e) : n(e)));
|
|
1167
1171
|
}
|
|
1168
|
-
let g = (await h.offset(c * l).limit(l)).map(
|
|
1172
|
+
let g = (await h.offset(c * l).limit(l)).map(gt);
|
|
1169
1173
|
if (!u) return {
|
|
1170
1174
|
actions: g,
|
|
1171
1175
|
start: 0,
|
|
1172
1176
|
limit: 0,
|
|
1173
1177
|
length: 0
|
|
1174
1178
|
};
|
|
1175
|
-
let [_] = await e.select({ count: r() }).from(
|
|
1179
|
+
let [_] = await e.select({ count: r() }).from(Re).where(m);
|
|
1176
1180
|
return {
|
|
1177
1181
|
actions: g,
|
|
1178
1182
|
start: c * l,
|
|
@@ -1183,7 +1187,7 @@ function mt(e) {
|
|
|
1183
1187
|
async update(n, r, i) {
|
|
1184
1188
|
let o = { updated_at_ts: Date.now() };
|
|
1185
1189
|
if (i.name !== void 0 && (o.name = i.name), i.code !== void 0 && (o.code = i.code), i.runtime !== void 0 && (o.runtime = i.runtime), i.secrets !== void 0) {
|
|
1186
|
-
let s = await e.select({ secrets:
|
|
1190
|
+
let s = await e.select({ secrets: Re.secrets }).from(Re).where(t(a(Re.tenant_id, n), a(Re.id, r))).get(), c = new Map(ht(s?.secrets).map((e) => [e.name, e])), l = i.secrets.map((e) => e.value === void 0 ? {
|
|
1187
1191
|
name: e.name,
|
|
1188
1192
|
value: c.get(e.name)?.value
|
|
1189
1193
|
} : e);
|
|
@@ -1193,21 +1197,21 @@ function mt(e) {
|
|
|
1193
1197
|
let e = new Date(i.deployed_at).getTime();
|
|
1194
1198
|
Number.isFinite(e) && (o.deployed_at_ts = e);
|
|
1195
1199
|
}
|
|
1196
|
-
return i.is_system !== void 0 && (o.is_system = +!!i.is_system), i.inherit !== void 0 && (o.inherit = +!!i.inherit), (await e.update(
|
|
1200
|
+
return i.is_system !== void 0 && (o.is_system = +!!i.is_system), i.inherit !== void 0 && (o.inherit = +!!i.inherit), (await e.update(Re).set(o).where(t(a(Re.tenant_id, n), a(Re.id, r))).returning()).length > 0;
|
|
1197
1201
|
},
|
|
1198
1202
|
async remove(n, r) {
|
|
1199
|
-
return (await e.delete(
|
|
1203
|
+
return (await e.delete(Re).where(t(a(Re.tenant_id, n), a(Re.id, r))).returning()).length > 0;
|
|
1200
1204
|
}
|
|
1201
1205
|
};
|
|
1202
1206
|
}
|
|
1203
1207
|
//#endregion
|
|
1204
1208
|
//#region src/adapters/actionExecutions.ts
|
|
1205
|
-
var
|
|
1206
|
-
function
|
|
1209
|
+
var vt = 500;
|
|
1210
|
+
function yt(e) {
|
|
1207
1211
|
return {
|
|
1208
1212
|
async create(t, n) {
|
|
1209
1213
|
let r = Date.now();
|
|
1210
|
-
return await e.insert(
|
|
1214
|
+
return await e.insert(ze).values({
|
|
1211
1215
|
id: n.id,
|
|
1212
1216
|
tenant_id: t,
|
|
1213
1217
|
trigger_id: n.trigger_id,
|
|
@@ -1228,14 +1232,14 @@ function gt(e) {
|
|
|
1228
1232
|
};
|
|
1229
1233
|
},
|
|
1230
1234
|
async get(n, r) {
|
|
1231
|
-
let i = await e.select().from(
|
|
1235
|
+
let i = await e.select().from(ze).where(t(a(ze.tenant_id, n), a(ze.id, r))).get();
|
|
1232
1236
|
return i ? {
|
|
1233
1237
|
id: i.id,
|
|
1234
1238
|
tenant_id: i.tenant_id,
|
|
1235
1239
|
trigger_id: i.trigger_id,
|
|
1236
1240
|
status: i.status,
|
|
1237
|
-
results:
|
|
1238
|
-
logs:
|
|
1241
|
+
results: Z(i.results) ?? [],
|
|
1242
|
+
logs: Z(i.logs),
|
|
1239
1243
|
created_at: new Date(Number(i.created_at_ts)).toISOString(),
|
|
1240
1244
|
updated_at: new Date(Number(i.updated_at_ts)).toISOString()
|
|
1241
1245
|
} : null;
|
|
@@ -1245,8 +1249,8 @@ function gt(e) {
|
|
|
1245
1249
|
if (Number.isNaN(n)) throw Error(`Invalid olderThan date: ${t}`);
|
|
1246
1250
|
let r = 0;
|
|
1247
1251
|
for (;;) {
|
|
1248
|
-
let t = await e.delete(
|
|
1249
|
-
if (r += t.length, t.length <
|
|
1252
|
+
let t = await e.delete(ze).where(y`rowid IN (SELECT rowid FROM ${ze} WHERE ${ze.created_at_ts} < ${n} LIMIT ${vt})`).returning({ id: ze.id });
|
|
1253
|
+
if (r += t.length, t.length < vt) break;
|
|
1250
1254
|
}
|
|
1251
1255
|
return r;
|
|
1252
1256
|
}
|
|
@@ -1254,12 +1258,12 @@ function gt(e) {
|
|
|
1254
1258
|
}
|
|
1255
1259
|
//#endregion
|
|
1256
1260
|
//#region src/adapters/atomic.ts
|
|
1257
|
-
function
|
|
1261
|
+
function bt(e) {
|
|
1258
1262
|
let t = e;
|
|
1259
1263
|
return typeof t == "object" && !!t && "batch" in t && typeof t.batch == "function";
|
|
1260
1264
|
}
|
|
1261
|
-
async function
|
|
1262
|
-
if (
|
|
1265
|
+
async function xt(e, t) {
|
|
1266
|
+
if (bt(e)) return e.batch(t);
|
|
1263
1267
|
await e.run(y`BEGIN`);
|
|
1264
1268
|
try {
|
|
1265
1269
|
let n = [];
|
|
@@ -1276,23 +1280,23 @@ async function vt(e, t) {
|
|
|
1276
1280
|
}
|
|
1277
1281
|
//#endregion
|
|
1278
1282
|
//#region src/adapters/actionVersions.ts
|
|
1279
|
-
function
|
|
1283
|
+
function St(e) {
|
|
1280
1284
|
let { created_at_ts: t, updated_at_ts: n, secrets: r, dependencies: i, supported_triggers: a, deployed: o, runtime: s, ...c } = e;
|
|
1281
1285
|
return {
|
|
1282
1286
|
...c,
|
|
1283
1287
|
runtime: s ?? void 0,
|
|
1284
1288
|
deployed: !!o,
|
|
1285
|
-
secrets:
|
|
1286
|
-
dependencies:
|
|
1287
|
-
supported_triggers:
|
|
1289
|
+
secrets: Z(r),
|
|
1290
|
+
dependencies: Z(i),
|
|
1291
|
+
supported_triggers: Z(a),
|
|
1288
1292
|
created_at: new Date(Number(t)).toISOString(),
|
|
1289
1293
|
updated_at: new Date(Number(n)).toISOString()
|
|
1290
1294
|
};
|
|
1291
1295
|
}
|
|
1292
|
-
function
|
|
1296
|
+
function Ct(e) {
|
|
1293
1297
|
return {
|
|
1294
1298
|
async create(n, r) {
|
|
1295
|
-
let o = Date.now(), s = `ver_${b()}`, c = r.deployed !== !1, l = ((await e.select({ number:
|
|
1299
|
+
let o = Date.now(), s = `ver_${b()}`, c = r.deployed !== !1, l = ((await e.select({ number: k.number }).from(k).where(t(a(k.tenant_id, n), a(k.action_id, r.action_id))).orderBy(i(k.number)).limit(1).get())?.number ?? 0) + 1, u = e.insert(k).values({
|
|
1296
1300
|
id: s,
|
|
1297
1301
|
tenant_id: n,
|
|
1298
1302
|
action_id: r.action_id,
|
|
@@ -1306,10 +1310,10 @@ function bt(e) {
|
|
|
1306
1310
|
created_at_ts: o,
|
|
1307
1311
|
updated_at_ts: o
|
|
1308
1312
|
});
|
|
1309
|
-
return await
|
|
1313
|
+
return await xt(e, c ? [e.update(k).set({
|
|
1310
1314
|
deployed: 0,
|
|
1311
1315
|
updated_at_ts: o
|
|
1312
|
-
}).where(t(a(
|
|
1316
|
+
}).where(t(a(k.tenant_id, n), a(k.action_id, r.action_id), a(k.deployed, 1))), u] : [u]), {
|
|
1313
1317
|
id: s,
|
|
1314
1318
|
tenant_id: n,
|
|
1315
1319
|
action_id: r.action_id,
|
|
@@ -1325,18 +1329,18 @@ function bt(e) {
|
|
|
1325
1329
|
};
|
|
1326
1330
|
},
|
|
1327
1331
|
async get(n, r, i) {
|
|
1328
|
-
let o = await e.select().from(
|
|
1329
|
-
return o ?
|
|
1332
|
+
let o = await e.select().from(k).where(t(a(k.tenant_id, n), a(k.action_id, r), a(k.id, i))).get();
|
|
1333
|
+
return o ? St(o) : null;
|
|
1330
1334
|
},
|
|
1331
1335
|
async list(n, o, s = {}) {
|
|
1332
|
-
let { page: c = 0, per_page: l = 50, include_totals: u = !1 } = s, d = t(a(
|
|
1336
|
+
let { page: c = 0, per_page: l = 50, include_totals: u = !1 } = s, d = t(a(k.tenant_id, n), a(k.action_id, o)), f = (await e.select().from(k).where(d).orderBy(i(k.number)).offset(c * l).limit(l)).map(St);
|
|
1333
1337
|
if (!u) return {
|
|
1334
1338
|
versions: f,
|
|
1335
1339
|
start: 0,
|
|
1336
1340
|
limit: 0,
|
|
1337
1341
|
length: 0
|
|
1338
1342
|
};
|
|
1339
|
-
let [p] = await e.select({ count: r() }).from(
|
|
1343
|
+
let [p] = await e.select({ count: r() }).from(k).where(d);
|
|
1340
1344
|
return {
|
|
1341
1345
|
versions: f,
|
|
1342
1346
|
start: c * l,
|
|
@@ -1345,19 +1349,19 @@ function bt(e) {
|
|
|
1345
1349
|
};
|
|
1346
1350
|
},
|
|
1347
1351
|
async removeForAction(n, r) {
|
|
1348
|
-
return (await e.delete(
|
|
1352
|
+
return (await e.delete(k).where(t(a(k.tenant_id, n), a(k.action_id, r))).returning()).length;
|
|
1349
1353
|
}
|
|
1350
1354
|
};
|
|
1351
1355
|
}
|
|
1352
1356
|
//#endregion
|
|
1353
1357
|
//#region src/adapters/branding.ts
|
|
1354
|
-
function
|
|
1358
|
+
function wt(e) {
|
|
1355
1359
|
return e === "dark" || e === "light" || e === "auto";
|
|
1356
1360
|
}
|
|
1357
|
-
function
|
|
1361
|
+
function Tt(e) {
|
|
1358
1362
|
return {
|
|
1359
1363
|
async get(t) {
|
|
1360
|
-
let n = await e.select().from(
|
|
1364
|
+
let n = await e.select().from(Ye).where(a(Ye.tenant_id, t)).get();
|
|
1361
1365
|
if (!n) return null;
|
|
1362
1366
|
let { tenant_id: r, colors_primary: i, colors_page_background_type: o, colors_page_background_start: s, colors_page_background_end: c, colors_page_background_angle_dev: l, font_url: u, dark_mode: d, ...f } = n;
|
|
1363
1367
|
return D({
|
|
@@ -1372,7 +1376,7 @@ function St(e) {
|
|
|
1372
1376
|
}
|
|
1373
1377
|
},
|
|
1374
1378
|
font: u ? { url: u } : void 0,
|
|
1375
|
-
dark_mode:
|
|
1379
|
+
dark_mode: wt(d) ? d : void 0
|
|
1376
1380
|
});
|
|
1377
1381
|
},
|
|
1378
1382
|
async set(t, n) {
|
|
@@ -1386,11 +1390,11 @@ function St(e) {
|
|
|
1386
1390
|
font_url: i?.url,
|
|
1387
1391
|
dark_mode: a
|
|
1388
1392
|
};
|
|
1389
|
-
await e.insert(
|
|
1393
|
+
await e.insert(Ye).values({
|
|
1390
1394
|
tenant_id: t,
|
|
1391
1395
|
...l
|
|
1392
1396
|
}).onConflictDoUpdate({
|
|
1393
|
-
target:
|
|
1397
|
+
target: Ye.tenant_id,
|
|
1394
1398
|
set: l
|
|
1395
1399
|
});
|
|
1396
1400
|
}
|
|
@@ -1398,26 +1402,26 @@ function St(e) {
|
|
|
1398
1402
|
}
|
|
1399
1403
|
//#endregion
|
|
1400
1404
|
//#region src/helpers/paginate.ts
|
|
1401
|
-
function
|
|
1405
|
+
function Et(e) {
|
|
1402
1406
|
return e?.from !== void 0 || e?.take !== void 0;
|
|
1403
1407
|
}
|
|
1404
|
-
function
|
|
1408
|
+
function Dt(e) {
|
|
1405
1409
|
let t = e?.take, n = typeof t == "number" && Number.isFinite(t) ? Math.floor(t) : NaN;
|
|
1406
1410
|
return n >= 1 ? n : 50;
|
|
1407
1411
|
}
|
|
1408
|
-
function
|
|
1412
|
+
function Ot(e) {
|
|
1409
1413
|
let t = e.sortOrder === "asc" ? n : i;
|
|
1410
1414
|
return [t(e.sortColumn), t(e.idColumn)];
|
|
1411
1415
|
}
|
|
1412
|
-
function
|
|
1416
|
+
function kt(e, t) {
|
|
1413
1417
|
let n = e?.from ? he(e.from) : null;
|
|
1414
1418
|
if (!n) return;
|
|
1415
|
-
if (n.k !== t.sortKey) throw new
|
|
1419
|
+
if (n.k !== t.sortKey) throw new Fe(400, { message: "The `from` cursor was issued under a different sort and cannot be used with this request" });
|
|
1416
1420
|
if (n.s === void 0 || n.s === null) return t.sortOrder === "asc" ? s(t.idColumn, n.i) : m(t.idColumn, n.i);
|
|
1417
1421
|
let r = t.sortOrder === "asc" ? y.raw(">") : y.raw("<");
|
|
1418
1422
|
return y`(${t.sortColumn}, ${t.idColumn}) ${r} (${n.s}, ${n.i})`;
|
|
1419
1423
|
}
|
|
1420
|
-
function
|
|
1424
|
+
function At(e, t, n, r = "id", i) {
|
|
1421
1425
|
let a = e.length > t, o = a ? e.slice(0, t) : e, s, c = o[o.length - 1];
|
|
1422
1426
|
if (a && c) {
|
|
1423
1427
|
let e = c[n];
|
|
@@ -1434,7 +1438,7 @@ function Dt(e, t, n, r = "id", i) {
|
|
|
1434
1438
|
}
|
|
1435
1439
|
//#endregion
|
|
1436
1440
|
//#region src/adapters/clients.ts
|
|
1437
|
-
var
|
|
1441
|
+
var jt = [
|
|
1438
1442
|
"global",
|
|
1439
1443
|
"is_first_party",
|
|
1440
1444
|
"oidc_conformant",
|
|
@@ -1446,7 +1450,7 @@ var Ot = [
|
|
|
1446
1450
|
"require_pushed_authorization_requests",
|
|
1447
1451
|
"require_proof_of_possession",
|
|
1448
1452
|
"hide_sign_up_disabled_error"
|
|
1449
|
-
],
|
|
1453
|
+
], Mt = [
|
|
1450
1454
|
"callbacks",
|
|
1451
1455
|
"allowed_origins",
|
|
1452
1456
|
"web_origins",
|
|
@@ -1455,7 +1459,7 @@ var Ot = [
|
|
|
1455
1459
|
"allowed_logout_urls",
|
|
1456
1460
|
"grant_types",
|
|
1457
1461
|
"signing_keys"
|
|
1458
|
-
],
|
|
1462
|
+
], Nt = [
|
|
1459
1463
|
"session_transfer",
|
|
1460
1464
|
"oidc_logout",
|
|
1461
1465
|
"jwt_configuration",
|
|
@@ -1471,21 +1475,21 @@ var Ot = [
|
|
|
1471
1475
|
"token_quota",
|
|
1472
1476
|
"registration_metadata"
|
|
1473
1477
|
];
|
|
1474
|
-
function
|
|
1478
|
+
function Pt(e) {
|
|
1475
1479
|
let { tenant_id: t, connections: n, ...r } = e, i = { ...r };
|
|
1476
|
-
for (let e of
|
|
1477
|
-
for (let e of
|
|
1478
|
-
for (let e of
|
|
1479
|
-
return i.connections =
|
|
1480
|
+
for (let e of jt) i[e] = !!r[e];
|
|
1481
|
+
for (let e of Mt) i[e] = Z(r[e], []);
|
|
1482
|
+
for (let e of Nt) i[e] = Z(r[e], {});
|
|
1483
|
+
return i.connections = Z(n, []), D(i);
|
|
1480
1484
|
}
|
|
1481
|
-
function
|
|
1485
|
+
function Ft(e) {
|
|
1482
1486
|
let t = { ...e };
|
|
1483
|
-
ie(e,
|
|
1484
|
-
for (let n of
|
|
1485
|
-
for (let n of
|
|
1487
|
+
ie(e, jt, t);
|
|
1488
|
+
for (let n of Mt) e[n] !== void 0 && (t[n] = JSON.stringify(e[n] || []));
|
|
1489
|
+
for (let n of Nt) e[n] !== void 0 && (t[n] = JSON.stringify(e[n] || {}));
|
|
1486
1490
|
return e.connections !== void 0 && (t.connections = JSON.stringify(e.connections || [])), ce(t);
|
|
1487
1491
|
}
|
|
1488
|
-
function
|
|
1492
|
+
function It(e) {
|
|
1489
1493
|
return {
|
|
1490
1494
|
async create(t, n) {
|
|
1491
1495
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
@@ -1509,51 +1513,51 @@ function Nt(e) {
|
|
|
1509
1513
|
created_at: r,
|
|
1510
1514
|
updated_at: r
|
|
1511
1515
|
};
|
|
1512
|
-
for (let e of
|
|
1516
|
+
for (let e of jt) i[e] = n[e] ?? !1;
|
|
1513
1517
|
i.oidc_conformant = n.oidc_conformant ?? !0, i.auth0_conformant = n.auth0_conformant ?? !0, i.sso_disabled = n.sso_disabled ?? !1;
|
|
1514
|
-
for (let e of
|
|
1515
|
-
for (let e of
|
|
1518
|
+
for (let e of Mt) i[e] = n[e] || [];
|
|
1519
|
+
for (let e of Nt) i[e] = n[e] || {};
|
|
1516
1520
|
i.connections = n.connections || [];
|
|
1517
|
-
let a =
|
|
1521
|
+
let a = Ft(i);
|
|
1518
1522
|
try {
|
|
1519
|
-
await e.insert(
|
|
1523
|
+
await e.insert(I).values({
|
|
1520
1524
|
...a,
|
|
1521
1525
|
tenant_id: t
|
|
1522
1526
|
});
|
|
1523
1527
|
} catch (e) {
|
|
1524
|
-
throw e?.message?.includes("UNIQUE constraint failed") || e?.message?.includes("duplicate key") ? new
|
|
1528
|
+
throw e?.message?.includes("UNIQUE constraint failed") || e?.message?.includes("duplicate key") ? new Fe(409, { message: "Client already exists" }) : e;
|
|
1525
1529
|
}
|
|
1526
|
-
return
|
|
1530
|
+
return Pt({
|
|
1527
1531
|
...a,
|
|
1528
1532
|
tenant_id: t
|
|
1529
1533
|
});
|
|
1530
1534
|
},
|
|
1531
1535
|
async get(n, r) {
|
|
1532
|
-
let i = await e.select().from(
|
|
1533
|
-
return i ?
|
|
1536
|
+
let i = await e.select().from(I).where(t(a(I.tenant_id, n), a(I.client_id, r))).get();
|
|
1537
|
+
return i ? Pt(i) : null;
|
|
1534
1538
|
},
|
|
1535
1539
|
async getByClientId(t) {
|
|
1536
|
-
let n = await e.select().from(
|
|
1540
|
+
let n = await e.select().from(I).where(a(I.client_id, t)).get();
|
|
1537
1541
|
return n ? {
|
|
1538
|
-
...
|
|
1542
|
+
...Pt(n),
|
|
1539
1543
|
tenant_id: n.tenant_id
|
|
1540
1544
|
} : null;
|
|
1541
1545
|
},
|
|
1542
1546
|
async update(n, r, i) {
|
|
1543
|
-
let o =
|
|
1547
|
+
let o = Ft({
|
|
1544
1548
|
...i,
|
|
1545
1549
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1546
1550
|
});
|
|
1547
|
-
return delete o.client_id, delete o.tenant_id, await e.update(
|
|
1551
|
+
return delete o.client_id, delete o.tenant_id, await e.update(I).set(o).where(t(a(I.tenant_id, n), a(I.client_id, r))), !0;
|
|
1548
1552
|
},
|
|
1549
1553
|
async list(o, s) {
|
|
1550
|
-
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ?
|
|
1551
|
-
if (
|
|
1554
|
+
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ? mt(I, f, ["name", "client_id"]) : void 0, m = p ? t(a(I.tenant_id, o), p) : a(I.tenant_id, o);
|
|
1555
|
+
if (Et(s)) {
|
|
1552
1556
|
let n = {
|
|
1553
|
-
sortColumn:
|
|
1554
|
-
idColumn:
|
|
1557
|
+
sortColumn: I.created_at,
|
|
1558
|
+
idColumn: I.client_id,
|
|
1555
1559
|
sortOrder: "desc"
|
|
1556
|
-
}, r =
|
|
1560
|
+
}, r = kt(s, n), i = Dt(s), { rows: a, next: o } = At(await e.select().from(I).where(r ? t(m, r) : m).orderBy(...Ot(n)).limit(i + 1), i, "created_at", "client_id"), c = a.map(Pt);
|
|
1557
1561
|
return {
|
|
1558
1562
|
clients: c,
|
|
1559
1563
|
totals: {
|
|
@@ -1564,14 +1568,14 @@ function Nt(e) {
|
|
|
1564
1568
|
}
|
|
1565
1569
|
};
|
|
1566
1570
|
}
|
|
1567
|
-
let h = e.select().from(
|
|
1571
|
+
let h = e.select().from(I).where(m).$dynamic();
|
|
1568
1572
|
if (d?.sort_by) {
|
|
1569
|
-
let e =
|
|
1573
|
+
let e = I[d.sort_by];
|
|
1570
1574
|
e && (h = h.orderBy(d.sort_order === "desc" ? i(e) : n(e)));
|
|
1571
1575
|
}
|
|
1572
|
-
let g = (await h.offset(c * l).limit(l)).map(
|
|
1576
|
+
let g = (await h.offset(c * l).limit(l)).map(Pt);
|
|
1573
1577
|
if (!u) return { clients: g };
|
|
1574
|
-
let [_] = await e.select({ count: r() }).from(
|
|
1578
|
+
let [_] = await e.select({ count: r() }).from(I).where(m);
|
|
1575
1579
|
return {
|
|
1576
1580
|
clients: g,
|
|
1577
1581
|
totals: {
|
|
@@ -1583,42 +1587,42 @@ function Nt(e) {
|
|
|
1583
1587
|
};
|
|
1584
1588
|
},
|
|
1585
1589
|
async remove(n, r) {
|
|
1586
|
-
return (await e.delete(
|
|
1590
|
+
return (await e.delete(I).where(t(a(I.tenant_id, n), a(I.client_id, r))).returning()).length > 0;
|
|
1587
1591
|
}
|
|
1588
1592
|
};
|
|
1589
1593
|
}
|
|
1590
1594
|
//#endregion
|
|
1591
1595
|
//#region src/adapters/clientConnections.ts
|
|
1592
|
-
function
|
|
1596
|
+
function Lt(e) {
|
|
1593
1597
|
let { tenant_id: t, is_system: n, options: r, metadata: i, ...a } = e;
|
|
1594
1598
|
return D({
|
|
1595
1599
|
...a,
|
|
1596
|
-
options:
|
|
1597
|
-
metadata:
|
|
1600
|
+
options: Z(r, {}),
|
|
1601
|
+
metadata: Z(i),
|
|
1598
1602
|
is_system: n ? !0 : void 0
|
|
1599
1603
|
});
|
|
1600
1604
|
}
|
|
1601
|
-
function
|
|
1605
|
+
function Rt(e) {
|
|
1602
1606
|
return {
|
|
1603
1607
|
async listByClient(n, r) {
|
|
1604
|
-
let i = await e.select({ connections:
|
|
1608
|
+
let i = await e.select({ connections: I.connections }).from(I).where(t(a(I.tenant_id, n), a(I.client_id, r))).get();
|
|
1605
1609
|
if (!i) return [];
|
|
1606
|
-
let o =
|
|
1610
|
+
let o = Z(i.connections, []) || [];
|
|
1607
1611
|
if (o.length === 0) return [];
|
|
1608
|
-
let s = (await e.select().from(
|
|
1612
|
+
let s = (await e.select().from(B).where(t(a(B.tenant_id, n), l(B.id, o))).all()).map(Lt);
|
|
1609
1613
|
return o.map((e) => s.find((t) => t.id === e)).filter(Boolean);
|
|
1610
1614
|
},
|
|
1611
1615
|
async updateByClient(n, r, i) {
|
|
1612
|
-
return (await e.update(
|
|
1616
|
+
return (await e.update(I).set({ connections: JSON.stringify([...new Set(i)]) }).where(t(a(I.tenant_id, n), a(I.client_id, r))).returning()).length > 0;
|
|
1613
1617
|
},
|
|
1614
1618
|
async listByConnection(t, n) {
|
|
1615
1619
|
return (await e.select({
|
|
1616
|
-
client_id:
|
|
1617
|
-
connections:
|
|
1618
|
-
}).from(
|
|
1620
|
+
client_id: I.client_id,
|
|
1621
|
+
connections: I.connections
|
|
1622
|
+
}).from(I).where(a(I.tenant_id, t)).all()).filter((e) => (Z(e.connections, []) || []).includes(n)).map((e) => e.client_id);
|
|
1619
1623
|
},
|
|
1620
1624
|
async addClientToConnection(n, r, i) {
|
|
1621
|
-
if (!await e.select({ client_id:
|
|
1625
|
+
if (!await e.select({ client_id: I.client_id }).from(I).where(t(a(I.tenant_id, n), a(I.client_id, i))).get()) return !1;
|
|
1622
1626
|
let o = await e.run(y`UPDATE clients SET connections = CASE
|
|
1623
1627
|
WHEN connections IS NULL OR connections = '[]' OR connections = ''
|
|
1624
1628
|
THEN json_array(${r})
|
|
@@ -1642,17 +1646,17 @@ function Ft(e) {
|
|
|
1642
1646
|
}
|
|
1643
1647
|
//#endregion
|
|
1644
1648
|
//#region src/adapters/clientGrants.ts
|
|
1645
|
-
function
|
|
1649
|
+
function zt(e) {
|
|
1646
1650
|
let { tenant_id: t, scope: n, authorization_details_types: r, allow_any_organization: i, is_system: a, ...o } = e;
|
|
1647
1651
|
return D({
|
|
1648
1652
|
...o,
|
|
1649
|
-
scope:
|
|
1650
|
-
authorization_details_types:
|
|
1653
|
+
scope: Z(n, []),
|
|
1654
|
+
authorization_details_types: Z(r, []),
|
|
1651
1655
|
allow_any_organization: !!i,
|
|
1652
1656
|
is_system: !!a
|
|
1653
1657
|
});
|
|
1654
1658
|
}
|
|
1655
|
-
function
|
|
1659
|
+
function Bt(e) {
|
|
1656
1660
|
return {
|
|
1657
1661
|
async create(t, n) {
|
|
1658
1662
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
@@ -1669,30 +1673,30 @@ function Lt(e) {
|
|
|
1669
1673
|
created_at: r,
|
|
1670
1674
|
updated_at: r
|
|
1671
1675
|
};
|
|
1672
|
-
return await e.insert(
|
|
1676
|
+
return await e.insert(R).values(i), zt({
|
|
1673
1677
|
...i,
|
|
1674
1678
|
tenant_id: t
|
|
1675
1679
|
});
|
|
1676
1680
|
},
|
|
1677
1681
|
async get(n, r) {
|
|
1678
|
-
let i = await e.select().from(
|
|
1679
|
-
return i ?
|
|
1682
|
+
let i = await e.select().from(R).where(t(a(R.tenant_id, n), a(R.id, r))).get();
|
|
1683
|
+
return i ? zt(i) : null;
|
|
1680
1684
|
},
|
|
1681
1685
|
async update(n, r, i) {
|
|
1682
1686
|
let { scope: o, authorization_details_types: s, allow_any_organization: c, is_system: l, ...u } = i, d = {
|
|
1683
1687
|
...u,
|
|
1684
1688
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1685
1689
|
};
|
|
1686
|
-
return o !== void 0 && (d.scope = JSON.stringify(o)), s !== void 0 && (d.authorization_details_types = JSON.stringify(s)), c !== void 0 && (d.allow_any_organization = +!!c), l !== void 0 && (d.is_system = +!!l), (await e.update(
|
|
1690
|
+
return o !== void 0 && (d.scope = JSON.stringify(o)), s !== void 0 && (d.authorization_details_types = JSON.stringify(s)), c !== void 0 && (d.allow_any_organization = +!!c), l !== void 0 && (d.is_system = +!!l), (await e.update(R).set(d).where(t(a(R.tenant_id, n), a(R.id, r))).returning()).length > 0;
|
|
1687
1691
|
},
|
|
1688
1692
|
async list(o, s) {
|
|
1689
|
-
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ?
|
|
1690
|
-
if (
|
|
1693
|
+
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ? mt(R, f, ["client_id", "audience"]) : void 0, m = p ? t(a(R.tenant_id, o), p) : a(R.tenant_id, o);
|
|
1694
|
+
if (Et(s)) {
|
|
1691
1695
|
let n = {
|
|
1692
|
-
sortColumn:
|
|
1693
|
-
idColumn:
|
|
1696
|
+
sortColumn: R.created_at,
|
|
1697
|
+
idColumn: R.id,
|
|
1694
1698
|
sortOrder: "desc"
|
|
1695
|
-
}, r =
|
|
1699
|
+
}, r = kt(s, n), i = Dt(s), { rows: a, next: o } = At(await e.select().from(R).where(r ? t(m, r) : m).orderBy(...Ot(n)).limit(i + 1), i, "created_at"), c = a.map(zt);
|
|
1696
1700
|
return {
|
|
1697
1701
|
client_grants: c,
|
|
1698
1702
|
start: 0,
|
|
@@ -1701,14 +1705,14 @@ function Lt(e) {
|
|
|
1701
1705
|
next: o
|
|
1702
1706
|
};
|
|
1703
1707
|
}
|
|
1704
|
-
let h = e.select().from(
|
|
1708
|
+
let h = e.select().from(R).where(m).$dynamic();
|
|
1705
1709
|
if (d?.sort_by) {
|
|
1706
|
-
let e =
|
|
1710
|
+
let e = R[d.sort_by];
|
|
1707
1711
|
e && (h = h.orderBy(d.sort_order === "desc" ? i(e) : n(e)));
|
|
1708
|
-
} else h = h.orderBy(
|
|
1709
|
-
let g = (await h.offset(c * l).limit(l)).map(
|
|
1712
|
+
} else h = h.orderBy(i(R.created_at), i(R.id));
|
|
1713
|
+
let g = (await h.offset(c * l).limit(l)).map(zt);
|
|
1710
1714
|
if (!u) return { client_grants: g };
|
|
1711
|
-
let [_] = await e.select({ count: r() }).from(
|
|
1715
|
+
let [_] = await e.select({ count: r() }).from(R).where(m);
|
|
1712
1716
|
return {
|
|
1713
1717
|
client_grants: g,
|
|
1714
1718
|
start: c * l,
|
|
@@ -1717,26 +1721,26 @@ function Lt(e) {
|
|
|
1717
1721
|
};
|
|
1718
1722
|
},
|
|
1719
1723
|
async remove(n, r) {
|
|
1720
|
-
return (await e.delete(
|
|
1724
|
+
return (await e.delete(R).where(t(a(R.tenant_id, n), a(R.id, r))).returning()).length > 0;
|
|
1721
1725
|
}
|
|
1722
1726
|
};
|
|
1723
1727
|
}
|
|
1724
1728
|
//#endregion
|
|
1725
1729
|
//#region src/adapters/clientRegistrationTokens.ts
|
|
1726
|
-
function
|
|
1730
|
+
function Vt(e) {
|
|
1727
1731
|
if (!e) return;
|
|
1728
1732
|
let t = JSON.parse(e);
|
|
1729
1733
|
return ye(t) ? t : void 0;
|
|
1730
1734
|
}
|
|
1731
|
-
function
|
|
1735
|
+
function Ht(e) {
|
|
1732
1736
|
return e == null ? void 0 : new Date(e).toISOString();
|
|
1733
1737
|
}
|
|
1734
|
-
function
|
|
1738
|
+
function Ut(e) {
|
|
1735
1739
|
if (!e) return null;
|
|
1736
1740
|
let t = new Date(e);
|
|
1737
1741
|
return isNaN(t.getTime()) ? null : t.getTime();
|
|
1738
1742
|
}
|
|
1739
|
-
function
|
|
1743
|
+
function Wt(e) {
|
|
1740
1744
|
let t = me.parse(e.type);
|
|
1741
1745
|
return {
|
|
1742
1746
|
id: e.id,
|
|
@@ -1744,19 +1748,19 @@ function Vt(e) {
|
|
|
1744
1748
|
type: t,
|
|
1745
1749
|
client_id: e.client_id ?? void 0,
|
|
1746
1750
|
sub: e.sub ?? void 0,
|
|
1747
|
-
constraints:
|
|
1751
|
+
constraints: Vt(e.constraints),
|
|
1748
1752
|
single_use: !!e.single_use,
|
|
1749
|
-
expires_at:
|
|
1750
|
-
used_at:
|
|
1751
|
-
revoked_at:
|
|
1753
|
+
expires_at: Ht(e.expires_at_ts),
|
|
1754
|
+
used_at: Ht(e.used_at_ts),
|
|
1755
|
+
revoked_at: Ht(e.revoked_at_ts),
|
|
1752
1756
|
created_at: new Date(e.created_at_ts).toISOString()
|
|
1753
1757
|
};
|
|
1754
1758
|
}
|
|
1755
|
-
function
|
|
1759
|
+
function Gt(e) {
|
|
1756
1760
|
return {
|
|
1757
1761
|
async create(t, n) {
|
|
1758
1762
|
let r = Date.now();
|
|
1759
|
-
return await e.insert(
|
|
1763
|
+
return await e.insert(L).values({
|
|
1760
1764
|
id: n.id,
|
|
1761
1765
|
tenant_id: t,
|
|
1762
1766
|
token_hash: n.token_hash,
|
|
@@ -1765,7 +1769,7 @@ function Ht(e) {
|
|
|
1765
1769
|
sub: n.sub ?? null,
|
|
1766
1770
|
constraints: n.constraints ? JSON.stringify(n.constraints) : null,
|
|
1767
1771
|
single_use: +!!n.single_use,
|
|
1768
|
-
expires_at_ts:
|
|
1772
|
+
expires_at_ts: Ut(n.expires_at),
|
|
1769
1773
|
created_at_ts: r
|
|
1770
1774
|
}), {
|
|
1771
1775
|
id: n.id,
|
|
@@ -1780,38 +1784,38 @@ function Ht(e) {
|
|
|
1780
1784
|
};
|
|
1781
1785
|
},
|
|
1782
1786
|
async get(n, r) {
|
|
1783
|
-
let i = await e.select().from(
|
|
1784
|
-
return i ?
|
|
1787
|
+
let i = await e.select().from(L).where(t(a(L.tenant_id, n), a(L.id, r))).get();
|
|
1788
|
+
return i ? Wt(i) : null;
|
|
1785
1789
|
},
|
|
1786
1790
|
async getByHash(n, r) {
|
|
1787
|
-
let i = await e.select().from(
|
|
1788
|
-
return i ?
|
|
1791
|
+
let i = await e.select().from(L).where(t(a(L.tenant_id, n), a(L.token_hash, r))).get();
|
|
1792
|
+
return i ? Wt(i) : null;
|
|
1789
1793
|
},
|
|
1790
1794
|
async listByClient(n, r) {
|
|
1791
|
-
return (await e.select().from(
|
|
1795
|
+
return (await e.select().from(L).where(t(a(L.tenant_id, n), a(L.client_id, r))).orderBy(i(L.created_at_ts))).map(Wt);
|
|
1792
1796
|
},
|
|
1793
1797
|
async markUsed(n, r, i) {
|
|
1794
|
-
return (await e.update(
|
|
1798
|
+
return (await e.update(L).set({ used_at_ts: Ut(i) }).where(t(a(L.tenant_id, n), a(L.id, r), f(L.used_at_ts))).returning()).length > 0;
|
|
1795
1799
|
},
|
|
1796
1800
|
async revoke(n, r, i) {
|
|
1797
|
-
return (await e.update(
|
|
1801
|
+
return (await e.update(L).set({ revoked_at_ts: Ut(i) }).where(t(a(L.tenant_id, n), a(L.id, r), f(L.revoked_at_ts))).returning()).length > 0;
|
|
1798
1802
|
},
|
|
1799
1803
|
async revokeByClient(n, r, i) {
|
|
1800
|
-
return (await e.update(
|
|
1804
|
+
return (await e.update(L).set({ revoked_at_ts: Ut(i) }).where(t(a(L.tenant_id, n), a(L.client_id, r), f(L.revoked_at_ts))).returning()).length;
|
|
1801
1805
|
},
|
|
1802
1806
|
async remove(n, r) {
|
|
1803
|
-
return (await e.delete(
|
|
1807
|
+
return (await e.delete(L).where(t(a(L.tenant_id, n), a(L.id, r))).returning()).length > 0;
|
|
1804
1808
|
}
|
|
1805
1809
|
};
|
|
1806
1810
|
}
|
|
1807
1811
|
//#endregion
|
|
1808
1812
|
//#region src/adapters/codes.ts
|
|
1809
|
-
var
|
|
1810
|
-
function
|
|
1813
|
+
var Kt = ["code_id", "login_id"], qt = 500;
|
|
1814
|
+
function Jt(e) {
|
|
1811
1815
|
let { tenant_id: t, ...n } = e;
|
|
1812
1816
|
return D(n);
|
|
1813
1817
|
}
|
|
1814
|
-
function
|
|
1818
|
+
function Yt(e) {
|
|
1815
1819
|
return {
|
|
1816
1820
|
async create(t, n) {
|
|
1817
1821
|
let r = {
|
|
@@ -1820,29 +1824,29 @@ function Kt(e) {
|
|
|
1820
1824
|
created_at: n.created_at || (/* @__PURE__ */ new Date()).toISOString(),
|
|
1821
1825
|
expires_at: n.expires_at
|
|
1822
1826
|
};
|
|
1823
|
-
return await e.insert(
|
|
1827
|
+
return await e.insert(F).values(r), Jt(r);
|
|
1824
1828
|
},
|
|
1825
1829
|
async get(n, r, i) {
|
|
1826
|
-
let o = n ? t(a(
|
|
1827
|
-
return s ?
|
|
1830
|
+
let o = n ? t(a(F.tenant_id, n), a(F.code_id, r), a(F.code_type, i)) : t(a(F.code_id, r), a(F.code_type, i)), s = await e.select().from(F).where(o).get();
|
|
1831
|
+
return s ? Jt(s) : null;
|
|
1828
1832
|
},
|
|
1829
1833
|
async list(o, s) {
|
|
1830
|
-
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = [a(
|
|
1834
|
+
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = [a(F.tenant_id, o)];
|
|
1831
1835
|
if (f) {
|
|
1832
|
-
let e = we(f,
|
|
1836
|
+
let e = we(f, Kt);
|
|
1833
1837
|
if (e) {
|
|
1834
|
-
let t =
|
|
1838
|
+
let t = mt(F, e, Kt);
|
|
1835
1839
|
t && p.push(t);
|
|
1836
1840
|
}
|
|
1837
1841
|
}
|
|
1838
|
-
let m = t(...p), h = e.select().from(
|
|
1842
|
+
let m = t(...p), h = e.select().from(F).where(m).$dynamic();
|
|
1839
1843
|
if (d?.sort_by) {
|
|
1840
|
-
let e =
|
|
1844
|
+
let e = F[d.sort_by];
|
|
1841
1845
|
e && (h = h.orderBy(d.sort_order === "desc" ? i(e) : n(e)));
|
|
1842
1846
|
}
|
|
1843
|
-
let g = (await h.offset(c * l).limit(l)).map(
|
|
1847
|
+
let g = (await h.offset(c * l).limit(l)).map(Jt);
|
|
1844
1848
|
if (!u) return { codes: g };
|
|
1845
|
-
let [_] = await e.select({ count: r() }).from(
|
|
1849
|
+
let [_] = await e.select({ count: r() }).from(F).where(m);
|
|
1846
1850
|
return {
|
|
1847
1851
|
codes: g,
|
|
1848
1852
|
start: c * l,
|
|
@@ -1851,19 +1855,19 @@ function Kt(e) {
|
|
|
1851
1855
|
};
|
|
1852
1856
|
},
|
|
1853
1857
|
async used(n, r) {
|
|
1854
|
-
return (await e.update(
|
|
1858
|
+
return (await e.update(F).set({ used_at: (/* @__PURE__ */ new Date()).toISOString() }).where(t(a(F.tenant_id, n), a(F.code_id, r))).returning()).length > 0;
|
|
1855
1859
|
},
|
|
1856
1860
|
async consume(n, r) {
|
|
1857
|
-
return (await e.update(
|
|
1861
|
+
return (await e.update(F).set({ used_at: (/* @__PURE__ */ new Date()).toISOString() }).where(t(a(F.tenant_id, n), a(F.code_id, r), f(F.used_at))).returning()).length > 0;
|
|
1858
1862
|
},
|
|
1859
1863
|
async remove(n, r) {
|
|
1860
|
-
return (await e.delete(
|
|
1864
|
+
return (await e.delete(F).where(t(a(F.tenant_id, n), a(F.code_id, r))).returning()).length > 0;
|
|
1861
1865
|
},
|
|
1862
1866
|
async cleanup(t) {
|
|
1863
1867
|
let n = 0;
|
|
1864
1868
|
for (;;) {
|
|
1865
|
-
let r = await e.delete(
|
|
1866
|
-
if (n += r.length, r.length <
|
|
1869
|
+
let r = await e.delete(F).where(y`rowid IN (SELECT rowid FROM ${F} WHERE ${F.expires_at} < ${t} LIMIT ${qt})`).returning({ code_id: F.code_id });
|
|
1870
|
+
if (n += r.length, r.length < qt) break;
|
|
1867
1871
|
}
|
|
1868
1872
|
return n;
|
|
1869
1873
|
}
|
|
@@ -1871,23 +1875,23 @@ function Kt(e) {
|
|
|
1871
1875
|
}
|
|
1872
1876
|
//#endregion
|
|
1873
1877
|
//#region src/adapters/connections.ts
|
|
1874
|
-
function
|
|
1878
|
+
function Xt() {
|
|
1875
1879
|
return `con_${ee("0123456789abcdefghijklmnopqrstuvwxyz", 17)()}`;
|
|
1876
1880
|
}
|
|
1877
|
-
function
|
|
1881
|
+
function Zt(e) {
|
|
1878
1882
|
let { tenant_id: t, is_system: n, options: r, metadata: i, ...a } = e;
|
|
1879
1883
|
return D({
|
|
1880
1884
|
...a,
|
|
1881
|
-
options:
|
|
1882
|
-
metadata:
|
|
1885
|
+
options: Z(r, {}),
|
|
1886
|
+
metadata: Z(i),
|
|
1883
1887
|
is_system: n ? !0 : void 0
|
|
1884
1888
|
});
|
|
1885
1889
|
}
|
|
1886
|
-
function
|
|
1890
|
+
function Qt(e) {
|
|
1887
1891
|
return {
|
|
1888
1892
|
async create(t, n) {
|
|
1889
1893
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
1890
|
-
id: n.id ||
|
|
1894
|
+
id: n.id || Xt(),
|
|
1891
1895
|
...n,
|
|
1892
1896
|
tenant_id: t,
|
|
1893
1897
|
options: JSON.stringify(n.options || {}),
|
|
@@ -1897,34 +1901,34 @@ function Yt(e) {
|
|
|
1897
1901
|
updated_at: r
|
|
1898
1902
|
};
|
|
1899
1903
|
try {
|
|
1900
|
-
await e.insert(
|
|
1904
|
+
await e.insert(B).values(i);
|
|
1901
1905
|
} catch (e) {
|
|
1902
|
-
throw e?.message?.includes("UNIQUE constraint failed") || e?.message?.includes("duplicate key") ? new
|
|
1906
|
+
throw e?.message?.includes("UNIQUE constraint failed") || e?.message?.includes("duplicate key") ? new Fe(409, { message: "Connection already exists" }) : e;
|
|
1903
1907
|
}
|
|
1904
|
-
return
|
|
1908
|
+
return Zt(i);
|
|
1905
1909
|
},
|
|
1906
1910
|
async get(n, r) {
|
|
1907
|
-
let i = await e.select().from(
|
|
1908
|
-
return i ?
|
|
1911
|
+
let i = await e.select().from(B).where(t(a(B.tenant_id, n), a(B.id, r))).get();
|
|
1912
|
+
return i ? Zt(i) : null;
|
|
1909
1913
|
},
|
|
1910
1914
|
async update(n, r, i) {
|
|
1911
1915
|
let o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
1912
|
-
return i.name !== void 0 && (o.name = i.name), i.strategy !== void 0 && (o.strategy = i.strategy), i.options !== void 0 && (o.options = JSON.stringify(i.options)), i.metadata !== void 0 && (o.metadata = JSON.stringify(i.metadata)), i.display_name !== void 0 && (o.display_name = i.display_name), i.response_type !== void 0 && (o.response_type = i.response_type), i.response_mode !== void 0 && (o.response_mode = i.response_mode), await e.update(
|
|
1916
|
+
return i.name !== void 0 && (o.name = i.name), i.strategy !== void 0 && (o.strategy = i.strategy), i.options !== void 0 && (o.options = JSON.stringify(i.options)), i.metadata !== void 0 && (o.metadata = JSON.stringify(i.metadata)), i.display_name !== void 0 && (o.display_name = i.display_name), i.response_type !== void 0 && (o.response_type = i.response_type), i.response_mode !== void 0 && (o.response_mode = i.response_mode), await e.update(B).set(o).where(t(a(B.tenant_id, n), a(B.id, r))), !0;
|
|
1913
1917
|
},
|
|
1914
1918
|
async list(o, s) {
|
|
1915
|
-
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = a(
|
|
1919
|
+
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = a(B.tenant_id, o);
|
|
1916
1920
|
if (f) {
|
|
1917
|
-
let e =
|
|
1921
|
+
let e = mt(B, f, ["name"]);
|
|
1918
1922
|
e && (p = t(p, e));
|
|
1919
1923
|
}
|
|
1920
|
-
let m = e.select().from(
|
|
1924
|
+
let m = e.select().from(B).where(p).$dynamic();
|
|
1921
1925
|
if (d?.sort_by) {
|
|
1922
|
-
let e =
|
|
1926
|
+
let e = B[d.sort_by];
|
|
1923
1927
|
e && (m = m.orderBy(d.sort_order === "desc" ? i(e) : n(e)));
|
|
1924
1928
|
}
|
|
1925
|
-
let h = (await m.offset(c * l).limit(l)).map(
|
|
1929
|
+
let h = (await m.offset(c * l).limit(l)).map(Zt);
|
|
1926
1930
|
if (!u) return { connections: h };
|
|
1927
|
-
let [g] = await e.select({ count: r() }).from(
|
|
1931
|
+
let [g] = await e.select({ count: r() }).from(B).where(p);
|
|
1928
1932
|
return {
|
|
1929
1933
|
connections: h,
|
|
1930
1934
|
start: c * l,
|
|
@@ -1933,22 +1937,22 @@ function Yt(e) {
|
|
|
1933
1937
|
};
|
|
1934
1938
|
},
|
|
1935
1939
|
async remove(n, r) {
|
|
1936
|
-
return (await e.delete(
|
|
1940
|
+
return (await e.delete(B).where(t(a(B.tenant_id, n), a(B.id, r))).returning()).length > 0;
|
|
1937
1941
|
}
|
|
1938
1942
|
};
|
|
1939
1943
|
}
|
|
1940
1944
|
//#endregion
|
|
1941
1945
|
//#region src/adapters/customDomains.ts
|
|
1942
|
-
function
|
|
1946
|
+
function $t(e) {
|
|
1943
1947
|
let { tenant_id: t, domain_metadata: n, verification: r, ...i } = e;
|
|
1944
1948
|
return D({
|
|
1945
1949
|
...i,
|
|
1946
1950
|
primary: !!i.primary,
|
|
1947
|
-
domain_metadata:
|
|
1948
|
-
verification:
|
|
1951
|
+
domain_metadata: Z(n),
|
|
1952
|
+
verification: Z(r)
|
|
1949
1953
|
});
|
|
1950
1954
|
}
|
|
1951
|
-
function
|
|
1955
|
+
function en(e) {
|
|
1952
1956
|
return {
|
|
1953
1957
|
async create(t, n) {
|
|
1954
1958
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
@@ -1966,40 +1970,40 @@ function Zt(e) {
|
|
|
1966
1970
|
created_at: r,
|
|
1967
1971
|
updated_at: r
|
|
1968
1972
|
};
|
|
1969
|
-
return await e.insert(
|
|
1973
|
+
return await e.insert(We).values(i), $t({
|
|
1970
1974
|
...i,
|
|
1971
1975
|
tenant_id: t
|
|
1972
1976
|
});
|
|
1973
1977
|
},
|
|
1974
1978
|
async get(n, r) {
|
|
1975
|
-
let i = await e.select().from(
|
|
1976
|
-
return i ?
|
|
1979
|
+
let i = await e.select().from(We).where(t(a(We.tenant_id, n), a(We.custom_domain_id, r))).get();
|
|
1980
|
+
return i ? $t(i) : null;
|
|
1977
1981
|
},
|
|
1978
1982
|
async getByDomain(t) {
|
|
1979
|
-
let n = await e.select().from(
|
|
1983
|
+
let n = await e.select().from(We).where(a(We.domain, t)).get();
|
|
1980
1984
|
return n ? {
|
|
1981
|
-
|
|
1985
|
+
...$t(n),
|
|
1982
1986
|
tenant_id: n.tenant_id
|
|
1983
1987
|
} : null;
|
|
1984
1988
|
},
|
|
1985
1989
|
async list(t) {
|
|
1986
|
-
return (await e.select().from(
|
|
1990
|
+
return (await e.select().from(We).where(a(We.tenant_id, t)).all()).map($t);
|
|
1987
1991
|
},
|
|
1988
1992
|
async update(n, r, i) {
|
|
1989
1993
|
let o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
1990
|
-
return i.domain !== void 0 && (o.domain = i.domain), i.primary !== void 0 && (o.primary = i.primary), i.status !== void 0 && (o.status = i.status), i.type !== void 0 && (o.type = i.type), i.origin_domain_name !== void 0 && (o.origin_domain_name = i.origin_domain_name), i.verification !== void 0 && (o.verification = JSON.stringify(i.verification)), i.custom_client_ip_header !== void 0 && (o.custom_client_ip_header = i.custom_client_ip_header), i.tls_policy !== void 0 && (o.tls_policy = i.tls_policy), i.domain_metadata !== void 0 && (o.domain_metadata = JSON.stringify(i.domain_metadata)), (await e.update(
|
|
1994
|
+
return i.domain !== void 0 && (o.domain = i.domain), i.primary !== void 0 && (o.primary = i.primary), i.status !== void 0 && (o.status = i.status), i.type !== void 0 && (o.type = i.type), i.origin_domain_name !== void 0 && (o.origin_domain_name = i.origin_domain_name), i.verification !== void 0 && (o.verification = JSON.stringify(i.verification)), i.custom_client_ip_header !== void 0 && (o.custom_client_ip_header = i.custom_client_ip_header), i.tls_policy !== void 0 && (o.tls_policy = i.tls_policy), i.domain_metadata !== void 0 && (o.domain_metadata = JSON.stringify(i.domain_metadata)), (await e.update(We).set(o).where(t(a(We.tenant_id, n), a(We.custom_domain_id, r))).returning()).length > 0;
|
|
1991
1995
|
},
|
|
1992
1996
|
async remove(n, r) {
|
|
1993
|
-
return (await e.delete(
|
|
1997
|
+
return (await e.delete(We).where(t(a(We.tenant_id, n), a(We.custom_domain_id, r))).returning()).length > 0;
|
|
1994
1998
|
}
|
|
1995
1999
|
};
|
|
1996
2000
|
}
|
|
1997
2001
|
//#endregion
|
|
1998
2002
|
//#region src/adapters/customText.ts
|
|
1999
|
-
function
|
|
2003
|
+
function tn(e) {
|
|
2000
2004
|
return {
|
|
2001
2005
|
async get(n, r, i) {
|
|
2002
|
-
let o = await e.select().from(
|
|
2006
|
+
let o = await e.select().from(ot).where(t(a(ot.tenant_id, n), a(ot.prompt, r), a(ot.language, i))).get();
|
|
2003
2007
|
if (!o) return null;
|
|
2004
2008
|
try {
|
|
2005
2009
|
return JSON.parse(o.custom_text);
|
|
@@ -2009,7 +2013,7 @@ function Qt(e) {
|
|
|
2009
2013
|
},
|
|
2010
2014
|
async set(t, n, r, i) {
|
|
2011
2015
|
let a = Date.now(), o = JSON.stringify(i);
|
|
2012
|
-
await e.insert(
|
|
2016
|
+
await e.insert(ot).values({
|
|
2013
2017
|
tenant_id: t,
|
|
2014
2018
|
prompt: n,
|
|
2015
2019
|
language: r,
|
|
@@ -2018,9 +2022,9 @@ function Qt(e) {
|
|
|
2018
2022
|
updated_at_ts: a
|
|
2019
2023
|
}).onConflictDoUpdate({
|
|
2020
2024
|
target: [
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2025
|
+
ot.tenant_id,
|
|
2026
|
+
ot.prompt,
|
|
2027
|
+
ot.language
|
|
2024
2028
|
],
|
|
2025
2029
|
set: {
|
|
2026
2030
|
custom_text: o,
|
|
@@ -2029,23 +2033,23 @@ function Qt(e) {
|
|
|
2029
2033
|
});
|
|
2030
2034
|
},
|
|
2031
2035
|
async delete(n, r, i) {
|
|
2032
|
-
await e.delete(
|
|
2036
|
+
await e.delete(ot).where(t(a(ot.tenant_id, n), a(ot.prompt, r), a(ot.language, i)));
|
|
2033
2037
|
},
|
|
2034
2038
|
async list(t) {
|
|
2035
2039
|
return await e.select({
|
|
2036
|
-
prompt:
|
|
2037
|
-
language:
|
|
2038
|
-
}).from(
|
|
2040
|
+
prompt: ot.prompt,
|
|
2041
|
+
language: ot.language
|
|
2042
|
+
}).from(ot).where(a(ot.tenant_id, t)).all();
|
|
2039
2043
|
}
|
|
2040
2044
|
};
|
|
2041
2045
|
}
|
|
2042
2046
|
//#endregion
|
|
2043
2047
|
//#region src/adapters/emailProviders.ts
|
|
2044
|
-
function
|
|
2048
|
+
function nn(e) {
|
|
2045
2049
|
return {
|
|
2046
2050
|
async create(t, n) {
|
|
2047
2051
|
let r = (/* @__PURE__ */ new Date()).toISOString();
|
|
2048
|
-
await e.insert(
|
|
2052
|
+
await e.insert(tt).values({
|
|
2049
2053
|
tenant_id: t,
|
|
2050
2054
|
name: n.name,
|
|
2051
2055
|
enabled: n.enabled,
|
|
@@ -2057,28 +2061,28 @@ function $t(e) {
|
|
|
2057
2061
|
});
|
|
2058
2062
|
},
|
|
2059
2063
|
async get(t) {
|
|
2060
|
-
let n = await e.select().from(
|
|
2064
|
+
let n = await e.select().from(tt).where(a(tt.tenant_id, t)).get();
|
|
2061
2065
|
if (!n) return null;
|
|
2062
2066
|
let { tenant_id: r, ...i } = n;
|
|
2063
2067
|
return D({
|
|
2064
2068
|
...i,
|
|
2065
2069
|
enabled: !!i.enabled,
|
|
2066
|
-
credentials:
|
|
2067
|
-
settings:
|
|
2070
|
+
credentials: Z(i.credentials, {}),
|
|
2071
|
+
settings: Z(i.settings, {})
|
|
2068
2072
|
});
|
|
2069
2073
|
},
|
|
2070
2074
|
async update(t, n) {
|
|
2071
2075
|
let r = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
2072
|
-
n.name !== void 0 && (r.name = n.name), n.enabled !== void 0 && (r.enabled = n.enabled), n.default_from_address !== void 0 && (r.default_from_address = n.default_from_address), n.credentials !== void 0 && (r.credentials = JSON.stringify(n.credentials)), n.settings !== void 0 && (r.settings = JSON.stringify(n.settings)), await e.update(
|
|
2076
|
+
n.name !== void 0 && (r.name = n.name), n.enabled !== void 0 && (r.enabled = n.enabled), n.default_from_address !== void 0 && (r.default_from_address = n.default_from_address), n.credentials !== void 0 && (r.credentials = JSON.stringify(n.credentials)), n.settings !== void 0 && (r.settings = JSON.stringify(n.settings)), await e.update(tt).set(r).where(a(tt.tenant_id, t));
|
|
2073
2077
|
},
|
|
2074
2078
|
async remove(t) {
|
|
2075
|
-
await e.delete(
|
|
2079
|
+
await e.delete(tt).where(a(tt.tenant_id, t));
|
|
2076
2080
|
}
|
|
2077
2081
|
};
|
|
2078
2082
|
}
|
|
2079
2083
|
//#endregion
|
|
2080
2084
|
//#region src/adapters/emailTemplates.ts
|
|
2081
|
-
function
|
|
2085
|
+
function rn(e) {
|
|
2082
2086
|
return D({
|
|
2083
2087
|
template: e.template,
|
|
2084
2088
|
body: e.body,
|
|
@@ -2091,18 +2095,18 @@ function en(e) {
|
|
|
2091
2095
|
urlLifetimeInSeconds: e.url_lifetime_in_seconds ?? void 0
|
|
2092
2096
|
});
|
|
2093
2097
|
}
|
|
2094
|
-
function
|
|
2098
|
+
function an(e) {
|
|
2095
2099
|
return {
|
|
2096
2100
|
async get(n, r) {
|
|
2097
|
-
let i = await e.select().from(
|
|
2098
|
-
return i ?
|
|
2101
|
+
let i = await e.select().from(nt).where(t(a(nt.tenant_id, n), a(nt.template, r))).get();
|
|
2102
|
+
return i ? rn(i) : null;
|
|
2099
2103
|
},
|
|
2100
2104
|
async list(t) {
|
|
2101
|
-
return (await e.select().from(
|
|
2105
|
+
return (await e.select().from(nt).where(a(nt.tenant_id, t)).all()).map(rn);
|
|
2102
2106
|
},
|
|
2103
2107
|
async create(t, n) {
|
|
2104
2108
|
let r = (/* @__PURE__ */ new Date()).toISOString();
|
|
2105
|
-
return await e.insert(
|
|
2109
|
+
return await e.insert(nt).values({
|
|
2106
2110
|
tenant_id: t,
|
|
2107
2111
|
template: n.template,
|
|
2108
2112
|
body: n.body,
|
|
@@ -2120,23 +2124,23 @@ function tn(e) {
|
|
|
2120
2124
|
async update(n, r, i) {
|
|
2121
2125
|
let o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
2122
2126
|
i.body !== void 0 && (o.body = i.body), i.from !== void 0 && (o.from = i.from), i.subject !== void 0 && (o.subject = i.subject), i.syntax !== void 0 && (o.syntax = i.syntax), i.resultUrl !== void 0 && (o.result_url = i.resultUrl), i.urlLifetimeInSeconds !== void 0 && (o.url_lifetime_in_seconds = i.urlLifetimeInSeconds), i.includeEmailInRedirect !== void 0 && (o.include_email_in_redirect = i.includeEmailInRedirect), i.enabled !== void 0 && (o.enabled = i.enabled);
|
|
2123
|
-
let s = await e.update(
|
|
2127
|
+
let s = await e.update(nt).set(o).where(t(a(nt.tenant_id, n), a(nt.template, r))).run();
|
|
2124
2128
|
return Number(s.changes ?? 0) > 0;
|
|
2125
2129
|
},
|
|
2126
2130
|
async remove(n, r) {
|
|
2127
|
-
let i = await e.delete(
|
|
2131
|
+
let i = await e.delete(nt).where(t(a(nt.tenant_id, n), a(nt.template, r))).run();
|
|
2128
2132
|
return Number(i.changes ?? 0) > 0;
|
|
2129
2133
|
}
|
|
2130
2134
|
};
|
|
2131
2135
|
}
|
|
2132
2136
|
//#endregion
|
|
2133
2137
|
//#region src/adapters/flows.ts
|
|
2134
|
-
var
|
|
2135
|
-
function
|
|
2138
|
+
var on = ["id", "name"];
|
|
2139
|
+
function sn(e) {
|
|
2136
2140
|
return {
|
|
2137
2141
|
async create(t, n) {
|
|
2138
2142
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = `af_${b()}`;
|
|
2139
|
-
return await e.insert(
|
|
2143
|
+
return await e.insert($e).values({
|
|
2140
2144
|
id: i,
|
|
2141
2145
|
tenant_id: t,
|
|
2142
2146
|
name: n.name,
|
|
@@ -2152,41 +2156,41 @@ function rn(e) {
|
|
|
2152
2156
|
};
|
|
2153
2157
|
},
|
|
2154
2158
|
async get(n, r) {
|
|
2155
|
-
let i = await e.select().from(
|
|
2159
|
+
let i = await e.select().from($e).where(t(a($e.tenant_id, n), a($e.id, r))).get();
|
|
2156
2160
|
if (!i) return null;
|
|
2157
2161
|
let { tenant_id: o, actions: s, ...c } = i;
|
|
2158
2162
|
return D({
|
|
2159
2163
|
...c,
|
|
2160
|
-
actions:
|
|
2164
|
+
actions: Z(s, [])
|
|
2161
2165
|
});
|
|
2162
2166
|
},
|
|
2163
2167
|
async update(n, r, i) {
|
|
2164
2168
|
let o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
2165
|
-
return i.name !== void 0 && (o.name = i.name), i.actions !== void 0 && (o.actions = JSON.stringify(i.actions)), (await e.update(
|
|
2169
|
+
return i.name !== void 0 && (o.name = i.name), i.actions !== void 0 && (o.actions = JSON.stringify(i.actions)), (await e.update($e).set(o).where(t(a($e.tenant_id, n), a($e.id, r))).returning()).length === 0 ? null : this.get(n, r);
|
|
2166
2170
|
},
|
|
2167
2171
|
async list(o, s) {
|
|
2168
|
-
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = [a(
|
|
2172
|
+
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = [a($e.tenant_id, o)];
|
|
2169
2173
|
if (f) {
|
|
2170
|
-
let e = we(f,
|
|
2174
|
+
let e = we(f, on);
|
|
2171
2175
|
if (e) {
|
|
2172
|
-
let t =
|
|
2176
|
+
let t = mt($e, e, []);
|
|
2173
2177
|
t && p.push(t);
|
|
2174
2178
|
}
|
|
2175
2179
|
}
|
|
2176
|
-
let m = t(...p), h = e.select().from(
|
|
2180
|
+
let m = t(...p), h = e.select().from($e).where(m).$dynamic();
|
|
2177
2181
|
if (d?.sort_by) {
|
|
2178
|
-
let e =
|
|
2182
|
+
let e = $e[d.sort_by];
|
|
2179
2183
|
e && (h = h.orderBy(d.sort_order === "desc" ? i(e) : n(e)));
|
|
2180
2184
|
}
|
|
2181
2185
|
let g = (await h.offset(c * l).limit(l)).map((e) => {
|
|
2182
2186
|
let { tenant_id: t, actions: n, ...r } = e;
|
|
2183
2187
|
return D({
|
|
2184
2188
|
...r,
|
|
2185
|
-
actions:
|
|
2189
|
+
actions: Z(n, [])
|
|
2186
2190
|
});
|
|
2187
2191
|
});
|
|
2188
2192
|
if (!u) return { flows: g };
|
|
2189
|
-
let [_] = await e.select({ count: r() }).from(
|
|
2193
|
+
let [_] = await e.select({ count: r() }).from($e).where(m);
|
|
2190
2194
|
return {
|
|
2191
2195
|
flows: g,
|
|
2192
2196
|
start: c * l,
|
|
@@ -2195,18 +2199,18 @@ function rn(e) {
|
|
|
2195
2199
|
};
|
|
2196
2200
|
},
|
|
2197
2201
|
async remove(n, r) {
|
|
2198
|
-
return (await e.delete(
|
|
2202
|
+
return (await e.delete($e).where(t(a($e.tenant_id, n), a($e.id, r))).returning()).length > 0;
|
|
2199
2203
|
}
|
|
2200
2204
|
};
|
|
2201
2205
|
}
|
|
2202
2206
|
//#endregion
|
|
2203
2207
|
//#region src/adapters/forms.ts
|
|
2204
|
-
var
|
|
2208
|
+
var cn = [
|
|
2205
2209
|
"nodes",
|
|
2206
2210
|
"start",
|
|
2207
2211
|
"ending"
|
|
2208
|
-
],
|
|
2209
|
-
function
|
|
2212
|
+
], ln = ["name"];
|
|
2213
|
+
function un(e) {
|
|
2210
2214
|
return {
|
|
2211
2215
|
async create(t, n) {
|
|
2212
2216
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = b(), a = {
|
|
@@ -2220,8 +2224,8 @@ function sn(e) {
|
|
|
2220
2224
|
created_at: r,
|
|
2221
2225
|
updated_at: r
|
|
2222
2226
|
};
|
|
2223
|
-
for (let e of
|
|
2224
|
-
return await e.insert(
|
|
2227
|
+
for (let e of cn) a[e] = JSON.stringify(n[e] || (e === "nodes" ? [] : {}));
|
|
2228
|
+
return await e.insert(Qe).values(a), {
|
|
2225
2229
|
id: i,
|
|
2226
2230
|
...n,
|
|
2227
2231
|
created_at: r,
|
|
@@ -2229,38 +2233,38 @@ function sn(e) {
|
|
|
2229
2233
|
};
|
|
2230
2234
|
},
|
|
2231
2235
|
async get(n, r) {
|
|
2232
|
-
let i = await e.select().from(
|
|
2236
|
+
let i = await e.select().from(Qe).where(t(a(Qe.tenant_id, n), a(Qe.id, r))).get();
|
|
2233
2237
|
if (!i) return null;
|
|
2234
2238
|
let { tenant_id: o, ...s } = i, c = { ...s };
|
|
2235
|
-
for (let e of
|
|
2239
|
+
for (let e of cn) c[e] = Z(s[e]);
|
|
2236
2240
|
return D(c);
|
|
2237
2241
|
},
|
|
2238
2242
|
async update(n, r, i) {
|
|
2239
2243
|
let o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
2240
|
-
for (let [e, t] of Object.entries(i)) t !== void 0 && (
|
|
2241
|
-
return (await e.update(
|
|
2244
|
+
for (let [e, t] of Object.entries(i)) t !== void 0 && (cn.includes(e) ? o[e] = JSON.stringify(t) : o[e] = t);
|
|
2245
|
+
return (await e.update(Qe).set(o).where(t(a(Qe.tenant_id, n), a(Qe.id, r))).returning()).length > 0;
|
|
2242
2246
|
},
|
|
2243
2247
|
async list(o, s) {
|
|
2244
|
-
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = [a(
|
|
2248
|
+
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = [a(Qe.tenant_id, o)];
|
|
2245
2249
|
if (f) {
|
|
2246
|
-
let e = we(f,
|
|
2250
|
+
let e = we(f, ln);
|
|
2247
2251
|
if (e) {
|
|
2248
|
-
let t =
|
|
2252
|
+
let t = mt(Qe, e, ln);
|
|
2249
2253
|
t && p.push(t);
|
|
2250
2254
|
}
|
|
2251
2255
|
}
|
|
2252
|
-
let m = t(...p), h = e.select().from(
|
|
2256
|
+
let m = t(...p), h = e.select().from(Qe).where(m).$dynamic();
|
|
2253
2257
|
if (d?.sort_by) {
|
|
2254
|
-
let e =
|
|
2258
|
+
let e = Qe[d.sort_by];
|
|
2255
2259
|
e && (h = h.orderBy(d.sort_order === "desc" ? i(e) : n(e)));
|
|
2256
2260
|
}
|
|
2257
2261
|
let g = (await h.offset(c * l).limit(l)).map((e) => {
|
|
2258
2262
|
let { tenant_id: t, ...n } = e, r = { ...n };
|
|
2259
|
-
for (let e of
|
|
2263
|
+
for (let e of cn) r[e] = Z(n[e]);
|
|
2260
2264
|
return D(r);
|
|
2261
2265
|
});
|
|
2262
2266
|
if (!u) return { forms: g };
|
|
2263
|
-
let [_] = await e.select({ count: r() }).from(
|
|
2267
|
+
let [_] = await e.select({ count: r() }).from(Qe).where(m);
|
|
2264
2268
|
return {
|
|
2265
2269
|
forms: g,
|
|
2266
2270
|
start: c * l,
|
|
@@ -2269,47 +2273,47 @@ function sn(e) {
|
|
|
2269
2273
|
};
|
|
2270
2274
|
},
|
|
2271
2275
|
async remove(n, r) {
|
|
2272
|
-
return (await e.delete(
|
|
2276
|
+
return (await e.delete(Qe).where(t(a(Qe.tenant_id, n), a(Qe.id, r))).returning()).length > 0;
|
|
2273
2277
|
}
|
|
2274
2278
|
};
|
|
2275
2279
|
}
|
|
2276
2280
|
//#endregion
|
|
2277
2281
|
//#region src/adapters/grants.ts
|
|
2278
|
-
function
|
|
2282
|
+
function dn(e) {
|
|
2279
2283
|
return {
|
|
2280
2284
|
id: e.id,
|
|
2281
2285
|
user_id: e.user_id,
|
|
2282
2286
|
clientID: e.client_id,
|
|
2283
2287
|
audience: e.audience || void 0,
|
|
2284
|
-
scope:
|
|
2288
|
+
scope: Z(e.scope, []) ?? []
|
|
2285
2289
|
};
|
|
2286
2290
|
}
|
|
2287
|
-
var
|
|
2288
|
-
user_id:
|
|
2289
|
-
client_id:
|
|
2290
|
-
audience:
|
|
2291
|
-
created_at:
|
|
2292
|
-
updated_at:
|
|
2291
|
+
var fn = {
|
|
2292
|
+
user_id: z.user_id,
|
|
2293
|
+
client_id: z.client_id,
|
|
2294
|
+
audience: z.audience,
|
|
2295
|
+
created_at: z.created_at,
|
|
2296
|
+
updated_at: z.updated_at
|
|
2293
2297
|
};
|
|
2294
|
-
function
|
|
2295
|
-
return Object.hasOwn(
|
|
2298
|
+
function pn(e) {
|
|
2299
|
+
return Object.hasOwn(fn, e) ? fn[e] : void 0;
|
|
2296
2300
|
}
|
|
2297
|
-
function
|
|
2301
|
+
function mn(e) {
|
|
2298
2302
|
return {
|
|
2299
2303
|
async create(n, r) {
|
|
2300
|
-
let i = (/* @__PURE__ */ new Date()).toISOString(), o = r.scope ?? [], s = r.audience ?? "", c = await e.select().from(
|
|
2304
|
+
let i = (/* @__PURE__ */ new Date()).toISOString(), o = r.scope ?? [], s = r.audience ?? "", c = await e.select().from(z).where(t(a(z.tenant_id, n), a(z.user_id, r.user_id), a(z.client_id, r.clientID), a(z.audience, s))).get();
|
|
2301
2305
|
if (c) {
|
|
2302
|
-
let r =
|
|
2303
|
-
return await e.update(
|
|
2306
|
+
let r = Z(c.scope, []) ?? [], s = Array.from(new Set([...r, ...o]));
|
|
2307
|
+
return await e.update(z).set({
|
|
2304
2308
|
scope: JSON.stringify(s),
|
|
2305
2309
|
updated_at: i
|
|
2306
|
-
}).where(t(a(
|
|
2310
|
+
}).where(t(a(z.tenant_id, n), a(z.id, c.id))), dn({
|
|
2307
2311
|
...c,
|
|
2308
2312
|
scope: JSON.stringify(s)
|
|
2309
2313
|
});
|
|
2310
2314
|
}
|
|
2311
2315
|
let l = b();
|
|
2312
|
-
return await e.insert(
|
|
2316
|
+
return await e.insert(z).values({
|
|
2313
2317
|
id: l,
|
|
2314
2318
|
tenant_id: n,
|
|
2315
2319
|
user_id: r.user_id,
|
|
@@ -2327,24 +2331,24 @@ function dn(e) {
|
|
|
2327
2331
|
};
|
|
2328
2332
|
},
|
|
2329
2333
|
async get(n, r, i, o) {
|
|
2330
|
-
let s = await e.select().from(
|
|
2331
|
-
return s ?
|
|
2334
|
+
let s = await e.select().from(z).where(t(a(z.tenant_id, n), a(z.user_id, r), a(z.client_id, i), a(z.audience, o ?? ""))).get();
|
|
2335
|
+
return s ? dn(s) : null;
|
|
2332
2336
|
},
|
|
2333
2337
|
async list(o, s) {
|
|
2334
|
-
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ?
|
|
2338
|
+
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ? mt(z, f, [
|
|
2335
2339
|
"user_id",
|
|
2336
2340
|
"client_id",
|
|
2337
2341
|
"audience"
|
|
2338
|
-
]) : void 0, m = p ? t(a(
|
|
2339
|
-
h = g ? h.orderBy(d?.sort_order === "desc" ? i(g) : n(g)) : h.orderBy(n(
|
|
2340
|
-
let _ = (await h.offset(c * l).limit(l)).map(
|
|
2342
|
+
]) : void 0, m = p ? t(a(z.tenant_id, o), p) : a(z.tenant_id, o), h = e.select().from(z).where(m).$dynamic(), g = d?.sort_by ? pn(d.sort_by) : void 0;
|
|
2343
|
+
h = g ? h.orderBy(d?.sort_order === "desc" ? i(g) : n(g)) : h.orderBy(n(z.created_at));
|
|
2344
|
+
let _ = (await h.offset(c * l).limit(l)).map(dn);
|
|
2341
2345
|
if (!u) return {
|
|
2342
2346
|
grants: _,
|
|
2343
2347
|
start: 0,
|
|
2344
2348
|
limit: 0,
|
|
2345
2349
|
length: 0
|
|
2346
2350
|
};
|
|
2347
|
-
let [v] = await e.select({ count: r() }).from(
|
|
2351
|
+
let [v] = await e.select({ count: r() }).from(z).where(m);
|
|
2348
2352
|
return {
|
|
2349
2353
|
grants: _,
|
|
2350
2354
|
start: c * l,
|
|
@@ -2353,20 +2357,20 @@ function dn(e) {
|
|
|
2353
2357
|
};
|
|
2354
2358
|
},
|
|
2355
2359
|
async remove(n, r) {
|
|
2356
|
-
return (await e.delete(
|
|
2360
|
+
return (await e.delete(z).where(t(a(z.tenant_id, n), a(z.id, r))).returning()).length > 0;
|
|
2357
2361
|
},
|
|
2358
2362
|
async removeByUser(n, r) {
|
|
2359
|
-
return (await e.delete(
|
|
2363
|
+
return (await e.delete(z).where(t(a(z.tenant_id, n), a(z.user_id, r))).returning()).length > 0;
|
|
2360
2364
|
}
|
|
2361
2365
|
};
|
|
2362
2366
|
}
|
|
2363
2367
|
//#endregion
|
|
2364
2368
|
//#region src/adapters/hookCode.ts
|
|
2365
|
-
var
|
|
2366
|
-
function
|
|
2367
|
-
return `hc_${
|
|
2369
|
+
var hn = ee("0123456789abcdefghijklmnopqrstuvwxyz", 17);
|
|
2370
|
+
function gn() {
|
|
2371
|
+
return `hc_${hn()}`;
|
|
2368
2372
|
}
|
|
2369
|
-
function
|
|
2373
|
+
function _n(e) {
|
|
2370
2374
|
let { created_at_ts: t, updated_at_ts: n, secrets: r, ...i } = e, a = ae({
|
|
2371
2375
|
created_at_ts: t,
|
|
2372
2376
|
updated_at_ts: n
|
|
@@ -2377,41 +2381,41 @@ function mn(e) {
|
|
|
2377
2381
|
secrets: r ? JSON.parse(r) : void 0
|
|
2378
2382
|
};
|
|
2379
2383
|
}
|
|
2380
|
-
function
|
|
2384
|
+
function vn(e) {
|
|
2381
2385
|
return {
|
|
2382
2386
|
async create(t, n) {
|
|
2383
2387
|
let r = Date.now(), i = {
|
|
2384
|
-
id:
|
|
2388
|
+
id: gn(),
|
|
2385
2389
|
tenant_id: t,
|
|
2386
2390
|
code: n.code,
|
|
2387
2391
|
secrets: n.secrets ? JSON.stringify(n.secrets) : null,
|
|
2388
2392
|
created_at_ts: r,
|
|
2389
2393
|
updated_at_ts: r
|
|
2390
2394
|
};
|
|
2391
|
-
return await e.insert(
|
|
2395
|
+
return await e.insert(it).values(i), _n({
|
|
2392
2396
|
...i,
|
|
2393
2397
|
tenant_id: t
|
|
2394
2398
|
});
|
|
2395
2399
|
},
|
|
2396
2400
|
async get(n, r) {
|
|
2397
|
-
let i = await e.select().from(
|
|
2398
|
-
return i ?
|
|
2401
|
+
let i = await e.select().from(it).where(t(a(it.tenant_id, n), a(it.id, r))).get();
|
|
2402
|
+
return i ? _n(i) : null;
|
|
2399
2403
|
},
|
|
2400
2404
|
async update(n, r, i) {
|
|
2401
2405
|
let o = { updated_at_ts: Date.now() };
|
|
2402
|
-
return i.code !== void 0 && (o.code = i.code), i.secrets !== void 0 && (o.secrets = JSON.stringify(i.secrets)), (await e.update(
|
|
2406
|
+
return i.code !== void 0 && (o.code = i.code), i.secrets !== void 0 && (o.secrets = JSON.stringify(i.secrets)), (await e.update(it).set(o).where(t(a(it.tenant_id, n), a(it.id, r))).returning()).length > 0;
|
|
2403
2407
|
},
|
|
2404
2408
|
async remove(n, r) {
|
|
2405
|
-
return (await e.delete(
|
|
2409
|
+
return (await e.delete(it).where(t(a(it.tenant_id, n), a(it.id, r))).returning()).length > 0;
|
|
2406
2410
|
}
|
|
2407
2411
|
};
|
|
2408
2412
|
}
|
|
2409
2413
|
//#endregion
|
|
2410
2414
|
//#region src/adapters/hooks.ts
|
|
2411
|
-
function
|
|
2415
|
+
function yn() {
|
|
2412
2416
|
return `h_${ee("0123456789abcdefghijklmnopqrstuvwxyz", 17)()}`;
|
|
2413
2417
|
}
|
|
2414
|
-
function
|
|
2418
|
+
function bn(e) {
|
|
2415
2419
|
if (!(typeof e != "string" || !e)) try {
|
|
2416
2420
|
let t = JSON.parse(e);
|
|
2417
2421
|
return t && typeof t == "object" && !Array.isArray(t) ? t : void 0;
|
|
@@ -2419,7 +2423,7 @@ function _n(e) {
|
|
|
2419
2423
|
return;
|
|
2420
2424
|
}
|
|
2421
2425
|
}
|
|
2422
|
-
function
|
|
2426
|
+
function xn(e) {
|
|
2423
2427
|
let { tenant_id: t, created_at_ts: n, updated_at_ts: r, metadata: i, ...a } = e, o = ae({
|
|
2424
2428
|
created_at_ts: n,
|
|
2425
2429
|
updated_at_ts: r
|
|
@@ -2428,15 +2432,15 @@ function vn(e) {
|
|
|
2428
2432
|
...a,
|
|
2429
2433
|
enabled: !!a.enabled,
|
|
2430
2434
|
synchronous: !!a.synchronous,
|
|
2431
|
-
metadata:
|
|
2435
|
+
metadata: bn(i),
|
|
2432
2436
|
...o
|
|
2433
2437
|
});
|
|
2434
2438
|
}
|
|
2435
|
-
function
|
|
2439
|
+
function Sn(e) {
|
|
2436
2440
|
return {
|
|
2437
2441
|
async create(t, n) {
|
|
2438
2442
|
let r = Date.now(), i = {
|
|
2439
|
-
hook_id: n.hook_id ||
|
|
2443
|
+
hook_id: n.hook_id || yn(),
|
|
2440
2444
|
tenant_id: t,
|
|
2441
2445
|
trigger_id: n.trigger_id,
|
|
2442
2446
|
url: n.url,
|
|
@@ -2452,30 +2456,30 @@ function yn(e) {
|
|
|
2452
2456
|
created_at_ts: r,
|
|
2453
2457
|
updated_at_ts: r
|
|
2454
2458
|
};
|
|
2455
|
-
return await e.insert(
|
|
2459
|
+
return await e.insert(rt).values(i), xn({
|
|
2456
2460
|
...i,
|
|
2457
2461
|
tenant_id: t
|
|
2458
2462
|
});
|
|
2459
2463
|
},
|
|
2460
2464
|
async get(n, r) {
|
|
2461
|
-
let i = await e.select().from(
|
|
2462
|
-
return i ?
|
|
2465
|
+
let i = await e.select().from(rt).where(t(a(rt.tenant_id, n), a(rt.hook_id, r))).get();
|
|
2466
|
+
return i ? xn(i) : null;
|
|
2463
2467
|
},
|
|
2464
2468
|
async update(n, r, i) {
|
|
2465
2469
|
let o = { updated_at_ts: Date.now() };
|
|
2466
|
-
return i.trigger_id !== void 0 && (o.trigger_id = i.trigger_id), i.url !== void 0 && (o.url = i.url), i.enabled !== void 0 && (o.enabled = i.enabled), i.synchronous !== void 0 && (o.synchronous = i.synchronous), i.priority !== void 0 && (o.priority = i.priority), i.form_id !== void 0 && (o.form_id = i.form_id), i.template_id !== void 0 && (o.template_id = i.template_id), i.code_id !== void 0 && (o.code_id = i.code_id), i.page_id !== void 0 && (o.page_id = i.page_id), i.permission_required !== void 0 && (o.permission_required = i.permission_required), i.metadata !== void 0 && (o.metadata = i.metadata === null ? null : JSON.stringify(i.metadata)), (await e.update(
|
|
2470
|
+
return i.trigger_id !== void 0 && (o.trigger_id = i.trigger_id), i.url !== void 0 && (o.url = i.url), i.enabled !== void 0 && (o.enabled = i.enabled), i.synchronous !== void 0 && (o.synchronous = i.synchronous), i.priority !== void 0 && (o.priority = i.priority), i.form_id !== void 0 && (o.form_id = i.form_id), i.template_id !== void 0 && (o.template_id = i.template_id), i.code_id !== void 0 && (o.code_id = i.code_id), i.page_id !== void 0 && (o.page_id = i.page_id), i.permission_required !== void 0 && (o.permission_required = i.permission_required), i.metadata !== void 0 && (o.metadata = i.metadata === null ? null : JSON.stringify(i.metadata)), (await e.update(rt).set(o).where(t(a(rt.tenant_id, n), a(rt.hook_id, r))).returning()).length > 0;
|
|
2467
2471
|
},
|
|
2468
2472
|
async list(o, s) {
|
|
2469
|
-
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ?
|
|
2473
|
+
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ? mt(rt, f, [
|
|
2470
2474
|
"url",
|
|
2471
2475
|
"form_id",
|
|
2472
2476
|
"template_id",
|
|
2473
2477
|
"code_id"
|
|
2474
|
-
]) : void 0, m = p ? t(a(
|
|
2475
|
-
h = g ? h.orderBy(d?.sort_order === "desc" ? i(g) : n(g)) : h.orderBy(i(
|
|
2476
|
-
let _ = (await h.offset(c * l).limit(l)).map(
|
|
2478
|
+
]) : void 0, m = p ? t(a(rt.tenant_id, o), p) : a(rt.tenant_id, o), h = e.select().from(rt).where(m).$dynamic(), g = d?.sort_by ? rt[d.sort_by] : void 0;
|
|
2479
|
+
h = g ? h.orderBy(d?.sort_order === "desc" ? i(g) : n(g)) : h.orderBy(i(rt.priority), n(rt.created_at_ts));
|
|
2480
|
+
let _ = (await h.offset(c * l).limit(l)).map(xn);
|
|
2477
2481
|
if (!u) return { hooks: _ };
|
|
2478
|
-
let [v] = await e.select({ count: r() }).from(
|
|
2482
|
+
let [v] = await e.select({ count: r() }).from(rt).where(m);
|
|
2479
2483
|
return {
|
|
2480
2484
|
hooks: _,
|
|
2481
2485
|
start: c * l,
|
|
@@ -2484,31 +2488,31 @@ function yn(e) {
|
|
|
2484
2488
|
};
|
|
2485
2489
|
},
|
|
2486
2490
|
async remove(n, r) {
|
|
2487
|
-
return (await e.delete(
|
|
2491
|
+
return (await e.delete(rt).where(t(a(rt.tenant_id, n), a(rt.hook_id, r))).returning()).length > 0;
|
|
2488
2492
|
}
|
|
2489
2493
|
};
|
|
2490
2494
|
}
|
|
2491
2495
|
//#endregion
|
|
2492
2496
|
//#region src/adapters/invites.ts
|
|
2493
|
-
function
|
|
2497
|
+
function Cn() {
|
|
2494
2498
|
return `inv_${ee("0123456789abcdefghijklmnopqrstuvwxyz", 17)()}`;
|
|
2495
2499
|
}
|
|
2496
|
-
var
|
|
2500
|
+
var wn = [
|
|
2497
2501
|
"inviter",
|
|
2498
2502
|
"invitee",
|
|
2499
2503
|
"app_metadata",
|
|
2500
2504
|
"user_metadata",
|
|
2501
2505
|
"roles"
|
|
2502
2506
|
];
|
|
2503
|
-
function
|
|
2507
|
+
function Tn(e) {
|
|
2504
2508
|
let { tenant_id: t, send_invitation_email: n, ...r } = e, i = { ...r };
|
|
2505
|
-
for (let e of
|
|
2509
|
+
for (let e of wn) i[e] = Z(r[e], e === "roles" ? [] : {});
|
|
2506
2510
|
return i.send_invitation_email = !!n, D(i);
|
|
2507
2511
|
}
|
|
2508
|
-
function
|
|
2512
|
+
function En(e) {
|
|
2509
2513
|
return {
|
|
2510
2514
|
async create(t, n) {
|
|
2511
|
-
let r = n.id ||
|
|
2515
|
+
let r = n.id || Cn(), i = n.ttl_sec || 604800, a = /* @__PURE__ */ new Date(), o = new Date(a.getTime() + i * 1e3).toISOString(), s = {
|
|
2512
2516
|
id: r,
|
|
2513
2517
|
tenant_id: t,
|
|
2514
2518
|
organization_id: n.organization_id,
|
|
@@ -2521,35 +2525,35 @@ function Cn(e) {
|
|
|
2521
2525
|
created_at: a.toISOString(),
|
|
2522
2526
|
expires_at: o
|
|
2523
2527
|
};
|
|
2524
|
-
for (let e of
|
|
2528
|
+
for (let e of wn) n[e] !== void 0 && (s[e] = JSON.stringify(n[e]));
|
|
2525
2529
|
try {
|
|
2526
|
-
await e.insert(
|
|
2530
|
+
await e.insert(Ke).values(s);
|
|
2527
2531
|
} catch (e) {
|
|
2528
|
-
throw e?.message?.includes("UNIQUE constraint failed") || e?.message?.includes("duplicate key") ? new
|
|
2532
|
+
throw e?.message?.includes("UNIQUE constraint failed") || e?.message?.includes("duplicate key") ? new Fe(409, { message: "Invite already exists" }) : e;
|
|
2529
2533
|
}
|
|
2530
|
-
return
|
|
2534
|
+
return Tn({
|
|
2531
2535
|
...s,
|
|
2532
2536
|
tenant_id: t
|
|
2533
2537
|
});
|
|
2534
2538
|
},
|
|
2535
2539
|
async get(n, r) {
|
|
2536
|
-
let i = await e.select().from(
|
|
2537
|
-
return i ?
|
|
2540
|
+
let i = await e.select().from(Ke).where(t(a(Ke.tenant_id, n), a(Ke.id, r))).get();
|
|
2541
|
+
return i ? Tn(i) : null;
|
|
2538
2542
|
},
|
|
2539
2543
|
async update(n, r, i) {
|
|
2540
2544
|
let o = {};
|
|
2541
|
-
for (let e of
|
|
2542
|
-
return i.connection_id !== void 0 && (o.connection_id = i.connection_id), i.ttl_sec !== void 0 && (o.ttl_sec = i.ttl_sec, o.expires_at = new Date(Date.now() + i.ttl_sec * 1e3).toISOString()), (await e.update(
|
|
2545
|
+
for (let e of wn) i[e] !== void 0 && (o[e] = JSON.stringify(i[e]));
|
|
2546
|
+
return i.connection_id !== void 0 && (o.connection_id = i.connection_id), i.ttl_sec !== void 0 && (o.ttl_sec = i.ttl_sec, o.expires_at = new Date(Date.now() + i.ttl_sec * 1e3).toISOString()), (await e.update(Ke).set(o).where(t(a(Ke.tenant_id, n), a(Ke.id, r))).returning()).length > 0;
|
|
2543
2547
|
},
|
|
2544
2548
|
async list(t, o) {
|
|
2545
|
-
let { page: s = 0, per_page: c = 50, include_totals: l = !1, sort: u } = o || {}, d = e.select().from(
|
|
2549
|
+
let { page: s = 0, per_page: c = 50, include_totals: l = !1, sort: u } = o || {}, d = e.select().from(Ke).where(a(Ke.tenant_id, t)).$dynamic();
|
|
2546
2550
|
if (u?.sort_by) {
|
|
2547
|
-
let e =
|
|
2551
|
+
let e = Ke[u.sort_by];
|
|
2548
2552
|
e && (d = d.orderBy(u.sort_order === "desc" ? i(e) : n(e)));
|
|
2549
2553
|
}
|
|
2550
|
-
let f = (await d.offset(s * c).limit(c)).map(
|
|
2554
|
+
let f = (await d.offset(s * c).limit(c)).map(Tn);
|
|
2551
2555
|
if (!l) return { invites: f };
|
|
2552
|
-
let [p] = await e.select({ count: r() }).from(
|
|
2556
|
+
let [p] = await e.select({ count: r() }).from(Ke).where(a(Ke.tenant_id, t));
|
|
2553
2557
|
return {
|
|
2554
2558
|
invites: f,
|
|
2555
2559
|
start: s * c,
|
|
@@ -2558,39 +2562,39 @@ function Cn(e) {
|
|
|
2558
2562
|
};
|
|
2559
2563
|
},
|
|
2560
2564
|
async remove(n, r) {
|
|
2561
|
-
return (await e.delete(
|
|
2565
|
+
return (await e.delete(Ke).where(t(a(Ke.tenant_id, n), a(Ke.id, r))).returning()).length > 0;
|
|
2562
2566
|
}
|
|
2563
2567
|
};
|
|
2564
2568
|
}
|
|
2565
2569
|
//#endregion
|
|
2566
2570
|
//#region src/adapters/keys.ts
|
|
2567
|
-
var
|
|
2571
|
+
var Dn = [
|
|
2568
2572
|
"kid",
|
|
2569
2573
|
"connection",
|
|
2570
2574
|
"fingerprint",
|
|
2571
2575
|
"thumbprint",
|
|
2572
2576
|
"type"
|
|
2573
2577
|
];
|
|
2574
|
-
function
|
|
2578
|
+
function On(e) {
|
|
2575
2579
|
return {
|
|
2576
2580
|
async create(t) {
|
|
2577
|
-
await e.insert(
|
|
2581
|
+
await e.insert(at).values({
|
|
2578
2582
|
...t,
|
|
2579
2583
|
created_at: (/* @__PURE__ */ new Date()).toDateString()
|
|
2580
2584
|
});
|
|
2581
2585
|
},
|
|
2582
2586
|
async list(a) {
|
|
2583
|
-
let { page: o = 0, per_page: c = 50, include_totals: l = !1, sort: u, q: d } = a || {}, p = (/* @__PURE__ */ new Date()).toISOString(), m = [v(s(
|
|
2587
|
+
let { page: o = 0, per_page: c = 50, include_totals: l = !1, sort: u, q: d } = a || {}, p = (/* @__PURE__ */ new Date()).toISOString(), m = [v(s(at.revoked_at, p), f(at.revoked_at))];
|
|
2584
2588
|
if (d) {
|
|
2585
|
-
let e = we(d,
|
|
2589
|
+
let e = we(d, Dn);
|
|
2586
2590
|
if (e) {
|
|
2587
|
-
let t =
|
|
2591
|
+
let t = mt(at, e, Dn);
|
|
2588
2592
|
t && m.push(t);
|
|
2589
2593
|
}
|
|
2590
2594
|
}
|
|
2591
|
-
let h = t(...m), g = e.select().from(
|
|
2595
|
+
let h = t(...m), g = e.select().from(at).where(h).$dynamic();
|
|
2592
2596
|
if (u?.sort_by) {
|
|
2593
|
-
let e =
|
|
2597
|
+
let e = at[u.sort_by];
|
|
2594
2598
|
e && (g = g.orderBy(u.sort_order === "desc" ? i(e) : n(e)));
|
|
2595
2599
|
}
|
|
2596
2600
|
let _ = (await g.offset(o * c).limit(c)).map((e) => {
|
|
@@ -2598,7 +2602,7 @@ function Tn(e) {
|
|
|
2598
2602
|
return D(n);
|
|
2599
2603
|
});
|
|
2600
2604
|
if (!l) return { signingKeys: _ };
|
|
2601
|
-
let [y] = await e.select({ count: r() }).from(
|
|
2605
|
+
let [y] = await e.select({ count: r() }).from(at).where(h);
|
|
2602
2606
|
return {
|
|
2603
2607
|
signingKeys: _,
|
|
2604
2608
|
start: o * c,
|
|
@@ -2607,22 +2611,22 @@ function Tn(e) {
|
|
|
2607
2611
|
};
|
|
2608
2612
|
},
|
|
2609
2613
|
async update(t, n) {
|
|
2610
|
-
return (await e.update(
|
|
2614
|
+
return (await e.update(at).set(n).where(a(at.kid, t)).returning()).length > 0;
|
|
2611
2615
|
}
|
|
2612
2616
|
};
|
|
2613
2617
|
}
|
|
2614
2618
|
//#endregion
|
|
2615
2619
|
//#region src/adapters/loginSessions.ts
|
|
2616
|
-
var
|
|
2617
|
-
function
|
|
2620
|
+
var kn = "0123456789ABCDEFGHJKMNPQRSTVWXYZ", An = 32;
|
|
2621
|
+
function jn() {
|
|
2618
2622
|
let e = Date.now(), t = "";
|
|
2619
|
-
for (let n = 10; n > 0; n--) t =
|
|
2623
|
+
for (let n = 10; n > 0; n--) t = kn.charAt(e % An) + t, e = Math.floor(e / An);
|
|
2620
2624
|
let n = new Uint8Array(16);
|
|
2621
2625
|
crypto.getRandomValues(n);
|
|
2622
|
-
for (let e = 0; e < 16; e++) t +=
|
|
2626
|
+
for (let e = 0; e < 16; e++) t += kn.charAt(n[e] % An);
|
|
2623
2627
|
return t;
|
|
2624
2628
|
}
|
|
2625
|
-
function
|
|
2629
|
+
function Mn(e) {
|
|
2626
2630
|
let { tenant_id: t, created_at_ts: n, updated_at_ts: r, expires_at_ts: i, state_data: a, auth_params: o, ...s } = e, c = ae({
|
|
2627
2631
|
created_at_ts: n,
|
|
2628
2632
|
updated_at_ts: r,
|
|
@@ -2634,17 +2638,17 @@ function kn(e) {
|
|
|
2634
2638
|
]), l = {};
|
|
2635
2639
|
for (let [e, t] of Object.entries(s)) t != null && (l[e] = t);
|
|
2636
2640
|
return D({
|
|
2637
|
-
...
|
|
2641
|
+
...dt(l, ["auth_strategy"]),
|
|
2638
2642
|
authParams: typeof o == "string" && o.length > 0 ? JSON.parse(o) : {},
|
|
2639
2643
|
...c,
|
|
2640
|
-
state_data:
|
|
2644
|
+
state_data: Z(a)
|
|
2641
2645
|
});
|
|
2642
2646
|
}
|
|
2643
|
-
function
|
|
2647
|
+
function Nn(e) {
|
|
2644
2648
|
return {
|
|
2645
2649
|
async create(t, n) {
|
|
2646
2650
|
let r = Date.now(), i = {
|
|
2647
|
-
id:
|
|
2651
|
+
id: jn(),
|
|
2648
2652
|
tenant_id: t,
|
|
2649
2653
|
session_id: n.session_id,
|
|
2650
2654
|
csrf_token: n.csrf_token,
|
|
@@ -2665,39 +2669,39 @@ function An(e) {
|
|
|
2665
2669
|
updated_at_ts: r,
|
|
2666
2670
|
expires_at_ts: n.expires_at ? E(n.expires_at) : r + 1e3 * 60 * 60 * 24
|
|
2667
2671
|
};
|
|
2668
|
-
return await e.insert(
|
|
2672
|
+
return await e.insert(P).values(i), Mn({
|
|
2669
2673
|
...i,
|
|
2670
2674
|
tenant_id: t
|
|
2671
2675
|
});
|
|
2672
2676
|
},
|
|
2673
2677
|
async get(n, r) {
|
|
2674
|
-
let i = n ? t(a(
|
|
2675
|
-
return o ?
|
|
2678
|
+
let i = n ? t(a(P.tenant_id, n), a(P.id, r)) : a(P.id, r), o = await e.select().from(P).where(i).get();
|
|
2679
|
+
return o ? Mn(o) : null;
|
|
2676
2680
|
},
|
|
2677
2681
|
async update(n, r, i) {
|
|
2678
2682
|
let o = { updated_at_ts: Date.now() };
|
|
2679
2683
|
if (i.session_id !== void 0 && (o.session_id = i.session_id), i.state !== void 0 && (o.state = i.state), i.state_data !== void 0 && (o.state_data = JSON.stringify(i.state_data)), i.failure_reason !== void 0 && (o.failure_reason = i.failure_reason), i.user_id !== void 0 && (o.user_id = i.user_id), i.auth_connection !== void 0 && (o.auth_connection = i.auth_connection), i.auth_strategy !== void 0 && (o.auth_strategy_strategy = i.auth_strategy?.strategy, o.auth_strategy_strategy_type = i.auth_strategy?.strategy_type), i.authenticated_at !== void 0 && (o.authenticated_at = i.authenticated_at), i.authorization_url !== void 0 && (o.authorization_url = i.authorization_url?.substring(0, 1024)), i.expires_at !== void 0 && (o.expires_at_ts = E(i.expires_at)), i.authParams !== void 0) {
|
|
2680
|
-
let s = await e.select({ auth_params:
|
|
2684
|
+
let s = await e.select({ auth_params: P.auth_params }).from(P).where(t(a(P.tenant_id, n), a(P.id, r))).get(), c = s?.auth_params && typeof s.auth_params == "string" && s.auth_params.length > 0 ? JSON.parse(s.auth_params) : {};
|
|
2681
2685
|
o.auth_params = JSON.stringify({
|
|
2682
2686
|
...c,
|
|
2683
2687
|
...i.authParams
|
|
2684
2688
|
});
|
|
2685
2689
|
}
|
|
2686
|
-
return await e.update(
|
|
2690
|
+
return await e.update(P).set(o).where(t(a(P.tenant_id, n), a(P.id, r))), !0;
|
|
2687
2691
|
},
|
|
2688
2692
|
async remove(n, r) {
|
|
2689
|
-
return (await e.delete(
|
|
2693
|
+
return (await e.delete(P).where(t(a(P.tenant_id, n), a(P.id, r))).returning()).length > 0;
|
|
2690
2694
|
}
|
|
2691
2695
|
};
|
|
2692
2696
|
}
|
|
2693
2697
|
//#endregion
|
|
2694
2698
|
//#region src/adapters/logs.ts
|
|
2695
|
-
function
|
|
2699
|
+
function Pn(e) {
|
|
2696
2700
|
let { tenant_id: t, isMobile: n, auth0_client: r, details: i, country_code: a, city_name: o, latitude: s, longitude: c, time_zone: l, continent_code: u, scope: d, ...f } = e, p = {
|
|
2697
2701
|
...f,
|
|
2698
2702
|
isMobile: !!n,
|
|
2699
|
-
auth0_client:
|
|
2700
|
-
details:
|
|
2703
|
+
auth0_client: Z(r),
|
|
2704
|
+
details: Z(i),
|
|
2701
2705
|
scope: d ? d.split(",") : void 0
|
|
2702
2706
|
};
|
|
2703
2707
|
return a && (p.location_info = D({
|
|
@@ -2709,7 +2713,7 @@ function jn(e) {
|
|
|
2709
2713
|
continent_code: u
|
|
2710
2714
|
})), D(p);
|
|
2711
2715
|
}
|
|
2712
|
-
function
|
|
2716
|
+
function Fn(e) {
|
|
2713
2717
|
return {
|
|
2714
2718
|
async create(t, n) {
|
|
2715
2719
|
let r = {
|
|
@@ -2735,15 +2739,15 @@ function Mn(e) {
|
|
|
2735
2739
|
hostname: n.hostname,
|
|
2736
2740
|
session_connection: n.session_connection
|
|
2737
2741
|
};
|
|
2738
|
-
return n.auth0_client && (r.auth0_client = JSON.stringify(n.auth0_client)), n.details && (r.details = JSON.stringify(n.details).substring(0, 8192)), n.location_info && (r.country_code = n.location_info.country_code, r.city_name = n.location_info.city_name, r.latitude = n.location_info.latitude, r.longitude = n.location_info.longitude, r.time_zone = n.location_info.time_zone, r.continent_code = n.location_info.continent_code), await e.insert(
|
|
2742
|
+
return n.auth0_client && (r.auth0_client = JSON.stringify(n.auth0_client)), n.details && (r.details = JSON.stringify(n.details).substring(0, 8192)), n.location_info && (r.country_code = n.location_info.country_code, r.city_name = n.location_info.city_name, r.latitude = n.location_info.latitude, r.longitude = n.location_info.longitude, r.time_zone = n.location_info.time_zone, r.continent_code = n.location_info.continent_code), await e.insert(q).values(r), Pn({
|
|
2739
2743
|
...r,
|
|
2740
2744
|
tenant_id: t
|
|
2741
2745
|
});
|
|
2742
2746
|
},
|
|
2743
2747
|
async list(o, s) {
|
|
2744
|
-
let { page: l = 0, per_page: u = 50, include_totals: d = !1, sort: f, q: p, from_date: h, to_date: g } = s || {}, _ = [a(
|
|
2748
|
+
let { page: l = 0, per_page: u = 50, include_totals: d = !1, sort: f, q: p, from_date: h, to_date: g } = s || {}, _ = [a(q.tenant_id, o)];
|
|
2745
2749
|
if (p) {
|
|
2746
|
-
let e =
|
|
2750
|
+
let e = mt(q, p, [
|
|
2747
2751
|
"user_id",
|
|
2748
2752
|
"ip",
|
|
2749
2753
|
"type",
|
|
@@ -2751,16 +2755,16 @@ function Mn(e) {
|
|
|
2751
2755
|
], ["description"]);
|
|
2752
2756
|
e && _.push(e);
|
|
2753
2757
|
}
|
|
2754
|
-
typeof h == "number" && Number.isFinite(h) && _.push(c(
|
|
2758
|
+
typeof h == "number" && Number.isFinite(h) && _.push(c(q.date, (/* @__PURE__ */ new Date(Math.floor(h) * 1e3)).toISOString())), typeof g == "number" && Number.isFinite(g) && _.push(m(q.date, (/* @__PURE__ */ new Date((Math.floor(g) + 1) * 1e3)).toISOString()));
|
|
2755
2759
|
let v = t(..._);
|
|
2756
|
-
if (
|
|
2757
|
-
if (f?.sort_by && f.sort_by !== "date") throw new
|
|
2760
|
+
if (Et(s)) {
|
|
2761
|
+
if (f?.sort_by && f.sort_by !== "date") throw new Fe(400, { message: `Sorting by ${f.sort_by} is not supported with checkpoint pagination (from/take); only date is` });
|
|
2758
2762
|
let n = f?.sort_order === "asc" ? "asc" : "desc", r = {
|
|
2759
|
-
sortColumn:
|
|
2760
|
-
idColumn:
|
|
2763
|
+
sortColumn: q.date,
|
|
2764
|
+
idColumn: q.log_id,
|
|
2761
2765
|
sortOrder: n,
|
|
2762
2766
|
sortKey: `date:${n}`
|
|
2763
|
-
}, i =
|
|
2767
|
+
}, i = kt(s, r), a = Dt(s), { rows: o, next: c } = At(await e.select().from(q).where(i ? t(v, i) : v).orderBy(...Ot(r)).limit(a + 1), a, "date", "log_id", r.sortKey), l = o.map(Pn);
|
|
2764
2768
|
return {
|
|
2765
2769
|
logs: l,
|
|
2766
2770
|
start: 0,
|
|
@@ -2769,14 +2773,14 @@ function Mn(e) {
|
|
|
2769
2773
|
next: c
|
|
2770
2774
|
};
|
|
2771
2775
|
}
|
|
2772
|
-
let y = e.select().from(
|
|
2776
|
+
let y = e.select().from(q).where(v).$dynamic();
|
|
2773
2777
|
if (f?.sort_by) {
|
|
2774
|
-
let e =
|
|
2778
|
+
let e = q[f.sort_by];
|
|
2775
2779
|
e && (y = y.orderBy(f.sort_order === "desc" ? i(e) : n(e)));
|
|
2776
|
-
} else y = y.orderBy(i(
|
|
2777
|
-
let ee = (await y.offset(l * u).limit(u)).map(
|
|
2780
|
+
} else y = y.orderBy(i(q.date));
|
|
2781
|
+
let ee = (await y.offset(l * u).limit(u)).map(Pn);
|
|
2778
2782
|
if (!d) return { logs: ee };
|
|
2779
|
-
let [b] = await e.select({ count: r() }).from(
|
|
2783
|
+
let [b] = await e.select({ count: r() }).from(q).where(v);
|
|
2780
2784
|
return {
|
|
2781
2785
|
logs: ee,
|
|
2782
2786
|
start: l * u,
|
|
@@ -2785,38 +2789,38 @@ function Mn(e) {
|
|
|
2785
2789
|
};
|
|
2786
2790
|
},
|
|
2787
2791
|
async get(n, r) {
|
|
2788
|
-
let i = await e.select().from(
|
|
2789
|
-
return i ?
|
|
2792
|
+
let i = await e.select().from(q).where(t(a(q.tenant_id, n), a(q.log_id, r))).get();
|
|
2793
|
+
return i ? Pn(i) : null;
|
|
2790
2794
|
}
|
|
2791
2795
|
};
|
|
2792
2796
|
}
|
|
2793
2797
|
//#endregion
|
|
2794
2798
|
//#region src/adapters/authenticationMethods.ts
|
|
2795
|
-
var
|
|
2796
|
-
function
|
|
2799
|
+
var In = "0123456789ABCDEFGHJKMNPQRSTVWXYZ", Ln = 32;
|
|
2800
|
+
function Rn() {
|
|
2797
2801
|
let e = Date.now(), t = "";
|
|
2798
|
-
for (let n = 10; n > 0; n--) t =
|
|
2802
|
+
for (let n = 10; n > 0; n--) t = In.charAt(e % Ln) + t, e = Math.floor(e / Ln);
|
|
2799
2803
|
let n = new Uint8Array(16);
|
|
2800
2804
|
crypto.getRandomValues(n);
|
|
2801
|
-
for (let e = 0; e < 16; e++) t +=
|
|
2805
|
+
for (let e = 0; e < 16; e++) t += In.charAt(n[e] % Ln);
|
|
2802
2806
|
return t;
|
|
2803
2807
|
}
|
|
2804
|
-
function
|
|
2808
|
+
function zn(e) {
|
|
2805
2809
|
let { tenant_id: t, created_at_ts: n, updated_at_ts: r, credential_backed_up: i, confirmed: a, transports: o, ...s } = e;
|
|
2806
2810
|
return D({
|
|
2807
2811
|
...s,
|
|
2808
2812
|
confirmed: !!a,
|
|
2809
2813
|
credential_backed_up: i == null ? void 0 : !!i,
|
|
2810
|
-
transports:
|
|
2814
|
+
transports: Z(o),
|
|
2811
2815
|
created_at: oe(n),
|
|
2812
2816
|
updated_at: oe(r)
|
|
2813
2817
|
});
|
|
2814
2818
|
}
|
|
2815
|
-
function
|
|
2819
|
+
function Bn(e) {
|
|
2816
2820
|
return {
|
|
2817
2821
|
async create(t, n) {
|
|
2818
2822
|
let r = Date.now(), i = {
|
|
2819
|
-
id: n.id ||
|
|
2823
|
+
id: n.id || Rn(),
|
|
2820
2824
|
tenant_id: t,
|
|
2821
2825
|
user_id: n.user_id,
|
|
2822
2826
|
type: n.type,
|
|
@@ -2832,55 +2836,55 @@ function Ln(e) {
|
|
|
2832
2836
|
created_at_ts: r,
|
|
2833
2837
|
updated_at_ts: r
|
|
2834
2838
|
};
|
|
2835
|
-
return await e.insert(
|
|
2839
|
+
return await e.insert(K).values(i), zn({
|
|
2836
2840
|
...i,
|
|
2837
2841
|
tenant_id: t
|
|
2838
2842
|
});
|
|
2839
2843
|
},
|
|
2840
2844
|
async get(n, r) {
|
|
2841
|
-
let i = await e.select().from(
|
|
2842
|
-
return i ?
|
|
2845
|
+
let i = await e.select().from(K).where(t(a(K.tenant_id, n), a(K.id, r))).get();
|
|
2846
|
+
return i ? zn(i) : null;
|
|
2843
2847
|
},
|
|
2844
2848
|
async getByCredentialId(n, r) {
|
|
2845
|
-
let i = await e.select().from(
|
|
2846
|
-
return i ?
|
|
2849
|
+
let i = await e.select().from(K).where(t(a(K.tenant_id, n), a(K.credential_id, r))).get();
|
|
2850
|
+
return i ? zn(i) : null;
|
|
2847
2851
|
},
|
|
2848
2852
|
async list(n, r) {
|
|
2849
|
-
return (await e.select().from(
|
|
2853
|
+
return (await e.select().from(K).where(t(a(K.tenant_id, n), a(K.user_id, r))).all()).map(zn);
|
|
2850
2854
|
},
|
|
2851
2855
|
async update(n, r, i) {
|
|
2852
2856
|
let o = { updated_at_ts: Date.now() };
|
|
2853
|
-
i.type !== void 0 && (o.type = i.type), i.phone_number !== void 0 && (o.phone_number = i.phone_number), i.totp_secret !== void 0 && (o.totp_secret = i.totp_secret), i.credential_id !== void 0 && (o.credential_id = i.credential_id), i.public_key !== void 0 && (o.public_key = i.public_key), i.sign_count !== void 0 && (o.sign_count = i.sign_count), i.credential_backed_up !== void 0 && (o.credential_backed_up = +!!i.credential_backed_up), i.transports !== void 0 && (o.transports = JSON.stringify(i.transports)), i.friendly_name !== void 0 && (o.friendly_name = i.friendly_name), i.confirmed !== void 0 && (o.confirmed = +!!i.confirmed), await e.update(
|
|
2857
|
+
i.type !== void 0 && (o.type = i.type), i.phone_number !== void 0 && (o.phone_number = i.phone_number), i.totp_secret !== void 0 && (o.totp_secret = i.totp_secret), i.credential_id !== void 0 && (o.credential_id = i.credential_id), i.public_key !== void 0 && (o.public_key = i.public_key), i.sign_count !== void 0 && (o.sign_count = i.sign_count), i.credential_backed_up !== void 0 && (o.credential_backed_up = +!!i.credential_backed_up), i.transports !== void 0 && (o.transports = JSON.stringify(i.transports)), i.friendly_name !== void 0 && (o.friendly_name = i.friendly_name), i.confirmed !== void 0 && (o.confirmed = +!!i.confirmed), await e.update(K).set(o).where(t(a(K.tenant_id, n), a(K.id, r)));
|
|
2854
2858
|
let s = await this.get(n, r);
|
|
2855
2859
|
if (!s) throw Error(`Authentication method ${r} not found after update`);
|
|
2856
2860
|
return s;
|
|
2857
2861
|
},
|
|
2858
2862
|
async remove(n, r) {
|
|
2859
|
-
return (await e.delete(
|
|
2863
|
+
return (await e.delete(K).where(t(a(K.tenant_id, n), a(K.id, r))).returning()).length > 0;
|
|
2860
2864
|
}
|
|
2861
2865
|
};
|
|
2862
2866
|
}
|
|
2863
2867
|
//#endregion
|
|
2864
2868
|
//#region src/adapters/organizations.ts
|
|
2865
|
-
var
|
|
2866
|
-
function
|
|
2869
|
+
var Vn = ["name", "display_name"];
|
|
2870
|
+
function Hn() {
|
|
2867
2871
|
return `org_${ee("0123456789abcdefghijklmnopqrstuvwxyz", 17)()}`;
|
|
2868
2872
|
}
|
|
2869
|
-
function
|
|
2873
|
+
function Un(e) {
|
|
2870
2874
|
let { tenant_id: t, branding: n, metadata: r, enabled_connections: i, token_quota: a, ...o } = e;
|
|
2871
2875
|
return D({
|
|
2872
2876
|
...o,
|
|
2873
|
-
branding:
|
|
2874
|
-
metadata:
|
|
2875
|
-
enabled_connections:
|
|
2876
|
-
token_quota:
|
|
2877
|
+
branding: Z(n, {}),
|
|
2878
|
+
metadata: Z(r, {}),
|
|
2879
|
+
enabled_connections: Z(i, []),
|
|
2880
|
+
token_quota: Z(a, {})
|
|
2877
2881
|
});
|
|
2878
2882
|
}
|
|
2879
|
-
function
|
|
2883
|
+
function Wn(e) {
|
|
2880
2884
|
return {
|
|
2881
2885
|
async create(t, n) {
|
|
2882
2886
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
2883
|
-
id: n.id ||
|
|
2887
|
+
id: n.id || Hn(),
|
|
2884
2888
|
tenant_id: t,
|
|
2885
2889
|
name: n.name,
|
|
2886
2890
|
display_name: n.display_name,
|
|
@@ -2892,39 +2896,39 @@ function Vn(e) {
|
|
|
2892
2896
|
updated_at: r
|
|
2893
2897
|
};
|
|
2894
2898
|
try {
|
|
2895
|
-
await e.insert(
|
|
2899
|
+
await e.insert(V).values(i);
|
|
2896
2900
|
} catch (e) {
|
|
2897
|
-
throw e?.message?.includes("UNIQUE constraint failed") || e?.message?.includes("AlreadyExists") ? new
|
|
2901
|
+
throw e?.message?.includes("UNIQUE constraint failed") || e?.message?.includes("AlreadyExists") ? new Fe(409, { message: "Organization already exists" }) : e;
|
|
2898
2902
|
}
|
|
2899
|
-
return
|
|
2903
|
+
return Un({
|
|
2900
2904
|
...i,
|
|
2901
2905
|
tenant_id: t
|
|
2902
2906
|
});
|
|
2903
2907
|
},
|
|
2904
2908
|
async get(n, r) {
|
|
2905
|
-
let i = await e.select().from(
|
|
2906
|
-
return i ||= await e.select().from(
|
|
2909
|
+
let i = await e.select().from(V).where(t(a(V.tenant_id, n), a(V.id, r))).get();
|
|
2910
|
+
return i ||= await e.select().from(V).where(t(a(V.tenant_id, n), a(V.name, r))).get(), i ? Un(i) : null;
|
|
2907
2911
|
},
|
|
2908
2912
|
async update(n, r, i) {
|
|
2909
2913
|
let o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
2910
|
-
return i.name !== void 0 && (o.name = i.name), i.display_name !== void 0 && (o.display_name = i.display_name), i.branding !== void 0 && (o.branding = JSON.stringify(i.branding)), i.metadata !== void 0 && (o.metadata = JSON.stringify(i.metadata)), i.enabled_connections !== void 0 && (o.enabled_connections = JSON.stringify(i.enabled_connections)), i.token_quota !== void 0 && (o.token_quota = JSON.stringify(i.token_quota)), (await e.update(
|
|
2914
|
+
return i.name !== void 0 && (o.name = i.name), i.display_name !== void 0 && (o.display_name = i.display_name), i.branding !== void 0 && (o.branding = JSON.stringify(i.branding)), i.metadata !== void 0 && (o.metadata = JSON.stringify(i.metadata)), i.enabled_connections !== void 0 && (o.enabled_connections = JSON.stringify(i.enabled_connections)), i.token_quota !== void 0 && (o.token_quota = JSON.stringify(i.token_quota)), (await e.update(V).set(o).where(t(a(V.tenant_id, n), a(V.id, r))).returning()).length > 0;
|
|
2911
2915
|
},
|
|
2912
2916
|
async list(o, s) {
|
|
2913
|
-
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = [a(
|
|
2917
|
+
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = [a(V.tenant_id, o)];
|
|
2914
2918
|
if (f) {
|
|
2915
|
-
let e = we(f,
|
|
2919
|
+
let e = we(f, Vn);
|
|
2916
2920
|
if (e) {
|
|
2917
|
-
let t =
|
|
2921
|
+
let t = mt(V, e, Vn);
|
|
2918
2922
|
t && p.push(t);
|
|
2919
2923
|
}
|
|
2920
2924
|
}
|
|
2921
2925
|
let m = t(...p);
|
|
2922
|
-
if (
|
|
2926
|
+
if (Et(s)) {
|
|
2923
2927
|
let n = {
|
|
2924
|
-
sortColumn:
|
|
2925
|
-
idColumn:
|
|
2928
|
+
sortColumn: V.created_at,
|
|
2929
|
+
idColumn: V.id,
|
|
2926
2930
|
sortOrder: "desc"
|
|
2927
|
-
}, r =
|
|
2931
|
+
}, r = kt(s, n), i = Dt(s), { rows: a, next: o } = At(await e.select().from(V).where(r ? t(m, r) : m).orderBy(...Ot(n)).limit(i + 1), i, "created_at"), c = a.map(Un);
|
|
2928
2932
|
return {
|
|
2929
2933
|
organizations: c,
|
|
2930
2934
|
start: 0,
|
|
@@ -2934,14 +2938,14 @@ function Vn(e) {
|
|
|
2934
2938
|
next: o
|
|
2935
2939
|
};
|
|
2936
2940
|
}
|
|
2937
|
-
let h = e.select().from(
|
|
2941
|
+
let h = e.select().from(V).where(m).$dynamic();
|
|
2938
2942
|
if (d?.sort_by) {
|
|
2939
|
-
let e =
|
|
2943
|
+
let e = V[d.sort_by];
|
|
2940
2944
|
e && (h = h.orderBy(d.sort_order === "desc" ? i(e) : n(e)));
|
|
2941
2945
|
}
|
|
2942
|
-
let g = (await h.offset(c * l).limit(l)).map(
|
|
2946
|
+
let g = (await h.offset(c * l).limit(l)).map(Un);
|
|
2943
2947
|
if (!u) return { organizations: g };
|
|
2944
|
-
let [_] = await e.select({ count: r() }).from(
|
|
2948
|
+
let [_] = await e.select({ count: r() }).from(V).where(m);
|
|
2945
2949
|
return {
|
|
2946
2950
|
organizations: g,
|
|
2947
2951
|
start: c * l,
|
|
@@ -2950,24 +2954,24 @@ function Vn(e) {
|
|
|
2950
2954
|
};
|
|
2951
2955
|
},
|
|
2952
2956
|
async remove(n, r) {
|
|
2953
|
-
return (await e.delete(
|
|
2957
|
+
return (await e.delete(V).where(t(a(V.tenant_id, n), a(V.id, r))).returning()).length > 0;
|
|
2954
2958
|
}
|
|
2955
2959
|
};
|
|
2956
2960
|
}
|
|
2957
2961
|
//#endregion
|
|
2958
2962
|
//#region src/adapters/passwords.ts
|
|
2959
|
-
function
|
|
2963
|
+
function Gn(e) {
|
|
2960
2964
|
let { tenant_id: t, is_current: n, ...r } = e;
|
|
2961
2965
|
return {
|
|
2962
2966
|
...r,
|
|
2963
2967
|
is_current: !!n
|
|
2964
2968
|
};
|
|
2965
2969
|
}
|
|
2966
|
-
function
|
|
2970
|
+
function Kn(e) {
|
|
2967
2971
|
return {
|
|
2968
2972
|
async create(n, r) {
|
|
2969
2973
|
let i = (/* @__PURE__ */ new Date()).toISOString(), o = r.id || b();
|
|
2970
|
-
r.is_current !== !1 && await e.update(
|
|
2974
|
+
r.is_current !== !1 && await e.update(j).set({ is_current: 0 }).where(t(a(j.tenant_id, n), a(j.user_id, r.user_id)));
|
|
2971
2975
|
let s = {
|
|
2972
2976
|
id: o,
|
|
2973
2977
|
tenant_id: n,
|
|
@@ -2978,31 +2982,31 @@ function Un(e) {
|
|
|
2978
2982
|
created_at: i,
|
|
2979
2983
|
updated_at: i
|
|
2980
2984
|
};
|
|
2981
|
-
return await e.insert(
|
|
2985
|
+
return await e.insert(j).values(s), Gn({
|
|
2982
2986
|
...s,
|
|
2983
2987
|
tenant_id: n
|
|
2984
2988
|
});
|
|
2985
2989
|
},
|
|
2986
2990
|
async get(n, r) {
|
|
2987
|
-
let i = await e.select().from(
|
|
2988
|
-
return i ?
|
|
2991
|
+
let i = await e.select().from(j).where(t(a(j.tenant_id, n), a(j.user_id, r), a(j.is_current, 1))).get();
|
|
2992
|
+
return i ? Gn(i) : null;
|
|
2989
2993
|
},
|
|
2990
2994
|
async list(n, r, o) {
|
|
2991
|
-
let s = e.select().from(
|
|
2992
|
-
return o && (s = s.limit(o)), (await s).map(
|
|
2995
|
+
let s = e.select().from(j).where(t(a(j.tenant_id, n), a(j.user_id, r))).orderBy(i(j.created_at)).$dynamic();
|
|
2996
|
+
return o && (s = s.limit(o)), (await s).map(Gn);
|
|
2993
2997
|
},
|
|
2994
2998
|
async update(n, r) {
|
|
2995
2999
|
let i = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
2996
|
-
return r.password !== void 0 && (i.password = r.password), r.algorithm !== void 0 && (i.algorithm = r.algorithm), r.is_current !== void 0 && (i.is_current = +!!r.is_current), r.id ? await e.update(
|
|
3000
|
+
return r.password !== void 0 && (i.password = r.password), r.algorithm !== void 0 && (i.algorithm = r.algorithm), r.is_current !== void 0 && (i.is_current = +!!r.is_current), r.id ? await e.update(j).set(i).where(t(a(j.tenant_id, n), a(j.id, r.id))) : await e.update(j).set(i).where(t(a(j.tenant_id, n), a(j.user_id, r.user_id), a(j.is_current, 1))), !0;
|
|
2997
3001
|
}
|
|
2998
3002
|
};
|
|
2999
3003
|
}
|
|
3000
3004
|
//#endregion
|
|
3001
3005
|
//#region src/adapters/promptSettings.ts
|
|
3002
|
-
function
|
|
3006
|
+
function qn(e) {
|
|
3003
3007
|
return {
|
|
3004
3008
|
async get(t) {
|
|
3005
|
-
let n = await e.select().from(
|
|
3009
|
+
let n = await e.select().from(et).where(a(et.tenant_id, t)).get();
|
|
3006
3010
|
return n ? {
|
|
3007
3011
|
universal_login_experience: n.universal_login_experience,
|
|
3008
3012
|
identifier_first: !!n.identifier_first,
|
|
@@ -3018,7 +3022,7 @@ function Wn(e) {
|
|
|
3018
3022
|
};
|
|
3019
3023
|
},
|
|
3020
3024
|
async set(t, n) {
|
|
3021
|
-
await e.insert(
|
|
3025
|
+
await e.insert(et).values({
|
|
3022
3026
|
tenant_id: t,
|
|
3023
3027
|
universal_login_experience: n.universal_login_experience,
|
|
3024
3028
|
identifier_first: n.identifier_first,
|
|
@@ -3026,7 +3030,7 @@ function Wn(e) {
|
|
|
3026
3030
|
webauthn_platform_first_factor: n.webauthn_platform_first_factor,
|
|
3027
3031
|
show_last_used_connection: n.show_last_used_connection
|
|
3028
3032
|
}).onConflictDoUpdate({
|
|
3029
|
-
target:
|
|
3033
|
+
target: et.tenant_id,
|
|
3030
3034
|
set: {
|
|
3031
3035
|
universal_login_experience: n.universal_login_experience,
|
|
3032
3036
|
identifier_first: n.identifier_first,
|
|
@@ -3040,7 +3044,7 @@ function Wn(e) {
|
|
|
3040
3044
|
}
|
|
3041
3045
|
//#endregion
|
|
3042
3046
|
//#region src/adapters/proxyRoutes.ts
|
|
3043
|
-
function
|
|
3047
|
+
function Jn(e) {
|
|
3044
3048
|
if (!e) return { path: "/*" };
|
|
3045
3049
|
try {
|
|
3046
3050
|
let t = JSON.parse(e), n = be.safeParse(t);
|
|
@@ -3048,7 +3052,7 @@ function Gn(e) {
|
|
|
3048
3052
|
} catch {}
|
|
3049
3053
|
return { path: "/*" };
|
|
3050
3054
|
}
|
|
3051
|
-
function
|
|
3055
|
+
function Yn(e) {
|
|
3052
3056
|
if (!e) return [];
|
|
3053
3057
|
try {
|
|
3054
3058
|
let t = JSON.parse(e);
|
|
@@ -3063,19 +3067,19 @@ function Kn(e) {
|
|
|
3063
3067
|
return [];
|
|
3064
3068
|
}
|
|
3065
3069
|
}
|
|
3066
|
-
function
|
|
3070
|
+
function Xn(e) {
|
|
3067
3071
|
return {
|
|
3068
3072
|
id: e.id,
|
|
3069
3073
|
tenant_id: e.tenant_id,
|
|
3070
3074
|
custom_domain_id: e.custom_domain_id,
|
|
3071
3075
|
priority: e.priority,
|
|
3072
|
-
match:
|
|
3073
|
-
handlers:
|
|
3076
|
+
match: Jn(e.match),
|
|
3077
|
+
handlers: Yn(e.handlers),
|
|
3074
3078
|
created_at: e.created_at,
|
|
3075
3079
|
updated_at: e.updated_at
|
|
3076
3080
|
};
|
|
3077
3081
|
}
|
|
3078
|
-
function
|
|
3082
|
+
function Zn(e) {
|
|
3079
3083
|
return {
|
|
3080
3084
|
async create(t, n) {
|
|
3081
3085
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
@@ -3088,7 +3092,7 @@ function Jn(e) {
|
|
|
3088
3092
|
created_at: r,
|
|
3089
3093
|
updated_at: r
|
|
3090
3094
|
};
|
|
3091
|
-
return await e.insert(
|
|
3095
|
+
return await e.insert(Y).values({
|
|
3092
3096
|
id: i.id,
|
|
3093
3097
|
tenant_id: i.tenant_id,
|
|
3094
3098
|
custom_domain_id: i.custom_domain_id,
|
|
@@ -3100,15 +3104,15 @@ function Jn(e) {
|
|
|
3100
3104
|
}), i;
|
|
3101
3105
|
},
|
|
3102
3106
|
async get(n, r) {
|
|
3103
|
-
let i = await e.select().from(
|
|
3104
|
-
return i[0] ?
|
|
3107
|
+
let i = await e.select().from(Y).where(t(a(Y.tenant_id, n), a(Y.id, r))).limit(1);
|
|
3108
|
+
return i[0] ? Xn(i[0]) : null;
|
|
3105
3109
|
},
|
|
3106
3110
|
async list(r, i = {}) {
|
|
3107
|
-
let o = i.page ?? 0, s = i.per_page ?? 50, c = [a(
|
|
3108
|
-
i.custom_domain_id && c.push(a(
|
|
3109
|
-
let l = await e.select().from(
|
|
3111
|
+
let o = i.page ?? 0, s = i.per_page ?? 50, c = [a(Y.tenant_id, r)];
|
|
3112
|
+
i.custom_domain_id && c.push(a(Y.custom_domain_id, i.custom_domain_id));
|
|
3113
|
+
let l = await e.select().from(Y).where(t(...c)).orderBy(n(Y.priority), n(Y.created_at)).offset(o * s).limit(s);
|
|
3110
3114
|
return {
|
|
3111
|
-
proxy_routes: l.map(
|
|
3115
|
+
proxy_routes: l.map(Xn),
|
|
3112
3116
|
start: o * s,
|
|
3113
3117
|
limit: s,
|
|
3114
3118
|
length: l.length
|
|
@@ -3117,17 +3121,17 @@ function Jn(e) {
|
|
|
3117
3121
|
async update(n, r, i) {
|
|
3118
3122
|
let o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
3119
3123
|
i.priority !== void 0 && (o.priority = i.priority), i.match !== void 0 && (o.match = JSON.stringify(i.match)), i.handlers !== void 0 && (o.handlers = JSON.stringify(i.handlers));
|
|
3120
|
-
let s = (await e.update(
|
|
3121
|
-
return typeof s == "number" ? s > 0 : (await e.select({ id:
|
|
3124
|
+
let s = (await e.update(Y).set(o).where(t(a(Y.tenant_id, n), a(Y.id, r))))?.changes;
|
|
3125
|
+
return typeof s == "number" ? s > 0 : (await e.select({ id: Y.id }).from(Y).where(t(a(Y.tenant_id, n), a(Y.id, r))).limit(1)).length > 0;
|
|
3122
3126
|
},
|
|
3123
3127
|
async remove(n, r) {
|
|
3124
|
-
return (await e.select({ id:
|
|
3128
|
+
return (await e.select({ id: Y.id }).from(Y).where(t(a(Y.tenant_id, n), a(Y.id, r))).limit(1)).length === 0 ? !1 : (await e.delete(Y).where(t(a(Y.tenant_id, n), a(Y.id, r))), !0);
|
|
3125
3129
|
}
|
|
3126
3130
|
};
|
|
3127
3131
|
}
|
|
3128
3132
|
//#endregion
|
|
3129
3133
|
//#region src/adapters/scim.ts
|
|
3130
|
-
function
|
|
3134
|
+
function Qn(e) {
|
|
3131
3135
|
if (!e) return [];
|
|
3132
3136
|
try {
|
|
3133
3137
|
let t = JSON.parse(e);
|
|
@@ -3142,7 +3146,7 @@ function Yn(e) {
|
|
|
3142
3146
|
return [];
|
|
3143
3147
|
}
|
|
3144
3148
|
}
|
|
3145
|
-
function
|
|
3149
|
+
function $n(e) {
|
|
3146
3150
|
if (!e) return [];
|
|
3147
3151
|
try {
|
|
3148
3152
|
let t = JSON.parse(e);
|
|
@@ -3151,16 +3155,16 @@ function Xn(e) {
|
|
|
3151
3155
|
return [];
|
|
3152
3156
|
}
|
|
3153
3157
|
}
|
|
3154
|
-
function
|
|
3158
|
+
function er(e) {
|
|
3155
3159
|
return {
|
|
3156
3160
|
connection_id: e.connection_id,
|
|
3157
3161
|
user_id_attribute: e.user_id_attribute,
|
|
3158
|
-
mapping:
|
|
3162
|
+
mapping: Qn(e.mapping),
|
|
3159
3163
|
created_at: e.created_at,
|
|
3160
3164
|
updated_at: e.updated_at
|
|
3161
3165
|
};
|
|
3162
3166
|
}
|
|
3163
|
-
function
|
|
3167
|
+
function tr(e) {
|
|
3164
3168
|
return {
|
|
3165
3169
|
async create(t, n) {
|
|
3166
3170
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
@@ -3170,7 +3174,7 @@ function Qn(e) {
|
|
|
3170
3174
|
created_at: r,
|
|
3171
3175
|
updated_at: r
|
|
3172
3176
|
};
|
|
3173
|
-
return await e.insert(
|
|
3177
|
+
return await e.insert(st).values({
|
|
3174
3178
|
connection_id: i.connection_id,
|
|
3175
3179
|
tenant_id: t,
|
|
3176
3180
|
user_id_attribute: i.user_id_attribute,
|
|
@@ -3180,31 +3184,31 @@ function Qn(e) {
|
|
|
3180
3184
|
}), i;
|
|
3181
3185
|
},
|
|
3182
3186
|
async get(n, r) {
|
|
3183
|
-
let i = await e.select().from(
|
|
3184
|
-
return i[0] ?
|
|
3187
|
+
let i = await e.select().from(st).where(t(a(st.tenant_id, n), a(st.connection_id, r))).limit(1);
|
|
3188
|
+
return i[0] ? er(i[0]) : null;
|
|
3185
3189
|
},
|
|
3186
3190
|
async update(n, r, i) {
|
|
3187
|
-
if ((await e.select({ connection_id:
|
|
3191
|
+
if ((await e.select({ connection_id: st.connection_id }).from(st).where(t(a(st.tenant_id, n), a(st.connection_id, r))).limit(1)).length === 0) return !1;
|
|
3188
3192
|
let o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
3189
|
-
return i.user_id_attribute !== void 0 && (o.user_id_attribute = i.user_id_attribute), i.mapping !== void 0 && (o.mapping = JSON.stringify(i.mapping)), await e.update(
|
|
3193
|
+
return i.user_id_attribute !== void 0 && (o.user_id_attribute = i.user_id_attribute), i.mapping !== void 0 && (o.mapping = JSON.stringify(i.mapping)), await e.update(st).set(o).where(t(a(st.tenant_id, n), a(st.connection_id, r))), !0;
|
|
3190
3194
|
},
|
|
3191
3195
|
async remove(n, r) {
|
|
3192
|
-
return (await e.select({ connection_id:
|
|
3196
|
+
return (await e.select({ connection_id: st.connection_id }).from(st).where(t(a(st.tenant_id, n), a(st.connection_id, r))).limit(1)).length === 0 ? !1 : (await e.delete(st).where(t(a(st.tenant_id, n), a(st.connection_id, r))), !0);
|
|
3193
3197
|
}
|
|
3194
3198
|
};
|
|
3195
3199
|
}
|
|
3196
|
-
function
|
|
3200
|
+
function nr(e) {
|
|
3197
3201
|
return {
|
|
3198
3202
|
token_id: e.token_id,
|
|
3199
3203
|
connection_id: e.connection_id,
|
|
3200
3204
|
token_hash: e.token_hash,
|
|
3201
|
-
scopes:
|
|
3205
|
+
scopes: $n(e.scopes),
|
|
3202
3206
|
valid_until: e.valid_until ?? void 0,
|
|
3203
3207
|
created_at: e.created_at,
|
|
3204
3208
|
last_used_at: e.last_used_at ?? void 0
|
|
3205
3209
|
};
|
|
3206
3210
|
}
|
|
3207
|
-
function
|
|
3211
|
+
function rr(e) {
|
|
3208
3212
|
return {
|
|
3209
3213
|
async create(t, n) {
|
|
3210
3214
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
@@ -3215,7 +3219,7 @@ function er(e) {
|
|
|
3215
3219
|
valid_until: n.valid_until,
|
|
3216
3220
|
created_at: r
|
|
3217
3221
|
};
|
|
3218
|
-
return await e.insert(
|
|
3222
|
+
return await e.insert(X).values({
|
|
3219
3223
|
token_id: i.token_id,
|
|
3220
3224
|
tenant_id: t,
|
|
3221
3225
|
connection_id: i.connection_id,
|
|
@@ -3226,25 +3230,25 @@ function er(e) {
|
|
|
3226
3230
|
}), i;
|
|
3227
3231
|
},
|
|
3228
3232
|
async get(n, r) {
|
|
3229
|
-
let i = await e.select().from(
|
|
3230
|
-
return i[0] ?
|
|
3233
|
+
let i = await e.select().from(X).where(t(a(X.tenant_id, n), a(X.token_id, r))).limit(1);
|
|
3234
|
+
return i[0] ? nr(i[0]) : null;
|
|
3231
3235
|
},
|
|
3232
3236
|
async getByHash(n, r) {
|
|
3233
|
-
let i = await e.select().from(
|
|
3234
|
-
return i[0] ?
|
|
3237
|
+
let i = await e.select().from(X).where(t(a(X.tenant_id, n), a(X.token_hash, r))).limit(1);
|
|
3238
|
+
return i[0] ? nr(i[0]) : null;
|
|
3235
3239
|
},
|
|
3236
3240
|
async listByConnection(n, r) {
|
|
3237
|
-
return (await e.select().from(
|
|
3241
|
+
return (await e.select().from(X).where(t(a(X.tenant_id, n), a(X.connection_id, r)))).map(nr);
|
|
3238
3242
|
},
|
|
3239
3243
|
async markUsed(n, r, i) {
|
|
3240
|
-
return (await e.select({ token_id:
|
|
3244
|
+
return (await e.select({ token_id: X.token_id }).from(X).where(t(a(X.tenant_id, n), a(X.token_id, r))).limit(1)).length === 0 ? !1 : (await e.update(X).set({ last_used_at: i }).where(t(a(X.tenant_id, n), a(X.token_id, r))), !0);
|
|
3241
3245
|
},
|
|
3242
3246
|
async remove(n, r) {
|
|
3243
|
-
return (await e.select({ token_id:
|
|
3247
|
+
return (await e.select({ token_id: X.token_id }).from(X).where(t(a(X.tenant_id, n), a(X.token_id, r))).limit(1)).length === 0 ? !1 : (await e.delete(X).where(t(a(X.tenant_id, n), a(X.token_id, r))), !0);
|
|
3244
3248
|
}
|
|
3245
3249
|
};
|
|
3246
3250
|
}
|
|
3247
|
-
function
|
|
3251
|
+
function ir(e) {
|
|
3248
3252
|
return {
|
|
3249
3253
|
connection_id: e.connection_id,
|
|
3250
3254
|
external_id: e.external_id,
|
|
@@ -3252,7 +3256,7 @@ function tr(e) {
|
|
|
3252
3256
|
created_at: e.created_at
|
|
3253
3257
|
};
|
|
3254
3258
|
}
|
|
3255
|
-
function
|
|
3259
|
+
function ar(e) {
|
|
3256
3260
|
return {
|
|
3257
3261
|
async create(t, n) {
|
|
3258
3262
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
@@ -3261,7 +3265,7 @@ function nr(e) {
|
|
|
3261
3265
|
user_id: n.user_id,
|
|
3262
3266
|
created_at: r
|
|
3263
3267
|
};
|
|
3264
|
-
return await e.insert(
|
|
3268
|
+
return await e.insert(ct).values({
|
|
3265
3269
|
tenant_id: t,
|
|
3266
3270
|
connection_id: i.connection_id,
|
|
3267
3271
|
external_id: i.external_id,
|
|
@@ -3270,21 +3274,21 @@ function nr(e) {
|
|
|
3270
3274
|
}), i;
|
|
3271
3275
|
},
|
|
3272
3276
|
async getByExternalId(n, r, i) {
|
|
3273
|
-
let o = await e.select().from(
|
|
3274
|
-
return o[0] ?
|
|
3277
|
+
let o = await e.select().from(ct).where(t(a(ct.tenant_id, n), a(ct.connection_id, r), a(ct.external_id, i))).limit(1);
|
|
3278
|
+
return o[0] ? ir(o[0]) : null;
|
|
3275
3279
|
},
|
|
3276
3280
|
async getByUserId(n, r, i) {
|
|
3277
|
-
let o = await e.select().from(
|
|
3278
|
-
return o[0] ?
|
|
3281
|
+
let o = await e.select().from(ct).where(t(a(ct.tenant_id, n), a(ct.connection_id, r), a(ct.user_id, i))).limit(1);
|
|
3282
|
+
return o[0] ? ir(o[0]) : null;
|
|
3279
3283
|
},
|
|
3280
3284
|
async remove(n, r, i) {
|
|
3281
|
-
return (await e.select({ user_id:
|
|
3285
|
+
return (await e.select({ user_id: ct.user_id }).from(ct).where(t(a(ct.tenant_id, n), a(ct.connection_id, r), a(ct.user_id, i))).limit(1)).length === 0 ? !1 : (await e.delete(ct).where(t(a(ct.tenant_id, n), a(ct.connection_id, r), a(ct.user_id, i))), !0);
|
|
3282
3286
|
}
|
|
3283
3287
|
};
|
|
3284
3288
|
}
|
|
3285
3289
|
//#endregion
|
|
3286
3290
|
//#region src/adapters/refreshTokens.ts
|
|
3287
|
-
function
|
|
3291
|
+
function or(e) {
|
|
3288
3292
|
let { tenant_id: t, created_at_ts: n, expires_at_ts: r, idle_expires_at_ts: i, last_exchanged_at_ts: a, revoked_at_ts: o, rotated_at_ts: s, device: c, resource_servers: l, rotating: u, auth_strategy_strategy: d, auth_strategy_strategy_type: f, ...p } = e, m = ae({
|
|
3289
3293
|
created_at_ts: n,
|
|
3290
3294
|
expires_at_ts: r,
|
|
@@ -3303,18 +3307,18 @@ function rr(e) {
|
|
|
3303
3307
|
...p,
|
|
3304
3308
|
...m,
|
|
3305
3309
|
rotating: !!u,
|
|
3306
|
-
device:
|
|
3307
|
-
resource_servers:
|
|
3310
|
+
device: Z(c, {}),
|
|
3311
|
+
resource_servers: Z(l, []),
|
|
3308
3312
|
...d && f ? { auth_strategy: {
|
|
3309
3313
|
strategy: d,
|
|
3310
3314
|
strategy_type: f
|
|
3311
3315
|
} } : {}
|
|
3312
3316
|
});
|
|
3313
3317
|
}
|
|
3314
|
-
function
|
|
3318
|
+
function sr(e, t) {
|
|
3315
3319
|
return Math.max(e ?? 0, t ?? 0);
|
|
3316
3320
|
}
|
|
3317
|
-
function
|
|
3321
|
+
function cr(e) {
|
|
3318
3322
|
return {
|
|
3319
3323
|
async create(n, r) {
|
|
3320
3324
|
let i = Date.now(), o = {
|
|
@@ -3340,44 +3344,44 @@ function ar(e) {
|
|
|
3340
3344
|
expires_at_ts: E(r.expires_at),
|
|
3341
3345
|
idle_expires_at_ts: E(r.idle_expires_at),
|
|
3342
3346
|
last_exchanged_at_ts: E(r.last_exchanged_at)
|
|
3343
|
-
}, s = [e.insert(
|
|
3344
|
-
return c > 0 && o.login_id && s.push(e.update(
|
|
3347
|
+
}, s = [e.insert(N).values(o)], c = sr(o.expires_at_ts, o.idle_expires_at_ts);
|
|
3348
|
+
return c > 0 && o.login_id && s.push(e.update(P).set({
|
|
3345
3349
|
expires_at_ts: c,
|
|
3346
3350
|
updated_at_ts: i
|
|
3347
|
-
}).where(t(a(
|
|
3351
|
+
}).where(t(a(P.tenant_id, n), a(P.id, o.login_id), m(P.expires_at_ts, c)))), await xt(e, s), or({
|
|
3348
3352
|
...o,
|
|
3349
3353
|
tenant_id: n
|
|
3350
3354
|
});
|
|
3351
3355
|
},
|
|
3352
3356
|
async get(n, r) {
|
|
3353
|
-
let i = await e.select().from(
|
|
3354
|
-
return i ?
|
|
3357
|
+
let i = await e.select().from(N).where(t(a(N.tenant_id, n), a(N.id, r))).get();
|
|
3358
|
+
return i ? or(i) : null;
|
|
3355
3359
|
},
|
|
3356
3360
|
async getByLookup(n, r) {
|
|
3357
|
-
let i = await e.select().from(
|
|
3358
|
-
return i ?
|
|
3361
|
+
let i = await e.select().from(N).where(t(a(N.tenant_id, n), a(N.token_lookup, r))).get();
|
|
3362
|
+
return i ? or(i) : null;
|
|
3359
3363
|
},
|
|
3360
3364
|
async update(n, r, i, o) {
|
|
3361
3365
|
let s = {};
|
|
3362
3366
|
i.device !== void 0 && (s.device = JSON.stringify(i.device)), i.resource_servers !== void 0 && (s.resource_servers = JSON.stringify(i.resource_servers)), i.rotating !== void 0 && (s.rotating = i.rotating), i.token_lookup !== void 0 && (s.token_lookup = i.token_lookup), i.token_hash !== void 0 && (s.token_hash = i.token_hash), i.family_id !== void 0 && (s.family_id = i.family_id), i.rotated_to !== void 0 && (s.rotated_to = i.rotated_to), i.rotated_at !== void 0 && (s.rotated_at_ts = E(i.rotated_at)), i.expires_at !== void 0 && (s.expires_at_ts = E(i.expires_at)), i.idle_expires_at !== void 0 && (s.idle_expires_at_ts = E(i.idle_expires_at)), i.last_exchanged_at !== void 0 && (s.last_exchanged_at_ts = E(i.last_exchanged_at)), i.revoked_at !== void 0 && (s.revoked_at_ts = E(i.revoked_at));
|
|
3363
|
-
let c = o?.loginSessionBump, l = c ? E(c.expires_at) : null, u = await e.update(
|
|
3364
|
-
return c?.login_id && l && l > 0 && await e.update(
|
|
3367
|
+
let c = o?.loginSessionBump, l = c ? E(c.expires_at) : null, u = await e.update(N).set(s).where(t(a(N.tenant_id, n), a(N.id, r))).returning();
|
|
3368
|
+
return c?.login_id && l && l > 0 && await e.update(P).set({
|
|
3365
3369
|
expires_at_ts: l,
|
|
3366
3370
|
updated_at_ts: Date.now()
|
|
3367
|
-
}).where(t(a(
|
|
3371
|
+
}).where(t(a(P.tenant_id, n), a(P.id, c.login_id), m(P.expires_at_ts, l))).catch(() => {}), u.length > 0;
|
|
3368
3372
|
},
|
|
3369
3373
|
async list(o, s) {
|
|
3370
|
-
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ?
|
|
3371
|
-
a(
|
|
3372
|
-
...s?.user_id === void 0 ? [] : [a(
|
|
3374
|
+
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ? mt(N, f, ["user_id", "login_id"]) : void 0, m = [
|
|
3375
|
+
a(N.tenant_id, o),
|
|
3376
|
+
...s?.user_id === void 0 ? [] : [a(N.user_id, s.user_id)],
|
|
3373
3377
|
...p ? [p] : []
|
|
3374
3378
|
], h = m.length === 1 ? m[0] : t(...m);
|
|
3375
|
-
if (
|
|
3379
|
+
if (Et(s)) {
|
|
3376
3380
|
let n = {
|
|
3377
|
-
sortColumn:
|
|
3378
|
-
idColumn:
|
|
3381
|
+
sortColumn: N.created_at_ts,
|
|
3382
|
+
idColumn: N.id,
|
|
3379
3383
|
sortOrder: "desc"
|
|
3380
|
-
}, r =
|
|
3384
|
+
}, r = kt(s, n), i = Dt(s), { rows: a, next: o } = At(await e.select().from(N).where(r ? t(h, r) : h).orderBy(...Ot(n)).limit(i + 1), i, "created_at_ts"), c = a.map(or);
|
|
3381
3385
|
return {
|
|
3382
3386
|
refresh_tokens: c,
|
|
3383
3387
|
start: 0,
|
|
@@ -3386,14 +3390,14 @@ function ar(e) {
|
|
|
3386
3390
|
next: o
|
|
3387
3391
|
};
|
|
3388
3392
|
}
|
|
3389
|
-
let g = e.select().from(
|
|
3393
|
+
let g = e.select().from(N).where(h).$dynamic();
|
|
3390
3394
|
if (d?.sort_by) {
|
|
3391
|
-
let e =
|
|
3395
|
+
let e = N[d.sort_by];
|
|
3392
3396
|
e && (g = g.orderBy(d.sort_order === "desc" ? i(e) : n(e)));
|
|
3393
3397
|
}
|
|
3394
|
-
let _ = (await g.offset(c * l).limit(l)).map(
|
|
3398
|
+
let _ = (await g.offset(c * l).limit(l)).map(or);
|
|
3395
3399
|
if (!u) return { refresh_tokens: _ };
|
|
3396
|
-
let [v] = await e.select({ count: r() }).from(
|
|
3400
|
+
let [v] = await e.select({ count: r() }).from(N).where(h);
|
|
3397
3401
|
return {
|
|
3398
3402
|
refresh_tokens: _,
|
|
3399
3403
|
start: c * l,
|
|
@@ -3402,33 +3406,33 @@ function ar(e) {
|
|
|
3402
3406
|
};
|
|
3403
3407
|
},
|
|
3404
3408
|
async remove(n, r) {
|
|
3405
|
-
return (await e.delete(
|
|
3409
|
+
return (await e.delete(N).where(t(a(N.tenant_id, n), a(N.id, r))).returning()).length > 0;
|
|
3406
3410
|
},
|
|
3407
3411
|
async revokeByUser(n, r, i) {
|
|
3408
|
-
return (await e.update(
|
|
3412
|
+
return (await e.update(N).set({ revoked_at_ts: E(i) }).where(t(a(N.tenant_id, n), a(N.user_id, r), f(N.revoked_at_ts))).returning()).length;
|
|
3409
3413
|
},
|
|
3410
3414
|
async revokeByLoginSession(n, r, i) {
|
|
3411
|
-
return (await e.update(
|
|
3415
|
+
return (await e.update(N).set({ revoked_at_ts: E(i) }).where(t(a(N.tenant_id, n), a(N.login_id, r), f(N.revoked_at_ts))).returning()).length;
|
|
3412
3416
|
},
|
|
3413
3417
|
async revokeBySession(n, r, i) {
|
|
3414
|
-
return (await e.update(
|
|
3418
|
+
return (await e.update(N).set({ revoked_at_ts: E(i) }).where(t(a(N.tenant_id, n), a(N.session_id, r), f(N.revoked_at_ts))).returning()).length;
|
|
3415
3419
|
},
|
|
3416
3420
|
async revokeFamily(n, r, i) {
|
|
3417
|
-
return (await e.update(
|
|
3421
|
+
return (await e.update(N).set({ revoked_at_ts: E(i) }).where(t(a(N.tenant_id, n), a(N.family_id, r), f(N.revoked_at_ts))).returning()).length;
|
|
3418
3422
|
}
|
|
3419
3423
|
};
|
|
3420
3424
|
}
|
|
3421
3425
|
//#endregion
|
|
3422
3426
|
//#region src/adapters/resourceServers.ts
|
|
3423
|
-
var
|
|
3424
|
-
function
|
|
3427
|
+
var lr = ["name", "identifier"];
|
|
3428
|
+
function ur() {
|
|
3425
3429
|
return `api_${ee("0123456789abcdefghijklmnopqrstuvwxyz", 17)()}`;
|
|
3426
3430
|
}
|
|
3427
|
-
var
|
|
3431
|
+
var dr = [
|
|
3428
3432
|
"skip_consent_for_verifiable_first_party_clients",
|
|
3429
3433
|
"allow_offline_access",
|
|
3430
3434
|
"is_system"
|
|
3431
|
-
],
|
|
3435
|
+
], fr = new Set([
|
|
3432
3436
|
"id",
|
|
3433
3437
|
"tenant_id",
|
|
3434
3438
|
"identifier",
|
|
@@ -3447,17 +3451,17 @@ var cr = [
|
|
|
3447
3451
|
"created_at",
|
|
3448
3452
|
"updated_at"
|
|
3449
3453
|
]);
|
|
3450
|
-
function
|
|
3454
|
+
function pr(e) {
|
|
3451
3455
|
let { tenant_id: t, verification_key: n, scopes: r, options: i, metadata: a, ...o } = e, s = { ...o };
|
|
3452
|
-
s.scopes =
|
|
3453
|
-
for (let e of
|
|
3456
|
+
s.scopes = Z(r, []), s.options = Z(i, {}), s.metadata = Z(a), n !== void 0 && (s.verificationKey = n);
|
|
3457
|
+
for (let e of dr) o[e] !== void 0 && o[e] !== null && (s[e] = !!o[e]);
|
|
3454
3458
|
return D(s);
|
|
3455
3459
|
}
|
|
3456
|
-
function
|
|
3460
|
+
function mr(e) {
|
|
3457
3461
|
return {
|
|
3458
3462
|
async create(t, n) {
|
|
3459
3463
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
3460
|
-
id: n.id ||
|
|
3464
|
+
id: n.id || ur(),
|
|
3461
3465
|
tenant_id: t,
|
|
3462
3466
|
identifier: n.identifier,
|
|
3463
3467
|
name: n.name,
|
|
@@ -3472,39 +3476,39 @@ function dr(e) {
|
|
|
3472
3476
|
created_at: r,
|
|
3473
3477
|
updated_at: r
|
|
3474
3478
|
};
|
|
3475
|
-
for (let e of
|
|
3476
|
-
return i.is_system === void 0 && (i.is_system = 0), await e.insert(
|
|
3479
|
+
for (let e of dr) n[e] !== void 0 && (i[e] = +!!n[e]);
|
|
3480
|
+
return i.is_system === void 0 && (i.is_system = 0), await e.insert(G).values(i), pr({
|
|
3477
3481
|
...i,
|
|
3478
3482
|
tenant_id: t
|
|
3479
3483
|
});
|
|
3480
3484
|
},
|
|
3481
3485
|
async get(n, r) {
|
|
3482
|
-
let i = await e.select().from(
|
|
3483
|
-
return i ?
|
|
3486
|
+
let i = await e.select().from(G).where(t(a(G.tenant_id, n), a(G.id, r))).get();
|
|
3487
|
+
return i ? pr(i) : null;
|
|
3484
3488
|
},
|
|
3485
3489
|
async update(n, r, i) {
|
|
3486
3490
|
let o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
3487
|
-
i.name !== void 0 && (o.name = i.name), i.identifier !== void 0 && (o.identifier = i.identifier), i.signing_alg !== void 0 && (o.signing_alg = i.signing_alg), i.signing_secret !== void 0 && (o.signing_secret = i.signing_secret), i.token_lifetime !== void 0 && (o.token_lifetime = i.token_lifetime), i.token_lifetime_for_web !== void 0 && (o.token_lifetime_for_web = i.token_lifetime_for_web), i.scopes !== void 0 && (o.scopes = JSON.stringify(i.scopes)), i.options !== void 0 && (o.options = y`json_patch(COALESCE(${
|
|
3488
|
-
for (let e of
|
|
3489
|
-
return (await e.update(
|
|
3491
|
+
i.name !== void 0 && (o.name = i.name), i.identifier !== void 0 && (o.identifier = i.identifier), i.signing_alg !== void 0 && (o.signing_alg = i.signing_alg), i.signing_secret !== void 0 && (o.signing_secret = i.signing_secret), i.token_lifetime !== void 0 && (o.token_lifetime = i.token_lifetime), i.token_lifetime_for_web !== void 0 && (o.token_lifetime_for_web = i.token_lifetime_for_web), i.scopes !== void 0 && (o.scopes = JSON.stringify(i.scopes)), i.options !== void 0 && (o.options = y`json_patch(COALESCE(${G.options}, '{}'), ${JSON.stringify(i.options)})`), i.metadata !== void 0 && (o.metadata = JSON.stringify(i.metadata)), i.verificationKey !== void 0 && (o.verification_key = i.verificationKey);
|
|
3492
|
+
for (let e of dr) i[e] !== void 0 && (o[e] = +!!i[e]);
|
|
3493
|
+
return (await e.update(G).set(o).where(t(a(G.tenant_id, n), a(G.id, r))).returning()).length > 0;
|
|
3490
3494
|
},
|
|
3491
3495
|
async list(o, s) {
|
|
3492
|
-
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = Math.max(0, Math.floor(Number(c) || 0)), m = Math.min(Math.max(1, Math.floor(Number(l) || 50)), 500), h = [a(
|
|
3496
|
+
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = Math.max(0, Math.floor(Number(c) || 0)), m = Math.min(Math.max(1, Math.floor(Number(l) || 50)), 500), h = [a(G.tenant_id, o)];
|
|
3493
3497
|
if (f) {
|
|
3494
|
-
let e = we(f,
|
|
3498
|
+
let e = we(f, lr);
|
|
3495
3499
|
if (e) {
|
|
3496
|
-
let t =
|
|
3500
|
+
let t = mt(G, e, lr, ["name", "identifier"]);
|
|
3497
3501
|
t && h.push(t);
|
|
3498
3502
|
}
|
|
3499
3503
|
}
|
|
3500
|
-
let g = e.select().from(
|
|
3501
|
-
if (d?.sort_by &&
|
|
3502
|
-
let e =
|
|
3504
|
+
let g = e.select().from(G).where(t(...h)).$dynamic();
|
|
3505
|
+
if (d?.sort_by && fr.has(d.sort_by)) {
|
|
3506
|
+
let e = G[d.sort_by];
|
|
3503
3507
|
g = g.orderBy(d.sort_order === "desc" ? i(e) : n(e));
|
|
3504
3508
|
}
|
|
3505
|
-
let _ = (await g.offset(p * m).limit(m)).map(
|
|
3509
|
+
let _ = (await g.offset(p * m).limit(m)).map(pr);
|
|
3506
3510
|
if (!u) return { resource_servers: _ };
|
|
3507
|
-
let [v] = await e.select({ count: r() }).from(
|
|
3511
|
+
let [v] = await e.select({ count: r() }).from(G).where(t(...h));
|
|
3508
3512
|
return {
|
|
3509
3513
|
resource_servers: _,
|
|
3510
3514
|
start: p * m,
|
|
@@ -3513,18 +3517,18 @@ function dr(e) {
|
|
|
3513
3517
|
};
|
|
3514
3518
|
},
|
|
3515
3519
|
async remove(n, r) {
|
|
3516
|
-
return (await e.delete(
|
|
3520
|
+
return (await e.delete(G).where(t(a(G.tenant_id, n), a(G.id, r))).returning()).length > 0;
|
|
3517
3521
|
}
|
|
3518
3522
|
};
|
|
3519
3523
|
}
|
|
3520
3524
|
//#endregion
|
|
3521
3525
|
//#region src/adapters/rolePermissions.ts
|
|
3522
|
-
function
|
|
3526
|
+
function hr(e) {
|
|
3523
3527
|
return {
|
|
3524
3528
|
async assign(t, n, r) {
|
|
3525
3529
|
if (r.length === 0) return !0;
|
|
3526
3530
|
let i = (/* @__PURE__ */ new Date()).toISOString();
|
|
3527
|
-
return await e.insert(
|
|
3531
|
+
return await e.insert(qe).values(r.map((e) => ({
|
|
3528
3532
|
tenant_id: t,
|
|
3529
3533
|
role_id: n,
|
|
3530
3534
|
resource_server_identifier: e.resource_server_identifier,
|
|
@@ -3534,15 +3538,15 @@ function fr(e) {
|
|
|
3534
3538
|
},
|
|
3535
3539
|
async list(n, r, i) {
|
|
3536
3540
|
let o = await e.select({
|
|
3537
|
-
resource_server_identifier:
|
|
3538
|
-
permission_name:
|
|
3539
|
-
created_at:
|
|
3540
|
-
}).from(
|
|
3541
|
+
resource_server_identifier: qe.resource_server_identifier,
|
|
3542
|
+
permission_name: qe.permission_name,
|
|
3543
|
+
created_at: qe.created_at
|
|
3544
|
+
}).from(qe).where(t(a(qe.tenant_id, n), a(qe.role_id, r))).all(), s = [...new Set(o.map((e) => e.resource_server_identifier))], c = /* @__PURE__ */ new Map();
|
|
3541
3545
|
if (s.length > 0) {
|
|
3542
3546
|
let r = await e.select({
|
|
3543
|
-
identifier:
|
|
3544
|
-
name:
|
|
3545
|
-
}).from(
|
|
3547
|
+
identifier: G.identifier,
|
|
3548
|
+
name: G.name
|
|
3549
|
+
}).from(G).where(t(a(G.tenant_id, n), l(G.identifier, s))).all();
|
|
3546
3550
|
for (let e of r) c.set(e.identifier, e.name);
|
|
3547
3551
|
}
|
|
3548
3552
|
return o.map((e) => ({
|
|
@@ -3552,18 +3556,18 @@ function fr(e) {
|
|
|
3552
3556
|
},
|
|
3553
3557
|
async remove(n, r, i) {
|
|
3554
3558
|
if (i.length === 0) return !0;
|
|
3555
|
-
let o = i.map((e) => t(a(
|
|
3556
|
-
return await e.delete(
|
|
3559
|
+
let o = i.map((e) => t(a(qe.resource_server_identifier, e.resource_server_identifier), a(qe.permission_name, e.permission_name)));
|
|
3560
|
+
return await e.delete(qe).where(t(a(qe.tenant_id, n), a(qe.role_id, r), v(...o))).returning(), !0;
|
|
3557
3561
|
}
|
|
3558
3562
|
};
|
|
3559
3563
|
}
|
|
3560
3564
|
//#endregion
|
|
3561
3565
|
//#region src/adapters/userPermissions.ts
|
|
3562
|
-
function
|
|
3566
|
+
function gr(e) {
|
|
3563
3567
|
return {
|
|
3564
3568
|
async create(t, n, r, i) {
|
|
3565
3569
|
try {
|
|
3566
|
-
await e.insert(
|
|
3570
|
+
await e.insert(Je).values({
|
|
3567
3571
|
tenant_id: t,
|
|
3568
3572
|
user_id: n,
|
|
3569
3573
|
resource_server_identifier: r.resource_server_identifier,
|
|
@@ -3578,11 +3582,11 @@ function pr(e) {
|
|
|
3578
3582
|
return !0;
|
|
3579
3583
|
},
|
|
3580
3584
|
async list(n, r, i, o) {
|
|
3581
|
-
let s = [a(
|
|
3582
|
-
o && s.push(a(
|
|
3583
|
-
let c = await e.select().from(
|
|
3585
|
+
let s = [a(Je.tenant_id, n), a(Je.user_id, r)];
|
|
3586
|
+
o && s.push(a(Je.organization_id, o));
|
|
3587
|
+
let c = await e.select().from(Je).where(t(...s)).all();
|
|
3584
3588
|
return await Promise.all(c.map(async (r) => {
|
|
3585
|
-
let i = await e.select({ name:
|
|
3589
|
+
let i = await e.select({ name: G.name }).from(G).where(t(a(G.tenant_id, n), a(G.identifier, r.resource_server_identifier))).get();
|
|
3586
3590
|
return {
|
|
3587
3591
|
resource_server_identifier: r.resource_server_identifier,
|
|
3588
3592
|
permission_name: r.permission_name,
|
|
@@ -3592,21 +3596,21 @@ function pr(e) {
|
|
|
3592
3596
|
}));
|
|
3593
3597
|
},
|
|
3594
3598
|
async remove(n, r, i, o) {
|
|
3595
|
-
return (await e.delete(
|
|
3599
|
+
return (await e.delete(Je).where(t(a(Je.tenant_id, n), a(Je.user_id, r), a(Je.resource_server_identifier, i.resource_server_identifier), a(Je.permission_name, i.permission_name), a(Je.organization_id, o || ""))).returning()).length > 0;
|
|
3596
3600
|
}
|
|
3597
3601
|
};
|
|
3598
3602
|
}
|
|
3599
3603
|
//#endregion
|
|
3600
3604
|
//#region src/adapters/roles.ts
|
|
3601
|
-
function
|
|
3605
|
+
function _r(e) {
|
|
3602
3606
|
let { tenant_id: t, is_system: n, metadata: r, ...i } = e;
|
|
3603
3607
|
return D({
|
|
3604
3608
|
...i,
|
|
3605
3609
|
is_system: n ? !0 : void 0,
|
|
3606
|
-
metadata:
|
|
3610
|
+
metadata: Z(r)
|
|
3607
3611
|
});
|
|
3608
3612
|
}
|
|
3609
|
-
function
|
|
3613
|
+
function vr(e) {
|
|
3610
3614
|
return {
|
|
3611
3615
|
async create(t, n) {
|
|
3612
3616
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
@@ -3619,28 +3623,28 @@ function hr(e) {
|
|
|
3619
3623
|
created_at: r,
|
|
3620
3624
|
updated_at: r
|
|
3621
3625
|
};
|
|
3622
|
-
return await e.insert(
|
|
3626
|
+
return await e.insert(U).values(i), _r({
|
|
3623
3627
|
...i,
|
|
3624
3628
|
tenant_id: t
|
|
3625
3629
|
});
|
|
3626
3630
|
},
|
|
3627
3631
|
async get(n, r) {
|
|
3628
|
-
let i = await e.select().from(
|
|
3629
|
-
return i ?
|
|
3632
|
+
let i = await e.select().from(U).where(t(a(U.tenant_id, n), a(U.id, r))).get();
|
|
3633
|
+
return i ? _r(i) : null;
|
|
3630
3634
|
},
|
|
3631
3635
|
async update(n, r, i) {
|
|
3632
3636
|
let o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
3633
|
-
return i.name !== void 0 && (o.name = i.name), i.description !== void 0 && (o.description = i.description), i.is_system !== void 0 && (o.is_system = +!!i.is_system), i.metadata !== void 0 && (o.metadata = JSON.stringify(i.metadata)), (await e.update(
|
|
3637
|
+
return i.name !== void 0 && (o.name = i.name), i.description !== void 0 && (o.description = i.description), i.is_system !== void 0 && (o.is_system = +!!i.is_system), i.metadata !== void 0 && (o.metadata = JSON.stringify(i.metadata)), (await e.update(U).set(o).where(t(a(U.tenant_id, n), a(U.id, r))).returning()).length > 0;
|
|
3634
3638
|
},
|
|
3635
3639
|
async list(o, s) {
|
|
3636
|
-
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ?
|
|
3640
|
+
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ? mt(U, f, ["name"]) : void 0, m = p ? t(a(U.tenant_id, o), p) : a(U.tenant_id, o), h = e.select().from(U).where(m).$dynamic();
|
|
3637
3641
|
if (d?.sort_by) {
|
|
3638
|
-
let e =
|
|
3642
|
+
let e = U[d.sort_by];
|
|
3639
3643
|
e && (h = h.orderBy(d.sort_order === "desc" ? i(e) : n(e)));
|
|
3640
3644
|
}
|
|
3641
|
-
let g = (await h.offset(c * l).limit(l)).map(
|
|
3645
|
+
let g = (await h.offset(c * l).limit(l)).map(_r);
|
|
3642
3646
|
if (!u) return { roles: g };
|
|
3643
|
-
let [_] = await e.select({ count: r() }).from(
|
|
3647
|
+
let [_] = await e.select({ count: r() }).from(U).where(m);
|
|
3644
3648
|
return {
|
|
3645
3649
|
roles: g,
|
|
3646
3650
|
start: c * l,
|
|
@@ -3649,13 +3653,13 @@ function hr(e) {
|
|
|
3649
3653
|
};
|
|
3650
3654
|
},
|
|
3651
3655
|
async remove(n, r) {
|
|
3652
|
-
return (await e.delete(
|
|
3656
|
+
return (await e.delete(U).where(t(a(U.tenant_id, n), a(U.id, r))).returning()).length > 0;
|
|
3653
3657
|
}
|
|
3654
3658
|
};
|
|
3655
3659
|
}
|
|
3656
3660
|
//#endregion
|
|
3657
3661
|
//#region src/adapters/sessions.ts
|
|
3658
|
-
var
|
|
3662
|
+
var yr = ["created_at_ts", "updated_at_ts"], br = [
|
|
3659
3663
|
"expires_at_ts",
|
|
3660
3664
|
"idle_expires_at_ts",
|
|
3661
3665
|
"authenticated_at_ts",
|
|
@@ -3663,7 +3667,7 @@ var gr = ["created_at_ts", "updated_at_ts"], _r = [
|
|
|
3663
3667
|
"used_at_ts",
|
|
3664
3668
|
"revoked_at_ts"
|
|
3665
3669
|
];
|
|
3666
|
-
function
|
|
3670
|
+
function xr(e) {
|
|
3667
3671
|
let { tenant_id: t, created_at_ts: n, updated_at_ts: r, expires_at_ts: i, idle_expires_at_ts: a, authenticated_at_ts: o, last_interaction_at_ts: s, used_at_ts: c, revoked_at_ts: l, device: u, clients: d, ...f } = e, p = ae({
|
|
3668
3672
|
created_at_ts: n,
|
|
3669
3673
|
updated_at_ts: r,
|
|
@@ -3673,18 +3677,18 @@ function vr(e) {
|
|
|
3673
3677
|
last_interaction_at_ts: s,
|
|
3674
3678
|
used_at_ts: c,
|
|
3675
3679
|
revoked_at_ts: l
|
|
3676
|
-
}, [...
|
|
3680
|
+
}, [...yr], [...br]);
|
|
3677
3681
|
return D({
|
|
3678
3682
|
...f,
|
|
3679
3683
|
...p,
|
|
3680
|
-
device:
|
|
3681
|
-
clients:
|
|
3684
|
+
device: Z(u, {}),
|
|
3685
|
+
clients: Z(d, [])
|
|
3682
3686
|
});
|
|
3683
3687
|
}
|
|
3684
|
-
function
|
|
3688
|
+
function Sr(e, t) {
|
|
3685
3689
|
return Math.max(e ?? 0, t ?? 0);
|
|
3686
3690
|
}
|
|
3687
|
-
function
|
|
3691
|
+
function Cr(e) {
|
|
3688
3692
|
return {
|
|
3689
3693
|
async create(n, r) {
|
|
3690
3694
|
let i = Date.now(), o = {
|
|
@@ -3702,41 +3706,41 @@ function br(e) {
|
|
|
3702
3706
|
last_interaction_at_ts: r.last_interaction_at ? E(r.last_interaction_at) : i,
|
|
3703
3707
|
used_at_ts: E(r.used_at),
|
|
3704
3708
|
revoked_at_ts: E(r.revoked_at)
|
|
3705
|
-
}, s = [e.insert(
|
|
3706
|
-
return c > 0 && o.login_session_id && s.push(e.update(
|
|
3709
|
+
}, s = [e.insert(M).values(o)], c = Sr(o.expires_at_ts, o.idle_expires_at_ts);
|
|
3710
|
+
return c > 0 && o.login_session_id && s.push(e.update(P).set({
|
|
3707
3711
|
expires_at_ts: c,
|
|
3708
3712
|
updated_at_ts: i
|
|
3709
|
-
}).where(t(a(
|
|
3713
|
+
}).where(t(a(P.tenant_id, n), a(P.id, o.login_session_id), m(P.expires_at_ts, c)))), await xt(e, s), xr({
|
|
3710
3714
|
...o,
|
|
3711
3715
|
tenant_id: n
|
|
3712
3716
|
});
|
|
3713
3717
|
},
|
|
3714
3718
|
async get(n, r) {
|
|
3715
|
-
let i = await e.select().from(
|
|
3716
|
-
return i ?
|
|
3719
|
+
let i = await e.select().from(M).where(t(a(M.tenant_id, n), a(M.id, r))).get();
|
|
3720
|
+
return i ? xr(i) : null;
|
|
3717
3721
|
},
|
|
3718
3722
|
async update(n, r, i) {
|
|
3719
3723
|
let o = { updated_at_ts: Date.now() };
|
|
3720
3724
|
i.user_id !== void 0 && (o.user_id = i.user_id), i.login_session_id !== void 0 && (o.login_session_id = i.login_session_id), i.device !== void 0 && (o.device = JSON.stringify(i.device)), i.clients !== void 0 && (o.clients = JSON.stringify(i.clients)), i.expires_at !== void 0 && (o.expires_at_ts = E(i.expires_at)), i.idle_expires_at !== void 0 && (o.idle_expires_at_ts = E(i.idle_expires_at)), i.authenticated_at !== void 0 && (o.authenticated_at_ts = E(i.authenticated_at)), i.last_interaction_at !== void 0 && (o.last_interaction_at_ts = E(i.last_interaction_at)), i.used_at !== void 0 && (o.used_at_ts = E(i.used_at)), i.revoked_at !== void 0 && (o.revoked_at_ts = E(i.revoked_at));
|
|
3721
|
-
let s = await e.update(
|
|
3725
|
+
let s = await e.update(M).set(o).where(t(a(M.tenant_id, n), a(M.id, r))).returning(), c = Sr(o.expires_at_ts, o.idle_expires_at_ts), l = s[0];
|
|
3722
3726
|
if (c > 0 && l) {
|
|
3723
3727
|
let r = i.login_session_id ?? l.login_session_id;
|
|
3724
|
-
r && await e.update(
|
|
3728
|
+
r && await e.update(P).set({
|
|
3725
3729
|
expires_at_ts: c,
|
|
3726
3730
|
updated_at_ts: Date.now()
|
|
3727
|
-
}).where(t(a(
|
|
3731
|
+
}).where(t(a(P.tenant_id, n), a(P.id, r), m(P.expires_at_ts, c))).catch(() => {});
|
|
3728
3732
|
}
|
|
3729
3733
|
return s.length > 0;
|
|
3730
3734
|
},
|
|
3731
3735
|
async list(o, s) {
|
|
3732
|
-
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ?
|
|
3736
|
+
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ? mt(M, f, ["user_id", "id"]) : void 0, m = p ? t(a(M.tenant_id, o), p) : a(M.tenant_id, o), h = e.select().from(M).where(m).$dynamic();
|
|
3733
3737
|
if (d?.sort_by) {
|
|
3734
|
-
let e =
|
|
3738
|
+
let e = M[d.sort_by];
|
|
3735
3739
|
e && (h = h.orderBy(d.sort_order === "desc" ? i(e) : n(e)));
|
|
3736
3740
|
}
|
|
3737
|
-
let g = (await h.offset(c * l).limit(l)).map(
|
|
3741
|
+
let g = (await h.offset(c * l).limit(l)).map(xr);
|
|
3738
3742
|
if (!u) return { sessions: g };
|
|
3739
|
-
let [_] = await e.select({ count: r() }).from(
|
|
3743
|
+
let [_] = await e.select({ count: r() }).from(M).where(m);
|
|
3740
3744
|
return {
|
|
3741
3745
|
sessions: g,
|
|
3742
3746
|
start: c * l,
|
|
@@ -3745,13 +3749,13 @@ function br(e) {
|
|
|
3745
3749
|
};
|
|
3746
3750
|
},
|
|
3747
3751
|
async remove(n, r) {
|
|
3748
|
-
return (await e.delete(
|
|
3752
|
+
return (await e.delete(M).where(t(a(M.tenant_id, n), a(M.id, r))).returning()).length > 0;
|
|
3749
3753
|
}
|
|
3750
3754
|
};
|
|
3751
3755
|
}
|
|
3752
3756
|
//#endregion
|
|
3753
3757
|
//#region src/adapters/tenants.ts
|
|
3754
|
-
var
|
|
3758
|
+
var wr = [
|
|
3755
3759
|
"session_cookie",
|
|
3756
3760
|
"enabled_locales",
|
|
3757
3761
|
"error_page",
|
|
@@ -3767,25 +3771,25 @@ var xr = [
|
|
|
3767
3771
|
"acr_values_supported",
|
|
3768
3772
|
"mtls",
|
|
3769
3773
|
"mfa"
|
|
3770
|
-
],
|
|
3774
|
+
], Tr = [
|
|
3771
3775
|
"allow_organization_name_in_authentication_api",
|
|
3772
3776
|
"customize_mfa_in_postlogin_action",
|
|
3773
3777
|
"pushed_authorization_requests_supported",
|
|
3774
3778
|
"authorization_response_iss_parameter_supported"
|
|
3775
3779
|
];
|
|
3776
|
-
function
|
|
3780
|
+
function Er(e) {
|
|
3777
3781
|
let t = { ...e };
|
|
3778
|
-
for (let e of
|
|
3779
|
-
for (let e of
|
|
3782
|
+
for (let e of wr) typeof t[e] == "string" && (t[e] = Z(t[e]));
|
|
3783
|
+
for (let e of Tr) t[e] !== void 0 && t[e] !== null && (t[e] = t[e] === 1);
|
|
3780
3784
|
return D(t);
|
|
3781
3785
|
}
|
|
3782
|
-
function
|
|
3786
|
+
function Dr(e) {
|
|
3783
3787
|
let t = { ...e };
|
|
3784
|
-
le(e,
|
|
3785
|
-
for (let n of
|
|
3788
|
+
le(e, wr, t);
|
|
3789
|
+
for (let n of Tr) e[n] !== void 0 && (t[n] = +!!e[n]);
|
|
3786
3790
|
return ce(t);
|
|
3787
3791
|
}
|
|
3788
|
-
function
|
|
3792
|
+
function Or(e) {
|
|
3789
3793
|
return {
|
|
3790
3794
|
async create(t) {
|
|
3791
3795
|
let n = {
|
|
@@ -3793,26 +3797,26 @@ function Tr(e) {
|
|
|
3793
3797
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3794
3798
|
updated_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3795
3799
|
...t
|
|
3796
|
-
}, r =
|
|
3800
|
+
}, r = Dr(n);
|
|
3797
3801
|
try {
|
|
3798
3802
|
await e.insert(O).values(r);
|
|
3799
3803
|
} catch (e) {
|
|
3800
3804
|
let t = e?.message ?? "";
|
|
3801
|
-
throw t.includes("UNIQUE constraint failed") || t.includes("Duplicate entry") || t.includes("duplicate key") || t.includes("AlreadyExists") || e?.code === "SQLITE_CONSTRAINT" || e?.code === "SQLITE_CONSTRAINT_UNIQUE" || e?.code === "SQLITE_CONSTRAINT_PRIMARYKEY" || e?.code === "ER_DUP_ENTRY" || e?.code === "23505" ? new
|
|
3805
|
+
throw t.includes("UNIQUE constraint failed") || t.includes("Duplicate entry") || t.includes("duplicate key") || t.includes("AlreadyExists") || e?.code === "SQLITE_CONSTRAINT" || e?.code === "SQLITE_CONSTRAINT_UNIQUE" || e?.code === "SQLITE_CONSTRAINT_PRIMARYKEY" || e?.code === "ER_DUP_ENTRY" || e?.code === "23505" ? new Fe(409, { message: `Tenant with ID '${n.id}' already exists` }) : e;
|
|
3802
3806
|
}
|
|
3803
3807
|
return n;
|
|
3804
3808
|
},
|
|
3805
3809
|
async get(t) {
|
|
3806
3810
|
let n = await e.select().from(O).where(a(O.id, t)).get();
|
|
3807
|
-
return n ?
|
|
3811
|
+
return n ? Er(n) : null;
|
|
3808
3812
|
},
|
|
3809
3813
|
async list(t) {
|
|
3810
|
-
let { page: a = 0, per_page: o = 50, include_totals: s = !1, sort: c, q: l } = t || {}, u = l ?
|
|
3814
|
+
let { page: a = 0, per_page: o = 50, include_totals: s = !1, sort: c, q: l } = t || {}, u = l ? mt(O, l, ["friendly_name"]) : void 0, d = e.select().from(O).$dynamic();
|
|
3811
3815
|
if (u && (d = d.where(u)), c?.sort_by) {
|
|
3812
3816
|
let e = O[c.sort_by];
|
|
3813
3817
|
e && (d = d.orderBy(c.sort_order === "desc" ? i(e) : n(e)));
|
|
3814
3818
|
}
|
|
3815
|
-
let f = (await d.offset(a * o).limit(o)).map(
|
|
3819
|
+
let f = (await d.offset(a * o).limit(o)).map(Er);
|
|
3816
3820
|
if (!s) return { tenants: f };
|
|
3817
3821
|
let p = e.select({ count: r() }).from(O).$dynamic();
|
|
3818
3822
|
u && (p = p.where(u));
|
|
@@ -3825,7 +3829,7 @@ function Tr(e) {
|
|
|
3825
3829
|
};
|
|
3826
3830
|
},
|
|
3827
3831
|
async update(t, n) {
|
|
3828
|
-
let r =
|
|
3832
|
+
let r = Dr({
|
|
3829
3833
|
...n,
|
|
3830
3834
|
id: t,
|
|
3831
3835
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
@@ -3839,62 +3843,62 @@ function Tr(e) {
|
|
|
3839
3843
|
}
|
|
3840
3844
|
//#endregion
|
|
3841
3845
|
//#region src/adapters/themes.ts
|
|
3842
|
-
var
|
|
3846
|
+
var kr = [
|
|
3843
3847
|
"colors",
|
|
3844
3848
|
"borders",
|
|
3845
3849
|
"fonts",
|
|
3846
3850
|
"page_background",
|
|
3847
3851
|
"widget"
|
|
3848
3852
|
];
|
|
3849
|
-
function
|
|
3850
|
-
let { tenant_id: t, ...n } = e, r =
|
|
3853
|
+
function Ar(e) {
|
|
3854
|
+
let { tenant_id: t, ...n } = e, r = dt(n, kr);
|
|
3851
3855
|
return r.borders && (r.borders.show_widget_shadow = !!r.borders.show_widget_shadow), r.fonts && (r.fonts.body_text_bold = !!r.fonts.body_text_bold, r.fonts.buttons_text_bold = !!r.fonts.buttons_text_bold, r.fonts.input_labels_bold = !!r.fonts.input_labels_bold, r.fonts.links_bold = !!r.fonts.links_bold, r.fonts.subtitle_bold = !!r.fonts.subtitle_bold, r.fonts.title_bold = !!r.fonts.title_bold), D(r);
|
|
3852
3856
|
}
|
|
3853
|
-
function
|
|
3857
|
+
function jr(e) {
|
|
3854
3858
|
return {
|
|
3855
3859
|
async create(t, n, r, i) {
|
|
3856
3860
|
let a = i?.importMetadata, o = (/* @__PURE__ */ new Date()).toISOString(), s = a?.id || r || b(), c = {
|
|
3857
|
-
...
|
|
3861
|
+
...ut(n),
|
|
3858
3862
|
tenant_id: t,
|
|
3859
3863
|
themeId: s,
|
|
3860
3864
|
created_at: a?.created_at ?? o,
|
|
3861
3865
|
updated_at: a?.updated_at ?? o
|
|
3862
3866
|
};
|
|
3863
|
-
return await e.insert(
|
|
3867
|
+
return await e.insert(Ze).values(c), Ar({
|
|
3864
3868
|
...c,
|
|
3865
3869
|
tenant_id: t
|
|
3866
3870
|
});
|
|
3867
3871
|
},
|
|
3868
3872
|
async get(n, r) {
|
|
3869
|
-
let i = await e.select().from(
|
|
3870
|
-
return i ?
|
|
3873
|
+
let i = await e.select().from(Ze).where(t(a(Ze.tenant_id, n), a(Ze.themeId, r))).get();
|
|
3874
|
+
return i ? Ar(i) : null;
|
|
3871
3875
|
},
|
|
3872
3876
|
async update(n, r, i) {
|
|
3873
|
-
let o =
|
|
3874
|
-
return o.updated_at = (/* @__PURE__ */ new Date()).toISOString(), await e.update(
|
|
3877
|
+
let o = ut(i);
|
|
3878
|
+
return o.updated_at = (/* @__PURE__ */ new Date()).toISOString(), await e.update(Ze).set(o).where(t(a(Ze.tenant_id, n), a(Ze.themeId, r))), !0;
|
|
3875
3879
|
},
|
|
3876
3880
|
async remove(n, r) {
|
|
3877
|
-
return (await e.delete(
|
|
3881
|
+
return (await e.delete(Ze).where(t(a(Ze.tenant_id, n), a(Ze.themeId, r))).returning()).length > 0;
|
|
3878
3882
|
}
|
|
3879
3883
|
};
|
|
3880
3884
|
}
|
|
3881
3885
|
//#endregion
|
|
3882
3886
|
//#region src/adapters/universalLoginTemplates.ts
|
|
3883
|
-
function
|
|
3887
|
+
function Mr(e) {
|
|
3884
3888
|
return {
|
|
3885
3889
|
async get(t) {
|
|
3886
|
-
let n = await e.select({ body:
|
|
3890
|
+
let n = await e.select({ body: Xe.body }).from(Xe).where(a(Xe.tenant_id, t)).get();
|
|
3887
3891
|
return n ? { body: n.body } : null;
|
|
3888
3892
|
},
|
|
3889
3893
|
async set(t, n) {
|
|
3890
3894
|
let r = Date.now();
|
|
3891
|
-
await e.insert(
|
|
3895
|
+
await e.insert(Xe).values({
|
|
3892
3896
|
tenant_id: t,
|
|
3893
3897
|
body: n.body,
|
|
3894
3898
|
created_at_ts: r,
|
|
3895
3899
|
updated_at_ts: r
|
|
3896
3900
|
}).onConflictDoUpdate({
|
|
3897
|
-
target:
|
|
3901
|
+
target: Xe.tenant_id,
|
|
3898
3902
|
set: {
|
|
3899
3903
|
body: n.body,
|
|
3900
3904
|
updated_at_ts: r
|
|
@@ -3902,20 +3906,20 @@ function kr(e) {
|
|
|
3902
3906
|
});
|
|
3903
3907
|
},
|
|
3904
3908
|
async delete(t) {
|
|
3905
|
-
await e.delete(
|
|
3909
|
+
await e.delete(Xe).where(a(Xe.tenant_id, t));
|
|
3906
3910
|
}
|
|
3907
3911
|
};
|
|
3908
3912
|
}
|
|
3909
3913
|
//#endregion
|
|
3910
3914
|
//#region src/adapters/userActivity.ts
|
|
3911
|
-
function
|
|
3915
|
+
function Nr(e) {
|
|
3912
3916
|
let t = {};
|
|
3913
3917
|
return e.last_login !== void 0 && (t.last_login = e.last_login), e.last_ip !== void 0 && (t.last_ip = e.last_ip), e.login_count !== void 0 && (t.login_count = e.login_count), e.failed_logins !== void 0 && (t.failed_logins = JSON.stringify(e.failed_logins)), e.last_password_reset !== void 0 && (t.last_password_reset = e.last_password_reset), t;
|
|
3914
3918
|
}
|
|
3915
|
-
function
|
|
3919
|
+
function Pr(e) {
|
|
3916
3920
|
return {
|
|
3917
3921
|
async get(n, r) {
|
|
3918
|
-
let i = await e.select().from(
|
|
3922
|
+
let i = await e.select().from(Be).where(t(a(Be.tenant_id, n), a(Be.user_id, r))).get();
|
|
3919
3923
|
return i ? {
|
|
3920
3924
|
user_id: i.user_id,
|
|
3921
3925
|
last_login: i.last_login ?? void 0,
|
|
@@ -3926,7 +3930,7 @@ function jr(e) {
|
|
|
3926
3930
|
} : null;
|
|
3927
3931
|
},
|
|
3928
3932
|
async upsert(t, n, r) {
|
|
3929
|
-
let i =
|
|
3933
|
+
let i = Nr(r), a = e.insert(Be).values({
|
|
3930
3934
|
tenant_id: t,
|
|
3931
3935
|
user_id: n,
|
|
3932
3936
|
login_count: 0,
|
|
@@ -3937,7 +3941,7 @@ function jr(e) {
|
|
|
3937
3941
|
return;
|
|
3938
3942
|
}
|
|
3939
3943
|
await a.onConflictDoUpdate({
|
|
3940
|
-
target: [
|
|
3944
|
+
target: [Be.tenant_id, Be.user_id],
|
|
3941
3945
|
set: i
|
|
3942
3946
|
});
|
|
3943
3947
|
}
|
|
@@ -3945,14 +3949,14 @@ function jr(e) {
|
|
|
3945
3949
|
}
|
|
3946
3950
|
//#endregion
|
|
3947
3951
|
//#region src/adapters/outbox.ts
|
|
3948
|
-
function
|
|
3952
|
+
function Fr(e) {
|
|
3949
3953
|
return {
|
|
3950
3954
|
...e,
|
|
3951
|
-
payload:
|
|
3955
|
+
payload: Z(e.payload, {})
|
|
3952
3956
|
};
|
|
3953
3957
|
}
|
|
3954
|
-
function
|
|
3955
|
-
return e.insert(
|
|
3958
|
+
function Ir(e, t, n, r) {
|
|
3959
|
+
return e.insert(J).values({
|
|
3956
3960
|
id: t,
|
|
3957
3961
|
tenant_id: n,
|
|
3958
3962
|
event_type: r.event_type,
|
|
@@ -3972,53 +3976,53 @@ function Nr(e, t, n, r) {
|
|
|
3972
3976
|
claim_expires_at: null
|
|
3973
3977
|
});
|
|
3974
3978
|
}
|
|
3975
|
-
function
|
|
3979
|
+
function Lr(e) {
|
|
3976
3980
|
return {
|
|
3977
3981
|
async create(t, n) {
|
|
3978
3982
|
let r = b();
|
|
3979
|
-
return await
|
|
3983
|
+
return await Ir(e, r, t, n), r;
|
|
3980
3984
|
},
|
|
3981
3985
|
async getByIds(t) {
|
|
3982
|
-
return t.length === 0 ? [] : (await e.select().from(
|
|
3986
|
+
return t.length === 0 ? [] : (await e.select().from(J).where(l(J.id, t)).all()).map(Fr);
|
|
3983
3987
|
},
|
|
3984
3988
|
async getUnprocessed(n) {
|
|
3985
3989
|
let r = (/* @__PURE__ */ new Date()).toISOString();
|
|
3986
|
-
return (await e.select().from(
|
|
3990
|
+
return (await e.select().from(J).where(t(f(J.processed_at), v(f(J.next_retry_at), h(J.next_retry_at, r)), v(f(J.claimed_by), h(J.claim_expires_at, r)))).orderBy(J.created_at, J.id).limit(n).all()).map(Fr);
|
|
3987
3991
|
},
|
|
3988
3992
|
async claimEvents(n, r, i) {
|
|
3989
3993
|
if (n.length === 0) return [];
|
|
3990
3994
|
let o = (/* @__PURE__ */ new Date()).toISOString(), s = new Date(Date.now() + i).toISOString();
|
|
3991
|
-
return await e.update(
|
|
3995
|
+
return await e.update(J).set({
|
|
3992
3996
|
claimed_by: r,
|
|
3993
3997
|
claim_expires_at: s
|
|
3994
|
-
}).where(t(l(
|
|
3998
|
+
}).where(t(l(J.id, n), f(J.processed_at), v(f(J.claimed_by), h(J.claim_expires_at, o)))), (await e.select({ id: J.id }).from(J).where(t(l(J.id, n), a(J.claimed_by, r))).all()).map((e) => e.id);
|
|
3995
3999
|
},
|
|
3996
4000
|
async markProcessed(t) {
|
|
3997
|
-
t.length !== 0 && await e.update(
|
|
4001
|
+
t.length !== 0 && await e.update(J).set({ processed_at: (/* @__PURE__ */ new Date()).toISOString() }).where(l(J.id, t));
|
|
3998
4002
|
},
|
|
3999
4003
|
async markRetry(t, n, r) {
|
|
4000
|
-
await e.update(
|
|
4004
|
+
await e.update(J).set({
|
|
4001
4005
|
error: n,
|
|
4002
4006
|
next_retry_at: r,
|
|
4003
|
-
retry_count: y`${
|
|
4007
|
+
retry_count: y`${J.retry_count} + 1`,
|
|
4004
4008
|
claimed_by: null,
|
|
4005
4009
|
claim_expires_at: null
|
|
4006
|
-
}).where(a(
|
|
4010
|
+
}).where(a(J.id, t));
|
|
4007
4011
|
},
|
|
4008
4012
|
async cleanup(n) {
|
|
4009
|
-
return (await e.delete(
|
|
4013
|
+
return (await e.delete(J).where(t(y`${J.processed_at} IS NOT NULL`, h(J.processed_at, n))).returning()).length;
|
|
4010
4014
|
},
|
|
4011
4015
|
async deadLetter(t, n) {
|
|
4012
4016
|
let r = (/* @__PURE__ */ new Date()).toISOString();
|
|
4013
|
-
await e.update(
|
|
4017
|
+
await e.update(J).set({
|
|
4014
4018
|
processed_at: r,
|
|
4015
4019
|
dead_lettered_at: r,
|
|
4016
4020
|
final_error: n
|
|
4017
|
-
}).where(a(
|
|
4021
|
+
}).where(a(J.id, t));
|
|
4018
4022
|
},
|
|
4019
4023
|
async listFailed(o, s = {}) {
|
|
4020
|
-
let { page: c = 0, per_page: l = 50, include_totals: u = !1 } = s, f = (await e.select().from(
|
|
4021
|
-
...
|
|
4024
|
+
let { page: c = 0, per_page: l = 50, include_totals: u = !1 } = s, f = (await e.select().from(J).where(t(a(J.tenant_id, o), d(J.dead_lettered_at))).orderBy(i(J.dead_lettered_at), n(J.id)).offset(c * l).limit(l).all()).map((e) => ({
|
|
4025
|
+
...Z(e.payload, {}),
|
|
4022
4026
|
id: e.id,
|
|
4023
4027
|
created_at: e.created_at,
|
|
4024
4028
|
processed_at: e.processed_at,
|
|
@@ -4029,7 +4033,7 @@ function Pr(e) {
|
|
|
4029
4033
|
final_error: e.final_error
|
|
4030
4034
|
})), p = f.length;
|
|
4031
4035
|
if (u) {
|
|
4032
|
-
let [n] = await e.select({ total: r() }).from(
|
|
4036
|
+
let [n] = await e.select({ total: r() }).from(J).where(t(a(J.tenant_id, o), d(J.dead_lettered_at)));
|
|
4033
4037
|
p = Number(n?.total ?? f.length);
|
|
4034
4038
|
}
|
|
4035
4039
|
return {
|
|
@@ -4040,7 +4044,7 @@ function Pr(e) {
|
|
|
4040
4044
|
};
|
|
4041
4045
|
},
|
|
4042
4046
|
async replay(n, r) {
|
|
4043
|
-
return (await e.update(
|
|
4047
|
+
return (await e.update(J).set({
|
|
4044
4048
|
processed_at: null,
|
|
4045
4049
|
dead_lettered_at: null,
|
|
4046
4050
|
final_error: null,
|
|
@@ -4049,16 +4053,16 @@ function Pr(e) {
|
|
|
4049
4053
|
error: null,
|
|
4050
4054
|
claimed_by: null,
|
|
4051
4055
|
claim_expires_at: null
|
|
4052
|
-
}).where(t(a(
|
|
4056
|
+
}).where(t(a(J.id, n), a(J.tenant_id, r), d(J.dead_lettered_at))).returning()).length > 0;
|
|
4053
4057
|
}
|
|
4054
4058
|
};
|
|
4055
4059
|
}
|
|
4056
4060
|
//#endregion
|
|
4057
4061
|
//#region src/adapters/users.ts
|
|
4058
|
-
function
|
|
4059
|
-
return (n?.outboxEvents ?? []).map((n) =>
|
|
4062
|
+
function Rr(e, t, n) {
|
|
4063
|
+
return (n?.outboxEvents ?? []).map((n) => Ir(e, n.id, t, n));
|
|
4060
4064
|
}
|
|
4061
|
-
var
|
|
4065
|
+
var zr = [
|
|
4062
4066
|
"user_id",
|
|
4063
4067
|
"email",
|
|
4064
4068
|
"email_verified",
|
|
@@ -4080,23 +4084,23 @@ var Ir = [
|
|
|
4080
4084
|
"login_count",
|
|
4081
4085
|
"created_at",
|
|
4082
4086
|
"updated_at"
|
|
4083
|
-
],
|
|
4087
|
+
], Br = [
|
|
4084
4088
|
"email",
|
|
4085
4089
|
"name",
|
|
4086
4090
|
"phone_number",
|
|
4087
4091
|
"user_id"
|
|
4088
|
-
],
|
|
4092
|
+
], Vr = new Set([
|
|
4089
4093
|
"last_login",
|
|
4090
4094
|
"last_ip",
|
|
4091
4095
|
"login_count"
|
|
4092
|
-
]),
|
|
4093
|
-
coalesce:
|
|
4096
|
+
]), Hr = o(A), Ur = o(Be), Wr = Object.fromEntries(zr.map((e) => [e, e === "login_count" ? {
|
|
4097
|
+
coalesce: Be.login_count,
|
|
4094
4098
|
defaultValue: 0
|
|
4095
|
-
} :
|
|
4096
|
-
function
|
|
4097
|
-
return t(a(
|
|
4099
|
+
} : Vr.has(e) ? Ur[e] : Hr[e]]));
|
|
4100
|
+
function Gr() {
|
|
4101
|
+
return t(a(Be.tenant_id, A.tenant_id), a(Be.user_id, A.user_id));
|
|
4098
4102
|
}
|
|
4099
|
-
function
|
|
4103
|
+
function Kr(e, t) {
|
|
4100
4104
|
return {
|
|
4101
4105
|
...e,
|
|
4102
4106
|
last_login: t?.last_login,
|
|
@@ -4104,7 +4108,7 @@ function Ur(e, t) {
|
|
|
4104
4108
|
login_count: t?.login_count ?? 0
|
|
4105
4109
|
};
|
|
4106
4110
|
}
|
|
4107
|
-
function
|
|
4111
|
+
function qr(e, t) {
|
|
4108
4112
|
let n = {
|
|
4109
4113
|
connection: e.connection,
|
|
4110
4114
|
provider: e.provider,
|
|
@@ -4114,11 +4118,11 @@ function Wr(e, t) {
|
|
|
4114
4118
|
return t ? n.isPrimary = !0 : n.profileData = {
|
|
4115
4119
|
email: e.email,
|
|
4116
4120
|
email_verified: !!e.email_verified,
|
|
4117
|
-
...typeof e.profileData == "string" ?
|
|
4121
|
+
...typeof e.profileData == "string" ? Z(e.profileData, {}) : {}
|
|
4118
4122
|
}, n;
|
|
4119
4123
|
}
|
|
4120
|
-
function
|
|
4121
|
-
let { tenant_id: n, app_metadata: r, user_metadata: i, address: a, email_verified: o, phone_verified: s, is_social: c, blocked: l, linked_to: u, profileData: d, ...f } = e, p =
|
|
4124
|
+
function Jr(e, t = []) {
|
|
4125
|
+
let { tenant_id: n, app_metadata: r, user_metadata: i, address: a, email_verified: o, phone_verified: s, is_social: c, blocked: l, linked_to: u, profileData: d, ...f } = e, p = qr(e, !0), m = t.map((e) => qr(e, !1));
|
|
4122
4126
|
return D({
|
|
4123
4127
|
...f,
|
|
4124
4128
|
email: e.email || "",
|
|
@@ -4126,13 +4130,13 @@ function Gr(e, t = []) {
|
|
|
4126
4130
|
phone_verified: s == null ? void 0 : !!s,
|
|
4127
4131
|
is_social: !!c,
|
|
4128
4132
|
blocked: l == null ? void 0 : !!l,
|
|
4129
|
-
app_metadata:
|
|
4130
|
-
user_metadata:
|
|
4131
|
-
address:
|
|
4133
|
+
app_metadata: Z(r, {}),
|
|
4134
|
+
user_metadata: Z(i, {}),
|
|
4135
|
+
address: Z(a),
|
|
4132
4136
|
identities: [p, ...m]
|
|
4133
4137
|
});
|
|
4134
4138
|
}
|
|
4135
|
-
function
|
|
4139
|
+
function Yr(e) {
|
|
4136
4140
|
let o = async (t, n, r) => {
|
|
4137
4141
|
let i = (/* @__PURE__ */ new Date()).toISOString(), a = {
|
|
4138
4142
|
user_id: n.user_id,
|
|
@@ -4169,14 +4173,14 @@ function Kr(e) {
|
|
|
4169
4173
|
updated_at: n.updated_at || i
|
|
4170
4174
|
}, o = n.password ? b() : void 0, s = n.last_login !== void 0 || n.last_ip !== void 0 || n.login_count !== void 0;
|
|
4171
4175
|
try {
|
|
4172
|
-
let c = [e.insert(
|
|
4173
|
-
s && c.push(e.insert(
|
|
4176
|
+
let c = [e.insert(A).values(a)];
|
|
4177
|
+
s && c.push(e.insert(Be).values({
|
|
4174
4178
|
tenant_id: t,
|
|
4175
4179
|
user_id: n.user_id,
|
|
4176
4180
|
last_login: n.last_login,
|
|
4177
4181
|
last_ip: n.last_ip,
|
|
4178
4182
|
login_count: n.login_count ?? 0
|
|
4179
|
-
})), n.password && o && c.push(e.insert(
|
|
4183
|
+
})), n.password && o && c.push(e.insert(j).values({
|
|
4180
4184
|
id: o,
|
|
4181
4185
|
tenant_id: t,
|
|
4182
4186
|
user_id: n.user_id,
|
|
@@ -4186,12 +4190,12 @@ function Kr(e) {
|
|
|
4186
4190
|
created_at: i,
|
|
4187
4191
|
updated_at: i
|
|
4188
4192
|
}));
|
|
4189
|
-
for (let n of
|
|
4190
|
-
c.length > 1 ? await
|
|
4193
|
+
for (let n of Rr(e, t, r)) c.push(n);
|
|
4194
|
+
c.length > 1 ? await xt(e, c) : await e.insert(A).values(a);
|
|
4191
4195
|
} catch (e) {
|
|
4192
|
-
throw e?.message?.includes("UNIQUE constraint") || e?.message?.includes("AlreadyExists") ? new
|
|
4196
|
+
throw e?.message?.includes("UNIQUE constraint") || e?.message?.includes("AlreadyExists") ? new Fe(409, { message: "User already exists" }) : (console.error("User upsert failed:", e?.code, e?.message), new Fe(500, { message: "Internal server error" }));
|
|
4193
4197
|
}
|
|
4194
|
-
return
|
|
4198
|
+
return Jr({
|
|
4195
4199
|
...a,
|
|
4196
4200
|
last_login: n.last_login,
|
|
4197
4201
|
last_ip: n.last_ip,
|
|
@@ -4202,10 +4206,10 @@ function Kr(e) {
|
|
|
4202
4206
|
create: o,
|
|
4203
4207
|
rawCreate: o,
|
|
4204
4208
|
async get(n, r) {
|
|
4205
|
-
let i = await e.select().from(
|
|
4209
|
+
let i = await e.select().from(A).leftJoin(Be, Gr()).where(t(a(A.tenant_id, n), a(A.user_id, r))).get();
|
|
4206
4210
|
if (!i) return null;
|
|
4207
|
-
let o = await e.select().from(
|
|
4208
|
-
return
|
|
4211
|
+
let o = await e.select().from(A).where(t(a(A.tenant_id, n), a(A.linked_to, r))).all();
|
|
4212
|
+
return Jr(Kr(i.users, i.user_activity), o);
|
|
4209
4213
|
},
|
|
4210
4214
|
async update(n, r, i, o) {
|
|
4211
4215
|
let s = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
@@ -4232,34 +4236,34 @@ function Kr(e) {
|
|
|
4232
4236
|
"zoneinfo"
|
|
4233
4237
|
]) i[e] !== void 0 && (s[e] = i[e]);
|
|
4234
4238
|
i.email_verified !== void 0 && (s.email_verified = i.email_verified), i.phone_verified !== void 0 && (s.phone_verified = i.phone_verified), i.is_social !== void 0 && (s.is_social = i.is_social), i.blocked !== void 0 && (s.blocked = i.blocked), i.app_metadata !== void 0 && (s.app_metadata = JSON.stringify(i.app_metadata)), i.user_metadata !== void 0 && (s.user_metadata = JSON.stringify(i.user_metadata)), i.address !== void 0 && (s.address = JSON.stringify(i.address)), i.profileData !== void 0 && (s.profileData = JSON.stringify(i.profileData));
|
|
4235
|
-
let c = e.update(
|
|
4236
|
-
return u = l.length > 0 ? (await
|
|
4239
|
+
let c = e.update(A).set(s).where(t(a(A.tenant_id, n), a(A.user_id, r))).returning(), l = Rr(e, n, o), u;
|
|
4240
|
+
return u = l.length > 0 ? (await xt(e, [c, ...l]))[0] : await c, !Array.isArray(u) || u.length === 0 ? !1 : ((i.last_login !== void 0 || i.last_ip !== void 0 || i.login_count !== void 0) && await Pr(e).upsert(n, r, {
|
|
4237
4241
|
last_login: i.last_login,
|
|
4238
4242
|
last_ip: i.last_ip,
|
|
4239
4243
|
login_count: i.login_count
|
|
4240
4244
|
}), !0);
|
|
4241
4245
|
},
|
|
4242
4246
|
async list(o, s) {
|
|
4243
|
-
let { page: c = 0, per_page: u = 50, include_totals: d = !1, sort: p, q: m } = s || {}, h = [a(
|
|
4247
|
+
let { page: c = 0, per_page: u = 50, include_totals: d = !1, sort: p, q: m } = s || {}, h = [a(A.tenant_id, o), f(A.linked_to)];
|
|
4244
4248
|
if (m) {
|
|
4245
|
-
let e = we(m,
|
|
4249
|
+
let e = we(m, zr);
|
|
4246
4250
|
if (e) {
|
|
4247
|
-
let t =
|
|
4251
|
+
let t = mt(Wr, e, Br);
|
|
4248
4252
|
t && h.push(t);
|
|
4249
4253
|
}
|
|
4250
4254
|
}
|
|
4251
4255
|
let g = t(...h), _ = async (n) => {
|
|
4252
|
-
let r = n.map((e) => e.user_id), i = r.length > 0 ? await e.select().from(
|
|
4253
|
-
return n.map((e) =>
|
|
4256
|
+
let r = n.map((e) => e.user_id), i = r.length > 0 ? await e.select().from(A).where(t(a(A.tenant_id, o), l(A.linked_to, r))) : [];
|
|
4257
|
+
return n.map((e) => Jr(e, i.filter((t) => t.linked_to === e.user_id)));
|
|
4254
4258
|
};
|
|
4255
|
-
if (
|
|
4256
|
-
if (p?.sort_by && p.sort_by !== "created_at") throw new
|
|
4259
|
+
if (Et(s)) {
|
|
4260
|
+
if (p?.sort_by && p.sort_by !== "created_at") throw new Fe(400, { message: `Sorting by ${p.sort_by} is not supported with checkpoint pagination (from/take); only created_at is` });
|
|
4257
4261
|
let n = p?.sort_order === "asc" ? "asc" : "desc", r = {
|
|
4258
|
-
sortColumn:
|
|
4259
|
-
idColumn:
|
|
4262
|
+
sortColumn: A.created_at,
|
|
4263
|
+
idColumn: A.user_id,
|
|
4260
4264
|
sortOrder: n,
|
|
4261
4265
|
sortKey: `created_at:${n}`
|
|
4262
|
-
}, i =
|
|
4266
|
+
}, i = Dt(s), a = kt(s, r), { rows: o, next: c } = At((await e.select().from(A).leftJoin(Be, Gr()).where(a ? t(g, a) : g).orderBy(...Ot(r)).limit(i + 1)).map((e) => Kr(e.users, e.user_activity)), i, "created_at", "user_id", r.sortKey), l = await _(o);
|
|
4263
4267
|
return {
|
|
4264
4268
|
users: l,
|
|
4265
4269
|
start: 0,
|
|
@@ -4268,15 +4272,15 @@ function Kr(e) {
|
|
|
4268
4272
|
next: c
|
|
4269
4273
|
};
|
|
4270
4274
|
}
|
|
4271
|
-
let v = e.select().from(
|
|
4275
|
+
let v = e.select().from(A).leftJoin(Be, Gr()).where(g).$dynamic();
|
|
4272
4276
|
if (p?.sort_by) {
|
|
4273
|
-
let e =
|
|
4277
|
+
let e = Wr[p.sort_by];
|
|
4274
4278
|
if (e) {
|
|
4275
|
-
let t =
|
|
4279
|
+
let t = ft(e) ? pt(e) : e;
|
|
4276
4280
|
v = v.orderBy(p.sort_order === "desc" ? i(t) : n(t));
|
|
4277
4281
|
}
|
|
4278
4282
|
}
|
|
4279
|
-
let [y, ee] = await Promise.all([v.offset(c * u).limit(u), d ? e.select({ count: r() }).from(
|
|
4283
|
+
let [y, ee] = await Promise.all([v.offset(c * u).limit(u), d ? e.select({ count: r() }).from(A).leftJoin(Be, Gr()).where(g) : void 0]), b = await _(y.map((e) => Kr(e.users, e.user_activity)));
|
|
4280
4284
|
if (!ee) return { users: b };
|
|
4281
4285
|
let [te] = ee;
|
|
4282
4286
|
return {
|
|
@@ -4287,30 +4291,30 @@ function Kr(e) {
|
|
|
4287
4291
|
};
|
|
4288
4292
|
},
|
|
4289
4293
|
async remove(n, r, i) {
|
|
4290
|
-
let o = await e.select({ user_id:
|
|
4291
|
-
e.delete(
|
|
4292
|
-
e.delete(
|
|
4293
|
-
e.delete(
|
|
4294
|
-
e.delete(
|
|
4295
|
-
e.delete(
|
|
4294
|
+
let o = await e.select({ user_id: A.user_id }).from(A).where(t(a(A.tenant_id, n), v(a(A.user_id, r), a(A.linked_to, r)))), s = o.some((e) => e.user_id === r), c = o.map((e) => e.user_id).filter((e) => e !== r), u = [r, ...c], d = [
|
|
4295
|
+
e.delete(K).where(t(a(K.tenant_id, n), l(K.user_id, u))),
|
|
4296
|
+
e.delete(j).where(t(a(j.tenant_id, n), l(j.user_id, u))),
|
|
4297
|
+
e.delete(Be).where(t(a(Be.tenant_id, n), l(Be.user_id, u))),
|
|
4298
|
+
e.delete(A).where(t(a(A.tenant_id, n), l(A.user_id, c))),
|
|
4299
|
+
e.delete(A).where(t(a(A.tenant_id, n), a(A.user_id, r))).returning()
|
|
4296
4300
|
], f = d.length - 1;
|
|
4297
|
-
if (s) for (let t of
|
|
4298
|
-
let p = (await
|
|
4301
|
+
if (s) for (let t of Rr(e, n, i)) d.push(t);
|
|
4302
|
+
let p = (await xt(e, d))[f];
|
|
4299
4303
|
return Array.isArray(p) && p.length > 0;
|
|
4300
4304
|
},
|
|
4301
4305
|
async unlink(n, r, i, o) {
|
|
4302
4306
|
let s = `${i}|${o}`;
|
|
4303
|
-
return (await e.update(
|
|
4307
|
+
return (await e.update(A).set({ linked_to: null }).where(t(a(A.tenant_id, n), a(A.user_id, s), a(A.linked_to, r))).returning()).length > 0;
|
|
4304
4308
|
}
|
|
4305
4309
|
};
|
|
4306
4310
|
}
|
|
4307
4311
|
//#endregion
|
|
4308
4312
|
//#region src/adapters/userRoles.ts
|
|
4309
|
-
function
|
|
4313
|
+
function Xr(e) {
|
|
4310
4314
|
return {
|
|
4311
4315
|
async create(t, n, r, i) {
|
|
4312
4316
|
try {
|
|
4313
|
-
await e.insert(
|
|
4317
|
+
await e.insert(W).values({
|
|
4314
4318
|
tenant_id: t,
|
|
4315
4319
|
user_id: n,
|
|
4316
4320
|
role_id: r,
|
|
@@ -4324,28 +4328,28 @@ function qr(e) {
|
|
|
4324
4328
|
return !0;
|
|
4325
4329
|
},
|
|
4326
4330
|
async list(n, r, i, o) {
|
|
4327
|
-
let s = [a(
|
|
4328
|
-
o !== void 0 && s.push(a(
|
|
4329
|
-
let c = await e.select({ role_id:
|
|
4331
|
+
let s = [a(W.tenant_id, n), a(W.user_id, r)];
|
|
4332
|
+
o !== void 0 && s.push(a(W.organization_id, o));
|
|
4333
|
+
let c = await e.select({ role_id: W.role_id }).from(W).where(t(...s)).all();
|
|
4330
4334
|
return c.length === 0 ? [] : (await Promise.all(c.map(async (r) => {
|
|
4331
|
-
let i = await e.select().from(
|
|
4335
|
+
let i = await e.select().from(U).where(t(a(U.tenant_id, n), a(U.id, r.role_id))).get();
|
|
4332
4336
|
if (!i) return null;
|
|
4333
4337
|
let { tenant_id: o, is_system: s, metadata: c, ...l } = i;
|
|
4334
4338
|
return D({
|
|
4335
4339
|
...l,
|
|
4336
4340
|
is_system: s ? !0 : void 0,
|
|
4337
|
-
metadata:
|
|
4341
|
+
metadata: Z(c)
|
|
4338
4342
|
});
|
|
4339
4343
|
}))).filter(Boolean);
|
|
4340
4344
|
},
|
|
4341
4345
|
async listUsers(r, i, o) {
|
|
4342
|
-
let s = t(a(
|
|
4343
|
-
if (
|
|
4346
|
+
let s = t(a(W.tenant_id, r), a(W.role_id, i));
|
|
4347
|
+
if (Et(o)) {
|
|
4344
4348
|
let n = {
|
|
4345
|
-
sortColumn:
|
|
4346
|
-
idColumn:
|
|
4349
|
+
sortColumn: W.user_id,
|
|
4350
|
+
idColumn: W.user_id,
|
|
4347
4351
|
sortOrder: "asc"
|
|
4348
|
-
}, r =
|
|
4352
|
+
}, r = kt(o, n), i = Dt(o), { rows: a, next: c } = At(await e.selectDistinct({ user_id: W.user_id }).from(W).where(r ? t(s, r) : s).orderBy(...Ot(n)).limit(i + 1).all(), i, "user_id", "user_id");
|
|
4349
4353
|
return {
|
|
4350
4354
|
userIds: a.map((e) => e.user_id),
|
|
4351
4355
|
start: 0,
|
|
@@ -4354,7 +4358,7 @@ function qr(e) {
|
|
|
4354
4358
|
next: c
|
|
4355
4359
|
};
|
|
4356
4360
|
}
|
|
4357
|
-
let c = o?.page || 0, l = o?.per_page || 50, u = c * l, d = await e.selectDistinct({ user_id:
|
|
4361
|
+
let c = o?.page || 0, l = o?.per_page || 50, u = c * l, d = await e.selectDistinct({ user_id: W.user_id }).from(W).where(s).orderBy(n(W.user_id)).limit(l).offset(u).all(), f = await e.select({ count: y`count(distinct ${W.user_id})` }).from(W).where(s).get();
|
|
4358
4362
|
return {
|
|
4359
4363
|
userIds: d.map((e) => e.user_id),
|
|
4360
4364
|
start: u,
|
|
@@ -4363,13 +4367,13 @@ function qr(e) {
|
|
|
4363
4367
|
};
|
|
4364
4368
|
},
|
|
4365
4369
|
async remove(n, r, i, o) {
|
|
4366
|
-
return (await e.delete(
|
|
4370
|
+
return (await e.delete(W).where(t(a(W.tenant_id, n), a(W.user_id, r), a(W.role_id, i), a(W.organization_id, o || ""))).returning()).length > 0;
|
|
4367
4371
|
}
|
|
4368
4372
|
};
|
|
4369
4373
|
}
|
|
4370
4374
|
//#endregion
|
|
4371
4375
|
//#region src/adapters/userOrganizations.ts
|
|
4372
|
-
function
|
|
4376
|
+
function Zr(e) {
|
|
4373
4377
|
return {
|
|
4374
4378
|
async create(t, n) {
|
|
4375
4379
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
@@ -4381,39 +4385,39 @@ function Jr(e) {
|
|
|
4381
4385
|
updated_at: r
|
|
4382
4386
|
};
|
|
4383
4387
|
try {
|
|
4384
|
-
await e.insert(
|
|
4388
|
+
await e.insert(H).values(i);
|
|
4385
4389
|
} catch (e) {
|
|
4386
|
-
throw e?.message?.includes("UNIQUE constraint") || e?.message?.includes("duplicate key") ? new
|
|
4390
|
+
throw e?.message?.includes("UNIQUE constraint") || e?.message?.includes("duplicate key") ? new Fe(409, { message: "User organization already exists" }) : e;
|
|
4387
4391
|
}
|
|
4388
4392
|
let { tenant_id: a, ...o } = i;
|
|
4389
4393
|
return o;
|
|
4390
4394
|
},
|
|
4391
4395
|
async get(n, r) {
|
|
4392
|
-
let i = await e.select().from(
|
|
4396
|
+
let i = await e.select().from(H).where(t(a(H.tenant_id, n), a(H.id, r))).get();
|
|
4393
4397
|
if (!i) return null;
|
|
4394
4398
|
let { tenant_id: o, ...s } = i;
|
|
4395
4399
|
return s;
|
|
4396
4400
|
},
|
|
4397
4401
|
async update(n, r, i) {
|
|
4398
4402
|
let o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
4399
|
-
return i.user_id !== void 0 && (o.user_id = i.user_id), i.organization_id !== void 0 && (o.organization_id = i.organization_id), (await e.update(
|
|
4403
|
+
return i.user_id !== void 0 && (o.user_id = i.user_id), i.organization_id !== void 0 && (o.organization_id = i.organization_id), (await e.update(H).set(o).where(t(a(H.tenant_id, n), a(H.id, r))).returning()).length > 0;
|
|
4400
4404
|
},
|
|
4401
4405
|
async list(n, o) {
|
|
4402
|
-
let { include_totals: s = !1, q: c } = o || {}, l = a(
|
|
4406
|
+
let { include_totals: s = !1, q: c } = o || {}, l = a(H.tenant_id, n), u = l;
|
|
4403
4407
|
if (c) {
|
|
4404
|
-
let e =
|
|
4408
|
+
let e = mt(H, c, ["user_id", "organization_id"]);
|
|
4405
4409
|
e && (u = t(l, e));
|
|
4406
4410
|
}
|
|
4407
4411
|
let d = (e) => {
|
|
4408
4412
|
let { tenant_id: t, ...n } = e;
|
|
4409
4413
|
return n;
|
|
4410
4414
|
};
|
|
4411
|
-
if (
|
|
4415
|
+
if (Et(o)) {
|
|
4412
4416
|
let n = {
|
|
4413
|
-
sortColumn:
|
|
4414
|
-
idColumn:
|
|
4417
|
+
sortColumn: H.created_at,
|
|
4418
|
+
idColumn: H.id,
|
|
4415
4419
|
sortOrder: "desc"
|
|
4416
|
-
}, r =
|
|
4420
|
+
}, r = kt(o, n), i = Dt(o), { rows: a, next: s } = At((await e.select().from(H).where(r ? t(u, r) : u).orderBy(...Ot(n)).limit(i + 1)).map(d), i, "created_at");
|
|
4417
4421
|
return {
|
|
4418
4422
|
userOrganizations: a,
|
|
4419
4423
|
start: 0,
|
|
@@ -4422,9 +4426,9 @@ function Jr(e) {
|
|
|
4422
4426
|
next: s
|
|
4423
4427
|
};
|
|
4424
4428
|
}
|
|
4425
|
-
let f = o?.page ?? 0, p = o?.per_page ?? 50, m = f * p, h = (await e.select().from(
|
|
4429
|
+
let f = o?.page ?? 0, p = o?.per_page ?? 50, m = f * p, h = (await e.select().from(H).where(u).orderBy(i(H.created_at), i(H.id)).offset(m).limit(p)).map(d);
|
|
4426
4430
|
if (!s) return { userOrganizations: h };
|
|
4427
|
-
let [g] = await e.select({ count: r() }).from(
|
|
4431
|
+
let [g] = await e.select({ count: r() }).from(H).where(u);
|
|
4428
4432
|
return {
|
|
4429
4433
|
userOrganizations: h,
|
|
4430
4434
|
start: m,
|
|
@@ -4433,20 +4437,20 @@ function Jr(e) {
|
|
|
4433
4437
|
};
|
|
4434
4438
|
},
|
|
4435
4439
|
async listUserOrganizations(n, i, o) {
|
|
4436
|
-
let { page: s = 0, per_page: c = 50, include_totals: l = !1 } = o || {}, u = await e.select().from(
|
|
4437
|
-
let i = await e.select().from(
|
|
4440
|
+
let { page: s = 0, per_page: c = 50, include_totals: l = !1 } = o || {}, u = await e.select().from(H).where(t(a(H.tenant_id, n), a(H.user_id, i))).offset(s * c).limit(c).all(), d = (await Promise.all(u.map(async (r) => {
|
|
4441
|
+
let i = await e.select().from(V).where(t(a(V.tenant_id, n), a(V.id, r.organization_id))).get();
|
|
4438
4442
|
if (!i) return null;
|
|
4439
4443
|
let { tenant_id: o, branding: s, metadata: c, enabled_connections: l, token_quota: u, ...d } = i;
|
|
4440
4444
|
return D({
|
|
4441
4445
|
...d,
|
|
4442
|
-
branding:
|
|
4443
|
-
metadata:
|
|
4444
|
-
enabled_connections:
|
|
4445
|
-
token_quota:
|
|
4446
|
+
branding: Z(s, {}),
|
|
4447
|
+
metadata: Z(c, {}),
|
|
4448
|
+
enabled_connections: Z(l, []),
|
|
4449
|
+
token_quota: Z(u, {})
|
|
4446
4450
|
});
|
|
4447
4451
|
}))).filter(Boolean);
|
|
4448
4452
|
if (!l) return { organizations: d };
|
|
4449
|
-
let [f] = await e.select({ count: r() }).from(
|
|
4453
|
+
let [f] = await e.select({ count: r() }).from(H).where(t(a(H.tenant_id, n), a(H.user_id, i)));
|
|
4450
4454
|
return {
|
|
4451
4455
|
organizations: d,
|
|
4452
4456
|
start: s * c,
|
|
@@ -4455,26 +4459,26 @@ function Jr(e) {
|
|
|
4455
4459
|
};
|
|
4456
4460
|
},
|
|
4457
4461
|
async remove(n, r) {
|
|
4458
|
-
return (await e.delete(
|
|
4462
|
+
return (await e.delete(H).where(t(a(H.tenant_id, n), a(H.id, r))).returning()).length > 0;
|
|
4459
4463
|
}
|
|
4460
4464
|
};
|
|
4461
4465
|
}
|
|
4462
4466
|
//#endregion
|
|
4463
4467
|
//#region src/adapters/stats.ts
|
|
4464
|
-
var
|
|
4465
|
-
function
|
|
4468
|
+
var Qr = ["s"], $r = ["pwd_leak"];
|
|
4469
|
+
function ei(e) {
|
|
4466
4470
|
return /^\d{8}$/.test(e) ? `${e.slice(0, 4)}-${e.slice(4, 6)}-${e.slice(6, 8)}` : e;
|
|
4467
4471
|
}
|
|
4468
|
-
function
|
|
4472
|
+
function ti(e) {
|
|
4469
4473
|
return {
|
|
4470
4474
|
async getDaily(n, r) {
|
|
4471
|
-
let i = /* @__PURE__ */ new Date(), o = r?.from ?
|
|
4475
|
+
let i = /* @__PURE__ */ new Date(), o = r?.from ? ei(r.from) : (/* @__PURE__ */ new Date(i.getTime() - 720 * 60 * 60 * 1e3)).toISOString().split("T")[0], s = r?.to ? ei(r.to) : i.toISOString().split("T")[0];
|
|
4472
4476
|
return (await e.select({
|
|
4473
|
-
date: y`substr(${
|
|
4474
|
-
logins: y`SUM(CASE WHEN ${
|
|
4475
|
-
signups: y`SUM(CASE WHEN ${
|
|
4476
|
-
leaked_passwords: y`SUM(CASE WHEN ${
|
|
4477
|
-
}).from(
|
|
4477
|
+
date: y`substr(${q.date}, 1, 10)`.as("date"),
|
|
4478
|
+
logins: y`SUM(CASE WHEN ${q.type} IN (${y.join(Qr.map((e) => y`${e}`), y`, `)}) THEN 1 ELSE 0 END)`.as("logins"),
|
|
4479
|
+
signups: y`SUM(CASE WHEN ${q.type} = 'ss' THEN 1 ELSE 0 END)`.as("signups"),
|
|
4480
|
+
leaked_passwords: y`SUM(CASE WHEN ${q.type} IN (${y.join($r.map((e) => y`${e}`), y`, `)}) THEN 1 ELSE 0 END)`.as("leaked_passwords")
|
|
4481
|
+
}).from(q).where(t(a(q.tenant_id, n), c(q.date, o), h(q.date, `${s}T23:59:59.999Z`))).groupBy(y`substr(${q.date}, 1, 10)`).orderBy(y`substr(${q.date}, 1, 10)`).all()).map((e) => ({
|
|
4478
4482
|
date: e.date,
|
|
4479
4483
|
logins: Number(e.logins) || 0,
|
|
4480
4484
|
signups: Number(e.signups) || 0,
|
|
@@ -4484,14 +4488,14 @@ function Qr(e) {
|
|
|
4484
4488
|
}));
|
|
4485
4489
|
},
|
|
4486
4490
|
async getActiveUsers(n) {
|
|
4487
|
-
let r = (/* @__PURE__ */ new Date(Date.now() - 720 * 60 * 60 * 1e3)).toISOString(), [i] = await e.select({ count: y`COUNT(DISTINCT ${
|
|
4491
|
+
let r = (/* @__PURE__ */ new Date(Date.now() - 720 * 60 * 60 * 1e3)).toISOString(), [i] = await e.select({ count: y`COUNT(DISTINCT ${q.user_id})`.as("count") }).from(q).where(t(a(q.tenant_id, n), c(q.date, r), y`${q.type} IN (${y.join(Qr.map((e) => y`${e}`), y`, `)})`));
|
|
4488
4492
|
return Number(i?.count) || 0;
|
|
4489
4493
|
}
|
|
4490
4494
|
};
|
|
4491
4495
|
}
|
|
4492
4496
|
//#endregion
|
|
4493
4497
|
//#region src/adapters/analytics.ts
|
|
4494
|
-
var
|
|
4498
|
+
var ni = {
|
|
4495
4499
|
"active-users": ["s", "seacft"],
|
|
4496
4500
|
logins: [
|
|
4497
4501
|
"s",
|
|
@@ -4521,7 +4525,7 @@ var $r = {
|
|
|
4521
4525
|
"fvr"
|
|
4522
4526
|
],
|
|
4523
4527
|
"codes-sent": ["cls", "cs"]
|
|
4524
|
-
},
|
|
4528
|
+
}, ri = {
|
|
4525
4529
|
"active-users": {
|
|
4526
4530
|
alias: "active_users",
|
|
4527
4531
|
type: "UInt64",
|
|
@@ -4578,64 +4582,64 @@ var $r = {
|
|
|
4578
4582
|
agg: "count"
|
|
4579
4583
|
}
|
|
4580
4584
|
};
|
|
4581
|
-
function
|
|
4585
|
+
function ii(e) {
|
|
4582
4586
|
switch (e) {
|
|
4583
|
-
case "hour": return y`substr(${
|
|
4584
|
-
case "month": return y`substr(${
|
|
4585
|
-
case "day": return y`substr(${
|
|
4586
|
-
case "week": return y`date(substr(${
|
|
4587
|
+
case "hour": return y`substr(${q.date}, 1, 13)`;
|
|
4588
|
+
case "month": return y`substr(${q.date}, 1, 7)`;
|
|
4589
|
+
case "day": return y`substr(${q.date}, 1, 10)`;
|
|
4590
|
+
case "week": return y`date(substr(${q.date}, 1, 10), '-' || ((cast(strftime('%w', substr(${q.date}, 1, 10)) as integer) + 6) % 7) || ' days')`;
|
|
4587
4591
|
default: throw Error(`Unsupported interval '${e}' for SQL analytics adapter`);
|
|
4588
4592
|
}
|
|
4589
4593
|
}
|
|
4590
|
-
function
|
|
4594
|
+
function ai(e) {
|
|
4591
4595
|
return `"${e.replace(/"/g, "\"\"")}"`;
|
|
4592
4596
|
}
|
|
4593
|
-
function
|
|
4597
|
+
function oi(e) {
|
|
4594
4598
|
switch (e) {
|
|
4595
|
-
case "connection": return
|
|
4596
|
-
case "client_id": return
|
|
4597
|
-
case "user_type": return
|
|
4598
|
-
case "event": return
|
|
4599
|
+
case "connection": return q.connection;
|
|
4600
|
+
case "client_id": return q.client_id;
|
|
4601
|
+
case "user_type": return q.strategy_type;
|
|
4602
|
+
case "event": return q.type;
|
|
4599
4603
|
case "time": throw Error("time dimension handled separately");
|
|
4600
4604
|
}
|
|
4601
4605
|
}
|
|
4602
|
-
function
|
|
4606
|
+
function si(e) {
|
|
4603
4607
|
return {
|
|
4604
4608
|
async query(n, r, i) {
|
|
4605
|
-
let o = Date.now(), s =
|
|
4606
|
-
a(
|
|
4607
|
-
c(
|
|
4608
|
-
m(
|
|
4609
|
-
l(
|
|
4609
|
+
let o = Date.now(), s = ni[r], u = ri[r], d = [
|
|
4610
|
+
a(q.tenant_id, n),
|
|
4611
|
+
c(q.date, i.from),
|
|
4612
|
+
m(q.date, i.to),
|
|
4613
|
+
l(q.type, s)
|
|
4610
4614
|
];
|
|
4611
|
-
i.filters.connection?.length && d.push(l(
|
|
4615
|
+
i.filters.connection?.length && d.push(l(q.connection, i.filters.connection)), i.filters.client_id?.length && d.push(l(q.client_id, i.filters.client_id)), i.filters.user_type?.length && d.push(l(q.strategy_type, i.filters.user_type)), i.filters.user_id?.length && d.push(l(q.user_id, i.filters.user_id));
|
|
4612
4616
|
let f = {}, p = [], h = [];
|
|
4613
4617
|
for (let e of i.group_by) if (e === "time") {
|
|
4614
|
-
let e =
|
|
4618
|
+
let e = ii(i.interval);
|
|
4615
4619
|
f.time = e, p.push(e), h.push({
|
|
4616
4620
|
name: "time",
|
|
4617
4621
|
type: i.interval === "hour" ? "DateTime" : "Date"
|
|
4618
4622
|
});
|
|
4619
4623
|
} else {
|
|
4620
|
-
let t =
|
|
4624
|
+
let t = oi(e);
|
|
4621
4625
|
f[e] = t, p.push(t), h.push({
|
|
4622
4626
|
name: e,
|
|
4623
4627
|
type: "String"
|
|
4624
4628
|
});
|
|
4625
4629
|
}
|
|
4626
|
-
f[u.alias] = u.agg === "uniq" ? y`COUNT(DISTINCT ${
|
|
4630
|
+
f[u.alias] = u.agg === "uniq" ? y`COUNT(DISTINCT ${q.user_id})` : y`COUNT(*)`, h.push({
|
|
4627
4631
|
name: u.alias,
|
|
4628
4632
|
type: u.type
|
|
4629
4633
|
});
|
|
4630
|
-
let g = e.select(f).from(
|
|
4634
|
+
let g = e.select(f).from(q).where(t(...d));
|
|
4631
4635
|
p.length > 0 && (g = g.groupBy(...p));
|
|
4632
4636
|
let _ = new Set([...Object.keys(f)]);
|
|
4633
4637
|
if (i.order_by) {
|
|
4634
4638
|
let e = i.order_by.startsWith("-"), t = e ? i.order_by.slice(1) : i.order_by;
|
|
4635
4639
|
if (!_.has(t)) throw Error(`Invalid order_by column '${t}' for analytics query`);
|
|
4636
|
-
let n =
|
|
4640
|
+
let n = ai(t);
|
|
4637
4641
|
g = g.orderBy(y.raw(`${n} ${e ? "DESC" : "ASC"}`));
|
|
4638
|
-
} else g = i.group_by[0] === "time" ? g.orderBy(y.raw(`${
|
|
4642
|
+
} else g = i.group_by[0] === "time" ? g.orderBy(y.raw(`${ai("time")} ASC`)) : g.orderBy(y.raw(`${ai(u.alias)} DESC`));
|
|
4639
4643
|
g = g.limit(i.limit).offset(i.offset);
|
|
4640
4644
|
let v = (await g.all()).map((e) => {
|
|
4641
4645
|
let t = {};
|
|
@@ -4654,22 +4658,22 @@ function ii(e) {
|
|
|
4654
4658
|
};
|
|
4655
4659
|
},
|
|
4656
4660
|
async sessionRetention(n, r) {
|
|
4657
|
-
let i = Date.now(), { sinceMs: o } = Ee(r.weeks, i), s = y`(${
|
|
4661
|
+
let i = Date.now(), { sinceMs: o } = Ee(r.weeks, i), s = y`(${M.created_at_ts} + ${ue}) / ${de}`, l = y`(COALESCE(${M.used_at_ts}, ${M.created_at_ts}) + ${ue}) / ${de}`;
|
|
4658
4662
|
return pe((await e.select({
|
|
4659
4663
|
created_week: s,
|
|
4660
4664
|
used_week: l,
|
|
4661
4665
|
count: y`COUNT(*)`
|
|
4662
|
-
}).from(
|
|
4666
|
+
}).from(M).where(t(a(M.tenant_id, n), c(M.created_at_ts, o))).groupBy(s, l).all()).map((e) => ({
|
|
4663
4667
|
created_week: Math.floor(Number(e.created_week)),
|
|
4664
4668
|
used_week: Math.floor(Number(e.used_week)),
|
|
4665
4669
|
count: Number(e.count)
|
|
4666
4670
|
})), r.weeks, i);
|
|
4667
4671
|
},
|
|
4668
4672
|
async refreshTokenRetention(n, r) {
|
|
4669
|
-
let i = Date.now(), { sinceMs: o } = Ee(r.weeks, i), s = r.client_id && r.client_id.length > 0 ? l(
|
|
4670
|
-
min_created: y`MIN(${
|
|
4671
|
-
max_used: y`MAX(COALESCE(${
|
|
4672
|
-
}).from(
|
|
4673
|
+
let i = Date.now(), { sinceMs: o } = Ee(r.weeks, i), s = r.client_id && r.client_id.length > 0 ? l(N.client_id, r.client_id) : void 0, u = e.select({
|
|
4674
|
+
min_created: y`MIN(${N.created_at_ts})`.as("min_created"),
|
|
4675
|
+
max_used: y`MAX(COALESCE(${N.last_exchanged_at_ts}, ${N.created_at_ts}))`.as("max_used")
|
|
4676
|
+
}).from(N).where(t(a(N.tenant_id, n), s)).groupBy(y`COALESCE(${N.family_id}, ${N.id})`).as("families"), d = y`(${u.min_created} + ${ue}) / ${de}`, f = y`(${u.max_used} + ${ue}) / ${de}`;
|
|
4673
4677
|
return fe((await e.select({
|
|
4674
4678
|
created_week: d,
|
|
4675
4679
|
used_week: f,
|
|
@@ -4684,13 +4688,13 @@ function ii(e) {
|
|
|
4684
4688
|
}
|
|
4685
4689
|
//#endregion
|
|
4686
4690
|
//#region src/adapters/cleanup.ts
|
|
4687
|
-
var
|
|
4688
|
-
function
|
|
4691
|
+
var ci = 10080 * 60 * 1e3;
|
|
4692
|
+
function li(e) {
|
|
4689
4693
|
return async (n) => {
|
|
4690
|
-
let r = Date.now() -
|
|
4694
|
+
let r = Date.now() - ci;
|
|
4691
4695
|
try {
|
|
4692
|
-
let i = [v(m(
|
|
4693
|
-
n?.tenant_id && i.push(a(
|
|
4696
|
+
let i = [v(m(N.expires_at_ts, r), m(N.idle_expires_at_ts, r))];
|
|
4697
|
+
n?.tenant_id && i.push(a(N.tenant_id, n.tenant_id)), await e.delete(N).where(t(...i)), i = [v(m(M.expires_at_ts, r), m(M.idle_expires_at_ts, r))], n?.tenant_id && i.push(a(M.tenant_id, n.tenant_id)), n?.user_id && i.push(a(M.user_id, n.user_id)), await e.delete(M).where(t(...i)), i = [m(P.expires_at_ts, r)], n?.tenant_id && i.push(a(P.tenant_id, n.tenant_id)), await e.delete(P).where(t(...i));
|
|
4694
4698
|
} catch (e) {
|
|
4695
4699
|
console.error("Session cleanup error:", e);
|
|
4696
4700
|
}
|
|
@@ -4698,7 +4702,7 @@ function oi(e) {
|
|
|
4698
4702
|
}
|
|
4699
4703
|
//#endregion
|
|
4700
4704
|
//#region src/schema/control-plane/tenantOperations.ts
|
|
4701
|
-
var
|
|
4705
|
+
var Q = w("tenant_operations", {
|
|
4702
4706
|
id: T("id", { length: 255 }).primaryKey(),
|
|
4703
4707
|
tenant_id: T("tenant_id", { length: 255 }),
|
|
4704
4708
|
rollout_id: T("rollout_id", { length: 255 }),
|
|
@@ -4711,6 +4715,10 @@ var $ = w("tenant_operations", {
|
|
|
4711
4715
|
target_database_version: T("target_database_version", { length: 255 }),
|
|
4712
4716
|
error: T("error"),
|
|
4713
4717
|
initiated_by: T("initiated_by", { length: 255 }),
|
|
4718
|
+
input: T("input"),
|
|
4719
|
+
result: T("result"),
|
|
4720
|
+
claimed_by: T("claimed_by", { length: 255 }),
|
|
4721
|
+
claim_expires_at: T("claim_expires_at", { length: 35 }),
|
|
4714
4722
|
created_at: T("created_at", { length: 35 }).notNull(),
|
|
4715
4723
|
updated_at: T("updated_at", { length: 35 }).notNull(),
|
|
4716
4724
|
finished_at: T("finished_at", { length: 35 })
|
|
@@ -4718,7 +4726,7 @@ var $ = w("tenant_operations", {
|
|
|
4718
4726
|
x("tenant_operations_tenant_id_created_at_idx").on(e.tenant_id, e.created_at),
|
|
4719
4727
|
x("tenant_operations_rollout_id_idx").on(e.rollout_id),
|
|
4720
4728
|
x("tenant_operations_status_idx").on(e.status)
|
|
4721
|
-
]),
|
|
4729
|
+
]), ui = w("tenant_operation_events", {
|
|
4722
4730
|
id: T("id", { length: 255 }).primaryKey(),
|
|
4723
4731
|
operation_id: T("operation_id", { length: 255 }).notNull(),
|
|
4724
4732
|
step: T("step", { length: 255 }).notNull(),
|
|
@@ -4728,9 +4736,28 @@ var $ = w("tenant_operations", {
|
|
|
4728
4736
|
created_at: T("created_at", { length: 35 }).notNull()
|
|
4729
4737
|
}, (e) => [ne({
|
|
4730
4738
|
columns: [e.operation_id],
|
|
4731
|
-
foreignColumns: [
|
|
4739
|
+
foreignColumns: [Q.id],
|
|
4732
4740
|
name: "tenant_operation_events_operation_id_constraint"
|
|
4733
|
-
}).onDelete("cascade"), x("tenant_operation_events_operation_id_created_at_idx").on(e.operation_id, e.created_at)]),
|
|
4741
|
+
}).onDelete("cascade"), x("tenant_operation_events_operation_id_created_at_idx").on(e.operation_id, e.created_at)]), $ = w("tenant_operation_rows", {
|
|
4742
|
+
operation_id: T("operation_id", { length: 255 }).notNull(),
|
|
4743
|
+
seq: S("seq").notNull(),
|
|
4744
|
+
payload: T("payload").notNull(),
|
|
4745
|
+
status: T("status", { length: 32 }).notNull(),
|
|
4746
|
+
error_code: T("error_code", { length: 64 }),
|
|
4747
|
+
error_message: T("error_message"),
|
|
4748
|
+
error_path: T("error_path", { length: 255 }),
|
|
4749
|
+
entity_id: T("entity_id", { length: 255 }),
|
|
4750
|
+
created_at: T("created_at", { length: 35 }).notNull(),
|
|
4751
|
+
updated_at: T("updated_at", { length: 35 }).notNull()
|
|
4752
|
+
}, (e) => [
|
|
4753
|
+
C({ columns: [e.operation_id, e.seq] }),
|
|
4754
|
+
ne({
|
|
4755
|
+
columns: [e.operation_id],
|
|
4756
|
+
foreignColumns: [Q.id],
|
|
4757
|
+
name: "tenant_operation_rows_operation_id_constraint"
|
|
4758
|
+
}).onDelete("cascade"),
|
|
4759
|
+
x("tenant_operation_rows_operation_id_status_idx").on(e.operation_id, e.status)
|
|
4760
|
+
]), di = w("rollouts", {
|
|
4734
4761
|
id: T("id", { length: 255 }).primaryKey(),
|
|
4735
4762
|
kind: T("kind", { length: 32 }).notNull(),
|
|
4736
4763
|
status: T("status", { length: 32 }).notNull(),
|
|
@@ -4746,8 +4773,16 @@ var $ = w("tenant_operations", {
|
|
|
4746
4773
|
});
|
|
4747
4774
|
//#endregion
|
|
4748
4775
|
//#region src/adapters/tenantOperations.ts
|
|
4749
|
-
function
|
|
4750
|
-
return
|
|
4776
|
+
function fi(e) {
|
|
4777
|
+
if (!e) return null;
|
|
4778
|
+
try {
|
|
4779
|
+
return JSON.parse(e);
|
|
4780
|
+
} catch {
|
|
4781
|
+
return null;
|
|
4782
|
+
}
|
|
4783
|
+
}
|
|
4784
|
+
function pi(e) {
|
|
4785
|
+
return Ne.parse({
|
|
4751
4786
|
id: e.id,
|
|
4752
4787
|
tenant_id: e.tenant_id,
|
|
4753
4788
|
rollout_id: e.rollout_id,
|
|
@@ -4760,12 +4795,16 @@ function li(e) {
|
|
|
4760
4795
|
target_database_version: e.target_database_version,
|
|
4761
4796
|
error: e.error,
|
|
4762
4797
|
initiated_by: e.initiated_by,
|
|
4798
|
+
input: fi(e.input),
|
|
4799
|
+
result: fi(e.result),
|
|
4800
|
+
claimed_by: e.claimed_by,
|
|
4801
|
+
claim_expires_at: e.claim_expires_at,
|
|
4763
4802
|
created_at: e.created_at,
|
|
4764
4803
|
updated_at: e.updated_at,
|
|
4765
4804
|
finished_at: e.finished_at
|
|
4766
4805
|
});
|
|
4767
4806
|
}
|
|
4768
|
-
function
|
|
4807
|
+
function mi(e) {
|
|
4769
4808
|
return {
|
|
4770
4809
|
async create(t) {
|
|
4771
4810
|
let n = Ae.parse(t), r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
@@ -4781,67 +4820,210 @@ function ui(e) {
|
|
|
4781
4820
|
target_database_version: n.target_database_version ?? null,
|
|
4782
4821
|
error: null,
|
|
4783
4822
|
initiated_by: n.initiated_by ?? null,
|
|
4823
|
+
input: n.input ? JSON.stringify(n.input) : null,
|
|
4824
|
+
result: null,
|
|
4825
|
+
claimed_by: null,
|
|
4826
|
+
claim_expires_at: null,
|
|
4784
4827
|
created_at: r,
|
|
4785
4828
|
updated_at: r,
|
|
4786
4829
|
finished_at: null
|
|
4787
4830
|
};
|
|
4788
|
-
await e.insert(
|
|
4831
|
+
await e.insert(Q).values(i);
|
|
4789
4832
|
let a = await this.get(i.id);
|
|
4790
4833
|
if (!a) throw Error(`Failed to create tenant operation ${i.id}`);
|
|
4791
4834
|
return a;
|
|
4792
4835
|
},
|
|
4793
4836
|
async get(t) {
|
|
4794
|
-
let n = await e.select().from(
|
|
4795
|
-
return n[0] ?
|
|
4837
|
+
let n = await e.select().from(Q).where(a(Q.id, t)).limit(1);
|
|
4838
|
+
return n[0] ? pi(n[0]) : null;
|
|
4796
4839
|
},
|
|
4797
4840
|
async list(n = {}) {
|
|
4798
4841
|
let r = n.page ?? 0, o = n.per_page ?? 50, s = [];
|
|
4799
|
-
if (n.tenant_id !== void 0 && s.push(a(
|
|
4842
|
+
if (n.tenant_id !== void 0 && s.push(a(Q.tenant_id, n.tenant_id)), n.rollout_id !== void 0 && s.push(a(Q.rollout_id, n.rollout_id)), n.kind !== void 0 && s.push(a(Q.kind, n.kind)), n.status !== void 0) {
|
|
4800
4843
|
let e = Array.isArray(n.status) ? n.status : [n.status];
|
|
4801
|
-
s.push(l(
|
|
4844
|
+
s.push(l(Q.status, e));
|
|
4802
4845
|
}
|
|
4803
|
-
n.engine !== void 0 && s.push(a(
|
|
4804
|
-
let c = await e.select().from(
|
|
4846
|
+
n.engine !== void 0 && s.push(a(Q.engine, n.engine)), n.updated_before !== void 0 && s.push(m(Q.updated_at, n.updated_before));
|
|
4847
|
+
let c = await e.select().from(Q).where(s.length ? t(...s) : void 0).orderBy(i(Q.created_at), i(Q.id)).offset(r * o).limit(o);
|
|
4805
4848
|
return {
|
|
4806
|
-
operations: c.map(
|
|
4849
|
+
operations: c.map(pi),
|
|
4807
4850
|
start: r * o,
|
|
4808
4851
|
limit: o,
|
|
4809
4852
|
length: c.length
|
|
4810
4853
|
};
|
|
4811
4854
|
},
|
|
4812
4855
|
async update(t, n) {
|
|
4813
|
-
if ((await e.select({ id:
|
|
4856
|
+
if ((await e.select({ id: Q.id }).from(Q).where(a(Q.id, t)).limit(1)).length === 0) return !1;
|
|
4814
4857
|
let r = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
4815
|
-
return n.status !== void 0 && (r.status = n.status), n.current_step !== void 0 && (r.current_step = n.current_step), n.engine_instance_id !== void 0 && (r.engine_instance_id = n.engine_instance_id), n.target_worker_version !== void 0 && (r.target_worker_version = n.target_worker_version), n.target_database_version !== void 0 && (r.target_database_version = n.target_database_version), n.error !== void 0 && (r.error = n.error), n.finished_at !== void 0 && (r.finished_at = n.finished_at), await e.update(
|
|
4858
|
+
return n.status !== void 0 && (r.status = n.status), n.current_step !== void 0 && (r.current_step = n.current_step), n.engine_instance_id !== void 0 && (r.engine_instance_id = n.engine_instance_id), n.target_worker_version !== void 0 && (r.target_worker_version = n.target_worker_version), n.target_database_version !== void 0 && (r.target_database_version = n.target_database_version), n.error !== void 0 && (r.error = n.error), n.result !== void 0 && (r.result = n.result ? JSON.stringify(n.result) : null), n.claimed_by !== void 0 && (r.claimed_by = n.claimed_by), n.claim_expires_at !== void 0 && (r.claim_expires_at = n.claim_expires_at), n.finished_at !== void 0 && (r.finished_at = n.finished_at), await e.update(Q).set(r).where(a(Q.id, t)), !0;
|
|
4859
|
+
},
|
|
4860
|
+
async claim(n, r, i) {
|
|
4861
|
+
let o = (/* @__PURE__ */ new Date()).toISOString(), s = new Date(Date.now() + i).toISOString();
|
|
4862
|
+
return await e.update(Q).set({
|
|
4863
|
+
claimed_by: r,
|
|
4864
|
+
claim_expires_at: s
|
|
4865
|
+
}).where(t(a(Q.id, n), v(f(Q.claimed_by), h(Q.claim_expires_at, o), a(Q.claimed_by, r)))), (await e.select({ id: Q.id }).from(Q).where(t(a(Q.id, n), a(Q.claimed_by, r), a(Q.claim_expires_at, s))).limit(1)).length > 0;
|
|
4866
|
+
},
|
|
4867
|
+
async release(n, r) {
|
|
4868
|
+
return (await e.select({ id: Q.id }).from(Q).where(t(a(Q.id, n), a(Q.claimed_by, r))).limit(1)).length === 0 ? !1 : (await e.update(Q).set({
|
|
4869
|
+
claimed_by: null,
|
|
4870
|
+
claim_expires_at: null
|
|
4871
|
+
}).where(t(a(Q.id, n), a(Q.claimed_by, r))), !0);
|
|
4872
|
+
},
|
|
4873
|
+
async listResumable(r) {
|
|
4874
|
+
let i = (/* @__PURE__ */ new Date()).toISOString();
|
|
4875
|
+
return (await e.select().from(Q).where(t(l(Q.status, ["pending", "running"]), a(Q.kind, r.kind), v(f(Q.claimed_by), h(Q.claim_expires_at, i)))).orderBy(n(Q.created_at), n(Q.id)).limit(r.limit)).map(pi);
|
|
4816
4876
|
},
|
|
4817
4877
|
async remove(t) {
|
|
4818
|
-
return (await e.select({ id:
|
|
4878
|
+
return (await e.select({ id: Q.id }).from(Q).where(a(Q.id, t)).limit(1)).length === 0 ? !1 : (await e.delete(Q).where(a(Q.id, t)), !0);
|
|
4879
|
+
}
|
|
4880
|
+
};
|
|
4881
|
+
}
|
|
4882
|
+
//#endregion
|
|
4883
|
+
//#region src/adapters/tenantOperationRows.ts
|
|
4884
|
+
var hi = 50, gi = 50;
|
|
4885
|
+
function _i(e) {
|
|
4886
|
+
try {
|
|
4887
|
+
return JSON.parse(e);
|
|
4888
|
+
} catch {
|
|
4889
|
+
return {};
|
|
4890
|
+
}
|
|
4891
|
+
}
|
|
4892
|
+
function vi(e) {
|
|
4893
|
+
return Me.parse({
|
|
4894
|
+
operation_id: e.operation_id,
|
|
4895
|
+
seq: e.seq,
|
|
4896
|
+
payload: _i(e.payload),
|
|
4897
|
+
status: e.status,
|
|
4898
|
+
error_code: e.error_code,
|
|
4899
|
+
error_message: e.error_message,
|
|
4900
|
+
error_path: e.error_path,
|
|
4901
|
+
entity_id: e.entity_id,
|
|
4902
|
+
created_at: e.created_at,
|
|
4903
|
+
updated_at: e.updated_at
|
|
4904
|
+
});
|
|
4905
|
+
}
|
|
4906
|
+
function yi(e, t) {
|
|
4907
|
+
let n = [];
|
|
4908
|
+
for (let r = 0; r < e.length; r += t) n.push(e.slice(r, r + t));
|
|
4909
|
+
return n;
|
|
4910
|
+
}
|
|
4911
|
+
function bi(e, n, r, i) {
|
|
4912
|
+
return e.update($).set({
|
|
4913
|
+
status: r.status,
|
|
4914
|
+
error_code: r.error_code ?? null,
|
|
4915
|
+
error_message: r.error_message ?? null,
|
|
4916
|
+
error_path: r.error_path ?? null,
|
|
4917
|
+
entity_id: r.entity_id ?? null,
|
|
4918
|
+
updated_at: i
|
|
4919
|
+
}).where(t(a($.operation_id, n), a($.seq, r.seq), a($.status, "pending")));
|
|
4920
|
+
}
|
|
4921
|
+
function xi(e) {
|
|
4922
|
+
return {
|
|
4923
|
+
async createMany(t) {
|
|
4924
|
+
if (t.length === 0) return 0;
|
|
4925
|
+
let n = (/* @__PURE__ */ new Date()).toISOString(), r = t.map((e) => {
|
|
4926
|
+
let t = je.parse(e);
|
|
4927
|
+
return {
|
|
4928
|
+
operation_id: t.operation_id,
|
|
4929
|
+
seq: t.seq,
|
|
4930
|
+
payload: JSON.stringify(t.payload),
|
|
4931
|
+
status: t.status,
|
|
4932
|
+
error_code: t.error_code ?? null,
|
|
4933
|
+
error_message: t.error_message ?? null,
|
|
4934
|
+
error_path: t.error_path ?? null,
|
|
4935
|
+
entity_id: t.entity_id ?? null,
|
|
4936
|
+
created_at: n,
|
|
4937
|
+
updated_at: n
|
|
4938
|
+
};
|
|
4939
|
+
});
|
|
4940
|
+
for (let t of yi(r, hi)) await e.insert($).values(t);
|
|
4941
|
+
return r.length;
|
|
4942
|
+
},
|
|
4943
|
+
async claimPending(r, i) {
|
|
4944
|
+
return (await e.select().from($).where(t(a($.operation_id, r), a($.status, "pending"))).orderBy(n($.seq)).limit(i)).map(vi);
|
|
4945
|
+
},
|
|
4946
|
+
async recordOutcomes(n, r) {
|
|
4947
|
+
if (r.length === 0) return 0;
|
|
4948
|
+
let i = (/* @__PURE__ */ new Date()).toISOString(), o = r.map((e) => e.seq), s = /* @__PURE__ */ new Set();
|
|
4949
|
+
for (let r of yi(o, gi)) {
|
|
4950
|
+
let i = await e.select({ seq: $.seq }).from($).where(t(a($.operation_id, n), a($.status, "pending"), l($.seq, r)));
|
|
4951
|
+
for (let e of i) s.add(e.seq);
|
|
4952
|
+
}
|
|
4953
|
+
let c = r.filter((e) => s.has(e.seq));
|
|
4954
|
+
if (c.length === 0) return 0;
|
|
4955
|
+
for (let t of yi(c, gi)) {
|
|
4956
|
+
let [r, ...a] = t.map((t) => bi(e, n, t, i));
|
|
4957
|
+
r && await xt(e, [r, ...a]);
|
|
4958
|
+
}
|
|
4959
|
+
return c.length;
|
|
4960
|
+
},
|
|
4961
|
+
async countByStatus(t) {
|
|
4962
|
+
let n = await e.select({
|
|
4963
|
+
status: $.status,
|
|
4964
|
+
total: r()
|
|
4965
|
+
}).from($).where(a($.operation_id, t)).groupBy($.status), i = {
|
|
4966
|
+
total: 0,
|
|
4967
|
+
pending: 0,
|
|
4968
|
+
inserted: 0,
|
|
4969
|
+
updated: 0,
|
|
4970
|
+
failed: 0,
|
|
4971
|
+
skipped: 0
|
|
4972
|
+
};
|
|
4973
|
+
for (let e of n) switch (i.total += e.total, e.status) {
|
|
4974
|
+
case "pending":
|
|
4975
|
+
case "inserted":
|
|
4976
|
+
case "updated":
|
|
4977
|
+
case "failed":
|
|
4978
|
+
case "skipped":
|
|
4979
|
+
i[e.status] += e.total;
|
|
4980
|
+
break;
|
|
4981
|
+
}
|
|
4982
|
+
return i;
|
|
4983
|
+
},
|
|
4984
|
+
async list(r, i = {}) {
|
|
4985
|
+
let o = i.page ?? 0, s = i.per_page ?? 50, c = [a($.operation_id, r)];
|
|
4986
|
+
if (i.status !== void 0) {
|
|
4987
|
+
let e = Array.isArray(i.status) ? i.status : [i.status];
|
|
4988
|
+
c.push(l($.status, e));
|
|
4989
|
+
}
|
|
4990
|
+
let u = await e.select().from($).where(t(...c)).orderBy(n($.seq)).offset(o * s).limit(s);
|
|
4991
|
+
return {
|
|
4992
|
+
rows: u.map(vi),
|
|
4993
|
+
start: o * s,
|
|
4994
|
+
limit: s,
|
|
4995
|
+
length: u.length
|
|
4996
|
+
};
|
|
4997
|
+
},
|
|
4998
|
+
async removeByOperation(t) {
|
|
4999
|
+
let n = await e.select({ seq: $.seq }).from($).where(a($.operation_id, t));
|
|
5000
|
+
return n.length === 0 ? 0 : (await e.delete($).where(a($.operation_id, t)), n.length);
|
|
4819
5001
|
}
|
|
4820
5002
|
};
|
|
4821
5003
|
}
|
|
4822
5004
|
//#endregion
|
|
4823
5005
|
//#region src/helpers/monotonic-id.ts
|
|
4824
|
-
var
|
|
4825
|
-
function
|
|
5006
|
+
var Si = "0123456789ABCDEFGHJKMNPQRSTVWXYZ", Ci = 32, wi = 10, Ti = 4, Ei = 10;
|
|
5007
|
+
function Di(e, t) {
|
|
4826
5008
|
let n = "";
|
|
4827
|
-
for (let r = t; r > 0; r--) n =
|
|
5009
|
+
for (let r = t; r > 0; r--) n = Si.charAt(e % Ci) + n, e = Math.floor(e / Ci);
|
|
4828
5010
|
return n;
|
|
4829
5011
|
}
|
|
4830
|
-
function
|
|
4831
|
-
let e = new Uint8Array(
|
|
5012
|
+
function Oi() {
|
|
5013
|
+
let e = new Uint8Array(Ei);
|
|
4832
5014
|
crypto.getRandomValues(e);
|
|
4833
5015
|
let t = "";
|
|
4834
|
-
for (let n = 0; n <
|
|
5016
|
+
for (let n = 0; n < Ei; n++) t += Si.charAt(e[n] % Ci);
|
|
4835
5017
|
return t;
|
|
4836
5018
|
}
|
|
4837
|
-
var
|
|
4838
|
-
function
|
|
5019
|
+
var ki = 0, Ai = 0;
|
|
5020
|
+
function ji() {
|
|
4839
5021
|
let e = Date.now();
|
|
4840
|
-
return e ===
|
|
5022
|
+
return e === ki ? Ai++ : (ki = e, Ai = 0), Di(e, wi) + Di(Ai, Ti) + Oi();
|
|
4841
5023
|
}
|
|
4842
5024
|
//#endregion
|
|
4843
5025
|
//#region src/adapters/tenantOperationEvents.ts
|
|
4844
|
-
function
|
|
5026
|
+
function Mi(e) {
|
|
4845
5027
|
if (!e) return null;
|
|
4846
5028
|
try {
|
|
4847
5029
|
let t = JSON.parse(e);
|
|
@@ -4849,22 +5031,22 @@ function xi(e) {
|
|
|
4849
5031
|
} catch {}
|
|
4850
5032
|
return null;
|
|
4851
5033
|
}
|
|
4852
|
-
function
|
|
5034
|
+
function Ni(e) {
|
|
4853
5035
|
return ke.parse({
|
|
4854
5036
|
id: e.id,
|
|
4855
5037
|
operation_id: e.operation_id,
|
|
4856
5038
|
step: e.step,
|
|
4857
5039
|
outcome: e.outcome,
|
|
4858
|
-
detail:
|
|
5040
|
+
detail: Mi(e.detail),
|
|
4859
5041
|
attempt: e.attempt,
|
|
4860
5042
|
created_at: e.created_at
|
|
4861
5043
|
});
|
|
4862
5044
|
}
|
|
4863
|
-
function
|
|
5045
|
+
function Pi(e) {
|
|
4864
5046
|
return {
|
|
4865
5047
|
async create(t) {
|
|
4866
5048
|
let n = Oe.parse(t), r = {
|
|
4867
|
-
id: `evt_${
|
|
5049
|
+
id: `evt_${ji()}`,
|
|
4868
5050
|
operation_id: n.operation_id,
|
|
4869
5051
|
step: n.step,
|
|
4870
5052
|
outcome: n.outcome,
|
|
@@ -4872,7 +5054,7 @@ function Ci(e) {
|
|
|
4872
5054
|
attempt: n.attempt,
|
|
4873
5055
|
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
4874
5056
|
};
|
|
4875
|
-
return await e.insert(
|
|
5057
|
+
return await e.insert(ui).values(r), ke.parse({
|
|
4876
5058
|
id: r.id,
|
|
4877
5059
|
operation_id: r.operation_id,
|
|
4878
5060
|
step: r.step,
|
|
@@ -4883,9 +5065,9 @@ function Ci(e) {
|
|
|
4883
5065
|
});
|
|
4884
5066
|
},
|
|
4885
5067
|
async listByOperation(t, r = {}) {
|
|
4886
|
-
let i = r.page ?? 0, o = r.per_page ?? 100, s = await e.select().from(
|
|
5068
|
+
let i = r.page ?? 0, o = r.per_page ?? 100, s = await e.select().from(ui).where(a(ui.operation_id, t)).orderBy(n(ui.created_at), n(ui.id)).offset(i * o).limit(o);
|
|
4887
5069
|
return {
|
|
4888
|
-
events: s.map(
|
|
5070
|
+
events: s.map(Ni),
|
|
4889
5071
|
start: i * o,
|
|
4890
5072
|
limit: o,
|
|
4891
5073
|
length: s.length
|
|
@@ -4895,7 +5077,7 @@ function Ci(e) {
|
|
|
4895
5077
|
}
|
|
4896
5078
|
//#endregion
|
|
4897
5079
|
//#region src/adapters/rollouts.ts
|
|
4898
|
-
function
|
|
5080
|
+
function Fi(e) {
|
|
4899
5081
|
if (!e) return null;
|
|
4900
5082
|
try {
|
|
4901
5083
|
return JSON.parse(e);
|
|
@@ -4903,7 +5085,7 @@ function wi(e) {
|
|
|
4903
5085
|
return null;
|
|
4904
5086
|
}
|
|
4905
5087
|
}
|
|
4906
|
-
function
|
|
5088
|
+
function Ii(e) {
|
|
4907
5089
|
return Ce.parse({
|
|
4908
5090
|
id: e.id,
|
|
4909
5091
|
kind: e.kind,
|
|
@@ -4911,15 +5093,15 @@ function Ti(e) {
|
|
|
4911
5093
|
target_worker_version: e.target_worker_version,
|
|
4912
5094
|
target_database_version: e.target_database_version,
|
|
4913
5095
|
wave_size: e.wave_size,
|
|
4914
|
-
canary_tenant_ids:
|
|
4915
|
-
filter:
|
|
5096
|
+
canary_tenant_ids: Fi(e.canary_tenant_ids),
|
|
5097
|
+
filter: Fi(e.filter),
|
|
4916
5098
|
initiated_by: e.initiated_by,
|
|
4917
5099
|
created_at: e.created_at,
|
|
4918
5100
|
updated_at: e.updated_at,
|
|
4919
5101
|
finished_at: e.finished_at
|
|
4920
5102
|
});
|
|
4921
5103
|
}
|
|
4922
|
-
function
|
|
5104
|
+
function Li(e) {
|
|
4923
5105
|
return {
|
|
4924
5106
|
async create(t) {
|
|
4925
5107
|
let n = Se.parse(t), r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
@@ -4936,93 +5118,94 @@ function Ei(e) {
|
|
|
4936
5118
|
updated_at: r,
|
|
4937
5119
|
finished_at: null
|
|
4938
5120
|
};
|
|
4939
|
-
await e.insert(
|
|
5121
|
+
await e.insert(di).values(i);
|
|
4940
5122
|
let a = await this.get(i.id);
|
|
4941
5123
|
if (!a) throw Error(`Failed to create rollout ${i.id}`);
|
|
4942
5124
|
return a;
|
|
4943
5125
|
},
|
|
4944
5126
|
async get(t) {
|
|
4945
|
-
let n = await e.select().from(
|
|
4946
|
-
return n[0] ?
|
|
5127
|
+
let n = await e.select().from(di).where(a(di.id, t)).limit(1);
|
|
5128
|
+
return n[0] ? Ii(n[0]) : null;
|
|
4947
5129
|
},
|
|
4948
5130
|
async list(t = {}) {
|
|
4949
|
-
let n = t.page ?? 0, r = t.per_page ?? 50, a = await e.select().from(
|
|
5131
|
+
let n = t.page ?? 0, r = t.per_page ?? 50, a = await e.select().from(di).orderBy(i(di.created_at), i(di.id)).offset(n * r).limit(r);
|
|
4950
5132
|
return {
|
|
4951
|
-
rollouts: a.map(
|
|
5133
|
+
rollouts: a.map(Ii),
|
|
4952
5134
|
start: n * r,
|
|
4953
5135
|
limit: r,
|
|
4954
5136
|
length: a.length
|
|
4955
5137
|
};
|
|
4956
5138
|
},
|
|
4957
5139
|
async update(t, n) {
|
|
4958
|
-
if ((await e.select({ id:
|
|
5140
|
+
if ((await e.select({ id: di.id }).from(di).where(a(di.id, t)).limit(1)).length === 0) return !1;
|
|
4959
5141
|
let r = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
4960
|
-
return n.status !== void 0 && (r.status = n.status), n.wave_size !== void 0 && (r.wave_size = n.wave_size), n.canary_tenant_ids !== void 0 && (r.canary_tenant_ids = n.canary_tenant_ids ? JSON.stringify(n.canary_tenant_ids) : null), n.filter !== void 0 && (r.filter = n.filter ? JSON.stringify(n.filter) : null), n.finished_at !== void 0 && (r.finished_at = n.finished_at), await e.update(
|
|
5142
|
+
return n.status !== void 0 && (r.status = n.status), n.wave_size !== void 0 && (r.wave_size = n.wave_size), n.canary_tenant_ids !== void 0 && (r.canary_tenant_ids = n.canary_tenant_ids ? JSON.stringify(n.canary_tenant_ids) : null), n.filter !== void 0 && (r.filter = n.filter ? JSON.stringify(n.filter) : null), n.finished_at !== void 0 && (r.finished_at = n.finished_at), await e.update(di).set(r).where(a(di.id, t)), !0;
|
|
4961
5143
|
},
|
|
4962
5144
|
async remove(t) {
|
|
4963
|
-
return (await e.select({ id:
|
|
5145
|
+
return (await e.select({ id: di.id }).from(di).where(a(di.id, t)).limit(1)).length === 0 ? !1 : (await e.delete(di).where(a(di.id, t)), !0);
|
|
4964
5146
|
}
|
|
4965
5147
|
};
|
|
4966
5148
|
}
|
|
4967
5149
|
//#endregion
|
|
4968
5150
|
//#region src/adapters/index.ts
|
|
4969
|
-
function
|
|
5151
|
+
function Ri(e, t = { useTransactions: !0 }) {
|
|
4970
5152
|
let n = {
|
|
4971
|
-
actions:
|
|
4972
|
-
actionExecutions:
|
|
4973
|
-
actionVersions:
|
|
4974
|
-
branding:
|
|
4975
|
-
clients:
|
|
4976
|
-
clientConnections:
|
|
4977
|
-
clientGrants:
|
|
4978
|
-
clientRegistrationTokens:
|
|
4979
|
-
codes:
|
|
4980
|
-
connections:
|
|
4981
|
-
customDomains:
|
|
4982
|
-
customText:
|
|
4983
|
-
emailProviders:
|
|
4984
|
-
emailTemplates:
|
|
4985
|
-
flows:
|
|
4986
|
-
forms:
|
|
4987
|
-
grants:
|
|
4988
|
-
hookCode:
|
|
4989
|
-
hooks:
|
|
4990
|
-
invites:
|
|
4991
|
-
keys:
|
|
4992
|
-
loginSessions:
|
|
4993
|
-
logs:
|
|
4994
|
-
authenticationMethods:
|
|
4995
|
-
organizations:
|
|
4996
|
-
passwords:
|
|
4997
|
-
promptSettings:
|
|
4998
|
-
proxyRoutes:
|
|
4999
|
-
scimConfigurations:
|
|
5000
|
-
scimTokens:
|
|
5001
|
-
scimExternalIds:
|
|
5002
|
-
refreshTokens:
|
|
5003
|
-
resourceServers:
|
|
5004
|
-
rolePermissions:
|
|
5005
|
-
userPermissions:
|
|
5006
|
-
roles:
|
|
5007
|
-
sessions:
|
|
5008
|
-
sessionCleanup:
|
|
5009
|
-
tenants:
|
|
5153
|
+
actions: _t(e),
|
|
5154
|
+
actionExecutions: yt(e),
|
|
5155
|
+
actionVersions: Ct(e),
|
|
5156
|
+
branding: Tt(e),
|
|
5157
|
+
clients: It(e),
|
|
5158
|
+
clientConnections: Rt(e),
|
|
5159
|
+
clientGrants: Bt(e),
|
|
5160
|
+
clientRegistrationTokens: Gt(e),
|
|
5161
|
+
codes: Yt(e),
|
|
5162
|
+
connections: Qt(e),
|
|
5163
|
+
customDomains: en(e),
|
|
5164
|
+
customText: tn(e),
|
|
5165
|
+
emailProviders: nn(e),
|
|
5166
|
+
emailTemplates: an(e),
|
|
5167
|
+
flows: sn(e),
|
|
5168
|
+
forms: un(e),
|
|
5169
|
+
grants: mn(e),
|
|
5170
|
+
hookCode: vn(e),
|
|
5171
|
+
hooks: Sn(e),
|
|
5172
|
+
invites: En(e),
|
|
5173
|
+
keys: On(e),
|
|
5174
|
+
loginSessions: Nn(e),
|
|
5175
|
+
logs: Fn(e),
|
|
5176
|
+
authenticationMethods: Bn(e),
|
|
5177
|
+
organizations: Wn(e),
|
|
5178
|
+
passwords: Kn(e),
|
|
5179
|
+
promptSettings: qn(e),
|
|
5180
|
+
proxyRoutes: Zn(e),
|
|
5181
|
+
scimConfigurations: tr(e),
|
|
5182
|
+
scimTokens: rr(e),
|
|
5183
|
+
scimExternalIds: ar(e),
|
|
5184
|
+
refreshTokens: cr(e),
|
|
5185
|
+
resourceServers: mr(e),
|
|
5186
|
+
rolePermissions: hr(e),
|
|
5187
|
+
userPermissions: gr(e),
|
|
5188
|
+
roles: vr(e),
|
|
5189
|
+
sessions: Cr(e),
|
|
5190
|
+
sessionCleanup: li(e),
|
|
5191
|
+
tenants: Or(e),
|
|
5010
5192
|
...t.controlPlane ? {
|
|
5011
|
-
tenantOperations:
|
|
5012
|
-
tenantOperationEvents:
|
|
5013
|
-
|
|
5193
|
+
tenantOperations: mi(e),
|
|
5194
|
+
tenantOperationEvents: Pi(e),
|
|
5195
|
+
tenantOperationRows: xi(e),
|
|
5196
|
+
rollouts: Li(e)
|
|
5014
5197
|
} : {},
|
|
5015
|
-
themes:
|
|
5016
|
-
universalLoginTemplates:
|
|
5017
|
-
users:
|
|
5018
|
-
userActivity:
|
|
5019
|
-
userRoles:
|
|
5020
|
-
userOrganizations:
|
|
5021
|
-
stats:
|
|
5022
|
-
analytics:
|
|
5023
|
-
outbox:
|
|
5198
|
+
themes: jr(e),
|
|
5199
|
+
universalLoginTemplates: Mr(e),
|
|
5200
|
+
users: Yr(e),
|
|
5201
|
+
userActivity: Pr(e),
|
|
5202
|
+
userRoles: Xr(e),
|
|
5203
|
+
userOrganizations: Zr(e),
|
|
5204
|
+
stats: ti(e),
|
|
5205
|
+
analytics: si(e),
|
|
5206
|
+
outbox: Lr(e),
|
|
5024
5207
|
async transaction(r) {
|
|
5025
|
-
if (t.useTransactions === !1 ||
|
|
5208
|
+
if (t.useTransactions === !1 || bt(e)) return r(n);
|
|
5026
5209
|
await e.run(y`BEGIN`);
|
|
5027
5210
|
try {
|
|
5028
5211
|
let t = await r(n);
|
|
@@ -5036,7 +5219,7 @@ function Di(e, t = { useTransactions: !0 }) {
|
|
|
5036
5219
|
}
|
|
5037
5220
|
//#endregion
|
|
5038
5221
|
//#region src/adapters/resolveHost.ts
|
|
5039
|
-
function
|
|
5222
|
+
function zi(e) {
|
|
5040
5223
|
if (!e) return { path: "/*" };
|
|
5041
5224
|
try {
|
|
5042
5225
|
let t = JSON.parse(e), n = be.safeParse(t);
|
|
@@ -5044,7 +5227,7 @@ function Oi(e) {
|
|
|
5044
5227
|
} catch {}
|
|
5045
5228
|
return { path: "/*" };
|
|
5046
5229
|
}
|
|
5047
|
-
function
|
|
5230
|
+
function Bi(e) {
|
|
5048
5231
|
if (!e) return [];
|
|
5049
5232
|
try {
|
|
5050
5233
|
let t = JSON.parse(e);
|
|
@@ -5059,20 +5242,20 @@ function ki(e) {
|
|
|
5059
5242
|
return [];
|
|
5060
5243
|
}
|
|
5061
5244
|
}
|
|
5062
|
-
async function
|
|
5245
|
+
async function Vi(e, r) {
|
|
5063
5246
|
let i = r.toLowerCase(), o = (await e.select({
|
|
5064
|
-
custom_domain_id:
|
|
5065
|
-
tenant_id:
|
|
5066
|
-
domain:
|
|
5067
|
-
}).from(
|
|
5247
|
+
custom_domain_id: We.custom_domain_id,
|
|
5248
|
+
tenant_id: We.tenant_id,
|
|
5249
|
+
domain: We.domain
|
|
5250
|
+
}).from(We).where(a(We.domain, i)).limit(1))[0];
|
|
5068
5251
|
if (!o) return null;
|
|
5069
|
-
let s = (await e.select().from(
|
|
5252
|
+
let s = (await e.select().from(Y).where(t(a(Y.tenant_id, o.tenant_id), a(Y.custom_domain_id, o.custom_domain_id))).orderBy(n(Y.priority), n(Y.created_at))).map((e) => ({
|
|
5070
5253
|
id: e.id,
|
|
5071
5254
|
tenant_id: e.tenant_id,
|
|
5072
5255
|
custom_domain_id: e.custom_domain_id,
|
|
5073
5256
|
priority: e.priority,
|
|
5074
|
-
match:
|
|
5075
|
-
handlers:
|
|
5257
|
+
match: zi(e.match),
|
|
5258
|
+
handlers: Bi(e.handlers),
|
|
5076
5259
|
created_at: e.created_at,
|
|
5077
5260
|
updated_at: e.updated_at
|
|
5078
5261
|
}));
|
|
@@ -5085,11 +5268,11 @@ async function Ai(e, r) {
|
|
|
5085
5268
|
}
|
|
5086
5269
|
//#endregion
|
|
5087
5270
|
//#region src/adapters/proxyData.ts
|
|
5088
|
-
function
|
|
5271
|
+
function Hi(e) {
|
|
5089
5272
|
return {
|
|
5090
|
-
proxyRoutes:
|
|
5091
|
-
resolveHost: (t) =>
|
|
5273
|
+
proxyRoutes: Zn(e),
|
|
5274
|
+
resolveHost: (t) => Vi(e, t)
|
|
5092
5275
|
};
|
|
5093
5276
|
}
|
|
5094
5277
|
//#endregion
|
|
5095
|
-
export {
|
|
5278
|
+
export { Hi as createProxyDataAdapter, Zn as createProxyRoutesAdapter, Ri as default, lt as sqlite };
|