@foldspace-fe/casdoor-next-auth-kit 0.1.21 → 0.1.23
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 +73 -1
- package/dist/billing/index.d.ts +32 -3
- package/dist/billing/index.js +3 -1
- package/dist/{chunk-NWYEHQNK.js → chunk-PILMR42A.js} +40 -1
- package/dist/chunk-PILMR42A.js.map +1 -0
- package/dist/{chunk-FW4WDHNS.js → chunk-SZVWLQQT.js} +4 -4
- package/dist/chunk-SZVWLQQT.js.map +1 -0
- package/dist/cli.js +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +30 -28
- package/dist/skills/casdoor-next-auth-kit/SKILL.md +49 -1
- package/package.json +1 -1
- package/dist/chunk-FW4WDHNS.js.map +0 -1
- package/dist/chunk-NWYEHQNK.js.map +0 -1
package/README.md
CHANGED
|
@@ -51,10 +51,82 @@ import {
|
|
|
51
51
|
### Billing runtime
|
|
52
52
|
|
|
53
53
|
```ts
|
|
54
|
-
import
|
|
54
|
+
import { buildBillingSubscriptionCatalog } from '@foldspace-fe/casdoor-next-auth-kit/billing';
|
|
55
55
|
import { BillingProvider } from '@foldspace-fe/casdoor-next-auth-kit/react';
|
|
56
56
|
```
|
|
57
57
|
|
|
58
|
+
如果宿主已经有自己的会员计划 rows,先用 `buildBillingSubscriptionCatalog()` 生成 subscription catalog,再把结果交给 `BillingProvider`。商品项仍然可以单独拼进同一个 catalog,但订阅和商品要保持语义分离。
|
|
59
|
+
|
|
60
|
+
一个可以直接复制的完整模板如下:
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
const membershipPlans = [
|
|
64
|
+
{
|
|
65
|
+
id: 'plan-basic',
|
|
66
|
+
code: 'membership-monthly',
|
|
67
|
+
name: 'Membership Monthly',
|
|
68
|
+
level: 'BASIC',
|
|
69
|
+
priceCents: 99900,
|
|
70
|
+
giftPoints: 10000,
|
|
71
|
+
billingCycle: 'MONTH',
|
|
72
|
+
benefits: {
|
|
73
|
+
faceLibrary: true,
|
|
74
|
+
monthlyReports: true,
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
];
|
|
78
|
+
|
|
79
|
+
const subscriptionCatalog = buildBillingSubscriptionCatalog(membershipPlans, {
|
|
80
|
+
catalogKey: 'main',
|
|
81
|
+
title: 'Billing Catalog',
|
|
82
|
+
mapPlan: (plan) => ({
|
|
83
|
+
source: plan,
|
|
84
|
+
key: plan.code,
|
|
85
|
+
title: plan.name,
|
|
86
|
+
description: `${plan.level} membership`,
|
|
87
|
+
productId: 'qixiaoju/创小剧会员订阅',
|
|
88
|
+
planId: plan.id,
|
|
89
|
+
priceId: `pricing_${plan.code}`,
|
|
90
|
+
interval: 'month',
|
|
91
|
+
priceValue: plan.priceCents,
|
|
92
|
+
metadata: {
|
|
93
|
+
level: plan.level,
|
|
94
|
+
giftPoints: String(plan.giftPoints),
|
|
95
|
+
billingCycle: plan.billingCycle,
|
|
96
|
+
},
|
|
97
|
+
}),
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const billingCatalog = {
|
|
101
|
+
...subscriptionCatalog,
|
|
102
|
+
purchasableIds: [...subscriptionCatalog.purchasableIds, 'credits-50'],
|
|
103
|
+
items: [
|
|
104
|
+
...subscriptionCatalog.items,
|
|
105
|
+
{
|
|
106
|
+
key: 'credits-50',
|
|
107
|
+
kind: 'product',
|
|
108
|
+
title: '50 Credits',
|
|
109
|
+
description: 'One-time product used for credits or other non-recurring goods.',
|
|
110
|
+
credits: 50,
|
|
111
|
+
backendRef: {
|
|
112
|
+
productId: 'qixiaoju/创小剧积分包-50',
|
|
113
|
+
priceId: 'price_credits_50',
|
|
114
|
+
},
|
|
115
|
+
creditGrant: {
|
|
116
|
+
creditsPerUnit: 50,
|
|
117
|
+
unitName: 'credits',
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
};
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
如果你只是想配白名单,`.env` 里可以直接写:
|
|
125
|
+
|
|
126
|
+
```env
|
|
127
|
+
NEXT_PUBLIC_BILLING_PURCHASABLE_IDS=membership-monthly,credits-50
|
|
128
|
+
```
|
|
129
|
+
|
|
58
130
|
### Billing 动作
|
|
59
131
|
|
|
60
132
|
```tsx
|
package/dist/billing/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { B as BillingActionPayload, b as BillingRuntimeConfig, a7 as BillingPaymentCallbackContext, aq as BillingPurchaseRequest, m as BillingCreditsState, j as BillingProductState, h as BillingSubscriptionState, n as BillingEntitlementState, a as BillingItem, c as BillingCatalogConfig, p as BillingPurchaseStatus, k as BillingOrderHistoryItem, l as BillingPaymentHistoryItem, t as BillingCasdoorOrderDetail, x as BillingCasdoorSubscriptionDetail, i as BillingSubscriptionHistoryItem, a4 as BillingInterval, r as BillingProductSnapshot, ak as BillingPurchasableEntry, M as BillingCasdoorBuyProductRequest, w as BillingCasdoorProductDetail, N as BillingCasdoorBuyProductResponse, z as BillingActionExecutionResult, af as BillingPaymentSuccessRouteOptions, aa as BillingPaymentFinishedRouteOptions } from '../types-oVIQpMut.js';
|
|
2
|
-
export { f as BillingActionExecutor, A as BillingActionKind, d as BillingApiClient, C as BillingCasdoorAccountDetail, D as BillingCasdoorAccountMultiFactorAuthDetail, E as BillingCasdoorAccountResponse, F as BillingCasdoorApiResponse, G as BillingCasdoorApplicationDetail, H as BillingCasdoorApplicationProviderDetail, I as BillingCasdoorApplicationResponse, J as BillingCasdoorApplicationSigninItemDetail, K as BillingCasdoorApplicationSigninMethodDetail, L as BillingCasdoorApplicationSignupItemDetail, O as BillingCasdoorErrorDetail, P as BillingCasdoorErrorPayload, Q as BillingCasdoorOrderResponse, R as BillingCasdoorOrdersResponse, S as BillingCasdoorOrganizationDetail, T as BillingCasdoorOrganizationNamesResponse, U as BillingCasdoorOrganizationOption, V as BillingCasdoorPaymentDetail, W as BillingCasdoorPaymentResponse, u as BillingCasdoorPlanDetail, X as BillingCasdoorPlanResponse, v as BillingCasdoorPricingDetail, Y as BillingCasdoorPricingResponse, Z as BillingCasdoorProductResponse, _ as BillingCasdoorProviderDetail, $ as BillingCasdoorProviderOption, s as BillingCasdoorQueryState, a0 as BillingCasdoorSubscriptionResponse, a1 as BillingCasdoorSubscriptionsResponse, a2 as BillingConversionRule, y as BillingCoreContextValue, a3 as BillingCreditsContextValue,
|
|
1
|
+
import { B as BillingActionPayload, b as BillingRuntimeConfig, a7 as BillingPaymentCallbackContext, aq as BillingPurchaseRequest, m as BillingCreditsState, j as BillingProductState, h as BillingSubscriptionState, n as BillingEntitlementState, a as BillingItem, c as BillingCatalogConfig, p as BillingPurchaseStatus, k as BillingOrderHistoryItem, l as BillingPaymentHistoryItem, t as BillingCasdoorOrderDetail, x as BillingCasdoorSubscriptionDetail, i as BillingSubscriptionHistoryItem, a4 as BillingInterval, r as BillingProductSnapshot, ak as BillingPurchasableEntry, g as BillingDefaults, M as BillingCasdoorBuyProductRequest, w as BillingCasdoorProductDetail, N as BillingCasdoorBuyProductResponse, z as BillingActionExecutionResult, af as BillingPaymentSuccessRouteOptions, aa as BillingPaymentFinishedRouteOptions } from '../types-oVIQpMut.js';
|
|
2
|
+
export { f as BillingActionExecutor, A as BillingActionKind, d as BillingApiClient, C as BillingCasdoorAccountDetail, D as BillingCasdoorAccountMultiFactorAuthDetail, E as BillingCasdoorAccountResponse, F as BillingCasdoorApiResponse, G as BillingCasdoorApplicationDetail, H as BillingCasdoorApplicationProviderDetail, I as BillingCasdoorApplicationResponse, J as BillingCasdoorApplicationSigninItemDetail, K as BillingCasdoorApplicationSigninMethodDetail, L as BillingCasdoorApplicationSignupItemDetail, O as BillingCasdoorErrorDetail, P as BillingCasdoorErrorPayload, Q as BillingCasdoorOrderResponse, R as BillingCasdoorOrdersResponse, S as BillingCasdoorOrganizationDetail, T as BillingCasdoorOrganizationNamesResponse, U as BillingCasdoorOrganizationOption, V as BillingCasdoorPaymentDetail, W as BillingCasdoorPaymentResponse, u as BillingCasdoorPlanDetail, X as BillingCasdoorPlanResponse, v as BillingCasdoorPricingDetail, Y as BillingCasdoorPricingResponse, Z as BillingCasdoorProductResponse, _ as BillingCasdoorProviderDetail, $ as BillingCasdoorProviderOption, s as BillingCasdoorQueryState, a0 as BillingCasdoorSubscriptionResponse, a1 as BillingCasdoorSubscriptionsResponse, a2 as BillingConversionRule, y as BillingCoreContextValue, a3 as BillingCreditsContextValue, a5 as BillingItemKind, e as BillingLoaders, a6 as BillingOrderCreatedContext, a8 as BillingPaymentFinishedContext, a9 as BillingPaymentFinishedHandler, ab as BillingPaymentRouteBaseOptions, ac as BillingPaymentSuccessContext, ad as BillingPaymentSuccessHandler, ae as BillingPaymentSuccessHandlerResult, ag as BillingProductContextValue, ah as BillingProductDetailState, ai as BillingProductPurchasableEntry, aj as BillingProductPurchaseConfig, al as BillingPurchasableEntryBase, am as BillingPurchasableKind, an as BillingPurchasableWhitelist, ao as BillingPurchaseCompleteContext, ap as BillingPurchaseErrorContext, q as BillingPurchaseHooks, o as BillingStatusState, ar as BillingSubscriptionContextValue, as as BillingSubscriptionPurchasableEntry, at as BillingSubscriptionPurchaseConfig } from '../types-oVIQpMut.js';
|
|
3
3
|
|
|
4
4
|
declare function normalizeBillingRuntimeConfig(config?: Partial<BillingRuntimeConfig> | null): BillingRuntimeConfig;
|
|
5
5
|
declare function normalizeBillingCatalogConfig(config?: Partial<BillingCatalogConfig> | null): BillingCatalogConfig;
|
|
@@ -33,6 +33,35 @@ declare function normalizeBillingPurchaseStatus(status?: Partial<BillingPurchase
|
|
|
33
33
|
declare function resolveBillingInterval(interval?: BillingInterval | null): BillingInterval | undefined;
|
|
34
34
|
declare function buildBillingActionPayload(payload: BillingActionPayload, runtimeConfig?: BillingRuntimeConfig | null): BillingActionPayload;
|
|
35
35
|
|
|
36
|
+
interface BillingSubscriptionCatalogItemInput<TSource = unknown> {
|
|
37
|
+
source: TSource;
|
|
38
|
+
key: string;
|
|
39
|
+
title: string;
|
|
40
|
+
description?: string;
|
|
41
|
+
productId: string;
|
|
42
|
+
planId?: string;
|
|
43
|
+
priceId?: string;
|
|
44
|
+
interval?: BillingInterval;
|
|
45
|
+
featured?: boolean;
|
|
46
|
+
badge?: string;
|
|
47
|
+
priceLabel?: string;
|
|
48
|
+
priceValue?: number;
|
|
49
|
+
features?: string[];
|
|
50
|
+
metadata?: Record<string, string>;
|
|
51
|
+
}
|
|
52
|
+
interface BillingSubscriptionCatalogBuilderOptions<TSource = unknown> {
|
|
53
|
+
catalogKey: string;
|
|
54
|
+
title?: string;
|
|
55
|
+
description?: string;
|
|
56
|
+
portalPath?: string;
|
|
57
|
+
successPath?: string;
|
|
58
|
+
cancelPath?: string;
|
|
59
|
+
purchasableIds?: string[];
|
|
60
|
+
defaults?: BillingDefaults;
|
|
61
|
+
mapPlan: (plan: TSource, index: number) => BillingSubscriptionCatalogItemInput<TSource>;
|
|
62
|
+
}
|
|
63
|
+
declare function buildBillingSubscriptionCatalog<TSource>(plans: readonly TSource[], options: BillingSubscriptionCatalogBuilderOptions<TSource>): BillingCatalogConfig;
|
|
64
|
+
|
|
36
65
|
interface NormalizedCasdoorProductId {
|
|
37
66
|
owner: string;
|
|
38
67
|
name: string;
|
|
@@ -50,4 +79,4 @@ declare function createBillingPaymentSuccessRouteHandler(options?: BillingPaymen
|
|
|
50
79
|
declare function createBillingPaymentFinishedResponse(request: Request, options?: BillingPaymentFinishedRouteOptions): Promise<Response>;
|
|
51
80
|
declare function createBillingPaymentFinishedRouteHandler(options?: BillingPaymentFinishedRouteOptions): (request: Request) => Promise<Response>;
|
|
52
81
|
|
|
53
|
-
export { BillingActionExecutionResult, BillingActionPayload, BillingCasdoorBuyProductRequest, BillingCasdoorBuyProductResponse, BillingCasdoorOrderDetail, BillingCasdoorProductDetail, BillingCasdoorSubscriptionDetail, BillingCatalogConfig, BillingCreditsState, BillingEntitlementState, BillingInterval, BillingItem, BillingOrderHistoryItem, BillingPaymentCallbackContext, BillingPaymentFinishedRouteOptions, BillingPaymentHistoryItem, BillingPaymentSuccessRouteOptions, BillingProductSnapshot, BillingProductState, BillingPurchasableEntry, BillingPurchaseRequest, BillingPurchaseStatus, BillingRuntimeConfig, BillingSubscriptionHistoryItem, BillingSubscriptionState, type NormalizedCasdoorProductId, buildBillingActionPayload, buildBillingPaymentCallbackContext, buildBillingPurchaseRequest, buildCasdoorBuyProductParams, buildCasdoorBuyProductRequest, chooseCasdoorProviderName, createBillingPaymentFinishedResponse, createBillingPaymentFinishedRouteHandler, createBillingPaymentSuccessResponse, createBillingPaymentSuccessRouteHandler, deriveBillingCreditsState, deriveBillingEntitlements, filterBillingPurchasableItems, normalizeBillingCatalogConfig, normalizeBillingPurchaseStatus, normalizeBillingRuntimeConfig, normalizeCasdoorBuyProductResponse, normalizeCasdoorOrderHistoryItem, normalizeCasdoorPaymentHistoryItem, normalizeCasdoorProductId, normalizeCasdoorSubscriptionDetail, normalizeCasdoorSubscriptionHistoryItem, readBuyProductRedirectTo, resolveBillingInterval, resolveBillingItem, resolveBillingProductSnapshot, resolveBillingPurchasable, resolveBillingSubscriptionProduct };
|
|
82
|
+
export { BillingActionExecutionResult, BillingActionPayload, BillingCasdoorBuyProductRequest, BillingCasdoorBuyProductResponse, BillingCasdoorOrderDetail, BillingCasdoorProductDetail, BillingCasdoorSubscriptionDetail, BillingCatalogConfig, BillingCreditsState, BillingDefaults, BillingEntitlementState, BillingInterval, BillingItem, BillingOrderHistoryItem, BillingPaymentCallbackContext, BillingPaymentFinishedRouteOptions, BillingPaymentHistoryItem, BillingPaymentSuccessRouteOptions, BillingProductSnapshot, BillingProductState, BillingPurchasableEntry, BillingPurchaseRequest, BillingPurchaseStatus, BillingRuntimeConfig, type BillingSubscriptionCatalogBuilderOptions, type BillingSubscriptionCatalogItemInput, BillingSubscriptionHistoryItem, BillingSubscriptionState, type NormalizedCasdoorProductId, buildBillingActionPayload, buildBillingPaymentCallbackContext, buildBillingPurchaseRequest, buildBillingSubscriptionCatalog, buildCasdoorBuyProductParams, buildCasdoorBuyProductRequest, chooseCasdoorProviderName, createBillingPaymentFinishedResponse, createBillingPaymentFinishedRouteHandler, createBillingPaymentSuccessResponse, createBillingPaymentSuccessRouteHandler, deriveBillingCreditsState, deriveBillingEntitlements, filterBillingPurchasableItems, normalizeBillingCatalogConfig, normalizeBillingPurchaseStatus, normalizeBillingRuntimeConfig, normalizeCasdoorBuyProductResponse, normalizeCasdoorOrderHistoryItem, normalizeCasdoorPaymentHistoryItem, normalizeCasdoorProductId, normalizeCasdoorSubscriptionDetail, normalizeCasdoorSubscriptionHistoryItem, readBuyProductRedirectTo, resolveBillingInterval, resolveBillingItem, resolveBillingProductSnapshot, resolveBillingPurchasable, resolveBillingSubscriptionProduct };
|
package/dist/billing/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
+
buildBillingSubscriptionCatalog,
|
|
2
3
|
createBillingPaymentFinishedResponse,
|
|
3
4
|
createBillingPaymentFinishedRouteHandler,
|
|
4
5
|
createBillingPaymentSuccessResponse,
|
|
5
6
|
createBillingPaymentSuccessRouteHandler
|
|
6
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-PILMR42A.js";
|
|
7
8
|
import {
|
|
8
9
|
buildBillingActionPayload,
|
|
9
10
|
buildBillingPaymentCallbackContext,
|
|
@@ -34,6 +35,7 @@ export {
|
|
|
34
35
|
buildBillingActionPayload,
|
|
35
36
|
buildBillingPaymentCallbackContext,
|
|
36
37
|
buildBillingPurchaseRequest,
|
|
38
|
+
buildBillingSubscriptionCatalog,
|
|
37
39
|
buildCasdoorBuyProductParams,
|
|
38
40
|
buildCasdoorBuyProductRequest,
|
|
39
41
|
chooseCasdoorProviderName,
|
|
@@ -2,6 +2,44 @@ import {
|
|
|
2
2
|
buildBillingPaymentCallbackContext
|
|
3
3
|
} from "./chunk-FL6LOXEG.js";
|
|
4
4
|
|
|
5
|
+
// src/billing/subscription-catalog.ts
|
|
6
|
+
function buildBillingSubscriptionCatalog(plans, options) {
|
|
7
|
+
const items = plans.map((plan, index) => {
|
|
8
|
+
const mapped = options.mapPlan(plan, index);
|
|
9
|
+
return {
|
|
10
|
+
key: mapped.key,
|
|
11
|
+
kind: "subscription",
|
|
12
|
+
title: mapped.title,
|
|
13
|
+
description: mapped.description,
|
|
14
|
+
featured: mapped.featured,
|
|
15
|
+
badge: mapped.badge,
|
|
16
|
+
priceLabel: mapped.priceLabel,
|
|
17
|
+
priceValue: mapped.priceValue,
|
|
18
|
+
interval: mapped.interval,
|
|
19
|
+
features: mapped.features,
|
|
20
|
+
backendRef: {
|
|
21
|
+
productId: mapped.productId,
|
|
22
|
+
planId: mapped.planId,
|
|
23
|
+
priceId: mapped.priceId
|
|
24
|
+
},
|
|
25
|
+
metadata: mapped.metadata
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
return {
|
|
29
|
+
catalogKey: options.catalogKey,
|
|
30
|
+
title: options.title,
|
|
31
|
+
description: options.description,
|
|
32
|
+
portalPath: options.portalPath,
|
|
33
|
+
successPath: options.successPath,
|
|
34
|
+
cancelPath: options.cancelPath,
|
|
35
|
+
purchasableIds: options.purchasableIds ?? items.map((item) => item.key),
|
|
36
|
+
purchasables: [],
|
|
37
|
+
conversionRules: [],
|
|
38
|
+
defaults: options.defaults ?? {},
|
|
39
|
+
items
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
5
43
|
// src/billing/payment-route.ts
|
|
6
44
|
import { NextResponse } from "next/server";
|
|
7
45
|
|
|
@@ -134,9 +172,10 @@ function createBillingPaymentFinishedRouteHandler(options = {}) {
|
|
|
134
172
|
}
|
|
135
173
|
|
|
136
174
|
export {
|
|
175
|
+
buildBillingSubscriptionCatalog,
|
|
137
176
|
createBillingPaymentSuccessResponse,
|
|
138
177
|
createBillingPaymentSuccessRouteHandler,
|
|
139
178
|
createBillingPaymentFinishedResponse,
|
|
140
179
|
createBillingPaymentFinishedRouteHandler
|
|
141
180
|
};
|
|
142
|
-
//# sourceMappingURL=chunk-
|
|
181
|
+
//# sourceMappingURL=chunk-PILMR42A.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/billing/subscription-catalog.ts","../src/billing/payment-route.ts","../src/core/origin.ts","../src/billing/payment-success.ts","../src/billing/payment-finished.ts"],"sourcesContent":["import type {\n BillingCatalogConfig,\n BillingDefaults,\n BillingInterval,\n BillingItem,\n} from './types';\n\nexport interface BillingSubscriptionCatalogItemInput<TSource = unknown> {\n source: TSource;\n key: string;\n title: string;\n description?: string;\n productId: string;\n planId?: string;\n priceId?: string;\n interval?: BillingInterval;\n featured?: boolean;\n badge?: string;\n priceLabel?: string;\n priceValue?: number;\n features?: string[];\n metadata?: Record<string, string>;\n}\n\nexport interface BillingSubscriptionCatalogBuilderOptions<TSource = unknown> {\n catalogKey: string;\n title?: string;\n description?: string;\n portalPath?: string;\n successPath?: string;\n cancelPath?: string;\n purchasableIds?: string[];\n defaults?: BillingDefaults;\n mapPlan: (plan: TSource, index: number) => BillingSubscriptionCatalogItemInput<TSource>;\n}\n\nexport function buildBillingSubscriptionCatalog<TSource>(\n plans: readonly TSource[],\n options: BillingSubscriptionCatalogBuilderOptions<TSource>,\n): BillingCatalogConfig {\n const items = plans.map((plan, index) => {\n const mapped = options.mapPlan(plan, index);\n\n return {\n key: mapped.key,\n kind: 'subscription',\n title: mapped.title,\n description: mapped.description,\n featured: mapped.featured,\n badge: mapped.badge,\n priceLabel: mapped.priceLabel,\n priceValue: mapped.priceValue,\n interval: mapped.interval,\n features: mapped.features,\n backendRef: {\n productId: mapped.productId,\n planId: mapped.planId,\n priceId: mapped.priceId,\n },\n metadata: mapped.metadata,\n } satisfies BillingItem;\n });\n\n return {\n catalogKey: options.catalogKey,\n title: options.title,\n description: options.description,\n portalPath: options.portalPath,\n successPath: options.successPath,\n cancelPath: options.cancelPath,\n purchasableIds: options.purchasableIds ?? items.map((item) => item.key),\n purchasables: [],\n conversionRules: [],\n defaults: options.defaults ?? {},\n items,\n };\n}\n","import { NextResponse } from 'next/server';\n\nimport { resolvePublicOrigin } from '../core/origin';\nimport { buildBillingPaymentCallbackContext } from './runtime';\nimport type {\n BillingPaymentRouteBaseOptions,\n BillingPaymentFinishedRouteOptions,\n BillingPaymentFinishedContext,\n BillingPaymentFinishedHandler,\n BillingPaymentSuccessContext,\n BillingPaymentSuccessHandlerResult,\n BillingPaymentSuccessRouteOptions,\n} from './types';\n\nexport interface BillingPaymentRouteOptions extends BillingPaymentRouteBaseOptions {\n routePath: string;\n missingHandlerFile: string;\n handler?: BillingPaymentSuccessRouteOptions['handler'] | BillingPaymentFinishedRouteOptions['handler'];\n phase?: 'success' | 'failure' | 'finished';\n}\n\nfunction sanitizeRedirectPath(value: string | null | undefined, fallback: string): string {\n if (!value || !value.startsWith('/') || value.startsWith('//')) {\n return fallback;\n }\n\n return value;\n}\n\nfunction isDebugEnabled(): boolean {\n const value = process.env.BILLING_PAYMENT_SUCCESS_DEBUG;\n if (!value) {\n return false;\n }\n\n return ['1', 'true', 'yes', 'on'].includes(value.toLowerCase());\n}\n\nfunction resolveRedirectTarget(\n result: BillingPaymentSuccessHandlerResult | undefined,\n context: BillingPaymentSuccessContext,\n fallbackRedirect: string,\n): string {\n if (typeof result === 'string') {\n return sanitizeRedirectPath(result, fallbackRedirect);\n }\n\n if (result && typeof result === 'object' && 'redirectTo' in result) {\n return sanitizeRedirectPath(result.redirectTo ?? null, fallbackRedirect);\n }\n\n return sanitizeRedirectPath(context.redirectTo, fallbackRedirect);\n}\n\nfunction resolveFallbackTarget(fallbackRedirect: string): string {\n return sanitizeRedirectPath(fallbackRedirect, '/');\n}\n\nfunction logMissingPaymentHandler(\n context: BillingPaymentSuccessContext,\n fallbackRedirect: string,\n missingHandlerFile: string,\n routePath: string,\n): void {\n console.warn(\n `[casdoor-next-auth-kit] default billing handler at ${missingHandlerFile} has no business logic. ` +\n `Edit this file to handle ${routePath} with order/payment enrichment before redirecting. ` +\n `Falling back to ${fallbackRedirect}.`,\n {\n paymentOwner: context.paymentOwner,\n paymentName: context.paymentName,\n paymentId: context.paymentId,\n orderId: context.orderId,\n params: context.params,\n },\n );\n}\n\nexport async function createBillingPaymentRouteResponse(\n request: Request,\n options: BillingPaymentRouteOptions,\n) {\n const origin = resolvePublicOrigin(request, options.appUrl);\n const fallbackRedirect = options.fallbackRedirect ?? '/';\n const context = await buildBillingPaymentCallbackContext(request, options.phase);\n\n if (isDebugEnabled()) {\n console.info(`[casdoor-next-auth-kit] ${options.routePath} request`, {\n method: request.method,\n path: context.url.pathname,\n query: context.params,\n body: context.body,\n });\n }\n\n try {\n if (options.handler) {\n const handler = options.handler;\n const result =\n options.phase === 'finished'\n ? await (handler as BillingPaymentFinishedHandler)(context as BillingPaymentFinishedContext)\n : await (handler as NonNullable<BillingPaymentSuccessRouteOptions['handler']>)(context);\n if (result instanceof Response) {\n return result;\n }\n\n const target = resolveRedirectTarget(result, context, fallbackRedirect);\n return NextResponse.redirect(new URL(target, origin), 307);\n }\n\n logMissingPaymentHandler(context, fallbackRedirect, options.missingHandlerFile, options.routePath);\n const target = resolveFallbackTarget(fallbackRedirect);\n return NextResponse.redirect(new URL(target, origin), 307);\n } catch (error) {\n console.error(`[casdoor-next-auth-kit] ${options.routePath} handler failed:`, error);\n return new NextResponse('Billing payment handler failed', { status: 500 });\n }\n}\n","export function normalizeOrigin(value: string | null | undefined): string | null {\n if (!value) return null;\n try {\n return new URL(value).origin;\n } catch {\n return null;\n }\n}\n\nexport function getRequestOrigin(request: Request, appUrl?: string): string {\n const configured = normalizeOrigin(appUrl);\n if (configured) return configured;\n\n const referer = normalizeOrigin(request.headers.get('referer'));\n if (referer) return referer;\n\n const origin = normalizeOrigin(request.headers.get('origin'));\n if (origin) return origin;\n\n const forwardedProto = request.headers.get('x-forwarded-proto')?.split(',')[0]?.trim();\n const forwardedHost = request.headers.get('x-forwarded-host')?.split(',')[0]?.trim();\n if (forwardedProto && forwardedHost) {\n return forwardedProto + '://' + forwardedHost;\n }\n\n return new URL(request.url).origin;\n}\n\nexport function resolvePublicOrigin(request: Request, appUrl?: string): string {\n return getRequestOrigin(request, appUrl);\n}\n","import type { BillingPaymentSuccessHandler, BillingPaymentSuccessRouteOptions } from './types';\nimport { createBillingPaymentRouteResponse } from './payment-route';\n\nexport async function createBillingPaymentSuccessResponse(\n request: Request,\n options: BillingPaymentSuccessRouteOptions = {},\n) {\n return createBillingPaymentRouteResponse(request, {\n ...options,\n routePath: '/auth/payment/success',\n missingHandlerFile: 'lib/billing/payment-success.ts',\n fallbackRedirect: options.fallbackRedirect ?? '/auth/payment/finished',\n phase: options.phase ?? 'success',\n });\n}\n\nexport function createBillingPaymentSuccessRouteHandler(options: BillingPaymentSuccessRouteOptions = {}) {\n return async function GET(request: Request) {\n return createBillingPaymentSuccessResponse(request, options);\n };\n}\n\nexport type { BillingPaymentSuccessHandler };\n","import type { BillingPaymentFinishedHandler, BillingPaymentFinishedRouteOptions } from './types';\nimport { createBillingPaymentRouteResponse } from './payment-route';\n\nexport async function createBillingPaymentFinishedResponse(\n request: Request,\n options: BillingPaymentFinishedRouteOptions = {},\n) {\n return createBillingPaymentRouteResponse(request, {\n ...options,\n routePath: '/auth/payment/finished',\n missingHandlerFile: 'lib/billing/payment-finished.ts',\n fallbackRedirect: options.fallbackRedirect ?? '/',\n phase: options.phase ?? 'finished',\n });\n}\n\nexport function createBillingPaymentFinishedRouteHandler(options: BillingPaymentFinishedRouteOptions = {}) {\n return async function GET(request: Request) {\n return createBillingPaymentFinishedResponse(request, options);\n };\n}\n\nexport type { BillingPaymentFinishedHandler };\n"],"mappings":";;;;;AAoCO,SAAS,gCACd,OACA,SACsB;AACtB,QAAM,QAAQ,MAAM,IAAI,CAAC,MAAM,UAAU;AACvC,UAAM,SAAS,QAAQ,QAAQ,MAAM,KAAK;AAE1C,WAAO;AAAA,MACL,KAAK,OAAO;AAAA,MACZ,MAAM;AAAA,MACN,OAAO,OAAO;AAAA,MACd,aAAa,OAAO;AAAA,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,SAAkB;AAC1C,WAAO,oCAAoC,SAAS,OAAO;AAAA,EAC7D;AACF;;;ACjBA,eAAsB,qCACpB,SACA,UAA8C,CAAC,GAC/C;AACA,SAAO,kCAAkC,SAAS;AAAA,IAChD,GAAG;AAAA,IACH,WAAW;AAAA,IACX,oBAAoB;AAAA,IACpB,kBAAkB,QAAQ,oBAAoB;AAAA,IAC9C,OAAO,QAAQ,SAAS;AAAA,EAC1B,CAAC;AACH;AAEO,SAAS,yCAAyC,UAA8C,CAAC,GAAG;AACzG,SAAO,eAAe,IAAI,SAAkB;AAC1C,WAAO,qCAAqC,SAAS,OAAO;AAAA,EAC9D;AACF;","names":["target"]}
|
|
@@ -88,9 +88,9 @@ var AUTH_KIT_ENV_VARIABLES = [
|
|
|
88
88
|
{
|
|
89
89
|
key: "NEXT_PUBLIC_BILLING_PURCHASABLE_IDS",
|
|
90
90
|
description: "Billing \u53EF\u8D2D\u4E70\u9879\u767D\u540D\u5355\uFF0C\u9017\u53F7\u5206\u9694",
|
|
91
|
-
example: "
|
|
92
|
-
local: "
|
|
93
|
-
production: "
|
|
91
|
+
example: "membership-monthly,credits-50",
|
|
92
|
+
local: "membership-monthly,credits-50",
|
|
93
|
+
production: "membership-monthly,credits-50"
|
|
94
94
|
},
|
|
95
95
|
{
|
|
96
96
|
key: "NEXT_PUBLIC_CASDOOR_STATIC_ORIGIN",
|
|
@@ -329,4 +329,4 @@ export {
|
|
|
329
329
|
AUTH_PRISMA_SCHEMA_MODELS,
|
|
330
330
|
buildAuthPrismaSchemaTemplate
|
|
331
331
|
};
|
|
332
|
-
//# sourceMappingURL=chunk-
|
|
332
|
+
//# sourceMappingURL=chunk-SZVWLQQT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/env.ts","../src/prisma/schema-template.ts"],"sourcesContent":["import type { ManagedEnvFile, ManagedEnvVariableDefinition } from '../types';\n\nexport const AUTH_KIT_ENV_FILES: ManagedEnvFile[] = ['.env', '.env.local', '.env.production', '.env.example'];\n\nexport const AUTH_KIT_ENV_VARIABLES: ManagedEnvVariableDefinition[] = [\n {\n key: 'APP_URL',\n description: '站点对外公开地址',\n example: 'https://your-domain.com',\n local: 'http://localhost:5177',\n production: 'https://your-domain.com',\n },\n {\n key: 'NEXTAUTH_URL',\n description: 'NextAuth 回调地址',\n example: 'http://localhost:5177',\n local: 'http://localhost:5177',\n production: 'https://your-domain.com',\n },\n {\n key: 'NEXTAUTH_SECRET',\n description: 'NextAuth JWT secret',\n example: 'replace-with-a-random-secret',\n local: 'replace-with-a-random-secret',\n production: 'replace-with-a-random-secret',\n },\n {\n key: 'GLOBAL_ADMIN_EMAILS',\n description: '全局管理员邮箱,逗号分隔',\n example: 'admin@example.com',\n local: 'admin@example.com',\n production: 'admin@example.com',\n },\n {\n key: 'AUTH_DEBUG',\n description: '是否开启认证调试日志',\n example: 'false',\n local: 'false',\n production: 'false',\n },\n {\n key: 'NEXT_PUBLIC_CASDOOR_SERVER_URL',\n description: 'Casdoor 服务地址',\n example: 'https://auth.example.com',\n local: 'https://auth.example.com',\n production: 'https://auth.example.com',\n },\n {\n key: 'NEXT_PUBLIC_CASDOOR_CLIENT_ID',\n description: 'Casdoor client id',\n example: 'your-casdoor-client-id',\n local: 'your-casdoor-client-id',\n production: 'your-casdoor-client-id',\n },\n {\n key: 'NEXT_PUBLIC_CASDOOR_APP_NAME',\n description: 'Casdoor app name',\n example: 'your-app-name',\n local: 'your-app-name',\n production: 'your-app-name',\n },\n {\n key: 'NEXT_PUBLIC_CASDOOR_ORGANIZATION_NAME',\n description: 'Casdoor organization name',\n example: 'your-org-name',\n local: 'your-org-name',\n production: 'your-org-name',\n },\n {\n key: 'NEXT_PUBLIC_CASDOOR_REDIRECT_PATH',\n description: 'Casdoor OAuth 回调路径',\n example: '/callback',\n local: '/callback',\n production: '/callback',\n },\n {\n key: 'NEXT_PUBLIC_CASDOOR_SIGNIN_PATH',\n description: 'Casdoor authorize 路径',\n example: '/login/oauth/authorize',\n local: '/login/oauth/authorize',\n production: '/login/oauth/authorize',\n },\n {\n key: 'NEXT_PUBLIC_AUTH_LOGOUT_REDIRECT_PATH',\n description: '注销后跳转路径,默认首页',\n example: '/',\n local: '/',\n production: '/',\n },\n {\n key: 'NEXT_PUBLIC_BILLING_PURCHASABLE_IDS',\n description: 'Billing 可购买项白名单,逗号分隔',\n example: 'membership-monthly,credits-50',\n local: 'membership-monthly,credits-50',\n production: 'membership-monthly,credits-50',\n },\n {\n key: 'NEXT_PUBLIC_CASDOOR_STATIC_ORIGIN',\n description: 'Casdoor 静态资源 origin',\n example: 'https://casdoor-static.foldspace.cn',\n local: 'https://casdoor-static.foldspace.cn',\n production: 'https://casdoor-static.foldspace.cn',\n },\n {\n key: 'CASDOOR_CLIENT_SECRET',\n description: 'Casdoor client secret',\n example: 'your-casdoor-client-secret',\n local: 'your-casdoor-client-secret',\n production: 'your-casdoor-client-secret',\n },\n {\n key: 'BILLING_PAYMENT_SUCCESS_DEBUG',\n description: '是否打印 payment-success 调试日志',\n example: 'false',\n local: 'false',\n production: 'false',\n },\n];\n\nfunction stringifyEnvValue(value: string): string {\n if (value === '') {\n return '\"\"';\n }\n\n if (/^[A-Za-z0-9_./:-]+$/.test(value)) {\n return value;\n }\n\n return JSON.stringify(value);\n}\n\nfunction stripQuotes(value: string): string {\n const trimmed = value.trim();\n if (\n (trimmed.startsWith('\"') && trimmed.endsWith('\"')) ||\n (trimmed.startsWith(\"'\") && trimmed.endsWith(\"'\"))\n ) {\n return trimmed.slice(1, -1);\n }\n\n return trimmed;\n}\n\nfunction parseEnvKeys(content: string): Set<string> {\n const keys = new Set<string>();\n for (const line of content.split(/\\r?\\n/)) {\n const trimmed = line.trim();\n if (!trimmed || trimmed.startsWith('#')) {\n continue;\n }\n\n const separatorIndex = trimmed.indexOf('=');\n if (separatorIndex === -1) {\n continue;\n }\n\n const key = trimmed.slice(0, separatorIndex).trim();\n if (key) {\n keys.add(key);\n }\n }\n return keys;\n}\n\nexport function readManagedEnvValue(content: string, key: string): string | null {\n for (const line of content.split(/\\r?\\n/)) {\n const trimmed = line.trim();\n if (!trimmed || trimmed.startsWith('#')) {\n continue;\n }\n\n const separatorIndex = trimmed.indexOf('=');\n if (separatorIndex === -1) {\n continue;\n }\n\n const currentKey = trimmed.slice(0, separatorIndex).trim();\n if (currentKey !== key) {\n continue;\n }\n\n const rawValue = trimmed.slice(separatorIndex + 1).trim();\n return stripQuotes(rawValue);\n }\n\n return null;\n}\n\nexport function getManagedEnvValue(definition: ManagedEnvVariableDefinition, file: ManagedEnvFile): string {\n if (file === '.env.example') {\n return definition.example;\n }\n if (file === '.env.production') {\n return definition.production ?? definition.example;\n }\n if (file === '.env.local') {\n return definition.local ?? definition.example;\n }\n return definition.base ?? definition.local ?? definition.production ?? definition.example;\n}\n\nexport function buildManagedEnvTemplate(file: ManagedEnvFile, existingContent = ''): string {\n const existingKeys = parseEnvKeys(existingContent);\n const lines: string[] = existingContent.trimEnd() ? existingContent.trimEnd().split(/\\r?\\n/) : [];\n const missing = AUTH_KIT_ENV_VARIABLES.filter((definition) => !existingKeys.has(definition.key));\n\n if (missing.length === 0 && existingContent) {\n return existingContent;\n }\n\n if (lines.length > 0) {\n lines.push('');\n }\n\n lines.push(`# Casdoor Next Auth Kit managed values for ${file}`);\n for (const definition of missing) {\n const value = getManagedEnvValue(definition, file);\n lines.push(`# ${definition.description}`);\n lines.push(`${definition.key}=${stringifyEnvValue(value)}`);\n lines.push('');\n }\n\n while (lines.length > 0 && lines[lines.length - 1] === '') {\n lines.pop();\n }\n\n return `${lines.join('\\n')}\\n`;\n}\n\nexport function getMissingManagedEnvKeys(content: string): string[] {\n const existingKeys = parseEnvKeys(content);\n return AUTH_KIT_ENV_VARIABLES.filter((definition) => !existingKeys.has(definition.key)).map(\n (definition) => definition.key,\n );\n}\n\nexport function sanitizeExistingEnvContent(content: string): string {\n return stripQuotes(content);\n}\n","import type { PrismaSchemaFieldDefinition, PrismaSchemaModelDefinition } from '../types';\n\nexport const AUTH_PRISMA_SCHEMA_MODELS: PrismaSchemaModelDefinition[] = [\n {\n name: 'AuthUser',\n description: 'Shared authentication user record',\n fields: [\n { name: 'id', type: 'String', attributes: ['@id', '@default(cuid())'] },\n { name: 'email', type: 'String?', attributes: ['@unique'] },\n { name: 'name', type: 'String?' },\n { name: 'image', type: 'String?' },\n { name: 'isAdmin', type: 'Boolean', attributes: ['@default(false)'] },\n { name: 'tokenBalance', type: 'Int', attributes: ['@default(0)'] },\n { name: 'isVip', type: 'Boolean', attributes: ['@default(false)'] },\n { name: 'createdAt', type: 'DateTime', attributes: ['@default(now())'] },\n { name: 'updatedAt', type: 'DateTime', attributes: ['@updatedAt'] },\n ],\n blockAttributes: ['@@index([email])'],\n },\n {\n name: 'AuthMembership',\n description: 'Subscription membership snapshot',\n fields: [\n { name: 'id', type: 'String', attributes: ['@id', '@default(cuid())'] },\n { name: 'userId', type: 'String', attributes: ['@unique'] },\n { name: 'plan', type: 'String' },\n { name: 'status', type: 'String' },\n { name: 'startsAt', type: 'DateTime?' },\n { name: 'endsAt', type: 'DateTime?' },\n { name: 'createdAt', type: 'DateTime', attributes: ['@default(now())'] },\n { name: 'updatedAt', type: 'DateTime', attributes: ['@updatedAt'] },\n ],\n blockAttributes: ['@@index([userId])'],\n },\n {\n name: 'AuthOrder',\n description: 'Commerce order record',\n fields: [\n { name: 'id', type: 'String', attributes: ['@id', '@default(cuid())'] },\n { name: 'userId', type: 'String' },\n { name: 'kind', type: 'String' },\n { name: 'status', type: 'String' },\n { name: 'amount', type: 'Int' },\n { name: 'currency', type: 'String', attributes: ['@default(\"CNY\")'] },\n { name: 'payload', type: 'Json?' },\n { name: 'createdAt', type: 'DateTime', attributes: ['@default(now())'] },\n { name: 'updatedAt', type: 'DateTime', attributes: ['@updatedAt'] },\n ],\n blockAttributes: ['@@index([userId])'],\n },\n {\n name: 'AuthSubscription',\n description: 'Commerce subscription record',\n fields: [\n { name: 'id', type: 'String', attributes: ['@id', '@default(cuid())'] },\n { name: 'userId', type: 'String' },\n { name: 'productId', type: 'String' },\n { name: 'status', type: 'String' },\n { name: 'interval', type: 'String' },\n { name: 'startsAt', type: 'DateTime?' },\n { name: 'endsAt', type: 'DateTime?' },\n { name: 'createdAt', type: 'DateTime', attributes: ['@default(now())'] },\n { name: 'updatedAt', type: 'DateTime', attributes: ['@updatedAt'] },\n ],\n blockAttributes: ['@@index([userId])', '@@index([productId])'],\n },\n {\n name: 'AuthInvoice',\n description: 'Commerce invoice record',\n fields: [\n { name: 'id', type: 'String', attributes: ['@id', '@default(cuid())'] },\n { name: 'userId', type: 'String' },\n { name: 'orderId', type: 'String?' },\n { name: 'invoiceNo', type: 'String', attributes: ['@unique'] },\n { name: 'status', type: 'String' },\n { name: 'amount', type: 'Int' },\n { name: 'createdAt', type: 'DateTime', attributes: ['@default(now())'] },\n { name: 'updatedAt', type: 'DateTime', attributes: ['@updatedAt'] },\n ],\n blockAttributes: ['@@index([userId])', '@@index([orderId])'],\n },\n];\n\nfunction renderField(field: PrismaSchemaFieldDefinition): string {\n const attributes = field.attributes?.length ? ` ${field.attributes.join(' ')}` : '';\n return ` ${field.name} ${field.type}${attributes}`;\n}\n\nfunction renderModel(model: PrismaSchemaModelDefinition): string {\n const lines = [\n `/// ${model.description}`,\n `model ${model.name} {`,\n ...model.fields.map(renderField),\n ];\n\n if (model.blockAttributes?.length) {\n lines.push(...model.blockAttributes.map((attribute) => ` ${attribute}`));\n }\n\n lines.push('}');\n return lines.join('\\n');\n}\n\nexport function buildAuthPrismaSchemaTemplate(models: PrismaSchemaModelDefinition[] = AUTH_PRISMA_SCHEMA_MODELS): string {\n return [\n '// generated by @foldspace-fe/casdoor-next-auth-kit',\n '// merge these models into the host Prisma schema if you want a dedicated auth module',\n '',\n ...models.map(renderModel),\n ].join('\\n\\n');\n}\n"],"mappings":";AAEO,IAAM,qBAAuC,CAAC,QAAQ,cAAc,mBAAmB,cAAc;AAErG,IAAM,yBAAyD;AAAA,EACpE;AAAA,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Aa,MAAM,YAAY,SAAS,IAAI,MAAM,WAAW,KAAK,GAAG,CAAC,KAAK;AACjF,SAAO,KAAK,MAAM,IAAI,IAAI,MAAM,IAAI,GAAG,UAAU;AACnD;AAEA,SAAS,YAAY,OAA4C;AAC/D,QAAM,QAAQ;AAAA,IACZ,OAAO,MAAM,WAAW;AAAA,IACxB,SAAS,MAAM,IAAI;AAAA,IACnB,GAAG,MAAM,OAAO,IAAI,WAAW;AAAA,EACjC;AAEA,MAAI,MAAM,iBAAiB,QAAQ;AACjC,UAAM,KAAK,GAAG,MAAM,gBAAgB,IAAI,CAAC,cAAc,KAAK,SAAS,EAAE,CAAC;AAAA,EAC1E;AAEA,QAAM,KAAK,GAAG;AACd,SAAO,MAAM,KAAK,IAAI;AACxB;AAEO,SAAS,8BAA8B,SAAwC,2BAAmC;AACvH,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG,OAAO,IAAI,WAAW;AAAA,EAC3B,EAAE,KAAK,MAAM;AACf;","names":[]}
|
package/dist/cli.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export { C as CallbackHandlerOptions, c as createCallbackHandler, a as createCal
|
|
|
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-D2YQdRWu.js';
|
|
8
8
|
export { z as BillingActionExecutionResult, f as BillingActionExecutor, A as BillingActionKind, B as BillingActionPayload, d as BillingApiClient, C as BillingCasdoorAccountDetail, D as BillingCasdoorAccountMultiFactorAuthDetail, E as BillingCasdoorAccountResponse, F as BillingCasdoorApiResponse, G as BillingCasdoorApplicationDetail, H as BillingCasdoorApplicationProviderDetail, I as BillingCasdoorApplicationResponse, J as BillingCasdoorApplicationSigninItemDetail, K as BillingCasdoorApplicationSigninMethodDetail, L as BillingCasdoorApplicationSignupItemDetail, M as BillingCasdoorBuyProductRequest, N as BillingCasdoorBuyProductResponse, O as BillingCasdoorErrorDetail, P as BillingCasdoorErrorPayload, t as BillingCasdoorOrderDetail, Q as BillingCasdoorOrderResponse, R as BillingCasdoorOrdersResponse, S as BillingCasdoorOrganizationDetail, T as BillingCasdoorOrganizationNamesResponse, U as BillingCasdoorOrganizationOption, V as BillingCasdoorPaymentDetail, W as BillingCasdoorPaymentResponse, u as BillingCasdoorPlanDetail, X as BillingCasdoorPlanResponse, v as BillingCasdoorPricingDetail, Y as BillingCasdoorPricingResponse, w as BillingCasdoorProductDetail, Z as BillingCasdoorProductResponse, _ as BillingCasdoorProviderDetail, $ as BillingCasdoorProviderOption, s as BillingCasdoorQueryState, x as BillingCasdoorSubscriptionDetail, a0 as BillingCasdoorSubscriptionResponse, a1 as BillingCasdoorSubscriptionsResponse, c as BillingCatalogConfig, a2 as BillingConversionRule, y as BillingCoreContextValue, a3 as BillingCreditsContextValue, m as BillingCreditsState, g as BillingDefaults, n as BillingEntitlementState, a4 as BillingInterval, a as BillingItem, a5 as BillingItemKind, e as BillingLoaders, a6 as BillingOrderCreatedContext, k as BillingOrderHistoryItem, a7 as BillingPaymentCallbackContext, a8 as BillingPaymentFinishedContext, a9 as BillingPaymentFinishedHandler, aa as BillingPaymentFinishedRouteOptions, l as BillingPaymentHistoryItem, ab as BillingPaymentRouteBaseOptions, ac as BillingPaymentSuccessContext, ad as BillingPaymentSuccessHandler, ae as BillingPaymentSuccessHandlerResult, af as BillingPaymentSuccessRouteOptions, ag as BillingProductContextValue, ah as BillingProductDetailState, ai as BillingProductPurchasableEntry, aj as BillingProductPurchaseConfig, r as BillingProductSnapshot, j as BillingProductState, ak as BillingPurchasableEntry, al as BillingPurchasableEntryBase, am as BillingPurchasableKind, an as BillingPurchasableWhitelist, ao as BillingPurchaseCompleteContext, ap as BillingPurchaseErrorContext, q as BillingPurchaseHooks, aq as BillingPurchaseRequest, p as BillingPurchaseStatus, b as BillingRuntimeConfig, o as BillingStatusState, ar as BillingSubscriptionContextValue, i as BillingSubscriptionHistoryItem, as as BillingSubscriptionPurchasableEntry, at as BillingSubscriptionPurchaseConfig, h as BillingSubscriptionState } from './types-oVIQpMut.js';
|
|
9
|
-
export { NormalizedCasdoorProductId, buildBillingActionPayload, buildBillingPaymentCallbackContext, buildBillingPurchaseRequest, buildCasdoorBuyProductParams, buildCasdoorBuyProductRequest, chooseCasdoorProviderName, createBillingPaymentFinishedResponse, createBillingPaymentFinishedRouteHandler, createBillingPaymentSuccessResponse, createBillingPaymentSuccessRouteHandler, deriveBillingCreditsState, deriveBillingEntitlements, filterBillingPurchasableItems, normalizeBillingCatalogConfig, normalizeBillingPurchaseStatus, normalizeBillingRuntimeConfig, normalizeCasdoorBuyProductResponse, normalizeCasdoorOrderHistoryItem, normalizeCasdoorPaymentHistoryItem, normalizeCasdoorProductId, normalizeCasdoorSubscriptionDetail, normalizeCasdoorSubscriptionHistoryItem, readBuyProductRedirectTo, resolveBillingInterval, resolveBillingItem, resolveBillingProductSnapshot, resolveBillingPurchasable, resolveBillingSubscriptionProduct } from './billing/index.js';
|
|
9
|
+
export { BillingSubscriptionCatalogBuilderOptions, BillingSubscriptionCatalogItemInput, NormalizedCasdoorProductId, buildBillingActionPayload, buildBillingPaymentCallbackContext, buildBillingPurchaseRequest, buildBillingSubscriptionCatalog, buildCasdoorBuyProductParams, buildCasdoorBuyProductRequest, chooseCasdoorProviderName, createBillingPaymentFinishedResponse, createBillingPaymentFinishedRouteHandler, createBillingPaymentSuccessResponse, createBillingPaymentSuccessRouteHandler, deriveBillingCreditsState, deriveBillingEntitlements, filterBillingPurchasableItems, normalizeBillingCatalogConfig, normalizeBillingPurchaseStatus, normalizeBillingRuntimeConfig, normalizeCasdoorBuyProductResponse, normalizeCasdoorOrderHistoryItem, normalizeCasdoorPaymentHistoryItem, normalizeCasdoorProductId, normalizeCasdoorSubscriptionDetail, normalizeCasdoorSubscriptionHistoryItem, readBuyProductRedirectTo, resolveBillingInterval, resolveBillingItem, resolveBillingProductSnapshot, resolveBillingPurchasable, resolveBillingSubscriptionProduct } from './billing/index.js';
|
|
10
10
|
import 'next/server';
|
|
11
11
|
import 'next-auth';
|
|
12
12
|
|
package/dist/index.js
CHANGED
|
@@ -8,18 +8,45 @@ import {
|
|
|
8
8
|
getMissingManagedEnvKeys,
|
|
9
9
|
readManagedEnvValue,
|
|
10
10
|
sanitizeExistingEnvContent
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-SZVWLQQT.js";
|
|
12
12
|
import {
|
|
13
|
+
buildBillingSubscriptionCatalog,
|
|
13
14
|
createBillingPaymentFinishedResponse,
|
|
14
15
|
createBillingPaymentFinishedRouteHandler,
|
|
15
16
|
createBillingPaymentSuccessResponse,
|
|
16
17
|
createBillingPaymentSuccessRouteHandler
|
|
17
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-PILMR42A.js";
|
|
18
19
|
import {
|
|
19
20
|
createCasdoorApiProxyHandler,
|
|
20
21
|
createCasdoorCommerceProxyHandler,
|
|
21
22
|
createCasdoorPageProxyHandler
|
|
22
23
|
} from "./chunk-5W4H2IMT.js";
|
|
24
|
+
import {
|
|
25
|
+
buildBillingActionPayload,
|
|
26
|
+
buildBillingPaymentCallbackContext,
|
|
27
|
+
buildBillingPurchaseRequest,
|
|
28
|
+
buildCasdoorBuyProductParams,
|
|
29
|
+
buildCasdoorBuyProductRequest,
|
|
30
|
+
chooseCasdoorProviderName,
|
|
31
|
+
deriveBillingCreditsState,
|
|
32
|
+
deriveBillingEntitlements,
|
|
33
|
+
filterBillingPurchasableItems,
|
|
34
|
+
normalizeBillingCatalogConfig,
|
|
35
|
+
normalizeBillingPurchaseStatus,
|
|
36
|
+
normalizeBillingRuntimeConfig,
|
|
37
|
+
normalizeCasdoorBuyProductResponse,
|
|
38
|
+
normalizeCasdoorOrderHistoryItem,
|
|
39
|
+
normalizeCasdoorPaymentHistoryItem,
|
|
40
|
+
normalizeCasdoorProductId,
|
|
41
|
+
normalizeCasdoorSubscriptionDetail,
|
|
42
|
+
normalizeCasdoorSubscriptionHistoryItem,
|
|
43
|
+
readBuyProductRedirectTo,
|
|
44
|
+
resolveBillingInterval,
|
|
45
|
+
resolveBillingItem,
|
|
46
|
+
resolveBillingProductSnapshot,
|
|
47
|
+
resolveBillingPurchasable,
|
|
48
|
+
resolveBillingSubscriptionProduct
|
|
49
|
+
} from "./chunk-FL6LOXEG.js";
|
|
23
50
|
import {
|
|
24
51
|
createAuthorizeRouteHandler,
|
|
25
52
|
createLoginRouteHandler,
|
|
@@ -66,32 +93,6 @@ import {
|
|
|
66
93
|
verifyState,
|
|
67
94
|
verifyStateToken
|
|
68
95
|
} from "./chunk-MWXY4JSL.js";
|
|
69
|
-
import {
|
|
70
|
-
buildBillingActionPayload,
|
|
71
|
-
buildBillingPaymentCallbackContext,
|
|
72
|
-
buildBillingPurchaseRequest,
|
|
73
|
-
buildCasdoorBuyProductParams,
|
|
74
|
-
buildCasdoorBuyProductRequest,
|
|
75
|
-
chooseCasdoorProviderName,
|
|
76
|
-
deriveBillingCreditsState,
|
|
77
|
-
deriveBillingEntitlements,
|
|
78
|
-
filterBillingPurchasableItems,
|
|
79
|
-
normalizeBillingCatalogConfig,
|
|
80
|
-
normalizeBillingPurchaseStatus,
|
|
81
|
-
normalizeBillingRuntimeConfig,
|
|
82
|
-
normalizeCasdoorBuyProductResponse,
|
|
83
|
-
normalizeCasdoorOrderHistoryItem,
|
|
84
|
-
normalizeCasdoorPaymentHistoryItem,
|
|
85
|
-
normalizeCasdoorProductId,
|
|
86
|
-
normalizeCasdoorSubscriptionDetail,
|
|
87
|
-
normalizeCasdoorSubscriptionHistoryItem,
|
|
88
|
-
readBuyProductRedirectTo,
|
|
89
|
-
resolveBillingInterval,
|
|
90
|
-
resolveBillingItem,
|
|
91
|
-
resolveBillingProductSnapshot,
|
|
92
|
-
resolveBillingPurchasable,
|
|
93
|
-
resolveBillingSubscriptionProduct
|
|
94
|
-
} from "./chunk-FL6LOXEG.js";
|
|
95
96
|
import {
|
|
96
97
|
buildAuthJumpHref,
|
|
97
98
|
resolvePostLoginRedirect
|
|
@@ -108,6 +109,7 @@ export {
|
|
|
108
109
|
buildBillingActionPayload,
|
|
109
110
|
buildBillingPaymentCallbackContext,
|
|
110
111
|
buildBillingPurchaseRequest,
|
|
112
|
+
buildBillingSubscriptionCatalog,
|
|
111
113
|
buildCasdoorBuyProductParams,
|
|
112
114
|
buildCasdoorBuyProductRequest,
|
|
113
115
|
buildManagedEnvTemplate,
|
|
@@ -82,6 +82,7 @@ npx @foldspace-fe/casdoor-next-auth-kit@latest check
|
|
|
82
82
|
- 数据库契约和同步接口 — 定义宿主项目必须实现的用户数据字段和同步行为
|
|
83
83
|
- `BillingProvider` / `BillingCoreProvider` — headless billing runtime 的根 Provider,支持 `purchasableIds` 白名单、`purchasables` 显式条目、Casdoor 商品购买适配器和购买回调 hooks
|
|
84
84
|
- `SubscriptionProvider` / `ProductProvider` / `CreditsProvider` — 分域 billing Provider,按需注入订阅、商品和额度状态
|
|
85
|
+
- `buildBillingSubscriptionCatalog` — 把宿主已有的会员计划 rows 转成 auth-kit 的 subscription catalog,适合 membership 这种“订阅为主、商品为辅”的接入场景
|
|
85
86
|
- `useBillingAvailablePlans` / `useBillingAvailableProducts` — 从配置或注入的 catalog 中读取可订阅套餐和可购买商品列表,并自动过滤白名单外条目
|
|
86
87
|
- `useBillingPricing` / `useBillingPlan` / `useBillingPricingPlans` / `useBillingSubscriptionPurchaseOptions` — 读取订阅定价、单个计划、计划组合和订阅购买选项
|
|
87
88
|
- `useBillingSubscription` / `useBillingSubscriptionHistory` / `useBillingSubscriptionRecord` / `useBillingSubscriptions` / `useBillingSubscriptionProduct` — 查看当前订阅、订阅历史、订阅记录、订阅列表和当前订阅对应产品
|
|
@@ -112,7 +113,53 @@ npx @foldspace-fe/casdoor-next-auth-kit@latest check
|
|
|
112
113
|
如果宿主希望注销后回到自定义配置页,可以在 `AuthKitConfig` 中设置 `logoutRedirectPath`,默认值为 `/`。
|
|
113
114
|
若想通过环境变量控制默认值,可设置 `NEXT_PUBLIC_AUTH_LOGOUT_REDIRECT_PATH=/` 或其他同源路径。
|
|
114
115
|
|
|
115
|
-
Billing 的购买白名单可以通过 `BillingCatalogConfig.purchasableIds` 或宿主注入的 `purchasables` 显式配置。宿主只需要在自己的项目里维护允许购买的少量条目,Casdoor
|
|
116
|
+
Billing 的购买白名单可以通过 `BillingCatalogConfig.purchasableIds` 或宿主注入的 `purchasables` 显式配置。宿主只需要在自己的项目里维护允许购买的少量条目,Casdoor 里可以继续保留更大的商品集合。订阅的 `pricing / plan` 不是 env 配置项,而是通过 `buildBillingSubscriptionCatalog()` 的 `mapPlan` 映射成 catalog 数据;env 模板里放的是白名单示例,不是定价本身。
|
|
117
|
+
|
|
118
|
+
如果宿主要同时配订阅和商品,推荐直接按这个结构写:
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
const membershipPlans = [
|
|
122
|
+
{
|
|
123
|
+
id: 'plan-basic',
|
|
124
|
+
code: 'membership-monthly',
|
|
125
|
+
name: 'Membership Monthly',
|
|
126
|
+
level: 'BASIC',
|
|
127
|
+
priceCents: 99900,
|
|
128
|
+
giftPoints: 10000,
|
|
129
|
+
billingCycle: 'MONTH',
|
|
130
|
+
benefits: {
|
|
131
|
+
faceLibrary: true,
|
|
132
|
+
monthlyReports: true,
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
];
|
|
136
|
+
|
|
137
|
+
const subscriptionCatalog = buildBillingSubscriptionCatalog(membershipPlans, {
|
|
138
|
+
catalogKey: 'main',
|
|
139
|
+
title: 'Billing Catalog',
|
|
140
|
+
mapPlan: (plan) => ({
|
|
141
|
+
source: plan,
|
|
142
|
+
key: plan.code,
|
|
143
|
+
title: plan.name,
|
|
144
|
+
description: `${plan.level} membership`,
|
|
145
|
+
productId: 'qixiaoju/创小剧会员订阅',
|
|
146
|
+
planId: plan.id,
|
|
147
|
+
priceId: `pricing_${plan.code}`,
|
|
148
|
+
interval: 'month',
|
|
149
|
+
priceValue: plan.priceCents,
|
|
150
|
+
metadata: {
|
|
151
|
+
level: plan.level,
|
|
152
|
+
giftPoints: String(plan.giftPoints),
|
|
153
|
+
billingCycle: plan.billingCycle,
|
|
154
|
+
},
|
|
155
|
+
}),
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
const billingCatalog = {
|
|
159
|
+
...subscriptionCatalog,
|
|
160
|
+
purchasableIds: [...subscriptionCatalog.purchasableIds, 'credits-50'],
|
|
161
|
+
};
|
|
162
|
+
```
|
|
116
163
|
|
|
117
164
|
商品购买的包内适配器会优先读取 Casdoor 商品详情,再按 `owner/name` 解析商品 ID,并自动选择可用 provider 后调用 `buy-product` 兼容接口;宿主只需要提供允许购买的商品 id 和相应的 Casdoor 接口 loader。loader 约定使用 Casdoor 的标准响应 envelope,然后从 `data` 中取出商品、组织、账号、应用或支付记录。`buy-product` 如果返回 `status: "error"`,包内会把 `msg` 里的错误信息和错误码透传到宿主的 `onPurchaseError` / `onPurchaseComplete`。`useBillingProductDetail` 会把商品详情里的 `providers` 和 `providerObjs` 暴露给宿主,`useBillingProductPurchaseOptions` 可以直接拿到商品详情、当前 provider 选择、当前选中 provider 对象和 setter,适合商品详情页按支付方式展示不同购买参数;宿主选中的 `providerName` 也可以直接传给 `purchaseProduct.run({ key, providerName })`,让包内适配器按这个 provider 下单。这个 hook 只是给单选场景提供默认态,如果宿主想同时渲染两个不同的支付入口,直接遍历 `providerObjs` 就行,`selectedProvider` 不会限制 UI 结构。`productId` 推荐写成 `owner/name` 形式,例如 `qixiaoju/创小剧积分包-50`,和 `GET /api/get-product?id=qixiaoju/创小剧积分包-50` 的查询值保持一致。支付结果轮询和 `get-account` / `get-application` / `get-payment` 这类浏览器侧查询,优先请求 `/auth/api/*` 同域代理;只有服务端或明确启用 CORS 的特殊场景,才考虑直接连 `NEXT_PUBLIC_CASDOOR_SERVER_URL` origin 的 `/api/*`。
|
|
118
165
|
|
|
@@ -363,6 +410,7 @@ NEXTAUTH_URL=http://localhost:5177
|
|
|
363
410
|
- `prisma/auth-kit.prisma`
|
|
364
411
|
- `.env`、`.env.local`、`.env.production`、`.env.example`
|
|
365
412
|
- `.agents/skills/casdoor-next-auth-kit/SKILL.md`
|
|
413
|
+
- 其中 `NEXT_PUBLIC_BILLING_PURCHASABLE_IDS` 的默认示例值会写成 `membership-monthly,credits-50`
|
|
366
414
|
4. 如果 `check` 仍然报缺失,优先排查这些问题
|
|
367
415
|
- 宿主项目还没重新安装到新的包产物,先回到本仓库执行 `pnpm build`
|
|
368
416
|
- 宿主项目没重新安装依赖,执行 `pnpm install` 后再跑一次 `update`
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/core/env.ts","../src/prisma/schema-template.ts"],"sourcesContent":["import type { ManagedEnvFile, ManagedEnvVariableDefinition } from '../types';\n\nexport const AUTH_KIT_ENV_FILES: ManagedEnvFile[] = ['.env', '.env.local', '.env.production', '.env.example'];\n\nexport const AUTH_KIT_ENV_VARIABLES: ManagedEnvVariableDefinition[] = [\n {\n key: 'APP_URL',\n description: '站点对外公开地址',\n example: 'https://your-domain.com',\n local: 'http://localhost:5177',\n production: 'https://your-domain.com',\n },\n {\n key: 'NEXTAUTH_URL',\n description: 'NextAuth 回调地址',\n example: 'http://localhost:5177',\n local: 'http://localhost:5177',\n production: 'https://your-domain.com',\n },\n {\n key: 'NEXTAUTH_SECRET',\n description: 'NextAuth JWT secret',\n example: 'replace-with-a-random-secret',\n local: 'replace-with-a-random-secret',\n production: 'replace-with-a-random-secret',\n },\n {\n key: 'GLOBAL_ADMIN_EMAILS',\n description: '全局管理员邮箱,逗号分隔',\n example: 'admin@example.com',\n local: 'admin@example.com',\n production: 'admin@example.com',\n },\n {\n key: 'AUTH_DEBUG',\n description: '是否开启认证调试日志',\n example: 'false',\n local: 'false',\n production: 'false',\n },\n {\n key: 'NEXT_PUBLIC_CASDOOR_SERVER_URL',\n description: 'Casdoor 服务地址',\n example: 'https://auth.example.com',\n local: 'https://auth.example.com',\n production: 'https://auth.example.com',\n },\n {\n key: 'NEXT_PUBLIC_CASDOOR_CLIENT_ID',\n description: 'Casdoor client id',\n example: 'your-casdoor-client-id',\n local: 'your-casdoor-client-id',\n production: 'your-casdoor-client-id',\n },\n {\n key: 'NEXT_PUBLIC_CASDOOR_APP_NAME',\n description: 'Casdoor app name',\n example: 'your-app-name',\n local: 'your-app-name',\n production: 'your-app-name',\n },\n {\n key: 'NEXT_PUBLIC_CASDOOR_ORGANIZATION_NAME',\n description: 'Casdoor organization name',\n example: 'your-org-name',\n local: 'your-org-name',\n production: 'your-org-name',\n },\n {\n key: 'NEXT_PUBLIC_CASDOOR_REDIRECT_PATH',\n description: 'Casdoor OAuth 回调路径',\n example: '/callback',\n local: '/callback',\n production: '/callback',\n },\n {\n key: 'NEXT_PUBLIC_CASDOOR_SIGNIN_PATH',\n description: 'Casdoor authorize 路径',\n example: '/login/oauth/authorize',\n local: '/login/oauth/authorize',\n production: '/login/oauth/authorize',\n },\n {\n key: 'NEXT_PUBLIC_AUTH_LOGOUT_REDIRECT_PATH',\n description: '注销后跳转路径,默认首页',\n example: '/',\n local: '/',\n production: '/',\n },\n {\n key: 'NEXT_PUBLIC_BILLING_PURCHASABLE_IDS',\n description: 'Billing 可购买项白名单,逗号分隔',\n example: 'starter-month,credits-1000',\n local: 'starter-month,credits-1000',\n production: 'starter-month,credits-1000',\n },\n {\n key: 'NEXT_PUBLIC_CASDOOR_STATIC_ORIGIN',\n description: 'Casdoor 静态资源 origin',\n example: 'https://casdoor-static.foldspace.cn',\n local: 'https://casdoor-static.foldspace.cn',\n production: 'https://casdoor-static.foldspace.cn',\n },\n {\n key: 'CASDOOR_CLIENT_SECRET',\n description: 'Casdoor client secret',\n example: 'your-casdoor-client-secret',\n local: 'your-casdoor-client-secret',\n production: 'your-casdoor-client-secret',\n },\n {\n key: 'BILLING_PAYMENT_SUCCESS_DEBUG',\n description: '是否打印 payment-success 调试日志',\n example: 'false',\n local: 'false',\n production: 'false',\n },\n];\n\nfunction stringifyEnvValue(value: string): string {\n if (value === '') {\n return '\"\"';\n }\n\n if (/^[A-Za-z0-9_./:-]+$/.test(value)) {\n return value;\n }\n\n return JSON.stringify(value);\n}\n\nfunction stripQuotes(value: string): string {\n const trimmed = value.trim();\n if (\n (trimmed.startsWith('\"') && trimmed.endsWith('\"')) ||\n (trimmed.startsWith(\"'\") && trimmed.endsWith(\"'\"))\n ) {\n return trimmed.slice(1, -1);\n }\n\n return trimmed;\n}\n\nfunction parseEnvKeys(content: string): Set<string> {\n const keys = new Set<string>();\n for (const line of content.split(/\\r?\\n/)) {\n const trimmed = line.trim();\n if (!trimmed || trimmed.startsWith('#')) {\n continue;\n }\n\n const separatorIndex = trimmed.indexOf('=');\n if (separatorIndex === -1) {\n continue;\n }\n\n const key = trimmed.slice(0, separatorIndex).trim();\n if (key) {\n keys.add(key);\n }\n }\n return keys;\n}\n\nexport function readManagedEnvValue(content: string, key: string): string | null {\n for (const line of content.split(/\\r?\\n/)) {\n const trimmed = line.trim();\n if (!trimmed || trimmed.startsWith('#')) {\n continue;\n }\n\n const separatorIndex = trimmed.indexOf('=');\n if (separatorIndex === -1) {\n continue;\n }\n\n const currentKey = trimmed.slice(0, separatorIndex).trim();\n if (currentKey !== key) {\n continue;\n }\n\n const rawValue = trimmed.slice(separatorIndex + 1).trim();\n return stripQuotes(rawValue);\n }\n\n return null;\n}\n\nexport function getManagedEnvValue(definition: ManagedEnvVariableDefinition, file: ManagedEnvFile): string {\n if (file === '.env.example') {\n return definition.example;\n }\n if (file === '.env.production') {\n return definition.production ?? definition.example;\n }\n if (file === '.env.local') {\n return definition.local ?? definition.example;\n }\n return definition.base ?? definition.local ?? definition.production ?? definition.example;\n}\n\nexport function buildManagedEnvTemplate(file: ManagedEnvFile, existingContent = ''): string {\n const existingKeys = parseEnvKeys(existingContent);\n const lines: string[] = existingContent.trimEnd() ? existingContent.trimEnd().split(/\\r?\\n/) : [];\n const missing = AUTH_KIT_ENV_VARIABLES.filter((definition) => !existingKeys.has(definition.key));\n\n if (missing.length === 0 && existingContent) {\n return existingContent;\n }\n\n if (lines.length > 0) {\n lines.push('');\n }\n\n lines.push(`# Casdoor Next Auth Kit managed values for ${file}`);\n for (const definition of missing) {\n const value = getManagedEnvValue(definition, file);\n lines.push(`# ${definition.description}`);\n lines.push(`${definition.key}=${stringifyEnvValue(value)}`);\n lines.push('');\n }\n\n while (lines.length > 0 && lines[lines.length - 1] === '') {\n lines.pop();\n }\n\n return `${lines.join('\\n')}\\n`;\n}\n\nexport function getMissingManagedEnvKeys(content: string): string[] {\n const existingKeys = parseEnvKeys(content);\n return AUTH_KIT_ENV_VARIABLES.filter((definition) => !existingKeys.has(definition.key)).map(\n (definition) => definition.key,\n );\n}\n\nexport function sanitizeExistingEnvContent(content: string): string {\n return stripQuotes(content);\n}\n","import type { PrismaSchemaFieldDefinition, PrismaSchemaModelDefinition } from '../types';\n\nexport const AUTH_PRISMA_SCHEMA_MODELS: PrismaSchemaModelDefinition[] = [\n {\n name: 'AuthUser',\n description: 'Shared authentication user record',\n fields: [\n { name: 'id', type: 'String', attributes: ['@id', '@default(cuid())'] },\n { name: 'email', type: 'String?', attributes: ['@unique'] },\n { name: 'name', type: 'String?' },\n { name: 'image', type: 'String?' },\n { name: 'isAdmin', type: 'Boolean', attributes: ['@default(false)'] },\n { name: 'tokenBalance', type: 'Int', attributes: ['@default(0)'] },\n { name: 'isVip', type: 'Boolean', attributes: ['@default(false)'] },\n { name: 'createdAt', type: 'DateTime', attributes: ['@default(now())'] },\n { name: 'updatedAt', type: 'DateTime', attributes: ['@updatedAt'] },\n ],\n blockAttributes: ['@@index([email])'],\n },\n {\n name: 'AuthMembership',\n description: 'Subscription membership snapshot',\n fields: [\n { name: 'id', type: 'String', attributes: ['@id', '@default(cuid())'] },\n { name: 'userId', type: 'String', attributes: ['@unique'] },\n { name: 'plan', type: 'String' },\n { name: 'status', type: 'String' },\n { name: 'startsAt', type: 'DateTime?' },\n { name: 'endsAt', type: 'DateTime?' },\n { name: 'createdAt', type: 'DateTime', attributes: ['@default(now())'] },\n { name: 'updatedAt', type: 'DateTime', attributes: ['@updatedAt'] },\n ],\n blockAttributes: ['@@index([userId])'],\n },\n {\n name: 'AuthOrder',\n description: 'Commerce order record',\n fields: [\n { name: 'id', type: 'String', attributes: ['@id', '@default(cuid())'] },\n { name: 'userId', type: 'String' },\n { name: 'kind', type: 'String' },\n { name: 'status', type: 'String' },\n { name: 'amount', type: 'Int' },\n { name: 'currency', type: 'String', attributes: ['@default(\"CNY\")'] },\n { name: 'payload', type: 'Json?' },\n { name: 'createdAt', type: 'DateTime', attributes: ['@default(now())'] },\n { name: 'updatedAt', type: 'DateTime', attributes: ['@updatedAt'] },\n ],\n blockAttributes: ['@@index([userId])'],\n },\n {\n name: 'AuthSubscription',\n description: 'Commerce subscription record',\n fields: [\n { name: 'id', type: 'String', attributes: ['@id', '@default(cuid())'] },\n { name: 'userId', type: 'String' },\n { name: 'productId', type: 'String' },\n { name: 'status', type: 'String' },\n { name: 'interval', type: 'String' },\n { name: 'startsAt', type: 'DateTime?' },\n { name: 'endsAt', type: 'DateTime?' },\n { name: 'createdAt', type: 'DateTime', attributes: ['@default(now())'] },\n { name: 'updatedAt', type: 'DateTime', attributes: ['@updatedAt'] },\n ],\n blockAttributes: ['@@index([userId])', '@@index([productId])'],\n },\n {\n name: 'AuthInvoice',\n description: 'Commerce invoice record',\n fields: [\n { name: 'id', type: 'String', attributes: ['@id', '@default(cuid())'] },\n { name: 'userId', type: 'String' },\n { name: 'orderId', type: 'String?' },\n { name: 'invoiceNo', type: 'String', attributes: ['@unique'] },\n { name: 'status', type: 'String' },\n { name: 'amount', type: 'Int' },\n { name: 'createdAt', type: 'DateTime', attributes: ['@default(now())'] },\n { name: 'updatedAt', type: 'DateTime', attributes: ['@updatedAt'] },\n ],\n blockAttributes: ['@@index([userId])', '@@index([orderId])'],\n },\n];\n\nfunction renderField(field: PrismaSchemaFieldDefinition): string {\n const attributes = field.attributes?.length ? ` ${field.attributes.join(' ')}` : '';\n return ` ${field.name} ${field.type}${attributes}`;\n}\n\nfunction renderModel(model: PrismaSchemaModelDefinition): string {\n const lines = [\n `/// ${model.description}`,\n `model ${model.name} {`,\n ...model.fields.map(renderField),\n ];\n\n if (model.blockAttributes?.length) {\n lines.push(...model.blockAttributes.map((attribute) => ` ${attribute}`));\n }\n\n lines.push('}');\n return lines.join('\\n');\n}\n\nexport function buildAuthPrismaSchemaTemplate(models: PrismaSchemaModelDefinition[] = AUTH_PRISMA_SCHEMA_MODELS): string {\n return [\n '// generated by @foldspace-fe/casdoor-next-auth-kit',\n '// merge these models into the host Prisma schema if you want a dedicated auth module',\n '',\n ...models.map(renderModel),\n ].join('\\n\\n');\n}\n"],"mappings":";AAEO,IAAM,qBAAuC,CAAC,QAAQ,cAAc,mBAAmB,cAAc;AAErG,IAAM,yBAAyD;AAAA,EACpE;AAAA,IACE,KAAK;AAAA,IACL,aAAa;AAAA,IACb,SAAS;AAAA,IACT,OAAO;AAAA,IACP,YAAY;AAAA,EACd;AAAA,EACA;AAAA,IACE,KAAK;AAAA,IACL,aAAa;AAAA,IACb,SAAS;AAAA,IACT,OAAO;AAAA,IACP,YAAY;AAAA,EACd;AAAA,EACA;AAAA,IACE,KAAK;AAAA,IACL,aAAa;AAAA,IACb,SAAS;AAAA,IACT,OAAO;AAAA,IACP,YAAY;AAAA,EACd;AAAA,EACA;AAAA,IACE,KAAK;AAAA,IACL,aAAa;AAAA,IACb,SAAS;AAAA,IACT,OAAO;AAAA,IACP,YAAY;AAAA,EACd;AAAA,EACA;AAAA,IACE,KAAK;AAAA,IACL,aAAa;AAAA,IACb,SAAS;AAAA,IACT,OAAO;AAAA,IACP,YAAY;AAAA,EACd;AAAA,EACA;AAAA,IACE,KAAK;AAAA,IACL,aAAa;AAAA,IACb,SAAS;AAAA,IACT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I,WAAW;AAAA,EAC3B,EAAE,KAAK,MAAM;AACf;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/billing/payment-route.ts","../src/core/origin.ts","../src/billing/payment-success.ts","../src/billing/payment-finished.ts"],"sourcesContent":["import { NextResponse } from 'next/server';\n\nimport { resolvePublicOrigin } from '../core/origin';\nimport { buildBillingPaymentCallbackContext } from './runtime';\nimport type {\n BillingPaymentRouteBaseOptions,\n BillingPaymentFinishedRouteOptions,\n BillingPaymentFinishedContext,\n BillingPaymentFinishedHandler,\n BillingPaymentSuccessContext,\n BillingPaymentSuccessHandlerResult,\n BillingPaymentSuccessRouteOptions,\n} from './types';\n\nexport interface BillingPaymentRouteOptions extends BillingPaymentRouteBaseOptions {\n routePath: string;\n missingHandlerFile: string;\n handler?: BillingPaymentSuccessRouteOptions['handler'] | BillingPaymentFinishedRouteOptions['handler'];\n phase?: 'success' | 'failure' | 'finished';\n}\n\nfunction sanitizeRedirectPath(value: string | null | undefined, fallback: string): string {\n if (!value || !value.startsWith('/') || value.startsWith('//')) {\n return fallback;\n }\n\n return value;\n}\n\nfunction isDebugEnabled(): boolean {\n const value = process.env.BILLING_PAYMENT_SUCCESS_DEBUG;\n if (!value) {\n return false;\n }\n\n return ['1', 'true', 'yes', 'on'].includes(value.toLowerCase());\n}\n\nfunction resolveRedirectTarget(\n result: BillingPaymentSuccessHandlerResult | undefined,\n context: BillingPaymentSuccessContext,\n fallbackRedirect: string,\n): string {\n if (typeof result === 'string') {\n return sanitizeRedirectPath(result, fallbackRedirect);\n }\n\n if (result && typeof result === 'object' && 'redirectTo' in result) {\n return sanitizeRedirectPath(result.redirectTo ?? null, fallbackRedirect);\n }\n\n return sanitizeRedirectPath(context.redirectTo, fallbackRedirect);\n}\n\nfunction resolveFallbackTarget(fallbackRedirect: string): string {\n return sanitizeRedirectPath(fallbackRedirect, '/');\n}\n\nfunction logMissingPaymentHandler(\n context: BillingPaymentSuccessContext,\n fallbackRedirect: string,\n missingHandlerFile: string,\n routePath: string,\n): void {\n console.warn(\n `[casdoor-next-auth-kit] default billing handler at ${missingHandlerFile} has no business logic. ` +\n `Edit this file to handle ${routePath} with order/payment enrichment before redirecting. ` +\n `Falling back to ${fallbackRedirect}.`,\n {\n paymentOwner: context.paymentOwner,\n paymentName: context.paymentName,\n paymentId: context.paymentId,\n orderId: context.orderId,\n params: context.params,\n },\n );\n}\n\nexport async function createBillingPaymentRouteResponse(\n request: Request,\n options: BillingPaymentRouteOptions,\n) {\n const origin = resolvePublicOrigin(request, options.appUrl);\n const fallbackRedirect = options.fallbackRedirect ?? '/';\n const context = await buildBillingPaymentCallbackContext(request, options.phase);\n\n if (isDebugEnabled()) {\n console.info(`[casdoor-next-auth-kit] ${options.routePath} request`, {\n method: request.method,\n path: context.url.pathname,\n query: context.params,\n body: context.body,\n });\n }\n\n try {\n if (options.handler) {\n const handler = options.handler;\n const result =\n options.phase === 'finished'\n ? await (handler as BillingPaymentFinishedHandler)(context as BillingPaymentFinishedContext)\n : await (handler as NonNullable<BillingPaymentSuccessRouteOptions['handler']>)(context);\n if (result instanceof Response) {\n return result;\n }\n\n const target = resolveRedirectTarget(result, context, fallbackRedirect);\n return NextResponse.redirect(new URL(target, origin), 307);\n }\n\n logMissingPaymentHandler(context, fallbackRedirect, options.missingHandlerFile, options.routePath);\n const target = resolveFallbackTarget(fallbackRedirect);\n return NextResponse.redirect(new URL(target, origin), 307);\n } catch (error) {\n console.error(`[casdoor-next-auth-kit] ${options.routePath} handler failed:`, error);\n return new NextResponse('Billing payment handler failed', { status: 500 });\n }\n}\n","export function normalizeOrigin(value: string | null | undefined): string | null {\n if (!value) return null;\n try {\n return new URL(value).origin;\n } catch {\n return null;\n }\n}\n\nexport function getRequestOrigin(request: Request, appUrl?: string): string {\n const configured = normalizeOrigin(appUrl);\n if (configured) return configured;\n\n const referer = normalizeOrigin(request.headers.get('referer'));\n if (referer) return referer;\n\n const origin = normalizeOrigin(request.headers.get('origin'));\n if (origin) return origin;\n\n const forwardedProto = request.headers.get('x-forwarded-proto')?.split(',')[0]?.trim();\n const forwardedHost = request.headers.get('x-forwarded-host')?.split(',')[0]?.trim();\n if (forwardedProto && forwardedHost) {\n return forwardedProto + '://' + forwardedHost;\n }\n\n return new URL(request.url).origin;\n}\n\nexport function resolvePublicOrigin(request: Request, appUrl?: string): string {\n return getRequestOrigin(request, appUrl);\n}\n","import type { BillingPaymentSuccessHandler, BillingPaymentSuccessRouteOptions } from './types';\nimport { createBillingPaymentRouteResponse } from './payment-route';\n\nexport async function createBillingPaymentSuccessResponse(\n request: Request,\n options: BillingPaymentSuccessRouteOptions = {},\n) {\n return createBillingPaymentRouteResponse(request, {\n ...options,\n routePath: '/auth/payment/success',\n missingHandlerFile: 'lib/billing/payment-success.ts',\n fallbackRedirect: options.fallbackRedirect ?? '/auth/payment/finished',\n phase: options.phase ?? 'success',\n });\n}\n\nexport function createBillingPaymentSuccessRouteHandler(options: BillingPaymentSuccessRouteOptions = {}) {\n return async function GET(request: Request) {\n return createBillingPaymentSuccessResponse(request, options);\n };\n}\n\nexport type { BillingPaymentSuccessHandler };\n","import type { BillingPaymentFinishedHandler, BillingPaymentFinishedRouteOptions } from './types';\nimport { createBillingPaymentRouteResponse } from './payment-route';\n\nexport async function createBillingPaymentFinishedResponse(\n request: Request,\n options: BillingPaymentFinishedRouteOptions = {},\n) {\n return createBillingPaymentRouteResponse(request, {\n ...options,\n routePath: '/auth/payment/finished',\n missingHandlerFile: 'lib/billing/payment-finished.ts',\n fallbackRedirect: options.fallbackRedirect ?? '/',\n phase: options.phase ?? 'finished',\n });\n}\n\nexport function createBillingPaymentFinishedRouteHandler(options: BillingPaymentFinishedRouteOptions = {}) {\n return async function GET(request: Request) {\n return createBillingPaymentFinishedResponse(request, options);\n };\n}\n\nexport type { BillingPaymentFinishedHandler };\n"],"mappings":";;;;;AAAA,SAAS,oBAAoB;;;ACAtB,SAAS,gBAAgB,OAAiD;AAC/E,MAAI,CAAC,MA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