@alipay/ams-checkout 0.0.1747014711-dev.7 → 0.0.1747014711-dev.9

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.
@@ -7,6 +7,7 @@ export declare const getCKPPageAddress: (env: IoptionsParams['environment'] | LO
7
7
  export declare class AMSCheckoutPage {
8
8
  logger: Logger;
9
9
  private _instanceId;
10
+ private iframe;
10
11
  private originOptions;
11
12
  private readonly APP_IFRAME_ID;
12
13
  private eventListener?;
@@ -15,6 +16,7 @@ export declare class AMSCheckoutPage {
15
16
  private eventListenerWrapper;
16
17
  private addListener;
17
18
  private removeListener;
19
+ private dispatchToApp;
18
20
  /**
19
21
  * 挂载组件
20
22
  */
@@ -1,15 +1,17 @@
1
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; }
2
4
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
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); } }
4
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; }
5
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; }
6
8
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
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 { redirect } from "../../../util/redirect";
8
11
  import { v4 as uuid } from 'uuid';
9
- import { EnvironmentEnum } from "../../../types";
12
+ import { EnvironmentEnum, MessageName } from "../../../types";
10
13
  import { queryParse } from "../../../util";
11
14
  import { LogConfig, Logger } from "../../../util/logger";
12
- import { handleRedirect } from "../../../util/redirect";
13
15
  var CKP_PAYMENT_PAGE_HOST = {
14
16
  DEV: 'https://dev.page.alipay.net',
15
17
  TEST: 'https://test.page.alipay.net',
@@ -44,6 +46,7 @@ export var AMSCheckoutPage = /*#__PURE__*/function () {
44
46
  _classCallCheck(this, AMSCheckoutPage);
45
47
  _defineProperty(this, "logger", void 0);
46
48
  _defineProperty(this, "_instanceId", void 0);
49
+ _defineProperty(this, "iframe", void 0);
47
50
  _defineProperty(this, "originOptions", void 0);
48
51
  _defineProperty(this, "APP_IFRAME_ID", 'antom-checkout-page-sub-page-iframe');
49
52
  _defineProperty(this, "eventListener", void 0);
@@ -77,7 +80,6 @@ export var AMSCheckoutPage = /*#__PURE__*/function () {
77
80
  var _dataObj$context = dataObj === null || dataObj === void 0 ? void 0 : dataObj.context,
78
81
  eventCode = _dataObj$context.event,
79
82
  data = _dataObj$context.data;
80
- console.log(eventCode, 'eventCode', eventCode && (eventCode === null || eventCode === void 0 ? void 0 : eventCode.startsWith('onRedirectCode')), "🚀 ~ onRedirectCodeAMSCheckoutPage ~ dataObj:", dataObj, dataObj === null || dataObj === void 0 ? void 0 : dataObj.context);
81
83
  if (code && code.startsWith('SDK_PAYMENT')) {
82
84
  var _this$eventListener;
83
85
  console.log('[antom-web-sdk] <antom-checkout-page> eventListenerWrapper', event, message, result);
@@ -89,13 +91,17 @@ export var AMSCheckoutPage = /*#__PURE__*/function () {
89
91
  }
90
92
  if (eventCode && eventCode !== null && eventCode !== void 0 && eventCode.startsWith('onRedirect')) {
91
93
  var _this$eventListener2;
92
- console.log(eventCode, '[antom-web-sdk] <antom-checkout-page> onRedirectCode', data);
93
94
  (_this$eventListener2 = _this.eventListener) === null || _this$eventListener2 === void 0 || _this$eventListener2.call(_this, {
94
95
  code: code,
95
96
  message: message,
96
97
  result: result
97
98
  });
98
- handleRedirect(data);
99
+ redirect(data).then(function () {
100
+ var content = _objectSpread(_objectSpread({}, dataObj === null || dataObj === void 0 ? void 0 : dataObj.context), {}, {
101
+ event: 'appEventCallback'
102
+ });
103
+ _this.dispatchToApp(content);
104
+ });
99
105
  }
100
106
  });
101
107
  _defineProperty(this, "addListener", function () {
@@ -104,8 +110,17 @@ export var AMSCheckoutPage = /*#__PURE__*/function () {
104
110
  _defineProperty(this, "removeListener", function () {
105
111
  window.removeEventListener('message', _this.eventListenerWrapper);
106
112
  });
113
+ _defineProperty(this, "dispatchToApp", function (payloadContext) {
114
+ var _this$iframe;
115
+ var data = {
116
+ name: MessageName.SDK_TO_APP,
117
+ context: payloadContext
118
+ };
119
+ (_this$iframe = _this.iframe) === null || _this$iframe === void 0 || (_this$iframe = _this$iframe.contentWindow) === null || _this$iframe === void 0 || _this$iframe.postMessage(JSON.stringify(data), '*');
120
+ });
107
121
  options.environment = options.environment || EnvironmentEnum.prod;
108
122
  this._instanceId = uuid();
123
+ this.iframe = null;
109
124
  this.originOptions = options;
110
125
  this.eventListener = options.onEventCallback;
111
126
  this.logger = new Logger(LogConfig, ![EnvironmentEnum.prod, EnvironmentEnum.sandbox].includes(options === null || options === void 0 ? void 0 : options.environment));
@@ -145,7 +160,6 @@ export var AMSCheckoutPage = /*#__PURE__*/function () {
145
160
  throw new Error('PARAMS_ERROR_ALREADY_MOUNTED');
146
161
  }
147
162
  this.addListener();
148
- console.log("🚀 ~ AMSCheckoutPage======== ~ event:", event);
149
163
  var ckpPageAddress = this.generateIframeSrc(params.sessionData);
150
164
  var iframe = document.createElement('iframe');
151
165
  iframe.id = this.APP_IFRAME_ID;
@@ -159,6 +173,7 @@ export var AMSCheckoutPage = /*#__PURE__*/function () {
159
173
  if (wrapper) {
160
174
  wrapper.innerHTML = '';
161
175
  wrapper.appendChild(iframe);
176
+ this.iframe = iframe;
162
177
  } else {
163
178
  this.logger.logError({
164
179
  title: 'event_important_error',
@@ -33,8 +33,7 @@ import { ElementContainerService } from "../elementContainerService"; // 引入
33
33
  import { IContainerStatus } from "../elementContainerService/containerService";
34
34
  import { oneAccountUpdate, sdkActionUpdate } from "../mock";
35
35
  import { ElementPaymentEvent, ElementPaymentMethod, ElementType, EventCallbackCode } from "../type";
36
- import { checkCanMount, checkCanUpdate, showToast } from "../util";
37
- import { handleRedirect } from "../../../../util/redirect";
36
+ import { checkCanMount, checkCanUpdate, handleRedirect, showToast } from "../util";
38
37
  var TIMEOUT_DURATION = 10000;
39
38
  var ElementController = /*#__PURE__*/function () {
40
39
  // 新增变量
@@ -49,6 +49,13 @@ export declare function generateIframeSrc({ paymentSessionObj, paymentSession, i
49
49
  appVersion: string;
50
50
  link?: string;
51
51
  }): string;
52
+ export declare function handleRedirect(data: any, fromFastSdk?: boolean): void;
53
+ export declare function redirect(data: {
54
+ normalUrl?: string;
55
+ schemeUrl?: string;
56
+ applinkUrl?: string;
57
+ callAppJudgeTime?: number;
58
+ }): Promise<void>;
52
59
  export declare function showToast(options?: IToastOptions, callback?: Function): void;
53
60
  export declare const isElementMobile: () => boolean;
54
61
  /**
@@ -10,9 +10,12 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
10
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
11
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
12
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 { ERRORMESSAGE } from "../../../constant";
13
14
  import { IElementStatus } from "../../../foundation";
14
15
  import { getIframeUrl } from "../../../plugin/component/cashierApp";
15
- import { DisplayTypeEnum } from "../../../types";
16
+ import { DisplayTypeEnum, RedirectType, TargetEnum, terminalTypeEnum } from "../../../types";
17
+ import { device } from "../../../util/index";
18
+ import CallApp from "../../../util/intl-callapp/es/main";
16
19
  import { getComponentSign, parseSessionData } from "../index";
17
20
  import { ELEMENT_ENVIRONMENT } from "./type";
18
21
  var formatElementOption = function formatElementOption(options) {
@@ -132,6 +135,195 @@ export function generateIframeSrc(_ref3) {
132
135
  console.log('[debug] generateIframeSrc', path, locationSearch);
133
136
  return "".concat(path, "?").concat(locationSearch);
134
137
  }
138
+ export function handleRedirect(data) {
139
+ var _data$isDestroy, _data$isCallApp, _data$callAppDetectSu;
140
+ var fromFastSdk = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
141
+ console.log('local payment sdk new element redirect arg ----', this);
142
+ var _data = typeof data === 'string' ? {
143
+ normalUrl: data
144
+ } : _objectSpread(_objectSpread({}, data), {}, {
145
+ applinkUrl: (data === null || data === void 0 ? void 0 : data.applinkUrl) || '',
146
+ schemeUrl: (data === null || data === void 0 ? void 0 : data.schemeUrl) || '',
147
+ normalUrl: (data === null || data === void 0 ? void 0 : data.normalUrl) || '',
148
+ target: data === null || data === void 0 ? void 0 : data.target,
149
+ isDestroy: (_data$isDestroy = data === null || data === void 0 ? void 0 : data.isDestroy) !== null && _data$isDestroy !== void 0 ? _data$isDestroy : true,
150
+ isCallApp: (_data$isCallApp = data === null || data === void 0 ? void 0 : data.isCallApp) !== null && _data$isCallApp !== void 0 ? _data$isCallApp : false,
151
+ callAppDetectSuccessDelay: (_data$callAppDetectSu = data === null || data === void 0 ? void 0 : data.callAppDetectSuccessDelay) !== null && _data$callAppDetectSu !== void 0 ? _data$callAppDetectSu : 2000
152
+ });
153
+ // const logParams = {
154
+ // applinkUrl: data?.applinkUrl || '',
155
+ // schemeUrl: data?.schemeUrl || '',
156
+ // normalUrl: data?.normalUrl || '',
157
+ // target: data?.target,
158
+ // isDestroy: data?.isDestroy ?? true,
159
+ // isCallApp: data?.isCallApp ?? false,
160
+ // callAppDetectSuccessDelay: data?.callAppDetectSuccessDelay ?? 2000,
161
+ // };
162
+ // this.AMSSDK.logger
163
+ // .logInfo(
164
+ // {
165
+ // title: 'sdk_event_call_url_start',
166
+ // },
167
+ // {
168
+ // redirectInfo: JSON.stringify(logParams),
169
+ // },
170
+ // )
171
+ // .send();
172
+ var successCallback = function successCallback(type, url, durationInSeconds) {
173
+ // TODO
174
+ // event.dispatchToSDK(EVENT.eventCallback.name, {
175
+ // code: eventCodeEnum.SDK_CALL_URL_SUCCESS,
176
+ // message: `Successfully opened the app,${type}: ${url}`,
177
+ // });
178
+ var extra = {
179
+ redirectInfo: JSON.stringify(_data),
180
+ openType: type,
181
+ url: url,
182
+ fromFastSdk: fromFastSdk
183
+ };
184
+ if (durationInSeconds) {
185
+ extra['durationInSeconds'] = durationInSeconds;
186
+ }
187
+ // this.AMSSDK.logger
188
+ // .logInfo(
189
+ // {
190
+ // title: 'sdk_event_call_url_success',
191
+ // },
192
+ // extra,
193
+ // )
194
+ // .send();
195
+ };
196
+ var failCallback = function failCallback(type, url, durationInSeconds) {
197
+ // event.dispatchToSDK(EVENT.eventCallback.name, {
198
+ // code: eventCodeEnum.SDK_CALL_URL_ERROR,
199
+ // message: `Failed to open app,applinkUrl: ${_data?.applinkUrl} schemeUrl: ${_data?.schemeUrl} normalUrl: ${_data?.normalUrl}`,
200
+ // });
201
+ var extra = {
202
+ redirectInfo: JSON.stringify(_data),
203
+ openType: type,
204
+ url: url,
205
+ fromFastSdk: fromFastSdk
206
+ };
207
+ if (durationInSeconds) {
208
+ extra['durationInSeconds'] = durationInSeconds;
209
+ }
210
+ // this.AMSSDK.logger
211
+ // .logInfo(
212
+ // {
213
+ // title: 'sdk_error_call_url_failed',
214
+ // },
215
+ // extra,
216
+ // )
217
+ // .send();
218
+ };
219
+
220
+ // 支持 target: _blank,新开tab页打开
221
+ if (_data.target === TargetEnum.BLANK) {
222
+ if (!_data.normalUrl) return failCallback(RedirectType.NormalUrl, '');
223
+ successCallback(RedirectType.NormalUrl, _data.normalUrl);
224
+ window.open(_data.normalUrl);
225
+ return;
226
+ }
227
+ if (_data.target === TargetEnum.REPLACE && !(_data !== null && _data !== void 0 && _data.applinkUrl) && !(_data !== null && _data !== void 0 && _data.schemeUrl)) {
228
+ if (!_data.normalUrl) return failCallback(RedirectType.NormalUrl, '');
229
+ successCallback(RedirectType.NormalUrl, _data.normalUrl);
230
+ window.location.replace(_data.normalUrl);
231
+ return;
232
+ }
233
+ // TODO 销毁iframe和全局loading
234
+ // if (_data?.isDestroy) this.cleanContainer();
235
+ // 唤端
236
+ if (_data !== null && _data !== void 0 && _data.isCallApp && _data !== null && _data !== void 0 && _data.schemeUrl) {
237
+ var startCallAppTime = new Date();
238
+ var detectSuccessDelay = typeof (data === null || data === void 0 ? void 0 : data.callAppDetectSuccessDelay) === 'number' ? data.callAppDetectSuccessDelay : 5000;
239
+ redirect({
240
+ schemeUrl: _data === null || _data === void 0 ? void 0 : _data.schemeUrl,
241
+ callAppJudgeTime: detectSuccessDelay
242
+ }).then(function () {
243
+ var endCallAppTime = new Date();
244
+ var durationInMilliseconds = endCallAppTime.getTime() - startCallAppTime.getTime();
245
+ var durationInSeconds = durationInMilliseconds / 1000;
246
+ successCallback(RedirectType.SchemeUrl, _data === null || _data === void 0 ? void 0 : _data.schemeUrl, durationInSeconds);
247
+ }).catch(function () {
248
+ var endCallAppTime = new Date();
249
+ var durationInMilliseconds = endCallAppTime.getTime() - startCallAppTime.getTime();
250
+ var durationInSeconds = durationInMilliseconds / 1000;
251
+ failCallback(RedirectType.SchemeUrl, _data.schemeUrl, durationInSeconds);
252
+ });
253
+ return;
254
+ }
255
+ redirect({
256
+ applinkUrl: _data === null || _data === void 0 ? void 0 : _data.applinkUrl
257
+ }).then(function () {
258
+ successCallback(RedirectType.ApplinkUrl, _data === null || _data === void 0 ? void 0 : _data.applinkUrl);
259
+ }).catch(function () {
260
+ if (_data !== null && _data !== void 0 && _data.applinkUrl) failCallback(RedirectType.ApplinkUrl, _data === null || _data === void 0 ? void 0 : _data.applinkUrl);
261
+ return redirect({
262
+ schemeUrl: _data === null || _data === void 0 ? void 0 : _data.schemeUrl
263
+ });
264
+ }).then(function () {
265
+ successCallback(RedirectType.SchemeUrl, _data === null || _data === void 0 ? void 0 : _data.schemeUrl);
266
+ }).catch(function () {
267
+ if (_data !== null && _data !== void 0 && _data.schemeUrl) failCallback(RedirectType.SchemeUrl, _data === null || _data === void 0 ? void 0 : _data.schemeUrl);
268
+ return redirect({
269
+ normalUrl: _data === null || _data === void 0 ? void 0 : _data.normalUrl
270
+ });
271
+ }).then(function () {
272
+ successCallback(RedirectType.NormalUrl, _data === null || _data === void 0 ? void 0 : _data.normalUrl);
273
+ }).catch(function () {
274
+ failCallback(RedirectType.NormalUrl, _data === null || _data === void 0 ? void 0 : _data.normalUrl);
275
+ });
276
+ }
277
+ export function redirect(data) {
278
+ return new Promise(function (resolve, reject) {
279
+ var terminalType = device.isMobile ? terminalTypeEnum.WAP : terminalTypeEnum.WEB;
280
+ var isWeb = terminalType === terminalTypeEnum.WEB;
281
+ var normalUrl = (data === null || data === void 0 ? void 0 : data.normalUrl) || '';
282
+ var schemeUrl = (data === null || data === void 0 ? void 0 : data.schemeUrl) || '';
283
+ var applinkUrl = (data === null || data === void 0 ? void 0 : data.applinkUrl) || '';
284
+ var callAppJudgeTime = (data === null || data === void 0 ? void 0 : data.callAppJudgeTime) || '';
285
+ var jumpFunc = function jumpFunc() {
286
+ if (normalUrl) {
287
+ resolve();
288
+ window.location.href = normalUrl;
289
+ return;
290
+ }
291
+ reject(ERRORMESSAGE.SDK_CALL_URL_ERROR.REDIRECT_ERROR);
292
+ };
293
+ var callAppFunc = function callAppFunc() {
294
+ if (!schemeUrl && !applinkUrl) {
295
+ jumpFunc();
296
+ return;
297
+ }
298
+ var config = {
299
+ fallback: function fallback() {
300
+ jumpFunc();
301
+ },
302
+ successCb: function successCb() {
303
+ resolve();
304
+ },
305
+ delay: 0
306
+ };
307
+ if (callAppJudgeTime) {
308
+ config['resultJudgmentTime'] = callAppJudgeTime;
309
+ }
310
+ try {
311
+ var callLib = new CallApp(config);
312
+ callLib.open({
313
+ scheme: schemeUrl,
314
+ link: applinkUrl
315
+ });
316
+ } catch (error) {
317
+ jumpFunc();
318
+ }
319
+ };
320
+ if (isWeb) {
321
+ jumpFunc();
322
+ } else {
323
+ callAppFunc();
324
+ }
325
+ });
326
+ }
135
327
  export function showToast() {
136
328
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
137
329
  var callback = arguments.length > 1 ? arguments[1] : undefined;
@@ -1,4 +1,3 @@
1
- export declare function handleRedirect(data: any, fromFastSdk?: boolean): void;
2
1
  export declare function redirect(data: {
3
2
  normalUrl?: string;
4
3
  schemeUrl?: string;
@@ -1,152 +1,7 @@
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 _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; }
5
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
- 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); }
7
1
  import { ERRORMESSAGE } from "../constant";
8
2
  import CallApp from "./intl-callapp/es/main";
9
- import { RedirectType, TargetEnum, terminalTypeEnum } from "../types";
3
+ import { terminalTypeEnum } from "../types";
10
4
  import { device } from ".";
11
- export function handleRedirect(data) {
12
- var _data$isDestroy, _data$isCallApp, _data$callAppDetectSu;
13
- var fromFastSdk = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
14
- console.log('local payment sdk new element redirect arg ----', this);
15
- var _data = typeof data === 'string' ? {
16
- normalUrl: data
17
- } : _objectSpread(_objectSpread({}, data), {}, {
18
- applinkUrl: (data === null || data === void 0 ? void 0 : data.applinkUrl) || '',
19
- schemeUrl: (data === null || data === void 0 ? void 0 : data.schemeUrl) || '',
20
- normalUrl: (data === null || data === void 0 ? void 0 : data.normalUrl) || '',
21
- target: data === null || data === void 0 ? void 0 : data.target,
22
- isDestroy: (_data$isDestroy = data === null || data === void 0 ? void 0 : data.isDestroy) !== null && _data$isDestroy !== void 0 ? _data$isDestroy : true,
23
- isCallApp: (_data$isCallApp = data === null || data === void 0 ? void 0 : data.isCallApp) !== null && _data$isCallApp !== void 0 ? _data$isCallApp : false,
24
- callAppDetectSuccessDelay: (_data$callAppDetectSu = data === null || data === void 0 ? void 0 : data.callAppDetectSuccessDelay) !== null && _data$callAppDetectSu !== void 0 ? _data$callAppDetectSu : 2000
25
- });
26
- // const logParams = {
27
- // applinkUrl: data?.applinkUrl || '',
28
- // schemeUrl: data?.schemeUrl || '',
29
- // normalUrl: data?.normalUrl || '',
30
- // target: data?.target,
31
- // isDestroy: data?.isDestroy ?? true,
32
- // isCallApp: data?.isCallApp ?? false,
33
- // callAppDetectSuccessDelay: data?.callAppDetectSuccessDelay ?? 2000,
34
- // };
35
- // this.AMSSDK.logger
36
- // .logInfo(
37
- // {
38
- // title: 'sdk_event_call_url_start',
39
- // },
40
- // {
41
- // redirectInfo: JSON.stringify(logParams),
42
- // },
43
- // )
44
- // .send();
45
- var successCallback = function successCallback(type, url, durationInSeconds) {
46
- // TODO
47
- // event.dispatchToSDK(EVENT.eventCallback.name, {
48
- // code: eventCodeEnum.SDK_CALL_URL_SUCCESS,
49
- // message: `Successfully opened the app,${type}: ${url}`,
50
- // });
51
- var extra = {
52
- redirectInfo: JSON.stringify(_data),
53
- openType: type,
54
- url: url,
55
- fromFastSdk: fromFastSdk
56
- };
57
- if (durationInSeconds) {
58
- extra['durationInSeconds'] = durationInSeconds;
59
- }
60
- // this.AMSSDK.logger
61
- // .logInfo(
62
- // {
63
- // title: 'sdk_event_call_url_success',
64
- // },
65
- // extra,
66
- // )
67
- // .send();
68
- };
69
- var failCallback = function failCallback(type, url, durationInSeconds) {
70
- // event.dispatchToSDK(EVENT.eventCallback.name, {
71
- // code: eventCodeEnum.SDK_CALL_URL_ERROR,
72
- // message: `Failed to open app,applinkUrl: ${_data?.applinkUrl} schemeUrl: ${_data?.schemeUrl} normalUrl: ${_data?.normalUrl}`,
73
- // });
74
- var extra = {
75
- redirectInfo: JSON.stringify(_data),
76
- openType: type,
77
- url: url,
78
- fromFastSdk: fromFastSdk
79
- };
80
- if (durationInSeconds) {
81
- extra['durationInSeconds'] = durationInSeconds;
82
- }
83
- // this.AMSSDK.logger
84
- // .logInfo(
85
- // {
86
- // title: 'sdk_error_call_url_failed',
87
- // },
88
- // extra,
89
- // )
90
- // .send();
91
- };
92
-
93
- // 支持 target: _blank,新开tab页打开
94
- if (_data.target === TargetEnum.BLANK) {
95
- if (!_data.normalUrl) return failCallback(RedirectType.NormalUrl, '');
96
- successCallback(RedirectType.NormalUrl, _data.normalUrl);
97
- window.open(_data.normalUrl);
98
- return;
99
- }
100
- if (_data.target === TargetEnum.REPLACE && !(_data !== null && _data !== void 0 && _data.applinkUrl) && !(_data !== null && _data !== void 0 && _data.schemeUrl)) {
101
- if (!_data.normalUrl) return failCallback(RedirectType.NormalUrl, '');
102
- successCallback(RedirectType.NormalUrl, _data.normalUrl);
103
- window.location.replace(_data.normalUrl);
104
- return;
105
- }
106
- // TODO 销毁iframe和全局loading
107
- // if (_data?.isDestroy) this.cleanContainer();
108
- // 唤端
109
- if (_data !== null && _data !== void 0 && _data.isCallApp && _data !== null && _data !== void 0 && _data.schemeUrl) {
110
- var startCallAppTime = new Date();
111
- var detectSuccessDelay = typeof (data === null || data === void 0 ? void 0 : data.callAppDetectSuccessDelay) === 'number' ? data.callAppDetectSuccessDelay : 5000;
112
- redirect({
113
- schemeUrl: _data === null || _data === void 0 ? void 0 : _data.schemeUrl,
114
- callAppJudgeTime: detectSuccessDelay
115
- }).then(function () {
116
- var endCallAppTime = new Date();
117
- var durationInMilliseconds = endCallAppTime.getTime() - startCallAppTime.getTime();
118
- var durationInSeconds = durationInMilliseconds / 1000;
119
- successCallback(RedirectType.SchemeUrl, _data === null || _data === void 0 ? void 0 : _data.schemeUrl, durationInSeconds);
120
- }).catch(function () {
121
- var endCallAppTime = new Date();
122
- var durationInMilliseconds = endCallAppTime.getTime() - startCallAppTime.getTime();
123
- var durationInSeconds = durationInMilliseconds / 1000;
124
- failCallback(RedirectType.SchemeUrl, _data.schemeUrl, durationInSeconds);
125
- });
126
- return;
127
- }
128
- redirect({
129
- applinkUrl: _data === null || _data === void 0 ? void 0 : _data.applinkUrl
130
- }).then(function () {
131
- successCallback(RedirectType.ApplinkUrl, _data === null || _data === void 0 ? void 0 : _data.applinkUrl);
132
- }).catch(function () {
133
- if (_data !== null && _data !== void 0 && _data.applinkUrl) failCallback(RedirectType.ApplinkUrl, _data === null || _data === void 0 ? void 0 : _data.applinkUrl);
134
- return redirect({
135
- schemeUrl: _data === null || _data === void 0 ? void 0 : _data.schemeUrl
136
- });
137
- }).then(function () {
138
- successCallback(RedirectType.SchemeUrl, _data === null || _data === void 0 ? void 0 : _data.schemeUrl);
139
- }).catch(function () {
140
- if (_data !== null && _data !== void 0 && _data.schemeUrl) failCallback(RedirectType.SchemeUrl, _data === null || _data === void 0 ? void 0 : _data.schemeUrl);
141
- return redirect({
142
- normalUrl: _data === null || _data === void 0 ? void 0 : _data.normalUrl
143
- });
144
- }).then(function () {
145
- successCallback(RedirectType.NormalUrl, _data === null || _data === void 0 ? void 0 : _data.normalUrl);
146
- }).catch(function () {
147
- failCallback(RedirectType.NormalUrl, _data === null || _data === void 0 ? void 0 : _data.normalUrl);
148
- });
149
- }
150
5
  export function redirect(data) {
151
6
  return new Promise(function (resolve, reject) {
152
7
  var terminalType = device.isMobile ? terminalTypeEnum.WAP : terminalTypeEnum.WEB;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alipay/ams-checkout",
3
- "version": "0.0.1747014711-dev.7",
3
+ "version": "0.0.1747014711-dev.9",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "main": "esm/index.js",