@pisell/private-materials 6.3.123 → 6.3.125

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 (129) hide show
  1. package/build/lowcode/assets-daily.json +11 -11
  2. package/build/lowcode/assets-dev.json +2 -2
  3. package/build/lowcode/assets-prod.json +11 -11
  4. package/build/lowcode/index.js +1 -1
  5. package/build/lowcode/meta.js +1 -1
  6. package/build/lowcode/preview.js +4 -4
  7. package/build/lowcode/render/default/view.js +4 -4
  8. package/build/lowcode/view.js +4 -4
  9. package/es/components/booking/addons/model.d.ts +10 -1
  10. package/es/components/booking/forms/model.d.ts +10 -1
  11. package/es/components/booking/forms/sendModal/useSendModal.d.ts +0 -1
  12. package/es/components/booking/info/clientVariant/hooks/useIsLowSpeedNetwork.d.ts +0 -1
  13. package/es/components/booking/info/hooks/useInfoHolder.d.ts +0 -1
  14. package/es/components/booking/info/model.d.ts +10 -1
  15. package/es/components/booking/model.d.ts +9 -1
  16. package/es/components/booking/notes/model.d.ts +10 -1
  17. package/es/components/booking/payments/model.d.ts +10 -1
  18. package/es/components/eftposPay/amount.js +15 -1
  19. package/es/components/eftposPay/app.js +2 -1
  20. package/es/components/eftposPay/component/fail/failCustom.js +12 -4
  21. package/es/components/eftposPay/component/fail/index.js +14 -6
  22. package/es/components/eftposPay/component/fail/network.js +3 -0
  23. package/es/components/eftposPay/component/fail/unknow.js +8 -0
  24. package/es/components/eftposPay/component/manual/index.js +13 -1
  25. package/es/components/eftposPay/component/signature/index.js +3 -0
  26. package/es/components/eftposPay/device.js +33 -22
  27. package/es/components/eftposPay/index.js +48 -11
  28. package/es/components/eftposPay/linkly/hooks/normal.js +21 -68
  29. package/es/components/eftposPay/linkly/hooks/useTimeQuery.js +20 -81
  30. package/es/components/eftposPay/linkly/index.js +10 -23
  31. package/es/components/eftposPay/pay.js +14 -7
  32. package/es/components/eftposPay/payo/config.js +38 -5
  33. package/es/components/eftposPay/payo/hooks.js +3 -12
  34. package/es/components/eftposPay/payo/payment.js +69 -136
  35. package/es/components/eftposPay/tip.js +5 -0
  36. package/es/components/eftposPay/tyro/hooks.d.ts +0 -1
  37. package/es/components/eftposPay/tyro/index.js +44 -11
  38. package/es/components/eftposPay/utils/payLog.d.ts +81 -0
  39. package/es/components/eftposPay/utils/payLog.js +430 -0
  40. package/es/components/eftposPay/windcave/receiptAction.js +5 -0
  41. package/es/components/eftposPay/windcave/windcave.js +28 -29
  42. package/es/components/eventBooking/components/ErrorTip/index.d.ts +0 -1
  43. package/es/components/eventBooking/components/bookingAvailabilityCalendar/components/CalendarDate/CalenDateStatus/index.d.ts +0 -1
  44. package/es/components/eventBooking/components/bookingAvailabilityCalendar/components/CalendarDate/CalenDateWeek/CallToBook/index.d.ts +0 -1
  45. package/es/components/eventBooking/components/bookingAvailabilityCalendar/components/CalendarDate/CalenDateWeek/WeekItem/index.d.ts +0 -1
  46. package/es/components/eventBooking/components/bookingAvailabilityCalendar/components/CalendarDate/CalenDateWeek/index.d.ts +0 -1
  47. package/es/components/eventBooking/components/bookingAvailabilityCalendar/components/CalendarDate/Item/DayItem/index.d.ts +0 -1
  48. package/es/components/eventBooking/components/bookingAvailabilityCalendar/components/CalendarDate/Item/index.d.ts +0 -1
  49. package/es/components/eventBooking/components/bookingAvailabilityCalendar/components/CalendarDate/Status/index.d.ts +0 -1
  50. package/es/components/pay/toC/PaymentMethods/StripePay/Stripe/Finish/index.d.ts +0 -1
  51. package/es/components/pay/toC/PaymentMethods/StripePay/Stripe/StripeSDK/index.d.ts +0 -1
  52. package/es/components/pay/toC/PaymentMethods/StripePay/Stripe/components/PageLoading/index.d.ts +0 -1
  53. package/es/components/pay/toC/PaymentMethods/WalletPass/index.d.ts +0 -5
  54. package/es/components/pay/toC/PaymentMethods/WalletPass/index.js +142 -165
  55. package/es/components/pay/toC/PaymentMethods/WalletPass/serve.d.ts +0 -6
  56. package/es/components/pay/toC/PaymentMethods/WalletPass/utils.js +3 -3
  57. package/es/components/pay/toC/WalletPassBlock/index.js +1 -3
  58. package/es/components/pay/toC/index.js +31 -65
  59. package/es/components/pay/toC/model.d.ts +9 -2
  60. package/es/components/pay/toC/serve.d.ts +0 -18
  61. package/es/components/pay/toC/serve.js +15 -42
  62. package/es/components/pay/toC/utils.d.ts +2 -2
  63. package/es/components/pay/toC/utils.js +0 -4
  64. package/es/components/schedules/model.d.ts +9 -1
  65. package/es/components/shoppingCart/components/Empty/index.d.ts +0 -1
  66. package/es/hooks/usePaymentLogger.d.ts +0 -1
  67. package/es/plus/selectHolder/components/ErrorTip/index.d.ts +0 -1
  68. package/es/pro/Login2.0/components/phoneValidation.js +65 -58
  69. package/lib/components/booking/addons/model.d.ts +10 -1
  70. package/lib/components/booking/forms/model.d.ts +10 -1
  71. package/lib/components/booking/forms/sendModal/useSendModal.d.ts +0 -1
  72. package/lib/components/booking/info/clientVariant/hooks/useIsLowSpeedNetwork.d.ts +0 -1
  73. package/lib/components/booking/info/hooks/useInfoHolder.d.ts +0 -1
  74. package/lib/components/booking/info/model.d.ts +10 -1
  75. package/lib/components/booking/model.d.ts +9 -1
  76. package/lib/components/booking/notes/model.d.ts +10 -1
  77. package/lib/components/booking/payments/model.d.ts +10 -1
  78. package/lib/components/eftposPay/amount.js +13 -1
  79. package/lib/components/eftposPay/app.js +2 -1
  80. package/lib/components/eftposPay/component/fail/failCustom.js +10 -2
  81. package/lib/components/eftposPay/component/fail/index.js +10 -2
  82. package/lib/components/eftposPay/component/fail/network.js +3 -0
  83. package/lib/components/eftposPay/component/fail/unknow.js +8 -0
  84. package/lib/components/eftposPay/component/manual/index.js +10 -0
  85. package/lib/components/eftposPay/component/signature/index.js +3 -0
  86. package/lib/components/eftposPay/device.js +11 -10
  87. package/lib/components/eftposPay/index.js +36 -11
  88. package/lib/components/eftposPay/linkly/hooks/normal.js +22 -43
  89. package/lib/components/eftposPay/linkly/hooks/useTimeQuery.js +13 -65
  90. package/lib/components/eftposPay/linkly/index.js +7 -10
  91. package/lib/components/eftposPay/pay.js +9 -1
  92. package/lib/components/eftposPay/payo/config.js +15 -8
  93. package/lib/components/eftposPay/payo/hooks.js +12 -10
  94. package/lib/components/eftposPay/payo/payment.js +31 -65
  95. package/lib/components/eftposPay/tip.js +5 -0
  96. package/lib/components/eftposPay/tyro/hooks.d.ts +0 -1
  97. package/lib/components/eftposPay/tyro/index.js +21 -17
  98. package/lib/components/eftposPay/utils/payLog.d.ts +81 -0
  99. package/lib/components/eftposPay/utils/payLog.js +320 -0
  100. package/lib/components/eftposPay/windcave/receiptAction.js +5 -0
  101. package/lib/components/eftposPay/windcave/windcave.js +18 -20
  102. package/lib/components/eventBooking/components/ErrorTip/index.d.ts +0 -1
  103. package/lib/components/eventBooking/components/bookingAvailabilityCalendar/components/CalendarDate/CalenDateStatus/index.d.ts +0 -1
  104. package/lib/components/eventBooking/components/bookingAvailabilityCalendar/components/CalendarDate/CalenDateWeek/CallToBook/index.d.ts +0 -1
  105. package/lib/components/eventBooking/components/bookingAvailabilityCalendar/components/CalendarDate/CalenDateWeek/WeekItem/index.d.ts +0 -1
  106. package/lib/components/eventBooking/components/bookingAvailabilityCalendar/components/CalendarDate/CalenDateWeek/index.d.ts +0 -1
  107. package/lib/components/eventBooking/components/bookingAvailabilityCalendar/components/CalendarDate/Item/DayItem/index.d.ts +0 -1
  108. package/lib/components/eventBooking/components/bookingAvailabilityCalendar/components/CalendarDate/Item/index.d.ts +0 -1
  109. package/lib/components/eventBooking/components/bookingAvailabilityCalendar/components/CalendarDate/Status/index.d.ts +0 -1
  110. package/lib/components/pay/toC/PaymentMethods/StripePay/Stripe/Finish/index.d.ts +0 -1
  111. package/lib/components/pay/toC/PaymentMethods/StripePay/Stripe/StripeSDK/index.d.ts +0 -1
  112. package/lib/components/pay/toC/PaymentMethods/StripePay/Stripe/components/PageLoading/index.d.ts +0 -1
  113. package/lib/components/pay/toC/PaymentMethods/WalletPass/index.d.ts +0 -5
  114. package/lib/components/pay/toC/PaymentMethods/WalletPass/index.js +100 -90
  115. package/lib/components/pay/toC/PaymentMethods/WalletPass/serve.d.ts +0 -6
  116. package/lib/components/pay/toC/PaymentMethods/WalletPass/utils.js +2 -2
  117. package/lib/components/pay/toC/WalletPassBlock/index.js +1 -3
  118. package/lib/components/pay/toC/index.js +19 -52
  119. package/lib/components/pay/toC/model.d.ts +9 -2
  120. package/lib/components/pay/toC/serve.d.ts +0 -18
  121. package/lib/components/pay/toC/serve.js +0 -6
  122. package/lib/components/pay/toC/utils.d.ts +2 -2
  123. package/lib/components/pay/toC/utils.js +2 -6
  124. package/lib/components/schedules/model.d.ts +9 -1
  125. package/lib/components/shoppingCart/components/Empty/index.d.ts +0 -1
  126. package/lib/hooks/usePaymentLogger.d.ts +0 -1
  127. package/lib/plus/selectHolder/components/ErrorTip/index.d.ts +0 -1
  128. package/lib/pro/Login2.0/components/phoneValidation.js +4 -2
  129. package/package.json +2 -2
@@ -24,6 +24,7 @@ import { Decimal } from 'decimal.js';
24
24
  import { getUuid, getPayParams, getBrowserVersion } from "../helper";
25
25
  import Step from "../component/step/step";
26
26
  import { useStoreRef } from "../hooks";
27
+ import payLog from "../utils/payLog";
27
28
  var Minute = 1000 * 60;
28
29
  export default (function (_ref) {
29
30
  var api = _ref.api,
@@ -116,6 +117,11 @@ export default (function (_ref) {
116
117
  var status = _ref2.status,
117
118
  message = _ref2.message,
118
119
  terminalInfo = _ref2.terminalInfo;
120
+ payLog.log('Tyro:终端信息回调', {
121
+ status: status,
122
+ terminalInfo: terminalInfo,
123
+ message: message
124
+ });
119
125
  if (status === 'success' && terminalInfo !== null && terminalInfo !== void 0 && terminalInfo.available) {
120
126
  cb();
121
127
  }
@@ -133,7 +139,7 @@ export default (function (_ref) {
133
139
  * @Date: 2024-08-19 11:32
134
140
  */
135
141
  var refundOrder = function refundOrder() {
136
- var _deviceRef$current3, _deviceRef$current4;
142
+ var _deviceRef$current3, _deviceRef$current4, _requestParams$curren;
137
143
  var iClient = iClientRef.current;
138
144
  if (!iClient) {
139
145
  return;
@@ -187,6 +193,13 @@ export default (function (_ref) {
187
193
  requestId: res.data.id
188
194
  }));
189
195
  });
196
+ payLog.setContext({
197
+ transactionNumber: numRef.current
198
+ });
199
+ payLog.log('Tyro:发起退款', {
200
+ number: numRef === null || numRef === void 0 ? void 0 : numRef.current,
201
+ amount: (_requestParams$curren = requestParams.current) === null || _requestParams$curren === void 0 ? void 0 : _requestParams$curren.amount
202
+ });
190
203
  iClient.initiateRefund(requestParams.current, {
191
204
  receiptCallback: receiptCallbackImpl,
192
205
  transactionCompleteCallback: transactionCompleteCallbackImpl,
@@ -261,6 +274,13 @@ export default (function (_ref) {
261
274
  requestId: res.data.id
262
275
  }));
263
276
  });
277
+ payLog.setContext({
278
+ transactionNumber: numRef.current
279
+ });
280
+ payLog.log('Tyro:发起支付', {
281
+ number: numRef.current,
282
+ amount: requestParams.current.amount
283
+ });
264
284
  iClient.initiatePurchase(requestParams.current, {
265
285
  receiptCallback: receiptCallbackImpl,
266
286
  transactionCompleteCallback: transactionCompleteCallbackImpl,
@@ -284,7 +304,7 @@ export default (function (_ref) {
284
304
  }
285
305
  setStatus(Date.now());
286
306
  merchantReceiptRef.current = {};
287
- // 恢复 记录
307
+ payLog.log('Tyro:恢复上次交易');
288
308
  iClient.continueLastTransaction({
289
309
  receiptCallback: receiptCallbackImpl,
290
310
  transactionCompleteCallback: transactionCompleteCallbackImpl,
@@ -303,8 +323,10 @@ export default (function (_ref) {
303
323
  var receiptCallbackImpl = function receiptCallbackImpl(_ref3) {
304
324
  var signatureRequired = _ref3.signatureRequired,
305
325
  merchantReceipt = _ref3.merchantReceipt;
306
- console.log('商家小票 客户端是否打印小票 = ', signatureRequired);
307
- console.log('商家小票 小票内容 = \n', merchantReceipt);
326
+ payLog.log('Tyro:小票回调', {
327
+ signatureRequired: signatureRequired,
328
+ hasReceipt: !!merchantReceipt
329
+ });
308
330
  var receipt = [merchantReceipt].filter(function (item) {
309
331
  return typeof item === 'string';
310
332
  }).filter(Boolean);
@@ -331,6 +353,9 @@ export default (function (_ref) {
331
353
  */
332
354
  var statusMessageCallbackImpl = function statusMessageCallbackImpl(message) {
333
355
  var _listRef$current;
356
+ payLog.log('Tyro:状态消息', {
357
+ message: message
358
+ });
334
359
  var translateMsg = locales.getText('page.eftpos-pay.text.tyro')(message);
335
360
  var msg = Array.isArray(translateMsg) ? translateMsg.reduce(function (accumulator, currentValue) {
336
361
  return accumulator + ' ' + currentValue;
@@ -359,7 +384,9 @@ export default (function (_ref) {
359
384
  * @Date: 2024-08-19 11:34
360
385
  */
361
386
  var questionCallbackImpl = function questionCallbackImpl(question, answerCallback) {
362
- console.log('Question is ' + JSON.stringify(question));
387
+ payLog.log('Tyro:交互问题回调', {
388
+ question: question
389
+ });
363
390
  setStatus(-1);
364
391
  setManually(false);
365
392
  var msg = locales.getText('page.eftpos-pay.text.tyro')(question.text);
@@ -406,8 +433,9 @@ export default (function (_ref) {
406
433
  var _deviceRef$current9;
407
434
  setStatus(-1);
408
435
  setManually(false);
409
- console.log('Response = ' + JSON.stringify(response), ', Request = ', JSON.stringify(requestParams.current));
410
- console.log(' 客户小票 response.customerReceipt = \n', response.customerReceipt);
436
+ payLog.log('Tyro:交易完成回调', {
437
+ response: response
438
+ });
411
439
  var receipt = [// merchantReceiptRef.current?.merchantReceipt,
412
440
  response === null || response === void 0 ? void 0 : response.customerReceipt].filter(function (item) {
413
441
  return typeof item === 'string';
@@ -504,20 +532,22 @@ export default (function (_ref) {
504
532
  if (load && TyroRef.current) {
505
533
  var _IClient = TyroRef.current.IClient;
506
534
  if (_IClient) {
507
- console.log('apiKey = ', apiKey, 'posProductData = ', posProductData);
508
535
  var iclient = new _IClient(apiKey, posProductData);
509
- console.log(iclient.posProductData);
510
536
  iClientRef.current = iclient;
537
+ payLog.log('Tyro:SDK 初始化完成');
511
538
  if (isCancelRef.current) {
512
539
  return;
513
540
  }
514
541
  if (!numRef.current) {
515
542
  if (modeRef.current === ModeEnum.Pay || modeRef.current === ModeEnum.FullPay) {
543
+ payLog.log('Tyro:支付交易,查询终端信息');
516
544
  getTerminalInfo(payOrder);
517
545
  } else if (modeRef.current === ModeEnum.Refund) {
546
+ payLog.log('Tyro:退款交易,查询终端信息');
518
547
  getTerminalInfo(refundOrder);
519
548
  }
520
549
  } else {
550
+ payLog.log('Tyro:恢复上次交易,查询终端信息');
521
551
  getTerminalInfo(continueLastOrder);
522
552
  }
523
553
  }
@@ -536,8 +566,8 @@ export default (function (_ref) {
536
566
  };
537
567
  }
538
568
  if (status === 0) {
539
- console.log('开始倒计时...');
540
569
  clear = setTimeout(function () {
570
+ payLog.log('Tyro:连接超时');
541
571
  dispatch(updateState({
542
572
  status: 'fail'
543
573
  }));
@@ -562,7 +592,7 @@ export default (function (_ref) {
562
592
  if (!iClient) {
563
593
  return;
564
594
  }
565
- console.log('倒计时到了');
595
+ payLog.log('Tyro:交易超时,显示手动标记');
566
596
  setManually(true);
567
597
  }, Minute);
568
598
  return function () {
@@ -572,6 +602,7 @@ export default (function (_ref) {
572
602
  };
573
603
  }, [status]);
574
604
  var onManually = function onManually() {
605
+ payLog.log('Tyro:点击手动标记');
575
606
  dispatch(updateState({
576
607
  manual: {
577
608
  title: locales.getText('page.eftpos-pay.text.request.title')(mode),
@@ -594,12 +625,14 @@ export default (function (_ref) {
594
625
  return;
595
626
  }
596
627
  if (status > 0) {
628
+ payLog.log('Tyro:取消当前交易');
597
629
  iClient.cancelCurrentTransaction();
598
630
  return;
599
631
  }
600
632
  if (isCancelRef.current) {
601
633
  return;
602
634
  }
635
+ payLog.log('Tyro:取消(交易未开始)');
603
636
  isCancelRef.current = true;
604
637
  dispatch(updateState({
605
638
  status: 'fail'
@@ -0,0 +1,81 @@
1
+ export interface PayLogContext {
2
+ /** 渠道 */
3
+ channel?: string;
4
+ /** 订单ID */
5
+ orderId?: string | number;
6
+ /** 设备ID */
7
+ deviceId?: string | number;
8
+ /** 支付类型:PAYO / WINDCAVE / LINKLY / TYRO */
9
+ paymentType?: string;
10
+ /** 交易记录号 */
11
+ transactionNumber?: string;
12
+ /** 模式:pay / refund / query */
13
+ mode?: string;
14
+ /** 其他扩展信息 */
15
+ extra?: Record<string, any>;
16
+ }
17
+ declare class PayLog {
18
+ private static instance;
19
+ private sessionKey;
20
+ private context;
21
+ private logs;
22
+ private startTime;
23
+ private flushed;
24
+ private constructor();
25
+ static getInstance(): PayLog;
26
+ /**
27
+ * 初始化一次交易会话
28
+ * - 生成唯一 sessionKey
29
+ * - 恢复上报 localStorage 中残留的旧日志
30
+ * - 接受部分 context(后续可通过 setContext 补充)
31
+ */
32
+ init(context?: Partial<PayLogContext>): void;
33
+ /**
34
+ * 补充/更新上下文信息
35
+ * 新值覆盖旧值,extra 做浅合并
36
+ */
37
+ setContext(partial: Partial<PayLogContext>): void;
38
+ /**
39
+ * 记录一条日志
40
+ */
41
+ log(title: string, data?: any): void;
42
+ /**
43
+ * 上报日志到飞书并清理 localStorage
44
+ */
45
+ flush(customTitle?: string): void;
46
+ /**
47
+ * flush + 重置内部状态
48
+ */
49
+ destroy(): void;
50
+ /**
51
+ * 构建 sendWarningLog 所需的 content 数组
52
+ */
53
+ private buildContent;
54
+ /**
55
+ * 持久化当前会话到 localStorage
56
+ */
57
+ private persistToStorage;
58
+ /**
59
+ * 从 localStorage 移除指定 session
60
+ */
61
+ private removeFromStorage;
62
+ /**
63
+ * 获取 localStorage 中所有 session
64
+ */
65
+ private getAllSessions;
66
+ /**
67
+ * 恢复上报 localStorage 中残留的旧日志(崩溃/异常退出场景)
68
+ */
69
+ private recoverOrphanedLogs;
70
+ }
71
+ declare const payLog: PayLog;
72
+ export default payLog;
73
+ /**
74
+ * 在根组件中使用,管理 PayLog 生命周期
75
+ * - mount 时 init(+ 恢复上报残留日志)
76
+ * - unmount 时 flush
77
+ */
78
+ export declare function usePayLog(context?: Partial<PayLogContext>): {
79
+ log: (title: string, data?: any) => void;
80
+ setContext: (partial: Partial<PayLogContext>) => void;
81
+ };
@@ -0,0 +1,430 @@
1
+ var _excluded = ["extra"];
2
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
3
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
6
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
7
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
8
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
9
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
10
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
11
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
12
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
13
+ import dayjs from 'dayjs';
14
+ import { useEffect, useRef } from 'react';
15
+ import { sendWarningLog } from '@pisell/utils';
16
+
17
+ /** localStorage 持久化 key */
18
+ var STORAGE_KEY = 'pisell2_eftpos_paylog';
19
+
20
+ /** 异常关键词,命中时不压缩 */
21
+ var ERROR_KEYWORDS = ['失败', '错误', '异常', 'error', 'fail', 'timeout', '超时'];
22
+
23
+ // ─── 类型定义 ───
24
+
25
+ /** 压缩后的日志条目 */
26
+
27
+ /** 持久化到 localStorage 的会话结构 */
28
+
29
+ // ─── 工具函数 ───
30
+
31
+ function generateSessionKey() {
32
+ var ts = Date.now();
33
+ var rand = Math.random().toString(36).substring(2, 8);
34
+ return "eft_".concat(ts, "_").concat(rand);
35
+ }
36
+
37
+ /**
38
+ * 判断 title 是否包含异常关键词
39
+ */
40
+ function isErrorLog(title) {
41
+ var lower = title.toLowerCase();
42
+ return ERROR_KEYWORDS.some(function (kw) {
43
+ return lower.includes(kw);
44
+ });
45
+ }
46
+
47
+ /**
48
+ * 浅比较两个值是否"相同"(用于 data 去重)
49
+ */
50
+ function shallowEqual(a, b) {
51
+ if (a === b) return true;
52
+ if (a == null && b == null) return true;
53
+ if (a == null || b == null) return false;
54
+ try {
55
+ return JSON.stringify(a) === JSON.stringify(b);
56
+ } catch (_unused) {
57
+ return false;
58
+ }
59
+ }
60
+
61
+ /**
62
+ * 将原始日志列表压缩:连续同名非异常日志合并
63
+ */
64
+ function compressLogs(logs) {
65
+ if (logs.length === 0) return [];
66
+ var result = [];
67
+ var i = 0;
68
+ while (i < logs.length) {
69
+ var current = logs[i];
70
+ if (isErrorLog(current.t)) {
71
+ result.push({
72
+ t: current.t,
73
+ ts: current.ts,
74
+ d: current.d
75
+ });
76
+ i++;
77
+ continue;
78
+ }
79
+ var j = i + 1;
80
+ while (j < logs.length && logs[j].t === current.t && !isErrorLog(logs[j].t)) {
81
+ j++;
82
+ }
83
+ var count = j - i;
84
+ if (count === 1) {
85
+ result.push({
86
+ t: current.t,
87
+ ts: current.ts,
88
+ d: current.d
89
+ });
90
+ } else {
91
+ var last = logs[j - 1];
92
+ var entry = {
93
+ t: current.t,
94
+ ts: current.ts,
95
+ count: count,
96
+ lastTs: last.ts
97
+ };
98
+ if (current.d !== undefined) entry.d = current.d;
99
+ if (!shallowEqual(current.d, last.d) && last.d !== undefined) {
100
+ entry.lastD = last.d;
101
+ }
102
+ result.push(entry);
103
+ }
104
+ i = j;
105
+ }
106
+ return result;
107
+ }
108
+
109
+ // ─── PayLog 单例类 ───
110
+ var PayLog = /*#__PURE__*/function () {
111
+ function PayLog() {
112
+ _classCallCheck(this, PayLog);
113
+ _defineProperty(this, "sessionKey", null);
114
+ _defineProperty(this, "context", {});
115
+ _defineProperty(this, "logs", []);
116
+ _defineProperty(this, "startTime", 0);
117
+ _defineProperty(this, "flushed", false);
118
+ }
119
+ _createClass(PayLog, [{
120
+ key: "init",
121
+ value:
122
+ /**
123
+ * 初始化一次交易会话
124
+ * - 生成唯一 sessionKey
125
+ * - 恢复上报 localStorage 中残留的旧日志
126
+ * - 接受部分 context(后续可通过 setContext 补充)
127
+ */
128
+ function init(context) {
129
+ try {
130
+ this.recoverOrphanedLogs();
131
+ this.sessionKey = generateSessionKey();
132
+ this.context = context || {};
133
+ this.logs = [];
134
+ this.startTime = Date.now();
135
+ this.flushed = false;
136
+ this.log('PayLog 初始化', context);
137
+ } catch (error) {
138
+ console.error('PayLog init error:', error);
139
+ }
140
+ }
141
+
142
+ /**
143
+ * 补充/更新上下文信息
144
+ * 新值覆盖旧值,extra 做浅合并
145
+ */
146
+ }, {
147
+ key: "setContext",
148
+ value: function setContext(partial) {
149
+ if (!this.sessionKey) return;
150
+ var extra = partial.extra,
151
+ rest = _objectWithoutProperties(partial, _excluded);
152
+ Object.assign(this.context, rest);
153
+ if (extra) {
154
+ var _this$context;
155
+ this.context.extra = _objectSpread(_objectSpread({}, ((_this$context = this.context) === null || _this$context === void 0 ? void 0 : _this$context.extra) || {}), extra || {});
156
+ }
157
+ this.persistToStorage();
158
+ }
159
+
160
+ /**
161
+ * 记录一条日志
162
+ */
163
+ }, {
164
+ key: "log",
165
+ value: function log(title, data) {
166
+ if (!this.sessionKey) {
167
+ console.warn('PayLog: 未初始化,日志将被忽略 -', title);
168
+ return;
169
+ }
170
+ var entry = {
171
+ t: title,
172
+ ts: dayjs().format('HH:mm:ss.SSS')
173
+ };
174
+ if (data !== undefined) {
175
+ entry.d = data;
176
+ }
177
+ this.logs.push(entry);
178
+ this.persistToStorage();
179
+ }
180
+
181
+ /**
182
+ * 上报日志到飞书并清理 localStorage
183
+ */
184
+ }, {
185
+ key: "flush",
186
+ value: function flush(customTitle) {
187
+ if (this.flushed || !this.sessionKey) return;
188
+ this.flushed = true;
189
+ try {
190
+ var elapsed = ((Date.now() - this.startTime) / 1000).toFixed(1);
191
+ var compressed = compressLogs(this.logs);
192
+ var _this$context2 = this.context,
193
+ paymentType = _this$context2.paymentType,
194
+ mode = _this$context2.mode,
195
+ orderId = _this$context2.orderId;
196
+ var title = customTitle || "[EFTPOS] ".concat(paymentType || 'Unknown', "-").concat(mode || 'unknown', "-").concat(orderId || 'Unknown');
197
+ var content = this.buildContent(compressed, elapsed);
198
+ sendWarningLog({
199
+ title: title,
200
+ content: content
201
+ });
202
+ this.removeFromStorage(this.sessionKey);
203
+ } catch (error) {
204
+ console.error('PayLog flush error:', error);
205
+ } finally {
206
+ // 无论上报成功与否,清空 sessionKey,防止 flush 后的 log() 调用
207
+ // 将僵尸日志重新写回 localStorage,被下次 init() 误判为孤儿 session
208
+ this.sessionKey = null;
209
+ }
210
+ }
211
+
212
+ /**
213
+ * flush + 重置内部状态
214
+ */
215
+ }, {
216
+ key: "destroy",
217
+ value: function destroy() {
218
+ this.flush();
219
+ this.sessionKey = null;
220
+ this.context = {};
221
+ this.logs = [];
222
+ this.startTime = 0;
223
+ this.flushed = false;
224
+ }
225
+
226
+ // ─── 私有方法 ───
227
+
228
+ /**
229
+ * 构建 sendWarningLog 所需的 content 数组
230
+ */
231
+ }, {
232
+ key: "buildContent",
233
+ value: function buildContent(compressed, elapsed) {
234
+ var ctx = this.context;
235
+ return [{
236
+ key: 'sessionKey',
237
+ value: this.sessionKey || ''
238
+ }, {
239
+ key: '发起时间',
240
+ value: dayjs(this.startTime).format('YYYY-MM-DD HH:mm:ss')
241
+ }, {
242
+ key: '交易号',
243
+ value: String(ctx.transactionNumber || '未知')
244
+ }, {
245
+ key: '订单ID',
246
+ value: String(ctx.orderId || '未知')
247
+ }, {
248
+ key: '设备ID',
249
+ value: String(ctx.deviceId || '未知')
250
+ }, {
251
+ key: '支付类型',
252
+ value: String(ctx.paymentType || '未知')
253
+ }, {
254
+ key: '模式',
255
+ value: String(ctx.mode || '未知')
256
+ }, {
257
+ key: '渠道',
258
+ value: String(ctx.channel || '未知')
259
+ }, {
260
+ key: '总耗时',
261
+ value: "".concat(elapsed, "s")
262
+ },
263
+ // { key: '日志条数(原始/压缩)', value: `${this.logs.length}/${compressed.length}` },
264
+ {
265
+ key: '时间线',
266
+ value: JSON.stringify(compressed)
267
+ }];
268
+ }
269
+
270
+ /**
271
+ * 持久化当前会话到 localStorage
272
+ */
273
+ }, {
274
+ key: "persistToStorage",
275
+ value: function persistToStorage() {
276
+ if (!this.sessionKey) return;
277
+ try {
278
+ var all = this.getAllSessions();
279
+ all[this.sessionKey] = {
280
+ sessionKey: this.sessionKey,
281
+ context: this.context,
282
+ logs: this.logs,
283
+ startTime: this.startTime
284
+ };
285
+ localStorage.setItem(STORAGE_KEY, JSON.stringify(all));
286
+ } catch (error) {
287
+ console.error('PayLog persist error:', error);
288
+ }
289
+ }
290
+
291
+ /**
292
+ * 从 localStorage 移除指定 session
293
+ */
294
+ }, {
295
+ key: "removeFromStorage",
296
+ value: function removeFromStorage(key) {
297
+ try {
298
+ var all = this.getAllSessions();
299
+ delete all[key];
300
+ if (Object.keys(all).length === 0) {
301
+ localStorage.removeItem(STORAGE_KEY);
302
+ } else {
303
+ localStorage.setItem(STORAGE_KEY, JSON.stringify(all));
304
+ }
305
+ } catch (error) {
306
+ console.error('PayLog removeFromStorage error:', error);
307
+ }
308
+ }
309
+
310
+ /**
311
+ * 获取 localStorage 中所有 session
312
+ */
313
+ }, {
314
+ key: "getAllSessions",
315
+ value: function getAllSessions() {
316
+ try {
317
+ var raw = localStorage.getItem(STORAGE_KEY);
318
+ if (!raw) return {};
319
+ return JSON.parse(raw);
320
+ } catch (_unused2) {
321
+ return {};
322
+ }
323
+ }
324
+
325
+ /**
326
+ * 恢复上报 localStorage 中残留的旧日志(崩溃/异常退出场景)
327
+ */
328
+ }, {
329
+ key: "recoverOrphanedLogs",
330
+ value: function recoverOrphanedLogs() {
331
+ try {
332
+ var all = this.getAllSessions();
333
+ var keys = Object.keys(all);
334
+ if (keys.length === 0) return;
335
+ for (var _i = 0, _keys = keys; _i < _keys.length; _i++) {
336
+ var key = _keys[_i];
337
+ var session = all[key];
338
+ try {
339
+ var elapsed = ((Date.now() - session.startTime) / 1000).toFixed(1);
340
+ var compressed = compressLogs(session.logs);
341
+ var ctx = session.context;
342
+ var title = "[PRE][EFTPOS] ".concat(ctx.paymentType || '未知支付', "-").concat(ctx.mode || '未知模式', "-").concat(ctx.orderId || '未知订单ID');
343
+ var content = [{
344
+ key: 'sessionKey',
345
+ value: session.sessionKey
346
+ }, {
347
+ key: '发起时间',
348
+ value: dayjs(session.startTime).format('YYYY-MM-DD HH:mm:ss')
349
+ }, {
350
+ key: '交易号',
351
+ value: String(ctx.transactionNumber || '未知')
352
+ }, {
353
+ key: '订单ID',
354
+ value: String(ctx.orderId || '未知')
355
+ }, {
356
+ key: '设备ID',
357
+ value: String(ctx.deviceId || '未知')
358
+ }, {
359
+ key: '支付类型',
360
+ value: String(ctx.paymentType || '未知')
361
+ }, {
362
+ key: '模式',
363
+ value: String(ctx.mode || '未知')
364
+ }, {
365
+ key: '总耗时',
366
+ value: "".concat(elapsed, "s")
367
+ }, {
368
+ key: '日志条数(原始/压缩)',
369
+ value: "".concat(session.logs.length, "/").concat(compressed.length)
370
+ }, {
371
+ key: '时间线',
372
+ value: JSON.stringify(compressed)
373
+ }];
374
+ sendWarningLog({
375
+ title: title,
376
+ content: content
377
+ });
378
+ this.removeFromStorage(key);
379
+ } catch (err) {
380
+ console.error("PayLog: \u6062\u590D\u4E0A\u62A5\u5931\u8D25 (".concat(key, "):"), err);
381
+ this.removeFromStorage(key);
382
+ }
383
+ }
384
+ } catch (error) {
385
+ console.error('PayLog recoverOrphanedLogs error:', error);
386
+ }
387
+ }
388
+ }], [{
389
+ key: "getInstance",
390
+ value: function getInstance() {
391
+ if (!PayLog.instance) {
392
+ PayLog.instance = new PayLog();
393
+ }
394
+ return PayLog.instance;
395
+ }
396
+ }]);
397
+ return PayLog;
398
+ }(); // ─── 单例导出 ───
399
+ _defineProperty(PayLog, "instance", void 0);
400
+ var payLog = PayLog.getInstance();
401
+ export default payLog;
402
+
403
+ // ─── usePayLog Hook ───
404
+
405
+ /**
406
+ * 在根组件中使用,管理 PayLog 生命周期
407
+ * - mount 时 init(+ 恢复上报残留日志)
408
+ * - unmount 时 flush
409
+ */
410
+ export function usePayLog(context) {
411
+ var initialized = useRef(false);
412
+ useEffect(function () {
413
+ if (!initialized.current) {
414
+ initialized.current = true;
415
+ payLog.init(context);
416
+ }
417
+ return function () {
418
+ payLog.log('流程结束,上报日志');
419
+ payLog.flush();
420
+ };
421
+ }, []);
422
+ return {
423
+ log: function log(title, data) {
424
+ return payLog.log(title, data);
425
+ },
426
+ setContext: function setContext(partial) {
427
+ return payLog.setContext(partial);
428
+ }
429
+ };
430
+ }