@foldspace-fe/casdoor-next-auth-kit 0.1.7 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -1
- package/dist/billing/index.d.ts +9 -4
- package/dist/billing/index.js +11 -4
- package/dist/casdoor/index.js +1 -1
- package/dist/chunk-NGKCQHB3.js +173 -0
- package/dist/chunk-NGKCQHB3.js.map +1 -0
- package/dist/{chunk-RGTVPBH7.js → chunk-O3FKI5NT.js} +13 -8
- package/dist/chunk-O3FKI5NT.js.map +1 -0
- package/dist/{chunk-6E27SZ7V.js → chunk-PFHMT4ZD.js} +42 -1
- package/dist/chunk-PFHMT4ZD.js.map +1 -0
- package/dist/{chunk-DONQHN4U.js → chunk-YXTDGBLC.js} +13 -3
- package/dist/chunk-YXTDGBLC.js.map +1 -0
- package/dist/cli.js +87 -30
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +15 -6
- package/dist/react/index.d.ts +3 -8
- package/dist/react/index.js +6 -11
- package/dist/react/index.js.map +1 -1
- package/dist/skills/casdoor-next-auth-kit/SKILL.md +241 -2
- package/dist/{types-BPsPs5Rv.d.ts → types-DwThfdu-.d.ts} +29 -4
- package/package.json +1 -1
- package/dist/chunk-6E27SZ7V.js.map +0 -1
- package/dist/chunk-DONQHN4U.js.map +0 -1
- package/dist/chunk-RGTVPBH7.js.map +0 -1
- package/dist/chunk-XMBHIEYL.js +0 -1
- package/dist/chunk-XMBHIEYL.js.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -2,8 +2,9 @@ import {
|
|
|
2
2
|
AUTH_KIT_ENV_FILES,
|
|
3
3
|
buildAuthPrismaSchemaTemplate,
|
|
4
4
|
buildManagedEnvTemplate,
|
|
5
|
-
getMissingManagedEnvKeys
|
|
6
|
-
|
|
5
|
+
getMissingManagedEnvKeys,
|
|
6
|
+
readManagedEnvValue
|
|
7
|
+
} from "./chunk-PFHMT4ZD.js";
|
|
7
8
|
|
|
8
9
|
// package.json
|
|
9
10
|
var package_default = {
|
|
@@ -75,8 +76,8 @@ var package_default = {
|
|
|
75
76
|
};
|
|
76
77
|
|
|
77
78
|
// src/cli/operations.ts
|
|
78
|
-
import
|
|
79
|
-
import
|
|
79
|
+
import fs3 from "fs";
|
|
80
|
+
import path3 from "path";
|
|
80
81
|
import { fileURLToPath } from "url";
|
|
81
82
|
|
|
82
83
|
// src/cli/fs.ts
|
|
@@ -117,6 +118,21 @@ function removePath(filePath) {
|
|
|
117
118
|
}
|
|
118
119
|
|
|
119
120
|
// src/cli/templates.ts
|
|
121
|
+
import fs2 from "fs";
|
|
122
|
+
import path2 from "path";
|
|
123
|
+
function getManagedEnvValue(key) {
|
|
124
|
+
for (const file of [".env.local", ".env", ".env.production", ".env.example"]) {
|
|
125
|
+
const filePath = path2.join(process.cwd(), file);
|
|
126
|
+
if (!fs2.existsSync(filePath)) {
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
const value = readManagedEnvValue(fs2.readFileSync(filePath, "utf8"), key);
|
|
130
|
+
if (value !== null) {
|
|
131
|
+
return value;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
120
136
|
function authLoginRouteTemplate() {
|
|
121
137
|
return `import { loginHandler } from '../../auth-config';
|
|
122
138
|
|
|
@@ -166,6 +182,12 @@ export const GET = logoutHandler;
|
|
|
166
182
|
`;
|
|
167
183
|
}
|
|
168
184
|
function authConfigTemplate() {
|
|
185
|
+
const billingPaymentSuccessHandlerImport = getManagedEnvValue("BILLING_PAYMENT_SUCCESS_HANDLER");
|
|
186
|
+
const billingPaymentFinishedHandlerImport = getManagedEnvValue("BILLING_PAYMENT_FINISHED_HANDLER");
|
|
187
|
+
const billingPaymentSuccessHandlerImportLine = billingPaymentSuccessHandlerImport ? `import { paymentSuccessHandler as billingPaymentSuccessHandler } from ${JSON.stringify(billingPaymentSuccessHandlerImport)};
|
|
188
|
+
` : "";
|
|
189
|
+
const billingPaymentFinishedHandlerImportLine = billingPaymentFinishedHandlerImport ? `import { paymentFinishedHandler as billingPaymentFinishedHandler } from ${JSON.stringify(billingPaymentFinishedHandlerImport)};
|
|
190
|
+
` : "";
|
|
169
191
|
return `import {
|
|
170
192
|
createCallbackHandler,
|
|
171
193
|
createCasdoorApiProxyHandler,
|
|
@@ -180,13 +202,13 @@ function authConfigTemplate() {
|
|
|
180
202
|
type AuthPersistenceAdapter,
|
|
181
203
|
type AuthUser,
|
|
182
204
|
} from '@foldspace-fe/casdoor-next-auth-kit';
|
|
183
|
-
import { db } from '@/lib/db';
|
|
205
|
+
${billingPaymentSuccessHandlerImportLine}${billingPaymentFinishedHandlerImportLine}import { db } from '@/lib/db';
|
|
184
206
|
import { isGlobalAdminEmail } from '@/lib/auth-roles';
|
|
185
207
|
import { syncUserRecord } from '@/lib/user-record';
|
|
186
208
|
|
|
187
209
|
export function createAuthKitConfig(): AuthKitConfig {
|
|
188
210
|
return {
|
|
189
|
-
appUrl: process.env.APP_URL ||
|
|
211
|
+
appUrl: process.env.APP_URL || '',
|
|
190
212
|
nextauthSecret: process.env.NEXTAUTH_SECRET || 'dev-nextauth-secret',
|
|
191
213
|
casdoor: {
|
|
192
214
|
serverUrl: process.env.NEXT_PUBLIC_CASDOOR_SERVER_URL || process.env.CASDOOR_SERVER_URL || '',
|
|
@@ -255,6 +277,9 @@ const persistence: AuthPersistenceAdapter = {
|
|
|
255
277
|
},
|
|
256
278
|
};
|
|
257
279
|
|
|
280
|
+
export const paymentSuccessHandler = ${billingPaymentSuccessHandlerImport ? "billingPaymentSuccessHandler" : "undefined"};
|
|
281
|
+
export const paymentFinishedHandler = ${billingPaymentFinishedHandlerImport ? "billingPaymentFinishedHandler" : "undefined"};
|
|
282
|
+
|
|
258
283
|
export const loginHandler = createLoginRouteHandler(authKitConfig);
|
|
259
284
|
export const signupHandler = createSignupRouteHandler(authKitConfig);
|
|
260
285
|
export const authorizeHandler = createAuthorizeRouteHandler(authKitConfig);
|
|
@@ -293,6 +318,34 @@ export const GET = handler;
|
|
|
293
318
|
export const POST = handler;
|
|
294
319
|
`;
|
|
295
320
|
}
|
|
321
|
+
function paymentSuccessRouteTemplate() {
|
|
322
|
+
return `import { createBillingPaymentSuccessRouteHandler } from '@foldspace-fe/casdoor-next-auth-kit';
|
|
323
|
+
import { authKitConfig, paymentSuccessHandler } from '../../../auth-config';
|
|
324
|
+
|
|
325
|
+
export const dynamic = 'force-dynamic';
|
|
326
|
+
export const runtime = 'nodejs';
|
|
327
|
+
|
|
328
|
+
export const GET = createBillingPaymentSuccessRouteHandler({
|
|
329
|
+
appUrl: authKitConfig.appUrl,
|
|
330
|
+
fallbackRedirect: '/auth/payment/finished',
|
|
331
|
+
handler: paymentSuccessHandler,
|
|
332
|
+
});
|
|
333
|
+
`;
|
|
334
|
+
}
|
|
335
|
+
function paymentFinishedRouteTemplate() {
|
|
336
|
+
return `import { createBillingPaymentFinishedRouteHandler } from '@foldspace-fe/casdoor-next-auth-kit';
|
|
337
|
+
import { authKitConfig, paymentFinishedHandler } from '../../../auth-config';
|
|
338
|
+
|
|
339
|
+
export const dynamic = 'force-dynamic';
|
|
340
|
+
export const runtime = 'nodejs';
|
|
341
|
+
|
|
342
|
+
export const GET = createBillingPaymentFinishedRouteHandler({
|
|
343
|
+
appUrl: authKitConfig.appUrl,
|
|
344
|
+
fallbackRedirect: '/',
|
|
345
|
+
handler: paymentFinishedHandler,
|
|
346
|
+
});
|
|
347
|
+
`;
|
|
348
|
+
}
|
|
296
349
|
function authIndexHtmlTemplate() {
|
|
297
350
|
return `export { AUTH_INDEX_HTML, createAuthIndexHtml } from '@foldspace-fe/casdoor-next-auth-kit';
|
|
298
351
|
`;
|
|
@@ -334,10 +387,10 @@ function envTemplate(file, existingContent = "") {
|
|
|
334
387
|
|
|
335
388
|
// src/cli/operations.ts
|
|
336
389
|
var projectRoot = process.cwd();
|
|
337
|
-
var distRoot =
|
|
390
|
+
var distRoot = path3.dirname(fileURLToPath(import.meta.url));
|
|
338
391
|
var canonicalSkillPaths = [
|
|
339
|
-
|
|
340
|
-
|
|
392
|
+
path3.join(distRoot, "skills/casdoor-next-auth-kit"),
|
|
393
|
+
path3.resolve(distRoot, "..", "..", "..", "skills/casdoor-next-auth-kit")
|
|
341
394
|
];
|
|
342
395
|
var skillTarget = ".agents/skills/casdoor-next-auth-kit";
|
|
343
396
|
var targets = [
|
|
@@ -348,6 +401,8 @@ var targets = [
|
|
|
348
401
|
["app/(auth-kit)/signup/oauth/authorize/route.ts", signupAuthorizeRouteTemplate],
|
|
349
402
|
["app/(auth-kit)/auth/api/[...path]/route.ts", apiProxyRouteTemplate],
|
|
350
403
|
["app/(auth-kit)/api/auth/[...nextauth]/route.ts", nextAuthRouteTemplate],
|
|
404
|
+
["app/(auth-kit)/auth/payment/success/route.ts", paymentSuccessRouteTemplate],
|
|
405
|
+
["app/(auth-kit)/auth/payment/finished/route.ts", paymentFinishedRouteTemplate],
|
|
351
406
|
["app/(auth-kit)/callback/route.ts", callbackRouteTemplate],
|
|
352
407
|
["app/(auth-kit)/logout/route.ts", logoutRouteTemplate],
|
|
353
408
|
["app/(auth-kit)/auth/api/commerce/[...path]/route.ts", commerceProxyRouteTemplate],
|
|
@@ -362,6 +417,8 @@ var deprecatedTargets = [
|
|
|
362
417
|
"app/(auth-kit)/login/route.ts",
|
|
363
418
|
"app/(auth-kit)/signup/route.ts",
|
|
364
419
|
"app/(auth-kit)/signup/oauth/authorize/route.ts",
|
|
420
|
+
"app/(auth-kit)/auth/payment-success/route.ts",
|
|
421
|
+
"app/(auth-kit)/auth/payment/finished/page.tsx",
|
|
365
422
|
"app/auth/index-html.ts",
|
|
366
423
|
"app/auth/libs/index.ts",
|
|
367
424
|
"app/auth/libs/auth-config.ts",
|
|
@@ -383,17 +440,17 @@ var deprecatedTargets = [
|
|
|
383
440
|
"lib/auth-redirect.ts"
|
|
384
441
|
];
|
|
385
442
|
function logCreated(filePath) {
|
|
386
|
-
console.log(`+ ${
|
|
443
|
+
console.log(`+ ${path3.relative(projectRoot, filePath)}`);
|
|
387
444
|
}
|
|
388
445
|
function logUpdated(filePath) {
|
|
389
|
-
console.log(`~ ${
|
|
446
|
+
console.log(`~ ${path3.relative(projectRoot, filePath)}`);
|
|
390
447
|
}
|
|
391
448
|
function logRemoved(filePath) {
|
|
392
|
-
console.log(`- ${
|
|
449
|
+
console.log(`- ${path3.relative(projectRoot, filePath)}`);
|
|
393
450
|
}
|
|
394
451
|
function syncManagedEnvFiles() {
|
|
395
452
|
for (const file of AUTH_KIT_ENV_FILES) {
|
|
396
|
-
const filePath =
|
|
453
|
+
const filePath = path3.join(projectRoot, file);
|
|
397
454
|
const existed = exists(filePath);
|
|
398
455
|
const current = existed ? read(filePath) : "";
|
|
399
456
|
const next = envTemplate(file, current);
|
|
@@ -408,25 +465,25 @@ function syncManagedEnvFiles() {
|
|
|
408
465
|
}
|
|
409
466
|
}
|
|
410
467
|
function syncManagedSkillFile() {
|
|
411
|
-
const filePath =
|
|
468
|
+
const filePath = path3.join(projectRoot, skillTarget);
|
|
412
469
|
try {
|
|
413
|
-
const sourcePath = canonicalSkillPaths.find((candidate) =>
|
|
470
|
+
const sourcePath = canonicalSkillPaths.find((candidate) => fs3.existsSync(candidate));
|
|
414
471
|
if (!sourcePath) {
|
|
415
472
|
throw new Error(`Unable to locate canonical skill directory. Checked: ${canonicalSkillPaths.join(", ")}`);
|
|
416
473
|
}
|
|
417
474
|
removePath(filePath);
|
|
418
|
-
|
|
475
|
+
fs3.mkdirSync(filePath, { recursive: true });
|
|
419
476
|
logCreated(filePath);
|
|
420
|
-
for (const entry of
|
|
421
|
-
const sourceEntry =
|
|
422
|
-
const targetEntry =
|
|
477
|
+
for (const entry of fs3.readdirSync(sourcePath, { withFileTypes: true })) {
|
|
478
|
+
const sourceEntry = path3.join(sourcePath, entry.name);
|
|
479
|
+
const targetEntry = path3.join(filePath, entry.name);
|
|
423
480
|
if (entry.isDirectory()) {
|
|
424
|
-
|
|
425
|
-
console.log(`+ ${
|
|
481
|
+
fs3.cpSync(sourceEntry, targetEntry, { recursive: true });
|
|
482
|
+
console.log(`+ ${path3.relative(projectRoot, targetEntry)}/`);
|
|
426
483
|
continue;
|
|
427
484
|
}
|
|
428
|
-
|
|
429
|
-
console.log(`+ ${
|
|
485
|
+
fs3.copyFileSync(sourceEntry, targetEntry);
|
|
486
|
+
console.log(`+ ${path3.relative(projectRoot, targetEntry)}`);
|
|
430
487
|
}
|
|
431
488
|
} catch (error) {
|
|
432
489
|
console.warn(`Skipped skill sync for ${skillTarget}: ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -434,7 +491,7 @@ function syncManagedSkillFile() {
|
|
|
434
491
|
}
|
|
435
492
|
async function initProject() {
|
|
436
493
|
for (const [rel, factory] of targets) {
|
|
437
|
-
const filePath =
|
|
494
|
+
const filePath = path3.join(projectRoot, rel);
|
|
438
495
|
if (!exists(filePath)) {
|
|
439
496
|
writeGeneratedFile(filePath, factory());
|
|
440
497
|
logCreated(filePath);
|
|
@@ -446,14 +503,14 @@ async function initProject() {
|
|
|
446
503
|
}
|
|
447
504
|
async function updateProject() {
|
|
448
505
|
for (const rel of deprecatedTargets) {
|
|
449
|
-
const filePath =
|
|
506
|
+
const filePath = path3.join(projectRoot, rel);
|
|
450
507
|
if (exists(filePath)) {
|
|
451
508
|
removePath(filePath);
|
|
452
509
|
logRemoved(filePath);
|
|
453
510
|
}
|
|
454
511
|
}
|
|
455
512
|
for (const [rel, factory] of targets) {
|
|
456
|
-
const filePath =
|
|
513
|
+
const filePath = path3.join(projectRoot, rel);
|
|
457
514
|
const next = "// generated by @foldspace-fe/casdoor-next-auth-kit\n" + factory();
|
|
458
515
|
if (!exists(filePath)) {
|
|
459
516
|
writeGeneratedFile(filePath, factory());
|
|
@@ -472,16 +529,16 @@ async function updateProject() {
|
|
|
472
529
|
console.log("Updated managed route shells, env files, and skill file.");
|
|
473
530
|
}
|
|
474
531
|
async function checkProject() {
|
|
475
|
-
const missingRoutes = targets.filter(([rel]) => !exists(
|
|
532
|
+
const missingRoutes = targets.filter(([rel]) => !exists(path3.join(projectRoot, rel))).map(([rel]) => rel);
|
|
476
533
|
const missingEnv = AUTH_KIT_ENV_FILES.filter((file) => {
|
|
477
|
-
const filePath =
|
|
534
|
+
const filePath = path3.join(projectRoot, file);
|
|
478
535
|
if (!exists(filePath)) {
|
|
479
536
|
return true;
|
|
480
537
|
}
|
|
481
538
|
return getMissingManagedEnvKeys(read(filePath)).length > 0;
|
|
482
539
|
});
|
|
483
|
-
const skillDir =
|
|
484
|
-
const missingSkill = exists(
|
|
540
|
+
const skillDir = path3.join(projectRoot, skillTarget);
|
|
541
|
+
const missingSkill = exists(path3.join(skillDir, "SKILL.md")) ? [] : [path3.join(skillTarget, "SKILL.md")];
|
|
485
542
|
const missing = [...missingRoutes, ...missingEnv, ...missingSkill];
|
|
486
543
|
if (missing.length > 0) {
|
|
487
544
|
console.error("Missing generated files:");
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../package.json","../src/cli/operations.ts","../src/cli/fs.ts","../src/cli/templates.ts","../src/cli/index.ts","../src/cli.ts"],"sourcesContent":["{\n \"name\": \"@foldspace-fe/casdoor-next-auth-kit\",\n \"version\": \"0.1.0\",\n \"private\": false,\n \"type\": \"module\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/foldspace-stack/casdoor-next-auth-kit\"\n },\n \"homepage\": \"https://github.com/foldspace-stack/casdoor-next-auth-kit#readme\",\n \"bugs\": {\n \"url\": \"https://github.com/foldspace-stack/casdoor-next-auth-kit/issues\"\n },\n \"main\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"default\": \"./dist/index.js\"\n },\n \"./casdoor\": {\n \"types\": \"./dist/casdoor/index.d.ts\",\n \"default\": \"./dist/casdoor/index.js\"\n },\n \"./next\": {\n \"types\": \"./dist/next/index.d.ts\",\n \"default\": \"./dist/next/index.js\"\n },\n \"./billing\": {\n \"types\": \"./dist/billing/index.d.ts\",\n \"default\": \"./dist/billing/index.js\"\n },\n \"./react\": {\n \"types\": \"./dist/react/index.d.ts\",\n \"default\": \"./dist/react/index.js\"\n }\n },\n \"bin\": {\n \"casdoor-next-auth-kit\": \"./dist/cli.js\"\n },\n \"publishConfig\": {\n \"access\": \"public\",\n \"provenance\": true\n },\n \"files\": [\"dist\", \"README.md\"],\n \"scripts\": {\n \"build\": \"tsup && node ./scripts/copy-skill.mjs\",\n \"typecheck\": \"tsc -p tsconfig.json --noEmit\",\n \"dev\": \"tsup --watch\"\n },\n \"peerDependencies\": {\n \"next\": \">=16\",\n \"next-auth\": \"^4.24.0\",\n \"react\": \">=19\",\n \"react-dom\": \">=19\"\n },\n \"dependencies\": {\n \"jose\": \"^6.1.0\"\n },\n \"devDependencies\": {\n \"@types/node\": \"^22.15.0\",\n \"@types/react\": \"^19.2.0\",\n \"@types/react-dom\": \"^19.2.0\",\n \"tsup\": \"^8.5.0\",\n \"typescript\": \"^5.6.3\"\n }\n}\n","import fs from 'node:fs';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nimport { AUTH_KIT_ENV_FILES, getMissingManagedEnvKeys } from '../core/env';\nimport { exists, preserveCustomBlock, read, removePath, writeGeneratedFile, writeTextFile } from './fs';\nimport {\n apiProxyRouteTemplate,\n authConfigTemplate,\n authIndexHtmlTemplate,\n authLoginRouteTemplate,\n authSignupRouteTemplate,\n authorizeRouteTemplate,\n callbackRouteTemplate,\n commerceProxyRouteTemplate,\n envTemplate,\n logoutRouteTemplate,\n nextAuthRouteTemplate,\n prismaSchemaTemplate,\n signupAuthorizeRouteTemplate,\n} from './templates';\n\nconst projectRoot = process.cwd();\nconst distRoot = path.dirname(fileURLToPath(import.meta.url));\nconst canonicalSkillPaths = [\n path.join(distRoot, 'skills/casdoor-next-auth-kit'),\n path.resolve(distRoot, '..', '..', '..', 'skills/casdoor-next-auth-kit'),\n];\nconst skillTarget = '.agents/skills/casdoor-next-auth-kit';\n\nconst targets = [\n ['app/(auth-kit)/auth-config.ts', authConfigTemplate],\n ['app/(auth-kit)/auth/login/route.ts', authLoginRouteTemplate],\n ['app/(auth-kit)/auth/signup/route.ts', authSignupRouteTemplate],\n ['app/(auth-kit)/login/oauth/authorize/route.ts', authorizeRouteTemplate],\n ['app/(auth-kit)/signup/oauth/authorize/route.ts', signupAuthorizeRouteTemplate],\n ['app/(auth-kit)/auth/api/[...path]/route.ts', apiProxyRouteTemplate],\n ['app/(auth-kit)/api/auth/[...nextauth]/route.ts', nextAuthRouteTemplate],\n ['app/(auth-kit)/callback/route.ts', callbackRouteTemplate],\n ['app/(auth-kit)/logout/route.ts', logoutRouteTemplate],\n ['app/(auth-kit)/auth/api/commerce/[...path]/route.ts', commerceProxyRouteTemplate],\n ['app/(auth-kit)/index-html.ts', authIndexHtmlTemplate],\n ['prisma/auth-kit.prisma', prismaSchemaTemplate],\n] as const;\n\nconst deprecatedTargets = [\n 'app/(auth-kit)/api/casdoor/[...path]/route.ts',\n 'app/(auth-kit)/api/casdoor/commerce/[...path]/route.ts',\n 'app/(auth-kit)/auth/api/casdoor/[...path]/route.ts',\n 'app/(auth-kit)/auth/api/casdoor/commerce/[...path]/route.ts',\n 'app/(auth-kit)/login/route.ts',\n 'app/(auth-kit)/signup/route.ts',\n 'app/(auth-kit)/signup/oauth/authorize/route.ts',\n 'app/auth/index-html.ts',\n 'app/auth/libs/index.ts',\n 'app/auth/libs/auth-config.ts',\n 'app/auth/libs/casdoor-config.ts',\n 'app/auth/libs/session-token.ts',\n 'app/auth/libs/oauth-state.ts',\n 'app/auth/libs/page-proxy.ts',\n 'app/auth/libs/api-proxy.ts',\n 'app/auth/libs/casdoor-oauth.ts',\n 'app/auth/libs/nextauth-route.ts',\n 'app/auth/libs',\n 'lib/auth-kit/index.ts',\n 'lib/auth-kit/index-html.ts',\n 'lib/auth-kit',\n 'lib/casdoor-entry.ts',\n 'lib/auth.ts',\n 'lib/public-origin.ts',\n 'lib/request-security.ts',\n 'lib/auth-redirect.ts',\n] as const;\n\nfunction logCreated(filePath: string) {\n console.log(`+ ${path.relative(projectRoot, filePath)}`);\n}\n\nfunction logUpdated(filePath: string) {\n console.log(`~ ${path.relative(projectRoot, filePath)}`);\n}\n\nfunction logRemoved(filePath: string) {\n console.log(`- ${path.relative(projectRoot, filePath)}`);\n}\n\nfunction syncManagedEnvFiles() {\n for (const file of AUTH_KIT_ENV_FILES) {\n const filePath = path.join(projectRoot, file);\n const existed = exists(filePath);\n const current = existed ? read(filePath) : '';\n const next = envTemplate(file, current);\n if (!existed || current !== next) {\n writeTextFile(filePath, next);\n if (!existed) {\n logCreated(filePath);\n } else {\n logUpdated(filePath);\n }\n }\n }\n}\n\nfunction syncManagedSkillFile() {\n const filePath = path.join(projectRoot, skillTarget);\n try {\n const sourcePath = canonicalSkillPaths.find((candidate) => fs.existsSync(candidate));\n if (!sourcePath) {\n throw new Error(`Unable to locate canonical skill directory. Checked: ${canonicalSkillPaths.join(', ')}`);\n }\n removePath(filePath);\n fs.mkdirSync(filePath, { recursive: true });\n logCreated(filePath);\n for (const entry of fs.readdirSync(sourcePath, { withFileTypes: true })) {\n const sourceEntry = path.join(sourcePath, entry.name);\n const targetEntry = path.join(filePath, entry.name);\n if (entry.isDirectory()) {\n fs.cpSync(sourceEntry, targetEntry, { recursive: true });\n console.log(`+ ${path.relative(projectRoot, targetEntry)}/`);\n continue;\n }\n fs.copyFileSync(sourceEntry, targetEntry);\n console.log(`+ ${path.relative(projectRoot, targetEntry)}`);\n }\n } catch (error) {\n console.warn(`Skipped skill sync for ${skillTarget}: ${error instanceof Error ? error.message : String(error)}`);\n }\n}\n\nexport async function initProject() {\n for (const [rel, factory] of targets) {\n const filePath = path.join(projectRoot, rel);\n if (!exists(filePath)) {\n writeGeneratedFile(filePath, factory());\n logCreated(filePath);\n }\n }\n\n syncManagedEnvFiles();\n syncManagedSkillFile();\n console.log('Initialized casdoor-next-auth-kit managed files.');\n}\n\nexport async function updateProject() {\n for (const rel of deprecatedTargets) {\n const filePath = path.join(projectRoot, rel);\n if (exists(filePath)) {\n removePath(filePath);\n logRemoved(filePath);\n }\n }\n\n for (const [rel, factory] of targets) {\n const filePath = path.join(projectRoot, rel);\n const next = '// generated by @foldspace-fe/casdoor-next-auth-kit\\n' + factory();\n if (!exists(filePath)) {\n writeGeneratedFile(filePath, factory());\n logCreated(filePath);\n continue;\n }\n\n const current = read(filePath);\n const updated = preserveCustomBlock(current, next);\n if (current !== updated) {\n writeTextFile(filePath, updated);\n logUpdated(filePath);\n }\n }\n\n syncManagedEnvFiles();\n syncManagedSkillFile();\n console.log('Updated managed route shells, env files, and skill file.');\n}\n\nexport async function checkProject() {\n const missingRoutes = targets.filter(([rel]) => !exists(path.join(projectRoot, rel))).map(([rel]) => rel);\n const missingEnv = AUTH_KIT_ENV_FILES.filter((file) => {\n const filePath = path.join(projectRoot, file);\n if (!exists(filePath)) {\n return true;\n }\n return getMissingManagedEnvKeys(read(filePath)).length > 0;\n });\n const skillDir = path.join(projectRoot, skillTarget);\n const missingSkill = exists(path.join(skillDir, 'SKILL.md')) ? [] : [path.join(skillTarget, 'SKILL.md')];\n const missing = [...missingRoutes, ...missingEnv, ...missingSkill];\n\n if (missing.length > 0) {\n console.error('Missing generated files:');\n for (const rel of missing) {\n console.error('- ' + rel);\n }\n process.exitCode = 1;\n return;\n }\n\n console.log('All managed files are present.');\n}\n"," import fs from 'node:fs';\n import path from 'node:path';\n\n export const generatedHeader = '// generated by @foldspace-fe/casdoor-next-auth-kit\\n';\n export const customBegin = '// @foldspace-fe/casdoor-next-auth-kit:begin custom';\n export const customEnd = '// @foldspace-fe/casdoor-next-auth-kit:end custom';\n\nexport function ensureDir(filePath: string) {\n fs.mkdirSync(path.dirname(filePath), { recursive: true });\n}\n\nexport function writeGeneratedFile(filePath: string, content: string) {\n ensureDir(filePath);\n fs.writeFileSync(filePath, generatedHeader + content, 'utf8');\n}\n\nexport function writeTextFile(filePath: string, content: string) {\n ensureDir(filePath);\n fs.writeFileSync(filePath, content, 'utf8');\n}\n\nexport function exists(filePath: string) {\n return fs.existsSync(filePath);\n}\n\n export function read(filePath: string) {\n return fs.readFileSync(filePath, 'utf8');\n }\n\nexport function preserveCustomBlock(existing: string, next: string) {\n const begin = existing.indexOf(customBegin);\n const end = existing.indexOf(customEnd);\n if (begin === -1 || end === -1 || end <= begin) return next;\n const custom = existing.slice(begin, end + customEnd.length);\n const targetBegin = next.indexOf(customBegin);\n const targetEnd = next.indexOf(customEnd);\n if (targetBegin === -1 || targetEnd === -1 || targetEnd <= targetBegin) return next;\n return next.slice(0, targetBegin) + custom + next.slice(targetEnd + customEnd.length);\n}\n\nexport function removePath(filePath: string) {\n fs.rmSync(filePath, { force: true, recursive: true });\n}\n"," import { customBegin, customEnd } from './fs';\n import { buildAuthPrismaSchemaTemplate } from '../prisma/schema-template';\n import { AUTH_KIT_ENV_FILES, buildManagedEnvTemplate } from '../core/env';\n\nexport function authLoginRouteTemplate() {\n return `import { loginHandler } from '../../auth-config';\n\nexport const dynamic = 'force-dynamic';\n\nexport const GET = loginHandler;\n`;\n}\n\nexport function authSignupRouteTemplate() {\n return `import { signupHandler } from '../../auth-config';\n\nexport const dynamic = 'force-dynamic';\n\nexport const GET = signupHandler;\n`;\n}\n\nexport function authorizeRouteTemplate() {\n return `import { authorizeHandler } from '../../../auth-config';\n\nexport const dynamic = 'force-dynamic';\n\nexport const GET = authorizeHandler;\n`;\n}\n\nexport function signupAuthorizeRouteTemplate() {\n return `import { authorizeHandler } from '../../../auth-config';\n\nexport const dynamic = 'force-dynamic';\n\nexport const GET = authorizeHandler;\n`;\n}\n\nexport function callbackRouteTemplate() {\n return `import { callbackHandler } from '../auth-config';\n\nexport const dynamic = 'force-dynamic';\n\nexport const GET = callbackHandler;\n`;\n}\n\nexport function logoutRouteTemplate() {\n return `import { logoutHandler } from '../auth-config';\n\nexport const dynamic = 'force-dynamic';\n\nexport const GET = logoutHandler;\n`;\n}\n\nexport function authConfigTemplate() {\n return `import {\n createCallbackHandler,\n createCasdoorApiProxyHandler,\n createCasdoorCommerceProxyHandler,\n createAuthorizeRouteHandler,\n createLoginRouteHandler,\n createLogoutHandler,\n createNextAuthOptions,\n createSignupRouteHandler,\n type AuthBusinessAdapter,\n type AuthKitConfig,\n type AuthPersistenceAdapter,\n type AuthUser,\n} from '@foldspace-fe/casdoor-next-auth-kit';\nimport { db } from '@/lib/db';\nimport { isGlobalAdminEmail } from '@/lib/auth-roles';\nimport { syncUserRecord } from '@/lib/user-record';\n\nexport function createAuthKitConfig(): AuthKitConfig {\n return {\n appUrl: process.env.APP_URL || process.env.NEXTAUTH_URL || '',\n nextauthSecret: process.env.NEXTAUTH_SECRET || 'dev-nextauth-secret',\n casdoor: {\n serverUrl: process.env.NEXT_PUBLIC_CASDOOR_SERVER_URL || process.env.CASDOOR_SERVER_URL || '',\n clientId: process.env.NEXT_PUBLIC_CASDOOR_CLIENT_ID || process.env.CASDOOR_CLIENT_ID || '',\n clientSecret: process.env.CASDOOR_CLIENT_SECRET || '',\n appName: process.env.NEXT_PUBLIC_CASDOOR_APP_NAME || '',\n organizationName: process.env.NEXT_PUBLIC_CASDOOR_ORGANIZATION_NAME || '',\n redirectPath: process.env.NEXT_PUBLIC_CASDOOR_REDIRECT_PATH || '/callback',\n signinPath: process.env.NEXT_PUBLIC_CASDOOR_SIGNIN_PATH || '/login/oauth/authorize',\n },\n };\n}\n\nconst authKitConfig = createAuthKitConfig();\n\nconst adapter: AuthBusinessAdapter = {\n isAdminEmail: isGlobalAdminEmail,\n};\n\nconst persistence: AuthPersistenceAdapter = {\n async syncAuthUser(user) {\n await syncUserRecord(user);\n },\n async findAuthUser({ id, email }) {\n const user = id\n ? await db.user.findUnique({\n where: { id },\n select: {\n id: true,\n name: true,\n email: true,\n image: true,\n tokenBalance: true,\n isVip: true,\n isAdmin: true,\n },\n })\n : email\n ? await db.user.findFirst({\n where: { email },\n select: {\n id: true,\n name: true,\n email: true,\n image: true,\n tokenBalance: true,\n isVip: true,\n isAdmin: true,\n },\n })\n : null;\n\n if (!user) {\n return null;\n }\n\n return {\n id: user.id,\n name: user.name,\n email: user.email,\n image: user.image,\n tokenBalance: Number(user.tokenBalance ?? 2580),\n isVip: Boolean(user.isVip ?? true),\n isAdmin: Boolean(user.isAdmin) || isGlobalAdminEmail(user.email),\n } satisfies AuthUser;\n },\n};\n\nexport const loginHandler = createLoginRouteHandler(authKitConfig);\nexport const signupHandler = createSignupRouteHandler(authKitConfig);\nexport const authorizeHandler = createAuthorizeRouteHandler(authKitConfig);\nexport const callbackHandler = createCallbackHandler({\n config: authKitConfig,\n adapter,\n persistence,\n});\nexport const logoutHandler = createLogoutHandler(authKitConfig);\nexport const authOptions = createNextAuthOptions({\n config: authKitConfig,\n adapter,\n persistence,\n});\nexport const apiProxyHandler = createCasdoorApiProxyHandler(authKitConfig, '/auth/api', '/api');\nexport const commerceProxyHandler = createCasdoorCommerceProxyHandler(authKitConfig, '/auth/api/commerce', '/api/commerce');\n`;\n}\n\nexport function nextAuthRouteTemplate() {\n return `import NextAuth from 'next-auth';\nimport { createNextAuthOptions } from '@foldspace-fe/casdoor-next-auth-kit';\nimport { adapter, authKitConfig, persistence } from '../../../auth-config';\n\nexport const dynamic = 'force-dynamic';\nexport const runtime = 'nodejs';\n\nconst handler = NextAuth(\n createNextAuthOptions({\n config: authKitConfig,\n adapter,\n persistence,\n }),\n);\n\nexport const GET = handler;\nexport const POST = handler;\n`;\n}\n\n export function authIndexHtmlTemplate() {\n return `export { AUTH_INDEX_HTML, createAuthIndexHtml } from '@foldspace-fe/casdoor-next-auth-kit';\n`;\n }\n\n export function prismaSchemaTemplate() {\n return buildAuthPrismaSchemaTemplate();\n }\n\nexport function apiProxyRouteTemplate() {\n return `import { apiProxyHandler } from '../../../auth-config';\n\nexport const dynamic = 'force-dynamic';\n\nexport const GET = apiProxyHandler;\nexport const HEAD = apiProxyHandler;\nexport const POST = apiProxyHandler;\nexport const PUT = apiProxyHandler;\nexport const PATCH = apiProxyHandler;\nexport const DELETE = apiProxyHandler;\nexport const OPTIONS = apiProxyHandler;\n`;\n}\n\nexport function commerceProxyRouteTemplate() {\n return `import { commerceProxyHandler } from '../../../../auth-config';\n\nexport const dynamic = 'force-dynamic';\n\nexport const GET = commerceProxyHandler;\nexport const HEAD = commerceProxyHandler;\nexport const POST = commerceProxyHandler;\nexport const PUT = commerceProxyHandler;\nexport const PATCH = commerceProxyHandler;\nexport const DELETE = commerceProxyHandler;\nexport const OPTIONS = commerceProxyHandler;\n`;\n}\n\n export function envTemplate(file: typeof AUTH_KIT_ENV_FILES[number], existingContent = '') {\n return buildManagedEnvTemplate(file, existingContent);\n }\n","import packageJson from '../../package.json';\n\nimport { initProject, checkProject, updateProject } from './operations';\n\nfunction printUsage() {\n console.log('Usage: npx @foldspace-fe/casdoor-next-auth-kit@latest <init|update|check>');\n console.log(' npx @foldspace-fe/casdoor-next-auth-kit@latest --help');\n console.log(' npx @foldspace-fe/casdoor-next-auth-kit@latest --version');\n}\n\nexport async function runCli(argv: string[]) {\n const command = argv[0] ?? 'help';\n if (command === '--help' || command === '-h' || command === 'help') {\n printUsage();\n return;\n }\n if (command === '--version' || command === '-v') {\n console.log(packageJson.version);\n return;\n }\n if (command === 'init') return initProject();\n if (command === 'update') return updateProject();\n if (command === 'check') return checkProject();\n printUsage();\n}\n","import { runCli } from './cli/index';\n\nrunCli(process.argv.slice(2)).catch((error) => {\n console.error(error instanceof Error ? error.message : error);\n process.exit(1);\n});\n"],"mappings":";;;;;;;;AAAA;AAAA,EACE,MAAQ;AAAA,EACR,SAAW;AAAA,EACX,SAAW;AAAA,EACX,MAAQ;AAAA,EACR,YAAc;AAAA,IACZ,MAAQ;AAAA,IACR,KAAO;AAAA,EACT;AAAA,EACA,UAAY;AAAA,EACZ,MAAQ;AAAA,IACN,KAAO;AAAA,EACT;AAAA,EACA,MAAQ;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/cli/templates.ts","../src/cli/index.ts","../src/cli.ts"],"sourcesContent":["{\n \"name\": \"@foldspace-fe/casdoor-next-auth-kit\",\n \"version\": \"0.1.0\",\n \"private\": false,\n \"type\": \"module\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/foldspace-stack/casdoor-next-auth-kit\"\n },\n \"homepage\": \"https://github.com/foldspace-stack/casdoor-next-auth-kit#readme\",\n \"bugs\": {\n \"url\": \"https://github.com/foldspace-stack/casdoor-next-auth-kit/issues\"\n },\n \"main\": \"./dist/index.js\",\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"default\": \"./dist/index.js\"\n },\n \"./casdoor\": {\n \"types\": \"./dist/casdoor/index.d.ts\",\n \"default\": \"./dist/casdoor/index.js\"\n },\n \"./next\": {\n \"types\": \"./dist/next/index.d.ts\",\n \"default\": \"./dist/next/index.js\"\n },\n \"./billing\": {\n \"types\": \"./dist/billing/index.d.ts\",\n \"default\": \"./dist/billing/index.js\"\n },\n \"./react\": {\n \"types\": \"./dist/react/index.d.ts\",\n \"default\": \"./dist/react/index.js\"\n }\n },\n \"bin\": {\n \"casdoor-next-auth-kit\": \"./dist/cli.js\"\n },\n \"publishConfig\": {\n \"access\": \"public\",\n \"provenance\": true\n },\n \"files\": [\"dist\", \"README.md\"],\n \"scripts\": {\n \"build\": \"tsup && node ./scripts/copy-skill.mjs\",\n \"typecheck\": \"tsc -p tsconfig.json --noEmit\",\n \"dev\": \"tsup --watch\"\n },\n \"peerDependencies\": {\n \"next\": \">=16\",\n \"next-auth\": \"^4.24.0\",\n \"react\": \">=19\",\n \"react-dom\": \">=19\"\n },\n \"dependencies\": {\n \"jose\": \"^6.1.0\"\n },\n \"devDependencies\": {\n \"@types/node\": \"^22.15.0\",\n \"@types/react\": \"^19.2.0\",\n \"@types/react-dom\": \"^19.2.0\",\n \"tsup\": \"^8.5.0\",\n \"typescript\": \"^5.6.3\"\n }\n}\n","import fs from 'node:fs';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\n\nimport { AUTH_KIT_ENV_FILES, getMissingManagedEnvKeys } from '../core/env';\nimport { exists, preserveCustomBlock, read, removePath, writeGeneratedFile, writeTextFile } from './fs';\nimport {\n apiProxyRouteTemplate,\n authConfigTemplate,\n authIndexHtmlTemplate,\n authLoginRouteTemplate,\n authSignupRouteTemplate,\n authorizeRouteTemplate,\n callbackRouteTemplate,\n commerceProxyRouteTemplate,\n envTemplate,\n logoutRouteTemplate,\n nextAuthRouteTemplate,\n paymentFinishedRouteTemplate,\n paymentSuccessRouteTemplate,\n prismaSchemaTemplate,\n signupAuthorizeRouteTemplate,\n} from './templates';\n\nconst projectRoot = process.cwd();\nconst distRoot = path.dirname(fileURLToPath(import.meta.url));\nconst canonicalSkillPaths = [\n path.join(distRoot, 'skills/casdoor-next-auth-kit'),\n path.resolve(distRoot, '..', '..', '..', 'skills/casdoor-next-auth-kit'),\n];\nconst skillTarget = '.agents/skills/casdoor-next-auth-kit';\n\nconst targets = [\n ['app/(auth-kit)/auth-config.ts', authConfigTemplate],\n ['app/(auth-kit)/auth/login/route.ts', authLoginRouteTemplate],\n ['app/(auth-kit)/auth/signup/route.ts', authSignupRouteTemplate],\n ['app/(auth-kit)/login/oauth/authorize/route.ts', authorizeRouteTemplate],\n ['app/(auth-kit)/signup/oauth/authorize/route.ts', signupAuthorizeRouteTemplate],\n ['app/(auth-kit)/auth/api/[...path]/route.ts', apiProxyRouteTemplate],\n ['app/(auth-kit)/api/auth/[...nextauth]/route.ts', nextAuthRouteTemplate],\n ['app/(auth-kit)/auth/payment/success/route.ts', paymentSuccessRouteTemplate],\n ['app/(auth-kit)/auth/payment/finished/route.ts', paymentFinishedRouteTemplate],\n ['app/(auth-kit)/callback/route.ts', callbackRouteTemplate],\n ['app/(auth-kit)/logout/route.ts', logoutRouteTemplate],\n ['app/(auth-kit)/auth/api/commerce/[...path]/route.ts', commerceProxyRouteTemplate],\n ['app/(auth-kit)/index-html.ts', authIndexHtmlTemplate],\n ['prisma/auth-kit.prisma', prismaSchemaTemplate],\n] as const;\n\nconst deprecatedTargets = [\n 'app/(auth-kit)/api/casdoor/[...path]/route.ts',\n 'app/(auth-kit)/api/casdoor/commerce/[...path]/route.ts',\n 'app/(auth-kit)/auth/api/casdoor/[...path]/route.ts',\n 'app/(auth-kit)/auth/api/casdoor/commerce/[...path]/route.ts',\n 'app/(auth-kit)/login/route.ts',\n 'app/(auth-kit)/signup/route.ts',\n 'app/(auth-kit)/signup/oauth/authorize/route.ts',\n 'app/(auth-kit)/auth/payment-success/route.ts',\n 'app/(auth-kit)/auth/payment/finished/page.tsx',\n 'app/auth/index-html.ts',\n 'app/auth/libs/index.ts',\n 'app/auth/libs/auth-config.ts',\n 'app/auth/libs/casdoor-config.ts',\n 'app/auth/libs/session-token.ts',\n 'app/auth/libs/oauth-state.ts',\n 'app/auth/libs/page-proxy.ts',\n 'app/auth/libs/api-proxy.ts',\n 'app/auth/libs/casdoor-oauth.ts',\n 'app/auth/libs/nextauth-route.ts',\n 'app/auth/libs',\n 'lib/auth-kit/index.ts',\n 'lib/auth-kit/index-html.ts',\n 'lib/auth-kit',\n 'lib/casdoor-entry.ts',\n 'lib/auth.ts',\n 'lib/public-origin.ts',\n 'lib/request-security.ts',\n 'lib/auth-redirect.ts',\n] as const;\n\nfunction logCreated(filePath: string) {\n console.log(`+ ${path.relative(projectRoot, filePath)}`);\n}\n\nfunction logUpdated(filePath: string) {\n console.log(`~ ${path.relative(projectRoot, filePath)}`);\n}\n\nfunction logRemoved(filePath: string) {\n console.log(`- ${path.relative(projectRoot, filePath)}`);\n}\n\nfunction syncManagedEnvFiles() {\n for (const file of AUTH_KIT_ENV_FILES) {\n const filePath = path.join(projectRoot, file);\n const existed = exists(filePath);\n const current = existed ? read(filePath) : '';\n const next = envTemplate(file, current);\n if (!existed || current !== next) {\n writeTextFile(filePath, next);\n if (!existed) {\n logCreated(filePath);\n } else {\n logUpdated(filePath);\n }\n }\n }\n}\n\nfunction syncManagedSkillFile() {\n const filePath = path.join(projectRoot, skillTarget);\n try {\n const sourcePath = canonicalSkillPaths.find((candidate) => fs.existsSync(candidate));\n if (!sourcePath) {\n throw new Error(`Unable to locate canonical skill directory. Checked: ${canonicalSkillPaths.join(', ')}`);\n }\n removePath(filePath);\n fs.mkdirSync(filePath, { recursive: true });\n logCreated(filePath);\n for (const entry of fs.readdirSync(sourcePath, { withFileTypes: true })) {\n const sourceEntry = path.join(sourcePath, entry.name);\n const targetEntry = path.join(filePath, entry.name);\n if (entry.isDirectory()) {\n fs.cpSync(sourceEntry, targetEntry, { recursive: true });\n console.log(`+ ${path.relative(projectRoot, targetEntry)}/`);\n continue;\n }\n fs.copyFileSync(sourceEntry, targetEntry);\n console.log(`+ ${path.relative(projectRoot, targetEntry)}`);\n }\n } catch (error) {\n console.warn(`Skipped skill sync for ${skillTarget}: ${error instanceof Error ? error.message : String(error)}`);\n }\n}\n\nexport async function initProject() {\n for (const [rel, factory] of targets) {\n const filePath = path.join(projectRoot, rel);\n if (!exists(filePath)) {\n writeGeneratedFile(filePath, factory());\n logCreated(filePath);\n }\n }\n\n syncManagedEnvFiles();\n syncManagedSkillFile();\n console.log('Initialized casdoor-next-auth-kit managed files.');\n}\n\nexport async function updateProject() {\n for (const rel of deprecatedTargets) {\n const filePath = path.join(projectRoot, rel);\n if (exists(filePath)) {\n removePath(filePath);\n logRemoved(filePath);\n }\n }\n\n for (const [rel, factory] of targets) {\n const filePath = path.join(projectRoot, rel);\n const next = '// generated by @foldspace-fe/casdoor-next-auth-kit\\n' + factory();\n if (!exists(filePath)) {\n writeGeneratedFile(filePath, factory());\n logCreated(filePath);\n continue;\n }\n\n const current = read(filePath);\n const updated = preserveCustomBlock(current, next);\n if (current !== updated) {\n writeTextFile(filePath, updated);\n logUpdated(filePath);\n }\n }\n\n syncManagedEnvFiles();\n syncManagedSkillFile();\n console.log('Updated managed route shells, env files, and skill file.');\n}\n\nexport async function checkProject() {\n const missingRoutes = targets.filter(([rel]) => !exists(path.join(projectRoot, rel))).map(([rel]) => rel);\n const missingEnv = AUTH_KIT_ENV_FILES.filter((file) => {\n const filePath = path.join(projectRoot, file);\n if (!exists(filePath)) {\n return true;\n }\n return getMissingManagedEnvKeys(read(filePath)).length > 0;\n });\n const skillDir = path.join(projectRoot, skillTarget);\n const missingSkill = exists(path.join(skillDir, 'SKILL.md')) ? [] : [path.join(skillTarget, 'SKILL.md')];\n const missing = [...missingRoutes, ...missingEnv, ...missingSkill];\n\n if (missing.length > 0) {\n console.error('Missing generated files:');\n for (const rel of missing) {\n console.error('- ' + rel);\n }\n process.exitCode = 1;\n return;\n }\n\n console.log('All managed files are present.');\n}\n"," import fs from 'node:fs';\n import path from 'node:path';\n\n export const generatedHeader = '// generated by @foldspace-fe/casdoor-next-auth-kit\\n';\n export const customBegin = '// @foldspace-fe/casdoor-next-auth-kit:begin custom';\n export const customEnd = '// @foldspace-fe/casdoor-next-auth-kit:end custom';\n\nexport function ensureDir(filePath: string) {\n fs.mkdirSync(path.dirname(filePath), { recursive: true });\n}\n\nexport function writeGeneratedFile(filePath: string, content: string) {\n ensureDir(filePath);\n fs.writeFileSync(filePath, generatedHeader + content, 'utf8');\n}\n\nexport function writeTextFile(filePath: string, content: string) {\n ensureDir(filePath);\n fs.writeFileSync(filePath, content, 'utf8');\n}\n\nexport function exists(filePath: string) {\n return fs.existsSync(filePath);\n}\n\n export function read(filePath: string) {\n return fs.readFileSync(filePath, 'utf8');\n }\n\nexport function preserveCustomBlock(existing: string, next: string) {\n const begin = existing.indexOf(customBegin);\n const end = existing.indexOf(customEnd);\n if (begin === -1 || end === -1 || end <= begin) return next;\n const custom = existing.slice(begin, end + customEnd.length);\n const targetBegin = next.indexOf(customBegin);\n const targetEnd = next.indexOf(customEnd);\n if (targetBegin === -1 || targetEnd === -1 || targetEnd <= targetBegin) return next;\n return next.slice(0, targetBegin) + custom + next.slice(targetEnd + customEnd.length);\n}\n\nexport function removePath(filePath: string) {\n fs.rmSync(filePath, { force: true, recursive: true });\n}\n","import fs from 'node:fs';\nimport path from 'node:path';\n\nimport { customBegin, customEnd } from './fs';\nimport { buildAuthPrismaSchemaTemplate } from '../prisma/schema-template';\nimport { AUTH_KIT_ENV_FILES, buildManagedEnvTemplate, readManagedEnvValue } from '../core/env';\n\nfunction getManagedEnvValue(key: string): string | null {\n for (const file of ['.env.local', '.env', '.env.production', '.env.example'] as const) {\n const filePath = path.join(process.cwd(), file);\n if (!fs.existsSync(filePath)) {\n continue;\n }\n\n const value = readManagedEnvValue(fs.readFileSync(filePath, 'utf8'), key);\n if (value !== null) {\n return value;\n }\n }\n\n return null;\n}\n\nexport function authLoginRouteTemplate() {\n return `import { loginHandler } from '../../auth-config';\n\nexport const dynamic = 'force-dynamic';\n\nexport const GET = loginHandler;\n`;\n}\n\nexport function authSignupRouteTemplate() {\n return `import { signupHandler } from '../../auth-config';\n\nexport const dynamic = 'force-dynamic';\n\nexport const GET = signupHandler;\n`;\n}\n\nexport function authorizeRouteTemplate() {\n return `import { authorizeHandler } from '../../../auth-config';\n\nexport const dynamic = 'force-dynamic';\n\nexport const GET = authorizeHandler;\n`;\n}\n\nexport function signupAuthorizeRouteTemplate() {\n return `import { authorizeHandler } from '../../../auth-config';\n\nexport const dynamic = 'force-dynamic';\n\nexport const GET = authorizeHandler;\n`;\n}\n\nexport function callbackRouteTemplate() {\n return `import { callbackHandler } from '../auth-config';\n\nexport const dynamic = 'force-dynamic';\n\nexport const GET = callbackHandler;\n`;\n}\n\nexport function logoutRouteTemplate() {\n return `import { logoutHandler } from '../auth-config';\n\nexport const dynamic = 'force-dynamic';\n\nexport const GET = logoutHandler;\n`;\n}\n\nexport function authConfigTemplate() {\n const billingPaymentSuccessHandlerImport = getManagedEnvValue('BILLING_PAYMENT_SUCCESS_HANDLER');\n const billingPaymentFinishedHandlerImport = getManagedEnvValue('BILLING_PAYMENT_FINISHED_HANDLER');\n const billingPaymentSuccessHandlerImportLine = billingPaymentSuccessHandlerImport\n ? `import { paymentSuccessHandler as billingPaymentSuccessHandler } from ${JSON.stringify(billingPaymentSuccessHandlerImport)};\\n`\n : '';\n const billingPaymentFinishedHandlerImportLine = billingPaymentFinishedHandlerImport\n ? `import { paymentFinishedHandler as billingPaymentFinishedHandler } from ${JSON.stringify(billingPaymentFinishedHandlerImport)};\\n`\n : '';\n\n return `import {\n createCallbackHandler,\n createCasdoorApiProxyHandler,\n createCasdoorCommerceProxyHandler,\n createAuthorizeRouteHandler,\n createLoginRouteHandler,\n createLogoutHandler,\n createNextAuthOptions,\n createSignupRouteHandler,\n type AuthBusinessAdapter,\n type AuthKitConfig,\n type AuthPersistenceAdapter,\n type AuthUser,\n} from '@foldspace-fe/casdoor-next-auth-kit';\n${billingPaymentSuccessHandlerImportLine}${billingPaymentFinishedHandlerImportLine}import { db } from '@/lib/db';\nimport { isGlobalAdminEmail } from '@/lib/auth-roles';\nimport { syncUserRecord } from '@/lib/user-record';\n\nexport function createAuthKitConfig(): AuthKitConfig {\n return {\n appUrl: process.env.APP_URL || '',\n nextauthSecret: process.env.NEXTAUTH_SECRET || 'dev-nextauth-secret',\n casdoor: {\n serverUrl: process.env.NEXT_PUBLIC_CASDOOR_SERVER_URL || process.env.CASDOOR_SERVER_URL || '',\n clientId: process.env.NEXT_PUBLIC_CASDOOR_CLIENT_ID || process.env.CASDOOR_CLIENT_ID || '',\n clientSecret: process.env.CASDOOR_CLIENT_SECRET || '',\n appName: process.env.NEXT_PUBLIC_CASDOOR_APP_NAME || '',\n organizationName: process.env.NEXT_PUBLIC_CASDOOR_ORGANIZATION_NAME || '',\n redirectPath: process.env.NEXT_PUBLIC_CASDOOR_REDIRECT_PATH || '/callback',\n signinPath: process.env.NEXT_PUBLIC_CASDOOR_SIGNIN_PATH || '/login/oauth/authorize',\n },\n };\n}\n\nconst authKitConfig = createAuthKitConfig();\n\nconst adapter: AuthBusinessAdapter = {\n isAdminEmail: isGlobalAdminEmail,\n};\n\nconst persistence: AuthPersistenceAdapter = {\n async syncAuthUser(user) {\n await syncUserRecord(user);\n },\n async findAuthUser({ id, email }) {\n const user = id\n ? await db.user.findUnique({\n where: { id },\n select: {\n id: true,\n name: true,\n email: true,\n image: true,\n tokenBalance: true,\n isVip: true,\n isAdmin: true,\n },\n })\n : email\n ? await db.user.findFirst({\n where: { email },\n select: {\n id: true,\n name: true,\n email: true,\n image: true,\n tokenBalance: true,\n isVip: true,\n isAdmin: true,\n },\n })\n : null;\n\n if (!user) {\n return null;\n }\n\n return {\n id: user.id,\n name: user.name,\n email: user.email,\n image: user.image,\n tokenBalance: Number(user.tokenBalance ?? 2580),\n isVip: Boolean(user.isVip ?? true),\n isAdmin: Boolean(user.isAdmin) || isGlobalAdminEmail(user.email),\n } satisfies AuthUser;\n },\n};\n\nexport const paymentSuccessHandler = ${billingPaymentSuccessHandlerImport ? 'billingPaymentSuccessHandler' : 'undefined'};\nexport const paymentFinishedHandler = ${billingPaymentFinishedHandlerImport ? 'billingPaymentFinishedHandler' : 'undefined'};\n\nexport const loginHandler = createLoginRouteHandler(authKitConfig);\nexport const signupHandler = createSignupRouteHandler(authKitConfig);\nexport const authorizeHandler = createAuthorizeRouteHandler(authKitConfig);\nexport const callbackHandler = createCallbackHandler({\n config: authKitConfig,\n adapter,\n persistence,\n});\nexport const logoutHandler = createLogoutHandler(authKitConfig);\nexport const authOptions = createNextAuthOptions({\n config: authKitConfig,\n adapter,\n persistence,\n});\nexport const apiProxyHandler = createCasdoorApiProxyHandler(authKitConfig, '/auth/api', '/api');\nexport const commerceProxyHandler = createCasdoorCommerceProxyHandler(authKitConfig, '/auth/api/commerce', '/api/commerce');\n`;\n}\n\nexport function nextAuthRouteTemplate() {\n return `import NextAuth from 'next-auth';\nimport { createNextAuthOptions } from '@foldspace-fe/casdoor-next-auth-kit';\nimport { adapter, authKitConfig, persistence } from '../../../auth-config';\n\nexport const dynamic = 'force-dynamic';\nexport const runtime = 'nodejs';\n\nconst handler = NextAuth(\n createNextAuthOptions({\n config: authKitConfig,\n adapter,\n persistence,\n }),\n);\n\nexport const GET = handler;\nexport const POST = handler;\n`;\n}\n\nexport function paymentSuccessRouteTemplate() {\n return `import { createBillingPaymentSuccessRouteHandler } from '@foldspace-fe/casdoor-next-auth-kit';\nimport { authKitConfig, paymentSuccessHandler } from '../../../auth-config';\n\nexport const dynamic = 'force-dynamic';\nexport const runtime = 'nodejs';\n\nexport const GET = createBillingPaymentSuccessRouteHandler({\n appUrl: authKitConfig.appUrl,\n fallbackRedirect: '/auth/payment/finished',\n handler: paymentSuccessHandler,\n});\n`;\n}\n\nexport function paymentFinishedRouteTemplate() {\n return `import { createBillingPaymentFinishedRouteHandler } from '@foldspace-fe/casdoor-next-auth-kit';\nimport { authKitConfig, paymentFinishedHandler } from '../../../auth-config';\n\nexport const dynamic = 'force-dynamic';\nexport const runtime = 'nodejs';\n\nexport const GET = createBillingPaymentFinishedRouteHandler({\n appUrl: authKitConfig.appUrl,\n fallbackRedirect: '/',\n handler: paymentFinishedHandler,\n});\n`;\n}\n\n export function authIndexHtmlTemplate() {\n return `export { AUTH_INDEX_HTML, createAuthIndexHtml } from '@foldspace-fe/casdoor-next-auth-kit';\n`;\n }\n\n export function prismaSchemaTemplate() {\n return buildAuthPrismaSchemaTemplate();\n }\n\nexport function apiProxyRouteTemplate() {\n return `import { apiProxyHandler } from '../../../auth-config';\n\nexport const dynamic = 'force-dynamic';\n\nexport const GET = apiProxyHandler;\nexport const HEAD = apiProxyHandler;\nexport const POST = apiProxyHandler;\nexport const PUT = apiProxyHandler;\nexport const PATCH = apiProxyHandler;\nexport const DELETE = apiProxyHandler;\nexport const OPTIONS = apiProxyHandler;\n`;\n}\n\nexport function commerceProxyRouteTemplate() {\n return `import { commerceProxyHandler } from '../../../../auth-config';\n\nexport const dynamic = 'force-dynamic';\n\nexport const GET = commerceProxyHandler;\nexport const HEAD = commerceProxyHandler;\nexport const POST = commerceProxyHandler;\nexport const PUT = commerceProxyHandler;\nexport const PATCH = commerceProxyHandler;\nexport const DELETE = commerceProxyHandler;\nexport const OPTIONS = commerceProxyHandler;\n`;\n}\n\n export function envTemplate(file: typeof AUTH_KIT_ENV_FILES[number], existingContent = '') {\n return buildManagedEnvTemplate(file, existingContent);\n }\n","import packageJson from '../../package.json';\n\nimport { initProject, checkProject, updateProject } from './operations';\n\nfunction printUsage() {\n console.log('Usage: npx @foldspace-fe/casdoor-next-auth-kit@latest <init|update|check>');\n console.log(' npx @foldspace-fe/casdoor-next-auth-kit@latest --help');\n console.log(' npx @foldspace-fe/casdoor-next-auth-kit@latest --version');\n}\n\nexport async function runCli(argv: string[]) {\n const command = argv[0] ?? 'help';\n if (command === '--help' || command === '-h' || command === 'help') {\n printUsage();\n return;\n }\n if (command === '--version' || command === '-v') {\n console.log(packageJson.version);\n return;\n }\n if (command === 'init') return initProject();\n if (command === 'update') return updateProject();\n if (command === 'check') return checkProject();\n printUsage();\n}\n","import { runCli } from './cli/index';\n\nrunCli(process.argv.slice(2)).catch((error) => {\n console.error(error instanceof Error ? error.message : error);\n process.exit(1);\n});\n"],"mappings":";;;;;;;;;AAAA;AAAA,EACE,MAAQ;AAAA,EACR,SAAW;AAAA,EACX,SAAW;AAAA,EACX,MAAQ;AAAA,EACR,YAAc;AAAA,IACZ,MAAQ;AAAA,IACR,KAAO;AAAA,EACT;AAAA,EACA,UAAY;AAAA,EACZ,MAAQ;AAAA,IACN,KAAO;AAAA,EACT;AAAA,EACA,MAAQ;AAAA,EACR,OAAS;AAAA,EACT,SAAW;AAAA,IACT,KAAK;AAAA,MACH,OAAS;AAAA,MACT,SAAW;AAAA,IACb;AAAA,IACA,aAAa;AAAA,MACX,OAAS;AAAA,MACT,SAAW;AAAA,IACb;AAAA,IACA,UAAU;AAAA,MACR,OAAS;AAAA,MACT,SAAW;AAAA,IACb;AAAA,IACA,aAAa;AAAA,MACX,OAAS;AAAA,MACT,SAAW;AAAA,IACb;AAAA,IACA,WAAW;AAAA,MACT,OAAS;AAAA,MACT,SAAW;AAAA,IACb;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,UAAQ,IAAI,2EAA2E;AACvF,UAAQ,IAAI,8DAA8D;AAC1E,UAAQ,IAAI,iEAAiE;AAC/E;AAEA,eAAsB,OAAO,MAAgB;AAC3C,QAAM,UAAU,KAAK,CAAC,KAAK;AAC3B,MAAI,YAAY,YAAY,YAAY,QAAQ,YAAY,QAAQ;AAClE,eAAW;AACX;AAAA,EACF;AACA,MAAI,YAAY,eAAe,YAAY,MAAM;AAC/C,YAAQ,IAAI,gBAAY,OAAO;AAC/B;AAAA,EACF;AACA,MAAI,YAAY,OAAQ,QAAO,YAAY;AAC3C,MAAI,YAAY,SAAU,QAAO,cAAc;AAC/C,MAAI,YAAY,QAAS,QAAO,aAAa;AAC7C,aAAW;AACb;;;ACtBA,OAAO,QAAQ,KAAK,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,UAAU;AAC7C,UAAQ,MAAM,iBAAiB,QAAQ,MAAM,UAAU,KAAK;AAC5D,UAAQ,KAAK,CAAC;AAChB,CAAC;","names":["fs","path","fs","path","path","fs","path","fs"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,8 +5,8 @@ export { createAuthorizeEntryResponse, createCasdoorApiProxyHandler, createCasdo
|
|
|
5
5
|
export { C as CallbackHandlerOptions, c as createCallbackHandler, a as createCallbackResponse } from './callback-BTzHQK_r.js';
|
|
6
6
|
export { createAuthorizeRouteHandler, createLoginRouteHandler, createLogoutHandler, createSignupRouteHandler } from './next/index.js';
|
|
7
7
|
export { A as AuthSession, a as AuthSessionUser, b as AuthTokenPayload, N as NextAuthRouteOptions, c as createNextAuthOptions, d as createNextAuthRouteHandler } from './options-JUwZSXu2.js';
|
|
8
|
-
export { f as BillingActionExecutor, s as BillingActionKind, B as BillingActionPayload, d as BillingApiClient, c as BillingCatalogConfig, t as BillingConversionRule, r as BillingCoreContextValue, u as BillingCreditsContextValue, m as BillingCreditsState, g as BillingDefaults, n as BillingEntitlementState, v as BillingInterval, a as BillingItem, w as BillingItemKind, e as BillingLoaders, k as BillingOrderHistoryItem, l as BillingPaymentHistoryItem,
|
|
9
|
-
export { buildBillingActionPayload, deriveBillingCreditsState, deriveBillingEntitlements,
|
|
8
|
+
export { f as BillingActionExecutor, s as BillingActionKind, B as BillingActionPayload, d as BillingApiClient, c as BillingCatalogConfig, t as BillingConversionRule, r as BillingCoreContextValue, u as BillingCreditsContextValue, m as BillingCreditsState, g as BillingDefaults, n as BillingEntitlementState, v as BillingInterval, a as BillingItem, w as BillingItemKind, e as BillingLoaders, k as BillingOrderHistoryItem, x as BillingPaymentFinishedHandler, y as BillingPaymentFinishedRouteOptions, l as BillingPaymentHistoryItem, z as BillingPaymentSuccessContext, A as BillingPaymentSuccessHandler, C as BillingPaymentSuccessHandlerResult, D as BillingPaymentSuccessRouteOptions, E as BillingProductContextValue, F as BillingProductPurchaseConfig, q as BillingProductSnapshot, j as BillingProductState, p as BillingPurchaseStatus, b as BillingRuntimeConfig, o as BillingStatusState, G as BillingSubscriptionContextValue, i as BillingSubscriptionHistoryItem, H as BillingSubscriptionPurchaseConfig, h as BillingSubscriptionState } from './types-DwThfdu-.js';
|
|
9
|
+
export { buildBillingActionPayload, createBillingPaymentFinishedResponse, createBillingPaymentFinishedRouteHandler, createBillingPaymentSuccessResponse, createBillingPaymentSuccessRouteHandler, deriveBillingCreditsState, deriveBillingEntitlements, normalizeBillingCatalogConfig, normalizeBillingPurchaseStatus, normalizeBillingRuntimeConfig, resolveBillingInterval, resolveBillingItem, resolveBillingProductSnapshot, resolveBillingSubscriptionProduct } from './billing/index.js';
|
|
10
10
|
import 'next/server';
|
|
11
11
|
import 'next-auth';
|
|
12
12
|
|
|
@@ -49,6 +49,7 @@ declare function isGlobalAdminEmail(email: string | null | undefined): boolean;
|
|
|
49
49
|
|
|
50
50
|
declare const AUTH_KIT_ENV_FILES: ManagedEnvFile[];
|
|
51
51
|
declare const AUTH_KIT_ENV_VARIABLES: ManagedEnvVariableDefinition[];
|
|
52
|
+
declare function readManagedEnvValue(content: string, key: string): string | null;
|
|
52
53
|
declare function getManagedEnvValue(definition: ManagedEnvVariableDefinition, file: ManagedEnvFile): string;
|
|
53
54
|
declare function buildManagedEnvTemplate(file: ManagedEnvFile, existingContent?: string): string;
|
|
54
55
|
declare function getMissingManagedEnvKeys(content: string): string[];
|
|
@@ -74,4 +75,4 @@ declare function decodeSessionToken(params: JWTDecodeParams): Promise<JWT | null
|
|
|
74
75
|
declare const AUTH_PRISMA_SCHEMA_MODELS: PrismaSchemaModelDefinition[];
|
|
75
76
|
declare function buildAuthPrismaSchemaTemplate(models?: PrismaSchemaModelDefinition[]): string;
|
|
76
77
|
|
|
77
|
-
export { AUTH_INDEX_HTML, AUTH_KIT_ENV_FILES, AUTH_KIT_ENV_VARIABLES, AUTH_PRISMA_SCHEMA_MODELS, AUTH_REDIRECT_COOKIE_NAME, AuthIndexHtmlOptions, AuthKitConfig, AuthUser, ManagedEnvFile, ManagedEnvVariableDefinition, PUBLIC_ORIGIN_COOKIE_NAME, PrismaSchemaModelDefinition, type StatePayload, buildAuthJumpHref, buildAuthPrismaSchemaTemplate, buildManagedEnvTemplate, clearAuthRedirectCookie, clearPublicOriginCookie, createAuthIndexHtml, decodeSessionToken, encodeSessionToken, generateStateToken, getAuthRedirectTarget, getGlobalAdminEmails, getManagedEnvValue, getMissingManagedEnvKeys, getPkceCookieName, getRequestOrigin, getStoredPublicOrigin, isGlobalAdminEmail, isSecureRequest, normalizeAuthKitConfig, parseStateToken, pkceCookiePrefix, resolvePostLoginRedirect, sanitizeExistingEnvContent, setAuthRedirectCookie, setPublicOriginCookie, verifyState, verifyStateToken };
|
|
78
|
+
export { AUTH_INDEX_HTML, AUTH_KIT_ENV_FILES, AUTH_KIT_ENV_VARIABLES, AUTH_PRISMA_SCHEMA_MODELS, AUTH_REDIRECT_COOKIE_NAME, AuthIndexHtmlOptions, AuthKitConfig, AuthUser, ManagedEnvFile, ManagedEnvVariableDefinition, PUBLIC_ORIGIN_COOKIE_NAME, PrismaSchemaModelDefinition, type StatePayload, buildAuthJumpHref, buildAuthPrismaSchemaTemplate, buildManagedEnvTemplate, clearAuthRedirectCookie, clearPublicOriginCookie, createAuthIndexHtml, decodeSessionToken, encodeSessionToken, generateStateToken, getAuthRedirectTarget, getGlobalAdminEmails, getManagedEnvValue, getMissingManagedEnvKeys, getPkceCookieName, getRequestOrigin, getStoredPublicOrigin, isGlobalAdminEmail, isSecureRequest, normalizeAuthKitConfig, parseStateToken, pkceCookiePrefix, readManagedEnvValue, resolvePostLoginRedirect, sanitizeExistingEnvContent, setAuthRedirectCookie, setPublicOriginCookie, verifyState, verifyStateToken };
|
package/dist/index.js
CHANGED
|
@@ -6,14 +6,20 @@ import {
|
|
|
6
6
|
buildManagedEnvTemplate,
|
|
7
7
|
getManagedEnvValue,
|
|
8
8
|
getMissingManagedEnvKeys,
|
|
9
|
+
readManagedEnvValue,
|
|
9
10
|
sanitizeExistingEnvContent
|
|
10
|
-
} from "./chunk-
|
|
11
|
-
import
|
|
11
|
+
} from "./chunk-PFHMT4ZD.js";
|
|
12
|
+
import {
|
|
13
|
+
createBillingPaymentFinishedResponse,
|
|
14
|
+
createBillingPaymentFinishedRouteHandler,
|
|
15
|
+
createBillingPaymentSuccessResponse,
|
|
16
|
+
createBillingPaymentSuccessRouteHandler
|
|
17
|
+
} from "./chunk-NGKCQHB3.js";
|
|
12
18
|
import {
|
|
13
19
|
createCasdoorApiProxyHandler,
|
|
14
20
|
createCasdoorCommerceProxyHandler,
|
|
15
21
|
createCasdoorPageProxyHandler
|
|
16
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-YXTDGBLC.js";
|
|
17
23
|
import {
|
|
18
24
|
createAuthorizeRouteHandler,
|
|
19
25
|
createLoginRouteHandler,
|
|
@@ -64,7 +70,6 @@ import {
|
|
|
64
70
|
buildBillingActionPayload,
|
|
65
71
|
deriveBillingCreditsState,
|
|
66
72
|
deriveBillingEntitlements,
|
|
67
|
-
filterProductsByKind,
|
|
68
73
|
normalizeBillingCatalogConfig,
|
|
69
74
|
normalizeBillingPurchaseStatus,
|
|
70
75
|
normalizeBillingRuntimeConfig,
|
|
@@ -72,7 +77,7 @@ import {
|
|
|
72
77
|
resolveBillingItem,
|
|
73
78
|
resolveBillingProductSnapshot,
|
|
74
79
|
resolveBillingSubscriptionProduct
|
|
75
|
-
} from "./chunk-
|
|
80
|
+
} from "./chunk-O3FKI5NT.js";
|
|
76
81
|
import {
|
|
77
82
|
buildAuthJumpHref,
|
|
78
83
|
resolvePostLoginRedirect
|
|
@@ -93,6 +98,10 @@ export {
|
|
|
93
98
|
createAuthIndexHtml,
|
|
94
99
|
createAuthorizeEntryResponse,
|
|
95
100
|
createAuthorizeRouteHandler,
|
|
101
|
+
createBillingPaymentFinishedResponse,
|
|
102
|
+
createBillingPaymentFinishedRouteHandler,
|
|
103
|
+
createBillingPaymentSuccessResponse,
|
|
104
|
+
createBillingPaymentSuccessRouteHandler,
|
|
96
105
|
createCallbackHandler,
|
|
97
106
|
createCallbackResponse,
|
|
98
107
|
createCasdoorApiProxyHandler,
|
|
@@ -113,7 +122,6 @@ export {
|
|
|
113
122
|
exchangeCasdoorOAuthToken,
|
|
114
123
|
exchangeCodeForToken,
|
|
115
124
|
fetchCasdoorUserInfo,
|
|
116
|
-
filterProductsByKind,
|
|
117
125
|
generateStateToken,
|
|
118
126
|
getAuthRedirectTarget,
|
|
119
127
|
getCasdoorAuthorizeUrl,
|
|
@@ -134,6 +142,7 @@ export {
|
|
|
134
142
|
normalizeBillingRuntimeConfig,
|
|
135
143
|
parseStateToken,
|
|
136
144
|
pkceCookiePrefix,
|
|
145
|
+
readManagedEnvValue,
|
|
137
146
|
resolveBillingInterval,
|
|
138
147
|
resolveBillingItem,
|
|
139
148
|
resolveBillingProductSnapshot,
|
package/dist/react/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { Session } from 'next-auth';
|
|
|
5
5
|
import { useSession } from 'next-auth/react';
|
|
6
6
|
import { A as AuthSession } from '../options-JUwZSXu2.js';
|
|
7
7
|
export { a as AuthSessionUser, b as AuthTokenPayload } from '../options-JUwZSXu2.js';
|
|
8
|
-
import { B as BillingActionPayload, a as BillingItem, b as BillingRuntimeConfig, c as BillingCatalogConfig, d as BillingApiClient, e as BillingLoaders, f as BillingActionExecutor, g as BillingDefaults, h as BillingSubscriptionState, i as BillingSubscriptionHistoryItem, j as BillingProductState, k as BillingOrderHistoryItem, l as BillingPaymentHistoryItem, m as BillingCreditsState, n as BillingEntitlementState, o as BillingStatusState, p as BillingPurchaseStatus, q as BillingProductSnapshot, r as BillingCoreContextValue } from '../types-
|
|
8
|
+
import { B as BillingActionPayload, a as BillingItem, b as BillingRuntimeConfig, c as BillingCatalogConfig, d as BillingApiClient, e as BillingLoaders, f as BillingActionExecutor, g as BillingDefaults, h as BillingSubscriptionState, i as BillingSubscriptionHistoryItem, j as BillingProductState, k as BillingOrderHistoryItem, l as BillingPaymentHistoryItem, m as BillingCreditsState, n as BillingEntitlementState, o as BillingStatusState, p as BillingPurchaseStatus, q as BillingProductSnapshot, r as BillingCoreContextValue } from '../types-DwThfdu-.js';
|
|
9
9
|
import 'next-auth/jwt';
|
|
10
10
|
import '../types-DqVXdUge.js';
|
|
11
11
|
|
|
@@ -118,11 +118,7 @@ interface BillingProductsState {
|
|
|
118
118
|
error: string | null;
|
|
119
119
|
refresh: () => Promise<void>;
|
|
120
120
|
}
|
|
121
|
-
declare function useBillingProducts(
|
|
122
|
-
userId?: string;
|
|
123
|
-
catalogKey?: string;
|
|
124
|
-
kind?: 'product' | 'credits';
|
|
125
|
-
}): BillingProductsState;
|
|
121
|
+
declare function useBillingProducts(): BillingProductsState;
|
|
126
122
|
interface BillingAvailablePlansState {
|
|
127
123
|
plans: BillingItem[];
|
|
128
124
|
loading: boolean;
|
|
@@ -228,7 +224,6 @@ declare function useSubscribePlan(): BillingActionHookResult;
|
|
|
228
224
|
declare function useManageSubscription(): BillingActionHookResult;
|
|
229
225
|
declare function useUpgradePlan(): BillingActionHookResult;
|
|
230
226
|
declare function useCancelSubscription(): BillingActionHookResult;
|
|
231
|
-
declare function usePurchaseCredits(): BillingActionHookResult;
|
|
232
227
|
declare function usePurchaseProduct(): BillingActionHookResult;
|
|
233
228
|
interface BillingProductStateView {
|
|
234
229
|
product?: BillingProductState;
|
|
@@ -239,4 +234,4 @@ interface BillingProductStateView {
|
|
|
239
234
|
declare function useBillingProduct(productKey: string): BillingProductStateView;
|
|
240
235
|
declare function useBillingCatalogConfig(): BillingCatalogState;
|
|
241
236
|
|
|
242
|
-
export { type AuthActions, type AuthActionsOptions, AuthProvider, type AuthRole, AuthSession, type AuthUserSummary, type BillingActionHookResult, type BillingAvailablePlansState, type BillingAvailableProductsState, type BillingCatalogState, BillingCoreProvider, type BillingCoreProviderProps, type BillingCreditsProviderProps, type BillingCreditsStateView, type BillingEntitlementsStateView, type BillingItemState, type BillingOrderHistoryState, type BillingPaymentHistoryState, type BillingPipelineOptions, type BillingPipelineResult, type BillingProductProviderProps, type BillingProductStateView, type BillingProductsState, BillingProvider, type BillingProviderProps, type BillingPurchaseStatusView, type BillingRefreshView, type BillingStatusView, type BillingSubscriptionHistoryState, type BillingSubscriptionProductState, type BillingSubscriptionProviderProps, type BillingSubscriptionStateView, CreditsProvider, ProductProvider, SubscriptionProvider, useAuthActions, useAuthRole, useAuthSession, useAuthUser, useBillingAvailablePlans, useBillingAvailableProducts, useBillingCatalog, useBillingCatalogConfig, useBillingContext, useBillingCredits, useBillingEntitlements, useBillingItem, useBillingOrderHistory, useBillingPaymentHistory, useBillingPipeline, useBillingProduct, useBillingProducts, useBillingPurchaseStatus, useBillingRefresh, useBillingStatus, useBillingSubscription, useBillingSubscriptionHistory, useBillingSubscriptionProduct, useCancelSubscription, useManageSubscription,
|
|
237
|
+
export { type AuthActions, type AuthActionsOptions, AuthProvider, type AuthRole, AuthSession, type AuthUserSummary, type BillingActionHookResult, type BillingAvailablePlansState, type BillingAvailableProductsState, type BillingCatalogState, BillingCoreProvider, type BillingCoreProviderProps, type BillingCreditsProviderProps, type BillingCreditsStateView, type BillingEntitlementsStateView, type BillingItemState, type BillingOrderHistoryState, type BillingPaymentHistoryState, type BillingPipelineOptions, type BillingPipelineResult, type BillingProductProviderProps, type BillingProductStateView, type BillingProductsState, BillingProvider, type BillingProviderProps, type BillingPurchaseStatusView, type BillingRefreshView, type BillingStatusView, type BillingSubscriptionHistoryState, type BillingSubscriptionProductState, type BillingSubscriptionProviderProps, type BillingSubscriptionStateView, CreditsProvider, ProductProvider, SubscriptionProvider, useAuthActions, useAuthRole, useAuthSession, useAuthUser, useBillingAvailablePlans, useBillingAvailableProducts, useBillingCatalog, useBillingCatalogConfig, useBillingContext, useBillingCredits, useBillingEntitlements, useBillingItem, useBillingOrderHistory, useBillingPaymentHistory, useBillingPipeline, useBillingProduct, useBillingProducts, useBillingPurchaseStatus, useBillingRefresh, useBillingStatus, useBillingSubscription, useBillingSubscriptionHistory, useBillingSubscriptionProduct, useCancelSubscription, useManageSubscription, usePurchaseProduct, useSubscribePlan, useUpgradePlan };
|
package/dist/react/index.js
CHANGED
|
@@ -2,14 +2,13 @@ import {
|
|
|
2
2
|
buildBillingActionPayload,
|
|
3
3
|
deriveBillingCreditsState,
|
|
4
4
|
deriveBillingEntitlements,
|
|
5
|
-
filterProductsByKind,
|
|
6
5
|
normalizeBillingCatalogConfig,
|
|
7
6
|
normalizeBillingPurchaseStatus,
|
|
8
7
|
normalizeBillingRuntimeConfig,
|
|
9
8
|
resolveBillingItem,
|
|
10
9
|
resolveBillingProductSnapshot,
|
|
11
10
|
resolveBillingSubscriptionProduct
|
|
12
|
-
} from "../chunk-
|
|
11
|
+
} from "../chunk-O3FKI5NT.js";
|
|
13
12
|
import {
|
|
14
13
|
buildAuthJumpHref
|
|
15
14
|
} from "../chunk-T2M5MVPE.js";
|
|
@@ -437,7 +436,7 @@ function ProductProvider({
|
|
|
437
436
|
const core = useOptionalContext(BillingCoreContext);
|
|
438
437
|
const value = useMemo(
|
|
439
438
|
() => ({
|
|
440
|
-
availableProducts: choose(availableProducts, core?.runtimeConfig?.items?.filter((item) => item.kind === "product"
|
|
439
|
+
availableProducts: choose(availableProducts, core?.runtimeConfig?.items?.filter((item) => item.kind === "product")),
|
|
441
440
|
products: choose(products, core?.products),
|
|
442
441
|
orderHistory: choose(orderHistory, core?.orderHistory),
|
|
443
442
|
paymentHistory: choose(paymentHistory, core?.paymentHistory),
|
|
@@ -485,18 +484,18 @@ function useBillingItem(itemKey) {
|
|
|
485
484
|
};
|
|
486
485
|
}, [core.refresh, core.runtimeConfig?.items, core.runtimeConfigError, core.runtimeConfigLoading, itemKey]);
|
|
487
486
|
}
|
|
488
|
-
function useBillingProducts(
|
|
487
|
+
function useBillingProducts() {
|
|
489
488
|
const core = useRequiredCoreContext();
|
|
490
489
|
const productContext = useOptionalContext(BillingProductContext);
|
|
491
490
|
const products = choose(productContext?.products, core.products) ?? [];
|
|
492
491
|
return useMemo(
|
|
493
492
|
() => ({
|
|
494
|
-
products
|
|
493
|
+
products,
|
|
495
494
|
loading: core.runtimeConfigLoading || core.status.loading,
|
|
496
495
|
error: core.runtimeConfigError ?? core.status.error,
|
|
497
496
|
refresh: core.refresh
|
|
498
497
|
}),
|
|
499
|
-
[core.refresh, core.runtimeConfigError, core.runtimeConfigLoading, core.status.error, core.status.loading,
|
|
498
|
+
[core.refresh, core.runtimeConfigError, core.runtimeConfigLoading, core.status.error, core.status.loading, products]
|
|
500
499
|
);
|
|
501
500
|
}
|
|
502
501
|
function useBillingAvailablePlans() {
|
|
@@ -516,7 +515,7 @@ function useBillingAvailablePlans() {
|
|
|
516
515
|
function useBillingAvailableProducts() {
|
|
517
516
|
const core = useRequiredCoreContext();
|
|
518
517
|
const productContext = useOptionalContext(BillingProductContext);
|
|
519
|
-
const items = choose(productContext?.availableProducts, core.runtimeConfig?.items?.filter((item) => item.kind === "product"
|
|
518
|
+
const items = choose(productContext?.availableProducts, core.runtimeConfig?.items?.filter((item) => item.kind === "product")) ?? [];
|
|
520
519
|
return useMemo(
|
|
521
520
|
() => ({
|
|
522
521
|
items,
|
|
@@ -712,9 +711,6 @@ function useUpgradePlan() {
|
|
|
712
711
|
function useCancelSubscription() {
|
|
713
712
|
return useBillingActionRunner("cancel");
|
|
714
713
|
}
|
|
715
|
-
function usePurchaseCredits() {
|
|
716
|
-
return useBillingActionRunner("purchase");
|
|
717
|
-
}
|
|
718
714
|
function usePurchaseProduct() {
|
|
719
715
|
return useBillingActionRunner("purchase");
|
|
720
716
|
}
|
|
@@ -766,7 +762,6 @@ export {
|
|
|
766
762
|
useBillingSubscriptionProduct,
|
|
767
763
|
useCancelSubscription,
|
|
768
764
|
useManageSubscription,
|
|
769
|
-
usePurchaseCredits,
|
|
770
765
|
usePurchaseProduct,
|
|
771
766
|
useSubscribePlan,
|
|
772
767
|
useUpgradePlan
|