@alicloud/alfa-core 1.4.36 → 1.4.38-alpha.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/es/utils/index.js +6 -6
- package/es/utils/locale.js +4 -7
- package/es/utils/uid.js +21 -0
- package/lib/utils/index.js +17 -7
- package/lib/utils/locale.js +4 -7
- package/lib/utils/uid.js +30 -0
- package/package.json +1 -2
- package/types/utils/index.d.ts +2 -0
- package/types/utils/uid.d.ts +11 -0
package/es/utils/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { getMainUid, getMD5MainUid } from './uid';
|
|
2
2
|
export { getEnv } from './env';
|
|
3
3
|
export { getLocale } from './locale';
|
|
4
|
+
export { getMainUid, getMD5MainUid };
|
|
4
5
|
export function getFeatureStatus(feature) {
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
if (!feature || !
|
|
8
|
-
var md5Uid = md5(uid).toString();
|
|
6
|
+
var uid = getMainUid();
|
|
7
|
+
var md5Uid = getMD5MainUid();
|
|
8
|
+
if (!feature || !md5Uid) return false;
|
|
9
9
|
var enableBlockList = feature.enableBlockList,
|
|
10
10
|
enableSampling = feature.enableSampling,
|
|
11
11
|
enableWhiteList = feature.enableWhiteList,
|
|
@@ -14,7 +14,7 @@ export function getFeatureStatus(feature) {
|
|
|
14
14
|
whiteList = feature.whiteList;
|
|
15
15
|
if (enableBlockList && blockList !== null && blockList !== void 0 && blockList.includes(md5Uid)) return false;
|
|
16
16
|
if (enableWhiteList && whiteList !== null && whiteList !== void 0 && whiteList.includes(md5Uid)) return true;
|
|
17
|
-
if (enableSampling) {
|
|
17
|
+
if (enableSampling && uid) {
|
|
18
18
|
var gray = uid.substring(uid.length - 2);
|
|
19
19
|
if (Number(gray) >= (sampling !== null && sampling !== void 0 ? sampling : 0) * 100 || sampling === 0) return false;
|
|
20
20
|
return true;
|
package/es/utils/locale.js
CHANGED
|
@@ -9,18 +9,15 @@ var localeMap = {
|
|
|
9
9
|
fr: 'fr_FR',
|
|
10
10
|
de: 'de_DE'
|
|
11
11
|
};
|
|
12
|
-
var getLocaleFromCookie = function getLocaleFromCookie() {
|
|
13
|
-
var lang = getCookie('aliyun_lang');
|
|
14
|
-
return lang && localeMap[lang];
|
|
15
|
-
};
|
|
16
12
|
|
|
17
13
|
/**
|
|
18
|
-
* x-X-Y to x_X_Y
|
|
14
|
+
* 1. x-X-Y to x_X_Y
|
|
15
|
+
* 2. zh to zh_CN
|
|
19
16
|
* @param key
|
|
20
17
|
* @returns
|
|
21
18
|
*/
|
|
22
19
|
var formatLocale = function formatLocale(key) {
|
|
23
|
-
return key.replace('-', '_');
|
|
20
|
+
return localeMap[key] ? localeMap[key] : key.replace('-', '_');
|
|
24
21
|
};
|
|
25
22
|
|
|
26
23
|
/**
|
|
@@ -29,5 +26,5 @@ var formatLocale = function formatLocale(key) {
|
|
|
29
26
|
*/
|
|
30
27
|
export var getLocale = function getLocale(key) {
|
|
31
28
|
var _window, _window$ALIYUN_CONSOL;
|
|
32
|
-
return formatLocale(key || ((_window = window) === null || _window === void 0 ? void 0 : (_window$ALIYUN_CONSOL = _window.ALIYUN_CONSOLE_CONFIG) === null || _window$ALIYUN_CONSOL === void 0 ? void 0 : _window$ALIYUN_CONSOL.LOCALE) ||
|
|
29
|
+
return formatLocale(key || ((_window = window) === null || _window === void 0 ? void 0 : (_window$ALIYUN_CONSOL = _window.ALIYUN_CONSOLE_CONFIG) === null || _window$ALIYUN_CONSOL === void 0 ? void 0 : _window$ALIYUN_CONSOL.LOCALE) || getCookie('aliyun_lang') || globalLocale);
|
|
33
30
|
};
|
package/es/utils/uid.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import md5 from 'crypto-js/md5';
|
|
2
|
+
import { getCookie } from '@alicloud/cookie';
|
|
3
|
+
/**
|
|
4
|
+
* 获取主账号 uid
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
export var getMainUid = function getMainUid() {
|
|
8
|
+
var _ALIYUN_CONSOLE_CONFI;
|
|
9
|
+
return ((_ALIYUN_CONSOLE_CONFI = window.ALIYUN_CONSOLE_CONFIG) === null || _ALIYUN_CONSOLE_CONFI === void 0 ? void 0 : _ALIYUN_CONSOLE_CONFI.MAIN_ACCOUNT_PK) || getCookie('login_aliyunid_pk') || undefined;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 获取 md5 后的主账号 uid
|
|
14
|
+
* @param uid
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
export var getMD5MainUid = function getMD5MainUid() {
|
|
18
|
+
var uid = getMainUid();
|
|
19
|
+
if (!uid) return undefined;
|
|
20
|
+
return md5(uid).toString();
|
|
21
|
+
};
|
package/lib/utils/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
@@ -17,15 +16,26 @@ Object.defineProperty(exports, "getLocale", {
|
|
|
17
16
|
return _locale.getLocale;
|
|
18
17
|
}
|
|
19
18
|
});
|
|
19
|
+
Object.defineProperty(exports, "getMD5MainUid", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function get() {
|
|
22
|
+
return _uid.getMD5MainUid;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(exports, "getMainUid", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function get() {
|
|
28
|
+
return _uid.getMainUid;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
20
31
|
exports.getURL = exports.getRelativePath = exports.getManifestFromConfig = void 0;
|
|
21
|
-
var
|
|
32
|
+
var _uid = require("./uid");
|
|
22
33
|
var _env = require("./env");
|
|
23
34
|
var _locale = require("./locale");
|
|
24
35
|
function getFeatureStatus(feature) {
|
|
25
|
-
var
|
|
26
|
-
var
|
|
27
|
-
if (!feature || !
|
|
28
|
-
var md5Uid = (0, _md.default)(uid).toString();
|
|
36
|
+
var uid = (0, _uid.getMainUid)();
|
|
37
|
+
var md5Uid = (0, _uid.getMD5MainUid)();
|
|
38
|
+
if (!feature || !md5Uid) return false;
|
|
29
39
|
var enableBlockList = feature.enableBlockList,
|
|
30
40
|
enableSampling = feature.enableSampling,
|
|
31
41
|
enableWhiteList = feature.enableWhiteList,
|
|
@@ -34,7 +44,7 @@ function getFeatureStatus(feature) {
|
|
|
34
44
|
whiteList = feature.whiteList;
|
|
35
45
|
if (enableBlockList && blockList !== null && blockList !== void 0 && blockList.includes(md5Uid)) return false;
|
|
36
46
|
if (enableWhiteList && whiteList !== null && whiteList !== void 0 && whiteList.includes(md5Uid)) return true;
|
|
37
|
-
if (enableSampling) {
|
|
47
|
+
if (enableSampling && uid) {
|
|
38
48
|
var gray = uid.substring(uid.length - 2);
|
|
39
49
|
if (Number(gray) >= (sampling !== null && sampling !== void 0 ? sampling : 0) * 100 || sampling === 0) return false;
|
|
40
50
|
return true;
|
package/lib/utils/locale.js
CHANGED
|
@@ -15,18 +15,15 @@ var localeMap = {
|
|
|
15
15
|
fr: 'fr_FR',
|
|
16
16
|
de: 'de_DE'
|
|
17
17
|
};
|
|
18
|
-
var getLocaleFromCookie = function getLocaleFromCookie() {
|
|
19
|
-
var lang = (0, _cookie.getCookie)('aliyun_lang');
|
|
20
|
-
return lang && localeMap[lang];
|
|
21
|
-
};
|
|
22
18
|
|
|
23
19
|
/**
|
|
24
|
-
* x-X-Y to x_X_Y
|
|
20
|
+
* 1. x-X-Y to x_X_Y
|
|
21
|
+
* 2. zh to zh_CN
|
|
25
22
|
* @param key
|
|
26
23
|
* @returns
|
|
27
24
|
*/
|
|
28
25
|
var formatLocale = function formatLocale(key) {
|
|
29
|
-
return key.replace('-', '_');
|
|
26
|
+
return localeMap[key] ? localeMap[key] : key.replace('-', '_');
|
|
30
27
|
};
|
|
31
28
|
|
|
32
29
|
/**
|
|
@@ -35,6 +32,6 @@ var formatLocale = function formatLocale(key) {
|
|
|
35
32
|
*/
|
|
36
33
|
var getLocale = function getLocale(key) {
|
|
37
34
|
var _window, _window$ALIYUN_CONSOL;
|
|
38
|
-
return formatLocale(key || ((_window = window) === null || _window === void 0 ? void 0 : (_window$ALIYUN_CONSOL = _window.ALIYUN_CONSOLE_CONFIG) === null || _window$ALIYUN_CONSOL === void 0 ? void 0 : _window$ALIYUN_CONSOL.LOCALE) ||
|
|
35
|
+
return formatLocale(key || ((_window = window) === null || _window === void 0 ? void 0 : (_window$ALIYUN_CONSOL = _window.ALIYUN_CONSOLE_CONFIG) === null || _window$ALIYUN_CONSOL === void 0 ? void 0 : _window$ALIYUN_CONSOL.LOCALE) || (0, _cookie.getCookie)('aliyun_lang') || globalLocale);
|
|
39
36
|
};
|
|
40
37
|
exports.getLocale = getLocale;
|
package/lib/utils/uid.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getMainUid = exports.getMD5MainUid = void 0;
|
|
8
|
+
var _md = _interopRequireDefault(require("crypto-js/md5"));
|
|
9
|
+
var _cookie = require("@alicloud/cookie");
|
|
10
|
+
/**
|
|
11
|
+
* 获取主账号 uid
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
var getMainUid = function getMainUid() {
|
|
15
|
+
var _ALIYUN_CONSOLE_CONFI;
|
|
16
|
+
return ((_ALIYUN_CONSOLE_CONFI = window.ALIYUN_CONSOLE_CONFIG) === null || _ALIYUN_CONSOLE_CONFI === void 0 ? void 0 : _ALIYUN_CONSOLE_CONFI.MAIN_ACCOUNT_PK) || (0, _cookie.getCookie)('login_aliyunid_pk') || undefined;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 获取 md5 后的主账号 uid
|
|
21
|
+
* @param uid
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
exports.getMainUid = getMainUid;
|
|
25
|
+
var getMD5MainUid = function getMD5MainUid() {
|
|
26
|
+
var uid = getMainUid();
|
|
27
|
+
if (!uid) return undefined;
|
|
28
|
+
return (0, _md.default)(uid).toString();
|
|
29
|
+
};
|
|
30
|
+
exports.getMD5MainUid = getMD5MainUid;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alicloud/alfa-core",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.38-alpha.0",
|
|
4
4
|
"description": "MicroFront End SDK for alicloud",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "es/index.js",
|
|
@@ -32,7 +32,6 @@
|
|
|
32
32
|
},
|
|
33
33
|
"gitHead": "6387c6b9e984da70641716a25ff92d382cc4d7ca",
|
|
34
34
|
"scripts": {
|
|
35
|
-
"prepublish": "npm run build && npm run babel && npm run babel:esm && npm run types",
|
|
36
35
|
"build": "breezr build --engine webpack",
|
|
37
36
|
"babel": "breezr build --engine babel",
|
|
38
37
|
"babel:esm": "breezr build --engine babel --es-module",
|
package/types/utils/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { getMainUid, getMD5MainUid } from './uid';
|
|
1
2
|
import { IAppConfig, AlfaFeature } from '../types';
|
|
2
3
|
export { getEnv } from './env';
|
|
3
4
|
export { getLocale } from './locale';
|
|
5
|
+
export { getMainUid, getMD5MainUid };
|
|
4
6
|
export declare function getFeatureStatus(feature?: AlfaFeature): boolean;
|
|
5
7
|
export declare const getURL: (appConfig: IAppConfig) => string;
|
|
6
8
|
export declare const getManifestFromConfig: (appConfig: IAppConfig) => string | import("@alicloud/console-os-kernal/lib/type").AppManifest | undefined;
|