@foldspace-fe/casdoor-next-auth-kit 0.1.22 → 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 CHANGED
@@ -57,6 +57,76 @@ import { BillingProvider } from '@foldspace-fe/casdoor-next-auth-kit/react';
57
57
 
58
58
  如果宿主已经有自己的会员计划 rows,先用 `buildBillingSubscriptionCatalog()` 生成 subscription catalog,再把结果交给 `BillingProvider`。商品项仍然可以单独拼进同一个 catalog,但订阅和商品要保持语义分离。
59
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
+
60
130
  ### Billing 动作
61
131
 
62
132
  ```tsx
@@ -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: "starter-month,credits-1000",
92
- local: "starter-month,credits-1000",
93
- production: "starter-month,credits-1000"
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-FW4WDHNS.js.map
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,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,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AO,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
@@ -4,7 +4,7 @@ import {
4
4
  buildAuthPrismaSchemaTemplate,
5
5
  buildManagedEnvTemplate,
6
6
  getMissingManagedEnvKeys
7
- } from "./chunk-FW4WDHNS.js";
7
+ } from "./chunk-SZVWLQQT.js";
8
8
 
9
9
  // package.json
10
10
  var package_default = {
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  getMissingManagedEnvKeys,
9
9
  readManagedEnvValue,
10
10
  sanitizeExistingEnvContent
11
- } from "./chunk-FW4WDHNS.js";
11
+ } from "./chunk-SZVWLQQT.js";
12
12
  import {
13
13
  buildBillingSubscriptionCatalog,
14
14
  createBillingPaymentFinishedResponse,
@@ -21,6 +21,32 @@ import {
21
21
  createCasdoorCommerceProxyHandler,
22
22
  createCasdoorPageProxyHandler
23
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";
24
50
  import {
25
51
  createAuthorizeRouteHandler,
26
52
  createLoginRouteHandler,
@@ -67,32 +93,6 @@ import {
67
93
  verifyState,
68
94
  verifyStateToken
69
95
  } from "./chunk-MWXY4JSL.js";
70
- import {
71
- buildBillingActionPayload,
72
- buildBillingPaymentCallbackContext,
73
- buildBillingPurchaseRequest,
74
- buildCasdoorBuyProductParams,
75
- buildCasdoorBuyProductRequest,
76
- chooseCasdoorProviderName,
77
- deriveBillingCreditsState,
78
- deriveBillingEntitlements,
79
- filterBillingPurchasableItems,
80
- normalizeBillingCatalogConfig,
81
- normalizeBillingPurchaseStatus,
82
- normalizeBillingRuntimeConfig,
83
- normalizeCasdoorBuyProductResponse,
84
- normalizeCasdoorOrderHistoryItem,
85
- normalizeCasdoorPaymentHistoryItem,
86
- normalizeCasdoorProductId,
87
- normalizeCasdoorSubscriptionDetail,
88
- normalizeCasdoorSubscriptionHistoryItem,
89
- readBuyProductRedirectTo,
90
- resolveBillingInterval,
91
- resolveBillingItem,
92
- resolveBillingProductSnapshot,
93
- resolveBillingPurchasable,
94
- resolveBillingSubscriptionProduct
95
- } from "./chunk-FL6LOXEG.js";
96
96
  import {
97
97
  buildAuthJumpHref,
98
98
  resolvePostLoginRedirect
@@ -113,7 +113,53 @@ npx @foldspace-fe/casdoor-next-auth-kit@latest check
113
113
  如果宿主希望注销后回到自定义配置页,可以在 `AuthKitConfig` 中设置 `logoutRedirectPath`,默认值为 `/`。
114
114
  若想通过环境变量控制默认值,可设置 `NEXT_PUBLIC_AUTH_LOGOUT_REDIRECT_PATH=/` 或其他同源路径。
115
115
 
116
- 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
+ ```
117
163
 
118
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/*`。
119
165
 
@@ -364,6 +410,7 @@ NEXTAUTH_URL=http://localhost:5177
364
410
  - `prisma/auth-kit.prisma`
365
411
  - `.env`、`.env.local`、`.env.production`、`.env.example`
366
412
  - `.agents/skills/casdoor-next-auth-kit/SKILL.md`
413
+ - 其中 `NEXT_PUBLIC_BILLING_PURCHASABLE_IDS` 的默认示例值会写成 `membership-monthly,credits-50`
367
414
  4. 如果 `check` 仍然报缺失,优先排查这些问题
368
415
  - 宿主项目还没重新安装到新的包产物,先回到本仓库执行 `pnpm build`
369
416
  - 宿主项目没重新安装依赖,执行 `pnpm install` 后再跑一次 `update`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foldspace-fe/casdoor-next-auth-kit",
3
- "version": "0.1.22",
3
+ "version": "0.1.23",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "repository": {
@@ -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,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,I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