@alipay/ams-checkout 0.0.1712728793-dev.1 → 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/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
@@ -57,6 +57,7 @@ var AMSSDK = /*#__PURE__*/function () {
|
|
57
57
|
|
58
58
|
// TODO Consumption data analysis control parameters
|
59
59
|
this.logger = new Logger(LogConfig, ![environmentEnum.prod, environmentEnum.sandbox].includes(options === null || options === void 0 ? void 0 : options.environment));
|
60
|
+
Logger.setInstance(this.logger);
|
60
61
|
this.logger.setMedta({
|
61
62
|
instanceId: this._instanceId
|
62
63
|
});
|
@@ -87,7 +88,7 @@ var AMSSDK = /*#__PURE__*/function () {
|
|
87
88
|
var matchingConfig = config['pl_sec'].find(function (item) {
|
88
89
|
var _item$v, _item$v2, _item$platform;
|
89
90
|
var minVersion = item === null || item === void 0 || (_item$v = item.v) === null || _item$v === void 0 ? void 0 : _item$v.split('|')[0];
|
90
|
-
var maxVersion = (item === null || item === void 0 || (_item$v2 = item.v) === null || _item$v2 === void 0 ? void 0 : _item$v2.split('|')[1]) || '
|
91
|
+
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';
|
91
92
|
var matchVersion = compareVersion(sdkVersion, minVersion) >= 0 && compareVersion(maxVersion, sdkVersion) >= 0;
|
92
93
|
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);
|
93
94
|
});
|
@@ -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.1';
|
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
|
@@ -681,6 +683,7 @@ var ComponentApp = /*#__PURE__*/function () {
|
|
681
683
|
analytics: {
|
682
684
|
enabled: false
|
683
685
|
},
|
686
|
+
productScene: componentSign,
|
684
687
|
productSceneVersion: productSceneVersion,
|
685
688
|
environment: this.AMSSDK.options.env.environment,
|
686
689
|
// TODO 确定一下这个参数是干啥的
|
@@ -688,7 +691,8 @@ var ComponentApp = /*#__PURE__*/function () {
|
|
688
691
|
extendInfo: '',
|
689
692
|
locale: '',
|
690
693
|
instanceId: '',
|
691
|
-
isPreload: 'true'
|
694
|
+
isPreload: 'true',
|
695
|
+
mid: ''
|
692
696
|
}),
|
693
697
|
path = _getIframeUrl.path,
|
694
698
|
locationSearch = _getIframeUrl.locationSearch;
|
@@ -718,16 +722,20 @@ var ComponentApp = /*#__PURE__*/function () {
|
|
718
722
|
value: Date.now()
|
719
723
|
});
|
720
724
|
try {
|
721
|
-
var _renderParams$payment, _renderParams$payment2;
|
725
|
+
var _renderParams$payment, _renderParams$payment2, _renderParams$payment3, _renderParams$payment4;
|
722
726
|
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) || '';
|
723
|
-
var
|
727
|
+
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) || '';
|
728
|
+
var extendInfo = (renderParams === null || renderParams === void 0 || (_renderParams$payment3 = renderParams.paymentSessionMetaData) === null || _renderParams$payment3 === void 0 ? void 0 : _renderParams$payment3.extendInfo) || '';
|
729
|
+
var mid = renderParams === null || renderParams === void 0 || (_renderParams$payment4 = renderParams.paymentSessionMetaData) === null || _renderParams$payment4 === void 0 ? void 0 : _renderParams$payment4.clientId;
|
724
730
|
var environment = this.AMSSDK.options.env.environment;
|
725
731
|
this.appDomain = getAppDomain({
|
726
732
|
environment: environment,
|
727
733
|
appVersion: this._appVersion,
|
728
734
|
componentSign: this._componentSign,
|
735
|
+
productScene: productScene,
|
729
736
|
productSceneVersion: productSceneVersion,
|
730
|
-
extendInfo: extendInfo
|
737
|
+
extendInfo: extendInfo,
|
738
|
+
mid: mid
|
731
739
|
});
|
732
740
|
this.app = createIframe(this.AMSSDK.options.mode, this.platform);
|
733
741
|
var hostSign = ((renderParams === null || renderParams === void 0 ? void 0 : renderParams.sessionData) || '').split('&&')[1] || '';
|
@@ -735,13 +743,15 @@ var ComponentApp = /*#__PURE__*/function () {
|
|
735
743
|
renderDisplayType: renderParams.renderDisplayType,
|
736
744
|
componentSign: this._componentSign,
|
737
745
|
analytics: this.AMSSDK.options.analytics,
|
746
|
+
productScene: productScene,
|
738
747
|
productSceneVersion: productSceneVersion,
|
739
748
|
environment: environment,
|
740
749
|
appVersion: this._appVersion,
|
741
750
|
extendInfo: extendInfo,
|
742
751
|
locale: this.AMSSDK.options.locale,
|
743
752
|
instanceId: this.AMSSDK._instanceId,
|
744
|
-
hostSign: hostSign
|
753
|
+
hostSign: hostSign,
|
754
|
+
mid: mid
|
745
755
|
}),
|
746
756
|
path = _getIframeUrl2.path,
|
747
757
|
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;
|
@@ -41,7 +42,10 @@ export declare class Logger {
|
|
41
42
|
private debug;
|
42
43
|
private componentStartTime;
|
43
44
|
private isLoaded;
|
45
|
+
private static instance;
|
44
46
|
constructor(config: Config, debug: boolean);
|
47
|
+
static setInstance(instance: Logger): Logger;
|
48
|
+
static getInstance(): Logger;
|
45
49
|
setMedta(mdata: LogMetaData): void;
|
46
50
|
logError(error: LogPayload, extra?: Extra): Logger;
|
47
51
|
logInfo(info: LogPayload, extra?: Extra): Logger;
|
package/esm/util/logger.js
CHANGED
@@ -166,9 +166,20 @@ export var Logger = /*#__PURE__*/function () {
|
|
166
166
|
value: function setComponentStartTime(val) {
|
167
167
|
this.componentStartTime = val;
|
168
168
|
}
|
169
|
+
}], [{
|
170
|
+
key: "setInstance",
|
171
|
+
value: function setInstance(instance) {
|
172
|
+
return this.instance = instance;
|
173
|
+
}
|
174
|
+
}, {
|
175
|
+
key: "getInstance",
|
176
|
+
value: function getInstance() {
|
177
|
+
return this.instance;
|
178
|
+
}
|
169
179
|
}]);
|
170
180
|
return Logger;
|
171
181
|
}();
|
182
|
+
_defineProperty(Logger, "instance", void 0);
|
172
183
|
export var LogConfig = {
|
173
184
|
scriptUrl: 'https://gw.alipayobjects.com/render/p/yuyan_npm/@alipay_intl-tracker/1.6.0/dist/common.min.js',
|
174
185
|
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): 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;
|
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) {
|