authfn 0.1.2 → 0.3.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/README.md +47 -292
- package/dist/core/account-linking.d.ts +30 -0
- package/dist/core/account-linking.d.ts.map +1 -0
- package/dist/core/account-linking.js +80 -0
- package/dist/core/account-linking.js.map +1 -0
- package/dist/core/account.d.ts +38 -0
- package/dist/core/account.d.ts.map +1 -0
- package/dist/core/account.js +164 -0
- package/dist/core/account.js.map +1 -0
- package/dist/core/admin-users.d.ts +50 -0
- package/dist/core/admin-users.d.ts.map +1 -0
- package/dist/core/admin-users.js +227 -0
- package/dist/core/admin-users.js.map +1 -0
- package/dist/core/api-keys.d.ts +40 -0
- package/dist/core/api-keys.d.ts.map +1 -0
- package/dist/core/api-keys.js +175 -0
- package/dist/core/api-keys.js.map +1 -0
- package/dist/core/cache.d.ts +18 -0
- package/dist/core/cache.d.ts.map +1 -0
- package/dist/core/cache.js +54 -0
- package/dist/core/cache.js.map +1 -0
- package/dist/core/cookies.d.ts +25 -0
- package/dist/core/cookies.d.ts.map +1 -0
- package/dist/core/cookies.js +89 -0
- package/dist/core/cookies.js.map +1 -0
- package/dist/core/delivery.d.ts +4 -0
- package/dist/core/delivery.d.ts.map +1 -0
- package/dist/core/delivery.js +37 -0
- package/dist/core/delivery.js.map +1 -0
- package/dist/core/environment.d.ts +4 -0
- package/dist/core/environment.d.ts.map +1 -0
- package/dist/core/environment.js +50 -0
- package/dist/core/environment.js.map +1 -0
- package/dist/core/errors.d.ts +123 -0
- package/dist/core/errors.d.ts.map +1 -0
- package/dist/core/errors.js +437 -0
- package/dist/core/errors.js.map +1 -0
- package/dist/core/gateway-routing.d.ts +88 -0
- package/dist/core/gateway-routing.d.ts.map +1 -0
- package/dist/core/gateway-routing.js +902 -0
- package/dist/core/gateway-routing.js.map +1 -0
- package/dist/core/limits.d.ts +4 -0
- package/dist/core/limits.d.ts.map +1 -0
- package/dist/core/limits.js +13 -0
- package/dist/core/limits.js.map +1 -0
- package/dist/core/oauth-accounts.d.ts +29 -0
- package/dist/core/oauth-accounts.d.ts.map +1 -0
- package/dist/core/oauth-accounts.js +123 -0
- package/dist/core/oauth-accounts.js.map +1 -0
- package/dist/core/observability.d.ts +4 -0
- package/dist/core/observability.d.ts.map +1 -0
- package/dist/core/observability.js +38 -0
- package/dist/core/observability.js.map +1 -0
- package/dist/core/passwords.d.ts +52 -0
- package/dist/core/passwords.d.ts.map +1 -0
- package/dist/core/passwords.js +468 -0
- package/dist/core/passwords.js.map +1 -0
- package/dist/core/placement-context.d.ts +90 -0
- package/dist/core/placement-context.d.ts.map +1 -0
- package/dist/core/placement-context.js +620 -0
- package/dist/core/placement-context.js.map +1 -0
- package/dist/core/plugin-runtime.d.ts +8 -0
- package/dist/core/plugin-runtime.d.ts.map +1 -0
- package/dist/core/plugin-runtime.js +15 -0
- package/dist/core/plugin-runtime.js.map +1 -0
- package/dist/core/rate-limit.d.ts +4 -0
- package/dist/core/rate-limit.d.ts.map +1 -0
- package/dist/core/rate-limit.js +177 -0
- package/dist/core/rate-limit.js.map +1 -0
- package/dist/core/regions.d.ts +47 -0
- package/dist/core/regions.d.ts.map +1 -0
- package/dist/core/regions.js +642 -0
- package/dist/core/regions.js.map +1 -0
- package/dist/core/session-responses.d.ts +10 -0
- package/dist/core/session-responses.d.ts.map +1 -0
- package/dist/core/session-responses.js +22 -0
- package/dist/core/session-responses.js.map +1 -0
- package/dist/core/sessions.d.ts +53 -0
- package/dist/core/sessions.d.ts.map +1 -0
- package/dist/core/sessions.js +442 -0
- package/dist/core/sessions.js.map +1 -0
- package/dist/core/two-factor.d.ts +34 -0
- package/dist/core/two-factor.d.ts.map +1 -0
- package/dist/core/two-factor.js +511 -0
- package/dist/core/two-factor.js.map +1 -0
- package/dist/core/users.d.ts +12 -0
- package/dist/core/users.d.ts.map +1 -0
- package/dist/core/users.js +74 -0
- package/dist/core/users.js.map +1 -0
- package/dist/core/verifications.d.ts +52 -0
- package/dist/core/verifications.d.ts.map +1 -0
- package/dist/core/verifications.js +522 -0
- package/dist/core/verifications.js.map +1 -0
- package/dist/http/envelopes.d.ts +10 -0
- package/dist/http/envelopes.d.ts.map +1 -0
- package/dist/http/envelopes.js +99 -0
- package/dist/http/envelopes.js.map +1 -0
- package/dist/http/router.d.ts +16 -0
- package/dist/http/router.d.ts.map +1 -0
- package/dist/http/router.js +347 -0
- package/dist/http/router.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +108 -0
- package/dist/index.js.map +1 -0
- package/dist/openapi.d.ts +4 -0
- package/dist/openapi.d.ts.map +1 -0
- package/dist/openapi.js +43 -0
- package/dist/openapi.js.map +1 -0
- package/dist/plugin-runner.d.ts +12 -0
- package/dist/plugin-runner.d.ts.map +1 -0
- package/dist/plugin-runner.js +206 -0
- package/dist/plugin-runner.js.map +1 -0
- package/dist/plugin-types.d.ts +205 -0
- package/dist/plugin-types.d.ts.map +1 -0
- package/dist/plugin-types.js +2 -0
- package/dist/plugin-types.js.map +1 -0
- package/dist/schema.d.ts +7 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +127 -0
- package/dist/schema.js.map +1 -0
- package/dist/types.d.ts +444 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +85 -59
package/README.md
CHANGED
|
@@ -1,292 +1,47 @@
|
|
|
1
|
-
# authfn
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
import { drizzleAdapter } from '@superfunctions/db/adapters';
|
|
49
|
-
|
|
50
|
-
const adapter = drizzleAdapter({ db, dialect: 'postgres' });
|
|
51
|
-
|
|
52
|
-
const auth = createAuthFn({
|
|
53
|
-
database: adapter,
|
|
54
|
-
namespace: 'authfn',
|
|
55
|
-
enableApi: true,
|
|
56
|
-
apiConfig: {
|
|
57
|
-
adminKey: process.env.ADMIN_KEY, // Optional: protect management API
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
### 4. Use with Libraries
|
|
63
|
-
|
|
64
|
-
Use the auth provider with any library accepting `@superfunctions/auth`:
|
|
65
|
-
|
|
66
|
-
```typescript
|
|
67
|
-
import { createConductBackend } from 'conduct-backend';
|
|
68
|
-
|
|
69
|
-
const conduct = createConductBackend({
|
|
70
|
-
database: adapter,
|
|
71
|
-
auth: auth.provider,
|
|
72
|
-
});
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
### 5. Mount API
|
|
76
|
-
|
|
77
|
-
Mount both the auth management API and your library's API:
|
|
78
|
-
|
|
79
|
-
```typescript
|
|
80
|
-
import express from 'express';
|
|
81
|
-
import { toExpress } from '@superfunctions/http-express';
|
|
82
|
-
|
|
83
|
-
const app = express();
|
|
84
|
-
|
|
85
|
-
// Mount auth management API
|
|
86
|
-
app.use('/api/auth', toExpress(auth.router));
|
|
87
|
-
|
|
88
|
-
// Mount your library's API
|
|
89
|
-
app.use('/api/conduct', toExpress(conduct.router));
|
|
90
|
-
|
|
91
|
-
app.listen(3000);
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
## API Reference
|
|
95
|
-
|
|
96
|
-
### createAuthFn(config)
|
|
97
|
-
|
|
98
|
-
Creates an authfn instance.
|
|
99
|
-
|
|
100
|
-
**Config Options:**
|
|
101
|
-
|
|
102
|
-
```typescript
|
|
103
|
-
{
|
|
104
|
-
database: Adapter; // Database adapter
|
|
105
|
-
namespace?: string; // Table prefix (default: 'authfn')
|
|
106
|
-
enableApi?: boolean; // Enable management API (default: false)
|
|
107
|
-
apiConfig?: {
|
|
108
|
-
basePath?: string; // API base path (default: '/auth')
|
|
109
|
-
adminKey?: string; // Admin key for managing keys
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
**Returns:**
|
|
115
|
-
|
|
116
|
-
```typescript
|
|
117
|
-
{
|
|
118
|
-
provider: AuthProvider; // Auth provider for use with libraries
|
|
119
|
-
router?: Router; // Management API router (if enabled)
|
|
120
|
-
createKey: Function; // Create API key programmatically
|
|
121
|
-
revokeKey: Function; // Revoke API key
|
|
122
|
-
getKey: Function; // Get API key by ID
|
|
123
|
-
listKeys: Function; // List API keys
|
|
124
|
-
}
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
### Management API Endpoints
|
|
128
|
-
|
|
129
|
-
When `enableApi` is true, the following endpoints are available:
|
|
130
|
-
|
|
131
|
-
#### POST /keys
|
|
132
|
-
|
|
133
|
-
Create a new API key.
|
|
134
|
-
|
|
135
|
-
**Request:**
|
|
136
|
-
```json
|
|
137
|
-
{
|
|
138
|
-
"name": "My API Key",
|
|
139
|
-
"resourceIds": ["project_abc", "project_def"],
|
|
140
|
-
"scopes": ["read", "write"],
|
|
141
|
-
"metadata": { "team": "engineering" },
|
|
142
|
-
"expiresAt": "2025-12-31T23:59:59Z"
|
|
143
|
-
}
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
**Response:**
|
|
147
|
-
```json
|
|
148
|
-
{
|
|
149
|
-
"id": "key_abc123",
|
|
150
|
-
"key": "ak_64characterhexstring..."
|
|
151
|
-
}
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
**Note:** The actual key value is only returned once during creation. Store it securely.
|
|
155
|
-
|
|
156
|
-
#### GET /keys
|
|
157
|
-
|
|
158
|
-
List all API keys (without key values).
|
|
159
|
-
|
|
160
|
-
**Query Parameters:**
|
|
161
|
-
- `resourceId` - Filter by resource ID
|
|
162
|
-
|
|
163
|
-
**Response:**
|
|
164
|
-
```json
|
|
165
|
-
{
|
|
166
|
-
"keys": [
|
|
167
|
-
{
|
|
168
|
-
"id": "key_abc123",
|
|
169
|
-
"name": "My API Key",
|
|
170
|
-
"resourceIds": ["project_abc"],
|
|
171
|
-
"scopes": ["read", "write"],
|
|
172
|
-
"metadata": { "team": "engineering" },
|
|
173
|
-
"expiresAt": "2025-12-31T23:59:59Z",
|
|
174
|
-
"lastUsedAt": "2025-01-15T10:30:00Z",
|
|
175
|
-
"createdAt": "2025-01-01T00:00:00Z"
|
|
176
|
-
}
|
|
177
|
-
]
|
|
178
|
-
}
|
|
179
|
-
```
|
|
180
|
-
|
|
181
|
-
#### GET /keys/:id
|
|
182
|
-
|
|
183
|
-
Get a specific API key by ID (without key value).
|
|
184
|
-
|
|
185
|
-
#### DELETE /keys/:id
|
|
186
|
-
|
|
187
|
-
Revoke an API key.
|
|
188
|
-
|
|
189
|
-
**Response:**
|
|
190
|
-
```json
|
|
191
|
-
{
|
|
192
|
-
"success": true
|
|
193
|
-
}
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
### Programmatic Usage
|
|
197
|
-
|
|
198
|
-
You can also create and manage keys programmatically:
|
|
199
|
-
|
|
200
|
-
```typescript
|
|
201
|
-
// Create a key
|
|
202
|
-
const { id, key } = await auth.createKey({
|
|
203
|
-
name: 'My API Key',
|
|
204
|
-
resourceIds: ['project_abc'],
|
|
205
|
-
scopes: ['read', 'write'],
|
|
206
|
-
expiresAt: new Date('2025-12-31'),
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
// List keys
|
|
210
|
-
const keys = await auth.listKeys();
|
|
211
|
-
|
|
212
|
-
// Get a key
|
|
213
|
-
const apiKey = await auth.getKey('key_abc123');
|
|
214
|
-
|
|
215
|
-
// Revoke a key
|
|
216
|
-
await auth.revokeKey('key_abc123');
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
## Database Schema
|
|
220
|
-
|
|
221
|
-
authfn creates a single table:
|
|
222
|
-
|
|
223
|
-
### `{namespace}_api_keys`
|
|
224
|
-
|
|
225
|
-
- `id` - Unique identifier
|
|
226
|
-
- `key` - API key value (unique, indexed)
|
|
227
|
-
- `name` - Descriptive name
|
|
228
|
-
- `resource_ids` - JSON array of resource IDs
|
|
229
|
-
- `scopes` - JSON array of scopes/permissions
|
|
230
|
-
- `metadata` - JSON object for additional data
|
|
231
|
-
- `expires_at` - Expiration timestamp
|
|
232
|
-
- `last_used_at` - Last usage timestamp
|
|
233
|
-
- `revoked_at` - Revocation timestamp
|
|
234
|
-
- `created_at` - Creation timestamp
|
|
235
|
-
|
|
236
|
-
## Security
|
|
237
|
-
|
|
238
|
-
- API keys are 64-character hex strings with a prefix
|
|
239
|
-
- Keys are validated against database on each request
|
|
240
|
-
- Expired and revoked keys are rejected
|
|
241
|
-
- Management API requires admin key authentication
|
|
242
|
-
- Key values are never returned in list/get operations
|
|
243
|
-
|
|
244
|
-
## Integration Examples
|
|
245
|
-
|
|
246
|
-
### With Conduct Backend
|
|
247
|
-
|
|
248
|
-
```typescript
|
|
249
|
-
const auth = createAuthFn({
|
|
250
|
-
database: adapter,
|
|
251
|
-
enableApi: true,
|
|
252
|
-
});
|
|
253
|
-
|
|
254
|
-
const conduct = createConductBackend({
|
|
255
|
-
database: adapter,
|
|
256
|
-
auth: {
|
|
257
|
-
...auth.provider,
|
|
258
|
-
// Map resourceIds to projectIds
|
|
259
|
-
authenticate: async (request) => {
|
|
260
|
-
const session = await auth.provider.authenticate(request);
|
|
261
|
-
if (!session) return null;
|
|
262
|
-
return {
|
|
263
|
-
...session,
|
|
264
|
-
projectIds: session.resourceIds,
|
|
265
|
-
};
|
|
266
|
-
},
|
|
267
|
-
},
|
|
268
|
-
});
|
|
269
|
-
```
|
|
270
|
-
|
|
271
|
-
### Custom Implementation
|
|
272
|
-
|
|
273
|
-
Implement your own auth provider using the same abstraction:
|
|
274
|
-
|
|
275
|
-
```typescript
|
|
276
|
-
import type { AuthProvider, AuthSession } from '@superfunctions/auth';
|
|
277
|
-
|
|
278
|
-
const customAuth: AuthProvider = {
|
|
279
|
-
async authenticate(request: Request): Promise<AuthSession | null> {
|
|
280
|
-
// Your custom auth logic
|
|
281
|
-
return {
|
|
282
|
-
id: 'user_123',
|
|
283
|
-
type: 'custom',
|
|
284
|
-
resourceIds: ['resource_1'],
|
|
285
|
-
};
|
|
286
|
-
},
|
|
287
|
-
};
|
|
288
|
-
```
|
|
289
|
-
|
|
290
|
-
## License
|
|
291
|
-
|
|
292
|
-
MIT
|
|
1
|
+
# authfn
|
|
2
|
+
|
|
3
|
+
`authfn` is the session and identity kernel for the Superfunctions ecosystem. It composes declared plugins, manages browser sessions, generates schema/OpenAPI output, and provides `@superfunctions/auth` provider integration without bundling every auth method into the root package.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install authfn
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Install only the plugin packages you use (`@authfn/password`, `@authfn/email-otp`, `@authfn/social-oauth`, `@authfn/api-keys`, `@authfn/two-factor`, `@authfn/multi-region`, `@authfn/native-handoff`) plus `@authfn/client` for browsers.
|
|
12
|
+
|
|
13
|
+
## Two-stage API
|
|
14
|
+
|
|
15
|
+
Declare a side-effect-free app, then inject runtime dependencies:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { memoryAdapter } from '@superfunctions/db/testing';
|
|
19
|
+
import { authFnPlugins, authfn } from 'authfn';
|
|
20
|
+
import { authFnPasswordPlugin } from '@authfn/password';
|
|
21
|
+
import { authFnEmailOtpPlugin } from '@authfn/email-otp';
|
|
22
|
+
|
|
23
|
+
const authApp = authfn({
|
|
24
|
+
namespace: 'authfn',
|
|
25
|
+
plugins: authFnPlugins(
|
|
26
|
+
authFnPasswordPlugin(),
|
|
27
|
+
authFnEmailOtpPlugin()
|
|
28
|
+
)
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const auth = authApp.createServer({
|
|
32
|
+
database: memoryAdapter({ debug: false }),
|
|
33
|
+
pluginRuntime: {
|
|
34
|
+
emailOtp: {
|
|
35
|
+
delivery: {
|
|
36
|
+
async send(input) {
|
|
37
|
+
return { sent: true, metadata: { channel: input.channel } };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
Mount `auth.router` with a `@superfunctions/http-*` adapter and use `auth.provider` anywhere an `@superfunctions/auth` provider is expected. `authApp.getSchema()` works without creating a server.
|
|
46
|
+
|
|
47
|
+
Full reference: [authfn docs → SDKs → authfn](https://authfn.superfunctions.dev/docs/sdk/core).
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { AuthFnRuntimeConfig, AuthFnSocialProviderId, AuthFnUserRecord } from '../types.js';
|
|
2
|
+
export declare function allowsOAuthLinkByVerifiedEmail(config: Pick<AuthFnRuntimeConfig, 'accountLinking'>, providerId: AuthFnSocialProviderId): {
|
|
3
|
+
allowed: boolean;
|
|
4
|
+
requireExistingEmailVerified: boolean;
|
|
5
|
+
requireProviderEmailVerified: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare function allowsOtpSignUpExistingUser(config: Pick<AuthFnRuntimeConfig, 'accountLinking'>): boolean;
|
|
8
|
+
export declare function allowsPasswordForAuthenticatedUser(config: Pick<AuthFnRuntimeConfig, 'accountLinking'>): {
|
|
9
|
+
allowed: boolean;
|
|
10
|
+
requireExistingEmailVerified: boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare function emitAccountLinkedEvent(config: Pick<AuthFnRuntimeConfig, 'observability'>, input: {
|
|
13
|
+
request?: Request;
|
|
14
|
+
user: AuthFnUserRecord;
|
|
15
|
+
method: string;
|
|
16
|
+
provider?: AuthFnSocialProviderId;
|
|
17
|
+
regionId?: string;
|
|
18
|
+
metadata?: Record<string, unknown>;
|
|
19
|
+
}): Promise<void>;
|
|
20
|
+
export declare function emitAccountLinkingConflictEvent(config: Pick<AuthFnRuntimeConfig, 'observability'>, input: {
|
|
21
|
+
request?: Request;
|
|
22
|
+
user?: AuthFnUserRecord;
|
|
23
|
+
primaryEmail?: string;
|
|
24
|
+
method: string;
|
|
25
|
+
provider?: AuthFnSocialProviderId;
|
|
26
|
+
regionId?: string;
|
|
27
|
+
reason: string;
|
|
28
|
+
metadata?: Record<string, unknown>;
|
|
29
|
+
}): Promise<void>;
|
|
30
|
+
//# sourceMappingURL=account-linking.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-linking.d.ts","sourceRoot":"","sources":["../../src/core/account-linking.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,mBAAmB,EACnB,sBAAsB,EACtB,gBAAgB,EACjB,MAAM,aAAa,CAAC;AAGrB,wBAAgB,8BAA8B,CAC5C,MAAM,EAAE,IAAI,CAAC,mBAAmB,EAAE,gBAAgB,CAAC,EACnD,UAAU,EAAE,sBAAsB,GACjC;IACD,OAAO,EAAE,OAAO,CAAC;IACjB,4BAA4B,EAAE,OAAO,CAAC;IACtC,4BAA4B,EAAE,OAAO,CAAC;CACvC,CAwBA;AAED,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,IAAI,CAAC,mBAAmB,EAAE,gBAAgB,CAAC,GAClD,OAAO,CAET;AAED,wBAAgB,kCAAkC,CAChD,MAAM,EAAE,IAAI,CAAC,mBAAmB,EAAE,gBAAgB,CAAC,GAClD;IACD,OAAO,EAAE,OAAO,CAAC;IACjB,4BAA4B,EAAE,OAAO,CAAC;CACvC,CAoBA;AAED,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,IAAI,CAAC,mBAAmB,EAAE,eAAe,CAAC,EAClD,KAAK,EAAE;IACL,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,gBAAgB,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,sBAAsB,CAAC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC,GACA,OAAO,CAAC,IAAI,CAAC,CAef;AAED,wBAAsB,+BAA+B,CACnD,MAAM,EAAE,IAAI,CAAC,mBAAmB,EAAE,eAAe,CAAC,EAClD,KAAK,EAAE;IACL,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,gBAAgB,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,sBAAsB,CAAC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC,GACA,OAAO,CAAC,IAAI,CAAC,CAgBf"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { emitAuthEvent, eventRequestId } from './observability.js';
|
|
2
|
+
export function allowsOAuthLinkByVerifiedEmail(config, providerId) {
|
|
3
|
+
const policy = config.accountLinking?.oauthByVerifiedEmail;
|
|
4
|
+
if (!policy) {
|
|
5
|
+
return {
|
|
6
|
+
allowed: false,
|
|
7
|
+
requireExistingEmailVerified: true,
|
|
8
|
+
requireProviderEmailVerified: true
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
if (policy === true) {
|
|
12
|
+
return {
|
|
13
|
+
allowed: true,
|
|
14
|
+
requireExistingEmailVerified: true,
|
|
15
|
+
requireProviderEmailVerified: true
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
const providers = policy.providers;
|
|
19
|
+
return {
|
|
20
|
+
allowed: !providers?.length || providers.includes(providerId),
|
|
21
|
+
requireExistingEmailVerified: policy.requireExistingEmailVerified ?? true,
|
|
22
|
+
requireProviderEmailVerified: policy.requireProviderEmailVerified ?? true
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export function allowsOtpSignUpExistingUser(config) {
|
|
26
|
+
return config.accountLinking?.otpSignUpExistingUser ?? false;
|
|
27
|
+
}
|
|
28
|
+
export function allowsPasswordForAuthenticatedUser(config) {
|
|
29
|
+
const policy = config.accountLinking?.passwordForAuthenticatedUser;
|
|
30
|
+
if (!policy) {
|
|
31
|
+
return {
|
|
32
|
+
allowed: false,
|
|
33
|
+
requireExistingEmailVerified: true
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
if (policy === true) {
|
|
37
|
+
return {
|
|
38
|
+
allowed: true,
|
|
39
|
+
requireExistingEmailVerified: true
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
allowed: true,
|
|
44
|
+
requireExistingEmailVerified: policy.requireExistingEmailVerified ?? true
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
export async function emitAccountLinkedEvent(config, input) {
|
|
48
|
+
await emitAuthEvent(config, {
|
|
49
|
+
type: 'authfn.account_linked',
|
|
50
|
+
requestId: eventRequestId(input.request),
|
|
51
|
+
actorId: input.user.id,
|
|
52
|
+
userId: input.user.id,
|
|
53
|
+
regionId: input.regionId,
|
|
54
|
+
provider: input.provider,
|
|
55
|
+
outcome: 'linked',
|
|
56
|
+
metadata: {
|
|
57
|
+
...(input.metadata ?? {}),
|
|
58
|
+
method: input.method,
|
|
59
|
+
primaryEmail: input.user.primaryEmail
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
export async function emitAccountLinkingConflictEvent(config, input) {
|
|
64
|
+
await emitAuthEvent(config, {
|
|
65
|
+
type: 'authfn.account_linking.conflict',
|
|
66
|
+
requestId: eventRequestId(input.request),
|
|
67
|
+
actorId: input.user?.id,
|
|
68
|
+
userId: input.user?.id,
|
|
69
|
+
regionId: input.regionId,
|
|
70
|
+
provider: input.provider,
|
|
71
|
+
outcome: 'conflict',
|
|
72
|
+
metadata: {
|
|
73
|
+
method: input.method,
|
|
74
|
+
primaryEmail: input.primaryEmail ?? input.user?.primaryEmail,
|
|
75
|
+
reason: input.reason,
|
|
76
|
+
...(input.metadata ?? {})
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=account-linking.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-linking.js","sourceRoot":"","sources":["../../src/core/account-linking.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEnE,MAAM,UAAU,8BAA8B,CAC5C,MAAmD,EACnD,UAAkC;IAMlC,MAAM,MAAM,GAAG,MAAM,CAAC,cAAc,EAAE,oBAAoB,CAAC;IAC3D,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO;YACL,OAAO,EAAE,KAAK;YACd,4BAA4B,EAAE,IAAI;YAClC,4BAA4B,EAAE,IAAI;SACnC,CAAC;IACJ,CAAC;IAED,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QACpB,OAAO;YACL,OAAO,EAAE,IAAI;YACb,4BAA4B,EAAE,IAAI;YAClC,4BAA4B,EAAE,IAAI;SACnC,CAAC;IACJ,CAAC;IAED,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;IACnC,OAAO;QACL,OAAO,EAAE,CAAC,SAAS,EAAE,MAAM,IAAI,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC;QAC7D,4BAA4B,EAAE,MAAM,CAAC,4BAA4B,IAAI,IAAI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AM,CAAC,KAAK,UAAU,+BAA+B,CACnD,MAAkD,EAClD,KASC;IAED,MAAM,aAAa,CAAC,MAAM,EAAE;QAC1B,IAAI,EAAE,iCAAiC;QACvC,SAAS,EAAE,cAAc,CAAC,KAAK,CAAC,OAAO,CAAC;QACxC,OAAO,EAAE,KAAK,CAAC,IAAI,EAAE,EAAE;QACvB,MAAM,EAAE,KAAK,CAAC,IAAI,EAAE,EAAE;QACtB,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,OAAO,EAAE,UAAU;QACnB,QAAQ,EAAE;YACR,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,YAAY,EAAE,KAAK,CAAC,YAAY,IAAI,KAAK,CAAC,IAAI,EAAE,YAAY;YAC5D,MAAM,EAAE,KAAK,CAAC,MAAM;YACpB,GAAG,CAAC,KAAK,CAAC,QAAQ,IAAI,EAAE,CAAC;SAC1B;KACF,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { AuthFnAccountDeletionResult, AuthFnRuntimeConfig, AuthFnHooks, AuthFnSession, AuthFnSocialProviderId, AuthFnUserRecord } from '../types.js';
|
|
2
|
+
export interface AuthFnAccountOAuthAccount {
|
|
3
|
+
id: string;
|
|
4
|
+
provider: AuthFnSocialProviderId;
|
|
5
|
+
email?: string;
|
|
6
|
+
profile?: Record<string, unknown>;
|
|
7
|
+
createdAt: Date | string;
|
|
8
|
+
updatedAt: Date | string;
|
|
9
|
+
}
|
|
10
|
+
export interface AuthFnAccountDetails {
|
|
11
|
+
user: {
|
|
12
|
+
id: string;
|
|
13
|
+
primaryEmail?: string;
|
|
14
|
+
emailVerifiedAt?: Date | string | null;
|
|
15
|
+
metadata?: Record<string, unknown>;
|
|
16
|
+
createdAt: Date | string;
|
|
17
|
+
updatedAt: Date | string;
|
|
18
|
+
};
|
|
19
|
+
hasPassword: boolean;
|
|
20
|
+
twoFactorEnabled: boolean;
|
|
21
|
+
oauthAccounts: AuthFnAccountOAuthAccount[];
|
|
22
|
+
methods: {
|
|
23
|
+
password: boolean;
|
|
24
|
+
emailOtp: boolean;
|
|
25
|
+
oauth: AuthFnSocialProviderId[];
|
|
26
|
+
twoFactor: boolean;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export declare function getAccountDetailsForUser(config: Pick<AuthFnRuntimeConfig, 'database' | 'namespace' | 'plugins'>, user: AuthFnUserRecord): Promise<AuthFnAccountDetails>;
|
|
30
|
+
export declare function deleteAccountForUser(config: AuthFnRuntimeConfig, hooks: Partial<AuthFnHooks>, input: {
|
|
31
|
+
user: AuthFnUserRecord;
|
|
32
|
+
session?: AuthFnSession;
|
|
33
|
+
request?: Request;
|
|
34
|
+
actorId?: string;
|
|
35
|
+
/** True for administrator/delegated deletion, independent of actor identity. */
|
|
36
|
+
delegated?: boolean;
|
|
37
|
+
}): Promise<AuthFnAccountDeletionResult>;
|
|
38
|
+
//# sourceMappingURL=account.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../../src/core/account.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,2BAA2B,EAC3B,mBAAmB,EACnB,WAAW,EACX,aAAa,EAEb,sBAAsB,EACtB,gBAAgB,EACjB,MAAM,aAAa,CAAC;AAUrB,MAAM,WAAW,yBAAyB;IACxC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,sBAAsB,CAAC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,SAAS,EAAE,IAAI,GAAG,MAAM,CAAC;IACzB,SAAS,EAAE,IAAI,GAAG,MAAM,CAAC;CAC1B;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE;QACJ,EAAE,EAAE,MAAM,CAAC;QACX,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,eAAe,CAAC,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,CAAC;QACvC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QACnC,SAAS,EAAE,IAAI,GAAG,MAAM,CAAC;QACzB,SAAS,EAAE,IAAI,GAAG,MAAM,CAAC;KAC1B,CAAC;IACF,WAAW,EAAE,OAAO,CAAC;IACrB,gBAAgB,EAAE,OAAO,CAAC;IAC1B,aAAa,EAAE,yBAAyB,EAAE,CAAC;IAC3C,OAAO,EAAE;QACP,QAAQ,EAAE,OAAO,CAAC;QAClB,QAAQ,EAAE,OAAO,CAAC;QAClB,KAAK,EAAE,sBAAsB,EAAE,CAAC;QAChC,SAAS,EAAE,OAAO,CAAC;KACpB,CAAC;CACH;AAED,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,IAAI,CAAC,mBAAmB,EAAE,UAAU,GAAG,WAAW,GAAG,SAAS,CAAC,EACvE,IAAI,EAAE,gBAAgB,GACrB,OAAO,CAAC,oBAAoB,CAAC,CAiC/B;AAED,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,mBAAmB,EAC3B,KAAK,EAAE,OAAO,CAAC,WAAW,CAAC,EAC3B,KAAK,EAAE;IACL,IAAI,EAAE,gBAAgB,CAAC;IACvB,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gFAAgF;IAChF,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,GACA,OAAO,CAAC,2BAA2B,CAAC,CA0GtC"}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { getPasswordCredentialByUserId } from './passwords.js';
|
|
2
|
+
import { hasConfirmedTwoFactorEnrollment } from './two-factor.js';
|
|
3
|
+
import { listOAuthAccountsForUser } from './oauth-accounts.js';
|
|
4
|
+
import { emitAuthEvent, eventRequestId } from './observability.js';
|
|
5
|
+
import { getMultiRegionPluginConfig, unregisterRegionLookupForIdentifier } from './regions.js';
|
|
6
|
+
export async function getAccountDetailsForUser(config, user) {
|
|
7
|
+
const hasPasswordPlugin = hasPlugin(config, 'password');
|
|
8
|
+
const hasSocialOAuthPlugin = hasPlugin(config, 'socialOAuth');
|
|
9
|
+
const hasEmailOtpPlugin = hasPlugin(config, 'emailOtp');
|
|
10
|
+
const hasTwoFactorPlugin = hasPlugin(config, 'twoFactor');
|
|
11
|
+
const [passwordCredential, oauthAccounts, twoFactorEnabled] = await Promise.all([
|
|
12
|
+
hasPasswordPlugin ? getPasswordCredentialByUserId(config, user.id) : null,
|
|
13
|
+
hasSocialOAuthPlugin ? listOAuthAccountsForUser(config, user.id) : [],
|
|
14
|
+
hasTwoFactorPlugin ? hasConfirmedTwoFactorEnrollment(config, user.id) : false
|
|
15
|
+
]);
|
|
16
|
+
const sanitizedOAuthAccounts = oauthAccounts
|
|
17
|
+
.map(sanitizeOAuthAccount)
|
|
18
|
+
.sort((left, right) => left.provider.localeCompare(right.provider));
|
|
19
|
+
return {
|
|
20
|
+
user: {
|
|
21
|
+
id: user.id,
|
|
22
|
+
primaryEmail: user.primaryEmail,
|
|
23
|
+
emailVerifiedAt: user.emailVerifiedAt ?? null,
|
|
24
|
+
metadata: user.metadata,
|
|
25
|
+
createdAt: user.createdAt,
|
|
26
|
+
updatedAt: user.updatedAt
|
|
27
|
+
},
|
|
28
|
+
hasPassword: Boolean(passwordCredential),
|
|
29
|
+
twoFactorEnabled,
|
|
30
|
+
oauthAccounts: sanitizedOAuthAccounts,
|
|
31
|
+
methods: {
|
|
32
|
+
password: Boolean(passwordCredential),
|
|
33
|
+
emailOtp: hasEmailOtpPlugin && Boolean(user.primaryEmail),
|
|
34
|
+
oauth: sanitizedOAuthAccounts.map((account) => account.provider),
|
|
35
|
+
twoFactor: twoFactorEnabled
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export async function deleteAccountForUser(config, hooks, input) {
|
|
40
|
+
const user = input.user;
|
|
41
|
+
const actorId = input.actorId ?? user.id;
|
|
42
|
+
const counts = {};
|
|
43
|
+
const hookContext = {
|
|
44
|
+
config,
|
|
45
|
+
request: input.request,
|
|
46
|
+
session: input.session,
|
|
47
|
+
actorId,
|
|
48
|
+
operationState: new Map()
|
|
49
|
+
};
|
|
50
|
+
try {
|
|
51
|
+
await hooks.beforeAccountDelete?.(hookContext, {
|
|
52
|
+
userId: user.id,
|
|
53
|
+
primaryEmail: user.primaryEmail,
|
|
54
|
+
sessionId: input.session?.id,
|
|
55
|
+
delegated: input.delegated === true
|
|
56
|
+
});
|
|
57
|
+
if (hasPlugin(config, 'twoFactor')) {
|
|
58
|
+
const enrollments = await config.database.findMany({
|
|
59
|
+
model: 'two_factor_enrollments',
|
|
60
|
+
where: [{ field: 'userId', operator: 'eq', value: user.id }],
|
|
61
|
+
namespace: namespace(config)
|
|
62
|
+
});
|
|
63
|
+
let recoveryCodes = 0;
|
|
64
|
+
for (const enrollment of enrollments) {
|
|
65
|
+
recoveryCodes += await deleteMany(config, 'two_factor_recovery_codes', 'enrollmentId', enrollment.id);
|
|
66
|
+
}
|
|
67
|
+
counts.twoFactorRecoveryCodes = recoveryCodes;
|
|
68
|
+
counts.twoFactorChallenges = await deleteMany(config, 'two_factor_challenges', 'userId', user.id);
|
|
69
|
+
counts.twoFactorEnrollments = await deleteMany(config, 'two_factor_enrollments', 'userId', user.id);
|
|
70
|
+
}
|
|
71
|
+
if (hasPlugin(config, 'nativeHandoff')) {
|
|
72
|
+
counts.nativeHandoffCodes = await deleteMany(config, 'native_handoff_codes', 'userId', user.id);
|
|
73
|
+
}
|
|
74
|
+
if (hasPlugin(config, 'apiKey')) {
|
|
75
|
+
counts.apiKeys = await deleteMany(config, 'api_keys', 'userId', user.id);
|
|
76
|
+
}
|
|
77
|
+
if (hasPlugin(config, 'socialOAuth')) {
|
|
78
|
+
counts.oauthAccounts = await deleteMany(config, 'oauth_accounts', 'userId', user.id);
|
|
79
|
+
}
|
|
80
|
+
if (hasPlugin(config, 'password')) {
|
|
81
|
+
counts.passwordCredentials = await deleteMany(config, 'password_credentials', 'userId', user.id);
|
|
82
|
+
}
|
|
83
|
+
if (hasPlugin(config, 'emailOtp') && user.primaryEmail) {
|
|
84
|
+
counts.otpChallenges = await deleteMany(config, 'otp_challenges', 'email', user.primaryEmail.trim().toLowerCase());
|
|
85
|
+
}
|
|
86
|
+
const multiRegion = getMultiRegionPluginConfig(config);
|
|
87
|
+
if (multiRegion && user.primaryEmail) {
|
|
88
|
+
await unregisterRegionLookupForIdentifier(config, multiRegion, user.primaryEmail);
|
|
89
|
+
}
|
|
90
|
+
if (multiRegion) {
|
|
91
|
+
counts.regionProfiles = await deleteMany(config, 'region_profiles', 'userId', user.id);
|
|
92
|
+
}
|
|
93
|
+
counts.sessions = await deleteMany(config, 'sessions', 'userId', user.id);
|
|
94
|
+
counts.users = await deleteMany(config, 'users', 'id', user.id);
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
try {
|
|
98
|
+
await hooks.afterAccountDeleteFailure?.(hookContext, {
|
|
99
|
+
userId: user.id,
|
|
100
|
+
primaryEmail: user.primaryEmail,
|
|
101
|
+
sessionId: input.session?.id,
|
|
102
|
+
delegated: input.delegated === true,
|
|
103
|
+
error
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
catch (hookError) {
|
|
107
|
+
if (hookError instanceof Error && hookError.cause === undefined) {
|
|
108
|
+
hookError.cause = error;
|
|
109
|
+
}
|
|
110
|
+
throw hookError;
|
|
111
|
+
}
|
|
112
|
+
throw error;
|
|
113
|
+
}
|
|
114
|
+
const result = {
|
|
115
|
+
deleted: true,
|
|
116
|
+
userId: user.id,
|
|
117
|
+
primaryEmail: user.primaryEmail,
|
|
118
|
+
delegated: input.delegated === true,
|
|
119
|
+
counts
|
|
120
|
+
};
|
|
121
|
+
await hooks.afterAccountDelete?.(hookContext, result);
|
|
122
|
+
try {
|
|
123
|
+
await emitAuthEvent(config, {
|
|
124
|
+
type: 'authfn.account.deleted',
|
|
125
|
+
requestId: eventRequestId(input.request),
|
|
126
|
+
actorId,
|
|
127
|
+
sessionId: input.session?.id,
|
|
128
|
+
userId: user.id,
|
|
129
|
+
regionId: input.session?.regionId,
|
|
130
|
+
outcome: 'deleted',
|
|
131
|
+
metadata: {
|
|
132
|
+
counts
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
// Deletion should not be reported as failed if observability is unavailable.
|
|
138
|
+
}
|
|
139
|
+
return result;
|
|
140
|
+
}
|
|
141
|
+
function hasPlugin(config, name) {
|
|
142
|
+
return config.plugins.some((plugin) => plugin.name === name);
|
|
143
|
+
}
|
|
144
|
+
function sanitizeOAuthAccount(account) {
|
|
145
|
+
return {
|
|
146
|
+
id: account.id,
|
|
147
|
+
provider: account.provider,
|
|
148
|
+
email: account.email,
|
|
149
|
+
profile: account.profile,
|
|
150
|
+
createdAt: account.createdAt,
|
|
151
|
+
updatedAt: account.updatedAt
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
async function deleteMany(config, model, field, value) {
|
|
155
|
+
return config.database.deleteMany({
|
|
156
|
+
model,
|
|
157
|
+
where: [{ field, operator: 'eq', value }],
|
|
158
|
+
namespace: namespace(config)
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
function namespace(config) {
|
|
162
|
+
return config.namespace ?? 'authfn';
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=account.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account.js","sourceRoot":"","sources":["../../src/core/account.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,6BAA6B,EAAE,MAAM,gBAAgB,CAAC;AAC/D,OAAO,EAAE,+BAA+B,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAE,wBAAwB,EAAiC,MAAM,qBAAqB,CAAC;AAC9F,O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