@opensaas/stack-auth 0.39.2 → 0.40.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 +151 -0
- package/CLAUDE.md +140 -22
- package/dist/client/index.d.ts +0 -16
- package/dist/client/index.d.ts.map +1 -1
- package/dist/config/adopt-better-auth-tables.d.ts +4 -49
- package/dist/config/adopt-better-auth-tables.d.ts.map +1 -1
- package/dist/config/adopt-better-auth-tables.js +4 -51
- package/dist/config/adopt-better-auth-tables.js.map +1 -1
- package/dist/config/derive-auth-lists.d.ts +42 -37
- package/dist/config/derive-auth-lists.d.ts.map +1 -1
- package/dist/config/derive-auth-lists.js +579 -223
- package/dist/config/derive-auth-lists.js.map +1 -1
- package/dist/config/index.d.ts +0 -3
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +4 -34
- package/dist/config/index.js.map +1 -1
- package/dist/config/plugin.d.ts.map +1 -1
- package/dist/config/plugin.js +20 -90
- package/dist/config/plugin.js.map +1 -1
- package/dist/config/types.d.ts +89 -67
- package/dist/config/types.d.ts.map +1 -1
- package/dist/index.d.ts +1 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -13
- package/dist/index.js.map +1 -1
- package/dist/lists/index.d.ts +9 -5
- package/dist/lists/index.d.ts.map +1 -1
- package/dist/lists/index.js +9 -6
- package/dist/lists/index.js.map +1 -1
- package/dist/mcp/better-auth.d.ts +6 -19
- package/dist/mcp/better-auth.d.ts.map +1 -1
- package/dist/mcp/better-auth.js +6 -20
- package/dist/mcp/better-auth.js.map +1 -1
- package/dist/plugins/index.d.ts +4 -4
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/index.js +4 -4
- package/dist/plugins/index.js.map +1 -1
- package/dist/runtime/types.d.ts +2 -9
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/runtime/types.js +0 -4
- package/dist/runtime/types.js.map +1 -1
- package/dist/server/index.d.ts +5 -12
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +14 -62
- package/dist/server/index.js.map +1 -1
- package/dist/ui/components/ForgotPasswordForm.d.ts +0 -3
- package/dist/ui/components/ForgotPasswordForm.d.ts.map +1 -1
- package/dist/ui/components/ForgotPasswordForm.js +0 -3
- package/dist/ui/components/ForgotPasswordForm.js.map +1 -1
- package/dist/ui/components/ResetPasswordForm.d.ts +0 -3
- package/dist/ui/components/ResetPasswordForm.d.ts.map +1 -1
- package/dist/ui/components/ResetPasswordForm.js +0 -5
- package/dist/ui/components/ResetPasswordForm.js.map +1 -1
- package/dist/ui/components/SignInForm.d.ts +0 -3
- package/dist/ui/components/SignInForm.d.ts.map +1 -1
- package/dist/ui/components/SignInForm.js +0 -4
- package/dist/ui/components/SignInForm.js.map +1 -1
- package/dist/ui/components/SignUpForm.d.ts +0 -3
- package/dist/ui/components/SignUpForm.d.ts.map +1 -1
- package/dist/ui/components/SignUpForm.js +0 -5
- package/dist/ui/components/SignUpForm.js.map +1 -1
- package/dist/ui/lib/clean-error-message.d.ts +3 -6
- package/dist/ui/lib/clean-error-message.d.ts.map +1 -1
- package/dist/ui/lib/clean-error-message.js +3 -6
- package/dist/ui/lib/clean-error-message.js.map +1 -1
- package/dist/ui/types.d.ts +2 -15
- package/dist/ui/types.d.ts.map +1 -1
- package/dist/ui/types.js +2 -7
- package/dist/ui/types.js.map +1 -1
- package/package.json +12 -5
- package/src/client/index.ts +0 -17
- package/src/config/adopt-better-auth-tables.ts +4 -51
- package/src/config/derive-auth-lists.ts +685 -252
- package/src/config/index.ts +4 -34
- package/src/config/plugin.ts +21 -91
- package/src/config/types.ts +90 -67
- package/src/index.ts +3 -14
- package/src/lists/index.ts +17 -5
- package/src/mcp/better-auth.ts +6 -25
- package/src/plugins/index.ts +4 -5
- package/src/runtime/types.ts +2 -10
- package/src/server/index.ts +17 -70
- package/src/ui/components/ForgotPasswordForm.tsx +0 -3
- package/src/ui/components/ResetPasswordForm.tsx +0 -5
- package/src/ui/components/SignInForm.tsx +0 -4
- package/src/ui/components/SignUpForm.tsx +0 -5
- package/src/ui/lib/clean-error-message.ts +3 -6
- package/src/ui/types.ts +2 -15
- package/tests/auth-lists-drift.test.ts +480 -0
- package/tests/config.test.ts +3 -0
- package/tests/credential-field-read-deny-e2e.test.ts +295 -0
- package/tests/derive-auth-lists.test.ts +263 -6
- package/tests/generated-fk-shape.test.ts +432 -9
- package/tests/mcp-oauth-cascade-e2e.test.ts +267 -0
- package/tests/plugin-derived-keys.test.ts +39 -0
- package/tests/plugin-table-derivation.test.ts +270 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/server/schema-converter.d.ts +0 -81
- package/dist/server/schema-converter.d.ts.map +0 -1
- package/dist/server/schema-converter.js +0 -157
- package/dist/server/schema-converter.js.map +0 -1
- package/src/server/schema-converter.ts +0 -243
- package/tests/schema-converter.test.ts +0 -399
|
@@ -1,40 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* adopt a differently-named live table
|
|
14
|
-
* - field-level `@map` (`db.map`) for any better-auth field → column override
|
|
15
|
-
* - relationship refs between the auth lists wired to the *derived* keys
|
|
16
|
-
* (e.g. `Session.user → AuthUser.sessions`)
|
|
17
|
-
*
|
|
18
|
-
* When the developer supplies no `modelName`/`fields` overrides, the output
|
|
19
|
-
* keeps the historical default keys (`User`/`Session`/`Account`/
|
|
20
|
-
* `Verification`) and field shapes — see the unit tests. Per ADR-0013, each
|
|
21
|
-
* list ships with **no** operation-level access unless the caller supplies it
|
|
22
|
-
* (`accessConfig`, or `userConfig.access` for the user list) — deny-by-default,
|
|
23
|
-
* not the plugin's former permissive defaults.
|
|
24
|
-
*
|
|
25
|
-
* `getAuthLists`/`convertBetterAuthSchema` (and the runtime user-key
|
|
26
|
-
* resolution) consume this module so derivation lives in exactly one place.
|
|
2
|
+
* `better-auth config → Auth lists` derivation, free of side effects and
|
|
3
|
+
* plugin/runtime concerns. Reads better-auth's own resolved table
|
|
4
|
+
* definitions (`getAuthTables`, re-exported from `better-auth/db`) rather
|
|
5
|
+
* than hand-transcribing them, so the Auth lists cannot silently drift from
|
|
6
|
+
* what better-auth itself declares (issue #987). This single derivation also
|
|
7
|
+
* covers better-auth *plugin* tables (e.g. the MCP plugin's OAuth tables) —
|
|
8
|
+
* `getAuthTables` merges a plugin's own `schema` into its result when
|
|
9
|
+
* `options.plugins` is populated, so one registry and one field-derivation
|
|
10
|
+
* pass cover base models and plugin tables alike (issue #992). See
|
|
11
|
+
* `packages/auth/CLAUDE.md` ("Deriving Auth lists from better-auth config")
|
|
12
|
+
* for the full behavior and examples.
|
|
27
13
|
*/
|
|
14
|
+
import type { BetterAuthPlugin } from 'better-auth';
|
|
28
15
|
import type { ListConfig } from '@opensaas/stack-core';
|
|
29
16
|
import type { ExtendUserListConfig } from '../lists/index.js';
|
|
30
17
|
import type { AuthAccessConfig, NormalizedAuthModels } from './types.js';
|
|
31
18
|
/**
|
|
32
|
-
* The derived Auth list set together with the keys each
|
|
33
|
-
* Keys are surfaced separately so
|
|
34
|
-
* user-key resolution) don't
|
|
19
|
+
* The derived Auth list set together with the keys each of the five base
|
|
20
|
+
* better-auth models was placed under. Keys are surfaced separately so
|
|
21
|
+
* callers (plugin add-vs-extend logic, runtime user-key resolution) don't
|
|
22
|
+
* have to re-derive them. Better-auth *plugin* tables (e.g. `oauthApplication`)
|
|
23
|
+
* are derived alongside these but aren't named here — their keys are only
|
|
24
|
+
* needed internally, to resolve a reference target, and by callers that just
|
|
25
|
+
* want every derived list (`Object.keys(lists)`).
|
|
35
26
|
*/
|
|
36
27
|
export type DerivedAuthLists = {
|
|
37
|
-
/** Derived list keys, one per better-auth model. */
|
|
38
28
|
keys: {
|
|
39
29
|
user: string;
|
|
40
30
|
session: string;
|
|
@@ -43,25 +33,40 @@ export type DerivedAuthLists = {
|
|
|
43
33
|
/** Only present when a `RateLimit` list was derived (`rateLimit.storage === 'database'`). */
|
|
44
34
|
rateLimit?: string;
|
|
45
35
|
};
|
|
46
|
-
/** The derived list configs, keyed by their derived list keys. */
|
|
36
|
+
/** The derived list configs, keyed by their derived list keys — base models and plugin tables alike. */
|
|
47
37
|
lists: Record<string, ListConfig<any>>;
|
|
48
38
|
};
|
|
49
39
|
/**
|
|
50
|
-
* Derive the OpenSaaS Auth lists from the resolved better-auth model config
|
|
40
|
+
* Derive the OpenSaaS Auth lists from the resolved better-auth model config —
|
|
41
|
+
* the four base models, an optional database-backed `RateLimit`, and any
|
|
42
|
+
* table a better-auth plugin declares in its own `schema` (issue #992).
|
|
51
43
|
*
|
|
52
|
-
* Per ADR-0013
|
|
44
|
+
* Per ADR-0013 every derived list ships **closed** (no permissive operation
|
|
53
45
|
* access) unless the application supplies access via `accessConfig` (the
|
|
54
46
|
* `authPlugin({ access: … })` passthrough, keyed by better-auth model name) or,
|
|
55
47
|
* for the user list specifically, `userConfig.access` (`extendUserList.access`,
|
|
56
|
-
* which takes precedence — see {@link AuthAccessConfig}).
|
|
48
|
+
* which takes precedence — see {@link AuthAccessConfig}). Plugin tables have no
|
|
49
|
+
* `access` passthrough at all — an app that needs to grant access declares the
|
|
50
|
+
* list itself under the same derived key so this function's field-only merge
|
|
51
|
+
* (in `authPlugin`'s add-vs-extend loop) leaves the app's own access standing.
|
|
57
52
|
*
|
|
58
53
|
* A fifth `RateLimit` list is included only when `models.rateLimit` is
|
|
59
54
|
* present (i.e. `rateLimit.storage === 'database'`).
|
|
60
55
|
*
|
|
61
|
-
*
|
|
56
|
+
* Each base model's `indexes` (`AuthModelConfig.indexes`) carries through to
|
|
57
|
+
* the derived list's `db.indexes` unchanged, and suppresses this function's
|
|
58
|
+
* own derived field-level `isIndexed` for any column an entry names — the
|
|
59
|
+
* application's declaration wins over a derived default (ADR-0035).
|
|
60
|
+
*
|
|
61
|
+
* @param models - Resolved better-auth per-model config (modelName + field column maps + app-supplied indexes)
|
|
62
62
|
* @param userConfig - Extra User-list fields/access/hooks supplied via `extendUserList`
|
|
63
|
-
* @param accessConfig - App-authored access for each Auth list, keyed by better-auth model name
|
|
64
|
-
* @
|
|
63
|
+
* @param accessConfig - App-authored access for each base Auth list, keyed by better-auth model name
|
|
64
|
+
* @param plugins - The app's better-auth plugins (`authPlugin({ betterAuthPlugins })`), whose own
|
|
65
|
+
* `schema` (base-model extensions and standalone plugin tables) is derived alongside the base models
|
|
66
|
+
* @param credentialFieldsConfig - App-authored additions to the credential-field read-deny
|
|
67
|
+
* (`authPlugin({ credentialFields })`), keyed by better-auth model key. Additive only — see
|
|
68
|
+
* {@link buildCredentialFieldRegistry}.
|
|
69
|
+
* @returns The derived base-model list keys and every derived list config (base models and plugin tables)
|
|
65
70
|
*/
|
|
66
|
-
export declare function deriveAuthLists(models: NormalizedAuthModels, userConfig?: ExtendUserListConfig, accessConfig?: AuthAccessConfig): DerivedAuthLists;
|
|
71
|
+
export declare function deriveAuthLists(models: NormalizedAuthModels, userConfig?: ExtendUserListConfig, accessConfig?: AuthAccessConfig, plugins?: BetterAuthPlugin[], credentialFieldsConfig?: Record<string, string[]>): DerivedAuthLists;
|
|
67
72
|
//# 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
|
|
1
|
+
{"version":3,"file":"derive-auth-lists.d.ts","sourceRoot":"","sources":["../../src/config/derive-auth-lists.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAYH,OAAO,KAAK,EAAqB,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAEtE,OAAO,KAAK,EAAE,UAAU,EAAuC,MAAM,sBAAsB,CAAA;AAE3F,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;AAC7D,OAAO,KAAK,EAAE,gBAAgB,EAA6B,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAEnG;;;;;;;;GAQG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,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,wGAAwG;IAExG,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,CAAA;CACvC,CAAA;AAufD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,oBAAoB,EAC5B,UAAU,GAAE,oBAAyB,EACrC,YAAY,GAAE,gBAAqB,EACnC,OAAO,GAAE,gBAAgB,EAAO,EAChC,sBAAsB,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAM,GACpD,gBAAgB,CAoMlB"}
|