@alipay/ams-checkout 0.0.1726734012-dev.1 → 0.0.1726734012-dev.2

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 (145) hide show
  1. package/dist/umd/ams-checkout.min.js +1 -1
  2. package/esm/component/channel.d.ts +19 -0
  3. package/esm/component/channel.js +87 -0
  4. package/esm/component/component.inline.style.d.ts +10 -0
  5. package/esm/component/component.inline.style.js +121 -0
  6. package/esm/component/component.popup.style.d.ts +25 -0
  7. package/esm/component/component.popup.style.js +203 -0
  8. package/esm/component/popupWindow.style.d.ts +11 -0
  9. package/esm/component/popupWindow.style.js +121 -0
  10. package/esm/config/index.d.ts +11 -0
  11. package/esm/config/index.js +20 -1
  12. package/esm/constant/index.d.ts +25 -0
  13. package/esm/constant/index.js +28 -0
  14. package/esm/core/bus/index.d.ts +3 -3
  15. package/esm/core/bus/index.js +14 -14
  16. package/esm/core/component/address.d.ts +8 -0
  17. package/esm/core/component/address.js +72 -0
  18. package/esm/core/component/appPreloadProcessing.js +2 -2
  19. package/esm/core/component/ckp/index.js +12 -8
  20. package/esm/core/component/element/components/address.d.ts +19 -0
  21. package/esm/core/component/element/components/address.js +68 -0
  22. package/esm/core/component/element/components/auth.d.ts +17 -0
  23. package/esm/core/component/element/components/auth.js +60 -0
  24. package/esm/core/component/element/components/payment.d.ts +19 -0
  25. package/esm/core/component/element/components/payment.js +74 -0
  26. package/esm/core/component/element/index.d.ts +47 -0
  27. package/esm/core/component/element/index.js +817 -0
  28. package/esm/core/component/element/mock.d.ts +4 -0
  29. package/esm/core/component/element/mock.js +491 -0
  30. package/esm/core/component/element/type.d.ts +191 -0
  31. package/esm/core/component/element/type.js +36 -0
  32. package/esm/core/component/element/utils.d.ts +13 -0
  33. package/esm/core/component/element/utils.js +6 -0
  34. package/esm/core/component/index.d.ts +12 -7
  35. package/esm/core/component/index.js +132 -78
  36. package/esm/core/drop-in/index.js +2 -2
  37. package/esm/core/instance/index.d.ts +1 -0
  38. package/esm/core/instance/index.js +24 -11
  39. package/esm/foundation/core/index.d.ts +28 -0
  40. package/esm/foundation/core/index.js +396 -0
  41. package/esm/foundation/index.d.ts +75 -0
  42. package/esm/foundation/index.js +42 -0
  43. package/esm/foundation/product-processor/easysafepay/deps.d.ts +18 -0
  44. package/esm/foundation/product-processor/easysafepay/deps.js +12 -0
  45. package/esm/foundation/product-processor/easysafepay/index.d.ts +26 -0
  46. package/esm/foundation/product-processor/easysafepay/index.js +464 -0
  47. package/esm/foundation/service/api-bus/ability/callback.d.ts +9 -0
  48. package/esm/foundation/service/api-bus/ability/callback.js +55 -0
  49. package/esm/foundation/service/api-bus/ability/globalData.d.ts +10 -0
  50. package/esm/foundation/service/api-bus/ability/globalData.js +89 -0
  51. package/esm/foundation/service/api-bus/ability/request.d.ts +10 -0
  52. package/esm/foundation/service/api-bus/ability/request.js +151 -0
  53. package/esm/foundation/service/api-bus/ability/security.d.ts +12 -0
  54. package/esm/foundation/service/api-bus/ability/security.js +161 -0
  55. package/esm/foundation/service/api-bus/ability/tracker.d.ts +9 -0
  56. package/esm/foundation/service/api-bus/ability/tracker.js +80 -0
  57. package/esm/foundation/service/api-bus/busManager.d.ts +127 -0
  58. package/esm/foundation/service/api-bus/busManager.js +398 -0
  59. package/esm/foundation/service/api-bus/index.d.ts +20 -0
  60. package/esm/foundation/service/api-bus/index.js +88 -0
  61. package/esm/foundation/service/api-bus/interface.d.ts +48 -0
  62. package/esm/foundation/service/api-bus/interface.js +54 -0
  63. package/esm/foundation/service/container/index.d.ts +32 -0
  64. package/esm/foundation/service/container/index.js +330 -0
  65. package/esm/foundation/service/container/popup.d.ts +17 -0
  66. package/esm/foundation/service/container/popup.js +103 -0
  67. package/esm/foundation/service/container/utils.d.ts +7 -0
  68. package/esm/foundation/service/container/utils.js +48 -0
  69. package/esm/foundation/service/event-center.d.ts +82 -0
  70. package/esm/foundation/service/event-center.js +274 -0
  71. package/esm/foundation/service/global-data/index.d.ts +11 -0
  72. package/esm/foundation/service/global-data/index.js +68 -0
  73. package/esm/foundation/service/index.d.ts +19 -0
  74. package/esm/foundation/service/index.js +82 -0
  75. package/esm/foundation/service/log/index.d.ts +43 -0
  76. package/esm/foundation/service/log/index.js +250 -0
  77. package/esm/foundation/service/log/keys.d.ts +13 -0
  78. package/esm/foundation/service/log/keys.js +103 -0
  79. package/esm/foundation/service/log/processor.d.ts +9 -0
  80. package/esm/foundation/service/log/processor.js +148 -0
  81. package/esm/foundation/service/log/types.d.ts +32 -0
  82. package/esm/foundation/service/log/types.js +1 -0
  83. package/esm/foundation/service/requester/deps.d.ts +17 -0
  84. package/esm/foundation/service/requester/deps.js +11 -0
  85. package/esm/foundation/service/requester/requester.d.ts +22 -0
  86. package/esm/foundation/service/requester/requester.js +217 -0
  87. package/esm/foundation/service/security/index.d.ts +28 -0
  88. package/esm/foundation/service/security/index.js +284 -0
  89. package/esm/foundation/service/security/security.d.ts +33 -0
  90. package/esm/foundation/service/security/security.js +182 -0
  91. package/esm/foundation/utils/gray_scale_utils.d.ts +7 -0
  92. package/esm/foundation/utils/gray_scale_utils.js +40 -0
  93. package/esm/foundation/utils/payment_context_utils.d.ts +13 -0
  94. package/esm/foundation/utils/payment_context_utils.js +57 -0
  95. package/esm/foundation/utils/payment_product_utils.d.ts +13 -0
  96. package/esm/foundation/utils/payment_product_utils.js +38 -0
  97. package/esm/foundation/utils/redirect_utils.d.ts +11 -0
  98. package/esm/foundation/utils/redirect_utils.js +262 -0
  99. package/esm/foundation/utils/system_events.d.ts +4 -0
  100. package/esm/foundation/utils/system_events.js +66 -0
  101. package/esm/foundation/utils/web_app_url_utils.d.ts +46 -0
  102. package/esm/foundation/utils/web_app_url_utils.js +112 -0
  103. package/esm/index.d.ts +19 -12
  104. package/esm/index.js +110 -56
  105. package/esm/plugin/applepay/component.js +13 -11
  106. package/esm/plugin/applepay/index.js +10 -6
  107. package/esm/plugin/applepay/service.d.ts +2 -2
  108. package/esm/plugin/applepay/service.js +26 -18
  109. package/esm/plugin/component/cashierApp.d.ts +10 -8
  110. package/esm/plugin/component/cashierApp.js +48 -11
  111. package/esm/plugin/component/channel.d.ts +4 -3
  112. package/esm/plugin/component/channel.js +39 -2
  113. package/esm/plugin/component/component.inline.style.d.ts +9 -10
  114. package/esm/plugin/component/component.inline.style.js +93 -10
  115. package/esm/plugin/component/component.popup.style.d.ts +15 -6
  116. package/esm/plugin/component/component.popup.style.js +30 -7
  117. package/esm/plugin/component/index.d.ts +14 -8
  118. package/esm/plugin/component/index.js +383 -187
  119. package/esm/plugin/component/popupWindow.style.d.ts +5 -2
  120. package/esm/plugin/component/popupWindow.style.js +70 -14
  121. package/esm/plugin/const.js +5 -5
  122. package/esm/plugin/drop-in/index.d.ts +5 -5
  123. package/esm/plugin/drop-in/index.js +7 -7
  124. package/esm/plugin/payment-element/utils.d.ts +2 -0
  125. package/esm/plugin/payment-element/utils.js +6 -0
  126. package/esm/plugin/paypal/index.js +2 -1
  127. package/esm/plugin/type.d.ts +4 -3
  128. package/esm/service/element.d.ts +4 -0
  129. package/esm/service/element.js +51 -0
  130. package/esm/service/index.d.ts +1 -0
  131. package/esm/service/index.js +6 -2
  132. package/esm/types/index.d.ts +337 -40
  133. package/esm/types/index.js +119 -55
  134. package/esm/util/createIframeNode.d.ts +2 -2
  135. package/esm/util/createIframeNode.js +3 -3
  136. package/esm/util/getBackScheme.d.ts +5 -0
  137. package/esm/util/getBackScheme.js +133 -0
  138. package/esm/util/index.js +4 -8
  139. package/esm/util/logger.d.ts +3 -3
  140. package/esm/util/logger.js +49 -13
  141. package/esm/util/security.d.ts +3 -2
  142. package/esm/util/security.js +2 -2
  143. package/esm/util/spm-map.d.ts +172 -0
  144. package/esm/util/spm-map.js +172 -0
  145. package/package.json +3 -1
@@ -0,0 +1,82 @@
1
+ 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); }
2
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
+ 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); } }
4
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
5
+ 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; }
6
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
+ 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); }
8
+ import { ContainerService } from "./container/index";
9
+ import { LogService } from "./log";
10
+ import { EventCenter } from "./event-center";
11
+ import { RequesterService } from "./requester/requester";
12
+ import { SecurityService } from "./security";
13
+ import { ApiBusManagerService } from "./api-bus";
14
+ import { GlobalDataService } from "./global-data";
15
+
16
+ /**
17
+ * @author 谦彧 <zhangmian.zm@alipay.com>
18
+ * @date 2024/9/17
19
+ */
20
+
21
+ export var ServiceProvider = /*#__PURE__*/function () {
22
+ function ServiceProvider(instanceId) {
23
+ _classCallCheck(this, ServiceProvider);
24
+ _defineProperty(this, "instanceId", void 0);
25
+ _defineProperty(this, "services", {
26
+ Log: new LogService(),
27
+ ApiBusManager: new ApiBusManagerService(),
28
+ Requester: new RequesterService(),
29
+ Container: new ContainerService(),
30
+ Security: new SecurityService(),
31
+ EventCenter: new EventCenter(),
32
+ GlobalData: new GlobalDataService()
33
+ });
34
+ _defineProperty(this, "extendServices", {});
35
+ this.instanceId = instanceId;
36
+ }
37
+ _createClass(ServiceProvider, [{
38
+ key: "init",
39
+ value: function init(initOptions, sdkMetaData) {
40
+ this.services['Log'].init(initOptions, this.instanceId, sdkMetaData);
41
+ this.services['ApiBusManager'].init(initOptions, this.instanceId, sdkMetaData);
42
+ this.services['Requester'].init(initOptions, this.instanceId, sdkMetaData);
43
+ this.services['Container'].init(initOptions, this.instanceId, sdkMetaData);
44
+ this.services['Security'].init(initOptions, this.instanceId, sdkMetaData);
45
+ this.services['EventCenter'].init(initOptions, this.instanceId, sdkMetaData);
46
+ this.services['GlobalData'].init(initOptions, this.instanceId, sdkMetaData);
47
+ }
48
+ }, {
49
+ key: "update",
50
+ value: function update(paymentContext) {
51
+ for (var serviceName in this.services) {
52
+ this.services[serviceName].update(paymentContext);
53
+ }
54
+ for (var _serviceName in this.extendServices) {
55
+ this.extendServices[_serviceName].update(paymentContext);
56
+ }
57
+ }
58
+ }, {
59
+ key: "getService",
60
+ value: function getService(serviceName) {
61
+ if (this.extendServices[serviceName]) {
62
+ return this.extendServices[serviceName];
63
+ }
64
+ return this.services[serviceName];
65
+ }
66
+ }, {
67
+ key: "registerService",
68
+ value: function registerService(serviceName, service) {
69
+ this.extendServices[serviceName] = service;
70
+ }
71
+ }], [{
72
+ key: "getInstance",
73
+ value: function getInstance(instanceId) {
74
+ if (!ServiceProvider.ProvidersMapping[instanceId]) {
75
+ ServiceProvider.ProvidersMapping[instanceId] = new ServiceProvider(instanceId);
76
+ }
77
+ return ServiceProvider.ProvidersMapping[instanceId];
78
+ }
79
+ }]);
80
+ return ServiceProvider;
81
+ }();
82
+ _defineProperty(ServiceProvider, "ProvidersMapping", {});
@@ -0,0 +1,43 @@
1
+ import { PaymentContext, SDKMetaData, Service } from '../../index';
2
+ import { IoptionsParams } from '../../../types';
3
+ import { LogExtra, LogMetaData, LogPayload } from './types';
4
+ /**
5
+ * @author 谦彧 <zhangmian.zm@alipay.com>
6
+ * @date 2024/9/18
7
+ */
8
+ interface Config {
9
+ scriptUrl: string;
10
+ spmConfig: object;
11
+ appId: string;
12
+ server?: string;
13
+ bizType: string;
14
+ batchCount: number;
15
+ productId: string;
16
+ mdata?: LogMetaData;
17
+ version?: string;
18
+ }
19
+ export declare class LogService implements Service {
20
+ private instanceId;
21
+ private logs;
22
+ private config;
23
+ private debug;
24
+ private componentStartTime;
25
+ private isLoaded;
26
+ private trackId;
27
+ constructor();
28
+ init(initOptions: IoptionsParams, instanceId: string, sdkMetaData: SDKMetaData): void;
29
+ update(paymentContext: PaymentContext): void;
30
+ destroy(): void;
31
+ setMetaData(metaData: LogMetaData): void;
32
+ getLogConfig(): Config;
33
+ logError(error: LogPayload, extra?: LogExtra, enableExtractCompliance?: boolean): LogService;
34
+ logInfo(info: LogPayload, extra?: LogExtra): LogService;
35
+ log(type: string, payload: LogPayload, extra?: LogExtra, enableExtractCompliance?: boolean): LogService;
36
+ private reportLogs;
37
+ private loadScript;
38
+ private initTracker;
39
+ send(): void;
40
+ setComponentStartTime(val: number): void;
41
+ getComponentStartTime(): number;
42
+ }
43
+ export {};
@@ -0,0 +1,250 @@
1
+ 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); }
2
+ 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; }
3
+ 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; }
4
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5
+ 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); } }
6
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
7
+ 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; }
8
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
9
+ 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); }
10
+ import { EnvironmentEnum } from "../../../types";
11
+ import { LogComplianceProcessor } from "./processor";
12
+ import { isPC } from "../../../util";
13
+ import { getStorageString, setStorageString } from "../../../util/storage";
14
+ import { SPM_MAP } from "../../../util/spm-map";
15
+
16
+ /**
17
+ * @author 谦彧 <zhangmian.zm@alipay.com>
18
+ * @date 2024/9/18
19
+ */
20
+
21
+ export var LogService = /*#__PURE__*/function () {
22
+ function LogService() {
23
+ _classCallCheck(this, LogService);
24
+ _defineProperty(this, "instanceId", void 0);
25
+ _defineProperty(this, "logs", void 0);
26
+ _defineProperty(this, "config", void 0);
27
+ _defineProperty(this, "debug", void 0);
28
+ // It will use to calc the timing from component creating/mounting for each event.
29
+ _defineProperty(this, "componentStartTime", void 0);
30
+ _defineProperty(this, "isLoaded", void 0);
31
+ _defineProperty(this, "trackId", void 0);
32
+ }
33
+ _createClass(LogService, [{
34
+ key: "init",
35
+ value: function init(initOptions, instanceId, sdkMetaData) {
36
+ this.logs = [];
37
+ this.config = LogConfig;
38
+ this.debug = ![EnvironmentEnum.prod, EnvironmentEnum.sandbox].includes(initOptions === null || initOptions === void 0 ? void 0 : initOptions.environment);
39
+ this.componentStartTime = 0;
40
+ this.isLoaded = false;
41
+ var deviceId = getStorageString('AMSSDK_STORAGE_ID');
42
+ if (!deviceId) {
43
+ deviceId = instanceId;
44
+ setStorageString('AMSSDK_STORAGE_ID', deviceId);
45
+ }
46
+ this.setMetaData({
47
+ instanceId: instanceId,
48
+ // use to identify a device, named from deprecated SDK
49
+ deviceId: deviceId,
50
+ sdkVersion: sdkMetaData.sdkVersion,
51
+ webAppVersion: sdkMetaData.webAppVersion,
52
+ productScene: sdkMetaData.productScene,
53
+ trackId: instanceId,
54
+ platform: isPC() ? 'PC' : 'WAP'
55
+ });
56
+ this.initTracker();
57
+ this.setComponentStartTime(Date.now());
58
+ this.logInfo({
59
+ title: 'NEW_AMSSDK_BY_MECHANT',
60
+ msg: "".concat(initOptions === null || initOptions === void 0 ? void 0 : initOptions.environment, "_").concat(initOptions === null || initOptions === void 0 ? void 0 : initOptions.locale)
61
+ }).send();
62
+ }
63
+ }, {
64
+ key: "update",
65
+ value: function update(paymentContext) {
66
+ var _paymentContext$payme, _paymentContext$payme2, _paymentContext$payme3, _paymentContext$payme4;
67
+ this.setComponentStartTime(Date.now());
68
+ this.setMetaData({
69
+ firstLogTime: this.componentStartTime,
70
+ renderDisplayType: paymentContext.displayInfo.type,
71
+ merchantId: paymentContext.paymentSessionObj.clientId,
72
+ productScene: (_paymentContext$payme = paymentContext.paymentSessionObj.paymentSessionConfig) === null || _paymentContext$payme === void 0 ? void 0 : _paymentContext$payme.productScene,
73
+ productSceneVersion: (_paymentContext$payme2 = paymentContext.paymentSessionObj.paymentSessionConfig) === null || _paymentContext$payme2 === void 0 ? void 0 : _paymentContext$payme2.productSceneVersion,
74
+ paymentMethodType: (_paymentContext$payme3 = paymentContext.paymentSessionObj.paymentMethodInfoView) === null || _paymentContext$payme3 === void 0 ? void 0 : _paymentContext$payme3.paymentMethodType,
75
+ paymentMethodCategoryType: (_paymentContext$payme4 = paymentContext.paymentSessionObj.paymentSessionConfig) === null || _paymentContext$payme4 === void 0 ? void 0 : _paymentContext$payme4.paymentMethodCategoryType,
76
+ trackId: paymentContext.paymentSessionId
77
+ });
78
+ }
79
+ }, {
80
+ key: "destroy",
81
+ value: function destroy() {}
82
+ }, {
83
+ key: "setMetaData",
84
+ value: function setMetaData(metaData) {
85
+ var _window,
86
+ _this = this;
87
+ this.config.mdata = Object.assign(this.config.mdata, metaData);
88
+ if ((_window = window) !== null && _window !== void 0 && _window.iTracker) {
89
+ var _window2;
90
+ (_window2 = window) === null || _window2 === void 0 || (_window2 = _window2.iTracker) === null || _window2 === void 0 || _window2.set({
91
+ mdata: this.config.mdata
92
+ });
93
+ setTimeout(function () {
94
+ _this.reportLogs();
95
+ }, 80);
96
+ } else {
97
+ this.initTracker();
98
+ }
99
+ }
100
+ }, {
101
+ key: "getLogConfig",
102
+ value: function getLogConfig() {
103
+ return this.config;
104
+ }
105
+ }, {
106
+ key: "logError",
107
+ value: function logError(error, extra) {
108
+ var enableExtractCompliance = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
109
+ return this.log('error', error, extra, enableExtractCompliance);
110
+ }
111
+ }, {
112
+ key: "logInfo",
113
+ value: function logInfo(info, extra) {
114
+ return this.log('info', info, extra);
115
+ }
116
+ }, {
117
+ key: "log",
118
+ value: function log(type, payload, extra) {
119
+ var _this2 = this;
120
+ var enableExtractCompliance = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
121
+ var newExtra = enableExtractCompliance ? LogComplianceProcessor.extractComplianceParams(payload.title, extra !== null && extra !== void 0 ? extra : {}, function (error, ext) {
122
+ _this2.logError(error, ext, false);
123
+ }) : extra !== null && extra !== void 0 ? extra : {};
124
+ var now = Date.now();
125
+ var fsDuration = now - this.componentStartTime;
126
+ var newPayload = _objectSpread({}, payload);
127
+ var oldTitle = payload === null || payload === void 0 ? void 0 : payload.title;
128
+ if (SPM_MAP[oldTitle]) {
129
+ newPayload.title = SPM_MAP[oldTitle];
130
+ }
131
+ newExtra.eventSource = 'sdk';
132
+ newExtra.eventAlias = extra !== null && extra !== void 0 && extra.eventAlias ? extra === null || extra === void 0 ? void 0 : extra.eventAlias : oldTitle;
133
+ this.logs.push({
134
+ type: type,
135
+ logPayload: newPayload,
136
+ extra: _objectSpread(_objectSpread({}, newExtra), {}, {
137
+ fsDuration: fsDuration,
138
+ timeStamp: now
139
+ })
140
+ });
141
+ if (this.debug) {
142
+ console.log('[web-sdk] Log', newPayload, newExtra);
143
+ }
144
+ this.send();
145
+ return this;
146
+ }
147
+ }, {
148
+ key: "reportLogs",
149
+ value: function reportLogs() {
150
+ var _window3;
151
+ if (!((_window3 = window) !== null && _window3 !== void 0 && _window3.iTracker)) {
152
+ return;
153
+ }
154
+ var _window$iTracker = window.iTracker,
155
+ logError = _window$iTracker.logError,
156
+ logInfo = _window$iTracker.logInfo,
157
+ reportRPC = _window$iTracker.reportRPC;
158
+ var logs = this.logs;
159
+ while (logs.length > 0) {
160
+ try {
161
+ var log = logs.pop();
162
+ if (log.type === 'error') {
163
+ var _log$logPayload;
164
+ logError(log.logPayload, _objectSpread({
165
+ title: (_log$logPayload = log.logPayload) === null || _log$logPayload === void 0 ? void 0 : _log$logPayload.title
166
+ }, log === null || log === void 0 ? void 0 : log.extra));
167
+ } else if (log.type === 'info') {
168
+ var _log$logPayload2;
169
+ logInfo(log.logPayload, _objectSpread({
170
+ title: (_log$logPayload2 = log.logPayload) === null || _log$logPayload2 === void 0 ? void 0 : _log$logPayload2.title
171
+ }, log === null || log === void 0 ? void 0 : log.extra));
172
+ } else if (log.type === 'rpc') {
173
+ var _log$logPayload3;
174
+ reportRPC(log.logPayload, _objectSpread({
175
+ title: (_log$logPayload3 = log.logPayload) === null || _log$logPayload3 === void 0 ? void 0 : _log$logPayload3.title
176
+ }, log === null || log === void 0 ? void 0 : log.extra));
177
+ }
178
+ } catch (error) {
179
+ console.error('Error occurred while calling iTracker method:', error);
180
+ }
181
+ }
182
+ }
183
+ }, {
184
+ key: "loadScript",
185
+ value: function loadScript(url, callback) {
186
+ var script = document.createElement('script');
187
+ script.type = 'text/javascript';
188
+ script.src = url;
189
+ script.onload = callback;
190
+ script.onerror = function () {
191
+ console.error("unable to load Antom script: ".concat(url));
192
+ };
193
+ document.body.appendChild(script);
194
+ }
195
+ }, {
196
+ key: "initTracker",
197
+ value: function initTracker() {
198
+ var _this3 = this;
199
+ if (this.isLoaded) return;
200
+ this.isLoaded = true;
201
+ try {
202
+ if (typeof localStorage !== 'undefined') {
203
+ this.loadScript(this.config.scriptUrl, function () {
204
+ var _window4;
205
+ (_window4 = window) === null || _window4 === void 0 || _window4.iTracker.initiTracker(_this3.config);
206
+ setTimeout(function () {
207
+ _this3.reportLogs();
208
+ }, 80);
209
+ });
210
+ }
211
+ } catch (error) {
212
+ console.error('Failed to initialize iTracker:', error);
213
+ }
214
+ }
215
+ }, {
216
+ key: "send",
217
+ value: function send() {
218
+ var _window5;
219
+ if ((_window5 = window) !== null && _window5 !== void 0 && _window5.iTracker) {
220
+ this.reportLogs();
221
+ } else {
222
+ this.initTracker();
223
+ }
224
+ }
225
+ }, {
226
+ key: "setComponentStartTime",
227
+ value: function setComponentStartTime(val) {
228
+ this.componentStartTime = val;
229
+ }
230
+ }, {
231
+ key: "getComponentStartTime",
232
+ value: function getComponentStartTime() {
233
+ return this.componentStartTime;
234
+ }
235
+ }]);
236
+ return LogService;
237
+ }();
238
+ var LogConfig = {
239
+ scriptUrl: 'https://gw.alipayobjects.com/render/p/yuyan_npm/@alipay_intl-tracker/1.6.0/dist/common.min.js',
240
+ spmConfig: {},
241
+ batchCount: 1,
242
+ appId: 'antom_sdk',
243
+ server: 'https://imdap-sea.alipay.com/loggw/dwcookieLogGet.do',
244
+ bizType: 'antom_sdk',
245
+ productId: 'ANTOM_SDK',
246
+ version: 'iteration/20231021',
247
+ mdata: {
248
+ firstLogTime: Date.now()
249
+ }
250
+ };
@@ -0,0 +1,13 @@
1
+ export declare class LogComplianceExtendKeys {
2
+ static complianceExtParams: Record<string, string>;
3
+ }
4
+ export declare const KEYS: {
5
+ EVENT_SDK_ON_ABNORMAL_EVENT_NAME: {
6
+ spmId: string;
7
+ alias: string;
8
+ };
9
+ EVENT_SDK_ON_ABNORMAL_EVENT_EXT_INFO: {
10
+ spmId: string;
11
+ alias: string;
12
+ };
13
+ };
@@ -0,0 +1,103 @@
1
+ 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); }
2
+ 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); } }
3
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
4
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5
+ 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; }
6
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
+ 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); }
8
+ export var LogComplianceExtendKeys = /*#__PURE__*/_createClass(function LogComplianceExtendKeys() {
9
+ _classCallCheck(this, LogComplianceExtendKeys);
10
+ });
11
+ // 静态常量字典,用于存储合规扩展参数
12
+ // c 辅助排查问题的内容,通常是字符串类型
13
+ // m 是 number 类型,通常用于数学计算,比如求平均数
14
+ // d 是维度,比如城市,就是维度信息,典型的用法就是按照维度计算 m 值,比如求上海人年龄的平均数,那么,上海这个城市信息,上报的时候就放在 d 字段,每个人的年龄信息,就应该放在 m 字段
15
+ _defineProperty(LogComplianceExtendKeys, "complianceExtParams", {
16
+ // C 字符串类型
17
+ requestSeq: 'C',
18
+ firstLogTime: 'C',
19
+ sessionData: 'C',
20
+ isPreload: 'C',
21
+ disableAccelerate: 'C',
22
+ deviceId: 'C',
23
+ url: 'C',
24
+ errorName: 'C',
25
+ isPrerender: 'C',
26
+ loadWebAppType: 'C',
27
+ rpcTraceId: 'C',
28
+ timezone: 'C',
29
+ userPath: 'C',
30
+ previousEventName: 'C',
31
+ containerCacheFileCount: 'C',
32
+ containerTotalFileCount: 'C',
33
+ containerMissedFiles: 'C',
34
+ containerOfflinePkgId: 'C',
35
+ containerTotalPkgCount: 'C',
36
+ webAppUrl: 'C',
37
+ edcDeviceRequest: 'C',
38
+ config: 'C',
39
+ initOptions: 'C',
40
+ edcDeviceId: 'C',
41
+ instanceId: 'C',
42
+ trackId: 'C',
43
+ errorMessage: 'C',
44
+ timestamp: 'C',
45
+ eventMessage: 'C',
46
+ checkoutUrl: 'C',
47
+ redirectInfo: 'C',
48
+ riskSdkInfo: 'C',
49
+ actionName: 'C',
50
+ requestId: 'C',
51
+ callbackData: 'C',
52
+ callbackId: 'C',
53
+ actionNames: 'C',
54
+ // D 维度信息
55
+ operationType: 'D',
56
+ jsApi: 'D',
57
+ extSdkError: 'D',
58
+ processResult: 'D',
59
+ iterationVersion: 'D',
60
+ OperationType: 'D',
61
+ edcVendor: 'D',
62
+ platform: 'D',
63
+ sdkVersion: 'D',
64
+ eventSource: 'D',
65
+ productScene: 'D',
66
+ paymentMethodCategoryType: 'D',
67
+ productSceneVersion: 'D',
68
+ merchantId: 'D',
69
+ eventName: 'D',
70
+ paymentMethodType: 'D',
71
+ containerVersion: 'D',
72
+ locale: 'D',
73
+ renderDisplayType: 'D',
74
+ webAppVersion: 'D',
75
+ eventCode: 'D',
76
+ containerType: 'D',
77
+ logVersion: 'D',
78
+ httpCode: 'D',
79
+ openType: 'D',
80
+ isCrashTack: 'D',
81
+ isCrashTrackOverride: 'D',
82
+ appUpgradeVersion: 'D',
83
+ fromFastSdk: 'D',
84
+ terminalType: 'D',
85
+ eventAlias: 'D',
86
+ // 用来标记事件别名
87
+ success: 'D',
88
+ // 用来标记行为是否成功
89
+ // M 数字类型
90
+ timeCost: 'M',
91
+ pageLoadProgress: 'M',
92
+ fsDuration: 'M'
93
+ });
94
+ export var KEYS = {
95
+ EVENT_SDK_ON_ABNORMAL_EVENT_NAME: {
96
+ spmId: 'a3753.b101271.c388193.d513345',
97
+ alias: 'sdk_event_onAbnormalEventName'
98
+ },
99
+ EVENT_SDK_ON_ABNORMAL_EVENT_EXT_INFO: {
100
+ spmId: 'a3753.b101271.c388193.d513391',
101
+ alias: 'sdk_event_onAbnormalKeys'
102
+ }
103
+ };
@@ -0,0 +1,9 @@
1
+ import { LogExtra, LogPayload } from './types';
2
+ export declare class LogComplianceProcessor {
3
+ private static abnormalEventNameSet;
4
+ private static nonComplianceEventKeys;
5
+ static extractComplianceParams(eventName: string, params: Record<string, any>, errorLogCallback?: (error: LogPayload, extra?: LogExtra) => void): Record<string, string>;
6
+ private static reportHasAbnormalEventName;
7
+ private static reportHasIllegalExtendInfoKey;
8
+ static flushAbnormalInfo(errorLogCallback?: (error: LogPayload, extra?: LogExtra) => void): void;
9
+ }
@@ -0,0 +1,148 @@
1
+ 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); }
2
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
+ 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); } }
4
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
5
+ 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; }
6
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
+ 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); }
8
+ import { LogComplianceExtendKeys, KEYS } from "./keys";
9
+ export var LogComplianceProcessor = /*#__PURE__*/function () {
10
+ function LogComplianceProcessor() {
11
+ _classCallCheck(this, LogComplianceProcessor);
12
+ }
13
+ _createClass(LogComplianceProcessor, null, [{
14
+ key: "extractComplianceParams",
15
+ value: function extractComplianceParams(eventName, params, errorLogCallback) {
16
+ var _this = this;
17
+ try {
18
+ // 触发防抖上报
19
+ logDebounceTracker.track(function () {
20
+ _this.flushAbnormalInfo(errorLogCallback);
21
+ });
22
+ // 事件名检测
23
+ var isSpmId = eventName ? eventName.includes('.') : false;
24
+ if (!isSpmId) {
25
+ // 非SPM,说明是未做映射的,需要加到埋点里面
26
+ this.reportHasAbnormalEventName(eventName);
27
+ }
28
+ var newParams = {};
29
+ // 逐个字段检查
30
+ for (var _i = 0, _Object$keys = Object.keys(params); _i < _Object$keys.length; _i++) {
31
+ var key = _Object$keys[_i];
32
+ // 如果当前字段不在合规表中,说明是未合规字段,剔除并且上报异常
33
+ if (key in LogComplianceExtendKeys.complianceExtParams) {
34
+ newParams[key] = "".concat(params[key]);
35
+ } else {
36
+ // 如果当前字段不在合规表中,说明是未合规字段,剔除并且上报异常
37
+ this.reportHasIllegalExtendInfoKey(eventName, key);
38
+ }
39
+ }
40
+ return newParams;
41
+ } catch (error) {
42
+ console.error(error);
43
+ return {};
44
+ }
45
+ }
46
+ }, {
47
+ key: "reportHasAbnormalEventName",
48
+ value: function reportHasAbnormalEventName(eventName) {
49
+ this.abnormalEventNameSet.add(eventName);
50
+ }
51
+ }, {
52
+ key: "reportHasIllegalExtendInfoKey",
53
+ value: function reportHasIllegalExtendInfoKey(eventName, key) {
54
+ if (!this.nonComplianceEventKeys[eventName]) {
55
+ this.nonComplianceEventKeys[eventName] = new Set();
56
+ }
57
+ this.nonComplianceEventKeys[eventName].add(key);
58
+ }
59
+ }, {
60
+ key: "flushAbnormalInfo",
61
+ value: function flushAbnormalInfo(errorLogCallback) {
62
+ try {
63
+ var _this$abnormalEventNa;
64
+ if (((_this$abnormalEventNa = this.abnormalEventNameSet) === null || _this$abnormalEventNa === void 0 ? void 0 : _this$abnormalEventNa.size) > 0) {
65
+ // 不正常的事件名按|分割
66
+ // Abnormal event use event name with divider "|"
67
+ var abnormalEventNames = Array.from(this.abnormalEventNameSet).join('|');
68
+ errorLogCallback && errorLogCallback({
69
+ title: KEYS.EVENT_SDK_ON_ABNORMAL_EVENT_NAME.spmId
70
+ }, {
71
+ eventAlias: KEYS.EVENT_SDK_ON_ABNORMAL_EVENT_NAME.alias,
72
+ errorMessage: abnormalEventNames
73
+ });
74
+ this.abnormalEventNameSet.clear();
75
+ }
76
+ // process nonComplianceEventKeys
77
+ // eg: if sdk_event_createComponent has key1,key2,key3
78
+ // sdk_event_createComponent>key1+key2+key3|otherEventName>key1+key2+key3
79
+ var nonComplianceEventKeysList = [];
80
+ if (Object.keys(this.nonComplianceEventKeys).length === 0) {
81
+ return;
82
+ }
83
+ for (var eventName in this.nonComplianceEventKeys) {
84
+ var keys = this.nonComplianceEventKeys[eventName];
85
+ var keyStr = "".concat(eventName, ">").concat(Array.from(keys).join('+'));
86
+ nonComplianceEventKeysList.push(keyStr);
87
+ }
88
+ var nonComplianceEventKeysLogString = nonComplianceEventKeysList.join('|');
89
+ errorLogCallback && errorLogCallback({
90
+ title: KEYS.EVENT_SDK_ON_ABNORMAL_EVENT_EXT_INFO.spmId
91
+ }, {
92
+ eventAlias: KEYS.EVENT_SDK_ON_ABNORMAL_EVENT_EXT_INFO.alias,
93
+ errorMessage: nonComplianceEventKeysLogString
94
+ });
95
+ this.nonComplianceEventKeys = {};
96
+ } catch (error) {
97
+ console.error(error);
98
+ }
99
+ }
100
+ }]);
101
+ return LogComplianceProcessor;
102
+ }();
103
+ // 记录不正常的事件名
104
+ _defineProperty(LogComplianceProcessor, "abnormalEventNameSet", new Set());
105
+ // 记录不合规的扩展字段,KEY是事件名,VALUE是非合规扩展字段列表
106
+ _defineProperty(LogComplianceProcessor, "nonComplianceEventKeys", {});
107
+ var LogDebounceTracker = /*#__PURE__*/function () {
108
+ function LogDebounceTracker() {
109
+ var debounceTime = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 5000;
110
+ _classCallCheck(this, LogDebounceTracker);
111
+ _defineProperty(this, "timeoutId", void 0);
112
+ _defineProperty(this, "debounceTime", void 0);
113
+ this.timeoutId = null;
114
+ this.debounceTime = debounceTime;
115
+ }
116
+ _createClass(LogDebounceTracker, [{
117
+ key: "track",
118
+ value: function track(callback) {
119
+ this.debounce(callback);
120
+ }
121
+
122
+ // 防抖实现
123
+ }, {
124
+ key: "debounce",
125
+ value: function debounce(callback) {
126
+ var _this2 = this;
127
+ if (this.timeoutId) {
128
+ clearTimeout(this.timeoutId);
129
+ }
130
+ this.timeoutId = setTimeout(function () {
131
+ _this2.report(callback);
132
+ _this2.reset();
133
+ }, this.debounceTime);
134
+ }
135
+ }, {
136
+ key: "report",
137
+ value: function report(callback) {
138
+ callback && callback();
139
+ }
140
+ }, {
141
+ key: "reset",
142
+ value: function reset() {
143
+ this.timeoutId = null;
144
+ }
145
+ }]);
146
+ return LogDebounceTracker;
147
+ }();
148
+ var logDebounceTracker = new LogDebounceTracker();