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