@voltro/plugin-auth 0.36.0 → 0.38.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 +182 -0
- package/dist/index.d.ts +0 -3
- package/dist/index.js +9 -9
- package/dist/{plugin-BZm5Semm.js → plugin-CFDw0Lks.js} +283 -283
- package/dist/plugin.js +1 -1
- package/package.json +3 -3
|
@@ -8,83 +8,83 @@ import { createHmac as S, randomBytes as re, timingSafeEqual as ie } from "node:
|
|
|
8
8
|
import { Data as ae, Effect as C } from "effect";
|
|
9
9
|
import { buildSetCookie as oe, readCookie as se } from "@voltro/protocol/session";
|
|
10
10
|
import { registerRetention as ce, retentionTtlMsFromEnv as le } from "@voltro/database";
|
|
11
|
-
import { definePlugin as ue } from "@voltro/protocol";
|
|
11
|
+
import { IMPERSONATION_METADATA_KEY as w, definePlugin as ue, rawImpersonationMark as de } from "@voltro/protocol";
|
|
12
12
|
//#region src/subjectGuard.ts
|
|
13
|
-
var
|
|
13
|
+
var fe = { ok: !0 }, pe = (e, t) => C.gen(function* () {
|
|
14
14
|
for (let n of e) {
|
|
15
15
|
let e = yield* n(t);
|
|
16
16
|
if (!e.ok) return e;
|
|
17
17
|
}
|
|
18
|
-
return
|
|
19
|
-
}),
|
|
18
|
+
return fe;
|
|
19
|
+
}), T = 30, E = 6, me = 20, he = "sha1", ge = 1, D = class extends ae.TaggedError("TotpVerifyError") {}, O = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", _e = (e) => {
|
|
20
20
|
let t = 0, n = 0, r = "";
|
|
21
|
-
for (let i of e) for (n = n << 8 | i, t += 8; t >= 5;) r +=
|
|
22
|
-
return t > 0 && (r +=
|
|
23
|
-
},
|
|
21
|
+
for (let i of e) for (n = n << 8 | i, t += 8; t >= 5;) r += O[n >>> t - 5 & 31], t -= 5;
|
|
22
|
+
return t > 0 && (r += O[n << 5 - t & 31]), r;
|
|
23
|
+
}, ve = (e) => {
|
|
24
24
|
let t = e.toUpperCase().replace(/[\s=]+/g, "");
|
|
25
25
|
if (!/^[A-Z2-7]+$/.test(t)) return null;
|
|
26
26
|
let n = new Uint8Array(Math.floor(t.length * 5 / 8)), r = 0, i = 0, a = 0;
|
|
27
27
|
for (let e of t) {
|
|
28
|
-
let t =
|
|
28
|
+
let t = O.indexOf(e);
|
|
29
29
|
if (t === -1) return null;
|
|
30
30
|
i = i << 5 | t, r += 5, r >= 8 && (n[a++] = i >>> r - 8 & 255, r -= 8);
|
|
31
31
|
}
|
|
32
32
|
return n.subarray(0, a);
|
|
33
|
-
},
|
|
33
|
+
}, ye = (e) => {
|
|
34
34
|
let t = Buffer.alloc(8);
|
|
35
35
|
return t.writeBigUInt64BE(BigInt(e), 0), t;
|
|
36
|
-
},
|
|
37
|
-
let n = S(
|
|
38
|
-
n.update(
|
|
36
|
+
}, be = (e, t) => {
|
|
37
|
+
let n = S(he, Buffer.from(e));
|
|
38
|
+
n.update(ye(t));
|
|
39
39
|
let r = n.digest(), i = r[r.length - 1] & 15, a = (r[i] & 127) << 24 | (r[i + 1] & 255) << 16 | (r[i + 2] & 255) << 8 | r[i + 3] & 255;
|
|
40
|
-
return String(a % 10 **
|
|
41
|
-
},
|
|
40
|
+
return String(a % 10 ** E).padStart(E, "0");
|
|
41
|
+
}, xe = () => _e(re(me)), Se = (e) => `otpauth://totp/${encodeURIComponent(`${e.issuer}:${e.accountName}`)}?${new URLSearchParams({
|
|
42
42
|
secret: e.secret,
|
|
43
43
|
issuer: e.issuer,
|
|
44
44
|
algorithm: "SHA1",
|
|
45
|
-
digits: String(
|
|
46
|
-
period: String(
|
|
47
|
-
}).toString()}`,
|
|
48
|
-
let n =
|
|
49
|
-
return n ?
|
|
50
|
-
},
|
|
51
|
-
let r =
|
|
52
|
-
if (!r) return yield* C.fail(new
|
|
45
|
+
digits: String(E),
|
|
46
|
+
period: String(T)
|
|
47
|
+
}).toString()}`, Ce = (e, t = Date.now()) => {
|
|
48
|
+
let n = ve(e);
|
|
49
|
+
return n ? be(n, Math.floor(t / 1e3 / T)) : "000000";
|
|
50
|
+
}, we = (e, t, n = Date.now()) => C.gen(function* () {
|
|
51
|
+
let r = ve(e);
|
|
52
|
+
if (!r) return yield* C.fail(new D({ reason: "malformedSecret" }));
|
|
53
53
|
let i = t.replace(/\s+/g, "");
|
|
54
|
-
if (!/^[0-9]{6}$/.test(i)) return yield* C.fail(new
|
|
55
|
-
let a = Math.floor(n / 1e3 /
|
|
56
|
-
for (let e = -1; e <=
|
|
57
|
-
let t =
|
|
54
|
+
if (!/^[0-9]{6}$/.test(i)) return yield* C.fail(new D({ reason: "invalidCode" }));
|
|
55
|
+
let a = Math.floor(n / 1e3 / T), o = Buffer.from(i);
|
|
56
|
+
for (let e = -1; e <= ge; e++) {
|
|
57
|
+
let t = be(r, a + e), n = Buffer.from(t);
|
|
58
58
|
if (n.length === o.length && ie(n, o)) return !0;
|
|
59
59
|
}
|
|
60
|
-
return yield* C.fail(new
|
|
61
|
-
}),
|
|
60
|
+
return yield* C.fail(new D({ reason: "invalidCode" }));
|
|
61
|
+
}), Te = (e = 10) => {
|
|
62
62
|
let t = [];
|
|
63
63
|
for (let n = 0; n < e; n++) {
|
|
64
|
-
let e =
|
|
64
|
+
let e = _e(re(16)).slice(0, 25).match(/.{1,5}/g) ?? [];
|
|
65
65
|
t.push(e.join("-"));
|
|
66
66
|
}
|
|
67
67
|
return t;
|
|
68
|
-
},
|
|
68
|
+
}, Ee = 60, De = "email_not_verified", k = "emailVerified", Oe = (e) => e?.policy ?? "off", A = (e) => Oe(e) !== "off", j = (e, t) => {
|
|
69
69
|
if (e.emailVerifiedAt != null) return !0;
|
|
70
70
|
let n = t?.exemptAccountsCreatedBefore;
|
|
71
71
|
return n !== void 0 && e.createdAt.getTime() < n.getTime();
|
|
72
|
-
},
|
|
72
|
+
}, ke = (e) => {
|
|
73
73
|
if (e.type !== "user") return null;
|
|
74
|
-
let t = e.metadata?.[
|
|
74
|
+
let t = e.metadata?.[k];
|
|
75
75
|
return typeof t == "boolean" ? t : null;
|
|
76
|
-
},
|
|
77
|
-
let t =
|
|
78
|
-
return (n) => C.succeed(!t ||
|
|
76
|
+
}, Ae = (e) => {
|
|
77
|
+
let t = Oe(e) === "strict";
|
|
78
|
+
return (n) => C.succeed(!t || j(n, e) ? { ok: !0 } : {
|
|
79
79
|
ok: !1,
|
|
80
|
-
code:
|
|
80
|
+
code: De,
|
|
81
81
|
message: "This account's email address has not been confirmed yet. Request a new confirmation link and follow it, then sign in again."
|
|
82
82
|
});
|
|
83
|
-
},
|
|
83
|
+
}, M = (e, t) => ({
|
|
84
84
|
status: e,
|
|
85
85
|
body: JSON.stringify(t),
|
|
86
86
|
contentType: "application/json; charset=utf-8"
|
|
87
|
-
}),
|
|
87
|
+
}), je = (e, t, n) => `${e}${t}${t.includes("?") ? "&" : "?"}token=${encodeURIComponent(n)}`, N = (e, t, n) => C.gen(function* () {
|
|
88
88
|
let r = n.emailVerification, i = (n.now ?? Date.now)(), a = (r?.resendCooldownSeconds ?? 60) * 1e3;
|
|
89
89
|
if (a > 0) {
|
|
90
90
|
let n = yield* t.latestToken(e.id, "email-verify");
|
|
@@ -98,7 +98,7 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
98
98
|
purpose: "email-verify",
|
|
99
99
|
expiresAt: o.expiresAt
|
|
100
100
|
}).pipe(C.ignore), !n.sendEmail) return !1;
|
|
101
|
-
let s =
|
|
101
|
+
let s = je(n.appBaseUrl ?? "", r?.callbackPath ?? "/auth/verify-email/callback", o.token);
|
|
102
102
|
return yield* C.tryPromise(() => n.sendEmail({
|
|
103
103
|
to: e.email,
|
|
104
104
|
kind: "email-verify",
|
|
@@ -107,43 +107,43 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
107
107
|
text: `Confirm your email address: ${s}`,
|
|
108
108
|
html: `<p><a href="${s}">Confirm your email address</a> — this link expires in 24 hours.</p>`
|
|
109
109
|
})).pipe(C.ignore), !0;
|
|
110
|
-
}),
|
|
111
|
-
if (!e.email && !e.userId) return
|
|
110
|
+
}), P = (e, t, n) => C.gen(function* () {
|
|
111
|
+
if (!e.email && !e.userId) return M(400, { error: "email or userId required" });
|
|
112
112
|
let r = e.userId ? yield* t.findById(e.userId) : yield* t.findByEmail(e.email);
|
|
113
|
-
return r && !
|
|
114
|
-
}),
|
|
115
|
-
if (!e.token) return
|
|
113
|
+
return r && !j(r, n.emailVerification) && (yield* N(r, t, n)), M(202, { ok: !0 });
|
|
114
|
+
}), Me = (e, t) => C.gen(function* () {
|
|
115
|
+
if (!e.token) return M(400, { error: "token required" });
|
|
116
116
|
let n = yield* t.consumeToken(h(e.token), "email-verify");
|
|
117
|
-
if (!n) return
|
|
117
|
+
if (!n) return M(401, { error: "invalid or expired token" });
|
|
118
118
|
let r = yield* t.findById(n.userId);
|
|
119
|
-
return r ? (yield* t.markEmailVerified(r.id).pipe(C.ignore),
|
|
119
|
+
return r ? (yield* t.markEmailVerified(r.id).pipe(C.ignore), M(200, {
|
|
120
120
|
ok: !0,
|
|
121
121
|
verified: !0
|
|
122
|
-
})) :
|
|
123
|
-
}),
|
|
124
|
-
maxAttempts: e.lockout?.maxAttempts ??
|
|
125
|
-
windowMs: (e.lockout?.windowSeconds ??
|
|
126
|
-
lockMs: (e.lockout?.lockSeconds ??
|
|
127
|
-
}),
|
|
122
|
+
})) : M(401, { error: "invalid or expired token" });
|
|
123
|
+
}), Ne = 5, Pe = 900, Fe = 900, Ie = (e) => ({
|
|
124
|
+
maxAttempts: e.lockout?.maxAttempts ?? Ne,
|
|
125
|
+
windowMs: (e.lockout?.windowSeconds ?? Pe) * 1e3,
|
|
126
|
+
lockMs: (e.lockout?.lockSeconds ?? Fe) * 1e3
|
|
127
|
+
}), F = (e) => e.secrets ?? (e.secret === void 0 ? c() : l(e.secret)), Le = (e) => e.secret ?? s(), I = (e, t, n = {}) => ({
|
|
128
128
|
status: e,
|
|
129
129
|
body: JSON.stringify(t),
|
|
130
130
|
contentType: "application/json; charset=utf-8",
|
|
131
131
|
...n
|
|
132
|
-
}),
|
|
132
|
+
}), L = (e, t = {}) => ({
|
|
133
133
|
status: 302,
|
|
134
134
|
body: "",
|
|
135
135
|
contentType: "text/plain",
|
|
136
136
|
location: e,
|
|
137
137
|
...t
|
|
138
|
-
}),
|
|
138
|
+
}), Re = 3600 * 24 * 7, ze = (e, t) => e.type === "user" ? {
|
|
139
139
|
...e,
|
|
140
140
|
metadata: {
|
|
141
141
|
...e.metadata ?? {},
|
|
142
142
|
sessionId: t
|
|
143
143
|
}
|
|
144
|
-
} : e,
|
|
144
|
+
} : e, R = (e, t, n, r = {}) => C.gen(function* () {
|
|
145
145
|
r.clearLoginFailures !== !1 && (yield* t.clearLoginFailures(e.email));
|
|
146
|
-
let i = yield* t.listMemberships(e.id), o = r.sessionId ?? u("sess"), s = r.ttlSeconds ??
|
|
146
|
+
let i = yield* t.listMemberships(e.id), o = r.sessionId ?? u("sess"), s = r.ttlSeconds ?? Re;
|
|
147
147
|
r.sessionRow !== "existing" && (yield* t.insertSession({
|
|
148
148
|
id: o,
|
|
149
149
|
userId: e.id,
|
|
@@ -153,31 +153,31 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
153
153
|
userAgent: r.userAgent ?? null
|
|
154
154
|
}).pipe(C.ignore));
|
|
155
155
|
let c = { ...r.metadata };
|
|
156
|
-
|
|
157
|
-
let l =
|
|
156
|
+
A(n.emailVerification) && (c[k] = j(e, n.emailVerification));
|
|
157
|
+
let l = ze(p(e, {
|
|
158
158
|
memberships: i,
|
|
159
159
|
...Object.keys(c).length > 0 ? { metadata: c } : {}
|
|
160
160
|
}), o);
|
|
161
161
|
return {
|
|
162
|
-
setCookie: a(l,
|
|
162
|
+
setCookie: a(l, F(n), {
|
|
163
163
|
ttlSeconds: s,
|
|
164
164
|
...n.cookieDomain ? { domain: n.cookieDomain } : {},
|
|
165
165
|
secure: n.cookieSecure ?? !0
|
|
166
166
|
}).setCookie,
|
|
167
167
|
subject: l
|
|
168
168
|
};
|
|
169
|
-
}),
|
|
169
|
+
}), z = (e, t) => C.gen(function* () {
|
|
170
170
|
let n = t.subjectGuards ?? [];
|
|
171
171
|
if (n.length === 0) return null;
|
|
172
|
-
let r = yield*
|
|
173
|
-
return r.ok ? null :
|
|
172
|
+
let r = yield* pe(n, e);
|
|
173
|
+
return r.ok ? null : I(403, {
|
|
174
174
|
error: r.code,
|
|
175
175
|
message: r.message
|
|
176
176
|
});
|
|
177
|
-
}),
|
|
178
|
-
if (!r.email || !r.password) return
|
|
177
|
+
}), Be = (r, i, a) => C.gen(function* () {
|
|
178
|
+
if (!r.email || !r.password) return I(400, { error: "email and password required" });
|
|
179
179
|
let o = yield* i.findByEmail(r.email), s = (a.now ?? Date.now)(), c = yield* i.isLockedOut(r.email, s);
|
|
180
|
-
if (c.locked) return
|
|
180
|
+
if (c.locked) return I(429, {
|
|
181
181
|
error: "account_locked",
|
|
182
182
|
retryAfterSeconds: c.retryAfterSeconds
|
|
183
183
|
});
|
|
@@ -185,8 +185,8 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
185
185
|
let n = yield* e("decoy-not-a-real-password").pipe(C.orElseSucceed(() => ""));
|
|
186
186
|
return yield* t(r.password, n), { valid: !1 };
|
|
187
187
|
});
|
|
188
|
-
if (!o || !d.valid) return yield* i.recordLoginFailure(r.email, s,
|
|
189
|
-
let f = yield*
|
|
188
|
+
if (!o || !d.valid) return yield* i.recordLoginFailure(r.email, s, Ie(a)), I(401, { error: "invalid credentials" });
|
|
189
|
+
let f = yield* z(o, a);
|
|
190
190
|
if (f) return f;
|
|
191
191
|
if (d.rehash && (yield* i.updatePassword(o.id, d.rehash).pipe(C.ignore)), o.mfaEnrolledAt) {
|
|
192
192
|
let e = _("mfa-pending", 300);
|
|
@@ -196,48 +196,48 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
196
196
|
userId: o.id,
|
|
197
197
|
purpose: "mfa-pending",
|
|
198
198
|
expiresAt: e.expiresAt
|
|
199
|
-
}).pipe(C.ignore),
|
|
199
|
+
}).pipe(C.ignore), I(200, {
|
|
200
200
|
ok: !0,
|
|
201
201
|
mfaRequired: !0,
|
|
202
202
|
pendingToken: e.token,
|
|
203
203
|
expiresInSeconds: 300
|
|
204
204
|
});
|
|
205
205
|
}
|
|
206
|
-
let { setCookie: p, subject: m } = yield*
|
|
206
|
+
let { setCookie: p, subject: m } = yield* R(o, i, a, {
|
|
207
207
|
ipAddress: r.ipAddress ?? null,
|
|
208
208
|
userAgent: r.userAgent ?? null
|
|
209
209
|
});
|
|
210
|
-
return r.redirectAfter ?
|
|
210
|
+
return r.redirectAfter ? L(a.successRedirect ?? "/", { setCookie: p }) : I(200, {
|
|
211
211
|
ok: !0,
|
|
212
212
|
subject: m
|
|
213
213
|
}, { setCookie: p });
|
|
214
|
-
}),
|
|
215
|
-
if (!e.pendingToken) return
|
|
216
|
-
if (!e.code && !e.recoveryCode) return
|
|
214
|
+
}), Ve = (e, t, n) => C.gen(function* () {
|
|
215
|
+
if (!e.pendingToken) return I(400, { error: "pending token required" });
|
|
216
|
+
if (!e.code && !e.recoveryCode) return I(400, { error: "code or recoveryCode required" });
|
|
217
217
|
let r = yield* t.consumeToken(h(e.pendingToken), "mfa-pending");
|
|
218
|
-
if (!r) return
|
|
218
|
+
if (!r) return I(401, { error: "invalid or expired challenge" });
|
|
219
219
|
let i = yield* t.findById(r.userId);
|
|
220
|
-
if (!i || !i.mfaEnrolledAt || !i.mfaSecret) return
|
|
220
|
+
if (!i || !i.mfaEnrolledAt || !i.mfaSecret) return I(401, { error: "mfa not enrolled" });
|
|
221
221
|
let a = (n.now ?? Date.now)(), o = yield* t.isLockedOut(i.email, a);
|
|
222
|
-
if (o.locked) return
|
|
222
|
+
if (o.locked) return I(429, {
|
|
223
223
|
error: "account_locked",
|
|
224
224
|
retryAfterSeconds: o.retryAfterSeconds
|
|
225
225
|
});
|
|
226
|
-
let s = yield*
|
|
226
|
+
let s = yield* z(i, n);
|
|
227
227
|
if (s) return s;
|
|
228
|
-
if (!(e.recoveryCode ? yield* t.consumeRecoveryCode(i.id, h(e.recoveryCode.trim())) : yield*
|
|
229
|
-
let { setCookie: c, subject: l } = yield*
|
|
228
|
+
if (!(e.recoveryCode ? yield* t.consumeRecoveryCode(i.id, h(e.recoveryCode.trim())) : yield* we(i.mfaSecret, e.code ?? "").pipe(C.map(() => !0), C.catchTag("TotpVerifyError", () => C.succeed(!1))))) return yield* t.recordLoginFailure(i.email, a, Ie(n)), I(401, { error: "invalid_code" });
|
|
229
|
+
let { setCookie: c, subject: l } = yield* R(i, t, n, {
|
|
230
230
|
ipAddress: e.ipAddress ?? null,
|
|
231
231
|
userAgent: e.userAgent ?? null
|
|
232
232
|
});
|
|
233
|
-
return e.redirectAfter ?
|
|
233
|
+
return e.redirectAfter ? L(n.successRedirect ?? "/", { setCookie: c }) : I(200, {
|
|
234
234
|
ok: !0,
|
|
235
235
|
subject: l
|
|
236
236
|
}, { setCookie: c });
|
|
237
|
-
}),
|
|
238
|
-
if (!t.email || !t.password) return
|
|
239
|
-
if (t.password.length < 8) return
|
|
240
|
-
if (yield* n.findByEmail(t.email)) return
|
|
237
|
+
}), He = (t, n, r) => C.gen(function* () {
|
|
238
|
+
if (!t.email || !t.password) return I(400, { error: "email and password required" });
|
|
239
|
+
if (t.password.length < 8) return I(400, { error: "password must be at least 8 characters" });
|
|
240
|
+
if (yield* n.findByEmail(t.email)) return I(409, { error: "email already registered" });
|
|
241
241
|
let i = t.tenantId ?? r.defaultTenantId, a = yield* e(t.password), o = yield* n.insert({
|
|
242
242
|
id: u("user"),
|
|
243
243
|
email: t.email,
|
|
@@ -248,16 +248,16 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
248
248
|
userId: o.id,
|
|
249
249
|
tenantId: i,
|
|
250
250
|
role: "owner"
|
|
251
|
-
}).pipe(C.ignore),
|
|
252
|
-
let { setCookie: s, subject: c } = yield*
|
|
253
|
-
return t.redirectAfter ?
|
|
251
|
+
}).pipe(C.ignore), A(r.emailVerification) && (r.emailVerification?.sendOnSignUp ?? !0) && (yield* N(o, n, r).pipe(C.ignore));
|
|
252
|
+
let { setCookie: s, subject: c } = yield* R(o, n, r);
|
|
253
|
+
return t.redirectAfter ? L(r.successRedirect ?? "/", { setCookie: s }) : I(200, {
|
|
254
254
|
ok: !0,
|
|
255
255
|
subject: c
|
|
256
256
|
}, { setCookie: s });
|
|
257
|
-
}).pipe(C.catchAll((e) => C.succeed(
|
|
257
|
+
}).pipe(C.catchAll((e) => C.succeed(I(500, {
|
|
258
258
|
error: "signup_failed",
|
|
259
259
|
cause: String(e)
|
|
260
|
-
})))),
|
|
260
|
+
})))), Ue = (e) => ({
|
|
261
261
|
status: 302,
|
|
262
262
|
body: "",
|
|
263
263
|
location: e.successRedirect ?? "/",
|
|
@@ -265,58 +265,58 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
265
265
|
...e.cookieDomain ? { domain: e.cookieDomain } : {},
|
|
266
266
|
secure: e.cookieSecure ?? !0
|
|
267
267
|
})
|
|
268
|
-
}),
|
|
268
|
+
}), We = (e, t) => C.gen(function* () {
|
|
269
269
|
let n = yield* t.findById(e.userId);
|
|
270
|
-
if (!n) return
|
|
271
|
-
let r =
|
|
272
|
-
return yield* t.setMfaSecret(n.id, r).pipe(C.catchAll(() => C.succeed(n))),
|
|
270
|
+
if (!n) return I(404, { error: "user_not_found" });
|
|
271
|
+
let r = xe();
|
|
272
|
+
return yield* t.setMfaSecret(n.id, r).pipe(C.catchAll(() => C.succeed(n))), I(200, {
|
|
273
273
|
ok: !0,
|
|
274
274
|
secret: r,
|
|
275
|
-
otpauthUrl:
|
|
275
|
+
otpauthUrl: Se({
|
|
276
276
|
issuer: e.issuer,
|
|
277
277
|
accountName: e.accountName,
|
|
278
278
|
secret: r
|
|
279
279
|
})
|
|
280
280
|
});
|
|
281
|
-
}),
|
|
281
|
+
}), Ge = (e, t) => C.gen(function* () {
|
|
282
282
|
let n = yield* t.findById(e.userId);
|
|
283
|
-
if (!n) return
|
|
284
|
-
if (!n.mfaSecret) return
|
|
285
|
-
if (n.mfaEnrolledAt) return
|
|
286
|
-
if (!(yield*
|
|
283
|
+
if (!n) return I(404, { error: "user_not_found" });
|
|
284
|
+
if (!n.mfaSecret) return I(400, { error: "no_enrollment_in_progress" });
|
|
285
|
+
if (n.mfaEnrolledAt) return I(409, { error: "already_enrolled" });
|
|
286
|
+
if (!(yield* we(n.mfaSecret, e.code).pipe(C.map(() => !0), C.catchTag("TotpVerifyError", () => C.succeed(!1))))) return I(401, { error: "invalid_code" });
|
|
287
287
|
yield* t.markMfaEnrolled(n.id).pipe(C.catchAll(() => C.succeed(n)));
|
|
288
|
-
let r =
|
|
289
|
-
return yield* t.replaceRecoveryCodes(n.id, r.map((e) => h(e))).pipe(C.ignore),
|
|
288
|
+
let r = Te();
|
|
289
|
+
return yield* t.replaceRecoveryCodes(n.id, r.map((e) => h(e))).pipe(C.ignore), I(200, {
|
|
290
290
|
ok: !0,
|
|
291
291
|
enrolled: !0,
|
|
292
292
|
recoveryCodes: r
|
|
293
293
|
});
|
|
294
|
-
}),
|
|
294
|
+
}), Ke = (e, t) => C.gen(function* () {
|
|
295
295
|
let n = yield* t.findById(e.userId);
|
|
296
|
-
if (!n) return
|
|
297
|
-
if (!n.mfaEnrolledAt) return
|
|
298
|
-
let r =
|
|
299
|
-
return yield* t.replaceRecoveryCodes(n.id, r.map((e) => h(e))).pipe(C.ignore),
|
|
296
|
+
if (!n) return I(404, { error: "user_not_found" });
|
|
297
|
+
if (!n.mfaEnrolledAt) return I(400, { error: "mfa_not_enrolled" });
|
|
298
|
+
let r = Te();
|
|
299
|
+
return yield* t.replaceRecoveryCodes(n.id, r.map((e) => h(e))).pipe(C.ignore), I(200, {
|
|
300
300
|
ok: !0,
|
|
301
301
|
recoveryCodes: r
|
|
302
302
|
});
|
|
303
|
-
}),
|
|
303
|
+
}), qe = (e, t) => C.gen(function* () {
|
|
304
304
|
let n = yield* t.findById(e.userId);
|
|
305
|
-
return n ? (yield* t.clearMfa(n.id).pipe(C.catchAll(() => C.succeed(n))), yield* t.replaceRecoveryCodes(n.id, []).pipe(C.ignore),
|
|
305
|
+
return n ? (yield* t.clearMfa(n.id).pipe(C.catchAll(() => C.succeed(n))), yield* t.replaceRecoveryCodes(n.id, []).pipe(C.ignore), I(200, {
|
|
306
306
|
ok: !0,
|
|
307
307
|
enrolled: !1
|
|
308
|
-
})) :
|
|
309
|
-
}),
|
|
310
|
-
let t = b(
|
|
308
|
+
})) : I(404, { error: "user_not_found" });
|
|
309
|
+
}), Je = (e) => {
|
|
310
|
+
let t = b(Le(e)), n = oe(v, t, {
|
|
311
311
|
httpOnly: !1,
|
|
312
312
|
sameSite: "lax",
|
|
313
313
|
secure: e.cookieSecure ?? !0,
|
|
314
314
|
...e.cookieDomain ? { domain: e.cookieDomain } : {},
|
|
315
315
|
path: "/"
|
|
316
316
|
});
|
|
317
|
-
return
|
|
318
|
-
},
|
|
319
|
-
if (!e.email) return
|
|
317
|
+
return I(200, { csrfToken: t }, { setCookie: n });
|
|
318
|
+
}, Ye = (e, t, n) => `${e}${t}${t.includes("?") ? "&" : "?"}token=${encodeURIComponent(n)}`, Xe = (e, t, n) => C.gen(function* () {
|
|
319
|
+
if (!e.email) return I(400, { error: "email required" });
|
|
320
320
|
let r = yield* t.findByEmail(e.email);
|
|
321
321
|
if (r) {
|
|
322
322
|
let i = _("magic-link");
|
|
@@ -327,7 +327,7 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
327
327
|
purpose: "magic-link",
|
|
328
328
|
expiresAt: i.expiresAt
|
|
329
329
|
}).pipe(C.ignore);
|
|
330
|
-
let a =
|
|
330
|
+
let a = Ye(n.appBaseUrl ?? "", e.callbackPath ?? "/auth/magic-link/callback", i.token);
|
|
331
331
|
n.sendEmail && (yield* C.tryPromise(() => n.sendEmail({
|
|
332
332
|
to: r.email,
|
|
333
333
|
kind: "magic-link",
|
|
@@ -337,22 +337,22 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
337
337
|
html: `<p><a href="${a}">Sign in</a> — this link expires shortly.</p>`
|
|
338
338
|
})).pipe(C.ignore));
|
|
339
339
|
}
|
|
340
|
-
return
|
|
341
|
-
}),
|
|
342
|
-
if (!e.token) return
|
|
340
|
+
return I(202, { ok: !0 });
|
|
341
|
+
}), Ze = (e, t, n) => C.gen(function* () {
|
|
342
|
+
if (!e.token) return I(400, { error: "token required" });
|
|
343
343
|
let r = yield* t.consumeToken(h(e.token), "magic-link");
|
|
344
|
-
if (!r) return
|
|
344
|
+
if (!r) return I(401, { error: "invalid or expired token" });
|
|
345
345
|
let i = yield* t.findById(r.userId);
|
|
346
|
-
if (!i) return
|
|
347
|
-
let a = yield* t.markEmailVerified(i.id).pipe(C.orElseSucceed(() => i)), o = yield*
|
|
346
|
+
if (!i) return I(401, { error: "invalid or expired token" });
|
|
347
|
+
let a = yield* t.markEmailVerified(i.id).pipe(C.orElseSucceed(() => i)), o = yield* z(a, n);
|
|
348
348
|
if (o) return o;
|
|
349
|
-
let { setCookie: s, subject: c } = yield*
|
|
350
|
-
return e.redirectAfter ?
|
|
349
|
+
let { setCookie: s, subject: c } = yield* R(a, t, n);
|
|
350
|
+
return e.redirectAfter ? L(n.successRedirect ?? "/", { setCookie: s }) : I(200, {
|
|
351
351
|
ok: !0,
|
|
352
352
|
subject: c
|
|
353
353
|
}, { setCookie: s });
|
|
354
|
-
}),
|
|
355
|
-
if (!e.email) return
|
|
354
|
+
}), Qe = (e, t, n) => C.gen(function* () {
|
|
355
|
+
if (!e.email) return I(400, { error: "email required" });
|
|
356
356
|
let r = yield* t.findByEmail(e.email);
|
|
357
357
|
if (r) {
|
|
358
358
|
let i = _("password-reset");
|
|
@@ -363,7 +363,7 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
363
363
|
purpose: "password-reset",
|
|
364
364
|
expiresAt: i.expiresAt
|
|
365
365
|
}).pipe(C.ignore);
|
|
366
|
-
let a =
|
|
366
|
+
let a = Ye(n.appBaseUrl ?? "", e.callbackPath ?? "/auth/password-reset/callback", i.token);
|
|
367
367
|
n.sendEmail && (yield* C.tryPromise(() => n.sendEmail({
|
|
368
368
|
to: r.email,
|
|
369
369
|
kind: "password-reset",
|
|
@@ -373,16 +373,16 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
373
373
|
html: `<p><a href="${a}">Reset your password</a> — this link expires shortly.</p>`
|
|
374
374
|
})).pipe(C.ignore));
|
|
375
375
|
}
|
|
376
|
-
return
|
|
377
|
-
}),
|
|
378
|
-
if (!t.token || !t.newPassword) return
|
|
379
|
-
if (t.newPassword.length < 8) return
|
|
376
|
+
return I(202, { ok: !0 });
|
|
377
|
+
}), $e = (t, n) => C.gen(function* () {
|
|
378
|
+
if (!t.token || !t.newPassword) return I(400, { error: "token and newPassword required" });
|
|
379
|
+
if (t.newPassword.length < 8) return I(400, { error: "password must be at least 8 characters" });
|
|
380
380
|
let r = yield* n.consumeToken(h(t.token), "password-reset");
|
|
381
|
-
if (!r) return
|
|
381
|
+
if (!r) return I(401, { error: "invalid or expired token" });
|
|
382
382
|
let i = yield* e(t.newPassword).pipe(C.orElseSucceed(() => ""));
|
|
383
|
-
return i ? (yield* n.updatePassword(r.userId, i).pipe(C.ignore), yield* n.markEmailVerified(r.userId).pipe(C.ignore), yield* n.revokeAllOtherSessions(r.userId, "__none__").pipe(C.ignore),
|
|
384
|
-
}),
|
|
385
|
-
return
|
|
383
|
+
return i ? (yield* n.updatePassword(r.userId, i).pipe(C.ignore), yield* n.markEmailVerified(r.userId).pipe(C.ignore), yield* n.revokeAllOtherSessions(r.userId, "__none__").pipe(C.ignore), I(200, { ok: !0 })) : I(500, { error: "hash_failed" });
|
|
384
|
+
}), et = (e, t) => C.gen(function* () {
|
|
385
|
+
return I(200, { sessions: (yield* t.listSessions(e.userId)).map((e) => ({
|
|
386
386
|
id: e.id,
|
|
387
387
|
tenantId: e.tenantId,
|
|
388
388
|
ipAddress: e.ipAddress ?? null,
|
|
@@ -391,48 +391,48 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
391
391
|
lastSeenAt: e.lastSeenAt.toISOString(),
|
|
392
392
|
expiresAt: e.expiresAt.toISOString()
|
|
393
393
|
})) });
|
|
394
|
-
}),
|
|
395
|
-
return (yield* t.revokeSession(e.userId, e.sessionId)) ?
|
|
394
|
+
}), tt = (e, t) => C.gen(function* () {
|
|
395
|
+
return (yield* t.revokeSession(e.userId, e.sessionId)) ? I(200, {
|
|
396
396
|
ok: !0,
|
|
397
397
|
revoked: 1
|
|
398
|
-
}) :
|
|
399
|
-
}),
|
|
400
|
-
return
|
|
398
|
+
}) : I(404, { error: "session_not_found" });
|
|
399
|
+
}), nt = (e, t) => C.gen(function* () {
|
|
400
|
+
return I(200, {
|
|
401
401
|
ok: !0,
|
|
402
402
|
revoked: yield* t.revokeAllOtherSessions(e.userId, e.keepSessionId)
|
|
403
403
|
});
|
|
404
|
-
}),
|
|
404
|
+
}), rt = (e, t, n, i) => C.gen(function* () {
|
|
405
405
|
let o = yield* t.findById(e.userId);
|
|
406
|
-
if (!o) return
|
|
406
|
+
if (!o) return I(404, { error: "user_not_found" });
|
|
407
407
|
let s = yield* t.membershipRole(e.userId, e.targetTenantId);
|
|
408
|
-
if (s === null) return
|
|
408
|
+
if (s === null) return I(403, { error: "not a member of the target tenant" });
|
|
409
409
|
let c = yield* t.listMemberships(o.id), l = e.metadata === void 0 ? void 0 : Object.fromEntries(Object.entries(e.metadata).filter(([e]) => e !== "memberships")), u = p(o, {
|
|
410
410
|
tenantId: e.targetTenantId,
|
|
411
411
|
memberships: c,
|
|
412
412
|
...l === void 0 ? {} : { metadata: l }
|
|
413
|
-
}), d = e.sessionId ?
|
|
414
|
-
ttlSeconds:
|
|
413
|
+
}), d = e.sessionId ? ze(u, e.sessionId) : u, f = a(d, F(n), {
|
|
414
|
+
ttlSeconds: Re,
|
|
415
415
|
...n.cookieDomain ? { domain: n.cookieDomain } : {},
|
|
416
416
|
secure: n.cookieSecure ?? !0
|
|
417
417
|
});
|
|
418
|
-
return e.clientId !== void 0 && i && i(e.clientId, { cookies: { [r]: f.value } }),
|
|
418
|
+
return e.clientId !== void 0 && i && i(e.clientId, { cookies: { [r]: f.value } }), I(200, {
|
|
419
419
|
ok: !0,
|
|
420
420
|
tenantId: e.targetTenantId,
|
|
421
421
|
role: s,
|
|
422
422
|
subject: d
|
|
423
423
|
}, { setCookie: f.setCookie });
|
|
424
|
-
}),
|
|
425
|
-
return
|
|
424
|
+
}), it = (e, t) => C.gen(function* () {
|
|
425
|
+
return I(200, { memberships: (yield* t.listMemberships(e.userId)).map((e) => ({
|
|
426
426
|
tenantId: e.tenantId,
|
|
427
427
|
role: e.role,
|
|
428
428
|
joinedAt: e.joinedAt.toISOString()
|
|
429
429
|
})) });
|
|
430
|
-
}),
|
|
430
|
+
}), B = (e, t, n = {}) => ({
|
|
431
431
|
status: e,
|
|
432
432
|
body: JSON.stringify(t),
|
|
433
433
|
contentType: "application/json; charset=utf-8",
|
|
434
434
|
...n
|
|
435
|
-
}),
|
|
435
|
+
}), at = 3600 * 24 * 7, ot = () => {
|
|
436
436
|
let e = /* @__PURE__ */ new Map();
|
|
437
437
|
return {
|
|
438
438
|
put: (t, n, r) => C.sync(() => {
|
|
@@ -446,7 +446,7 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
446
446
|
return e.delete(t), !n || n.expiresAt < Date.now() ? null : n.challenge;
|
|
447
447
|
})
|
|
448
448
|
};
|
|
449
|
-
},
|
|
449
|
+
}, st = (e) => ({
|
|
450
450
|
put: (t, n, r) => C.gen(function* () {
|
|
451
451
|
let i = /* @__PURE__ */ new Date(), a = new Date(i.getTime() + r * 1e3);
|
|
452
452
|
(yield* e`
|
|
@@ -466,12 +466,12 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
466
466
|
`)[0];
|
|
467
467
|
return n && n.expiresAt.getTime() > Date.now() ? n.challenge : null;
|
|
468
468
|
}).pipe(C.orElseSucceed(() => null))
|
|
469
|
-
}),
|
|
470
|
-
if (!(yield* t.findById(e.userId))) return
|
|
469
|
+
}), V = 300, ct = (e, t, n, r) => C.gen(function* () {
|
|
470
|
+
if (!(yield* t.findById(e.userId))) return B(404, { error: "user_not_found" });
|
|
471
471
|
let i = x();
|
|
472
|
-
yield* n.put(`${e.userId}:register`, i,
|
|
472
|
+
yield* n.put(`${e.userId}:register`, i, V);
|
|
473
473
|
let a = yield* t.listPasskeys(e.userId);
|
|
474
|
-
return
|
|
474
|
+
return B(200, {
|
|
475
475
|
challenge: i,
|
|
476
476
|
rp: {
|
|
477
477
|
id: r.rpId,
|
|
@@ -497,12 +497,12 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
497
497
|
userVerification: "preferred",
|
|
498
498
|
residentKey: "preferred"
|
|
499
499
|
},
|
|
500
|
-
timeout:
|
|
500
|
+
timeout: V * 1e3
|
|
501
501
|
});
|
|
502
|
-
}),
|
|
503
|
-
if (!(yield* t.findById(e.userId))) return
|
|
502
|
+
}), lt = (e, t, n, r) => C.gen(function* () {
|
|
503
|
+
if (!(yield* t.findById(e.userId))) return B(404, { error: "user_not_found" });
|
|
504
504
|
let i = yield* n.take(`${e.userId}:register`);
|
|
505
|
-
if (!i) return
|
|
505
|
+
if (!i) return B(400, { error: "no_pending_challenge" });
|
|
506
506
|
let a = ne({
|
|
507
507
|
clientDataJSON: e.clientDataJSON,
|
|
508
508
|
authenticatorData: e.authenticatorData,
|
|
@@ -517,29 +517,29 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
517
517
|
publicKey: a.result.publicKey,
|
|
518
518
|
counter: a.result.counter,
|
|
519
519
|
transports: e.transports ?? null
|
|
520
|
-
}).pipe(C.ignore),
|
|
520
|
+
}).pipe(C.ignore), B(200, {
|
|
521
521
|
ok: !0,
|
|
522
522
|
credentialId: a.result.credentialId
|
|
523
|
-
})) :
|
|
524
|
-
}),
|
|
523
|
+
})) : B(400, { error: a.error });
|
|
524
|
+
}), ut = (e, t, n, r) => C.gen(function* () {
|
|
525
525
|
let i = x(), a = e.userId ? `${e.userId}:assert` : "*:assert";
|
|
526
|
-
yield* n.put(a, i,
|
|
526
|
+
yield* n.put(a, i, V);
|
|
527
527
|
let o = e.userId ? (yield* t.listPasskeys(e.userId)).map((e) => ({
|
|
528
528
|
type: "public-key",
|
|
529
529
|
id: e.credentialId
|
|
530
530
|
})) : [];
|
|
531
|
-
return
|
|
531
|
+
return B(200, {
|
|
532
532
|
challenge: i,
|
|
533
533
|
rpId: r.rpId,
|
|
534
534
|
allowCredentials: o,
|
|
535
535
|
userVerification: "preferred",
|
|
536
|
-
timeout:
|
|
536
|
+
timeout: V * 1e3
|
|
537
537
|
});
|
|
538
|
-
}),
|
|
538
|
+
}), dt = (e, t, n, r, i) => C.gen(function* () {
|
|
539
539
|
let o = yield* t.findPasskey(e.credentialId);
|
|
540
|
-
if (!o) return
|
|
540
|
+
if (!o) return B(401, { error: "unknown_credential" });
|
|
541
541
|
let s = e.userId ? `${e.userId}:assert` : "*:assert", c = yield* n.take(s);
|
|
542
|
-
if (!c) return
|
|
542
|
+
if (!c) return B(400, { error: "no_pending_challenge" });
|
|
543
543
|
let l = te({
|
|
544
544
|
clientDataJSON: e.clientDataJSON,
|
|
545
545
|
authenticatorData: e.authenticatorData,
|
|
@@ -550,18 +550,18 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
550
550
|
storedPublicKey: o.publicKey,
|
|
551
551
|
storedCounter: o.counter
|
|
552
552
|
});
|
|
553
|
-
if (!l.ok) return
|
|
554
|
-
if (!(yield* t.advancePasskeyCounter(e.credentialId, l.result.newCounter)) && l.result.newCounter !== 0) return
|
|
553
|
+
if (!l.ok) return B(401, { error: l.error });
|
|
554
|
+
if (!(yield* t.advancePasskeyCounter(e.credentialId, l.result.newCounter)) && l.result.newCounter !== 0) return B(401, { error: "counter_regressed" });
|
|
555
555
|
let d = yield* t.findById(o.userId);
|
|
556
|
-
if (!d) return
|
|
557
|
-
let f = yield*
|
|
556
|
+
if (!d) return B(401, { error: "unknown_credential" });
|
|
557
|
+
let f = yield* z(d, i);
|
|
558
558
|
if (f) return f;
|
|
559
559
|
let m = yield* t.listMemberships(d.id), h = u("sess");
|
|
560
560
|
yield* t.insertSession({
|
|
561
561
|
id: h,
|
|
562
562
|
userId: d.id,
|
|
563
563
|
tenantId: d.tenantId,
|
|
564
|
-
expiresAt: new Date(Date.now() +
|
|
564
|
+
expiresAt: new Date(Date.now() + at * 1e3),
|
|
565
565
|
ipAddress: null,
|
|
566
566
|
userAgent: null
|
|
567
567
|
}).pipe(C.ignore);
|
|
@@ -571,34 +571,34 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
571
571
|
...g.metadata ?? {},
|
|
572
572
|
sessionId: h
|
|
573
573
|
}
|
|
574
|
-
} : g, v = a(_,
|
|
575
|
-
ttlSeconds:
|
|
574
|
+
} : g, v = a(_, F(i), {
|
|
575
|
+
ttlSeconds: at,
|
|
576
576
|
...i.cookieDomain ? { domain: i.cookieDomain } : {},
|
|
577
577
|
secure: i.cookieSecure ?? !0
|
|
578
578
|
});
|
|
579
|
-
return
|
|
579
|
+
return B(200, {
|
|
580
580
|
ok: !0,
|
|
581
581
|
subject: _
|
|
582
582
|
}, { setCookie: v.setCookie });
|
|
583
|
-
}),
|
|
583
|
+
}), ft = 10080 * 60, pt = 500, H = [
|
|
584
584
|
"owner",
|
|
585
585
|
"admin",
|
|
586
586
|
"member",
|
|
587
587
|
"viewer"
|
|
588
|
-
],
|
|
589
|
-
let n =
|
|
588
|
+
], mt = ["owner", "admin"], ht = (e, t) => t.indexOf(e), gt = (e, t = H) => {
|
|
589
|
+
let n = ht(e.inviterRole, t);
|
|
590
590
|
if (n < 0) return !1;
|
|
591
|
-
let r =
|
|
591
|
+
let r = ht(e.requestedRole, t);
|
|
592
592
|
return r < 0 ? n === 0 : r >= n;
|
|
593
|
-
},
|
|
594
|
-
let t = e?.roleRank ??
|
|
595
|
-
return e?.canGrantRole ?? ((e) =>
|
|
596
|
-
},
|
|
593
|
+
}, _t = (e) => {
|
|
594
|
+
let t = e?.roleRank ?? H;
|
|
595
|
+
return e?.canGrantRole ?? ((e) => gt(e, t));
|
|
596
|
+
}, U = (e, t, n = {}) => ({
|
|
597
597
|
status: e,
|
|
598
598
|
body: JSON.stringify(t),
|
|
599
599
|
contentType: "application/json; charset=utf-8",
|
|
600
600
|
...n
|
|
601
|
-
}),
|
|
601
|
+
}), vt = (e, t, n) => `${e}${t}${t.includes("?") ? "&" : "?"}token=${encodeURIComponent(n)}`, yt = (e) => ({
|
|
602
602
|
id: e.id,
|
|
603
603
|
email: e.email,
|
|
604
604
|
tenantId: e.tenantId,
|
|
@@ -608,26 +608,26 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
608
608
|
acceptedAt: e.acceptedAt?.toISOString() ?? null,
|
|
609
609
|
revokedAt: e.revokedAt?.toISOString() ?? null,
|
|
610
610
|
createdAt: e.createdAt.toISOString()
|
|
611
|
-
}),
|
|
611
|
+
}), W = (e, t, n, r) => C.gen(function* () {
|
|
612
612
|
let i = yield* n.membershipRole(e, t);
|
|
613
|
-
return i === null || !(r?.inviterRoles ??
|
|
614
|
-
}),
|
|
613
|
+
return i === null || !(r?.inviterRoles ?? mt).includes(i) ? U(403, { error: "not_permitted" }) : { role: i };
|
|
614
|
+
}), G = (e) => "status" in e, bt = (e, t, n) => C.gen(function* () {
|
|
615
615
|
let r = e.email.trim().toLowerCase();
|
|
616
|
-
if (!r || !r.includes("@")) return
|
|
617
|
-
if (!e.tenantId) return
|
|
618
|
-
if (!e.role) return
|
|
619
|
-
let i = n.invitations, a = yield*
|
|
620
|
-
if (
|
|
621
|
-
if (!
|
|
616
|
+
if (!r || !r.includes("@")) return U(400, { error: "a valid email is required" });
|
|
617
|
+
if (!e.tenantId) return U(400, { error: "tenantId required" });
|
|
618
|
+
if (!e.role) return U(400, { error: "role required" });
|
|
619
|
+
let i = n.invitations, a = yield* W(e.inviterUserId, e.tenantId, t, i);
|
|
620
|
+
if (G(a)) return a;
|
|
621
|
+
if (!_t(i)({
|
|
622
622
|
inviterRole: a.role,
|
|
623
623
|
requestedRole: e.role,
|
|
624
624
|
tenantId: e.tenantId
|
|
625
|
-
})) return
|
|
625
|
+
})) return U(403, {
|
|
626
626
|
error: "role_not_grantable",
|
|
627
627
|
message: `A '${a.role}' may not invite a '${e.role}'.`
|
|
628
628
|
});
|
|
629
629
|
let o = new Date((n.now ?? Date.now)());
|
|
630
|
-
if ((yield* t.countPendingInvitations(e.tenantId, o)) >= (i?.maxPending ?? 500)) return
|
|
630
|
+
if ((yield* t.countPendingInvitations(e.tenantId, o)) >= (i?.maxPending ?? 500)) return U(429, { error: "too_many_pending_invitations" });
|
|
631
631
|
yield* t.supersedePendingInvitations(e.tenantId, r, e.inviterUserId, o).pipe(C.ignore);
|
|
632
632
|
let s = i?.ttlSeconds ?? 604800, c = g(s), l = yield* t.insertInvitation({
|
|
633
633
|
id: u("inv"),
|
|
@@ -639,7 +639,7 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
639
639
|
expiresAt: new Date(o.getTime() + s * 1e3)
|
|
640
640
|
});
|
|
641
641
|
if (n.sendEmail) {
|
|
642
|
-
let t =
|
|
642
|
+
let t = vt(n.appBaseUrl ?? "", i?.callbackPath ?? "/auth/invitations/accept", c.token);
|
|
643
643
|
yield* C.tryPromise(() => n.sendEmail({
|
|
644
644
|
to: r,
|
|
645
645
|
kind: "invitation",
|
|
@@ -649,28 +649,28 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
649
649
|
html: `<p>You have been invited to join as <strong>${e.role}</strong>. <a href="${t}">Accept the invitation</a> — this link expires.</p>`
|
|
650
650
|
})).pipe(C.ignore);
|
|
651
651
|
}
|
|
652
|
-
return
|
|
652
|
+
return U(201, {
|
|
653
653
|
ok: !0,
|
|
654
|
-
invitation:
|
|
654
|
+
invitation: yt(l)
|
|
655
655
|
});
|
|
656
|
-
}), bt = (e, t, n) => C.gen(function* () {
|
|
657
|
-
let r = yield* U(e.callerUserId, e.tenantId, t, n.invitations);
|
|
658
|
-
return W(r) ? r : H(200, { invitations: (yield* t.listInvitations(e.tenantId)).map(vt) });
|
|
659
656
|
}), xt = (e, t, n) => C.gen(function* () {
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
657
|
+
let r = yield* W(e.callerUserId, e.tenantId, t, n.invitations);
|
|
658
|
+
return G(r) ? r : U(200, { invitations: (yield* t.listInvitations(e.tenantId)).map(yt) });
|
|
659
|
+
}), St = (e, t, n) => C.gen(function* () {
|
|
660
|
+
if (!e.invitationId) return U(400, { error: "invitationId required" });
|
|
661
|
+
let r = yield* W(e.callerUserId, e.tenantId, t, n.invitations);
|
|
662
|
+
if (G(r)) return r;
|
|
663
663
|
let i = new Date((n.now ?? Date.now)());
|
|
664
|
-
return (yield* t.revokeInvitation(e.invitationId, e.tenantId, e.callerUserId, i)) ?
|
|
664
|
+
return (yield* t.revokeInvitation(e.invitationId, e.tenantId, e.callerUserId, i)) ? U(200, {
|
|
665
665
|
ok: !0,
|
|
666
666
|
revoked: 1
|
|
667
|
-
}) :
|
|
668
|
-
}),
|
|
669
|
-
if (!e.token) return
|
|
667
|
+
}) : U(404, { error: "invitation_not_found" });
|
|
668
|
+
}), Ct = (e, t, n = {}) => C.gen(function* () {
|
|
669
|
+
if (!e.token) return U(400, { error: "token required" });
|
|
670
670
|
let r = yield* t.findInvitationByHash(h(e.token));
|
|
671
|
-
if (!r) return
|
|
671
|
+
if (!r) return U(404, { error: "invalid_invitation" });
|
|
672
672
|
let i = new Date((n.now ?? Date.now)());
|
|
673
|
-
return
|
|
673
|
+
return U(200, {
|
|
674
674
|
ok: !0,
|
|
675
675
|
state: r.acceptedAt === null ? r.revokedAt === null ? r.expiresAt.getTime() <= i.getTime() ? "expired" : "pending" : "revoked" : "accepted",
|
|
676
676
|
email: r.email,
|
|
@@ -678,31 +678,31 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
678
678
|
role: r.role,
|
|
679
679
|
expiresAt: r.expiresAt.toISOString()
|
|
680
680
|
});
|
|
681
|
-
}),
|
|
682
|
-
if (!e.token) return
|
|
681
|
+
}), wt = (e, t, n = {}) => C.gen(function* () {
|
|
682
|
+
if (!e.token) return U(400, { error: "token required" });
|
|
683
683
|
let r = h(e.token), i = new Date((n.now ?? Date.now)()), a = yield* t.findInvitationByHash(r);
|
|
684
|
-
if (!a) return
|
|
685
|
-
if (!e.userId) return
|
|
684
|
+
if (!a) return U(401, { error: "invalid_or_expired_invitation" });
|
|
685
|
+
if (!e.userId) return U(401, {
|
|
686
686
|
error: "authentication_required",
|
|
687
687
|
email: a.email
|
|
688
688
|
});
|
|
689
689
|
let o = yield* t.findById(e.userId);
|
|
690
|
-
if (!o) return
|
|
690
|
+
if (!o) return U(401, {
|
|
691
691
|
error: "authentication_required",
|
|
692
692
|
email: a.email
|
|
693
693
|
});
|
|
694
|
-
if (o.email.toLowerCase() !== a.email.toLowerCase()) return
|
|
694
|
+
if (o.email.toLowerCase() !== a.email.toLowerCase()) return U(403, {
|
|
695
695
|
error: "invitation_email_mismatch",
|
|
696
696
|
message: "This invitation was issued to a different email address. Sign in as that address to accept it."
|
|
697
697
|
});
|
|
698
698
|
let s = yield* t.acceptInvitation(r, o.id, i);
|
|
699
|
-
if (!s) return
|
|
699
|
+
if (!s) return U(401, { error: "invalid_or_expired_invitation" });
|
|
700
700
|
let c = yield* t.addMembership({
|
|
701
701
|
userId: o.id,
|
|
702
702
|
tenantId: s.tenantId,
|
|
703
703
|
role: s.role
|
|
704
704
|
});
|
|
705
|
-
return yield* t.markEmailVerified(o.id).pipe(C.ignore),
|
|
705
|
+
return yield* t.markEmailVerified(o.id).pipe(C.ignore), U(200, {
|
|
706
706
|
ok: !0,
|
|
707
707
|
membership: {
|
|
708
708
|
tenantId: c.tenantId,
|
|
@@ -710,19 +710,19 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
710
710
|
joinedAt: c.joinedAt.toISOString()
|
|
711
711
|
}
|
|
712
712
|
});
|
|
713
|
-
}),
|
|
714
|
-
if (!e.token || !e.password) return
|
|
715
|
-
if (e.password.length < (n.minPasswordLength ?? 8)) return
|
|
713
|
+
}), Tt = (e, t, n) => C.gen(function* () {
|
|
714
|
+
if (!e.token || !e.password) return U(400, { error: "token and password required" });
|
|
715
|
+
if (e.password.length < (n.minPasswordLength ?? 8)) return U(400, { error: "password must be at least 8 characters" });
|
|
716
716
|
let r = h(e.token), i = new Date((n.now ?? Date.now)()), a = yield* t.findInvitationByHash(r);
|
|
717
|
-
if (!a) return
|
|
718
|
-
if (yield* t.findByEmail(a.email)) return
|
|
717
|
+
if (!a) return U(401, { error: "invalid_or_expired_invitation" });
|
|
718
|
+
if (yield* t.findByEmail(a.email)) return U(409, {
|
|
719
719
|
error: "account_exists",
|
|
720
720
|
message: "An account already exists for this address. Sign in, then accept the invitation."
|
|
721
721
|
});
|
|
722
722
|
let o = yield* n.hashPassword(e.password).pipe(C.orElseSucceed(() => ""));
|
|
723
|
-
if (!o) return
|
|
723
|
+
if (!o) return U(500, { error: "hash_failed" });
|
|
724
724
|
let s = u("user"), c = yield* t.acceptInvitation(r, s, i);
|
|
725
|
-
if (!c) return
|
|
725
|
+
if (!c) return U(401, { error: "invalid_or_expired_invitation" });
|
|
726
726
|
let l = yield* t.insert({
|
|
727
727
|
id: s,
|
|
728
728
|
email: c.email,
|
|
@@ -733,13 +733,13 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
733
733
|
userId: l.id,
|
|
734
734
|
tenantId: c.tenantId,
|
|
735
735
|
role: c.role
|
|
736
|
-
}), yield* t.markEmailVerified(l.id).pipe(C.ignore),
|
|
736
|
+
}), yield* t.markEmailVerified(l.id).pipe(C.ignore), U(201, {
|
|
737
737
|
ok: !0,
|
|
738
738
|
userId: l.id,
|
|
739
739
|
tenantId: c.tenantId,
|
|
740
740
|
role: c.role
|
|
741
|
-
})) :
|
|
742
|
-
}),
|
|
741
|
+
})) : U(409, { error: "account_exists" });
|
|
742
|
+
}), Et = 900, Dt = [
|
|
743
743
|
"/mfa/enroll/start",
|
|
744
744
|
"/mfa/enroll/verify",
|
|
745
745
|
"/mfa/unenroll",
|
|
@@ -749,7 +749,7 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
749
749
|
"/sessions/revoke-others",
|
|
750
750
|
"/switch-tenant",
|
|
751
751
|
"/impersonate/start"
|
|
752
|
-
],
|
|
752
|
+
], Ot = (e) => {
|
|
753
753
|
if (typeof e != "object" || !e) return null;
|
|
754
754
|
let t = e;
|
|
755
755
|
return typeof t.actorUserId != "string" || t.actorUserId.length === 0 || typeof t.grantId != "string" || typeof t.expiresAt != "string" || typeof t.actorSessionId != "string" || typeof t.startedAt != "string" ? null : {
|
|
@@ -760,14 +760,14 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
760
760
|
expiresAt: t.expiresAt,
|
|
761
761
|
...typeof t.reason == "string" ? { reason: t.reason } : {}
|
|
762
762
|
};
|
|
763
|
-
}, K = (e) => e.type === "user" ?
|
|
763
|
+
}, K = (e) => e.type === "user" ? Ot(de(e)) : null, q = (e) => K(e) !== null, kt = () => (e) => {
|
|
764
764
|
if (e.type !== "user" || e.metadata === void 0) return e;
|
|
765
|
-
let t =
|
|
765
|
+
let t = Ot(e.metadata[w]), { metadata: n, ...r } = e;
|
|
766
766
|
return {
|
|
767
767
|
...r,
|
|
768
768
|
metadata: t === null ? { __redacted: "all" } : {
|
|
769
769
|
__redacted: "all-except-impersonation",
|
|
770
|
-
[
|
|
770
|
+
[w]: t
|
|
771
771
|
}
|
|
772
772
|
};
|
|
773
773
|
}, J = (e, t, n = {}) => ({
|
|
@@ -781,7 +781,7 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
781
781
|
try: () => Promise.resolve(n),
|
|
782
782
|
catch: (e) => e
|
|
783
783
|
});
|
|
784
|
-
}).pipe(C.catchAllCause(() => C.void)),
|
|
784
|
+
}).pipe(C.catchAllCause(() => C.void)), At = (e, t, n) => C.gen(function* () {
|
|
785
785
|
let r = n.impersonation, i = (n.now ?? Date.now)(), a = new Date(i), o = e.actorSubject, s = (t, n, i = {}) => Y(r, {
|
|
786
786
|
kind: "refused",
|
|
787
787
|
at: a,
|
|
@@ -854,7 +854,7 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
854
854
|
}, y = yield* n.issuer.issue(l, {
|
|
855
855
|
sessionId: g,
|
|
856
856
|
ttlSeconds: m,
|
|
857
|
-
metadata: { [
|
|
857
|
+
metadata: { [w]: v },
|
|
858
858
|
ipAddress: e.ipAddress ?? null,
|
|
859
859
|
userAgent: e.userAgent ?? null
|
|
860
860
|
});
|
|
@@ -877,7 +877,7 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
877
877
|
impersonation: v,
|
|
878
878
|
subject: y.subject
|
|
879
879
|
}, { setCookie: y.setCookie });
|
|
880
|
-
}),
|
|
880
|
+
}), jt = (e, t, n) => C.gen(function* () {
|
|
881
881
|
let r = n.impersonation, i = (n.now ?? Date.now)(), a = new Date(i), o = K(e.subject);
|
|
882
882
|
if (!o || !e.sessionId) return J(400, { error: "not_impersonating" });
|
|
883
883
|
let s = yield* t.findImpersonationGrantBySession(e.sessionId);
|
|
@@ -907,10 +907,10 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
907
907
|
restored: !0,
|
|
908
908
|
subject: d.subject
|
|
909
909
|
}, { setCookie: d.setCookie });
|
|
910
|
-
}),
|
|
911
|
-
for (let t of e) if (
|
|
910
|
+
}), Mt = (e) => {
|
|
911
|
+
for (let t of e) if (Nt(t)) return t.auth.sessionStrategy;
|
|
912
912
|
return null;
|
|
913
|
-
},
|
|
913
|
+
}, Nt = (e) => typeof e.auth == "object" && e.auth !== null && typeof e.auth.sessionStrategy == "object", Pt = "/auth", Ft = (e) => {
|
|
914
914
|
let t = Buffer.from(e.rawBody).toString("utf8");
|
|
915
915
|
if (!t) return {};
|
|
916
916
|
if ((e.headers["content-type"] ?? "").includes("application/x-www-form-urlencoded")) {
|
|
@@ -936,8 +936,8 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
936
936
|
status: e,
|
|
937
937
|
body: JSON.stringify(t),
|
|
938
938
|
contentType: "application/json; charset=utf-8"
|
|
939
|
-
}), Q = (e) => typeof e == "string" ? e : void 0, $ = (e, t) => typeof t == "string" && t.length > 0 ? { [e]: t } : {},
|
|
940
|
-
let n = t.prefix ??
|
|
939
|
+
}), Q = (e) => typeof e == "string" ? e : void 0, $ = (e, t) => typeof t == "string" && t.length > 0 ? { [e]: t } : {}, It = (t) => {
|
|
940
|
+
let n = t.prefix ?? Pt, r = t.store, s = t.challengeStore ?? ot(), c = {
|
|
941
941
|
...t.secret === void 0 ? {} : { secret: t.secret },
|
|
942
942
|
...t.secrets === void 0 ? {} : { secrets: t.secrets },
|
|
943
943
|
defaultTenantId: t.defaultTenantId,
|
|
@@ -946,7 +946,7 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
946
946
|
...t.successRedirect === void 0 ? {} : { successRedirect: t.successRedirect },
|
|
947
947
|
...t.sendEmail === void 0 ? {} : { sendEmail: t.sendEmail },
|
|
948
948
|
...t.appBaseUrl === void 0 ? {} : { appBaseUrl: t.appBaseUrl },
|
|
949
|
-
subjectGuards: [...t.subjectGuards ?? [], ...
|
|
949
|
+
subjectGuards: [...t.subjectGuards ?? [], ...A(t.emailVerification) ? [Ae(t.emailVerification)] : []],
|
|
950
950
|
...t.lockout === void 0 ? {} : { lockout: t.lockout },
|
|
951
951
|
...t.now === void 0 ? {} : { now: t.now },
|
|
952
952
|
...t.emailVerification === void 0 ? {} : { emailVerification: t.emailVerification }
|
|
@@ -970,7 +970,7 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
970
970
|
envVar: "VOLTRO_IMPERSONATION_GRANTS_TTL_HOURS"
|
|
971
971
|
});
|
|
972
972
|
let u = d(r, t.sessionRevocation ?? {}), p = async (e) => {
|
|
973
|
-
let t =
|
|
973
|
+
let t = F(c), n = o(e.headers.cookie, t);
|
|
974
974
|
if (!n) return null;
|
|
975
975
|
let i = f(n.subject);
|
|
976
976
|
if (i && !await C.runPromise(u.isLive(i))) return null;
|
|
@@ -1002,9 +1002,9 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
1002
1002
|
};
|
|
1003
1003
|
}, g = (e) => {
|
|
1004
1004
|
let n = e.headers[y];
|
|
1005
|
-
return ee(n, se(e.headers.cookie, v),
|
|
1005
|
+
return ee(n, se(e.headers.cookie, v), Le(t));
|
|
1006
1006
|
}, _ = (e, t) => e.path === `${n}${t}`, b = (e) => C.runPromise(e).then(X), x = {
|
|
1007
|
-
issue: (e, t) =>
|
|
1007
|
+
issue: (e, t) => R(e, r, c, {
|
|
1008
1008
|
sessionId: t.sessionId,
|
|
1009
1009
|
ttlSeconds: t.ttlSeconds,
|
|
1010
1010
|
metadata: t.metadata,
|
|
@@ -1012,7 +1012,7 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
1012
1012
|
userAgent: t.userAgent ?? null,
|
|
1013
1013
|
clearLoginFailures: !1
|
|
1014
1014
|
}),
|
|
1015
|
-
reissue: (e, t) =>
|
|
1015
|
+
reissue: (e, t) => R(e, r, c, {
|
|
1016
1016
|
sessionId: t.sessionId,
|
|
1017
1017
|
ttlSeconds: t.ttlSeconds,
|
|
1018
1018
|
sessionRow: "existing",
|
|
@@ -1026,16 +1026,16 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
1026
1026
|
method: "*",
|
|
1027
1027
|
path: n,
|
|
1028
1028
|
handle: async (i) => {
|
|
1029
|
-
let a = i.method === "GET" ? {} :
|
|
1030
|
-
if (i.method === "GET" && _(i, "/csrf")) return X(
|
|
1031
|
-
if (i.method === "POST" && _(i, "/sign-in")) return b(
|
|
1029
|
+
let a = i.method === "GET" ? {} : Ft(i);
|
|
1030
|
+
if (i.method === "GET" && _(i, "/csrf")) return X(Je(c));
|
|
1031
|
+
if (i.method === "POST" && _(i, "/sign-in")) return b(Be({
|
|
1032
1032
|
email: Q(a.email) ?? "",
|
|
1033
1033
|
password: Q(a.password) ?? "",
|
|
1034
1034
|
...a.redirectAfter === void 0 ? {} : { redirectAfter: !!a.redirectAfter },
|
|
1035
1035
|
...i.remoteAddr ? { ipAddress: i.remoteAddr } : {},
|
|
1036
1036
|
...i.headers["user-agent"] ? { userAgent: i.headers["user-agent"] } : {}
|
|
1037
1037
|
}, r, c));
|
|
1038
|
-
if (i.method === "POST" && _(i, "/sign-up")) return b(
|
|
1038
|
+
if (i.method === "POST" && _(i, "/sign-up")) return b(He({
|
|
1039
1039
|
email: Q(a.email) ?? "",
|
|
1040
1040
|
password: Q(a.password) ?? "",
|
|
1041
1041
|
...$("tenantId", a.tenantId),
|
|
@@ -1043,40 +1043,40 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
1043
1043
|
}, r, c));
|
|
1044
1044
|
if (i.method === "POST" && _(i, "/sign-out")) {
|
|
1045
1045
|
let e = await p(i);
|
|
1046
|
-
return e && e.subject.type === "user" && e.sessionId && (await C.runPromise(r.revokeSession(e.subject.id, e.sessionId)), u.invalidate(e.sessionId)), X(
|
|
1046
|
+
return e && e.subject.type === "user" && e.sessionId && (await C.runPromise(r.revokeSession(e.subject.id, e.sessionId)), u.invalidate(e.sessionId)), X(Ue(c));
|
|
1047
1047
|
}
|
|
1048
|
-
if (i.method === "POST" && _(i, "/magic-link")) return b(
|
|
1048
|
+
if (i.method === "POST" && _(i, "/magic-link")) return b(Xe({
|
|
1049
1049
|
email: Q(a.email) ?? "",
|
|
1050
1050
|
...$("callbackPath", a.callbackPath)
|
|
1051
1051
|
}, r, c));
|
|
1052
|
-
if (i.method === "POST" && _(i, "/magic-link/callback")) return b(
|
|
1052
|
+
if (i.method === "POST" && _(i, "/magic-link/callback")) return b(Ze({
|
|
1053
1053
|
token: Q(a.token) ?? "",
|
|
1054
1054
|
...a.redirectAfter === void 0 ? {} : { redirectAfter: !!a.redirectAfter }
|
|
1055
1055
|
}, r, c));
|
|
1056
|
-
if (i.method === "POST" && _(i, "/password-reset")) return b(
|
|
1056
|
+
if (i.method === "POST" && _(i, "/password-reset")) return b(Qe({
|
|
1057
1057
|
email: Q(a.email) ?? "",
|
|
1058
1058
|
...$("callbackPath", a.callbackPath)
|
|
1059
1059
|
}, r, c));
|
|
1060
|
-
if (i.method === "POST" && _(i, "/password-reset/confirm")) return b(
|
|
1060
|
+
if (i.method === "POST" && _(i, "/password-reset/confirm")) return b($e({
|
|
1061
1061
|
token: Q(a.token) ?? "",
|
|
1062
1062
|
newPassword: Q(a.newPassword) ?? ""
|
|
1063
1063
|
}, r));
|
|
1064
1064
|
if (i.method === "POST" && _(i, "/verify-email")) {
|
|
1065
1065
|
let e = Q(a.email);
|
|
1066
|
-
if (e) return b(
|
|
1066
|
+
if (e) return b(P({ email: e }, r, c));
|
|
1067
1067
|
let t = await p(i);
|
|
1068
|
-
return !t || t.subject.type !== "user" ? Z(400, { error: "email required" }) : b(
|
|
1068
|
+
return !t || t.subject.type !== "user" ? Z(400, { error: "email required" }) : b(P({ userId: t.subject.id }, r, c));
|
|
1069
1069
|
}
|
|
1070
|
-
if (i.method === "POST" && _(i, "/verify-email/callback")) return b(
|
|
1071
|
-
if (t.invitations && i.method === "POST" && _(i, "/invitations/preview")) return b(
|
|
1072
|
-
if (t.invitations && i.method === "POST" && _(i, "/invitations/sign-up")) return b(
|
|
1070
|
+
if (i.method === "POST" && _(i, "/verify-email/callback")) return b(Me({ token: Q(a.token) ?? "" }, r));
|
|
1071
|
+
if (t.invitations && i.method === "POST" && _(i, "/invitations/preview")) return b(Ct({ token: Q(a.token) ?? "" }, r, l));
|
|
1072
|
+
if (t.invitations && i.method === "POST" && _(i, "/invitations/sign-up")) return b(Tt({
|
|
1073
1073
|
token: Q(a.token) ?? "",
|
|
1074
1074
|
password: Q(a.password) ?? ""
|
|
1075
1075
|
}, r, {
|
|
1076
1076
|
...l,
|
|
1077
1077
|
hashPassword: e
|
|
1078
1078
|
}));
|
|
1079
|
-
if (i.method === "POST" && _(i, "/mfa/verify")) return b(
|
|
1079
|
+
if (i.method === "POST" && _(i, "/mfa/verify")) return b(Ve({
|
|
1080
1080
|
pendingToken: Q(a.pendingToken) ?? "",
|
|
1081
1081
|
...$("code", a.code),
|
|
1082
1082
|
...$("recoveryCode", a.recoveryCode),
|
|
@@ -1084,8 +1084,8 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
1084
1084
|
...i.remoteAddr ? { ipAddress: i.remoteAddr } : {},
|
|
1085
1085
|
...i.headers["user-agent"] ? { userAgent: i.headers["user-agent"] } : {}
|
|
1086
1086
|
}, r, c));
|
|
1087
|
-
if (t.passkey && i.method === "POST" && _(i, "/passkey/assert/options")) return b(
|
|
1088
|
-
if (t.passkey && i.method === "POST" && _(i, "/passkey/assert/verify")) return b(
|
|
1087
|
+
if (t.passkey && i.method === "POST" && _(i, "/passkey/assert/options")) return b(ut({ ...$("userId", a.userId) }, r, s, t.passkey));
|
|
1088
|
+
if (t.passkey && i.method === "POST" && _(i, "/passkey/assert/verify")) return b(dt({
|
|
1089
1089
|
credentialId: Q(a.credentialId) ?? "",
|
|
1090
1090
|
clientDataJSON: Q(a.clientDataJSON) ?? "",
|
|
1091
1091
|
authenticatorData: Q(a.authenticatorData) ?? "",
|
|
@@ -1095,7 +1095,7 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
1095
1095
|
let o = await p(i), d = o?.subject ?? null, f = () => !d || d.type !== "user" ? Z(401, { error: "unauthenticated" }) : { userId: d.id }, m = () => g(i) ? null : Z(403, { error: "csrf" }), v = (e) => b(e).then((e) => h(e, o?.renewSetCookie));
|
|
1096
1096
|
if (d && q(d)) {
|
|
1097
1097
|
let e = i.path.startsWith(n) ? i.path.slice(n.length) : "";
|
|
1098
|
-
if (
|
|
1098
|
+
if (Dt.includes(e)) return Z(403, {
|
|
1099
1099
|
error: "forbidden_while_impersonating",
|
|
1100
1100
|
message: "This action changes account credentials or session scope and is refused while impersonating. Stop the impersonation first."
|
|
1101
1101
|
});
|
|
@@ -1110,11 +1110,11 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
1110
1110
|
}
|
|
1111
1111
|
if (i.method === "GET" && _(i, "/sessions")) {
|
|
1112
1112
|
let e = f();
|
|
1113
|
-
return "status" in e ? e : v(
|
|
1113
|
+
return "status" in e ? e : v(et({ userId: e.userId }, r));
|
|
1114
1114
|
}
|
|
1115
1115
|
if (i.method === "GET" && _(i, "/memberships")) {
|
|
1116
1116
|
let e = f();
|
|
1117
|
-
return "status" in e ? e : v(
|
|
1117
|
+
return "status" in e ? e : v(it({ userId: e.userId }, r));
|
|
1118
1118
|
}
|
|
1119
1119
|
if (i.method === "POST" && _(i, "/sessions/revoke")) {
|
|
1120
1120
|
let e = f();
|
|
@@ -1122,21 +1122,21 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
1122
1122
|
let t = m();
|
|
1123
1123
|
if (t) return t;
|
|
1124
1124
|
let n = Q(a.sessionId) ?? "";
|
|
1125
|
-
return v(
|
|
1125
|
+
return v(tt({
|
|
1126
1126
|
userId: e.userId,
|
|
1127
1127
|
sessionId: n
|
|
1128
1128
|
}, r)).then((e) => (n && u.invalidate(n), e));
|
|
1129
1129
|
}
|
|
1130
1130
|
if (i.method === "POST" && _(i, "/sessions/revoke-others")) {
|
|
1131
1131
|
let e = f();
|
|
1132
|
-
return "status" in e ? e : m() || v(
|
|
1132
|
+
return "status" in e ? e : m() || v(nt({
|
|
1133
1133
|
userId: e.userId,
|
|
1134
1134
|
keepSessionId: o?.sessionId ?? "__none__"
|
|
1135
1135
|
}, r));
|
|
1136
1136
|
}
|
|
1137
1137
|
if (t.invitations && i.method === "POST" && _(i, "/invitations")) {
|
|
1138
1138
|
let e = f();
|
|
1139
|
-
return "status" in e ? e : m() || v(
|
|
1139
|
+
return "status" in e ? e : m() || v(bt({
|
|
1140
1140
|
inviterUserId: e.userId,
|
|
1141
1141
|
tenantId: Q(a.tenantId) ?? d?.tenantId ?? "",
|
|
1142
1142
|
email: Q(a.email) ?? "",
|
|
@@ -1145,14 +1145,14 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
1145
1145
|
}
|
|
1146
1146
|
if (t.invitations && i.method === "GET" && i.path === `${n}/invitations`) {
|
|
1147
1147
|
let e = f();
|
|
1148
|
-
return "status" in e ? e : v(
|
|
1148
|
+
return "status" in e ? e : v(xt({
|
|
1149
1149
|
callerUserId: e.userId,
|
|
1150
1150
|
tenantId: d?.tenantId ?? ""
|
|
1151
1151
|
}, r, l));
|
|
1152
1152
|
}
|
|
1153
1153
|
if (t.invitations && i.method === "POST" && _(i, "/invitations/revoke")) {
|
|
1154
1154
|
let e = f();
|
|
1155
|
-
return "status" in e ? e : m() || v(
|
|
1155
|
+
return "status" in e ? e : m() || v(St({
|
|
1156
1156
|
callerUserId: e.userId,
|
|
1157
1157
|
tenantId: Q(a.tenantId) ?? d?.tenantId ?? "",
|
|
1158
1158
|
invitationId: Q(a.invitationId) ?? ""
|
|
@@ -1164,14 +1164,14 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
1164
1164
|
let e = m();
|
|
1165
1165
|
if (e) return e;
|
|
1166
1166
|
}
|
|
1167
|
-
return v(
|
|
1167
|
+
return v(wt({
|
|
1168
1168
|
token: Q(a.token) ?? "",
|
|
1169
1169
|
..."status" in e ? {} : { userId: e.userId }
|
|
1170
1170
|
}, r, l));
|
|
1171
1171
|
}
|
|
1172
1172
|
if (t.impersonation && i.method === "POST" && _(i, "/impersonate/start")) {
|
|
1173
1173
|
let e = f();
|
|
1174
|
-
return "status" in e ? e : m() || b(
|
|
1174
|
+
return "status" in e ? e : m() || b(At({
|
|
1175
1175
|
actorSubject: d,
|
|
1176
1176
|
actorSessionId: o?.sessionId ?? "",
|
|
1177
1177
|
...$("targetUserId", a.userId),
|
|
@@ -1189,7 +1189,7 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
1189
1189
|
}
|
|
1190
1190
|
if (t.impersonation && i.method === "POST" && _(i, "/impersonate/stop")) {
|
|
1191
1191
|
let e = f();
|
|
1192
|
-
return "status" in e ? e : m() || b(
|
|
1192
|
+
return "status" in e ? e : m() || b(jt({
|
|
1193
1193
|
subject: d,
|
|
1194
1194
|
sessionId: o?.sessionId ?? ""
|
|
1195
1195
|
}, r, {
|
|
@@ -1201,7 +1201,7 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
1201
1201
|
}
|
|
1202
1202
|
if (i.method === "POST" && _(i, "/switch-tenant")) {
|
|
1203
1203
|
let e = f();
|
|
1204
|
-
return "status" in e ? e : m() || b(
|
|
1204
|
+
return "status" in e ? e : m() || b(rt({
|
|
1205
1205
|
userId: e.userId,
|
|
1206
1206
|
targetTenantId: Q(a.targetTenantId) ?? "",
|
|
1207
1207
|
...typeof a.clientId == "number" ? { clientId: a.clientId } : {},
|
|
@@ -1215,7 +1215,7 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
1215
1215
|
let n = m();
|
|
1216
1216
|
if (n) return n;
|
|
1217
1217
|
let i = await C.runPromise(r.findById(e.userId));
|
|
1218
|
-
return v(
|
|
1218
|
+
return v(We({
|
|
1219
1219
|
userId: e.userId,
|
|
1220
1220
|
issuer: t.mfa.issuer,
|
|
1221
1221
|
accountName: i?.email ?? e.userId
|
|
@@ -1223,29 +1223,29 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
1223
1223
|
}
|
|
1224
1224
|
if (t.mfa && i.method === "POST" && _(i, "/mfa/enroll/verify")) {
|
|
1225
1225
|
let e = f();
|
|
1226
|
-
return "status" in e ? e : m() || v(
|
|
1226
|
+
return "status" in e ? e : m() || v(Ge({
|
|
1227
1227
|
userId: e.userId,
|
|
1228
1228
|
code: Q(a.code) ?? ""
|
|
1229
1229
|
}, r));
|
|
1230
1230
|
}
|
|
1231
1231
|
if (t.mfa && i.method === "POST" && _(i, "/mfa/unenroll")) {
|
|
1232
1232
|
let e = f();
|
|
1233
|
-
return "status" in e ? e : m() || v(
|
|
1233
|
+
return "status" in e ? e : m() || v(qe({ userId: e.userId }, r));
|
|
1234
1234
|
}
|
|
1235
1235
|
if (t.mfa && i.method === "POST" && _(i, "/mfa/recovery-codes/regenerate")) {
|
|
1236
1236
|
let e = f();
|
|
1237
|
-
return "status" in e ? e : m() || v(
|
|
1237
|
+
return "status" in e ? e : m() || v(Ke({ userId: e.userId }, r));
|
|
1238
1238
|
}
|
|
1239
1239
|
if (t.passkey && i.method === "POST" && _(i, "/passkey/register/options")) {
|
|
1240
1240
|
let e = f();
|
|
1241
|
-
return "status" in e ? e : m() || v(
|
|
1241
|
+
return "status" in e ? e : m() || v(ct({
|
|
1242
1242
|
userId: e.userId,
|
|
1243
1243
|
userName: Q(a.userName) ?? e.userId
|
|
1244
1244
|
}, r, s, t.passkey));
|
|
1245
1245
|
}
|
|
1246
1246
|
if (t.passkey && i.method === "POST" && _(i, "/passkey/register/verify")) {
|
|
1247
1247
|
let e = f();
|
|
1248
|
-
return "status" in e ? e : m() || v(
|
|
1248
|
+
return "status" in e ? e : m() || v(lt({
|
|
1249
1249
|
userId: e.userId,
|
|
1250
1250
|
credentialId: Q(a.credentialId) ?? "",
|
|
1251
1251
|
clientDataJSON: Q(a.clientDataJSON) ?? "",
|
|
@@ -1259,7 +1259,7 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
1259
1259
|
name: t.name ? `@voltro/plugin-auth#${t.name}` : "@voltro/plugin-auth",
|
|
1260
1260
|
description: "Auth routes — mounts the full auth surface (password, magic-link, password-reset, CSRF, session probe/list/revoke, memberships, switch-tenant, passkey ceremonies) under /auth on the framework listener, with keyed secret rotation + request-time revocation.",
|
|
1261
1261
|
permissions: [],
|
|
1262
|
-
declaredEnv:
|
|
1262
|
+
declaredEnv: Lt,
|
|
1263
1263
|
httpRoutes: [te],
|
|
1264
1264
|
onActivate: (e) => C.sync(() => {
|
|
1265
1265
|
e.logger.info("auth routes active", {
|
|
@@ -1282,7 +1282,7 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
1282
1282
|
revocation: u
|
|
1283
1283
|
}) }
|
|
1284
1284
|
};
|
|
1285
|
-
},
|
|
1285
|
+
}, Lt = [
|
|
1286
1286
|
{
|
|
1287
1287
|
name: "VOLTRO_SESSION_SECRET_PREVIOUS",
|
|
1288
1288
|
required: !1,
|
|
@@ -1327,4 +1327,4 @@ var de = { ok: !0 }, fe = (e, t) => C.gen(function* () {
|
|
|
1327
1327
|
}
|
|
1328
1328
|
];
|
|
1329
1329
|
//#endregion
|
|
1330
|
-
export {
|
|
1330
|
+
export { Me as $, it as A, Qe as B, dt as C, F as D, ot as E, Ge as F, He as G, tt as H, Ke as I, De as J, rt as K, qe as L, Ze as M, Xe as N, z as O, We as P, Ae as Q, Ve as R, ut as S, lt as T, Be as U, nt as V, Ue as W, Ee as X, k as Y, A as Z, bt as _, At as a, Te as at, St as b, K as c, Se as ct, H as d, P as et, pt as f, Tt as g, wt as h, Dt as i, D as it, et as j, Je as k, q as l, we as lt, gt as m, Mt as n, N as nt, jt as o, Ce as ot, ft as p, R as q, Et as r, j as rt, kt as s, xe as st, It as t, ke as tt, mt as u, pe as ut, xt as v, ct as w, st as x, Ct as y, $e as z };
|