@next-core/brick-kit 2.124.0 → 2.126.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/index.esm.js CHANGED
@@ -4,7 +4,7 @@ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProper
4
4
  import _asyncToGenerator$4 from '@babel/runtime/helpers/asyncToGenerator';
5
5
  import _defineProperty$1 from '@babel/runtime/helpers/defineProperty';
6
6
  import React, { useState, useEffect, useRef, forwardRef, useImperativeHandle, useMemo, useContext, createContext, useReducer, useCallback } from 'react';
7
- import { JsonStorage, toPath, computeRealRoutePath, hasOwnProperty, isObject, isEvaluable, transformAndInject, transform, trackContext, trackState, scanPermissionActionsInStoryboard, precookFunction, cook, resolveContextConcurrently, syncResolveContextConcurrently, shouldAllowRecursiveEvaluations, preevaluate, inject, deepFreeze, createProviderClass, getTemplateDepsOfStoryboard, getDllAndDepsOfStoryboard, asyncProcessStoryboard, getDllAndDepsByResource, scanRouteAliasInStoryboard, prefetchScript, scanBricksInBrickConf, scanProcessorsInAny, loadScript, matchPath, scanAppGetMenuInAny, asyncProcessBrick, restoreDynamicTemplates, scanStoryboard, mapCustomApisToNameAndNamespace } from '@next-core/brick-utils';
7
+ import { JsonStorage, toPath, computeRealRoutePath, hasOwnProperty, isObject, isEvaluable, transformAndInject, transform, trackContext, trackState, scanPermissionActionsInStoryboard, precookFunction, cook, resolveContextConcurrently, syncResolveContextConcurrently, shouldAllowRecursiveEvaluations, preevaluate, inject, deepFreeze, createProviderClass, getTemplateDepsOfStoryboard, getDllAndDepsOfStoryboard, asyncProcessStoryboard, getDllAndDepsByResource, scanRouteAliasInStoryboard, prefetchScript, scanBricksInBrickConf, scanProcessorsInAny, loadScript, matchPath, scanAppGetMenuInAny, asyncProcessBrick, scanInstalledAppsInStoryboard, restoreDynamicTemplates, scanStoryboard, mapCustomApisToNameAndNamespace } from '@next-core/brick-utils';
8
8
  import _, { set, get, difference, identity, uniqueId, cloneDeep, clamp, isNil, sortBy, merge, isEmpty, isObject as isObject$1, pick, orderBy, omit, findLastIndex, noop, isString } from 'lodash';
9
9
  import { http, HttpResponseError, HttpFetchError } from '@next-core/brick-http';
10
10
  import moment from 'moment';
@@ -2924,7 +2924,7 @@ function getNextInternalOptions(internalOptions, isArray, key) {
2924
2924
  }
2925
2925
 
2926
2926
  var _excluded$6 = ["children"],
2927
- _excluded2$1 = ["items", "app"];
2927
+ _excluded2$2 = ["items", "app"];
2928
2928
  var symbolAppId = Symbol("appId");
2929
2929
  // Caching menu requests to avoid flicker.
2930
2930
  var menuCache = new Map();
@@ -3108,7 +3108,7 @@ function _processMenu() {
3108
3108
  items,
3109
3109
  app
3110
3110
  } = _yield$fetchMenuById,
3111
- restMenuData = _objectWithoutProperties(_yield$fetchMenuById, _excluded2$1);
3111
+ restMenuData = _objectWithoutProperties(_yield$fetchMenuById, _excluded2$2);
3112
3112
 
3113
3113
  var menuData = _objectSpread(_objectSpread({}, yield computeRealValueWithOverrideApp(restMenuData, app[0].appId, context, kernel)), {}, {
3114
3114
  items: yield computeMenuItemsWithOverrideApp(items, context, kernel)
@@ -3496,7 +3496,8 @@ class Runtime {
3496
3496
  }
3497
3497
 
3498
3498
  hasInstalledApp(appId, matchVersion) {
3499
- return kernel.bootstrapData.microApps.some(app => {
3499
+ var allMicroApps = window.STANDALONE_MICRO_APPS ? kernel.bootstrapData.offSiteStandaloneApps : kernel.bootstrapData.microApps;
3500
+ return allMicroApps.some(app => {
3500
3501
  var foundApp = app.id === appId && app.installStatus !== "running";
3501
3502
 
3502
3503
  if (!matchVersion || !foundApp) {
@@ -5794,6 +5795,24 @@ function clearPollTimeout() {
5794
5795
  timeoutIdList.clear();
5795
5796
  }
5796
5797
 
5798
+ /**
5799
+ * @description 独立小产品Runtime接口
5800
+ * @endpoint GET /api/v1/runtime_standalone
5801
+ */
5802
+
5803
+
5804
+ var BootstrapStandaloneApi_runtimeStandalone = /*#__PURE__*/function () {
5805
+ var _ref = _asyncToGenerator$4(function* (options) {
5806
+ return (
5807
+ /**! @contract easyops.api.api_gateway.bootstrap_standalone.RuntimeStandalone@1.0.1 */
5808
+ (yield http.get("api/v1/runtime_standalone", options)).data
5809
+ );
5810
+ });
5811
+
5812
+ return function BootstrapStandaloneApi_runtimeStandalone(_x) {
5813
+ return _ref.apply(this, arguments);
5814
+ };
5815
+ }();
5797
5816
  /**
5798
5817
  * @description 获取系统初始化信息
5799
5818
  * @endpoint GET /api/auth/v2/bootstrap
@@ -6886,6 +6905,43 @@ var UserAdminApi_searchAllUsersInfo = /*#__PURE__*/function () {
6886
6905
  };
6887
6906
  }();
6888
6907
 
6908
+ /**
6909
+ * @description 独立小产品Runtime接口
6910
+ * @endpoint GET /api/v1/micro_app_standalone/runtime/:appId
6911
+ */
6912
+
6913
+
6914
+ var RuntimeApi_runtimeMicroAppStandalone = /*#__PURE__*/function () {
6915
+ var _ref = _asyncToGenerator$4(function* (appId, options) {
6916
+ return (
6917
+ /**! @contract easyops.api.micro_app_standalone.runtime.RuntimeMicroAppStandalone@1.0.1 */
6918
+ (yield http.get("api/gateway/micro_app_standalone.runtime.RuntimeMicroAppStandalone/api/v1/micro_app_standalone/runtime/".concat(appId), options)).data
6919
+ );
6920
+ });
6921
+
6922
+ return function RuntimeApi_runtimeMicroAppStandalone(_x, _x2) {
6923
+ return _ref.apply(this, arguments);
6924
+ };
6925
+ }();
6926
+ /**
6927
+ * @description 查询独立部署小产品
6928
+ * @endpoint POST /api/v1/micro_app_standalone/search
6929
+ */
6930
+
6931
+
6932
+ var RuntimeApi_searchMicroAppStandalone = /*#__PURE__*/function () {
6933
+ var _ref = _asyncToGenerator$4(function* (data, options) {
6934
+ return (
6935
+ /**! @contract easyops.api.micro_app_standalone.runtime.SearchMicroAppStandalone@1.0.1 */
6936
+ (yield http.post("api/gateway/micro_app_standalone.runtime.SearchMicroAppStandalone/api/v1/micro_app_standalone/search", data, options)).data
6937
+ );
6938
+ });
6939
+
6940
+ return function RuntimeApi_searchMicroAppStandalone(_x, _x2) {
6941
+ return _ref.apply(this, arguments);
6942
+ };
6943
+ }();
6944
+
6889
6945
  /**
6890
6946
  * Merge `app.defaultConfig` and `app.userConfig` to `app.config`.
6891
6947
  *
@@ -7078,15 +7134,21 @@ function initAnalytics() {
7078
7134
  }
7079
7135
  }
7080
7136
 
7081
- var _excluded$4 = ["feature_flags"];
7137
+ var _excluded$4 = ["feature_flags"],
7138
+ _excluded2$1 = ["featureFlags", "misc"];
7082
7139
  function standaloneBootstrap() {
7083
7140
  return _standaloneBootstrap.apply(this, arguments);
7084
7141
  }
7085
7142
 
7086
7143
  function _standaloneBootstrap() {
7087
7144
  _standaloneBootstrap = _asyncToGenerator$4(function* () {
7088
- var [bootstrapResult, confString] = yield Promise.all([http.get(window.BOOTSTRAP_FILE), http.get("".concat(window.APP_ROOT, "conf.yaml"), {
7145
+ var [bootstrapResult, confString, runtimeData] = yield Promise.all([http.get(window.BOOTSTRAP_FILE), http.get("".concat(window.APP_ROOT, "conf.yaml"), {
7089
7146
  responseType: "text"
7147
+ }), yield BootstrapStandaloneApi_runtimeStandalone().catch(function (error) {
7148
+ // make it not crash when the backend service is not updated.
7149
+ // eslint-disable-next-line no-console
7150
+ console.warn("request runtime api from api-gateway failed: ", error, ", something might went wrong running standalone micro app");
7151
+ return undefined;
7090
7152
  })]);
7091
7153
  var conf;
7092
7154
 
@@ -7134,6 +7196,24 @@ function _standaloneBootstrap() {
7134
7196
  }
7135
7197
  }
7136
7198
 
7199
+ if (runtimeData) {
7200
+ var runtimeSetings = runtimeData.settings;
7201
+
7202
+ if (!isEmpty(runtimeSetings)) {
7203
+ // Merge Feature Flags
7204
+ if (!settings) {
7205
+ settings = runtimeSetings;
7206
+ } else {
7207
+ // Merge Feature Flags & Misc
7208
+ var rest = _objectWithoutProperties(runtimeSetings, _excluded2$1);
7209
+
7210
+ settings.featureFlags = _objectSpread(_objectSpread({}, settings.featureFlags), runtimeSetings.featureFlags);
7211
+ settings.misc = _objectSpread(_objectSpread({}, settings.misc), runtimeSetings.misc);
7212
+ settings = Object.assign(settings, rest);
7213
+ }
7214
+ }
7215
+ }
7216
+
7137
7217
  return _objectSpread(_objectSpread({}, bootstrapResult), {}, {
7138
7218
  settings
7139
7219
  });
@@ -8855,6 +8935,27 @@ class Kernel {
8855
8935
  Object.assign(storyboard, {
8856
8936
  $$fulfilled: true
8857
8937
  });
8938
+
8939
+ if (!window.NO_AUTH_GUARD) {
8940
+ var appRuntimeData;
8941
+
8942
+ try {
8943
+ appRuntimeData = yield RuntimeApi_runtimeMicroAppStandalone(storyboard.app.id);
8944
+ } catch (error) {
8945
+ // make it not crash when the backend service is not updated.
8946
+ // eslint-disable-next-line no-console
8947
+ console.warn("request standalone runtime api from micro-app-standalone failed: ", error, ", something might went wrong running standalone micro app");
8948
+ }
8949
+
8950
+ if (appRuntimeData) {
8951
+ // merge user config
8952
+ storyboard.app.userConfig = _objectSpread(_objectSpread({}, storyboard.app.userConfig), appRuntimeData.userConfig); // get inject menus (Actually, appRuntimeData contains both main and inject menus)
8953
+
8954
+ storyboard.meta = _objectSpread(_objectSpread({}, storyboard.meta), {}, {
8955
+ injectMenus: appRuntimeData.injectMenus
8956
+ });
8957
+ }
8958
+ }
8858
8959
  } else {
8859
8960
  var {
8860
8961
  routes,
@@ -9369,15 +9470,20 @@ class Kernel {
9369
9470
  }
9370
9471
 
9371
9472
  getStandaloneMenus(menuId) {
9372
- var _cloneDeep, _currentStoryboard$me;
9473
+ var _currentStoryboard$me, _currentStoryboard$me2;
9373
9474
 
9374
9475
  var currentAppId = this.currentApp.id;
9375
9476
  var currentStoryboard = this.bootstrapData.storyboards.find(storyboard => storyboard.app.id === currentAppId);
9376
- return ((_cloneDeep = cloneDeep((_currentStoryboard$me = currentStoryboard.meta) === null || _currentStoryboard$me === void 0 ? void 0 : _currentStoryboard$me.menus)) !== null && _cloneDeep !== void 0 ? _cloneDeep : []).filter(menu => menu.menuId === menuId).map(menu => _objectSpread(_objectSpread({}, menu), {}, {
9377
- app: [{
9378
- appId: currentAppId
9379
- }]
9380
- }));
9477
+ var menus = (_currentStoryboard$me = currentStoryboard.meta) !== null && _currentStoryboard$me !== void 0 && _currentStoryboard$me.injectMenus ? cloneDeep(currentStoryboard.meta.injectMenus) : (_currentStoryboard$me2 = currentStoryboard.meta) !== null && _currentStoryboard$me2 !== void 0 && _currentStoryboard$me2.menus ? cloneDeep(currentStoryboard.meta.menus) : [];
9478
+ return menus.filter(menu => menu.menuId === menuId).map(menu => {
9479
+ var _menu$app;
9480
+
9481
+ return _objectSpread(_objectSpread({}, menu), (_menu$app = menu.app) !== null && _menu$app !== void 0 && _menu$app.length && menu.app[0].appId ? {} : {
9482
+ app: [{
9483
+ appId: currentAppId
9484
+ }]
9485
+ });
9486
+ });
9381
9487
  }
9382
9488
 
9383
9489
  getProviderBrick(provider) {
@@ -9918,6 +10024,7 @@ function getDefaultProperties(_name, fields) {
9918
10024
  break;
9919
10025
 
9920
10026
  case "IP":
10027
+ /* eslint-disable */
9921
10028
  defaultValue = {
9922
10029
  brick: "forms.general-input",
9923
10030
  properties: {
@@ -9927,9 +10034,14 @@ function getDefaultProperties(_name, fields) {
9927
10034
  readOnly: field.limit.includes("READONLY"),
9928
10035
  required: field.limit.includes("REQUIRED"),
9929
10036
  placeholder: field.description,
9930
- pattern: /((^\s*((([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5]))\s*$)|(^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|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d|1dd|[1-9]?d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]d|1dd|[1-9]?d)(.(25[0-5]|2[0-4]d|1dd|[1-9]?d)){3}))|:)))(%.+)?s*$))",
10038
+ message: {
10039
+ pattern: "输入字符不匹配IP格式"
10040
+ }
9931
10041
  }
9932
10042
  };
10043
+ /* eslint-disable */
10044
+
9933
10045
  break;
9934
10046
 
9935
10047
  case "JSON":
@@ -11329,6 +11441,69 @@ function registerFormRenderer() {
11329
11441
  });
11330
11442
  }
11331
11443
 
11444
+ var standaloneApps = [];
11445
+ var appIdSet = new Set();
11446
+ function preFetchStandaloneInstalledApps(_x) {
11447
+ return _preFetchStandaloneInstalledApps.apply(this, arguments);
11448
+ }
11449
+
11450
+ function _preFetchStandaloneInstalledApps() {
11451
+ _preFetchStandaloneInstalledApps = _asyncToGenerator$4(function* (storyboard) {
11452
+ var saIds = scanInstalledAppsInStoryboard(storyboard);
11453
+ yield fetchStandaloneApps(saIds);
11454
+ });
11455
+ return _preFetchStandaloneInstalledApps.apply(this, arguments);
11456
+ }
11457
+
11458
+ function fetchStandaloneApps(_x2) {
11459
+ return _fetchStandaloneApps.apply(this, arguments);
11460
+ }
11461
+
11462
+ function _fetchStandaloneApps() {
11463
+ _fetchStandaloneApps = _asyncToGenerator$4(function* (saIds) {
11464
+ // ignore apps which are already searched
11465
+ var searchIds = difference(saIds, Array.from(appIdSet));
11466
+
11467
+ if (searchIds.length === 0) {
11468
+ return;
11469
+ }
11470
+
11471
+ try {
11472
+ var result = yield RuntimeApi_searchMicroAppStandalone({
11473
+ query: {
11474
+ isActiveVersion: true,
11475
+ appId: {
11476
+ $in: searchIds
11477
+ }
11478
+ },
11479
+ fields: ["appId", "version"]
11480
+ });
11481
+
11482
+ for (var item of result.list) {
11483
+ standaloneApps.push({
11484
+ id: item.appId,
11485
+ currentVersion: item.version,
11486
+ installStatus: "ok"
11487
+ });
11488
+ }
11489
+
11490
+ for (var id of searchIds) {
11491
+ appIdSet.add(id);
11492
+ }
11493
+ } catch (error) {
11494
+ // Allow search micro app to fail, and
11495
+ // make it not crash when the backend service is not updated.
11496
+ // eslint-disable-next-line no-console
11497
+ console.error("get off site standalone micro app failed", error);
11498
+ }
11499
+ });
11500
+ return _fetchStandaloneApps.apply(this, arguments);
11501
+ }
11502
+
11503
+ function getStandaloneInstalledApps() {
11504
+ return standaloneApps;
11505
+ }
11506
+
11332
11507
  class Router {
11333
11508
  constructor(kernel) {
11334
11509
  _defineProperty$1(this, "defaultCollapsed", false);
@@ -11526,6 +11701,13 @@ class Router {
11526
11701
 
11527
11702
  if (isLoggedIn() && !getAuth().isAdmin) {
11528
11703
  yield preCheckPermissions(storyboard);
11704
+ } // Standalone App 需要额外读取 Installed App 信息
11705
+
11706
+
11707
+ if (window.STANDALONE_MICRO_APPS && !window.NO_AUTH_GUARD) {
11708
+ // TODO: get standalone apps when NO_AUTH_GUARD, maybe from conf.yaml
11709
+ yield preFetchStandaloneInstalledApps(storyboard);
11710
+ _this3.kernel.bootstrapData.offSiteStandaloneApps = getStandaloneInstalledApps();
11529
11711
  } // 如果找到匹配的 storyboard,那么根据路由匹配得到的 sub-storyboard 加载它的依赖库。
11530
11712
 
11531
11713