@alipay/ams-checkout 1.12.0 → 1.14.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/core/instance/index.js +2 -1
- package/esm/plugin/component/cashierApp.d.ts +6 -2
- package/esm/plugin/component/cashierApp.js +68 -12
- package/esm/plugin/component/index.js +17 -7
- 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 +7 -0
- package/esm/util/versionCompare.js +22 -0
- package/package.json +1 -1
@@ -58,6 +58,7 @@ var AMSSDK = /*#__PURE__*/function () {
|
|
58
58
|
|
59
59
|
// TODO Consumption data analysis control parameters
|
60
60
|
this.logger = new Logger(LogConfig, ![environmentEnum.prod, environmentEnum.sandbox].includes(options === null || options === void 0 ? void 0 : options.environment));
|
61
|
+
Logger.setInstance(this.logger);
|
61
62
|
this.logger.setMedta({
|
62
63
|
instanceId: this._instanceId
|
63
64
|
});
|
@@ -90,7 +91,7 @@ var AMSSDK = /*#__PURE__*/function () {
|
|
90
91
|
var matchingConfig = config['pl_sec'].find(function (item) {
|
91
92
|
var _item$v, _item$v2, _item$platform;
|
92
93
|
var minVersion = item === null || item === void 0 || (_item$v = item.v) === null || _item$v === void 0 ? void 0 : _item$v.split('|')[0];
|
93
|
-
var maxVersion = (item === null || item === void 0 || (_item$v2 = item.v) === null || _item$v2 === void 0 ? void 0 : _item$v2.split('|')[1]) || '
|
94
|
+
var maxVersion = (item === null || item === void 0 || (_item$v2 = item.v) === null || _item$v2 === void 0 ? void 0 : _item$v2.split('|')[1]) || '999999.9.9';
|
94
95
|
var matchVersion = compareVersion(sdkVersion, minVersion) >= 0 && compareVersion(maxVersion, sdkVersion) >= 0;
|
95
96
|
return ((item === null || item === void 0 || (_item$platform = item.platform) === null || _item$platform === void 0 ? void 0 : _item$platform.includes('Web')) || (item === null || item === void 0 ? void 0 : item.platform) === '') && (item === null || item === void 0 ? void 0 : item.product) === product && (!(item !== null && item !== void 0 && item.v) || matchVersion);
|
96
97
|
});
|
@@ -1,15 +1,18 @@
|
|
1
|
-
import {
|
2
|
-
export declare const getAppPath: (environment: string, appVersion: string, componentSign: componentSignEnum, productSceneVersion: string, extendInfo: string) => any;
|
1
|
+
import { componentSignEnum, Ianalytics, renderDisplayTypeEnum } from '../../types';
|
2
|
+
export declare const getAppPath: (environment: string, appVersion: string, componentSign: componentSignEnum, productScene: string, productSceneVersion: string, extendInfo: string, mid: string) => any;
|
3
3
|
export declare const getAppDomain: (domainParams: {
|
4
4
|
environment: string;
|
5
5
|
appVersion: string;
|
6
6
|
componentSign: componentSignEnum;
|
7
|
+
productScene: string;
|
7
8
|
productSceneVersion: string;
|
8
9
|
extendInfo: string;
|
10
|
+
mid: string;
|
9
11
|
}) => string;
|
10
12
|
export declare const getIframeUrl: (iframeParams: {
|
11
13
|
componentSign: componentSignEnum;
|
12
14
|
analytics?: Ianalytics;
|
15
|
+
productScene: string;
|
13
16
|
productSceneVersion: string;
|
14
17
|
environment: string;
|
15
18
|
appVersion: string;
|
@@ -19,6 +22,7 @@ export declare const getIframeUrl: (iframeParams: {
|
|
19
22
|
renderDisplayType: renderDisplayTypeEnum;
|
20
23
|
isPreload?: string;
|
21
24
|
hostSign?: string;
|
25
|
+
mid: string;
|
22
26
|
}) => {
|
23
27
|
path: string;
|
24
28
|
locationSearch: string;
|
@@ -10,12 +10,40 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
10
10
|
* 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
|
11
11
|
*/
|
12
12
|
import { marmotMap, sdkVersion } from "../../config/index";
|
13
|
-
import { getViewPort, queryParse, serialize } from "../../util/index";
|
14
13
|
import { componentSignEnum } from "../../types";
|
15
|
-
|
14
|
+
import { isDebugLog } from "../../util/debug";
|
15
|
+
import { getViewPort, queryParse, serialize } from "../../util/index";
|
16
|
+
import { Logger } from "../../util/logger";
|
17
|
+
import { getLastAppVersion, getMatchAppVersion, setLastAppVersion } from "../../util/upgrade";
|
18
|
+
var getAppVersion = function getAppVersion(_extendInfo, productScene, mid) {
|
16
19
|
try {
|
17
|
-
var
|
18
|
-
|
20
|
+
var _Logger$getInstance;
|
21
|
+
var appVersion = getMatchAppVersion(_extendInfo, {
|
22
|
+
sdkVersion: sdkVersion,
|
23
|
+
productScene: productScene,
|
24
|
+
mid: mid
|
25
|
+
});
|
26
|
+
// 有sessionData加载时
|
27
|
+
(_Logger$getInstance = Logger.getInstance()) === null || _Logger$getInstance === void 0 || _Logger$getInstance.logInfo({
|
28
|
+
title: 'sdk_event_appUpgradeInfo'
|
29
|
+
}, {
|
30
|
+
appUpgradeVersion: appVersion,
|
31
|
+
appUpgraded: appVersion ? true : false,
|
32
|
+
isPreload: _extendInfo ? false : true,
|
33
|
+
extendInfo: _extendInfo,
|
34
|
+
productScene: productScene,
|
35
|
+
mid: mid
|
36
|
+
});
|
37
|
+
// 没有匹配到版本,查询上次的加载版本
|
38
|
+
if (!appVersion) {
|
39
|
+
appVersion = getLastAppVersion(productScene);
|
40
|
+
return appVersion;
|
41
|
+
}
|
42
|
+
// 不为空时代表是有sessionData,因此要保存当前版本
|
43
|
+
if (_extendInfo) {
|
44
|
+
setLastAppVersion(productScene, appVersion);
|
45
|
+
}
|
46
|
+
return appVersion;
|
19
47
|
} catch (error) {
|
20
48
|
return '';
|
21
49
|
}
|
@@ -34,13 +62,26 @@ export var getAppPath = function getAppPath() {
|
|
34
62
|
var environment = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'prod';
|
35
63
|
var appVersion = arguments.length > 1 ? arguments[1] : undefined;
|
36
64
|
var componentSign = arguments.length > 2 ? arguments[2] : undefined;
|
37
|
-
var
|
38
|
-
var
|
65
|
+
var productScene = arguments.length > 3 ? arguments[3] : undefined;
|
66
|
+
var productSceneVersion = arguments.length > 4 ? arguments[4] : undefined;
|
67
|
+
var extendInfo = arguments.length > 5 ? arguments[5] : undefined;
|
68
|
+
var mid = arguments.length > 6 ? arguments[6] : undefined;
|
39
69
|
var _ref = queryParse() || {},
|
40
70
|
urlTestHost = _ref.host;
|
41
|
-
var
|
71
|
+
var upgradeAppVersion = getAppVersion(extendInfo, productScene, mid);
|
72
|
+
var finalAppVersion = upgradeAppVersion || appVersion;
|
73
|
+
// 当有升级版本时,更新到全局字段
|
74
|
+
if (upgradeAppVersion) {
|
75
|
+
var _Logger$getInstance2;
|
76
|
+
(_Logger$getInstance2 = Logger.getInstance()) === null || _Logger$getInstance2 === void 0 || _Logger$getInstance2.setMedta({
|
77
|
+
webAppVersion: finalAppVersion
|
78
|
+
});
|
79
|
+
}
|
80
|
+
if (isDebugLog()) {
|
81
|
+
console.log('appUpgrade#getAppPath#finalAppVersion', finalAppVersion);
|
82
|
+
console.log('appUpgrade#getAppPath#extendInfo', extendInfo, mid);
|
83
|
+
}
|
42
84
|
var finalProductSceneVersion = getFinalProductSceneVersion(componentSign, productSceneVersion);
|
43
|
-
|
44
85
|
// only for test while testurl?host=https://xxxxx.test.html
|
45
86
|
if (urlTestHost && !['sandbox', 'light_sandbox', 'prod'].includes(environment)) {
|
46
87
|
return urlTestHost;
|
@@ -51,10 +92,12 @@ export var getAppDomain = function getAppDomain(domainParams) {
|
|
51
92
|
var environment = domainParams.environment,
|
52
93
|
appVersion = domainParams.appVersion,
|
53
94
|
componentSign = domainParams.componentSign,
|
95
|
+
productScene = domainParams.productScene,
|
54
96
|
productSceneVersion = domainParams.productSceneVersion,
|
55
|
-
extendInfo = domainParams.extendInfo
|
97
|
+
extendInfo = domainParams.extendInfo,
|
98
|
+
mid = domainParams.mid;
|
56
99
|
var reg = /^https?:\/\/([^/<>\s]+\.?)*/;
|
57
|
-
var macth = reg.exec(getAppPath(environment, appVersion, componentSign, productSceneVersion, extendInfo));
|
100
|
+
var macth = reg.exec(getAppPath(environment, appVersion, componentSign, productScene, productSceneVersion, extendInfo, mid));
|
58
101
|
return macth && macth[0] || '';
|
59
102
|
};
|
60
103
|
export var getIframeUrl = function getIframeUrl(iframeParams) {
|
@@ -63,6 +106,7 @@ export var getIframeUrl = function getIframeUrl(iframeParams) {
|
|
63
106
|
analytics = _iframeParams$analyti === void 0 ? {
|
64
107
|
enabled: true
|
65
108
|
} : _iframeParams$analyti,
|
109
|
+
productScene = iframeParams.productScene,
|
66
110
|
productSceneVersion = iframeParams.productSceneVersion,
|
67
111
|
environment = iframeParams.environment,
|
68
112
|
appVersion = iframeParams.appVersion,
|
@@ -73,8 +117,15 @@ export var getIframeUrl = function getIframeUrl(iframeParams) {
|
|
73
117
|
_iframeParams$isPrelo = iframeParams.isPreload,
|
74
118
|
isPreload = _iframeParams$isPrelo === void 0 ? '' : _iframeParams$isPrelo,
|
75
119
|
_iframeParams$hostSig = iframeParams.hostSign,
|
76
|
-
hostSign = _iframeParams$hostSig === void 0 ? '' : _iframeParams$hostSig
|
77
|
-
|
120
|
+
hostSign = _iframeParams$hostSig === void 0 ? '' : _iframeParams$hostSig,
|
121
|
+
_iframeParams$mid = iframeParams.mid,
|
122
|
+
mid = _iframeParams$mid === void 0 ? '' : _iframeParams$mid;
|
123
|
+
var path = getAppPath(environment, appVersion, componentSign, productScene, productSceneVersion, extendInfo || '', mid);
|
124
|
+
var appMatched = getMatchAppVersion(extendInfo, {
|
125
|
+
sdkVersion: sdkVersion,
|
126
|
+
productScene: productScene,
|
127
|
+
mid: mid
|
128
|
+
}) ? 'true' : 'false';
|
78
129
|
var initialScale = 1;
|
79
130
|
var scale = getViewPort('initial-scale') || initialScale;
|
80
131
|
var _queryParse = queryParse(),
|
@@ -91,6 +142,7 @@ export var getIframeUrl = function getIframeUrl(iframeParams) {
|
|
91
142
|
locale: locale,
|
92
143
|
scale: scale,
|
93
144
|
instanceId: instanceId,
|
145
|
+
appMatched: appMatched,
|
94
146
|
analyticsEnabled: (analytics === null || analytics === void 0 ? void 0 : analytics.enabled) === false ? 'false' : 'true',
|
95
147
|
sdkVersion: sdkVersion,
|
96
148
|
refUrl: window.location.href,
|
@@ -106,6 +158,10 @@ export var getIframeUrl = function getIframeUrl(iframeParams) {
|
|
106
158
|
if (_displayType) urlParams.displayType = _displayType;
|
107
159
|
if (isPreload) urlParams.isPreload = isPreload;
|
108
160
|
var locationSearch = serialize(urlParams);
|
161
|
+
if (isDebugLog()) {
|
162
|
+
console.log('appUpgrade#getIframeUrl#appMatched', appMatched);
|
163
|
+
console.log('appUpgrade#getIframeUrl#url', path, locationSearch);
|
164
|
+
}
|
109
165
|
return {
|
110
166
|
path: path,
|
111
167
|
locationSearch: locationSearch
|
@@ -17,6 +17,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
17
17
|
* 2. If applicable, the use of the Software is also subject to the terms and conditions of any non-disclosure agreement signed by you and the relevant Ant Group entity.
|
18
18
|
*/
|
19
19
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
20
|
+
import { sdkVersion } from "../../config";
|
20
21
|
import { COMPONENTPLUGINID, COMPONENT_CLOSE_BLOCK_ID, COMPONENT_CONTAINER_ID, COMPONENT_RETENTION_ID, COMPONENT_SECTION_ID, ERRORMESSAGE, EVENT, LISTENER_PREFIX, LOADING_ID, LOADTIME_LIMIT, MOCKUP_ID, POPUP_LOADTIME_LOG_LIMIT, TIMEOUT_WEB_APP_HEART_BEAT, TIME_DELAY_SEND_HEART_BEAT } from "../../constant";
|
21
22
|
import { queryPaymentInfo, submitPayInfo } from "../../service";
|
22
23
|
import { componentSignEnum, eventCodeEnum, messageName, platformEnum, productSceneEnum, RedirectType, renderDisplayTypeEnum, targetEnum } from "../../types";
|
@@ -54,7 +55,7 @@ var ComponentApp = /*#__PURE__*/function () {
|
|
54
55
|
_defineProperty(this, "_multipleCallbackEvents", void 0);
|
55
56
|
_defineProperty(this, "_merchantAppointParam", void 0);
|
56
57
|
_defineProperty(this, "_webAppHeartBeatTimeoutFn", void 0);
|
57
|
-
this._appVersion = '1.
|
58
|
+
this._appVersion = '1.13.0';
|
58
59
|
this._isInitComponent = false;
|
59
60
|
this._selector = "#".concat(COMPONENT_SECTION_ID);
|
60
61
|
this.createIframeNode = function () {
|
@@ -100,7 +101,8 @@ var ComponentApp = /*#__PURE__*/function () {
|
|
100
101
|
this.AMSSDK.logger.setMedta({
|
101
102
|
platform: this.platform === platformEnum.desktop ? 'PC' : 'WAP',
|
102
103
|
// PC/WAP,
|
103
|
-
sdkVersion:
|
104
|
+
sdkVersion: sdkVersion,
|
105
|
+
webAppVersion: this._appVersion,
|
104
106
|
instanceId: this.AMSSDK._instanceId,
|
105
107
|
storageId: this.AMSSDK._storageId,
|
106
108
|
// the better way to use md5 paymentSesionID
|
@@ -691,6 +693,7 @@ var ComponentApp = /*#__PURE__*/function () {
|
|
691
693
|
analytics: {
|
692
694
|
enabled: false
|
693
695
|
},
|
696
|
+
productScene: componentSign,
|
694
697
|
productSceneVersion: productSceneVersion,
|
695
698
|
environment: this.AMSSDK.options.env.environment,
|
696
699
|
// TODO 确定一下这个参数是干啥的
|
@@ -698,7 +701,8 @@ var ComponentApp = /*#__PURE__*/function () {
|
|
698
701
|
extendInfo: '',
|
699
702
|
locale: '',
|
700
703
|
instanceId: '',
|
701
|
-
isPreload: 'true'
|
704
|
+
isPreload: 'true',
|
705
|
+
mid: ''
|
702
706
|
}),
|
703
707
|
path = _getIframeUrl.path,
|
704
708
|
locationSearch = _getIframeUrl.locationSearch;
|
@@ -728,16 +732,20 @@ var ComponentApp = /*#__PURE__*/function () {
|
|
728
732
|
value: Date.now()
|
729
733
|
});
|
730
734
|
try {
|
731
|
-
var _renderParams$payment, _renderParams$payment2;
|
735
|
+
var _renderParams$payment, _renderParams$payment2, _renderParams$payment3, _renderParams$payment4;
|
732
736
|
var productSceneVersion = (renderParams === null || renderParams === void 0 || (_renderParams$payment = renderParams.paymentSessionMetaData) === null || _renderParams$payment === void 0 || (_renderParams$payment = _renderParams$payment.paymentSessionConfig) === null || _renderParams$payment === void 0 ? void 0 : _renderParams$payment.productSceneVersion) || '';
|
733
|
-
var
|
737
|
+
var productScene = (renderParams === null || renderParams === void 0 || (_renderParams$payment2 = renderParams.paymentSessionMetaData) === null || _renderParams$payment2 === void 0 || (_renderParams$payment2 = _renderParams$payment2.paymentSessionConfig) === null || _renderParams$payment2 === void 0 ? void 0 : _renderParams$payment2.productScene) || '';
|
738
|
+
var extendInfo = (renderParams === null || renderParams === void 0 || (_renderParams$payment3 = renderParams.paymentSessionMetaData) === null || _renderParams$payment3 === void 0 ? void 0 : _renderParams$payment3.extendInfo) || '';
|
739
|
+
var mid = renderParams === null || renderParams === void 0 || (_renderParams$payment4 = renderParams.paymentSessionMetaData) === null || _renderParams$payment4 === void 0 ? void 0 : _renderParams$payment4.clientId;
|
734
740
|
var environment = this.AMSSDK.options.env.environment;
|
735
741
|
this.appDomain = getAppDomain({
|
736
742
|
environment: environment,
|
737
743
|
appVersion: this._appVersion,
|
738
744
|
componentSign: this._componentSign,
|
745
|
+
productScene: productScene,
|
739
746
|
productSceneVersion: productSceneVersion,
|
740
|
-
extendInfo: extendInfo
|
747
|
+
extendInfo: extendInfo,
|
748
|
+
mid: mid
|
741
749
|
});
|
742
750
|
this.app = createIframe(this.AMSSDK.options.mode, this.platform);
|
743
751
|
var hostSign = ((renderParams === null || renderParams === void 0 ? void 0 : renderParams.sessionData) || '').split('&&')[1] || '';
|
@@ -745,13 +753,15 @@ var ComponentApp = /*#__PURE__*/function () {
|
|
745
753
|
renderDisplayType: renderParams.renderDisplayType,
|
746
754
|
componentSign: this._componentSign,
|
747
755
|
analytics: this.AMSSDK.options.analytics,
|
756
|
+
productScene: productScene,
|
748
757
|
productSceneVersion: productSceneVersion,
|
749
758
|
environment: environment,
|
750
759
|
appVersion: this._appVersion,
|
751
760
|
extendInfo: extendInfo,
|
752
761
|
locale: this.AMSSDK.options.locale,
|
753
762
|
instanceId: this.AMSSDK._instanceId,
|
754
|
-
hostSign: hostSign
|
763
|
+
hostSign: hostSign,
|
764
|
+
mid: mid
|
755
765
|
}),
|
756
766
|
path = _getIframeUrl2.path,
|
757
767
|
locationSearch = _getIframeUrl2.locationSearch;
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const isDebugLog: () => boolean;
|
package/esm/util/logger.d.ts
CHANGED
@@ -12,6 +12,7 @@ type Extra = Record<string, any>;
|
|
12
12
|
export interface LogMetaData {
|
13
13
|
platform?: string;
|
14
14
|
sdkVersion?: string;
|
15
|
+
webAppVersion?: string;
|
15
16
|
fistLogTime?: number;
|
16
17
|
fsDuration?: number;
|
17
18
|
instanceId?: string;
|
@@ -42,8 +43,11 @@ export declare class Logger {
|
|
42
43
|
private debug;
|
43
44
|
private componentStartTime;
|
44
45
|
private isLoaded;
|
46
|
+
private static instance;
|
45
47
|
private trackId;
|
46
48
|
constructor(config: Config, debug: boolean);
|
49
|
+
static setInstance(instance: Logger): Logger;
|
50
|
+
static getInstance(): Logger;
|
47
51
|
setMedta(mdata: LogMetaData): void;
|
48
52
|
logError(error: LogPayload, extra?: Extra): Logger;
|
49
53
|
logInfo(info: LogPayload, extra?: Extra): Logger;
|
package/esm/util/logger.js
CHANGED
@@ -186,9 +186,20 @@ export var Logger = /*#__PURE__*/function () {
|
|
186
186
|
value: function getComponentStartTime() {
|
187
187
|
return this.componentStartTime;
|
188
188
|
}
|
189
|
+
}], [{
|
190
|
+
key: "setInstance",
|
191
|
+
value: function setInstance(instance) {
|
192
|
+
return this.instance = instance;
|
193
|
+
}
|
194
|
+
}, {
|
195
|
+
key: "getInstance",
|
196
|
+
value: function getInstance() {
|
197
|
+
return this.instance;
|
198
|
+
}
|
189
199
|
}]);
|
190
200
|
return Logger;
|
191
201
|
}();
|
202
|
+
_defineProperty(Logger, "instance", void 0);
|
192
203
|
export var LogConfig = {
|
193
204
|
scriptUrl: 'https://gw.alipayobjects.com/render/p/yuyan_npm/@alipay_intl-tracker/1.6.0/dist/common.min.js',
|
194
205
|
spmConfig: {},
|
@@ -0,0 +1,23 @@
|
|
1
|
+
export var getStorageString = function getStorageString(key) {
|
2
|
+
var fallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
3
|
+
try {
|
4
|
+
if (key && window) {
|
5
|
+
var storageValue = window.localStorage.getItem(key);
|
6
|
+
if (storageValue) {
|
7
|
+
return storageValue;
|
8
|
+
}
|
9
|
+
return fallback;
|
10
|
+
}
|
11
|
+
} catch (error) {
|
12
|
+
return fallback;
|
13
|
+
}
|
14
|
+
};
|
15
|
+
export var setStorageString = function setStorageString(key, value) {
|
16
|
+
try {
|
17
|
+
if (key && window) {
|
18
|
+
window.localStorage.setItem(key, value);
|
19
|
+
return true;
|
20
|
+
}
|
21
|
+
} catch (error) {}
|
22
|
+
return false;
|
23
|
+
};
|
@@ -0,0 +1,39 @@
|
|
1
|
+
export declare function isWebPlatform(platform?: string): boolean;
|
2
|
+
export interface UpgradeItem {
|
3
|
+
productScene?: string;
|
4
|
+
v: string;
|
5
|
+
appVersion: string;
|
6
|
+
platform?: string;
|
7
|
+
mid?: string;
|
8
|
+
greyscale?: string;
|
9
|
+
}
|
10
|
+
export interface UpgradeSdkInfo {
|
11
|
+
productScene?: string;
|
12
|
+
sdkVersion: string;
|
13
|
+
appVersion?: string;
|
14
|
+
greyscale?: number;
|
15
|
+
mid?: string;
|
16
|
+
}
|
17
|
+
export declare function findUpgradeVersion(upgradeItems: UpgradeItem[], sdkInfo: UpgradeSdkInfo): string;
|
18
|
+
export declare const getGrascaleId: (key?: string) => string;
|
19
|
+
export declare function getGrayscaleValue(seed?: string): number;
|
20
|
+
export declare function isGreyscaleMatch(item: UpgradeItem, randomGreyscale: number): boolean;
|
21
|
+
/**
|
22
|
+
* 查询匹配到的版本
|
23
|
+
* @param _extendInfo
|
24
|
+
* @param param1
|
25
|
+
* @returns
|
26
|
+
*/
|
27
|
+
export declare const getMatchAppVersion: (_extendInfo: string, sdkInfo: UpgradeSdkInfo) => string;
|
28
|
+
/**
|
29
|
+
* 获取保存的加载版本
|
30
|
+
* @param productScene
|
31
|
+
* @returns
|
32
|
+
*/
|
33
|
+
export declare const getLastAppVersion: (productScene: string) => string;
|
34
|
+
/**
|
35
|
+
* 保存指定场景的加载版本供下次使用
|
36
|
+
* @param productScene
|
37
|
+
* @returns
|
38
|
+
*/
|
39
|
+
export declare const setLastAppVersion: (productScene: string, appVersion: string) => boolean;
|
@@ -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,5 +4,12 @@
|
|
4
4
|
* @param v2
|
5
5
|
*/
|
6
6
|
export declare function compareVersion(v1: string, v2: string): 0 | 1 | -1;
|
7
|
+
/**
|
8
|
+
* 判断version版本是否在range参数版本的范围内
|
9
|
+
* @param version
|
10
|
+
* @param range
|
11
|
+
* @returns
|
12
|
+
*/
|
13
|
+
export declare function isVersionInStringRange(version: string, range: string): boolean;
|
7
14
|
export declare function isVersionInRange(currentVersion: any, minVersion: any, maxVersion: any): boolean;
|
8
15
|
export declare function matchVersion(config: any, currentVersion: any): boolean;
|
@@ -49,6 +49,28 @@ export function compareVersion(v1, v2) {
|
|
49
49
|
return 1;
|
50
50
|
}
|
51
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
|
+
}
|
52
74
|
export function isVersionInRange(currentVersion, minVersion, maxVersion) {
|
53
75
|
function splitVersion(version) {
|
54
76
|
return version.split('.').map(function (num) {
|