@opensaas/stack-auth 0.37.0 → 0.39.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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +60 -0
- package/CLAUDE.md +50 -3
- package/dist/config/adopt-better-auth-tables.d.ts +23 -3
- package/dist/config/adopt-better-auth-tables.d.ts.map +1 -1
- package/dist/config/adopt-better-auth-tables.js +7 -2
- package/dist/config/adopt-better-auth-tables.js.map +1 -1
- package/dist/config/derive-auth-lists.d.ts +6 -1
- package/dist/config/derive-auth-lists.d.ts.map +1 -1
- package/dist/config/derive-auth-lists.js +63 -16
- package/dist/config/derive-auth-lists.js.map +1 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +12 -5
- package/dist/config/index.js.map +1 -1
- package/dist/config/plugin.d.ts.map +1 -1
- package/dist/config/plugin.js +7 -2
- package/dist/config/plugin.js.map +1 -1
- package/dist/config/types.d.ts +62 -7
- package/dist/config/types.d.ts.map +1 -1
- package/dist/server/build-better-auth-options.test.d.ts +2 -0
- package/dist/server/build-better-auth-options.test.d.ts.map +1 -0
- package/dist/server/build-better-auth-options.test.js +29 -0
- package/dist/server/build-better-auth-options.test.js.map +1 -0
- package/dist/server/get-session-from-auth.test.d.ts +2 -0
- package/dist/server/get-session-from-auth.test.d.ts.map +1 -0
- package/dist/server/get-session-from-auth.test.js +25 -0
- package/dist/server/get-session-from-auth.test.js.map +1 -0
- package/dist/server/index.d.ts +108 -15
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +151 -63
- package/dist/server/index.js.map +1 -1
- package/dist/server/schema-converter.d.ts +15 -6
- package/dist/server/schema-converter.d.ts.map +1 -1
- package/dist/server/schema-converter.js +14 -2
- package/dist/server/schema-converter.js.map +1 -1
- package/package.json +5 -5
- package/src/config/adopt-better-auth-tables.ts +31 -4
- package/src/config/derive-auth-lists.ts +82 -21
- package/src/config/index.ts +18 -5
- package/src/config/plugin.ts +7 -2
- package/src/config/types.ts +63 -9
- package/src/server/build-better-auth-options.test.ts +59 -0
- package/src/server/get-session-from-auth.test.ts +52 -0
- package/src/server/index.ts +273 -41
- package/src/server/schema-converter.ts +29 -8
- package/tests/adopt-better-auth-tables.test.ts +73 -0
- package/tests/config.test.ts +161 -0
- package/tests/derive-auth-lists.test.ts +104 -0
- package/tests/generated-fk-shape.test.ts +81 -0
- package/tests/plugin-schema-placement.test.ts +39 -0
- package/tests/rate-limit-e2e.test.ts +239 -0
- package/tests/schema-converter.test.ts +58 -0
- package/tests/server.test.ts +310 -4
- package/tsconfig.tsbuildinfo +1 -1
- package/vitest.config.ts +7 -1
package/.turbo/turbo-build.log
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,65 @@
|
|
|
1
1
|
# @opensaas/stack-auth
|
|
2
2
|
|
|
3
|
+
## 0.39.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#928](https://github.com/OpenSaasAU/stack/pull/928) [`d5a04bb`](https://github.com/OpenSaasAU/stack/commit/d5a04bb7936a2663fbbfcacbf44f777d423dbc05) Thanks [@borisno2](https://github.com/borisno2)! - Add a `rateLimit.storage` option to `authPlugin`. Setting it to `'database'` derives a fifth `RateLimit` Auth list, mirroring better-auth's own database-backed rate limiter table (`key`/`count`/`lastRequest`, no timestamps, no defaults) so an app that wants a persisted limiter no longer has to hand-write the model.
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
authPlugin({
|
|
11
|
+
rateLimit: {
|
|
12
|
+
enabled: true,
|
|
13
|
+
storage: 'database',
|
|
14
|
+
},
|
|
15
|
+
})
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
`rateLimit` also carries the same `modelName`/`fields`/`tableName`/`schema` adoption knobs as the other four models, so an app with an existing limiter table can adopt it. `access.rateLimit` grants access to the derived list (closed by default, per ADR-0013). `adoptBetterAuthTables({ rateLimit: true })` adopts an existing database-backed limiter table alongside the other four. Setting `rateLimit.storage` via the `betterAuthOptions` passthrough is now rejected — use the first-class option instead.
|
|
19
|
+
|
|
20
|
+
### Patch Changes
|
|
21
|
+
|
|
22
|
+
- [#930](https://github.com/OpenSaasAU/stack/pull/930) [`bb04e44`](https://github.com/OpenSaasAU/stack/commit/bb04e44c0f758e00b61d34efc829d0d25b0be3d2) Thanks [@borisno2](https://github.com/borisno2)! - Fix the better-auth schema converter mapping a `bigint: true` field attribute to a 32-bit `Int` instead of a `BigInt` column, which silently overflowed on values like a millisecond epoch.
|
|
23
|
+
|
|
24
|
+
- [#923](https://github.com/OpenSaasAU/stack/pull/923) [`d0763c5`](https://github.com/OpenSaasAU/stack/commit/d0763c56ff15dd3bb16e00e5dae4d216b7bbdbaf) Thanks [@borisno2](https://github.com/borisno2)! - `getSessionFromAuth()` now accepts an auth instance from either `createAuth()` overload — including the plugin-narrowed one — without a cast.
|
|
25
|
+
|
|
26
|
+
## 0.38.0
|
|
27
|
+
|
|
28
|
+
### Minor Changes
|
|
29
|
+
|
|
30
|
+
- [#888](https://github.com/OpenSaasAU/stack/pull/888) [`8183827`](https://github.com/OpenSaasAU/stack/commit/8183827ec65d6cfd7153028f84057ab65dfdc7dd) Thanks [@borisno2](https://github.com/borisno2)! - `buildBetterAuthOptions()` and `createAuth()` now accept an optional third argument — your app's `betterAuthPlugins` array, the same array passed to `authPlugin({ betterAuthPlugins })` — so the returned options/`Auth` type carries the literal plugin tuple instead of the widened `BetterAuthOptions`/`Auth<BetterAuthOptions>`. Without this, `betterAuth()` constructed from the widened return loses plugin-derived `auth.api.*` endpoints (e.g. `emailOTP()`'s `signInEmailOTP`) and a `customSession()` plugin's replaced session shape.
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
export const appBetterAuthPlugins = [emailOTP({ sendVerificationOTP })] // same array passed to authPlugin({ betterAuthPlugins })
|
|
34
|
+
|
|
35
|
+
export const auth = betterAuth({
|
|
36
|
+
...(await buildBetterAuthOptions(config, rawOpensaasContext, appBetterAuthPlugins)),
|
|
37
|
+
})
|
|
38
|
+
// auth.api.signInEmailOTP is now typed, and auth.api.getSession() returns your customSession() shape.
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
The supplied tuple is for typing only — the plugin array used at runtime is always the one resolved from `authPlugin({ betterAuthPlugins })`. Passing a tuple that isn't the same plugin instances in the same order throws, naming the mismatch, so the two can't silently drift apart. Calling either function with no third argument is unchanged — same widened return type, same runtime options, fully backwards compatible.
|
|
42
|
+
|
|
43
|
+
Also, `AuthConfig`/`NormalizedAuthConfig`'s `betterAuthPlugins` field is now typed as better-auth's own `BetterAuthPlugin[]` instead of `any[]`.
|
|
44
|
+
|
|
45
|
+
- [#889](https://github.com/OpenSaasAU/stack/pull/889) [`b9b9357`](https://github.com/OpenSaasAU/stack/commit/b9b935719774b01a81cfd2082387b76806c1a484) Thanks [@borisno2](https://github.com/borisno2)! - Fix `getSessionFromAuth` to project `sessionFields` from the _resolved_ better-auth session instead of only its `user` sub-object. A `customSession` plugin's replaced shape with no `user` key is now correctly treated as a signed-in session (never misreported as anonymous), and a session-only field (e.g. the admin plugin's `impersonatedBy`) is now resolvable. Errors from the underlying session lookup now propagate instead of silently becoming `null`, and a `sessionFields` entry that can't be resolved is omitted and logs a warning (once per field, per process) instead of vanishing silently.
|
|
46
|
+
|
|
47
|
+
The scaffolded `getSession()` — the CLI feature generator's `lib/auth.ts` template, and `examples/starter-auth`/`examples/auth-demo` — now call this single shared helper, reading `sessionFields` from the resolved config at runtime instead of baking a field list in at generation time. `examples/auth-demo`'s `getSession()` also now correctly returns `null` for an anonymous visitor (previously returned a truthy object of `undefined` values).
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
authPlugin({ sessionFields: ['userId', 'email', 'name', 'role'] })
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
```typescript
|
|
54
|
+
// lib/auth.ts
|
|
55
|
+
export async function getSession() {
|
|
56
|
+
const resolvedConfig = await config
|
|
57
|
+
const authConfig = resolvedConfig._pluginData?.auth as NormalizedAuthConfig | undefined
|
|
58
|
+
const sessionFields = authConfig?.sessionFields ?? ['userId', 'email', 'name']
|
|
59
|
+
return getSessionFromAuth(auth, sessionFields, await headers())
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
3
63
|
## 0.37.0
|
|
4
64
|
|
|
5
65
|
### Minor Changes
|
package/CLAUDE.md
CHANGED
|
@@ -28,8 +28,8 @@ Auto-generated lists:
|
|
|
28
28
|
|
|
29
29
|
### Server (`src/server/index.ts`)
|
|
30
30
|
|
|
31
|
-
- `createAuth(config, rawContext?)` - Creates Better-auth instance with MCP plugin support
|
|
32
|
-
- `buildBetterAuthOptions(config, rawContext?)` - Returns the same `BetterAuthOptions` `createAuth()` builds, without constructing an instance — for apps that need to hand-wire their own `betterAuth()`
|
|
31
|
+
- `createAuth(config, rawContext?, betterAuthPlugins?)` - Creates Better-auth instance with MCP plugin support
|
|
32
|
+
- `buildBetterAuthOptions(config, rawContext?, betterAuthPlugins?)` - Returns the same `BetterAuthOptions` `createAuth()` builds, without constructing an instance — for apps that need to hand-wire their own `betterAuth()`. The optional third argument (the app's own `betterAuthPlugins` array) makes the return type carry that literal plugin tuple instead of the widened array type — see "Typed `auth.api.*` reads" below.
|
|
33
33
|
- Returns `{ handler, signIn, signOut, ... }` - Better-auth methods
|
|
34
34
|
|
|
35
35
|
### Client (`src/client/index.ts`)
|
|
@@ -235,7 +235,8 @@ const context = createContext(config, prisma, session)
|
|
|
235
235
|
|
|
236
236
|
### Session Fields Configuration
|
|
237
237
|
|
|
238
|
-
|
|
238
|
+
`sessionFields` describes a **flattened projection** of the resolved better-auth session, not
|
|
239
|
+
the session's own shape:
|
|
239
240
|
|
|
240
241
|
```typescript
|
|
241
242
|
authPlugin({ sessionFields: ['userId', 'email', 'name', 'role'] })
|
|
@@ -247,6 +248,15 @@ access: {
|
|
|
247
248
|
}
|
|
248
249
|
```
|
|
249
250
|
|
|
251
|
+
`getSessionFromAuth()` (`@opensaas/stack-auth/server`) is the single implementation of this
|
|
252
|
+
projection — the scaffolded `getSession()` calls it with `sessionFields` read from the resolved
|
|
253
|
+
config at runtime. Each name resolves against a fixed precedence (a top-level key on the
|
|
254
|
+
resolved session, then `user`, then `session`), with `userId` special-cased to the user's `id`.
|
|
255
|
+
A `customSession` better-auth plugin fully replaces the resolved shape and can nest fields
|
|
256
|
+
anywhere; reconciling that against `sessionFields` is the app's job — an unresolvable name is
|
|
257
|
+
omitted and warns once (per field, per process) rather than silently becoming `undefined`. See
|
|
258
|
+
the `sessionFields` reference (`docs/content/reference/auth.md`) for the full contract.
|
|
259
|
+
|
|
250
260
|
### Session Type Safety
|
|
251
261
|
|
|
252
262
|
To get autocomplete and type safety for session fields, use module augmentation:
|
|
@@ -391,6 +401,43 @@ can't be synchronous. It gives an incremental path onto `createAuth()`: adopt
|
|
|
391
401
|
the builder first, then fold options into `betterAuthOptions` above as the
|
|
392
402
|
stack grows first-class config for them.
|
|
393
403
|
|
|
404
|
+
**Typed `auth.api.*` reads.** Called with just `(config, context)`, both
|
|
405
|
+
`buildBetterAuthOptions()` and `createAuth()` return the widened
|
|
406
|
+
`BetterAuthOptions` / `Auth<BetterAuthOptions>` — better-auth infers plugin
|
|
407
|
+
endpoints and a `customSession()`'s replaced session shape from the _literal_
|
|
408
|
+
options type, so the widened form erases them (an `emailOTP()` plugin loses
|
|
409
|
+
`auth.api.signInEmailOTP`; `auth.api.getSession()` falls back to `{ user,
|
|
410
|
+
session }` instead of a `customSession()` shape). Both functions take the
|
|
411
|
+
app's `betterAuthPlugins` array — the exact same array passed to
|
|
412
|
+
`authPlugin({ betterAuthPlugins })` — as an optional third argument, and their
|
|
413
|
+
return type then carries that literal tuple (plus the `nextCookies()` the
|
|
414
|
+
stack always appends last) instead of the widened array type:
|
|
415
|
+
|
|
416
|
+
```typescript
|
|
417
|
+
export const appBetterAuthPlugins = [emailOTP({ sendVerificationOTP })] // same array passed to authPlugin({ betterAuthPlugins })
|
|
418
|
+
|
|
419
|
+
export const auth = betterAuth({
|
|
420
|
+
...(await buildBetterAuthOptions(config, rawOpensaasContext, appBetterAuthPlugins)),
|
|
421
|
+
})
|
|
422
|
+
// auth.api.signInEmailOTP is now typed.
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
The supplied tuple is for typing only — the plugin array used at runtime is
|
|
426
|
+
always the one resolved from `authPlugin({ betterAuthPlugins })` — so both
|
|
427
|
+
functions verify the supplied tuple is the same plugin instances in the same
|
|
428
|
+
order as the resolved array, throwing a prefixed error naming the mismatch if
|
|
429
|
+
not (`assertPluginTupleMatchesResolved` in `src/server/index.ts`). This is
|
|
430
|
+
what closes the drift hole a hand-rolled re-pass of the plugin array would
|
|
431
|
+
otherwise open.
|
|
432
|
+
|
|
433
|
+
`createAuth()`'s lazy `Proxy` does not behave identically to a real `Auth`
|
|
434
|
+
instance for every property regardless of which form you use — every access,
|
|
435
|
+
including a non-function property, is surfaced through an `async` wrapper (so
|
|
436
|
+
`auth.options` reads back as a `Promise`, not the plain object a real
|
|
437
|
+
instance returns synchronously). Reach for `buildBetterAuthOptions()` plus
|
|
438
|
+
`betterAuth()` instead when the app reads `auth.api.*` in typed code — it
|
|
439
|
+
constructs a real instance and does not have this gap.
|
|
440
|
+
|
|
394
441
|
## Integration Points
|
|
395
442
|
|
|
396
443
|
### With @opensaas/stack-core
|
|
@@ -100,6 +100,7 @@ export type AdoptBetterAuthTablesOptions = {
|
|
|
100
100
|
session?: Record<string, string>;
|
|
101
101
|
account?: Record<string, string>;
|
|
102
102
|
verification?: Record<string, string>;
|
|
103
|
+
rateLimit?: Record<string, string>;
|
|
103
104
|
};
|
|
104
105
|
/**
|
|
105
106
|
* Set every model's physical table name to better-auth's own default
|
|
@@ -131,14 +132,33 @@ export type AdoptBetterAuthTablesOptions = {
|
|
|
131
132
|
session?: string;
|
|
132
133
|
account?: string;
|
|
133
134
|
verification?: string;
|
|
135
|
+
rateLimit?: string;
|
|
134
136
|
};
|
|
137
|
+
/**
|
|
138
|
+
* Also adopt an existing database-backed rate limiter table, deriving a
|
|
139
|
+
* fifth `<prefix>RateLimit` Auth list alongside the other four (per
|
|
140
|
+
* ADR-0007). Better-auth only creates this table when
|
|
141
|
+
* `rateLimit.storage: 'database'` — most installs use the in-memory
|
|
142
|
+
* limiter, so this defaults to `false` and must be opted into explicitly.
|
|
143
|
+
* The returned fragment sets `rateLimit: { enabled: true, storage:
|
|
144
|
+
* 'database', modelName: ... }`; override `enabled`/`window`/`max` by
|
|
145
|
+
* setting `rateLimit` again on your own `authPlugin` config after spreading
|
|
146
|
+
* this fragment.
|
|
147
|
+
*
|
|
148
|
+
* @default false
|
|
149
|
+
*/
|
|
150
|
+
rateLimit?: boolean;
|
|
135
151
|
};
|
|
136
152
|
/**
|
|
137
153
|
* The adoption-relevant slice of {@link AuthConfig}: the plugin-level `schema`
|
|
138
|
-
* and the per-model `modelName`/`fields
|
|
139
|
-
*
|
|
154
|
+
* and the per-model `modelName`/`fields` (`user`/`session`/`account`/
|
|
155
|
+
* `verification` always; `rateLimit` only when the `rateLimit` option is set).
|
|
156
|
+
* Returned (not the full `AuthConfig`) so it spreads cleanly into the
|
|
157
|
+
* developer's own `authPlugin` config.
|
|
140
158
|
*/
|
|
141
|
-
export type AdoptBetterAuthTablesConfig = Pick<AuthConfig, 'schema' | 'user' | 'session' | 'account' | 'verification'
|
|
159
|
+
export type AdoptBetterAuthTablesConfig = Pick<AuthConfig, 'schema' | 'user' | 'session' | 'account' | 'verification'> & {
|
|
160
|
+
rateLimit?: AuthConfig['rateLimit'];
|
|
161
|
+
};
|
|
142
162
|
/**
|
|
143
163
|
* Build the adoption {@link AuthConfig} fragment for a pre-existing better-auth
|
|
144
164
|
* installation.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adopt-better-auth-tables.d.ts","sourceRoot":"","sources":["../../src/config/adopt-better-auth-tables.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;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E,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QACrC,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KACnC,CAAA;IAED;;;;;;;;;;;;;;OAcG;IACH,uBAAuB,CAAC,EAAE,OAAO,CAAA;IAEjC;;;;;;;;OAQG;IACH,UAAU,CAAC,EAAE;QACX,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,OAAO,CAAC,EAAE,MAAM,CAAA;QAChB,OAAO,CAAC,EAAE,MAAM,CAAA;QAChB,YAAY,CAAC,EAAE,MAAM,CAAA;QACrB,SAAS,CAAC,EAAE,MAAM,CAAA;KACnB,CAAA;IAED;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB,CAAA;AAoBD;;;;;;GAMG;AACH,MAAM,MAAM,2BAA2B,GAAG,IAAI,CAC5C,UAAU,EACV,QAAQ,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,cAAc,CAC3D,GAAG;IACF,SAAS,CAAC,EAAE,UAAU,CAAC,WAAW,CAAC,CAAA;CACpC,CAAA;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,GAAE,4BAAiC,GACzC,2BAA2B,CAqC7B"}
|
|
@@ -45,12 +45,13 @@
|
|
|
45
45
|
* })
|
|
46
46
|
* ```
|
|
47
47
|
*/
|
|
48
|
-
/** The
|
|
48
|
+
/** The better-auth models and their default (unprefixed) model names. */
|
|
49
49
|
const MODEL_DEFAULT_NAMES = {
|
|
50
50
|
user: 'User',
|
|
51
51
|
session: 'Session',
|
|
52
52
|
account: 'Account',
|
|
53
53
|
verification: 'Verification',
|
|
54
|
+
rateLimit: 'RateLimit',
|
|
54
55
|
};
|
|
55
56
|
/** better-auth's own default lowercase table names, per model. */
|
|
56
57
|
const BETTER_AUTH_DEFAULT_TABLE_NAMES = {
|
|
@@ -58,6 +59,7 @@ const BETTER_AUTH_DEFAULT_TABLE_NAMES = {
|
|
|
58
59
|
session: 'session',
|
|
59
60
|
account: 'account',
|
|
60
61
|
verification: 'verification',
|
|
62
|
+
rateLimit: 'rateLimit',
|
|
61
63
|
};
|
|
62
64
|
/**
|
|
63
65
|
* Build the adoption {@link AuthConfig} fragment for a pre-existing better-auth
|
|
@@ -71,7 +73,7 @@ const BETTER_AUTH_DEFAULT_TABLE_NAMES = {
|
|
|
71
73
|
* (and any field column maps) set to match the live tables
|
|
72
74
|
*/
|
|
73
75
|
export function adoptBetterAuthTables(options = {}) {
|
|
74
|
-
const { schema = 'auth', modelNamePrefix = 'Auth', fields = {}, useBetterAuthTableNames = false, tableNames = {}, } = options;
|
|
76
|
+
const { schema = 'auth', modelNamePrefix = 'Auth', fields = {}, useBetterAuthTableNames = false, tableNames = {}, rateLimit = false, } = options;
|
|
75
77
|
const buildModel = (model) => {
|
|
76
78
|
const config = {
|
|
77
79
|
modelName: `${modelNamePrefix}${MODEL_DEFAULT_NAMES[model]}`,
|
|
@@ -93,6 +95,9 @@ export function adoptBetterAuthTables(options = {}) {
|
|
|
93
95
|
session: buildModel('session'),
|
|
94
96
|
account: buildModel('account'),
|
|
95
97
|
verification: buildModel('verification'),
|
|
98
|
+
...(rateLimit
|
|
99
|
+
? { rateLimit: { enabled: true, storage: 'database', ...buildModel('rateLimit') } }
|
|
100
|
+
: {}),
|
|
96
101
|
};
|
|
97
102
|
}
|
|
98
103
|
//# sourceMappingURL=adopt-better-auth-tables.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adopt-better-auth-tables.js","sourceRoot":"","sources":["../../src/config/adopt-better-auth-tables.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;
|
|
1
|
+
{"version":3,"file":"adopt-better-auth-tables.js","sourceRoot":"","sources":["../../src/config/adopt-better-auth-tables.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAA;QAC1B,CAAC;QACD,OAAO,MAAM,CAAA;IACf,CAAC,CAAA;IAED,OAAO;QACL,MAAM;QACN,IAAI,EAAE,UAAU,CAAC,MAAM,CAAC;QACxB,OAAO,EAAE,UAAU,CAAC,SAAS,CAAC;QAC9B,OAAO,EAAE,UAAU,CAAC,SAAS,CAAC;QAC9B,YAAY,EAAE,UAAU,CAAC,cAAc,CAAC;QACxC,GAAG,CAAC,SAAS;YACX,CAAC,CAAC,EAAE,SAAS,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,UAAmB,EAAE,GAAG,UAAU,CAAC,WAAW,CAAC,EAAE,EAAE;YAC5F,CAAC,CAAC,EAAE,CAAC;KACR,CAAA;AACH,CAAC"}
|
|
@@ -40,6 +40,8 @@ export type DerivedAuthLists = {
|
|
|
40
40
|
session: string;
|
|
41
41
|
account: string;
|
|
42
42
|
verification: string;
|
|
43
|
+
/** Only present when a `RateLimit` list was derived (`rateLimit.storage === 'database'`). */
|
|
44
|
+
rateLimit?: string;
|
|
43
45
|
};
|
|
44
46
|
/** The derived list configs, keyed by their derived list keys. */
|
|
45
47
|
lists: Record<string, ListConfig<any>>;
|
|
@@ -53,10 +55,13 @@ export type DerivedAuthLists = {
|
|
|
53
55
|
* for the user list specifically, `userConfig.access` (`extendUserList.access`,
|
|
54
56
|
* which takes precedence — see {@link AuthAccessConfig}).
|
|
55
57
|
*
|
|
58
|
+
* A fifth `RateLimit` list is included only when `models.rateLimit` is
|
|
59
|
+
* present (i.e. `rateLimit.storage === 'database'`).
|
|
60
|
+
*
|
|
56
61
|
* @param models - Resolved better-auth per-model config (modelName + field column maps)
|
|
57
62
|
* @param userConfig - Extra User-list fields/access/hooks supplied via `extendUserList`
|
|
58
63
|
* @param accessConfig - App-authored access for each Auth list, keyed by better-auth model name
|
|
59
|
-
* @returns The derived list keys and the
|
|
64
|
+
* @returns The derived list keys and the Auth list configs keyed by those keys
|
|
60
65
|
*/
|
|
61
66
|
export declare function deriveAuthLists(models: NormalizedAuthModels, userConfig?: ExtendUserListConfig, accessConfig?: AuthAccessConfig): DerivedAuthLists;
|
|
62
67
|
//# sourceMappingURL=derive-auth-lists.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"derive-auth-lists.d.ts","sourceRoot":"","sources":["../../src/config/derive-auth-lists.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;
|
|
1
|
+
{"version":3,"file":"derive-auth-lists.d.ts","sourceRoot":"","sources":["../../src/config/derive-auth-lists.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAWH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAEtD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;AAC7D,OAAO,KAAK,EAAE,gBAAgB,EAA6B,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAEnG;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,oDAAoD;IACpD,IAAI,EAAE;QACJ,IAAI,EAAE,MAAM,CAAA;QACZ,OAAO,EAAE,MAAM,CAAA;QACf,OAAO,EAAE,MAAM,CAAA;QACf,YAAY,EAAE,MAAM,CAAA;QACpB,6FAA6F;QAC7F,SAAS,CAAC,EAAE,MAAM,CAAA;KACnB,CAAA;IACD,kEAAkE;IAElE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,CAAA;CACvC,CAAA;AA6PD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,oBAAoB,EAC5B,UAAU,GAAE,oBAAyB,EACrC,YAAY,GAAE,gBAAqB,GAClC,gBAAgB,CAsBlB"}
|
|
@@ -26,17 +26,17 @@
|
|
|
26
26
|
* resolution) consume this module so derivation lives in exactly one place.
|
|
27
27
|
*/
|
|
28
28
|
import { list } from '@opensaas/stack-core';
|
|
29
|
-
import { text, timestamp, checkbox, relationship } from '@opensaas/stack-core/fields';
|
|
29
|
+
import { text, timestamp, checkbox, integer, bigInt, relationship, } from '@opensaas/stack-core/fields';
|
|
30
30
|
/**
|
|
31
31
|
* Build the list-level `db` config (`timestamps` + `@@map` + `@@schema`) for a
|
|
32
32
|
* derived list.
|
|
33
33
|
*
|
|
34
|
-
*
|
|
35
|
-
* adapter writes `createdAt`/`updatedAt` on every
|
|
36
|
-
* converter returns `null` for those columns
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* better-auth
|
|
34
|
+
* `timestamps` is a per-model input rather than hardcoded: better-auth's
|
|
35
|
+
* adapter writes `createdAt`/`updatedAt` on every user/session/account/
|
|
36
|
+
* verification row (and the schema converter returns `null` for those columns,
|
|
37
|
+
* assuming the generator injects them), so those four opt back into
|
|
38
|
+
* auto-timestamps now that they're OFF by default (ADR-0004). The `RateLimit`
|
|
39
|
+
* model has neither column in better-auth's own schema, so it passes `false`.
|
|
40
40
|
*
|
|
41
41
|
* The physical table name (`@@map`) comes from the model's resolved
|
|
42
42
|
* `tableName` — independent of the list key/`modelName` — so a renamed list
|
|
@@ -44,13 +44,14 @@ import { text, timestamp, checkbox, relationship } from '@opensaas/stack-core/fi
|
|
|
44
44
|
* default lowercase table names). When a `schema` is configured (plugin-level
|
|
45
45
|
* or per-model), the list is placed in that Postgres schema via `@@schema(...)`.
|
|
46
46
|
*
|
|
47
|
-
* With no `tableName`/`schema` overrides
|
|
48
|
-
* leaving the default `User`/`Session`/...
|
|
47
|
+
* With no `tableName`/`schema` overrides and `timestamps: true` we emit only
|
|
48
|
+
* `{ timestamps: true }`, leaving the default `User`/`Session`/... output
|
|
49
|
+
* unchanged.
|
|
49
50
|
*/
|
|
50
|
-
function listDb(model) {
|
|
51
|
+
function listDb(model, timestamps) {
|
|
51
52
|
const schema = model.schema;
|
|
52
53
|
return {
|
|
53
|
-
timestamps: true,
|
|
54
|
+
...(timestamps ? { timestamps: true } : {}),
|
|
54
55
|
...(model.tableName !== undefined ? { map: model.tableName } : {}),
|
|
55
56
|
...(schema !== undefined ? { schema } : {}),
|
|
56
57
|
};
|
|
@@ -117,7 +118,7 @@ function createUserList(model, keys, userConfig, access) {
|
|
|
117
118
|
// Custom fields from user config
|
|
118
119
|
...(userConfig.fields || {}),
|
|
119
120
|
},
|
|
120
|
-
db: listDb(model),
|
|
121
|
+
db: listDb(model, true),
|
|
121
122
|
access: userConfig.access || access,
|
|
122
123
|
hooks: userConfig.hooks,
|
|
123
124
|
});
|
|
@@ -148,7 +149,7 @@ function createSessionList(model, keys, access) {
|
|
|
148
149
|
db: userRelationshipDb(f),
|
|
149
150
|
}),
|
|
150
151
|
},
|
|
151
|
-
db: listDb(model),
|
|
152
|
+
db: listDb(model, true),
|
|
152
153
|
access,
|
|
153
154
|
});
|
|
154
155
|
}
|
|
@@ -177,7 +178,7 @@ function createAccountList(model, keys, access) {
|
|
|
177
178
|
idToken: text({ db: fieldDb('idToken', f) }),
|
|
178
179
|
password: text({ db: fieldDb('password', f) }),
|
|
179
180
|
},
|
|
180
|
-
db: listDb(model),
|
|
181
|
+
db: listDb(model, true),
|
|
181
182
|
access,
|
|
182
183
|
});
|
|
183
184
|
}
|
|
@@ -197,7 +198,46 @@ function createVerificationList(model, access) {
|
|
|
197
198
|
db: { isNullable: false, ...fieldDb('expiresAt', f) },
|
|
198
199
|
}),
|
|
199
200
|
},
|
|
200
|
-
db: listDb(model),
|
|
201
|
+
db: listDb(model, true),
|
|
202
|
+
access,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Create the Auth rate-limit list, present only when `rateLimit.storage ===
|
|
207
|
+
* 'database'` derives a `rateLimit` model. Mirrors better-auth's own
|
|
208
|
+
* `rateLimit` table exactly (`getAuthTables` in `@better-auth/core`, verified
|
|
209
|
+
* against better-auth@1.6.25): `key` (unique — load-bearing, not cosmetic,
|
|
210
|
+
* since the limiter races concurrent requests into a create and relies on the
|
|
211
|
+
* resulting constraint violation to serialise them), `count`, and
|
|
212
|
+
* `lastRequest` (a millisecond epoch, hence `bigInt()` rather than
|
|
213
|
+
* `integer()`, which would overflow). None of the three columns carries a
|
|
214
|
+
* Prisma default — the limiter supplies `lastRequest` explicitly on every
|
|
215
|
+
* create/update, and an adopted live table has no default to match. No
|
|
216
|
+
* `createdAt`/`updatedAt` either (see `listDb`'s `timestamps` argument):
|
|
217
|
+
* better-auth's own rate-limit table has neither column.
|
|
218
|
+
*
|
|
219
|
+
* Per ADR-0013, the plugin ships no permissive access default — closed unless
|
|
220
|
+
* the application supplies `access.rateLimit`.
|
|
221
|
+
*/
|
|
222
|
+
function createRateLimitList(model, access) {
|
|
223
|
+
const f = model.fields;
|
|
224
|
+
return list({
|
|
225
|
+
fields: {
|
|
226
|
+
key: text({
|
|
227
|
+
validation: { isRequired: true },
|
|
228
|
+
isIndexed: 'unique',
|
|
229
|
+
db: fieldDb('key', f),
|
|
230
|
+
}),
|
|
231
|
+
count: integer({
|
|
232
|
+
validation: { isRequired: true },
|
|
233
|
+
db: { isNullable: false, ...fieldDb('count', f) },
|
|
234
|
+
}),
|
|
235
|
+
lastRequest: bigInt({
|
|
236
|
+
validation: { isRequired: true },
|
|
237
|
+
db: { isNullable: false, ...fieldDb('lastRequest', f) },
|
|
238
|
+
}),
|
|
239
|
+
},
|
|
240
|
+
db: listDb(model, false),
|
|
201
241
|
access,
|
|
202
242
|
});
|
|
203
243
|
}
|
|
@@ -210,10 +250,13 @@ function createVerificationList(model, access) {
|
|
|
210
250
|
* for the user list specifically, `userConfig.access` (`extendUserList.access`,
|
|
211
251
|
* which takes precedence — see {@link AuthAccessConfig}).
|
|
212
252
|
*
|
|
253
|
+
* A fifth `RateLimit` list is included only when `models.rateLimit` is
|
|
254
|
+
* present (i.e. `rateLimit.storage === 'database'`).
|
|
255
|
+
*
|
|
213
256
|
* @param models - Resolved better-auth per-model config (modelName + field column maps)
|
|
214
257
|
* @param userConfig - Extra User-list fields/access/hooks supplied via `extendUserList`
|
|
215
258
|
* @param accessConfig - App-authored access for each Auth list, keyed by better-auth model name
|
|
216
|
-
* @returns The derived list keys and the
|
|
259
|
+
* @returns The derived list keys and the Auth list configs keyed by those keys
|
|
217
260
|
*/
|
|
218
261
|
export function deriveAuthLists(models, userConfig = {}, accessConfig = {}) {
|
|
219
262
|
const keys = {
|
|
@@ -221,6 +264,7 @@ export function deriveAuthLists(models, userConfig = {}, accessConfig = {}) {
|
|
|
221
264
|
session: models.session.modelName,
|
|
222
265
|
account: models.account.modelName,
|
|
223
266
|
verification: models.verification.modelName,
|
|
267
|
+
...(models.rateLimit ? { rateLimit: models.rateLimit.modelName } : {}),
|
|
224
268
|
};
|
|
225
269
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ListConfig must accept any TypeInfo
|
|
226
270
|
const lists = {
|
|
@@ -229,6 +273,9 @@ export function deriveAuthLists(models, userConfig = {}, accessConfig = {}) {
|
|
|
229
273
|
[keys.account]: createAccountList(models.account, keys, accessConfig.account),
|
|
230
274
|
[keys.verification]: createVerificationList(models.verification, accessConfig.verification),
|
|
231
275
|
};
|
|
276
|
+
if (models.rateLimit && keys.rateLimit) {
|
|
277
|
+
lists[keys.rateLimit] = createRateLimitList(models.rateLimit, accessConfig.rateLimit);
|
|
278
|
+
}
|
|
232
279
|
return { keys, lists };
|
|
233
280
|
}
|
|
234
281
|
//# sourceMappingURL=derive-auth-lists.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"derive-auth-lists.js","sourceRoot":"","sources":["../../src/config/derive-auth-lists.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAA;AAC3C,OAAO,
|
|
1
|
+
{"version":3,"file":"derive-auth-lists.js","sourceRoot":"","sources":["../../src/config/derive-auth-lists.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;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Y,CAAC;KAC5F,CAAA;IAED,IAAI,MAAM,CAAC,SAAS,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;QACvC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,mBAAmB,CAAC,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,SAAS,CAAC,CAAA;IACvF,CAAC;IAED,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAA;AACxB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EAEV,oBAAoB,EAOrB,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EAEV,oBAAoB,EAOrB,MAAM,YAAY,CAAA;AAyFnB;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,UAAU,GAAG,oBAAoB,CAyE5E;AAED,YAAY,EAAE,UAAU,EAAE,oBAAoB,EAAE,CAAA;AAChD,cAAc,YAAY,CAAA"}
|
package/dist/config/index.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Default better-auth model names. Used when the developer does not override
|
|
3
3
|
* `modelName`, preserving the historical `User`/`Session`/`Account`/`Verification`
|
|
4
|
-
* keys exactly.
|
|
4
|
+
* keys exactly. `rateLimit` only applies when `rateLimit.storage: 'database'`
|
|
5
|
+
* derives the fifth Auth list.
|
|
5
6
|
*/
|
|
6
7
|
const DEFAULT_MODEL_NAMES = {
|
|
7
8
|
user: 'User',
|
|
8
9
|
session: 'Session',
|
|
9
10
|
account: 'Account',
|
|
10
11
|
verification: 'Verification',
|
|
12
|
+
rateLimit: 'RateLimit',
|
|
11
13
|
};
|
|
12
14
|
/**
|
|
13
15
|
* Resolve a single better-auth model config block into its normalized form,
|
|
@@ -33,18 +35,23 @@ function normalizeModelConfig(config, defaultModelName, defaultSchema) {
|
|
|
33
35
|
};
|
|
34
36
|
}
|
|
35
37
|
/**
|
|
36
|
-
* Resolve the better-auth model config for all four auth models
|
|
37
|
-
* `
|
|
38
|
-
*
|
|
38
|
+
* Resolve the better-auth model config for all four auth models, plus a fifth
|
|
39
|
+
* `rateLimit` model when `rateLimit.storage: 'database'` requires deriving
|
|
40
|
+
* the `RateLimit` list. `defaultSchema` is the plugin-level `schema` applied
|
|
41
|
+
* to every model unless a per-model `schema` override is given.
|
|
39
42
|
*/
|
|
40
43
|
function normalizeAuthModels(config) {
|
|
41
44
|
const defaultSchema = config.schema;
|
|
42
|
-
|
|
45
|
+
const models = {
|
|
43
46
|
user: normalizeModelConfig(config.user, DEFAULT_MODEL_NAMES.user, defaultSchema),
|
|
44
47
|
session: normalizeModelConfig(config.session, DEFAULT_MODEL_NAMES.session, defaultSchema),
|
|
45
48
|
account: normalizeModelConfig(config.account, DEFAULT_MODEL_NAMES.account, defaultSchema),
|
|
46
49
|
verification: normalizeModelConfig(config.verification, DEFAULT_MODEL_NAMES.verification, defaultSchema),
|
|
47
50
|
};
|
|
51
|
+
if (config.rateLimit?.storage === 'database') {
|
|
52
|
+
models.rateLimit = normalizeModelConfig(config.rateLimit, DEFAULT_MODEL_NAMES.rateLimit, defaultSchema);
|
|
53
|
+
}
|
|
54
|
+
return models;
|
|
48
55
|
}
|
|
49
56
|
/**
|
|
50
57
|
* Default `sendResetPassword`/`sendVerificationEmail` — logs to console
|
package/dist/config/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAYA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAYA;;;;;GAKG;AACH,MAAM,mBAAmB,GAAG;IAC1B,IAAI,EAAE,MAAM;IACZ,OA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AAI,EAAE;QACjD,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,iBAAiB,EAAE,MAAM,CAAC,iBAAiB,IAAI,EAAE;KAClD,CAAA;AACH,CAAC;AAGD,cAAc,YAAY,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/config/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAA;AAEzD,OAAO,KAAK,EAAE,UAAU,EAAwB,MAAM,YAAY,CAAA;AAKlE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/config/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAA;AAEzD,OAAO,KAAK,EAAE,UAAU,EAAwB,MAAM,YAAY,CAAA;AAKlE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CA6LrD"}
|
package/dist/config/plugin.js
CHANGED
|
@@ -43,12 +43,17 @@ export function authPlugin(config) {
|
|
|
43
43
|
// (e.g. `user.modelName: 'AuthUser'`). A provider plugin's schema
|
|
44
44
|
// extension of a base model (e.g. `user`) must resolve against this
|
|
45
45
|
// remap too, so it lands on the adopted Auth list rather than a
|
|
46
|
-
// re-derived key that can collide with an unrelated host list.
|
|
46
|
+
// re-derived key that can collide with an unrelated host list. The
|
|
47
|
+
// `rateLimit` key is only present when `rateLimit.storage: 'database'`
|
|
48
|
+
// derived the fifth Auth list.
|
|
47
49
|
const baseModelKeys = {
|
|
48
50
|
user: normalized.models.user.modelName,
|
|
49
51
|
session: normalized.models.session.modelName,
|
|
50
52
|
account: normalized.models.account.modelName,
|
|
51
53
|
verification: normalized.models.verification.modelName,
|
|
54
|
+
...(normalized.models.rateLimit
|
|
55
|
+
? { rateLimit: normalized.models.rateLimit.modelName }
|
|
56
|
+
: {}),
|
|
52
57
|
};
|
|
53
58
|
// Add all auth lists FIRST, before any better-auth plugin schema
|
|
54
59
|
// extension is processed. This must happen before the betterAuthPlugins
|
|
@@ -90,7 +95,7 @@ export function authPlugin(config) {
|
|
|
90
95
|
// `oauth_application`, `passkey`) still register as new lists via
|
|
91
96
|
// `addList`, same as before.
|
|
92
97
|
for (const plugin of normalized.betterAuthPlugins) {
|
|
93
|
-
if (plugin && typeof plugin === 'object' &&
|
|
98
|
+
if (plugin && typeof plugin === 'object' && plugin.schema) {
|
|
94
99
|
// Plugin has schema property - convert to OpenSaaS lists
|
|
95
100
|
const pluginSchema = plugin.schema;
|
|
96
101
|
const pluginLists = convertBetterAuthSchema(pluginSchema, baseModelKeys);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../src/config/plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAE/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAChD,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAA;AAEvE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,UAAU,CAAC,MAAkB;IAC3C,MAAM,UAAU,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAA;IAE9C,OAAO;QACL,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,OAAO;QAEhB,mBAAmB,EAAE;YACnB,MAAM,EAAE,iEAAiE;YACzE,QAAQ,EAAE,qBAAqB;SAChC;QAED,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;YACtB,uEAAuE;YACvE,mEAAmE;YACnE,+DAA+D;YAC/D,uEAA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