@alipay/ams-checkout 0.0.1697942541-dev.4 → 0.0.1697942541-dev.6

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,81 +12,107 @@ 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.sence) || !(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.sence);
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.sence, " 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
+ APDID.initToken(appName, {
31
+ host: h5gateway
32
+ }, function (success, tokenResult, msg) {
33
+ if (success) {
34
+ console.log("-----------Risk control project test: \u521D\u59CB\u5316\u5B89\u5168sdk\u6210\u529F");
35
+ successCallback && successCallback();
36
+ } else {
37
+ console.log("-----------Risk control project test: \u521D\u59CB\u5316\u5B89\u5168sdk\u5931\u8D25");
38
+ failCallback && failCallback(msg);
39
+ }
40
+ console.log('initToken result tokenResult', JSON.stringify(tokenResult), msg);
41
+ });
17
42
  };
18
43
  export var getAppname = function getAppname(scene) {
19
44
  return appName[scene] || '';
20
45
  };
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 () {
46
+ export var getApdidToken = function getApdidToken(scene, securityConfig) {
47
+ var tokenCollectTime = parseInt((securityConfig === null || securityConfig === void 0 ? void 0 : securityConfig.tokenCollectTime) || '1500', 10);
48
+ var dataPollingInterval = parseInt((securityConfig === null || securityConfig === void 0 ? void 0 : securityConfig.dataPollingInterval) || '500', 10);
49
+ var asyncFunc = /*#__PURE__*/function () {
50
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(resolve) {
51
+ var deviceId, interval, polling;
52
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
53
+ while (1) switch (_context2.prev = _context2.next) {
54
+ case 0:
55
+ console.log("-----------Risk control project test: \u5FAA\u73AF\u83B7\u53D6deviceId\uFF0C\u95F4\u9694".concat(dataPollingInterval));
56
+ _context2.next = 3;
57
+ return tryGetDeviceId(scene);
58
+ case 3:
59
+ deviceId = _context2.sent;
60
+ polling = /*#__PURE__*/function () {
61
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
62
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
63
+ while (1) switch (_context.prev = _context.next) {
64
+ case 0:
65
+ console.log("-----------Risk control project test: \u5FAA\u73AF\u83B7\u53D6deviceId\uFF0C\u95F4\u9694".concat(dataPollingInterval));
66
+ _context.next = 3;
67
+ return tryGetDeviceId(scene);
68
+ case 3:
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
+ console.log("-----------Risk control project test: \u83B7\u53D6deviceId\u6210\u529F".concat(deviceId));
73
+ resolve(deviceId);
74
+ }
75
+ case 5:
76
+ case "end":
77
+ return _context.stop();
78
+ }
79
+ }, _callee);
80
+ }));
81
+ return function polling() {
82
+ return _ref2.apply(this, arguments);
83
+ };
84
+ }();
85
+ if (deviceId) {
86
+ console.log("-----------Risk control project test: \u6210\u529F\u83B7\u53D6deviceId\uFF1A".concat(deviceId));
87
+ resolve(deviceId);
88
+ } else {
89
+ interval = setInterval(polling, dataPollingInterval);
90
+ setTimeout(function () {
91
+ clearInterval(interval);
92
+ console.log("-----------Risk control project test: \u83B7\u53D6deviceId\u5931\u8D25");
93
+ resolve('');
94
+ }, tokenCollectTime);
95
+ }
96
+ case 6:
97
+ case "end":
98
+ return _context2.stop();
99
+ }
100
+ }, _callee2);
101
+ }));
102
+ return function asyncFunc(_x) {
103
+ return _ref.apply(this, arguments);
104
+ };
105
+ }();
106
+ return new Promise(function (resolve) {
107
+ asyncFunc(resolve);
108
+ });
109
+ };
84
110
  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) {
111
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(scene) {
112
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
113
+ while (1) switch (_context3.prev = _context3.next) {
88
114
  case 0:
89
- return _context4.abrupt("return", new Promise(function (resolve, reject) {
115
+ return _context3.abrupt("return", new Promise(function (resolve) {
90
116
  try {
91
117
  APDID.getApdidToken(scene, function (tokenResult) {
92
118
  resolve(tokenResult === null || tokenResult === void 0 ? void 0 : tokenResult.token);
@@ -97,11 +123,11 @@ var tryGetDeviceId = /*#__PURE__*/function () {
97
123
  }));
98
124
  case 1:
99
125
  case "end":
100
- return _context4.stop();
126
+ return _context3.stop();
101
127
  }
102
- }, _callee4);
128
+ }, _callee3);
103
129
  }));
104
- return function tryGetDeviceId(_x5) {
105
- return _ref4.apply(this, arguments);
130
+ return function tryGetDeviceId(_x2) {
131
+ return _ref3.apply(this, arguments);
106
132
  };
107
133
  }();
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"@alipay/ams-checkout","version":"0.0.1697942541-dev.4","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":"0.0.1697942541-dev.6","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"}}