@alipay/ams-checkout 1.23.0 → 1.24.0

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 (124) hide show
  1. package/dist/umd/ams-checkout.min.js +1 -1
  2. package/esm/config/index.d.ts +7 -7
  3. package/esm/config/index.js +10 -10
  4. package/esm/constant/index.d.ts +6 -0
  5. package/esm/constant/index.js +8 -0
  6. package/esm/core/bus/ability/globalData.d.ts +10 -0
  7. package/esm/core/bus/ability/globalData.js +89 -0
  8. package/esm/core/bus/ability/request.d.ts +10 -0
  9. package/esm/core/bus/ability/request.js +151 -0
  10. package/esm/core/bus/interface.d.ts +12 -0
  11. package/esm/core/bus/interface.js +16 -2
  12. package/esm/core/component/address.d.ts +2 -2
  13. package/esm/core/component/appPreloadProcessing.js +2 -0
  14. package/esm/core/component/ckp/index.d.ts +3 -3
  15. package/esm/core/component/ckp/index.js +6 -5
  16. package/esm/core/component/element/components/address.d.ts +19 -0
  17. package/esm/core/component/element/components/address.js +68 -0
  18. package/esm/core/component/element/components/auth.d.ts +17 -0
  19. package/esm/core/component/element/components/auth.js +60 -0
  20. package/esm/core/component/element/components/payment.d.ts +19 -0
  21. package/esm/core/component/element/components/payment.js +74 -0
  22. package/esm/core/component/element/index.d.ts +47 -0
  23. package/esm/core/component/element/index.js +816 -0
  24. package/esm/core/component/element/mock.d.ts +4 -0
  25. package/esm/core/component/element/mock.js +491 -0
  26. package/esm/core/component/element/type.d.ts +184 -0
  27. package/esm/core/component/element/type.js +35 -0
  28. package/esm/core/component/element/utils.d.ts +13 -0
  29. package/esm/core/component/element/utils.js +6 -0
  30. package/esm/core/component/index.d.ts +5 -5
  31. package/esm/core/component/index.js +20 -16
  32. package/esm/core/drop-in/index.d.ts +2 -2
  33. package/esm/core/drop-in/index.js +2 -2
  34. package/esm/core/instance/index.d.ts +5 -5
  35. package/esm/core/instance/index.js +11 -10
  36. package/esm/foundation/core/index.d.ts +26 -0
  37. package/esm/foundation/core/index.js +301 -0
  38. package/esm/foundation/index.d.ts +72 -0
  39. package/esm/foundation/index.js +42 -0
  40. package/esm/foundation/product-processor/easysafepay/deps.d.ts +15 -0
  41. package/esm/foundation/product-processor/easysafepay/deps.js +9 -0
  42. package/esm/foundation/product-processor/easysafepay/index.d.ts +26 -0
  43. package/esm/foundation/product-processor/easysafepay/index.js +536 -0
  44. package/esm/foundation/service/container/index.d.ts +28 -0
  45. package/esm/foundation/service/container/index.js +256 -0
  46. package/esm/foundation/service/container/popup.d.ts +17 -0
  47. package/esm/foundation/service/container/popup.js +103 -0
  48. package/esm/foundation/service/container/utils.d.ts +7 -0
  49. package/esm/foundation/service/container/utils.js +48 -0
  50. package/esm/foundation/service/event-bus/ability/callback.d.ts +9 -0
  51. package/esm/foundation/service/event-bus/ability/callback.js +55 -0
  52. package/esm/foundation/service/event-bus/ability/globalData.d.ts +10 -0
  53. package/esm/foundation/service/event-bus/ability/globalData.js +89 -0
  54. package/esm/foundation/service/event-bus/ability/request.d.ts +10 -0
  55. package/esm/foundation/service/event-bus/ability/request.js +151 -0
  56. package/esm/foundation/service/event-bus/ability/security.d.ts +12 -0
  57. package/esm/foundation/service/event-bus/ability/security.js +151 -0
  58. package/esm/foundation/service/event-bus/ability/tracker.d.ts +9 -0
  59. package/esm/foundation/service/event-bus/ability/tracker.js +80 -0
  60. package/esm/foundation/service/event-bus/busManager.d.ts +127 -0
  61. package/esm/foundation/service/event-bus/busManager.js +398 -0
  62. package/esm/foundation/service/event-bus/index.d.ts +20 -0
  63. package/esm/foundation/service/event-bus/index.js +88 -0
  64. package/esm/foundation/service/event-center.d.ts +75 -0
  65. package/esm/foundation/service/event-center.js +244 -0
  66. package/esm/foundation/service/global-data/index.d.ts +11 -0
  67. package/esm/foundation/service/global-data/index.js +69 -0
  68. package/esm/foundation/service/index.d.ts +19 -0
  69. package/esm/foundation/service/index.js +82 -0
  70. package/esm/foundation/service/log/index.d.ts +43 -0
  71. package/esm/foundation/service/log/index.js +235 -0
  72. package/esm/foundation/service/log/types.d.ts +32 -0
  73. package/esm/foundation/service/log/types.js +1 -0
  74. package/esm/foundation/service/requester/deps.d.ts +17 -0
  75. package/esm/foundation/service/requester/deps.js +11 -0
  76. package/esm/foundation/service/requester/requester.d.ts +22 -0
  77. package/esm/foundation/service/requester/requester.js +211 -0
  78. package/esm/foundation/service/security/index.d.ts +26 -0
  79. package/esm/foundation/service/security/index.js +216 -0
  80. package/esm/{util → foundation/service/security}/security.d.ts +2 -2
  81. package/esm/{util → foundation/service/security}/security.js +3 -3
  82. package/esm/foundation/types/index.d.ts +4 -0
  83. package/esm/foundation/types/index.js +4 -0
  84. package/esm/foundation/utils/gray_scale_utils.d.ts +7 -0
  85. package/esm/foundation/utils/gray_scale_utils.js +40 -0
  86. package/esm/foundation/utils/payment_context_utils.d.ts +13 -0
  87. package/esm/foundation/utils/payment_context_utils.js +57 -0
  88. package/esm/foundation/utils/redirect_utils.d.ts +6 -0
  89. package/esm/foundation/utils/redirect_utils.js +99 -0
  90. package/esm/foundation/utils/system_events.d.ts +4 -0
  91. package/esm/foundation/utils/system_events.js +71 -0
  92. package/esm/foundation/utils/web_app_url_utils.d.ts +37 -0
  93. package/esm/foundation/utils/web_app_url_utils.js +97 -0
  94. package/esm/index.d.ts +16 -10
  95. package/esm/index.js +70 -59
  96. package/esm/plugin/applepay/component.js +3 -3
  97. package/esm/plugin/applepay/service.d.ts +2 -2
  98. package/esm/plugin/applepay/service.js +2 -2
  99. package/esm/plugin/component/cashierApp.d.ts +7 -5
  100. package/esm/plugin/component/cashierApp.js +16 -8
  101. package/esm/plugin/component/channel.d.ts +4 -4
  102. package/esm/plugin/component/component.inline.style.d.ts +4 -4
  103. package/esm/plugin/component/component.inline.style.js +10 -7
  104. package/esm/plugin/component/component.popup.style.d.ts +15 -6
  105. package/esm/plugin/component/component.popup.style.js +33 -15
  106. package/esm/plugin/component/index.d.ts +8 -7
  107. package/esm/plugin/component/index.js +153 -98
  108. package/esm/plugin/const.js +5 -5
  109. package/esm/plugin/drop-in/index.d.ts +5 -5
  110. package/esm/plugin/drop-in/index.js +7 -7
  111. package/esm/plugin/payment-element/utils.d.ts +1 -1
  112. package/esm/plugin/payment-element/utils.js +2 -1
  113. package/esm/plugin/type.d.ts +4 -4
  114. package/esm/service/element.d.ts +4 -0
  115. package/esm/service/element.js +51 -0
  116. package/esm/service/index.d.ts +1 -0
  117. package/esm/service/index.js +2 -0
  118. package/esm/types/index.d.ts +240 -38
  119. package/esm/types/index.js +103 -59
  120. package/esm/util/createIframeNode.d.ts +2 -2
  121. package/esm/util/createIframeNode.js +3 -3
  122. package/esm/util/index.d.ts +1 -1
  123. package/esm/util/index.js +3 -4
  124. package/package.json +2 -1
@@ -0,0 +1,244 @@
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 { v4 as uuid } from 'uuid';
11
+ import { ERRORMESSAGE } from "../../constant";
12
+ import { MessageName } from "../../types";
13
+ import { isJsonString } from "../../util";
14
+ import { getIframeOrigin, registerSystemEvents, unRegisterSystemEvents } from "../utils/system_events";
15
+
16
+ /**
17
+ * @author 江跃 <jiangbin.gjb@antgroup.com>
18
+ * @date 2024/9/17
19
+ */
20
+ export var EventCenter = /*#__PURE__*/function () {
21
+ function EventCenter() {
22
+ _classCallCheck(this, EventCenter);
23
+ _defineProperty(this, "events", void 0);
24
+ _defineProperty(this, "iframes", void 0);
25
+ this.events = new Map();
26
+ this.iframes = [];
27
+ }
28
+
29
+ /**
30
+ * Initializes the event center
31
+ */
32
+ _createClass(EventCenter, [{
33
+ key: "init",
34
+ value: function init() {
35
+ this.handleAppMessage = this.handleAppMessage.bind(this);
36
+ window.addEventListener('message', this.handleAppMessage);
37
+ registerSystemEvents(this);
38
+ }
39
+
40
+ /**
41
+ * Cleans up event listeners when the event center is destroyed.
42
+ */
43
+ }, {
44
+ key: "destroy",
45
+ value: function destroy() {
46
+ window.removeEventListener('message', this.handleAppMessage);
47
+ this.iframes = [];
48
+ unRegisterSystemEvents(this);
49
+ }
50
+
51
+ /**
52
+ * Placeholder for future update logic.
53
+ */
54
+ }, {
55
+ key: "update",
56
+ value: function update() {
57
+ // TODO:
58
+ }
59
+
60
+ /**
61
+ * Sets the iframe container and its domain.
62
+ * @param iframe - The HTMLIFrameElement that serves as the container.
63
+ * @param domain - The domain of the app.
64
+ */
65
+ }, {
66
+ key: "addIFrame",
67
+ value: function addIFrame(iframe) {
68
+ this.iframes.push({
69
+ ref: iframe,
70
+ origin: getIframeOrigin(iframe)
71
+ });
72
+ }
73
+ }, {
74
+ key: "removeIFrame",
75
+ value: function removeIFrame(iframe) {
76
+ var index = this.iframes.findIndex(function (item) {
77
+ return item.origin === getIframeOrigin(iframe);
78
+ });
79
+ if (index !== -1) {
80
+ this.iframes.splice(index, 1);
81
+ }
82
+ }
83
+
84
+ /**
85
+ * Handles messages received from the app.
86
+ * @param e - The message event.
87
+ */
88
+ }, {
89
+ key: "handleAppMessage",
90
+ value: function handleAppMessage(e) {
91
+ var _e$data;
92
+ // console.log('sdk received message:', e);
93
+ if (!this.iframes.some(function (iframe) {
94
+ return iframe.origin === e.origin;
95
+ })) return;
96
+ if (((_e$data = e.data) === null || _e$data === void 0 ? void 0 : _e$data.source) === 'react-devtools-content-script') {
97
+ return; // Ignore messages from React DevTools
98
+ }
99
+ var isJson = isJsonString(e.data);
100
+ if (isJson) {
101
+ var _eventPayload = JSON.parse(e.data);
102
+ console.log('handleAppMessage', _eventPayload);
103
+ if (_eventPayload.name !== MessageName.APP_TO_SDK) {
104
+ return;
105
+ }
106
+ this._handleAppMessage(_eventPayload);
107
+ } else {
108
+ console.warn(ERRORMESSAGE.NOT_JSON_FORMAT);
109
+ // TODO: 异常上报
110
+ }
111
+ }
112
+
113
+ /**
114
+ * Processes the application message and emits the associated event.
115
+ * @param data - Parsed EventPayload from the app.
116
+ */
117
+ }, {
118
+ key: "_handleAppMessage",
119
+ value: function _handleAppMessage(eventPayload) {
120
+ var context = eventPayload.context;
121
+ var event = context.event,
122
+ data = context.data;
123
+ this.emit(event, data, eventPayload);
124
+ }
125
+
126
+ /**
127
+ * Listens to an event by adding a callback function.
128
+ * @param name - The name of the event to listen for.
129
+ * @param func - The callback function to execute when the event is emitted.
130
+ */
131
+ }, {
132
+ key: "listen",
133
+ value: function listen(name, func) {
134
+ var eventList = this.events.get(name) || [];
135
+ eventList.push({
136
+ func: func
137
+ });
138
+ this.events.set(name, eventList);
139
+ }
140
+
141
+ /**
142
+ * Unsubscribes from an event. If a function is provided, only that function is removed.
143
+ * @param name - The name of the event to unlisten to.
144
+ * @param func - The optional callback function to remove.
145
+ */
146
+ }, {
147
+ key: "unlisten",
148
+ value: function unlisten(name, func) {
149
+ if (func) {
150
+ if (this.events.has(name)) {
151
+ var eventList = this.events.get(name);
152
+ eventList = eventList.filter(function (item) {
153
+ return item.func !== func;
154
+ });
155
+ this.events.set(name, eventList);
156
+ }
157
+ } else {
158
+ this.events.delete(name);
159
+ }
160
+ }
161
+
162
+ /**
163
+ * Emits an event, executing all associated callback functions.
164
+ * @param name - The name of the event to emit.
165
+ * @param data - The event data to pass to the event listeners.
166
+ */
167
+ }, {
168
+ key: "emit",
169
+ value: function emit(name, data, eventPayload) {
170
+ if (this.events.has(name)) {
171
+ var eventList = this.events.get(name);
172
+ eventList.forEach(function (item) {
173
+ item.func(data, eventPayload);
174
+ });
175
+ }
176
+ }
177
+
178
+ /**
179
+ * Registers a callback for an event and immediately dispatches the event to the app.
180
+ * @param payloadContext - The context containing event information and callback ID.
181
+ * @param func - The callback function to execute when the event is emitted.
182
+ */
183
+ }, {
184
+ key: "emitAndListen",
185
+ value: function emitAndListen(payloadContext, func) {
186
+ if (!payloadContext.eventCallbackId) {
187
+ payloadContext.eventCallbackId = uuid();
188
+ }
189
+ this.listen(payloadContext.eventCallbackId, func);
190
+ this.dispatchToApp(payloadContext);
191
+ }
192
+ }, {
193
+ key: "queryParse",
194
+ value: function queryParse(url) {
195
+ var qs = {};
196
+ var urlString = url;
197
+ if (!urlString) {
198
+ urlString = window.location.href;
199
+ }
200
+ urlString.replace(/([^?=&#]+)(=([^&#]*))?/g, function (_$0, $1, _$2, $3) {
201
+ if ($3 === undefined) {
202
+ return '';
203
+ }
204
+ qs[$1] = decodeURIComponent($3);
205
+ return qs[$1];
206
+ });
207
+ return qs;
208
+ }
209
+
210
+ /**
211
+ * Dispatches the event payload to the app via postMessage.
212
+ * @param payloadContext - The context containing event to be dispatched.
213
+ */
214
+ }, {
215
+ key: "dispatchToApp",
216
+ value: function dispatchToApp(payloadContext) {
217
+ var _this$iframes,
218
+ _this = this;
219
+ var data = {
220
+ name: MessageName.SDK_TO_APP,
221
+ context: payloadContext
222
+ };
223
+ console.log('dispatchToApp');
224
+ (_this$iframes = this.iframes) === null || _this$iframes === void 0 || _this$iframes.forEach(function (iframe) {
225
+ var _iframe$origin;
226
+ if (!iframe.ref.contentWindow) {
227
+ console.warn('get app contentWindow error', iframe);
228
+ return;
229
+ }
230
+ var _ref = _this.queryParse(iframe.ref.src) || {},
231
+ instanceId = _ref.instanceId;
232
+ iframe.ref.contentWindow.postMessage(JSON.stringify(_objectSpread(_objectSpread({}, data), {}, {
233
+ instanceId: instanceId
234
+ })), (_iframe$origin = iframe.origin) !== null && _iframe$origin !== void 0 ? _iframe$origin : '*');
235
+ });
236
+ }
237
+ }, {
238
+ key: "isExist",
239
+ value: function isExist(name) {
240
+ return this.events.has(name);
241
+ }
242
+ }]);
243
+ return EventCenter;
244
+ }();
@@ -0,0 +1,11 @@
1
+ import { IOptionsParams } from "../../../types";
2
+ import { Service } from "../../index";
3
+ export declare class GlobalDataService implements Service {
4
+ private globalData;
5
+ init(initOptions: IOptionsParams, instanceId: string): void;
6
+ destroy(): void;
7
+ update(): void;
8
+ getGlobalData(dataKey: string): any;
9
+ setGlobalData(dataKey: string, data: any): void;
10
+ clearGlobalData(): void;
11
+ }
@@ -0,0 +1,69 @@
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 { ServiceProvider } from "../index";
9
+ import { EVENT } from "../../../constant";
10
+ export var GlobalDataService = /*#__PURE__*/function () {
11
+ function GlobalDataService() {
12
+ _classCallCheck(this, GlobalDataService);
13
+ _defineProperty(this, "globalData", new Map());
14
+ }
15
+ _createClass(GlobalDataService, [{
16
+ key: "init",
17
+ value: function init(initOptions, instanceId) {
18
+ var _this = this;
19
+ // add capability to EventCenter
20
+ var eventCenter = ServiceProvider.getInstance(instanceId).getService('EventCenter');
21
+ eventCenter.listen(EVENT.getGlobalData.name, function (payload) {
22
+ var _payload$context, _payload$context2, _payload$context3, _payload$context4;
23
+ if (!((_payload$context = payload.context) !== null && _payload$context !== void 0 && _payload$context.eventCallbackId) || !((_payload$context2 = payload.context) !== null && _payload$context2 !== void 0 && (_payload$context2 = _payload$context2.data) !== null && _payload$context2 !== void 0 && _payload$context2.dataKey)) {
24
+ return;
25
+ }
26
+ var targetData = _this.globalData.get((_payload$context3 = payload.context) === null || _payload$context3 === void 0 || (_payload$context3 = _payload$context3.data) === null || _payload$context3 === void 0 ? void 0 : _payload$context3.dataKey);
27
+ eventCenter.dispatchToApp({
28
+ event: 'appEventCallback',
29
+ eventCallbackId: (_payload$context4 = payload.context) === null || _payload$context4 === void 0 ? void 0 : _payload$context4.eventCallbackId,
30
+ data: targetData
31
+ });
32
+ });
33
+ eventCenter.listen(EVENT.setGlobalData.name, function (payload) {
34
+ var _payload$context5, _payload$context6, _payload$context$data, _payload$context$data2;
35
+ if (!((_payload$context5 = payload.context) !== null && _payload$context5 !== void 0 && (_payload$context5 = _payload$context5.data) !== null && _payload$context5 !== void 0 && _payload$context5.dataKey) || !((_payload$context6 = payload.context) !== null && _payload$context6 !== void 0 && (_payload$context6 = _payload$context6.data) !== null && _payload$context6 !== void 0 && _payload$context6.data)) {
36
+ return;
37
+ }
38
+ _this.globalData.set((_payload$context$data = payload.context.data) === null || _payload$context$data === void 0 ? void 0 : _payload$context$data.dataKey, (_payload$context$data2 = payload.context.data) === null || _payload$context$data2 === void 0 ? void 0 : _payload$context$data2.data);
39
+ });
40
+
41
+ // register
42
+ }
43
+ }, {
44
+ key: "destroy",
45
+ value: function destroy() {
46
+ this.globalData.clear();
47
+ }
48
+ }, {
49
+ key: "update",
50
+ value: function update() {}
51
+ }, {
52
+ key: "getGlobalData",
53
+ value: function getGlobalData(dataKey) {
54
+ var targetData = this.globalData.get(dataKey);
55
+ return targetData;
56
+ }
57
+ }, {
58
+ key: "setGlobalData",
59
+ value: function setGlobalData(dataKey, data) {
60
+ this.globalData.set(dataKey, data);
61
+ }
62
+ }, {
63
+ key: "clearGlobalData",
64
+ value: function clearGlobalData() {
65
+ this.globalData = new Map();
66
+ }
67
+ }]);
68
+ return GlobalDataService;
69
+ }();
@@ -0,0 +1,19 @@
1
+ import { IOptionsParams } from '../../types';
2
+ import { PaymentContext, SDKMetaData, Service } from '../index';
3
+ /**
4
+ * @author 谦彧 <zhangmian.zm@alipay.com>
5
+ * @date 2024/9/17
6
+ */
7
+ export type ServiceName = 'Container' | 'EventCenter' | 'Log' | 'ApiBusManager' | 'Requester' | 'Security' | 'GlobalData';
8
+ export declare class ServiceProvider {
9
+ private static ProvidersMapping;
10
+ static getInstance(instanceId: string): ServiceProvider;
11
+ private readonly instanceId;
12
+ private services;
13
+ private extendServices;
14
+ private constructor();
15
+ init(initOptions: IOptionsParams, sdkMetaData: SDKMetaData): void;
16
+ update(paymentContext: PaymentContext): void;
17
+ getService<T>(serviceName: ServiceName): T;
18
+ registerService(serviceName: string, service: Service): void;
19
+ }
@@ -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 "./event-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): LogService;
34
+ logInfo(info: LogPayload, extra?: LogExtra): LogService;
35
+ log(type: string, payload: any, extra?: LogExtra): LogService;
36
+ private reportLogs;
37
+ private loadScript;
38
+ private initTracker;
39
+ send(): void;
40
+ setComponentStartTime(val: number): void;
41
+ getComponentStartTime(): number;
42
+ }
43
+ export {};