@lunora/auth 1.0.0-alpha.7 → 1.0.0-alpha.71
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/LICENSE.md +38 -0
- package/README.md +56 -1
- package/dist/adapter.d.mts +4 -43
- package/dist/adapter.d.ts +4 -43
- package/dist/adapter.mjs +1 -47
- package/dist/audit.d.mts +146 -0
- package/dist/audit.d.ts +146 -0
- package/dist/audit.mjs +12 -0
- package/dist/email-guard.d.mts +122 -0
- package/dist/email-guard.d.ts +122 -0
- package/dist/email-guard.mjs +1 -0
- package/dist/index.d.mts +698 -147
- package/dist/index.d.ts +698 -147
- package/dist/index.mjs +1 -12
- package/dist/middleware.d.mts +157 -156
- package/dist/middleware.d.ts +157 -156
- package/dist/middleware.mjs +1 -53
- package/dist/packem_shared/AUTH_DO_AUDIT_PATH-C4897amZ.mjs +1 -0
- package/dist/packem_shared/DEFAULT_AUTH_BASE_PATH-kIwlEt8i.mjs +1 -0
- package/dist/packem_shared/LunoraAuthAdminError-CiHsF1qZ.mjs +1 -0
- package/dist/packem_shared/adapter-RvDcm0Zy.mjs +1 -0
- package/dist/packem_shared/adapter.d-2a61HAY2.d.ts +76 -0
- package/dist/packem_shared/adapter.d-DrD3bb1u.d.mts +76 -0
- package/dist/packem_shared/authAuditHook-DG_ZNO53.mjs +1 -0
- package/dist/packem_shared/authDoColumnAdditions-B8BRbdzn.mjs +1 -0
- package/dist/packem_shared/compileMigrationsSql-BcvcHAqo.mjs +1 -0
- package/dist/packem_shared/create-auth.d-De6IOirt.d.mts +128 -0
- package/dist/packem_shared/create-auth.d-De6IOirt.d.ts +128 -0
- package/dist/packem_shared/createAuth-DRtd4q6u.mjs +1 -0
- package/dist/packem_shared/createDoAuthWiring-acnXUGZr.mjs +1 -0
- package/dist/packem_shared/createLunoraAuthClient-CedinxXU.mjs +1 -0
- package/dist/packem_shared/emailGateDatabaseHooks-DzBD1Qoq.mjs +1 -0
- package/dist/packem_shared/sessionPresets-DpEFjXKV.mjs +1 -0
- package/dist/packem_shared/uiConfig-BrYEFK3O.mjs +1 -0
- package/dist/plugins-client.d.mts +68 -1
- package/dist/plugins-client.d.ts +68 -1
- package/dist/plugins-client.mjs +1 -2
- package/dist/plugins-enterprise-client.d.mts +9 -0
- package/dist/plugins-enterprise-client.d.ts +9 -0
- package/dist/plugins-enterprise-client.mjs +1 -0
- package/dist/plugins-enterprise.d.mts +1576 -0
- package/dist/plugins-enterprise.d.ts +1576 -0
- package/dist/plugins-enterprise.mjs +1 -0
- package/dist/plugins.d.mts +83 -2
- package/dist/plugins.d.ts +83 -2
- package/dist/plugins.mjs +1 -22
- package/dist/schema.d.mts +39 -39
- package/dist/schema.d.ts +39 -39
- package/dist/schema.mjs +1 -62
- package/dist/sql-store.d.mts +28 -28
- package/dist/sql-store.d.ts +28 -28
- package/dist/sql-store.mjs +1 -162
- package/dist/store.d.mts +49 -31
- package/dist/store.d.ts +49 -31
- package/dist/store.mjs +1 -170
- package/dist/turnstile-middleware.d.mts +55 -55
- package/dist/turnstile-middleware.d.ts +55 -55
- package/dist/turnstile-middleware.mjs +1 -45
- package/dist/turnstile.d.mts +42 -59
- package/dist/turnstile.d.ts +42 -59
- package/dist/turnstile.mjs +1 -61
- package/package.json +38 -5
- package/dist/packem_shared/DEFAULT_AUTH_BASE_PATH-DjcUWEQl.mjs +0 -11
- package/dist/packem_shared/LunoraAuthAdminError-BxrfEeA_.mjs +0 -249
- package/dist/packem_shared/compileMigrationsSql-wZH3oXDu.mjs +0 -28
- package/dist/packem_shared/create-auth.d-M36jwG_Y.d.mts +0 -58
- package/dist/packem_shared/create-auth.d-M36jwG_Y.d.ts +0 -58
- package/dist/packem_shared/createAuth-B-tvsvQU.mjs +0 -56
- package/dist/packem_shared/sessionPresets-B95rXrd8.mjs +0 -35
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{sso as s}from"@better-auth/sso";export{s as sso};
|
package/dist/plugins.d.mts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import { BetterAuthPlugin } from 'better-auth';
|
|
2
|
+
export { mcp, mcpHandler, requireMcpAuth } from '@better-auth/mcp';
|
|
3
|
+
export { oauthProvider } from '@better-auth/oauth-provider';
|
|
1
4
|
export { passkey } from '@better-auth/passkey';
|
|
2
|
-
export {
|
|
5
|
+
export { scim } from '@better-auth/scim';
|
|
6
|
+
export { captcha } from 'better-auth/plugins';
|
|
3
7
|
export { createAccessControl } from 'better-auth/plugins/access';
|
|
4
8
|
export { admin } from 'better-auth/plugins/admin';
|
|
5
9
|
export { anonymous } from 'better-auth/plugins/anonymous';
|
|
@@ -13,10 +17,87 @@ export { jwt } from 'better-auth/plugins/jwt';
|
|
|
13
17
|
export { magicLink } from 'better-auth/plugins/magic-link';
|
|
14
18
|
export { multiSession } from 'better-auth/plugins/multi-session';
|
|
15
19
|
export { oAuthProxy } from 'better-auth/plugins/oauth-proxy';
|
|
16
|
-
export { oidcProvider } from 'better-auth/plugins/oidc-provider';
|
|
17
20
|
export { oneTimeToken } from 'better-auth/plugins/one-time-token';
|
|
18
21
|
export { organization } from 'better-auth/plugins/organization';
|
|
19
22
|
export { phoneNumber } from 'better-auth/plugins/phone-number';
|
|
20
23
|
export { siwe } from 'better-auth/plugins/siwe';
|
|
21
24
|
export { twoFactor } from 'better-auth/plugins/two-factor';
|
|
22
25
|
export { username } from 'better-auth/plugins/username';
|
|
26
|
+
/** Organization sub-features a UI branches on. */
|
|
27
|
+
interface UiConfigOrganization {
|
|
28
|
+
/** Whether an ordinary user may create one at all. */
|
|
29
|
+
allowUserToCreate: boolean;
|
|
30
|
+
enabled: boolean;
|
|
31
|
+
/** Max invitations per organization, when configured. */
|
|
32
|
+
invitationLimit?: number;
|
|
33
|
+
/** Max organizations one user may belong to, when configured. */
|
|
34
|
+
limit?: number;
|
|
35
|
+
/** Max members per organization, when configured. */
|
|
36
|
+
membershipLimit?: number;
|
|
37
|
+
/** Custom roles / dynamic access control are configured. */
|
|
38
|
+
roles: boolean;
|
|
39
|
+
/** Teams are enabled. */
|
|
40
|
+
teams: boolean;
|
|
41
|
+
}
|
|
42
|
+
/** The public payload `GET {basePath}/ui-config` returns. */
|
|
43
|
+
interface UiConfigPayload {
|
|
44
|
+
/** Whether email + password sign-in is enabled. */
|
|
45
|
+
emailAndPassword: boolean;
|
|
46
|
+
/** Absent when `expose.organization` is false — see {@link UiConfigOptions.expose}. */
|
|
47
|
+
organization?: UiConfigOrganization;
|
|
48
|
+
/** Enabled better-auth plugin ids, sorted. Absent when not disclosed. */
|
|
49
|
+
plugins?: string[];
|
|
50
|
+
/** Whether self-serve sign-up is open. */
|
|
51
|
+
signUp: boolean;
|
|
52
|
+
/** Configured social/OAuth provider ids, sorted. Absent when not disclosed. */
|
|
53
|
+
socialProviders?: string[];
|
|
54
|
+
}
|
|
55
|
+
/** Options for {@link uiConfig}. */
|
|
56
|
+
interface UiConfigOptions {
|
|
57
|
+
/**
|
|
58
|
+
* Omit fields from the payload. Everything is published by default; set a
|
|
59
|
+
* key to `false` for a deployment that would rather not enumerate, say, its
|
|
60
|
+
* plugin set to anonymous callers.
|
|
61
|
+
*
|
|
62
|
+
* The field is **omitted, not emptied**. An empty `plugins: []` is
|
|
63
|
+
* indistinguishable from "this deployment runs no plugins", and the client
|
|
64
|
+
* ANDs the server's answer with its own registration — so emptying it would
|
|
65
|
+
* silently switch off every gated card instead of merely withholding the
|
|
66
|
+
* list. Absent means "not disclosed", and the client falls back to what
|
|
67
|
+
* `client.ts` registered.
|
|
68
|
+
*/
|
|
69
|
+
expose?: {
|
|
70
|
+
organization?: boolean;
|
|
71
|
+
plugins?: boolean;
|
|
72
|
+
socialProviders?: boolean;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Extra provider ids to advertise beyond `socialProviders`. Providers wired
|
|
76
|
+
* through the `genericOAuth` plugin live in that plugin's own options rather
|
|
77
|
+
* than in `socialProviders`, so they cannot be derived here — list them if
|
|
78
|
+
* you want buttons for them.
|
|
79
|
+
*/
|
|
80
|
+
extraProviders?: string[];
|
|
81
|
+
/**
|
|
82
|
+
* Path the endpoint mounts at, relative to the auth basePath.
|
|
83
|
+
* @default "/ui-config"
|
|
84
|
+
*/
|
|
85
|
+
path?: string;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* A better-auth server plugin publishing {@link UiConfigPayload} at
|
|
89
|
+
* `GET {basePath}/ui-config`.
|
|
90
|
+
*
|
|
91
|
+
* There is no client half: the payload is fetched with a plain `fetch` by
|
|
92
|
+
* whatever renders your auth screens, so it works before a client exists and
|
|
93
|
+
* from a framework this package knows nothing about.
|
|
94
|
+
*
|
|
95
|
+
* The return type is better-auth's own `BetterAuthPlugin` rather than the precise
|
|
96
|
+
* shape of the endpoint map. That is deliberate: `createAuthEndpoint`'s inferred
|
|
97
|
+
* type is anonymous, and naming it is the difference between a build that emits
|
|
98
|
+
* declarations and one that fails only in the bundler — after `tsc` and the
|
|
99
|
+
* tests have both gone green. `BetterAuthPlugin` is what `createAuth({ plugins })`
|
|
100
|
+
* consumes anyway.
|
|
101
|
+
*/
|
|
102
|
+
declare const uiConfig: (options?: UiConfigOptions) => BetterAuthPlugin;
|
|
103
|
+
export { type UiConfigOptions, type UiConfigOrganization, type UiConfigPayload, uiConfig };
|
package/dist/plugins.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import { BetterAuthPlugin } from 'better-auth';
|
|
2
|
+
export { mcp, mcpHandler, requireMcpAuth } from '@better-auth/mcp';
|
|
3
|
+
export { oauthProvider } from '@better-auth/oauth-provider';
|
|
1
4
|
export { passkey } from '@better-auth/passkey';
|
|
2
|
-
export {
|
|
5
|
+
export { scim } from '@better-auth/scim';
|
|
6
|
+
export { captcha } from 'better-auth/plugins';
|
|
3
7
|
export { createAccessControl } from 'better-auth/plugins/access';
|
|
4
8
|
export { admin } from 'better-auth/plugins/admin';
|
|
5
9
|
export { anonymous } from 'better-auth/plugins/anonymous';
|
|
@@ -13,10 +17,87 @@ export { jwt } from 'better-auth/plugins/jwt';
|
|
|
13
17
|
export { magicLink } from 'better-auth/plugins/magic-link';
|
|
14
18
|
export { multiSession } from 'better-auth/plugins/multi-session';
|
|
15
19
|
export { oAuthProxy } from 'better-auth/plugins/oauth-proxy';
|
|
16
|
-
export { oidcProvider } from 'better-auth/plugins/oidc-provider';
|
|
17
20
|
export { oneTimeToken } from 'better-auth/plugins/one-time-token';
|
|
18
21
|
export { organization } from 'better-auth/plugins/organization';
|
|
19
22
|
export { phoneNumber } from 'better-auth/plugins/phone-number';
|
|
20
23
|
export { siwe } from 'better-auth/plugins/siwe';
|
|
21
24
|
export { twoFactor } from 'better-auth/plugins/two-factor';
|
|
22
25
|
export { username } from 'better-auth/plugins/username';
|
|
26
|
+
/** Organization sub-features a UI branches on. */
|
|
27
|
+
interface UiConfigOrganization {
|
|
28
|
+
/** Whether an ordinary user may create one at all. */
|
|
29
|
+
allowUserToCreate: boolean;
|
|
30
|
+
enabled: boolean;
|
|
31
|
+
/** Max invitations per organization, when configured. */
|
|
32
|
+
invitationLimit?: number;
|
|
33
|
+
/** Max organizations one user may belong to, when configured. */
|
|
34
|
+
limit?: number;
|
|
35
|
+
/** Max members per organization, when configured. */
|
|
36
|
+
membershipLimit?: number;
|
|
37
|
+
/** Custom roles / dynamic access control are configured. */
|
|
38
|
+
roles: boolean;
|
|
39
|
+
/** Teams are enabled. */
|
|
40
|
+
teams: boolean;
|
|
41
|
+
}
|
|
42
|
+
/** The public payload `GET {basePath}/ui-config` returns. */
|
|
43
|
+
interface UiConfigPayload {
|
|
44
|
+
/** Whether email + password sign-in is enabled. */
|
|
45
|
+
emailAndPassword: boolean;
|
|
46
|
+
/** Absent when `expose.organization` is false — see {@link UiConfigOptions.expose}. */
|
|
47
|
+
organization?: UiConfigOrganization;
|
|
48
|
+
/** Enabled better-auth plugin ids, sorted. Absent when not disclosed. */
|
|
49
|
+
plugins?: string[];
|
|
50
|
+
/** Whether self-serve sign-up is open. */
|
|
51
|
+
signUp: boolean;
|
|
52
|
+
/** Configured social/OAuth provider ids, sorted. Absent when not disclosed. */
|
|
53
|
+
socialProviders?: string[];
|
|
54
|
+
}
|
|
55
|
+
/** Options for {@link uiConfig}. */
|
|
56
|
+
interface UiConfigOptions {
|
|
57
|
+
/**
|
|
58
|
+
* Omit fields from the payload. Everything is published by default; set a
|
|
59
|
+
* key to `false` for a deployment that would rather not enumerate, say, its
|
|
60
|
+
* plugin set to anonymous callers.
|
|
61
|
+
*
|
|
62
|
+
* The field is **omitted, not emptied**. An empty `plugins: []` is
|
|
63
|
+
* indistinguishable from "this deployment runs no plugins", and the client
|
|
64
|
+
* ANDs the server's answer with its own registration — so emptying it would
|
|
65
|
+
* silently switch off every gated card instead of merely withholding the
|
|
66
|
+
* list. Absent means "not disclosed", and the client falls back to what
|
|
67
|
+
* `client.ts` registered.
|
|
68
|
+
*/
|
|
69
|
+
expose?: {
|
|
70
|
+
organization?: boolean;
|
|
71
|
+
plugins?: boolean;
|
|
72
|
+
socialProviders?: boolean;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Extra provider ids to advertise beyond `socialProviders`. Providers wired
|
|
76
|
+
* through the `genericOAuth` plugin live in that plugin's own options rather
|
|
77
|
+
* than in `socialProviders`, so they cannot be derived here — list them if
|
|
78
|
+
* you want buttons for them.
|
|
79
|
+
*/
|
|
80
|
+
extraProviders?: string[];
|
|
81
|
+
/**
|
|
82
|
+
* Path the endpoint mounts at, relative to the auth basePath.
|
|
83
|
+
* @default "/ui-config"
|
|
84
|
+
*/
|
|
85
|
+
path?: string;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* A better-auth server plugin publishing {@link UiConfigPayload} at
|
|
89
|
+
* `GET {basePath}/ui-config`.
|
|
90
|
+
*
|
|
91
|
+
* There is no client half: the payload is fetched with a plain `fetch` by
|
|
92
|
+
* whatever renders your auth screens, so it works before a client exists and
|
|
93
|
+
* from a framework this package knows nothing about.
|
|
94
|
+
*
|
|
95
|
+
* The return type is better-auth's own `BetterAuthPlugin` rather than the precise
|
|
96
|
+
* shape of the endpoint map. That is deliberate: `createAuthEndpoint`'s inferred
|
|
97
|
+
* type is anonymous, and naming it is the difference between a build that emits
|
|
98
|
+
* declarations and one that fails only in the bundler — after `tsc` and the
|
|
99
|
+
* tests have both gone green. `BetterAuthPlugin` is what `createAuth({ plugins })`
|
|
100
|
+
* consumes anyway.
|
|
101
|
+
*/
|
|
102
|
+
declare const uiConfig: (options?: UiConfigOptions) => BetterAuthPlugin;
|
|
103
|
+
export { type UiConfigOptions, type UiConfigOrganization, type UiConfigPayload, uiConfig };
|
package/dist/plugins.mjs
CHANGED
|
@@ -1,22 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { captcha, mcp, withMcpAuth } from 'better-auth/plugins';
|
|
3
|
-
export { createAccessControl } from 'better-auth/plugins/access';
|
|
4
|
-
export { admin } from 'better-auth/plugins/admin';
|
|
5
|
-
export { anonymous } from 'better-auth/plugins/anonymous';
|
|
6
|
-
export { bearer } from 'better-auth/plugins/bearer';
|
|
7
|
-
export { customSession } from 'better-auth/plugins/custom-session';
|
|
8
|
-
export { deviceAuthorization } from 'better-auth/plugins/device-authorization';
|
|
9
|
-
export { emailOTP } from 'better-auth/plugins/email-otp';
|
|
10
|
-
export { genericOAuth } from 'better-auth/plugins/generic-oauth';
|
|
11
|
-
export { haveIBeenPwned } from 'better-auth/plugins/haveibeenpwned';
|
|
12
|
-
export { jwt } from 'better-auth/plugins/jwt';
|
|
13
|
-
export { magicLink } from 'better-auth/plugins/magic-link';
|
|
14
|
-
export { multiSession } from 'better-auth/plugins/multi-session';
|
|
15
|
-
export { oAuthProxy } from 'better-auth/plugins/oauth-proxy';
|
|
16
|
-
export { oidcProvider } from 'better-auth/plugins/oidc-provider';
|
|
17
|
-
export { oneTimeToken } from 'better-auth/plugins/one-time-token';
|
|
18
|
-
export { organization } from 'better-auth/plugins/organization';
|
|
19
|
-
export { phoneNumber } from 'better-auth/plugins/phone-number';
|
|
20
|
-
export { siwe } from 'better-auth/plugins/siwe';
|
|
21
|
-
export { twoFactor } from 'better-auth/plugins/two-factor';
|
|
22
|
-
export { username } from 'better-auth/plugins/username';
|
|
1
|
+
import{uiConfig as e}from"./packem_shared/uiConfig-BrYEFK3O.mjs";import{mcp as m,mcpHandler as p,requireMcpAuth as f}from"@better-auth/mcp";import{oauthProvider as i}from"@better-auth/oauth-provider";import{passkey as a}from"@better-auth/passkey";import{scim as s}from"@better-auth/scim";import{captcha as h}from"better-auth/plugins";import{createAccessControl as A}from"better-auth/plugins/access";import{admin as l}from"better-auth/plugins/admin";import{anonymous as P}from"better-auth/plugins/anonymous";import{bearer as v}from"better-auth/plugins/bearer";import{customSession as T}from"better-auth/plugins/custom-session";import{deviceAuthorization as z}from"better-auth/plugins/device-authorization";import{emailOTP as O}from"better-auth/plugins/email-otp";import{genericOAuth as j}from"better-auth/plugins/generic-oauth";import{haveIBeenPwned as B}from"better-auth/plugins/haveibeenpwned";import{jwt as H}from"better-auth/plugins/jwt";import{magicLink as L}from"better-auth/plugins/magic-link";import{multiSession as N}from"better-auth/plugins/multi-session";import{oAuthProxy as E}from"better-auth/plugins/oauth-proxy";import{oneTimeToken as J}from"better-auth/plugins/one-time-token";import{organization as Q}from"better-auth/plugins/organization";import{phoneNumber as U}from"better-auth/plugins/phone-number";import{siwe as W}from"better-auth/plugins/siwe";import{twoFactor as Y}from"better-auth/plugins/two-factor";import{username as _}from"better-auth/plugins/username";export{l as admin,P as anonymous,v as bearer,h as captcha,A as createAccessControl,T as customSession,z as deviceAuthorization,O as emailOTP,j as genericOAuth,B as haveIBeenPwned,H as jwt,L as magicLink,m as mcp,p as mcpHandler,N as multiSession,E as oAuthProxy,i as oauthProvider,J as oneTimeToken,Q as organization,a as passkey,U as phoneNumber,f as requireMcpAuth,s as scim,W as siwe,Y as twoFactor,e as uiConfig,_ as username};
|
package/dist/schema.d.mts
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
1
|
import { TableDefinition } from '@lunora/server';
|
|
2
|
-
import { a as LunoraAuthOptions } from "./packem_shared/create-auth.d-
|
|
2
|
+
import { a as LunoraAuthOptions } from "./packem_shared/create-auth.d-De6IOirt.mjs";
|
|
3
3
|
import 'better-auth';
|
|
4
4
|
/**
|
|
5
|
-
* Derive Lunora table definitions from a better-auth config — the bridge that
|
|
6
|
-
* makes the **full** better-auth plugin ecosystem first-class Lunora data.
|
|
7
|
-
*
|
|
8
|
-
* better-auth's own `getAuthTables(options)` already merges every configured
|
|
9
|
-
* plugin's `schema` into one table map (core `user`/`session`/`account`/
|
|
10
|
-
* `verification`, plus whatever the plugins on `options.plugins` add —
|
|
11
|
-
* `organization`/`member`/`invitation`/`team`/`teamMember` from the
|
|
12
|
-
* organization plugin, `role`/`banned`/… columns from admin, `passkey`,
|
|
13
|
-
* `twoFactor`, `jwks`, …). This walks that map and emits an equivalent
|
|
14
|
-
* `defineTable` for each, so adding a plugin to `options.plugins` automatically
|
|
15
|
-
* surfaces its tables in the Lunora schema — no hand-written table definitions
|
|
16
|
-
* to keep in sync.
|
|
17
|
-
*
|
|
18
|
-
* Spread the result into `defineSchema` alongside your app tables (the keys are
|
|
19
|
-
* better-auth's real table names — `user`, `session`, … — left **unprefixed**
|
|
20
|
-
* because better-auth's adapter addresses them by exactly those names). Because
|
|
21
|
-
* the names are unprefixed, do **not** declare an app table that reuses one of
|
|
22
|
-
* better-auth's reserved names in the same `defineSchema` — JS spread order
|
|
23
|
-
* would let the later key win silently (unlike the plugin-extension path, which
|
|
24
|
-
* throws on collision):
|
|
25
|
-
*
|
|
26
|
-
* ```ts
|
|
27
|
-
* import { authTables } from "@lunora/auth";
|
|
28
|
-
* const authOptions = { emailAndPassword: { enabled: true }, plugins: [organization(), admin()] };
|
|
29
|
-
* export const schema = defineSchema({
|
|
30
|
-
* ...authTables(authOptions),
|
|
31
|
-
* todos: defineTable({ title: v.string() }),
|
|
32
|
-
* });
|
|
33
|
-
* ```
|
|
34
|
-
*
|
|
35
|
-
* Scope: this emits the table **shapes** (columns + types + nullability +
|
|
36
|
-
* uniqueness + FK ids). It deliberately does not carry better-auth's
|
|
37
|
-
* `defaultValue`/`onUpdate` (filled by better-auth's own write layer), `index`
|
|
38
|
-
* hints, or `bigint` precision (`bigint` fields map to `v.number()`). Those only
|
|
39
|
-
* matter once better-auth's writes are routed through Lunora's ORM — a separate
|
|
40
|
-
* adapter follow-up; today the auth rows are still written by better-auth's D1
|
|
41
|
-
* adapter and these tables make them typed + queryable via `ctx.db`.
|
|
42
|
-
*/
|
|
5
|
+
* Derive Lunora table definitions from a better-auth config — the bridge that
|
|
6
|
+
* makes the **full** better-auth plugin ecosystem first-class Lunora data.
|
|
7
|
+
*
|
|
8
|
+
* better-auth's own `getAuthTables(options)` already merges every configured
|
|
9
|
+
* plugin's `schema` into one table map (core `user`/`session`/`account`/
|
|
10
|
+
* `verification`, plus whatever the plugins on `options.plugins` add —
|
|
11
|
+
* `organization`/`member`/`invitation`/`team`/`teamMember` from the
|
|
12
|
+
* organization plugin, `role`/`banned`/… columns from admin, `passkey`,
|
|
13
|
+
* `twoFactor`, `jwks`, …). This walks that map and emits an equivalent
|
|
14
|
+
* `defineTable` for each, so adding a plugin to `options.plugins` automatically
|
|
15
|
+
* surfaces its tables in the Lunora schema — no hand-written table definitions
|
|
16
|
+
* to keep in sync.
|
|
17
|
+
*
|
|
18
|
+
* Spread the result into `defineSchema` alongside your app tables (the keys are
|
|
19
|
+
* better-auth's real table names — `user`, `session`, … — left **unprefixed**
|
|
20
|
+
* because better-auth's adapter addresses them by exactly those names). Because
|
|
21
|
+
* the names are unprefixed, do **not** declare an app table that reuses one of
|
|
22
|
+
* better-auth's reserved names in the same `defineSchema` — JS spread order
|
|
23
|
+
* would let the later key win silently (unlike the plugin-extension path, which
|
|
24
|
+
* throws on collision):
|
|
25
|
+
*
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { authTables } from "@lunora/auth";
|
|
28
|
+
* const authOptions = { emailAndPassword: { enabled: true }, plugins: [organization(), admin()] };
|
|
29
|
+
* export const schema = defineSchema({
|
|
30
|
+
* ...authTables(authOptions),
|
|
31
|
+
* todos: defineTable({ title: v.string() }),
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* Scope: this emits the table **shapes** (columns + types + nullability +
|
|
36
|
+
* uniqueness + FK ids). It deliberately does not carry better-auth's
|
|
37
|
+
* `defaultValue`/`onUpdate` (filled by better-auth's own write layer), `index`
|
|
38
|
+
* hints, or `bigint` precision (`bigint` fields map to `v.number()`). Those only
|
|
39
|
+
* matter once better-auth's writes are routed through Lunora's ORM — a separate
|
|
40
|
+
* adapter follow-up; today the auth rows are still written by better-auth's D1
|
|
41
|
+
* adapter and these tables make them typed + queryable via `ctx.db`.
|
|
42
|
+
*/
|
|
43
43
|
declare const authTables: (options: LunoraAuthOptions) => Record<string, TableDefinition>;
|
|
44
44
|
export { authTables as default };
|
package/dist/schema.d.ts
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
1
|
import { TableDefinition } from '@lunora/server';
|
|
2
|
-
import { a as LunoraAuthOptions } from "./packem_shared/create-auth.d-
|
|
2
|
+
import { a as LunoraAuthOptions } from "./packem_shared/create-auth.d-De6IOirt.js";
|
|
3
3
|
import 'better-auth';
|
|
4
4
|
/**
|
|
5
|
-
* Derive Lunora table definitions from a better-auth config — the bridge that
|
|
6
|
-
* makes the **full** better-auth plugin ecosystem first-class Lunora data.
|
|
7
|
-
*
|
|
8
|
-
* better-auth's own `getAuthTables(options)` already merges every configured
|
|
9
|
-
* plugin's `schema` into one table map (core `user`/`session`/`account`/
|
|
10
|
-
* `verification`, plus whatever the plugins on `options.plugins` add —
|
|
11
|
-
* `organization`/`member`/`invitation`/`team`/`teamMember` from the
|
|
12
|
-
* organization plugin, `role`/`banned`/… columns from admin, `passkey`,
|
|
13
|
-
* `twoFactor`, `jwks`, …). This walks that map and emits an equivalent
|
|
14
|
-
* `defineTable` for each, so adding a plugin to `options.plugins` automatically
|
|
15
|
-
* surfaces its tables in the Lunora schema — no hand-written table definitions
|
|
16
|
-
* to keep in sync.
|
|
17
|
-
*
|
|
18
|
-
* Spread the result into `defineSchema` alongside your app tables (the keys are
|
|
19
|
-
* better-auth's real table names — `user`, `session`, … — left **unprefixed**
|
|
20
|
-
* because better-auth's adapter addresses them by exactly those names). Because
|
|
21
|
-
* the names are unprefixed, do **not** declare an app table that reuses one of
|
|
22
|
-
* better-auth's reserved names in the same `defineSchema` — JS spread order
|
|
23
|
-
* would let the later key win silently (unlike the plugin-extension path, which
|
|
24
|
-
* throws on collision):
|
|
25
|
-
*
|
|
26
|
-
* ```ts
|
|
27
|
-
* import { authTables } from "@lunora/auth";
|
|
28
|
-
* const authOptions = { emailAndPassword: { enabled: true }, plugins: [organization(), admin()] };
|
|
29
|
-
* export const schema = defineSchema({
|
|
30
|
-
* ...authTables(authOptions),
|
|
31
|
-
* todos: defineTable({ title: v.string() }),
|
|
32
|
-
* });
|
|
33
|
-
* ```
|
|
34
|
-
*
|
|
35
|
-
* Scope: this emits the table **shapes** (columns + types + nullability +
|
|
36
|
-
* uniqueness + FK ids). It deliberately does not carry better-auth's
|
|
37
|
-
* `defaultValue`/`onUpdate` (filled by better-auth's own write layer), `index`
|
|
38
|
-
* hints, or `bigint` precision (`bigint` fields map to `v.number()`). Those only
|
|
39
|
-
* matter once better-auth's writes are routed through Lunora's ORM — a separate
|
|
40
|
-
* adapter follow-up; today the auth rows are still written by better-auth's D1
|
|
41
|
-
* adapter and these tables make them typed + queryable via `ctx.db`.
|
|
42
|
-
*/
|
|
5
|
+
* Derive Lunora table definitions from a better-auth config — the bridge that
|
|
6
|
+
* makes the **full** better-auth plugin ecosystem first-class Lunora data.
|
|
7
|
+
*
|
|
8
|
+
* better-auth's own `getAuthTables(options)` already merges every configured
|
|
9
|
+
* plugin's `schema` into one table map (core `user`/`session`/`account`/
|
|
10
|
+
* `verification`, plus whatever the plugins on `options.plugins` add —
|
|
11
|
+
* `organization`/`member`/`invitation`/`team`/`teamMember` from the
|
|
12
|
+
* organization plugin, `role`/`banned`/… columns from admin, `passkey`,
|
|
13
|
+
* `twoFactor`, `jwks`, …). This walks that map and emits an equivalent
|
|
14
|
+
* `defineTable` for each, so adding a plugin to `options.plugins` automatically
|
|
15
|
+
* surfaces its tables in the Lunora schema — no hand-written table definitions
|
|
16
|
+
* to keep in sync.
|
|
17
|
+
*
|
|
18
|
+
* Spread the result into `defineSchema` alongside your app tables (the keys are
|
|
19
|
+
* better-auth's real table names — `user`, `session`, … — left **unprefixed**
|
|
20
|
+
* because better-auth's adapter addresses them by exactly those names). Because
|
|
21
|
+
* the names are unprefixed, do **not** declare an app table that reuses one of
|
|
22
|
+
* better-auth's reserved names in the same `defineSchema` — JS spread order
|
|
23
|
+
* would let the later key win silently (unlike the plugin-extension path, which
|
|
24
|
+
* throws on collision):
|
|
25
|
+
*
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { authTables } from "@lunora/auth";
|
|
28
|
+
* const authOptions = { emailAndPassword: { enabled: true }, plugins: [organization(), admin()] };
|
|
29
|
+
* export const schema = defineSchema({
|
|
30
|
+
* ...authTables(authOptions),
|
|
31
|
+
* todos: defineTable({ title: v.string() }),
|
|
32
|
+
* });
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* Scope: this emits the table **shapes** (columns + types + nullability +
|
|
36
|
+
* uniqueness + FK ids). It deliberately does not carry better-auth's
|
|
37
|
+
* `defaultValue`/`onUpdate` (filled by better-auth's own write layer), `index`
|
|
38
|
+
* hints, or `bigint` precision (`bigint` fields map to `v.number()`). Those only
|
|
39
|
+
* matter once better-auth's writes are routed through Lunora's ORM — a separate
|
|
40
|
+
* adapter follow-up; today the auth rows are still written by better-auth's D1
|
|
41
|
+
* adapter and these tables make them typed + queryable via `ctx.db`.
|
|
42
|
+
*/
|
|
43
43
|
declare const authTables: (options: LunoraAuthOptions) => Record<string, TableDefinition>;
|
|
44
44
|
export { authTables as default };
|
package/dist/schema.mjs
CHANGED
|
@@ -1,62 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { v } from '@lunora/values';
|
|
3
|
-
import { getAuthTables } from 'better-auth/db';
|
|
4
|
-
|
|
5
|
-
const baseValidator = (attribute) => {
|
|
6
|
-
if (attribute.references) {
|
|
7
|
-
return v.id(attribute.references.model);
|
|
8
|
-
}
|
|
9
|
-
const { type } = attribute;
|
|
10
|
-
if (Array.isArray(type)) {
|
|
11
|
-
return v.string();
|
|
12
|
-
}
|
|
13
|
-
switch (type) {
|
|
14
|
-
case "boolean": {
|
|
15
|
-
return v.boolean();
|
|
16
|
-
}
|
|
17
|
-
case "date": {
|
|
18
|
-
return v.date();
|
|
19
|
-
}
|
|
20
|
-
case "number": {
|
|
21
|
-
return v.number();
|
|
22
|
-
}
|
|
23
|
-
case "number[]": {
|
|
24
|
-
return v.array(v.number());
|
|
25
|
-
}
|
|
26
|
-
case "string": {
|
|
27
|
-
return v.string();
|
|
28
|
-
}
|
|
29
|
-
case "string[]": {
|
|
30
|
-
return v.array(v.string());
|
|
31
|
-
}
|
|
32
|
-
// "json" and anything unrecognised: keep the row shape permissive rather
|
|
33
|
-
// than fail schema generation on a plugin's exotic column type.
|
|
34
|
-
default: {
|
|
35
|
-
return v.any();
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
const fieldValidator = (attribute) => {
|
|
40
|
-
let validator = baseValidator(attribute);
|
|
41
|
-
if (attribute.required === false) {
|
|
42
|
-
validator = validator.nullable();
|
|
43
|
-
}
|
|
44
|
-
if (attribute.unique === true) {
|
|
45
|
-
validator = validator.unique();
|
|
46
|
-
}
|
|
47
|
-
return validator;
|
|
48
|
-
};
|
|
49
|
-
const authTables = (options) => {
|
|
50
|
-
const tables = getAuthTables(options);
|
|
51
|
-
const schema = {};
|
|
52
|
-
for (const table of Object.values(tables)) {
|
|
53
|
-
const shape = {};
|
|
54
|
-
for (const [fieldKey, attribute] of Object.entries(table.fields)) {
|
|
55
|
-
shape[attribute.fieldName ?? fieldKey] = fieldValidator(attribute);
|
|
56
|
-
}
|
|
57
|
-
schema[table.modelName] = defineTable(shape).externallyManaged();
|
|
58
|
-
}
|
|
59
|
-
return schema;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
export { authTables as default };
|
|
1
|
+
import{defineTable as i}from"@lunora/server";import{v as e}from"@lunora/values";import{getAuthTables as c}from"better-auth/db";const f=n=>{if(n.references)return e.id(n.references.model);const{type:r}=n;if(Array.isArray(r))return e.string();switch(r){case"boolean":return e.boolean();case"date":return e.date();case"number":return e.number();case"number[]":return e.array(e.number());case"string":return e.string();case"string[]":return e.array(e.string());default:return e.any()}},l=n=>{let r=f(n);return n.required===!1&&(r=r.nullable()),n.unique===!0&&(r=r.unique()),r},g=n=>{const r=c(n),t={};for(const a of Object.values(r)){const s={};for(const[o,u]of Object.entries(a.fields))s[u.fieldName??o]=l(u);t[a.modelName]=i(s).externallyManaged()}return t};export{g as default};
|
package/dist/sql-store.d.mts
CHANGED
|
@@ -12,40 +12,40 @@ interface D1Like {
|
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
|
-
* The minimal SQL seam a {@link createSqlAuthStore} runs on — structurally the
|
|
16
|
-
* same `{ all, run }` contract as `@lunora/d1`'s `D1Exec`, so a Lunora D1 binding
|
|
17
|
-
* satisfies it directly (see {@link d1Executor}) and a `node:sqlite` handle does
|
|
18
|
-
* too in tests. `all` runs reads and returns rows; `run` runs writes.
|
|
19
|
-
*/
|
|
15
|
+
* The minimal SQL seam a {@link createSqlAuthStore} runs on — structurally the
|
|
16
|
+
* same `{ all, run }` contract as `@lunora/d1`'s `D1Exec`, so a Lunora D1 binding
|
|
17
|
+
* satisfies it directly (see {@link d1Executor}) and a `node:sqlite` handle does
|
|
18
|
+
* too in tests. `all` runs reads and returns rows; `run` runs writes.
|
|
19
|
+
*/
|
|
20
20
|
interface SqlExecutor {
|
|
21
21
|
all: (sql: string, parameters: ReadonlyArray<unknown>) => Promise<Record<string, unknown>[]>;
|
|
22
22
|
run: (sql: string, parameters: ReadonlyArray<unknown>) => Promise<void>;
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
|
-
* An {@link AuthStore} backed by a SQL database through the {@link SqlExecutor}
|
|
26
|
-
* seam — the production counterpart to `createMemoryAuthStore`. Point it at the
|
|
27
|
-
* same database that hosts Lunora's global (D1) tables (the ones `authTables(...)`
|
|
28
|
-
* generates) and better-auth's reads/writes land there as ordinary rows Lunora
|
|
29
|
-
* can also query. Assumes the auth tables already exist (Lunora owns the schema /
|
|
30
|
-
* migrations); it never issues DDL.
|
|
31
|
-
*
|
|
32
|
-
* ```ts
|
|
33
|
-
* const store = createSqlAuthStore(d1Executor(env.DB));
|
|
34
|
-
* const auth = createAuth({ secret: env.AUTH_SECRET, database: lunoraAuthAdapter(store) });
|
|
35
|
-
* ```
|
|
36
|
-
*
|
|
37
|
-
* Clause semantics match `createMemoryAuthStore` (operator parity is
|
|
38
|
-
* covered by a cross-store agreement test) with one unavoidable caveat:
|
|
39
|
-
* case-**insensitive** matching uses SQLite's ASCII-only `LOWER()`, whereas the
|
|
40
|
-
* in-memory store uses JS full-Unicode `toLowerCase()`. They agree on ASCII
|
|
41
|
-
* (emails, ids, tokens — the credential path); they can differ only for
|
|
42
|
-
* case-insensitive comparison of non-ASCII text.
|
|
43
|
-
*/
|
|
25
|
+
* An {@link AuthStore} backed by a SQL database through the {@link SqlExecutor}
|
|
26
|
+
* seam — the production counterpart to `createMemoryAuthStore`. Point it at the
|
|
27
|
+
* same database that hosts Lunora's global (D1) tables (the ones `authTables(...)`
|
|
28
|
+
* generates) and better-auth's reads/writes land there as ordinary rows Lunora
|
|
29
|
+
* can also query. Assumes the auth tables already exist (Lunora owns the schema /
|
|
30
|
+
* migrations); it never issues DDL.
|
|
31
|
+
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* const store = createSqlAuthStore(d1Executor(env.DB));
|
|
34
|
+
* const auth = createAuth({ secret: env.AUTH_SECRET, database: lunoraAuthAdapter(store) });
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* Clause semantics match `createMemoryAuthStore` (operator parity is
|
|
38
|
+
* covered by a cross-store agreement test) with one unavoidable caveat:
|
|
39
|
+
* case-**insensitive** matching uses SQLite's ASCII-only `LOWER()`, whereas the
|
|
40
|
+
* in-memory store uses JS full-Unicode `toLowerCase()`. They agree on ASCII
|
|
41
|
+
* (emails, ids, tokens — the credential path); they can differ only for
|
|
42
|
+
* case-insensitive comparison of non-ASCII text.
|
|
43
|
+
*/
|
|
44
44
|
declare const createSqlAuthStore: (executor: SqlExecutor) => AuthStore;
|
|
45
45
|
/**
|
|
46
|
-
* Wrap a Cloudflare D1 binding (`env.DB`) as a {@link SqlExecutor}, so
|
|
47
|
-
* `createSqlAuthStore(d1Executor(env.DB))` routes better-auth onto D1 — the same
|
|
48
|
-
* binding Lunora's `.global()` tables use.
|
|
49
|
-
*/
|
|
46
|
+
* Wrap a Cloudflare D1 binding (`env.DB`) as a {@link SqlExecutor}, so
|
|
47
|
+
* `createSqlAuthStore(d1Executor(env.DB))` routes better-auth onto D1 — the same
|
|
48
|
+
* binding Lunora's `.global()` tables use.
|
|
49
|
+
*/
|
|
50
50
|
declare const d1Executor: (database: D1Like) => SqlExecutor;
|
|
51
51
|
export { SqlExecutor, createSqlAuthStore, d1Executor };
|
package/dist/sql-store.d.ts
CHANGED
|
@@ -12,40 +12,40 @@ interface D1Like {
|
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
|
-
* The minimal SQL seam a {@link createSqlAuthStore} runs on — structurally the
|
|
16
|
-
* same `{ all, run }` contract as `@lunora/d1`'s `D1Exec`, so a Lunora D1 binding
|
|
17
|
-
* satisfies it directly (see {@link d1Executor}) and a `node:sqlite` handle does
|
|
18
|
-
* too in tests. `all` runs reads and returns rows; `run` runs writes.
|
|
19
|
-
*/
|
|
15
|
+
* The minimal SQL seam a {@link createSqlAuthStore} runs on — structurally the
|
|
16
|
+
* same `{ all, run }` contract as `@lunora/d1`'s `D1Exec`, so a Lunora D1 binding
|
|
17
|
+
* satisfies it directly (see {@link d1Executor}) and a `node:sqlite` handle does
|
|
18
|
+
* too in tests. `all` runs reads and returns rows; `run` runs writes.
|
|
19
|
+
*/
|
|
20
20
|
interface SqlExecutor {
|
|
21
21
|
all: (sql: string, parameters: ReadonlyArray<unknown>) => Promise<Record<string, unknown>[]>;
|
|
22
22
|
run: (sql: string, parameters: ReadonlyArray<unknown>) => Promise<void>;
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
|
-
* An {@link AuthStore} backed by a SQL database through the {@link SqlExecutor}
|
|
26
|
-
* seam — the production counterpart to `createMemoryAuthStore`. Point it at the
|
|
27
|
-
* same database that hosts Lunora's global (D1) tables (the ones `authTables(...)`
|
|
28
|
-
* generates) and better-auth's reads/writes land there as ordinary rows Lunora
|
|
29
|
-
* can also query. Assumes the auth tables already exist (Lunora owns the schema /
|
|
30
|
-
* migrations); it never issues DDL.
|
|
31
|
-
*
|
|
32
|
-
* ```ts
|
|
33
|
-
* const store = createSqlAuthStore(d1Executor(env.DB));
|
|
34
|
-
* const auth = createAuth({ secret: env.AUTH_SECRET, database: lunoraAuthAdapter(store) });
|
|
35
|
-
* ```
|
|
36
|
-
*
|
|
37
|
-
* Clause semantics match `createMemoryAuthStore` (operator parity is
|
|
38
|
-
* covered by a cross-store agreement test) with one unavoidable caveat:
|
|
39
|
-
* case-**insensitive** matching uses SQLite's ASCII-only `LOWER()`, whereas the
|
|
40
|
-
* in-memory store uses JS full-Unicode `toLowerCase()`. They agree on ASCII
|
|
41
|
-
* (emails, ids, tokens — the credential path); they can differ only for
|
|
42
|
-
* case-insensitive comparison of non-ASCII text.
|
|
43
|
-
*/
|
|
25
|
+
* An {@link AuthStore} backed by a SQL database through the {@link SqlExecutor}
|
|
26
|
+
* seam — the production counterpart to `createMemoryAuthStore`. Point it at the
|
|
27
|
+
* same database that hosts Lunora's global (D1) tables (the ones `authTables(...)`
|
|
28
|
+
* generates) and better-auth's reads/writes land there as ordinary rows Lunora
|
|
29
|
+
* can also query. Assumes the auth tables already exist (Lunora owns the schema /
|
|
30
|
+
* migrations); it never issues DDL.
|
|
31
|
+
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* const store = createSqlAuthStore(d1Executor(env.DB));
|
|
34
|
+
* const auth = createAuth({ secret: env.AUTH_SECRET, database: lunoraAuthAdapter(store) });
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* Clause semantics match `createMemoryAuthStore` (operator parity is
|
|
38
|
+
* covered by a cross-store agreement test) with one unavoidable caveat:
|
|
39
|
+
* case-**insensitive** matching uses SQLite's ASCII-only `LOWER()`, whereas the
|
|
40
|
+
* in-memory store uses JS full-Unicode `toLowerCase()`. They agree on ASCII
|
|
41
|
+
* (emails, ids, tokens — the credential path); they can differ only for
|
|
42
|
+
* case-insensitive comparison of non-ASCII text.
|
|
43
|
+
*/
|
|
44
44
|
declare const createSqlAuthStore: (executor: SqlExecutor) => AuthStore;
|
|
45
45
|
/**
|
|
46
|
-
* Wrap a Cloudflare D1 binding (`env.DB`) as a {@link SqlExecutor}, so
|
|
47
|
-
* `createSqlAuthStore(d1Executor(env.DB))` routes better-auth onto D1 — the same
|
|
48
|
-
* binding Lunora's `.global()` tables use.
|
|
49
|
-
*/
|
|
46
|
+
* Wrap a Cloudflare D1 binding (`env.DB`) as a {@link SqlExecutor}, so
|
|
47
|
+
* `createSqlAuthStore(d1Executor(env.DB))` routes better-auth onto D1 — the same
|
|
48
|
+
* binding Lunora's `.global()` tables use.
|
|
49
|
+
*/
|
|
50
50
|
declare const d1Executor: (database: D1Like) => SqlExecutor;
|
|
51
51
|
export { SqlExecutor, createSqlAuthStore, d1Executor };
|