@alicloud/alfa-core 1.5.0 → 1.5.2

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.
@@ -1,5 +1,8 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
1
2
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
3
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
4
+ 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; }
5
+ 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; }
3
6
  import _regeneratorRuntime from "@babel/runtime/regenerator";
4
7
  import parseEnv from '@alicloud/console-base-conf-parse-env';
5
8
  import { getRelease } from './getRelease';
@@ -90,7 +93,7 @@ export var getConfig = /*#__PURE__*/function () {
90
93
  */
91
94
  export var getConfigV2 = /*#__PURE__*/function () {
92
95
  var _ref4 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(config) {
93
- var releaseConfig, _ref5, relatedConsoleAppId, _ALIYUN_CONSOLE_CONFI, res;
96
+ var releaseConfig, _ref5, relatedConsoleAppId, currentConfig, _ALIYUN_CONSOLE_CONFI, res;
94
97
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
95
98
  while (1) switch (_context2.prev = _context2.next) {
96
99
  case 0:
@@ -99,35 +102,39 @@ export var getConfigV2 = /*#__PURE__*/function () {
99
102
  case 2:
100
103
  releaseConfig = _context2.sent;
101
104
  _ref5 = releaseConfig.metadata || {}, relatedConsoleAppId = _ref5.relatedConsoleAppId;
105
+ currentConfig = {
106
+ ALIYUN_CONSOLE_CONFIG: window.ALIYUN_CONSOLE_CONFIG || {},
107
+ ALIYUN_CONSOLE_GLOBAL: window.ALIYUN_CONSOLE_GLOBAL || {}
108
+ };
102
109
  if (!relatedConsoleAppId) {
103
- _context2.next = 16;
110
+ _context2.next = 17;
104
111
  break;
105
112
  }
106
113
  if (!(relatedConsoleAppId === ((_ALIYUN_CONSOLE_CONFI = window.ALIYUN_CONSOLE_CONFIG) === null || _ALIYUN_CONSOLE_CONFI === void 0 ? void 0 : _ALIYUN_CONSOLE_CONFI.APP_ID))) {
107
- _context2.next = 7;
114
+ _context2.next = 8;
108
115
  break;
109
116
  }
110
- return _context2.abrupt("return", {
111
- ALIYUN_CONSOLE_CONFIG: window.ALIYUN_CONSOLE_CONFIG,
112
- ALIYUN_CONSOLE_GLOBAL: window.ALIYUN_CONSOLE_GLOBAL || {}
113
- });
114
- case 7:
115
- _context2.prev = 7;
116
- _context2.next = 10;
117
+ return _context2.abrupt("return", currentConfig);
118
+ case 8:
119
+ _context2.prev = 8;
120
+ _context2.next = 11;
117
121
  return request.get("https://".concat(config.env !== 'prod' ? 'pre-' : '', "fecs.console.").concat(parseEnv().MAIN_DOMAIN, "/api/alfa/console/config?appId=").concat(relatedConsoleAppId));
118
- case 10:
122
+ case 11:
119
123
  res = _context2.sent;
120
- return _context2.abrupt("return", res.data.data);
121
- case 14:
122
- _context2.prev = 14;
123
- _context2.t0 = _context2["catch"](7);
124
- case 16:
125
- return _context2.abrupt("return", undefined);
124
+ return _context2.abrupt("return", {
125
+ ALIYUN_CONSOLE_CONFIG: _objectSpread(_objectSpread({}, window.ALIYUN_CONSOLE_CONFIG), res.data.data.ALIYUN_CONSOLE_CONFIG),
126
+ ALIYUN_CONSOLE_GLOBAL: res.data.data.ALIYUN_CONSOLE_GLOBAL
127
+ });
128
+ case 15:
129
+ _context2.prev = 15;
130
+ _context2.t0 = _context2["catch"](8);
126
131
  case 17:
132
+ return _context2.abrupt("return", currentConfig);
133
+ case 18:
127
134
  case "end":
128
135
  return _context2.stop();
129
136
  }
130
- }, _callee2, null, [[7, 14]]);
137
+ }, _callee2, null, [[8, 15]]);
131
138
  }));
132
139
  return function getConfigV2(_x2) {
133
140
  return _ref4.apply(this, arguments);
@@ -1,5 +1,7 @@
1
1
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
2
2
  import _regeneratorRuntime from "@babel/runtime/regenerator";
3
+ var whiteList = ['alicdn.com', 'idptcloud01cdn.com'];
4
+
3
5
  // 兼容非公有云环境
4
6
  var getCurrentCdnHost = function getCurrentCdnHost() {
5
7
  try {
@@ -13,6 +15,8 @@ var getCurrentCdnHost = function getCurrentCdnHost() {
13
15
  }
14
16
  };
15
17
  var currentCdnHost = getCurrentCdnHost();
18
+
19
+ // 根据不同环境替换 cdn 的域名
16
20
  export default function requestInterceptor(_x) {
17
21
  return _requestInterceptor.apply(this, arguments);
18
22
  }
@@ -21,9 +25,9 @@ function _requestInterceptor() {
21
25
  return _regeneratorRuntime.wrap(function _callee$(_context) {
22
26
  while (1) switch (_context.prev = _context.next) {
23
27
  case 0:
24
- if (currentCdnHost !== 'alicdn.com') {
28
+ if (currentCdnHost && currentCdnHost !== 'alicdn.com' && whiteList.includes(currentCdnHost)) {
25
29
  // if cdn is not alicdn, replace it
26
- if (currentCdnHost && config.url) {
30
+ if (config.url) {
27
31
  config.url = config.url.replace(new RegExp('.alicdn.com'), ".".concat(currentCdnHost)).replace('cws2.', 'cws.') // 非公有云下无 cws2
28
32
  .replace('dev.g.idptcloud01cdn.com', 'dev-g.idptcloud01cdn.com'); // idptcloud01cdn 无 dev.g 子域名
29
33
  }
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.getConfigV2 = exports.getConfig = void 0;
8
8
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
10
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
11
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
11
12
  var _consoleBaseConfParseEnv = _interopRequireDefault(require("@alicloud/console-base-conf-parse-env"));
@@ -14,6 +15,8 @@ var _cacheManager = _interopRequireDefault(require("./cacheManager"));
14
15
  var _oss = require("./oss");
15
16
  var _env = require("./env");
16
17
  var _request = _interopRequireDefault(require("./request"));
18
+ 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; }
19
+ 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; }
17
20
  var defaultConfig = {
18
21
  ALL_CHANNEL_FEATURE_STATUS: {},
19
22
  ALL_CHANNEL_LINKS: {},
@@ -97,7 +100,7 @@ var getConfig = exports.getConfig = /*#__PURE__*/function () {
97
100
  */
98
101
  var getConfigV2 = exports.getConfigV2 = /*#__PURE__*/function () {
99
102
  var _ref4 = (0, _asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function _callee2(config) {
100
- var releaseConfig, _ref5, relatedConsoleAppId, _ALIYUN_CONSOLE_CONFI, res;
103
+ var releaseConfig, _ref5, relatedConsoleAppId, currentConfig, _ALIYUN_CONSOLE_CONFI, res;
101
104
  return _regenerator.default.wrap(function _callee2$(_context2) {
102
105
  while (1) switch (_context2.prev = _context2.next) {
103
106
  case 0:
@@ -106,35 +109,39 @@ var getConfigV2 = exports.getConfigV2 = /*#__PURE__*/function () {
106
109
  case 2:
107
110
  releaseConfig = _context2.sent;
108
111
  _ref5 = releaseConfig.metadata || {}, relatedConsoleAppId = _ref5.relatedConsoleAppId;
112
+ currentConfig = {
113
+ ALIYUN_CONSOLE_CONFIG: window.ALIYUN_CONSOLE_CONFIG || {},
114
+ ALIYUN_CONSOLE_GLOBAL: window.ALIYUN_CONSOLE_GLOBAL || {}
115
+ };
109
116
  if (!relatedConsoleAppId) {
110
- _context2.next = 16;
117
+ _context2.next = 17;
111
118
  break;
112
119
  }
113
120
  if (!(relatedConsoleAppId === ((_ALIYUN_CONSOLE_CONFI = window.ALIYUN_CONSOLE_CONFIG) === null || _ALIYUN_CONSOLE_CONFI === void 0 ? void 0 : _ALIYUN_CONSOLE_CONFI.APP_ID))) {
114
- _context2.next = 7;
121
+ _context2.next = 8;
115
122
  break;
116
123
  }
117
- return _context2.abrupt("return", {
118
- ALIYUN_CONSOLE_CONFIG: window.ALIYUN_CONSOLE_CONFIG,
119
- ALIYUN_CONSOLE_GLOBAL: window.ALIYUN_CONSOLE_GLOBAL || {}
120
- });
121
- case 7:
122
- _context2.prev = 7;
123
- _context2.next = 10;
124
+ return _context2.abrupt("return", currentConfig);
125
+ case 8:
126
+ _context2.prev = 8;
127
+ _context2.next = 11;
124
128
  return _request.default.get("https://".concat(config.env !== 'prod' ? 'pre-' : '', "fecs.console.").concat((0, _consoleBaseConfParseEnv.default)().MAIN_DOMAIN, "/api/alfa/console/config?appId=").concat(relatedConsoleAppId));
125
- case 10:
129
+ case 11:
126
130
  res = _context2.sent;
127
- return _context2.abrupt("return", res.data.data);
128
- case 14:
129
- _context2.prev = 14;
130
- _context2.t0 = _context2["catch"](7);
131
- case 16:
132
- return _context2.abrupt("return", undefined);
131
+ return _context2.abrupt("return", {
132
+ ALIYUN_CONSOLE_CONFIG: _objectSpread(_objectSpread({}, window.ALIYUN_CONSOLE_CONFIG), res.data.data.ALIYUN_CONSOLE_CONFIG),
133
+ ALIYUN_CONSOLE_GLOBAL: res.data.data.ALIYUN_CONSOLE_GLOBAL
134
+ });
135
+ case 15:
136
+ _context2.prev = 15;
137
+ _context2.t0 = _context2["catch"](8);
133
138
  case 17:
139
+ return _context2.abrupt("return", currentConfig);
140
+ case 18:
134
141
  case "end":
135
142
  return _context2.stop();
136
143
  }
137
- }, _callee2, null, [[7, 14]]);
144
+ }, _callee2, null, [[8, 15]]);
138
145
  }));
139
146
  return function getConfigV2(_x2) {
140
147
  return _ref4.apply(this, arguments);
@@ -7,6 +7,8 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.default = requestInterceptor;
8
8
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
9
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
+ var whiteList = ['alicdn.com', 'idptcloud01cdn.com'];
11
+
10
12
  // 兼容非公有云环境
11
13
  var getCurrentCdnHost = function getCurrentCdnHost() {
12
14
  try {
@@ -20,6 +22,8 @@ var getCurrentCdnHost = function getCurrentCdnHost() {
20
22
  }
21
23
  };
22
24
  var currentCdnHost = getCurrentCdnHost();
25
+
26
+ // 根据不同环境替换 cdn 的域名
23
27
  function requestInterceptor(_x) {
24
28
  return _requestInterceptor.apply(this, arguments);
25
29
  }
@@ -28,9 +32,9 @@ function _requestInterceptor() {
28
32
  return _regenerator.default.wrap(function _callee$(_context) {
29
33
  while (1) switch (_context.prev = _context.next) {
30
34
  case 0:
31
- if (currentCdnHost !== 'alicdn.com') {
35
+ if (currentCdnHost && currentCdnHost !== 'alicdn.com' && whiteList.includes(currentCdnHost)) {
32
36
  // if cdn is not alicdn, replace it
33
- if (currentCdnHost && config.url) {
37
+ if (config.url) {
34
38
  config.url = config.url.replace(new RegExp('.alicdn.com'), ".".concat(currentCdnHost)).replace('cws2.', 'cws.') // 非公有云下无 cws2
35
39
  .replace('dev.g.idptcloud01cdn.com', 'dev-g.idptcloud01cdn.com'); // idptcloud01cdn 无 dev.g 子域名
36
40
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alicloud/alfa-core",
3
- "version": "1.5.0",
3
+ "version": "1.5.2",
4
4
  "description": "MicroFront End SDK for alicloud",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -29,6 +29,6 @@ export declare const getConfigV2: (config: IAppConfig) => Promise<{
29
29
  MAIN_ACCOUNT_PK: string;
30
30
  CURRENT_PK: string;
31
31
  APP_ID?: string | undefined;
32
- }> | undefined;
32
+ }>;
33
33
  ALIYUN_CONSOLE_GLOBAL: Record<string, any>;
34
- } | undefined>;
34
+ }>;