@voltro/plugin-auth 0.71.1 → 0.73.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +468 -0
- package/THIRD-PARTY-NOTICES.md +29 -1
- package/dist/index.d.ts +260 -176
- package/dist/index.js +184 -131
- package/dist/{plugin-CPcpSSf9.js → plugin-DFQ8N52Q.js} +236 -232
- package/dist/plugin.d.ts +179 -142
- package/dist/plugin.js +1 -1
- package/dist/strategy.d.ts +179 -142
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,83 +1,136 @@
|
|
|
1
1
|
import { PasswordEmptyError as e, PasswordHashError as t, hashPassword as n, needsRehash as r, parseScryptParams as i, verifyPassword as a, verifyPasswordWithRehash as o } from "./password.js";
|
|
2
2
|
import { SESSION_COOKIE_NAME as s, clearSessionCookie as c, issueSession as l, readSession as u, readSessionKeyed as d, resolveSessionSecret as f, resolveSessionSecrets as p, sessionSecretsOf as m } from "./session.js";
|
|
3
3
|
import { a as h, c as g, i as _, l as v, n as y, o as b, r as x, s as S, t as C } from "./strategy-MP_KxNuA.js";
|
|
4
|
-
import { $ as w, A as T, B as E, C as D, D as O, E as k, F as A, G as j, H as M, I as N, J as P, K as F, L as I, M as L, N as R, O as z, P as B, Q as V, R as H, S as
|
|
5
|
-
import { EMAIL_VERIFY_TTL_S as
|
|
6
|
-
import { CSRF_COOKIE_NAME as
|
|
4
|
+
import { $ as w, A as T, B as E, C as D, D as O, E as k, F as A, G as j, H as M, I as N, J as P, K as F, L as I, M as L, N as R, O as z, P as B, Q as V, R as H, S as U, T as W, U as G, V as K, W as q, X as J, Y, Z as X, _ as Z, a as Q, at as ee, b as te, c as ne, ct as re, d as ie, et as ae, f as oe, g as se, h as ce, i as le, it as ue, j as de, k as fe, l as pe, lt as me, m as he, n as ge, nt as _e, o as ve, ot as ye, p as be, q as xe, r as Se, rt as Ce, s as we, st as Te, t as Ee, tt as De, u as Oe, ut as ke, v as Ae, w as je, x as Me, y as Ne, z as Pe } from "./plugin-DFQ8N52Q.js";
|
|
5
|
+
import { EMAIL_VERIFY_TTL_S as Fe, MAGIC_LINK_TTL_S as Ie, MFA_PENDING_TTL_S as Le, PASSWORD_RESET_TTL_S as Re, hashToken as ze, mintSecret as Be, mintToken as Ve } from "./tokens.js";
|
|
6
|
+
import { CSRF_COOKIE_NAME as He, CSRF_HEADER_NAME as Ue, isCsrfTokenWellFormed as We, issueCsrfToken as Ge, verifyCsrf as Ke } from "./csrf.js";
|
|
7
7
|
import { generateChallenge as qe, verifyAssertion as Je, verifyRegistration as Ye } from "./webauthn.js";
|
|
8
8
|
import { Effect as $ } from "effect";
|
|
9
|
-
//#region src/
|
|
10
|
-
var Xe = (e) => {
|
|
9
|
+
//#region src/memberships.ts
|
|
10
|
+
var Xe = (e) => async (t) => t.type === "user" ? (await $.runPromise(e.listMemberships(t.id))).map((e) => ({
|
|
11
|
+
tenantId: e.tenantId,
|
|
12
|
+
role: e.role
|
|
13
|
+
})) : [], Ze = (e) => {
|
|
11
14
|
let t = e?.code;
|
|
12
15
|
if (typeof t == "string") return t;
|
|
13
16
|
let n = e?.cause?.code;
|
|
14
17
|
return typeof n == "string" ? n : void 0;
|
|
15
|
-
},
|
|
16
|
-
let t =
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
}, Qe = (e) => {
|
|
19
|
+
let t = e?.columns ?? {};
|
|
20
|
+
return {
|
|
21
|
+
table: e?.table ?? "users",
|
|
22
|
+
col: {
|
|
23
|
+
id: t.id ?? "id",
|
|
24
|
+
email: t.email ?? "email",
|
|
25
|
+
tenantId: t.tenantId ?? "tenantId",
|
|
26
|
+
createdAt: t.createdAt ?? "createdAt",
|
|
27
|
+
passwordHash: t.passwordHash ?? "passwordHash",
|
|
28
|
+
updatedAt: t.updatedAt ?? "updatedAt",
|
|
29
|
+
mfaSecret: t.mfaSecret ?? "mfaSecret",
|
|
30
|
+
mfaEnrolledAt: t.mfaEnrolledAt ?? "mfaEnrolledAt",
|
|
31
|
+
emailVerifiedAt: t.emailVerifiedAt ?? "emailVerifiedAt",
|
|
32
|
+
deactivatedAt: t.deactivatedAt ?? !1
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
}, $e = (e, t = {}) => {
|
|
36
|
+
let n = Qe(t.identity), { col: r } = n, i = (t) => e`${e(r[t])}`, a = [
|
|
37
|
+
"id",
|
|
38
|
+
"email",
|
|
39
|
+
"passwordHash",
|
|
40
|
+
"tenantId",
|
|
41
|
+
"createdAt",
|
|
42
|
+
"mfaSecret",
|
|
43
|
+
"mfaEnrolledAt",
|
|
44
|
+
"emailVerifiedAt",
|
|
45
|
+
"deactivatedAt"
|
|
46
|
+
], o, s = () => o ??= {
|
|
47
|
+
usersTable: e.join(".", !1)(n.table.split(".").map((t) => e`${e(t)}`)),
|
|
48
|
+
selectList: e.csv(a.map((t) => r[t] === !1 ? e`NULL AS ${e(t)}` : e`${i(t)} AS ${e(t)}`))
|
|
49
|
+
}, c = (e, t) => /* @__PURE__ */ Error(`postgresUserStore: ${t} needs the "${e}" column, and identity.columns.${e} is false — this table has none`), l = (t) => r.updatedAt === !1 ? e`` : e`, ${i("updatedAt")} = ${t}`, u = (e) => ({
|
|
50
|
+
id: e.id,
|
|
51
|
+
email: e.email,
|
|
52
|
+
passwordHash: e.passwordHash,
|
|
53
|
+
tenantId: e.tenantId,
|
|
54
|
+
createdAt: e.createdAt,
|
|
55
|
+
mfaSecret: e.mfaSecret,
|
|
56
|
+
mfaEnrolledAt: e.mfaEnrolledAt,
|
|
57
|
+
emailVerifiedAt: e.emailVerifiedAt,
|
|
58
|
+
...r.deactivatedAt === !1 ? {} : { deactivatedAt: e.deactivatedAt ?? null }
|
|
59
|
+
}), d = (t) => $.gen(function* () {
|
|
60
|
+
let n = yield* e`
|
|
61
|
+
SELECT ${s().selectList} FROM ${s().usersTable}
|
|
62
|
+
WHERE ${i("email")} = ${t.toLowerCase()}
|
|
21
63
|
LIMIT 1
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
FROM
|
|
27
|
-
WHERE id = ${t}
|
|
64
|
+
`;
|
|
65
|
+
return n[0] ? u(n[0]) : null;
|
|
66
|
+
}).pipe($.orElseSucceed(() => null)), f = (t) => $.gen(function* () {
|
|
67
|
+
let n = yield* e`
|
|
68
|
+
SELECT ${s().selectList} FROM ${s().usersTable}
|
|
69
|
+
WHERE ${i("id")} = ${t}
|
|
28
70
|
LIMIT 1
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
71
|
+
`;
|
|
72
|
+
return n[0] ? u(n[0]) : null;
|
|
73
|
+
}).pipe($.orElseSucceed(() => null)), p = (t) => $.gen(function* () {
|
|
74
|
+
let n = t.email.toLowerCase(), a = /* @__PURE__ */ new Date(), o = [
|
|
75
|
+
i("id"),
|
|
76
|
+
i("email"),
|
|
77
|
+
i("tenantId"),
|
|
78
|
+
i("createdAt")
|
|
79
|
+
], c = [
|
|
80
|
+
t.id,
|
|
81
|
+
n,
|
|
82
|
+
t.tenantId,
|
|
83
|
+
a
|
|
84
|
+
];
|
|
85
|
+
return r.passwordHash !== !1 && (o.push(i("passwordHash")), c.push(t.passwordHash ?? null)), r.updatedAt !== !1 && (o.push(i("updatedAt")), c.push(a)), yield* e`
|
|
86
|
+
INSERT INTO ${s().usersTable} (${e.csv(o)})
|
|
87
|
+
VALUES ${e.in(c)}
|
|
35
88
|
`.pipe($.map(() => ({
|
|
36
89
|
...t,
|
|
37
90
|
email: n,
|
|
38
|
-
createdAt:
|
|
39
|
-
})), $.catchAll((e) =>
|
|
40
|
-
}),
|
|
41
|
-
|
|
42
|
-
SELECT
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}).pipe($.catchTag("SqlError", (e) => $.die(e))),
|
|
46
|
-
return yield* e`
|
|
47
|
-
UPDATE
|
|
48
|
-
WHERE id = ${t}
|
|
49
|
-
`.pipe($.catchTag("SqlError", (e) => $.die(e))), yield*
|
|
50
|
-
}),
|
|
51
|
-
return yield* e`
|
|
52
|
-
UPDATE
|
|
53
|
-
SET "mfaSecret" = ${n}, "mfaEnrolledAt" = ${null}
|
|
54
|
-
WHERE id = ${t}
|
|
55
|
-
`.pipe($.catchTag("SqlError", (e) => $.die(e))), yield*
|
|
56
|
-
}),
|
|
57
|
-
return yield* e`
|
|
58
|
-
UPDATE
|
|
59
|
-
SET "mfaEnrolledAt" = ${/* @__PURE__ */ new Date()}
|
|
60
|
-
WHERE id = ${t}
|
|
61
|
-
`.pipe($.catchTag("SqlError", (e) => $.die(e))), yield*
|
|
62
|
-
}),
|
|
63
|
-
return yield* e`
|
|
64
|
-
UPDATE
|
|
65
|
-
SET "mfaSecret" = ${null}, "mfaEnrolledAt" = ${null}
|
|
66
|
-
WHERE id = ${t}
|
|
67
|
-
`.pipe($.catchTag("SqlError", (e) => $.die(e))), yield*
|
|
68
|
-
}),
|
|
69
|
-
return yield* e`
|
|
70
|
-
UPDATE
|
|
71
|
-
SET "emailVerifiedAt" = ${/* @__PURE__ */ new Date()}
|
|
72
|
-
WHERE id = ${t} AND "emailVerifiedAt" IS NULL
|
|
73
|
-
`.pipe($.catchTag("SqlError", (e) => $.die(e))), yield*
|
|
74
|
-
}),
|
|
91
|
+
createdAt: a
|
|
92
|
+
})), $.catchAll((e) => Ze(e) === "23505" ? $.fail(new y({ email: n })) : $.die(e)));
|
|
93
|
+
}), m = (t) => $.gen(function* () {
|
|
94
|
+
let n = (yield* e`
|
|
95
|
+
SELECT ${s().selectList} FROM ${s().usersTable} WHERE ${i("id")} = ${t} LIMIT 1
|
|
96
|
+
`)[0];
|
|
97
|
+
return n ? u(n) : yield* $.fail(new x({ userId: t }));
|
|
98
|
+
}).pipe($.catchTag("SqlError", (e) => $.die(e))), g = (t, n) => $.gen(function* () {
|
|
99
|
+
return r.passwordHash === !1 ? yield* $.die(c("passwordHash", "updatePassword")) : (yield* e`
|
|
100
|
+
UPDATE ${s().usersTable} SET ${i("passwordHash")} = ${n}${l(/* @__PURE__ */ new Date())}
|
|
101
|
+
WHERE ${i("id")} = ${t}
|
|
102
|
+
`.pipe($.catchTag("SqlError", (e) => $.die(e))), yield* m(t));
|
|
103
|
+
}), _ = (t, n) => $.gen(function* () {
|
|
104
|
+
return r.mfaSecret === !1 ? yield* $.die(c("mfaSecret", "setMfaSecret")) : r.mfaEnrolledAt === !1 ? yield* $.die(c("mfaEnrolledAt", "setMfaSecret")) : (yield* e`
|
|
105
|
+
UPDATE ${s().usersTable}
|
|
106
|
+
SET ${i("mfaSecret")} = ${n}, ${i("mfaEnrolledAt")} = ${null}
|
|
107
|
+
WHERE ${i("id")} = ${t}
|
|
108
|
+
`.pipe($.catchTag("SqlError", (e) => $.die(e))), yield* m(t));
|
|
109
|
+
}), v = (t) => $.gen(function* () {
|
|
110
|
+
return r.mfaEnrolledAt === !1 ? yield* $.die(c("mfaEnrolledAt", "markMfaEnrolled")) : (yield* e`
|
|
111
|
+
UPDATE ${s().usersTable}
|
|
112
|
+
SET ${i("mfaEnrolledAt")} = ${/* @__PURE__ */ new Date()}
|
|
113
|
+
WHERE ${i("id")} = ${t}
|
|
114
|
+
`.pipe($.catchTag("SqlError", (e) => $.die(e))), yield* m(t));
|
|
115
|
+
}), b = (t) => $.gen(function* () {
|
|
116
|
+
return r.mfaSecret === !1 ? yield* $.die(c("mfaSecret", "clearMfa")) : r.mfaEnrolledAt === !1 ? yield* $.die(c("mfaEnrolledAt", "clearMfa")) : (yield* e`
|
|
117
|
+
UPDATE ${s().usersTable}
|
|
118
|
+
SET ${i("mfaSecret")} = ${null}, ${i("mfaEnrolledAt")} = ${null}
|
|
119
|
+
WHERE ${i("id")} = ${t}
|
|
120
|
+
`.pipe($.catchTag("SqlError", (e) => $.die(e))), yield* m(t));
|
|
121
|
+
}), S = (t) => $.gen(function* () {
|
|
122
|
+
return r.emailVerifiedAt === !1 ? yield* $.die(c("emailVerifiedAt", "markEmailVerified")) : (yield* e`
|
|
123
|
+
UPDATE ${s().usersTable}
|
|
124
|
+
SET ${i("emailVerifiedAt")} = ${/* @__PURE__ */ new Date()}${l(/* @__PURE__ */ new Date())}
|
|
125
|
+
WHERE ${i("id")} = ${t} AND ${i("emailVerifiedAt")} IS NULL
|
|
126
|
+
`.pipe($.catchTag("SqlError", (e) => $.die(e))), yield* m(t));
|
|
127
|
+
}), C = (t) => $.gen(function* () {
|
|
75
128
|
return (yield* e`
|
|
76
129
|
SELECT "userId", "tenantId", role, "joinedAt"
|
|
77
130
|
FROM memberships WHERE "userId" = ${t}
|
|
78
131
|
ORDER BY "joinedAt" ASC
|
|
79
132
|
`).map((e) => ({ ...e }));
|
|
80
|
-
}).pipe($.orElseSucceed(() => [])),
|
|
133
|
+
}).pipe($.orElseSucceed(() => [])), w = (t) => $.gen(function* () {
|
|
81
134
|
let n = /* @__PURE__ */ new Date();
|
|
82
135
|
yield* e`
|
|
83
136
|
UPDATE memberships SET role = ${t.role}
|
|
@@ -99,18 +152,18 @@ var Xe = (e) => {
|
|
|
99
152
|
}).pipe($.catchAll(() => $.succeed({
|
|
100
153
|
...t,
|
|
101
154
|
joinedAt: /* @__PURE__ */ new Date()
|
|
102
|
-
}))),
|
|
155
|
+
}))), T = (t, n) => $.gen(function* () {
|
|
103
156
|
return (yield* e`
|
|
104
157
|
SELECT role FROM memberships
|
|
105
158
|
WHERE "userId" = ${t} AND "tenantId" = ${n} LIMIT 1
|
|
106
159
|
`)[0]?.role ?? null;
|
|
107
|
-
}).pipe($.orElseSucceed(() => null)),
|
|
160
|
+
}).pipe($.orElseSucceed(() => null)), E = (t) => $.gen(function* () {
|
|
108
161
|
return (yield* e`
|
|
109
162
|
SELECT id, "userId", "tenantId", "expiresAt", "ipAddress", "userAgent", "createdAt", "lastSeenAt"
|
|
110
163
|
FROM sessions WHERE "userId" = ${t}
|
|
111
164
|
ORDER BY "createdAt" DESC
|
|
112
165
|
`).map((e) => ({ ...e }));
|
|
113
|
-
}).pipe($.orElseSucceed(() => [])),
|
|
166
|
+
}).pipe($.orElseSucceed(() => [])), D = (t) => $.gen(function* () {
|
|
114
167
|
let n = /* @__PURE__ */ new Date();
|
|
115
168
|
return yield* e`
|
|
116
169
|
INSERT INTO sessions (id, "userId", "tenantId", "expiresAt", "ipAddress", "userAgent", "createdAt", "lastSeenAt")
|
|
@@ -127,28 +180,28 @@ var Xe = (e) => {
|
|
|
127
180
|
...t,
|
|
128
181
|
createdAt: /* @__PURE__ */ new Date(),
|
|
129
182
|
lastSeenAt: /* @__PURE__ */ new Date()
|
|
130
|
-
}))),
|
|
183
|
+
}))), O = (t) => $.gen(function* () {
|
|
131
184
|
let n = yield* e`
|
|
132
185
|
SELECT id, "userId", "tenantId", "expiresAt", "ipAddress", "userAgent", "createdAt", "lastSeenAt"
|
|
133
186
|
FROM sessions WHERE id = ${t} LIMIT 1
|
|
134
187
|
`;
|
|
135
188
|
return n[0] ? { ...n[0] } : null;
|
|
136
|
-
}).pipe($.orElseSucceed(() => null)),
|
|
189
|
+
}).pipe($.orElseSucceed(() => null)), k = (t, n) => $.gen(function* () {
|
|
137
190
|
yield* e`
|
|
138
191
|
UPDATE sessions SET "expiresAt" = ${n}, "lastSeenAt" = ${/* @__PURE__ */ new Date()}
|
|
139
192
|
WHERE id = ${t}
|
|
140
193
|
`;
|
|
141
|
-
}).pipe($.asVoid, $.orElseSucceed(() => void 0)),
|
|
194
|
+
}).pipe($.asVoid, $.orElseSucceed(() => void 0)), A = (t, n) => $.gen(function* () {
|
|
142
195
|
return (yield* e`
|
|
143
196
|
DELETE FROM sessions WHERE id = ${n} AND "userId" = ${t}
|
|
144
197
|
RETURNING id
|
|
145
198
|
`).length > 0;
|
|
146
|
-
}).pipe($.orElseSucceed(() => !1)),
|
|
199
|
+
}).pipe($.orElseSucceed(() => !1)), j = (t, n) => $.gen(function* () {
|
|
147
200
|
return (yield* e`
|
|
148
201
|
DELETE FROM sessions WHERE "userId" = ${t} AND id <> ${n}
|
|
149
202
|
RETURNING id
|
|
150
203
|
`).length;
|
|
151
|
-
}).pipe($.orElseSucceed(() => 0)),
|
|
204
|
+
}).pipe($.orElseSucceed(() => 0)), M = (t) => $.gen(function* () {
|
|
152
205
|
let n = /* @__PURE__ */ new Date();
|
|
153
206
|
return yield* e`
|
|
154
207
|
INSERT INTO "authTokens" (id, "tokenHash", "userId", purpose, "expiresAt", "consumedAt", "createdAt")
|
|
@@ -162,7 +215,7 @@ var Xe = (e) => {
|
|
|
162
215
|
...t,
|
|
163
216
|
consumedAt: null,
|
|
164
217
|
createdAt: /* @__PURE__ */ new Date()
|
|
165
|
-
}))),
|
|
218
|
+
}))), N = (t, n) => $.gen(function* () {
|
|
166
219
|
let r = yield* e`
|
|
167
220
|
UPDATE "authTokens"
|
|
168
221
|
SET "consumedAt" = ${/* @__PURE__ */ new Date()}
|
|
@@ -173,7 +226,7 @@ var Xe = (e) => {
|
|
|
173
226
|
RETURNING id, "tokenHash", "userId", purpose, "expiresAt", "consumedAt", "createdAt"
|
|
174
227
|
`;
|
|
175
228
|
return r[0] ? { ...r[0] } : null;
|
|
176
|
-
}).pipe($.orElseSucceed(() => null)),
|
|
229
|
+
}).pipe($.orElseSucceed(() => null)), P = (t, n) => $.gen(function* () {
|
|
177
230
|
let r = yield* e`
|
|
178
231
|
SELECT id, "tokenHash", "userId", purpose, "expiresAt", "consumedAt", "createdAt"
|
|
179
232
|
FROM "authTokens"
|
|
@@ -182,7 +235,7 @@ var Xe = (e) => {
|
|
|
182
235
|
LIMIT 1
|
|
183
236
|
`;
|
|
184
237
|
return r[0] ? { ...r[0] } : null;
|
|
185
|
-
}).pipe($.orElseSucceed(() => null)),
|
|
238
|
+
}).pipe($.orElseSucceed(() => null)), F = (t) => $.gen(function* () {
|
|
186
239
|
let n = /* @__PURE__ */ new Date(), r = t.email.toLowerCase();
|
|
187
240
|
return yield* e`
|
|
188
241
|
INSERT INTO invitations (
|
|
@@ -202,14 +255,14 @@ var Xe = (e) => {
|
|
|
202
255
|
revokedByUserId: null,
|
|
203
256
|
createdAt: n
|
|
204
257
|
};
|
|
205
|
-
}).pipe($.catchAll((e) => $.die(e))),
|
|
258
|
+
}).pipe($.catchAll((e) => $.die(e))), I = (t) => $.gen(function* () {
|
|
206
259
|
let n = yield* e`
|
|
207
260
|
SELECT id, "tokenHash", email, "tenantId", role, "invitedByUserId", "expiresAt",
|
|
208
261
|
"acceptedAt", "acceptedByUserId", "revokedAt", "revokedByUserId", "createdAt"
|
|
209
262
|
FROM invitations WHERE "tokenHash" = ${t} LIMIT 1
|
|
210
263
|
`;
|
|
211
264
|
return n[0] ? { ...n[0] } : null;
|
|
212
|
-
}).pipe($.orElseSucceed(() => null)),
|
|
265
|
+
}).pipe($.orElseSucceed(() => null)), L = (t, n, r) => $.gen(function* () {
|
|
213
266
|
let i = yield* e`
|
|
214
267
|
UPDATE invitations
|
|
215
268
|
SET "acceptedAt" = ${r}, "acceptedByUserId" = ${n}
|
|
@@ -221,7 +274,7 @@ var Xe = (e) => {
|
|
|
221
274
|
"acceptedAt", "acceptedByUserId", "revokedAt", "revokedByUserId", "createdAt"
|
|
222
275
|
`;
|
|
223
276
|
return i[0] ? { ...i[0] } : null;
|
|
224
|
-
}).pipe($.catchAll((e) => $.die(e))),
|
|
277
|
+
}).pipe($.catchAll((e) => $.die(e))), R = (t, n, r, i) => $.gen(function* () {
|
|
225
278
|
return (yield* e`
|
|
226
279
|
UPDATE invitations
|
|
227
280
|
SET "revokedAt" = ${i}, "revokedByUserId" = ${r}
|
|
@@ -231,20 +284,20 @@ var Xe = (e) => {
|
|
|
231
284
|
AND "revokedAt" IS NULL
|
|
232
285
|
RETURNING id
|
|
233
286
|
`).length > 0;
|
|
234
|
-
}).pipe($.catchAll((e) => $.die(e))),
|
|
287
|
+
}).pipe($.catchAll((e) => $.die(e))), z = (t) => $.gen(function* () {
|
|
235
288
|
return (yield* e`
|
|
236
289
|
SELECT id, "tokenHash", email, "tenantId", role, "invitedByUserId", "expiresAt",
|
|
237
290
|
"acceptedAt", "acceptedByUserId", "revokedAt", "revokedByUserId", "createdAt"
|
|
238
291
|
FROM invitations WHERE "tenantId" = ${t}
|
|
239
292
|
ORDER BY "createdAt" DESC
|
|
240
293
|
`).map((e) => ({ ...e }));
|
|
241
|
-
}).pipe($.orElseSucceed(() => [])),
|
|
294
|
+
}).pipe($.orElseSucceed(() => [])), B = (t, n) => $.gen(function* () {
|
|
242
295
|
return (yield* e`
|
|
243
296
|
SELECT COUNT(*)::int AS n FROM invitations
|
|
244
297
|
WHERE "tenantId" = ${t}
|
|
245
298
|
AND "acceptedAt" IS NULL AND "revokedAt" IS NULL AND "expiresAt" > ${n}
|
|
246
299
|
`)[0]?.n ?? 0;
|
|
247
|
-
}).pipe($.catchAll((e) => $.die(e))),
|
|
300
|
+
}).pipe($.catchAll((e) => $.die(e))), V = (t, n, r, i) => $.gen(function* () {
|
|
248
301
|
return (yield* e`
|
|
249
302
|
UPDATE invitations
|
|
250
303
|
SET "revokedAt" = ${i}, "revokedByUserId" = ${r}
|
|
@@ -254,7 +307,7 @@ var Xe = (e) => {
|
|
|
254
307
|
AND "revokedAt" IS NULL
|
|
255
308
|
RETURNING id
|
|
256
309
|
`).length;
|
|
257
|
-
}).pipe($.catchAll((e) => $.die(e))),
|
|
310
|
+
}).pipe($.catchAll((e) => $.die(e))), H = (t) => $.gen(function* () {
|
|
258
311
|
let n = /* @__PURE__ */ new Date();
|
|
259
312
|
return yield* e`
|
|
260
313
|
INSERT INTO "impersonationGrants" (
|
|
@@ -271,32 +324,32 @@ var Xe = (e) => {
|
|
|
271
324
|
endedAt: null,
|
|
272
325
|
endedReason: null
|
|
273
326
|
};
|
|
274
|
-
}).pipe($.catchAll((e) => $.die(e))),
|
|
327
|
+
}).pipe($.catchAll((e) => $.die(e))), U = (t) => $.gen(function* () {
|
|
275
328
|
let n = yield* e`
|
|
276
329
|
SELECT id, "sessionId", "actorUserId", "actorSessionId", "targetUserId", "tenantId",
|
|
277
330
|
reason, "startedAt", "expiresAt", "endedAt", "endedReason", "ipAddress", "userAgent"
|
|
278
331
|
FROM "impersonationGrants" WHERE "sessionId" = ${t} LIMIT 1
|
|
279
332
|
`;
|
|
280
333
|
return n[0] ? { ...n[0] } : null;
|
|
281
|
-
}).pipe($.orElseSucceed(() => null)),
|
|
334
|
+
}).pipe($.orElseSucceed(() => null)), W = (t, n, r) => $.gen(function* () {
|
|
282
335
|
return (yield* e`
|
|
283
336
|
UPDATE "impersonationGrants"
|
|
284
337
|
SET "endedAt" = ${r}, "endedReason" = ${n}
|
|
285
338
|
WHERE "sessionId" = ${t} AND "endedAt" IS NULL
|
|
286
339
|
RETURNING id
|
|
287
340
|
`).length > 0;
|
|
288
|
-
}).pipe($.catchAll((e) => $.die(e))),
|
|
341
|
+
}).pipe($.catchAll((e) => $.die(e))), G = (t) => $.gen(function* () {
|
|
289
342
|
return (yield* e`
|
|
290
343
|
SELECT id, "credentialId", "userId", "publicKey", counter, transports, "createdAt", "lastUsedAt"
|
|
291
344
|
FROM passkeys WHERE "userId" = ${t}
|
|
292
345
|
`).map((e) => ({ ...e }));
|
|
293
|
-
}).pipe($.orElseSucceed(() => [])),
|
|
346
|
+
}).pipe($.orElseSucceed(() => [])), K = (t) => $.gen(function* () {
|
|
294
347
|
let n = yield* e`
|
|
295
348
|
SELECT id, "credentialId", "userId", "publicKey", counter, transports, "createdAt", "lastUsedAt"
|
|
296
349
|
FROM passkeys WHERE "credentialId" = ${t} LIMIT 1
|
|
297
350
|
`;
|
|
298
351
|
return n[0] ? { ...n[0] } : null;
|
|
299
|
-
}).pipe($.orElseSucceed(() => null)),
|
|
352
|
+
}).pipe($.orElseSucceed(() => null)), q = (t) => $.gen(function* () {
|
|
300
353
|
let n = /* @__PURE__ */ new Date();
|
|
301
354
|
return yield* e`
|
|
302
355
|
INSERT INTO passkeys (id, "credentialId", "userId", "publicKey", counter, transports, "createdAt", "lastUsedAt")
|
|
@@ -313,7 +366,7 @@ var Xe = (e) => {
|
|
|
313
366
|
...t,
|
|
314
367
|
createdAt: /* @__PURE__ */ new Date(),
|
|
315
368
|
lastUsedAt: null
|
|
316
|
-
}))),
|
|
369
|
+
}))), J = (t, n) => $.gen(function* () {
|
|
317
370
|
return (yield* e`
|
|
318
371
|
UPDATE passkeys
|
|
319
372
|
SET counter = ${n}, "lastUsedAt" = ${/* @__PURE__ */ new Date()}
|
|
@@ -321,14 +374,14 @@ var Xe = (e) => {
|
|
|
321
374
|
AND counter < ${n}
|
|
322
375
|
RETURNING id
|
|
323
376
|
`).length > 0;
|
|
324
|
-
}).pipe($.orElseSucceed(() => !1)),
|
|
377
|
+
}).pipe($.orElseSucceed(() => !1)), Y = (t, n) => $.gen(function* () {
|
|
325
378
|
let r = /* @__PURE__ */ new Date();
|
|
326
379
|
yield* e`DELETE FROM "recoveryCodes" WHERE "userId" = ${t}`;
|
|
327
380
|
for (let i of n) yield* e`
|
|
328
381
|
INSERT INTO "recoveryCodes" (id, "userId", "codeHash", "consumedAt", "createdAt")
|
|
329
382
|
VALUES (${h("rc")}, ${t}, ${i}, ${null}, ${r})
|
|
330
383
|
`;
|
|
331
|
-
}).pipe($.asVoid, $.orElseSucceed(() => void 0)),
|
|
384
|
+
}).pipe($.asVoid, $.orElseSucceed(() => void 0)), X = (t, n) => $.gen(function* () {
|
|
332
385
|
return (yield* e`
|
|
333
386
|
UPDATE "recoveryCodes"
|
|
334
387
|
SET "consumedAt" = ${/* @__PURE__ */ new Date()}
|
|
@@ -337,50 +390,50 @@ var Xe = (e) => {
|
|
|
337
390
|
AND "consumedAt" IS NULL
|
|
338
391
|
RETURNING id
|
|
339
392
|
`).length > 0;
|
|
340
|
-
}).pipe($.orElseSucceed(() => !1)),
|
|
393
|
+
}).pipe($.orElseSucceed(() => !1)), Z = (t) => $.gen(function* () {
|
|
341
394
|
return (yield* e`
|
|
342
395
|
SELECT COUNT(*)::int AS n FROM "recoveryCodes"
|
|
343
396
|
WHERE "userId" = ${t} AND "consumedAt" IS NULL
|
|
344
397
|
`)[0]?.n ?? 0;
|
|
345
|
-
}).pipe($.orElseSucceed(() => 0)),
|
|
398
|
+
}).pipe($.orElseSucceed(() => 0)), Q = (e, t) => $.catchAll((n) => $.logWarning(`[auth] lockout ${e} failed — brute-force protection is not counting`).pipe($.annotateLogs("cause", String(n)), $.as(t)));
|
|
346
399
|
return {
|
|
347
|
-
findByEmail:
|
|
348
|
-
findById:
|
|
349
|
-
insert:
|
|
350
|
-
updatePassword:
|
|
351
|
-
setMfaSecret:
|
|
352
|
-
markMfaEnrolled:
|
|
353
|
-
clearMfa:
|
|
354
|
-
markEmailVerified:
|
|
355
|
-
listMemberships:
|
|
356
|
-
addMembership:
|
|
357
|
-
membershipRole:
|
|
358
|
-
listSessions:
|
|
359
|
-
insertSession:
|
|
360
|
-
findSession:
|
|
361
|
-
touchSession:
|
|
362
|
-
revokeSession:
|
|
363
|
-
revokeAllOtherSessions:
|
|
364
|
-
insertToken:
|
|
365
|
-
consumeToken:
|
|
366
|
-
latestToken:
|
|
367
|
-
insertInvitation:
|
|
368
|
-
findInvitationByHash:
|
|
369
|
-
acceptInvitation:
|
|
370
|
-
revokeInvitation:
|
|
371
|
-
listInvitations:
|
|
372
|
-
countPendingInvitations:
|
|
373
|
-
supersedePendingInvitations:
|
|
374
|
-
insertImpersonationGrant:
|
|
375
|
-
findImpersonationGrantBySession:
|
|
376
|
-
endImpersonationGrant:
|
|
377
|
-
replaceRecoveryCodes:
|
|
378
|
-
consumeRecoveryCode:
|
|
379
|
-
countRecoveryCodes:
|
|
380
|
-
listPasskeys:
|
|
381
|
-
findPasskey:
|
|
382
|
-
insertPasskey:
|
|
383
|
-
advancePasskeyCounter:
|
|
400
|
+
findByEmail: d,
|
|
401
|
+
findById: f,
|
|
402
|
+
insert: p,
|
|
403
|
+
updatePassword: g,
|
|
404
|
+
setMfaSecret: _,
|
|
405
|
+
markMfaEnrolled: v,
|
|
406
|
+
clearMfa: b,
|
|
407
|
+
markEmailVerified: S,
|
|
408
|
+
listMemberships: C,
|
|
409
|
+
addMembership: w,
|
|
410
|
+
membershipRole: T,
|
|
411
|
+
listSessions: E,
|
|
412
|
+
insertSession: D,
|
|
413
|
+
findSession: O,
|
|
414
|
+
touchSession: k,
|
|
415
|
+
revokeSession: A,
|
|
416
|
+
revokeAllOtherSessions: j,
|
|
417
|
+
insertToken: M,
|
|
418
|
+
consumeToken: N,
|
|
419
|
+
latestToken: P,
|
|
420
|
+
insertInvitation: F,
|
|
421
|
+
findInvitationByHash: I,
|
|
422
|
+
acceptInvitation: L,
|
|
423
|
+
revokeInvitation: R,
|
|
424
|
+
listInvitations: z,
|
|
425
|
+
countPendingInvitations: B,
|
|
426
|
+
supersedePendingInvitations: V,
|
|
427
|
+
insertImpersonationGrant: H,
|
|
428
|
+
findImpersonationGrantBySession: U,
|
|
429
|
+
endImpersonationGrant: W,
|
|
430
|
+
replaceRecoveryCodes: Y,
|
|
431
|
+
consumeRecoveryCode: X,
|
|
432
|
+
countRecoveryCodes: Z,
|
|
433
|
+
listPasskeys: G,
|
|
434
|
+
findPasskey: K,
|
|
435
|
+
insertPasskey: q,
|
|
436
|
+
advancePasskeyCounter: J,
|
|
384
437
|
isLockedOut: (t, n) => $.gen(function* () {
|
|
385
438
|
let r = (yield* e`
|
|
386
439
|
SELECT "lockedUntil" FROM "loginAttempts"
|
|
@@ -393,7 +446,7 @@ var Xe = (e) => {
|
|
|
393
446
|
locked: !1,
|
|
394
447
|
retryAfterSeconds: 0
|
|
395
448
|
};
|
|
396
|
-
}).pipe(
|
|
449
|
+
}).pipe(Q("read", {
|
|
397
450
|
locked: !1,
|
|
398
451
|
retryAfterSeconds: 0
|
|
399
452
|
})),
|
|
@@ -411,16 +464,16 @@ var Xe = (e) => {
|
|
|
411
464
|
"lockedUntil" = ${f},
|
|
412
465
|
"updatedAt" = ${p}
|
|
413
466
|
`;
|
|
414
|
-
}).pipe($.asVoid,
|
|
467
|
+
}).pipe($.asVoid, Q("record", void 0)),
|
|
415
468
|
clearLoginFailures: (t) => $.gen(function* () {
|
|
416
469
|
yield* e`DELETE FROM "loginAttempts" WHERE email = ${t.toLowerCase()}`;
|
|
417
|
-
}).pipe($.asVoid,
|
|
470
|
+
}).pipe($.asVoid, Q("clear", void 0))
|
|
418
471
|
};
|
|
419
|
-
},
|
|
472
|
+
}, et = (e) => (t) => $.runPromise(e.send({
|
|
420
473
|
to: t.to,
|
|
421
474
|
subject: t.subject,
|
|
422
475
|
html: t.html,
|
|
423
476
|
text: t.text
|
|
424
477
|
}).pipe($.asVoid, $.orElseSucceed(() => void 0)));
|
|
425
478
|
//#endregion
|
|
426
|
-
export {
|
|
479
|
+
export { He as CSRF_COOKIE_NAME, Ue as CSRF_HEADER_NAME, Oe as DEFAULT_INVITER_ROLES, ie as DEFAULT_ROLE_RANK, P as EMAIL_NOT_VERIFIED_CODE, Y as EMAIL_VERIFIED_METADATA_KEY, J as EMAIL_VERIFY_RESEND_COOLDOWN_S, Fe as EMAIL_VERIFY_TTL_S, Se as IMPERSONATION_DEFAULT_DURATION_S, le as IMPERSONATION_FORBIDDEN_SUBPATHS, oe as INVITATION_MAX_PENDING, be as INVITATION_TTL_S, Ie as MAGIC_LINK_TTL_S, Le as MFA_PENDING_TTL_S, Re as PASSWORD_RESET_TTL_S, e as PasswordEmptyError, t as PasswordHashError, s as SESSION_COOKIE_NAME, ue as TotpVerifyError, y as UserAlreadyExistsError, x as UserNotFoundError, Xe as authMemberships, Ee as authRoutesPlugin, c as clearSessionCookie, O as configSessionSecrets, Me as dataStoreChallengeStore, he as defaultCanGrantRole, X as emailVerificationActive, V as emailVerificationGuard, qe as generateChallenge, ee as generateRecoveryCodes, ye as generateTotpCode, Te as generateTotpSecret, ge as getAuthSessionStrategy, z as guardSubject, ce as handleAcceptInvitation, se as handleAcceptInvitationWithSignUp, Z as handleCreateInvitation, fe as handleCsrf, w as handleEmailVerifyConfirm, ae as handleEmailVerifyRequest, Q as handleImpersonationStart, ve as handleImpersonationStop, Ae as handleListInvitations, T as handleListMemberships, de as handleListSessions, L as handleMagicLinkConsume, R as handleMagicLinkRequest, B as handleMfaEnrollStart, A as handleMfaEnrollVerify, N as handleMfaRegenerateRecoveryCodes, I as handleMfaUnenroll, H as handleMfaVerify, U as handlePasskeyAssertOptions, D as handlePasskeyAssertVerify, je as handlePasskeyRegisterOptions, W as handlePasskeyRegisterVerify, Pe as handlePasswordResetConfirm, E as handlePasswordResetRequest, Ne as handlePreviewInvitation, K as handleRevokeAllOtherSessions, te as handleRevokeInvitation, M as handleRevokeSession, G as handleSignIn, q as handleSignOut, j as handleSignUp, F as handleSwitchTenant, n as hashPassword, ze as hashToken, we as impersonationAuditRedactor, ne as impersonationOf, We as isCsrfTokenWellFormed, De as isEmailVerified, pe as isImpersonated, Ge as issueCsrfToken, l as issueSession, xe as issueUserSession, et as mailSender, v as makeSessionRevocationChecker, k as memoryChallengeStore, _ as memoryUserStore, Be as mintSecret, Ve as mintToken, r as needsRehash, h as newAuthId, re as otpauthUrl, i as parseScryptParams, $e as postgresUserStore, u as readSession, d as readSessionKeyed, f as resolveSessionSecret, p as resolveSessionSecrets, ke as runSubjectGuards, _e as sendEmailVerification, b as sessionIdOfSubject, m as sessionSecretsOf, S as subjectFromUser, g as subjectMemberships, Ce as userEmailVerified, Je as verifyAssertion, Ke as verifyCsrf, a as verifyPassword, o as verifyPasswordWithRehash, Ye as verifyRegistration, me as verifyTotpCode, C as voltroPasswordStrategy };
|