@be-link/ecommerce-trade-service-node-sdk 0.1.58 → 0.1.60

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/enums.d.ts CHANGED
@@ -192,7 +192,9 @@ export declare namespace ENUM {
192
192
  /** 一元入会订单 */
193
193
  ONE_RMB_MEMBER = "ONE_RMB_MEMBER",
194
194
  /** 黑钻会员订单 */
195
- BLACK_DIAMOND_MEMBER = "BLACK_DIAMOND_MEMBER"
195
+ BLACK_DIAMOND_MEMBER = "BLACK_DIAMOND_MEMBER",
196
+ /** 核销券订单 */
197
+ VOUCHER = "VOUCHER"
196
198
  }
197
199
  /** 订单类型中文映射 */
198
200
  const OrderType_CN: Record<ENUM.OrderType, string>;
@@ -229,6 +231,23 @@ export declare namespace ENUM {
229
231
  /** 商家手动退款 */
230
232
  MERCHANT_MANUAL = "MERCHANT_MANUAL"
231
233
  }
234
+ /**
235
+ * 直播状态
236
+ * - 1:直播中。
237
+ * - 2:预告。
238
+ * - 3:回放。
239
+ * - 4:结束。
240
+ */
241
+ enum LiveRoomStatus {
242
+ /** 直播中 */
243
+ LIVE = "1",
244
+ /** 预告 */
245
+ PREVIEW = "2",
246
+ /** 回放 */
247
+ PLAYBACK = "3",
248
+ /** 结束 */
249
+ ENDED = "4"
250
+ }
232
251
  }
233
252
  /** RabbitMQ 交换机路由枚举 */
234
253
  export declare namespace EXCHANGE_ENUM {
package/enums.js CHANGED
@@ -214,6 +214,8 @@ var ENUM;
214
214
  OrderType["ONE_RMB_MEMBER"] = "ONE_RMB_MEMBER";
215
215
  /** 黑钻会员订单 */
216
216
  OrderType["BLACK_DIAMOND_MEMBER"] = "BLACK_DIAMOND_MEMBER";
217
+ /** 核销券订单 */
218
+ OrderType["VOUCHER"] = "VOUCHER";
217
219
  })(OrderType = ENUM.OrderType || (ENUM.OrderType = {}));
218
220
  /** 订单类型中文映射 */
219
221
  ENUM.OrderType_CN = {
@@ -222,6 +224,7 @@ var ENUM;
222
224
  [ENUM.OrderType.FULL_GIFT]: '满赠订单',
223
225
  [ENUM.OrderType.ONE_RMB_MEMBER]: '一元入会订单',
224
226
  [ENUM.OrderType.BLACK_DIAMOND_MEMBER]: '黑钻会员订单',
227
+ [ENUM.OrderType.VOUCHER]: '核销券订单',
225
228
  };
226
229
  let OrderPromotionType;
227
230
  (function (OrderPromotionType) {
@@ -260,6 +263,24 @@ var ENUM;
260
263
  /** 商家手动退款 */
261
264
  ReverseRefundHandlerEnum["MERCHANT_MANUAL"] = "MERCHANT_MANUAL";
262
265
  })(ReverseRefundHandlerEnum = ENUM.ReverseRefundHandlerEnum || (ENUM.ReverseRefundHandlerEnum = {}));
266
+ /**
267
+ * 直播状态
268
+ * - 1:直播中。
269
+ * - 2:预告。
270
+ * - 3:回放。
271
+ * - 4:结束。
272
+ */
273
+ let LiveRoomStatus;
274
+ (function (LiveRoomStatus) {
275
+ /** 直播中 */
276
+ LiveRoomStatus["LIVE"] = "1";
277
+ /** 预告 */
278
+ LiveRoomStatus["PREVIEW"] = "2";
279
+ /** 回放 */
280
+ LiveRoomStatus["PLAYBACK"] = "3";
281
+ /** 结束 */
282
+ LiveRoomStatus["ENDED"] = "4";
283
+ })(LiveRoomStatus = ENUM.LiveRoomStatus || (ENUM.LiveRoomStatus = {}));
263
284
  })(ENUM || (exports.ENUM = ENUM = {}));
264
285
  /** RabbitMQ 交换机路由枚举 */
265
286
  var EXCHANGE_ENUM;
@@ -84,6 +84,8 @@ export declare namespace PosCoreService {
84
84
  skuId: string;
85
85
  /** 直播间ID */
86
86
  liveRoomId?: string;
87
+ /** 直播间状态 */
88
+ liveRoomStatus?: ENUM.LiveRoomStatus;
87
89
  /** 订单来源类型k */
88
90
  source: ENUM.OrderSource;
89
91
  /** 订单来源平台类型 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@be-link/ecommerce-trade-service-node-sdk",
3
- "version": "0.1.58",
3
+ "version": "0.1.60",
4
4
  "description": "EcommerceTradeService Node.js SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/utils/http.d.ts CHANGED
@@ -9,27 +9,3 @@ declare module '@fastify/request-context' {
9
9
  }
10
10
  }
11
11
  export declare function callApi<T extends (...args: any[]) => Promise<any>>(url: string, request?: Parameters<T>[0]): Promise<Awaited<ReturnType<T>>>;
12
- export declare function getConnectionStats(): {
13
- activeRequests: number;
14
- totalRequests: number;
15
- peakActiveRequests: number;
16
- httpSockets: {
17
- total: number;
18
- hosts: number;
19
- details: NodeJS.ReadOnlyDict<import("net").Socket[]>;
20
- };
21
- httpsSockets: {
22
- total: number;
23
- hosts: number;
24
- details: NodeJS.ReadOnlyDict<import("net").Socket[]>;
25
- };
26
- config: {
27
- maxSockets: number;
28
- maxTotalSockets: number;
29
- requestTimeout: number;
30
- note: string;
31
- };
32
- };
33
- export declare function resetPeakStats(): void;
34
- export declare function startMonitoring(interval?: number): void;
35
- export declare function stopMonitoring(): void;
package/utils/http.js CHANGED
@@ -4,10 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.callApi = callApi;
7
- exports.getConnectionStats = getConnectionStats;
8
- exports.resetPeakStats = resetPeakStats;
9
- exports.startMonitoring = startMonitoring;
10
- exports.stopMonitoring = stopMonitoring;
11
7
  const axios_1 = __importDefault(require("axios"));
12
8
  const uuid_1 = require("uuid");
13
9
  const axios_retry_1 = __importDefault(require("axios-retry"));
@@ -17,13 +13,13 @@ const https_1 = __importDefault(require("https"));
17
13
  const safe_stable_stringify_1 = __importDefault(require("safe-stable-stringify"));
18
14
  // 针对高并发优化配置 - 支持2000并发
19
15
  const HTTP_CONFIG = {
20
- maxSockets: 2000, // 每个主机的最大socket连接数(支持2000并发)
16
+ maxSockets: 3000, // 每个主机的最大socket连接数(支持2000并发)
21
17
  maxFreeSockets: 1000, // 空闲socket保留数(50%复用率,提高连接复用效率)
22
- maxTotalSockets: 3000, // 所有主机总socket数(单后端场景优化)
18
+ maxTotalSockets: 10000, // 所有主机总socket数(单后端场景优化)
23
19
  keepAliveMsecs: 30000, // 保持连接30秒(平衡资源占用和连接复用)
24
- timeout: 3000, // socket超时3秒(高并发场景快速失败)
25
- requestTimeout: 30000, // 请求超时3秒(快速释放资源,避免慢请求占用连接)
26
- retryBaseDelay: 100, // 基础重试延迟100ms(给服务恢复时间)
20
+ timeout: 5000, // socket超时3秒(高并发场景快速失败)
21
+ requestTimeout: 5000, // 请求超时5秒(快速释放资源,避免慢请求占用连接)
22
+ retryBaseDelay: 200, // 基础重试延迟100ms(给服务恢复时间)
27
23
  logThreshold: 1000, // 日志采样率(每1000个请求采样1次,降低日志开销)
28
24
  monitorInterval: 5000, // 监控日志间隔(毫秒)
29
25
  };
@@ -174,108 +170,129 @@ async function callApi(url, request) {
174
170
  }
175
171
  }
176
172
  // 导出监控函数
177
- function getConnectionStats() {
178
- const stats = {
179
- // 当前状态
180
- activeRequests,
181
- totalRequests: requestCount,
182
- // 峰值指标
183
- peakActiveRequests,
184
- // Socket连接池状态(这是真正的并发控制点)
185
- httpSockets: {
186
- total: Object.keys(httpAgent.sockets).reduce((sum, host) => sum + (httpAgent.sockets[host]?.length || 0), 0),
187
- hosts: Object.keys(httpAgent.sockets).length,
188
- details: httpAgent.sockets,
189
- },
190
- httpsSockets: {
191
- total: Object.keys(httpsAgent.sockets).reduce((sum, host) => sum + (httpsAgent.sockets[host]?.length || 0), 0),
192
- hosts: Object.keys(httpsAgent.sockets).length,
193
- details: httpsAgent.sockets,
194
- },
195
- // 配置信息
196
- config: {
197
- maxSockets: HTTP_CONFIG.maxSockets,
198
- maxTotalSockets: HTTP_CONFIG.maxTotalSockets,
199
- requestTimeout: HTTP_CONFIG.requestTimeout,
200
- note: '已移除应用层并发队列限制,完全依赖socket连接池',
201
- },
202
- };
203
- return stats;
204
- }
173
+ // export function getConnectionStats() {
174
+ // const stats = {
175
+ // // 当前状态
176
+ // activeRequests,
177
+ // totalRequests: requestCount,
178
+ // // 峰值指标
179
+ // peakActiveRequests,
180
+ // // Socket连接池状态(这是真正的并发控制点)
181
+ // httpSockets: {
182
+ // total: Object.keys(httpAgent.sockets).reduce(
183
+ // (sum, host) => sum + (httpAgent.sockets[host]?.length || 0),
184
+ // 0,
185
+ // ),
186
+ // hosts: Object.keys(httpAgent.sockets).length,
187
+ // details: httpAgent.sockets,
188
+ // },
189
+ // httpsSockets: {
190
+ // total: Object.keys(httpsAgent.sockets).reduce(
191
+ // (sum, host) => sum + (httpsAgent.sockets[host]?.length || 0),
192
+ // 0,
193
+ // ),
194
+ // hosts: Object.keys(httpsAgent.sockets).length,
195
+ // details: httpsAgent.sockets,
196
+ // },
197
+ // // 配置信息
198
+ // config: {
199
+ // maxSockets: HTTP_CONFIG.maxSockets,
200
+ // maxTotalSockets: HTTP_CONFIG.maxTotalSockets,
201
+ // requestTimeout: HTTP_CONFIG.requestTimeout,
202
+ // note: '已移除应用层并发队列限制,完全依赖socket连接池',
203
+ // },
204
+ // }
205
+ // return stats
206
+ // }
205
207
  // 重置峰值统计(可用于定期重置)
206
- function resetPeakStats() {
207
- peakActiveRequests = activeRequests;
208
- console.log((0, safe_stable_stringify_1.default)({
209
- message: '峰值统计已重置',
210
- type: 'stats_reset',
211
- }));
212
- }
213
- // 定期监控日志
214
- let monitorTimer = null;
215
- function startMonitoring(interval = HTTP_CONFIG.monitorInterval) {
216
- if (monitorTimer) {
217
- console.log((0, safe_stable_stringify_1.default)({
218
- message: '监控已在运行中',
219
- type: 'monitor_already_running',
220
- }));
221
- return;
222
- }
223
- console.log((0, safe_stable_stringify_1.default)({
224
- message: '启动并发监控',
225
- interval: `${interval}ms`,
226
- type: 'monitor_start',
227
- }));
228
- monitorTimer = setInterval(() => {
229
- const stats = getConnectionStats();
230
- // 只在有活动时打印
231
- if (stats.totalRequests === 0) {
232
- return;
233
- }
234
- // 检测异常情况(基于socket连接池使用率)
235
- const httpSocketsUsage = stats.httpSockets.total / HTTP_CONFIG.maxSockets;
236
- const httpsSocketsUsage = stats.httpsSockets.total / HTTP_CONFIG.maxSockets;
237
- const maxSocketUsage = Math.max(httpSocketsUsage, httpsSocketsUsage);
238
- // Socket连接池使用率超过80%视为瓶颈
239
- const hasIssue = maxSocketUsage > 0.8;
240
- if (hasIssue) {
241
- console.warn((0, safe_stable_stringify_1.default)({
242
- message: '并发监控检测到瓶颈',
243
- 当前并发: stats.activeRequests,
244
- 峰值并发: stats.peakActiveRequests,
245
- 总请求数: stats.totalRequests,
246
- HTTP_Sockets: `${stats.httpSockets.total}/${HTTP_CONFIG.maxSockets} (${Math.round(httpSocketsUsage * 100)}%)`,
247
- HTTPS_Sockets: `${stats.httpsSockets.total}/${HTTP_CONFIG.maxSockets} (${Math.round(httpsSocketsUsage * 100)}%)`,
248
- 建议: 'Socket连接池接近饱和,考虑提高maxSockets配置',
249
- type: 'monitor_bottleneck_detected',
250
- }));
251
- }
252
- else if (stats.totalRequests % 10000 === 0) {
253
- // 每1万次请求打印一次正常状态
254
- console.log((0, safe_stable_stringify_1.default)({
255
- message: '并发监控运行正常',
256
- 总请求: stats.totalRequests,
257
- 当前并发: stats.activeRequests,
258
- 峰值并发: stats.peakActiveRequests,
259
- HTTP_Sockets使用率: `${Math.round(httpSocketsUsage * 100)}%`,
260
- HTTPS_Sockets使用率: `${Math.round(httpsSocketsUsage * 100)}%`,
261
- type: 'monitor_normal',
262
- }));
263
- }
264
- }, interval);
265
- }
266
- function stopMonitoring() {
267
- if (monitorTimer) {
268
- clearInterval(monitorTimer);
269
- monitorTimer = null;
270
- console.log((0, safe_stable_stringify_1.default)({
271
- message: '监控已停止',
272
- type: 'monitor_stop',
273
- }));
274
- }
275
- }
276
- // 自动启动监控(可选,如果不想自动启动可以注释掉)
277
- if (process.env.NODE_ENV !== 'test') {
278
- setTimeout(() => {
279
- startMonitoring();
280
- }, 3000); // 延迟3秒启动,避免服务启动时的干扰
281
- }
208
+ // export function resetPeakStats() {
209
+ // peakActiveRequests = activeRequests
210
+ // console.log(
211
+ // stringify({
212
+ // message: '峰值统计已重置',
213
+ // type: 'stats_reset',
214
+ // }),
215
+ // )
216
+ // }
217
+ // // 定期监控日志
218
+ // let monitorTimer: NodeJS.Timeout | null = null
219
+ // export function startMonitoring(interval: number = HTTP_CONFIG.monitorInterval) {
220
+ // if (monitorTimer) {
221
+ // console.log(
222
+ // stringify({
223
+ // message: '监控已在运行中',
224
+ // type: 'monitor_already_running',
225
+ // }),
226
+ // )
227
+ // return
228
+ // }
229
+ // console.log(
230
+ // stringify({
231
+ // message: '启动并发监控',
232
+ // interval: `${interval}ms`,
233
+ // type: 'monitor_start',
234
+ // }),
235
+ // )
236
+ // monitorTimer = setInterval(() => {
237
+ // const stats = getConnectionStats()
238
+ // // 只在有活动时打印
239
+ // if (stats.totalRequests === 0) {
240
+ // return
241
+ // }
242
+ // // 检测异常情况(基于socket连接池使用率)
243
+ // const httpSocketsUsage = stats.httpSockets.total / HTTP_CONFIG.maxSockets
244
+ // const httpsSocketsUsage = stats.httpsSockets.total / HTTP_CONFIG.maxSockets
245
+ // const maxSocketUsage = Math.max(httpSocketsUsage, httpsSocketsUsage)
246
+ // // Socket连接池使用率超过80%视为瓶颈
247
+ // const hasIssue = maxSocketUsage > 0.8
248
+ // if (hasIssue) {
249
+ // console.warn(
250
+ // stringify({
251
+ // message: '并发监控检测到瓶颈',
252
+ // 当前并发: stats.activeRequests,
253
+ // 峰值并发: stats.peakActiveRequests,
254
+ // 总请求数: stats.totalRequests,
255
+ // HTTP_Sockets: `${stats.httpSockets.total}/${HTTP_CONFIG.maxSockets} (${Math.round(
256
+ // httpSocketsUsage * 100,
257
+ // )}%)`,
258
+ // HTTPS_Sockets: `${stats.httpsSockets.total}/${HTTP_CONFIG.maxSockets} (${Math.round(
259
+ // httpsSocketsUsage * 100,
260
+ // )}%)`,
261
+ // 建议: 'Socket连接池接近饱和,考虑提高maxSockets配置',
262
+ // type: 'monitor_bottleneck_detected',
263
+ // }),
264
+ // )
265
+ // } else if (stats.totalRequests % 10000 === 0) {
266
+ // // 每1万次请求打印一次正常状态
267
+ // console.log(
268
+ // stringify({
269
+ // message: '并发监控运行正常',
270
+ // 总请求: stats.totalRequests,
271
+ // 当前并发: stats.activeRequests,
272
+ // 峰值并发: stats.peakActiveRequests,
273
+ // HTTP_Sockets使用率: `${Math.round(httpSocketsUsage * 100)}%`,
274
+ // HTTPS_Sockets使用率: `${Math.round(httpsSocketsUsage * 100)}%`,
275
+ // type: 'monitor_normal',
276
+ // }),
277
+ // )
278
+ // }
279
+ // }, interval)
280
+ // }
281
+ // export function stopMonitoring() {
282
+ // if (monitorTimer) {
283
+ // clearInterval(monitorTimer)
284
+ // monitorTimer = null
285
+ // console.log(
286
+ // stringify({
287
+ // message: '监控已停止',
288
+ // type: 'monitor_stop',
289
+ // }),
290
+ // )
291
+ // }
292
+ // }
293
+ // // 自动启动监控(可选,如果不想自动启动可以注释掉)
294
+ // if (process.env.NODE_ENV !== 'test') {
295
+ // setTimeout(() => {
296
+ // startMonitoring()
297
+ // }, 3000) // 延迟3秒启动,避免服务启动时的干扰
298
+ // }