@lunora/auth 1.0.0-alpha.132 → 1.0.0-alpha.133
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/adapter.d.mts +1 -1
- package/dist/adapter.d.ts +1 -1
- package/dist/adapter.mjs +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/packem_shared/{AUTH_DO_AUDIT_PATH-ucS0M60j.mjs → AUTH_DO_AUDIT_PATH-th2-Hb30.mjs} +1 -1
- package/dist/packem_shared/adapter-CG0Yv85f.mjs +2 -0
- package/dist/packem_shared/{adapter.d-DrD3bb1u.d.mts → adapter.d-BW_ovHul.d.mts} +13 -0
- package/dist/packem_shared/{adapter.d-2a61HAY2.d.ts → adapter.d-BWw-tC_U.d.ts} +13 -0
- package/dist/packem_shared/compileMigrationsSql-Ds2snsWg.mjs +1 -0
- package/dist/packem_shared/{createDoAuthWiring-68YJP-VM.mjs → createDoAuthWiring-C8BRUjf6.mjs} +1 -1
- package/dist/packem_shared/sql-store-CYa4HJsO.mjs +1 -0
- package/dist/sql-store.mjs +1 -1
- package/package.json +2 -2
- package/dist/packem_shared/adapter-DA8DdALX.mjs +0 -1
- package/dist/packem_shared/compileMigrationsSql-ByVJhjR6.mjs +0 -1
package/dist/adapter.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import 'better-auth/adapters';
|
|
2
|
-
export { l as lunoraAuthAdapter, a as lunoraD1Adapter, b as lunoraDoAdapter } from "./packem_shared/adapter.d-
|
|
2
|
+
export { l as lunoraAuthAdapter, a as lunoraD1Adapter, b as lunoraDoAdapter } from "./packem_shared/adapter.d-BW_ovHul.mjs";
|
|
3
3
|
import "./sql-store.mjs";
|
|
4
4
|
import "./store.mjs";
|
package/dist/adapter.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import 'better-auth/adapters';
|
|
2
|
-
export { l as lunoraAuthAdapter, a as lunoraD1Adapter, b as lunoraDoAdapter } from "./packem_shared/adapter.d-
|
|
2
|
+
export { l as lunoraAuthAdapter, a as lunoraD1Adapter, b as lunoraDoAdapter } from "./packem_shared/adapter.d-BWw-tC_U.js";
|
|
3
3
|
import "./sql-store.js";
|
|
4
4
|
import "./store.js";
|
package/dist/adapter.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{l as t,a as p,b as e}from"./packem_shared/adapter-
|
|
1
|
+
import{l as t,a as p,b as e}from"./packem_shared/adapter-CG0Yv85f.mjs";import"./packem_shared/sql-store-CYa4HJsO.mjs";export{t as lunoraAuthAdapter,p as lunoraD1Adapter,e as lunoraDoAdapter};
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { D as DoStorageLike } from "./packem_shared/adapter.d-
|
|
2
|
-
export { l as lunoraAuthAdapter, a as lunoraD1Adapter, b as lunoraDoAdapter } from "./packem_shared/adapter.d-
|
|
1
|
+
import { D as DoStorageLike } from "./packem_shared/adapter.d-BW_ovHul.mjs";
|
|
2
|
+
export { l as lunoraAuthAdapter, a as lunoraD1Adapter, b as lunoraDoAdapter } from "./packem_shared/adapter.d-BW_ovHul.mjs";
|
|
3
3
|
import { LunoraError } from '@lunora/errors';
|
|
4
4
|
import { L as LunoraAuth, a as LunoraAuthOptions } from "./packem_shared/create-auth.d-D1CKOFWc.mjs";
|
|
5
5
|
export { c as createAuth, r as resolveAuthOptions } from "./packem_shared/create-auth.d-D1CKOFWc.mjs";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { D as DoStorageLike } from "./packem_shared/adapter.d-
|
|
2
|
-
export { l as lunoraAuthAdapter, a as lunoraD1Adapter, b as lunoraDoAdapter } from "./packem_shared/adapter.d-
|
|
1
|
+
import { D as DoStorageLike } from "./packem_shared/adapter.d-BWw-tC_U.js";
|
|
2
|
+
export { l as lunoraAuthAdapter, a as lunoraD1Adapter, b as lunoraDoAdapter } from "./packem_shared/adapter.d-BWw-tC_U.js";
|
|
3
3
|
import { LunoraError } from '@lunora/errors';
|
|
4
4
|
import { L as LunoraAuth, a as LunoraAuthOptions } from "./packem_shared/create-auth.d-D1CKOFWc.js";
|
|
5
5
|
export { c as createAuth, r as resolveAuthOptions } from "./packem_shared/create-auth.d-D1CKOFWc.js";
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{l as r,a as o,b as a}from"./packem_shared/adapter-
|
|
1
|
+
import{l as r,a as o,b as a}from"./packem_shared/adapter-CG0Yv85f.mjs";import{LunoraAuthAdminError as A,createAuthAdmin as u}from"./packem_shared/LunoraAuthAdminError-4r29Kj_y.mjs";import{AUTH_AUDIT_TABLE as n,appendAuthAuditEntry as m,createAuthAuditReader as l,ensureAuthAuditTable as p,readAuthAuditLog as d}from"./audit.mjs";import{authAuditHook as E,buildAuditEntry as f,eventForPath as T,withAuthAudit as S}from"./packem_shared/authAuditHook-C9Gt2iYp.mjs";import{READ_AUDIT_PATH as _,INTERNAL_SECRET_HEADER as D,RESOLVE_SESSION_PATH as c,LunoraAuthDO as H}from"./packem_shared/AUTH_DO_AUDIT_PATH-th2-Hb30.mjs";import{createAuth as U,resolveAuthOptions as R}from"./packem_shared/createAuth-8aUw8v8D.mjs";import{authDoColumnAdditions as v,authDoSchemaStatements as L}from"./packem_shared/authDoColumnAdditions-UwF3Rl41.mjs";import{createDoAuthWiring as O}from"./packem_shared/createDoAuthWiring-C8BRUjf6.mjs";import{emailGateDatabaseHooks as N,withEmailGate as w}from"./packem_shared/emailGateDatabaseHooks-CAygR3iq.mjs";import{assertEmailAllowed as M,classifyEmail as C,emailGateMiddleware as k,loadEmailDomainLists as q}from"./email-guard.mjs";import{DEFAULT_AUTH_BASE_PATH as G,handleAuthRequest as B}from"./packem_shared/DEFAULT_AUTH_BASE_PATH-DneiLGpv.mjs";import{createSignUpInvitation as W,listSignUpInvitations as Y,pruneSignUpInvitations as j,revokeSignUpInvitation as z}from"./packem_shared/createSignUpInvitation-ClvskwuB.mjs";import{legacyIssuerCleanupStatements as K}from"./packem_shared/legacyIssuerCleanupStatements-D9Kf8OD1.mjs";import{LunoraAuthHeadersError as X,withAuthPlugins as Z}from"./middleware.mjs";import{compileMigrationsSql as tt,ensureMigrated as et}from"./packem_shared/compileMigrationsSql-Ds2snsWg.mjs";import{default as ot}from"./schema.mjs";import{sessionPresets as it,validateSessionPolicy as At}from"./packem_shared/sessionPresets-C867Mlo4.mjs";import{c as st,d as nt}from"./packem_shared/sql-store-CYa4HJsO.mjs";import{createMemoryAuthStore as lt,matchesWhere as pt}from"./store.mjs";import{TURNSTILE_VERIFY_ENDPOINT as ht,verifyTurnstile as Et}from"./turnstile.mjs";import{verifyTurnstileMiddleware as Tt}from"./turnstile-middleware.mjs";export{n as AUTH_AUDIT_TABLE,_ as AUTH_DO_AUDIT_PATH,D as AUTH_DO_SECRET_HEADER,c as AUTH_DO_SESSION_PATH,G as DEFAULT_AUTH_BASE_PATH,A as LunoraAuthAdminError,H as LunoraAuthDO,X as LunoraAuthHeadersError,ht as TURNSTILE_VERIFY_ENDPOINT,m as appendAuthAuditEntry,M as assertEmailAllowed,E as authAuditHook,v as authDoColumnAdditions,L as authDoSchemaStatements,ot as authTables,f as buildAuditEntry,C as classifyEmail,tt as compileMigrationsSql,U as createAuth,u as createAuthAdmin,l as createAuthAuditReader,O as createDoAuthWiring,lt as createMemoryAuthStore,W as createSignUpInvitation,st as createSqlAuthStore,nt as d1Executor,N as emailGateDatabaseHooks,k as emailGateMiddleware,p as ensureAuthAuditTable,et as ensureMigrated,T as eventForPath,B as handleAuthRequest,K as legacyIssuerCleanupStatements,Y as listSignUpInvitations,q as loadEmailDomainLists,r as lunoraAuthAdapter,o as lunoraD1Adapter,a as lunoraDoAdapter,pt as matchesWhere,j as pruneSignUpInvitations,d as readAuthAuditLog,R as resolveAuthOptions,z as revokeSignUpInvitation,it as sessionPresets,At as validateSessionPolicy,Et as verifyTurnstile,Tt as verifyTurnstileMiddleware,S as withAuthAudit,Z as withAuthPlugins,w as withEmailGate};
|
package/dist/packem_shared/{AUTH_DO_AUDIT_PATH-ucS0M60j.mjs → AUTH_DO_AUDIT_PATH-th2-Hb30.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getAuthTablesWithResolvedIndexes as u}from"@better-auth/core/db/internal";import{b as c,d as l}from"./adapter-
|
|
1
|
+
import{getAuthTablesWithResolvedIndexes as u}from"@better-auth/core/db/internal";import{b as c,d as l}from"./adapter-CG0Yv85f.mjs";import{ensureAuthAuditTable as h,createAuthAuditReader as m}from"../audit.mjs";import{resolveAuthOptions as d,createAuth as p}from"./createAuth-8aUw8v8D.mjs";import{authDoSchemaStatements as f,authDoColumnAdditions as A}from"./authDoColumnAdditions-UwF3Rl41.mjs";import{handleAuthRequest as g}from"./DEFAULT_AUTH_BASE_PATH-DneiLGpv.mjs";import{schemaDeclaresIssuer as y,legacyIssuerCleanupStatements as R,indexesReferencingIssuer as x}from"./legacyIssuerCleanupStatements-D9Kf8OD1.mjs";const b=(i,s)=>{const t=Math.max(i.length,s.length);let e=i.length^s.length;for(let r=0;r<t;r+=1){const o=r<i.length?i.charCodeAt(r):0,n=r<s.length?s.charCodeAt(r):0;e|=o^n}return e===0},E="/__lunora/auth/session",S="/__lunora/auth/audit",v="x-lunora-auth-do-secret",_=i=>{if(i===null||typeof i!="object"||Array.isArray(i))return{error:"body must be a JSON object"};const s={};for(const[t,e]of Object.entries(i))if(t==="limit"||t==="sinceSeq"){if(typeof e!="number"||!Number.isFinite(e))return{error:`"${t}" must be a finite number`};s[t]=e}else if(t==="actorId"||t==="event"){if(typeof e!="string")return{error:`"${t}" must be a string`};s[t]=e}else return{error:`unknown audit read option "${t}"`};return{options:s}};class q{#s;#r;#e;#t;#n=!1;constructor(s,t,e={}){this.#e=s.storage,this.#r=t,this.#s=e}#o(){if(this.#t!==void 0)return this.#t;const s=this.#r();if(!this.#n){const t=d(s);for(const e of f(t))[...this.#e.sql.exec(e)];for(const e of A(t,r=>this.#i(r)))[...this.#e.sql.exec(e)];this.#u(t),this.#n=!0}return this.#t=p({...s,database:c(this.#e)}),this.#t}#i(s){return[...this.#e.sql.exec("SELECT name FROM pragma_table_info(?)",s)].map(e=>String(e.name))}#u(s){const{tables:t}=u(s),{account:e}=t;if(e===void 0)return;const r=Object.entries(e.fields).map(([o,n])=>n.fieldName??o);if(!(y(r)||!this.#i(e.modelName).includes("issuer")))try{const o=[...this.#e.sql.exec("SELECT name, sql FROM sqlite_master WHERE type = 'index' AND tbl_name = ?",e.modelName)].map(n=>({name:String(n.name),sql:typeof n.sql=="string"?n.sql:void 0}));for(const n of R(e.modelName,x(o)))[...this.#e.sql.exec(n)]}catch(o){console.error("@lunora/auth: could not drop the reverted `account.issuer` column; sign-ups will fail until it is removed.",o)}}async#c(s){if(!this.#a(s))return Response.json({error:"unauthorized"},{status:401});let t;try{t=await s.json()}catch{return Response.json({error:"invalid body"},{status:400})}const e=_(t??{});if("error"in e)return Response.json({error:e.error},{status:400});const r=l(this.#e);await h(r);const o=await m(r).read(e.options);return Response.json({entries:o})}#a(s){const{internalSecret:t}=this.#s;if(t===void 0||t==="")return!1;const e=s.headers.get(v);return e!==null&&b(e,t)}async#l(s){if(!this.#a(s))return Response.json({error:"unauthorized"},{status:401});const e=await this.#o().api.getSession({headers:s.headers}),r=e?.user.id;if(r===void 0)return Response.json({});const o=e?.session.expiresAt,n=e?.user,a=n?.role;return Response.json({...typeof n?.email=="string"&&n.email.length>0?{email:n.email}:{},...o instanceof Date?{expiresAtMs:o.getTime()}:{},...typeof n?.name=="string"&&n.name.length>0?{name:n.name}:{},...typeof a=="string"&&a.length>0?{role:a}:{},userId:r})}async fetch(s){const t=new URL(s.url);if(t.pathname===E)return this.#l(s);if(t.pathname===S)return this.#c(s);const e=this.#o();return await g(e,s,this.#s.basePath)??Response.json({error:"not an auth route"},{status:404})}}export{v as INTERNAL_SECRET_HEADER,q as LunoraAuthDO,S as READ_AUDIT_PATH,E as RESOLVE_SESSION_PATH};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{createAdapterFactory as m}from"better-auth/adapters";import{checksSchema as p,registerSchemaCheck as f,createSchemaCheck as h,getExpectedSchema as y,diffSchema as b,formatSchemaFinding as w}from"@better-auth/core/db/internal";import{q as S}from"./quote-identifier-CGiYFBvY.mjs";import{C as g,c as u,d as x}from"./sql-store-CYa4HJsO.mjs";const A=e=>({all:(a,t)=>Promise.resolve([...e.sql.exec(a,...t)]),run:(a,t)=>([...e.sql.exec(a,...t)],Promise.resolve())}),O=e=>async a=>e.transaction(a),M=e=>({parameters:[],sql:`PRAGMA table_info(${S(e)})`}),q=e=>({parameters:[e],sql:"SELECT * FROM pragma_table_info(?)"}),I=e=>{const a=String(e.name),t=e.dflt_value;return{hasDefault:t!=null||a===g,name:a,nullable:Number(e.notnull??0)===0}},v=async(e,a,t)=>{const{parameters:n,sql:r}=a(t),s=await e.all(r,n);if(s.length!==0)return{columns:s.map(o=>I(o)),name:t}},C=e=>{const a=["@lunora/auth: the auth tables do not match the better-auth options this app runs.",...e.map(t=>` - ${w(t,"database")}`),"Fix the schema, not the adapter. better-auth's own tables are created by `ensureMigrated(...)` or by","`compileMigrationsSql(...)` at deploy time; tables you declared yourself come from `authTables(options)`","in `lunora/schema.ts` plus `lunora migrate`. `npx auth migrate` does not apply to a Lunora app."];console.error(a.join(`
|
|
2
|
+
`))},T=async(e,a,t)=>{const n=y(e),r=Object.entries(n).filter(([,c])=>!c.disableMigrations).map(([c])=>c),s=await Promise.all(r.map(async c=>v(a,t,c))),o=b(n,s.filter(c=>c!==void 0));return o.length>0&&C(o),o},i=(e,a)=>t=>{const n=e(t);if(p(t)){const{database:r,executor:s,tableInfo:o}=a;f(n,h(async()=>T(t,s,o),"database",r))}return n},E=e=>e,l=e=>e??null,N=e=>e,R=e=>({consumeOne:async({model:a,where:t})=>l(await e.consumeOne(a,t)),count:async({model:a,where:t})=>e.count(a,t??[]),create:async({data:a,model:t})=>E(await e.create(t,a)),delete:async({model:a,where:t})=>{await e.remove(a,t)},deleteMany:async({model:a,where:t})=>e.remove(a,t),findMany:async({limit:a,model:t,offset:n,sortBy:r,where:s})=>N(await e.read(t,{limit:a,offset:n,sortBy:r,where:s??[]})),findOne:async({model:a,where:t})=>{const[n]=await e.read(a,{limit:1,where:t});return l(n)},incrementOne:async({increment:a,model:t,set:n,where:r})=>l(await e.incrementOne(t,r,a,n)),update:async({model:a,update:t,where:n})=>{const[r]=await e.update(a,n,t);return l(r)},updateMany:async({model:a,update:t,where:n})=>(await e.update(a,n,t)).length}),d=(e,a)=>{const t=r=>s=>m({adapter:()=>R(e),config:{adapterId:"lunora",adapterName:"Lunora Adapter",transaction:r(s),supportsBooleans:!1,supportsDates:!1,supportsJSON:!1,supportsNumericIds:!1}})(s),n=()=>!1;return t(a?r=>async s=>a(async()=>s(t(n)(r))):n)},k=e=>{const a=x(e);return i(d(u(a)),{database:e,executor:a,tableInfo:M})},L=e=>{const a=A(e);return i(d(u(a),O(e)),{database:e,executor:a,tableInfo:q})};export{k as a,L as b,A as d,d as l};
|
|
@@ -44,6 +44,11 @@ type TransactionRunner = <R>(closure: () => Promise<R>) => Promise<R>;
|
|
|
44
44
|
* Scope: the {@link AuthStore} interface is single-table CRUD. better-auth's
|
|
45
45
|
* relational `join` reads (an advanced opt-in) are not handled — pair the
|
|
46
46
|
* adapter with `disableJoins` or let better-auth fall back to per-table reads.
|
|
47
|
+
*
|
|
48
|
+
* No schema check either: an {@link AuthStore} is opaque CRUD with nothing to
|
|
49
|
+
* introspect, so better-auth logs that validation is unavailable for this adapter
|
|
50
|
+
* and proceeds. {@link lunoraD1Adapter} and {@link lunoraDoAdapter} know which
|
|
51
|
+
* SQLite backend they sit on and register one — see `schema-check.ts`.
|
|
47
52
|
*/
|
|
48
53
|
declare const lunoraAuthAdapter: (store: AuthStore, runInTransaction?: TransactionRunner) => ReturnType<typeof createAdapterFactory>;
|
|
49
54
|
/**
|
|
@@ -61,6 +66,12 @@ declare const lunoraAuthAdapter: (store: AuthStore, runInTransaction?: Transacti
|
|
|
61
66
|
* same. The migration instance is the one exception — it wants raw `env.DB` so
|
|
62
67
|
* `ensureMigrated`'s Kysely migrator can create the tables (its `$context` is
|
|
63
68
|
* never resolved, so the hang doesn't apply there).
|
|
69
|
+
*
|
|
70
|
+
* Carries a schema check: before the first write — better-auth awaits it in the
|
|
71
|
+
* router ahead of the rate limiter, which is the first thing that writes — the
|
|
72
|
+
* tables this configuration needs are compared against the ones D1 holds, and a
|
|
73
|
+
* mismatch fails with the table and column named instead of `no such table: …`
|
|
74
|
+
* inside an empty 500. See `schema-check.ts`.
|
|
64
75
|
*/
|
|
65
76
|
declare const lunoraD1Adapter: (d1: Parameters<typeof d1Executor>[0]) => ReturnType<typeof lunoraAuthAdapter>;
|
|
66
77
|
/**
|
|
@@ -70,6 +81,8 @@ declare const lunoraD1Adapter: (d1: Parameters<typeof d1Executor>[0]) => ReturnT
|
|
|
70
81
|
* Unlike `lunoraD1Adapter` this one exposes real transactions, so plugins that
|
|
71
82
|
* demand them (`@better-auth/scim`) accept it. Read the trade-offs in `do-store.ts`
|
|
72
83
|
* before reaching for it: the auth tables then live inside a single Durable Object.
|
|
84
|
+
*
|
|
85
|
+
* Schema-checked like {@link lunoraD1Adapter}, against the object's own SQLite.
|
|
73
86
|
* @experimental
|
|
74
87
|
*/
|
|
75
88
|
declare const lunoraDoAdapter: (storage: DoStorageLike) => ReturnType<typeof lunoraAuthAdapter>;
|
|
@@ -44,6 +44,11 @@ type TransactionRunner = <R>(closure: () => Promise<R>) => Promise<R>;
|
|
|
44
44
|
* Scope: the {@link AuthStore} interface is single-table CRUD. better-auth's
|
|
45
45
|
* relational `join` reads (an advanced opt-in) are not handled — pair the
|
|
46
46
|
* adapter with `disableJoins` or let better-auth fall back to per-table reads.
|
|
47
|
+
*
|
|
48
|
+
* No schema check either: an {@link AuthStore} is opaque CRUD with nothing to
|
|
49
|
+
* introspect, so better-auth logs that validation is unavailable for this adapter
|
|
50
|
+
* and proceeds. {@link lunoraD1Adapter} and {@link lunoraDoAdapter} know which
|
|
51
|
+
* SQLite backend they sit on and register one — see `schema-check.ts`.
|
|
47
52
|
*/
|
|
48
53
|
declare const lunoraAuthAdapter: (store: AuthStore, runInTransaction?: TransactionRunner) => ReturnType<typeof createAdapterFactory>;
|
|
49
54
|
/**
|
|
@@ -61,6 +66,12 @@ declare const lunoraAuthAdapter: (store: AuthStore, runInTransaction?: Transacti
|
|
|
61
66
|
* same. The migration instance is the one exception — it wants raw `env.DB` so
|
|
62
67
|
* `ensureMigrated`'s Kysely migrator can create the tables (its `$context` is
|
|
63
68
|
* never resolved, so the hang doesn't apply there).
|
|
69
|
+
*
|
|
70
|
+
* Carries a schema check: before the first write — better-auth awaits it in the
|
|
71
|
+
* router ahead of the rate limiter, which is the first thing that writes — the
|
|
72
|
+
* tables this configuration needs are compared against the ones D1 holds, and a
|
|
73
|
+
* mismatch fails with the table and column named instead of `no such table: …`
|
|
74
|
+
* inside an empty 500. See `schema-check.ts`.
|
|
64
75
|
*/
|
|
65
76
|
declare const lunoraD1Adapter: (d1: Parameters<typeof d1Executor>[0]) => ReturnType<typeof lunoraAuthAdapter>;
|
|
66
77
|
/**
|
|
@@ -70,6 +81,8 @@ declare const lunoraD1Adapter: (d1: Parameters<typeof d1Executor>[0]) => ReturnT
|
|
|
70
81
|
* Unlike `lunoraD1Adapter` this one exposes real transactions, so plugins that
|
|
71
82
|
* demand them (`@better-auth/scim`) accept it. Read the trade-offs in `do-store.ts`
|
|
72
83
|
* before reaching for it: the auth tables then live inside a single Durable Object.
|
|
84
|
+
*
|
|
85
|
+
* Schema-checked like {@link lunoraD1Adapter}, against the object's own SQLite.
|
|
73
86
|
* @experimental
|
|
74
87
|
*/
|
|
75
88
|
declare const lunoraDoAdapter: (storage: DoStorageLike) => ReturnType<typeof lunoraAuthAdapter>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{getAuthTablesWithResolvedIndexes as w,invalidateSchemaChecks as y}from"@better-auth/core/db/internal";import{LunoraError as R}from"@lunora/errors";import{getMigrations as l}from"better-auth/db/migration";import{q as u}from"./quote-identifier-CGiYFBvY.mjs";import{resolveAuthOptions as _}from"./createAuth-8aUw8v8D.mjs";import{schemaDeclaresIssuer as x,legacyIssuerCleanupStatements as M,indexesReferencingIssuer as T}from"./legacyIssuerCleanupStatements-D9Kf8OD1.mjs";const N=/pragma_index_list\s*\(/iu,A=/sqlite_master/iu,C=/^["`[]|["\]`]$/gu,D=/\s+/u,S=/create\s+unique\s+index/iu,O=/\bwhere\b/iu,P=e=>N.test(e)&&A.test(e),L=e=>(e.trim().split(D)[0]??"").replaceAll(C,"").trim(),U=e=>{const t=e.indexOf("(");if(t===-1)return{columns:[],tail:""};let a=0;for(let n=t;n<e.length;n+=1){const s=e[n];if(s==="(")a+=1;else if(s===")"&&(a-=1,a===0))return{columns:e.slice(t+1,n).split(",").map(o=>L(o)).filter(o=>o!==""),tail:e.slice(n+1)}}return{columns:[],tail:""}},q=async e=>{const t=e.prepare("SELECT name, tbl_name, sql FROM sqlite_master WHERE type = 'index'"),{results:a}=await t.all(),n=[];for(const s of a??[]){const o=s.name,r=s.tbl_name,i=s.sql;if(typeof o!="string"||typeof r!="string")continue;if(typeof i!="string"){n.push({columnPosition:0,indexName:o,isPartial:0,isUnique:1,tableName:r});continue}const f=S.test(i)?1:0,{columns:h,tail:b}=U(i),E=O.test(b)?1:0;for(const[I,g]of h.entries())n.push({columnName:g,columnPosition:I,indexName:o,isPartial:E,isUnique:f,tableName:r})}return n},v=e=>{const t=async()=>{const n=await q(e);return{meta:{},results:n,success:!0}},a={all:t,bind:()=>a,run:t};return a},W=e=>new Proxy(e,{get(t,a,n){if(a==="prepare")return o=>P(o)?v(t):t.prepare(o);const s=Reflect.get(t,a,n);return typeof s=="function"?s.bind(t):s}}),m=e=>typeof e=="object"&&e!==null&&typeof e.prepare=="function"&&typeof e.batch=="function",p=e=>{const{database:t}=e;if(!(t&&typeof t!="function"))throw new R("AUTH_MIGRATOR_UNSUPPORTED",t?"@lunora/auth: this auth instance's `database` is a custom adapter, which better-auth's migrator cannot drive.":"@lunora/auth: this auth instance has no `database`, so better-auth's migrator has nothing to introspect.")},d=e=>m(e.database)?{...e,database:W(e.database)}:e,F=async(e,t)=>{try{return await e.prepare(`SELECT ${u("issuer")} FROM ${u(t)} LIMIT 0`).run(),!0}catch{return!1}},H=async e=>{const{database:t}=e,{tables:a}=w(e),{account:n}=a;if(n!==void 0&&!x(Object.entries(n.fields).map(([s,o])=>o.fieldName??s))&&m(t)&&await F(t,n.modelName))try{const{results:s}=await t.prepare("SELECT name, sql FROM sqlite_master WHERE type = 'index' AND tbl_name = ?").bind(n.modelName).all();await t.batch(M(n.modelName,T(s)).map(o=>t.prepare(o)))}catch(s){console.error("@lunora/auth: could not drop the reverted `account.issuer` column; sign-ups will fail until it is removed.",s)}},Q=e=>{const{database:t}=e;typeof t=="object"&&t!==null&&y(t)},c=new WeakMap,Y=async e=>{const{options:t}=e;p(t);const a=c.get(t);if(a){await a;return}const n=(async()=>{const{runMigrations:s}=await l(d(t));await s(),await H(t),Q(t)})();c.set(t,n);try{await n}catch(s){throw c.delete(t),s}},z=async e=>{const t=_(e);p(t);const{compileMigrations:a}=await l(d(t));return a()};export{z as compileMigrationsSql,Y as ensureMigrated};
|
package/dist/packem_shared/{createDoAuthWiring-68YJP-VM.mjs → createDoAuthWiring-C8BRUjf6.mjs}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{INTERNAL_SECRET_HEADER as u,RESOLVE_SESSION_PATH as p,READ_AUDIT_PATH as f}from"./AUTH_DO_AUDIT_PATH-
|
|
1
|
+
import{INTERNAL_SECRET_HEADER as u,RESOLVE_SESSION_PATH as p,READ_AUDIT_PATH as f}from"./AUTH_DO_AUDIT_PATH-th2-Hb30.mjs";import{DEFAULT_AUTH_BASE_PATH as h,isAuthRoutePath as A}from"./DEFAULT_AUTH_BASE_PATH-DneiLGpv.mjs";const g=l=>{const{basePath:c=h,internalSecret:a,namespace:o,objectName:d="auth"}=l,i=()=>{if(o)return o.get(o.idFromName(d))},m=async(t,n,r)=>{if(!a)return;const s=i();if(!s)return;const e=await s.fetch(new Request(new URL(t,n),{body:JSON.stringify(r),headers:{"content-type":"application/json",[u]:a},method:"POST"}));return e.ok?e:void 0};return{auditReader:{read:async t=>{const n=await m(f,"https://auth-do.invalid",t);return n?(await n.json())?.entries??[]:[]}},authHandler:async t=>{if(A(new URL(t.url).pathname,c))return i()?.fetch(t)},resolveIdentity:async t=>{if(!a)return null;const n=i();if(!n)return null;const r=new Headers(t.headers);r.set(u,a);const s=await n.fetch(new Request(new URL(p,t.url),{headers:r}));if(!s.ok)return null;const e=await s.json();return e?.userId?{...typeof e.email=="string"&&e.email.length>0?{email:e.email}:{},...typeof e.expiresAtMs=="number"&&Number.isFinite(e.expiresAtMs)?{expiresAtMs:e.expiresAtMs}:{},...typeof e.name=="string"&&e.name.length>0?{name:e.name}:{},...typeof e.role=="string"&&e.role.length>0?{role:e.role}:{},userId:e.userId}:null}}};export{g as createDoAuthWiring};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const T="_creationTime",l=s=>`"${s.replaceAll('"','""')}"`,N=/no such column|column .{0,64}? does not exist/iu,g={params:[],sql:"0"},R=(s,r)=>r?{column:`LOWER(${s})`,placeholder:"LOWER(?)"}:{column:s,placeholder:"?"},M=(s,r,a,c)=>{if(typeof r!="string")return g;const t=R(s,c);return a==="contains"?{params:[r],sql:`instr(${t.column}, ${t.placeholder}) > 0`}:a==="starts_with"?{params:[r],sql:`instr(${t.column}, ${t.placeholder}) = 1`}:{params:[r,r],sql:`substr(${t.column}, -length(?)) = ${t.placeholder}`}},h=(s,r,a,c)=>{if(r===null)return{params:[],sql:`${s} IS ${c?"NOT ":""}NULL`};const t=R(s,a),n=c?"<>":"=";return{params:[r],sql:`${t.column} ${n} ${t.placeholder}`}},O=(s,r,a,c)=>{const t=Array.isArray(r)?r:[];if(t.length===0)return{params:[],sql:a?"1":"0"};const n=R(s,c),e=t.map(()=>n.placeholder).join(", ");return{params:[...t],sql:`${n.column} ${a?"NOT IN":"IN"} (${e})`}},L=s=>{const r=l(s.field),{mode:a,operator:c,value:t}=s,n=a==="insensitive";switch(c){case"contains":case"ends_with":case"starts_with":return M(r,t,c,n);case"gt":return{params:[t],sql:`${r} > ?`};case"gte":return{params:[t],sql:`${r} >= ?`};case"in":return O(r,t,!1,n);case"lt":return{params:[t],sql:`${r} < ?`};case"lte":return{params:[t],sql:`${r} <= ?`};case"ne":return h(r,t,n,!0);case"not_in":return O(r,t,!0,n);default:return h(r,t,n,!1)}},d=(s,r)=>{if(s.length===0)return;const a=s.map(c=>L(c));return{params:a.flatMap(c=>c.params),sql:a.map(c=>`(${c.sql})`).join(` ${r} `)}},E=s=>{const r=[d(s.filter(a=>a.connector!=="OR"),"AND"),d(s.filter(a=>a.connector==="OR"),"OR")].filter(a=>a!==void 0);return r.length===0?{params:[],sql:""}:{params:r.flatMap(a=>a.params),sql:r.map(a=>`(${a.sql})`).join(" AND ")}},$=s=>s.sql?` WHERE ${s.sql}`:"",S=s=>{const r=(t,n)=>{const e=E(n);return s.all(`SELECT * FROM ${l(t)}${$(e)}`,e.params)},a=new Map,c=async t=>{const n=a.get(t);if(n!==void 0)return n;try{await s.all(`SELECT ${l(t)}.${l(T)} FROM ${l(t)} LIMIT 0`,[])}catch(e){return N.test(e instanceof Error?e.message:String(e))&&a.set(t,!1),!1}return a.set(t,!0),!0};return{consumeOne:async(t,n)=>{const e=E(n),o=l(t),[i]=await s.all(`DELETE FROM ${o} WHERE rowid IN (SELECT rowid FROM ${o}${$(e)} LIMIT 1) RETURNING *`,e.params);return i},count:async(t,n)=>{const e=E(n),[o]=await s.all(`SELECT COUNT(*) AS __count FROM ${l(t)}${$(e)}`,e.params);return Number(o?.__count??0)},create:async(t,n)=>{const e=T in n||!await c(t)?n:{[T]:Date.now(),...n},o=Object.keys(e),i=o.map(()=>"?").join(", "),u=`INSERT INTO ${l(t)} (${o.map(m=>l(m)).join(", ")}) VALUES (${i})`;return await s.run(u,o.map(m=>e[m])),{...n}},incrementOne:async(t,n,e,o)=>{const i=l(t),u=Object.keys(e),m=o?Object.keys(o):[],f=E(n);if(u.length===0&&m.length===0){const[p]=await s.all(`SELECT * FROM ${i}${$(f)} LIMIT 1`,f.params);return p}const I=[...u.map(p=>`${l(p)} = COALESCE(${l(p)}, 0) + ?`),...m.map(p=>`${l(p)} = ?`)].join(", "),[w]=await s.all(`UPDATE ${i} SET ${I} WHERE rowid IN (SELECT rowid FROM ${i}${$(f)} LIMIT 1) RETURNING *`,[...u.map(p=>e[p]),...m.map(p=>o[p]),...f.params]);return w},read:async(t,n)=>{const e=E(n.where),o=[...e.params];let i=`SELECT * FROM ${l(t)}${$(e)}`;return n.sortBy&&(i+=` ORDER BY ${l(n.sortBy.field)} ${n.sortBy.direction==="asc"?"ASC":"DESC"}`),n.limit!==void 0&&(i+=" LIMIT ?",o.push(Math.trunc(n.limit))),n.offset&&(i+=`${n.limit===void 0?" LIMIT -1":""} OFFSET ?`,o.push(Math.trunc(n.offset))),s.all(i,o)},remove:async(t,n)=>{const e=E(n);return(await s.all(`DELETE FROM ${l(t)}${$(e)} RETURNING *`,e.params)).length},update:async(t,n,e)=>{const o=Object.keys(e);if(o.length===0)return r(t,n);const i=o.map(m=>`${l(m)} = ?`).join(", "),u=E(n);return s.all(`UPDATE ${l(t)} SET ${i}${$(u)} RETURNING *`,[...o.map(m=>e[m]),...u.params])}}},C=s=>({all:async(r,a)=>(await s.prepare(r).bind(...a).all()).results??[],run:async(r,a)=>{await s.prepare(r).bind(...a).run()}});export{T as C,S as c,C as d};
|
package/dist/sql-store.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{c as t,d as o}from"./packem_shared/sql-store-CYa4HJsO.mjs";export{t as createSqlAuthStore,o as d1Executor};
|
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.133",
|
|
4
4
|
"description": "Auth for Lunora — a thin better-auth wrapper: email/password, OAuth, plugins, D1-backed",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"auth",
|
|
@@ -104,7 +104,7 @@
|
|
|
104
104
|
"@better-auth/passkey": "1.7.3",
|
|
105
105
|
"@better-auth/scim": "1.7.3",
|
|
106
106
|
"@lunora/errors": "1.0.0-alpha.35",
|
|
107
|
-
"@lunora/values": "1.0.0-alpha.
|
|
107
|
+
"@lunora/values": "1.0.0-alpha.44",
|
|
108
108
|
"@visulima/disposable-email-domains": "1.1.1",
|
|
109
109
|
"@visulima/email-verifier": "1.0.9",
|
|
110
110
|
"@visulima/free-email-domains": "1.0.1",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{createAdapterFactory as d}from"better-auth/adapters";import{createSqlAuthStore as o,d1Executor as l}from"../sql-store.mjs";const p=a=>({all:(e,n)=>Promise.resolve([...a.sql.exec(e,...n)]),run:(e,n)=>([...a.sql.exec(e,...n)],Promise.resolve())}),i=a=>async e=>a.transaction(e),y=a=>a,c=a=>a??null,m=a=>a,w=a=>({consumeOne:async({model:e,where:n})=>c(await a.consumeOne(e,n)),count:async({model:e,where:n})=>a.count(e,n??[]),create:async({data:e,model:n})=>y(await a.create(n,e)),delete:async({model:e,where:n})=>{await a.remove(e,n)},deleteMany:async({model:e,where:n})=>a.remove(e,n),findMany:async({limit:e,model:n,offset:t,sortBy:r,where:s})=>m(await a.read(n,{limit:e,offset:t,sortBy:r,where:s??[]})),findOne:async({model:e,where:n})=>{const[t]=await a.read(e,{limit:1,where:n});return c(t)},incrementOne:async({increment:e,model:n,set:t,where:r})=>c(await a.incrementOne(n,r,e,t)),update:async({model:e,update:n,where:t})=>{const[r]=await a.update(e,t,n);return c(r)},updateMany:async({model:e,update:n,where:t})=>(await a.update(e,t,n)).length}),u=(a,e)=>{const n=r=>s=>d({adapter:()=>w(a),config:{adapterId:"lunora",adapterName:"Lunora Adapter",transaction:r(s),supportsBooleans:!1,supportsDates:!1,supportsJSON:!1,supportsNumericIds:!1}})(s),t=()=>!1;return n(e?r=>async s=>e(async()=>s(n(t)(r))):t)},O=a=>u(o(l(a))),h=a=>u(o(p(a)),i(a));export{O as a,h as b,p as d,u as l};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{getAuthTablesWithResolvedIndexes as w}from"@better-auth/core/db/internal";import{LunoraError as y}from"@lunora/errors";import{getMigrations as l}from"better-auth/db/migration";import{q as u}from"./quote-identifier-CGiYFBvY.mjs";import{resolveAuthOptions as R}from"./createAuth-8aUw8v8D.mjs";import{schemaDeclaresIssuer as _,legacyIssuerCleanupStatements as x,indexesReferencingIssuer as M}from"./legacyIssuerCleanupStatements-D9Kf8OD1.mjs";const T=/pragma_index_list\s*\(/iu,N=/sqlite_master/iu,D=/^["`[]|["\]`]$/gu,A=/\s+/u,C=/create\s+unique\s+index/iu,O=/\bwhere\b/iu,P=t=>T.test(t)&&N.test(t),S=t=>(t.trim().split(A)[0]??"").replaceAll(D,"").trim(),L=t=>{const e=t.indexOf("(");if(e===-1)return{columns:[],tail:""};let a=0;for(let n=e;n<t.length;n+=1){const s=t[n];if(s==="(")a+=1;else if(s===")"&&(a-=1,a===0))return{columns:t.slice(e+1,n).split(",").map(r=>S(r)).filter(r=>r!==""),tail:t.slice(n+1)}}return{columns:[],tail:""}},U=async t=>{const e=t.prepare("SELECT name, tbl_name, sql FROM sqlite_master WHERE type = 'index'"),{results:a}=await e.all(),n=[];for(const s of a??[]){const r=s.name,o=s.tbl_name,i=s.sql;if(typeof r!="string"||typeof o!="string")continue;if(typeof i!="string"){n.push({columnPosition:0,indexName:r,isPartial:0,isUnique:1,tableName:o});continue}const f=C.test(i)?1:0,{columns:h,tail:b}=L(i),E=O.test(b)?1:0;for(const[I,g]of h.entries())n.push({columnName:g,columnPosition:I,indexName:r,isPartial:E,isUnique:f,tableName:o})}return n},q=t=>{const e=async()=>{const n=await U(t);return{meta:{},results:n,success:!0}},a={all:e,bind:()=>a,run:e};return a},W=t=>new Proxy(t,{get(e,a,n){if(a==="prepare")return r=>P(r)?q(e):e.prepare(r);const s=Reflect.get(e,a,n);return typeof s=="function"?s.bind(e):s}}),m=t=>typeof t=="object"&&t!==null&&typeof t.prepare=="function"&&typeof t.batch=="function",p=t=>{const{database:e}=t;if(!(e&&typeof e!="function"))throw new y("AUTH_MIGRATOR_UNSUPPORTED",e?"@lunora/auth: this auth instance's `database` is a custom adapter, which better-auth's migrator cannot drive.":"@lunora/auth: this auth instance has no `database`, so better-auth's migrator has nothing to introspect.")},d=t=>m(t.database)?{...t,database:W(t.database)}:t,v=async(t,e)=>{try{return await t.prepare(`SELECT ${u("issuer")} FROM ${u(e)} LIMIT 0`).run(),!0}catch{return!1}},F=async t=>{const{database:e}=t,{tables:a}=w(t),{account:n}=a;if(n!==void 0&&!_(Object.entries(n.fields).map(([s,r])=>r.fieldName??s))&&m(e)&&await v(e,n.modelName))try{const{results:s}=await e.prepare("SELECT name, sql FROM sqlite_master WHERE type = 'index' AND tbl_name = ?").bind(n.modelName).all();await e.batch(x(n.modelName,M(s)).map(r=>e.prepare(r)))}catch(s){console.error("@lunora/auth: could not drop the reverted `account.issuer` column; sign-ups will fail until it is removed.",s)}},c=new WeakMap,k=async t=>{const{options:e}=t;p(e);const a=c.get(e);if(a){await a;return}const n=(async()=>{const{runMigrations:s}=await l(d(e));await s(),await F(e)})();c.set(e,n);try{await n}catch(s){throw c.delete(e),s}},K=async t=>{const e=R(t);p(e);const{compileMigrations:a}=await l(d(e));return a()};export{K as compileMigrationsSql,k as ensureMigrated};
|