@alipay/ams-checkout 0.0.1693912790-dev.2 → 0.0.1693912790-dev.3

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.
@@ -20,11 +20,17 @@ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input ==
20
20
  import { closeImg, COMPONENTPLUGINID, ERRORMESSAGE, EVENT } from "../../constant";
21
21
  import { queryPaymentInfo } from "../../service";
22
22
  import { componentSignEnum, messageName, productSceneEnum, Target } from "../../types";
23
- import { getDesignFontSize, getType, isJsonString, isPC } from "../../util";
23
+ import { getDesignFontSize, getType, isJsonString, isPC, queryParse } from "../../util";
24
24
  import { isLocalMock } from "../../util/mock";
25
25
  import { createIframe, getAppDomain, getIframeUrl } from "./cashierApp";
26
26
  import { componentAddCSS } from "./component.style";
27
27
  import APDID from '@alipay/jshield-apdid';
28
+ import { getSecurityHost, getAppname } from "../../util/security";
29
+ var _ref = queryParse() || {},
30
+ preinit = _ref.preinit,
31
+ rebuild = _ref.rebuild,
32
+ scene = _ref.scene,
33
+ region = _ref.region;
28
34
  var _window = window,
29
35
  innerHeight = _window.innerHeight;
30
36
  var amsSetSize = function amsSetSize(event, dom) {
@@ -111,12 +117,21 @@ var ComponentApp = /*#__PURE__*/function () {
111
117
  key: "initAPSecurity",
112
118
  value: function initAPSecurity() {
113
119
  var _this$_renderParams, _this$_renderParams$p;
120
+ if (componentSignEnum.CASHIER_PAYMENT_CARD !== this._componentSign) {
121
+ return;
122
+ }
114
123
  var securityConfig = (_this$_renderParams = this._renderParams) === null || _this$_renderParams === void 0 ? void 0 : (_this$_renderParams$p = _this$_renderParams.paymentSessionMetaData) === null || _this$_renderParams$p === void 0 ? void 0 : _this$_renderParams$p.securityConfig;
115
124
  if (!securityConfig) {
116
125
  return;
117
126
  }
118
- APDID.initToken(securityConfig === null || securityConfig === void 0 ? void 0 : securityConfig.appName, {
119
- host: securityConfig === null || securityConfig === void 0 ? void 0 : securityConfig.h5gateway
127
+ var appName = securityConfig === null || securityConfig === void 0 ? void 0 : securityConfig.appName;
128
+ var h5gateway = securityConfig === null || securityConfig === void 0 ? void 0 : securityConfig.h5gateway;
129
+ if (preinit === 'true' || rebuild === 'true') {
130
+ appName = getAppname(scene);
131
+ h5gateway = getSecurityHost(region);
132
+ }
133
+ APDID.initToken(appName, {
134
+ host: h5gateway
120
135
  }, function (success, tokenResult, msg) {
121
136
  console.log("initToken result tokenResult", JSON.stringify(tokenResult));
122
137
  });
@@ -181,13 +196,16 @@ var ComponentApp = /*#__PURE__*/function () {
181
196
  params.paymentMethodType = 'CARD';
182
197
  }
183
198
  var needDeviceId = false;
199
+ var waitTime = '3000';
184
200
  var securityConfig = (_this2$_renderParams4 = _this2._renderParams) === null || _this2$_renderParams4 === void 0 ? void 0 : (_this2$_renderParams5 = _this2$_renderParams4.paymentSessionMetaData) === null || _this2$_renderParams5 === void 0 ? void 0 : _this2$_renderParams5.securityConfig;
185
201
  if (componentSignEnum.CASHIER_PAYMENT_CARD === _this2._componentSign && securityConfig) {
186
202
  var _this2$_renderParams6, _this2$_renderParams7;
187
203
  var extendInfo = ((_this2$_renderParams6 = _this2._renderParams) === null || _this2$_renderParams6 === void 0 ? void 0 : (_this2$_renderParams7 = _this2$_renderParams6.paymentSessionMetaData) === null || _this2$_renderParams7 === void 0 ? void 0 : _this2$_renderParams7.extendInfo) || '';
188
204
  var info = JSON.parse(extendInfo);
189
205
  if ((info === null || info === void 0 ? void 0 : info.cardTokenPay) !== 'false') {
206
+ var _this2$_renderParams8, _this2$_renderParams9, _this2$_renderParams10;
190
207
  needDeviceId = true;
208
+ waitTime = (_this2$_renderParams8 = _this2._renderParams) === null || _this2$_renderParams8 === void 0 ? void 0 : (_this2$_renderParams9 = _this2$_renderParams8.paymentSessionMetaData) === null || _this2$_renderParams9 === void 0 ? void 0 : (_this2$_renderParams10 = _this2$_renderParams9.securityConfig) === null || _this2$_renderParams10 === void 0 ? void 0 : _this2$_renderParams10.tokenCollectTime;
191
209
  }
192
210
  }
193
211
 
@@ -195,17 +213,17 @@ var ComponentApp = /*#__PURE__*/function () {
195
213
  * @description easyPay
196
214
  */
197
215
  if (componentSignEnum.EASY_PAY_WALLET === _this2._componentSign) {
198
- var _this2$_renderParams8;
199
- var _ref = params.paymentSessionConfig || {},
200
- _ref$productSceneVers = _ref.productSceneVersion,
201
- productSceneVersion = _ref$productSceneVers === void 0 ? '' : _ref$productSceneVers,
202
- _ref$productScene = _ref.productScene,
203
- productScene = _ref$productScene === void 0 ? '' : _ref$productScene;
204
- var _ref2 = ((_this2$_renderParams8 = _this2._renderParams) === null || _this2$_renderParams8 === void 0 ? void 0 : _this2$_renderParams8.paymentSessionMetaData) || {},
205
- _ref2$action = _ref2.action,
206
- _ref2$action2 = _ref2$action === void 0 ? {} : _ref2$action,
207
- _ref2$action2$autoDeb = _ref2$action2.autoDebitWithToken,
208
- autoDebitWithToken = _ref2$action2$autoDeb === void 0 ? false : _ref2$action2$autoDeb;
216
+ var _this2$_renderParams11;
217
+ var _ref2 = params.paymentSessionConfig || {},
218
+ _ref2$productSceneVer = _ref2.productSceneVersion,
219
+ productSceneVersion = _ref2$productSceneVer === void 0 ? '' : _ref2$productSceneVer,
220
+ _ref2$productScene = _ref2.productScene,
221
+ productScene = _ref2$productScene === void 0 ? '' : _ref2$productScene;
222
+ var _ref3 = ((_this2$_renderParams11 = _this2._renderParams) === null || _this2$_renderParams11 === void 0 ? void 0 : _this2$_renderParams11.paymentSessionMetaData) || {},
223
+ _ref3$action = _ref3.action,
224
+ _ref3$action2 = _ref3$action === void 0 ? {} : _ref3$action,
225
+ _ref3$action2$autoDeb = _ref3$action2.autoDebitWithToken,
226
+ autoDebitWithToken = _ref3$action2$autoDeb === void 0 ? false : _ref3$action2$autoDeb;
209
227
  if (productScene === productSceneEnum.EASY_PAY && productSceneVersion === '2.0' && !autoDebitWithToken) {
210
228
  // if EASY_PAY 2.0 , no need to query payment request
211
229
  return resolve({
@@ -219,8 +237,8 @@ var ComponentApp = /*#__PURE__*/function () {
219
237
  * @description autoDebit
220
238
  */
221
239
  if (componentSignEnum.AUTO_DEBIT_WALLET === _this2._componentSign) {
222
- var _this2$_renderParams9, _this2$_renderParams10, _action$web, _action$wap;
223
- var action = ((_this2$_renderParams9 = _this2._renderParams) === null || _this2$_renderParams9 === void 0 ? void 0 : (_this2$_renderParams10 = _this2$_renderParams9.paymentSessionMetaData) === null || _this2$_renderParams10 === void 0 ? void 0 : _this2$_renderParams10.action) || {};
240
+ var _this2$_renderParams12, _this2$_renderParams13, _action$web, _action$wap;
241
+ var action = ((_this2$_renderParams12 = _this2._renderParams) === null || _this2$_renderParams12 === void 0 ? void 0 : (_this2$_renderParams13 = _this2$_renderParams12.paymentSessionMetaData) === null || _this2$_renderParams13 === void 0 ? void 0 : _this2$_renderParams13.action) || {};
224
242
  var signType = isPC() ? action === null || action === void 0 ? void 0 : (_action$web = action.web) === null || _action$web === void 0 ? void 0 : _action$web.signType : action === null || action === void 0 ? void 0 : (_action$wap = action.wap) === null || _action$wap === void 0 ? void 0 : _action$wap.signType;
225
243
  if (signType === 'SMS') {
226
244
  return resolve({
@@ -245,7 +263,8 @@ var ComponentApp = /*#__PURE__*/function () {
245
263
  queryPaymentInfo(params, {
246
264
  env: _this2.AMSSDK.options.env.environment,
247
265
  locale: _this2.AMSSDK.options.locale,
248
- needDeviceId: needDeviceId
266
+ needDeviceId: needDeviceId,
267
+ waitTime: waitTime
249
268
  }).then(function (res) {
250
269
  _this2._performanceData.push({
251
270
  key: 'sdk_action_query_end',
@@ -539,9 +558,9 @@ var ComponentApp = /*#__PURE__*/function () {
539
558
  }
540
559
  }, {
541
560
  key: "handleDeclareInfo",
542
- value: function handleDeclareInfo(_ref3) {
543
- var _ref3$closeDialogData = _ref3.closeDialogData,
544
- closeDialogData = _ref3$closeDialogData === void 0 ? {} : _ref3$closeDialogData;
561
+ value: function handleDeclareInfo(_ref4) {
562
+ var _ref4$closeDialogData = _ref4.closeDialogData,
563
+ closeDialogData = _ref4$closeDialogData === void 0 ? {} : _ref4$closeDialogData;
545
564
  try {
546
565
  if (closeDialogData) {
547
566
  var retentionTitle = document.getElementById('ams-component-retention-title');
@@ -19,7 +19,7 @@ import { sdkVersion } from "../config/index";
19
19
  import { appId, hostSignMap, lightSandboxMap, requestHost, sofaId, tntInstId } from "../config/request";
20
20
  import { ERROR } from "../types";
21
21
  import { get } from "../util/get";
22
- import { getApdidToken } from "../util/security";
22
+ import { getApdidToken, getAppname } from "../util/security";
23
23
  import axios from 'axios';
24
24
  import { device, fomatGetwayError, isPC, queryParse, safeJson } from "../util";
25
25
  var _queryParse = queryParse(),
@@ -89,7 +89,7 @@ function _request() {
89
89
  break;
90
90
  }
91
91
  _context.next = 6;
92
- return getApdidToken('Acquirer');
92
+ return getApdidToken(getAppname('Card'), options === null || options === void 0 ? void 0 : options.waitTime);
93
93
  case 6:
94
94
  deviceId = _context.sent;
95
95
  envInfo.deviceId = deviceId;
@@ -189,6 +189,7 @@ export interface RequestConfig {
189
189
  afterRequest?: () => void;
190
190
  needEnvInfo?: boolean;
191
191
  needDeviceId?: boolean;
192
+ waitTime?: string;
192
193
  locale?: string;
193
194
  hostSign?: string;
194
195
  }
@@ -1,7 +1,12 @@
1
- export declare enum securityHost {
2
- SG = "http://iopengw-9395.sggz00b.dev.alipay.net/api/open/risk_client",
3
- US = "http://iopengw-5506.gz00b.dev.alipay.net/api/open/risk_client",
4
- DE = "http://iopengw-910.degz00b.dev.alipay.net/api/open/risk_client"
5
- }
6
- export declare const getSecurityConfig: () => string;
7
- export declare const getApdidToken: (scene: string) => Promise<string>;
1
+ export declare const securityHost: {
2
+ SG: string;
3
+ US: string;
4
+ DE: string;
5
+ };
6
+ export declare const getSecurityHost: (region: string) => string;
7
+ export declare const appName: {
8
+ Card: string;
9
+ EasyPay: string;
10
+ };
11
+ export declare const getAppname: (scene: string) => string;
12
+ export declare const getApdidToken: (scene: string, waitTime?: string) => Promise<string>;
@@ -3,36 +3,105 @@ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyri
3
3
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
4
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
5
5
  import APDID from '@alipay/jshield-apdid';
6
- export var securityHost = /*#__PURE__*/function (securityHost) {
7
- securityHost["SG"] = "http://iopengw-9395.sggz00b.dev.alipay.net/api/open/risk_client";
8
- securityHost["US"] = "http://iopengw-5506.gz00b.dev.alipay.net/api/open/risk_client";
9
- securityHost["DE"] = "http://iopengw-910.degz00b.dev.alipay.net/api/open/risk_client";
10
- return securityHost;
11
- }({});
12
- export var getSecurityConfig = function getSecurityConfig() {
13
- return '';
6
+ export var securityHost = {
7
+ SG: 'http://iopengw-9395.sggz00b.dev.alipay.net/api/open/risk_client',
8
+ US: 'http://iopengw-5506.gz00b.dev.alipay.net/api/open/risk_client',
9
+ DE: 'http://iopengw-910.degz00b.dev.alipay.net/api/open/risk_client'
10
+ };
11
+ export var getSecurityHost = function getSecurityHost(region) {
12
+ return securityHost[region] || '';
13
+ };
14
+ export var appName = {
15
+ Card: 'Acquirer',
16
+ EasyPay: 'EasyPay'
17
+ };
18
+ export var getAppname = function getAppname(scene) {
19
+ return appName[scene] || '';
14
20
  };
15
21
  export var getApdidToken = /*#__PURE__*/function () {
16
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(scene) {
17
- return _regeneratorRuntime().wrap(function _callee$(_context) {
18
- while (1) switch (_context.prev = _context.next) {
22
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(scene, waitTime) {
23
+ var waitTimeMs;
24
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
25
+ while (1) switch (_context3.prev = _context3.next) {
26
+ case 0:
27
+ waitTimeMs = waitTime ? parseInt(waitTime, 10) : 3000;
28
+ return _context3.abrupt("return", new Promise( /*#__PURE__*/function () {
29
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(resolve, reject) {
30
+ var deviceId, interval;
31
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
32
+ while (1) switch (_context2.prev = _context2.next) {
33
+ case 0:
34
+ _context2.next = 2;
35
+ return tryGetDeviceId(scene);
36
+ case 2:
37
+ deviceId = _context2.sent;
38
+ if (deviceId) {
39
+ resolve(deviceId);
40
+ } else {
41
+ interval = setInterval( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
42
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
43
+ while (1) switch (_context.prev = _context.next) {
44
+ case 0:
45
+ _context.next = 2;
46
+ return tryGetDeviceId(scene);
47
+ case 2:
48
+ deviceId = _context.sent;
49
+ if (deviceId) {
50
+ clearInterval(interval);
51
+ resolve(deviceId);
52
+ }
53
+ case 4:
54
+ case "end":
55
+ return _context.stop();
56
+ }
57
+ }, _callee);
58
+ })), 1000);
59
+ setTimeout(function () {
60
+ clearInterval(interval);
61
+ resolve('');
62
+ }, waitTimeMs);
63
+ }
64
+ case 4:
65
+ case "end":
66
+ return _context2.stop();
67
+ }
68
+ }, _callee2);
69
+ }));
70
+ return function (_x3, _x4) {
71
+ return _ref2.apply(this, arguments);
72
+ };
73
+ }()));
74
+ case 2:
75
+ case "end":
76
+ return _context3.stop();
77
+ }
78
+ }, _callee3);
79
+ }));
80
+ return function getApdidToken(_x, _x2) {
81
+ return _ref.apply(this, arguments);
82
+ };
83
+ }();
84
+ var tryGetDeviceId = /*#__PURE__*/function () {
85
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(scene) {
86
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
87
+ while (1) switch (_context4.prev = _context4.next) {
19
88
  case 0:
20
- return _context.abrupt("return", new Promise(function (resolve, reject) {
89
+ return _context4.abrupt("return", new Promise(function (resolve, reject) {
21
90
  try {
22
91
  APDID.getApdidToken(scene, function (tokenResult) {
23
92
  resolve(tokenResult === null || tokenResult === void 0 ? void 0 : tokenResult.token);
24
93
  });
25
94
  } catch (error) {
26
- reject('');
95
+ resolve('');
27
96
  }
28
97
  }));
29
98
  case 1:
30
99
  case "end":
31
- return _context.stop();
100
+ return _context4.stop();
32
101
  }
33
- }, _callee);
102
+ }, _callee4);
34
103
  }));
35
- return function getApdidToken(_x) {
36
- return _ref.apply(this, arguments);
104
+ return function tryGetDeviceId(_x5) {
105
+ return _ref4.apply(this, arguments);
37
106
  };
38
107
  }();
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@alipay/ams-checkout","version":"0.0.1693912790-dev.2","description":"","author":"","main":"esm/index.js","module":"esm/index.js","typings":"esm/index.d.ts","files":["dist","esm","LEGAL.md","LICENSE","README.md"],"scripts":{"build":"father build","ci":"npm run lint","cov":"jest --coverage","format":"prettier --write --no-error-on-unmatched-pattern \"**/*.{js,jsx,ts,tsx,md,json,css,less}\"","lint":"eslint ./src","test":"jest"},"dependencies":{"axios":"^1.3.4","uuid":"^9.0.0"},"devDependencies":{"@alipay/jshield-apdid":"^2.0.3","@babel/core":"^7.20.7","@babel/preset-env":"^7.20.2","@testing-library/jest-dom":"^5.1.1","@testing-library/react":"^9.5.0","@types/jest":"^29.2.4","@types/uuid":"^9.0.0","@typescript-eslint/parser":"^5.60.0","babel-jest":"^29.3.1","babel-loader":"^9.1.0","babel-plugin-import":"^1.13.0","eslint":"^8.36.0","father":"^4.2.3","jest":"^29.5.0","jest-environment-jsdom":"^29.3.1","prettier":"^2.8.4","prettier-plugin-organize-imports":"^3.2.3","prettier-plugin-packagejson":"^2.4.5","ts-jest":"^29.0.3","ts-node":"^10.9.1","typescript":"^4.9.5"},"engines":{},"publishConfig":{"access":"public"}}
1
+ {"name":"@alipay/ams-checkout","version":"0.0.1693912790-dev.3","description":"","author":"","main":"esm/index.js","module":"esm/index.js","typings":"esm/index.d.ts","files":["dist","esm","LEGAL.md","LICENSE","README.md"],"scripts":{"build":"father build","ci":"npm run lint","cov":"jest --coverage","format":"prettier --write --no-error-on-unmatched-pattern \"**/*.{js,jsx,ts,tsx,md,json,css,less}\"","lint":"eslint ./src","test":"jest"},"dependencies":{"axios":"^1.3.4","uuid":"^9.0.0"},"devDependencies":{"@alipay/jshield-apdid":"^2.0.3","@babel/core":"^7.20.7","@babel/preset-env":"^7.20.2","@testing-library/jest-dom":"^5.1.1","@testing-library/react":"^9.5.0","@types/jest":"^29.2.4","@types/uuid":"^9.0.0","@typescript-eslint/parser":"^5.60.0","babel-jest":"^29.3.1","babel-loader":"^9.1.0","babel-plugin-import":"^1.13.0","eslint":"^8.36.0","father":"^4.2.3","jest":"^29.5.0","jest-environment-jsdom":"^29.3.1","prettier":"^2.8.4","prettier-plugin-organize-imports":"^3.2.3","prettier-plugin-packagejson":"^2.4.5","ts-jest":"^29.0.3","ts-node":"^10.9.1","typescript":"^4.9.5"},"engines":{},"publishConfig":{"access":"public"}}