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