@vexcms/better-auth 0.1.0-alpha.2 → 0.1.0-alpha.21
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 +147 -40
- package/dist/adapter.d.ts +17 -5
- package/dist/adapter.d.ts.map +1 -1
- package/dist/chunk-YPIEILO5.js +196 -0
- package/dist/chunk-YPIEILO5.js.map +1 -0
- package/dist/client.d.ts +24 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +997 -0
- package/dist/client.js.map +1 -0
- package/dist/collections.d.ts +88 -0
- package/dist/collections.d.ts.map +1 -0
- package/dist/convex/anonRole.d.ts +45 -0
- package/dist/convex/anonRole.d.ts.map +1 -0
- package/dist/convex/getAuth.d.ts +7 -4
- package/dist/convex/getAuth.d.ts.map +1 -1
- package/dist/convex/index.d.ts +4 -3
- package/dist/convex/index.d.ts.map +1 -1
- package/dist/index.d.ts +25 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +30 -209
- package/dist/index.js.map +1 -1
- package/dist/pluginSchemas.d.ts +159 -0
- package/dist/pluginSchemas.d.ts.map +1 -0
- package/dist/pluginSchemas.generated.d.ts +4 -0
- package/dist/pluginSchemas.generated.d.ts.map +1 -0
- package/package.json +13 -5
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import type { DBFieldAttribute } from "better-auth";
|
|
2
|
+
import type * as BetterAuthPlugins from "better-auth/plugins";
|
|
3
|
+
/**
|
|
4
|
+
* A Better Auth plugin's DB schema contribution — one entry per table it adds
|
|
5
|
+
* or extends.
|
|
6
|
+
*
|
|
7
|
+
* Declared structurally rather than imported from `@better-auth/core/db`:
|
|
8
|
+
* that package is a transitive dependency of `better-auth`, not one this
|
|
9
|
+
* package declares, so naming it in a public type would be an undeclared
|
|
10
|
+
* dependency on consumers' resolution.
|
|
11
|
+
*/
|
|
12
|
+
export type PluginDBSchema = Record<string, {
|
|
13
|
+
fields: Record<string, DBFieldAttribute>;
|
|
14
|
+
modelName?: string | undefined;
|
|
15
|
+
disableMigration?: boolean | undefined;
|
|
16
|
+
}>;
|
|
17
|
+
/**
|
|
18
|
+
* Every export of `better-auth/plugins` that is a plugin factory — derived
|
|
19
|
+
* from the module's own types, so the union tracks upstream automatically:
|
|
20
|
+
* a Better Auth release that adds a plugin adds a member here with no code
|
|
21
|
+
* change, and {@link UnclassifiedPlugin} turns that into a compile error in
|
|
22
|
+
* this package until the plugin is classified.
|
|
23
|
+
*/
|
|
24
|
+
export type BetterAuthPluginName = {
|
|
25
|
+
[K in keyof typeof BetterAuthPlugins]: (typeof BetterAuthPlugins)[K] extends (...args: never[]) => {
|
|
26
|
+
id: string;
|
|
27
|
+
} ? K : never;
|
|
28
|
+
}[keyof typeof BetterAuthPlugins];
|
|
29
|
+
/**
|
|
30
|
+
* Per-table overrides a plugin's own `schema` option accepts — renaming its
|
|
31
|
+
* table or adding fields to it. Mirrors Better Auth's `schema` option shape so
|
|
32
|
+
* the value can be authored once and passed to both the real plugin factory
|
|
33
|
+
* and {@link betterAuthCollections}.
|
|
34
|
+
*/
|
|
35
|
+
export type PluginSchemaOverride = Record<string, {
|
|
36
|
+
modelName?: string | undefined;
|
|
37
|
+
/** Column renames, keyed by the plugin's own field name. */
|
|
38
|
+
fields?: Record<string, string> | undefined;
|
|
39
|
+
additionalFields?: Record<string, DBFieldAttribute> | undefined;
|
|
40
|
+
}>;
|
|
41
|
+
/**
|
|
42
|
+
* Plugins whose DB schema this package models. `true` enables a plugin with
|
|
43
|
+
* its default schema; an object supplies the SCHEMA-AFFECTING options only.
|
|
44
|
+
*
|
|
45
|
+
* Runtime options (`adminRoles`, `sendInvitationEmail`, OAuth secrets, …) are
|
|
46
|
+
* deliberately absent: this descriptor is authored in a client-safe module and
|
|
47
|
+
* accepting a plugin's full option type is how a server callback — and
|
|
48
|
+
* whatever it closes over — would end up in the browser bundle. Options that
|
|
49
|
+
* do not change the schema cannot change what the admin panel renders, so
|
|
50
|
+
* nothing is lost by keeping them on the server's real plugin instances.
|
|
51
|
+
*/
|
|
52
|
+
export interface ModelledPluginDescriptors {
|
|
53
|
+
/** Roles, bans, and impersonation fields on `user`/`session`. */
|
|
54
|
+
admin?: true | {
|
|
55
|
+
schema?: PluginSchemaOverride;
|
|
56
|
+
};
|
|
57
|
+
/** `isAnonymous` on `user`. */
|
|
58
|
+
anonymous?: true | {
|
|
59
|
+
schema?: PluginSchemaOverride;
|
|
60
|
+
};
|
|
61
|
+
/** The `apikey` table. */
|
|
62
|
+
apiKey?: true | {
|
|
63
|
+
schema?: PluginSchemaOverride;
|
|
64
|
+
};
|
|
65
|
+
/** `userId` on `user`, plus the `jwks` table the Convex plugin's JWT half adds. */
|
|
66
|
+
convex?: true | {
|
|
67
|
+
schema?: PluginSchemaOverride;
|
|
68
|
+
};
|
|
69
|
+
/** The `deviceCode` table. */
|
|
70
|
+
deviceAuthorization?: true | {
|
|
71
|
+
schema?: PluginSchemaOverride;
|
|
72
|
+
};
|
|
73
|
+
/** The `jwks` table. */
|
|
74
|
+
jwt?: true | {
|
|
75
|
+
schema?: PluginSchemaOverride;
|
|
76
|
+
};
|
|
77
|
+
/** The OAuth application/access-token/consent tables. */
|
|
78
|
+
mcp?: true | {
|
|
79
|
+
schema?: PluginSchemaOverride;
|
|
80
|
+
};
|
|
81
|
+
/** The OAuth application/access-token/consent tables. */
|
|
82
|
+
oidcProvider?: true | {
|
|
83
|
+
schema?: PluginSchemaOverride;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Organizations, members, and invitations — plus `team`/`teamMember` when
|
|
87
|
+
* `teams` is enabled, which is the one option that changes which tables exist.
|
|
88
|
+
*/
|
|
89
|
+
organization?: true | {
|
|
90
|
+
teams?: boolean;
|
|
91
|
+
schema?: PluginSchemaOverride;
|
|
92
|
+
};
|
|
93
|
+
/** `phoneNumber`/`phoneNumberVerified` on `user`. */
|
|
94
|
+
phoneNumber?: true | {
|
|
95
|
+
schema?: PluginSchemaOverride;
|
|
96
|
+
};
|
|
97
|
+
/** The `walletAddress` table. */
|
|
98
|
+
siwe?: true | {
|
|
99
|
+
schema?: PluginSchemaOverride;
|
|
100
|
+
};
|
|
101
|
+
/** The `twoFactor` table and `twoFactorEnabled` on `user`. */
|
|
102
|
+
twoFactor?: true | {
|
|
103
|
+
schema?: PluginSchemaOverride;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/** A plugin name this package models. */
|
|
107
|
+
export type ModelledPluginName = keyof ModelledPluginDescriptors;
|
|
108
|
+
/**
|
|
109
|
+
* Plugins that exist upstream but contribute no tables, or whose schema this
|
|
110
|
+
* package does not model. Passing one is a type error naming the escape hatch:
|
|
111
|
+
* read its `schema` off your real plugin instance on the server and hand the
|
|
112
|
+
* value to `betterAuthCollections`'s `extraSchema`.
|
|
113
|
+
*/
|
|
114
|
+
export type UnmodelledPluginDescriptor<TName extends string> = {
|
|
115
|
+
readonly __unmodelled_plugin_pass_its_schema_via_extraSchema: TName;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Plugin names neither modelled nor explicitly acknowledged as unmodelled.
|
|
119
|
+
* Always `never`; {@link assertEveryPluginClassified} makes a non-`never`
|
|
120
|
+
* value a compile error naming the plugin a Better Auth release just added.
|
|
121
|
+
*/
|
|
122
|
+
export type UnclassifiedPlugin = Exclude<BetterAuthPluginName, ModelledPluginName | UnmodelledPluginName>;
|
|
123
|
+
/**
|
|
124
|
+
* Upstream plugins knowingly left unmodelled. Enumerated rather than inferred
|
|
125
|
+
* so adding a plugin upstream breaks this package's typecheck instead of
|
|
126
|
+
* silently widening the accepted descriptor map.
|
|
127
|
+
*/
|
|
128
|
+
export type UnmodelledPluginName = "backupCode2fa" | "bearer" | "captcha" | "customSession" | "emailOTP" | "genericOAuth" | "haveIBeenPwned" | "lastLoginMethod" | "magicLink" | "multiSession" | "oAuthProxy" | "oauthPopup" | "oneTap" | "oneTimeToken" | "openAPI" | "otp2fa" | "passkey" | "sso" | "testUtils" | "totp2fa" | "twoFactorClient" | "username";
|
|
129
|
+
/**
|
|
130
|
+
* The `plugins` map `betterAuthCollections` accepts: modelled plugins carry a
|
|
131
|
+
* descriptor, every other upstream plugin is rejected with a message pointing
|
|
132
|
+
* at `extraSchema`.
|
|
133
|
+
*/
|
|
134
|
+
export type BetterAuthPluginDescriptors = ModelledPluginDescriptors & {
|
|
135
|
+
[K in UnmodelledPluginName]?: UnmodelledPluginDescriptor<K>;
|
|
136
|
+
};
|
|
137
|
+
/**
|
|
138
|
+
* Resolves a descriptor map into the plain plugin stubs `getAuthTables` reads.
|
|
139
|
+
*
|
|
140
|
+
* Each enabled plugin contributes its generated schema snapshot with the
|
|
141
|
+
* caller's `schema` overrides applied the same way the real plugin applies
|
|
142
|
+
* them: `additionalFields` are spread into the table (plugins do this
|
|
143
|
+
* themselves when building their schema, so the snapshot — generated with no
|
|
144
|
+
* overrides — cannot already contain them), then Better Auth's own
|
|
145
|
+
* the same field renames and `modelName` override Better Auth's `mergeSchema` applies.
|
|
146
|
+
*
|
|
147
|
+
* @param props.plugins - Descriptor map; omitted or `undefined` entries contribute nothing.
|
|
148
|
+
* @param props.extraSchema - Schemas of plugins this package does not model, taken from a real plugin instance's `schema`.
|
|
149
|
+
* @returns One `{ id, schema }` stub per contributing plugin, in descriptor-key order.
|
|
150
|
+
* @throws {Error} When a descriptor names a plugin with no modelled schema.
|
|
151
|
+
*/
|
|
152
|
+
export declare function resolvePluginStubs(props: {
|
|
153
|
+
plugins?: BetterAuthPluginDescriptors | undefined;
|
|
154
|
+
extraSchema?: PluginDBSchema | PluginDBSchema[] | undefined;
|
|
155
|
+
}): {
|
|
156
|
+
id: string;
|
|
157
|
+
schema: PluginDBSchema;
|
|
158
|
+
}[];
|
|
159
|
+
//# sourceMappingURL=pluginSchemas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pluginSchemas.d.ts","sourceRoot":"","sources":["../src/pluginSchemas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK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;;GAIG;AACH,MAAM,MAAM,kBAAkB,GAAG,OAAO,CACtC,oBAAoB,EACpB,kBAAkB,GAAG,oBAAoB,CAC1C,CAAC;AAEF;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,GAC5B,eAAe,GACf,QAAQ,GACR,SAAS,GACT,eAAe,GACf,UAAU,GACV,cAAc,GACd,gBAAgB,GAChB,iBAAiB,GACjB,WAAW,GACX,cAAc,GACd,YAAY,GACZ,YAAY,GACZ,QAAQ,GACR,cAAc,GACd,SAAS,GACT,QAAQ,GACR,SAAS,GACT,KAAK,GACL,WAAW,GACX,SAAS,GACT,iBAAiB,GACjB,UAAU,CAAC;AAEf;;;;GAIG;AACH,MAAM,MAAM,2BAA2B,GAAG,yBAAyB,GAAG;KACnE,CAAC,IAAI,oBAAoB,CAAC,CAAC,EAAE,0BAA0B,CAAC,CAAC,CAAC;CAC5D,CAAC;AAeF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE;IACxC,OAAO,CAAC,EAAE,2BAA2B,GAAG,SAAS,CAAC;IAClD,WAAW,CAAC,EAAE,cAAc,GAAG,cAAc,EAAE,GAAG,SAAS,CAAC;CAC7D,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,cAAc,CAAA;CAAE,EAAE,CAoD3C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pluginSchemas.generated.d.ts","sourceRoot":"","sources":["../src/pluginSchemas.generated.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEtD,oDAAoD;AACpD,eAAO,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAw6BzD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vexcms/better-auth",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.21",
|
|
4
4
|
"description": "better-auth adapter for VexCMS on Convex",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cms",
|
|
@@ -25,6 +25,11 @@
|
|
|
25
25
|
"source": "./src/index.ts",
|
|
26
26
|
"import": "./dist/index.js",
|
|
27
27
|
"types": "./dist/index.d.ts"
|
|
28
|
+
},
|
|
29
|
+
"./client": {
|
|
30
|
+
"source": "./src/client.ts",
|
|
31
|
+
"import": "./dist/client.js",
|
|
32
|
+
"types": "./dist/client.d.ts"
|
|
28
33
|
}
|
|
29
34
|
},
|
|
30
35
|
"main": "./dist/index.js",
|
|
@@ -35,9 +40,11 @@
|
|
|
35
40
|
"peerDependencies": {
|
|
36
41
|
"better-auth": ">=1.6.23 <1.7.0",
|
|
37
42
|
"convex": ">=1.44.0 <2",
|
|
38
|
-
"@vexcms/core": "^0.1.0-alpha.
|
|
43
|
+
"@vexcms/core": "^0.1.0-alpha.21"
|
|
39
44
|
},
|
|
40
45
|
"devDependencies": {
|
|
46
|
+
"@better-auth/api-key": "1.6.23",
|
|
47
|
+
"@convex-dev/better-auth": "0.11.5",
|
|
41
48
|
"@types/node": "20.19.43",
|
|
42
49
|
"@vitest/coverage-v8": "4.1.10",
|
|
43
50
|
"better-auth": "1.6.23",
|
|
@@ -47,7 +54,7 @@
|
|
|
47
54
|
"tsup": "8.5.1",
|
|
48
55
|
"typescript": "6.0.3",
|
|
49
56
|
"vitest": "4.1.10",
|
|
50
|
-
"@vexcms/core": "0.1.0-alpha.
|
|
57
|
+
"@vexcms/core": "0.1.0-alpha.21",
|
|
51
58
|
"@vexcms/tsconfig": "0.0.0"
|
|
52
59
|
},
|
|
53
60
|
"publishConfig": {
|
|
@@ -56,11 +63,12 @@
|
|
|
56
63
|
},
|
|
57
64
|
"scripts": {
|
|
58
65
|
"build": "tsup && tsc -p tsconfig.build.json --emitDeclarationOnly",
|
|
59
|
-
"dev": "tsup --watch",
|
|
66
|
+
"dev": "tsup --watch src",
|
|
60
67
|
"clean": "rm -rf dist",
|
|
61
68
|
"coverage": "vitest run --coverage",
|
|
62
69
|
"typecheck": "tsc --noEmit -p tsconfig.check.json",
|
|
63
70
|
"test": "vitest run",
|
|
64
|
-
"test:watch": "vitest"
|
|
71
|
+
"test:watch": "vitest",
|
|
72
|
+
"gen:auth-schemas": "UPDATE_AUTH_SCHEMAS=1 vitest run src/pluginSchemas.test.ts"
|
|
65
73
|
}
|
|
66
74
|
}
|