@next-core/brick-kit 2.89.0 → 2.90.1

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)) {
@@ -1428,10 +1495,7 @@ function StoryboardFunctionRegistryFactory() {
1428
1495
  rules: {
1429
1496
  noVar: true
1430
1497
  },
1431
- globalVariables: supply(precooked.attemptToVisitGlobals, {
1432
- // Functions can call other functions.
1433
- FN: storyboardFunctions
1434
- }),
1498
+ globalVariables: supply(precooked.attemptToVisitGlobals, builtinSupply),
1435
1499
  hooks: collector && {
1436
1500
  beforeEvaluate: collector.beforeEvaluate,
1437
1501
  beforeCall: collector.beforeCall,
@@ -1456,6 +1520,19 @@ function StoryboardFunctionRegistryFactory() {
1456
1520
  };
1457
1521
  }
1458
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
+
1459
1536
  var {
1460
1537
  storyboardFunctions,
1461
1538
  registerStoryboardFunctions
@@ -1477,7 +1554,9 @@ function registerWidgetFunctions(widgetId, functions) {
1477
1554
  var {
1478
1555
  storyboardFunctions,
1479
1556
  registerStoryboardFunctions
1480
- } = StoryboardFunctionRegistryFactory();
1557
+ } = StoryboardFunctionRegistryFactory({
1558
+ widgetId
1559
+ });
1481
1560
  widgetFunctionRegistry.set(widgetId, storyboardFunctions);
1482
1561
  registerStoryboardFunctions(functions);
1483
1562
  }
@@ -1648,7 +1727,7 @@ function evaluate(raw) {
1648
1727
  }
1649
1728
 
1650
1729
  if (attemptToVisitGlobals.has("IMG")) {
1651
- globalVariables.IMG = imagesFactory(app);
1730
+ globalVariables.IMG = imagesFactory(app.id, app.isBuildPush);
1652
1731
  }
1653
1732
 
1654
1733
  if (attemptToVisitGlobals.has("__WIDGET_IMG__")) {
@@ -1656,7 +1735,11 @@ function evaluate(raw) {
1656
1735
  }
1657
1736
 
1658
1737
  if (attemptToVisitGlobals.has("I18N")) {
1659
- 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;
1660
1743
  }
1661
1744
 
1662
1745
  if (attemptToVisitGlobals.has("I18N_TEXT")) {
@@ -2448,6 +2531,8 @@ class Runtime {
2448
2531
 
2449
2532
  _defineProperty$2(this, "registerWidgetFunctions", registerWidgetFunctions);
2450
2533
 
2534
+ _defineProperty$2(this, "registerWidgetI18n", registerWidgetI18n);
2535
+
2451
2536
  _defineProperty$2(this, "getBasePath", getBasePath);
2452
2537
 
2453
2538
  _defineProperty$2(this, "getCurrentTheme", getCurrentTheme);
@@ -4752,6 +4837,26 @@ var BootstrapV2Api_bootstrapV2 = /*#__PURE__*/function () {
4752
4837
  return _ref.apply(this, arguments);
4753
4838
  };
4754
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
+ }();
4755
4860
  /**
4756
4861
  * @description 通过defaultOrg查找单个契约信息
4757
4862
  * @endpoint POST /api/contract/single_search
@@ -5765,6 +5870,18 @@ var checkLogin = /*#__PURE__*/function () {
5765
5870
  };
5766
5871
  }();
5767
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
+
5768
5885
  var getAppStoryboard = /*#__PURE__*/function () {
5769
5886
  var _ref4 = _asyncToGenerator$1(function* (appId, params, options) {
5770
5887
  return (yield http.get("api/auth/bootstrap/".concat(appId), _objectSpread2(_objectSpread2({}, options), {}, {
@@ -6202,12 +6319,17 @@ class Kernel {
6202
6319
  var _this3 = this;
6203
6320
 
6204
6321
  return _asyncToGenerator$4(function* () {
6205
- 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({
6206
6324
  appFields: "defaultConfig,userConfig,locales,name,homepage,id,currentVersion,installStatus,internal,status",
6207
6325
  ignoreTemplateFields: "templates",
6208
6326
  ignoreBrickFields: "bricks,processors,providers,editors"
6209
6327
  }, params), {
6210
6328
  interceptorParams
6329
+ }) : bootstrap(_objectSpread({
6330
+ brief: true
6331
+ }, params), {
6332
+ interceptorParams
6211
6333
  });
6212
6334
 
6213
6335
  var bootstrapResponse = _objectSpread({
@@ -6254,11 +6376,12 @@ class Kernel {
6254
6376
  $$fulfilled: true
6255
6377
  });
6256
6378
  } else {
6379
+ /* istanbul ignore next */
6257
6380
  var {
6258
6381
  routes,
6259
6382
  meta,
6260
6383
  app
6261
- } = yield getAppStoryboard(storyboard.app.id);
6384
+ } = yield localStorage.getItem("__$$use-bootstrap-v2-provider$$__") ? BootstrapV2Api_getAppStoryboardV2(storyboard.app.id, {}) : getAppStoryboard(storyboard.app.id);
6262
6385
  Object.assign(storyboard, {
6263
6386
  routes,
6264
6387
  meta,
@@ -6271,7 +6394,7 @@ class Kernel {
6271
6394
 
6272
6395
  if ((_storyboard$meta = storyboard.meta) !== null && _storyboard$meta !== void 0 && _storyboard$meta.i18n) {
6273
6396
  // Prefix to avoid conflict between brick package's i18n namespace.
6274
- 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`.
6275
6398
 
6276
6399
  Object.entries(storyboard.meta.i18n).forEach(_ref => {
6277
6400
  var [lang, resources] = _ref;
@@ -8921,12 +9044,13 @@ class Resolver {
8921
9044
  } else {
8922
9045
  var actualArgs = args ? ref ? args // `args` are already computed for `defineResolves`
8923
9046
  : context ? computeRealValue(args, context, true) : args : providerBrick.args || [];
9047
+ promise = _asyncToGenerator$4(function* () {
9048
+ if (useProvider) {
9049
+ actualArgs = yield getArgsOfCustomApi(useProvider, actualArgs);
9050
+ }
8924
9051
 
8925
- if (useProvider) {
8926
- actualArgs = yield getArgsOfCustomApi(useProvider, actualArgs);
8927
- }
8928
-
8929
- promise = providerBrick[method](...actualArgs);
9052
+ return providerBrick[method](...actualArgs);
9053
+ })();
8930
9054
 
8931
9055
  _this2.cache.set(cacheKey, promise);
8932
9056
  }
@@ -8994,7 +9118,7 @@ class Resolver {
8994
9118
 
8995
9119
  var _loop = function (providerBrick, interval) {
8996
9120
  var request = /*#__PURE__*/function () {
8997
- var _ref = _asyncToGenerator$4(function* () {
9121
+ var _ref2 = _asyncToGenerator$4(function* () {
8998
9122
  yield providerBrick.$refresh({
8999
9123
  ignoreErrors: interval.ignoreErrors,
9000
9124
  throwErrors: true,
@@ -9008,7 +9132,7 @@ class Resolver {
9008
9132
  });
9009
9133
 
9010
9134
  return function request() {
9011
- return _ref.apply(this, arguments);
9135
+ return _ref2.apply(this, arguments);
9012
9136
  };
9013
9137
  }();
9014
9138
 
@@ -9250,7 +9374,7 @@ class Router {
9250
9374
 
9251
9375
  _this3.kernel.registerCustomTemplatesInStoryboard(storyboard);
9252
9376
 
9253
- 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);
9254
9378
  }
9255
9379
 
9256
9380
  var {
@@ -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) {