better-auth 0.2.2 → 0.2.3-beta.2
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/adapters.d.ts +32 -6
- package/dist/adapters.js +22 -1
- package/dist/api.d.ts +2 -4
- package/dist/cli.js +4 -2
- package/dist/client/plugins.d.ts +5 -7
- package/dist/client.d.ts +3 -5
- package/dist/{index-DsEvbKjm.d.ts → index-3B6zGicM.d.ts} +10 -2
- package/dist/{index-D_ohe9r9.d.ts → index-BMYcrOqA.d.ts} +72 -113
- package/dist/index-CE92ti2Z.d.ts +827 -0
- package/dist/index.d.ts +4 -6
- package/dist/index.js +5 -3
- package/dist/next-js.d.ts +2 -4
- package/dist/node.d.ts +4 -6
- package/dist/plugins.d.ts +6 -8
- package/dist/plugins.js +1 -1
- package/dist/react.d.ts +3 -5
- package/dist/social.d.ts +3 -742
- package/dist/solid-start.d.ts +4 -6
- package/dist/solid.d.ts +3 -5
- package/dist/svelte-kit.d.ts +4 -6
- package/dist/svelte.d.ts +3 -5
- package/dist/types.d.ts +3 -5
- package/dist/utils.d.ts +5 -7
- package/dist/vue.d.ts +3 -5
- package/package.json +7 -5
- package/dist/.DS_Store +0 -0
- package/dist/adapter-D-m9-hQp.d.ts +0 -54
- package/dist/schema-D9o3OF80.d.ts +0 -88
package/dist/adapters.d.ts
CHANGED
|
@@ -1,15 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import '
|
|
1
|
+
import { f as Adapter, W as Where, F as FieldAttribute } from './index-BMYcrOqA.js';
|
|
2
|
+
import { Kysely } from 'kysely';
|
|
3
|
+
import './index-CE92ti2Z.js';
|
|
4
|
+
import 'arctic';
|
|
3
5
|
import 'zod';
|
|
6
|
+
import './helper-C1ihmerM.js';
|
|
7
|
+
import 'better-call';
|
|
4
8
|
|
|
5
|
-
declare const prismaAdapter: (
|
|
9
|
+
declare const prismaAdapter: ({ db: prisma, provider, }: {
|
|
10
|
+
db: any;
|
|
11
|
+
provider: "sqlite" | "cockroachdb" | "mysql" | "postgresql" | "sqlserver";
|
|
12
|
+
}) => Adapter;
|
|
6
13
|
|
|
7
14
|
interface DrizzleAdapterOptions {
|
|
8
|
-
schema
|
|
15
|
+
schema?: Record<string, any>;
|
|
16
|
+
provider: "pg" | "mysql" | "sqlite";
|
|
9
17
|
}
|
|
10
|
-
|
|
18
|
+
interface DB {
|
|
19
|
+
[key: string]: any;
|
|
20
|
+
}
|
|
21
|
+
declare const drizzleAdapter: (db: DB, options: DrizzleAdapterOptions) => Adapter;
|
|
11
22
|
|
|
12
23
|
declare const mongodbAdapter: (mongo: any) => {
|
|
24
|
+
id: string;
|
|
13
25
|
create<T, R = T>(data: {
|
|
14
26
|
model: string;
|
|
15
27
|
data: T;
|
|
@@ -35,4 +47,18 @@ declare const mongodbAdapter: (mongo: any) => {
|
|
|
35
47
|
}): Promise<any>;
|
|
36
48
|
};
|
|
37
49
|
|
|
38
|
-
|
|
50
|
+
interface KyselyAdapterConfig {
|
|
51
|
+
/**
|
|
52
|
+
* Transform dates and booleans for sqlite.
|
|
53
|
+
*/
|
|
54
|
+
transform?: {
|
|
55
|
+
schema: {
|
|
56
|
+
[table: string]: Record<string, FieldAttribute>;
|
|
57
|
+
};
|
|
58
|
+
boolean: boolean;
|
|
59
|
+
date: boolean;
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
declare const kyselyAdapter: (db: Kysely<any>, config?: KyselyAdapterConfig) => Adapter;
|
|
63
|
+
|
|
64
|
+
export { type DrizzleAdapterOptions, type KyselyAdapterConfig, drizzleAdapter, kyselyAdapter, mongodbAdapter, prismaAdapter };
|
package/dist/adapters.js
CHANGED
|
@@ -1 +1,22 @@
|
|
|
1
|
-
var
|
|
1
|
+
var Z=Object.defineProperty,ee=Object.defineProperties;var te=Object.getOwnPropertyDescriptors;var R=Object.getOwnPropertySymbols;var F=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable;var I=(e,t,a)=>t in e?Z(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a,m=(e,t)=>{for(var a in t||(t={}))F.call(t,a)&&I(e,a,t[a]);if(R)for(var a of R(t))U.call(t,a)&&I(e,a,t[a]);return e},C=(e,t)=>ee(e,te(t));var re=(e=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(e,{get:(t,a)=>(typeof require!="undefined"?require:t)[a]}):e)(function(e){if(typeof require!="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var S=(e,t)=>{var a={};for(var s in e)F.call(e,s)&&t.indexOf(s)<0&&(a[s]=e[s]);if(e!=null&&R)for(var s of R(e))t.indexOf(s)<0&&U.call(e,s)&&(a[s]=e[s]);return a};var f=(e,t,a)=>new Promise((s,i)=>{var n=c=>{try{o(a.next(c))}catch(l){i(l)}},r=c=>{try{o(a.throw(c))}catch(l){i(l)}},o=c=>c.done?s(c.value):Promise.resolve(c.value).then(n,r);o((a=a.apply(e,t)).next())});import{existsSync as se}from"fs";import z from"path";var $=e=>{var c,l,u,h,b,A;let t=(c=e.plugins)==null?void 0:c.reduce((p,y)=>{var g;let w=y.schema;if(!w)return p;for(let[x,k]of Object.entries(w))p[x]={fields:m(m({},(g=p[x])==null?void 0:g.fields),k.fields),tableName:x};return p},{}),a=((l=e.rateLimit)==null?void 0:l.storage)==="database",s={rateLimit:{tableName:((u=e.rateLimit)==null?void 0:u.tableName)||"rateLimit",fields:{key:{type:"string"},count:{type:"number"},lastRequest:{type:"number"}}}},d=t||{},{user:i,session:n,account:r}=d,o=S(d,["user","session","account"]);return m(m({user:{tableName:((h=e.user)==null?void 0:h.modelName)||"user",fields:m({name:{type:"string",required:!0},email:{type:"string",unique:!0,required:!0},emailVerified:{type:"boolean",defaultValue:()=>!1,required:!0},image:{type:"string",required:!1},createdAt:{type:"date",defaultValue:()=>new Date,required:!0},updatedAt:{type:"date",defaultValue:()=>new Date,required:!0}},i==null?void 0:i.fields),order:0},session:{tableName:((b=e.session)==null?void 0:b.modelName)||"session",fields:m({expiresAt:{type:"date",required:!0},ipAddress:{type:"string",required:!1},userAgent:{type:"string",required:!1},userId:{type:"string",references:{model:"user",field:"id",onDelete:"cascade"},required:!0}},n==null?void 0:n.fields),order:1},account:{tableName:((A=e.account)==null?void 0:A.modelName)||"account",fields:m({accountId:{type:"string",required:!0},providerId:{type:"string",required:!0},userId:{type:"string",references:{model:"user",field:"id",onDelete:"cascade"},required:!0},accessToken:{type:"string",required:!1},refreshToken:{type:"string",required:!1},idToken:{type:"string",required:!1},expiresAt:{type:"date",required:!1},password:{type:"string",required:!1}},r==null?void 0:r.fields),order:2}},o),a?s:{})};import ae from"fs/promises";import{produceSchema as ie}from"@mrleebo/prisma-ast";var O=class extends Error{constructor(t,a,s){super(t),this.name="BetterAuthError",this.message=t,this.cause=a}};import{TimeSpan as _e}from"oslo";import{alphabet as je,generateRandomString as ze}from"oslo/crypto";import{createConsola as ne}from"consola";var q=ne({formatOptions:{date:!1,colors:!0,compact:!0},defaults:{tag:"Better Auth"}}),oe=e=>({log:(...t)=>{!(e!=null&&e.disabled)&&q.log("",...t)},error:(...t)=>{!(e!=null&&e.disabled)&&q.error("",...t)},warn:(...t)=>{!(e!=null&&e.disabled)&&q.warn("",...t)},info:(...t)=>{!(e!=null&&e.disabled)&&q.info("",...t)},debug:(...t)=>{!(e!=null&&e.disabled)&&q.debug("",...t)},box:(...t)=>{!(e!=null&&e.disabled)&&q.box("",...t)},success:(...t)=>{!(e!=null&&e.disabled)&&q.success("",...t)},break:(...t)=>{!(e!=null&&e.disabled)&&console.log(`
|
|
2
|
+
`)}}),M=oe();function j(e){return e.charAt(0).toUpperCase()+e.slice(1)}import{generateState as et}from"oslo/oauth2";import{z as rt}from"zod";function N(e){if(!e)return{};if(e.length===1){let n=e[0];return n?{[n.field]:n.value}:void 0}let t=e.filter(n=>n.connector==="AND"||!n.connector),a=e.filter(n=>n.connector==="OR"),s=t.map(n=>({[n.field]:n.operator==="eq"||!n.operator?n.value:{[n.operator]:n.value}})),i=a.map(n=>({[n.field]:{[n.operator||"eq"]:n.value}}));return{AND:s.length?s:void 0,OR:i.length?i:void 0}}var Tt=({db:e,provider:t})=>{let a=e;return{id:"prisma",create(i){return f(this,null,function*(){let{model:n,data:r,select:o}=i;return yield a[n].create(m({data:r},o!=null&&o.length?{select:o.reduce((c,l)=>C(m({},c),{[l]:!0}),{})}:{}))})},findOne(i){return f(this,null,function*(){let{model:n,where:r,select:o}=i,c=N(r);return yield a[n].findFirst(m({where:c},o!=null&&o.length?{select:o.reduce((l,u)=>C(m({},l),{[u]:!0}),{})}:{}))})},findMany(i){return f(this,null,function*(){let{model:n,where:r}=i,o=N(r);return yield a[n].findMany({where:o})})},update(i){return f(this,null,function*(){let{model:n,where:r,update:o}=i,c=N(r);return yield a[n].update({where:c,data:o})})},delete(i){return f(this,null,function*(){let{model:n,where:r}=i,o=N(r);return yield a[n].delete({where:o})})},createSchema(i,n){return f(this,null,function*(){let r=$(i),o=n||"./prisma/schema.prisma",c=se(z.join(process.cwd(),o)),l="";return c?l=yield ae.readFile(z.join(process.cwd(),o),"utf-8"):l=ce(t),{code:ie(l,d=>{for(let b in r){let y=function(g,x){if(g==="string")return x?"String?":"String";if(g==="number")return x?"Int?":"Int";if(g==="boolean")return x?"Boolean?":"Boolean";if(g==="date")return x?"DateTime?":"DateTime"};var h=y;let A=r[b].fields,p=r[b].tableName,w=d.findByType("model",{name:p});!w&&d.model(p).field("id","String").attribute("id");for(let g in A){let x=A[g];if(w){let k=d.findByType("field",{name:g,within:w.properties});if(console.log(g,"exists"),k)continue}d.model(p).field(g,y(x.type,!x.required)),x.unique&&d.model(p).blockAttribute(`unique([${g}])`),x.references&&d.model(p).field(j(x.references.model),x.references.model).attribute(`relation(fields: [${g}], references: [${x.references.field}], onDelete: Cascade)`)}}}),fileName:o}})}}},ce=e=>`generator client {
|
|
3
|
+
provider = "prisma-client-js"
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
datasource db {
|
|
7
|
+
provider = "${e}"
|
|
8
|
+
url = ${e==="sqlite"?'"file:./dev.db"':'env("DATABASE_URL")'}
|
|
9
|
+
}`;import{and as le,eq as L,or as de}from"drizzle-orm";import*as V from"prettier";import{existsSync as ue}from"fs";import fe from"fs/promises";function v(e,t){let a=Object.keys(t).find(s=>{let i=t[s].name;return i===i});if(!a)throw new Error("Model not found");return t[a]}function B(e,t){if(!e)return[];if(e.length===1){let o=e[0];return o?[L(t[o.field],o.value)]:[]}let a=e.filter(o=>o.connector==="AND"||!o.connector),s=e.filter(o=>o.connector==="OR"),i=le(...a.map(o=>L(t[o.field],o.value))),n=de(...s.map(o=>L(t[o.field],o.value))),r=[];return a.length&&r.push(i),s.length&&r.push(n),r}var Dt=(e,t)=>{let a=(t==null?void 0:t.schema)||e._.schema;if(!a)throw new O("Drizzle adapter failed to initialize. Schema not found. Please provide a schema object in the adapter options object.");let s=t==null?void 0:t.provider;return{id:"drizzle",create(n){return f(this,null,function*(){let{model:r,data:o}=n,c=v(r,a);return(yield e.insert(c).values(o).returning())[0]})},findOne(n){return f(this,null,function*(){let{model:r,where:o,select:c}=n,l=v(r,a),u=B(o,l),d=null;return c!=null&&c.length?d=yield e.select(...c.map(h=>({[h]:l[h]}))).from(l).where(...u):d=yield e.select().from(l).where(...u),d.length?d[0]:null})},findMany(n){return f(this,null,function*(){let{model:r,where:o}=n,c=v(r,a),l=o?B(o,c):[];return yield e.select().from(c).findMany(...l)})},update(n){return f(this,null,function*(){let{model:r,where:o,update:c}=n,l=v(r,a),u=B(o,l);return(yield e.update(l).set(c).where(...u).returning())[0]})},delete(n){return f(this,null,function*(){let{model:r,where:o}=n,c=v(r,a),l=B(o,c);return(yield e.delete(c).where(...l))[0]})},createSchema(n,r){return f(this,null,function*(){let o=$(n),c=r||"./schema.ts",l=s!=="sqlite"?"timestamp, boolean":"",u=s==="mysql"?"int":"integer",d="",h=ue(c);if(h){let p=yield fe.readFile(c,"utf-8");p.includes("import")?d=p:d=`import { ${s}Table, text, ${u}, ${l} } from "drizzle-orm/${s}-core";
|
|
10
|
+
`}else d=`import { ${s}Table, text, ${u}, ${l} } from "drizzle-orm/${s}-core";
|
|
11
|
+
`;for(let p in o){let g=function(k,T){if(T==="string")return`text('${k}')`;if(T==="number")return`${u}('${k}')`;if(T==="boolean")return s==="sqlite"?`integer('${k}', {
|
|
12
|
+
mode: "boolean"
|
|
13
|
+
})`:`boolean('${k}')`;if(T==="date")return s==="sqlite"?`integer('${k}', {
|
|
14
|
+
mode: "timestamp"
|
|
15
|
+
})`:`timestamp('${k}')`};var A=g;let y=o[p].tableName,w=o[p].fields,x=`export const ${p} = ${s}Table("${y}", {
|
|
16
|
+
id: text("id").primaryKey(),
|
|
17
|
+
${Object.keys(w).map(k=>{let T=w[k];return`${k}: ${g(k,T.type)}${T.required?".notNull()":""}${T.unique?".unique()":""}${T.references?`.references(()=> ${T.references.model}.${T.references.field})`:""}`}).join()}
|
|
18
|
+
});`;d+=`
|
|
19
|
+
${x}
|
|
20
|
+
`}return{code:yield V.format(d,{semi:!0,parser:"typescript",tabWidth:4}),fileName:c,append:h}})}}};function D(e){if(!e)return{};if(e.length===1){let r=e[0];return r?{[r.field]:r.value}:void 0}let t=e.filter(r=>r.connector==="AND"||!r.connector),a=e.filter(r=>r.connector==="OR"),s=t.map(r=>({[r.field]:r.operator==="eq"||!r.operator?r.value:{[r.field]:r.value}})),i=a.map(r=>({[r.field]:r.value})),n={};return s.length&&(n=C(m({},n),{$and:s})),i.length&&(n=C(m({},n),{$or:i})),n}function E(e){let s=e,{_id:t}=s;return S(s,["_id"])}function me(e){return e.reduce((a,s)=>(a[s]=1,a),{})}var Pt=e=>{let t=e;return{id:"mongodb",create(s){return f(this,null,function*(){let{model:i,data:n}=s,o=(yield t.collection(i).insertOne(m({},n))).insertedId,c=m({id:o},n);return E(c)})},findOne(s){return f(this,null,function*(){let{model:i,where:n,select:r}=s,o=D(n),c={};r&&(c=me(r));let u=(yield t.collection(i).find(m({},o),{projection:c}).toArray())[0];return u?E(u):null})},findMany(s){return f(this,null,function*(){let{model:i,where:n}=s,r=D(n),o=yield t.collection(i).findMany(r);return E(o)})},update(s){return f(this,null,function*(){let{model:i,where:n,update:r}=s,o=D(n),c=yield t.collection(i).findOneAndUpdate(o,{$set:r},{returnDocument:"after"});return E(c)})},delete(s){return f(this,null,function*(){let{model:i,where:n}=s,r=D(n);return yield t.collection(i).findOneAndDelete(r)})}}};import"kysely";function pe(e){var a;return((a=e.plugins)==null?void 0:a.flatMap(s=>Object.keys(s.schema||{}).map(i=>{let r=(s.schema||{})[i];if(!(r!=null&&r.disableMigration))return{tableName:i,fields:r==null?void 0:r.fields}}).filter(i=>i!==void 0)))||[]}function G(e){let t=$(e),a=pe(e);return[t.user,t.session,t.account,...a].reduce((i,n)=>{var r;return i[n.tableName]={fields:m(m({},(r=i[n.tableName])==null?void 0:r.fields),n.fields)},i},{})}import{Kysely as ye}from"kysely";import{MysqlDialect as K,PostgresDialect as W,SqliteDialect as H}from"kysely";import{createPool as he}from"mysql2";import be from"pg";var{Pool:ge}=be,Ae=e=>{var a,s;if(!e.database)return;if("createDriver"in e.database)return e.database;let t;if("provider"in e.database){let i=e.database.provider,n=(s=(a=e.database)==null?void 0:a.url)==null?void 0:s.trim();if(i==="postgres"&&(t=new W({pool:new ge({connectionString:n})})),i==="mysql")try{let r=new URL(n),o=he({host:r.hostname,user:r.username,password:r.password,database:r.pathname.split("/")[1],port:Number(r.port)});t=new K({pool:o})}catch(r){if(r instanceof TypeError)throw new O("Invalid database URL")}if(i==="sqlite"){let r=re("better-sqlite3"),o=new r(n);t=new H({database:o})}}return t},X=e=>{let t=Ae(e);return t&&new ye({dialect:t})},J=e=>{if("provider"in e.database)return e.database.provider;if("dialect"in e.database){if(e.database.dialect instanceof W)return"postgres";if(e.database.dialect instanceof K)return"mysql";if(e.database.dialect instanceof H)return"sqlite"}return"sqlite"};var xe={string:["character varying","text"],number:["int4","integer","bigint","smallint","numeric","real","double precision"],boolean:["bool","boolean"],date:["timestamp","date"]},we={string:["varchar","text"],number:["integer","int","bigint","smallint","decimal","float","double"],boolean:["boolean"],date:["date","datetime"]},ke={string:["TEXT"],number:["INTEGER","REAL"],boolean:["INTEGER","BOOLEAN"],date:["DATE","INTEGER"]},Ce={postgres:xe,mysql:we,sqlite:ke};function Te(e,t,a){return Ce[a][t].map(r=>r.toLowerCase()).includes(e.toLowerCase())}function Q(e){return f(this,null,function*(){let t=G(e),a=J(e),s=X(e);s||(M.error("Invalid database configuration."),process.exit(1));let i=yield s.introspection.getTables(),n=[],r=[];for(let[d,h]of Object.entries(t)){let b=i.find(p=>p.name===d);if(!b){let p=n.findIndex(g=>g.table===d),y={table:d,fields:h.fields,order:h.order||1/0},w=n.findIndex(g=>(g.order||1/0)>y.order);w===-1?p===-1?n.push(y):n[p].fields=m(m({},n[p].fields),h.fields):n.splice(w,0,y);continue}let A={};for(let[p,y]of Object.entries(h.fields)){let w=b.columns.find(g=>g.name===p);if(!w){A[p]=y;continue}Te(w.dataType,y.type,a)||M.warn(`Field ${p} in table ${d} has a different type in the database. Expected ${y.type} but got ${w.dataType}.`)}Object.keys(A).length>0&&r.push({table:d,fields:A,order:h.order||1/0})}let o=[];function c(d){let h={string:"text",boolean:"boolean",number:"integer",date:"date"};return a==="mysql"&&d==="string"?"varchar(255)":h[d]}if(r.length)for(let d of r)for(let[h,b]of Object.entries(d.fields)){let A=c(b.type),p=s.schema.alterTable(d.table).addColumn(h,A,y=>(y=b.required!==!1?y.notNull():y,b.references&&(y=y.references(`${b.references.model}.${b.references.field}`)),y));o.push(p)}if(n.length)for(let d of n){let h=s.schema.createTable(d.table).addColumn("id",c("string"),b=>b.primaryKey());for(let[b,A]of Object.entries(d.fields)){let p=c(A.type);h=h.addColumn(b,p,y=>(y=A.required!==!1?y.notNull():y,A.references&&(y=y.references(`${A.references.model}.${A.references.field}`)),A.unique&&(y=y.unique()),y))}o.push(h)}function l(){return f(this,null,function*(){for(let d of o)yield d.execute()})}function u(){return f(this,null,function*(){return o.map(h=>h.compile().sql).join(`;
|
|
21
|
+
|
|
22
|
+
`)})}return{toBeCreated:n,toBeAdded:r,runMigrations:l,compileMigrations:u}})}function _(e){if(!e)return{and:null,or:null};let t=e==null?void 0:e.filter(s=>s.connector==="AND"||!s.connector).reduce((s,i)=>C(m({},s),{[i.field]:i.value}),{}),a=e==null?void 0:e.filter(s=>s.connector==="OR").reduce((s,i)=>C(m({},s),{[i.field]:i.value}),{});return{and:Object.keys(t).length?t:null,or:Object.keys(a).length?a:null}}function P(e,t,a){var s,i,n;for(let r in e)e[r]===0&&((s=t[r])==null?void 0:s.type)==="boolean"&&(a!=null&&a.boolean)&&(e[r]=!1),e[r]===1&&((i=t[r])==null?void 0:i.type)==="boolean"&&(a!=null&&a.boolean)&&(e[r]=!0),((n=t[r])==null?void 0:n.type)==="date"&&(e[r]instanceof Date||(e[r]=new Date(e[r])));return e}function Y(e,t){for(let a in e)typeof e[a]=="boolean"&&(t!=null&&t.boolean)&&(e[a]=e[a]?1:0),e[a]instanceof Date&&(e[a]=e[a].toISOString());return e}var rr=(e,t)=>({id:"kysely",create(s){return f(this,null,function*(){let{model:i,data:n,select:r}=s;t!=null&&t.transform&&(n=Y(n,t.transform));let o=yield e.insertInto(i).values(n).returningAll().executeTakeFirst();if(t!=null&&t.transform){let c=t.transform.schema[i];o=c?P(n,c,t.transform):o}return r!=null&&r.length&&(o=o?r.reduce((l,u)=>o!=null&&o[u]?C(m({},l),{[u]:o[u]}):l,{}):null),o})},findOne(s){return f(this,null,function*(){let{model:i,where:n,select:r}=s,{and:o,or:c}=_(n),l=e.selectFrom(i).selectAll();c&&(l=l.where(d=>d.or(c))),o&&(l=l.where(d=>d.and(o)));let u=yield l.executeTakeFirst();if(r!=null&&r.length&&(u=u?r.reduce((h,b)=>u!=null&&u[b]?C(m({},h),{[b]:u[b]}):h,{}):null),t!=null&&t.transform){let d=t.transform.schema[i];return u=u&&d?P(u,d,t.transform):u,u||null}return u||null})},findMany(s){return f(this,null,function*(){let{model:i,where:n}=s,r=e.selectFrom(i),{and:o,or:c}=_(n);o&&(r=r.where(u=>u.and(o))),c&&(r=r.where(u=>u.or(c)));let l=yield r.selectAll().execute();if(t!=null&&t.transform){let u=t.transform.schema[i];return u?l.map(d=>P(d,u,t.transform)):l}return l})},update(s){return f(this,null,function*(){let{model:i,where:n,update:r}=s,{and:o,or:c}=_(n);t!=null&&t.transform&&(r=Y(r,t.transform));let l=e.updateTable(i).set(r);o&&(l=l.where(d=>d.and(o))),c&&(l=l.where(d=>d.or(c)));let u=(yield l.returningAll().executeTakeFirst())||null;if(t!=null&&t.transform){let d=t.transform.schema[i];return d?P(u,d,t.transform):u}return u})},delete(s){return f(this,null,function*(){let{model:i,where:n}=s,{and:r,or:o}=_(n),c=e.deleteFrom(i);r&&(c=c.where(l=>l.and(r))),o&&(c=c.where(l=>l.or(o))),yield c.execute()})},createSchema(s){return f(this,null,function*(){let{compileMigrations:i}=yield Q(s);return console.log(i),{code:yield i(),fileName:`./better-auth_migrations/${new Date().toISOString()}.sql`}})}});export{Dt as drizzleAdapter,rr as kyselyAdapter,Pt as mongodbAdapter,Tt as prismaAdapter};
|
package/dist/api.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
export { A as AuthEndpoint, b as AuthMiddleware,
|
|
1
|
+
export { A as AuthEndpoint, b as AuthMiddleware, y as callbackOAuth, X as changePassword, a as createAuthEndpoint, c as createAuthMiddleware, Q as createEmailVerificationToken, a1 as csrfMiddleware, _ as error, M as forgetPassword, N as forgetPasswordCallback, Z as getCSRFToken, u as getEndpoints, z as getSession, C as getSessionFromCtx, E as listSessions, $ as ok, o as optionsMiddleware, O as resetPassword, J as revokeSession, K as revokeSessions, v as router, T as sendVerificationEmail, D as sessionMiddleware, Y as setPassword, x as signInEmail, w as signInOAuth, L as signOut, a0 as signUpEmail, V as updateUser, U as verifyEmail } from './index-BMYcrOqA.js';
|
|
2
2
|
import 'zod';
|
|
3
3
|
import './helper-C1ihmerM.js';
|
|
4
4
|
import 'better-call';
|
|
5
5
|
import 'kysely';
|
|
6
|
-
import './
|
|
7
|
-
import './social.js';
|
|
6
|
+
import './index-CE92ti2Z.js';
|
|
8
7
|
import 'arctic';
|
|
9
|
-
import './adapter-D-m9-hQp.js';
|
package/dist/cli.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
var
|
|
3
|
-
`)}}),
|
|
2
|
+
var ie=Object.defineProperty,se=Object.defineProperties;var ne=Object.getOwnPropertyDescriptors;var D=Object.getOwnPropertySymbols;var P=Object.prototype.hasOwnProperty,V=Object.prototype.propertyIsEnumerable;var K=(e,t,a)=>t in e?ie(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a,h=(e,t)=>{for(var a in t||(t={}))P.call(t,a)&&K(e,a,t[a]);if(D)for(var a of D(t))V.call(t,a)&&K(e,a,t[a]);return e},k=(e,t)=>se(e,ne(t));var le=(e=>typeof require!="undefined"?require:typeof Proxy!="undefined"?new Proxy(e,{get:(t,a)=>(typeof require!="undefined"?require:t)[a]}):e)(function(e){if(typeof require!="undefined")return require.apply(this,arguments);throw Error('Dynamic require of "'+e+'" is not supported')});var z=(e,t)=>{var a={};for(var o in e)P.call(e,o)&&t.indexOf(o)<0&&(a[o]=e[o]);if(e!=null&&D)for(var o of D(e))t.indexOf(o)<0&&V.call(e,o)&&(a[o]=e[o]);return a};var b=(e,t,a)=>new Promise((o,i)=>{var n=l=>{try{s(a.next(l))}catch(d){i(d)}},r=l=>{try{s(a.throw(l))}catch(d){i(d)}},s=l=>l.done?o(l.value):Promise.resolve(l.value).then(n,r);s((a=a.apply(e,t)).next())});import{Command as Se}from"commander";import"dotenv/config";import{Command as Be}from"commander";import{loadConfig as G}from"c12";import{createConsola as de}from"consola";var T=de({formatOptions:{date:!1,colors:!0,compact:!0},defaults:{tag:"Better Auth"}}),ce=e=>({log:(...t)=>{!(e!=null&&e.disabled)&&T.log("",...t)},error:(...t)=>{!(e!=null&&e.disabled)&&T.error("",...t)},warn:(...t)=>{!(e!=null&&e.disabled)&&T.warn("",...t)},info:(...t)=>{!(e!=null&&e.disabled)&&T.info("",...t)},debug:(...t)=>{!(e!=null&&e.disabled)&&T.debug("",...t)},box:(...t)=>{!(e!=null&&e.disabled)&&T.box("",...t)},success:(...t)=>{!(e!=null&&e.disabled)&&T.success("",...t)},break:(...t)=>{!(e!=null&&e.disabled)&&console.log(`
|
|
3
|
+
`)}}),m=ce();import ue from"path";import me from"@babel/preset-typescript";import fe from"@babel/preset-react";var q=["auth.ts","auth.tsx"];q=[...q,...q.map(e=>`lib/${e}`),...q.map(e=>`utils/${e}`)];q=[...q,...q.map(e=>`src/${e}`)];var W={transformOptions:{babel:{presets:[[me,{isTSX:!0,allExtensions:!0}],[fe,{runtime:"automatic"}]]}},extensions:[".ts",".tsx",".js",".jsx"]};function N(a){return b(this,arguments,function*({cwd:e,configPath:t}){var o,i,n,r;try{let s=null;if(t){let{config:l}=yield G({configFile:ue.join(e,t),dotenv:!0,jitiOptions:W});!l.auth&&!l.default&&(m.error("[#better-auth]: Couldn't read your auth config. Make sure to default export your auth instance or to export as a variable named auth."),process.exit(1)),s=((o=l.auth)==null?void 0:o.options)||((i=l.default)==null?void 0:i.options)||null}if(!s)for(let l of q)try{let{config:d}=yield G({configFile:l,jitiOptions:W});if(Object.keys(d).length>0){s=((n=d.auth)==null?void 0:n.options)||((r=d.default)==null?void 0:r.options)||null,s||(m.error("[#better-auth]: Couldn't read your auth config."),m.break(),m.info("[#better-auth]: Make sure to default export your auth instance or to export as a variable named auth."),process.exit(1));break}}catch(d){m.error(d),process.exit(1)}return s}catch(s){m.error("Error while reading your auth config.",s),process.exit(1)}})}import{z as v}from"zod";import{existsSync as Fe}from"fs";import ke from"path";import{Kysely as pe}from"kysely";import{MysqlDialect as U,PostgresDialect as X,SqliteDialect as _}from"kysely";import{createPool as ye}from"mysql2";import he from"pg";var O=class extends Error{constructor(t,a,o){super(t),this.name="BetterAuthError",this.message=t,this.cause=a}};var{Pool:be}=he,ge=e=>{var a,o;if(!e.database)return;if("createDriver"in e.database)return e.database;let t;if("provider"in e.database){let i=e.database.provider,n=(o=(a=e.database)==null?void 0:a.url)==null?void 0:o.trim();if(i==="postgres"&&(t=new X({pool:new be({connectionString:n})})),i==="mysql")try{let r=new URL(n),s=ye({host:r.hostname,user:r.username,password:r.password,database:r.pathname.split("/")[1],port:Number(r.port)});t=new U({pool:s})}catch(r){if(r instanceof TypeError)throw new O("Invalid database URL")}if(i==="sqlite"){let r=le("better-sqlite3"),s=new r(n);t=new _({database:s})}}return t},F=e=>{let t=ge(e);return t&&new pe({dialect:t})},C=e=>{if("provider"in e.database)return e.database.provider;if("dialect"in e.database){if(e.database.dialect instanceof X)return"postgres";if(e.database.dialect instanceof U)return"mysql";if(e.database.dialect instanceof _)return"sqlite"}return"sqlite"};import De from"ora";import M from"chalk";import Ne from"prompts";import"kysely";var j=e=>{var l,d,u,p,y,A;let t=(l=e.plugins)==null?void 0:l.reduce((g,f)=>{var x;let w=f.schema;if(!w)return g;for(let[$,oe]of Object.entries(w))g[$]={fields:h(h({},(x=g[$])==null?void 0:x.fields),oe.fields),tableName:$};return g},{}),a=((d=e.rateLimit)==null?void 0:d.storage)==="database",o={rateLimit:{tableName:((u=e.rateLimit)==null?void 0:u.tableName)||"rateLimit",fields:{key:{type:"string"},count:{type:"number"},lastRequest:{type:"number"}}}},c=t||{},{user:i,session:n,account:r}=c,s=z(c,["user","session","account"]);return h(h({user:{tableName:((p=e.user)==null?void 0:p.modelName)||"user",fields:h({name:{type:"string",required:!0},email:{type:"string",unique:!0,required:!0},emailVerified:{type:"boolean",defaultValue:()=>!1,required:!0},image:{type:"string",required:!1},createdAt:{type:"date",defaultValue:()=>new Date,required:!0},updatedAt:{type:"date",defaultValue:()=>new Date,required:!0}},i==null?void 0:i.fields),order:0},session:{tableName:((y=e.session)==null?void 0:y.modelName)||"session",fields:h({expiresAt:{type:"date",required:!0},ipAddress:{type:"string",required:!1},userAgent:{type:"string",required:!1},userId:{type:"string",references:{model:"user",field:"id",onDelete:"cascade"},required:!0}},n==null?void 0:n.fields),order:1},account:{tableName:((A=e.account)==null?void 0:A.modelName)||"account",fields:h({accountId:{type:"string",required:!0},providerId:{type:"string",required:!0},userId:{type:"string",references:{model:"user",field:"id",onDelete:"cascade"},required:!0},accessToken:{type:"string",required:!1},refreshToken:{type:"string",required:!1},idToken:{type:"string",required:!1},expiresAt:{type:"date",required:!1},password:{type:"string",required:!1}},r==null?void 0:r.fields),order:2}},s),a?o:{})};function Ae(e){var a;return((a=e.plugins)==null?void 0:a.flatMap(o=>Object.keys(o.schema||{}).map(i=>{let r=(o.schema||{})[i];if(!(r!=null&&r.disableMigration))return{tableName:i,fields:r==null?void 0:r.fields}}).filter(i=>i!==void 0)))||[]}function H(e){let t=j(e),a=Ae(e);return[t.user,t.session,t.account,...a].reduce((i,n)=>{var r;return i[n.tableName]={fields:h(h({},(r=i[n.tableName])==null?void 0:r.fields),n.fields)},i},{})}var we={string:["character varying","text"],number:["int4","integer","bigint","smallint","numeric","real","double precision"],boolean:["bool","boolean"],date:["timestamp","date"]},xe={string:["varchar","text"],number:["integer","int","bigint","smallint","decimal","float","double"],boolean:["boolean"],date:["date","datetime"]},qe={string:["TEXT"],number:["INTEGER","REAL"],boolean:["INTEGER","BOOLEAN"],date:["DATE","INTEGER"]},Te={postgres:we,mysql:xe,sqlite:qe};function Oe(e,t,a){return Te[a][t].map(r=>r.toLowerCase()).includes(e.toLowerCase())}function S(e){return b(this,null,function*(){let t=H(e),a=C(e),o=F(e);o||(m.error("Invalid database configuration."),process.exit(1));let i=yield o.introspection.getTables(),n=[],r=[];for(let[c,p]of Object.entries(t)){let y=i.find(g=>g.name===c);if(!y){let g=n.findIndex(x=>x.table===c),f={table:c,fields:p.fields,order:p.order||1/0},w=n.findIndex(x=>(x.order||1/0)>f.order);w===-1?g===-1?n.push(f):n[g].fields=h(h({},n[g].fields),p.fields):n.splice(w,0,f);continue}let A={};for(let[g,f]of Object.entries(p.fields)){let w=y.columns.find(x=>x.name===g);if(!w){A[g]=f;continue}Oe(w.dataType,f.type,a)||m.warn(`Field ${g} in table ${c} has a different type in the database. Expected ${f.type} but got ${w.dataType}.`)}Object.keys(A).length>0&&r.push({table:c,fields:A,order:p.order||1/0})}let s=[];function l(c){let p={string:"text",boolean:"boolean",number:"integer",date:"date"};return a==="mysql"&&c==="string"?"varchar(255)":p[c]}if(r.length)for(let c of r)for(let[p,y]of Object.entries(c.fields)){let A=l(y.type),g=o.schema.alterTable(c.table).addColumn(p,A,f=>(f=y.required!==!1?f.notNull():f,y.references&&(f=f.references(`${y.references.model}.${y.references.field}`)),f));s.push(g)}if(n.length)for(let c of n){let p=o.schema.createTable(c.table).addColumn("id",l("string"),y=>y.primaryKey());for(let[y,A]of Object.entries(c.fields)){let g=l(A.type);p=p.addColumn(y,g,f=>(f=A.required!==!1?f.notNull():f,A.references&&(f=f.references(`${A.references.model}.${A.references.field}`)),A.unique&&(f=f.unique()),f))}s.push(p)}function d(){return b(this,null,function*(){for(let c of s)yield c.execute()})}function u(){return b(this,null,function*(){return s.map(p=>p.compile().sql).join(`;
|
|
4
|
+
|
|
5
|
+
`)})}return{toBeCreated:n,toBeAdded:r,runMigrations:d,compileMigrations:u}})}var J=new Be("migrate").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("--config <config>","the path to the configuration file. defaults to the first configuration file found.").option("--y","").action(e=>b(void 0,null,function*(){let t=v.object({cwd:v.string(),config:v.string().optional()}).parse(e),a=ke.resolve(t.cwd);Fe(a)||(m.error(`The directory "${a}" does not exist.`),process.exit(1));let o=yield N({cwd:a,configPath:t.config});if(!o){m.error("No configuration file found. Add a `auth.ts` file to your project or pass the path to the configuration file using the `--config` flag.");return}F(o)||(m.error("Invalid database configuration."),process.exit(1));let n=De("preparing migration...").start(),{toBeAdded:r,toBeCreated:s,runMigrations:l}=yield S(o);!r.length&&!s.length&&(n.stop(),m.success("\u{1F680} No migrations needed."),process.exit(0)),n.stop(),m.info("\u{1F511} The migration will affect the following:");for(let u of[...s,...r])m.info("->",M.magenta(Object.keys(u.fields).join(", ")),M.white("fields on"),M.yellow(`${u.table}`),M.white("table."));let{migrate:d}=yield Ne({type:"confirm",name:"migrate",message:"Are you sure you want to run these migrations?",initial:!1});d||(m.info("Migration cancelled."),process.exit(0)),n==null||n.start("migrating..."),yield l(),n.stop(),m.success("\u{1F680} migration was completed successfully!"),process.exit(0)}));import{Command as Ce}from"commander";import{z as E}from"zod";import{existsSync as ee}from"fs";import B from"path";import je from"ora";import te from"prompts";function R(e){if(!e)return{and:null,or:null};let t=e==null?void 0:e.filter(o=>o.connector==="AND"||!o.connector).reduce((o,i)=>k(h({},o),{[i.field]:i.value}),{}),a=e==null?void 0:e.filter(o=>o.connector==="OR").reduce((o,i)=>k(h({},o),{[i.field]:i.value}),{});return{and:Object.keys(t).length?t:null,or:Object.keys(a).length?a:null}}function I(e,t,a){var o,i,n;for(let r in e)e[r]===0&&((o=t[r])==null?void 0:o.type)==="boolean"&&(a!=null&&a.boolean)&&(e[r]=!1),e[r]===1&&((i=t[r])==null?void 0:i.type)==="boolean"&&(a!=null&&a.boolean)&&(e[r]=!0),((n=t[r])==null?void 0:n.type)==="date"&&(e[r]instanceof Date||(e[r]=new Date(e[r])));return e}function Q(e,t){for(let a in e)typeof e[a]=="boolean"&&(t!=null&&t.boolean)&&(e[a]=e[a]?1:0),e[a]instanceof Date&&(e[a]=e[a].toISOString());return e}var Y=(e,t)=>({id:"kysely",create(o){return b(this,null,function*(){let{model:i,data:n,select:r}=o;t!=null&&t.transform&&(n=Q(n,t.transform));let s=yield e.insertInto(i).values(n).returningAll().executeTakeFirst();if(t!=null&&t.transform){let l=t.transform.schema[i];s=l?I(n,l,t.transform):s}return r!=null&&r.length&&(s=s?r.reduce((d,u)=>s!=null&&s[u]?k(h({},d),{[u]:s[u]}):d,{}):null),s})},findOne(o){return b(this,null,function*(){let{model:i,where:n,select:r}=o,{and:s,or:l}=R(n),d=e.selectFrom(i).selectAll();l&&(d=d.where(c=>c.or(l))),s&&(d=d.where(c=>c.and(s)));let u=yield d.executeTakeFirst();if(r!=null&&r.length&&(u=u?r.reduce((p,y)=>u!=null&&u[y]?k(h({},p),{[y]:u[y]}):p,{}):null),t!=null&&t.transform){let c=t.transform.schema[i];return u=u&&c?I(u,c,t.transform):u,u||null}return u||null})},findMany(o){return b(this,null,function*(){let{model:i,where:n}=o,r=e.selectFrom(i),{and:s,or:l}=R(n);s&&(r=r.where(u=>u.and(s))),l&&(r=r.where(u=>u.or(l)));let d=yield r.selectAll().execute();if(t!=null&&t.transform){let u=t.transform.schema[i];return u?d.map(c=>I(c,u,t.transform)):d}return d})},update(o){return b(this,null,function*(){let{model:i,where:n,update:r}=o,{and:s,or:l}=R(n);t!=null&&t.transform&&(r=Q(r,t.transform));let d=e.updateTable(i).set(r);s&&(d=d.where(c=>c.and(s))),l&&(d=d.where(c=>c.or(l)));let u=(yield d.returningAll().executeTakeFirst())||null;if(t!=null&&t.transform){let c=t.transform.schema[i];return c?I(u,c,t.transform):u}return u})},delete(o){return b(this,null,function*(){let{model:i,where:n}=o,{and:r,or:s}=R(n),l=e.deleteFrom(i);r&&(l=l.where(d=>d.and(r))),s&&(l=l.where(d=>d.or(s))),yield l.execute()})},createSchema(o){return b(this,null,function*(){let{compileMigrations:i}=yield S(o);return console.log(i),{code:yield i(),fileName:`./better-auth_migrations/${new Date().toISOString()}.sql`}})}});function Z(e){if(!e.database)throw new O("Database configuration is required");if("create"in e.database)return e.database;let t=F(e);if(!t)throw new O("Failed to initialize database adapter");let a=j(e),o={};for(let i of Object.values(a))o[i.tableName]=i.fields;return Y(t,{transform:{schema:o,date:!0,boolean:C(e)==="sqlite"}})}import L from"fs/promises";import re from"chalk";var ae=new Ce("generate").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("--config <config>","the path to the configuration file. defaults to the first configuration file found.").option("--out <output>","the file to output to the generated schema").option("--y","").action(e=>b(void 0,null,function*(){let t=E.object({cwd:E.string(),config:E.string().optional(),out:E.string().optional()}).parse(e),a=B.resolve(t.cwd);ee(a)||(m.error(`The directory "${a}" does not exist.`),process.exit(1));let o=yield N({cwd:a,configPath:t.config});if(!o){m.error("No configuration file found. Add a `auth.ts` file to your project or pass the path to the configuration file using the `--config` flag.");return}let i=Z(o);i.createSchema||(m.error("The adapter does not support schema generation."),process.exit(1));let n=je("preparing schema...").start(),{code:r,fileName:s,append:l}=yield i.createSchema(o,t.out);if(n.stop(),l){let{append:c}=yield te({type:"confirm",name:"append",message:`The file ${s} already exists. Do you want to ${re.yellow("append")} the schema to the file?`});c?(yield L.appendFile(B.join(a,s),r),m.success("\u{1F680} schema was appended successfully!"),process.exit(0)):(m.error("Schema generation aborted."),process.exit(1))}let{confirm:d}=yield te({type:"confirm",name:"confirm",message:`Do you want to generate the schema to ${re.yellow(s)}?`});d||(m.error("Schema generation aborted."),process.exit(1)),ee(B.dirname(B.join(a,s)))||(yield L.mkdir(B.dirname(B.join(a,s)),{recursive:!0})),yield L.writeFile(t.out||B.join(a,s),r),m.success("\u{1F680} schema was generated successfully!"),process.exit(0)}));function Me(){return b(this,null,function*(){let e=new Se().name("better-auth");e.addCommand(J).addCommand(ae),e.parse()})}Me();
|
package/dist/client/plugins.d.ts
CHANGED
|
@@ -2,17 +2,15 @@ import * as nanostores from 'nanostores';
|
|
|
2
2
|
import { A as AccessControl, S as StatementsPrimitive, R as Role } from '../statement-CU-fdHXK.js';
|
|
3
3
|
import * as _better_fetch_fetch from '@better-fetch/fetch';
|
|
4
4
|
import { BetterFetchOption } from '@better-fetch/fetch';
|
|
5
|
-
import { o as organization, d as Organization, M as Member, I as Invitation, u as username, m as magicLink } from '../index-
|
|
6
|
-
export { g as getPasskeyActions, c as passkeyClient, a as twoFactorClient } from '../index-
|
|
5
|
+
import { o as organization, d as Organization, M as Member, I as Invitation, u as username, m as magicLink } from '../index-3B6zGicM.js';
|
|
6
|
+
export { g as getPasskeyActions, c as passkeyClient, a as twoFactorClient } from '../index-3B6zGicM.js';
|
|
7
7
|
import { P as Prettify } from '../helper-C1ihmerM.js';
|
|
8
|
-
import '../
|
|
8
|
+
import '../index-CE92ti2Z.js';
|
|
9
|
+
import 'arctic';
|
|
9
10
|
import 'zod';
|
|
10
11
|
import 'better-call';
|
|
11
|
-
import '../index-
|
|
12
|
+
import '../index-BMYcrOqA.js';
|
|
12
13
|
import 'kysely';
|
|
13
|
-
import '../social.js';
|
|
14
|
-
import 'arctic';
|
|
15
|
-
import '../adapter-D-m9-hQp.js';
|
|
16
14
|
import '@simplewebauthn/types';
|
|
17
15
|
|
|
18
16
|
interface OrganizationClientOptions {
|
package/dist/client.d.ts
CHANGED
|
@@ -3,16 +3,14 @@ import * as nanostores from 'nanostores';
|
|
|
3
3
|
import { PreinitializedWritableAtom } from 'nanostores';
|
|
4
4
|
import * as _better_fetch_fetch from '@better-fetch/fetch';
|
|
5
5
|
import { BetterFetch, BetterFetchError, BetterFetchOption } from '@better-fetch/fetch';
|
|
6
|
-
import { B as BetterAuthPlugin, F as FieldAttribute, I as InferFieldOutput } from './index-
|
|
6
|
+
import { B as BetterAuthPlugin, F as FieldAttribute, I as InferFieldOutput } from './index-BMYcrOqA.js';
|
|
7
7
|
import { U as UnionToIntersection, P as Prettify } from './helper-C1ihmerM.js';
|
|
8
8
|
import { ClientOptions, InferClientAPI, InferActions, BetterAuthClientPlugin, InferSessionFromClient, InferUserFromClient, IsSignal } from './types.js';
|
|
9
9
|
export { AtomListener, InferPluginsFromClient } from './types.js';
|
|
10
10
|
import 'kysely';
|
|
11
|
-
import './
|
|
12
|
-
import 'better-call';
|
|
13
|
-
import './social.js';
|
|
11
|
+
import './index-CE92ti2Z.js';
|
|
14
12
|
import 'arctic';
|
|
15
|
-
import '
|
|
13
|
+
import 'better-call';
|
|
16
14
|
|
|
17
15
|
type InferResolvedHooks<O extends ClientOptions> = O["plugins"] extends Array<infer Plugin> ? Plugin extends BetterAuthClientPlugin ? Plugin["getAtoms"] extends (fetch: any) => infer Atoms ? Atoms extends Record<string, any> ? {
|
|
18
16
|
[key in keyof Atoms as IsSignal<key> extends true ? never : key extends string ? `use${Capitalize<key>}` : never]: Atoms[key];
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { U as User, S as Session } from './
|
|
1
|
+
import { U as User, S as Session } from './index-CE92ti2Z.js';
|
|
2
2
|
import * as better_call from 'better-call';
|
|
3
3
|
import { z, ZodObject, ZodOptional, ZodArray, ZodLiteral } from 'zod';
|
|
4
4
|
import { P as Prettify } from './helper-C1ihmerM.js';
|
|
5
5
|
import { A as AccessControl, R as Role, S as StatementsPrimitive, g as defaultRoles } from './statement-CU-fdHXK.js';
|
|
6
6
|
import * as _better_fetch_fetch from '@better-fetch/fetch';
|
|
7
7
|
import { BetterFetch, BetterFetchOption } from '@better-fetch/fetch';
|
|
8
|
-
import { H as HookEndpointContext } from './index-
|
|
8
|
+
import { H as HookEndpointContext } from './index-BMYcrOqA.js';
|
|
9
9
|
import * as nanostores from 'nanostores';
|
|
10
10
|
import { atom } from 'nanostores';
|
|
11
11
|
import * as _simplewebauthn_types from '@simplewebauthn/types';
|
|
@@ -2357,6 +2357,7 @@ declare const organization: <O extends OrganizationOptions>(options?: O) => {
|
|
|
2357
2357
|
fields: {
|
|
2358
2358
|
name: {
|
|
2359
2359
|
type: "string";
|
|
2360
|
+
required: true;
|
|
2360
2361
|
};
|
|
2361
2362
|
slug: {
|
|
2362
2363
|
type: "string";
|
|
@@ -2430,6 +2431,7 @@ declare const organization: <O extends OrganizationOptions>(options?: O) => {
|
|
|
2430
2431
|
model: string;
|
|
2431
2432
|
field: string;
|
|
2432
2433
|
};
|
|
2434
|
+
required: true;
|
|
2433
2435
|
};
|
|
2434
2436
|
};
|
|
2435
2437
|
};
|
|
@@ -4009,6 +4011,7 @@ declare const passkey: (options?: PasskeyOptions) => {
|
|
|
4009
4011
|
};
|
|
4010
4012
|
publicKey: {
|
|
4011
4013
|
type: "string";
|
|
4014
|
+
required: true;
|
|
4012
4015
|
};
|
|
4013
4016
|
userId: {
|
|
4014
4017
|
type: "string";
|
|
@@ -4016,18 +4019,23 @@ declare const passkey: (options?: PasskeyOptions) => {
|
|
|
4016
4019
|
model: string;
|
|
4017
4020
|
field: string;
|
|
4018
4021
|
};
|
|
4022
|
+
required: true;
|
|
4019
4023
|
};
|
|
4020
4024
|
webauthnUserID: {
|
|
4021
4025
|
type: "string";
|
|
4026
|
+
required: true;
|
|
4022
4027
|
};
|
|
4023
4028
|
counter: {
|
|
4024
4029
|
type: "number";
|
|
4030
|
+
required: true;
|
|
4025
4031
|
};
|
|
4026
4032
|
deviceType: {
|
|
4027
4033
|
type: "string";
|
|
4034
|
+
required: true;
|
|
4028
4035
|
};
|
|
4029
4036
|
backedUp: {
|
|
4030
4037
|
type: "boolean";
|
|
4038
|
+
required: true;
|
|
4031
4039
|
};
|
|
4032
4040
|
transports: {
|
|
4033
4041
|
type: "string";
|
|
@@ -1,14 +1,75 @@
|
|
|
1
1
|
import * as kysely from 'kysely';
|
|
2
2
|
import { Kysely, Migration, Dialect } from 'kysely';
|
|
3
|
-
import { U as User, A as Account,
|
|
3
|
+
import { S as Session, U as User, A as Account, O as OAuthProvider, a as AppleProfile, D as DiscordProfile, F as FacebookProfile, G as GithubProfile, b as GoogleProfile, c as SpotifyProfile, T as TwitchProfile, d as TwitterProfile, e as SocialProviders, f as OAuthProviderList } from './index-CE92ti2Z.js';
|
|
4
4
|
import * as better_call from 'better-call';
|
|
5
5
|
import { ContextTools, CookieOptions, Endpoint, EndpointResponse, Context, Prettify as Prettify$1 } from 'better-call';
|
|
6
6
|
import * as zod from 'zod';
|
|
7
7
|
import { ZodSchema, z } from 'zod';
|
|
8
8
|
import { L as LiteralString, U as UnionToIntersection, P as Prettify } from './helper-C1ihmerM.js';
|
|
9
|
-
import { OAuthProvider, AppleProfile, DiscordProfile, FacebookProfile, GithubProfile, GoogleProfile, SpotifyProfile, TwitchProfile, TwitterProfile, SocialProviders, OAuthProviderList } from './social.js';
|
|
10
9
|
import * as arctic from 'arctic';
|
|
11
|
-
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Adapter where clause
|
|
13
|
+
*/
|
|
14
|
+
type Where = {
|
|
15
|
+
operator?: "eq" | "ne" | "lt" | "lte" | "gt" | "gte";
|
|
16
|
+
value: string;
|
|
17
|
+
field: string;
|
|
18
|
+
connector?: "AND" | "OR";
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Adapter Interface
|
|
22
|
+
*/
|
|
23
|
+
interface Adapter {
|
|
24
|
+
id: string;
|
|
25
|
+
create: <T, R = T>(data: {
|
|
26
|
+
model: string;
|
|
27
|
+
data: T;
|
|
28
|
+
select?: string[];
|
|
29
|
+
}) => Promise<R>;
|
|
30
|
+
findOne: <T>(data: {
|
|
31
|
+
model: string;
|
|
32
|
+
where: Where[];
|
|
33
|
+
select?: string[];
|
|
34
|
+
}) => Promise<T | null>;
|
|
35
|
+
findMany: <T>(data: {
|
|
36
|
+
model: string;
|
|
37
|
+
where?: Where[];
|
|
38
|
+
}) => Promise<T[]>;
|
|
39
|
+
update: <T>(data: {
|
|
40
|
+
model: string;
|
|
41
|
+
where: Where[];
|
|
42
|
+
update: Record<string, any>;
|
|
43
|
+
}) => Promise<T | null>;
|
|
44
|
+
delete: <T>(data: {
|
|
45
|
+
model: string;
|
|
46
|
+
where: Where[];
|
|
47
|
+
}) => Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
*
|
|
50
|
+
* @param options
|
|
51
|
+
* @param file - file path if provided by the user
|
|
52
|
+
* @returns
|
|
53
|
+
*/
|
|
54
|
+
createSchema?: (options: BetterAuthOptions, file?: string) => Promise<{
|
|
55
|
+
code: string;
|
|
56
|
+
fileName: string;
|
|
57
|
+
append?: boolean;
|
|
58
|
+
}>;
|
|
59
|
+
}
|
|
60
|
+
interface SessionAdapter {
|
|
61
|
+
create: (data: {
|
|
62
|
+
userId: string;
|
|
63
|
+
expiresAt: Date;
|
|
64
|
+
}) => Promise<Session>;
|
|
65
|
+
findOne: (data: {
|
|
66
|
+
userId: string;
|
|
67
|
+
}) => Promise<Session | null>;
|
|
68
|
+
update: (data: Session) => Promise<Session>;
|
|
69
|
+
delete: (data: {
|
|
70
|
+
sessionId: string;
|
|
71
|
+
}) => Promise<void>;
|
|
72
|
+
}
|
|
12
73
|
|
|
13
74
|
declare const createInternalAdapter: (adapter: Adapter, options: BetterAuthOptions) => {
|
|
14
75
|
createOAuthUser: (user: User, account: Account) => Promise<{
|
|
@@ -225,115 +286,13 @@ type RequiredKeysOf<BaseType extends object> = Exclude<{
|
|
|
225
286
|
}[keyof BaseType], undefined>;
|
|
226
287
|
type HasRequiredKeys<BaseType extends object> = RequiredKeysOf<BaseType> extends never ? false : true;
|
|
227
288
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
count: {
|
|
236
|
-
type: "number";
|
|
237
|
-
};
|
|
238
|
-
lastRequest: {
|
|
239
|
-
type: "number";
|
|
240
|
-
};
|
|
241
|
-
};
|
|
242
|
-
} | undefined;
|
|
243
|
-
user: {
|
|
244
|
-
tableName: string;
|
|
245
|
-
fields: {
|
|
246
|
-
name: {
|
|
247
|
-
type: "string";
|
|
248
|
-
};
|
|
249
|
-
email: {
|
|
250
|
-
type: "string";
|
|
251
|
-
};
|
|
252
|
-
emailVerified: {
|
|
253
|
-
type: "boolean";
|
|
254
|
-
defaultValue: () => false;
|
|
255
|
-
};
|
|
256
|
-
image: {
|
|
257
|
-
type: "string";
|
|
258
|
-
required: false;
|
|
259
|
-
};
|
|
260
|
-
createdAt: {
|
|
261
|
-
type: "date";
|
|
262
|
-
defaultValue: () => Date;
|
|
263
|
-
};
|
|
264
|
-
updatedAt: {
|
|
265
|
-
type: "date";
|
|
266
|
-
defaultValue: () => Date;
|
|
267
|
-
};
|
|
268
|
-
};
|
|
269
|
-
order: number;
|
|
270
|
-
};
|
|
271
|
-
session: {
|
|
272
|
-
tableName: string;
|
|
273
|
-
fields: {
|
|
274
|
-
expiresAt: {
|
|
275
|
-
type: "date";
|
|
276
|
-
};
|
|
277
|
-
ipAddress: {
|
|
278
|
-
type: "string";
|
|
279
|
-
required: false;
|
|
280
|
-
};
|
|
281
|
-
userAgent: {
|
|
282
|
-
type: "string";
|
|
283
|
-
required: false;
|
|
284
|
-
};
|
|
285
|
-
userId: {
|
|
286
|
-
type: "string";
|
|
287
|
-
references: {
|
|
288
|
-
model: string;
|
|
289
|
-
field: string;
|
|
290
|
-
onDelete: "cascade";
|
|
291
|
-
};
|
|
292
|
-
};
|
|
293
|
-
};
|
|
294
|
-
order: number;
|
|
295
|
-
};
|
|
296
|
-
account: {
|
|
297
|
-
tableName: string;
|
|
298
|
-
fields: {
|
|
299
|
-
accountId: {
|
|
300
|
-
type: "string";
|
|
301
|
-
};
|
|
302
|
-
providerId: {
|
|
303
|
-
type: "string";
|
|
304
|
-
};
|
|
305
|
-
userId: {
|
|
306
|
-
type: "string";
|
|
307
|
-
references: {
|
|
308
|
-
model: string;
|
|
309
|
-
field: string;
|
|
310
|
-
onDelete: "cascade";
|
|
311
|
-
};
|
|
312
|
-
};
|
|
313
|
-
accessToken: {
|
|
314
|
-
type: "string";
|
|
315
|
-
required: false;
|
|
316
|
-
};
|
|
317
|
-
refreshToken: {
|
|
318
|
-
type: "string";
|
|
319
|
-
required: false;
|
|
320
|
-
};
|
|
321
|
-
idToken: {
|
|
322
|
-
type: "string";
|
|
323
|
-
required: false;
|
|
324
|
-
};
|
|
325
|
-
expiresAt: {
|
|
326
|
-
type: "date";
|
|
327
|
-
required: false;
|
|
328
|
-
};
|
|
329
|
-
password: {
|
|
330
|
-
type: "string";
|
|
331
|
-
required: false;
|
|
332
|
-
};
|
|
333
|
-
};
|
|
334
|
-
order: number;
|
|
335
|
-
};
|
|
336
|
-
};
|
|
289
|
+
type BetterAuthDbSchema = Record<string, {
|
|
290
|
+
tableName: string;
|
|
291
|
+
fields: Record<string, FieldAttribute>;
|
|
292
|
+
disableMigrations?: boolean;
|
|
293
|
+
order?: number;
|
|
294
|
+
}>;
|
|
295
|
+
declare const getAuthTables: (options: BetterAuthOptions) => BetterAuthDbSchema;
|
|
337
296
|
|
|
338
297
|
declare function getAdapter(options: BetterAuthOptions): Adapter;
|
|
339
298
|
|
|
@@ -5421,4 +5380,4 @@ type Auth = {
|
|
|
5421
5380
|
options: BetterAuthOptions;
|
|
5422
5381
|
};
|
|
5423
5382
|
|
|
5424
|
-
export {
|
|
5383
|
+
export { ok as $, type AuthEndpoint as A, type BetterAuthPlugin as B, getSessionFromCtx as C, sessionMiddleware as D, listSessions as E, type FieldAttribute as F, type GenericEndpointContext as G, type HookEndpointContext as H, type InferFieldOutput as I, revokeSession as J, revokeSessions as K, signOut as L, forgetPassword as M, forgetPasswordCallback as N, resetPassword as O, type PluginSchema as P, createEmailVerificationToken as Q, type RateLimit as R, type SessionAdapter as S, sendVerificationEmail as T, verifyEmail as U, updateUser as V, type Where as W, changePassword as X, setPassword as Y, getCSRFToken as Z, error as _, createAuthEndpoint as a, signUpEmail as a0, csrfMiddleware as a1, betterAuth as a2, type AuthMiddleware as b, createAuthMiddleware as c, type Auth as d, type BetterAuthOptions as e, type Adapter as f, type AuthContext as g, getCookies as h, createCookieGetter as i, type BetterAuthCookies as j, deleteSessionCookie as k, createLogger as l, logger as m, type InferSession as n, optionsMiddleware as o, parseSetCookieHeader as p, type InferUser as q, type InferPluginTypes as r, setSessionCookie as s, init as t, getEndpoints as u, router as v, signInOAuth as w, signInEmail as x, callbackOAuth as y, getSession as z };
|