@alipay/ams-checkout 0.0.1698890614-dev.1 → 0.0.1699863258-dev.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.
@@ -15,12 +15,13 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
15
15
  * 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
16
16
  */
17
17
  /* eslint-disable @typescript-eslint/no-explicit-any */
18
+ import axios from 'axios';
18
19
  import { sdkVersion } from "../config/index";
19
20
  import { appId, hostSignMap, lightSandboxMap, requestHost, sofaId, tntInstId } from "../config/request";
20
21
  import { errorEnum } from "../types";
22
+ import { device, isPC, queryParse, safeJson } from "../util";
21
23
  import { get } from "../util/get";
22
- import axios from 'axios';
23
- import { device, fomatGetwayError, isPC, queryParse, safeJson } from "../util";
24
+ import { fomatGetwayError } from "./utils";
24
25
  var _queryParse = queryParse(),
25
26
  _sandbox = _queryParse._sandbox;
26
27
  function requestInstance(options) {
@@ -47,7 +48,7 @@ function requestInstance(options) {
47
48
  timeout: (_options$timeout = options.timeout) !== null && _options$timeout !== void 0 ? _options$timeout : 15000,
48
49
  headers: _headers,
49
50
  withCredentials: (_options$withCredenti = options.withCredentials) !== null && _options$withCredenti !== void 0 ? _options$withCredenti : true,
50
- method: 'POST'
51
+ method: (options === null || options === void 0 ? void 0 : options.method) || 'POST'
51
52
  });
52
53
  return instance.request;
53
54
  }
@@ -88,12 +89,12 @@ function _request() {
88
89
  // eslint-disable-next-line no-empty
89
90
  } catch (error) {}
90
91
  if (envInfo.terminalType === 'WAP') envInfo.osType = device.iOS ? 'IOS' : 'ANDROID';
91
- _data = options.needEnvInfo ? [_objectSpread(_objectSpread({}, requestData), {}, {
92
+ _data = [_objectSpread(_objectSpread({}, requestData), {}, {
92
93
  envInfo: envInfo,
93
94
  extParams: {
94
95
  refUrl: window.location.href
95
96
  }
96
- })] : [requestData];
97
+ })];
97
98
  startTime = Date.now();
98
99
  _context.prev = 5;
99
100
  myRequest = requestInstance(options);
@@ -123,8 +124,6 @@ function _request() {
123
124
  code: errorCode,
124
125
  msg: errorMessage,
125
126
  traceId: traceId
126
- }, {
127
- // TODO Concerned input data
128
127
  }).send();
129
128
  throw new Error(JSON.stringify({
130
129
  errorMessage: errorMessage,
@@ -158,9 +157,7 @@ function _request() {
158
157
  time: Date.now() - startTime,
159
158
  success: false,
160
159
  code: _errorCode,
161
- msg: _error === null || _error === void 0 ? void 0 : _error.message
162
- }, {
163
- // TODO Concerned input data
160
+ msg: JSON.stringify((_error === null || _error === void 0 ? void 0 : _error.message) || _context.t0)
164
161
  }).send();
165
162
  return _context.abrupt("return", Promise.reject({
166
163
  success: false,
@@ -5,11 +5,9 @@
5
5
  * 1. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE; and
6
6
  * 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
7
7
  */
8
-
8
+ /* eslint-disable @typescript-eslint/no-explicit-any */
9
9
  import { errorEnum } from "../types";
10
10
  import { get } from "../util/get";
11
-
12
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
11
  export var safeJson = function safeJson(data, obj) {
14
12
  try {
15
13
  return JSON.parse(data) || obj;
@@ -19,7 +17,6 @@ export var safeJson = function safeJson(data, obj) {
19
17
  };
20
18
 
21
19
  // 判断header 中的resultStatus
22
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
20
  export var fomatGetwayError = function fomatGetwayError(headers, traceId) {
24
21
  var resultStatus = get(headers, 'Result-Status') || get(headers, 'result-status', '');
25
22
  // 请求静态数据情况
@@ -1,10 +1,4 @@
1
- /**
2
- * Copyright (c) 2022 International Business Group, Ant Group. All rights reserved.
3
- *
4
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), the rights to use, copy, modify, merge, and/or distribute the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
- * 1. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE; and
6
- * 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
7
- */
8
- import { Logger } from '../util/logger';
9
1
  import { CashierSdkActionQueryRequest, CashierSdkActionQueryResult, IrequestConfig } from '../types';
2
+ import { Logger } from '../util/logger';
10
3
  export declare function queryPaymentInfo(params: CashierSdkActionQueryRequest, options: IrequestConfig, logger: Logger): Promise<CashierSdkActionQueryResult>;
4
+ export declare function antomConfig(options: IrequestConfig, logger: Logger): Promise<any>;
@@ -14,7 +14,7 @@ function _asyncToGenerator(fn) { return function () { var self = this, args = ar
14
14
  * 1. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE; and
15
15
  * 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
16
16
  */
17
-
17
+ import { marmotConfigMap } from "../config";
18
18
  import { request } from "../request";
19
19
  export function queryPaymentInfo(_x, _x2, _x3) {
20
20
  return _queryPaymentInfo.apply(this, arguments);
@@ -28,7 +28,6 @@ function _queryPaymentInfo() {
28
28
  hostSign = ((params === null || params === void 0 ? void 0 : params.paymentSessionData) || '').split('&&')[1] || '';
29
29
  return _context.abrupt("return", request(params, _objectSpread(_objectSpread({}, options), {}, {
30
30
  hostSign: hostSign,
31
- needEnvInfo: true,
32
31
  'Operation-Type': 'com.ipay.iexpcashier.sdkAction.query'
33
32
  }), logger));
34
33
  case 2:
@@ -38,4 +37,41 @@ function _queryPaymentInfo() {
38
37
  }, _callee);
39
38
  }));
40
39
  return _queryPaymentInfo.apply(this, arguments);
40
+ }
41
+ export function antomConfig(_x4, _x5) {
42
+ return _antomConfig.apply(this, arguments);
43
+ }
44
+ function _antomConfig() {
45
+ _antomConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(options, logger) {
46
+ var res, json;
47
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
48
+ while (1) switch (_context2.prev = _context2.next) {
49
+ case 0:
50
+ _context2.prev = 0;
51
+ _context2.next = 3;
52
+ return fetch(marmotConfigMap[options.env]);
53
+ case 3:
54
+ res = _context2.sent;
55
+ _context2.next = 6;
56
+ return res.json();
57
+ case 6:
58
+ json = _context2.sent;
59
+ logger.logInfo({
60
+ title: 'Successfully obtained marmot emergency configuration'
61
+ });
62
+ return _context2.abrupt("return", json);
63
+ case 11:
64
+ _context2.prev = 11;
65
+ _context2.t0 = _context2["catch"](0);
66
+ logger.logError({
67
+ title: 'Abnormal acquisition of marmot emergency configuration'
68
+ });
69
+ return _context2.abrupt("return", '{}');
70
+ case 15:
71
+ case "end":
72
+ return _context2.stop();
73
+ }
74
+ }, _callee2, null, [[0, 11]]);
75
+ }));
76
+ return _antomConfig.apply(this, arguments);
41
77
  }
@@ -22,7 +22,7 @@ export interface IoptionsParams {
22
22
  analytics?: {
23
23
  enabled: boolean;
24
24
  };
25
- securityConfig?: IsecurityConfig;
25
+ product?: string;
26
26
  }
27
27
  export type Iselector = string;
28
28
  export declare enum renderDisplayTypeEnum {
@@ -50,13 +50,21 @@ export declare enum productSceneEnum {
50
50
  'EASY_PAY' = "EASY_PAY",
51
51
  'CASHIER_PAYMENT' = "CASHIER_PAYMENT",
52
52
  'AUTO_DEBIT' = "AUTO_DEBIT",
53
- 'VAULTING' = "VAULTING"
53
+ 'VAULTING' = "VAULTING",
54
+ 'FLASH_BUY' = "FLASH_BUY"
54
55
  }
55
56
  export declare enum paymentMethodCategoryTypeEnum {
56
57
  'CARD' = "CARD",
57
58
  'WALLET' = "WALLET",
58
59
  'BANK' = "BANK"
59
60
  }
61
+ export interface DeviceIdParameter {
62
+ scene?: string;
63
+ productScene?: productSceneEnum;
64
+ paymentMethodCategoryType?: paymentMethodCategoryTypeEnum;
65
+ tokenCollectTime?: string;
66
+ dataPollingInterval?: string;
67
+ }
60
68
  export interface IcreateComponent {
61
69
  sessionData: string;
62
70
  paymentSessionData?: string;
@@ -94,6 +102,14 @@ export interface IpaymentSecurityConfig {
94
102
  dataPollingInterval?: string;
95
103
  workSpaceId: string;
96
104
  }
105
+ export interface IsecurityConfig {
106
+ scene: string;
107
+ h5gateway: string;
108
+ }
109
+ export interface InitSecurityConfig {
110
+ product: productSceneEnum;
111
+ region?: string;
112
+ }
97
113
  export interface IpaymentSessionMetaData {
98
114
  clientId?: string;
99
115
  renderDisplayType?: string;
@@ -216,6 +232,7 @@ export interface AMSCheckoutOptions {
216
232
  networkMode: string;
217
233
  mode: string;
218
234
  analytics?: Ianalytics;
235
+ product: string;
219
236
  }
220
237
  export interface Ianalytics {
221
238
  enabled: boolean;
@@ -296,14 +313,6 @@ export interface ThreedData {
296
313
  pti?: number;
297
314
  pt?: number;
298
315
  }
299
- export declare enum SecuritySceneEnum {
300
- CARD = "CARD",
301
- EASYPAY = "EASYPAY"
302
- }
303
- export interface IsecurityConfig {
304
- scene: string;
305
- region: string;
306
- }
307
316
  export declare enum RedirectType {
308
317
  ApplinkUrl = "ApplinkUrl",
309
318
  SchemeUrl = "SchemeUrl",
@@ -29,6 +29,7 @@ export var productSceneEnum = /*#__PURE__*/function (productSceneEnum) {
29
29
  productSceneEnum["CASHIER_PAYMENT"] = "CASHIER_PAYMENT";
30
30
  productSceneEnum["AUTO_DEBIT"] = "AUTO_DEBIT";
31
31
  productSceneEnum["VAULTING"] = "VAULTING";
32
+ productSceneEnum["FLASH_BUY"] = "FLASH_BUY";
32
33
  return productSceneEnum;
33
34
  }({});
34
35
  export var paymentMethodCategoryTypeEnum = /*#__PURE__*/function (paymentMethodCategoryTypeEnum) {
@@ -135,11 +136,6 @@ export var eventCodeEnum = /*#__PURE__*/function (eventCodeEnum) {
135
136
  eventCodeEnum["SDK_CALL_URL_SUCCESS"] = "SDK_CALL_URL_SUCCESS";
136
137
  return eventCodeEnum;
137
138
  }({});
138
- export var SecuritySceneEnum = /*#__PURE__*/function (SecuritySceneEnum) {
139
- SecuritySceneEnum["CARD"] = "CARD";
140
- SecuritySceneEnum["EASYPAY"] = "EASYPAY";
141
- return SecuritySceneEnum;
142
- }({});
143
139
  export var RedirectType = /*#__PURE__*/function (RedirectType) {
144
140
  RedirectType["ApplinkUrl"] = "ApplinkUrl";
145
141
  RedirectType["SchemeUrl"] = "SchemeUrl";
@@ -4,7 +4,6 @@
4
4
  * 1. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE; and
5
5
  * 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
6
6
  */
7
- import { errorEnum } from '../types';
8
7
  declare const getType: (target: any) => string;
9
8
  declare class EventCenter {
10
9
  private events;
@@ -28,28 +27,14 @@ declare const device: {
28
27
  isMobile: boolean;
29
28
  };
30
29
  declare const safeJson: (data: any, obj: any) => any;
31
- declare const fomatGetwayError: (headers: Record<string, any>, traceId: string) => {
32
- success: boolean;
33
- traceId: string;
34
- errorCode: errorEnum;
35
- resultStatus: any;
36
- errorMessage?: undefined;
37
- result?: undefined;
38
- } | {
39
- success: boolean;
40
- traceId: string;
41
- errorCode: errorEnum;
42
- errorMessage: string;
43
- result: {
44
- resultStatus: any;
45
- tips: string;
46
- memo: string;
47
- };
48
- resultStatus: any;
49
- };
50
30
  declare const isPC: () => boolean;
51
31
  declare const queryParse: (url?: string) => Record<string, any>;
52
32
  declare const getDesignFontSize: () => number;
53
33
  declare const amsSetSize: (event?: any, dom?: any) => void;
54
34
  declare const addSetFontSizeEvent: () => void;
55
- export { getType, EventCenter, getViewPort, getOrigin, serialize, isJsonString, isDom, device, fomatGetwayError, safeJson, isPC, queryParse, getDesignFontSize, amsSetSize, addSetFontSizeEvent };
35
+ /**
36
+ * @description get or set STORAGE
37
+ */
38
+ declare const getOrSetStorageId: (key: string, value?: string) => string;
39
+ declare const checkTimeElapsed: () => boolean;
40
+ export { getType, EventCenter, getViewPort, getOrigin, serialize, isJsonString, isDom, device, safeJson, isPC, queryParse, getDesignFontSize, amsSetSize, addSetFontSizeEvent, getOrSetStorageId, checkTimeElapsed, };
package/esm/util/index.js CHANGED
@@ -12,8 +12,7 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
12
12
  * 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
13
13
  */
14
14
  /* eslint-disable @typescript-eslint/no-explicit-any */
15
- import { errorEnum } from "../types";
16
- import { get } from "./get";
15
+
17
16
  var getType = function getType(target) {
18
17
  return Object.prototype.toString.call(target).slice(8, -1).toLowerCase();
19
18
  };
@@ -160,48 +159,6 @@ var safeJson = function safeJson(data, obj) {
160
159
  return obj;
161
160
  }
162
161
  };
163
-
164
- // 判断header 中的resultStatus
165
- var fomatGetwayError = function fomatGetwayError(headers, traceId) {
166
- var resultStatus = get(headers, 'Result-Status') || get(headers, 'result-status', '');
167
- // 请求静态数据情况
168
- if (!resultStatus) return null;
169
- // 未登录
170
- if (+resultStatus === 2000) {
171
- return {
172
- success: false,
173
- traceId: traceId,
174
- errorCode: errorEnum.LOGIN,
175
- resultStatus: resultStatus
176
- };
177
- }
178
- // 网关超时
179
- if (+resultStatus === 4001) {
180
- return {
181
- success: false,
182
- traceId: traceId,
183
- errorCode: errorEnum.TIMEOUT,
184
- resultStatus: resultStatus
185
- };
186
- }
187
- if (+resultStatus !== 1000) {
188
- var tips = get(headers, 'Tips') || get(headers, 'tips', '');
189
- var memo = get(headers, 'Memo') || get(headers, 'memo', '');
190
- return {
191
- success: false,
192
- traceId: traceId,
193
- errorCode: errorEnum.GATEWAY,
194
- errorMessage: decodeURIComponent(tips || ''),
195
- result: {
196
- resultStatus: resultStatus || '',
197
- tips: decodeURIComponent(tips || ''),
198
- memo: decodeURIComponent(memo || '')
199
- },
200
- resultStatus: resultStatus
201
- };
202
- }
203
- return null;
204
- };
205
162
  var isPC = function isPC() {
206
163
  var userAgentInfo = navigator.userAgent;
207
164
  var agents = ['Android', 'iPhone', 'SymbianOS', 'Windows Phone', 'iPod'];
@@ -248,4 +205,40 @@ var addSetFontSizeEvent = function addSetFontSizeEvent() {
248
205
  window.addEventListener('pageShow', amsSetSize);
249
206
  window.addEventListener('DOMContentLoaded', amsSetSize);
250
207
  };
251
- export { getType, EventCenter, getViewPort, getOrigin, serialize, isJsonString, isDom, device, fomatGetwayError, safeJson, isPC, queryParse, getDesignFontSize, amsSetSize, addSetFontSizeEvent };
208
+
209
+ /**
210
+ * @description get or set STORAGE
211
+ */
212
+ var getOrSetStorageId = function getOrSetStorageId(key, value) {
213
+ try {
214
+ if (key && !value) {
215
+ var storageValue = window.localStorage.getItem(key);
216
+ if (storageValue) {
217
+ return storageValue;
218
+ } else return '';
219
+ }
220
+ if (key && value) {
221
+ window.localStorage.setItem(key, value);
222
+ }
223
+ } catch (error) {
224
+ return '';
225
+ }
226
+ };
227
+ var checkTimeElapsed = function checkTimeElapsed() {
228
+ try {
229
+ var key = 'antomSDKConfiglastCallTime';
230
+ var currentTime = new Date().getTime();
231
+ var lastCallTime = localStorage.getItem(key);
232
+ if (lastCallTime) {
233
+ var elapsedTime = currentTime - parseInt(lastCallTime);
234
+ if (elapsedTime >= 10 * 60 * 1000) {
235
+ // 超过10分钟
236
+ return true;
237
+ } else return false;
238
+ }
239
+ // 记录当前调用时间
240
+ localStorage.setItem(key, currentTime.toString());
241
+ } catch (error) {/* empty */}
242
+ return true;
243
+ };
244
+ export { getType, EventCenter, getViewPort, getOrigin, serialize, isJsonString, isDom, device, safeJson, isPC, queryParse, getDesignFontSize, amsSetSize, addSetFontSizeEvent, getOrSetStorageId, checkTimeElapsed };
@@ -1,15 +1,31 @@
1
- import type { IpaymentSecurityConfig, IsecurityConfig } from '../types';
1
+ import { IsecurityConfig, productSceneEnum, DeviceIdParameter } from '../types';
2
+ export declare const getSecurityConfigStorageKey: (scene: productSceneEnum) => string;
3
+ export declare enum SecurityRegionEnum {
4
+ SG = "SG",
5
+ US = "US",
6
+ DE = "DE"
7
+ }
2
8
  export declare const securityHost: {
3
9
  SG: string;
4
10
  US: string;
5
11
  DE: string;
6
12
  };
7
- export declare const getSecurityHost: (region: string) => string;
8
- export declare const appName: {
9
- CARD: string;
13
+ export declare const sceneMap: {
14
+ CASHIER_PAYMENT: string;
15
+ AUTO_DEBIT: string;
16
+ VAULTING: string;
10
17
  EASYPAY: string;
18
+ EASY_PAY: string;
19
+ FLASH_BUY: string;
11
20
  };
12
- export declare const initAPSecurity: (securityConfig: IsecurityConfig, successCallback: any, failCallback: any) => void;
13
- export declare const initSecuritySDK: (appName: string, h5gateway: string, successCallback: () => void, failCallback: (errMsg?: string) => void) => void;
14
- export declare const getAppname: (scene: string) => string;
15
- export declare const getApdidToken: (scene: string, securityConfig?: IpaymentSecurityConfig) => Promise<string>;
21
+ export declare const getSecurityHost: (region: string) => string;
22
+ export declare const getSecurityScene: (product: string) => string;
23
+ export declare class Security {
24
+ scene: string;
25
+ h5gateway: string;
26
+ constructor(options: IsecurityConfig);
27
+ initSecurity(successCallback: any, failCallback: any): void;
28
+ private initToken;
29
+ pollingGetApdidToken(config?: DeviceIdParameter): Promise<string>;
30
+ getApdidToken(): Promise<string>;
31
+ }