@alipay/ams-checkout 1.5.8 → 1.5.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.
@@ -12,83 +12,106 @@ export var getSecurityHost = function getSecurityHost(region) {
12
12
  return securityHost[region] || '';
13
13
  };
14
14
  export var appName = {
15
- Card: 'Acquirer',
16
- EasyPay: 'EasyPay'
15
+ CARD: 'Acquirer',
16
+ EASYPAY: 'EasyPay'
17
+ };
18
+ export var initAPSecurity = function initAPSecurity(securityConfig, successCallback, failCallback) {
19
+ if (!securityConfig || !(securityConfig !== null && securityConfig !== void 0 && securityConfig.scene) || !(securityConfig !== null && securityConfig !== void 0 && securityConfig.region)) {
20
+ throw new Error('securityConfig parameter error');
21
+ }
22
+ var curAppName = getAppname(securityConfig === null || securityConfig === void 0 ? void 0 : securityConfig.scene);
23
+ var h5gateway = getSecurityHost(securityConfig === null || securityConfig === void 0 ? void 0 : securityConfig.region);
24
+ if (!curAppName || !h5gateway) {
25
+ throw new Error("appName:".concat(securityConfig === null || securityConfig === void 0 ? void 0 : securityConfig.scene, " or region:").concat(securityConfig === null || securityConfig === void 0 ? void 0 : securityConfig.region, " do not supported"));
26
+ }
27
+ initSecuritySDK(curAppName, h5gateway, successCallback, failCallback);
28
+ };
29
+ export var initSecuritySDK = function initSecuritySDK(appName, h5gateway, successCallback, failCallback) {
30
+ try {
31
+ APDID === null || APDID === void 0 || APDID.initToken(appName, {
32
+ host: h5gateway
33
+ }, function (success, tokenResult, msg) {
34
+ if (success) {
35
+ successCallback && successCallback();
36
+ } else {
37
+ failCallback && failCallback(msg);
38
+ }
39
+ console.log('initToken result tokenResult', JSON.stringify(tokenResult), msg);
40
+ });
41
+ } catch (error) {
42
+ failCallback && failCallback();
43
+ }
17
44
  };
18
45
  export var getAppname = function getAppname(scene) {
19
46
  return appName[scene] || '';
20
47
  };
21
- export var getApdidToken = /*#__PURE__*/function () {
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 () {
48
+ export var getApdidToken = function getApdidToken(scene, securityConfig) {
49
+ var tokenCollectTime = parseInt((securityConfig === null || securityConfig === void 0 ? void 0 : securityConfig.tokenCollectTime) || '1500', 10);
50
+ var dataPollingInterval = parseInt((securityConfig === null || securityConfig === void 0 ? void 0 : securityConfig.dataPollingInterval) || '500', 10);
51
+ var asyncFunc = /*#__PURE__*/function () {
52
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(resolve) {
53
+ var deviceId, interval, polling;
54
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
55
+ while (1) switch (_context2.prev = _context2.next) {
56
+ case 0:
57
+ _context2.next = 2;
58
+ return tryGetDeviceId(scene);
59
+ case 2:
60
+ deviceId = _context2.sent;
61
+ polling = /*#__PURE__*/function () {
62
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
63
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
64
+ while (1) switch (_context.prev = _context.next) {
65
+ case 0:
66
+ _context.next = 2;
67
+ return tryGetDeviceId(scene);
68
+ case 2:
69
+ deviceId = _context.sent;
70
+ if (deviceId) {
60
71
  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
- }();
72
+ resolve(deviceId);
73
+ }
74
+ case 4:
75
+ case "end":
76
+ return _context.stop();
77
+ }
78
+ }, _callee);
79
+ }));
80
+ return function polling() {
81
+ return _ref2.apply(this, arguments);
82
+ };
83
+ }();
84
+ if (deviceId) {
85
+ resolve(deviceId);
86
+ } else {
87
+ interval = setInterval(polling, dataPollingInterval);
88
+ setTimeout(function () {
89
+ clearInterval(interval);
90
+ resolve('');
91
+ }, tokenCollectTime);
92
+ }
93
+ case 5:
94
+ case "end":
95
+ return _context2.stop();
96
+ }
97
+ }, _callee2);
98
+ }));
99
+ return function asyncFunc(_x) {
100
+ return _ref.apply(this, arguments);
101
+ };
102
+ }();
103
+ return new Promise(function (resolve) {
104
+ asyncFunc(resolve);
105
+ });
106
+ };
84
107
  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) {
108
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(scene) {
109
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
110
+ while (1) switch (_context3.prev = _context3.next) {
88
111
  case 0:
89
- return _context4.abrupt("return", new Promise(function (resolve, reject) {
112
+ return _context3.abrupt("return", new Promise(function (resolve) {
90
113
  try {
91
- APDID.getApdidToken(scene, function (tokenResult) {
114
+ APDID === null || APDID === void 0 || APDID.getApdidToken(scene, function (tokenResult) {
92
115
  resolve(tokenResult === null || tokenResult === void 0 ? void 0 : tokenResult.token);
93
116
  });
94
117
  } catch (error) {
@@ -97,11 +120,11 @@ var tryGetDeviceId = /*#__PURE__*/function () {
97
120
  }));
98
121
  case 1:
99
122
  case "end":
100
- return _context4.stop();
123
+ return _context3.stop();
101
124
  }
102
- }, _callee4);
125
+ }, _callee3);
103
126
  }));
104
- return function tryGetDeviceId(_x5) {
105
- return _ref4.apply(this, arguments);
127
+ return function tryGetDeviceId(_x2) {
128
+ return _ref3.apply(this, arguments);
106
129
  };
107
130
  }();
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@alipay/ams-checkout","version":"1.5.8","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/eslint-plugin":"latest","@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","eslint-plugin-prettier":"latest","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":"1.5.9","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":{"@alipay/jshield-apdid":"^2.0.3","axios":"^1.3.4","uuid":"^9.0.0"},"devDependencies":{"@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/eslint-plugin":"latest","@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","eslint-plugin-prettier":"latest","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"}}