pecunia-root 0.1.2 → 0.1.4

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.
@@ -46,7 +46,7 @@ async function runPluginInit(ctx) {
46
46
  async function createPecuniaContext(adapter, options, getDatabaseType) {
47
47
  const plugins = options.plugins || [];
48
48
  const baseURL = getBaseURL(options.baseURL, options.basePath);
49
- if (!baseURL) console.warn(`[senly] Base URL could not be determined. Please set a valid base URL using the baseURL config option or the BETTER_AUTH_BASE_URL environment variable. Without this, callbacks and redirects may not work correctly.`);
49
+ if (!baseURL) console.warn(`[senly] Base URL could not be determined. Please set a valid base URL using the baseURL config option or the PECUNIA_BASE_URL environment variable. Without this, callbacks and redirects may not work correctly.`);
50
50
  env.BETTER_AUTH_SECRET || env.AUTH_SECRET;
51
51
  options = {
52
52
  ...options,
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../src/context/index.ts"],"sourcesContent":["import type { PecuniaContext, PecuniaOptions, PecuniaPlugin } from \"pecunia-core\";\nimport { getPaymentTables } from \"pecunia-core\";\nimport type { DBAdapter } from \"pecunia-core\";\nimport { createLogger, env, isProduction, isTest } from \"pecunia-core\";\nimport { PecuniaError } from \"pecunia-core\";\nimport defu from \"defu\";\n// import type { Entries } from \"type-fest\";\n// import { checkEndpointConflicts } from \"../api\";\n// import { matchesOriginPattern } from \"../payment/trusted-origins\";\nimport { createInternalAdapter } from \"../adapters/internal\";\nimport { isPromise } from \"../utils/is-promise\";\nimport { getBaseURL } from \"../utils/url\";\nimport { getKyselyDatabaseType } from \"../adapters/kysely-adapter/dialect\";\nimport { getMigrations } from \"../db/migrations\";\nimport { getAdapter } from \"../adapters/get-adapter\";\n\nexport const init = async (options: PecuniaOptions) => {\n\tconst adapter = await getAdapter(options);\n\n\t// Get database type using Kysely's dialect detection\n\tconst getDatabaseType = (database: PecuniaOptions[\"database\"]) =>\n\t\tgetKyselyDatabaseType(database) || \"unknown\";\n\n\t// Use base context creation\n\tconst ctx = await createPecuniaContext(adapter, options, getDatabaseType);\n\n\t// Add runMigrations with Kysely support\n\tctx.runMigrations = async function () {\n\t\t// only run migrations if database is provided and it's not an adapter\n\t\tif (!options.database || \"updateMany\" in options.database) {\n\t\t\tthrow new PecuniaError(\n\t\t\t\t\"Database is not provided or it's an adapter. Migrations are only supported with a database instance.\",\n\t\t\t);\n\t\t}\n\t\tconst { runMigrations } = await getMigrations(options);\n\t\tawait runMigrations();\n\t};\n\n\treturn ctx;\n};\n\n\nexport async function runPluginInit(ctx: PecuniaContext) {\n\tlet options = ctx.options;\n\tconst plugins = options.plugins || [];\n\tlet context: PecuniaContext = ctx;\n\tfor (const plugin of plugins) {\n\t\tif (plugin.init) {\n\t\t\tlet initPromise = plugin.init(context);\n\t\t\tlet result: ReturnType<Required<PecuniaPlugin>[\"init\"]>;\n\t\t\tif (isPromise(initPromise)) {\n\t\t\t\tresult = await initPromise;\n\t\t\t} else {\n\t\t\t\tresult = initPromise;\n\t\t\t}\n\t\t\tif (typeof result === \"object\") {\n\t\t\t\tif (result.options) {\n\t\t\t\t\tconst { ...restOpts } = result.options;\n\t\t\t\t\toptions = defu(options, restOpts);\n\t\t\t\t}\n\t\t\t\tif (result.context) {\n\t\t\t\t\tcontext = {\n\t\t\t\t\t\t...context,\n\t\t\t\t\t\t...(result.context as Partial<PecuniaContext>),\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tcontext.internalAdapter = createInternalAdapter(context.adapter, {\n\t\toptions\n\t});\n\tcontext.options = options;\n\treturn { context };\n}\n\nexport async function createPecuniaContext(\n\tadapter: DBAdapter<PecuniaOptions>,\n\toptions: PecuniaOptions,\n\tgetDatabaseType: (database: PecuniaOptions[\"database\"]) => string,\n): Promise<PecuniaContext> {\n\tconst plugins = options.plugins || [];\n\tconst baseURL = getBaseURL(options.baseURL, options.basePath);\n\n\tif (!baseURL) {\n\t\tconsole.warn(\n\t\t\t`[senly] Base URL could not be determined. Please set a valid base URL using the baseURL config option or the BETTER_AUTH_BASE_URL environment variable. Without this, callbacks and redirects may not work correctly.`,\n\t\t);\n\t}\n\n\tconst secret =\n\t\tenv.BETTER_AUTH_SECRET ||\n\t\tenv.AUTH_SECRET\n\n\toptions = {\n\t\t...options,\n\t\t// secret,\n\t\tbaseURL: baseURL ? new URL(baseURL).origin : \"\",\n\t\tbasePath: options.basePath || \"/api/payment\",\n\t\tplugins\n\t};\n\n\t// checkEndpointConflicts(options);\n\tconst tables = getPaymentTables(options);\n\n\n\tlet ctx: PecuniaContext = {\n\t\tappName: 'Pecunia',\n\t\toptions,\n\t\ttables,\n\t\t// trustedOrigins: await getTrustedOrigins(options),\n\t\t// isTrustedOrigin(\n\t\t// \turl: string,\n\t\t// \tsettings?: {\n\t\t// \t\tallowRelativePaths: boolean;\n\t\t// \t},\n\t\t// ) {\n\t\t// \treturn this.trustedOrigins.some((origin) =>\n\t\t// \t\tmatchesOriginPattern(url, origin, settings),\n\t\t// \t);\n\t\t// },\n\t\tbaseURL: baseURL || \"\",\n\t\t// generateId: generateIdFunc,\n\t\tadapter: adapter,\n\t\tinternalAdapter: createInternalAdapter(adapter, {\n\t\t\toptions\n\t\t}),\n\t\tasync runMigrations() {\n\t\t\tthrow new PecuniaError(\n\t\t\t\t\"runMigrations will be set by the specific init implementation\",\n\t\t\t);\n\t\t},\n\t};\n\n\tconst initOrPromise = runPluginInit(ctx);\n\tlet context: PecuniaContext;\n\tif (isPromise(initOrPromise)) {\n\t\t({ context } = await initOrPromise);\n\t} else {\n\t\t({ context } = initOrPromise);\n\t}\n\n\treturn context;\n}\n"],"mappings":";;;;;;;;;;AAgBA,MAAa,OAAO,OAAO,YAA4B;CACtD,MAAM,UAAU,MAAM,WAAW,QAAQ;CAGzC,MAAM,mBAAmB,aACxB,sBAAsB,SAAS,IAAI;CAGpC,MAAM,MAAM,MAAM,qBAAqB,SAAS,SAAS,gBAAgB;AAGzE,KAAI,gBAAgB,iBAAkB;AAEr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,IAAI;AACJ,KAAI,UAAU,cAAc,CAC3B,EAAC,CAAE,WAAY,MAAM;KAErB,EAAC,CAAE,WAAY;AAGhB,QAAO"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../src/context/index.ts"],"sourcesContent":["import type { PecuniaContext, PecuniaOptions, PecuniaPlugin } from \"pecunia-core\";\nimport { getPaymentTables } from \"pecunia-core\";\nimport type { DBAdapter } from \"pecunia-core\";\nimport { createLogger, env, isProduction, isTest } from \"pecunia-core\";\nimport { PecuniaError } from \"pecunia-core\";\nimport defu from \"defu\";\n// import type { Entries } from \"type-fest\";\n// import { checkEndpointConflicts } from \"../api\";\n// import { matchesOriginPattern } from \"../payment/trusted-origins\";\nimport { createInternalAdapter } from \"../adapters/internal\";\nimport { isPromise } from \"../utils/is-promise\";\nimport { getBaseURL } from \"../utils/url\";\nimport { getKyselyDatabaseType } from \"../adapters/kysely-adapter/dialect\";\nimport { getMigrations } from \"../db/migrations\";\nimport { getAdapter } from \"../adapters/get-adapter\";\n\nexport const init = async (options: PecuniaOptions) => {\n\tconst adapter = await getAdapter(options);\n\n\t// Get database type using Kysely's dialect detection\n\tconst getDatabaseType = (database: PecuniaOptions[\"database\"]) =>\n\t\tgetKyselyDatabaseType(database) || \"unknown\";\n\n\t// Use base context creation\n\tconst ctx = await createPecuniaContext(adapter, options, getDatabaseType);\n\n\t// Add runMigrations with Kysely support\n\tctx.runMigrations = async function () {\n\t\t// only run migrations if database is provided and it's not an adapter\n\t\tif (!options.database || \"updateMany\" in options.database) {\n\t\t\tthrow new PecuniaError(\n\t\t\t\t\"Database is not provided or it's an adapter. Migrations are only supported with a database instance.\",\n\t\t\t);\n\t\t}\n\t\tconst { runMigrations } = await getMigrations(options);\n\t\tawait runMigrations();\n\t};\n\n\treturn ctx;\n};\n\n\nexport async function runPluginInit(ctx: PecuniaContext) {\n\tlet options = ctx.options;\n\tconst plugins = options.plugins || [];\n\tlet context: PecuniaContext = ctx;\n\tfor (const plugin of plugins) {\n\t\tif (plugin.init) {\n\t\t\tlet initPromise = plugin.init(context);\n\t\t\tlet result: ReturnType<Required<PecuniaPlugin>[\"init\"]>;\n\t\t\tif (isPromise(initPromise)) {\n\t\t\t\tresult = await initPromise;\n\t\t\t} else {\n\t\t\t\tresult = initPromise;\n\t\t\t}\n\t\t\tif (typeof result === \"object\") {\n\t\t\t\tif (result.options) {\n\t\t\t\t\tconst { ...restOpts } = result.options;\n\t\t\t\t\toptions = defu(options, restOpts);\n\t\t\t\t}\n\t\t\t\tif (result.context) {\n\t\t\t\t\tcontext = {\n\t\t\t\t\t\t...context,\n\t\t\t\t\t\t...(result.context as Partial<PecuniaContext>),\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tcontext.internalAdapter = createInternalAdapter(context.adapter, {\n\t\toptions\n\t});\n\tcontext.options = options;\n\treturn { context };\n}\n\nexport async function createPecuniaContext(\n\tadapter: DBAdapter<PecuniaOptions>,\n\toptions: PecuniaOptions,\n\tgetDatabaseType: (database: PecuniaOptions[\"database\"]) => string,\n): Promise<PecuniaContext> {\n\tconst plugins = options.plugins || [];\n\tconst baseURL = getBaseURL(options.baseURL, options.basePath);\n\n\tif (!baseURL) {\n\t\tconsole.warn(\n\t\t\t`[senly] Base URL could not be determined. Please set a valid base URL using the baseURL config option or the PECUNIA_BASE_URL environment variable. Without this, callbacks and redirects may not work correctly.`,\n\t\t);\n\t}\n\n\tconst secret =\n\t\tenv.BETTER_AUTH_SECRET ||\n\t\tenv.AUTH_SECRET\n\n\toptions = {\n\t\t...options,\n\t\t// secret,\n\t\tbaseURL: baseURL ? new URL(baseURL).origin : \"\",\n\t\tbasePath: options.basePath || \"/api/payment\",\n\t\tplugins\n\t};\n\n\t// checkEndpointConflicts(options);\n\tconst tables = getPaymentTables(options);\n\n\n\tlet ctx: PecuniaContext = {\n\t\tappName: 'Pecunia',\n\t\toptions,\n\t\ttables,\n\t\t// trustedOrigins: await getTrustedOrigins(options),\n\t\t// isTrustedOrigin(\n\t\t// \turl: string,\n\t\t// \tsettings?: {\n\t\t// \t\tallowRelativePaths: boolean;\n\t\t// \t},\n\t\t// ) {\n\t\t// \treturn this.trustedOrigins.some((origin) =>\n\t\t// \t\tmatchesOriginPattern(url, origin, settings),\n\t\t// \t);\n\t\t// },\n\t\tbaseURL: baseURL || \"\",\n\t\t// generateId: generateIdFunc,\n\t\tadapter: adapter,\n\t\tinternalAdapter: createInternalAdapter(adapter, {\n\t\t\toptions\n\t\t}),\n\t\tasync runMigrations() {\n\t\t\tthrow new PecuniaError(\n\t\t\t\t\"runMigrations will be set by the specific init implementation\",\n\t\t\t);\n\t\t},\n\t};\n\n\tconst initOrPromise = runPluginInit(ctx);\n\tlet context: PecuniaContext;\n\tif (isPromise(initOrPromise)) {\n\t\t({ context } = await initOrPromise);\n\t} else {\n\t\t({ context } = initOrPromise);\n\t}\n\n\treturn context;\n}\n"],"mappings":";;;;;;;;;;AAgBA,MAAa,OAAO,OAAO,YAA4B;CACtD,MAAM,UAAU,MAAM,WAAW,QAAQ;CAGzC,MAAM,mBAAmB,aACxB,sBAAsB,SAAS,IAAI;CAGpC,MAAM,MAAM,MAAM,qBAAqB,SAAS,SAAS,gBAAgB;AAGzE,KAAI,gBAAgB,iBAAkB;AAErC,MAAI,CAAC,QAAQ,YAAY,gBAAgB,QAAQ,SAChD,OAAM,IAAI,aACT,uGACA;EAEF,MAAM,EAAE,kBAAkB,MAAM,cAAc,QAAQ;AACtD,QAAM,eAAe;;AAGtB,QAAO;;AAIR,eAAsB,cAAc,KAAqB;CACxD,IAAI,UAAU,IAAI;CAClB,MAAM,UAAU,QAAQ,WAAW,EAAE;CACrC,IAAI,UAA0B;AAC9B,MAAK,MAAM,UAAU,QACpB,KAAI,OAAO,MAAM;EAChB,IAAI,cAAc,OAAO,KAAK,QAAQ;EACtC,IAAI;AACJ,MAAI,UAAU,YAAY,CACzB,UAAS,MAAM;MAEf,UAAS;AAEV,MAAI,OAAO,WAAW,UAAU;AAC/B,OAAI,OAAO,SAAS;IACnB,MAAM,EAAE,GAAG,aAAa,OAAO;AAC/B,cAAU,KAAK,SAAS,SAAS;;AAElC,OAAI,OAAO,QACV,WAAU;IACT,GAAG;IACH,GAAI,OAAO;IACX;;;AAKL,SAAQ,kBAAkB,sBAAsB,QAAQ,SAAS,EAChE,SACA,CAAC;AACF,SAAQ,UAAU;AAClB,QAAO,EAAE,SAAS;;AAGnB,eAAsB,qBACrB,SACA,SACA,iBAC0B;CAC1B,MAAM,UAAU,QAAQ,WAAW,EAAE;CACrC,MAAM,UAAU,WAAW,QAAQ,SAAS,QAAQ,SAAS;AAE7D,KAAI,CAAC,QACJ,SAAQ,KACP,oNACA;AAID,KAAI,sBACJ,IAAI;AAEL,WAAU;EACT,GAAG;EAEH,SAAS,UAAU,IAAI,IAAI,QAAQ,CAAC,SAAS;EAC7C,UAAU,QAAQ,YAAY;EAC9B;EACA;CAGD,MAAM,SAAS,iBAAiB,QAAQ;CA+BxC,MAAM,gBAAgB,cA5BI;EACzB,SAAS;EACT;EACA;EAYA,SAAS,WAAW;EAEX;EACT,iBAAiB,sBAAsB,SAAS,EAC/C,SACA,CAAC;EACF,MAAM,gBAAgB;AACrB,SAAM,IAAI,aACT,gEACA;;EAEF,CAEuC;CACxC,IAAI;AACJ,KAAI,UAAU,cAAc,CAC3B,EAAC,CAAE,WAAY,MAAM;KAErB,EAAC,CAAE,WAAY;AAGhB,QAAO"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pecunia-root",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -95,7 +95,7 @@
95
95
  "jose": "^6.1.0",
96
96
  "kysely": "^0.28.5",
97
97
  "nanostores": "^1.0.1",
98
- "pecunia-core": "^0.0.4",
98
+ "pecunia-core": "^0.0.6",
99
99
  "zod": "^4.1.12"
100
100
  },
101
101
  "devDependencies": {