@windrun-huaiin/backend-core 10.0.1
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/LICENSE +21 -0
- package/dist/app/api/stripe/checkout/route.d.ts +19 -0
- package/dist/app/api/stripe/checkout/route.d.ts.map +1 -0
- package/dist/app/api/stripe/checkout/route.js +120 -0
- package/dist/app/api/stripe/checkout/route.mjs +118 -0
- package/dist/app/api/stripe/customer-portal/route.d.ts +11 -0
- package/dist/app/api/stripe/customer-portal/route.d.ts.map +1 -0
- package/dist/app/api/stripe/customer-portal/route.js +73 -0
- package/dist/app/api/stripe/customer-portal/route.mjs +71 -0
- package/dist/app/api/user/anonymous/init/route.d.ts +7 -0
- package/dist/app/api/user/anonymous/init/route.d.ts.map +1 -0
- package/dist/app/api/user/anonymous/init/route.js +210 -0
- package/dist/app/api/user/anonymous/init/route.mjs +208 -0
- package/dist/app/api/webhook/clerk/user/route.d.ts +7 -0
- package/dist/app/api/webhook/clerk/user/route.d.ts.map +1 -0
- package/dist/app/api/webhook/clerk/user/route.js +202 -0
- package/dist/app/api/webhook/clerk/user/route.mjs +200 -0
- package/dist/app/api/webhook/stripe/route.d.ts +8 -0
- package/dist/app/api/webhook/stripe/route.d.ts.map +1 -0
- package/dist/app/api/webhook/stripe/route.js +70 -0
- package/dist/app/api/webhook/stripe/route.mjs +67 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +83 -0
- package/dist/index.mjs +18 -0
- package/dist/lib/auth-utils.d.ts +46 -0
- package/dist/lib/auth-utils.d.ts.map +1 -0
- package/dist/lib/auth-utils.js +107 -0
- package/dist/lib/auth-utils.mjs +102 -0
- package/dist/lib/credit-init.d.ts +8 -0
- package/dist/lib/credit-init.d.ts.map +1 -0
- package/dist/lib/credit-init.js +16 -0
- package/dist/lib/credit-init.mjs +10 -0
- package/dist/lib/index.d.ts +5 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +31 -0
- package/dist/lib/index.mjs +4 -0
- package/dist/lib/money-price-config.d.ts +51 -0
- package/dist/lib/money-price-config.d.ts.map +1 -0
- package/dist/lib/money-price-config.js +156 -0
- package/dist/lib/money-price-config.mjs +151 -0
- package/dist/lib/stripe-config.d.ts +31 -0
- package/dist/lib/stripe-config.d.ts.map +1 -0
- package/dist/lib/stripe-config.js +278 -0
- package/dist/lib/stripe-config.mjs +268 -0
- package/dist/node_modules/.pnpm/@rollup_plugin-typescript@12.1.4_rollup@4.46.2_tslib@2.8.1_typescript@5.9.3/node_modules/tslib/tslib.es6.js +48 -0
- package/dist/node_modules/.pnpm/@rollup_plugin-typescript@12.1.4_rollup@4.46.2_tslib@2.8.1_typescript@5.9.3/node_modules/tslib/tslib.es6.mjs +45 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/errors.js +54 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/errors.mjs +51 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/iso.js +44 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/iso.mjs +35 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/parse.js +31 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/parse.mjs +18 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/schemas.js +587 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/classic/schemas.mjs +527 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/api.js +447 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/api.mjs +399 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/checks.js +245 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/checks.mjs +232 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/core.js +68 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/core.mjs +62 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/doc.js +39 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/doc.mjs +37 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/errors.js +80 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/errors.mjs +75 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/parse.js +101 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/parse.mjs +86 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/regexes.js +102 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/regexes.mjs +76 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/registries.js +56 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/registries.mjs +52 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/schemas.js +1205 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/schemas.mjs +1157 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/util.js +407 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/util.mjs +374 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/versions.js +9 -0
- package/dist/node_modules/.pnpm/zod@4.1.12/node_modules/zod/v4/core/versions.mjs +7 -0
- package/dist/prisma/client.d.ts +2 -0
- package/dist/prisma/client.d.ts.map +1 -0
- package/dist/prisma/client.js +12 -0
- package/dist/prisma/client.mjs +1 -0
- package/dist/prisma/index.d.ts +4 -0
- package/dist/prisma/index.d.ts.map +1 -0
- package/dist/prisma/index.js +10 -0
- package/dist/prisma/index.mjs +2 -0
- package/dist/prisma/prisma-transaction-util.d.ts +3 -0
- package/dist/prisma/prisma-transaction-util.d.ts.map +1 -0
- package/dist/prisma/prisma-transaction-util.js +29 -0
- package/dist/prisma/prisma-transaction-util.mjs +27 -0
- package/dist/prisma/prisma.d.ts +4 -0
- package/dist/prisma/prisma.d.ts.map +1 -0
- package/dist/prisma/prisma.js +109 -0
- package/dist/prisma/prisma.mjs +106 -0
- package/dist/services/aggregate/billing.aggregate.service.d.ts +83 -0
- package/dist/services/aggregate/billing.aggregate.service.d.ts.map +1 -0
- package/dist/services/aggregate/billing.aggregate.service.js +308 -0
- package/dist/services/aggregate/billing.aggregate.service.mjs +306 -0
- package/dist/services/aggregate/index.d.ts +3 -0
- package/dist/services/aggregate/index.d.ts.map +1 -0
- package/dist/services/aggregate/index.js +9 -0
- package/dist/services/aggregate/index.mjs +2 -0
- package/dist/services/aggregate/user.aggregate.service.d.ts +34 -0
- package/dist/services/aggregate/user.aggregate.service.d.ts.map +1 -0
- package/dist/services/aggregate/user.aggregate.service.js +136 -0
- package/dist/services/aggregate/user.aggregate.service.mjs +133 -0
- package/dist/services/context/index.d.ts +2 -0
- package/dist/services/context/index.d.ts.map +1 -0
- package/dist/services/context/index.js +13 -0
- package/dist/services/context/index.mjs +1 -0
- package/dist/services/context/user-context-service.d.ts +30 -0
- package/dist/services/context/user-context-service.d.ts.map +1 -0
- package/dist/services/context/user-context-service.js +170 -0
- package/dist/services/context/user-context-service.mjs +162 -0
- package/dist/services/database/apilog.service.d.ts +39 -0
- package/dist/services/database/apilog.service.d.ts.map +1 -0
- package/dist/services/database/apilog.service.js +174 -0
- package/dist/services/database/apilog.service.mjs +170 -0
- package/dist/services/database/constants.d.ts +73 -0
- package/dist/services/database/constants.d.ts.map +1 -0
- package/dist/services/database/constants.js +135 -0
- package/dist/services/database/constants.mjs +117 -0
- package/dist/services/database/credit.service.d.ts +107 -0
- package/dist/services/database/credit.service.d.ts.map +1 -0
- package/dist/services/database/credit.service.js +515 -0
- package/dist/services/database/credit.service.mjs +512 -0
- package/dist/services/database/creditAuditLog.service.d.ts +73 -0
- package/dist/services/database/creditAuditLog.service.d.ts.map +1 -0
- package/dist/services/database/creditAuditLog.service.js +305 -0
- package/dist/services/database/creditAuditLog.service.mjs +302 -0
- package/dist/services/database/index.d.ts +10 -0
- package/dist/services/database/index.d.ts.map +1 -0
- package/dist/services/database/index.js +38 -0
- package/dist/services/database/index.mjs +8 -0
- package/dist/services/database/prisma-model-type.d.ts +3 -0
- package/dist/services/database/prisma-model-type.d.ts.map +1 -0
- package/dist/services/database/subscription.service.d.ts +48 -0
- package/dist/services/database/subscription.service.d.ts.map +1 -0
- package/dist/services/database/subscription.service.js +267 -0
- package/dist/services/database/subscription.service.mjs +264 -0
- package/dist/services/database/transaction.service.d.ts +92 -0
- package/dist/services/database/transaction.service.d.ts.map +1 -0
- package/dist/services/database/transaction.service.js +326 -0
- package/dist/services/database/transaction.service.mjs +323 -0
- package/dist/services/database/user.service.d.ts +45 -0
- package/dist/services/database/user.service.d.ts.map +1 -0
- package/dist/services/database/user.service.js +180 -0
- package/dist/services/database/user.service.mjs +177 -0
- package/dist/services/database/userBackup.service.d.ts +45 -0
- package/dist/services/database/userBackup.service.d.ts.map +1 -0
- package/dist/services/database/userBackup.service.js +249 -0
- package/dist/services/database/userBackup.service.mjs +246 -0
- package/dist/services/stripe/index.d.ts +2 -0
- package/dist/services/stripe/index.d.ts.map +1 -0
- package/dist/services/stripe/index.js +7 -0
- package/dist/services/stripe/index.mjs +1 -0
- package/dist/services/stripe/webhook-handler.d.ts +6 -0
- package/dist/services/stripe/webhook-handler.d.ts.map +1 -0
- package/dist/services/stripe/webhook-handler.js +537 -0
- package/dist/services/stripe/webhook-handler.mjs +535 -0
- package/migrations/create.sql +176 -0
- package/migrations/db.init.sql +13 -0
- package/migrations/init-schema.sql +19 -0
- package/migrations/purge.sql +27 -0
- package/migrations/test-check.sql +167 -0
- package/package.json +123 -0
- package/prisma/schema.prisma +191 -0
- package/src/app/api/stripe/checkout/route.ts +145 -0
- package/src/app/api/stripe/customer-portal/route.ts +83 -0
- package/src/app/api/user/anonymous/init/route.ts +284 -0
- package/src/app/api/webhook/clerk/user/route.ts +249 -0
- package/src/app/api/webhook/stripe/route.ts +93 -0
- package/src/index.ts +6 -0
- package/src/lib/auth-utils.ts +101 -0
- package/src/lib/credit-init.ts +9 -0
- package/src/lib/index.ts +4 -0
- package/src/lib/money-price-config.ts +168 -0
- package/src/lib/stripe-config.ts +333 -0
- package/src/prisma/client.ts +2 -0
- package/src/prisma/index.ts +3 -0
- package/src/prisma/prisma-transaction-util.ts +24 -0
- package/src/prisma/prisma.ts +122 -0
- package/src/services/aggregate/billing.aggregate.service.ts +498 -0
- package/src/services/aggregate/index.ts +2 -0
- package/src/services/aggregate/user.aggregate.service.ts +168 -0
- package/src/services/context/index.ts +1 -0
- package/src/services/context/user-context-service.ts +200 -0
- package/src/services/database/apilog.service.ts +185 -0
- package/src/services/database/constants.ts +148 -0
- package/src/services/database/credit.service.ts +747 -0
- package/src/services/database/creditAuditLog.service.ts +402 -0
- package/src/services/database/index.ts +41 -0
- package/src/services/database/prisma-model-type.ts +13 -0
- package/src/services/database/subscription.service.ts +319 -0
- package/src/services/database/transaction.service.ts +447 -0
- package/src/services/database/user.service.ts +218 -0
- package/src/services/database/userBackup.service.ts +290 -0
- package/src/services/stripe/index.ts +1 -0
- package/src/services/stripe/webhook-handler.ts +648 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var tslib_es6 = require('../../../../node_modules/.pnpm/@rollup_plugin-typescript@12.1.4_rollup@4.46.2_tslib@2.8.1_typescript@5.9.3/node_modules/tslib/tslib.es6.js');
|
|
4
|
+
var server = require('next/server');
|
|
5
|
+
var headers = require('next/headers');
|
|
6
|
+
var stripeConfig = require('../../../../lib/stripe-config.js');
|
|
7
|
+
var Stripe = require('stripe');
|
|
8
|
+
require('../../../../prisma/prisma.js');
|
|
9
|
+
require('../../../../services/database/credit.service.js');
|
|
10
|
+
require('@prisma/client');
|
|
11
|
+
var apilog_service = require('../../../../services/database/apilog.service.js');
|
|
12
|
+
var webhookHandler = require('../../../../services/stripe/webhook-handler.js');
|
|
13
|
+
|
|
14
|
+
// Disable body parsing, need raw body for signature verification
|
|
15
|
+
const runtime = 'nodejs';
|
|
16
|
+
function POST(request) {
|
|
17
|
+
return tslib_es6.__awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
try {
|
|
19
|
+
// 1. Get raw request body and signature
|
|
20
|
+
const body = yield request.text();
|
|
21
|
+
const headersList = yield headers.headers();
|
|
22
|
+
const signature = headersList.get('stripe-signature');
|
|
23
|
+
if (!signature) {
|
|
24
|
+
return server.NextResponse.json({ error: 'Missing stripe-signature header' }, { status: 400 });
|
|
25
|
+
}
|
|
26
|
+
if (!process.env.STRIPE_WEBHOOK_SECRET) {
|
|
27
|
+
console.error('STRIPE_WEBHOOK_SECRET is not configured');
|
|
28
|
+
return server.NextResponse.json({ error: 'Webhook configuration error' }, { status: 500 });
|
|
29
|
+
}
|
|
30
|
+
// 2. Validate webhook signature
|
|
31
|
+
const event = stripeConfig.validateStripeWebhook(body, signature, process.env.STRIPE_WEBHOOK_SECRET);
|
|
32
|
+
console.log(`Received webhook event: ${event.type} | ID: ${event.id}`);
|
|
33
|
+
// 3. Log incoming webhook and capture log ID for later updates
|
|
34
|
+
const logId = yield apilog_service.Apilogger.logStripeIncoming(event.type, event.id, event);
|
|
35
|
+
try {
|
|
36
|
+
// 4. Handle the event
|
|
37
|
+
yield webhookHandler.handleStripeEvent(event);
|
|
38
|
+
// 5. Update log with success response
|
|
39
|
+
const processingResult = {
|
|
40
|
+
success: true,
|
|
41
|
+
message: 'Event processed successfully'
|
|
42
|
+
};
|
|
43
|
+
apilog_service.Apilogger.updateResponse(logId, processingResult);
|
|
44
|
+
return server.NextResponse.json({ received: true });
|
|
45
|
+
}
|
|
46
|
+
catch (handlerError) {
|
|
47
|
+
console.error('Stripe webhook processing error:', handlerError);
|
|
48
|
+
const errorResult = {
|
|
49
|
+
success: false,
|
|
50
|
+
error: handlerError instanceof Error
|
|
51
|
+
? handlerError.message
|
|
52
|
+
: 'Unknown error',
|
|
53
|
+
stack: handlerError instanceof Error ? handlerError.stack : undefined,
|
|
54
|
+
};
|
|
55
|
+
apilog_service.Apilogger.updateResponse(logId, errorResult);
|
|
56
|
+
return server.NextResponse.json({ error: 'Webhook processing failed' }, { status: 500 });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
console.error('Webhook error:', error);
|
|
61
|
+
if (error instanceof Stripe.errors.StripeSignatureVerificationError) {
|
|
62
|
+
return server.NextResponse.json({ error: 'Invalid signature' }, { status: 400 });
|
|
63
|
+
}
|
|
64
|
+
return server.NextResponse.json({ error: 'Webhook processing failed' }, { status: 500 });
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
exports.POST = POST;
|
|
70
|
+
exports.runtime = runtime;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { __awaiter } from '../../../../node_modules/.pnpm/@rollup_plugin-typescript@12.1.4_rollup@4.46.2_tslib@2.8.1_typescript@5.9.3/node_modules/tslib/tslib.es6.mjs';
|
|
2
|
+
import { NextResponse } from 'next/server';
|
|
3
|
+
import { headers } from 'next/headers';
|
|
4
|
+
import { validateStripeWebhook } from '../../../../lib/stripe-config.mjs';
|
|
5
|
+
import Stripe from 'stripe';
|
|
6
|
+
import '../../../../prisma/prisma.mjs';
|
|
7
|
+
import '../../../../services/database/credit.service.mjs';
|
|
8
|
+
import '@prisma/client';
|
|
9
|
+
import { Apilogger } from '../../../../services/database/apilog.service.mjs';
|
|
10
|
+
import { handleStripeEvent } from '../../../../services/stripe/webhook-handler.mjs';
|
|
11
|
+
|
|
12
|
+
// Disable body parsing, need raw body for signature verification
|
|
13
|
+
const runtime = 'nodejs';
|
|
14
|
+
function POST(request) {
|
|
15
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
+
try {
|
|
17
|
+
// 1. Get raw request body and signature
|
|
18
|
+
const body = yield request.text();
|
|
19
|
+
const headersList = yield headers();
|
|
20
|
+
const signature = headersList.get('stripe-signature');
|
|
21
|
+
if (!signature) {
|
|
22
|
+
return NextResponse.json({ error: 'Missing stripe-signature header' }, { status: 400 });
|
|
23
|
+
}
|
|
24
|
+
if (!process.env.STRIPE_WEBHOOK_SECRET) {
|
|
25
|
+
console.error('STRIPE_WEBHOOK_SECRET is not configured');
|
|
26
|
+
return NextResponse.json({ error: 'Webhook configuration error' }, { status: 500 });
|
|
27
|
+
}
|
|
28
|
+
// 2. Validate webhook signature
|
|
29
|
+
const event = validateStripeWebhook(body, signature, process.env.STRIPE_WEBHOOK_SECRET);
|
|
30
|
+
console.log(`Received webhook event: ${event.type} | ID: ${event.id}`);
|
|
31
|
+
// 3. Log incoming webhook and capture log ID for later updates
|
|
32
|
+
const logId = yield Apilogger.logStripeIncoming(event.type, event.id, event);
|
|
33
|
+
try {
|
|
34
|
+
// 4. Handle the event
|
|
35
|
+
yield handleStripeEvent(event);
|
|
36
|
+
// 5. Update log with success response
|
|
37
|
+
const processingResult = {
|
|
38
|
+
success: true,
|
|
39
|
+
message: 'Event processed successfully'
|
|
40
|
+
};
|
|
41
|
+
Apilogger.updateResponse(logId, processingResult);
|
|
42
|
+
return NextResponse.json({ received: true });
|
|
43
|
+
}
|
|
44
|
+
catch (handlerError) {
|
|
45
|
+
console.error('Stripe webhook processing error:', handlerError);
|
|
46
|
+
const errorResult = {
|
|
47
|
+
success: false,
|
|
48
|
+
error: handlerError instanceof Error
|
|
49
|
+
? handlerError.message
|
|
50
|
+
: 'Unknown error',
|
|
51
|
+
stack: handlerError instanceof Error ? handlerError.stack : undefined,
|
|
52
|
+
};
|
|
53
|
+
Apilogger.updateResponse(logId, errorResult);
|
|
54
|
+
return NextResponse.json({ error: 'Webhook processing failed' }, { status: 500 });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
console.error('Webhook error:', error);
|
|
59
|
+
if (error instanceof Stripe.errors.StripeSignatureVerificationError) {
|
|
60
|
+
return NextResponse.json({ error: 'Invalid signature' }, { status: 400 });
|
|
61
|
+
}
|
|
62
|
+
return NextResponse.json({ error: 'Webhook processing failed' }, { status: 500 });
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export { POST, runtime };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,OAAO,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var prisma = require('./prisma/prisma.js');
|
|
4
|
+
var prismaTransactionUtil = require('./prisma/prisma-transaction-util.js');
|
|
5
|
+
var user_service = require('./services/database/user.service.js');
|
|
6
|
+
var subscription_service = require('./services/database/subscription.service.js');
|
|
7
|
+
var credit_service = require('./services/database/credit.service.js');
|
|
8
|
+
var transaction_service = require('./services/database/transaction.service.js');
|
|
9
|
+
var creditAuditLog_service = require('./services/database/creditAuditLog.service.js');
|
|
10
|
+
var userBackup_service = require('./services/database/userBackup.service.js');
|
|
11
|
+
var apilog_service = require('./services/database/apilog.service.js');
|
|
12
|
+
var constants = require('./services/database/constants.js');
|
|
13
|
+
var user_aggregate_service = require('./services/aggregate/user.aggregate.service.js');
|
|
14
|
+
var billing_aggregate_service = require('./services/aggregate/billing.aggregate.service.js');
|
|
15
|
+
var userContextService = require('./services/context/user-context-service.js');
|
|
16
|
+
var webhookHandler = require('./services/stripe/webhook-handler.js');
|
|
17
|
+
var moneyPriceConfig = require('./lib/money-price-config.js');
|
|
18
|
+
var creditInit = require('./lib/credit-init.js');
|
|
19
|
+
var stripeConfig = require('./lib/stripe-config.js');
|
|
20
|
+
var authUtils = require('./lib/auth-utils.js');
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
exports.checkAndFallbackWithNonTCClient = prisma.checkAndFallbackWithNonTCClient;
|
|
25
|
+
exports.prisma = prisma.prisma;
|
|
26
|
+
exports.runInTransaction = prismaTransactionUtil.runInTransaction;
|
|
27
|
+
exports.userService = user_service.userService;
|
|
28
|
+
exports.subscriptionService = subscription_service.subscriptionService;
|
|
29
|
+
exports.creditService = credit_service.creditService;
|
|
30
|
+
exports.transactionService = transaction_service.transactionService;
|
|
31
|
+
exports.creditAuditLogService = creditAuditLog_service.creditAuditLogService;
|
|
32
|
+
exports.userBackupService = userBackup_service.userBackupService;
|
|
33
|
+
exports.Apilogger = apilog_service.Apilogger;
|
|
34
|
+
exports.apilogService = apilog_service.apilogService;
|
|
35
|
+
exports.BillingReason = constants.BillingReason;
|
|
36
|
+
exports.CreditType = constants.CreditType;
|
|
37
|
+
exports.OperationType = constants.OperationType;
|
|
38
|
+
exports.OrderStatus = constants.OrderStatus;
|
|
39
|
+
exports.PaySupplier = constants.PaySupplier;
|
|
40
|
+
exports.PaymentStatus = constants.PaymentStatus;
|
|
41
|
+
exports.SubscriptionStatus = constants.SubscriptionStatus;
|
|
42
|
+
exports.TransactionType = constants.TransactionType;
|
|
43
|
+
exports.UserStatus = constants.UserStatus;
|
|
44
|
+
exports.isValidBillingReason = constants.isValidBillingReason;
|
|
45
|
+
exports.isValidCreditType = constants.isValidCreditType;
|
|
46
|
+
exports.isValidOperationType = constants.isValidOperationType;
|
|
47
|
+
exports.isValidOrderStatus = constants.isValidOrderStatus;
|
|
48
|
+
exports.isValidPaymentStatus = constants.isValidPaymentStatus;
|
|
49
|
+
exports.isValidSubscriptionStatus = constants.isValidSubscriptionStatus;
|
|
50
|
+
exports.isValidTransactionType = constants.isValidTransactionType;
|
|
51
|
+
exports.isValidUserStatus = constants.isValidUserStatus;
|
|
52
|
+
exports.userAggregateService = user_aggregate_service.userAggregateService;
|
|
53
|
+
exports.billingAggregateService = billing_aggregate_service.billingAggregateService;
|
|
54
|
+
exports.applyUserMockContext = userContextService.applyUserMockContext;
|
|
55
|
+
exports.buildInitUserContextFromEntities = userContextService.buildInitUserContextFromEntities;
|
|
56
|
+
exports.fetchLatestUserContextByFingerprintId = userContextService.fetchLatestUserContextByFingerprintId;
|
|
57
|
+
exports.fetchUserContextByClerkUserId = userContextService.fetchUserContextByClerkUserId;
|
|
58
|
+
exports.mapCreditToXCredit = userContextService.mapCreditToXCredit;
|
|
59
|
+
exports.mapSubscriptionToXSubscription = userContextService.mapSubscriptionToXSubscription;
|
|
60
|
+
exports.mapUserToXUser = userContextService.mapUserToXUser;
|
|
61
|
+
exports.handleStripeEvent = webhookHandler.handleStripeEvent;
|
|
62
|
+
exports.getActiveProviderConfig = moneyPriceConfig.getActiveProviderConfig;
|
|
63
|
+
exports.getCreditsFromPriceId = moneyPriceConfig.getCreditsFromPriceId;
|
|
64
|
+
exports.getPriceConfig = moneyPriceConfig.getPriceConfig;
|
|
65
|
+
exports.moneyPriceConfig = moneyPriceConfig.moneyPriceConfig;
|
|
66
|
+
exports.creditsConfig = creditInit.creditsConfig;
|
|
67
|
+
exports.freeAmount = creditInit.freeAmount;
|
|
68
|
+
exports.freeExpiredDays = creditInit.freeExpiredDays;
|
|
69
|
+
exports.freeRegisterAmount = creditInit.freeRegisterAmount;
|
|
70
|
+
exports.oneTimeExpiredDays = creditInit.oneTimeExpiredDays;
|
|
71
|
+
exports.ActiveSubscriptionExistsError = stripeConfig.ActiveSubscriptionExistsError;
|
|
72
|
+
exports.cancelSubscription = stripeConfig.cancelSubscription;
|
|
73
|
+
exports.createCheckoutSession = stripeConfig.createCheckoutSession;
|
|
74
|
+
exports.createCustomerPortalSession = stripeConfig.createCustomerPortalSession;
|
|
75
|
+
exports.createOrGetCustomer = stripeConfig.createOrGetCustomer;
|
|
76
|
+
exports.fetchPaymentId = stripeConfig.fetchPaymentId;
|
|
77
|
+
exports.stripe = stripeConfig.stripe;
|
|
78
|
+
exports.updateSubscription = stripeConfig.updateSubscription;
|
|
79
|
+
exports.validateStripeWebhook = stripeConfig.validateStripeWebhook;
|
|
80
|
+
exports.ApiAuthUtils = authUtils.ApiAuthUtils;
|
|
81
|
+
exports.getAuthenticatedUser = authUtils.getAuthenticatedUser;
|
|
82
|
+
exports.requireAuth = authUtils.requireAuth;
|
|
83
|
+
exports.requireAuthWithUser = authUtils.requireAuthWithUser;
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export { checkAndFallbackWithNonTCClient, prisma } from './prisma/prisma.mjs';
|
|
2
|
+
export { runInTransaction } from './prisma/prisma-transaction-util.mjs';
|
|
3
|
+
export { userService } from './services/database/user.service.mjs';
|
|
4
|
+
export { subscriptionService } from './services/database/subscription.service.mjs';
|
|
5
|
+
export { creditService } from './services/database/credit.service.mjs';
|
|
6
|
+
export { transactionService } from './services/database/transaction.service.mjs';
|
|
7
|
+
export { creditAuditLogService } from './services/database/creditAuditLog.service.mjs';
|
|
8
|
+
export { userBackupService } from './services/database/userBackup.service.mjs';
|
|
9
|
+
export { Apilogger, apilogService } from './services/database/apilog.service.mjs';
|
|
10
|
+
export { BillingReason, CreditType, OperationType, OrderStatus, PaySupplier, PaymentStatus, SubscriptionStatus, TransactionType, UserStatus, isValidBillingReason, isValidCreditType, isValidOperationType, isValidOrderStatus, isValidPaymentStatus, isValidSubscriptionStatus, isValidTransactionType, isValidUserStatus } from './services/database/constants.mjs';
|
|
11
|
+
export { userAggregateService } from './services/aggregate/user.aggregate.service.mjs';
|
|
12
|
+
export { billingAggregateService } from './services/aggregate/billing.aggregate.service.mjs';
|
|
13
|
+
export { applyUserMockContext, buildInitUserContextFromEntities, fetchLatestUserContextByFingerprintId, fetchUserContextByClerkUserId, mapCreditToXCredit, mapSubscriptionToXSubscription, mapUserToXUser } from './services/context/user-context-service.mjs';
|
|
14
|
+
export { handleStripeEvent } from './services/stripe/webhook-handler.mjs';
|
|
15
|
+
export { getActiveProviderConfig, getCreditsFromPriceId, getPriceConfig, moneyPriceConfig } from './lib/money-price-config.mjs';
|
|
16
|
+
export { creditsConfig, freeAmount, freeExpiredDays, freeRegisterAmount, oneTimeExpiredDays } from './lib/credit-init.mjs';
|
|
17
|
+
export { ActiveSubscriptionExistsError, cancelSubscription, createCheckoutSession, createCustomerPortalSession, createOrGetCustomer, fetchPaymentId, stripe, updateSubscription, validateStripeWebhook } from './lib/stripe-config.mjs';
|
|
18
|
+
export { ApiAuthUtils, getAuthenticatedUser, requireAuth, requireAuthWithUser } from './lib/auth-utils.mjs';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { NextRequest } from 'next/server';
|
|
2
|
+
import { User } from '../services/database/prisma-model-type';
|
|
3
|
+
/**
|
|
4
|
+
* 认证结果类型
|
|
5
|
+
*/
|
|
6
|
+
export interface AuthResult {
|
|
7
|
+
userId: string;
|
|
8
|
+
user: User;
|
|
9
|
+
clerkUserId: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* 从中间件设置的 Clerk ID 获取完整用户信息
|
|
13
|
+
*/
|
|
14
|
+
export declare function getAuthenticatedUser(req: NextRequest): Promise<AuthResult>;
|
|
15
|
+
/**
|
|
16
|
+
* 要求用户必须已认证,返回用户ID
|
|
17
|
+
*/
|
|
18
|
+
export declare function requireAuth(req: NextRequest): Promise<string>;
|
|
19
|
+
/**
|
|
20
|
+
* 要求用户必须已认证,返回完整用户信息
|
|
21
|
+
*/
|
|
22
|
+
export declare function requireAuthWithUser(req: NextRequest): Promise<AuthResult>;
|
|
23
|
+
/**
|
|
24
|
+
* API Route版本的认证工具函数
|
|
25
|
+
*/
|
|
26
|
+
export declare class ApiAuthUtils {
|
|
27
|
+
private req;
|
|
28
|
+
constructor(req: NextRequest);
|
|
29
|
+
/**
|
|
30
|
+
* 要求用户必须已认证,返回用户ID
|
|
31
|
+
*/
|
|
32
|
+
requireAuth(): Promise<string>;
|
|
33
|
+
/**
|
|
34
|
+
* 要求用户必须已认证,返回完整用户信息
|
|
35
|
+
*/
|
|
36
|
+
requireAuthWithUser(): Promise<AuthResult>;
|
|
37
|
+
/**
|
|
38
|
+
* 获取用户ID(如果已认证)
|
|
39
|
+
*/
|
|
40
|
+
getUserId(): Promise<string | null>;
|
|
41
|
+
/**
|
|
42
|
+
* 获取完整用户信息(如果已认证)
|
|
43
|
+
*/
|
|
44
|
+
getUser(): Promise<AuthResult | null>;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=auth-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-utils.d.ts","sourceRoot":"","sources":["../../src/lib/auth-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,EAAE,IAAI,EAAE,MAAM,wCAAwC,CAAC;AAE9D;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,IAAI,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAqBhF;AAED;;GAEG;AACH,wBAAsB,WAAW,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,CAAC,CAGnE;AAED;;GAEG;AACH,wBAAsB,mBAAmB,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAE/E;AAED;;GAEG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,GAAG,CAAc;gBAEb,GAAG,EAAE,WAAW;IAI5B;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC;IAIpC;;OAEG;IACG,mBAAmB,IAAI,OAAO,CAAC,UAAU,CAAC;IAIhD;;OAEG;IACG,SAAS,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IASzC;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;CAO5C"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var tslib_es6 = require('../node_modules/.pnpm/@rollup_plugin-typescript@12.1.4_rollup@4.46.2_tslib@2.8.1_typescript@5.9.3/node_modules/tslib/tslib.es6.js');
|
|
4
|
+
var user_service = require('../services/database/user.service.js');
|
|
5
|
+
require('../prisma/prisma.js');
|
|
6
|
+
require('../services/database/credit.service.js');
|
|
7
|
+
require('@prisma/client');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 从中间件设置的 Clerk ID 获取完整用户信息
|
|
11
|
+
*/
|
|
12
|
+
function getAuthenticatedUser(req) {
|
|
13
|
+
return tslib_es6.__awaiter(this, void 0, void 0, function* () {
|
|
14
|
+
try {
|
|
15
|
+
const clerkUserId = req.headers.get('x-clerk-user-id');
|
|
16
|
+
if (!clerkUserId) {
|
|
17
|
+
throw new Error('Authentication required');
|
|
18
|
+
}
|
|
19
|
+
const user = yield user_service.userService.findByClerkUserId(clerkUserId);
|
|
20
|
+
if (!user) {
|
|
21
|
+
throw new Error('User not found in database');
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
userId: user.userId,
|
|
25
|
+
user,
|
|
26
|
+
clerkUserId
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
console.error('Error getting authenticated user:', error);
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 要求用户必须已认证,返回用户ID
|
|
37
|
+
*/
|
|
38
|
+
function requireAuth(req) {
|
|
39
|
+
return tslib_es6.__awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
const auth = yield getAuthenticatedUser(req);
|
|
41
|
+
return auth.userId;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* 要求用户必须已认证,返回完整用户信息
|
|
46
|
+
*/
|
|
47
|
+
function requireAuthWithUser(req) {
|
|
48
|
+
return tslib_es6.__awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
return yield getAuthenticatedUser(req);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* API Route版本的认证工具函数
|
|
54
|
+
*/
|
|
55
|
+
class ApiAuthUtils {
|
|
56
|
+
constructor(req) {
|
|
57
|
+
this.req = req;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* 要求用户必须已认证,返回用户ID
|
|
61
|
+
*/
|
|
62
|
+
requireAuth() {
|
|
63
|
+
return tslib_es6.__awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
return yield requireAuth(this.req);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* 要求用户必须已认证,返回完整用户信息
|
|
69
|
+
*/
|
|
70
|
+
requireAuthWithUser() {
|
|
71
|
+
return tslib_es6.__awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
return yield requireAuthWithUser(this.req);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* 获取用户ID(如果已认证)
|
|
77
|
+
*/
|
|
78
|
+
getUserId() {
|
|
79
|
+
return tslib_es6.__awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
try {
|
|
81
|
+
const auth = yield getAuthenticatedUser(this.req);
|
|
82
|
+
return auth.userId;
|
|
83
|
+
}
|
|
84
|
+
catch (_a) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* 获取完整用户信息(如果已认证)
|
|
91
|
+
*/
|
|
92
|
+
getUser() {
|
|
93
|
+
return tslib_es6.__awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
try {
|
|
95
|
+
return yield getAuthenticatedUser(this.req);
|
|
96
|
+
}
|
|
97
|
+
catch (_a) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
exports.ApiAuthUtils = ApiAuthUtils;
|
|
105
|
+
exports.getAuthenticatedUser = getAuthenticatedUser;
|
|
106
|
+
exports.requireAuth = requireAuth;
|
|
107
|
+
exports.requireAuthWithUser = requireAuthWithUser;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { __awaiter } from '../node_modules/.pnpm/@rollup_plugin-typescript@12.1.4_rollup@4.46.2_tslib@2.8.1_typescript@5.9.3/node_modules/tslib/tslib.es6.mjs';
|
|
2
|
+
import { userService } from '../services/database/user.service.mjs';
|
|
3
|
+
import '../prisma/prisma.mjs';
|
|
4
|
+
import '../services/database/credit.service.mjs';
|
|
5
|
+
import '@prisma/client';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 从中间件设置的 Clerk ID 获取完整用户信息
|
|
9
|
+
*/
|
|
10
|
+
function getAuthenticatedUser(req) {
|
|
11
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
12
|
+
try {
|
|
13
|
+
const clerkUserId = req.headers.get('x-clerk-user-id');
|
|
14
|
+
if (!clerkUserId) {
|
|
15
|
+
throw new Error('Authentication required');
|
|
16
|
+
}
|
|
17
|
+
const user = yield userService.findByClerkUserId(clerkUserId);
|
|
18
|
+
if (!user) {
|
|
19
|
+
throw new Error('User not found in database');
|
|
20
|
+
}
|
|
21
|
+
return {
|
|
22
|
+
userId: user.userId,
|
|
23
|
+
user,
|
|
24
|
+
clerkUserId
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
console.error('Error getting authenticated user:', error);
|
|
29
|
+
throw error;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* 要求用户必须已认证,返回用户ID
|
|
35
|
+
*/
|
|
36
|
+
function requireAuth(req) {
|
|
37
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
+
const auth = yield getAuthenticatedUser(req);
|
|
39
|
+
return auth.userId;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 要求用户必须已认证,返回完整用户信息
|
|
44
|
+
*/
|
|
45
|
+
function requireAuthWithUser(req) {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
return yield getAuthenticatedUser(req);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* API Route版本的认证工具函数
|
|
52
|
+
*/
|
|
53
|
+
class ApiAuthUtils {
|
|
54
|
+
constructor(req) {
|
|
55
|
+
this.req = req;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* 要求用户必须已认证,返回用户ID
|
|
59
|
+
*/
|
|
60
|
+
requireAuth() {
|
|
61
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
return yield requireAuth(this.req);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* 要求用户必须已认证,返回完整用户信息
|
|
67
|
+
*/
|
|
68
|
+
requireAuthWithUser() {
|
|
69
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
+
return yield requireAuthWithUser(this.req);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* 获取用户ID(如果已认证)
|
|
75
|
+
*/
|
|
76
|
+
getUserId() {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
try {
|
|
79
|
+
const auth = yield getAuthenticatedUser(this.req);
|
|
80
|
+
return auth.userId;
|
|
81
|
+
}
|
|
82
|
+
catch (_a) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* 获取完整用户信息(如果已认证)
|
|
89
|
+
*/
|
|
90
|
+
getUser() {
|
|
91
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
try {
|
|
93
|
+
return yield getAuthenticatedUser(this.req);
|
|
94
|
+
}
|
|
95
|
+
catch (_a) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export { ApiAuthUtils, getAuthenticatedUser, requireAuth, requireAuthWithUser };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const creditsConfig: {
|
|
2
|
+
freeAmount: number;
|
|
3
|
+
freeRegisterAmount: number;
|
|
4
|
+
freeExpiredDays: number;
|
|
5
|
+
oneTimeExpiredDays: number;
|
|
6
|
+
};
|
|
7
|
+
export declare const freeAmount: number, freeRegisterAmount: number, freeExpiredDays: number, oneTimeExpiredDays: number;
|
|
8
|
+
//# sourceMappingURL=credit-init.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"credit-init.d.ts","sourceRoot":"","sources":["../../src/lib/credit-init.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,aAAa;;;;;CAKzB,CAAC;AAEF,eAAO,MAAQ,UAAU,UAAE,kBAAkB,UAAE,eAAe,UAAE,kBAAkB,QAAkB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// create app config
|
|
4
|
+
const creditsConfig = {
|
|
5
|
+
freeAmount: Number(process.env.CREDITS_INIT_FREE_AMOUNT) || 1,
|
|
6
|
+
freeRegisterAmount: Number(process.env.CREDITS_INIT_FREE_REGISTER_AMOUNT) || 2,
|
|
7
|
+
freeExpiredDays: Number(process.env.CREDITS_INIT_FREE_EXPIRED_DAYS) || 7,
|
|
8
|
+
oneTimeExpiredDays: Number(process.env.CREDITS_ONE_TIME_EXPIRED_DAYS) || 30
|
|
9
|
+
};
|
|
10
|
+
const { freeAmount, freeRegisterAmount, freeExpiredDays, oneTimeExpiredDays } = creditsConfig;
|
|
11
|
+
|
|
12
|
+
exports.creditsConfig = creditsConfig;
|
|
13
|
+
exports.freeAmount = freeAmount;
|
|
14
|
+
exports.freeExpiredDays = freeExpiredDays;
|
|
15
|
+
exports.freeRegisterAmount = freeRegisterAmount;
|
|
16
|
+
exports.oneTimeExpiredDays = oneTimeExpiredDays;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// create app config
|
|
2
|
+
const creditsConfig = {
|
|
3
|
+
freeAmount: Number(process.env.CREDITS_INIT_FREE_AMOUNT) || 1,
|
|
4
|
+
freeRegisterAmount: Number(process.env.CREDITS_INIT_FREE_REGISTER_AMOUNT) || 2,
|
|
5
|
+
freeExpiredDays: Number(process.env.CREDITS_INIT_FREE_EXPIRED_DAYS) || 7,
|
|
6
|
+
oneTimeExpiredDays: Number(process.env.CREDITS_ONE_TIME_EXPIRED_DAYS) || 30
|
|
7
|
+
};
|
|
8
|
+
const { freeAmount, freeRegisterAmount, freeExpiredDays, oneTimeExpiredDays } = creditsConfig;
|
|
9
|
+
|
|
10
|
+
export { creditsConfig, freeAmount, freeExpiredDays, freeRegisterAmount, oneTimeExpiredDays };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var moneyPriceConfig = require('./money-price-config.js');
|
|
4
|
+
var creditInit = require('./credit-init.js');
|
|
5
|
+
var stripeConfig = require('./stripe-config.js');
|
|
6
|
+
var authUtils = require('./auth-utils.js');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
exports.getActiveProviderConfig = moneyPriceConfig.getActiveProviderConfig;
|
|
11
|
+
exports.getCreditsFromPriceId = moneyPriceConfig.getCreditsFromPriceId;
|
|
12
|
+
exports.getPriceConfig = moneyPriceConfig.getPriceConfig;
|
|
13
|
+
exports.moneyPriceConfig = moneyPriceConfig.moneyPriceConfig;
|
|
14
|
+
exports.creditsConfig = creditInit.creditsConfig;
|
|
15
|
+
exports.freeAmount = creditInit.freeAmount;
|
|
16
|
+
exports.freeExpiredDays = creditInit.freeExpiredDays;
|
|
17
|
+
exports.freeRegisterAmount = creditInit.freeRegisterAmount;
|
|
18
|
+
exports.oneTimeExpiredDays = creditInit.oneTimeExpiredDays;
|
|
19
|
+
exports.ActiveSubscriptionExistsError = stripeConfig.ActiveSubscriptionExistsError;
|
|
20
|
+
exports.cancelSubscription = stripeConfig.cancelSubscription;
|
|
21
|
+
exports.createCheckoutSession = stripeConfig.createCheckoutSession;
|
|
22
|
+
exports.createCustomerPortalSession = stripeConfig.createCustomerPortalSession;
|
|
23
|
+
exports.createOrGetCustomer = stripeConfig.createOrGetCustomer;
|
|
24
|
+
exports.fetchPaymentId = stripeConfig.fetchPaymentId;
|
|
25
|
+
exports.stripe = stripeConfig.stripe;
|
|
26
|
+
exports.updateSubscription = stripeConfig.updateSubscription;
|
|
27
|
+
exports.validateStripeWebhook = stripeConfig.validateStripeWebhook;
|
|
28
|
+
exports.ApiAuthUtils = authUtils.ApiAuthUtils;
|
|
29
|
+
exports.getAuthenticatedUser = authUtils.getAuthenticatedUser;
|
|
30
|
+
exports.requireAuth = authUtils.requireAuth;
|
|
31
|
+
exports.requireAuthWithUser = authUtils.requireAuthWithUser;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { getActiveProviderConfig, getCreditsFromPriceId, getPriceConfig, moneyPriceConfig } from './money-price-config.mjs';
|
|
2
|
+
export { creditsConfig, freeAmount, freeExpiredDays, freeRegisterAmount, oneTimeExpiredDays } from './credit-init.mjs';
|
|
3
|
+
export { ActiveSubscriptionExistsError, cancelSubscription, createCheckoutSession, createCustomerPortalSession, createOrGetCustomer, fetchPaymentId, stripe, updateSubscription, validateStripeWebhook } from './stripe-config.mjs';
|
|
4
|
+
export { ApiAuthUtils, getAuthenticatedUser, requireAuth, requireAuthWithUser } from './auth-utils.mjs';
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { MoneyPriceConfig, PaymentProviderConfig, EnhancePricePlan } from '@windrun-huaiin/third-ui/main/server';
|
|
2
|
+
export declare const moneyPriceConfig: MoneyPriceConfig;
|
|
3
|
+
/**
|
|
4
|
+
* 获取当前激活的支付供应商配置
|
|
5
|
+
*
|
|
6
|
+
* 🔒 安全设计:
|
|
7
|
+
* - wrapper函数隐藏moneyPriceConfig
|
|
8
|
+
* - util层负责从config中提取激活的provider配置
|
|
9
|
+
* - 外部只能通过这个wrapper访问,看不到config对象
|
|
10
|
+
*
|
|
11
|
+
* @returns 当前激活的支付供应商配置
|
|
12
|
+
*/
|
|
13
|
+
export declare function getActiveProviderConfig(): PaymentProviderConfig;
|
|
14
|
+
/**
|
|
15
|
+
* 根据 priceId 获取对应的积分数量
|
|
16
|
+
*
|
|
17
|
+
* 🔒 安全设计:
|
|
18
|
+
* - wrapper函数隐藏moneyPriceConfig
|
|
19
|
+
* - util层负责解析config并提取结果
|
|
20
|
+
* - 外部只能通过这个wrapper访问,看不到config对象
|
|
21
|
+
*
|
|
22
|
+
* @param priceId - 查询的价格ID
|
|
23
|
+
* @param _provider - 保留参数(向后兼容),暂未使用
|
|
24
|
+
* @returns 对应的积分数量,或null
|
|
25
|
+
*/
|
|
26
|
+
export declare function getCreditsFromPriceId(priceId?: string, _provider?: string): number | null;
|
|
27
|
+
/**
|
|
28
|
+
* 根据查询参数获取价格配置
|
|
29
|
+
*
|
|
30
|
+
* 支持三种查询方式:
|
|
31
|
+
* 1. 按 priceId 查询:getPriceConfig(priceId='price_xxx')
|
|
32
|
+
* 2. 按 plan 和 billingType 查询:getPriceConfig(undefined, 'P2', 'monthly')
|
|
33
|
+
* 3. 按 plan 查询:getPriceConfig(undefined, 'P2')
|
|
34
|
+
*
|
|
35
|
+
* 🔒 安全设计:
|
|
36
|
+
* - wrapper函数隐藏moneyPriceConfig
|
|
37
|
+
* - util层负责解析config并提取匹配的结果
|
|
38
|
+
* - 外部只能通过这个wrapper访问,看不到config对象
|
|
39
|
+
*
|
|
40
|
+
* @param priceId - 查询的价格ID(可选)
|
|
41
|
+
* @param plan - 查询的套餐名称如'P2'、'U3'(可选)
|
|
42
|
+
* @param billingType - 查询的计费类型如'monthly'、'yearly'(可选)
|
|
43
|
+
* @param _provider - 保留参数(向后兼容),暂未使用
|
|
44
|
+
* @returns 匹配的价格配置,包含计算好的元数据(priceName、description、interval)
|
|
45
|
+
*/
|
|
46
|
+
export declare function getPriceConfig(priceId?: string, plan?: string, billingType?: string, _provider?: string): (EnhancePricePlan & {
|
|
47
|
+
priceName: string;
|
|
48
|
+
description: string;
|
|
49
|
+
interval?: string;
|
|
50
|
+
}) | null;
|
|
51
|
+
//# sourceMappingURL=money-price-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"money-price-config.d.ts","sourceRoot":"","sources":["../../src/lib/money-price-config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACrB,gBAAgB,EAIjB,MAAM,sCAAsC,CAAA;AAE7C,eAAO,MAAM,gBAAgB,EAAE,gBAiG9B,CAAC;AAIF;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,IAAI,qBAAqB,CAE/D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAEzF;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,cAAc,CAC5B,OAAO,CAAC,EAAE,MAAM,EAChB,IAAI,CAAC,EAAE,MAAM,EACb,WAAW,CAAC,EAAE,MAAM,EACpB,SAAS,CAAC,EAAE,MAAM,GACjB,CAAC,gBAAgB,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,IAAI,CAE3F"}
|