@authhero/drizzle 1.0.0 → 1.2.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 +969 -757
- package/drizzle/0001_scim_inbound_provisioning.sql +34 -0
- package/drizzle/0002_user_blocked.sql +1 -0
- package/drizzle/0003_prompt_settings_last_used.sql +1 -0
- package/drizzle/0004_action_executions_created_at_index.sql +1 -0
- package/drizzle/meta/0001_snapshot.json +6563 -0
- package/drizzle/meta/0002_snapshot.json +6570 -0
- package/drizzle/meta/0003_snapshot.json +6578 -0
- package/drizzle/meta/0004_snapshot.json +6586 -0
- package/drizzle/meta/_journal.json +28 -0
- package/package.json +3 -3
- package/src/schema/sqlite/actions.ts +1 -0
- package/src/schema/sqlite/branding.ts +5 -0
- package/src/schema/sqlite/index.ts +3 -0
- package/src/schema/sqlite/scim.ts +79 -0
- package/src/schema/sqlite/users.ts +2 -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 E } from "drizzle-orm/sqlite-core";
|
|
4
4
|
import { booleanToInt as re, convertDatesToAdapter as ie, dbDateToIsoRequired as ae, getCountAsInt as oe, isoToDbDate as D, removeNullProperties as O, removeUndefinedAndNull as se, stringifyProperties as ce } from "@authhero/adapter-interfaces/sql";
|
|
5
|
-
import { clientRegistrationTokenTypeSchema as le, decodeCursor as ue, encodeCursor as de, handlerConfigSchema as fe, isPlainObject as pe, matchSchema as me, rolloutInsertSchema as he, rolloutSchema as ge, sanitizeLuceneQuery as _e,
|
|
6
|
-
import { HTTPException as
|
|
5
|
+
import { clientRegistrationTokenTypeSchema as le, decodeCursor as ue, encodeCursor as de, handlerConfigSchema as fe, isPlainObject as pe, matchSchema as me, rolloutInsertSchema as he, rolloutSchema as ge, sanitizeLuceneQuery as _e, scimMappingEntrySchema as ve, tenantOperationEventInsertSchema as ye, tenantOperationEventSchema as be, tenantOperationInsertSchema as xe, tenantOperationSchema as Se } from "@authhero/adapter-interfaces";
|
|
6
|
+
import { HTTPException as Ce } from "hono/http-exception";
|
|
7
7
|
//#region \0rolldown/runtime.js
|
|
8
|
-
var
|
|
8
|
+
var we = Object.defineProperty, Te = (e, t) => {
|
|
9
9
|
let n = {};
|
|
10
|
-
for (var r in e)
|
|
10
|
+
for (var r in e) we(n, r, {
|
|
11
11
|
get: e[r],
|
|
12
12
|
enumerable: !0
|
|
13
13
|
});
|
|
14
|
-
return t ||
|
|
14
|
+
return t || we(n, Symbol.toStringTag, { value: "Module" }), n;
|
|
15
15
|
}, k = w("tenants", {
|
|
16
16
|
id: T("id", { length: 191 }).primaryKey(),
|
|
17
17
|
name: T("name", { length: 255 }),
|
|
@@ -67,7 +67,7 @@ var Ce = Object.defineProperty, we = (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
|
+
}), Ee = w("actions", {
|
|
71
71
|
id: T("id", { length: 255 }).notNull(),
|
|
72
72
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => k.id, { onDelete: "cascade" }),
|
|
73
73
|
name: T("name", { length: 255 }).notNull(),
|
|
@@ -109,7 +109,7 @@ var Ce = Object.defineProperty, we = (e, t) => {
|
|
|
109
109
|
}),
|
|
110
110
|
E("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
|
+
]), De = w("action_executions", {
|
|
113
113
|
id: T("id", { length: 255 }).notNull(),
|
|
114
114
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => k.id, { onDelete: "cascade" }),
|
|
115
115
|
trigger_id: T("trigger_id", { length: 255 }).notNull(),
|
|
@@ -121,7 +121,7 @@ var Ce = Object.defineProperty, we = (e, t) => {
|
|
|
121
121
|
}, (e) => [C({
|
|
122
122
|
columns: [e.tenant_id, e.id],
|
|
123
123
|
name: "action_executions_pk"
|
|
124
|
-
})]), j = w("users", {
|
|
124
|
+
}), x("action_executions_created_at_ts_index").on(e.created_at_ts)]), j = w("users", {
|
|
125
125
|
user_id: T("user_id", { length: 255 }).notNull(),
|
|
126
126
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => k.id, { onDelete: "cascade" }),
|
|
127
127
|
email: T("email", { length: 255 }),
|
|
@@ -142,6 +142,7 @@ var Ce = Object.defineProperty, we = (e, t) => {
|
|
|
142
142
|
connection: T("connection", { length: 255 }),
|
|
143
143
|
email_verified: S("email_verified", { mode: "boolean" }).notNull(),
|
|
144
144
|
is_social: S("is_social", { mode: "boolean" }).notNull(),
|
|
145
|
+
blocked: S("blocked", { mode: "boolean" }),
|
|
145
146
|
app_metadata: T("app_metadata", { length: 4096 }).notNull().default("{}"),
|
|
146
147
|
user_metadata: T("user_metadata").notNull().default("{}"),
|
|
147
148
|
profileData: T("profileData", { length: 2048 }),
|
|
@@ -174,7 +175,7 @@ var Ce = Object.defineProperty, we = (e, t) => {
|
|
|
174
175
|
password: T("password", { length: 255 }).notNull(),
|
|
175
176
|
algorithm: T("algorithm", { length: 16 }).notNull().default("bcrypt"),
|
|
176
177
|
is_current: S("is_current").notNull().default(1)
|
|
177
|
-
}),
|
|
178
|
+
}), Oe = w("user_activity", {
|
|
178
179
|
tenant_id: T("tenant_id", { length: 255 }).notNull(),
|
|
179
180
|
user_id: T("user_id", { length: 255 }).notNull(),
|
|
180
181
|
last_login: T("last_login", { length: 35 }),
|
|
@@ -291,7 +292,7 @@ var Ce = Object.defineProperty, we = (e, t) => {
|
|
|
291
292
|
}, (e) => [C({
|
|
292
293
|
columns: [e.code_id, e.code_type],
|
|
293
294
|
name: "PK_codes_code_id_code_type"
|
|
294
|
-
}), x("codes_expires_at_index").on(e.expires_at)]),
|
|
295
|
+
}), x("codes_expires_at_index").on(e.expires_at)]), ke = w("authentication_codes", {
|
|
295
296
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => k.id, { onDelete: "cascade" }),
|
|
296
297
|
code: T("code", { length: 255 }).primaryKey(),
|
|
297
298
|
client_id: T("client_id", { length: 255 }).notNull(),
|
|
@@ -305,7 +306,7 @@ var Ce = Object.defineProperty, we = (e, t) => {
|
|
|
305
306
|
created_at: T("created_at", { length: 35 }).notNull(),
|
|
306
307
|
expires_at: T("expires_at", { length: 35 }).notNull(),
|
|
307
308
|
used_at: T("used_at", { length: 35 })
|
|
308
|
-
}),
|
|
309
|
+
}), Ae = w("otps", {
|
|
309
310
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => k.id, { onDelete: "cascade" }),
|
|
310
311
|
id: T("id", { length: 255 }).primaryKey(),
|
|
311
312
|
client_id: T("client_id", { length: 255 }).notNull(),
|
|
@@ -324,7 +325,7 @@ var Ce = Object.defineProperty, we = (e, t) => {
|
|
|
324
325
|
used_at: T("used_at", { length: 35 }),
|
|
325
326
|
audience: T("audience", { length: 255 }),
|
|
326
327
|
ip: T("ip", { length: 64 })
|
|
327
|
-
}, (e) => [x("otps_email_index").on(e.email), x("otps_expires_at_index").on(e.expires_at)]),
|
|
328
|
+
}, (e) => [x("otps_email_index").on(e.email), x("otps_expires_at_index").on(e.expires_at)]), je = w("tickets", {
|
|
328
329
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => k.id, { onDelete: "cascade" }),
|
|
329
330
|
id: T("id", { length: 255 }).primaryKey(),
|
|
330
331
|
client_id: T("client_id", { length: 255 }).notNull(),
|
|
@@ -463,7 +464,7 @@ var Ce = Object.defineProperty, we = (e, t) => {
|
|
|
463
464
|
C({ columns: [e.tenant_id, e.id] }),
|
|
464
465
|
x("connections_tenant_id_index").on(e.tenant_id),
|
|
465
466
|
E("connections_id_unique").on(e.id)
|
|
466
|
-
]),
|
|
467
|
+
]), Me = w("custom_domains", {
|
|
467
468
|
custom_domain_id: T("custom_domain_id", { length: 256 }).primaryKey(),
|
|
468
469
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => k.id, { onDelete: "cascade" }),
|
|
469
470
|
domain: T("domain", { length: 255 }).notNull(),
|
|
@@ -477,7 +478,7 @@ var Ce = Object.defineProperty, we = (e, t) => {
|
|
|
477
478
|
domain_metadata: T("domain_metadata", { length: 2048 }),
|
|
478
479
|
created_at: T("created_at", { length: 35 }).notNull(),
|
|
479
480
|
updated_at: T("updated_at", { length: 35 }).notNull()
|
|
480
|
-
}, (e) => [E("custom_domains_domain_unique").on(e.domain)]),
|
|
481
|
+
}, (e) => [E("custom_domains_domain_unique").on(e.domain)]), Ne = w("domains", {
|
|
481
482
|
id: T("id", { length: 255 }).primaryKey(),
|
|
482
483
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => k.id, { onDelete: "cascade" }),
|
|
483
484
|
domain: T("domain", { length: 255 }).notNull(),
|
|
@@ -487,7 +488,7 @@ var Ce = Object.defineProperty, we = (e, t) => {
|
|
|
487
488
|
dkim_public_key: T("dkim_public_key", { length: 2048 }),
|
|
488
489
|
created_at: T("created_at", { length: 35 }).notNull(),
|
|
489
490
|
updated_at: T("updated_at", { length: 35 }).notNull()
|
|
490
|
-
}),
|
|
491
|
+
}), H = w("organizations", {
|
|
491
492
|
id: T("id", { length: 21 }).primaryKey(),
|
|
492
493
|
tenant_id: T("tenant_id", { length: 191 }).notNull(),
|
|
493
494
|
name: T("name", { length: 256 }).notNull(),
|
|
@@ -498,7 +499,7 @@ var Ce = Object.defineProperty, we = (e, t) => {
|
|
|
498
499
|
token_quota: T("token_quota"),
|
|
499
500
|
created_at: T("created_at", { length: 35 }).notNull(),
|
|
500
501
|
updated_at: T("updated_at", { length: 35 }).notNull()
|
|
501
|
-
}, (e) => [x("idx_organizations_tenant_id").on(e.tenant_id)]),
|
|
502
|
+
}, (e) => [x("idx_organizations_tenant_id").on(e.tenant_id)]), U = w("user_organizations", {
|
|
502
503
|
id: T("id", { length: 21 }).primaryKey(),
|
|
503
504
|
tenant_id: T("tenant_id", { length: 191 }).notNull(),
|
|
504
505
|
user_id: T("user_id", { length: 191 }).notNull(),
|
|
@@ -510,7 +511,7 @@ var Ce = Object.defineProperty, we = (e, t) => {
|
|
|
510
511
|
x("idx_user_organizations_tenant_id").on(e.tenant_id),
|
|
511
512
|
x("idx_user_organizations_user_id").on(e.user_id),
|
|
512
513
|
x("idx_user_organizations_organization_id").on(e.organization_id)
|
|
513
|
-
]),
|
|
514
|
+
]), Pe = w("invites", {
|
|
514
515
|
id: T("id", { length: 21 }).primaryKey(),
|
|
515
516
|
tenant_id: T("tenant_id", { length: 191 }).notNull(),
|
|
516
517
|
organization_id: T("organization_id", { length: 21 }).notNull(),
|
|
@@ -532,7 +533,7 @@ var Ce = Object.defineProperty, we = (e, t) => {
|
|
|
532
533
|
x("idx_invites_organization_id").on(e.organization_id),
|
|
533
534
|
x("idx_invites_expires_at").on(e.expires_at),
|
|
534
535
|
x("idx_invites_tenant_created").on(e.tenant_id, e.created_at)
|
|
535
|
-
]),
|
|
536
|
+
]), W = w("roles", {
|
|
536
537
|
id: T("id", { length: 21 }).notNull(),
|
|
537
538
|
tenant_id: T("tenant_id", { length: 191 }).notNull(),
|
|
538
539
|
name: T("name", { length: 50 }).notNull(),
|
|
@@ -544,7 +545,7 @@ var Ce = Object.defineProperty, we = (e, t) => {
|
|
|
544
545
|
}, (e) => [C({
|
|
545
546
|
columns: [e.tenant_id, e.id],
|
|
546
547
|
name: "roles_pk"
|
|
547
|
-
})]),
|
|
548
|
+
})]), Fe = w("role_permissions", {
|
|
548
549
|
tenant_id: T("tenant_id", { length: 191 }).notNull(),
|
|
549
550
|
role_id: T("role_id", { length: 21 }).notNull(),
|
|
550
551
|
resource_server_identifier: T("resource_server_identifier", { length: 191 }).notNull(),
|
|
@@ -562,7 +563,7 @@ var Ce = Object.defineProperty, we = (e, t) => {
|
|
|
562
563
|
}),
|
|
563
564
|
x("role_permissions_role_fk").on(e.tenant_id, e.role_id),
|
|
564
565
|
x("role_permissions_permission_fk").on(e.tenant_id, e.resource_server_identifier, e.permission_name)
|
|
565
|
-
]),
|
|
566
|
+
]), Ie = w("user_permissions", {
|
|
566
567
|
tenant_id: T("tenant_id", { length: 191 }).notNull(),
|
|
567
568
|
user_id: T("user_id", { length: 191 }).notNull(),
|
|
568
569
|
resource_server_identifier: T("resource_server_identifier", { length: 191 }).notNull(),
|
|
@@ -583,7 +584,7 @@ var Ce = Object.defineProperty, we = (e, t) => {
|
|
|
583
584
|
x("user_permissions_user_fk").on(e.tenant_id, e.user_id),
|
|
584
585
|
x("user_permissions_permission_fk").on(e.tenant_id, e.resource_server_identifier, e.permission_name),
|
|
585
586
|
x("user_permissions_organization_fk").on(e.organization_id)
|
|
586
|
-
]),
|
|
587
|
+
]), G = w("user_roles", {
|
|
587
588
|
tenant_id: T("tenant_id", { length: 191 }).notNull(),
|
|
588
589
|
user_id: T("user_id", { length: 191 }).notNull(),
|
|
589
590
|
role_id: T("role_id", { length: 21 }).notNull(),
|
|
@@ -602,7 +603,7 @@ var Ce = Object.defineProperty, we = (e, t) => {
|
|
|
602
603
|
x("user_roles_user_fk").on(e.tenant_id, e.user_id),
|
|
603
604
|
x("user_roles_role_fk").on(e.tenant_id, e.role_id),
|
|
604
605
|
x("user_roles_organization_fk").on(e.organization_id)
|
|
605
|
-
]),
|
|
606
|
+
]), K = w("resource_servers", {
|
|
606
607
|
id: T("id", { length: 21 }).notNull(),
|
|
607
608
|
tenant_id: T("tenant_id", { length: 191 }).notNull(),
|
|
608
609
|
identifier: T("identifier", { length: 191 }).notNull(),
|
|
@@ -623,7 +624,7 @@ var Ce = Object.defineProperty, we = (e, t) => {
|
|
|
623
624
|
}, (e) => [C({
|
|
624
625
|
columns: [e.tenant_id, e.id],
|
|
625
626
|
name: "resource_servers_pk"
|
|
626
|
-
})]),
|
|
627
|
+
})]), Le = w("branding", {
|
|
627
628
|
tenant_id: T("tenant_id", { length: 191 }).primaryKey().references(() => k.id, { onDelete: "cascade" }),
|
|
628
629
|
logo_url: T("logo_url", { length: 512 }),
|
|
629
630
|
favicon_url: T("favicon_url", { length: 512 }),
|
|
@@ -634,12 +635,12 @@ var Ce = Object.defineProperty, we = (e, t) => {
|
|
|
634
635
|
colors_page_background_end: T("colors_page_background_end", { length: 8 }),
|
|
635
636
|
colors_page_background_angle_dev: S("colors_page_background_angle_dev"),
|
|
636
637
|
dark_mode: T("dark_mode", { length: 8 })
|
|
637
|
-
}),
|
|
638
|
+
}), Re = w("universal_login_templates", {
|
|
638
639
|
tenant_id: T("tenant_id", { length: 191 }).primaryKey().references(() => k.id, { onDelete: "cascade" }),
|
|
639
640
|
body: T("body").notNull(),
|
|
640
641
|
created_at_ts: S("created_at_ts").notNull(),
|
|
641
642
|
updated_at_ts: S("updated_at_ts").notNull()
|
|
642
|
-
}),
|
|
643
|
+
}), ze = w("themes", {
|
|
643
644
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => k.id, { onDelete: "cascade" }),
|
|
644
645
|
themeId: T("themeId", { length: 255 }).notNull(),
|
|
645
646
|
displayName: T("displayName", { length: 255 }).notNull(),
|
|
@@ -699,7 +700,7 @@ var Ce = Object.defineProperty, we = (e, t) => {
|
|
|
699
700
|
}, (e) => [C({
|
|
700
701
|
columns: [e.tenant_id, e.themeId],
|
|
701
702
|
name: "themes_pkey"
|
|
702
|
-
}), x("themes_tenant_id_idx").on(e.tenant_id)]),
|
|
703
|
+
}), x("themes_tenant_id_idx").on(e.tenant_id)]), Be = w("forms", {
|
|
703
704
|
id: T("id", { length: 255 }).primaryKey(),
|
|
704
705
|
name: T("name", { length: 255 }).notNull(),
|
|
705
706
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => k.id, { onDelete: "cascade" }),
|
|
@@ -712,20 +713,21 @@ var Ce = Object.defineProperty, we = (e, t) => {
|
|
|
712
713
|
style: T("style", { length: 1042 }),
|
|
713
714
|
created_at: T("created_at", { length: 35 }).notNull(),
|
|
714
715
|
updated_at: T("updated_at", { length: 35 }).notNull()
|
|
715
|
-
}, (e) => [x("forms_tenant_id_idx").on(e.tenant_id)]),
|
|
716
|
+
}, (e) => [x("forms_tenant_id_idx").on(e.tenant_id)]), Ve = w("flows", {
|
|
716
717
|
id: T("id", { length: 24 }).primaryKey(),
|
|
717
718
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => k.id, { onDelete: "cascade" }),
|
|
718
719
|
name: T("name", { length: 150 }).notNull(),
|
|
719
720
|
actions: T("actions"),
|
|
720
721
|
created_at: T("created_at", { length: 35 }).notNull(),
|
|
721
722
|
updated_at: T("updated_at", { length: 35 }).notNull()
|
|
722
|
-
}, (e) => [x("flows_tenant_id_idx").on(e.tenant_id)]),
|
|
723
|
+
}, (e) => [x("flows_tenant_id_idx").on(e.tenant_id)]), He = w("prompt_settings", {
|
|
723
724
|
tenant_id: T("tenant_id", { length: 191 }).primaryKey(),
|
|
724
725
|
universal_login_experience: T("universal_login_experience", { length: 16 }).notNull().default("new"),
|
|
725
726
|
identifier_first: S("identifier_first", { mode: "boolean" }).notNull().default(!0),
|
|
726
727
|
password_first: S("password_first", { mode: "boolean" }).notNull().default(!1),
|
|
727
|
-
webauthn_platform_first_factor: S("webauthn_platform_first_factor", { mode: "boolean" }).notNull().default(!1)
|
|
728
|
-
|
|
728
|
+
webauthn_platform_first_factor: S("webauthn_platform_first_factor", { mode: "boolean" }).notNull().default(!1),
|
|
729
|
+
show_last_used_connection: S("show_last_used_connection", { mode: "boolean" }).notNull().default(!1)
|
|
730
|
+
}), Ue = w("email_providers", {
|
|
729
731
|
tenant_id: T("tenant_id", { length: 191 }).primaryKey(),
|
|
730
732
|
name: T("name", { length: 255 }).notNull(),
|
|
731
733
|
enabled: S("enabled", { mode: "boolean" }).notNull(),
|
|
@@ -734,7 +736,7 @@ var Ce = Object.defineProperty, we = (e, t) => {
|
|
|
734
736
|
settings: T("settings", { length: 2048 }).notNull().default("{}"),
|
|
735
737
|
created_at: T("created_at", { length: 35 }).notNull(),
|
|
736
738
|
updated_at: T("updated_at", { length: 35 }).notNull()
|
|
737
|
-
}),
|
|
739
|
+
}), We = w("email_templates", {
|
|
738
740
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => k.id, { onDelete: "cascade" }),
|
|
739
741
|
template: T("template", { length: 64 }).notNull(),
|
|
740
742
|
body: T("body").notNull(),
|
|
@@ -747,7 +749,7 @@ var Ce = Object.defineProperty, we = (e, t) => {
|
|
|
747
749
|
enabled: S("enabled", { mode: "boolean" }).notNull().default(!0),
|
|
748
750
|
created_at: T("created_at", { length: 35 }).notNull(),
|
|
749
751
|
updated_at: T("updated_at", { length: 35 }).notNull()
|
|
750
|
-
}, (e) => [C({ columns: [e.tenant_id, e.template] })]),
|
|
752
|
+
}, (e) => [C({ columns: [e.tenant_id, e.template] })]), Ge = w("hooks", {
|
|
751
753
|
hook_id: T("hook_id", { length: 21 }).primaryKey(),
|
|
752
754
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => k.id, { onDelete: "cascade" }),
|
|
753
755
|
url: T("url", { length: 512 }),
|
|
@@ -761,14 +763,14 @@ var Ce = Object.defineProperty, we = (e, t) => {
|
|
|
761
763
|
template_id: T("template_id", { length: 64 }),
|
|
762
764
|
code_id: T("code_id", { length: 21 }),
|
|
763
765
|
metadata: T("metadata")
|
|
764
|
-
}, (e) => [x("hooks_tenant_id_idx").on(e.tenant_id)]),
|
|
766
|
+
}, (e) => [x("hooks_tenant_id_idx").on(e.tenant_id)]), Ke = w("hook_code", {
|
|
765
767
|
id: T("id", { length: 21 }).primaryKey(),
|
|
766
768
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => k.id, { onDelete: "cascade" }),
|
|
767
769
|
code: T("code").notNull(),
|
|
768
770
|
secrets: T("secrets"),
|
|
769
771
|
created_at_ts: S("created_at_ts").notNull(),
|
|
770
772
|
updated_at_ts: S("updated_at_ts").notNull()
|
|
771
|
-
}, (e) => [x("hook_code_tenant_id_idx").on(e.tenant_id)]),
|
|
773
|
+
}, (e) => [x("hook_code_tenant_id_idx").on(e.tenant_id)]), qe = w("keys", {
|
|
772
774
|
kid: T("kid", { length: 255 }).primaryKey(),
|
|
773
775
|
tenant_id: T("tenant_id", { length: 191 }).references(() => k.id, { onDelete: "cascade" }),
|
|
774
776
|
created_at: T("created_at", { length: 35 }).notNull(),
|
|
@@ -781,7 +783,7 @@ var Ce = Object.defineProperty, we = (e, t) => {
|
|
|
781
783
|
current_until: T("current_until", { length: 35 }),
|
|
782
784
|
type: T("type", { length: 50 }).notNull().default("jwt_signing"),
|
|
783
785
|
connection: T("connection", { length: 255 }).references(() => V.id, { onDelete: "cascade" })
|
|
784
|
-
}),
|
|
786
|
+
}), Je = w("custom_text", {
|
|
785
787
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => k.id, { onDelete: "cascade" }),
|
|
786
788
|
prompt: T("prompt", { length: 64 }).notNull(),
|
|
787
789
|
language: T("language", { length: 16 }).notNull(),
|
|
@@ -792,7 +794,7 @@ var Ce = Object.defineProperty, we = (e, t) => {
|
|
|
792
794
|
e.tenant_id,
|
|
793
795
|
e.prompt,
|
|
794
796
|
e.language
|
|
795
|
-
] })]),
|
|
797
|
+
] })]), q = w("authentication_methods", {
|
|
796
798
|
id: T("id", { length: 26 }).primaryKey(),
|
|
797
799
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => k.id, { onDelete: "cascade" }),
|
|
798
800
|
user_id: T("user_id", { length: 255 }).notNull(),
|
|
@@ -808,7 +810,7 @@ var Ce = Object.defineProperty, we = (e, t) => {
|
|
|
808
810
|
confirmed: S("confirmed").notNull().default(0),
|
|
809
811
|
created_at_ts: S("created_at_ts").notNull(),
|
|
810
812
|
updated_at_ts: S("updated_at_ts").notNull()
|
|
811
|
-
}, (e) => [x("authentication_methods_tenant_user_idx").on(e.tenant_id, e.user_id), x("authentication_methods_credential_id_idx").on(e.credential_id)]),
|
|
813
|
+
}, (e) => [x("authentication_methods_tenant_user_idx").on(e.tenant_id, e.user_id), x("authentication_methods_credential_id_idx").on(e.credential_id)]), J = w("logs", {
|
|
812
814
|
log_id: T("log_id", { length: 21 }).primaryKey(),
|
|
813
815
|
category: T("category", { length: 255 }),
|
|
814
816
|
tenant_id: T("tenant_id", { length: 64 }),
|
|
@@ -843,7 +845,7 @@ var Ce = Object.defineProperty, we = (e, t) => {
|
|
|
843
845
|
x("logs_tenant_id").on(e.tenant_id),
|
|
844
846
|
x("logs_date").on(e.date),
|
|
845
847
|
x("IDX_logs_tenant_date_type_user").on(e.tenant_id, e.date, e.type, e.user_id)
|
|
846
|
-
]),
|
|
848
|
+
]), Y = w("outbox_events", {
|
|
847
849
|
id: T("id", { length: 26 }).primaryKey(),
|
|
848
850
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => k.id, { onDelete: "cascade" }),
|
|
849
851
|
event_type: T("event_type", { length: 64 }).notNull(),
|
|
@@ -865,7 +867,7 @@ var Ce = Object.defineProperty, we = (e, t) => {
|
|
|
865
867
|
x("idx_outbox_events_processed_at").on(e.processed_at),
|
|
866
868
|
x("idx_outbox_events_claimed_by").on(e.claimed_by),
|
|
867
869
|
x("idx_outbox_events_tenant_dead_lettered").on(e.tenant_id, e.dead_lettered_at)
|
|
868
|
-
]),
|
|
870
|
+
]), X = w("proxy_routes", {
|
|
869
871
|
id: T("id", { length: 64 }).primaryKey(),
|
|
870
872
|
tenant_id: T("tenant_id", { length: 255 }).notNull(),
|
|
871
873
|
custom_domain_id: T("custom_domain_id", { length: 256 }).notNull(),
|
|
@@ -874,51 +876,84 @@ var Ce = Object.defineProperty, we = (e, t) => {
|
|
|
874
876
|
handlers: T("handlers", { length: 16384 }).notNull().default("[]"),
|
|
875
877
|
created_at: T("created_at", { length: 35 }).notNull(),
|
|
876
878
|
updated_at: T("updated_at", { length: 35 }).notNull()
|
|
877
|
-
}, (e) => [x("proxy_routes_tenant_id_idx").on(e.tenant_id), x("proxy_routes_custom_domain_id_idx").on(e.custom_domain_id)]),
|
|
878
|
-
|
|
879
|
+
}, (e) => [x("proxy_routes_tenant_id_idx").on(e.tenant_id), x("proxy_routes_custom_domain_id_idx").on(e.custom_domain_id)]), Ye = w("scim_configurations", {
|
|
880
|
+
connection_id: T("connection_id", { length: 255 }).notNull(),
|
|
881
|
+
tenant_id: T("tenant_id", { length: 255 }).notNull(),
|
|
882
|
+
user_id_attribute: T("user_id_attribute", { length: 255 }).notNull().default("externalId"),
|
|
883
|
+
mapping: T("mapping", { length: 16384 }).notNull().default("[]"),
|
|
884
|
+
created_at: T("created_at", { length: 35 }).notNull(),
|
|
885
|
+
updated_at: T("updated_at", { length: 35 }).notNull()
|
|
886
|
+
}, (e) => [C({ columns: [e.tenant_id, e.connection_id] })]), Z = w("scim_tokens", {
|
|
887
|
+
token_id: T("token_id", { length: 64 }).notNull(),
|
|
888
|
+
tenant_id: T("tenant_id", { length: 255 }).notNull(),
|
|
889
|
+
connection_id: T("connection_id", { length: 255 }).notNull(),
|
|
890
|
+
token_hash: T("token_hash", { length: 128 }).notNull(),
|
|
891
|
+
scopes: T("scopes", { length: 4096 }).notNull().default("[]"),
|
|
892
|
+
valid_until: T("valid_until", { length: 35 }),
|
|
893
|
+
created_at: T("created_at", { length: 35 }).notNull(),
|
|
894
|
+
last_used_at: T("last_used_at", { length: 35 })
|
|
895
|
+
}, (e) => [
|
|
896
|
+
C({ columns: [e.tenant_id, e.token_id] }),
|
|
897
|
+
x("scim_tokens_tenant_connection_idx").on(e.tenant_id, e.connection_id),
|
|
898
|
+
E("scim_tokens_tenant_hash_idx").on(e.tenant_id, e.token_hash)
|
|
899
|
+
]), Xe = w("scim_external_ids", {
|
|
900
|
+
tenant_id: T("tenant_id", { length: 255 }).notNull(),
|
|
901
|
+
connection_id: T("connection_id", { length: 255 }).notNull(),
|
|
902
|
+
external_id: T("external_id", { length: 255 }).notNull(),
|
|
903
|
+
user_id: T("user_id", { length: 255 }).notNull(),
|
|
904
|
+
created_at: T("created_at", { length: 35 }).notNull()
|
|
905
|
+
}, (e) => [C({ columns: [
|
|
906
|
+
e.tenant_id,
|
|
907
|
+
e.connection_id,
|
|
908
|
+
e.user_id
|
|
909
|
+
] }), E("scim_external_ids_connection_external_idx").on(e.tenant_id, e.connection_id, e.external_id)]), Ze = /* @__PURE__ */ Te({
|
|
910
|
+
actionExecutions: () => De,
|
|
879
911
|
actionVersions: () => A,
|
|
880
|
-
actions: () =>
|
|
881
|
-
authenticationCodes: () =>
|
|
882
|
-
authenticationMethods: () =>
|
|
883
|
-
branding: () =>
|
|
912
|
+
actions: () => Ee,
|
|
913
|
+
authenticationCodes: () => ke,
|
|
914
|
+
authenticationMethods: () => q,
|
|
915
|
+
branding: () => Le,
|
|
884
916
|
clientGrants: () => z,
|
|
885
917
|
clientRegistrationTokens: () => R,
|
|
886
918
|
clients: () => L,
|
|
887
919
|
codes: () => I,
|
|
888
920
|
connections: () => V,
|
|
889
|
-
customDomains: () =>
|
|
890
|
-
customText: () =>
|
|
891
|
-
domains: () =>
|
|
892
|
-
emailProviders: () =>
|
|
893
|
-
emailTemplates: () =>
|
|
894
|
-
flows: () =>
|
|
895
|
-
forms: () =>
|
|
921
|
+
customDomains: () => Me,
|
|
922
|
+
customText: () => Je,
|
|
923
|
+
domains: () => Ne,
|
|
924
|
+
emailProviders: () => Ue,
|
|
925
|
+
emailTemplates: () => We,
|
|
926
|
+
flows: () => Ve,
|
|
927
|
+
forms: () => Be,
|
|
896
928
|
grants: () => B,
|
|
897
|
-
hookCode: () =>
|
|
898
|
-
hooks: () =>
|
|
899
|
-
invites: () =>
|
|
900
|
-
keys: () =>
|
|
929
|
+
hookCode: () => Ke,
|
|
930
|
+
hooks: () => Ge,
|
|
931
|
+
invites: () => Pe,
|
|
932
|
+
keys: () => qe,
|
|
901
933
|
loginSessions: () => F,
|
|
902
|
-
logs: () =>
|
|
903
|
-
organizations: () =>
|
|
904
|
-
otps: () =>
|
|
905
|
-
outboxEvents: () =>
|
|
934
|
+
logs: () => J,
|
|
935
|
+
organizations: () => H,
|
|
936
|
+
otps: () => Ae,
|
|
937
|
+
outboxEvents: () => Y,
|
|
906
938
|
passwords: () => M,
|
|
907
|
-
promptSettings: () =>
|
|
908
|
-
proxyRoutes: () =>
|
|
939
|
+
promptSettings: () => He,
|
|
940
|
+
proxyRoutes: () => X,
|
|
909
941
|
refreshTokens: () => P,
|
|
910
|
-
resourceServers: () =>
|
|
911
|
-
rolePermissions: () =>
|
|
912
|
-
roles: () =>
|
|
942
|
+
resourceServers: () => K,
|
|
943
|
+
rolePermissions: () => Fe,
|
|
944
|
+
roles: () => W,
|
|
945
|
+
scimConfigurations: () => Ye,
|
|
946
|
+
scimExternalIds: () => Xe,
|
|
947
|
+
scimTokens: () => Z,
|
|
913
948
|
sessions: () => N,
|
|
914
949
|
tenants: () => k,
|
|
915
|
-
themes: () =>
|
|
916
|
-
tickets: () =>
|
|
917
|
-
universalLoginTemplates: () =>
|
|
918
|
-
userActivity: () =>
|
|
919
|
-
userOrganizations: () =>
|
|
920
|
-
userPermissions: () =>
|
|
921
|
-
userRoles: () =>
|
|
950
|
+
themes: () => ze,
|
|
951
|
+
tickets: () => je,
|
|
952
|
+
universalLoginTemplates: () => Re,
|
|
953
|
+
userActivity: () => Oe,
|
|
954
|
+
userOrganizations: () => U,
|
|
955
|
+
userPermissions: () => Ie,
|
|
956
|
+
userRoles: () => G,
|
|
922
957
|
users: () => j
|
|
923
958
|
});
|
|
924
959
|
//#endregion
|
|
@@ -932,14 +967,14 @@ function Q(e, t) {
|
|
|
932
967
|
}
|
|
933
968
|
return e;
|
|
934
969
|
}
|
|
935
|
-
function
|
|
970
|
+
function Qe(e, t = "", n = {}) {
|
|
936
971
|
for (let r in e) if (Object.prototype.hasOwnProperty.call(e, r)) {
|
|
937
972
|
let i = t ? `${t}_${r}` : r, a = e[r];
|
|
938
|
-
typeof a == "object" && a && !Array.isArray(a) ?
|
|
973
|
+
typeof a == "object" && a && !Array.isArray(a) ? Qe(a, i, n) : typeof a == "boolean" ? n[i] = +!!a : n[i] = a;
|
|
939
974
|
}
|
|
940
975
|
return n;
|
|
941
976
|
}
|
|
942
|
-
function
|
|
977
|
+
function $e(e, t) {
|
|
943
978
|
let n = {};
|
|
944
979
|
for (let [r, i] of Object.entries(e)) {
|
|
945
980
|
let e = t.find((e) => r.startsWith(`${e}_`));
|
|
@@ -956,13 +991,13 @@ function Ye(e, t) {
|
|
|
956
991
|
}
|
|
957
992
|
//#endregion
|
|
958
993
|
//#region src/helpers/filter.ts
|
|
959
|
-
function
|
|
994
|
+
function et(e) {
|
|
960
995
|
return typeof e == "object" && !!e && "coalesce" in e && "defaultValue" in e;
|
|
961
996
|
}
|
|
962
|
-
function
|
|
997
|
+
function tt(e) {
|
|
963
998
|
return y`coalesce(${e.coalesce}, ${e.defaultValue})`;
|
|
964
999
|
}
|
|
965
|
-
function
|
|
1000
|
+
function nt(n, r, i, l = []) {
|
|
966
1001
|
let ee = u(n, te) ? o(n) : n, b = new Set(l), ne = (e) => {
|
|
967
1002
|
let t = Number(e);
|
|
968
1003
|
return Number.isFinite(t) ? t : e;
|
|
@@ -974,7 +1009,7 @@ function Qe(n, r, i, l = []) {
|
|
|
974
1009
|
let [, t, r] = n;
|
|
975
1010
|
if (!t || !r) return null;
|
|
976
1011
|
let i = t.trim(), o = r.replace(/^"(.*)"$/, "$1").trim(), s = ee[i];
|
|
977
|
-
return
|
|
1012
|
+
return et(s) ? a(tt(s), ne(o)) : u(s, e) ? b.has(i) ? p(s, `%${o}%`) : a(s, o) : null;
|
|
978
1013
|
}
|
|
979
1014
|
return null;
|
|
980
1015
|
}).filter((e) => e !== null);
|
|
@@ -1003,12 +1038,12 @@ function Qe(n, r, i, l = []) {
|
|
|
1003
1038
|
};
|
|
1004
1039
|
}), E = [];
|
|
1005
1040
|
for (let { key: t, value: n, isNegation: r, isExistsQuery: o, operator: l } of T) if (t) {
|
|
1006
|
-
let i = ee[t], v =
|
|
1041
|
+
let i = ee[t], v = et(i), te = v ? i.coalesce : u(i, e) ? i : void 0, x = v ? ne(n) : n;
|
|
1007
1042
|
if (!te) {
|
|
1008
1043
|
o ? E.push(r ? y`${y.identifier(t)} IS NULL` : y`${y.identifier(t)} IS NOT NULL`) : E.push(y`${y.identifier(t)} ${y.raw(r ? "!=" : l ?? "=")} ${n}`);
|
|
1009
1044
|
continue;
|
|
1010
1045
|
}
|
|
1011
|
-
let S = v ?
|
|
1046
|
+
let S = v ? tt(i) : y`${te}`;
|
|
1012
1047
|
if (o) E.push(r ? f(te) : d(te));
|
|
1013
1048
|
else if (b.has(t) && l === "=") E.push(r ? _(te, `%${n}%`) : p(te, `%${n}%`));
|
|
1014
1049
|
else if (r) switch (l) {
|
|
@@ -1052,11 +1087,11 @@ function Qe(n, r, i, l = []) {
|
|
|
1052
1087
|
}
|
|
1053
1088
|
//#endregion
|
|
1054
1089
|
//#region src/adapters/actions.ts
|
|
1055
|
-
function
|
|
1090
|
+
function rt(e) {
|
|
1056
1091
|
let t = Q(e);
|
|
1057
1092
|
return Array.isArray(t) ? t : [];
|
|
1058
1093
|
}
|
|
1059
|
-
function
|
|
1094
|
+
function it(e) {
|
|
1060
1095
|
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;
|
|
1061
1096
|
return {
|
|
1062
1097
|
...f,
|
|
@@ -1073,11 +1108,11 @@ function et(e) {
|
|
|
1073
1108
|
updated_at: new Date(Number(n)).toISOString()
|
|
1074
1109
|
};
|
|
1075
1110
|
}
|
|
1076
|
-
function
|
|
1111
|
+
function at(e) {
|
|
1077
1112
|
return {
|
|
1078
1113
|
async create(t, n) {
|
|
1079
1114
|
let r = Date.now(), i = `act_${b()}`;
|
|
1080
|
-
return await e.insert(
|
|
1115
|
+
return await e.insert(Ee).values({
|
|
1081
1116
|
id: i,
|
|
1082
1117
|
tenant_id: t,
|
|
1083
1118
|
name: n.name,
|
|
@@ -1108,28 +1143,28 @@ function tt(e) {
|
|
|
1108
1143
|
};
|
|
1109
1144
|
},
|
|
1110
1145
|
async get(n, r) {
|
|
1111
|
-
let i = await e.select().from(
|
|
1112
|
-
return i ?
|
|
1146
|
+
let i = await e.select().from(Ee).where(t(a(Ee.tenant_id, n), a(Ee.id, r))).get();
|
|
1147
|
+
return i ? it(i) : null;
|
|
1113
1148
|
},
|
|
1114
1149
|
async list(o, s = {}) {
|
|
1115
|
-
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s, p = [a(
|
|
1150
|
+
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s, p = [a(Ee.tenant_id, o)];
|
|
1116
1151
|
if (f) {
|
|
1117
|
-
let e =
|
|
1152
|
+
let e = nt(Ee, f, ["name"]);
|
|
1118
1153
|
e && p.push(e);
|
|
1119
1154
|
}
|
|
1120
|
-
let m = t(...p), h = e.select().from(
|
|
1155
|
+
let m = t(...p), h = e.select().from(Ee).where(m).$dynamic();
|
|
1121
1156
|
if (d?.sort_by) {
|
|
1122
|
-
let e =
|
|
1157
|
+
let e = Ee[d.sort_by];
|
|
1123
1158
|
e && (h = h.orderBy(d.sort_order === "desc" ? i(e) : n(e)));
|
|
1124
1159
|
}
|
|
1125
|
-
let g = (await h.offset(c * l).limit(l)).map(
|
|
1160
|
+
let g = (await h.offset(c * l).limit(l)).map(it);
|
|
1126
1161
|
if (!u) return {
|
|
1127
1162
|
actions: g,
|
|
1128
1163
|
start: 0,
|
|
1129
1164
|
limit: 0,
|
|
1130
1165
|
length: 0
|
|
1131
1166
|
};
|
|
1132
|
-
let [_] = await e.select({ count: r() }).from(
|
|
1167
|
+
let [_] = await e.select({ count: r() }).from(Ee).where(m);
|
|
1133
1168
|
return {
|
|
1134
1169
|
actions: g,
|
|
1135
1170
|
start: c * l,
|
|
@@ -1140,7 +1175,7 @@ function tt(e) {
|
|
|
1140
1175
|
async update(n, r, i) {
|
|
1141
1176
|
let o = { updated_at_ts: Date.now() };
|
|
1142
1177
|
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) {
|
|
1143
|
-
let s = await e.select({ secrets:
|
|
1178
|
+
let s = await e.select({ secrets: Ee.secrets }).from(Ee).where(t(a(Ee.tenant_id, n), a(Ee.id, r))).get(), c = new Map(rt(s?.secrets).map((e) => [e.name, e])), l = i.secrets.map((e) => e.value === void 0 ? {
|
|
1144
1179
|
name: e.name,
|
|
1145
1180
|
value: c.get(e.name)?.value
|
|
1146
1181
|
} : e);
|
|
@@ -1150,20 +1185,21 @@ function tt(e) {
|
|
|
1150
1185
|
let e = new Date(i.deployed_at).getTime();
|
|
1151
1186
|
Number.isFinite(e) && (o.deployed_at_ts = e);
|
|
1152
1187
|
}
|
|
1153
|
-
return i.is_system !== void 0 && (o.is_system = +!!i.is_system), i.inherit !== void 0 && (o.inherit = +!!i.inherit), (await e.update(
|
|
1188
|
+
return i.is_system !== void 0 && (o.is_system = +!!i.is_system), i.inherit !== void 0 && (o.inherit = +!!i.inherit), (await e.update(Ee).set(o).where(t(a(Ee.tenant_id, n), a(Ee.id, r))).returning()).length > 0;
|
|
1154
1189
|
},
|
|
1155
1190
|
async remove(n, r) {
|
|
1156
|
-
return (await e.delete(
|
|
1191
|
+
return (await e.delete(Ee).where(t(a(Ee.tenant_id, n), a(Ee.id, r))).returning()).length > 0;
|
|
1157
1192
|
}
|
|
1158
1193
|
};
|
|
1159
1194
|
}
|
|
1160
1195
|
//#endregion
|
|
1161
1196
|
//#region src/adapters/actionExecutions.ts
|
|
1162
|
-
|
|
1197
|
+
var ot = 500;
|
|
1198
|
+
function st(e) {
|
|
1163
1199
|
return {
|
|
1164
1200
|
async create(t, n) {
|
|
1165
1201
|
let r = Date.now();
|
|
1166
|
-
return await e.insert(
|
|
1202
|
+
return await e.insert(De).values({
|
|
1167
1203
|
id: n.id,
|
|
1168
1204
|
tenant_id: t,
|
|
1169
1205
|
trigger_id: n.trigger_id,
|
|
@@ -1184,7 +1220,7 @@ function nt(e) {
|
|
|
1184
1220
|
};
|
|
1185
1221
|
},
|
|
1186
1222
|
async get(n, r) {
|
|
1187
|
-
let i = await e.select().from(
|
|
1223
|
+
let i = await e.select().from(De).where(t(a(De.tenant_id, n), a(De.id, r))).get();
|
|
1188
1224
|
return i ? {
|
|
1189
1225
|
id: i.id,
|
|
1190
1226
|
tenant_id: i.tenant_id,
|
|
@@ -1195,17 +1231,27 @@ function nt(e) {
|
|
|
1195
1231
|
created_at: new Date(Number(i.created_at_ts)).toISOString(),
|
|
1196
1232
|
updated_at: new Date(Number(i.updated_at_ts)).toISOString()
|
|
1197
1233
|
} : null;
|
|
1234
|
+
},
|
|
1235
|
+
async cleanup(t) {
|
|
1236
|
+
let n = Date.parse(t);
|
|
1237
|
+
if (Number.isNaN(n)) throw Error(`Invalid olderThan date: ${t}`);
|
|
1238
|
+
let r = 0;
|
|
1239
|
+
for (;;) {
|
|
1240
|
+
let t = await e.delete(De).where(y`rowid IN (SELECT rowid FROM ${De} WHERE ${De.created_at_ts} < ${n} LIMIT ${ot})`).returning({ id: De.id });
|
|
1241
|
+
if (r += t.length, t.length < ot) break;
|
|
1242
|
+
}
|
|
1243
|
+
return r;
|
|
1198
1244
|
}
|
|
1199
1245
|
};
|
|
1200
1246
|
}
|
|
1201
1247
|
//#endregion
|
|
1202
1248
|
//#region src/adapters/atomic.ts
|
|
1203
|
-
function
|
|
1249
|
+
function ct(e) {
|
|
1204
1250
|
let t = e;
|
|
1205
1251
|
return typeof t == "object" && !!t && "batch" in t && typeof t.batch == "function";
|
|
1206
1252
|
}
|
|
1207
|
-
async function
|
|
1208
|
-
if (
|
|
1253
|
+
async function lt(e, t) {
|
|
1254
|
+
if (ct(e)) return e.batch(t);
|
|
1209
1255
|
await e.run(y`BEGIN`);
|
|
1210
1256
|
try {
|
|
1211
1257
|
let n = [];
|
|
@@ -1222,7 +1268,7 @@ async function it(e, t) {
|
|
|
1222
1268
|
}
|
|
1223
1269
|
//#endregion
|
|
1224
1270
|
//#region src/adapters/actionVersions.ts
|
|
1225
|
-
function
|
|
1271
|
+
function ut(e) {
|
|
1226
1272
|
let { created_at_ts: t, updated_at_ts: n, secrets: r, dependencies: i, supported_triggers: a, deployed: o, runtime: s, ...c } = e;
|
|
1227
1273
|
return {
|
|
1228
1274
|
...c,
|
|
@@ -1235,7 +1281,7 @@ function at(e) {
|
|
|
1235
1281
|
updated_at: new Date(Number(n)).toISOString()
|
|
1236
1282
|
};
|
|
1237
1283
|
}
|
|
1238
|
-
function
|
|
1284
|
+
function dt(e) {
|
|
1239
1285
|
return {
|
|
1240
1286
|
async create(n, r) {
|
|
1241
1287
|
let o = Date.now(), s = `ver_${b()}`, c = r.deployed !== !1, l = ((await e.select({ number: A.number }).from(A).where(t(a(A.tenant_id, n), a(A.action_id, r.action_id))).orderBy(i(A.number)).limit(1).get())?.number ?? 0) + 1, u = e.insert(A).values({
|
|
@@ -1252,7 +1298,7 @@ function ot(e) {
|
|
|
1252
1298
|
created_at_ts: o,
|
|
1253
1299
|
updated_at_ts: o
|
|
1254
1300
|
});
|
|
1255
|
-
return await
|
|
1301
|
+
return await lt(e, c ? [e.update(A).set({
|
|
1256
1302
|
deployed: 0,
|
|
1257
1303
|
updated_at_ts: o
|
|
1258
1304
|
}).where(t(a(A.tenant_id, n), a(A.action_id, r.action_id), a(A.deployed, 1))), u] : [u]), {
|
|
@@ -1272,10 +1318,10 @@ function ot(e) {
|
|
|
1272
1318
|
},
|
|
1273
1319
|
async get(n, r, i) {
|
|
1274
1320
|
let o = await e.select().from(A).where(t(a(A.tenant_id, n), a(A.action_id, r), a(A.id, i))).get();
|
|
1275
|
-
return o ?
|
|
1321
|
+
return o ? ut(o) : null;
|
|
1276
1322
|
},
|
|
1277
1323
|
async list(n, o, s = {}) {
|
|
1278
|
-
let { page: c = 0, per_page: l = 50, include_totals: u = !1 } = s, d = t(a(A.tenant_id, n), a(A.action_id, o)), f = (await e.select().from(A).where(d).orderBy(i(A.number)).offset(c * l).limit(l)).map(
|
|
1324
|
+
let { page: c = 0, per_page: l = 50, include_totals: u = !1 } = s, d = t(a(A.tenant_id, n), a(A.action_id, o)), f = (await e.select().from(A).where(d).orderBy(i(A.number)).offset(c * l).limit(l)).map(ut);
|
|
1279
1325
|
if (!u) return {
|
|
1280
1326
|
versions: f,
|
|
1281
1327
|
start: 0,
|
|
@@ -1297,13 +1343,13 @@ function ot(e) {
|
|
|
1297
1343
|
}
|
|
1298
1344
|
//#endregion
|
|
1299
1345
|
//#region src/adapters/branding.ts
|
|
1300
|
-
function
|
|
1346
|
+
function ft(e) {
|
|
1301
1347
|
return e === "dark" || e === "light" || e === "auto";
|
|
1302
1348
|
}
|
|
1303
|
-
function
|
|
1349
|
+
function pt(e) {
|
|
1304
1350
|
return {
|
|
1305
1351
|
async get(t) {
|
|
1306
|
-
let n = await e.select().from(
|
|
1352
|
+
let n = await e.select().from(Le).where(a(Le.tenant_id, t)).get();
|
|
1307
1353
|
if (!n) return null;
|
|
1308
1354
|
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;
|
|
1309
1355
|
return O({
|
|
@@ -1318,7 +1364,7 @@ function ct(e) {
|
|
|
1318
1364
|
}
|
|
1319
1365
|
},
|
|
1320
1366
|
font: u ? { url: u } : void 0,
|
|
1321
|
-
dark_mode:
|
|
1367
|
+
dark_mode: ft(d) ? d : void 0
|
|
1322
1368
|
});
|
|
1323
1369
|
},
|
|
1324
1370
|
async set(t, n) {
|
|
@@ -1332,11 +1378,11 @@ function ct(e) {
|
|
|
1332
1378
|
font_url: i?.url,
|
|
1333
1379
|
dark_mode: a
|
|
1334
1380
|
};
|
|
1335
|
-
await e.insert(
|
|
1381
|
+
await e.insert(Le).values({
|
|
1336
1382
|
tenant_id: t,
|
|
1337
1383
|
...l
|
|
1338
1384
|
}).onConflictDoUpdate({
|
|
1339
|
-
target:
|
|
1385
|
+
target: Le.tenant_id,
|
|
1340
1386
|
set: l
|
|
1341
1387
|
});
|
|
1342
1388
|
}
|
|
@@ -1344,26 +1390,26 @@ function ct(e) {
|
|
|
1344
1390
|
}
|
|
1345
1391
|
//#endregion
|
|
1346
1392
|
//#region src/helpers/paginate.ts
|
|
1347
|
-
function
|
|
1393
|
+
function mt(e) {
|
|
1348
1394
|
return e?.from !== void 0 || e?.take !== void 0;
|
|
1349
1395
|
}
|
|
1350
|
-
function
|
|
1396
|
+
function ht(e) {
|
|
1351
1397
|
let t = e?.take, n = typeof t == "number" && Number.isFinite(t) ? Math.floor(t) : NaN;
|
|
1352
1398
|
return n >= 1 ? n : 50;
|
|
1353
1399
|
}
|
|
1354
|
-
function
|
|
1400
|
+
function gt(e) {
|
|
1355
1401
|
let t = e.sortOrder === "asc" ? n : i;
|
|
1356
1402
|
return [t(e.sortColumn), t(e.idColumn)];
|
|
1357
1403
|
}
|
|
1358
|
-
function
|
|
1404
|
+
function _t(e, t) {
|
|
1359
1405
|
let n = e?.from ? ue(e.from) : null;
|
|
1360
1406
|
if (!n) return;
|
|
1361
|
-
if (n.k !== t.sortKey) throw new
|
|
1407
|
+
if (n.k !== t.sortKey) throw new Ce(400, { message: "The `from` cursor was issued under a different sort and cannot be used with this request" });
|
|
1362
1408
|
if (n.s === void 0 || n.s === null) return t.sortOrder === "asc" ? s(t.idColumn, n.i) : m(t.idColumn, n.i);
|
|
1363
1409
|
let r = t.sortOrder === "asc" ? y.raw(">") : y.raw("<");
|
|
1364
1410
|
return y`(${t.sortColumn}, ${t.idColumn}) ${r} (${n.s}, ${n.i})`;
|
|
1365
1411
|
}
|
|
1366
|
-
function
|
|
1412
|
+
function vt(e, t, n, r = "id", i) {
|
|
1367
1413
|
let a = e.length > t, o = a ? e.slice(0, t) : e, s, c = o[o.length - 1];
|
|
1368
1414
|
if (a && c) {
|
|
1369
1415
|
let e = c[n];
|
|
@@ -1380,7 +1426,7 @@ function pt(e, t, n, r = "id", i) {
|
|
|
1380
1426
|
}
|
|
1381
1427
|
//#endregion
|
|
1382
1428
|
//#region src/adapters/clients.ts
|
|
1383
|
-
var
|
|
1429
|
+
var yt = [
|
|
1384
1430
|
"global",
|
|
1385
1431
|
"is_first_party",
|
|
1386
1432
|
"oidc_conformant",
|
|
@@ -1392,7 +1438,7 @@ var mt = [
|
|
|
1392
1438
|
"require_pushed_authorization_requests",
|
|
1393
1439
|
"require_proof_of_possession",
|
|
1394
1440
|
"hide_sign_up_disabled_error"
|
|
1395
|
-
],
|
|
1441
|
+
], bt = [
|
|
1396
1442
|
"callbacks",
|
|
1397
1443
|
"allowed_origins",
|
|
1398
1444
|
"web_origins",
|
|
@@ -1401,7 +1447,7 @@ var mt = [
|
|
|
1401
1447
|
"allowed_logout_urls",
|
|
1402
1448
|
"grant_types",
|
|
1403
1449
|
"signing_keys"
|
|
1404
|
-
],
|
|
1450
|
+
], xt = [
|
|
1405
1451
|
"session_transfer",
|
|
1406
1452
|
"oidc_logout",
|
|
1407
1453
|
"jwt_configuration",
|
|
@@ -1417,21 +1463,21 @@ var mt = [
|
|
|
1417
1463
|
"token_quota",
|
|
1418
1464
|
"registration_metadata"
|
|
1419
1465
|
];
|
|
1420
|
-
function
|
|
1466
|
+
function St(e) {
|
|
1421
1467
|
let { tenant_id: t, connections: n, ...r } = e, i = { ...r };
|
|
1422
|
-
for (let e of
|
|
1423
|
-
for (let e of
|
|
1424
|
-
for (let e of
|
|
1468
|
+
for (let e of yt) i[e] = !!r[e];
|
|
1469
|
+
for (let e of bt) i[e] = Q(r[e], []);
|
|
1470
|
+
for (let e of xt) i[e] = Q(r[e], {});
|
|
1425
1471
|
return i.connections = Q(n, []), O(i);
|
|
1426
1472
|
}
|
|
1427
|
-
function
|
|
1473
|
+
function Ct(e) {
|
|
1428
1474
|
let t = { ...e };
|
|
1429
|
-
re(e,
|
|
1430
|
-
for (let n of
|
|
1431
|
-
for (let n of
|
|
1475
|
+
re(e, yt, t);
|
|
1476
|
+
for (let n of bt) e[n] !== void 0 && (t[n] = JSON.stringify(e[n] || []));
|
|
1477
|
+
for (let n of xt) e[n] !== void 0 && (t[n] = JSON.stringify(e[n] || {}));
|
|
1432
1478
|
return e.connections !== void 0 && (t.connections = JSON.stringify(e.connections || [])), se(t);
|
|
1433
1479
|
}
|
|
1434
|
-
function
|
|
1480
|
+
function wt(e) {
|
|
1435
1481
|
return {
|
|
1436
1482
|
async create(t, n) {
|
|
1437
1483
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
@@ -1455,51 +1501,51 @@ function yt(e) {
|
|
|
1455
1501
|
created_at: r,
|
|
1456
1502
|
updated_at: r
|
|
1457
1503
|
};
|
|
1458
|
-
for (let e of
|
|
1504
|
+
for (let e of yt) i[e] = n[e] ?? !1;
|
|
1459
1505
|
i.oidc_conformant = n.oidc_conformant ?? !0, i.auth0_conformant = n.auth0_conformant ?? !0, i.sso_disabled = n.sso_disabled ?? !1;
|
|
1460
|
-
for (let e of
|
|
1461
|
-
for (let e of
|
|
1506
|
+
for (let e of bt) i[e] = n[e] || [];
|
|
1507
|
+
for (let e of xt) i[e] = n[e] || {};
|
|
1462
1508
|
i.connections = n.connections || [];
|
|
1463
|
-
let a =
|
|
1509
|
+
let a = Ct(i);
|
|
1464
1510
|
try {
|
|
1465
1511
|
await e.insert(L).values({
|
|
1466
1512
|
...a,
|
|
1467
1513
|
tenant_id: t
|
|
1468
1514
|
});
|
|
1469
1515
|
} catch (e) {
|
|
1470
|
-
throw e?.message?.includes("UNIQUE constraint failed") || e?.message?.includes("duplicate key") ? new
|
|
1516
|
+
throw e?.message?.includes("UNIQUE constraint failed") || e?.message?.includes("duplicate key") ? new Ce(409, { message: "Client already exists" }) : e;
|
|
1471
1517
|
}
|
|
1472
|
-
return
|
|
1518
|
+
return St({
|
|
1473
1519
|
...a,
|
|
1474
1520
|
tenant_id: t
|
|
1475
1521
|
});
|
|
1476
1522
|
},
|
|
1477
1523
|
async get(n, r) {
|
|
1478
1524
|
let i = await e.select().from(L).where(t(a(L.tenant_id, n), a(L.client_id, r))).get();
|
|
1479
|
-
return i ?
|
|
1525
|
+
return i ? St(i) : null;
|
|
1480
1526
|
},
|
|
1481
1527
|
async getByClientId(t) {
|
|
1482
1528
|
let n = await e.select().from(L).where(a(L.client_id, t)).get();
|
|
1483
1529
|
return n ? {
|
|
1484
|
-
...
|
|
1530
|
+
...St(n),
|
|
1485
1531
|
tenant_id: n.tenant_id
|
|
1486
1532
|
} : null;
|
|
1487
1533
|
},
|
|
1488
1534
|
async update(n, r, i) {
|
|
1489
|
-
let o =
|
|
1535
|
+
let o = Ct({
|
|
1490
1536
|
...i,
|
|
1491
1537
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1492
1538
|
});
|
|
1493
1539
|
return delete o.client_id, delete o.tenant_id, await e.update(L).set(o).where(t(a(L.tenant_id, n), a(L.client_id, r))), !0;
|
|
1494
1540
|
},
|
|
1495
1541
|
async list(o, s) {
|
|
1496
|
-
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ?
|
|
1497
|
-
if (
|
|
1542
|
+
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ? nt(L, f, ["name", "client_id"]) : void 0, m = p ? t(a(L.tenant_id, o), p) : a(L.tenant_id, o);
|
|
1543
|
+
if (mt(s)) {
|
|
1498
1544
|
let n = {
|
|
1499
1545
|
sortColumn: L.created_at,
|
|
1500
1546
|
idColumn: L.client_id,
|
|
1501
1547
|
sortOrder: "desc"
|
|
1502
|
-
}, r =
|
|
1548
|
+
}, r = _t(s, n), i = ht(s), { rows: a, next: o } = vt(await e.select().from(L).where(r ? t(m, r) : m).orderBy(...gt(n)).limit(i + 1), i, "created_at", "client_id"), c = a.map(St);
|
|
1503
1549
|
return {
|
|
1504
1550
|
clients: c,
|
|
1505
1551
|
totals: {
|
|
@@ -1515,7 +1561,7 @@ function yt(e) {
|
|
|
1515
1561
|
let e = L[d.sort_by];
|
|
1516
1562
|
e && (h = h.orderBy(d.sort_order === "desc" ? i(e) : n(e)));
|
|
1517
1563
|
}
|
|
1518
|
-
let g = (await h.offset(c * l).limit(l)).map(
|
|
1564
|
+
let g = (await h.offset(c * l).limit(l)).map(St);
|
|
1519
1565
|
if (!u) return { clients: g };
|
|
1520
1566
|
let [_] = await e.select({ count: r() }).from(L).where(m);
|
|
1521
1567
|
return {
|
|
@@ -1535,7 +1581,7 @@ function yt(e) {
|
|
|
1535
1581
|
}
|
|
1536
1582
|
//#endregion
|
|
1537
1583
|
//#region src/adapters/clientConnections.ts
|
|
1538
|
-
function
|
|
1584
|
+
function Tt(e) {
|
|
1539
1585
|
let { tenant_id: t, is_system: n, options: r, metadata: i, ...a } = e;
|
|
1540
1586
|
return O({
|
|
1541
1587
|
...a,
|
|
@@ -1544,14 +1590,14 @@ function bt(e) {
|
|
|
1544
1590
|
is_system: n ? !0 : void 0
|
|
1545
1591
|
});
|
|
1546
1592
|
}
|
|
1547
|
-
function
|
|
1593
|
+
function Et(e) {
|
|
1548
1594
|
return {
|
|
1549
1595
|
async listByClient(n, r) {
|
|
1550
1596
|
let i = await e.select({ connections: L.connections }).from(L).where(t(a(L.tenant_id, n), a(L.client_id, r))).get();
|
|
1551
1597
|
if (!i) return [];
|
|
1552
1598
|
let o = Q(i.connections, []) || [];
|
|
1553
1599
|
if (o.length === 0) return [];
|
|
1554
|
-
let s = (await e.select().from(V).where(t(a(V.tenant_id, n), l(V.id, o))).all()).map(
|
|
1600
|
+
let s = (await e.select().from(V).where(t(a(V.tenant_id, n), l(V.id, o))).all()).map(Tt);
|
|
1555
1601
|
return o.map((e) => s.find((t) => t.id === e)).filter(Boolean);
|
|
1556
1602
|
},
|
|
1557
1603
|
async updateByClient(n, r, i) {
|
|
@@ -1588,7 +1634,7 @@ function xt(e) {
|
|
|
1588
1634
|
}
|
|
1589
1635
|
//#endregion
|
|
1590
1636
|
//#region src/adapters/clientGrants.ts
|
|
1591
|
-
function
|
|
1637
|
+
function Dt(e) {
|
|
1592
1638
|
let { tenant_id: t, scope: n, authorization_details_types: r, allow_any_organization: i, is_system: a, ...o } = e;
|
|
1593
1639
|
return O({
|
|
1594
1640
|
...o,
|
|
@@ -1598,7 +1644,7 @@ function St(e) {
|
|
|
1598
1644
|
is_system: !!a
|
|
1599
1645
|
});
|
|
1600
1646
|
}
|
|
1601
|
-
function
|
|
1647
|
+
function Ot(e) {
|
|
1602
1648
|
return {
|
|
1603
1649
|
async create(t, n) {
|
|
1604
1650
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
@@ -1615,14 +1661,14 @@ function Ct(e) {
|
|
|
1615
1661
|
created_at: r,
|
|
1616
1662
|
updated_at: r
|
|
1617
1663
|
};
|
|
1618
|
-
return await e.insert(z).values(i),
|
|
1664
|
+
return await e.insert(z).values(i), Dt({
|
|
1619
1665
|
...i,
|
|
1620
1666
|
tenant_id: t
|
|
1621
1667
|
});
|
|
1622
1668
|
},
|
|
1623
1669
|
async get(n, r) {
|
|
1624
1670
|
let i = await e.select().from(z).where(t(a(z.tenant_id, n), a(z.id, r))).get();
|
|
1625
|
-
return i ?
|
|
1671
|
+
return i ? Dt(i) : null;
|
|
1626
1672
|
},
|
|
1627
1673
|
async update(n, r, i) {
|
|
1628
1674
|
let { scope: o, authorization_details_types: s, allow_any_organization: c, is_system: l, ...u } = i, d = {
|
|
@@ -1632,13 +1678,13 @@ function Ct(e) {
|
|
|
1632
1678
|
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(z).set(d).where(t(a(z.tenant_id, n), a(z.id, r))).returning()).length > 0;
|
|
1633
1679
|
},
|
|
1634
1680
|
async list(o, s) {
|
|
1635
|
-
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ?
|
|
1636
|
-
if (
|
|
1681
|
+
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ? nt(z, f, ["client_id", "audience"]) : void 0, m = p ? t(a(z.tenant_id, o), p) : a(z.tenant_id, o);
|
|
1682
|
+
if (mt(s)) {
|
|
1637
1683
|
let n = {
|
|
1638
1684
|
sortColumn: z.created_at,
|
|
1639
1685
|
idColumn: z.id,
|
|
1640
1686
|
sortOrder: "desc"
|
|
1641
|
-
}, r =
|
|
1687
|
+
}, r = _t(s, n), i = ht(s), { rows: a, next: o } = vt(await e.select().from(z).where(r ? t(m, r) : m).orderBy(...gt(n)).limit(i + 1), i, "created_at"), c = a.map(Dt);
|
|
1642
1688
|
return {
|
|
1643
1689
|
client_grants: c,
|
|
1644
1690
|
start: 0,
|
|
@@ -1652,7 +1698,7 @@ function Ct(e) {
|
|
|
1652
1698
|
let e = z[d.sort_by];
|
|
1653
1699
|
e && (h = h.orderBy(d.sort_order === "desc" ? i(e) : n(e)));
|
|
1654
1700
|
} else h = h.orderBy(n(z.created_at));
|
|
1655
|
-
let g = (await h.offset(c * l).limit(l)).map(
|
|
1701
|
+
let g = (await h.offset(c * l).limit(l)).map(Dt);
|
|
1656
1702
|
if (!u) return { client_grants: g };
|
|
1657
1703
|
let [_] = await e.select({ count: r() }).from(z).where(m);
|
|
1658
1704
|
return {
|
|
@@ -1669,20 +1715,20 @@ function Ct(e) {
|
|
|
1669
1715
|
}
|
|
1670
1716
|
//#endregion
|
|
1671
1717
|
//#region src/adapters/clientRegistrationTokens.ts
|
|
1672
|
-
function
|
|
1718
|
+
function kt(e) {
|
|
1673
1719
|
if (!e) return;
|
|
1674
1720
|
let t = JSON.parse(e);
|
|
1675
1721
|
return pe(t) ? t : void 0;
|
|
1676
1722
|
}
|
|
1677
|
-
function
|
|
1723
|
+
function At(e) {
|
|
1678
1724
|
return e == null ? void 0 : new Date(e).toISOString();
|
|
1679
1725
|
}
|
|
1680
|
-
function
|
|
1726
|
+
function jt(e) {
|
|
1681
1727
|
if (!e) return null;
|
|
1682
1728
|
let t = new Date(e);
|
|
1683
1729
|
return isNaN(t.getTime()) ? null : t.getTime();
|
|
1684
1730
|
}
|
|
1685
|
-
function
|
|
1731
|
+
function Mt(e) {
|
|
1686
1732
|
let t = le.parse(e.type);
|
|
1687
1733
|
return {
|
|
1688
1734
|
id: e.id,
|
|
@@ -1690,15 +1736,15 @@ function Dt(e) {
|
|
|
1690
1736
|
type: t,
|
|
1691
1737
|
client_id: e.client_id ?? void 0,
|
|
1692
1738
|
sub: e.sub ?? void 0,
|
|
1693
|
-
constraints:
|
|
1739
|
+
constraints: kt(e.constraints),
|
|
1694
1740
|
single_use: !!e.single_use,
|
|
1695
|
-
expires_at:
|
|
1696
|
-
used_at:
|
|
1697
|
-
revoked_at:
|
|
1741
|
+
expires_at: At(e.expires_at_ts),
|
|
1742
|
+
used_at: At(e.used_at_ts),
|
|
1743
|
+
revoked_at: At(e.revoked_at_ts),
|
|
1698
1744
|
created_at: new Date(e.created_at_ts).toISOString()
|
|
1699
1745
|
};
|
|
1700
1746
|
}
|
|
1701
|
-
function
|
|
1747
|
+
function Nt(e) {
|
|
1702
1748
|
return {
|
|
1703
1749
|
async create(t, n) {
|
|
1704
1750
|
let r = Date.now();
|
|
@@ -1711,7 +1757,7 @@ function Ot(e) {
|
|
|
1711
1757
|
sub: n.sub ?? null,
|
|
1712
1758
|
constraints: n.constraints ? JSON.stringify(n.constraints) : null,
|
|
1713
1759
|
single_use: +!!n.single_use,
|
|
1714
|
-
expires_at_ts:
|
|
1760
|
+
expires_at_ts: jt(n.expires_at),
|
|
1715
1761
|
created_at_ts: r
|
|
1716
1762
|
}), {
|
|
1717
1763
|
id: n.id,
|
|
@@ -1727,23 +1773,23 @@ function Ot(e) {
|
|
|
1727
1773
|
},
|
|
1728
1774
|
async get(n, r) {
|
|
1729
1775
|
let i = await e.select().from(R).where(t(a(R.tenant_id, n), a(R.id, r))).get();
|
|
1730
|
-
return i ?
|
|
1776
|
+
return i ? Mt(i) : null;
|
|
1731
1777
|
},
|
|
1732
1778
|
async getByHash(n, r) {
|
|
1733
1779
|
let i = await e.select().from(R).where(t(a(R.tenant_id, n), a(R.token_hash, r))).get();
|
|
1734
|
-
return i ?
|
|
1780
|
+
return i ? Mt(i) : null;
|
|
1735
1781
|
},
|
|
1736
1782
|
async listByClient(n, r) {
|
|
1737
|
-
return (await e.select().from(R).where(t(a(R.tenant_id, n), a(R.client_id, r))).orderBy(i(R.created_at_ts))).map(
|
|
1783
|
+
return (await e.select().from(R).where(t(a(R.tenant_id, n), a(R.client_id, r))).orderBy(i(R.created_at_ts))).map(Mt);
|
|
1738
1784
|
},
|
|
1739
1785
|
async markUsed(n, r, i) {
|
|
1740
|
-
return (await e.update(R).set({ used_at_ts:
|
|
1786
|
+
return (await e.update(R).set({ used_at_ts: jt(i) }).where(t(a(R.tenant_id, n), a(R.id, r), f(R.used_at_ts))).returning()).length > 0;
|
|
1741
1787
|
},
|
|
1742
1788
|
async revoke(n, r, i) {
|
|
1743
|
-
return (await e.update(R).set({ revoked_at_ts:
|
|
1789
|
+
return (await e.update(R).set({ revoked_at_ts: jt(i) }).where(t(a(R.tenant_id, n), a(R.id, r), f(R.revoked_at_ts))).returning()).length > 0;
|
|
1744
1790
|
},
|
|
1745
1791
|
async revokeByClient(n, r, i) {
|
|
1746
|
-
return (await e.update(R).set({ revoked_at_ts:
|
|
1792
|
+
return (await e.update(R).set({ revoked_at_ts: jt(i) }).where(t(a(R.tenant_id, n), a(R.client_id, r), f(R.revoked_at_ts))).returning()).length;
|
|
1747
1793
|
},
|
|
1748
1794
|
async remove(n, r) {
|
|
1749
1795
|
return (await e.delete(R).where(t(a(R.tenant_id, n), a(R.id, r))).returning()).length > 0;
|
|
@@ -1752,12 +1798,12 @@ function Ot(e) {
|
|
|
1752
1798
|
}
|
|
1753
1799
|
//#endregion
|
|
1754
1800
|
//#region src/adapters/codes.ts
|
|
1755
|
-
var
|
|
1756
|
-
function
|
|
1801
|
+
var Pt = ["code_id", "login_id"], Ft = 500;
|
|
1802
|
+
function It(e) {
|
|
1757
1803
|
let { tenant_id: t, ...n } = e;
|
|
1758
1804
|
return O(n);
|
|
1759
1805
|
}
|
|
1760
|
-
function
|
|
1806
|
+
function Lt(e) {
|
|
1761
1807
|
return {
|
|
1762
1808
|
async create(t, n) {
|
|
1763
1809
|
let r = {
|
|
@@ -1766,18 +1812,18 @@ function Mt(e) {
|
|
|
1766
1812
|
created_at: n.created_at || (/* @__PURE__ */ new Date()).toISOString(),
|
|
1767
1813
|
expires_at: n.expires_at
|
|
1768
1814
|
};
|
|
1769
|
-
return await e.insert(I).values(r),
|
|
1815
|
+
return await e.insert(I).values(r), It(r);
|
|
1770
1816
|
},
|
|
1771
1817
|
async get(n, r, i) {
|
|
1772
1818
|
let o = n ? t(a(I.tenant_id, n), a(I.code_id, r), a(I.code_type, i)) : t(a(I.code_id, r), a(I.code_type, i)), s = await e.select().from(I).where(o).get();
|
|
1773
|
-
return s ?
|
|
1819
|
+
return s ? It(s) : null;
|
|
1774
1820
|
},
|
|
1775
1821
|
async list(o, s) {
|
|
1776
1822
|
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = [a(I.tenant_id, o)];
|
|
1777
1823
|
if (f) {
|
|
1778
|
-
let e = _e(f,
|
|
1824
|
+
let e = _e(f, Pt);
|
|
1779
1825
|
if (e) {
|
|
1780
|
-
let t =
|
|
1826
|
+
let t = nt(I, e, Pt);
|
|
1781
1827
|
t && p.push(t);
|
|
1782
1828
|
}
|
|
1783
1829
|
}
|
|
@@ -1786,7 +1832,7 @@ function Mt(e) {
|
|
|
1786
1832
|
let e = I[d.sort_by];
|
|
1787
1833
|
e && (h = h.orderBy(d.sort_order === "desc" ? i(e) : n(e)));
|
|
1788
1834
|
}
|
|
1789
|
-
let g = (await h.offset(c * l).limit(l)).map(
|
|
1835
|
+
let g = (await h.offset(c * l).limit(l)).map(It);
|
|
1790
1836
|
if (!u) return { codes: g };
|
|
1791
1837
|
let [_] = await e.select({ count: r() }).from(I).where(m);
|
|
1792
1838
|
return {
|
|
@@ -1808,8 +1854,8 @@ function Mt(e) {
|
|
|
1808
1854
|
async cleanup(t) {
|
|
1809
1855
|
let n = 0;
|
|
1810
1856
|
for (;;) {
|
|
1811
|
-
let r = await e.delete(I).where(y`rowid IN (SELECT rowid FROM ${I} WHERE ${I.expires_at} < ${t} LIMIT ${
|
|
1812
|
-
if (n += r.length, r.length <
|
|
1857
|
+
let r = await e.delete(I).where(y`rowid IN (SELECT rowid FROM ${I} WHERE ${I.expires_at} < ${t} LIMIT ${Ft})`).returning({ code_id: I.code_id });
|
|
1858
|
+
if (n += r.length, r.length < Ft) break;
|
|
1813
1859
|
}
|
|
1814
1860
|
return n;
|
|
1815
1861
|
}
|
|
@@ -1817,10 +1863,10 @@ function Mt(e) {
|
|
|
1817
1863
|
}
|
|
1818
1864
|
//#endregion
|
|
1819
1865
|
//#region src/adapters/connections.ts
|
|
1820
|
-
function
|
|
1866
|
+
function Rt() {
|
|
1821
1867
|
return `con_${ee("0123456789abcdefghijklmnopqrstuvwxyz", 17)()}`;
|
|
1822
1868
|
}
|
|
1823
|
-
function
|
|
1869
|
+
function zt(e) {
|
|
1824
1870
|
let { tenant_id: t, is_system: n, options: r, metadata: i, ...a } = e;
|
|
1825
1871
|
return O({
|
|
1826
1872
|
...a,
|
|
@@ -1829,11 +1875,11 @@ function Pt(e) {
|
|
|
1829
1875
|
is_system: n ? !0 : void 0
|
|
1830
1876
|
});
|
|
1831
1877
|
}
|
|
1832
|
-
function
|
|
1878
|
+
function Bt(e) {
|
|
1833
1879
|
return {
|
|
1834
1880
|
async create(t, n) {
|
|
1835
1881
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
1836
|
-
id: n.id ||
|
|
1882
|
+
id: n.id || Rt(),
|
|
1837
1883
|
...n,
|
|
1838
1884
|
tenant_id: t,
|
|
1839
1885
|
options: JSON.stringify(n.options || {}),
|
|
@@ -1845,13 +1891,13 @@ function Ft(e) {
|
|
|
1845
1891
|
try {
|
|
1846
1892
|
await e.insert(V).values(i);
|
|
1847
1893
|
} catch (e) {
|
|
1848
|
-
throw e?.message?.includes("UNIQUE constraint failed") || e?.message?.includes("duplicate key") ? new
|
|
1894
|
+
throw e?.message?.includes("UNIQUE constraint failed") || e?.message?.includes("duplicate key") ? new Ce(409, { message: "Connection already exists" }) : e;
|
|
1849
1895
|
}
|
|
1850
|
-
return
|
|
1896
|
+
return zt(i);
|
|
1851
1897
|
},
|
|
1852
1898
|
async get(n, r) {
|
|
1853
1899
|
let i = await e.select().from(V).where(t(a(V.tenant_id, n), a(V.id, r))).get();
|
|
1854
|
-
return i ?
|
|
1900
|
+
return i ? zt(i) : null;
|
|
1855
1901
|
},
|
|
1856
1902
|
async update(n, r, i) {
|
|
1857
1903
|
let o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
@@ -1860,7 +1906,7 @@ function Ft(e) {
|
|
|
1860
1906
|
async list(o, s) {
|
|
1861
1907
|
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = a(V.tenant_id, o);
|
|
1862
1908
|
if (f) {
|
|
1863
|
-
let e =
|
|
1909
|
+
let e = nt(V, f, ["name"]);
|
|
1864
1910
|
e && (p = t(p, e));
|
|
1865
1911
|
}
|
|
1866
1912
|
let m = e.select().from(V).where(p).$dynamic();
|
|
@@ -1868,7 +1914,7 @@ function Ft(e) {
|
|
|
1868
1914
|
let e = V[d.sort_by];
|
|
1869
1915
|
e && (m = m.orderBy(d.sort_order === "desc" ? i(e) : n(e)));
|
|
1870
1916
|
}
|
|
1871
|
-
let h = (await m.offset(c * l).limit(l)).map(
|
|
1917
|
+
let h = (await m.offset(c * l).limit(l)).map(zt);
|
|
1872
1918
|
if (!u) return { connections: h };
|
|
1873
1919
|
let [g] = await e.select({ count: r() }).from(V).where(p);
|
|
1874
1920
|
return {
|
|
@@ -1885,7 +1931,7 @@ function Ft(e) {
|
|
|
1885
1931
|
}
|
|
1886
1932
|
//#endregion
|
|
1887
1933
|
//#region src/adapters/customDomains.ts
|
|
1888
|
-
function
|
|
1934
|
+
function Vt(e) {
|
|
1889
1935
|
let { tenant_id: t, domain_metadata: n, ...r } = e;
|
|
1890
1936
|
return O({
|
|
1891
1937
|
...r,
|
|
@@ -1893,7 +1939,7 @@ function It(e) {
|
|
|
1893
1939
|
domain_metadata: Q(n)
|
|
1894
1940
|
});
|
|
1895
1941
|
}
|
|
1896
|
-
function
|
|
1942
|
+
function Ht(e) {
|
|
1897
1943
|
return {
|
|
1898
1944
|
async create(t, n) {
|
|
1899
1945
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
@@ -1911,40 +1957,40 @@ function Lt(e) {
|
|
|
1911
1957
|
created_at: r,
|
|
1912
1958
|
updated_at: r
|
|
1913
1959
|
};
|
|
1914
|
-
return await e.insert(
|
|
1960
|
+
return await e.insert(Me).values(i), Vt({
|
|
1915
1961
|
...i,
|
|
1916
1962
|
tenant_id: t
|
|
1917
1963
|
});
|
|
1918
1964
|
},
|
|
1919
1965
|
async get(n, r) {
|
|
1920
|
-
let i = await e.select().from(
|
|
1921
|
-
return i ?
|
|
1966
|
+
let i = await e.select().from(Me).where(t(a(Me.tenant_id, n), a(Me.custom_domain_id, r))).get();
|
|
1967
|
+
return i ? Vt(i) : null;
|
|
1922
1968
|
},
|
|
1923
1969
|
async getByDomain(t) {
|
|
1924
|
-
let n = await e.select().from(
|
|
1970
|
+
let n = await e.select().from(Me).where(a(Me.domain, t)).get();
|
|
1925
1971
|
return n ? {
|
|
1926
|
-
...
|
|
1972
|
+
...Vt(n),
|
|
1927
1973
|
tenant_id: n.tenant_id
|
|
1928
1974
|
} : null;
|
|
1929
1975
|
},
|
|
1930
1976
|
async list(t) {
|
|
1931
|
-
return (await e.select().from(
|
|
1977
|
+
return (await e.select().from(Me).where(a(Me.tenant_id, t)).all()).map(Vt);
|
|
1932
1978
|
},
|
|
1933
1979
|
async update(n, r, i) {
|
|
1934
1980
|
let o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
1935
|
-
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(
|
|
1981
|
+
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(Me).set(o).where(t(a(Me.tenant_id, n), a(Me.custom_domain_id, r))).returning()).length > 0;
|
|
1936
1982
|
},
|
|
1937
1983
|
async remove(n, r) {
|
|
1938
|
-
return (await e.delete(
|
|
1984
|
+
return (await e.delete(Me).where(t(a(Me.tenant_id, n), a(Me.custom_domain_id, r))).returning()).length > 0;
|
|
1939
1985
|
}
|
|
1940
1986
|
};
|
|
1941
1987
|
}
|
|
1942
1988
|
//#endregion
|
|
1943
1989
|
//#region src/adapters/customText.ts
|
|
1944
|
-
function
|
|
1990
|
+
function Ut(e) {
|
|
1945
1991
|
return {
|
|
1946
1992
|
async get(n, r, i) {
|
|
1947
|
-
let o = await e.select().from(
|
|
1993
|
+
let o = await e.select().from(Je).where(t(a(Je.tenant_id, n), a(Je.prompt, r), a(Je.language, i))).get();
|
|
1948
1994
|
if (!o) return null;
|
|
1949
1995
|
try {
|
|
1950
1996
|
return JSON.parse(o.custom_text);
|
|
@@ -1954,7 +2000,7 @@ function Rt(e) {
|
|
|
1954
2000
|
},
|
|
1955
2001
|
async set(t, n, r, i) {
|
|
1956
2002
|
let a = Date.now(), o = JSON.stringify(i);
|
|
1957
|
-
await e.insert(
|
|
2003
|
+
await e.insert(Je).values({
|
|
1958
2004
|
tenant_id: t,
|
|
1959
2005
|
prompt: n,
|
|
1960
2006
|
language: r,
|
|
@@ -1963,9 +2009,9 @@ function Rt(e) {
|
|
|
1963
2009
|
updated_at_ts: a
|
|
1964
2010
|
}).onConflictDoUpdate({
|
|
1965
2011
|
target: [
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
2012
|
+
Je.tenant_id,
|
|
2013
|
+
Je.prompt,
|
|
2014
|
+
Je.language
|
|
1969
2015
|
],
|
|
1970
2016
|
set: {
|
|
1971
2017
|
custom_text: o,
|
|
@@ -1974,23 +2020,23 @@ function Rt(e) {
|
|
|
1974
2020
|
});
|
|
1975
2021
|
},
|
|
1976
2022
|
async delete(n, r, i) {
|
|
1977
|
-
await e.delete(
|
|
2023
|
+
await e.delete(Je).where(t(a(Je.tenant_id, n), a(Je.prompt, r), a(Je.language, i)));
|
|
1978
2024
|
},
|
|
1979
2025
|
async list(t) {
|
|
1980
2026
|
return await e.select({
|
|
1981
|
-
prompt:
|
|
1982
|
-
language:
|
|
1983
|
-
}).from(
|
|
2027
|
+
prompt: Je.prompt,
|
|
2028
|
+
language: Je.language
|
|
2029
|
+
}).from(Je).where(a(Je.tenant_id, t)).all();
|
|
1984
2030
|
}
|
|
1985
2031
|
};
|
|
1986
2032
|
}
|
|
1987
2033
|
//#endregion
|
|
1988
2034
|
//#region src/adapters/emailProviders.ts
|
|
1989
|
-
function
|
|
2035
|
+
function Wt(e) {
|
|
1990
2036
|
return {
|
|
1991
2037
|
async create(t, n) {
|
|
1992
2038
|
let r = (/* @__PURE__ */ new Date()).toISOString();
|
|
1993
|
-
await e.insert(
|
|
2039
|
+
await e.insert(Ue).values({
|
|
1994
2040
|
tenant_id: t,
|
|
1995
2041
|
name: n.name,
|
|
1996
2042
|
enabled: n.enabled,
|
|
@@ -2002,7 +2048,7 @@ function zt(e) {
|
|
|
2002
2048
|
});
|
|
2003
2049
|
},
|
|
2004
2050
|
async get(t) {
|
|
2005
|
-
let n = await e.select().from(
|
|
2051
|
+
let n = await e.select().from(Ue).where(a(Ue.tenant_id, t)).get();
|
|
2006
2052
|
if (!n) return null;
|
|
2007
2053
|
let { tenant_id: r, ...i } = n;
|
|
2008
2054
|
return O({
|
|
@@ -2014,16 +2060,16 @@ function zt(e) {
|
|
|
2014
2060
|
},
|
|
2015
2061
|
async update(t, n) {
|
|
2016
2062
|
let r = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
2017
|
-
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(
|
|
2063
|
+
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(Ue).set(r).where(a(Ue.tenant_id, t));
|
|
2018
2064
|
},
|
|
2019
2065
|
async remove(t) {
|
|
2020
|
-
await e.delete(
|
|
2066
|
+
await e.delete(Ue).where(a(Ue.tenant_id, t));
|
|
2021
2067
|
}
|
|
2022
2068
|
};
|
|
2023
2069
|
}
|
|
2024
2070
|
//#endregion
|
|
2025
2071
|
//#region src/adapters/emailTemplates.ts
|
|
2026
|
-
function
|
|
2072
|
+
function Gt(e) {
|
|
2027
2073
|
return O({
|
|
2028
2074
|
template: e.template,
|
|
2029
2075
|
body: e.body,
|
|
@@ -2036,18 +2082,18 @@ function Bt(e) {
|
|
|
2036
2082
|
urlLifetimeInSeconds: e.url_lifetime_in_seconds ?? void 0
|
|
2037
2083
|
});
|
|
2038
2084
|
}
|
|
2039
|
-
function
|
|
2085
|
+
function Kt(e) {
|
|
2040
2086
|
return {
|
|
2041
2087
|
async get(n, r) {
|
|
2042
|
-
let i = await e.select().from(
|
|
2043
|
-
return i ?
|
|
2088
|
+
let i = await e.select().from(We).where(t(a(We.tenant_id, n), a(We.template, r))).get();
|
|
2089
|
+
return i ? Gt(i) : null;
|
|
2044
2090
|
},
|
|
2045
2091
|
async list(t) {
|
|
2046
|
-
return (await e.select().from(
|
|
2092
|
+
return (await e.select().from(We).where(a(We.tenant_id, t)).all()).map(Gt);
|
|
2047
2093
|
},
|
|
2048
2094
|
async create(t, n) {
|
|
2049
2095
|
let r = (/* @__PURE__ */ new Date()).toISOString();
|
|
2050
|
-
return await e.insert(
|
|
2096
|
+
return await e.insert(We).values({
|
|
2051
2097
|
tenant_id: t,
|
|
2052
2098
|
template: n.template,
|
|
2053
2099
|
body: n.body,
|
|
@@ -2065,23 +2111,23 @@ function Vt(e) {
|
|
|
2065
2111
|
async update(n, r, i) {
|
|
2066
2112
|
let o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
2067
2113
|
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);
|
|
2068
|
-
let s = await e.update(
|
|
2114
|
+
let s = await e.update(We).set(o).where(t(a(We.tenant_id, n), a(We.template, r))).run();
|
|
2069
2115
|
return Number(s.changes ?? 0) > 0;
|
|
2070
2116
|
},
|
|
2071
2117
|
async remove(n, r) {
|
|
2072
|
-
let i = await e.delete(
|
|
2118
|
+
let i = await e.delete(We).where(t(a(We.tenant_id, n), a(We.template, r))).run();
|
|
2073
2119
|
return Number(i.changes ?? 0) > 0;
|
|
2074
2120
|
}
|
|
2075
2121
|
};
|
|
2076
2122
|
}
|
|
2077
2123
|
//#endregion
|
|
2078
2124
|
//#region src/adapters/flows.ts
|
|
2079
|
-
var
|
|
2080
|
-
function
|
|
2125
|
+
var qt = ["id", "name"];
|
|
2126
|
+
function Jt(e) {
|
|
2081
2127
|
return {
|
|
2082
2128
|
async create(t, n) {
|
|
2083
2129
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = `af_${b()}`;
|
|
2084
|
-
return await e.insert(
|
|
2130
|
+
return await e.insert(Ve).values({
|
|
2085
2131
|
id: i,
|
|
2086
2132
|
tenant_id: t,
|
|
2087
2133
|
name: n.name,
|
|
@@ -2097,7 +2143,7 @@ function Ut(e) {
|
|
|
2097
2143
|
};
|
|
2098
2144
|
},
|
|
2099
2145
|
async get(n, r) {
|
|
2100
|
-
let i = await e.select().from(
|
|
2146
|
+
let i = await e.select().from(Ve).where(t(a(Ve.tenant_id, n), a(Ve.id, r))).get();
|
|
2101
2147
|
if (!i) return null;
|
|
2102
2148
|
let { tenant_id: o, actions: s, ...c } = i;
|
|
2103
2149
|
return O({
|
|
@@ -2107,20 +2153,20 @@ function Ut(e) {
|
|
|
2107
2153
|
},
|
|
2108
2154
|
async update(n, r, i) {
|
|
2109
2155
|
let o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
2110
|
-
return i.name !== void 0 && (o.name = i.name), i.actions !== void 0 && (o.actions = JSON.stringify(i.actions)), (await e.update(
|
|
2156
|
+
return i.name !== void 0 && (o.name = i.name), i.actions !== void 0 && (o.actions = JSON.stringify(i.actions)), (await e.update(Ve).set(o).where(t(a(Ve.tenant_id, n), a(Ve.id, r))).returning()).length === 0 ? null : this.get(n, r);
|
|
2111
2157
|
},
|
|
2112
2158
|
async list(o, s) {
|
|
2113
|
-
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = [a(
|
|
2159
|
+
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = [a(Ve.tenant_id, o)];
|
|
2114
2160
|
if (f) {
|
|
2115
|
-
let e = _e(f,
|
|
2161
|
+
let e = _e(f, qt);
|
|
2116
2162
|
if (e) {
|
|
2117
|
-
let t =
|
|
2163
|
+
let t = nt(Ve, e, []);
|
|
2118
2164
|
t && p.push(t);
|
|
2119
2165
|
}
|
|
2120
2166
|
}
|
|
2121
|
-
let m = t(...p), h = e.select().from(
|
|
2167
|
+
let m = t(...p), h = e.select().from(Ve).where(m).$dynamic();
|
|
2122
2168
|
if (d?.sort_by) {
|
|
2123
|
-
let e =
|
|
2169
|
+
let e = Ve[d.sort_by];
|
|
2124
2170
|
e && (h = h.orderBy(d.sort_order === "desc" ? i(e) : n(e)));
|
|
2125
2171
|
}
|
|
2126
2172
|
let g = (await h.offset(c * l).limit(l)).map((e) => {
|
|
@@ -2131,7 +2177,7 @@ function Ut(e) {
|
|
|
2131
2177
|
});
|
|
2132
2178
|
});
|
|
2133
2179
|
if (!u) return { flows: g };
|
|
2134
|
-
let [_] = await e.select({ count: r() }).from(
|
|
2180
|
+
let [_] = await e.select({ count: r() }).from(Ve).where(m);
|
|
2135
2181
|
return {
|
|
2136
2182
|
flows: g,
|
|
2137
2183
|
start: c * l,
|
|
@@ -2140,18 +2186,18 @@ function Ut(e) {
|
|
|
2140
2186
|
};
|
|
2141
2187
|
},
|
|
2142
2188
|
async remove(n, r) {
|
|
2143
|
-
return (await e.delete(
|
|
2189
|
+
return (await e.delete(Ve).where(t(a(Ve.tenant_id, n), a(Ve.id, r))).returning()).length > 0;
|
|
2144
2190
|
}
|
|
2145
2191
|
};
|
|
2146
2192
|
}
|
|
2147
2193
|
//#endregion
|
|
2148
2194
|
//#region src/adapters/forms.ts
|
|
2149
|
-
var
|
|
2195
|
+
var Yt = [
|
|
2150
2196
|
"nodes",
|
|
2151
2197
|
"start",
|
|
2152
2198
|
"ending"
|
|
2153
|
-
],
|
|
2154
|
-
function
|
|
2199
|
+
], Xt = ["name"];
|
|
2200
|
+
function Zt(e) {
|
|
2155
2201
|
return {
|
|
2156
2202
|
async create(t, n) {
|
|
2157
2203
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = b(), a = {
|
|
@@ -2165,8 +2211,8 @@ function Kt(e) {
|
|
|
2165
2211
|
created_at: r,
|
|
2166
2212
|
updated_at: r
|
|
2167
2213
|
};
|
|
2168
|
-
for (let e of
|
|
2169
|
-
return await e.insert(
|
|
2214
|
+
for (let e of Yt) a[e] = JSON.stringify(n[e] || (e === "nodes" ? [] : {}));
|
|
2215
|
+
return await e.insert(Be).values(a), {
|
|
2170
2216
|
id: i,
|
|
2171
2217
|
...n,
|
|
2172
2218
|
created_at: r,
|
|
@@ -2174,38 +2220,38 @@ function Kt(e) {
|
|
|
2174
2220
|
};
|
|
2175
2221
|
},
|
|
2176
2222
|
async get(n, r) {
|
|
2177
|
-
let i = await e.select().from(
|
|
2223
|
+
let i = await e.select().from(Be).where(t(a(Be.tenant_id, n), a(Be.id, r))).get();
|
|
2178
2224
|
if (!i) return null;
|
|
2179
2225
|
let { tenant_id: o, ...s } = i, c = { ...s };
|
|
2180
|
-
for (let e of
|
|
2226
|
+
for (let e of Yt) c[e] = Q(s[e]);
|
|
2181
2227
|
return O(c);
|
|
2182
2228
|
},
|
|
2183
2229
|
async update(n, r, i) {
|
|
2184
2230
|
let o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
2185
|
-
for (let [e, t] of Object.entries(i)) t !== void 0 && (
|
|
2186
|
-
return (await e.update(
|
|
2231
|
+
for (let [e, t] of Object.entries(i)) t !== void 0 && (Yt.includes(e) ? o[e] = JSON.stringify(t) : o[e] = t);
|
|
2232
|
+
return (await e.update(Be).set(o).where(t(a(Be.tenant_id, n), a(Be.id, r))).returning()).length > 0;
|
|
2187
2233
|
},
|
|
2188
2234
|
async list(o, s) {
|
|
2189
|
-
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = [a(
|
|
2235
|
+
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = [a(Be.tenant_id, o)];
|
|
2190
2236
|
if (f) {
|
|
2191
|
-
let e = _e(f,
|
|
2237
|
+
let e = _e(f, Xt);
|
|
2192
2238
|
if (e) {
|
|
2193
|
-
let t =
|
|
2239
|
+
let t = nt(Be, e, Xt);
|
|
2194
2240
|
t && p.push(t);
|
|
2195
2241
|
}
|
|
2196
2242
|
}
|
|
2197
|
-
let m = t(...p), h = e.select().from(
|
|
2243
|
+
let m = t(...p), h = e.select().from(Be).where(m).$dynamic();
|
|
2198
2244
|
if (d?.sort_by) {
|
|
2199
|
-
let e =
|
|
2245
|
+
let e = Be[d.sort_by];
|
|
2200
2246
|
e && (h = h.orderBy(d.sort_order === "desc" ? i(e) : n(e)));
|
|
2201
2247
|
}
|
|
2202
2248
|
let g = (await h.offset(c * l).limit(l)).map((e) => {
|
|
2203
2249
|
let { tenant_id: t, ...n } = e, r = { ...n };
|
|
2204
|
-
for (let e of
|
|
2250
|
+
for (let e of Yt) r[e] = Q(n[e]);
|
|
2205
2251
|
return O(r);
|
|
2206
2252
|
});
|
|
2207
2253
|
if (!u) return { forms: g };
|
|
2208
|
-
let [_] = await e.select({ count: r() }).from(
|
|
2254
|
+
let [_] = await e.select({ count: r() }).from(Be).where(m);
|
|
2209
2255
|
return {
|
|
2210
2256
|
forms: g,
|
|
2211
2257
|
start: c * l,
|
|
@@ -2214,13 +2260,13 @@ function Kt(e) {
|
|
|
2214
2260
|
};
|
|
2215
2261
|
},
|
|
2216
2262
|
async remove(n, r) {
|
|
2217
|
-
return (await e.delete(
|
|
2263
|
+
return (await e.delete(Be).where(t(a(Be.tenant_id, n), a(Be.id, r))).returning()).length > 0;
|
|
2218
2264
|
}
|
|
2219
2265
|
};
|
|
2220
2266
|
}
|
|
2221
2267
|
//#endregion
|
|
2222
2268
|
//#region src/adapters/grants.ts
|
|
2223
|
-
function
|
|
2269
|
+
function Qt(e) {
|
|
2224
2270
|
return {
|
|
2225
2271
|
id: e.id,
|
|
2226
2272
|
user_id: e.user_id,
|
|
@@ -2229,17 +2275,17 @@ function qt(e) {
|
|
|
2229
2275
|
scope: Q(e.scope, []) ?? []
|
|
2230
2276
|
};
|
|
2231
2277
|
}
|
|
2232
|
-
var
|
|
2278
|
+
var $t = {
|
|
2233
2279
|
user_id: B.user_id,
|
|
2234
2280
|
client_id: B.client_id,
|
|
2235
2281
|
audience: B.audience,
|
|
2236
2282
|
created_at: B.created_at,
|
|
2237
2283
|
updated_at: B.updated_at
|
|
2238
2284
|
};
|
|
2239
|
-
function
|
|
2240
|
-
return Object.hasOwn(
|
|
2285
|
+
function en(e) {
|
|
2286
|
+
return Object.hasOwn($t, e) ? $t[e] : void 0;
|
|
2241
2287
|
}
|
|
2242
|
-
function
|
|
2288
|
+
function tn(e) {
|
|
2243
2289
|
return {
|
|
2244
2290
|
async create(n, r) {
|
|
2245
2291
|
let i = (/* @__PURE__ */ new Date()).toISOString(), o = r.scope ?? [], s = r.audience ?? "", c = await e.select().from(B).where(t(a(B.tenant_id, n), a(B.user_id, r.user_id), a(B.client_id, r.clientID), a(B.audience, s))).get();
|
|
@@ -2248,7 +2294,7 @@ function Xt(e) {
|
|
|
2248
2294
|
return await e.update(B).set({
|
|
2249
2295
|
scope: JSON.stringify(s),
|
|
2250
2296
|
updated_at: i
|
|
2251
|
-
}).where(t(a(B.tenant_id, n), a(B.id, c.id))),
|
|
2297
|
+
}).where(t(a(B.tenant_id, n), a(B.id, c.id))), Qt({
|
|
2252
2298
|
...c,
|
|
2253
2299
|
scope: JSON.stringify(s)
|
|
2254
2300
|
});
|
|
@@ -2273,16 +2319,16 @@ function Xt(e) {
|
|
|
2273
2319
|
},
|
|
2274
2320
|
async get(n, r, i, o) {
|
|
2275
2321
|
let s = await e.select().from(B).where(t(a(B.tenant_id, n), a(B.user_id, r), a(B.client_id, i), a(B.audience, o ?? ""))).get();
|
|
2276
|
-
return s ?
|
|
2322
|
+
return s ? Qt(s) : null;
|
|
2277
2323
|
},
|
|
2278
2324
|
async list(o, s) {
|
|
2279
|
-
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ?
|
|
2325
|
+
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ? nt(B, f, [
|
|
2280
2326
|
"user_id",
|
|
2281
2327
|
"client_id",
|
|
2282
2328
|
"audience"
|
|
2283
|
-
]) : void 0, m = p ? t(a(B.tenant_id, o), p) : a(B.tenant_id, o), h = e.select().from(B).where(m).$dynamic(), g = d?.sort_by ?
|
|
2329
|
+
]) : void 0, m = p ? t(a(B.tenant_id, o), p) : a(B.tenant_id, o), h = e.select().from(B).where(m).$dynamic(), g = d?.sort_by ? en(d.sort_by) : void 0;
|
|
2284
2330
|
h = g ? h.orderBy(d?.sort_order === "desc" ? i(g) : n(g)) : h.orderBy(n(B.created_at));
|
|
2285
|
-
let _ = (await h.offset(c * l).limit(l)).map(
|
|
2331
|
+
let _ = (await h.offset(c * l).limit(l)).map(Qt);
|
|
2286
2332
|
if (!u) return {
|
|
2287
2333
|
grants: _,
|
|
2288
2334
|
start: 0,
|
|
@@ -2307,11 +2353,11 @@ function Xt(e) {
|
|
|
2307
2353
|
}
|
|
2308
2354
|
//#endregion
|
|
2309
2355
|
//#region src/adapters/hookCode.ts
|
|
2310
|
-
var
|
|
2311
|
-
function
|
|
2312
|
-
return `hc_${
|
|
2356
|
+
var nn = ee("0123456789abcdefghijklmnopqrstuvwxyz", 17);
|
|
2357
|
+
function rn() {
|
|
2358
|
+
return `hc_${nn()}`;
|
|
2313
2359
|
}
|
|
2314
|
-
function
|
|
2360
|
+
function an(e) {
|
|
2315
2361
|
let { created_at_ts: t, updated_at_ts: n, secrets: r, ...i } = e, a = ie({
|
|
2316
2362
|
created_at_ts: t,
|
|
2317
2363
|
updated_at_ts: n
|
|
@@ -2322,41 +2368,41 @@ function $t(e) {
|
|
|
2322
2368
|
secrets: r ? JSON.parse(r) : void 0
|
|
2323
2369
|
};
|
|
2324
2370
|
}
|
|
2325
|
-
function
|
|
2371
|
+
function on(e) {
|
|
2326
2372
|
return {
|
|
2327
2373
|
async create(t, n) {
|
|
2328
2374
|
let r = Date.now(), i = {
|
|
2329
|
-
id:
|
|
2375
|
+
id: rn(),
|
|
2330
2376
|
tenant_id: t,
|
|
2331
2377
|
code: n.code,
|
|
2332
2378
|
secrets: n.secrets ? JSON.stringify(n.secrets) : null,
|
|
2333
2379
|
created_at_ts: r,
|
|
2334
2380
|
updated_at_ts: r
|
|
2335
2381
|
};
|
|
2336
|
-
return await e.insert(
|
|
2382
|
+
return await e.insert(Ke).values(i), an({
|
|
2337
2383
|
...i,
|
|
2338
2384
|
tenant_id: t
|
|
2339
2385
|
});
|
|
2340
2386
|
},
|
|
2341
2387
|
async get(n, r) {
|
|
2342
|
-
let i = await e.select().from(
|
|
2343
|
-
return i ?
|
|
2388
|
+
let i = await e.select().from(Ke).where(t(a(Ke.tenant_id, n), a(Ke.id, r))).get();
|
|
2389
|
+
return i ? an(i) : null;
|
|
2344
2390
|
},
|
|
2345
2391
|
async update(n, r, i) {
|
|
2346
2392
|
let o = { updated_at_ts: Date.now() };
|
|
2347
|
-
return i.code !== void 0 && (o.code = i.code), i.secrets !== void 0 && (o.secrets = JSON.stringify(i.secrets)), (await e.update(
|
|
2393
|
+
return i.code !== void 0 && (o.code = i.code), i.secrets !== void 0 && (o.secrets = JSON.stringify(i.secrets)), (await e.update(Ke).set(o).where(t(a(Ke.tenant_id, n), a(Ke.id, r))).returning()).length > 0;
|
|
2348
2394
|
},
|
|
2349
2395
|
async remove(n, r) {
|
|
2350
|
-
return (await e.delete(
|
|
2396
|
+
return (await e.delete(Ke).where(t(a(Ke.tenant_id, n), a(Ke.id, r))).returning()).length > 0;
|
|
2351
2397
|
}
|
|
2352
2398
|
};
|
|
2353
2399
|
}
|
|
2354
2400
|
//#endregion
|
|
2355
2401
|
//#region src/adapters/hooks.ts
|
|
2356
|
-
function
|
|
2402
|
+
function sn() {
|
|
2357
2403
|
return `h_${ee("0123456789abcdefghijklmnopqrstuvwxyz", 17)()}`;
|
|
2358
2404
|
}
|
|
2359
|
-
function
|
|
2405
|
+
function cn(e) {
|
|
2360
2406
|
if (!(typeof e != "string" || !e)) try {
|
|
2361
2407
|
let t = JSON.parse(e);
|
|
2362
2408
|
return t && typeof t == "object" && !Array.isArray(t) ? t : void 0;
|
|
@@ -2364,7 +2410,7 @@ function nn(e) {
|
|
|
2364
2410
|
return;
|
|
2365
2411
|
}
|
|
2366
2412
|
}
|
|
2367
|
-
function
|
|
2413
|
+
function ln(e) {
|
|
2368
2414
|
let { tenant_id: t, created_at_ts: n, updated_at_ts: r, metadata: i, ...a } = e, o = ie({
|
|
2369
2415
|
created_at_ts: n,
|
|
2370
2416
|
updated_at_ts: r
|
|
@@ -2373,15 +2419,15 @@ function rn(e) {
|
|
|
2373
2419
|
...a,
|
|
2374
2420
|
enabled: !!a.enabled,
|
|
2375
2421
|
synchronous: !!a.synchronous,
|
|
2376
|
-
metadata:
|
|
2422
|
+
metadata: cn(i),
|
|
2377
2423
|
...o
|
|
2378
2424
|
});
|
|
2379
2425
|
}
|
|
2380
|
-
function
|
|
2426
|
+
function un(e) {
|
|
2381
2427
|
return {
|
|
2382
2428
|
async create(t, n) {
|
|
2383
2429
|
let r = Date.now(), i = {
|
|
2384
|
-
hook_id: n.hook_id ||
|
|
2430
|
+
hook_id: n.hook_id || sn(),
|
|
2385
2431
|
tenant_id: t,
|
|
2386
2432
|
trigger_id: n.trigger_id,
|
|
2387
2433
|
url: n.url,
|
|
@@ -2395,30 +2441,30 @@ function an(e) {
|
|
|
2395
2441
|
created_at_ts: r,
|
|
2396
2442
|
updated_at_ts: r
|
|
2397
2443
|
};
|
|
2398
|
-
return await e.insert(
|
|
2444
|
+
return await e.insert(Ge).values(i), ln({
|
|
2399
2445
|
...i,
|
|
2400
2446
|
tenant_id: t
|
|
2401
2447
|
});
|
|
2402
2448
|
},
|
|
2403
2449
|
async get(n, r) {
|
|
2404
|
-
let i = await e.select().from(
|
|
2405
|
-
return i ?
|
|
2450
|
+
let i = await e.select().from(Ge).where(t(a(Ge.tenant_id, n), a(Ge.hook_id, r))).get();
|
|
2451
|
+
return i ? ln(i) : null;
|
|
2406
2452
|
},
|
|
2407
2453
|
async update(n, r, i) {
|
|
2408
2454
|
let o = { updated_at_ts: Date.now() };
|
|
2409
|
-
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.metadata !== void 0 && (o.metadata = i.metadata === null ? null : JSON.stringify(i.metadata)), (await e.update(
|
|
2455
|
+
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.metadata !== void 0 && (o.metadata = i.metadata === null ? null : JSON.stringify(i.metadata)), (await e.update(Ge).set(o).where(t(a(Ge.tenant_id, n), a(Ge.hook_id, r))).returning()).length > 0;
|
|
2410
2456
|
},
|
|
2411
2457
|
async list(o, s) {
|
|
2412
|
-
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ?
|
|
2458
|
+
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ? nt(Ge, f, [
|
|
2413
2459
|
"url",
|
|
2414
2460
|
"form_id",
|
|
2415
2461
|
"template_id",
|
|
2416
2462
|
"code_id"
|
|
2417
|
-
]) : void 0, m = p ? t(a(
|
|
2418
|
-
h = g ? h.orderBy(d?.sort_order === "desc" ? i(g) : n(g)) : h.orderBy(i(
|
|
2419
|
-
let _ = (await h.offset(c * l).limit(l)).map(
|
|
2463
|
+
]) : void 0, m = p ? t(a(Ge.tenant_id, o), p) : a(Ge.tenant_id, o), h = e.select().from(Ge).where(m).$dynamic(), g = d?.sort_by ? Ge[d.sort_by] : void 0;
|
|
2464
|
+
h = g ? h.orderBy(d?.sort_order === "desc" ? i(g) : n(g)) : h.orderBy(i(Ge.priority), n(Ge.created_at_ts));
|
|
2465
|
+
let _ = (await h.offset(c * l).limit(l)).map(ln);
|
|
2420
2466
|
if (!u) return { hooks: _ };
|
|
2421
|
-
let [v] = await e.select({ count: r() }).from(
|
|
2467
|
+
let [v] = await e.select({ count: r() }).from(Ge).where(m);
|
|
2422
2468
|
return {
|
|
2423
2469
|
hooks: _,
|
|
2424
2470
|
start: c * l,
|
|
@@ -2427,31 +2473,31 @@ function an(e) {
|
|
|
2427
2473
|
};
|
|
2428
2474
|
},
|
|
2429
2475
|
async remove(n, r) {
|
|
2430
|
-
return (await e.delete(
|
|
2476
|
+
return (await e.delete(Ge).where(t(a(Ge.tenant_id, n), a(Ge.hook_id, r))).returning()).length > 0;
|
|
2431
2477
|
}
|
|
2432
2478
|
};
|
|
2433
2479
|
}
|
|
2434
2480
|
//#endregion
|
|
2435
2481
|
//#region src/adapters/invites.ts
|
|
2436
|
-
function
|
|
2482
|
+
function dn() {
|
|
2437
2483
|
return `inv_${ee("0123456789abcdefghijklmnopqrstuvwxyz", 17)()}`;
|
|
2438
2484
|
}
|
|
2439
|
-
var
|
|
2485
|
+
var fn = [
|
|
2440
2486
|
"inviter",
|
|
2441
2487
|
"invitee",
|
|
2442
2488
|
"app_metadata",
|
|
2443
2489
|
"user_metadata",
|
|
2444
2490
|
"roles"
|
|
2445
2491
|
];
|
|
2446
|
-
function
|
|
2492
|
+
function pn(e) {
|
|
2447
2493
|
let { tenant_id: t, send_invitation_email: n, ...r } = e, i = { ...r };
|
|
2448
|
-
for (let e of
|
|
2494
|
+
for (let e of fn) i[e] = Q(r[e], e === "roles" ? [] : {});
|
|
2449
2495
|
return i.send_invitation_email = !!n, O(i);
|
|
2450
2496
|
}
|
|
2451
|
-
function
|
|
2497
|
+
function mn(e) {
|
|
2452
2498
|
return {
|
|
2453
2499
|
async create(t, n) {
|
|
2454
|
-
let r = n.id ||
|
|
2500
|
+
let r = n.id || dn(), i = n.ttl_sec || 604800, a = /* @__PURE__ */ new Date(), o = new Date(a.getTime() + i * 1e3).toISOString(), s = {
|
|
2455
2501
|
id: r,
|
|
2456
2502
|
tenant_id: t,
|
|
2457
2503
|
organization_id: n.organization_id,
|
|
@@ -2464,35 +2510,35 @@ function ln(e) {
|
|
|
2464
2510
|
created_at: a.toISOString(),
|
|
2465
2511
|
expires_at: o
|
|
2466
2512
|
};
|
|
2467
|
-
for (let e of
|
|
2513
|
+
for (let e of fn) n[e] !== void 0 && (s[e] = JSON.stringify(n[e]));
|
|
2468
2514
|
try {
|
|
2469
|
-
await e.insert(
|
|
2515
|
+
await e.insert(Pe).values(s);
|
|
2470
2516
|
} catch (e) {
|
|
2471
|
-
throw e?.message?.includes("UNIQUE constraint failed") || e?.message?.includes("duplicate key") ? new
|
|
2517
|
+
throw e?.message?.includes("UNIQUE constraint failed") || e?.message?.includes("duplicate key") ? new Ce(409, { message: "Invite already exists" }) : e;
|
|
2472
2518
|
}
|
|
2473
|
-
return
|
|
2519
|
+
return pn({
|
|
2474
2520
|
...s,
|
|
2475
2521
|
tenant_id: t
|
|
2476
2522
|
});
|
|
2477
2523
|
},
|
|
2478
2524
|
async get(n, r) {
|
|
2479
|
-
let i = await e.select().from(
|
|
2480
|
-
return i ?
|
|
2525
|
+
let i = await e.select().from(Pe).where(t(a(Pe.tenant_id, n), a(Pe.id, r))).get();
|
|
2526
|
+
return i ? pn(i) : null;
|
|
2481
2527
|
},
|
|
2482
2528
|
async update(n, r, i) {
|
|
2483
2529
|
let o = {};
|
|
2484
|
-
for (let e of
|
|
2485
|
-
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(
|
|
2530
|
+
for (let e of fn) i[e] !== void 0 && (o[e] = JSON.stringify(i[e]));
|
|
2531
|
+
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(Pe).set(o).where(t(a(Pe.tenant_id, n), a(Pe.id, r))).returning()).length > 0;
|
|
2486
2532
|
},
|
|
2487
2533
|
async list(t, o) {
|
|
2488
|
-
let { page: s = 0, per_page: c = 50, include_totals: l = !1, sort: u } = o || {}, d = e.select().from(
|
|
2534
|
+
let { page: s = 0, per_page: c = 50, include_totals: l = !1, sort: u } = o || {}, d = e.select().from(Pe).where(a(Pe.tenant_id, t)).$dynamic();
|
|
2489
2535
|
if (u?.sort_by) {
|
|
2490
|
-
let e =
|
|
2536
|
+
let e = Pe[u.sort_by];
|
|
2491
2537
|
e && (d = d.orderBy(u.sort_order === "desc" ? i(e) : n(e)));
|
|
2492
2538
|
}
|
|
2493
|
-
let f = (await d.offset(s * c).limit(c)).map(
|
|
2539
|
+
let f = (await d.offset(s * c).limit(c)).map(pn);
|
|
2494
2540
|
if (!l) return { invites: f };
|
|
2495
|
-
let [p] = await e.select({ count: r() }).from(
|
|
2541
|
+
let [p] = await e.select({ count: r() }).from(Pe).where(a(Pe.tenant_id, t));
|
|
2496
2542
|
return {
|
|
2497
2543
|
invites: f,
|
|
2498
2544
|
start: s * c,
|
|
@@ -2501,39 +2547,39 @@ function ln(e) {
|
|
|
2501
2547
|
};
|
|
2502
2548
|
},
|
|
2503
2549
|
async remove(n, r) {
|
|
2504
|
-
return (await e.delete(
|
|
2550
|
+
return (await e.delete(Pe).where(t(a(Pe.tenant_id, n), a(Pe.id, r))).returning()).length > 0;
|
|
2505
2551
|
}
|
|
2506
2552
|
};
|
|
2507
2553
|
}
|
|
2508
2554
|
//#endregion
|
|
2509
2555
|
//#region src/adapters/keys.ts
|
|
2510
|
-
var
|
|
2556
|
+
var hn = [
|
|
2511
2557
|
"kid",
|
|
2512
2558
|
"connection",
|
|
2513
2559
|
"fingerprint",
|
|
2514
2560
|
"thumbprint",
|
|
2515
2561
|
"type"
|
|
2516
2562
|
];
|
|
2517
|
-
function
|
|
2563
|
+
function gn(e) {
|
|
2518
2564
|
return {
|
|
2519
2565
|
async create(t) {
|
|
2520
|
-
await e.insert(
|
|
2566
|
+
await e.insert(qe).values({
|
|
2521
2567
|
...t,
|
|
2522
2568
|
created_at: (/* @__PURE__ */ new Date()).toDateString()
|
|
2523
2569
|
});
|
|
2524
2570
|
},
|
|
2525
2571
|
async list(a) {
|
|
2526
|
-
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(
|
|
2572
|
+
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(qe.revoked_at, p), f(qe.revoked_at))];
|
|
2527
2573
|
if (d) {
|
|
2528
|
-
let e = _e(d,
|
|
2574
|
+
let e = _e(d, hn);
|
|
2529
2575
|
if (e) {
|
|
2530
|
-
let t =
|
|
2576
|
+
let t = nt(qe, e, hn);
|
|
2531
2577
|
t && m.push(t);
|
|
2532
2578
|
}
|
|
2533
2579
|
}
|
|
2534
|
-
let h = t(...m), g = e.select().from(
|
|
2580
|
+
let h = t(...m), g = e.select().from(qe).where(h).$dynamic();
|
|
2535
2581
|
if (u?.sort_by) {
|
|
2536
|
-
let e =
|
|
2582
|
+
let e = qe[u.sort_by];
|
|
2537
2583
|
e && (g = g.orderBy(u.sort_order === "desc" ? i(e) : n(e)));
|
|
2538
2584
|
}
|
|
2539
2585
|
let _ = (await g.offset(o * c).limit(c)).map((e) => {
|
|
@@ -2541,7 +2587,7 @@ function dn(e) {
|
|
|
2541
2587
|
return O(n);
|
|
2542
2588
|
});
|
|
2543
2589
|
if (!l) return { signingKeys: _ };
|
|
2544
|
-
let [y] = await e.select({ count: r() }).from(
|
|
2590
|
+
let [y] = await e.select({ count: r() }).from(qe).where(h);
|
|
2545
2591
|
return {
|
|
2546
2592
|
signingKeys: _,
|
|
2547
2593
|
start: o * c,
|
|
@@ -2550,22 +2596,22 @@ function dn(e) {
|
|
|
2550
2596
|
};
|
|
2551
2597
|
},
|
|
2552
2598
|
async update(t, n) {
|
|
2553
|
-
return (await e.update(
|
|
2599
|
+
return (await e.update(qe).set(n).where(a(qe.kid, t)).returning()).length > 0;
|
|
2554
2600
|
}
|
|
2555
2601
|
};
|
|
2556
2602
|
}
|
|
2557
2603
|
//#endregion
|
|
2558
2604
|
//#region src/adapters/loginSessions.ts
|
|
2559
|
-
var
|
|
2560
|
-
function
|
|
2605
|
+
var _n = "0123456789ABCDEFGHJKMNPQRSTVWXYZ", vn = 32;
|
|
2606
|
+
function yn() {
|
|
2561
2607
|
let e = Date.now(), t = "";
|
|
2562
|
-
for (let n = 10; n > 0; n--) t =
|
|
2608
|
+
for (let n = 10; n > 0; n--) t = _n.charAt(e % vn) + t, e = Math.floor(e / vn);
|
|
2563
2609
|
let n = new Uint8Array(16);
|
|
2564
2610
|
crypto.getRandomValues(n);
|
|
2565
|
-
for (let e = 0; e < 16; e++) t +=
|
|
2611
|
+
for (let e = 0; e < 16; e++) t += _n.charAt(n[e] % vn);
|
|
2566
2612
|
return t;
|
|
2567
2613
|
}
|
|
2568
|
-
function
|
|
2614
|
+
function bn(e) {
|
|
2569
2615
|
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 = ie({
|
|
2570
2616
|
created_at_ts: n,
|
|
2571
2617
|
updated_at_ts: r,
|
|
@@ -2577,17 +2623,17 @@ function hn(e) {
|
|
|
2577
2623
|
]), l = {};
|
|
2578
2624
|
for (let [e, t] of Object.entries(s)) t != null && (l[e] = t);
|
|
2579
2625
|
return O({
|
|
2580
|
-
|
|
2626
|
+
...$e(l, ["auth_strategy"]),
|
|
2581
2627
|
authParams: typeof o == "string" && o.length > 0 ? JSON.parse(o) : {},
|
|
2582
2628
|
...c,
|
|
2583
2629
|
state_data: Q(a)
|
|
2584
2630
|
});
|
|
2585
2631
|
}
|
|
2586
|
-
function
|
|
2632
|
+
function xn(e) {
|
|
2587
2633
|
return {
|
|
2588
2634
|
async create(t, n) {
|
|
2589
2635
|
let r = Date.now(), i = {
|
|
2590
|
-
id:
|
|
2636
|
+
id: yn(),
|
|
2591
2637
|
tenant_id: t,
|
|
2592
2638
|
session_id: n.session_id,
|
|
2593
2639
|
csrf_token: n.csrf_token,
|
|
@@ -2608,14 +2654,14 @@ function gn(e) {
|
|
|
2608
2654
|
updated_at_ts: r,
|
|
2609
2655
|
expires_at_ts: n.expires_at ? D(n.expires_at) : r + 1e3 * 60 * 60 * 24
|
|
2610
2656
|
};
|
|
2611
|
-
return await e.insert(F).values(i),
|
|
2657
|
+
return await e.insert(F).values(i), bn({
|
|
2612
2658
|
...i,
|
|
2613
2659
|
tenant_id: t
|
|
2614
2660
|
});
|
|
2615
2661
|
},
|
|
2616
2662
|
async get(n, r) {
|
|
2617
2663
|
let i = n ? t(a(F.tenant_id, n), a(F.id, r)) : a(F.id, r), o = await e.select().from(F).where(i).get();
|
|
2618
|
-
return o ?
|
|
2664
|
+
return o ? bn(o) : null;
|
|
2619
2665
|
},
|
|
2620
2666
|
async update(n, r, i) {
|
|
2621
2667
|
let o = { updated_at_ts: Date.now() };
|
|
@@ -2635,7 +2681,7 @@ function gn(e) {
|
|
|
2635
2681
|
}
|
|
2636
2682
|
//#endregion
|
|
2637
2683
|
//#region src/adapters/logs.ts
|
|
2638
|
-
function
|
|
2684
|
+
function Sn(e) {
|
|
2639
2685
|
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 = {
|
|
2640
2686
|
...f,
|
|
2641
2687
|
isMobile: !!n,
|
|
@@ -2652,7 +2698,7 @@ function _n(e) {
|
|
|
2652
2698
|
continent_code: u
|
|
2653
2699
|
})), O(p);
|
|
2654
2700
|
}
|
|
2655
|
-
function
|
|
2701
|
+
function Cn(e) {
|
|
2656
2702
|
return {
|
|
2657
2703
|
async create(t, n) {
|
|
2658
2704
|
let r = {
|
|
@@ -2678,15 +2724,15 @@ function vn(e) {
|
|
|
2678
2724
|
hostname: n.hostname,
|
|
2679
2725
|
session_connection: n.session_connection
|
|
2680
2726
|
};
|
|
2681
|
-
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(
|
|
2727
|
+
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(J).values(r), Sn({
|
|
2682
2728
|
...r,
|
|
2683
2729
|
tenant_id: t
|
|
2684
2730
|
});
|
|
2685
2731
|
},
|
|
2686
2732
|
async list(o, s) {
|
|
2687
|
-
let { page: l = 0, per_page: u = 50, include_totals: d = !1, sort: f, q: p, from_date: h, to_date: g } = s || {}, _ = [a(
|
|
2733
|
+
let { page: l = 0, per_page: u = 50, include_totals: d = !1, sort: f, q: p, from_date: h, to_date: g } = s || {}, _ = [a(J.tenant_id, o)];
|
|
2688
2734
|
if (p) {
|
|
2689
|
-
let e =
|
|
2735
|
+
let e = nt(J, p, [
|
|
2690
2736
|
"user_id",
|
|
2691
2737
|
"ip",
|
|
2692
2738
|
"type",
|
|
@@ -2694,16 +2740,16 @@ function vn(e) {
|
|
|
2694
2740
|
], ["description"]);
|
|
2695
2741
|
e && _.push(e);
|
|
2696
2742
|
}
|
|
2697
|
-
typeof h == "number" && Number.isFinite(h) && _.push(c(
|
|
2743
|
+
typeof h == "number" && Number.isFinite(h) && _.push(c(J.date, (/* @__PURE__ */ new Date(Math.floor(h) * 1e3)).toISOString())), typeof g == "number" && Number.isFinite(g) && _.push(m(J.date, (/* @__PURE__ */ new Date((Math.floor(g) + 1) * 1e3)).toISOString()));
|
|
2698
2744
|
let v = t(..._);
|
|
2699
|
-
if (
|
|
2700
|
-
if (f?.sort_by && f.sort_by !== "date") throw new
|
|
2745
|
+
if (mt(s)) {
|
|
2746
|
+
if (f?.sort_by && f.sort_by !== "date") throw new Ce(400, { message: `Sorting by ${f.sort_by} is not supported with checkpoint pagination (from/take); only date is` });
|
|
2701
2747
|
let n = f?.sort_order === "asc" ? "asc" : "desc", r = {
|
|
2702
|
-
sortColumn:
|
|
2703
|
-
idColumn:
|
|
2748
|
+
sortColumn: J.date,
|
|
2749
|
+
idColumn: J.log_id,
|
|
2704
2750
|
sortOrder: n,
|
|
2705
2751
|
sortKey: `date:${n}`
|
|
2706
|
-
}, i =
|
|
2752
|
+
}, i = _t(s, r), a = ht(s), { rows: o, next: c } = vt(await e.select().from(J).where(i ? t(v, i) : v).orderBy(...gt(r)).limit(a + 1), a, "date", "log_id", r.sortKey), l = o.map(Sn);
|
|
2707
2753
|
return {
|
|
2708
2754
|
logs: l,
|
|
2709
2755
|
start: 0,
|
|
@@ -2712,14 +2758,14 @@ function vn(e) {
|
|
|
2712
2758
|
next: c
|
|
2713
2759
|
};
|
|
2714
2760
|
}
|
|
2715
|
-
let y = e.select().from(
|
|
2761
|
+
let y = e.select().from(J).where(v).$dynamic();
|
|
2716
2762
|
if (f?.sort_by) {
|
|
2717
|
-
let e =
|
|
2763
|
+
let e = J[f.sort_by];
|
|
2718
2764
|
e && (y = y.orderBy(f.sort_order === "desc" ? i(e) : n(e)));
|
|
2719
|
-
} else y = y.orderBy(i(
|
|
2720
|
-
let ee = (await y.offset(l * u).limit(u)).map(
|
|
2765
|
+
} else y = y.orderBy(i(J.date));
|
|
2766
|
+
let ee = (await y.offset(l * u).limit(u)).map(Sn);
|
|
2721
2767
|
if (!d) return { logs: ee };
|
|
2722
|
-
let [b] = await e.select({ count: r() }).from(
|
|
2768
|
+
let [b] = await e.select({ count: r() }).from(J).where(v);
|
|
2723
2769
|
return {
|
|
2724
2770
|
logs: ee,
|
|
2725
2771
|
start: l * u,
|
|
@@ -2728,23 +2774,23 @@ function vn(e) {
|
|
|
2728
2774
|
};
|
|
2729
2775
|
},
|
|
2730
2776
|
async get(n, r) {
|
|
2731
|
-
let i = await e.select().from(
|
|
2732
|
-
return i ?
|
|
2777
|
+
let i = await e.select().from(J).where(t(a(J.tenant_id, n), a(J.log_id, r))).get();
|
|
2778
|
+
return i ? Sn(i) : null;
|
|
2733
2779
|
}
|
|
2734
2780
|
};
|
|
2735
2781
|
}
|
|
2736
2782
|
//#endregion
|
|
2737
2783
|
//#region src/adapters/authenticationMethods.ts
|
|
2738
|
-
var
|
|
2739
|
-
function
|
|
2784
|
+
var wn = "0123456789ABCDEFGHJKMNPQRSTVWXYZ", Tn = 32;
|
|
2785
|
+
function En() {
|
|
2740
2786
|
let e = Date.now(), t = "";
|
|
2741
|
-
for (let n = 10; n > 0; n--) t =
|
|
2787
|
+
for (let n = 10; n > 0; n--) t = wn.charAt(e % Tn) + t, e = Math.floor(e / Tn);
|
|
2742
2788
|
let n = new Uint8Array(16);
|
|
2743
2789
|
crypto.getRandomValues(n);
|
|
2744
|
-
for (let e = 0; e < 16; e++) t +=
|
|
2790
|
+
for (let e = 0; e < 16; e++) t += wn.charAt(n[e] % Tn);
|
|
2745
2791
|
return t;
|
|
2746
2792
|
}
|
|
2747
|
-
function
|
|
2793
|
+
function Dn(e) {
|
|
2748
2794
|
let { tenant_id: t, created_at_ts: n, updated_at_ts: r, credential_backed_up: i, confirmed: a, transports: o, ...s } = e;
|
|
2749
2795
|
return O({
|
|
2750
2796
|
...s,
|
|
@@ -2755,11 +2801,11 @@ function Sn(e) {
|
|
|
2755
2801
|
updated_at: ae(r)
|
|
2756
2802
|
});
|
|
2757
2803
|
}
|
|
2758
|
-
function
|
|
2804
|
+
function On(e) {
|
|
2759
2805
|
return {
|
|
2760
2806
|
async create(t, n) {
|
|
2761
2807
|
let r = Date.now(), i = {
|
|
2762
|
-
id: n.id ||
|
|
2808
|
+
id: n.id || En(),
|
|
2763
2809
|
tenant_id: t,
|
|
2764
2810
|
user_id: n.user_id,
|
|
2765
2811
|
type: n.type,
|
|
@@ -2775,41 +2821,41 @@ function Cn(e) {
|
|
|
2775
2821
|
created_at_ts: r,
|
|
2776
2822
|
updated_at_ts: r
|
|
2777
2823
|
};
|
|
2778
|
-
return await e.insert(
|
|
2824
|
+
return await e.insert(q).values(i), Dn({
|
|
2779
2825
|
...i,
|
|
2780
2826
|
tenant_id: t
|
|
2781
2827
|
});
|
|
2782
2828
|
},
|
|
2783
2829
|
async get(n, r) {
|
|
2784
|
-
let i = await e.select().from(
|
|
2785
|
-
return i ?
|
|
2830
|
+
let i = await e.select().from(q).where(t(a(q.tenant_id, n), a(q.id, r))).get();
|
|
2831
|
+
return i ? Dn(i) : null;
|
|
2786
2832
|
},
|
|
2787
2833
|
async getByCredentialId(n, r) {
|
|
2788
|
-
let i = await e.select().from(
|
|
2789
|
-
return i ?
|
|
2834
|
+
let i = await e.select().from(q).where(t(a(q.tenant_id, n), a(q.credential_id, r))).get();
|
|
2835
|
+
return i ? Dn(i) : null;
|
|
2790
2836
|
},
|
|
2791
2837
|
async list(n, r) {
|
|
2792
|
-
return (await e.select().from(
|
|
2838
|
+
return (await e.select().from(q).where(t(a(q.tenant_id, n), a(q.user_id, r))).all()).map(Dn);
|
|
2793
2839
|
},
|
|
2794
2840
|
async update(n, r, i) {
|
|
2795
2841
|
let o = { updated_at_ts: Date.now() };
|
|
2796
|
-
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(
|
|
2842
|
+
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(q).set(o).where(t(a(q.tenant_id, n), a(q.id, r)));
|
|
2797
2843
|
let s = await this.get(n, r);
|
|
2798
2844
|
if (!s) throw Error(`Authentication method ${r} not found after update`);
|
|
2799
2845
|
return s;
|
|
2800
2846
|
},
|
|
2801
2847
|
async remove(n, r) {
|
|
2802
|
-
return (await e.delete(
|
|
2848
|
+
return (await e.delete(q).where(t(a(q.tenant_id, n), a(q.id, r))).returning()).length > 0;
|
|
2803
2849
|
}
|
|
2804
2850
|
};
|
|
2805
2851
|
}
|
|
2806
2852
|
//#endregion
|
|
2807
2853
|
//#region src/adapters/organizations.ts
|
|
2808
|
-
var
|
|
2809
|
-
function
|
|
2854
|
+
var kn = ["name", "display_name"];
|
|
2855
|
+
function An() {
|
|
2810
2856
|
return `org_${ee("0123456789abcdefghijklmnopqrstuvwxyz", 17)()}`;
|
|
2811
2857
|
}
|
|
2812
|
-
function
|
|
2858
|
+
function jn(e) {
|
|
2813
2859
|
let { tenant_id: t, branding: n, metadata: r, enabled_connections: i, token_quota: a, ...o } = e;
|
|
2814
2860
|
return O({
|
|
2815
2861
|
...o,
|
|
@@ -2819,11 +2865,11 @@ function En(e) {
|
|
|
2819
2865
|
token_quota: Q(a, {})
|
|
2820
2866
|
});
|
|
2821
2867
|
}
|
|
2822
|
-
function
|
|
2868
|
+
function Mn(e) {
|
|
2823
2869
|
return {
|
|
2824
2870
|
async create(t, n) {
|
|
2825
2871
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
2826
|
-
id: n.id ||
|
|
2872
|
+
id: n.id || An(),
|
|
2827
2873
|
tenant_id: t,
|
|
2828
2874
|
name: n.name,
|
|
2829
2875
|
display_name: n.display_name,
|
|
@@ -2835,39 +2881,39 @@ function Dn(e) {
|
|
|
2835
2881
|
updated_at: r
|
|
2836
2882
|
};
|
|
2837
2883
|
try {
|
|
2838
|
-
await e.insert(
|
|
2884
|
+
await e.insert(H).values(i);
|
|
2839
2885
|
} catch (e) {
|
|
2840
|
-
throw e?.message?.includes("UNIQUE constraint failed") || e?.message?.includes("AlreadyExists") ? new
|
|
2886
|
+
throw e?.message?.includes("UNIQUE constraint failed") || e?.message?.includes("AlreadyExists") ? new Ce(409, { message: "Organization already exists" }) : e;
|
|
2841
2887
|
}
|
|
2842
|
-
return
|
|
2888
|
+
return jn({
|
|
2843
2889
|
...i,
|
|
2844
2890
|
tenant_id: t
|
|
2845
2891
|
});
|
|
2846
2892
|
},
|
|
2847
2893
|
async get(n, r) {
|
|
2848
|
-
let i = await e.select().from(
|
|
2849
|
-
return i ||= await e.select().from(
|
|
2894
|
+
let i = await e.select().from(H).where(t(a(H.tenant_id, n), a(H.id, r))).get();
|
|
2895
|
+
return i ||= await e.select().from(H).where(t(a(H.tenant_id, n), a(H.name, r))).get(), i ? jn(i) : null;
|
|
2850
2896
|
},
|
|
2851
2897
|
async update(n, r, i) {
|
|
2852
2898
|
let o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
2853
|
-
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(
|
|
2899
|
+
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(H).set(o).where(t(a(H.tenant_id, n), a(H.id, r))).returning()).length > 0;
|
|
2854
2900
|
},
|
|
2855
2901
|
async list(o, s) {
|
|
2856
|
-
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = [a(
|
|
2902
|
+
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = [a(H.tenant_id, o)];
|
|
2857
2903
|
if (f) {
|
|
2858
|
-
let e = _e(f,
|
|
2904
|
+
let e = _e(f, kn);
|
|
2859
2905
|
if (e) {
|
|
2860
|
-
let t =
|
|
2906
|
+
let t = nt(H, e, kn);
|
|
2861
2907
|
t && p.push(t);
|
|
2862
2908
|
}
|
|
2863
2909
|
}
|
|
2864
2910
|
let m = t(...p);
|
|
2865
|
-
if (
|
|
2911
|
+
if (mt(s)) {
|
|
2866
2912
|
let n = {
|
|
2867
|
-
sortColumn:
|
|
2868
|
-
idColumn:
|
|
2913
|
+
sortColumn: H.created_at,
|
|
2914
|
+
idColumn: H.id,
|
|
2869
2915
|
sortOrder: "desc"
|
|
2870
|
-
}, r =
|
|
2916
|
+
}, r = _t(s, n), i = ht(s), { rows: a, next: o } = vt(await e.select().from(H).where(r ? t(m, r) : m).orderBy(...gt(n)).limit(i + 1), i, "created_at"), c = a.map(jn);
|
|
2871
2917
|
return {
|
|
2872
2918
|
organizations: c,
|
|
2873
2919
|
start: 0,
|
|
@@ -2877,14 +2923,14 @@ function Dn(e) {
|
|
|
2877
2923
|
next: o
|
|
2878
2924
|
};
|
|
2879
2925
|
}
|
|
2880
|
-
let h = e.select().from(
|
|
2926
|
+
let h = e.select().from(H).where(m).$dynamic();
|
|
2881
2927
|
if (d?.sort_by) {
|
|
2882
|
-
let e =
|
|
2928
|
+
let e = H[d.sort_by];
|
|
2883
2929
|
e && (h = h.orderBy(d.sort_order === "desc" ? i(e) : n(e)));
|
|
2884
2930
|
}
|
|
2885
|
-
let g = (await h.offset(c * l).limit(l)).map(
|
|
2931
|
+
let g = (await h.offset(c * l).limit(l)).map(jn);
|
|
2886
2932
|
if (!u) return { organizations: g };
|
|
2887
|
-
let [_] = await e.select({ count: r() }).from(
|
|
2933
|
+
let [_] = await e.select({ count: r() }).from(H).where(m);
|
|
2888
2934
|
return {
|
|
2889
2935
|
organizations: g,
|
|
2890
2936
|
start: c * l,
|
|
@@ -2893,20 +2939,20 @@ function Dn(e) {
|
|
|
2893
2939
|
};
|
|
2894
2940
|
},
|
|
2895
2941
|
async remove(n, r) {
|
|
2896
|
-
return (await e.delete(
|
|
2942
|
+
return (await e.delete(H).where(t(a(H.tenant_id, n), a(H.id, r))).returning()).length > 0;
|
|
2897
2943
|
}
|
|
2898
2944
|
};
|
|
2899
2945
|
}
|
|
2900
2946
|
//#endregion
|
|
2901
2947
|
//#region src/adapters/passwords.ts
|
|
2902
|
-
function
|
|
2948
|
+
function Nn(e) {
|
|
2903
2949
|
let { tenant_id: t, is_current: n, ...r } = e;
|
|
2904
2950
|
return {
|
|
2905
2951
|
...r,
|
|
2906
2952
|
is_current: !!n
|
|
2907
2953
|
};
|
|
2908
2954
|
}
|
|
2909
|
-
function
|
|
2955
|
+
function Pn(e) {
|
|
2910
2956
|
return {
|
|
2911
2957
|
async create(n, r) {
|
|
2912
2958
|
let i = (/* @__PURE__ */ new Date()).toISOString(), o = r.id || b();
|
|
@@ -2921,18 +2967,18 @@ function kn(e) {
|
|
|
2921
2967
|
created_at: i,
|
|
2922
2968
|
updated_at: i
|
|
2923
2969
|
};
|
|
2924
|
-
return await e.insert(M).values(s),
|
|
2970
|
+
return await e.insert(M).values(s), Nn({
|
|
2925
2971
|
...s,
|
|
2926
2972
|
tenant_id: n
|
|
2927
2973
|
});
|
|
2928
2974
|
},
|
|
2929
2975
|
async get(n, r) {
|
|
2930
2976
|
let i = await e.select().from(M).where(t(a(M.tenant_id, n), a(M.user_id, r), a(M.is_current, 1))).get();
|
|
2931
|
-
return i ?
|
|
2977
|
+
return i ? Nn(i) : null;
|
|
2932
2978
|
},
|
|
2933
2979
|
async list(n, r, o) {
|
|
2934
2980
|
let s = e.select().from(M).where(t(a(M.tenant_id, n), a(M.user_id, r))).orderBy(i(M.created_at)).$dynamic();
|
|
2935
|
-
return o && (s = s.limit(o)), (await s).map(
|
|
2981
|
+
return o && (s = s.limit(o)), (await s).map(Nn);
|
|
2936
2982
|
},
|
|
2937
2983
|
async update(n, r) {
|
|
2938
2984
|
let i = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
@@ -2942,36 +2988,40 @@ function kn(e) {
|
|
|
2942
2988
|
}
|
|
2943
2989
|
//#endregion
|
|
2944
2990
|
//#region src/adapters/promptSettings.ts
|
|
2945
|
-
function
|
|
2991
|
+
function Fn(e) {
|
|
2946
2992
|
return {
|
|
2947
2993
|
async get(t) {
|
|
2948
|
-
let n = await e.select().from(
|
|
2994
|
+
let n = await e.select().from(He).where(a(He.tenant_id, t)).get();
|
|
2949
2995
|
return n ? {
|
|
2950
2996
|
universal_login_experience: n.universal_login_experience,
|
|
2951
2997
|
identifier_first: !!n.identifier_first,
|
|
2952
2998
|
password_first: !!n.password_first,
|
|
2953
|
-
webauthn_platform_first_factor: !!n.webauthn_platform_first_factor
|
|
2999
|
+
webauthn_platform_first_factor: !!n.webauthn_platform_first_factor,
|
|
3000
|
+
show_last_used_connection: !!n.show_last_used_connection
|
|
2954
3001
|
} : {
|
|
2955
3002
|
universal_login_experience: "new",
|
|
2956
3003
|
identifier_first: !0,
|
|
2957
3004
|
password_first: !1,
|
|
2958
|
-
webauthn_platform_first_factor: !1
|
|
3005
|
+
webauthn_platform_first_factor: !1,
|
|
3006
|
+
show_last_used_connection: !1
|
|
2959
3007
|
};
|
|
2960
3008
|
},
|
|
2961
3009
|
async set(t, n) {
|
|
2962
|
-
await e.insert(
|
|
3010
|
+
await e.insert(He).values({
|
|
2963
3011
|
tenant_id: t,
|
|
2964
3012
|
universal_login_experience: n.universal_login_experience,
|
|
2965
3013
|
identifier_first: n.identifier_first,
|
|
2966
3014
|
password_first: n.password_first,
|
|
2967
|
-
webauthn_platform_first_factor: n.webauthn_platform_first_factor
|
|
3015
|
+
webauthn_platform_first_factor: n.webauthn_platform_first_factor,
|
|
3016
|
+
show_last_used_connection: n.show_last_used_connection
|
|
2968
3017
|
}).onConflictDoUpdate({
|
|
2969
|
-
target:
|
|
3018
|
+
target: He.tenant_id,
|
|
2970
3019
|
set: {
|
|
2971
3020
|
universal_login_experience: n.universal_login_experience,
|
|
2972
3021
|
identifier_first: n.identifier_first,
|
|
2973
3022
|
password_first: n.password_first,
|
|
2974
|
-
webauthn_platform_first_factor: n.webauthn_platform_first_factor
|
|
3023
|
+
webauthn_platform_first_factor: n.webauthn_platform_first_factor,
|
|
3024
|
+
show_last_used_connection: n.show_last_used_connection
|
|
2975
3025
|
}
|
|
2976
3026
|
});
|
|
2977
3027
|
}
|
|
@@ -2979,7 +3029,7 @@ function An(e) {
|
|
|
2979
3029
|
}
|
|
2980
3030
|
//#endregion
|
|
2981
3031
|
//#region src/adapters/proxyRoutes.ts
|
|
2982
|
-
function
|
|
3032
|
+
function In(e) {
|
|
2983
3033
|
if (!e) return { path: "/*" };
|
|
2984
3034
|
try {
|
|
2985
3035
|
let t = JSON.parse(e), n = me.safeParse(t);
|
|
@@ -2987,7 +3037,7 @@ function jn(e) {
|
|
|
2987
3037
|
} catch {}
|
|
2988
3038
|
return { path: "/*" };
|
|
2989
3039
|
}
|
|
2990
|
-
function
|
|
3040
|
+
function Ln(e) {
|
|
2991
3041
|
if (!e) return [];
|
|
2992
3042
|
try {
|
|
2993
3043
|
let t = JSON.parse(e);
|
|
@@ -3002,19 +3052,19 @@ function Mn(e) {
|
|
|
3002
3052
|
return [];
|
|
3003
3053
|
}
|
|
3004
3054
|
}
|
|
3005
|
-
function
|
|
3055
|
+
function Rn(e) {
|
|
3006
3056
|
return {
|
|
3007
3057
|
id: e.id,
|
|
3008
3058
|
tenant_id: e.tenant_id,
|
|
3009
3059
|
custom_domain_id: e.custom_domain_id,
|
|
3010
3060
|
priority: e.priority,
|
|
3011
|
-
match:
|
|
3012
|
-
handlers:
|
|
3061
|
+
match: In(e.match),
|
|
3062
|
+
handlers: Ln(e.handlers),
|
|
3013
3063
|
created_at: e.created_at,
|
|
3014
3064
|
updated_at: e.updated_at
|
|
3015
3065
|
};
|
|
3016
3066
|
}
|
|
3017
|
-
function
|
|
3067
|
+
function zn(e) {
|
|
3018
3068
|
return {
|
|
3019
3069
|
async create(t, n) {
|
|
3020
3070
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
@@ -3027,7 +3077,7 @@ function Pn(e) {
|
|
|
3027
3077
|
created_at: r,
|
|
3028
3078
|
updated_at: r
|
|
3029
3079
|
};
|
|
3030
|
-
return await e.insert(
|
|
3080
|
+
return await e.insert(X).values({
|
|
3031
3081
|
id: i.id,
|
|
3032
3082
|
tenant_id: i.tenant_id,
|
|
3033
3083
|
custom_domain_id: i.custom_domain_id,
|
|
@@ -3039,15 +3089,15 @@ function Pn(e) {
|
|
|
3039
3089
|
}), i;
|
|
3040
3090
|
},
|
|
3041
3091
|
async get(n, r) {
|
|
3042
|
-
let i = await e.select().from(
|
|
3043
|
-
return i[0] ?
|
|
3092
|
+
let i = await e.select().from(X).where(t(a(X.tenant_id, n), a(X.id, r))).limit(1);
|
|
3093
|
+
return i[0] ? Rn(i[0]) : null;
|
|
3044
3094
|
},
|
|
3045
3095
|
async list(r, i = {}) {
|
|
3046
|
-
let o = i.page ?? 0, s = i.per_page ?? 50, c = [a(
|
|
3047
|
-
i.custom_domain_id && c.push(a(
|
|
3048
|
-
let l = await e.select().from(
|
|
3096
|
+
let o = i.page ?? 0, s = i.per_page ?? 50, c = [a(X.tenant_id, r)];
|
|
3097
|
+
i.custom_domain_id && c.push(a(X.custom_domain_id, i.custom_domain_id));
|
|
3098
|
+
let l = await e.select().from(X).where(t(...c)).orderBy(n(X.priority), n(X.created_at)).offset(o * s).limit(s);
|
|
3049
3099
|
return {
|
|
3050
|
-
proxy_routes: l.map(
|
|
3100
|
+
proxy_routes: l.map(Rn),
|
|
3051
3101
|
start: o * s,
|
|
3052
3102
|
limit: s,
|
|
3053
3103
|
length: l.length
|
|
@@ -3056,17 +3106,174 @@ function Pn(e) {
|
|
|
3056
3106
|
async update(n, r, i) {
|
|
3057
3107
|
let o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
3058
3108
|
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));
|
|
3059
|
-
let s = (await e.update(
|
|
3060
|
-
return typeof s == "number" ? s > 0 : (await e.select({ id:
|
|
3109
|
+
let s = (await e.update(X).set(o).where(t(a(X.tenant_id, n), a(X.id, r))))?.changes;
|
|
3110
|
+
return typeof s == "number" ? s > 0 : (await e.select({ id: X.id }).from(X).where(t(a(X.tenant_id, n), a(X.id, r))).limit(1)).length > 0;
|
|
3111
|
+
},
|
|
3112
|
+
async remove(n, r) {
|
|
3113
|
+
return (await e.select({ id: X.id }).from(X).where(t(a(X.tenant_id, n), a(X.id, r))).limit(1)).length === 0 ? !1 : (await e.delete(X).where(t(a(X.tenant_id, n), a(X.id, r))), !0);
|
|
3114
|
+
}
|
|
3115
|
+
};
|
|
3116
|
+
}
|
|
3117
|
+
//#endregion
|
|
3118
|
+
//#region src/adapters/scim.ts
|
|
3119
|
+
function Bn(e) {
|
|
3120
|
+
if (!e) return [];
|
|
3121
|
+
try {
|
|
3122
|
+
let t = JSON.parse(e);
|
|
3123
|
+
if (!Array.isArray(t)) return [];
|
|
3124
|
+
let n = [];
|
|
3125
|
+
for (let e of t) {
|
|
3126
|
+
let t = ve.safeParse(e);
|
|
3127
|
+
t.success && n.push(t.data);
|
|
3128
|
+
}
|
|
3129
|
+
return n;
|
|
3130
|
+
} catch {
|
|
3131
|
+
return [];
|
|
3132
|
+
}
|
|
3133
|
+
}
|
|
3134
|
+
function Vn(e) {
|
|
3135
|
+
if (!e) return [];
|
|
3136
|
+
try {
|
|
3137
|
+
let t = JSON.parse(e);
|
|
3138
|
+
return Array.isArray(t) ? t.filter((e) => typeof e == "string") : [];
|
|
3139
|
+
} catch {
|
|
3140
|
+
return [];
|
|
3141
|
+
}
|
|
3142
|
+
}
|
|
3143
|
+
function Hn(e) {
|
|
3144
|
+
return {
|
|
3145
|
+
connection_id: e.connection_id,
|
|
3146
|
+
user_id_attribute: e.user_id_attribute,
|
|
3147
|
+
mapping: Bn(e.mapping),
|
|
3148
|
+
created_at: e.created_at,
|
|
3149
|
+
updated_at: e.updated_at
|
|
3150
|
+
};
|
|
3151
|
+
}
|
|
3152
|
+
function Un(e) {
|
|
3153
|
+
return {
|
|
3154
|
+
async create(t, n) {
|
|
3155
|
+
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
3156
|
+
connection_id: n.connection_id,
|
|
3157
|
+
user_id_attribute: n.user_id_attribute,
|
|
3158
|
+
mapping: n.mapping,
|
|
3159
|
+
created_at: r,
|
|
3160
|
+
updated_at: r
|
|
3161
|
+
};
|
|
3162
|
+
return await e.insert(Ye).values({
|
|
3163
|
+
connection_id: i.connection_id,
|
|
3164
|
+
tenant_id: t,
|
|
3165
|
+
user_id_attribute: i.user_id_attribute,
|
|
3166
|
+
mapping: JSON.stringify(i.mapping),
|
|
3167
|
+
created_at: r,
|
|
3168
|
+
updated_at: r
|
|
3169
|
+
}), i;
|
|
3170
|
+
},
|
|
3171
|
+
async get(n, r) {
|
|
3172
|
+
let i = await e.select().from(Ye).where(t(a(Ye.tenant_id, n), a(Ye.connection_id, r))).limit(1);
|
|
3173
|
+
return i[0] ? Hn(i[0]) : null;
|
|
3174
|
+
},
|
|
3175
|
+
async update(n, r, i) {
|
|
3176
|
+
if ((await e.select({ connection_id: Ye.connection_id }).from(Ye).where(t(a(Ye.tenant_id, n), a(Ye.connection_id, r))).limit(1)).length === 0) return !1;
|
|
3177
|
+
let o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
3178
|
+
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(Ye).set(o).where(t(a(Ye.tenant_id, n), a(Ye.connection_id, r))), !0;
|
|
3179
|
+
},
|
|
3180
|
+
async remove(n, r) {
|
|
3181
|
+
return (await e.select({ connection_id: Ye.connection_id }).from(Ye).where(t(a(Ye.tenant_id, n), a(Ye.connection_id, r))).limit(1)).length === 0 ? !1 : (await e.delete(Ye).where(t(a(Ye.tenant_id, n), a(Ye.connection_id, r))), !0);
|
|
3182
|
+
}
|
|
3183
|
+
};
|
|
3184
|
+
}
|
|
3185
|
+
function Wn(e) {
|
|
3186
|
+
return {
|
|
3187
|
+
token_id: e.token_id,
|
|
3188
|
+
connection_id: e.connection_id,
|
|
3189
|
+
token_hash: e.token_hash,
|
|
3190
|
+
scopes: Vn(e.scopes),
|
|
3191
|
+
valid_until: e.valid_until ?? void 0,
|
|
3192
|
+
created_at: e.created_at,
|
|
3193
|
+
last_used_at: e.last_used_at ?? void 0
|
|
3194
|
+
};
|
|
3195
|
+
}
|
|
3196
|
+
function Gn(e) {
|
|
3197
|
+
return {
|
|
3198
|
+
async create(t, n) {
|
|
3199
|
+
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
3200
|
+
token_id: n.token_id,
|
|
3201
|
+
connection_id: n.connection_id,
|
|
3202
|
+
token_hash: n.token_hash,
|
|
3203
|
+
scopes: n.scopes,
|
|
3204
|
+
valid_until: n.valid_until,
|
|
3205
|
+
created_at: r
|
|
3206
|
+
};
|
|
3207
|
+
return await e.insert(Z).values({
|
|
3208
|
+
token_id: i.token_id,
|
|
3209
|
+
tenant_id: t,
|
|
3210
|
+
connection_id: i.connection_id,
|
|
3211
|
+
token_hash: i.token_hash,
|
|
3212
|
+
scopes: JSON.stringify(i.scopes),
|
|
3213
|
+
valid_until: i.valid_until,
|
|
3214
|
+
created_at: r
|
|
3215
|
+
}), i;
|
|
3216
|
+
},
|
|
3217
|
+
async get(n, r) {
|
|
3218
|
+
let i = await e.select().from(Z).where(t(a(Z.tenant_id, n), a(Z.token_id, r))).limit(1);
|
|
3219
|
+
return i[0] ? Wn(i[0]) : null;
|
|
3220
|
+
},
|
|
3221
|
+
async getByHash(n, r) {
|
|
3222
|
+
let i = await e.select().from(Z).where(t(a(Z.tenant_id, n), a(Z.token_hash, r))).limit(1);
|
|
3223
|
+
return i[0] ? Wn(i[0]) : null;
|
|
3224
|
+
},
|
|
3225
|
+
async listByConnection(n, r) {
|
|
3226
|
+
return (await e.select().from(Z).where(t(a(Z.tenant_id, n), a(Z.connection_id, r)))).map(Wn);
|
|
3227
|
+
},
|
|
3228
|
+
async markUsed(n, r, i) {
|
|
3229
|
+
return (await e.select({ token_id: Z.token_id }).from(Z).where(t(a(Z.tenant_id, n), a(Z.token_id, r))).limit(1)).length === 0 ? !1 : (await e.update(Z).set({ last_used_at: i }).where(t(a(Z.tenant_id, n), a(Z.token_id, r))), !0);
|
|
3061
3230
|
},
|
|
3062
3231
|
async remove(n, r) {
|
|
3063
|
-
return (await e.select({
|
|
3232
|
+
return (await e.select({ token_id: Z.token_id }).from(Z).where(t(a(Z.tenant_id, n), a(Z.token_id, r))).limit(1)).length === 0 ? !1 : (await e.delete(Z).where(t(a(Z.tenant_id, n), a(Z.token_id, r))), !0);
|
|
3233
|
+
}
|
|
3234
|
+
};
|
|
3235
|
+
}
|
|
3236
|
+
function Kn(e) {
|
|
3237
|
+
return {
|
|
3238
|
+
connection_id: e.connection_id,
|
|
3239
|
+
external_id: e.external_id,
|
|
3240
|
+
user_id: e.user_id,
|
|
3241
|
+
created_at: e.created_at
|
|
3242
|
+
};
|
|
3243
|
+
}
|
|
3244
|
+
function qn(e) {
|
|
3245
|
+
return {
|
|
3246
|
+
async create(t, n) {
|
|
3247
|
+
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
3248
|
+
connection_id: n.connection_id,
|
|
3249
|
+
external_id: n.external_id,
|
|
3250
|
+
user_id: n.user_id,
|
|
3251
|
+
created_at: r
|
|
3252
|
+
};
|
|
3253
|
+
return await e.insert(Xe).values({
|
|
3254
|
+
tenant_id: t,
|
|
3255
|
+
connection_id: i.connection_id,
|
|
3256
|
+
external_id: i.external_id,
|
|
3257
|
+
user_id: i.user_id,
|
|
3258
|
+
created_at: r
|
|
3259
|
+
}), i;
|
|
3260
|
+
},
|
|
3261
|
+
async getByExternalId(n, r, i) {
|
|
3262
|
+
let o = await e.select().from(Xe).where(t(a(Xe.tenant_id, n), a(Xe.connection_id, r), a(Xe.external_id, i))).limit(1);
|
|
3263
|
+
return o[0] ? Kn(o[0]) : null;
|
|
3264
|
+
},
|
|
3265
|
+
async getByUserId(n, r, i) {
|
|
3266
|
+
let o = await e.select().from(Xe).where(t(a(Xe.tenant_id, n), a(Xe.connection_id, r), a(Xe.user_id, i))).limit(1);
|
|
3267
|
+
return o[0] ? Kn(o[0]) : null;
|
|
3268
|
+
},
|
|
3269
|
+
async remove(n, r, i) {
|
|
3270
|
+
return (await e.select({ user_id: Xe.user_id }).from(Xe).where(t(a(Xe.tenant_id, n), a(Xe.connection_id, r), a(Xe.user_id, i))).limit(1)).length === 0 ? !1 : (await e.delete(Xe).where(t(a(Xe.tenant_id, n), a(Xe.connection_id, r), a(Xe.user_id, i))), !0);
|
|
3064
3271
|
}
|
|
3065
3272
|
};
|
|
3066
3273
|
}
|
|
3067
3274
|
//#endregion
|
|
3068
3275
|
//#region src/adapters/refreshTokens.ts
|
|
3069
|
-
function
|
|
3276
|
+
function Jn(e) {
|
|
3070
3277
|
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, ...d } = e, f = ie({
|
|
3071
3278
|
created_at_ts: n,
|
|
3072
3279
|
expires_at_ts: r,
|
|
@@ -3089,10 +3296,10 @@ function Fn(e) {
|
|
|
3089
3296
|
resource_servers: Q(l, [])
|
|
3090
3297
|
});
|
|
3091
3298
|
}
|
|
3092
|
-
function
|
|
3299
|
+
function Yn(e, t) {
|
|
3093
3300
|
return Math.max(e ?? 0, t ?? 0);
|
|
3094
3301
|
}
|
|
3095
|
-
function
|
|
3302
|
+
function Xn(e) {
|
|
3096
3303
|
return {
|
|
3097
3304
|
async create(n, r) {
|
|
3098
3305
|
let i = Date.now(), o = {
|
|
@@ -3113,22 +3320,22 @@ function Ln(e) {
|
|
|
3113
3320
|
expires_at_ts: D(r.expires_at),
|
|
3114
3321
|
idle_expires_at_ts: D(r.idle_expires_at),
|
|
3115
3322
|
last_exchanged_at_ts: D(r.last_exchanged_at)
|
|
3116
|
-
}, s = [e.insert(P).values(o)], c =
|
|
3323
|
+
}, s = [e.insert(P).values(o)], c = Yn(o.expires_at_ts, o.idle_expires_at_ts);
|
|
3117
3324
|
return c > 0 && o.login_id && s.push(e.update(F).set({
|
|
3118
3325
|
expires_at_ts: c,
|
|
3119
3326
|
updated_at_ts: i
|
|
3120
|
-
}).where(t(a(F.tenant_id, n), a(F.id, o.login_id), m(F.expires_at_ts, c)))), await
|
|
3327
|
+
}).where(t(a(F.tenant_id, n), a(F.id, o.login_id), m(F.expires_at_ts, c)))), await lt(e, s), Jn({
|
|
3121
3328
|
...o,
|
|
3122
3329
|
tenant_id: n
|
|
3123
3330
|
});
|
|
3124
3331
|
},
|
|
3125
3332
|
async get(n, r) {
|
|
3126
3333
|
let i = await e.select().from(P).where(t(a(P.tenant_id, n), a(P.id, r))).get();
|
|
3127
|
-
return i ?
|
|
3334
|
+
return i ? Jn(i) : null;
|
|
3128
3335
|
},
|
|
3129
3336
|
async getByLookup(n, r) {
|
|
3130
3337
|
let i = await e.select().from(P).where(t(a(P.tenant_id, n), a(P.token_lookup, r))).get();
|
|
3131
|
-
return i ?
|
|
3338
|
+
return i ? Jn(i) : null;
|
|
3132
3339
|
},
|
|
3133
3340
|
async update(n, r, i, o) {
|
|
3134
3341
|
let s = {};
|
|
@@ -3142,14 +3349,14 @@ function Ln(e) {
|
|
|
3142
3349
|
async list(o, s) {
|
|
3143
3350
|
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = e.select().from(P).where(a(P.tenant_id, o)).$dynamic();
|
|
3144
3351
|
if (f) {
|
|
3145
|
-
let e =
|
|
3352
|
+
let e = nt(P, f, ["user_id", "login_id"]);
|
|
3146
3353
|
e && (p = p.where(t(a(P.tenant_id, o), e)));
|
|
3147
3354
|
}
|
|
3148
3355
|
if (d?.sort_by) {
|
|
3149
3356
|
let e = P[d.sort_by];
|
|
3150
3357
|
e && (p = p.orderBy(d.sort_order === "desc" ? i(e) : n(e)));
|
|
3151
3358
|
}
|
|
3152
|
-
let m = (await p.offset(c * l).limit(l)).map(
|
|
3359
|
+
let m = (await p.offset(c * l).limit(l)).map(Jn);
|
|
3153
3360
|
if (!u) return { refresh_tokens: m };
|
|
3154
3361
|
let [h] = await e.select({ count: r() }).from(P).where(a(P.tenant_id, o));
|
|
3155
3362
|
return {
|
|
@@ -3172,15 +3379,15 @@ function Ln(e) {
|
|
|
3172
3379
|
}
|
|
3173
3380
|
//#endregion
|
|
3174
3381
|
//#region src/adapters/resourceServers.ts
|
|
3175
|
-
var
|
|
3176
|
-
function
|
|
3382
|
+
var Zn = ["name", "identifier"];
|
|
3383
|
+
function Qn() {
|
|
3177
3384
|
return `api_${ee("0123456789abcdefghijklmnopqrstuvwxyz", 17)()}`;
|
|
3178
3385
|
}
|
|
3179
|
-
var
|
|
3386
|
+
var $n = [
|
|
3180
3387
|
"skip_consent_for_verifiable_first_party_clients",
|
|
3181
3388
|
"allow_offline_access",
|
|
3182
3389
|
"is_system"
|
|
3183
|
-
],
|
|
3390
|
+
], er = new Set([
|
|
3184
3391
|
"id",
|
|
3185
3392
|
"tenant_id",
|
|
3186
3393
|
"identifier",
|
|
@@ -3199,17 +3406,17 @@ var Bn = [
|
|
|
3199
3406
|
"created_at",
|
|
3200
3407
|
"updated_at"
|
|
3201
3408
|
]);
|
|
3202
|
-
function
|
|
3409
|
+
function tr(e) {
|
|
3203
3410
|
let { tenant_id: t, verification_key: n, scopes: r, options: i, metadata: a, ...o } = e, s = { ...o };
|
|
3204
3411
|
s.scopes = Q(r, []), s.options = Q(i, {}), s.metadata = Q(a), n !== void 0 && (s.verificationKey = n);
|
|
3205
|
-
for (let e of
|
|
3412
|
+
for (let e of $n) o[e] !== void 0 && o[e] !== null && (s[e] = !!o[e]);
|
|
3206
3413
|
return O(s);
|
|
3207
3414
|
}
|
|
3208
|
-
function
|
|
3415
|
+
function nr(e) {
|
|
3209
3416
|
return {
|
|
3210
3417
|
async create(t, n) {
|
|
3211
3418
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
3212
|
-
id: n.id ||
|
|
3419
|
+
id: n.id || Qn(),
|
|
3213
3420
|
tenant_id: t,
|
|
3214
3421
|
identifier: n.identifier,
|
|
3215
3422
|
name: n.name,
|
|
@@ -3224,39 +3431,39 @@ function Un(e) {
|
|
|
3224
3431
|
created_at: r,
|
|
3225
3432
|
updated_at: r
|
|
3226
3433
|
};
|
|
3227
|
-
for (let e of
|
|
3228
|
-
return i.is_system === void 0 && (i.is_system = 0), await e.insert(
|
|
3434
|
+
for (let e of $n) n[e] !== void 0 && (i[e] = +!!n[e]);
|
|
3435
|
+
return i.is_system === void 0 && (i.is_system = 0), await e.insert(K).values(i), tr({
|
|
3229
3436
|
...i,
|
|
3230
3437
|
tenant_id: t
|
|
3231
3438
|
});
|
|
3232
3439
|
},
|
|
3233
3440
|
async get(n, r) {
|
|
3234
|
-
let i = await e.select().from(
|
|
3235
|
-
return i ?
|
|
3441
|
+
let i = await e.select().from(K).where(t(a(K.tenant_id, n), a(K.id, r))).get();
|
|
3442
|
+
return i ? tr(i) : null;
|
|
3236
3443
|
},
|
|
3237
3444
|
async update(n, r, i) {
|
|
3238
3445
|
let o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
3239
|
-
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(${
|
|
3240
|
-
for (let e of
|
|
3241
|
-
return (await e.update(
|
|
3446
|
+
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(${K.options}, '{}'), ${JSON.stringify(i.options)})`), i.metadata !== void 0 && (o.metadata = JSON.stringify(i.metadata)), i.verificationKey !== void 0 && (o.verification_key = i.verificationKey);
|
|
3447
|
+
for (let e of $n) i[e] !== void 0 && (o[e] = +!!i[e]);
|
|
3448
|
+
return (await e.update(K).set(o).where(t(a(K.tenant_id, n), a(K.id, r))).returning()).length > 0;
|
|
3242
3449
|
},
|
|
3243
3450
|
async list(o, s) {
|
|
3244
|
-
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(
|
|
3451
|
+
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(K.tenant_id, o)];
|
|
3245
3452
|
if (f) {
|
|
3246
|
-
let e = _e(f,
|
|
3453
|
+
let e = _e(f, Zn);
|
|
3247
3454
|
if (e) {
|
|
3248
|
-
let t =
|
|
3455
|
+
let t = nt(K, e, Zn, ["name", "identifier"]);
|
|
3249
3456
|
t && h.push(t);
|
|
3250
3457
|
}
|
|
3251
3458
|
}
|
|
3252
|
-
let g = e.select().from(
|
|
3253
|
-
if (d?.sort_by &&
|
|
3254
|
-
let e =
|
|
3459
|
+
let g = e.select().from(K).where(t(...h)).$dynamic();
|
|
3460
|
+
if (d?.sort_by && er.has(d.sort_by)) {
|
|
3461
|
+
let e = K[d.sort_by];
|
|
3255
3462
|
g = g.orderBy(d.sort_order === "desc" ? i(e) : n(e));
|
|
3256
3463
|
}
|
|
3257
|
-
let _ = (await g.offset(p * m).limit(m)).map(
|
|
3464
|
+
let _ = (await g.offset(p * m).limit(m)).map(tr);
|
|
3258
3465
|
if (!u) return { resource_servers: _ };
|
|
3259
|
-
let [v] = await e.select({ count: r() }).from(
|
|
3466
|
+
let [v] = await e.select({ count: r() }).from(K).where(t(...h));
|
|
3260
3467
|
return {
|
|
3261
3468
|
resource_servers: _,
|
|
3262
3469
|
start: p * m,
|
|
@@ -3265,17 +3472,17 @@ function Un(e) {
|
|
|
3265
3472
|
};
|
|
3266
3473
|
},
|
|
3267
3474
|
async remove(n, r) {
|
|
3268
|
-
return (await e.delete(
|
|
3475
|
+
return (await e.delete(K).where(t(a(K.tenant_id, n), a(K.id, r))).returning()).length > 0;
|
|
3269
3476
|
}
|
|
3270
3477
|
};
|
|
3271
3478
|
}
|
|
3272
3479
|
//#endregion
|
|
3273
3480
|
//#region src/adapters/rolePermissions.ts
|
|
3274
|
-
function
|
|
3481
|
+
function rr(e) {
|
|
3275
3482
|
return {
|
|
3276
3483
|
async assign(t, n, r) {
|
|
3277
3484
|
let i = (/* @__PURE__ */ new Date()).toISOString();
|
|
3278
|
-
return await e.insert(
|
|
3485
|
+
return await e.insert(Fe).values(r.map((e) => ({
|
|
3279
3486
|
tenant_id: t,
|
|
3280
3487
|
role_id: n,
|
|
3281
3488
|
resource_server_identifier: e.resource_server_identifier,
|
|
@@ -3285,15 +3492,15 @@ function Wn(e) {
|
|
|
3285
3492
|
},
|
|
3286
3493
|
async list(n, r, i) {
|
|
3287
3494
|
let o = await e.select({
|
|
3288
|
-
resource_server_identifier:
|
|
3289
|
-
permission_name:
|
|
3290
|
-
created_at:
|
|
3291
|
-
}).from(
|
|
3495
|
+
resource_server_identifier: Fe.resource_server_identifier,
|
|
3496
|
+
permission_name: Fe.permission_name,
|
|
3497
|
+
created_at: Fe.created_at
|
|
3498
|
+
}).from(Fe).where(t(a(Fe.tenant_id, n), a(Fe.role_id, r))).all(), s = [...new Set(o.map((e) => e.resource_server_identifier))], c = /* @__PURE__ */ new Map();
|
|
3292
3499
|
if (s.length > 0) {
|
|
3293
3500
|
let r = await e.select({
|
|
3294
|
-
identifier:
|
|
3295
|
-
name:
|
|
3296
|
-
}).from(
|
|
3501
|
+
identifier: K.identifier,
|
|
3502
|
+
name: K.name
|
|
3503
|
+
}).from(K).where(t(a(K.tenant_id, n), l(K.identifier, s))).all();
|
|
3297
3504
|
for (let e of r) c.set(e.identifier, e.name);
|
|
3298
3505
|
}
|
|
3299
3506
|
return o.map((e) => ({
|
|
@@ -3302,18 +3509,18 @@ function Wn(e) {
|
|
|
3302
3509
|
}));
|
|
3303
3510
|
},
|
|
3304
3511
|
async remove(n, r, i) {
|
|
3305
|
-
let o = i.map((e) => t(a(
|
|
3306
|
-
return (await e.delete(
|
|
3512
|
+
let o = i.map((e) => t(a(Fe.resource_server_identifier, e.resource_server_identifier), a(Fe.permission_name, e.permission_name)));
|
|
3513
|
+
return (await e.delete(Fe).where(t(a(Fe.tenant_id, n), a(Fe.role_id, r), v(...o))).returning()).length > 0;
|
|
3307
3514
|
}
|
|
3308
3515
|
};
|
|
3309
3516
|
}
|
|
3310
3517
|
//#endregion
|
|
3311
3518
|
//#region src/adapters/userPermissions.ts
|
|
3312
|
-
function
|
|
3519
|
+
function ir(e) {
|
|
3313
3520
|
return {
|
|
3314
3521
|
async create(t, n, r, i) {
|
|
3315
3522
|
try {
|
|
3316
|
-
await e.insert(
|
|
3523
|
+
await e.insert(Ie).values({
|
|
3317
3524
|
tenant_id: t,
|
|
3318
3525
|
user_id: n,
|
|
3319
3526
|
resource_server_identifier: r.resource_server_identifier,
|
|
@@ -3328,11 +3535,11 @@ function Gn(e) {
|
|
|
3328
3535
|
return !0;
|
|
3329
3536
|
},
|
|
3330
3537
|
async list(n, r, i, o) {
|
|
3331
|
-
let s = [a(
|
|
3332
|
-
o && s.push(a(
|
|
3333
|
-
let c = await e.select().from(
|
|
3538
|
+
let s = [a(Ie.tenant_id, n), a(Ie.user_id, r)];
|
|
3539
|
+
o && s.push(a(Ie.organization_id, o));
|
|
3540
|
+
let c = await e.select().from(Ie).where(t(...s)).all();
|
|
3334
3541
|
return await Promise.all(c.map(async (r) => {
|
|
3335
|
-
let i = await e.select({ name:
|
|
3542
|
+
let i = await e.select({ name: K.name }).from(K).where(t(a(K.tenant_id, n), a(K.identifier, r.resource_server_identifier))).get();
|
|
3336
3543
|
return {
|
|
3337
3544
|
resource_server_identifier: r.resource_server_identifier,
|
|
3338
3545
|
permission_name: r.permission_name,
|
|
@@ -3342,13 +3549,13 @@ function Gn(e) {
|
|
|
3342
3549
|
}));
|
|
3343
3550
|
},
|
|
3344
3551
|
async remove(n, r, i, o) {
|
|
3345
|
-
return (await e.delete(
|
|
3552
|
+
return (await e.delete(Ie).where(t(a(Ie.tenant_id, n), a(Ie.user_id, r), a(Ie.resource_server_identifier, i.resource_server_identifier), a(Ie.permission_name, i.permission_name), a(Ie.organization_id, o || ""))).returning()).length > 0;
|
|
3346
3553
|
}
|
|
3347
3554
|
};
|
|
3348
3555
|
}
|
|
3349
3556
|
//#endregion
|
|
3350
3557
|
//#region src/adapters/roles.ts
|
|
3351
|
-
function
|
|
3558
|
+
function ar(e) {
|
|
3352
3559
|
let { tenant_id: t, is_system: n, metadata: r, ...i } = e;
|
|
3353
3560
|
return O({
|
|
3354
3561
|
...i,
|
|
@@ -3356,7 +3563,7 @@ function Kn(e) {
|
|
|
3356
3563
|
metadata: Q(r)
|
|
3357
3564
|
});
|
|
3358
3565
|
}
|
|
3359
|
-
function
|
|
3566
|
+
function or(e) {
|
|
3360
3567
|
return {
|
|
3361
3568
|
async create(t, n) {
|
|
3362
3569
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
@@ -3369,28 +3576,28 @@ function qn(e) {
|
|
|
3369
3576
|
created_at: r,
|
|
3370
3577
|
updated_at: r
|
|
3371
3578
|
};
|
|
3372
|
-
return await e.insert(
|
|
3579
|
+
return await e.insert(W).values(i), ar({
|
|
3373
3580
|
...i,
|
|
3374
3581
|
tenant_id: t
|
|
3375
3582
|
});
|
|
3376
3583
|
},
|
|
3377
3584
|
async get(n, r) {
|
|
3378
|
-
let i = await e.select().from(
|
|
3379
|
-
return i ?
|
|
3585
|
+
let i = await e.select().from(W).where(t(a(W.tenant_id, n), a(W.id, r))).get();
|
|
3586
|
+
return i ? ar(i) : null;
|
|
3380
3587
|
},
|
|
3381
3588
|
async update(n, r, i) {
|
|
3382
3589
|
let o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
3383
|
-
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(
|
|
3590
|
+
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(W).set(o).where(t(a(W.tenant_id, n), a(W.id, r))).returning()).length > 0;
|
|
3384
3591
|
},
|
|
3385
3592
|
async list(o, s) {
|
|
3386
|
-
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ?
|
|
3593
|
+
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ? nt(W, f, ["name"]) : void 0, m = p ? t(a(W.tenant_id, o), p) : a(W.tenant_id, o), h = e.select().from(W).where(m).$dynamic();
|
|
3387
3594
|
if (d?.sort_by) {
|
|
3388
|
-
let e =
|
|
3595
|
+
let e = W[d.sort_by];
|
|
3389
3596
|
e && (h = h.orderBy(d.sort_order === "desc" ? i(e) : n(e)));
|
|
3390
3597
|
}
|
|
3391
|
-
let g = (await h.offset(c * l).limit(l)).map(
|
|
3598
|
+
let g = (await h.offset(c * l).limit(l)).map(ar);
|
|
3392
3599
|
if (!u) return { roles: g };
|
|
3393
|
-
let [_] = await e.select({ count: r() }).from(
|
|
3600
|
+
let [_] = await e.select({ count: r() }).from(W).where(m);
|
|
3394
3601
|
return {
|
|
3395
3602
|
roles: g,
|
|
3396
3603
|
start: c * l,
|
|
@@ -3399,13 +3606,13 @@ function qn(e) {
|
|
|
3399
3606
|
};
|
|
3400
3607
|
},
|
|
3401
3608
|
async remove(n, r) {
|
|
3402
|
-
return (await e.delete(
|
|
3609
|
+
return (await e.delete(W).where(t(a(W.tenant_id, n), a(W.id, r))).returning()).length > 0;
|
|
3403
3610
|
}
|
|
3404
3611
|
};
|
|
3405
3612
|
}
|
|
3406
3613
|
//#endregion
|
|
3407
3614
|
//#region src/adapters/sessions.ts
|
|
3408
|
-
var
|
|
3615
|
+
var sr = ["created_at_ts", "updated_at_ts"], cr = [
|
|
3409
3616
|
"expires_at_ts",
|
|
3410
3617
|
"idle_expires_at_ts",
|
|
3411
3618
|
"authenticated_at_ts",
|
|
@@ -3413,7 +3620,7 @@ var Jn = ["created_at_ts", "updated_at_ts"], Yn = [
|
|
|
3413
3620
|
"used_at_ts",
|
|
3414
3621
|
"revoked_at_ts"
|
|
3415
3622
|
];
|
|
3416
|
-
function
|
|
3623
|
+
function lr(e) {
|
|
3417
3624
|
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 = ie({
|
|
3418
3625
|
created_at_ts: n,
|
|
3419
3626
|
updated_at_ts: r,
|
|
@@ -3423,7 +3630,7 @@ function Xn(e) {
|
|
|
3423
3630
|
last_interaction_at_ts: s,
|
|
3424
3631
|
used_at_ts: c,
|
|
3425
3632
|
revoked_at_ts: l
|
|
3426
|
-
}, [...
|
|
3633
|
+
}, [...sr], [...cr]);
|
|
3427
3634
|
return O({
|
|
3428
3635
|
...f,
|
|
3429
3636
|
...p,
|
|
@@ -3431,10 +3638,10 @@ function Xn(e) {
|
|
|
3431
3638
|
clients: Q(d, [])
|
|
3432
3639
|
});
|
|
3433
3640
|
}
|
|
3434
|
-
function
|
|
3641
|
+
function ur(e, t) {
|
|
3435
3642
|
return Math.max(e ?? 0, t ?? 0);
|
|
3436
3643
|
}
|
|
3437
|
-
function
|
|
3644
|
+
function dr(e) {
|
|
3438
3645
|
return {
|
|
3439
3646
|
async create(n, r) {
|
|
3440
3647
|
let i = Date.now(), o = {
|
|
@@ -3452,23 +3659,23 @@ function Qn(e) {
|
|
|
3452
3659
|
last_interaction_at_ts: r.last_interaction_at ? D(r.last_interaction_at) : i,
|
|
3453
3660
|
used_at_ts: D(r.used_at),
|
|
3454
3661
|
revoked_at_ts: D(r.revoked_at)
|
|
3455
|
-
}, s = [e.insert(N).values(o)], c =
|
|
3662
|
+
}, s = [e.insert(N).values(o)], c = ur(o.expires_at_ts, o.idle_expires_at_ts);
|
|
3456
3663
|
return c > 0 && o.login_session_id && s.push(e.update(F).set({
|
|
3457
3664
|
expires_at_ts: c,
|
|
3458
3665
|
updated_at_ts: i
|
|
3459
|
-
}).where(t(a(F.tenant_id, n), a(F.id, o.login_session_id), m(F.expires_at_ts, c)))), await
|
|
3666
|
+
}).where(t(a(F.tenant_id, n), a(F.id, o.login_session_id), m(F.expires_at_ts, c)))), await lt(e, s), lr({
|
|
3460
3667
|
...o,
|
|
3461
3668
|
tenant_id: n
|
|
3462
3669
|
});
|
|
3463
3670
|
},
|
|
3464
3671
|
async get(n, r) {
|
|
3465
3672
|
let i = await e.select().from(N).where(t(a(N.tenant_id, n), a(N.id, r))).get();
|
|
3466
|
-
return i ?
|
|
3673
|
+
return i ? lr(i) : null;
|
|
3467
3674
|
},
|
|
3468
3675
|
async update(n, r, i) {
|
|
3469
3676
|
let o = { updated_at_ts: Date.now() };
|
|
3470
3677
|
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 = D(i.expires_at)), i.idle_expires_at !== void 0 && (o.idle_expires_at_ts = D(i.idle_expires_at)), i.authenticated_at !== void 0 && (o.authenticated_at_ts = D(i.authenticated_at)), i.last_interaction_at !== void 0 && (o.last_interaction_at_ts = D(i.last_interaction_at)), i.used_at !== void 0 && (o.used_at_ts = D(i.used_at)), i.revoked_at !== void 0 && (o.revoked_at_ts = D(i.revoked_at));
|
|
3471
|
-
let s = await e.update(N).set(o).where(t(a(N.tenant_id, n), a(N.id, r))).returning(), c =
|
|
3678
|
+
let s = await e.update(N).set(o).where(t(a(N.tenant_id, n), a(N.id, r))).returning(), c = ur(o.expires_at_ts, o.idle_expires_at_ts), l = s[0];
|
|
3472
3679
|
if (c > 0 && l) {
|
|
3473
3680
|
let r = i.login_session_id ?? l.login_session_id;
|
|
3474
3681
|
r && await e.update(F).set({
|
|
@@ -3479,12 +3686,12 @@ function Qn(e) {
|
|
|
3479
3686
|
return s.length > 0;
|
|
3480
3687
|
},
|
|
3481
3688
|
async list(o, s) {
|
|
3482
|
-
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ?
|
|
3689
|
+
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ? nt(N, f, ["user_id", "id"]) : void 0, m = p ? t(a(N.tenant_id, o), p) : a(N.tenant_id, o), h = e.select().from(N).where(m).$dynamic();
|
|
3483
3690
|
if (d?.sort_by) {
|
|
3484
3691
|
let e = N[d.sort_by];
|
|
3485
3692
|
e && (h = h.orderBy(d.sort_order === "desc" ? i(e) : n(e)));
|
|
3486
3693
|
}
|
|
3487
|
-
let g = (await h.offset(c * l).limit(l)).map(
|
|
3694
|
+
let g = (await h.offset(c * l).limit(l)).map(lr);
|
|
3488
3695
|
if (!u) return { sessions: g };
|
|
3489
3696
|
let [_] = await e.select({ count: r() }).from(N).where(m);
|
|
3490
3697
|
return {
|
|
@@ -3501,7 +3708,7 @@ function Qn(e) {
|
|
|
3501
3708
|
}
|
|
3502
3709
|
//#endregion
|
|
3503
3710
|
//#region src/adapters/tenants.ts
|
|
3504
|
-
var
|
|
3711
|
+
var fr = [
|
|
3505
3712
|
"session_cookie",
|
|
3506
3713
|
"enabled_locales",
|
|
3507
3714
|
"error_page",
|
|
@@ -3517,25 +3724,25 @@ var $n = [
|
|
|
3517
3724
|
"acr_values_supported",
|
|
3518
3725
|
"mtls",
|
|
3519
3726
|
"mfa"
|
|
3520
|
-
],
|
|
3727
|
+
], pr = [
|
|
3521
3728
|
"allow_organization_name_in_authentication_api",
|
|
3522
3729
|
"customize_mfa_in_postlogin_action",
|
|
3523
3730
|
"pushed_authorization_requests_supported",
|
|
3524
3731
|
"authorization_response_iss_parameter_supported"
|
|
3525
3732
|
];
|
|
3526
|
-
function
|
|
3733
|
+
function mr(e) {
|
|
3527
3734
|
let t = { ...e };
|
|
3528
|
-
for (let e of
|
|
3529
|
-
for (let e of
|
|
3735
|
+
for (let e of fr) typeof t[e] == "string" && (t[e] = Q(t[e]));
|
|
3736
|
+
for (let e of pr) t[e] !== void 0 && t[e] !== null && (t[e] = t[e] === 1);
|
|
3530
3737
|
return O(t);
|
|
3531
3738
|
}
|
|
3532
|
-
function
|
|
3739
|
+
function hr(e) {
|
|
3533
3740
|
let t = { ...e };
|
|
3534
|
-
ce(e,
|
|
3535
|
-
for (let n of
|
|
3741
|
+
ce(e, fr, t);
|
|
3742
|
+
for (let n of pr) e[n] !== void 0 && (t[n] = +!!e[n]);
|
|
3536
3743
|
return se(t);
|
|
3537
3744
|
}
|
|
3538
|
-
function
|
|
3745
|
+
function gr(e) {
|
|
3539
3746
|
return {
|
|
3540
3747
|
async create(t) {
|
|
3541
3748
|
let n = {
|
|
@@ -3543,26 +3750,26 @@ function rr(e) {
|
|
|
3543
3750
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3544
3751
|
updated_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3545
3752
|
...t
|
|
3546
|
-
}, r =
|
|
3753
|
+
}, r = hr(n);
|
|
3547
3754
|
try {
|
|
3548
3755
|
await e.insert(k).values(r);
|
|
3549
3756
|
} catch (e) {
|
|
3550
3757
|
let t = e?.message ?? "";
|
|
3551
|
-
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
|
|
3758
|
+
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 Ce(409, { message: `Tenant with ID '${n.id}' already exists` }) : e;
|
|
3552
3759
|
}
|
|
3553
3760
|
return n;
|
|
3554
3761
|
},
|
|
3555
3762
|
async get(t) {
|
|
3556
3763
|
let n = await e.select().from(k).where(a(k.id, t)).get();
|
|
3557
|
-
return n ?
|
|
3764
|
+
return n ? mr(n) : null;
|
|
3558
3765
|
},
|
|
3559
3766
|
async list(t) {
|
|
3560
|
-
let { page: a = 0, per_page: o = 50, include_totals: s = !1, sort: c, q: l } = t || {}, u = l ?
|
|
3767
|
+
let { page: a = 0, per_page: o = 50, include_totals: s = !1, sort: c, q: l } = t || {}, u = l ? nt(k, l, ["friendly_name"]) : void 0, d = e.select().from(k).$dynamic();
|
|
3561
3768
|
if (u && (d = d.where(u)), c?.sort_by) {
|
|
3562
3769
|
let e = k[c.sort_by];
|
|
3563
3770
|
e && (d = d.orderBy(c.sort_order === "desc" ? i(e) : n(e)));
|
|
3564
3771
|
}
|
|
3565
|
-
let f = (await d.offset(a * o).limit(o)).map(
|
|
3772
|
+
let f = (await d.offset(a * o).limit(o)).map(mr);
|
|
3566
3773
|
if (!s) return { tenants: f };
|
|
3567
3774
|
let p = e.select({ count: r() }).from(k).$dynamic();
|
|
3568
3775
|
u && (p = p.where(u));
|
|
@@ -3575,7 +3782,7 @@ function rr(e) {
|
|
|
3575
3782
|
};
|
|
3576
3783
|
},
|
|
3577
3784
|
async update(t, n) {
|
|
3578
|
-
let r =
|
|
3785
|
+
let r = hr({
|
|
3579
3786
|
...n,
|
|
3580
3787
|
id: t,
|
|
3581
3788
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
@@ -3589,62 +3796,62 @@ function rr(e) {
|
|
|
3589
3796
|
}
|
|
3590
3797
|
//#endregion
|
|
3591
3798
|
//#region src/adapters/themes.ts
|
|
3592
|
-
var
|
|
3799
|
+
var _r = [
|
|
3593
3800
|
"colors",
|
|
3594
3801
|
"borders",
|
|
3595
3802
|
"fonts",
|
|
3596
3803
|
"page_background",
|
|
3597
3804
|
"widget"
|
|
3598
3805
|
];
|
|
3599
|
-
function
|
|
3600
|
-
let { tenant_id: t, ...n } = e, r =
|
|
3806
|
+
function vr(e) {
|
|
3807
|
+
let { tenant_id: t, ...n } = e, r = $e(n, _r);
|
|
3601
3808
|
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), O(r);
|
|
3602
3809
|
}
|
|
3603
|
-
function
|
|
3810
|
+
function yr(e) {
|
|
3604
3811
|
return {
|
|
3605
3812
|
async create(t, n, r, i) {
|
|
3606
3813
|
let a = i?.importMetadata, o = (/* @__PURE__ */ new Date()).toISOString(), s = a?.id || r || b(), c = {
|
|
3607
|
-
...
|
|
3814
|
+
...Qe(n),
|
|
3608
3815
|
tenant_id: t,
|
|
3609
3816
|
themeId: s,
|
|
3610
3817
|
created_at: a?.created_at ?? o,
|
|
3611
3818
|
updated_at: a?.updated_at ?? o
|
|
3612
3819
|
};
|
|
3613
|
-
return await e.insert(
|
|
3820
|
+
return await e.insert(ze).values(c), vr({
|
|
3614
3821
|
...c,
|
|
3615
3822
|
tenant_id: t
|
|
3616
3823
|
});
|
|
3617
3824
|
},
|
|
3618
3825
|
async get(n, r) {
|
|
3619
|
-
let i = await e.select().from(
|
|
3620
|
-
return i ?
|
|
3826
|
+
let i = await e.select().from(ze).where(t(a(ze.tenant_id, n), a(ze.themeId, r))).get();
|
|
3827
|
+
return i ? vr(i) : null;
|
|
3621
3828
|
},
|
|
3622
3829
|
async update(n, r, i) {
|
|
3623
|
-
let o =
|
|
3624
|
-
return o.updated_at = (/* @__PURE__ */ new Date()).toISOString(), await e.update(
|
|
3830
|
+
let o = Qe(i);
|
|
3831
|
+
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;
|
|
3625
3832
|
},
|
|
3626
3833
|
async remove(n, r) {
|
|
3627
|
-
return (await e.delete(
|
|
3834
|
+
return (await e.delete(ze).where(t(a(ze.tenant_id, n), a(ze.themeId, r))).returning()).length > 0;
|
|
3628
3835
|
}
|
|
3629
3836
|
};
|
|
3630
3837
|
}
|
|
3631
3838
|
//#endregion
|
|
3632
3839
|
//#region src/adapters/universalLoginTemplates.ts
|
|
3633
|
-
function
|
|
3840
|
+
function br(e) {
|
|
3634
3841
|
return {
|
|
3635
3842
|
async get(t) {
|
|
3636
|
-
let n = await e.select({ body:
|
|
3843
|
+
let n = await e.select({ body: Re.body }).from(Re).where(a(Re.tenant_id, t)).get();
|
|
3637
3844
|
return n ? { body: n.body } : null;
|
|
3638
3845
|
},
|
|
3639
3846
|
async set(t, n) {
|
|
3640
3847
|
let r = Date.now();
|
|
3641
|
-
await e.insert(
|
|
3848
|
+
await e.insert(Re).values({
|
|
3642
3849
|
tenant_id: t,
|
|
3643
3850
|
body: n.body,
|
|
3644
3851
|
created_at_ts: r,
|
|
3645
3852
|
updated_at_ts: r
|
|
3646
3853
|
}).onConflictDoUpdate({
|
|
3647
|
-
target:
|
|
3854
|
+
target: Re.tenant_id,
|
|
3648
3855
|
set: {
|
|
3649
3856
|
body: n.body,
|
|
3650
3857
|
updated_at_ts: r
|
|
@@ -3652,20 +3859,20 @@ function sr(e) {
|
|
|
3652
3859
|
});
|
|
3653
3860
|
},
|
|
3654
3861
|
async delete(t) {
|
|
3655
|
-
await e.delete(
|
|
3862
|
+
await e.delete(Re).where(a(Re.tenant_id, t));
|
|
3656
3863
|
}
|
|
3657
3864
|
};
|
|
3658
3865
|
}
|
|
3659
3866
|
//#endregion
|
|
3660
3867
|
//#region src/adapters/userActivity.ts
|
|
3661
|
-
function
|
|
3868
|
+
function xr(e) {
|
|
3662
3869
|
let t = {};
|
|
3663
3870
|
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;
|
|
3664
3871
|
}
|
|
3665
|
-
function
|
|
3872
|
+
function Sr(e) {
|
|
3666
3873
|
return {
|
|
3667
3874
|
async get(n, r) {
|
|
3668
|
-
let i = await e.select().from(
|
|
3875
|
+
let i = await e.select().from(Oe).where(t(a(Oe.tenant_id, n), a(Oe.user_id, r))).get();
|
|
3669
3876
|
return i ? {
|
|
3670
3877
|
user_id: i.user_id,
|
|
3671
3878
|
last_login: i.last_login ?? void 0,
|
|
@@ -3676,7 +3883,7 @@ function lr(e) {
|
|
|
3676
3883
|
} : null;
|
|
3677
3884
|
},
|
|
3678
3885
|
async upsert(t, n, r) {
|
|
3679
|
-
let i =
|
|
3886
|
+
let i = xr(r), a = e.insert(Oe).values({
|
|
3680
3887
|
tenant_id: t,
|
|
3681
3888
|
user_id: n,
|
|
3682
3889
|
login_count: 0,
|
|
@@ -3687,7 +3894,7 @@ function lr(e) {
|
|
|
3687
3894
|
return;
|
|
3688
3895
|
}
|
|
3689
3896
|
await a.onConflictDoUpdate({
|
|
3690
|
-
target: [
|
|
3897
|
+
target: [Oe.tenant_id, Oe.user_id],
|
|
3691
3898
|
set: i
|
|
3692
3899
|
});
|
|
3693
3900
|
}
|
|
@@ -3695,14 +3902,14 @@ function lr(e) {
|
|
|
3695
3902
|
}
|
|
3696
3903
|
//#endregion
|
|
3697
3904
|
//#region src/adapters/outbox.ts
|
|
3698
|
-
function
|
|
3905
|
+
function Cr(e) {
|
|
3699
3906
|
return {
|
|
3700
3907
|
...e,
|
|
3701
3908
|
payload: Q(e.payload, {})
|
|
3702
3909
|
};
|
|
3703
3910
|
}
|
|
3704
|
-
function
|
|
3705
|
-
return e.insert(
|
|
3911
|
+
function wr(e, t, n, r) {
|
|
3912
|
+
return e.insert(Y).values({
|
|
3706
3913
|
id: t,
|
|
3707
3914
|
tenant_id: n,
|
|
3708
3915
|
event_type: r.event_type,
|
|
@@ -3722,52 +3929,52 @@ function dr(e, t, n, r) {
|
|
|
3722
3929
|
claim_expires_at: null
|
|
3723
3930
|
});
|
|
3724
3931
|
}
|
|
3725
|
-
function
|
|
3932
|
+
function Tr(e) {
|
|
3726
3933
|
return {
|
|
3727
3934
|
async create(t, n) {
|
|
3728
3935
|
let r = b();
|
|
3729
|
-
return await
|
|
3936
|
+
return await wr(e, r, t, n), r;
|
|
3730
3937
|
},
|
|
3731
3938
|
async getByIds(t) {
|
|
3732
|
-
return t.length === 0 ? [] : (await e.select().from(
|
|
3939
|
+
return t.length === 0 ? [] : (await e.select().from(Y).where(l(Y.id, t)).all()).map(Cr);
|
|
3733
3940
|
},
|
|
3734
3941
|
async getUnprocessed(n) {
|
|
3735
3942
|
let r = (/* @__PURE__ */ new Date()).toISOString();
|
|
3736
|
-
return (await e.select().from(
|
|
3943
|
+
return (await e.select().from(Y).where(t(f(Y.processed_at), v(f(Y.next_retry_at), h(Y.next_retry_at, r)), v(f(Y.claimed_by), h(Y.claim_expires_at, r)))).orderBy(Y.created_at, Y.id).limit(n).all()).map(Cr);
|
|
3737
3944
|
},
|
|
3738
3945
|
async claimEvents(n, r, i) {
|
|
3739
3946
|
if (n.length === 0) return [];
|
|
3740
3947
|
let o = (/* @__PURE__ */ new Date()).toISOString(), s = new Date(Date.now() + i).toISOString();
|
|
3741
|
-
return await e.update(
|
|
3948
|
+
return await e.update(Y).set({
|
|
3742
3949
|
claimed_by: r,
|
|
3743
3950
|
claim_expires_at: s
|
|
3744
|
-
}).where(t(l(
|
|
3951
|
+
}).where(t(l(Y.id, n), f(Y.processed_at), v(f(Y.claimed_by), h(Y.claim_expires_at, o)))), (await e.select({ id: Y.id }).from(Y).where(t(l(Y.id, n), a(Y.claimed_by, r))).all()).map((e) => e.id);
|
|
3745
3952
|
},
|
|
3746
3953
|
async markProcessed(t) {
|
|
3747
|
-
t.length !== 0 && await e.update(
|
|
3954
|
+
t.length !== 0 && await e.update(Y).set({ processed_at: (/* @__PURE__ */ new Date()).toISOString() }).where(l(Y.id, t));
|
|
3748
3955
|
},
|
|
3749
3956
|
async markRetry(t, n, r) {
|
|
3750
|
-
await e.update(
|
|
3957
|
+
await e.update(Y).set({
|
|
3751
3958
|
error: n,
|
|
3752
3959
|
next_retry_at: r,
|
|
3753
|
-
retry_count: y`${
|
|
3960
|
+
retry_count: y`${Y.retry_count} + 1`,
|
|
3754
3961
|
claimed_by: null,
|
|
3755
3962
|
claim_expires_at: null
|
|
3756
|
-
}).where(a(
|
|
3963
|
+
}).where(a(Y.id, t));
|
|
3757
3964
|
},
|
|
3758
3965
|
async cleanup(n) {
|
|
3759
|
-
return (await e.delete(
|
|
3966
|
+
return (await e.delete(Y).where(t(y`${Y.processed_at} IS NOT NULL`, h(Y.processed_at, n))).returning()).length;
|
|
3760
3967
|
},
|
|
3761
3968
|
async deadLetter(t, n) {
|
|
3762
3969
|
let r = (/* @__PURE__ */ new Date()).toISOString();
|
|
3763
|
-
await e.update(
|
|
3970
|
+
await e.update(Y).set({
|
|
3764
3971
|
processed_at: r,
|
|
3765
3972
|
dead_lettered_at: r,
|
|
3766
3973
|
final_error: n
|
|
3767
|
-
}).where(a(
|
|
3974
|
+
}).where(a(Y.id, t));
|
|
3768
3975
|
},
|
|
3769
3976
|
async listFailed(o, s = {}) {
|
|
3770
|
-
let { page: c = 0, per_page: l = 50, include_totals: u = !1 } = s, f = (await e.select().from(
|
|
3977
|
+
let { page: c = 0, per_page: l = 50, include_totals: u = !1 } = s, f = (await e.select().from(Y).where(t(a(Y.tenant_id, o), d(Y.dead_lettered_at))).orderBy(i(Y.dead_lettered_at), n(Y.id)).offset(c * l).limit(l).all()).map((e) => ({
|
|
3771
3978
|
...Q(e.payload, {}),
|
|
3772
3979
|
id: e.id,
|
|
3773
3980
|
created_at: e.created_at,
|
|
@@ -3779,7 +3986,7 @@ function fr(e) {
|
|
|
3779
3986
|
final_error: e.final_error
|
|
3780
3987
|
})), p = f.length;
|
|
3781
3988
|
if (u) {
|
|
3782
|
-
let [n] = await e.select({ total: r() }).from(
|
|
3989
|
+
let [n] = await e.select({ total: r() }).from(Y).where(t(a(Y.tenant_id, o), d(Y.dead_lettered_at)));
|
|
3783
3990
|
p = Number(n?.total ?? f.length);
|
|
3784
3991
|
}
|
|
3785
3992
|
return {
|
|
@@ -3790,23 +3997,23 @@ function fr(e) {
|
|
|
3790
3997
|
};
|
|
3791
3998
|
},
|
|
3792
3999
|
async replay(n, r) {
|
|
3793
|
-
return (await e.update(
|
|
4000
|
+
return (await e.update(Y).set({
|
|
3794
4001
|
processed_at: null,
|
|
3795
4002
|
dead_lettered_at: null,
|
|
3796
4003
|
final_error: null,
|
|
3797
4004
|
retry_count: 0,
|
|
3798
4005
|
next_retry_at: null,
|
|
3799
4006
|
error: null
|
|
3800
|
-
}).where(t(a(
|
|
4007
|
+
}).where(t(a(Y.id, n), a(Y.tenant_id, r), d(Y.dead_lettered_at))).returning()).length > 0;
|
|
3801
4008
|
}
|
|
3802
4009
|
};
|
|
3803
4010
|
}
|
|
3804
4011
|
//#endregion
|
|
3805
4012
|
//#region src/adapters/users.ts
|
|
3806
|
-
function
|
|
3807
|
-
return (n?.outboxEvents ?? []).map((n) =>
|
|
4013
|
+
function Er(e, t, n) {
|
|
4014
|
+
return (n?.outboxEvents ?? []).map((n) => wr(e, n.id, t, n));
|
|
3808
4015
|
}
|
|
3809
|
-
var
|
|
4016
|
+
var Dr = [
|
|
3810
4017
|
"user_id",
|
|
3811
4018
|
"email",
|
|
3812
4019
|
"email_verified",
|
|
@@ -3828,23 +4035,23 @@ var mr = [
|
|
|
3828
4035
|
"login_count",
|
|
3829
4036
|
"created_at",
|
|
3830
4037
|
"updated_at"
|
|
3831
|
-
],
|
|
4038
|
+
], Or = [
|
|
3832
4039
|
"email",
|
|
3833
4040
|
"name",
|
|
3834
4041
|
"phone_number",
|
|
3835
4042
|
"user_id"
|
|
3836
|
-
],
|
|
4043
|
+
], kr = new Set([
|
|
3837
4044
|
"last_login",
|
|
3838
4045
|
"last_ip",
|
|
3839
4046
|
"login_count"
|
|
3840
|
-
]),
|
|
3841
|
-
coalesce:
|
|
4047
|
+
]), Ar = o(j), jr = o(Oe), Mr = Object.fromEntries(Dr.map((e) => [e, e === "login_count" ? {
|
|
4048
|
+
coalesce: Oe.login_count,
|
|
3842
4049
|
defaultValue: 0
|
|
3843
|
-
} :
|
|
3844
|
-
function
|
|
3845
|
-
return t(a(
|
|
4050
|
+
} : kr.has(e) ? jr[e] : Ar[e]]));
|
|
4051
|
+
function Nr() {
|
|
4052
|
+
return t(a(Oe.tenant_id, j.tenant_id), a(Oe.user_id, j.user_id));
|
|
3846
4053
|
}
|
|
3847
|
-
function
|
|
4054
|
+
function Pr(e, t) {
|
|
3848
4055
|
return {
|
|
3849
4056
|
...e,
|
|
3850
4057
|
last_login: t?.last_login,
|
|
@@ -3852,7 +4059,7 @@ function xr(e, t) {
|
|
|
3852
4059
|
login_count: t?.login_count ?? 0
|
|
3853
4060
|
};
|
|
3854
4061
|
}
|
|
3855
|
-
function
|
|
4062
|
+
function Fr(e, t) {
|
|
3856
4063
|
let n = {
|
|
3857
4064
|
connection: e.connection,
|
|
3858
4065
|
provider: e.provider,
|
|
@@ -3865,21 +4072,22 @@ function Sr(e, t) {
|
|
|
3865
4072
|
...typeof e.profileData == "string" ? Q(e.profileData, {}) : {}
|
|
3866
4073
|
}, n;
|
|
3867
4074
|
}
|
|
3868
|
-
function
|
|
3869
|
-
let { tenant_id: n, app_metadata: r, user_metadata: i, address: a, email_verified: o, phone_verified: s, is_social: c,
|
|
4075
|
+
function Ir(e, t = []) {
|
|
4076
|
+
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 = Fr(e, !0), m = t.map((e) => Fr(e, !1));
|
|
3870
4077
|
return O({
|
|
3871
|
-
...
|
|
4078
|
+
...f,
|
|
3872
4079
|
email: e.email || "",
|
|
3873
4080
|
email_verified: !!o,
|
|
3874
4081
|
phone_verified: s == null ? void 0 : !!s,
|
|
3875
4082
|
is_social: !!c,
|
|
4083
|
+
blocked: l == null ? void 0 : !!l,
|
|
3876
4084
|
app_metadata: Q(r, {}),
|
|
3877
4085
|
user_metadata: Q(i, {}),
|
|
3878
4086
|
address: Q(a),
|
|
3879
|
-
identities: [
|
|
4087
|
+
identities: [p, ...m]
|
|
3880
4088
|
});
|
|
3881
4089
|
}
|
|
3882
|
-
function
|
|
4090
|
+
function Lr(e) {
|
|
3883
4091
|
let o = async (t, n, r) => {
|
|
3884
4092
|
let i = (/* @__PURE__ */ new Date()).toISOString(), a = {
|
|
3885
4093
|
user_id: n.user_id,
|
|
@@ -3899,6 +4107,7 @@ function wr(e) {
|
|
|
3899
4107
|
connection: n.connection,
|
|
3900
4108
|
email_verified: n.email_verified ?? !1,
|
|
3901
4109
|
is_social: n.is_social ?? !1,
|
|
4110
|
+
blocked: n.blocked ?? !1,
|
|
3902
4111
|
app_metadata: JSON.stringify(n.app_metadata || {}),
|
|
3903
4112
|
user_metadata: JSON.stringify(n.user_metadata || {}),
|
|
3904
4113
|
address: n.address ? JSON.stringify(n.address) : void 0,
|
|
@@ -3916,7 +4125,7 @@ function wr(e) {
|
|
|
3916
4125
|
}, o = n.password ? b() : void 0, s = n.last_login !== void 0 || n.last_ip !== void 0 || n.login_count !== void 0;
|
|
3917
4126
|
try {
|
|
3918
4127
|
let c = [e.insert(j).values(a)];
|
|
3919
|
-
s && c.push(e.insert(
|
|
4128
|
+
s && c.push(e.insert(Oe).values({
|
|
3920
4129
|
tenant_id: t,
|
|
3921
4130
|
user_id: n.user_id,
|
|
3922
4131
|
last_login: n.last_login,
|
|
@@ -3932,12 +4141,12 @@ function wr(e) {
|
|
|
3932
4141
|
created_at: i,
|
|
3933
4142
|
updated_at: i
|
|
3934
4143
|
}));
|
|
3935
|
-
for (let n of
|
|
3936
|
-
c.length > 1 ? await
|
|
4144
|
+
for (let n of Er(e, t, r)) c.push(n);
|
|
4145
|
+
c.length > 1 ? await lt(e, c) : await e.insert(j).values(a);
|
|
3937
4146
|
} catch (e) {
|
|
3938
|
-
throw e?.message?.includes("UNIQUE constraint") || e?.message?.includes("AlreadyExists") ? new
|
|
4147
|
+
throw e?.message?.includes("UNIQUE constraint") || e?.message?.includes("AlreadyExists") ? new Ce(409, { message: "User already exists" }) : (console.error("User upsert failed:", e?.code, e?.message), new Ce(500, { message: "Internal server error" }));
|
|
3939
4148
|
}
|
|
3940
|
-
return
|
|
4149
|
+
return Ir({
|
|
3941
4150
|
...a,
|
|
3942
4151
|
last_login: n.last_login,
|
|
3943
4152
|
last_ip: n.last_ip,
|
|
@@ -3948,10 +4157,10 @@ function wr(e) {
|
|
|
3948
4157
|
create: o,
|
|
3949
4158
|
rawCreate: o,
|
|
3950
4159
|
async get(n, r) {
|
|
3951
|
-
let i = await e.select().from(j).leftJoin(
|
|
4160
|
+
let i = await e.select().from(j).leftJoin(Oe, Nr()).where(t(a(j.tenant_id, n), a(j.user_id, r))).get();
|
|
3952
4161
|
if (!i) return null;
|
|
3953
4162
|
let o = await e.select().from(j).where(t(a(j.tenant_id, n), a(j.linked_to, r))).all();
|
|
3954
|
-
return
|
|
4163
|
+
return Ir(Pr(i.users, i.user_activity), o);
|
|
3955
4164
|
},
|
|
3956
4165
|
async update(n, r, i, o) {
|
|
3957
4166
|
let s = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
@@ -3977,9 +4186,9 @@ function wr(e) {
|
|
|
3977
4186
|
"birthdate",
|
|
3978
4187
|
"zoneinfo"
|
|
3979
4188
|
]) i[e] !== void 0 && (s[e] = i[e]);
|
|
3980
|
-
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.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));
|
|
3981
|
-
let c = e.update(j).set(s).where(t(a(j.tenant_id, n), a(j.user_id, r))).returning(), l =
|
|
3982
|
-
return u = l.length > 0 ? (await
|
|
4189
|
+
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));
|
|
4190
|
+
let c = e.update(j).set(s).where(t(a(j.tenant_id, n), a(j.user_id, r))).returning(), l = Er(e, n, o), u;
|
|
4191
|
+
return u = l.length > 0 ? (await lt(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 Sr(e).upsert(n, r, {
|
|
3983
4192
|
last_login: i.last_login,
|
|
3984
4193
|
last_ip: i.last_ip,
|
|
3985
4194
|
login_count: i.login_count
|
|
@@ -3988,24 +4197,24 @@ function wr(e) {
|
|
|
3988
4197
|
async list(o, s) {
|
|
3989
4198
|
let { page: c = 0, per_page: u = 50, include_totals: d = !1, sort: p, q: m } = s || {}, h = [a(j.tenant_id, o), f(j.linked_to)];
|
|
3990
4199
|
if (m) {
|
|
3991
|
-
let e = _e(m,
|
|
4200
|
+
let e = _e(m, Dr);
|
|
3992
4201
|
if (e) {
|
|
3993
|
-
let t =
|
|
4202
|
+
let t = nt(Mr, e, Or);
|
|
3994
4203
|
t && h.push(t);
|
|
3995
4204
|
}
|
|
3996
4205
|
}
|
|
3997
4206
|
let g = t(...h), _ = async (n) => {
|
|
3998
4207
|
let r = n.map((e) => e.user_id), i = r.length > 0 ? await e.select().from(j).where(t(a(j.tenant_id, o), l(j.linked_to, r))) : [];
|
|
3999
|
-
return n.map((e) =>
|
|
4208
|
+
return n.map((e) => Ir(e, i.filter((t) => t.linked_to === e.user_id)));
|
|
4000
4209
|
};
|
|
4001
|
-
if (
|
|
4002
|
-
if (p?.sort_by && p.sort_by !== "created_at") throw new
|
|
4210
|
+
if (mt(s)) {
|
|
4211
|
+
if (p?.sort_by && p.sort_by !== "created_at") throw new Ce(400, { message: `Sorting by ${p.sort_by} is not supported with checkpoint pagination (from/take); only created_at is` });
|
|
4003
4212
|
let n = p?.sort_order === "asc" ? "asc" : "desc", r = {
|
|
4004
4213
|
sortColumn: j.created_at,
|
|
4005
4214
|
idColumn: j.user_id,
|
|
4006
4215
|
sortOrder: n,
|
|
4007
4216
|
sortKey: `created_at:${n}`
|
|
4008
|
-
}, i =
|
|
4217
|
+
}, i = ht(s), a = _t(s, r), { rows: o, next: c } = vt((await e.select().from(j).leftJoin(Oe, Nr()).where(a ? t(g, a) : g).orderBy(...gt(r)).limit(i + 1)).map((e) => Pr(e.users, e.user_activity)), i, "created_at", "user_id", r.sortKey), l = await _(o);
|
|
4009
4218
|
return {
|
|
4010
4219
|
users: l,
|
|
4011
4220
|
start: 0,
|
|
@@ -4014,17 +4223,17 @@ function wr(e) {
|
|
|
4014
4223
|
next: c
|
|
4015
4224
|
};
|
|
4016
4225
|
}
|
|
4017
|
-
let v = e.select().from(j).leftJoin(
|
|
4226
|
+
let v = e.select().from(j).leftJoin(Oe, Nr()).where(g).$dynamic();
|
|
4018
4227
|
if (p?.sort_by) {
|
|
4019
|
-
let e =
|
|
4228
|
+
let e = Mr[p.sort_by];
|
|
4020
4229
|
if (e) {
|
|
4021
|
-
let t =
|
|
4230
|
+
let t = et(e) ? tt(e) : e;
|
|
4022
4231
|
v = v.orderBy(p.sort_order === "desc" ? i(t) : n(t));
|
|
4023
4232
|
}
|
|
4024
4233
|
}
|
|
4025
|
-
let y = await _((await v.offset(c * u).limit(u)).map((e) =>
|
|
4234
|
+
let y = await _((await v.offset(c * u).limit(u)).map((e) => Pr(e.users, e.user_activity)));
|
|
4026
4235
|
if (!d) return { users: y };
|
|
4027
|
-
let [ee] = await e.select({ count: r() }).from(j).leftJoin(
|
|
4236
|
+
let [ee] = await e.select({ count: r() }).from(j).leftJoin(Oe, Nr()).where(g);
|
|
4028
4237
|
return {
|
|
4029
4238
|
users: y,
|
|
4030
4239
|
start: c * u,
|
|
@@ -4034,14 +4243,14 @@ function wr(e) {
|
|
|
4034
4243
|
},
|
|
4035
4244
|
async remove(n, r, i) {
|
|
4036
4245
|
let o = await e.select({ user_id: j.user_id }).from(j).where(t(a(j.tenant_id, n), v(a(j.user_id, r), a(j.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 = [
|
|
4037
|
-
e.delete(
|
|
4246
|
+
e.delete(q).where(t(a(q.tenant_id, n), l(q.user_id, u))),
|
|
4038
4247
|
e.delete(M).where(t(a(M.tenant_id, n), l(M.user_id, u))),
|
|
4039
|
-
e.delete(
|
|
4248
|
+
e.delete(Oe).where(t(a(Oe.tenant_id, n), l(Oe.user_id, u))),
|
|
4040
4249
|
e.delete(j).where(t(a(j.tenant_id, n), l(j.user_id, c))),
|
|
4041
4250
|
e.delete(j).where(t(a(j.tenant_id, n), a(j.user_id, r))).returning()
|
|
4042
4251
|
], f = d.length - 1;
|
|
4043
|
-
if (s) for (let t of
|
|
4044
|
-
let p = (await
|
|
4252
|
+
if (s) for (let t of Er(e, n, i)) d.push(t);
|
|
4253
|
+
let p = (await lt(e, d))[f];
|
|
4045
4254
|
return Array.isArray(p) && p.length > 0;
|
|
4046
4255
|
},
|
|
4047
4256
|
async unlink(n, r, i, o) {
|
|
@@ -4052,11 +4261,11 @@ function wr(e) {
|
|
|
4052
4261
|
}
|
|
4053
4262
|
//#endregion
|
|
4054
4263
|
//#region src/adapters/userRoles.ts
|
|
4055
|
-
function
|
|
4264
|
+
function Rr(e) {
|
|
4056
4265
|
return {
|
|
4057
4266
|
async create(t, n, r, i) {
|
|
4058
4267
|
try {
|
|
4059
|
-
await e.insert(
|
|
4268
|
+
await e.insert(G).values({
|
|
4060
4269
|
tenant_id: t,
|
|
4061
4270
|
user_id: n,
|
|
4062
4271
|
role_id: r,
|
|
@@ -4070,11 +4279,11 @@ function Tr(e) {
|
|
|
4070
4279
|
return !0;
|
|
4071
4280
|
},
|
|
4072
4281
|
async list(n, r, i, o) {
|
|
4073
|
-
let s = [a(
|
|
4074
|
-
o !== void 0 && s.push(a(
|
|
4075
|
-
let c = await e.select({ role_id:
|
|
4282
|
+
let s = [a(G.tenant_id, n), a(G.user_id, r)];
|
|
4283
|
+
o !== void 0 && s.push(a(G.organization_id, o));
|
|
4284
|
+
let c = await e.select({ role_id: G.role_id }).from(G).where(t(...s)).all();
|
|
4076
4285
|
return c.length === 0 ? [] : (await Promise.all(c.map(async (r) => {
|
|
4077
|
-
let i = await e.select().from(
|
|
4286
|
+
let i = await e.select().from(W).where(t(a(W.tenant_id, n), a(W.id, r.role_id))).get();
|
|
4078
4287
|
if (!i) return null;
|
|
4079
4288
|
let { tenant_id: o, is_system: s, metadata: c, ...l } = i;
|
|
4080
4289
|
return O({
|
|
@@ -4085,13 +4294,13 @@ function Tr(e) {
|
|
|
4085
4294
|
}))).filter(Boolean);
|
|
4086
4295
|
},
|
|
4087
4296
|
async listUsers(r, i, o) {
|
|
4088
|
-
let s = t(a(
|
|
4089
|
-
if (
|
|
4297
|
+
let s = t(a(G.tenant_id, r), a(G.role_id, i));
|
|
4298
|
+
if (mt(o)) {
|
|
4090
4299
|
let n = {
|
|
4091
|
-
sortColumn:
|
|
4092
|
-
idColumn:
|
|
4300
|
+
sortColumn: G.user_id,
|
|
4301
|
+
idColumn: G.user_id,
|
|
4093
4302
|
sortOrder: "asc"
|
|
4094
|
-
}, r =
|
|
4303
|
+
}, r = _t(o, n), i = ht(o), { rows: a, next: c } = vt(await e.selectDistinct({ user_id: G.user_id }).from(G).where(r ? t(s, r) : s).orderBy(...gt(n)).limit(i + 1).all(), i, "user_id", "user_id");
|
|
4095
4304
|
return {
|
|
4096
4305
|
userIds: a.map((e) => e.user_id),
|
|
4097
4306
|
start: 0,
|
|
@@ -4100,7 +4309,7 @@ function Tr(e) {
|
|
|
4100
4309
|
next: c
|
|
4101
4310
|
};
|
|
4102
4311
|
}
|
|
4103
|
-
let c = o?.page || 0, l = o?.per_page || 50, u = c * l, d = await e.selectDistinct({ user_id:
|
|
4312
|
+
let c = o?.page || 0, l = o?.per_page || 50, u = c * l, d = await e.selectDistinct({ user_id: G.user_id }).from(G).where(s).orderBy(n(G.user_id)).limit(l).offset(u).all(), f = await e.select({ count: y`count(distinct ${G.user_id})` }).from(G).where(s).get();
|
|
4104
4313
|
return {
|
|
4105
4314
|
userIds: d.map((e) => e.user_id),
|
|
4106
4315
|
start: u,
|
|
@@ -4109,13 +4318,13 @@ function Tr(e) {
|
|
|
4109
4318
|
};
|
|
4110
4319
|
},
|
|
4111
4320
|
async remove(n, r, i, o) {
|
|
4112
|
-
return (await e.delete(
|
|
4321
|
+
return (await e.delete(G).where(t(a(G.tenant_id, n), a(G.user_id, r), a(G.role_id, i), a(G.organization_id, o || ""))).returning()).length > 0;
|
|
4113
4322
|
}
|
|
4114
4323
|
};
|
|
4115
4324
|
}
|
|
4116
4325
|
//#endregion
|
|
4117
4326
|
//#region src/adapters/userOrganizations.ts
|
|
4118
|
-
function
|
|
4327
|
+
function zr(e) {
|
|
4119
4328
|
return {
|
|
4120
4329
|
async create(t, n) {
|
|
4121
4330
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
@@ -4127,39 +4336,39 @@ function Er(e) {
|
|
|
4127
4336
|
updated_at: r
|
|
4128
4337
|
};
|
|
4129
4338
|
try {
|
|
4130
|
-
await e.insert(
|
|
4339
|
+
await e.insert(U).values(i);
|
|
4131
4340
|
} catch (e) {
|
|
4132
|
-
throw e?.message?.includes("UNIQUE constraint") || e?.message?.includes("duplicate key") ? new
|
|
4341
|
+
throw e?.message?.includes("UNIQUE constraint") || e?.message?.includes("duplicate key") ? new Ce(409, { message: "User organization already exists" }) : e;
|
|
4133
4342
|
}
|
|
4134
4343
|
let { tenant_id: a, ...o } = i;
|
|
4135
4344
|
return o;
|
|
4136
4345
|
},
|
|
4137
4346
|
async get(n, r) {
|
|
4138
|
-
let i = await e.select().from(
|
|
4347
|
+
let i = await e.select().from(U).where(t(a(U.tenant_id, n), a(U.id, r))).get();
|
|
4139
4348
|
if (!i) return null;
|
|
4140
4349
|
let { tenant_id: o, ...s } = i;
|
|
4141
4350
|
return s;
|
|
4142
4351
|
},
|
|
4143
4352
|
async update(n, r, i) {
|
|
4144
4353
|
let o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
4145
|
-
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(
|
|
4354
|
+
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(U).set(o).where(t(a(U.tenant_id, n), a(U.id, r))).returning()).length > 0;
|
|
4146
4355
|
},
|
|
4147
4356
|
async list(n, o) {
|
|
4148
|
-
let { include_totals: s = !1, q: c } = o || {}, l = a(
|
|
4357
|
+
let { include_totals: s = !1, q: c } = o || {}, l = a(U.tenant_id, n), u = l;
|
|
4149
4358
|
if (c) {
|
|
4150
|
-
let e =
|
|
4359
|
+
let e = nt(U, c, ["user_id", "organization_id"]);
|
|
4151
4360
|
e && (u = t(l, e));
|
|
4152
4361
|
}
|
|
4153
4362
|
let d = (e) => {
|
|
4154
4363
|
let { tenant_id: t, ...n } = e;
|
|
4155
4364
|
return n;
|
|
4156
4365
|
};
|
|
4157
|
-
if (
|
|
4366
|
+
if (mt(o)) {
|
|
4158
4367
|
let n = {
|
|
4159
|
-
sortColumn:
|
|
4160
|
-
idColumn:
|
|
4368
|
+
sortColumn: U.created_at,
|
|
4369
|
+
idColumn: U.id,
|
|
4161
4370
|
sortOrder: "desc"
|
|
4162
|
-
}, r =
|
|
4371
|
+
}, r = _t(o, n), i = ht(o), { rows: a, next: s } = vt((await e.select().from(U).where(r ? t(u, r) : u).orderBy(...gt(n)).limit(i + 1)).map(d), i, "created_at");
|
|
4163
4372
|
return {
|
|
4164
4373
|
userOrganizations: a,
|
|
4165
4374
|
start: 0,
|
|
@@ -4168,9 +4377,9 @@ function Er(e) {
|
|
|
4168
4377
|
next: s
|
|
4169
4378
|
};
|
|
4170
4379
|
}
|
|
4171
|
-
let f = o?.page ?? 0, p = o?.per_page ?? 50, m = f * p, h = (await e.select().from(
|
|
4380
|
+
let f = o?.page ?? 0, p = o?.per_page ?? 50, m = f * p, h = (await e.select().from(U).where(u).orderBy(i(U.created_at), i(U.id)).offset(m).limit(p)).map(d);
|
|
4172
4381
|
if (!s) return { userOrganizations: h };
|
|
4173
|
-
let [g] = await e.select({ count: r() }).from(
|
|
4382
|
+
let [g] = await e.select({ count: r() }).from(U).where(u);
|
|
4174
4383
|
return {
|
|
4175
4384
|
userOrganizations: h,
|
|
4176
4385
|
start: m,
|
|
@@ -4179,8 +4388,8 @@ function Er(e) {
|
|
|
4179
4388
|
};
|
|
4180
4389
|
},
|
|
4181
4390
|
async listUserOrganizations(n, i, o) {
|
|
4182
|
-
let { page: s = 0, per_page: c = 50, include_totals: l = !1 } = o || {}, u = await e.select().from(
|
|
4183
|
-
let i = await e.select().from(
|
|
4391
|
+
let { page: s = 0, per_page: c = 50, include_totals: l = !1 } = o || {}, u = await e.select().from(U).where(t(a(U.tenant_id, n), a(U.user_id, i))).offset(s * c).limit(c).all(), d = (await Promise.all(u.map(async (r) => {
|
|
4392
|
+
let i = await e.select().from(H).where(t(a(H.tenant_id, n), a(H.id, r.organization_id))).get();
|
|
4184
4393
|
if (!i) return null;
|
|
4185
4394
|
let { tenant_id: o, branding: s, metadata: c, enabled_connections: l, token_quota: u, ...d } = i;
|
|
4186
4395
|
return O({
|
|
@@ -4192,7 +4401,7 @@ function Er(e) {
|
|
|
4192
4401
|
});
|
|
4193
4402
|
}))).filter(Boolean);
|
|
4194
4403
|
if (!l) return { organizations: d };
|
|
4195
|
-
let [f] = await e.select({ count: r() }).from(
|
|
4404
|
+
let [f] = await e.select({ count: r() }).from(U).where(t(a(U.tenant_id, n), a(U.user_id, i)));
|
|
4196
4405
|
return {
|
|
4197
4406
|
organizations: d,
|
|
4198
4407
|
start: s * c,
|
|
@@ -4201,26 +4410,26 @@ function Er(e) {
|
|
|
4201
4410
|
};
|
|
4202
4411
|
},
|
|
4203
4412
|
async remove(n, r) {
|
|
4204
|
-
return (await e.delete(
|
|
4413
|
+
return (await e.delete(U).where(t(a(U.tenant_id, n), a(U.id, r))).returning()).length > 0;
|
|
4205
4414
|
}
|
|
4206
4415
|
};
|
|
4207
4416
|
}
|
|
4208
4417
|
//#endregion
|
|
4209
4418
|
//#region src/adapters/stats.ts
|
|
4210
|
-
var
|
|
4211
|
-
function
|
|
4419
|
+
var Br = ["s"], Vr = ["pwd_leak"];
|
|
4420
|
+
function Hr(e) {
|
|
4212
4421
|
return /^\d{8}$/.test(e) ? `${e.slice(0, 4)}-${e.slice(4, 6)}-${e.slice(6, 8)}` : e;
|
|
4213
4422
|
}
|
|
4214
|
-
function
|
|
4423
|
+
function Ur(e) {
|
|
4215
4424
|
return {
|
|
4216
4425
|
async getDaily(n, r) {
|
|
4217
|
-
let i = /* @__PURE__ */ new Date(), o = r?.from ?
|
|
4426
|
+
let i = /* @__PURE__ */ new Date(), o = r?.from ? Hr(r.from) : (/* @__PURE__ */ new Date(i.getTime() - 720 * 60 * 60 * 1e3)).toISOString().split("T")[0], s = r?.to ? Hr(r.to) : i.toISOString().split("T")[0];
|
|
4218
4427
|
return (await e.select({
|
|
4219
|
-
date: y`substr(${
|
|
4220
|
-
logins: y`SUM(CASE WHEN ${
|
|
4221
|
-
signups: y`SUM(CASE WHEN ${
|
|
4222
|
-
leaked_passwords: y`SUM(CASE WHEN ${
|
|
4223
|
-
}).from(
|
|
4428
|
+
date: y`substr(${J.date}, 1, 10)`.as("date"),
|
|
4429
|
+
logins: y`SUM(CASE WHEN ${J.type} IN (${y.join(Br.map((e) => y`${e}`), y`, `)}) THEN 1 ELSE 0 END)`.as("logins"),
|
|
4430
|
+
signups: y`SUM(CASE WHEN ${J.type} = 'ss' THEN 1 ELSE 0 END)`.as("signups"),
|
|
4431
|
+
leaked_passwords: y`SUM(CASE WHEN ${J.type} IN (${y.join(Vr.map((e) => y`${e}`), y`, `)}) THEN 1 ELSE 0 END)`.as("leaked_passwords")
|
|
4432
|
+
}).from(J).where(t(a(J.tenant_id, n), c(J.date, o), h(J.date, `${s}T23:59:59.999Z`))).groupBy(y`substr(${J.date}, 1, 10)`).orderBy(y`substr(${J.date}, 1, 10)`).all()).map((e) => ({
|
|
4224
4433
|
date: e.date,
|
|
4225
4434
|
logins: Number(e.logins) || 0,
|
|
4226
4435
|
signups: Number(e.signups) || 0,
|
|
@@ -4230,14 +4439,14 @@ function Ar(e) {
|
|
|
4230
4439
|
}));
|
|
4231
4440
|
},
|
|
4232
4441
|
async getActiveUsers(n) {
|
|
4233
|
-
let r = (/* @__PURE__ */ new Date(Date.now() - 720 * 60 * 60 * 1e3)).toISOString(), [i] = await e.select({ count: y`COUNT(DISTINCT ${
|
|
4442
|
+
let r = (/* @__PURE__ */ new Date(Date.now() - 720 * 60 * 60 * 1e3)).toISOString(), [i] = await e.select({ count: y`COUNT(DISTINCT ${J.user_id})`.as("count") }).from(J).where(t(a(J.tenant_id, n), c(J.date, r), y`${J.type} IN (${y.join(Br.map((e) => y`${e}`), y`, `)})`));
|
|
4234
4443
|
return Number(i?.count) || 0;
|
|
4235
4444
|
}
|
|
4236
4445
|
};
|
|
4237
4446
|
}
|
|
4238
4447
|
//#endregion
|
|
4239
4448
|
//#region src/adapters/analytics.ts
|
|
4240
|
-
var
|
|
4449
|
+
var Wr = {
|
|
4241
4450
|
"active-users": ["s", "seacft"],
|
|
4242
4451
|
logins: [
|
|
4243
4452
|
"s",
|
|
@@ -4267,7 +4476,7 @@ var jr = {
|
|
|
4267
4476
|
"fvr"
|
|
4268
4477
|
],
|
|
4269
4478
|
"codes-sent": ["cls", "cs"]
|
|
4270
|
-
},
|
|
4479
|
+
}, Gr = {
|
|
4271
4480
|
"active-users": {
|
|
4272
4481
|
alias: "active_users",
|
|
4273
4482
|
type: "UInt64",
|
|
@@ -4324,63 +4533,63 @@ var jr = {
|
|
|
4324
4533
|
agg: "count"
|
|
4325
4534
|
}
|
|
4326
4535
|
};
|
|
4327
|
-
function
|
|
4536
|
+
function Kr(e) {
|
|
4328
4537
|
switch (e) {
|
|
4329
|
-
case "hour": return y`substr(${
|
|
4330
|
-
case "month": return y`substr(${
|
|
4331
|
-
case "day": return y`substr(${
|
|
4332
|
-
case "week": return y`date(substr(${
|
|
4538
|
+
case "hour": return y`substr(${J.date}, 1, 13)`;
|
|
4539
|
+
case "month": return y`substr(${J.date}, 1, 7)`;
|
|
4540
|
+
case "day": return y`substr(${J.date}, 1, 10)`;
|
|
4541
|
+
case "week": return y`date(substr(${J.date}, 1, 10), '-' || ((cast(strftime('%w', substr(${J.date}, 1, 10)) as integer) + 6) % 7) || ' days')`;
|
|
4333
4542
|
default: throw Error(`Unsupported interval '${e}' for SQL analytics adapter`);
|
|
4334
4543
|
}
|
|
4335
4544
|
}
|
|
4336
|
-
function
|
|
4545
|
+
function qr(e) {
|
|
4337
4546
|
return `"${e.replace(/"/g, "\"\"")}"`;
|
|
4338
4547
|
}
|
|
4339
|
-
function
|
|
4548
|
+
function Jr(e) {
|
|
4340
4549
|
switch (e) {
|
|
4341
|
-
case "connection": return
|
|
4342
|
-
case "client_id": return
|
|
4343
|
-
case "user_type": return
|
|
4344
|
-
case "event": return
|
|
4550
|
+
case "connection": return J.connection;
|
|
4551
|
+
case "client_id": return J.client_id;
|
|
4552
|
+
case "user_type": return J.strategy_type;
|
|
4553
|
+
case "event": return J.type;
|
|
4345
4554
|
case "time": throw Error("time dimension handled separately");
|
|
4346
4555
|
}
|
|
4347
4556
|
}
|
|
4348
|
-
function
|
|
4557
|
+
function Yr(e) {
|
|
4349
4558
|
return { async query(n, r, i) {
|
|
4350
|
-
let o = Date.now(), s =
|
|
4351
|
-
a(
|
|
4352
|
-
c(
|
|
4353
|
-
m(
|
|
4354
|
-
l(
|
|
4559
|
+
let o = Date.now(), s = Wr[r], u = Gr[r], d = [
|
|
4560
|
+
a(J.tenant_id, n),
|
|
4561
|
+
c(J.date, i.from),
|
|
4562
|
+
m(J.date, i.to),
|
|
4563
|
+
l(J.type, s)
|
|
4355
4564
|
];
|
|
4356
|
-
i.filters.connection?.length && d.push(l(
|
|
4565
|
+
i.filters.connection?.length && d.push(l(J.connection, i.filters.connection)), i.filters.client_id?.length && d.push(l(J.client_id, i.filters.client_id)), i.filters.user_type?.length && d.push(l(J.strategy_type, i.filters.user_type)), i.filters.user_id?.length && d.push(l(J.user_id, i.filters.user_id));
|
|
4357
4566
|
let f = {}, p = [], h = [];
|
|
4358
4567
|
for (let e of i.group_by) if (e === "time") {
|
|
4359
|
-
let e =
|
|
4568
|
+
let e = Kr(i.interval);
|
|
4360
4569
|
f.time = e, p.push(e), h.push({
|
|
4361
4570
|
name: "time",
|
|
4362
4571
|
type: i.interval === "hour" ? "DateTime" : "Date"
|
|
4363
4572
|
});
|
|
4364
4573
|
} else {
|
|
4365
|
-
let t =
|
|
4574
|
+
let t = Jr(e);
|
|
4366
4575
|
f[e] = t, p.push(t), h.push({
|
|
4367
4576
|
name: e,
|
|
4368
4577
|
type: "String"
|
|
4369
4578
|
});
|
|
4370
4579
|
}
|
|
4371
|
-
f[u.alias] = u.agg === "uniq" ? y`COUNT(DISTINCT ${
|
|
4580
|
+
f[u.alias] = u.agg === "uniq" ? y`COUNT(DISTINCT ${J.user_id})` : y`COUNT(*)`, h.push({
|
|
4372
4581
|
name: u.alias,
|
|
4373
4582
|
type: u.type
|
|
4374
4583
|
});
|
|
4375
|
-
let g = e.select(f).from(
|
|
4584
|
+
let g = e.select(f).from(J).where(t(...d));
|
|
4376
4585
|
p.length > 0 && (g = g.groupBy(...p));
|
|
4377
4586
|
let _ = new Set([...Object.keys(f)]);
|
|
4378
4587
|
if (i.order_by) {
|
|
4379
4588
|
let e = i.order_by.startsWith("-"), t = e ? i.order_by.slice(1) : i.order_by;
|
|
4380
4589
|
if (!_.has(t)) throw Error(`Invalid order_by column '${t}' for analytics query`);
|
|
4381
|
-
let n =
|
|
4590
|
+
let n = qr(t);
|
|
4382
4591
|
g = g.orderBy(y.raw(`${n} ${e ? "DESC" : "ASC"}`));
|
|
4383
|
-
} else g = i.group_by[0] === "time" ? g.orderBy(y.raw(`${
|
|
4592
|
+
} else g = i.group_by[0] === "time" ? g.orderBy(y.raw(`${qr("time")} ASC`)) : g.orderBy(y.raw(`${qr(u.alias)} DESC`));
|
|
4384
4593
|
g = g.limit(i.limit).offset(i.offset);
|
|
4385
4594
|
let v = (await g.all()).map((e) => {
|
|
4386
4595
|
let t = {};
|
|
@@ -4401,10 +4610,10 @@ function Ir(e) {
|
|
|
4401
4610
|
}
|
|
4402
4611
|
//#endregion
|
|
4403
4612
|
//#region src/adapters/cleanup.ts
|
|
4404
|
-
var
|
|
4405
|
-
function
|
|
4613
|
+
var Xr = 10080 * 60 * 1e3;
|
|
4614
|
+
function Zr(e) {
|
|
4406
4615
|
return async (n) => {
|
|
4407
|
-
let r = Date.now() -
|
|
4616
|
+
let r = Date.now() - Xr;
|
|
4408
4617
|
try {
|
|
4409
4618
|
let i = [v(m(P.expires_at_ts, r), m(P.idle_expires_at_ts, r))];
|
|
4410
4619
|
n?.tenant_id && i.push(a(P.tenant_id, n.tenant_id)), await e.delete(P).where(t(...i)), i = [v(m(N.expires_at_ts, r), m(N.idle_expires_at_ts, r))], n?.tenant_id && i.push(a(N.tenant_id, n.tenant_id)), n?.user_id && i.push(a(N.user_id, n.user_id)), await e.delete(N).where(t(...i)), i = [m(F.expires_at_ts, r)], n?.tenant_id && i.push(a(F.tenant_id, n.tenant_id)), await e.delete(F).where(t(...i));
|
|
@@ -4435,7 +4644,7 @@ var $ = w("tenant_operations", {
|
|
|
4435
4644
|
x("tenant_operations_tenant_id_created_at_idx").on(e.tenant_id, e.created_at),
|
|
4436
4645
|
x("tenant_operations_rollout_id_idx").on(e.rollout_id),
|
|
4437
4646
|
x("tenant_operations_status_idx").on(e.status)
|
|
4438
|
-
]),
|
|
4647
|
+
]), Qr = w("tenant_operation_events", {
|
|
4439
4648
|
id: T("id", { length: 255 }).primaryKey(),
|
|
4440
4649
|
operation_id: T("operation_id", { length: 255 }).notNull(),
|
|
4441
4650
|
step: T("step", { length: 255 }).notNull(),
|
|
@@ -4447,7 +4656,7 @@ var $ = w("tenant_operations", {
|
|
|
4447
4656
|
columns: [e.operation_id],
|
|
4448
4657
|
foreignColumns: [$.id],
|
|
4449
4658
|
name: "tenant_operation_events_operation_id_constraint"
|
|
4450
|
-
}).onDelete("cascade"), x("tenant_operation_events_operation_id_created_at_idx").on(e.operation_id, e.created_at)]),
|
|
4659
|
+
}).onDelete("cascade"), x("tenant_operation_events_operation_id_created_at_idx").on(e.operation_id, e.created_at)]), $r = w("rollouts", {
|
|
4451
4660
|
id: T("id", { length: 255 }).primaryKey(),
|
|
4452
4661
|
kind: T("kind", { length: 32 }).notNull(),
|
|
4453
4662
|
status: T("status", { length: 32 }).notNull(),
|
|
@@ -4463,8 +4672,8 @@ var $ = w("tenant_operations", {
|
|
|
4463
4672
|
});
|
|
4464
4673
|
//#endregion
|
|
4465
4674
|
//#region src/adapters/tenantOperations.ts
|
|
4466
|
-
function
|
|
4467
|
-
return
|
|
4675
|
+
function ei(e) {
|
|
4676
|
+
return Se.parse({
|
|
4468
4677
|
id: e.id,
|
|
4469
4678
|
tenant_id: e.tenant_id,
|
|
4470
4679
|
rollout_id: e.rollout_id,
|
|
@@ -4482,10 +4691,10 @@ function Vr(e) {
|
|
|
4482
4691
|
finished_at: e.finished_at
|
|
4483
4692
|
});
|
|
4484
4693
|
}
|
|
4485
|
-
function
|
|
4694
|
+
function ti(e) {
|
|
4486
4695
|
return {
|
|
4487
4696
|
async create(t) {
|
|
4488
|
-
let n =
|
|
4697
|
+
let n = xe.parse(t), r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
4489
4698
|
id: `op_${b()}`,
|
|
4490
4699
|
tenant_id: n.tenant_id,
|
|
4491
4700
|
rollout_id: n.rollout_id ?? null,
|
|
@@ -4509,7 +4718,7 @@ function Hr(e) {
|
|
|
4509
4718
|
},
|
|
4510
4719
|
async get(t) {
|
|
4511
4720
|
let n = await e.select().from($).where(a($.id, t)).limit(1);
|
|
4512
|
-
return n[0] ?
|
|
4721
|
+
return n[0] ? ei(n[0]) : null;
|
|
4513
4722
|
},
|
|
4514
4723
|
async list(n = {}) {
|
|
4515
4724
|
let r = n.page ?? 0, o = n.per_page ?? 50, s = [];
|
|
@@ -4520,7 +4729,7 @@ function Hr(e) {
|
|
|
4520
4729
|
n.engine !== void 0 && s.push(a($.engine, n.engine)), n.updated_before !== void 0 && s.push(m($.updated_at, n.updated_before));
|
|
4521
4730
|
let c = await e.select().from($).where(s.length ? t(...s) : void 0).orderBy(i($.created_at), i($.id)).offset(r * o).limit(o);
|
|
4522
4731
|
return {
|
|
4523
|
-
operations: c.map(
|
|
4732
|
+
operations: c.map(ei),
|
|
4524
4733
|
start: r * o,
|
|
4525
4734
|
limit: o,
|
|
4526
4735
|
length: c.length
|
|
@@ -4538,27 +4747,27 @@ function Hr(e) {
|
|
|
4538
4747
|
}
|
|
4539
4748
|
//#endregion
|
|
4540
4749
|
//#region src/helpers/monotonic-id.ts
|
|
4541
|
-
var
|
|
4542
|
-
function
|
|
4750
|
+
var ni = "0123456789ABCDEFGHJKMNPQRSTVWXYZ", ri = 32, ii = 10, ai = 4, oi = 10;
|
|
4751
|
+
function si(e, t) {
|
|
4543
4752
|
let n = "";
|
|
4544
|
-
for (let r = t; r > 0; r--) n =
|
|
4753
|
+
for (let r = t; r > 0; r--) n = ni.charAt(e % ri) + n, e = Math.floor(e / ri);
|
|
4545
4754
|
return n;
|
|
4546
4755
|
}
|
|
4547
|
-
function
|
|
4548
|
-
let e = new Uint8Array(
|
|
4756
|
+
function ci() {
|
|
4757
|
+
let e = new Uint8Array(oi);
|
|
4549
4758
|
crypto.getRandomValues(e);
|
|
4550
4759
|
let t = "";
|
|
4551
|
-
for (let n = 0; n <
|
|
4760
|
+
for (let n = 0; n < oi; n++) t += ni.charAt(e[n] % ri);
|
|
4552
4761
|
return t;
|
|
4553
4762
|
}
|
|
4554
|
-
var
|
|
4555
|
-
function
|
|
4763
|
+
var li = 0, ui = 0;
|
|
4764
|
+
function di() {
|
|
4556
4765
|
let e = Date.now();
|
|
4557
|
-
return e ===
|
|
4766
|
+
return e === li ? ui++ : (li = e, ui = 0), si(e, ii) + si(ui, ai) + ci();
|
|
4558
4767
|
}
|
|
4559
4768
|
//#endregion
|
|
4560
4769
|
//#region src/adapters/tenantOperationEvents.ts
|
|
4561
|
-
function
|
|
4770
|
+
function fi(e) {
|
|
4562
4771
|
if (!e) return null;
|
|
4563
4772
|
try {
|
|
4564
4773
|
let t = JSON.parse(e);
|
|
@@ -4566,22 +4775,22 @@ function $r(e) {
|
|
|
4566
4775
|
} catch {}
|
|
4567
4776
|
return null;
|
|
4568
4777
|
}
|
|
4569
|
-
function
|
|
4570
|
-
return
|
|
4778
|
+
function pi(e) {
|
|
4779
|
+
return be.parse({
|
|
4571
4780
|
id: e.id,
|
|
4572
4781
|
operation_id: e.operation_id,
|
|
4573
4782
|
step: e.step,
|
|
4574
4783
|
outcome: e.outcome,
|
|
4575
|
-
detail:
|
|
4784
|
+
detail: fi(e.detail),
|
|
4576
4785
|
attempt: e.attempt,
|
|
4577
4786
|
created_at: e.created_at
|
|
4578
4787
|
});
|
|
4579
4788
|
}
|
|
4580
|
-
function
|
|
4789
|
+
function mi(e) {
|
|
4581
4790
|
return {
|
|
4582
4791
|
async create(t) {
|
|
4583
|
-
let n =
|
|
4584
|
-
id: `evt_${
|
|
4792
|
+
let n = ye.parse(t), r = {
|
|
4793
|
+
id: `evt_${di()}`,
|
|
4585
4794
|
operation_id: n.operation_id,
|
|
4586
4795
|
step: n.step,
|
|
4587
4796
|
outcome: n.outcome,
|
|
@@ -4589,7 +4798,7 @@ function ti(e) {
|
|
|
4589
4798
|
attempt: n.attempt,
|
|
4590
4799
|
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
4591
4800
|
};
|
|
4592
|
-
return await e.insert(
|
|
4801
|
+
return await e.insert(Qr).values(r), be.parse({
|
|
4593
4802
|
id: r.id,
|
|
4594
4803
|
operation_id: r.operation_id,
|
|
4595
4804
|
step: r.step,
|
|
@@ -4600,9 +4809,9 @@ function ti(e) {
|
|
|
4600
4809
|
});
|
|
4601
4810
|
},
|
|
4602
4811
|
async listByOperation(t, r = {}) {
|
|
4603
|
-
let i = r.page ?? 0, o = r.per_page ?? 100, s = await e.select().from(
|
|
4812
|
+
let i = r.page ?? 0, o = r.per_page ?? 100, s = await e.select().from(Qr).where(a(Qr.operation_id, t)).orderBy(n(Qr.created_at), n(Qr.id)).offset(i * o).limit(o);
|
|
4604
4813
|
return {
|
|
4605
|
-
events: s.map(
|
|
4814
|
+
events: s.map(pi),
|
|
4606
4815
|
start: i * o,
|
|
4607
4816
|
limit: o,
|
|
4608
4817
|
length: s.length
|
|
@@ -4612,7 +4821,7 @@ function ti(e) {
|
|
|
4612
4821
|
}
|
|
4613
4822
|
//#endregion
|
|
4614
4823
|
//#region src/adapters/rollouts.ts
|
|
4615
|
-
function
|
|
4824
|
+
function hi(e) {
|
|
4616
4825
|
if (!e) return null;
|
|
4617
4826
|
try {
|
|
4618
4827
|
return JSON.parse(e);
|
|
@@ -4620,7 +4829,7 @@ function ni(e) {
|
|
|
4620
4829
|
return null;
|
|
4621
4830
|
}
|
|
4622
4831
|
}
|
|
4623
|
-
function
|
|
4832
|
+
function gi(e) {
|
|
4624
4833
|
return ge.parse({
|
|
4625
4834
|
id: e.id,
|
|
4626
4835
|
kind: e.kind,
|
|
@@ -4628,15 +4837,15 @@ function ri(e) {
|
|
|
4628
4837
|
target_worker_version: e.target_worker_version,
|
|
4629
4838
|
target_database_version: e.target_database_version,
|
|
4630
4839
|
wave_size: e.wave_size,
|
|
4631
|
-
canary_tenant_ids:
|
|
4632
|
-
filter:
|
|
4840
|
+
canary_tenant_ids: hi(e.canary_tenant_ids),
|
|
4841
|
+
filter: hi(e.filter),
|
|
4633
4842
|
initiated_by: e.initiated_by,
|
|
4634
4843
|
created_at: e.created_at,
|
|
4635
4844
|
updated_at: e.updated_at,
|
|
4636
4845
|
finished_at: e.finished_at
|
|
4637
4846
|
});
|
|
4638
4847
|
}
|
|
4639
|
-
function
|
|
4848
|
+
function _i(e) {
|
|
4640
4849
|
return {
|
|
4641
4850
|
async create(t) {
|
|
4642
4851
|
let n = he.parse(t), r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
@@ -4653,90 +4862,93 @@ function ii(e) {
|
|
|
4653
4862
|
updated_at: r,
|
|
4654
4863
|
finished_at: null
|
|
4655
4864
|
};
|
|
4656
|
-
await e.insert(
|
|
4865
|
+
await e.insert($r).values(i);
|
|
4657
4866
|
let a = await this.get(i.id);
|
|
4658
4867
|
if (!a) throw Error(`Failed to create rollout ${i.id}`);
|
|
4659
4868
|
return a;
|
|
4660
4869
|
},
|
|
4661
4870
|
async get(t) {
|
|
4662
|
-
let n = await e.select().from(
|
|
4663
|
-
return n[0] ?
|
|
4871
|
+
let n = await e.select().from($r).where(a($r.id, t)).limit(1);
|
|
4872
|
+
return n[0] ? gi(n[0]) : null;
|
|
4664
4873
|
},
|
|
4665
4874
|
async list(t = {}) {
|
|
4666
|
-
let n = t.page ?? 0, r = t.per_page ?? 50, a = await e.select().from(
|
|
4875
|
+
let n = t.page ?? 0, r = t.per_page ?? 50, a = await e.select().from($r).orderBy(i($r.created_at), i($r.id)).offset(n * r).limit(r);
|
|
4667
4876
|
return {
|
|
4668
|
-
rollouts: a.map(
|
|
4877
|
+
rollouts: a.map(gi),
|
|
4669
4878
|
start: n * r,
|
|
4670
4879
|
limit: r,
|
|
4671
4880
|
length: a.length
|
|
4672
4881
|
};
|
|
4673
4882
|
},
|
|
4674
4883
|
async update(t, n) {
|
|
4675
|
-
if ((await e.select({ id:
|
|
4884
|
+
if ((await e.select({ id: $r.id }).from($r).where(a($r.id, t)).limit(1)).length === 0) return !1;
|
|
4676
4885
|
let r = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
4677
|
-
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(
|
|
4886
|
+
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($r).set(r).where(a($r.id, t)), !0;
|
|
4678
4887
|
},
|
|
4679
4888
|
async remove(t) {
|
|
4680
|
-
return (await e.select({ id:
|
|
4889
|
+
return (await e.select({ id: $r.id }).from($r).where(a($r.id, t)).limit(1)).length === 0 ? !1 : (await e.delete($r).where(a($r.id, t)), !0);
|
|
4681
4890
|
}
|
|
4682
4891
|
};
|
|
4683
4892
|
}
|
|
4684
4893
|
//#endregion
|
|
4685
4894
|
//#region src/adapters/index.ts
|
|
4686
|
-
function
|
|
4895
|
+
function vi(e, t = { useTransactions: !0 }) {
|
|
4687
4896
|
let n = {
|
|
4688
|
-
actions:
|
|
4689
|
-
actionExecutions:
|
|
4690
|
-
actionVersions:
|
|
4691
|
-
branding:
|
|
4692
|
-
clients:
|
|
4693
|
-
clientConnections:
|
|
4694
|
-
clientGrants:
|
|
4695
|
-
clientRegistrationTokens:
|
|
4696
|
-
codes:
|
|
4697
|
-
connections:
|
|
4698
|
-
customDomains:
|
|
4699
|
-
customText:
|
|
4700
|
-
emailProviders:
|
|
4701
|
-
emailTemplates:
|
|
4702
|
-
flows:
|
|
4703
|
-
forms:
|
|
4704
|
-
grants:
|
|
4705
|
-
hookCode:
|
|
4706
|
-
hooks:
|
|
4707
|
-
invites:
|
|
4708
|
-
keys:
|
|
4709
|
-
loginSessions:
|
|
4710
|
-
logs:
|
|
4711
|
-
authenticationMethods:
|
|
4712
|
-
organizations:
|
|
4713
|
-
passwords:
|
|
4714
|
-
promptSettings:
|
|
4715
|
-
proxyRoutes:
|
|
4716
|
-
|
|
4717
|
-
|
|
4718
|
-
|
|
4719
|
-
|
|
4720
|
-
|
|
4721
|
-
|
|
4722
|
-
|
|
4723
|
-
|
|
4897
|
+
actions: at(e),
|
|
4898
|
+
actionExecutions: st(e),
|
|
4899
|
+
actionVersions: dt(e),
|
|
4900
|
+
branding: pt(e),
|
|
4901
|
+
clients: wt(e),
|
|
4902
|
+
clientConnections: Et(e),
|
|
4903
|
+
clientGrants: Ot(e),
|
|
4904
|
+
clientRegistrationTokens: Nt(e),
|
|
4905
|
+
codes: Lt(e),
|
|
4906
|
+
connections: Bt(e),
|
|
4907
|
+
customDomains: Ht(e),
|
|
4908
|
+
customText: Ut(e),
|
|
4909
|
+
emailProviders: Wt(e),
|
|
4910
|
+
emailTemplates: Kt(e),
|
|
4911
|
+
flows: Jt(e),
|
|
4912
|
+
forms: Zt(e),
|
|
4913
|
+
grants: tn(e),
|
|
4914
|
+
hookCode: on(e),
|
|
4915
|
+
hooks: un(e),
|
|
4916
|
+
invites: mn(e),
|
|
4917
|
+
keys: gn(e),
|
|
4918
|
+
loginSessions: xn(e),
|
|
4919
|
+
logs: Cn(e),
|
|
4920
|
+
authenticationMethods: On(e),
|
|
4921
|
+
organizations: Mn(e),
|
|
4922
|
+
passwords: Pn(e),
|
|
4923
|
+
promptSettings: Fn(e),
|
|
4924
|
+
proxyRoutes: zn(e),
|
|
4925
|
+
scimConfigurations: Un(e),
|
|
4926
|
+
scimTokens: Gn(e),
|
|
4927
|
+
scimExternalIds: qn(e),
|
|
4928
|
+
refreshTokens: Xn(e),
|
|
4929
|
+
resourceServers: nr(e),
|
|
4930
|
+
rolePermissions: rr(e),
|
|
4931
|
+
userPermissions: ir(e),
|
|
4932
|
+
roles: or(e),
|
|
4933
|
+
sessions: dr(e),
|
|
4934
|
+
sessionCleanup: Zr(e),
|
|
4935
|
+
tenants: gr(e),
|
|
4724
4936
|
...t.controlPlane ? {
|
|
4725
|
-
tenantOperations:
|
|
4726
|
-
tenantOperationEvents:
|
|
4727
|
-
rollouts:
|
|
4937
|
+
tenantOperations: ti(e),
|
|
4938
|
+
tenantOperationEvents: mi(e),
|
|
4939
|
+
rollouts: _i(e)
|
|
4728
4940
|
} : {},
|
|
4729
|
-
themes:
|
|
4730
|
-
universalLoginTemplates:
|
|
4731
|
-
users:
|
|
4732
|
-
userActivity:
|
|
4733
|
-
userRoles:
|
|
4734
|
-
userOrganizations:
|
|
4735
|
-
stats:
|
|
4736
|
-
analytics:
|
|
4737
|
-
outbox:
|
|
4941
|
+
themes: yr(e),
|
|
4942
|
+
universalLoginTemplates: br(e),
|
|
4943
|
+
users: Lr(e),
|
|
4944
|
+
userActivity: Sr(e),
|
|
4945
|
+
userRoles: Rr(e),
|
|
4946
|
+
userOrganizations: zr(e),
|
|
4947
|
+
stats: Ur(e),
|
|
4948
|
+
analytics: Yr(e),
|
|
4949
|
+
outbox: Tr(e),
|
|
4738
4950
|
async transaction(r) {
|
|
4739
|
-
if (t.useTransactions === !1 ||
|
|
4951
|
+
if (t.useTransactions === !1 || ct(e)) return r(n);
|
|
4740
4952
|
await e.run(y`BEGIN`);
|
|
4741
4953
|
try {
|
|
4742
4954
|
let t = await r(n);
|
|
@@ -4750,7 +4962,7 @@ function ai(e, t = { useTransactions: !0 }) {
|
|
|
4750
4962
|
}
|
|
4751
4963
|
//#endregion
|
|
4752
4964
|
//#region src/adapters/resolveHost.ts
|
|
4753
|
-
function
|
|
4965
|
+
function yi(e) {
|
|
4754
4966
|
if (!e) return { path: "/*" };
|
|
4755
4967
|
try {
|
|
4756
4968
|
let t = JSON.parse(e), n = me.safeParse(t);
|
|
@@ -4758,7 +4970,7 @@ function oi(e) {
|
|
|
4758
4970
|
} catch {}
|
|
4759
4971
|
return { path: "/*" };
|
|
4760
4972
|
}
|
|
4761
|
-
function
|
|
4973
|
+
function bi(e) {
|
|
4762
4974
|
if (!e) return [];
|
|
4763
4975
|
try {
|
|
4764
4976
|
let t = JSON.parse(e);
|
|
@@ -4773,20 +4985,20 @@ function si(e) {
|
|
|
4773
4985
|
return [];
|
|
4774
4986
|
}
|
|
4775
4987
|
}
|
|
4776
|
-
async function
|
|
4988
|
+
async function xi(e, r) {
|
|
4777
4989
|
let i = r.toLowerCase(), o = (await e.select({
|
|
4778
|
-
custom_domain_id:
|
|
4779
|
-
tenant_id:
|
|
4780
|
-
domain:
|
|
4781
|
-
}).from(
|
|
4990
|
+
custom_domain_id: Me.custom_domain_id,
|
|
4991
|
+
tenant_id: Me.tenant_id,
|
|
4992
|
+
domain: Me.domain
|
|
4993
|
+
}).from(Me).where(a(Me.domain, i)).limit(1))[0];
|
|
4782
4994
|
if (!o) return null;
|
|
4783
|
-
let s = (await e.select().from(
|
|
4995
|
+
let s = (await e.select().from(X).where(t(a(X.tenant_id, o.tenant_id), a(X.custom_domain_id, o.custom_domain_id))).orderBy(n(X.priority), n(X.created_at))).map((e) => ({
|
|
4784
4996
|
id: e.id,
|
|
4785
4997
|
tenant_id: e.tenant_id,
|
|
4786
4998
|
custom_domain_id: e.custom_domain_id,
|
|
4787
4999
|
priority: e.priority,
|
|
4788
|
-
match:
|
|
4789
|
-
handlers:
|
|
5000
|
+
match: yi(e.match),
|
|
5001
|
+
handlers: bi(e.handlers),
|
|
4790
5002
|
created_at: e.created_at,
|
|
4791
5003
|
updated_at: e.updated_at
|
|
4792
5004
|
}));
|
|
@@ -4799,11 +5011,11 @@ async function ci(e, r) {
|
|
|
4799
5011
|
}
|
|
4800
5012
|
//#endregion
|
|
4801
5013
|
//#region src/adapters/proxyData.ts
|
|
4802
|
-
function
|
|
5014
|
+
function Si(e) {
|
|
4803
5015
|
return {
|
|
4804
|
-
proxyRoutes:
|
|
4805
|
-
resolveHost: (t) =>
|
|
5016
|
+
proxyRoutes: zn(e),
|
|
5017
|
+
resolveHost: (t) => xi(e, t)
|
|
4806
5018
|
};
|
|
4807
5019
|
}
|
|
4808
5020
|
//#endregion
|
|
4809
|
-
export {
|
|
5021
|
+
export { Si as createProxyDataAdapter, zn as createProxyRoutesAdapter, vi as default, Ze as sqlite };
|