@authhero/drizzle 1.11.0 → 1.12.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/dist/drizzle-adapter.mjs
CHANGED
|
@@ -807,7 +807,13 @@ var Re = Object.defineProperty, ze = (e, t) => {
|
|
|
807
807
|
e.tenant_id,
|
|
808
808
|
e.prompt,
|
|
809
809
|
e.language
|
|
810
|
-
] })]), ct = w("
|
|
810
|
+
] })]), ct = w("prompt_partials", {
|
|
811
|
+
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => O.id, { onDelete: "cascade" }),
|
|
812
|
+
prompt: T("prompt", { length: 64 }).notNull(),
|
|
813
|
+
body: T("body").notNull(),
|
|
814
|
+
created_at_ts: S("created_at_ts").notNull(),
|
|
815
|
+
updated_at_ts: S("updated_at_ts").notNull()
|
|
816
|
+
}, (e) => [C({ columns: [e.tenant_id, e.prompt] })]), lt = w("authentication_methods", {
|
|
811
817
|
id: T("id", { length: 26 }).primaryKey(),
|
|
812
818
|
tenant_id: T("tenant_id", { length: 191 }).notNull().references(() => O.id, { onDelete: "cascade" }),
|
|
813
819
|
user_id: T("user_id", { length: 255 }).notNull(),
|
|
@@ -889,7 +895,7 @@ var Re = Object.defineProperty, ze = (e, t) => {
|
|
|
889
895
|
handlers: T("handlers", { length: 16384 }).notNull().default("[]"),
|
|
890
896
|
created_at: T("created_at", { length: 35 }).notNull(),
|
|
891
897
|
updated_at: T("updated_at", { length: 35 }).notNull()
|
|
892
|
-
}, (e) => [x("proxy_routes_tenant_id_idx").on(e.tenant_id), x("proxy_routes_custom_domain_id_idx").on(e.custom_domain_id)]),
|
|
898
|
+
}, (e) => [x("proxy_routes_tenant_id_idx").on(e.tenant_id), x("proxy_routes_custom_domain_id_idx").on(e.custom_domain_id)]), ut = w("scim_configurations", {
|
|
893
899
|
connection_id: T("connection_id", { length: 255 }).notNull(),
|
|
894
900
|
tenant_id: T("tenant_id", { length: 255 }).notNull(),
|
|
895
901
|
user_id_attribute: T("user_id_attribute", { length: 255 }).notNull().default("externalId"),
|
|
@@ -909,7 +915,7 @@ var Re = Object.defineProperty, ze = (e, t) => {
|
|
|
909
915
|
C({ columns: [e.tenant_id, e.token_id] }),
|
|
910
916
|
x("scim_tokens_tenant_connection_idx").on(e.tenant_id, e.connection_id),
|
|
911
917
|
re("scim_tokens_tenant_hash_idx").on(e.tenant_id, e.token_hash)
|
|
912
|
-
]),
|
|
918
|
+
]), dt = w("scim_external_ids", {
|
|
913
919
|
tenant_id: T("tenant_id", { length: 255 }).notNull(),
|
|
914
920
|
connection_id: T("connection_id", { length: 255 }).notNull(),
|
|
915
921
|
external_id: T("external_id", { length: 255 }).notNull(),
|
|
@@ -919,7 +925,7 @@ var Re = Object.defineProperty, ze = (e, t) => {
|
|
|
919
925
|
e.tenant_id,
|
|
920
926
|
e.connection_id,
|
|
921
927
|
e.user_id
|
|
922
|
-
] }), re("scim_external_ids_connection_external_idx").on(e.tenant_id, e.connection_id, e.external_id)]),
|
|
928
|
+
] }), re("scim_external_ids_connection_external_idx").on(e.tenant_id, e.connection_id, e.external_id)]), ft = w("token_exchange_profiles", {
|
|
923
929
|
id: T("id", { length: 64 }).primaryKey(),
|
|
924
930
|
tenant_id: T("tenant_id", { length: 255 }).notNull(),
|
|
925
931
|
name: T("name", { length: 255 }).notNull(),
|
|
@@ -929,12 +935,12 @@ var Re = Object.defineProperty, ze = (e, t) => {
|
|
|
929
935
|
jwt_verification: T("jwt_verification"),
|
|
930
936
|
created_at: T("created_at", { length: 35 }).notNull(),
|
|
931
937
|
updated_at: T("updated_at", { length: 35 }).notNull()
|
|
932
|
-
}, (e) => [re("token_exchange_profiles_tenant_subject_token_type_idx").on(e.tenant_id, e.subject_token_type)]),
|
|
938
|
+
}, (e) => [re("token_exchange_profiles_tenant_subject_token_type_idx").on(e.tenant_id, e.subject_token_type)]), pt = /* @__PURE__ */ ze({
|
|
933
939
|
actionExecutions: () => Ve,
|
|
934
940
|
actionVersions: () => k,
|
|
935
941
|
actions: () => Be,
|
|
936
942
|
authenticationCodes: () => Ue,
|
|
937
|
-
authenticationMethods: () =>
|
|
943
|
+
authenticationMethods: () => lt,
|
|
938
944
|
branding: () => Xe,
|
|
939
945
|
clientGrants: () => R,
|
|
940
946
|
clientRegistrationTokens: () => L,
|
|
@@ -959,20 +965,21 @@ var Re = Object.defineProperty, ze = (e, t) => {
|
|
|
959
965
|
otps: () => We,
|
|
960
966
|
outboxEvents: () => J,
|
|
961
967
|
passwords: () => j,
|
|
968
|
+
promptPartials: () => ct,
|
|
962
969
|
promptSettings: () => tt,
|
|
963
970
|
proxyRoutes: () => Y,
|
|
964
971
|
refreshTokens: () => N,
|
|
965
972
|
resourceServers: () => K,
|
|
966
973
|
rolePermissions: () => W,
|
|
967
974
|
roles: () => U,
|
|
968
|
-
scimConfigurations: () =>
|
|
969
|
-
scimExternalIds: () =>
|
|
975
|
+
scimConfigurations: () => ut,
|
|
976
|
+
scimExternalIds: () => dt,
|
|
970
977
|
scimTokens: () => X,
|
|
971
978
|
sessions: () => M,
|
|
972
979
|
tenants: () => O,
|
|
973
980
|
themes: () => Qe,
|
|
974
981
|
tickets: () => Ge,
|
|
975
|
-
tokenExchangeProfiles: () =>
|
|
982
|
+
tokenExchangeProfiles: () => ft,
|
|
976
983
|
universalLoginTemplates: () => Ze,
|
|
977
984
|
userActivity: () => He,
|
|
978
985
|
userOrganizations: () => H,
|
|
@@ -991,14 +998,14 @@ function Z(e, t) {
|
|
|
991
998
|
}
|
|
992
999
|
return e;
|
|
993
1000
|
}
|
|
994
|
-
function
|
|
1001
|
+
function mt(e, t = "", n = {}) {
|
|
995
1002
|
for (let r in e) if (Object.prototype.hasOwnProperty.call(e, r)) {
|
|
996
1003
|
let i = t ? `${t}_${r}` : r, a = e[r];
|
|
997
|
-
typeof a == "object" && a && !Array.isArray(a) ?
|
|
1004
|
+
typeof a == "object" && a && !Array.isArray(a) ? mt(a, i, n) : typeof a == "boolean" ? n[i] = +!!a : n[i] = a;
|
|
998
1005
|
}
|
|
999
1006
|
return n;
|
|
1000
1007
|
}
|
|
1001
|
-
function
|
|
1008
|
+
function ht(e, t) {
|
|
1002
1009
|
let n = {};
|
|
1003
1010
|
for (let [r, i] of Object.entries(e)) {
|
|
1004
1011
|
let e = t.find((e) => r.startsWith(`${e}_`));
|
|
@@ -1015,13 +1022,13 @@ function mt(e, t) {
|
|
|
1015
1022
|
}
|
|
1016
1023
|
//#endregion
|
|
1017
1024
|
//#region src/helpers/filter.ts
|
|
1018
|
-
function
|
|
1025
|
+
function gt(e) {
|
|
1019
1026
|
return typeof e == "object" && !!e && "coalesce" in e && "defaultValue" in e;
|
|
1020
1027
|
}
|
|
1021
|
-
function
|
|
1028
|
+
function _t(e) {
|
|
1022
1029
|
return y`coalesce(${e.coalesce}, ${e.defaultValue})`;
|
|
1023
1030
|
}
|
|
1024
|
-
function
|
|
1031
|
+
function vt(n, r, i, l = []) {
|
|
1025
1032
|
let ee = u(n, te) ? o(n) : n, b = new Set(l), ne = (e) => {
|
|
1026
1033
|
let t = Number(e);
|
|
1027
1034
|
return Number.isFinite(t) ? t : e;
|
|
@@ -1034,7 +1041,7 @@ function _t(n, r, i, l = []) {
|
|
|
1034
1041
|
let [, r, i] = n;
|
|
1035
1042
|
if (!r || !i) return null;
|
|
1036
1043
|
let o = r.trim(), s = Ie(i.replace(/^"(.*)"$/, "$1").trim()), c = ee[o];
|
|
1037
|
-
return
|
|
1044
|
+
return gt(c) ? a(_t(c), ne(s)) : u(c, e) ? b.has(o) ? p(c, `%${s}%`) : a(c, s) : null;
|
|
1038
1045
|
}).filter((e) => e !== null);
|
|
1039
1046
|
return r.length === 0 ? null : r.length === 1 ? r[0] : t(...r) ?? null;
|
|
1040
1047
|
}).filter((e) => e !== null);
|
|
@@ -1057,12 +1064,12 @@ function _t(n, r, i, l = []) {
|
|
|
1057
1064
|
};
|
|
1058
1065
|
}), C = [];
|
|
1059
1066
|
for (let { key: t, value: n, isNegation: r, isExistsQuery: o, operator: l } of S) if (t) {
|
|
1060
|
-
let i = ee[t], v =
|
|
1067
|
+
let i = ee[t], v = gt(i), te = v ? i.coalesce : u(i, e) ? i : void 0, x = v ? ne(n) : n;
|
|
1061
1068
|
if (!te) {
|
|
1062
1069
|
o ? C.push(r ? y`${y.identifier(t)} IS NULL` : y`${y.identifier(t)} IS NOT NULL`) : C.push(y`${y.identifier(t)} ${y.raw(r ? "!=" : l ?? "=")} ${n}`);
|
|
1063
1070
|
continue;
|
|
1064
1071
|
}
|
|
1065
|
-
let S = v ?
|
|
1072
|
+
let S = v ? _t(i) : y`${te}`;
|
|
1066
1073
|
if (o) C.push(r ? f(te) : d(te));
|
|
1067
1074
|
else if (b.has(t) && l === "=") C.push(r ? _(te, `%${n}%`) : p(te, `%${n}%`));
|
|
1068
1075
|
else if (r) switch (l) {
|
|
@@ -1111,11 +1118,11 @@ function _t(n, r, i, l = []) {
|
|
|
1111
1118
|
}
|
|
1112
1119
|
//#endregion
|
|
1113
1120
|
//#region src/adapters/actions.ts
|
|
1114
|
-
function
|
|
1121
|
+
function yt(e) {
|
|
1115
1122
|
let t = Z(e);
|
|
1116
1123
|
return Array.isArray(t) ? t : [];
|
|
1117
1124
|
}
|
|
1118
|
-
function
|
|
1125
|
+
function bt(e) {
|
|
1119
1126
|
let { created_at_ts: t, updated_at_ts: n, deployed_at_ts: r, secrets: i, dependencies: a, supported_triggers: o, is_system: s, inherit: c, tenant_id: l, runtime: u, status: d, ...f } = e;
|
|
1120
1127
|
return {
|
|
1121
1128
|
...f,
|
|
@@ -1132,7 +1139,7 @@ function yt(e) {
|
|
|
1132
1139
|
updated_at: new Date(Number(n)).toISOString()
|
|
1133
1140
|
};
|
|
1134
1141
|
}
|
|
1135
|
-
function
|
|
1142
|
+
function xt(e) {
|
|
1136
1143
|
return {
|
|
1137
1144
|
async create(t, n) {
|
|
1138
1145
|
let r = Date.now(), i = `act_${b()}`;
|
|
@@ -1168,12 +1175,12 @@ function bt(e) {
|
|
|
1168
1175
|
},
|
|
1169
1176
|
async get(n, r) {
|
|
1170
1177
|
let i = await e.select().from(Be).where(t(a(Be.tenant_id, n), a(Be.id, r))).get();
|
|
1171
|
-
return i ?
|
|
1178
|
+
return i ? bt(i) : null;
|
|
1172
1179
|
},
|
|
1173
1180
|
async list(o, s = {}) {
|
|
1174
1181
|
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s, p = [a(Be.tenant_id, o)];
|
|
1175
1182
|
if (f) {
|
|
1176
|
-
let e =
|
|
1183
|
+
let e = vt(Be, f, ["name"]);
|
|
1177
1184
|
e && p.push(e);
|
|
1178
1185
|
}
|
|
1179
1186
|
let m = t(...p), h = e.select().from(Be).where(m).$dynamic();
|
|
@@ -1181,7 +1188,7 @@ function bt(e) {
|
|
|
1181
1188
|
let e = Be[d.sort_by];
|
|
1182
1189
|
e && (h = h.orderBy(d.sort_order === "desc" ? i(e) : n(e)));
|
|
1183
1190
|
}
|
|
1184
|
-
let g = (await h.offset(c * l).limit(l)).map(
|
|
1191
|
+
let g = (await h.offset(c * l).limit(l)).map(bt);
|
|
1185
1192
|
if (!u) return {
|
|
1186
1193
|
actions: g,
|
|
1187
1194
|
start: 0,
|
|
@@ -1199,7 +1206,7 @@ function bt(e) {
|
|
|
1199
1206
|
async update(n, r, i) {
|
|
1200
1207
|
let o = { updated_at_ts: Date.now() };
|
|
1201
1208
|
if (i.name !== void 0 && (o.name = i.name), i.code !== void 0 && (o.code = i.code), i.runtime !== void 0 && (o.runtime = i.runtime), i.secrets !== void 0) {
|
|
1202
|
-
let s = await e.select({ secrets: Be.secrets }).from(Be).where(t(a(Be.tenant_id, n), a(Be.id, r))).get(), c = new Map(
|
|
1209
|
+
let s = await e.select({ secrets: Be.secrets }).from(Be).where(t(a(Be.tenant_id, n), a(Be.id, r))).get(), c = new Map(yt(s?.secrets).map((e) => [e.name, e])), l = i.secrets.map((e) => e.value === void 0 ? {
|
|
1203
1210
|
name: e.name,
|
|
1204
1211
|
value: c.get(e.name)?.value
|
|
1205
1212
|
} : e);
|
|
@@ -1218,8 +1225,8 @@ function bt(e) {
|
|
|
1218
1225
|
}
|
|
1219
1226
|
//#endregion
|
|
1220
1227
|
//#region src/adapters/actionExecutions.ts
|
|
1221
|
-
var
|
|
1222
|
-
function
|
|
1228
|
+
var St = 500;
|
|
1229
|
+
function Ct(e) {
|
|
1223
1230
|
return {
|
|
1224
1231
|
async create(t, n) {
|
|
1225
1232
|
let r = Date.now();
|
|
@@ -1261,8 +1268,8 @@ function St(e) {
|
|
|
1261
1268
|
if (Number.isNaN(n)) throw Error(`Invalid olderThan date: ${t}`);
|
|
1262
1269
|
let r = 0;
|
|
1263
1270
|
for (;;) {
|
|
1264
|
-
let t = await e.delete(Ve).where(y`rowid IN (SELECT rowid FROM ${Ve} WHERE ${Ve.created_at_ts} < ${n} LIMIT ${
|
|
1265
|
-
if (r += t.length, t.length <
|
|
1271
|
+
let t = await e.delete(Ve).where(y`rowid IN (SELECT rowid FROM ${Ve} WHERE ${Ve.created_at_ts} < ${n} LIMIT ${St})`).returning({ id: Ve.id });
|
|
1272
|
+
if (r += t.length, t.length < St) break;
|
|
1266
1273
|
}
|
|
1267
1274
|
return r;
|
|
1268
1275
|
}
|
|
@@ -1270,12 +1277,12 @@ function St(e) {
|
|
|
1270
1277
|
}
|
|
1271
1278
|
//#endregion
|
|
1272
1279
|
//#region src/adapters/atomic.ts
|
|
1273
|
-
function
|
|
1280
|
+
function wt(e) {
|
|
1274
1281
|
let t = e;
|
|
1275
1282
|
return typeof t == "object" && !!t && "batch" in t && typeof t.batch == "function";
|
|
1276
1283
|
}
|
|
1277
|
-
async function
|
|
1278
|
-
if (
|
|
1284
|
+
async function Tt(e, t) {
|
|
1285
|
+
if (wt(e)) return e.batch(t);
|
|
1279
1286
|
await e.run(y`BEGIN`);
|
|
1280
1287
|
try {
|
|
1281
1288
|
let n = [];
|
|
@@ -1292,7 +1299,7 @@ async function wt(e, t) {
|
|
|
1292
1299
|
}
|
|
1293
1300
|
//#endregion
|
|
1294
1301
|
//#region src/adapters/actionVersions.ts
|
|
1295
|
-
function
|
|
1302
|
+
function Et(e) {
|
|
1296
1303
|
let { created_at_ts: t, updated_at_ts: n, secrets: r, dependencies: i, supported_triggers: a, deployed: o, runtime: s, ...c } = e;
|
|
1297
1304
|
return {
|
|
1298
1305
|
...c,
|
|
@@ -1305,7 +1312,7 @@ function Tt(e) {
|
|
|
1305
1312
|
updated_at: new Date(Number(n)).toISOString()
|
|
1306
1313
|
};
|
|
1307
1314
|
}
|
|
1308
|
-
function
|
|
1315
|
+
function Dt(e) {
|
|
1309
1316
|
return {
|
|
1310
1317
|
async create(n, r) {
|
|
1311
1318
|
let o = Date.now(), s = `ver_${b()}`, c = r.deployed !== !1, l = ((await e.select({ number: k.number }).from(k).where(t(a(k.tenant_id, n), a(k.action_id, r.action_id))).orderBy(i(k.number)).limit(1).get())?.number ?? 0) + 1, u = e.insert(k).values({
|
|
@@ -1322,7 +1329,7 @@ function Et(e) {
|
|
|
1322
1329
|
created_at_ts: o,
|
|
1323
1330
|
updated_at_ts: o
|
|
1324
1331
|
});
|
|
1325
|
-
return await
|
|
1332
|
+
return await Tt(e, c ? [e.update(k).set({
|
|
1326
1333
|
deployed: 0,
|
|
1327
1334
|
updated_at_ts: o
|
|
1328
1335
|
}).where(t(a(k.tenant_id, n), a(k.action_id, r.action_id), a(k.deployed, 1))), u] : [u]), {
|
|
@@ -1342,10 +1349,10 @@ function Et(e) {
|
|
|
1342
1349
|
},
|
|
1343
1350
|
async get(n, r, i) {
|
|
1344
1351
|
let o = await e.select().from(k).where(t(a(k.tenant_id, n), a(k.action_id, r), a(k.id, i))).get();
|
|
1345
|
-
return o ?
|
|
1352
|
+
return o ? Et(o) : null;
|
|
1346
1353
|
},
|
|
1347
1354
|
async list(n, o, s = {}) {
|
|
1348
|
-
let { page: c = 0, per_page: l = 50, include_totals: u = !1 } = s, d = t(a(k.tenant_id, n), a(k.action_id, o)), f = (await e.select().from(k).where(d).orderBy(i(k.number)).offset(c * l).limit(l)).map(
|
|
1355
|
+
let { page: c = 0, per_page: l = 50, include_totals: u = !1 } = s, d = t(a(k.tenant_id, n), a(k.action_id, o)), f = (await e.select().from(k).where(d).orderBy(i(k.number)).offset(c * l).limit(l)).map(Et);
|
|
1349
1356
|
if (!u) return {
|
|
1350
1357
|
versions: f,
|
|
1351
1358
|
start: 0,
|
|
@@ -1367,10 +1374,10 @@ function Et(e) {
|
|
|
1367
1374
|
}
|
|
1368
1375
|
//#endregion
|
|
1369
1376
|
//#region src/adapters/branding.ts
|
|
1370
|
-
function
|
|
1377
|
+
function Ot(e) {
|
|
1371
1378
|
return e === "dark" || e === "light" || e === "auto";
|
|
1372
1379
|
}
|
|
1373
|
-
function
|
|
1380
|
+
function kt(e) {
|
|
1374
1381
|
return {
|
|
1375
1382
|
async get(t) {
|
|
1376
1383
|
let n = await e.select().from(Xe).where(a(Xe.tenant_id, t)).get();
|
|
@@ -1388,7 +1395,7 @@ function Ot(e) {
|
|
|
1388
1395
|
}
|
|
1389
1396
|
},
|
|
1390
1397
|
font: u ? { url: u } : void 0,
|
|
1391
|
-
dark_mode:
|
|
1398
|
+
dark_mode: Ot(d) ? d : void 0
|
|
1392
1399
|
});
|
|
1393
1400
|
},
|
|
1394
1401
|
async set(t, n) {
|
|
@@ -1414,18 +1421,18 @@ function Ot(e) {
|
|
|
1414
1421
|
}
|
|
1415
1422
|
//#endregion
|
|
1416
1423
|
//#region src/helpers/paginate.ts
|
|
1417
|
-
function
|
|
1424
|
+
function At(e) {
|
|
1418
1425
|
return e?.from !== void 0 || e?.take !== void 0;
|
|
1419
1426
|
}
|
|
1420
|
-
function
|
|
1427
|
+
function jt(e) {
|
|
1421
1428
|
let t = e?.take, n = typeof t == "number" && Number.isFinite(t) ? Math.floor(t) : NaN;
|
|
1422
1429
|
return n >= 1 ? n : 50;
|
|
1423
1430
|
}
|
|
1424
|
-
function
|
|
1431
|
+
function Mt(e) {
|
|
1425
1432
|
let t = e.sortOrder === "asc" ? n : i;
|
|
1426
1433
|
return [t(e.sortColumn), t(e.idColumn)];
|
|
1427
1434
|
}
|
|
1428
|
-
function
|
|
1435
|
+
function Nt(e, t) {
|
|
1429
1436
|
let n = e?.from ? ge(e.from) : null;
|
|
1430
1437
|
if (!n) return;
|
|
1431
1438
|
if (n.k !== t.sortKey) throw new Le(400, { message: "The `from` cursor was issued under a different sort and cannot be used with this request" });
|
|
@@ -1433,7 +1440,7 @@ function Mt(e, t) {
|
|
|
1433
1440
|
let r = t.sortOrder === "asc" ? y.raw(">") : y.raw("<");
|
|
1434
1441
|
return y`(${t.sortColumn}, ${t.idColumn}) ${r} (${n.s}, ${n.i})`;
|
|
1435
1442
|
}
|
|
1436
|
-
function
|
|
1443
|
+
function Pt(e, t, n, r = "id", i) {
|
|
1437
1444
|
let a = e.length > t, o = a ? e.slice(0, t) : e, s, c = o[o.length - 1];
|
|
1438
1445
|
if (a && c) {
|
|
1439
1446
|
let e = c[n];
|
|
@@ -1450,7 +1457,7 @@ function Nt(e, t, n, r = "id", i) {
|
|
|
1450
1457
|
}
|
|
1451
1458
|
//#endregion
|
|
1452
1459
|
//#region src/adapters/clients.ts
|
|
1453
|
-
var
|
|
1460
|
+
var Ft = [
|
|
1454
1461
|
"global",
|
|
1455
1462
|
"is_first_party",
|
|
1456
1463
|
"oidc_conformant",
|
|
@@ -1462,7 +1469,7 @@ var Pt = [
|
|
|
1462
1469
|
"require_pushed_authorization_requests",
|
|
1463
1470
|
"require_proof_of_possession",
|
|
1464
1471
|
"hide_sign_up_disabled_error"
|
|
1465
|
-
],
|
|
1472
|
+
], It = [
|
|
1466
1473
|
"callbacks",
|
|
1467
1474
|
"allowed_origins",
|
|
1468
1475
|
"web_origins",
|
|
@@ -1471,7 +1478,7 @@ var Pt = [
|
|
|
1471
1478
|
"allowed_logout_urls",
|
|
1472
1479
|
"grant_types",
|
|
1473
1480
|
"signing_keys"
|
|
1474
|
-
],
|
|
1481
|
+
], Lt = [
|
|
1475
1482
|
"session_transfer",
|
|
1476
1483
|
"oidc_logout",
|
|
1477
1484
|
"jwt_configuration",
|
|
@@ -1488,21 +1495,21 @@ var Pt = [
|
|
|
1488
1495
|
"registration_metadata",
|
|
1489
1496
|
"token_exchange"
|
|
1490
1497
|
];
|
|
1491
|
-
function
|
|
1498
|
+
function Rt(e) {
|
|
1492
1499
|
let { tenant_id: t, connections: n, ...r } = e, i = { ...r };
|
|
1493
|
-
for (let e of
|
|
1494
|
-
for (let e of
|
|
1495
|
-
for (let e of
|
|
1500
|
+
for (let e of Ft) i[e] = !!r[e];
|
|
1501
|
+
for (let e of It) i[e] = Z(r[e], []);
|
|
1502
|
+
for (let e of Lt) i[e] = Z(r[e], {});
|
|
1496
1503
|
return i.connections = Z(n, []), D(i);
|
|
1497
1504
|
}
|
|
1498
|
-
function
|
|
1505
|
+
function zt(e) {
|
|
1499
1506
|
let t = { ...e };
|
|
1500
|
-
ie(e,
|
|
1501
|
-
for (let n of
|
|
1502
|
-
for (let n of
|
|
1507
|
+
ie(e, Ft, t);
|
|
1508
|
+
for (let n of It) e[n] !== void 0 && (t[n] = JSON.stringify(e[n] || []));
|
|
1509
|
+
for (let n of Lt) e[n] !== void 0 && (t[n] = JSON.stringify(e[n] || {}));
|
|
1503
1510
|
return e.connections !== void 0 && (t.connections = JSON.stringify(e.connections || [])), ce(t);
|
|
1504
1511
|
}
|
|
1505
|
-
function
|
|
1512
|
+
function Bt(e) {
|
|
1506
1513
|
return {
|
|
1507
1514
|
async create(t, n) {
|
|
1508
1515
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
@@ -1526,12 +1533,12 @@ function zt(e) {
|
|
|
1526
1533
|
created_at: r,
|
|
1527
1534
|
updated_at: r
|
|
1528
1535
|
};
|
|
1529
|
-
for (let e of
|
|
1536
|
+
for (let e of Ft) i[e] = n[e] ?? !1;
|
|
1530
1537
|
i.oidc_conformant = n.oidc_conformant ?? !0, i.auth0_conformant = n.auth0_conformant ?? !0, i.sso_disabled = n.sso_disabled ?? !1;
|
|
1531
|
-
for (let e of
|
|
1532
|
-
for (let e of
|
|
1538
|
+
for (let e of It) i[e] = n[e] || [];
|
|
1539
|
+
for (let e of Lt) i[e] = n[e] || {};
|
|
1533
1540
|
i.connections = n.connections || [];
|
|
1534
|
-
let a =
|
|
1541
|
+
let a = zt(i);
|
|
1535
1542
|
try {
|
|
1536
1543
|
await e.insert(I).values({
|
|
1537
1544
|
...a,
|
|
@@ -1540,37 +1547,37 @@ function zt(e) {
|
|
|
1540
1547
|
} catch (e) {
|
|
1541
1548
|
throw e?.message?.includes("UNIQUE constraint failed") || e?.message?.includes("duplicate key") ? new Le(409, { message: "Client already exists" }) : e;
|
|
1542
1549
|
}
|
|
1543
|
-
return
|
|
1550
|
+
return Rt({
|
|
1544
1551
|
...a,
|
|
1545
1552
|
tenant_id: t
|
|
1546
1553
|
});
|
|
1547
1554
|
},
|
|
1548
1555
|
async get(n, r) {
|
|
1549
1556
|
let i = await e.select().from(I).where(t(a(I.tenant_id, n), a(I.client_id, r))).get();
|
|
1550
|
-
return i ?
|
|
1557
|
+
return i ? Rt(i) : null;
|
|
1551
1558
|
},
|
|
1552
1559
|
async getByClientId(t) {
|
|
1553
1560
|
let n = await e.select().from(I).where(a(I.client_id, t)).get();
|
|
1554
1561
|
return n ? {
|
|
1555
|
-
...
|
|
1562
|
+
...Rt(n),
|
|
1556
1563
|
tenant_id: n.tenant_id
|
|
1557
1564
|
} : null;
|
|
1558
1565
|
},
|
|
1559
1566
|
async update(n, r, i) {
|
|
1560
|
-
let o =
|
|
1567
|
+
let o = zt({
|
|
1561
1568
|
...i,
|
|
1562
1569
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1563
1570
|
});
|
|
1564
1571
|
return delete o.client_id, delete o.tenant_id, await e.update(I).set(o).where(t(a(I.tenant_id, n), a(I.client_id, r))), !0;
|
|
1565
1572
|
},
|
|
1566
1573
|
async list(o, s) {
|
|
1567
|
-
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ?
|
|
1568
|
-
if (
|
|
1574
|
+
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ? vt(I, f, ["name", "client_id"]) : void 0, m = p ? t(a(I.tenant_id, o), p) : a(I.tenant_id, o);
|
|
1575
|
+
if (At(s)) {
|
|
1569
1576
|
let n = {
|
|
1570
1577
|
sortColumn: I.created_at,
|
|
1571
1578
|
idColumn: I.client_id,
|
|
1572
1579
|
sortOrder: "desc"
|
|
1573
|
-
}, r =
|
|
1580
|
+
}, r = Nt(s, n), i = jt(s), { rows: a, next: o } = Pt(await e.select().from(I).where(r ? t(m, r) : m).orderBy(...Mt(n)).limit(i + 1), i, "created_at", "client_id"), c = a.map(Rt);
|
|
1574
1581
|
return {
|
|
1575
1582
|
clients: c,
|
|
1576
1583
|
totals: {
|
|
@@ -1586,7 +1593,7 @@ function zt(e) {
|
|
|
1586
1593
|
let e = I[d.sort_by];
|
|
1587
1594
|
e && (h = h.orderBy(d.sort_order === "desc" ? i(e) : n(e)));
|
|
1588
1595
|
}
|
|
1589
|
-
let g = (await h.offset(c * l).limit(l)).map(
|
|
1596
|
+
let g = (await h.offset(c * l).limit(l)).map(Rt);
|
|
1590
1597
|
if (!u) return { clients: g };
|
|
1591
1598
|
let [_] = await e.select({ count: r() }).from(I).where(m);
|
|
1592
1599
|
return {
|
|
@@ -1606,7 +1613,7 @@ function zt(e) {
|
|
|
1606
1613
|
}
|
|
1607
1614
|
//#endregion
|
|
1608
1615
|
//#region src/adapters/clientConnections.ts
|
|
1609
|
-
function
|
|
1616
|
+
function Vt(e) {
|
|
1610
1617
|
let { tenant_id: t, is_system: n, options: r, metadata: i, ...a } = e;
|
|
1611
1618
|
return D({
|
|
1612
1619
|
...a,
|
|
@@ -1615,14 +1622,14 @@ function Bt(e) {
|
|
|
1615
1622
|
is_system: n ? !0 : void 0
|
|
1616
1623
|
});
|
|
1617
1624
|
}
|
|
1618
|
-
function
|
|
1625
|
+
function Ht(e) {
|
|
1619
1626
|
return {
|
|
1620
1627
|
async listByClient(n, r) {
|
|
1621
1628
|
let i = await e.select({ connections: I.connections }).from(I).where(t(a(I.tenant_id, n), a(I.client_id, r))).get();
|
|
1622
1629
|
if (!i) return [];
|
|
1623
1630
|
let o = Z(i.connections, []) || [];
|
|
1624
1631
|
if (o.length === 0) return [];
|
|
1625
|
-
let s = (await e.select().from(B).where(t(a(B.tenant_id, n), l(B.id, o))).all()).map(
|
|
1632
|
+
let s = (await e.select().from(B).where(t(a(B.tenant_id, n), l(B.id, o))).all()).map(Vt);
|
|
1626
1633
|
return o.map((e) => s.find((t) => t.id === e)).filter(Boolean);
|
|
1627
1634
|
},
|
|
1628
1635
|
async updateByClient(n, r, i) {
|
|
@@ -1659,7 +1666,7 @@ function Vt(e) {
|
|
|
1659
1666
|
}
|
|
1660
1667
|
//#endregion
|
|
1661
1668
|
//#region src/adapters/clientGrants.ts
|
|
1662
|
-
function
|
|
1669
|
+
function Ut(e) {
|
|
1663
1670
|
let { tenant_id: t, scope: n, authorization_details_types: r, allow_any_organization: i, is_system: a, ...o } = e;
|
|
1664
1671
|
return D({
|
|
1665
1672
|
...o,
|
|
@@ -1669,7 +1676,7 @@ function Ht(e) {
|
|
|
1669
1676
|
is_system: !!a
|
|
1670
1677
|
});
|
|
1671
1678
|
}
|
|
1672
|
-
function
|
|
1679
|
+
function Wt(e) {
|
|
1673
1680
|
return {
|
|
1674
1681
|
async create(t, n) {
|
|
1675
1682
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
@@ -1686,14 +1693,14 @@ function Ut(e) {
|
|
|
1686
1693
|
created_at: r,
|
|
1687
1694
|
updated_at: r
|
|
1688
1695
|
};
|
|
1689
|
-
return await e.insert(R).values(i),
|
|
1696
|
+
return await e.insert(R).values(i), Ut({
|
|
1690
1697
|
...i,
|
|
1691
1698
|
tenant_id: t
|
|
1692
1699
|
});
|
|
1693
1700
|
},
|
|
1694
1701
|
async get(n, r) {
|
|
1695
1702
|
let i = await e.select().from(R).where(t(a(R.tenant_id, n), a(R.id, r))).get();
|
|
1696
|
-
return i ?
|
|
1703
|
+
return i ? Ut(i) : null;
|
|
1697
1704
|
},
|
|
1698
1705
|
async update(n, r, i) {
|
|
1699
1706
|
let { scope: o, authorization_details_types: s, allow_any_organization: c, is_system: l, ...u } = i, d = {
|
|
@@ -1703,13 +1710,13 @@ function Ut(e) {
|
|
|
1703
1710
|
return o !== void 0 && (d.scope = JSON.stringify(o)), s !== void 0 && (d.authorization_details_types = JSON.stringify(s)), c !== void 0 && (d.allow_any_organization = +!!c), l !== void 0 && (d.is_system = +!!l), (await e.update(R).set(d).where(t(a(R.tenant_id, n), a(R.id, r))).returning()).length > 0;
|
|
1704
1711
|
},
|
|
1705
1712
|
async list(o, s) {
|
|
1706
|
-
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ?
|
|
1707
|
-
if (
|
|
1713
|
+
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ? vt(R, f, ["client_id", "audience"]) : void 0, m = p ? t(a(R.tenant_id, o), p) : a(R.tenant_id, o);
|
|
1714
|
+
if (At(s)) {
|
|
1708
1715
|
let n = {
|
|
1709
1716
|
sortColumn: R.created_at,
|
|
1710
1717
|
idColumn: R.id,
|
|
1711
1718
|
sortOrder: "desc"
|
|
1712
|
-
}, r =
|
|
1719
|
+
}, r = Nt(s, n), i = jt(s), { rows: a, next: o } = Pt(await e.select().from(R).where(r ? t(m, r) : m).orderBy(...Mt(n)).limit(i + 1), i, "created_at"), c = a.map(Ut);
|
|
1713
1720
|
return {
|
|
1714
1721
|
client_grants: c,
|
|
1715
1722
|
start: 0,
|
|
@@ -1723,7 +1730,7 @@ function Ut(e) {
|
|
|
1723
1730
|
let e = R[d.sort_by];
|
|
1724
1731
|
e && (h = h.orderBy(d.sort_order === "desc" ? i(e) : n(e)));
|
|
1725
1732
|
} else h = h.orderBy(i(R.created_at), i(R.id));
|
|
1726
|
-
let g = (await h.offset(c * l).limit(l)).map(
|
|
1733
|
+
let g = (await h.offset(c * l).limit(l)).map(Ut);
|
|
1727
1734
|
if (!u) return { client_grants: g };
|
|
1728
1735
|
let [_] = await e.select({ count: r() }).from(R).where(m);
|
|
1729
1736
|
return {
|
|
@@ -1740,20 +1747,20 @@ function Ut(e) {
|
|
|
1740
1747
|
}
|
|
1741
1748
|
//#endregion
|
|
1742
1749
|
//#region src/adapters/clientRegistrationTokens.ts
|
|
1743
|
-
function
|
|
1750
|
+
function Gt(e) {
|
|
1744
1751
|
if (!e) return;
|
|
1745
1752
|
let t = JSON.parse(e);
|
|
1746
1753
|
return be(t) ? t : void 0;
|
|
1747
1754
|
}
|
|
1748
|
-
function
|
|
1755
|
+
function Kt(e) {
|
|
1749
1756
|
return e == null ? void 0 : new Date(e).toISOString();
|
|
1750
1757
|
}
|
|
1751
|
-
function
|
|
1758
|
+
function qt(e) {
|
|
1752
1759
|
if (!e) return null;
|
|
1753
1760
|
let t = new Date(e);
|
|
1754
1761
|
return isNaN(t.getTime()) ? null : t.getTime();
|
|
1755
1762
|
}
|
|
1756
|
-
function
|
|
1763
|
+
function Jt(e) {
|
|
1757
1764
|
let t = he.parse(e.type);
|
|
1758
1765
|
return {
|
|
1759
1766
|
id: e.id,
|
|
@@ -1761,15 +1768,15 @@ function qt(e) {
|
|
|
1761
1768
|
type: t,
|
|
1762
1769
|
client_id: e.client_id ?? void 0,
|
|
1763
1770
|
sub: e.sub ?? void 0,
|
|
1764
|
-
constraints:
|
|
1771
|
+
constraints: Gt(e.constraints),
|
|
1765
1772
|
single_use: !!e.single_use,
|
|
1766
|
-
expires_at:
|
|
1767
|
-
used_at:
|
|
1768
|
-
revoked_at:
|
|
1773
|
+
expires_at: Kt(e.expires_at_ts),
|
|
1774
|
+
used_at: Kt(e.used_at_ts),
|
|
1775
|
+
revoked_at: Kt(e.revoked_at_ts),
|
|
1769
1776
|
created_at: new Date(e.created_at_ts).toISOString()
|
|
1770
1777
|
};
|
|
1771
1778
|
}
|
|
1772
|
-
function
|
|
1779
|
+
function Yt(e) {
|
|
1773
1780
|
return {
|
|
1774
1781
|
async create(t, n) {
|
|
1775
1782
|
let r = Date.now();
|
|
@@ -1782,7 +1789,7 @@ function Jt(e) {
|
|
|
1782
1789
|
sub: n.sub ?? null,
|
|
1783
1790
|
constraints: n.constraints ? JSON.stringify(n.constraints) : null,
|
|
1784
1791
|
single_use: +!!n.single_use,
|
|
1785
|
-
expires_at_ts:
|
|
1792
|
+
expires_at_ts: qt(n.expires_at),
|
|
1786
1793
|
created_at_ts: r
|
|
1787
1794
|
}), {
|
|
1788
1795
|
id: n.id,
|
|
@@ -1798,23 +1805,23 @@ function Jt(e) {
|
|
|
1798
1805
|
},
|
|
1799
1806
|
async get(n, r) {
|
|
1800
1807
|
let i = await e.select().from(L).where(t(a(L.tenant_id, n), a(L.id, r))).get();
|
|
1801
|
-
return i ?
|
|
1808
|
+
return i ? Jt(i) : null;
|
|
1802
1809
|
},
|
|
1803
1810
|
async getByHash(n, r) {
|
|
1804
1811
|
let i = await e.select().from(L).where(t(a(L.tenant_id, n), a(L.token_hash, r))).get();
|
|
1805
|
-
return i ?
|
|
1812
|
+
return i ? Jt(i) : null;
|
|
1806
1813
|
},
|
|
1807
1814
|
async listByClient(n, r) {
|
|
1808
|
-
return (await e.select().from(L).where(t(a(L.tenant_id, n), a(L.client_id, r))).orderBy(i(L.created_at_ts))).map(
|
|
1815
|
+
return (await e.select().from(L).where(t(a(L.tenant_id, n), a(L.client_id, r))).orderBy(i(L.created_at_ts))).map(Jt);
|
|
1809
1816
|
},
|
|
1810
1817
|
async markUsed(n, r, i) {
|
|
1811
|
-
return (await e.update(L).set({ used_at_ts:
|
|
1818
|
+
return (await e.update(L).set({ used_at_ts: qt(i) }).where(t(a(L.tenant_id, n), a(L.id, r), f(L.used_at_ts))).returning()).length > 0;
|
|
1812
1819
|
},
|
|
1813
1820
|
async revoke(n, r, i) {
|
|
1814
|
-
return (await e.update(L).set({ revoked_at_ts:
|
|
1821
|
+
return (await e.update(L).set({ revoked_at_ts: qt(i) }).where(t(a(L.tenant_id, n), a(L.id, r), f(L.revoked_at_ts))).returning()).length > 0;
|
|
1815
1822
|
},
|
|
1816
1823
|
async revokeByClient(n, r, i) {
|
|
1817
|
-
return (await e.update(L).set({ revoked_at_ts:
|
|
1824
|
+
return (await e.update(L).set({ revoked_at_ts: qt(i) }).where(t(a(L.tenant_id, n), a(L.client_id, r), f(L.revoked_at_ts))).returning()).length;
|
|
1818
1825
|
},
|
|
1819
1826
|
async remove(n, r) {
|
|
1820
1827
|
return (await e.delete(L).where(t(a(L.tenant_id, n), a(L.id, r))).returning()).length > 0;
|
|
@@ -1823,12 +1830,12 @@ function Jt(e) {
|
|
|
1823
1830
|
}
|
|
1824
1831
|
//#endregion
|
|
1825
1832
|
//#region src/adapters/codes.ts
|
|
1826
|
-
var
|
|
1827
|
-
function
|
|
1833
|
+
var Xt = ["code_id", "login_id"], Zt = 500;
|
|
1834
|
+
function Qt(e) {
|
|
1828
1835
|
let { tenant_id: t, ...n } = e;
|
|
1829
1836
|
return D(n);
|
|
1830
1837
|
}
|
|
1831
|
-
function
|
|
1838
|
+
function $t(e) {
|
|
1832
1839
|
return {
|
|
1833
1840
|
async create(t, n) {
|
|
1834
1841
|
let r = {
|
|
@@ -1837,18 +1844,18 @@ function Qt(e) {
|
|
|
1837
1844
|
created_at: n.created_at || (/* @__PURE__ */ new Date()).toISOString(),
|
|
1838
1845
|
expires_at: n.expires_at
|
|
1839
1846
|
};
|
|
1840
|
-
return await e.insert(F).values(r),
|
|
1847
|
+
return await e.insert(F).values(r), Qt(r);
|
|
1841
1848
|
},
|
|
1842
1849
|
async get(n, r, i) {
|
|
1843
1850
|
let o = n ? t(a(F.tenant_id, n), a(F.code_id, r), a(F.code_type, i)) : t(a(F.code_id, r), a(F.code_type, i)), s = await e.select().from(F).where(o).get();
|
|
1844
|
-
return s ?
|
|
1851
|
+
return s ? Qt(s) : null;
|
|
1845
1852
|
},
|
|
1846
1853
|
async list(o, s) {
|
|
1847
1854
|
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = [a(F.tenant_id, o)];
|
|
1848
1855
|
if (f) {
|
|
1849
|
-
let e = Te(f,
|
|
1856
|
+
let e = Te(f, Xt);
|
|
1850
1857
|
if (e) {
|
|
1851
|
-
let t =
|
|
1858
|
+
let t = vt(F, e, Xt);
|
|
1852
1859
|
t && p.push(t);
|
|
1853
1860
|
}
|
|
1854
1861
|
}
|
|
@@ -1857,7 +1864,7 @@ function Qt(e) {
|
|
|
1857
1864
|
let e = F[d.sort_by];
|
|
1858
1865
|
e && (h = h.orderBy(d.sort_order === "desc" ? i(e) : n(e)));
|
|
1859
1866
|
}
|
|
1860
|
-
let g = (await h.offset(c * l).limit(l)).map(
|
|
1867
|
+
let g = (await h.offset(c * l).limit(l)).map(Qt);
|
|
1861
1868
|
if (!u) return { codes: g };
|
|
1862
1869
|
let [_] = await e.select({ count: r() }).from(F).where(m);
|
|
1863
1870
|
return {
|
|
@@ -1879,8 +1886,8 @@ function Qt(e) {
|
|
|
1879
1886
|
async cleanup(t) {
|
|
1880
1887
|
let n = 0;
|
|
1881
1888
|
for (;;) {
|
|
1882
|
-
let r = await e.delete(F).where(y`rowid IN (SELECT rowid FROM ${F} WHERE ${F.expires_at} < ${t} LIMIT ${
|
|
1883
|
-
if (n += r.length, r.length <
|
|
1889
|
+
let r = await e.delete(F).where(y`rowid IN (SELECT rowid FROM ${F} WHERE ${F.expires_at} < ${t} LIMIT ${Zt})`).returning({ code_id: F.code_id });
|
|
1890
|
+
if (n += r.length, r.length < Zt) break;
|
|
1884
1891
|
}
|
|
1885
1892
|
return n;
|
|
1886
1893
|
}
|
|
@@ -1888,10 +1895,10 @@ function Qt(e) {
|
|
|
1888
1895
|
}
|
|
1889
1896
|
//#endregion
|
|
1890
1897
|
//#region src/adapters/connections.ts
|
|
1891
|
-
function
|
|
1898
|
+
function en() {
|
|
1892
1899
|
return `con_${ee("0123456789abcdefghijklmnopqrstuvwxyz", 17)()}`;
|
|
1893
1900
|
}
|
|
1894
|
-
function
|
|
1901
|
+
function tn(e) {
|
|
1895
1902
|
let { tenant_id: t, is_system: n, options: r, metadata: i, ...a } = e;
|
|
1896
1903
|
return D({
|
|
1897
1904
|
...a,
|
|
@@ -1900,11 +1907,11 @@ function en(e) {
|
|
|
1900
1907
|
is_system: n ? !0 : void 0
|
|
1901
1908
|
});
|
|
1902
1909
|
}
|
|
1903
|
-
function
|
|
1910
|
+
function nn(e) {
|
|
1904
1911
|
return {
|
|
1905
1912
|
async create(t, n) {
|
|
1906
1913
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
1907
|
-
id: n.id ||
|
|
1914
|
+
id: n.id || en(),
|
|
1908
1915
|
...n,
|
|
1909
1916
|
tenant_id: t,
|
|
1910
1917
|
options: JSON.stringify(n.options || {}),
|
|
@@ -1918,11 +1925,11 @@ function tn(e) {
|
|
|
1918
1925
|
} catch (e) {
|
|
1919
1926
|
throw e?.message?.includes("UNIQUE constraint failed") || e?.message?.includes("duplicate key") ? new Le(409, { message: "Connection already exists" }) : e;
|
|
1920
1927
|
}
|
|
1921
|
-
return
|
|
1928
|
+
return tn(i);
|
|
1922
1929
|
},
|
|
1923
1930
|
async get(n, r) {
|
|
1924
1931
|
let i = await e.select().from(B).where(t(a(B.tenant_id, n), a(B.id, r))).get();
|
|
1925
|
-
return i ?
|
|
1932
|
+
return i ? tn(i) : null;
|
|
1926
1933
|
},
|
|
1927
1934
|
async update(n, r, i) {
|
|
1928
1935
|
let o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
@@ -1931,15 +1938,15 @@ function tn(e) {
|
|
|
1931
1938
|
async list(o, s) {
|
|
1932
1939
|
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = a(B.tenant_id, o);
|
|
1933
1940
|
if (f) {
|
|
1934
|
-
let e =
|
|
1941
|
+
let e = vt(B, f, ["name"]);
|
|
1935
1942
|
e && (p = t(p, e));
|
|
1936
1943
|
}
|
|
1937
|
-
if (
|
|
1944
|
+
if (At(s)) {
|
|
1938
1945
|
let n = {
|
|
1939
1946
|
sortColumn: B.created_at,
|
|
1940
1947
|
idColumn: B.id,
|
|
1941
1948
|
sortOrder: "desc"
|
|
1942
|
-
}, r =
|
|
1949
|
+
}, r = Nt(s, n), i = jt(s), { rows: a, next: o } = Pt(await e.select().from(B).where(r ? t(p, r) : p).orderBy(...Mt(n)).limit(i + 1), i, "created_at", "id"), c = a.map(tn);
|
|
1943
1950
|
return {
|
|
1944
1951
|
connections: c,
|
|
1945
1952
|
start: 0,
|
|
@@ -1953,7 +1960,7 @@ function tn(e) {
|
|
|
1953
1960
|
let e = B[d.sort_by];
|
|
1954
1961
|
e && (m = m.orderBy(d.sort_order === "desc" ? i(e) : n(e)));
|
|
1955
1962
|
}
|
|
1956
|
-
let h = (await m.offset(c * l).limit(l)).map(
|
|
1963
|
+
let h = (await m.offset(c * l).limit(l)).map(tn);
|
|
1957
1964
|
if (!u) return { connections: h };
|
|
1958
1965
|
let [g] = await e.select({ count: r() }).from(B).where(p);
|
|
1959
1966
|
return {
|
|
@@ -1970,7 +1977,7 @@ function tn(e) {
|
|
|
1970
1977
|
}
|
|
1971
1978
|
//#endregion
|
|
1972
1979
|
//#region src/adapters/customDomains.ts
|
|
1973
|
-
function
|
|
1980
|
+
function rn(e) {
|
|
1974
1981
|
let { tenant_id: t, domain_metadata: n, verification: r, ...i } = e;
|
|
1975
1982
|
return D({
|
|
1976
1983
|
...i,
|
|
@@ -1979,7 +1986,7 @@ function nn(e) {
|
|
|
1979
1986
|
verification: Z(r)
|
|
1980
1987
|
});
|
|
1981
1988
|
}
|
|
1982
|
-
function
|
|
1989
|
+
function an(e) {
|
|
1983
1990
|
return {
|
|
1984
1991
|
async create(t, n) {
|
|
1985
1992
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
@@ -1997,24 +2004,24 @@ function rn(e) {
|
|
|
1997
2004
|
created_at: r,
|
|
1998
2005
|
updated_at: r
|
|
1999
2006
|
};
|
|
2000
|
-
return await e.insert(Ke).values(i),
|
|
2007
|
+
return await e.insert(Ke).values(i), rn({
|
|
2001
2008
|
...i,
|
|
2002
2009
|
tenant_id: t
|
|
2003
2010
|
});
|
|
2004
2011
|
},
|
|
2005
2012
|
async get(n, r) {
|
|
2006
2013
|
let i = await e.select().from(Ke).where(t(a(Ke.tenant_id, n), a(Ke.custom_domain_id, r))).get();
|
|
2007
|
-
return i ?
|
|
2014
|
+
return i ? rn(i) : null;
|
|
2008
2015
|
},
|
|
2009
2016
|
async getByDomain(t) {
|
|
2010
2017
|
let n = await e.select().from(Ke).where(a(Ke.domain, t)).get();
|
|
2011
2018
|
return n ? {
|
|
2012
|
-
...
|
|
2019
|
+
...rn(n),
|
|
2013
2020
|
tenant_id: n.tenant_id
|
|
2014
2021
|
} : null;
|
|
2015
2022
|
},
|
|
2016
2023
|
async list(t) {
|
|
2017
|
-
return (await e.select().from(Ke).where(a(Ke.tenant_id, t)).all()).map(
|
|
2024
|
+
return (await e.select().from(Ke).where(a(Ke.tenant_id, t)).all()).map(rn);
|
|
2018
2025
|
},
|
|
2019
2026
|
async update(n, r, i) {
|
|
2020
2027
|
let o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
@@ -2027,7 +2034,7 @@ function rn(e) {
|
|
|
2027
2034
|
}
|
|
2028
2035
|
//#endregion
|
|
2029
2036
|
//#region src/adapters/customText.ts
|
|
2030
|
-
function
|
|
2037
|
+
function on(e) {
|
|
2031
2038
|
return {
|
|
2032
2039
|
async get(n, r, i) {
|
|
2033
2040
|
let o = await e.select().from(st).where(t(a(st.tenant_id, n), a(st.prompt, r), a(st.language, i))).get();
|
|
@@ -2072,7 +2079,7 @@ function an(e) {
|
|
|
2072
2079
|
}
|
|
2073
2080
|
//#endregion
|
|
2074
2081
|
//#region src/adapters/emailProviders.ts
|
|
2075
|
-
function
|
|
2082
|
+
function sn(e) {
|
|
2076
2083
|
return {
|
|
2077
2084
|
async create(t, n) {
|
|
2078
2085
|
let r = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -2109,7 +2116,7 @@ function on(e) {
|
|
|
2109
2116
|
}
|
|
2110
2117
|
//#endregion
|
|
2111
2118
|
//#region src/adapters/emailTemplates.ts
|
|
2112
|
-
function
|
|
2119
|
+
function cn(e) {
|
|
2113
2120
|
return D({
|
|
2114
2121
|
template: e.template,
|
|
2115
2122
|
body: e.body,
|
|
@@ -2122,14 +2129,14 @@ function sn(e) {
|
|
|
2122
2129
|
urlLifetimeInSeconds: e.url_lifetime_in_seconds ?? void 0
|
|
2123
2130
|
});
|
|
2124
2131
|
}
|
|
2125
|
-
function
|
|
2132
|
+
function ln(e) {
|
|
2126
2133
|
return {
|
|
2127
2134
|
async get(n, r) {
|
|
2128
2135
|
let i = await e.select().from(rt).where(t(a(rt.tenant_id, n), a(rt.template, r))).get();
|
|
2129
|
-
return i ?
|
|
2136
|
+
return i ? cn(i) : null;
|
|
2130
2137
|
},
|
|
2131
2138
|
async list(t) {
|
|
2132
|
-
return (await e.select().from(rt).where(a(rt.tenant_id, t)).all()).map(
|
|
2139
|
+
return (await e.select().from(rt).where(a(rt.tenant_id, t)).all()).map(cn);
|
|
2133
2140
|
},
|
|
2134
2141
|
async create(t, n) {
|
|
2135
2142
|
let r = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -2162,8 +2169,8 @@ function cn(e) {
|
|
|
2162
2169
|
}
|
|
2163
2170
|
//#endregion
|
|
2164
2171
|
//#region src/adapters/flows.ts
|
|
2165
|
-
var
|
|
2166
|
-
function
|
|
2172
|
+
var un = ["id", "name"];
|
|
2173
|
+
function dn(e) {
|
|
2167
2174
|
return {
|
|
2168
2175
|
async create(t, n) {
|
|
2169
2176
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = `af_${b()}`;
|
|
@@ -2198,9 +2205,9 @@ function un(e) {
|
|
|
2198
2205
|
async list(o, s) {
|
|
2199
2206
|
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = [a(et.tenant_id, o)];
|
|
2200
2207
|
if (f) {
|
|
2201
|
-
let e = Te(f,
|
|
2208
|
+
let e = Te(f, un);
|
|
2202
2209
|
if (e) {
|
|
2203
|
-
let t =
|
|
2210
|
+
let t = vt(et, e, []);
|
|
2204
2211
|
t && p.push(t);
|
|
2205
2212
|
}
|
|
2206
2213
|
}
|
|
@@ -2232,12 +2239,12 @@ function un(e) {
|
|
|
2232
2239
|
}
|
|
2233
2240
|
//#endregion
|
|
2234
2241
|
//#region src/adapters/forms.ts
|
|
2235
|
-
var
|
|
2242
|
+
var fn = [
|
|
2236
2243
|
"nodes",
|
|
2237
2244
|
"start",
|
|
2238
2245
|
"ending"
|
|
2239
|
-
],
|
|
2240
|
-
function
|
|
2246
|
+
], pn = ["name"];
|
|
2247
|
+
function mn(e) {
|
|
2241
2248
|
return {
|
|
2242
2249
|
async create(t, n) {
|
|
2243
2250
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = b(), a = {
|
|
@@ -2251,7 +2258,7 @@ function pn(e) {
|
|
|
2251
2258
|
created_at: r,
|
|
2252
2259
|
updated_at: r
|
|
2253
2260
|
};
|
|
2254
|
-
for (let e of
|
|
2261
|
+
for (let e of fn) a[e] = JSON.stringify(n[e] || (e === "nodes" ? [] : {}));
|
|
2255
2262
|
return await e.insert($e).values(a), {
|
|
2256
2263
|
id: i,
|
|
2257
2264
|
...n,
|
|
@@ -2263,20 +2270,20 @@ function pn(e) {
|
|
|
2263
2270
|
let i = await e.select().from($e).where(t(a($e.tenant_id, n), a($e.id, r))).get();
|
|
2264
2271
|
if (!i) return null;
|
|
2265
2272
|
let { tenant_id: o, ...s } = i, c = { ...s };
|
|
2266
|
-
for (let e of
|
|
2273
|
+
for (let e of fn) c[e] = Z(s[e]);
|
|
2267
2274
|
return D(c);
|
|
2268
2275
|
},
|
|
2269
2276
|
async update(n, r, i) {
|
|
2270
2277
|
let o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
2271
|
-
for (let [e, t] of Object.entries(i)) t !== void 0 && (
|
|
2278
|
+
for (let [e, t] of Object.entries(i)) t !== void 0 && (fn.includes(e) ? o[e] = JSON.stringify(t) : o[e] = t);
|
|
2272
2279
|
return (await e.update($e).set(o).where(t(a($e.tenant_id, n), a($e.id, r))).returning()).length > 0;
|
|
2273
2280
|
},
|
|
2274
2281
|
async list(o, s) {
|
|
2275
2282
|
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = [a($e.tenant_id, o)];
|
|
2276
2283
|
if (f) {
|
|
2277
|
-
let e = Te(f,
|
|
2284
|
+
let e = Te(f, pn);
|
|
2278
2285
|
if (e) {
|
|
2279
|
-
let t =
|
|
2286
|
+
let t = vt($e, e, pn);
|
|
2280
2287
|
t && p.push(t);
|
|
2281
2288
|
}
|
|
2282
2289
|
}
|
|
@@ -2287,7 +2294,7 @@ function pn(e) {
|
|
|
2287
2294
|
}
|
|
2288
2295
|
let g = (await h.offset(c * l).limit(l)).map((e) => {
|
|
2289
2296
|
let { tenant_id: t, ...n } = e, r = { ...n };
|
|
2290
|
-
for (let e of
|
|
2297
|
+
for (let e of fn) r[e] = Z(n[e]);
|
|
2291
2298
|
return D(r);
|
|
2292
2299
|
});
|
|
2293
2300
|
if (!u) return { forms: g };
|
|
@@ -2306,7 +2313,7 @@ function pn(e) {
|
|
|
2306
2313
|
}
|
|
2307
2314
|
//#endregion
|
|
2308
2315
|
//#region src/adapters/grants.ts
|
|
2309
|
-
function
|
|
2316
|
+
function hn(e) {
|
|
2310
2317
|
return {
|
|
2311
2318
|
id: e.id,
|
|
2312
2319
|
user_id: e.user_id,
|
|
@@ -2315,17 +2322,17 @@ function mn(e) {
|
|
|
2315
2322
|
scope: Z(e.scope, []) ?? []
|
|
2316
2323
|
};
|
|
2317
2324
|
}
|
|
2318
|
-
var
|
|
2325
|
+
var gn = {
|
|
2319
2326
|
user_id: z.user_id,
|
|
2320
2327
|
client_id: z.client_id,
|
|
2321
2328
|
audience: z.audience,
|
|
2322
2329
|
created_at: z.created_at,
|
|
2323
2330
|
updated_at: z.updated_at
|
|
2324
2331
|
};
|
|
2325
|
-
function gn(e) {
|
|
2326
|
-
return Object.hasOwn(hn, e) ? hn[e] : void 0;
|
|
2327
|
-
}
|
|
2328
2332
|
function _n(e) {
|
|
2333
|
+
return Object.hasOwn(gn, e) ? gn[e] : void 0;
|
|
2334
|
+
}
|
|
2335
|
+
function vn(e) {
|
|
2329
2336
|
return {
|
|
2330
2337
|
async create(n, r) {
|
|
2331
2338
|
let i = (/* @__PURE__ */ new Date()).toISOString(), o = r.scope ?? [], s = r.audience ?? "", c = await e.select().from(z).where(t(a(z.tenant_id, n), a(z.user_id, r.user_id), a(z.client_id, r.clientID), a(z.audience, s))).get();
|
|
@@ -2334,7 +2341,7 @@ function _n(e) {
|
|
|
2334
2341
|
return await e.update(z).set({
|
|
2335
2342
|
scope: JSON.stringify(s),
|
|
2336
2343
|
updated_at: i
|
|
2337
|
-
}).where(t(a(z.tenant_id, n), a(z.id, c.id))),
|
|
2344
|
+
}).where(t(a(z.tenant_id, n), a(z.id, c.id))), hn({
|
|
2338
2345
|
...c,
|
|
2339
2346
|
scope: JSON.stringify(s)
|
|
2340
2347
|
});
|
|
@@ -2359,16 +2366,16 @@ function _n(e) {
|
|
|
2359
2366
|
},
|
|
2360
2367
|
async get(n, r, i, o) {
|
|
2361
2368
|
let s = await e.select().from(z).where(t(a(z.tenant_id, n), a(z.user_id, r), a(z.client_id, i), a(z.audience, o ?? ""))).get();
|
|
2362
|
-
return s ?
|
|
2369
|
+
return s ? hn(s) : null;
|
|
2363
2370
|
},
|
|
2364
2371
|
async list(o, s) {
|
|
2365
|
-
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ?
|
|
2372
|
+
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ? vt(z, f, [
|
|
2366
2373
|
"user_id",
|
|
2367
2374
|
"client_id",
|
|
2368
2375
|
"audience"
|
|
2369
|
-
]) : void 0, m = p ? t(a(z.tenant_id, o), p) : a(z.tenant_id, o), h = e.select().from(z).where(m).$dynamic(), g = d?.sort_by ?
|
|
2376
|
+
]) : void 0, m = p ? t(a(z.tenant_id, o), p) : a(z.tenant_id, o), h = e.select().from(z).where(m).$dynamic(), g = d?.sort_by ? _n(d.sort_by) : void 0;
|
|
2370
2377
|
h = g ? h.orderBy(d?.sort_order === "desc" ? i(g) : n(g)) : h.orderBy(n(z.created_at));
|
|
2371
|
-
let _ = (await h.offset(c * l).limit(l)).map(
|
|
2378
|
+
let _ = (await h.offset(c * l).limit(l)).map(hn);
|
|
2372
2379
|
if (!u) return {
|
|
2373
2380
|
grants: _,
|
|
2374
2381
|
start: 0,
|
|
@@ -2393,11 +2400,11 @@ function _n(e) {
|
|
|
2393
2400
|
}
|
|
2394
2401
|
//#endregion
|
|
2395
2402
|
//#region src/adapters/hookCode.ts
|
|
2396
|
-
var
|
|
2397
|
-
function
|
|
2398
|
-
return `hc_${
|
|
2403
|
+
var yn = ee("0123456789abcdefghijklmnopqrstuvwxyz", 17);
|
|
2404
|
+
function bn() {
|
|
2405
|
+
return `hc_${yn()}`;
|
|
2399
2406
|
}
|
|
2400
|
-
function
|
|
2407
|
+
function xn(e) {
|
|
2401
2408
|
let { created_at_ts: t, updated_at_ts: n, secrets: r, ...i } = e, a = ae({
|
|
2402
2409
|
created_at_ts: t,
|
|
2403
2410
|
updated_at_ts: n
|
|
@@ -2408,25 +2415,25 @@ function bn(e) {
|
|
|
2408
2415
|
secrets: r ? JSON.parse(r) : void 0
|
|
2409
2416
|
};
|
|
2410
2417
|
}
|
|
2411
|
-
function
|
|
2418
|
+
function Sn(e) {
|
|
2412
2419
|
return {
|
|
2413
2420
|
async create(t, n) {
|
|
2414
2421
|
let r = Date.now(), i = {
|
|
2415
|
-
id:
|
|
2422
|
+
id: bn(),
|
|
2416
2423
|
tenant_id: t,
|
|
2417
2424
|
code: n.code,
|
|
2418
2425
|
secrets: n.secrets ? JSON.stringify(n.secrets) : null,
|
|
2419
2426
|
created_at_ts: r,
|
|
2420
2427
|
updated_at_ts: r
|
|
2421
2428
|
};
|
|
2422
|
-
return await e.insert(at).values(i),
|
|
2429
|
+
return await e.insert(at).values(i), xn({
|
|
2423
2430
|
...i,
|
|
2424
2431
|
tenant_id: t
|
|
2425
2432
|
});
|
|
2426
2433
|
},
|
|
2427
2434
|
async get(n, r) {
|
|
2428
2435
|
let i = await e.select().from(at).where(t(a(at.tenant_id, n), a(at.id, r))).get();
|
|
2429
|
-
return i ?
|
|
2436
|
+
return i ? xn(i) : null;
|
|
2430
2437
|
},
|
|
2431
2438
|
async update(n, r, i) {
|
|
2432
2439
|
let o = { updated_at_ts: Date.now() };
|
|
@@ -2439,10 +2446,10 @@ function xn(e) {
|
|
|
2439
2446
|
}
|
|
2440
2447
|
//#endregion
|
|
2441
2448
|
//#region src/adapters/hooks.ts
|
|
2442
|
-
function
|
|
2449
|
+
function Cn() {
|
|
2443
2450
|
return `h_${ee("0123456789abcdefghijklmnopqrstuvwxyz", 17)()}`;
|
|
2444
2451
|
}
|
|
2445
|
-
function
|
|
2452
|
+
function wn(e) {
|
|
2446
2453
|
if (!(typeof e != "string" || !e)) try {
|
|
2447
2454
|
let t = JSON.parse(e);
|
|
2448
2455
|
return t && typeof t == "object" && !Array.isArray(t) ? t : void 0;
|
|
@@ -2450,7 +2457,7 @@ function Cn(e) {
|
|
|
2450
2457
|
return;
|
|
2451
2458
|
}
|
|
2452
2459
|
}
|
|
2453
|
-
function
|
|
2460
|
+
function Tn(e) {
|
|
2454
2461
|
let { tenant_id: t, created_at_ts: n, updated_at_ts: r, metadata: i, ...a } = e, o = ae({
|
|
2455
2462
|
created_at_ts: n,
|
|
2456
2463
|
updated_at_ts: r
|
|
@@ -2459,15 +2466,15 @@ function wn(e) {
|
|
|
2459
2466
|
...a,
|
|
2460
2467
|
enabled: !!a.enabled,
|
|
2461
2468
|
synchronous: !!a.synchronous,
|
|
2462
|
-
metadata:
|
|
2469
|
+
metadata: wn(i),
|
|
2463
2470
|
...o
|
|
2464
2471
|
});
|
|
2465
2472
|
}
|
|
2466
|
-
function
|
|
2473
|
+
function En(e) {
|
|
2467
2474
|
return {
|
|
2468
2475
|
async create(t, n) {
|
|
2469
2476
|
let r = Date.now(), i = {
|
|
2470
|
-
hook_id: n.hook_id ||
|
|
2477
|
+
hook_id: n.hook_id || Cn(),
|
|
2471
2478
|
tenant_id: t,
|
|
2472
2479
|
trigger_id: n.trigger_id,
|
|
2473
2480
|
url: n.url,
|
|
@@ -2483,28 +2490,28 @@ function Tn(e) {
|
|
|
2483
2490
|
created_at_ts: r,
|
|
2484
2491
|
updated_at_ts: r
|
|
2485
2492
|
};
|
|
2486
|
-
return await e.insert(it).values(i),
|
|
2493
|
+
return await e.insert(it).values(i), Tn({
|
|
2487
2494
|
...i,
|
|
2488
2495
|
tenant_id: t
|
|
2489
2496
|
});
|
|
2490
2497
|
},
|
|
2491
2498
|
async get(n, r) {
|
|
2492
2499
|
let i = await e.select().from(it).where(t(a(it.tenant_id, n), a(it.hook_id, r))).get();
|
|
2493
|
-
return i ?
|
|
2500
|
+
return i ? Tn(i) : null;
|
|
2494
2501
|
},
|
|
2495
2502
|
async update(n, r, i) {
|
|
2496
2503
|
let o = { updated_at_ts: Date.now() };
|
|
2497
2504
|
return i.trigger_id !== void 0 && (o.trigger_id = i.trigger_id), i.url !== void 0 && (o.url = i.url), i.enabled !== void 0 && (o.enabled = i.enabled), i.synchronous !== void 0 && (o.synchronous = i.synchronous), i.priority !== void 0 && (o.priority = i.priority), i.form_id !== void 0 && (o.form_id = i.form_id), i.template_id !== void 0 && (o.template_id = i.template_id), i.code_id !== void 0 && (o.code_id = i.code_id), i.page_id !== void 0 && (o.page_id = i.page_id), i.permission_required !== void 0 && (o.permission_required = i.permission_required), i.metadata !== void 0 && (o.metadata = i.metadata === null ? null : JSON.stringify(i.metadata)), (await e.update(it).set(o).where(t(a(it.tenant_id, n), a(it.hook_id, r))).returning()).length > 0;
|
|
2498
2505
|
},
|
|
2499
2506
|
async list(o, s) {
|
|
2500
|
-
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ?
|
|
2507
|
+
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ? vt(it, f, [
|
|
2501
2508
|
"url",
|
|
2502
2509
|
"form_id",
|
|
2503
2510
|
"template_id",
|
|
2504
2511
|
"code_id"
|
|
2505
2512
|
]) : void 0, m = p ? t(a(it.tenant_id, o), p) : a(it.tenant_id, o), h = e.select().from(it).where(m).$dynamic(), g = d?.sort_by ? it[d.sort_by] : void 0;
|
|
2506
2513
|
h = g ? h.orderBy(d?.sort_order === "desc" ? i(g) : n(g)) : h.orderBy(i(it.priority), n(it.created_at_ts));
|
|
2507
|
-
let _ = (await h.offset(c * l).limit(l)).map(
|
|
2514
|
+
let _ = (await h.offset(c * l).limit(l)).map(Tn);
|
|
2508
2515
|
if (!u) return { hooks: _ };
|
|
2509
2516
|
let [v] = await e.select({ count: r() }).from(it).where(m);
|
|
2510
2517
|
return {
|
|
@@ -2521,25 +2528,25 @@ function Tn(e) {
|
|
|
2521
2528
|
}
|
|
2522
2529
|
//#endregion
|
|
2523
2530
|
//#region src/adapters/invites.ts
|
|
2524
|
-
function
|
|
2531
|
+
function Dn() {
|
|
2525
2532
|
return `inv_${ee("0123456789abcdefghijklmnopqrstuvwxyz", 17)()}`;
|
|
2526
2533
|
}
|
|
2527
|
-
var
|
|
2534
|
+
var On = [
|
|
2528
2535
|
"inviter",
|
|
2529
2536
|
"invitee",
|
|
2530
2537
|
"app_metadata",
|
|
2531
2538
|
"user_metadata",
|
|
2532
2539
|
"roles"
|
|
2533
2540
|
];
|
|
2534
|
-
function
|
|
2541
|
+
function kn(e) {
|
|
2535
2542
|
let { tenant_id: t, send_invitation_email: n, ...r } = e, i = { ...r };
|
|
2536
|
-
for (let e of
|
|
2543
|
+
for (let e of On) i[e] = Z(r[e], e === "roles" ? [] : {});
|
|
2537
2544
|
return i.send_invitation_email = !!n, D(i);
|
|
2538
2545
|
}
|
|
2539
|
-
function
|
|
2546
|
+
function An(e) {
|
|
2540
2547
|
return {
|
|
2541
2548
|
async create(t, n) {
|
|
2542
|
-
let r = n.id ||
|
|
2549
|
+
let r = n.id || Dn(), i = n.ttl_sec || 604800, a = /* @__PURE__ */ new Date(), o = new Date(a.getTime() + i * 1e3).toISOString(), s = {
|
|
2543
2550
|
id: r,
|
|
2544
2551
|
tenant_id: t,
|
|
2545
2552
|
organization_id: n.organization_id,
|
|
@@ -2552,24 +2559,24 @@ function kn(e) {
|
|
|
2552
2559
|
created_at: a.toISOString(),
|
|
2553
2560
|
expires_at: o
|
|
2554
2561
|
};
|
|
2555
|
-
for (let e of
|
|
2562
|
+
for (let e of On) n[e] !== void 0 && (s[e] = JSON.stringify(n[e]));
|
|
2556
2563
|
try {
|
|
2557
2564
|
await e.insert(Je).values(s);
|
|
2558
2565
|
} catch (e) {
|
|
2559
2566
|
throw e?.message?.includes("UNIQUE constraint failed") || e?.message?.includes("duplicate key") ? new Le(409, { message: "Invite already exists" }) : e;
|
|
2560
2567
|
}
|
|
2561
|
-
return
|
|
2568
|
+
return kn({
|
|
2562
2569
|
...s,
|
|
2563
2570
|
tenant_id: t
|
|
2564
2571
|
});
|
|
2565
2572
|
},
|
|
2566
2573
|
async get(n, r) {
|
|
2567
2574
|
let i = await e.select().from(Je).where(t(a(Je.tenant_id, n), a(Je.id, r))).get();
|
|
2568
|
-
return i ?
|
|
2575
|
+
return i ? kn(i) : null;
|
|
2569
2576
|
},
|
|
2570
2577
|
async update(n, r, i) {
|
|
2571
2578
|
let o = {};
|
|
2572
|
-
for (let e of
|
|
2579
|
+
for (let e of On) i[e] !== void 0 && (o[e] = JSON.stringify(i[e]));
|
|
2573
2580
|
return i.connection_id !== void 0 && (o.connection_id = i.connection_id), i.ttl_sec !== void 0 && (o.ttl_sec = i.ttl_sec, o.expires_at = new Date(Date.now() + i.ttl_sec * 1e3).toISOString()), (await e.update(Je).set(o).where(t(a(Je.tenant_id, n), a(Je.id, r))).returning()).length > 0;
|
|
2574
2581
|
},
|
|
2575
2582
|
async list(t, o) {
|
|
@@ -2578,7 +2585,7 @@ function kn(e) {
|
|
|
2578
2585
|
let e = Je[u.sort_by];
|
|
2579
2586
|
e && (d = d.orderBy(u.sort_order === "desc" ? i(e) : n(e)));
|
|
2580
2587
|
}
|
|
2581
|
-
let f = (await d.offset(s * c).limit(c)).map(
|
|
2588
|
+
let f = (await d.offset(s * c).limit(c)).map(kn);
|
|
2582
2589
|
if (!l) return { invites: f };
|
|
2583
2590
|
let [p] = await e.select({ count: r() }).from(Je).where(a(Je.tenant_id, t));
|
|
2584
2591
|
return {
|
|
@@ -2595,14 +2602,14 @@ function kn(e) {
|
|
|
2595
2602
|
}
|
|
2596
2603
|
//#endregion
|
|
2597
2604
|
//#region src/adapters/keys.ts
|
|
2598
|
-
var
|
|
2605
|
+
var jn = [
|
|
2599
2606
|
"kid",
|
|
2600
2607
|
"connection",
|
|
2601
2608
|
"fingerprint",
|
|
2602
2609
|
"thumbprint",
|
|
2603
2610
|
"type"
|
|
2604
2611
|
];
|
|
2605
|
-
function
|
|
2612
|
+
function Mn(e) {
|
|
2606
2613
|
return {
|
|
2607
2614
|
async create(t) {
|
|
2608
2615
|
await e.insert(ot).values({
|
|
@@ -2613,9 +2620,9 @@ function jn(e) {
|
|
|
2613
2620
|
async list(a) {
|
|
2614
2621
|
let { page: o = 0, per_page: c = 50, include_totals: l = !1, sort: u, q: d } = a || {}, p = (/* @__PURE__ */ new Date()).toISOString(), m = [v(s(ot.revoked_at, p), f(ot.revoked_at))];
|
|
2615
2622
|
if (d) {
|
|
2616
|
-
let e = Te(d,
|
|
2623
|
+
let e = Te(d, jn);
|
|
2617
2624
|
if (e) {
|
|
2618
|
-
let t =
|
|
2625
|
+
let t = vt(ot, e, jn);
|
|
2619
2626
|
t && m.push(t);
|
|
2620
2627
|
}
|
|
2621
2628
|
}
|
|
@@ -2644,16 +2651,16 @@ function jn(e) {
|
|
|
2644
2651
|
}
|
|
2645
2652
|
//#endregion
|
|
2646
2653
|
//#region src/adapters/loginSessions.ts
|
|
2647
|
-
var
|
|
2648
|
-
function
|
|
2654
|
+
var Nn = "0123456789ABCDEFGHJKMNPQRSTVWXYZ", Pn = 32;
|
|
2655
|
+
function Fn() {
|
|
2649
2656
|
let e = Date.now(), t = "";
|
|
2650
|
-
for (let n = 10; n > 0; n--) t =
|
|
2657
|
+
for (let n = 10; n > 0; n--) t = Nn.charAt(e % Pn) + t, e = Math.floor(e / Pn);
|
|
2651
2658
|
let n = new Uint8Array(16);
|
|
2652
2659
|
crypto.getRandomValues(n);
|
|
2653
|
-
for (let e = 0; e < 16; e++) t +=
|
|
2660
|
+
for (let e = 0; e < 16; e++) t += Nn.charAt(n[e] % Pn);
|
|
2654
2661
|
return t;
|
|
2655
2662
|
}
|
|
2656
|
-
function
|
|
2663
|
+
function In(e) {
|
|
2657
2664
|
let { tenant_id: t, created_at_ts: n, updated_at_ts: r, expires_at_ts: i, state_data: a, auth_params: o, ...s } = e, c = ae({
|
|
2658
2665
|
created_at_ts: n,
|
|
2659
2666
|
updated_at_ts: r,
|
|
@@ -2665,17 +2672,17 @@ function Fn(e) {
|
|
|
2665
2672
|
]), l = {};
|
|
2666
2673
|
for (let [e, t] of Object.entries(s)) t != null && (l[e] = t);
|
|
2667
2674
|
return D({
|
|
2668
|
-
...
|
|
2675
|
+
...ht(l, ["auth_strategy"]),
|
|
2669
2676
|
authParams: typeof o == "string" && o.length > 0 ? JSON.parse(o) : {},
|
|
2670
2677
|
...c,
|
|
2671
2678
|
state_data: Z(a)
|
|
2672
2679
|
});
|
|
2673
2680
|
}
|
|
2674
|
-
function
|
|
2681
|
+
function Ln(e) {
|
|
2675
2682
|
return {
|
|
2676
2683
|
async create(t, n) {
|
|
2677
2684
|
let r = Date.now(), i = {
|
|
2678
|
-
id:
|
|
2685
|
+
id: Fn(),
|
|
2679
2686
|
tenant_id: t,
|
|
2680
2687
|
session_id: n.session_id,
|
|
2681
2688
|
csrf_token: n.csrf_token,
|
|
@@ -2696,14 +2703,14 @@ function In(e) {
|
|
|
2696
2703
|
updated_at_ts: r,
|
|
2697
2704
|
expires_at_ts: n.expires_at ? E(n.expires_at) : r + 1e3 * 60 * 60 * 24
|
|
2698
2705
|
};
|
|
2699
|
-
return await e.insert(P).values(i),
|
|
2706
|
+
return await e.insert(P).values(i), In({
|
|
2700
2707
|
...i,
|
|
2701
2708
|
tenant_id: t
|
|
2702
2709
|
});
|
|
2703
2710
|
},
|
|
2704
2711
|
async get(n, r) {
|
|
2705
2712
|
let i = n ? t(a(P.tenant_id, n), a(P.id, r)) : a(P.id, r), o = await e.select().from(P).where(i).get();
|
|
2706
|
-
return o ?
|
|
2713
|
+
return o ? In(o) : null;
|
|
2707
2714
|
},
|
|
2708
2715
|
async update(n, r, i) {
|
|
2709
2716
|
let o = { updated_at_ts: Date.now() };
|
|
@@ -2723,7 +2730,7 @@ function In(e) {
|
|
|
2723
2730
|
}
|
|
2724
2731
|
//#endregion
|
|
2725
2732
|
//#region src/adapters/logs.ts
|
|
2726
|
-
function
|
|
2733
|
+
function Rn(e) {
|
|
2727
2734
|
let { tenant_id: t, isMobile: n, auth0_client: r, details: i, country_code: a, city_name: o, latitude: s, longitude: c, time_zone: l, continent_code: u, scope: d, ...f } = e, p = {
|
|
2728
2735
|
...f,
|
|
2729
2736
|
isMobile: !!n,
|
|
@@ -2740,7 +2747,7 @@ function Ln(e) {
|
|
|
2740
2747
|
continent_code: u
|
|
2741
2748
|
})), D(p);
|
|
2742
2749
|
}
|
|
2743
|
-
function
|
|
2750
|
+
function zn(e) {
|
|
2744
2751
|
return {
|
|
2745
2752
|
async create(t, n) {
|
|
2746
2753
|
let r = {
|
|
@@ -2766,7 +2773,7 @@ function Rn(e) {
|
|
|
2766
2773
|
hostname: n.hostname,
|
|
2767
2774
|
session_connection: n.session_connection
|
|
2768
2775
|
};
|
|
2769
|
-
return n.auth0_client && (r.auth0_client = JSON.stringify(n.auth0_client)), n.details && (r.details = JSON.stringify(n.details).substring(0, 8192)), n.location_info && (r.country_code = n.location_info.country_code, r.city_name = n.location_info.city_name, r.latitude = n.location_info.latitude, r.longitude = n.location_info.longitude, r.time_zone = n.location_info.time_zone, r.continent_code = n.location_info.continent_code), await e.insert(q).values(r),
|
|
2776
|
+
return n.auth0_client && (r.auth0_client = JSON.stringify(n.auth0_client)), n.details && (r.details = JSON.stringify(n.details).substring(0, 8192)), n.location_info && (r.country_code = n.location_info.country_code, r.city_name = n.location_info.city_name, r.latitude = n.location_info.latitude, r.longitude = n.location_info.longitude, r.time_zone = n.location_info.time_zone, r.continent_code = n.location_info.continent_code), await e.insert(q).values(r), Rn({
|
|
2770
2777
|
...r,
|
|
2771
2778
|
tenant_id: t
|
|
2772
2779
|
});
|
|
@@ -2774,7 +2781,7 @@ function Rn(e) {
|
|
|
2774
2781
|
async list(o, s) {
|
|
2775
2782
|
let { page: l = 0, per_page: u = 50, include_totals: d = !1, sort: f, q: p, from_date: h, to_date: g } = s || {}, _ = [a(q.tenant_id, o)];
|
|
2776
2783
|
if (p) {
|
|
2777
|
-
let e =
|
|
2784
|
+
let e = vt(q, p, [
|
|
2778
2785
|
"user_id",
|
|
2779
2786
|
"ip",
|
|
2780
2787
|
"type",
|
|
@@ -2784,14 +2791,14 @@ function Rn(e) {
|
|
|
2784
2791
|
}
|
|
2785
2792
|
typeof h == "number" && Number.isFinite(h) && _.push(c(q.date, (/* @__PURE__ */ new Date(Math.floor(h) * 1e3)).toISOString())), typeof g == "number" && Number.isFinite(g) && _.push(m(q.date, (/* @__PURE__ */ new Date((Math.floor(g) + 1) * 1e3)).toISOString()));
|
|
2786
2793
|
let v = t(..._);
|
|
2787
|
-
if (
|
|
2794
|
+
if (At(s)) {
|
|
2788
2795
|
if (f?.sort_by && f.sort_by !== "date") throw new Le(400, { message: `Sorting by ${f.sort_by} is not supported with checkpoint pagination (from/take); only date is` });
|
|
2789
2796
|
let n = f?.sort_order === "asc" ? "asc" : "desc", r = {
|
|
2790
2797
|
sortColumn: q.date,
|
|
2791
2798
|
idColumn: q.log_id,
|
|
2792
2799
|
sortOrder: n,
|
|
2793
2800
|
sortKey: `date:${n}`
|
|
2794
|
-
}, i =
|
|
2801
|
+
}, i = Nt(s, r), a = jt(s), { rows: o, next: c } = Pt(await e.select().from(q).where(i ? t(v, i) : v).orderBy(...Mt(r)).limit(a + 1), a, "date", "log_id", r.sortKey), l = o.map(Rn);
|
|
2795
2802
|
return {
|
|
2796
2803
|
logs: l,
|
|
2797
2804
|
start: 0,
|
|
@@ -2805,7 +2812,7 @@ function Rn(e) {
|
|
|
2805
2812
|
let e = q[f.sort_by];
|
|
2806
2813
|
e && (y = y.orderBy(f.sort_order === "desc" ? i(e) : n(e)));
|
|
2807
2814
|
} else y = y.orderBy(i(q.date));
|
|
2808
|
-
let ee = (await y.offset(l * u).limit(u)).map(
|
|
2815
|
+
let ee = (await y.offset(l * u).limit(u)).map(Rn);
|
|
2809
2816
|
if (!d) return { logs: ee };
|
|
2810
2817
|
let [b] = await e.select({ count: r() }).from(q).where(v);
|
|
2811
2818
|
return {
|
|
@@ -2817,22 +2824,22 @@ function Rn(e) {
|
|
|
2817
2824
|
},
|
|
2818
2825
|
async get(n, r) {
|
|
2819
2826
|
let i = await e.select().from(q).where(t(a(q.tenant_id, n), a(q.log_id, r))).get();
|
|
2820
|
-
return i ?
|
|
2827
|
+
return i ? Rn(i) : null;
|
|
2821
2828
|
}
|
|
2822
2829
|
};
|
|
2823
2830
|
}
|
|
2824
2831
|
//#endregion
|
|
2825
2832
|
//#region src/adapters/authenticationMethods.ts
|
|
2826
|
-
var
|
|
2827
|
-
function
|
|
2833
|
+
var Bn = "0123456789ABCDEFGHJKMNPQRSTVWXYZ", Vn = 32;
|
|
2834
|
+
function Hn() {
|
|
2828
2835
|
let e = Date.now(), t = "";
|
|
2829
|
-
for (let n = 10; n > 0; n--) t =
|
|
2836
|
+
for (let n = 10; n > 0; n--) t = Bn.charAt(e % Vn) + t, e = Math.floor(e / Vn);
|
|
2830
2837
|
let n = new Uint8Array(16);
|
|
2831
2838
|
crypto.getRandomValues(n);
|
|
2832
|
-
for (let e = 0; e < 16; e++) t +=
|
|
2839
|
+
for (let e = 0; e < 16; e++) t += Bn.charAt(n[e] % Vn);
|
|
2833
2840
|
return t;
|
|
2834
2841
|
}
|
|
2835
|
-
function
|
|
2842
|
+
function Un(e) {
|
|
2836
2843
|
let { tenant_id: t, created_at_ts: n, updated_at_ts: r, credential_backed_up: i, confirmed: a, transports: o, ...s } = e;
|
|
2837
2844
|
return D({
|
|
2838
2845
|
...s,
|
|
@@ -2843,11 +2850,11 @@ function Hn(e) {
|
|
|
2843
2850
|
updated_at: oe(r)
|
|
2844
2851
|
});
|
|
2845
2852
|
}
|
|
2846
|
-
function
|
|
2853
|
+
function Wn(e) {
|
|
2847
2854
|
return {
|
|
2848
2855
|
async create(t, n) {
|
|
2849
2856
|
let r = Date.now(), i = {
|
|
2850
|
-
id: n.id ||
|
|
2857
|
+
id: n.id || Hn(),
|
|
2851
2858
|
tenant_id: t,
|
|
2852
2859
|
user_id: n.user_id,
|
|
2853
2860
|
type: n.type,
|
|
@@ -2863,41 +2870,41 @@ function Un(e) {
|
|
|
2863
2870
|
created_at_ts: r,
|
|
2864
2871
|
updated_at_ts: r
|
|
2865
2872
|
};
|
|
2866
|
-
return await e.insert(
|
|
2873
|
+
return await e.insert(lt).values(i), Un({
|
|
2867
2874
|
...i,
|
|
2868
2875
|
tenant_id: t
|
|
2869
2876
|
});
|
|
2870
2877
|
},
|
|
2871
2878
|
async get(n, r) {
|
|
2872
|
-
let i = await e.select().from(
|
|
2873
|
-
return i ?
|
|
2879
|
+
let i = await e.select().from(lt).where(t(a(lt.tenant_id, n), a(lt.id, r))).get();
|
|
2880
|
+
return i ? Un(i) : null;
|
|
2874
2881
|
},
|
|
2875
2882
|
async getByCredentialId(n, r) {
|
|
2876
|
-
let i = await e.select().from(
|
|
2877
|
-
return i ?
|
|
2883
|
+
let i = await e.select().from(lt).where(t(a(lt.tenant_id, n), a(lt.credential_id, r))).get();
|
|
2884
|
+
return i ? Un(i) : null;
|
|
2878
2885
|
},
|
|
2879
2886
|
async list(n, r) {
|
|
2880
|
-
return (await e.select().from(
|
|
2887
|
+
return (await e.select().from(lt).where(t(a(lt.tenant_id, n), a(lt.user_id, r))).all()).map(Un);
|
|
2881
2888
|
},
|
|
2882
2889
|
async update(n, r, i) {
|
|
2883
2890
|
let o = { updated_at_ts: Date.now() };
|
|
2884
|
-
i.type !== void 0 && (o.type = i.type), i.phone_number !== void 0 && (o.phone_number = i.phone_number), i.totp_secret !== void 0 && (o.totp_secret = i.totp_secret), i.credential_id !== void 0 && (o.credential_id = i.credential_id), i.public_key !== void 0 && (o.public_key = i.public_key), i.sign_count !== void 0 && (o.sign_count = i.sign_count), i.credential_backed_up !== void 0 && (o.credential_backed_up = +!!i.credential_backed_up), i.transports !== void 0 && (o.transports = JSON.stringify(i.transports)), i.friendly_name !== void 0 && (o.friendly_name = i.friendly_name), i.confirmed !== void 0 && (o.confirmed = +!!i.confirmed), await e.update(
|
|
2891
|
+
i.type !== void 0 && (o.type = i.type), i.phone_number !== void 0 && (o.phone_number = i.phone_number), i.totp_secret !== void 0 && (o.totp_secret = i.totp_secret), i.credential_id !== void 0 && (o.credential_id = i.credential_id), i.public_key !== void 0 && (o.public_key = i.public_key), i.sign_count !== void 0 && (o.sign_count = i.sign_count), i.credential_backed_up !== void 0 && (o.credential_backed_up = +!!i.credential_backed_up), i.transports !== void 0 && (o.transports = JSON.stringify(i.transports)), i.friendly_name !== void 0 && (o.friendly_name = i.friendly_name), i.confirmed !== void 0 && (o.confirmed = +!!i.confirmed), await e.update(lt).set(o).where(t(a(lt.tenant_id, n), a(lt.id, r)));
|
|
2885
2892
|
let s = await this.get(n, r);
|
|
2886
2893
|
if (!s) throw Error(`Authentication method ${r} not found after update`);
|
|
2887
2894
|
return s;
|
|
2888
2895
|
},
|
|
2889
2896
|
async remove(n, r) {
|
|
2890
|
-
return (await e.delete(
|
|
2897
|
+
return (await e.delete(lt).where(t(a(lt.tenant_id, n), a(lt.id, r))).returning()).length > 0;
|
|
2891
2898
|
}
|
|
2892
2899
|
};
|
|
2893
2900
|
}
|
|
2894
2901
|
//#endregion
|
|
2895
2902
|
//#region src/adapters/organizations.ts
|
|
2896
|
-
var
|
|
2897
|
-
function
|
|
2903
|
+
var Gn = ["name", "display_name"];
|
|
2904
|
+
function Kn() {
|
|
2898
2905
|
return `org_${ee("0123456789abcdefghijklmnopqrstuvwxyz", 17)()}`;
|
|
2899
2906
|
}
|
|
2900
|
-
function
|
|
2907
|
+
function qn(e) {
|
|
2901
2908
|
let { tenant_id: t, branding: n, metadata: r, enabled_connections: i, token_quota: a, ...o } = e;
|
|
2902
2909
|
return D({
|
|
2903
2910
|
...o,
|
|
@@ -2907,11 +2914,11 @@ function Kn(e) {
|
|
|
2907
2914
|
token_quota: Z(a, {})
|
|
2908
2915
|
});
|
|
2909
2916
|
}
|
|
2910
|
-
function
|
|
2917
|
+
function Jn(e) {
|
|
2911
2918
|
return {
|
|
2912
2919
|
async create(t, n) {
|
|
2913
2920
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
2914
|
-
id: n.id ||
|
|
2921
|
+
id: n.id || Kn(),
|
|
2915
2922
|
tenant_id: t,
|
|
2916
2923
|
name: n.name,
|
|
2917
2924
|
display_name: n.display_name,
|
|
@@ -2927,14 +2934,14 @@ function qn(e) {
|
|
|
2927
2934
|
} catch (e) {
|
|
2928
2935
|
throw e?.message?.includes("UNIQUE constraint failed") || e?.message?.includes("AlreadyExists") ? new Le(409, { message: "Organization already exists" }) : e;
|
|
2929
2936
|
}
|
|
2930
|
-
return
|
|
2937
|
+
return qn({
|
|
2931
2938
|
...i,
|
|
2932
2939
|
tenant_id: t
|
|
2933
2940
|
});
|
|
2934
2941
|
},
|
|
2935
2942
|
async get(n, r) {
|
|
2936
2943
|
let i = await e.select().from(V).where(t(a(V.tenant_id, n), a(V.id, r))).get();
|
|
2937
|
-
return i ||= await e.select().from(V).where(t(a(V.tenant_id, n), a(V.name, r))).get(), i ?
|
|
2944
|
+
return i ||= await e.select().from(V).where(t(a(V.tenant_id, n), a(V.name, r))).get(), i ? qn(i) : null;
|
|
2938
2945
|
},
|
|
2939
2946
|
async update(n, r, i) {
|
|
2940
2947
|
let o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
@@ -2943,19 +2950,19 @@ function qn(e) {
|
|
|
2943
2950
|
async list(o, s) {
|
|
2944
2951
|
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = [a(V.tenant_id, o)];
|
|
2945
2952
|
if (f) {
|
|
2946
|
-
let e = Te(f,
|
|
2953
|
+
let e = Te(f, Gn);
|
|
2947
2954
|
if (e) {
|
|
2948
|
-
let t =
|
|
2955
|
+
let t = vt(V, e, Gn);
|
|
2949
2956
|
t && p.push(t);
|
|
2950
2957
|
}
|
|
2951
2958
|
}
|
|
2952
2959
|
let m = t(...p);
|
|
2953
|
-
if (
|
|
2960
|
+
if (At(s)) {
|
|
2954
2961
|
let n = {
|
|
2955
2962
|
sortColumn: V.created_at,
|
|
2956
2963
|
idColumn: V.id,
|
|
2957
2964
|
sortOrder: "desc"
|
|
2958
|
-
}, r =
|
|
2965
|
+
}, r = Nt(s, n), i = jt(s), { rows: a, next: o } = Pt(await e.select().from(V).where(r ? t(m, r) : m).orderBy(...Mt(n)).limit(i + 1), i, "created_at"), c = a.map(qn);
|
|
2959
2966
|
return {
|
|
2960
2967
|
organizations: c,
|
|
2961
2968
|
start: 0,
|
|
@@ -2970,7 +2977,7 @@ function qn(e) {
|
|
|
2970
2977
|
let e = V[d.sort_by];
|
|
2971
2978
|
e && (h = h.orderBy(d.sort_order === "desc" ? i(e) : n(e)));
|
|
2972
2979
|
}
|
|
2973
|
-
let g = (await h.offset(c * l).limit(l)).map(
|
|
2980
|
+
let g = (await h.offset(c * l).limit(l)).map(qn);
|
|
2974
2981
|
if (!u) return { organizations: g };
|
|
2975
2982
|
let [_] = await e.select({ count: r() }).from(V).where(m);
|
|
2976
2983
|
return {
|
|
@@ -2987,14 +2994,14 @@ function qn(e) {
|
|
|
2987
2994
|
}
|
|
2988
2995
|
//#endregion
|
|
2989
2996
|
//#region src/adapters/passwords.ts
|
|
2990
|
-
function
|
|
2997
|
+
function Yn(e) {
|
|
2991
2998
|
let { tenant_id: t, is_current: n, ...r } = e;
|
|
2992
2999
|
return {
|
|
2993
3000
|
...r,
|
|
2994
3001
|
is_current: !!n
|
|
2995
3002
|
};
|
|
2996
3003
|
}
|
|
2997
|
-
function
|
|
3004
|
+
function Xn(e) {
|
|
2998
3005
|
return {
|
|
2999
3006
|
async create(n, r) {
|
|
3000
3007
|
let i = (/* @__PURE__ */ new Date()).toISOString(), o = r.id || b();
|
|
@@ -3009,18 +3016,18 @@ function Yn(e) {
|
|
|
3009
3016
|
created_at: i,
|
|
3010
3017
|
updated_at: i
|
|
3011
3018
|
};
|
|
3012
|
-
return await e.insert(j).values(s),
|
|
3019
|
+
return await e.insert(j).values(s), Yn({
|
|
3013
3020
|
...s,
|
|
3014
3021
|
tenant_id: n
|
|
3015
3022
|
});
|
|
3016
3023
|
},
|
|
3017
3024
|
async get(n, r) {
|
|
3018
3025
|
let i = await e.select().from(j).where(t(a(j.tenant_id, n), a(j.user_id, r), a(j.is_current, 1))).get();
|
|
3019
|
-
return i ?
|
|
3026
|
+
return i ? Yn(i) : null;
|
|
3020
3027
|
},
|
|
3021
3028
|
async list(n, r, o) {
|
|
3022
3029
|
let s = e.select().from(j).where(t(a(j.tenant_id, n), a(j.user_id, r))).orderBy(i(j.created_at)).$dynamic();
|
|
3023
|
-
return o && (s = s.limit(o)), (await s).map(
|
|
3030
|
+
return o && (s = s.limit(o)), (await s).map(Yn);
|
|
3024
3031
|
},
|
|
3025
3032
|
async update(n, r) {
|
|
3026
3033
|
let i = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
@@ -3030,7 +3037,7 @@ function Yn(e) {
|
|
|
3030
3037
|
}
|
|
3031
3038
|
//#endregion
|
|
3032
3039
|
//#region src/adapters/promptSettings.ts
|
|
3033
|
-
function
|
|
3040
|
+
function Zn(e) {
|
|
3034
3041
|
return {
|
|
3035
3042
|
async get(t) {
|
|
3036
3043
|
let n = await e.select().from(tt).where(a(tt.tenant_id, t)).get();
|
|
@@ -3070,8 +3077,45 @@ function Xn(e) {
|
|
|
3070
3077
|
};
|
|
3071
3078
|
}
|
|
3072
3079
|
//#endregion
|
|
3080
|
+
//#region src/adapters/promptPartials.ts
|
|
3081
|
+
function Qn(e) {
|
|
3082
|
+
return {
|
|
3083
|
+
async get(n, r) {
|
|
3084
|
+
let i = await e.select({ body: ct.body }).from(ct).where(t(a(ct.tenant_id, n), a(ct.prompt, r))).get();
|
|
3085
|
+
if (!i) return null;
|
|
3086
|
+
try {
|
|
3087
|
+
return JSON.parse(i.body);
|
|
3088
|
+
} catch {
|
|
3089
|
+
return null;
|
|
3090
|
+
}
|
|
3091
|
+
},
|
|
3092
|
+
async set(t, n, r, i) {
|
|
3093
|
+
let a = Date.now(), o = i?.importMetadata?.created_at, s = i?.importMetadata?.updated_at, c = o ? new Date(o).getTime() : a, l = s ? new Date(s).getTime() : c, u = JSON.stringify(r);
|
|
3094
|
+
await e.insert(ct).values({
|
|
3095
|
+
tenant_id: t,
|
|
3096
|
+
prompt: n,
|
|
3097
|
+
body: u,
|
|
3098
|
+
created_at_ts: c,
|
|
3099
|
+
updated_at_ts: l
|
|
3100
|
+
}).onConflictDoUpdate({
|
|
3101
|
+
target: [ct.tenant_id, ct.prompt],
|
|
3102
|
+
set: {
|
|
3103
|
+
body: u,
|
|
3104
|
+
updated_at_ts: s ? l : a
|
|
3105
|
+
}
|
|
3106
|
+
});
|
|
3107
|
+
},
|
|
3108
|
+
async delete(n, r) {
|
|
3109
|
+
await e.delete(ct).where(t(a(ct.tenant_id, n), a(ct.prompt, r)));
|
|
3110
|
+
},
|
|
3111
|
+
async list(t) {
|
|
3112
|
+
return (await e.select({ prompt: ct.prompt }).from(ct).where(a(ct.tenant_id, t)).all()).map(({ prompt: e }) => e);
|
|
3113
|
+
}
|
|
3114
|
+
};
|
|
3115
|
+
}
|
|
3116
|
+
//#endregion
|
|
3073
3117
|
//#region src/adapters/proxyRoutes.ts
|
|
3074
|
-
function
|
|
3118
|
+
function $n(e) {
|
|
3075
3119
|
if (!e) return { path: "/*" };
|
|
3076
3120
|
try {
|
|
3077
3121
|
let t = JSON.parse(e), n = xe.safeParse(t);
|
|
@@ -3079,7 +3123,7 @@ function Zn(e) {
|
|
|
3079
3123
|
} catch {}
|
|
3080
3124
|
return { path: "/*" };
|
|
3081
3125
|
}
|
|
3082
|
-
function
|
|
3126
|
+
function er(e) {
|
|
3083
3127
|
if (!e) return [];
|
|
3084
3128
|
try {
|
|
3085
3129
|
let t = JSON.parse(e);
|
|
@@ -3094,19 +3138,19 @@ function Qn(e) {
|
|
|
3094
3138
|
return [];
|
|
3095
3139
|
}
|
|
3096
3140
|
}
|
|
3097
|
-
function
|
|
3141
|
+
function tr(e) {
|
|
3098
3142
|
return {
|
|
3099
3143
|
id: e.id,
|
|
3100
3144
|
tenant_id: e.tenant_id,
|
|
3101
3145
|
custom_domain_id: e.custom_domain_id,
|
|
3102
3146
|
priority: e.priority,
|
|
3103
|
-
match:
|
|
3104
|
-
handlers:
|
|
3147
|
+
match: $n(e.match),
|
|
3148
|
+
handlers: er(e.handlers),
|
|
3105
3149
|
created_at: e.created_at,
|
|
3106
3150
|
updated_at: e.updated_at
|
|
3107
3151
|
};
|
|
3108
3152
|
}
|
|
3109
|
-
function
|
|
3153
|
+
function nr(e) {
|
|
3110
3154
|
return {
|
|
3111
3155
|
async create(t, n) {
|
|
3112
3156
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
@@ -3132,14 +3176,14 @@ function er(e) {
|
|
|
3132
3176
|
},
|
|
3133
3177
|
async get(n, r) {
|
|
3134
3178
|
let i = await e.select().from(Y).where(t(a(Y.tenant_id, n), a(Y.id, r))).limit(1);
|
|
3135
|
-
return i[0] ?
|
|
3179
|
+
return i[0] ? tr(i[0]) : null;
|
|
3136
3180
|
},
|
|
3137
3181
|
async list(r, i = {}) {
|
|
3138
3182
|
let o = i.page ?? 0, s = i.per_page ?? 50, c = [a(Y.tenant_id, r)];
|
|
3139
3183
|
i.custom_domain_id && c.push(a(Y.custom_domain_id, i.custom_domain_id));
|
|
3140
3184
|
let l = await e.select().from(Y).where(t(...c)).orderBy(n(Y.priority), n(Y.created_at)).offset(o * s).limit(s);
|
|
3141
3185
|
return {
|
|
3142
|
-
proxy_routes: l.map(
|
|
3186
|
+
proxy_routes: l.map(tr),
|
|
3143
3187
|
start: o * s,
|
|
3144
3188
|
limit: s,
|
|
3145
3189
|
length: l.length
|
|
@@ -3158,8 +3202,8 @@ function er(e) {
|
|
|
3158
3202
|
}
|
|
3159
3203
|
//#endregion
|
|
3160
3204
|
//#region src/adapters/tokenExchangeProfiles.ts
|
|
3161
|
-
var
|
|
3162
|
-
function
|
|
3205
|
+
var rr = ee("0123456789abcdefghijklmnopqrstuvwxyz", 17);
|
|
3206
|
+
function ir(e) {
|
|
3163
3207
|
if (e) try {
|
|
3164
3208
|
let t = Fe.safeParse(JSON.parse(e));
|
|
3165
3209
|
return t.success ? t.data : void 0;
|
|
@@ -3167,7 +3211,7 @@ function nr(e) {
|
|
|
3167
3211
|
return;
|
|
3168
3212
|
}
|
|
3169
3213
|
}
|
|
3170
|
-
function
|
|
3214
|
+
function ar(e) {
|
|
3171
3215
|
let t = {
|
|
3172
3216
|
id: e.id,
|
|
3173
3217
|
name: e.name,
|
|
@@ -3177,14 +3221,14 @@ function rr(e) {
|
|
|
3177
3221
|
updated_at: e.updated_at
|
|
3178
3222
|
};
|
|
3179
3223
|
e.action_id && (t.action_id = e.action_id);
|
|
3180
|
-
let n =
|
|
3224
|
+
let n = ir(e.jwt_verification);
|
|
3181
3225
|
return n && (t.jwt_verification = n), t;
|
|
3182
3226
|
}
|
|
3183
|
-
function
|
|
3227
|
+
function or(e) {
|
|
3184
3228
|
return {
|
|
3185
3229
|
async create(t, n, r) {
|
|
3186
3230
|
let i = r?.importMetadata, a = (/* @__PURE__ */ new Date()).toISOString(), o = {
|
|
3187
|
-
id: i?.id ?? `tep_${
|
|
3231
|
+
id: i?.id ?? `tep_${rr()}`,
|
|
3188
3232
|
tenant_id: t,
|
|
3189
3233
|
name: n.name,
|
|
3190
3234
|
subject_token_type: n.subject_token_type,
|
|
@@ -3194,27 +3238,27 @@ function ir(e) {
|
|
|
3194
3238
|
created_at: i?.created_at ?? a,
|
|
3195
3239
|
updated_at: i?.updated_at ?? a
|
|
3196
3240
|
};
|
|
3197
|
-
return await e.insert(
|
|
3241
|
+
return await e.insert(ft).values(o), ar(o);
|
|
3198
3242
|
},
|
|
3199
3243
|
async get(n, r) {
|
|
3200
|
-
let i = await e.select().from(
|
|
3201
|
-
return i[0] ?
|
|
3244
|
+
let i = await e.select().from(ft).where(t(a(ft.tenant_id, n), a(ft.id, r))).limit(1);
|
|
3245
|
+
return i[0] ? ar(i[0]) : null;
|
|
3202
3246
|
},
|
|
3203
3247
|
async list(t) {
|
|
3204
|
-
return (await e.select().from(
|
|
3248
|
+
return (await e.select().from(ft).where(a(ft.tenant_id, t)).orderBy(n(ft.created_at), n(ft.id))).map(ar);
|
|
3205
3249
|
},
|
|
3206
3250
|
async update(n, r, i) {
|
|
3207
3251
|
let o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
3208
|
-
return i.name !== void 0 && (o.name = i.name), i.subject_token_type !== void 0 && (o.subject_token_type = i.subject_token_type), i.jwt_verification !== void 0 && (o.jwt_verification = JSON.stringify(i.jwt_verification)), (await e.update(
|
|
3252
|
+
return i.name !== void 0 && (o.name = i.name), i.subject_token_type !== void 0 && (o.subject_token_type = i.subject_token_type), i.jwt_verification !== void 0 && (o.jwt_verification = JSON.stringify(i.jwt_verification)), (await e.update(ft).set(o).where(t(a(ft.tenant_id, n), a(ft.id, r))).returning({ id: ft.id })).length > 0;
|
|
3209
3253
|
},
|
|
3210
3254
|
async remove(n, r) {
|
|
3211
|
-
return (await e.delete(
|
|
3255
|
+
return (await e.delete(ft).where(t(a(ft.tenant_id, n), a(ft.id, r))).returning({ id: ft.id })).length > 0;
|
|
3212
3256
|
}
|
|
3213
3257
|
};
|
|
3214
3258
|
}
|
|
3215
3259
|
//#endregion
|
|
3216
3260
|
//#region src/adapters/scim.ts
|
|
3217
|
-
function
|
|
3261
|
+
function sr(e) {
|
|
3218
3262
|
if (!e) return [];
|
|
3219
3263
|
try {
|
|
3220
3264
|
let t = JSON.parse(e);
|
|
@@ -3229,7 +3273,7 @@ function ar(e) {
|
|
|
3229
3273
|
return [];
|
|
3230
3274
|
}
|
|
3231
3275
|
}
|
|
3232
|
-
function
|
|
3276
|
+
function cr(e) {
|
|
3233
3277
|
if (!e) return [];
|
|
3234
3278
|
try {
|
|
3235
3279
|
let t = JSON.parse(e);
|
|
@@ -3238,16 +3282,16 @@ function or(e) {
|
|
|
3238
3282
|
return [];
|
|
3239
3283
|
}
|
|
3240
3284
|
}
|
|
3241
|
-
function
|
|
3285
|
+
function lr(e) {
|
|
3242
3286
|
return {
|
|
3243
3287
|
connection_id: e.connection_id,
|
|
3244
3288
|
user_id_attribute: e.user_id_attribute,
|
|
3245
|
-
mapping:
|
|
3289
|
+
mapping: sr(e.mapping),
|
|
3246
3290
|
created_at: e.created_at,
|
|
3247
3291
|
updated_at: e.updated_at
|
|
3248
3292
|
};
|
|
3249
3293
|
}
|
|
3250
|
-
function
|
|
3294
|
+
function ur(e) {
|
|
3251
3295
|
return {
|
|
3252
3296
|
async create(t, n) {
|
|
3253
3297
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
@@ -3257,7 +3301,7 @@ function cr(e) {
|
|
|
3257
3301
|
created_at: r,
|
|
3258
3302
|
updated_at: r
|
|
3259
3303
|
};
|
|
3260
|
-
return await e.insert(
|
|
3304
|
+
return await e.insert(ut).values({
|
|
3261
3305
|
connection_id: i.connection_id,
|
|
3262
3306
|
tenant_id: t,
|
|
3263
3307
|
user_id_attribute: i.user_id_attribute,
|
|
@@ -3267,31 +3311,31 @@ function cr(e) {
|
|
|
3267
3311
|
}), i;
|
|
3268
3312
|
},
|
|
3269
3313
|
async get(n, r) {
|
|
3270
|
-
let i = await e.select().from(
|
|
3271
|
-
return i[0] ?
|
|
3314
|
+
let i = await e.select().from(ut).where(t(a(ut.tenant_id, n), a(ut.connection_id, r))).limit(1);
|
|
3315
|
+
return i[0] ? lr(i[0]) : null;
|
|
3272
3316
|
},
|
|
3273
3317
|
async update(n, r, i) {
|
|
3274
|
-
if ((await e.select({ connection_id:
|
|
3318
|
+
if ((await e.select({ connection_id: ut.connection_id }).from(ut).where(t(a(ut.tenant_id, n), a(ut.connection_id, r))).limit(1)).length === 0) return !1;
|
|
3275
3319
|
let o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
3276
|
-
return i.user_id_attribute !== void 0 && (o.user_id_attribute = i.user_id_attribute), i.mapping !== void 0 && (o.mapping = JSON.stringify(i.mapping)), await e.update(
|
|
3320
|
+
return i.user_id_attribute !== void 0 && (o.user_id_attribute = i.user_id_attribute), i.mapping !== void 0 && (o.mapping = JSON.stringify(i.mapping)), await e.update(ut).set(o).where(t(a(ut.tenant_id, n), a(ut.connection_id, r))), !0;
|
|
3277
3321
|
},
|
|
3278
3322
|
async remove(n, r) {
|
|
3279
|
-
return (await e.select({ connection_id:
|
|
3323
|
+
return (await e.select({ connection_id: ut.connection_id }).from(ut).where(t(a(ut.tenant_id, n), a(ut.connection_id, r))).limit(1)).length === 0 ? !1 : (await e.delete(ut).where(t(a(ut.tenant_id, n), a(ut.connection_id, r))), !0);
|
|
3280
3324
|
}
|
|
3281
3325
|
};
|
|
3282
3326
|
}
|
|
3283
|
-
function
|
|
3327
|
+
function dr(e) {
|
|
3284
3328
|
return {
|
|
3285
3329
|
token_id: e.token_id,
|
|
3286
3330
|
connection_id: e.connection_id,
|
|
3287
3331
|
token_hash: e.token_hash,
|
|
3288
|
-
scopes:
|
|
3332
|
+
scopes: cr(e.scopes),
|
|
3289
3333
|
valid_until: e.valid_until ?? void 0,
|
|
3290
3334
|
created_at: e.created_at,
|
|
3291
3335
|
last_used_at: e.last_used_at ?? void 0
|
|
3292
3336
|
};
|
|
3293
3337
|
}
|
|
3294
|
-
function
|
|
3338
|
+
function fr(e) {
|
|
3295
3339
|
return {
|
|
3296
3340
|
async create(t, n) {
|
|
3297
3341
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
@@ -3314,14 +3358,14 @@ function ur(e) {
|
|
|
3314
3358
|
},
|
|
3315
3359
|
async get(n, r) {
|
|
3316
3360
|
let i = await e.select().from(X).where(t(a(X.tenant_id, n), a(X.token_id, r))).limit(1);
|
|
3317
|
-
return i[0] ?
|
|
3361
|
+
return i[0] ? dr(i[0]) : null;
|
|
3318
3362
|
},
|
|
3319
3363
|
async getByHash(n, r) {
|
|
3320
3364
|
let i = await e.select().from(X).where(t(a(X.tenant_id, n), a(X.token_hash, r))).limit(1);
|
|
3321
|
-
return i[0] ?
|
|
3365
|
+
return i[0] ? dr(i[0]) : null;
|
|
3322
3366
|
},
|
|
3323
3367
|
async listByConnection(n, r) {
|
|
3324
|
-
return (await e.select().from(X).where(t(a(X.tenant_id, n), a(X.connection_id, r)))).map(
|
|
3368
|
+
return (await e.select().from(X).where(t(a(X.tenant_id, n), a(X.connection_id, r)))).map(dr);
|
|
3325
3369
|
},
|
|
3326
3370
|
async markUsed(n, r, i) {
|
|
3327
3371
|
return (await e.select({ token_id: X.token_id }).from(X).where(t(a(X.tenant_id, n), a(X.token_id, r))).limit(1)).length === 0 ? !1 : (await e.update(X).set({ last_used_at: i }).where(t(a(X.tenant_id, n), a(X.token_id, r))), !0);
|
|
@@ -3331,7 +3375,7 @@ function ur(e) {
|
|
|
3331
3375
|
}
|
|
3332
3376
|
};
|
|
3333
3377
|
}
|
|
3334
|
-
function
|
|
3378
|
+
function pr(e) {
|
|
3335
3379
|
return {
|
|
3336
3380
|
connection_id: e.connection_id,
|
|
3337
3381
|
external_id: e.external_id,
|
|
@@ -3339,7 +3383,7 @@ function dr(e) {
|
|
|
3339
3383
|
created_at: e.created_at
|
|
3340
3384
|
};
|
|
3341
3385
|
}
|
|
3342
|
-
function
|
|
3386
|
+
function mr(e) {
|
|
3343
3387
|
return {
|
|
3344
3388
|
async create(t, n) {
|
|
3345
3389
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
@@ -3348,7 +3392,7 @@ function fr(e) {
|
|
|
3348
3392
|
user_id: n.user_id,
|
|
3349
3393
|
created_at: r
|
|
3350
3394
|
};
|
|
3351
|
-
return await e.insert(
|
|
3395
|
+
return await e.insert(dt).values({
|
|
3352
3396
|
tenant_id: t,
|
|
3353
3397
|
connection_id: i.connection_id,
|
|
3354
3398
|
external_id: i.external_id,
|
|
@@ -3357,21 +3401,21 @@ function fr(e) {
|
|
|
3357
3401
|
}), i;
|
|
3358
3402
|
},
|
|
3359
3403
|
async getByExternalId(n, r, i) {
|
|
3360
|
-
let o = await e.select().from(
|
|
3361
|
-
return o[0] ?
|
|
3404
|
+
let o = await e.select().from(dt).where(t(a(dt.tenant_id, n), a(dt.connection_id, r), a(dt.external_id, i))).limit(1);
|
|
3405
|
+
return o[0] ? pr(o[0]) : null;
|
|
3362
3406
|
},
|
|
3363
3407
|
async getByUserId(n, r, i) {
|
|
3364
|
-
let o = await e.select().from(
|
|
3365
|
-
return o[0] ?
|
|
3408
|
+
let o = await e.select().from(dt).where(t(a(dt.tenant_id, n), a(dt.connection_id, r), a(dt.user_id, i))).limit(1);
|
|
3409
|
+
return o[0] ? pr(o[0]) : null;
|
|
3366
3410
|
},
|
|
3367
3411
|
async remove(n, r, i) {
|
|
3368
|
-
return (await e.select({ user_id:
|
|
3412
|
+
return (await e.select({ user_id: dt.user_id }).from(dt).where(t(a(dt.tenant_id, n), a(dt.connection_id, r), a(dt.user_id, i))).limit(1)).length === 0 ? !1 : (await e.delete(dt).where(t(a(dt.tenant_id, n), a(dt.connection_id, r), a(dt.user_id, i))), !0);
|
|
3369
3413
|
}
|
|
3370
3414
|
};
|
|
3371
3415
|
}
|
|
3372
3416
|
//#endregion
|
|
3373
3417
|
//#region src/adapters/refreshTokens.ts
|
|
3374
|
-
function
|
|
3418
|
+
function hr(e) {
|
|
3375
3419
|
let { tenant_id: t, created_at_ts: n, expires_at_ts: r, idle_expires_at_ts: i, last_exchanged_at_ts: a, revoked_at_ts: o, rotated_at_ts: s, device: c, resource_servers: l, rotating: u, auth_strategy_strategy: d, auth_strategy_strategy_type: f, ...p } = e, m = ae({
|
|
3376
3420
|
created_at_ts: n,
|
|
3377
3421
|
expires_at_ts: r,
|
|
@@ -3398,10 +3442,10 @@ function pr(e) {
|
|
|
3398
3442
|
} } : {}
|
|
3399
3443
|
});
|
|
3400
3444
|
}
|
|
3401
|
-
function
|
|
3445
|
+
function gr(e, t) {
|
|
3402
3446
|
return Math.max(e ?? 0, t ?? 0);
|
|
3403
3447
|
}
|
|
3404
|
-
function
|
|
3448
|
+
function _r(e) {
|
|
3405
3449
|
return {
|
|
3406
3450
|
async create(n, r) {
|
|
3407
3451
|
let i = Date.now(), o = {
|
|
@@ -3427,22 +3471,22 @@ function hr(e) {
|
|
|
3427
3471
|
expires_at_ts: E(r.expires_at),
|
|
3428
3472
|
idle_expires_at_ts: E(r.idle_expires_at),
|
|
3429
3473
|
last_exchanged_at_ts: E(r.last_exchanged_at)
|
|
3430
|
-
}, s = [e.insert(N).values(o)], c =
|
|
3474
|
+
}, s = [e.insert(N).values(o)], c = gr(o.expires_at_ts, o.idle_expires_at_ts);
|
|
3431
3475
|
return c > 0 && o.login_id && s.push(e.update(P).set({
|
|
3432
3476
|
expires_at_ts: c,
|
|
3433
3477
|
updated_at_ts: i
|
|
3434
|
-
}).where(t(a(P.tenant_id, n), a(P.id, o.login_id), m(P.expires_at_ts, c)))), await
|
|
3478
|
+
}).where(t(a(P.tenant_id, n), a(P.id, o.login_id), m(P.expires_at_ts, c)))), await Tt(e, s), hr({
|
|
3435
3479
|
...o,
|
|
3436
3480
|
tenant_id: n
|
|
3437
3481
|
});
|
|
3438
3482
|
},
|
|
3439
3483
|
async get(n, r) {
|
|
3440
3484
|
let i = await e.select().from(N).where(t(a(N.tenant_id, n), a(N.id, r))).get();
|
|
3441
|
-
return i ?
|
|
3485
|
+
return i ? hr(i) : null;
|
|
3442
3486
|
},
|
|
3443
3487
|
async getByLookup(n, r) {
|
|
3444
3488
|
let i = await e.select().from(N).where(t(a(N.tenant_id, n), a(N.token_lookup, r))).get();
|
|
3445
|
-
return i ?
|
|
3489
|
+
return i ? hr(i) : null;
|
|
3446
3490
|
},
|
|
3447
3491
|
async update(n, r, i, o) {
|
|
3448
3492
|
let s = {};
|
|
@@ -3454,17 +3498,17 @@ function hr(e) {
|
|
|
3454
3498
|
}).where(t(a(P.tenant_id, n), a(P.id, c.login_id), m(P.expires_at_ts, l))).catch(() => {}), u.length > 0;
|
|
3455
3499
|
},
|
|
3456
3500
|
async list(o, s) {
|
|
3457
|
-
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ?
|
|
3501
|
+
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ? vt(N, f, ["user_id", "login_id"]) : void 0, m = [
|
|
3458
3502
|
a(N.tenant_id, o),
|
|
3459
3503
|
...s?.user_id === void 0 ? [] : [a(N.user_id, s.user_id)],
|
|
3460
3504
|
...p ? [p] : []
|
|
3461
3505
|
], h = m.length === 1 ? m[0] : t(...m);
|
|
3462
|
-
if (
|
|
3506
|
+
if (At(s)) {
|
|
3463
3507
|
let n = {
|
|
3464
3508
|
sortColumn: N.created_at_ts,
|
|
3465
3509
|
idColumn: N.id,
|
|
3466
3510
|
sortOrder: "desc"
|
|
3467
|
-
}, r =
|
|
3511
|
+
}, r = Nt(s, n), i = jt(s), { rows: a, next: o } = Pt(await e.select().from(N).where(r ? t(h, r) : h).orderBy(...Mt(n)).limit(i + 1), i, "created_at_ts"), c = a.map(hr);
|
|
3468
3512
|
return {
|
|
3469
3513
|
refresh_tokens: c,
|
|
3470
3514
|
start: 0,
|
|
@@ -3478,7 +3522,7 @@ function hr(e) {
|
|
|
3478
3522
|
let e = N[d.sort_by];
|
|
3479
3523
|
e && (g = g.orderBy(d.sort_order === "desc" ? i(e) : n(e)));
|
|
3480
3524
|
}
|
|
3481
|
-
let _ = (await g.offset(c * l).limit(l)).map(
|
|
3525
|
+
let _ = (await g.offset(c * l).limit(l)).map(hr);
|
|
3482
3526
|
if (!u) return { refresh_tokens: _ };
|
|
3483
3527
|
let [v] = await e.select({ count: r() }).from(N).where(h);
|
|
3484
3528
|
return {
|
|
@@ -3507,15 +3551,15 @@ function hr(e) {
|
|
|
3507
3551
|
}
|
|
3508
3552
|
//#endregion
|
|
3509
3553
|
//#region src/adapters/resourceServers.ts
|
|
3510
|
-
var
|
|
3511
|
-
function
|
|
3554
|
+
var vr = ["name", "identifier"];
|
|
3555
|
+
function yr() {
|
|
3512
3556
|
return `api_${ee("0123456789abcdefghijklmnopqrstuvwxyz", 17)()}`;
|
|
3513
3557
|
}
|
|
3514
|
-
var
|
|
3558
|
+
var br = [
|
|
3515
3559
|
"skip_consent_for_verifiable_first_party_clients",
|
|
3516
3560
|
"allow_offline_access",
|
|
3517
3561
|
"is_system"
|
|
3518
|
-
],
|
|
3562
|
+
], xr = new Set([
|
|
3519
3563
|
"id",
|
|
3520
3564
|
"tenant_id",
|
|
3521
3565
|
"identifier",
|
|
@@ -3534,17 +3578,17 @@ var vr = [
|
|
|
3534
3578
|
"created_at",
|
|
3535
3579
|
"updated_at"
|
|
3536
3580
|
]);
|
|
3537
|
-
function
|
|
3581
|
+
function Sr(e) {
|
|
3538
3582
|
let { tenant_id: t, verification_key: n, scopes: r, options: i, metadata: a, ...o } = e, s = { ...o };
|
|
3539
3583
|
s.scopes = Z(r, []), s.options = Z(i, {}), s.metadata = Z(a), n !== void 0 && (s.verificationKey = n);
|
|
3540
|
-
for (let e of
|
|
3584
|
+
for (let e of br) o[e] !== void 0 && o[e] !== null && (s[e] = !!o[e]);
|
|
3541
3585
|
return D(s);
|
|
3542
3586
|
}
|
|
3543
|
-
function
|
|
3587
|
+
function Cr(e) {
|
|
3544
3588
|
return {
|
|
3545
3589
|
async create(t, n) {
|
|
3546
3590
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
3547
|
-
id: n.id ||
|
|
3591
|
+
id: n.id || yr(),
|
|
3548
3592
|
tenant_id: t,
|
|
3549
3593
|
identifier: n.identifier,
|
|
3550
3594
|
name: n.name,
|
|
@@ -3559,37 +3603,37 @@ function xr(e) {
|
|
|
3559
3603
|
created_at: r,
|
|
3560
3604
|
updated_at: r
|
|
3561
3605
|
};
|
|
3562
|
-
for (let e of
|
|
3563
|
-
return i.is_system === void 0 && (i.is_system = 0), await e.insert(K).values(i),
|
|
3606
|
+
for (let e of br) n[e] !== void 0 && (i[e] = +!!n[e]);
|
|
3607
|
+
return i.is_system === void 0 && (i.is_system = 0), await e.insert(K).values(i), Sr({
|
|
3564
3608
|
...i,
|
|
3565
3609
|
tenant_id: t
|
|
3566
3610
|
});
|
|
3567
3611
|
},
|
|
3568
3612
|
async get(n, r) {
|
|
3569
3613
|
let i = await e.select().from(K).where(t(a(K.tenant_id, n), a(K.id, r))).get();
|
|
3570
|
-
return i ?
|
|
3614
|
+
return i ? Sr(i) : null;
|
|
3571
3615
|
},
|
|
3572
3616
|
async update(n, r, i) {
|
|
3573
3617
|
let o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
3574
3618
|
i.name !== void 0 && (o.name = i.name), i.identifier !== void 0 && (o.identifier = i.identifier), i.signing_alg !== void 0 && (o.signing_alg = i.signing_alg), i.signing_secret !== void 0 && (o.signing_secret = i.signing_secret), i.token_lifetime !== void 0 && (o.token_lifetime = i.token_lifetime), i.token_lifetime_for_web !== void 0 && (o.token_lifetime_for_web = i.token_lifetime_for_web), i.scopes !== void 0 && (o.scopes = JSON.stringify(i.scopes)), i.options !== void 0 && (o.options = y`json_patch(COALESCE(${K.options}, '{}'), ${JSON.stringify(i.options)})`), i.metadata !== void 0 && (o.metadata = JSON.stringify(i.metadata)), i.verificationKey !== void 0 && (o.verification_key = i.verificationKey);
|
|
3575
|
-
for (let e of
|
|
3619
|
+
for (let e of br) i[e] !== void 0 && (o[e] = +!!i[e]);
|
|
3576
3620
|
return (await e.update(K).set(o).where(t(a(K.tenant_id, n), a(K.id, r))).returning()).length > 0;
|
|
3577
3621
|
},
|
|
3578
3622
|
async list(o, s) {
|
|
3579
3623
|
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = Math.max(0, Math.floor(Number(c) || 0)), m = Math.min(Math.max(1, Math.floor(Number(l) || 50)), 500), h = [a(K.tenant_id, o)];
|
|
3580
3624
|
if (f) {
|
|
3581
|
-
let e = Te(f,
|
|
3625
|
+
let e = Te(f, vr);
|
|
3582
3626
|
if (e) {
|
|
3583
|
-
let t =
|
|
3627
|
+
let t = vt(K, e, vr, ["name", "identifier"]);
|
|
3584
3628
|
t && h.push(t);
|
|
3585
3629
|
}
|
|
3586
3630
|
}
|
|
3587
|
-
if (
|
|
3631
|
+
if (At(s)) {
|
|
3588
3632
|
let n = {
|
|
3589
3633
|
sortColumn: K.created_at,
|
|
3590
3634
|
idColumn: K.id,
|
|
3591
3635
|
sortOrder: "desc"
|
|
3592
|
-
}, r =
|
|
3636
|
+
}, r = Nt(s, n), i = jt(s), { rows: a, next: o } = Pt(await e.select().from(K).where(t(...h, r)).orderBy(...Mt(n)).limit(i + 1), i, "created_at", "id"), c = a.map(Sr);
|
|
3593
3637
|
return {
|
|
3594
3638
|
resource_servers: c,
|
|
3595
3639
|
start: 0,
|
|
@@ -3599,11 +3643,11 @@ function xr(e) {
|
|
|
3599
3643
|
};
|
|
3600
3644
|
}
|
|
3601
3645
|
let g = e.select().from(K).where(t(...h)).$dynamic();
|
|
3602
|
-
if (d?.sort_by &&
|
|
3646
|
+
if (d?.sort_by && xr.has(d.sort_by)) {
|
|
3603
3647
|
let e = K[d.sort_by];
|
|
3604
3648
|
g = g.orderBy(d.sort_order === "desc" ? i(e) : n(e));
|
|
3605
3649
|
}
|
|
3606
|
-
let _ = (await g.offset(p * m).limit(m)).map(
|
|
3650
|
+
let _ = (await g.offset(p * m).limit(m)).map(Sr);
|
|
3607
3651
|
if (!u) return { resource_servers: _ };
|
|
3608
3652
|
let [v] = await e.select({ count: r() }).from(K).where(t(...h));
|
|
3609
3653
|
return {
|
|
@@ -3620,7 +3664,7 @@ function xr(e) {
|
|
|
3620
3664
|
}
|
|
3621
3665
|
//#endregion
|
|
3622
3666
|
//#region src/adapters/rolePermissions.ts
|
|
3623
|
-
function
|
|
3667
|
+
function wr(e) {
|
|
3624
3668
|
return {
|
|
3625
3669
|
async assign(t, n, r) {
|
|
3626
3670
|
if (r.length === 0) return !0;
|
|
@@ -3634,7 +3678,7 @@ function Sr(e) {
|
|
|
3634
3678
|
}))).onConflictDoNothing(), !0;
|
|
3635
3679
|
},
|
|
3636
3680
|
async list(n, r, i) {
|
|
3637
|
-
return
|
|
3681
|
+
return Tr(e, n, await e.select({
|
|
3638
3682
|
resource_server_identifier: W.resource_server_identifier,
|
|
3639
3683
|
permission_name: W.permission_name,
|
|
3640
3684
|
created_at: W.created_at
|
|
@@ -3645,14 +3689,14 @@ function Sr(e) {
|
|
|
3645
3689
|
sortColumn: W.resource_server_identifier,
|
|
3646
3690
|
idColumn: W.permission_name,
|
|
3647
3691
|
sortOrder: "asc"
|
|
3648
|
-
}, s =
|
|
3692
|
+
}, s = jt(i), { rows: c, next: l } = Pt(await e.select({
|
|
3649
3693
|
role_id: W.role_id,
|
|
3650
3694
|
resource_server_identifier: W.resource_server_identifier,
|
|
3651
3695
|
permission_name: W.permission_name,
|
|
3652
3696
|
created_at: W.created_at
|
|
3653
|
-
}).from(W).where(t(a(W.tenant_id, n), a(W.role_id, r),
|
|
3697
|
+
}).from(W).where(t(a(W.tenant_id, n), a(W.role_id, r), Nt(i, o))).orderBy(...Mt(o)).limit(s + 1).all(), s, "resource_server_identifier", "permission_name");
|
|
3654
3698
|
return {
|
|
3655
|
-
permissions: await
|
|
3699
|
+
permissions: await Tr(e, n, c),
|
|
3656
3700
|
next: l
|
|
3657
3701
|
};
|
|
3658
3702
|
},
|
|
@@ -3663,7 +3707,7 @@ function Sr(e) {
|
|
|
3663
3707
|
}
|
|
3664
3708
|
};
|
|
3665
3709
|
}
|
|
3666
|
-
async function
|
|
3710
|
+
async function Tr(e, n, r) {
|
|
3667
3711
|
let i = [...new Set(r.map((e) => e.resource_server_identifier))], o = /* @__PURE__ */ new Map();
|
|
3668
3712
|
if (i.length > 0) {
|
|
3669
3713
|
let r = await e.select({
|
|
@@ -3679,7 +3723,7 @@ async function Cr(e, n, r) {
|
|
|
3679
3723
|
}
|
|
3680
3724
|
//#endregion
|
|
3681
3725
|
//#region src/adapters/userPermissions.ts
|
|
3682
|
-
function
|
|
3726
|
+
function Er(e) {
|
|
3683
3727
|
return {
|
|
3684
3728
|
async create(t, n, r, i) {
|
|
3685
3729
|
try {
|
|
@@ -3718,7 +3762,7 @@ function wr(e) {
|
|
|
3718
3762
|
}
|
|
3719
3763
|
//#endregion
|
|
3720
3764
|
//#region src/adapters/roles.ts
|
|
3721
|
-
function
|
|
3765
|
+
function Dr(e) {
|
|
3722
3766
|
let { tenant_id: t, is_system: n, metadata: r, ...i } = e;
|
|
3723
3767
|
return D({
|
|
3724
3768
|
...i,
|
|
@@ -3726,7 +3770,7 @@ function Tr(e) {
|
|
|
3726
3770
|
metadata: Z(r)
|
|
3727
3771
|
});
|
|
3728
3772
|
}
|
|
3729
|
-
function
|
|
3773
|
+
function Or(e) {
|
|
3730
3774
|
return {
|
|
3731
3775
|
async create(t, n) {
|
|
3732
3776
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
@@ -3739,29 +3783,29 @@ function Er(e) {
|
|
|
3739
3783
|
created_at: r,
|
|
3740
3784
|
updated_at: r
|
|
3741
3785
|
};
|
|
3742
|
-
return await e.insert(U).values(i),
|
|
3786
|
+
return await e.insert(U).values(i), Dr({
|
|
3743
3787
|
...i,
|
|
3744
3788
|
tenant_id: t
|
|
3745
3789
|
});
|
|
3746
3790
|
},
|
|
3747
3791
|
async get(n, r) {
|
|
3748
3792
|
let i = await e.select().from(U).where(t(a(U.tenant_id, n), a(U.id, r))).get();
|
|
3749
|
-
return i ?
|
|
3793
|
+
return i ? Dr(i) : null;
|
|
3750
3794
|
},
|
|
3751
3795
|
async update(n, r, i) {
|
|
3752
3796
|
let o = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
3753
3797
|
return i.name !== void 0 && (o.name = i.name), i.description !== void 0 && (o.description = i.description), i.is_system !== void 0 && (o.is_system = +!!i.is_system), i.metadata !== void 0 && (o.metadata = JSON.stringify(i.metadata)), (await e.update(U).set(o).where(t(a(U.tenant_id, n), a(U.id, r))).returning()).length > 0;
|
|
3754
3798
|
},
|
|
3755
3799
|
async list(o, s) {
|
|
3756
|
-
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ?
|
|
3757
|
-
if (
|
|
3800
|
+
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ? vt(U, f, ["name"]) : void 0, m = p ? t(a(U.tenant_id, o), p) : a(U.tenant_id, o);
|
|
3801
|
+
if (At(s)) {
|
|
3758
3802
|
let n = {
|
|
3759
3803
|
sortColumn: U.created_at,
|
|
3760
3804
|
idColumn: U.id,
|
|
3761
3805
|
sortOrder: "desc"
|
|
3762
|
-
}, r =
|
|
3806
|
+
}, r = jt(s), { rows: i, next: a } = Pt(await e.select().from(U).where(t(m, Nt(s, n))).orderBy(...Mt(n)).limit(r + 1), r, "created_at");
|
|
3763
3807
|
return {
|
|
3764
|
-
roles: i.map(
|
|
3808
|
+
roles: i.map(Dr),
|
|
3765
3809
|
start: 0,
|
|
3766
3810
|
limit: r,
|
|
3767
3811
|
length: i.length,
|
|
@@ -3773,7 +3817,7 @@ function Er(e) {
|
|
|
3773
3817
|
let e = U[d.sort_by];
|
|
3774
3818
|
e && (h = h.orderBy(d.sort_order === "desc" ? i(e) : n(e)));
|
|
3775
3819
|
}
|
|
3776
|
-
let g = (await h.offset(c * l).limit(l)).map(
|
|
3820
|
+
let g = (await h.offset(c * l).limit(l)).map(Dr);
|
|
3777
3821
|
if (!u) return { roles: g };
|
|
3778
3822
|
let [_] = await e.select({ count: r() }).from(U).where(m);
|
|
3779
3823
|
return {
|
|
@@ -3790,7 +3834,7 @@ function Er(e) {
|
|
|
3790
3834
|
}
|
|
3791
3835
|
//#endregion
|
|
3792
3836
|
//#region src/adapters/sessions.ts
|
|
3793
|
-
var
|
|
3837
|
+
var kr = ["created_at_ts", "updated_at_ts"], Ar = [
|
|
3794
3838
|
"expires_at_ts",
|
|
3795
3839
|
"idle_expires_at_ts",
|
|
3796
3840
|
"authenticated_at_ts",
|
|
@@ -3798,7 +3842,7 @@ var Dr = ["created_at_ts", "updated_at_ts"], Or = [
|
|
|
3798
3842
|
"used_at_ts",
|
|
3799
3843
|
"revoked_at_ts"
|
|
3800
3844
|
];
|
|
3801
|
-
function
|
|
3845
|
+
function jr(e) {
|
|
3802
3846
|
let { tenant_id: t, created_at_ts: n, updated_at_ts: r, expires_at_ts: i, idle_expires_at_ts: a, authenticated_at_ts: o, last_interaction_at_ts: s, used_at_ts: c, revoked_at_ts: l, device: u, clients: d, ...f } = e, p = ae({
|
|
3803
3847
|
created_at_ts: n,
|
|
3804
3848
|
updated_at_ts: r,
|
|
@@ -3808,7 +3852,7 @@ function kr(e) {
|
|
|
3808
3852
|
last_interaction_at_ts: s,
|
|
3809
3853
|
used_at_ts: c,
|
|
3810
3854
|
revoked_at_ts: l
|
|
3811
|
-
}, [...
|
|
3855
|
+
}, [...kr], [...Ar]);
|
|
3812
3856
|
return D({
|
|
3813
3857
|
...f,
|
|
3814
3858
|
...p,
|
|
@@ -3816,10 +3860,10 @@ function kr(e) {
|
|
|
3816
3860
|
clients: Z(d, [])
|
|
3817
3861
|
});
|
|
3818
3862
|
}
|
|
3819
|
-
function
|
|
3863
|
+
function Mr(e, t) {
|
|
3820
3864
|
return Math.max(e ?? 0, t ?? 0);
|
|
3821
3865
|
}
|
|
3822
|
-
function
|
|
3866
|
+
function Nr(e) {
|
|
3823
3867
|
return {
|
|
3824
3868
|
async create(n, r) {
|
|
3825
3869
|
let i = Date.now(), o = {
|
|
@@ -3837,23 +3881,23 @@ function jr(e) {
|
|
|
3837
3881
|
last_interaction_at_ts: r.last_interaction_at ? E(r.last_interaction_at) : i,
|
|
3838
3882
|
used_at_ts: E(r.used_at),
|
|
3839
3883
|
revoked_at_ts: E(r.revoked_at)
|
|
3840
|
-
}, s = [e.insert(M).values(o)], c =
|
|
3884
|
+
}, s = [e.insert(M).values(o)], c = Mr(o.expires_at_ts, o.idle_expires_at_ts);
|
|
3841
3885
|
return c > 0 && o.login_session_id && s.push(e.update(P).set({
|
|
3842
3886
|
expires_at_ts: c,
|
|
3843
3887
|
updated_at_ts: i
|
|
3844
|
-
}).where(t(a(P.tenant_id, n), a(P.id, o.login_session_id), m(P.expires_at_ts, c)))), await
|
|
3888
|
+
}).where(t(a(P.tenant_id, n), a(P.id, o.login_session_id), m(P.expires_at_ts, c)))), await Tt(e, s), jr({
|
|
3845
3889
|
...o,
|
|
3846
3890
|
tenant_id: n
|
|
3847
3891
|
});
|
|
3848
3892
|
},
|
|
3849
3893
|
async get(n, r) {
|
|
3850
3894
|
let i = await e.select().from(M).where(t(a(M.tenant_id, n), a(M.id, r))).get();
|
|
3851
|
-
return i ?
|
|
3895
|
+
return i ? jr(i) : null;
|
|
3852
3896
|
},
|
|
3853
3897
|
async update(n, r, i) {
|
|
3854
3898
|
let o = { updated_at_ts: Date.now() };
|
|
3855
3899
|
i.user_id !== void 0 && (o.user_id = i.user_id), i.login_session_id !== void 0 && (o.login_session_id = i.login_session_id), i.device !== void 0 && (o.device = JSON.stringify(i.device)), i.clients !== void 0 && (o.clients = JSON.stringify(i.clients)), i.expires_at !== void 0 && (o.expires_at_ts = E(i.expires_at)), i.idle_expires_at !== void 0 && (o.idle_expires_at_ts = E(i.idle_expires_at)), i.authenticated_at !== void 0 && (o.authenticated_at_ts = E(i.authenticated_at)), i.last_interaction_at !== void 0 && (o.last_interaction_at_ts = E(i.last_interaction_at)), i.used_at !== void 0 && (o.used_at_ts = E(i.used_at)), i.revoked_at !== void 0 && (o.revoked_at_ts = E(i.revoked_at));
|
|
3856
|
-
let s = await e.update(M).set(o).where(t(a(M.tenant_id, n), a(M.id, r))).returning(), c =
|
|
3900
|
+
let s = await e.update(M).set(o).where(t(a(M.tenant_id, n), a(M.id, r))).returning(), c = Mr(o.expires_at_ts, o.idle_expires_at_ts), l = s[0];
|
|
3857
3901
|
if (c > 0 && l) {
|
|
3858
3902
|
let r = i.login_session_id ?? l.login_session_id;
|
|
3859
3903
|
r && await e.update(P).set({
|
|
@@ -3864,12 +3908,12 @@ function jr(e) {
|
|
|
3864
3908
|
return s.length > 0;
|
|
3865
3909
|
},
|
|
3866
3910
|
async list(o, s) {
|
|
3867
|
-
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ?
|
|
3911
|
+
let { page: c = 0, per_page: l = 50, include_totals: u = !1, sort: d, q: f } = s || {}, p = f ? vt(M, f, ["user_id", "id"]) : void 0, m = p ? t(a(M.tenant_id, o), p) : a(M.tenant_id, o), h = e.select().from(M).where(m).$dynamic();
|
|
3868
3912
|
if (d?.sort_by) {
|
|
3869
3913
|
let e = M[d.sort_by];
|
|
3870
3914
|
e && (h = h.orderBy(d.sort_order === "desc" ? i(e) : n(e)));
|
|
3871
3915
|
}
|
|
3872
|
-
let g = (await h.offset(c * l).limit(l)).map(
|
|
3916
|
+
let g = (await h.offset(c * l).limit(l)).map(jr);
|
|
3873
3917
|
if (!u) return { sessions: g };
|
|
3874
3918
|
let [_] = await e.select({ count: r() }).from(M).where(m);
|
|
3875
3919
|
return {
|
|
@@ -3886,7 +3930,7 @@ function jr(e) {
|
|
|
3886
3930
|
}
|
|
3887
3931
|
//#endregion
|
|
3888
3932
|
//#region src/adapters/tenants.ts
|
|
3889
|
-
var
|
|
3933
|
+
var Pr = [
|
|
3890
3934
|
"session_cookie",
|
|
3891
3935
|
"enabled_locales",
|
|
3892
3936
|
"error_page",
|
|
@@ -3902,25 +3946,25 @@ var Mr = [
|
|
|
3902
3946
|
"acr_values_supported",
|
|
3903
3947
|
"mtls",
|
|
3904
3948
|
"mfa"
|
|
3905
|
-
],
|
|
3949
|
+
], Fr = [
|
|
3906
3950
|
"allow_organization_name_in_authentication_api",
|
|
3907
3951
|
"customize_mfa_in_postlogin_action",
|
|
3908
3952
|
"pushed_authorization_requests_supported",
|
|
3909
3953
|
"authorization_response_iss_parameter_supported"
|
|
3910
3954
|
];
|
|
3911
|
-
function
|
|
3955
|
+
function Ir(e) {
|
|
3912
3956
|
let t = { ...e };
|
|
3913
|
-
for (let e of
|
|
3914
|
-
for (let e of
|
|
3957
|
+
for (let e of Pr) typeof t[e] == "string" && (t[e] = Z(t[e]));
|
|
3958
|
+
for (let e of Fr) t[e] !== void 0 && t[e] !== null && (t[e] = t[e] === 1);
|
|
3915
3959
|
return D(t);
|
|
3916
3960
|
}
|
|
3917
|
-
function
|
|
3961
|
+
function Lr(e) {
|
|
3918
3962
|
let t = { ...e };
|
|
3919
|
-
le(e,
|
|
3920
|
-
for (let n of
|
|
3963
|
+
le(e, Pr, t);
|
|
3964
|
+
for (let n of Fr) e[n] !== void 0 && (t[n] = +!!e[n]);
|
|
3921
3965
|
return ce(t);
|
|
3922
3966
|
}
|
|
3923
|
-
function
|
|
3967
|
+
function Rr(e) {
|
|
3924
3968
|
return {
|
|
3925
3969
|
async create(t) {
|
|
3926
3970
|
let n = {
|
|
@@ -3928,7 +3972,7 @@ function Ir(e) {
|
|
|
3928
3972
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3929
3973
|
updated_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3930
3974
|
...t
|
|
3931
|
-
}, r =
|
|
3975
|
+
}, r = Lr(n);
|
|
3932
3976
|
try {
|
|
3933
3977
|
await e.insert(O).values(r);
|
|
3934
3978
|
} catch (e) {
|
|
@@ -3939,15 +3983,15 @@ function Ir(e) {
|
|
|
3939
3983
|
},
|
|
3940
3984
|
async get(t) {
|
|
3941
3985
|
let n = await e.select().from(O).where(a(O.id, t)).get();
|
|
3942
|
-
return n ?
|
|
3986
|
+
return n ? Ir(n) : null;
|
|
3943
3987
|
},
|
|
3944
3988
|
async list(t) {
|
|
3945
|
-
let { page: a = 0, per_page: o = 50, include_totals: s = !1, sort: c, q: l } = t || {}, u = l ?
|
|
3989
|
+
let { page: a = 0, per_page: o = 50, include_totals: s = !1, sort: c, q: l } = t || {}, u = l ? vt(O, l, ["friendly_name"]) : void 0, d = e.select().from(O).$dynamic();
|
|
3946
3990
|
if (u && (d = d.where(u)), c?.sort_by) {
|
|
3947
3991
|
let e = O[c.sort_by];
|
|
3948
3992
|
e && (d = d.orderBy(c.sort_order === "desc" ? i(e) : n(e)));
|
|
3949
3993
|
}
|
|
3950
|
-
let f = (await d.offset(a * o).limit(o)).map(
|
|
3994
|
+
let f = (await d.offset(a * o).limit(o)).map(Ir);
|
|
3951
3995
|
if (!s) return { tenants: f };
|
|
3952
3996
|
let p = e.select({ count: r() }).from(O).$dynamic();
|
|
3953
3997
|
u && (p = p.where(u));
|
|
@@ -3960,7 +4004,7 @@ function Ir(e) {
|
|
|
3960
4004
|
};
|
|
3961
4005
|
},
|
|
3962
4006
|
async update(t, n) {
|
|
3963
|
-
let r =
|
|
4007
|
+
let r = Lr({
|
|
3964
4008
|
...n,
|
|
3965
4009
|
id: t,
|
|
3966
4010
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
@@ -3974,38 +4018,38 @@ function Ir(e) {
|
|
|
3974
4018
|
}
|
|
3975
4019
|
//#endregion
|
|
3976
4020
|
//#region src/adapters/themes.ts
|
|
3977
|
-
var
|
|
4021
|
+
var zr = [
|
|
3978
4022
|
"colors",
|
|
3979
4023
|
"borders",
|
|
3980
4024
|
"fonts",
|
|
3981
4025
|
"page_background",
|
|
3982
4026
|
"widget"
|
|
3983
4027
|
];
|
|
3984
|
-
function
|
|
3985
|
-
let { tenant_id: t, ...n } = e, r =
|
|
4028
|
+
function Br(e) {
|
|
4029
|
+
let { tenant_id: t, ...n } = e, r = ht(n, zr);
|
|
3986
4030
|
return r.borders && (r.borders.show_widget_shadow = !!r.borders.show_widget_shadow), r.fonts && (r.fonts.body_text_bold = !!r.fonts.body_text_bold, r.fonts.buttons_text_bold = !!r.fonts.buttons_text_bold, r.fonts.input_labels_bold = !!r.fonts.input_labels_bold, r.fonts.links_bold = !!r.fonts.links_bold, r.fonts.subtitle_bold = !!r.fonts.subtitle_bold, r.fonts.title_bold = !!r.fonts.title_bold), D(r);
|
|
3987
4031
|
}
|
|
3988
|
-
function
|
|
4032
|
+
function Vr(e) {
|
|
3989
4033
|
return {
|
|
3990
4034
|
async create(t, n, r, i) {
|
|
3991
4035
|
let a = i?.importMetadata, o = (/* @__PURE__ */ new Date()).toISOString(), s = a?.id || r || b(), c = {
|
|
3992
|
-
...
|
|
4036
|
+
...mt(n),
|
|
3993
4037
|
tenant_id: t,
|
|
3994
4038
|
themeId: s,
|
|
3995
4039
|
created_at: a?.created_at ?? o,
|
|
3996
4040
|
updated_at: a?.updated_at ?? o
|
|
3997
4041
|
};
|
|
3998
|
-
return await e.insert(Qe).values(c),
|
|
4042
|
+
return await e.insert(Qe).values(c), Br({
|
|
3999
4043
|
...c,
|
|
4000
4044
|
tenant_id: t
|
|
4001
4045
|
});
|
|
4002
4046
|
},
|
|
4003
4047
|
async get(n, r) {
|
|
4004
4048
|
let i = await e.select().from(Qe).where(t(a(Qe.tenant_id, n), a(Qe.themeId, r))).get();
|
|
4005
|
-
return i ?
|
|
4049
|
+
return i ? Br(i) : null;
|
|
4006
4050
|
},
|
|
4007
4051
|
async update(n, r, i) {
|
|
4008
|
-
let o =
|
|
4052
|
+
let o = mt(i);
|
|
4009
4053
|
return o.updated_at = (/* @__PURE__ */ new Date()).toISOString(), await e.update(Qe).set(o).where(t(a(Qe.tenant_id, n), a(Qe.themeId, r))), !0;
|
|
4010
4054
|
},
|
|
4011
4055
|
async remove(n, r) {
|
|
@@ -4015,7 +4059,7 @@ function zr(e) {
|
|
|
4015
4059
|
}
|
|
4016
4060
|
//#endregion
|
|
4017
4061
|
//#region src/adapters/universalLoginTemplates.ts
|
|
4018
|
-
function
|
|
4062
|
+
function Hr(e) {
|
|
4019
4063
|
return {
|
|
4020
4064
|
async get(t) {
|
|
4021
4065
|
let n = await e.select({ body: Ze.body }).from(Ze).where(a(Ze.tenant_id, t)).get();
|
|
@@ -4043,11 +4087,11 @@ function Br(e) {
|
|
|
4043
4087
|
}
|
|
4044
4088
|
//#endregion
|
|
4045
4089
|
//#region src/adapters/userActivity.ts
|
|
4046
|
-
function
|
|
4090
|
+
function Ur(e) {
|
|
4047
4091
|
let t = {};
|
|
4048
4092
|
return e.last_login !== void 0 && (t.last_login = e.last_login), e.last_ip !== void 0 && (t.last_ip = e.last_ip), e.login_count !== void 0 && (t.login_count = e.login_count), e.failed_logins !== void 0 && (t.failed_logins = JSON.stringify(e.failed_logins)), e.last_password_reset !== void 0 && (t.last_password_reset = e.last_password_reset), t;
|
|
4049
4093
|
}
|
|
4050
|
-
function
|
|
4094
|
+
function Wr(e) {
|
|
4051
4095
|
return {
|
|
4052
4096
|
async get(n, r) {
|
|
4053
4097
|
let i = await e.select().from(He).where(t(a(He.tenant_id, n), a(He.user_id, r))).get();
|
|
@@ -4061,7 +4105,7 @@ function Hr(e) {
|
|
|
4061
4105
|
} : null;
|
|
4062
4106
|
},
|
|
4063
4107
|
async upsert(t, n, r) {
|
|
4064
|
-
let i =
|
|
4108
|
+
let i = Ur(r), a = e.insert(He).values({
|
|
4065
4109
|
tenant_id: t,
|
|
4066
4110
|
user_id: n,
|
|
4067
4111
|
login_count: 0,
|
|
@@ -4080,13 +4124,13 @@ function Hr(e) {
|
|
|
4080
4124
|
}
|
|
4081
4125
|
//#endregion
|
|
4082
4126
|
//#region src/adapters/outbox.ts
|
|
4083
|
-
function
|
|
4127
|
+
function Gr(e) {
|
|
4084
4128
|
return {
|
|
4085
4129
|
...e,
|
|
4086
4130
|
payload: Z(e.payload, {})
|
|
4087
4131
|
};
|
|
4088
4132
|
}
|
|
4089
|
-
function
|
|
4133
|
+
function Kr(e, t, n, r) {
|
|
4090
4134
|
return e.insert(J).values({
|
|
4091
4135
|
id: t,
|
|
4092
4136
|
tenant_id: n,
|
|
@@ -4107,18 +4151,18 @@ function Wr(e, t, n, r) {
|
|
|
4107
4151
|
claim_expires_at: null
|
|
4108
4152
|
});
|
|
4109
4153
|
}
|
|
4110
|
-
function
|
|
4154
|
+
function qr(e) {
|
|
4111
4155
|
return {
|
|
4112
4156
|
async create(t, n) {
|
|
4113
4157
|
let r = b();
|
|
4114
|
-
return await
|
|
4158
|
+
return await Kr(e, r, t, n), r;
|
|
4115
4159
|
},
|
|
4116
4160
|
async getByIds(t) {
|
|
4117
|
-
return t.length === 0 ? [] : (await e.select().from(J).where(l(J.id, t)).all()).map(
|
|
4161
|
+
return t.length === 0 ? [] : (await e.select().from(J).where(l(J.id, t)).all()).map(Gr);
|
|
4118
4162
|
},
|
|
4119
4163
|
async getUnprocessed(n) {
|
|
4120
4164
|
let r = (/* @__PURE__ */ new Date()).toISOString();
|
|
4121
|
-
return (await e.select().from(J).where(t(f(J.processed_at), v(f(J.next_retry_at), h(J.next_retry_at, r)), v(f(J.claimed_by), h(J.claim_expires_at, r)))).orderBy(J.created_at, J.id).limit(n).all()).map(
|
|
4165
|
+
return (await e.select().from(J).where(t(f(J.processed_at), v(f(J.next_retry_at), h(J.next_retry_at, r)), v(f(J.claimed_by), h(J.claim_expires_at, r)))).orderBy(J.created_at, J.id).limit(n).all()).map(Gr);
|
|
4122
4166
|
},
|
|
4123
4167
|
async claimEvents(n, r, i) {
|
|
4124
4168
|
if (n.length === 0) return [];
|
|
@@ -4193,10 +4237,10 @@ function Gr(e) {
|
|
|
4193
4237
|
}
|
|
4194
4238
|
//#endregion
|
|
4195
4239
|
//#region src/adapters/users.ts
|
|
4196
|
-
function
|
|
4197
|
-
return (n?.outboxEvents ?? []).map((n) =>
|
|
4240
|
+
function Jr(e, t, n) {
|
|
4241
|
+
return (n?.outboxEvents ?? []).map((n) => Kr(e, n.id, t, n));
|
|
4198
4242
|
}
|
|
4199
|
-
var
|
|
4243
|
+
var Yr = [
|
|
4200
4244
|
"user_id",
|
|
4201
4245
|
"email",
|
|
4202
4246
|
"email_verified",
|
|
@@ -4218,23 +4262,23 @@ var qr = [
|
|
|
4218
4262
|
"login_count",
|
|
4219
4263
|
"created_at",
|
|
4220
4264
|
"updated_at"
|
|
4221
|
-
],
|
|
4265
|
+
], Xr = [
|
|
4222
4266
|
"email",
|
|
4223
4267
|
"name",
|
|
4224
4268
|
"phone_number",
|
|
4225
4269
|
"user_id"
|
|
4226
|
-
],
|
|
4270
|
+
], Zr = new Set([
|
|
4227
4271
|
"last_login",
|
|
4228
4272
|
"last_ip",
|
|
4229
4273
|
"login_count"
|
|
4230
|
-
]),
|
|
4274
|
+
]), Qr = o(A), $r = o(He), ei = Object.fromEntries(Yr.map((e) => [e, e === "login_count" ? {
|
|
4231
4275
|
coalesce: He.login_count,
|
|
4232
4276
|
defaultValue: 0
|
|
4233
|
-
} :
|
|
4234
|
-
function
|
|
4277
|
+
} : Zr.has(e) ? $r[e] : Qr[e]]));
|
|
4278
|
+
function ti() {
|
|
4235
4279
|
return t(a(He.tenant_id, A.tenant_id), a(He.user_id, A.user_id));
|
|
4236
4280
|
}
|
|
4237
|
-
function
|
|
4281
|
+
function ni(e, t) {
|
|
4238
4282
|
return {
|
|
4239
4283
|
...e,
|
|
4240
4284
|
last_login: t?.last_login,
|
|
@@ -4242,7 +4286,7 @@ function ei(e, t) {
|
|
|
4242
4286
|
login_count: t?.login_count ?? 0
|
|
4243
4287
|
};
|
|
4244
4288
|
}
|
|
4245
|
-
function
|
|
4289
|
+
function ri(e, t) {
|
|
4246
4290
|
let n = {
|
|
4247
4291
|
connection: e.connection,
|
|
4248
4292
|
provider: e.provider,
|
|
@@ -4255,8 +4299,8 @@ function ti(e, t) {
|
|
|
4255
4299
|
...typeof e.profileData == "string" ? Z(e.profileData, {}) : {}
|
|
4256
4300
|
}, n;
|
|
4257
4301
|
}
|
|
4258
|
-
function
|
|
4259
|
-
let { tenant_id: n, app_metadata: r, user_metadata: i, address: a, email_verified: o, phone_verified: s, is_social: c, blocked: l, linked_to: u, profileData: d, ...f } = e, p =
|
|
4302
|
+
function ii(e, t = []) {
|
|
4303
|
+
let { tenant_id: n, app_metadata: r, user_metadata: i, address: a, email_verified: o, phone_verified: s, is_social: c, blocked: l, linked_to: u, profileData: d, ...f } = e, p = ri(e, !0), m = t.map((e) => ri(e, !1));
|
|
4260
4304
|
return D({
|
|
4261
4305
|
...f,
|
|
4262
4306
|
email: e.email || "",
|
|
@@ -4270,7 +4314,7 @@ function ni(e, t = []) {
|
|
|
4270
4314
|
identities: [p, ...m]
|
|
4271
4315
|
});
|
|
4272
4316
|
}
|
|
4273
|
-
function
|
|
4317
|
+
function ai(e) {
|
|
4274
4318
|
let o = async (t, n, r) => {
|
|
4275
4319
|
let i = (/* @__PURE__ */ new Date()).toISOString(), a = {
|
|
4276
4320
|
user_id: n.user_id,
|
|
@@ -4324,12 +4368,12 @@ function ri(e) {
|
|
|
4324
4368
|
created_at: i,
|
|
4325
4369
|
updated_at: i
|
|
4326
4370
|
}));
|
|
4327
|
-
for (let n of
|
|
4328
|
-
c.length > 1 ? await
|
|
4371
|
+
for (let n of Jr(e, t, r)) c.push(n);
|
|
4372
|
+
c.length > 1 ? await Tt(e, c) : await e.insert(A).values(a);
|
|
4329
4373
|
} catch (e) {
|
|
4330
4374
|
throw e?.message?.includes("UNIQUE constraint") || e?.message?.includes("AlreadyExists") ? new Le(409, { message: "User already exists" }) : (console.error("User upsert failed:", e?.code, e?.message), new Le(500, { message: "Internal server error" }));
|
|
4331
4375
|
}
|
|
4332
|
-
return
|
|
4376
|
+
return ii({
|
|
4333
4377
|
...a,
|
|
4334
4378
|
last_login: n.last_login,
|
|
4335
4379
|
last_ip: n.last_ip,
|
|
@@ -4340,10 +4384,10 @@ function ri(e) {
|
|
|
4340
4384
|
create: o,
|
|
4341
4385
|
rawCreate: o,
|
|
4342
4386
|
async get(n, r) {
|
|
4343
|
-
let i = await e.select().from(A).leftJoin(He,
|
|
4387
|
+
let i = await e.select().from(A).leftJoin(He, ti()).where(t(a(A.tenant_id, n), a(A.user_id, r))).get();
|
|
4344
4388
|
if (!i) return null;
|
|
4345
4389
|
let o = await e.select().from(A).where(t(a(A.tenant_id, n), a(A.linked_to, r))).all();
|
|
4346
|
-
return ni(
|
|
4390
|
+
return ii(ni(i.users, i.user_activity), o);
|
|
4347
4391
|
},
|
|
4348
4392
|
async update(n, r, i, o) {
|
|
4349
4393
|
let s = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
@@ -4370,8 +4414,8 @@ function ri(e) {
|
|
|
4370
4414
|
"zoneinfo"
|
|
4371
4415
|
]) i[e] !== void 0 && (s[e] = i[e]);
|
|
4372
4416
|
i.email_verified !== void 0 && (s.email_verified = i.email_verified), i.phone_verified !== void 0 && (s.phone_verified = i.phone_verified), i.is_social !== void 0 && (s.is_social = i.is_social), i.blocked !== void 0 && (s.blocked = i.blocked), i.app_metadata !== void 0 && (s.app_metadata = JSON.stringify(i.app_metadata)), i.user_metadata !== void 0 && (s.user_metadata = JSON.stringify(i.user_metadata)), i.address !== void 0 && (s.address = JSON.stringify(i.address)), i.profileData !== void 0 && (s.profileData = JSON.stringify(i.profileData));
|
|
4373
|
-
let c = e.update(A).set(s).where(t(a(A.tenant_id, n), a(A.user_id, r))).returning(), l =
|
|
4374
|
-
return u = l.length > 0 ? (await
|
|
4417
|
+
let c = e.update(A).set(s).where(t(a(A.tenant_id, n), a(A.user_id, r))).returning(), l = Jr(e, n, o), u;
|
|
4418
|
+
return u = l.length > 0 ? (await Tt(e, [c, ...l]))[0] : await c, !Array.isArray(u) || u.length === 0 ? !1 : ((i.last_login !== void 0 || i.last_ip !== void 0 || i.login_count !== void 0) && await Wr(e).upsert(n, r, {
|
|
4375
4419
|
last_login: i.last_login,
|
|
4376
4420
|
last_ip: i.last_ip,
|
|
4377
4421
|
login_count: i.login_count
|
|
@@ -4380,24 +4424,24 @@ function ri(e) {
|
|
|
4380
4424
|
async list(o, s) {
|
|
4381
4425
|
let { page: c = 0, per_page: u = 50, include_totals: d = !1, sort: p, q: m } = s || {}, h = [a(A.tenant_id, o), f(A.linked_to)];
|
|
4382
4426
|
if (m) {
|
|
4383
|
-
let e = Te(m,
|
|
4427
|
+
let e = Te(m, Yr);
|
|
4384
4428
|
if (e) {
|
|
4385
|
-
let t =
|
|
4429
|
+
let t = vt(ei, e, Xr);
|
|
4386
4430
|
t && h.push(t);
|
|
4387
4431
|
}
|
|
4388
4432
|
}
|
|
4389
4433
|
let g = t(...h), _ = async (n) => {
|
|
4390
4434
|
let r = n.map((e) => e.user_id), i = r.length > 0 ? await e.select().from(A).where(t(a(A.tenant_id, o), l(A.linked_to, r))) : [];
|
|
4391
|
-
return n.map((e) =>
|
|
4435
|
+
return n.map((e) => ii(e, i.filter((t) => t.linked_to === e.user_id)));
|
|
4392
4436
|
};
|
|
4393
|
-
if (
|
|
4437
|
+
if (At(s)) {
|
|
4394
4438
|
if (p?.sort_by && p.sort_by !== "created_at") throw new Le(400, { message: `Sorting by ${p.sort_by} is not supported with checkpoint pagination (from/take); only created_at is` });
|
|
4395
4439
|
let n = p?.sort_order === "asc" ? "asc" : "desc", r = {
|
|
4396
4440
|
sortColumn: A.created_at,
|
|
4397
4441
|
idColumn: A.user_id,
|
|
4398
4442
|
sortOrder: n,
|
|
4399
4443
|
sortKey: `created_at:${n}`
|
|
4400
|
-
}, i =
|
|
4444
|
+
}, i = jt(s), a = Nt(s, r), { rows: o, next: c } = Pt((await e.select().from(A).leftJoin(He, ti()).where(a ? t(g, a) : g).orderBy(...Mt(r)).limit(i + 1)).map((e) => ni(e.users, e.user_activity)), i, "created_at", "user_id", r.sortKey), l = await _(o);
|
|
4401
4445
|
return {
|
|
4402
4446
|
users: l,
|
|
4403
4447
|
start: 0,
|
|
@@ -4406,15 +4450,15 @@ function ri(e) {
|
|
|
4406
4450
|
next: c
|
|
4407
4451
|
};
|
|
4408
4452
|
}
|
|
4409
|
-
let v = e.select().from(A).leftJoin(He,
|
|
4453
|
+
let v = e.select().from(A).leftJoin(He, ti()).where(g).$dynamic();
|
|
4410
4454
|
if (p?.sort_by) {
|
|
4411
|
-
let e =
|
|
4455
|
+
let e = ei[p.sort_by];
|
|
4412
4456
|
if (e) {
|
|
4413
|
-
let t =
|
|
4457
|
+
let t = gt(e) ? _t(e) : e;
|
|
4414
4458
|
v = v.orderBy(p.sort_order === "desc" ? i(t) : n(t));
|
|
4415
4459
|
}
|
|
4416
4460
|
}
|
|
4417
|
-
let [y, ee] = await Promise.all([v.offset(c * u).limit(u), d ? e.select({ count: r() }).from(A).leftJoin(He,
|
|
4461
|
+
let [y, ee] = await Promise.all([v.offset(c * u).limit(u), d ? e.select({ count: r() }).from(A).leftJoin(He, ti()).where(g) : void 0]), b = await _(y.map((e) => ni(e.users, e.user_activity)));
|
|
4418
4462
|
if (!ee) return { users: b };
|
|
4419
4463
|
let [te] = ee;
|
|
4420
4464
|
return {
|
|
@@ -4426,14 +4470,14 @@ function ri(e) {
|
|
|
4426
4470
|
},
|
|
4427
4471
|
async remove(n, r, i) {
|
|
4428
4472
|
let o = await e.select({ user_id: A.user_id }).from(A).where(t(a(A.tenant_id, n), v(a(A.user_id, r), a(A.linked_to, r)))), s = o.some((e) => e.user_id === r), c = o.map((e) => e.user_id).filter((e) => e !== r), u = [r, ...c], d = [
|
|
4429
|
-
e.delete(
|
|
4473
|
+
e.delete(lt).where(t(a(lt.tenant_id, n), l(lt.user_id, u))),
|
|
4430
4474
|
e.delete(j).where(t(a(j.tenant_id, n), l(j.user_id, u))),
|
|
4431
4475
|
e.delete(He).where(t(a(He.tenant_id, n), l(He.user_id, u))),
|
|
4432
4476
|
e.delete(A).where(t(a(A.tenant_id, n), l(A.user_id, c))),
|
|
4433
4477
|
e.delete(A).where(t(a(A.tenant_id, n), a(A.user_id, r))).returning()
|
|
4434
4478
|
], f = d.length - 1;
|
|
4435
|
-
if (s) for (let t of
|
|
4436
|
-
let p = (await
|
|
4479
|
+
if (s) for (let t of Jr(e, n, i)) d.push(t);
|
|
4480
|
+
let p = (await Tt(e, d))[f];
|
|
4437
4481
|
return Array.isArray(p) && p.length > 0;
|
|
4438
4482
|
},
|
|
4439
4483
|
async unlink(n, r, i, o) {
|
|
@@ -4444,7 +4488,7 @@ function ri(e) {
|
|
|
4444
4488
|
}
|
|
4445
4489
|
//#endregion
|
|
4446
4490
|
//#region src/adapters/userRoles.ts
|
|
4447
|
-
function
|
|
4491
|
+
function oi(e) {
|
|
4448
4492
|
return {
|
|
4449
4493
|
async create(t, n, r, i) {
|
|
4450
4494
|
try {
|
|
@@ -4478,12 +4522,12 @@ function ii(e) {
|
|
|
4478
4522
|
},
|
|
4479
4523
|
async listUsers(r, i, o) {
|
|
4480
4524
|
let s = t(a(G.tenant_id, r), a(G.role_id, i));
|
|
4481
|
-
if (
|
|
4525
|
+
if (At(o)) {
|
|
4482
4526
|
let n = {
|
|
4483
4527
|
sortColumn: G.user_id,
|
|
4484
4528
|
idColumn: G.user_id,
|
|
4485
4529
|
sortOrder: "asc"
|
|
4486
|
-
}, r =
|
|
4530
|
+
}, r = Nt(o, n), i = jt(o), { rows: a, next: c } = Pt(await e.selectDistinct({ user_id: G.user_id }).from(G).where(r ? t(s, r) : s).orderBy(...Mt(n)).limit(i + 1).all(), i, "user_id", "user_id");
|
|
4487
4531
|
return {
|
|
4488
4532
|
userIds: a.map((e) => e.user_id),
|
|
4489
4533
|
start: 0,
|
|
@@ -4507,7 +4551,7 @@ function ii(e) {
|
|
|
4507
4551
|
}
|
|
4508
4552
|
//#endregion
|
|
4509
4553
|
//#region src/adapters/userOrganizations.ts
|
|
4510
|
-
function
|
|
4554
|
+
function si(e) {
|
|
4511
4555
|
return {
|
|
4512
4556
|
async create(t, n) {
|
|
4513
4557
|
let r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
@@ -4539,19 +4583,19 @@ function ai(e) {
|
|
|
4539
4583
|
async list(n, o) {
|
|
4540
4584
|
let { include_totals: s = !1, q: c } = o || {}, l = a(H.tenant_id, n), u = l;
|
|
4541
4585
|
if (c) {
|
|
4542
|
-
let e =
|
|
4586
|
+
let e = vt(H, c, ["user_id", "organization_id"]);
|
|
4543
4587
|
e && (u = t(l, e));
|
|
4544
4588
|
}
|
|
4545
4589
|
let d = (e) => {
|
|
4546
4590
|
let { tenant_id: t, ...n } = e;
|
|
4547
4591
|
return n;
|
|
4548
4592
|
};
|
|
4549
|
-
if (
|
|
4593
|
+
if (At(o)) {
|
|
4550
4594
|
let n = {
|
|
4551
4595
|
sortColumn: H.created_at,
|
|
4552
4596
|
idColumn: H.id,
|
|
4553
4597
|
sortOrder: "desc"
|
|
4554
|
-
}, r =
|
|
4598
|
+
}, r = Nt(o, n), i = jt(o), { rows: a, next: s } = Pt((await e.select().from(H).where(r ? t(u, r) : u).orderBy(...Mt(n)).limit(i + 1)).map(d), i, "created_at");
|
|
4555
4599
|
return {
|
|
4556
4600
|
userOrganizations: a,
|
|
4557
4601
|
start: 0,
|
|
@@ -4599,19 +4643,19 @@ function ai(e) {
|
|
|
4599
4643
|
}
|
|
4600
4644
|
//#endregion
|
|
4601
4645
|
//#region src/adapters/stats.ts
|
|
4602
|
-
var
|
|
4603
|
-
function
|
|
4646
|
+
var ci = ["s"], li = ["pwd_leak"];
|
|
4647
|
+
function ui(e) {
|
|
4604
4648
|
return /^\d{8}$/.test(e) ? `${e.slice(0, 4)}-${e.slice(4, 6)}-${e.slice(6, 8)}` : e;
|
|
4605
4649
|
}
|
|
4606
|
-
function
|
|
4650
|
+
function di(e) {
|
|
4607
4651
|
return {
|
|
4608
4652
|
async getDaily(n, r) {
|
|
4609
|
-
let i = /* @__PURE__ */ new Date(), o = r?.from ?
|
|
4653
|
+
let i = /* @__PURE__ */ new Date(), o = r?.from ? ui(r.from) : (/* @__PURE__ */ new Date(i.getTime() - 720 * 60 * 60 * 1e3)).toISOString().split("T")[0], s = r?.to ? ui(r.to) : i.toISOString().split("T")[0];
|
|
4610
4654
|
return (await e.select({
|
|
4611
4655
|
date: y`substr(${q.date}, 1, 10)`.as("date"),
|
|
4612
|
-
logins: y`SUM(CASE WHEN ${q.type} IN (${y.join(
|
|
4656
|
+
logins: y`SUM(CASE WHEN ${q.type} IN (${y.join(ci.map((e) => y`${e}`), y`, `)}) THEN 1 ELSE 0 END)`.as("logins"),
|
|
4613
4657
|
signups: y`SUM(CASE WHEN ${q.type} = 'ss' THEN 1 ELSE 0 END)`.as("signups"),
|
|
4614
|
-
leaked_passwords: y`SUM(CASE WHEN ${q.type} IN (${y.join(
|
|
4658
|
+
leaked_passwords: y`SUM(CASE WHEN ${q.type} IN (${y.join(li.map((e) => y`${e}`), y`, `)}) THEN 1 ELSE 0 END)`.as("leaked_passwords")
|
|
4615
4659
|
}).from(q).where(t(a(q.tenant_id, n), c(q.date, o), h(q.date, `${s}T23:59:59.999Z`))).groupBy(y`substr(${q.date}, 1, 10)`).orderBy(y`substr(${q.date}, 1, 10)`).all()).map((e) => ({
|
|
4616
4660
|
date: e.date,
|
|
4617
4661
|
logins: Number(e.logins) || 0,
|
|
@@ -4622,14 +4666,14 @@ function li(e) {
|
|
|
4622
4666
|
}));
|
|
4623
4667
|
},
|
|
4624
4668
|
async getActiveUsers(n) {
|
|
4625
|
-
let r = (/* @__PURE__ */ new Date(Date.now() - 720 * 60 * 60 * 1e3)).toISOString(), [i] = await e.select({ count: y`COUNT(DISTINCT ${q.user_id})`.as("count") }).from(q).where(t(a(q.tenant_id, n), c(q.date, r), y`${q.type} IN (${y.join(
|
|
4669
|
+
let r = (/* @__PURE__ */ new Date(Date.now() - 720 * 60 * 60 * 1e3)).toISOString(), [i] = await e.select({ count: y`COUNT(DISTINCT ${q.user_id})`.as("count") }).from(q).where(t(a(q.tenant_id, n), c(q.date, r), y`${q.type} IN (${y.join(ci.map((e) => y`${e}`), y`, `)})`));
|
|
4626
4670
|
return Number(i?.count) || 0;
|
|
4627
4671
|
}
|
|
4628
4672
|
};
|
|
4629
4673
|
}
|
|
4630
4674
|
//#endregion
|
|
4631
4675
|
//#region src/adapters/analytics.ts
|
|
4632
|
-
var
|
|
4676
|
+
var fi = {
|
|
4633
4677
|
"active-users": ["s", "seacft"],
|
|
4634
4678
|
logins: [
|
|
4635
4679
|
"s",
|
|
@@ -4659,7 +4703,7 @@ var ui = {
|
|
|
4659
4703
|
"fvr"
|
|
4660
4704
|
],
|
|
4661
4705
|
"codes-sent": ["cls", "cs"]
|
|
4662
|
-
},
|
|
4706
|
+
}, pi = {
|
|
4663
4707
|
"active-users": {
|
|
4664
4708
|
alias: "active_users",
|
|
4665
4709
|
type: "UInt64",
|
|
@@ -4716,7 +4760,7 @@ var ui = {
|
|
|
4716
4760
|
agg: "count"
|
|
4717
4761
|
}
|
|
4718
4762
|
};
|
|
4719
|
-
function
|
|
4763
|
+
function mi(e) {
|
|
4720
4764
|
switch (e) {
|
|
4721
4765
|
case "hour": return y`substr(${q.date}, 1, 13)`;
|
|
4722
4766
|
case "month": return y`substr(${q.date}, 1, 7)`;
|
|
@@ -4725,10 +4769,10 @@ function fi(e) {
|
|
|
4725
4769
|
default: throw Error(`Unsupported interval '${e}' for SQL analytics adapter`);
|
|
4726
4770
|
}
|
|
4727
4771
|
}
|
|
4728
|
-
function
|
|
4772
|
+
function hi(e) {
|
|
4729
4773
|
return `"${e.replace(/"/g, "\"\"")}"`;
|
|
4730
4774
|
}
|
|
4731
|
-
function
|
|
4775
|
+
function gi(e) {
|
|
4732
4776
|
switch (e) {
|
|
4733
4777
|
case "connection": return q.connection;
|
|
4734
4778
|
case "client_id": return q.client_id;
|
|
@@ -4737,10 +4781,10 @@ function mi(e) {
|
|
|
4737
4781
|
case "time": throw Error("time dimension handled separately");
|
|
4738
4782
|
}
|
|
4739
4783
|
}
|
|
4740
|
-
function
|
|
4784
|
+
function _i(e) {
|
|
4741
4785
|
return {
|
|
4742
4786
|
async query(n, r, i) {
|
|
4743
|
-
let o = Date.now(), s =
|
|
4787
|
+
let o = Date.now(), s = fi[r], u = pi[r], d = [
|
|
4744
4788
|
a(q.tenant_id, n),
|
|
4745
4789
|
c(q.date, i.from),
|
|
4746
4790
|
m(q.date, i.to),
|
|
@@ -4749,13 +4793,13 @@ function hi(e) {
|
|
|
4749
4793
|
i.filters.connection?.length && d.push(l(q.connection, i.filters.connection)), i.filters.client_id?.length && d.push(l(q.client_id, i.filters.client_id)), i.filters.user_type?.length && d.push(l(q.strategy_type, i.filters.user_type)), i.filters.user_id?.length && d.push(l(q.user_id, i.filters.user_id));
|
|
4750
4794
|
let f = {}, p = [], h = [];
|
|
4751
4795
|
for (let e of i.group_by) if (e === "time") {
|
|
4752
|
-
let e =
|
|
4796
|
+
let e = mi(i.interval);
|
|
4753
4797
|
f.time = e, p.push(e), h.push({
|
|
4754
4798
|
name: "time",
|
|
4755
4799
|
type: i.interval === "hour" ? "DateTime" : "Date"
|
|
4756
4800
|
});
|
|
4757
4801
|
} else {
|
|
4758
|
-
let t =
|
|
4802
|
+
let t = gi(e);
|
|
4759
4803
|
f[e] = t, p.push(t), h.push({
|
|
4760
4804
|
name: e,
|
|
4761
4805
|
type: "String"
|
|
@@ -4771,9 +4815,9 @@ function hi(e) {
|
|
|
4771
4815
|
if (i.order_by) {
|
|
4772
4816
|
let e = i.order_by.startsWith("-"), t = e ? i.order_by.slice(1) : i.order_by;
|
|
4773
4817
|
if (!_.has(t)) throw Error(`Invalid order_by column '${t}' for analytics query`);
|
|
4774
|
-
let n =
|
|
4818
|
+
let n = hi(t);
|
|
4775
4819
|
g = g.orderBy(y.raw(`${n} ${e ? "DESC" : "ASC"}`));
|
|
4776
|
-
} else g = i.group_by[0] === "time" ? g.orderBy(y.raw(`${
|
|
4820
|
+
} else g = i.group_by[0] === "time" ? g.orderBy(y.raw(`${hi("time")} ASC`)) : g.orderBy(y.raw(`${hi(u.alias)} DESC`));
|
|
4777
4821
|
g = g.limit(i.limit).offset(i.offset);
|
|
4778
4822
|
let v = (await g.all()).map((e) => {
|
|
4779
4823
|
let t = {};
|
|
@@ -4822,10 +4866,10 @@ function hi(e) {
|
|
|
4822
4866
|
}
|
|
4823
4867
|
//#endregion
|
|
4824
4868
|
//#region src/adapters/cleanup.ts
|
|
4825
|
-
var
|
|
4826
|
-
function
|
|
4869
|
+
var vi = 10080 * 60 * 1e3;
|
|
4870
|
+
function yi(e) {
|
|
4827
4871
|
return async (n) => {
|
|
4828
|
-
let r = Date.now() -
|
|
4872
|
+
let r = Date.now() - vi;
|
|
4829
4873
|
try {
|
|
4830
4874
|
let i = [v(m(N.expires_at_ts, r), m(N.idle_expires_at_ts, r))];
|
|
4831
4875
|
n?.tenant_id && i.push(a(N.tenant_id, n.tenant_id)), await e.delete(N).where(t(...i)), i = [v(m(M.expires_at_ts, r), m(M.idle_expires_at_ts, r))], n?.tenant_id && i.push(a(M.tenant_id, n.tenant_id)), n?.user_id && i.push(a(M.user_id, n.user_id)), await e.delete(M).where(t(...i)), i = [m(P.expires_at_ts, r)], n?.tenant_id && i.push(a(P.tenant_id, n.tenant_id)), await e.delete(P).where(t(...i));
|
|
@@ -4860,7 +4904,7 @@ var Q = w("tenant_operations", {
|
|
|
4860
4904
|
x("tenant_operations_tenant_id_created_at_idx").on(e.tenant_id, e.created_at),
|
|
4861
4905
|
x("tenant_operations_rollout_id_idx").on(e.rollout_id),
|
|
4862
4906
|
x("tenant_operations_status_idx").on(e.status)
|
|
4863
|
-
]),
|
|
4907
|
+
]), bi = w("tenant_operation_events", {
|
|
4864
4908
|
id: T("id", { length: 255 }).primaryKey(),
|
|
4865
4909
|
operation_id: T("operation_id", { length: 255 }).notNull(),
|
|
4866
4910
|
step: T("step", { length: 255 }).notNull(),
|
|
@@ -4891,7 +4935,7 @@ var Q = w("tenant_operations", {
|
|
|
4891
4935
|
name: "tenant_operation_rows_operation_id_constraint"
|
|
4892
4936
|
}).onDelete("cascade"),
|
|
4893
4937
|
x("tenant_operation_rows_operation_id_status_idx").on(e.operation_id, e.status)
|
|
4894
|
-
]),
|
|
4938
|
+
]), xi = w("rollouts", {
|
|
4895
4939
|
id: T("id", { length: 255 }).primaryKey(),
|
|
4896
4940
|
kind: T("kind", { length: 32 }).notNull(),
|
|
4897
4941
|
status: T("status", { length: 32 }).notNull(),
|
|
@@ -4907,7 +4951,7 @@ var Q = w("tenant_operations", {
|
|
|
4907
4951
|
});
|
|
4908
4952
|
//#endregion
|
|
4909
4953
|
//#region src/adapters/tenantOperations.ts
|
|
4910
|
-
function
|
|
4954
|
+
function Si(e) {
|
|
4911
4955
|
if (!e) return null;
|
|
4912
4956
|
try {
|
|
4913
4957
|
return JSON.parse(e);
|
|
@@ -4915,7 +4959,7 @@ function bi(e) {
|
|
|
4915
4959
|
return null;
|
|
4916
4960
|
}
|
|
4917
4961
|
}
|
|
4918
|
-
function
|
|
4962
|
+
function Ci(e) {
|
|
4919
4963
|
return Pe.parse({
|
|
4920
4964
|
id: e.id,
|
|
4921
4965
|
tenant_id: e.tenant_id,
|
|
@@ -4929,8 +4973,8 @@ function xi(e) {
|
|
|
4929
4973
|
target_database_version: e.target_database_version,
|
|
4930
4974
|
error: e.error,
|
|
4931
4975
|
initiated_by: e.initiated_by,
|
|
4932
|
-
input:
|
|
4933
|
-
result:
|
|
4976
|
+
input: Si(e.input),
|
|
4977
|
+
result: Si(e.result),
|
|
4934
4978
|
claimed_by: e.claimed_by,
|
|
4935
4979
|
claim_expires_at: e.claim_expires_at,
|
|
4936
4980
|
created_at: e.created_at,
|
|
@@ -4938,7 +4982,7 @@ function xi(e) {
|
|
|
4938
4982
|
finished_at: e.finished_at
|
|
4939
4983
|
});
|
|
4940
4984
|
}
|
|
4941
|
-
function
|
|
4985
|
+
function wi(e) {
|
|
4942
4986
|
return {
|
|
4943
4987
|
async create(t) {
|
|
4944
4988
|
let n = je.parse(t), r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
@@ -4969,7 +5013,7 @@ function Si(e) {
|
|
|
4969
5013
|
},
|
|
4970
5014
|
async get(t) {
|
|
4971
5015
|
let n = await e.select().from(Q).where(a(Q.id, t)).limit(1);
|
|
4972
|
-
return n[0] ?
|
|
5016
|
+
return n[0] ? Ci(n[0]) : null;
|
|
4973
5017
|
},
|
|
4974
5018
|
async list(n = {}) {
|
|
4975
5019
|
let r = n.page ?? 0, o = n.per_page ?? 50, s = [];
|
|
@@ -4980,7 +5024,7 @@ function Si(e) {
|
|
|
4980
5024
|
n.engine !== void 0 && s.push(a(Q.engine, n.engine)), n.updated_before !== void 0 && s.push(m(Q.updated_at, n.updated_before));
|
|
4981
5025
|
let c = await e.select().from(Q).where(s.length ? t(...s) : void 0).orderBy(i(Q.created_at), i(Q.id)).offset(r * o).limit(o);
|
|
4982
5026
|
return {
|
|
4983
|
-
operations: c.map(
|
|
5027
|
+
operations: c.map(Ci),
|
|
4984
5028
|
start: r * o,
|
|
4985
5029
|
limit: o,
|
|
4986
5030
|
length: c.length
|
|
@@ -5006,7 +5050,7 @@ function Si(e) {
|
|
|
5006
5050
|
},
|
|
5007
5051
|
async listResumable(r) {
|
|
5008
5052
|
let i = (/* @__PURE__ */ new Date()).toISOString();
|
|
5009
|
-
return (await e.select().from(Q).where(t(l(Q.status, ["pending", "running"]), a(Q.kind, r.kind), v(f(Q.claimed_by), h(Q.claim_expires_at, i)))).orderBy(n(Q.created_at), n(Q.id)).limit(r.limit)).map(
|
|
5053
|
+
return (await e.select().from(Q).where(t(l(Q.status, ["pending", "running"]), a(Q.kind, r.kind), v(f(Q.claimed_by), h(Q.claim_expires_at, i)))).orderBy(n(Q.created_at), n(Q.id)).limit(r.limit)).map(Ci);
|
|
5010
5054
|
},
|
|
5011
5055
|
async remove(t) {
|
|
5012
5056
|
return (await e.select({ id: Q.id }).from(Q).where(a(Q.id, t)).limit(1)).length === 0 ? !1 : (await e.delete(Q).where(a(Q.id, t)), !0);
|
|
@@ -5015,19 +5059,19 @@ function Si(e) {
|
|
|
5015
5059
|
}
|
|
5016
5060
|
//#endregion
|
|
5017
5061
|
//#region src/adapters/tenantOperationRows.ts
|
|
5018
|
-
var
|
|
5019
|
-
function
|
|
5062
|
+
var Ti = 50, Ei = 50;
|
|
5063
|
+
function Di(e) {
|
|
5020
5064
|
try {
|
|
5021
5065
|
return JSON.parse(e);
|
|
5022
5066
|
} catch {
|
|
5023
5067
|
return {};
|
|
5024
5068
|
}
|
|
5025
5069
|
}
|
|
5026
|
-
function
|
|
5070
|
+
function Oi(e) {
|
|
5027
5071
|
return Ne.parse({
|
|
5028
5072
|
operation_id: e.operation_id,
|
|
5029
5073
|
seq: e.seq,
|
|
5030
|
-
payload:
|
|
5074
|
+
payload: Di(e.payload),
|
|
5031
5075
|
status: e.status,
|
|
5032
5076
|
error_code: e.error_code,
|
|
5033
5077
|
error_message: e.error_message,
|
|
@@ -5037,12 +5081,12 @@ function Ei(e) {
|
|
|
5037
5081
|
updated_at: e.updated_at
|
|
5038
5082
|
});
|
|
5039
5083
|
}
|
|
5040
|
-
function
|
|
5084
|
+
function ki(e, t) {
|
|
5041
5085
|
let n = [];
|
|
5042
5086
|
for (let r = 0; r < e.length; r += t) n.push(e.slice(r, r + t));
|
|
5043
5087
|
return n;
|
|
5044
5088
|
}
|
|
5045
|
-
function
|
|
5089
|
+
function Ai(e, n, r, i) {
|
|
5046
5090
|
return e.update($).set({
|
|
5047
5091
|
status: r.status,
|
|
5048
5092
|
error_code: r.error_code ?? null,
|
|
@@ -5052,7 +5096,7 @@ function Oi(e, n, r, i) {
|
|
|
5052
5096
|
updated_at: i
|
|
5053
5097
|
}).where(t(a($.operation_id, n), a($.seq, r.seq), a($.status, "pending")));
|
|
5054
5098
|
}
|
|
5055
|
-
function
|
|
5099
|
+
function ji(e) {
|
|
5056
5100
|
return {
|
|
5057
5101
|
async createMany(t) {
|
|
5058
5102
|
if (t.length === 0) return 0;
|
|
@@ -5071,24 +5115,24 @@ function ki(e) {
|
|
|
5071
5115
|
updated_at: n
|
|
5072
5116
|
};
|
|
5073
5117
|
});
|
|
5074
|
-
for (let t of
|
|
5118
|
+
for (let t of ki(r, Ti)) await e.insert($).values(t);
|
|
5075
5119
|
return r.length;
|
|
5076
5120
|
},
|
|
5077
5121
|
async claimPending(r, i) {
|
|
5078
|
-
return (await e.select().from($).where(t(a($.operation_id, r), a($.status, "pending"))).orderBy(n($.seq)).limit(i)).map(
|
|
5122
|
+
return (await e.select().from($).where(t(a($.operation_id, r), a($.status, "pending"))).orderBy(n($.seq)).limit(i)).map(Oi);
|
|
5079
5123
|
},
|
|
5080
5124
|
async recordOutcomes(n, r) {
|
|
5081
5125
|
if (r.length === 0) return 0;
|
|
5082
5126
|
let i = (/* @__PURE__ */ new Date()).toISOString(), o = r.map((e) => e.seq), s = /* @__PURE__ */ new Set();
|
|
5083
|
-
for (let r of
|
|
5127
|
+
for (let r of ki(o, Ei)) {
|
|
5084
5128
|
let i = await e.select({ seq: $.seq }).from($).where(t(a($.operation_id, n), a($.status, "pending"), l($.seq, r)));
|
|
5085
5129
|
for (let e of i) s.add(e.seq);
|
|
5086
5130
|
}
|
|
5087
5131
|
let c = r.filter((e) => s.has(e.seq));
|
|
5088
5132
|
if (c.length === 0) return 0;
|
|
5089
|
-
for (let t of
|
|
5090
|
-
let [r, ...a] = t.map((t) =>
|
|
5091
|
-
r && await
|
|
5133
|
+
for (let t of ki(c, Ei)) {
|
|
5134
|
+
let [r, ...a] = t.map((t) => Ai(e, n, t, i));
|
|
5135
|
+
r && await Tt(e, [r, ...a]);
|
|
5092
5136
|
}
|
|
5093
5137
|
return c.length;
|
|
5094
5138
|
},
|
|
@@ -5123,7 +5167,7 @@ function ki(e) {
|
|
|
5123
5167
|
}
|
|
5124
5168
|
let u = await e.select().from($).where(t(...c)).orderBy(n($.seq)).offset(o * s).limit(s);
|
|
5125
5169
|
return {
|
|
5126
|
-
rows: u.map(
|
|
5170
|
+
rows: u.map(Oi),
|
|
5127
5171
|
start: o * s,
|
|
5128
5172
|
limit: s,
|
|
5129
5173
|
length: u.length
|
|
@@ -5137,27 +5181,27 @@ function ki(e) {
|
|
|
5137
5181
|
}
|
|
5138
5182
|
//#endregion
|
|
5139
5183
|
//#region src/helpers/monotonic-id.ts
|
|
5140
|
-
var
|
|
5141
|
-
function
|
|
5184
|
+
var Mi = "0123456789ABCDEFGHJKMNPQRSTVWXYZ", Ni = 32, Pi = 10, Fi = 4, Ii = 10;
|
|
5185
|
+
function Li(e, t) {
|
|
5142
5186
|
let n = "";
|
|
5143
|
-
for (let r = t; r > 0; r--) n =
|
|
5187
|
+
for (let r = t; r > 0; r--) n = Mi.charAt(e % Ni) + n, e = Math.floor(e / Ni);
|
|
5144
5188
|
return n;
|
|
5145
5189
|
}
|
|
5146
|
-
function
|
|
5147
|
-
let e = new Uint8Array(
|
|
5190
|
+
function Ri() {
|
|
5191
|
+
let e = new Uint8Array(Ii);
|
|
5148
5192
|
crypto.getRandomValues(e);
|
|
5149
5193
|
let t = "";
|
|
5150
|
-
for (let n = 0; n <
|
|
5194
|
+
for (let n = 0; n < Ii; n++) t += Mi.charAt(e[n] % Ni);
|
|
5151
5195
|
return t;
|
|
5152
5196
|
}
|
|
5153
|
-
var
|
|
5154
|
-
function
|
|
5197
|
+
var zi = 0, Bi = 0;
|
|
5198
|
+
function Vi() {
|
|
5155
5199
|
let e = Date.now();
|
|
5156
|
-
return e ===
|
|
5200
|
+
return e === zi ? Bi++ : (zi = e, Bi = 0), Li(e, Pi) + Li(Bi, Fi) + Ri();
|
|
5157
5201
|
}
|
|
5158
5202
|
//#endregion
|
|
5159
5203
|
//#region src/adapters/tenantOperationEvents.ts
|
|
5160
|
-
function
|
|
5204
|
+
function Hi(e) {
|
|
5161
5205
|
if (!e) return null;
|
|
5162
5206
|
try {
|
|
5163
5207
|
let t = JSON.parse(e);
|
|
@@ -5165,22 +5209,22 @@ function Bi(e) {
|
|
|
5165
5209
|
} catch {}
|
|
5166
5210
|
return null;
|
|
5167
5211
|
}
|
|
5168
|
-
function
|
|
5212
|
+
function Ui(e) {
|
|
5169
5213
|
return Ae.parse({
|
|
5170
5214
|
id: e.id,
|
|
5171
5215
|
operation_id: e.operation_id,
|
|
5172
5216
|
step: e.step,
|
|
5173
5217
|
outcome: e.outcome,
|
|
5174
|
-
detail:
|
|
5218
|
+
detail: Hi(e.detail),
|
|
5175
5219
|
attempt: e.attempt,
|
|
5176
5220
|
created_at: e.created_at
|
|
5177
5221
|
});
|
|
5178
5222
|
}
|
|
5179
|
-
function
|
|
5223
|
+
function Wi(e) {
|
|
5180
5224
|
return {
|
|
5181
5225
|
async create(t) {
|
|
5182
5226
|
let n = ke.parse(t), r = {
|
|
5183
|
-
id: `evt_${
|
|
5227
|
+
id: `evt_${Vi()}`,
|
|
5184
5228
|
operation_id: n.operation_id,
|
|
5185
5229
|
step: n.step,
|
|
5186
5230
|
outcome: n.outcome,
|
|
@@ -5188,7 +5232,7 @@ function Hi(e) {
|
|
|
5188
5232
|
attempt: n.attempt,
|
|
5189
5233
|
created_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
5190
5234
|
};
|
|
5191
|
-
return await e.insert(
|
|
5235
|
+
return await e.insert(bi).values(r), Ae.parse({
|
|
5192
5236
|
id: r.id,
|
|
5193
5237
|
operation_id: r.operation_id,
|
|
5194
5238
|
step: r.step,
|
|
@@ -5199,9 +5243,9 @@ function Hi(e) {
|
|
|
5199
5243
|
});
|
|
5200
5244
|
},
|
|
5201
5245
|
async listByOperation(t, r = {}) {
|
|
5202
|
-
let i = r.page ?? 0, o = r.per_page ?? 100, s = await e.select().from(
|
|
5246
|
+
let i = r.page ?? 0, o = r.per_page ?? 100, s = await e.select().from(bi).where(a(bi.operation_id, t)).orderBy(n(bi.created_at), n(bi.id)).offset(i * o).limit(o);
|
|
5203
5247
|
return {
|
|
5204
|
-
events: s.map(
|
|
5248
|
+
events: s.map(Ui),
|
|
5205
5249
|
start: i * o,
|
|
5206
5250
|
limit: o,
|
|
5207
5251
|
length: s.length
|
|
@@ -5211,7 +5255,7 @@ function Hi(e) {
|
|
|
5211
5255
|
}
|
|
5212
5256
|
//#endregion
|
|
5213
5257
|
//#region src/adapters/rollouts.ts
|
|
5214
|
-
function
|
|
5258
|
+
function Gi(e) {
|
|
5215
5259
|
if (!e) return null;
|
|
5216
5260
|
try {
|
|
5217
5261
|
return JSON.parse(e);
|
|
@@ -5219,7 +5263,7 @@ function Ui(e) {
|
|
|
5219
5263
|
return null;
|
|
5220
5264
|
}
|
|
5221
5265
|
}
|
|
5222
|
-
function
|
|
5266
|
+
function Ki(e) {
|
|
5223
5267
|
return we.parse({
|
|
5224
5268
|
id: e.id,
|
|
5225
5269
|
kind: e.kind,
|
|
@@ -5227,15 +5271,15 @@ function Wi(e) {
|
|
|
5227
5271
|
target_worker_version: e.target_worker_version,
|
|
5228
5272
|
target_database_version: e.target_database_version,
|
|
5229
5273
|
wave_size: e.wave_size,
|
|
5230
|
-
canary_tenant_ids:
|
|
5231
|
-
filter:
|
|
5274
|
+
canary_tenant_ids: Gi(e.canary_tenant_ids),
|
|
5275
|
+
filter: Gi(e.filter),
|
|
5232
5276
|
initiated_by: e.initiated_by,
|
|
5233
5277
|
created_at: e.created_at,
|
|
5234
5278
|
updated_at: e.updated_at,
|
|
5235
5279
|
finished_at: e.finished_at
|
|
5236
5280
|
});
|
|
5237
5281
|
}
|
|
5238
|
-
function
|
|
5282
|
+
function qi(e) {
|
|
5239
5283
|
return {
|
|
5240
5284
|
async create(t) {
|
|
5241
5285
|
let n = Ce.parse(t), r = (/* @__PURE__ */ new Date()).toISOString(), i = {
|
|
@@ -5252,95 +5296,96 @@ function Gi(e) {
|
|
|
5252
5296
|
updated_at: r,
|
|
5253
5297
|
finished_at: null
|
|
5254
5298
|
};
|
|
5255
|
-
await e.insert(
|
|
5299
|
+
await e.insert(xi).values(i);
|
|
5256
5300
|
let a = await this.get(i.id);
|
|
5257
5301
|
if (!a) throw Error(`Failed to create rollout ${i.id}`);
|
|
5258
5302
|
return a;
|
|
5259
5303
|
},
|
|
5260
5304
|
async get(t) {
|
|
5261
|
-
let n = await e.select().from(
|
|
5262
|
-
return n[0] ?
|
|
5305
|
+
let n = await e.select().from(xi).where(a(xi.id, t)).limit(1);
|
|
5306
|
+
return n[0] ? Ki(n[0]) : null;
|
|
5263
5307
|
},
|
|
5264
5308
|
async list(t = {}) {
|
|
5265
|
-
let n = t.page ?? 0, r = t.per_page ?? 50, a = await e.select().from(
|
|
5309
|
+
let n = t.page ?? 0, r = t.per_page ?? 50, a = await e.select().from(xi).orderBy(i(xi.created_at), i(xi.id)).offset(n * r).limit(r);
|
|
5266
5310
|
return {
|
|
5267
|
-
rollouts: a.map(
|
|
5311
|
+
rollouts: a.map(Ki),
|
|
5268
5312
|
start: n * r,
|
|
5269
5313
|
limit: r,
|
|
5270
5314
|
length: a.length
|
|
5271
5315
|
};
|
|
5272
5316
|
},
|
|
5273
5317
|
async update(t, n) {
|
|
5274
|
-
if ((await e.select({ id:
|
|
5318
|
+
if ((await e.select({ id: xi.id }).from(xi).where(a(xi.id, t)).limit(1)).length === 0) return !1;
|
|
5275
5319
|
let r = { updated_at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
5276
|
-
return n.status !== void 0 && (r.status = n.status), n.wave_size !== void 0 && (r.wave_size = n.wave_size), n.canary_tenant_ids !== void 0 && (r.canary_tenant_ids = n.canary_tenant_ids ? JSON.stringify(n.canary_tenant_ids) : null), n.filter !== void 0 && (r.filter = n.filter ? JSON.stringify(n.filter) : null), n.finished_at !== void 0 && (r.finished_at = n.finished_at), await e.update(
|
|
5320
|
+
return n.status !== void 0 && (r.status = n.status), n.wave_size !== void 0 && (r.wave_size = n.wave_size), n.canary_tenant_ids !== void 0 && (r.canary_tenant_ids = n.canary_tenant_ids ? JSON.stringify(n.canary_tenant_ids) : null), n.filter !== void 0 && (r.filter = n.filter ? JSON.stringify(n.filter) : null), n.finished_at !== void 0 && (r.finished_at = n.finished_at), await e.update(xi).set(r).where(a(xi.id, t)), !0;
|
|
5277
5321
|
},
|
|
5278
5322
|
async remove(t) {
|
|
5279
|
-
return (await e.select({ id:
|
|
5323
|
+
return (await e.select({ id: xi.id }).from(xi).where(a(xi.id, t)).limit(1)).length === 0 ? !1 : (await e.delete(xi).where(a(xi.id, t)), !0);
|
|
5280
5324
|
}
|
|
5281
5325
|
};
|
|
5282
5326
|
}
|
|
5283
5327
|
//#endregion
|
|
5284
5328
|
//#region src/adapters/index.ts
|
|
5285
|
-
function
|
|
5329
|
+
function Ji(e, t = { useTransactions: !0 }) {
|
|
5286
5330
|
let n = {
|
|
5287
|
-
actions:
|
|
5288
|
-
actionExecutions:
|
|
5289
|
-
actionVersions:
|
|
5290
|
-
branding:
|
|
5291
|
-
clients:
|
|
5292
|
-
clientConnections:
|
|
5293
|
-
clientGrants:
|
|
5294
|
-
clientRegistrationTokens:
|
|
5295
|
-
codes:
|
|
5296
|
-
connections:
|
|
5297
|
-
customDomains:
|
|
5298
|
-
customText:
|
|
5299
|
-
emailProviders:
|
|
5300
|
-
emailTemplates:
|
|
5301
|
-
flows:
|
|
5302
|
-
forms:
|
|
5303
|
-
grants:
|
|
5304
|
-
hookCode:
|
|
5305
|
-
hooks:
|
|
5306
|
-
invites:
|
|
5307
|
-
keys:
|
|
5308
|
-
loginSessions:
|
|
5309
|
-
logs:
|
|
5310
|
-
authenticationMethods:
|
|
5311
|
-
organizations:
|
|
5312
|
-
passwords:
|
|
5313
|
-
promptSettings:
|
|
5314
|
-
|
|
5315
|
-
|
|
5316
|
-
|
|
5317
|
-
|
|
5318
|
-
|
|
5319
|
-
|
|
5320
|
-
|
|
5321
|
-
|
|
5322
|
-
|
|
5323
|
-
|
|
5324
|
-
|
|
5325
|
-
|
|
5326
|
-
|
|
5331
|
+
actions: xt(e),
|
|
5332
|
+
actionExecutions: Ct(e),
|
|
5333
|
+
actionVersions: Dt(e),
|
|
5334
|
+
branding: kt(e),
|
|
5335
|
+
clients: Bt(e),
|
|
5336
|
+
clientConnections: Ht(e),
|
|
5337
|
+
clientGrants: Wt(e),
|
|
5338
|
+
clientRegistrationTokens: Yt(e),
|
|
5339
|
+
codes: $t(e),
|
|
5340
|
+
connections: nn(e),
|
|
5341
|
+
customDomains: an(e),
|
|
5342
|
+
customText: on(e),
|
|
5343
|
+
emailProviders: sn(e),
|
|
5344
|
+
emailTemplates: ln(e),
|
|
5345
|
+
flows: dn(e),
|
|
5346
|
+
forms: mn(e),
|
|
5347
|
+
grants: vn(e),
|
|
5348
|
+
hookCode: Sn(e),
|
|
5349
|
+
hooks: En(e),
|
|
5350
|
+
invites: An(e),
|
|
5351
|
+
keys: Mn(e),
|
|
5352
|
+
loginSessions: Ln(e),
|
|
5353
|
+
logs: zn(e),
|
|
5354
|
+
authenticationMethods: Wn(e),
|
|
5355
|
+
organizations: Jn(e),
|
|
5356
|
+
passwords: Xn(e),
|
|
5357
|
+
promptSettings: Zn(e),
|
|
5358
|
+
promptPartials: Qn(e),
|
|
5359
|
+
proxyRoutes: nr(e),
|
|
5360
|
+
scimConfigurations: ur(e),
|
|
5361
|
+
scimTokens: fr(e),
|
|
5362
|
+
scimExternalIds: mr(e),
|
|
5363
|
+
refreshTokens: _r(e),
|
|
5364
|
+
resourceServers: Cr(e),
|
|
5365
|
+
rolePermissions: wr(e),
|
|
5366
|
+
userPermissions: Er(e),
|
|
5367
|
+
roles: Or(e),
|
|
5368
|
+
sessions: Nr(e),
|
|
5369
|
+
sessionCleanup: yi(e),
|
|
5370
|
+
tenants: Rr(e),
|
|
5371
|
+
tokenExchangeProfiles: or(e),
|
|
5327
5372
|
...t.controlPlane ? {
|
|
5328
|
-
tenantOperations:
|
|
5329
|
-
tenantOperationEvents:
|
|
5330
|
-
tenantOperationRows:
|
|
5331
|
-
rollouts:
|
|
5373
|
+
tenantOperations: wi(e),
|
|
5374
|
+
tenantOperationEvents: Wi(e),
|
|
5375
|
+
tenantOperationRows: ji(e),
|
|
5376
|
+
rollouts: qi(e)
|
|
5332
5377
|
} : {},
|
|
5333
|
-
themes:
|
|
5334
|
-
universalLoginTemplates:
|
|
5335
|
-
users:
|
|
5336
|
-
userActivity:
|
|
5337
|
-
userRoles:
|
|
5338
|
-
userOrganizations:
|
|
5339
|
-
stats:
|
|
5340
|
-
analytics:
|
|
5341
|
-
outbox:
|
|
5378
|
+
themes: Vr(e),
|
|
5379
|
+
universalLoginTemplates: Hr(e),
|
|
5380
|
+
users: ai(e),
|
|
5381
|
+
userActivity: Wr(e),
|
|
5382
|
+
userRoles: oi(e),
|
|
5383
|
+
userOrganizations: si(e),
|
|
5384
|
+
stats: di(e),
|
|
5385
|
+
analytics: _i(e),
|
|
5386
|
+
outbox: qr(e),
|
|
5342
5387
|
async transaction(r) {
|
|
5343
|
-
if (t.useTransactions === !1 ||
|
|
5388
|
+
if (t.useTransactions === !1 || wt(e)) return r(n);
|
|
5344
5389
|
await e.run(y`BEGIN`);
|
|
5345
5390
|
try {
|
|
5346
5391
|
let t = await r(n);
|
|
@@ -5354,7 +5399,7 @@ function Ki(e, t = { useTransactions: !0 }) {
|
|
|
5354
5399
|
}
|
|
5355
5400
|
//#endregion
|
|
5356
5401
|
//#region src/adapters/resolveHost.ts
|
|
5357
|
-
function
|
|
5402
|
+
function Yi(e) {
|
|
5358
5403
|
if (!e) return { path: "/*" };
|
|
5359
5404
|
try {
|
|
5360
5405
|
let t = JSON.parse(e), n = xe.safeParse(t);
|
|
@@ -5362,7 +5407,7 @@ function qi(e) {
|
|
|
5362
5407
|
} catch {}
|
|
5363
5408
|
return { path: "/*" };
|
|
5364
5409
|
}
|
|
5365
|
-
function
|
|
5410
|
+
function Xi(e) {
|
|
5366
5411
|
if (!e) return [];
|
|
5367
5412
|
try {
|
|
5368
5413
|
let t = JSON.parse(e);
|
|
@@ -5377,7 +5422,7 @@ function Ji(e) {
|
|
|
5377
5422
|
return [];
|
|
5378
5423
|
}
|
|
5379
5424
|
}
|
|
5380
|
-
async function
|
|
5425
|
+
async function Zi(e, r) {
|
|
5381
5426
|
let i = r.toLowerCase(), o = (await e.select({
|
|
5382
5427
|
custom_domain_id: Ke.custom_domain_id,
|
|
5383
5428
|
tenant_id: Ke.tenant_id,
|
|
@@ -5389,8 +5434,8 @@ async function Yi(e, r) {
|
|
|
5389
5434
|
tenant_id: e.tenant_id,
|
|
5390
5435
|
custom_domain_id: e.custom_domain_id,
|
|
5391
5436
|
priority: e.priority,
|
|
5392
|
-
match:
|
|
5393
|
-
handlers:
|
|
5437
|
+
match: Yi(e.match),
|
|
5438
|
+
handlers: Xi(e.handlers),
|
|
5394
5439
|
created_at: e.created_at,
|
|
5395
5440
|
updated_at: e.updated_at
|
|
5396
5441
|
}));
|
|
@@ -5403,11 +5448,11 @@ async function Yi(e, r) {
|
|
|
5403
5448
|
}
|
|
5404
5449
|
//#endregion
|
|
5405
5450
|
//#region src/adapters/proxyData.ts
|
|
5406
|
-
function
|
|
5451
|
+
function Qi(e) {
|
|
5407
5452
|
return {
|
|
5408
|
-
proxyRoutes:
|
|
5409
|
-
resolveHost: (t) =>
|
|
5453
|
+
proxyRoutes: nr(e),
|
|
5454
|
+
resolveHost: (t) => Zi(e, t)
|
|
5410
5455
|
};
|
|
5411
5456
|
}
|
|
5412
5457
|
//#endregion
|
|
5413
|
-
export {
|
|
5458
|
+
export { Qi as createProxyDataAdapter, nr as createProxyRoutesAdapter, Ji as default, pt as sqlite };
|