@authhero/drizzle 0.36.0 → 0.37.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,20 +1,20 @@
1
1
  var yr = Object.defineProperty;
2
- var wr = (i, n, e) => n in i ? yr(i, n, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[n] = e;
3
- var m = (i, n, e) => wr(i, typeof n != "symbol" ? n + "" : n, e);
2
+ var wr = (n, i, e) => i in n ? yr(n, i, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[i] = e;
3
+ var m = (n, i, e) => wr(n, typeof i != "symbol" ? i + "" : i, e);
4
4
  const v = Symbol.for("drizzle:entityKind");
5
- function Y(i, n) {
6
- if (!i || typeof i != "object")
5
+ function Y(n, i) {
6
+ if (!n || typeof n != "object")
7
7
  return !1;
8
- if (i instanceof n)
8
+ if (n instanceof i)
9
9
  return !0;
10
- if (!Object.prototype.hasOwnProperty.call(n, v))
10
+ if (!Object.prototype.hasOwnProperty.call(i, v))
11
11
  throw new Error(
12
- `Class "${n.name ?? "<unknown>"}" doesn't look like a Drizzle entity. If this is incorrect and the class is provided by Drizzle, please report this as a bug.`
12
+ `Class "${i.name ?? "<unknown>"}" doesn't look like a Drizzle entity. If this is incorrect and the class is provided by Drizzle, please report this as a bug.`
13
13
  );
14
- let e = Object.getPrototypeOf(i).constructor;
14
+ let e = Object.getPrototypeOf(n).constructor;
15
15
  if (e)
16
16
  for (; e; ) {
17
- if (v in e && e[v] === n[v])
17
+ if (v in e && e[v] === i[v])
18
18
  return !0;
19
19
  e = Object.getPrototypeOf(e);
20
20
  }
@@ -23,7 +23,7 @@ function Y(i, n) {
23
23
  var jt;
24
24
  jt = v;
25
25
  class Qe {
26
- constructor(n, e) {
26
+ constructor(i, e) {
27
27
  m(this, "name");
28
28
  m(this, "keyAsName");
29
29
  m(this, "primary");
@@ -41,13 +41,13 @@ class Qe {
41
41
  m(this, "generated");
42
42
  m(this, "generatedIdentity");
43
43
  m(this, "config");
44
- this.table = n, this.config = e, this.name = e.name, this.keyAsName = e.keyAsName, this.notNull = e.notNull, this.default = e.default, this.defaultFn = e.defaultFn, this.onUpdateFn = e.onUpdateFn, this.hasDefault = e.hasDefault, this.primary = e.primaryKey, this.isUnique = e.isUnique, this.uniqueName = e.uniqueName, this.uniqueType = e.uniqueType, this.dataType = e.dataType, this.columnType = e.columnType, this.generated = e.generated, this.generatedIdentity = e.generatedIdentity;
44
+ this.table = i, this.config = e, this.name = e.name, this.keyAsName = e.keyAsName, this.notNull = e.notNull, this.default = e.default, this.defaultFn = e.defaultFn, this.onUpdateFn = e.onUpdateFn, this.hasDefault = e.hasDefault, this.primary = e.primaryKey, this.isUnique = e.isUnique, this.uniqueName = e.uniqueName, this.uniqueType = e.uniqueType, this.dataType = e.dataType, this.columnType = e.columnType, this.generated = e.generated, this.generatedIdentity = e.generatedIdentity;
45
45
  }
46
- mapFromDriverValue(n) {
47
- return n;
46
+ mapFromDriverValue(i) {
47
+ return i;
48
48
  }
49
- mapToDriverValue(n) {
50
- return n;
49
+ mapToDriverValue(i) {
50
+ return i;
51
51
  }
52
52
  // ** @internal */
53
53
  shouldDisableInsert() {
@@ -58,7 +58,7 @@ m(Qe, jt, "Column");
58
58
  var Mt;
59
59
  Mt = v;
60
60
  class Ti {
61
- constructor(n, e, t) {
61
+ constructor(i, e, t) {
62
62
  m(this, "config");
63
63
  /**
64
64
  * Alias for {@link $defaultFn}.
@@ -69,8 +69,8 @@ class Ti {
69
69
  */
70
70
  m(this, "$onUpdate", this.$onUpdateFn);
71
71
  this.config = {
72
- name: n,
73
- keyAsName: n === "",
72
+ name: i,
73
+ keyAsName: i === "",
74
74
  notNull: !1,
75
75
  default: void 0,
76
76
  hasDefault: !1,
@@ -112,8 +112,8 @@ class Ti {
112
112
  *
113
113
  * If you need to set a dynamic default value, use {@link $defaultFn} instead.
114
114
  */
115
- default(n) {
116
- return this.config.default = n, this.config.hasDefault = !0, this;
115
+ default(i) {
116
+ return this.config.default = i, this.config.hasDefault = !0, this;
117
117
  }
118
118
  /**
119
119
  * Adds a dynamic default value to the column.
@@ -121,8 +121,8 @@ class Ti {
121
121
  *
122
122
  * **Note:** This value does not affect the `drizzle-kit` behavior, it is only used at runtime in `drizzle-orm`.
123
123
  */
124
- $defaultFn(n) {
125
- return this.config.defaultFn = n, this.config.hasDefault = !0, this;
124
+ $defaultFn(i) {
125
+ return this.config.defaultFn = i, this.config.hasDefault = !0, this;
126
126
  }
127
127
  /**
128
128
  * Adds a dynamic update value to the column.
@@ -131,8 +131,8 @@ class Ti {
131
131
  *
132
132
  * **Note:** This value does not affect the `drizzle-kit` behavior, it is only used at runtime in `drizzle-orm`.
133
133
  */
134
- $onUpdateFn(n) {
135
- return this.config.onUpdateFn = n, this.config.hasDefault = !0, this;
134
+ $onUpdateFn(i) {
135
+ return this.config.onUpdateFn = i, this.config.hasDefault = !0, this;
136
136
  }
137
137
  /**
138
138
  * Adds a `primary key` clause to the column definition. This implicitly makes the column `not null`.
@@ -143,22 +143,22 @@ class Ti {
143
143
  return this.config.primaryKey = !0, this.config.notNull = !0, this;
144
144
  }
145
145
  /** @internal Sets the name of the column to the key within the table definition if a name was not given. */
146
- setName(n) {
147
- this.config.name === "" && (this.config.name = n);
146
+ setName(i) {
147
+ this.config.name === "" && (this.config.name = i);
148
148
  }
149
149
  }
150
150
  m(Ti, Mt, "ColumnBuilder");
151
151
  const ze = Symbol.for("drizzle:Name"), Tt = Symbol.for("drizzle:isPgEnum");
152
- function Nr(i) {
153
- return !!i && typeof i == "function" && Tt in i && i[Tt] === !0;
152
+ function Nr(n) {
153
+ return !!n && typeof n == "function" && Tt in n && n[Tt] === !0;
154
154
  }
155
155
  var Vt;
156
156
  Vt = v;
157
157
  class xt {
158
- constructor(n, e, t, r = !1, o = []) {
158
+ constructor(i, e, t, r = !1, o = []) {
159
159
  this._ = {
160
160
  brand: "Subquery",
161
- sql: n,
161
+ sql: i,
162
162
  selectedFields: e,
163
163
  alias: t,
164
164
  isWith: r,
@@ -171,14 +171,14 @@ class xt {
171
171
  }
172
172
  m(xt, Vt, "Subquery");
173
173
  const vr = {
174
- startActiveSpan(i, n) {
175
- return n();
174
+ startActiveSpan(n, i) {
175
+ return i();
176
176
  }
177
177
  }, Ae = Symbol.for("drizzle:ViewBaseConfig"), Ze = Symbol.for("drizzle:Schema"), qt = Symbol.for("drizzle:Columns"), Lt = Symbol.for("drizzle:ExtraConfigColumns"), et = Symbol.for("drizzle:OriginalName"), tt = Symbol.for("drizzle:BaseName"), Re = Symbol.for("drizzle:IsAlias"), Et = Symbol.for("drizzle:ExtraConfigBuilder"), Sr = Symbol.for("drizzle:IsDrizzleTable");
178
178
  var Rt, Wt, Ht, Gt, Yt, Xt, Zt, en, tn, nn;
179
179
  nn = v, tn = ze, en = et, Zt = Ze, Xt = qt, Yt = Lt, Gt = tt, Ht = Re, Wt = Sr, Rt = Et;
180
180
  class j {
181
- constructor(n, e, t) {
181
+ constructor(i, e, t) {
182
182
  /**
183
183
  * @internal
184
184
  * Can be changed if the table is aliased.
@@ -206,7 +206,7 @@ class j {
206
206
  m(this, Wt, !0);
207
207
  /** @internal */
208
208
  m(this, Rt);
209
- this[ze] = this[et] = n, this[Ze] = e, this[tt] = t;
209
+ this[ze] = this[et] = i, this[Ze] = e, this[tt] = t;
210
210
  }
211
211
  }
212
212
  m(j, nn, "Table"), /** @internal */
@@ -220,22 +220,22 @@ m(j, "Symbol", {
220
220
  IsAlias: Re,
221
221
  ExtraConfigBuilder: Et
222
222
  });
223
- function qi(i) {
224
- return i != null && typeof i.getSQL == "function";
223
+ function qi(n) {
224
+ return n != null && typeof n.getSQL == "function";
225
225
  }
226
- function br(i) {
226
+ function br(n) {
227
227
  var e;
228
- const n = { sql: "", params: [] };
229
- for (const t of i)
230
- n.sql += t.sql, n.params.push(...t.params), (e = t.typings) != null && e.length && (n.typings || (n.typings = []), n.typings.push(...t.typings));
231
- return n;
228
+ const i = { sql: "", params: [] };
229
+ for (const t of n)
230
+ i.sql += t.sql, i.params.push(...t.params), (e = t.typings) != null && e.length && (i.typings || (i.typings = []), i.typings.push(...t.typings));
231
+ return i;
232
232
  }
233
233
  var rn;
234
234
  rn = v;
235
235
  class X {
236
- constructor(n) {
236
+ constructor(i) {
237
237
  m(this, "value");
238
- this.value = Array.isArray(n) ? n : [n];
238
+ this.value = Array.isArray(i) ? i : [i];
239
239
  }
240
240
  getSQL() {
241
241
  return new Q([this]);
@@ -245,14 +245,14 @@ m(X, rn, "StringChunk");
245
245
  var sn;
246
246
  sn = v;
247
247
  const De = class De {
248
- constructor(n) {
248
+ constructor(i) {
249
249
  /** @internal */
250
250
  m(this, "decoder", Li);
251
251
  m(this, "shouldInlineParams", !1);
252
252
  /** @internal */
253
253
  m(this, "usedTables", []);
254
- this.queryChunks = n;
255
- for (const e of n)
254
+ this.queryChunks = i;
255
+ for (const e of i)
256
256
  if (Y(e, j)) {
257
257
  const t = e[j.Symbol.Schema];
258
258
  this.usedTables.push(
@@ -260,19 +260,19 @@ const De = class De {
260
260
  );
261
261
  }
262
262
  }
263
- append(n) {
264
- return this.queryChunks.push(...n.queryChunks), this;
263
+ append(i) {
264
+ return this.queryChunks.push(...i.queryChunks), this;
265
265
  }
266
- toQuery(n) {
266
+ toQuery(i) {
267
267
  return vr.startActiveSpan("drizzle.buildSQL", (e) => {
268
- const t = this.buildQueryFromSourceParams(this.queryChunks, n);
268
+ const t = this.buildQueryFromSourceParams(this.queryChunks, i);
269
269
  return e == null || e.setAttributes({
270
270
  "drizzle.query.text": t.sql,
271
271
  "drizzle.query.params": JSON.stringify(t.params)
272
272
  }), t;
273
273
  });
274
274
  }
275
- buildQueryFromSourceParams(n, e) {
275
+ buildQueryFromSourceParams(i, e) {
276
276
  const t = Object.assign({}, e, {
277
277
  inlineParams: e.inlineParams || this.shouldInlineParams,
278
278
  paramStartIndex: e.paramStartIndex || { value: 0 }
@@ -284,7 +284,7 @@ const De = class De {
284
284
  inlineParams: d,
285
285
  paramStartIndex: c
286
286
  } = t;
287
- return br(n.map((u) => {
287
+ return br(i.map((u) => {
288
288
  var h;
289
289
  if (Y(u, X))
290
290
  return { sql: u.value.join(""), params: [] };
@@ -350,27 +350,27 @@ const De = class De {
350
350
  ], t) : d ? { sql: this.mapInlineParam(u, t), params: [] } : { sql: l(c.value++, u), params: [u], typings: ["none"] };
351
351
  }));
352
352
  }
353
- mapInlineParam(n, { escapeString: e }) {
354
- if (n === null)
353
+ mapInlineParam(i, { escapeString: e }) {
354
+ if (i === null)
355
355
  return "null";
356
- if (typeof n == "number" || typeof n == "boolean")
357
- return n.toString();
358
- if (typeof n == "string")
359
- return e(n);
360
- if (typeof n == "object") {
361
- const t = n.toString();
362
- return e(t === "[object Object]" ? JSON.stringify(n) : t);
356
+ if (typeof i == "number" || typeof i == "boolean")
357
+ return i.toString();
358
+ if (typeof i == "string")
359
+ return e(i);
360
+ if (typeof i == "object") {
361
+ const t = i.toString();
362
+ return e(t === "[object Object]" ? JSON.stringify(i) : t);
363
363
  }
364
- throw new Error("Unexpected param value: " + n);
364
+ throw new Error("Unexpected param value: " + i);
365
365
  }
366
366
  getSQL() {
367
367
  return this;
368
368
  }
369
- as(n) {
370
- return n === void 0 ? this : new De.Aliased(this, n);
369
+ as(i) {
370
+ return i === void 0 ? this : new De.Aliased(this, i);
371
371
  }
372
- mapWith(n) {
373
- return this.decoder = typeof n == "function" ? { mapFromDriverValue: n } : n, this;
372
+ mapWith(i) {
373
+ return this.decoder = typeof i == "function" ? { mapFromDriverValue: i } : i, this;
374
374
  }
375
375
  inlineParams() {
376
376
  return this.shouldInlineParams = !0, this;
@@ -381,8 +381,8 @@ const De = class De {
381
381
  * @param condition - Condition to check
382
382
  * @returns itself if the condition is `true`, otherwise `undefined`
383
383
  */
384
- if(n) {
385
- return n ? this : void 0;
384
+ if(i) {
385
+ return i ? this : void 0;
386
386
  }
387
387
  };
388
388
  m(De, sn, "SQL");
@@ -390,22 +390,22 @@ let Q = De;
390
390
  var on;
391
391
  on = v;
392
392
  class We {
393
- constructor(n) {
393
+ constructor(i) {
394
394
  m(this, "brand");
395
- this.value = n;
395
+ this.value = i;
396
396
  }
397
397
  getSQL() {
398
398
  return new Q([this]);
399
399
  }
400
400
  }
401
401
  m(We, on, "Name");
402
- function xr(i) {
403
- return typeof i == "object" && i !== null && "mapToDriverValue" in i && typeof i.mapToDriverValue == "function";
402
+ function xr(n) {
403
+ return typeof n == "object" && n !== null && "mapToDriverValue" in n && typeof n.mapToDriverValue == "function";
404
404
  }
405
405
  const Li = {
406
- mapFromDriverValue: (i) => i
406
+ mapFromDriverValue: (n) => n
407
407
  }, Ei = {
408
- mapToDriverValue: (i) => i
408
+ mapToDriverValue: (n) => n
409
409
  };
410
410
  ({
411
411
  ...Li,
@@ -418,56 +418,56 @@ class Ce {
418
418
  * @param value - Parameter value
419
419
  * @param encoder - Encoder to convert the value to a driver parameter
420
420
  */
421
- constructor(n, e = Ei) {
421
+ constructor(i, e = Ei) {
422
422
  m(this, "brand");
423
- this.value = n, this.encoder = e;
423
+ this.value = i, this.encoder = e;
424
424
  }
425
425
  getSQL() {
426
426
  return new Q([this]);
427
427
  }
428
428
  }
429
429
  m(Ce, an, "Param");
430
- function N(i, ...n) {
430
+ function N(n, ...i) {
431
431
  const e = [];
432
- (n.length > 0 || i.length > 0 && i[0] !== "") && e.push(new X(i[0]));
433
- for (const [t, r] of n.entries())
434
- e.push(r, new X(i[t + 1]));
432
+ (i.length > 0 || n.length > 0 && n[0] !== "") && e.push(new X(n[0]));
433
+ for (const [t, r] of i.entries())
434
+ e.push(r, new X(n[t + 1]));
435
435
  return new Q(e);
436
436
  }
437
- ((i) => {
438
- function n() {
437
+ ((n) => {
438
+ function i() {
439
439
  return new Q([]);
440
440
  }
441
- i.empty = n;
441
+ n.empty = i;
442
442
  function e(d) {
443
443
  return new Q(d);
444
444
  }
445
- i.fromList = e;
445
+ n.fromList = e;
446
446
  function t(d) {
447
447
  return new Q([new X(d)]);
448
448
  }
449
- i.raw = t;
449
+ n.raw = t;
450
450
  function r(d, c) {
451
451
  const u = [];
452
452
  for (const [h, f] of d.entries())
453
453
  h > 0 && c !== void 0 && u.push(c), u.push(f);
454
454
  return new Q(u);
455
455
  }
456
- i.join = r;
456
+ n.join = r;
457
457
  function o(d) {
458
458
  return new We(d);
459
459
  }
460
- i.identifier = o;
460
+ n.identifier = o;
461
461
  function l(d) {
462
462
  return new $e(d);
463
463
  }
464
- i.placeholder = l;
464
+ n.placeholder = l;
465
465
  function _(d, c) {
466
466
  return new Ce(d, c);
467
467
  }
468
- i.param = _;
468
+ n.param = _;
469
469
  })(N || (N = {}));
470
- ((i) => {
470
+ ((n) => {
471
471
  var e;
472
472
  e = v;
473
473
  const t = class t {
@@ -485,14 +485,14 @@ function N(i, ...n) {
485
485
  }
486
486
  };
487
487
  m(t, e, "SQL.Aliased");
488
- let n = t;
489
- i.Aliased = n;
488
+ let i = t;
489
+ n.Aliased = i;
490
490
  })(Q || (Q = {}));
491
491
  var ln;
492
492
  ln = v;
493
493
  class $e {
494
- constructor(n) {
495
- this.name = n;
494
+ constructor(i) {
495
+ this.name = i;
496
496
  }
497
497
  getSQL() {
498
498
  return new Q([this]);
@@ -503,14 +503,14 @@ const Dr = Symbol.for("drizzle:IsDrizzleView");
503
503
  var _n, un, dn;
504
504
  dn = v, un = Ae, _n = Dr;
505
505
  class Dt {
506
- constructor({ name: n, schema: e, selectedFields: t, query: r }) {
506
+ constructor({ name: i, schema: e, selectedFields: t, query: r }) {
507
507
  /** @internal */
508
508
  m(this, un);
509
509
  /** @internal */
510
510
  m(this, _n, !0);
511
511
  this[Ae] = {
512
- name: n,
513
- originalName: n,
512
+ name: i,
513
+ originalName: i,
514
514
  schema: e,
515
515
  selectedFields: t,
516
516
  query: r,
@@ -532,79 +532,79 @@ j.prototype.getSQL = function() {
532
532
  xt.prototype.getSQL = function() {
533
533
  return new Q([this]);
534
534
  };
535
- function Je(i, n) {
535
+ function Je(n, i) {
536
536
  return {
537
- name: typeof i == "string" && i.length > 0 ? i : "",
538
- config: typeof i == "object" ? i : n
537
+ name: typeof n == "string" && n.length > 0 ? n : "",
538
+ config: typeof n == "object" ? n : i
539
539
  };
540
540
  }
541
541
  const Ai = typeof TextDecoder > "u" ? null : new TextDecoder();
542
- function Se(i, n) {
543
- return xr(n) && !qi(i) && !Y(i, Ce) && !Y(i, $e) && !Y(i, Qe) && !Y(i, j) && !Y(i, Dt) ? new Ce(i, n) : i;
542
+ function Se(n, i) {
543
+ return xr(i) && !qi(n) && !Y(n, Ce) && !Y(n, $e) && !Y(n, Qe) && !Y(n, j) && !Y(n, Dt) ? new Ce(n, i) : n;
544
544
  }
545
- const a = (i, n) => N`${i} = ${Se(n, i)}`, Or = (i, n) => N`${i} <> ${Se(n, i)}`;
546
- function g(...i) {
547
- const n = i.filter(
545
+ const a = (n, i) => N`${n} = ${Se(i, n)}`, Or = (n, i) => N`${n} <> ${Se(i, n)}`;
546
+ function g(...n) {
547
+ const i = n.filter(
548
548
  (e) => e !== void 0
549
549
  );
550
- if (n.length !== 0)
551
- return n.length === 1 ? new Q(n) : new Q([
550
+ if (i.length !== 0)
551
+ return i.length === 1 ? new Q(i) : new Q([
552
552
  new X("("),
553
- N.join(n, new X(" and ")),
553
+ N.join(i, new X(" and ")),
554
554
  new X(")")
555
555
  ]);
556
556
  }
557
- function de(...i) {
558
- const n = i.filter(
557
+ function de(...n) {
558
+ const i = n.filter(
559
559
  (e) => e !== void 0
560
560
  );
561
- if (n.length !== 0)
562
- return n.length === 1 ? new Q(n) : new Q([
561
+ if (i.length !== 0)
562
+ return i.length === 1 ? new Q(i) : new Q([
563
563
  new X("("),
564
- N.join(n, new X(" or ")),
564
+ N.join(i, new X(" or ")),
565
565
  new X(")")
566
566
  ]);
567
567
  }
568
- const He = (i, n) => N`${i} > ${Se(n, i)}`, Ge = (i, n) => N`${i} >= ${Se(n, i)}`, xe = (i, n) => N`${i} < ${Se(n, i)}`, Oe = (i, n) => N`${i} <= ${Se(n, i)}`;
569
- function we(i, n) {
570
- return Array.isArray(n) ? n.length === 0 ? N`false` : N`${i} in ${n.map((e) => Se(e, i))}` : N`${i} in ${Se(n, i)}`;
568
+ const He = (n, i) => N`${n} > ${Se(i, n)}`, Ge = (n, i) => N`${n} >= ${Se(i, n)}`, xe = (n, i) => N`${n} < ${Se(i, n)}`, Oe = (n, i) => N`${n} <= ${Se(i, n)}`;
569
+ function we(n, i) {
570
+ return Array.isArray(i) ? i.length === 0 ? N`false` : N`${n} in ${i.map((e) => Se(e, n))}` : N`${n} in ${Se(i, n)}`;
571
571
  }
572
- function ye(i) {
573
- return N`${i} is null`;
572
+ function ye(n) {
573
+ return N`${n} is null`;
574
574
  }
575
- function Ve(i) {
576
- return N`${i} is not null`;
575
+ function Ve(n) {
576
+ return N`${n} is not null`;
577
577
  }
578
- function Ie(i, n) {
579
- return N`${i} like ${n}`;
578
+ function Ie(n, i) {
579
+ return N`${n} like ${i}`;
580
580
  }
581
- function H(i) {
582
- return N`${i} asc`;
581
+ function H(n) {
582
+ return N`${n} asc`;
583
583
  }
584
- function M(i) {
585
- return N`${i} desc`;
584
+ function M(n) {
585
+ return N`${n} desc`;
586
586
  }
587
- function V(i) {
587
+ function V(n) {
588
588
  return N`count(${N.raw("*")})`.mapWith(Number);
589
589
  }
590
590
  function kr() {
591
- const i = (n) => {
591
+ const n = (i) => {
592
592
  throw new Error(
593
- `Actions are not implemented in the Drizzle adapter (called ${n}). Use the Kysely adapter for tenants that require actions.`
593
+ `Actions are not implemented in the Drizzle adapter (called ${i}). Use the Kysely adapter for tenants that require actions.`
594
594
  );
595
595
  };
596
596
  return {
597
- create: () => i("create"),
598
- get: () => i("get"),
599
- list: () => i("list"),
600
- update: () => i("update"),
601
- remove: () => i("remove")
597
+ create: () => n("create"),
598
+ get: () => n("get"),
599
+ list: () => n("list"),
600
+ update: () => n("update"),
601
+ remove: () => n("remove")
602
602
  };
603
603
  }
604
604
  var cn;
605
605
  cn = v;
606
606
  class Ci {
607
- constructor(n, e) {
607
+ constructor(i, e) {
608
608
  /** @internal */
609
609
  m(this, "reference");
610
610
  /** @internal */
@@ -612,44 +612,44 @@ class Ci {
612
612
  /** @internal */
613
613
  m(this, "_onDelete");
614
614
  this.reference = () => {
615
- const { name: t, columns: r, foreignColumns: o } = n();
615
+ const { name: t, columns: r, foreignColumns: o } = i();
616
616
  return { name: t, columns: r, foreignTable: o[0].table, foreignColumns: o };
617
617
  }, e && (this._onUpdate = e.onUpdate, this._onDelete = e.onDelete);
618
618
  }
619
- onUpdate(n) {
620
- return this._onUpdate = n, this;
619
+ onUpdate(i) {
620
+ return this._onUpdate = i, this;
621
621
  }
622
- onDelete(n) {
623
- return this._onDelete = n, this;
622
+ onDelete(i) {
623
+ return this._onDelete = i, this;
624
624
  }
625
625
  /** @internal */
626
- build(n) {
627
- return new $i(n, this);
626
+ build(i) {
627
+ return new $i(i, this);
628
628
  }
629
629
  }
630
630
  m(Ci, cn, "SQLiteForeignKeyBuilder");
631
631
  var gn;
632
632
  gn = v;
633
633
  class $i {
634
- constructor(n, e) {
634
+ constructor(i, e) {
635
635
  m(this, "reference");
636
636
  m(this, "onUpdate");
637
637
  m(this, "onDelete");
638
- this.table = n, this.reference = e.reference, this.onUpdate = e._onUpdate, this.onDelete = e._onDelete;
638
+ this.table = i, this.reference = e.reference, this.onUpdate = e._onUpdate, this.onDelete = e._onDelete;
639
639
  }
640
640
  getName() {
641
- const { name: n, columns: e, foreignColumns: t } = this.reference(), r = e.map((_) => _.name), o = t.map((_) => _.name), l = [
641
+ const { name: i, columns: e, foreignColumns: t } = this.reference(), r = e.map((_) => _.name), o = t.map((_) => _.name), l = [
642
642
  this.table[ze],
643
643
  ...r,
644
644
  t[0].table[ze],
645
645
  ...o
646
646
  ];
647
- return n ?? `${l.join("_")}_fk`;
647
+ return i ?? `${l.join("_")}_fk`;
648
648
  }
649
649
  }
650
650
  m($i, gn, "SQLiteForeignKey");
651
- function Ir(i, n) {
652
- return `${i[ze]}_${n.join("_")}_unique`;
651
+ function Ir(n, i) {
652
+ return `${n[ze]}_${i.join("_")}_unique`;
653
653
  }
654
654
  var fn, mn;
655
655
  class ce extends (mn = Ti, fn = v, mn) {
@@ -684,19 +684,19 @@ class ce extends (mn = Ti, fn = v, mn) {
684
684
  m(ce, fn, "SQLiteColumnBuilder");
685
685
  var hn, pn;
686
686
  class ge extends (pn = Qe, hn = v, pn) {
687
- constructor(n, e) {
688
- e.uniqueName || (e.uniqueName = Ir(n, [e.name])), super(n, e), this.table = n;
687
+ constructor(i, e) {
688
+ e.uniqueName || (e.uniqueName = Ir(i, [e.name])), super(i, e), this.table = i;
689
689
  }
690
690
  }
691
691
  m(ge, hn, "SQLiteColumn");
692
692
  var yn, wn;
693
693
  class Bi extends (wn = ce, yn = v, wn) {
694
- constructor(n) {
695
- super(n, "bigint", "SQLiteBigInt");
694
+ constructor(i) {
695
+ super(i, "bigint", "SQLiteBigInt");
696
696
  }
697
697
  /** @internal */
698
- build(n) {
699
- return new Pi(n, this.config);
698
+ build(i) {
699
+ return new Pi(i, this.config);
700
700
  }
701
701
  }
702
702
  m(Bi, yn, "SQLiteBigIntBuilder");
@@ -705,27 +705,27 @@ class Pi extends (vn = ge, Nn = v, vn) {
705
705
  getSQLType() {
706
706
  return "blob";
707
707
  }
708
- mapFromDriverValue(n) {
708
+ mapFromDriverValue(i) {
709
709
  if (typeof Buffer < "u" && Buffer.from) {
710
- const e = Buffer.isBuffer(n) ? n : n instanceof ArrayBuffer ? Buffer.from(n) : n.buffer ? Buffer.from(n.buffer, n.byteOffset, n.byteLength) : Buffer.from(n);
710
+ const e = Buffer.isBuffer(i) ? i : i instanceof ArrayBuffer ? Buffer.from(i) : i.buffer ? Buffer.from(i.buffer, i.byteOffset, i.byteLength) : Buffer.from(i);
711
711
  return BigInt(e.toString("utf8"));
712
712
  }
713
- return BigInt(Ai.decode(n));
713
+ return BigInt(Ai.decode(i));
714
714
  }
715
- mapToDriverValue(n) {
716
- return Buffer.from(n.toString());
715
+ mapToDriverValue(i) {
716
+ return Buffer.from(i.toString());
717
717
  }
718
718
  }
719
719
  m(Pi, Nn, "SQLiteBigInt");
720
720
  var Sn, bn;
721
721
  class Qi extends (bn = ce, Sn = v, bn) {
722
- constructor(n) {
723
- super(n, "json", "SQLiteBlobJson");
722
+ constructor(i) {
723
+ super(i, "json", "SQLiteBlobJson");
724
724
  }
725
725
  /** @internal */
726
- build(n) {
726
+ build(i) {
727
727
  return new Ji(
728
- n,
728
+ i,
729
729
  this.config
730
730
  );
731
731
  }
@@ -736,52 +736,52 @@ class Ji extends (Dn = ge, xn = v, Dn) {
736
736
  getSQLType() {
737
737
  return "blob";
738
738
  }
739
- mapFromDriverValue(n) {
739
+ mapFromDriverValue(i) {
740
740
  if (typeof Buffer < "u" && Buffer.from) {
741
- const e = Buffer.isBuffer(n) ? n : n instanceof ArrayBuffer ? Buffer.from(n) : n.buffer ? Buffer.from(n.buffer, n.byteOffset, n.byteLength) : Buffer.from(n);
741
+ const e = Buffer.isBuffer(i) ? i : i instanceof ArrayBuffer ? Buffer.from(i) : i.buffer ? Buffer.from(i.buffer, i.byteOffset, i.byteLength) : Buffer.from(i);
742
742
  return JSON.parse(e.toString("utf8"));
743
743
  }
744
- return JSON.parse(Ai.decode(n));
744
+ return JSON.parse(Ai.decode(i));
745
745
  }
746
- mapToDriverValue(n) {
747
- return Buffer.from(JSON.stringify(n));
746
+ mapToDriverValue(i) {
747
+ return Buffer.from(JSON.stringify(i));
748
748
  }
749
749
  }
750
750
  m(Ji, xn, "SQLiteBlobJson");
751
751
  var On, kn;
752
752
  class Fi extends (kn = ce, On = v, kn) {
753
- constructor(n) {
754
- super(n, "buffer", "SQLiteBlobBuffer");
753
+ constructor(i) {
754
+ super(i, "buffer", "SQLiteBlobBuffer");
755
755
  }
756
756
  /** @internal */
757
- build(n) {
758
- return new Ui(n, this.config);
757
+ build(i) {
758
+ return new Ui(i, this.config);
759
759
  }
760
760
  }
761
761
  m(Fi, On, "SQLiteBlobBufferBuilder");
762
762
  var In, zn;
763
763
  class Ui extends (zn = ge, In = v, zn) {
764
- mapFromDriverValue(n) {
765
- return Buffer.isBuffer(n) ? n : Buffer.from(n);
764
+ mapFromDriverValue(i) {
765
+ return Buffer.isBuffer(i) ? i : Buffer.from(i);
766
766
  }
767
767
  getSQLType() {
768
768
  return "blob";
769
769
  }
770
770
  }
771
771
  m(Ui, In, "SQLiteBlobBuffer");
772
- function zr(i, n) {
773
- const { name: e, config: t } = Je(i, n);
772
+ function zr(n, i) {
773
+ const { name: e, config: t } = Je(n, i);
774
774
  return (t == null ? void 0 : t.mode) === "json" ? new Qi(e) : (t == null ? void 0 : t.mode) === "bigint" ? new Bi(e) : new Fi(e);
775
775
  }
776
776
  var Tn, qn;
777
777
  class Ki extends (qn = ce, Tn = v, qn) {
778
- constructor(n, e, t) {
779
- super(n, "custom", "SQLiteCustomColumn"), this.config.fieldConfig = e, this.config.customTypeParams = t;
778
+ constructor(i, e, t) {
779
+ super(i, "custom", "SQLiteCustomColumn"), this.config.fieldConfig = e, this.config.customTypeParams = t;
780
780
  }
781
781
  /** @internal */
782
- build(n) {
782
+ build(i) {
783
783
  return new ji(
784
- n,
784
+ i,
785
785
  this.config
786
786
  );
787
787
  }
@@ -807,23 +807,23 @@ class ji extends (En = ge, Ln = v, En) {
807
807
  }
808
808
  }
809
809
  m(ji, Ln, "SQLiteCustomColumn");
810
- function Tr(i) {
811
- return (n, e) => {
812
- const { name: t, config: r } = Je(n, e);
810
+ function Tr(n) {
811
+ return (i, e) => {
812
+ const { name: t, config: r } = Je(i, e);
813
813
  return new Ki(
814
814
  t,
815
815
  r,
816
- i
816
+ n
817
817
  );
818
818
  };
819
819
  }
820
820
  var An, Cn;
821
821
  class Ye extends (Cn = ce, An = v, Cn) {
822
- constructor(n, e, t) {
823
- super(n, e, t), this.config.autoIncrement = !1;
822
+ constructor(i, e, t) {
823
+ super(i, e, t), this.config.autoIncrement = !1;
824
824
  }
825
- primaryKey(n) {
826
- return n != null && n.autoIncrement && (this.config.autoIncrement = !0), this.config.hasDefault = !0, super.primaryKey();
825
+ primaryKey(i) {
826
+ return i != null && i.autoIncrement && (this.config.autoIncrement = !0), this.config.hasDefault = !0, super.primaryKey();
827
827
  }
828
828
  }
829
829
  m(Ye, An, "SQLiteBaseIntegerBuilder");
@@ -840,12 +840,12 @@ class Xe extends (Bn = ge, $n = v, Bn) {
840
840
  m(Xe, $n, "SQLiteBaseInteger");
841
841
  var Pn, Qn;
842
842
  class Mi extends (Qn = Ye, Pn = v, Qn) {
843
- constructor(n) {
844
- super(n, "number", "SQLiteInteger");
843
+ constructor(i) {
844
+ super(i, "number", "SQLiteInteger");
845
845
  }
846
- build(n) {
846
+ build(i) {
847
847
  return new Vi(
848
- n,
848
+ i,
849
849
  this.config
850
850
  );
851
851
  }
@@ -857,8 +857,8 @@ class Vi extends (Fn = Xe, Jn = v, Fn) {
857
857
  m(Vi, Jn, "SQLiteInteger");
858
858
  var Un, Kn;
859
859
  class Ri extends (Kn = Ye, Un = v, Kn) {
860
- constructor(n, e) {
861
- super(n, "date", "SQLiteTimestamp"), this.config.mode = e;
860
+ constructor(i, e) {
861
+ super(i, "date", "SQLiteTimestamp"), this.config.mode = e;
862
862
  }
863
863
  /**
864
864
  * @deprecated Use `default()` with your own expression instead.
@@ -868,9 +868,9 @@ class Ri extends (Kn = Ye, Un = v, Kn) {
868
868
  defaultNow() {
869
869
  return this.default(N`(cast((julianday('now') - 2440587.5)*86400000 as integer))`);
870
870
  }
871
- build(n) {
871
+ build(i) {
872
872
  return new Wi(
873
- n,
873
+ i,
874
874
  this.config
875
875
  );
876
876
  }
@@ -893,12 +893,12 @@ class Wi extends (Mn = Xe, jn = v, Mn) {
893
893
  m(Wi, jn, "SQLiteTimestamp");
894
894
  var Vn, Rn;
895
895
  class Hi extends (Rn = Ye, Vn = v, Rn) {
896
- constructor(n, e) {
897
- super(n, "boolean", "SQLiteBoolean"), this.config.mode = e;
896
+ constructor(i, e) {
897
+ super(i, "boolean", "SQLiteBoolean"), this.config.mode = e;
898
898
  }
899
- build(n) {
899
+ build(i) {
900
900
  return new Gi(
901
- n,
901
+ i,
902
902
  this.config
903
903
  );
904
904
  }
@@ -918,19 +918,19 @@ class Gi extends (Hn = Xe, Wn = v, Hn) {
918
918
  }
919
919
  }
920
920
  m(Gi, Wn, "SQLiteBoolean");
921
- function p(i, n) {
922
- const { name: e, config: t } = Je(i, n);
921
+ function p(n, i) {
922
+ const { name: e, config: t } = Je(n, i);
923
923
  return (t == null ? void 0 : t.mode) === "timestamp" || (t == null ? void 0 : t.mode) === "timestamp_ms" ? new Ri(e, t.mode) : (t == null ? void 0 : t.mode) === "boolean" ? new Hi(e, t.mode) : new Mi(e);
924
924
  }
925
925
  var Gn, Yn;
926
926
  class Yi extends (Yn = ce, Gn = v, Yn) {
927
- constructor(n) {
928
- super(n, "string", "SQLiteNumeric");
927
+ constructor(i) {
928
+ super(i, "string", "SQLiteNumeric");
929
929
  }
930
930
  /** @internal */
931
- build(n) {
931
+ build(i) {
932
932
  return new Xi(
933
- n,
933
+ i,
934
934
  this.config
935
935
  );
936
936
  }
@@ -938,8 +938,8 @@ class Yi extends (Yn = ce, Gn = v, Yn) {
938
938
  m(Yi, Gn, "SQLiteNumericBuilder");
939
939
  var Xn, Zn;
940
940
  class Xi extends (Zn = ge, Xn = v, Zn) {
941
- mapFromDriverValue(n) {
942
- return typeof n == "string" ? n : String(n);
941
+ mapFromDriverValue(i) {
942
+ return typeof i == "string" ? i : String(i);
943
943
  }
944
944
  getSQLType() {
945
945
  return "numeric";
@@ -948,13 +948,13 @@ class Xi extends (Zn = ge, Xn = v, Zn) {
948
948
  m(Xi, Xn, "SQLiteNumeric");
949
949
  var ei, ti;
950
950
  class Zi extends (ti = ce, ei = v, ti) {
951
- constructor(n) {
952
- super(n, "number", "SQLiteNumericNumber");
951
+ constructor(i) {
952
+ super(i, "number", "SQLiteNumericNumber");
953
953
  }
954
954
  /** @internal */
955
- build(n) {
955
+ build(i) {
956
956
  return new er(
957
- n,
957
+ i,
958
958
  this.config
959
959
  );
960
960
  }
@@ -976,13 +976,13 @@ class er extends (ii = ge, ni = v, ii) {
976
976
  m(er, ni, "SQLiteNumericNumber");
977
977
  var ri, si;
978
978
  class tr extends (si = ce, ri = v, si) {
979
- constructor(n) {
980
- super(n, "bigint", "SQLiteNumericBigInt");
979
+ constructor(i) {
980
+ super(i, "bigint", "SQLiteNumericBigInt");
981
981
  }
982
982
  /** @internal */
983
- build(n) {
983
+ build(i) {
984
984
  return new nr(
985
- n,
985
+ i,
986
986
  this.config
987
987
  );
988
988
  }
@@ -1000,18 +1000,18 @@ class nr extends (ai = ge, oi = v, ai) {
1000
1000
  }
1001
1001
  }
1002
1002
  m(nr, oi, "SQLiteNumericBigInt");
1003
- function qr(i, n) {
1004
- const { name: e, config: t } = Je(i, n), r = t == null ? void 0 : t.mode;
1003
+ function qr(n, i) {
1004
+ const { name: e, config: t } = Je(n, i), r = t == null ? void 0 : t.mode;
1005
1005
  return r === "number" ? new Zi(e) : r === "bigint" ? new tr(e) : new Yi(e);
1006
1006
  }
1007
1007
  var li, _i;
1008
1008
  class ir extends (_i = ce, li = v, _i) {
1009
- constructor(n) {
1010
- super(n, "number", "SQLiteReal");
1009
+ constructor(i) {
1010
+ super(i, "number", "SQLiteReal");
1011
1011
  }
1012
1012
  /** @internal */
1013
- build(n) {
1014
- return new rr(n, this.config);
1013
+ build(i) {
1014
+ return new rr(i, this.config);
1015
1015
  }
1016
1016
  }
1017
1017
  m(ir, li, "SQLiteRealBuilder");
@@ -1022,18 +1022,18 @@ class rr extends (di = ge, ui = v, di) {
1022
1022
  }
1023
1023
  }
1024
1024
  m(rr, ui, "SQLiteReal");
1025
- function Lr(i) {
1026
- return new ir(i ?? "");
1025
+ function Lr(n) {
1026
+ return new ir(n ?? "");
1027
1027
  }
1028
1028
  var ci, gi;
1029
1029
  class sr extends (gi = ce, ci = v, gi) {
1030
- constructor(n, e) {
1031
- super(n, "string", "SQLiteText"), this.config.enumValues = e.enum, this.config.length = e.length;
1030
+ constructor(i, e) {
1031
+ super(i, "string", "SQLiteText"), this.config.enumValues = e.enum, this.config.length = e.length;
1032
1032
  }
1033
1033
  /** @internal */
1034
- build(n) {
1034
+ build(i) {
1035
1035
  return new or(
1036
- n,
1036
+ i,
1037
1037
  this.config
1038
1038
  );
1039
1039
  }
@@ -1053,13 +1053,13 @@ class or extends (mi = ge, fi = v, mi) {
1053
1053
  m(or, fi, "SQLiteText");
1054
1054
  var hi, pi;
1055
1055
  class ar extends (pi = ce, hi = v, pi) {
1056
- constructor(n) {
1057
- super(n, "json", "SQLiteTextJson");
1056
+ constructor(i) {
1057
+ super(i, "json", "SQLiteTextJson");
1058
1058
  }
1059
1059
  /** @internal */
1060
- build(n) {
1060
+ build(i) {
1061
1061
  return new lr(
1062
- n,
1062
+ i,
1063
1063
  this.config
1064
1064
  );
1065
1065
  }
@@ -1070,16 +1070,16 @@ class lr extends (wi = ge, yi = v, wi) {
1070
1070
  getSQLType() {
1071
1071
  return "text";
1072
1072
  }
1073
- mapFromDriverValue(n) {
1074
- return JSON.parse(n);
1073
+ mapFromDriverValue(i) {
1074
+ return JSON.parse(i);
1075
1075
  }
1076
- mapToDriverValue(n) {
1077
- return JSON.stringify(n);
1076
+ mapToDriverValue(i) {
1077
+ return JSON.stringify(i);
1078
1078
  }
1079
1079
  }
1080
1080
  m(lr, yi, "SQLiteTextJson");
1081
- function s(i, n = {}) {
1082
- const { name: e, config: t } = Je(i, n);
1081
+ function s(n, i = {}) {
1082
+ const { name: e, config: t } = Je(n, i);
1083
1083
  return t.mode === "json" ? new ar(e) : new sr(e, t);
1084
1084
  }
1085
1085
  function Er() {
@@ -1109,8 +1109,8 @@ m(Be, bi, "SQLiteTable"), /** @internal */
1109
1109
  m(Be, "Symbol", Object.assign({}, j.Symbol, {
1110
1110
  InlineForeignKeys: pt
1111
1111
  }));
1112
- function Ar(i, n, e, t, r = i) {
1113
- const o = new Be(i, t, r), l = typeof n == "function" ? n(Er()) : n, _ = Object.fromEntries(
1112
+ function Ar(n, i, e, t, r = n) {
1113
+ const o = new Be(n, t, r), l = typeof i == "function" ? i(Er()) : i, _ = Object.fromEntries(
1114
1114
  Object.entries(l).map(([c, u]) => {
1115
1115
  const h = u;
1116
1116
  h.setName(c);
@@ -1120,26 +1120,26 @@ function Ar(i, n, e, t, r = i) {
1120
1120
  ), d = Object.assign(o, _);
1121
1121
  return d[j.Symbol.Columns] = _, d[j.Symbol.ExtraConfigColumns] = _, e && (d[Be.Symbol.ExtraConfigBuilder] = e), d;
1122
1122
  }
1123
- const O = (i, n, e) => Ar(i, n, e);
1123
+ const O = (n, i, e) => Ar(n, i, e);
1124
1124
  var Di;
1125
1125
  Di = v;
1126
1126
  class Ot {
1127
- constructor(n, e) {
1128
- this.name = n, this.unique = e;
1127
+ constructor(i, e) {
1128
+ this.name = i, this.unique = e;
1129
1129
  }
1130
- on(...n) {
1131
- return new _r(this.name, n, this.unique);
1130
+ on(...i) {
1131
+ return new _r(this.name, i, this.unique);
1132
1132
  }
1133
1133
  }
1134
1134
  m(Ot, Di, "SQLiteIndexBuilderOn");
1135
1135
  var Oi;
1136
1136
  Oi = v;
1137
1137
  class _r {
1138
- constructor(n, e, t) {
1138
+ constructor(i, e, t) {
1139
1139
  /** @internal */
1140
1140
  m(this, "config");
1141
1141
  this.config = {
1142
- name: n,
1142
+ name: i,
1143
1143
  columns: e,
1144
1144
  unique: t,
1145
1145
  where: void 0
@@ -1148,59 +1148,59 @@ class _r {
1148
1148
  /**
1149
1149
  * Condition for partial index.
1150
1150
  */
1151
- where(n) {
1152
- return this.config.where = n, this;
1151
+ where(i) {
1152
+ return this.config.where = i, this;
1153
1153
  }
1154
1154
  /** @internal */
1155
- build(n) {
1156
- return new ur(this.config, n);
1155
+ build(i) {
1156
+ return new ur(this.config, i);
1157
1157
  }
1158
1158
  }
1159
1159
  m(_r, Oi, "SQLiteIndexBuilder");
1160
1160
  var ki;
1161
1161
  ki = v;
1162
1162
  class ur {
1163
- constructor(n, e) {
1163
+ constructor(i, e) {
1164
1164
  m(this, "config");
1165
- this.config = { ...n, table: e };
1165
+ this.config = { ...i, table: e };
1166
1166
  }
1167
1167
  }
1168
1168
  m(ur, ki, "SQLiteIndex");
1169
- function S(i) {
1170
- return new Ot(i, !1);
1169
+ function S(n) {
1170
+ return new Ot(n, !1);
1171
1171
  }
1172
- function Te(i) {
1173
- return new Ot(i, !0);
1172
+ function Te(n) {
1173
+ return new Ot(n, !0);
1174
1174
  }
1175
- function se(...i) {
1176
- return i[0].columns ? new yt(i[0].columns, i[0].name) : new yt(i);
1175
+ function se(...n) {
1176
+ return n[0].columns ? new yt(n[0].columns, n[0].name) : new yt(n);
1177
1177
  }
1178
1178
  var Ii;
1179
1179
  Ii = v;
1180
1180
  class yt {
1181
- constructor(n, e) {
1181
+ constructor(i, e) {
1182
1182
  /** @internal */
1183
1183
  m(this, "columns");
1184
1184
  /** @internal */
1185
1185
  m(this, "name");
1186
- this.columns = n, this.name = e;
1186
+ this.columns = i, this.name = e;
1187
1187
  }
1188
1188
  /** @internal */
1189
- build(n) {
1190
- return new dr(n, this.columns, this.name);
1189
+ build(i) {
1190
+ return new dr(i, this.columns, this.name);
1191
1191
  }
1192
1192
  }
1193
1193
  m(yt, Ii, "SQLitePrimaryKeyBuilder");
1194
1194
  var zi;
1195
1195
  zi = v;
1196
1196
  class dr {
1197
- constructor(n, e, t) {
1197
+ constructor(i, e, t) {
1198
1198
  m(this, "columns");
1199
1199
  m(this, "name");
1200
- this.table = n, this.columns = e, this.name = t;
1200
+ this.table = i, this.columns = e, this.name = t;
1201
1201
  }
1202
1202
  getName() {
1203
- return this.name ?? `${this.table[Be.Symbol.Name]}_${this.columns.map((n) => n.name).join("_")}_pk`;
1203
+ return this.name ?? `${this.table[Be.Symbol.Name]}_${this.columns.map((i) => i.name).join("_")}_pk`;
1204
1204
  }
1205
1205
  }
1206
1206
  m(dr, zi, "SQLitePrimaryKey");
@@ -1301,33 +1301,33 @@ const D = O("tenants", {
1301
1301
  // OIDC address claim (OIDC Core 5.1.1) - stored as JSON string
1302
1302
  address: s("address")
1303
1303
  },
1304
- (i) => [
1304
+ (n) => [
1305
1305
  se({
1306
- columns: [i.user_id, i.tenant_id],
1306
+ columns: [n.user_id, n.tenant_id],
1307
1307
  name: "users_tenants"
1308
1308
  }),
1309
1309
  Te("unique_email_provider").on(
1310
- i.email,
1311
- i.provider,
1312
- i.tenant_id
1310
+ n.email,
1311
+ n.provider,
1312
+ n.tenant_id
1313
1313
  ),
1314
1314
  Te("unique_phone_provider").on(
1315
- i.phone_number,
1316
- i.provider,
1317
- i.tenant_id
1315
+ n.phone_number,
1316
+ n.provider,
1317
+ n.tenant_id
1318
1318
  ),
1319
1319
  Te("unique_username_provider").on(
1320
- i.username,
1321
- i.provider,
1322
- i.tenant_id
1320
+ n.username,
1321
+ n.provider,
1322
+ n.tenant_id
1323
1323
  ),
1324
- S("users_email_index").on(i.email),
1325
- S("users_linked_to_index").on(i.linked_to),
1326
- S("users_name_index").on(i.name),
1324
+ S("users_email_index").on(n.email),
1325
+ S("users_linked_to_index").on(n.linked_to),
1326
+ S("users_name_index").on(n.name),
1327
1327
  S("users_phone_tenant_provider_index").on(
1328
- i.tenant_id,
1329
- i.phone_number,
1330
- i.provider
1328
+ n.tenant_id,
1329
+ n.phone_number,
1330
+ n.provider
1331
1331
  )
1332
1332
  ]
1333
1333
  ), E = O("passwords", {
@@ -1357,11 +1357,11 @@ const D = O("tenants", {
1357
1357
  clients: s("clients").notNull(),
1358
1358
  login_session_id: s("login_session_id", { length: 21 })
1359
1359
  },
1360
- (i) => [
1361
- se({ columns: [i.tenant_id, i.id], name: "sessions_pk" }),
1362
- S("IDX_sessions_login_session_id").on(i.login_session_id),
1363
- S("idx_sessions_user_id").on(i.tenant_id, i.user_id),
1364
- S("idx_sessions_expires_at_ts").on(i.expires_at_ts)
1360
+ (n) => [
1361
+ se({ columns: [n.tenant_id, n.id], name: "sessions_pk" }),
1362
+ S("IDX_sessions_login_session_id").on(n.login_session_id),
1363
+ S("idx_sessions_user_id").on(n.tenant_id, n.user_id),
1364
+ S("idx_sessions_expires_at_ts").on(n.expires_at_ts)
1365
1365
  ]
1366
1366
  ), C = O(
1367
1367
  "refresh_tokens",
@@ -1379,14 +1379,14 @@ const D = O("tenants", {
1379
1379
  idle_expires_at_ts: p("idle_expires_at_ts"),
1380
1380
  last_exchanged_at_ts: p("last_exchanged_at_ts")
1381
1381
  },
1382
- (i) => [
1382
+ (n) => [
1383
1383
  se({
1384
- columns: [i.tenant_id, i.id],
1384
+ columns: [n.tenant_id, n.id],
1385
1385
  name: "refresh_tokens_pk"
1386
1386
  }),
1387
- S("idx_refresh_tokens_user_id").on(i.tenant_id, i.user_id),
1388
- S("idx_refresh_tokens_login_id").on(i.login_id),
1389
- S("idx_refresh_tokens_expires_at_ts").on(i.expires_at_ts)
1387
+ S("idx_refresh_tokens_user_id").on(n.tenant_id, n.user_id),
1388
+ S("idx_refresh_tokens_login_id").on(n.login_id),
1389
+ S("idx_refresh_tokens_expires_at_ts").on(n.expires_at_ts)
1390
1390
  ]
1391
1391
  ), oe = O(
1392
1392
  "login_sessions",
@@ -1431,19 +1431,19 @@ const D = O("tenants", {
1431
1431
  user_id: s("user_id", { length: 255 }),
1432
1432
  auth_connection: s("auth_connection", { length: 255 })
1433
1433
  },
1434
- (i) => [
1434
+ (n) => [
1435
1435
  se({
1436
- columns: [i.tenant_id, i.id],
1436
+ columns: [n.tenant_id, n.id],
1437
1437
  name: "login_sessions_pk"
1438
1438
  }),
1439
- S("login_sessions_id_index").on(i.id),
1440
- S("login_sessions_state_idx").on(i.state),
1439
+ S("login_sessions_id_index").on(n.id),
1440
+ S("login_sessions_state_idx").on(n.state),
1441
1441
  S("login_sessions_state_updated_idx").on(
1442
- i.state,
1443
- i.updated_at_ts
1442
+ n.state,
1443
+ n.updated_at_ts
1444
1444
  ),
1445
- S("login_sessions_tenant_user_idx").on(i.tenant_id, i.user_id),
1446
- S("idx_login_sessions_expires_at_ts").on(i.expires_at_ts)
1445
+ S("login_sessions_tenant_user_idx").on(n.tenant_id, n.user_id),
1446
+ S("idx_login_sessions_expires_at_ts").on(n.expires_at_ts)
1447
1447
  ]
1448
1448
  ), B = O(
1449
1449
  "codes",
@@ -1464,12 +1464,12 @@ const D = O("tenants", {
1464
1464
  nonce: s("nonce", { length: 1024 }),
1465
1465
  state: s("state", { length: 2048 })
1466
1466
  },
1467
- (i) => [
1467
+ (n) => [
1468
1468
  se({
1469
- columns: [i.code_id, i.code_type],
1469
+ columns: [n.code_id, n.code_type],
1470
1470
  name: "PK_codes_code_id_code_type"
1471
1471
  }),
1472
- S("codes_expires_at_index").on(i.expires_at)
1472
+ S("codes_expires_at_index").on(n.expires_at)
1473
1473
  ]
1474
1474
  ), Cr = O("authentication_codes", {
1475
1475
  tenant_id: s("tenant_id", { length: 191 }).notNull().references(() => D.id, { onDelete: "cascade" }),
@@ -1507,9 +1507,9 @@ const D = O("tenants", {
1507
1507
  audience: s("audience", { length: 255 }),
1508
1508
  ip: s("ip", { length: 64 })
1509
1509
  },
1510
- (i) => [
1511
- S("otps_email_index").on(i.email),
1512
- S("otps_expires_at_index").on(i.expires_at)
1510
+ (n) => [
1511
+ S("otps_email_index").on(n.email),
1512
+ S("otps_expires_at_index").on(n.expires_at)
1513
1513
  ]
1514
1514
  ), Br = O("tickets", {
1515
1515
  tenant_id: s("tenant_id", { length: 191 }).notNull().references(() => D.id, { onDelete: "cascade" }),
@@ -1590,9 +1590,9 @@ const D = O("tenants", {
1590
1590
  updated_at: s("updated_at", { length: 35 }).notNull(),
1591
1591
  connections: s("connections").notNull().default("[]")
1592
1592
  },
1593
- (i) => [
1593
+ (n) => [
1594
1594
  se({
1595
- columns: [i.tenant_id, i.client_id],
1595
+ columns: [n.tenant_id, n.client_id],
1596
1596
  name: "clients_tenant_id_client_id"
1597
1597
  })
1598
1598
  ]
@@ -1614,12 +1614,12 @@ const D = O("tenants", {
1614
1614
  created_at: s("created_at", { length: 35 }).notNull(),
1615
1615
  updated_at: s("updated_at", { length: 35 }).notNull()
1616
1616
  },
1617
- (i) => [
1617
+ (n) => [
1618
1618
  se({
1619
- columns: [i.tenant_id, i.id],
1619
+ columns: [n.tenant_id, n.id],
1620
1620
  name: "pk_client_grants"
1621
1621
  }),
1622
- S("idx_client_grants_audience").on(i.audience)
1622
+ S("idx_client_grants_audience").on(n.audience)
1623
1623
  ]
1624
1624
  ), U = O(
1625
1625
  "connections",
@@ -1639,11 +1639,11 @@ const D = O("tenants", {
1639
1639
  is_system: p("is_system").notNull().default(0),
1640
1640
  metadata: s("metadata", { length: 4096 })
1641
1641
  },
1642
- (i) => [
1643
- se({ columns: [i.tenant_id, i.id] }),
1644
- S("connections_tenant_id_index").on(i.tenant_id),
1642
+ (n) => [
1643
+ se({ columns: [n.tenant_id, n.id] }),
1644
+ S("connections_tenant_id_index").on(n.tenant_id),
1645
1645
  // Required for keys.connection foreign key reference
1646
- Te("connections_id_unique").on(i.id)
1646
+ Te("connections_id_unique").on(n.id)
1647
1647
  ]
1648
1648
  ), re = O(
1649
1649
  "custom_domains",
@@ -1662,7 +1662,7 @@ const D = O("tenants", {
1662
1662
  created_at: s("created_at", { length: 35 }).notNull(),
1663
1663
  updated_at: s("updated_at", { length: 35 }).notNull()
1664
1664
  },
1665
- (i) => [Te("custom_domains_domain_unique").on(i.domain)]
1665
+ (n) => [Te("custom_domains_domain_unique").on(n.domain)]
1666
1666
  ), Pr = O("domains", {
1667
1667
  id: s("id", { length: 255 }).primaryKey(),
1668
1668
  tenant_id: s("tenant_id", { length: 191 }).notNull().references(() => D.id, { onDelete: "cascade" }),
@@ -1687,7 +1687,7 @@ const D = O("tenants", {
1687
1687
  created_at: s("created_at", { length: 35 }).notNull(),
1688
1688
  updated_at: s("updated_at", { length: 35 }).notNull()
1689
1689
  },
1690
- (i) => [S("idx_organizations_tenant_id").on(i.tenant_id)]
1690
+ (n) => [S("idx_organizations_tenant_id").on(n.tenant_id)]
1691
1691
  ), P = O(
1692
1692
  "user_organizations",
1693
1693
  {
@@ -1698,15 +1698,15 @@ const D = O("tenants", {
1698
1698
  created_at: s("created_at", { length: 35 }).notNull(),
1699
1699
  updated_at: s("updated_at", { length: 35 }).notNull()
1700
1700
  },
1701
- (i) => [
1701
+ (n) => [
1702
1702
  Te("user_organizations_unique").on(
1703
- i.tenant_id,
1704
- i.user_id,
1705
- i.organization_id
1703
+ n.tenant_id,
1704
+ n.user_id,
1705
+ n.organization_id
1706
1706
  ),
1707
- S("idx_user_organizations_tenant_id").on(i.tenant_id),
1708
- S("idx_user_organizations_user_id").on(i.user_id),
1709
- S("idx_user_organizations_organization_id").on(i.organization_id)
1707
+ S("idx_user_organizations_tenant_id").on(n.tenant_id),
1708
+ S("idx_user_organizations_user_id").on(n.user_id),
1709
+ S("idx_user_organizations_organization_id").on(n.organization_id)
1710
1710
  ]
1711
1711
  ), te = O(
1712
1712
  "invites",
@@ -1728,11 +1728,11 @@ const D = O("tenants", {
1728
1728
  ttl_sec: p("ttl_sec"),
1729
1729
  send_invitation_email: p("send_invitation_email")
1730
1730
  },
1731
- (i) => [
1732
- S("idx_invites_tenant_id").on(i.tenant_id),
1733
- S("idx_invites_organization_id").on(i.organization_id),
1734
- S("idx_invites_expires_at").on(i.expires_at),
1735
- S("idx_invites_tenant_created").on(i.tenant_id, i.created_at)
1731
+ (n) => [
1732
+ S("idx_invites_tenant_id").on(n.tenant_id),
1733
+ S("idx_invites_organization_id").on(n.organization_id),
1734
+ S("idx_invites_expires_at").on(n.expires_at),
1735
+ S("idx_invites_tenant_created").on(n.tenant_id, n.created_at)
1736
1736
  ]
1737
1737
  ), J = O(
1738
1738
  "roles",
@@ -1746,8 +1746,8 @@ const D = O("tenants", {
1746
1746
  created_at: s("created_at", { length: 35 }).notNull(),
1747
1747
  updated_at: s("updated_at", { length: 35 }).notNull()
1748
1748
  },
1749
- (i) => [
1750
- se({ columns: [i.tenant_id, i.id], name: "roles_pk" })
1749
+ (n) => [
1750
+ se({ columns: [n.tenant_id, n.id], name: "roles_pk" })
1751
1751
  ]
1752
1752
  ), le = O(
1753
1753
  "role_permissions",
@@ -1760,21 +1760,21 @@ const D = O("tenants", {
1760
1760
  permission_name: s("permission_name", { length: 191 }).notNull(),
1761
1761
  created_at: s("created_at", { length: 35 }).notNull()
1762
1762
  },
1763
- (i) => [
1763
+ (n) => [
1764
1764
  se({
1765
1765
  columns: [
1766
- i.tenant_id,
1767
- i.role_id,
1768
- i.resource_server_identifier,
1769
- i.permission_name
1766
+ n.tenant_id,
1767
+ n.role_id,
1768
+ n.resource_server_identifier,
1769
+ n.permission_name
1770
1770
  ],
1771
1771
  name: "role_permissions_pk"
1772
1772
  }),
1773
- S("role_permissions_role_fk").on(i.tenant_id, i.role_id),
1773
+ S("role_permissions_role_fk").on(n.tenant_id, n.role_id),
1774
1774
  S("role_permissions_permission_fk").on(
1775
- i.tenant_id,
1776
- i.resource_server_identifier,
1777
- i.permission_name
1775
+ n.tenant_id,
1776
+ n.resource_server_identifier,
1777
+ n.permission_name
1778
1778
  )
1779
1779
  ]
1780
1780
  ), _e = O(
@@ -1789,24 +1789,24 @@ const D = O("tenants", {
1789
1789
  organization_id: s("organization_id", { length: 21 }).notNull().default(""),
1790
1790
  created_at: s("created_at", { length: 35 }).notNull()
1791
1791
  },
1792
- (i) => [
1792
+ (n) => [
1793
1793
  se({
1794
1794
  columns: [
1795
- i.tenant_id,
1796
- i.user_id,
1797
- i.resource_server_identifier,
1798
- i.permission_name,
1799
- i.organization_id
1795
+ n.tenant_id,
1796
+ n.user_id,
1797
+ n.resource_server_identifier,
1798
+ n.permission_name,
1799
+ n.organization_id
1800
1800
  ],
1801
1801
  name: "user_permissions_pk"
1802
1802
  }),
1803
- S("user_permissions_user_fk").on(i.tenant_id, i.user_id),
1803
+ S("user_permissions_user_fk").on(n.tenant_id, n.user_id),
1804
1804
  S("user_permissions_permission_fk").on(
1805
- i.tenant_id,
1806
- i.resource_server_identifier,
1807
- i.permission_name
1805
+ n.tenant_id,
1806
+ n.resource_server_identifier,
1807
+ n.permission_name
1808
1808
  ),
1809
- S("user_permissions_organization_fk").on(i.organization_id)
1809
+ S("user_permissions_organization_fk").on(n.organization_id)
1810
1810
  ]
1811
1811
  ), ue = O(
1812
1812
  "user_roles",
@@ -1817,19 +1817,19 @@ const D = O("tenants", {
1817
1817
  organization_id: s("organization_id", { length: 191 }).notNull().default(""),
1818
1818
  created_at: s("created_at", { length: 35 }).notNull()
1819
1819
  },
1820
- (i) => [
1820
+ (n) => [
1821
1821
  se({
1822
1822
  columns: [
1823
- i.tenant_id,
1824
- i.user_id,
1825
- i.role_id,
1826
- i.organization_id
1823
+ n.tenant_id,
1824
+ n.user_id,
1825
+ n.role_id,
1826
+ n.organization_id
1827
1827
  ],
1828
1828
  name: "user_roles_pk"
1829
1829
  }),
1830
- S("user_roles_user_fk").on(i.tenant_id, i.user_id),
1831
- S("user_roles_role_fk").on(i.tenant_id, i.role_id),
1832
- S("user_roles_organization_fk").on(i.organization_id)
1830
+ S("user_roles_user_fk").on(n.tenant_id, n.user_id),
1831
+ S("user_roles_role_fk").on(n.tenant_id, n.role_id),
1832
+ S("user_roles_organization_fk").on(n.organization_id)
1833
1833
  ]
1834
1834
  ), L = O(
1835
1835
  "resource_servers",
@@ -1854,9 +1854,9 @@ const D = O("tenants", {
1854
1854
  created_at: s("created_at", { length: 35 }).notNull(),
1855
1855
  updated_at: s("updated_at", { length: 35 }).notNull()
1856
1856
  },
1857
- (i) => [
1857
+ (n) => [
1858
1858
  se({
1859
- columns: [i.tenant_id, i.id],
1859
+ columns: [n.tenant_id, n.id],
1860
1860
  name: "resource_servers_pk"
1861
1861
  })
1862
1862
  ]
@@ -2005,12 +2005,12 @@ const D = O("tenants", {
2005
2005
  created_at: s("created_at", { length: 35 }).notNull(),
2006
2006
  updated_at: s("updated_at", { length: 35 }).notNull()
2007
2007
  },
2008
- (i) => [
2008
+ (n) => [
2009
2009
  se({
2010
- columns: [i.tenant_id, i.themeId],
2010
+ columns: [n.tenant_id, n.themeId],
2011
2011
  name: "themes_pkey"
2012
2012
  }),
2013
- S("themes_tenant_id_idx").on(i.tenant_id)
2013
+ S("themes_tenant_id_idx").on(n.tenant_id)
2014
2014
  ]
2015
2015
  ), ne = O(
2016
2016
  "forms",
@@ -2028,7 +2028,7 @@ const D = O("tenants", {
2028
2028
  created_at: s("created_at", { length: 35 }).notNull(),
2029
2029
  updated_at: s("updated_at", { length: 35 }).notNull()
2030
2030
  },
2031
- (i) => [S("forms_tenant_id_idx").on(i.tenant_id)]
2031
+ (n) => [S("forms_tenant_id_idx").on(n.tenant_id)]
2032
2032
  ), ie = O(
2033
2033
  "flows",
2034
2034
  {
@@ -2039,7 +2039,7 @@ const D = O("tenants", {
2039
2039
  created_at: s("created_at", { length: 35 }).notNull(),
2040
2040
  updated_at: s("updated_at", { length: 35 }).notNull()
2041
2041
  },
2042
- (i) => [S("flows_tenant_id_idx").on(i.tenant_id)]
2042
+ (n) => [S("flows_tenant_id_idx").on(n.tenant_id)]
2043
2043
  ), Ee = O("prompt_settings", {
2044
2044
  tenant_id: s("tenant_id", { length: 191 }).primaryKey(),
2045
2045
  universal_login_experience: s("universal_login_experience", { length: 16 }).notNull().default("new"),
@@ -2077,7 +2077,7 @@ const D = O("tenants", {
2077
2077
  code_id: s("code_id", { length: 21 })
2078
2078
  // only required for code type hooks
2079
2079
  },
2080
- (i) => [S("hooks_tenant_id_idx").on(i.tenant_id)]
2080
+ (n) => [S("hooks_tenant_id_idx").on(n.tenant_id)]
2081
2081
  ), me = O(
2082
2082
  "hook_code",
2083
2083
  {
@@ -2088,7 +2088,7 @@ const D = O("tenants", {
2088
2088
  created_at_ts: p("created_at_ts").notNull(),
2089
2089
  updated_at_ts: p("updated_at_ts").notNull()
2090
2090
  },
2091
- (i) => [S("hook_code_tenant_id_idx").on(i.tenant_id)]
2091
+ (n) => [S("hook_code_tenant_id_idx").on(n.tenant_id)]
2092
2092
  ), he = O("keys", {
2093
2093
  kid: s("kid", { length: 255 }).primaryKey(),
2094
2094
  tenant_id: s("tenant_id", { length: 191 }).references(() => D.id, {
@@ -2117,8 +2117,8 @@ const D = O("tenants", {
2117
2117
  created_at_ts: p("created_at_ts").notNull(),
2118
2118
  updated_at_ts: p("updated_at_ts").notNull()
2119
2119
  },
2120
- (i) => [
2121
- se({ columns: [i.tenant_id, i.prompt, i.language] })
2120
+ (n) => [
2121
+ se({ columns: [n.tenant_id, n.prompt, n.language] })
2122
2122
  ]
2123
2123
  ), F = O(
2124
2124
  "authentication_methods",
@@ -2139,12 +2139,12 @@ const D = O("tenants", {
2139
2139
  created_at_ts: p("created_at_ts").notNull(),
2140
2140
  updated_at_ts: p("updated_at_ts").notNull()
2141
2141
  },
2142
- (i) => [
2142
+ (n) => [
2143
2143
  S("authentication_methods_tenant_user_idx").on(
2144
- i.tenant_id,
2145
- i.user_id
2144
+ n.tenant_id,
2145
+ n.user_id
2146
2146
  ),
2147
- S("authentication_methods_credential_id_idx").on(i.credential_id)
2147
+ S("authentication_methods_credential_id_idx").on(n.credential_id)
2148
2148
  ]
2149
2149
  ), T = O(
2150
2150
  "logs",
@@ -2179,15 +2179,15 @@ const D = O("tenants", {
2179
2179
  time_zone: s("time_zone", { length: 255 }),
2180
2180
  continent_code: s("continent_code", { length: 2 })
2181
2181
  },
2182
- (i) => [
2183
- S("logs_user_id").on(i.user_id),
2184
- S("logs_tenant_id").on(i.tenant_id),
2185
- S("logs_date").on(i.date),
2182
+ (n) => [
2183
+ S("logs_user_id").on(n.user_id),
2184
+ S("logs_tenant_id").on(n.tenant_id),
2185
+ S("logs_date").on(n.date),
2186
2186
  S("IDX_logs_tenant_date_type_user").on(
2187
- i.tenant_id,
2188
- i.date,
2189
- i.type,
2190
- i.user_id
2187
+ n.tenant_id,
2188
+ n.date,
2189
+ n.type,
2190
+ n.user_id
2191
2191
  )
2192
2192
  ]
2193
2193
  ), x = O(
@@ -2210,17 +2210,17 @@ const D = O("tenants", {
2210
2210
  dead_lettered_at: s("dead_lettered_at", { length: 35 }),
2211
2211
  final_error: s("final_error")
2212
2212
  },
2213
- (i) => [
2214
- S("idx_outbox_events_tenant_id").on(i.tenant_id),
2215
- S("idx_outbox_events_processed_at").on(i.processed_at),
2216
- S("idx_outbox_events_claimed_by").on(i.claimed_by),
2213
+ (n) => [
2214
+ S("idx_outbox_events_tenant_id").on(n.tenant_id),
2215
+ S("idx_outbox_events_processed_at").on(n.processed_at),
2216
+ S("idx_outbox_events_claimed_by").on(n.claimed_by),
2217
2217
  // Composite index for the failed-events management endpoints
2218
2218
  // (`listFailed` query: tenant_id equality + dead_lettered_at IS NOT NULL
2219
2219
  // + ORDER BY dead_lettered_at DESC). Equality column first so the
2220
2220
  // optimizer can seek directly to the tenant's dead-letter slice.
2221
2221
  S("idx_outbox_events_tenant_dead_lettered").on(
2222
- i.tenant_id,
2223
- i.dead_lettered_at
2222
+ n.tenant_id,
2223
+ n.dead_lettered_at
2224
2224
  )
2225
2225
  ]
2226
2226
  ), js = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
@@ -2263,60 +2263,60 @@ const D = O("tenants", {
2263
2263
  userRoles: ue,
2264
2264
  users: k
2265
2265
  }, Symbol.toStringTag, { value: "Module" }));
2266
- function z(i) {
2267
- if (i == null || typeof i != "object")
2268
- return i;
2269
- if (Array.isArray(i))
2270
- return i.map(
2266
+ function z(n) {
2267
+ if (n == null || typeof n != "object")
2268
+ return n;
2269
+ if (Array.isArray(n))
2270
+ return n.map(
2271
2271
  (e) => e !== null && typeof e == "object" ? z(e) : e
2272
2272
  );
2273
- const n = { ...i };
2274
- for (const e in n) {
2275
- const t = n[e];
2276
- t === null ? delete n[e] : t !== null && typeof t == "object" && (Array.isArray(t) ? n[e] = t.map(
2273
+ const i = { ...n };
2274
+ for (const e in i) {
2275
+ const t = i[e];
2276
+ t === null ? delete i[e] : t !== null && typeof t == "object" && (Array.isArray(t) ? i[e] = t.map(
2277
2277
  (r) => r !== null && typeof r == "object" ? z(r) : r
2278
- ) : n[e] = z(t));
2278
+ ) : i[e] = z(t));
2279
2279
  }
2280
- return n;
2280
+ return i;
2281
2281
  }
2282
- function Qr(i, n, e = { ...i }) {
2283
- for (const t of n)
2284
- i[t] !== void 0 && (e[t] = JSON.stringify(i[t]));
2282
+ function Qr(n, i, e = { ...n }) {
2283
+ for (const t of i)
2284
+ n[t] !== void 0 && (e[t] = JSON.stringify(n[t]));
2285
2285
  return e;
2286
2286
  }
2287
- function Jr(i, n, e = i) {
2288
- for (const t of n)
2289
- i[t] !== void 0 && (e[t] = i[t] ? 1 : 0);
2287
+ function Jr(n, i, e = n) {
2288
+ for (const t of i)
2289
+ n[t] !== void 0 && (e[t] = n[t] ? 1 : 0);
2290
2290
  }
2291
- function cr(i) {
2292
- const n = {};
2293
- for (const e in i)
2294
- i[e] !== void 0 && i[e] !== null && (n[e] = i[e]);
2295
- return n;
2291
+ function cr(n) {
2292
+ const i = {};
2293
+ for (const e in n)
2294
+ n[e] !== void 0 && n[e] !== null && (i[e] = n[e]);
2295
+ return i;
2296
2296
  }
2297
- function b(i, n) {
2298
- if (i == null)
2299
- return n;
2300
- if (typeof i == "string")
2297
+ function b(n, i) {
2298
+ if (n == null)
2299
+ return i;
2300
+ if (typeof n == "string")
2301
2301
  try {
2302
- return JSON.parse(i);
2302
+ return JSON.parse(n);
2303
2303
  } catch {
2304
- return n;
2304
+ return i;
2305
2305
  }
2306
- return i;
2306
+ return n;
2307
2307
  }
2308
- function Pe(i, n = "", e = {}) {
2309
- for (const t in i)
2310
- if (Object.prototype.hasOwnProperty.call(i, t)) {
2311
- const r = n ? `${n}_${t}` : t, o = i[t];
2308
+ function Pe(n, i = "", e = {}) {
2309
+ for (const t in n)
2310
+ if (Object.prototype.hasOwnProperty.call(n, t)) {
2311
+ const r = i ? `${i}_${t}` : t, o = n[t];
2312
2312
  typeof o == "object" && o !== null && !Array.isArray(o) ? Pe(o, r, e) : typeof o == "boolean" ? e[r] = o ? 1 : 0 : e[r] = o;
2313
2313
  }
2314
2314
  return e;
2315
2315
  }
2316
- function gr(i, n) {
2316
+ function gr(n, i) {
2317
2317
  const e = {};
2318
- for (const [t, r] of Object.entries(i)) {
2319
- const o = n.find(
2318
+ for (const [t, r] of Object.entries(n)) {
2319
+ const o = i.find(
2320
2320
  (l) => t.startsWith(`${l}_`)
2321
2321
  );
2322
2322
  if (!o)
@@ -2331,13 +2331,13 @@ function gr(i, n) {
2331
2331
  }
2332
2332
  return e;
2333
2333
  }
2334
- function Fr(i) {
2335
- return typeof i == "string" ? parseInt(i, 10) : typeof i == "bigint" ? Number(i) : i;
2334
+ function Fr(n) {
2335
+ return typeof n == "string" ? parseInt(n, 10) : typeof n == "bigint" ? Number(n) : n;
2336
2336
  }
2337
- function Ur(i) {
2337
+ function Ur(n) {
2338
2338
  return {
2339
- async get(n) {
2340
- const e = await i.select().from(Le).where(a(Le.tenant_id, n)).get();
2339
+ async get(i) {
2340
+ const e = await n.select().from(Le).where(a(Le.tenant_id, i)).get();
2341
2341
  if (!e) return null;
2342
2342
  const {
2343
2343
  tenant_id: t,
@@ -2363,11 +2363,11 @@ function Ur(i) {
2363
2363
  font: c ? { url: c } : void 0
2364
2364
  });
2365
2365
  },
2366
- async set(n, e) {
2366
+ async set(i, e) {
2367
2367
  var _, d, c, u, h, f, y, w;
2368
2368
  const { colors: t, font: r, ...o } = e, l = {
2369
2369
  ...o,
2370
- tenant_id: n,
2370
+ tenant_id: i,
2371
2371
  colors_primary: t == null ? void 0 : t.primary,
2372
2372
  colors_page_background_type: (_ = t == null ? void 0 : t.page_background) == null ? void 0 : _.type,
2373
2373
  colors_page_background_start: (d = t == null ? void 0 : t.page_background) == null ? void 0 : d.start,
@@ -2375,7 +2375,7 @@ function Ur(i) {
2375
2375
  colors_page_background_angle_dev: (u = t == null ? void 0 : t.page_background) == null ? void 0 : u.angle_deg,
2376
2376
  font_url: r == null ? void 0 : r.url
2377
2377
  };
2378
- await i.insert(Le).values(l).onConflictDoUpdate({
2378
+ await n.insert(Le).values(l).onConflictDoUpdate({
2379
2379
  target: Le.tenant_id,
2380
2380
  set: {
2381
2381
  ...o,
@@ -2396,11 +2396,11 @@ var be = class extends Error {
2396
2396
  * @param status - HTTP status code for the exception. Defaults to 500.
2397
2397
  * @param options - Additional options for the exception.
2398
2398
  */
2399
- constructor(n = 500, e) {
2399
+ constructor(i = 500, e) {
2400
2400
  super(e == null ? void 0 : e.message, { cause: e == null ? void 0 : e.cause });
2401
2401
  m(this, "res");
2402
2402
  m(this, "status");
2403
- this.res = e == null ? void 0 : e.res, this.status = n;
2403
+ this.res = e == null ? void 0 : e.res, this.status = i;
2404
2404
  }
2405
2405
  /**
2406
2406
  * Returns the response object associated with the exception.
@@ -2416,15 +2416,15 @@ var be = class extends Error {
2416
2416
  });
2417
2417
  }
2418
2418
  };
2419
- function pe(i, n, e) {
2420
- const t = n.split(/ OR /i);
2419
+ function pe(n, i, e) {
2420
+ const t = i.split(/ OR /i);
2421
2421
  if (t.length > 1) {
2422
2422
  const c = t.map((u) => {
2423
2423
  const h = u.trim().match(/^([^:]+):(.+)$/);
2424
2424
  if (h) {
2425
2425
  const [, f, y] = h;
2426
2426
  if (!f || !y) return null;
2427
- const w = y.replace(/^"(.*)"$/, "$1"), A = i[f.trim()];
2427
+ const w = y.replace(/^"(.*)"$/, "$1"), A = n[f.trim()];
2428
2428
  return A ? a(A, w.trim()) : null;
2429
2429
  }
2430
2430
  return null;
@@ -2433,8 +2433,8 @@ function pe(i, n, e) {
2433
2433
  }
2434
2434
  const r = [];
2435
2435
  let o = "", l = !1;
2436
- for (let c = 0; c < n.length; c++) {
2437
- const u = n[c];
2436
+ for (let c = 0; c < i.length; c++) {
2437
+ const u = i[c];
2438
2438
  u === '"' ? (l = !l, o += u) : u === " " && !l ? o.trim() && (r.push(o.trim()), o = "") : o += u;
2439
2439
  }
2440
2440
  o.trim() && r.push(o.trim());
@@ -2453,7 +2453,7 @@ function pe(i, n, e) {
2453
2453
  }), d = [];
2454
2454
  for (const { key: c, value: u, isNegation: h, isExistsQuery: f, operator: y } of _)
2455
2455
  if (c) {
2456
- const w = i[c];
2456
+ const w = n[c];
2457
2457
  if (!w) {
2458
2458
  f ? d.push(
2459
2459
  h ? N`${N.identifier(c)} IS NULL` : N`${N.identifier(c)} IS NOT NULL`
@@ -2500,7 +2500,7 @@ function pe(i, n, e) {
2500
2500
  }
2501
2501
  } else if (u) {
2502
2502
  const A = (u.includes("|") ? [...e, "user_id"] : e).map((R) => {
2503
- const W = i[R];
2503
+ const W = n[R];
2504
2504
  return W ? R === "user_id" ? a(W, u) : Ie(W, `%${u}%`) : null;
2505
2505
  }).filter(Boolean);
2506
2506
  A.length > 0 && d.push(de(...A));
@@ -2543,8 +2543,8 @@ const kt = [
2543
2543
  "signed_request_object",
2544
2544
  "token_quota"
2545
2545
  ];
2546
- function Ue(i) {
2547
- const { tenant_id: n, connections: e, ...t } = i, r = { ...t };
2546
+ function Ue(n) {
2547
+ const { tenant_id: i, connections: e, ...t } = n, r = { ...t };
2548
2548
  for (const o of kt)
2549
2549
  r[o] = !!t[o];
2550
2550
  for (const o of It)
@@ -2553,26 +2553,26 @@ function Ue(i) {
2553
2553
  r[o] = b(t[o], {});
2554
2554
  return r.connections = b(e, []), z(r);
2555
2555
  }
2556
- function At(i) {
2557
- const n = { ...i };
2556
+ function At(n) {
2557
+ const i = { ...n };
2558
2558
  Jr(
2559
- i,
2559
+ n,
2560
2560
  kt,
2561
- n
2561
+ i
2562
2562
  );
2563
2563
  for (const e of It)
2564
- i[e] !== void 0 && (n[e] = JSON.stringify(i[e] || []));
2564
+ n[e] !== void 0 && (i[e] = JSON.stringify(n[e] || []));
2565
2565
  for (const e of zt)
2566
- i[e] !== void 0 && (n[e] = JSON.stringify(i[e] || {}));
2567
- return i.connections !== void 0 && (n.connections = JSON.stringify(i.connections || [])), cr(n);
2566
+ n[e] !== void 0 && (i[e] = JSON.stringify(n[e] || {}));
2567
+ return n.connections !== void 0 && (i.connections = JSON.stringify(n.connections || [])), cr(i);
2568
2568
  }
2569
- function Kr(i) {
2569
+ function Kr(n) {
2570
2570
  return {
2571
- async create(n, e) {
2571
+ async create(i, e) {
2572
2572
  var l, _;
2573
2573
  const t = (/* @__PURE__ */ new Date()).toISOString(), r = {
2574
2574
  client_id: e.client_id,
2575
- tenant_id: n,
2575
+ tenant_id: i,
2576
2576
  name: e.name,
2577
2577
  description: e.description,
2578
2578
  app_type: e.app_type ?? "regular_web",
@@ -2601,43 +2601,43 @@ function Kr(i) {
2601
2601
  r.connections = e.connections || [];
2602
2602
  const o = At(r);
2603
2603
  try {
2604
- await i.insert(I).values({ ...o, tenant_id: n });
2604
+ await n.insert(I).values({ ...o, tenant_id: i });
2605
2605
  } catch (d) {
2606
2606
  throw (l = d == null ? void 0 : d.message) != null && l.includes("UNIQUE constraint failed") || (_ = d == null ? void 0 : d.message) != null && _.includes("duplicate key") ? new be(409, {
2607
2607
  message: "Client already exists"
2608
2608
  }) : d;
2609
2609
  }
2610
- return Ue({ ...o, tenant_id: n });
2610
+ return Ue({ ...o, tenant_id: i });
2611
2611
  },
2612
- async get(n, e) {
2613
- const t = await i.select().from(I).where(
2612
+ async get(i, e) {
2613
+ const t = await n.select().from(I).where(
2614
2614
  g(
2615
- a(I.tenant_id, n),
2615
+ a(I.tenant_id, i),
2616
2616
  a(I.client_id, e)
2617
2617
  )
2618
2618
  ).get();
2619
2619
  return t ? Ue(t) : null;
2620
2620
  },
2621
- async getByClientId(n) {
2622
- const e = await i.select().from(I).where(a(I.client_id, n)).get();
2621
+ async getByClientId(i) {
2622
+ const e = await n.select().from(I).where(a(I.client_id, i)).get();
2623
2623
  return e ? {
2624
2624
  ...Ue(e),
2625
2625
  tenant_id: e.tenant_id
2626
2626
  } : null;
2627
2627
  },
2628
- async update(n, e, t) {
2628
+ async update(i, e, t) {
2629
2629
  const r = At({
2630
2630
  ...t,
2631
2631
  updated_at: (/* @__PURE__ */ new Date()).toISOString()
2632
2632
  });
2633
- return delete r.client_id, delete r.tenant_id, await i.update(I).set(r).where(
2633
+ return delete r.client_id, delete r.tenant_id, await n.update(I).set(r).where(
2634
2634
  g(
2635
- a(I.tenant_id, n),
2635
+ a(I.tenant_id, i),
2636
2636
  a(I.client_id, e)
2637
2637
  )
2638
2638
  ), !0;
2639
2639
  },
2640
- async list(n, e) {
2640
+ async list(i, e) {
2641
2641
  const {
2642
2642
  page: t = 0,
2643
2643
  per_page: r = 50,
@@ -2645,10 +2645,10 @@ function Kr(i) {
2645
2645
  sort: l,
2646
2646
  q: _
2647
2647
  } = e || {};
2648
- let d = i.select().from(I).where(a(I.tenant_id, n)).$dynamic();
2648
+ let d = n.select().from(I).where(a(I.tenant_id, i)).$dynamic();
2649
2649
  if (_) {
2650
2650
  const f = pe(I, _, ["name", "client_id"]);
2651
- f && (d = d.where(g(a(I.tenant_id, n), f)));
2651
+ f && (d = d.where(g(a(I.tenant_id, i), f)));
2652
2652
  }
2653
2653
  if (l != null && l.sort_by) {
2654
2654
  const f = I[l.sort_by];
@@ -2659,7 +2659,7 @@ function Kr(i) {
2659
2659
  const u = (await d.offset(t * r).limit(r)).map(Ue);
2660
2660
  if (!o)
2661
2661
  return { clients: u };
2662
- const [h] = await i.select({ count: V() }).from(I).where(a(I.tenant_id, n));
2662
+ const [h] = await n.select({ count: V() }).from(I).where(a(I.tenant_id, i));
2663
2663
  return {
2664
2664
  clients: u,
2665
2665
  start: t * r,
@@ -2667,18 +2667,18 @@ function Kr(i) {
2667
2667
  length: Number((h == null ? void 0 : h.count) ?? 0)
2668
2668
  };
2669
2669
  },
2670
- async remove(n, e) {
2671
- return (await i.delete(I).where(
2670
+ async remove(i, e) {
2671
+ return (await n.delete(I).where(
2672
2672
  g(
2673
- a(I.tenant_id, n),
2673
+ a(I.tenant_id, i),
2674
2674
  a(I.client_id, e)
2675
2675
  )
2676
2676
  ).returning()).length > 0;
2677
2677
  }
2678
2678
  };
2679
2679
  }
2680
- function jr(i) {
2681
- const { tenant_id: n, is_system: e, options: t, metadata: r, ...o } = i;
2680
+ function jr(n) {
2681
+ const { tenant_id: i, is_system: e, options: t, metadata: r, ...o } = n;
2682
2682
  return z({
2683
2683
  ...o,
2684
2684
  options: b(t, {}),
@@ -2686,49 +2686,49 @@ function jr(i) {
2686
2686
  is_system: e ? !0 : void 0
2687
2687
  });
2688
2688
  }
2689
- function Mr(i) {
2689
+ function Mr(n) {
2690
2690
  return {
2691
- async listByClient(n, e) {
2692
- const t = await i.select({ connections: I.connections }).from(I).where(
2691
+ async listByClient(i, e) {
2692
+ const t = await n.select({ connections: I.connections }).from(I).where(
2693
2693
  g(
2694
- a(I.tenant_id, n),
2694
+ a(I.tenant_id, i),
2695
2695
  a(I.client_id, e)
2696
2696
  )
2697
2697
  ).get();
2698
2698
  if (!t) return [];
2699
2699
  const r = b(t.connections, []) || [];
2700
2700
  if (r.length === 0) return [];
2701
- const l = (await i.select().from(U).where(
2701
+ const l = (await n.select().from(U).where(
2702
2702
  g(
2703
- a(U.tenant_id, n),
2703
+ a(U.tenant_id, i),
2704
2704
  we(U.id, r)
2705
2705
  )
2706
2706
  ).all()).map(jr);
2707
2707
  return r.map((_) => l.find((d) => d.id === _)).filter(Boolean);
2708
2708
  },
2709
- async updateByClient(n, e, t) {
2710
- return (await i.update(I).set({ connections: JSON.stringify([...new Set(t)]) }).where(
2709
+ async updateByClient(i, e, t) {
2710
+ return (await n.update(I).set({ connections: JSON.stringify([...new Set(t)]) }).where(
2711
2711
  g(
2712
- a(I.tenant_id, n),
2712
+ a(I.tenant_id, i),
2713
2713
  a(I.client_id, e)
2714
2714
  )
2715
2715
  ).returning()).length > 0;
2716
2716
  },
2717
- async listByConnection(n, e) {
2718
- return (await i.select({
2717
+ async listByConnection(i, e) {
2718
+ return (await n.select({
2719
2719
  client_id: I.client_id,
2720
2720
  connections: I.connections
2721
- }).from(I).where(a(I.tenant_id, n)).all()).filter((r) => (b(r.connections, []) || []).includes(e)).map((r) => r.client_id);
2721
+ }).from(I).where(a(I.tenant_id, i)).all()).filter((r) => (b(r.connections, []) || []).includes(e)).map((r) => r.client_id);
2722
2722
  },
2723
- async addClientToConnection(n, e, t) {
2723
+ async addClientToConnection(i, e, t) {
2724
2724
  var _;
2725
- if (!await i.select({ client_id: I.client_id }).from(I).where(
2725
+ if (!await n.select({ client_id: I.client_id }).from(I).where(
2726
2726
  g(
2727
- a(I.tenant_id, n),
2727
+ a(I.tenant_id, i),
2728
2728
  a(I.client_id, t)
2729
2729
  )
2730
2730
  ).get()) return !1;
2731
- const o = await i.run(
2731
+ const o = await n.run(
2732
2732
  N`UPDATE clients SET connections = CASE
2733
2733
  WHEN connections IS NULL OR connections = '[]' OR connections = ''
2734
2734
  THEN json_array(${e})
@@ -2736,64 +2736,64 @@ function Mr(i) {
2736
2736
  THEN connections
2737
2737
  ELSE json_insert(connections, '$[#]', ${e})
2738
2738
  END
2739
- WHERE tenant_id = ${n} AND client_id = ${t}`
2739
+ WHERE tenant_id = ${i} AND client_id = ${t}`
2740
2740
  );
2741
2741
  return (o.changes ?? ((_ = o.meta) == null ? void 0 : _.changes) ?? 0) > 0;
2742
2742
  },
2743
- async removeClientFromConnection(n, e, t) {
2743
+ async removeClientFromConnection(i, e, t) {
2744
2744
  var l;
2745
- const r = await i.run(
2745
+ const r = await n.run(
2746
2746
  N`UPDATE clients SET connections = (
2747
2747
  SELECT COALESCE(json_group_array(je.value), '[]')
2748
2748
  FROM json_each(COALESCE(connections, '[]')) AS je
2749
2749
  WHERE je.value != ${e}
2750
2750
  )
2751
- WHERE tenant_id = ${n} AND client_id = ${t}`
2751
+ WHERE tenant_id = ${i} AND client_id = ${t}`
2752
2752
  );
2753
2753
  return (r.changes ?? ((l = r.meta) == null ? void 0 : l.changes) ?? 0) > 0;
2754
2754
  }
2755
2755
  };
2756
2756
  }
2757
- let Vr = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict", Rr = (i) => crypto.getRandomValues(new Uint8Array(i)), Wr = (i, n, e) => {
2758
- let t = 256 - 256 % i.length;
2757
+ let Vr = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict", Rr = (n) => crypto.getRandomValues(new Uint8Array(n)), Wr = (n, i, e) => {
2758
+ let t = 256 - 256 % n.length;
2759
2759
  if (t === 256) {
2760
- let o = i.length - 1;
2761
- return (l = n) => {
2760
+ let o = n.length - 1;
2761
+ return (l = i) => {
2762
2762
  if (!l) return "";
2763
2763
  let _ = "";
2764
2764
  for (; ; ) {
2765
2765
  let d = e(l), c = l;
2766
2766
  for (; c--; )
2767
- if (_ += i[d[c] & o], _.length >= l) return _;
2767
+ if (_ += n[d[c] & o], _.length >= l) return _;
2768
2768
  }
2769
2769
  };
2770
2770
  }
2771
- let r = Math.ceil(1.6 * 256 * n / t);
2772
- return (o = n) => {
2771
+ let r = Math.ceil(1.6 * 256 * i / t);
2772
+ return (o = i) => {
2773
2773
  if (!o) return "";
2774
2774
  let l = "";
2775
2775
  for (; ; ) {
2776
2776
  let _ = e(r), d = r;
2777
2777
  for (; d--; )
2778
- if (_[d] < t && (l += i[_[d] % i.length], l.length >= o))
2778
+ if (_[d] < t && (l += n[_[d] % n.length], l.length >= o))
2779
2779
  return l;
2780
2780
  }
2781
2781
  };
2782
- }, Hr = (i, n = 21) => Wr(i, n | 0, Rr), ae = (i = 21) => {
2783
- let n = "", e = crypto.getRandomValues(new Uint8Array(i |= 0));
2784
- for (; i--; )
2785
- n += Vr[e[i] & 63];
2786
- return n;
2782
+ }, Hr = (n, i = 21) => Wr(n, i | 0, Rr), ae = (n = 21) => {
2783
+ let i = "", e = crypto.getRandomValues(new Uint8Array(n |= 0));
2784
+ for (; n--; )
2785
+ i += Vr[e[n] & 63];
2786
+ return i;
2787
2787
  };
2788
- function nt(i) {
2788
+ function nt(n) {
2789
2789
  const {
2790
- tenant_id: n,
2790
+ tenant_id: i,
2791
2791
  scope: e,
2792
2792
  authorization_details_types: t,
2793
2793
  allow_any_organization: r,
2794
2794
  is_system: o,
2795
2795
  ...l
2796
- } = i;
2796
+ } = n;
2797
2797
  return z({
2798
2798
  ...l,
2799
2799
  scope: b(e, []),
@@ -2805,12 +2805,12 @@ function nt(i) {
2805
2805
  is_system: !!o
2806
2806
  });
2807
2807
  }
2808
- function Gr(i) {
2808
+ function Gr(n) {
2809
2809
  return {
2810
- async create(n, e) {
2810
+ async create(i, e) {
2811
2811
  const t = (/* @__PURE__ */ new Date()).toISOString(), o = {
2812
2812
  id: e.id || ae(),
2813
- tenant_id: n,
2813
+ tenant_id: i,
2814
2814
  client_id: e.client_id,
2815
2815
  audience: e.audience,
2816
2816
  scope: JSON.stringify(e.scope || []),
@@ -2824,15 +2824,15 @@ function Gr(i) {
2824
2824
  created_at: t,
2825
2825
  updated_at: t
2826
2826
  };
2827
- return await i.insert(G).values(o), nt({ ...o, tenant_id: n });
2827
+ return await n.insert(G).values(o), nt({ ...o, tenant_id: i });
2828
2828
  },
2829
- async get(n, e) {
2830
- const t = await i.select().from(G).where(
2831
- g(a(G.tenant_id, n), a(G.id, e))
2829
+ async get(i, e) {
2830
+ const t = await n.select().from(G).where(
2831
+ g(a(G.tenant_id, i), a(G.id, e))
2832
2832
  ).get();
2833
2833
  return t ? nt(t) : null;
2834
2834
  },
2835
- async update(n, e, t) {
2835
+ async update(i, e, t) {
2836
2836
  const {
2837
2837
  scope: r,
2838
2838
  authorization_details_types: o,
@@ -2845,19 +2845,19 @@ function Gr(i) {
2845
2845
  };
2846
2846
  return r !== void 0 && (c.scope = JSON.stringify(r)), o !== void 0 && (c.authorization_details_types = JSON.stringify(
2847
2847
  o
2848
- )), l !== void 0 && (c.allow_any_organization = l ? 1 : 0), _ !== void 0 && (c.is_system = _ ? 1 : 0), (await i.update(G).set(c).where(
2849
- g(a(G.tenant_id, n), a(G.id, e))
2848
+ )), l !== void 0 && (c.allow_any_organization = l ? 1 : 0), _ !== void 0 && (c.is_system = _ ? 1 : 0), (await n.update(G).set(c).where(
2849
+ g(a(G.tenant_id, i), a(G.id, e))
2850
2850
  ).returning()).length > 0;
2851
2851
  },
2852
- async list(n, e) {
2852
+ async list(i, e) {
2853
2853
  const {
2854
2854
  page: t = 0,
2855
2855
  per_page: r = 50,
2856
2856
  include_totals: o = !1,
2857
2857
  sort: l,
2858
2858
  q: _
2859
- } = e || {}, d = _ ? pe(G, _, ["client_id", "audience"]) : void 0, c = d ? g(a(G.tenant_id, n), d) : a(G.tenant_id, n);
2860
- let u = i.select().from(G).where(c).$dynamic();
2859
+ } = e || {}, d = _ ? pe(G, _, ["client_id", "audience"]) : void 0, c = d ? g(a(G.tenant_id, i), d) : a(G.tenant_id, i);
2860
+ let u = n.select().from(G).where(c).$dynamic();
2861
2861
  if (l != null && l.sort_by) {
2862
2862
  const w = G[l.sort_by];
2863
2863
  w && (u = u.orderBy(
@@ -2868,7 +2868,7 @@ function Gr(i) {
2868
2868
  const f = (await u.offset(t * r).limit(r)).map(nt);
2869
2869
  if (!o)
2870
2870
  return { client_grants: f };
2871
- const [y] = await i.select({ count: V() }).from(G).where(c);
2871
+ const [y] = await n.select({ count: V() }).from(G).where(c);
2872
2872
  return {
2873
2873
  client_grants: f,
2874
2874
  start: t * r,
@@ -2876,48 +2876,48 @@ function Gr(i) {
2876
2876
  length: Number((y == null ? void 0 : y.count) ?? 0)
2877
2877
  };
2878
2878
  },
2879
- async remove(n, e) {
2880
- return (await i.delete(G).where(
2881
- g(a(G.tenant_id, n), a(G.id, e))
2879
+ async remove(i, e) {
2880
+ return (await n.delete(G).where(
2881
+ g(a(G.tenant_id, i), a(G.id, e))
2882
2882
  ).returning()).length > 0;
2883
2883
  }
2884
2884
  };
2885
2885
  }
2886
- function it(i) {
2887
- const { tenant_id: n, ...e } = i;
2886
+ function it(n) {
2887
+ const { tenant_id: i, ...e } = n;
2888
2888
  return z(e);
2889
2889
  }
2890
- function Yr(i) {
2890
+ function Yr(n) {
2891
2891
  return {
2892
- async create(n, e) {
2892
+ async create(i, e) {
2893
2893
  const t = {
2894
2894
  ...e,
2895
- tenant_id: n,
2895
+ tenant_id: i,
2896
2896
  created_at: e.created_at || (/* @__PURE__ */ new Date()).toISOString(),
2897
2897
  expires_at: e.expires_at
2898
2898
  };
2899
- return await i.insert(B).values(t), it(t);
2899
+ return await n.insert(B).values(t), it(t);
2900
2900
  },
2901
- async get(n, e, t) {
2902
- if (!n)
2901
+ async get(i, e, t) {
2902
+ if (!i)
2903
2903
  throw new Error("tenant_id is required");
2904
- const r = await i.select().from(B).where(
2904
+ const r = await n.select().from(B).where(
2905
2905
  g(
2906
- a(B.tenant_id, n),
2906
+ a(B.tenant_id, i),
2907
2907
  a(B.code_id, e),
2908
2908
  a(B.code_type, t)
2909
2909
  )
2910
2910
  ).get();
2911
2911
  return r ? it(r) : null;
2912
2912
  },
2913
- async list(n, e) {
2913
+ async list(i, e) {
2914
2914
  const {
2915
2915
  page: t = 0,
2916
2916
  per_page: r = 50,
2917
2917
  include_totals: o = !1,
2918
2918
  sort: l
2919
2919
  } = e || {};
2920
- let _ = i.select().from(B).where(a(B.tenant_id, n)).$dynamic();
2920
+ let _ = n.select().from(B).where(a(B.tenant_id, i)).$dynamic();
2921
2921
  if (l != null && l.sort_by) {
2922
2922
  const h = B[l.sort_by];
2923
2923
  h && (_ = _.orderBy(
@@ -2927,7 +2927,7 @@ function Yr(i) {
2927
2927
  const c = (await _.offset(t * r).limit(r)).map(it);
2928
2928
  if (!o)
2929
2929
  return { codes: c };
2930
- const [u] = await i.select({ count: V() }).from(B).where(a(B.tenant_id, n));
2930
+ const [u] = await n.select({ count: V() }).from(B).where(a(B.tenant_id, i));
2931
2931
  return {
2932
2932
  codes: c,
2933
2933
  start: t * r,
@@ -2935,29 +2935,29 @@ function Yr(i) {
2935
2935
  length: Number((u == null ? void 0 : u.count) ?? 0)
2936
2936
  };
2937
2937
  },
2938
- async used(n, e) {
2939
- return (await i.update(B).set({ used_at: (/* @__PURE__ */ new Date()).toISOString() }).where(g(a(B.tenant_id, n), a(B.code_id, e))).returning()).length > 0;
2938
+ async used(i, e) {
2939
+ return (await n.update(B).set({ used_at: (/* @__PURE__ */ new Date()).toISOString() }).where(g(a(B.tenant_id, i), a(B.code_id, e))).returning()).length > 0;
2940
2940
  },
2941
- async consume(n, e) {
2942
- return (await i.update(B).set({ used_at: (/* @__PURE__ */ new Date()).toISOString() }).where(
2941
+ async consume(i, e) {
2942
+ return (await n.update(B).set({ used_at: (/* @__PURE__ */ new Date()).toISOString() }).where(
2943
2943
  g(
2944
- a(B.tenant_id, n),
2944
+ a(B.tenant_id, i),
2945
2945
  a(B.code_id, e),
2946
2946
  ye(B.used_at)
2947
2947
  )
2948
2948
  ).returning()).length > 0;
2949
2949
  },
2950
- async remove(n, e) {
2951
- return (await i.delete(B).where(g(a(B.tenant_id, n), a(B.code_id, e))).returning()).length > 0;
2950
+ async remove(i, e) {
2951
+ return (await n.delete(B).where(g(a(B.tenant_id, i), a(B.code_id, e))).returning()).length > 0;
2952
2952
  }
2953
2953
  };
2954
2954
  }
2955
2955
  function Xr() {
2956
- const { customAlphabet: i } = require("nanoid");
2957
- return `con_${i("0123456789abcdefghijklmnopqrstuvwxyz", 17)()}`;
2956
+ const { customAlphabet: n } = require("nanoid");
2957
+ return `con_${n("0123456789abcdefghijklmnopqrstuvwxyz", 17)()}`;
2958
2958
  }
2959
- function rt(i) {
2960
- const { tenant_id: n, is_system: e, options: t, metadata: r, ...o } = i;
2959
+ function rt(n) {
2960
+ const { tenant_id: i, is_system: e, options: t, metadata: r, ...o } = n;
2961
2961
  return z({
2962
2962
  ...o,
2963
2963
  options: b(t, {}),
@@ -2965,14 +2965,14 @@ function rt(i) {
2965
2965
  is_system: e ? !0 : void 0
2966
2966
  });
2967
2967
  }
2968
- function Zr(i) {
2968
+ function Zr(n) {
2969
2969
  return {
2970
- async create(n, e) {
2970
+ async create(i, e) {
2971
2971
  var o, l;
2972
2972
  const t = (/* @__PURE__ */ new Date()).toISOString(), r = {
2973
2973
  id: e.id || Xr(),
2974
2974
  ...e,
2975
- tenant_id: n,
2975
+ tenant_id: i,
2976
2976
  options: JSON.stringify(e.options || {}),
2977
2977
  metadata: e.metadata ? JSON.stringify(e.metadata) : void 0,
2978
2978
  is_system: e.is_system ? 1 : 0,
@@ -2980,7 +2980,7 @@ function Zr(i) {
2980
2980
  updated_at: t
2981
2981
  };
2982
2982
  try {
2983
- await i.insert(U).values(r);
2983
+ await n.insert(U).values(r);
2984
2984
  } catch (_) {
2985
2985
  throw (o = _ == null ? void 0 : _.message) != null && o.includes("UNIQUE constraint failed") || (l = _ == null ? void 0 : _.message) != null && l.includes("duplicate key") ? new be(409, {
2986
2986
  message: "Connection already exists"
@@ -2988,27 +2988,27 @@ function Zr(i) {
2988
2988
  }
2989
2989
  return rt(r);
2990
2990
  },
2991
- async get(n, e) {
2992
- const t = await i.select().from(U).where(
2991
+ async get(i, e) {
2992
+ const t = await n.select().from(U).where(
2993
2993
  g(
2994
- a(U.tenant_id, n),
2994
+ a(U.tenant_id, i),
2995
2995
  a(U.id, e)
2996
2996
  )
2997
2997
  ).get();
2998
2998
  return t ? rt(t) : null;
2999
2999
  },
3000
- async update(n, e, t) {
3000
+ async update(i, e, t) {
3001
3001
  const r = {
3002
3002
  updated_at: (/* @__PURE__ */ new Date()).toISOString()
3003
3003
  };
3004
- return t.name !== void 0 && (r.name = t.name), t.strategy !== void 0 && (r.strategy = t.strategy), t.options !== void 0 && (r.options = JSON.stringify(t.options)), t.metadata !== void 0 && (r.metadata = JSON.stringify(t.metadata)), t.display_name !== void 0 && (r.display_name = t.display_name), t.response_type !== void 0 && (r.response_type = t.response_type), t.response_mode !== void 0 && (r.response_mode = t.response_mode), await i.update(U).set(r).where(
3004
+ return t.name !== void 0 && (r.name = t.name), t.strategy !== void 0 && (r.strategy = t.strategy), t.options !== void 0 && (r.options = JSON.stringify(t.options)), t.metadata !== void 0 && (r.metadata = JSON.stringify(t.metadata)), t.display_name !== void 0 && (r.display_name = t.display_name), t.response_type !== void 0 && (r.response_type = t.response_type), t.response_mode !== void 0 && (r.response_mode = t.response_mode), await n.update(U).set(r).where(
3005
3005
  g(
3006
- a(U.tenant_id, n),
3006
+ a(U.tenant_id, i),
3007
3007
  a(U.id, e)
3008
3008
  )
3009
3009
  ), !0;
3010
3010
  },
3011
- async list(n, e) {
3011
+ async list(i, e) {
3012
3012
  const {
3013
3013
  page: t = 0,
3014
3014
  per_page: r = 50,
@@ -3016,12 +3016,12 @@ function Zr(i) {
3016
3016
  sort: l,
3017
3017
  q: _
3018
3018
  } = e || {};
3019
- let d = a(U.tenant_id, n);
3019
+ let d = a(U.tenant_id, i);
3020
3020
  if (_) {
3021
3021
  const y = pe(U, _, ["name"]);
3022
3022
  y && (d = g(d, y));
3023
3023
  }
3024
- let c = i.select().from(U).where(d).$dynamic();
3024
+ let c = n.select().from(U).where(d).$dynamic();
3025
3025
  if (l != null && l.sort_by) {
3026
3026
  const y = U[l.sort_by];
3027
3027
  y && (c = c.orderBy(
@@ -3031,7 +3031,7 @@ function Zr(i) {
3031
3031
  const h = (await c.offset(t * r).limit(r)).map(rt);
3032
3032
  if (!o)
3033
3033
  return { connections: h };
3034
- const [f] = await i.select({ count: V() }).from(U).where(d);
3034
+ const [f] = await n.select({ count: V() }).from(U).where(d);
3035
3035
  return {
3036
3036
  connections: h,
3037
3037
  start: t * r,
@@ -3039,30 +3039,30 @@ function Zr(i) {
3039
3039
  length: Number((f == null ? void 0 : f.count) ?? 0)
3040
3040
  };
3041
3041
  },
3042
- async remove(n, e) {
3043
- return (await i.delete(U).where(
3042
+ async remove(i, e) {
3043
+ return (await n.delete(U).where(
3044
3044
  g(
3045
- a(U.tenant_id, n),
3045
+ a(U.tenant_id, i),
3046
3046
  a(U.id, e)
3047
3047
  )
3048
3048
  ).returning()).length > 0;
3049
3049
  }
3050
3050
  };
3051
3051
  }
3052
- function Ke(i) {
3053
- const { tenant_id: n, domain_metadata: e, ...t } = i;
3052
+ function Ke(n) {
3053
+ const { tenant_id: i, domain_metadata: e, ...t } = n;
3054
3054
  return z({
3055
3055
  ...t,
3056
3056
  primary: !!t.primary,
3057
3057
  domain_metadata: b(e)
3058
3058
  });
3059
3059
  }
3060
- function es(i) {
3060
+ function es(n) {
3061
3061
  return {
3062
- async create(n, e) {
3062
+ async create(i, e) {
3063
3063
  const t = (/* @__PURE__ */ new Date()).toISOString(), o = {
3064
3064
  custom_domain_id: e.custom_domain_id || ae(),
3065
- tenant_id: n,
3065
+ tenant_id: i,
3066
3066
  domain: e.domain,
3067
3067
  primary: e.primary ?? !1,
3068
3068
  status: e.status || "pending",
@@ -3075,54 +3075,54 @@ function es(i) {
3075
3075
  created_at: t,
3076
3076
  updated_at: t
3077
3077
  };
3078
- return await i.insert(re).values(o), Ke({ ...o, tenant_id: n });
3078
+ return await n.insert(re).values(o), Ke({ ...o, tenant_id: i });
3079
3079
  },
3080
- async get(n, e) {
3081
- const t = await i.select().from(re).where(
3080
+ async get(i, e) {
3081
+ const t = await n.select().from(re).where(
3082
3082
  g(
3083
- a(re.tenant_id, n),
3083
+ a(re.tenant_id, i),
3084
3084
  a(re.custom_domain_id, e)
3085
3085
  )
3086
3086
  ).get();
3087
3087
  return t ? Ke(t) : null;
3088
3088
  },
3089
- async getByDomain(n) {
3090
- const e = await i.select().from(re).where(a(re.domain, n)).get();
3089
+ async getByDomain(i) {
3090
+ const e = await n.select().from(re).where(a(re.domain, i)).get();
3091
3091
  return e ? {
3092
3092
  ...Ke(e),
3093
3093
  tenant_id: e.tenant_id
3094
3094
  } : null;
3095
3095
  },
3096
- async list(n) {
3097
- return (await i.select().from(re).where(a(re.tenant_id, n)).all()).map(Ke);
3096
+ async list(i) {
3097
+ return (await n.select().from(re).where(a(re.tenant_id, i)).all()).map(Ke);
3098
3098
  },
3099
- async update(n, e, t) {
3099
+ async update(i, e, t) {
3100
3100
  const r = {
3101
3101
  updated_at: (/* @__PURE__ */ new Date()).toISOString()
3102
3102
  };
3103
- return t.domain !== void 0 && (r.domain = t.domain), t.primary !== void 0 && (r.primary = t.primary), t.status !== void 0 && (r.status = t.status), t.type !== void 0 && (r.type = t.type), t.origin_domain_name !== void 0 && (r.origin_domain_name = t.origin_domain_name), t.verification !== void 0 && (r.verification = t.verification), t.custom_client_ip_header !== void 0 && (r.custom_client_ip_header = t.custom_client_ip_header), t.tls_policy !== void 0 && (r.tls_policy = t.tls_policy), t.domain_metadata !== void 0 && (r.domain_metadata = JSON.stringify(t.domain_metadata)), (await i.update(re).set(r).where(
3103
+ return t.domain !== void 0 && (r.domain = t.domain), t.primary !== void 0 && (r.primary = t.primary), t.status !== void 0 && (r.status = t.status), t.type !== void 0 && (r.type = t.type), t.origin_domain_name !== void 0 && (r.origin_domain_name = t.origin_domain_name), t.verification !== void 0 && (r.verification = t.verification), t.custom_client_ip_header !== void 0 && (r.custom_client_ip_header = t.custom_client_ip_header), t.tls_policy !== void 0 && (r.tls_policy = t.tls_policy), t.domain_metadata !== void 0 && (r.domain_metadata = JSON.stringify(t.domain_metadata)), (await n.update(re).set(r).where(
3104
3104
  g(
3105
- a(re.tenant_id, n),
3105
+ a(re.tenant_id, i),
3106
3106
  a(re.custom_domain_id, e)
3107
3107
  )
3108
3108
  ).returning()).length > 0;
3109
3109
  },
3110
- async remove(n, e) {
3111
- return (await i.delete(re).where(
3110
+ async remove(i, e) {
3111
+ return (await n.delete(re).where(
3112
3112
  g(
3113
- a(re.tenant_id, n),
3113
+ a(re.tenant_id, i),
3114
3114
  a(re.custom_domain_id, e)
3115
3115
  )
3116
3116
  ).returning()).length > 0;
3117
3117
  }
3118
3118
  };
3119
3119
  }
3120
- function ts(i) {
3120
+ function ts(n) {
3121
3121
  return {
3122
- async get(n, e, t) {
3123
- const r = await i.select().from(ee).where(
3122
+ async get(i, e, t) {
3123
+ const r = await n.select().from(ee).where(
3124
3124
  g(
3125
- a(ee.tenant_id, n),
3125
+ a(ee.tenant_id, i),
3126
3126
  a(ee.prompt, e),
3127
3127
  a(ee.language, t)
3128
3128
  )
@@ -3134,10 +3134,10 @@ function ts(i) {
3134
3134
  return null;
3135
3135
  }
3136
3136
  },
3137
- async set(n, e, t, r) {
3137
+ async set(i, e, t, r) {
3138
3138
  const o = Date.now(), l = JSON.stringify(r);
3139
- await i.insert(ee).values({
3140
- tenant_id: n,
3139
+ await n.insert(ee).values({
3140
+ tenant_id: i,
3141
3141
  prompt: e,
3142
3142
  language: t,
3143
3143
  custom_text: l,
@@ -3152,29 +3152,29 @@ function ts(i) {
3152
3152
  set: { custom_text: l, updated_at_ts: o }
3153
3153
  });
3154
3154
  },
3155
- async delete(n, e, t) {
3156
- await i.delete(ee).where(
3155
+ async delete(i, e, t) {
3156
+ await n.delete(ee).where(
3157
3157
  g(
3158
- a(ee.tenant_id, n),
3158
+ a(ee.tenant_id, i),
3159
3159
  a(ee.prompt, e),
3160
3160
  a(ee.language, t)
3161
3161
  )
3162
3162
  );
3163
3163
  },
3164
- async list(n) {
3165
- return await i.select({
3164
+ async list(i) {
3165
+ return await n.select({
3166
3166
  prompt: ee.prompt,
3167
3167
  language: ee.language
3168
- }).from(ee).where(a(ee.tenant_id, n)).all();
3168
+ }).from(ee).where(a(ee.tenant_id, i)).all();
3169
3169
  }
3170
3170
  };
3171
3171
  }
3172
- function ns(i) {
3172
+ function ns(n) {
3173
3173
  return {
3174
- async create(n, e) {
3174
+ async create(i, e) {
3175
3175
  const t = (/* @__PURE__ */ new Date()).toISOString();
3176
- await i.insert(ve).values({
3177
- tenant_id: n,
3176
+ await n.insert(ve).values({
3177
+ tenant_id: i,
3178
3178
  name: e.name,
3179
3179
  enabled: e.enabled,
3180
3180
  default_from_address: e.default_from_address,
@@ -3184,8 +3184,8 @@ function ns(i) {
3184
3184
  updated_at: t
3185
3185
  });
3186
3186
  },
3187
- async get(n) {
3188
- const e = await i.select().from(ve).where(a(ve.tenant_id, n)).get();
3187
+ async get(i) {
3188
+ const e = await n.select().from(ve).where(a(ve.tenant_id, i)).get();
3189
3189
  if (!e) return null;
3190
3190
  const { tenant_id: t, ...r } = e;
3191
3191
  return z({
@@ -3195,24 +3195,24 @@ function ns(i) {
3195
3195
  settings: b(r.settings, {})
3196
3196
  });
3197
3197
  },
3198
- async update(n, e) {
3198
+ async update(i, e) {
3199
3199
  const t = {
3200
3200
  updated_at: (/* @__PURE__ */ new Date()).toISOString()
3201
3201
  };
3202
- e.name !== void 0 && (t.name = e.name), e.enabled !== void 0 && (t.enabled = e.enabled), e.default_from_address !== void 0 && (t.default_from_address = e.default_from_address), e.credentials !== void 0 && (t.credentials = JSON.stringify(e.credentials)), e.settings !== void 0 && (t.settings = JSON.stringify(e.settings)), await i.update(ve).set(t).where(a(ve.tenant_id, n));
3202
+ e.name !== void 0 && (t.name = e.name), e.enabled !== void 0 && (t.enabled = e.enabled), e.default_from_address !== void 0 && (t.default_from_address = e.default_from_address), e.credentials !== void 0 && (t.credentials = JSON.stringify(e.credentials)), e.settings !== void 0 && (t.settings = JSON.stringify(e.settings)), await n.update(ve).set(t).where(a(ve.tenant_id, i));
3203
3203
  },
3204
- async remove(n) {
3205
- await i.delete(ve).where(a(ve.tenant_id, n));
3204
+ async remove(i) {
3205
+ await n.delete(ve).where(a(ve.tenant_id, i));
3206
3206
  }
3207
3207
  };
3208
3208
  }
3209
- function is(i) {
3209
+ function is(n) {
3210
3210
  return {
3211
- async create(n, e) {
3211
+ async create(i, e) {
3212
3212
  const t = (/* @__PURE__ */ new Date()).toISOString(), r = `af_${ae()}`;
3213
- return await i.insert(ie).values({
3213
+ return await n.insert(ie).values({
3214
3214
  id: r,
3215
- tenant_id: n,
3215
+ tenant_id: i,
3216
3216
  name: e.name,
3217
3217
  actions: JSON.stringify(e.actions || []),
3218
3218
  created_at: t,
@@ -3225,8 +3225,8 @@ function is(i) {
3225
3225
  updated_at: t
3226
3226
  };
3227
3227
  },
3228
- async get(n, e) {
3229
- const t = await i.select().from(ie).where(g(a(ie.tenant_id, n), a(ie.id, e))).get();
3228
+ async get(i, e) {
3229
+ const t = await n.select().from(ie).where(g(a(ie.tenant_id, i), a(ie.id, e))).get();
3230
3230
  if (!t) return null;
3231
3231
  const { tenant_id: r, actions: o, ...l } = t;
3232
3232
  return z({
@@ -3234,20 +3234,20 @@ function is(i) {
3234
3234
  actions: b(o, [])
3235
3235
  });
3236
3236
  },
3237
- async update(n, e, t) {
3237
+ async update(i, e, t) {
3238
3238
  const r = {
3239
3239
  updated_at: (/* @__PURE__ */ new Date()).toISOString()
3240
3240
  };
3241
- return t.name !== void 0 && (r.name = t.name), t.actions !== void 0 && (r.actions = JSON.stringify(t.actions)), (await i.update(ie).set(r).where(g(a(ie.tenant_id, n), a(ie.id, e))).returning()).length === 0 ? null : this.get(n, e);
3241
+ return t.name !== void 0 && (r.name = t.name), t.actions !== void 0 && (r.actions = JSON.stringify(t.actions)), (await n.update(ie).set(r).where(g(a(ie.tenant_id, i), a(ie.id, e))).returning()).length === 0 ? null : this.get(i, e);
3242
3242
  },
3243
- async list(n, e) {
3243
+ async list(i, e) {
3244
3244
  const {
3245
3245
  page: t = 0,
3246
3246
  per_page: r = 50,
3247
3247
  include_totals: o = !1,
3248
3248
  sort: l
3249
3249
  } = e || {};
3250
- let _ = i.select().from(ie).where(a(ie.tenant_id, n)).$dynamic();
3250
+ let _ = n.select().from(ie).where(a(ie.tenant_id, i)).$dynamic();
3251
3251
  if (l != null && l.sort_by) {
3252
3252
  const h = ie[l.sort_by];
3253
3253
  h && (_ = _.orderBy(
@@ -3263,7 +3263,7 @@ function is(i) {
3263
3263
  });
3264
3264
  if (!o)
3265
3265
  return { flows: c };
3266
- const [u] = await i.select({ count: V() }).from(ie).where(a(ie.tenant_id, n));
3266
+ const [u] = await n.select({ count: V() }).from(ie).where(a(ie.tenant_id, i));
3267
3267
  return {
3268
3268
  flows: c,
3269
3269
  start: t * r,
@@ -3271,18 +3271,18 @@ function is(i) {
3271
3271
  length: Number((u == null ? void 0 : u.count) ?? 0)
3272
3272
  };
3273
3273
  },
3274
- async remove(n, e) {
3275
- return (await i.delete(ie).where(g(a(ie.tenant_id, n), a(ie.id, e))).returning()).length > 0;
3274
+ async remove(i, e) {
3275
+ return (await n.delete(ie).where(g(a(ie.tenant_id, i), a(ie.id, e))).returning()).length > 0;
3276
3276
  }
3277
3277
  };
3278
3278
  }
3279
3279
  const je = ["nodes", "start", "ending"];
3280
- function rs(i) {
3280
+ function rs(n) {
3281
3281
  return {
3282
- async create(n, e) {
3282
+ async create(i, e) {
3283
3283
  const t = (/* @__PURE__ */ new Date()).toISOString(), r = ae(), o = {
3284
3284
  id: r,
3285
- tenant_id: n,
3285
+ tenant_id: i,
3286
3286
  name: e.name,
3287
3287
  messages: e.messages,
3288
3288
  languages: e.languages,
@@ -3295,37 +3295,37 @@ function rs(i) {
3295
3295
  o[l] = JSON.stringify(
3296
3296
  e[l] || (l === "nodes" ? [] : {})
3297
3297
  );
3298
- return await i.insert(ne).values(o), {
3298
+ return await n.insert(ne).values(o), {
3299
3299
  id: r,
3300
3300
  ...e,
3301
3301
  created_at: t,
3302
3302
  updated_at: t
3303
3303
  };
3304
3304
  },
3305
- async get(n, e) {
3306
- const t = await i.select().from(ne).where(g(a(ne.tenant_id, n), a(ne.id, e))).get();
3305
+ async get(i, e) {
3306
+ const t = await n.select().from(ne).where(g(a(ne.tenant_id, i), a(ne.id, e))).get();
3307
3307
  if (!t) return null;
3308
3308
  const { tenant_id: r, ...o } = t, l = { ...o };
3309
3309
  for (const _ of je)
3310
3310
  l[_] = b(o[_]);
3311
3311
  return z(l);
3312
3312
  },
3313
- async update(n, e, t) {
3313
+ async update(i, e, t) {
3314
3314
  const r = {
3315
3315
  updated_at: (/* @__PURE__ */ new Date()).toISOString()
3316
3316
  };
3317
3317
  for (const [l, _] of Object.entries(t))
3318
3318
  _ !== void 0 && (je.includes(l) ? r[l] = JSON.stringify(_) : r[l] = _);
3319
- return (await i.update(ne).set(r).where(g(a(ne.tenant_id, n), a(ne.id, e))).returning()).length > 0;
3319
+ return (await n.update(ne).set(r).where(g(a(ne.tenant_id, i), a(ne.id, e))).returning()).length > 0;
3320
3320
  },
3321
- async list(n, e) {
3321
+ async list(i, e) {
3322
3322
  const {
3323
3323
  page: t = 0,
3324
3324
  per_page: r = 50,
3325
3325
  include_totals: o = !1,
3326
3326
  sort: l
3327
3327
  } = e || {};
3328
- let _ = i.select().from(ne).where(a(ne.tenant_id, n)).$dynamic();
3328
+ let _ = n.select().from(ne).where(a(ne.tenant_id, i)).$dynamic();
3329
3329
  if (l != null && l.sort_by) {
3330
3330
  const h = ne[l.sort_by];
3331
3331
  h && (_ = _.orderBy(
@@ -3340,7 +3340,7 @@ function rs(i) {
3340
3340
  });
3341
3341
  if (!o)
3342
3342
  return { forms: c };
3343
- const [u] = await i.select({ count: V() }).from(ne).where(a(ne.tenant_id, n));
3343
+ const [u] = await n.select({ count: V() }).from(ne).where(a(ne.tenant_id, i));
3344
3344
  return {
3345
3345
  forms: c,
3346
3346
  start: t * r,
@@ -3348,41 +3348,41 @@ function rs(i) {
3348
3348
  length: Number((u == null ? void 0 : u.count) ?? 0)
3349
3349
  };
3350
3350
  },
3351
- async remove(n, e) {
3352
- return (await i.delete(ne).where(g(a(ne.tenant_id, n), a(ne.id, e))).returning()).length > 0;
3351
+ async remove(i, e) {
3352
+ return (await n.delete(ne).where(g(a(ne.tenant_id, i), a(ne.id, e))).returning()).length > 0;
3353
3353
  }
3354
3354
  };
3355
3355
  }
3356
- function fr(i) {
3357
- if (i != null) {
3358
- if (typeof i == "number")
3359
- return new Date(i).toISOString();
3360
- if (typeof i == "string") {
3361
- if (i === "")
3356
+ function fr(n) {
3357
+ if (n != null) {
3358
+ if (typeof n == "number")
3359
+ return new Date(n).toISOString();
3360
+ if (typeof n == "string") {
3361
+ if (n === "")
3362
3362
  return;
3363
- const n = parseFloat(i);
3364
- return !isNaN(n) && /^\d+(\.\d+)?$/.test(i) ? new Date(n).toISOString() : i;
3363
+ const i = parseFloat(n);
3364
+ return !isNaN(i) && /^\d+(\.\d+)?$/.test(n) ? new Date(i).toISOString() : n;
3365
3365
  }
3366
3366
  }
3367
3367
  }
3368
- function wt(i, n = (/* @__PURE__ */ new Date(0)).toISOString()) {
3369
- return fr(i) ?? n;
3368
+ function wt(n, i = (/* @__PURE__ */ new Date(0)).toISOString()) {
3369
+ return fr(n) ?? i;
3370
3370
  }
3371
- function K(i) {
3372
- if (!i || i === "")
3371
+ function K(n) {
3372
+ if (!n || n === "")
3373
3373
  return null;
3374
- const n = new Date(i);
3375
- return isNaN(n.getTime()) ? null : n.getTime();
3374
+ const i = new Date(n);
3375
+ return isNaN(i.getTime()) ? null : i.getTime();
3376
3376
  }
3377
- function Fe(i, n, e = []) {
3377
+ function Fe(n, i, e = []) {
3378
3378
  const t = {};
3379
- for (const r of n) {
3379
+ for (const r of i) {
3380
3380
  const o = r.replace(/_ts$/, "");
3381
- t[o] = wt(i[r]);
3381
+ t[o] = wt(n[r]);
3382
3382
  }
3383
3383
  for (const r of e) {
3384
3384
  const o = r.replace(/_ts$/, "");
3385
- t[o] = fr(i[r]);
3385
+ t[o] = fr(n[r]);
3386
3386
  }
3387
3387
  return t;
3388
3388
  }
@@ -3393,8 +3393,8 @@ const ss = Hr(
3393
3393
  function os() {
3394
3394
  return `hc_${ss()}`;
3395
3395
  }
3396
- function Ct(i) {
3397
- const { created_at_ts: n, updated_at_ts: e, secrets: t, ...r } = i, o = Fe({ created_at_ts: n, updated_at_ts: e }, [
3396
+ function Ct(n) {
3397
+ const { created_at_ts: i, updated_at_ts: e, secrets: t, ...r } = n, o = Fe({ created_at_ts: i, updated_at_ts: e }, [
3398
3398
  "created_at_ts",
3399
3399
  "updated_at_ts"
3400
3400
  ]);
@@ -3404,40 +3404,40 @@ function Ct(i) {
3404
3404
  secrets: t ? JSON.parse(t) : void 0
3405
3405
  };
3406
3406
  }
3407
- function as(i) {
3407
+ function as(n) {
3408
3408
  return {
3409
- async create(n, e) {
3409
+ async create(i, e) {
3410
3410
  const t = Date.now(), o = {
3411
3411
  id: os(),
3412
- tenant_id: n,
3412
+ tenant_id: i,
3413
3413
  code: e.code,
3414
3414
  secrets: e.secrets ? JSON.stringify(e.secrets) : null,
3415
3415
  created_at_ts: t,
3416
3416
  updated_at_ts: t
3417
3417
  };
3418
- return await i.insert(me).values(o), Ct({ ...o, tenant_id: n });
3418
+ return await n.insert(me).values(o), Ct({ ...o, tenant_id: i });
3419
3419
  },
3420
- async get(n, e) {
3421
- const t = await i.select().from(me).where(g(a(me.tenant_id, n), a(me.id, e))).get();
3420
+ async get(i, e) {
3421
+ const t = await n.select().from(me).where(g(a(me.tenant_id, i), a(me.id, e))).get();
3422
3422
  return t ? Ct(t) : null;
3423
3423
  },
3424
- async update(n, e, t) {
3424
+ async update(i, e, t) {
3425
3425
  const r = {
3426
3426
  updated_at_ts: Date.now()
3427
3427
  };
3428
- return t.code !== void 0 && (r.code = t.code), t.secrets !== void 0 && (r.secrets = JSON.stringify(t.secrets)), (await i.update(me).set(r).where(g(a(me.tenant_id, n), a(me.id, e))).returning()).length > 0;
3428
+ return t.code !== void 0 && (r.code = t.code), t.secrets !== void 0 && (r.secrets = JSON.stringify(t.secrets)), (await n.update(me).set(r).where(g(a(me.tenant_id, i), a(me.id, e))).returning()).length > 0;
3429
3429
  },
3430
- async remove(n, e) {
3431
- return (await i.delete(me).where(g(a(me.tenant_id, n), a(me.id, e))).returning()).length > 0;
3430
+ async remove(i, e) {
3431
+ return (await n.delete(me).where(g(a(me.tenant_id, i), a(me.id, e))).returning()).length > 0;
3432
3432
  }
3433
3433
  };
3434
3434
  }
3435
3435
  function ls() {
3436
- const { customAlphabet: i } = require("nanoid");
3437
- return `h_${i("0123456789abcdefghijklmnopqrstuvwxyz", 17)()}`;
3436
+ const { customAlphabet: n } = require("nanoid");
3437
+ return `h_${n("0123456789abcdefghijklmnopqrstuvwxyz", 17)()}`;
3438
3438
  }
3439
- function st(i) {
3440
- const { tenant_id: n, created_at_ts: e, updated_at_ts: t, ...r } = i, o = Fe({ created_at_ts: e, updated_at_ts: t }, [
3439
+ function st(n) {
3440
+ const { tenant_id: i, created_at_ts: e, updated_at_ts: t, ...r } = n, o = Fe({ created_at_ts: e, updated_at_ts: t }, [
3441
3441
  "created_at_ts",
3442
3442
  "updated_at_ts"
3443
3443
  ]);
@@ -3448,12 +3448,12 @@ function st(i) {
3448
3448
  ...o
3449
3449
  });
3450
3450
  }
3451
- function _s(i) {
3451
+ function _s(n) {
3452
3452
  return {
3453
- async create(n, e) {
3453
+ async create(i, e) {
3454
3454
  const t = Date.now(), o = {
3455
3455
  hook_id: e.hook_id || ls(),
3456
- tenant_id: n,
3456
+ tenant_id: i,
3457
3457
  trigger_id: e.trigger_id,
3458
3458
  url: e.url,
3459
3459
  enabled: e.enabled ?? !0,
@@ -3465,19 +3465,19 @@ function _s(i) {
3465
3465
  created_at_ts: t,
3466
3466
  updated_at_ts: t
3467
3467
  };
3468
- return await i.insert(Z).values(o), st({ ...o, tenant_id: n });
3468
+ return await n.insert(Z).values(o), st({ ...o, tenant_id: i });
3469
3469
  },
3470
- async get(n, e) {
3471
- const t = await i.select().from(Z).where(g(a(Z.tenant_id, n), a(Z.hook_id, e))).get();
3470
+ async get(i, e) {
3471
+ const t = await n.select().from(Z).where(g(a(Z.tenant_id, i), a(Z.hook_id, e))).get();
3472
3472
  return t ? st(t) : null;
3473
3473
  },
3474
- async update(n, e, t) {
3474
+ async update(i, e, t) {
3475
3475
  const r = {
3476
3476
  updated_at_ts: Date.now()
3477
3477
  };
3478
- return t.trigger_id !== void 0 && (r.trigger_id = t.trigger_id), t.url !== void 0 && (r.url = t.url), t.enabled !== void 0 && (r.enabled = t.enabled), t.synchronous !== void 0 && (r.synchronous = t.synchronous), t.priority !== void 0 && (r.priority = t.priority), t.form_id !== void 0 && (r.form_id = t.form_id), t.template_id !== void 0 && (r.template_id = t.template_id), t.code_id !== void 0 && (r.code_id = t.code_id), (await i.update(Z).set(r).where(g(a(Z.tenant_id, n), a(Z.hook_id, e))).returning()).length > 0;
3478
+ return t.trigger_id !== void 0 && (r.trigger_id = t.trigger_id), t.url !== void 0 && (r.url = t.url), t.enabled !== void 0 && (r.enabled = t.enabled), t.synchronous !== void 0 && (r.synchronous = t.synchronous), t.priority !== void 0 && (r.priority = t.priority), t.form_id !== void 0 && (r.form_id = t.form_id), t.template_id !== void 0 && (r.template_id = t.template_id), t.code_id !== void 0 && (r.code_id = t.code_id), (await n.update(Z).set(r).where(g(a(Z.tenant_id, i), a(Z.hook_id, e))).returning()).length > 0;
3479
3479
  },
3480
- async list(n, e) {
3480
+ async list(i, e) {
3481
3481
  const {
3482
3482
  page: t = 0,
3483
3483
  per_page: r = 50,
@@ -3489,8 +3489,8 @@ function _s(i) {
3489
3489
  "form_id",
3490
3490
  "template_id",
3491
3491
  "code_id"
3492
- ]) : void 0, c = d ? g(a(Z.tenant_id, n), d) : a(Z.tenant_id, n);
3493
- let u = i.select().from(Z).where(c).$dynamic();
3492
+ ]) : void 0, c = d ? g(a(Z.tenant_id, i), d) : a(Z.tenant_id, i);
3493
+ let u = n.select().from(Z).where(c).$dynamic();
3494
3494
  if (l != null && l.sort_by) {
3495
3495
  const w = Z[l.sort_by];
3496
3496
  w && (u = u.orderBy(
@@ -3500,7 +3500,7 @@ function _s(i) {
3500
3500
  const f = (await u.offset(t * r).limit(r)).map(st);
3501
3501
  if (!o)
3502
3502
  return { hooks: f };
3503
- const [y] = await i.select({ count: V() }).from(Z).where(c);
3503
+ const [y] = await n.select({ count: V() }).from(Z).where(c);
3504
3504
  return {
3505
3505
  hooks: f,
3506
3506
  start: t * r,
@@ -3508,14 +3508,14 @@ function _s(i) {
3508
3508
  length: Number((y == null ? void 0 : y.count) ?? 0)
3509
3509
  };
3510
3510
  },
3511
- async remove(n, e) {
3512
- return (await i.delete(Z).where(g(a(Z.tenant_id, n), a(Z.hook_id, e))).returning()).length > 0;
3511
+ async remove(i, e) {
3512
+ return (await n.delete(Z).where(g(a(Z.tenant_id, i), a(Z.hook_id, e))).returning()).length > 0;
3513
3513
  }
3514
3514
  };
3515
3515
  }
3516
3516
  function us() {
3517
- const { customAlphabet: i } = require("nanoid");
3518
- return `inv_${i("0123456789abcdefghijklmnopqrstuvwxyz", 17)()}`;
3517
+ const { customAlphabet: n } = require("nanoid");
3518
+ return `inv_${n("0123456789abcdefghijklmnopqrstuvwxyz", 17)()}`;
3519
3519
  }
3520
3520
  const Nt = [
3521
3521
  "inviter",
@@ -3524,19 +3524,19 @@ const Nt = [
3524
3524
  "user_metadata",
3525
3525
  "roles"
3526
3526
  ];
3527
- function ot(i) {
3528
- const { tenant_id: n, send_invitation_email: e, ...t } = i, r = { ...t };
3527
+ function ot(n) {
3528
+ const { tenant_id: i, send_invitation_email: e, ...t } = n, r = { ...t };
3529
3529
  for (const o of Nt)
3530
3530
  r[o] = b(t[o], o === "roles" ? [] : {});
3531
3531
  return r.send_invitation_email = !!e, z(r);
3532
3532
  }
3533
- function ds(i) {
3533
+ function ds(n) {
3534
3534
  return {
3535
- async create(n, e) {
3535
+ async create(i, e) {
3536
3536
  var d, c;
3537
3537
  const t = e.id || us(), r = e.ttl_sec || 604800, o = /* @__PURE__ */ new Date(), l = new Date(o.getTime() + r * 1e3).toISOString(), _ = {
3538
3538
  id: t,
3539
- tenant_id: n,
3539
+ tenant_id: i,
3540
3540
  organization_id: e.organization_id,
3541
3541
  client_id: e.client_id,
3542
3542
  connection_id: e.connection_id,
@@ -3550,32 +3550,32 @@ function ds(i) {
3550
3550
  for (const u of Nt)
3551
3551
  e[u] !== void 0 && (_[u] = JSON.stringify(e[u]));
3552
3552
  try {
3553
- await i.insert(te).values(_);
3553
+ await n.insert(te).values(_);
3554
3554
  } catch (u) {
3555
3555
  throw (d = u == null ? void 0 : u.message) != null && d.includes("UNIQUE constraint failed") || (c = u == null ? void 0 : u.message) != null && c.includes("duplicate key") ? new be(409, { message: "Invite already exists" }) : u;
3556
3556
  }
3557
- return ot({ ..._, tenant_id: n });
3557
+ return ot({ ..._, tenant_id: i });
3558
3558
  },
3559
- async get(n, e) {
3560
- const t = await i.select().from(te).where(g(a(te.tenant_id, n), a(te.id, e))).get();
3559
+ async get(i, e) {
3560
+ const t = await n.select().from(te).where(g(a(te.tenant_id, i), a(te.id, e))).get();
3561
3561
  return t ? ot(t) : null;
3562
3562
  },
3563
- async update(n, e, t) {
3563
+ async update(i, e, t) {
3564
3564
  const r = {};
3565
3565
  for (const l of Nt)
3566
3566
  t[l] !== void 0 && (r[l] = JSON.stringify(t[l]));
3567
3567
  return t.connection_id !== void 0 && (r.connection_id = t.connection_id), t.ttl_sec !== void 0 && (r.ttl_sec = t.ttl_sec, r.expires_at = new Date(
3568
3568
  Date.now() + t.ttl_sec * 1e3
3569
- ).toISOString()), (await i.update(te).set(r).where(g(a(te.tenant_id, n), a(te.id, e))).returning()).length > 0;
3569
+ ).toISOString()), (await n.update(te).set(r).where(g(a(te.tenant_id, i), a(te.id, e))).returning()).length > 0;
3570
3570
  },
3571
- async list(n, e) {
3571
+ async list(i, e) {
3572
3572
  const {
3573
3573
  page: t = 0,
3574
3574
  per_page: r = 50,
3575
3575
  include_totals: o = !1,
3576
3576
  sort: l
3577
3577
  } = e || {};
3578
- let _ = i.select().from(te).where(a(te.tenant_id, n)).$dynamic();
3578
+ let _ = n.select().from(te).where(a(te.tenant_id, i)).$dynamic();
3579
3579
  if (l != null && l.sort_by) {
3580
3580
  const h = te[l.sort_by];
3581
3581
  h && (_ = _.orderBy(
@@ -3585,7 +3585,7 @@ function ds(i) {
3585
3585
  const c = (await _.offset(t * r).limit(r)).map(ot);
3586
3586
  if (!o)
3587
3587
  return { invites: c };
3588
- const [u] = await i.select({ count: V() }).from(te).where(a(te.tenant_id, n));
3588
+ const [u] = await n.select({ count: V() }).from(te).where(a(te.tenant_id, i));
3589
3589
  return {
3590
3590
  invites: c,
3591
3591
  start: t * r,
@@ -3593,27 +3593,27 @@ function ds(i) {
3593
3593
  length: Number((u == null ? void 0 : u.count) ?? 0)
3594
3594
  };
3595
3595
  },
3596
- async remove(n, e) {
3597
- return (await i.delete(te).where(g(a(te.tenant_id, n), a(te.id, e))).returning()).length > 0;
3596
+ async remove(i, e) {
3597
+ return (await n.delete(te).where(g(a(te.tenant_id, i), a(te.id, e))).returning()).length > 0;
3598
3598
  }
3599
3599
  };
3600
3600
  }
3601
- function cs(i) {
3601
+ function cs(n) {
3602
3602
  return {
3603
- async create(n) {
3604
- await i.insert(he).values({
3605
- ...n,
3603
+ async create(i) {
3604
+ await n.insert(he).values({
3605
+ ...i,
3606
3606
  created_at: (/* @__PURE__ */ new Date()).toDateString()
3607
3607
  });
3608
3608
  },
3609
- async list(n) {
3609
+ async list(i) {
3610
3610
  const {
3611
3611
  page: e = 0,
3612
3612
  per_page: t = 50,
3613
3613
  include_totals: r = !1,
3614
3614
  sort: o
3615
- } = n || {}, l = (/* @__PURE__ */ new Date()).toISOString();
3616
- let _ = i.select().from(he).where(de(He(he.revoked_at, l), ye(he.revoked_at))).$dynamic();
3615
+ } = i || {}, l = (/* @__PURE__ */ new Date()).toISOString();
3616
+ let _ = n.select().from(he).where(de(He(he.revoked_at, l), ye(he.revoked_at))).$dynamic();
3617
3617
  if (o != null && o.sort_by) {
3618
3618
  const h = he[o.sort_by];
3619
3619
  h && (_ = _.orderBy(
@@ -3626,7 +3626,7 @@ function cs(i) {
3626
3626
  });
3627
3627
  if (!r)
3628
3628
  return { signingKeys: c };
3629
- const [u] = await i.select({ count: V() }).from(he).where(de(He(he.revoked_at, l), ye(he.revoked_at)));
3629
+ const [u] = await n.select({ count: V() }).from(he).where(de(He(he.revoked_at, l), ye(he.revoked_at)));
3630
3630
  return {
3631
3631
  signingKeys: c,
3632
3632
  start: e * t,
@@ -3634,8 +3634,8 @@ function cs(i) {
3634
3634
  length: Fr((u == null ? void 0 : u.count) ?? 0)
3635
3635
  };
3636
3636
  },
3637
- async update(n, e) {
3638
- return (await i.update(he).set(e).where(a(he.kid, n)).returning()).length > 0;
3637
+ async update(i, e) {
3638
+ return (await n.update(he).set(e).where(a(he.kid, i)).returning()).length > 0;
3639
3639
  }
3640
3640
  };
3641
3641
  }
@@ -3650,15 +3650,15 @@ function gs() {
3650
3650
  t += vt.charAt(r[o] % at);
3651
3651
  return t;
3652
3652
  }
3653
- function $t(i) {
3653
+ function $t(n) {
3654
3654
  const {
3655
- tenant_id: n,
3655
+ tenant_id: i,
3656
3656
  created_at_ts: e,
3657
3657
  updated_at_ts: t,
3658
3658
  expires_at_ts: r,
3659
3659
  state_data: o,
3660
3660
  ...l
3661
- } = i, _ = Fe(
3661
+ } = n, _ = Fe(
3662
3662
  { created_at_ts: e, updated_at_ts: t, expires_at_ts: r },
3663
3663
  ["created_at_ts", "updated_at_ts", "expires_at_ts"]
3664
3664
  ), d = gr(l, ["authParams"]);
@@ -3668,15 +3668,15 @@ function $t(i) {
3668
3668
  state_data: b(o)
3669
3669
  });
3670
3670
  }
3671
- function fs(i) {
3671
+ function fs(n) {
3672
3672
  return {
3673
- async create(n, e) {
3673
+ async create(i, e) {
3674
3674
  const t = Date.now(), r = gs(), o = Pe(
3675
3675
  { authParams: e.authParams || {} },
3676
3676
  "authParams"
3677
3677
  ), l = {
3678
3678
  id: r,
3679
- tenant_id: n,
3679
+ tenant_id: i,
3680
3680
  session_id: e.session_id,
3681
3681
  csrf_token: e.csrf_token,
3682
3682
  authorization_url: e.authorization_url ? e.authorization_url.substring(0, 1024) : void 0,
@@ -3694,15 +3694,15 @@ function fs(i) {
3694
3694
  };
3695
3695
  for (const [_, d] of Object.entries(o))
3696
3696
  l[_] = d;
3697
- return await i.insert(oe).values(l), $t({ ...l, tenant_id: n });
3697
+ return await n.insert(oe).values(l), $t({ ...l, tenant_id: i });
3698
3698
  },
3699
- async get(n, e) {
3700
- const t = await i.select().from(oe).where(
3701
- g(a(oe.tenant_id, n), a(oe.id, e))
3699
+ async get(i, e) {
3700
+ const t = await n.select().from(oe).where(
3701
+ g(a(oe.tenant_id, i), a(oe.id, e))
3702
3702
  ).get();
3703
3703
  return t ? $t(t) : null;
3704
3704
  },
3705
- async update(n, e, t) {
3705
+ async update(i, e, t) {
3706
3706
  var o;
3707
3707
  const r = {
3708
3708
  updated_at_ts: Date.now()
@@ -3717,20 +3717,20 @@ function fs(i) {
3717
3717
  );
3718
3718
  Object.assign(r, l);
3719
3719
  }
3720
- return await i.update(oe).set(r).where(
3721
- g(a(oe.tenant_id, n), a(oe.id, e))
3720
+ return await n.update(oe).set(r).where(
3721
+ g(a(oe.tenant_id, i), a(oe.id, e))
3722
3722
  ), !0;
3723
3723
  },
3724
- async remove(n, e) {
3725
- return (await i.delete(oe).where(
3726
- g(a(oe.tenant_id, n), a(oe.id, e))
3724
+ async remove(i, e) {
3725
+ return (await n.delete(oe).where(
3726
+ g(a(oe.tenant_id, i), a(oe.id, e))
3727
3727
  ).returning()).length > 0;
3728
3728
  }
3729
3729
  };
3730
3730
  }
3731
- function lt(i) {
3731
+ function lt(n) {
3732
3732
  const {
3733
- tenant_id: n,
3733
+ tenant_id: i,
3734
3734
  isMobile: e,
3735
3735
  auth0_client: t,
3736
3736
  details: r,
@@ -3742,7 +3742,7 @@ function lt(i) {
3742
3742
  continent_code: u,
3743
3743
  scope: h,
3744
3744
  ...f
3745
- } = i, y = {
3745
+ } = n, y = {
3746
3746
  ...f,
3747
3747
  isMobile: !!e,
3748
3748
  auth0_client: b(t),
@@ -3758,13 +3758,13 @@ function lt(i) {
3758
3758
  continent_code: u
3759
3759
  })), z(y);
3760
3760
  }
3761
- function ms(i) {
3761
+ function ms(n) {
3762
3762
  return {
3763
- async create(n, e) {
3763
+ async create(i, e) {
3764
3764
  var o, l;
3765
3765
  const r = {
3766
3766
  log_id: e.log_id || ae(),
3767
- tenant_id: n,
3767
+ tenant_id: i,
3768
3768
  type: e.type,
3769
3769
  date: e.date || (/* @__PURE__ */ new Date()).toISOString(),
3770
3770
  category: e.category,
@@ -3785,9 +3785,9 @@ function ms(i) {
3785
3785
  hostname: e.hostname,
3786
3786
  session_connection: e.session_connection
3787
3787
  };
3788
- return e.auth0_client && (r.auth0_client = JSON.stringify(e.auth0_client)), e.details && (r.details = JSON.stringify(e.details).substring(0, 8192)), e.location_info && (r.country_code = e.location_info.country_code, r.city_name = e.location_info.city_name, r.latitude = e.location_info.latitude, r.longitude = e.location_info.longitude, r.time_zone = e.location_info.time_zone, r.continent_code = e.location_info.continent_code), await i.insert(T).values(r), lt({ ...r, tenant_id: n });
3788
+ return e.auth0_client && (r.auth0_client = JSON.stringify(e.auth0_client)), e.details && (r.details = JSON.stringify(e.details).substring(0, 8192)), e.location_info && (r.country_code = e.location_info.country_code, r.city_name = e.location_info.city_name, r.latitude = e.location_info.latitude, r.longitude = e.location_info.longitude, r.time_zone = e.location_info.time_zone, r.continent_code = e.location_info.continent_code), await n.insert(T).values(r), lt({ ...r, tenant_id: i });
3789
3789
  },
3790
- async list(n, e) {
3790
+ async list(i, e) {
3791
3791
  const {
3792
3792
  page: t = 0,
3793
3793
  per_page: r = 50,
@@ -3795,7 +3795,7 @@ function ms(i) {
3795
3795
  sort: l,
3796
3796
  q: _
3797
3797
  } = e || {};
3798
- let d = i.select().from(T).where(a(T.tenant_id, n)).$dynamic();
3798
+ let d = n.select().from(T).where(a(T.tenant_id, i)).$dynamic();
3799
3799
  if (_) {
3800
3800
  const f = pe(T, _, [
3801
3801
  "user_id",
@@ -3803,7 +3803,7 @@ function ms(i) {
3803
3803
  "type",
3804
3804
  "client_id"
3805
3805
  ]);
3806
- f && (d = d.where(g(a(T.tenant_id, n), f)));
3806
+ f && (d = d.where(g(a(T.tenant_id, i), f)));
3807
3807
  }
3808
3808
  if (l != null && l.sort_by) {
3809
3809
  const f = T[l.sort_by];
@@ -3815,7 +3815,7 @@ function ms(i) {
3815
3815
  const u = (await d.offset(t * r).limit(r)).map(lt);
3816
3816
  if (!o)
3817
3817
  return { logs: u };
3818
- const [h] = await i.select({ count: V() }).from(T).where(a(T.tenant_id, n));
3818
+ const [h] = await n.select({ count: V() }).from(T).where(a(T.tenant_id, i));
3819
3819
  return {
3820
3820
  logs: u,
3821
3821
  start: t * r,
@@ -3823,8 +3823,8 @@ function ms(i) {
3823
3823
  length: Number((h == null ? void 0 : h.count) ?? 0)
3824
3824
  };
3825
3825
  },
3826
- async get(n, e) {
3827
- const t = await i.select().from(T).where(g(a(T.tenant_id, n), a(T.log_id, e))).get();
3826
+ async get(i, e) {
3827
+ const t = await n.select().from(T).where(g(a(T.tenant_id, i), a(T.log_id, e))).get();
3828
3828
  return t ? lt(t) : null;
3829
3829
  }
3830
3830
  };
@@ -3840,16 +3840,16 @@ function hs() {
3840
3840
  t += St.charAt(r[o] % _t);
3841
3841
  return t;
3842
3842
  }
3843
- function Me(i) {
3843
+ function Me(n) {
3844
3844
  const {
3845
- tenant_id: n,
3845
+ tenant_id: i,
3846
3846
  created_at_ts: e,
3847
3847
  updated_at_ts: t,
3848
3848
  credential_backed_up: r,
3849
3849
  confirmed: o,
3850
3850
  transports: l,
3851
3851
  ..._
3852
- } = i;
3852
+ } = n;
3853
3853
  return z({
3854
3854
  ..._,
3855
3855
  confirmed: !!o,
@@ -3859,12 +3859,12 @@ function Me(i) {
3859
3859
  updated_at: wt(t)
3860
3860
  });
3861
3861
  }
3862
- function ps(i) {
3862
+ function ps(n) {
3863
3863
  return {
3864
- async create(n, e) {
3864
+ async create(i, e) {
3865
3865
  const t = Date.now(), o = {
3866
3866
  id: e.id || hs(),
3867
- tenant_id: n,
3867
+ tenant_id: i,
3868
3868
  user_id: e.user_id,
3869
3869
  type: e.type,
3870
3870
  phone_number: e.phone_number,
@@ -3879,55 +3879,55 @@ function ps(i) {
3879
3879
  created_at_ts: t,
3880
3880
  updated_at_ts: t
3881
3881
  };
3882
- return await i.insert(F).values(o), Me({ ...o, tenant_id: n });
3882
+ return await n.insert(F).values(o), Me({ ...o, tenant_id: i });
3883
3883
  },
3884
- async get(n, e) {
3885
- const t = await i.select().from(F).where(
3884
+ async get(i, e) {
3885
+ const t = await n.select().from(F).where(
3886
3886
  g(
3887
- a(F.tenant_id, n),
3887
+ a(F.tenant_id, i),
3888
3888
  a(F.id, e)
3889
3889
  )
3890
3890
  ).get();
3891
3891
  return t ? Me(t) : null;
3892
3892
  },
3893
- async getByCredentialId(n, e) {
3894
- const t = await i.select().from(F).where(
3893
+ async getByCredentialId(i, e) {
3894
+ const t = await n.select().from(F).where(
3895
3895
  g(
3896
- a(F.tenant_id, n),
3896
+ a(F.tenant_id, i),
3897
3897
  a(F.credential_id, e)
3898
3898
  )
3899
3899
  ).get();
3900
3900
  return t ? Me(t) : null;
3901
3901
  },
3902
- async list(n, e) {
3903
- return (await i.select().from(F).where(
3902
+ async list(i, e) {
3903
+ return (await n.select().from(F).where(
3904
3904
  g(
3905
- a(F.tenant_id, n),
3905
+ a(F.tenant_id, i),
3906
3906
  a(F.user_id, e)
3907
3907
  )
3908
3908
  ).all()).map(Me);
3909
3909
  },
3910
- async update(n, e, t) {
3910
+ async update(i, e, t) {
3911
3911
  const r = {
3912
3912
  updated_at_ts: Date.now()
3913
3913
  };
3914
- t.type !== void 0 && (r.type = t.type), t.phone_number !== void 0 && (r.phone_number = t.phone_number), t.totp_secret !== void 0 && (r.totp_secret = t.totp_secret), t.credential_id !== void 0 && (r.credential_id = t.credential_id), t.public_key !== void 0 && (r.public_key = t.public_key), t.sign_count !== void 0 && (r.sign_count = t.sign_count), t.credential_backed_up !== void 0 && (r.credential_backed_up = t.credential_backed_up ? 1 : 0), t.transports !== void 0 && (r.transports = JSON.stringify(t.transports)), t.friendly_name !== void 0 && (r.friendly_name = t.friendly_name), t.confirmed !== void 0 && (r.confirmed = t.confirmed ? 1 : 0), await i.update(F).set(r).where(
3914
+ t.type !== void 0 && (r.type = t.type), t.phone_number !== void 0 && (r.phone_number = t.phone_number), t.totp_secret !== void 0 && (r.totp_secret = t.totp_secret), t.credential_id !== void 0 && (r.credential_id = t.credential_id), t.public_key !== void 0 && (r.public_key = t.public_key), t.sign_count !== void 0 && (r.sign_count = t.sign_count), t.credential_backed_up !== void 0 && (r.credential_backed_up = t.credential_backed_up ? 1 : 0), t.transports !== void 0 && (r.transports = JSON.stringify(t.transports)), t.friendly_name !== void 0 && (r.friendly_name = t.friendly_name), t.confirmed !== void 0 && (r.confirmed = t.confirmed ? 1 : 0), await n.update(F).set(r).where(
3915
3915
  g(
3916
- a(F.tenant_id, n),
3916
+ a(F.tenant_id, i),
3917
3917
  a(F.id, e)
3918
3918
  )
3919
3919
  );
3920
- const o = await this.get(n, e);
3920
+ const o = await this.get(i, e);
3921
3921
  if (!o)
3922
3922
  throw new Error(
3923
3923
  `Authentication method ${e} not found after update`
3924
3924
  );
3925
3925
  return o;
3926
3926
  },
3927
- async remove(n, e) {
3928
- return (await i.delete(F).where(
3927
+ async remove(i, e) {
3928
+ return (await n.delete(F).where(
3929
3929
  g(
3930
- a(F.tenant_id, n),
3930
+ a(F.tenant_id, i),
3931
3931
  a(F.id, e)
3932
3932
  )
3933
3933
  ).returning()).length > 0;
@@ -3935,18 +3935,18 @@ function ps(i) {
3935
3935
  };
3936
3936
  }
3937
3937
  function ys() {
3938
- const { customAlphabet: i } = require("nanoid");
3939
- return `org_${i("0123456789abcdefghijklmnopqrstuvwxyz", 17)()}`;
3938
+ const { customAlphabet: n } = require("nanoid");
3939
+ return `org_${n("0123456789abcdefghijklmnopqrstuvwxyz", 17)()}`;
3940
3940
  }
3941
- function ut(i) {
3941
+ function ut(n) {
3942
3942
  const {
3943
- tenant_id: n,
3943
+ tenant_id: i,
3944
3944
  branding: e,
3945
3945
  metadata: t,
3946
3946
  enabled_connections: r,
3947
3947
  token_quota: o,
3948
3948
  ...l
3949
- } = i;
3949
+ } = n;
3950
3950
  return z({
3951
3951
  ...l,
3952
3952
  branding: b(e, {}),
@@ -3955,13 +3955,13 @@ function ut(i) {
3955
3955
  token_quota: b(o, {})
3956
3956
  });
3957
3957
  }
3958
- function ws(i) {
3958
+ function ws(n) {
3959
3959
  return {
3960
- async create(n, e) {
3960
+ async create(i, e) {
3961
3961
  var l, _;
3962
3962
  const t = (/* @__PURE__ */ new Date()).toISOString(), o = {
3963
3963
  id: e.id || ys(),
3964
- tenant_id: n,
3964
+ tenant_id: i,
3965
3965
  name: e.name,
3966
3966
  display_name: e.display_name,
3967
3967
  branding: JSON.stringify(e.branding || {}),
@@ -3972,36 +3972,36 @@ function ws(i) {
3972
3972
  updated_at: t
3973
3973
  };
3974
3974
  try {
3975
- await i.insert(q).values(o);
3975
+ await n.insert(q).values(o);
3976
3976
  } catch (d) {
3977
3977
  throw (l = d == null ? void 0 : d.message) != null && l.includes("UNIQUE constraint failed") || (_ = d == null ? void 0 : d.message) != null && _.includes("AlreadyExists") ? new be(409, {
3978
3978
  message: "Organization already exists"
3979
3979
  }) : d;
3980
3980
  }
3981
- return ut({ ...o, tenant_id: n });
3981
+ return ut({ ...o, tenant_id: i });
3982
3982
  },
3983
- async get(n, e) {
3984
- let t = await i.select().from(q).where(
3985
- g(a(q.tenant_id, n), a(q.id, e))
3983
+ async get(i, e) {
3984
+ let t = await n.select().from(q).where(
3985
+ g(a(q.tenant_id, i), a(q.id, e))
3986
3986
  ).get();
3987
- return t || (t = await i.select().from(q).where(
3987
+ return t || (t = await n.select().from(q).where(
3988
3988
  g(
3989
- a(q.tenant_id, n),
3989
+ a(q.tenant_id, i),
3990
3990
  a(q.name, e)
3991
3991
  )
3992
3992
  ).get()), t ? ut(t) : null;
3993
3993
  },
3994
- async update(n, e, t) {
3994
+ async update(i, e, t) {
3995
3995
  const r = {
3996
3996
  updated_at: (/* @__PURE__ */ new Date()).toISOString()
3997
3997
  };
3998
3998
  return t.name !== void 0 && (r.name = t.name), t.display_name !== void 0 && (r.display_name = t.display_name), t.branding !== void 0 && (r.branding = JSON.stringify(t.branding)), t.metadata !== void 0 && (r.metadata = JSON.stringify(t.metadata)), t.enabled_connections !== void 0 && (r.enabled_connections = JSON.stringify(
3999
3999
  t.enabled_connections
4000
- )), t.token_quota !== void 0 && (r.token_quota = JSON.stringify(t.token_quota)), (await i.update(q).set(r).where(
4001
- g(a(q.tenant_id, n), a(q.id, e))
4000
+ )), t.token_quota !== void 0 && (r.token_quota = JSON.stringify(t.token_quota)), (await n.update(q).set(r).where(
4001
+ g(a(q.tenant_id, i), a(q.id, e))
4002
4002
  ).returning()).length > 0;
4003
4003
  },
4004
- async list(n, e) {
4004
+ async list(i, e) {
4005
4005
  const {
4006
4006
  page: t = 0,
4007
4007
  per_page: r = 50,
@@ -4009,7 +4009,7 @@ function ws(i) {
4009
4009
  sort: l,
4010
4010
  q: _
4011
4011
  } = e || {};
4012
- let d = i.select().from(q).where(a(q.tenant_id, n)).$dynamic();
4012
+ let d = n.select().from(q).where(a(q.tenant_id, i)).$dynamic();
4013
4013
  if (_ && (d = d.where(
4014
4014
  de(
4015
4015
  Ie(q.name, `%${_}%`),
@@ -4024,14 +4024,14 @@ function ws(i) {
4024
4024
  const u = (await d.offset(t * r).limit(r)).map(ut);
4025
4025
  if (!o)
4026
4026
  return { organizations: u };
4027
- const h = [a(q.tenant_id, n)];
4027
+ const h = [a(q.tenant_id, i)];
4028
4028
  _ && h.push(
4029
4029
  de(
4030
4030
  Ie(q.name, `%${_}%`),
4031
4031
  Ie(q.display_name, `%${_}%`)
4032
4032
  )
4033
4033
  );
4034
- const [f] = await i.select({ count: V() }).from(q).where(g(...h));
4034
+ const [f] = await n.select({ count: V() }).from(q).where(g(...h));
4035
4035
  return {
4036
4036
  organizations: u,
4037
4037
  start: t * r,
@@ -4039,33 +4039,33 @@ function ws(i) {
4039
4039
  length: Number((f == null ? void 0 : f.count) ?? 0)
4040
4040
  };
4041
4041
  },
4042
- async remove(n, e) {
4043
- return (await i.delete(q).where(
4044
- g(a(q.tenant_id, n), a(q.id, e))
4042
+ async remove(i, e) {
4043
+ return (await n.delete(q).where(
4044
+ g(a(q.tenant_id, i), a(q.id, e))
4045
4045
  ).returning()).length > 0;
4046
4046
  }
4047
4047
  };
4048
4048
  }
4049
- function dt(i) {
4050
- const { tenant_id: n, is_current: e, ...t } = i;
4049
+ function dt(n) {
4050
+ const { tenant_id: i, is_current: e, ...t } = n;
4051
4051
  return {
4052
4052
  ...t,
4053
4053
  is_current: !!e
4054
4054
  };
4055
4055
  }
4056
- function Ns(i) {
4056
+ function Ns(n) {
4057
4057
  return {
4058
- async create(n, e) {
4058
+ async create(i, e) {
4059
4059
  const t = (/* @__PURE__ */ new Date()).toISOString(), r = e.id || ae();
4060
- e.is_current !== !1 && await i.update(E).set({ is_current: 0 }).where(
4060
+ e.is_current !== !1 && await n.update(E).set({ is_current: 0 }).where(
4061
4061
  g(
4062
- a(E.tenant_id, n),
4062
+ a(E.tenant_id, i),
4063
4063
  a(E.user_id, e.user_id)
4064
4064
  )
4065
4065
  );
4066
4066
  const o = {
4067
4067
  id: r,
4068
- tenant_id: n,
4068
+ tenant_id: i,
4069
4069
  user_id: e.user_id,
4070
4070
  password: e.password,
4071
4071
  algorithm: e.algorithm || "bcrypt",
@@ -4073,39 +4073,39 @@ function Ns(i) {
4073
4073
  created_at: t,
4074
4074
  updated_at: t
4075
4075
  };
4076
- return await i.insert(E).values(o), dt({ ...o, tenant_id: n });
4076
+ return await n.insert(E).values(o), dt({ ...o, tenant_id: i });
4077
4077
  },
4078
- async get(n, e) {
4079
- const t = await i.select().from(E).where(
4078
+ async get(i, e) {
4079
+ const t = await n.select().from(E).where(
4080
4080
  g(
4081
- a(E.tenant_id, n),
4081
+ a(E.tenant_id, i),
4082
4082
  a(E.user_id, e),
4083
4083
  a(E.is_current, 1)
4084
4084
  )
4085
4085
  ).get();
4086
4086
  return t ? dt(t) : null;
4087
4087
  },
4088
- async list(n, e, t) {
4089
- let r = i.select().from(E).where(
4088
+ async list(i, e, t) {
4089
+ let r = n.select().from(E).where(
4090
4090
  g(
4091
- a(E.tenant_id, n),
4091
+ a(E.tenant_id, i),
4092
4092
  a(E.user_id, e)
4093
4093
  )
4094
4094
  ).orderBy(M(E.created_at)).$dynamic();
4095
4095
  return t && (r = r.limit(t)), (await r).map(dt);
4096
4096
  },
4097
- async update(n, e) {
4097
+ async update(i, e) {
4098
4098
  const t = {
4099
4099
  updated_at: (/* @__PURE__ */ new Date()).toISOString()
4100
4100
  };
4101
- return e.password !== void 0 && (t.password = e.password), e.algorithm !== void 0 && (t.algorithm = e.algorithm), e.is_current !== void 0 && (t.is_current = e.is_current ? 1 : 0), e.id ? await i.update(E).set(t).where(
4101
+ return e.password !== void 0 && (t.password = e.password), e.algorithm !== void 0 && (t.algorithm = e.algorithm), e.is_current !== void 0 && (t.is_current = e.is_current ? 1 : 0), e.id ? await n.update(E).set(t).where(
4102
4102
  g(
4103
- a(E.tenant_id, n),
4103
+ a(E.tenant_id, i),
4104
4104
  a(E.id, e.id)
4105
4105
  )
4106
- ) : await i.update(E).set(t).where(
4106
+ ) : await n.update(E).set(t).where(
4107
4107
  g(
4108
- a(E.tenant_id, n),
4108
+ a(E.tenant_id, i),
4109
4109
  a(E.user_id, e.user_id),
4110
4110
  a(E.is_current, 1)
4111
4111
  )
@@ -4113,10 +4113,10 @@ function Ns(i) {
4113
4113
  }
4114
4114
  };
4115
4115
  }
4116
- function vs(i) {
4116
+ function vs(n) {
4117
4117
  return {
4118
- async get(n) {
4119
- const e = await i.select().from(Ee).where(a(Ee.tenant_id, n)).get();
4118
+ async get(i) {
4119
+ const e = await n.select().from(Ee).where(a(Ee.tenant_id, i)).get();
4120
4120
  return e ? {
4121
4121
  universal_login_experience: e.universal_login_experience,
4122
4122
  identifier_first: !!e.identifier_first,
@@ -4129,9 +4129,9 @@ function vs(i) {
4129
4129
  webauthn_platform_first_factor: !1
4130
4130
  };
4131
4131
  },
4132
- async set(n, e) {
4133
- await i.insert(Ee).values({
4134
- tenant_id: n,
4132
+ async set(i, e) {
4133
+ await n.insert(Ee).values({
4134
+ tenant_id: i,
4135
4135
  universal_login_experience: e.universal_login_experience,
4136
4136
  identifier_first: e.identifier_first,
4137
4137
  password_first: e.password_first,
@@ -4148,9 +4148,9 @@ function vs(i) {
4148
4148
  }
4149
4149
  };
4150
4150
  }
4151
- function ct(i) {
4151
+ function ct(n) {
4152
4152
  const {
4153
- tenant_id: n,
4153
+ tenant_id: i,
4154
4154
  created_at_ts: e,
4155
4155
  expires_at_ts: t,
4156
4156
  idle_expires_at_ts: r,
@@ -4159,7 +4159,7 @@ function ct(i) {
4159
4159
  resource_servers: _,
4160
4160
  rotating: d,
4161
4161
  ...c
4162
- } = i, u = Fe(
4162
+ } = n, u = Fe(
4163
4163
  { created_at_ts: e, expires_at_ts: t, idle_expires_at_ts: r, last_exchanged_at_ts: o },
4164
4164
  ["created_at_ts"],
4165
4165
  ["expires_at_ts", "idle_expires_at_ts", "last_exchanged_at_ts"]
@@ -4172,12 +4172,12 @@ function ct(i) {
4172
4172
  resource_servers: b(_, [])
4173
4173
  });
4174
4174
  }
4175
- function Ss(i) {
4175
+ function Ss(n) {
4176
4176
  return {
4177
- async create(n, e) {
4177
+ async create(i, e) {
4178
4178
  const t = Date.now(), r = {
4179
4179
  id: e.id || ae(),
4180
- tenant_id: n,
4180
+ tenant_id: i,
4181
4181
  client_id: e.client_id,
4182
4182
  login_id: e.login_id,
4183
4183
  user_id: e.user_id,
@@ -4189,21 +4189,21 @@ function Ss(i) {
4189
4189
  idle_expires_at_ts: K(e.idle_expires_at),
4190
4190
  last_exchanged_at_ts: K(e.last_exchanged_at)
4191
4191
  };
4192
- return await i.insert(C).values(r), ct({ ...r, tenant_id: n });
4192
+ return await n.insert(C).values(r), ct({ ...r, tenant_id: i });
4193
4193
  },
4194
- async get(n, e) {
4195
- const t = await i.select().from(C).where(
4196
- g(a(C.tenant_id, n), a(C.id, e))
4194
+ async get(i, e) {
4195
+ const t = await n.select().from(C).where(
4196
+ g(a(C.tenant_id, i), a(C.id, e))
4197
4197
  ).get();
4198
4198
  return t ? ct(t) : null;
4199
4199
  },
4200
- async update(n, e, t) {
4200
+ async update(i, e, t) {
4201
4201
  const r = {};
4202
- return t.device !== void 0 && (r.device = JSON.stringify(t.device)), t.resource_servers !== void 0 && (r.resource_servers = JSON.stringify(t.resource_servers)), t.rotating !== void 0 && (r.rotating = t.rotating), t.expires_at !== void 0 && (r.expires_at_ts = K(t.expires_at)), t.idle_expires_at !== void 0 && (r.idle_expires_at_ts = K(t.idle_expires_at)), t.last_exchanged_at !== void 0 && (r.last_exchanged_at_ts = K(t.last_exchanged_at)), (await i.update(C).set(r).where(
4203
- g(a(C.tenant_id, n), a(C.id, e))
4202
+ return t.device !== void 0 && (r.device = JSON.stringify(t.device)), t.resource_servers !== void 0 && (r.resource_servers = JSON.stringify(t.resource_servers)), t.rotating !== void 0 && (r.rotating = t.rotating), t.expires_at !== void 0 && (r.expires_at_ts = K(t.expires_at)), t.idle_expires_at !== void 0 && (r.idle_expires_at_ts = K(t.idle_expires_at)), t.last_exchanged_at !== void 0 && (r.last_exchanged_at_ts = K(t.last_exchanged_at)), (await n.update(C).set(r).where(
4203
+ g(a(C.tenant_id, i), a(C.id, e))
4204
4204
  ).returning()).length > 0;
4205
4205
  },
4206
- async list(n, e) {
4206
+ async list(i, e) {
4207
4207
  const {
4208
4208
  page: t = 0,
4209
4209
  per_page: r = 50,
@@ -4211,11 +4211,11 @@ function Ss(i) {
4211
4211
  sort: l,
4212
4212
  q: _
4213
4213
  } = e || {};
4214
- let d = i.select().from(C).where(a(C.tenant_id, n)).$dynamic();
4214
+ let d = n.select().from(C).where(a(C.tenant_id, i)).$dynamic();
4215
4215
  if (_) {
4216
4216
  const f = pe(C, _, ["user_id"]);
4217
4217
  f && (d = d.where(
4218
- g(a(C.tenant_id, n), f)
4218
+ g(a(C.tenant_id, i), f)
4219
4219
  ));
4220
4220
  }
4221
4221
  if (l != null && l.sort_by) {
@@ -4227,7 +4227,7 @@ function Ss(i) {
4227
4227
  const u = (await d.offset(t * r).limit(r)).map(ct);
4228
4228
  if (!o)
4229
4229
  return { refresh_tokens: u };
4230
- const [h] = await i.select({ count: V() }).from(C).where(a(C.tenant_id, n));
4230
+ const [h] = await n.select({ count: V() }).from(C).where(a(C.tenant_id, i));
4231
4231
  return {
4232
4232
  refresh_tokens: u,
4233
4233
  start: t * r,
@@ -4235,16 +4235,16 @@ function Ss(i) {
4235
4235
  length: Number((h == null ? void 0 : h.count) ?? 0)
4236
4236
  };
4237
4237
  },
4238
- async remove(n, e) {
4239
- return (await i.delete(C).where(
4240
- g(a(C.tenant_id, n), a(C.id, e))
4238
+ async remove(i, e) {
4239
+ return (await n.delete(C).where(
4240
+ g(a(C.tenant_id, i), a(C.id, e))
4241
4241
  ).returning()).length > 0;
4242
4242
  }
4243
4243
  };
4244
4244
  }
4245
4245
  function bs() {
4246
- const { customAlphabet: i } = require("nanoid");
4247
- return `api_${i("0123456789abcdefghijklmnopqrstuvwxyz", 17)()}`;
4246
+ const { customAlphabet: n } = require("nanoid");
4247
+ return `api_${n("0123456789abcdefghijklmnopqrstuvwxyz", 17)()}`;
4248
4248
  }
4249
4249
  const bt = [
4250
4250
  "skip_consent_for_verifiable_first_party_clients",
@@ -4269,26 +4269,26 @@ const bt = [
4269
4269
  "created_at",
4270
4270
  "updated_at"
4271
4271
  ]);
4272
- function gt(i) {
4272
+ function gt(n) {
4273
4273
  const {
4274
- tenant_id: n,
4274
+ tenant_id: i,
4275
4275
  verification_key: e,
4276
4276
  scopes: t,
4277
4277
  options: r,
4278
4278
  metadata: o,
4279
4279
  ...l
4280
- } = i, _ = { ...l };
4280
+ } = n, _ = { ...l };
4281
4281
  _.scopes = b(t, []), _.options = b(r, {}), _.metadata = b(o), e !== void 0 && (_.verificationKey = e);
4282
4282
  for (const d of bt)
4283
4283
  l[d] !== void 0 && l[d] !== null && (_[d] = !!l[d]);
4284
4284
  return z(_);
4285
4285
  }
4286
- function xs(i) {
4286
+ function xs(n) {
4287
4287
  return {
4288
- async create(n, e) {
4288
+ async create(i, e) {
4289
4289
  const t = (/* @__PURE__ */ new Date()).toISOString(), o = {
4290
4290
  id: e.id || bs(),
4291
- tenant_id: n,
4291
+ tenant_id: i,
4292
4292
  identifier: e.identifier,
4293
4293
  name: e.name,
4294
4294
  signing_alg: e.signing_alg,
@@ -4304,32 +4304,32 @@ function xs(i) {
4304
4304
  };
4305
4305
  for (const l of bt)
4306
4306
  e[l] !== void 0 && (o[l] = e[l] ? 1 : 0);
4307
- return o.is_system === void 0 && (o.is_system = 0), await i.insert(L).values(o), gt({ ...o, tenant_id: n });
4307
+ return o.is_system === void 0 && (o.is_system = 0), await n.insert(L).values(o), gt({ ...o, tenant_id: i });
4308
4308
  },
4309
- async get(n, e) {
4310
- const t = await i.select().from(L).where(
4309
+ async get(i, e) {
4310
+ const t = await n.select().from(L).where(
4311
4311
  g(
4312
- a(L.tenant_id, n),
4312
+ a(L.tenant_id, i),
4313
4313
  a(L.id, e)
4314
4314
  )
4315
4315
  ).get();
4316
4316
  return t ? gt(t) : null;
4317
4317
  },
4318
- async update(n, e, t) {
4318
+ async update(i, e, t) {
4319
4319
  const r = {
4320
4320
  updated_at: (/* @__PURE__ */ new Date()).toISOString()
4321
4321
  };
4322
4322
  t.name !== void 0 && (r.name = t.name), t.identifier !== void 0 && (r.identifier = t.identifier), t.signing_alg !== void 0 && (r.signing_alg = t.signing_alg), t.signing_secret !== void 0 && (r.signing_secret = t.signing_secret), t.token_lifetime !== void 0 && (r.token_lifetime = t.token_lifetime), t.token_lifetime_for_web !== void 0 && (r.token_lifetime_for_web = t.token_lifetime_for_web), t.scopes !== void 0 && (r.scopes = JSON.stringify(t.scopes)), t.options !== void 0 && (r.options = N`json_patch(COALESCE(${L.options}, '{}'), ${JSON.stringify(t.options)})`), t.metadata !== void 0 && (r.metadata = JSON.stringify(t.metadata)), t.verificationKey !== void 0 && (r.verification_key = t.verificationKey);
4323
4323
  for (const l of bt)
4324
4324
  t[l] !== void 0 && (r[l] = t[l] ? 1 : 0);
4325
- return (await i.update(L).set(r).where(
4325
+ return (await n.update(L).set(r).where(
4326
4326
  g(
4327
- a(L.tenant_id, n),
4327
+ a(L.tenant_id, i),
4328
4328
  a(L.id, e)
4329
4329
  )
4330
4330
  ).returning()).length > 0;
4331
4331
  },
4332
- async list(n, e) {
4332
+ async list(i, e) {
4333
4333
  const {
4334
4334
  page: t = 0,
4335
4335
  per_page: r = 50,
@@ -4339,7 +4339,7 @@ function xs(i) {
4339
4339
  } = e || {}, d = Math.max(0, Math.floor(Number(t) || 0)), c = Math.min(
4340
4340
  Math.max(1, Math.floor(Number(r) || 50)),
4341
4341
  500
4342
- ), u = [a(L.tenant_id, n)];
4342
+ ), u = [a(L.tenant_id, i)];
4343
4343
  if (_) {
4344
4344
  const A = _.match(/^([^:]+):(.+)$/);
4345
4345
  if (A) {
@@ -4350,7 +4350,7 @@ function xs(i) {
4350
4350
  }
4351
4351
  }
4352
4352
  }
4353
- let h = i.select().from(L).where(g(...u)).$dynamic();
4353
+ let h = n.select().from(L).where(g(...u)).$dynamic();
4354
4354
  if (l != null && l.sort_by && Bt.has(l.sort_by)) {
4355
4355
  const A = L[l.sort_by];
4356
4356
  h = h.orderBy(
@@ -4360,7 +4360,7 @@ function xs(i) {
4360
4360
  const y = (await h.offset(d * c).limit(c)).map(gt);
4361
4361
  if (!o)
4362
4362
  return { resource_servers: y };
4363
- const [w] = await i.select({ count: V() }).from(L).where(g(...u));
4363
+ const [w] = await n.select({ count: V() }).from(L).where(g(...u));
4364
4364
  return {
4365
4365
  resource_servers: y,
4366
4366
  start: d * c,
@@ -4368,23 +4368,23 @@ function xs(i) {
4368
4368
  length: Number((w == null ? void 0 : w.count) ?? 0)
4369
4369
  };
4370
4370
  },
4371
- async remove(n, e) {
4372
- return (await i.delete(L).where(
4371
+ async remove(i, e) {
4372
+ return (await n.delete(L).where(
4373
4373
  g(
4374
- a(L.tenant_id, n),
4374
+ a(L.tenant_id, i),
4375
4375
  a(L.id, e)
4376
4376
  )
4377
4377
  ).returning()).length > 0;
4378
4378
  }
4379
4379
  };
4380
4380
  }
4381
- function Ds(i) {
4381
+ function Ds(n) {
4382
4382
  return {
4383
- async assign(n, e, t) {
4383
+ async assign(i, e, t) {
4384
4384
  const r = (/* @__PURE__ */ new Date()).toISOString();
4385
- return await i.insert(le).values(
4385
+ return await n.insert(le).values(
4386
4386
  t.map((o) => ({
4387
- tenant_id: n,
4387
+ tenant_id: i,
4388
4388
  role_id: e,
4389
4389
  resource_server_identifier: o.resource_server_identifier,
4390
4390
  permission_name: o.permission_name,
@@ -4392,26 +4392,26 @@ function Ds(i) {
4392
4392
  }))
4393
4393
  ).onConflictDoNothing(), !0;
4394
4394
  },
4395
- async list(n, e, t) {
4396
- const r = await i.select({
4395
+ async list(i, e, t) {
4396
+ const r = await n.select({
4397
4397
  resource_server_identifier: le.resource_server_identifier,
4398
4398
  permission_name: le.permission_name,
4399
4399
  created_at: le.created_at
4400
4400
  }).from(le).where(
4401
4401
  g(
4402
- a(le.tenant_id, n),
4402
+ a(le.tenant_id, i),
4403
4403
  a(le.role_id, e)
4404
4404
  )
4405
4405
  ).all(), o = [
4406
4406
  ...new Set(r.map((_) => _.resource_server_identifier))
4407
4407
  ], l = /* @__PURE__ */ new Map();
4408
4408
  if (o.length > 0) {
4409
- const _ = await i.select({
4409
+ const _ = await n.select({
4410
4410
  identifier: L.identifier,
4411
4411
  name: L.name
4412
4412
  }).from(L).where(
4413
4413
  g(
4414
- a(L.tenant_id, n),
4414
+ a(L.tenant_id, i),
4415
4415
  we(L.identifier, o)
4416
4416
  )
4417
4417
  ).all();
@@ -4423,7 +4423,7 @@ function Ds(i) {
4423
4423
  resource_server_name: l.get(_.resource_server_identifier) || _.resource_server_identifier
4424
4424
  }));
4425
4425
  },
4426
- async remove(n, e, t) {
4426
+ async remove(i, e, t) {
4427
4427
  const r = t.map(
4428
4428
  (l) => g(
4429
4429
  a(
@@ -4433,9 +4433,9 @@ function Ds(i) {
4433
4433
  a(le.permission_name, l.permission_name)
4434
4434
  )
4435
4435
  );
4436
- return (await i.delete(le).where(
4436
+ return (await n.delete(le).where(
4437
4437
  g(
4438
- a(le.tenant_id, n),
4438
+ a(le.tenant_id, i),
4439
4439
  a(le.role_id, e),
4440
4440
  de(...r)
4441
4441
  )
@@ -4443,13 +4443,13 @@ function Ds(i) {
4443
4443
  }
4444
4444
  };
4445
4445
  }
4446
- function Os(i) {
4446
+ function Os(n) {
4447
4447
  return {
4448
- async create(n, e, t, r) {
4448
+ async create(i, e, t, r) {
4449
4449
  var o, l;
4450
4450
  try {
4451
- await i.insert(_e).values({
4452
- tenant_id: n,
4451
+ await n.insert(_e).values({
4452
+ tenant_id: i,
4453
4453
  user_id: e,
4454
4454
  resource_server_identifier: t.resource_server_identifier,
4455
4455
  permission_name: t.permission_name,
@@ -4463,18 +4463,18 @@ function Os(i) {
4463
4463
  }
4464
4464
  return !0;
4465
4465
  },
4466
- async list(n, e, t, r) {
4466
+ async list(i, e, t, r) {
4467
4467
  let o = [
4468
- a(_e.tenant_id, n),
4468
+ a(_e.tenant_id, i),
4469
4469
  a(_e.user_id, e)
4470
4470
  ];
4471
4471
  r && o.push(a(_e.organization_id, r));
4472
- const l = await i.select().from(_e).where(g(...o)).all();
4472
+ const l = await n.select().from(_e).where(g(...o)).all();
4473
4473
  return await Promise.all(
4474
4474
  l.map(async (d) => {
4475
- const c = await i.select({ name: L.name }).from(L).where(
4475
+ const c = await n.select({ name: L.name }).from(L).where(
4476
4476
  g(
4477
- a(L.tenant_id, n),
4477
+ a(L.tenant_id, i),
4478
4478
  a(L.identifier, d.resource_server_identifier)
4479
4479
  )
4480
4480
  ).get();
@@ -4487,10 +4487,10 @@ function Os(i) {
4487
4487
  })
4488
4488
  );
4489
4489
  },
4490
- async remove(n, e, t, r) {
4491
- return (await i.delete(_e).where(
4490
+ async remove(i, e, t, r) {
4491
+ return (await n.delete(_e).where(
4492
4492
  g(
4493
- a(_e.tenant_id, n),
4493
+ a(_e.tenant_id, i),
4494
4494
  a(_e.user_id, e),
4495
4495
  a(
4496
4496
  _e.resource_server_identifier,
@@ -4503,20 +4503,20 @@ function Os(i) {
4503
4503
  }
4504
4504
  };
4505
4505
  }
4506
- function ft(i) {
4507
- const { tenant_id: n, is_system: e, metadata: t, ...r } = i;
4506
+ function ft(n) {
4507
+ const { tenant_id: i, is_system: e, metadata: t, ...r } = n;
4508
4508
  return z({
4509
4509
  ...r,
4510
4510
  is_system: e ? !0 : void 0,
4511
4511
  metadata: b(t)
4512
4512
  });
4513
4513
  }
4514
- function ks(i) {
4514
+ function ks(n) {
4515
4515
  return {
4516
- async create(n, e) {
4516
+ async create(i, e) {
4517
4517
  const t = (/* @__PURE__ */ new Date()).toISOString(), o = {
4518
4518
  id: e.id || ae(),
4519
- tenant_id: n,
4519
+ tenant_id: i,
4520
4520
  name: e.name,
4521
4521
  description: e.description,
4522
4522
  is_system: e.is_system ? 1 : 0,
@@ -4524,27 +4524,27 @@ function ks(i) {
4524
4524
  created_at: t,
4525
4525
  updated_at: t
4526
4526
  };
4527
- return await i.insert(J).values(o), ft({ ...o, tenant_id: n });
4527
+ return await n.insert(J).values(o), ft({ ...o, tenant_id: i });
4528
4528
  },
4529
- async get(n, e) {
4530
- const t = await i.select().from(J).where(g(a(J.tenant_id, n), a(J.id, e))).get();
4529
+ async get(i, e) {
4530
+ const t = await n.select().from(J).where(g(a(J.tenant_id, i), a(J.id, e))).get();
4531
4531
  return t ? ft(t) : null;
4532
4532
  },
4533
- async update(n, e, t) {
4533
+ async update(i, e, t) {
4534
4534
  const r = {
4535
4535
  updated_at: (/* @__PURE__ */ new Date()).toISOString()
4536
4536
  };
4537
- return t.name !== void 0 && (r.name = t.name), t.description !== void 0 && (r.description = t.description), t.is_system !== void 0 && (r.is_system = t.is_system ? 1 : 0), t.metadata !== void 0 && (r.metadata = JSON.stringify(t.metadata)), (await i.update(J).set(r).where(g(a(J.tenant_id, n), a(J.id, e))).returning()).length > 0;
4537
+ return t.name !== void 0 && (r.name = t.name), t.description !== void 0 && (r.description = t.description), t.is_system !== void 0 && (r.is_system = t.is_system ? 1 : 0), t.metadata !== void 0 && (r.metadata = JSON.stringify(t.metadata)), (await n.update(J).set(r).where(g(a(J.tenant_id, i), a(J.id, e))).returning()).length > 0;
4538
4538
  },
4539
- async list(n, e) {
4539
+ async list(i, e) {
4540
4540
  const {
4541
4541
  page: t = 0,
4542
4542
  per_page: r = 50,
4543
4543
  include_totals: o = !1,
4544
4544
  sort: l,
4545
4545
  q: _
4546
- } = e || {}, d = _ ? pe(J, _, ["name"]) : void 0, c = d ? g(a(J.tenant_id, n), d) : a(J.tenant_id, n);
4547
- let u = i.select().from(J).where(c).$dynamic();
4546
+ } = e || {}, d = _ ? pe(J, _, ["name"]) : void 0, c = d ? g(a(J.tenant_id, i), d) : a(J.tenant_id, i);
4547
+ let u = n.select().from(J).where(c).$dynamic();
4548
4548
  if (l != null && l.sort_by) {
4549
4549
  const w = J[l.sort_by];
4550
4550
  w && (u = u.orderBy(
@@ -4554,7 +4554,7 @@ function ks(i) {
4554
4554
  const f = (await u.offset(t * r).limit(r)).map(ft);
4555
4555
  if (!o)
4556
4556
  return { roles: f };
4557
- const [y] = await i.select({ count: V() }).from(J).where(c);
4557
+ const [y] = await n.select({ count: V() }).from(J).where(c);
4558
4558
  return {
4559
4559
  roles: f,
4560
4560
  start: t * r,
@@ -4562,8 +4562,8 @@ function ks(i) {
4562
4562
  length: Number((y == null ? void 0 : y.count) ?? 0)
4563
4563
  };
4564
4564
  },
4565
- async remove(n, e) {
4566
- return (await i.delete(J).where(g(a(J.tenant_id, n), a(J.id, e))).returning()).length > 0;
4565
+ async remove(i, e) {
4566
+ return (await n.delete(J).where(g(a(J.tenant_id, i), a(J.id, e))).returning()).length > 0;
4567
4567
  }
4568
4568
  };
4569
4569
  }
@@ -4575,9 +4575,9 @@ const Is = ["created_at_ts", "updated_at_ts"], zs = [
4575
4575
  "used_at_ts",
4576
4576
  "revoked_at_ts"
4577
4577
  ];
4578
- function mt(i) {
4578
+ function mt(n) {
4579
4579
  const {
4580
- tenant_id: n,
4580
+ tenant_id: i,
4581
4581
  created_at_ts: e,
4582
4582
  updated_at_ts: t,
4583
4583
  expires_at_ts: r,
@@ -4589,7 +4589,7 @@ function mt(i) {
4589
4589
  device: u,
4590
4590
  clients: h,
4591
4591
  ...f
4592
- } = i, y = Fe(
4592
+ } = n, y = Fe(
4593
4593
  {
4594
4594
  created_at_ts: e,
4595
4595
  updated_at_ts: t,
@@ -4610,12 +4610,12 @@ function mt(i) {
4610
4610
  clients: b(h, [])
4611
4611
  });
4612
4612
  }
4613
- function Ts(i) {
4613
+ function Ts(n) {
4614
4614
  return {
4615
- async create(n, e) {
4615
+ async create(i, e) {
4616
4616
  const t = Date.now(), r = {
4617
4617
  id: e.id || ae(),
4618
- tenant_id: n,
4618
+ tenant_id: i,
4619
4619
  user_id: e.user_id,
4620
4620
  login_session_id: e.login_session_id,
4621
4621
  device: JSON.stringify(e.device || {}),
@@ -4629,29 +4629,29 @@ function Ts(i) {
4629
4629
  used_at_ts: K(e.used_at),
4630
4630
  revoked_at_ts: K(e.revoked_at)
4631
4631
  };
4632
- return await i.insert($).values(r), mt({ ...r, tenant_id: n });
4632
+ return await n.insert($).values(r), mt({ ...r, tenant_id: i });
4633
4633
  },
4634
- async get(n, e) {
4635
- const t = await i.select().from($).where(g(a($.tenant_id, n), a($.id, e))).get();
4634
+ async get(i, e) {
4635
+ const t = await n.select().from($).where(g(a($.tenant_id, i), a($.id, e))).get();
4636
4636
  return t ? mt(t) : null;
4637
4637
  },
4638
- async update(n, e, t) {
4638
+ async update(i, e, t) {
4639
4639
  const r = {
4640
4640
  updated_at_ts: Date.now()
4641
4641
  };
4642
4642
  return t.user_id !== void 0 && (r.user_id = t.user_id), t.login_session_id !== void 0 && (r.login_session_id = t.login_session_id), t.device !== void 0 && (r.device = JSON.stringify(t.device)), t.clients !== void 0 && (r.clients = JSON.stringify(t.clients)), t.expires_at !== void 0 && (r.expires_at_ts = K(t.expires_at)), t.idle_expires_at !== void 0 && (r.idle_expires_at_ts = K(t.idle_expires_at)), t.authenticated_at !== void 0 && (r.authenticated_at_ts = K(t.authenticated_at)), t.last_interaction_at !== void 0 && (r.last_interaction_at_ts = K(
4643
4643
  t.last_interaction_at
4644
- )), t.used_at !== void 0 && (r.used_at_ts = K(t.used_at)), t.revoked_at !== void 0 && (r.revoked_at_ts = K(t.revoked_at)), (await i.update($).set(r).where(g(a($.tenant_id, n), a($.id, e))).returning()).length > 0;
4644
+ )), t.used_at !== void 0 && (r.used_at_ts = K(t.used_at)), t.revoked_at !== void 0 && (r.revoked_at_ts = K(t.revoked_at)), (await n.update($).set(r).where(g(a($.tenant_id, i), a($.id, e))).returning()).length > 0;
4645
4645
  },
4646
- async list(n, e) {
4646
+ async list(i, e) {
4647
4647
  const {
4648
4648
  page: t = 0,
4649
4649
  per_page: r = 50,
4650
4650
  include_totals: o = !1,
4651
4651
  sort: l,
4652
4652
  q: _
4653
- } = e || {}, d = _ ? pe($, _, ["user_id"]) : void 0, c = d ? g(a($.tenant_id, n), d) : a($.tenant_id, n);
4654
- let u = i.select().from($).where(c).$dynamic();
4653
+ } = e || {}, d = _ ? pe($, _, ["user_id"]) : void 0, c = d ? g(a($.tenant_id, i), d) : a($.tenant_id, i);
4654
+ let u = n.select().from($).where(c).$dynamic();
4655
4655
  if (l != null && l.sort_by) {
4656
4656
  const w = $[l.sort_by];
4657
4657
  w && (u = u.orderBy(
@@ -4661,7 +4661,7 @@ function Ts(i) {
4661
4661
  const f = (await u.offset(t * r).limit(r)).map(mt);
4662
4662
  if (!o)
4663
4663
  return { sessions: f };
4664
- const [y] = await i.select({ count: V() }).from($).where(c);
4664
+ const [y] = await n.select({ count: V() }).from($).where(c);
4665
4665
  return {
4666
4666
  sessions: f,
4667
4667
  start: t * r,
@@ -4669,8 +4669,8 @@ function Ts(i) {
4669
4669
  length: Number((y == null ? void 0 : y.count) ?? 0)
4670
4670
  };
4671
4671
  },
4672
- async remove(n, e) {
4673
- return (await i.delete($).where(g(a($.tenant_id, n), a($.id, e))).returning()).length > 0;
4672
+ async remove(i, e) {
4673
+ return (await n.delete($).where(g(a($.tenant_id, i), a($.id, e))).returning()).length > 0;
4674
4674
  }
4675
4675
  };
4676
4676
  }
@@ -4696,39 +4696,37 @@ const mr = [
4696
4696
  "pushed_authorization_requests_supported",
4697
4697
  "authorization_response_iss_parameter_supported"
4698
4698
  ];
4699
- function Pt(i) {
4700
- const n = { ...i };
4699
+ function Pt(n) {
4700
+ const i = { ...n };
4701
4701
  for (const e of mr)
4702
- typeof n[e] == "string" && (n[e] = b(n[e]));
4702
+ typeof i[e] == "string" && (i[e] = b(i[e]));
4703
4703
  for (const e of hr)
4704
- n[e] !== void 0 && n[e] !== null && (n[e] = n[e] === 1);
4705
- return n.session_lifetime ?? (n.session_lifetime = 168), n.idle_session_lifetime ?? (n.idle_session_lifetime = 72), z(n);
4704
+ i[e] !== void 0 && i[e] !== null && (i[e] = i[e] === 1);
4705
+ return z(i);
4706
4706
  }
4707
- function Qt(i) {
4708
- const n = { ...i };
4707
+ function Qt(n) {
4708
+ const i = { ...n };
4709
4709
  Qr(
4710
- i,
4710
+ n,
4711
4711
  mr,
4712
- n
4712
+ i
4713
4713
  );
4714
4714
  for (const e of hr)
4715
- i[e] !== void 0 && (n[e] = i[e] ? 1 : 0);
4716
- return cr(n);
4715
+ n[e] !== void 0 && (i[e] = n[e] ? 1 : 0);
4716
+ return cr(i);
4717
4717
  }
4718
- function qs(i) {
4718
+ function qs(n) {
4719
4719
  return {
4720
- async create(n) {
4720
+ async create(i) {
4721
4721
  var r, o;
4722
4722
  const e = {
4723
- id: n.id || ae(),
4724
- session_lifetime: 168,
4725
- idle_session_lifetime: 72,
4723
+ id: i.id || ae(),
4726
4724
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
4727
4725
  updated_at: (/* @__PURE__ */ new Date()).toISOString(),
4728
- ...n
4726
+ ...i
4729
4727
  }, t = Qt(e);
4730
4728
  try {
4731
- await i.insert(D).values(t);
4729
+ await n.insert(D).values(t);
4732
4730
  } catch (l) {
4733
4731
  throw (r = l == null ? void 0 : l.message) != null && r.includes("UNIQUE constraint failed") || (o = l == null ? void 0 : l.message) != null && o.includes("duplicate key") || (l == null ? void 0 : l.code) === "SQLITE_CONSTRAINT" ? new be(409, {
4734
4732
  message: `Tenant with ID '${e.id}' already exists`
@@ -4736,19 +4734,19 @@ function qs(i) {
4736
4734
  }
4737
4735
  return e;
4738
4736
  },
4739
- async get(n) {
4740
- const e = await i.select().from(D).where(a(D.id, n)).get();
4737
+ async get(i) {
4738
+ const e = await n.select().from(D).where(a(D.id, i)).get();
4741
4739
  return e ? Pt(e) : null;
4742
4740
  },
4743
- async list(n) {
4741
+ async list(i) {
4744
4742
  const {
4745
4743
  page: e = 0,
4746
4744
  per_page: t = 50,
4747
4745
  include_totals: r = !1,
4748
4746
  sort: o,
4749
4747
  q: l
4750
- } = n || {};
4751
- let _ = i.select().from(D).$dynamic();
4748
+ } = i || {};
4749
+ let _ = n.select().from(D).$dynamic();
4752
4750
  if (l) {
4753
4751
  const h = pe(D, l, ["friendly_name"]);
4754
4752
  h && (_ = _.where(h));
@@ -4762,7 +4760,7 @@ function qs(i) {
4762
4760
  const c = (await _.offset(e * t).limit(t)).map(Pt);
4763
4761
  if (!r)
4764
4762
  return { tenants: c };
4765
- const [u] = await i.select({ count: V() }).from(D);
4763
+ const [u] = await n.select({ count: V() }).from(D);
4766
4764
  return {
4767
4765
  tenants: c,
4768
4766
  start: e * t,
@@ -4770,16 +4768,16 @@ function qs(i) {
4770
4768
  length: Number((u == null ? void 0 : u.count) ?? 0)
4771
4769
  };
4772
4770
  },
4773
- async update(n, e) {
4771
+ async update(i, e) {
4774
4772
  const t = Qt({
4775
4773
  ...e,
4776
- id: n,
4774
+ id: i,
4777
4775
  updated_at: (/* @__PURE__ */ new Date()).toISOString()
4778
4776
  });
4779
- await i.update(D).set(t).where(a(D.id, n));
4777
+ await n.update(D).set(t).where(a(D.id, i));
4780
4778
  },
4781
- async remove(n) {
4782
- return (await i.delete(D).where(a(D.id, n)).returning()).length > 0;
4779
+ async remove(i) {
4780
+ return (await n.delete(D).where(a(D.id, i)).returning()).length > 0;
4783
4781
  }
4784
4782
  };
4785
4783
  }
@@ -4790,51 +4788,51 @@ const Ls = [
4790
4788
  "page_background",
4791
4789
  "widget"
4792
4790
  ];
4793
- function Jt(i) {
4794
- const { tenant_id: n, ...e } = i, t = gr(e, Ls);
4791
+ function Jt(n) {
4792
+ const { tenant_id: i, ...e } = n, t = gr(e, Ls);
4795
4793
  return t.borders && (t.borders.show_widget_shadow = !!t.borders.show_widget_shadow), t.fonts && (t.fonts.links_bold = !!t.fonts.links_bold, t.fonts.subtitle_bold = !!t.fonts.subtitle_bold, t.fonts.title_bold = !!t.fonts.title_bold), z(t);
4796
4794
  }
4797
- function Es(i) {
4795
+ function Es(n) {
4798
4796
  return {
4799
- async create(n, e, t) {
4797
+ async create(i, e, t) {
4800
4798
  const r = (/* @__PURE__ */ new Date()).toISOString(), o = t || ae(), _ = {
4801
4799
  ...Pe(e),
4802
- tenant_id: n,
4800
+ tenant_id: i,
4803
4801
  themeId: o,
4804
4802
  created_at: r,
4805
4803
  updated_at: r
4806
4804
  };
4807
- return await i.insert(fe).values(_), Jt({ ..._, tenant_id: n });
4805
+ return await n.insert(fe).values(_), Jt({ ..._, tenant_id: i });
4808
4806
  },
4809
- async get(n, e) {
4810
- const t = await i.select().from(fe).where(
4811
- g(a(fe.tenant_id, n), a(fe.themeId, e))
4807
+ async get(i, e) {
4808
+ const t = await n.select().from(fe).where(
4809
+ g(a(fe.tenant_id, i), a(fe.themeId, e))
4812
4810
  ).get();
4813
4811
  return t ? Jt(t) : null;
4814
4812
  },
4815
- async update(n, e, t) {
4813
+ async update(i, e, t) {
4816
4814
  const r = Pe(t);
4817
- return r.updated_at = (/* @__PURE__ */ new Date()).toISOString(), await i.update(fe).set(r).where(
4818
- g(a(fe.tenant_id, n), a(fe.themeId, e))
4815
+ return r.updated_at = (/* @__PURE__ */ new Date()).toISOString(), await n.update(fe).set(r).where(
4816
+ g(a(fe.tenant_id, i), a(fe.themeId, e))
4819
4817
  ), !0;
4820
4818
  },
4821
- async remove(n, e) {
4822
- return (await i.delete(fe).where(
4823
- g(a(fe.tenant_id, n), a(fe.themeId, e))
4819
+ async remove(i, e) {
4820
+ return (await n.delete(fe).where(
4821
+ g(a(fe.tenant_id, i), a(fe.themeId, e))
4824
4822
  ).returning()).length > 0;
4825
4823
  }
4826
4824
  };
4827
4825
  }
4828
- function As(i) {
4826
+ function As(n) {
4829
4827
  return {
4830
- async get(n) {
4831
- const e = await i.select({ body: Ne.body }).from(Ne).where(a(Ne.tenant_id, n)).get();
4828
+ async get(i) {
4829
+ const e = await n.select({ body: Ne.body }).from(Ne).where(a(Ne.tenant_id, i)).get();
4832
4830
  return e ? { body: e.body } : null;
4833
4831
  },
4834
- async set(n, e) {
4832
+ async set(i, e) {
4835
4833
  const t = Date.now();
4836
- await i.insert(Ne).values({
4837
- tenant_id: n,
4834
+ await n.insert(Ne).values({
4835
+ tenant_id: i,
4838
4836
  body: e.body,
4839
4837
  created_at_ts: t,
4840
4838
  updated_at_ts: t
@@ -4846,25 +4844,25 @@ function As(i) {
4846
4844
  }
4847
4845
  });
4848
4846
  },
4849
- async delete(n) {
4850
- await i.delete(Ne).where(a(Ne.tenant_id, n));
4847
+ async delete(i) {
4848
+ await n.delete(Ne).where(a(Ne.tenant_id, i));
4851
4849
  }
4852
4850
  };
4853
4851
  }
4854
- function Ft(i, n) {
4852
+ function Ft(n, i) {
4855
4853
  const e = {
4856
- connection: i.connection,
4857
- provider: i.provider,
4858
- user_id: i.user_id,
4859
- isSocial: !!i.is_social
4854
+ connection: n.connection,
4855
+ provider: n.provider,
4856
+ user_id: n.user_id,
4857
+ isSocial: !!n.is_social
4860
4858
  };
4861
- return n ? e.isPrimary = !0 : e.profileData = {
4862
- email: i.email,
4863
- email_verified: !!i.email_verified,
4864
- ...typeof i.profileData == "string" ? b(i.profileData, {}) : {}
4859
+ return i ? e.isPrimary = !0 : e.profileData = {
4860
+ email: n.email,
4861
+ email_verified: !!n.email_verified,
4862
+ ...typeof n.profileData == "string" ? b(n.profileData, {}) : {}
4865
4863
  }, e;
4866
4864
  }
4867
- function ht(i, n = []) {
4865
+ function ht(n, i = []) {
4868
4866
  const {
4869
4867
  tenant_id: e,
4870
4868
  app_metadata: t,
@@ -4876,10 +4874,10 @@ function ht(i, n = []) {
4876
4874
  linked_to: c,
4877
4875
  profileData: u,
4878
4876
  ...h
4879
- } = i, f = Ft(i, !0), y = n.map((w) => Ft(w, !1));
4877
+ } = n, f = Ft(n, !0), y = i.map((w) => Ft(w, !1));
4880
4878
  return z({
4881
4879
  ...h,
4882
- email: i.email || "",
4880
+ email: n.email || "",
4883
4881
  email_verified: !!l,
4884
4882
  phone_verified: _ != null ? !!_ : void 0,
4885
4883
  is_social: !!d,
@@ -4889,8 +4887,8 @@ function ht(i, n = []) {
4889
4887
  identities: [f, ...y]
4890
4888
  });
4891
4889
  }
4892
- function Cs(i) {
4893
- const n = async (e, t) => {
4890
+ function Cs(n) {
4891
+ const i = async (e, t) => {
4894
4892
  var _, d;
4895
4893
  const r = (/* @__PURE__ */ new Date()).toISOString(), o = {
4896
4894
  user_id: t.user_id,
@@ -4930,9 +4928,9 @@ function Cs(i) {
4930
4928
  }, l = t.password ? ae() : void 0;
4931
4929
  try {
4932
4930
  if (t.password && l) {
4933
- i.run(N`BEGIN`);
4931
+ n.run(N`BEGIN`);
4934
4932
  try {
4935
- await i.insert(k).values(o), await i.insert(E).values({
4933
+ await n.insert(k).values(o), await n.insert(E).values({
4936
4934
  id: l,
4937
4935
  tenant_id: e,
4938
4936
  user_id: t.user_id,
@@ -4941,12 +4939,12 @@ function Cs(i) {
4941
4939
  is_current: 1,
4942
4940
  created_at: r,
4943
4941
  updated_at: r
4944
- }), i.run(N`COMMIT`);
4942
+ }), n.run(N`COMMIT`);
4945
4943
  } catch (c) {
4946
- throw i.run(N`ROLLBACK`), c;
4944
+ throw n.run(N`ROLLBACK`), c;
4947
4945
  }
4948
4946
  } else
4949
- await i.insert(k).values(o);
4947
+ await n.insert(k).values(o);
4950
4948
  } catch (c) {
4951
4949
  throw (_ = c == null ? void 0 : c.message) != null && _.includes("UNIQUE constraint") || (d = c == null ? void 0 : c.message) != null && d.includes("AlreadyExists") ? new be(409, { message: "User already exists" }) : (console.error("User upsert failed:", c == null ? void 0 : c.code, c == null ? void 0 : c.message), new be(500, {
4952
4950
  message: "Internal server error"
@@ -4955,12 +4953,12 @@ function Cs(i) {
4955
4953
  return ht(o);
4956
4954
  };
4957
4955
  return {
4958
- create: n,
4959
- rawCreate: n,
4956
+ create: i,
4957
+ rawCreate: i,
4960
4958
  async get(e, t) {
4961
- const r = await i.select().from(k).where(g(a(k.tenant_id, e), a(k.user_id, t))).get();
4959
+ const r = await n.select().from(k).where(g(a(k.tenant_id, e), a(k.user_id, t))).get();
4962
4960
  if (!r) return null;
4963
- const o = await i.select().from(k).where(
4961
+ const o = await n.select().from(k).where(
4964
4962
  g(a(k.tenant_id, e), a(k.linked_to, t))
4965
4963
  ).all();
4966
4964
  return ht(r, o);
@@ -4995,7 +4993,7 @@ function Cs(i) {
4995
4993
  ];
4996
4994
  for (const d of l)
4997
4995
  r[d] !== void 0 && (o[d] = r[d]);
4998
- return r.email_verified !== void 0 && (o.email_verified = r.email_verified), r.phone_verified !== void 0 && (o.phone_verified = r.phone_verified), r.is_social !== void 0 && (o.is_social = r.is_social), r.app_metadata !== void 0 && (o.app_metadata = JSON.stringify(r.app_metadata)), r.user_metadata !== void 0 && (o.user_metadata = JSON.stringify(r.user_metadata)), r.address !== void 0 && (o.address = JSON.stringify(r.address)), r.profileData !== void 0 && (o.profileData = JSON.stringify(r.profileData)), (await i.update(k).set(o).where(g(a(k.tenant_id, e), a(k.user_id, t))).returning()).length > 0;
4996
+ return r.email_verified !== void 0 && (o.email_verified = r.email_verified), r.phone_verified !== void 0 && (o.phone_verified = r.phone_verified), r.is_social !== void 0 && (o.is_social = r.is_social), r.app_metadata !== void 0 && (o.app_metadata = JSON.stringify(r.app_metadata)), r.user_metadata !== void 0 && (o.user_metadata = JSON.stringify(r.user_metadata)), r.address !== void 0 && (o.address = JSON.stringify(r.address)), r.profileData !== void 0 && (o.profileData = JSON.stringify(r.profileData)), (await n.update(k).set(o).where(g(a(k.tenant_id, e), a(k.user_id, t))).returning()).length > 0;
4999
4997
  },
5000
4998
  async list(e, t) {
5001
4999
  const {
@@ -5018,7 +5016,7 @@ function Cs(i) {
5018
5016
  W && c.push(W);
5019
5017
  }
5020
5018
  const u = g(...c);
5021
- let h = i.select().from(k).where(u).$dynamic();
5019
+ let h = n.select().from(k).where(u).$dynamic();
5022
5020
  if (_ != null && _.sort_by) {
5023
5021
  const W = k[_.sort_by];
5024
5022
  W && (h = h.orderBy(
@@ -5027,7 +5025,7 @@ function Cs(i) {
5027
5025
  }
5028
5026
  const f = await h.offset(r * o).limit(o), y = f.map((W) => W.user_id);
5029
5027
  let w = [];
5030
- y.length > 0 && (w = await i.select().from(k).where(
5028
+ y.length > 0 && (w = await n.select().from(k).where(
5031
5029
  g(
5032
5030
  a(k.tenant_id, e),
5033
5031
  we(k.linked_to, y)
@@ -5039,7 +5037,7 @@ function Cs(i) {
5039
5037
  });
5040
5038
  if (!l)
5041
5039
  return { users: A };
5042
- const [R] = await i.select({ count: V() }).from(k).where(u);
5040
+ const [R] = await n.select({ count: V() }).from(k).where(u);
5043
5041
  return {
5044
5042
  users: A,
5045
5043
  start: r * o,
@@ -5048,35 +5046,35 @@ function Cs(i) {
5048
5046
  };
5049
5047
  },
5050
5048
  async remove(e, t) {
5051
- i.run(N`BEGIN`);
5049
+ n.run(N`BEGIN`);
5052
5050
  try {
5053
- const r = await i.select({ user_id: k.user_id }).from(k).where(
5051
+ const r = await n.select({ user_id: k.user_id }).from(k).where(
5054
5052
  g(a(k.tenant_id, e), a(k.linked_to, t))
5055
5053
  ), o = [t, ...r.map((_) => _.user_id)];
5056
- await i.delete(F).where(
5054
+ await n.delete(F).where(
5057
5055
  g(
5058
5056
  a(F.tenant_id, e),
5059
5057
  we(F.user_id, o)
5060
5058
  )
5061
- ), await i.delete(E).where(
5059
+ ), await n.delete(E).where(
5062
5060
  g(
5063
5061
  a(E.tenant_id, e),
5064
5062
  we(E.user_id, o)
5065
5063
  )
5066
- ), await i.delete(k).where(
5064
+ ), await n.delete(k).where(
5067
5065
  g(a(k.tenant_id, e), a(k.linked_to, t))
5068
5066
  );
5069
- const l = await i.delete(k).where(
5067
+ const l = await n.delete(k).where(
5070
5068
  g(a(k.tenant_id, e), a(k.user_id, t))
5071
5069
  ).returning();
5072
- return i.run(N`COMMIT`), l.length > 0;
5070
+ return n.run(N`COMMIT`), l.length > 0;
5073
5071
  } catch (r) {
5074
- throw i.run(N`ROLLBACK`), r;
5072
+ throw n.run(N`ROLLBACK`), r;
5075
5073
  }
5076
5074
  },
5077
5075
  async unlink(e, t, r, o) {
5078
5076
  const l = `${r}|${o}`;
5079
- return (await i.update(k).set({ linked_to: null }).where(
5077
+ return (await n.update(k).set({ linked_to: null }).where(
5080
5078
  g(
5081
5079
  a(k.tenant_id, e),
5082
5080
  a(k.user_id, l),
@@ -5086,13 +5084,13 @@ function Cs(i) {
5086
5084
  }
5087
5085
  };
5088
5086
  }
5089
- function $s(i) {
5087
+ function $s(n) {
5090
5088
  return {
5091
- async create(n, e, t, r) {
5089
+ async create(i, e, t, r) {
5092
5090
  var o, l;
5093
5091
  try {
5094
- await i.insert(ue).values({
5095
- tenant_id: n,
5092
+ await n.insert(ue).values({
5093
+ tenant_id: i,
5096
5094
  user_id: e,
5097
5095
  role_id: t,
5098
5096
  organization_id: r || "",
@@ -5105,19 +5103,19 @@ function $s(i) {
5105
5103
  }
5106
5104
  return !0;
5107
5105
  },
5108
- async list(n, e, t, r) {
5106
+ async list(i, e, t, r) {
5109
5107
  let o = [
5110
- a(ue.tenant_id, n),
5108
+ a(ue.tenant_id, i),
5111
5109
  a(ue.user_id, e)
5112
5110
  ];
5113
5111
  r && o.push(a(ue.organization_id, r));
5114
- const l = await i.select({
5112
+ const l = await n.select({
5115
5113
  role_id: ue.role_id
5116
5114
  }).from(ue).where(g(...o)).all();
5117
5115
  return l.length === 0 ? [] : (await Promise.all(
5118
5116
  l.map(async (d) => {
5119
- const c = await i.select().from(J).where(
5120
- g(a(J.tenant_id, n), a(J.id, d.role_id))
5117
+ const c = await n.select().from(J).where(
5118
+ g(a(J.tenant_id, i), a(J.id, d.role_id))
5121
5119
  ).get();
5122
5120
  if (!c) return null;
5123
5121
  const { tenant_id: u, is_system: h, metadata: f, ...y } = c;
@@ -5129,10 +5127,10 @@ function $s(i) {
5129
5127
  })
5130
5128
  )).filter(Boolean);
5131
5129
  },
5132
- async remove(n, e, t, r) {
5133
- return (await i.delete(ue).where(
5130
+ async remove(i, e, t, r) {
5131
+ return (await n.delete(ue).where(
5134
5132
  g(
5135
- a(ue.tenant_id, n),
5133
+ a(ue.tenant_id, i),
5136
5134
  a(ue.user_id, e),
5137
5135
  a(ue.role_id, t),
5138
5136
  a(ue.organization_id, r || "")
@@ -5141,20 +5139,20 @@ function $s(i) {
5141
5139
  }
5142
5140
  };
5143
5141
  }
5144
- function Bs(i) {
5142
+ function Bs(n) {
5145
5143
  return {
5146
- async create(n, e) {
5144
+ async create(i, e) {
5147
5145
  var d, c;
5148
5146
  const t = (/* @__PURE__ */ new Date()).toISOString(), o = {
5149
5147
  id: e.id || ae(),
5150
- tenant_id: n,
5148
+ tenant_id: i,
5151
5149
  user_id: e.user_id,
5152
5150
  organization_id: e.organization_id,
5153
5151
  created_at: t,
5154
5152
  updated_at: t
5155
5153
  };
5156
5154
  try {
5157
- await i.insert(P).values(o);
5155
+ await n.insert(P).values(o);
5158
5156
  } catch (u) {
5159
5157
  throw (d = u == null ? void 0 : u.message) != null && d.includes("UNIQUE constraint") || (c = u == null ? void 0 : u.message) != null && c.includes("duplicate key") ? new be(409, {
5160
5158
  message: "User organization already exists"
@@ -5163,10 +5161,10 @@ function Bs(i) {
5163
5161
  const { tenant_id: l, ..._ } = o;
5164
5162
  return _;
5165
5163
  },
5166
- async get(n, e) {
5167
- const t = await i.select().from(P).where(
5164
+ async get(i, e) {
5165
+ const t = await n.select().from(P).where(
5168
5166
  g(
5169
- a(P.tenant_id, n),
5167
+ a(P.tenant_id, i),
5170
5168
  a(P.id, e)
5171
5169
  )
5172
5170
  ).get();
@@ -5174,24 +5172,24 @@ function Bs(i) {
5174
5172
  const { tenant_id: r, ...o } = t;
5175
5173
  return o;
5176
5174
  },
5177
- async update(n, e, t) {
5175
+ async update(i, e, t) {
5178
5176
  const r = {
5179
5177
  updated_at: (/* @__PURE__ */ new Date()).toISOString()
5180
5178
  };
5181
- return t.user_id !== void 0 && (r.user_id = t.user_id), t.organization_id !== void 0 && (r.organization_id = t.organization_id), (await i.update(P).set(r).where(
5179
+ return t.user_id !== void 0 && (r.user_id = t.user_id), t.organization_id !== void 0 && (r.organization_id = t.organization_id), (await n.update(P).set(r).where(
5182
5180
  g(
5183
- a(P.tenant_id, n),
5181
+ a(P.tenant_id, i),
5184
5182
  a(P.id, e)
5185
5183
  )
5186
5184
  ).returning()).length > 0;
5187
5185
  },
5188
- async list(n, e) {
5186
+ async list(i, e) {
5189
5187
  const {
5190
5188
  page: t = 0,
5191
5189
  per_page: r = 50,
5192
5190
  include_totals: o = !1,
5193
5191
  q: l
5194
- } = e || {}, _ = a(P.tenant_id, n);
5192
+ } = e || {}, _ = a(P.tenant_id, i);
5195
5193
  let d = _;
5196
5194
  if (l) {
5197
5195
  const f = pe(P, l, [
@@ -5200,13 +5198,13 @@ function Bs(i) {
5200
5198
  ]);
5201
5199
  f && (d = g(_, f));
5202
5200
  }
5203
- const u = (await i.select().from(P).where(d).offset(t * r).limit(r)).map((f) => {
5201
+ const u = (await n.select().from(P).where(d).offset(t * r).limit(r)).map((f) => {
5204
5202
  const { tenant_id: y, ...w } = f;
5205
5203
  return w;
5206
5204
  });
5207
5205
  if (!o)
5208
5206
  return { userOrganizations: u };
5209
- const [h] = await i.select({ count: V() }).from(P).where(d);
5207
+ const [h] = await n.select({ count: V() }).from(P).where(d);
5210
5208
  return {
5211
5209
  userOrganizations: u,
5212
5210
  start: t * r,
@@ -5214,17 +5212,17 @@ function Bs(i) {
5214
5212
  length: Number((h == null ? void 0 : h.count) ?? 0)
5215
5213
  };
5216
5214
  },
5217
- async listUserOrganizations(n, e, t) {
5218
- const { page: r = 0, per_page: o = 50, include_totals: l = !1 } = t || {}, _ = await i.select().from(P).where(
5215
+ async listUserOrganizations(i, e, t) {
5216
+ const { page: r = 0, per_page: o = 50, include_totals: l = !1 } = t || {}, _ = await n.select().from(P).where(
5219
5217
  g(
5220
- a(P.tenant_id, n),
5218
+ a(P.tenant_id, i),
5221
5219
  a(P.user_id, e)
5222
5220
  )
5223
5221
  ).offset(r * o).limit(o).all(), c = (await Promise.all(
5224
5222
  _.map(async (h) => {
5225
- const f = await i.select().from(q).where(
5223
+ const f = await n.select().from(q).where(
5226
5224
  g(
5227
- a(q.tenant_id, n),
5225
+ a(q.tenant_id, i),
5228
5226
  a(q.id, h.organization_id)
5229
5227
  )
5230
5228
  ).get();
@@ -5248,9 +5246,9 @@ function Bs(i) {
5248
5246
  )).filter(Boolean);
5249
5247
  if (!l)
5250
5248
  return { organizations: c };
5251
- const [u] = await i.select({ count: V() }).from(P).where(
5249
+ const [u] = await n.select({ count: V() }).from(P).where(
5252
5250
  g(
5253
- a(P.tenant_id, n),
5251
+ a(P.tenant_id, i),
5254
5252
  a(P.user_id, e)
5255
5253
  )
5256
5254
  );
@@ -5261,10 +5259,10 @@ function Bs(i) {
5261
5259
  length: Number((u == null ? void 0 : u.count) ?? 0)
5262
5260
  };
5263
5261
  },
5264
- async remove(n, e) {
5265
- return (await i.delete(P).where(
5262
+ async remove(i, e) {
5263
+ return (await n.delete(P).where(
5266
5264
  g(
5267
- a(P.tenant_id, n),
5265
+ a(P.tenant_id, i),
5268
5266
  a(P.id, e)
5269
5267
  )
5270
5268
  ).returning()).length > 0;
@@ -5272,11 +5270,11 @@ function Bs(i) {
5272
5270
  };
5273
5271
  }
5274
5272
  const Ut = ["s", "seacft", "seccft", "sepft", "sertft", "ssa"], Ps = ["pwd_leak", "signup_pwd_leak", "reset_pwd_leak"];
5275
- function Qs(i) {
5273
+ function Qs(n) {
5276
5274
  return {
5277
- async getDaily(n, e) {
5275
+ async getDaily(i, e) {
5278
5276
  const t = /* @__PURE__ */ new Date(), r = (e == null ? void 0 : e.from) || new Date(t.getTime() - 30 * 24 * 60 * 60 * 1e3).toISOString().split("T")[0], o = (e == null ? void 0 : e.to) || t.toISOString().split("T")[0];
5279
- return (await i.select({
5277
+ return (await n.select({
5280
5278
  date: N`substr(${T.date}, 1, 10)`.as("date"),
5281
5279
  logins: N`SUM(CASE WHEN ${T.type} IN (${N.join(
5282
5280
  Ut.map((_) => N`${_}`),
@@ -5291,7 +5289,7 @@ function Qs(i) {
5291
5289
  )}) THEN 1 ELSE 0 END)`.as("leaked_passwords")
5292
5290
  }).from(T).where(
5293
5291
  g(
5294
- a(T.tenant_id, n),
5292
+ a(T.tenant_id, i),
5295
5293
  Ge(T.date, r),
5296
5294
  Oe(T.date, `${o}T23:59:59.999Z`)
5297
5295
  )
@@ -5304,14 +5302,14 @@ function Qs(i) {
5304
5302
  updated_at: (/* @__PURE__ */ new Date()).toISOString()
5305
5303
  }));
5306
5304
  },
5307
- async getActiveUsers(n) {
5305
+ async getActiveUsers(i) {
5308
5306
  const e = new Date(
5309
5307
  Date.now() - 2592e6
5310
- ).toISOString(), [t] = await i.select({
5308
+ ).toISOString(), [t] = await n.select({
5311
5309
  count: N`COUNT(DISTINCT ${T.user_id})`.as("count")
5312
5310
  }).from(T).where(
5313
5311
  g(
5314
- a(T.tenant_id, n),
5312
+ a(T.tenant_id, i),
5315
5313
  Ge(T.date, e),
5316
5314
  N`${T.type} IN (${N.join(
5317
5315
  Ut.map((r) => N`${r}`),
@@ -5323,19 +5321,19 @@ function Qs(i) {
5323
5321
  }
5324
5322
  };
5325
5323
  }
5326
- function Kt(i) {
5324
+ function Kt(n) {
5327
5325
  return {
5328
- ...i,
5329
- payload: b(i.payload, {})
5326
+ ...n,
5327
+ payload: b(n.payload, {})
5330
5328
  };
5331
5329
  }
5332
- function Js(i) {
5330
+ function Js(n) {
5333
5331
  return {
5334
- async create(n, e) {
5332
+ async create(i, e) {
5335
5333
  const t = ae(), r = (/* @__PURE__ */ new Date()).toISOString();
5336
- return await i.insert(x).values({
5334
+ return await n.insert(x).values({
5337
5335
  id: t,
5338
- tenant_id: n,
5336
+ tenant_id: i,
5339
5337
  event_type: e.event_type,
5340
5338
  log_type: e.log_type,
5341
5339
  aggregate_type: e.aggregate_type,
@@ -5350,12 +5348,12 @@ function Js(i) {
5350
5348
  claim_expires_at: null
5351
5349
  }), t;
5352
5350
  },
5353
- async getByIds(n) {
5354
- return n.length === 0 ? [] : (await i.select().from(x).where(we(x.id, n)).all()).map(Kt);
5351
+ async getByIds(i) {
5352
+ return i.length === 0 ? [] : (await n.select().from(x).where(we(x.id, i)).all()).map(Kt);
5355
5353
  },
5356
- async getUnprocessed(n) {
5354
+ async getUnprocessed(i) {
5357
5355
  const e = (/* @__PURE__ */ new Date()).toISOString();
5358
- return (await i.select().from(x).where(
5356
+ return (await n.select().from(x).where(
5359
5357
  g(
5360
5358
  ye(x.processed_at),
5361
5359
  de(
@@ -5367,62 +5365,62 @@ function Js(i) {
5367
5365
  Oe(x.claim_expires_at, e)
5368
5366
  )
5369
5367
  )
5370
- ).orderBy(x.created_at, x.id).limit(n).all()).map(Kt);
5368
+ ).orderBy(x.created_at, x.id).limit(i).all()).map(Kt);
5371
5369
  },
5372
- async claimEvents(n, e, t) {
5373
- if (n.length === 0) return [];
5370
+ async claimEvents(i, e, t) {
5371
+ if (i.length === 0) return [];
5374
5372
  const r = (/* @__PURE__ */ new Date()).toISOString(), o = new Date(Date.now() + t).toISOString();
5375
- return await i.update(x).set({
5373
+ return await n.update(x).set({
5376
5374
  claimed_by: e,
5377
5375
  claim_expires_at: o
5378
5376
  }).where(
5379
5377
  g(
5380
- we(x.id, n),
5378
+ we(x.id, i),
5381
5379
  ye(x.processed_at),
5382
5380
  de(
5383
5381
  ye(x.claimed_by),
5384
5382
  Oe(x.claim_expires_at, r)
5385
5383
  )
5386
5384
  )
5387
- ), (await i.select({ id: x.id }).from(x).where(
5385
+ ), (await n.select({ id: x.id }).from(x).where(
5388
5386
  g(
5389
- we(x.id, n),
5387
+ we(x.id, i),
5390
5388
  a(x.claimed_by, e)
5391
5389
  )
5392
5390
  ).all()).map((_) => _.id);
5393
5391
  },
5394
- async markProcessed(n) {
5395
- n.length !== 0 && await i.update(x).set({ processed_at: (/* @__PURE__ */ new Date()).toISOString() }).where(we(x.id, n));
5392
+ async markProcessed(i) {
5393
+ i.length !== 0 && await n.update(x).set({ processed_at: (/* @__PURE__ */ new Date()).toISOString() }).where(we(x.id, i));
5396
5394
  },
5397
- async markRetry(n, e, t) {
5398
- await i.update(x).set({
5395
+ async markRetry(i, e, t) {
5396
+ await n.update(x).set({
5399
5397
  error: e,
5400
5398
  next_retry_at: t,
5401
5399
  retry_count: N`${x.retry_count} + 1`,
5402
5400
  claimed_by: null,
5403
5401
  claim_expires_at: null
5404
- }).where(a(x.id, n));
5402
+ }).where(a(x.id, i));
5405
5403
  },
5406
- async cleanup(n) {
5407
- return (await i.delete(x).where(
5404
+ async cleanup(i) {
5405
+ return (await n.delete(x).where(
5408
5406
  g(
5409
5407
  N`${x.processed_at} IS NOT NULL`,
5410
- Oe(x.processed_at, n)
5408
+ Oe(x.processed_at, i)
5411
5409
  )
5412
5410
  ).returning()).length;
5413
5411
  },
5414
- async deadLetter(n, e) {
5412
+ async deadLetter(i, e) {
5415
5413
  const t = (/* @__PURE__ */ new Date()).toISOString();
5416
- await i.update(x).set({
5414
+ await n.update(x).set({
5417
5415
  processed_at: t,
5418
5416
  dead_lettered_at: t,
5419
5417
  final_error: e
5420
- }).where(a(x.id, n));
5418
+ }).where(a(x.id, i));
5421
5419
  },
5422
- async listFailed(n, e = {}) {
5423
- const { page: t = 0, per_page: r = 50, include_totals: o = !1 } = e, _ = (await i.select().from(x).where(
5420
+ async listFailed(i, e = {}) {
5421
+ const { page: t = 0, per_page: r = 50, include_totals: o = !1 } = e, _ = (await n.select().from(x).where(
5424
5422
  g(
5425
- a(x.tenant_id, n),
5423
+ a(x.tenant_id, i),
5426
5424
  Ve(x.dead_lettered_at)
5427
5425
  )
5428
5426
  ).orderBy(M(x.dead_lettered_at), H(x.id)).offset(t * r).limit(r).all()).map((c) => ({
@@ -5438,9 +5436,9 @@ function Js(i) {
5438
5436
  }));
5439
5437
  let d = _.length;
5440
5438
  if (o) {
5441
- const [c] = await i.select({ total: V() }).from(x).where(
5439
+ const [c] = await n.select({ total: V() }).from(x).where(
5442
5440
  g(
5443
- a(x.tenant_id, n),
5441
+ a(x.tenant_id, i),
5444
5442
  Ve(x.dead_lettered_at)
5445
5443
  )
5446
5444
  );
@@ -5453,8 +5451,8 @@ function Js(i) {
5453
5451
  length: d
5454
5452
  };
5455
5453
  },
5456
- async replay(n, e) {
5457
- return (await i.update(x).set({
5454
+ async replay(i, e) {
5455
+ return (await n.update(x).set({
5458
5456
  processed_at: null,
5459
5457
  dead_lettered_at: null,
5460
5458
  final_error: null,
@@ -5463,7 +5461,7 @@ function Js(i) {
5463
5461
  error: null
5464
5462
  }).where(
5465
5463
  g(
5466
- a(x.id, n),
5464
+ a(x.id, i),
5467
5465
  a(x.tenant_id, e),
5468
5466
  Ve(x.dead_lettered_at)
5469
5467
  )
@@ -5472,8 +5470,8 @@ function Js(i) {
5472
5470
  };
5473
5471
  }
5474
5472
  const Fs = 7 * 24 * 60 * 60 * 1e3;
5475
- function Us(i) {
5476
- return async (n) => {
5473
+ function Us(n) {
5474
+ return async (i) => {
5477
5475
  const e = Date.now() - Fs;
5478
5476
  try {
5479
5477
  let t = [
@@ -5482,65 +5480,65 @@ function Us(i) {
5482
5480
  xe(C.idle_expires_at_ts, e)
5483
5481
  )
5484
5482
  ];
5485
- n != null && n.tenant_id && t.push(a(C.tenant_id, n.tenant_id)), await i.delete(C).where(g(...t)), t = [
5483
+ i != null && i.tenant_id && t.push(a(C.tenant_id, i.tenant_id)), await n.delete(C).where(g(...t)), t = [
5486
5484
  de(
5487
5485
  xe($.expires_at_ts, e),
5488
5486
  xe($.idle_expires_at_ts, e)
5489
5487
  )
5490
- ], n != null && n.tenant_id && t.push(a($.tenant_id, n.tenant_id)), n != null && n.user_id && t.push(a($.user_id, n.user_id)), await i.delete($).where(g(...t)), t = [xe(oe.expires_at_ts, e)], n != null && n.tenant_id && t.push(a(oe.tenant_id, n.tenant_id)), await i.delete(oe).where(g(...t));
5488
+ ], i != null && i.tenant_id && t.push(a($.tenant_id, i.tenant_id)), i != null && i.user_id && t.push(a($.user_id, i.user_id)), await n.delete($).where(g(...t)), t = [xe(oe.expires_at_ts, e)], i != null && i.tenant_id && t.push(a(oe.tenant_id, i.tenant_id)), await n.delete(oe).where(g(...t));
5491
5489
  } catch (t) {
5492
5490
  console.error("Session cleanup error:", t);
5493
5491
  }
5494
5492
  };
5495
5493
  }
5496
- function Ms(i, n = { useTransactions: !0 }) {
5494
+ function Ms(n, i = { useTransactions: !0 }) {
5497
5495
  const e = {
5498
5496
  actions: kr(),
5499
- branding: Ur(i),
5500
- clients: Kr(i),
5501
- clientConnections: Mr(i),
5502
- clientGrants: Gr(i),
5503
- codes: Yr(i),
5504
- connections: Zr(i),
5505
- customDomains: es(i),
5506
- customText: ts(i),
5507
- emailProviders: ns(i),
5508
- flows: is(i),
5509
- forms: rs(i),
5510
- hookCode: as(i),
5511
- hooks: _s(i),
5512
- invites: ds(i),
5513
- keys: cs(i),
5514
- loginSessions: fs(i),
5515
- logs: ms(i),
5516
- authenticationMethods: ps(i),
5517
- organizations: ws(i),
5518
- passwords: Ns(i),
5519
- promptSettings: vs(i),
5520
- refreshTokens: Ss(i),
5521
- resourceServers: xs(i),
5522
- rolePermissions: Ds(i),
5523
- userPermissions: Os(i),
5524
- roles: ks(i),
5525
- sessions: Ts(i),
5526
- sessionCleanup: Us(i),
5527
- tenants: qs(i),
5528
- themes: Es(i),
5529
- universalLoginTemplates: As(i),
5530
- users: Cs(i),
5531
- userRoles: $s(i),
5532
- userOrganizations: Bs(i),
5533
- stats: Qs(i),
5534
- outbox: Js(i),
5497
+ branding: Ur(n),
5498
+ clients: Kr(n),
5499
+ clientConnections: Mr(n),
5500
+ clientGrants: Gr(n),
5501
+ codes: Yr(n),
5502
+ connections: Zr(n),
5503
+ customDomains: es(n),
5504
+ customText: ts(n),
5505
+ emailProviders: ns(n),
5506
+ flows: is(n),
5507
+ forms: rs(n),
5508
+ hookCode: as(n),
5509
+ hooks: _s(n),
5510
+ invites: ds(n),
5511
+ keys: cs(n),
5512
+ loginSessions: fs(n),
5513
+ logs: ms(n),
5514
+ authenticationMethods: ps(n),
5515
+ organizations: ws(n),
5516
+ passwords: Ns(n),
5517
+ promptSettings: vs(n),
5518
+ refreshTokens: Ss(n),
5519
+ resourceServers: xs(n),
5520
+ rolePermissions: Ds(n),
5521
+ userPermissions: Os(n),
5522
+ roles: ks(n),
5523
+ sessions: Ts(n),
5524
+ sessionCleanup: Us(n),
5525
+ tenants: qs(n),
5526
+ themes: Es(n),
5527
+ universalLoginTemplates: As(n),
5528
+ users: Cs(n),
5529
+ userRoles: $s(n),
5530
+ userOrganizations: Bs(n),
5531
+ stats: Qs(n),
5532
+ outbox: Js(n),
5535
5533
  async transaction(t) {
5536
- if (n.useTransactions === !1)
5534
+ if (i.useTransactions === !1)
5537
5535
  return t(e);
5538
- i.run(N`BEGIN`);
5536
+ n.run(N`BEGIN`);
5539
5537
  try {
5540
5538
  const r = await t(e);
5541
- return i.run(N`COMMIT`), r;
5539
+ return n.run(N`COMMIT`), r;
5542
5540
  } catch (r) {
5543
- throw i.run(N`ROLLBACK`), r;
5541
+ throw n.run(N`ROLLBACK`), r;
5544
5542
  }
5545
5543
  }
5546
5544
  };