@prunellejs/auth 0.0.0-stage → 0.6.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/llms.txt +89 -0
- package/package.json +27 -4
- package/src/crypto.ts +130 -0
- package/src/http.ts +168 -0
- package/src/index.ts +566 -0
- package/src/links.ts +150 -0
- package/src/oauth-routes.ts +255 -0
- package/src/oauth.ts +155 -0
- package/src/org-routes.ts +216 -0
- package/src/orgs.ts +386 -0
- package/src/passkey-client.ts +207 -0
- package/src/passkey-routes.ts +210 -0
- package/src/passkeys.ts +425 -0
- package/src/routes.ts +294 -0
- package/src/session.ts +380 -0
- package/src/sqlite-ext.ts +516 -0
- package/src/sqlite.ts +351 -0
- package/src/store-ext.ts +425 -0
- package/src/store.ts +310 -0
- package/src/totp-routes.ts +138 -0
- package/src/totp.ts +338 -0
- package/src/webauthn-crypto.ts +284 -0
- package/README.md +0 -3
package/src/store-ext.ts
ADDED
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
// Extended AuthStore types (TOTP 2FA, Passkeys/WebAuthn, Organizations) and in-memory implementation.
|
|
2
|
+
// All extension methods are optional on `AuthStore` so existing custom stores remain 100% compatible.
|
|
3
|
+
|
|
4
|
+
export interface TotpRecord {
|
|
5
|
+
userId: string
|
|
6
|
+
/** AES-256-GCM encrypted base32 secret (`v1.<iv>.<ciphertext>`). */
|
|
7
|
+
encryptedSecret: string
|
|
8
|
+
enabled: boolean
|
|
9
|
+
/** Last accepted 30-second TOTP time step (prevents replay within the same window). */
|
|
10
|
+
lastUsedStep?: number | undefined
|
|
11
|
+
createdAt: number
|
|
12
|
+
updatedAt: number
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface RecoveryCodeRecord {
|
|
16
|
+
id: string
|
|
17
|
+
userId: string
|
|
18
|
+
codeHash: string
|
|
19
|
+
salt: string
|
|
20
|
+
createdAt: number
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface PasskeyRecord {
|
|
24
|
+
/** Base64url-encoded WebAuthn credential ID. */
|
|
25
|
+
id: string
|
|
26
|
+
userId: string
|
|
27
|
+
/** JSON-serialized JWK public key derived from the COSE key. */
|
|
28
|
+
publicKeyJwk: string
|
|
29
|
+
/** COSE algorithm identifier: -7 (ES256), -257 (RS256), -8 (EdDSA). */
|
|
30
|
+
algorithm: number
|
|
31
|
+
signCount: number
|
|
32
|
+
transports?: string[] | undefined
|
|
33
|
+
name?: string | undefined
|
|
34
|
+
aaguid?: string | undefined
|
|
35
|
+
createdAt: number
|
|
36
|
+
lastUsedAt?: number | undefined
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface PasskeySummary {
|
|
40
|
+
id: string
|
|
41
|
+
name?: string | undefined
|
|
42
|
+
createdAt: number
|
|
43
|
+
lastUsedAt?: number | undefined
|
|
44
|
+
transports?: string[] | undefined
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface Organization {
|
|
48
|
+
id: string
|
|
49
|
+
slug: string
|
|
50
|
+
name: string
|
|
51
|
+
createdAt: number
|
|
52
|
+
updatedAt: number
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface OrgMembership {
|
|
56
|
+
orgId: string
|
|
57
|
+
userId: string
|
|
58
|
+
role: string
|
|
59
|
+
createdAt: number
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface OrgInvitation {
|
|
63
|
+
id: string
|
|
64
|
+
orgId: string
|
|
65
|
+
email: string
|
|
66
|
+
role: string
|
|
67
|
+
invitedBy: string
|
|
68
|
+
tokenHash: string
|
|
69
|
+
expiresAt: number
|
|
70
|
+
createdAt: number
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface UserOrgSummary {
|
|
74
|
+
org: Organization
|
|
75
|
+
role: string
|
|
76
|
+
joinedAt: number
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface UserExportExt {
|
|
80
|
+
totp?: { enabled: boolean, createdAt: number, recoveryCodesRemaining: number } | undefined
|
|
81
|
+
passkeys?: PasskeySummary[] | undefined
|
|
82
|
+
organizations?: Array<{ orgId: string, slug: string, name: string, role: string, joinedAt: number }> | undefined
|
|
83
|
+
invitations?: Array<{ id: string, orgId: string, email: string, role: string, expiresAt: number, createdAt: number }> | undefined
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface AuthStoreExt {
|
|
87
|
+
getTotp?(userId: string): TotpRecord | undefined | Promise<TotpRecord | undefined>
|
|
88
|
+
setTotp?(record: TotpRecord): void | Promise<void>
|
|
89
|
+
deleteTotp?(userId: string): void | Promise<void>
|
|
90
|
+
listRecoveryCodes?(userId: string): RecoveryCodeRecord[] | Promise<RecoveryCodeRecord[]>
|
|
91
|
+
setRecoveryCodes?(userId: string, codes: RecoveryCodeRecord[]): void | Promise<void>
|
|
92
|
+
consumeRecoveryCode?(id: string): boolean | Promise<boolean>
|
|
93
|
+
deleteRecoveryCodes?(userId: string): void | Promise<void>
|
|
94
|
+
|
|
95
|
+
getPasskey?(credentialId: string): PasskeyRecord | undefined | Promise<PasskeyRecord | undefined>
|
|
96
|
+
listPasskeys?(userId: string): PasskeyRecord[] | Promise<PasskeyRecord[]>
|
|
97
|
+
createPasskey?(record: PasskeyRecord): void | Promise<void>
|
|
98
|
+
updatePasskeyUsage?(credentialId: string, signCount: number, lastUsedAt: number): void | Promise<void>
|
|
99
|
+
deletePasskey?(userId: string, credentialId: string): boolean | Promise<boolean>
|
|
100
|
+
deleteUserPasskeys?(userId: string): void | Promise<void>
|
|
101
|
+
|
|
102
|
+
createOrg?(org: Organization): Organization | Promise<Organization>
|
|
103
|
+
getOrgById?(id: string): Organization | undefined | Promise<Organization | undefined>
|
|
104
|
+
getOrgBySlug?(slug: string): Organization | undefined | Promise<Organization | undefined>
|
|
105
|
+
deleteOrg?(orgId: string): void | Promise<void>
|
|
106
|
+
getOrgMember?(orgId: string, userId: string): OrgMembership | undefined | Promise<OrgMembership | undefined>
|
|
107
|
+
listOrgMembers?(orgId: string): OrgMembership[] | Promise<OrgMembership[]>
|
|
108
|
+
listUserOrgMemberships?(userId: string): UserOrgSummary[] | Promise<UserOrgSummary[]>
|
|
109
|
+
addOrgMember?(membership: OrgMembership): OrgMembership | Promise<OrgMembership>
|
|
110
|
+
updateOrgMemberRole?(orgId: string, userId: string, role: string): OrgMembership | undefined | Promise<OrgMembership | undefined>
|
|
111
|
+
removeOrgMember?(orgId: string, userId: string): boolean | Promise<boolean>
|
|
112
|
+
createOrgInvite?(invite: OrgInvitation): OrgInvitation | Promise<OrgInvitation>
|
|
113
|
+
getOrgInviteByTokenHash?(tokenHash: string): OrgInvitation | undefined | Promise<OrgInvitation | undefined>
|
|
114
|
+
listOrgInvites?(orgId: string): OrgInvitation[] | Promise<OrgInvitation[]>
|
|
115
|
+
deleteOrgInvite?(orgId: string, inviteId: string): boolean | Promise<boolean>
|
|
116
|
+
consumeOrgInvite?(tokenHash: string): OrgInvitation | undefined | Promise<OrgInvitation | undefined>
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function toPasskeySummary(record: PasskeyRecord): PasskeySummary {
|
|
120
|
+
return {
|
|
121
|
+
id: record.id,
|
|
122
|
+
createdAt: record.createdAt,
|
|
123
|
+
...(record.name !== undefined ? { name: record.name } : {}),
|
|
124
|
+
...(record.lastUsedAt !== undefined ? { lastUsedAt: record.lastUsedAt } : {}),
|
|
125
|
+
...(record.transports !== undefined ? { transports: [...record.transports] } : {}),
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export interface MemoryStoreExtHooks {
|
|
130
|
+
methods: Required<AuthStoreExt>
|
|
131
|
+
exportUserExt: (userId: string, email: string, now: number) => UserExportExt
|
|
132
|
+
deleteUserExt: (userId: string, email: string | undefined) => void
|
|
133
|
+
pruneExpiredExt: (now: number) => void
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
interface MemoryExtState {
|
|
137
|
+
totp: Map<string, TotpRecord>
|
|
138
|
+
recoveryCodes: Map<string, RecoveryCodeRecord>
|
|
139
|
+
passkeys: Map<string, PasskeyRecord>
|
|
140
|
+
orgs: Map<string, Organization>
|
|
141
|
+
orgsBySlug: Map<string, string>
|
|
142
|
+
orgMembers: Map<string, OrgMembership>
|
|
143
|
+
orgInvites: Map<string, OrgInvitation>
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const memberKey = (orgId: string, userId: string): string => `${orgId}:${userId}`
|
|
147
|
+
|
|
148
|
+
function buildMemoryTotpPasskeyMethods(state: MemoryExtState) {
|
|
149
|
+
const clonePasskey = (rec: PasskeyRecord): PasskeyRecord => ({
|
|
150
|
+
...rec,
|
|
151
|
+
...(rec.transports ? { transports: [...rec.transports] } : {}),
|
|
152
|
+
})
|
|
153
|
+
return {
|
|
154
|
+
getTotp(userId: string): TotpRecord | undefined {
|
|
155
|
+
const rec = state.totp.get(userId)
|
|
156
|
+
return rec ? { ...rec } : undefined
|
|
157
|
+
},
|
|
158
|
+
setTotp(record: TotpRecord): void {
|
|
159
|
+
state.totp.set(record.userId, { ...record })
|
|
160
|
+
},
|
|
161
|
+
deleteTotp(userId: string): void {
|
|
162
|
+
state.totp.delete(userId)
|
|
163
|
+
},
|
|
164
|
+
listRecoveryCodes(userId: string): RecoveryCodeRecord[] {
|
|
165
|
+
const out: RecoveryCodeRecord[] = []
|
|
166
|
+
for (const rec of state.recoveryCodes.values()) {
|
|
167
|
+
if (rec.userId === userId)
|
|
168
|
+
out.push({ ...rec })
|
|
169
|
+
}
|
|
170
|
+
return out
|
|
171
|
+
},
|
|
172
|
+
setRecoveryCodes(userId: string, codes: RecoveryCodeRecord[]): void {
|
|
173
|
+
for (const [id, rec] of state.recoveryCodes) {
|
|
174
|
+
if (rec.userId === userId)
|
|
175
|
+
state.recoveryCodes.delete(id)
|
|
176
|
+
}
|
|
177
|
+
for (const rec of codes)
|
|
178
|
+
state.recoveryCodes.set(rec.id, { ...rec })
|
|
179
|
+
},
|
|
180
|
+
consumeRecoveryCode(id: string): boolean {
|
|
181
|
+
return state.recoveryCodes.delete(id)
|
|
182
|
+
},
|
|
183
|
+
deleteRecoveryCodes(userId: string): void {
|
|
184
|
+
for (const [id, rec] of state.recoveryCodes) {
|
|
185
|
+
if (rec.userId === userId)
|
|
186
|
+
state.recoveryCodes.delete(id)
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
getPasskey(credentialId: string): PasskeyRecord | undefined {
|
|
190
|
+
const rec = state.passkeys.get(credentialId)
|
|
191
|
+
return rec ? clonePasskey(rec) : undefined
|
|
192
|
+
},
|
|
193
|
+
listPasskeys(userId: string): PasskeyRecord[] {
|
|
194
|
+
const out: PasskeyRecord[] = []
|
|
195
|
+
for (const rec of state.passkeys.values()) {
|
|
196
|
+
if (rec.userId === userId)
|
|
197
|
+
out.push(clonePasskey(rec))
|
|
198
|
+
}
|
|
199
|
+
out.sort((a, b) => a.createdAt - b.createdAt)
|
|
200
|
+
return out
|
|
201
|
+
},
|
|
202
|
+
createPasskey(record: PasskeyRecord): void {
|
|
203
|
+
state.passkeys.set(record.id, clonePasskey(record))
|
|
204
|
+
},
|
|
205
|
+
updatePasskeyUsage(credentialId: string, signCount: number, lastUsedAt: number): void {
|
|
206
|
+
const rec = state.passkeys.get(credentialId)
|
|
207
|
+
if (rec) {
|
|
208
|
+
rec.signCount = signCount
|
|
209
|
+
rec.lastUsedAt = lastUsedAt
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
deletePasskey(userId: string, credentialId: string): boolean {
|
|
213
|
+
const rec = state.passkeys.get(credentialId)
|
|
214
|
+
if (!rec || rec.userId !== userId)
|
|
215
|
+
return false
|
|
216
|
+
return state.passkeys.delete(credentialId)
|
|
217
|
+
},
|
|
218
|
+
deleteUserPasskeys(userId: string): void {
|
|
219
|
+
for (const [id, rec] of state.passkeys) {
|
|
220
|
+
if (rec.userId === userId)
|
|
221
|
+
state.passkeys.delete(id)
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function buildMemoryOrgMethods(state: MemoryExtState) {
|
|
228
|
+
return {
|
|
229
|
+
createOrg(org: Organization): Organization {
|
|
230
|
+
const copy: Organization = { ...org, slug: org.slug.toLowerCase() }
|
|
231
|
+
if (state.orgsBySlug.has(copy.slug))
|
|
232
|
+
throw new Error(`prunelle: organization slug "${copy.slug}" already exists`)
|
|
233
|
+
state.orgs.set(copy.id, copy)
|
|
234
|
+
state.orgsBySlug.set(copy.slug, copy.id)
|
|
235
|
+
return { ...copy }
|
|
236
|
+
},
|
|
237
|
+
getOrgById(id: string): Organization | undefined {
|
|
238
|
+
const rec = state.orgs.get(id)
|
|
239
|
+
return rec ? { ...rec } : undefined
|
|
240
|
+
},
|
|
241
|
+
getOrgBySlug(slug: string): Organization | undefined {
|
|
242
|
+
const id = state.orgsBySlug.get(slug.toLowerCase())
|
|
243
|
+
if (id === undefined)
|
|
244
|
+
return undefined
|
|
245
|
+
const rec = state.orgs.get(id)
|
|
246
|
+
return rec ? { ...rec } : undefined
|
|
247
|
+
},
|
|
248
|
+
deleteOrg(orgId: string): void {
|
|
249
|
+
const rec = state.orgs.get(orgId)
|
|
250
|
+
if (rec)
|
|
251
|
+
state.orgsBySlug.delete(rec.slug)
|
|
252
|
+
state.orgs.delete(orgId)
|
|
253
|
+
for (const [k, m] of state.orgMembers) {
|
|
254
|
+
if (m.orgId === orgId)
|
|
255
|
+
state.orgMembers.delete(k)
|
|
256
|
+
}
|
|
257
|
+
for (const [k, inv] of state.orgInvites) {
|
|
258
|
+
if (inv.orgId === orgId)
|
|
259
|
+
state.orgInvites.delete(k)
|
|
260
|
+
}
|
|
261
|
+
},
|
|
262
|
+
getOrgMember(orgId: string, userId: string): OrgMembership | undefined {
|
|
263
|
+
const m = state.orgMembers.get(memberKey(orgId, userId))
|
|
264
|
+
return m ? { ...m } : undefined
|
|
265
|
+
},
|
|
266
|
+
listOrgMembers(orgId: string): OrgMembership[] {
|
|
267
|
+
const out: OrgMembership[] = []
|
|
268
|
+
for (const m of state.orgMembers.values()) {
|
|
269
|
+
if (m.orgId === orgId)
|
|
270
|
+
out.push({ ...m })
|
|
271
|
+
}
|
|
272
|
+
out.sort((a, b) => a.createdAt - b.createdAt)
|
|
273
|
+
return out
|
|
274
|
+
},
|
|
275
|
+
listUserOrgMemberships(userId: string): UserOrgSummary[] {
|
|
276
|
+
const out: UserOrgSummary[] = []
|
|
277
|
+
for (const m of state.orgMembers.values()) {
|
|
278
|
+
if (m.userId !== userId)
|
|
279
|
+
continue
|
|
280
|
+
const org = state.orgs.get(m.orgId)
|
|
281
|
+
if (org)
|
|
282
|
+
out.push({ org: { ...org }, role: m.role, joinedAt: m.createdAt })
|
|
283
|
+
}
|
|
284
|
+
out.sort((a, b) => a.joinedAt - b.joinedAt)
|
|
285
|
+
return out
|
|
286
|
+
},
|
|
287
|
+
addOrgMember(membership: OrgMembership): OrgMembership {
|
|
288
|
+
const copy: OrgMembership = { ...membership }
|
|
289
|
+
state.orgMembers.set(memberKey(copy.orgId, copy.userId), copy)
|
|
290
|
+
return { ...copy }
|
|
291
|
+
},
|
|
292
|
+
updateOrgMemberRole(orgId: string, userId: string, role: string): OrgMembership | undefined {
|
|
293
|
+
const cur = state.orgMembers.get(memberKey(orgId, userId))
|
|
294
|
+
if (!cur)
|
|
295
|
+
return undefined
|
|
296
|
+
cur.role = role
|
|
297
|
+
return { ...cur }
|
|
298
|
+
},
|
|
299
|
+
removeOrgMember(orgId: string, userId: string): boolean {
|
|
300
|
+
return state.orgMembers.delete(memberKey(orgId, userId))
|
|
301
|
+
},
|
|
302
|
+
createOrgInvite(invite: OrgInvitation): OrgInvitation {
|
|
303
|
+
const copy: OrgInvitation = { ...invite, email: invite.email.trim().toLowerCase() }
|
|
304
|
+
state.orgInvites.set(copy.tokenHash, copy)
|
|
305
|
+
return { ...copy }
|
|
306
|
+
},
|
|
307
|
+
getOrgInviteByTokenHash(tokenHash: string): OrgInvitation | undefined {
|
|
308
|
+
const inv = state.orgInvites.get(tokenHash)
|
|
309
|
+
if (!inv)
|
|
310
|
+
return undefined
|
|
311
|
+
if (inv.expiresAt <= Date.now()) {
|
|
312
|
+
state.orgInvites.delete(tokenHash)
|
|
313
|
+
return undefined
|
|
314
|
+
}
|
|
315
|
+
return { ...inv }
|
|
316
|
+
},
|
|
317
|
+
listOrgInvites(orgId: string): OrgInvitation[] {
|
|
318
|
+
const now = Date.now()
|
|
319
|
+
const out: OrgInvitation[] = []
|
|
320
|
+
for (const [k, inv] of state.orgInvites) {
|
|
321
|
+
if (inv.expiresAt <= now) {
|
|
322
|
+
state.orgInvites.delete(k)
|
|
323
|
+
continue
|
|
324
|
+
}
|
|
325
|
+
if (inv.orgId === orgId)
|
|
326
|
+
out.push({ ...inv })
|
|
327
|
+
}
|
|
328
|
+
out.sort((a, b) => a.createdAt - b.createdAt)
|
|
329
|
+
return out
|
|
330
|
+
},
|
|
331
|
+
deleteOrgInvite(orgId: string, inviteId: string): boolean {
|
|
332
|
+
for (const [k, inv] of state.orgInvites) {
|
|
333
|
+
if (inv.orgId === orgId && inv.id === inviteId) {
|
|
334
|
+
state.orgInvites.delete(k)
|
|
335
|
+
return true
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return false
|
|
339
|
+
},
|
|
340
|
+
consumeOrgInvite(tokenHash: string): OrgInvitation | undefined {
|
|
341
|
+
const inv = state.orgInvites.get(tokenHash)
|
|
342
|
+
if (!inv)
|
|
343
|
+
return undefined
|
|
344
|
+
state.orgInvites.delete(tokenHash)
|
|
345
|
+
if (inv.expiresAt <= Date.now())
|
|
346
|
+
return undefined
|
|
347
|
+
return { ...inv }
|
|
348
|
+
},
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
export function createMemoryStoreExt(): MemoryStoreExtHooks {
|
|
353
|
+
const state: MemoryExtState = {
|
|
354
|
+
totp: new Map(),
|
|
355
|
+
recoveryCodes: new Map(),
|
|
356
|
+
passkeys: new Map(),
|
|
357
|
+
orgs: new Map(),
|
|
358
|
+
orgsBySlug: new Map(),
|
|
359
|
+
orgMembers: new Map(),
|
|
360
|
+
orgInvites: new Map(),
|
|
361
|
+
}
|
|
362
|
+
const tp = buildMemoryTotpPasskeyMethods(state)
|
|
363
|
+
const org = buildMemoryOrgMethods(state)
|
|
364
|
+
|
|
365
|
+
return {
|
|
366
|
+
methods: { ...tp, ...org },
|
|
367
|
+
exportUserExt(userId, email, now) {
|
|
368
|
+
const totpRec = state.totp.get(userId)
|
|
369
|
+
const rcCount = tp.listRecoveryCodes(userId).length
|
|
370
|
+
const userPasskeys = tp.listPasskeys(userId).map(toPasskeySummary)
|
|
371
|
+
const organizations = org.listUserOrgMemberships(userId).map(item => ({
|
|
372
|
+
orgId: item.org.id,
|
|
373
|
+
slug: item.org.slug,
|
|
374
|
+
name: item.org.name,
|
|
375
|
+
role: item.role,
|
|
376
|
+
joinedAt: item.joinedAt,
|
|
377
|
+
}))
|
|
378
|
+
const invitations: NonNullable<UserExportExt['invitations']> = []
|
|
379
|
+
const normEmail = email.trim().toLowerCase()
|
|
380
|
+
for (const [k, inv] of state.orgInvites) {
|
|
381
|
+
if (inv.expiresAt <= now) {
|
|
382
|
+
state.orgInvites.delete(k)
|
|
383
|
+
continue
|
|
384
|
+
}
|
|
385
|
+
if (inv.email === normEmail || inv.invitedBy === userId) {
|
|
386
|
+
invitations.push({
|
|
387
|
+
id: inv.id,
|
|
388
|
+
orgId: inv.orgId,
|
|
389
|
+
email: inv.email,
|
|
390
|
+
role: inv.role,
|
|
391
|
+
expiresAt: inv.expiresAt,
|
|
392
|
+
createdAt: inv.createdAt,
|
|
393
|
+
})
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
invitations.sort((a, b) => a.createdAt - b.createdAt)
|
|
397
|
+
return {
|
|
398
|
+
...(totpRec ? { totp: { enabled: totpRec.enabled, createdAt: totpRec.createdAt, recoveryCodesRemaining: rcCount } } : {}),
|
|
399
|
+
passkeys: userPasskeys,
|
|
400
|
+
organizations,
|
|
401
|
+
invitations,
|
|
402
|
+
}
|
|
403
|
+
},
|
|
404
|
+
deleteUserExt(userId, email) {
|
|
405
|
+
state.totp.delete(userId)
|
|
406
|
+
tp.deleteRecoveryCodes(userId)
|
|
407
|
+
tp.deleteUserPasskeys(userId)
|
|
408
|
+
for (const [k, m] of state.orgMembers) {
|
|
409
|
+
if (m.userId === userId)
|
|
410
|
+
state.orgMembers.delete(k)
|
|
411
|
+
}
|
|
412
|
+
const normEmail = email?.trim().toLowerCase()
|
|
413
|
+
for (const [k, inv] of state.orgInvites) {
|
|
414
|
+
if (inv.invitedBy === userId || (normEmail !== undefined && inv.email === normEmail))
|
|
415
|
+
state.orgInvites.delete(k)
|
|
416
|
+
}
|
|
417
|
+
},
|
|
418
|
+
pruneExpiredExt(now) {
|
|
419
|
+
for (const [k, inv] of state.orgInvites) {
|
|
420
|
+
if (inv.expiresAt <= now)
|
|
421
|
+
state.orgInvites.delete(k)
|
|
422
|
+
}
|
|
423
|
+
},
|
|
424
|
+
}
|
|
425
|
+
}
|