@alipay/ams-checkout 0.0.1783663570-dev.1 → 0.0.1783663570-dev.2
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.
- package/ams-checkout.js +3 -3
- package/dist/ams-checkout.min.js +1 -1
- package/esm/core/instance/index.d.ts +12 -4
- package/esm/core/instance/index.js +152 -26
- package/esm/foundation/service/security/index.d.ts +9 -4
- package/esm/foundation/service/security/index.js +158 -35
- package/esm/foundation/service/security/security.d.ts +22 -1
- package/esm/foundation/service/security/security.js +150 -37
- package/esm/foundation/utils/preload_helper.d.ts +6 -3
- package/esm/foundation/utils/preload_helper.js +122 -32
- package/esm/main.js +4 -4
- package/esm/plugin/component/index.js +36 -29
- package/esm/util/jshield-apdid/apdid-loader.js +340 -0
- package/esm/util/jshield-apdid/index.js +21 -0
- package/esm/util/security-registry.d.ts +72 -0
- package/esm/util/security-registry.js +175 -0
- package/esm/util/security.d.ts +22 -1
- package/esm/util/security.js +150 -39
- package/package.json +1 -1
package/esm/util/security.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { IsecurityConfig, ProductSceneEnum, DeviceIdParameter } from '../types';
|
|
2
|
+
import type { ApdidEnvironment } from './jshield-apdid';
|
|
2
3
|
export declare const getSecurityConfigStorageKey: (scene: ProductSceneEnum) => string;
|
|
3
4
|
export declare enum SecurityRegionEnum {
|
|
4
5
|
SG = "SG",
|
|
@@ -23,10 +24,30 @@ export declare const sceneMap: {
|
|
|
23
24
|
};
|
|
24
25
|
export declare const getSecurityHost: (region: string) => string;
|
|
25
26
|
export declare const getSecurityScene: (product: string) => string;
|
|
27
|
+
/**
|
|
28
|
+
* Map SDK environment string to ApdidEnvironment for CDN URL selection.
|
|
29
|
+
*/
|
|
30
|
+
export declare const mapEnvironment: (env?: string) => ApdidEnvironment;
|
|
26
31
|
export declare class Security {
|
|
27
32
|
scene: string;
|
|
28
33
|
h5gateway: string;
|
|
29
|
-
|
|
34
|
+
private environment?;
|
|
35
|
+
private apdidLoaded;
|
|
36
|
+
private apdidLoadFailed;
|
|
37
|
+
constructor(options: IsecurityConfig & {
|
|
38
|
+
environment?: string;
|
|
39
|
+
});
|
|
40
|
+
/**
|
|
41
|
+
* Ensure the apdid-core script is loaded async.
|
|
42
|
+
* Returns true if loaded successfully, false otherwise.
|
|
43
|
+
* On failure, sets apdidLoadFailed flag for graceful degradation.
|
|
44
|
+
*/
|
|
45
|
+
private ensureApdidLoaded;
|
|
46
|
+
/**
|
|
47
|
+
* Get the APDID module from the loader.
|
|
48
|
+
* Returns undefined if not loaded.
|
|
49
|
+
*/
|
|
50
|
+
private getAPDIDModule;
|
|
30
51
|
initSecurity(successCallback: any, failCallback: any): void;
|
|
31
52
|
private initToken;
|
|
32
53
|
pollingGetApdidToken(config?: DeviceIdParameter): Promise<string>;
|
package/esm/util/security.js
CHANGED
|
@@ -9,7 +9,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
9
9
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
10
10
|
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); }
|
|
11
11
|
import { ProductSceneEnum } from "../types";
|
|
12
|
-
import
|
|
12
|
+
import { ApdidLoader } from "./jshield-apdid";
|
|
13
13
|
export var getSecurityConfigStorageKey = function getSecurityConfigStorageKey(scene) {
|
|
14
14
|
return "AMSSDK_SECURITY_CONFIG_".concat(scene);
|
|
15
15
|
};
|
|
@@ -29,21 +29,110 @@ export var getSecurityHost = function getSecurityHost(region) {
|
|
|
29
29
|
return securityHost[region] || securityHost[SecurityRegionEnum.SG];
|
|
30
30
|
};
|
|
31
31
|
export var getSecurityScene = function getSecurityScene(product) {
|
|
32
|
-
console.log('getSecurityScene', product);
|
|
33
32
|
return sceneMap[product] || '';
|
|
34
33
|
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Map SDK environment string to ApdidEnvironment for CDN URL selection.
|
|
37
|
+
*/
|
|
38
|
+
export var mapEnvironment = function mapEnvironment(env) {
|
|
39
|
+
if (!env) return 'production';
|
|
40
|
+
var lower = env.toLowerCase();
|
|
41
|
+
if (lower === 'pre' || lower === 'light_sandbox') return 'pre';
|
|
42
|
+
if (lower === 'dev' || lower === 'test' || lower === 'local') return 'dev';
|
|
43
|
+
return 'production';
|
|
44
|
+
};
|
|
35
45
|
export var Security = /*#__PURE__*/function () {
|
|
36
46
|
function Security(options) {
|
|
37
47
|
_classCallCheck(this, Security);
|
|
38
48
|
_defineProperty(this, "scene", void 0);
|
|
39
49
|
_defineProperty(this, "h5gateway", void 0);
|
|
50
|
+
_defineProperty(this, "environment", void 0);
|
|
51
|
+
_defineProperty(this, "apdidLoaded", false);
|
|
52
|
+
_defineProperty(this, "apdidLoadFailed", false);
|
|
40
53
|
this.scene = options.scene;
|
|
41
54
|
this.h5gateway = options.h5gateway || securityHost[SecurityRegionEnum.SG];
|
|
55
|
+
this.environment = options.environment;
|
|
42
56
|
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Ensure the apdid-core script is loaded async.
|
|
60
|
+
* Returns true if loaded successfully, false otherwise.
|
|
61
|
+
* On failure, sets apdidLoadFailed flag for graceful degradation.
|
|
62
|
+
*/
|
|
43
63
|
_createClass(Security, [{
|
|
64
|
+
key: "ensureApdidLoaded",
|
|
65
|
+
value: (function () {
|
|
66
|
+
var _ensureApdidLoaded = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
67
|
+
var loader, apdidEnv;
|
|
68
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
69
|
+
while (1) switch (_context.prev = _context.next) {
|
|
70
|
+
case 0:
|
|
71
|
+
if (!this.apdidLoaded) {
|
|
72
|
+
_context.next = 2;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
return _context.abrupt("return", true);
|
|
76
|
+
case 2:
|
|
77
|
+
if (!this.apdidLoadFailed) {
|
|
78
|
+
_context.next = 4;
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
return _context.abrupt("return", false);
|
|
82
|
+
case 4:
|
|
83
|
+
loader = ApdidLoader.getInstance();
|
|
84
|
+
apdidEnv = mapEnvironment(this.environment);
|
|
85
|
+
_context.prev = 6;
|
|
86
|
+
_context.next = 9;
|
|
87
|
+
return loader.load({
|
|
88
|
+
environment: apdidEnv,
|
|
89
|
+
callbacks: {
|
|
90
|
+
onLoad: function onLoad(duration) {
|
|
91
|
+
console.log("[Security] apdid-core script loaded in ".concat(duration, "ms"));
|
|
92
|
+
},
|
|
93
|
+
onLoadFailed: function onLoadFailed(error) {
|
|
94
|
+
console.error('[Security] apdid-core script load failed:', error.message);
|
|
95
|
+
},
|
|
96
|
+
onLoadTimeout: function onLoadTimeout() {
|
|
97
|
+
console.error('[Security] apdid-core script load timeout');
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
case 9:
|
|
102
|
+
this.apdidLoaded = true;
|
|
103
|
+
return _context.abrupt("return", true);
|
|
104
|
+
case 13:
|
|
105
|
+
_context.prev = 13;
|
|
106
|
+
_context.t0 = _context["catch"](6);
|
|
107
|
+
console.error('[Security] apdid-core load error, degrading:', _context.t0);
|
|
108
|
+
this.apdidLoadFailed = true;
|
|
109
|
+
return _context.abrupt("return", false);
|
|
110
|
+
case 18:
|
|
111
|
+
case "end":
|
|
112
|
+
return _context.stop();
|
|
113
|
+
}
|
|
114
|
+
}, _callee, this, [[6, 13]]);
|
|
115
|
+
}));
|
|
116
|
+
function ensureApdidLoaded() {
|
|
117
|
+
return _ensureApdidLoaded.apply(this, arguments);
|
|
118
|
+
}
|
|
119
|
+
return ensureApdidLoaded;
|
|
120
|
+
}()
|
|
121
|
+
/**
|
|
122
|
+
* Get the APDID module from the loader.
|
|
123
|
+
* Returns undefined if not loaded.
|
|
124
|
+
*/
|
|
125
|
+
)
|
|
126
|
+
}, {
|
|
127
|
+
key: "getAPDIDModule",
|
|
128
|
+
value: function getAPDIDModule() {
|
|
129
|
+
var loader = ApdidLoader.getInstance();
|
|
130
|
+
return loader.getApdidModule();
|
|
131
|
+
}
|
|
132
|
+
}, {
|
|
44
133
|
key: "initSecurity",
|
|
45
134
|
value: function initSecurity(successCallback, failCallback) {
|
|
46
|
-
|
|
135
|
+
var _this = this;
|
|
47
136
|
if (!this.scene) {
|
|
48
137
|
throw new Error('securityConfig parameter error');
|
|
49
138
|
}
|
|
@@ -52,12 +141,23 @@ export var Security = /*#__PURE__*/function () {
|
|
|
52
141
|
console.error(errorMsg);
|
|
53
142
|
throw new Error(errorMsg);
|
|
54
143
|
}
|
|
55
|
-
|
|
144
|
+
|
|
145
|
+
// Async: ensure script is loaded before calling initToken
|
|
146
|
+
this.ensureApdidLoaded().then(function (loaded) {
|
|
147
|
+
if (!loaded) {
|
|
148
|
+
failCallback && failCallback('apdid-core script load failed');
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
_this.initToken(successCallback, failCallback);
|
|
152
|
+
}).catch(function () {
|
|
153
|
+
failCallback && failCallback('apdid-core script load failed');
|
|
154
|
+
});
|
|
56
155
|
}
|
|
57
156
|
}, {
|
|
58
157
|
key: "initToken",
|
|
59
158
|
value: function initToken(successCallback, failCallback) {
|
|
60
159
|
try {
|
|
160
|
+
var APDID = this.getAPDIDModule();
|
|
61
161
|
APDID === null || APDID === void 0 || APDID.initToken(this.scene, {
|
|
62
162
|
host: this.h5gateway
|
|
63
163
|
}, function (success, tokenResult, msg) {
|
|
@@ -66,7 +166,6 @@ export var Security = /*#__PURE__*/function () {
|
|
|
66
166
|
} else {
|
|
67
167
|
failCallback && failCallback(msg);
|
|
68
168
|
}
|
|
69
|
-
console.log('initToken result tokenResult', JSON.stringify(tokenResult), msg);
|
|
70
169
|
});
|
|
71
170
|
} catch (error) {
|
|
72
171
|
failCallback && failCallback(error === null || error === void 0 ? void 0 : error.toString());
|
|
@@ -75,48 +174,48 @@ export var Security = /*#__PURE__*/function () {
|
|
|
75
174
|
}, {
|
|
76
175
|
key: "pollingGetApdidToken",
|
|
77
176
|
value: function () {
|
|
78
|
-
var _pollingGetApdidToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
79
|
-
var
|
|
177
|
+
var _pollingGetApdidToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(config) {
|
|
178
|
+
var _this2 = this;
|
|
80
179
|
var tokenCollectTime, dataPollingInterval, asyncFunc;
|
|
81
|
-
return _regeneratorRuntime().wrap(function
|
|
82
|
-
while (1) switch (
|
|
180
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
181
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
83
182
|
case 0:
|
|
84
183
|
tokenCollectTime = parseInt((config === null || config === void 0 ? void 0 : config.tokenCollectTime) || '0', 10);
|
|
85
184
|
dataPollingInterval = parseInt((config === null || config === void 0 ? void 0 : config.dataPollingInterval) || '500', 10);
|
|
86
185
|
asyncFunc = /*#__PURE__*/function () {
|
|
87
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
186
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(resolve) {
|
|
88
187
|
var deviceId, interval, polling;
|
|
89
|
-
return _regeneratorRuntime().wrap(function
|
|
90
|
-
while (1) switch (
|
|
188
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
189
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
91
190
|
case 0:
|
|
92
|
-
|
|
93
|
-
return
|
|
191
|
+
_context3.next = 2;
|
|
192
|
+
return _this2.getApdidToken();
|
|
94
193
|
case 2:
|
|
95
|
-
deviceId =
|
|
194
|
+
deviceId = _context3.sent;
|
|
96
195
|
if (!deviceId) {
|
|
97
|
-
|
|
196
|
+
_context3.next = 5;
|
|
98
197
|
break;
|
|
99
198
|
}
|
|
100
|
-
return
|
|
199
|
+
return _context3.abrupt("return", resolve(deviceId));
|
|
101
200
|
case 5:
|
|
102
201
|
polling = /*#__PURE__*/function () {
|
|
103
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
104
|
-
return _regeneratorRuntime().wrap(function
|
|
105
|
-
while (1) switch (
|
|
202
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
203
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
204
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
106
205
|
case 0:
|
|
107
|
-
|
|
108
|
-
return
|
|
206
|
+
_context2.next = 2;
|
|
207
|
+
return _this2.getApdidToken();
|
|
109
208
|
case 2:
|
|
110
|
-
deviceId =
|
|
209
|
+
deviceId = _context2.sent;
|
|
111
210
|
if (deviceId) {
|
|
112
211
|
clearInterval(interval);
|
|
113
212
|
resolve(deviceId);
|
|
114
213
|
}
|
|
115
214
|
case 4:
|
|
116
215
|
case "end":
|
|
117
|
-
return
|
|
216
|
+
return _context2.stop();
|
|
118
217
|
}
|
|
119
|
-
},
|
|
218
|
+
}, _callee2);
|
|
120
219
|
}));
|
|
121
220
|
return function polling() {
|
|
122
221
|
return _ref2.apply(this, arguments);
|
|
@@ -129,22 +228,22 @@ export var Security = /*#__PURE__*/function () {
|
|
|
129
228
|
}, tokenCollectTime);
|
|
130
229
|
case 8:
|
|
131
230
|
case "end":
|
|
132
|
-
return
|
|
231
|
+
return _context3.stop();
|
|
133
232
|
}
|
|
134
|
-
},
|
|
233
|
+
}, _callee3);
|
|
135
234
|
}));
|
|
136
235
|
return function asyncFunc(_x2) {
|
|
137
236
|
return _ref.apply(this, arguments);
|
|
138
237
|
};
|
|
139
238
|
}();
|
|
140
|
-
return
|
|
239
|
+
return _context4.abrupt("return", new Promise(function (resolve) {
|
|
141
240
|
asyncFunc(resolve);
|
|
142
241
|
}));
|
|
143
242
|
case 4:
|
|
144
243
|
case "end":
|
|
145
|
-
return
|
|
244
|
+
return _context4.stop();
|
|
146
245
|
}
|
|
147
|
-
},
|
|
246
|
+
}, _callee4);
|
|
148
247
|
}));
|
|
149
248
|
function pollingGetApdidToken(_x) {
|
|
150
249
|
return _pollingGetApdidToken.apply(this, arguments);
|
|
@@ -154,25 +253,37 @@ export var Security = /*#__PURE__*/function () {
|
|
|
154
253
|
}, {
|
|
155
254
|
key: "getApdidToken",
|
|
156
255
|
value: function () {
|
|
157
|
-
var _getApdidToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
158
|
-
var
|
|
159
|
-
|
|
160
|
-
|
|
256
|
+
var _getApdidToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
257
|
+
var _this3 = this;
|
|
258
|
+
var loaded;
|
|
259
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
260
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
161
261
|
case 0:
|
|
162
|
-
|
|
262
|
+
_context5.next = 2;
|
|
263
|
+
return this.ensureApdidLoaded();
|
|
264
|
+
case 2:
|
|
265
|
+
loaded = _context5.sent;
|
|
266
|
+
if (loaded) {
|
|
267
|
+
_context5.next = 5;
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
return _context5.abrupt("return", '');
|
|
271
|
+
case 5:
|
|
272
|
+
return _context5.abrupt("return", new Promise(function (resolve) {
|
|
163
273
|
try {
|
|
164
|
-
|
|
274
|
+
var APDID = _this3.getAPDIDModule();
|
|
275
|
+
APDID === null || APDID === void 0 || APDID.getApdidToken(_this3.scene, function (tokenResult) {
|
|
165
276
|
resolve(tokenResult === null || tokenResult === void 0 ? void 0 : tokenResult.token);
|
|
166
277
|
});
|
|
167
278
|
} catch (error) {
|
|
168
279
|
resolve('');
|
|
169
280
|
}
|
|
170
281
|
}));
|
|
171
|
-
case
|
|
282
|
+
case 6:
|
|
172
283
|
case "end":
|
|
173
|
-
return
|
|
284
|
+
return _context5.stop();
|
|
174
285
|
}
|
|
175
|
-
},
|
|
286
|
+
}, _callee5, this);
|
|
176
287
|
}));
|
|
177
288
|
function getApdidToken() {
|
|
178
289
|
return _getApdidToken.apply(this, arguments);
|