@alicloud/alfa-core 1.5.13-beta.1 → 1.6.0-beta.10

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.
@@ -0,0 +1,36 @@
1
+ export function getChannel(value) {
2
+ var _window, _window$ALIYUN_CONSOL;
3
+ if (value) return value;
4
+ if ((_window = window) !== null && _window !== void 0 && (_window$ALIYUN_CONSOL = _window.ALIYUN_CONSOLE_CONFIG) !== null && _window$ALIYUN_CONSOL !== void 0 && _window$ALIYUN_CONSOL.CHANNEL) {
5
+ var _ALIYUN_CONSOLE_CONFI;
6
+ return (_ALIYUN_CONSOLE_CONFI = window.ALIYUN_CONSOLE_CONFIG) === null || _ALIYUN_CONSOLE_CONFI === void 0 ? void 0 : _ALIYUN_CONSOLE_CONFI.CHANNEL;
7
+ }
8
+
9
+ // 本地始终返回 OFFICIAL
10
+ if (typeof process !== 'undefined') {
11
+ var _process;
12
+ if (((_process = process) === null || _process === void 0 ? void 0 : _process.env.NODE_ENV) === 'development') {
13
+ return 'OFFICIAL';
14
+ }
15
+ }
16
+
17
+ // 尝试根据域名判断
18
+ if (['alibabacloud.com'].find(function (domain) {
19
+ return location.hostname.endsWith(domain);
20
+ })) {
21
+ return 'SIN';
22
+ }
23
+ if (['idptcloud01.com', 'idptcloud01cs.com', 'idptcloud01-inc.com'].find(function (domain) {
24
+ return location.hostname.endsWith(domain);
25
+ })) {
26
+ return 'EA134';
27
+ }
28
+ if (['idptcloud.com'].find(function (domain) {
29
+ return location.hostname.endsWith(domain);
30
+ })) {
31
+ return 'CM10';
32
+ }
33
+
34
+ // 默认返回 OFFICIAL
35
+ return 'OFFICIAL';
36
+ }
@@ -5,23 +5,6 @@ import { getRelease } from './getRelease';
5
5
  import cache from './cacheManager';
6
6
  import { getMicroAppLocale } from './oss';
7
7
  import { getEnv } from './env';
8
- var findLocaleEntry = function findLocaleEntry(localeVersionMap, locale) {
9
- var matchKey = Object.keys(localeVersionMap || {}).find(function (key) {
10
- return key && key.toLowerCase() === locale.toLowerCase();
11
- });
12
- var entry = matchKey && (localeVersionMap === null || localeVersionMap === void 0 ? void 0 : localeVersionMap[matchKey]);
13
- if (matchKey && entry) return {
14
- matchKey: matchKey,
15
- entry: entry
16
- };
17
- return undefined;
18
- };
19
- var getFallbackLocale = function getFallbackLocale() {
20
- var _window, _window$ALIYUN_CONSOL;
21
- var channel = (_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.CHANNEL;
22
- return channel === 'SIN' ? 'en_US' : 'zh_CN';
23
- };
24
-
25
8
  /**
26
9
  * 获取国际化文案
27
10
  * @param config
@@ -29,8 +12,8 @@ var getFallbackLocale = function getFallbackLocale() {
29
12
  */
30
13
  export var getI18nMessages = /*#__PURE__*/function () {
31
14
  var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(config) {
32
- var _releaseConfig$distT, _releaseConfig$locale, _matched, _matched2;
33
- var releaseConfig, logger, locale, localeVersion, localeVersionMap, matched, localeEntry, resolvedLocale, messages, _t, _t2;
15
+ var _releaseConfig$distT, _releaseConfig$locale, _releaseConfig$locale2, _releaseConfig$locale3;
16
+ var releaseConfig, logger, locale, localeVersion, matchKey, localeEntry, messages, _t, _t2;
34
17
  return _regeneratorRuntime.wrap(function (_context) {
35
18
  while (1) switch (_context.prev = _context.next) {
36
19
  case 0:
@@ -41,13 +24,10 @@ export var getI18nMessages = /*#__PURE__*/function () {
41
24
  logger = config.logger;
42
25
  locale = getLocale(config.locale);
43
26
  localeVersion = ((_releaseConfig$distT = releaseConfig['dist-tags']) === null || _releaseConfig$distT === void 0 ? void 0 : _releaseConfig$distT['locales-latest']) || '';
44
- localeVersionMap = (_releaseConfig$locale = releaseConfig['locales-versions']) === null || _releaseConfig$locale === void 0 ? void 0 : _releaseConfig$locale[localeVersion];
45
- matched = findLocaleEntry(localeVersionMap, locale);
46
- if (!matched) {
47
- matched = findLocaleEntry(localeVersionMap, getFallbackLocale());
48
- }
49
- localeEntry = (_matched = matched) === null || _matched === void 0 ? void 0 : _matched.entry;
50
- resolvedLocale = ((_matched2 = matched) === null || _matched2 === void 0 ? void 0 : _matched2.matchKey) || locale;
27
+ matchKey = Object.keys(((_releaseConfig$locale = releaseConfig['locales-versions']) === null || _releaseConfig$locale === void 0 ? void 0 : _releaseConfig$locale[localeVersion]) || {}).find(function (key) {
28
+ return key && key.toLowerCase() === locale.toLowerCase();
29
+ });
30
+ localeEntry = matchKey && ((_releaseConfig$locale2 = releaseConfig['locales-versions']) === null || _releaseConfig$locale2 === void 0 ? void 0 : (_releaseConfig$locale3 = _releaseConfig$locale2[localeVersion]) === null || _releaseConfig$locale3 === void 0 ? void 0 : _releaseConfig$locale3[matchKey]);
51
31
  messages = {};
52
32
  if (localeVersion) {
53
33
  _context.next = 2;
@@ -73,7 +53,7 @@ export var getI18nMessages = /*#__PURE__*/function () {
73
53
  _t = _context["catch"](2);
74
54
  _context.prev = 6;
75
55
  _context.next = 7;
76
- return getMicroAppLocale(config.name, localeVersion, resolvedLocale, getEnv(config.env));
56
+ return getMicroAppLocale(config.name, localeVersion, locale, getEnv(config.env));
77
57
  case 7:
78
58
  messages = _context.sent;
79
59
  _context.next = 9;
@@ -106,11 +106,6 @@ export var getManifest = /*#__PURE__*/function () {
106
106
  _context.next = 5;
107
107
  break;
108
108
  }
109
- (logger === null || logger === void 0 ? void 0 : logger.error) && logger.error({
110
- E_CODE: 'GetManifestError',
111
- E_MSG: 'no entry of manifest.',
112
- data: JSON.stringify(releaseConfig)
113
- });
114
109
  return _context.abrupt("return", undefined);
115
110
  case 5:
116
111
  _context.prev = 5;
@@ -1,8 +1,35 @@
1
1
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
2
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
3
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
4
  import _regeneratorRuntime from "@babel/runtime/regenerator";
5
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
6
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
7
+ import parseEnv from '@alicloud/console-base-conf-parse-env';
3
8
  import cache from './cacheManager';
4
9
  import { getMicroAppRelease } from './oss';
5
10
  import { getEnv } from './env';
11
+ import { getChannel } from './channel';
12
+ var idptcloud03CdnHost = 'idptcloud03asset.alibaba';
13
+ var getMainResourceCdn = function getMainResourceCdn() {
14
+ try {
15
+ var _parseEnv;
16
+ return ((_parseEnv = parseEnv()) === null || _parseEnv === void 0 ? void 0 : _parseEnv.MAIN_RESOURCE_CDN) || '';
17
+ } catch (e) {
18
+ return '';
19
+ }
20
+ };
21
+ var isIdptcloud03Cdn = function isIdptcloud03Cdn() {
22
+ return getMainResourceCdn().includes(idptcloud03CdnHost);
23
+ };
24
+ var getCwsHost = function getCwsHost(channel) {
25
+ if (isIdptcloud03Cdn()) {
26
+ return "cws.".concat(idptcloud03CdnHost);
27
+ }
28
+ if (['SIN', 'EA134', 'CM10'].includes(channel)) {
29
+ return 'cws.alcasset.com';
30
+ }
31
+ return 'cws.alyasset.com';
32
+ };
6
33
 
7
34
  /**
8
35
  * get alfa release url
@@ -10,10 +37,12 @@ import { getEnv } from './env';
10
37
  * @param env
11
38
  * @returns
12
39
  */
13
- export var getReleaseUrl = function getReleaseUrl(name, env) {
40
+ export var getReleaseUrl = function getReleaseUrl(name, env, channel) {
14
41
  var _process;
15
- var cdnUrl = "https://cws.alicdn.com/Release/alfa/".concat(name, "/release.json");
16
- var cdnPreUrl = "https://cws2.alicdn.com/Prepub/alfa/".concat(name, "/release.json");
42
+ var cwsHost = getCwsHost(channel);
43
+ var path = isIdptcloud03Cdn() ? 'Release' : 'Prepub';
44
+ var cdnUrl = "https://".concat(cwsHost, "/Release/alfa/").concat(name, "/release.json");
45
+ var cdnPreUrl = "https://".concat(cwsHost, "/").concat(path, "/alfa/").concat(name, "/release.json");
17
46
  switch (env) {
18
47
  case 'local':
19
48
  return ((_process = process) === null || _process === void 0 ? void 0 : _process.env.ALFA_RELEASE_URL) || cdnPreUrl;
@@ -28,17 +57,54 @@ export var getReleaseUrl = function getReleaseUrl(name, env) {
28
57
  }
29
58
  return undefined;
30
59
  };
60
+ function patchReleaseResult(releaseConfig, channel) {
61
+ if (!channel) {
62
+ return releaseConfig;
63
+ }
64
+ var replace = function replace(domain) {
65
+ if (!domain) {
66
+ return domain;
67
+ }
68
+ var path = isIdptcloud03Cdn() ? '/Release/' : '/Prepub/';
69
+ return domain.replace(/cws2?\.alicdn\.com/, getCwsHost(channel)).replace(/\/Prepub\//g, path);
70
+ };
71
+ var mapObject = function mapObject(obj, fn) {
72
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
73
+ var newObject = {};
74
+ Object.entries(obj).forEach(function (_ref) {
75
+ var _ref2 = _slicedToArray(_ref, 2),
76
+ key = _ref2[0],
77
+ value = _ref2[1];
78
+ newObject[key] = fn(value, key);
79
+ });
80
+ return newObject;
81
+ };
82
+ return _objectSpread(_objectSpread(_objectSpread({}, releaseConfig), releaseConfig['locales-versions'] ? {
83
+ 'locales-versions': mapObject(releaseConfig['locales-versions'], function (localeVersion) {
84
+ return mapObject(localeVersion, function (url) {
85
+ return replace(url);
86
+ });
87
+ })
88
+ } : undefined), releaseConfig['config-versions'] ? {
89
+ 'config-versions': mapObject(releaseConfig['config-versions'], function (configVersion) {
90
+ return mapObject(configVersion, function (url) {
91
+ return replace(url);
92
+ });
93
+ })
94
+ } : undefined);
95
+ }
31
96
  export var getRelease = /*#__PURE__*/function () {
32
- var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(config) {
33
- var logger, name, env, releaseConfig, _t, _t2;
97
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(config) {
98
+ var logger, name, env, channel, releaseConfig, _t, _t2, _t3;
34
99
  return _regeneratorRuntime.wrap(function (_context) {
35
100
  while (1) switch (_context.prev = _context.next) {
36
101
  case 0:
37
102
  logger = config.logger, name = config.name;
38
103
  env = getEnv(config.env);
104
+ channel = getChannel(config.channel);
39
105
  _context.prev = 1;
40
106
  _context.next = 2;
41
- return cache.getRemote(getReleaseUrl(name, env));
107
+ return cache.getRemote(getReleaseUrl(name, env, channel));
42
108
  case 2:
43
109
  releaseConfig = _context.sent.data;
44
110
  if (releaseConfig) {
@@ -47,18 +113,19 @@ export var getRelease = /*#__PURE__*/function () {
47
113
  }
48
114
  throw new Error('releaseConfig is null');
49
115
  case 3:
50
- return _context.abrupt("return", releaseConfig);
116
+ return _context.abrupt("return", patchReleaseResult(releaseConfig, channel));
51
117
  case 4:
52
118
  _context.prev = 4;
53
119
  _t = _context["catch"](1);
54
120
  _context.prev = 5;
121
+ _t2 = patchReleaseResult;
55
122
  _context.next = 6;
56
123
  return getMicroAppRelease(name, env);
57
124
  case 6:
58
- return _context.abrupt("return", _context.sent);
125
+ return _context.abrupt("return", _t2(_context.sent, channel));
59
126
  case 7:
60
127
  _context.prev = 7;
61
- _t2 = _context["catch"](5);
128
+ _t3 = _context["catch"](5);
62
129
  (logger === null || logger === void 0 ? void 0 : logger.error) && logger.error({
63
130
  E_CODE: 'GetReleaseError',
64
131
  E_MSG: _t.message
@@ -71,6 +138,6 @@ export var getRelease = /*#__PURE__*/function () {
71
138
  }, _callee, null, [[1, 4], [5, 7]]);
72
139
  }));
73
140
  return function getRelease(_x) {
74
- return _ref.apply(this, arguments);
141
+ return _ref3.apply(this, arguments);
75
142
  };
76
143
  }();
@@ -10,7 +10,8 @@ function isManifest(url, data) {
10
10
  return false;
11
11
  }
12
12
  function isRelease(url, data) {
13
- var pathname = new URL(url).pathname;
13
+ var _URL = new URL(url),
14
+ pathname = _URL.pathname;
14
15
  if (!data) return false;
15
16
 
16
17
  // central cws release.json
@@ -88,7 +89,7 @@ function _responseInterceptor() {
88
89
  }
89
90
  return _context.abrupt("return", response);
90
91
  case 1:
91
- // 非公有云域名(.alibaba 等)没有 cws2 fallback,直接跳过
92
+ // 非公有云域名(一国一云等)没有 cws2 fallback,直接跳过
92
93
  shouldSkipFallback = url && noCws2FallbackHosts.some(function (host) {
93
94
  return url.includes(host);
94
95
  });
@@ -96,9 +97,17 @@ function _responseInterceptor() {
96
97
  _context.next = 3;
97
98
  break;
98
99
  }
99
- config.url = url === null || url === void 0 ? void 0 : url.replace(/:\/\/cws\.([a-z0-9-]+\.(?:com|alibaba))\//, function (match, p1) {
100
- return "://cws2.".concat(p1, "/");
101
- });
100
+ if (['cws.alyasset.com', 'cws.alcasset.com'].some(function (domain) {
101
+ return url === null || url === void 0 ? void 0 : url.includes("://".concat(domain, "/"));
102
+ })) {
103
+ config.url = url === null || url === void 0 ? void 0 : url.replace(/:\/\/cws\.al[yc]asset\.com\//, function () {
104
+ return '://cws2.alicdn.com/';
105
+ });
106
+ } else {
107
+ config.url = url === null || url === void 0 ? void 0 : url.replace(/:\/\/cws\.([a-z0-9-]+\.(?:com|alibaba))\//, function (match, p1) {
108
+ return "://cws2.".concat(p1, "/");
109
+ });
110
+ }
102
111
  _context.next = 2;
103
112
  return axios(config);
104
113
  case 2:
@@ -10,11 +10,6 @@ var logger = createLogger({
10
10
  // project_xx 的外网域名,在 SLS project 概览里可以找到
11
11
  logstore: 'loader' // 日志落库的地方
12
12
  });
13
- var loggerIdpt = createLogger({
14
- project: 'alfa',
15
- endpoint: 'log.cn-hangzhou-idpt-2.idptcloud01cs.com',
16
- logstore: 'loader'
17
- });
18
13
  var Method = /*#__PURE__*/function (Method) {
19
14
  Method["log"] = "log";
20
15
  Method["info"] = "info";
@@ -86,14 +81,11 @@ var Logger = /*#__PURE__*/function () {
86
81
  })) return false;
87
82
 
88
83
  // do not track during development
89
- if (this.context.ENV === 'local' && !(params !== null && params !== void 0 && params.__force_log__)) {
84
+ if (this.context.ENV !== 'prod' && !(params !== null && params !== void 0 && params.__force_log__)) {
90
85
  console[method](topic, data);
91
86
  return;
92
87
  }
93
- var isIdpt = ['idptcloud01.com', 'idptcloud01-inc.com'].find(function (domain) {
94
- return location.hostname.endsWith(domain);
95
- });
96
- (isIdpt ? loggerIdpt : logger)[method](topic, data);
88
+ logger[method](topic, data);
97
89
  }
98
90
  }]);
99
91
  }();
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getChannel = getChannel;
7
+ function getChannel(value) {
8
+ var _window, _window$ALIYUN_CONSOL;
9
+ if (value) return value;
10
+ if ((_window = window) !== null && _window !== void 0 && (_window$ALIYUN_CONSOL = _window.ALIYUN_CONSOLE_CONFIG) !== null && _window$ALIYUN_CONSOL !== void 0 && _window$ALIYUN_CONSOL.CHANNEL) {
11
+ var _ALIYUN_CONSOLE_CONFI;
12
+ return (_ALIYUN_CONSOLE_CONFI = window.ALIYUN_CONSOLE_CONFIG) === null || _ALIYUN_CONSOLE_CONFI === void 0 ? void 0 : _ALIYUN_CONSOLE_CONFI.CHANNEL;
13
+ }
14
+
15
+ // 本地始终返回 OFFICIAL
16
+ if (typeof process !== 'undefined') {
17
+ var _process;
18
+ if (((_process = process) === null || _process === void 0 ? void 0 : _process.env.NODE_ENV) === 'development') {
19
+ return 'OFFICIAL';
20
+ }
21
+ }
22
+
23
+ // 尝试根据域名判断
24
+ if (['alibabacloud.com'].find(function (domain) {
25
+ return location.hostname.endsWith(domain);
26
+ })) {
27
+ return 'SIN';
28
+ }
29
+ if (['idptcloud01.com', 'idptcloud01cs.com', 'idptcloud01-inc.com'].find(function (domain) {
30
+ return location.hostname.endsWith(domain);
31
+ })) {
32
+ return 'EA134';
33
+ }
34
+ if (['idptcloud.com'].find(function (domain) {
35
+ return location.hostname.endsWith(domain);
36
+ })) {
37
+ return 'CM10';
38
+ }
39
+
40
+ // 默认返回 OFFICIAL
41
+ return 'OFFICIAL';
42
+ }
@@ -12,23 +12,6 @@ var _getRelease = require("./getRelease");
12
12
  var _cacheManager = _interopRequireDefault(require("./cacheManager"));
13
13
  var _oss = require("./oss");
14
14
  var _env = require("./env");
15
- var findLocaleEntry = function findLocaleEntry(localeVersionMap, locale) {
16
- var matchKey = Object.keys(localeVersionMap || {}).find(function (key) {
17
- return key && key.toLowerCase() === locale.toLowerCase();
18
- });
19
- var entry = matchKey && (localeVersionMap === null || localeVersionMap === void 0 ? void 0 : localeVersionMap[matchKey]);
20
- if (matchKey && entry) return {
21
- matchKey: matchKey,
22
- entry: entry
23
- };
24
- return undefined;
25
- };
26
- var getFallbackLocale = function getFallbackLocale() {
27
- var _window, _window$ALIYUN_CONSOL;
28
- var channel = (_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.CHANNEL;
29
- return channel === 'SIN' ? 'en_US' : 'zh_CN';
30
- };
31
-
32
15
  /**
33
16
  * 获取国际化文案
34
17
  * @param config
@@ -36,8 +19,8 @@ var getFallbackLocale = function getFallbackLocale() {
36
19
  */
37
20
  var getI18nMessages = exports.getI18nMessages = /*#__PURE__*/function () {
38
21
  var _ref = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee(config) {
39
- var _releaseConfig$distT, _releaseConfig$locale, _matched, _matched2;
40
- var releaseConfig, logger, locale, localeVersion, localeVersionMap, matched, localeEntry, resolvedLocale, messages, _t, _t2;
22
+ var _releaseConfig$distT, _releaseConfig$locale, _releaseConfig$locale2, _releaseConfig$locale3;
23
+ var releaseConfig, logger, locale, localeVersion, matchKey, localeEntry, messages, _t, _t2;
41
24
  return _regenerator.default.wrap(function (_context) {
42
25
  while (1) switch (_context.prev = _context.next) {
43
26
  case 0:
@@ -48,13 +31,10 @@ var getI18nMessages = exports.getI18nMessages = /*#__PURE__*/function () {
48
31
  logger = config.logger;
49
32
  locale = (0, _locale.getLocale)(config.locale);
50
33
  localeVersion = ((_releaseConfig$distT = releaseConfig['dist-tags']) === null || _releaseConfig$distT === void 0 ? void 0 : _releaseConfig$distT['locales-latest']) || '';
51
- localeVersionMap = (_releaseConfig$locale = releaseConfig['locales-versions']) === null || _releaseConfig$locale === void 0 ? void 0 : _releaseConfig$locale[localeVersion];
52
- matched = findLocaleEntry(localeVersionMap, locale);
53
- if (!matched) {
54
- matched = findLocaleEntry(localeVersionMap, getFallbackLocale());
55
- }
56
- localeEntry = (_matched = matched) === null || _matched === void 0 ? void 0 : _matched.entry;
57
- resolvedLocale = ((_matched2 = matched) === null || _matched2 === void 0 ? void 0 : _matched2.matchKey) || locale;
34
+ matchKey = Object.keys(((_releaseConfig$locale = releaseConfig['locales-versions']) === null || _releaseConfig$locale === void 0 ? void 0 : _releaseConfig$locale[localeVersion]) || {}).find(function (key) {
35
+ return key && key.toLowerCase() === locale.toLowerCase();
36
+ });
37
+ localeEntry = matchKey && ((_releaseConfig$locale2 = releaseConfig['locales-versions']) === null || _releaseConfig$locale2 === void 0 ? void 0 : (_releaseConfig$locale3 = _releaseConfig$locale2[localeVersion]) === null || _releaseConfig$locale3 === void 0 ? void 0 : _releaseConfig$locale3[matchKey]);
58
38
  messages = {};
59
39
  if (localeVersion) {
60
40
  _context.next = 2;
@@ -80,7 +60,7 @@ var getI18nMessages = exports.getI18nMessages = /*#__PURE__*/function () {
80
60
  _t = _context["catch"](2);
81
61
  _context.prev = 6;
82
62
  _context.next = 7;
83
- return (0, _oss.getMicroAppLocale)(config.name, localeVersion, resolvedLocale, (0, _env.getEnv)(config.env));
63
+ return (0, _oss.getMicroAppLocale)(config.name, localeVersion, locale, (0, _env.getEnv)(config.env));
84
64
  case 7:
85
65
  messages = _context.sent;
86
66
  _context.next = 9;
@@ -113,11 +113,6 @@ var getManifest = exports.getManifest = /*#__PURE__*/function () {
113
113
  _context.next = 5;
114
114
  break;
115
115
  }
116
- (logger === null || logger === void 0 ? void 0 : logger.error) && logger.error({
117
- E_CODE: 'GetManifestError',
118
- E_MSG: 'no entry of manifest.',
119
- data: JSON.stringify(releaseConfig)
120
- });
121
116
  return _context.abrupt("return", undefined);
122
117
  case 5:
123
118
  _context.prev = 5;
@@ -7,19 +7,49 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.getReleaseUrl = exports.getRelease = void 0;
8
8
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
9
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
12
+ var _consoleBaseConfParseEnv = _interopRequireDefault(require("@alicloud/console-base-conf-parse-env"));
10
13
  var _cacheManager = _interopRequireDefault(require("./cacheManager"));
11
14
  var _oss = require("./oss");
12
15
  var _env = require("./env");
16
+ var _channel = require("./channel");
17
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
18
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
19
+ var idptcloud03CdnHost = 'idptcloud03asset.alibaba';
20
+ var getMainResourceCdn = function getMainResourceCdn() {
21
+ try {
22
+ var _parseEnv;
23
+ return ((_parseEnv = (0, _consoleBaseConfParseEnv.default)()) === null || _parseEnv === void 0 ? void 0 : _parseEnv.MAIN_RESOURCE_CDN) || '';
24
+ } catch (e) {
25
+ return '';
26
+ }
27
+ };
28
+ var isIdptcloud03Cdn = function isIdptcloud03Cdn() {
29
+ return getMainResourceCdn().includes(idptcloud03CdnHost);
30
+ };
31
+ var getCwsHost = function getCwsHost(channel) {
32
+ if (isIdptcloud03Cdn()) {
33
+ return "cws.".concat(idptcloud03CdnHost);
34
+ }
35
+ if (['SIN', 'EA134', 'CM10'].includes(channel)) {
36
+ return 'cws.alcasset.com';
37
+ }
38
+ return 'cws.alyasset.com';
39
+ };
40
+
13
41
  /**
14
42
  * get alfa release url
15
43
  * @param appId
16
44
  * @param env
17
45
  * @returns
18
46
  */
19
- var getReleaseUrl = exports.getReleaseUrl = function getReleaseUrl(name, env) {
47
+ var getReleaseUrl = exports.getReleaseUrl = function getReleaseUrl(name, env, channel) {
20
48
  var _process;
21
- var cdnUrl = "https://cws.alicdn.com/Release/alfa/".concat(name, "/release.json");
22
- var cdnPreUrl = "https://cws2.alicdn.com/Prepub/alfa/".concat(name, "/release.json");
49
+ var cwsHost = getCwsHost(channel);
50
+ var path = isIdptcloud03Cdn() ? 'Release' : 'Prepub';
51
+ var cdnUrl = "https://".concat(cwsHost, "/Release/alfa/").concat(name, "/release.json");
52
+ var cdnPreUrl = "https://".concat(cwsHost, "/").concat(path, "/alfa/").concat(name, "/release.json");
23
53
  switch (env) {
24
54
  case 'local':
25
55
  return ((_process = process) === null || _process === void 0 ? void 0 : _process.env.ALFA_RELEASE_URL) || cdnPreUrl;
@@ -34,17 +64,54 @@ var getReleaseUrl = exports.getReleaseUrl = function getReleaseUrl(name, env) {
34
64
  }
35
65
  return undefined;
36
66
  };
67
+ function patchReleaseResult(releaseConfig, channel) {
68
+ if (!channel) {
69
+ return releaseConfig;
70
+ }
71
+ var replace = function replace(domain) {
72
+ if (!domain) {
73
+ return domain;
74
+ }
75
+ var path = isIdptcloud03Cdn() ? '/Release/' : '/Prepub/';
76
+ return domain.replace(/cws2?\.alicdn\.com/, getCwsHost(channel)).replace(/\/Prepub\//g, path);
77
+ };
78
+ var mapObject = function mapObject(obj, fn) {
79
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
80
+ var newObject = {};
81
+ Object.entries(obj).forEach(function (_ref) {
82
+ var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
83
+ key = _ref2[0],
84
+ value = _ref2[1];
85
+ newObject[key] = fn(value, key);
86
+ });
87
+ return newObject;
88
+ };
89
+ return _objectSpread(_objectSpread(_objectSpread({}, releaseConfig), releaseConfig['locales-versions'] ? {
90
+ 'locales-versions': mapObject(releaseConfig['locales-versions'], function (localeVersion) {
91
+ return mapObject(localeVersion, function (url) {
92
+ return replace(url);
93
+ });
94
+ })
95
+ } : undefined), releaseConfig['config-versions'] ? {
96
+ 'config-versions': mapObject(releaseConfig['config-versions'], function (configVersion) {
97
+ return mapObject(configVersion, function (url) {
98
+ return replace(url);
99
+ });
100
+ })
101
+ } : undefined);
102
+ }
37
103
  var getRelease = exports.getRelease = /*#__PURE__*/function () {
38
- var _ref = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee(config) {
39
- var logger, name, env, releaseConfig, _t, _t2;
104
+ var _ref3 = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee(config) {
105
+ var logger, name, env, channel, releaseConfig, _t, _t2, _t3;
40
106
  return _regenerator.default.wrap(function (_context) {
41
107
  while (1) switch (_context.prev = _context.next) {
42
108
  case 0:
43
109
  logger = config.logger, name = config.name;
44
110
  env = (0, _env.getEnv)(config.env);
111
+ channel = (0, _channel.getChannel)(config.channel);
45
112
  _context.prev = 1;
46
113
  _context.next = 2;
47
- return _cacheManager.default.getRemote(getReleaseUrl(name, env));
114
+ return _cacheManager.default.getRemote(getReleaseUrl(name, env, channel));
48
115
  case 2:
49
116
  releaseConfig = _context.sent.data;
50
117
  if (releaseConfig) {
@@ -53,18 +120,19 @@ var getRelease = exports.getRelease = /*#__PURE__*/function () {
53
120
  }
54
121
  throw new Error('releaseConfig is null');
55
122
  case 3:
56
- return _context.abrupt("return", releaseConfig);
123
+ return _context.abrupt("return", patchReleaseResult(releaseConfig, channel));
57
124
  case 4:
58
125
  _context.prev = 4;
59
126
  _t = _context["catch"](1);
60
127
  _context.prev = 5;
128
+ _t2 = patchReleaseResult;
61
129
  _context.next = 6;
62
130
  return (0, _oss.getMicroAppRelease)(name, env);
63
131
  case 6:
64
- return _context.abrupt("return", _context.sent);
132
+ return _context.abrupt("return", _t2(_context.sent, channel));
65
133
  case 7:
66
134
  _context.prev = 7;
67
- _t2 = _context["catch"](5);
135
+ _t3 = _context["catch"](5);
68
136
  (logger === null || logger === void 0 ? void 0 : logger.error) && logger.error({
69
137
  E_CODE: 'GetReleaseError',
70
138
  E_MSG: _t.message
@@ -77,6 +145,6 @@ var getRelease = exports.getRelease = /*#__PURE__*/function () {
77
145
  }, _callee, null, [[1, 4], [5, 7]]);
78
146
  }));
79
147
  return function getRelease(_x) {
80
- return _ref.apply(this, arguments);
148
+ return _ref3.apply(this, arguments);
81
149
  };
82
150
  }();
@@ -17,7 +17,8 @@ function isManifest(url, data) {
17
17
  return false;
18
18
  }
19
19
  function isRelease(url, data) {
20
- var pathname = new URL(url).pathname;
20
+ var _URL = new URL(url),
21
+ pathname = _URL.pathname;
21
22
  if (!data) return false;
22
23
 
23
24
  // central cws release.json
@@ -95,7 +96,7 @@ function _responseInterceptor() {
95
96
  }
96
97
  return _context.abrupt("return", response);
97
98
  case 1:
98
- // 非公有云域名(.alibaba 等)没有 cws2 fallback,直接跳过
99
+ // 非公有云域名(一国一云等)没有 cws2 fallback,直接跳过
99
100
  shouldSkipFallback = url && noCws2FallbackHosts.some(function (host) {
100
101
  return url.includes(host);
101
102
  });
@@ -103,9 +104,17 @@ function _responseInterceptor() {
103
104
  _context.next = 3;
104
105
  break;
105
106
  }
106
- config.url = url === null || url === void 0 ? void 0 : url.replace(/:\/\/cws\.([a-z0-9-]+\.(?:com|alibaba))\//, function (match, p1) {
107
- return "://cws2.".concat(p1, "/");
108
- });
107
+ if (['cws.alyasset.com', 'cws.alcasset.com'].some(function (domain) {
108
+ return url === null || url === void 0 ? void 0 : url.includes("://".concat(domain, "/"));
109
+ })) {
110
+ config.url = url === null || url === void 0 ? void 0 : url.replace(/:\/\/cws\.al[yc]asset\.com\//, function () {
111
+ return '://cws2.alicdn.com/';
112
+ });
113
+ } else {
114
+ config.url = url === null || url === void 0 ? void 0 : url.replace(/:\/\/cws\.([a-z0-9-]+\.(?:com|alibaba))\//, function (match, p1) {
115
+ return "://cws2.".concat(p1, "/");
116
+ });
117
+ }
109
118
  _context.next = 2;
110
119
  return (0, _axios.default)(config);
111
120
  case 2:
@@ -17,11 +17,6 @@ var logger = (0, _consoleLoggerSls.default)({
17
17
  // project_xx 的外网域名,在 SLS project 概览里可以找到
18
18
  logstore: 'loader' // 日志落库的地方
19
19
  });
20
- var loggerIdpt = (0, _consoleLoggerSls.default)({
21
- project: 'alfa',
22
- endpoint: 'log.cn-hangzhou-idpt-2.idptcloud01cs.com',
23
- logstore: 'loader'
24
- });
25
20
  var Method = /*#__PURE__*/function (Method) {
26
21
  Method["log"] = "log";
27
22
  Method["info"] = "info";
@@ -93,14 +88,11 @@ var Logger = exports.default = /*#__PURE__*/function () {
93
88
  })) return false;
94
89
 
95
90
  // do not track during development
96
- if (this.context.ENV === 'local' && !(params !== null && params !== void 0 && params.__force_log__)) {
91
+ if (this.context.ENV !== 'prod' && !(params !== null && params !== void 0 && params.__force_log__)) {
97
92
  console[method](topic, data);
98
93
  return;
99
94
  }
100
- var isIdpt = ['idptcloud01.com', 'idptcloud01-inc.com'].find(function (domain) {
101
- return location.hostname.endsWith(domain);
102
- });
103
- (isIdpt ? loggerIdpt : logger)[method](topic, data);
95
+ logger[method](topic, data);
104
96
  }
105
97
  }]);
106
98
  }();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alicloud/alfa-core",
3
- "version": "1.5.13-beta.1",
3
+ "version": "1.6.0-beta.10",
4
4
  "description": "MicroFront End SDK for alicloud",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -16,7 +16,6 @@
16
16
  "@types/axios": "^0.14.0",
17
17
  "@types/chai": "^4.1.7",
18
18
  "@types/jest": "^23.3.13",
19
- "@types/node": "^20.0.0",
20
19
  "@types/qs": "^6.9.18",
21
20
  "@types/react": "^16.9.2",
22
21
  "jest": "^23.6.0",
@@ -33,7 +32,7 @@
33
32
  "crypto-js": "^4.1.1",
34
33
  "qs": "^6.14.0",
35
34
  "tslib": "^2.4.0",
36
- "@alicloud/console-os-kernal": "^1.4.40"
35
+ "@alicloud/console-os-kernal": "^1.4.38"
37
36
  },
38
37
  "scripts": {
39
38
  "build": "npm run babel && npm run babel:esm && npm run types",
@@ -9,7 +9,7 @@ export declare class AlfaLogger<P = any> {
9
9
  warn?: (params: P) => void;
10
10
  debug?: (params: P) => void;
11
11
  }
12
- type Channel = string;
12
+ export type Channel = 'OFFICIAL' | 'SIN' | string;
13
13
  type ChannelLinks = Partial<Record<string, string>>;
14
14
  type ChannelFeatures = Partial<Record<string, {
15
15
  status: boolean;
@@ -57,6 +57,7 @@ export interface IAppConfig<P = any> extends IOptions {
57
57
  };
58
58
  app?: OSApplication;
59
59
  env?: EnvEnum;
60
+ channel?: Channel;
60
61
  locale?: string;
61
62
  dynamicConfig?: boolean;
62
63
  }
@@ -0,0 +1,2 @@
1
+ import { Channel } from 'types';
2
+ export declare function getChannel(value?: Channel): Channel;
@@ -1,9 +1,9 @@
1
- import { IAppConfig, AlfaReleaseConfig } from '../types';
1
+ import { IAppConfig, AlfaReleaseConfig, Channel } from '../types';
2
2
  /**
3
3
  * get alfa release url
4
4
  * @param appId
5
5
  * @param env
6
6
  * @returns
7
7
  */
8
- export declare const getReleaseUrl: (name?: string, env?: string) => string | undefined;
8
+ export declare const getReleaseUrl: (name?: string, env?: string, channel?: Channel) => string | undefined;
9
9
  export declare const getRelease: (config: IAppConfig) => Promise<AlfaReleaseConfig>;