@faire-auth/cli 1.0.4 → 1.1.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.
Files changed (2) hide show
  1. package/dist/index.mjs +16 -16
  2. package/package.json +17 -15
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import{Command as e}from"commander";import{cancel as t,confirm as n,intro as r,isCancel as i,log as a,multiselect as o,outro as s,select as c,spinner as l,text as u}from"@clack/prompts";import d from"chalk";import{parse as ee}from"dotenv";import*as f from"fs";import p,{existsSync as m,readFileSync as h}from"fs";import g from"fs/promises";import*as _ from"path";import v from"path";import y,{format as b}from"prettier";import x from"semver";import*as S from"zod";import{FaireAuthError as C,createTelemetry as w,getTelemetryAuthConfig as T,logger as E}from"faire-auth";import{exec as D,execSync as O}from"child_process";import k from"crypto";import{getAdapter as A,getAuthTables as j,getMigrations as M}from"faire-auth/db";import N from"prompts";import P from"yocto-spinner";import{loadConfig as F}from"c12";import I from"@babel/preset-typescript";import te from"@babel/preset-react";import{produceSchema as ne}from"@mrleebo/prisma-ast";import*as re from"os";import L from"os";import{base64 as ie}from"@faire-auth/core/datatypes";import"dotenv/config";async function ae({format:e,current_user_config:t,spinner:n,plugins:r,database:i}){let a={START_OF_PLUGINS:{START_OF_PLUGINS:{type:`regex`,regex:/faireAuth\([\w\W]*plugins:[\W]*\[()/m,getIndex:({matchIndex:e,match:t})=>e+t[0].length}}.START_OF_PLUGINS,END_OF_PLUGINS:{type:`manual`,getIndex:({content:e,additionalFields:t})=>oe(e,t.start_of_plugins,`[`,`]`)},START_OF_BETTERAUTH:{type:`regex`,regex:/faireAuth\({()/m,getIndex:({matchIndex:e})=>e+11}},o={add_plugin:async t=>{let n=z(t.config,a.START_OF_PLUGINS,{});if(!n)throw Error(`Couldn't find start of your plugins array in your auth config file.`);let r=z(t.config,a.END_OF_PLUGINS,{start_of_plugins:n.index});if(!r)throw Error(`Couldn't find end of your plugins array in your auth config file.`);let i;if(t.direction_in_plugins_array===`prepend`)i=R({line:n.line,character:n.character,content:t.config,insert_content:`${t.pluginFunctionName}(${t.pluginContents}),`});else{let e=t.config.slice(n.index,r.index).trim(),a=e===``,o=e.endsWith(`,`),s=!a&&!o;i=R({line:r.line,character:r.character,content:t.config,insert_content:`${s?`,`:``}${t.pluginFunctionName}(${t.pluginContents})`})}try{i=await e(i)}catch(e){throw console.error(e),Error(`Failed to generate new auth config during plugin addition phase.`)}return{code:i,dependencies:[],envs:[]}},add_import:async t=>{let n=``;for(let e of t.imports)Array.isArray(e.variables)?n+=`import { ${e.variables.map(e=>`${e.asType?`type `:``}${e.name}${e.as?` as ${e.as}`:``}`).join(`, `)} } from "${e.path}";\n`:n+=`import ${e.variables.asType?`type `:``}${e.variables.name}${e.variables.as?` as ${e.variables.as}`:``} from "${e.path}";\n`;try{return{code:await e(n+t.config),dependencies:[],envs:[]}}catch(e){throw console.error(e),Error(`Failed to generate new auth config during import addition phase.`)}},add_database:async t=>{let n=[],r=[],i=``;async function s({db_code:e,dependencies:s,envs:c,imports:l,code_before_faireAuth:u}){if(u){let e=z(t.config,a.START_OF_BETTERAUTH,{});if(!e)throw Error(`Couldn't find start of faireAuth() function.`);t.config=R({line:e.line-1,character:0,content:t.config,insert_content:`\n${u}\n`})}let d=await o.add_import({config:t.config,imports:l});t.config=d.code,i=e,n.push(...c,...d.envs),r.push(...s,...d.dependencies)}t.database===`sqlite`?await s({db_code:`new Database(process.env.DATABASE_URL || "database.sqlite")`,dependencies:[`better-sqlite3`],envs:[`DATABASE_URL`],imports:[{path:`better-sqlite3`,variables:{asType:!1,name:`Database`}}]}):t.database===`postgres`?await s({db_code:`new Pool({
2
+ import{Command as e}from"commander";import{cancel as t,confirm as n,intro as r,isCancel as i,log as a,multiselect as o,outro as s,select as c,spinner as l,text as u}from"@clack/prompts";import d from"chalk";import{parse as ee}from"dotenv";import*as f from"fs";import p,{existsSync as m,readFileSync as h}from"fs";import g from"fs/promises";import _,*as v from"path";import y,{format as b}from"prettier";import x from"semver";import*as S from"zod";import{FaireAuthError as C,createTelemetry as w,getTelemetryAuthConfig as T,logger as E}from"faire-auth";import{exec as D,execSync as O}from"child_process";import k from"crypto";import{getAdapter as A,getAuthTables as j,getMigrations as M}from"faire-auth/db";import N from"prompts";import P from"yocto-spinner";import{loadConfig as F}from"c12";import I from"@babel/preset-typescript";import te from"@babel/preset-react";import{produceSchema as ne}from"@mrleebo/prisma-ast";import L,*as re from"os";import{base64 as ie}from"@faire-auth/core/datatypes";import"dotenv/config";async function ae({format:e,current_user_config:t,spinner:n,plugins:r,database:i}){let a={START_OF_PLUGINS:{START_OF_PLUGINS:{type:`regex`,regex:/faireAuth\([\w\W]*plugins:[\W]*\[()/m,getIndex:({matchIndex:e,match:t})=>e+t[0].length}}.START_OF_PLUGINS,END_OF_PLUGINS:{type:`manual`,getIndex:({content:e,additionalFields:t})=>oe(e,t.start_of_plugins,`[`,`]`)},START_OF_BETTERAUTH:{type:`regex`,regex:/faireAuth\({()/m,getIndex:({matchIndex:e})=>e+11}},o={add_plugin:async t=>{let n=z(t.config,a.START_OF_PLUGINS,{});if(!n)throw Error(`Couldn't find start of your plugins array in your auth config file.`);let r=z(t.config,a.END_OF_PLUGINS,{start_of_plugins:n.index});if(!r)throw Error(`Couldn't find end of your plugins array in your auth config file.`);let i;if(t.direction_in_plugins_array===`prepend`)i=R({line:n.line,character:n.character,content:t.config,insert_content:`${t.pluginFunctionName}(${t.pluginContents}),`});else{let e=t.config.slice(n.index,r.index).trim(),a=e===``,o=e.endsWith(`,`),s=!a&&!o;i=R({line:r.line,character:r.character,content:t.config,insert_content:`${s?`,`:``}${t.pluginFunctionName}(${t.pluginContents})`})}try{i=await e(i)}catch(e){throw console.error(e),Error(`Failed to generate new auth config during plugin addition phase.`)}return{code:i,dependencies:[],envs:[]}},add_import:async t=>{let n=``;for(let e of t.imports)Array.isArray(e.variables)?n+=`import { ${e.variables.map(e=>`${e.asType?`type `:``}${e.name}${e.as?` as ${e.as}`:``}`).join(`, `)} } from "${e.path}";\n`:n+=`import ${e.variables.asType?`type `:``}${e.variables.name}${e.variables.as?` as ${e.variables.as}`:``} from "${e.path}";\n`;try{return{code:await e(n+t.config),dependencies:[],envs:[]}}catch(e){throw console.error(e),Error(`Failed to generate new auth config during import addition phase.`)}},add_database:async t=>{let n=[],r=[],i=``;async function s({db_code:e,dependencies:s,envs:c,imports:l,code_before_faireAuth:u}){if(u){let e=z(t.config,a.START_OF_BETTERAUTH,{});if(!e)throw Error(`Couldn't find start of faireAuth() function.`);t.config=R({line:e.line-1,character:0,content:t.config,insert_content:`\n${u}\n`})}let d=await o.add_import({config:t.config,imports:l});t.config=d.code,i=e,n.push(...c,...d.envs),r.push(...s,...d.dependencies)}t.database===`sqlite`?await s({db_code:`new Database(process.env.DATABASE_URL || "database.sqlite")`,dependencies:[`better-sqlite3`],envs:[`DATABASE_URL`],imports:[{path:`better-sqlite3`,variables:{asType:!1,name:`Database`}}]}):t.database===`postgres`?await s({db_code:`new Pool({
3
3
  connectionString: process.env.DATABASE_URL || "postgresql://postgres:password@localhost:5432/database"
4
4
  })`,dependencies:[`pg`],envs:[`DATABASE_URL`],imports:[{path:`pg`,variables:[{asType:!1,name:`Pool`}]}]}):t.database===`mysql`?await s({db_code:`createPool(process.env.DATABASE_URL!)`,dependencies:[`mysql2`],envs:[`DATABASE_URL`],imports:[{path:`mysql2/promise`,variables:[{asType:!1,name:`createPool`}]}]}):t.database===`mssql`?await s({code_before_faireAuth:`new MssqlDialect({
5
5
  tarn: {
@@ -27,8 +27,8 @@ connectionString: process.env.DATABASE_URL || "postgresql://postgres:password@lo
27
27
  server: 'localhost',
28
28
  }),
29
29
  },
30
- })`,db_code:`dialect`,dependencies:[`tedious`,`tarn`,`kysely`],envs:[`DATABASE_URL`],imports:[{path:`tedious`,variables:{name:`*`,as:`Tedious`}},{path:`tarn`,variables:{name:`*`,as:`Tarn`}},{path:`kysely`,variables:[{name:`MssqlDialect`}]}]}):t.database===`drizzle:mysql`||t.database===`drizzle:sqlite`||t.database===`drizzle:pg`?await s({db_code:`drizzleAdapter(db, {\nprovider: "${t.database.replace(`drizzle:`,``)}",\n})`,dependencies:[``],envs:[],imports:[{path:`faire-auth/adapters/drizzle`,variables:[{name:`drizzleAdapter`}]},{path:`./database.ts`,variables:[{name:`db`}]}]}):t.database===`prisma:mysql`||t.database===`prisma:sqlite`||t.database===`prisma:postgresql`?await s({db_code:`prismaAdapter(client, {\nprovider: "${t.database.replace(`prisma:`,``)}",\n})`,dependencies:[`@prisma/client`],envs:[],code_before_faireAuth:`const client = new PrismaClient();`,imports:[{path:`faire-auth/adapters/prisma`,variables:[{name:`prismaAdapter`}]},{path:`@prisma/client`,variables:[{name:`PrismaClient`}]}]}):t.database===`mongodb`&&await s({db_code:`mongodbAdapter(db)`,dependencies:[`mongodb`],envs:[`DATABASE_URL`],code_before_faireAuth:[`const client = new MongoClient(process.env.DATABASE_URL || "mongodb://localhost:27017/database");`,`const db = client.db();`].join(`
31
- `),imports:[{path:`faire-auth/adapters/mongodb`,variables:[{name:`mongodbAdapter`}]},{path:`mongodb`,variables:[{name:`MongoClient`}]}]});let c=z(t.config,a.START_OF_BETTERAUTH,{});if(!c)throw Error(`Couldn't find start of faireAuth() function.`);let l;l=R({line:c.line,character:c.character,content:t.config,insert_content:`database: ${i},`});try{return l=await e(l),{code:l,dependencies:r,envs:n}}catch(e){throw console.error(e),Error(`Failed to generate new auth config during database addition phase.`)}}},s=await e(t),c=[],l=[];if(r.length!==0){let e=[];for await(let t of r){let n=e.findIndex(e=>e.path===t.path);n===-1?e.push({path:t.path,variables:[{name:t.name,asType:!1}]}):e[n].variables.push({name:t.name,asType:!1})}if(e.length!==0){let{code:t,envs:n,dependencies:r}=await o.add_import({config:s,imports:e});c.push(...r),l.push(...n),s=t}}for await(let e of r)try{let t=``;e.id===`magic-link`?t=`{
30
+ })`,db_code:`dialect`,dependencies:[`tedious`,`tarn`,`kysely`],envs:[`DATABASE_URL`],imports:[{path:`tedious`,variables:{name:`*`,as:`Tedious`}},{path:`tarn`,variables:{name:`*`,as:`Tarn`}},{path:`kysely`,variables:[{name:`MssqlDialect`}]}]}):t.database===`drizzle:mysql`||t.database===`drizzle:sqlite`||t.database===`drizzle:pg`?await s({db_code:`drizzleAdapter(db, {\nprovider: "${t.database.replace(`drizzle:`,``)}",\n})`,dependencies:[``],envs:[],imports:[{path:`faire-auth/adapters/drizzle`,variables:[{name:`drizzleAdapter`}]},{path:`./database.ts`,variables:[{name:`db`}]}]}):t.database===`prisma:mysql`||t.database===`prisma:sqlite`||t.database===`prisma:postgresql`?await s({db_code:`prismaAdapter(client, {\nprovider: "${t.database.replace(`prisma:`,``)}",\n})`,dependencies:[`@prisma/client`],envs:[],code_before_faireAuth:`const client = new PrismaClient();`,imports:[{path:`faire-auth/adapters/prisma`,variables:[{name:`prismaAdapter`}]},{path:`@prisma/client`,variables:[{name:`PrismaClient`}]}]}):t.database===`mongodb`&&await s({db_code:`mongodbAdapter(db)`,dependencies:[`mongodb`],envs:[`DATABASE_URL`],code_before_faireAuth:`const client = new MongoClient(process.env.DATABASE_URL || "mongodb://localhost:27017/database");
31
+ const db = client.db();`,imports:[{path:`faire-auth/adapters/mongodb`,variables:[{name:`mongodbAdapter`}]},{path:`mongodb`,variables:[{name:`MongoClient`}]}]});let c=z(t.config,a.START_OF_BETTERAUTH,{});if(!c)throw Error(`Couldn't find start of faireAuth() function.`);let l;l=R({line:c.line,character:c.character,content:t.config,insert_content:`database: ${i},`});try{return l=await e(l),{code:l,dependencies:r,envs:n}}catch(e){throw console.error(e),Error(`Failed to generate new auth config during database addition phase.`)}}},s=await e(t),c=[],l=[];if(r.length!==0){let e=[];for await(let t of r){let n=e.findIndex(e=>e.path===t.path);n===-1?e.push({path:t.path,variables:[{name:t.name,asType:!1}]}):e[n].variables.push({name:t.name,asType:!1})}if(e.length!==0){let{code:t,envs:n,dependencies:r}=await o.add_import({config:s,imports:e});c.push(...r),l.push(...n),s=t}}for await(let e of r)try{let t=``;e.id===`magic-link`?t=`{
32
32
  sendMagicLink({ email, token, url }, request) {
33
33
  // Send email with magic link
34
34
  },
@@ -40,15 +40,15 @@ async sendVerificationOTP({ email, otp, type }, request) {
40
40
  config: [],
41
41
  }`:e.id===`oidc`&&(t=`{
42
42
  loginPage: "/sign-in",
43
- }`);let{code:n,dependencies:r,envs:i}=await o.add_plugin({config:s,direction_in_plugins_array:e.id===`next-cookies`?`append`:`prepend`,pluginFunctionName:e.name,pluginContents:t});s=n,l.push(...i),c.push(...r)}catch(e){n.stop(`Something went wrong while generating/updating your new auth config file.`,1),E.error(e.message),process.exit(1)}if(i)try{let{code:e,dependencies:t,envs:n}=await o.add_database({config:s,database:i});s=e,c.push(...t),l.push(...n)}catch(e){n.stop(`Something went wrong while generating/updating your new auth config file.`,1),E.error(e.message),process.exit(1)}return{generatedCode:s,dependencies:c,envs:l}}function oe(e,t,n,r){let i=0,a=!1,o=null;for(let s=t;s<e.length;s++){let t=e[s];if(t===`"`||t===`'`||t==="`"){a?t===o&&(a=!1,o=null):(a=!0,o=t);continue}if(!a){if(t===n)i++;else if(t===r){if(i===0)return s;i--}}}return null}function R(e){let{line:t,character:n,content:r,insert_content:i}=e,a=r.split(`
43
+ }`);let{code:n,dependencies:r,envs:i}=await o.add_plugin({config:s,direction_in_plugins_array:e.id===`next-cookies`?`append`:`prepend`,pluginFunctionName:e.name,pluginContents:t});s=n,l.push(...i),c.push(...r)}catch(e){n.stop(`Something went wrong while generating/updating your new auth config file.`,1),E.error(e.message),process.exit(1)}if(i)try{let{code:e,dependencies:t,envs:n}=await o.add_database({config:s,database:i});s=e,c.push(...t),l.push(...n)}catch(e){n.stop(`Something went wrong while generating/updating your new auth config file.`,1),E.error(e.message),process.exit(1)}return{generatedCode:s,dependencies:c,envs:l}}function oe(e,t,n,r){let i=0,a=!1,o=null;for(let s=t;s<e.length;s++){let t=e[s];if(t===`"`||t===`'`||t==="`")a?t===o&&(a=!1,o=null):(a=!0,o=t);else if(!a){if(t===n)i++;else if(t===r){if(i===0)return s;i--}}}return null}function R(e){let{line:t,character:n,content:r,insert_content:i}=e,a=r.split(`
44
44
  `);if(t<1||t>a.length)throw Error(`Invalid line number`);let o=t-1;if(n<0||n>a[o].length)throw Error(`Invalid character index`);let s=a[o];return a[o]=s.slice(0,n)+i+s.slice(n),a.join(`
45
- `)}function z(e,t,n){if(t.type===`regex`){let{regex:r,getIndex:i}=t,a=r.exec(e);if(a){let t=a.index,r=i({matchIndex:t,match:a,additionalFields:n});if(r===null)return null;let o=B(e,r);return{line:o.line,character:o.character,index:r}}return null}else{let{getIndex:r}=t,i=r({content:e,additionalFields:n});if(i===null)return null;let{line:a,character:o}=B(e,i);return{line:a,character:o,index:i}}}const B=(e,t)=>{let n=e.slice(0,t).split(`
46
- `);return{line:n.length,character:n[n.length-1].length}};function se(e){return new Promise(t=>{D(`${e} --version`,e=>{t(!e)})})}async function ce(){return{hasPnpm:await se(`pnpm`),hasBun:await se(`bun`)}}function V(e){if(e<0)throw Error(`Milliseconds cannot be negative`);return e<1e3?`${e}ms`:`${Math.floor(e/1e3)}s ${e%1e3}ms`}function H(e){let t=e?v.join(e,`package.json`):v.join(`package.json`);return JSON.parse(p.readFileSync(t,`utf-8`))}function le(e){return e.replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g,(e,t)=>t?``:e).replace(/,(?=\s*[}\]])/g,``)}function ue(e,t){let n;n=t||(e?v.join(e,`tsconfig.json`):v.join(`tsconfig.json`));try{let e=p.readFileSync(n,`utf-8`);return JSON.parse(le(e))}catch(e){throw e}}function U({dependencies:e,packageManager:t,cwd:n}){let r;switch(t){case`npm`:r=`npm install --force`;break;case`pnpm`:r=`pnpm install`;break;case`bun`:r=`bun install`;break;case`yarn`:r=`yarn install`;break;default:throw Error(`Invalid package manager`)}let i=`${r} ${e.join(` `)}`;return new Promise((e,t)=>{D(i,{cwd:n},(n,r,i)=>{if(n){t(Error(i));return}e(!0)})})}const de=new e(`secret`).action(()=>{let e=fe();E.info(`\nAdd the following to your .env file:
45
+ `)}function z(e,t,n){if(t.type===`regex`){let{regex:r,getIndex:i}=t,a=r.exec(e);if(a){let t=a.index,r=i({matchIndex:t,match:a,additionalFields:n});if(r===null)return null;let o=B(e,r);return{line:o.line,character:o.character,index:r}}return null}{let{getIndex:r}=t,i=r({content:e,additionalFields:n});if(i===null)return null;let{line:a,character:o}=B(e,i);return{line:a,character:o,index:i}}}const B=(e,t)=>{let n=e.slice(0,t).split(`
46
+ `);return{line:n.length,character:n[n.length-1].length}};function se(e){return new Promise(t=>{D(`${e} --version`,e=>{t(!e)})})}async function ce(){return{hasPnpm:await se(`pnpm`),hasBun:await se(`bun`)}}function V(e){if(e<0)throw Error(`Milliseconds cannot be negative`);return e<1e3?`${e}ms`:`${Math.floor(e/1e3)}s ${e%1e3}ms`}function H(e){let t=e?_.join(e,`package.json`):_.join(`package.json`);return JSON.parse(p.readFileSync(t,`utf-8`))}function le(e){return e.replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g,(e,t)=>t?``:e).replace(/,(?=\s*[}\]])/g,``)}function ue(e,t){let n;n=t||(e?_.join(e,`tsconfig.json`):_.join(`tsconfig.json`));try{let e=p.readFileSync(n,`utf-8`);return JSON.parse(le(e))}catch(e){throw e}}function U({dependencies:e,packageManager:t,cwd:n}){let r;switch(t){case`npm`:r=`npm install --force`;break;case`pnpm`:r=`pnpm install`;break;case`bun`:r=`bun install`;break;case`yarn`:r=`yarn install`;break;default:throw Error(`Invalid package manager`)}let i=`${r} ${e.join(` `)}`;return new Promise((e,t)=>{D(i,{cwd:n},(n,r,i)=>{n?t(Error(i)):e(!0)})})}const de=new e(`secret`).action(()=>{let e=fe();E.info(`\nAdd the following to your .env file:
47
47
  ${d.gray(`# Auth Secret`)+d.green(`\nFAIRE_AUTH_SECRET=${e}`)}`)}),fe=()=>k.randomBytes(32).toString(`hex`),pe=[`sqlite`,`mysql`,`mssql`,`postgres`,`drizzle:pg`,`drizzle:mysql`,`drizzle:sqlite`,`prisma:postgresql`,`prisma:mysql`,`prisma:sqlite`,`mongodb`],W=[{id:`bearer`,name:`bearer`,clientName:void 0,path:`faire-auth/plugins`,clientPath:void 0}],G={trailingComma:`all`,useTabs:!1,tabWidth:4},me=async({appName:e})=>await b([`import { faireAuth } from 'faire-auth';`,``,`export const auth = faireAuth({`,e?`appName: "${e}",`:``,`plugins: [],`,`});`].join(`
48
48
  `),{filepath:`auth.ts`,...G}),he=async({auth_config_path:e,framework:t,clientPlugins:n})=>{function r(){let e=[{path:`faire-auth/client/plugins`,variables:[{name:`inferAdditionalFields`}]}];for(let t of n)for(let n of t.imports)if(Array.isArray(n.variables))for(let t of n.variables){let r=e.findIndex(e=>e.path===n.path);if(r!==-1){let n=e[r].variables;Array.isArray(n)?n.push(t):e[r].variables=[n,t]}else e.push({path:n.path,variables:[t]})}else{let t=e.findIndex(e=>e.path===n.path);if(t!==-1){let r=e[t].variables;Array.isArray(r)?r.push(n.variables):e[t].variables=[r,n.variables]}else e.push({path:n.path,variables:[n.variables]})}return e}let i=r(),a=``;for(let e of i)Array.isArray(e.variables)?a+=`import { ${e.variables.map(e=>`${e.asType?`type `:``}${e.name}${e.as?` as ${e.as}`:``}`).join(`, `)} } from "${e.path}";\n`:a+=`import ${e.variables.asType?`type `:``}${e.variables.name}${e.variables.as?` as ${e.variables.as}`:``} from "${e.path}";\n`;return await b([`import { createAuthClient } from "faire-auth/${t===`nextjs`?`react`:t===`vanilla`?`client`:t}";`,`import type { auth } from "${e}";`,a,``,`export const authClient = createAuthClient({`,`baseURL: "http://localhost:3000",`,`plugins: [inferAdditionalFields<typeof auth>(),${n.map(e=>`${e.name}(${e.contents})`).join(`, `)}],`,`});`].join(`
49
- `),{filepath:`auth-client.ts`,...G})},ge=S.object({cwd:S.string(),config:S.string().optional(),database:S.enum(pe).optional(),"skip-db":S.boolean().optional(),"skip-plugins":S.boolean().optional(),"package-manager":S.string().optional(),tsconfig:S.string().optional()});async function _e(e){console.log(),r(`šŸ‘‹ Initializing Faire Auth`);let f=ge.parse(e),p=v.resolve(f.cwd),h,_=``,y=`vanilla`,S=async e=>await b(e,{filepath:_,...G}),C;try{C=H(p)}catch(e){a.error(`āŒ Couldn't read your package.json file. (dir: ${p})`),a.error(JSON.stringify(e,null,2)),process.exit(1)}let w=await be(p);w.length||(s(`āŒ No .env files found. Please create an env file first.`),process.exit(0));let T;T=w.includes(`.env`)?`.env`:w.includes(`.env.local`)?`.env.local`:w.includes(`.env.development`)?`.env.development`:w.length===1?w[0]:`none`;let E;try{E=await ue(p,f.tsconfig===void 0?v.join(p,`tsconfig.json`):v.resolve(p,f.tsconfig))}catch(e){a.error(`āŒ Couldn't read your tsconfig.json file. (dir: ${p})`),console.error(e),process.exit(1)}if(!(`compilerOptions`in E&&`strict`in E.compilerOptions&&E.compilerOptions.strict===!0)){a.warn(`Faire Auth requires your tsconfig.json to have "compilerOptions.strict" set to true.`);let e=await n({message:`Would you like us to set ${d.bold(`strict`)} to ${d.bold(`true`)}?`});if(i(e)&&(t(`āœ‹ Operation cancelled.`),process.exit(0)),e)try{await g.writeFile(v.join(p,`tsconfig.json`),await b(JSON.stringify(Object.assign(E,{compilerOptions:{strict:!0}})),{filepath:`tsconfig.json`,...G}),`utf-8`),a.success(`šŸš€ tsconfig.json successfully updated!`)}catch(e){a.error(`Failed to add "compilerOptions.strict" to your tsconfig.json file.`),console.error(e),process.exit(1)}}let D=l({indicator:`dots`});D.start(`Checking faire-auth installation`);let O;try{O=await ye(`faire-auth`)}catch(e){a.error(`āŒ Couldn't get latest version of faire-auth.`),console.error(e),process.exit(1)}if(!C.dependencies||!Object.keys(C.dependencies).includes(`faire-auth`)){D.stop(`Finished fetching latest version of faire-auth.`);let e=l({indicator:`dots`}),r=await n({message:`Would you like to install Faire Auth?`});if(i(r)&&(t(`āœ‹ Operation cancelled.`),process.exit(0)),h===void 0&&(h=await K()),r){e.start(`Installing Faire Auth using ${d.bold(h)}`);try{let t=Date.now();await U({dependencies:[`faire-auth@latest`],packageManager:h,cwd:p}),e.stop(`Faire Auth installed ${d.greenBright(`successfully`)}! ${d.gray(`(${V(Date.now()-t)})`)}`)}catch(t){e.stop(`Failed to install Faire Auth:`),console.error(t),process.exit(1)}}}else if(C.dependencies[`faire-auth`]!==`workspace:*`&&x.lt(x.coerce(C.dependencies[`faire-auth`])?.toString(),x.clean(O))){D.stop(`Finished fetching latest version of faire-auth.`);let e=await n({message:`Your current Faire Auth dependency is out-of-date. Would you like to update it? (${d.bold(C.dependencies[`faire-auth`])} → ${d.bold(`v${O}`)})`});if(i(e)&&(t(`āœ‹ Operation cancelled.`),process.exit(0)),e){h===void 0&&(h=await K());let e=l({indicator:`dots`});e.start(`Updating Faire Auth using ${d.bold(h)}`);try{let t=Date.now();await U({dependencies:[`faire-auth@latest`],packageManager:h,cwd:p}),e.stop(`Faire Auth updated ${d.greenBright(`successfully`)}! ${d.gray(`(${V(Date.now()-t)})`)}`)}catch(t){e.stop(`Failed to update Faire Auth:`),a.error(t.message),process.exit(1)}}}else D.stop(`Faire Auth dependencies are ${d.greenBright(`up to date`)}!`);let k=H(p),A;if(k.name)A=k.name;else{let e=await u({message:`What is the name of your application?`});i(e)&&(t(`āœ‹ Operation cancelled.`),process.exit(0)),A=e}let j=[`auth.ts`,`auth.tsx`,`auth.js`,`auth.jsx`];if(j=[...j,...j.map(e=>`lib/server/${e}`),...j.map(e=>`server/${e}`),...j.map(e=>`lib/${e}`),...j.map(e=>`utils/${e}`)],j=[...j,...j.map(e=>`src/${e}`),...j.map(e=>`app/${e}`)],f.config)_=v.join(p,f.config);else for(let e of j)if(m(v.join(p,e))){_=v.join(p,e);break}let M=``,N=null,P=[];if(_)a.message(),a.success(`Found auth config file. ${d.gray(`(${_})`)}`),a.message();else{let e=await c({message:`Would you like to create an auth config file?`,options:[{label:`Yes`,value:`yes`},{label:`No`,value:`no`}]});if(i(e)&&(t(`āœ‹ Operation cancelled.`),process.exit(0)),e===`yes`){let e=await n({message:`Would you like to set up your ${d.bold(`database`)}?`,initialValue:!0});if(i(e)&&(t(`āœ‹ Operating cancelled.`),process.exit(0)),e){let e=await c({message:`Choose a Database Dialect`,options:pe.map(e=>({value:e,label:e}))});i(e)&&(t(`āœ‹ Operating cancelled.`),process.exit(0)),N=e}if(f[`skip-plugins`]!==!1){let e=await n({message:`Would you like to set up ${d.bold(`plugins`)}?`});if(i(e)&&(t(`āœ‹ Operating cancelled.`),process.exit(0)),e){let e=await o({message:`Select your new plugins`,options:W.filter(e=>e.id!==`next-cookies`).map(e=>({value:e.id,label:e.id})),required:!1});i(e)&&(t(`āœ‹ Operating cancelled.`),process.exit(0)),P=e.map(e=>W.find(t=>t.id===e));for(let e of[`next.config.js`,`next.config.ts`,`next.config.mjs`,`.next/server/next.config.js`,`.next/server/next.config.ts`,`.next/server/next.config.mjs`])if(m(v.join(p,e))){y=`nextjs`;break}if(y===`nextjs`){let e=await n({message:`It looks like you're using NextJS. Do you want to add the next-cookies plugin? ${d.bold(`(Recommended)`)}`});i(e)&&(t(`āœ‹ Operating cancelled.`),process.exit(0)),e&&P.push(W.find(e=>e.id===`next-cookies`))}}}let r=v.join(p,`auth.ts`);_=r,a.info(`Creating auth config file: ${r}`);try{M=await me({appName:A});let{dependencies:e,envs:s,generatedCode:c}=await ae({current_user_config:M,format:S,s:D,plugins:P,database:N});if(M=c,await g.writeFile(r,M),_=r,a.success(`šŸš€ Auth config file successfully created!`),s.length!==0){a.info(`There are ${s.length} environment variables for your database of choice.`);let e=await n({message:`Would you like us to update your ENV files?`});if(i(e)&&(t(`āœ‹ Operation cancelled.`),process.exit(0)),e){let e=await o({message:`Select the .env files you want to update`,options:w.map(e=>({value:v.join(p,e),label:e})),required:!1});if(i(e)&&(t(`āœ‹ Operation cancelled.`),process.exit(0)),e.length===0)a.info(`No .env files to update. Skipping...`);else{try{await q({files:e,envs:s,isCommented:!0})}catch(e){a.error(`Failed to update .env files:`),a.error(JSON.stringify(e,null,2)),process.exit(1)}a.success(`šŸš€ ENV files successfully updated!`)}}}if(e.length!==0){a.info(`There are ${e.length} dependencies to install. (${e.map(e=>d.green(e)).join(`, `)})`);let r=await n({message:`Would you like us to install dependencies?`});if(i(r)&&(t(`āœ‹ Operation cancelled.`),process.exit(0)),r){let t=l({indicator:`dots`});h===void 0&&(h=await K()),t.start(`Installing dependencies using ${d.bold(h)}...`);try{let n=Date.now();await U({dependencies:e,packageManager:h,cwd:p}),t.stop(`Dependencies installed ${d.greenBright(`successfully`)} ${d.gray(`(${V(Date.now()-n)})`)}`)}catch(e){t.stop(`Failed to install dependencies using ${h}:`),a.error(e.message),process.exit(1)}}}}catch(e){a.error(`Failed to create auth config file: ${r}`),console.error(e),process.exit(1)}}else e===`no`&&a.info(`Skipping auth config file creation.`)}let F=[`auth-client.ts`,`auth-client.tsx`,`auth-client.js`,`auth-client.jsx`,`client.ts`,`client.tsx`,`client.js`,`client.jsx`];F=[...F,...F.map(e=>`lib/server/${e}`),...F.map(e=>`server/${e}`),...F.map(e=>`lib/${e}`),...F.map(e=>`utils/${e}`)],F=[...F,...F.map(e=>`src/${e}`),...F.map(e=>`app/${e}`)];let I=null;for(let e of F)if(m(v.join(p,e))){I=v.join(p,e);break}if(I)a.success(`Found auth client config file. ${d.gray(`(${I})`)}`);else{let e=await c({message:`Would you like to create an auth client config file?`,options:[{label:`Yes`,value:`yes`},{label:`No`,value:`no`}]});if(i(e)&&(t(`āœ‹ Operation cancelled.`),process.exit(0)),e===`yes`){I=v.join(p,`auth-client.ts`),a.info(`Creating auth client config file: ${I}`);try{let e=await he({auth_config_path:(`./`+v.join(_.replace(p,``))).replace(`.//`,`./`),clientPlugins:P.filter(e=>e.clientName).map(e=>{let t=``;return e.id===`one-tap`&&(t=`{ clientId: "MY_CLIENT_ID" }`),{contents:t,id:e.id,name:e.clientName,imports:[{path:`faire-auth/client/plugins`,variables:[{name:e.clientName}]}]}}),framework:y});await g.writeFile(I,e),a.success(`šŸš€ Auth client config file successfully created!`)}catch(e){a.error(`Failed to create auth client config file: ${I}`),a.error(JSON.stringify(e,null,2)),process.exit(1)}}else e===`no`&&a.info(`Skipping auth client config file creation.`)}if(T!==`none`)try{let e=ee(await g.readFile(v.join(p,T),`utf8`)),n=!1,r=!1;if(e.FAIRE_AUTH_SECRET===void 0&&(n=!0),e.FAIRE_AUTH_URL===void 0&&(r=!0),n||r){let e=``;e=n&&!r?d.bold(`FAIRE_AUTH_SECRET`):!n&&r?d.bold(`FAIRE_AUTH_URL`):d.bold.underline(`FAIRE_AUTH_SECRET`)+` and `+d.bold.underline(`FAIRE_AUTH_URL`),a.warn(`Missing ${e} in ${T}`);let s=await c({message:`Do you want to add ${e} to ${T}?`,options:[{label:`Yes`,value:`yes`},{label:`No`,value:`no`},{label:`Choose other file(s)`,value:`other`}]});i(s)&&(t(`āœ‹ Operation cancelled.`),process.exit(0));let l=[];if(n&&l.push(`FAIRE_AUTH_SECRET`),r&&l.push(`FAIRE_AUTH_URL`),s===`yes`){try{await q({files:[v.join(p,T)],envs:l,isCommented:!1})}catch(e){a.error(`Failed to add ENV variables to ${T}`),a.error(JSON.stringify(e,null,2)),process.exit(1)}a.success(`šŸš€ ENV variables successfully added!`),r&&a.info(`Be sure to update your FAIRE_AUTH_URL according to your app's needs.`)}else if(s===`no`)a.info(`Skipping ENV step.`);else if(s===`other`){w.length||(t(`No env files found. Please create an env file first.`),process.exit(0));let e=await o({message:`Select the .env files you want to update`,options:w.map(e=>({value:v.join(p,e),label:e})),required:!1});if(i(e)&&(t(`āœ‹ Operation cancelled.`),process.exit(0)),e.length===0)a.info(`No .env files to update. Skipping...`);else{try{await q({files:e,envs:l,isCommented:!1})}catch(e){a.error(`Failed to update .env files:`),a.error(JSON.stringify(e,null,2)),process.exit(1)}a.success(`šŸš€ ENV files successfully updated!`)}}}}catch{}s(`🄳 All Done, Happy Hacking!`),console.log(),process.exit(0)}const ve=new e(`init`).option(`-c, --cwd <cwd>`,`The working directory.`,process.cwd()).option(`--config <config>`,"The path to the auth configuration file. defaults to the first `auth.ts` file found.").option(`--tsconfig <tsconfig>`,`The path to the tsconfig file.`).option(`--skip-db`,`Skip the database setup.`).option(`--skip-plugins`,`Skip the plugins setup.`).option(`--package-manager <package-manager>`,`The package manager you want to use.`).action(_e);async function ye(e){try{let t=await fetch(`https://registry.npmjs.org/${e}`);if(!t.ok)throw Error(`Package not found: ${t.statusText}`);return(await t.json())[`dist-tags`].latest}catch(e){throw e?.message}}async function K(){let{hasBun:e,hasPnpm:n}=await ce();if(!e&&!n)return`npm`;let r=[];n&&r.push({value:`pnpm`,label:`pnpm`,hint:`recommended`}),e&&r.push({value:`bun`,label:`bun`}),r.push({value:`npm`,hint:`not recommended`});let a=await c({message:`Choose a package manager`,options:r});return i(a)&&(t(`Operation cancelled.`),process.exit(0)),a}async function be(e){return(await g.readdir(e)).filter(e=>e.startsWith(`.env`))}async function q({envs:e,files:t,isCommented:n}){let r=null;for(let r of t){let t=(await g.readFile(r,`utf8`)).split(`
49
+ `),{filepath:`auth-client.ts`,...G})},ge=S.object({cwd:S.string(),config:S.string().optional(),database:S.enum(pe).optional(),"skip-db":S.boolean().optional(),"skip-plugins":S.boolean().optional(),"package-manager":S.string().optional(),tsconfig:S.string().optional()});async function _e(e){console.log(),r(`šŸ‘‹ Initializing Faire Auth`);let f=ge.parse(e),p=_.resolve(f.cwd),h,v=``,y=`vanilla`,S=async e=>await b(e,{filepath:v,...G}),C;try{C=H(p)}catch(e){a.error(`āŒ Couldn't read your package.json file. (dir: ${p})`),a.error(JSON.stringify(e,null,2)),process.exit(1)}let w=await be(p);w.length||(s(`āŒ No .env files found. Please create an env file first.`),process.exit(0));let T;T=w.includes(`.env`)?`.env`:w.includes(`.env.local`)?`.env.local`:w.includes(`.env.development`)?`.env.development`:w.length===1?w[0]:`none`;let E;try{E=await ue(p,f.tsconfig===void 0?_.join(p,`tsconfig.json`):_.resolve(p,f.tsconfig))}catch(e){a.error(`āŒ Couldn't read your tsconfig.json file. (dir: ${p})`),console.error(e),process.exit(1)}if(!(`compilerOptions`in E&&`strict`in E.compilerOptions&&E.compilerOptions.strict===!0)){a.warn(`Faire Auth requires your tsconfig.json to have "compilerOptions.strict" set to true.`);let e=await n({message:`Would you like us to set ${d.bold(`strict`)} to ${d.bold(`true`)}?`});if(i(e)&&(t(`āœ‹ Operation cancelled.`),process.exit(0)),e)try{await g.writeFile(_.join(p,`tsconfig.json`),await b(JSON.stringify(Object.assign(E,{compilerOptions:{strict:!0}})),{filepath:`tsconfig.json`,...G}),`utf-8`),a.success(`šŸš€ tsconfig.json successfully updated!`)}catch(e){a.error(`Failed to add "compilerOptions.strict" to your tsconfig.json file.`),console.error(e),process.exit(1)}}let D=l({indicator:`dots`});D.start(`Checking faire-auth installation`);let O;try{O=await ye(`faire-auth`)}catch(e){a.error(`āŒ Couldn't get latest version of faire-auth.`),console.error(e),process.exit(1)}if(!C.dependencies||!Object.keys(C.dependencies).includes(`faire-auth`)){D.stop(`Finished fetching latest version of faire-auth.`);let e=l({indicator:`dots`}),r=await n({message:`Would you like to install Faire Auth?`});if(i(r)&&(t(`āœ‹ Operation cancelled.`),process.exit(0)),h===void 0&&(h=await K()),r){e.start(`Installing Faire Auth using ${d.bold(h)}`);try{let t=Date.now();await U({dependencies:[`faire-auth@latest`],packageManager:h,cwd:p}),e.stop(`Faire Auth installed ${d.greenBright(`successfully`)}! ${d.gray(`(${V(Date.now()-t)})`)}`)}catch(t){e.stop(`Failed to install Faire Auth:`),console.error(t),process.exit(1)}}}else if(C.dependencies[`faire-auth`]!==`workspace:*`&&x.lt(x.coerce(C.dependencies[`faire-auth`])?.toString(),x.clean(O))){D.stop(`Finished fetching latest version of faire-auth.`);let e=await n({message:`Your current Faire Auth dependency is out-of-date. Would you like to update it? (${d.bold(C.dependencies[`faire-auth`])} → ${d.bold(`v${O}`)})`});if(i(e)&&(t(`āœ‹ Operation cancelled.`),process.exit(0)),e){h===void 0&&(h=await K());let e=l({indicator:`dots`});e.start(`Updating Faire Auth using ${d.bold(h)}`);try{let t=Date.now();await U({dependencies:[`faire-auth@latest`],packageManager:h,cwd:p}),e.stop(`Faire Auth updated ${d.greenBright(`successfully`)}! ${d.gray(`(${V(Date.now()-t)})`)}`)}catch(t){e.stop(`Failed to update Faire Auth:`),a.error(t.message),process.exit(1)}}}else D.stop(`Faire Auth dependencies are ${d.greenBright(`up to date`)}!`);let k=H(p),A;if(k.name)A=k.name;else{let e=await u({message:`What is the name of your application?`});i(e)&&(t(`āœ‹ Operation cancelled.`),process.exit(0)),A=e}let j=[`auth.ts`,`auth.tsx`,`auth.js`,`auth.jsx`];if(j=[...j,...j.map(e=>`lib/server/${e}`),...j.map(e=>`server/${e}`),...j.map(e=>`lib/${e}`),...j.map(e=>`utils/${e}`)],j=[...j,...j.map(e=>`src/${e}`),...j.map(e=>`app/${e}`)],f.config)v=_.join(p,f.config);else for(let e of j)if(m(_.join(p,e))){v=_.join(p,e);break}let M=``,N=null,P=[];if(v)a.message(),a.success(`Found auth config file. ${d.gray(`(${v})`)}`),a.message();else{let e=await c({message:`Would you like to create an auth config file?`,options:[{label:`Yes`,value:`yes`},{label:`No`,value:`no`}]});if(i(e)&&(t(`āœ‹ Operation cancelled.`),process.exit(0)),e===`yes`){let e=await n({message:`Would you like to set up your ${d.bold(`database`)}?`,initialValue:!0});if(i(e)&&(t(`āœ‹ Operating cancelled.`),process.exit(0)),e){let e=await c({message:`Choose a Database Dialect`,options:pe.map(e=>({value:e,label:e}))});i(e)&&(t(`āœ‹ Operating cancelled.`),process.exit(0)),N=e}if(f[`skip-plugins`]!==!1){let e=await n({message:`Would you like to set up ${d.bold(`plugins`)}?`});if(i(e)&&(t(`āœ‹ Operating cancelled.`),process.exit(0)),e){let e=await o({message:`Select your new plugins`,options:W.filter(e=>e.id!==`next-cookies`).map(e=>({value:e.id,label:e.id})),required:!1});i(e)&&(t(`āœ‹ Operating cancelled.`),process.exit(0)),P=e.map(e=>W.find(t=>t.id===e));for(let e of[`next.config.js`,`next.config.ts`,`next.config.mjs`,`.next/server/next.config.js`,`.next/server/next.config.ts`,`.next/server/next.config.mjs`])if(m(_.join(p,e))){y=`nextjs`;break}if(y===`nextjs`){let e=await n({message:`It looks like you're using NextJS. Do you want to add the next-cookies plugin? ${d.bold(`(Recommended)`)}`});i(e)&&(t(`āœ‹ Operating cancelled.`),process.exit(0)),e&&P.push(W.find(e=>e.id===`next-cookies`))}}}let r=_.join(p,`auth.ts`);v=r,a.info(`Creating auth config file: ${r}`);try{M=await me({appName:A});let{dependencies:e,envs:s,generatedCode:c}=await ae({current_user_config:M,format:S,s:D,plugins:P,database:N});if(M=c,await g.writeFile(r,M),v=r,a.success(`šŸš€ Auth config file successfully created!`),s.length!==0){a.info(`There are ${s.length} environment variables for your database of choice.`);let e=await n({message:`Would you like us to update your ENV files?`});if(i(e)&&(t(`āœ‹ Operation cancelled.`),process.exit(0)),e){let e=await o({message:`Select the .env files you want to update`,options:w.map(e=>({value:_.join(p,e),label:e})),required:!1});if(i(e)&&(t(`āœ‹ Operation cancelled.`),process.exit(0)),e.length===0)a.info(`No .env files to update. Skipping...`);else{try{await q({files:e,envs:s,isCommented:!0})}catch(e){a.error(`Failed to update .env files:`),a.error(JSON.stringify(e,null,2)),process.exit(1)}a.success(`šŸš€ ENV files successfully updated!`)}}}if(e.length!==0){a.info(`There are ${e.length} dependencies to install. (${e.map(e=>d.green(e)).join(`, `)})`);let r=await n({message:`Would you like us to install dependencies?`});if(i(r)&&(t(`āœ‹ Operation cancelled.`),process.exit(0)),r){let t=l({indicator:`dots`});h===void 0&&(h=await K()),t.start(`Installing dependencies using ${d.bold(h)}...`);try{let n=Date.now();await U({dependencies:e,packageManager:h,cwd:p}),t.stop(`Dependencies installed ${d.greenBright(`successfully`)} ${d.gray(`(${V(Date.now()-n)})`)}`)}catch(e){t.stop(`Failed to install dependencies using ${h}:`),a.error(e.message),process.exit(1)}}}}catch(e){a.error(`Failed to create auth config file: ${r}`),console.error(e),process.exit(1)}}else e===`no`&&a.info(`Skipping auth config file creation.`)}let F=[`auth-client.ts`,`auth-client.tsx`,`auth-client.js`,`auth-client.jsx`,`client.ts`,`client.tsx`,`client.js`,`client.jsx`];F=[...F,...F.map(e=>`lib/server/${e}`),...F.map(e=>`server/${e}`),...F.map(e=>`lib/${e}`),...F.map(e=>`utils/${e}`)],F=[...F,...F.map(e=>`src/${e}`),...F.map(e=>`app/${e}`)];let I=null;for(let e of F)if(m(_.join(p,e))){I=_.join(p,e);break}if(I)a.success(`Found auth client config file. ${d.gray(`(${I})`)}`);else{let e=await c({message:`Would you like to create an auth client config file?`,options:[{label:`Yes`,value:`yes`},{label:`No`,value:`no`}]});if(i(e)&&(t(`āœ‹ Operation cancelled.`),process.exit(0)),e===`yes`){I=_.join(p,`auth-client.ts`),a.info(`Creating auth client config file: ${I}`);try{let e=await he({auth_config_path:(`./`+_.join(v.replace(p,``))).replace(`.//`,`./`),clientPlugins:P.filter(e=>e.clientName).map(e=>{let t=``;return e.id===`one-tap`&&(t=`{ clientId: "MY_CLIENT_ID" }`),{contents:t,id:e.id,name:e.clientName,imports:[{path:`faire-auth/client/plugins`,variables:[{name:e.clientName}]}]}}),framework:y});await g.writeFile(I,e),a.success(`šŸš€ Auth client config file successfully created!`)}catch(e){a.error(`Failed to create auth client config file: ${I}`),a.error(JSON.stringify(e,null,2)),process.exit(1)}}else e===`no`&&a.info(`Skipping auth client config file creation.`)}if(T!==`none`)try{let e=await g.readFile(_.join(p,T),`utf8`),n=ee(e),r=!1,s=!1;if(n.FAIRE_AUTH_SECRET===void 0&&(r=!0),n.FAIRE_AUTH_URL===void 0&&(s=!0),r||s){let e=``;e=r&&!s?d.bold(`FAIRE_AUTH_SECRET`):!r&&s?d.bold(`FAIRE_AUTH_URL`):d.bold.underline(`FAIRE_AUTH_SECRET`)+` and `+d.bold.underline(`FAIRE_AUTH_URL`),a.warn(`Missing ${e} in ${T}`);let n=await c({message:`Do you want to add ${e} to ${T}?`,options:[{label:`Yes`,value:`yes`},{label:`No`,value:`no`},{label:`Choose other file(s)`,value:`other`}]});i(n)&&(t(`āœ‹ Operation cancelled.`),process.exit(0));let l=[];if(r&&l.push(`FAIRE_AUTH_SECRET`),s&&l.push(`FAIRE_AUTH_URL`),n===`yes`){try{await q({files:[_.join(p,T)],envs:l,isCommented:!1})}catch(e){a.error(`Failed to add ENV variables to ${T}`),a.error(JSON.stringify(e,null,2)),process.exit(1)}a.success(`šŸš€ ENV variables successfully added!`),s&&a.info(`Be sure to update your FAIRE_AUTH_URL according to your app's needs.`)}else if(n===`no`)a.info(`Skipping ENV step.`);else if(n===`other`){w.length||(t(`No env files found. Please create an env file first.`),process.exit(0));let e=await o({message:`Select the .env files you want to update`,options:w.map(e=>({value:_.join(p,e),label:e})),required:!1});if(i(e)&&(t(`āœ‹ Operation cancelled.`),process.exit(0)),e.length===0)a.info(`No .env files to update. Skipping...`);else{try{await q({files:e,envs:l,isCommented:!1})}catch(e){a.error(`Failed to update .env files:`),a.error(JSON.stringify(e,null,2)),process.exit(1)}a.success(`šŸš€ ENV files successfully updated!`)}}}}catch{}s(`🄳 All Done, Happy Hacking!`),console.log(),process.exit(0)}const ve=new e(`init`).option(`-c, --cwd <cwd>`,`The working directory.`,process.cwd()).option(`--config <config>`,"The path to the auth configuration file. defaults to the first `auth.ts` file found.").option(`--tsconfig <tsconfig>`,`The path to the tsconfig file.`).option(`--skip-db`,`Skip the database setup.`).option(`--skip-plugins`,`Skip the plugins setup.`).option(`--package-manager <package-manager>`,`The package manager you want to use.`).action(_e);async function ye(e){try{let t=await fetch(`https://registry.npmjs.org/${e}`);if(!t.ok)throw Error(`Package not found: ${t.statusText}`);return(await t.json())[`dist-tags`].latest}catch(e){throw e?.message}}async function K(){let{hasBun:e,hasPnpm:n}=await ce();if(!e&&!n)return`npm`;let r=[];n&&r.push({value:`pnpm`,label:`pnpm`,hint:`recommended`}),e&&r.push({value:`bun`,label:`bun`}),r.push({value:`npm`,hint:`not recommended`});let a=await c({message:`Choose a package manager`,options:r});return i(a)&&(t(`Operation cancelled.`),process.exit(0)),a}async function be(e){return(await g.readdir(e)).filter(e=>e.startsWith(`.env`))}async function q({envs:e,files:t,isCommented:n}){let r=null;for(let r of t){let t=(await g.readFile(r,`utf8`)).split(`
50
50
  `),a=e.map(e=>`${n?`# `:``}${e}=${i(e)??`"some_value"`}`);a.push(``),a.push(...t),await g.writeFile(r,a.join(`
51
- `),`utf8`)}function i(e){if(e===`DATABASE_HOST`)return`"The host of your database"`;if(e===`DATABASE_PORT`)return`"The port of your database"`;if(e===`DATABASE_USER`)return`"The username of your database"`;if(e===`DATABASE_PASSWORD`)return`"The password of your database"`;if(e===`DATABASE_NAME`)return`"The name of your database"`;if(e===`DATABASE_URL`)return`"The URL of your database"`;if(e===`FAIRE_AUTH_SECRET`)return r??=fe(),`"${r}"`;if(e===`FAIRE_AUTH_URL`)return`"http://localhost:3000" # Your APP URL`}}function xe(e,t){let n=t||process.cwd();e[`$env/dynamic/private`]=J(Ee()),e[`$env/dynamic/public`]=J(Ee()),e[`$env/static/private`]=J(Te(De(`PUBLIC_`,``))),e[`$env/static/public`]=J(Te(Oe(`PUBLIC_`,``)));let r=Se(n);Object.assign(e,r)}function Se(e){let t={},n=v.join(e,`package.json`),r=v.join(e,`svelte.config.js`),i=v.join(e,`svelte.config.ts`),a=!1;if(p.existsSync(n))try{let e=JSON.parse(p.readFileSync(n,`utf-8`));a=!!{...e.dependencies,...e.devDependencies}[`@sveltejs/kit`]}catch{}if(a||=p.existsSync(r)||p.existsSync(i),!a)return t;let o=[v.join(e,`src`,`lib`),v.join(e,`lib`)];for(let e of o)if(p.existsSync(e)){t.$lib=e;for(let n of[`server`,`utils`,`components`,`stores`]){let r=v.join(e,n);p.existsSync(r)&&(t[`$lib/${n}`]=r)}break}t[`$app/server`]=J(we());let s=Ce(e);return Object.assign(t,s),t}function Ce(e){let t={},n=[v.join(e,`svelte.config.js`),v.join(e,`svelte.config.ts`)];for(let r of n)if(p.existsSync(r)){try{let n=p.readFileSync(r,`utf-8`).match(/alias\s*:\s*\{([^}]+)\}/);if(n&&n[1]){let r=n[1].matchAll(/['"`](\$[^'"`]+)['"`]\s*:\s*['"`]([^'"`]+)['"`]/g);for(let n of r){let[,r,i]=n;r&&i&&(t[r+`/*`]=v.resolve(e,i)+`/*`,t[r]=v.resolve(e,i))}}}catch{}break}return t}function we(){return`
51
+ `),`utf8`)}function i(e){if(e===`DATABASE_HOST`)return`"The host of your database"`;if(e===`DATABASE_PORT`)return`"The port of your database"`;if(e===`DATABASE_USER`)return`"The username of your database"`;if(e===`DATABASE_PASSWORD`)return`"The password of your database"`;if(e===`DATABASE_NAME`)return`"The name of your database"`;if(e===`DATABASE_URL`)return`"The URL of your database"`;if(e===`FAIRE_AUTH_SECRET`)return r??=fe(),`"${r}"`;if(e===`FAIRE_AUTH_URL`)return`"http://localhost:3000" # Your APP URL`}}function xe(e,t){let n=t||process.cwd();e[`$env/dynamic/private`]=J(Ee()),e[`$env/dynamic/public`]=J(Ee()),e[`$env/static/private`]=J(Te(De(`PUBLIC_`,``))),e[`$env/static/public`]=J(Te(Oe(`PUBLIC_`,``)));let r=Se(n);Object.assign(e,r)}function Se(e){let t={},n=_.join(e,`package.json`),r=_.join(e,`svelte.config.js`),i=_.join(e,`svelte.config.ts`),a=!1;if(p.existsSync(n))try{let e=JSON.parse(p.readFileSync(n,`utf-8`));a=!!{...e.dependencies,...e.devDependencies}[`@sveltejs/kit`]}catch{}if(a||=p.existsSync(r)||p.existsSync(i),!a)return t;let o=[_.join(e,`src`,`lib`),_.join(e,`lib`)];for(let e of o)if(p.existsSync(e)){t.$lib=e;for(let n of[`server`,`utils`,`components`,`stores`]){let r=_.join(e,n);p.existsSync(r)&&(t[`$lib/${n}`]=r)}break}t[`$app/server`]=J(we());let s=Ce(e);return Object.assign(t,s),t}function Ce(e){let t={},n=[_.join(e,`svelte.config.js`),_.join(e,`svelte.config.ts`)];for(let r of n)if(p.existsSync(r)){try{let n=p.readFileSync(r,`utf-8`).match(/alias\s*:\s*\{([^}]+)\}/);if(n&&n[1]){let r=n[1].matchAll(/['"`](\$[^'"`]+)['"`]\s*:\s*['"`]([^'"`]+)['"`]/g);for(let n of r){let[,r,i]=n;r&&i&&(t[r+`/*`]=_.resolve(e,i)+`/*`,t[r]=_.resolve(e,i))}}}catch{}break}return t}function we(){return`
52
52
  // $app/server stub for CLI compatibility
53
53
  export default {};
54
54
  // jiti dirty hack: .unknown
@@ -59,24 +59,24 @@ export default {};
59
59
  `}function Ee(){return`
60
60
  export const env = process.env;
61
61
  // jiti dirty hack: .unknown
62
- `}function De(e,t){return Object.fromEntries(Object.entries(process.env).filter(([n])=>n.startsWith(t)&&(e===``||!n.startsWith(e))))}function Oe(e,t){return Object.fromEntries(Object.entries(process.env).filter(([n])=>n.startsWith(e)&&(t===``||!n.startsWith(t))))}const ke=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/,Ae=new Set(`do.if.in.for.let.new.try.var.case.else.enum.eval.null.this.true.void.with.await.break.catch.class.const.false.super.throw.while.yield.delete.export.import.public.return.static.switch.typeof.default.extends.finally.package.private.continue.debugger.function.arguments.interface.protected.implements.instanceof`.split(`.`));let Y=[`auth.ts`,`auth.tsx`,`auth.js`,`auth.jsx`,`auth.server.js`,`auth.server.ts`];Y=[...Y,...Y.map(e=>`lib/server/${e}`),...Y.map(e=>`server/${e}`),...Y.map(e=>`lib/${e}`),...Y.map(e=>`utils/${e}`)],Y=[...Y,...Y.map(e=>`src/${e}`),...Y.map(e=>`app/${e}`)];function je(e,t){let n=v.resolve(e,t);if(t.endsWith(`.json`))return n;if(p.existsSync(n))try{if(p.statSync(n).isFile())return n}catch{}return v.resolve(e,t,`tsconfig.json`)}function Me(e,t=new Set){if(t.has(e))return{};if(t.add(e),!p.existsSync(e))return E.warn(`Referenced tsconfig not found: ${e}`),{};try{let n=ue(void 0,e),{paths:r={},baseUrl:i=`.`}=n.compilerOptions||{},a={},o=v.dirname(e),s=Object.entries(r);for(let[e,t]of s)for(let n of t){let t=v.resolve(o,i),r=e.slice(-1)===`*`?e.slice(0,-1):e,s=n.slice(-1)===`*`?n.slice(0,-1):n;a[r||``]=v.join(t,s)}if(n.references)for(let e of n.references){let n=Me(je(o,e.path),t);for(let[e,t]of Object.entries(n))e in a||(a[e]=t)}return a}catch(t){return E.warn(`Error parsing tsconfig at ${e}: ${t}`),{}}}function Ne(e){let t=v.join(e,`tsconfig.json`);if(!p.existsSync(t))return null;try{let e=Me(t);return xe(e),e}catch(e){throw console.error(e),new C(`Error parsing tsconfig.json`)}}const Pe=e=>{let t=Ne(e)||{};return{transformOptions:{babel:{presets:[[I,{isTSX:!0,allExtensions:!0}],[te,{runtime:`automatic`}]]}},extensions:[`.ts`,`.tsx`,`.js`,`.jsx`],alias:t}},Fe=e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.keys(e).length>0&&`options`in e;async function X({cwd:e,configPath:t,shouldThrowOnError:n=!1}){process.env.IS_FAIRE_AUTH_CLI_ACCESS=`true`;try{let r=null;if(t){let i=v.join(e,t);m(t)&&(i=t);let{config:a}=await F({configFile:i,dotenv:!0,jitiOptions:Pe(e)});if(!(`auth`in a)&&!Fe(a)){if(n)throw Error(`Couldn't read your auth config in ${i}. Make sure to default export your auth instance or to export as a variable named auth.`);E.error(`[#faire-auth]: Couldn't read your auth config in ${i}. Make sure to default export your auth instance or to export as a variable named auth.`),process.exit(1)}r=`auth`in a?a.auth?.options:a.options}if(!r)for(let t of Y)try{let{config:i}=await F({configFile:t,jitiOptions:Pe(e)});if(Object.keys(i).length>0){if(r=i.auth?.options||i.default?.options||null,!r){if(n)throw Error(`Couldn't read your auth config. Make sure to default export your auth instance or to export as a variable named auth.`);E.error(`[#faire-auth]: Couldn't read your auth config.`),console.log(``),E.info(`[#faire-auth]: Make sure to default export your auth instance or to export as a variable named auth.`),process.exit(1)}break}}catch(e){if(typeof e==`object`&&e&&`message`in e&&typeof e.message==`string`&&e.message.includes(`This module cannot be imported from a Client Component module`)){if(n)throw Error(`Please remove import 'server-only' from your auth config file temporarily. The CLI cannot resolve the configuration with it included. You can re-add it after running the CLI.`);E.error(`Please remove import 'server-only' from your auth config file temporarily. The CLI cannot resolve the configuration with it included. You can re-add it after running the CLI.`),process.exit(1)}if(n)throw e;E.error(`[#faire-auth]: Couldn't read your auth config.`,e),process.exit(1)}return r}catch(e){if(typeof e==`object`&&e&&`message`in e&&typeof e.message==`string`&&e.message.includes(`This module cannot be imported from a Client Component module`)){if(n)throw Error(`Please remove import 'server-only' from your auth config file temporarily. The CLI cannot resolve the configuration with it included. You can re-add it after running the CLI.`);E.error(`Please remove import 'server-only' from your auth config file temporarily. The CLI cannot resolve the configuration with it included. You can re-add it after running the CLI.`),process.exit(1)}if(n)throw e;E.error(`Couldn't read your auth config.`,e),process.exit(1)}finally{process.env.IS_FAIRE_AUTH_CLI_ACCESS=void 0}}async function Ie(e){let t=S.object({cwd:S.string(),config:S.string().optional(),y:S.boolean().optional(),yes:S.boolean().optional()}).parse(e),n=v.resolve(t.cwd);m(n)||(E.error(`The directory "${n}" does not exist.`),process.exit(1));let r=await X({cwd:n,...t.config&&{configPath:t.config}});if(!r){E.error("No configuration file found. Add a `auth.ts` file to your project or pass the path to the configuration file using the `--config` flag.");return}let i=A(r);if(i||(E.error(`Invalid database configuration. Make sure you're not using adapters. Migrate command only works with built-in Kysely adapter.`),process.exit(1)),i.id!==`kysely`){if(i.id===`prisma`){E.error("The migrate command only works with the built-in Kysely adapter. For Prisma, run `npx @faire-auth/cli generate` to create the schema, then use Prisma’s migrate or push to apply it.");try{await w(r).publish({type:`cli_migrate`,payload:{outcome:`unsupported_adapter`,adapter:`prisma`,config:T(r)}})}catch{}process.exit(0)}if(i.id===`drizzle`){E.error("The migrate command only works with the built-in Kysely adapter. For Drizzle, run `npx @faire-auth/cli generate` to create the schema, then use Drizzle’s migrate or push to apply it.");try{await w(r).publish({type:`cli_migrate`,payload:{outcome:`unsupported_adapter`,adapter:`drizzle`,config:T(r)}})}catch{}process.exit(0)}E.error(`Migrate command isn't supported for this adapter.`);try{await w(r).publish({type:`cli_migrate`,payload:{outcome:`unsupported_adapter`,adapter:i.id,config:T(r)}})}catch{}process.exit(1)}let a=P({text:`preparing migration...`}).start(),{toBeAdded:o,toBeCreated:s,runMigrations:c}=await M(r);if(!o.length&&!s.length){a.stop(),E.info(`šŸš€ No migrations needed.`);try{await w(r).publish({type:`cli_migrate`,payload:{outcome:`no_changes`,config:T(r)}})}catch{}process.exit(0)}a.stop(),E.info(`šŸ”‘ The migration will affect the following:`);for(let e of[...s,...o])console.log(`->`,d.magenta(Object.keys(e.fields).join(`, `)),d.white(`fields on`),d.yellow(`${e.table}`),d.white(`table.`));t.y&&(console.warn(`WARNING: --y is deprecated. Consider -y or --yes`),t.yes=!0);let l=t.yes;if(l||=(await N({type:`confirm`,name:`migrate`,message:`Are you sure you want to run these migrations?`,initial:!1})).migrate,!l){E.info(`Migration cancelled.`);try{await w(r).publish({type:`cli_migrate`,payload:{outcome:`aborted`,config:T(r)}})}catch{}process.exit(0)}a?.start(`migrating...`),await c(),a.stop(),E.info(`šŸš€ migration was completed successfully!`);try{await w(r).publish({type:`cli_migrate`,payload:{outcome:`migrated`,config:T(r)}})}catch{}process.exit(0)}const Le=new e(`migrate`).option(`-c, --cwd <cwd>`,`the working directory. defaults to the current directory.`,process.cwd()).option(`--config <config>`,`the path to the configuration file. defaults to the first configuration file found.`).option(`-y, --yes`,`automatically accept and run migrations without prompting`,!1).option(`--y`,`(deprecated) same as --yes`,!1).action(Ie);function Re(e,t){return t?e:e.replace(/([A-Z]+)([A-Z][a-z])/g,`$1_$2`).replace(/([a-z\d])([A-Z])/g,`$1_$2`).toLowerCase()}const ze=async({options:e,file:t,adapter:n})=>{let r=j(e),i=t||`./auth-schema.ts`,a=n.options?.provider;if(!a)throw Error("Database provider type is undefined during Drizzle schema generation. Please define a `provider` in the Drizzle adapter config. Read more at https://faire-auth.com/docs/adapters/drizzle");let o=m(i),s=Be({databaseType:a,tables:r,options:e});for(let t in r){let i=r[t],o=Ve(i.modelName,n.options),c=i.fields;function l(t,r){if(!a)throw Error("Database provider type is undefined during Drizzle schema generation. Please define a `provider` in the Drizzle adapter config. Read more at https://faire-auth.com/docs/adapters/drizzle");if(t=Re(t,n.options?.camelCase),r.references?.field===`id`)return e.advanced?.database?.useNumberId?a===`pg`?`integer('${t}')`:a===`mysql`?`int('${t}')`:`integer('${t}')`:r.references.field&&a===`mysql`?`varchar('${t}', { length: 36 })`:`text('${t}')`;let i=r.type;return{string:{sqlite:`text('${t}')`,pg:`text('${t}')`,mysql:r.unique?`varchar('${t}', { length: 255 })`:r.references?`varchar('${t}', { length: 36 })`:`text('${t}')`},boolean:{sqlite:`integer('${t}', { mode: 'boolean' })`,pg:`boolean('${t}')`,mysql:`boolean('${t}')`},number:{sqlite:`integer('${t}')`,pg:r.bigint?`bigint('${t}', { mode: 'number' })`:`integer('${t}')`,mysql:r.bigint?`bigint('${t}', { mode: 'number' })`:`int('${t}')`},date:{sqlite:`integer('${t}', { mode: 'timestamp_ms' })`,pg:`timestamp('${t}')`,mysql:`timestamp('${t}', { fsp: 3 })`},"number[]":{sqlite:`integer('${t}').array()`,pg:r.bigint?`bigint('${t}', { mode: 'number' }).array()`:`integer('${t}').array()`,mysql:r.bigint?`bigint('${t}', { mode: 'number' }).array()`:`int('${t}').array()`},"string[]":{sqlite:`text('${t}').array()`,pg:`text('${t}').array()`,mysql:`text('${t}').array()`},json:{sqlite:`text('${t}')`,pg:`jsonb('${t}')`,mysql:`json('${t}')`}}[i][a]}let u=``;u=e.advanced?.database?.useNumberId?a===`pg`?`serial("id").primaryKey()`:a===`sqlite`?`integer("id", { mode: "number" }).primaryKey({ autoIncrement: true })`:`int("id").autoincrement().primaryKey()`:a===`mysql`?`varchar('id', { length: 36 }).primaryKey()`:`text('id').primaryKey()`;let d=`export const ${o} = ${a}Table("${Re(o,n.options?.camelCase)}", {
62
+ `}function De(e,t){return Object.fromEntries(Object.entries(process.env).filter(([n])=>n.startsWith(t)&&(e===``||!n.startsWith(e))))}function Oe(e,t){return Object.fromEntries(Object.entries(process.env).filter(([n])=>n.startsWith(e)&&(t===``||!n.startsWith(t))))}const ke=/^[a-zA-Z_$][a-zA-Z0-9_$]*$/,Ae=/* @__PURE__ */ new Set(/* @__PURE__ */ `do.if.in.for.let.new.try.var.case.else.enum.eval.null.this.true.void.with.await.break.catch.class.const.false.super.throw.while.yield.delete.export.import.public.return.static.switch.typeof.default.extends.finally.package.private.continue.debugger.function.arguments.interface.protected.implements.instanceof`.split(`.`));let Y=[`auth.ts`,`auth.tsx`,`auth.js`,`auth.jsx`,`auth.server.js`,`auth.server.ts`];Y=[...Y,...Y.map(e=>`lib/server/${e}`),...Y.map(e=>`server/${e}`),...Y.map(e=>`lib/${e}`),...Y.map(e=>`utils/${e}`)],Y=[...Y,...Y.map(e=>`src/${e}`),...Y.map(e=>`app/${e}`)];function je(e,t){let n=_.resolve(e,t);if(t.endsWith(`.json`))return n;if(p.existsSync(n))try{if(p.statSync(n).isFile())return n}catch{}return _.resolve(e,t,`tsconfig.json`)}function Me(e,t=/* @__PURE__ */ new Set){if(t.has(e))return{};if(t.add(e),!p.existsSync(e))return E.warn(`Referenced tsconfig not found: ${e}`),{};try{let n=ue(void 0,e),{paths:r={},baseUrl:i=`.`}=n.compilerOptions||{},a={},o=_.dirname(e),s=Object.entries(r);for(let[e,t]of s)for(let n of t){let t=_.resolve(o,i),r=e.slice(-1)===`*`?e.slice(0,-1):e,s=n.slice(-1)===`*`?n.slice(0,-1):n;a[r||``]=_.join(t,s)}if(n.references)for(let e of n.references){let n=Me(je(o,e.path),t);for(let[e,t]of Object.entries(n))e in a||(a[e]=t)}return a}catch(t){return E.warn(`Error parsing tsconfig at ${e}: ${t}`),{}}}function Ne(e){let t=_.join(e,`tsconfig.json`);if(!p.existsSync(t))return null;try{let e=Me(t);return xe(e),e}catch(e){throw console.error(e),new C(`Error parsing tsconfig.json`)}}const Pe=e=>{let t=Ne(e)||{};return{transformOptions:{babel:{presets:[[I,{isTSX:!0,allExtensions:!0}],[te,{runtime:`automatic`}]]}},extensions:[`.ts`,`.tsx`,`.js`,`.jsx`],alias:t}},Fe=e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&Object.keys(e).length>0&&`options`in e;async function X({cwd:e,configPath:t,shouldThrowOnError:n=!1}){process.env.IS_FAIRE_AUTH_CLI_ACCESS=`true`;try{let r=null;if(t){let i=_.join(e,t);m(t)&&(i=t);let{config:a}=await F({configFile:i,dotenv:!0,jitiOptions:Pe(e)});if(!(`auth`in a)&&!Fe(a)){if(n)throw Error(`Couldn't read your auth config in ${i}. Make sure to default export your auth instance or to export as a variable named auth.`);E.error(`[#faire-auth]: Couldn't read your auth config in ${i}. Make sure to default export your auth instance or to export as a variable named auth.`),process.exit(1)}r=`auth`in a?a.auth?.options:a.options}if(!r)for(let t of Y)try{let{config:i}=await F({configFile:t,jitiOptions:Pe(e)});if(Object.keys(i).length>0){if(r=i.auth?.options||i.default?.options||null,!r){if(n)throw Error(`Couldn't read your auth config. Make sure to default export your auth instance or to export as a variable named auth.`);E.error(`[#faire-auth]: Couldn't read your auth config.`),console.log(``),E.info(`[#faire-auth]: Make sure to default export your auth instance or to export as a variable named auth.`),process.exit(1)}break}}catch(e){if(typeof e==`object`&&e&&`message`in e&&typeof e.message==`string`&&e.message.includes(`This module cannot be imported from a Client Component module`)){if(n)throw Error(`Please remove import 'server-only' from your auth config file temporarily. The CLI cannot resolve the configuration with it included. You can re-add it after running the CLI.`);E.error(`Please remove import 'server-only' from your auth config file temporarily. The CLI cannot resolve the configuration with it included. You can re-add it after running the CLI.`),process.exit(1)}if(n)throw e;E.error(`[#faire-auth]: Couldn't read your auth config.`,e),process.exit(1)}return r}catch(e){if(typeof e==`object`&&e&&`message`in e&&typeof e.message==`string`&&e.message.includes(`This module cannot be imported from a Client Component module`)){if(n)throw Error(`Please remove import 'server-only' from your auth config file temporarily. The CLI cannot resolve the configuration with it included. You can re-add it after running the CLI.`);E.error(`Please remove import 'server-only' from your auth config file temporarily. The CLI cannot resolve the configuration with it included. You can re-add it after running the CLI.`),process.exit(1)}if(n)throw e;E.error(`Couldn't read your auth config.`,e),process.exit(1)}finally{process.env.IS_FAIRE_AUTH_CLI_ACCESS=void 0}}async function Ie(e){let t=S.object({cwd:S.string(),config:S.string().optional(),y:S.boolean().optional(),yes:S.boolean().optional()}).parse(e),n=_.resolve(t.cwd);m(n)||(E.error(`The directory "${n}" does not exist.`),process.exit(1));let r=await X({cwd:n,...t.config&&{configPath:t.config}});if(!r){E.error("No configuration file found. Add a `auth.ts` file to your project or pass the path to the configuration file using the `--config` flag.");return}let i=A(r);if(i||(E.error(`Invalid database configuration. Make sure you're not using adapters. Migrate command only works with built-in Kysely adapter.`),process.exit(1)),i.id!==`kysely`){if(i.id===`prisma`){E.error("The migrate command only works with the built-in Kysely adapter. For Prisma, run `npx @faire-auth/cli generate` to create the schema, then use Prisma’s migrate or push to apply it.");try{await w(r).publish({type:`cli_migrate`,payload:{outcome:`unsupported_adapter`,adapter:`prisma`,config:T(r)}})}catch{}process.exit(0)}if(i.id===`drizzle`){E.error("The migrate command only works with the built-in Kysely adapter. For Drizzle, run `npx @faire-auth/cli generate` to create the schema, then use Drizzle’s migrate or push to apply it.");try{await w(r).publish({type:`cli_migrate`,payload:{outcome:`unsupported_adapter`,adapter:`drizzle`,config:T(r)}})}catch{}process.exit(0)}E.error(`Migrate command isn't supported for this adapter.`);try{await w(r).publish({type:`cli_migrate`,payload:{outcome:`unsupported_adapter`,adapter:i.id,config:T(r)}})}catch{}process.exit(1)}let a=P({text:`preparing migration...`}).start(),{toBeAdded:o,toBeCreated:s,runMigrations:c}=await M(r);if(!o.length&&!s.length){a.stop(),E.info(`šŸš€ No migrations needed.`);try{await w(r).publish({type:`cli_migrate`,payload:{outcome:`no_changes`,config:T(r)}})}catch{}process.exit(0)}a.stop(),E.info(`šŸ”‘ The migration will affect the following:`);for(let e of[...s,...o])console.log(`->`,d.magenta(Object.keys(e.fields).join(`, `)),d.white(`fields on`),d.yellow(`${e.table}`),d.white(`table.`));t.y&&(console.warn(`WARNING: --y is deprecated. Consider -y or --yes`),t.yes=!0);let l=t.yes;if(l||=(await N({type:`confirm`,name:`migrate`,message:`Are you sure you want to run these migrations?`,initial:!1})).migrate,!l){E.info(`Migration cancelled.`);try{await w(r).publish({type:`cli_migrate`,payload:{outcome:`aborted`,config:T(r)}})}catch{}process.exit(0)}a?.start(`migrating...`),await c(),a.stop(),E.info(`šŸš€ migration was completed successfully!`);try{await w(r).publish({type:`cli_migrate`,payload:{outcome:`migrated`,config:T(r)}})}catch{}process.exit(0)}const Le=new e(`migrate`).option(`-c, --cwd <cwd>`,`the working directory. defaults to the current directory.`,process.cwd()).option(`--config <config>`,`the path to the configuration file. defaults to the first configuration file found.`).option(`-y, --yes`,`automatically accept and run migrations without prompting`,!1).option(`--y`,`(deprecated) same as --yes`,!1).action(Ie);function Re(e,t){return t?e:e.replace(/([A-Z]+)([A-Z][a-z])/g,`$1_$2`).replace(/([a-z\d])([A-Z])/g,`$1_$2`).toLowerCase()}const ze=async({options:e,file:t,adapter:n})=>{let r=j(e),i=t||`./auth-schema.ts`,a=n.options?.provider;if(!a)throw Error("Database provider type is undefined during Drizzle schema generation. Please define a `provider` in the Drizzle adapter config. Read more at https://faire-auth.com/docs/adapters/drizzle");let o=m(i),s=Be({databaseType:a,tables:r,options:e});for(let t in r){let i=r[t],o=Ve(i.modelName,n.options),c=i.fields;function l(t,r){if(!a)throw Error("Database provider type is undefined during Drizzle schema generation. Please define a `provider` in the Drizzle adapter config. Read more at https://faire-auth.com/docs/adapters/drizzle");if(t=Re(t,n.options?.camelCase),r.references?.field===`id`)return e.advanced?.database?.useNumberId?a===`pg`?`integer('${t}')`:a===`mysql`?`int('${t}')`:`integer('${t}')`:r.references.field&&a===`mysql`?`varchar('${t}', { length: 36 })`:`text('${t}')`;let i=r.type;return{string:{sqlite:`text('${t}')`,pg:`text('${t}')`,mysql:r.unique?`varchar('${t}', { length: 255 })`:r.references?`varchar('${t}', { length: 36 })`:`text('${t}')`},boolean:{sqlite:`integer('${t}', { mode: 'boolean' })`,pg:`boolean('${t}')`,mysql:`boolean('${t}')`},number:{sqlite:`integer('${t}')`,pg:r.bigint?`bigint('${t}', { mode: 'number' })`:`integer('${t}')`,mysql:r.bigint?`bigint('${t}', { mode: 'number' })`:`int('${t}')`},date:{sqlite:`integer('${t}', { mode: 'timestamp_ms' })`,pg:`timestamp('${t}')`,mysql:`timestamp('${t}', { fsp: 3 })`},"number[]":{sqlite:`integer('${t}').array()`,pg:r.bigint?`bigint('${t}', { mode: 'number' }).array()`:`integer('${t}').array()`,mysql:r.bigint?`bigint('${t}', { mode: 'number' }).array()`:`int('${t}').array()`},"string[]":{sqlite:`text('${t}').array()`,pg:`text('${t}').array()`,mysql:`text('${t}').array()`},json:{sqlite:`text('${t}')`,pg:`jsonb('${t}')`,mysql:`json('${t}')`}}[i][a]}let u=``;u=e.advanced?.database?.useNumberId?a===`pg`?`serial("id").primaryKey()`:a===`sqlite`?`integer("id", { mode: "number" }).primaryKey({ autoIncrement: true })`:`int("id").autoincrement().primaryKey()`:a===`mysql`?`varchar('id', { length: 36 }).primaryKey()`:`text('id').primaryKey()`;let d=`export const ${o} = ${a}Table("${Re(o,n.options?.camelCase)}", {
63
63
  id: ${u},
64
- ${Object.keys(c).map(e=>{let t=c[e],i=t.fieldName||e,o=l(i,t);return t.defaultValue!==null&&t.defaultValue!==void 0&&(typeof t.defaultValue==`function`?t.type===`date`&&t.defaultValue.toString().includes(`new Date()`)&&(a===`sqlite`?o+=".default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)":o+=`.defaultNow()`):typeof t.defaultValue==`string`?o+=`.default("${t.defaultValue}")`:o+=`.default(${t.defaultValue})`),t.onUpdate&&t.type===`date`&&typeof t.onUpdate==`function`&&(o+=`.$onUpdate(${t.onUpdate})`),`${i}: ${o}${t.required?`.notNull()`:``}${t.unique?`.unique()`:``}${t.references?`.references(()=> ${Ve(r[t.references.model]?.modelName||t.references.model,n.options)}.${c[t.references.field]?.fieldName||t.references.field}, { onDelete: '${t.references.onDelete||`cascade`}' })`:``}`}).join(`,
64
+ ${Object.keys(c).map(e=>{let t=c[e],i=t.fieldName||e,o=l(i,t);return t.defaultValue!==null&&t.defaultValue!==void 0&&(typeof t.defaultValue==`function`?t.type===`date`&&t.defaultValue.toString().includes(`new Date()`)&&(o+=a===`sqlite`?".default(sql`(cast(unixepoch('subsecond') * 1000 as integer))`)":`.defaultNow()`):typeof t.defaultValue==`string`?o+=`.default("${t.defaultValue}")`:o+=`.default(${t.defaultValue})`),t.onUpdate&&t.type===`date`&&typeof t.onUpdate==`function`&&(o+=`.$onUpdate(${t.onUpdate})`),`${i}: ${o}${t.required?`.notNull()`:``}${t.unique?`.unique()`:``}${t.references?`.references(()=> ${Ve(r[t.references.model]?.modelName||t.references.model,n.options)}.${c[t.references.field]?.fieldName||t.references.field}, { onDelete: '${t.references.onDelete||`cascade`}' })`:``}`}).join(`,
65
65
  `)}
66
- });`;s+=`\n${d}\n`}return{code:await y.format(s,{parser:`typescript`}),fileName:i,overwrite:o}};function Be({databaseType:e,tables:t,options:n}){let r=[],i=[],a=!1,o=!1;for(let e of Object.values(t)){for(let t of Object.values(e.fields))t.bigint&&(a=!0),t.type===`json`&&(o=!0);if(o&&a)break}let s=n.advanced?.database?.useNumberId;if(i.push(`${e}Table`),i.push(e===`mysql`?`varchar, text`:`text`),i.push(a?e===`sqlite`?``:`bigint`:``),i.push(e===`sqlite`?``:`timestamp, boolean`),e===`mysql`){let e=Object.values(t).some(e=>Object.values(e.fields).some(e=>(e.type===`number`||e.type===`number[]`)&&!e.bigint));(s||e)&&i.push(`int`),Object.values(t).some(e=>Object.values(e.fields).some(e=>typeof e.type!=`string`&&Array.isArray(e.type)&&e.type.every(e=>typeof e==`string`)))&&i.push(`mysqlEnum`)}else if(e===`pg`){let e=Object.values(t).some(e=>Object.values(e.fields).some(e=>(e.type===`number`||e.type===`number[]`)&&!e.bigint)),r=Object.values(t).some(e=>Object.values(e.fields).some(e=>e.references?.field===`id`));(e||n.advanced?.database?.useNumberId&&r)&&i.push(`integer`),Object.values(t).some(e=>Object.values(e.fields).some(e=>typeof e.type!=`string`&&Array.isArray(e.type)&&e.type.every(e=>typeof e==`string`)))&&i.push(`pgEnum`)}else i.push(`integer`);return i.push(s&&e===`pg`?`serial`:``),o&&(e===`pg`&&i.push(`jsonb`),e===`mysql`&&i.push(`json`)),e===`sqlite`&&Object.values(t).some(e=>Object.values(e.fields).some(e=>e.type===`date`&&e.defaultValue&&typeof e.defaultValue==`function`&&e.defaultValue.toString().includes(`new Date()`)))&&r.push(`sql`),`${r.length>0?`import { ${r.join(`, `)} } from "drizzle-orm";\n`:``}import { ${i.map(e=>e.trim()).filter(e=>e!==``).join(`, `)} } from "drizzle-orm/${e}-core";\n`}function Ve(e,t){return t?.usePlural?`${e}s`:e}const Z=e=>e.charAt(0).toUpperCase()+e.slice(1),He=async({adapter:e,options:t,file:n})=>{let r=e.options?.provider||`postgresql`,i=j(t),a=n||`./prisma/schema.prisma`,o=m(v.join(process.cwd(),a)),s=``;s=o?await g.readFile(v.join(process.cwd(),a),`utf-8`):Ue(r);let c=new Map;for(let e in i){let t=i[e]?.fields;for(let n in t){let r=t[n];if(r.references){let t=r.references.model,n=Z(i[t]?.modelName||t);c.has(n)||c.set(n,new Set);let a=Z(i[e]?.modelName||e);c.get(n).add(a)}}}let l=ne(s,e=>{for(let n in i){let a=n,o=i[n]?.modelName||n,s=Z(o),l=i[n]?.fields;function u({isBigint:e,isOptional:t,type:n}){if(n===`string`)return t?`String?`:`String`;if(n===`number`&&e)return t?`BigInt?`:`BigInt`;if(n===`number`)return t?`Int?`:`Int`;if(n===`boolean`)return t?`Boolean?`:`Boolean`;if(n===`date`)return t?`DateTime?`:`DateTime`;if(n===`json`)return t?`Json?`:`Json`;if(n===`string[]`)return`String[]`;if(n===`number[]`)return`Int[]`}let d=e.findByType(`model`,{name:s});for(let n in d||(r===`mongodb`?e.model(s).field(`id`,`String`).attribute(`id`).attribute(`map("_id")`):t.advanced?.database?.useNumberId?e.model(s).field(`id`,`Int`).attribute(`id`).attribute(`default(autoincrement())`):e.model(s).field(`id`,`String`).attribute(`id`)),l){let a=l[n],o=a.fieldName||n;if(d&&e.findByType(`field`,{name:o,within:d.properties}))continue;let c=e.model(s).field(o,n===`id`&&t.advanced?.database?.useNumberId?u({isBigint:!1,isOptional:!1,type:`number`}):u({isBigint:a?.bigint||!1,isOptional:!a?.required,type:a.references?.field===`id`?t.advanced?.database?.useNumberId?`number`:`string`:a.type}));if(n===`id`&&(c.attribute(`id`),r===`mongodb`&&c.attribute(`map("_id")`)),a.unique&&e.model(s).blockAttribute(`unique([${o}])`),a.defaultValue!==void 0&&(n===`createdAt`||n===`updatedAt`?c.attribute(`default(now())`):typeof a.defaultValue==`boolean`?c.attribute(`default(${a.defaultValue})`):a.defaultValue),n===`updatedAt`&&a.onUpdate?c.attribute(`updatedAt`):a.onUpdate,a.references){let t=a.references.model,n=i[t]?.modelName||t,r=`Cascade`;a.references.onDelete===`no action`?r=`NoAction`:a.references.onDelete===`set null`?r=`SetNull`:a.references.onDelete===`set default`?r=`SetDefault`:a.references.onDelete===`restrict`&&(r=`Restrict`),e.model(s).field(`${n.toLowerCase()}`,`${Z(n)}${a.required?``:`?`}`).attribute(`relation(fields: [${o}], references: [${a.references.field}], onDelete: ${r})`)}!a.unique&&!a.references&&r===`mysql`&&a.type===`string`&&e.model(s).field(o).attribute(`db.Text`)}if(c.has(s))for(let t of c.get(s)){let n=`${t.toLowerCase()}s`;e.findByType(`field`,{name:n,...d?.properties&&{within:d.properties}})||e.model(s).field(n,`${t}[]`)}let ee=e.findByType(`attribute`,{name:`map`,...d?.properties&&{within:d.properties}}),f=o!==a;ee||e.model(s).blockAttribute(`map`,`${f?o:a}`)}}),u=l.trim()!==s.trim();return{code:u?l:``,fileName:a,overwrite:o&&u}},Ue=e=>`generator client {
66
+ });`;s+=`\n${d}\n`}return{code:await y.format(s,{parser:`typescript`}),fileName:i,overwrite:o}};function Be({databaseType:e,tables:t,options:n}){let r=[],i=[],a=!1,o=!1;for(let e of Object.values(t)){for(let t of Object.values(e.fields))t.bigint&&(a=!0),t.type===`json`&&(o=!0);if(o&&a)break}let s=n.advanced?.database?.useNumberId;if(i.push(`${e}Table`),i.push(e===`mysql`?`varchar, text`:`text`),i.push(a?e===`sqlite`?``:`bigint`:``),i.push(e===`sqlite`?``:`timestamp, boolean`),e===`mysql`){let e=Object.values(t).some(e=>Object.values(e.fields).some(e=>(e.type===`number`||e.type===`number[]`)&&!e.bigint));(s||e)&&i.push(`int`),Object.values(t).some(e=>Object.values(e.fields).some(e=>typeof e.type!=`string`&&Array.isArray(e.type)&&e.type.every(e=>typeof e==`string`)))&&i.push(`mysqlEnum`)}else if(e===`pg`){let e=Object.values(t).some(e=>Object.values(e.fields).some(e=>(e.type===`number`||e.type===`number[]`)&&!e.bigint)),r=Object.values(t).some(e=>Object.values(e.fields).some(e=>e.references?.field===`id`));(e||n.advanced?.database?.useNumberId&&r)&&i.push(`integer`),Object.values(t).some(e=>Object.values(e.fields).some(e=>typeof e.type!=`string`&&Array.isArray(e.type)&&e.type.every(e=>typeof e==`string`)))&&i.push(`pgEnum`)}else i.push(`integer`);return i.push(s&&e===`pg`?`serial`:``),o&&(e===`pg`&&i.push(`jsonb`),e===`mysql`&&i.push(`json`)),e===`sqlite`&&Object.values(t).some(e=>Object.values(e.fields).some(e=>e.type===`date`&&e.defaultValue&&typeof e.defaultValue==`function`&&e.defaultValue.toString().includes(`new Date()`)))&&r.push(`sql`),`${r.length>0?`import { ${r.join(`, `)} } from "drizzle-orm";\n`:``}import { ${i.map(e=>e.trim()).filter(e=>e!==``).join(`, `)} } from "drizzle-orm/${e}-core";\n`}function Ve(e,t){return t?.usePlural?`${e}s`:e}const Z=e=>e.charAt(0).toUpperCase()+e.slice(1),He=async({adapter:e,options:t,file:n})=>{let r=e.options?.provider||`postgresql`,i=j(t),a=n||`./prisma/schema.prisma`,o=m(_.join(process.cwd(),a)),s=``;s=o?await g.readFile(_.join(process.cwd(),a),`utf-8`):Ue(r);let c=/* @__PURE__ */ new Map;for(let e in i){let t=i[e]?.fields;for(let n in t){let r=t[n];if(r.references){let t=r.references.model,n=i[t]?.modelName||t,a=Z(n);c.has(a)||c.set(a,/* @__PURE__ */ new Set);let o=i[e]?.modelName||e,s=Z(o);c.get(a).add(s)}}}let l=ne(s,e=>{for(let n in i){let a=n,o=i[n]?.modelName||n,s=Z(o),l=i[n]?.fields;function u({isBigint:e,isOptional:t,type:n}){if(n===`string`)return t?`String?`:`String`;if(n===`number`&&e)return t?`BigInt?`:`BigInt`;if(n===`number`)return t?`Int?`:`Int`;if(n===`boolean`)return t?`Boolean?`:`Boolean`;if(n===`date`)return t?`DateTime?`:`DateTime`;if(n===`json`)return t?`Json?`:`Json`;if(n===`string[]`)return`String[]`;if(n===`number[]`)return`Int[]`}let d=e.findByType(`model`,{name:s});d||(r===`mongodb`?e.model(s).field(`id`,`String`).attribute(`id`).attribute(`map("_id")`):t.advanced?.database?.useNumberId?e.model(s).field(`id`,`Int`).attribute(`id`).attribute(`default(autoincrement())`):e.model(s).field(`id`,`String`).attribute(`id`));for(let n in l){let a=l[n],o=a.fieldName||n;if(d&&e.findByType(`field`,{name:o,within:d.properties}))continue;let c=e.model(s).field(o,n===`id`&&t.advanced?.database?.useNumberId?u({isBigint:!1,isOptional:!1,type:`number`}):u({isBigint:a?.bigint||!1,isOptional:!a?.required,type:a.references?.field===`id`?t.advanced?.database?.useNumberId?`number`:`string`:a.type}));if(n===`id`&&(c.attribute(`id`),r===`mongodb`&&c.attribute(`map("_id")`)),a.unique&&e.model(s).blockAttribute(`unique([${o}])`),a.defaultValue!==void 0&&(n===`createdAt`||n===`updatedAt`?c.attribute(`default(now())`):typeof a.defaultValue==`boolean`?c.attribute(`default(${a.defaultValue})`):a.defaultValue),n===`updatedAt`&&a.onUpdate?c.attribute(`updatedAt`):a.onUpdate,a.references){let t=a.references.model,n=i[t]?.modelName||t,r=`Cascade`;a.references.onDelete===`no action`?r=`NoAction`:a.references.onDelete===`set null`?r=`SetNull`:a.references.onDelete===`set default`?r=`SetDefault`:a.references.onDelete===`restrict`&&(r=`Restrict`),e.model(s).field(`${n.toLowerCase()}`,`${Z(n)}${a.required?``:`?`}`).attribute(`relation(fields: [${o}], references: [${a.references.field}], onDelete: ${r})`)}!a.unique&&!a.references&&r===`mysql`&&a.type===`string`&&e.model(s).field(o).attribute(`db.Text`)}if(c.has(s))for(let t of c.get(s)){let n=`${t.toLowerCase()}s`;e.findByType(`field`,{name:n,...d?.properties&&{within:d.properties}})||e.model(s).field(n,`${t}[]`)}let ee=e.findByType(`attribute`,{name:`map`,...d?.properties&&{within:d.properties}}),f=o!==a;ee||e.model(s).blockAttribute(`map`,`${f?o:a}`)}}),u=l.trim()!==s.trim();return{code:u?l:``,fileName:a,overwrite:o&&u}},Ue=e=>`generator client {
67
67
  provider = "prisma-client-js"
68
68
  }
69
69
 
70
70
  datasource db {
71
71
  provider = "${e}"
72
72
  url = ${e===`sqlite`?`"file:./dev.db"`:`env("DATABASE_URL")`}
73
- }`,We={prisma:He,drizzle:ze,kysely:async({options:e,file:t})=>{let{compileMigrations:n}=await M(e),r=await n();return{code:r.trim()===`;`?``:r,fileName:t||`./faire-auth_migrations/${new Date().toISOString().replace(/:/g,`-`)}.sql`}}},Ge=e=>{let t=e.adapter,n=t.id in We?We[t.id]:null;if(n)return n(e);if(t.createSchema)return t.createSchema(e.options,e.file).then(({code:e,path:t,overwrite:n})=>({code:e,fileName:t,overwrite:n}));E.error(`${t.id} is not supported. If it is a custom adapter, please request the maintainer to implement createSchema`),process.exit(1)};async function Ke(e){let t=S.object({cwd:S.string(),config:S.string().optional(),output:S.string().optional(),y:S.boolean().optional(),yes:S.boolean().optional()}).parse(e),n=v.resolve(t.cwd);m(n)||(E.error(`The directory "${n}" does not exist.`),process.exit(1));let r=await X({cwd:n,...t.config&&{configPath:t.config}});if(!r){E.error("No configuration file found. Add a `auth.ts` file to your project or pass the path to the configuration file using the `--config` flag.");return}let i;try{i=A(r)}catch(e){E.error(e instanceof Error?e.message:`Unknown getAdapter() error`),process.exit(1)}let a=P({text:`preparing schema...`}).start(),o=await Ge({adapter:i,...t.output&&{file:t.output},options:r});if(a.stop(),!o.code){E.info(`Your schema is already up to date.`);try{await w(r).publish({type:`cli_generate`,payload:{outcome:`no_changes`,config:T(r,{adapter:i.id,database:typeof r.database==`function`?`adapter`:`kysely`})}})}catch{}process.exit(0)}if(o.overwrite){let e=t.y||t.yes;if(e||=(await N({type:`confirm`,name:`confirm`,message:`The file ${o.fileName} already exists. Do you want to ${d.yellow(`${o.overwrite?`overwrite`:`append`}`)} the schema to the file?`})).confirm,e){m(v.join(n,o.fileName))||await g.mkdir(v.dirname(v.join(n,o.fileName)),{recursive:!0}),o.overwrite?await g.writeFile(v.join(n,o.fileName),o.code):await g.appendFile(v.join(n,o.fileName),o.code),E.success(`šŸš€ Schema was ${o.overwrite?`overwritten`:`appended`} successfully!`);try{await w(r).publish({type:`cli_generate`,payload:{outcome:o.overwrite?`overwritten`:`appended`,config:T(r)}})}catch{}process.exit(0)}else{E.error(`Schema generation aborted.`);try{await w(r).publish({type:`cli_generate`,payload:{outcome:`aborted`,config:T(r)}})}catch{}process.exit(1)}}t.y&&(console.warn(`WARNING: --y is deprecated. Consider -y or --yes`),t.yes=!0);let s=t.yes;if(s||=(await N({type:`confirm`,name:`confirm`,message:`Do you want to generate the schema to ${d.yellow(o.fileName)}?`})).confirm,!s){E.error(`Schema generation aborted.`);try{await w(r).publish({type:`cli_generate`,payload:{outcome:`aborted`,config:T(r)}})}catch{}process.exit(1)}t.output||m(v.dirname(v.join(n,o.fileName)))||await g.mkdir(v.dirname(v.join(n,o.fileName)),{recursive:!0}),await g.writeFile(t.output||v.join(n,o.fileName),o.code),E.success(`šŸš€ Schema was generated successfully!`);try{await w(r).publish({type:`cli_generate`,payload:{outcome:`generated`,config:T(r)}})}catch{}process.exit(0)}const qe=new e(`generate`).option(`-c, --cwd <cwd>`,`the working directory. defaults to the current directory.`,process.cwd()).option(`--config <config>`,`the path to the configuration file. defaults to the first configuration file found.`).option(`--output <output>`,`the file to output to the generated schema`).option(`-y, --yes`,`automatically answer yes to all prompts`,!1).option(`--y`,`(deprecated) same as --yes`,!1).action(Ke);function Je(){let e=L.platform(),t=L.arch(),n=L.version(),r=L.release(),i=L.cpus(),a=L.totalmem(),o=L.freemem();return{platform:e,arch:t,version:n,release:r,cpuCount:i.length,cpuModel:i[0]?.model||`Unknown`,totalMemory:`${(a/1024/1024/1024).toFixed(2)} GB`,freeMemory:`${(o/1024/1024/1024).toFixed(2)} GB`}}function Ye(){return{version:process.version,env:process.env.NODE_ENV||`development`}}function Xe(){let e=process.env.npm_config_user_agent||``;return e.includes(`yarn`)?{name:`yarn`,version:Q(`yarn`)}:e.includes(`pnpm`)?{name:`pnpm`,version:Q(`pnpm`)}:e.includes(`bun`)?{name:`bun`,version:Q(`bun`)}:{name:`npm`,version:Q(`npm`)}}function Q(e){try{return O(`${e} --version`,{encoding:`utf8`}).trim()}catch{return`Not installed`}}function Ze(e){let t=v.join(e,`package.json`);if(!m(t))return null;try{let e=JSON.parse(h(t,`utf8`)),n={...e.dependencies,...e.devDependencies},r={next:n.next,react:n.react,vue:n.vue,nuxt:n.nuxt,svelte:n.svelte,"@sveltejs/kit":n[`@sveltejs/kit`],express:n.express,fastify:n.fastify,hono:n.hono,remix:n[`@remix-run/react`],astro:n.astro,solid:n[`solid-js`],qwik:n[`@builder.io/qwik`]},i=Object.entries(r).filter(([e,t])=>t).map(([e,t])=>({name:e,version:t}));return i.length>0?i:null}catch{return null}}function Qe(e){let t=v.join(e,`package.json`);if(!m(t))return null;try{let e=JSON.parse(h(t,`utf8`)),n={...e.dependencies,...e.devDependencies},r={"better-sqlite3":n[`better-sqlite3`],"@libsql/client":n[`@libsql/client`],"@libsql/kysely-libsql":n[`@libsql/kysely-libsql`],mysql2:n.mysql2,pg:n.pg,postgres:n.postgres,"@prisma/client":n[`@prisma/client`],drizzle:n[`drizzle-orm`],kysely:n.kysely,mongodb:n.mongodb,"@neondatabase/serverless":n[`@neondatabase/serverless`],"@vercel/postgres":n[`@vercel/postgres`],"@planetscale/database":n[`@planetscale/database`]},i=Object.entries(r).filter(([e,t])=>t).map(([e,t])=>({name:e,version:t}));return i.length>0?i:null}catch{return null}}function $e(e){if(!e)return null;let t=JSON.parse(JSON.stringify(e)),n=[`secret`,`clientSecret`,`clientId`,`authToken`,`apiKey`,`apiSecret`,`privateKey`,`publicKey`,`password`,`token`,`webhook`,`connectionString`,`databaseUrl`,`databaseURL`,`TURSO_AUTH_TOKEN`,`TURSO_DATABASE_URL`,`MYSQL_DATABASE_URL`,`DATABASE_URL`,`POSTGRES_URL`,`MONGODB_URI`,`stripeKey`,`stripeWebhookSecret`],r=[`baseURL`,`callbackURL`,`redirectURL`,`trustedOrigins`,`appName`];function i(e,t){if(typeof e!=`object`||!e){if(t&&typeof e==`string`&&e.length>0){if(r.some(e=>t.toLowerCase()===e.toLowerCase()))return e;let i=t.toLowerCase();if(n.some(e=>{let t=e.toLowerCase();return i===t||i.endsWith(t)}))return`[REDACTED]`}return e}if(Array.isArray(e))return e.map(e=>i(e,t));let a={};for(let[t,o]of Object.entries(e)){if(r.some(e=>t.toLowerCase()===e.toLowerCase())){a[t]=o;continue}let e=t.toLowerCase();n.some(t=>{let n=t.toLowerCase();return e===n||e.endsWith(n)})?typeof o==`string`&&o.length>0?a[t]=`[REDACTED]`:typeof o==`object`&&o?a[t]=i(o,t):a[t]=o:a[t]=i(o,t)}return a}if(t.database&&(typeof t.database==`string`?t.database=`[REDACTED]`:t.database.url&&(t.database.url=`[REDACTED]`),t.database.authToken&&(t.database.authToken=`[REDACTED]`)),t.socialProviders)for(let e in t.socialProviders)t.socialProviders[e]&&(t.socialProviders[e]=i(t.socialProviders[e],e));return t.emailAndPassword?.sendResetPassword&&(t.emailAndPassword.sendResetPassword=`[Function]`),t.emailVerification?.sendVerificationEmail&&(t.emailVerification.sendVerificationEmail=`[Function]`),t.plugins&&Array.isArray(t.plugins)&&(t.plugins=t.plugins.map(e=>typeof e==`function`?`[Plugin Function]`:e&&typeof e==`object`?{name:e.id||e.name||`unknown`,config:i(e.config||e)}:e)),i(t)}async function et(e,t,n=!1){try{let r=console.log,i=console.warn,a=console.error;n&&(console.log=()=>{},console.warn=()=>{},console.error=()=>{});try{let n=await X({cwd:e,...t&&{configPath:t},shouldThrowOnError:!1}),r=await H();return{version:r.dependencies?.[`faire-auth`]||r.devDependencies?.[`faire-auth`]||r.peerDependencies?.[`faire-auth`]||r.optionalDependencies?.[`faire-auth`]||`Unknown`,config:$e(n)}}finally{n&&(console.log=r,console.warn=i,console.error=a)}}catch(e){return{version:`Unknown`,config:null,error:e instanceof Error?e.message:`Failed to load Faire Auth config`}}}function $(e,t=0){let n=` `.repeat(t);if(e==null)return`${n}${d.gray(`N/A`)}`;if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`)return`${n}${e}`;if(Array.isArray(e))return e.length===0?`${n}${d.gray(`[]`)}`:e.map(e=>$(e,t)).join(`
73
+ }`,We={prisma:He,drizzle:ze,kysely:async({options:e,file:t})=>{let{compileMigrations:n}=await M(e),r=await n();return{code:r.trim()===`;`?``:r,fileName:t||`./faire-auth_migrations/${(/* @__PURE__ */ new Date()).toISOString().replace(/:/g,`-`)}.sql`}}},Ge=e=>{let t=e.adapter,n=t.id in We?We[t.id]:null;if(n)return n(e);if(t.createSchema)return t.createSchema(e.options,e.file).then(({code:e,path:t,overwrite:n})=>({code:e,fileName:t,overwrite:n}));E.error(`${t.id} is not supported. If it is a custom adapter, please request the maintainer to implement createSchema`),process.exit(1)};async function Ke(e){let t=S.object({cwd:S.string(),config:S.string().optional(),output:S.string().optional(),y:S.boolean().optional(),yes:S.boolean().optional()}).parse(e),n=_.resolve(t.cwd);m(n)||(E.error(`The directory "${n}" does not exist.`),process.exit(1));let r=await X({cwd:n,...t.config&&{configPath:t.config}});if(!r){E.error("No configuration file found. Add a `auth.ts` file to your project or pass the path to the configuration file using the `--config` flag.");return}let i;try{i=A(r)}catch(e){E.error(e instanceof Error?e.message:`Unknown getAdapter() error`),process.exit(1)}let a=P({text:`preparing schema...`}).start(),o=await Ge({adapter:i,...t.output&&{file:t.output},options:r});if(a.stop(),!o.code){E.info(`Your schema is already up to date.`);try{await w(r).publish({type:`cli_generate`,payload:{outcome:`no_changes`,config:T(r,{adapter:i.id,database:typeof r.database==`function`?`adapter`:`kysely`})}})}catch{}process.exit(0)}if(o.overwrite){let e=t.y||t.yes;if(e||=(await N({type:`confirm`,name:`confirm`,message:`The file ${o.fileName} already exists. Do you want to ${d.yellow(`${o.overwrite?`overwrite`:`append`}`)} the schema to the file?`})).confirm,e){m(_.join(n,o.fileName))||await g.mkdir(_.dirname(_.join(n,o.fileName)),{recursive:!0}),o.overwrite?await g.writeFile(_.join(n,o.fileName),o.code):await g.appendFile(_.join(n,o.fileName),o.code),E.success(`šŸš€ Schema was ${o.overwrite?`overwritten`:`appended`} successfully!`);try{await w(r).publish({type:`cli_generate`,payload:{outcome:o.overwrite?`overwritten`:`appended`,config:T(r)}})}catch{}process.exit(0)}else{E.error(`Schema generation aborted.`);try{await w(r).publish({type:`cli_generate`,payload:{outcome:`aborted`,config:T(r)}})}catch{}process.exit(1)}}t.y&&(console.warn(`WARNING: --y is deprecated. Consider -y or --yes`),t.yes=!0);let s=t.yes;if(s||=(await N({type:`confirm`,name:`confirm`,message:`Do you want to generate the schema to ${d.yellow(o.fileName)}?`})).confirm,!s){E.error(`Schema generation aborted.`);try{await w(r).publish({type:`cli_generate`,payload:{outcome:`aborted`,config:T(r)}})}catch{}process.exit(1)}t.output||m(_.dirname(_.join(n,o.fileName)))||await g.mkdir(_.dirname(_.join(n,o.fileName)),{recursive:!0}),await g.writeFile(t.output||_.join(n,o.fileName),o.code),E.success(`šŸš€ Schema was generated successfully!`);try{await w(r).publish({type:`cli_generate`,payload:{outcome:`generated`,config:T(r)}})}catch{}process.exit(0)}const qe=new e(`generate`).option(`-c, --cwd <cwd>`,`the working directory. defaults to the current directory.`,process.cwd()).option(`--config <config>`,`the path to the configuration file. defaults to the first configuration file found.`).option(`--output <output>`,`the file to output to the generated schema`).option(`-y, --yes`,`automatically answer yes to all prompts`,!1).option(`--y`,`(deprecated) same as --yes`,!1).action(Ke);function Je(){let e=L.platform(),t=L.arch(),n=L.version(),r=L.release(),i=L.cpus(),a=L.totalmem(),o=L.freemem();return{platform:e,arch:t,version:n,release:r,cpuCount:i.length,cpuModel:i[0]?.model||`Unknown`,totalMemory:`${(a/1024/1024/1024).toFixed(2)} GB`,freeMemory:`${(o/1024/1024/1024).toFixed(2)} GB`}}function Ye(){return{version:process.version,env:process.env.NODE_ENV||`development`}}function Xe(){let e=process.env.npm_config_user_agent||``;return e.includes(`yarn`)?{name:`yarn`,version:Q(`yarn`)}:e.includes(`pnpm`)?{name:`pnpm`,version:Q(`pnpm`)}:e.includes(`bun`)?{name:`bun`,version:Q(`bun`)}:{name:`npm`,version:Q(`npm`)}}function Q(e){try{return O(`${e} --version`,{encoding:`utf8`}).trim()}catch{return`Not installed`}}function Ze(e){let t=_.join(e,`package.json`);if(!m(t))return null;try{let e=JSON.parse(h(t,`utf8`)),n={...e.dependencies,...e.devDependencies},r={next:n.next,react:n.react,vue:n.vue,nuxt:n.nuxt,svelte:n.svelte,"@sveltejs/kit":n[`@sveltejs/kit`],express:n.express,fastify:n.fastify,hono:n.hono,remix:n[`@remix-run/react`],astro:n.astro,solid:n[`solid-js`],qwik:n[`@builder.io/qwik`]},i=Object.entries(r).filter(([e,t])=>t).map(([e,t])=>({name:e,version:t}));return i.length>0?i:null}catch{return null}}function Qe(e){let t=_.join(e,`package.json`);if(!m(t))return null;try{let e=JSON.parse(h(t,`utf8`)),n={...e.dependencies,...e.devDependencies},r={"better-sqlite3":n[`better-sqlite3`],"@libsql/client":n[`@libsql/client`],"@libsql/kysely-libsql":n[`@libsql/kysely-libsql`],mysql2:n.mysql2,pg:n.pg,postgres:n.postgres,"@prisma/client":n[`@prisma/client`],drizzle:n[`drizzle-orm`],kysely:n.kysely,mongodb:n.mongodb,"@neondatabase/serverless":n[`@neondatabase/serverless`],"@vercel/postgres":n[`@vercel/postgres`],"@planetscale/database":n[`@planetscale/database`]},i=Object.entries(r).filter(([e,t])=>t).map(([e,t])=>({name:e,version:t}));return i.length>0?i:null}catch{return null}}function $e(e){if(!e)return null;let t=JSON.parse(JSON.stringify(e)),n=[`secret`,`clientSecret`,`clientId`,`authToken`,`apiKey`,`apiSecret`,`privateKey`,`publicKey`,`password`,`token`,`webhook`,`connectionString`,`databaseUrl`,`databaseURL`,`TURSO_AUTH_TOKEN`,`TURSO_DATABASE_URL`,`MYSQL_DATABASE_URL`,`DATABASE_URL`,`POSTGRES_URL`,`MONGODB_URI`,`stripeKey`,`stripeWebhookSecret`],r=[`baseURL`,`callbackURL`,`redirectURL`,`trustedOrigins`,`appName`];function i(e,t){if(typeof e!=`object`||!e){if(t&&typeof e==`string`&&e.length>0){if(r.some(e=>t.toLowerCase()===e.toLowerCase()))return e;let i=t.toLowerCase();if(n.some(e=>{let t=e.toLowerCase();return i===t||i.endsWith(t)}))return`[REDACTED]`}return e}if(Array.isArray(e))return e.map(e=>i(e,t));let a={};for(let[t,o]of Object.entries(e)){if(r.some(e=>t.toLowerCase()===e.toLowerCase())){a[t]=o;continue}let e=t.toLowerCase();a[t]=n.some(t=>{let n=t.toLowerCase();return e===n||e.endsWith(n)})?typeof o==`string`&&o.length>0?`[REDACTED]`:typeof o==`object`&&o?i(o,t):o:i(o,t)}return a}if(t.database&&(typeof t.database==`string`?t.database=`[REDACTED]`:t.database.url&&(t.database.url=`[REDACTED]`),t.database.authToken&&(t.database.authToken=`[REDACTED]`)),t.socialProviders)for(let e in t.socialProviders)t.socialProviders[e]&&(t.socialProviders[e]=i(t.socialProviders[e],e));return t.emailAndPassword?.sendResetPassword&&(t.emailAndPassword.sendResetPassword=`[Function]`),t.emailVerification?.sendVerificationEmail&&(t.emailVerification.sendVerificationEmail=`[Function]`),t.plugins&&Array.isArray(t.plugins)&&(t.plugins=t.plugins.map(e=>typeof e==`function`?`[Plugin Function]`:e&&typeof e==`object`?{name:e.id||e.name||`unknown`,config:i(e.config||e)}:e)),i(t)}async function et(e,t,n=!1){try{let r=console.log,i=console.warn,a=console.error;n&&(console.log=()=>{},console.warn=()=>{},console.error=()=>{});try{let n=await X({cwd:e,...t&&{configPath:t},shouldThrowOnError:!1}),r=await H();return{version:r.dependencies?.[`faire-auth`]||r.devDependencies?.[`faire-auth`]||r.peerDependencies?.[`faire-auth`]||r.optionalDependencies?.[`faire-auth`]||`Unknown`,config:$e(n)}}finally{n&&(console.log=r,console.warn=i,console.error=a)}}catch(e){return{version:`Unknown`,config:null,error:e instanceof Error?e.message:`Failed to load Faire Auth config`}}}function $(e,t=0){let n=` `.repeat(t);if(e==null)return`${n}${d.gray(`N/A`)}`;if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`)return`${n}${e}`;if(Array.isArray(e))return e.length===0?`${n}${d.gray(`[]`)}`:e.map(e=>$(e,t)).join(`
74
74
  `);if(typeof e==`object`){let r=Object.entries(e);return r.length===0?`${n}${d.gray(`{}`)}`:r.map(([e,r])=>typeof r==`object`&&r&&!Array.isArray(r)?`${n}${d.cyan(e)}:\n${$(r,t+2)}`:`${n}${d.cyan(e)}: ${$(r,0)}`).join(`
75
- `)}return`${n}${JSON.stringify(e)}`}const tt=new e(`info`).description(`Display system and Faire Auth configuration information`).option(`--cwd <cwd>`,`The working directory`,process.cwd()).option(`--config <config>`,`Path to the Faire Auth configuration file`).option(`-j, --json`,`Output as JSON`).option(`-c, --copy`,`Copy output to clipboard (requires pbcopy/xclip)`).action(async e=>{let t=v.resolve(e.cwd||process.cwd()),n=Je(),r=Ye(),i=Xe(),a=Ze(t),o=Qe(t),s=await et(t,e.config,e.json),c={system:n,node:r,packageManager:i,frameworks:a,databases:o,faireAuth:s};if(e.json){let t=JSON.stringify(c,null,2);if(console.log(t),e.copy)try{let e=L.platform();e===`darwin`?(O(`pbcopy`,{input:t}),console.log(d.green(`
75
+ `)}return`${n}${JSON.stringify(e)}`}const tt=new e(`info`).description(`Display system and Faire Auth configuration information`).option(`--cwd <cwd>`,`The working directory`,process.cwd()).option(`--config <config>`,`Path to the Faire Auth configuration file`).option(`-j, --json`,`Output as JSON`).option(`-c, --copy`,`Copy output to clipboard (requires pbcopy/xclip)`).action(async e=>{let t=_.resolve(e.cwd||process.cwd()),n=Je(),r=Ye(),i=Xe(),a=Ze(t),o=Qe(t),s=await et(t,e.config,e.json),c={system:n,node:r,packageManager:i,frameworks:a,databases:o,faireAuth:s};if(e.json){let t=JSON.stringify(c,null,2);if(console.log(t),e.copy)try{let e=L.platform();e===`darwin`?(O(`pbcopy`,{input:t}),console.log(d.green(`
76
76
  āœ“ Copied to clipboard`))):e===`linux`?(O(`xclip -selection clipboard`,{input:t}),console.log(d.green(`
77
77
  āœ“ Copied to clipboard`))):e===`win32`&&(O(`clip`,{input:t}),console.log(d.green(`
78
78
  āœ“ Copied to clipboard`)))}catch{console.log(d.yellow(`
79
- ! Could not copy to clipboard`))}return}if(console.log(d.bold(`
79
+ ! Could not copy to clipboard`))}}else if(console.log(d.bold(`
80
80
  šŸ“Š Faire Auth System Information
81
81
  `)),console.log(d.gray(`=`.repeat(50))),console.log(d.bold.white(`
82
82
  šŸ–„ System Information:`)),console.log($(n,2)),console.log(d.bold.white(`
@@ -115,8 +115,8 @@ You can also manually add this configuration to your Cursor MCP settings:`)),con
115
115
  ✨ Next Steps:`)),console.log(d.gray(`• The MCP server will be added to your Cursor configuration`)),console.log(d.gray(`• You can now use Faire Auth features directly in Cursor`))}function it(e){console.log(d.bold.blue(`šŸ¤– Adding Faire Auth MCP to Claude Code...`));let t=`claude mcp add --transport http faire-auth ${e}`;try{O(t,{stdio:`inherit`}),console.log(d.green(`
116
116
  āœ“ Claude Code MCP installed successfully!`))}catch{console.log(d.yellow(`
117
117
  ! Could not automatically add to Claude Code. Please run this command manually:`)),console.log(d.cyan(t))}console.log(d.bold.white(`
118
- ✨ Next Steps:`)),console.log(d.gray(`• The MCP server will be added to your Claude Code configuration`)),console.log(d.gray(`• You can now use Faire Auth features directly in Claude Code`))}function at(e){console.log(d.bold.blue(`šŸ”§ Adding Faire Auth MCP to Open Code...`));let t={$schema:`https://opencode.ai/config.json`,mcp:{"Faire Auth":{type:`remote`,url:e,enabled:!0}}},n=_.join(process.cwd(),`opencode.json`);try{let e={};if(f.existsSync(n)){let t=f.readFileSync(n,`utf8`);e=JSON.parse(t)}let r={...e,...t,mcp:{...e.mcp,...t.mcp}};f.writeFileSync(n,JSON.stringify(r,null,2)),console.log(d.green(`\nāœ“ Open Code configuration written to ${n}`)),console.log(d.green(`āœ“ Faire Auth MCP added successfully!`))}catch{console.log(d.yellow(`
118
+ ✨ Next Steps:`)),console.log(d.gray(`• The MCP server will be added to your Claude Code configuration`)),console.log(d.gray(`• You can now use Faire Auth features directly in Claude Code`))}function at(e){console.log(d.bold.blue(`šŸ”§ Adding Faire Auth MCP to Open Code...`));let t={$schema:`https://opencode.ai/config.json`,mcp:{"Faire Auth":{type:`remote`,url:e,enabled:!0}}},n=v.join(process.cwd(),`opencode.json`);try{let e={};if(f.existsSync(n)){let t=f.readFileSync(n,`utf8`);e=JSON.parse(t)}let r={...e,...t,mcp:{...e.mcp,...t.mcp}};f.writeFileSync(n,JSON.stringify(r,null,2)),console.log(d.green(`\nāœ“ Open Code configuration written to ${n}`)),console.log(d.green(`āœ“ Faire Auth MCP added successfully!`))}catch{console.log(d.yellow(`
119
119
  ! Could not automatically write opencode.json. Please add this configuration manually:`)),console.log(d.cyan(JSON.stringify(t,null,2)))}console.log(d.bold.white(`
120
- ✨ Next Steps:`)),console.log(d.gray(`• Restart Open Code to load the new MCP server`)),console.log(d.gray(`• You can now use Faire Auth features directly in Open Code`))}function ot(e,t){console.log(d.bold.blue(`šŸ“ Adding Faire Auth MCP Configuration...`));let n={[t]:{url:e}},r=_.join(process.cwd(),`mcp.json`);try{let e={};if(f.existsSync(r)){let t=f.readFileSync(r,`utf8`);e=JSON.parse(t)}let t={...e,...n};f.writeFileSync(r,JSON.stringify(t,null,2)),console.log(d.green(`\nāœ“ MCP configuration written to ${r}`)),console.log(d.green(`āœ“ Faire Auth MCP added successfully!`))}catch{console.log(d.yellow(`
120
+ ✨ Next Steps:`)),console.log(d.gray(`• Restart Open Code to load the new MCP server`)),console.log(d.gray(`• You can now use Faire Auth features directly in Open Code`))}function ot(e,t){console.log(d.bold.blue(`šŸ“ Adding Faire Auth MCP Configuration...`));let n={[t]:{url:e}},r=v.join(process.cwd(),`mcp.json`);try{let e={};if(f.existsSync(r)){let t=f.readFileSync(r,`utf8`);e=JSON.parse(t)}let t={...e,...n};f.writeFileSync(r,JSON.stringify(t,null,2)),console.log(d.green(`\nāœ“ MCP configuration written to ${r}`)),console.log(d.green(`āœ“ Faire Auth MCP added successfully!`))}catch{console.log(d.yellow(`
121
121
  ! Could not automatically write mcp.json. Please add this configuration manually:`)),console.log(d.cyan(JSON.stringify(n,null,2)))}console.log(d.bold.white(`
122
122
  ✨ Next Steps:`)),console.log(d.gray(`• Restart your MCP client to load the new server`)),console.log(d.gray(`• You can now use Faire Auth features directly in your MCP client`))}function st(e,t){console.log(d.bold.blue(`šŸ”Œ Faire Auth MCP Server`)),console.log(d.gray(`Choose your MCP client to get started:`)),console.log(),console.log(d.bold.white(`Available Commands:`)),console.log(d.cyan(` --cursor `)+d.gray(`Add to Cursor`)),console.log(d.cyan(` --claude-code `)+d.gray(`Add to Claude Code`)),console.log(d.cyan(` --open-code `)+d.gray(`Add to Open Code`)),console.log(d.cyan(` --manual `)+d.gray(`Manual configuration`)),console.log()}const ct=new e(`mcp`).description(`Add Faire Auth MCP server to MCP Clients`).option(`--cursor`,`Automatically open Cursor with the MCP configuration`).option(`--claude-code`,`Show Claude Code MCP configuration command`).option(`--open-code`,`Show Open Code MCP configuration`).option(`--manual`,`Show manual MCP configuration for mcp.json`).action(nt);process.on(`SIGINT`,()=>process.exit(0)),process.on(`SIGTERM`,()=>process.exit(0));async function lt(){let t=new e(`faire-auth`),n={};try{n=await H()}catch{}t.addCommand(ve).addCommand(Le).addCommand(qe).addCommand(de).addCommand(tt).addCommand(ct).version(n.version||`1.1.2`).description(`Faire Auth CLI`).action(()=>t.help()),t.parse()}lt().catch(e=>{console.error(`Error running Faire Auth CLI:`,e),process.exit(1)});export{};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faire-auth/cli",
3
- "version": "1.0.4",
3
+ "version": "1.1.1",
4
4
  "type": "module",
5
5
  "description": "The CLI for Faire Auth",
6
6
  "repository": {
@@ -12,7 +12,6 @@
12
12
  "main": "./dist/index.mjs",
13
13
  "module": "./dist/index.mjs",
14
14
  "exports": "./dist/index.mjs",
15
- "bin": "./dist/index.mjs",
16
15
  "publishConfig": {
17
16
  "access": "public",
18
17
  "executableFiles": [
@@ -27,12 +26,12 @@
27
26
  "faire-auth"
28
27
  ],
29
28
  "devDependencies": {
30
- "@types/semver": "^7.7.1",
31
- "tsx": "^4.20.5",
32
- "tsdown": "^0.16.0"
29
+ "@types/semver": "^7.8.0",
30
+ "tsx": "^4.23.15",
31
+ "tsdown": "^0.23.7"
33
32
  },
34
33
  "dependencies": {
35
- "@babel/core": "^7.28.4",
34
+ "@babel/core": "^7.29.13",
36
35
  "@babel/preset-react": "^7.27.1",
37
36
  "@babel/preset-typescript": "^7.27.1",
38
37
  "@clack/prompts": "^0.11.0",
@@ -40,24 +39,24 @@
40
39
  "@prisma/client": "^5.22.0",
41
40
  "@types/better-sqlite3": "^7.6.13",
42
41
  "@types/prompts": "^2.4.9",
43
- "better-sqlite3": "^12.2.0",
42
+ "better-sqlite3": "^12.11.1",
44
43
  "c12": "^3.2.0",
45
44
  "chalk": "^5.6.2",
46
45
  "commander": "^12.1.0",
47
46
  "dotenv": "^17.2.2",
48
- "drizzle-orm": "^0.44.7",
49
- "get-tsconfig": "^4.10.1",
50
- "jiti": "^2.6.0",
47
+ "drizzle-orm": "^0.45.4",
48
+ "get-tsconfig": "^4.14.3",
49
+ "jiti": "^2.7.0",
51
50
  "open": "^10.2.0",
52
- "prettier": "^3.6.2",
51
+ "prettier": "^3.9.10",
53
52
  "prisma": "^5.22.0",
54
53
  "prompts": "^2.4.2",
55
- "semver": "^7.7.2",
54
+ "semver": "^7.8.6",
56
55
  "tinyexec": "^0.3.2",
57
56
  "yocto-spinner": "^0.2.3",
58
- "zod": "4.1.4",
59
- "@faire-auth/core": "1.0.4",
60
- "faire-auth": "1.0.4"
57
+ "zod": "^4.6.7",
58
+ "@faire-auth/core": "1.1.1",
59
+ "faire-auth": "1.1.1"
61
60
  },
62
61
  "files": [
63
62
  "dist"
@@ -68,5 +67,8 @@
68
67
  "dev": "tsx ./src/index.ts",
69
68
  "test": "vitest",
70
69
  "typecheck": "tsc --project tsconfig.json"
70
+ },
71
+ "bin": {
72
+ "cli": "./dist/index.mjs"
71
73
  }
72
74
  }