@authhero/drizzle 0.54.1 → 0.55.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.
@@ -1067,6 +1067,7 @@ var b = y("tenants", {
1067
1067
  provisioning_state_changed_at: _("provisioning_state_changed_at", { length: 35 }),
1068
1068
  bundle_configuration: _("bundle_configuration", { length: 64 }),
1069
1069
  worker_version: _("worker_version", { length: 64 }),
1070
+ database_version: _("database_version", { length: 64 }),
1070
1071
  worker_script_name: _("worker_script_name", { length: 255 }),
1071
1072
  storage_kind: _("storage_kind", { length: 32 }),
1072
1073
  d1_database_id: _("d1_database_id", { length: 64 })
@@ -15774,6 +15775,7 @@ var Ly = q({
15774
15775
  provisioning_state_changed_at: V().optional(),
15775
15776
  bundle_configuration: V().max(64).optional(),
15776
15777
  worker_version: V().max(64).optional(),
15778
+ database_version: V().max(64).optional(),
15777
15779
  worker_script_name: V().max(255).optional(),
15778
15780
  storage_kind: Y([
15779
15781
  "own_d1",
@@ -18021,7 +18023,10 @@ function kx(e) {
18021
18023
  clients: A(d, [])
18022
18024
  });
18023
18025
  }
18024
- function Ax(e) {
18026
+ function Ax(e, t) {
18027
+ return Math.max(e ?? 0, t ?? 0);
18028
+ }
18029
+ function jx(e) {
18025
18030
  return {
18026
18031
  async create(t, n) {
18027
18032
  let r = Date.now(), i = {
@@ -18040,7 +18045,18 @@ function Ax(e) {
18040
18045
  used_at_ts: $(n.used_at),
18041
18046
  revoked_at_ts: $(n.revoked_at)
18042
18047
  };
18043
- return await e.insert(Yt).values(i), kx({
18048
+ await e.run(p`BEGIN`);
18049
+ try {
18050
+ await e.insert(Yt).values(i);
18051
+ let n = Ax(i.expires_at_ts, i.idle_expires_at_ts);
18052
+ n > 0 && i.login_session_id && await e.update(C).set({
18053
+ expires_at_ts: n,
18054
+ updated_at_ts: r
18055
+ }).where(h(m(C.tenant_id, t), m(C.id, i.login_session_id), je(C.expires_at_ts, n))), await e.run(p`COMMIT`);
18056
+ } catch (t) {
18057
+ throw await e.run(p`ROLLBACK`), t;
18058
+ }
18059
+ return kx({
18044
18060
  ...i,
18045
18061
  tenant_id: t
18046
18062
  });
@@ -18051,7 +18067,16 @@ function Ax(e) {
18051
18067
  },
18052
18068
  async update(t, n, r) {
18053
18069
  let i = { updated_at_ts: Date.now() };
18054
- return r.user_id !== void 0 && (i.user_id = r.user_id), r.login_session_id !== void 0 && (i.login_session_id = r.login_session_id), r.device !== void 0 && (i.device = JSON.stringify(r.device)), r.clients !== void 0 && (i.clients = JSON.stringify(r.clients)), r.expires_at !== void 0 && (i.expires_at_ts = $(r.expires_at)), r.idle_expires_at !== void 0 && (i.idle_expires_at_ts = $(r.idle_expires_at)), r.authenticated_at !== void 0 && (i.authenticated_at_ts = $(r.authenticated_at)), r.last_interaction_at !== void 0 && (i.last_interaction_at_ts = $(r.last_interaction_at)), r.used_at !== void 0 && (i.used_at_ts = $(r.used_at)), r.revoked_at !== void 0 && (i.revoked_at_ts = $(r.revoked_at)), (await e.update(Yt).set(i).where(h(m(Yt.tenant_id, t), m(Yt.id, n))).returning()).length > 0;
18070
+ r.user_id !== void 0 && (i.user_id = r.user_id), r.login_session_id !== void 0 && (i.login_session_id = r.login_session_id), r.device !== void 0 && (i.device = JSON.stringify(r.device)), r.clients !== void 0 && (i.clients = JSON.stringify(r.clients)), r.expires_at !== void 0 && (i.expires_at_ts = $(r.expires_at)), r.idle_expires_at !== void 0 && (i.idle_expires_at_ts = $(r.idle_expires_at)), r.authenticated_at !== void 0 && (i.authenticated_at_ts = $(r.authenticated_at)), r.last_interaction_at !== void 0 && (i.last_interaction_at_ts = $(r.last_interaction_at)), r.used_at !== void 0 && (i.used_at_ts = $(r.used_at)), r.revoked_at !== void 0 && (i.revoked_at_ts = $(r.revoked_at));
18071
+ let a = await e.update(Yt).set(i).where(h(m(Yt.tenant_id, t), m(Yt.id, n))).returning(), o = Ax(i.expires_at_ts, i.idle_expires_at_ts), s = a[0];
18072
+ if (o > 0 && s) {
18073
+ let n = r.login_session_id ?? s.login_session_id;
18074
+ n && await e.update(C).set({
18075
+ expires_at_ts: o,
18076
+ updated_at_ts: Date.now()
18077
+ }).where(h(m(C.tenant_id, t), m(C.id, n), je(C.expires_at_ts, o))).catch(() => {});
18078
+ }
18079
+ return a.length > 0;
18055
18080
  },
18056
18081
  async list(t, n) {
18057
18082
  let { page: r = 0, per_page: i = 50, include_totals: a = !1, sort: o, q: s } = n || {}, c = s ? Pn(Yt, s, ["user_id", "id"]) : void 0, l = c ? h(m(Yt.tenant_id, t), c) : m(Yt.tenant_id, t), u = e.select().from(Yt).where(l).$dynamic();
@@ -18077,7 +18102,7 @@ function Ax(e) {
18077
18102
  //#endregion
18078
18103
  //#region src/adapters/tenants.ts
18079
18104
  Xe();
18080
- var jx = [
18105
+ var Mx = [
18081
18106
  "session_cookie",
18082
18107
  "enabled_locales",
18083
18108
  "error_page",
@@ -18093,25 +18118,25 @@ var jx = [
18093
18118
  "acr_values_supported",
18094
18119
  "mtls",
18095
18120
  "mfa"
18096
- ], Mx = [
18121
+ ], Nx = [
18097
18122
  "allow_organization_name_in_authentication_api",
18098
18123
  "customize_mfa_in_postlogin_action",
18099
18124
  "pushed_authorization_requests_supported",
18100
18125
  "authorization_response_iss_parameter_supported"
18101
18126
  ];
18102
- function Nx(e) {
18127
+ function Px(e) {
18103
18128
  let t = { ...e };
18104
- for (let e of jx) typeof t[e] == "string" && (t[e] = A(t[e]));
18105
- for (let e of Mx) t[e] !== void 0 && t[e] !== null && (t[e] = t[e] === 1);
18129
+ for (let e of Mx) typeof t[e] == "string" && (t[e] = A(t[e]));
18130
+ for (let e of Nx) t[e] !== void 0 && t[e] !== null && (t[e] = t[e] === 1);
18106
18131
  return k(t);
18107
18132
  }
18108
- function Px(e) {
18133
+ function Fx(e) {
18109
18134
  let t = { ...e };
18110
- Dn(e, jx, t);
18111
- for (let n of Mx) e[n] !== void 0 && (t[n] = +!!e[n]);
18135
+ Dn(e, Mx, t);
18136
+ for (let n of Nx) e[n] !== void 0 && (t[n] = +!!e[n]);
18112
18137
  return kn(t);
18113
18138
  }
18114
- function Fx(e) {
18139
+ function Ix(e) {
18115
18140
  return {
18116
18141
  async create(t) {
18117
18142
  let n = {
@@ -18119,7 +18144,7 @@ function Fx(e) {
18119
18144
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
18120
18145
  updated_at: (/* @__PURE__ */ new Date()).toISOString(),
18121
18146
  ...t
18122
- }, r = Px(n);
18147
+ }, r = Fx(n);
18123
18148
  try {
18124
18149
  await e.insert(b).values(r);
18125
18150
  } catch (e) {
@@ -18130,7 +18155,7 @@ function Fx(e) {
18130
18155
  },
18131
18156
  async get(t) {
18132
18157
  let n = await e.select().from(b).where(m(b.id, t)).get();
18133
- return n ? Nx(n) : null;
18158
+ return n ? Px(n) : null;
18134
18159
  },
18135
18160
  async list(t) {
18136
18161
  let { page: n = 0, per_page: r = 50, include_totals: i = !1, sort: a, q: o } = t || {}, s = e.select().from(b).$dynamic();
@@ -18142,7 +18167,7 @@ function Fx(e) {
18142
18167
  let e = b[a.sort_by];
18143
18168
  e && (s = s.orderBy(a.sort_order === "desc" ? ze(e) : Re(e)));
18144
18169
  }
18145
- let c = (await s.offset(n * r).limit(r)).map(Nx);
18170
+ let c = (await s.offset(n * r).limit(r)).map(Px);
18146
18171
  if (!i) return { tenants: c };
18147
18172
  let [l] = await e.select({ count: Be() }).from(b);
18148
18173
  return {
@@ -18153,7 +18178,7 @@ function Fx(e) {
18153
18178
  };
18154
18179
  },
18155
18180
  async update(t, n) {
18156
- let r = Px({
18181
+ let r = Fx({
18157
18182
  ...n,
18158
18183
  id: t,
18159
18184
  updated_at: (/* @__PURE__ */ new Date()).toISOString()
@@ -18168,18 +18193,18 @@ function Fx(e) {
18168
18193
  //#endregion
18169
18194
  //#region src/adapters/themes.ts
18170
18195
  Xe();
18171
- var Ix = [
18196
+ var Lx = [
18172
18197
  "colors",
18173
18198
  "borders",
18174
18199
  "fonts",
18175
18200
  "page_background",
18176
18201
  "widget"
18177
18202
  ];
18178
- function Lx(e) {
18179
- let { tenant_id: t, ...n } = e, r = jn(n, Ix);
18203
+ function Rx(e) {
18204
+ let { tenant_id: t, ...n } = e, r = jn(n, Lx);
18180
18205
  return r.borders && (r.borders.show_widget_shadow = !!r.borders.show_widget_shadow), r.fonts && (r.fonts.links_bold = !!r.fonts.links_bold, r.fonts.subtitle_bold = !!r.fonts.subtitle_bold, r.fonts.title_bold = !!r.fonts.title_bold), k(r);
18181
18206
  }
18182
- function Rx(e) {
18207
+ function zx(e) {
18183
18208
  return {
18184
18209
  async create(t, n, r) {
18185
18210
  let i = (/* @__PURE__ */ new Date()).toISOString(), a = r || Ye(), o = {
@@ -18189,14 +18214,14 @@ function Rx(e) {
18189
18214
  created_at: i,
18190
18215
  updated_at: i
18191
18216
  };
18192
- return await e.insert(hn).values(o), Lx({
18217
+ return await e.insert(hn).values(o), Rx({
18193
18218
  ...o,
18194
18219
  tenant_id: t
18195
18220
  });
18196
18221
  },
18197
18222
  async get(t, n) {
18198
18223
  let r = await e.select().from(hn).where(h(m(hn.tenant_id, t), m(hn.themeId, n))).get();
18199
- return r ? Lx(r) : null;
18224
+ return r ? Rx(r) : null;
18200
18225
  },
18201
18226
  async update(t, n, r) {
18202
18227
  let i = An(r);
@@ -18209,7 +18234,7 @@ function Rx(e) {
18209
18234
  }
18210
18235
  //#endregion
18211
18236
  //#region src/adapters/universalLoginTemplates.ts
18212
- function zx(e) {
18237
+ function Bx(e) {
18213
18238
  return {
18214
18239
  async get(t) {
18215
18240
  let n = await e.select({ body: mn.body }).from(mn).where(m(mn.tenant_id, t)).get();
@@ -18238,7 +18263,7 @@ function zx(e) {
18238
18263
  //#endregion
18239
18264
  //#region src/adapters/users.ts
18240
18265
  Xe();
18241
- var Bx = [
18266
+ var Vx = [
18242
18267
  "user_id",
18243
18268
  "email",
18244
18269
  "email_verified",
@@ -18260,13 +18285,13 @@ var Bx = [
18260
18285
  "login_count",
18261
18286
  "created_at",
18262
18287
  "updated_at"
18263
- ], Vx = [
18288
+ ], Hx = [
18264
18289
  "email",
18265
18290
  "name",
18266
18291
  "phone_number",
18267
18292
  "user_id"
18268
18293
  ];
18269
- function Hx(e, t) {
18294
+ function Ux(e, t) {
18270
18295
  let n = {
18271
18296
  connection: e.connection,
18272
18297
  provider: e.provider,
@@ -18279,8 +18304,8 @@ function Hx(e, t) {
18279
18304
  ...typeof e.profileData == "string" ? A(e.profileData, {}) : {}
18280
18305
  }, n;
18281
18306
  }
18282
- function Ux(e, t = []) {
18283
- let { tenant_id: n, app_metadata: r, user_metadata: i, address: a, email_verified: o, phone_verified: s, is_social: c, linked_to: l, profileData: u, ...d } = e, f = Hx(e, !0), ee = t.map((e) => Hx(e, !1));
18307
+ function Wx(e, t = []) {
18308
+ let { tenant_id: n, app_metadata: r, user_metadata: i, address: a, email_verified: o, phone_verified: s, is_social: c, linked_to: l, profileData: u, ...d } = e, f = Ux(e, !0), ee = t.map((e) => Ux(e, !1));
18284
18309
  return k({
18285
18310
  ...d,
18286
18311
  email: e.email || "",
@@ -18293,7 +18318,7 @@ function Ux(e, t = []) {
18293
18318
  identities: [f, ...ee]
18294
18319
  });
18295
18320
  }
18296
- function Wx(e) {
18321
+ function Gx(e) {
18297
18322
  let t = async (t, n) => {
18298
18323
  let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
18299
18324
  user_id: n.user_id,
@@ -18352,14 +18377,14 @@ function Wx(e) {
18352
18377
  } catch (e) {
18353
18378
  throw e?.message?.includes("UNIQUE constraint") || e?.message?.includes("AlreadyExists") ? new Un(409, { message: "User already exists" }) : (console.error("User upsert failed:", e?.code, e?.message), new Un(500, { message: "Internal server error" }));
18354
18379
  }
18355
- return Ux(i);
18380
+ return Wx(i);
18356
18381
  };
18357
18382
  return {
18358
18383
  create: t,
18359
18384
  rawCreate: t,
18360
18385
  async get(t, n) {
18361
18386
  let r = await e.select().from(x).where(h(m(x.tenant_id, t), m(x.user_id, n))).get();
18362
- return r ? Ux(r, await e.select().from(x).where(h(m(x.tenant_id, t), m(x.linked_to, n))).all()) : null;
18387
+ return r ? Wx(r, await e.select().from(x).where(h(m(x.tenant_id, t), m(x.linked_to, n))).all()) : null;
18363
18388
  },
18364
18389
  async update(t, n, r) {
18365
18390
  let i = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
@@ -18393,9 +18418,9 @@ function Wx(e) {
18393
18418
  async list(t, n) {
18394
18419
  let { page: r = 0, per_page: i = 50, include_totals: a = !1, sort: o, q: s } = n || {}, c = [m(x.tenant_id, t), Pe(x.linked_to)];
18395
18420
  if (s) {
18396
- let e = Nn(s, Bx);
18421
+ let e = Nn(s, Vx);
18397
18422
  if (e) {
18398
- let t = Pn(x, e, Vx);
18423
+ let t = Pn(x, e, Hx);
18399
18424
  t && c.push(t);
18400
18425
  }
18401
18426
  }
@@ -18406,7 +18431,7 @@ function Wx(e) {
18406
18431
  }
18407
18432
  let d = await u.offset(r * i).limit(i), f = d.map((e) => e.user_id), ee = [];
18408
18433
  f.length > 0 && (ee = await e.select().from(x).where(h(m(x.tenant_id, t), Ne(x.linked_to, f))));
18409
- let te = d.map((e) => Ux(e, ee.filter((t) => t.linked_to === e.user_id)));
18434
+ let te = d.map((e) => Wx(e, ee.filter((t) => t.linked_to === e.user_id)));
18410
18435
  if (!a) return { users: te };
18411
18436
  let [ne] = await e.select({ count: Be() }).from(x).where(l);
18412
18437
  return {
@@ -18435,7 +18460,7 @@ function Wx(e) {
18435
18460
  }
18436
18461
  //#endregion
18437
18462
  //#region src/adapters/userRoles.ts
18438
- function Gx(e) {
18463
+ function Kx(e) {
18439
18464
  return {
18440
18465
  async create(t, n, r, i) {
18441
18466
  try {
@@ -18475,7 +18500,7 @@ function Gx(e) {
18475
18500
  //#endregion
18476
18501
  //#region src/adapters/userOrganizations.ts
18477
18502
  Xe();
18478
- function Kx(e) {
18503
+ function qx(e) {
18479
18504
  return {
18480
18505
  async create(t, n) {
18481
18506
  let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
@@ -18552,19 +18577,19 @@ function Kx(e) {
18552
18577
  }
18553
18578
  //#endregion
18554
18579
  //#region src/adapters/stats.ts
18555
- var qx = ["s"], Jx = ["pwd_leak"];
18556
- function Yx(e) {
18580
+ var Jx = ["s"], Yx = ["pwd_leak"];
18581
+ function Xx(e) {
18557
18582
  return /^\d{8}$/.test(e) ? `${e.slice(0, 4)}-${e.slice(4, 6)}-${e.slice(6, 8)}` : e;
18558
18583
  }
18559
- function Xx(e) {
18584
+ function Zx(e) {
18560
18585
  return {
18561
18586
  async getDaily(t, n) {
18562
- let r = /* @__PURE__ */ new Date(), i = n?.from ? Yx(n.from) : (/* @__PURE__ */ new Date(r.getTime() - 720 * 60 * 60 * 1e3)).toISOString().split("T")[0], a = n?.to ? Yx(n.to) : r.toISOString().split("T")[0];
18587
+ let r = /* @__PURE__ */ new Date(), i = n?.from ? Xx(n.from) : (/* @__PURE__ */ new Date(r.getTime() - 720 * 60 * 60 * 1e3)).toISOString().split("T")[0], a = n?.to ? Xx(n.to) : r.toISOString().split("T")[0];
18563
18588
  return (await e.select({
18564
18589
  date: p`substr(${E.date}, 1, 10)`.as("date"),
18565
- logins: p`SUM(CASE WHEN ${E.type} IN (${p.join(qx.map((e) => p`${e}`), p`, `)}) THEN 1 ELSE 0 END)`.as("logins"),
18590
+ logins: p`SUM(CASE WHEN ${E.type} IN (${p.join(Jx.map((e) => p`${e}`), p`, `)}) THEN 1 ELSE 0 END)`.as("logins"),
18566
18591
  signups: p`SUM(CASE WHEN ${E.type} = 'ss' THEN 1 ELSE 0 END)`.as("signups"),
18567
- leaked_passwords: p`SUM(CASE WHEN ${E.type} IN (${p.join(Jx.map((e) => p`${e}`), p`, `)}) THEN 1 ELSE 0 END)`.as("leaked_passwords")
18592
+ leaked_passwords: p`SUM(CASE WHEN ${E.type} IN (${p.join(Yx.map((e) => p`${e}`), p`, `)}) THEN 1 ELSE 0 END)`.as("leaked_passwords")
18568
18593
  }).from(E).where(h(m(E.tenant_id, t), Ae(E.date, i), Me(E.date, `${a}T23:59:59.999Z`))).groupBy(p`substr(${E.date}, 1, 10)`).orderBy(p`substr(${E.date}, 1, 10)`).all()).map((e) => ({
18569
18594
  date: e.date,
18570
18595
  logins: Number(e.logins) || 0,
@@ -18575,14 +18600,14 @@ function Xx(e) {
18575
18600
  }));
18576
18601
  },
18577
18602
  async getActiveUsers(t) {
18578
- let n = (/* @__PURE__ */ new Date(Date.now() - 720 * 60 * 60 * 1e3)).toISOString(), [r] = await e.select({ count: p`COUNT(DISTINCT ${E.user_id})`.as("count") }).from(E).where(h(m(E.tenant_id, t), Ae(E.date, n), p`${E.type} IN (${p.join(qx.map((e) => p`${e}`), p`, `)})`));
18603
+ let n = (/* @__PURE__ */ new Date(Date.now() - 720 * 60 * 60 * 1e3)).toISOString(), [r] = await e.select({ count: p`COUNT(DISTINCT ${E.user_id})`.as("count") }).from(E).where(h(m(E.tenant_id, t), Ae(E.date, n), p`${E.type} IN (${p.join(Jx.map((e) => p`${e}`), p`, `)})`));
18579
18604
  return Number(r?.count) || 0;
18580
18605
  }
18581
18606
  };
18582
18607
  }
18583
18608
  //#endregion
18584
18609
  //#region src/adapters/analytics.ts
18585
- var Zx = {
18610
+ var Qx = {
18586
18611
  "active-users": ["s", "seacft"],
18587
18612
  logins: [
18588
18613
  "s",
@@ -18592,7 +18617,7 @@ var Zx = {
18592
18617
  signups: ["ss", "fs"],
18593
18618
  "refresh-tokens": ["seacft", "fertft"],
18594
18619
  sessions: ["slo"]
18595
- }, Qx = {
18620
+ }, $x = {
18596
18621
  "active-users": {
18597
18622
  alias: "active_users",
18598
18623
  type: "UInt64",
@@ -18619,7 +18644,7 @@ var Zx = {
18619
18644
  agg: "count"
18620
18645
  }
18621
18646
  };
18622
- function $x(e) {
18647
+ function eS(e) {
18623
18648
  switch (e) {
18624
18649
  case "hour": return p`substr(${E.date}, 1, 13)`;
18625
18650
  case "month": return p`substr(${E.date}, 1, 7)`;
@@ -18628,10 +18653,10 @@ function $x(e) {
18628
18653
  default: throw Error(`Unsupported interval '${e}' for SQL analytics adapter`);
18629
18654
  }
18630
18655
  }
18631
- function eS(e) {
18656
+ function tS(e) {
18632
18657
  return `"${e.replace(/"/g, "\"\"")}"`;
18633
18658
  }
18634
- function tS(e) {
18659
+ function nS(e) {
18635
18660
  switch (e) {
18636
18661
  case "connection": return E.connection;
18637
18662
  case "client_id": return E.client_id;
@@ -18640,9 +18665,9 @@ function tS(e) {
18640
18665
  case "time": throw Error("time dimension handled separately");
18641
18666
  }
18642
18667
  }
18643
- function nS(e) {
18668
+ function rS(e) {
18644
18669
  return { async query(t, n, r) {
18645
- let i = Date.now(), a = Zx[n], o = Qx[n], s = [
18670
+ let i = Date.now(), a = Qx[n], o = $x[n], s = [
18646
18671
  m(E.tenant_id, t),
18647
18672
  Ae(E.date, r.from),
18648
18673
  je(E.date, r.to),
@@ -18651,13 +18676,13 @@ function nS(e) {
18651
18676
  r.filters.connection?.length && s.push(Ne(E.connection, r.filters.connection)), r.filters.client_id?.length && s.push(Ne(E.client_id, r.filters.client_id)), r.filters.user_type?.length && s.push(Ne(E.strategy_type, r.filters.user_type)), r.filters.user_id?.length && s.push(Ne(E.user_id, r.filters.user_id));
18652
18677
  let c = {}, l = [], u = [];
18653
18678
  for (let e of r.group_by) if (e === "time") {
18654
- let e = $x(r.interval);
18679
+ let e = eS(r.interval);
18655
18680
  c.time = e, l.push(e), u.push({
18656
18681
  name: "time",
18657
18682
  type: r.interval === "hour" ? "DateTime" : "Date"
18658
18683
  });
18659
18684
  } else {
18660
- let t = tS(e);
18685
+ let t = nS(e);
18661
18686
  c[e] = t, l.push(t), u.push({
18662
18687
  name: e,
18663
18688
  type: "String"
@@ -18673,9 +18698,9 @@ function nS(e) {
18673
18698
  if (r.order_by) {
18674
18699
  let e = r.order_by.startsWith("-"), t = e ? r.order_by.slice(1) : r.order_by;
18675
18700
  if (!f.has(t)) throw Error(`Invalid order_by column '${t}' for analytics query`);
18676
- let n = eS(t);
18701
+ let n = tS(t);
18677
18702
  d = d.orderBy(p.raw(`${n} ${e ? "DESC" : "ASC"}`));
18678
- } else d = r.group_by[0] === "time" ? d.orderBy(p.raw(`${eS("time")} ASC`)) : d.orderBy(p.raw(`${eS(o.alias)} DESC`));
18703
+ } else d = r.group_by[0] === "time" ? d.orderBy(p.raw(`${tS("time")} ASC`)) : d.orderBy(p.raw(`${tS(o.alias)} DESC`));
18679
18704
  d = d.limit(r.limit).offset(r.offset);
18680
18705
  let ee = (await d.all()).map((e) => {
18681
18706
  let t = {};
@@ -18697,13 +18722,13 @@ function nS(e) {
18697
18722
  //#endregion
18698
18723
  //#region src/adapters/outbox.ts
18699
18724
  Xe();
18700
- function rS(e) {
18725
+ function iS(e) {
18701
18726
  return {
18702
18727
  ...e,
18703
18728
  payload: A(e.payload, {})
18704
18729
  };
18705
18730
  }
18706
- function iS(e) {
18731
+ function aS(e) {
18707
18732
  return {
18708
18733
  async create(t, n) {
18709
18734
  let r = Ye(), i = (/* @__PURE__ */ new Date()).toISOString();
@@ -18728,11 +18753,11 @@ function iS(e) {
18728
18753
  }), r;
18729
18754
  },
18730
18755
  async getByIds(t) {
18731
- return t.length === 0 ? [] : (await e.select().from(D).where(Ne(D.id, t)).all()).map(rS);
18756
+ return t.length === 0 ? [] : (await e.select().from(D).where(Ne(D.id, t)).all()).map(iS);
18732
18757
  },
18733
18758
  async getUnprocessed(t) {
18734
18759
  let n = (/* @__PURE__ */ new Date()).toISOString();
18735
- return (await e.select().from(D).where(h(Pe(D.processed_at), Oe(Pe(D.next_retry_at), Me(D.next_retry_at, n)), Oe(Pe(D.claimed_by), Me(D.claim_expires_at, n)))).orderBy(D.created_at, D.id).limit(t).all()).map(rS);
18760
+ return (await e.select().from(D).where(h(Pe(D.processed_at), Oe(Pe(D.next_retry_at), Me(D.next_retry_at, n)), Oe(Pe(D.claimed_by), Me(D.claim_expires_at, n)))).orderBy(D.created_at, D.id).limit(t).all()).map(iS);
18736
18761
  },
18737
18762
  async claimEvents(t, n, r) {
18738
18763
  if (t.length === 0) return [];
@@ -18802,10 +18827,10 @@ function iS(e) {
18802
18827
  }
18803
18828
  //#endregion
18804
18829
  //#region src/adapters/cleanup.ts
18805
- var aS = 10080 * 60 * 1e3;
18806
- function oS(e) {
18830
+ var oS = 10080 * 60 * 1e3;
18831
+ function sS(e) {
18807
18832
  return async (t) => {
18808
- let n = Date.now() - aS;
18833
+ let n = Date.now() - oS;
18809
18834
  try {
18810
18835
  let r = [Oe(je(S.expires_at_ts, n), je(S.idle_expires_at_ts, n))];
18811
18836
  t?.tenant_id && r.push(m(S.tenant_id, t.tenant_id)), await e.delete(S).where(h(...r)), r = [Oe(je(Yt.expires_at_ts, n), je(Yt.idle_expires_at_ts, n))], t?.tenant_id && r.push(m(Yt.tenant_id, t.tenant_id)), t?.user_id && r.push(m(Yt.user_id, t.user_id)), await e.delete(Yt).where(h(...r)), r = [je(C.expires_at_ts, n)], t?.tenant_id && r.push(m(C.tenant_id, t.tenant_id)), await e.delete(C).where(h(...r));
@@ -18816,7 +18841,7 @@ function oS(e) {
18816
18841
  }
18817
18842
  //#endregion
18818
18843
  //#region src/adapters/index.ts
18819
- function sS(e, t = { useTransactions: !0 }) {
18844
+ function cS(e, t = { useTransactions: !0 }) {
18820
18845
  let n = {
18821
18846
  actions: Ln(e),
18822
18847
  actionExecutions: Rn(e),
@@ -18850,17 +18875,17 @@ function sS(e, t = { useTransactions: !0 }) {
18850
18875
  rolePermissions: Cx(e),
18851
18876
  userPermissions: wx(e),
18852
18877
  roles: Ex(e),
18853
- sessions: Ax(e),
18854
- sessionCleanup: oS(e),
18855
- tenants: Fx(e),
18856
- themes: Rx(e),
18857
- universalLoginTemplates: zx(e),
18858
- users: Wx(e),
18859
- userRoles: Gx(e),
18860
- userOrganizations: Kx(e),
18861
- stats: Xx(e),
18862
- analytics: nS(e),
18863
- outbox: iS(e),
18878
+ sessions: jx(e),
18879
+ sessionCleanup: sS(e),
18880
+ tenants: Ix(e),
18881
+ themes: zx(e),
18882
+ universalLoginTemplates: Bx(e),
18883
+ users: Gx(e),
18884
+ userRoles: Kx(e),
18885
+ userOrganizations: qx(e),
18886
+ stats: Zx(e),
18887
+ analytics: rS(e),
18888
+ outbox: aS(e),
18864
18889
  async transaction(r) {
18865
18890
  if (t.useTransactions === !1) return r(n);
18866
18891
  await e.run(p`BEGIN`);
@@ -18876,7 +18901,7 @@ function sS(e, t = { useTransactions: !0 }) {
18876
18901
  }
18877
18902
  //#endregion
18878
18903
  //#region src/adapters/resolveHost.ts
18879
- function cS(e) {
18904
+ function lS(e) {
18880
18905
  if (!e) return { path: "/*" };
18881
18906
  try {
18882
18907
  let t = JSON.parse(e), n = Wy.safeParse(t);
@@ -18884,7 +18909,7 @@ function cS(e) {
18884
18909
  } catch {}
18885
18910
  return { path: "/*" };
18886
18911
  }
18887
- function lS(e) {
18912
+ function uS(e) {
18888
18913
  if (!e) return [];
18889
18914
  try {
18890
18915
  let t = JSON.parse(e);
@@ -18899,7 +18924,7 @@ function lS(e) {
18899
18924
  return [];
18900
18925
  }
18901
18926
  }
18902
- async function uS(e, t) {
18927
+ async function dS(e, t) {
18903
18928
  let n = t.toLowerCase(), r = (await e.select({
18904
18929
  custom_domain_id: nn.custom_domain_id,
18905
18930
  tenant_id: nn.tenant_id,
@@ -18911,8 +18936,8 @@ async function uS(e, t) {
18911
18936
  tenant_id: e.tenant_id,
18912
18937
  custom_domain_id: e.custom_domain_id,
18913
18938
  priority: e.priority,
18914
- match: cS(e.match),
18915
- handlers: lS(e.handlers),
18939
+ match: lS(e.match),
18940
+ handlers: uS(e.handlers),
18916
18941
  created_at: e.created_at,
18917
18942
  updated_at: e.updated_at
18918
18943
  }));
@@ -18925,11 +18950,11 @@ async function uS(e, t) {
18925
18950
  }
18926
18951
  //#endregion
18927
18952
  //#region src/adapters/proxyData.ts
18928
- function dS(e) {
18953
+ function fS(e) {
18929
18954
  return {
18930
18955
  proxyRoutes: px(e),
18931
- resolveHost: (t) => uS(e, t)
18956
+ resolveHost: (t) => dS(e, t)
18932
18957
  };
18933
18958
  }
18934
18959
  //#endregion
18935
- export { dS as createProxyDataAdapter, px as createProxyRoutesAdapter, sS as default, En as sqlite };
18960
+ export { fS as createProxyDataAdapter, px as createProxyRoutesAdapter, cS as default, En as sqlite };
@@ -49,6 +49,7 @@ CREATE TABLE `tenants` (
49
49
  `provisioning_state_changed_at` text(35),
50
50
  `bundle_configuration` text(64),
51
51
  `worker_version` text(64),
52
+ `database_version` text(64),
52
53
  `worker_script_name` text(255),
53
54
  `storage_kind` text(32),
54
55
  `d1_database_id` text(64)
@@ -359,6 +359,13 @@
359
359
  "notNull": false,
360
360
  "autoincrement": false
361
361
  },
362
+ "database_version": {
363
+ "name": "database_version",
364
+ "type": "text(64)",
365
+ "primaryKey": false,
366
+ "notNull": false,
367
+ "autoincrement": false
368
+ },
362
369
  "worker_script_name": {
363
370
  "name": "worker_script_name",
364
371
  "type": "text(255)",
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "type": "git",
12
12
  "url": "https://github.com/markusahlstrand/authhero"
13
13
  },
14
- "version": "0.54.1",
14
+ "version": "0.55.0",
15
15
  "files": [
16
16
  "dist",
17
17
  "src/schema",
@@ -34,8 +34,8 @@
34
34
  "dependencies": {
35
35
  "drizzle-orm": "^0.44.2",
36
36
  "nanoid": "^5.1.11",
37
- "@authhero/adapter-interfaces": "3.2.0",
38
- "@authhero/proxy": "0.7.2"
37
+ "@authhero/adapter-interfaces": "3.3.0",
38
+ "@authhero/proxy": "0.7.3"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@hono/zod-openapi": "^1.4.0",
@@ -65,6 +65,7 @@ export const tenants = sqliteTable("tenants", {
65
65
  }),
66
66
  bundle_configuration: text("bundle_configuration", { length: 64 }),
67
67
  worker_version: text("worker_version", { length: 64 }),
68
+ database_version: text("database_version", { length: 64 }),
68
69
  worker_script_name: text("worker_script_name", { length: 255 }),
69
70
  storage_kind: text("storage_kind", { length: 32 }),
70
71
  d1_database_id: text("d1_database_id", { length: 64 }),