@lunora/auth 1.0.0-alpha.79 → 1.0.0-alpha.80
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/dist/index.d.mts
CHANGED
|
@@ -501,6 +501,14 @@ interface AuthAuditHookConfig extends AppendAuthAuditOptions {
|
|
|
501
501
|
* auth request.
|
|
502
502
|
*/
|
|
503
503
|
onRecord?: (entry: AppendAuthAuditEntry) => Promise<void> | void;
|
|
504
|
+
/**
|
|
505
|
+
* When true, `x-forwarded-for` is trusted as a client-IP fallback when
|
|
506
|
+
* `cf-connecting-ip` is absent — only enable this behind a proxy you control,
|
|
507
|
+
* or the recorded IP is attacker-chosen. Defaults to `false`: off Cloudflare,
|
|
508
|
+
* with no trusted proxy configured, the audit record's `ip` is omitted rather
|
|
509
|
+
* than populated from a spoofable header.
|
|
510
|
+
*/
|
|
511
|
+
trustProxyHeaders?: boolean;
|
|
504
512
|
}
|
|
505
513
|
/**
|
|
506
514
|
* Structural view of the fields we read off better-auth's after-hook context —
|
|
@@ -581,7 +589,10 @@ declare const eventForPath: (path: string) => AuthAuditEvent | undefined;
|
|
|
581
589
|
* plugin-ordered-after-`twoFactor` hook, or reading `twoFactor`'s own
|
|
582
590
|
* database state) and is left to a follow-up.
|
|
583
591
|
*/
|
|
584
|
-
declare const buildAuditEntry: (context: AuditHookContext, now
|
|
592
|
+
declare const buildAuditEntry: (context: AuditHookContext, { now, trustProxyHeaders }?: {
|
|
593
|
+
now?: number;
|
|
594
|
+
trustProxyHeaders?: boolean;
|
|
595
|
+
}) => AppendAuthAuditEntry | undefined;
|
|
585
596
|
/**
|
|
586
597
|
* Create the better-auth `hooks.after` middleware that records the auth/security
|
|
587
598
|
* audit trail. Assign it to `hooks.after` (or compose via {@link withAuthAudit}).
|
package/dist/index.d.ts
CHANGED
|
@@ -501,6 +501,14 @@ interface AuthAuditHookConfig extends AppendAuthAuditOptions {
|
|
|
501
501
|
* auth request.
|
|
502
502
|
*/
|
|
503
503
|
onRecord?: (entry: AppendAuthAuditEntry) => Promise<void> | void;
|
|
504
|
+
/**
|
|
505
|
+
* When true, `x-forwarded-for` is trusted as a client-IP fallback when
|
|
506
|
+
* `cf-connecting-ip` is absent — only enable this behind a proxy you control,
|
|
507
|
+
* or the recorded IP is attacker-chosen. Defaults to `false`: off Cloudflare,
|
|
508
|
+
* with no trusted proxy configured, the audit record's `ip` is omitted rather
|
|
509
|
+
* than populated from a spoofable header.
|
|
510
|
+
*/
|
|
511
|
+
trustProxyHeaders?: boolean;
|
|
504
512
|
}
|
|
505
513
|
/**
|
|
506
514
|
* Structural view of the fields we read off better-auth's after-hook context —
|
|
@@ -581,7 +589,10 @@ declare const eventForPath: (path: string) => AuthAuditEvent | undefined;
|
|
|
581
589
|
* plugin-ordered-after-`twoFactor` hook, or reading `twoFactor`'s own
|
|
582
590
|
* database state) and is left to a follow-up.
|
|
583
591
|
*/
|
|
584
|
-
declare const buildAuditEntry: (context: AuditHookContext, now
|
|
592
|
+
declare const buildAuditEntry: (context: AuditHookContext, { now, trustProxyHeaders }?: {
|
|
593
|
+
now?: number;
|
|
594
|
+
trustProxyHeaders?: boolean;
|
|
595
|
+
}) => AppendAuthAuditEntry | undefined;
|
|
585
596
|
/**
|
|
586
597
|
* Create the better-auth `hooks.after` middleware that records the auth/security
|
|
587
598
|
* audit trail. Assign it to `hooks.after` (or compose via {@link withAuthAudit}).
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{s as r,l as o,w as a}from"./packem_shared/adapter-RvDcm0Zy.mjs";import{LunoraAuthAdminError as u,createAuthAdmin as i}from"./packem_shared/LunoraAuthAdminError-CMUphsi_.mjs";import{AUTH_AUDIT_TABLE as m,appendAuthAuditEntry as l,createAuthAuditReader as d,ensureAuthAuditTable as h,readAuthAuditLog as E}from"./audit.mjs";import{authAuditHook as p,buildAuditEntry as T,eventForPath as f,withAuthAudit as _}from"./packem_shared/authAuditHook-
|
|
1
|
+
import{s as r,l as o,w as a}from"./packem_shared/adapter-RvDcm0Zy.mjs";import{LunoraAuthAdminError as u,createAuthAdmin as i}from"./packem_shared/LunoraAuthAdminError-CMUphsi_.mjs";import{AUTH_AUDIT_TABLE as m,appendAuthAuditEntry as l,createAuthAuditReader as d,ensureAuthAuditTable as h,readAuthAuditLog as E}from"./audit.mjs";import{authAuditHook as p,buildAuditEntry as T,eventForPath as f,withAuthAudit as _}from"./packem_shared/authAuditHook-CP7kj4Ob.mjs";import{READ_AUDIT_PATH as D,INTERNAL_SECRET_HEADER as S,RESOLVE_SESSION_PATH as H,LunoraAuthDO as c}from"./packem_shared/AUTH_DO_AUDIT_PATH-C4897amZ.mjs";import{createAuth as L,resolveAuthOptions as P}from"./packem_shared/createAuth-DRtd4q6u.mjs";import{authDoColumnAdditions as I,authDoSchemaStatements as O}from"./packem_shared/authDoColumnAdditions-B8BRbdzn.mjs";import{createDoAuthWiring as y}from"./packem_shared/createDoAuthWiring-acnXUGZr.mjs";import{emailGateDatabaseHooks as g,withEmailGate as v}from"./packem_shared/emailGateDatabaseHooks-DzBD1Qoq.mjs";import{assertEmailAllowed as b,classifyEmail as q,emailGateMiddleware as C,loadEmailDomainLists as F}from"./email-guard.mjs";import{DEFAULT_AUTH_BASE_PATH as k,handleAuthRequest as B}from"./packem_shared/DEFAULT_AUTH_BASE_PATH-kIwlEt8i.mjs";import{LunoraAuthHeadersError as W,withAuthPlugins as Y}from"./middleware.mjs";import{compileMigrationsSql as z,ensureMigrated as J}from"./packem_shared/compileMigrationsSql-BcvcHAqo.mjs";import{default as Q}from"./schema.mjs";import{sessionPresets as Z,validateSessionPolicy as $}from"./packem_shared/sessionPresets-DpEFjXKV.mjs";import{createSqlAuthStore as te,d1Executor as re}from"./sql-store.mjs";import{createMemoryAuthStore as ae,matchesWhere as Ae}from"./store.mjs";import{TURNSTILE_VERIFY_ENDPOINT as ie,verifyTurnstile as se}from"./turnstile.mjs";import{verifyTurnstileMiddleware as le}from"./turnstile-middleware.mjs";export{m as AUTH_AUDIT_TABLE,D as AUTH_DO_AUDIT_PATH,S as AUTH_DO_SECRET_HEADER,H as AUTH_DO_SESSION_PATH,k as DEFAULT_AUTH_BASE_PATH,u as LunoraAuthAdminError,c as LunoraAuthDO,W as LunoraAuthHeadersError,ie as TURNSTILE_VERIFY_ENDPOINT,l as appendAuthAuditEntry,b as assertEmailAllowed,p as authAuditHook,I as authDoColumnAdditions,O as authDoSchemaStatements,Q as authTables,T as buildAuditEntry,q as classifyEmail,z as compileMigrationsSql,L as createAuth,i as createAuthAdmin,d as createAuthAuditReader,y as createDoAuthWiring,ae as createMemoryAuthStore,te as createSqlAuthStore,re as d1Executor,g as emailGateDatabaseHooks,C as emailGateMiddleware,h as ensureAuthAuditTable,J as ensureMigrated,f as eventForPath,B as handleAuthRequest,F as loadEmailDomainLists,r as lunoraAuthAdapter,o as lunoraD1Adapter,a as lunoraDoAdapter,Ae as matchesWhere,E as readAuthAuditLog,P as resolveAuthOptions,Z as sessionPresets,$ as validateSessionPolicy,se as verifyTurnstile,le as verifyTurnstileMiddleware,_ as withAuthAudit,Y as withAuthPlugins,v as withEmailGate};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createAuthMiddleware as c}from"better-auth/api";import{appendAuthAuditEntry as d}from"../audit.mjs";const f=t=>{const r=t.toLowerCase(),e=i=>r===i||r.endsWith(i);if(e("/sign-up/email")||e("/sign-up"))return"sign-up";if(e("/sign-in/social")||e("/sign-in/magic-link"))return"sign-in-initiated";if(r.includes("/sign-in/")||r.includes("/callback/")||e("/magic-link/verify")||r.includes("/two-factor/verify-"))return"sign-in";if(e("/sign-out"))return"sign-out";if(e("/change-password")||e("/set-password"))return"password-change";if(e("/reset-password")||e("/request-password-reset")||e("/forget-password"))return"password-reset";if(e("/verify-email"))return"email-verification";if(r.includes("/two-factor/enable")||r.includes("/totp/enable"))return"mfa-enable";if(r.includes("/two-factor/disable")||r.includes("/totp/disable"))return"mfa-disable";if(e("/refresh-token")||e("/token"))return"token-refresh";if(e("/revoke-session")||e("/revoke-sessions")||e("/revoke-other-sessions"))return"session-revoke";if(e("/link-social"))return"account-link";if(e("/unlink-account"))return"account-unlink"},n=(t,r)=>t.headers?.get(r)??t.request?.headers.get(r)??void 0,l=(t,r)=>{const e=n(t,"cf-connecting-ip");if(e!==void 0)return e;if(r===!0)return n(t,"x-forwarded-for")?.split(",")[0]?.trim()},g=t=>{const r=t.context?.newSession??t.context?.session,e=r?.user?.id??r?.session?.userId,i=r?.user?.email;return{...e===void 0?{}:{actorId:e},...i===void 0?{}:{actorEmail:i}}},h=t=>{const r=t.context?.returned;if(r instanceof Error)return"failure";if(typeof r=="object"&&r!==null&&"status"in r){const e=Number(r.status);if(Number.isFinite(e)&&e>=400)return"failure"}return"success"},u=320,p=(t,r)=>{if(r!=="sign-in"&&r!=="sign-in-initiated")return;const e=t.body?.email??t.body?.username;if(!(typeof e!="string"||e.length===0))return e.length>u?e.slice(0,u):e},v=(t,{now:r=Date.now(),trustProxyHeaders:e}={})=>{const i=t.path===void 0?void 0:f(t.path);if(i===void 0)return;const o=l(t,e),s=n(t,"user-agent"),a=p(t,i);return{...g(t),event:i,outcome:h(t),ts:r,...o===void 0?{}:{ip:o},...a===void 0?{}:{targetEmail:a},...s===void 0?{}:{userAgent:s},detail:{path:t.path}}},m=t=>c(async r=>{try{const e=v(r,{trustProxyHeaders:t.trustProxyHeaders});if(e!==void 0){const i=await d(t.executor,e,{redactDetail:t.redactDetail,retention:t.retention});t.onRecord!==void 0&&await t.onRecord(i)}}catch(e){console.error("@lunora/auth: audit hook failed to record event",e)}}),y=(t,r)=>{const e=m(r),i=t.hooks?.after,o=i?async s=>(await i(s),e(s)):e;return{...t,hooks:{...t.hooks,after:o}}};export{m as authAuditHook,v as buildAuditEntry,f as eventForPath,y as withAuthAudit};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lunora/auth",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.80",
|
|
4
4
|
"description": "Auth for Lunora — a thin better-auth wrapper: email/password, OAuth, plugins, D1-backed",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"auth",
|
|
@@ -103,7 +103,7 @@
|
|
|
103
103
|
"@better-auth/passkey": "1.7.0-rc.2",
|
|
104
104
|
"@better-auth/scim": "1.7.0-rc.2",
|
|
105
105
|
"@lunora/errors": "1.0.0-alpha.21",
|
|
106
|
-
"@lunora/server": "1.0.0-alpha.
|
|
106
|
+
"@lunora/server": "1.0.0-alpha.72",
|
|
107
107
|
"@lunora/values": "1.0.0-alpha.26",
|
|
108
108
|
"@visulima/disposable-email-domains": "1.0.1",
|
|
109
109
|
"@visulima/email-verifier": "1.0.1",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{createAuthMiddleware as u}from"better-auth/api";import{appendAuthAuditEntry as c}from"../audit.mjs";const d=t=>{const i=t.toLowerCase(),e=r=>i===r||i.endsWith(r);if(e("/sign-up/email")||e("/sign-up"))return"sign-up";if(e("/sign-in/social")||e("/sign-in/magic-link"))return"sign-in-initiated";if(i.includes("/sign-in/")||i.includes("/callback/")||e("/magic-link/verify")||i.includes("/two-factor/verify-"))return"sign-in";if(e("/sign-out"))return"sign-out";if(e("/change-password")||e("/set-password"))return"password-change";if(e("/reset-password")||e("/request-password-reset")||e("/forget-password"))return"password-reset";if(e("/verify-email"))return"email-verification";if(i.includes("/two-factor/enable")||i.includes("/totp/enable"))return"mfa-enable";if(i.includes("/two-factor/disable")||i.includes("/totp/disable"))return"mfa-disable";if(e("/refresh-token")||e("/token"))return"token-refresh";if(e("/revoke-session")||e("/revoke-sessions")||e("/revoke-other-sessions"))return"session-revoke";if(e("/link-social"))return"account-link";if(e("/unlink-account"))return"account-unlink"},n=(t,i)=>t.headers?.get(i)??t.request?.headers.get(i)??void 0,l=t=>{const i=n(t,"x-forwarded-for");return n(t,"cf-connecting-ip")??(i===void 0?void 0:i.split(",")[0]?.trim())??n(t,"x-real-ip")},f=t=>{const i=t.context?.newSession??t.context?.session,e=i?.user?.id??i?.session?.userId,r=i?.user?.email;return{...e===void 0?{}:{actorId:e},...r===void 0?{}:{actorEmail:r}}},p=t=>{const i=t.context?.returned;if(i instanceof Error)return"failure";if(typeof i=="object"&&i!==null&&"status"in i){const e=Number(i.status);if(Number.isFinite(e)&&e>=400)return"failure"}return"success"},a=320,g=(t,i)=>{if(i!=="sign-in"&&i!=="sign-in-initiated")return;const e=t.body?.email??t.body?.username;if(!(typeof e!="string"||e.length===0))return e.length>a?e.slice(0,a):e},h=(t,i=Date.now())=>{const e=t.path===void 0?void 0:d(t.path);if(e===void 0)return;const r=l(t),s=n(t,"user-agent"),o=g(t,e);return{...f(t),event:e,outcome:p(t),ts:i,...r===void 0?{}:{ip:r},...o===void 0?{}:{targetEmail:o},...s===void 0?{}:{userAgent:s},detail:{path:t.path}}},v=t=>u(async i=>{try{const e=h(i);if(e!==void 0){const r=await c(t.executor,e,{redactDetail:t.redactDetail,retention:t.retention});t.onRecord!==void 0&&await t.onRecord(r)}}catch(e){console.error("@lunora/auth: audit hook failed to record event",e)}}),w=(t,i)=>{const e=v(i),r=t.hooks?.after,s=r?async o=>(await r(o),e(o)):e;return{...t,hooks:{...t.hooks,after:s}}};export{v as authAuditHook,h as buildAuditEntry,d as eventForPath,w as withAuthAudit};
|