@authhero/drizzle 1.6.1 → 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 +1182 -1000
- 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,21 +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
|
|
1943
|
-
let { tenant_id: t, domain_metadata: n,
|
|
1942
|
+
function $t(e) {
|
|
1943
|
+
let { tenant_id: t, domain_metadata: n, verification: r, ...i } = e;
|
|
1944
1944
|
return D({
|
|
1945
|
-
...
|
|
1946
|
-
primary: !!
|
|
1947
|
-
domain_metadata:
|
|
1945
|
+
...i,
|
|
1946
|
+
primary: !!i.primary,
|
|
1947
|
+
domain_metadata: Z(n),
|
|
1948
|
+
verification: Z(r)
|
|
1948
1949
|
});
|
|
1949
1950
|
}
|
|
1950
|
-
function
|
|
1951
|
+
function en(e) {
|
|
1951
1952
|
return {
|
|
1952
1953
|
async create(t, n) {
|
|
1953
1954
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
@@ -1958,47 +1959,47 @@ function Zt(e) {
|
|
|
1958
1959
|
status: n.status || "pending",
|
|
1959
1960
|
type: n.type,
|
|
1960
1961
|
origin_domain_name: n.origin_domain_name,
|
|
1961
|
-
verification: n.verification,
|
|
1962
|
+
verification: n.verification ? JSON.stringify(n.verification) : void 0,
|
|
1962
1963
|
custom_client_ip_header: n.custom_client_ip_header,
|
|
1963
1964
|
tls_policy: n.tls_policy,
|
|
1964
1965
|
domain_metadata: n.domain_metadata ? JSON.stringify(n.domain_metadata) : void 0,
|
|
1965
1966
|
created_at: r,
|
|
1966
1967
|
updated_at: r
|
|
1967
1968
|
};
|
|
1968
|
-
return await e.insert(
|
|
1969
|
+
return await e.insert(We).values(i), $t({
|
|
1969
1970
|
...i,
|
|
1970
1971
|
tenant_id: t
|
|
1971
1972
|
});
|
|
1972
1973
|
},
|
|
1973
1974
|
async get(n, r) {
|
|
1974
|
-
let i = await e.select().from(
|
|
1975
|
-
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;
|
|
1976
1977
|
},
|
|
1977
1978
|
async getByDomain(t) {
|
|
1978
|
-
let n = await e.select().from(
|
|
1979
|
+
let n = await e.select().from(We).where(a(We.domain, t)).get();
|
|
1979
1980
|
return n ? {
|
|
1980
|
-
|
|
1981
|
+
...$t(n),
|
|
1981
1982
|
tenant_id: n.tenant_id
|
|
1982
1983
|
} : null;
|
|
1983
1984
|
},
|
|
1984
1985
|
async list(t) {
|
|
1985
|
-
return (await e.select().from(
|
|
1986
|
+
return (await e.select().from(We).where(a(We.tenant_id, t)).all()).map($t);
|
|
1986
1987
|
},
|
|
1987
1988
|
async update(n, r, i) {
|
|
1988
1989
|
let o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
1989
|
-
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 = 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;
|
|
1990
1991
|
},
|
|
1991
1992
|
async remove(n, r) {
|
|
1992
|
-
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;
|
|
1993
1994
|
}
|
|
1994
1995
|
};
|
|
1995
1996
|
}
|
|
1996
1997
|
//#endregion
|
|
1997
1998
|
//#region src/adapters/customText.ts
|
|
1998
|
-
function
|
|
1999
|
+
function tn(e) {
|
|
1999
2000
|
return {
|
|
2000
2001
|
async get(n, r, i) {
|
|
2001
|
-
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();
|
|
2002
2003
|
if (!o) return null;
|
|
2003
2004
|
try {
|
|
2004
2005
|
return JSON.parse(o.custom_text);
|
|
@@ -2008,7 +2009,7 @@ function Qt(e) {
|
|
|
2008
2009
|
},
|
|
2009
2010
|
async set(t, n, r, i) {
|
|
2010
2011
|
let a = Date.now(), o = JSON.stringify(i);
|
|
2011
|
-
await e.insert(
|
|
2012
|
+
await e.insert(ot).values({
|
|
2012
2013
|
tenant_id: t,
|
|
2013
2014
|
prompt: n,
|
|
2014
2015
|
language: r,
|
|
@@ -2017,9 +2018,9 @@ function Qt(e) {
|
|
|
2017
2018
|
updated_at_ts: a
|
|
2018
2019
|
}).onConflictDoUpdate({
|
|
2019
2020
|
target: [
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2021
|
+
ot.tenant_id,
|
|
2022
|
+
ot.prompt,
|
|
2023
|
+
ot.language
|
|
2023
2024
|
],
|
|
2024
2025
|
set: {
|
|
2025
2026
|
custom_text: o,
|
|
@@ -2028,23 +2029,23 @@ function Qt(e) {
|
|
|
2028
2029
|
});
|
|
2029
2030
|
},
|
|
2030
2031
|
async delete(n, r, i) {
|
|
2031
|
-
await e.delete(
|
|
2032
|
+
await e.delete(ot).where(t(a(ot.tenant_id, n), a(ot.prompt, r), a(ot.language, i)));
|
|
2032
2033
|
},
|
|
2033
2034
|
async list(t) {
|
|
2034
2035
|
return await e.select({
|
|
2035
|
-
prompt:
|
|
2036
|
-
language:
|
|
2037
|
-
}).from(
|
|
2036
|
+
prompt: ot.prompt,
|
|
2037
|
+
language: ot.language
|
|
2038
|
+
}).from(ot).where(a(ot.tenant_id, t)).all();
|
|
2038
2039
|
}
|
|
2039
2040
|
};
|
|
2040
2041
|
}
|
|
2041
2042
|
//#endregion
|
|
2042
2043
|
//#region src/adapters/emailProviders.ts
|
|
2043
|
-
function
|
|
2044
|
+
function nn(e) {
|
|
2044
2045
|
return {
|
|
2045
2046
|
async create(t, n) {
|
|
2046
2047
|
let r = (/* @__PURE__ */ new Date()).toISOString();
|
|
2047
|
-
await e.insert(
|
|
2048
|
+
await e.insert(tt).values({
|
|
2048
2049
|
tenant_id: t,
|
|
2049
2050
|
name: n.name,
|
|
2050
2051
|
enabled: n.enabled,
|
|
@@ -2056,28 +2057,28 @@ function $t(e) {
|
|
|
2056
2057
|
});
|
|
2057
2058
|
},
|
|
2058
2059
|
async get(t) {
|
|
2059
|
-
let n = await e.select().from(
|
|
2060
|
+
let n = await e.select().from(tt).where(a(tt.tenant_id, t)).get();
|
|
2060
2061
|
if (!n) return null;
|
|
2061
2062
|
let { tenant_id: r, ...i } = n;
|
|
2062
2063
|
return D({
|
|
2063
2064
|
...i,
|
|
2064
2065
|
enabled: !!i.enabled,
|
|
2065
|
-
credentials:
|
|
2066
|
-
settings:
|
|
2066
|
+
credentials: Z(i.credentials, {}),
|
|
2067
|
+
settings: Z(i.settings, {})
|
|
2067
2068
|
});
|
|
2068
2069
|
},
|
|
2069
2070
|
async update(t, n) {
|
|
2070
2071
|
let r = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
2071
|
-
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));
|
|
2072
2073
|
},
|
|
2073
2074
|
async remove(t) {
|
|
2074
|
-
await e.delete(
|
|
2075
|
+
await e.delete(tt).where(a(tt.tenant_id, t));
|
|
2075
2076
|
}
|
|
2076
2077
|
};
|
|
2077
2078
|
}
|
|
2078
2079
|
//#endregion
|
|
2079
2080
|
//#region src/adapters/emailTemplates.ts
|
|
2080
|
-
function
|
|
2081
|
+
function rn(e) {
|
|
2081
2082
|
return D({
|
|
2082
2083
|
template: e.template,
|
|
2083
2084
|
body: e.body,
|
|
@@ -2090,18 +2091,18 @@ function en(e) {
|
|
|
2090
2091
|
urlLifetimeInSeconds: e.url_lifetime_in_seconds ?? void 0
|
|
2091
2092
|
});
|
|
2092
2093
|
}
|
|
2093
|
-
function
|
|
2094
|
+
function an(e) {
|
|
2094
2095
|
return {
|
|
2095
2096
|
async get(n, r) {
|
|
2096
|
-
let i = await e.select().from(
|
|
2097
|
-
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;
|
|
2098
2099
|
},
|
|
2099
2100
|
async list(t) {
|
|
2100
|
-
return (await e.select().from(
|
|
2101
|
+
return (await e.select().from(nt).where(a(nt.tenant_id, t)).all()).map(rn);
|
|
2101
2102
|
},
|
|
2102
2103
|
async create(t, n) {
|
|
2103
2104
|
let r = (/* @__PURE__ */ new Date()).toISOString();
|
|
2104
|
-
return await e.insert(
|
|
2105
|
+
return await e.insert(nt).values({
|
|
2105
2106
|
tenant_id: t,
|
|
2106
2107
|
template: n.template,
|
|
2107
2108
|
body: n.body,
|
|
@@ -2119,23 +2120,23 @@ function tn(e) {
|
|
|
2119
2120
|
async update(n, r, i) {
|
|
2120
2121
|
let o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
2121
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);
|
|
2122
|
-
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();
|
|
2123
2124
|
return Number(s.changes ?? 0) > 0;
|
|
2124
2125
|
},
|
|
2125
2126
|
async remove(n, r) {
|
|
2126
|
-
let i = await e.delete(
|
|
2127
|
+
let i = await e.delete(nt).where(t(a(nt.tenant_id, n), a(nt.template, r))).run();
|
|
2127
2128
|
return Number(i.changes ?? 0) > 0;
|
|
2128
2129
|
}
|
|
2129
2130
|
};
|
|
2130
2131
|
}
|
|
2131
2132
|
//#endregion
|
|
2132
2133
|
//#region src/adapters/flows.ts
|
|
2133
|
-
var
|
|
2134
|
-
function
|
|
2134
|
+
var on = ["id", "name"];
|
|
2135
|
+
function sn(e) {
|
|
2135
2136
|
return {
|
|
2136
2137
|
async create(t, n) {
|
|
2137
2138
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = `af_${b()}`;
|
|
2138
|
-
return await e.insert(
|
|
2139
|
+
return await e.insert($e).values({
|
|
2139
2140
|
id: i,
|
|
2140
2141
|
tenant_id: t,
|
|
2141
2142
|
name: n.name,
|
|
@@ -2151,41 +2152,41 @@ function rn(e) {
|
|
|
2151
2152
|
};
|
|
2152
2153
|
},
|
|
2153
2154
|
async get(n, r) {
|
|
2154
|
-
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();
|
|
2155
2156
|
if (!i) return null;
|
|
2156
2157
|
let { tenant_id: o, actions: s, ...c } = i;
|
|
2157
2158
|
return D({
|
|
2158
2159
|
...c,
|
|
2159
|
-
actions:
|
|
2160
|
+
actions: Z(s, [])
|
|
2160
2161
|
});
|
|
2161
2162
|
},
|
|
2162
2163
|
async update(n, r, i) {
|
|
2163
2164
|
let o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
2164
|
-
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);
|
|
2165
2166
|
},
|
|
2166
2167
|
async list(o, s) {
|
|
2167
|
-
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)];
|
|
2168
2169
|
if (f) {
|
|
2169
|
-
let e = we(f,
|
|
2170
|
+
let e = we(f, on);
|
|
2170
2171
|
if (e) {
|
|
2171
|
-
let t =
|
|
2172
|
+
let t = mt($e, e, []);
|
|
2172
2173
|
t && p.push(t);
|
|
2173
2174
|
}
|
|
2174
2175
|
}
|
|
2175
|
-
let m = t(...p), h = e.select().from(
|
|
2176
|
+
let m = t(...p), h = e.select().from($e).where(m).$dynamic();
|
|
2176
2177
|
if (d?.sort_by) {
|
|
2177
|
-
let e =
|
|
2178
|
+
let e = $e[d.sort_by];
|
|
2178
2179
|
e && (h = h.orderBy(d.sort_order === "desc" ? i(e) : n(e)));
|
|
2179
2180
|
}
|
|
2180
2181
|
let g = (await h.offset(c * l).limit(l)).map((e) => {
|
|
2181
2182
|
let { tenant_id: t, actions: n, ...r } = e;
|
|
2182
2183
|
return D({
|
|
2183
2184
|
...r,
|
|
2184
|
-
actions:
|
|
2185
|
+
actions: Z(n, [])
|
|
2185
2186
|
});
|
|
2186
2187
|
});
|
|
2187
2188
|
if (!u) return { flows: g };
|
|
2188
|
-
let [_] = await e.select({ count: r() }).from(
|
|
2189
|
+
let [_] = await e.select({ count: r() }).from($e).where(m);
|
|
2189
2190
|
return {
|
|
2190
2191
|
flows: g,
|
|
2191
2192
|
start: c * l,
|
|
@@ -2194,18 +2195,18 @@ function rn(e) {
|
|
|
2194
2195
|
};
|
|
2195
2196
|
},
|
|
2196
2197
|
async remove(n, r) {
|
|
2197
|
-
return (await e.delete(
|
|
2198
|
+
return (await e.delete($e).where(t(a($e.tenant_id, n), a($e.id, r))).returning()).length > 0;
|
|
2198
2199
|
}
|
|
2199
2200
|
};
|
|
2200
2201
|
}
|
|
2201
2202
|
//#endregion
|
|
2202
2203
|
//#region src/adapters/forms.ts
|
|
2203
|
-
var
|
|
2204
|
+
var cn = [
|
|
2204
2205
|
"nodes",
|
|
2205
2206
|
"start",
|
|
2206
2207
|
"ending"
|
|
2207
|
-
],
|
|
2208
|
-
function
|
|
2208
|
+
], ln = ["name"];
|
|
2209
|
+
function un(e) {
|
|
2209
2210
|
return {
|
|
2210
2211
|
async create(t, n) {
|
|
2211
2212
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = b(), a = {
|
|
@@ -2219,8 +2220,8 @@ function sn(e) {
|
|
|
2219
2220
|
created_at: r,
|
|
2220
2221
|
updated_at: r
|
|
2221
2222
|
};
|
|
2222
|
-
for (let e of
|
|
2223
|
-
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), {
|
|
2224
2225
|
id: i,
|
|
2225
2226
|
...n,
|
|
2226
2227
|
created_at: r,
|
|
@@ -2228,38 +2229,38 @@ function sn(e) {
|
|
|
2228
2229
|
};
|
|
2229
2230
|
},
|
|
2230
2231
|
async get(n, r) {
|
|
2231
|
-
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();
|
|
2232
2233
|
if (!i) return null;
|
|
2233
2234
|
let { tenant_id: o, ...s } = i, c = { ...s };
|
|
2234
|
-
for (let e of
|
|
2235
|
+
for (let e of cn) c[e] = Z(s[e]);
|
|
2235
2236
|
return D(c);
|
|
2236
2237
|
},
|
|
2237
2238
|
async update(n, r, i) {
|
|
2238
2239
|
let o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
2239
|
-
for (let [e, t] of Object.entries(i)) t !== void 0 && (
|
|
2240
|
-
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;
|
|
2241
2242
|
},
|
|
2242
2243
|
async list(o, s) {
|
|
2243
|
-
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)];
|
|
2244
2245
|
if (f) {
|
|
2245
|
-
let e = we(f,
|
|
2246
|
+
let e = we(f, ln);
|
|
2246
2247
|
if (e) {
|
|
2247
|
-
let t =
|
|
2248
|
+
let t = mt(Qe, e, ln);
|
|
2248
2249
|
t && p.push(t);
|
|
2249
2250
|
}
|
|
2250
2251
|
}
|
|
2251
|
-
let m = t(...p), h = e.select().from(
|
|
2252
|
+
let m = t(...p), h = e.select().from(Qe).where(m).$dynamic();
|
|
2252
2253
|
if (d?.sort_by) {
|
|
2253
|
-
let e =
|
|
2254
|
+
let e = Qe[d.sort_by];
|
|
2254
2255
|
e && (h = h.orderBy(d.sort_order === "desc" ? i(e) : n(e)));
|
|
2255
2256
|
}
|
|
2256
2257
|
let g = (await h.offset(c * l).limit(l)).map((e) => {
|
|
2257
2258
|
let { tenant_id: t, ...n } = e, r = { ...n };
|
|
2258
|
-
for (let e of
|
|
2259
|
+
for (let e of cn) r[e] = Z(n[e]);
|
|
2259
2260
|
return D(r);
|
|
2260
2261
|
});
|
|
2261
2262
|
if (!u) return { forms: g };
|
|
2262
|
-
let [_] = await e.select({ count: r() }).from(
|
|
2263
|
+
let [_] = await e.select({ count: r() }).from(Qe).where(m);
|
|
2263
2264
|
return {
|
|
2264
2265
|
forms: g,
|
|
2265
2266
|
start: c * l,
|
|
@@ -2268,47 +2269,47 @@ function sn(e) {
|
|
|
2268
2269
|
};
|
|
2269
2270
|
},
|
|
2270
2271
|
async remove(n, r) {
|
|
2271
|
-
return (await e.delete(
|
|
2272
|
+
return (await e.delete(Qe).where(t(a(Qe.tenant_id, n), a(Qe.id, r))).returning()).length > 0;
|
|
2272
2273
|
}
|
|
2273
2274
|
};
|
|
2274
2275
|
}
|
|
2275
2276
|
//#endregion
|
|
2276
2277
|
//#region src/adapters/grants.ts
|
|
2277
|
-
function
|
|
2278
|
+
function dn(e) {
|
|
2278
2279
|
return {
|
|
2279
2280
|
id: e.id,
|
|
2280
2281
|
user_id: e.user_id,
|
|
2281
2282
|
clientID: e.client_id,
|
|
2282
2283
|
audience: e.audience || void 0,
|
|
2283
|
-
scope:
|
|
2284
|
+
scope: Z(e.scope, []) ?? []
|
|
2284
2285
|
};
|
|
2285
2286
|
}
|
|
2286
|
-
var
|
|
2287
|
-
user_id:
|
|
2288
|
-
client_id:
|
|
2289
|
-
audience:
|
|
2290
|
-
created_at:
|
|
2291
|
-
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
|
|
2292
2293
|
};
|
|
2293
|
-
function
|
|
2294
|
-
return Object.hasOwn(
|
|
2294
|
+
function pn(e) {
|
|
2295
|
+
return Object.hasOwn(fn, e) ? fn[e] : void 0;
|
|
2295
2296
|
}
|
|
2296
|
-
function
|
|
2297
|
+
function mn(e) {
|
|
2297
2298
|
return {
|
|
2298
2299
|
async create(n, r) {
|
|
2299
|
-
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();
|
|
2300
2301
|
if (c) {
|
|
2301
|
-
let r =
|
|
2302
|
-
return await e.update(
|
|
2302
|
+
let r = Z(c.scope, []) ?? [], s = Array.from(new Set([...r, ...o]));
|
|
2303
|
+
return await e.update(z).set({
|
|
2303
2304
|
scope: JSON.stringify(s),
|
|
2304
2305
|
updated_at: i
|
|
2305
|
-
}).where(t(a(
|
|
2306
|
+
}).where(t(a(z.tenant_id, n), a(z.id, c.id))), dn({
|
|
2306
2307
|
...c,
|
|
2307
2308
|
scope: JSON.stringify(s)
|
|
2308
2309
|
});
|
|
2309
2310
|
}
|
|
2310
2311
|
let l = b();
|
|
2311
|
-
return await e.insert(
|
|
2312
|
+
return await e.insert(z).values({
|
|
2312
2313
|
id: l,
|
|
2313
2314
|
tenant_id: n,
|
|
2314
2315
|
user_id: r.user_id,
|
|
@@ -2326,24 +2327,24 @@ function dn(e) {
|
|
|
2326
2327
|
};
|
|
2327
2328
|
},
|
|
2328
2329
|
async get(n, r, i, o) {
|
|
2329
|
-
let s = await e.select().from(
|
|
2330
|
-
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;
|
|
2331
2332
|
},
|
|
2332
2333
|
async list(o, s) {
|
|
2333
|
-
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, [
|
|
2334
2335
|
"user_id",
|
|
2335
2336
|
"client_id",
|
|
2336
2337
|
"audience"
|
|
2337
|
-
]) : void 0, m = p ? t(a(
|
|
2338
|
-
h = g ? h.orderBy(d?.sort_order === "desc" ? i(g) : n(g)) : h.orderBy(n(
|
|
2339
|
-
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);
|
|
2340
2341
|
if (!u) return {
|
|
2341
2342
|
grants: _,
|
|
2342
2343
|
start: 0,
|
|
2343
2344
|
limit: 0,
|
|
2344
2345
|
length: 0
|
|
2345
2346
|
};
|
|
2346
|
-
let [v] = await e.select({ count: r() }).from(
|
|
2347
|
+
let [v] = await e.select({ count: r() }).from(z).where(m);
|
|
2347
2348
|
return {
|
|
2348
2349
|
grants: _,
|
|
2349
2350
|
start: c * l,
|
|
@@ -2352,20 +2353,20 @@ function dn(e) {
|
|
|
2352
2353
|
};
|
|
2353
2354
|
},
|
|
2354
2355
|
async remove(n, r) {
|
|
2355
|
-
return (await e.delete(
|
|
2356
|
+
return (await e.delete(z).where(t(a(z.tenant_id, n), a(z.id, r))).returning()).length > 0;
|
|
2356
2357
|
},
|
|
2357
2358
|
async removeByUser(n, r) {
|
|
2358
|
-
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;
|
|
2359
2360
|
}
|
|
2360
2361
|
};
|
|
2361
2362
|
}
|
|
2362
2363
|
//#endregion
|
|
2363
2364
|
//#region src/adapters/hookCode.ts
|
|
2364
|
-
var
|
|
2365
|
-
function
|
|
2366
|
-
return `hc_${
|
|
2365
|
+
var hn = ee("0123456789abcdefghijklmnopqrstuvwxyz", 17);
|
|
2366
|
+
function gn() {
|
|
2367
|
+
return `hc_${hn()}`;
|
|
2367
2368
|
}
|
|
2368
|
-
function
|
|
2369
|
+
function _n(e) {
|
|
2369
2370
|
let { created_at_ts: t, updated_at_ts: n, secrets: r, ...i } = e, a = ae({
|
|
2370
2371
|
created_at_ts: t,
|
|
2371
2372
|
updated_at_ts: n
|
|
@@ -2376,41 +2377,41 @@ function mn(e) {
|
|
|
2376
2377
|
secrets: r ? JSON.parse(r) : void 0
|
|
2377
2378
|
};
|
|
2378
2379
|
}
|
|
2379
|
-
function
|
|
2380
|
+
function vn(e) {
|
|
2380
2381
|
return {
|
|
2381
2382
|
async create(t, n) {
|
|
2382
2383
|
let r = Date.now(), i = {
|
|
2383
|
-
id:
|
|
2384
|
+
id: gn(),
|
|
2384
2385
|
tenant_id: t,
|
|
2385
2386
|
code: n.code,
|
|
2386
2387
|
secrets: n.secrets ? JSON.stringify(n.secrets) : null,
|
|
2387
2388
|
created_at_ts: r,
|
|
2388
2389
|
updated_at_ts: r
|
|
2389
2390
|
};
|
|
2390
|
-
return await e.insert(
|
|
2391
|
+
return await e.insert(it).values(i), _n({
|
|
2391
2392
|
...i,
|
|
2392
2393
|
tenant_id: t
|
|
2393
2394
|
});
|
|
2394
2395
|
},
|
|
2395
2396
|
async get(n, r) {
|
|
2396
|
-
let i = await e.select().from(
|
|
2397
|
-
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;
|
|
2398
2399
|
},
|
|
2399
2400
|
async update(n, r, i) {
|
|
2400
2401
|
let o = { updated_at_ts: Date.now() };
|
|
2401
|
-
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;
|
|
2402
2403
|
},
|
|
2403
2404
|
async remove(n, r) {
|
|
2404
|
-
return (await e.delete(
|
|
2405
|
+
return (await e.delete(it).where(t(a(it.tenant_id, n), a(it.id, r))).returning()).length > 0;
|
|
2405
2406
|
}
|
|
2406
2407
|
};
|
|
2407
2408
|
}
|
|
2408
2409
|
//#endregion
|
|
2409
2410
|
//#region src/adapters/hooks.ts
|
|
2410
|
-
function
|
|
2411
|
+
function yn() {
|
|
2411
2412
|
return `h_${ee("0123456789abcdefghijklmnopqrstuvwxyz", 17)()}`;
|
|
2412
2413
|
}
|
|
2413
|
-
function
|
|
2414
|
+
function bn(e) {
|
|
2414
2415
|
if (!(typeof e != "string" || !e)) try {
|
|
2415
2416
|
let t = JSON.parse(e);
|
|
2416
2417
|
return t && typeof t == "object" && !Array.isArray(t) ? t : void 0;
|
|
@@ -2418,7 +2419,7 @@ function _n(e) {
|
|
|
2418
2419
|
return;
|
|
2419
2420
|
}
|
|
2420
2421
|
}
|
|
2421
|
-
function
|
|
2422
|
+
function xn(e) {
|
|
2422
2423
|
let { tenant_id: t, created_at_ts: n, updated_at_ts: r, metadata: i, ...a } = e, o = ae({
|
|
2423
2424
|
created_at_ts: n,
|
|
2424
2425
|
updated_at_ts: r
|
|
@@ -2427,15 +2428,15 @@ function vn(e) {
|
|
|
2427
2428
|
...a,
|
|
2428
2429
|
enabled: !!a.enabled,
|
|
2429
2430
|
synchronous: !!a.synchronous,
|
|
2430
|
-
metadata:
|
|
2431
|
+
metadata: bn(i),
|
|
2431
2432
|
...o
|
|
2432
2433
|
});
|
|
2433
2434
|
}
|
|
2434
|
-
function
|
|
2435
|
+
function Sn(e) {
|
|
2435
2436
|
return {
|
|
2436
2437
|
async create(t, n) {
|
|
2437
2438
|
let r = Date.now(), i = {
|
|
2438
|
-
hook_id: n.hook_id ||
|
|
2439
|
+
hook_id: n.hook_id || yn(),
|
|
2439
2440
|
tenant_id: t,
|
|
2440
2441
|
trigger_id: n.trigger_id,
|
|
2441
2442
|
url: n.url,
|
|
@@ -2451,30 +2452,30 @@ function yn(e) {
|
|
|
2451
2452
|
created_at_ts: r,
|
|
2452
2453
|
updated_at_ts: r
|
|
2453
2454
|
};
|
|
2454
|
-
return await e.insert(
|
|
2455
|
+
return await e.insert(rt).values(i), xn({
|
|
2455
2456
|
...i,
|
|
2456
2457
|
tenant_id: t
|
|
2457
2458
|
});
|
|
2458
2459
|
},
|
|
2459
2460
|
async get(n, r) {
|
|
2460
|
-
let i = await e.select().from(
|
|
2461
|
-
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;
|
|
2462
2463
|
},
|
|
2463
2464
|
async update(n, r, i) {
|
|
2464
2465
|
let o = { updated_at_ts: Date.now() };
|
|
2465
|
-
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;
|
|
2466
2467
|
},
|
|
2467
2468
|
async list(o, s) {
|
|
2468
|
-
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, [
|
|
2469
2470
|
"url",
|
|
2470
2471
|
"form_id",
|
|
2471
2472
|
"template_id",
|
|
2472
2473
|
"code_id"
|
|
2473
|
-
]) : void 0, m = p ? t(a(
|
|
2474
|
-
h = g ? h.orderBy(d?.sort_order === "desc" ? i(g) : n(g)) : h.orderBy(i(
|
|
2475
|
-
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);
|
|
2476
2477
|
if (!u) return { hooks: _ };
|
|
2477
|
-
let [v] = await e.select({ count: r() }).from(
|
|
2478
|
+
let [v] = await e.select({ count: r() }).from(rt).where(m);
|
|
2478
2479
|
return {
|
|
2479
2480
|
hooks: _,
|
|
2480
2481
|
start: c * l,
|
|
@@ -2483,31 +2484,31 @@ function yn(e) {
|
|
|
2483
2484
|
};
|
|
2484
2485
|
},
|
|
2485
2486
|
async remove(n, r) {
|
|
2486
|
-
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;
|
|
2487
2488
|
}
|
|
2488
2489
|
};
|
|
2489
2490
|
}
|
|
2490
2491
|
//#endregion
|
|
2491
2492
|
//#region src/adapters/invites.ts
|
|
2492
|
-
function
|
|
2493
|
+
function Cn() {
|
|
2493
2494
|
return `inv_${ee("0123456789abcdefghijklmnopqrstuvwxyz", 17)()}`;
|
|
2494
2495
|
}
|
|
2495
|
-
var
|
|
2496
|
+
var wn = [
|
|
2496
2497
|
"inviter",
|
|
2497
2498
|
"invitee",
|
|
2498
2499
|
"app_metadata",
|
|
2499
2500
|
"user_metadata",
|
|
2500
2501
|
"roles"
|
|
2501
2502
|
];
|
|
2502
|
-
function
|
|
2503
|
+
function Tn(e) {
|
|
2503
2504
|
let { tenant_id: t, send_invitation_email: n, ...r } = e, i = { ...r };
|
|
2504
|
-
for (let e of
|
|
2505
|
+
for (let e of wn) i[e] = Z(r[e], e === "roles" ? [] : {});
|
|
2505
2506
|
return i.send_invitation_email = !!n, D(i);
|
|
2506
2507
|
}
|
|
2507
|
-
function
|
|
2508
|
+
function En(e) {
|
|
2508
2509
|
return {
|
|
2509
2510
|
async create(t, n) {
|
|
2510
|
-
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 = {
|
|
2511
2512
|
id: r,
|
|
2512
2513
|
tenant_id: t,
|
|
2513
2514
|
organization_id: n.organization_id,
|
|
@@ -2520,35 +2521,35 @@ function Cn(e) {
|
|
|
2520
2521
|
created_at: a.toISOString(),
|
|
2521
2522
|
expires_at: o
|
|
2522
2523
|
};
|
|
2523
|
-
for (let e of
|
|
2524
|
+
for (let e of wn) n[e] !== void 0 && (s[e] = JSON.stringify(n[e]));
|
|
2524
2525
|
try {
|
|
2525
|
-
await e.insert(
|
|
2526
|
+
await e.insert(Ke).values(s);
|
|
2526
2527
|
} catch (e) {
|
|
2527
|
-
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;
|
|
2528
2529
|
}
|
|
2529
|
-
return
|
|
2530
|
+
return Tn({
|
|
2530
2531
|
...s,
|
|
2531
2532
|
tenant_id: t
|
|
2532
2533
|
});
|
|
2533
2534
|
},
|
|
2534
2535
|
async get(n, r) {
|
|
2535
|
-
let i = await e.select().from(
|
|
2536
|
-
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;
|
|
2537
2538
|
},
|
|
2538
2539
|
async update(n, r, i) {
|
|
2539
2540
|
let o = {};
|
|
2540
|
-
for (let e of
|
|
2541
|
-
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;
|
|
2542
2543
|
},
|
|
2543
2544
|
async list(t, o) {
|
|
2544
|
-
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();
|
|
2545
2546
|
if (u?.sort_by) {
|
|
2546
|
-
let e =
|
|
2547
|
+
let e = Ke[u.sort_by];
|
|
2547
2548
|
e && (d = d.orderBy(u.sort_order === "desc" ? i(e) : n(e)));
|
|
2548
2549
|
}
|
|
2549
|
-
let f = (await d.offset(s * c).limit(c)).map(
|
|
2550
|
+
let f = (await d.offset(s * c).limit(c)).map(Tn);
|
|
2550
2551
|
if (!l) return { invites: f };
|
|
2551
|
-
let [p] = await e.select({ count: r() }).from(
|
|
2552
|
+
let [p] = await e.select({ count: r() }).from(Ke).where(a(Ke.tenant_id, t));
|
|
2552
2553
|
return {
|
|
2553
2554
|
invites: f,
|
|
2554
2555
|
start: s * c,
|
|
@@ -2557,39 +2558,39 @@ function Cn(e) {
|
|
|
2557
2558
|
};
|
|
2558
2559
|
},
|
|
2559
2560
|
async remove(n, r) {
|
|
2560
|
-
return (await e.delete(
|
|
2561
|
+
return (await e.delete(Ke).where(t(a(Ke.tenant_id, n), a(Ke.id, r))).returning()).length > 0;
|
|
2561
2562
|
}
|
|
2562
2563
|
};
|
|
2563
2564
|
}
|
|
2564
2565
|
//#endregion
|
|
2565
2566
|
//#region src/adapters/keys.ts
|
|
2566
|
-
var
|
|
2567
|
+
var Dn = [
|
|
2567
2568
|
"kid",
|
|
2568
2569
|
"connection",
|
|
2569
2570
|
"fingerprint",
|
|
2570
2571
|
"thumbprint",
|
|
2571
2572
|
"type"
|
|
2572
2573
|
];
|
|
2573
|
-
function
|
|
2574
|
+
function On(e) {
|
|
2574
2575
|
return {
|
|
2575
2576
|
async create(t) {
|
|
2576
|
-
await e.insert(
|
|
2577
|
+
await e.insert(at).values({
|
|
2577
2578
|
...t,
|
|
2578
2579
|
created_at: (/* @__PURE__ */ new Date()).toDateString()
|
|
2579
2580
|
});
|
|
2580
2581
|
},
|
|
2581
2582
|
async list(a) {
|
|
2582
|
-
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))];
|
|
2583
2584
|
if (d) {
|
|
2584
|
-
let e = we(d,
|
|
2585
|
+
let e = we(d, Dn);
|
|
2585
2586
|
if (e) {
|
|
2586
|
-
let t =
|
|
2587
|
+
let t = mt(at, e, Dn);
|
|
2587
2588
|
t && m.push(t);
|
|
2588
2589
|
}
|
|
2589
2590
|
}
|
|
2590
|
-
let h = t(...m), g = e.select().from(
|
|
2591
|
+
let h = t(...m), g = e.select().from(at).where(h).$dynamic();
|
|
2591
2592
|
if (u?.sort_by) {
|
|
2592
|
-
let e =
|
|
2593
|
+
let e = at[u.sort_by];
|
|
2593
2594
|
e && (g = g.orderBy(u.sort_order === "desc" ? i(e) : n(e)));
|
|
2594
2595
|
}
|
|
2595
2596
|
let _ = (await g.offset(o * c).limit(c)).map((e) => {
|
|
@@ -2597,7 +2598,7 @@ function Tn(e) {
|
|
|
2597
2598
|
return D(n);
|
|
2598
2599
|
});
|
|
2599
2600
|
if (!l) return { signingKeys: _ };
|
|
2600
|
-
let [y] = await e.select({ count: r() }).from(
|
|
2601
|
+
let [y] = await e.select({ count: r() }).from(at).where(h);
|
|
2601
2602
|
return {
|
|
2602
2603
|
signingKeys: _,
|
|
2603
2604
|
start: o * c,
|
|
@@ -2606,22 +2607,22 @@ function Tn(e) {
|
|
|
2606
2607
|
};
|
|
2607
2608
|
},
|
|
2608
2609
|
async update(t, n) {
|
|
2609
|
-
return (await e.update(
|
|
2610
|
+
return (await e.update(at).set(n).where(a(at.kid, t)).returning()).length > 0;
|
|
2610
2611
|
}
|
|
2611
2612
|
};
|
|
2612
2613
|
}
|
|
2613
2614
|
//#endregion
|
|
2614
2615
|
//#region src/adapters/loginSessions.ts
|
|
2615
|
-
var
|
|
2616
|
-
function
|
|
2616
|
+
var kn = "0123456789ABCDEFGHJKMNPQRSTVWXYZ", An = 32;
|
|
2617
|
+
function jn() {
|
|
2617
2618
|
let e = Date.now(), t = "";
|
|
2618
|
-
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);
|
|
2619
2620
|
let n = new Uint8Array(16);
|
|
2620
2621
|
crypto.getRandomValues(n);
|
|
2621
|
-
for (let e = 0; e < 16; e++) t +=
|
|
2622
|
+
for (let e = 0; e < 16; e++) t += kn.charAt(n[e] % An);
|
|
2622
2623
|
return t;
|
|
2623
2624
|
}
|
|
2624
|
-
function
|
|
2625
|
+
function Mn(e) {
|
|
2625
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({
|
|
2626
2627
|
created_at_ts: n,
|
|
2627
2628
|
updated_at_ts: r,
|
|
@@ -2633,17 +2634,17 @@ function kn(e) {
|
|
|
2633
2634
|
]), l = {};
|
|
2634
2635
|
for (let [e, t] of Object.entries(s)) t != null && (l[e] = t);
|
|
2635
2636
|
return D({
|
|
2636
|
-
...
|
|
2637
|
+
...dt(l, ["auth_strategy"]),
|
|
2637
2638
|
authParams: typeof o == "string" && o.length > 0 ? JSON.parse(o) : {},
|
|
2638
2639
|
...c,
|
|
2639
|
-
state_data:
|
|
2640
|
+
state_data: Z(a)
|
|
2640
2641
|
});
|
|
2641
2642
|
}
|
|
2642
|
-
function
|
|
2643
|
+
function Nn(e) {
|
|
2643
2644
|
return {
|
|
2644
2645
|
async create(t, n) {
|
|
2645
2646
|
let r = Date.now(), i = {
|
|
2646
|
-
id:
|
|
2647
|
+
id: jn(),
|
|
2647
2648
|
tenant_id: t,
|
|
2648
2649
|
session_id: n.session_id,
|
|
2649
2650
|
csrf_token: n.csrf_token,
|
|
@@ -2664,39 +2665,39 @@ function An(e) {
|
|
|
2664
2665
|
updated_at_ts: r,
|
|
2665
2666
|
expires_at_ts: n.expires_at ? E(n.expires_at) : r + 1e3 * 60 * 60 * 24
|
|
2666
2667
|
};
|
|
2667
|
-
return await e.insert(
|
|
2668
|
+
return await e.insert(P).values(i), Mn({
|
|
2668
2669
|
...i,
|
|
2669
2670
|
tenant_id: t
|
|
2670
2671
|
});
|
|
2671
2672
|
},
|
|
2672
2673
|
async get(n, r) {
|
|
2673
|
-
let i = n ? t(a(
|
|
2674
|
-
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;
|
|
2675
2676
|
},
|
|
2676
2677
|
async update(n, r, i) {
|
|
2677
2678
|
let o = { updated_at_ts: Date.now() };
|
|
2678
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) {
|
|
2679
|
-
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) : {};
|
|
2680
2681
|
o.auth_params = JSON.stringify({
|
|
2681
2682
|
...c,
|
|
2682
2683
|
...i.authParams
|
|
2683
2684
|
});
|
|
2684
2685
|
}
|
|
2685
|
-
return await e.update(
|
|
2686
|
+
return await e.update(P).set(o).where(t(a(P.tenant_id, n), a(P.id, r))), !0;
|
|
2686
2687
|
},
|
|
2687
2688
|
async remove(n, r) {
|
|
2688
|
-
return (await e.delete(
|
|
2689
|
+
return (await e.delete(P).where(t(a(P.tenant_id, n), a(P.id, r))).returning()).length > 0;
|
|
2689
2690
|
}
|
|
2690
2691
|
};
|
|
2691
2692
|
}
|
|
2692
2693
|
//#endregion
|
|
2693
2694
|
//#region src/adapters/logs.ts
|
|
2694
|
-
function
|
|
2695
|
+
function Pn(e) {
|
|
2695
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 = {
|
|
2696
2697
|
...f,
|
|
2697
2698
|
isMobile: !!n,
|
|
2698
|
-
auth0_client:
|
|
2699
|
-
details:
|
|
2699
|
+
auth0_client: Z(r),
|
|
2700
|
+
details: Z(i),
|
|
2700
2701
|
scope: d ? d.split(",") : void 0
|
|
2701
2702
|
};
|
|
2702
2703
|
return a && (p.location_info = D({
|
|
@@ -2708,7 +2709,7 @@ function jn(e) {
|
|
|
2708
2709
|
continent_code: u
|
|
2709
2710
|
})), D(p);
|
|
2710
2711
|
}
|
|
2711
|
-
function
|
|
2712
|
+
function Fn(e) {
|
|
2712
2713
|
return {
|
|
2713
2714
|
async create(t, n) {
|
|
2714
2715
|
let r = {
|
|
@@ -2734,15 +2735,15 @@ function Mn(e) {
|
|
|
2734
2735
|
hostname: n.hostname,
|
|
2735
2736
|
session_connection: n.session_connection
|
|
2736
2737
|
};
|
|
2737
|
-
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({
|
|
2738
2739
|
...r,
|
|
2739
2740
|
tenant_id: t
|
|
2740
2741
|
});
|
|
2741
2742
|
},
|
|
2742
2743
|
async list(o, s) {
|
|
2743
|
-
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)];
|
|
2744
2745
|
if (p) {
|
|
2745
|
-
let e =
|
|
2746
|
+
let e = mt(q, p, [
|
|
2746
2747
|
"user_id",
|
|
2747
2748
|
"ip",
|
|
2748
2749
|
"type",
|
|
@@ -2750,16 +2751,16 @@ function Mn(e) {
|
|
|
2750
2751
|
], ["description"]);
|
|
2751
2752
|
e && _.push(e);
|
|
2752
2753
|
}
|
|
2753
|
-
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()));
|
|
2754
2755
|
let v = t(..._);
|
|
2755
|
-
if (
|
|
2756
|
-
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` });
|
|
2757
2758
|
let n = f?.sort_order === "asc" ? "asc" : "desc", r = {
|
|
2758
|
-
sortColumn:
|
|
2759
|
-
idColumn:
|
|
2759
|
+
sortColumn: q.date,
|
|
2760
|
+
idColumn: q.log_id,
|
|
2760
2761
|
sortOrder: n,
|
|
2761
2762
|
sortKey: `date:${n}`
|
|
2762
|
-
}, 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);
|
|
2763
2764
|
return {
|
|
2764
2765
|
logs: l,
|
|
2765
2766
|
start: 0,
|
|
@@ -2768,14 +2769,14 @@ function Mn(e) {
|
|
|
2768
2769
|
next: c
|
|
2769
2770
|
};
|
|
2770
2771
|
}
|
|
2771
|
-
let y = e.select().from(
|
|
2772
|
+
let y = e.select().from(q).where(v).$dynamic();
|
|
2772
2773
|
if (f?.sort_by) {
|
|
2773
|
-
let e =
|
|
2774
|
+
let e = q[f.sort_by];
|
|
2774
2775
|
e && (y = y.orderBy(f.sort_order === "desc" ? i(e) : n(e)));
|
|
2775
|
-
} else y = y.orderBy(i(
|
|
2776
|
-
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);
|
|
2777
2778
|
if (!d) return { logs: ee };
|
|
2778
|
-
let [b] = await e.select({ count: r() }).from(
|
|
2779
|
+
let [b] = await e.select({ count: r() }).from(q).where(v);
|
|
2779
2780
|
return {
|
|
2780
2781
|
logs: ee,
|
|
2781
2782
|
start: l * u,
|
|
@@ -2784,38 +2785,38 @@ function Mn(e) {
|
|
|
2784
2785
|
};
|
|
2785
2786
|
},
|
|
2786
2787
|
async get(n, r) {
|
|
2787
|
-
let i = await e.select().from(
|
|
2788
|
-
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;
|
|
2789
2790
|
}
|
|
2790
2791
|
};
|
|
2791
2792
|
}
|
|
2792
2793
|
//#endregion
|
|
2793
2794
|
//#region src/adapters/authenticationMethods.ts
|
|
2794
|
-
var
|
|
2795
|
-
function
|
|
2795
|
+
var In = "0123456789ABCDEFGHJKMNPQRSTVWXYZ", Ln = 32;
|
|
2796
|
+
function Rn() {
|
|
2796
2797
|
let e = Date.now(), t = "";
|
|
2797
|
-
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);
|
|
2798
2799
|
let n = new Uint8Array(16);
|
|
2799
2800
|
crypto.getRandomValues(n);
|
|
2800
|
-
for (let e = 0; e < 16; e++) t +=
|
|
2801
|
+
for (let e = 0; e < 16; e++) t += In.charAt(n[e] % Ln);
|
|
2801
2802
|
return t;
|
|
2802
2803
|
}
|
|
2803
|
-
function
|
|
2804
|
+
function zn(e) {
|
|
2804
2805
|
let { tenant_id: t, created_at_ts: n, updated_at_ts: r, credential_backed_up: i, confirmed: a, transports: o, ...s } = e;
|
|
2805
2806
|
return D({
|
|
2806
2807
|
...s,
|
|
2807
2808
|
confirmed: !!a,
|
|
2808
2809
|
credential_backed_up: i == null ? void 0 : !!i,
|
|
2809
|
-
transports:
|
|
2810
|
+
transports: Z(o),
|
|
2810
2811
|
created_at: oe(n),
|
|
2811
2812
|
updated_at: oe(r)
|
|
2812
2813
|
});
|
|
2813
2814
|
}
|
|
2814
|
-
function
|
|
2815
|
+
function Bn(e) {
|
|
2815
2816
|
return {
|
|
2816
2817
|
async create(t, n) {
|
|
2817
2818
|
let r = Date.now(), i = {
|
|
2818
|
-
id: n.id ||
|
|
2819
|
+
id: n.id || Rn(),
|
|
2819
2820
|
tenant_id: t,
|
|
2820
2821
|
user_id: n.user_id,
|
|
2821
2822
|
type: n.type,
|
|
@@ -2831,55 +2832,55 @@ function Ln(e) {
|
|
|
2831
2832
|
created_at_ts: r,
|
|
2832
2833
|
updated_at_ts: r
|
|
2833
2834
|
};
|
|
2834
|
-
return await e.insert(
|
|
2835
|
+
return await e.insert(K).values(i), zn({
|
|
2835
2836
|
...i,
|
|
2836
2837
|
tenant_id: t
|
|
2837
2838
|
});
|
|
2838
2839
|
},
|
|
2839
2840
|
async get(n, r) {
|
|
2840
|
-
let i = await e.select().from(
|
|
2841
|
-
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;
|
|
2842
2843
|
},
|
|
2843
2844
|
async getByCredentialId(n, r) {
|
|
2844
|
-
let i = await e.select().from(
|
|
2845
|
-
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;
|
|
2846
2847
|
},
|
|
2847
2848
|
async list(n, r) {
|
|
2848
|
-
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);
|
|
2849
2850
|
},
|
|
2850
2851
|
async update(n, r, i) {
|
|
2851
2852
|
let o = { updated_at_ts: Date.now() };
|
|
2852
|
-
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)));
|
|
2853
2854
|
let s = await this.get(n, r);
|
|
2854
2855
|
if (!s) throw Error(`Authentication method ${r} not found after update`);
|
|
2855
2856
|
return s;
|
|
2856
2857
|
},
|
|
2857
2858
|
async remove(n, r) {
|
|
2858
|
-
return (await e.delete(
|
|
2859
|
+
return (await e.delete(K).where(t(a(K.tenant_id, n), a(K.id, r))).returning()).length > 0;
|
|
2859
2860
|
}
|
|
2860
2861
|
};
|
|
2861
2862
|
}
|
|
2862
2863
|
//#endregion
|
|
2863
2864
|
//#region src/adapters/organizations.ts
|
|
2864
|
-
var
|
|
2865
|
-
function
|
|
2865
|
+
var Vn = ["name", "display_name"];
|
|
2866
|
+
function Hn() {
|
|
2866
2867
|
return `org_${ee("0123456789abcdefghijklmnopqrstuvwxyz", 17)()}`;
|
|
2867
2868
|
}
|
|
2868
|
-
function
|
|
2869
|
+
function Un(e) {
|
|
2869
2870
|
let { tenant_id: t, branding: n, metadata: r, enabled_connections: i, token_quota: a, ...o } = e;
|
|
2870
2871
|
return D({
|
|
2871
2872
|
...o,
|
|
2872
|
-
branding:
|
|
2873
|
-
metadata:
|
|
2874
|
-
enabled_connections:
|
|
2875
|
-
token_quota:
|
|
2873
|
+
branding: Z(n, {}),
|
|
2874
|
+
metadata: Z(r, {}),
|
|
2875
|
+
enabled_connections: Z(i, []),
|
|
2876
|
+
token_quota: Z(a, {})
|
|
2876
2877
|
});
|
|
2877
2878
|
}
|
|
2878
|
-
function
|
|
2879
|
+
function Wn(e) {
|
|
2879
2880
|
return {
|
|
2880
2881
|
async create(t, n) {
|
|
2881
2882
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
2882
|
-
id: n.id ||
|
|
2883
|
+
id: n.id || Hn(),
|
|
2883
2884
|
tenant_id: t,
|
|
2884
2885
|
name: n.name,
|
|
2885
2886
|
display_name: n.display_name,
|
|
@@ -2891,39 +2892,39 @@ function Vn(e) {
|
|
|
2891
2892
|
updated_at: r
|
|
2892
2893
|
};
|
|
2893
2894
|
try {
|
|
2894
|
-
await e.insert(
|
|
2895
|
+
await e.insert(V).values(i);
|
|
2895
2896
|
} catch (e) {
|
|
2896
|
-
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;
|
|
2897
2898
|
}
|
|
2898
|
-
return
|
|
2899
|
+
return Un({
|
|
2899
2900
|
...i,
|
|
2900
2901
|
tenant_id: t
|
|
2901
2902
|
});
|
|
2902
2903
|
},
|
|
2903
2904
|
async get(n, r) {
|
|
2904
|
-
let i = await e.select().from(
|
|
2905
|
-
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;
|
|
2906
2907
|
},
|
|
2907
2908
|
async update(n, r, i) {
|
|
2908
2909
|
let o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
2909
|
-
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;
|
|
2910
2911
|
},
|
|
2911
2912
|
async list(o, s) {
|
|
2912
|
-
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)];
|
|
2913
2914
|
if (f) {
|
|
2914
|
-
let e = we(f,
|
|
2915
|
+
let e = we(f, Vn);
|
|
2915
2916
|
if (e) {
|
|
2916
|
-
let t =
|
|
2917
|
+
let t = mt(V, e, Vn);
|
|
2917
2918
|
t && p.push(t);
|
|
2918
2919
|
}
|
|
2919
2920
|
}
|
|
2920
2921
|
let m = t(...p);
|
|
2921
|
-
if (
|
|
2922
|
+
if (Et(s)) {
|
|
2922
2923
|
let n = {
|
|
2923
|
-
sortColumn:
|
|
2924
|
-
idColumn:
|
|
2924
|
+
sortColumn: V.created_at,
|
|
2925
|
+
idColumn: V.id,
|
|
2925
2926
|
sortOrder: "desc"
|
|
2926
|
-
}, 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);
|
|
2927
2928
|
return {
|
|
2928
2929
|
organizations: c,
|
|
2929
2930
|
start: 0,
|
|
@@ -2933,14 +2934,14 @@ function Vn(e) {
|
|
|
2933
2934
|
next: o
|
|
2934
2935
|
};
|
|
2935
2936
|
}
|
|
2936
|
-
let h = e.select().from(
|
|
2937
|
+
let h = e.select().from(V).where(m).$dynamic();
|
|
2937
2938
|
if (d?.sort_by) {
|
|
2938
|
-
let e =
|
|
2939
|
+
let e = V[d.sort_by];
|
|
2939
2940
|
e && (h = h.orderBy(d.sort_order === "desc" ? i(e) : n(e)));
|
|
2940
2941
|
}
|
|
2941
|
-
let g = (await h.offset(c * l).limit(l)).map(
|
|
2942
|
+
let g = (await h.offset(c * l).limit(l)).map(Un);
|
|
2942
2943
|
if (!u) return { organizations: g };
|
|
2943
|
-
let [_] = await e.select({ count: r() }).from(
|
|
2944
|
+
let [_] = await e.select({ count: r() }).from(V).where(m);
|
|
2944
2945
|
return {
|
|
2945
2946
|
organizations: g,
|
|
2946
2947
|
start: c * l,
|
|
@@ -2949,24 +2950,24 @@ function Vn(e) {
|
|
|
2949
2950
|
};
|
|
2950
2951
|
},
|
|
2951
2952
|
async remove(n, r) {
|
|
2952
|
-
return (await e.delete(
|
|
2953
|
+
return (await e.delete(V).where(t(a(V.tenant_id, n), a(V.id, r))).returning()).length > 0;
|
|
2953
2954
|
}
|
|
2954
2955
|
};
|
|
2955
2956
|
}
|
|
2956
2957
|
//#endregion
|
|
2957
2958
|
//#region src/adapters/passwords.ts
|
|
2958
|
-
function
|
|
2959
|
+
function Gn(e) {
|
|
2959
2960
|
let { tenant_id: t, is_current: n, ...r } = e;
|
|
2960
2961
|
return {
|
|
2961
2962
|
...r,
|
|
2962
2963
|
is_current: !!n
|
|
2963
2964
|
};
|
|
2964
2965
|
}
|
|
2965
|
-
function
|
|
2966
|
+
function Kn(e) {
|
|
2966
2967
|
return {
|
|
2967
2968
|
async create(n, r) {
|
|
2968
2969
|
let i = (/* @__PURE__ */ new Date()).toISOString(), o = r.id || b();
|
|
2969
|
-
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)));
|
|
2970
2971
|
let s = {
|
|
2971
2972
|
id: o,
|
|
2972
2973
|
tenant_id: n,
|
|
@@ -2977,31 +2978,31 @@ function Un(e) {
|
|
|
2977
2978
|
created_at: i,
|
|
2978
2979
|
updated_at: i
|
|
2979
2980
|
};
|
|
2980
|
-
return await e.insert(
|
|
2981
|
+
return await e.insert(j).values(s), Gn({
|
|
2981
2982
|
...s,
|
|
2982
2983
|
tenant_id: n
|
|
2983
2984
|
});
|
|
2984
2985
|
},
|
|
2985
2986
|
async get(n, r) {
|
|
2986
|
-
let i = await e.select().from(
|
|
2987
|
-
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;
|
|
2988
2989
|
},
|
|
2989
2990
|
async list(n, r, o) {
|
|
2990
|
-
let s = e.select().from(
|
|
2991
|
-
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);
|
|
2992
2993
|
},
|
|
2993
2994
|
async update(n, r) {
|
|
2994
2995
|
let i = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
2995
|
-
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;
|
|
2996
2997
|
}
|
|
2997
2998
|
};
|
|
2998
2999
|
}
|
|
2999
3000
|
//#endregion
|
|
3000
3001
|
//#region src/adapters/promptSettings.ts
|
|
3001
|
-
function
|
|
3002
|
+
function qn(e) {
|
|
3002
3003
|
return {
|
|
3003
3004
|
async get(t) {
|
|
3004
|
-
let n = await e.select().from(
|
|
3005
|
+
let n = await e.select().from(et).where(a(et.tenant_id, t)).get();
|
|
3005
3006
|
return n ? {
|
|
3006
3007
|
universal_login_experience: n.universal_login_experience,
|
|
3007
3008
|
identifier_first: !!n.identifier_first,
|
|
@@ -3017,7 +3018,7 @@ function Wn(e) {
|
|
|
3017
3018
|
};
|
|
3018
3019
|
},
|
|
3019
3020
|
async set(t, n) {
|
|
3020
|
-
await e.insert(
|
|
3021
|
+
await e.insert(et).values({
|
|
3021
3022
|
tenant_id: t,
|
|
3022
3023
|
universal_login_experience: n.universal_login_experience,
|
|
3023
3024
|
identifier_first: n.identifier_first,
|
|
@@ -3025,7 +3026,7 @@ function Wn(e) {
|
|
|
3025
3026
|
webauthn_platform_first_factor: n.webauthn_platform_first_factor,
|
|
3026
3027
|
show_last_used_connection: n.show_last_used_connection
|
|
3027
3028
|
}).onConflictDoUpdate({
|
|
3028
|
-
target:
|
|
3029
|
+
target: et.tenant_id,
|
|
3029
3030
|
set: {
|
|
3030
3031
|
universal_login_experience: n.universal_login_experience,
|
|
3031
3032
|
identifier_first: n.identifier_first,
|
|
@@ -3039,7 +3040,7 @@ function Wn(e) {
|
|
|
3039
3040
|
}
|
|
3040
3041
|
//#endregion
|
|
3041
3042
|
//#region src/adapters/proxyRoutes.ts
|
|
3042
|
-
function
|
|
3043
|
+
function Jn(e) {
|
|
3043
3044
|
if (!e) return { path: "/*" };
|
|
3044
3045
|
try {
|
|
3045
3046
|
let t = JSON.parse(e), n = be.safeParse(t);
|
|
@@ -3047,7 +3048,7 @@ function Gn(e) {
|
|
|
3047
3048
|
} catch {}
|
|
3048
3049
|
return { path: "/*" };
|
|
3049
3050
|
}
|
|
3050
|
-
function
|
|
3051
|
+
function Yn(e) {
|
|
3051
3052
|
if (!e) return [];
|
|
3052
3053
|
try {
|
|
3053
3054
|
let t = JSON.parse(e);
|
|
@@ -3062,19 +3063,19 @@ function Kn(e) {
|
|
|
3062
3063
|
return [];
|
|
3063
3064
|
}
|
|
3064
3065
|
}
|
|
3065
|
-
function
|
|
3066
|
+
function Xn(e) {
|
|
3066
3067
|
return {
|
|
3067
3068
|
id: e.id,
|
|
3068
3069
|
tenant_id: e.tenant_id,
|
|
3069
3070
|
custom_domain_id: e.custom_domain_id,
|
|
3070
3071
|
priority: e.priority,
|
|
3071
|
-
match:
|
|
3072
|
-
handlers:
|
|
3072
|
+
match: Jn(e.match),
|
|
3073
|
+
handlers: Yn(e.handlers),
|
|
3073
3074
|
created_at: e.created_at,
|
|
3074
3075
|
updated_at: e.updated_at
|
|
3075
3076
|
};
|
|
3076
3077
|
}
|
|
3077
|
-
function
|
|
3078
|
+
function Zn(e) {
|
|
3078
3079
|
return {
|
|
3079
3080
|
async create(t, n) {
|
|
3080
3081
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
@@ -3087,7 +3088,7 @@ function Jn(e) {
|
|
|
3087
3088
|
created_at: r,
|
|
3088
3089
|
updated_at: r
|
|
3089
3090
|
};
|
|
3090
|
-
return await e.insert(
|
|
3091
|
+
return await e.insert(Y).values({
|
|
3091
3092
|
id: i.id,
|
|
3092
3093
|
tenant_id: i.tenant_id,
|
|
3093
3094
|
custom_domain_id: i.custom_domain_id,
|
|
@@ -3099,15 +3100,15 @@ function Jn(e) {
|
|
|
3099
3100
|
}), i;
|
|
3100
3101
|
},
|
|
3101
3102
|
async get(n, r) {
|
|
3102
|
-
let i = await e.select().from(
|
|
3103
|
-
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;
|
|
3104
3105
|
},
|
|
3105
3106
|
async list(r, i = {}) {
|
|
3106
|
-
let o = i.page ?? 0, s = i.per_page ?? 50, c = [a(
|
|
3107
|
-
i.custom_domain_id && c.push(a(
|
|
3108
|
-
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);
|
|
3109
3110
|
return {
|
|
3110
|
-
proxy_routes: l.map(
|
|
3111
|
+
proxy_routes: l.map(Xn),
|
|
3111
3112
|
start: o * s,
|
|
3112
3113
|
limit: s,
|
|
3113
3114
|
length: l.length
|
|
@@ -3116,17 +3117,17 @@ function Jn(e) {
|
|
|
3116
3117
|
async update(n, r, i) {
|
|
3117
3118
|
let o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
3118
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));
|
|
3119
|
-
let s = (await e.update(
|
|
3120
|
-
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;
|
|
3121
3122
|
},
|
|
3122
3123
|
async remove(n, r) {
|
|
3123
|
-
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);
|
|
3124
3125
|
}
|
|
3125
3126
|
};
|
|
3126
3127
|
}
|
|
3127
3128
|
//#endregion
|
|
3128
3129
|
//#region src/adapters/scim.ts
|
|
3129
|
-
function
|
|
3130
|
+
function Qn(e) {
|
|
3130
3131
|
if (!e) return [];
|
|
3131
3132
|
try {
|
|
3132
3133
|
let t = JSON.parse(e);
|
|
@@ -3141,7 +3142,7 @@ function Yn(e) {
|
|
|
3141
3142
|
return [];
|
|
3142
3143
|
}
|
|
3143
3144
|
}
|
|
3144
|
-
function
|
|
3145
|
+
function $n(e) {
|
|
3145
3146
|
if (!e) return [];
|
|
3146
3147
|
try {
|
|
3147
3148
|
let t = JSON.parse(e);
|
|
@@ -3150,16 +3151,16 @@ function Xn(e) {
|
|
|
3150
3151
|
return [];
|
|
3151
3152
|
}
|
|
3152
3153
|
}
|
|
3153
|
-
function
|
|
3154
|
+
function er(e) {
|
|
3154
3155
|
return {
|
|
3155
3156
|
connection_id: e.connection_id,
|
|
3156
3157
|
user_id_attribute: e.user_id_attribute,
|
|
3157
|
-
mapping:
|
|
3158
|
+
mapping: Qn(e.mapping),
|
|
3158
3159
|
created_at: e.created_at,
|
|
3159
3160
|
updated_at: e.updated_at
|
|
3160
3161
|
};
|
|
3161
3162
|
}
|
|
3162
|
-
function
|
|
3163
|
+
function tr(e) {
|
|
3163
3164
|
return {
|
|
3164
3165
|
async create(t, n) {
|
|
3165
3166
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
@@ -3169,7 +3170,7 @@ function Qn(e) {
|
|
|
3169
3170
|
created_at: r,
|
|
3170
3171
|
updated_at: r
|
|
3171
3172
|
};
|
|
3172
|
-
return await e.insert(
|
|
3173
|
+
return await e.insert(st).values({
|
|
3173
3174
|
connection_id: i.connection_id,
|
|
3174
3175
|
tenant_id: t,
|
|
3175
3176
|
user_id_attribute: i.user_id_attribute,
|
|
@@ -3179,31 +3180,31 @@ function Qn(e) {
|
|
|
3179
3180
|
}), i;
|
|
3180
3181
|
},
|
|
3181
3182
|
async get(n, r) {
|
|
3182
|
-
let i = await e.select().from(
|
|
3183
|
-
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;
|
|
3184
3185
|
},
|
|
3185
3186
|
async update(n, r, i) {
|
|
3186
|
-
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;
|
|
3187
3188
|
let o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
3188
|
-
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;
|
|
3189
3190
|
},
|
|
3190
3191
|
async remove(n, r) {
|
|
3191
|
-
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);
|
|
3192
3193
|
}
|
|
3193
3194
|
};
|
|
3194
3195
|
}
|
|
3195
|
-
function
|
|
3196
|
+
function nr(e) {
|
|
3196
3197
|
return {
|
|
3197
3198
|
token_id: e.token_id,
|
|
3198
3199
|
connection_id: e.connection_id,
|
|
3199
3200
|
token_hash: e.token_hash,
|
|
3200
|
-
scopes:
|
|
3201
|
+
scopes: $n(e.scopes),
|
|
3201
3202
|
valid_until: e.valid_until ?? void 0,
|
|
3202
3203
|
created_at: e.created_at,
|
|
3203
3204
|
last_used_at: e.last_used_at ?? void 0
|
|
3204
3205
|
};
|
|
3205
3206
|
}
|
|
3206
|
-
function
|
|
3207
|
+
function rr(e) {
|
|
3207
3208
|
return {
|
|
3208
3209
|
async create(t, n) {
|
|
3209
3210
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
@@ -3214,7 +3215,7 @@ function er(e) {
|
|
|
3214
3215
|
valid_until: n.valid_until,
|
|
3215
3216
|
created_at: r
|
|
3216
3217
|
};
|
|
3217
|
-
return await e.insert(
|
|
3218
|
+
return await e.insert(X).values({
|
|
3218
3219
|
token_id: i.token_id,
|
|
3219
3220
|
tenant_id: t,
|
|
3220
3221
|
connection_id: i.connection_id,
|
|
@@ -3225,25 +3226,25 @@ function er(e) {
|
|
|
3225
3226
|
}), i;
|
|
3226
3227
|
},
|
|
3227
3228
|
async get(n, r) {
|
|
3228
|
-
let i = await e.select().from(
|
|
3229
|
-
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;
|
|
3230
3231
|
},
|
|
3231
3232
|
async getByHash(n, r) {
|
|
3232
|
-
let i = await e.select().from(
|
|
3233
|
-
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;
|
|
3234
3235
|
},
|
|
3235
3236
|
async listByConnection(n, r) {
|
|
3236
|
-
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);
|
|
3237
3238
|
},
|
|
3238
3239
|
async markUsed(n, r, i) {
|
|
3239
|
-
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);
|
|
3240
3241
|
},
|
|
3241
3242
|
async remove(n, r) {
|
|
3242
|
-
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);
|
|
3243
3244
|
}
|
|
3244
3245
|
};
|
|
3245
3246
|
}
|
|
3246
|
-
function
|
|
3247
|
+
function ir(e) {
|
|
3247
3248
|
return {
|
|
3248
3249
|
connection_id: e.connection_id,
|
|
3249
3250
|
external_id: e.external_id,
|
|
@@ -3251,7 +3252,7 @@ function tr(e) {
|
|
|
3251
3252
|
created_at: e.created_at
|
|
3252
3253
|
};
|
|
3253
3254
|
}
|
|
3254
|
-
function
|
|
3255
|
+
function ar(e) {
|
|
3255
3256
|
return {
|
|
3256
3257
|
async create(t, n) {
|
|
3257
3258
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
@@ -3260,7 +3261,7 @@ function nr(e) {
|
|
|
3260
3261
|
user_id: n.user_id,
|
|
3261
3262
|
created_at: r
|
|
3262
3263
|
};
|
|
3263
|
-
return await e.insert(
|
|
3264
|
+
return await e.insert(ct).values({
|
|
3264
3265
|
tenant_id: t,
|
|
3265
3266
|
connection_id: i.connection_id,
|
|
3266
3267
|
external_id: i.external_id,
|
|
@@ -3269,21 +3270,21 @@ function nr(e) {
|
|
|
3269
3270
|
}), i;
|
|
3270
3271
|
},
|
|
3271
3272
|
async getByExternalId(n, r, i) {
|
|
3272
|
-
let o = await e.select().from(
|
|
3273
|
-
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;
|
|
3274
3275
|
},
|
|
3275
3276
|
async getByUserId(n, r, i) {
|
|
3276
|
-
let o = await e.select().from(
|
|
3277
|
-
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;
|
|
3278
3279
|
},
|
|
3279
3280
|
async remove(n, r, i) {
|
|
3280
|
-
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);
|
|
3281
3282
|
}
|
|
3282
3283
|
};
|
|
3283
3284
|
}
|
|
3284
3285
|
//#endregion
|
|
3285
3286
|
//#region src/adapters/refreshTokens.ts
|
|
3286
|
-
function
|
|
3287
|
+
function or(e) {
|
|
3287
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({
|
|
3288
3289
|
created_at_ts: n,
|
|
3289
3290
|
expires_at_ts: r,
|
|
@@ -3302,18 +3303,18 @@ function rr(e) {
|
|
|
3302
3303
|
...p,
|
|
3303
3304
|
...m,
|
|
3304
3305
|
rotating: !!u,
|
|
3305
|
-
device:
|
|
3306
|
-
resource_servers:
|
|
3306
|
+
device: Z(c, {}),
|
|
3307
|
+
resource_servers: Z(l, []),
|
|
3307
3308
|
...d && f ? { auth_strategy: {
|
|
3308
3309
|
strategy: d,
|
|
3309
3310
|
strategy_type: f
|
|
3310
3311
|
} } : {}
|
|
3311
3312
|
});
|
|
3312
3313
|
}
|
|
3313
|
-
function
|
|
3314
|
+
function sr(e, t) {
|
|
3314
3315
|
return Math.max(e ?? 0, t ?? 0);
|
|
3315
3316
|
}
|
|
3316
|
-
function
|
|
3317
|
+
function cr(e) {
|
|
3317
3318
|
return {
|
|
3318
3319
|
async create(n, r) {
|
|
3319
3320
|
let i = Date.now(), o = {
|
|
@@ -3339,44 +3340,44 @@ function ar(e) {
|
|
|
3339
3340
|
expires_at_ts: E(r.expires_at),
|
|
3340
3341
|
idle_expires_at_ts: E(r.idle_expires_at),
|
|
3341
3342
|
last_exchanged_at_ts: E(r.last_exchanged_at)
|
|
3342
|
-
}, s = [e.insert(
|
|
3343
|
-
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({
|
|
3344
3345
|
expires_at_ts: c,
|
|
3345
3346
|
updated_at_ts: i
|
|
3346
|
-
}).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({
|
|
3347
3348
|
...o,
|
|
3348
3349
|
tenant_id: n
|
|
3349
3350
|
});
|
|
3350
3351
|
},
|
|
3351
3352
|
async get(n, r) {
|
|
3352
|
-
let i = await e.select().from(
|
|
3353
|
-
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;
|
|
3354
3355
|
},
|
|
3355
3356
|
async getByLookup(n, r) {
|
|
3356
|
-
let i = await e.select().from(
|
|
3357
|
-
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;
|
|
3358
3359
|
},
|
|
3359
3360
|
async update(n, r, i, o) {
|
|
3360
3361
|
let s = {};
|
|
3361
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));
|
|
3362
|
-
let c = o?.loginSessionBump, l = c ? E(c.expires_at) : null, u = await e.update(
|
|
3363
|
-
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({
|
|
3364
3365
|
expires_at_ts: l,
|
|
3365
3366
|
updated_at_ts: Date.now()
|
|
3366
|
-
}).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;
|
|
3367
3368
|
},
|
|
3368
3369
|
async list(o, s) {
|
|
3369
|
-
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ?
|
|
3370
|
-
a(
|
|
3371
|
-
...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)],
|
|
3372
3373
|
...p ? [p] : []
|
|
3373
3374
|
], h = m.length === 1 ? m[0] : t(...m);
|
|
3374
|
-
if (
|
|
3375
|
+
if (Et(s)) {
|
|
3375
3376
|
let n = {
|
|
3376
|
-
sortColumn:
|
|
3377
|
-
idColumn:
|
|
3377
|
+
sortColumn: N.created_at_ts,
|
|
3378
|
+
idColumn: N.id,
|
|
3378
3379
|
sortOrder: "desc"
|
|
3379
|
-
}, 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);
|
|
3380
3381
|
return {
|
|
3381
3382
|
refresh_tokens: c,
|
|
3382
3383
|
start: 0,
|
|
@@ -3385,14 +3386,14 @@ function ar(e) {
|
|
|
3385
3386
|
next: o
|
|
3386
3387
|
};
|
|
3387
3388
|
}
|
|
3388
|
-
let g = e.select().from(
|
|
3389
|
+
let g = e.select().from(N).where(h).$dynamic();
|
|
3389
3390
|
if (d?.sort_by) {
|
|
3390
|
-
let e =
|
|
3391
|
+
let e = N[d.sort_by];
|
|
3391
3392
|
e && (g = g.orderBy(d.sort_order === "desc" ? i(e) : n(e)));
|
|
3392
3393
|
}
|
|
3393
|
-
let _ = (await g.offset(c * l).limit(l)).map(
|
|
3394
|
+
let _ = (await g.offset(c * l).limit(l)).map(or);
|
|
3394
3395
|
if (!u) return { refresh_tokens: _ };
|
|
3395
|
-
let [v] = await e.select({ count: r() }).from(
|
|
3396
|
+
let [v] = await e.select({ count: r() }).from(N).where(h);
|
|
3396
3397
|
return {
|
|
3397
3398
|
refresh_tokens: _,
|
|
3398
3399
|
start: c * l,
|
|
@@ -3401,33 +3402,33 @@ function ar(e) {
|
|
|
3401
3402
|
};
|
|
3402
3403
|
},
|
|
3403
3404
|
async remove(n, r) {
|
|
3404
|
-
return (await e.delete(
|
|
3405
|
+
return (await e.delete(N).where(t(a(N.tenant_id, n), a(N.id, r))).returning()).length > 0;
|
|
3405
3406
|
},
|
|
3406
3407
|
async revokeByUser(n, r, i) {
|
|
3407
|
-
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;
|
|
3408
3409
|
},
|
|
3409
3410
|
async revokeByLoginSession(n, r, i) {
|
|
3410
|
-
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;
|
|
3411
3412
|
},
|
|
3412
3413
|
async revokeBySession(n, r, i) {
|
|
3413
|
-
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;
|
|
3414
3415
|
},
|
|
3415
3416
|
async revokeFamily(n, r, i) {
|
|
3416
|
-
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;
|
|
3417
3418
|
}
|
|
3418
3419
|
};
|
|
3419
3420
|
}
|
|
3420
3421
|
//#endregion
|
|
3421
3422
|
//#region src/adapters/resourceServers.ts
|
|
3422
|
-
var
|
|
3423
|
-
function
|
|
3423
|
+
var lr = ["name", "identifier"];
|
|
3424
|
+
function ur() {
|
|
3424
3425
|
return `api_${ee("0123456789abcdefghijklmnopqrstuvwxyz", 17)()}`;
|
|
3425
3426
|
}
|
|
3426
|
-
var
|
|
3427
|
+
var dr = [
|
|
3427
3428
|
"skip_consent_for_verifiable_first_party_clients",
|
|
3428
3429
|
"allow_offline_access",
|
|
3429
3430
|
"is_system"
|
|
3430
|
-
],
|
|
3431
|
+
], fr = new Set([
|
|
3431
3432
|
"id",
|
|
3432
3433
|
"tenant_id",
|
|
3433
3434
|
"identifier",
|
|
@@ -3446,17 +3447,17 @@ var cr = [
|
|
|
3446
3447
|
"created_at",
|
|
3447
3448
|
"updated_at"
|
|
3448
3449
|
]);
|
|
3449
|
-
function
|
|
3450
|
+
function pr(e) {
|
|
3450
3451
|
let { tenant_id: t, verification_key: n, scopes: r, options: i, metadata: a, ...o } = e, s = { ...o };
|
|
3451
|
-
s.scopes =
|
|
3452
|
-
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]);
|
|
3453
3454
|
return D(s);
|
|
3454
3455
|
}
|
|
3455
|
-
function
|
|
3456
|
+
function mr(e) {
|
|
3456
3457
|
return {
|
|
3457
3458
|
async create(t, n) {
|
|
3458
3459
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
3459
|
-
id: n.id ||
|
|
3460
|
+
id: n.id || ur(),
|
|
3460
3461
|
tenant_id: t,
|
|
3461
3462
|
identifier: n.identifier,
|
|
3462
3463
|
name: n.name,
|
|
@@ -3471,39 +3472,39 @@ function dr(e) {
|
|
|
3471
3472
|
created_at: r,
|
|
3472
3473
|
updated_at: r
|
|
3473
3474
|
};
|
|
3474
|
-
for (let e of
|
|
3475
|
-
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({
|
|
3476
3477
|
...i,
|
|
3477
3478
|
tenant_id: t
|
|
3478
3479
|
});
|
|
3479
3480
|
},
|
|
3480
3481
|
async get(n, r) {
|
|
3481
|
-
let i = await e.select().from(
|
|
3482
|
-
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;
|
|
3483
3484
|
},
|
|
3484
3485
|
async update(n, r, i) {
|
|
3485
3486
|
let o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
3486
|
-
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(${
|
|
3487
|
-
for (let e of
|
|
3488
|
-
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;
|
|
3489
3490
|
},
|
|
3490
3491
|
async list(o, s) {
|
|
3491
|
-
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)];
|
|
3492
3493
|
if (f) {
|
|
3493
|
-
let e = we(f,
|
|
3494
|
+
let e = we(f, lr);
|
|
3494
3495
|
if (e) {
|
|
3495
|
-
let t =
|
|
3496
|
+
let t = mt(G, e, lr, ["name", "identifier"]);
|
|
3496
3497
|
t && h.push(t);
|
|
3497
3498
|
}
|
|
3498
3499
|
}
|
|
3499
|
-
let g = e.select().from(
|
|
3500
|
-
if (d?.sort_by &&
|
|
3501
|
-
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];
|
|
3502
3503
|
g = g.orderBy(d.sort_order === "desc" ? i(e) : n(e));
|
|
3503
3504
|
}
|
|
3504
|
-
let _ = (await g.offset(p * m).limit(m)).map(
|
|
3505
|
+
let _ = (await g.offset(p * m).limit(m)).map(pr);
|
|
3505
3506
|
if (!u) return { resource_servers: _ };
|
|
3506
|
-
let [v] = await e.select({ count: r() }).from(
|
|
3507
|
+
let [v] = await e.select({ count: r() }).from(G).where(t(...h));
|
|
3507
3508
|
return {
|
|
3508
3509
|
resource_servers: _,
|
|
3509
3510
|
start: p * m,
|
|
@@ -3512,18 +3513,18 @@ function dr(e) {
|
|
|
3512
3513
|
};
|
|
3513
3514
|
},
|
|
3514
3515
|
async remove(n, r) {
|
|
3515
|
-
return (await e.delete(
|
|
3516
|
+
return (await e.delete(G).where(t(a(G.tenant_id, n), a(G.id, r))).returning()).length > 0;
|
|
3516
3517
|
}
|
|
3517
3518
|
};
|
|
3518
3519
|
}
|
|
3519
3520
|
//#endregion
|
|
3520
3521
|
//#region src/adapters/rolePermissions.ts
|
|
3521
|
-
function
|
|
3522
|
+
function hr(e) {
|
|
3522
3523
|
return {
|
|
3523
3524
|
async assign(t, n, r) {
|
|
3524
3525
|
if (r.length === 0) return !0;
|
|
3525
3526
|
let i = (/* @__PURE__ */ new Date()).toISOString();
|
|
3526
|
-
return await e.insert(
|
|
3527
|
+
return await e.insert(qe).values(r.map((e) => ({
|
|
3527
3528
|
tenant_id: t,
|
|
3528
3529
|
role_id: n,
|
|
3529
3530
|
resource_server_identifier: e.resource_server_identifier,
|
|
@@ -3533,15 +3534,15 @@ function fr(e) {
|
|
|
3533
3534
|
},
|
|
3534
3535
|
async list(n, r, i) {
|
|
3535
3536
|
let o = await e.select({
|
|
3536
|
-
resource_server_identifier:
|
|
3537
|
-
permission_name:
|
|
3538
|
-
created_at:
|
|
3539
|
-
}).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();
|
|
3540
3541
|
if (s.length > 0) {
|
|
3541
3542
|
let r = await e.select({
|
|
3542
|
-
identifier:
|
|
3543
|
-
name:
|
|
3544
|
-
}).from(
|
|
3543
|
+
identifier: G.identifier,
|
|
3544
|
+
name: G.name
|
|
3545
|
+
}).from(G).where(t(a(G.tenant_id, n), l(G.identifier, s))).all();
|
|
3545
3546
|
for (let e of r) c.set(e.identifier, e.name);
|
|
3546
3547
|
}
|
|
3547
3548
|
return o.map((e) => ({
|
|
@@ -3551,18 +3552,18 @@ function fr(e) {
|
|
|
3551
3552
|
},
|
|
3552
3553
|
async remove(n, r, i) {
|
|
3553
3554
|
if (i.length === 0) return !0;
|
|
3554
|
-
let o = i.map((e) => t(a(
|
|
3555
|
-
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;
|
|
3556
3557
|
}
|
|
3557
3558
|
};
|
|
3558
3559
|
}
|
|
3559
3560
|
//#endregion
|
|
3560
3561
|
//#region src/adapters/userPermissions.ts
|
|
3561
|
-
function
|
|
3562
|
+
function gr(e) {
|
|
3562
3563
|
return {
|
|
3563
3564
|
async create(t, n, r, i) {
|
|
3564
3565
|
try {
|
|
3565
|
-
await e.insert(
|
|
3566
|
+
await e.insert(Je).values({
|
|
3566
3567
|
tenant_id: t,
|
|
3567
3568
|
user_id: n,
|
|
3568
3569
|
resource_server_identifier: r.resource_server_identifier,
|
|
@@ -3577,11 +3578,11 @@ function pr(e) {
|
|
|
3577
3578
|
return !0;
|
|
3578
3579
|
},
|
|
3579
3580
|
async list(n, r, i, o) {
|
|
3580
|
-
let s = [a(
|
|
3581
|
-
o && s.push(a(
|
|
3582
|
-
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();
|
|
3583
3584
|
return await Promise.all(c.map(async (r) => {
|
|
3584
|
-
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();
|
|
3585
3586
|
return {
|
|
3586
3587
|
resource_server_identifier: r.resource_server_identifier,
|
|
3587
3588
|
permission_name: r.permission_name,
|
|
@@ -3591,21 +3592,21 @@ function pr(e) {
|
|
|
3591
3592
|
}));
|
|
3592
3593
|
},
|
|
3593
3594
|
async remove(n, r, i, o) {
|
|
3594
|
-
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;
|
|
3595
3596
|
}
|
|
3596
3597
|
};
|
|
3597
3598
|
}
|
|
3598
3599
|
//#endregion
|
|
3599
3600
|
//#region src/adapters/roles.ts
|
|
3600
|
-
function
|
|
3601
|
+
function _r(e) {
|
|
3601
3602
|
let { tenant_id: t, is_system: n, metadata: r, ...i } = e;
|
|
3602
3603
|
return D({
|
|
3603
3604
|
...i,
|
|
3604
3605
|
is_system: n ? !0 : void 0,
|
|
3605
|
-
metadata:
|
|
3606
|
+
metadata: Z(r)
|
|
3606
3607
|
});
|
|
3607
3608
|
}
|
|
3608
|
-
function
|
|
3609
|
+
function vr(e) {
|
|
3609
3610
|
return {
|
|
3610
3611
|
async create(t, n) {
|
|
3611
3612
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
@@ -3618,28 +3619,28 @@ function hr(e) {
|
|
|
3618
3619
|
created_at: r,
|
|
3619
3620
|
updated_at: r
|
|
3620
3621
|
};
|
|
3621
|
-
return await e.insert(
|
|
3622
|
+
return await e.insert(U).values(i), _r({
|
|
3622
3623
|
...i,
|
|
3623
3624
|
tenant_id: t
|
|
3624
3625
|
});
|
|
3625
3626
|
},
|
|
3626
3627
|
async get(n, r) {
|
|
3627
|
-
let i = await e.select().from(
|
|
3628
|
-
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;
|
|
3629
3630
|
},
|
|
3630
3631
|
async update(n, r, i) {
|
|
3631
3632
|
let o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
3632
|
-
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;
|
|
3633
3634
|
},
|
|
3634
3635
|
async list(o, s) {
|
|
3635
|
-
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();
|
|
3636
3637
|
if (d?.sort_by) {
|
|
3637
|
-
let e =
|
|
3638
|
+
let e = U[d.sort_by];
|
|
3638
3639
|
e && (h = h.orderBy(d.sort_order === "desc" ? i(e) : n(e)));
|
|
3639
3640
|
}
|
|
3640
|
-
let g = (await h.offset(c * l).limit(l)).map(
|
|
3641
|
+
let g = (await h.offset(c * l).limit(l)).map(_r);
|
|
3641
3642
|
if (!u) return { roles: g };
|
|
3642
|
-
let [_] = await e.select({ count: r() }).from(
|
|
3643
|
+
let [_] = await e.select({ count: r() }).from(U).where(m);
|
|
3643
3644
|
return {
|
|
3644
3645
|
roles: g,
|
|
3645
3646
|
start: c * l,
|
|
@@ -3648,13 +3649,13 @@ function hr(e) {
|
|
|
3648
3649
|
};
|
|
3649
3650
|
},
|
|
3650
3651
|
async remove(n, r) {
|
|
3651
|
-
return (await e.delete(
|
|
3652
|
+
return (await e.delete(U).where(t(a(U.tenant_id, n), a(U.id, r))).returning()).length > 0;
|
|
3652
3653
|
}
|
|
3653
3654
|
};
|
|
3654
3655
|
}
|
|
3655
3656
|
//#endregion
|
|
3656
3657
|
//#region src/adapters/sessions.ts
|
|
3657
|
-
var
|
|
3658
|
+
var yr = ["created_at_ts", "updated_at_ts"], br = [
|
|
3658
3659
|
"expires_at_ts",
|
|
3659
3660
|
"idle_expires_at_ts",
|
|
3660
3661
|
"authenticated_at_ts",
|
|
@@ -3662,7 +3663,7 @@ var gr = ["created_at_ts", "updated_at_ts"], _r = [
|
|
|
3662
3663
|
"used_at_ts",
|
|
3663
3664
|
"revoked_at_ts"
|
|
3664
3665
|
];
|
|
3665
|
-
function
|
|
3666
|
+
function xr(e) {
|
|
3666
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({
|
|
3667
3668
|
created_at_ts: n,
|
|
3668
3669
|
updated_at_ts: r,
|
|
@@ -3672,18 +3673,18 @@ function vr(e) {
|
|
|
3672
3673
|
last_interaction_at_ts: s,
|
|
3673
3674
|
used_at_ts: c,
|
|
3674
3675
|
revoked_at_ts: l
|
|
3675
|
-
}, [...
|
|
3676
|
+
}, [...yr], [...br]);
|
|
3676
3677
|
return D({
|
|
3677
3678
|
...f,
|
|
3678
3679
|
...p,
|
|
3679
|
-
device:
|
|
3680
|
-
clients:
|
|
3680
|
+
device: Z(u, {}),
|
|
3681
|
+
clients: Z(d, [])
|
|
3681
3682
|
});
|
|
3682
3683
|
}
|
|
3683
|
-
function
|
|
3684
|
+
function Sr(e, t) {
|
|
3684
3685
|
return Math.max(e ?? 0, t ?? 0);
|
|
3685
3686
|
}
|
|
3686
|
-
function
|
|
3687
|
+
function Cr(e) {
|
|
3687
3688
|
return {
|
|
3688
3689
|
async create(n, r) {
|
|
3689
3690
|
let i = Date.now(), o = {
|
|
@@ -3701,41 +3702,41 @@ function br(e) {
|
|
|
3701
3702
|
last_interaction_at_ts: r.last_interaction_at ? E(r.last_interaction_at) : i,
|
|
3702
3703
|
used_at_ts: E(r.used_at),
|
|
3703
3704
|
revoked_at_ts: E(r.revoked_at)
|
|
3704
|
-
}, s = [e.insert(
|
|
3705
|
-
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({
|
|
3706
3707
|
expires_at_ts: c,
|
|
3707
3708
|
updated_at_ts: i
|
|
3708
|
-
}).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({
|
|
3709
3710
|
...o,
|
|
3710
3711
|
tenant_id: n
|
|
3711
3712
|
});
|
|
3712
3713
|
},
|
|
3713
3714
|
async get(n, r) {
|
|
3714
|
-
let i = await e.select().from(
|
|
3715
|
-
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;
|
|
3716
3717
|
},
|
|
3717
3718
|
async update(n, r, i) {
|
|
3718
3719
|
let o = { updated_at_ts: Date.now() };
|
|
3719
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));
|
|
3720
|
-
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];
|
|
3721
3722
|
if (c > 0 && l) {
|
|
3722
3723
|
let r = i.login_session_id ?? l.login_session_id;
|
|
3723
|
-
r && await e.update(
|
|
3724
|
+
r && await e.update(P).set({
|
|
3724
3725
|
expires_at_ts: c,
|
|
3725
3726
|
updated_at_ts: Date.now()
|
|
3726
|
-
}).where(t(a(
|
|
3727
|
+
}).where(t(a(P.tenant_id, n), a(P.id, r), m(P.expires_at_ts, c))).catch(() => {});
|
|
3727
3728
|
}
|
|
3728
3729
|
return s.length > 0;
|
|
3729
3730
|
},
|
|
3730
3731
|
async list(o, s) {
|
|
3731
|
-
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();
|
|
3732
3733
|
if (d?.sort_by) {
|
|
3733
|
-
let e =
|
|
3734
|
+
let e = M[d.sort_by];
|
|
3734
3735
|
e && (h = h.orderBy(d.sort_order === "desc" ? i(e) : n(e)));
|
|
3735
3736
|
}
|
|
3736
|
-
let g = (await h.offset(c * l).limit(l)).map(
|
|
3737
|
+
let g = (await h.offset(c * l).limit(l)).map(xr);
|
|
3737
3738
|
if (!u) return { sessions: g };
|
|
3738
|
-
let [_] = await e.select({ count: r() }).from(
|
|
3739
|
+
let [_] = await e.select({ count: r() }).from(M).where(m);
|
|
3739
3740
|
return {
|
|
3740
3741
|
sessions: g,
|
|
3741
3742
|
start: c * l,
|
|
@@ -3744,13 +3745,13 @@ function br(e) {
|
|
|
3744
3745
|
};
|
|
3745
3746
|
},
|
|
3746
3747
|
async remove(n, r) {
|
|
3747
|
-
return (await e.delete(
|
|
3748
|
+
return (await e.delete(M).where(t(a(M.tenant_id, n), a(M.id, r))).returning()).length > 0;
|
|
3748
3749
|
}
|
|
3749
3750
|
};
|
|
3750
3751
|
}
|
|
3751
3752
|
//#endregion
|
|
3752
3753
|
//#region src/adapters/tenants.ts
|
|
3753
|
-
var
|
|
3754
|
+
var wr = [
|
|
3754
3755
|
"session_cookie",
|
|
3755
3756
|
"enabled_locales",
|
|
3756
3757
|
"error_page",
|
|
@@ -3766,25 +3767,25 @@ var xr = [
|
|
|
3766
3767
|
"acr_values_supported",
|
|
3767
3768
|
"mtls",
|
|
3768
3769
|
"mfa"
|
|
3769
|
-
],
|
|
3770
|
+
], Tr = [
|
|
3770
3771
|
"allow_organization_name_in_authentication_api",
|
|
3771
3772
|
"customize_mfa_in_postlogin_action",
|
|
3772
3773
|
"pushed_authorization_requests_supported",
|
|
3773
3774
|
"authorization_response_iss_parameter_supported"
|
|
3774
3775
|
];
|
|
3775
|
-
function
|
|
3776
|
+
function Er(e) {
|
|
3776
3777
|
let t = { ...e };
|
|
3777
|
-
for (let e of
|
|
3778
|
-
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);
|
|
3779
3780
|
return D(t);
|
|
3780
3781
|
}
|
|
3781
|
-
function
|
|
3782
|
+
function Dr(e) {
|
|
3782
3783
|
let t = { ...e };
|
|
3783
|
-
le(e,
|
|
3784
|
-
for (let n of
|
|
3784
|
+
le(e, wr, t);
|
|
3785
|
+
for (let n of Tr) e[n] !== void 0 && (t[n] = +!!e[n]);
|
|
3785
3786
|
return ce(t);
|
|
3786
3787
|
}
|
|
3787
|
-
function
|
|
3788
|
+
function Or(e) {
|
|
3788
3789
|
return {
|
|
3789
3790
|
async create(t) {
|
|
3790
3791
|
let n = {
|
|
@@ -3792,26 +3793,26 @@ function Tr(e) {
|
|
|
3792
3793
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3793
3794
|
updated_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3794
3795
|
...t
|
|
3795
|
-
}, r =
|
|
3796
|
+
}, r = Dr(n);
|
|
3796
3797
|
try {
|
|
3797
3798
|
await e.insert(O).values(r);
|
|
3798
3799
|
} catch (e) {
|
|
3799
3800
|
let t = e?.message ?? "";
|
|
3800
|
-
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;
|
|
3801
3802
|
}
|
|
3802
3803
|
return n;
|
|
3803
3804
|
},
|
|
3804
3805
|
async get(t) {
|
|
3805
3806
|
let n = await e.select().from(O).where(a(O.id, t)).get();
|
|
3806
|
-
return n ?
|
|
3807
|
+
return n ? Er(n) : null;
|
|
3807
3808
|
},
|
|
3808
3809
|
async list(t) {
|
|
3809
|
-
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();
|
|
3810
3811
|
if (u && (d = d.where(u)), c?.sort_by) {
|
|
3811
3812
|
let e = O[c.sort_by];
|
|
3812
3813
|
e && (d = d.orderBy(c.sort_order === "desc" ? i(e) : n(e)));
|
|
3813
3814
|
}
|
|
3814
|
-
let f = (await d.offset(a * o).limit(o)).map(
|
|
3815
|
+
let f = (await d.offset(a * o).limit(o)).map(Er);
|
|
3815
3816
|
if (!s) return { tenants: f };
|
|
3816
3817
|
let p = e.select({ count: r() }).from(O).$dynamic();
|
|
3817
3818
|
u && (p = p.where(u));
|
|
@@ -3824,7 +3825,7 @@ function Tr(e) {
|
|
|
3824
3825
|
};
|
|
3825
3826
|
},
|
|
3826
3827
|
async update(t, n) {
|
|
3827
|
-
let r =
|
|
3828
|
+
let r = Dr({
|
|
3828
3829
|
...n,
|
|
3829
3830
|
id: t,
|
|
3830
3831
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
@@ -3838,62 +3839,62 @@ function Tr(e) {
|
|
|
3838
3839
|
}
|
|
3839
3840
|
//#endregion
|
|
3840
3841
|
//#region src/adapters/themes.ts
|
|
3841
|
-
var
|
|
3842
|
+
var kr = [
|
|
3842
3843
|
"colors",
|
|
3843
3844
|
"borders",
|
|
3844
3845
|
"fonts",
|
|
3845
3846
|
"page_background",
|
|
3846
3847
|
"widget"
|
|
3847
3848
|
];
|
|
3848
|
-
function
|
|
3849
|
-
let { tenant_id: t, ...n } = e, r =
|
|
3849
|
+
function Ar(e) {
|
|
3850
|
+
let { tenant_id: t, ...n } = e, r = dt(n, kr);
|
|
3850
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);
|
|
3851
3852
|
}
|
|
3852
|
-
function
|
|
3853
|
+
function jr(e) {
|
|
3853
3854
|
return {
|
|
3854
3855
|
async create(t, n, r, i) {
|
|
3855
3856
|
let a = i?.importMetadata, o = (/* @__PURE__ */ new Date()).toISOString(), s = a?.id || r || b(), c = {
|
|
3856
|
-
...
|
|
3857
|
+
...ut(n),
|
|
3857
3858
|
tenant_id: t,
|
|
3858
3859
|
themeId: s,
|
|
3859
3860
|
created_at: a?.created_at ?? o,
|
|
3860
3861
|
updated_at: a?.updated_at ?? o
|
|
3861
3862
|
};
|
|
3862
|
-
return await e.insert(
|
|
3863
|
+
return await e.insert(Ze).values(c), Ar({
|
|
3863
3864
|
...c,
|
|
3864
3865
|
tenant_id: t
|
|
3865
3866
|
});
|
|
3866
3867
|
},
|
|
3867
3868
|
async get(n, r) {
|
|
3868
|
-
let i = await e.select().from(
|
|
3869
|
-
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;
|
|
3870
3871
|
},
|
|
3871
3872
|
async update(n, r, i) {
|
|
3872
|
-
let o =
|
|
3873
|
-
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;
|
|
3874
3875
|
},
|
|
3875
3876
|
async remove(n, r) {
|
|
3876
|
-
return (await e.delete(
|
|
3877
|
+
return (await e.delete(Ze).where(t(a(Ze.tenant_id, n), a(Ze.themeId, r))).returning()).length > 0;
|
|
3877
3878
|
}
|
|
3878
3879
|
};
|
|
3879
3880
|
}
|
|
3880
3881
|
//#endregion
|
|
3881
3882
|
//#region src/adapters/universalLoginTemplates.ts
|
|
3882
|
-
function
|
|
3883
|
+
function Mr(e) {
|
|
3883
3884
|
return {
|
|
3884
3885
|
async get(t) {
|
|
3885
|
-
let n = await e.select({ body:
|
|
3886
|
+
let n = await e.select({ body: Xe.body }).from(Xe).where(a(Xe.tenant_id, t)).get();
|
|
3886
3887
|
return n ? { body: n.body } : null;
|
|
3887
3888
|
},
|
|
3888
3889
|
async set(t, n) {
|
|
3889
3890
|
let r = Date.now();
|
|
3890
|
-
await e.insert(
|
|
3891
|
+
await e.insert(Xe).values({
|
|
3891
3892
|
tenant_id: t,
|
|
3892
3893
|
body: n.body,
|
|
3893
3894
|
created_at_ts: r,
|
|
3894
3895
|
updated_at_ts: r
|
|
3895
3896
|
}).onConflictDoUpdate({
|
|
3896
|
-
target:
|
|
3897
|
+
target: Xe.tenant_id,
|
|
3897
3898
|
set: {
|
|
3898
3899
|
body: n.body,
|
|
3899
3900
|
updated_at_ts: r
|
|
@@ -3901,20 +3902,20 @@ function kr(e) {
|
|
|
3901
3902
|
});
|
|
3902
3903
|
},
|
|
3903
3904
|
async delete(t) {
|
|
3904
|
-
await e.delete(
|
|
3905
|
+
await e.delete(Xe).where(a(Xe.tenant_id, t));
|
|
3905
3906
|
}
|
|
3906
3907
|
};
|
|
3907
3908
|
}
|
|
3908
3909
|
//#endregion
|
|
3909
3910
|
//#region src/adapters/userActivity.ts
|
|
3910
|
-
function
|
|
3911
|
+
function Nr(e) {
|
|
3911
3912
|
let t = {};
|
|
3912
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;
|
|
3913
3914
|
}
|
|
3914
|
-
function
|
|
3915
|
+
function Pr(e) {
|
|
3915
3916
|
return {
|
|
3916
3917
|
async get(n, r) {
|
|
3917
|
-
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();
|
|
3918
3919
|
return i ? {
|
|
3919
3920
|
user_id: i.user_id,
|
|
3920
3921
|
last_login: i.last_login ?? void 0,
|
|
@@ -3925,7 +3926,7 @@ function jr(e) {
|
|
|
3925
3926
|
} : null;
|
|
3926
3927
|
},
|
|
3927
3928
|
async upsert(t, n, r) {
|
|
3928
|
-
let i =
|
|
3929
|
+
let i = Nr(r), a = e.insert(Be).values({
|
|
3929
3930
|
tenant_id: t,
|
|
3930
3931
|
user_id: n,
|
|
3931
3932
|
login_count: 0,
|
|
@@ -3936,7 +3937,7 @@ function jr(e) {
|
|
|
3936
3937
|
return;
|
|
3937
3938
|
}
|
|
3938
3939
|
await a.onConflictDoUpdate({
|
|
3939
|
-
target: [
|
|
3940
|
+
target: [Be.tenant_id, Be.user_id],
|
|
3940
3941
|
set: i
|
|
3941
3942
|
});
|
|
3942
3943
|
}
|
|
@@ -3944,14 +3945,14 @@ function jr(e) {
|
|
|
3944
3945
|
}
|
|
3945
3946
|
//#endregion
|
|
3946
3947
|
//#region src/adapters/outbox.ts
|
|
3947
|
-
function
|
|
3948
|
+
function Fr(e) {
|
|
3948
3949
|
return {
|
|
3949
3950
|
...e,
|
|
3950
|
-
payload:
|
|
3951
|
+
payload: Z(e.payload, {})
|
|
3951
3952
|
};
|
|
3952
3953
|
}
|
|
3953
|
-
function
|
|
3954
|
-
return e.insert(
|
|
3954
|
+
function Ir(e, t, n, r) {
|
|
3955
|
+
return e.insert(J).values({
|
|
3955
3956
|
id: t,
|
|
3956
3957
|
tenant_id: n,
|
|
3957
3958
|
event_type: r.event_type,
|
|
@@ -3971,53 +3972,53 @@ function Nr(e, t, n, r) {
|
|
|
3971
3972
|
claim_expires_at: null
|
|
3972
3973
|
});
|
|
3973
3974
|
}
|
|
3974
|
-
function
|
|
3975
|
+
function Lr(e) {
|
|
3975
3976
|
return {
|
|
3976
3977
|
async create(t, n) {
|
|
3977
3978
|
let r = b();
|
|
3978
|
-
return await
|
|
3979
|
+
return await Ir(e, r, t, n), r;
|
|
3979
3980
|
},
|
|
3980
3981
|
async getByIds(t) {
|
|
3981
|
-
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);
|
|
3982
3983
|
},
|
|
3983
3984
|
async getUnprocessed(n) {
|
|
3984
3985
|
let r = (/* @__PURE__ */ new Date()).toISOString();
|
|
3985
|
-
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);
|
|
3986
3987
|
},
|
|
3987
3988
|
async claimEvents(n, r, i) {
|
|
3988
3989
|
if (n.length === 0) return [];
|
|
3989
3990
|
let o = (/* @__PURE__ */ new Date()).toISOString(), s = new Date(Date.now() + i).toISOString();
|
|
3990
|
-
return await e.update(
|
|
3991
|
+
return await e.update(J).set({
|
|
3991
3992
|
claimed_by: r,
|
|
3992
3993
|
claim_expires_at: s
|
|
3993
|
-
}).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);
|
|
3994
3995
|
},
|
|
3995
3996
|
async markProcessed(t) {
|
|
3996
|
-
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));
|
|
3997
3998
|
},
|
|
3998
3999
|
async markRetry(t, n, r) {
|
|
3999
|
-
await e.update(
|
|
4000
|
+
await e.update(J).set({
|
|
4000
4001
|
error: n,
|
|
4001
4002
|
next_retry_at: r,
|
|
4002
|
-
retry_count: y`${
|
|
4003
|
+
retry_count: y`${J.retry_count} + 1`,
|
|
4003
4004
|
claimed_by: null,
|
|
4004
4005
|
claim_expires_at: null
|
|
4005
|
-
}).where(a(
|
|
4006
|
+
}).where(a(J.id, t));
|
|
4006
4007
|
},
|
|
4007
4008
|
async cleanup(n) {
|
|
4008
|
-
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;
|
|
4009
4010
|
},
|
|
4010
4011
|
async deadLetter(t, n) {
|
|
4011
4012
|
let r = (/* @__PURE__ */ new Date()).toISOString();
|
|
4012
|
-
await e.update(
|
|
4013
|
+
await e.update(J).set({
|
|
4013
4014
|
processed_at: r,
|
|
4014
4015
|
dead_lettered_at: r,
|
|
4015
4016
|
final_error: n
|
|
4016
|
-
}).where(a(
|
|
4017
|
+
}).where(a(J.id, t));
|
|
4017
4018
|
},
|
|
4018
4019
|
async listFailed(o, s = {}) {
|
|
4019
|
-
let { page: c = 0, per_page: l = 50, include_totals: u = !1 } = s, f = (await e.select().from(
|
|
4020
|
-
...
|
|
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, {}),
|
|
4021
4022
|
id: e.id,
|
|
4022
4023
|
created_at: e.created_at,
|
|
4023
4024
|
processed_at: e.processed_at,
|
|
@@ -4028,7 +4029,7 @@ function Pr(e) {
|
|
|
4028
4029
|
final_error: e.final_error
|
|
4029
4030
|
})), p = f.length;
|
|
4030
4031
|
if (u) {
|
|
4031
|
-
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)));
|
|
4032
4033
|
p = Number(n?.total ?? f.length);
|
|
4033
4034
|
}
|
|
4034
4035
|
return {
|
|
@@ -4039,23 +4040,25 @@ function Pr(e) {
|
|
|
4039
4040
|
};
|
|
4040
4041
|
},
|
|
4041
4042
|
async replay(n, r) {
|
|
4042
|
-
return (await e.update(
|
|
4043
|
+
return (await e.update(J).set({
|
|
4043
4044
|
processed_at: null,
|
|
4044
4045
|
dead_lettered_at: null,
|
|
4045
4046
|
final_error: null,
|
|
4046
4047
|
retry_count: 0,
|
|
4047
4048
|
next_retry_at: null,
|
|
4048
|
-
error: null
|
|
4049
|
-
|
|
4049
|
+
error: null,
|
|
4050
|
+
claimed_by: null,
|
|
4051
|
+
claim_expires_at: null
|
|
4052
|
+
}).where(t(a(J.id, n), a(J.tenant_id, r), d(J.dead_lettered_at))).returning()).length > 0;
|
|
4050
4053
|
}
|
|
4051
4054
|
};
|
|
4052
4055
|
}
|
|
4053
4056
|
//#endregion
|
|
4054
4057
|
//#region src/adapters/users.ts
|
|
4055
|
-
function
|
|
4056
|
-
return (n?.outboxEvents ?? []).map((n) =>
|
|
4058
|
+
function Rr(e, t, n) {
|
|
4059
|
+
return (n?.outboxEvents ?? []).map((n) => Ir(e, n.id, t, n));
|
|
4057
4060
|
}
|
|
4058
|
-
var
|
|
4061
|
+
var zr = [
|
|
4059
4062
|
"user_id",
|
|
4060
4063
|
"email",
|
|
4061
4064
|
"email_verified",
|
|
@@ -4077,23 +4080,23 @@ var Ir = [
|
|
|
4077
4080
|
"login_count",
|
|
4078
4081
|
"created_at",
|
|
4079
4082
|
"updated_at"
|
|
4080
|
-
],
|
|
4083
|
+
], Br = [
|
|
4081
4084
|
"email",
|
|
4082
4085
|
"name",
|
|
4083
4086
|
"phone_number",
|
|
4084
4087
|
"user_id"
|
|
4085
|
-
],
|
|
4088
|
+
], Vr = new Set([
|
|
4086
4089
|
"last_login",
|
|
4087
4090
|
"last_ip",
|
|
4088
4091
|
"login_count"
|
|
4089
|
-
]),
|
|
4090
|
-
coalesce:
|
|
4092
|
+
]), Hr = o(A), Ur = o(Be), Wr = Object.fromEntries(zr.map((e) => [e, e === "login_count" ? {
|
|
4093
|
+
coalesce: Be.login_count,
|
|
4091
4094
|
defaultValue: 0
|
|
4092
|
-
} :
|
|
4093
|
-
function
|
|
4094
|
-
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));
|
|
4095
4098
|
}
|
|
4096
|
-
function
|
|
4099
|
+
function Kr(e, t) {
|
|
4097
4100
|
return {
|
|
4098
4101
|
...e,
|
|
4099
4102
|
last_login: t?.last_login,
|
|
@@ -4101,7 +4104,7 @@ function Ur(e, t) {
|
|
|
4101
4104
|
login_count: t?.login_count ?? 0
|
|
4102
4105
|
};
|
|
4103
4106
|
}
|
|
4104
|
-
function
|
|
4107
|
+
function qr(e, t) {
|
|
4105
4108
|
let n = {
|
|
4106
4109
|
connection: e.connection,
|
|
4107
4110
|
provider: e.provider,
|
|
@@ -4111,11 +4114,11 @@ function Wr(e, t) {
|
|
|
4111
4114
|
return t ? n.isPrimary = !0 : n.profileData = {
|
|
4112
4115
|
email: e.email,
|
|
4113
4116
|
email_verified: !!e.email_verified,
|
|
4114
|
-
...typeof e.profileData == "string" ?
|
|
4117
|
+
...typeof e.profileData == "string" ? Z(e.profileData, {}) : {}
|
|
4115
4118
|
}, n;
|
|
4116
4119
|
}
|
|
4117
|
-
function
|
|
4118
|
-
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));
|
|
4119
4122
|
return D({
|
|
4120
4123
|
...f,
|
|
4121
4124
|
email: e.email || "",
|
|
@@ -4123,13 +4126,13 @@ function Gr(e, t = []) {
|
|
|
4123
4126
|
phone_verified: s == null ? void 0 : !!s,
|
|
4124
4127
|
is_social: !!c,
|
|
4125
4128
|
blocked: l == null ? void 0 : !!l,
|
|
4126
|
-
app_metadata:
|
|
4127
|
-
user_metadata:
|
|
4128
|
-
address:
|
|
4129
|
+
app_metadata: Z(r, {}),
|
|
4130
|
+
user_metadata: Z(i, {}),
|
|
4131
|
+
address: Z(a),
|
|
4129
4132
|
identities: [p, ...m]
|
|
4130
4133
|
});
|
|
4131
4134
|
}
|
|
4132
|
-
function
|
|
4135
|
+
function Yr(e) {
|
|
4133
4136
|
let o = async (t, n, r) => {
|
|
4134
4137
|
let i = (/* @__PURE__ */ new Date()).toISOString(), a = {
|
|
4135
4138
|
user_id: n.user_id,
|
|
@@ -4166,14 +4169,14 @@ function Kr(e) {
|
|
|
4166
4169
|
updated_at: n.updated_at || i
|
|
4167
4170
|
}, o = n.password ? b() : void 0, s = n.last_login !== void 0 || n.last_ip !== void 0 || n.login_count !== void 0;
|
|
4168
4171
|
try {
|
|
4169
|
-
let c = [e.insert(
|
|
4170
|
-
s && c.push(e.insert(
|
|
4172
|
+
let c = [e.insert(A).values(a)];
|
|
4173
|
+
s && c.push(e.insert(Be).values({
|
|
4171
4174
|
tenant_id: t,
|
|
4172
4175
|
user_id: n.user_id,
|
|
4173
4176
|
last_login: n.last_login,
|
|
4174
4177
|
last_ip: n.last_ip,
|
|
4175
4178
|
login_count: n.login_count ?? 0
|
|
4176
|
-
})), n.password && o && c.push(e.insert(
|
|
4179
|
+
})), n.password && o && c.push(e.insert(j).values({
|
|
4177
4180
|
id: o,
|
|
4178
4181
|
tenant_id: t,
|
|
4179
4182
|
user_id: n.user_id,
|
|
@@ -4183,12 +4186,12 @@ function Kr(e) {
|
|
|
4183
4186
|
created_at: i,
|
|
4184
4187
|
updated_at: i
|
|
4185
4188
|
}));
|
|
4186
|
-
for (let n of
|
|
4187
|
-
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);
|
|
4188
4191
|
} catch (e) {
|
|
4189
|
-
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" }));
|
|
4190
4193
|
}
|
|
4191
|
-
return
|
|
4194
|
+
return Jr({
|
|
4192
4195
|
...a,
|
|
4193
4196
|
last_login: n.last_login,
|
|
4194
4197
|
last_ip: n.last_ip,
|
|
@@ -4199,10 +4202,10 @@ function Kr(e) {
|
|
|
4199
4202
|
create: o,
|
|
4200
4203
|
rawCreate: o,
|
|
4201
4204
|
async get(n, r) {
|
|
4202
|
-
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();
|
|
4203
4206
|
if (!i) return null;
|
|
4204
|
-
let o = await e.select().from(
|
|
4205
|
-
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);
|
|
4206
4209
|
},
|
|
4207
4210
|
async update(n, r, i, o) {
|
|
4208
4211
|
let s = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
@@ -4229,34 +4232,34 @@ function Kr(e) {
|
|
|
4229
4232
|
"zoneinfo"
|
|
4230
4233
|
]) i[e] !== void 0 && (s[e] = i[e]);
|
|
4231
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));
|
|
4232
|
-
let c = e.update(
|
|
4233
|
-
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, {
|
|
4234
4237
|
last_login: i.last_login,
|
|
4235
4238
|
last_ip: i.last_ip,
|
|
4236
4239
|
login_count: i.login_count
|
|
4237
4240
|
}), !0);
|
|
4238
4241
|
},
|
|
4239
4242
|
async list(o, s) {
|
|
4240
|
-
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)];
|
|
4241
4244
|
if (m) {
|
|
4242
|
-
let e = we(m,
|
|
4245
|
+
let e = we(m, zr);
|
|
4243
4246
|
if (e) {
|
|
4244
|
-
let t =
|
|
4247
|
+
let t = mt(Wr, e, Br);
|
|
4245
4248
|
t && h.push(t);
|
|
4246
4249
|
}
|
|
4247
4250
|
}
|
|
4248
4251
|
let g = t(...h), _ = async (n) => {
|
|
4249
|
-
let r = n.map((e) => e.user_id), i = r.length > 0 ? await e.select().from(
|
|
4250
|
-
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)));
|
|
4251
4254
|
};
|
|
4252
|
-
if (
|
|
4253
|
-
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` });
|
|
4254
4257
|
let n = p?.sort_order === "asc" ? "asc" : "desc", r = {
|
|
4255
|
-
sortColumn:
|
|
4256
|
-
idColumn:
|
|
4258
|
+
sortColumn: A.created_at,
|
|
4259
|
+
idColumn: A.user_id,
|
|
4257
4260
|
sortOrder: n,
|
|
4258
4261
|
sortKey: `created_at:${n}`
|
|
4259
|
-
}, 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);
|
|
4260
4263
|
return {
|
|
4261
4264
|
users: l,
|
|
4262
4265
|
start: 0,
|
|
@@ -4265,15 +4268,15 @@ function Kr(e) {
|
|
|
4265
4268
|
next: c
|
|
4266
4269
|
};
|
|
4267
4270
|
}
|
|
4268
|
-
let v = e.select().from(
|
|
4271
|
+
let v = e.select().from(A).leftJoin(Be, Gr()).where(g).$dynamic();
|
|
4269
4272
|
if (p?.sort_by) {
|
|
4270
|
-
let e =
|
|
4273
|
+
let e = Wr[p.sort_by];
|
|
4271
4274
|
if (e) {
|
|
4272
|
-
let t =
|
|
4275
|
+
let t = ft(e) ? pt(e) : e;
|
|
4273
4276
|
v = v.orderBy(p.sort_order === "desc" ? i(t) : n(t));
|
|
4274
4277
|
}
|
|
4275
4278
|
}
|
|
4276
|
-
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)));
|
|
4277
4280
|
if (!ee) return { users: b };
|
|
4278
4281
|
let [te] = ee;
|
|
4279
4282
|
return {
|
|
@@ -4284,30 +4287,30 @@ function Kr(e) {
|
|
|
4284
4287
|
};
|
|
4285
4288
|
},
|
|
4286
4289
|
async remove(n, r, i) {
|
|
4287
|
-
let o = await e.select({ user_id:
|
|
4288
|
-
e.delete(
|
|
4289
|
-
e.delete(
|
|
4290
|
-
e.delete(
|
|
4291
|
-
e.delete(
|
|
4292
|
-
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()
|
|
4293
4296
|
], f = d.length - 1;
|
|
4294
|
-
if (s) for (let t of
|
|
4295
|
-
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];
|
|
4296
4299
|
return Array.isArray(p) && p.length > 0;
|
|
4297
4300
|
},
|
|
4298
4301
|
async unlink(n, r, i, o) {
|
|
4299
4302
|
let s = `${i}|${o}`;
|
|
4300
|
-
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;
|
|
4301
4304
|
}
|
|
4302
4305
|
};
|
|
4303
4306
|
}
|
|
4304
4307
|
//#endregion
|
|
4305
4308
|
//#region src/adapters/userRoles.ts
|
|
4306
|
-
function
|
|
4309
|
+
function Xr(e) {
|
|
4307
4310
|
return {
|
|
4308
4311
|
async create(t, n, r, i) {
|
|
4309
4312
|
try {
|
|
4310
|
-
await e.insert(
|
|
4313
|
+
await e.insert(W).values({
|
|
4311
4314
|
tenant_id: t,
|
|
4312
4315
|
user_id: n,
|
|
4313
4316
|
role_id: r,
|
|
@@ -4321,28 +4324,28 @@ function qr(e) {
|
|
|
4321
4324
|
return !0;
|
|
4322
4325
|
},
|
|
4323
4326
|
async list(n, r, i, o) {
|
|
4324
|
-
let s = [a(
|
|
4325
|
-
o !== void 0 && s.push(a(
|
|
4326
|
-
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();
|
|
4327
4330
|
return c.length === 0 ? [] : (await Promise.all(c.map(async (r) => {
|
|
4328
|
-
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();
|
|
4329
4332
|
if (!i) return null;
|
|
4330
4333
|
let { tenant_id: o, is_system: s, metadata: c, ...l } = i;
|
|
4331
4334
|
return D({
|
|
4332
4335
|
...l,
|
|
4333
4336
|
is_system: s ? !0 : void 0,
|
|
4334
|
-
metadata:
|
|
4337
|
+
metadata: Z(c)
|
|
4335
4338
|
});
|
|
4336
4339
|
}))).filter(Boolean);
|
|
4337
4340
|
},
|
|
4338
4341
|
async listUsers(r, i, o) {
|
|
4339
|
-
let s = t(a(
|
|
4340
|
-
if (
|
|
4342
|
+
let s = t(a(W.tenant_id, r), a(W.role_id, i));
|
|
4343
|
+
if (Et(o)) {
|
|
4341
4344
|
let n = {
|
|
4342
|
-
sortColumn:
|
|
4343
|
-
idColumn:
|
|
4345
|
+
sortColumn: W.user_id,
|
|
4346
|
+
idColumn: W.user_id,
|
|
4344
4347
|
sortOrder: "asc"
|
|
4345
|
-
}, 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");
|
|
4346
4349
|
return {
|
|
4347
4350
|
userIds: a.map((e) => e.user_id),
|
|
4348
4351
|
start: 0,
|
|
@@ -4351,7 +4354,7 @@ function qr(e) {
|
|
|
4351
4354
|
next: c
|
|
4352
4355
|
};
|
|
4353
4356
|
}
|
|
4354
|
-
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();
|
|
4355
4358
|
return {
|
|
4356
4359
|
userIds: d.map((e) => e.user_id),
|
|
4357
4360
|
start: u,
|
|
@@ -4360,13 +4363,13 @@ function qr(e) {
|
|
|
4360
4363
|
};
|
|
4361
4364
|
},
|
|
4362
4365
|
async remove(n, r, i, o) {
|
|
4363
|
-
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;
|
|
4364
4367
|
}
|
|
4365
4368
|
};
|
|
4366
4369
|
}
|
|
4367
4370
|
//#endregion
|
|
4368
4371
|
//#region src/adapters/userOrganizations.ts
|
|
4369
|
-
function
|
|
4372
|
+
function Zr(e) {
|
|
4370
4373
|
return {
|
|
4371
4374
|
async create(t, n) {
|
|
4372
4375
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
@@ -4378,39 +4381,39 @@ function Jr(e) {
|
|
|
4378
4381
|
updated_at: r
|
|
4379
4382
|
};
|
|
4380
4383
|
try {
|
|
4381
|
-
await e.insert(
|
|
4384
|
+
await e.insert(H).values(i);
|
|
4382
4385
|
} catch (e) {
|
|
4383
|
-
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;
|
|
4384
4387
|
}
|
|
4385
4388
|
let { tenant_id: a, ...o } = i;
|
|
4386
4389
|
return o;
|
|
4387
4390
|
},
|
|
4388
4391
|
async get(n, r) {
|
|
4389
|
-
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();
|
|
4390
4393
|
if (!i) return null;
|
|
4391
4394
|
let { tenant_id: o, ...s } = i;
|
|
4392
4395
|
return s;
|
|
4393
4396
|
},
|
|
4394
4397
|
async update(n, r, i) {
|
|
4395
4398
|
let o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
4396
|
-
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;
|
|
4397
4400
|
},
|
|
4398
4401
|
async list(n, o) {
|
|
4399
|
-
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;
|
|
4400
4403
|
if (c) {
|
|
4401
|
-
let e =
|
|
4404
|
+
let e = mt(H, c, ["user_id", "organization_id"]);
|
|
4402
4405
|
e && (u = t(l, e));
|
|
4403
4406
|
}
|
|
4404
4407
|
let d = (e) => {
|
|
4405
4408
|
let { tenant_id: t, ...n } = e;
|
|
4406
4409
|
return n;
|
|
4407
4410
|
};
|
|
4408
|
-
if (
|
|
4411
|
+
if (Et(o)) {
|
|
4409
4412
|
let n = {
|
|
4410
|
-
sortColumn:
|
|
4411
|
-
idColumn:
|
|
4413
|
+
sortColumn: H.created_at,
|
|
4414
|
+
idColumn: H.id,
|
|
4412
4415
|
sortOrder: "desc"
|
|
4413
|
-
}, 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");
|
|
4414
4417
|
return {
|
|
4415
4418
|
userOrganizations: a,
|
|
4416
4419
|
start: 0,
|
|
@@ -4419,9 +4422,9 @@ function Jr(e) {
|
|
|
4419
4422
|
next: s
|
|
4420
4423
|
};
|
|
4421
4424
|
}
|
|
4422
|
-
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);
|
|
4423
4426
|
if (!s) return { userOrganizations: h };
|
|
4424
|
-
let [g] = await e.select({ count: r() }).from(
|
|
4427
|
+
let [g] = await e.select({ count: r() }).from(H).where(u);
|
|
4425
4428
|
return {
|
|
4426
4429
|
userOrganizations: h,
|
|
4427
4430
|
start: m,
|
|
@@ -4430,20 +4433,20 @@ function Jr(e) {
|
|
|
4430
4433
|
};
|
|
4431
4434
|
},
|
|
4432
4435
|
async listUserOrganizations(n, i, o) {
|
|
4433
|
-
let { page: s = 0, per_page: c = 50, include_totals: l = !1 } = o || {}, u = await e.select().from(
|
|
4434
|
-
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();
|
|
4435
4438
|
if (!i) return null;
|
|
4436
4439
|
let { tenant_id: o, branding: s, metadata: c, enabled_connections: l, token_quota: u, ...d } = i;
|
|
4437
4440
|
return D({
|
|
4438
4441
|
...d,
|
|
4439
|
-
branding:
|
|
4440
|
-
metadata:
|
|
4441
|
-
enabled_connections:
|
|
4442
|
-
token_quota:
|
|
4442
|
+
branding: Z(s, {}),
|
|
4443
|
+
metadata: Z(c, {}),
|
|
4444
|
+
enabled_connections: Z(l, []),
|
|
4445
|
+
token_quota: Z(u, {})
|
|
4443
4446
|
});
|
|
4444
4447
|
}))).filter(Boolean);
|
|
4445
4448
|
if (!l) return { organizations: d };
|
|
4446
|
-
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)));
|
|
4447
4450
|
return {
|
|
4448
4451
|
organizations: d,
|
|
4449
4452
|
start: s * c,
|
|
@@ -4452,26 +4455,26 @@ function Jr(e) {
|
|
|
4452
4455
|
};
|
|
4453
4456
|
},
|
|
4454
4457
|
async remove(n, r) {
|
|
4455
|
-
return (await e.delete(
|
|
4458
|
+
return (await e.delete(H).where(t(a(H.tenant_id, n), a(H.id, r))).returning()).length > 0;
|
|
4456
4459
|
}
|
|
4457
4460
|
};
|
|
4458
4461
|
}
|
|
4459
4462
|
//#endregion
|
|
4460
4463
|
//#region src/adapters/stats.ts
|
|
4461
|
-
var
|
|
4462
|
-
function
|
|
4464
|
+
var Qr = ["s"], $r = ["pwd_leak"];
|
|
4465
|
+
function ei(e) {
|
|
4463
4466
|
return /^\d{8}$/.test(e) ? `${e.slice(0, 4)}-${e.slice(4, 6)}-${e.slice(6, 8)}` : e;
|
|
4464
4467
|
}
|
|
4465
|
-
function
|
|
4468
|
+
function ti(e) {
|
|
4466
4469
|
return {
|
|
4467
4470
|
async getDaily(n, r) {
|
|
4468
|
-
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];
|
|
4469
4472
|
return (await e.select({
|
|
4470
|
-
date: y`substr(${
|
|
4471
|
-
logins: y`SUM(CASE WHEN ${
|
|
4472
|
-
signups: y`SUM(CASE WHEN ${
|
|
4473
|
-
leaked_passwords: y`SUM(CASE WHEN ${
|
|
4474
|
-
}).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) => ({
|
|
4475
4478
|
date: e.date,
|
|
4476
4479
|
logins: Number(e.logins) || 0,
|
|
4477
4480
|
signups: Number(e.signups) || 0,
|
|
@@ -4481,14 +4484,14 @@ function Qr(e) {
|
|
|
4481
4484
|
}));
|
|
4482
4485
|
},
|
|
4483
4486
|
async getActiveUsers(n) {
|
|
4484
|
-
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`, `)})`));
|
|
4485
4488
|
return Number(i?.count) || 0;
|
|
4486
4489
|
}
|
|
4487
4490
|
};
|
|
4488
4491
|
}
|
|
4489
4492
|
//#endregion
|
|
4490
4493
|
//#region src/adapters/analytics.ts
|
|
4491
|
-
var
|
|
4494
|
+
var ni = {
|
|
4492
4495
|
"active-users": ["s", "seacft"],
|
|
4493
4496
|
logins: [
|
|
4494
4497
|
"s",
|
|
@@ -4518,7 +4521,7 @@ var $r = {
|
|
|
4518
4521
|
"fvr"
|
|
4519
4522
|
],
|
|
4520
4523
|
"codes-sent": ["cls", "cs"]
|
|
4521
|
-
},
|
|
4524
|
+
}, ri = {
|
|
4522
4525
|
"active-users": {
|
|
4523
4526
|
alias: "active_users",
|
|
4524
4527
|
type: "UInt64",
|
|
@@ -4575,64 +4578,64 @@ var $r = {
|
|
|
4575
4578
|
agg: "count"
|
|
4576
4579
|
}
|
|
4577
4580
|
};
|
|
4578
|
-
function
|
|
4581
|
+
function ii(e) {
|
|
4579
4582
|
switch (e) {
|
|
4580
|
-
case "hour": return y`substr(${
|
|
4581
|
-
case "month": return y`substr(${
|
|
4582
|
-
case "day": return y`substr(${
|
|
4583
|
-
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')`;
|
|
4584
4587
|
default: throw Error(`Unsupported interval '${e}' for SQL analytics adapter`);
|
|
4585
4588
|
}
|
|
4586
4589
|
}
|
|
4587
|
-
function
|
|
4590
|
+
function ai(e) {
|
|
4588
4591
|
return `"${e.replace(/"/g, "\"\"")}"`;
|
|
4589
4592
|
}
|
|
4590
|
-
function
|
|
4593
|
+
function oi(e) {
|
|
4591
4594
|
switch (e) {
|
|
4592
|
-
case "connection": return
|
|
4593
|
-
case "client_id": return
|
|
4594
|
-
case "user_type": return
|
|
4595
|
-
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;
|
|
4596
4599
|
case "time": throw Error("time dimension handled separately");
|
|
4597
4600
|
}
|
|
4598
4601
|
}
|
|
4599
|
-
function
|
|
4602
|
+
function si(e) {
|
|
4600
4603
|
return {
|
|
4601
4604
|
async query(n, r, i) {
|
|
4602
|
-
let o = Date.now(), s =
|
|
4603
|
-
a(
|
|
4604
|
-
c(
|
|
4605
|
-
m(
|
|
4606
|
-
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)
|
|
4607
4610
|
];
|
|
4608
|
-
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));
|
|
4609
4612
|
let f = {}, p = [], h = [];
|
|
4610
4613
|
for (let e of i.group_by) if (e === "time") {
|
|
4611
|
-
let e =
|
|
4614
|
+
let e = ii(i.interval);
|
|
4612
4615
|
f.time = e, p.push(e), h.push({
|
|
4613
4616
|
name: "time",
|
|
4614
4617
|
type: i.interval === "hour" ? "DateTime" : "Date"
|
|
4615
4618
|
});
|
|
4616
4619
|
} else {
|
|
4617
|
-
let t =
|
|
4620
|
+
let t = oi(e);
|
|
4618
4621
|
f[e] = t, p.push(t), h.push({
|
|
4619
4622
|
name: e,
|
|
4620
4623
|
type: "String"
|
|
4621
4624
|
});
|
|
4622
4625
|
}
|
|
4623
|
-
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({
|
|
4624
4627
|
name: u.alias,
|
|
4625
4628
|
type: u.type
|
|
4626
4629
|
});
|
|
4627
|
-
let g = e.select(f).from(
|
|
4630
|
+
let g = e.select(f).from(q).where(t(...d));
|
|
4628
4631
|
p.length > 0 && (g = g.groupBy(...p));
|
|
4629
4632
|
let _ = new Set([...Object.keys(f)]);
|
|
4630
4633
|
if (i.order_by) {
|
|
4631
4634
|
let e = i.order_by.startsWith("-"), t = e ? i.order_by.slice(1) : i.order_by;
|
|
4632
4635
|
if (!_.has(t)) throw Error(`Invalid order_by column '${t}' for analytics query`);
|
|
4633
|
-
let n =
|
|
4636
|
+
let n = ai(t);
|
|
4634
4637
|
g = g.orderBy(y.raw(`${n} ${e ? "DESC" : "ASC"}`));
|
|
4635
|
-
} 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`));
|
|
4636
4639
|
g = g.limit(i.limit).offset(i.offset);
|
|
4637
4640
|
let v = (await g.all()).map((e) => {
|
|
4638
4641
|
let t = {};
|
|
@@ -4651,22 +4654,22 @@ function ii(e) {
|
|
|
4651
4654
|
};
|
|
4652
4655
|
},
|
|
4653
4656
|
async sessionRetention(n, r) {
|
|
4654
|
-
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}`;
|
|
4655
4658
|
return pe((await e.select({
|
|
4656
4659
|
created_week: s,
|
|
4657
4660
|
used_week: l,
|
|
4658
4661
|
count: y`COUNT(*)`
|
|
4659
|
-
}).from(
|
|
4662
|
+
}).from(M).where(t(a(M.tenant_id, n), c(M.created_at_ts, o))).groupBy(s, l).all()).map((e) => ({
|
|
4660
4663
|
created_week: Math.floor(Number(e.created_week)),
|
|
4661
4664
|
used_week: Math.floor(Number(e.used_week)),
|
|
4662
4665
|
count: Number(e.count)
|
|
4663
4666
|
})), r.weeks, i);
|
|
4664
4667
|
},
|
|
4665
4668
|
async refreshTokenRetention(n, r) {
|
|
4666
|
-
let i = Date.now(), { sinceMs: o } = Ee(r.weeks, i), s = r.client_id && r.client_id.length > 0 ? l(
|
|
4667
|
-
min_created: y`MIN(${
|
|
4668
|
-
max_used: y`MAX(COALESCE(${
|
|
4669
|
-
}).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}`;
|
|
4670
4673
|
return fe((await e.select({
|
|
4671
4674
|
created_week: d,
|
|
4672
4675
|
used_week: f,
|
|
@@ -4681,13 +4684,13 @@ function ii(e) {
|
|
|
4681
4684
|
}
|
|
4682
4685
|
//#endregion
|
|
4683
4686
|
//#region src/adapters/cleanup.ts
|
|
4684
|
-
var
|
|
4685
|
-
function
|
|
4687
|
+
var ci = 10080 * 60 * 1e3;
|
|
4688
|
+
function li(e) {
|
|
4686
4689
|
return async (n) => {
|
|
4687
|
-
let r = Date.now() -
|
|
4690
|
+
let r = Date.now() - ci;
|
|
4688
4691
|
try {
|
|
4689
|
-
let i = [v(m(
|
|
4690
|
-
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));
|
|
4691
4694
|
} catch (e) {
|
|
4692
4695
|
console.error("Session cleanup error:", e);
|
|
4693
4696
|
}
|
|
@@ -4695,7 +4698,7 @@ function oi(e) {
|
|
|
4695
4698
|
}
|
|
4696
4699
|
//#endregion
|
|
4697
4700
|
//#region src/schema/control-plane/tenantOperations.ts
|
|
4698
|
-
var
|
|
4701
|
+
var Q = w("tenant_operations", {
|
|
4699
4702
|
id: T("id", { length: 255 }).primaryKey(),
|
|
4700
4703
|
tenant_id: T("tenant_id", { length: 255 }),
|
|
4701
4704
|
rollout_id: T("rollout_id", { length: 255 }),
|
|
@@ -4708,6 +4711,10 @@ var $ = w("tenant_operations", {
|
|
|
4708
4711
|
target_database_version: T("target_database_version", { length: 255 }),
|
|
4709
4712
|
error: T("error"),
|
|
4710
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 }),
|
|
4711
4718
|
created_at: T("created_at", { length: 35 }).notNull(),
|
|
4712
4719
|
updated_at: T("updated_at", { length: 35 }).notNull(),
|
|
4713
4720
|
finished_at: T("finished_at", { length: 35 })
|
|
@@ -4715,7 +4722,7 @@ var $ = w("tenant_operations", {
|
|
|
4715
4722
|
x("tenant_operations_tenant_id_created_at_idx").on(e.tenant_id, e.created_at),
|
|
4716
4723
|
x("tenant_operations_rollout_id_idx").on(e.rollout_id),
|
|
4717
4724
|
x("tenant_operations_status_idx").on(e.status)
|
|
4718
|
-
]),
|
|
4725
|
+
]), ui = w("tenant_operation_events", {
|
|
4719
4726
|
id: T("id", { length: 255 }).primaryKey(),
|
|
4720
4727
|
operation_id: T("operation_id", { length: 255 }).notNull(),
|
|
4721
4728
|
step: T("step", { length: 255 }).notNull(),
|
|
@@ -4725,9 +4732,28 @@ var $ = w("tenant_operations", {
|
|
|
4725
4732
|
created_at: T("created_at", { length: 35 }).notNull()
|
|
4726
4733
|
}, (e) => [ne({
|
|
4727
4734
|
columns: [e.operation_id],
|
|
4728
|
-
foreignColumns: [
|
|
4735
|
+
foreignColumns: [Q.id],
|
|
4729
4736
|
name: "tenant_operation_events_operation_id_constraint"
|
|
4730
|
-
}).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", {
|
|
4731
4757
|
id: T("id", { length: 255 }).primaryKey(),
|
|
4732
4758
|
kind: T("kind", { length: 32 }).notNull(),
|
|
4733
4759
|
status: T("status", { length: 32 }).notNull(),
|
|
@@ -4743,8 +4769,16 @@ var $ = w("tenant_operations", {
|
|
|
4743
4769
|
});
|
|
4744
4770
|
//#endregion
|
|
4745
4771
|
//#region src/adapters/tenantOperations.ts
|
|
4746
|
-
function
|
|
4747
|
-
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({
|
|
4748
4782
|
id: e.id,
|
|
4749
4783
|
tenant_id: e.tenant_id,
|
|
4750
4784
|
rollout_id: e.rollout_id,
|
|
@@ -4757,12 +4791,16 @@ function li(e) {
|
|
|
4757
4791
|
target_database_version: e.target_database_version,
|
|
4758
4792
|
error: e.error,
|
|
4759
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,
|
|
4760
4798
|
created_at: e.created_at,
|
|
4761
4799
|
updated_at: e.updated_at,
|
|
4762
4800
|
finished_at: e.finished_at
|
|
4763
4801
|
});
|
|
4764
4802
|
}
|
|
4765
|
-
function
|
|
4803
|
+
function mi(e) {
|
|
4766
4804
|
return {
|
|
4767
4805
|
async create(t) {
|
|
4768
4806
|
let n = Ae.parse(t), r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
@@ -4778,67 +4816,210 @@ function ui(e) {
|
|
|
4778
4816
|
target_database_version: n.target_database_version ?? null,
|
|
4779
4817
|
error: null,
|
|
4780
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,
|
|
4781
4823
|
created_at: r,
|
|
4782
4824
|
updated_at: r,
|
|
4783
4825
|
finished_at: null
|
|
4784
4826
|
};
|
|
4785
|
-
await e.insert(
|
|
4827
|
+
await e.insert(Q).values(i);
|
|
4786
4828
|
let a = await this.get(i.id);
|
|
4787
4829
|
if (!a) throw Error(`Failed to create tenant operation ${i.id}`);
|
|
4788
4830
|
return a;
|
|
4789
4831
|
},
|
|
4790
4832
|
async get(t) {
|
|
4791
|
-
let n = await e.select().from(
|
|
4792
|
-
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;
|
|
4793
4835
|
},
|
|
4794
4836
|
async list(n = {}) {
|
|
4795
4837
|
let r = n.page ?? 0, o = n.per_page ?? 50, s = [];
|
|
4796
|
-
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) {
|
|
4797
4839
|
let e = Array.isArray(n.status) ? n.status : [n.status];
|
|
4798
|
-
s.push(l(
|
|
4840
|
+
s.push(l(Q.status, e));
|
|
4799
4841
|
}
|
|
4800
|
-
n.engine !== void 0 && s.push(a(
|
|
4801
|
-
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);
|
|
4802
4844
|
return {
|
|
4803
|
-
operations: c.map(
|
|
4845
|
+
operations: c.map(pi),
|
|
4804
4846
|
start: r * o,
|
|
4805
4847
|
limit: o,
|
|
4806
4848
|
length: c.length
|
|
4807
4849
|
};
|
|
4808
4850
|
},
|
|
4809
4851
|
async update(t, n) {
|
|
4810
|
-
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;
|
|
4811
4853
|
let r = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
4812
|
-
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);
|
|
4813
4872
|
},
|
|
4814
4873
|
async remove(t) {
|
|
4815
|
-
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);
|
|
4816
4997
|
}
|
|
4817
4998
|
};
|
|
4818
4999
|
}
|
|
4819
5000
|
//#endregion
|
|
4820
5001
|
//#region src/helpers/monotonic-id.ts
|
|
4821
|
-
var
|
|
4822
|
-
function
|
|
5002
|
+
var Si = "0123456789ABCDEFGHJKMNPQRSTVWXYZ", Ci = 32, wi = 10, Ti = 4, Ei = 10;
|
|
5003
|
+
function Di(e, t) {
|
|
4823
5004
|
let n = "";
|
|
4824
|
-
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);
|
|
4825
5006
|
return n;
|
|
4826
5007
|
}
|
|
4827
|
-
function
|
|
4828
|
-
let e = new Uint8Array(
|
|
5008
|
+
function Oi() {
|
|
5009
|
+
let e = new Uint8Array(Ei);
|
|
4829
5010
|
crypto.getRandomValues(e);
|
|
4830
5011
|
let t = "";
|
|
4831
|
-
for (let n = 0; n <
|
|
5012
|
+
for (let n = 0; n < Ei; n++) t += Si.charAt(e[n] % Ci);
|
|
4832
5013
|
return t;
|
|
4833
5014
|
}
|
|
4834
|
-
var
|
|
4835
|
-
function
|
|
5015
|
+
var ki = 0, Ai = 0;
|
|
5016
|
+
function ji() {
|
|
4836
5017
|
let e = Date.now();
|
|
4837
|
-
return e ===
|
|
5018
|
+
return e === ki ? Ai++ : (ki = e, Ai = 0), Di(e, wi) + Di(Ai, Ti) + Oi();
|
|
4838
5019
|
}
|
|
4839
5020
|
//#endregion
|
|
4840
5021
|
//#region src/adapters/tenantOperationEvents.ts
|
|
4841
|
-
function
|
|
5022
|
+
function Mi(e) {
|
|
4842
5023
|
if (!e) return null;
|
|
4843
5024
|
try {
|
|
4844
5025
|
let t = JSON.parse(e);
|
|
@@ -4846,22 +5027,22 @@ function xi(e) {
|
|
|
4846
5027
|
} catch {}
|
|
4847
5028
|
return null;
|
|
4848
5029
|
}
|
|
4849
|
-
function
|
|
5030
|
+
function Ni(e) {
|
|
4850
5031
|
return ke.parse({
|
|
4851
5032
|
id: e.id,
|
|
4852
5033
|
operation_id: e.operation_id,
|
|
4853
5034
|
step: e.step,
|
|
4854
5035
|
outcome: e.outcome,
|
|
4855
|
-
detail:
|
|
5036
|
+
detail: Mi(e.detail),
|
|
4856
5037
|
attempt: e.attempt,
|
|
4857
5038
|
created_at: e.created_at
|
|
4858
5039
|
});
|
|
4859
5040
|
}
|
|
4860
|
-
function
|
|
5041
|
+
function Pi(e) {
|
|
4861
5042
|
return {
|
|
4862
5043
|
async create(t) {
|
|
4863
5044
|
let n = Oe.parse(t), r = {
|
|
4864
|
-
id: `evt_${
|
|
5045
|
+
id: `evt_${ji()}`,
|
|
4865
5046
|
operation_id: n.operation_id,
|
|
4866
5047
|
step: n.step,
|
|
4867
5048
|
outcome: n.outcome,
|
|
@@ -4869,7 +5050,7 @@ function Ci(e) {
|
|
|
4869
5050
|
attempt: n.attempt,
|
|
4870
5051
|
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
4871
5052
|
};
|
|
4872
|
-
return await e.insert(
|
|
5053
|
+
return await e.insert(ui).values(r), ke.parse({
|
|
4873
5054
|
id: r.id,
|
|
4874
5055
|
operation_id: r.operation_id,
|
|
4875
5056
|
step: r.step,
|
|
@@ -4880,9 +5061,9 @@ function Ci(e) {
|
|
|
4880
5061
|
});
|
|
4881
5062
|
},
|
|
4882
5063
|
async listByOperation(t, r = {}) {
|
|
4883
|
-
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);
|
|
4884
5065
|
return {
|
|
4885
|
-
events: s.map(
|
|
5066
|
+
events: s.map(Ni),
|
|
4886
5067
|
start: i * o,
|
|
4887
5068
|
limit: o,
|
|
4888
5069
|
length: s.length
|
|
@@ -4892,7 +5073,7 @@ function Ci(e) {
|
|
|
4892
5073
|
}
|
|
4893
5074
|
//#endregion
|
|
4894
5075
|
//#region src/adapters/rollouts.ts
|
|
4895
|
-
function
|
|
5076
|
+
function Fi(e) {
|
|
4896
5077
|
if (!e) return null;
|
|
4897
5078
|
try {
|
|
4898
5079
|
return JSON.parse(e);
|
|
@@ -4900,7 +5081,7 @@ function wi(e) {
|
|
|
4900
5081
|
return null;
|
|
4901
5082
|
}
|
|
4902
5083
|
}
|
|
4903
|
-
function
|
|
5084
|
+
function Ii(e) {
|
|
4904
5085
|
return Ce.parse({
|
|
4905
5086
|
id: e.id,
|
|
4906
5087
|
kind: e.kind,
|
|
@@ -4908,15 +5089,15 @@ function Ti(e) {
|
|
|
4908
5089
|
target_worker_version: e.target_worker_version,
|
|
4909
5090
|
target_database_version: e.target_database_version,
|
|
4910
5091
|
wave_size: e.wave_size,
|
|
4911
|
-
canary_tenant_ids:
|
|
4912
|
-
filter:
|
|
5092
|
+
canary_tenant_ids: Fi(e.canary_tenant_ids),
|
|
5093
|
+
filter: Fi(e.filter),
|
|
4913
5094
|
initiated_by: e.initiated_by,
|
|
4914
5095
|
created_at: e.created_at,
|
|
4915
5096
|
updated_at: e.updated_at,
|
|
4916
5097
|
finished_at: e.finished_at
|
|
4917
5098
|
});
|
|
4918
5099
|
}
|
|
4919
|
-
function
|
|
5100
|
+
function Li(e) {
|
|
4920
5101
|
return {
|
|
4921
5102
|
async create(t) {
|
|
4922
5103
|
let n = Se.parse(t), r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
@@ -4933,93 +5114,94 @@ function Ei(e) {
|
|
|
4933
5114
|
updated_at: r,
|
|
4934
5115
|
finished_at: null
|
|
4935
5116
|
};
|
|
4936
|
-
await e.insert(
|
|
5117
|
+
await e.insert(di).values(i);
|
|
4937
5118
|
let a = await this.get(i.id);
|
|
4938
5119
|
if (!a) throw Error(`Failed to create rollout ${i.id}`);
|
|
4939
5120
|
return a;
|
|
4940
5121
|
},
|
|
4941
5122
|
async get(t) {
|
|
4942
|
-
let n = await e.select().from(
|
|
4943
|
-
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;
|
|
4944
5125
|
},
|
|
4945
5126
|
async list(t = {}) {
|
|
4946
|
-
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);
|
|
4947
5128
|
return {
|
|
4948
|
-
rollouts: a.map(
|
|
5129
|
+
rollouts: a.map(Ii),
|
|
4949
5130
|
start: n * r,
|
|
4950
5131
|
limit: r,
|
|
4951
5132
|
length: a.length
|
|
4952
5133
|
};
|
|
4953
5134
|
},
|
|
4954
5135
|
async update(t, n) {
|
|
4955
|
-
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;
|
|
4956
5137
|
let r = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
4957
|
-
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;
|
|
4958
5139
|
},
|
|
4959
5140
|
async remove(t) {
|
|
4960
|
-
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);
|
|
4961
5142
|
}
|
|
4962
5143
|
};
|
|
4963
5144
|
}
|
|
4964
5145
|
//#endregion
|
|
4965
5146
|
//#region src/adapters/index.ts
|
|
4966
|
-
function
|
|
5147
|
+
function Ri(e, t = { useTransactions: !0 }) {
|
|
4967
5148
|
let n = {
|
|
4968
|
-
actions:
|
|
4969
|
-
actionExecutions:
|
|
4970
|
-
actionVersions:
|
|
4971
|
-
branding:
|
|
4972
|
-
clients:
|
|
4973
|
-
clientConnections:
|
|
4974
|
-
clientGrants:
|
|
4975
|
-
clientRegistrationTokens:
|
|
4976
|
-
codes:
|
|
4977
|
-
connections:
|
|
4978
|
-
customDomains:
|
|
4979
|
-
customText:
|
|
4980
|
-
emailProviders:
|
|
4981
|
-
emailTemplates:
|
|
4982
|
-
flows:
|
|
4983
|
-
forms:
|
|
4984
|
-
grants:
|
|
4985
|
-
hookCode:
|
|
4986
|
-
hooks:
|
|
4987
|
-
invites:
|
|
4988
|
-
keys:
|
|
4989
|
-
loginSessions:
|
|
4990
|
-
logs:
|
|
4991
|
-
authenticationMethods:
|
|
4992
|
-
organizations:
|
|
4993
|
-
passwords:
|
|
4994
|
-
promptSettings:
|
|
4995
|
-
proxyRoutes:
|
|
4996
|
-
scimConfigurations:
|
|
4997
|
-
scimTokens:
|
|
4998
|
-
scimExternalIds:
|
|
4999
|
-
refreshTokens:
|
|
5000
|
-
resourceServers:
|
|
5001
|
-
rolePermissions:
|
|
5002
|
-
userPermissions:
|
|
5003
|
-
roles:
|
|
5004
|
-
sessions:
|
|
5005
|
-
sessionCleanup:
|
|
5006
|
-
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),
|
|
5007
5188
|
...t.controlPlane ? {
|
|
5008
|
-
tenantOperations:
|
|
5009
|
-
tenantOperationEvents:
|
|
5010
|
-
|
|
5189
|
+
tenantOperations: mi(e),
|
|
5190
|
+
tenantOperationEvents: Pi(e),
|
|
5191
|
+
tenantOperationRows: xi(e),
|
|
5192
|
+
rollouts: Li(e)
|
|
5011
5193
|
} : {},
|
|
5012
|
-
themes:
|
|
5013
|
-
universalLoginTemplates:
|
|
5014
|
-
users:
|
|
5015
|
-
userActivity:
|
|
5016
|
-
userRoles:
|
|
5017
|
-
userOrganizations:
|
|
5018
|
-
stats:
|
|
5019
|
-
analytics:
|
|
5020
|
-
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),
|
|
5021
5203
|
async transaction(r) {
|
|
5022
|
-
if (t.useTransactions === !1 ||
|
|
5204
|
+
if (t.useTransactions === !1 || bt(e)) return r(n);
|
|
5023
5205
|
await e.run(y`BEGIN`);
|
|
5024
5206
|
try {
|
|
5025
5207
|
let t = await r(n);
|
|
@@ -5033,7 +5215,7 @@ function Di(e, t = { useTransactions: !0 }) {
|
|
|
5033
5215
|
}
|
|
5034
5216
|
//#endregion
|
|
5035
5217
|
//#region src/adapters/resolveHost.ts
|
|
5036
|
-
function
|
|
5218
|
+
function zi(e) {
|
|
5037
5219
|
if (!e) return { path: "/*" };
|
|
5038
5220
|
try {
|
|
5039
5221
|
let t = JSON.parse(e), n = be.safeParse(t);
|
|
@@ -5041,7 +5223,7 @@ function Oi(e) {
|
|
|
5041
5223
|
} catch {}
|
|
5042
5224
|
return { path: "/*" };
|
|
5043
5225
|
}
|
|
5044
|
-
function
|
|
5226
|
+
function Bi(e) {
|
|
5045
5227
|
if (!e) return [];
|
|
5046
5228
|
try {
|
|
5047
5229
|
let t = JSON.parse(e);
|
|
@@ -5056,20 +5238,20 @@ function ki(e) {
|
|
|
5056
5238
|
return [];
|
|
5057
5239
|
}
|
|
5058
5240
|
}
|
|
5059
|
-
async function
|
|
5241
|
+
async function Vi(e, r) {
|
|
5060
5242
|
let i = r.toLowerCase(), o = (await e.select({
|
|
5061
|
-
custom_domain_id:
|
|
5062
|
-
tenant_id:
|
|
5063
|
-
domain:
|
|
5064
|
-
}).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];
|
|
5065
5247
|
if (!o) return null;
|
|
5066
|
-
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) => ({
|
|
5067
5249
|
id: e.id,
|
|
5068
5250
|
tenant_id: e.tenant_id,
|
|
5069
5251
|
custom_domain_id: e.custom_domain_id,
|
|
5070
5252
|
priority: e.priority,
|
|
5071
|
-
match:
|
|
5072
|
-
handlers:
|
|
5253
|
+
match: zi(e.match),
|
|
5254
|
+
handlers: Bi(e.handlers),
|
|
5073
5255
|
created_at: e.created_at,
|
|
5074
5256
|
updated_at: e.updated_at
|
|
5075
5257
|
}));
|
|
@@ -5082,11 +5264,11 @@ async function Ai(e, r) {
|
|
|
5082
5264
|
}
|
|
5083
5265
|
//#endregion
|
|
5084
5266
|
//#region src/adapters/proxyData.ts
|
|
5085
|
-
function
|
|
5267
|
+
function Hi(e) {
|
|
5086
5268
|
return {
|
|
5087
|
-
proxyRoutes:
|
|
5088
|
-
resolveHost: (t) =>
|
|
5269
|
+
proxyRoutes: Zn(e),
|
|
5270
|
+
resolveHost: (t) => Vi(e, t)
|
|
5089
5271
|
};
|
|
5090
5272
|
}
|
|
5091
5273
|
//#endregion
|
|
5092
|
-
export {
|
|
5274
|
+
export { Hi as createProxyDataAdapter, Zn as createProxyRoutesAdapter, Ri as default, lt as sqlite };
|