better-auth 0.6.1-beta.9 → 0.6.2-beta.1
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/access.cjs +2 -1
- package/dist/access.cjs.map +1 -0
- package/dist/access.js +2 -1
- package/dist/access.js.map +1 -0
- package/dist/adapters/drizzle.cjs +2 -1
- package/dist/adapters/drizzle.cjs.map +1 -0
- package/dist/adapters/drizzle.js +2 -1
- package/dist/adapters/drizzle.js.map +1 -0
- package/dist/adapters/kysely.cjs +2 -1
- package/dist/adapters/kysely.cjs.map +1 -0
- package/dist/adapters/kysely.js +2 -1
- package/dist/adapters/kysely.js.map +1 -0
- package/dist/adapters/mongodb.cjs +2 -1
- package/dist/adapters/mongodb.cjs.map +1 -0
- package/dist/adapters/mongodb.js +2 -1
- package/dist/adapters/mongodb.js.map +1 -0
- package/dist/adapters/prisma.cjs +2 -1
- package/dist/adapters/prisma.cjs.map +1 -0
- package/dist/adapters/prisma.js +2 -1
- package/dist/adapters/prisma.js.map +1 -0
- package/dist/api.cjs +2 -1
- package/dist/api.cjs.map +1 -0
- package/dist/api.js +2 -1
- package/dist/api.js.map +1 -0
- package/dist/chunk-2BBAB6DP.cjs +2 -0
- package/dist/chunk-2BBAB6DP.cjs.map +1 -0
- package/dist/chunk-3AAEZ2OW.js +2 -0
- package/dist/chunk-3AAEZ2OW.js.map +1 -0
- package/dist/chunk-4C666HHU.js +2 -0
- package/dist/chunk-4C666HHU.js.map +1 -0
- package/dist/chunk-4CFYZITA.cjs +2 -0
- package/dist/chunk-4CFYZITA.cjs.map +1 -0
- package/dist/chunk-4CY5SJAH.js +2 -0
- package/dist/chunk-4CY5SJAH.js.map +1 -0
- package/dist/chunk-4INQICGP.cjs +3 -0
- package/dist/chunk-4INQICGP.cjs.map +1 -0
- package/dist/chunk-4LSFAAZW.js +1 -0
- package/dist/chunk-4LSFAAZW.js.map +1 -0
- package/dist/chunk-4X5O2226.js +2 -0
- package/dist/chunk-4X5O2226.js.map +1 -0
- package/dist/chunk-57KKPQYR.js +2 -0
- package/dist/chunk-57KKPQYR.js.map +1 -0
- package/dist/chunk-5CGFZN2L.cjs +2 -0
- package/dist/chunk-5CGFZN2L.cjs.map +1 -0
- package/dist/chunk-5TFMNJQL.cjs +2 -0
- package/dist/chunk-5TFMNJQL.cjs.map +1 -0
- package/dist/chunk-622ZL6N3.cjs +2 -0
- package/dist/chunk-622ZL6N3.cjs.map +1 -0
- package/dist/chunk-6YSOZOBL.cjs +2 -0
- package/dist/chunk-6YSOZOBL.cjs.map +1 -0
- package/dist/chunk-73SJ5X6L.cjs +2 -0
- package/dist/chunk-73SJ5X6L.cjs.map +1 -0
- package/dist/chunk-7OILVMQO.js +2 -0
- package/dist/chunk-7OILVMQO.js.map +1 -0
- package/dist/chunk-AFA2APLD.js +2 -0
- package/dist/chunk-AFA2APLD.js.map +1 -0
- package/dist/chunk-C57CCQKY.js +2 -0
- package/dist/chunk-C57CCQKY.js.map +1 -0
- package/dist/chunk-CKMZLDAT.js +2 -0
- package/dist/chunk-CKMZLDAT.js.map +1 -0
- package/dist/chunk-CO5UG7AX.js +2 -0
- package/dist/chunk-CO5UG7AX.js.map +1 -0
- package/dist/chunk-DMAK6URH.cjs +2 -0
- package/dist/chunk-DMAK6URH.cjs.map +1 -0
- package/dist/chunk-FUVIWAGV.js +2 -0
- package/dist/chunk-FUVIWAGV.js.map +1 -0
- package/dist/chunk-GFCR6QEP.js +2 -0
- package/dist/chunk-GFCR6QEP.js.map +1 -0
- package/dist/chunk-GNYPEE5I.js +2 -0
- package/dist/chunk-GNYPEE5I.js.map +1 -0
- package/dist/chunk-GOLT3J43.js +2 -0
- package/dist/chunk-GOLT3J43.js.map +1 -0
- package/dist/chunk-H27YSXFM.cjs +2 -0
- package/dist/chunk-H27YSXFM.cjs.map +1 -0
- package/dist/chunk-H5ZHLIW4.cjs +2 -0
- package/dist/chunk-H5ZHLIW4.cjs.map +1 -0
- package/dist/{chunk-IOGBXWDX.js → chunk-HBHHT77G.js} +2 -1
- package/dist/{chunk-CLON6BC7.cjs → chunk-HORVA6HL.cjs} +2 -1
- package/dist/chunk-L3RMKKWR.js +3 -0
- package/dist/chunk-L3RMKKWR.js.map +1 -0
- package/dist/chunk-LE7R2XND.js +4 -0
- package/dist/chunk-LE7R2XND.js.map +1 -0
- package/dist/chunk-LF4SJYGR.cjs +2 -0
- package/dist/chunk-LF4SJYGR.cjs.map +1 -0
- package/dist/chunk-M4G6J7DP.cjs +2 -0
- package/dist/chunk-M4G6J7DP.cjs.map +1 -0
- package/dist/chunk-NZ3R5XBV.cjs +2 -0
- package/dist/chunk-NZ3R5XBV.cjs.map +1 -0
- package/dist/chunk-OQSWDMGG.cjs +2 -0
- package/dist/chunk-OQSWDMGG.cjs.map +1 -0
- package/dist/chunk-OXAT7NHE.js +2 -0
- package/dist/chunk-OXAT7NHE.js.map +1 -0
- package/dist/chunk-PQ5IONW7.cjs +2 -0
- package/dist/chunk-PQ5IONW7.cjs.map +1 -0
- package/dist/chunk-RUHFLVS7.cjs +4 -0
- package/dist/chunk-RUHFLVS7.cjs.map +1 -0
- package/dist/chunk-RW5L5YQV.cjs +2 -0
- package/dist/chunk-RW5L5YQV.cjs.map +1 -0
- package/dist/chunk-S56R3UUZ.js +84 -0
- package/dist/chunk-S56R3UUZ.js.map +1 -0
- package/dist/chunk-T3MCWLBP.cjs +2 -0
- package/dist/chunk-T3MCWLBP.cjs.map +1 -0
- package/dist/chunk-TCHOIK53.cjs +1 -0
- package/dist/chunk-TCHOIK53.cjs.map +1 -0
- package/dist/chunk-TKTXK746.cjs +2 -0
- package/dist/chunk-TKTXK746.cjs.map +1 -0
- package/dist/chunk-TUL3AUOB.js +2 -0
- package/dist/chunk-TUL3AUOB.js.map +1 -0
- package/dist/chunk-U5FXGV3G.cjs +2 -0
- package/dist/chunk-U5FXGV3G.cjs.map +1 -0
- package/dist/chunk-UGP43E4I.cjs +84 -0
- package/dist/chunk-UGP43E4I.cjs.map +1 -0
- package/dist/chunk-UMXT2JXJ.js +2 -0
- package/dist/chunk-UMXT2JXJ.js.map +1 -0
- package/dist/chunk-WNGZ4EQP.cjs +2 -0
- package/dist/chunk-WNGZ4EQP.cjs.map +1 -0
- package/dist/chunk-X25G3YQH.cjs +2 -0
- package/dist/chunk-X25G3YQH.cjs.map +1 -0
- package/dist/chunk-XVQ2OCXP.js +2 -0
- package/dist/chunk-XVQ2OCXP.js.map +1 -0
- package/dist/chunk-XYSHU5WH.js +2 -0
- package/dist/chunk-XYSHU5WH.js.map +1 -0
- package/dist/chunk-YVCL4SNR.js +2 -0
- package/dist/chunk-YVCL4SNR.js.map +1 -0
- package/dist/chunk-ZB5XSQW3.js +2 -0
- package/dist/chunk-ZB5XSQW3.js.map +1 -0
- package/dist/chunk-ZXH7J5K5.js +2 -0
- package/dist/chunk-ZXH7J5K5.js.map +1 -0
- package/dist/chunk-ZZ4X6MII.cjs +2 -0
- package/dist/chunk-ZZ4X6MII.cjs.map +1 -0
- package/dist/client/plugins.cjs +2 -1
- package/dist/client/plugins.cjs.map +1 -0
- package/dist/client/plugins.js +2 -1
- package/dist/client/plugins.js.map +1 -0
- package/dist/client.cjs +2 -1
- package/dist/client.cjs.map +1 -0
- package/dist/client.js +2 -1
- package/dist/client.js.map +1 -0
- package/dist/cookies.cjs +2 -1
- package/dist/cookies.cjs.map +1 -0
- package/dist/cookies.js +2 -1
- package/dist/cookies.js.map +1 -0
- package/dist/crypto.cjs +2 -1
- package/dist/crypto.cjs.map +1 -0
- package/dist/crypto.js +2 -1
- package/dist/crypto.js.map +1 -0
- package/dist/db.cjs +2 -1
- package/dist/db.cjs.map +1 -0
- package/dist/db.js +2 -1
- package/dist/db.js.map +1 -0
- package/dist/index.cjs +2 -1
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -0
- package/dist/next-js.cjs +2 -1
- package/dist/next-js.cjs.map +1 -0
- package/dist/next-js.js +2 -1
- package/dist/next-js.js.map +1 -0
- package/dist/node.cjs +2 -1
- package/dist/node.cjs.map +1 -0
- package/dist/node.js +2 -1
- package/dist/node.js.map +1 -0
- package/dist/oauth2.cjs +2 -1
- package/dist/oauth2.cjs.map +1 -0
- package/dist/oauth2.js +2 -1
- package/dist/oauth2.js.map +1 -0
- package/dist/plugins.cjs +3 -2
- package/dist/plugins.cjs.map +1 -0
- package/dist/plugins.js +2 -1
- package/dist/plugins.js.map +1 -0
- package/dist/react.cjs +2 -1
- package/dist/react.cjs.map +1 -0
- package/dist/react.js +2 -1
- package/dist/react.js.map +1 -0
- package/dist/social.cjs +2 -1
- package/dist/social.cjs.map +1 -0
- package/dist/social.js +2 -1
- package/dist/social.js.map +1 -0
- package/dist/solid-start.cjs +2 -1
- package/dist/solid-start.cjs.map +1 -0
- package/dist/solid-start.js +2 -1
- package/dist/solid-start.js.map +1 -0
- package/dist/solid.cjs +2 -1
- package/dist/solid.cjs.map +1 -0
- package/dist/solid.js +2 -1
- package/dist/solid.js.map +1 -0
- package/dist/svelte-kit.cjs +2 -1
- package/dist/svelte-kit.cjs.map +1 -0
- package/dist/svelte-kit.js +2 -1
- package/dist/svelte-kit.js.map +1 -0
- package/dist/svelte.cjs +2 -1
- package/dist/svelte.cjs.map +1 -0
- package/dist/svelte.js +2 -1
- package/dist/svelte.js.map +1 -0
- package/dist/types.cjs +2 -1
- package/dist/types.cjs.map +1 -0
- package/dist/types.js +2 -1
- package/dist/types.js.map +1 -0
- package/dist/vue.cjs +2 -1
- package/dist/vue.cjs.map +1 -0
- package/dist/vue.js +2 -1
- package/dist/vue.js.map +1 -0
- package/package.json +1 -1
package/dist/access.cjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunk622ZL6N3cjs = require('./chunk-622ZL6N3.cjs');require('./chunk-M4G6J7DP.cjs');exports.AccessControl = _chunk622ZL6N3cjs.b; exports.ParsingError = _chunk622ZL6N3cjs.a; exports.Role = _chunk622ZL6N3cjs.c; exports.adminAc = _chunk622ZL6N3cjs.g; exports.createAccessControl = _chunk622ZL6N3cjs.d; exports.defaultAc = _chunk622ZL6N3cjs.f; exports.defaultRoles = _chunk622ZL6N3cjs.j; exports.defaultStatements = _chunk622ZL6N3cjs.e; exports.memberAc = _chunk622ZL6N3cjs.i; exports.ownerAc = _chunk622ZL6N3cjs.h; exports.permissionFromString = _chunk622ZL6N3cjs.k;
|
|
2
|
+
//# sourceMappingURL=access.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/beka/Desktop/Development/better-auth/packages/better-auth/dist/access.cjs"],"names":[],"mappings":"AAAA,iIAAuD,gCAA6B,+dAA0M","file":"/Users/beka/Desktop/Development/better-auth/packages/better-auth/dist/access.cjs"}
|
package/dist/access.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import{a,b,c,d,e,f,g,h,i,j,k}from"./chunk-
|
|
1
|
+
import{a,b,c,d,e,f,g,h,i,j,k}from"./chunk-ZB5XSQW3.js";import"./chunk-4C666HHU.js";export{b as AccessControl,a as ParsingError,c as Role,g as adminAc,d as createAccessControl,f as defaultAc,j as defaultRoles,e as defaultStatements,i as memberAc,h as ownerAc,k as permissionFromString};
|
|
2
|
+
//# sourceMappingURL=access.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkWNGZ4EQPcjs = require('../chunk-WNGZ4EQP.cjs');require('../chunk-M4G6J7DP.cjs');var _drizzleorm = require('drizzle-orm');function f(t,r){let i=r.schema;if(!i)throw new (0, _chunkWNGZ4EQPcjs.a)("Drizzle adapter failed to initialize. Schema not found. Please provide a schema object in the adapter options object.");let c=r.usePlural?`${t}s`:t,n=i[c];if(!n)throw new (0, _chunkWNGZ4EQPcjs.a)(`[# Drizzle Adapter]: The model "${t}" was not found in the schema object. Please pass the schema directly to the adapter options.`);return n}function m(t,r){if(!t)return[];if(t.length===1){let e=t[0];if(!e)return[];if(e.operator==="in"){if(!Array.isArray(e.value))throw new (0, _chunkWNGZ4EQPcjs.a)(`The value for the field "${e.field}" must be an array when using the "in" operator.`);return[_drizzleorm.inArray.call(void 0, r[e.field],e.value)]}return e.operator==="contains"?[_drizzleorm.like.call(void 0, r[e.field],`%${e.value}%`)]:e.operator==="starts_with"?[_drizzleorm.like.call(void 0, r[e.field],`${e.value}%`)]:e.operator==="ends_with"?[_drizzleorm.like.call(void 0, r[e.field],`%${e.value}`)]:[_drizzleorm.eq.call(void 0, r[e.field],e.value)]}let i=t.filter(e=>e.connector==="AND"||!e.connector),c=t.filter(e=>e.connector==="OR"),n=_drizzleorm.and.call(void 0, ...i.map(e=>{if(e.operator==="in"){if(!Array.isArray(e.value))throw new (0, _chunkWNGZ4EQPcjs.a)(`The value for the field "${e.field}" must be an array when using the "in" operator.`);return _drizzleorm.inArray.call(void 0, r[e.field],e.value)}return _drizzleorm.eq.call(void 0, r[e.field],e.value)})),l=_drizzleorm.or.call(void 0, ...c.map(e=>_drizzleorm.eq.call(void 0, r[e.field],e.value))),s=[];return i.length&&s.push(n),c.length&&s.push(l),s}var S=(t,r)=>{let i=r.schema||t._.fullSchema,c=_optionalChain([r, 'optionalAccess', _2 => _2.provider]);return{id:"drizzle",async create(n){let{model:l,data:s}=n,e=f(l,{schema:i,usePlural:r.usePlural});r.generateId!==void 0&&(s.id=r.generateId?r.generateId():void 0);let a=t.insert(e).values(s);return c!=="mysql"?(await a.returning())[0]:(await a,(await t.select().from(e).where(_drizzleorm.eq.call(void 0, e.id,n.data.id)))[0])},async findOne(n){let{model:l,where:s,select:e}=n,a=f(l,{schema:i,usePlural:r.usePlural}),u=m(s,a),o=null;return _optionalChain([e, 'optionalAccess', _3 => _3.length])?o=await t.select(...e.map(d=>({[d]:a[d]}))).from(a).where(...u):o=await t.select().from(a).where(...u),o.length?o[0]:null},async findMany(n){let{model:l,where:s,limit:e,offset:a,sortBy:u}=n,o=f(l,{schema:i,usePlural:r.usePlural}),d=s?m(s,o):[],g=_optionalChain([u, 'optionalAccess', _4 => _4.direction])==="desc"?_drizzleorm.desc:_drizzleorm.asc;return await t.select().from(o).limit(e||100).offset(a||0).orderBy(g(o[_optionalChain([u, 'optionalAccess', _5 => _5.field])||"id"])).where(...d.length?d:[])},async update(n){let{model:l,where:s,update:e}=n,a=f(l,{schema:i,usePlural:r.usePlural});e.id&&(e.id=void 0);let u=m(s,a),o=t.update(a).set(e).where(...u);return c!=="mysql"?(await o.returning())[0]:(await o,(await t.select().from(a).where(_drizzleorm.eq.call(void 0, a.id,n.update.id)))[0])},async delete(n){let{model:l,where:s}=n,e=f(l,{schema:i,usePlural:r.usePlural}),a=m(s,e);return(await t.delete(e).where(...a))[0]},async deleteMany(n){let{model:l,where:s}=n,e=f(l,{schema:i,usePlural:r.usePlural}),a=m(s,e);await t.delete(e).where(...a)},options:r}};exports.drizzleAdapter = S;
|
|
2
|
+
//# sourceMappingURL=drizzle.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/beka/Desktop/Development/better-auth/packages/better-auth/dist/adapters/drizzle.cjs","../../src/adapters/drizzle-adapter/index.ts"],"names":["getSchema","modelName","options","schema","BetterAuthError","model"],"mappings":"AAAA,soBAAyC,iCAA8B,yCCAZ,SAwBlDA,CAAAA,CACRC,CAAAA,CACAC,CAAAA,CAIC,CACD,IAAMC,CAAAA,CAASD,CAAAA,CAAQ,MAAA,CACvB,EAAA,CAAI,CAACC,CAAAA,CACJ,MAAM,IAAIC,wBAAAA,CACT,uHACD,CAAA,CAED,IAAMC,CAAAA,CAAQH,CAAAA,CAAQ,SAAA,CAAY,CAAA,EAAA","file":"/Users/beka/Desktop/Development/better-auth/packages/better-auth/dist/adapters/drizzle.cjs","sourcesContent":[null,"import { and, asc, desc, eq, or, SQL, inArray, like } from \"drizzle-orm\";\nimport type { Adapter, Where } from \"../../types\";\nimport { BetterAuthError } from \"../../error\";\n\nexport interface DrizzleAdapterOptions {\n\tschema?: Record<string, any>;\n\tprovider: \"pg\" | \"mysql\" | \"sqlite\";\n\t/**\n\t * If the table names in the schema are plural\n\t * set this to true. For example, if the schema\n\t * has an object with a key \"users\" instead of \"user\"\n\t */\n\tusePlural?: boolean;\n\t/**\n\t * Custom generateId function.\n\t *\n\t * If not provided, nanoid will be used.\n\t * If set to false, the database's auto generated id will be used.\n\t *\n\t * @default nanoid\n\t */\n\tgenerateId?: ((size?: number) => string) | false;\n}\n\nfunction getSchema(\n\tmodelName: string,\n\toptions: {\n\t\tschema: Record<string, any>;\n\t\tusePlural?: boolean;\n\t},\n) {\n\tconst schema = options.schema;\n\tif (!schema) {\n\t\tthrow new BetterAuthError(\n\t\t\t\"Drizzle adapter failed to initialize. Schema not found. Please provide a schema object in the adapter options object.\",\n\t\t);\n\t}\n\tconst model = options.usePlural ? `${modelName}s` : modelName;\n\n\tconst schemaModel = schema[model];\n\tif (!schemaModel) {\n\t\tthrow new BetterAuthError(\n\t\t\t`[# Drizzle Adapter]: The model \"${modelName}\" was not found in the schema object. Please pass the schema directly to the adapter options.`,\n\t\t);\n\t}\n\treturn schemaModel;\n}\n\nfunction whereConvertor(where: Where[], schemaModel: any) {\n\tif (!where) return [];\n\tif (where.length === 1) {\n\t\tconst w = where[0];\n\t\tif (!w) {\n\t\t\treturn [];\n\t\t}\n\n\t\tif (w.operator === \"in\") {\n\t\t\tif (!Array.isArray(w.value)) {\n\t\t\t\tthrow new BetterAuthError(\n\t\t\t\t\t`The value for the field \"${w.field}\" must be an array when using the \"in\" operator.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn [inArray(schemaModel[w.field], w.value)];\n\t\t}\n\n\t\tif (w.operator === \"contains\") {\n\t\t\treturn [like(schemaModel[w.field], `%${w.value}%`)];\n\t\t}\n\n\t\tif (w.operator === \"starts_with\") {\n\t\t\treturn [like(schemaModel[w.field], `${w.value}%`)];\n\t\t}\n\n\t\tif (w.operator === \"ends_with\") {\n\t\t\treturn [like(schemaModel[w.field], `%${w.value}`)];\n\t\t}\n\n\t\treturn [eq(schemaModel[w.field], w.value)];\n\t}\n\tconst andGroup = where.filter((w) => w.connector === \"AND\" || !w.connector);\n\tconst orGroup = where.filter((w) => w.connector === \"OR\");\n\n\tconst andClause = and(\n\t\t...andGroup.map((w) => {\n\t\t\tif (w.operator === \"in\") {\n\t\t\t\tif (!Array.isArray(w.value)) {\n\t\t\t\t\tthrow new BetterAuthError(\n\t\t\t\t\t\t`The value for the field \"${w.field}\" must be an array when using the \"in\" operator.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn inArray(schemaModel[w.field], w.value);\n\t\t\t}\n\t\t\treturn eq(schemaModel[w.field], w.value);\n\t\t}),\n\t);\n\tconst orClause = or(\n\t\t...orGroup.map((w) => {\n\t\t\treturn eq(schemaModel[w.field], w.value);\n\t\t}),\n\t);\n\n\tconst clause: SQL<unknown>[] = [];\n\n\tif (andGroup.length) clause.push(andClause!);\n\tif (orGroup.length) clause.push(orClause!);\n\treturn clause;\n}\n\ninterface DB {\n\t[key: string]: any;\n}\n\nexport const drizzleAdapter = (\n\tdb: DB,\n\toptions: DrizzleAdapterOptions,\n): Adapter => {\n\tconst schema = options.schema || db._.fullSchema;\n\tconst databaseType = options?.provider;\n\treturn {\n\t\tid: \"drizzle\",\n\t\tasync create(data) {\n\t\t\tconst { model, data: val } = data;\n\t\t\tconst schemaModel = getSchema(model, {\n\t\t\t\tschema,\n\t\t\t\tusePlural: options.usePlural,\n\t\t\t});\n\t\t\tif (options.generateId !== undefined) {\n\t\t\t\tval.id = options.generateId ? options.generateId() : undefined;\n\t\t\t}\n\n\t\t\tconst mutation = db.insert(schemaModel).values(val);\n\t\t\tif (databaseType !== \"mysql\") return (await mutation.returning())[0];\n\n\t\t\tawait mutation;\n\t\t\tconst res = await db\n\t\t\t\t.select()\n\t\t\t\t.from(schemaModel)\n\t\t\t\t.where(eq(schemaModel.id, (data.data as { id: string }).id));\n\t\t\treturn res[0];\n\t\t},\n\t\tasync findOne(data) {\n\t\t\tconst { model, where, select: included } = data;\n\n\t\t\tconst schemaModel = getSchema(model, {\n\t\t\t\tschema,\n\t\t\t\tusePlural: options.usePlural,\n\t\t\t});\n\n\t\t\tconst wheres = whereConvertor(where, schemaModel);\n\n\t\t\tlet res = null;\n\t\t\tif (!!included?.length) {\n\t\t\t\tres = await db\n\t\t\t\t\t.select(\n\t\t\t\t\t\t...included.map((include) => {\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t[include]: schemaModel[include],\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}),\n\t\t\t\t\t)\n\t\t\t\t\t.from(schemaModel)\n\t\t\t\t\t.where(...wheres);\n\t\t\t} else {\n\t\t\t\tres = await db\n\t\t\t\t\t.select()\n\t\t\t\t\t.from(schemaModel)\n\t\t\t\t\t.where(...wheres);\n\t\t\t}\n\n\t\t\tif (!!res.length) return res[0];\n\t\t\telse return null;\n\t\t},\n\t\tasync findMany(data) {\n\t\t\tconst { model, where, limit, offset, sortBy } = data;\n\t\t\tconst schemaModel = getSchema(model, {\n\t\t\t\tschema,\n\t\t\t\tusePlural: options.usePlural,\n\t\t\t});\n\t\t\tconst filters = where ? whereConvertor(where, schemaModel) : [];\n\t\t\tconst fn = sortBy?.direction === \"desc\" ? desc : asc;\n\t\t\tconst res = await db\n\t\t\t\t.select()\n\t\t\t\t.from(schemaModel)\n\t\t\t\t.limit(limit || 100)\n\t\t\t\t.offset(offset || 0)\n\t\t\t\t.orderBy(fn(schemaModel[sortBy?.field || \"id\"]))\n\t\t\t\t.where(...(filters.length ? filters : []));\n\n\t\t\treturn res;\n\t\t},\n\t\tasync update(data) {\n\t\t\tconst { model, where, update } = data;\n\t\t\tconst schemaModel = getSchema(model, {\n\t\t\t\tschema,\n\t\t\t\tusePlural: options.usePlural,\n\t\t\t});\n\t\t\tif (update.id) {\n\t\t\t\tupdate.id = undefined;\n\t\t\t}\n\t\t\tconst wheres = whereConvertor(where, schemaModel);\n\t\t\tconst mutation = db\n\t\t\t\t.update(schemaModel)\n\t\t\t\t.set(update)\n\t\t\t\t.where(...wheres);\n\t\t\tif (databaseType !== \"mysql\") return (await mutation.returning())[0];\n\n\t\t\tawait mutation;\n\t\t\tconst res = await db\n\t\t\t\t.select()\n\t\t\t\t.from(schemaModel)\n\t\t\t\t.where(eq(schemaModel.id, (data.update as { id: string }).id));\n\t\t\treturn res[0];\n\t\t},\n\t\tasync delete(data) {\n\t\t\tconst { model, where } = data;\n\t\t\tconst schemaModel = getSchema(model, {\n\t\t\t\tschema,\n\t\t\t\tusePlural: options.usePlural,\n\t\t\t});\n\t\t\tconst wheres = whereConvertor(where, schemaModel);\n\t\t\tconst res = await db.delete(schemaModel).where(...wheres);\n\n\t\t\treturn res[0];\n\t\t},\n\t\tasync deleteMany(data) {\n\t\t\tconst { model, where } = data;\n\t\t\tconst schemaModel = getSchema(model, {\n\t\t\t\tschema,\n\t\t\t\tusePlural: options.usePlural,\n\t\t\t});\n\t\t\tconst wheres = whereConvertor(where, schemaModel);\n\t\t\tawait db.delete(schemaModel).where(...wheres);\n\t\t},\n\t\toptions,\n\t};\n};\n"]}
|
package/dist/adapters/drizzle.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import{a as h}from"../chunk-
|
|
1
|
+
import{a as h}from"../chunk-GNYPEE5I.js";import"../chunk-4C666HHU.js";import{and as v,asc as P,desc as z,eq as p,or as A,inArray as y,like as w}from"drizzle-orm";function f(t,r){let i=r.schema;if(!i)throw new h("Drizzle adapter failed to initialize. Schema not found. Please provide a schema object in the adapter options object.");let c=r.usePlural?`${t}s`:t,n=i[c];if(!n)throw new h(`[# Drizzle Adapter]: The model "${t}" was not found in the schema object. Please pass the schema directly to the adapter options.`);return n}function m(t,r){if(!t)return[];if(t.length===1){let e=t[0];if(!e)return[];if(e.operator==="in"){if(!Array.isArray(e.value))throw new h(`The value for the field "${e.field}" must be an array when using the "in" operator.`);return[y(r[e.field],e.value)]}return e.operator==="contains"?[w(r[e.field],`%${e.value}%`)]:e.operator==="starts_with"?[w(r[e.field],`${e.value}%`)]:e.operator==="ends_with"?[w(r[e.field],`%${e.value}`)]:[p(r[e.field],e.value)]}let i=t.filter(e=>e.connector==="AND"||!e.connector),c=t.filter(e=>e.connector==="OR"),n=v(...i.map(e=>{if(e.operator==="in"){if(!Array.isArray(e.value))throw new h(`The value for the field "${e.field}" must be an array when using the "in" operator.`);return y(r[e.field],e.value)}return p(r[e.field],e.value)})),l=A(...c.map(e=>p(r[e.field],e.value))),s=[];return i.length&&s.push(n),c.length&&s.push(l),s}var S=(t,r)=>{let i=r.schema||t._.fullSchema,c=r?.provider;return{id:"drizzle",async create(n){let{model:l,data:s}=n,e=f(l,{schema:i,usePlural:r.usePlural});r.generateId!==void 0&&(s.id=r.generateId?r.generateId():void 0);let a=t.insert(e).values(s);return c!=="mysql"?(await a.returning())[0]:(await a,(await t.select().from(e).where(p(e.id,n.data.id)))[0])},async findOne(n){let{model:l,where:s,select:e}=n,a=f(l,{schema:i,usePlural:r.usePlural}),u=m(s,a),o=null;return e?.length?o=await t.select(...e.map(d=>({[d]:a[d]}))).from(a).where(...u):o=await t.select().from(a).where(...u),o.length?o[0]:null},async findMany(n){let{model:l,where:s,limit:e,offset:a,sortBy:u}=n,o=f(l,{schema:i,usePlural:r.usePlural}),d=s?m(s,o):[],g=u?.direction==="desc"?z:P;return await t.select().from(o).limit(e||100).offset(a||0).orderBy(g(o[u?.field||"id"])).where(...d.length?d:[])},async update(n){let{model:l,where:s,update:e}=n,a=f(l,{schema:i,usePlural:r.usePlural});e.id&&(e.id=void 0);let u=m(s,a),o=t.update(a).set(e).where(...u);return c!=="mysql"?(await o.returning())[0]:(await o,(await t.select().from(a).where(p(a.id,n.update.id)))[0])},async delete(n){let{model:l,where:s}=n,e=f(l,{schema:i,usePlural:r.usePlural}),a=m(s,e);return(await t.delete(e).where(...a))[0]},async deleteMany(n){let{model:l,where:s}=n,e=f(l,{schema:i,usePlural:r.usePlural}),a=m(s,e);await t.delete(e).where(...a)},options:r}};export{S as drizzleAdapter};
|
|
2
|
+
//# sourceMappingURL=drizzle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/adapters/drizzle-adapter/index.ts"],"sourcesContent":["import { and, asc, desc, eq, or, SQL, inArray, like } from \"drizzle-orm\";\nimport type { Adapter, Where } from \"../../types\";\nimport { BetterAuthError } from \"../../error\";\n\nexport interface DrizzleAdapterOptions {\n\tschema?: Record<string, any>;\n\tprovider: \"pg\" | \"mysql\" | \"sqlite\";\n\t/**\n\t * If the table names in the schema are plural\n\t * set this to true. For example, if the schema\n\t * has an object with a key \"users\" instead of \"user\"\n\t */\n\tusePlural?: boolean;\n\t/**\n\t * Custom generateId function.\n\t *\n\t * If not provided, nanoid will be used.\n\t * If set to false, the database's auto generated id will be used.\n\t *\n\t * @default nanoid\n\t */\n\tgenerateId?: ((size?: number) => string) | false;\n}\n\nfunction getSchema(\n\tmodelName: string,\n\toptions: {\n\t\tschema: Record<string, any>;\n\t\tusePlural?: boolean;\n\t},\n) {\n\tconst schema = options.schema;\n\tif (!schema) {\n\t\tthrow new BetterAuthError(\n\t\t\t\"Drizzle adapter failed to initialize. Schema not found. Please provide a schema object in the adapter options object.\",\n\t\t);\n\t}\n\tconst model = options.usePlural ? `${modelName}s` : modelName;\n\n\tconst schemaModel = schema[model];\n\tif (!schemaModel) {\n\t\tthrow new BetterAuthError(\n\t\t\t`[# Drizzle Adapter]: The model \"${modelName}\" was not found in the schema object. Please pass the schema directly to the adapter options.`,\n\t\t);\n\t}\n\treturn schemaModel;\n}\n\nfunction whereConvertor(where: Where[], schemaModel: any) {\n\tif (!where) return [];\n\tif (where.length === 1) {\n\t\tconst w = where[0];\n\t\tif (!w) {\n\t\t\treturn [];\n\t\t}\n\n\t\tif (w.operator === \"in\") {\n\t\t\tif (!Array.isArray(w.value)) {\n\t\t\t\tthrow new BetterAuthError(\n\t\t\t\t\t`The value for the field \"${w.field}\" must be an array when using the \"in\" operator.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn [inArray(schemaModel[w.field], w.value)];\n\t\t}\n\n\t\tif (w.operator === \"contains\") {\n\t\t\treturn [like(schemaModel[w.field], `%${w.value}%`)];\n\t\t}\n\n\t\tif (w.operator === \"starts_with\") {\n\t\t\treturn [like(schemaModel[w.field], `${w.value}%`)];\n\t\t}\n\n\t\tif (w.operator === \"ends_with\") {\n\t\t\treturn [like(schemaModel[w.field], `%${w.value}`)];\n\t\t}\n\n\t\treturn [eq(schemaModel[w.field], w.value)];\n\t}\n\tconst andGroup = where.filter((w) => w.connector === \"AND\" || !w.connector);\n\tconst orGroup = where.filter((w) => w.connector === \"OR\");\n\n\tconst andClause = and(\n\t\t...andGroup.map((w) => {\n\t\t\tif (w.operator === \"in\") {\n\t\t\t\tif (!Array.isArray(w.value)) {\n\t\t\t\t\tthrow new BetterAuthError(\n\t\t\t\t\t\t`The value for the field \"${w.field}\" must be an array when using the \"in\" operator.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\treturn inArray(schemaModel[w.field], w.value);\n\t\t\t}\n\t\t\treturn eq(schemaModel[w.field], w.value);\n\t\t}),\n\t);\n\tconst orClause = or(\n\t\t...orGroup.map((w) => {\n\t\t\treturn eq(schemaModel[w.field], w.value);\n\t\t}),\n\t);\n\n\tconst clause: SQL<unknown>[] = [];\n\n\tif (andGroup.length) clause.push(andClause!);\n\tif (orGroup.length) clause.push(orClause!);\n\treturn clause;\n}\n\ninterface DB {\n\t[key: string]: any;\n}\n\nexport const drizzleAdapter = (\n\tdb: DB,\n\toptions: DrizzleAdapterOptions,\n): Adapter => {\n\tconst schema = options.schema || db._.fullSchema;\n\tconst databaseType = options?.provider;\n\treturn {\n\t\tid: \"drizzle\",\n\t\tasync create(data) {\n\t\t\tconst { model, data: val } = data;\n\t\t\tconst schemaModel = getSchema(model, {\n\t\t\t\tschema,\n\t\t\t\tusePlural: options.usePlural,\n\t\t\t});\n\t\t\tif (options.generateId !== undefined) {\n\t\t\t\tval.id = options.generateId ? options.generateId() : undefined;\n\t\t\t}\n\n\t\t\tconst mutation = db.insert(schemaModel).values(val);\n\t\t\tif (databaseType !== \"mysql\") return (await mutation.returning())[0];\n\n\t\t\tawait mutation;\n\t\t\tconst res = await db\n\t\t\t\t.select()\n\t\t\t\t.from(schemaModel)\n\t\t\t\t.where(eq(schemaModel.id, (data.data as { id: string }).id));\n\t\t\treturn res[0];\n\t\t},\n\t\tasync findOne(data) {\n\t\t\tconst { model, where, select: included } = data;\n\n\t\t\tconst schemaModel = getSchema(model, {\n\t\t\t\tschema,\n\t\t\t\tusePlural: options.usePlural,\n\t\t\t});\n\n\t\t\tconst wheres = whereConvertor(where, schemaModel);\n\n\t\t\tlet res = null;\n\t\t\tif (!!included?.length) {\n\t\t\t\tres = await db\n\t\t\t\t\t.select(\n\t\t\t\t\t\t...included.map((include) => {\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t[include]: schemaModel[include],\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t}),\n\t\t\t\t\t)\n\t\t\t\t\t.from(schemaModel)\n\t\t\t\t\t.where(...wheres);\n\t\t\t} else {\n\t\t\t\tres = await db\n\t\t\t\t\t.select()\n\t\t\t\t\t.from(schemaModel)\n\t\t\t\t\t.where(...wheres);\n\t\t\t}\n\n\t\t\tif (!!res.length) return res[0];\n\t\t\telse return null;\n\t\t},\n\t\tasync findMany(data) {\n\t\t\tconst { model, where, limit, offset, sortBy } = data;\n\t\t\tconst schemaModel = getSchema(model, {\n\t\t\t\tschema,\n\t\t\t\tusePlural: options.usePlural,\n\t\t\t});\n\t\t\tconst filters = where ? whereConvertor(where, schemaModel) : [];\n\t\t\tconst fn = sortBy?.direction === \"desc\" ? desc : asc;\n\t\t\tconst res = await db\n\t\t\t\t.select()\n\t\t\t\t.from(schemaModel)\n\t\t\t\t.limit(limit || 100)\n\t\t\t\t.offset(offset || 0)\n\t\t\t\t.orderBy(fn(schemaModel[sortBy?.field || \"id\"]))\n\t\t\t\t.where(...(filters.length ? filters : []));\n\n\t\t\treturn res;\n\t\t},\n\t\tasync update(data) {\n\t\t\tconst { model, where, update } = data;\n\t\t\tconst schemaModel = getSchema(model, {\n\t\t\t\tschema,\n\t\t\t\tusePlural: options.usePlural,\n\t\t\t});\n\t\t\tif (update.id) {\n\t\t\t\tupdate.id = undefined;\n\t\t\t}\n\t\t\tconst wheres = whereConvertor(where, schemaModel);\n\t\t\tconst mutation = db\n\t\t\t\t.update(schemaModel)\n\t\t\t\t.set(update)\n\t\t\t\t.where(...wheres);\n\t\t\tif (databaseType !== \"mysql\") return (await mutation.returning())[0];\n\n\t\t\tawait mutation;\n\t\t\tconst res = await db\n\t\t\t\t.select()\n\t\t\t\t.from(schemaModel)\n\t\t\t\t.where(eq(schemaModel.id, (data.update as { id: string }).id));\n\t\t\treturn res[0];\n\t\t},\n\t\tasync delete(data) {\n\t\t\tconst { model, where } = data;\n\t\t\tconst schemaModel = getSchema(model, {\n\t\t\t\tschema,\n\t\t\t\tusePlural: options.usePlural,\n\t\t\t});\n\t\t\tconst wheres = whereConvertor(where, schemaModel);\n\t\t\tconst res = await db.delete(schemaModel).where(...wheres);\n\n\t\t\treturn res[0];\n\t\t},\n\t\tasync deleteMany(data) {\n\t\t\tconst { model, where } = data;\n\t\t\tconst schemaModel = getSchema(model, {\n\t\t\t\tschema,\n\t\t\t\tusePlural: options.usePlural,\n\t\t\t});\n\t\t\tconst wheres = whereConvertor(where, schemaModel);\n\t\t\tawait db.delete(schemaModel).where(...wheres);\n\t\t},\n\t\toptions,\n\t};\n};\n"],"mappings":"sEAAA,OAAS,OAAAA,EAAK,OAAAC,EAAK,QAAAC,EAAM,MAAAC,EAAI,MAAAC,EAAS,WAAAC,EAAS,QAAAC,MAAY,cAwB3D,SAASC,EACRC,EACAC,EAIC,CACD,IAAMC,EAASD,EAAQ,OACvB,GAAI,CAACC,EACJ,MAAM,IAAIC,EACT,uHACD,EAED,IAAMC,EAAQH,EAAQ,UAAY,GAAGD,CAAS,IAAMA,EAE9CK,EAAcH,EAAOE,CAAK,EAChC,GAAI,CAACC,EACJ,MAAM,IAAIF,EACT,mCAAmCH,CAAS,+FAC7C,EAED,OAAOK,CACR,CAEA,SAASC,EAAeC,EAAgBF,EAAkB,CACzD,GAAI,CAACE,EAAO,MAAO,CAAC,EACpB,GAAIA,EAAM,SAAW,EAAG,CACvB,IAAMC,EAAID,EAAM,CAAC,EACjB,GAAI,CAACC,EACJ,MAAO,CAAC,EAGT,GAAIA,EAAE,WAAa,KAAM,CACxB,GAAI,CAAC,MAAM,QAAQA,EAAE,KAAK,EACzB,MAAM,IAAIL,EACT,4BAA4BK,EAAE,KAAK,kDACpC,EAED,MAAO,CAACC,EAAQJ,EAAYG,EAAE,KAAK,EAAGA,EAAE,KAAK,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,MAAM,GAAGqB,CAAM,CAC7C,EACA,QAAAzB,CACD,CACD","names":["and","asc","desc","eq","or","inArray","like","getSchema","modelName","options","schema","BetterAuthError","model","schemaModel","whereConvertor","where","w","inArray","like","eq","andGroup","orGroup","andClause","and","orClause","or","clause","drizzleAdapter","db","databaseType","data","val","mutation","included","wheres","res","include","limit","offset","sortBy","filters","fn","desc","asc","update"]}
|
package/dist/adapters/kysely.cjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkTKTXK746cjs = require('../chunk-TKTXK746.cjs');require('../chunk-M4G6J7DP.cjs');exports.createKyselyAdapter = _chunkTKTXK746cjs.a; exports.kyselyAdapter = _chunkTKTXK746cjs.b;
|
|
2
|
+
//# sourceMappingURL=kysely.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/beka/Desktop/Development/better-auth/packages/better-auth/dist/adapters/kysely.cjs"],"names":[],"mappings":"AAAA,kIAAsC,iCAA8B,+FAAoD","file":"/Users/beka/Desktop/Development/better-auth/packages/better-auth/dist/adapters/kysely.cjs"}
|
package/dist/adapters/kysely.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import{a,b}from"../chunk-
|
|
1
|
+
import{a,b}from"../chunk-GFCR6QEP.js";import"../chunk-4C666HHU.js";export{a as createKyselyAdapter,b as kyselyAdapter};
|
|
2
|
+
//# sourceMappingURL=kysely.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }require('../chunk-
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }require('../chunk-M4G6J7DP.cjs');function u(l){if(!l)return{};let d=l.map(n=>{let{field:t,value:e,operator:c="eq",connector:i="AND"}=n,o;switch(c.toLowerCase()){case"eq":o={[t]:e};break;case"in":o={[t]:{$in:Array.isArray(e)?e:[e]}};break;case"gt":o={[t]:{$gt:e}};break;case"gte":o={[t]:{$gte:e}};break;case"lt":o={[t]:{$lt:e}};break;case"lte":o={[t]:{$lte:e}};break;case"ne":o={[t]:{$ne:e}};break;case"contains":o={[t]:{$regex:`.*${e}.*`}};break;case"starts_with":o={[t]:{$regex:`${e}.*`}};break;case"ends_with":o={[t]:{$regex:`.*${e}`}};break;default:throw new Error(`Unsupported operator: ${c}`)}return{condition:o,connector:i}}),s=d.filter(n=>n.connector==="AND").map(n=>n.condition),a=d.filter(n=>n.connector==="OR").map(n=>n.condition),r={};return s.length&&(r={...r,$and:s}),a.length&&(r={...r,$or:a}),r}function f(l){let{_id:d,...s}=l;return s}function w(l){return l.reduce((s,a)=>(s[a]=1,s),{})}var m=(l,d)=>{let s=l,a=r=>_optionalChain([d, 'optionalAccess', _ => _.usePlural])?`${r}s`:r;return{id:"mongodb",async create(r){let{model:n,data:t}=r;_optionalChain([d, 'optionalAccess', _2 => _2.generateId])!==void 0&&(t.id=d.generateId?d.generateId():void 0);let c=(await s.collection(a(n)).insertOne({...t})).insertedId,i={...t,id:c};return f(i)},async findOne(r){let{model:n,where:t,select:e}=r,c=u(t),i={};e&&(i=w(e));let o=await s.collection(a(n)).findOne(c,{projection:i});return o?f(o):null},async findMany(r){let{model:n,where:t,limit:e,offset:c,sortBy:i}=r,o=u(t);return(await s.collection(a(n)).find(o).skip(c||0).limit(e||100).sort(_optionalChain([i, 'optionalAccess', _3 => _3.field])||"id",_optionalChain([i, 'optionalAccess', _4 => _4.direction])==="desc"?-1:1).toArray()).map(f)},async update(r){let{model:n,where:t,update:e}=r,c=u(t);if(e.id&&(e.id=void 0),t.length===1){let o=await s.collection(a(n)).findOneAndUpdate(c,{$set:e},{returnDocument:"after"});return f(o)}let i=await s.collection(a(n)).updateMany(c,{$set:e});return{}},async delete(r){let{model:n,where:t}=r,e=u(t),c=await s.collection(a(n)).findOneAndDelete(e)},async deleteMany(r){let{model:n,where:t}=r,e=u(t),c=await s.collection(a(n)).deleteMany(e)}}};exports.mongodbAdapter = m;
|
|
2
|
+
//# sourceMappingURL=mongodb.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/beka/Desktop/Development/better-auth/packages/better-auth/dist/adapters/mongodb.cjs","../../src/adapters/mongodb-adapter/index.ts"],"names":["whereConvertor","where","conditions","w","field","value","operator","connector","condition"],"mappings":"AAAA,8mBAA6B,SCGpBA,CAAAA,CAAeC,CAAAA,CAAiB,CACxC,EAAA,CAAI,CAACA,CAAAA,CAAO,MAAO,CAAC,CAAA,CAEpB,IAAMC,CAAAA,CAAaD,CAAAA,CAAM,GAAA,CAAKE,CAAAA,EAAM,CACnC,GAAM,CAAE,KAAA,CAAAC,CAAAA,CAAO,KAAA,CAAAC,CAAAA,CAAO,QAAA,CAAAC,CAAAA,CAAW,IAAA,CAAM,SAAA,CAAAC,CAAAA,CAAY,KAAM,CAAA,CAAIJ,CAAAA,CACz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ongodb.cjs","sourcesContent":[null,"import type { Db } from \"mongodb\";\nimport type { Adapter, Where } from \"../../types\";\n\nfunction whereConvertor(where?: Where[]) {\n\tif (!where) return {};\n\n\tconst conditions = where.map((w) => {\n\t\tconst { field, value, operator = \"eq\", connector = \"AND\" } = w;\n\t\tlet condition: any;\n\n\t\tswitch (operator.toLowerCase()) {\n\t\t\tcase \"eq\":\n\t\t\t\tcondition = { [field]: value };\n\t\t\t\tbreak;\n\t\t\tcase \"in\":\n\t\t\t\tcondition = {\n\t\t\t\t\t[field]: { $in: Array.isArray(value) ? value : [value] },\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tcase \"gt\":\n\t\t\t\tcondition = { [field]: { $gt: value } };\n\t\t\t\tbreak;\n\t\t\tcase \"gte\":\n\t\t\t\tcondition = { [field]: { $gte: value } };\n\t\t\t\tbreak;\n\t\t\tcase \"lt\":\n\t\t\t\tcondition = { [field]: { $lt: value } };\n\t\t\t\tbreak;\n\t\t\tcase \"lte\":\n\t\t\t\tcondition = { [field]: { $lte: value } };\n\t\t\t\tbreak;\n\t\t\tcase \"ne\":\n\t\t\t\tcondition = { [field]: { $ne: value } };\n\t\t\t\tbreak;\n\n\t\t\tcase \"contains\":\n\t\t\t\tcondition = { [field]: { $regex: `.*${value}.*` } };\n\t\t\t\tbreak;\n\t\t\tcase \"starts_with\":\n\t\t\t\tcondition = { [field]: { $regex: `${value}.*` } };\n\t\t\t\tbreak;\n\t\t\tcase \"ends_with\":\n\t\t\t\tcondition = { [field]: { $regex: `.*${value}` } };\n\t\t\t\tbreak;\n\n\t\t\t// Add more operators as needed\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Unsupported operator: ${operator}`);\n\t\t}\n\n\t\treturn { condition, connector };\n\t});\n\n\tconst andConditions = conditions\n\t\t.filter((c) => c.connector === \"AND\")\n\t\t.map((c) => c.condition);\n\tconst orConditions = conditions\n\t\t.filter((c) => c.connector === \"OR\")\n\t\t.map((c) => c.condition);\n\n\tlet clause = {};\n\tif (andConditions.length) {\n\t\tclause = { ...clause, $and: andConditions };\n\t}\n\tif (orConditions.length) {\n\t\tclause = { ...clause, $or: orConditions };\n\t}\n\n\treturn clause;\n}\n\nfunction removeMongoId(data: any) {\n\tconst { _id, ...rest } = data;\n\treturn rest;\n}\n\nfunction selectConvertor(selects: string[]) {\n\tconst selectConstruct = selects.reduce((acc, field) => {\n\t\t//@ts-expect-error\n\t\tacc[field] = 1;\n\t\treturn acc;\n\t}, {});\n\n\treturn selectConstruct;\n}\n\nexport const mongodbAdapter = (\n\tmongo: Db,\n\topts?: {\n\t\tusePlural?: boolean;\n\t\t/**\n\t\t * Custom generateId function.\n\t\t *\n\t\t * If not provided, nanoid will be used.\n\t\t * If set to false, the database's auto generated id will be used.\n\t\t *\n\t\t * @default nanoid\n\t\t */\n\t\tgenerateId?: ((size?: number) => string) | false;\n\t},\n) => {\n\tconst db = mongo;\n\tconst getModelName = (name: string) => (opts?.usePlural ? `${name}s` : name);\n\treturn {\n\t\tid: \"mongodb\",\n\t\tasync create(data) {\n\t\t\tconst { model, data: val } = data;\n\n\t\t\tif (opts?.generateId !== undefined) {\n\t\t\t\tval.id = opts.generateId ? opts.generateId() : undefined;\n\t\t\t}\n\n\t\t\tconst res = await db.collection(getModelName(model)).insertOne({\n\t\t\t\t...val,\n\t\t\t});\n\t\t\tconst id_ = res.insertedId;\n\t\t\tconst returned = { ...val, id: id_ };\n\t\t\treturn removeMongoId(returned);\n\t\t},\n\t\tasync findOne(data) {\n\t\t\tconst { model, where, select } = data;\n\n\t\t\tconst wheres = whereConvertor(where);\n\t\t\tlet selects = {};\n\t\t\tif (select) {\n\t\t\t\tselects = selectConvertor(select);\n\t\t\t}\n\n\t\t\tconst result = await db\n\t\t\t\t.collection(getModelName(model))\n\t\t\t\t.findOne(wheres, { projection: selects });\n\n\t\t\tif (!result) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\treturn removeMongoId(result);\n\t\t},\n\t\tasync findMany(data) {\n\t\t\tconst { model, where, limit, offset, sortBy } = data;\n\t\t\tconst wheres = whereConvertor(where);\n\t\t\tconst toReturn = await db\n\t\t\t\t.collection(getModelName(model))\n\t\t\t\t.find(wheres)\n\t\t\t\t.skip(offset || 0)\n\t\t\t\t.limit(limit || 100)\n\t\t\t\t.sort(sortBy?.field || \"id\", sortBy?.direction === \"desc\" ? -1 : 1)\n\t\t\t\t.toArray();\n\t\t\treturn toReturn.map(removeMongoId);\n\t\t},\n\t\tasync update(data) {\n\t\t\tconst { model, where, update } = data;\n\t\t\tconst wheres = whereConvertor(where);\n\n\t\t\tif (update.id) {\n\t\t\t\tupdate.id = undefined;\n\t\t\t}\n\n\t\t\tif (where.length === 1) {\n\t\t\t\tconst res = await db.collection(getModelName(model)).findOneAndUpdate(\n\t\t\t\t\twheres,\n\t\t\t\t\t{\n\t\t\t\t\t\t$set: update,\n\t\t\t\t\t},\n\t\t\t\t\t{ returnDocument: \"after\" },\n\t\t\t\t);\n\t\t\t\treturn removeMongoId(res);\n\t\t\t}\n\t\t\tconst res = await db.collection(getModelName(model)).updateMany(wheres, {\n\t\t\t\t$set: update,\n\t\t\t});\n\t\t\treturn {};\n\t\t},\n\t\tasync delete(data) {\n\t\t\tconst { model, where } = data;\n\t\t\tconst wheres = whereConvertor(where);\n\n\t\t\tconst res = await db\n\t\t\t\t.collection(getModelName(model))\n\t\t\t\t.findOneAndDelete(wheres);\n\t\t},\n\t\tasync deleteMany(data) {\n\t\t\tconst { model, where } = data;\n\t\t\tconst wheres = whereConvertor(where);\n\n\t\t\tconst res = await db.collection(getModelName(model)).deleteMany(wheres);\n\t\t},\n\t} satisfies Adapter;\n};\n"]}
|
package/dist/adapters/mongodb.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import"../chunk-
|
|
1
|
+
import"../chunk-4C666HHU.js";function u(l){if(!l)return{};let d=l.map(n=>{let{field:t,value:e,operator:c="eq",connector:i="AND"}=n,o;switch(c.toLowerCase()){case"eq":o={[t]:e};break;case"in":o={[t]:{$in:Array.isArray(e)?e:[e]}};break;case"gt":o={[t]:{$gt:e}};break;case"gte":o={[t]:{$gte:e}};break;case"lt":o={[t]:{$lt:e}};break;case"lte":o={[t]:{$lte:e}};break;case"ne":o={[t]:{$ne:e}};break;case"contains":o={[t]:{$regex:`.*${e}.*`}};break;case"starts_with":o={[t]:{$regex:`${e}.*`}};break;case"ends_with":o={[t]:{$regex:`.*${e}`}};break;default:throw new Error(`Unsupported operator: ${c}`)}return{condition:o,connector:i}}),s=d.filter(n=>n.connector==="AND").map(n=>n.condition),a=d.filter(n=>n.connector==="OR").map(n=>n.condition),r={};return s.length&&(r={...r,$and:s}),a.length&&(r={...r,$or:a}),r}function f(l){let{_id:d,...s}=l;return s}function w(l){return l.reduce((s,a)=>(s[a]=1,s),{})}var m=(l,d)=>{let s=l,a=r=>d?.usePlural?`${r}s`:r;return{id:"mongodb",async create(r){let{model:n,data:t}=r;d?.generateId!==void 0&&(t.id=d.generateId?d.generateId():void 0);let c=(await s.collection(a(n)).insertOne({...t})).insertedId,i={...t,id:c};return f(i)},async findOne(r){let{model:n,where:t,select:e}=r,c=u(t),i={};e&&(i=w(e));let o=await s.collection(a(n)).findOne(c,{projection:i});return o?f(o):null},async findMany(r){let{model:n,where:t,limit:e,offset:c,sortBy:i}=r,o=u(t);return(await s.collection(a(n)).find(o).skip(c||0).limit(e||100).sort(i?.field||"id",i?.direction==="desc"?-1:1).toArray()).map(f)},async update(r){let{model:n,where:t,update:e}=r,c=u(t);if(e.id&&(e.id=void 0),t.length===1){let o=await s.collection(a(n)).findOneAndUpdate(c,{$set:e},{returnDocument:"after"});return f(o)}let i=await s.collection(a(n)).updateMany(c,{$set:e});return{}},async delete(r){let{model:n,where:t}=r,e=u(t),c=await s.collection(a(n)).findOneAndDelete(e)},async deleteMany(r){let{model:n,where:t}=r,e=u(t),c=await s.collection(a(n)).deleteMany(e)}}};export{m as mongodbAdapter};
|
|
2
|
+
//# sourceMappingURL=mongodb.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/adapters/mongodb-adapter/index.ts"],"sourcesContent":["import type { Db } from \"mongodb\";\nimport type { Adapter, Where } from \"../../types\";\n\nfunction whereConvertor(where?: Where[]) {\n\tif (!where) return {};\n\n\tconst conditions = where.map((w) => {\n\t\tconst { field, value, operator = \"eq\", connector = \"AND\" } = w;\n\t\tlet condition: any;\n\n\t\tswitch (operator.toLowerCase()) {\n\t\t\tcase \"eq\":\n\t\t\t\tcondition = { [field]: value };\n\t\t\t\tbreak;\n\t\t\tcase \"in\":\n\t\t\t\tcondition = {\n\t\t\t\t\t[field]: { $in: Array.isArray(value) ? value : [value] },\n\t\t\t\t};\n\t\t\t\tbreak;\n\t\t\tcase \"gt\":\n\t\t\t\tcondition = { [field]: { $gt: value } };\n\t\t\t\tbreak;\n\t\t\tcase \"gte\":\n\t\t\t\tcondition = { [field]: { $gte: value } };\n\t\t\t\tbreak;\n\t\t\tcase \"lt\":\n\t\t\t\tcondition = { [field]: { $lt: value } };\n\t\t\t\tbreak;\n\t\t\tcase \"lte\":\n\t\t\t\tcondition = { [field]: { $lte: value } };\n\t\t\t\tbreak;\n\t\t\tcase \"ne\":\n\t\t\t\tcondition = { [field]: { $ne: value } };\n\t\t\t\tbreak;\n\n\t\t\tcase \"contains\":\n\t\t\t\tcondition = { [field]: { $regex: `.*${value}.*` } };\n\t\t\t\tbreak;\n\t\t\tcase \"starts_with\":\n\t\t\t\tcondition = { [field]: { $regex: `${value}.*` } };\n\t\t\t\tbreak;\n\t\t\tcase \"ends_with\":\n\t\t\t\tcondition = { [field]: { $regex: `.*${value}` } };\n\t\t\t\tbreak;\n\n\t\t\t// Add more operators as needed\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Unsupported operator: ${operator}`);\n\t\t}\n\n\t\treturn { condition, connector };\n\t});\n\n\tconst andConditions = conditions\n\t\t.filter((c) => c.connector === \"AND\")\n\t\t.map((c) => c.condition);\n\tconst orConditions = conditions\n\t\t.filter((c) => c.connector === \"OR\")\n\t\t.map((c) => c.condition);\n\n\tlet clause = {};\n\tif (andConditions.length) {\n\t\tclause = { ...clause, $and: andConditions };\n\t}\n\tif (orConditions.length) {\n\t\tclause = { ...clause, $or: orConditions };\n\t}\n\n\treturn clause;\n}\n\nfunction removeMongoId(data: any) {\n\tconst { _id, ...rest } = data;\n\treturn rest;\n}\n\nfunction selectConvertor(selects: string[]) {\n\tconst selectConstruct = selects.reduce((acc, field) => {\n\t\t//@ts-expect-error\n\t\tacc[field] = 1;\n\t\treturn acc;\n\t}, {});\n\n\treturn selectConstruct;\n}\n\nexport const mongodbAdapter = (\n\tmongo: Db,\n\topts?: {\n\t\tusePlural?: boolean;\n\t\t/**\n\t\t * Custom generateId function.\n\t\t *\n\t\t * If not provided, nanoid will be used.\n\t\t * If set to false, the database's auto generated id will be used.\n\t\t *\n\t\t * @default nanoid\n\t\t */\n\t\tgenerateId?: ((size?: number) => string) | false;\n\t},\n) => {\n\tconst db = mongo;\n\tconst getModelName = (name: string) => (opts?.usePlural ? `${name}s` : name);\n\treturn {\n\t\tid: \"mongodb\",\n\t\tasync create(data) {\n\t\t\tconst { model, data: val } = data;\n\n\t\t\tif (opts?.generateId !== undefined) {\n\t\t\t\tval.id = opts.generateId ? opts.generateId() : undefined;\n\t\t\t}\n\n\t\t\tconst res = await db.collection(getModelName(model)).insertOne({\n\t\t\t\t...val,\n\t\t\t});\n\t\t\tconst id_ = res.insertedId;\n\t\t\tconst returned = { ...val, id: id_ };\n\t\t\treturn removeMongoId(returned);\n\t\t},\n\t\tasync findOne(data) {\n\t\t\tconst { model, where, select } = data;\n\n\t\t\tconst wheres = whereConvertor(where);\n\t\t\tlet selects = {};\n\t\t\tif (select) {\n\t\t\t\tselects = selectConvertor(select);\n\t\t\t}\n\n\t\t\tconst result = await db\n\t\t\t\t.collection(getModelName(model))\n\t\t\t\t.findOne(wheres, { projection: selects });\n\n\t\t\tif (!result) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\treturn removeMongoId(result);\n\t\t},\n\t\tasync findMany(data) {\n\t\t\tconst { model, where, limit, offset, sortBy } = data;\n\t\t\tconst wheres = whereConvertor(where);\n\t\t\tconst toReturn = await db\n\t\t\t\t.collection(getModelName(model))\n\t\t\t\t.find(wheres)\n\t\t\t\t.skip(offset || 0)\n\t\t\t\t.limit(limit || 100)\n\t\t\t\t.sort(sortBy?.field || \"id\", sortBy?.direction === \"desc\" ? -1 : 1)\n\t\t\t\t.toArray();\n\t\t\treturn toReturn.map(removeMongoId);\n\t\t},\n\t\tasync update(data) {\n\t\t\tconst { model, where, update } = data;\n\t\t\tconst wheres = whereConvertor(where);\n\n\t\t\tif (update.id) {\n\t\t\t\tupdate.id = undefined;\n\t\t\t}\n\n\t\t\tif (where.length === 1) {\n\t\t\t\tconst res = await db.collection(getModelName(model)).findOneAndUpdate(\n\t\t\t\t\twheres,\n\t\t\t\t\t{\n\t\t\t\t\t\t$set: update,\n\t\t\t\t\t},\n\t\t\t\t\t{ returnDocument: \"after\" },\n\t\t\t\t);\n\t\t\t\treturn removeMongoId(res);\n\t\t\t}\n\t\t\tconst res = await db.collection(getModelName(model)).updateMany(wheres, {\n\t\t\t\t$set: update,\n\t\t\t});\n\t\t\treturn {};\n\t\t},\n\t\tasync delete(data) {\n\t\t\tconst { model, where } = data;\n\t\t\tconst wheres = whereConvertor(where);\n\n\t\t\tconst res = await db\n\t\t\t\t.collection(getModelName(model))\n\t\t\t\t.findOneAndDelete(wheres);\n\t\t},\n\t\tasync deleteMany(data) {\n\t\t\tconst { model, where } = data;\n\t\t\tconst wheres = whereConvertor(where);\n\n\t\t\tconst res = await db.collection(getModelName(model)).deleteMany(wheres);\n\t\t},\n\t} satisfies Adapter;\n};\n"],"mappings":"6BAGA,SAASA,EAAeC,EAAiB,CACxC,GAAI,CAACA,EAAO,MAAO,CAAC,EAEpB,IAAMC,EAAaD,EAAM,IAAKE,GAAM,CACnC,GAAM,CAAE,MAAAC,EAAO,M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ertor","where","conditions","w","field","value","operator","connector","condition","andConditions","c","orConditions","clause","removeMongoId","data","_id","rest","selectConvertor","selects","acc","mongodbAdapter","mongo","opts","db","getModelName","name","model","val","id_","returned","select","wheres","result","limit","offset","sortBy","update","res"]}
|
package/dist/adapters/prisma.cjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }require('../chunk-
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }require('../chunk-M4G6J7DP.cjs');function f(a){switch(a){case"starts_with":return"startsWith";case"ends_with":return"endsWith";default:return a}}function c(a){if(!a)return{};if(a.length===1){let e=a[0];return e?{[e.field]:e.operator==="eq"||!e.operator?e.value:{[f(e.operator)]:e.value}}:void 0}let l=a.filter(e=>e.connector==="AND"||!e.connector),s=a.filter(e=>e.connector==="OR"),o=l.map(e=>({[e.field]:e.operator==="eq"||!e.operator?e.value:{[f(e.operator)]:e.value}})),r=s.map(e=>({[e.field]:{[e.operator||"eq"]:e.value}}));return{AND:o.length?o:void 0,OR:r.length?r:void 0}}var y=(a,l)=>{let s=a,o=l.generateId;return{id:"prisma",async create(r){let{model:e,data:n,select:t}=r;return o!==void 0&&(n.id=o?o():void 0),await s[e].create({data:n,..._optionalChain([t, 'optionalAccess', _ => _.length])?{select:t.reduce((d,i)=>({...d,[i]:!0}),{})}:{}})},async findOne(r){let{model:e,where:n,select:t}=r,d=c(n);return await s[e].findFirst({where:d,..._optionalChain([t, 'optionalAccess', _2 => _2.length])?{select:t.reduce((i,u)=>({...i,[u]:!0}),{})}:{}})},async findMany(r){let{model:e,where:n,limit:t,offset:d,sortBy:i}=r,u=c(n);return await s[e].findMany({where:u,take:t||100,skip:d||0,orderBy:_optionalChain([i, 'optionalAccess', _3 => _3.field])?{[i.field]:i.direction==="desc"?"desc":"asc"}:void 0})},async update(r){let{model:e,where:n,update:t}=r;t.id&&(t.id=void 0);let d=c(n);return n.length===1?await s[e].update({where:d,data:t}):await s[e].updateMany({where:d,data:t})},async delete(r){let{model:e,where:n}=r,t=c(n);return await s[e].delete({where:t}).catch(d=>{})},async deleteMany(r){let{model:e,where:n}=r,t=c(n);return await s[e].deleteMany({where:t})},options:l}};exports.prismaAdapter = y;
|
|
2
|
+
//# sourceMappingURL=prisma.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/beka/Desktop/Development/better-auth/packages/better-auth/dist/adapters/prisma.cjs","../../src/adapters/prisma-adapter/index.ts"],"names":["operatorToPrismaOperator","operator","whereConvertor","where","w","and","or","andClause","orClause","prismaAdapter","prisma","options","db","generateId","data","model","val","select","prev","cur","whereClause","limit","offset","sortBy","update","e"],"mappings":"AAAA,8mBAA6B,SCEpBA,CAAAA,CAAyBC,CAAAA,CAAkB,CACnD,MAAA,CAAQA,CAAAA,CAAU,CACjB,IAAK,aAAA,CACJ,MAAO,YAAA,CACR,IAAK,WAAA,CACJ,MAAO,UAAA,CACR,OAAA,CACC,OAAOA,CACT,CACD,CAEA,SAASC,CAAAA,CAAeC,CAAAA,CAAiB,CACxC,EAAA,CAAI,CA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AO,CAC7B,KAAA,CAAOK,CAAAA,CACP,IAAA,CAAMI,CACP,CAAC,CAAA,CAEK,MAAMZ,CAAAA,CAAGG,CAAK,CAAA,CAAE,UAAA,CAAW,CACjC,KAAA,CAAOK,CAAAA,CACP,IAAA,CAAMI,CACP,CAAC,CACF,CAAA,CACA,MAAM,MAAA,CAAOV,CAAAA,CAAM,CAClB,GAAM,CAAE,KAAA,CAAAC,CAAAA,CAAO,KAAA,CAAAZ,CAAM,CAAA,CAAIW,CAAAA,CACnBM,CAAAA,CAAclB,CAAAA,CAAeC,CAAK,CAAA,CAExC,OAAO,MAAMS,CAAAA,CAAGG,CAAK,CAAA,CAAE,MAAA,CAAO,CAAE,KAAA,CAAOK,CAAY,CAAC,CAAA,CAAE,KAAA,CAAOK,CAAAA,EAAM,CAEnE,CAAC,CACF,CAAA,CACA,MAAM,UAAA,CAAWX,CAAAA,CAAM,CACtB,GAAM,CAAE,KAAA,CAAAC,CAAAA,CAAO,KAAA,CAAAZ,CAAM,CAAA,CAAIW,CAAAA,CACnBM,CAAAA,CAAclB,CAAAA,CAAeC,CAAK,CAAA,CAExC,OAAO,MAAMS,CAAAA,CAAGG,CAAK,CAAA,CAAE,UAAA,CAAW,CAAE,KAAA,CAAOK,CAAY,CAAC,CACzD,CAAA,CACA,OAAA,CAAAT,CACD,CACD,CAAA,CAAA,0BAAA","file":"/Users/beka/Desktop/Development/better-auth/packages/better-auth/dist/adapters/prisma.cjs","sourcesContent":[null,"import type { Adapter, Where } from \"../../types\";\n\nfunction operatorToPrismaOperator(operator: string) {\n\tswitch (operator) {\n\t\tcase \"starts_with\":\n\t\t\treturn \"startsWith\";\n\t\tcase \"ends_with\":\n\t\t\treturn \"endsWith\";\n\t\tdefault:\n\t\t\treturn operator;\n\t}\n}\n\nfunction whereConvertor(where?: Where[]) {\n\tif (!where) return {};\n\tif (where.length === 1) {\n\t\tconst w = where[0];\n\t\tif (!w) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn {\n\t\t\t[w.field]:\n\t\t\t\tw.operator === \"eq\" || !w.operator\n\t\t\t\t\t? w.value\n\t\t\t\t\t: {\n\t\t\t\t\t\t\t[operatorToPrismaOperator(w.operator)]: w.value,\n\t\t\t\t\t\t},\n\t\t};\n\t}\n\tconst and = where.filter((w) => w.connector === \"AND\" || !w.connector);\n\tconst or = where.filter((w) => w.connector === \"OR\");\n\tconst andClause = and.map((w) => {\n\t\treturn {\n\t\t\t[w.field]:\n\t\t\t\tw.operator === \"eq\" || !w.operator\n\t\t\t\t\t? w.value\n\t\t\t\t\t: {\n\t\t\t\t\t\t\t[operatorToPrismaOperator(w.operator)]: w.value,\n\t\t\t\t\t\t},\n\t\t};\n\t});\n\tconst orClause = or.map((w) => {\n\t\treturn {\n\t\t\t[w.field]: {\n\t\t\t\t[w.operator || \"eq\"]: w.value,\n\t\t\t},\n\t\t};\n\t});\n\n\treturn {\n\t\tAND: andClause.length ? andClause : undefined,\n\t\tOR: orClause.length ? orClause : undefined,\n\t};\n}\n\ninterface PrismaClient {\n\t[model: string]: {\n\t\tcreate: (data: any) => Promise<any>;\n\t\tfindFirst: (data: any) => Promise<any>;\n\t\tfindMany: (data: any) => Promise<any>;\n\t\tupdate: (data: any) => Promise<any>;\n\t\tdelete: (data: any) => Promise<any>;\n\t\t[key: string]: any;\n\t};\n}\n\nexport const prismaAdapter = (\n\tprisma: any,\n\toptions: {\n\t\tprovider:\n\t\t\t| \"sqlite\"\n\t\t\t| \"cockroachdb\"\n\t\t\t| \"mysql\"\n\t\t\t| \"postgresql\"\n\t\t\t| \"sqlserver\"\n\t\t\t| \"mongodb\";\n\t\t/**\n\t\t * Custom generateId function.\n\t\t *\n\t\t * If not provided, nanoid will be used.\n\t\t * If set to false, the database's auto generated id will be used.\n\t\t *\n\t\t * @default nanoid\n\t\t */\n\t\tgenerateId?: ((size?: number) => string) | false;\n\t},\n): Adapter => {\n\tconst db: PrismaClient = prisma;\n\tconst generateId = options.generateId;\n\treturn {\n\t\tid: \"prisma\",\n\t\tasync create(data) {\n\t\t\tconst { model, data: val, select } = data;\n\t\t\tif (generateId !== undefined) {\n\t\t\t\tval.id = generateId ? generateId() : undefined;\n\t\t\t}\n\t\t\treturn await db[model].create({\n\t\t\t\tdata: val,\n\t\t\t\t...(select?.length\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tselect: select.reduce((prev, cur) => {\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t...prev,\n\t\t\t\t\t\t\t\t\t[cur]: true,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}, {}),\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t});\n\t\t},\n\t\tasync findOne(data) {\n\t\t\tconst { model, where, select } = data;\n\t\t\tconst whereClause = whereConvertor(where);\n\n\t\t\treturn await db[model].findFirst({\n\t\t\t\twhere: whereClause,\n\t\t\t\t...(select?.length\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tselect: select.reduce((prev, cur) => {\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t...prev,\n\t\t\t\t\t\t\t\t\t[cur]: true,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}, {}),\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t});\n\t\t},\n\t\tasync findMany(data) {\n\t\t\tconst { model, where, limit, offset, sortBy } = data;\n\n\t\t\tconst whereClause = whereConvertor(where);\n\n\t\t\treturn await db[model].findMany({\n\t\t\t\twhere: whereClause,\n\t\t\t\ttake: limit || 100,\n\t\t\t\tskip: offset || 0,\n\t\t\t\torderBy: sortBy?.field\n\t\t\t\t\t? {\n\t\t\t\t\t\t\t[sortBy.field]: sortBy.direction === \"desc\" ? \"desc\" : \"asc\",\n\t\t\t\t\t\t}\n\t\t\t\t\t: undefined,\n\t\t\t});\n\t\t},\n\t\tasync update(data) {\n\t\t\tconst { model, where, update } = data;\n\t\t\tif (update.id) {\n\t\t\t\tupdate.id = undefined;\n\t\t\t}\n\t\t\tconst whereClause = whereConvertor(where);\n\t\t\tif (where.length === 1) {\n\t\t\t\treturn await db[model].update({\n\t\t\t\t\twhere: whereClause,\n\t\t\t\t\tdata: update,\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn await db[model].updateMany({\n\t\t\t\twhere: whereClause,\n\t\t\t\tdata: update,\n\t\t\t});\n\t\t},\n\t\tasync delete(data) {\n\t\t\tconst { model, where } = data;\n\t\t\tconst whereClause = whereConvertor(where);\n\n\t\t\treturn await db[model].delete({ where: whereClause }).catch((e) => {\n\t\t\t\t//handle delete gracefully (if not found)\n\t\t\t});\n\t\t},\n\t\tasync deleteMany(data) {\n\t\t\tconst { model, where } = data;\n\t\t\tconst whereClause = whereConvertor(where);\n\n\t\t\treturn await db[model].deleteMany({ where: whereClause });\n\t\t},\n\t\toptions,\n\t};\n};\n"]}
|
package/dist/adapters/prisma.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import"../chunk-
|
|
1
|
+
import"../chunk-4C666HHU.js";function f(a){switch(a){case"starts_with":return"startsWith";case"ends_with":return"endsWith";default:return a}}function c(a){if(!a)return{};if(a.length===1){let e=a[0];return e?{[e.field]:e.operator==="eq"||!e.operator?e.value:{[f(e.operator)]:e.value}}:void 0}let l=a.filter(e=>e.connector==="AND"||!e.connector),s=a.filter(e=>e.connector==="OR"),o=l.map(e=>({[e.field]:e.operator==="eq"||!e.operator?e.value:{[f(e.operator)]:e.value}})),r=s.map(e=>({[e.field]:{[e.operator||"eq"]:e.value}}));return{AND:o.length?o:void 0,OR:r.length?r:void 0}}var y=(a,l)=>{let s=a,o=l.generateId;return{id:"prisma",async create(r){let{model:e,data:n,select:t}=r;return o!==void 0&&(n.id=o?o():void 0),await s[e].create({data:n,...t?.length?{select:t.reduce((d,i)=>({...d,[i]:!0}),{})}:{}})},async findOne(r){let{model:e,where:n,select:t}=r,d=c(n);return await s[e].findFirst({where:d,...t?.length?{select:t.reduce((i,u)=>({...i,[u]:!0}),{})}:{}})},async findMany(r){let{model:e,where:n,limit:t,offset:d,sortBy:i}=r,u=c(n);return await s[e].findMany({where:u,take:t||100,skip:d||0,orderBy:i?.field?{[i.field]:i.direction==="desc"?"desc":"asc"}:void 0})},async update(r){let{model:e,where:n,update:t}=r;t.id&&(t.id=void 0);let d=c(n);return n.length===1?await s[e].update({where:d,data:t}):await s[e].updateMany({where:d,data:t})},async delete(r){let{model:e,where:n}=r,t=c(n);return await s[e].delete({where:t}).catch(d=>{})},async deleteMany(r){let{model:e,where:n}=r,t=c(n);return await s[e].deleteMany({where:t})},options:l}};export{y as prismaAdapter};
|
|
2
|
+
//# sourceMappingURL=prisma.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/adapters/prisma-adapter/index.ts"],"sourcesContent":["import type { Adapter, Where } from \"../../types\";\n\nfunction operatorToPrismaOperator(operator: string) {\n\tswitch (operator) {\n\t\tcase \"starts_with\":\n\t\t\treturn \"startsWith\";\n\t\tcase \"ends_with\":\n\t\t\treturn \"endsWith\";\n\t\tdefault:\n\t\t\treturn operator;\n\t}\n}\n\nfunction whereConvertor(where?: Where[]) {\n\tif (!where) return {};\n\tif (where.length === 1) {\n\t\tconst w = where[0];\n\t\tif (!w) {\n\t\t\treturn;\n\t\t}\n\n\t\treturn {\n\t\t\t[w.field]:\n\t\t\t\tw.operator === \"eq\" || !w.operator\n\t\t\t\t\t? w.value\n\t\t\t\t\t: {\n\t\t\t\t\t\t\t[operatorToPrismaOperator(w.operator)]: w.value,\n\t\t\t\t\t\t},\n\t\t};\n\t}\n\tconst and = where.filter((w) => w.connector === \"AND\" || !w.connector);\n\tconst or = where.filter((w) => w.connector === \"OR\");\n\tconst andClause = and.map((w) => {\n\t\treturn {\n\t\t\t[w.field]:\n\t\t\t\tw.operator === \"eq\" || !w.operator\n\t\t\t\t\t? w.value\n\t\t\t\t\t: {\n\t\t\t\t\t\t\t[operatorToPrismaOperator(w.operator)]: w.value,\n\t\t\t\t\t\t},\n\t\t};\n\t});\n\tconst orClause = or.map((w) => {\n\t\treturn {\n\t\t\t[w.field]: {\n\t\t\t\t[w.operator || \"eq\"]: w.value,\n\t\t\t},\n\t\t};\n\t});\n\n\treturn {\n\t\tAND: andClause.length ? andClause : undefined,\n\t\tOR: orClause.length ? orClause : undefined,\n\t};\n}\n\ninterface PrismaClient {\n\t[model: string]: {\n\t\tcreate: (data: any) => Promise<any>;\n\t\tfindFirst: (data: any) => Promise<any>;\n\t\tfindMany: (data: any) => Promise<any>;\n\t\tupdate: (data: any) => Promise<any>;\n\t\tdelete: (data: any) => Promise<any>;\n\t\t[key: string]: any;\n\t};\n}\n\nexport const prismaAdapter = (\n\tprisma: any,\n\toptions: {\n\t\tprovider:\n\t\t\t| \"sqlite\"\n\t\t\t| \"cockroachdb\"\n\t\t\t| \"mysql\"\n\t\t\t| \"postgresql\"\n\t\t\t| \"sqlserver\"\n\t\t\t| \"mongodb\";\n\t\t/**\n\t\t * Custom generateId function.\n\t\t *\n\t\t * If not provided, nanoid will be used.\n\t\t * If set to false, the database's auto generated id will be used.\n\t\t *\n\t\t * @default nanoid\n\t\t */\n\t\tgenerateId?: ((size?: number) => string) | false;\n\t},\n): Adapter => {\n\tconst db: PrismaClient = prisma;\n\tconst generateId = options.generateId;\n\treturn {\n\t\tid: \"prisma\",\n\t\tasync create(data) {\n\t\t\tconst { model, data: val, select } = data;\n\t\t\tif (generateId !== undefined) {\n\t\t\t\tval.id = generateId ? generateId() : undefined;\n\t\t\t}\n\t\t\treturn await db[model].create({\n\t\t\t\tdata: val,\n\t\t\t\t...(select?.length\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tselect: select.reduce((prev, cur) => {\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t...prev,\n\t\t\t\t\t\t\t\t\t[cur]: true,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}, {}),\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t});\n\t\t},\n\t\tasync findOne(data) {\n\t\t\tconst { model, where, select } = data;\n\t\t\tconst whereClause = whereConvertor(where);\n\n\t\t\treturn await db[model].findFirst({\n\t\t\t\twhere: whereClause,\n\t\t\t\t...(select?.length\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tselect: select.reduce((prev, cur) => {\n\t\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t\t...prev,\n\t\t\t\t\t\t\t\t\t[cur]: true,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t}, {}),\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t});\n\t\t},\n\t\tasync findMany(data) {\n\t\t\tconst { model, where, limit, offset, sortBy } = data;\n\n\t\t\tconst whereClause = whereConvertor(where);\n\n\t\t\treturn await db[model].findMany({\n\t\t\t\twhere: whereClause,\n\t\t\t\ttake: limit || 100,\n\t\t\t\tskip: offset || 0,\n\t\t\t\torderBy: sortBy?.field\n\t\t\t\t\t? {\n\t\t\t\t\t\t\t[sortBy.field]: sortBy.direction === \"desc\" ? \"desc\" : \"asc\",\n\t\t\t\t\t\t}\n\t\t\t\t\t: undefined,\n\t\t\t});\n\t\t},\n\t\tasync update(data) {\n\t\t\tconst { model, where, update } = data;\n\t\t\tif (update.id) {\n\t\t\t\tupdate.id = undefined;\n\t\t\t}\n\t\t\tconst whereClause = whereConvertor(where);\n\t\t\tif (where.length === 1) {\n\t\t\t\treturn await db[model].update({\n\t\t\t\t\twhere: whereClause,\n\t\t\t\t\tdata: update,\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn await db[model].updateMany({\n\t\t\t\twhere: whereClause,\n\t\t\t\tdata: update,\n\t\t\t});\n\t\t},\n\t\tasync delete(data) {\n\t\t\tconst { model, where } = data;\n\t\t\tconst whereClause = whereConvertor(where);\n\n\t\t\treturn await db[model].delete({ where: whereClause }).catch((e) => {\n\t\t\t\t//handle delete gracefully (if not found)\n\t\t\t});\n\t\t},\n\t\tasync deleteMany(data) {\n\t\t\tconst { model, where } = data;\n\t\t\tconst whereClause = whereConvertor(where);\n\n\t\t\treturn await db[model].deleteMany({ where: whereClause });\n\t\t},\n\t\toptions,\n\t};\n};\n"],"mappings":"6BAEA,SAASA,EAAyBC,EAAkB,CACnD,OAAQA,EAAU,CACjB,IAAK,cACJ,MAAO,aACR,IAAK,YACJ,MAAO,WACR,QACC,OAAOA,CACT,CACD,CAEA,SAASC,EAAeC,EAAiB,CACxC,GAAI,CAACA,EAAO,MAAO,CAAC,EACpB,GAAIA,EAAM,SAAW,EAAG,CACvB,IAAMC,EAAID,EAAM,CAAC,EACjB,OAAKC,EAIE,CACN,CAACA,EAAE,KAAK,EACPA,EAAE,WAAa,MAAQ,CAACA,EAAE,SACvBA,EAAE,MACF,CACA,CAACJ,EAAyBI,EAAE,QAAQ,CAAC,EAAGA,EAAE,KAC3C,CACJ,EAVC,MAWF,CACA,IAAMC,EAAMF,EAAM,OAAQC,GAAMA,EAAE,YAAc,OAAS,CAACA,EAAE,SAAS,EAC/DE,EAAKH,EAAM,OAAQC,GAAMA,EAAE,YAAc,IAAI,EAC7CG,EAAYF,EAAI,IAAKD,IACnB,CACN,CAACA,EAAE,KAAK,EACPA,EAAE,WAAa,MAAQ,CAACA,EAAE,SACvBA,EAAE,MACF,CACA,CAACJ,EAAyBI,EAAE,QAAQ,CAAC,EAAGA,EAAE,KAC3C,CACJ,EACA,EACKI,EAAWF,EAAG,IAAKF,IACjB,CACN,CAACA,EAAE,KAAK,EAAG,CACV,CAACA,EAAE,UAAY,IAAI,EAAGA,EAAE,KACzB,CACD,EACA,EAED,MAAO,CACN,IAAKG,EAAU,OAASA,EAAY,OACpC,GAAIC,EAAS,OAASA,EAAW,MAClC,CACD,CAaO,IAAMC,EAAgB,CAC5BC,EACAC,IAkBa,CACb,IAAMC,EAAmBF,EACnBG,EAAaF,EAAQ,WAC3B,MAAO,CACN,GAAI,SACJ,MAAM,OAAOG,EAAM,CAClB,GAAM,CAAE,MAAAC,EAAO,KA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AAC,EAEK,MAAMZ,EAAGG,CAAK,EAAE,WAAW,CACjC,MAAOK,EACP,KAAMI,CACP,CAAC,CACF,EACA,MAAM,OAAOV,EAAM,CAClB,GAAM,CAAE,MAAAC,EAAO,MAAAZ,CAAM,EAAIW,EACnBM,EAAclB,EAAeC,CAAK,EAExC,OAAO,MAAMS,EAAGG,CAAK,EAAE,OAAO,CAAE,MAAOK,CAAY,CAAC,EAAE,MAAOK,GAAM,CAEnE,CAAC,CACF,EACA,MAAM,WAAWX,EAAM,CACtB,GAAM,CAAE,MAAAC,EAAO,MAAAZ,CAAM,EAAIW,EACnBM,EAAclB,EAAeC,CAAK,EAExC,OAAO,MAAMS,EAAGG,CAAK,EAAE,WAAW,CAAE,MAAOK,CAAY,CAAC,CACzD,EACA,QAAAT,CACD,CACD","names":["operatorToPrismaOperator","operator","whereConvertor","where","w","and","or","andClause","orClause","prismaAdapter","prisma","options","db","generateId","data","model","val","select","prev","cur","whereClause","limit","offset","sortBy","update","e"]}
|
package/dist/api.cjs
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkUGP43E4Icjs = require('./chunk-UGP43E4I.cjs');require('./chunk-5CGFZN2L.cjs');require('./chunk-2BBAB6DP.cjs');require('./chunk-4INQICGP.cjs');require('./chunk-U5FXGV3G.cjs');require('./chunk-DMAK6URH.cjs');require('./chunk-6YSOZOBL.cjs');require('./chunk-OQSWDMGG.cjs');require('./chunk-4CFYZITA.cjs');require('./chunk-LF4SJYGR.cjs');require('./chunk-WNGZ4EQP.cjs');require('./chunk-M4G6J7DP.cjs');exports.APIError = _chunkUGP43E4Icjs.J; exports.callbackOAuth = _chunkUGP43E4Icjs.r; exports.changeEmail = _chunkUGP43E4Icjs.A; exports.changePassword = _chunkUGP43E4Icjs.x; exports.createAuthEndpoint = _chunkUGP43E4Icjs.c; exports.createAuthMiddleware = _chunkUGP43E4Icjs.b; exports.createEmailVerificationToken = _chunkUGP43E4Icjs.l; exports.csrfMiddleware = _chunkUGP43E4Icjs.d; exports.deleteUser = _chunkUGP43E4Icjs.z; exports.error = _chunkUGP43E4Icjs.C; exports.forgetPassword = _chunkUGP43E4Icjs.t; exports.forgetPasswordCallback = _chunkUGP43E4Icjs.u; exports.getCSRFToken = _chunkUGP43E4Icjs.B; exports.getEndpoints = _chunkUGP43E4Icjs.H; exports.getSession = _chunkUGP43E4Icjs.f; exports.getSessionFromCtx = _chunkUGP43E4Icjs.g; exports.linkSocialAccount = _chunkUGP43E4Icjs.G; exports.listSessions = _chunkUGP43E4Icjs.i; exports.listUserAccounts = _chunkUGP43E4Icjs.F; exports.ok = _chunkUGP43E4Icjs.D; exports.optionsMiddleware = _chunkUGP43E4Icjs.a; exports.resetPassword = _chunkUGP43E4Icjs.v; exports.revokeSession = _chunkUGP43E4Icjs.j; exports.revokeSessions = _chunkUGP43E4Icjs.k; exports.router = _chunkUGP43E4Icjs.I; exports.sendVerificationEmail = _chunkUGP43E4Icjs.m; exports.sessionMiddleware = _chunkUGP43E4Icjs.h; exports.setPassword = _chunkUGP43E4Icjs.y; exports.signInEmail = _chunkUGP43E4Icjs.p; exports.signInOAuth = _chunkUGP43E4Icjs.o; exports.signOut = _chunkUGP43E4Icjs.s; exports.signUpEmail = _chunkUGP43E4Icjs.E; exports.updateUser = _chunkUGP43E4Icjs.w; exports.verifyEmail = _chunkUGP43E4Icjs.n;
|
|
2
|
+
//# sourceMappingURL=api.cjs.map
|
package/dist/api.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/beka/Desktop/Development/better-auth/packages/better-auth/dist/api.cjs"],"names":[],"mappings":"AAAA,iIAA2P,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,gCAA6B,+/CAAopB","file":"/Users/beka/Desktop/Development/better-auth/packages/better-auth/dist/api.cjs"}
|
package/dist/api.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
import{A as y,B as z,C as A,D as B,E as C,F as D,G as E,H as F,I as G,J as H,a,b,c,d,f as e,g as f,h as g,i as h,j as i,k as j,l as k,m as l,n as m,o as n,p as o,r as p,s as q,t as r,u as s,v as t,w as u,x as v,y as w,z as x}from"./chunk-
|
|
1
|
+
import{A as y,B as z,C as A,D as B,E as C,F as D,G as E,H as F,I as G,J as H,a,b,c,d,f as e,g as f,h as g,i as h,j as i,k as j,l as k,m as l,n as m,o as n,p as o,r as p,s as q,t as r,u as s,v as t,w as u,x as v,y as w,z as x}from"./chunk-S56R3UUZ.js";import"./chunk-57KKPQYR.js";import"./chunk-UMXT2JXJ.js";import"./chunk-L3RMKKWR.js";import"./chunk-4X5O2226.js";import"./chunk-TUL3AUOB.js";import"./chunk-C57CCQKY.js";import"./chunk-CO5UG7AX.js";import"./chunk-AFA2APLD.js";import"./chunk-4CY5SJAH.js";import"./chunk-GNYPEE5I.js";import"./chunk-4C666HHU.js";export{H as APIError,p as callbackOAuth,y as changeEmail,v as changePassword,c as createAuthEndpoint,b as createAuthMiddleware,k as createEmailVerificationToken,d as csrfMiddleware,x as deleteUser,A as error,r as forgetPassword,s as forgetPasswordCallback,z as getCSRFToken,F as getEndpoints,e as getSession,f as getSessionFromCtx,E as linkSocialAccount,h as listSessions,D as listUserAccounts,B as ok,a as optionsMiddleware,t as resetPassword,i as revokeSession,j as revokeSessions,G as router,l as sendVerificationEmail,g as sessionMiddleware,w as setPassword,o as signInEmail,n as signInOAuth,q as signOut,C as signUpEmail,u as updateUser,m as verifyEmail};
|
|
2
|
+
//# sourceMappingURL=api.js.map
|
package/dist/api.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunk4INQICGPcjs = require('./chunk-4INQICGP.cjs');var _chunkU5FXGV3Gcjs = require('./chunk-U5FXGV3G.cjs');var _chunkWNGZ4EQPcjs = require('./chunk-WNGZ4EQP.cjs');var _jwt = require('oslo/jwt');var m=r=>{let o="https://appleid.apple.com/auth/token";return{id:"apple",name:"Apple",createAuthorizationURL({state:e,scopes:t,redirectURI:i}){let a=t||["email","name","openid"];return r.scope&&a.push(...r.scope),new URL(`https://appleid.apple.com/auth/authorize?client_id=${r.clientId}&response_type=code&redirect_uri=${i||r.redirectURI}&scope=${a.join(" ")}&state=${e}`)},validateAuthorizationCode:async({code:e,codeVerifier:t,redirectURI:i})=>_chunkU5FXGV3Gcjs.g.call(void 0, {code:e,codeVerifier:t,redirectURI:r.redirectURI||i,options:r,tokenEndpoint:o}),async getUserInfo(e){if(!e.idToken)return null;let t=_optionalChain([_jwt.parseJWT.call(void 0, e.idToken), 'optionalAccess', _2 => _2.payload]);return t?{user:{id:t.sub,name:t.name,email:t.email,emailVerified:t.email_verified==="true"},data:t}:null}}};var _fetch = require('@better-fetch/fetch');var f=r=>({id:"discord",name:"Discord",createAuthorizationURL({state:o,scopes:e,redirectURI:t}){let i=e||["identify","email"];return r.scope&&i.push(...r.scope),new URL(`https://discord.com/api/oauth2/authorize?scope=${i.join("+")}&response_type=code&client_id=${r.clientId}&redirect_uri=${encodeURIComponent(r.redirectURI||t)}&state=${o}`)},validateAuthorizationCode:async({code:o,redirectURI:e})=>_chunkU5FXGV3Gcjs.g.call(void 0, {code:o,redirectURI:r.redirectURI||e,options:r,tokenEndpoint:"https://discord.com/api/oauth2/token"}),async getUserInfo(o){let{data:e,error:t}=await _fetch.betterFetch.call(void 0, "https://discord.com/api/users/@me",{headers:{authorization:`Bearer ${o.accessToken}`}});if(t)return null;if(e.avatar===null){let i=e.discriminator==="0"?Number(BigInt(e.id)>>BigInt(22))%6:parseInt(e.discriminator)%5;e.image_url=`https://cdn.discordapp.com/embed/avatars/${i}.png`}else{let i=e.avatar.startsWith("a_")?"gif":"png";e.image_url=`https://cdn.discordapp.com/avatars/${e.id}/${e.avatar}.${i}`}return{user:{id:e.id,name:e.display_name||e.username||"",email:e.email,emailVerified:e.verified,image:e.image_url},data:e}}});var h=r=>({id:"facebook",name:"Facebook",async createAuthorizationURL({state:o,scopes:e,redirectURI:t}){let i=e||["email","public_profile"];return r.scope&&i.push(...r.scope),await _chunkU5FXGV3Gcjs.f.call(void 0, {id:"facebook",options:r,authorizationEndpoint:"https://www.facebook.com/v21.0/dialog/oauth",scopes:i,state:o,redirectURI:t})},validateAuthorizationCode:async({code:o,redirectURI:e})=>_chunkU5FXGV3Gcjs.g.call(void 0, {code:o,redirectURI:r.redirectURI||e,options:r,tokenEndpoint:"https://graph.facebook.com/oauth/access_token"}),async getUserInfo(o){let{data:e,error:t}=await _fetch.betterFetch.call(void 0, "https://graph.facebook.com/me?fields=id,name,email,picture",{auth:{type:"Bearer",token:o.accessToken}});return t?null:{user:{id:e.id,name:e.name,email:e.email,image:e.picture.data.url,emailVerified:e.email_verified},data:e}}});var v=r=>{let o="https://github.com/login/oauth/access_token";return{id:"github",name:"GitHub",createAuthorizationURL({state:e,scopes:t,codeVerifier:i,redirectURI:a}){let s=t||["user:email"];return r.scope&&s.push(...r.scope),_chunkU5FXGV3Gcjs.f.call(void 0, {id:"github",options:r,authorizationEndpoint:"https://github.com/login/oauth/authorize",scopes:s,state:e,redirectURI:a,codeVerifier:i})},validateAuthorizationCode:async({code:e,redirectURI:t})=>_chunkU5FXGV3Gcjs.g.call(void 0, {code:e,redirectURI:r.redirectURI||t,options:r,tokenEndpoint:o}),async getUserInfo(e){let{data:t,error:i}=await _fetch.betterFetch.call(void 0, "https://api.github.com/user",{headers:{"User-Agent":"better-auth",authorization:`Bearer ${e.accessToken}`}});if(i)return null;let a=!1;if(!t.email){let{data:s,error:l}=await _fetch.betterFetch.call(void 0, "https://api.github.com/user/emails",{headers:{authorization:`Bearer ${e.accessToken}`,"User-Agent":"better-auth"}});l||(t.email=_optionalChain([(_nullishCoalesce(s.find(p=>p.primary), () => (s[0]))), 'optionalAccess', _3 => _3.email]),a=_nullishCoalesce(_optionalChain([s, 'access', _4 => _4.find, 'call', _5 => _5(p=>p.email===t.email), 'optionalAccess', _6 => _6.verified]), () => (!1)))}return{user:{id:t.id.toString(),name:t.name||t.login,email:t.email,image:t.avatar_url,emailVerified:a},data:t}}}};var b=r=>({id:"google",name:"Google",async createAuthorizationURL({state:o,scopes:e,codeVerifier:t,redirectURI:i}){if(!r.clientId||!r.clientSecret)throw _chunk4INQICGPcjs.b.error("Client Id and Client Secret is required for Google. Make sure to provide them in the options."),new (0, _chunkWNGZ4EQPcjs.a)("CLIENT_ID_AND_SECRET_REQUIRED");if(!t)throw new (0, _chunkWNGZ4EQPcjs.a)("codeVerifier is required for Google");let a=e||["email","profile","openid"];r.scope&&a.push(...r.scope);let s=await _chunkU5FXGV3Gcjs.f.call(void 0, {id:"google",options:r,authorizationEndpoint:"https://accounts.google.com/o/oauth2/auth",scopes:a,state:o,codeVerifier:t,redirectURI:i});return r.accessType&&s.searchParams.set("access_type",r.accessType),r.prompt&&s.searchParams.set("prompt",r.prompt),s},validateAuthorizationCode:async({code:o,codeVerifier:e,redirectURI:t})=>_chunkU5FXGV3Gcjs.g.call(void 0, {code:o,codeVerifier:e,redirectURI:r.redirectURI||t,options:r,tokenEndpoint:"https://oauth2.googleapis.com/token"}),async getUserInfo(o){if(!o.idToken)return null;let e=_optionalChain([_jwt.parseJWT.call(void 0, o.idToken), 'optionalAccess', _7 => _7.payload]);return{user:{id:e.sub,name:e.name,email:e.email,image:e.picture,emailVerified:e.email_verified},data:e}}});var _=r=>{let o=r.tenantId||"common",e=`https://login.microsoftonline.com/${o}/oauth2/v2.0/authorize`,t=`https://login.microsoftonline.com/${o}/oauth2/v2.0/token`;return{id:"microsoft",name:"Microsoft EntraID",createAuthorizationURL(i){let a=i.scopes||["openid","profile","email","User.Read"];return r.scope&&a.push(...r.scope),_chunkU5FXGV3Gcjs.f.call(void 0, {id:"microsoft",options:r,authorizationEndpoint:e,state:i.state,codeVerifier:i.codeVerifier,scopes:a,redirectURI:i.redirectURI})},validateAuthorizationCode({code:i,codeVerifier:a,redirectURI:s}){return _chunkU5FXGV3Gcjs.g.call(void 0, {code:i,codeVerifier:a,redirectURI:r.redirectURI||s,options:r,tokenEndpoint:t})},async getUserInfo(i){if(!i.idToken)return null;let a=_optionalChain([_jwt.parseJWT.call(void 0, i.idToken), 'optionalAccess', _8 => _8.payload]),s=r.profilePhotoSize||48;return await _fetch.betterFetch.call(void 0, `https://graph.microsoft.com/v1.0/me/photos/${s}x${s}/$value`,{headers:{Authorization:`Bearer ${i.accessToken}`},async onResponse(l){if(!(r.disableProfilePhoto||!l.response.ok))try{let k=await l.response.clone().arrayBuffer(),w=Buffer.from(k).toString("base64");a.picture=`data:image/jpeg;base64, ${w}`}catch(p){_chunk4INQICGPcjs.b.error(p)}}}),{user:{id:a.sub,name:a.name,email:a.email,image:a.picture,emailVerified:!0},data:a}}}};var y=r=>({id:"spotify",name:"Spotify",createAuthorizationURL({state:o,scopes:e,codeVerifier:t,redirectURI:i}){let a=e||["user-read-email"];return r.scope&&a.push(...r.scope),_chunkU5FXGV3Gcjs.f.call(void 0, {id:"spotify",options:r,authorizationEndpoint:"https://accounts.spotify.com/authorize",scopes:a,state:o,codeVerifier:t,redirectURI:i})},validateAuthorizationCode:async({code:o,codeVerifier:e,redirectURI:t})=>_chunkU5FXGV3Gcjs.g.call(void 0, {code:o,codeVerifier:e,redirectURI:r.redirectURI||t,options:r,tokenEndpoint:"https://accounts.spotify.com/api/token"}),async getUserInfo(o){let{data:e,error:t}=await _fetch.betterFetch.call(void 0, "https://api.spotify.com/v1/me",{method:"GET",headers:{Authorization:`Bearer ${o.accessToken}`}});return t?null:{user:{id:e.id,name:e.display_name,email:e.email,image:_optionalChain([e, 'access', _9 => _9.images, 'access', _10 => _10[0], 'optionalAccess', _11 => _11.url]),emailVerified:!1},data:e}}});var de={isAction:!1};var P=r=>({id:"twitch",name:"Twitch",createAuthorizationURL({state:o,scopes:e,redirectURI:t}){let i=e||["user:read:email","openid"];return r.scope&&i.push(...r.scope),_chunkU5FXGV3Gcjs.f.call(void 0, {id:"twitch",redirectURI:t,options:r,authorizationEndpoint:"https://id.twitch.tv/oauth2/authorize",scopes:i,state:o,claims:r.claims||["email","email_verified","preferred_username","picture"]})},validateAuthorizationCode:async({code:o,redirectURI:e})=>_chunkU5FXGV3Gcjs.g.call(void 0, {code:o,redirectURI:r.redirectURI||e,options:r,tokenEndpoint:"https://id.twitch.tv/oauth2/token"}),async getUserInfo(o){let e=o.idToken;if(!e)return _chunk4INQICGPcjs.b.error("No idToken found in token"),null;let t=_optionalChain([_jwt.parseJWT.call(void 0, e), 'optionalAccess', _12 => _12.payload]);return{user:{id:t.sub,name:t.preferred_username,email:t.email,image:t.picture,emailVerified:!1},data:t}}});var A=r=>({id:"twitter",name:"Twitter",createAuthorizationURL(o){let e=o.scopes||["account_info.read"];return r.scope&&e.push(...r.scope),_chunkU5FXGV3Gcjs.f.call(void 0, {id:"twitter",options:r,authorizationEndpoint:"https://twitter.com/i/oauth2/authorize",scopes:e,state:o.state,codeVerifier:o.codeVerifier,redirectURI:o.redirectURI})},validateAuthorizationCode:async({code:o,codeVerifier:e,redirectURI:t})=>_chunkU5FXGV3Gcjs.g.call(void 0, {code:o,codeVerifier:e,redirectURI:r.redirectURI||t,options:r,tokenEndpoint:"https://id.twitch.tv/oauth2/token"}),async getUserInfo(o){let{data:e,error:t}=await _fetch.betterFetch.call(void 0, "https://api.x.com/2/users/me?user.fields=profile_image_url",{method:"GET",headers:{Authorization:`Bearer ${o.accessToken}`}});return t||!e.data.email?null:{user:{id:e.data.id,name:e.data.name,email:e.data.email,image:e.data.profile_image_url,emailVerified:e.data.verified||!1},data:e}}});var x=r=>{let o="https://api.dropboxapi.com/oauth2/token";return{id:"dropbox",name:"Dropbox",createAuthorizationURL:async({state:e,scopes:t,codeVerifier:i,redirectURI:a})=>{let s=t||["account_info.read"];return r.scope&&s.push(...r.scope),await _chunkU5FXGV3Gcjs.f.call(void 0, {id:"dropbox",options:r,authorizationEndpoint:"https://www.dropbox.com/oauth2/authorize",scopes:s,state:e,redirectURI:a,codeVerifier:i})},validateAuthorizationCode:async({code:e,codeVerifier:t,redirectURI:i})=>await _chunkU5FXGV3Gcjs.g.call(void 0, {code:e,codeVerifier:t,redirectURI:r.redirectURI||i,options:r,tokenEndpoint:o}),async getUserInfo(e){let{data:t,error:i}=await _fetch.betterFetch.call(void 0, "https://api.dropboxapi.com/2/users/get_current_account",{method:"POST",headers:{Authorization:`Bearer ${e.accessToken}`}});return i?null:{user:{id:t.account_id,name:_optionalChain([t, 'access', _13 => _13.name, 'optionalAccess', _14 => _14.display_name]),email:t.email,emailVerified:t.email_verified||!1,image:t.profile_photo_url},data:t}}}};var z=r=>{let o="https://www.linkedin.com/oauth/v2/authorization",e="https://www.linkedin.com/oauth/v2/accessToken";return{id:"linkedin",name:"Linkedin",createAuthorizationURL:async({state:t,scopes:i,redirectURI:a})=>{let s=i||["profile","email","openid"];return r.scope&&s.push(...r.scope),await _chunkU5FXGV3Gcjs.f.call(void 0, {id:"linkedin",options:r,authorizationEndpoint:o,scopes:s,state:t,redirectURI:a})},validateAuthorizationCode:async({code:t,redirectURI:i})=>await _chunkU5FXGV3Gcjs.g.call(void 0, {code:t,redirectURI:r.redirectURI||i,options:r,tokenEndpoint:e}),async getUserInfo(t){let{data:i,error:a}=await _fetch.betterFetch.call(void 0, "https://api.linkedin.com/v2/userinfo",{method:"GET",headers:{Authorization:`Bearer ${t.accessToken}`}});return a?null:{user:{id:i.sub,name:i.name,email:i.email,emailVerified:i.email_verified||!1,image:i.picture},data:i}}}};var B={apple:m,discord:f,facebook:h,github:v,microsoft:_,google:b,spotify:y,twitch:P,twitter:A,dropbox:x,linkedin:z},We= exports.n =Object.keys(B);exports.a = m; exports.b = f; exports.c = h; exports.d = v; exports.e = b; exports.f = _; exports.g = y; exports.h = de; exports.i = P; exports.j = A; exports.k = x; exports.l = z; exports.m = B; exports.n = We;
|
|
2
|
+
//# sourceMappingURL=chunk-2BBAB6DP.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/beka/Desktop/Development/better-auth/packages/better-auth/dist/chunk-2BBAB6DP.cjs","../src/social-providers/apple.ts"],"names":["apple","options","tokenEndpoint","state","scopes","redirectURI","_scope"],"mappings":"AAAA,yuBAAwC,wDAAgD,wDAAyC,+BCCxG,IA+CZA,CAAAA,CAASC,CAAAA,EAA0B,CAC/C,IAAMC,CAAAA,CAAgB,sCAAA,CACtB,MAAO,CACN,EAAA,CAAI,OAAA,CACJ,IAAA,CAAM,OAAA,CACN,sBAAA,CAAuB,CAAE,KAAA,CAAAC,CAAAA,CAAO,MAAA,CAAAC,CAAAA,CAAQ,WAAA,CAAAC,CAAY,CAAA,CAAG,CACtD,IAAMC,CAAAA,CAASF,CAAAA,EAAU,CAAC,OAAA,CAAS,MAAA,CAAQ,QAAQ,CAAA,CACnD,OAAAH,CAAAA,CAAQ,KAAA,EAASK,CAAAA,CAAO,IAAA,CAAK,GAAGL,CAAAA,CAAQ,KAAK,CAAA,CACtC,IAAI,GAAA,CACV,CAAA,mDAAA,EACCA,CAAAA,CAAQ,QACT,CAAA,iCAAA,EACCI,CAAAA,EAAeJ,CAAAA,CAAQ,WACxB,CAAA,OAAA,EAAUK,CAAAA,CAAO,IAAA,CAAK,GAAG,CAAC,CAAA,OAAA,EAAUH,CAAK,CAAA,CAAA","file":"/Users/beka/Desktop/Development/better-auth/packages/better-auth/dist/chunk-2BBAB6DP.cjs","sourcesContent":[null,"import type { OAuthProvider, ProviderOptions } from \"../oauth2\";\nimport { parseJWT } from \"oslo/jwt\";\nimport { validateAuthorizationCode } from \"../oauth2\";\nexport interface AppleProfile {\n\t/**\n\t * The subject registered claim identifies the principal that’s the subject\n\t * of the identity token. Because this token is for your app, the value is\n\t * the unique identifier for the user.\n\t */\n\tsub: string;\n\t/**\n\t * A String value representing the user's email address.\n\t * The email address is either the user's real email address or the proxy\n\t * address, depending on their status private email relay service.\n\t */\n\temail: string;\n\t/**\n\t * A string or Boolean value that indicates whether the service verifies\n\t * the email. The value can either be a string (\"true\" or \"false\") or a\n\t * Boolean (true or false). The system may not verify email addresses for\n\t * Sign in with Apple at Work & School users, and this claim is \"false\" or\n\t * false for those users.\n\t */\n\temail_verified: true | \"true\";\n\t/**\n\t * A string or Boolean value that indicates whether the email that the user\n\t * shares is the proxy address. The value can either be a string (\"true\" or\n\t * \"false\") or a Boolean (true or false).\n\t */\n\tis_private_email: boolean;\n\t/**\n\t * An Integer value that indicates whether the user appears to be a real\n\t * person. Use the value of this claim to mitigate fraud. The possible\n\t * values are: 0 (or Unsupported), 1 (or Unknown), 2 (or LikelyReal). For\n\t * more information, see ASUserDetectionStatus. This claim is present only\n\t * in iOS 14 and later, macOS 11 and later, watchOS 7 and later, tvOS 14\n\t * and later. The claim isn’t present or supported for web-based apps.\n\t */\n\treal_user_status: number;\n\t/**\n\t * The user’s full name in the format provided during the authorization\n\t * process.\n\t */\n\tname: string;\n}\n\nexport interface AppleOptions extends ProviderOptions {}\n\nexport const apple = (options: AppleOptions) => {\n\tconst tokenEndpoint = \"https://appleid.apple.com/auth/token\";\n\treturn {\n\t\tid: \"apple\",\n\t\tname: \"Apple\",\n\t\tcreateAuthorizationURL({ state, scopes, redirectURI }) {\n\t\t\tconst _scope = scopes || [\"email\", \"name\", \"openid\"];\n\t\t\toptions.scope && _scope.push(...options.scope);\n\t\t\treturn new URL(\n\t\t\t\t`https://appleid.apple.com/auth/authorize?client_id=${\n\t\t\t\t\toptions.clientId\n\t\t\t\t}&response_type=code&redirect_uri=${\n\t\t\t\t\tredirectURI || options.redirectURI\n\t\t\t\t}&scope=${_scope.join(\" \")}&state=${state}`,\n\t\t\t);\n\t\t},\n\t\tvalidateAuthorizationCode: async ({ code, codeVerifier, redirectURI }) => {\n\t\t\treturn validateAuthorizationCode({\n\t\t\t\tcode,\n\t\t\t\tcodeVerifier,\n\t\t\t\tredirectURI: options.redirectURI || redirectURI,\n\t\t\t\toptions,\n\t\t\t\ttokenEndpoint,\n\t\t\t});\n\t\t},\n\t\tasync getUserInfo(token) {\n\t\t\tif (!token.idToken) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\tconst data = parseJWT(token.idToken)?.payload as AppleProfile | null;\n\t\t\tif (!data) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tuser: {\n\t\t\t\t\tid: data.sub,\n\t\t\t\t\tname: data.name,\n\t\t\t\t\temail: data.email,\n\t\t\t\t\temailVerified: data.email_verified === \"true\",\n\t\t\t\t},\n\t\t\t\tdata,\n\t\t\t};\n\t\t},\n\t} satisfies OAuthProvider<AppleProfile>;\n};\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as s,b as i,d as r}from"./chunk-GOLT3J43.js";import{a as o}from"./chunk-C57CCQKY.js";function O(p){let{pluginPathMethods:f,pluginsActions:l,pluginsAtoms:t,$fetch:e,atomListeners:m}=s(p),n={};for(let[a,g]of Object.entries(t))n[`use${o(a)}`]=g;let{$session:c,_sessionSignal:u}=r(e),y={...l,...n,$fetch:e,useSession:c};return i(y,e,f,{...t,_sessionSignal:u},m)}export{O as a};
|
|
2
|
+
//# sourceMappingURL=chunk-3AAEZ2OW.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client/vanilla.ts"],"sourcesContent":["import { getClientConfig } from \"./config\";\nimport { capitalizeFirstLetter } from \"../utils/misc\";\nimport type {\n\tBetterAuthClientPlugin,\n\tClientOptions,\n\tInferActions,\n\tInferClientAPI,\n\tInferSessionFromClient,\n\tInferUserFromClient,\n\tIsSignal,\n} from \"./types\";\nimport { createDynamicPathProxy } from \"./proxy\";\nimport { getSessionAtom } from \"./session-atom\";\nimport type { UnionToIntersection } from \"../types/helper\";\n\ntype InferResolvedHooks<O extends ClientOptions> = O[\"plugins\"] extends Array<\n\tinfer Plugin\n>\n\t? Plugin extends BetterAuthClientPlugin\n\t\t? Plugin[\"getAtoms\"] extends (fetch: any) => infer Atoms\n\t\t\t? Atoms extends Record<string, any>\n\t\t\t\t? {\n\t\t\t\t\t\t[key in keyof Atoms as IsSignal<key> extends true\n\t\t\t\t\t\t\t? never\n\t\t\t\t\t\t\t: key extends string\n\t\t\t\t\t\t\t\t? `use${Capitalize<key>}`\n\t\t\t\t\t\t\t\t: never]: Atoms[key];\n\t\t\t\t\t}\n\t\t\t\t: {}\n\t\t\t: {}\n\t\t: {}\n\t: {};\n\nexport function createAuthClient<Option extends ClientOptions>(\n\toptions?: Option,\n) {\n\tconst {\n\t\tpluginPathMethods,\n\t\tpluginsActions,\n\t\tpluginsAtoms,\n\t\t$fetch,\n\t\tatomListeners,\n\t} = getClientConfig(options);\n\tlet resolvedHooks: Record<string, any> = {};\n\tfor (const [key, value] of Object.entries(pluginsAtoms)) {\n\t\tresolvedHooks[`use${capitalizeFirstLetter(key)}`] = value;\n\t}\n\n\tconst { $session, _sessionSignal } = getSessionAtom<Option>($fetch);\n\tconst routes = {\n\t\t...pluginsActions,\n\t\t...resolvedHooks,\n\t\t$fetch,\n\t\tuseSession: $session,\n\t};\n\tconst proxy = createDynamicPathProxy(\n\t\troutes,\n\t\t$fetch,\n\t\tpluginPathMethods,\n\t\t{\n\t\t\t...pluginsAtoms,\n\t\t\t_sessionSignal,\n\t\t},\n\t\tatomListeners,\n\t);\n\treturn proxy as UnionToIntersection<InferResolvedHooks<Option>> &\n\t\tInferClientAPI<Option> &\n\t\tInferActions<Option> & {\n\t\t\tuseSession: typeof $session;\n\t\t\t$fetch: typeof $fetch;\n\t\t\t$Infer: {\n\t\t\t\tSession: {\n\t\t\t\t\tsession: InferSessionFromClient<Option>;\n\t\t\t\t\tuser: InferUserFromClient<Option>;\n\t\t\t\t};\n\t\t\t};\n\t\t};\n}\n"],"mappings":"8FAiCO,SAASA,EACfC,EACC,CACD,GAAM,CACL,kBAAAC,EACA,eAAAC,EACA,aAAAC,EACA,OAAAC,EACA,cAAAC,CACD,EAAIC,EAAgBN,CAAO,EACvBO,EAAqC,CAAC,EAC1C,OAAW,CAACC,EAAKC,CAAK,IAAK,OAAO,QAAQN,CAAY,EACrDI,EAAc,MAAMG,EAAsBF,CAAG,CAAC,EAAE,EAAIC,EAGrD,GAAM,CAAE,SAAAE,EAAU,eAAAC,CAAe,EAAIC,EAAuBT,CAAM,EAC5DU,EAAS,CACd,GAAGZ,EACH,GAAGK,EACH,OAAAH,EACA,WAAYO,CACb,EAWA,OAVcI,EACbD,EACAV,EACAH,EACA,CACC,GAAGE,EACH,eAAAS,CACD,EACAP,CACD,CAaD","names":["createAuthClient","options","pluginPathMethods","pluginsActions","pluginsAtoms","$fetch","atomListeners","getClientConfig","resolvedHooks","key","value","capitalizeFirstLetter","$session","_sessionSignal","getSessionAtom","routes","createDynamicPathProxy"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});function i(f,a){let n=new Uint8Array(f),e=new Uint8Array(a);if(n.length!==e.length)return!1;let t=0;for(let r=0;r<n.length;r++)t|=n[r]^e[r];return t===0}exports.a = i;
|
|
2
|
+
//# sourceMappingURL=chunk-4CFYZITA.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/crypto/buffer.ts"],"names":["constantTimeEqual","a","b","aBuffer","bBuffer","c","i"],"mappings":"AAGO,kFAASA,CAAAA,CACfC,CAAAA,CACAC,CAAAA,CACU,CACV,IAAMC,CAAAA,CAAU,IAAI,UAAA,CAAWF,CAAC,CAAA,CAC1BG,CAAAA,CAAU,IAAI,UAAA,CAAWF,CAAC,CAAA,CAChC,EAAA,CAAIC,CAAAA,CAAQ,MAAA,GAAWC,CAAAA,CAAQ,MAAA,CAC9B,MAAO,CAAA,CAAA,CAER,IAAIC,CAAAA,CAAI,CAAA,CACR,GAAA,CAAA,IAASC,CAAAA,CAAI,CAAA,CAAGA,CAAAA,CAAIH,CAAAA,CAAQ,MAAA,CAAQG,CAAAA,EAAAA,CACnCD,CAAAA,EAAKF,CAAAA,CAAQG,CAAC,CAAA,CAAKF,CAAAA,CAAQE,CAAC,CAAA,CAE7B,OAAOD,CAAAA,GAAM,CACd,CAAA,cAAA","file":"/Users/beka/Desktop/Development/better-auth/packages/better-auth/dist/chunk-4CFYZITA.cjs","sourcesContent":["/**\n * Compare two buffers in constant time.\n */\nexport function constantTimeEqual(\n\ta: ArrayBuffer | Uint8Array,\n\tb: ArrayBuffer | Uint8Array,\n): boolean {\n\tconst aBuffer = new Uint8Array(a);\n\tconst bBuffer = new Uint8Array(b);\n\tif (aBuffer.length !== bBuffer.length) {\n\t\treturn false;\n\t}\n\tlet c = 0;\n\tfor (let i = 0; i < aBuffer.length; i++) {\n\t\tc |= aBuffer[i]! ^ bBuffer[i]!; // ^: XOR operator\n\t}\n\treturn c === 0;\n}\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as c}from"./chunk-GNYPEE5I.js";import{TimeSpan as C}from"oslo";import{env as h,isProduction as k}from"std-env";function g(e){let o=(e.advanced?.useSecureCookies!==void 0?e.advanced?.useSecureCookies:e.baseURL!==void 0?!!e.baseURL.startsWith("https://"):k)?"__Secure-":"",s="better-auth",a=e.session?.expiresIn||new C(7,"d").seconds(),t=!!e.advanced?.crossSubDomainCookies?.enabled,n=t?e.advanced?.crossSubDomainCookies?.domain||(e.baseURL?new URL(e.baseURL).hostname:void 0):void 0;if(t&&!n)throw new c("baseURL is required when crossSubdomainCookies are enabled");let i=t?"none":"lax";return{sessionToken:{name:`${o}${s}.session_token`,options:{httpOnly:!0,sameSite:i,path:"/",secure:!!o,maxAge:a,...t?{domain:n}:{}}},sessionData:{name:`${o}${s}.session_data`,options:{httpOnly:!0,sameSite:i,path:"/",secure:!!o,maxAge:e.session?.cookieCache?.maxAge||60*5,...t?{domain:n}:{}}},csrfToken:{name:`${o}${s}.csrf_token`,options:{httpOnly:!0,sameSite:i,path:"/",secure:!!o,maxAge:60*60*24*7,...t?{domain:n}:{}}},state:{name:`${o}${s}.state`,options:{httpOnly:!0,sameSite:i,path:"/",secure:!!o,maxAge:60*15,...t?{domain:n}:{}}},pkCodeVerifier:{name:`${o}${s}.pk_code_verifier`,options:{httpOnly:!0,sameSite:i,path:"/",secure:!!o,maxAge:60*15,...t?{domain:n}:{}}},dontRememberToken:{name:`${o}${s}.dont_remember`,options:{httpOnly:!0,sameSite:i,path:"/",secure:!!o,...t?{domain:n}:{}}},nonce:{name:`${o}${s}.nonce`,options:{httpOnly:!0,sameSite:i,path:"/",secure:!!o,maxAge:60*15,...t?{domain:n}:{}}}}}function S(e){let o=(e.advanced?.useSecureCookies!==void 0?e.advanced?.useSecureCookies:e.baseURL?.startsWith("https://")||k)?"__Secure-":"",s="better-auth",a=e.advanced?.crossSubDomainCookies?.domain||(e.baseURL?new URL(e.baseURL).hostname:void 0);function t(n,i){let u=e.advanced?.crossSubDomainCookies?.enabled?e.advanced.crossSubDomainCookies.additionalCookies?.includes(n):void 0;return{name:h.NODE_ENV==="production"?`${o}${s}.${n}`:`${s}.${n}`,options:{secure:!!o,sameSite:"lax",path:"/",maxAge:60*15,...i,...u?{domain:a}:{}}}}return t}async function x(e,r,o,s){let a=e.context.authCookies.sessionToken.options;a.maxAge=o?void 0:e.context.sessionConfig.expiresIn,await e.setSignedCookie(e.context.authCookies.sessionToken.name,r.session.id,e.context.secret,{...a,...s}),o&&await e.setSignedCookie(e.context.authCookies.dontRememberToken.name,"true",e.context.secret,e.context.authCookies.dontRememberToken.options),e.context.options.session?.cookieCache?.enabled&&await e.setSignedCookie(e.context.authCookies.sessionData.name,JSON.stringify(r),e.context.secret,e.context.authCookies.sessionData.options)}function O(e){e.setCookie(e.context.authCookies.sessionToken.name,"",{maxAge:0}),e.setCookie(e.context.authCookies.sessionData.name,"",{maxAge:0}),e.setCookie(e.context.authCookies.dontRememberToken.name,"",{maxAge:0})}function y(e){let r=new Map;return e.split(", ").forEach(s=>{let[a,...t]=s.split("; "),[n,i]=a.split("="),u={value:i};t.forEach(p=>{let[d,m]=p.split("=");u[d.toLowerCase()]=m||!0}),r.set(n,u)}),r}function A(e){let r=e.split("; "),o=new Map;return r.forEach(s=>{let[a,t]=s.split("=");o.set(a,t)}),o}export{g as a,S as b,x as c,O as d,y as e,A as f};
|
|
2
|
+
//# sourceMappingURL=chunk-4CY5SJAH.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cookies/index.ts"],"sourcesContent":["import type { CookieOptions } from \"better-call\";\nimport { TimeSpan } from \"oslo\";\nimport type { BetterAuthOptions } from \"../types/options\";\nimport type { GenericEndpointContext } from \"../types/context\";\nimport { BetterAuthError } from \"../error\";\nimport { env, isProduction } from \"std-env\";\nimport type { Session, User } from \"../types\";\n\nexport function getCookies(options: BetterAuthOptions) {\n\tconst secure =\n\t\toptions.advanced?.useSecureCookies !== undefined\n\t\t\t? options.advanced?.useSecureCookies\n\t\t\t: options.baseURL !== undefined\n\t\t\t\t? options.baseURL.startsWith(\"https://\")\n\t\t\t\t\t? true\n\t\t\t\t\t: false\n\t\t\t\t: isProduction;\n\n\tconst secureCookiePrefix = secure ? \"__Secure-\" : \"\";\n\tconst cookiePrefix = \"better-auth\";\n\tconst sessionMaxAge =\n\t\toptions.session?.expiresIn || new TimeSpan(7, \"d\").seconds();\n\tconst crossSubdomainEnabled =\n\t\t!!options.advanced?.crossSubDomainCookies?.enabled;\n\n\tconst domain = crossSubdomainEnabled\n\t\t? options.advanced?.crossSubDomainCookies?.domain ||\n\t\t\t(options.baseURL ? new URL(options.baseURL).hostname : undefined)\n\t\t: undefined;\n\n\tif (crossSubdomainEnabled && !domain) {\n\t\tthrow new BetterAuthError(\n\t\t\t\"baseURL is required when crossSubdomainCookies are enabled\",\n\t\t);\n\t}\n\n\tconst sameSite = crossSubdomainEnabled ? \"none\" : \"lax\";\n\treturn {\n\t\tsessionToken: {\n\t\t\tname: `${secureCookiePrefix}${cookiePrefix}.session_token`,\n\t\t\toptions: {\n\t\t\t\thttpOnly: true,\n\t\t\t\tsameSite,\n\t\t\t\tpath: \"/\",\n\t\t\t\tsecure: !!secureCookiePrefix,\n\t\t\t\tmaxAge: sessionMaxAge,\n\t\t\t\t...(crossSubdomainEnabled ? { domain } : {}),\n\t\t\t} satisfies CookieOptions,\n\t\t},\n\t\t/**\n\t\t * This cookie is used to store the session data in the cookie\n\t\t * This is useful for when you want to cache the session in the cookie\n\t\t */\n\t\tsessionData: {\n\t\t\tname: `${secureCookiePrefix}${cookiePrefix}.session_data`,\n\t\t\toptions: {\n\t\t\t\thttpOnly: true,\n\t\t\t\tsameSite,\n\t\t\t\tpath: \"/\",\n\t\t\t\tsecure: !!secureCookiePrefix,\n\t\t\t\tmaxAge: options.session?.cookieCache?.maxAge || 60 * 5,\n\t\t\t\t...(crossSubdomainEnabled ? { domain } : {}),\n\t\t\t} satisfies CookieOptions,\n\t\t},\n\t\tcsrfToken: {\n\t\t\tname: `${secureCookiePrefix}${cookiePrefix}.csrf_token`,\n\t\t\toptions: {\n\t\t\t\thttpOnly: true,\n\t\t\t\tsameSite,\n\t\t\t\tpath: \"/\",\n\t\t\t\tsecure: !!secureCookiePrefix,\n\t\t\t\tmaxAge: 60 * 60 * 24 * 7,\n\t\t\t\t...(crossSubdomainEnabled ? { domain } : {}),\n\t\t\t} satisfies CookieOptions,\n\t\t},\n\t\tstate: {\n\t\t\tname: `${secureCookiePrefix}${cookiePrefix}.state`,\n\t\t\toptions: {\n\t\t\t\thttpOnly: true,\n\t\t\t\tsameSite,\n\t\t\t\tpath: \"/\",\n\t\t\t\tsecure: !!secureCookiePrefix,\n\t\t\t\tmaxAge: 60 * 15,\n\t\t\t\t...(crossSubdomainEnabled ? { domain } : {}),\n\t\t\t} satisfies CookieOptions,\n\t\t},\n\t\tpkCodeVerifier: {\n\t\t\tname: `${secureCookiePrefix}${cookiePrefix}.pk_code_verifier`,\n\t\t\toptions: {\n\t\t\t\thttpOnly: true,\n\t\t\t\tsameSite,\n\t\t\t\tpath: \"/\",\n\t\t\t\tsecure: !!secureCookiePrefix,\n\t\t\t\tmaxAge: 60 * 15,\n\t\t\t\t...(crossSubdomainEnabled ? { domain } : {}),\n\t\t\t} as CookieOptions,\n\t\t},\n\t\tdontRememberToken: {\n\t\t\tname: `${secureCookiePrefix}${cookiePrefix}.dont_remember`,\n\t\t\toptions: {\n\t\t\t\thttpOnly: true,\n\t\t\t\tsameSite,\n\t\t\t\tpath: \"/\",\n\t\t\t\tsecure: !!secureCookiePrefix,\n\t\t\t\t//no max age so it expires when the browser closes\n\t\t\t\t...(crossSubdomainEnabled ? { domain } : {}),\n\t\t\t} as CookieOptions,\n\t\t},\n\t\tnonce: {\n\t\t\tname: `${secureCookiePrefix}${cookiePrefix}.nonce`,\n\t\t\toptions: {\n\t\t\t\thttpOnly: true,\n\t\t\t\tsameSite,\n\t\t\t\tpath: \"/\",\n\t\t\t\tsecure: !!secureCookiePrefix,\n\t\t\t\tmaxAge: 60 * 15,\n\t\t\t\t...(crossSubdomainEnabled ? { domain } : {}),\n\t\t\t} as CookieOptions,\n\t\t},\n\t};\n}\n\nexport function createCookieGetter(options: BetterAuthOptions) {\n\tconst secure =\n\t\toptions.advanced?.useSecureCookies !== undefined\n\t\t\t? options.advanced?.useSecureCookies\n\t\t\t: options.baseURL?.startsWith(\"https://\") || isProduction;\n\tconst secureCookiePrefix = secure ? \"__Secure-\" : \"\";\n\tconst cookiePrefix = \"better-auth\";\n\n\tconst domain =\n\t\toptions.advanced?.crossSubDomainCookies?.domain ||\n\t\t(options.baseURL ? new URL(options.baseURL).hostname : undefined);\n\n\tfunction getCookie(cookieName: string, opts?: CookieOptions) {\n\t\tconst crossSubdomainEnabled = options.advanced?.crossSubDomainCookies\n\t\t\t?.enabled\n\t\t\t? options.advanced.crossSubDomainCookies.additionalCookies?.includes(\n\t\t\t\t\tcookieName,\n\t\t\t\t)\n\t\t\t: undefined;\n\t\treturn {\n\t\t\tname:\n\t\t\t\tenv.NODE_ENV === \"production\"\n\t\t\t\t\t? `${secureCookiePrefix}${cookiePrefix}.${cookieName}`\n\t\t\t\t\t: `${cookiePrefix}.${cookieName}`,\n\t\t\toptions: {\n\t\t\t\tsecure: !!secureCookiePrefix,\n\t\t\t\tsameSite: \"lax\",\n\t\t\t\tpath: \"/\",\n\t\t\t\tmaxAge: 60 * 15, // 15 minutes in seconds\n\t\t\t\t...opts,\n\t\t\t\t...(crossSubdomainEnabled ? { domain } : {}),\n\t\t\t} as CookieOptions,\n\t\t};\n\t}\n\treturn getCookie;\n}\nexport type BetterAuthCookies = ReturnType<typeof getCookies>;\n\nexport async function setSessionCookie(\n\tctx: GenericEndpointContext,\n\tsession: {\n\t\tsession: Session;\n\t\tuser: User;\n\t},\n\tdontRememberMe?: boolean,\n\toverrides?: Partial<CookieOptions>,\n) {\n\tconst options = ctx.context.authCookies.sessionToken.options;\n\t//@ts-expect-error\n\toptions.maxAge = dontRememberMe\n\t\t? undefined\n\t\t: ctx.context.sessionConfig.expiresIn;\n\n\tawait ctx.setSignedCookie(\n\t\tctx.context.authCookies.sessionToken.name,\n\t\tsession.session.id,\n\t\tctx.context.secret,\n\t\t{\n\t\t\t...options,\n\t\t\t...overrides,\n\t\t},\n\t);\n\tif (dontRememberMe) {\n\t\tawait ctx.setSignedCookie(\n\t\t\tctx.context.authCookies.dontRememberToken.name,\n\t\t\t\"true\",\n\t\t\tctx.context.secret,\n\t\t\tctx.context.authCookies.dontRememberToken.options,\n\t\t);\n\t}\n\tconst shouldStoreSessionDataInCookie =\n\t\tctx.context.options.session?.cookieCache?.enabled;\n\tshouldStoreSessionDataInCookie &&\n\t\t(await ctx.setSignedCookie(\n\t\t\tctx.context.authCookies.sessionData.name,\n\t\t\tJSON.stringify(session),\n\t\t\tctx.context.secret,\n\t\t\tctx.context.authCookies.sessionData.options,\n\t\t));\n}\n\nexport function deleteSessionCookie(ctx: GenericEndpointContext) {\n\tctx.setCookie(ctx.context.authCookies.sessionToken.name, \"\", {\n\t\tmaxAge: 0,\n\t});\n\tctx.setCookie(ctx.context.authCookies.sessionData.name, \"\", {\n\t\tmaxAge: 0,\n\t});\n\tctx.setCookie(ctx.context.authCookies.dontRememberToken.name, \"\", {\n\t\tmaxAge: 0,\n\t});\n}\n\ntype CookieAttributes = {\n\tvalue: string;\n\t[key: string]: string | boolean;\n};\n\nexport function parseSetCookieHeader(\n\theader: string,\n): Map<string, CookieAttributes> {\n\tconst cookieMap = new Map<string, CookieAttributes>();\n\n\t// Split the header into individual cookies\n\tconst cookies = header.split(\", \");\n\n\tcookies.forEach((cookie) => {\n\t\tconst [nameValue, ...attributes] = cookie.split(\"; \");\n\t\tconst [name, value] = nameValue.split(\"=\");\n\n\t\tconst cookieObj: CookieAttributes = { value };\n\n\t\tattributes.forEach((attr) => {\n\t\t\tconst [attrName, attrValue] = attr.split(\"=\");\n\t\t\tcookieObj[attrName.toLowerCase()] = attrValue || true;\n\t\t});\n\n\t\tcookieMap.set(name, cookieObj);\n\t});\n\n\treturn cookieMap;\n}\nexport function parseCookies(cookieHeader: string) {\n\tconst cookies = cookieHeader.split(\"; \");\n\tconst cookieMap = new Map<string, string>();\n\n\tcookies.forEach((cookie) => {\n\t\tconst [name, value] = cookie.split(\"=\");\n\t\tcookieMap.set(name, value);\n\t});\n\treturn cookieMap;\n}\n\nexport type EligibleCookies = (string & {}) | (keyof BetterAuthCookies & {});\n"],"mappings":"wCACA,OAAS,YAAAA,MAAgB,OAIzB,OAAS,OAAAC,EAAK,gBAAAC,MAAoB,UAG3B,SAASC,EAAWC,EAA4B,CAUtD,IAAMC,GARLD,EAAQ,UAAU,mBAAqB,OACpCA,EAAQ,UAAU,iBAClBA,EAAQ,UAAY,OACnB,EAAAA,EAAQ,QAAQ,WAAW,UAAU,EAGrCF,GAE+B,YAAc,GAC5CI,EAAe,cACfC,EACLH,EAAQ,SAAS,WAAa,IAAII,EAAS,EAAG,GAAG,EAAE,QAAQ,EACtDC,EACL,CAAC,CAACL,EAAQ,UAAU,uBAAuB,QAEtCM,EAASD,EACZL,EAAQ,UAAU,uBAAuB,SACzCA,EAAQ,QAAU,IAAI,IAAIA,EAAQ,OAAO,EAAE,SAAW,QACtD,OAEH,GAAIK,GAAyB,CAACC,EAC7B,MAAM,IAAIC,EACT,4DACD,EAGD,IAAMC,EAAWH,EAAwB,OAAS,MAClD,MAAO,CACN,aAAc,CACb,KAAM,GAAGJ,CAAkB,GAAGC,CAAY,iBAC1C,QAAS,CACR,SAAU,GACV,SAAAM,EACA,KAAM,IACN,OAAQ,CAAC,CAACP,EACV,OAAQE,EACR,GAAIE,EAAwB,CAAE,OAAAC,CAAO,EAAI,CAAC,CAC3C,CACD,EAKA,YAAa,CACZ,KAAM,GAAGL,CAAkB,GAAGC,CAAY,gBAC1C,QAAS,CACR,SAAU,GACV,SAAAM,EACA,KAAM,IACN,OAAQ,CAAC,CAACP,EACV,OAAQD,EAAQ,SAAS,aAAa,QAAU,GAAK,EACrD,GAAIK,EAAwB,CAAE,OAAAC,CAAO,EAAI,CAAC,CAC3C,CACD,EACA,UAAW,CACV,KAAM,GAAGL,CAAkB,GAAGC,CAAY,cAC1C,QAAS,CACR,SAAU,GACV,SAAAM,EACA,KAAM,IACN,O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EACgC,CAChC,IAAMC,EAAY,IAAI,IAKtB,OAFgBD,EAAO,MAAM,IAAI,EAEzB,QAASE,GAAW,CAC3B,GAAM,CAACC,EAAW,GAAGC,CAAU,EAAIF,EAAO,MAAM,IAAI,EAC9C,CAACG,EAAMC,CAAK,EAAIH,EAAU,MAAM,GAAG,EAEnCI,EAA8B,CAAE,MAAAD,CAAM,EAE5CF,EAAW,QAASI,GAAS,CAC5B,GAAM,CAACC,EAAUC,CAAS,EAAIF,EAAK,MAAM,GAAG,EAC5CD,EAAUE,EAAS,YAAY,CAAC,EAAIC,GAAa,EAClD,CAAC,EAEDT,EAAU,IAAII,EAAME,CAAS,CAC9B,CAAC,EAEMN,CACR,CACO,SAASU,EAAaC,EAAsB,CAClD,IAAMC,EAAUD,EAAa,MAAM,IAAI,EACjCX,EAAY,IAAI,IAEtB,OAAAY,EAAQ,QAASX,GAAW,CAC3B,GAAM,CAACG,EAAMC,CAAK,EAAIJ,EAAO,MAAM,GAAG,EACtCD,EAAU,IAAII,EAAMC,CAAK,CAC1B,CAAC,EACML,CACR","names":["TimeSpan","env","isProduction","getCookies","options","secureCookiePrefix","cookiePrefix","sessionMaxAge","TimeSpan","crossSubdomainEnabled","domain","BetterAuthError","sameSite","createCookieGetter","getCookie","cookieName","opts","setSessionCookie","ctx","session","dontRememberMe","overrides","deleteSessionCookie","parseSetCookieHeader","header","cookieMap","cookie","nameValue","attributes","name","value","cookieObj","attr","attrName","attrValue","parseCookies","cookieHeader","cookies"]}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _consola = require('consola');var r=_consola.createConsola.call(void 0, {formatOptions:{date:!1,colors:!0,compact:!0},defaults:{tag:"Better Auth"}}),o= exports.a =a=>({log:(...e)=>{!_optionalChain([a, 'optionalAccess', _ => _.disabled])&&r.log("",...e)},error:(...e)=>{!_optionalChain([a, 'optionalAccess', _2 => _2.disabled])&&r.error("",...e)},warn:(...e)=>{!_optionalChain([a, 'optionalAccess', _3 => _3.disabled])&&r.warn("",...e)},info:(...e)=>{!_optionalChain([a, 'optionalAccess', _4 => _4.disabled])&&r.info("",...e)},debug:(...e)=>{!_optionalChain([a, 'optionalAccess', _5 => _5.disabled])&&r.debug("",...e)},box:(...e)=>{!_optionalChain([a, 'optionalAccess', _6 => _6.disabled])&&r.box("",...e)},success:(...e)=>{!_optionalChain([a, 'optionalAccess', _7 => _7.disabled])&&r.success("",...e)},break:(...e)=>{!_optionalChain([a, 'optionalAccess', _8 => _8.disabled])&&console.log(`
|
|
2
|
+
`)}}),s= exports.b =o();var _nanoid = require('nanoid');var c=a=>_nanoid.nanoid.call(void 0, a);exports.a = o; exports.b = s; exports.c = c;
|
|
3
|
+
//# sourceMappingURL=chunk-4INQICGP.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/logger.ts","../src/utils/id.ts"],"names":["consola","createConsola","createLogger","options","args","logger","generateId","size","nanoid"],"mappings":"AAAA,+mBAA8B,IAExBA,CAAAA,CAAUC,oCAAAA,CACf,aAAA,CAAe,CACd,IAAA,CAAM,CAAA,CAAA,CACN,MAAA,CAAQ,CAAA,CAAA,CACR,OAAA,CAAS,CAAA,CACV,CAAA,CACA,QAAA,CAAU,CACT,GAAA,CAAK,aACN,CACD,CAAC,CAAA,CAEYC,CAAAA,aAAgBC,CAAAA,EAAAA,CAGrB,CACN,GAAA,CAAK,CAAA,GAAIC,CAAAA,CAAAA,EAAgB,CACxB,iBAACD,CAAAA,2BAAS,UAAA,E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,IAEVI,CAAAA,CAAcC,CAAAA,EACnBC,4BAAAA,CAAW,CAAA,CAAA,4CAAA","file":"/Users/beka/Desktop/Development/better-auth/packages/better-auth/dist/chunk-4INQICGP.cjs","sourcesContent":["import { createConsola } from \"consola\";\n\nconst consola = createConsola({\n\tformatOptions: {\n\t\tdate: false,\n\t\tcolors: true,\n\t\tcompact: true,\n\t},\n\tdefaults: {\n\t\ttag: \"Better Auth\",\n\t},\n});\n\nexport const createLogger = (options?: {\n\tdisabled?: boolean;\n}) => {\n\treturn {\n\t\tlog: (...args: any[]) => {\n\t\t\t!options?.disabled && consola.log(\"\", ...args);\n\t\t},\n\t\terror: (...args: any[]) => {\n\t\t\t!options?.disabled && consola.error(\"\", ...args);\n\t\t},\n\t\twarn: (...args: any[]) => {\n\t\t\t!options?.disabled && consola.warn(\"\", ...args);\n\t\t},\n\t\tinfo: (...args: any[]) => {\n\t\t\t!options?.disabled && consola.info(\"\", ...args);\n\t\t},\n\t\tdebug: (...args: any[]) => {\n\t\t\t!options?.disabled && consola.debug(\"\", ...args);\n\t\t},\n\t\tbox: (...args: any[]) => {\n\t\t\t!options?.disabled && consola.box(\"\", ...args);\n\t\t},\n\t\tsuccess: (...args: any[]) => {\n\t\t\t!options?.disabled && consola.success(\"\", ...args);\n\t\t},\n\t\tbreak: (...args: any[]) => {\n\t\t\t!options?.disabled && console.log(\"\\n\");\n\t\t},\n\t};\n};\n\nexport const logger = createLogger();\n","import { nanoid } from \"nanoid\";\n\nexport const generateId = (size?: number) => {\n\treturn nanoid(size);\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=chunk-4LSFAAZW.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{a as u}from"./chunk-TUL3AUOB.js";import{a as l}from"./chunk-AFA2APLD.js";import{sha256 as _}from"oslo/crypto";import{base64url as P}from"oslo/encoding";async function g(e){let t=await _(new TextEncoder().encode(e));return P.encode(new Uint8Array(t),{includePadding:!1})}function h(e){return{tokenType:e.token_type,accessToken:e.access_token,refreshToken:e.refresh_token,accessTokenExpiresAt:e.expires_in?u(e.expires_in,"sec"):void 0,scopes:e?.scope?typeof e.scope=="string"?e.scope.split(" "):e.scope:[],idToken:e.id_token}}async function U({id:e,options:t,authorizationEndpoint:s,state:r,codeVerifier:a,scopes:o,claims:c,disablePkce:p,redirectURI:m}){let n=new URL(s);if(n.searchParams.set("response_type","code"),n.searchParams.set("client_id",t.clientId),n.searchParams.set("state",r),n.searchParams.set("scope",o.join(" ")),n.searchParams.set("redirect_uri",t.redirectURI||m),!p&&a){let f=await g(a);n.searchParams.set("code_challenge_method","S256"),n.searchParams.set("code_challenge",f)}if(c){let f=c.reduce((d,x)=>(d[x]=null,d),{});n.searchParams.set("claims",JSON.stringify({id_token:{email:null,email_verified:null,...f}}))}return n}import{betterFetch as b}from"@better-fetch/fetch";async function E({code:e,codeVerifier:t,redirectURI:s,options:r,tokenEndpoint:a}){let o=new URLSearchParams;o.set("grant_type","authorization_code"),o.set("code",e),t&&o.set("code_verifier",t),o.set("redirect_uri",s),o.set("client_id",r.clientId),o.set("client_secret",r.clientSecret);let{data:c,error:p}=await b(a,{method:"POST",body:o,headers:{"content-type":"application/x-www-form-urlencoded",accept:"application/json","user-agent":"better-auth"}});if(p)throw p;return h(c)}import{generateState as w}from"oslo/oauth2";import{z as i}from"zod";import{sha256 as y}from"oslo/crypto";async function k(e){let t=await y(typeof e=="string"?new TextEncoder().encode(e):e);return Buffer.from(t).toString("base64")}async function L(e,t){let s=await y(typeof e=="string"?new TextEncoder().encode(e):e),r=Buffer.from(t,"base64");return l(s,r)}async function F(e,t){let s=w(),r=JSON.stringify({code:s,callbackURL:e,link:t}),a=await k(r);return{raw:r,hash:a}}function H(e){return i.object({code:i.string(),callbackURL:i.string().optional(),currentURL:i.string().optional(),link:i.object({email:i.string(),userId:i.string()}).optional()}).safeParse(JSON.parse(e))}export{L as a,F as b,H as c,g as d,h as e,U as f,E as g};
|
|
2
|
+
//# sourceMappingURL=chunk-4X5O2226.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/oauth2/utils.ts","../src/oauth2/create-authorization-url.ts","../src/oauth2/validate-authorization-code.ts","../src/oauth2/state.ts","../src/crypto/hash.ts"],"sourcesContent":["import { sha256 } from \"oslo/crypto\";\nimport { base64url } from \"oslo/encoding\";\nimport type { OAuth2Tokens } from \"./types\";\nimport { getDate } from \"../utils/date\";\n\nexport async function generateCodeChallenge(codeVerifier: string) {\n\tconst codeChallengeBytes = await sha256(\n\t\tnew TextEncoder().encode(codeVerifier),\n\t);\n\treturn base64url.encode(new Uint8Array(codeChallengeBytes), {\n\t\tincludePadding: false,\n\t});\n}\n\nexport function getOAuth2Tokens(data: Record<string, any>): OAuth2Tokens {\n\treturn {\n\t\ttokenType: data.token_type,\n\t\taccessToken: data.access_token,\n\t\trefreshToken: data.refresh_token,\n\t\taccessTokenExpiresAt: data.expires_in\n\t\t\t? getDate(data.expires_in, \"sec\")\n\t\t\t: undefined,\n\t\tscopes: data?.scope\n\t\t\t? typeof data.scope === \"string\"\n\t\t\t\t? data.scope.split(\" \")\n\t\t\t\t: data.scope\n\t\t\t: [],\n\t\tidToken: data.id_token,\n\t};\n}\n","import type { ProviderOptions } from \"./types\";\nimport { generateCodeChallenge } from \"./utils\";\n\nexport async function createAuthorizationURL({\n\tid,\n\toptions,\n\tauthorizationEndpoint,\n\tstate,\n\tcodeVerifier,\n\tscopes,\n\tclaims,\n\tdisablePkce,\n\tredirectURI,\n}: {\n\tid: string;\n\toptions: ProviderOptions;\n\tredirectURI: string;\n\tauthorizationEndpoint: string;\n\tstate: string;\n\tcodeVerifier?: string;\n\tscopes: string[];\n\tdisablePkce?: boolean;\n\tclaims?: string[];\n}) {\n\tconst url = new URL(authorizationEndpoint);\n\turl.searchParams.set(\"response_type\", \"code\");\n\turl.searchParams.set(\"client_id\", options.clientId);\n\turl.searchParams.set(\"state\", state);\n\turl.searchParams.set(\"scope\", scopes.join(\" \"));\n\turl.searchParams.set(\"redirect_uri\", options.redirectURI || redirectURI);\n\n\tif (!disablePkce && codeVerifier) {\n\t\tconst codeChallenge = await generateCodeChallenge(codeVerifier);\n\t\turl.searchParams.set(\"code_challenge_method\", \"S256\");\n\t\turl.searchParams.set(\"code_challenge\", codeChallenge);\n\t}\n\tif (claims) {\n\t\tconst claimsObj = claims.reduce(\n\t\t\t(acc, claim) => {\n\t\t\t\tacc[claim] = null;\n\t\t\t\treturn acc;\n\t\t\t},\n\t\t\t{} as Record<string, null>,\n\t\t);\n\t\turl.searchParams.set(\n\t\t\t\"claims\",\n\t\t\tJSON.stringify({\n\t\t\t\tid_token: { email: null, email_verified: null, ...claimsObj },\n\t\t\t}),\n\t\t);\n\t}\n\treturn url;\n}\n","import { betterFetch } from \"@better-fetch/fetch\";\nimport type { ProviderOptions } from \"./types\";\nimport { getOAuth2Tokens } from \"./utils\";\n\nexport async function validateAuthorizationCode({\n\tcode,\n\tcodeVerifier,\n\tredirectURI,\n\toptions,\n\ttokenEndpoint,\n}: {\n\tcode: string;\n\tredirectURI: string;\n\toptions: ProviderOptions;\n\tcodeVerifier?: string;\n\ttokenEndpoint: string;\n}) {\n\tconst body = new URLSearchParams();\n\tbody.set(\"grant_type\", \"authorization_code\");\n\tbody.set(\"code\", code);\n\tcodeVerifier && body.set(\"code_verifier\", codeVerifier);\n\tbody.set(\"redirect_uri\", redirectURI);\n\tbody.set(\"client_id\", options.clientId);\n\tbody.set(\"client_secret\", options.clientSecret);\n\tconst { data, error } = await betterFetch<object>(tokenEndpoint, {\n\t\tmethod: \"POST\",\n\t\tbody: body,\n\t\theaders: {\n\t\t\t\"content-type\": \"application/x-www-form-urlencoded\",\n\t\t\taccept: \"application/json\",\n\t\t\t\"user-agent\": \"better-auth\",\n\t\t},\n\t});\n\tif (error) {\n\t\tthrow error;\n\t}\n\tconst tokens = getOAuth2Tokens(data);\n\treturn tokens;\n}\n","import { generateState as generateStateOAuth } from \"oslo/oauth2\";\nimport { z } from \"zod\";\nimport { hashToBase64 } from \"../crypto/hash\";\n\nexport async function generateState(\n\tcallbackURL?: string,\n\tlink?: {\n\t\temail: string;\n\t\tuserId: string;\n\t},\n) {\n\tconst code = generateStateOAuth();\n\tconst raw = JSON.stringify({\n\t\tcode,\n\t\tcallbackURL,\n\t\tlink,\n\t});\n\tconst hash = await hashToBase64(raw);\n\treturn { raw, hash };\n}\n\nexport function parseState(state: string) {\n\tconst data = z\n\t\t.object({\n\t\t\tcode: z.string(),\n\t\t\tcallbackURL: z.string().optional(),\n\t\t\tcurrentURL: z.string().optional(),\n\t\t\tlink: z\n\t\t\t\t.object({\n\t\t\t\t\temail: z.string(),\n\t\t\t\t\tuserId: z.string(),\n\t\t\t\t})\n\t\t\t\t.optional(),\n\t\t})\n\t\t.safeParse(JSON.parse(state));\n\treturn data;\n}\n","import { sha256 } from \"oslo/crypto\";\nimport { constantTimeEqual } from \"./buffer\";\n\nexport async function hashToBase64(\n\tdata: string | ArrayBuffer,\n): Promise<string> {\n\tconst buffer = await sha256(\n\t\ttypeof data === \"string\" ? new TextEncoder().encode(data) : data,\n\t);\n\treturn Buffer.from(buffer).toString(\"base64\");\n}\n\nexport async function compareHash(\n\tdata: string | ArrayBuffer,\n\thash: string,\n): Promise<boolean> {\n\tconst buffer = await sha256(\n\t\ttypeof data === \"string\" ? new TextEncoder().encode(data) : data,\n\t);\n\tconst hashBuffer = Buffer.from(hash, \"base64\");\n\treturn constantTimeEqual(buffer, hashBuffer);\n}\n"],"mappings":"gFAAA,OAAS,UAAAA,MAAc,cACvB,OAAS,aAAAC,MAAiB,gBAI1B,eAAsBC,EAAsBC,EAAsB,CACjE,IAAMC,EAAqB,MAAMC,EAChC,IAAI,YAAY,EAAE,OAAOF,CAAY,CACtC,EACA,OAAOG,EAAU,OAAO,IAAI,WAAWF,CAAkB,EA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AWC,EAAe,CAczC,OAbaC,EACX,OAAO,CACP,KAAMA,EAAE,OAAO,EACf,YAAaA,EAAE,OAAO,EAAE,SAAS,EACjC,WAAYA,EAAE,OAAO,EAAE,SAAS,EAChC,KAAMA,EACJ,OAAO,CACP,MAAOA,EAAE,OAAO,EAChB,OAAQA,EAAE,OAAO,CAClB,CAAC,EACA,SAAS,CACZ,CAAC,EACA,UAAU,KAAK,MAAMD,CAAK,CAAC,CAE9B","names":["sha256","base64url","generateCodeChallenge","codeVerifier","codeChallengeBytes","sha256","base64url","getOAuth2Tokens","data","getDate","createAuthorizationURL","id","options","authorizationEndpoint","state","codeVerifier","scopes","claims","disablePkce","redirectURI","url","codeChallenge","generateCodeChallenge","claimsObj","acc","claim","betterFetch","validateAuthorizationCode","code","codeVerifier","redirectURI","options","tokenEndpoint","body","data","error","betterFetch","getOAuth2Tokens","generateStateOAuth","z","sha256","hashToBase64","data","buffer","sha256","compareHash","hash","hashBuffer","constantTimeEqual","generateState","callbackURL","link","code","generateStateOAuth","raw","hash","hashToBase64","parseState","state","z"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{isTest as f}from"std-env";function l(e){let n="127.0.0.1";if(f)return n;let i=["x-client-ip","x-forwarded-for","cf-connecting-ip","fastly-client-ip","x-real-ip","x-cluster-client-ip","x-forwarded","forwarded-for","forwarded"],o=e instanceof Request?e.headers:e;for(let s of i){let t=o.get(s);if(typeof t=="string"){let r=t.split(",")[0].trim();if(r)return r}}return null}export{l as a};
|
|
2
|
+
//# sourceMappingURL=chunk-57KKPQYR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/get-request-ip.ts"],"sourcesContent":["import { isTest } from \"std-env\";\n\nexport function getIp(req: Request | Headers): string | null {\n\tconst testIP = \"127.0.0.1\";\n\tif (isTest) {\n\t\treturn testIP;\n\t}\n\tconst keys = [\n\t\t\"x-client-ip\",\n\t\t\"x-forwarded-for\",\n\t\t\"cf-connecting-ip\",\n\t\t\"fastly-client-ip\",\n\t\t\"x-real-ip\",\n\t\t\"x-cluster-client-ip\",\n\t\t\"x-forwarded\",\n\t\t\"forwarded-for\",\n\t\t\"forwarded\",\n\t];\n\tconst headers = req instanceof Request ? req.headers : req;\n\tfor (const key of keys) {\n\t\tconst value = headers.get(key);\n\t\tif (typeof value === \"string\") {\n\t\t\tconst ip = value.split(\",\")[0].trim();\n\t\t\tif (ip) return ip;\n\t\t}\n\t}\n\treturn null;\n}\n"],"mappings":"AAAA,OAAS,UAAAA,MAAc,UAEhB,SAASC,EAAMC,EAAuC,CAC5D,IAAMC,EAAS,YACf,GAAIH,EACH,OAAOG,EAER,IAAMC,EAAO,CACZ,cACA,kBACA,mBACA,mBACA,YACA,sBACA,cACA,gBACA,WACD,EACMC,EAAUH,aAAe,QAAUA,EAAI,QAAUA,EACvD,QAAWI,KAAOF,EAAM,CACvB,IAAMG,EAAQF,EAAQ,IAAIC,CAAG,EAC7B,GAAI,OAAOC,GAAU,SAAU,CAC9B,IAAMC,EAAKD,EAAM,MAAM,GAAG,EAAE,CAAC,EAAE,KAAK,EACpC,GAAIC,EAAI,OAAOA,CAChB,CACD,CACA,OAAO,IACR","names":["isTest","getIp","req","testIP","keys","headers","key","value","ip"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var _stdenv = require('std-env');function l(e){let n="127.0.0.1";if(_stdenv.isTest)return n;let i=["x-client-ip","x-forwarded-for","cf-connecting-ip","fastly-client-ip","x-real-ip","x-cluster-client-ip","x-forwarded","forwarded-for","forwarded"],o=e instanceof Request?e.headers:e;for(let s of i){let t=o.get(s);if(typeof t=="string"){let r=t.split(",")[0].trim();if(r)return r}}return null}exports.a = l;
|
|
2
|
+
//# sourceMappingURL=chunk-5CGFZN2L.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/get-request-ip.ts"],"names":["getIp","req","testIP","isTest","keys","headers","key","value","ip"],"mappings":"AAAA,0GAAuB,SAEPA,CAAAA,CAAMC,CAAAA,CAAuC,CAC5D,IAAMC,CAAAA,CAAS,WAAA,CACf,EAAA,CAAIC,cAAAA,CACH,OAAOD,CAAAA,CAER,IAAME,CAAAA,CAAO,CACZ,aAAA,CACA,iBAAA,CACA,kBAAA,CACA,kBAAA,CACA,WAAA,CACA,qBAAA,CACA,aAAA,CACA,eAAA,CACA,WACD,CAAA,CACMC,CAAAA,CAAUJ,EAAAA,WAAe,OAAA,CAAUA,CAAAA,CAAI,OAAA,CAAUA,CAAAA,CACvD,GAAA,CAAA,IAAWK,EAAAA,GAAOF,CAAAA,CAAM,CACvB,IAAMG,CAAAA,CAAQF,CAAAA,CAAQ,GAAA,CAAIC,CAAG,CAAA,CAC7B,EAAA,CAAI,OAAOC,CAAAA,EAAU,QAAA,CAAU,CAC9B,IAAMC,CAAAA,CAAKD,CAAAA,CAAM,KAAA,CAAM,GAAG,CAAA,CAAE,CAAC,CAAA,CAAE,IAAA,CAAK,CAAA,CACpC,EAAA,CAAIC,CAAAA,CAAI,OAAOA,CAChB,CACD,CACA,OAAO,IACR,CAAA,cAAA","file":"/Users/beka/Desktop/Development/better-auth/packages/better-auth/dist/chunk-5CGFZN2L.cjs","sourcesContent":["import { isTest } from \"std-env\";\n\nexport function getIp(req: Request | Headers): string | null {\n\tconst testIP = \"127.0.0.1\";\n\tif (isTest) {\n\t\treturn testIP;\n\t}\n\tconst keys = [\n\t\t\"x-client-ip\",\n\t\t\"x-forwarded-for\",\n\t\t\"cf-connecting-ip\",\n\t\t\"fastly-client-ip\",\n\t\t\"x-real-ip\",\n\t\t\"x-cluster-client-ip\",\n\t\t\"x-forwarded\",\n\t\t\"forwarded-for\",\n\t\t\"forwarded\",\n\t];\n\tconst headers = req instanceof Request ? req.headers : req;\n\tfor (const key of keys) {\n\t\tconst value = headers.get(key);\n\t\tif (typeof value === \"string\") {\n\t\t\tconst ip = value.split(\",\")[0].trim();\n\t\t\tif (ip) return ip;\n\t\t}\n\t}\n\treturn null;\n}\n"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _chunkH5ZHLIW4cjs = require('./chunk-H5ZHLIW4.cjs');var _chunkWNGZ4EQPcjs = require('./chunk-WNGZ4EQP.cjs');var _fetch = require('@better-fetch/fetch');var _nanostores = require('nanostores');var F={id:"redirect",name:"Redirect",hooks:{onSuccess(e){_optionalChain([e, 'access', _ => _.data, 'optionalAccess', _2 => _2.url])&&_optionalChain([e, 'access', _3 => _3.data, 'optionalAccess', _4 => _4.redirect])&&typeof window<"u"&&(window.location.href=e.data.url)}}},b={id:"add-current-url",name:"Add current URL",hooks:{onRequest(e){if(typeof window<"u"){let r=new URL(e.url);r.searchParams.set("currentURL",window.location.href),e.url=r}return e}}},R={id:"csrf",name:"CSRF Check",async init(e,r){if(_optionalChain([r, 'optionalAccess', _5 => _5.method])!=="GET"){r=r||{};let{data:a,error:s}=await _fetch.betterFetch.call(void 0, "/csrf",{body:void 0,baseURL:r.baseURL,plugins:[],method:"GET",credentials:"include",customFetchImpl:r.customFetchImpl});if(s){if(s.status===404)throw new (0, _chunkWNGZ4EQPcjs.a)("CSRF route not found. Make sure the server is running and the base URL is correct and includes the path (e.g. http://localhost:3000/api/auth).");if(s.status===429)return new Response(JSON.stringify({message:"Too many requests. Please try again later."}),{status:429,statusText:"Too Many Requests"});throw new (0, _chunkWNGZ4EQPcjs.a)("Failed to fetch CSRF token: "+s.message)}let n=_optionalChain([a, 'optionalAccess', _6 => _6.csrfToken]);r.body={..._optionalChain([r, 'optionalAccess', _7 => _7.body]),csrfToken:n}}return r.credentials="include",{url:e,options:r}}};var $=e=>{let r=_fetch.createFetch.call(void 0, {baseURL:_chunkH5ZHLIW4cjs.a.call(void 0, _optionalChain([e, 'optionalAccess', _8 => _8.fetchOptions, 'optionalAccess', _9 => _9.baseURL])||_optionalChain([e, 'optionalAccess', _10 => _10.baseURL])),method:"GET",..._optionalChain([e, 'optionalAccess', _11 => _11.fetchOptions]),plugins:_optionalChain([e, 'optionalAccess', _12 => _12.disableDefaultFetchPlugins])?_optionalChain([e, 'access', _13 => _13.fetchOptions, 'optionalAccess', _14 => _14.plugins]):[..._optionalChain([e, 'optionalAccess', _15 => _15.disableCSRFTokenCheck])?[]:[R],F,b,..._optionalChain([e, 'optionalAccess', _16 => _16.fetchOptions, 'optionalAccess', _17 => _17.plugins, 'optionalAccess', _18 => _18.filter, 'call', _19 => _19(t=>t!==void 0)])||[],..._optionalChain([e, 'optionalAccess', _20 => _20.plugins, 'optionalAccess', _21 => _21.flatMap, 'call', _22 => _22(t=>t.fetchPlugins), 'access', _23 => _23.filter, 'call', _24 => _24(t=>t!==void 0)])||[]]}),a=_optionalChain([e, 'optionalAccess', _25 => _25.plugins])||[],s={},n={},u={"/sign-out":"POST","/user/revoke-sessions":"POST"},o=[{signal:"_sessionSignal",matcher(t){return t==="/sign-out"||t==="/user/update"||t.startsWith("/sign-in")||t.startsWith("/sign-up")}}];for(let t of a)t.getActions&&Object.assign(s,_optionalChain([t, 'access', _26 => _26.getActions, 'optionalCall', _27 => _27(r)])),t.getAtoms&&Object.assign(n,_optionalChain([t, 'access', _28 => _28.getAtoms, 'optionalCall', _29 => _29(r)])),t.pathMethods&&Object.assign(u,t.pathMethods),t.atomListeners&&o.push(...t.atomListeners);return{pluginsActions:s,pluginsAtoms:n,pluginPathMethods:u,atomListeners:o,$fetch:r}};function E(e,r,a){let s=r[e],{fetchOptions:n,query:u,...o}=a||{};return s||(_optionalChain([n, 'optionalAccess', _30 => _30.method])?n.method:o&&Object.keys(o).length>0?"POST":"GET")}function Q(e,r,a,s,n){function u(o=[]){return new Proxy(function(){},{get(t,c){let l=[...o,c],i=e;for(let f of l)if(i&&typeof i=="object"&&f in i)i=i[f];else{i=void 0;break}return typeof i=="function"?i:u(l)},apply:async(t,c,l)=>{let i="/"+o.map(g=>g.replace(/[A-Z]/g,h=>`-${h.toLowerCase()}`)).join("/"),f=l[0]||{},T=l[1]||{},{query:A,fetchOptions:S,...B}=f,d={...T,...S},y=E(i,a,f);return await r(i,{...d,body:y==="GET"?void 0:{...B,..._optionalChain([d, 'optionalAccess', _31 => _31.body])||{}},query:A||_optionalChain([d, 'optionalAccess', _32 => _32.query]),method:y,async onSuccess(g){await _optionalChain([d, 'optionalAccess', _33 => _33.onSuccess, 'optionalCall', _34 => _34(g)]);let h=_optionalChain([n, 'optionalAccess', _35 => _35.find, 'call', _36 => _36(C=>C.matcher(i))]);if(!h)return;let m=s[h.signal];if(!m)return;let w=m.get();setTimeout(()=>{m.set(!w)},10)}})}})}return u()}var O=(e,r,a,s)=>{let n=_nanostores.atom.call(void 0, {data:null,error:null,isPending:!0,isRefetching:!1}),u=()=>{let t=typeof s=="function"?s({data:n.get().data,error:n.get().error,isPending:n.get().isPending}):s;return a(r,{...t,onSuccess:async c=>{n.set({data:c.data,error:null,isPending:!1,isRefetching:!1}),await _optionalChain([t, 'optionalAccess', _37 => _37.onSuccess, 'optionalCall', _38 => _38(c)])},async onError(c){n.set({error:c.error,data:null,isPending:!1,isRefetching:!1}),await _optionalChain([t, 'optionalAccess', _39 => _39.onError, 'optionalCall', _40 => _40(c)])},async onRequest(c){let l=n.get();n.set({isPending:l.data===null,data:l.data,error:null,isRefetching:!0}),await _optionalChain([t, 'optionalAccess', _41 => _41.onRequest, 'optionalCall', _42 => _42(c)])}})};e=Array.isArray(e)?e:[e];let o=!1;for(let t of e)t.subscribe(()=>{o?u():_nanostores.onMount.call(void 0, n,()=>(u(),o=!0,()=>{n.off(),t.off()}))});return n};function X(e){let r=_nanostores.atom.call(void 0, !1);return{$session:O(r,"/get-session",e,{method:"GET"}),_sessionSignal:r,$Infer:{}}}exports.a = $; exports.b = Q; exports.c = O; exports.d = X;
|
|
2
|
+
//# sourceMappingURL=chunk-5TFMNJQL.cjs.map
|