@authhero/kysely-adapter 10.36.0 → 10.37.1
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/kysely-adapter.cjs +1 -1
- package/dist/kysely-adapter.d.ts +43 -9
- package/dist/kysely-adapter.mjs +815 -711
- package/package.json +3 -3
package/dist/kysely-adapter.mjs
CHANGED
|
@@ -3,15 +3,15 @@ var ue = (t) => {
|
|
|
3
3
|
throw TypeError(t);
|
|
4
4
|
};
|
|
5
5
|
var Re = (t, e, r) => e in t ? Je(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
|
|
6
|
-
var
|
|
7
|
-
var d = (t, e, r) => (
|
|
8
|
-
import { parseUserId as
|
|
6
|
+
var R = (t, e, r) => Re(t, typeof e != "symbol" ? e + "" : e, r), Y = (t, e, r) => e.has(t) || ue("Cannot " + r);
|
|
7
|
+
var d = (t, e, r) => (Y(t, e, "read from private field"), r ? r.call(t) : e.get(t)), S = (t, e, r) => e.has(t) ? ue("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, r), K = (t, e, r, a) => (Y(t, e, "write to private field"), a ? a.call(t, r) : e.set(t, r), r), p = (t, e, r) => (Y(t, e, "access private method"), r);
|
|
8
|
+
import { parseUserId as ie, codeSchema as Ke, connectionSchema as Ue, loginSessionSchema as Be, promptSettingSchema as Qe, formSchema as G, resourceServerSchema as qe } from "@authhero/adapter-interfaces";
|
|
9
9
|
import "@hono/zod-openapi";
|
|
10
|
-
var
|
|
10
|
+
var te = class extends Error {
|
|
11
11
|
constructor(e = 500, r) {
|
|
12
12
|
super(r == null ? void 0 : r.message, { cause: r == null ? void 0 : r.cause });
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
R(this, "res");
|
|
14
|
+
R(this, "status");
|
|
15
15
|
this.res = r == null ? void 0 : r.res, this.status = e;
|
|
16
16
|
}
|
|
17
17
|
getResponse() {
|
|
@@ -25,8 +25,8 @@ var Y = class extends Error {
|
|
|
25
25
|
};
|
|
26
26
|
function Ve(t) {
|
|
27
27
|
return async (e, r) => {
|
|
28
|
-
const { identities: a, ...
|
|
29
|
-
...
|
|
28
|
+
const { identities: a, ...n } = r, o = {
|
|
29
|
+
...n,
|
|
30
30
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
31
31
|
updated_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
32
32
|
login_count: 0,
|
|
@@ -37,35 +37,35 @@ function Ve(t) {
|
|
|
37
37
|
user_metadata: JSON.stringify(r.user_metadata)
|
|
38
38
|
};
|
|
39
39
|
try {
|
|
40
|
-
await t.insertInto("users").values(
|
|
40
|
+
await t.insertInto("users").values(o).execute();
|
|
41
41
|
} catch (s) {
|
|
42
|
-
throw s.code === "SQLITE_CONSTRAINT_UNIQUE" || s.message.includes("AlreadyExists") ? new
|
|
42
|
+
throw s.code === "SQLITE_CONSTRAINT_UNIQUE" || s.message.includes("AlreadyExists") ? new te(409, { message: "User already exists" }) : new te(500, { message: `${s.code}, ${s.message}` });
|
|
43
43
|
}
|
|
44
44
|
return {
|
|
45
|
-
...
|
|
45
|
+
...o,
|
|
46
46
|
// TODO: check if this is correct. Should it be optional?
|
|
47
|
-
email:
|
|
48
|
-
email_verified:
|
|
49
|
-
is_social:
|
|
47
|
+
email: o.email || "",
|
|
48
|
+
email_verified: o.email_verified === 1,
|
|
49
|
+
is_social: o.is_social === 1
|
|
50
50
|
};
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
|
-
function
|
|
53
|
+
function y(t) {
|
|
54
54
|
if (t == null || typeof t != "object")
|
|
55
55
|
return t;
|
|
56
56
|
if (Array.isArray(t))
|
|
57
57
|
return t.map(
|
|
58
58
|
(r) => (
|
|
59
59
|
// Only recurse into objects; leave primitives untouched
|
|
60
|
-
r !== null && typeof r == "object" ?
|
|
60
|
+
r !== null && typeof r == "object" ? y(r) : r
|
|
61
61
|
)
|
|
62
62
|
);
|
|
63
63
|
const e = { ...t };
|
|
64
64
|
for (const r in e) {
|
|
65
65
|
const a = e[r];
|
|
66
66
|
a === null ? delete e[r] : a !== null && typeof a == "object" && (Array.isArray(a) ? e[r] = a.map(
|
|
67
|
-
(
|
|
68
|
-
) : e[r] =
|
|
67
|
+
(n) => n !== null && typeof n == "object" ? y(n) : n
|
|
68
|
+
) : e[r] = y(a));
|
|
69
69
|
}
|
|
70
70
|
return e;
|
|
71
71
|
}
|
|
@@ -79,7 +79,7 @@ function pe(t) {
|
|
|
79
79
|
return {
|
|
80
80
|
connection: t.connection,
|
|
81
81
|
provider: t.provider,
|
|
82
|
-
user_id:
|
|
82
|
+
user_id: ie(t.user_id).id,
|
|
83
83
|
isSocial: !!t.is_social,
|
|
84
84
|
profileData: {
|
|
85
85
|
email: t.email,
|
|
@@ -90,13 +90,13 @@ function pe(t) {
|
|
|
90
90
|
}
|
|
91
91
|
function We(t) {
|
|
92
92
|
return async (e, r) => {
|
|
93
|
-
const [a,
|
|
93
|
+
const [a, n] = await Promise.all([
|
|
94
94
|
t.selectFrom("users").where("users.tenant_id", "=", e).where("users.user_id", "=", r).selectAll().executeTakeFirst(),
|
|
95
95
|
t.selectFrom("users").where("users.tenant_id", "=", e).where("users.linked_to", "=", r).selectAll().execute()
|
|
96
96
|
]);
|
|
97
97
|
if (!a)
|
|
98
98
|
return null;
|
|
99
|
-
const { tenant_id:
|
|
99
|
+
const { tenant_id: o, ...s } = a, i = {
|
|
100
100
|
...s,
|
|
101
101
|
email: a.email || "",
|
|
102
102
|
email_verified: a.email_verified === 1,
|
|
@@ -107,128 +107,133 @@ function We(t) {
|
|
|
107
107
|
{
|
|
108
108
|
connection: a.connection,
|
|
109
109
|
provider: a.provider,
|
|
110
|
-
user_id:
|
|
110
|
+
user_id: ie(a.user_id).id,
|
|
111
111
|
isSocial: !!a.is_social
|
|
112
112
|
},
|
|
113
|
-
...
|
|
113
|
+
...n.map(pe)
|
|
114
114
|
]
|
|
115
115
|
};
|
|
116
|
-
return
|
|
116
|
+
return y(i);
|
|
117
117
|
};
|
|
118
118
|
}
|
|
119
|
-
function
|
|
120
|
-
return r.split(/\s+/).map((
|
|
121
|
-
let s =
|
|
122
|
-
if (
|
|
123
|
-
|
|
124
|
-
else if (
|
|
125
|
-
|
|
126
|
-
else if (
|
|
127
|
-
const
|
|
128
|
-
|
|
119
|
+
function T(t, e, r, a) {
|
|
120
|
+
return r.split(/\s+/).map((o) => o.replace(/^([^:]+)=/g, "$1:")).map((o) => {
|
|
121
|
+
let s = o.startsWith("-"), i = null, c = "", _ = !1, u;
|
|
122
|
+
if (o.startsWith("-_exists_:"))
|
|
123
|
+
i = o.substring(10), _ = !0, s = !0;
|
|
124
|
+
else if (o.startsWith("_exists_:"))
|
|
125
|
+
i = o.substring(9), _ = !0, s = !1;
|
|
126
|
+
else if (o.includes(":")) {
|
|
127
|
+
const m = s ? o.substring(1) : o, h = m.indexOf(":");
|
|
128
|
+
i = m.substring(0, h), c = m.substring(h + 1), _ = !1, c.startsWith(">=") ? (u = ">=", c = c.substring(2)) : c.startsWith(">") ? (u = ">", c = c.substring(1)) : c.startsWith("<=") ? (u = "<=", c = c.substring(2)) : c.startsWith("<") ? (u = "<", c = c.substring(1)) : u = "=";
|
|
129
129
|
} else
|
|
130
|
-
|
|
131
|
-
return { key:
|
|
132
|
-
}).forEach(({ key:
|
|
133
|
-
if (
|
|
130
|
+
i = null, c = o, _ = !1;
|
|
131
|
+
return { key: i, value: c, isNegation: s, isExistsQuery: _, operator: u };
|
|
132
|
+
}).forEach(({ key: o, value: s, isNegation: i, isExistsQuery: c, operator: _ }) => {
|
|
133
|
+
if (o)
|
|
134
134
|
if (c)
|
|
135
|
-
|
|
136
|
-
else if (
|
|
135
|
+
i ? e = e.where(o, "is", null) : e = e.where(o, "is not", null);
|
|
136
|
+
else if (i)
|
|
137
137
|
switch (_) {
|
|
138
138
|
case ">":
|
|
139
|
-
e = e.where(
|
|
139
|
+
e = e.where(o, "<=", s);
|
|
140
140
|
break;
|
|
141
141
|
case ">=":
|
|
142
|
-
e = e.where(
|
|
142
|
+
e = e.where(o, "<", s);
|
|
143
143
|
break;
|
|
144
144
|
case "<":
|
|
145
|
-
e = e.where(
|
|
145
|
+
e = e.where(o, ">=", s);
|
|
146
146
|
break;
|
|
147
147
|
case "<=":
|
|
148
|
-
e = e.where(
|
|
148
|
+
e = e.where(o, ">", s);
|
|
149
149
|
break;
|
|
150
150
|
default:
|
|
151
|
-
e = e.where(
|
|
151
|
+
e = e.where(o, "!=", s);
|
|
152
152
|
}
|
|
153
153
|
else
|
|
154
|
-
e = e.where(
|
|
154
|
+
e = e.where(o, _, s);
|
|
155
155
|
else if (s) {
|
|
156
156
|
const { ref: u } = t.dynamic;
|
|
157
157
|
e = e.where(
|
|
158
|
-
(
|
|
159
|
-
a.map((
|
|
158
|
+
(m) => m.or(
|
|
159
|
+
a.map((h) => m(u(h), "like", `%${s}%`))
|
|
160
160
|
)
|
|
161
161
|
);
|
|
162
162
|
}
|
|
163
163
|
}), e;
|
|
164
164
|
}
|
|
165
|
-
function
|
|
165
|
+
function x(t) {
|
|
166
166
|
return typeof t == "string" ? parseInt(t, 10) : typeof t == "bigint" ? Number(t) : t;
|
|
167
167
|
}
|
|
168
168
|
function Ge(t) {
|
|
169
|
-
return async (e, r = {
|
|
170
|
-
page: 0,
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
if (r.q && (a = C(t, a, r.q, ["email", "name"])), r.sort && r.sort.sort_by) {
|
|
176
|
-
const { ref: u } = t.dynamic;
|
|
177
|
-
a = a.orderBy(u(r.sort.sort_by), r.sort.sort_order);
|
|
169
|
+
return async (e, r = {}) => {
|
|
170
|
+
const { page: a = 0, per_page: n = 50, include_totals: o = !1, sort: s, q: i } = r;
|
|
171
|
+
let c = t.selectFrom("users").where("users.tenant_id", "=", e);
|
|
172
|
+
if (i && (c = T(t, c, i, ["email", "name"])), s && s.sort_by) {
|
|
173
|
+
const { ref: w } = t.dynamic;
|
|
174
|
+
c = c.orderBy(w(s.sort_by), s.sort_order);
|
|
178
175
|
}
|
|
179
|
-
const
|
|
180
|
-
const
|
|
181
|
-
(
|
|
176
|
+
const u = await c.offset(a * n).limit(n).selectAll().execute(), m = u.map((w) => w.user_id), h = m.length ? await t.selectFrom("users").selectAll().where("users.tenant_id", "=", e).where("users.linked_to", "in", m).execute() : [], f = u.map((w) => {
|
|
177
|
+
const b = h.filter(
|
|
178
|
+
(D) => D.linked_to === w.user_id
|
|
182
179
|
);
|
|
183
|
-
return
|
|
184
|
-
...
|
|
185
|
-
email_verified:
|
|
186
|
-
is_social:
|
|
187
|
-
app_metadata: JSON.parse(
|
|
188
|
-
user_metadata: JSON.parse(
|
|
180
|
+
return y({
|
|
181
|
+
...w,
|
|
182
|
+
email_verified: w.email_verified === 1,
|
|
183
|
+
is_social: w.is_social === 1,
|
|
184
|
+
app_metadata: JSON.parse(w.app_metadata),
|
|
185
|
+
user_metadata: JSON.parse(w.user_metadata),
|
|
189
186
|
identities: [
|
|
190
187
|
{
|
|
191
|
-
connection:
|
|
192
|
-
provider:
|
|
193
|
-
user_id:
|
|
194
|
-
isSocial: !!
|
|
188
|
+
connection: w.connection,
|
|
189
|
+
provider: w.provider,
|
|
190
|
+
user_id: ie(w.user_id).id,
|
|
191
|
+
isSocial: !!w.is_social
|
|
195
192
|
},
|
|
196
|
-
...
|
|
193
|
+
...b.map(pe)
|
|
197
194
|
]
|
|
198
195
|
});
|
|
199
|
-
})
|
|
196
|
+
});
|
|
197
|
+
if (!o)
|
|
198
|
+
return {
|
|
199
|
+
users: f,
|
|
200
|
+
start: 0,
|
|
201
|
+
limit: 0,
|
|
202
|
+
length: 0
|
|
203
|
+
};
|
|
204
|
+
const { count: g } = await c.select((w) => w.fn.countAll().as("count")).executeTakeFirstOrThrow();
|
|
200
205
|
return {
|
|
201
|
-
users:
|
|
202
|
-
start:
|
|
203
|
-
limit:
|
|
204
|
-
length:
|
|
206
|
+
users: f,
|
|
207
|
+
start: a * n,
|
|
208
|
+
limit: n,
|
|
209
|
+
length: x(g)
|
|
205
210
|
};
|
|
206
211
|
};
|
|
207
212
|
}
|
|
208
213
|
function He(t) {
|
|
209
214
|
return async (e, r) => (await t.deleteFrom("users").where("users.tenant_id", "=", e).where("users.linked_to", "=", r).execute(), (await t.deleteFrom("users").where("users.tenant_id", "=", e).where("users.user_id", "=", r).execute()).length === 1);
|
|
210
215
|
}
|
|
211
|
-
function
|
|
216
|
+
function J(t, e = "", r = {}) {
|
|
212
217
|
for (let a in t)
|
|
213
218
|
if (Object.prototype.hasOwnProperty.call(t, a)) {
|
|
214
|
-
const
|
|
215
|
-
typeof
|
|
219
|
+
const n = e ? `${e}_${a}` : a, o = t[a];
|
|
220
|
+
typeof o == "object" && o !== null && !Array.isArray(o) ? J(o, n, r) : typeof o == "boolean" ? r[n] = o ? 1 : 0 : r[n] = o;
|
|
216
221
|
}
|
|
217
222
|
return r;
|
|
218
223
|
}
|
|
219
224
|
function ge(t, e) {
|
|
220
225
|
const r = {};
|
|
221
|
-
for (const [a,
|
|
222
|
-
const
|
|
226
|
+
for (const [a, n] of Object.entries(t)) {
|
|
227
|
+
const o = e.find(
|
|
223
228
|
(s) => a.startsWith(`${s}_`)
|
|
224
229
|
);
|
|
225
|
-
if (!
|
|
226
|
-
r[a] =
|
|
230
|
+
if (!o)
|
|
231
|
+
r[a] = n;
|
|
227
232
|
else {
|
|
228
|
-
const s = a.slice(
|
|
229
|
-
r[
|
|
230
|
-
...r[
|
|
231
|
-
[s]:
|
|
233
|
+
const s = a.slice(o.length + 1);
|
|
234
|
+
r[o] = {
|
|
235
|
+
...r[o],
|
|
236
|
+
[s]: n
|
|
232
237
|
};
|
|
233
238
|
}
|
|
234
239
|
}
|
|
@@ -236,19 +241,19 @@ function ge(t, e) {
|
|
|
236
241
|
}
|
|
237
242
|
function Ye(t) {
|
|
238
243
|
return async (e, r, a) => {
|
|
239
|
-
const
|
|
244
|
+
const n = J({
|
|
240
245
|
...a,
|
|
241
246
|
updated_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
242
247
|
app_metadata: a.app_metadata ? JSON.stringify(a.app_metadata) : void 0,
|
|
243
248
|
user_metadata: a.user_metadata ? JSON.stringify(a.user_metadata) : void 0
|
|
244
249
|
});
|
|
245
|
-
return (await t.updateTable("users").set(
|
|
250
|
+
return (await t.updateTable("users").set(n).where("users.tenant_id", "=", e).where("users.user_id", "=", r).execute()).length === 1;
|
|
246
251
|
};
|
|
247
252
|
}
|
|
248
253
|
function Xe(t) {
|
|
249
|
-
return async (e, r, a,
|
|
250
|
-
const
|
|
251
|
-
return (await t.updateTable("users").set(
|
|
254
|
+
return async (e, r, a, n) => {
|
|
255
|
+
const o = { linked_to: null };
|
|
256
|
+
return (await t.updateTable("users").set(o).where("users.tenant_id", "=", e).where("users.user_id", "=", `${a}|${n}`).where("users.linked_to", "=", `${r}`).execute()).length === 1;
|
|
252
257
|
};
|
|
253
258
|
}
|
|
254
259
|
function Ze(t) {
|
|
@@ -263,7 +268,7 @@ function Ze(t) {
|
|
|
263
268
|
};
|
|
264
269
|
}
|
|
265
270
|
const et = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
266
|
-
let
|
|
271
|
+
let O = (t = 21) => {
|
|
267
272
|
let e = "", r = crypto.getRandomValues(new Uint8Array(t));
|
|
268
273
|
for (; t--; )
|
|
269
274
|
e += et[r[t] & 63];
|
|
@@ -272,7 +277,7 @@ let b = (t = 21) => {
|
|
|
272
277
|
function tt(t) {
|
|
273
278
|
return async (e) => {
|
|
274
279
|
const r = {
|
|
275
|
-
id: e.id ||
|
|
280
|
+
id: e.id || O(),
|
|
276
281
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
277
282
|
updated_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
278
283
|
...e
|
|
@@ -283,32 +288,29 @@ function tt(t) {
|
|
|
283
288
|
function rt(t) {
|
|
284
289
|
return async (e) => {
|
|
285
290
|
const r = await t.selectFrom("tenants").where("tenants.id", "=", e).selectAll().executeTakeFirst();
|
|
286
|
-
return r ?
|
|
291
|
+
return r ? y(r) : null;
|
|
287
292
|
};
|
|
288
293
|
}
|
|
289
294
|
function at(t) {
|
|
290
|
-
return async (e
|
|
291
|
-
page: 0,
|
|
292
|
-
per_page: 50,
|
|
293
|
-
include_totals: !1
|
|
294
|
-
}) => {
|
|
295
|
+
return async (e) => {
|
|
295
296
|
let r = t.selectFrom("tenants");
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
297
|
+
const { page: a = 0, per_page: n = 50, include_totals: o = !1, sort: s, q: i } = e;
|
|
298
|
+
if (s && s.sort_by) {
|
|
299
|
+
const { ref: f } = t.dynamic;
|
|
300
|
+
r = r.orderBy(f(s.sort_by), s.sort_order);
|
|
299
301
|
}
|
|
300
|
-
|
|
301
|
-
const
|
|
302
|
-
if (!
|
|
302
|
+
i && (r = r.where((f) => f.or([f("name", "like", `%${i}%`)])));
|
|
303
|
+
const u = (await r.offset(a * n).limit(n).selectAll().execute()).map(y);
|
|
304
|
+
if (!o)
|
|
303
305
|
return {
|
|
304
|
-
tenants:
|
|
306
|
+
tenants: u
|
|
305
307
|
};
|
|
306
|
-
const { count:
|
|
308
|
+
const { count: m } = await r.select((f) => f.fn.countAll().as("count")).executeTakeFirstOrThrow(), h = x(m);
|
|
307
309
|
return {
|
|
308
|
-
tenants:
|
|
309
|
-
start:
|
|
310
|
-
limit:
|
|
311
|
-
length:
|
|
310
|
+
tenants: u,
|
|
311
|
+
start: a * n,
|
|
312
|
+
limit: n,
|
|
313
|
+
length: h
|
|
312
314
|
};
|
|
313
315
|
};
|
|
314
316
|
}
|
|
@@ -340,19 +342,19 @@ function me(t) {
|
|
|
340
342
|
const it = 1024;
|
|
341
343
|
function lt(t) {
|
|
342
344
|
return async (e, r) => {
|
|
343
|
-
var
|
|
345
|
+
var n, o, s;
|
|
344
346
|
const a = {
|
|
345
|
-
id:
|
|
347
|
+
id: O(),
|
|
346
348
|
...r,
|
|
347
349
|
user_agent: r.user_agent.slice(0, it)
|
|
348
350
|
};
|
|
349
351
|
return await t.insertInto("logs").values({
|
|
350
352
|
...a,
|
|
351
353
|
// Truncate long strings to avoid database errors
|
|
352
|
-
description: (
|
|
354
|
+
description: (n = a.description) == null ? void 0 : n.substring(0, 256),
|
|
353
355
|
isMobile: r.isMobile ? 1 : 0,
|
|
354
356
|
tenant_id: e,
|
|
355
|
-
scope: (
|
|
357
|
+
scope: (o = r.scope) == null ? void 0 : o.join(","),
|
|
356
358
|
auth0_client: me(r.auth0_client),
|
|
357
359
|
details: (s = me(r.details)) == null ? void 0 : s.substring(0, 8192)
|
|
358
360
|
}).execute(), a;
|
|
@@ -381,28 +383,30 @@ function we(t) {
|
|
|
381
383
|
};
|
|
382
384
|
}
|
|
383
385
|
function ct(t) {
|
|
384
|
-
return async (e, r = {
|
|
385
|
-
page: 0,
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
if (r.sort && r.sort.sort_by) {
|
|
393
|
-
const { ref: l } = t.dynamic;
|
|
394
|
-
o = o.orderBy(
|
|
395
|
-
l(r.sort.sort_by),
|
|
396
|
-
r.sort.sort_order
|
|
397
|
-
);
|
|
386
|
+
return async (e, r = {}) => {
|
|
387
|
+
const { page: a = 0, per_page: n = 50, include_totals: o = !1, sort: s, q: i } = r;
|
|
388
|
+
let c = t.selectFrom("logs").where("logs.tenant_id", "=", e);
|
|
389
|
+
i && (c = T(t, c, i, ["user_id", "ip"]));
|
|
390
|
+
let _ = c;
|
|
391
|
+
if (s && s.sort_by) {
|
|
392
|
+
const { ref: f } = t.dynamic;
|
|
393
|
+
_ = _.orderBy(f(s.sort_by), s.sort_order);
|
|
398
394
|
}
|
|
399
|
-
|
|
400
|
-
const
|
|
395
|
+
_ = _.offset(a * n).limit(n);
|
|
396
|
+
const m = (await _.selectAll().execute()).map(we);
|
|
397
|
+
if (!o)
|
|
398
|
+
return {
|
|
399
|
+
logs: m,
|
|
400
|
+
start: 0,
|
|
401
|
+
limit: 0,
|
|
402
|
+
length: 0
|
|
403
|
+
};
|
|
404
|
+
const { count: h } = await c.select((f) => f.fn.countAll().as("count")).executeTakeFirstOrThrow();
|
|
401
405
|
return {
|
|
402
|
-
logs:
|
|
403
|
-
start:
|
|
404
|
-
limit:
|
|
405
|
-
length:
|
|
406
|
+
logs: m,
|
|
407
|
+
start: a * n,
|
|
408
|
+
limit: n,
|
|
409
|
+
length: x(h)
|
|
406
410
|
};
|
|
407
411
|
};
|
|
408
412
|
}
|
|
@@ -424,10 +428,10 @@ function mt(t) {
|
|
|
424
428
|
const a = await t.selectFrom("sessions").where("sessions.tenant_id", "=", e).where("sessions.id", "=", r).selectAll().executeTakeFirst();
|
|
425
429
|
if (!a)
|
|
426
430
|
return null;
|
|
427
|
-
const { tenant_id:
|
|
431
|
+
const { tenant_id: n, device: o, clients: s, ...i } = a;
|
|
428
432
|
return {
|
|
429
|
-
...
|
|
430
|
-
device: JSON.parse(
|
|
433
|
+
...i,
|
|
434
|
+
device: JSON.parse(o),
|
|
431
435
|
clients: JSON.parse(s)
|
|
432
436
|
};
|
|
433
437
|
};
|
|
@@ -454,42 +458,44 @@ function ht(t) {
|
|
|
454
458
|
}
|
|
455
459
|
function ft(t) {
|
|
456
460
|
return async (e, r, a) => {
|
|
457
|
-
const
|
|
461
|
+
const n = {
|
|
458
462
|
...a,
|
|
459
463
|
updated_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
460
464
|
device: a.device ? JSON.stringify(a.device) : void 0,
|
|
461
465
|
clients: a.clients ? JSON.stringify(a.clients) : void 0
|
|
462
466
|
};
|
|
463
|
-
return !!(await t.updateTable("sessions").set(
|
|
467
|
+
return !!(await t.updateTable("sessions").set(n).where("tenant_id", "=", e).where("sessions.id", "=", r).execute()).length;
|
|
464
468
|
};
|
|
465
469
|
}
|
|
466
470
|
function pt(t) {
|
|
467
|
-
return async (e, r = {
|
|
468
|
-
page: 0,
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
if (r.sort && r.sort.sort_by) {
|
|
476
|
-
const { ref: c } = t.dynamic;
|
|
477
|
-
o = o.orderBy(
|
|
478
|
-
c(r.sort.sort_by),
|
|
479
|
-
r.sort.sort_order
|
|
480
|
-
);
|
|
471
|
+
return async (e, r = {}) => {
|
|
472
|
+
const { page: a = 0, per_page: n = 50, include_totals: o = !1, sort: s, q: i } = r;
|
|
473
|
+
let c = t.selectFrom("sessions").where("sessions.tenant_id", "=", e);
|
|
474
|
+
i && (c = T(t, c, i, ["user_id", "session_id"]));
|
|
475
|
+
let _ = c;
|
|
476
|
+
if (s && s.sort_by) {
|
|
477
|
+
const { ref: g } = t.dynamic;
|
|
478
|
+
_ = _.orderBy(g(s.sort_by), s.sort_order);
|
|
481
479
|
}
|
|
482
|
-
|
|
483
|
-
const
|
|
480
|
+
_ = _.offset(a * n).limit(n);
|
|
481
|
+
const m = (await _.selectAll().execute()).map((g) => ({
|
|
482
|
+
...g,
|
|
483
|
+
device: JSON.parse(g.device),
|
|
484
|
+
clients: JSON.parse(g.clients)
|
|
485
|
+
}));
|
|
486
|
+
if (!o)
|
|
487
|
+
return {
|
|
488
|
+
sessions: m,
|
|
489
|
+
start: 0,
|
|
490
|
+
limit: 0,
|
|
491
|
+
length: 0
|
|
492
|
+
};
|
|
493
|
+
const { count: h } = await c.select((g) => g.fn.countAll().as("count")).executeTakeFirstOrThrow(), f = x(h);
|
|
484
494
|
return {
|
|
485
|
-
sessions:
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
})),
|
|
490
|
-
start: r.page * r.per_page,
|
|
491
|
-
limit: r.per_page,
|
|
492
|
-
length: l
|
|
495
|
+
sessions: m,
|
|
496
|
+
start: a * n,
|
|
497
|
+
limit: n,
|
|
498
|
+
length: f
|
|
493
499
|
};
|
|
494
500
|
};
|
|
495
501
|
}
|
|
@@ -507,8 +513,8 @@ function wt(t) {
|
|
|
507
513
|
const a = await t.selectFrom("passwords").where("passwords.tenant_id", "=", e).where("passwords.user_id", "=", r).selectAll().executeTakeFirst();
|
|
508
514
|
if (!a)
|
|
509
515
|
return null;
|
|
510
|
-
const { tenant_id:
|
|
511
|
-
return
|
|
516
|
+
const { tenant_id: n, ...o } = a;
|
|
517
|
+
return o;
|
|
512
518
|
};
|
|
513
519
|
}
|
|
514
520
|
function yt(t) {
|
|
@@ -538,22 +544,27 @@ function Nt(t) {
|
|
|
538
544
|
};
|
|
539
545
|
}
|
|
540
546
|
function Ct(t) {
|
|
541
|
-
return async (e, r = {
|
|
542
|
-
page: 0,
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
547
|
+
return async (e, r = {}) => {
|
|
548
|
+
const { page: a = 0, per_page: n = 50, include_totals: o = !1, q: s } = r;
|
|
549
|
+
let i = t.selectFrom("codes").where("codes.tenant_id", "=", e);
|
|
550
|
+
s && (i = T(t, i, s, ["code", "login_id"]));
|
|
551
|
+
const u = (await i.offset(a * n).limit(n).selectAll().execute()).map((h) => {
|
|
552
|
+
const { tenant_id: f, ...g } = h;
|
|
553
|
+
return Ke.parse(y(g));
|
|
554
|
+
});
|
|
555
|
+
if (!o)
|
|
556
|
+
return {
|
|
557
|
+
codes: u,
|
|
558
|
+
start: 0,
|
|
559
|
+
limit: 0,
|
|
560
|
+
length: 0
|
|
561
|
+
};
|
|
562
|
+
const { count: m } = await i.select((h) => h.fn.countAll().as("count")).executeTakeFirstOrThrow();
|
|
549
563
|
return {
|
|
550
|
-
codes:
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
start: r.page * r.per_page,
|
|
555
|
-
limit: r.per_page,
|
|
556
|
-
length: v(s)
|
|
564
|
+
codes: u,
|
|
565
|
+
start: a * n,
|
|
566
|
+
limit: n,
|
|
567
|
+
length: x(m)
|
|
557
568
|
};
|
|
558
569
|
};
|
|
559
570
|
}
|
|
@@ -574,10 +585,10 @@ function xt(t) {
|
|
|
574
585
|
}
|
|
575
586
|
function Tt(t) {
|
|
576
587
|
return async (e, r, a) => {
|
|
577
|
-
let
|
|
578
|
-
e.length && (
|
|
579
|
-
const
|
|
580
|
-
return
|
|
588
|
+
let n = t.selectFrom("codes").where("codes.code_id", "=", r).where("codes.code_type", "=", a);
|
|
589
|
+
e.length && (n = n.where("codes.tenant_id", "=", e));
|
|
590
|
+
const o = await n.selectAll().executeTakeFirst();
|
|
591
|
+
return o ? y(o) : null;
|
|
581
592
|
};
|
|
582
593
|
}
|
|
583
594
|
function St(t) {
|
|
@@ -599,38 +610,38 @@ function kt(t) {
|
|
|
599
610
|
updated_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
600
611
|
...r,
|
|
601
612
|
disable_sign_ups: r.disable_sign_ups ?? !1
|
|
602
|
-
},
|
|
613
|
+
}, n = JSON.stringify(r.allowed_origins), o = JSON.stringify(r.callbacks), s = JSON.stringify(r.web_origins), i = JSON.stringify(r.allowed_logout_urls), c = JSON.stringify(r.allowed_clients);
|
|
603
614
|
return await t.insertInto("applications").values({
|
|
604
615
|
...a,
|
|
605
616
|
tenant_id: e,
|
|
606
617
|
disable_sign_ups: r.disable_sign_ups ? 1 : 0,
|
|
607
618
|
addons: r.addons ? JSON.stringify(r.addons) : "{}",
|
|
608
|
-
callbacks:
|
|
609
|
-
allowed_origins:
|
|
619
|
+
callbacks: o,
|
|
620
|
+
allowed_origins: n,
|
|
610
621
|
web_origins: s,
|
|
611
|
-
allowed_logout_urls:
|
|
622
|
+
allowed_logout_urls: i,
|
|
612
623
|
allowed_clients: c
|
|
613
624
|
}).execute(), a;
|
|
614
625
|
};
|
|
615
626
|
}
|
|
616
627
|
function $t(t) {
|
|
617
628
|
return async (e) => ({
|
|
618
|
-
applications: (await t.selectFrom("applications").where("applications.tenant_id", "=", e).selectAll().execute()).map((
|
|
619
|
-
...
|
|
620
|
-
disable_sign_ups: !!
|
|
621
|
-
addons:
|
|
622
|
-
callbacks:
|
|
623
|
-
allowed_origins:
|
|
624
|
-
web_origins:
|
|
625
|
-
allowed_logout_urls:
|
|
626
|
-
allowed_clients:
|
|
629
|
+
applications: (await t.selectFrom("applications").where("applications.tenant_id", "=", e).selectAll().execute()).map((o) => ({
|
|
630
|
+
...o,
|
|
631
|
+
disable_sign_ups: !!o.disable_sign_ups,
|
|
632
|
+
addons: o.addons ? JSON.parse(o.addons) : {},
|
|
633
|
+
callbacks: o.callbacks ? JSON.parse(o.callbacks) : [],
|
|
634
|
+
allowed_origins: o.allowed_origins ? JSON.parse(o.allowed_origins) : [],
|
|
635
|
+
web_origins: o.web_origins ? JSON.parse(o.web_origins) : [],
|
|
636
|
+
allowed_logout_urls: o.allowed_logout_urls ? JSON.parse(o.allowed_logout_urls) : [],
|
|
637
|
+
allowed_clients: o.allowed_logout_urls ? JSON.parse(o.allowed_logout_urls) : []
|
|
627
638
|
}))
|
|
628
639
|
});
|
|
629
640
|
}
|
|
630
641
|
function It(t) {
|
|
631
642
|
return async (e, r) => {
|
|
632
643
|
const a = await t.selectFrom("applications").where("applications.tenant_id", "=", e).where("applications.id", "=", r).selectAll().executeTakeFirst();
|
|
633
|
-
return a ?
|
|
644
|
+
return a ? y({
|
|
634
645
|
...a,
|
|
635
646
|
disable_sign_ups: !!a.disable_sign_ups,
|
|
636
647
|
addons: JSON.parse(a.addons),
|
|
@@ -646,7 +657,7 @@ function Dt(t) {
|
|
|
646
657
|
}
|
|
647
658
|
function Pt(t) {
|
|
648
659
|
return async (e, r, a) => {
|
|
649
|
-
const
|
|
660
|
+
const n = {
|
|
650
661
|
...a,
|
|
651
662
|
updated_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
652
663
|
allowed_origins: a.allowed_origins ? JSON.stringify(a.allowed_origins) : void 0,
|
|
@@ -657,7 +668,7 @@ function Pt(t) {
|
|
|
657
668
|
addons: a.addons ? JSON.stringify(a.addons) : "{}",
|
|
658
669
|
disable_sign_ups: a.disable_sign_ups ? 1 : 0
|
|
659
670
|
};
|
|
660
|
-
return await t.updateTable("applications").set(
|
|
671
|
+
return await t.updateTable("applications").set(n).where("applications.id", "=", r).where("applications.tenant_id", "=", e).execute(), !0;
|
|
661
672
|
};
|
|
662
673
|
}
|
|
663
674
|
function jt(t) {
|
|
@@ -672,7 +683,7 @@ function jt(t) {
|
|
|
672
683
|
function Ft(t) {
|
|
673
684
|
return async (e, r) => {
|
|
674
685
|
const a = {
|
|
675
|
-
id:
|
|
686
|
+
id: O(),
|
|
676
687
|
...r,
|
|
677
688
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
678
689
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
@@ -686,24 +697,29 @@ function Ft(t) {
|
|
|
686
697
|
};
|
|
687
698
|
}
|
|
688
699
|
function Mt(t) {
|
|
689
|
-
return async (e, r = {
|
|
690
|
-
page: 0,
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
(c) => f({
|
|
698
|
-
...c,
|
|
699
|
-
options: JSON.parse(c.options)
|
|
700
|
+
return async (e, r = {}) => {
|
|
701
|
+
const { page: a = 0, per_page: n = 50, include_totals: o = !1, q: s } = r;
|
|
702
|
+
let i = t.selectFrom("connections").where("connections.tenant_id", "=", e);
|
|
703
|
+
s && (i = T(t, i, s, ["user_id", "ip"]));
|
|
704
|
+
const u = (await i.offset(a * n).limit(n).selectAll().execute()).map(
|
|
705
|
+
(h) => y({
|
|
706
|
+
...h,
|
|
707
|
+
options: JSON.parse(h.options)
|
|
700
708
|
})
|
|
701
|
-
)
|
|
709
|
+
);
|
|
710
|
+
if (!o)
|
|
711
|
+
return {
|
|
712
|
+
connections: u,
|
|
713
|
+
start: 0,
|
|
714
|
+
limit: 0,
|
|
715
|
+
length: 0
|
|
716
|
+
};
|
|
717
|
+
const { count: m } = await i.select((h) => h.fn.countAll().as("count")).executeTakeFirstOrThrow();
|
|
702
718
|
return {
|
|
703
|
-
connections:
|
|
704
|
-
start:
|
|
705
|
-
limit:
|
|
706
|
-
length:
|
|
719
|
+
connections: u,
|
|
720
|
+
start: a * n,
|
|
721
|
+
limit: n,
|
|
722
|
+
length: x(m)
|
|
707
723
|
};
|
|
708
724
|
};
|
|
709
725
|
}
|
|
@@ -713,7 +729,7 @@ function At(t) {
|
|
|
713
729
|
function zt(t) {
|
|
714
730
|
return async (e, r) => {
|
|
715
731
|
const a = await t.selectFrom("connections").where("connections.tenant_id", "=", e).where("connections.id", "=", r).selectAll().executeTakeFirst();
|
|
716
|
-
return a ?
|
|
732
|
+
return a ? y({
|
|
717
733
|
...a,
|
|
718
734
|
options: JSON.parse(a.options)
|
|
719
735
|
}) : null;
|
|
@@ -721,13 +737,13 @@ function zt(t) {
|
|
|
721
737
|
}
|
|
722
738
|
function Lt(t) {
|
|
723
739
|
return async (e, r, a) => {
|
|
724
|
-
const
|
|
740
|
+
const n = {
|
|
725
741
|
...a,
|
|
726
742
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
727
743
|
};
|
|
728
744
|
return await t.updateTable("connections").set({
|
|
729
|
-
...
|
|
730
|
-
options:
|
|
745
|
+
...n,
|
|
746
|
+
options: n.options ? JSON.stringify(n.options) : void 0
|
|
731
747
|
}).where("connections.id", "=", r).where("connections.tenant_id", "=", e).execute(), !0;
|
|
732
748
|
};
|
|
733
749
|
}
|
|
@@ -748,13 +764,13 @@ function Jt(t) {
|
|
|
748
764
|
return null;
|
|
749
765
|
const a = await t.selectFrom("tenants").selectAll().where("id", "=", r.tenant_id).executeTakeFirst();
|
|
750
766
|
if (!a)
|
|
751
|
-
throw new
|
|
752
|
-
const
|
|
767
|
+
throw new te(404, { message: "Tenant not found" });
|
|
768
|
+
const n = await t.selectFrom("connections").where("tenant_id", "=", r.tenant_id).selectAll().execute();
|
|
753
769
|
return {
|
|
754
770
|
...r,
|
|
755
|
-
connections:
|
|
771
|
+
connections: n.map(
|
|
756
772
|
(s) => Ue.parse(
|
|
757
|
-
|
|
773
|
+
y({
|
|
758
774
|
...s,
|
|
759
775
|
options: s.options ? JSON.parse(s.options) : {}
|
|
760
776
|
})
|
|
@@ -766,7 +782,7 @@ function Jt(t) {
|
|
|
766
782
|
web_origins: r.web_origins ? JSON.parse(r.web_origins) : [],
|
|
767
783
|
allowed_logout_urls: r.allowed_logout_urls ? JSON.parse(r.allowed_logout_urls) : [],
|
|
768
784
|
allowed_clients: r.allowed_clients ? JSON.parse(r.allowed_clients) : [],
|
|
769
|
-
tenant:
|
|
785
|
+
tenant: y(a),
|
|
770
786
|
// this is really an integer in the database
|
|
771
787
|
disable_sign_ups: !!r.disable_sign_ups
|
|
772
788
|
};
|
|
@@ -774,12 +790,46 @@ function Jt(t) {
|
|
|
774
790
|
};
|
|
775
791
|
}
|
|
776
792
|
function Rt(t) {
|
|
777
|
-
return async () =>
|
|
778
|
-
|
|
779
|
-
r
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
793
|
+
return async (e = {}) => {
|
|
794
|
+
const {
|
|
795
|
+
page: r = 0,
|
|
796
|
+
per_page: a = 100,
|
|
797
|
+
include_totals: n = !1,
|
|
798
|
+
sort: o,
|
|
799
|
+
q: s
|
|
800
|
+
} = e;
|
|
801
|
+
let i = t.selectFrom("keys").where(
|
|
802
|
+
(f) => f.or([
|
|
803
|
+
f("revoked_at", ">", (/* @__PURE__ */ new Date()).toISOString()),
|
|
804
|
+
f("revoked_at", "is", null)
|
|
805
|
+
])
|
|
806
|
+
);
|
|
807
|
+
s && (i = T(t, i, s, [
|
|
808
|
+
"kid",
|
|
809
|
+
"connection",
|
|
810
|
+
"fingerprint",
|
|
811
|
+
"thumbprint",
|
|
812
|
+
"type"
|
|
813
|
+
]));
|
|
814
|
+
let c = i.select((f) => f.fn.count("kid").as("count"));
|
|
815
|
+
const _ = r * a;
|
|
816
|
+
i = i.limit(a).offset(_), o && (i = i.orderBy(o.sort_by, o.sort_order));
|
|
817
|
+
const u = await i.selectAll().execute();
|
|
818
|
+
if (!n)
|
|
819
|
+
return {
|
|
820
|
+
signingKeys: u,
|
|
821
|
+
start: 0,
|
|
822
|
+
limit: 0,
|
|
823
|
+
length: 0
|
|
824
|
+
};
|
|
825
|
+
const m = await c.executeTakeFirst(), h = x((m == null ? void 0 : m.count) ?? 0);
|
|
826
|
+
return {
|
|
827
|
+
signingKeys: u,
|
|
828
|
+
start: _,
|
|
829
|
+
limit: a,
|
|
830
|
+
length: h
|
|
831
|
+
};
|
|
832
|
+
};
|
|
783
833
|
}
|
|
784
834
|
function Kt(t) {
|
|
785
835
|
return async (e) => {
|
|
@@ -799,7 +849,7 @@ function Bt(t) {
|
|
|
799
849
|
function Qt(t) {
|
|
800
850
|
return async (e, r) => {
|
|
801
851
|
const a = {
|
|
802
|
-
custom_domain_id:
|
|
852
|
+
custom_domain_id: O(),
|
|
803
853
|
status: "pending",
|
|
804
854
|
primary: !1,
|
|
805
855
|
...r
|
|
@@ -833,12 +883,12 @@ function Wt(t) {
|
|
|
833
883
|
}
|
|
834
884
|
function Gt(t) {
|
|
835
885
|
return async (e, r, a) => {
|
|
836
|
-
const
|
|
886
|
+
const n = {
|
|
837
887
|
...a,
|
|
838
888
|
updated_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
839
889
|
primary: a.primary ? 1 : 0
|
|
840
890
|
};
|
|
841
|
-
return (await t.updateTable("custom_domains").set(
|
|
891
|
+
return (await t.updateTable("custom_domains").set(n).where("custom_domains.tenant_id", "=", e).where("custom_domains.custom_domain_id", "=", r).execute()).length > 0;
|
|
842
892
|
};
|
|
843
893
|
}
|
|
844
894
|
function Ht(t) {
|
|
@@ -867,22 +917,22 @@ function Xt(t) {
|
|
|
867
917
|
return null;
|
|
868
918
|
const {
|
|
869
919
|
tenant_id: a,
|
|
870
|
-
colors_primary:
|
|
871
|
-
colors_page_background_type:
|
|
920
|
+
colors_primary: n,
|
|
921
|
+
colors_page_background_type: o,
|
|
872
922
|
colors_page_background_start: s,
|
|
873
|
-
colors_page_background_end:
|
|
923
|
+
colors_page_background_end: i,
|
|
874
924
|
colors_page_background_angle_dev: c,
|
|
875
925
|
font_url: _,
|
|
876
926
|
...u
|
|
877
927
|
} = r;
|
|
878
|
-
return
|
|
928
|
+
return y({
|
|
879
929
|
...u,
|
|
880
930
|
colors: {
|
|
881
|
-
primary:
|
|
931
|
+
primary: n,
|
|
882
932
|
page_background: {
|
|
883
|
-
type:
|
|
933
|
+
type: o,
|
|
884
934
|
start: s,
|
|
885
|
-
end:
|
|
935
|
+
end: i,
|
|
886
936
|
angle_deg: c
|
|
887
937
|
}
|
|
888
938
|
},
|
|
@@ -892,26 +942,26 @@ function Xt(t) {
|
|
|
892
942
|
}
|
|
893
943
|
function Zt(t) {
|
|
894
944
|
return async (e, r) => {
|
|
895
|
-
var s,
|
|
896
|
-
const { colors: a, font:
|
|
945
|
+
var s, i, c, _, u, m, h, f, g, w, b, D, M, P, V, le, ce, de;
|
|
946
|
+
const { colors: a, font: n, ...o } = r;
|
|
897
947
|
try {
|
|
898
948
|
await t.insertInto("branding").values({
|
|
899
|
-
...
|
|
949
|
+
...o,
|
|
900
950
|
colors_primary: a == null ? void 0 : a.primary,
|
|
901
|
-
colors_page_background_type: (
|
|
951
|
+
colors_page_background_type: (i = (s = r.colors) == null ? void 0 : s.page_background) == null ? void 0 : i.type,
|
|
902
952
|
colors_page_background_start: (_ = (c = r.colors) == null ? void 0 : c.page_background) == null ? void 0 : _.start,
|
|
903
|
-
colors_page_background_end: (
|
|
904
|
-
colors_page_background_angle_dev: (
|
|
905
|
-
font_url: (
|
|
953
|
+
colors_page_background_end: (m = (u = r.colors) == null ? void 0 : u.page_background) == null ? void 0 : m.end,
|
|
954
|
+
colors_page_background_angle_dev: (f = (h = r.colors) == null ? void 0 : h.page_background) == null ? void 0 : f.angle_deg,
|
|
955
|
+
font_url: (g = r.font) == null ? void 0 : g.url,
|
|
906
956
|
tenant_id: e
|
|
907
957
|
}).execute();
|
|
908
958
|
} catch {
|
|
909
959
|
await t.updateTable("branding").set({
|
|
910
|
-
...
|
|
960
|
+
...o,
|
|
911
961
|
colors_primary: a == null ? void 0 : a.primary,
|
|
912
|
-
colors_page_background_type: (
|
|
913
|
-
colors_page_background_start: (
|
|
914
|
-
colors_page_background_end: (
|
|
962
|
+
colors_page_background_type: (b = (w = r.colors) == null ? void 0 : w.page_background) == null ? void 0 : b.type,
|
|
963
|
+
colors_page_background_start: (M = (D = r.colors) == null ? void 0 : D.page_background) == null ? void 0 : M.start,
|
|
964
|
+
colors_page_background_end: (V = (P = r.colors) == null ? void 0 : P.page_background) == null ? void 0 : V.end,
|
|
915
965
|
colors_page_background_angle_dev: (ce = (le = r.colors) == null ? void 0 : le.page_background) == null ? void 0 : ce.angle_deg,
|
|
916
966
|
font_url: (de = r.font) == null ? void 0 : de.url
|
|
917
967
|
}).where("tenant_id", "=", e).execute();
|
|
@@ -925,33 +975,38 @@ function er(t) {
|
|
|
925
975
|
};
|
|
926
976
|
}
|
|
927
977
|
function tr(t) {
|
|
928
|
-
return async (e, r = {
|
|
929
|
-
page: 0,
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
978
|
+
return async (e, r = {}) => {
|
|
979
|
+
const { page: a = 0, per_page: n = 50, include_totals: o = !1, q: s } = r;
|
|
980
|
+
let i = t.selectFrom("hooks").where("hooks.tenant_id", "=", e);
|
|
981
|
+
s && (i = T(t, i, s, ["url", "form_id"]));
|
|
982
|
+
const u = (await i.offset(a * n).limit(n).selectAll().execute()).map((h) => {
|
|
983
|
+
const { tenant_id: f, enabled: g, synchronous: w, ...b } = h;
|
|
984
|
+
return y({
|
|
985
|
+
...b,
|
|
986
|
+
enabled: !!g,
|
|
987
|
+
synchronous: !!w
|
|
988
|
+
});
|
|
989
|
+
});
|
|
990
|
+
if (!o)
|
|
991
|
+
return {
|
|
992
|
+
hooks: u,
|
|
993
|
+
start: 0,
|
|
994
|
+
limit: 0,
|
|
995
|
+
length: 0
|
|
996
|
+
};
|
|
997
|
+
const { count: m } = await i.select((h) => h.fn.countAll().as("count")).executeTakeFirstOrThrow();
|
|
936
998
|
return {
|
|
937
|
-
hooks:
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
enabled: !!u,
|
|
942
|
-
synchronous: !!h
|
|
943
|
-
});
|
|
944
|
-
}),
|
|
945
|
-
start: r.page * r.per_page,
|
|
946
|
-
limit: r.per_page,
|
|
947
|
-
length: v(s)
|
|
999
|
+
hooks: u,
|
|
1000
|
+
start: a * n,
|
|
1001
|
+
limit: n,
|
|
1002
|
+
length: x(m)
|
|
948
1003
|
};
|
|
949
1004
|
};
|
|
950
1005
|
}
|
|
951
1006
|
function rr(t) {
|
|
952
1007
|
return async (e, r) => {
|
|
953
1008
|
const a = await t.selectFrom("hooks").where("hooks.tenant_id", "=", e).where("hooks.hook_id", "=", r).selectAll().executeTakeFirst();
|
|
954
|
-
return a ?
|
|
1009
|
+
return a ? y({
|
|
955
1010
|
...a,
|
|
956
1011
|
enabled: !!a.enabled,
|
|
957
1012
|
synchronous: !!a.synchronous
|
|
@@ -964,7 +1019,7 @@ function ar(t) {
|
|
|
964
1019
|
function nr(t) {
|
|
965
1020
|
return async (e, r) => {
|
|
966
1021
|
const a = {
|
|
967
|
-
hook_id:
|
|
1022
|
+
hook_id: O(),
|
|
968
1023
|
...r,
|
|
969
1024
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
970
1025
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
@@ -979,13 +1034,13 @@ function nr(t) {
|
|
|
979
1034
|
}
|
|
980
1035
|
function or(t) {
|
|
981
1036
|
return async (e, r, a) => {
|
|
982
|
-
const
|
|
1037
|
+
const n = {
|
|
983
1038
|
...a,
|
|
984
1039
|
updated_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
985
1040
|
enabled: a.enabled !== void 0 ? a.enabled ? 1 : 0 : void 0,
|
|
986
1041
|
synchronous: a.enabled !== void 0 ? a.synchronous ? 1 : 0 : void 0
|
|
987
1042
|
};
|
|
988
|
-
return await t.updateTable("hooks").set(
|
|
1043
|
+
return await t.updateTable("hooks").set(n).where("hooks.hook_id", "=", r).where("hooks.tenant_id", "=", e).execute(), !0;
|
|
989
1044
|
};
|
|
990
1045
|
}
|
|
991
1046
|
function sr(t) {
|
|
@@ -1000,15 +1055,15 @@ function sr(t) {
|
|
|
1000
1055
|
function ir(t) {
|
|
1001
1056
|
return async (e, r) => {
|
|
1002
1057
|
const a = {
|
|
1003
|
-
themeId:
|
|
1058
|
+
themeId: O(),
|
|
1004
1059
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1005
1060
|
updated_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1006
1061
|
...r
|
|
1007
|
-
},
|
|
1062
|
+
}, n = {
|
|
1008
1063
|
...a,
|
|
1009
1064
|
tenant_id: e
|
|
1010
1065
|
};
|
|
1011
|
-
return await t.insertInto("themes").values(
|
|
1066
|
+
return await t.insertInto("themes").values(J(n)).execute(), a;
|
|
1012
1067
|
};
|
|
1013
1068
|
}
|
|
1014
1069
|
function lr(t) {
|
|
@@ -1019,7 +1074,7 @@ function cr(t) {
|
|
|
1019
1074
|
const a = await t.selectFrom("themes").where("themes.tenant_id", "=", e).where("themes.themeId", "=", r).selectAll().executeTakeFirst();
|
|
1020
1075
|
if (!a)
|
|
1021
1076
|
return null;
|
|
1022
|
-
const
|
|
1077
|
+
const n = {
|
|
1023
1078
|
...a,
|
|
1024
1079
|
borders_show_widget_shadow: !!a.borders_show_widget_shadow,
|
|
1025
1080
|
fonts_body_text_bold: !!a.fonts_body_text_bold,
|
|
@@ -1029,8 +1084,8 @@ function cr(t) {
|
|
|
1029
1084
|
fonts_subtitle_bold: !!a.fonts_subtitle_bold,
|
|
1030
1085
|
fonts_title_bold: !!a.fonts_title_bold
|
|
1031
1086
|
};
|
|
1032
|
-
return
|
|
1033
|
-
ge(
|
|
1087
|
+
return y(
|
|
1088
|
+
ge(n, [
|
|
1034
1089
|
"widget",
|
|
1035
1090
|
"colors",
|
|
1036
1091
|
"borders",
|
|
@@ -1042,11 +1097,11 @@ function cr(t) {
|
|
|
1042
1097
|
}
|
|
1043
1098
|
function dr(t) {
|
|
1044
1099
|
return async (e, r, a) => {
|
|
1045
|
-
const
|
|
1100
|
+
const n = J({
|
|
1046
1101
|
...a,
|
|
1047
1102
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1048
1103
|
});
|
|
1049
|
-
return await t.updateTable("themes").set(
|
|
1104
|
+
return await t.updateTable("themes").set(n).where("themes.themeId", "=", r).where("themes.tenant_id", "=", e).execute(), !0;
|
|
1050
1105
|
};
|
|
1051
1106
|
}
|
|
1052
1107
|
function ur(t) {
|
|
@@ -1062,7 +1117,7 @@ function mr(t) {
|
|
|
1062
1117
|
const a = await t.selectFrom("login_sessions").where("login_sessions.id", "=", r).selectAll().executeTakeFirst();
|
|
1063
1118
|
return a ? Be.parse(
|
|
1064
1119
|
ge(
|
|
1065
|
-
|
|
1120
|
+
y({
|
|
1066
1121
|
...a,
|
|
1067
1122
|
login_completed: !!a.login_completed
|
|
1068
1123
|
}),
|
|
@@ -1073,24 +1128,24 @@ function mr(t) {
|
|
|
1073
1128
|
}
|
|
1074
1129
|
function _r(t) {
|
|
1075
1130
|
return async (e, r) => {
|
|
1076
|
-
var
|
|
1131
|
+
var n;
|
|
1077
1132
|
const a = {
|
|
1078
|
-
id:
|
|
1133
|
+
id: O(),
|
|
1079
1134
|
...r,
|
|
1080
|
-
authorization_url: (
|
|
1135
|
+
authorization_url: (n = r.authorization_url) == null ? void 0 : n.slice(0, 1024),
|
|
1081
1136
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1082
1137
|
updated_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1083
1138
|
login_completed: !!r.login_completed
|
|
1084
1139
|
};
|
|
1085
1140
|
return await t.insertInto("login_sessions").values({
|
|
1086
|
-
...
|
|
1141
|
+
...J(a),
|
|
1087
1142
|
tenant_id: e
|
|
1088
1143
|
}).execute(), a;
|
|
1089
1144
|
};
|
|
1090
1145
|
}
|
|
1091
1146
|
function hr(t) {
|
|
1092
1147
|
return async (e, r, a) => (await t.updateTable("login_sessions").set(
|
|
1093
|
-
|
|
1148
|
+
J({
|
|
1094
1149
|
...a
|
|
1095
1150
|
})
|
|
1096
1151
|
).where("login_sessions.id", "=", r).where("login_sessions.tenant_id", "=", e).execute()).length === 1;
|
|
@@ -1109,7 +1164,7 @@ function pr(t) {
|
|
|
1109
1164
|
function gr(t) {
|
|
1110
1165
|
return async (e) => {
|
|
1111
1166
|
const [r] = await t.selectFrom("prompt_settings").where("prompt_settings.tenant_id", "=", e).selectAll().execute();
|
|
1112
|
-
return
|
|
1167
|
+
return y({
|
|
1113
1168
|
identifier_first: !!(r != null && r.identifier_first),
|
|
1114
1169
|
password_first: !!(r != null && r.password_first),
|
|
1115
1170
|
webauthn_platform_first_factor: !!(r != null && r.webauthn_platform_first_factor),
|
|
@@ -1118,7 +1173,7 @@ function gr(t) {
|
|
|
1118
1173
|
};
|
|
1119
1174
|
}
|
|
1120
1175
|
function he(t) {
|
|
1121
|
-
return
|
|
1176
|
+
return y({
|
|
1122
1177
|
...t,
|
|
1123
1178
|
webauthn_platform_first_factor: t.webauthn_platform_first_factor ? !!t.webauthn_platform_first_factor : void 0,
|
|
1124
1179
|
identifier_first: t.identifier_first ? !!t.identifier_first : void 0,
|
|
@@ -1152,38 +1207,38 @@ function vr(t) {
|
|
|
1152
1207
|
return null;
|
|
1153
1208
|
const {
|
|
1154
1209
|
tenant_id: a,
|
|
1155
|
-
credentials:
|
|
1156
|
-
settings:
|
|
1210
|
+
credentials: n,
|
|
1211
|
+
settings: o,
|
|
1157
1212
|
enabled: s,
|
|
1158
|
-
...
|
|
1213
|
+
...i
|
|
1159
1214
|
} = r;
|
|
1160
|
-
return
|
|
1161
|
-
...
|
|
1162
|
-
credentials: JSON.parse(
|
|
1163
|
-
settings: JSON.parse(
|
|
1215
|
+
return y({
|
|
1216
|
+
...i,
|
|
1217
|
+
credentials: JSON.parse(n),
|
|
1218
|
+
settings: JSON.parse(o),
|
|
1164
1219
|
enabled: !!s
|
|
1165
1220
|
});
|
|
1166
1221
|
};
|
|
1167
1222
|
}
|
|
1168
1223
|
function Nr(t) {
|
|
1169
1224
|
return async (e, r) => {
|
|
1170
|
-
const { credentials: a, settings:
|
|
1225
|
+
const { credentials: a, settings: n, enabled: o, ...s } = r;
|
|
1171
1226
|
await t.updateTable("email_providers").set({
|
|
1172
1227
|
...s,
|
|
1173
1228
|
credentials: a ? JSON.stringify(a) : void 0,
|
|
1174
|
-
settings:
|
|
1175
|
-
enabled:
|
|
1229
|
+
settings: n ? JSON.stringify(n) : void 0,
|
|
1230
|
+
enabled: o !== void 0 ? o ? 1 : 0 : void 0
|
|
1176
1231
|
}).where("tenant_id", "=", e).execute();
|
|
1177
1232
|
};
|
|
1178
1233
|
}
|
|
1179
1234
|
function Cr(t) {
|
|
1180
1235
|
return async (e, r) => {
|
|
1181
|
-
const { credentials: a, settings:
|
|
1236
|
+
const { credentials: a, settings: n, enabled: o, ...s } = r;
|
|
1182
1237
|
await t.insertInto("email_providers").values({
|
|
1183
1238
|
...s,
|
|
1184
|
-
enabled:
|
|
1239
|
+
enabled: o ? 1 : 0,
|
|
1185
1240
|
credentials: JSON.stringify(a),
|
|
1186
|
-
settings: JSON.stringify(
|
|
1241
|
+
settings: JSON.stringify(n),
|
|
1187
1242
|
tenant_id: e,
|
|
1188
1243
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1189
1244
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
@@ -1228,43 +1283,45 @@ function Sr(t) {
|
|
|
1228
1283
|
}
|
|
1229
1284
|
function Or(t) {
|
|
1230
1285
|
return async (e, r, a) => {
|
|
1231
|
-
const
|
|
1286
|
+
const n = {
|
|
1232
1287
|
...a,
|
|
1233
1288
|
device: a.device ? JSON.stringify(a.device) : void 0,
|
|
1234
1289
|
resource_servers: a.resource_servers ? JSON.stringify(a.resource_servers) : void 0,
|
|
1235
1290
|
rotating: a.rotating ? 1 : 0
|
|
1236
1291
|
};
|
|
1237
|
-
return !!(await t.updateTable("refresh_tokens").set(
|
|
1292
|
+
return !!(await t.updateTable("refresh_tokens").set(n).where("tenant_id", "=", e).where("refresh_tokens.id", "=", r).execute()).length;
|
|
1238
1293
|
};
|
|
1239
1294
|
}
|
|
1240
1295
|
function kr(t) {
|
|
1241
|
-
return async (e, r = {
|
|
1242
|
-
page: 0,
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
if (r.sort && r.sort.sort_by) {
|
|
1250
|
-
const { ref: c } = t.dynamic;
|
|
1251
|
-
o = o.orderBy(
|
|
1252
|
-
c(r.sort.sort_by),
|
|
1253
|
-
r.sort.sort_order
|
|
1254
|
-
);
|
|
1296
|
+
return async (e, r = {}) => {
|
|
1297
|
+
const { page: a = 0, per_page: n = 50, include_totals: o = !1, sort: s, q: i } = r;
|
|
1298
|
+
let c = t.selectFrom("refresh_tokens").where("refresh_tokens.tenant_id", "=", e);
|
|
1299
|
+
i && (c = T(t, c, i, ["token", "session_id"]));
|
|
1300
|
+
let _ = c;
|
|
1301
|
+
if (s && s.sort_by) {
|
|
1302
|
+
const { ref: g } = t.dynamic;
|
|
1303
|
+
_ = _.orderBy(g(s.sort_by), s.sort_order);
|
|
1255
1304
|
}
|
|
1256
|
-
|
|
1257
|
-
const
|
|
1305
|
+
_ = _.offset(a * n).limit(n);
|
|
1306
|
+
const m = (await _.selectAll().execute()).map((g) => ({
|
|
1307
|
+
...g,
|
|
1308
|
+
rotating: !!g.rotating,
|
|
1309
|
+
device: g.device ? JSON.parse(g.device) : {},
|
|
1310
|
+
resource_servers: g.resource_servers ? JSON.parse(g.resource_servers) : []
|
|
1311
|
+
}));
|
|
1312
|
+
if (!o)
|
|
1313
|
+
return {
|
|
1314
|
+
refresh_tokens: m,
|
|
1315
|
+
start: 0,
|
|
1316
|
+
limit: 0,
|
|
1317
|
+
length: 0
|
|
1318
|
+
};
|
|
1319
|
+
const { count: h } = await c.select((g) => g.fn.countAll().as("count")).executeTakeFirstOrThrow(), f = x(h);
|
|
1258
1320
|
return {
|
|
1259
|
-
refresh_tokens:
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
resource_servers: c.resource_servers ? JSON.parse(c.resource_servers) : []
|
|
1264
|
-
})),
|
|
1265
|
-
start: r.page * r.per_page,
|
|
1266
|
-
limit: r.per_page,
|
|
1267
|
-
length: l
|
|
1321
|
+
refresh_tokens: m,
|
|
1322
|
+
start: a * n,
|
|
1323
|
+
limit: n,
|
|
1324
|
+
length: f
|
|
1268
1325
|
};
|
|
1269
1326
|
};
|
|
1270
1327
|
}
|
|
@@ -1285,32 +1342,32 @@ function Ir(t) {
|
|
|
1285
1342
|
Date.now() - 1e3 * 60 * 60 * 24 * 30 * 3
|
|
1286
1343
|
).toISOString();
|
|
1287
1344
|
console.log("delete codes"), await t.deleteFrom("codes").where("created_at", "<", e).limit(1e5).execute(), console.log("delete sessions"), await t.deleteFrom("login_sessions").where("created_at", "<", r).where("session_id", "is", null).limit(1e5).execute(), console.log("delete logs"), await t.deleteFrom("logs").where("date", "<", a).limit(1e5).execute(), console.log("delete refresh tokens"), await t.deleteFrom("refresh_tokens").where(
|
|
1288
|
-
(
|
|
1289
|
-
|
|
1290
|
-
|
|
1345
|
+
(o) => o.or([
|
|
1346
|
+
o("expires_at", "<", r),
|
|
1347
|
+
o("idle_expires_at", "<", r)
|
|
1291
1348
|
])
|
|
1292
1349
|
).limit(1e4).execute(), console.log("delete sessions");
|
|
1293
|
-
const
|
|
1294
|
-
(
|
|
1295
|
-
|
|
1296
|
-
|
|
1350
|
+
const n = await t.selectFrom("sessions").select("id").where(
|
|
1351
|
+
(o) => o.or([
|
|
1352
|
+
o("expires_at", "<", r),
|
|
1353
|
+
o("idle_expires_at", "<", r)
|
|
1297
1354
|
])
|
|
1298
1355
|
).where(
|
|
1299
1356
|
"id",
|
|
1300
1357
|
"not in",
|
|
1301
1358
|
t.selectFrom("refresh_tokens").select("session_id")
|
|
1302
1359
|
).limit(1e5).execute();
|
|
1303
|
-
|
|
1360
|
+
n.length > 0 && await t.deleteFrom("sessions").where(
|
|
1304
1361
|
"id",
|
|
1305
1362
|
"in",
|
|
1306
|
-
|
|
1363
|
+
n.map((o) => o.id)
|
|
1307
1364
|
).execute(), console.log("cleanup complete");
|
|
1308
1365
|
};
|
|
1309
1366
|
}
|
|
1310
1367
|
function Dr(t) {
|
|
1311
1368
|
return async (e, r) => {
|
|
1312
|
-
const a =
|
|
1313
|
-
id:
|
|
1369
|
+
const a = G.parse({
|
|
1370
|
+
id: O(),
|
|
1314
1371
|
...r,
|
|
1315
1372
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1316
1373
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
@@ -1322,41 +1379,46 @@ function Dr(t) {
|
|
|
1322
1379
|
start: JSON.stringify(a.start || {}),
|
|
1323
1380
|
ending: JSON.stringify(a.ending || {}),
|
|
1324
1381
|
tenant_id: e
|
|
1325
|
-
}).execute(),
|
|
1382
|
+
}).execute(), G.parse(a);
|
|
1326
1383
|
};
|
|
1327
1384
|
}
|
|
1328
1385
|
function Pr(t) {
|
|
1329
|
-
return async (e, r = {
|
|
1330
|
-
page: 0,
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
const s = (await a.offset(r.page * r.per_page).limit(r.per_page).selectAll().execute()).map((c) => {
|
|
1337
|
-
const _ = { ...c };
|
|
1338
|
-
if (typeof _.nodes == "string")
|
|
1386
|
+
return async (e, r = {}) => {
|
|
1387
|
+
const { page: a = 0, per_page: n = 50, include_totals: o = !1, q: s } = r;
|
|
1388
|
+
let i = t.selectFrom("forms").where("tenant_id", "=", e);
|
|
1389
|
+
s && (i = T(t, i, s, []));
|
|
1390
|
+
const u = (await i.offset(a * n).limit(n).selectAll().execute()).map((h) => {
|
|
1391
|
+
const f = { ...h };
|
|
1392
|
+
if (typeof f.nodes == "string")
|
|
1339
1393
|
try {
|
|
1340
|
-
|
|
1394
|
+
f.nodes = JSON.parse(f.nodes);
|
|
1341
1395
|
} catch {
|
|
1342
1396
|
}
|
|
1343
|
-
if (typeof
|
|
1397
|
+
if (typeof f.start == "string")
|
|
1344
1398
|
try {
|
|
1345
|
-
|
|
1399
|
+
f.start = JSON.parse(f.start);
|
|
1346
1400
|
} catch {
|
|
1347
1401
|
}
|
|
1348
|
-
if (typeof
|
|
1402
|
+
if (typeof f.ending == "string")
|
|
1349
1403
|
try {
|
|
1350
|
-
|
|
1404
|
+
f.ending = JSON.parse(f.ending);
|
|
1351
1405
|
} catch {
|
|
1352
1406
|
}
|
|
1353
|
-
return
|
|
1354
|
-
})
|
|
1407
|
+
return G.parse(y(f));
|
|
1408
|
+
});
|
|
1409
|
+
if (!o)
|
|
1410
|
+
return {
|
|
1411
|
+
forms: u,
|
|
1412
|
+
start: 0,
|
|
1413
|
+
limit: 0,
|
|
1414
|
+
length: 0
|
|
1415
|
+
};
|
|
1416
|
+
const { count: m } = await i.select((h) => h.fn.countAll().as("count")).executeTakeFirstOrThrow();
|
|
1355
1417
|
return {
|
|
1356
|
-
forms:
|
|
1357
|
-
start:
|
|
1358
|
-
limit:
|
|
1359
|
-
length:
|
|
1418
|
+
forms: u,
|
|
1419
|
+
start: a * n,
|
|
1420
|
+
limit: n,
|
|
1421
|
+
length: x(m)
|
|
1360
1422
|
};
|
|
1361
1423
|
};
|
|
1362
1424
|
}
|
|
@@ -1370,34 +1432,34 @@ function Fr(t) {
|
|
|
1370
1432
|
return async (e, r) => {
|
|
1371
1433
|
const a = await t.selectFrom("forms").selectAll().where("forms.id", "=", r).where("tenant_id", "=", e).executeTakeFirst();
|
|
1372
1434
|
if (!a) return null;
|
|
1373
|
-
const
|
|
1374
|
-
if (typeof
|
|
1435
|
+
const n = { ...a };
|
|
1436
|
+
if (typeof n.nodes == "string")
|
|
1375
1437
|
try {
|
|
1376
|
-
|
|
1438
|
+
n.nodes = JSON.parse(n.nodes);
|
|
1377
1439
|
} catch {
|
|
1378
1440
|
}
|
|
1379
|
-
if (typeof
|
|
1441
|
+
if (typeof n.start == "string")
|
|
1380
1442
|
try {
|
|
1381
|
-
|
|
1443
|
+
n.start = JSON.parse(n.start);
|
|
1382
1444
|
} catch {
|
|
1383
1445
|
}
|
|
1384
|
-
if (typeof
|
|
1446
|
+
if (typeof n.ending == "string")
|
|
1385
1447
|
try {
|
|
1386
|
-
|
|
1448
|
+
n.ending = JSON.parse(n.ending);
|
|
1387
1449
|
} catch {
|
|
1388
1450
|
}
|
|
1389
|
-
return
|
|
1451
|
+
return G.parse(y(n));
|
|
1390
1452
|
};
|
|
1391
1453
|
}
|
|
1392
1454
|
function Mr(t) {
|
|
1393
1455
|
return async (e, r, a) => {
|
|
1394
|
-
const
|
|
1456
|
+
const n = {
|
|
1395
1457
|
...a,
|
|
1396
1458
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1397
1459
|
};
|
|
1398
|
-
a.nodes && (
|
|
1399
|
-
const { numUpdatedRows:
|
|
1400
|
-
return
|
|
1460
|
+
a.nodes && (n.nodes = JSON.stringify(a.nodes)), a.start && (n.start = JSON.stringify(a.start)), a.ending && (n.ending = JSON.stringify(a.ending));
|
|
1461
|
+
const { numUpdatedRows: o } = await t.updateTable("forms").set(n).where("id", "=", r).where("tenant_id", "=", e).executeTakeFirst();
|
|
1462
|
+
return o > 0;
|
|
1401
1463
|
};
|
|
1402
1464
|
}
|
|
1403
1465
|
function Ar(t) {
|
|
@@ -1411,22 +1473,22 @@ function Ar(t) {
|
|
|
1411
1473
|
}
|
|
1412
1474
|
function zr(t) {
|
|
1413
1475
|
return async (e, r) => {
|
|
1414
|
-
const a = (/* @__PURE__ */ new Date()).toISOString(),
|
|
1415
|
-
id:
|
|
1476
|
+
const a = (/* @__PURE__ */ new Date()).toISOString(), n = {
|
|
1477
|
+
id: O(),
|
|
1416
1478
|
...r,
|
|
1417
1479
|
created_at: a,
|
|
1418
1480
|
updated_at: a
|
|
1419
|
-
},
|
|
1481
|
+
}, o = qe.parse(n), {
|
|
1420
1482
|
verificationKey: s,
|
|
1421
|
-
scopes:
|
|
1483
|
+
scopes: i,
|
|
1422
1484
|
options: c,
|
|
1423
1485
|
skip_consent_for_verifiable_first_party_clients: _,
|
|
1424
1486
|
allow_offline_access: u,
|
|
1425
|
-
...
|
|
1426
|
-
} =
|
|
1427
|
-
...
|
|
1487
|
+
...m
|
|
1488
|
+
} = o, h = {
|
|
1489
|
+
...m,
|
|
1428
1490
|
tenant_id: e,
|
|
1429
|
-
scopes:
|
|
1491
|
+
scopes: i ? JSON.stringify(i) : "[]",
|
|
1430
1492
|
options: c ? JSON.stringify(c) : "{}",
|
|
1431
1493
|
skip_consent_for_verifiable_first_party_clients: _ ? 1 : 0,
|
|
1432
1494
|
allow_offline_access: u ? 1 : 0,
|
|
@@ -1434,70 +1496,79 @@ function zr(t) {
|
|
|
1434
1496
|
created_at: a,
|
|
1435
1497
|
updated_at: a
|
|
1436
1498
|
};
|
|
1437
|
-
return await t.insertInto("resource_servers").values(
|
|
1499
|
+
return await t.insertInto("resource_servers").values(h).execute(), y(o);
|
|
1438
1500
|
};
|
|
1439
1501
|
}
|
|
1440
1502
|
function Lr(t) {
|
|
1441
1503
|
return async (e, r) => {
|
|
1442
1504
|
const a = await t.selectFrom("resource_servers").selectAll().where("tenant_id", "=", e).where("id", "=", r).executeTakeFirst();
|
|
1443
1505
|
if (!a) return null;
|
|
1444
|
-
const
|
|
1445
|
-
verification_key:
|
|
1506
|
+
const n = a, {
|
|
1507
|
+
verification_key: o,
|
|
1446
1508
|
scopes: s,
|
|
1447
|
-
options:
|
|
1509
|
+
options: i,
|
|
1448
1510
|
skip_consent_for_verifiable_first_party_clients: c,
|
|
1449
1511
|
allow_offline_access: _,
|
|
1450
1512
|
...u
|
|
1451
|
-
} =
|
|
1513
|
+
} = n, m = {
|
|
1452
1514
|
...u,
|
|
1453
1515
|
scopes: s ? JSON.parse(s) : [],
|
|
1454
|
-
options:
|
|
1516
|
+
options: i ? JSON.parse(i) : {},
|
|
1455
1517
|
skip_consent_for_verifiable_first_party_clients: !!c,
|
|
1456
1518
|
allow_offline_access: !!_,
|
|
1457
1519
|
// Convert verification_key back to verificationKey for API
|
|
1458
|
-
verificationKey:
|
|
1520
|
+
verificationKey: o
|
|
1459
1521
|
};
|
|
1460
|
-
return
|
|
1522
|
+
return y(m);
|
|
1461
1523
|
};
|
|
1462
1524
|
}
|
|
1463
1525
|
function Er(t) {
|
|
1464
|
-
return async (e, r = {
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1526
|
+
return async (e, r = {}) => {
|
|
1527
|
+
const { page: a = 0, per_page: n = 50, include_totals: o = !1, q: s } = r;
|
|
1528
|
+
let i = t.selectFrom("resource_servers").where("resource_servers.tenant_id", "=", e);
|
|
1529
|
+
if (s) {
|
|
1530
|
+
const h = s.trim(), f = h.split(/\s+/), g = f.length === 1 ? f[0] : void 0, w = g ? g.match(/^(-)?(name|identifier):(.*)$/) : null, b = w ? w[3] : "", D = /^(>=|>|<=|<)/.test(b || "");
|
|
1531
|
+
if (w && !D) {
|
|
1532
|
+
const M = !!w[1], P = w[2] === "name" ? "resource_servers.name" : "resource_servers.identifier";
|
|
1533
|
+
i = M ? i.where(P, "not like", `%${b}%`) : i.where(P, "like", `%${b}%`);
|
|
1471
1534
|
} else
|
|
1472
|
-
|
|
1535
|
+
i = T(t, i, h, [
|
|
1473
1536
|
"resource_servers.name",
|
|
1474
1537
|
"resource_servers.identifier"
|
|
1475
1538
|
]);
|
|
1476
1539
|
}
|
|
1477
|
-
const
|
|
1478
|
-
const
|
|
1479
|
-
verification_key:
|
|
1480
|
-
scopes:
|
|
1481
|
-
options:
|
|
1482
|
-
skip_consent_for_verifiable_first_party_clients:
|
|
1483
|
-
allow_offline_access:
|
|
1484
|
-
...
|
|
1485
|
-
} =
|
|
1486
|
-
...
|
|
1487
|
-
scopes:
|
|
1488
|
-
options:
|
|
1489
|
-
skip_consent_for_verifiable_first_party_clients: !!
|
|
1490
|
-
allow_offline_access: !!
|
|
1540
|
+
const u = (await i.offset(a * n).limit(n).selectAll().execute()).map((h) => {
|
|
1541
|
+
const f = h, {
|
|
1542
|
+
verification_key: g,
|
|
1543
|
+
scopes: w,
|
|
1544
|
+
options: b,
|
|
1545
|
+
skip_consent_for_verifiable_first_party_clients: D,
|
|
1546
|
+
allow_offline_access: M,
|
|
1547
|
+
...P
|
|
1548
|
+
} = f, V = {
|
|
1549
|
+
...P,
|
|
1550
|
+
scopes: w ? JSON.parse(w) : [],
|
|
1551
|
+
options: b ? JSON.parse(b) : {},
|
|
1552
|
+
skip_consent_for_verifiable_first_party_clients: !!D,
|
|
1553
|
+
allow_offline_access: !!M,
|
|
1491
1554
|
// Convert verification_key back to verificationKey for API
|
|
1492
|
-
verificationKey:
|
|
1555
|
+
verificationKey: g
|
|
1493
1556
|
};
|
|
1494
|
-
return
|
|
1495
|
-
})
|
|
1557
|
+
return y(V);
|
|
1558
|
+
});
|
|
1559
|
+
if (!o)
|
|
1560
|
+
return {
|
|
1561
|
+
resource_servers: u,
|
|
1562
|
+
start: 0,
|
|
1563
|
+
limit: 0,
|
|
1564
|
+
length: 0
|
|
1565
|
+
};
|
|
1566
|
+
const { count: m } = await i.select((h) => h.fn.countAll().as("count")).executeTakeFirstOrThrow();
|
|
1496
1567
|
return {
|
|
1497
|
-
resource_servers:
|
|
1498
|
-
start:
|
|
1499
|
-
limit:
|
|
1500
|
-
length:
|
|
1568
|
+
resource_servers: u,
|
|
1569
|
+
start: a * n,
|
|
1570
|
+
limit: n,
|
|
1571
|
+
length: x(m)
|
|
1501
1572
|
};
|
|
1502
1573
|
};
|
|
1503
1574
|
}
|
|
@@ -1510,19 +1581,19 @@ function Jr(t) {
|
|
|
1510
1581
|
function Rr(t) {
|
|
1511
1582
|
return async (e, r, a) => {
|
|
1512
1583
|
const {
|
|
1513
|
-
verificationKey:
|
|
1514
|
-
scopes:
|
|
1584
|
+
verificationKey: n,
|
|
1585
|
+
scopes: o,
|
|
1515
1586
|
options: s,
|
|
1516
|
-
skip_consent_for_verifiable_first_party_clients:
|
|
1587
|
+
skip_consent_for_verifiable_first_party_clients: i,
|
|
1517
1588
|
allow_offline_access: c,
|
|
1518
1589
|
..._
|
|
1519
1590
|
} = a, u = {
|
|
1520
1591
|
..._,
|
|
1521
1592
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1522
1593
|
};
|
|
1523
|
-
|
|
1524
|
-
const
|
|
1525
|
-
return Number(
|
|
1594
|
+
n !== void 0 && (u.verification_key = n), o !== void 0 && (u.scopes = JSON.stringify(o)), s !== void 0 && (u.options = JSON.stringify(s)), i !== void 0 && (u.skip_consent_for_verifiable_first_party_clients = i ? 1 : 0), c !== void 0 && (u.allow_offline_access = c ? 1 : 0);
|
|
1595
|
+
const m = await t.updateTable("resource_servers").set(u).where("tenant_id", "=", e).where("id", "=", r).executeTakeFirst();
|
|
1596
|
+
return Number(m.numUpdatedRows) > 0;
|
|
1526
1597
|
};
|
|
1527
1598
|
}
|
|
1528
1599
|
function Kr(t) {
|
|
@@ -1536,15 +1607,15 @@ function Kr(t) {
|
|
|
1536
1607
|
}
|
|
1537
1608
|
function Ur(t) {
|
|
1538
1609
|
return async (e, r) => {
|
|
1539
|
-
const a = (/* @__PURE__ */ new Date()).toISOString(),
|
|
1540
|
-
id:
|
|
1610
|
+
const a = (/* @__PURE__ */ new Date()).toISOString(), n = O(), o = {
|
|
1611
|
+
id: n,
|
|
1541
1612
|
...r,
|
|
1542
1613
|
tenant_id: e,
|
|
1543
1614
|
created_at: a,
|
|
1544
1615
|
updated_at: a
|
|
1545
1616
|
};
|
|
1546
|
-
return await t.insertInto("roles").values(
|
|
1547
|
-
id:
|
|
1617
|
+
return await t.insertInto("roles").values(o).execute(), {
|
|
1618
|
+
id: n,
|
|
1548
1619
|
...r,
|
|
1549
1620
|
created_at: a,
|
|
1550
1621
|
updated_at: a
|
|
@@ -1560,25 +1631,34 @@ function Br(t) {
|
|
|
1560
1631
|
};
|
|
1561
1632
|
}
|
|
1562
1633
|
function Qr(t) {
|
|
1563
|
-
return async (e, r
|
|
1634
|
+
return async (e, r) => {
|
|
1564
1635
|
let a = t.selectFrom("roles").where("roles.tenant_id", "=", e);
|
|
1565
|
-
|
|
1566
|
-
|
|
1636
|
+
const { page: n = 0, per_page: o = 50, include_totals: s = !1 } = r;
|
|
1637
|
+
r.q && (a = T(t, a, r.q, ["name"]));
|
|
1638
|
+
const c = await a.offset(n * o).limit(o).selectAll().execute();
|
|
1639
|
+
if (!s)
|
|
1640
|
+
return {
|
|
1641
|
+
roles: c,
|
|
1642
|
+
start: n * o,
|
|
1643
|
+
limit: o,
|
|
1644
|
+
length: c.length
|
|
1645
|
+
};
|
|
1646
|
+
const { count: _ } = await a.select((u) => u.fn.countAll().as("count")).executeTakeFirstOrThrow();
|
|
1567
1647
|
return {
|
|
1568
|
-
roles:
|
|
1569
|
-
start:
|
|
1570
|
-
limit:
|
|
1571
|
-
length:
|
|
1648
|
+
roles: c,
|
|
1649
|
+
start: n * o,
|
|
1650
|
+
limit: o,
|
|
1651
|
+
length: x(_)
|
|
1572
1652
|
};
|
|
1573
1653
|
};
|
|
1574
1654
|
}
|
|
1575
1655
|
function qr(t) {
|
|
1576
1656
|
return async (e, r, a) => {
|
|
1577
|
-
const
|
|
1657
|
+
const n = {
|
|
1578
1658
|
...a,
|
|
1579
1659
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1580
|
-
},
|
|
1581
|
-
return Number(
|
|
1660
|
+
}, o = await t.updateTable("roles").set(n).where("roles.tenant_id", "=", e).where("roles.id", "=", r).executeTakeFirst();
|
|
1661
|
+
return Number(o.numUpdatedRows) > 0;
|
|
1582
1662
|
};
|
|
1583
1663
|
}
|
|
1584
1664
|
function Vr(t) {
|
|
@@ -1599,31 +1679,31 @@ function Wr(t) {
|
|
|
1599
1679
|
function Gr(t) {
|
|
1600
1680
|
return async (e, r, a) => {
|
|
1601
1681
|
if (a.length === 0) return !0;
|
|
1602
|
-
const
|
|
1682
|
+
const n = (/* @__PURE__ */ new Date()).toISOString();
|
|
1603
1683
|
try {
|
|
1604
|
-
for (const
|
|
1605
|
-
if (
|
|
1684
|
+
for (const o of a) {
|
|
1685
|
+
if (o.role_id !== r)
|
|
1606
1686
|
throw new Error(
|
|
1607
|
-
`Permission role_id ${
|
|
1687
|
+
`Permission role_id ${o.role_id} does not match expected role_id ${r}`
|
|
1608
1688
|
);
|
|
1609
1689
|
const s = {
|
|
1610
1690
|
tenant_id: e,
|
|
1611
|
-
role_id:
|
|
1612
|
-
resource_server_identifier:
|
|
1613
|
-
permission_name:
|
|
1614
|
-
created_at:
|
|
1691
|
+
role_id: o.role_id,
|
|
1692
|
+
resource_server_identifier: o.resource_server_identifier,
|
|
1693
|
+
permission_name: o.permission_name,
|
|
1694
|
+
created_at: n
|
|
1615
1695
|
};
|
|
1616
1696
|
try {
|
|
1617
1697
|
await t.insertInto("role_permissions").values(s).execute();
|
|
1618
|
-
} catch (
|
|
1619
|
-
if (
|
|
1698
|
+
} catch (i) {
|
|
1699
|
+
if (i.code === "SQLITE_CONSTRAINT_PRIMARYKEY" || i.code === "SQLITE_CONSTRAINT_UNIQUE")
|
|
1620
1700
|
continue;
|
|
1621
|
-
throw
|
|
1701
|
+
throw i;
|
|
1622
1702
|
}
|
|
1623
1703
|
}
|
|
1624
1704
|
return !0;
|
|
1625
|
-
} catch (
|
|
1626
|
-
return console.error("Error assigning role permissions:",
|
|
1705
|
+
} catch (o) {
|
|
1706
|
+
return console.error("Error assigning role permissions:", o), !1;
|
|
1627
1707
|
}
|
|
1628
1708
|
};
|
|
1629
1709
|
}
|
|
@@ -1633,46 +1713,51 @@ function Hr(t) {
|
|
|
1633
1713
|
try {
|
|
1634
1714
|
return (await Promise.all(
|
|
1635
1715
|
a.map(
|
|
1636
|
-
(
|
|
1716
|
+
(o) => t.deleteFrom("role_permissions").where("tenant_id", "=", e).where("role_id", "=", r).where(
|
|
1637
1717
|
"resource_server_identifier",
|
|
1638
1718
|
"=",
|
|
1639
|
-
|
|
1640
|
-
).where("permission_name", "=",
|
|
1719
|
+
o.resource_server_identifier
|
|
1720
|
+
).where("permission_name", "=", o.permission_name).executeTakeFirst()
|
|
1641
1721
|
)
|
|
1642
|
-
)).some((
|
|
1643
|
-
} catch (
|
|
1644
|
-
return console.error("Error removing role permissions:",
|
|
1722
|
+
)).some((o) => Number(o.numDeletedRows) > 0);
|
|
1723
|
+
} catch (n) {
|
|
1724
|
+
return console.error("Error removing role permissions:", n), !1;
|
|
1645
1725
|
}
|
|
1646
1726
|
};
|
|
1647
1727
|
}
|
|
1648
1728
|
function Yr(t) {
|
|
1649
|
-
return async (e, r, a = {
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
"
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1729
|
+
return async (e, r, a = {}) => {
|
|
1730
|
+
const { page: n = 0, per_page: o = 50, include_totals: s = !1 } = a;
|
|
1731
|
+
let i = t.selectFrom("role_permissions").leftJoin(
|
|
1732
|
+
"resource_servers",
|
|
1733
|
+
(m) => m.onRef(
|
|
1734
|
+
"role_permissions.tenant_id",
|
|
1735
|
+
"=",
|
|
1736
|
+
"resource_servers.tenant_id"
|
|
1737
|
+
).onRef(
|
|
1738
|
+
"role_permissions.resource_server_identifier",
|
|
1739
|
+
"=",
|
|
1740
|
+
"resource_servers.id"
|
|
1741
|
+
)
|
|
1742
|
+
).select([
|
|
1743
|
+
"role_permissions.role_id",
|
|
1656
1744
|
"role_permissions.resource_server_identifier",
|
|
1657
|
-
"
|
|
1658
|
-
"
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
// No description available from role_permissions directly
|
|
1674
|
-
created_at: s.created_at
|
|
1675
|
-
}));
|
|
1745
|
+
"role_permissions.permission_name",
|
|
1746
|
+
"role_permissions.created_at",
|
|
1747
|
+
"resource_servers.name as resource_server_name"
|
|
1748
|
+
]).where("role_permissions.tenant_id", "=", e).where("role_permissions.role_id", "=", r);
|
|
1749
|
+
const u = (await i.offset(n * o).limit(o).execute()).map((m) => ({
|
|
1750
|
+
role_id: m.role_id,
|
|
1751
|
+
resource_server_identifier: m.resource_server_identifier,
|
|
1752
|
+
resource_server_name: m.resource_server_name || m.resource_server_identifier,
|
|
1753
|
+
// Fallback to identifier if name is null
|
|
1754
|
+
permission_name: m.permission_name,
|
|
1755
|
+
description: null,
|
|
1756
|
+
// No description available from role_permissions directly
|
|
1757
|
+
created_at: m.created_at
|
|
1758
|
+
}));
|
|
1759
|
+
return s && await i.select((m) => m.fn.countAll().as("count")).executeTakeFirstOrThrow(), u;
|
|
1760
|
+
};
|
|
1676
1761
|
}
|
|
1677
1762
|
function Xr(t) {
|
|
1678
1763
|
return {
|
|
@@ -1684,27 +1769,27 @@ function Xr(t) {
|
|
|
1684
1769
|
function Zr(t) {
|
|
1685
1770
|
return async (e, r, a) => {
|
|
1686
1771
|
if (a.length === 0) return !0;
|
|
1687
|
-
const
|
|
1772
|
+
const n = (/* @__PURE__ */ new Date()).toISOString();
|
|
1688
1773
|
try {
|
|
1689
|
-
for (const
|
|
1774
|
+
for (const o of a) {
|
|
1690
1775
|
const s = {
|
|
1691
1776
|
tenant_id: e,
|
|
1692
1777
|
user_id: r,
|
|
1693
|
-
resource_server_identifier:
|
|
1694
|
-
permission_name:
|
|
1695
|
-
created_at:
|
|
1778
|
+
resource_server_identifier: o.resource_server_identifier,
|
|
1779
|
+
permission_name: o.permission_name,
|
|
1780
|
+
created_at: n
|
|
1696
1781
|
};
|
|
1697
1782
|
try {
|
|
1698
1783
|
await t.insertInto("user_permissions").values(s).execute();
|
|
1699
|
-
} catch (
|
|
1700
|
-
if (
|
|
1784
|
+
} catch (i) {
|
|
1785
|
+
if (i.code === "SQLITE_CONSTRAINT_PRIMARYKEY" || i.code === "SQLITE_CONSTRAINT_UNIQUE")
|
|
1701
1786
|
continue;
|
|
1702
|
-
throw
|
|
1787
|
+
throw i;
|
|
1703
1788
|
}
|
|
1704
1789
|
}
|
|
1705
1790
|
return !0;
|
|
1706
|
-
} catch (
|
|
1707
|
-
return console.error("Error assigning user permissions:",
|
|
1791
|
+
} catch (o) {
|
|
1792
|
+
return console.error("Error assigning user permissions:", o), !1;
|
|
1708
1793
|
}
|
|
1709
1794
|
};
|
|
1710
1795
|
}
|
|
@@ -1712,22 +1797,22 @@ function ea(t) {
|
|
|
1712
1797
|
return async (e, r, a) => {
|
|
1713
1798
|
if (a.length === 0) return !0;
|
|
1714
1799
|
try {
|
|
1715
|
-
for (const
|
|
1800
|
+
for (const n of a)
|
|
1716
1801
|
await t.deleteFrom("user_permissions").where("tenant_id", "=", e).where("user_id", "=", r).where(
|
|
1717
1802
|
"resource_server_identifier",
|
|
1718
1803
|
"=",
|
|
1719
|
-
|
|
1720
|
-
).where("permission_name", "=",
|
|
1804
|
+
n.resource_server_identifier
|
|
1805
|
+
).where("permission_name", "=", n.permission_name).execute();
|
|
1721
1806
|
return !0;
|
|
1722
|
-
} catch (
|
|
1723
|
-
return console.error("Error removing user permissions:",
|
|
1807
|
+
} catch (n) {
|
|
1808
|
+
return console.error("Error removing user permissions:", n), !1;
|
|
1724
1809
|
}
|
|
1725
1810
|
};
|
|
1726
1811
|
}
|
|
1727
1812
|
function ta(t) {
|
|
1728
1813
|
return async (e, r, a) => (await t.selectFrom("user_permissions").leftJoin(
|
|
1729
1814
|
"resource_servers",
|
|
1730
|
-
(
|
|
1815
|
+
(o) => o.onRef(
|
|
1731
1816
|
"user_permissions.tenant_id",
|
|
1732
1817
|
"=",
|
|
1733
1818
|
"resource_servers.tenant_id"
|
|
@@ -1742,15 +1827,15 @@ function ta(t) {
|
|
|
1742
1827
|
"resource_servers.name as resource_server_name",
|
|
1743
1828
|
"user_permissions.user_id",
|
|
1744
1829
|
"user_permissions.created_at"
|
|
1745
|
-
]).where("user_permissions.tenant_id", "=", e).where("user_permissions.user_id", "=", r).execute()).map((
|
|
1746
|
-
resource_server_identifier:
|
|
1747
|
-
permission_name:
|
|
1830
|
+
]).where("user_permissions.tenant_id", "=", e).where("user_permissions.user_id", "=", r).execute()).map((o) => ({
|
|
1831
|
+
resource_server_identifier: o.resource_server_identifier,
|
|
1832
|
+
permission_name: o.permission_name,
|
|
1748
1833
|
description: null,
|
|
1749
1834
|
// No description available from user_permissions directly
|
|
1750
|
-
resource_server_name:
|
|
1835
|
+
resource_server_name: o.resource_server_name || o.resource_server_identifier,
|
|
1751
1836
|
// Fallback to identifier if name is null
|
|
1752
|
-
user_id:
|
|
1753
|
-
created_at:
|
|
1837
|
+
user_id: o.user_id,
|
|
1838
|
+
created_at: o.created_at
|
|
1754
1839
|
}));
|
|
1755
1840
|
}
|
|
1756
1841
|
function ra(t) {
|
|
@@ -1763,7 +1848,7 @@ function ra(t) {
|
|
|
1763
1848
|
function aa(t) {
|
|
1764
1849
|
return async (e, r) => await t.selectFrom("user_roles as ur").innerJoin(
|
|
1765
1850
|
"roles as r",
|
|
1766
|
-
(
|
|
1851
|
+
(n) => n.onRef("ur.role_id", "=", "r.id").onRef("ur.tenant_id", "=", "r.tenant_id")
|
|
1767
1852
|
).select([
|
|
1768
1853
|
"r.id",
|
|
1769
1854
|
"r.name",
|
|
@@ -1775,28 +1860,28 @@ function aa(t) {
|
|
|
1775
1860
|
function na(t) {
|
|
1776
1861
|
return async (e, r, a) => {
|
|
1777
1862
|
if (a.length === 0) return !0;
|
|
1778
|
-
const
|
|
1863
|
+
const n = (/* @__PURE__ */ new Date()).toISOString();
|
|
1779
1864
|
try {
|
|
1780
|
-
for (const
|
|
1865
|
+
for (const o of a)
|
|
1781
1866
|
try {
|
|
1782
|
-
await t.insertInto("user_roles").values({ tenant_id: e, user_id: r, role_id:
|
|
1867
|
+
await t.insertInto("user_roles").values({ tenant_id: e, user_id: r, role_id: o, created_at: n }).execute();
|
|
1783
1868
|
} catch (s) {
|
|
1784
1869
|
if (s.code === "SQLITE_CONSTRAINT_PRIMARYKEY" || s.code === "SQLITE_CONSTRAINT_UNIQUE")
|
|
1785
1870
|
continue;
|
|
1786
1871
|
throw s;
|
|
1787
1872
|
}
|
|
1788
1873
|
return !0;
|
|
1789
|
-
} catch (
|
|
1790
|
-
return console.error("Error assigning user roles:",
|
|
1874
|
+
} catch (o) {
|
|
1875
|
+
return console.error("Error assigning user roles:", o), !1;
|
|
1791
1876
|
}
|
|
1792
1877
|
};
|
|
1793
1878
|
}
|
|
1794
1879
|
function oa(t) {
|
|
1795
1880
|
return async (e, r, a) => {
|
|
1796
1881
|
try {
|
|
1797
|
-
return a.length && await t.deleteFrom("user_roles").where("tenant_id", "=", e).where("user_id", "=", r).where((
|
|
1798
|
-
} catch (
|
|
1799
|
-
return console.error("Error removing user roles:",
|
|
1882
|
+
return a.length && await t.deleteFrom("user_roles").where("tenant_id", "=", e).where("user_id", "=", r).where((n) => n("role_id", "in", a)).execute(), !0;
|
|
1883
|
+
} catch (n) {
|
|
1884
|
+
return console.error("Error removing user roles:", n), !1;
|
|
1800
1885
|
}
|
|
1801
1886
|
};
|
|
1802
1887
|
}
|
|
@@ -1810,69 +1895,69 @@ function sa(t) {
|
|
|
1810
1895
|
function ia(t) {
|
|
1811
1896
|
return t[t.length - 1];
|
|
1812
1897
|
}
|
|
1813
|
-
function
|
|
1898
|
+
function C(t) {
|
|
1814
1899
|
return Object.freeze(t);
|
|
1815
1900
|
}
|
|
1816
|
-
const
|
|
1901
|
+
const W = C({
|
|
1817
1902
|
is(t) {
|
|
1818
1903
|
return t.kind === "IdentifierNode";
|
|
1819
1904
|
},
|
|
1820
1905
|
create(t) {
|
|
1821
|
-
return
|
|
1906
|
+
return C({
|
|
1822
1907
|
kind: "IdentifierNode",
|
|
1823
1908
|
name: t
|
|
1824
1909
|
});
|
|
1825
1910
|
}
|
|
1826
|
-
}),
|
|
1911
|
+
}), re = C({
|
|
1827
1912
|
is(t) {
|
|
1828
1913
|
return t.kind === "SchemableIdentifierNode";
|
|
1829
1914
|
},
|
|
1830
1915
|
create(t) {
|
|
1831
|
-
return
|
|
1916
|
+
return C({
|
|
1832
1917
|
kind: "SchemableIdentifierNode",
|
|
1833
|
-
identifier:
|
|
1918
|
+
identifier: W.create(t)
|
|
1834
1919
|
});
|
|
1835
1920
|
},
|
|
1836
1921
|
createWithSchema(t, e) {
|
|
1837
|
-
return
|
|
1922
|
+
return C({
|
|
1838
1923
|
kind: "SchemableIdentifierNode",
|
|
1839
|
-
schema:
|
|
1840
|
-
identifier:
|
|
1924
|
+
schema: W.create(t),
|
|
1925
|
+
identifier: W.create(e)
|
|
1841
1926
|
});
|
|
1842
1927
|
}
|
|
1843
|
-
}), la =
|
|
1928
|
+
}), la = C({
|
|
1844
1929
|
is(t) {
|
|
1845
1930
|
return t.kind === "AliasNode";
|
|
1846
1931
|
},
|
|
1847
1932
|
create(t, e) {
|
|
1848
|
-
return
|
|
1933
|
+
return C({
|
|
1849
1934
|
kind: "AliasNode",
|
|
1850
1935
|
node: t,
|
|
1851
1936
|
alias: e
|
|
1852
1937
|
});
|
|
1853
1938
|
}
|
|
1854
|
-
}),
|
|
1939
|
+
}), X = C({
|
|
1855
1940
|
is(t) {
|
|
1856
1941
|
return t.kind === "TableNode";
|
|
1857
1942
|
},
|
|
1858
1943
|
create(t) {
|
|
1859
|
-
return
|
|
1944
|
+
return C({
|
|
1860
1945
|
kind: "TableNode",
|
|
1861
|
-
table:
|
|
1946
|
+
table: re.create(t)
|
|
1862
1947
|
});
|
|
1863
1948
|
},
|
|
1864
1949
|
createWithSchema(t, e) {
|
|
1865
|
-
return
|
|
1950
|
+
return C({
|
|
1866
1951
|
kind: "TableNode",
|
|
1867
|
-
table:
|
|
1952
|
+
table: re.createWithSchema(t, e)
|
|
1868
1953
|
});
|
|
1869
1954
|
}
|
|
1870
1955
|
});
|
|
1871
|
-
var
|
|
1956
|
+
var H;
|
|
1872
1957
|
class ca {
|
|
1873
1958
|
constructor() {
|
|
1874
|
-
|
|
1875
|
-
|
|
1959
|
+
R(this, "nodeStack", []);
|
|
1960
|
+
S(this, H, C({
|
|
1876
1961
|
AliasNode: this.transformAlias.bind(this),
|
|
1877
1962
|
ColumnNode: this.transformColumn.bind(this),
|
|
1878
1963
|
IdentifierNode: this.transformIdentifier.bind(this),
|
|
@@ -1973,13 +2058,13 @@ class ca {
|
|
|
1973
2058
|
return e;
|
|
1974
2059
|
this.nodeStack.push(e);
|
|
1975
2060
|
const r = this.transformNodeImpl(e);
|
|
1976
|
-
return this.nodeStack.pop(),
|
|
2061
|
+
return this.nodeStack.pop(), C(r);
|
|
1977
2062
|
}
|
|
1978
2063
|
transformNodeImpl(e) {
|
|
1979
|
-
return d(this,
|
|
2064
|
+
return d(this, H)[e.kind](e);
|
|
1980
2065
|
}
|
|
1981
2066
|
transformNodeList(e) {
|
|
1982
|
-
return e &&
|
|
2067
|
+
return e && C(e.map((r) => this.transformNode(r)));
|
|
1983
2068
|
}
|
|
1984
2069
|
transformSelectQuery(e) {
|
|
1985
2070
|
return {
|
|
@@ -2078,7 +2163,7 @@ class ca {
|
|
|
2078
2163
|
transformRaw(e) {
|
|
2079
2164
|
return {
|
|
2080
2165
|
kind: "RawNode",
|
|
2081
|
-
sqlFragments:
|
|
2166
|
+
sqlFragments: C([...e.sqlFragments]),
|
|
2082
2167
|
parameters: this.transformNodeList(e.parameters)
|
|
2083
2168
|
};
|
|
2084
2169
|
}
|
|
@@ -2702,8 +2787,8 @@ class ca {
|
|
|
2702
2787
|
return e;
|
|
2703
2788
|
}
|
|
2704
2789
|
}
|
|
2705
|
-
|
|
2706
|
-
const da =
|
|
2790
|
+
H = new WeakMap();
|
|
2791
|
+
const da = C({
|
|
2707
2792
|
AlterTableNode: !0,
|
|
2708
2793
|
CreateIndexNode: !0,
|
|
2709
2794
|
CreateSchemaNode: !0,
|
|
@@ -2722,87 +2807,87 @@ const da = y({
|
|
|
2722
2807
|
UpdateQueryNode: !0,
|
|
2723
2808
|
MergeQueryNode: !0
|
|
2724
2809
|
});
|
|
2725
|
-
var
|
|
2810
|
+
var E, j, F, N, ye, ve, Ne, A, ae, Ce;
|
|
2726
2811
|
class ua extends ca {
|
|
2727
2812
|
constructor(r) {
|
|
2728
2813
|
super();
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2814
|
+
S(this, N);
|
|
2815
|
+
S(this, E);
|
|
2816
|
+
S(this, j, /* @__PURE__ */ new Set());
|
|
2817
|
+
S(this, F, /* @__PURE__ */ new Set());
|
|
2818
|
+
K(this, E, r);
|
|
2734
2819
|
}
|
|
2735
2820
|
transformNodeImpl(r) {
|
|
2736
|
-
if (!
|
|
2821
|
+
if (!p(this, N, ye).call(this, r))
|
|
2737
2822
|
return super.transformNodeImpl(r);
|
|
2738
|
-
const a =
|
|
2823
|
+
const a = p(this, N, Ne).call(this, r);
|
|
2739
2824
|
for (const s of a)
|
|
2740
|
-
d(this,
|
|
2741
|
-
const
|
|
2742
|
-
for (const s of
|
|
2743
|
-
d(this,
|
|
2744
|
-
const
|
|
2745
|
-
for (const s of
|
|
2746
|
-
d(this,
|
|
2825
|
+
d(this, F).add(s);
|
|
2826
|
+
const n = p(this, N, ve).call(this, r);
|
|
2827
|
+
for (const s of n)
|
|
2828
|
+
d(this, j).add(s);
|
|
2829
|
+
const o = super.transformNodeImpl(r);
|
|
2830
|
+
for (const s of n)
|
|
2831
|
+
d(this, j).delete(s);
|
|
2747
2832
|
for (const s of a)
|
|
2748
|
-
d(this,
|
|
2749
|
-
return
|
|
2833
|
+
d(this, F).delete(s);
|
|
2834
|
+
return o;
|
|
2750
2835
|
}
|
|
2751
2836
|
transformSchemableIdentifier(r) {
|
|
2752
2837
|
const a = super.transformSchemableIdentifier(r);
|
|
2753
|
-
return a.schema || !d(this,
|
|
2838
|
+
return a.schema || !d(this, j).has(r.identifier.name) ? a : {
|
|
2754
2839
|
...a,
|
|
2755
|
-
schema:
|
|
2840
|
+
schema: W.create(d(this, E))
|
|
2756
2841
|
};
|
|
2757
2842
|
}
|
|
2758
2843
|
transformReferences(r) {
|
|
2759
2844
|
const a = super.transformReferences(r);
|
|
2760
2845
|
return a.table.table.schema ? a : {
|
|
2761
2846
|
...a,
|
|
2762
|
-
table:
|
|
2847
|
+
table: X.createWithSchema(d(this, E), a.table.table.identifier.name)
|
|
2763
2848
|
};
|
|
2764
2849
|
}
|
|
2765
2850
|
}
|
|
2766
|
-
|
|
2851
|
+
E = new WeakMap(), j = new WeakMap(), F = new WeakMap(), N = new WeakSet(), ye = function(r) {
|
|
2767
2852
|
return r.kind in da;
|
|
2768
2853
|
}, ve = function(r) {
|
|
2769
2854
|
const a = /* @__PURE__ */ new Set();
|
|
2770
|
-
if ("name" in r && r.name &&
|
|
2771
|
-
for (const
|
|
2772
|
-
|
|
2773
|
-
if ("into" in r && r.into &&
|
|
2774
|
-
for (const
|
|
2775
|
-
|
|
2776
|
-
return "using" in r && r.using &&
|
|
2855
|
+
if ("name" in r && r.name && re.is(r.name) && p(this, N, ae).call(this, r.name, a), "from" in r && r.from)
|
|
2856
|
+
for (const n of r.from.froms)
|
|
2857
|
+
p(this, N, A).call(this, n, a);
|
|
2858
|
+
if ("into" in r && r.into && p(this, N, A).call(this, r.into, a), "table" in r && r.table && p(this, N, A).call(this, r.table, a), "joins" in r && r.joins)
|
|
2859
|
+
for (const n of r.joins)
|
|
2860
|
+
p(this, N, A).call(this, n.table, a);
|
|
2861
|
+
return "using" in r && r.using && p(this, N, A).call(this, r.using, a), a;
|
|
2777
2862
|
}, Ne = function(r) {
|
|
2778
2863
|
const a = /* @__PURE__ */ new Set();
|
|
2779
|
-
return "with" in r && r.with &&
|
|
2780
|
-
},
|
|
2781
|
-
const
|
|
2782
|
-
|
|
2783
|
-
},
|
|
2784
|
-
const
|
|
2785
|
-
!d(this,
|
|
2864
|
+
return "with" in r && r.with && p(this, N, Ce).call(this, r.with, a), a;
|
|
2865
|
+
}, A = function(r, a) {
|
|
2866
|
+
const n = X.is(r) ? r : la.is(r) && X.is(r.node) ? r.node : null;
|
|
2867
|
+
n && p(this, N, ae).call(this, n.table, a);
|
|
2868
|
+
}, ae = function(r, a) {
|
|
2869
|
+
const n = r.identifier.name;
|
|
2870
|
+
!d(this, j).has(n) && !d(this, F).has(n) && a.add(n);
|
|
2786
2871
|
}, Ce = function(r, a) {
|
|
2787
|
-
for (const
|
|
2788
|
-
const
|
|
2789
|
-
d(this,
|
|
2872
|
+
for (const n of r.expressions) {
|
|
2873
|
+
const o = n.name.table.table.identifier.name;
|
|
2874
|
+
d(this, F).has(o) || a.add(o);
|
|
2790
2875
|
}
|
|
2791
2876
|
};
|
|
2792
|
-
var
|
|
2877
|
+
var Q;
|
|
2793
2878
|
class ma {
|
|
2794
2879
|
constructor(e) {
|
|
2795
|
-
|
|
2796
|
-
|
|
2880
|
+
S(this, Q);
|
|
2881
|
+
K(this, Q, new ua(e));
|
|
2797
2882
|
}
|
|
2798
2883
|
transformQuery(e) {
|
|
2799
|
-
return d(this,
|
|
2884
|
+
return d(this, Q).transformNode(e.node);
|
|
2800
2885
|
}
|
|
2801
2886
|
async transformResult(e) {
|
|
2802
2887
|
return e.result;
|
|
2803
2888
|
}
|
|
2804
2889
|
}
|
|
2805
|
-
|
|
2890
|
+
Q = new WeakMap();
|
|
2806
2891
|
class _a {
|
|
2807
2892
|
transformQuery(e) {
|
|
2808
2893
|
return e.node;
|
|
@@ -2811,13 +2896,13 @@ class _a {
|
|
|
2811
2896
|
return e.result;
|
|
2812
2897
|
}
|
|
2813
2898
|
}
|
|
2814
|
-
const ha = "kysely_migration", fe = "kysely_migration_lock", fa = !1,
|
|
2815
|
-
var
|
|
2899
|
+
const ha = "kysely_migration", fe = "kysely_migration_lock", fa = !1, Z = "migration_lock", pa = C({ __noMigrations__: !0 });
|
|
2900
|
+
var v, l, U, k, $, z, xe, I, Te, Se, Oe, ke, $e, ne, L, oe, Ie, De, Pe, se, je, Fe, Me, Ae, ze, B;
|
|
2816
2901
|
class be {
|
|
2817
2902
|
constructor(e) {
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2903
|
+
S(this, l);
|
|
2904
|
+
S(this, v);
|
|
2905
|
+
K(this, v, C(e));
|
|
2821
2906
|
}
|
|
2822
2907
|
/**
|
|
2823
2908
|
* Returns a {@link MigrationInfo} object for each migration.
|
|
@@ -2825,13 +2910,13 @@ class be {
|
|
|
2825
2910
|
* The returned array is sorted by migration name.
|
|
2826
2911
|
*/
|
|
2827
2912
|
async getMigrations() {
|
|
2828
|
-
const e = await
|
|
2829
|
-
return (await
|
|
2830
|
-
const
|
|
2913
|
+
const e = await p(this, l, L).call(this, d(this, l, $)) ? await d(this, v).db.withPlugin(d(this, l, I)).selectFrom(d(this, l, $)).select(["name", "timestamp"]).execute() : [];
|
|
2914
|
+
return (await p(this, l, se).call(this)).map(({ name: a, ...n }) => {
|
|
2915
|
+
const o = e.find((s) => s.name === a);
|
|
2831
2916
|
return {
|
|
2832
2917
|
name: a,
|
|
2833
|
-
migration:
|
|
2834
|
-
executedAt:
|
|
2918
|
+
migration: n,
|
|
2919
|
+
executedAt: o ? new Date(o.timestamp) : void 0
|
|
2835
2920
|
};
|
|
2836
2921
|
});
|
|
2837
2922
|
}
|
|
@@ -2883,7 +2968,7 @@ class be {
|
|
|
2883
2968
|
* ```
|
|
2884
2969
|
*/
|
|
2885
2970
|
async migrateToLatest() {
|
|
2886
|
-
return
|
|
2971
|
+
return p(this, l, U).call(this, () => ({ direction: "Up", step: 1 / 0 }));
|
|
2887
2972
|
}
|
|
2888
2973
|
/**
|
|
2889
2974
|
* Migrate up/down to a specific migration.
|
|
@@ -2909,16 +2994,16 @@ class be {
|
|
|
2909
2994
|
* ```
|
|
2910
2995
|
*/
|
|
2911
2996
|
async migrateTo(e) {
|
|
2912
|
-
return
|
|
2997
|
+
return p(this, l, U).call(this, ({ migrations: r, executedMigrations: a, pendingMigrations: n }) => {
|
|
2913
2998
|
if (e === pa)
|
|
2914
2999
|
return { direction: "Down", step: 1 / 0 };
|
|
2915
|
-
if (!r.find((
|
|
3000
|
+
if (!r.find((i) => i.name === e))
|
|
2916
3001
|
throw new Error(`migration "${e}" doesn't exist`);
|
|
2917
|
-
const
|
|
2918
|
-
if (
|
|
3002
|
+
const o = a.indexOf(e), s = n.findIndex((i) => i.name === e);
|
|
3003
|
+
if (o !== -1)
|
|
2919
3004
|
return {
|
|
2920
3005
|
direction: "Down",
|
|
2921
|
-
step: a.length -
|
|
3006
|
+
step: a.length - o - 1
|
|
2922
3007
|
};
|
|
2923
3008
|
if (s !== -1)
|
|
2924
3009
|
return { direction: "Up", step: s + 1 };
|
|
@@ -2940,7 +3025,7 @@ class be {
|
|
|
2940
3025
|
* ```
|
|
2941
3026
|
*/
|
|
2942
3027
|
async migrateUp() {
|
|
2943
|
-
return
|
|
3028
|
+
return p(this, l, U).call(this, () => ({ direction: "Up", step: 1 }));
|
|
2944
3029
|
}
|
|
2945
3030
|
/**
|
|
2946
3031
|
* Migrate one step down.
|
|
@@ -2957,187 +3042,187 @@ class be {
|
|
|
2957
3042
|
* ```
|
|
2958
3043
|
*/
|
|
2959
3044
|
async migrateDown() {
|
|
2960
|
-
return
|
|
3045
|
+
return p(this, l, U).call(this, () => ({ direction: "Down", step: 1 }));
|
|
2961
3046
|
}
|
|
2962
3047
|
}
|
|
2963
|
-
|
|
3048
|
+
v = new WeakMap(), l = new WeakSet(), U = async function(e) {
|
|
2964
3049
|
try {
|
|
2965
|
-
return await
|
|
3050
|
+
return await p(this, l, Te).call(this), await p(this, l, Ie).call(this, e);
|
|
2966
3051
|
} catch (r) {
|
|
2967
|
-
return r instanceof
|
|
2968
|
-
}
|
|
2969
|
-
},
|
|
2970
|
-
return d(this,
|
|
2971
|
-
},
|
|
2972
|
-
return d(this,
|
|
2973
|
-
},
|
|
2974
|
-
return d(this,
|
|
3052
|
+
return r instanceof ee ? r.resultSet : { error: r };
|
|
3053
|
+
}
|
|
3054
|
+
}, k = function() {
|
|
3055
|
+
return d(this, v).migrationTableSchema;
|
|
3056
|
+
}, $ = function() {
|
|
3057
|
+
return d(this, v).migrationTableName ?? ha;
|
|
3058
|
+
}, z = function() {
|
|
3059
|
+
return d(this, v).migrationLockTableName ?? fe;
|
|
2975
3060
|
}, xe = function() {
|
|
2976
|
-
return d(this,
|
|
2977
|
-
},
|
|
2978
|
-
return d(this,
|
|
3061
|
+
return d(this, v).allowUnorderedMigrations ?? fa;
|
|
3062
|
+
}, I = function() {
|
|
3063
|
+
return d(this, l, k) ? new ma(d(this, l, k)) : new _a();
|
|
2979
3064
|
}, Te = async function() {
|
|
2980
|
-
await
|
|
3065
|
+
await p(this, l, Se).call(this), await p(this, l, Oe).call(this), await p(this, l, ke).call(this), await p(this, l, $e).call(this);
|
|
2981
3066
|
}, Se = async function() {
|
|
2982
|
-
if (d(this,
|
|
3067
|
+
if (d(this, l, k) && !await p(this, l, ne).call(this))
|
|
2983
3068
|
try {
|
|
2984
|
-
await
|
|
3069
|
+
await p(this, l, B).call(this, d(this, v).db.schema.createSchema(d(this, l, k)));
|
|
2985
3070
|
} catch (e) {
|
|
2986
|
-
if (!await
|
|
3071
|
+
if (!await p(this, l, ne).call(this))
|
|
2987
3072
|
throw e;
|
|
2988
3073
|
}
|
|
2989
3074
|
}, Oe = async function() {
|
|
2990
|
-
if (!await
|
|
3075
|
+
if (!await p(this, l, L).call(this, d(this, l, $)))
|
|
2991
3076
|
try {
|
|
2992
|
-
d(this,
|
|
3077
|
+
d(this, l, k) && await p(this, l, B).call(this, d(this, v).db.schema.createSchema(d(this, l, k))), await p(this, l, B).call(this, d(this, v).db.schema.withPlugin(d(this, l, I)).createTable(d(this, l, $)).addColumn("name", "varchar(255)", (e) => e.notNull().primaryKey()).addColumn("timestamp", "varchar(255)", (e) => e.notNull()));
|
|
2993
3078
|
} catch (e) {
|
|
2994
|
-
if (!await
|
|
3079
|
+
if (!await p(this, l, L).call(this, d(this, l, $)))
|
|
2995
3080
|
throw e;
|
|
2996
3081
|
}
|
|
2997
3082
|
}, ke = async function() {
|
|
2998
|
-
if (!await
|
|
3083
|
+
if (!await p(this, l, L).call(this, d(this, l, z)))
|
|
2999
3084
|
try {
|
|
3000
|
-
await
|
|
3085
|
+
await p(this, l, B).call(this, d(this, v).db.schema.withPlugin(d(this, l, I)).createTable(d(this, l, z)).addColumn("id", "varchar(255)", (e) => e.notNull().primaryKey()).addColumn("is_locked", "integer", (e) => e.notNull().defaultTo(0)));
|
|
3001
3086
|
} catch (e) {
|
|
3002
|
-
if (!await
|
|
3087
|
+
if (!await p(this, l, L).call(this, d(this, l, z)))
|
|
3003
3088
|
throw e;
|
|
3004
3089
|
}
|
|
3005
3090
|
}, $e = async function() {
|
|
3006
|
-
if (!await
|
|
3091
|
+
if (!await p(this, l, oe).call(this))
|
|
3007
3092
|
try {
|
|
3008
|
-
await d(this,
|
|
3093
|
+
await d(this, v).db.withPlugin(d(this, l, I)).insertInto(d(this, l, z)).values({ id: Z, is_locked: 0 }).execute();
|
|
3009
3094
|
} catch (e) {
|
|
3010
|
-
if (!await
|
|
3095
|
+
if (!await p(this, l, oe).call(this))
|
|
3011
3096
|
throw e;
|
|
3012
3097
|
}
|
|
3013
|
-
},
|
|
3014
|
-
return (await d(this,
|
|
3015
|
-
},
|
|
3016
|
-
const r = d(this,
|
|
3017
|
-
return (await d(this,
|
|
3098
|
+
}, ne = async function() {
|
|
3099
|
+
return (await d(this, v).db.introspection.getSchemas()).some((r) => r.name === d(this, l, k));
|
|
3100
|
+
}, L = async function(e) {
|
|
3101
|
+
const r = d(this, l, k);
|
|
3102
|
+
return (await d(this, v).db.introspection.getTables({
|
|
3018
3103
|
withInternalKyselyTables: !0
|
|
3019
|
-
})).some((
|
|
3020
|
-
},
|
|
3021
|
-
return !!await d(this,
|
|
3104
|
+
})).some((n) => n.name === e && (!r || n.schema === r));
|
|
3105
|
+
}, oe = async function() {
|
|
3106
|
+
return !!await d(this, v).db.withPlugin(d(this, l, I)).selectFrom(d(this, l, z)).where("id", "=", Z).select("id").executeTakeFirst();
|
|
3022
3107
|
}, Ie = async function(e) {
|
|
3023
|
-
const r = d(this,
|
|
3024
|
-
lockTable: d(this,
|
|
3025
|
-
lockRowId:
|
|
3026
|
-
lockTableSchema: d(this,
|
|
3027
|
-
}),
|
|
3108
|
+
const r = d(this, v).db.getExecutor().adapter, a = C({
|
|
3109
|
+
lockTable: d(this, v).migrationLockTableName ?? fe,
|
|
3110
|
+
lockRowId: Z,
|
|
3111
|
+
lockTableSchema: d(this, v).migrationTableSchema
|
|
3112
|
+
}), n = async (o) => {
|
|
3028
3113
|
try {
|
|
3029
|
-
await r.acquireMigrationLock(
|
|
3030
|
-
const s = await
|
|
3114
|
+
await r.acquireMigrationLock(o, a);
|
|
3115
|
+
const s = await p(this, l, De).call(this, o);
|
|
3031
3116
|
if (s.migrations.length === 0)
|
|
3032
3117
|
return { results: [] };
|
|
3033
|
-
const { direction:
|
|
3034
|
-
return c <= 0 ? { results: [] } :
|
|
3118
|
+
const { direction: i, step: c } = e(s);
|
|
3119
|
+
return c <= 0 ? { results: [] } : i === "Down" ? await p(this, l, Ae).call(this, o, s, c) : i === "Up" ? await p(this, l, ze).call(this, o, s, c) : { results: [] };
|
|
3035
3120
|
} finally {
|
|
3036
|
-
await r.releaseMigrationLock(
|
|
3121
|
+
await r.releaseMigrationLock(o, a);
|
|
3037
3122
|
}
|
|
3038
3123
|
};
|
|
3039
|
-
return r.supportsTransactionalDdl ? d(this,
|
|
3124
|
+
return r.supportsTransactionalDdl ? d(this, v).db.transaction().execute(n) : d(this, v).db.connection().execute(n);
|
|
3040
3125
|
}, De = async function(e) {
|
|
3041
|
-
const r = await
|
|
3042
|
-
|
|
3043
|
-
const
|
|
3044
|
-
return
|
|
3126
|
+
const r = await p(this, l, se).call(this), a = await p(this, l, je).call(this, e);
|
|
3127
|
+
p(this, l, Fe).call(this, r, a), d(this, l, xe) || p(this, l, Me).call(this, r, a);
|
|
3128
|
+
const n = p(this, l, Pe).call(this, r, a);
|
|
3129
|
+
return C({
|
|
3045
3130
|
migrations: r,
|
|
3046
3131
|
executedMigrations: a,
|
|
3047
3132
|
lastMigration: ia(a),
|
|
3048
|
-
pendingMigrations:
|
|
3133
|
+
pendingMigrations: n
|
|
3049
3134
|
});
|
|
3050
3135
|
}, Pe = function(e, r) {
|
|
3051
3136
|
return e.filter((a) => !r.includes(a.name));
|
|
3052
|
-
},
|
|
3053
|
-
const e = await d(this,
|
|
3137
|
+
}, se = async function() {
|
|
3138
|
+
const e = await d(this, v).provider.getMigrations();
|
|
3054
3139
|
return Object.keys(e).sort().map((r) => ({
|
|
3055
3140
|
...e[r],
|
|
3056
3141
|
name: r
|
|
3057
3142
|
}));
|
|
3058
3143
|
}, je = async function(e) {
|
|
3059
|
-
return (await e.withPlugin(d(this,
|
|
3144
|
+
return (await e.withPlugin(d(this, l, I)).selectFrom(d(this, l, $)).select("name").orderBy(["timestamp", "name"]).execute()).map((a) => a.name);
|
|
3060
3145
|
}, Fe = function(e, r) {
|
|
3061
3146
|
for (const a of r)
|
|
3062
|
-
if (!e.some((
|
|
3147
|
+
if (!e.some((n) => n.name === a))
|
|
3063
3148
|
throw new Error(`corrupted migrations: previously executed migration ${a} is missing`);
|
|
3064
3149
|
}, Me = function(e, r) {
|
|
3065
3150
|
for (let a = 0; a < r.length; ++a)
|
|
3066
3151
|
if (e[a].name !== r[a])
|
|
3067
3152
|
throw new Error(`corrupted migrations: expected previously executed migration ${r[a]} to be at index ${a} but ${e[a].name} was found in its place. New migrations must always have a name that comes alphabetically after the last executed migration.`);
|
|
3068
3153
|
}, Ae = async function(e, r, a) {
|
|
3069
|
-
const
|
|
3154
|
+
const n = r.executedMigrations.slice().reverse().slice(0, a).map((s) => r.migrations.find((i) => i.name === s)), o = n.map((s) => ({
|
|
3070
3155
|
migrationName: s.name,
|
|
3071
3156
|
direction: "Down",
|
|
3072
3157
|
status: "NotExecuted"
|
|
3073
3158
|
}));
|
|
3074
|
-
for (let s = 0; s <
|
|
3075
|
-
const
|
|
3159
|
+
for (let s = 0; s < o.length; ++s) {
|
|
3160
|
+
const i = n[s];
|
|
3076
3161
|
try {
|
|
3077
|
-
|
|
3078
|
-
migrationName:
|
|
3162
|
+
i.down && (await i.down(e), await e.withPlugin(d(this, l, I)).deleteFrom(d(this, l, $)).where("name", "=", i.name).execute(), o[s] = {
|
|
3163
|
+
migrationName: i.name,
|
|
3079
3164
|
direction: "Down",
|
|
3080
3165
|
status: "Success"
|
|
3081
3166
|
});
|
|
3082
3167
|
} catch (c) {
|
|
3083
|
-
throw
|
|
3084
|
-
migrationName:
|
|
3168
|
+
throw o[s] = {
|
|
3169
|
+
migrationName: i.name,
|
|
3085
3170
|
direction: "Down",
|
|
3086
3171
|
status: "Error"
|
|
3087
|
-
}, new
|
|
3172
|
+
}, new ee({
|
|
3088
3173
|
error: c,
|
|
3089
|
-
results:
|
|
3174
|
+
results: o
|
|
3090
3175
|
});
|
|
3091
3176
|
}
|
|
3092
3177
|
}
|
|
3093
|
-
return { results:
|
|
3178
|
+
return { results: o };
|
|
3094
3179
|
}, ze = async function(e, r, a) {
|
|
3095
|
-
const
|
|
3180
|
+
const o = r.pendingMigrations.slice(0, a).map((s) => ({
|
|
3096
3181
|
migrationName: s.name,
|
|
3097
3182
|
direction: "Up",
|
|
3098
3183
|
status: "NotExecuted"
|
|
3099
3184
|
}));
|
|
3100
|
-
for (let s = 0; s <
|
|
3101
|
-
const
|
|
3185
|
+
for (let s = 0; s < o.length; s++) {
|
|
3186
|
+
const i = r.pendingMigrations[s];
|
|
3102
3187
|
try {
|
|
3103
|
-
await
|
|
3104
|
-
name:
|
|
3188
|
+
await i.up(e), await e.withPlugin(d(this, l, I)).insertInto(d(this, l, $)).values({
|
|
3189
|
+
name: i.name,
|
|
3105
3190
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3106
|
-
}).execute(),
|
|
3107
|
-
migrationName:
|
|
3191
|
+
}).execute(), o[s] = {
|
|
3192
|
+
migrationName: i.name,
|
|
3108
3193
|
direction: "Up",
|
|
3109
3194
|
status: "Success"
|
|
3110
3195
|
};
|
|
3111
3196
|
} catch (c) {
|
|
3112
|
-
throw
|
|
3113
|
-
migrationName:
|
|
3197
|
+
throw o[s] = {
|
|
3198
|
+
migrationName: i.name,
|
|
3114
3199
|
direction: "Up",
|
|
3115
3200
|
status: "Error"
|
|
3116
|
-
}, new
|
|
3201
|
+
}, new ee({
|
|
3117
3202
|
error: c,
|
|
3118
|
-
results:
|
|
3203
|
+
results: o
|
|
3119
3204
|
});
|
|
3120
3205
|
}
|
|
3121
3206
|
}
|
|
3122
|
-
return { results:
|
|
3123
|
-
},
|
|
3124
|
-
d(this,
|
|
3207
|
+
return { results: o };
|
|
3208
|
+
}, B = async function(e) {
|
|
3209
|
+
d(this, v).db.getExecutor().adapter.supportsCreateIfNotExists && (e = e.ifNotExists()), await e.execute();
|
|
3125
3210
|
};
|
|
3126
|
-
var
|
|
3127
|
-
class
|
|
3211
|
+
var q;
|
|
3212
|
+
class ee extends Error {
|
|
3128
3213
|
constructor(r) {
|
|
3129
3214
|
super();
|
|
3130
|
-
|
|
3131
|
-
|
|
3215
|
+
S(this, q);
|
|
3216
|
+
K(this, q, r);
|
|
3132
3217
|
}
|
|
3133
3218
|
get resultSet() {
|
|
3134
|
-
return d(this,
|
|
3219
|
+
return d(this, q);
|
|
3135
3220
|
}
|
|
3136
3221
|
}
|
|
3137
|
-
|
|
3222
|
+
q = new WeakMap();
|
|
3138
3223
|
class Le {
|
|
3139
3224
|
constructor(e) {
|
|
3140
|
-
|
|
3225
|
+
R(this, "migrations");
|
|
3141
3226
|
this.migrations = e;
|
|
3142
3227
|
}
|
|
3143
3228
|
async getMigrations() {
|
|
@@ -3427,7 +3512,15 @@ async function mn(t) {
|
|
|
3427
3512
|
"tenant_id",
|
|
3428
3513
|
"varchar(255)",
|
|
3429
3514
|
(e) => e.references("tenants.id").onDelete("cascade")
|
|
3430
|
-
).addColumn("created_at", "varchar(255)", (e) => e.notNull()).addColumn("revoked_at", "varchar(255)").addColumn("cert", "varchar(
|
|
3515
|
+
).addColumn("created_at", "varchar(255)", (e) => e.notNull()).addColumn("revoked_at", "varchar(255)").addColumn("cert", "varchar(4096)").addColumn("pkcs7", "varchar(4096)").addColumn("fingerprint", "varchar(256)").addColumn("thumbprint", "varchar(256)").addColumn("current_since", "varchar(256)").addColumn("current_until", "varchar(256)").addColumn(
|
|
3516
|
+
"type",
|
|
3517
|
+
"varchar(50)",
|
|
3518
|
+
(e) => e.notNull().defaultTo("jwt_signing")
|
|
3519
|
+
).addColumn(
|
|
3520
|
+
"connection",
|
|
3521
|
+
"varchar(255)",
|
|
3522
|
+
(e) => e.references("connections.id").onDelete("cascade")
|
|
3523
|
+
).execute();
|
|
3431
3524
|
}
|
|
3432
3525
|
async function _n(t) {
|
|
3433
3526
|
await t.schema.dropTable("keys").execute();
|
|
@@ -4455,7 +4548,7 @@ const fl = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
4455
4548
|
up: _l
|
|
4456
4549
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
4457
4550
|
async function pl(t) {
|
|
4458
|
-
await t.schema.createTable("resource_servers").addColumn("id", "varchar(21)", (e) => e.notNull()).addColumn("tenant_id", "varchar(191)", (e) => e.notNull()).addColumn("identifier", "varchar(191)", (e) => e.notNull()).addColumn("name", "varchar(255)", (e) => e.notNull()).addColumn("scopes", "varchar(4096)").addColumn("signing_alg", "varchar(64)").addColumn("signing_secret", "varchar(2048)").addColumn("token_lifetime", "integer").addColumn("token_lifetime_for_web", "integer").addColumn("skip_consent_for_verifiable_first_party_clients", "integer").addColumn("allow_offline_access", "integer").addColumn("verification_key", "varchar(4096)").addColumn("options", "varchar(4096)").addColumn("created_at", "varchar(
|
|
4551
|
+
await t.schema.createTable("resource_servers").addColumn("id", "varchar(21)", (e) => e.notNull()).addColumn("tenant_id", "varchar(191)", (e) => e.notNull()).addColumn("identifier", "varchar(191)", (e) => e.notNull()).addColumn("name", "varchar(255)", (e) => e.notNull()).addColumn("scopes", "varchar(4096)").addColumn("signing_alg", "varchar(64)").addColumn("signing_secret", "varchar(2048)").addColumn("token_lifetime", "integer").addColumn("token_lifetime_for_web", "integer").addColumn("skip_consent_for_verifiable_first_party_clients", "integer").addColumn("allow_offline_access", "integer").addColumn("verification_key", "varchar(4096)").addColumn("options", "varchar(4096)").addColumn("created_at", "varchar(35)", (e) => e.notNull()).addColumn("updated_at", "varchar(35)", (e) => e.notNull()).addPrimaryKeyConstraint("resource_servers_pk", ["tenant_id", "id"]).execute(), await t.schema.createIndex("resource_servers_tenant_identifier_uq").on("resource_servers").columns(["tenant_id", "identifier"]).unique().execute(), await t.schema.createTable("roles").addColumn("id", "varchar(21)", (e) => e.notNull()).addColumn("tenant_id", "varchar(191)", (e) => e.notNull()).addColumn("name", "varchar(50)", (e) => e.notNull()).addColumn("description", "varchar(255)").addColumn("created_at", "varchar(35)", (e) => e.notNull()).addColumn("updated_at", "varchar(35)", (e) => e.notNull()).addPrimaryKeyConstraint("roles_pk", ["tenant_id", "id"]).execute(), await t.schema.createIndex("roles_tenant_name_uq").on("roles").columns(["tenant_id", "name"]).unique().execute();
|
|
4459
4552
|
}
|
|
4460
4553
|
async function gl(t) {
|
|
4461
4554
|
await t.schema.dropTable("roles").execute(), await t.schema.dropTable("resource_servers").execute();
|
|
@@ -4470,7 +4563,7 @@ async function yl(t) {
|
|
|
4470
4563
|
"resource_server_identifier",
|
|
4471
4564
|
"varchar(191)",
|
|
4472
4565
|
(e) => e.notNull()
|
|
4473
|
-
).addColumn("permission_name", "varchar(
|
|
4566
|
+
).addColumn("permission_name", "varchar(191)", (e) => e.notNull()).addColumn("created_at", "varchar(35)", (e) => e.notNull()).addPrimaryKeyConstraint("role_permissions_pk", [
|
|
4474
4567
|
"tenant_id",
|
|
4475
4568
|
"role_id",
|
|
4476
4569
|
"resource_server_identifier",
|
|
@@ -4479,7 +4572,7 @@ async function yl(t) {
|
|
|
4479
4572
|
"resource_server_identifier",
|
|
4480
4573
|
"varchar(191)",
|
|
4481
4574
|
(e) => e.notNull()
|
|
4482
|
-
).addColumn("permission_name", "varchar(
|
|
4575
|
+
).addColumn("permission_name", "varchar(191)", (e) => e.notNull()).addColumn("created_at", "varchar(35)", (e) => e.notNull()).addPrimaryKeyConstraint("user_permissions_pk", [
|
|
4483
4576
|
"tenant_id",
|
|
4484
4577
|
"user_id",
|
|
4485
4578
|
"resource_server_identifier",
|
|
@@ -4495,7 +4588,7 @@ const Nl = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
4495
4588
|
up: yl
|
|
4496
4589
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
4497
4590
|
async function Cl(t) {
|
|
4498
|
-
await t.schema.createTable("user_roles").addColumn("tenant_id", "varchar(191)", (e) => e.notNull()).addColumn("user_id", "varchar(191)", (e) => e.notNull()).addColumn("role_id", "varchar(21)", (e) => e.notNull()).addColumn("created_at", "varchar(
|
|
4591
|
+
await t.schema.createTable("user_roles").addColumn("tenant_id", "varchar(191)", (e) => e.notNull()).addColumn("user_id", "varchar(191)", (e) => e.notNull()).addColumn("role_id", "varchar(21)", (e) => e.notNull()).addColumn("created_at", "varchar(35)", (e) => e.notNull()).addPrimaryKeyConstraint("user_roles_pk", [
|
|
4499
4592
|
"tenant_id",
|
|
4500
4593
|
"user_id",
|
|
4501
4594
|
"role_id"
|
|
@@ -4508,6 +4601,16 @@ const xl = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
4508
4601
|
__proto__: null,
|
|
4509
4602
|
down: bl,
|
|
4510
4603
|
up: Cl
|
|
4604
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
4605
|
+
async function Tl(t) {
|
|
4606
|
+
}
|
|
4607
|
+
async function Sl(t) {
|
|
4608
|
+
await t.schema.alterTable("keys").dropColumn("connection").execute(), await t.schema.alterTable("keys").modifyColumn("cert", "varchar(2048)").execute(), await t.schema.alterTable("keys").modifyColumn("pkcs7", "varchar(2048)").execute(), await t.schema.alterTable("keys").dropColumn("type").execute();
|
|
4609
|
+
}
|
|
4610
|
+
const Ol = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
4611
|
+
__proto__: null,
|
|
4612
|
+
down: Sl,
|
|
4613
|
+
up: Tl
|
|
4511
4614
|
}, Symbol.toStringTag, { value: "Module" })), Ee = {
|
|
4512
4615
|
m1_init: ya,
|
|
4513
4616
|
m2_magicLink: Ca,
|
|
@@ -4600,33 +4703,34 @@ const xl = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
4600
4703
|
n90_themes: fl,
|
|
4601
4704
|
n91_resource_servers_rules_permissions: wl,
|
|
4602
4705
|
n92_role_permissions: Nl,
|
|
4603
|
-
n93_add_permissions_to_roles: xl
|
|
4706
|
+
n93_add_permissions_to_roles: xl,
|
|
4707
|
+
n94_keys_connection_and_extend_columns: Ol
|
|
4604
4708
|
};
|
|
4605
|
-
async function
|
|
4709
|
+
async function Pl(t, e = !1) {
|
|
4606
4710
|
e && console.log("migrating...");
|
|
4607
4711
|
const r = new Le(Ee), a = new be({
|
|
4608
4712
|
db: t,
|
|
4609
4713
|
provider: r
|
|
4610
|
-
}), { error:
|
|
4611
|
-
if (
|
|
4714
|
+
}), { error: n, results: o } = await a.migrateToLatest();
|
|
4715
|
+
if (o == null || o.forEach((s) => {
|
|
4612
4716
|
s.status === "Success" ? e && console.log(
|
|
4613
4717
|
`migration "${s.migrationName}" was executed successfully`
|
|
4614
4718
|
) : s.status === "Error" && console.error(`failed to execute migration "${s.migrationName}"`);
|
|
4615
|
-
}),
|
|
4616
|
-
throw console.error("failed to migrate"), console.error(
|
|
4719
|
+
}), n)
|
|
4720
|
+
throw console.error("failed to migrate"), console.error(n), n;
|
|
4617
4721
|
}
|
|
4618
|
-
async function
|
|
4722
|
+
async function jl(t) {
|
|
4619
4723
|
console.log("migrating...");
|
|
4620
4724
|
const e = new Le(Ee), r = new be({
|
|
4621
4725
|
db: t,
|
|
4622
4726
|
provider: e
|
|
4623
|
-
}), { error: a, results:
|
|
4624
|
-
if (
|
|
4625
|
-
|
|
4727
|
+
}), { error: a, results: n } = await r.migrateDown();
|
|
4728
|
+
if (n == null || n.forEach((o) => {
|
|
4729
|
+
o.status === "Success" ? console.log(`migration "${o.migrationName}" was reverted successfully`) : o.status === "Error" && console.error(`failed to execute migration "${o.migrationName}"`);
|
|
4626
4730
|
}), a)
|
|
4627
4731
|
throw console.error("failed to migrate"), console.error(a), a;
|
|
4628
4732
|
}
|
|
4629
|
-
function
|
|
4733
|
+
function Fl(t) {
|
|
4630
4734
|
return {
|
|
4631
4735
|
applications: jt(t),
|
|
4632
4736
|
branding: er(t),
|
|
@@ -4656,7 +4760,7 @@ function Dl(t) {
|
|
|
4656
4760
|
};
|
|
4657
4761
|
}
|
|
4658
4762
|
export {
|
|
4659
|
-
|
|
4660
|
-
|
|
4661
|
-
|
|
4763
|
+
Fl as default,
|
|
4764
|
+
jl as migrateDown,
|
|
4765
|
+
Pl as migrateToLatest
|
|
4662
4766
|
};
|