@windrun-huaiin/backend-core 31.0.0 → 31.0.2

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.
Files changed (26) hide show
  1. package/dist/app/api/user/anonymous/init/fingerprint-only-route.d.ts +8 -0
  2. package/dist/app/api/user/anonymous/init/fingerprint-only-route.d.ts.map +1 -0
  3. package/dist/app/api/user/anonymous/init/fingerprint-only-route.js +20 -0
  4. package/dist/app/api/user/anonymous/init/fingerprint-only-route.mjs +18 -0
  5. package/dist/app/api/user/anonymous/init/route-shared.d.ts +10 -0
  6. package/dist/app/api/user/anonymous/init/route-shared.d.ts.map +1 -0
  7. package/dist/app/api/user/anonymous/init/route-shared.js +557 -0
  8. package/dist/app/api/user/anonymous/init/route-shared.mjs +555 -0
  9. package/dist/app/api/user/anonymous/init/route.d.ts +3 -3
  10. package/dist/app/api/user/anonymous/init/route.d.ts.map +1 -1
  11. package/dist/app/api/user/anonymous/init/route.js +6 -553
  12. package/dist/app/api/user/anonymous/init/route.mjs +7 -554
  13. package/dist/app/api/user/credit-overview/route.d.ts +1 -0
  14. package/dist/app/api/user/credit-overview/route.d.ts.map +1 -1
  15. package/dist/app/api/user/credit-overview/route.js +8 -0
  16. package/dist/app/api/user/credit-overview/route.mjs +8 -0
  17. package/dist/lib/credit-overview.d.ts +1 -0
  18. package/dist/lib/credit-overview.d.ts.map +1 -1
  19. package/dist/lib/credit-overview.js +37 -21
  20. package/dist/lib/credit-overview.mjs +37 -21
  21. package/package.json +9 -4
  22. package/src/app/api/user/anonymous/init/fingerprint-only-route.ts +14 -0
  23. package/src/app/api/user/anonymous/init/route-shared.ts +710 -0
  24. package/src/app/api/user/anonymous/init/route.ts +7 -711
  25. package/src/app/api/user/credit-overview/route.ts +9 -0
  26. package/src/lib/credit-overview.ts +48 -18
@@ -15,6 +15,14 @@ var server = require('@windrun-huaiin/third-ui/main/money-price/server');
15
15
  BigInt.prototype.toJSON = function () {
16
16
  return this.toString();
17
17
  };
18
+ const DEFAULT_ENABLED_BILLING_TYPES = ['monthly', 'yearly', 'onetime'];
19
+ const SUBSCRIPTION_BILLING_TYPES = new Set(['monthly', 'yearly']);
20
+ function normalizeEnabledBillingTypes(enabledBillingTypes) {
21
+ const normalized = Array.from(new Set(((enabledBillingTypes === null || enabledBillingTypes === void 0 ? void 0 : enabledBillingTypes.length) ? enabledBillingTypes : DEFAULT_ENABLED_BILLING_TYPES)
22
+ .map((billingType) => billingType.trim())
23
+ .filter((billingType) => billingType.length > 0)));
24
+ return normalized.length ? normalized : DEFAULT_ENABLED_BILLING_TYPES;
25
+ }
18
26
  function buildCreditOverviewPayload(options) {
19
27
  return tslib.__awaiter(this, void 0, void 0, function* () {
20
28
  var _a, _b, _c, _d;
@@ -22,16 +30,19 @@ function buildCreditOverviewPayload(options) {
22
30
  if (!authUser) {
23
31
  return null;
24
32
  }
25
- const { locale, defaultLocale = 'en', localePrefixAsNeeded = true, translations, pricingPath = '/pricing', checkoutApiEndpoint = '/api/stripe/checkout', customerPortalApiEndpoint = '/api/stripe/customer-portal', } = options;
33
+ const { locale, defaultLocale = 'en', localePrefixAsNeeded = true, translations, pricingPath = '/pricing', checkoutApiEndpoint = '/api/stripe/checkout', customerPortalApiEndpoint = '/api/stripe/customer-portal', enabledBillingTypes: enabledBillingTypesOption, } = options;
26
34
  const { user } = authUser;
27
35
  const enableSubscriptionUpgrade = process.env.ENABLE_STRIPE_SUBSCRIPTION_UPGRADE !== 'false';
36
+ const enabledBillingTypes = normalizeEnabledBillingTypes(enabledBillingTypesOption);
37
+ const subscriptionBillingEnabled = enabledBillingTypes.some((billingType) => SUBSCRIPTION_BILLING_TYPES.has(billingType));
38
+ const onetimeBillingEnabled = enabledBillingTypes.includes('onetime');
28
39
  const [credit, subscription, moneyPriceData] = yield Promise.all([
29
40
  credit_service.creditService.getCredit(user.userId),
30
41
  subscription_service.subscriptionService.getActiveSubscription(user.userId),
31
42
  server.buildMoneyPriceData({
32
43
  locale,
33
44
  currency: moneyPriceConfig.moneyPriceConfig.display.currency,
34
- enabledBillingTypes: ['monthly', 'yearly', 'onetime'],
45
+ enabledBillingTypes,
35
46
  }),
36
47
  ]);
37
48
  if (!credit) {
@@ -43,10 +54,10 @@ function buildCreditOverviewPayload(options) {
43
54
  subscription,
44
55
  });
45
56
  const totalBalance = ((_a = credit.balanceFree) !== null && _a !== void 0 ? _a : 0) +
46
- ((_b = credit.balancePaid) !== null && _b !== void 0 ? _b : 0) +
47
- ((_c = credit.balanceOneTimePaid) !== null && _c !== void 0 ? _c : 0);
57
+ (subscriptionBillingEnabled ? (_b = credit.balancePaid) !== null && _b !== void 0 ? _b : 0 : 0) +
58
+ (onetimeBillingEnabled ? (_c = credit.balanceOneTimePaid) !== null && _c !== void 0 ? _c : 0 : 0);
48
59
  const buckets = [
49
- ...(credit.balancePaid > 0
60
+ ...(subscriptionBillingEnabled && credit.balancePaid > 0
50
61
  ? [{
51
62
  kind: 'subscription',
52
63
  balance: credit.balancePaid,
@@ -54,7 +65,7 @@ function buildCreditOverviewPayload(options) {
54
65
  expiresAt: utils.viewLocalTime(credit.paidEnd),
55
66
  }]
56
67
  : []),
57
- ...(credit.balanceOneTimePaid > 0
68
+ ...(onetimeBillingEnabled && credit.balanceOneTimePaid > 0
58
69
  ? [{
59
70
  kind: 'onetime',
60
71
  balance: credit.balanceOneTimePaid,
@@ -83,22 +94,27 @@ function buildCreditOverviewPayload(options) {
83
94
  enableSubscriptionUpgrade,
84
95
  initUserContext,
85
96
  },
86
- ctaBehaviors: {
87
- subscribe: {
88
- desktop: { kind: 'modal', mode: 'subscription' },
89
- mobile: { kind: 'redirect', url: `${pricingPageBaseUrl}?initialBillingType=subscription` },
90
- },
91
- manage: {
92
- desktop: { kind: 'auth' },
93
- mobile: { kind: 'auth' },
94
- },
95
- onetime: {
96
- desktop: { kind: 'modal', mode: 'onetime' },
97
- mobile: { kind: 'redirect', url: `${pricingPageBaseUrl}?initialBillingType=onetime` },
98
- },
99
- },
97
+ ctaBehaviors: Object.assign(Object.assign({}, (subscriptionBillingEnabled
98
+ ? {
99
+ subscribe: {
100
+ desktop: { kind: 'modal', mode: 'subscription' },
101
+ mobile: { kind: 'redirect', url: `${pricingPageBaseUrl}?initialBillingType=subscription` },
102
+ },
103
+ manage: {
104
+ desktop: { kind: 'auth' },
105
+ mobile: { kind: 'auth' },
106
+ },
107
+ }
108
+ : {})), (onetimeBillingEnabled
109
+ ? {
110
+ onetime: {
111
+ desktop: { kind: 'modal', mode: 'onetime' },
112
+ mobile: { kind: 'redirect', url: `${pricingPageBaseUrl}?initialBillingType=onetime` },
113
+ },
114
+ }
115
+ : {})),
100
116
  };
101
- if (subscription) {
117
+ if (subscriptionBillingEnabled && subscription) {
102
118
  data.subscription = {
103
119
  planName: (_d = subscription.priceName) !== null && _d !== void 0 ? _d : '',
104
120
  periodStart: utils.viewLocalTime(subscription.subPeriodStart),
@@ -13,6 +13,14 @@ import { buildMoneyPriceData } from '@windrun-huaiin/third-ui/main/money-price/s
13
13
  BigInt.prototype.toJSON = function () {
14
14
  return this.toString();
15
15
  };
16
+ const DEFAULT_ENABLED_BILLING_TYPES = ['monthly', 'yearly', 'onetime'];
17
+ const SUBSCRIPTION_BILLING_TYPES = new Set(['monthly', 'yearly']);
18
+ function normalizeEnabledBillingTypes(enabledBillingTypes) {
19
+ const normalized = Array.from(new Set(((enabledBillingTypes === null || enabledBillingTypes === void 0 ? void 0 : enabledBillingTypes.length) ? enabledBillingTypes : DEFAULT_ENABLED_BILLING_TYPES)
20
+ .map((billingType) => billingType.trim())
21
+ .filter((billingType) => billingType.length > 0)));
22
+ return normalized.length ? normalized : DEFAULT_ENABLED_BILLING_TYPES;
23
+ }
16
24
  function buildCreditOverviewPayload(options) {
17
25
  return __awaiter(this, void 0, void 0, function* () {
18
26
  var _a, _b, _c, _d;
@@ -20,16 +28,19 @@ function buildCreditOverviewPayload(options) {
20
28
  if (!authUser) {
21
29
  return null;
22
30
  }
23
- const { locale, defaultLocale = 'en', localePrefixAsNeeded = true, translations, pricingPath = '/pricing', checkoutApiEndpoint = '/api/stripe/checkout', customerPortalApiEndpoint = '/api/stripe/customer-portal', } = options;
31
+ const { locale, defaultLocale = 'en', localePrefixAsNeeded = true, translations, pricingPath = '/pricing', checkoutApiEndpoint = '/api/stripe/checkout', customerPortalApiEndpoint = '/api/stripe/customer-portal', enabledBillingTypes: enabledBillingTypesOption, } = options;
24
32
  const { user } = authUser;
25
33
  const enableSubscriptionUpgrade = process.env.ENABLE_STRIPE_SUBSCRIPTION_UPGRADE !== 'false';
34
+ const enabledBillingTypes = normalizeEnabledBillingTypes(enabledBillingTypesOption);
35
+ const subscriptionBillingEnabled = enabledBillingTypes.some((billingType) => SUBSCRIPTION_BILLING_TYPES.has(billingType));
36
+ const onetimeBillingEnabled = enabledBillingTypes.includes('onetime');
26
37
  const [credit, subscription, moneyPriceData] = yield Promise.all([
27
38
  creditService.getCredit(user.userId),
28
39
  subscriptionService.getActiveSubscription(user.userId),
29
40
  buildMoneyPriceData({
30
41
  locale,
31
42
  currency: moneyPriceConfig.display.currency,
32
- enabledBillingTypes: ['monthly', 'yearly', 'onetime'],
43
+ enabledBillingTypes,
33
44
  }),
34
45
  ]);
35
46
  if (!credit) {
@@ -41,10 +52,10 @@ function buildCreditOverviewPayload(options) {
41
52
  subscription,
42
53
  });
43
54
  const totalBalance = ((_a = credit.balanceFree) !== null && _a !== void 0 ? _a : 0) +
44
- ((_b = credit.balancePaid) !== null && _b !== void 0 ? _b : 0) +
45
- ((_c = credit.balanceOneTimePaid) !== null && _c !== void 0 ? _c : 0);
55
+ (subscriptionBillingEnabled ? (_b = credit.balancePaid) !== null && _b !== void 0 ? _b : 0 : 0) +
56
+ (onetimeBillingEnabled ? (_c = credit.balanceOneTimePaid) !== null && _c !== void 0 ? _c : 0 : 0);
46
57
  const buckets = [
47
- ...(credit.balancePaid > 0
58
+ ...(subscriptionBillingEnabled && credit.balancePaid > 0
48
59
  ? [{
49
60
  kind: 'subscription',
50
61
  balance: credit.balancePaid,
@@ -52,7 +63,7 @@ function buildCreditOverviewPayload(options) {
52
63
  expiresAt: viewLocalTime(credit.paidEnd),
53
64
  }]
54
65
  : []),
55
- ...(credit.balanceOneTimePaid > 0
66
+ ...(onetimeBillingEnabled && credit.balanceOneTimePaid > 0
56
67
  ? [{
57
68
  kind: 'onetime',
58
69
  balance: credit.balanceOneTimePaid,
@@ -81,22 +92,27 @@ function buildCreditOverviewPayload(options) {
81
92
  enableSubscriptionUpgrade,
82
93
  initUserContext,
83
94
  },
84
- ctaBehaviors: {
85
- subscribe: {
86
- desktop: { kind: 'modal', mode: 'subscription' },
87
- mobile: { kind: 'redirect', url: `${pricingPageBaseUrl}?initialBillingType=subscription` },
88
- },
89
- manage: {
90
- desktop: { kind: 'auth' },
91
- mobile: { kind: 'auth' },
92
- },
93
- onetime: {
94
- desktop: { kind: 'modal', mode: 'onetime' },
95
- mobile: { kind: 'redirect', url: `${pricingPageBaseUrl}?initialBillingType=onetime` },
96
- },
97
- },
95
+ ctaBehaviors: Object.assign(Object.assign({}, (subscriptionBillingEnabled
96
+ ? {
97
+ subscribe: {
98
+ desktop: { kind: 'modal', mode: 'subscription' },
99
+ mobile: { kind: 'redirect', url: `${pricingPageBaseUrl}?initialBillingType=subscription` },
100
+ },
101
+ manage: {
102
+ desktop: { kind: 'auth' },
103
+ mobile: { kind: 'auth' },
104
+ },
105
+ }
106
+ : {})), (onetimeBillingEnabled
107
+ ? {
108
+ onetime: {
109
+ desktop: { kind: 'modal', mode: 'onetime' },
110
+ mobile: { kind: 'redirect', url: `${pricingPageBaseUrl}?initialBillingType=onetime` },
111
+ },
112
+ }
113
+ : {})),
98
114
  };
99
- if (subscription) {
115
+ if (subscriptionBillingEnabled && subscription) {
100
116
  data.subscription = {
101
117
  planName: (_d = subscription.priceName) !== null && _d !== void 0 ? _d : '',
102
118
  periodStart: viewLocalTime(subscription.subPeriodStart),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@windrun-huaiin/backend-core",
3
- "version": "31.0.0",
3
+ "version": "31.0.2",
4
4
  "description": "Shared backend primitives: Prisma schema/client, database services, routing helpers",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -107,6 +107,11 @@
107
107
  "import": "./dist/app/api/user/anonymous/init/route.mjs",
108
108
  "require": "./dist/app/api/user/anonymous/init/route.js"
109
109
  },
110
+ "./app/api/user/anonymous/init/fingerprint-only-route": {
111
+ "types": "./dist/app/api/user/anonymous/init/fingerprint-only-route.d.ts",
112
+ "import": "./dist/app/api/user/anonymous/init/fingerprint-only-route.mjs",
113
+ "require": "./dist/app/api/user/anonymous/init/fingerprint-only-route.js"
114
+ },
110
115
  "./app/api/user/credit-overview/route": {
111
116
  "types": "./dist/app/api/user/credit-overview/route.d.ts",
112
117
  "import": "./dist/app/api/user/credit-overview/route.mjs",
@@ -148,9 +153,9 @@
148
153
  "svix": "^1.86.0",
149
154
  "tslib": "^2.8.1",
150
155
  "zod": "^4.3.6",
151
- "@windrun-huaiin/lib": "^31.0.0",
152
- "@windrun-huaiin/third-ui": "^31.0.0",
153
- "@windrun-huaiin/contracts": "^31.0.0"
156
+ "@windrun-huaiin/contracts": "^31.0.0",
157
+ "@windrun-huaiin/lib": "^31.0.3",
158
+ "@windrun-huaiin/third-ui": "^31.3.7"
154
159
  },
155
160
  "devDependencies": {
156
161
  "@rollup/plugin-alias": "^5.1.1",
@@ -0,0 +1,14 @@
1
+ import { handleFingerprintRequest } from './route-shared';
2
+ import type { NextRequest } from 'next/server';
3
+
4
+ /**
5
+ * Fingerprint-only anonymous user initialization API.
6
+ * Use this route in apps that do not install or configure Clerk.
7
+ * POST /api/user/anonymous/init
8
+ */
9
+ export async function POST(request: NextRequest) {
10
+ return handleFingerprintRequest(request, {
11
+ createIfNotExists: true,
12
+ getAuthIdentity: async () => null,
13
+ });
14
+ }