mirror of
https://github.com/certd/certd.git
synced 2026-07-12 16:27:34 +08:00
refactor(certd-server): 移除非运行时依赖到动态导入
将alipay-sdk、openid-client、otplib、wechatpay-node-v3改为动态导入,从dependencies移到devDependencies?不,是改为通过importRuntime动态加载,移除顶层静态引入,优化启动时依赖加载,减少初始包体积和启动耗时
This commit is contained in:
@@ -71,7 +71,6 @@
|
|||||||
"@peculiar/x509": "^1.11.0",
|
"@peculiar/x509": "^1.11.0",
|
||||||
"@simplewebauthn/browser": "^13.2.2",
|
"@simplewebauthn/browser": "^13.2.2",
|
||||||
"@simplewebauthn/server": "^13.2.3",
|
"@simplewebauthn/server": "^13.2.3",
|
||||||
"alipay-sdk": "^4.13.0",
|
|
||||||
"axios": "^1.9.0",
|
"axios": "^1.9.0",
|
||||||
"bcryptjs": "^2.4.3",
|
"bcryptjs": "^2.4.3",
|
||||||
"better-sqlite3": "^11.1.2",
|
"better-sqlite3": "^11.1.2",
|
||||||
@@ -96,8 +95,6 @@
|
|||||||
"nanoid": "^5.0.7",
|
"nanoid": "^5.0.7",
|
||||||
"node-forge": "^1.3.1",
|
"node-forge": "^1.3.1",
|
||||||
"nodemailer": "^6.9.16",
|
"nodemailer": "^6.9.16",
|
||||||
"openid-client": "^6.8.1",
|
|
||||||
"otplib": "^12.0.1",
|
|
||||||
"pg": "^8.12.0",
|
"pg": "^8.12.0",
|
||||||
"psl": "^1.15.0",
|
"psl": "^1.15.0",
|
||||||
"punycode.js": "^2.3.1",
|
"punycode.js": "^2.3.1",
|
||||||
@@ -113,7 +110,6 @@
|
|||||||
"svg-captcha": "^1.4.0",
|
"svg-captcha": "^1.4.0",
|
||||||
"typeorm": "^0.3.20",
|
"typeorm": "^0.3.20",
|
||||||
"uuid": "^10.0.0",
|
"uuid": "^10.0.0",
|
||||||
"wechatpay-node-v3": "^2.2.1",
|
|
||||||
"whoiser": "2.0.0-beta.10",
|
"whoiser": "2.0.0-beta.10",
|
||||||
"xml2js": "^0.6.2"
|
"xml2js": "^0.6.2"
|
||||||
},
|
},
|
||||||
@@ -170,7 +166,11 @@
|
|||||||
"@google-cloud/publicca": "^1.3.0",
|
"@google-cloud/publicca": "^1.3.0",
|
||||||
"basic-ftp": "^5.0.5",
|
"basic-ftp": "^5.0.5",
|
||||||
"esdk-obs-nodejs": "^3.25.6",
|
"esdk-obs-nodejs": "^3.25.6",
|
||||||
"qiniu": "^7.12.0"
|
"qiniu": "^7.12.0",
|
||||||
|
"alipay-sdk": "^4.13.0",
|
||||||
|
"wechatpay-node-v3": "^2.2.1",
|
||||||
|
"openid-client": "^6.8.1",
|
||||||
|
"otplib": "^12.0.1"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=20.0.0"
|
"node": ">=20.0.0"
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ export class PaymentAlipay implements IPaymentProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async createAlipaySdk() {
|
private async createAlipaySdk() {
|
||||||
const AlipaySdk = await import("alipay-sdk");
|
const AlipaySdk = await this.access.importRuntime("alipay-sdk");
|
||||||
|
|
||||||
const alipaySdk = new AlipaySdk.AlipaySdk({
|
const alipaySdk = new AlipaySdk.AlipaySdk({
|
||||||
appId: this.access.appId,
|
appId: this.access.appId,
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { IPaymentProvider, TradeEntity, UpdateTrade, UpdateTradeInfo } from "@certd/commercial-core";
|
import { IPaymentProvider, TradeEntity, UpdateTrade, UpdateTradeInfo } from "@certd/commercial-core";
|
||||||
import WxPay from "wechatpay-node-v3";
|
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import { logger } from "@certd/basic"; // 支持使用require
|
import { logger } from "@certd/basic";
|
||||||
import { WxpayAccess } from "../../../plugins/plugin-plus/wxpay/access.js";
|
import { WxpayAccess } from "../../../plugins/plugin-plus/wxpay/access.js";
|
||||||
export class PaymentWxpay implements IPaymentProvider {
|
export class PaymentWxpay implements IPaymentProvider {
|
||||||
access: WxpayAccess;
|
access: WxpayAccess;
|
||||||
@@ -26,7 +25,7 @@ export class PaymentWxpay implements IPaymentProvider {
|
|||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const pay = this.createSdk();
|
const pay = await this.createSdk();
|
||||||
|
|
||||||
const result: any = await pay.query({ out_trade_no: tradeNo });
|
const result: any = await pay.query({ out_trade_no: tradeNo });
|
||||||
logger.info(`微信支付查询订单返回:${JSON.stringify(result)}`);
|
logger.info(`微信支付查询订单返回:${JSON.stringify(result)}`);
|
||||||
@@ -58,7 +57,7 @@ export class PaymentWxpay implements IPaymentProvider {
|
|||||||
async createOrder(trade: TradeEntity, opts: { bindUrl: string; clientIp: string }) {
|
async createOrder(trade: TradeEntity, opts: { bindUrl: string; clientIp: string }) {
|
||||||
const notify_url = `${opts.bindUrl}/api/payment/notify/wxpay`;
|
const notify_url = `${opts.bindUrl}/api/payment/notify/wxpay`;
|
||||||
|
|
||||||
const pay = this.createSdk();
|
const pay = await this.createSdk();
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
description: trade.title,
|
description: trade.title,
|
||||||
@@ -83,7 +82,9 @@ export class PaymentWxpay implements IPaymentProvider {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private createSdk() {
|
private async createSdk() {
|
||||||
|
const WxPayLib = await this.access.importRuntime("wechatpay-node-v3");
|
||||||
|
const WxPay = WxPayLib.default;
|
||||||
const pay = new WxPay({
|
const pay = new WxPay({
|
||||||
appid: this.access.appId,
|
appid: this.access.appId,
|
||||||
mchid: this.access.mchid,
|
mchid: this.access.mchid,
|
||||||
@@ -94,7 +95,7 @@ export class PaymentWxpay implements IPaymentProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async onNotify(notifyData: any, updateTrade: UpdateTrade) {
|
async onNotify(notifyData: any, updateTrade: UpdateTrade) {
|
||||||
const pay = this.createSdk();
|
const pay = await this.createSdk();
|
||||||
const { ciphertext, associated_data, nonce } = notifyData.resource;
|
const { ciphertext, associated_data, nonce } = notifyData.resource;
|
||||||
logger.info(`微信支付notify:${JSON.stringify(notifyData)}`);
|
logger.info(`微信支付notify:${JSON.stringify(notifyData)}`);
|
||||||
const key = this.access.key;
|
const key = this.access.key;
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import { AccessInput, BaseAccess, IsAccess } from "@certd/pipeline";
|
import { AccessInput, BaseAccess, IsAccess } from "@certd/pipeline";
|
||||||
import FormData from "form-data";
|
import FormData from "form-data";
|
||||||
import { authenticator } from "otplib";
|
|
||||||
|
|
||||||
export interface ProxyHost {
|
export interface ProxyHost {
|
||||||
id: number;
|
id: number;
|
||||||
@@ -274,6 +273,7 @@ export class NginxProxyManagerAccess extends BaseAccess {
|
|||||||
|
|
||||||
let code: string;
|
let code: string;
|
||||||
try {
|
try {
|
||||||
|
const { authenticator } = await this.importRuntime("otplib");
|
||||||
code = authenticator.generate(this.totpSecret);
|
code = authenticator.generate(this.totpSecret);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw this.describeError(error, "Generating TOTP code");
|
throw this.describeError(error, "Generating TOTP code");
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ export class OidcOauthProvider extends BaseAddon implements IOauthProvider {
|
|||||||
issuerUrl = "";
|
issuerUrl = "";
|
||||||
|
|
||||||
async getClient() {
|
async getClient() {
|
||||||
const client = await import("openid-client");
|
const client = await this.importRuntime("openid-client");
|
||||||
const server = new URL(this.issuerUrl); // Authorization Server's Issuer Identifier
|
const server = new URL(this.issuerUrl); // Authorization Server's Issuer Identifier
|
||||||
|
|
||||||
const config = await client.discovery(server, this.clientId, this.clientSecretKey);
|
const config = await client.discovery(server, this.clientId, this.clientSecretKey);
|
||||||
|
|||||||
Reference in New Issue
Block a user