@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/CHANGELOG.md CHANGED
@@ -3,6 +3,62 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [2.90.0](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.89.2...@next-core/brick-kit@2.90.0) (2021-11-26)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * fix a regression of caching resolves ([e9cd56d](https://github.com/easyops-cn/next-core/commit/e9cd56d882d0a13ee1cb13c4ed752a15f2c15bfd))
12
+
13
+
14
+ ### Features
15
+
16
+ * support i18n in storyboard functions ([5891932](https://github.com/easyops-cn/next-core/commit/589193250f22735b20e93d32c807896f4ae0932b))
17
+ * support i18n in widgets ([6020545](https://github.com/easyops-cn/next-core/commit/60205457fedbc7c000bb60b1e97729e3151be33d))
18
+ * support img in widgets ([f19ad53](https://github.com/easyops-cn/next-core/commit/f19ad5329b95c71e612f4be0ffa57b5a3d9ec570))
19
+
20
+
21
+
22
+
23
+
24
+ ## [2.89.2](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.89.1...@next-core/brick-kit@2.89.2) (2021-11-25)
25
+
26
+
27
+ ### Bug Fixes
28
+
29
+ * get stroyboard v2 ([602d086](https://github.com/easyops-cn/next-core/commit/602d0860fc6c7c9e5ffc116ff023addb0f57efe1))
30
+
31
+
32
+
33
+
34
+
35
+ ## [2.89.1](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.89.0...@next-core/brick-kit@2.89.1) (2021-11-25)
36
+
37
+
38
+ ### Bug Fixes
39
+
40
+ * bootsrtrap 增加开关控制 ([360b913](https://github.com/easyops-cn/next-core/commit/360b913f324f10ac79b1d637ec598583a89a61da))
41
+
42
+
43
+
44
+
45
+
46
+ # [2.89.0](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.88.1...@next-core/brick-kit@2.89.0) (2021-11-25)
47
+
48
+
49
+ ### Bug Fixes
50
+
51
+ * refine storyboard function ([90c42c1](https://github.com/easyops-cn/next-core/commit/90c42c1f49a7d7e8297d424bd02a3957787fb8e3))
52
+
53
+
54
+ ### Features
55
+
56
+ * use global noCurrentApp as default ([4e18163](https://github.com/easyops-cn/next-core/commit/4e18163eeefa24cb022cb9b936746c9e7ad80e70))
57
+
58
+
59
+
60
+
61
+
6
62
  ## [2.88.1](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.88.0...@next-core/brick-kit@2.88.1) (2021-11-25)
7
63
 
8
64
 
@@ -685,12 +685,12 @@
685
685
  };
686
686
  }
687
687
 
688
- function imagesFactory(app) {
688
+ function imagesFactory(appId, isBuildPush) {
689
689
  return {
690
690
  get(name) {
691
691
  var _window$PUBLIC_ROOT;
692
692
 
693
- 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);
693
+ 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);
694
694
  }
695
695
 
696
696
  };
@@ -1389,11 +1389,55 @@
1389
1389
  }
1390
1390
  }
1391
1391
 
1392
+ var locale$7 = {
1393
+ [K.REQUEST_FAILED]: "Request Failed",
1394
+ [K.MODAL_OK]: "Ok",
1395
+ [K.MODAL_CANCEL]: "Cancel",
1396
+ [K.SOMETHING_WENT_WRONG]: "Something went wrong!",
1397
+ [K.LOGIN_TIMEOUT_MESSAGE]: "You haven't logged in or your login session has expired. Login right now?",
1398
+ [K.NETWORK_ERROR]: "Network error, please check your network."
1399
+ };
1400
+ var en = locale$7;
1401
+
1402
+ var locale$6 = {
1403
+ [K.REQUEST_FAILED]: "请求失败",
1404
+ [K.MODAL_OK]: "确认",
1405
+ [K.MODAL_CANCEL]: "取消",
1406
+ [K.SOMETHING_WENT_WRONG]: "出现了一些问题!",
1407
+ [K.LOGIN_TIMEOUT_MESSAGE]: "您还未登录或登录信息已过期,现在重新登录?",
1408
+ [K.NETWORK_ERROR]: "网络错误,请检查您的网络连接。"
1409
+ };
1410
+ var zh = locale$6;
1411
+
1412
+ /** @internal */
1413
+
1414
+ var initI18n = () => {
1415
+ i18next__default["default"].addResourceBundle("en", NS_BRICK_KIT, en);
1416
+ i18next__default["default"].addResourceBundle("zh", NS_BRICK_KIT, zh);
1417
+ };
1418
+ /** @internal */
1419
+
1420
+ function getI18nNamespace(type, id) {
1421
+ return "$".concat(type, "-").concat(id);
1422
+ }
1423
+
1424
+ function registerWidgetI18n(widgetId, i18n) {
1425
+ var ns = getI18nNamespace("widget", widgetId);
1426
+ Object.entries(i18n).forEach(_ref => {
1427
+ var [lang, resources] = _ref;
1428
+ i18next__default["default"].addResourceBundle(lang, ns, resources);
1429
+ });
1430
+ }
1431
+ function widgetI18nFactory(widgetId) {
1432
+ return i18next.getFixedT(null, getI18nNamespace("widget", widgetId));
1433
+ }
1434
+
1392
1435
  /** @internal */
1393
1436
 
1394
1437
  /** @internal */
1395
1438
  function StoryboardFunctionRegistryFactory() {
1396
1439
  var {
1440
+ widgetId,
1397
1441
  collectCoverage
1398
1442
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1399
1443
  var registeredFunctions = new Map(); // Use `Proxy` with a frozen target, to make a readonly function registry.
@@ -1405,7 +1449,30 @@
1405
1449
 
1406
1450
  });
1407
1451
 
1408
- function registerStoryboardFunctions(functions) {
1452
+ var builtinSupply = _objectSpread__default["default"]({
1453
+ // Functions can call other functions.
1454
+ FN: storyboardFunctions
1455
+ }, collectCoverage ? {
1456
+ // Fake builtin methods for tests.
1457
+ I18N: lodash.identity,
1458
+ I18N_TEXT: fakeI18nText,
1459
+ IMG: fakeImageFactory()
1460
+ } : widgetId ? {
1461
+ I18N: widgetI18nFactory(widgetId),
1462
+ I18N_TEXT: i18nText,
1463
+ IMG: widgetImagesFactory(widgetId)
1464
+ } : {
1465
+ I18N_TEXT: i18nText
1466
+ });
1467
+
1468
+ function registerStoryboardFunctions(functions, app) {
1469
+ if (app) {
1470
+ Object.assign(builtinSupply, {
1471
+ I18N: i18next.getFixedT(null, getI18nNamespace("app", app.id)),
1472
+ IMG: imagesFactory(app.id, app.isBuildPush)
1473
+ });
1474
+ }
1475
+
1409
1476
  registeredFunctions.clear();
1410
1477
 
1411
1478
  if (Array.isArray(functions)) {
@@ -1419,8 +1486,6 @@
1419
1486
  }
1420
1487
 
1421
1488
  function getStoryboardFunction(name) {
1422
- var _collector, _collector2, _collector3, _collector4;
1423
-
1424
1489
  var fn = registeredFunctions.get(name);
1425
1490
 
1426
1491
  if (!fn) {
@@ -1439,22 +1504,19 @@
1439
1504
 
1440
1505
  var precooked = brickUtils.precookFunction(fn.source, {
1441
1506
  typescript: fn.typescript,
1442
- hooks: {
1443
- beforeVisit: (_collector = collector) === null || _collector === void 0 ? void 0 : _collector.beforeVisit
1507
+ hooks: collector && {
1508
+ beforeVisit: collector.beforeVisit
1444
1509
  }
1445
1510
  });
1446
1511
  fn.cooked = brickUtils.cook(precooked.function, fn.source, {
1447
1512
  rules: {
1448
1513
  noVar: true
1449
1514
  },
1450
- globalVariables: supply(precooked.attemptToVisitGlobals, {
1451
- // Functions can call other functions.
1452
- FN: storyboardFunctions
1453
- }),
1454
- hooks: {
1455
- beforeEvaluate: (_collector2 = collector) === null || _collector2 === void 0 ? void 0 : _collector2.beforeEvaluate,
1456
- beforeCall: (_collector3 = collector) === null || _collector3 === void 0 ? void 0 : _collector3.beforeCall,
1457
- beforeBranch: (_collector4 = collector) === null || _collector4 === void 0 ? void 0 : _collector4.beforeBranch
1515
+ globalVariables: supply(precooked.attemptToVisitGlobals, builtinSupply),
1516
+ hooks: collector && {
1517
+ beforeEvaluate: collector.beforeEvaluate,
1518
+ beforeCall: collector.beforeCall,
1519
+ beforeBranch: collector.beforeBranch
1458
1520
  }
1459
1521
  });
1460
1522
  fn.processed = true;
@@ -1475,6 +1537,19 @@
1475
1537
  };
1476
1538
  }
1477
1539
 
1540
+ function fakeI18nText(data) {
1541
+ return data === null || data === void 0 ? void 0 : data.en;
1542
+ }
1543
+
1544
+ function fakeImageFactory() {
1545
+ return {
1546
+ get(name) {
1547
+ return "mock/images/".concat(name);
1548
+ }
1549
+
1550
+ };
1551
+ }
1552
+
1478
1553
  var {
1479
1554
  storyboardFunctions,
1480
1555
  registerStoryboardFunctions
@@ -1496,7 +1571,9 @@
1496
1571
  var {
1497
1572
  storyboardFunctions,
1498
1573
  registerStoryboardFunctions
1499
- } = StoryboardFunctionRegistryFactory();
1574
+ } = StoryboardFunctionRegistryFactory({
1575
+ widgetId
1576
+ });
1500
1577
  widgetFunctionRegistry.set(widgetId, storyboardFunctions);
1501
1578
  registerStoryboardFunctions(functions);
1502
1579
  }
@@ -1667,7 +1744,7 @@
1667
1744
  }
1668
1745
 
1669
1746
  if (attemptToVisitGlobals.has("IMG")) {
1670
- globalVariables.IMG = imagesFactory(app);
1747
+ globalVariables.IMG = imagesFactory(app.id, app.isBuildPush);
1671
1748
  }
1672
1749
 
1673
1750
  if (attemptToVisitGlobals.has("__WIDGET_IMG__")) {
@@ -1675,7 +1752,11 @@
1675
1752
  }
1676
1753
 
1677
1754
  if (attemptToVisitGlobals.has("I18N")) {
1678
- globalVariables.I18N = i18next__default["default"].getFixedT(null, "$app-".concat(app.id));
1755
+ globalVariables.I18N = i18next__default["default"].getFixedT(null, getI18nNamespace("app", app.id));
1756
+ }
1757
+
1758
+ if (attemptToVisitGlobals.has("__WIDGET_I18N__")) {
1759
+ globalVariables.__WIDGET_I18N__ = widgetI18nFactory;
1679
1760
  }
1680
1761
 
1681
1762
  if (attemptToVisitGlobals.has("I18N_TEXT")) {
@@ -2467,6 +2548,8 @@
2467
2548
 
2468
2549
  _defineProperty__default["default"](this, "registerWidgetFunctions", registerWidgetFunctions);
2469
2550
 
2551
+ _defineProperty__default["default"](this, "registerWidgetI18n", registerWidgetI18n);
2552
+
2470
2553
  _defineProperty__default["default"](this, "getBasePath", getBasePath);
2471
2554
 
2472
2555
  _defineProperty__default["default"](this, "getCurrentTheme", getCurrentTheme);
@@ -4771,6 +4854,26 @@
4771
4854
  return _ref.apply(this, arguments);
4772
4855
  };
4773
4856
  }();
4857
+ /**
4858
+ * @description 获取app storyboard初始化信息
4859
+ * @endpoint GET /api/auth/v2/bootstrap/:appId
4860
+ */
4861
+
4862
+
4863
+ var BootstrapV2Api_getAppStoryboardV2 = /*#__PURE__*/function () {
4864
+ var _ref = _asyncToGenerator__default["default"](function* (appId, params, options) {
4865
+ return (
4866
+ /**! @contract easyops.api.api_gateway.bootstrap_v2.GetAppStoryboardV2@1.0.0 */
4867
+ (yield brickHttp.http.get("api/auth/v2/bootstrap/".concat(appId), _objectSpread__default["default"](_objectSpread__default["default"]({}, options), {}, {
4868
+ params
4869
+ }))).data
4870
+ );
4871
+ });
4872
+
4873
+ return function BootstrapV2Api_getAppStoryboardV2(_x, _x2, _x3) {
4874
+ return _ref.apply(this, arguments);
4875
+ };
4876
+ }();
4774
4877
  /**
4775
4878
  * @description 通过defaultOrg查找单个契约信息
4776
4879
  * @endpoint POST /api/contract/single_search
@@ -5784,6 +5887,18 @@
5784
5887
  };
5785
5888
  }();
5786
5889
 
5890
+ var bootstrap = /*#__PURE__*/function () {
5891
+ var _ref3 = _asyncToGenerator$1(function* (params, options) {
5892
+ return (yield brickHttp.http.get("api/auth/bootstrap", _objectSpread2(_objectSpread2({}, options), {}, {
5893
+ params
5894
+ }))).data;
5895
+ });
5896
+
5897
+ return function bootstrap(_x4, _x5) {
5898
+ return _ref3.apply(this, arguments);
5899
+ };
5900
+ }();
5901
+
5787
5902
  var getAppStoryboard = /*#__PURE__*/function () {
5788
5903
  var _ref4 = _asyncToGenerator$1(function* (appId, params, options) {
5789
5904
  return (yield brickHttp.http.get("api/auth/bootstrap/".concat(appId), _objectSpread2(_objectSpread2({}, options), {}, {
@@ -6221,12 +6336,17 @@
6221
6336
  var _this3 = this;
6222
6337
 
6223
6338
  return _asyncToGenerator__default["default"](function* () {
6224
- var data = yield window.STANDALONE_MICRO_APPS ? standaloneBootstrap() : BootstrapV2Api_bootstrapV2(_objectSpread__default["default"]({
6339
+ // Todo(jojiang): boostrap V2 接口测试通过后移除 V1 版本的兼容
6340
+ var data = yield window.STANDALONE_MICRO_APPS ? standaloneBootstrap() : localStorage.getItem("__$$use-bootstrap-v2-provider$$__") ? BootstrapV2Api_bootstrapV2(_objectSpread__default["default"]({
6225
6341
  appFields: "defaultConfig,userConfig,locales,name,homepage,id,currentVersion,installStatus,internal,status",
6226
6342
  ignoreTemplateFields: "templates",
6227
6343
  ignoreBrickFields: "bricks,processors,providers,editors"
6228
6344
  }, params), {
6229
6345
  interceptorParams
6346
+ }) : bootstrap(_objectSpread__default["default"]({
6347
+ brief: true
6348
+ }, params), {
6349
+ interceptorParams
6230
6350
  });
6231
6351
 
6232
6352
  var bootstrapResponse = _objectSpread__default["default"]({
@@ -6273,11 +6393,12 @@
6273
6393
  $$fulfilled: true
6274
6394
  });
6275
6395
  } else {
6396
+ /* istanbul ignore next */
6276
6397
  var {
6277
6398
  routes,
6278
6399
  meta,
6279
6400
  app
6280
- } = yield getAppStoryboard(storyboard.app.id);
6401
+ } = yield localStorage.getItem("__$$use-bootstrap-v2-provider$$__") ? BootstrapV2Api_getAppStoryboardV2(storyboard.app.id, {}) : getAppStoryboard(storyboard.app.id);
6281
6402
  Object.assign(storyboard, {
6282
6403
  routes,
6283
6404
  meta,
@@ -6290,7 +6411,7 @@
6290
6411
 
6291
6412
  if ((_storyboard$meta = storyboard.meta) !== null && _storyboard$meta !== void 0 && _storyboard$meta.i18n) {
6292
6413
  // Prefix to avoid conflict between brick package's i18n namespace.
6293
- var i18nNamespace = "$app-".concat(storyboard.app.id); // Support any language in `meta.i18n`.
6414
+ var i18nNamespace = getI18nNamespace("app", storyboard.app.id); // Support any language in `meta.i18n`.
6294
6415
 
6295
6416
  Object.entries(storyboard.meta.i18n).forEach(_ref => {
6296
6417
  var [lang, resources] = _ref;
@@ -8940,12 +9061,13 @@
8940
9061
  } else {
8941
9062
  var actualArgs = args ? ref ? args // `args` are already computed for `defineResolves`
8942
9063
  : context ? computeRealValue(args, context, true) : args : providerBrick.args || [];
9064
+ promise = _asyncToGenerator__default["default"](function* () {
9065
+ if (useProvider) {
9066
+ actualArgs = yield getArgsOfCustomApi(useProvider, actualArgs);
9067
+ }
8943
9068
 
8944
- if (useProvider) {
8945
- actualArgs = yield getArgsOfCustomApi(useProvider, actualArgs);
8946
- }
8947
-
8948
- promise = providerBrick[method](...actualArgs);
9069
+ return providerBrick[method](...actualArgs);
9070
+ })();
8949
9071
 
8950
9072
  _this2.cache.set(cacheKey, promise);
8951
9073
  }
@@ -9013,7 +9135,7 @@
9013
9135
 
9014
9136
  var _loop = function (providerBrick, interval) {
9015
9137
  var request = /*#__PURE__*/function () {
9016
- var _ref = _asyncToGenerator__default["default"](function* () {
9138
+ var _ref2 = _asyncToGenerator__default["default"](function* () {
9017
9139
  yield providerBrick.$refresh({
9018
9140
  ignoreErrors: interval.ignoreErrors,
9019
9141
  throwErrors: true,
@@ -9027,7 +9149,7 @@
9027
9149
  });
9028
9150
 
9029
9151
  return function request() {
9030
- return _ref.apply(this, arguments);
9152
+ return _ref2.apply(this, arguments);
9031
9153
  };
9032
9154
  }();
9033
9155
 
@@ -9269,7 +9391,7 @@
9269
9391
 
9270
9392
  _this3.kernel.registerCustomTemplatesInStoryboard(storyboard);
9271
9393
 
9272
- registerStoryboardFunctions((_storyboard$meta = storyboard.meta) === null || _storyboard$meta === void 0 ? void 0 : _storyboard$meta.functions);
9394
+ registerStoryboardFunctions((_storyboard$meta = storyboard.meta) === null || _storyboard$meta === void 0 ? void 0 : _storyboard$meta.functions, storyboard.app);
9273
9395
  }
9274
9396
 
9275
9397
  var {
@@ -9292,6 +9414,8 @@
9292
9414
  };
9293
9415
 
9294
9416
  if (storyboard) {
9417
+ var _currentApp$breadcrum, _currentApp$breadcrum2;
9418
+
9295
9419
  if (appChanged && currentApp.id && isLoggedIn()) {
9296
9420
  var usedCustomApis = brickUtils.mapCustomApisToNameAndNamespace(brickUtils.scanCustomApisInStoryboard(storyboard));
9297
9421
 
@@ -9308,7 +9432,7 @@
9308
9432
  appBar: {
9309
9433
  breadcrumb: [],
9310
9434
  documentId: null,
9311
- noCurrentApp: false
9435
+ 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
9312
9436
  },
9313
9437
  flags: {
9314
9438
  redirect: undefined,
@@ -9593,33 +9717,6 @@
9593
9717
  return runtime;
9594
9718
  }
9595
9719
 
9596
- var locale$7 = {
9597
- [K.REQUEST_FAILED]: "Request Failed",
9598
- [K.MODAL_OK]: "Ok",
9599
- [K.MODAL_CANCEL]: "Cancel",
9600
- [K.SOMETHING_WENT_WRONG]: "Something went wrong!",
9601
- [K.LOGIN_TIMEOUT_MESSAGE]: "You haven't logged in or your login session has expired. Login right now?",
9602
- [K.NETWORK_ERROR]: "Network error, please check your network."
9603
- };
9604
- var en = locale$7;
9605
-
9606
- var locale$6 = {
9607
- [K.REQUEST_FAILED]: "请求失败",
9608
- [K.MODAL_OK]: "确认",
9609
- [K.MODAL_CANCEL]: "取消",
9610
- [K.SOMETHING_WENT_WRONG]: "出现了一些问题!",
9611
- [K.LOGIN_TIMEOUT_MESSAGE]: "您还未登录或登录信息已过期,现在重新登录?",
9612
- [K.NETWORK_ERROR]: "网络错误,请检查您的网络连接。"
9613
- };
9614
- var zh = locale$6;
9615
-
9616
- /** @internal */
9617
-
9618
- var initI18n = () => {
9619
- i18next__default["default"].addResourceBundle("en", NS_BRICK_KIT, en);
9620
- i18next__default["default"].addResourceBundle("zh", NS_BRICK_KIT, zh);
9621
- };
9622
-
9623
9720
  // Ref https://reactjs.org/docs/error-boundaries.html
9624
9721
  class LegacyErrorBoundary extends React__default["default"].Component {
9625
9722
  constructor(props) {