@lunora/auth 1.0.0-alpha.28 → 1.0.0-alpha.280
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 +233 -104
- package/README.md +109 -15
- package/dist/adapter.d.mts +4 -43
- package/dist/adapter.d.ts +4 -43
- package/dist/adapter.mjs +1 -48
- package/dist/audit.d.mts +173 -0
- package/dist/audit.d.ts +173 -0
- package/dist/audit.mjs +1 -0
- package/dist/cimd-node.d.mts +1 -0
- package/dist/cimd-node.d.ts +1 -0
- package/dist/cimd-node.mjs +1 -0
- package/dist/cimd-workers.d.mts +64 -0
- package/dist/cimd-workers.d.ts +64 -0
- package/dist/cimd-workers.mjs +1 -0
- package/dist/email-guard.d.mts +143 -0
- package/dist/email-guard.d.ts +143 -0
- package/dist/email-guard.mjs +1 -0
- package/dist/index.d.mts +620 -541
- package/dist/index.d.ts +620 -541
- package/dist/index.mjs +1 -12
- package/dist/middleware.d.mts +165 -155
- package/dist/middleware.d.ts +165 -155
- package/dist/middleware.mjs +1 -56
- package/dist/migrate.d.mts +62 -0
- package/dist/migrate.d.ts +62 -0
- package/dist/migrate.mjs +1 -0
- package/dist/packem_shared/AUTH_DO_AUDIT_PATH-jbpoDPJs.mjs +1 -0
- package/dist/packem_shared/DEFAULT_AUTH_BASE_PATH-C3SqYG3N.mjs +1 -0
- package/dist/packem_shared/LunoraAuthAdminError-Cg94b5lr.mjs +1 -0
- package/dist/packem_shared/adapter-L3XvHnkW.mjs +2 -0
- package/dist/packem_shared/adapter.d-BEvPbvSs.d.ts +110 -0
- package/dist/packem_shared/adapter.d-RQVSeO5T.d.mts +110 -0
- package/dist/packem_shared/api-key-storage-D15k9_CF.mjs +1 -0
- package/dist/packem_shared/apiKey-B9uGt5Nc.mjs +1 -0
- package/dist/packem_shared/audit-daeExZWv.mjs +12 -0
- package/dist/packem_shared/auth-do-JzJM4sBK.mjs +1 -0
- package/dist/packem_shared/authAuditBeforeHook-DPRq6mbA.mjs +1 -0
- package/dist/packem_shared/authBackfillStatus-ZDUCk4U6.mjs +1 -0
- package/dist/packem_shared/authCanonicalEmailColumn-CfhnJ1Wp.mjs +1 -0
- package/dist/packem_shared/authCredentialColumns-CnsISHUl.mjs +1 -0
- package/dist/packem_shared/authDiscoveryPaths-BtKCs_3V.mjs +1 -0
- package/dist/packem_shared/authDoColumnAdditions-UwF3Rl41.mjs +1 -0
- package/dist/packem_shared/convertAuthDatesOnce-DE_O-bpx.mjs +1 -0
- package/dist/packem_shared/create-auth.d-B8S7aw9O.d.mts +153 -0
- package/dist/packem_shared/create-auth.d-B8S7aw9O.d.ts +153 -0
- package/dist/packem_shared/createAuth-DFkaeVge.mjs +1 -0
- package/dist/packem_shared/createDoAuthWiring-o3mfSSIf.mjs +1 -0
- package/dist/packem_shared/createLunoraAuthClient-wzZk9E0m.mjs +1 -0
- package/dist/packem_shared/createSignUpInvitation-miwkunlA.mjs +1 -0
- package/dist/packem_shared/effectiveCookieCache-JvL6i6YO.mjs +1 -0
- package/dist/packem_shared/emailGateDatabaseHooks-Dvyliwxx.mjs +1 -0
- package/dist/packem_shared/handleAuthRequest-Id9Vv_Tk.mjs +1 -0
- package/dist/packem_shared/identity-claims-hAvIl2wm.mjs +1 -0
- package/dist/packem_shared/invitation-email-backfill-DUwurNbV.mjs +1 -0
- package/dist/packem_shared/invite-only.d-CsBPLsY1.d.mts +126 -0
- package/dist/packem_shared/invite-only.d-JdPDmy_a.d.ts +126 -0
- package/dist/packem_shared/isDevEnvironment-yLbPngwn.mjs +1 -0
- package/dist/packem_shared/legacyIssuerCleanupStatements-DCL5uV55.mjs +1 -0
- package/dist/packem_shared/mcp-CK5XkDFp.mjs +1 -0
- package/dist/packem_shared/on-cloudflare-edge-Dx6gFjBO.mjs +1 -0
- package/dist/packem_shared/prepareAuthData-CP4M7zk1.mjs +1 -0
- package/dist/packem_shared/provision-DWGVCbQD.mjs +1 -0
- package/dist/packem_shared/quote-identifier-CGiYFBvY.mjs +1 -0
- package/dist/packem_shared/resolveSessionIdentity-EBhckRBW.mjs +1 -0
- package/dist/packem_shared/sessionPresets-DQQYAOER.mjs +1 -0
- package/dist/packem_shared/sql-store-CFeVqF0V.mjs +1 -0
- package/dist/packem_shared/uiConfig-B8pN6pks.mjs +1 -0
- package/dist/packem_shared/worker.d-CDnMrB5s.d.mts +912 -0
- package/dist/packem_shared/worker.d-CVuhZPM3.d.ts +912 -0
- package/dist/plugins-client.d.mts +251 -1
- package/dist/plugins-client.d.ts +251 -1
- package/dist/plugins-client.mjs +1 -2
- package/dist/plugins-enterprise-client.d.mts +13 -0
- package/dist/plugins-enterprise-client.d.ts +13 -0
- package/dist/plugins-enterprise-client.mjs +1 -0
- package/dist/plugins-enterprise.d.mts +1659 -0
- package/dist/plugins-enterprise.d.ts +1659 -0
- package/dist/plugins-enterprise.mjs +1 -0
- package/dist/plugins.d.mts +180 -2
- package/dist/plugins.d.ts +180 -2
- package/dist/plugins.mjs +1 -22
- package/dist/schema.d.mts +47 -39
- package/dist/schema.d.ts +47 -39
- package/dist/schema.mjs +1 -62
- package/dist/sql-store.d.mts +48 -29
- package/dist/sql-store.d.ts +48 -29
- package/dist/sql-store.mjs +1 -184
- package/dist/store.d.mts +65 -47
- package/dist/store.d.ts +65 -47
- package/dist/store.mjs +1 -183
- package/dist/turnstile-middleware.d.mts +73 -55
- package/dist/turnstile-middleware.d.ts +73 -55
- package/dist/turnstile-middleware.mjs +1 -34
- package/dist/turnstile.d.mts +42 -49
- package/dist/turnstile.d.ts +42 -49
- package/dist/turnstile.mjs +1 -54
- package/dist/worker.d.mts +9 -0
- package/dist/worker.d.ts +9 -0
- package/dist/worker.mjs +1 -0
- package/package.json +58 -7
- package/dist/packem_shared/DEFAULT_AUTH_BASE_PATH-DjcUWEQl.mjs +0 -11
- package/dist/packem_shared/LunoraAuthAdminError-D4L7n6gN.mjs +0 -510
- package/dist/packem_shared/compileMigrationsSql-B9bj-mJv.mjs +0 -29
- package/dist/packem_shared/create-auth.d-Mwhb4gSc.d.mts +0 -128
- package/dist/packem_shared/create-auth.d-Mwhb4gSc.d.ts +0 -128
- package/dist/packem_shared/createAuth-BVMMllTm.mjs +0 -87
- package/dist/packem_shared/sessionPresets-Dwwd74_J.mjs +0 -38
package/dist/index.d.ts
CHANGED
|
@@ -1,578 +1,657 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
export { c as
|
|
1
|
+
import { D as DoStorageLike } from "./packem_shared/adapter.d-BEvPbvSs.js";
|
|
2
|
+
export { type L as LunoraD1AdapterOptions, l as lunoraAuthAdapter, a as lunoraD1Adapter, b as lunoraDoAdapter } from "./packem_shared/adapter.d-BEvPbvSs.js";
|
|
3
|
+
import { D as DuplicateRow, B as BackfillExecutor } from "./packem_shared/worker.d-CVuhZPM3.js";
|
|
4
|
+
export { type A as AuthAccount, type a as AuthAdmin, type b as AuthAdminSession, type c as AuthAdminUser, type d as AuthApiKey, type e as AuthCapabilities, type f as AuthConfigInfo, type g as AuthDataPortLike, type h as AuthImportResult, type i as AuthInvitation, type j as AuthJurisdiction, type k as AuthJurisdictionMove, type l as AuthMember, type m as AuthMoveResult, type n as AuthMoveTableReport, type o as AuthNamespaceLike, type p as AuthOrgRole, type q as AuthOrganization, type r as AuthPage, type s as AuthPasskey, type t as AuthReplaceResult, type u as AuthSignUpInvitation, type v as AuthTeam, type w as AuthTeamMember, type x as AuthTimestamp, type y as AuthUserFieldSpec, type C as CanonicalEmailColumn, type z as CookieCache, type E as CreateAuthAdminOptions, type F as DoAuthWiring, type G as DoAuthWiringOptions, type I as ImpersonationResult, type L as ListUsersOptions, H as LunoraAuthAdminError, type S as SessionIdentity, J as authCanonicalEmailColumn, K as authCredentialColumns, M as authCredentialTableNames, N as authDiscoveryPaths, O as authDiscoveryPathsFor, P as authTableNames, Q as canonicalEmail, R as createAuthAdmin, T as createDoAuthWiring, U as createSqlAuthDataPort, V as effectiveCookieCache, W as handleAuthDiscoveryRequest, X as handleAuthRequest, Y as resolveSessionIdentity } from "./packem_shared/worker.d-CVuhZPM3.js";
|
|
5
|
+
import { AppendAuthAuditEntry, AppendAuthAuditOptions, AuthAuditEvent } from "./audit.js";
|
|
6
|
+
export { AUTH_AUDIT_TABLE, type AuthAuditEntry, type AuthAuditOutcome, type AuthAuditReader, type AuthAuditWriter, type ReadAuthAuditOptions, appendAuthAuditEntry, createAuthAuditReader, createAuthAuditWriter, ensureAuthAuditTable, readAuthAuditLog } from "./audit.js";
|
|
7
|
+
import { createAuthMiddleware } from 'better-auth/api';
|
|
8
|
+
import { SqlExecutor } from "./sql-store.js";
|
|
9
|
+
export { createSqlAuthStore, d1Executor } from "./sql-store.js";
|
|
10
|
+
import { a as LunoraAuthOptions } from "./packem_shared/create-auth.d-B8S7aw9O.js";
|
|
11
|
+
export { type L as LunoraAuth, c as createAuth, r as resolveAuthOptions } from "./packem_shared/create-auth.d-B8S7aw9O.js";
|
|
12
|
+
import { BetterAuthOptions } from 'better-auth';
|
|
13
|
+
import { EmailClassification, EmailGateConfig } from "./email-guard.js";
|
|
14
|
+
export { type EmailClass, type EmailGateMiddlewareOptions, assertEmailAllowed, classifyEmail, emailGateMiddleware, loadEmailDomainLists } from "./email-guard.js";
|
|
15
|
+
export { type I as InviteOnlyOptions, type a as IssuedSignUpInvitation, type S as SignUpInvitation, c as createSignUpInvitation, l as listSignUpInvitations, p as pruneSignUpInvitations, r as revokeSignUpInvitation } from "./packem_shared/invite-only.d-JdPDmy_a.js";
|
|
5
16
|
export { type LunoraAuthApiContext, LunoraAuthHeadersError, type WithAuthPluginsMiddleware, type WithAuthPluginsOptions, withAuthPlugins } from "./middleware.js";
|
|
6
17
|
export { default as authTables } from "./schema.js";
|
|
7
|
-
import { BetterAuthOptions } from 'better-auth';
|
|
8
|
-
export { type SqlExecutor, createSqlAuthStore, d1Executor } from "./sql-store.js";
|
|
9
18
|
export { type AuthQuery, type AuthRow, type AuthStore, type AuthWhereClause, createMemoryAuthStore, matchesWhere } from "./store.js";
|
|
10
19
|
export { type FetchLike, TURNSTILE_VERIFY_ENDPOINT, type TurnstileVerifyResult, type VerifyTurnstileOptions, verifyTurnstile } from "./turnstile.js";
|
|
11
20
|
export { type VerifyTurnstileMiddlewareOptions, verifyTurnstileMiddleware } from "./turnstile-middleware.js";
|
|
12
21
|
import 'better-auth/adapters';
|
|
22
|
+
import '@lunora/errors';
|
|
13
23
|
import '@lunora/server';
|
|
14
|
-
/**
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
name?: null | string;
|
|
37
|
-
role?: null | string;
|
|
38
|
-
updatedAt?: AuthTimestamp;
|
|
24
|
+
/** Configuration for {@link authAuditHook}. */
|
|
25
|
+
interface AuthAuditHookConfig extends AppendAuthAuditOptions {
|
|
26
|
+
/**
|
|
27
|
+
* Where to persist the trail — the same {@link SqlExecutor} seam better-auth's
|
|
28
|
+
* store rides (`d1Executor(env.DB)`), so events land in the auth D1 database.
|
|
29
|
+
*/
|
|
30
|
+
executor: SqlExecutor;
|
|
31
|
+
/**
|
|
32
|
+
* Optional export tap (pairs with SIEM forwarding): called with each redacted
|
|
33
|
+
* entry right after it is persisted, so a deployment can fan events out to an
|
|
34
|
+
* external sink. Rejections/throws are swallowed so forwarding can't break an
|
|
35
|
+
* auth request.
|
|
36
|
+
*/
|
|
37
|
+
onRecord?: (entry: AppendAuthAuditEntry) => Promise<void> | void;
|
|
38
|
+
/**
|
|
39
|
+
* When true, `x-forwarded-for` is trusted as a client-IP fallback when
|
|
40
|
+
* `cf-connecting-ip` is absent — only enable this behind a proxy you control,
|
|
41
|
+
* or the recorded IP is attacker-chosen. Defaults to `false`: off Cloudflare,
|
|
42
|
+
* with no trusted proxy configured, the audit record's `ip` is omitted rather
|
|
43
|
+
* than populated from a spoofable header.
|
|
44
|
+
*/
|
|
45
|
+
trustProxyHeaders?: boolean;
|
|
39
46
|
}
|
|
40
47
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
interface AuthInvitation {
|
|
86
|
-
[key: string]: unknown;
|
|
87
|
-
email?: null | string;
|
|
88
|
-
expiresAt?: AuthTimestamp;
|
|
89
|
-
id: string;
|
|
90
|
-
organizationId: string;
|
|
91
|
-
role?: null | string;
|
|
92
|
-
status?: null | string;
|
|
93
|
-
}
|
|
94
|
-
/** One team row (from the `organization` plugin with `teams.enabled`). */
|
|
95
|
-
interface AuthTeam {
|
|
96
|
-
[key: string]: unknown;
|
|
97
|
-
createdAt?: AuthTimestamp;
|
|
98
|
-
id: string;
|
|
99
|
-
name?: null | string;
|
|
100
|
-
organizationId: string;
|
|
101
|
-
}
|
|
102
|
-
/** One team-membership row (teams). */
|
|
103
|
-
interface AuthTeamMember {
|
|
104
|
-
[key: string]: unknown;
|
|
105
|
-
createdAt?: AuthTimestamp;
|
|
106
|
-
id: string;
|
|
107
|
-
teamId: string;
|
|
108
|
-
userId: string;
|
|
48
|
+
* Structural view of the fields we read off better-auth's after-hook context —
|
|
49
|
+
* kept loose to avoid coupling to internal types.
|
|
50
|
+
*
|
|
51
|
+
* `body` is the parsed request body better-auth's middleware context exposes
|
|
52
|
+
* as `ctx.body` — pinned present and populated (e.g. `.email`) in the after-hook
|
|
53
|
+
* by `__tests__/audit-hooks.behaviour.test.ts` (plan 280 S0).
|
|
54
|
+
*/
|
|
55
|
+
interface AuditHookContext {
|
|
56
|
+
body?: Record<string, unknown>;
|
|
57
|
+
context?: {
|
|
58
|
+
newSession?: {
|
|
59
|
+
session?: {
|
|
60
|
+
activeOrganizationId?: string;
|
|
61
|
+
impersonatedBy?: string;
|
|
62
|
+
userId?: string;
|
|
63
|
+
};
|
|
64
|
+
user?: {
|
|
65
|
+
email?: string;
|
|
66
|
+
id?: string;
|
|
67
|
+
};
|
|
68
|
+
} | null;
|
|
69
|
+
/** Cookies and headers the endpoint set on its way to the response, which the response is built from. */
|
|
70
|
+
responseHeaders?: Headers;
|
|
71
|
+
returned?: unknown;
|
|
72
|
+
secret?: string;
|
|
73
|
+
session?: {
|
|
74
|
+
session?: {
|
|
75
|
+
activeOrganizationId?: string;
|
|
76
|
+
impersonatedBy?: string;
|
|
77
|
+
userId?: string;
|
|
78
|
+
};
|
|
79
|
+
user?: {
|
|
80
|
+
email?: string;
|
|
81
|
+
id?: string;
|
|
82
|
+
};
|
|
83
|
+
} | null;
|
|
84
|
+
};
|
|
85
|
+
headers?: Headers;
|
|
86
|
+
/** The HTTP verb. better-auth sets it for a request over `handler`, not for a direct `auth.api.*` call. */
|
|
87
|
+
method?: string;
|
|
88
|
+
/** Path parameters, e.g. `{ userId }`. Can carry secrets, so only allow-listed keys are ever copied. */
|
|
89
|
+
params?: Record<string, unknown>;
|
|
90
|
+
path?: string;
|
|
91
|
+
request?: Request;
|
|
109
92
|
}
|
|
110
93
|
/**
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
94
|
+
* Map a better-auth endpoint path to the security event it represents, or
|
|
95
|
+
* `undefined` for endpoints not worth auditing (session reads, config, …). Match
|
|
96
|
+
* is by suffix so a caller `basePath` prefix (`/api/auth`) never affects it.
|
|
97
|
+
*
|
|
98
|
+
* Sign-in is split by what the endpoint actually DOES (plan 280 §4):
|
|
99
|
+
*
|
|
100
|
+
* - `/sign-in/social`, `/sign-in/magic-link` and `@better-auth/sso`'s
|
|
101
|
+
* `/sign-in/sso` only DISPATCH — the first mints a provider redirect URL, the
|
|
102
|
+
* second sends an email, the third answers `{ url, redirect: true }` pointing
|
|
103
|
+
* at the identity provider's authorization endpoint. Nobody is authenticated
|
|
104
|
+
* yet, so these are `sign-in-initiated`, not `sign-in`. Without the `sso`
|
|
105
|
+
* branch that path fell through to the `/sign-in/` substring below and every
|
|
106
|
+
* SSO redirect mint was recorded as a completed, successful `sign-in` with no
|
|
107
|
+
* actor — in exactly the flow where the "who authenticated" trail matters
|
|
108
|
+
* most.
|
|
109
|
+
* - `/callback/:id` (social + generic-oauth), `/magic-link/verify`,
|
|
110
|
+
* `@better-auth/sso`'s `/sso/saml2/sp/acs/:providerId`, and every
|
|
111
|
+
* `/two-factor/verify-*` (`verify-totp` / `verify-otp` / `verify-backup-code`
|
|
112
|
+
* — all three complete a challenged sign-in the same way) are where a
|
|
113
|
+
* session actually gets issued, so they join credential sign-ins
|
|
114
|
+
* (`/sign-in/email`, `/sign-in/username`, `/sign-in/phone-number`, …) as
|
|
115
|
+
* plain `sign-in`. They were NOT recorded at all before this change.
|
|
116
|
+
*
|
|
117
|
+
* The SAML assertion consumer service needs its own branch because it is the
|
|
118
|
+
* one completion that carries no `/callback/` segment: `processSAMLResponse`
|
|
119
|
+
* validates the assertion, resolves the user and calls `setSessionCookie`, all
|
|
120
|
+
* under `/sso/saml2/sp/acs/:providerId`. Matching neither that substring nor
|
|
121
|
+
* any other branch, it classified as `undefined` — the endpoint that issues
|
|
122
|
+
* every SAML session left no audit row at all.
|
|
123
|
+
*
|
|
124
|
+
* SAML sign-OUT has the mirror-image problem, and two endpoints rather than
|
|
125
|
+
* one. Neither ends in `/sign-out`, and both terminate the local session before
|
|
126
|
+
* redirecting, so both are `sign-out` rather than an initiated event:
|
|
127
|
+
*
|
|
128
|
+
* - `/sso/saml2/logout/:providerId` — SP-initiated. Deletes the SAML session
|
|
129
|
+
* keys, calls `deleteSession` on the current session token and
|
|
130
|
+
* `deleteSessionCookie`, then redirects to the IdP's logout URL.
|
|
131
|
+
* - `/sso/saml2/sp/slo/:providerId` — the SP's single-logout receiver, for the
|
|
132
|
+
* IdP-initiated direction and for the response leg of an SP-initiated one.
|
|
133
|
+
* Both `handleLogoutRequest` and `handleLogoutResponse` call `deleteSession`
|
|
134
|
+
* and `deleteSessionCookie` the same way.
|
|
135
|
+
*
|
|
136
|
+
* Recording the SAML sign-in while leaving these silent is worse than either
|
|
137
|
+
* gap alone: the trail would show a session opening and never closing, so a
|
|
138
|
+
* reader cannot tell "still signed in" from "we stopped watching".
|
|
139
|
+
*
|
|
140
|
+
* There is no dedicated `/oauth2/callback/*` branch because the generic
|
|
141
|
+
* `/callback/` check above already covers it, and covering it is CORRECT: an
|
|
142
|
+
* OAuth callback is a completed sign-in whatever path prefix it arrives on. The
|
|
143
|
+
* same substring also catches `@better-auth/sso`'s `/sso/callback/:providerId`,
|
|
144
|
+
* which is where an SSO sign-in actually completes — `sso` is re-exported from
|
|
145
|
+
* `@lunora/auth/plugins/enterprise`, so that path is live, not hypothetical.
|
|
146
|
+
*
|
|
147
|
+
* Checked against the installed `better-auth` and `@better-auth/*` dist for
|
|
148
|
+
* 1.7.3: generic-oauth registers NO endpoints of its own (there is no
|
|
149
|
+
* `/sign-in/oauth2`) — it registers providers used through the core
|
|
150
|
+
* `/sign-in/social` and `/callback/:id`, and the one dist hit for a literal
|
|
151
|
+
* `/oauth2/callback/` is inside `better-auth/plugins/oauth-popup`, which
|
|
152
|
+
* `plugins.ts` does not re-export — so today the branch fires for the core
|
|
153
|
+
* callback, and stays correct if the other becomes reachable.
|
|
154
|
+
*
|
|
155
|
+
* The plugin endpoints in {@link SUFFIX_EVENTS} are pinned against the installed
|
|
156
|
+
* better-auth by `__tests__/audit-endpoint-coverage.test.ts`, which fails on any
|
|
157
|
+
* endpoint it does not classify, so an upgrade cannot add one silently.
|
|
158
|
+
*
|
|
159
|
+
* The method-keyed rows are checked first, then the exact suffix table {@link SUFFIX_EVENTS},
|
|
160
|
+
* then the substring branches.
|
|
161
|
+
*
|
|
162
|
+
* `method` only matters for {@link METHOD_EVENTS}, the paths that serve a read and a
|
|
163
|
+
* write under one template (SCIM users, OAuth resources). Pass it whenever the verb
|
|
164
|
+
* is known; a direct server call has none, and those paths are left unclassified.
|
|
165
|
+
*
|
|
166
|
+
* `grantType` is the request's `grant_type`. The OAuth token endpoint serves both the
|
|
167
|
+
* initial grant and a refresh, and only the refresh is a token refresh.
|
|
168
|
+
*/
|
|
169
|
+
declare const eventForPath: (path: string, method?: string, grantType?: string) => AuthAuditEvent | undefined;
|
|
137
170
|
/**
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
171
|
+
* Build the entry a given after-hook context should record, or `undefined` when
|
|
172
|
+
* the path is not an audited security event. Exported for direct unit testing of
|
|
173
|
+
* the classification/extraction without spinning up better-auth.
|
|
174
|
+
*
|
|
175
|
+
* Does NOT attempt to distinguish a 2FA-challenged credential sign-in from a
|
|
176
|
+
* fully successful one (a `sign-in-challenged` event, as an earlier design for
|
|
177
|
+
* this change proposed) — pinned in `__tests__/audit-hooks.behaviour.test.ts`
|
|
178
|
+
* (plan 280 S0): better-auth runs the APP's own `hooks.after` BEFORE the
|
|
179
|
+
* `twoFactor` plugin's own after-hook that rewrites the response to
|
|
180
|
+
* `{ twoFactorRedirect: true }` and nulls `ctx.context.newSession`. By the time
|
|
181
|
+
* THIS hook runs, `context.returned`/`context.newSession` still reflect the
|
|
182
|
+
* pre-interception, fully-successful sign-in — there is nothing here to detect
|
|
183
|
+
* the challenge from. Distinguishing it would need a different seam (e.g. a
|
|
184
|
+
* plugin-ordered-after-`twoFactor` hook, or reading `twoFactor`'s own
|
|
185
|
+
* database state) and is left to a follow-up.
|
|
186
|
+
*/
|
|
187
|
+
declare const buildAuditEntry: (context: AuditHookContext, { now, trustProxyHeaders }?: {
|
|
188
|
+
now?: number;
|
|
189
|
+
trustProxyHeaders?: boolean;
|
|
190
|
+
}) => AppendAuthAuditEntry | undefined;
|
|
156
191
|
/**
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
161
|
-
*
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
192
|
+
* Create the better-auth `hooks.after` middleware that records the auth/security
|
|
193
|
+
* audit trail. Assign it to `hooks.after` (or compose via {@link withAuthAudit}).
|
|
194
|
+
*
|
|
195
|
+
* ```ts
|
|
196
|
+
* const auth = createAuth({
|
|
197
|
+
* secret: env.AUTH_SECRET,
|
|
198
|
+
* database: lunoraD1Adapter(env.DB),
|
|
199
|
+
* hooks: { after: authAuditHook({ executor: d1Executor(env.DB), retention: 100_000 }) },
|
|
200
|
+
* });
|
|
201
|
+
* ```
|
|
202
|
+
*
|
|
203
|
+
* ## Behaviour change (plan 280) — `onRecord`/SIEM consumers keyed on `event` strings, read this
|
|
204
|
+
*
|
|
205
|
+
* | Endpoint | Before | After |
|
|
206
|
+
* | -------------------------------------------------- | ------------------- | --------------------- |
|
|
207
|
+
* | `/sign-in/email` (and other credential sign-ins) | `sign-in` | `sign-in` (unchanged) |
|
|
208
|
+
* | `/sign-in/social` | `sign-in` | `sign-in-initiated` |
|
|
209
|
+
* | `/sign-in/magic-link` | `sign-in` | `sign-in-initiated` |
|
|
210
|
+
* | `/callback/:id` (social + generic-oauth) | _(not recorded)_ | `sign-in` |
|
|
211
|
+
* | `/magic-link/verify` | _(not recorded)_ | `sign-in` |
|
|
212
|
+
* | `/two-factor/verify-totp` / `-otp` / `-backup-code`| _(not recorded)_ | `sign-in` |
|
|
213
|
+
* | `/device/token` | `token-refresh` | `sign-in` |
|
|
214
|
+
* | `/request-password-reset`, `/forget-password`, `…/forget-password/email-otp`, `…/request-password-reset` | `password-reset` | `password-reset-request` |
|
|
215
|
+
* | Any event in a session that is impersonating another user | actor is the impersonated user, with `actorEmail` | actor is the administrator (`impersonatedBy`), with no `actorEmail`; the impersonated user is `detail.targetUserId` |
|
|
216
|
+
*
|
|
217
|
+
* A caller matching on `event === "sign-in"` now sees FEWER events for
|
|
218
|
+
* `/sign-in/social` and `/sign-in/magic-link` (they never actually authenticated
|
|
219
|
+
* anyone) and MORE events for the four previously-unrecorded completion
|
|
220
|
+
* endpoints — the net effect is a more truthful count, not a strictly larger or
|
|
221
|
+
* smaller one. `sign-in-initiated` is a new event name (open `AuthAuditEvent`
|
|
222
|
+
* union, so no wire/type break, but SIEM rules enumerating event names should
|
|
223
|
+
* add it). A failed sign-in now also carries `targetEmail` (a keyed digest of the
|
|
224
|
+
* attempted address/username) when the request body supplied one — see
|
|
225
|
+
* {@link AppendAuthAuditEntry.targetEmail} — so credential-stuffing attempts can
|
|
226
|
+
* be grouped by target even though they never produce an `actorEmail`.
|
|
227
|
+
*
|
|
228
|
+
* NOT changed: `/sign-in/email` under an active 2FA challenge still records
|
|
229
|
+
* plain `sign-in` / `success` (not a distinct `sign-in-challenged` event) — see
|
|
230
|
+
* {@link buildAuditEntry}'s docblock for why that distinction turned out not to
|
|
231
|
+
* be buildable from this hook.
|
|
232
|
+
*/
|
|
233
|
+
declare const authAuditHook: (config: AuthAuditHookConfig) => ReturnType<typeof createAuthMiddleware>;
|
|
173
234
|
/**
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
* {@link
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
};
|
|
193
|
-
/** Enabled better-auth plugin ids, sorted. */
|
|
194
|
-
plugins: string[];
|
|
195
|
-
/** Rate-limit policy (window is in seconds). */
|
|
196
|
-
rateLimit: {
|
|
197
|
-
enabled: boolean;
|
|
198
|
-
max?: number;
|
|
199
|
-
window?: number;
|
|
200
|
-
};
|
|
201
|
-
/** Session policy (all durations in seconds). */
|
|
202
|
-
session: {
|
|
203
|
-
cookieCache?: boolean;
|
|
204
|
-
expiresIn?: number;
|
|
205
|
-
freshAge?: number;
|
|
206
|
-
updateAge?: number;
|
|
235
|
+
* Create the better-auth `hooks.before` middleware that reads what an audited endpoint
|
|
236
|
+
* destroys: the owner of the session `/admin/revoke-user-session` deletes, so the
|
|
237
|
+
* {@link authAuditHook} row can name the user as `detail.targetUserId`. Only the user id is
|
|
238
|
+
* kept, never the session token. Install it as `hooks.before` next to `authAuditHook`, or let
|
|
239
|
+
* {@link withAuthAudit} install both.
|
|
240
|
+
*/
|
|
241
|
+
declare const authAuditBeforeHook: () => ReturnType<typeof createAuthMiddleware>;
|
|
242
|
+
/**
|
|
243
|
+
* Merge the audit middleware into a better-auth options object: `hooks.before`
|
|
244
|
+
* reads what a revoke is about to delete, then `hooks.after` records the row.
|
|
245
|
+
* Each composes with the hook the caller already set: the audit's before hook
|
|
246
|
+
* runs ahead of the caller's, which may end the request, and the caller's after
|
|
247
|
+
* hook runs ahead of the audit record. Returns a new options object.
|
|
248
|
+
*/
|
|
249
|
+
declare const withAuthAudit: <Options extends {
|
|
250
|
+
hooks?: {
|
|
251
|
+
after?: unknown;
|
|
252
|
+
before?: unknown;
|
|
207
253
|
};
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
254
|
+
}>(options: Options, config: AuthAuditHookConfig) => Options;
|
|
255
|
+
/**
|
|
256
|
+
* The part of an app's Lunora schema `prepareAuthData` reads: each table's columns. A
|
|
257
|
+
* `defineSchema(...)` result fits.
|
|
258
|
+
*/
|
|
259
|
+
interface AuthDataSchema {
|
|
260
|
+
readonly tables: Readonly<Record<string, {
|
|
261
|
+
readonly shape: Readonly<Record<string, unknown>>;
|
|
262
|
+
}>>;
|
|
212
263
|
}
|
|
213
|
-
/**
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
264
|
+
/** What {@link prepareAuthData} may do before the data steps, and which of them it runs. */
|
|
265
|
+
interface PrepareAuthDataOptions {
|
|
266
|
+
/**
|
|
267
|
+
* Fill `user.emailCanonical` on rows written before the column existed. Default `true`. Set
|
|
268
|
+
* `false` when the app runs its own backfill, for example one that stops for an operator while
|
|
269
|
+
* two accounts share a canonical address.
|
|
270
|
+
*/
|
|
271
|
+
canonicalEmailBackfill?: boolean;
|
|
272
|
+
/** Rewrite `signUpInvitation.email` to its canonical form. Default `true`. */
|
|
273
|
+
invitationEmailBackfill?: boolean;
|
|
274
|
+
/**
|
|
275
|
+
* Create the auth tables if they are missing, before anything reads them: for an app whose auth
|
|
276
|
+
* tables are `.global()` tables in its Lunora schema, `(executor) => runD1GlobalTableMigrations(executor, schema)`.
|
|
277
|
+
* Shared with `lunoraD1Adapter(db, { provision })` over the same binding, so it runs once per isolate across both.
|
|
278
|
+
*/
|
|
279
|
+
provision?: (executor: SqlExecutor) => Promise<void>;
|
|
280
|
+
/**
|
|
281
|
+
* The app's Lunora schema, the one that declares the auth tables. The `account.issuer` cleanup
|
|
282
|
+
* reads the account table's columns from it: it drops the column only when the schema declares
|
|
283
|
+
* the table without it. Without a schema the column is never dropped, only reported.
|
|
284
|
+
*/
|
|
285
|
+
schema?: AuthDataSchema;
|
|
230
286
|
}
|
|
231
|
-
/**
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
287
|
+
/**
|
|
288
|
+
* Lunora's data steps for the auth tables, without better-auth's schema migrator: the
|
|
289
|
+
* `account.issuer` cleanup, the canonical-email and invitation-email backfills, and the
|
|
290
|
+
* ISO-date → epoch-ms conversion that keeps converting for a day after the first clean run
|
|
291
|
+
* (so ISO dates written by isolates still on an older version during a rollout are caught).
|
|
292
|
+
*
|
|
293
|
+
* **Which to call.** `ensureMigrated` runs better-auth's migrator and then exactly these steps;
|
|
294
|
+
* it needs a `database` the migrator can drive (a raw D1 binding) and throws
|
|
295
|
+
* `AUTH_MIGRATOR_UNSUPPORTED` for an adapter. When the auth tables come from somewhere else —
|
|
296
|
+
* `authTables(options)` declared `.global()` in the app's Lunora schema, served through
|
|
297
|
+
* `lunoraD1Adapter` from the app's own Worker entry — call this instead, with the executor over
|
|
298
|
+
* the same D1 binding, before building the auth instance (so a schema verdict the adapter takes
|
|
299
|
+
* sees the cleaned-up `account` table).
|
|
300
|
+
*
|
|
301
|
+
* **What each step touches.**
|
|
302
|
+
* - `account.issuer` cleanup: reads the account table's columns and indexes. Destructive: drops
|
|
303
|
+
* the column and its indexes, but only when `settings.schema` declares the account table
|
|
304
|
+
* without `issuer`. With no schema it only logs.
|
|
305
|
+
* - Canonical-email backfill (`canonicalEmailBackfill: false` skips it): reads rows whose
|
|
306
|
+
* `user.emailCanonical` is `NULL` and fills them. Leaves an address another account holds
|
|
307
|
+
* `NULL` and logs it by id with its holder; `authBackfillStatus` reads the same. Its position is kept in
|
|
308
|
+
* `__lunora_auth_backfill__`.
|
|
309
|
+
* - Invitation-email backfill (`invitationEmailBackfill: false` skips it): rewrites
|
|
310
|
+
* `signUpInvitation.email` to its canonical form, unless another invitation holds that form.
|
|
311
|
+
* - Date conversion: rewrites ISO-string dates in the auth tables to epoch ms. Always runs.
|
|
312
|
+
*
|
|
313
|
+
* Never rejects for a data step: each logs and resumes on a later call or cold start, like
|
|
314
|
+
* `ensureMigrated`. Memoised per `options` object and executor for the isolate (`d1Executor` returns
|
|
315
|
+
* one executor per binding): the cleanup and conversion run
|
|
316
|
+
* once, the backfill until it reaches the end of its tables. Pass the same long-lived options
|
|
317
|
+
* object and the same settings on every call; a fresh options object per request repeats the work.
|
|
318
|
+
*
|
|
319
|
+
* ```ts
|
|
320
|
+
* await prepareAuthData(d1Executor(env.DB), authOptions, { provision: (exec) => runD1GlobalTableMigrations(exec, schema), schema });
|
|
321
|
+
* ```
|
|
322
|
+
*/
|
|
323
|
+
declare const prepareAuthData: (executor: SqlExecutor, options: LunoraAuthOptions, settings?: PrepareAuthDataOptions) => Promise<void>;
|
|
324
|
+
/**
|
|
325
|
+
* The Durable Object state slice this class needs — structural so unit tests can
|
|
326
|
+
* pass a double without depending on the workers runtime.
|
|
327
|
+
*/
|
|
328
|
+
interface AuthDoState {
|
|
329
|
+
storage: DoStorageLike;
|
|
237
330
|
}
|
|
331
|
+
/** Path the worker calls to resolve a request's identity. Not part of `/api/auth/*`. */
|
|
332
|
+
declare const RESOLVE_SESSION_PATH = "/__lunora/auth/session";
|
|
238
333
|
/**
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
}) => Promise<AuthAdminUser>;
|
|
264
|
-
cancelInvitation: (input: {
|
|
265
|
-
invitationId: string;
|
|
266
|
-
}) => Promise<void>;
|
|
267
|
-
capabilities: () => Promise<AuthCapabilities>;
|
|
268
|
-
/** Rich, read-only description of the auth configuration (plugins, fields, session policy, …). */
|
|
269
|
-
config: () => Promise<AuthConfigInfo>;
|
|
270
|
-
/** Create an organization; optionally seed an `owner` member for `ownerId`. */
|
|
271
|
-
createOrganization: (input: {
|
|
272
|
-
logo?: string;
|
|
273
|
-
metadata?: Record<string, unknown>;
|
|
274
|
-
name: string;
|
|
275
|
-
ownerId?: string;
|
|
276
|
-
slug?: string;
|
|
277
|
-
}) => Promise<AuthOrganization>;
|
|
278
|
-
/** Create a custom org role with a permission grant (a `resource → actions[]` map). */
|
|
279
|
-
createOrgRole: (input: {
|
|
280
|
-
organizationId: string;
|
|
281
|
-
permission: Record<string, string[]>;
|
|
282
|
-
role: string;
|
|
283
|
-
}) => Promise<AuthOrgRole>;
|
|
284
|
-
/** Create a team under an organization. */
|
|
285
|
-
createTeam: (input: {
|
|
286
|
-
name: string;
|
|
287
|
-
organizationId: string;
|
|
288
|
-
}) => Promise<AuthTeam>;
|
|
289
|
-
createUser: (input: {
|
|
290
|
-
data?: Record<string, unknown>;
|
|
291
|
-
email: string;
|
|
292
|
-
name: string;
|
|
293
|
-
password?: string;
|
|
294
|
-
role?: string | string[];
|
|
295
|
-
}) => Promise<AuthAdminUser>;
|
|
296
|
-
/** Delete an organization and cascade-delete its members, invitations, teams, and custom roles. */
|
|
297
|
-
deleteOrganization: (input: {
|
|
298
|
-
organizationId: string;
|
|
299
|
-
}) => Promise<void>;
|
|
300
|
-
/** Delete a custom org role. */
|
|
301
|
-
deleteOrgRole: (input: {
|
|
302
|
-
roleId: string;
|
|
303
|
-
}) => Promise<void>;
|
|
304
|
-
deletePasskey: (input: {
|
|
305
|
-
passkeyId: string;
|
|
306
|
-
}) => Promise<void>;
|
|
307
|
-
disableTwoFactor: (input: {
|
|
308
|
-
userId: string;
|
|
309
|
-
}) => Promise<void>;
|
|
310
|
-
impersonateUser: (input: {
|
|
311
|
-
userId: string;
|
|
312
|
-
}) => Promise<ImpersonationResult>;
|
|
313
|
-
/** Create a pending email invitation to an org (no acceptance side effects). */
|
|
314
|
-
inviteMember: (input: {
|
|
315
|
-
email: string;
|
|
316
|
-
inviterId?: string;
|
|
317
|
-
organizationId: string;
|
|
318
|
-
role?: string;
|
|
319
|
-
}) => Promise<AuthInvitation>;
|
|
320
|
-
listAccounts: (input: {
|
|
321
|
-
userId: string;
|
|
322
|
-
}) => Promise<AuthAccount[]>;
|
|
323
|
-
listInvitations: (options: {
|
|
324
|
-
limit?: number;
|
|
325
|
-
offset?: number;
|
|
326
|
-
organizationId: string;
|
|
327
|
-
}) => Promise<AuthPage<AuthInvitation>>;
|
|
328
|
-
listMembers: (options: {
|
|
329
|
-
limit?: number;
|
|
330
|
-
offset?: number;
|
|
331
|
-
organizationId: string;
|
|
332
|
-
}) => Promise<AuthPage<AuthMember>>;
|
|
333
|
-
listOrganizations: (options: {
|
|
334
|
-
limit?: number;
|
|
335
|
-
offset?: number;
|
|
336
|
-
}) => Promise<AuthPage<AuthOrganization>>;
|
|
337
|
-
/** List an org's custom roles. */
|
|
338
|
-
listOrgRoles: (options: {
|
|
339
|
-
limit?: number;
|
|
340
|
-
offset?: number;
|
|
341
|
-
organizationId: string;
|
|
342
|
-
}) => Promise<AuthPage<AuthOrgRole>>;
|
|
343
|
-
listPasskeys: (input: {
|
|
344
|
-
userId: string;
|
|
345
|
-
}) => Promise<AuthPasskey[]>;
|
|
346
|
-
listSessions: (options: {
|
|
347
|
-
limit?: number;
|
|
348
|
-
offset?: number;
|
|
349
|
-
userId?: string;
|
|
350
|
-
}) => Promise<AuthPage<AuthAdminSession>>;
|
|
351
|
-
/** List a team's members. */
|
|
352
|
-
listTeamMembers: (options: {
|
|
353
|
-
limit?: number;
|
|
354
|
-
offset?: number;
|
|
355
|
-
teamId: string;
|
|
356
|
-
}) => Promise<AuthPage<AuthTeamMember>>;
|
|
357
|
-
/** List an org's teams. */
|
|
358
|
-
listTeams: (options: {
|
|
359
|
-
limit?: number;
|
|
360
|
-
offset?: number;
|
|
361
|
-
organizationId: string;
|
|
362
|
-
}) => Promise<AuthPage<AuthTeam>>;
|
|
363
|
-
listUsers: (options: ListUsersOptions) => Promise<AuthPage<AuthAdminUser>>;
|
|
364
|
-
removeMember: (input: {
|
|
365
|
-
memberId: string;
|
|
366
|
-
}) => Promise<void>;
|
|
367
|
-
/** Delete a team and its memberships. */
|
|
368
|
-
removeTeam: (input: {
|
|
369
|
-
teamId: string;
|
|
370
|
-
}) => Promise<void>;
|
|
371
|
-
/** Remove a member from a team. */
|
|
372
|
-
removeTeamMember: (input: {
|
|
373
|
-
teamMemberId: string;
|
|
374
|
-
}) => Promise<void>;
|
|
375
|
-
removeUser: (input: {
|
|
376
|
-
userId: string;
|
|
377
|
-
}) => Promise<void>;
|
|
378
|
-
revokeUserSession: (input: {
|
|
379
|
-
sessionId: string;
|
|
380
|
-
}) => Promise<void>;
|
|
381
|
-
revokeUserSessions: (input: {
|
|
382
|
-
userId: string;
|
|
383
|
-
}) => Promise<void>;
|
|
384
|
-
setRole: (input: {
|
|
385
|
-
role: string | string[];
|
|
386
|
-
userId: string;
|
|
387
|
-
}) => Promise<AuthAdminUser>;
|
|
388
|
-
setUserPassword: (input: {
|
|
389
|
-
newPassword: string;
|
|
390
|
-
userId: string;
|
|
391
|
-
}) => Promise<void>;
|
|
392
|
-
unbanUser: (input: {
|
|
393
|
-
userId: string;
|
|
394
|
-
}) => Promise<AuthAdminUser>;
|
|
395
|
-
unlinkAccount: (input: {
|
|
396
|
-
accountId: string;
|
|
397
|
-
userId: string;
|
|
398
|
-
}) => Promise<void>;
|
|
399
|
-
/** Change a member's role. */
|
|
400
|
-
updateMemberRole: (input: {
|
|
401
|
-
memberId: string;
|
|
402
|
-
role: string | string[];
|
|
403
|
-
}) => Promise<AuthMember>;
|
|
404
|
-
/** Update an organization's name/slug/logo/metadata. */
|
|
405
|
-
updateOrganization: (input: {
|
|
406
|
-
logo?: string;
|
|
407
|
-
metadata?: Record<string, unknown>;
|
|
408
|
-
name?: string;
|
|
409
|
-
organizationId: string;
|
|
410
|
-
slug?: string;
|
|
411
|
-
}) => Promise<AuthOrganization>;
|
|
412
|
-
/** Replace a custom org role's permission grant. */
|
|
413
|
-
updateOrgRole: (input: {
|
|
414
|
-
permission: Record<string, string[]>;
|
|
415
|
-
roleId: string;
|
|
416
|
-
}) => Promise<AuthOrgRole>;
|
|
417
|
-
/** Rename a team. */
|
|
418
|
-
updateTeam: (input: {
|
|
419
|
-
name: string;
|
|
420
|
-
teamId: string;
|
|
421
|
-
}) => Promise<AuthTeam>;
|
|
422
|
-
updateUser: (input: {
|
|
423
|
-
data: Record<string, unknown>;
|
|
424
|
-
userId: string;
|
|
425
|
-
}) => Promise<AuthAdminUser>;
|
|
334
|
+
* Path the worker calls to read the audit log. Also not part of `/api/auth/*`.
|
|
335
|
+
*
|
|
336
|
+
* The audit table lives in this object like every other auth table, so the worker
|
|
337
|
+
* cannot query it directly — same constraint as the session route, same shared secret.
|
|
338
|
+
*/
|
|
339
|
+
declare const READ_AUDIT_PATH = "/__lunora/auth/audit";
|
|
340
|
+
/** Header carrying the shared secret that authenticates the calling worker. */
|
|
341
|
+
declare const INTERNAL_SECRET_HEADER = "x-lunora-auth-do-secret";
|
|
342
|
+
/**
|
|
343
|
+
* Options for the auth DO, beyond the better-auth options themselves.
|
|
344
|
+
*/
|
|
345
|
+
interface AuthDoOptions {
|
|
346
|
+
/**
|
|
347
|
+
* Shared secret authenticating the worker on {@link RESOLVE_SESSION_PATH}.
|
|
348
|
+
*
|
|
349
|
+
* The DO binding is reachable from any worker bound to the namespace, so the
|
|
350
|
+
* binding alone is not an authorization boundary — same reasoning as
|
|
351
|
+
* `SessionDO`'s `SESSION_DO_SECRET`. When this is unset the internal route is
|
|
352
|
+
* refused outright rather than served unauthenticated: a missing secret is a
|
|
353
|
+
* misconfiguration, and answering identity questions to anyone is the one
|
|
354
|
+
* failure mode worth being loud about. `/api/auth/*` is unaffected — those
|
|
355
|
+
* routes carry their own credentials.
|
|
356
|
+
*/
|
|
357
|
+
internalSecret?: string;
|
|
426
358
|
}
|
|
427
|
-
/**
|
|
428
|
-
|
|
359
|
+
/**
|
|
360
|
+
* Base class for an app's auth Durable Object. Subclass it (or let codegen emit the
|
|
361
|
+
* subclass) and register the subclass in `wrangler.jsonc`.
|
|
362
|
+
*
|
|
363
|
+
* ```ts
|
|
364
|
+
* export class AuthDO extends LunoraAuthDO {
|
|
365
|
+
* public constructor(state: DurableObjectState, env: Env) {
|
|
366
|
+
* super(state, () => ({ secret: env.AUTH_SECRET, plugins: [scim({ … })] }), {
|
|
367
|
+
* internalSecret: env.AUTH_DO_SECRET,
|
|
368
|
+
* });
|
|
369
|
+
* }
|
|
370
|
+
* }
|
|
371
|
+
* ```
|
|
372
|
+
*/
|
|
373
|
+
declare class LunoraAuthDO {
|
|
374
|
+
#private;
|
|
429
375
|
/**
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
*/
|
|
436
|
-
features?: Partial<AuthCapabilities>;
|
|
376
|
+
* @param state The Durable Object state — its `storage` becomes better-auth's database.
|
|
377
|
+
* @param optionsFactory Builds the better-auth options. Called once, lazily, on the first request.
|
|
378
|
+
* @param options Auth-DO specific options (base path, internal secret).
|
|
379
|
+
*/
|
|
380
|
+
constructor(state: AuthDoState, optionsFactory: () => LunoraAuthOptions, options?: AuthDoOptions);
|
|
437
381
|
/**
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
382
|
+
* Serve an auth request. Routes under `/api/auth` go to better-auth, and so do
|
|
383
|
+
* the OAuth discovery documents its options configure (`./discovery`); the
|
|
384
|
+
* internal session route is handled here; anything else is a 404.
|
|
385
|
+
*
|
|
386
|
+
* The base path is not configurable. The worker half only ever forwards
|
|
387
|
+
* `/api/auth/*` (`createDoAuthWiring`, which codegen calls with no base path),
|
|
388
|
+
* so a second knob here could only ever disagree with it.
|
|
389
|
+
*/
|
|
390
|
+
fetch(request: Request): Promise<Response>;
|
|
391
|
+
}
|
|
392
|
+
/** Where the canonical-email backfill stands, read from the database rather than from a past run. */
|
|
393
|
+
interface CanonicalEmailBackfillStatus {
|
|
443
394
|
/**
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
395
|
+
* Unfilled rows whose canonical value another account already holds: the backfill will never fill
|
|
396
|
+
* them, and only an operator can say which account keeps the address. At most
|
|
397
|
+
* {@link MAX_REPORTED_DUPLICATES}, taken from the first unfilled rows; see `truncated`.
|
|
398
|
+
*/
|
|
399
|
+
duplicates: DuplicateRow[];
|
|
400
|
+
/** A pass stopped part-way and saved its position; the next `prepareAuthData` / `ensureMigrated` call resumes it. */
|
|
401
|
+
inProgress: boolean;
|
|
402
|
+
/** Whether more unfilled rows exist than were checked for `duplicates`. */
|
|
403
|
+
truncated: boolean;
|
|
404
|
+
/** Rows whose `emailCanonical` is still `NULL`: duplicates, and rows a pass has not reached yet. */
|
|
405
|
+
unfilled: number;
|
|
406
|
+
}
|
|
407
|
+
/** Where each of Lunora's auth backfills stands; a key is absent when its table is not configured. */
|
|
408
|
+
interface AuthBackfillStatus {
|
|
409
|
+
canonicalEmail?: CanonicalEmailBackfillStatus;
|
|
410
|
+
invitationEmail?: {
|
|
411
|
+
inProgress: boolean;
|
|
412
|
+
};
|
|
450
413
|
}
|
|
451
414
|
/**
|
|
452
|
-
*
|
|
453
|
-
*
|
|
454
|
-
*
|
|
455
|
-
*
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
415
|
+
* Report where the canonical-email and invitation-email backfills stand, for an admin route or an
|
|
416
|
+
* operator script: how many `user` rows are still unfilled, which of them another account blocks
|
|
417
|
+
* (with that account's id), and whether a pass is part-way.
|
|
418
|
+
*
|
|
419
|
+
* Read-only, and bounded: at most five statements for the canonical email and two for invitations. SQLite
|
|
420
|
+
* only (it reads `rowid`, `json_each` and `sqlite_master`): use the executor over the D1 database the auth
|
|
421
|
+
* tables live in (`d1Executor(env.DB)`). Postgres and MySQL, which `ensureMigrated` backfills through
|
|
422
|
+
* better-auth's adapter, are not covered, and the auth Durable Object keeps its tables in its own
|
|
423
|
+
* storage, which no executor reaches.
|
|
424
|
+
*
|
|
425
|
+
* ```ts
|
|
426
|
+
* const status = await authBackfillStatus(d1Executor(env.DB), authOptions);
|
|
427
|
+
* if (status.canonicalEmail?.duplicates.length) {
|
|
428
|
+
* // merge or rename each `id`; `heldBy` is the account that keeps the address
|
|
429
|
+
* }
|
|
430
|
+
* ```
|
|
431
|
+
*/
|
|
432
|
+
declare const authBackfillStatus: (executor: BackfillExecutor, options: LunoraAuthOptions) => Promise<AuthBackfillStatus>;
|
|
433
|
+
/** One table rewritten by {@link convertAuthDatesToEpochMs}. */
|
|
434
|
+
interface AuthDateConversion {
|
|
435
|
+
/** Rows with at least one date column rewritten. */
|
|
436
|
+
converted: number;
|
|
437
|
+
table: string;
|
|
459
438
|
}
|
|
460
439
|
/**
|
|
461
|
-
*
|
|
462
|
-
*
|
|
463
|
-
*
|
|
464
|
-
*
|
|
465
|
-
*
|
|
466
|
-
*
|
|
467
|
-
*
|
|
468
|
-
*
|
|
469
|
-
*
|
|
470
|
-
*
|
|
471
|
-
*
|
|
472
|
-
*
|
|
473
|
-
*
|
|
474
|
-
*
|
|
475
|
-
*
|
|
476
|
-
*
|
|
477
|
-
*
|
|
478
|
-
*
|
|
479
|
-
*
|
|
480
|
-
|
|
481
|
-
|
|
440
|
+
* Rewrite the ISO-string dates earlier `@lunora/auth` versions stored in better-auth's
|
|
441
|
+
* tables as epoch-ms numbers, matching the `v.date()` columns `authTables` declares.
|
|
442
|
+
*
|
|
443
|
+
* Until a row is converted, a Lunora `ctx.db.patch` on it fails validation, and SQL range
|
|
444
|
+
* filters on its date columns misbehave: SQLite orders every string above every number, so
|
|
445
|
+
* a legacy `expiresAt` never matches `< now` and always matches `> now`.
|
|
446
|
+
*
|
|
447
|
+
* Pass the same options as `createAuth`, so the plugin tables are covered. The tables Lunora
|
|
448
|
+
* provisions must exist; a plugin table the app manages itself (`disableMigration`) is
|
|
449
|
+
* converted when present and skipped when absent. SQLite only (D1, a Durable Object's
|
|
450
|
+
* storage): the conversion runs in SQL, a fixed handful of statements per table whatever its
|
|
451
|
+
* size, so it stays inside D1's per-invocation query limit and returns no rows.
|
|
452
|
+
*
|
|
453
|
+
* Every table is checked before anything is written: a value that is not an ISO-8601 date
|
|
454
|
+
* throws, naming the table, column and row, and no row is changed. The update converts only
|
|
455
|
+
* text SQLite can still read as a date, so a value written meanwhile is never erased.
|
|
456
|
+
* Idempotent: a converted cell holds a number, which no later run touches, so a run that
|
|
457
|
+
* stops part-way is finished by running it again.
|
|
458
|
+
*
|
|
459
|
+
* ```ts
|
|
460
|
+
* await convertAuthDatesToEpochMs(d1Executor(env.DB), authOptions);
|
|
461
|
+
* ```
|
|
462
|
+
*/
|
|
463
|
+
declare const convertAuthDatesToEpochMs: (executor: SqlExecutor, options: LunoraAuthOptions) => Promise<AuthDateConversion[]>;
|
|
482
464
|
/**
|
|
483
|
-
*
|
|
484
|
-
*
|
|
485
|
-
|
|
486
|
-
|
|
465
|
+
* The recorded form of {@link convertAuthDatesToEpochMs}: the run `ensureMigrated`, `prepareAuthData`
|
|
466
|
+
* and the auth Durable Object make on their own, and the one to call on every cold start.
|
|
467
|
+
*
|
|
468
|
+
* Each run records its coverage (tables and date columns) and when a run over it first came back
|
|
469
|
+
* clean, in the backfill state table. Runs keep converting for 24 hours after that, which catches
|
|
470
|
+
* ISO dates written by isolates still on an older version during a rollout; the first clean run
|
|
471
|
+
* after it marks the record final, and from then on a run is one indexed lookup. Adding a plugin
|
|
472
|
+
* with date columns changes the coverage and starts over. An import or replace through the data
|
|
473
|
+
* port invalidates the record, so restored rows are converted too.
|
|
474
|
+
*/
|
|
475
|
+
declare const convertAuthDatesOnce: (executor: SqlExecutor, options: LunoraAuthOptions) => Promise<AuthDateConversion[]>;
|
|
476
|
+
/**
|
|
477
|
+
* The `CREATE TABLE` / `CREATE INDEX` statements for a better-auth config, in
|
|
478
|
+
* execution order (every table before any index).
|
|
479
|
+
*
|
|
480
|
+
* All statements are `IF NOT EXISTS`, so this is safe to run on every cold start —
|
|
481
|
+
* which is how `LunoraAuthDO` uses it. It creates; it never alters or drops, so a
|
|
482
|
+
* schema that has already diverged is left alone rather than half-migrated.
|
|
483
|
+
*
|
|
484
|
+
* Physical names throughout: `modelName` for tables, `fieldName ?? key` for columns,
|
|
485
|
+
* and better-auth's own resolved `columns` / `name` for indexes — so an index name
|
|
486
|
+
* here is the name better-auth's introspection expects to find.
|
|
487
|
+
* @param options The better-auth options the DO will run — the plugin list decides which tables exist.
|
|
488
|
+
* @returns SQL statements to execute in order.
|
|
489
|
+
*/
|
|
490
|
+
declare const authDoSchemaStatements: (options: LunoraAuthOptions) => string[];
|
|
491
|
+
/**
|
|
492
|
+
* `ALTER TABLE … ADD COLUMN` statements for columns the live schema is missing.
|
|
493
|
+
*
|
|
494
|
+
* ## Why this is needed at all
|
|
495
|
+
*
|
|
496
|
+
* {@link authDoSchemaStatements} is entirely `IF NOT EXISTS`, which makes it safe to
|
|
497
|
+
* re-run but blind to change: a *new table* appears on the next cold start, a *new
|
|
498
|
+
* column on an existing table* never does. That is not a hypothetical — enabling the
|
|
499
|
+
* `admin` plugin after first deploy adds `role` / `banned` / `banExpires` to `user`,
|
|
500
|
+
* and without this the object would keep serving a `user` table that cannot hold them.
|
|
501
|
+
*
|
|
502
|
+
* Additive only. Nothing here drops, renames, or retypes a column: a column that
|
|
503
|
+
* exists is left exactly as it is, so a schema someone has deliberately diverged is
|
|
504
|
+
* never "corrected" underneath them.
|
|
505
|
+
*
|
|
506
|
+
* ## What SQLite will not let us do
|
|
507
|
+
*
|
|
508
|
+
* `ADD COLUMN` cannot introduce a `NOT NULL` column without a default (existing rows
|
|
509
|
+
* would violate it immediately), and cannot introduce `UNIQUE`. So a required column
|
|
510
|
+
* with a static default is added with both; a required column *without* one is added
|
|
511
|
+
* **nullable**, which differs from what a fresh `CREATE TABLE` would produce. That is
|
|
512
|
+
* the deliberate trade: better-auth writes these fields on every insert, so nullable
|
|
513
|
+
* is harmless, whereas refusing to add the column at all would leave the object
|
|
514
|
+
* broken. Uniqueness is unaffected — better-auth expresses it as a separate index, and
|
|
515
|
+
* those are `IF NOT EXISTS`, so they are created by the statements above.
|
|
516
|
+
* @param options The better-auth options the DO runs, already resolved.
|
|
517
|
+
* @param existingColumns Physical column names currently present on a table; empty/absent for a table that does not exist yet (it will be created instead).
|
|
518
|
+
* @returns SQL statements to execute in order; empty when the live schema is current.
|
|
519
|
+
*/
|
|
520
|
+
declare const authDoColumnAdditions: (options: LunoraAuthOptions, existingColumns: (table: string) => Iterable<string>) => string[];
|
|
521
|
+
/** better-auth's `databaseHooks` shape, derived so a rename upstream fails to compile rather than silently mis-hooking. */
|
|
522
|
+
type DatabaseHooks = NonNullable<BetterAuthOptions["databaseHooks"]>;
|
|
523
|
+
/** Config for the signup gate hooks: the base {@link EmailGateConfig} plus an optional classification tap. */
|
|
524
|
+
interface EmailGateHookConfig extends EmailGateConfig {
|
|
525
|
+
/**
|
|
526
|
+
* Called with the resolved classification once the gate passes, so app policy
|
|
527
|
+
* can react to `free` vs `business` at signup (e.g. tag the account). Never
|
|
528
|
+
* fires when the gate rejects. Fires only at creation: an address change never
|
|
529
|
+
* calls it, because its hook receives the patch rather than the new user record.
|
|
530
|
+
* `context` is better-auth's endpoint context (`null` outside a request, e.g. an
|
|
531
|
+
* internal create).
|
|
532
|
+
*/
|
|
533
|
+
onClassify?: (classification: EmailClassification, user: Record<string, unknown>, context: unknown) => void;
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* Produce a `databaseHooks` fragment that gates better-auth's user lifecycle on the
|
|
537
|
+
* email-domain policy: sign-up (`user.create.before`) and address changes
|
|
538
|
+
* (`user.update.before`). Spread it into `createAuth({ databaseHooks: … })`, or
|
|
539
|
+
* use {@link withEmailGate} to merge it (composing with any existing hooks).
|
|
540
|
+
*
|
|
541
|
+
* ```ts
|
|
542
|
+
* const auth = createAuth({
|
|
543
|
+
* secret: env.AUTH_SECRET,
|
|
544
|
+
* database: lunoraD1Adapter(env.DB),
|
|
545
|
+
* databaseHooks: emailGateDatabaseHooks({ blockDisposable: true }),
|
|
546
|
+
* });
|
|
547
|
+
* ```
|
|
548
|
+
*/
|
|
549
|
+
declare const emailGateDatabaseHooks: (config?: EmailGateHookConfig) => DatabaseHooks;
|
|
550
|
+
/**
|
|
551
|
+
* Merge the email-domain gate into an existing better-auth options object,
|
|
552
|
+
* preserving any `databaseHooks` the caller already set. For each hook the caller
|
|
553
|
+
* already declared (`user.create.before`, `user.update.before`), the gate runs
|
|
554
|
+
* first, rejecting a disallowed address before their hook sees it, then theirs
|
|
555
|
+
* runs on the (possibly rewritten) input. Other existing hooks, such as
|
|
556
|
+
* `user.update.after`, are kept as they were.
|
|
557
|
+
*
|
|
558
|
+
* ```ts
|
|
559
|
+
* const auth = createAuth(withEmailGate({ secret, database }, { blockDisposable: true }));
|
|
560
|
+
* ```
|
|
561
|
+
*/
|
|
562
|
+
declare const withEmailGate: (options: BetterAuthOptions, config?: EmailGateHookConfig) => BetterAuthOptions;
|
|
487
563
|
/**
|
|
488
|
-
*
|
|
489
|
-
* `
|
|
490
|
-
*
|
|
491
|
-
*
|
|
492
|
-
*
|
|
493
|
-
*
|
|
494
|
-
|
|
495
|
-
|
|
564
|
+
* Whether the Worker is running in development: at least one of `CF_ENV`,
|
|
565
|
+
* `ENVIRONMENT`, `NODE_ENV` or `WORKER_ENV` is set, and EVERY one that is set
|
|
566
|
+
* names a dev environment. A set-but-empty var counts as set, so it vetoes dev.
|
|
567
|
+
* `@lunora/mail`, `@lunora/queue` and `@lunora/shard-engine` still treat an empty
|
|
568
|
+
* var as unset; this copy is stricter on purpose.
|
|
569
|
+
*
|
|
570
|
+
* `every`, not `some`: a production deploy that also carries a leftover dev
|
|
571
|
+
* `NODE_ENV` must stay production, or it would log auth links (bearer
|
|
572
|
+
* credentials) and run migrations on cold start. A deploy that sets none of the
|
|
573
|
+
* vars is production too — fail closed either way.
|
|
574
|
+
*/
|
|
575
|
+
declare const isDevEnvironment: (env: Record<string, unknown>) => boolean;
|
|
496
576
|
/**
|
|
497
|
-
*
|
|
498
|
-
* `
|
|
499
|
-
*
|
|
500
|
-
*
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
*
|
|
504
|
-
*
|
|
505
|
-
*
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
* via `compileMigrationsSql` + `wrangler d1 execute`; this helper exists for
|
|
509
|
-
* dev/playground and small deployments.
|
|
510
|
-
*/
|
|
511
|
-
declare const ensureMigrated: (auth: LunoraAuth | {
|
|
512
|
-
options: LunoraAuthOptions;
|
|
513
|
-
}) => Promise<void>;
|
|
577
|
+
* Where `@lunora/auth` serves its routes, for the packages that must know without
|
|
578
|
+
* importing it. `@lunora/config` routes these paths to the Worker ahead of the
|
|
579
|
+
* static assets (`assets.run_worker_first`) but cannot import `@lunora/auth`,
|
|
580
|
+
* which depends on it, so both read them here.
|
|
581
|
+
*/
|
|
582
|
+
/**
|
|
583
|
+
* Default basePath used by better-auth's client + handler. Override via the
|
|
584
|
+
* second argument of `handleAuthRequest` if you mount the auth routes somewhere
|
|
585
|
+
* else.
|
|
586
|
+
*/
|
|
587
|
+
declare const DEFAULT_AUTH_BASE_PATH: string;
|
|
514
588
|
/**
|
|
515
|
-
*
|
|
516
|
-
*
|
|
517
|
-
*
|
|
518
|
-
*
|
|
519
|
-
*
|
|
520
|
-
*
|
|
521
|
-
* `
|
|
522
|
-
*
|
|
523
|
-
*
|
|
524
|
-
|
|
525
|
-
|
|
589
|
+
* The cleanup statements, in execution order: every blocking index, then the column.
|
|
590
|
+
*
|
|
591
|
+
* Exported for the pre-applied-schema path (`compileMigrationsSql` + `wrangler d1 execute`),
|
|
592
|
+
* which compiles DDL without ever reading the database and so can neither tell whether the
|
|
593
|
+
* column is present nor discover the index names — SQLite has no `DROP COLUMN IF EXISTS` to
|
|
594
|
+
* make either unnecessary. Pass the names from
|
|
595
|
+
* `SELECT name, sql FROM sqlite_master WHERE type = 'index' AND tbl_name = 'account'`, and
|
|
596
|
+
* run this only against a database that still has the column.
|
|
597
|
+
* @param accountTable Physical name of the account table (`account` unless renamed via `account.modelName`).
|
|
598
|
+
* @param indexNames Indexes to drop first, from {@link indexesReferencingIssuer}.
|
|
599
|
+
* @returns The `DROP INDEX` statements followed by the `DROP COLUMN`.
|
|
600
|
+
*/
|
|
601
|
+
declare const legacyIssuerCleanupStatements: (accountTable?: string, indexNames?: Iterable<string>) => string[];
|
|
526
602
|
/**
|
|
527
|
-
* Lunora-friendly view over better-auth's `session` option.
|
|
528
|
-
*
|
|
529
|
-
* This is a typed alias for better-auth's own `session` shape — Lunora stays a
|
|
530
|
-
* thin wrapper, so we don't reimplement the fields, we just give them a named,
|
|
531
|
-
* documented home so callers get autocomplete without reaching into
|
|
532
|
-
* `BetterAuthOptions`. The most relevant fields for session rotation / richer
|
|
533
|
-
* policies are `expiresIn` (absolute session lifetime, in seconds),
|
|
534
|
-
* `updateAge` (rolling-rotation interval, in seconds — how often an active
|
|
535
|
-
* session's expiry is pushed forward; `0` rotates on every use),
|
|
536
|
-
* `disableSessionRefresh` (turn rolling rotation off entirely so sessions
|
|
537
|
-
* expire at the absolute `expiresIn` regardless of activity), `freshAge`
|
|
538
|
-
* (freshness window, in seconds, for sensitive operations like account
|
|
539
|
-
* deletion; `0` treats every session as fresh — not recommended), and
|
|
540
|
-
* `cookieCache` (
|
|
541
|
-
*
|
|
542
|
-
*
|
|
543
|
-
|
|
603
|
+
* Lunora-friendly view over better-auth's `session` option.
|
|
604
|
+
*
|
|
605
|
+
* This is a typed alias for better-auth's own `session` shape — Lunora stays a
|
|
606
|
+
* thin wrapper, so we don't reimplement the fields, we just give them a named,
|
|
607
|
+
* documented home so callers get autocomplete without reaching into
|
|
608
|
+
* `BetterAuthOptions`. The most relevant fields for session rotation / richer
|
|
609
|
+
* policies are `expiresIn` (absolute session lifetime, in seconds),
|
|
610
|
+
* `updateAge` (rolling-rotation interval, in seconds — how often an active
|
|
611
|
+
* session's expiry is pushed forward; `0` rotates on every use),
|
|
612
|
+
* `disableSessionRefresh` (turn rolling rotation off entirely so sessions
|
|
613
|
+
* expire at the absolute `expiresIn` regardless of activity), `freshAge`
|
|
614
|
+
* (freshness window, in seconds, for sensitive operations like account
|
|
615
|
+
* deletion; `0` treats every session as fresh — not recommended), and
|
|
616
|
+
* `cookieCache` (signed-cookie session cache that skips DB reads —
|
|
617
|
+
* `createAuth` fills `{ enabled: true, maxAge: 60 }` when you leave it unset, so
|
|
618
|
+
* a revoked session keeps authenticating for up to that many seconds; pass
|
|
619
|
+
* `{ enabled: false }` where that window is unacceptable).
|
|
620
|
+
*
|
|
621
|
+
* See better-auth's `session` option for the full field list.
|
|
622
|
+
*/
|
|
544
623
|
type SessionPolicy = NonNullable<BetterAuthOptions["session"]>;
|
|
545
624
|
/**
|
|
546
|
-
* Validate a {@link SessionPolicy} and return it unchanged (pass-through).
|
|
547
|
-
*
|
|
548
|
-
* better-auth happily accepts the `session` block verbatim, so the only job
|
|
549
|
-
* here is to catch obviously-broken numeric inputs at construction time —
|
|
550
|
-
* negative or non-finite durations — rather than letting them produce
|
|
551
|
-
* surprising cookie expiries at runtime. Field names mirror better-auth's
|
|
552
|
-
* `session` option exactly so the validated object forwards 1:1.
|
|
553
|
-
*/
|
|
625
|
+
* Validate a {@link SessionPolicy} and return it unchanged (pass-through).
|
|
626
|
+
*
|
|
627
|
+
* better-auth happily accepts the `session` block verbatim, so the only job
|
|
628
|
+
* here is to catch obviously-broken numeric inputs at construction time —
|
|
629
|
+
* negative or non-finite durations — rather than letting them produce
|
|
630
|
+
* surprising cookie expiries at runtime. Field names mirror better-auth's
|
|
631
|
+
* `session` option exactly so the validated object forwards 1:1.
|
|
632
|
+
*/
|
|
554
633
|
declare const validateSessionPolicy: (policy: SessionPolicy) => SessionPolicy;
|
|
555
634
|
/**
|
|
556
|
-
* Ready-made {@link SessionPolicy} presets covering the common rotation /
|
|
557
|
-
* expiry trade-offs. Spread or override fields as needed:
|
|
558
|
-
*
|
|
559
|
-
* ```ts
|
|
560
|
-
* import { createAuth, sessionPresets } from "@lunora/auth";
|
|
561
|
-
*
|
|
562
|
-
* export const auth = createAuth({
|
|
563
|
-
* secret: env.AUTH_SECRET,
|
|
564
|
-
* database: env.DB,
|
|
565
|
-
* session: { ...sessionPresets.rolling, freshAge: 60 * 5 },
|
|
566
|
-
* });
|
|
567
|
-
* ```
|
|
568
|
-
*
|
|
569
|
-
* - `rolling` — balanced default: 7-day absolute expiry, rotated once per day
|
|
570
|
-
*
|
|
571
|
-
*
|
|
572
|
-
* - `strict` — short, security-sensitive: 1-hour expiry, 15-minute rotation,
|
|
573
|
-
* cookie cache **off** (fast revocation / short freshness is the whole point).
|
|
574
|
-
* - `longLived` — low-friction consumer apps: 30-day expiry, daily rotation,
|
|
575
|
-
* with the same
|
|
576
|
-
*/
|
|
635
|
+
* Ready-made {@link SessionPolicy} presets covering the common rotation /
|
|
636
|
+
* expiry trade-offs. Spread or override fields as needed:
|
|
637
|
+
*
|
|
638
|
+
* ```ts
|
|
639
|
+
* import { createAuth, sessionPresets } from "@lunora/auth";
|
|
640
|
+
*
|
|
641
|
+
* export const auth = createAuth({
|
|
642
|
+
* secret: env.AUTH_SECRET,
|
|
643
|
+
* database: env.DB,
|
|
644
|
+
* session: { ...sessionPresets.rolling, freshAge: 60 * 5 },
|
|
645
|
+
* });
|
|
646
|
+
* ```
|
|
647
|
+
*
|
|
648
|
+
* - `rolling` — balanced default: 7-day absolute expiry, rotated once per day.
|
|
649
|
+
* It leaves `cookieCache` to `createAuth`'s default: a 60s signed-cookie
|
|
650
|
+
* session cache, or none with the `admin()` plugin so a ban is immediate.
|
|
651
|
+
* - `strict` — short, security-sensitive: 1-hour expiry, 15-minute rotation,
|
|
652
|
+
* cookie cache **off** (fast revocation / short freshness is the whole point).
|
|
653
|
+
* - `longLived` — low-friction consumer apps: 30-day expiry, daily rotation,
|
|
654
|
+
* with the same cookie-cache default as `rolling`.
|
|
655
|
+
*/
|
|
577
656
|
declare const sessionPresets: Record<"longLived" | "rolling" | "strict", SessionPolicy>;
|
|
578
|
-
export {
|
|
657
|
+
export { READ_AUDIT_PATH as AUTH_DO_AUDIT_PATH, INTERNAL_SECRET_HEADER as AUTH_DO_SECRET_HEADER, RESOLVE_SESSION_PATH as AUTH_DO_SESSION_PATH, type AppendAuthAuditEntry, type AppendAuthAuditOptions, type AuthAuditEvent, type AuthAuditHookConfig, type AuthBackfillStatus, type AuthDataSchema, type AuthDateConversion, type AuthDoOptions, type AuthDoState, type CanonicalEmailBackfillStatus, DEFAULT_AUTH_BASE_PATH, type DuplicateRow, type EmailClassification, type EmailGateConfig, type EmailGateHookConfig, LunoraAuthDO, type LunoraAuthOptions, type PrepareAuthDataOptions, type SessionPolicy, type SqlExecutor, authAuditBeforeHook, authAuditHook, authBackfillStatus, authDoColumnAdditions, authDoSchemaStatements, buildAuditEntry, convertAuthDatesOnce, convertAuthDatesToEpochMs, emailGateDatabaseHooks, eventForPath, isDevEnvironment, legacyIssuerCleanupStatements, prepareAuthData, sessionPresets, validateSessionPolicy, withAuthAudit, withEmailGate };
|