@authhero/kysely-adapter 11.21.0 → 12.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -21
- package/dist/kysely-adapter.cjs +1 -27
- package/dist/kysely-adapter.mjs +63 -112
- package/dist/types/migrate/migrations/index.d.ts +0 -2
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/package.json +4 -3
- package/dist/types/migrate/migrations/2026-07-16T16:00:00_restore_unique_phone_provider.d.ts +0 -29
package/dist/kysely-adapter.mjs
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { customAlphabet as e, nanoid as t } from "nanoid";
|
|
2
2
|
import { booleanToInt as n, convertDatesToAdapter as r, dbDateToIso as i, dbDateToIsoRequired as a, getCountAsInt as o, isoToDbDate as s, nowIso as c, removeNullProperties as l, removeUndefinedAndNull as u, stringifyProperties as d } from "@authhero/adapter-interfaces/sql";
|
|
3
3
|
import { sql as f } from "kysely";
|
|
4
|
-
import { LoginSessionState as p, clientGrantSchema as m, clientRegistrationTokenTypeSchema as h, codeSchema as g, decodeCursor as _, emailTemplateSchema as v, encodeCursor as
|
|
5
|
-
import { HTTPException as
|
|
4
|
+
import { LoginSessionState as p, clientGrantSchema as m, clientRegistrationTokenTypeSchema as h, codeSchema as g, decodeCursor as _, emailTemplateSchema as v, encodeCursor as y, flowSchema as b, formSchema as x, handlerConfigSchema as ee, isPlainObject as te, loginSessionSchema as ne, matchSchema as re, migrationProviderTypeSchema as ie, parseUserId as ae, resourceServerSchema as oe, rolloutInsertSchema as se, rolloutSchema as ce, sanitizeLuceneQuery as S, tenantOperationEventInsertSchema as le, tenantOperationEventSchema as ue, tenantOperationInsertSchema as de, tenantOperationSchema as fe } from "@authhero/adapter-interfaces";
|
|
5
|
+
import { HTTPException as C } from "hono/http-exception";
|
|
6
6
|
import "@hono/zod-openapi";
|
|
7
|
-
import { Migrator as
|
|
7
|
+
import { Migrator as pe } from "kysely/migration";
|
|
8
8
|
//#region \0rolldown/runtime.js
|
|
9
|
-
var
|
|
9
|
+
var me = Object.defineProperty, he = (e, t) => {
|
|
10
10
|
let n = {};
|
|
11
|
-
for (var r in e)
|
|
11
|
+
for (var r in e) me(n, r, {
|
|
12
12
|
get: e[r],
|
|
13
13
|
enumerable: !0
|
|
14
14
|
});
|
|
15
|
-
return t ||
|
|
15
|
+
return t || me(n, Symbol.toStringTag, { value: "Module" }), n;
|
|
16
16
|
}, ge = 17, _e = {
|
|
17
17
|
organization: "org_",
|
|
18
18
|
connection: "con_",
|
|
@@ -502,7 +502,7 @@ function Ve(e) {
|
|
|
502
502
|
try {
|
|
503
503
|
e.isTransaction ? await h(e) : await e.transaction().execute(h);
|
|
504
504
|
} catch (e) {
|
|
505
|
-
throw e.code === "SQLITE_CONSTRAINT_UNIQUE" || e.code === "ER_DUP_ENTRY" || e.message.includes("AlreadyExists") ? new
|
|
505
|
+
throw e.code === "SQLITE_CONSTRAINT_UNIQUE" || e.code === "ER_DUP_ENTRY" || e.message.includes("AlreadyExists") ? new C(409, { message: "User already exists" }) : new C(500, { message: `${e.code}, ${e.message}` });
|
|
506
506
|
}
|
|
507
507
|
return {
|
|
508
508
|
...m,
|
|
@@ -532,7 +532,7 @@ function j(e, t = !1) {
|
|
|
532
532
|
let n = {
|
|
533
533
|
connection: e.connection,
|
|
534
534
|
provider: e.provider,
|
|
535
|
-
user_id:
|
|
535
|
+
user_id: ae(e.user_id).id,
|
|
536
536
|
isSocial: !!e.is_social
|
|
537
537
|
};
|
|
538
538
|
for (let t of He) e[t] !== void 0 && e[t] !== null && (n[t] = t.endsWith("_verified") ? !!e[t] : e[t]);
|
|
@@ -589,7 +589,7 @@ function We(e, t) {
|
|
|
589
589
|
}
|
|
590
590
|
async function N(e, t, n) {
|
|
591
591
|
let { sortColumn: r, sortOrder: i } = n, a = n.idColumn ?? "id", o = We(t?.take, 50), s = e.orderBy(f.ref(r), i).orderBy(f.ref(a), i), c = t?.from ? _(t.from) : null;
|
|
592
|
-
if (c && c.k !== n.sortKey) throw new
|
|
592
|
+
if (c && c.k !== n.sortKey) throw new C(400, { message: "The `from` cursor was issued under a different sort and cannot be used with this request" });
|
|
593
593
|
if (c) if (c.s === void 0 || c.s === null) s = s.where(f.ref(a), i === "asc" ? ">" : "<", c.i);
|
|
594
594
|
else {
|
|
595
595
|
let e = i === "asc" ? f.raw(">") : f.raw("<");
|
|
@@ -598,7 +598,7 @@ async function N(e, t, n) {
|
|
|
598
598
|
let l = await s.limit(o + 1).execute(), u = l.length > o, d = u ? l.slice(0, o) : l, p;
|
|
599
599
|
if (u && d.length > 0) {
|
|
600
600
|
let e = d[d.length - 1], t = r.split(".").pop(), i = a.split(".").pop(), o = e[t];
|
|
601
|
-
p =
|
|
601
|
+
p = y({
|
|
602
602
|
s: typeof o == "string" || typeof o == "number" || o === null ? o : String(o),
|
|
603
603
|
i: String(e[i]),
|
|
604
604
|
...n.sortKey !== void 0 && { k: n.sortKey }
|
|
@@ -634,7 +634,7 @@ var Ge = [
|
|
|
634
634
|
"login_count",
|
|
635
635
|
"created_at",
|
|
636
636
|
"updated_at"
|
|
637
|
-
], Ke =
|
|
637
|
+
], Ke = new Set([
|
|
638
638
|
"last_login",
|
|
639
639
|
"last_ip",
|
|
640
640
|
"login_count"
|
|
@@ -668,11 +668,11 @@ function Xe(e) {
|
|
|
668
668
|
return async (t, n = {}) => {
|
|
669
669
|
let { page: r = 0, per_page: i = 50, include_totals: a = !1, sort: s, q: c } = n, l = e.selectFrom("users").leftJoin("user_activity", (e) => e.onRef("user_activity.tenant_id", "=", "users.tenant_id").onRef("user_activity.user_id", "=", "users.user_id")).where("users.tenant_id", "=", t);
|
|
670
670
|
if (c) {
|
|
671
|
-
let t =
|
|
671
|
+
let t = S(c, Ge);
|
|
672
672
|
t && (l = D(e, l, t, Je, [], qe));
|
|
673
673
|
}
|
|
674
674
|
if (M(n)) {
|
|
675
|
-
if (s?.sort_by && s.sort_by !== "created_at") throw new
|
|
675
|
+
if (s?.sort_by && s.sort_by !== "created_at") throw new C(400, { message: `Sorting by ${s.sort_by} is not supported with checkpoint pagination (from/take); only created_at is` });
|
|
676
676
|
let r = s?.sort_order === "asc" ? "asc" : "desc", { rows: i, limit: a, next: o } = await N(l.where("users.linked_to", "is", null).selectAll("users").select([
|
|
677
677
|
"user_activity.last_login",
|
|
678
678
|
"user_activity.last_ip",
|
|
@@ -846,7 +846,7 @@ function it(e) {
|
|
|
846
846
|
//#region src/flows/create.ts
|
|
847
847
|
function at(e) {
|
|
848
848
|
return async (n, r, i) => {
|
|
849
|
-
let a = i?.importMetadata, o = (/* @__PURE__ */ new Date()).toISOString(), s =
|
|
849
|
+
let a = i?.importMetadata, o = (/* @__PURE__ */ new Date()).toISOString(), s = b.parse({
|
|
850
850
|
id: a?.id ?? `af_${t()}`,
|
|
851
851
|
...r,
|
|
852
852
|
actions: r.actions || [],
|
|
@@ -892,7 +892,7 @@ function ct(e) {
|
|
|
892
892
|
...r,
|
|
893
893
|
actions: F(r.actions, [])
|
|
894
894
|
};
|
|
895
|
-
return
|
|
895
|
+
return b.parse(l(i));
|
|
896
896
|
};
|
|
897
897
|
}
|
|
898
898
|
//#endregion
|
|
@@ -906,7 +906,7 @@ function lt(e) {
|
|
|
906
906
|
...e,
|
|
907
907
|
actions: F(e.actions, [])
|
|
908
908
|
};
|
|
909
|
-
return
|
|
909
|
+
return b.parse(l(t));
|
|
910
910
|
});
|
|
911
911
|
if (!a) return {
|
|
912
912
|
flows: u,
|
|
@@ -935,7 +935,7 @@ function ut(e) {
|
|
|
935
935
|
let { numUpdatedRows: a } = await e.updateTable("flows").set(i).where("id", "=", n).where("tenant_id", "=", t).executeTakeFirst();
|
|
936
936
|
if (a === 0n) return null;
|
|
937
937
|
let o = await e.selectFrom("flows").selectAll().where("id", "=", n).where("tenant_id", "=", t).executeTakeFirst();
|
|
938
|
-
return o ?
|
|
938
|
+
return o ? b.parse({
|
|
939
939
|
...o,
|
|
940
940
|
actions: o.actions ? JSON.parse(o.actions) : []
|
|
941
941
|
}) : null;
|
|
@@ -998,7 +998,7 @@ function ht(e) {
|
|
|
998
998
|
await e.insertInto("tenants").values(s).execute();
|
|
999
999
|
} catch (e) {
|
|
1000
1000
|
let t = e?.message ?? "";
|
|
1001
|
-
throw t.includes("UNIQUE constraint failed") || t.includes("Duplicate entry") || t.includes("duplicate key") || t.includes("AlreadyExists") || e?.code === "SQLITE_CONSTRAINT" || e?.code === "SQLITE_CONSTRAINT_UNIQUE" || e?.code === "SQLITE_CONSTRAINT_PRIMARYKEY" || e?.code === "ER_DUP_ENTRY" || e?.code === "23505" ? new
|
|
1001
|
+
throw t.includes("UNIQUE constraint failed") || t.includes("Duplicate entry") || t.includes("duplicate key") || t.includes("AlreadyExists") || e?.code === "SQLITE_CONSTRAINT" || e?.code === "SQLITE_CONSTRAINT_UNIQUE" || e?.code === "SQLITE_CONSTRAINT_PRIMARYKEY" || e?.code === "ER_DUP_ENTRY" || e?.code === "23505" ? new C(409, { message: `Tenant with ID '${o.id}' already exists` }) : e;
|
|
1002
1002
|
}
|
|
1003
1003
|
return o;
|
|
1004
1004
|
};
|
|
@@ -1154,7 +1154,7 @@ function Et(e) {
|
|
|
1154
1154
|
return async (t, n = {}) => {
|
|
1155
1155
|
let { page: r = 0, per_page: i = 50, include_totals: a = !1, sort: s, q: c, from_date: l, to_date: u } = n, d = e.selectFrom("logs").where("logs.tenant_id", "=", t);
|
|
1156
1156
|
if (c) {
|
|
1157
|
-
let t =
|
|
1157
|
+
let t = S(c, Tt);
|
|
1158
1158
|
t && (d = D(e, d, t, [
|
|
1159
1159
|
"user_id",
|
|
1160
1160
|
"ip",
|
|
@@ -1162,7 +1162,7 @@ function Et(e) {
|
|
|
1162
1162
|
], ["description"]));
|
|
1163
1163
|
}
|
|
1164
1164
|
if (typeof l == "number" && Number.isFinite(l) && (d = d.where("logs.date", ">=", (/* @__PURE__ */ new Date(Math.floor(l) * 1e3)).toISOString())), typeof u == "number" && Number.isFinite(u) && (d = d.where("logs.date", "<=", (/* @__PURE__ */ new Date(Math.floor(u) * 1e3 + 999)).toISOString())), M(n)) {
|
|
1165
|
-
if (s?.sort_by && s.sort_by !== "date") throw new
|
|
1165
|
+
if (s?.sort_by && s.sort_by !== "date") throw new C(400, { message: `Sorting by ${s.sort_by} is not supported with checkpoint pagination (from/take); only date is` });
|
|
1166
1166
|
let e = s?.sort_order === "asc" ? "asc" : "desc", { rows: t, limit: r, next: i } = await N(d.selectAll(), n, {
|
|
1167
1167
|
sortColumn: "date",
|
|
1168
1168
|
sortOrder: e,
|
|
@@ -1826,7 +1826,7 @@ function on(e) {
|
|
|
1826
1826
|
}
|
|
1827
1827
|
function sn(e) {
|
|
1828
1828
|
return async (t, n) => {
|
|
1829
|
-
let r = e.selectFrom("clients").where("clients.tenant_id", "=", t), i =
|
|
1829
|
+
let r = e.selectFrom("clients").where("clients.tenant_id", "=", t), i = new Set(["owner_user_id", "registration_type"]);
|
|
1830
1830
|
if (n?.q) {
|
|
1831
1831
|
let e = n.q.trim().match(/^([a-zA-Z_][a-zA-Z0-9_]*):"?([^"]*)"?$/);
|
|
1832
1832
|
if (e && i.has(e[1]) && e[2]) {
|
|
@@ -1997,7 +1997,7 @@ function hn(e) {
|
|
|
1997
1997
|
let i = await e.selectFrom("clients").where("clients.tenant_id", "=", t).where("clients.client_id", "=", r).select("connections").executeTakeFirst();
|
|
1998
1998
|
if (!i) return !1;
|
|
1999
1999
|
let a = JSON.parse(i.connections || "[]"), o = a.filter((e) => e !== n);
|
|
2000
|
-
return o.length === a.length
|
|
2000
|
+
return o.length === a.length ? !0 : (await e.updateTable("clients").set({
|
|
2001
2001
|
connections: JSON.stringify(o),
|
|
2002
2002
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
2003
2003
|
}).where("clients.tenant_id", "=", t).where("clients.client_id", "=", r).executeTakeFirst()).numUpdatedRows > 0;
|
|
@@ -2053,8 +2053,8 @@ function vn(e) {
|
|
|
2053
2053
|
audience: r.audience,
|
|
2054
2054
|
scope: r.scope ? JSON.parse(r.scope) : [],
|
|
2055
2055
|
organization_usage: r.organization_usage,
|
|
2056
|
-
allow_any_organization: r.allow_any_organization
|
|
2057
|
-
is_system: r.is_system
|
|
2056
|
+
allow_any_organization: r.allow_any_organization === void 0 ? !1 : !!r.allow_any_organization,
|
|
2057
|
+
is_system: r.is_system === void 0 ? !1 : !!r.is_system,
|
|
2058
2058
|
subject_type: r.subject_type,
|
|
2059
2059
|
authorization_details_types: r.authorization_details_types ? JSON.parse(r.authorization_details_types) : [],
|
|
2060
2060
|
created_at: r.created_at,
|
|
@@ -2193,7 +2193,7 @@ function En(e) {
|
|
|
2193
2193
|
} catch {
|
|
2194
2194
|
return;
|
|
2195
2195
|
}
|
|
2196
|
-
return
|
|
2196
|
+
return te(t) ? t : void 0;
|
|
2197
2197
|
}
|
|
2198
2198
|
function R(e) {
|
|
2199
2199
|
return {
|
|
@@ -2784,7 +2784,7 @@ function hr(e) {
|
|
|
2784
2784
|
state_data: i.state_data,
|
|
2785
2785
|
failure_reason: i.failure_reason
|
|
2786
2786
|
}), ["auth_strategy"]);
|
|
2787
|
-
return f.authParams = typeof c == "string" && c.length > 0 ? JSON.parse(c) : {},
|
|
2787
|
+
return f.authParams = typeof c == "string" && c.length > 0 ? JSON.parse(c) : {}, ne.parse(f);
|
|
2788
2788
|
};
|
|
2789
2789
|
}
|
|
2790
2790
|
//#endregion
|
|
@@ -3171,11 +3171,11 @@ function Jr(e) {
|
|
|
3171
3171
|
last_exchanged_at_ts: l === void 0 ? void 0 : s(l),
|
|
3172
3172
|
revoked_at_ts: u === void 0 ? void 0 : s(u),
|
|
3173
3173
|
rotated_at_ts: d === void 0 ? void 0 : s(d)
|
|
3174
|
-
}, _ = i?.loginSessionBump, v = _ ? s(_.expires_at) : null,
|
|
3174
|
+
}, _ = i?.loginSessionBump, v = _ ? s(_.expires_at) : null, y = await e.updateTable("refresh_tokens").set(g).where("tenant_id", "=", t).where("refresh_tokens.id", "=", n).executeTakeFirst();
|
|
3175
3175
|
return _?.login_id && v && v > 0 && await e.updateTable("login_sessions").set({
|
|
3176
3176
|
expires_at_ts: v,
|
|
3177
3177
|
updated_at_ts: Date.now()
|
|
3178
|
-
}).where("tenant_id", "=", t).where("id", "=", _.login_id).where("expires_at_ts", "<", v).execute().catch(() => {}), (
|
|
3178
|
+
}).where("tenant_id", "=", t).where("id", "=", _.login_id).where("expires_at_ts", "<", v).execute().catch(() => {}), (y?.numUpdatedRows ?? 0n) > 0n;
|
|
3179
3179
|
};
|
|
3180
3180
|
}
|
|
3181
3181
|
//#endregion
|
|
@@ -3280,7 +3280,7 @@ function Qr(e) {
|
|
|
3280
3280
|
//#region src/forms/create.ts
|
|
3281
3281
|
function $r(e) {
|
|
3282
3282
|
return async (n, r, i) => {
|
|
3283
|
-
let a = i?.importMetadata, o = (/* @__PURE__ */ new Date()).toISOString(), s =
|
|
3283
|
+
let a = i?.importMetadata, o = (/* @__PURE__ */ new Date()).toISOString(), s = x.parse({
|
|
3284
3284
|
id: a?.id ?? t(),
|
|
3285
3285
|
...r,
|
|
3286
3286
|
created_at: a?.created_at ?? o,
|
|
@@ -3292,7 +3292,7 @@ function $r(e) {
|
|
|
3292
3292
|
start: JSON.stringify(s.start || {}),
|
|
3293
3293
|
ending: JSON.stringify(s.ending || {}),
|
|
3294
3294
|
tenant_id: n
|
|
3295
|
-
}).execute(),
|
|
3295
|
+
}).execute(), x.parse(s);
|
|
3296
3296
|
};
|
|
3297
3297
|
}
|
|
3298
3298
|
//#endregion
|
|
@@ -3312,7 +3312,7 @@ function ei(e) {
|
|
|
3312
3312
|
if (typeof t.ending == "string") try {
|
|
3313
3313
|
t.ending = JSON.parse(t.ending);
|
|
3314
3314
|
} catch {}
|
|
3315
|
-
return
|
|
3315
|
+
return x.parse(l(t));
|
|
3316
3316
|
});
|
|
3317
3317
|
if (!a) return {
|
|
3318
3318
|
forms: u,
|
|
@@ -3353,7 +3353,7 @@ function ni(e) {
|
|
|
3353
3353
|
if (typeof i.ending == "string") try {
|
|
3354
3354
|
i.ending = JSON.parse(i.ending);
|
|
3355
3355
|
} catch {}
|
|
3356
|
-
return
|
|
3356
|
+
return x.parse(l(i));
|
|
3357
3357
|
};
|
|
3358
3358
|
}
|
|
3359
3359
|
//#endregion
|
|
@@ -3393,7 +3393,7 @@ function ai(e) {
|
|
|
3393
3393
|
id: i?.id ?? n.id ?? Ce(),
|
|
3394
3394
|
created_at: o,
|
|
3395
3395
|
updated_at: s
|
|
3396
|
-
}, u =
|
|
3396
|
+
}, u = oe.parse(c), { verificationKey: d, scopes: f, options: p, skip_consent_for_verifiable_first_party_clients: m, allow_offline_access: h, is_system: g, metadata: _, ...v } = u, y = {
|
|
3397
3397
|
...v,
|
|
3398
3398
|
tenant_id: t,
|
|
3399
3399
|
scopes: f ? JSON.stringify(f) : "[]",
|
|
@@ -3406,7 +3406,7 @@ function ai(e) {
|
|
|
3406
3406
|
created_at: o,
|
|
3407
3407
|
updated_at: s
|
|
3408
3408
|
};
|
|
3409
|
-
return await e.insertInto("resource_servers").values(
|
|
3409
|
+
return await e.insertInto("resource_servers").values(y).execute(), l(u);
|
|
3410
3410
|
};
|
|
3411
3411
|
}
|
|
3412
3412
|
//#endregion
|
|
@@ -3682,7 +3682,7 @@ function xi(e) {
|
|
|
3682
3682
|
return async (n, r) => {
|
|
3683
3683
|
let i = (/* @__PURE__ */ new Date()).toISOString(), a = r.scope ?? [], o = r.audience ?? "", s = await e.selectFrom("grants").where("tenant_id", "=", n).where("user_id", "=", r.user_id).where("client_id", "=", r.clientID).where("audience", "=", o).selectAll().executeTakeFirst();
|
|
3684
3684
|
if (s) {
|
|
3685
|
-
let t = s.scope ? JSON.parse(s.scope) : [], r = Array.from(
|
|
3685
|
+
let t = s.scope ? JSON.parse(s.scope) : [], r = Array.from(new Set([...t, ...a]));
|
|
3686
3686
|
return await e.updateTable("grants").set({
|
|
3687
3687
|
scope: JSON.stringify(r),
|
|
3688
3688
|
updated_at: i
|
|
@@ -3969,7 +3969,7 @@ function Ri(e) {
|
|
|
3969
3969
|
try {
|
|
3970
3970
|
await e.insertInto("organizations").values(o).execute();
|
|
3971
3971
|
} catch (e) {
|
|
3972
|
-
throw e.code === "SQLITE_CONSTRAINT_UNIQUE" || e.code === "ER_DUP_ENTRY" || e.message.includes("AlreadyExists") ? new
|
|
3972
|
+
throw e.code === "SQLITE_CONSTRAINT_UNIQUE" || e.code === "ER_DUP_ENTRY" || e.message.includes("AlreadyExists") ? new C(409, { message: "Organization already exists" }) : e;
|
|
3973
3973
|
}
|
|
3974
3974
|
return {
|
|
3975
3975
|
...n,
|
|
@@ -4000,7 +4000,7 @@ function Bi(e) {
|
|
|
4000
4000
|
return async (t, n) => {
|
|
4001
4001
|
let r = e.selectFrom("organizations").where("tenant_id", "=", t);
|
|
4002
4002
|
if (n?.q) {
|
|
4003
|
-
let t =
|
|
4003
|
+
let t = S(n.q, B);
|
|
4004
4004
|
t && (r = D(e, r, t, B));
|
|
4005
4005
|
}
|
|
4006
4006
|
if (M(n)) {
|
|
@@ -4037,7 +4037,7 @@ function Bi(e) {
|
|
|
4037
4037
|
if (n?.include_totals) {
|
|
4038
4038
|
let r = e.selectFrom("organizations").where("tenant_id", "=", t);
|
|
4039
4039
|
if (n?.q) {
|
|
4040
|
-
let t =
|
|
4040
|
+
let t = S(n.q, B);
|
|
4041
4041
|
t && (r = D(e, r, t, B));
|
|
4042
4042
|
}
|
|
4043
4043
|
let i = await r.select(f`count(*)`.as("count")).executeTakeFirst();
|
|
@@ -4170,7 +4170,7 @@ function Gi(e) {
|
|
|
4170
4170
|
try {
|
|
4171
4171
|
await e.insertInto("user_organizations").values(s).execute();
|
|
4172
4172
|
} catch (e) {
|
|
4173
|
-
throw e.code === "SQLITE_CONSTRAINT_UNIQUE" || e.code === "ER_DUP_ENTRY" ? new
|
|
4173
|
+
throw e.code === "SQLITE_CONSTRAINT_UNIQUE" || e.code === "ER_DUP_ENTRY" ? new C(409, { message: "User is already a member of this organization" }) : e;
|
|
4174
4174
|
}
|
|
4175
4175
|
return { ...s };
|
|
4176
4176
|
};
|
|
@@ -4332,7 +4332,7 @@ function Qi(e) {
|
|
|
4332
4332
|
try {
|
|
4333
4333
|
await e.insertInto("invites").values(l).execute();
|
|
4334
4334
|
} catch (e) {
|
|
4335
|
-
throw e.code === "SQLITE_CONSTRAINT_UNIQUE" || e.code === "ER_DUP_ENTRY" || e.message.includes("AlreadyExists") ? new
|
|
4335
|
+
throw e.code === "SQLITE_CONSTRAINT_UNIQUE" || e.code === "ER_DUP_ENTRY" || e.message.includes("AlreadyExists") ? new C(409, { message: "Invite already exists" }) : e;
|
|
4336
4336
|
}
|
|
4337
4337
|
return {
|
|
4338
4338
|
id: a,
|
|
@@ -4407,7 +4407,7 @@ function ta(e) {
|
|
|
4407
4407
|
function na(e) {
|
|
4408
4408
|
return async (t, n, r) => {
|
|
4409
4409
|
let i = {};
|
|
4410
|
-
return r.inviter !== void 0 && (i.inviter = JSON.stringify(r.inviter)), r.invitee !== void 0 && (i.invitee = JSON.stringify(r.invitee)), r.client_id !== void 0 && (i.client_id = r.client_id), r.connection_id !== void 0 && (i.connection_id = r.connection_id), r.app_metadata !== void 0 && (i.app_metadata = JSON.stringify(r.app_metadata)), r.user_metadata !== void 0 && (i.user_metadata = JSON.stringify(r.user_metadata)), r.roles !== void 0 && (i.roles = JSON.stringify(r.roles)), r.ttl_sec !== void 0 && (i.ttl_sec = r.ttl_sec, i.expires_at = new Date(Date.now() + r.ttl_sec * 1e3).toISOString()), r.send_invitation_email !== void 0 && (i.send_invitation_email = +!!r.send_invitation_email), Object.keys(i).length === 0
|
|
4410
|
+
return r.inviter !== void 0 && (i.inviter = JSON.stringify(r.inviter)), r.invitee !== void 0 && (i.invitee = JSON.stringify(r.invitee)), r.client_id !== void 0 && (i.client_id = r.client_id), r.connection_id !== void 0 && (i.connection_id = r.connection_id), r.app_metadata !== void 0 && (i.app_metadata = JSON.stringify(r.app_metadata)), r.user_metadata !== void 0 && (i.user_metadata = JSON.stringify(r.user_metadata)), r.roles !== void 0 && (i.roles = JSON.stringify(r.roles)), r.ttl_sec !== void 0 && (i.ttl_sec = r.ttl_sec, i.expires_at = new Date(Date.now() + r.ttl_sec * 1e3).toISOString()), r.send_invitation_email !== void 0 && (i.send_invitation_email = +!!r.send_invitation_email), Object.keys(i).length === 0 ? !0 : (await e.updateTable("invites").set(i).where("tenant_id", "=", t).where("id", "=", n).executeTakeFirst()).numUpdatedRows > 0n;
|
|
4411
4411
|
};
|
|
4412
4412
|
}
|
|
4413
4413
|
//#endregion
|
|
@@ -5074,7 +5074,7 @@ function G(e) {
|
|
|
5074
5074
|
return {
|
|
5075
5075
|
id: e.id,
|
|
5076
5076
|
name: e.name,
|
|
5077
|
-
provider:
|
|
5077
|
+
provider: ie.parse(e.provider),
|
|
5078
5078
|
connection: e.connection,
|
|
5079
5079
|
enabled: e.enabled === 1,
|
|
5080
5080
|
credentials: JSON.parse(e.credentials),
|
|
@@ -5131,7 +5131,7 @@ function K(e) {
|
|
|
5131
5131
|
function Ba(e) {
|
|
5132
5132
|
if (!e) return { path: "/*" };
|
|
5133
5133
|
try {
|
|
5134
|
-
let t = JSON.parse(e), n =
|
|
5134
|
+
let t = JSON.parse(e), n = re.safeParse(t);
|
|
5135
5135
|
if (n.success) return n.data;
|
|
5136
5136
|
} catch {}
|
|
5137
5137
|
return { path: "/*" };
|
|
@@ -5143,7 +5143,7 @@ function Va(e) {
|
|
|
5143
5143
|
if (!Array.isArray(t)) return [];
|
|
5144
5144
|
let n = [];
|
|
5145
5145
|
for (let e of t) {
|
|
5146
|
-
let t =
|
|
5146
|
+
let t = ee.safeParse(e);
|
|
5147
5147
|
t.success && n.push(t.data);
|
|
5148
5148
|
}
|
|
5149
5149
|
return n;
|
|
@@ -5232,7 +5232,7 @@ function Ua(e) {
|
|
|
5232
5232
|
//#endregion
|
|
5233
5233
|
//#region src/tenantOperations/index.ts
|
|
5234
5234
|
function J(e) {
|
|
5235
|
-
return
|
|
5235
|
+
return fe.parse({
|
|
5236
5236
|
id: e.id,
|
|
5237
5237
|
tenant_id: e.tenant_id,
|
|
5238
5238
|
rollout_id: e.rollout_id,
|
|
@@ -5253,7 +5253,7 @@ function J(e) {
|
|
|
5253
5253
|
function Wa(e) {
|
|
5254
5254
|
return {
|
|
5255
5255
|
async create(n) {
|
|
5256
|
-
let r =
|
|
5256
|
+
let r = de.parse(n), i = (/* @__PURE__ */ new Date()).toISOString(), a = {
|
|
5257
5257
|
id: `op_${t()}`,
|
|
5258
5258
|
tenant_id: r.tenant_id,
|
|
5259
5259
|
rollout_id: r.rollout_id ?? null,
|
|
@@ -5334,7 +5334,7 @@ function $a(e) {
|
|
|
5334
5334
|
return null;
|
|
5335
5335
|
}
|
|
5336
5336
|
function eo(e) {
|
|
5337
|
-
return
|
|
5337
|
+
return ue.parse({
|
|
5338
5338
|
id: e.id,
|
|
5339
5339
|
operation_id: e.operation_id,
|
|
5340
5340
|
step: e.step,
|
|
@@ -5347,7 +5347,7 @@ function eo(e) {
|
|
|
5347
5347
|
function to(e) {
|
|
5348
5348
|
return {
|
|
5349
5349
|
async create(t) {
|
|
5350
|
-
let n =
|
|
5350
|
+
let n = le.parse(t), r = {
|
|
5351
5351
|
id: `evt_${Qa()}`,
|
|
5352
5352
|
operation_id: n.operation_id,
|
|
5353
5353
|
step: n.step,
|
|
@@ -5380,7 +5380,7 @@ function no(e) {
|
|
|
5380
5380
|
}
|
|
5381
5381
|
}
|
|
5382
5382
|
function Z(e) {
|
|
5383
|
-
return
|
|
5383
|
+
return ce.parse({
|
|
5384
5384
|
id: e.id,
|
|
5385
5385
|
kind: e.kind,
|
|
5386
5386
|
status: e.status,
|
|
@@ -5398,7 +5398,7 @@ function Z(e) {
|
|
|
5398
5398
|
function ro(e) {
|
|
5399
5399
|
return {
|
|
5400
5400
|
async create(n) {
|
|
5401
|
-
let r =
|
|
5401
|
+
let r = se.parse(n), i = (/* @__PURE__ */ new Date()).toISOString(), a = {
|
|
5402
5402
|
id: `rol_${t()}`,
|
|
5403
5403
|
kind: r.kind,
|
|
5404
5404
|
status: "pending",
|
|
@@ -5449,7 +5449,7 @@ var io = class {
|
|
|
5449
5449
|
async getMigrations() {
|
|
5450
5450
|
return this.migrations;
|
|
5451
5451
|
}
|
|
5452
|
-
}, ao = /* @__PURE__ */
|
|
5452
|
+
}, ao = /* @__PURE__ */ he({
|
|
5453
5453
|
down: () => lo,
|
|
5454
5454
|
up: () => co
|
|
5455
5455
|
}), oo = [
|
|
@@ -5943,7 +5943,7 @@ function po(...e) {
|
|
|
5943
5943
|
}
|
|
5944
5944
|
//#endregion
|
|
5945
5945
|
//#region migrate/migrations/2026-07-16T15:00:00_codes_expires_at_ts.ts
|
|
5946
|
-
var mo = /* @__PURE__ */
|
|
5946
|
+
var mo = /* @__PURE__ */ he({
|
|
5947
5947
|
down: () => To,
|
|
5948
5948
|
up: () => So
|
|
5949
5949
|
}), ho = 5e4, go = 500;
|
|
@@ -6044,77 +6044,28 @@ async function To(e) {
|
|
|
6044
6044
|
await Co(e, "idx_codes_expires_at_ts", "codes"), await wo(e, "codes", "expires_at_ts");
|
|
6045
6045
|
}
|
|
6046
6046
|
//#endregion
|
|
6047
|
-
//#region migrate/migrations/2026-07-16T16:00:00_restore_unique_phone_provider.ts
|
|
6048
|
-
var Eo = /* @__PURE__ */ C({
|
|
6049
|
-
down: () => Oo,
|
|
6050
|
-
up: () => Do
|
|
6051
|
-
});
|
|
6052
|
-
async function Do(e) {
|
|
6053
|
-
let { rows: t } = await f`
|
|
6054
|
-
SELECT phone_number, provider, tenant_id, COUNT(*) AS cnt
|
|
6055
|
-
FROM users
|
|
6056
|
-
WHERE phone_number IS NOT NULL
|
|
6057
|
-
GROUP BY phone_number, provider, tenant_id
|
|
6058
|
-
HAVING COUNT(*) > 1
|
|
6059
|
-
`.execute(e);
|
|
6060
|
-
if (t.length > 0) {
|
|
6061
|
-
$(`Found ${t.length} duplicate (phone_number, provider, tenant_id) group(s) – cleaning up…`);
|
|
6062
|
-
for (let e of t) $(` provider=${e.provider} count=${e.cnt}`);
|
|
6063
|
-
await f`
|
|
6064
|
-
DELETE FROM users
|
|
6065
|
-
WHERE phone_number IS NOT NULL
|
|
6066
|
-
AND (user_id, tenant_id) NOT IN (
|
|
6067
|
-
SELECT keep.user_id, keep.tenant_id FROM (
|
|
6068
|
-
SELECT MIN(user_id) AS user_id, tenant_id
|
|
6069
|
-
FROM users
|
|
6070
|
-
WHERE phone_number IS NOT NULL
|
|
6071
|
-
GROUP BY phone_number, provider, tenant_id
|
|
6072
|
-
) AS keep
|
|
6073
|
-
)
|
|
6074
|
-
AND (phone_number, provider, tenant_id) IN (
|
|
6075
|
-
SELECT dupes.phone_number, dupes.provider, dupes.tenant_id FROM (
|
|
6076
|
-
SELECT phone_number, provider, tenant_id
|
|
6077
|
-
FROM users
|
|
6078
|
-
WHERE phone_number IS NOT NULL
|
|
6079
|
-
GROUP BY phone_number, provider, tenant_id
|
|
6080
|
-
HAVING COUNT(*) > 1
|
|
6081
|
-
) AS dupes
|
|
6082
|
-
)
|
|
6083
|
-
`.execute(e), $("Duplicate rows removed.");
|
|
6084
|
-
}
|
|
6085
|
-
await e.schema.createIndex("unique_phone_provider").on("users").unique().columns([
|
|
6086
|
-
"phone_number",
|
|
6087
|
-
"provider",
|
|
6088
|
-
"tenant_id"
|
|
6089
|
-
]).execute();
|
|
6090
|
-
}
|
|
6091
|
-
async function Oo(e) {
|
|
6092
|
-
await e.schema.dropIndex("unique_phone_provider").execute();
|
|
6093
|
-
}
|
|
6094
|
-
//#endregion
|
|
6095
6047
|
//#region migrate/migrations/index.ts
|
|
6096
|
-
var
|
|
6048
|
+
var Eo = {
|
|
6097
6049
|
"2026-07-16T14:00:00_baseline": ao,
|
|
6098
|
-
"2026-07-16T15:00:00_codes_expires_at_ts": mo
|
|
6099
|
-
"2026-07-16T16:00:00_restore_unique_phone_provider": Eo
|
|
6050
|
+
"2026-07-16T15:00:00_codes_expires_at_ts": mo
|
|
6100
6051
|
};
|
|
6101
6052
|
//#endregion
|
|
6102
6053
|
//#region migrate/migrate.ts
|
|
6103
|
-
async function
|
|
6054
|
+
async function Do(e, t = !1) {
|
|
6104
6055
|
fo(t), t && console.log("migrating...");
|
|
6105
|
-
let { error: n, results: r } = await new
|
|
6056
|
+
let { error: n, results: r } = await new pe({
|
|
6106
6057
|
db: e,
|
|
6107
|
-
provider: new io(
|
|
6058
|
+
provider: new io(Eo)
|
|
6108
6059
|
}).migrateToLatest();
|
|
6109
6060
|
if (r?.forEach((e) => {
|
|
6110
6061
|
e.status === "Success" ? t && console.log(`migration "${e.migrationName}" was executed successfully`) : e.status === "Error" && console.error(`failed to execute migration "${e.migrationName}"`);
|
|
6111
6062
|
}), n) throw console.error("failed to migrate"), console.error(n), n;
|
|
6112
6063
|
}
|
|
6113
|
-
async function
|
|
6064
|
+
async function Oo(e, t = !1) {
|
|
6114
6065
|
fo(t), t && console.log("migrating...");
|
|
6115
|
-
let { error: n, results: r } = await new
|
|
6066
|
+
let { error: n, results: r } = await new pe({
|
|
6116
6067
|
db: e,
|
|
6117
|
-
provider: new io(
|
|
6068
|
+
provider: new io(Eo)
|
|
6118
6069
|
}).migrateDown();
|
|
6119
6070
|
if (r?.forEach((e) => {
|
|
6120
6071
|
e.status === "Success" ? t && console.log(`migration "${e.migrationName}" was reverted successfully`) : e.status === "Error" && console.error(`failed to execute migration "${e.migrationName}"`);
|
|
@@ -6122,7 +6073,7 @@ async function jo(e, t = !1) {
|
|
|
6122
6073
|
}
|
|
6123
6074
|
//#endregion
|
|
6124
6075
|
//#region src/index.ts
|
|
6125
|
-
function
|
|
6076
|
+
function ko(e, t = { useTransactions: !0 }) {
|
|
6126
6077
|
let n = {
|
|
6127
6078
|
actions: Ne(e),
|
|
6128
6079
|
actionExecutions: Le(e),
|
|
@@ -6176,7 +6127,7 @@ function Mo(e, t = { useTransactions: !0 }) {
|
|
|
6176
6127
|
analytics: ya(e),
|
|
6177
6128
|
outbox: La(e),
|
|
6178
6129
|
async transaction(r) {
|
|
6179
|
-
return t.useTransactions === !1 ? r(n) : e.transaction().execute(async (e) => r(
|
|
6130
|
+
return t.useTransactions === !1 ? r(n) : e.transaction().execute(async (e) => r(ko(e, {
|
|
6180
6131
|
...t,
|
|
6181
6132
|
useTransactions: !1
|
|
6182
6133
|
})));
|
|
@@ -6185,4 +6136,4 @@ function Mo(e, t = { useTransactions: !0 }) {
|
|
|
6185
6136
|
return n;
|
|
6186
6137
|
}
|
|
6187
6138
|
//#endregion
|
|
6188
|
-
export { Ua as createProxyDataAdapter, q as createProxyRoutesAdapter,
|
|
6139
|
+
export { Ua as createProxyDataAdapter, q as createProxyRoutesAdapter, ko as default, Oo as migrateDown, Do as migrateToLatest };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as baseline from "./2026-07-16T14:00:00_baseline";
|
|
2
2
|
import * as codesExpiresAtTs from "./2026-07-16T15:00:00_codes_expires_at_ts";
|
|
3
|
-
import * as restoreUniquePhoneProvider from "./2026-07-16T16:00:00_restore_unique_phone_provider";
|
|
4
3
|
/**
|
|
5
4
|
* Kysely runs these in key order and refuses to start if an already-executed
|
|
6
5
|
* migration sorts after a pending one, so the keys must sort in execution
|
|
@@ -19,6 +18,5 @@ import * as restoreUniquePhoneProvider from "./2026-07-16T16:00:00_restore_uniqu
|
|
|
19
18
|
declare const _default: {
|
|
20
19
|
"2026-07-16T14:00:00_baseline": typeof baseline;
|
|
21
20
|
"2026-07-16T15:00:00_codes_expires_at_ts": typeof codesExpiresAtTs;
|
|
22
|
-
"2026-07-16T16:00:00_restore_unique_phone_provider": typeof restoreUniquePhoneProvider;
|
|
23
21
|
};
|
|
24
22
|
export default _default;
|