@alipay/ams-checkout 0.0.1713146800-dev.0 → 0.0.1713838058-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.
- package/dist/umd/ams-checkout.min.js +1 -1
- package/esm/config/request.js +3 -3
- package/esm/core/component/index.d.ts +1 -0
- package/esm/core/component/index.js +4 -2
- package/esm/core/instance/index.js +6 -4
- package/esm/plugin/component/cashierApp.d.ts +6 -2
- package/esm/plugin/component/cashierApp.js +68 -12
- package/esm/plugin/component/component.popup.style.js +1 -1
- package/esm/plugin/component/index.d.ts +1 -2
- package/esm/plugin/component/index.js +97 -55
- package/esm/request/index.js +8 -14
- package/esm/types/index.d.ts +5 -0
- package/esm/util/debug.d.ts +1 -0
- package/esm/util/debug.js +9 -0
- package/esm/util/logger.d.ts +4 -0
- package/esm/util/logger.js +11 -0
- package/esm/util/storage.d.ts +2 -0
- package/esm/util/storage.js +23 -0
- package/esm/util/upgrade.d.ts +39 -0
- package/esm/util/upgrade.js +115 -0
- package/esm/util/versionCompare.d.ts +9 -0
- package/esm/util/versionCompare.js +97 -0
- package/package.json +1 -1
@@ -0,0 +1,115 @@
|
|
1
|
+
import { v4 as uuid } from 'uuid';
|
2
|
+
import { getStorageString, setStorageString } from "./storage";
|
3
|
+
import { compareVersion, isVersionInStringRange } from "./versionCompare";
|
4
|
+
export function isWebPlatform(platform) {
|
5
|
+
if (platform) {
|
6
|
+
return platform.toUpperCase().includes('Web'.toUpperCase()) || platform === '';
|
7
|
+
}
|
8
|
+
return true;
|
9
|
+
}
|
10
|
+
export function findUpgradeVersion(upgradeItems, sdkInfo) {
|
11
|
+
var sortedItems = upgradeItems.sort(function (a, b) {
|
12
|
+
return compareVersion(b.appVersion, a.appVersion);
|
13
|
+
});
|
14
|
+
// console.log("sortedItems",sortedItems)
|
15
|
+
var upgradeItem = sortedItems.find(function (item) {
|
16
|
+
if (isVersionInStringRange(sdkInfo.sdkVersion, item.v) && isWebPlatform(item.platform)) {
|
17
|
+
var _item$productScene, _sdkInfo$productScene, _item$mid, _sdkInfo$mid, _sdkInfo$greyscale;
|
18
|
+
var matchProductScene = (_item$productScene = item.productScene) !== null && _item$productScene !== void 0 && _item$productScene.trim() ? item.productScene.toUpperCase().includes(sdkInfo === null || sdkInfo === void 0 || (_sdkInfo$productScene = sdkInfo.productScene) === null || _sdkInfo$productScene === void 0 ? void 0 : _sdkInfo$productScene.toUpperCase()) : true;
|
19
|
+
var matchMid = (_item$mid = item.mid) !== null && _item$mid !== void 0 && _item$mid.trim() ? item.mid.toUpperCase().includes(sdkInfo === null || sdkInfo === void 0 || (_sdkInfo$mid = sdkInfo.mid) === null || _sdkInfo$mid === void 0 ? void 0 : _sdkInfo$mid.toUpperCase()) : true;
|
20
|
+
var matchGreyscale = isGreyscaleMatch(item, (_sdkInfo$greyscale = sdkInfo.greyscale) !== null && _sdkInfo$greyscale !== void 0 ? _sdkInfo$greyscale : getGrayscaleValue());
|
21
|
+
if (matchProductScene && matchMid && matchGreyscale) {
|
22
|
+
return item;
|
23
|
+
}
|
24
|
+
}
|
25
|
+
});
|
26
|
+
return (upgradeItem === null || upgradeItem === void 0 ? void 0 : upgradeItem.appVersion) || null;
|
27
|
+
}
|
28
|
+
export var getGrascaleId = function getGrascaleId() {
|
29
|
+
var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'AntomDefaultGrascaleId';
|
30
|
+
try {
|
31
|
+
if (key && window) {
|
32
|
+
var storageValue = getStorageString(key, '');
|
33
|
+
if (storageValue) {
|
34
|
+
return storageValue;
|
35
|
+
}
|
36
|
+
var grascaleId = uuid();
|
37
|
+
if (key && grascaleId) {
|
38
|
+
setStorageString(key, grascaleId);
|
39
|
+
}
|
40
|
+
}
|
41
|
+
} catch (error) {
|
42
|
+
return '';
|
43
|
+
}
|
44
|
+
};
|
45
|
+
export function getGrayscaleValue() {
|
46
|
+
var seed = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getGrascaleId();
|
47
|
+
if (!seed) {
|
48
|
+
return 0;
|
49
|
+
}
|
50
|
+
// 取倒数2、3位
|
51
|
+
var sub = seed.substring(seed.length - 3, seed.length - 1);
|
52
|
+
// 将16进制转成10进制值
|
53
|
+
var decimal = parseInt(sub, 16);
|
54
|
+
var finalValue = Math.floor(decimal * 100 / 255);
|
55
|
+
return finalValue;
|
56
|
+
}
|
57
|
+
export function isGreyscaleMatch(item, randomGreyscale) {
|
58
|
+
if (!(item !== null && item !== void 0 && item.greyscale)) {
|
59
|
+
return true;
|
60
|
+
}
|
61
|
+
try {
|
62
|
+
var greyscale = parseInt(item === null || item === void 0 ? void 0 : item.greyscale);
|
63
|
+
if (greyscale === 0) {
|
64
|
+
return false;
|
65
|
+
}
|
66
|
+
return greyscale >= randomGreyscale;
|
67
|
+
} catch (error) {
|
68
|
+
return false;
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
/**
|
73
|
+
* 查询匹配到的版本
|
74
|
+
* @param _extendInfo
|
75
|
+
* @param param1
|
76
|
+
* @returns
|
77
|
+
*/
|
78
|
+
export var getMatchAppVersion = function getMatchAppVersion(_extendInfo, sdkInfo) {
|
79
|
+
try {
|
80
|
+
var _info$sdkUpgradeInfo;
|
81
|
+
var info = JSON.parse(_extendInfo);
|
82
|
+
var versions = info === null || info === void 0 || (_info$sdkUpgradeInfo = info.sdkUpgradeInfo) === null || _info$sdkUpgradeInfo === void 0 ? void 0 : _info$sdkUpgradeInfo.versions;
|
83
|
+
var appVersion = findUpgradeVersion(versions, sdkInfo);
|
84
|
+
return appVersion;
|
85
|
+
} catch (error) {
|
86
|
+
return '';
|
87
|
+
}
|
88
|
+
};
|
89
|
+
|
90
|
+
/**
|
91
|
+
* 获取保存的加载版本
|
92
|
+
* @param productScene
|
93
|
+
* @returns
|
94
|
+
*/
|
95
|
+
export var getLastAppVersion = function getLastAppVersion(productScene) {
|
96
|
+
try {
|
97
|
+
var key = "Antom_".concat(productScene, "_LastAppVersion");
|
98
|
+
return getStorageString(key, '');
|
99
|
+
} catch (error) {
|
100
|
+
return '';
|
101
|
+
}
|
102
|
+
};
|
103
|
+
/**
|
104
|
+
* 保存指定场景的加载版本供下次使用
|
105
|
+
* @param productScene
|
106
|
+
* @returns
|
107
|
+
*/
|
108
|
+
export var setLastAppVersion = function setLastAppVersion(productScene, appVersion) {
|
109
|
+
try {
|
110
|
+
var key = "Antom_".concat(productScene, "_LastAppVersion");
|
111
|
+
return setStorageString(key, appVersion);
|
112
|
+
} catch (error) {
|
113
|
+
return false;
|
114
|
+
}
|
115
|
+
};
|
@@ -4,3 +4,12 @@
|
|
4
4
|
* @param v2
|
5
5
|
*/
|
6
6
|
export declare function compareVersion(v1: string, v2: string): 1 | 0 | -1;
|
7
|
+
/**
|
8
|
+
* 判断version版本是否在range参数版本的范围内
|
9
|
+
* @param version
|
10
|
+
* @param range
|
11
|
+
* @returns
|
12
|
+
*/
|
13
|
+
export declare function isVersionInStringRange(version: string, range: string): boolean;
|
14
|
+
export declare function isVersionInRange(currentVersion: any, minVersion: any, maxVersion: any): boolean;
|
15
|
+
export declare function matchVersion(config: any, currentVersion: any): boolean;
|
@@ -1,3 +1,9 @@
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
2
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
4
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
5
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
1
7
|
/**
|
2
8
|
* 返回值0标识一样大,1表示v1大,-1表示v2大
|
3
9
|
* @param v1
|
@@ -42,4 +48,95 @@ export function compareVersion(v1, v2) {
|
|
42
48
|
} else {
|
43
49
|
return 1;
|
44
50
|
}
|
51
|
+
}
|
52
|
+
/**
|
53
|
+
* 判断version版本是否在range参数版本的范围内
|
54
|
+
* @param version
|
55
|
+
* @param range
|
56
|
+
* @returns
|
57
|
+
*/
|
58
|
+
export function isVersionInStringRange(version, range) {
|
59
|
+
if (!range) {
|
60
|
+
// 未指定版本限制
|
61
|
+
return true;
|
62
|
+
}
|
63
|
+
if (range.includes(',')) {
|
64
|
+
return range.split(',').includes(version);
|
65
|
+
}
|
66
|
+
if (!range.includes('|')) {
|
67
|
+
return version === range;
|
68
|
+
}
|
69
|
+
var minVersion = range.split('|')[0];
|
70
|
+
var maxVersion = range.split('|')[1] || '999999.9.9';
|
71
|
+
var matchVersion = compareVersion(version, minVersion) >= 0 && compareVersion(maxVersion, version) >= 0;
|
72
|
+
return matchVersion;
|
73
|
+
}
|
74
|
+
export function isVersionInRange(currentVersion, minVersion, maxVersion) {
|
75
|
+
function splitVersion(version) {
|
76
|
+
return version.split('.').map(function (num) {
|
77
|
+
return parseInt(num, 10);
|
78
|
+
});
|
79
|
+
}
|
80
|
+
function compareVersions(v1, v2) {
|
81
|
+
for (var i = 0; i < Math.max(v1.length, v2.length); i++) {
|
82
|
+
var num1 = v1[i] === undefined ? 0 : v1[i];
|
83
|
+
var num2 = v2[i] === undefined ? 0 : v2[i];
|
84
|
+
if (num1 > num2) return 1;
|
85
|
+
if (num1 < num2) return -1;
|
86
|
+
}
|
87
|
+
return 0;
|
88
|
+
}
|
89
|
+
var current = splitVersion(currentVersion);
|
90
|
+
var min = minVersion ? splitVersion(minVersion) : null;
|
91
|
+
var max = maxVersion ? splitVersion(maxVersion) : null;
|
92
|
+
if (min && compareVersions(current, min) < 0) {
|
93
|
+
// 当前版本小于最小允许版本
|
94
|
+
return false;
|
95
|
+
}
|
96
|
+
if (max && compareVersions(current, max) > 0) {
|
97
|
+
// 当前版本大于最大允许版本
|
98
|
+
return false;
|
99
|
+
}
|
100
|
+
// 当前版本在允许的版本范围内
|
101
|
+
return true;
|
102
|
+
}
|
103
|
+
export function matchVersion(config, currentVersion) {
|
104
|
+
var value = config.value,
|
105
|
+
version = config.version,
|
106
|
+
platform = config.platform;
|
107
|
+
var CURRENT_PLATFORM = 'WEB';
|
108
|
+
var isMatchVersion = false;
|
109
|
+
var isMatchPlatform = false;
|
110
|
+
|
111
|
+
// 平台判断
|
112
|
+
if (platform) {
|
113
|
+
var platformList = platform.split('|').map(function (platform) {
|
114
|
+
return platform.toLocaleUpperCase();
|
115
|
+
});
|
116
|
+
isMatchPlatform = platformList.includes(CURRENT_PLATFORM);
|
117
|
+
} else {
|
118
|
+
// 没有表示平台全匹配
|
119
|
+
isMatchPlatform = true;
|
120
|
+
}
|
121
|
+
// 版本判断
|
122
|
+
if (!version) {
|
123
|
+
// 为空全匹配
|
124
|
+
isMatchVersion = true;
|
125
|
+
} else if (version.indexOf('|') !== -1) {
|
126
|
+
// | 范围匹配
|
127
|
+
var _version$split = version.split('|'),
|
128
|
+
_version$split2 = _slicedToArray(_version$split, 2),
|
129
|
+
_version$split2$ = _version$split2[0],
|
130
|
+
minVersion = _version$split2$ === void 0 ? '' : _version$split2$,
|
131
|
+
_version$split2$2 = _version$split2[1],
|
132
|
+
maxVersion = _version$split2$2 === void 0 ? '' : _version$split2$2;
|
133
|
+
isMatchVersion = isVersionInRange(currentVersion, minVersion, maxVersion);
|
134
|
+
} else if (version.indexOf(',') !== -1) {
|
135
|
+
// , 枚举匹配
|
136
|
+
var versionList = version.split(',');
|
137
|
+
isMatchVersion = versionList.includes(currentVersion);
|
138
|
+
} else {
|
139
|
+
isMatchVersion = version === currentVersion;
|
140
|
+
}
|
141
|
+
return value && isMatchPlatform && isMatchVersion;
|
45
142
|
}
|