@authhero/drizzle 1.6.0 → 1.6.2

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