@foldspace-fe/casdoor-next-auth-kit 0.1.15 → 0.1.17

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.
@@ -1,9 +1,13 @@
1
- import { B as BillingActionPayload, b as BillingRuntimeConfig, m as BillingCreditsState, j as BillingProductState, h as BillingSubscriptionState, n as BillingEntitlementState, c as BillingCatalogConfig, p as BillingPurchaseStatus, k as BillingOrderHistoryItem, l as BillingPaymentHistoryItem, v as BillingInterval, a as BillingItem, q as BillingProductSnapshot, D as BillingPaymentSuccessRouteOptions, y as BillingPaymentFinishedRouteOptions } from '../types-DwThfdu-.js';
2
- export { f as BillingActionExecutor, s as BillingActionKind, d as BillingApiClient, t as BillingConversionRule, r as BillingCoreContextValue, u as BillingCreditsContextValue, g as BillingDefaults, w as BillingItemKind, e as BillingLoaders, x as BillingPaymentFinishedHandler, z as BillingPaymentSuccessContext, A as BillingPaymentSuccessHandler, C as BillingPaymentSuccessHandlerResult, E as BillingProductContextValue, F as BillingProductPurchaseConfig, o as BillingStatusState, G as BillingSubscriptionContextValue, i as BillingSubscriptionHistoryItem, H as BillingSubscriptionPurchaseConfig } from '../types-DwThfdu-.js';
1
+ import { B as BillingActionPayload, b as BillingRuntimeConfig, Y as BillingPaymentCallbackContext, af 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, V as BillingInterval, r as BillingProductSnapshot, a9 as BillingPurchasableEntry, H as BillingCasdoorBuyProductRequest, s as BillingCasdoorProductDetail, I as BillingCasdoorBuyProductResponse, u as BillingActionExecutionResult, a4 as BillingPaymentSuccessRouteOptions, $ as BillingPaymentFinishedRouteOptions } from '../types-xgHVGy75.js';
2
+ export { f as BillingActionExecutor, v as BillingActionKind, d as BillingApiClient, w as BillingCasdoorAccountDetail, x as BillingCasdoorAccountMultiFactorAuthDetail, y as BillingCasdoorAccountResponse, z as BillingCasdoorApiResponse, A as BillingCasdoorApplicationDetail, C as BillingCasdoorApplicationProviderDetail, D as BillingCasdoorApplicationResponse, E as BillingCasdoorApplicationSigninItemDetail, F as BillingCasdoorApplicationSigninMethodDetail, G as BillingCasdoorApplicationSignupItemDetail, J as BillingCasdoorErrorDetail, K as BillingCasdoorErrorPayload, L as BillingCasdoorOrganizationDetail, M as BillingCasdoorOrganizationNamesResponse, N as BillingCasdoorOrganizationOption, O as BillingCasdoorPaymentDetail, P as BillingCasdoorPaymentResponse, Q as BillingCasdoorProductResponse, R as BillingCasdoorProviderDetail, S as BillingCasdoorProviderOption, T as BillingConversionRule, t as BillingCoreContextValue, U as BillingCreditsContextValue, g as BillingDefaults, W as BillingItemKind, e as BillingLoaders, X as BillingOrderCreatedContext, Z as BillingPaymentFinishedContext, _ as BillingPaymentFinishedHandler, a0 as BillingPaymentRouteBaseOptions, a1 as BillingPaymentSuccessContext, a2 as BillingPaymentSuccessHandler, a3 as BillingPaymentSuccessHandlerResult, a5 as BillingProductContextValue, a6 as BillingProductDetailState, a7 as BillingProductPurchasableEntry, a8 as BillingProductPurchaseConfig, aa as BillingPurchasableEntryBase, ab as BillingPurchasableKind, ac as BillingPurchasableWhitelist, ad as BillingPurchaseCompleteContext, ae as BillingPurchaseErrorContext, q as BillingPurchaseHooks, o as BillingStatusState, ag as BillingSubscriptionContextValue, i as BillingSubscriptionHistoryItem, ah as BillingSubscriptionPurchasableEntry, ai as BillingSubscriptionPurchaseConfig } from '../types-xgHVGy75.js';
3
3
 
4
4
  declare function normalizeBillingRuntimeConfig(config?: Partial<BillingRuntimeConfig> | null): BillingRuntimeConfig;
5
5
  declare function normalizeBillingCatalogConfig(config?: Partial<BillingCatalogConfig> | null): BillingCatalogConfig;
6
6
  declare function resolveBillingItem(items: BillingItem[] | undefined, key?: string | null): BillingItem | undefined;
7
+ declare function resolveBillingPurchasable(runtimeConfig: BillingRuntimeConfig | undefined, key?: string | null): BillingPurchasableEntry | undefined;
8
+ declare function buildBillingPurchaseRequest(payload: BillingActionPayload, runtimeConfig?: BillingRuntimeConfig | null): BillingPurchaseRequest | null;
9
+ declare function filterBillingPurchasableItems(items: BillingItem[] | undefined, runtimeConfig?: BillingRuntimeConfig | null): BillingItem[];
10
+ declare function buildBillingPaymentCallbackContext(request: Request, phase?: 'success' | 'failure' | 'finished'): Promise<BillingPaymentCallbackContext>;
7
11
  declare function resolveBillingSubscriptionProduct(subscription: BillingSubscriptionState | undefined, runtimeConfig: BillingRuntimeConfig | undefined): BillingProductSnapshot | undefined;
8
12
  declare function resolveBillingProductSnapshot(item?: BillingItem | null): BillingProductSnapshot | undefined;
9
13
  declare function deriveBillingCreditsState(credits?: BillingCreditsState | null, products?: BillingProductState[] | null, conversionRules?: BillingRuntimeConfig['conversionRules']): BillingCreditsState;
@@ -12,10 +16,21 @@ declare function normalizeBillingPurchaseStatus(status?: Partial<BillingPurchase
12
16
  declare function resolveBillingInterval(interval?: BillingInterval | null): BillingInterval | undefined;
13
17
  declare function buildBillingActionPayload(payload: BillingActionPayload, runtimeConfig?: BillingRuntimeConfig | null): BillingActionPayload;
14
18
 
19
+ interface NormalizedCasdoorProductId {
20
+ owner: string;
21
+ name: string;
22
+ }
23
+ declare function readBuyProductRedirectTo(value: unknown): string | undefined;
24
+ declare function normalizeCasdoorProductId(id: string): NormalizedCasdoorProductId;
25
+ declare function chooseCasdoorProviderName(product: Pick<BillingCasdoorProductDetail, 'providers' | 'providerObjs'>, preferredProviderName?: string): string;
26
+ declare function buildCasdoorBuyProductParams(input: BillingCasdoorBuyProductRequest): URLSearchParams;
27
+ declare function buildCasdoorBuyProductRequest(purchase: BillingPurchaseRequest, product: BillingCasdoorProductDetail, preferredProviderName?: string): BillingCasdoorBuyProductRequest;
28
+ declare function normalizeCasdoorBuyProductResponse(response: BillingCasdoorBuyProductResponse, fallbackRedirectTo?: string): BillingActionExecutionResult;
29
+
15
30
  declare function createBillingPaymentSuccessResponse(request: Request, options?: BillingPaymentSuccessRouteOptions): Promise<Response>;
16
31
  declare function createBillingPaymentSuccessRouteHandler(options?: BillingPaymentSuccessRouteOptions): (request: Request) => Promise<Response>;
17
32
 
18
33
  declare function createBillingPaymentFinishedResponse(request: Request, options?: BillingPaymentFinishedRouteOptions): Promise<Response>;
19
34
  declare function createBillingPaymentFinishedRouteHandler(options?: BillingPaymentFinishedRouteOptions): (request: Request) => Promise<Response>;
20
35
 
21
- export { BillingActionPayload, BillingCatalogConfig, BillingCreditsState, BillingEntitlementState, BillingInterval, BillingItem, BillingOrderHistoryItem, BillingPaymentFinishedRouteOptions, BillingPaymentHistoryItem, BillingPaymentSuccessRouteOptions, BillingProductSnapshot, BillingProductState, BillingPurchaseStatus, BillingRuntimeConfig, BillingSubscriptionState, buildBillingActionPayload, createBillingPaymentFinishedResponse, createBillingPaymentFinishedRouteHandler, createBillingPaymentSuccessResponse, createBillingPaymentSuccessRouteHandler, deriveBillingCreditsState, deriveBillingEntitlements, normalizeBillingCatalogConfig, normalizeBillingPurchaseStatus, normalizeBillingRuntimeConfig, resolveBillingInterval, resolveBillingItem, resolveBillingProductSnapshot, resolveBillingSubscriptionProduct };
36
+ export { BillingActionExecutionResult, BillingActionPayload, BillingCasdoorBuyProductRequest, BillingCasdoorBuyProductResponse, BillingCasdoorProductDetail, BillingCatalogConfig, BillingCreditsState, BillingEntitlementState, BillingInterval, BillingItem, BillingOrderHistoryItem, BillingPaymentCallbackContext, BillingPaymentFinishedRouteOptions, BillingPaymentHistoryItem, BillingPaymentSuccessRouteOptions, BillingProductSnapshot, BillingProductState, BillingPurchasableEntry, BillingPurchaseRequest, BillingPurchaseStatus, BillingRuntimeConfig, BillingSubscriptionState, type NormalizedCasdoorProductId, buildBillingActionPayload, buildBillingPaymentCallbackContext, buildBillingPurchaseRequest, buildCasdoorBuyProductParams, buildCasdoorBuyProductRequest, chooseCasdoorProviderName, createBillingPaymentFinishedResponse, createBillingPaymentFinishedRouteHandler, createBillingPaymentSuccessResponse, createBillingPaymentSuccessRouteHandler, deriveBillingCreditsState, deriveBillingEntitlements, filterBillingPurchasableItems, normalizeBillingCatalogConfig, normalizeBillingPurchaseStatus, normalizeBillingRuntimeConfig, normalizeCasdoorBuyProductResponse, normalizeCasdoorProductId, readBuyProductRedirectTo, resolveBillingInterval, resolveBillingItem, resolveBillingProductSnapshot, resolveBillingPurchasable, resolveBillingSubscriptionProduct };
@@ -3,33 +3,53 @@ import {
3
3
  createBillingPaymentFinishedRouteHandler,
4
4
  createBillingPaymentSuccessResponse,
5
5
  createBillingPaymentSuccessRouteHandler
6
- } from "../chunk-5ISF7ZAG.js";
6
+ } from "../chunk-ZCHLJYLN.js";
7
7
  import {
8
8
  buildBillingActionPayload,
9
+ buildBillingPaymentCallbackContext,
10
+ buildBillingPurchaseRequest,
11
+ buildCasdoorBuyProductParams,
12
+ buildCasdoorBuyProductRequest,
13
+ chooseCasdoorProviderName,
9
14
  deriveBillingCreditsState,
10
15
  deriveBillingEntitlements,
16
+ filterBillingPurchasableItems,
11
17
  normalizeBillingCatalogConfig,
12
18
  normalizeBillingPurchaseStatus,
13
19
  normalizeBillingRuntimeConfig,
20
+ normalizeCasdoorBuyProductResponse,
21
+ normalizeCasdoorProductId,
22
+ readBuyProductRedirectTo,
14
23
  resolveBillingInterval,
15
24
  resolveBillingItem,
16
25
  resolveBillingProductSnapshot,
26
+ resolveBillingPurchasable,
17
27
  resolveBillingSubscriptionProduct
18
- } from "../chunk-O3FKI5NT.js";
28
+ } from "../chunk-46V73LSW.js";
19
29
  export {
20
30
  buildBillingActionPayload,
31
+ buildBillingPaymentCallbackContext,
32
+ buildBillingPurchaseRequest,
33
+ buildCasdoorBuyProductParams,
34
+ buildCasdoorBuyProductRequest,
35
+ chooseCasdoorProviderName,
21
36
  createBillingPaymentFinishedResponse,
22
37
  createBillingPaymentFinishedRouteHandler,
23
38
  createBillingPaymentSuccessResponse,
24
39
  createBillingPaymentSuccessRouteHandler,
25
40
  deriveBillingCreditsState,
26
41
  deriveBillingEntitlements,
42
+ filterBillingPurchasableItems,
27
43
  normalizeBillingCatalogConfig,
28
44
  normalizeBillingPurchaseStatus,
29
45
  normalizeBillingRuntimeConfig,
46
+ normalizeCasdoorBuyProductResponse,
47
+ normalizeCasdoorProductId,
48
+ readBuyProductRedirectTo,
30
49
  resolveBillingInterval,
31
50
  resolveBillingItem,
32
51
  resolveBillingProductSnapshot,
52
+ resolveBillingPurchasable,
33
53
  resolveBillingSubscriptionProduct
34
54
  };
35
55
  //# sourceMappingURL=index.js.map
@@ -0,0 +1,494 @@
1
+ // src/billing/runtime.ts
2
+ function normalizeCasdoorProductId(id) {
3
+ const [owner, ...rest] = id.split("/");
4
+ const name = rest.join("/");
5
+ if (!owner || !name) {
6
+ throw new Error(`Invalid Casdoor product id: ${id}`);
7
+ }
8
+ return { owner, name };
9
+ }
10
+ function normalizeBillingRuntimeConfig(config) {
11
+ return {
12
+ catalogKey: config?.catalogKey ?? "default",
13
+ items: config?.items ?? [],
14
+ purchasableIds: config?.purchasableIds ?? [],
15
+ purchasables: config?.purchasables ?? [],
16
+ conversionRules: config?.conversionRules ?? [],
17
+ defaults: config?.defaults ?? {}
18
+ };
19
+ }
20
+ function normalizeBillingCatalogConfig(config) {
21
+ return {
22
+ ...normalizeBillingRuntimeConfig(config),
23
+ title: config?.title,
24
+ description: config?.description,
25
+ portalPath: config?.portalPath,
26
+ successPath: config?.successPath,
27
+ cancelPath: config?.cancelPath
28
+ };
29
+ }
30
+ function resolveBillingItem(items, key) {
31
+ if (!key) return void 0;
32
+ return items?.find((item) => item.key === key || item.backendRef.productId === key || item.backendRef.planId === key);
33
+ }
34
+ function isBillingPurchasableIdMatch(id, item) {
35
+ return id === item.key || id === item.backendRef.productId || "planId" in item.backendRef && id === item.backendRef.planId;
36
+ }
37
+ function resolveBillingPurchasable(runtimeConfig, key) {
38
+ if (!runtimeConfig || !key) {
39
+ return void 0;
40
+ }
41
+ const explicit = runtimeConfig.purchasables?.find(
42
+ (item2) => item2.key === key || item2.backendRef.productId === key || "planId" in item2.backendRef && item2.backendRef.planId === key
43
+ );
44
+ if (explicit) {
45
+ return explicit;
46
+ }
47
+ if (runtimeConfig.purchasableIds?.length) {
48
+ const matchingItem = resolveBillingItem(runtimeConfig.items, key);
49
+ if (!matchingItem) {
50
+ return void 0;
51
+ }
52
+ const allowed = runtimeConfig.purchasableIds.some((itemKey) => isBillingPurchasableIdMatch(itemKey, matchingItem));
53
+ if (!allowed) {
54
+ return void 0;
55
+ }
56
+ }
57
+ const item = resolveBillingItem(runtimeConfig.items, key);
58
+ if (!item) {
59
+ return void 0;
60
+ }
61
+ if (item.kind === "subscription") {
62
+ return {
63
+ key: item.key,
64
+ kind: "subscription",
65
+ title: item.title,
66
+ description: item.description,
67
+ enabled: true,
68
+ backendRef: {
69
+ productId: item.backendRef.productId,
70
+ planId: item.backendRef.planId,
71
+ priceId: item.backendRef.priceId
72
+ },
73
+ interval: item.interval,
74
+ hooks: void 0
75
+ };
76
+ }
77
+ return {
78
+ key: item.key,
79
+ kind: "product",
80
+ title: item.title,
81
+ description: item.description,
82
+ enabled: true,
83
+ backendRef: {
84
+ productId: item.backendRef.productId,
85
+ priceId: item.backendRef.priceId
86
+ },
87
+ quantity: void 0,
88
+ creditGrant: item.creditGrant,
89
+ creditRedeem: item.creditRedeem,
90
+ hooks: void 0
91
+ };
92
+ }
93
+ function buildBillingPurchaseRequest(payload, runtimeConfig) {
94
+ const config = normalizeBillingRuntimeConfig(runtimeConfig);
95
+ const purchasable = resolveBillingPurchasable(config, payload.key) ?? resolveBillingPurchasable(config, payload.productId);
96
+ if (!purchasable) {
97
+ return null;
98
+ }
99
+ let productOwner;
100
+ let productName;
101
+ try {
102
+ const normalized = normalizeCasdoorProductId(purchasable.backendRef.productId);
103
+ productOwner = normalized.owner;
104
+ productName = normalized.name;
105
+ } catch {
106
+ productOwner = void 0;
107
+ productName = void 0;
108
+ }
109
+ return {
110
+ kind: purchasable.kind,
111
+ key: purchasable.key,
112
+ productId: purchasable.backendRef.productId,
113
+ productOwner,
114
+ productName,
115
+ providerName: payload.providerName,
116
+ pricingName: payload.pricingName,
117
+ planName: payload.planName,
118
+ userName: payload.userName,
119
+ paymentEnv: payload.paymentEnv,
120
+ customPrice: payload.customPrice,
121
+ quantity: payload.quantity ?? 1,
122
+ returnTo: payload.returnTo,
123
+ metadata: payload.metadata
124
+ };
125
+ }
126
+ function filterBillingPurchasableItems(items, runtimeConfig) {
127
+ if (!runtimeConfig) {
128
+ return items ?? [];
129
+ }
130
+ const config = normalizeBillingRuntimeConfig(runtimeConfig);
131
+ if (!config.purchasableIds?.length && !config.purchasables?.length) {
132
+ return items ?? [];
133
+ }
134
+ return (items ?? []).filter((item) => {
135
+ const purchasable = resolveBillingPurchasable(config, item.key);
136
+ return Boolean(purchasable);
137
+ });
138
+ }
139
+ async function readRequestBody(request) {
140
+ if (request.method === "GET" || request.method === "HEAD") {
141
+ return null;
142
+ }
143
+ const rawBody = await request.clone().text();
144
+ if (!rawBody) {
145
+ return null;
146
+ }
147
+ const contentType = request.headers.get("content-type") ?? "";
148
+ if (contentType.includes("application/json")) {
149
+ try {
150
+ return JSON.parse(rawBody);
151
+ } catch {
152
+ return rawBody;
153
+ }
154
+ }
155
+ if (contentType.includes("application/x-www-form-urlencoded")) {
156
+ return Object.fromEntries(new URLSearchParams(rawBody).entries());
157
+ }
158
+ return rawBody;
159
+ }
160
+ async function buildBillingPaymentCallbackContext(request, phase) {
161
+ const url = new URL(request.url);
162
+ const params = {};
163
+ for (const [key, value] of url.searchParams.entries()) {
164
+ params[key] = value;
165
+ }
166
+ const paymentOwner = url.searchParams.get("paymentOwner") ?? url.searchParams.get("owner");
167
+ const paymentName = url.searchParams.get("paymentName") ?? url.searchParams.get("name");
168
+ const paymentId = url.searchParams.get("paymentId");
169
+ const orderId = url.searchParams.get("orderId");
170
+ const redirectTo = url.searchParams.get("redirect") ?? url.searchParams.get("returnTo");
171
+ const failureSignal = url.searchParams.get("error") || url.searchParams.get("status") === "failed";
172
+ const status = failureSignal ? "failure" : phase === "finished" ? "finished" : phase === "failure" ? "failure" : "success";
173
+ return {
174
+ request,
175
+ url,
176
+ searchParams: url.searchParams,
177
+ params,
178
+ paymentOwner,
179
+ paymentName,
180
+ paymentId,
181
+ orderId,
182
+ redirectTo,
183
+ status,
184
+ body: await readRequestBody(request)
185
+ };
186
+ }
187
+ function resolveBillingSubscriptionProduct(subscription, runtimeConfig) {
188
+ if (!subscription) return void 0;
189
+ if (subscription.product) return subscription.product;
190
+ const item = resolveBillingItem(runtimeConfig?.items, subscription.planKey ?? subscription.subscriptionId);
191
+ if (!item) return void 0;
192
+ return {
193
+ productKey: item.key,
194
+ productId: item.backendRef.productId,
195
+ title: item.title,
196
+ kind: item.kind,
197
+ planId: item.backendRef.planId,
198
+ priceId: item.backendRef.priceId,
199
+ interval: item.interval,
200
+ creditGrant: item.creditGrant,
201
+ creditRedeem: item.creditRedeem,
202
+ metadata: item.metadata
203
+ };
204
+ }
205
+ function resolveBillingProductSnapshot(item) {
206
+ if (!item) return void 0;
207
+ return {
208
+ productKey: item.key,
209
+ productId: item.backendRef.productId,
210
+ title: item.title,
211
+ kind: item.kind,
212
+ planId: item.backendRef.planId,
213
+ priceId: item.backendRef.priceId,
214
+ interval: item.interval,
215
+ creditGrant: item.creditGrant,
216
+ creditRedeem: item.creditRedeem,
217
+ metadata: item.metadata
218
+ };
219
+ }
220
+ function deriveBillingCreditsState(credits, products, conversionRules) {
221
+ if (credits) return credits;
222
+ const fromProducts = products?.reduce((total, product) => {
223
+ if (typeof product.creditsBalance === "number") {
224
+ return total + Number(product.creditsBalance);
225
+ }
226
+ if (!product.creditGrant) {
227
+ return total;
228
+ }
229
+ const quantity = Number(product.quantity ?? 1);
230
+ return total + Number(product.creditGrant.creditsPerUnit || 0) * quantity;
231
+ }, 0);
232
+ const fromRules = conversionRules?.reduce((total, rule) => {
233
+ if (rule.kind !== "grant-credits") return total;
234
+ return total + Number(rule.creditsPerUnit || 0);
235
+ }, 0);
236
+ return {
237
+ balance: Number(fromProducts ?? fromRules ?? 0)
238
+ };
239
+ }
240
+ function deriveBillingEntitlements(subscription, products, credits, runtimeConfig) {
241
+ const features = /* @__PURE__ */ new Set();
242
+ const limits = {};
243
+ const flags = {};
244
+ const creditBalance = credits?.balance ?? 0;
245
+ for (const item of runtimeConfig?.items ?? []) {
246
+ for (const feature of item.features ?? []) {
247
+ features.add(feature);
248
+ }
249
+ if (item.metadata?.tier) {
250
+ flags[item.metadata.tier] = true;
251
+ }
252
+ }
253
+ if (subscription?.status === "active" || subscription?.status === "trialing") {
254
+ flags.subscribed = true;
255
+ }
256
+ if (creditBalance > 0) {
257
+ flags.hasCredits = true;
258
+ limits.credits = creditBalance;
259
+ }
260
+ for (const product of products ?? []) {
261
+ if (product.owned) {
262
+ flags[`product:${product.productKey}`] = true;
263
+ }
264
+ }
265
+ return {
266
+ features: [...features],
267
+ limits,
268
+ flags
269
+ };
270
+ }
271
+ function normalizeBillingPurchaseStatus(status, order, payment) {
272
+ if (status) {
273
+ return {
274
+ actionKey: status.actionKey,
275
+ orderId: status.orderId,
276
+ paymentId: status.paymentId,
277
+ transactionId: status.transactionId,
278
+ status: status.status ?? "idle",
279
+ orderStatus: status.orderStatus,
280
+ paymentStatus: status.paymentStatus,
281
+ transactionStatus: status.transactionStatus,
282
+ redirectTo: status.redirectTo,
283
+ updatedAt: status.updatedAt
284
+ };
285
+ }
286
+ const orderStatus = order?.status;
287
+ const paymentStatus = payment?.status;
288
+ const normalizedStatus = paymentStatus === "paid" || orderStatus === "paid" ? "paid" : paymentStatus === "pending" || orderStatus === "pending" ? "pending" : paymentStatus === "failed" || orderStatus === "failed" ? "failed" : paymentStatus === "canceled" || orderStatus === "canceled" ? "canceled" : paymentStatus === "refunded" || orderStatus === "refunded" ? "refunded" : paymentStatus === "pending" ? "requires_payment" : "idle";
289
+ return {
290
+ actionKey: order?.orderId ?? payment?.paymentId,
291
+ orderId: order?.orderId,
292
+ paymentId: payment?.paymentId,
293
+ transactionId: payment?.transactionId ?? order?.transactionId,
294
+ status: normalizedStatus,
295
+ orderStatus,
296
+ paymentStatus,
297
+ transactionStatus: payment?.transactionId ? "linked" : void 0,
298
+ updatedAt: payment?.updatedAt ?? order?.updatedAt
299
+ };
300
+ }
301
+ function resolveBillingInterval(interval) {
302
+ return interval === "month" || interval === "year" ? interval : void 0;
303
+ }
304
+ function buildBillingActionPayload(payload, runtimeConfig) {
305
+ const config = normalizeBillingRuntimeConfig(runtimeConfig);
306
+ const item = resolveBillingItem(config.items, payload.key) ?? resolveBillingItem(config.items, payload.productId);
307
+ if (payload.kind === "subscribe" && item) {
308
+ return {
309
+ ...payload,
310
+ subscriptionConfig: payload.subscriptionConfig ?? {
311
+ productKey: item.key,
312
+ productId: item.backendRef.productId,
313
+ planId: item.backendRef.planId,
314
+ priceId: item.backendRef.priceId,
315
+ interval: item.interval ?? config.defaults?.defaultInterval,
316
+ quantity: payload.quantity ?? config.defaults?.defaultQuantity,
317
+ metadata: item.metadata
318
+ }
319
+ };
320
+ }
321
+ if ((payload.kind === "purchase" || payload.kind === "manage" || payload.kind === "upgrade" || payload.kind === "cancel") && item) {
322
+ return {
323
+ ...payload,
324
+ productConfig: payload.productConfig ?? {
325
+ productKey: item.key,
326
+ productId: item.backendRef.productId,
327
+ priceId: item.backendRef.priceId,
328
+ quantity: payload.quantity ?? config.defaults?.defaultQuantity,
329
+ creditGrant: item.creditGrant,
330
+ creditRedeem: item.creditRedeem,
331
+ metadata: item.metadata
332
+ }
333
+ };
334
+ }
335
+ return payload;
336
+ }
337
+
338
+ // src/billing/casdoor-purchase.ts
339
+ function isNonEmptyString(value) {
340
+ return typeof value === "string" && value.trim().length > 0;
341
+ }
342
+ function isRecord(value) {
343
+ return typeof value === "object" && value !== null;
344
+ }
345
+ function extractString(value) {
346
+ return isNonEmptyString(value) ? value : void 0;
347
+ }
348
+ function parseCasdoorErrorPayload(message) {
349
+ if (!isNonEmptyString(message)) {
350
+ return void 0;
351
+ }
352
+ const trimmed = message.trim();
353
+ if (!trimmed.startsWith("{")) {
354
+ return { message: trimmed };
355
+ }
356
+ try {
357
+ const parsed = JSON.parse(trimmed);
358
+ if (!isRecord(parsed)) {
359
+ return { message: trimmed };
360
+ }
361
+ const detail = isRecord(parsed.detail) ? {
362
+ ...parsed.detail,
363
+ field: extractString(parsed.detail.field),
364
+ value: extractString(parsed.detail.value),
365
+ issue: extractString(parsed.detail.issue),
366
+ location: extractString(parsed.detail.location)
367
+ } : void 0;
368
+ return {
369
+ ...parsed,
370
+ code: extractString(parsed.code),
371
+ message: extractString(parsed.message) ?? extractString(parsed.msg) ?? extractString(detail?.issue) ?? trimmed,
372
+ detail
373
+ };
374
+ } catch {
375
+ return { message: trimmed };
376
+ }
377
+ }
378
+ function readBuyProductRedirectTo(value) {
379
+ if (!isRecord(value)) {
380
+ return void 0;
381
+ }
382
+ for (const key of ["redirectTo", "redirectUrl", "redirect_url", "url", "href", "location"]) {
383
+ const candidate = value[key];
384
+ if (isNonEmptyString(candidate)) {
385
+ return candidate;
386
+ }
387
+ }
388
+ return void 0;
389
+ }
390
+ function normalizeCasdoorProductId2(id) {
391
+ const [owner, ...rest] = id.split("/");
392
+ const name = rest.join("/");
393
+ if (!isNonEmptyString(owner) || !isNonEmptyString(name)) {
394
+ throw new Error(`Invalid Casdoor product id: ${id}`);
395
+ }
396
+ return { owner, name };
397
+ }
398
+ function chooseProviderFromObjects(providerObjs, preferredProviderName) {
399
+ if (isNonEmptyString(preferredProviderName)) {
400
+ return preferredProviderName;
401
+ }
402
+ return providerObjs?.find((provider) => isNonEmptyString(provider.name))?.name;
403
+ }
404
+ function chooseCasdoorProviderName(product, preferredProviderName) {
405
+ if (isNonEmptyString(preferredProviderName)) {
406
+ return preferredProviderName;
407
+ }
408
+ const fromProviders = product.providers?.find(isNonEmptyString);
409
+ if (fromProviders) {
410
+ return fromProviders;
411
+ }
412
+ const fromProviderObjs = chooseProviderFromObjects(product.providerObjs, preferredProviderName);
413
+ if (fromProviderObjs) {
414
+ return fromProviderObjs;
415
+ }
416
+ throw new Error("No providerName available for Casdoor buy-product request.");
417
+ }
418
+ function buildCasdoorBuyProductParams(input) {
419
+ const params = new URLSearchParams();
420
+ params.set("id", input.id);
421
+ params.set("providerName", input.providerName);
422
+ params.set("pricingName", input.pricingName ?? "");
423
+ params.set("planName", input.planName ?? "");
424
+ params.set("userName", input.userName ?? "");
425
+ params.set("paymentEnv", input.paymentEnv ?? "");
426
+ params.set("customPrice", String(input.customPrice ?? 0));
427
+ return params;
428
+ }
429
+ function buildCasdoorBuyProductRequest(purchase, product, preferredProviderName) {
430
+ const providerName = chooseCasdoorProviderName(product, purchase.providerName ?? preferredProviderName);
431
+ const productId = `${product.owner}/${product.name}`;
432
+ return {
433
+ id: productId,
434
+ providerName,
435
+ pricingName: purchase.pricingName ?? "",
436
+ planName: purchase.planName ?? "",
437
+ userName: purchase.userName ?? "",
438
+ paymentEnv: purchase.paymentEnv ?? "",
439
+ customPrice: purchase.customPrice ?? 0
440
+ };
441
+ }
442
+ function normalizeCasdoorBuyProductStatus(status) {
443
+ const statusText = typeof status === "string" ? status.toLowerCase() : "";
444
+ if (statusText.includes("error") || statusText.includes("fail") || statusText.includes("cancel")) {
445
+ return "failed";
446
+ }
447
+ if (statusText.includes("pend") || statusText.includes("require")) {
448
+ return "pending";
449
+ }
450
+ return "succeeded";
451
+ }
452
+ function normalizeCasdoorBuyProductResponse(response, fallbackRedirectTo) {
453
+ const errorPayload = parseCasdoorErrorPayload(response.msg);
454
+ const redirectTo = readBuyProductRedirectTo(response.data) ?? readBuyProductRedirectTo(response.data2) ?? readBuyProductRedirectTo(response.data3) ?? fallbackRedirectTo;
455
+ const status = normalizeCasdoorBuyProductStatus(response.status);
456
+ if (status === "failed") {
457
+ return {
458
+ status,
459
+ redirectTo,
460
+ message: errorPayload?.message ?? response.msg ?? "Casdoor buy-product failed.",
461
+ errorCode: errorPayload?.code,
462
+ rawResult: response
463
+ };
464
+ }
465
+ return {
466
+ status,
467
+ redirectTo,
468
+ rawResult: response
469
+ };
470
+ }
471
+
472
+ export {
473
+ normalizeBillingRuntimeConfig,
474
+ normalizeBillingCatalogConfig,
475
+ resolveBillingItem,
476
+ resolveBillingPurchasable,
477
+ buildBillingPurchaseRequest,
478
+ filterBillingPurchasableItems,
479
+ buildBillingPaymentCallbackContext,
480
+ resolveBillingSubscriptionProduct,
481
+ resolveBillingProductSnapshot,
482
+ deriveBillingCreditsState,
483
+ deriveBillingEntitlements,
484
+ normalizeBillingPurchaseStatus,
485
+ resolveBillingInterval,
486
+ buildBillingActionPayload,
487
+ readBuyProductRedirectTo,
488
+ normalizeCasdoorProductId2 as normalizeCasdoorProductId,
489
+ chooseCasdoorProviderName,
490
+ buildCasdoorBuyProductParams,
491
+ buildCasdoorBuyProductRequest,
492
+ normalizeCasdoorBuyProductResponse
493
+ };
494
+ //# sourceMappingURL=chunk-46V73LSW.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/billing/runtime.ts","../src/billing/casdoor-purchase.ts"],"sourcesContent":["import type {\n BillingActionPayload,\n BillingCatalogConfig,\n BillingCreditsState,\n BillingEntitlementState,\n BillingInterval,\n BillingItem,\n BillingPurchasableEntry,\n BillingPaymentCallbackContext,\n BillingPurchaseRequest,\n BillingOrderHistoryItem,\n BillingPaymentHistoryItem,\n BillingProductSnapshot,\n BillingProductState,\n BillingPurchaseStatus,\n BillingRuntimeConfig,\n BillingSubscriptionHistoryItem,\n BillingSubscriptionState,\n} from './types';\n\nfunction normalizeCasdoorProductId(id: string): { owner: string; name: string } {\n const [owner, ...rest] = id.split('/');\n const name = rest.join('/');\n\n if (!owner || !name) {\n throw new Error(`Invalid Casdoor product id: ${id}`);\n }\n\n return { owner, name };\n}\n\nexport function normalizeBillingRuntimeConfig(config?: Partial<BillingRuntimeConfig> | null): BillingRuntimeConfig {\n return {\n catalogKey: config?.catalogKey ?? 'default',\n items: config?.items ?? [],\n purchasableIds: config?.purchasableIds ?? [],\n purchasables: config?.purchasables ?? [],\n conversionRules: config?.conversionRules ?? [],\n defaults: config?.defaults ?? {},\n };\n}\n\nexport function normalizeBillingCatalogConfig(config?: Partial<BillingCatalogConfig> | null): BillingCatalogConfig {\n return {\n ...normalizeBillingRuntimeConfig(config),\n title: config?.title,\n description: config?.description,\n portalPath: config?.portalPath,\n successPath: config?.successPath,\n cancelPath: config?.cancelPath,\n };\n}\n\nexport function resolveBillingItem(items: BillingItem[] | undefined, key?: string | null): BillingItem | undefined {\n if (!key) return undefined;\n return items?.find((item) => item.key === key || item.backendRef.productId === key || item.backendRef.planId === key);\n}\n\nfunction isBillingPurchasableIdMatch(id: string, item: BillingItem | BillingPurchasableEntry): boolean {\n return id === item.key || id === item.backendRef.productId || ('planId' in item.backendRef && id === item.backendRef.planId);\n}\n\nexport function resolveBillingPurchasable(\n runtimeConfig: BillingRuntimeConfig | undefined,\n key?: string | null,\n): BillingPurchasableEntry | undefined {\n if (!runtimeConfig || !key) {\n return undefined;\n }\n\n const explicit = runtimeConfig.purchasables?.find(\n (item) => item.key === key || item.backendRef.productId === key || ('planId' in item.backendRef && item.backendRef.planId === key),\n );\n if (explicit) {\n return explicit;\n }\n\n if (runtimeConfig.purchasableIds?.length) {\n const matchingItem = resolveBillingItem(runtimeConfig.items, key);\n if (!matchingItem) {\n return undefined;\n }\n\n const allowed = runtimeConfig.purchasableIds.some((itemKey) => isBillingPurchasableIdMatch(itemKey, matchingItem));\n if (!allowed) {\n return undefined;\n }\n }\n\n const item = resolveBillingItem(runtimeConfig.items, key);\n if (!item) {\n return undefined;\n }\n\n if (item.kind === 'subscription') {\n return {\n key: item.key,\n kind: 'subscription',\n title: item.title,\n description: item.description,\n enabled: true,\n backendRef: {\n productId: item.backendRef.productId,\n planId: item.backendRef.planId,\n priceId: item.backendRef.priceId,\n },\n interval: item.interval,\n hooks: undefined,\n };\n }\n\n return {\n key: item.key,\n kind: 'product',\n title: item.title,\n description: item.description,\n enabled: true,\n backendRef: {\n productId: item.backendRef.productId,\n priceId: item.backendRef.priceId,\n },\n quantity: undefined,\n creditGrant: item.creditGrant,\n creditRedeem: item.creditRedeem,\n hooks: undefined,\n };\n}\n\nexport function buildBillingPurchaseRequest(\n payload: BillingActionPayload,\n runtimeConfig?: BillingRuntimeConfig | null,\n): BillingPurchaseRequest | null {\n const config = normalizeBillingRuntimeConfig(runtimeConfig);\n const purchasable = resolveBillingPurchasable(config, payload.key) ?? resolveBillingPurchasable(config, payload.productId);\n if (!purchasable) {\n return null;\n }\n\n let productOwner: string | undefined;\n let productName: string | undefined;\n try {\n const normalized = normalizeCasdoorProductId(purchasable.backendRef.productId);\n productOwner = normalized.owner;\n productName = normalized.name;\n } catch {\n productOwner = undefined;\n productName = undefined;\n }\n\n return {\n kind: purchasable.kind,\n key: purchasable.key,\n productId: purchasable.backendRef.productId,\n productOwner,\n productName,\n providerName: payload.providerName,\n pricingName: payload.pricingName,\n planName: payload.planName,\n userName: payload.userName,\n paymentEnv: payload.paymentEnv,\n customPrice: payload.customPrice,\n quantity: payload.quantity ?? 1,\n returnTo: payload.returnTo,\n metadata: payload.metadata,\n };\n}\n\nexport function filterBillingPurchasableItems(\n items: BillingItem[] | undefined,\n runtimeConfig?: BillingRuntimeConfig | null,\n): BillingItem[] {\n if (!runtimeConfig) {\n return items ?? [];\n }\n\n const config = normalizeBillingRuntimeConfig(runtimeConfig);\n if (!config.purchasableIds?.length && !config.purchasables?.length) {\n return items ?? [];\n }\n\n return (items ?? []).filter((item) => {\n const purchasable = resolveBillingPurchasable(config, item.key);\n return Boolean(purchasable);\n });\n}\n\nasync function readRequestBody(request: Request): Promise<unknown> {\n if (request.method === 'GET' || request.method === 'HEAD') {\n return null;\n }\n\n const rawBody = await request.clone().text();\n if (!rawBody) {\n return null;\n }\n\n const contentType = request.headers.get('content-type') ?? '';\n if (contentType.includes('application/json')) {\n try {\n return JSON.parse(rawBody);\n } catch {\n return rawBody;\n }\n }\n\n if (contentType.includes('application/x-www-form-urlencoded')) {\n return Object.fromEntries(new URLSearchParams(rawBody).entries());\n }\n\n return rawBody;\n}\n\nexport async function buildBillingPaymentCallbackContext(\n request: Request,\n phase?: 'success' | 'failure' | 'finished',\n): Promise<BillingPaymentCallbackContext> {\n const url = new URL(request.url);\n const params: Record<string, string> = {};\n\n for (const [key, value] of url.searchParams.entries()) {\n params[key] = value;\n }\n\n const paymentOwner = url.searchParams.get('paymentOwner') ?? url.searchParams.get('owner');\n const paymentName = url.searchParams.get('paymentName') ?? url.searchParams.get('name');\n const paymentId = url.searchParams.get('paymentId');\n const orderId = url.searchParams.get('orderId');\n const redirectTo = url.searchParams.get('redirect') ?? url.searchParams.get('returnTo');\n const failureSignal = url.searchParams.get('error') || url.searchParams.get('status') === 'failed';\n const status: BillingPaymentCallbackContext['status'] = failureSignal\n ? 'failure'\n : phase === 'finished'\n ? 'finished'\n : phase === 'failure'\n ? 'failure'\n : 'success';\n\n return {\n request,\n url,\n searchParams: url.searchParams,\n params,\n paymentOwner,\n paymentName,\n paymentId,\n orderId,\n redirectTo,\n status,\n body: await readRequestBody(request),\n };\n}\n\nexport function resolveBillingSubscriptionProduct(\n subscription: BillingSubscriptionState | undefined,\n runtimeConfig: BillingRuntimeConfig | undefined,\n): BillingProductSnapshot | undefined {\n if (!subscription) return undefined;\n if (subscription.product) return subscription.product;\n\n const item = resolveBillingItem(runtimeConfig?.items, subscription.planKey ?? subscription.subscriptionId);\n if (!item) return undefined;\n\n return {\n productKey: item.key,\n productId: item.backendRef.productId,\n title: item.title,\n kind: item.kind,\n planId: item.backendRef.planId,\n priceId: item.backendRef.priceId,\n interval: item.interval,\n creditGrant: item.creditGrant,\n creditRedeem: item.creditRedeem,\n metadata: item.metadata,\n };\n}\n\nexport function resolveBillingProductSnapshot(item?: BillingItem | null): BillingProductSnapshot | undefined {\n if (!item) return undefined;\n return {\n productKey: item.key,\n productId: item.backendRef.productId,\n title: item.title,\n kind: item.kind,\n planId: item.backendRef.planId,\n priceId: item.backendRef.priceId,\n interval: item.interval,\n creditGrant: item.creditGrant,\n creditRedeem: item.creditRedeem,\n metadata: item.metadata,\n };\n}\n\nexport function deriveBillingCreditsState(\n credits?: BillingCreditsState | null,\n products?: BillingProductState[] | null,\n conversionRules?: BillingRuntimeConfig['conversionRules'],\n): BillingCreditsState {\n if (credits) return credits;\n\n const fromProducts = products?.reduce((total, product) => {\n if (typeof product.creditsBalance === 'number') {\n return total + Number(product.creditsBalance);\n }\n\n if (!product.creditGrant) {\n return total;\n }\n\n const quantity = Number(product.quantity ?? 1);\n return total + Number(product.creditGrant.creditsPerUnit || 0) * quantity;\n }, 0);\n\n const fromRules = conversionRules?.reduce((total, rule) => {\n if (rule.kind !== 'grant-credits') return total;\n return total + Number(rule.creditsPerUnit || 0);\n }, 0);\n\n return {\n balance: Number(fromProducts ?? fromRules ?? 0),\n };\n}\n\nexport function deriveBillingEntitlements(\n subscription: BillingSubscriptionState | undefined,\n products: BillingProductState[] | undefined,\n credits: BillingCreditsState | undefined,\n runtimeConfig: BillingRuntimeConfig | undefined,\n): BillingEntitlementState {\n const features = new Set<string>();\n const limits: Record<string, number> = {};\n const flags: Record<string, boolean> = {};\n const creditBalance = credits?.balance ?? 0;\n\n for (const item of runtimeConfig?.items ?? []) {\n for (const feature of item.features ?? []) {\n features.add(feature);\n }\n if (item.metadata?.tier) {\n flags[item.metadata.tier] = true;\n }\n }\n\n if (subscription?.status === 'active' || subscription?.status === 'trialing') {\n flags.subscribed = true;\n }\n\n if (creditBalance > 0) {\n flags.hasCredits = true;\n limits.credits = creditBalance;\n }\n\n for (const product of products ?? []) {\n if (product.owned) {\n flags[`product:${product.productKey}`] = true;\n }\n }\n\n return {\n features: [...features],\n limits,\n flags,\n };\n}\n\nexport function normalizeBillingPurchaseStatus(\n status?: Partial<BillingPurchaseStatus> | null,\n order?: BillingOrderHistoryItem | null,\n payment?: BillingPaymentHistoryItem | null,\n): BillingPurchaseStatus {\n if (status) {\n return {\n actionKey: status.actionKey,\n orderId: status.orderId,\n paymentId: status.paymentId,\n transactionId: status.transactionId,\n status: status.status ?? 'idle',\n orderStatus: status.orderStatus,\n paymentStatus: status.paymentStatus,\n transactionStatus: status.transactionStatus,\n redirectTo: status.redirectTo,\n updatedAt: status.updatedAt,\n };\n }\n\n const orderStatus = order?.status;\n const paymentStatus = payment?.status;\n const normalizedStatus =\n paymentStatus === 'paid' || orderStatus === 'paid'\n ? 'paid'\n : paymentStatus === 'pending' || orderStatus === 'pending'\n ? 'pending'\n : paymentStatus === 'failed' || orderStatus === 'failed'\n ? 'failed'\n : paymentStatus === 'canceled' || orderStatus === 'canceled'\n ? 'canceled'\n : paymentStatus === 'refunded' || orderStatus === 'refunded'\n ? 'refunded'\n : paymentStatus === 'pending'\n ? 'requires_payment'\n : 'idle';\n\n return {\n actionKey: order?.orderId ?? payment?.paymentId,\n orderId: order?.orderId,\n paymentId: payment?.paymentId,\n transactionId: payment?.transactionId ?? order?.transactionId,\n status: normalizedStatus,\n orderStatus,\n paymentStatus,\n transactionStatus: payment?.transactionId ? 'linked' : undefined,\n updatedAt: payment?.updatedAt ?? order?.updatedAt,\n };\n}\n\nexport function resolveBillingInterval(interval?: BillingInterval | null): BillingInterval | undefined {\n return interval === 'month' || interval === 'year' ? interval : undefined;\n}\n\nexport function buildBillingActionPayload(\n payload: BillingActionPayload,\n runtimeConfig?: BillingRuntimeConfig | null,\n): BillingActionPayload {\n const config = normalizeBillingRuntimeConfig(runtimeConfig);\n const item = resolveBillingItem(config.items, payload.key) ?? resolveBillingItem(config.items, payload.productId);\n\n if (payload.kind === 'subscribe' && item) {\n return {\n ...payload,\n subscriptionConfig: payload.subscriptionConfig ?? {\n productKey: item.key,\n productId: item.backendRef.productId,\n planId: item.backendRef.planId,\n priceId: item.backendRef.priceId,\n interval: item.interval ?? config.defaults?.defaultInterval,\n quantity: payload.quantity ?? config.defaults?.defaultQuantity,\n metadata: item.metadata,\n },\n };\n }\n\n if ((payload.kind === 'purchase' || payload.kind === 'manage' || payload.kind === 'upgrade' || payload.kind === 'cancel') && item) {\n return {\n ...payload,\n productConfig: payload.productConfig ?? {\n productKey: item.key,\n productId: item.backendRef.productId,\n priceId: item.backendRef.priceId,\n quantity: payload.quantity ?? config.defaults?.defaultQuantity,\n creditGrant: item.creditGrant,\n creditRedeem: item.creditRedeem,\n metadata: item.metadata,\n },\n };\n }\n\n return payload;\n}\n","import type {\n BillingActionExecutionResult,\n BillingCasdoorBuyProductRequest,\n BillingCasdoorBuyProductResponse,\n BillingCasdoorErrorPayload,\n BillingCasdoorProductDetail,\n BillingCasdoorProviderOption,\n BillingPurchaseRequest,\n} from './types';\n\nexport interface NormalizedCasdoorProductId {\n owner: string;\n name: string;\n}\n\nfunction isNonEmptyString(value: unknown): value is string {\n return typeof value === 'string' && value.trim().length > 0;\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null;\n}\n\nfunction extractString(value: unknown): string | undefined {\n return isNonEmptyString(value) ? value : undefined;\n}\n\nfunction parseCasdoorErrorPayload(message: string | undefined): BillingCasdoorErrorPayload | undefined {\n if (!isNonEmptyString(message)) {\n return undefined;\n }\n\n const trimmed = message.trim();\n if (!trimmed.startsWith('{')) {\n return { message: trimmed };\n }\n\n try {\n const parsed = JSON.parse(trimmed) as unknown;\n if (!isRecord(parsed)) {\n return { message: trimmed };\n }\n\n const detail = isRecord(parsed.detail)\n ? {\n ...parsed.detail,\n field: extractString(parsed.detail.field),\n value: extractString(parsed.detail.value),\n issue: extractString(parsed.detail.issue),\n location: extractString(parsed.detail.location),\n }\n : undefined;\n\n return {\n ...parsed,\n code: extractString(parsed.code),\n message: extractString(parsed.message) ?? extractString(parsed.msg) ?? extractString(detail?.issue) ?? trimmed,\n detail,\n };\n } catch {\n return { message: trimmed };\n }\n}\n\nexport function readBuyProductRedirectTo(value: unknown): string | undefined {\n if (!isRecord(value)) {\n return undefined;\n }\n\n for (const key of ['redirectTo', 'redirectUrl', 'redirect_url', 'url', 'href', 'location']) {\n const candidate = value[key];\n if (isNonEmptyString(candidate)) {\n return candidate;\n }\n }\n\n return undefined;\n}\n\nexport function normalizeCasdoorProductId(id: string): NormalizedCasdoorProductId {\n const [owner, ...rest] = id.split('/');\n const name = rest.join('/');\n\n if (!isNonEmptyString(owner) || !isNonEmptyString(name)) {\n throw new Error(`Invalid Casdoor product id: ${id}`);\n }\n\n return { owner, name };\n}\n\nfunction chooseProviderFromObjects(\n providerObjs: BillingCasdoorProviderOption[] | undefined,\n preferredProviderName?: string,\n): string | undefined {\n if (isNonEmptyString(preferredProviderName)) {\n return preferredProviderName;\n }\n\n return providerObjs?.find((provider) => isNonEmptyString(provider.name))?.name;\n}\n\nexport function chooseCasdoorProviderName(\n product: Pick<BillingCasdoorProductDetail, 'providers' | 'providerObjs'>,\n preferredProviderName?: string,\n): string {\n if (isNonEmptyString(preferredProviderName)) {\n return preferredProviderName;\n }\n\n const fromProviders = product.providers?.find(isNonEmptyString);\n if (fromProviders) {\n return fromProviders;\n }\n\n const fromProviderObjs = chooseProviderFromObjects(product.providerObjs, preferredProviderName);\n if (fromProviderObjs) {\n return fromProviderObjs;\n }\n\n throw new Error('No providerName available for Casdoor buy-product request.');\n}\n\nexport function buildCasdoorBuyProductParams(\n input: BillingCasdoorBuyProductRequest,\n): URLSearchParams {\n const params = new URLSearchParams();\n params.set('id', input.id);\n params.set('providerName', input.providerName);\n params.set('pricingName', input.pricingName ?? '');\n params.set('planName', input.planName ?? '');\n params.set('userName', input.userName ?? '');\n params.set('paymentEnv', input.paymentEnv ?? '');\n params.set('customPrice', String(input.customPrice ?? 0));\n return params;\n}\n\nexport function buildCasdoorBuyProductRequest(\n purchase: BillingPurchaseRequest,\n product: BillingCasdoorProductDetail,\n preferredProviderName?: string,\n): BillingCasdoorBuyProductRequest {\n const providerName = chooseCasdoorProviderName(product, purchase.providerName ?? preferredProviderName);\n const productId = `${product.owner}/${product.name}`;\n\n return {\n id: productId,\n providerName,\n pricingName: purchase.pricingName ?? '',\n planName: purchase.planName ?? '',\n userName: purchase.userName ?? '',\n paymentEnv: purchase.paymentEnv ?? '',\n customPrice: purchase.customPrice ?? 0,\n };\n}\n\nfunction normalizeCasdoorBuyProductStatus(status: string | undefined): 'succeeded' | 'pending' | 'failed' {\n const statusText = typeof status === 'string' ? status.toLowerCase() : '';\n if (statusText.includes('error') || statusText.includes('fail') || statusText.includes('cancel')) {\n return 'failed';\n }\n if (statusText.includes('pend') || statusText.includes('require')) {\n return 'pending';\n }\n return 'succeeded';\n}\n\nexport function normalizeCasdoorBuyProductResponse(\n response: BillingCasdoorBuyProductResponse,\n fallbackRedirectTo?: string,\n): BillingActionExecutionResult {\n const errorPayload = parseCasdoorErrorPayload(response.msg);\n const redirectTo =\n readBuyProductRedirectTo(response.data) ??\n readBuyProductRedirectTo(response.data2) ??\n readBuyProductRedirectTo(response.data3) ??\n fallbackRedirectTo;\n const status = normalizeCasdoorBuyProductStatus(response.status);\n\n if (status === 'failed') {\n return {\n status,\n redirectTo,\n message: errorPayload?.message ?? response.msg ?? 'Casdoor buy-product failed.',\n errorCode: errorPayload?.code,\n rawResult: response,\n };\n }\n\n return {\n status,\n redirectTo,\n rawResult: response,\n };\n}\n"],"mappings":";AAoBA,SAAS,0BAA0B,IAA6C;AAC9E,QAAM,CAAC,OAAO,GAAG,IAAI,IAAI,GAAG,MAAM,GAAG;AACrC,QAAM,OAAO,KAAK,KAAK,GAAG;AAE1B,MAAI,CAAC,SAAS,CAAC,MAAM;AACnB,UAAM,IAAI,MAAM,+BAA+B,EAAE,EAAE;AAAA,EACrD;AAEA,SAAO,EAAE,OAAO,KAAK;AACvB;AAEO,SAAS,8BAA8B,QAAqE;AACjH,SAAO;AAAA,IACL,YAAY,QAAQ,cAAc;AAAA,IAClC,OAAO,QAAQ,SAAS,CAAC;AAAA,IACzB,gBAAgB,QAAQ,kBAAkB,CAAC;AAAA,IAC3C,cAAc,QAAQ,gBAAgB,CAAC;AAAA,IACvC,iBAAiB,QAAQ,mBA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