mirror of
https://github.com/certd/certd.git
synced 2026-07-12 08:17:32 +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",
|
||||
"@simplewebauthn/browser": "^13.2.2",
|
||||
"@simplewebauthn/server": "^13.2.3",
|
||||
"alipay-sdk": "^4.13.0",
|
||||
"axios": "^1.9.0",
|
||||
"bcryptjs": "^2.4.3",
|
||||
"better-sqlite3": "^11.1.2",
|
||||
@@ -96,8 +95,6 @@
|
||||
"nanoid": "^5.0.7",
|
||||
"node-forge": "^1.3.1",
|
||||
"nodemailer": "^6.9.16",
|
||||
"openid-client": "^6.8.1",
|
||||
"otplib": "^12.0.1",
|
||||
"pg": "^8.12.0",
|
||||
"psl": "^1.15.0",
|
||||
"punycode.js": "^2.3.1",
|
||||
@@ -113,7 +110,6 @@
|
||||
"svg-captcha": "^1.4.0",
|
||||
"typeorm": "^0.3.20",
|
||||
"uuid": "^10.0.0",
|
||||
"wechatpay-node-v3": "^2.2.1",
|
||||
"whoiser": "2.0.0-beta.10",
|
||||
"xml2js": "^0.6.2"
|
||||
},
|
||||
@@ -170,7 +166,11 @@
|
||||
"@google-cloud/publicca": "^1.3.0",
|
||||
"basic-ftp": "^5.0.5",
|
||||
"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": {
|
||||
"node": ">=20.0.0"
|
||||
|
||||
@@ -105,7 +105,7 @@ export class PaymentAlipay implements IPaymentProvider {
|
||||
}
|
||||
|
||||
private async createAlipaySdk() {
|
||||
const AlipaySdk = await import("alipay-sdk");
|
||||
const AlipaySdk = await this.access.importRuntime("alipay-sdk");
|
||||
|
||||
const alipaySdk = new AlipaySdk.AlipaySdk({
|
||||
appId: this.access.appId,
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { IPaymentProvider, TradeEntity, UpdateTrade, UpdateTradeInfo } from "@certd/commercial-core";
|
||||
import WxPay from "wechatpay-node-v3";
|
||||
import dayjs from "dayjs";
|
||||
import { logger } from "@certd/basic"; // 支持使用require
|
||||
import { logger } from "@certd/basic";
|
||||
import { WxpayAccess } from "../../../plugins/plugin-plus/wxpay/access.js";
|
||||
export class PaymentWxpay implements IPaymentProvider {
|
||||
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 });
|
||||
logger.info(`微信支付查询订单返回:${JSON.stringify(result)}`);
|
||||
@@ -58,7 +57,7 @@ export class PaymentWxpay implements IPaymentProvider {
|
||||
async createOrder(trade: TradeEntity, opts: { bindUrl: string; clientIp: string }) {
|
||||
const notify_url = `${opts.bindUrl}/api/payment/notify/wxpay`;
|
||||
|
||||
const pay = this.createSdk();
|
||||
const pay = await this.createSdk();
|
||||
|
||||
const params = {
|
||||
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({
|
||||
appid: this.access.appId,
|
||||
mchid: this.access.mchid,
|
||||
@@ -94,7 +95,7 @@ export class PaymentWxpay implements IPaymentProvider {
|
||||
}
|
||||
|
||||
async onNotify(notifyData: any, updateTrade: UpdateTrade) {
|
||||
const pay = this.createSdk();
|
||||
const pay = await this.createSdk();
|
||||
const { ciphertext, associated_data, nonce } = notifyData.resource;
|
||||
logger.info(`微信支付notify:${JSON.stringify(notifyData)}`);
|
||||
const key = this.access.key;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { AccessInput, BaseAccess, IsAccess } from "@certd/pipeline";
|
||||
import FormData from "form-data";
|
||||
import { authenticator } from "otplib";
|
||||
|
||||
export interface ProxyHost {
|
||||
id: number;
|
||||
@@ -274,6 +273,7 @@ export class NginxProxyManagerAccess extends BaseAccess {
|
||||
|
||||
let code: string;
|
||||
try {
|
||||
const { authenticator } = await this.importRuntime("otplib");
|
||||
code = authenticator.generate(this.totpSecret);
|
||||
} catch (error) {
|
||||
throw this.describeError(error, "Generating TOTP code");
|
||||
|
||||
@@ -49,7 +49,7 @@ export class OidcOauthProvider extends BaseAddon implements IOauthProvider {
|
||||
issuerUrl = "";
|
||||
|
||||
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 config = await client.discovery(server, this.clientId, this.clientSecretKey);
|
||||
|
||||
Reference in New Issue
Block a user