@next-core/brick-kit 2.88.1 → 2.90.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
@@ -5,10 +5,10 @@ import _asyncToGenerator$4 from '@babel/runtime/helpers/asyncToGenerator';
5
5
  import _defineProperty$2 from '@babel/runtime/helpers/defineProperty';
6
6
  import * as React from 'react';
7
7
  import React__default, { useState, useEffect, forwardRef, useRef, useImperativeHandle, useMemo, useContext, createContext } from 'react';
8
- import lodash, { set, get, difference, cloneDeep, isNil, sortBy, merge, clamp, uniqueId, orderBy, omit, isEmpty } from 'lodash';
8
+ import lodash, { set, get, difference, identity, cloneDeep, isNil, sortBy, merge, clamp, uniqueId, orderBy, omit, isEmpty } from 'lodash';
9
9
  import { toPath, computeRealRoutePath, hasOwnProperty, isObject, isEvaluable, transformAndInject, transform, trackContext, scanPermissionActionsInStoryboard, precookFunction, cook, shouldAllowRecursiveEvaluations, preevaluate, inject, deepFreeze, createProviderClass, scanRouteAliasInStoryboard, loadScript, getTemplateDepsOfStoryboard, getDllAndDepsOfStoryboard, asyncProcessStoryboard, prefetchScript, scanBricksInBrickConf, scanProcessorsInAny, getDllAndDepsByResource, resolveContextConcurrently, matchPath, asyncProcessBrick, restoreDynamicTemplates, mapCustomApisToNameAndNamespace, scanCustomApisInStoryboard } from '@next-core/brick-utils';
10
10
  import { http, HttpResponseError, HttpFetchError } from '@next-core/brick-http';
11
- import i18next from 'i18next';
11
+ import i18next, { getFixedT } from 'i18next';
12
12
  import moment from 'moment';
13
13
  import { pipes } from '@next-core/pipes';
14
14
  import { userAnalytics, apiAnalyzer } from '@next-core/easyops-analytics';
@@ -668,12 +668,12 @@ function getUrlBySegueFactory(app, segues) {
668
668
  };
669
669
  }
670
670
 
671
- function imagesFactory(app) {
671
+ function imagesFactory(appId, isBuildPush) {
672
672
  return {
673
673
  get(name) {
674
674
  var _window$PUBLIC_ROOT;
675
675
 
676
- return app.isBuildPush ? "api/gateway/object_store.object_store.GetObject/api/v1/objectStore/bucket/next-builder/object/".concat(name) : "".concat((_window$PUBLIC_ROOT = window.PUBLIC_ROOT) !== null && _window$PUBLIC_ROOT !== void 0 ? _window$PUBLIC_ROOT : "", "micro-apps/").concat(app.id, "/images/").concat(name);
676
+ return isBuildPush ? "api/gateway/object_store.object_store.GetObject/api/v1/objectStore/bucket/next-builder/object/".concat(name) : "".concat((_window$PUBLIC_ROOT = window.PUBLIC_ROOT) !== null && _window$PUBLIC_ROOT !== void 0 ? _window$PUBLIC_ROOT : "", "micro-apps/").concat(appId, "/images/").concat(name);
677
677
  }
678
678
 
679
679
  };
@@ -1372,11 +1372,55 @@ function i18nText(data) {
1372
1372
  }
1373
1373
  }
1374
1374
 
1375
+ var locale$7 = {
1376
+ [K.REQUEST_FAILED]: "Request Failed",
1377
+ [K.MODAL_OK]: "Ok",
1378
+ [K.MODAL_CANCEL]: "Cancel",
1379
+ [K.SOMETHING_WENT_WRONG]: "Something went wrong!",
1380
+ [K.LOGIN_TIMEOUT_MESSAGE]: "You haven't logged in or your login session has expired. Login right now?",
1381
+ [K.NETWORK_ERROR]: "Network error, please check your network."
1382
+ };
1383
+ var en = locale$7;
1384
+
1385
+ var locale$6 = {
1386
+ [K.REQUEST_FAILED]: "请求失败",
1387
+ [K.MODAL_OK]: "确认",
1388
+ [K.MODAL_CANCEL]: "取消",
1389
+ [K.SOMETHING_WENT_WRONG]: "出现了一些问题!",
1390
+ [K.LOGIN_TIMEOUT_MESSAGE]: "您还未登录或登录信息已过期,现在重新登录?",
1391
+ [K.NETWORK_ERROR]: "网络错误,请检查您的网络连接。"
1392
+ };
1393
+ var zh = locale$6;
1394
+
1395
+ /** @internal */
1396
+
1397
+ var initI18n = () => {
1398
+ i18next.addResourceBundle("en", NS_BRICK_KIT, en);
1399
+ i18next.addResourceBundle("zh", NS_BRICK_KIT, zh);
1400
+ };
1401
+ /** @internal */
1402
+
1403
+ function getI18nNamespace(type, id) {
1404
+ return "$".concat(type, "-").concat(id);
1405
+ }
1406
+
1407
+ function registerWidgetI18n(widgetId, i18n) {
1408
+ var ns = getI18nNamespace("widget", widgetId);
1409
+ Object.entries(i18n).forEach(_ref => {
1410
+ var [lang, resources] = _ref;
1411
+ i18next.addResourceBundle(lang, ns, resources);
1412
+ });
1413
+ }
1414
+ function widgetI18nFactory(widgetId) {
1415
+ return getFixedT(null, getI18nNamespace("widget", widgetId));
1416
+ }
1417
+
1375
1418
  /** @internal */
1376
1419
 
1377
1420
  /** @internal */
1378
1421
  function StoryboardFunctionRegistryFactory() {
1379
1422
  var {
1423
+ widgetId,
1380
1424
  collectCoverage
1381
1425
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1382
1426
  var registeredFunctions = new Map(); // Use `Proxy` with a frozen target, to make a readonly function registry.
@@ -1388,7 +1432,30 @@ function StoryboardFunctionRegistryFactory() {
1388
1432
 
1389
1433
  });
1390
1434
 
1391
- function registerStoryboardFunctions(functions) {
1435
+ var builtinSupply = _objectSpread({
1436
+ // Functions can call other functions.
1437
+ FN: storyboardFunctions
1438
+ }, collectCoverage ? {
1439
+ // Fake builtin methods for tests.
1440
+ I18N: identity,
1441
+ I18N_TEXT: fakeI18nText,
1442
+ IMG: fakeImageFactory()
1443
+ } : widgetId ? {
1444
+ I18N: widgetI18nFactory(widgetId),
1445
+ I18N_TEXT: i18nText,
1446
+ IMG: widgetImagesFactory(widgetId)
1447
+ } : {
1448
+ I18N_TEXT: i18nText
1449
+ });
1450
+
1451
+ function registerStoryboardFunctions(functions, app) {
1452
+ if (app) {
1453
+ Object.assign(builtinSupply, {
1454
+ I18N: getFixedT(null, getI18nNamespace("app", app.id)),
1455
+ IMG: imagesFactory(app.id, app.isBuildPush)
1456
+ });
1457
+ }
1458
+
1392
1459
  registeredFunctions.clear();
1393
1460
 
1394
1461
  if (Array.isArray(functions)) {
@@ -1402,8 +1469,6 @@ function StoryboardFunctionRegistryFactory() {
1402
1469
  }
1403
1470
 
1404
1471
  function getStoryboardFunction(name) {
1405
- var _collector, _collector2, _collector3, _collector4;
1406
-
1407
1472
  var fn = registeredFunctions.get(name);
1408
1473
 
1409
1474
  if (!fn) {
@@ -1422,22 +1487,19 @@ function StoryboardFunctionRegistryFactory() {
1422
1487
 
1423
1488
  var precooked = precookFunction(fn.source, {
1424
1489
  typescript: fn.typescript,
1425
- hooks: {
1426
- beforeVisit: (_collector = collector) === null || _collector === void 0 ? void 0 : _collector.beforeVisit
1490
+ hooks: collector && {
1491
+ beforeVisit: collector.beforeVisit
1427
1492
  }
1428
1493
  });
1429
1494
  fn.cooked = cook(precooked.function, fn.source, {
1430
1495
  rules: {
1431
1496
  noVar: true
1432
1497
  },
1433
- globalVariables: supply(precooked.attemptToVisitGlobals, {
1434
- // Functions can call other functions.
1435
- FN: storyboardFunctions
1436
- }),
1437
- hooks: {
1438
- beforeEvaluate: (_collector2 = collector) === null || _collector2 === void 0 ? void 0 : _collector2.beforeEvaluate,
1439
- beforeCall: (_collector3 = collector) === null || _collector3 === void 0 ? void 0 : _collector3.beforeCall,
1440
- beforeBranch: (_collector4 = collector) === null || _collector4 === void 0 ? void 0 : _collector4.beforeBranch
1498
+ globalVariables: supply(precooked.attemptToVisitGlobals, builtinSupply),
1499
+ hooks: collector && {
1500
+ beforeEvaluate: collector.beforeEvaluate,
1501
+ beforeCall: collector.beforeCall,
1502
+ beforeBranch: collector.beforeBranch
1441
1503
  }
1442
1504
  });
1443
1505
  fn.processed = true;
@@ -1458,6 +1520,19 @@ function StoryboardFunctionRegistryFactory() {
1458
1520
  };
1459
1521
  }
1460
1522
 
1523
+ function fakeI18nText(data) {
1524
+ return data === null || data === void 0 ? void 0 : data.en;
1525
+ }
1526
+
1527
+ function fakeImageFactory() {
1528
+ return {
1529
+ get(name) {
1530
+ return "mock/images/".concat(name);
1531
+ }
1532
+
1533
+ };
1534
+ }
1535
+
1461
1536
  var {
1462
1537
  storyboardFunctions,
1463
1538
  registerStoryboardFunctions
@@ -1479,7 +1554,9 @@ function registerWidgetFunctions(widgetId, functions) {
1479
1554
  var {
1480
1555
  storyboardFunctions,
1481
1556
  registerStoryboardFunctions
1482
- } = StoryboardFunctionRegistryFactory();
1557
+ } = StoryboardFunctionRegistryFactory({
1558
+ widgetId
1559
+ });
1483
1560
  widgetFunctionRegistry.set(widgetId, storyboardFunctions);
1484
1561
  registerStoryboardFunctions(functions);
1485
1562
  }
@@ -1650,7 +1727,7 @@ function evaluate(raw) {
1650
1727
  }
1651
1728
 
1652
1729
  if (attemptToVisitGlobals.has("IMG")) {
1653
- globalVariables.IMG = imagesFactory(app);
1730
+ globalVariables.IMG = imagesFactory(app.id, app.isBuildPush);
1654
1731
  }
1655
1732
 
1656
1733
  if (attemptToVisitGlobals.has("__WIDGET_IMG__")) {
@@ -1658,7 +1735,11 @@ function evaluate(raw) {
1658
1735
  }
1659
1736
 
1660
1737
  if (attemptToVisitGlobals.has("I18N")) {
1661
- globalVariables.I18N = i18next.getFixedT(null, "$app-".concat(app.id));
1738
+ globalVariables.I18N = i18next.getFixedT(null, getI18nNamespace("app", app.id));
1739
+ }
1740
+
1741
+ if (attemptToVisitGlobals.has("__WIDGET_I18N__")) {
1742
+ globalVariables.__WIDGET_I18N__ = widgetI18nFactory;
1662
1743
  }
1663
1744
 
1664
1745
  if (attemptToVisitGlobals.has("I18N_TEXT")) {
@@ -2450,6 +2531,8 @@ class Runtime {
2450
2531
 
2451
2532
  _defineProperty$2(this, "registerWidgetFunctions", registerWidgetFunctions);
2452
2533
 
2534
+ _defineProperty$2(this, "registerWidgetI18n", registerWidgetI18n);
2535
+
2453
2536
  _defineProperty$2(this, "getBasePath", getBasePath);
2454
2537
 
2455
2538
  _defineProperty$2(this, "getCurrentTheme", getCurrentTheme);
@@ -4754,6 +4837,26 @@ var BootstrapV2Api_bootstrapV2 = /*#__PURE__*/function () {
4754
4837
  return _ref.apply(this, arguments);
4755
4838
  };
4756
4839
  }();
4840
+ /**
4841
+ * @description 获取app storyboard初始化信息
4842
+ * @endpoint GET /api/auth/v2/bootstrap/:appId
4843
+ */
4844
+
4845
+
4846
+ var BootstrapV2Api_getAppStoryboardV2 = /*#__PURE__*/function () {
4847
+ var _ref = _asyncToGenerator$4(function* (appId, params, options) {
4848
+ return (
4849
+ /**! @contract easyops.api.api_gateway.bootstrap_v2.GetAppStoryboardV2@1.0.0 */
4850
+ (yield http.get("api/auth/v2/bootstrap/".concat(appId), _objectSpread(_objectSpread({}, options), {}, {
4851
+ params
4852
+ }))).data
4853
+ );
4854
+ });
4855
+
4856
+ return function BootstrapV2Api_getAppStoryboardV2(_x, _x2, _x3) {
4857
+ return _ref.apply(this, arguments);
4858
+ };
4859
+ }();
4757
4860
  /**
4758
4861
  * @description 通过defaultOrg查找单个契约信息
4759
4862
  * @endpoint POST /api/contract/single_search
@@ -5767,6 +5870,18 @@ var checkLogin = /*#__PURE__*/function () {
5767
5870
  };
5768
5871
  }();
5769
5872
 
5873
+ var bootstrap = /*#__PURE__*/function () {
5874
+ var _ref3 = _asyncToGenerator$1(function* (params, options) {
5875
+ return (yield http.get("api/auth/bootstrap", _objectSpread2(_objectSpread2({}, options), {}, {
5876
+ params
5877
+ }))).data;
5878
+ });
5879
+
5880
+ return function bootstrap(_x4, _x5) {
5881
+ return _ref3.apply(this, arguments);
5882
+ };
5883
+ }();
5884
+
5770
5885
  var getAppStoryboard = /*#__PURE__*/function () {
5771
5886
  var _ref4 = _asyncToGenerator$1(function* (appId, params, options) {
5772
5887
  return (yield http.get("api/auth/bootstrap/".concat(appId), _objectSpread2(_objectSpread2({}, options), {}, {
@@ -6204,12 +6319,17 @@ class Kernel {
6204
6319
  var _this3 = this;
6205
6320
 
6206
6321
  return _asyncToGenerator$4(function* () {
6207
- var data = yield window.STANDALONE_MICRO_APPS ? standaloneBootstrap() : BootstrapV2Api_bootstrapV2(_objectSpread({
6322
+ // Todo(jojiang): boostrap V2 接口测试通过后移除 V1 版本的兼容
6323
+ var data = yield window.STANDALONE_MICRO_APPS ? standaloneBootstrap() : localStorage.getItem("__$$use-bootstrap-v2-provider$$__") ? BootstrapV2Api_bootstrapV2(_objectSpread({
6208
6324
  appFields: "defaultConfig,userConfig,locales,name,homepage,id,currentVersion,installStatus,internal,status",
6209
6325
  ignoreTemplateFields: "templates",
6210
6326
  ignoreBrickFields: "bricks,processors,providers,editors"
6211
6327
  }, params), {
6212
6328
  interceptorParams
6329
+ }) : bootstrap(_objectSpread({
6330
+ brief: true
6331
+ }, params), {
6332
+ interceptorParams
6213
6333
  });
6214
6334
 
6215
6335
  var bootstrapResponse = _objectSpread({
@@ -6256,11 +6376,12 @@ class Kernel {
6256
6376
  $$fulfilled: true
6257
6377
  });
6258
6378
  } else {
6379
+ /* istanbul ignore next */
6259
6380
  var {
6260
6381
  routes,
6261
6382
  meta,
6262
6383
  app
6263
- } = yield getAppStoryboard(storyboard.app.id);
6384
+ } = yield localStorage.getItem("__$$use-bootstrap-v2-provider$$__") ? BootstrapV2Api_getAppStoryboardV2(storyboard.app.id, {}) : getAppStoryboard(storyboard.app.id);
6264
6385
  Object.assign(storyboard, {
6265
6386
  routes,
6266
6387
  meta,
@@ -6273,7 +6394,7 @@ class Kernel {
6273
6394
 
6274
6395
  if ((_storyboard$meta = storyboard.meta) !== null && _storyboard$meta !== void 0 && _storyboard$meta.i18n) {
6275
6396
  // Prefix to avoid conflict between brick package's i18n namespace.
6276
- var i18nNamespace = "$app-".concat(storyboard.app.id); // Support any language in `meta.i18n`.
6397
+ var i18nNamespace = getI18nNamespace("app", storyboard.app.id); // Support any language in `meta.i18n`.
6277
6398
 
6278
6399
  Object.entries(storyboard.meta.i18n).forEach(_ref => {
6279
6400
  var [lang, resources] = _ref;
@@ -8923,12 +9044,13 @@ class Resolver {
8923
9044
  } else {
8924
9045
  var actualArgs = args ? ref ? args // `args` are already computed for `defineResolves`
8925
9046
  : context ? computeRealValue(args, context, true) : args : providerBrick.args || [];
9047
+ promise = _asyncToGenerator$4(function* () {
9048
+ if (useProvider) {
9049
+ actualArgs = yield getArgsOfCustomApi(useProvider, actualArgs);
9050
+ }
8926
9051
 
8927
- if (useProvider) {
8928
- actualArgs = yield getArgsOfCustomApi(useProvider, actualArgs);
8929
- }
8930
-
8931
- promise = providerBrick[method](...actualArgs);
9052
+ return providerBrick[method](...actualArgs);
9053
+ })();
8932
9054
 
8933
9055
  _this2.cache.set(cacheKey, promise);
8934
9056
  }
@@ -8996,7 +9118,7 @@ class Resolver {
8996
9118
 
8997
9119
  var _loop = function (providerBrick, interval) {
8998
9120
  var request = /*#__PURE__*/function () {
8999
- var _ref = _asyncToGenerator$4(function* () {
9121
+ var _ref2 = _asyncToGenerator$4(function* () {
9000
9122
  yield providerBrick.$refresh({
9001
9123
  ignoreErrors: interval.ignoreErrors,
9002
9124
  throwErrors: true,
@@ -9010,7 +9132,7 @@ class Resolver {
9010
9132
  });
9011
9133
 
9012
9134
  return function request() {
9013
- return _ref.apply(this, arguments);
9135
+ return _ref2.apply(this, arguments);
9014
9136
  };
9015
9137
  }();
9016
9138
 
@@ -9252,7 +9374,7 @@ class Router {
9252
9374
 
9253
9375
  _this3.kernel.registerCustomTemplatesInStoryboard(storyboard);
9254
9376
 
9255
- registerStoryboardFunctions((_storyboard$meta = storyboard.meta) === null || _storyboard$meta === void 0 ? void 0 : _storyboard$meta.functions);
9377
+ registerStoryboardFunctions((_storyboard$meta = storyboard.meta) === null || _storyboard$meta === void 0 ? void 0 : _storyboard$meta.functions, storyboard.app);
9256
9378
  }
9257
9379
 
9258
9380
  var {
@@ -9275,6 +9397,8 @@ class Router {
9275
9397
  };
9276
9398
 
9277
9399
  if (storyboard) {
9400
+ var _currentApp$breadcrum, _currentApp$breadcrum2;
9401
+
9278
9402
  if (appChanged && currentApp.id && isLoggedIn()) {
9279
9403
  var usedCustomApis = mapCustomApisToNameAndNamespace(scanCustomApisInStoryboard(storyboard));
9280
9404
 
@@ -9291,7 +9415,7 @@ class Router {
9291
9415
  appBar: {
9292
9416
  breadcrumb: [],
9293
9417
  documentId: null,
9294
- noCurrentApp: false
9418
+ noCurrentApp: (_currentApp$breadcrum = (_currentApp$breadcrum2 = currentApp.breadcrumb) === null || _currentApp$breadcrum2 === void 0 ? void 0 : _currentApp$breadcrum2.noCurrentApp) !== null && _currentApp$breadcrum !== void 0 ? _currentApp$breadcrum : false
9295
9419
  },
9296
9420
  flags: {
9297
9421
  redirect: undefined,
@@ -9576,33 +9700,6 @@ function getRuntime() {
9576
9700
  return runtime;
9577
9701
  }
9578
9702
 
9579
- var locale$7 = {
9580
- [K.REQUEST_FAILED]: "Request Failed",
9581
- [K.MODAL_OK]: "Ok",
9582
- [K.MODAL_CANCEL]: "Cancel",
9583
- [K.SOMETHING_WENT_WRONG]: "Something went wrong!",
9584
- [K.LOGIN_TIMEOUT_MESSAGE]: "You haven't logged in or your login session has expired. Login right now?",
9585
- [K.NETWORK_ERROR]: "Network error, please check your network."
9586
- };
9587
- var en = locale$7;
9588
-
9589
- var locale$6 = {
9590
- [K.REQUEST_FAILED]: "请求失败",
9591
- [K.MODAL_OK]: "确认",
9592
- [K.MODAL_CANCEL]: "取消",
9593
- [K.SOMETHING_WENT_WRONG]: "出现了一些问题!",
9594
- [K.LOGIN_TIMEOUT_MESSAGE]: "您还未登录或登录信息已过期,现在重新登录?",
9595
- [K.NETWORK_ERROR]: "网络错误,请检查您的网络连接。"
9596
- };
9597
- var zh = locale$6;
9598
-
9599
- /** @internal */
9600
-
9601
- var initI18n = () => {
9602
- i18next.addResourceBundle("en", NS_BRICK_KIT, en);
9603
- i18next.addResourceBundle("zh", NS_BRICK_KIT, zh);
9604
- };
9605
-
9606
9703
  // Ref https://reactjs.org/docs/error-boundaries.html
9607
9704
  class LegacyErrorBoundary extends React__default.Component {
9608
9705
  constructor(props) {