@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/CHANGELOG.md CHANGED
@@ -3,6 +3,54 @@
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.1](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.90.0...@next-core/brick-kit@2.90.1) (2021-11-29)
7
+
8
+ **Note:** Version bump only for package @next-core/brick-kit
9
+
10
+
11
+
12
+
13
+
14
+ # [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)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * fix a regression of caching resolves ([e9cd56d](https://github.com/easyops-cn/next-core/commit/e9cd56d882d0a13ee1cb13c4ed752a15f2c15bfd))
20
+
21
+
22
+ ### Features
23
+
24
+ * support i18n in storyboard functions ([5891932](https://github.com/easyops-cn/next-core/commit/589193250f22735b20e93d32c807896f4ae0932b))
25
+ * support i18n in widgets ([6020545](https://github.com/easyops-cn/next-core/commit/60205457fedbc7c000bb60b1e97729e3151be33d))
26
+ * support img in widgets ([f19ad53](https://github.com/easyops-cn/next-core/commit/f19ad5329b95c71e612f4be0ffa57b5a3d9ec570))
27
+
28
+
29
+
30
+
31
+
32
+ ## [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)
33
+
34
+
35
+ ### Bug Fixes
36
+
37
+ * get stroyboard v2 ([602d086](https://github.com/easyops-cn/next-core/commit/602d0860fc6c7c9e5ffc116ff023addb0f57efe1))
38
+
39
+
40
+
41
+
42
+
43
+ ## [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)
44
+
45
+
46
+ ### Bug Fixes
47
+
48
+ * bootsrtrap 增加开关控制 ([360b913](https://github.com/easyops-cn/next-core/commit/360b913f324f10ac79b1d637ec598583a89a61da))
49
+
50
+
51
+
52
+
53
+
6
54
  # [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)
7
55
 
8
56
 
@@ -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)) {
@@ -1445,10 +1512,7 @@
1445
1512
  rules: {
1446
1513
  noVar: true
1447
1514
  },
1448
- globalVariables: supply(precooked.attemptToVisitGlobals, {
1449
- // Functions can call other functions.
1450
- FN: storyboardFunctions
1451
- }),
1515
+ globalVariables: supply(precooked.attemptToVisitGlobals, builtinSupply),
1452
1516
  hooks: collector && {
1453
1517
  beforeEvaluate: collector.beforeEvaluate,
1454
1518
  beforeCall: collector.beforeCall,
@@ -1473,6 +1537,19 @@
1473
1537
  };
1474
1538
  }
1475
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
+
1476
1553
  var {
1477
1554
  storyboardFunctions,
1478
1555
  registerStoryboardFunctions
@@ -1494,7 +1571,9 @@
1494
1571
  var {
1495
1572
  storyboardFunctions,
1496
1573
  registerStoryboardFunctions
1497
- } = StoryboardFunctionRegistryFactory();
1574
+ } = StoryboardFunctionRegistryFactory({
1575
+ widgetId
1576
+ });
1498
1577
  widgetFunctionRegistry.set(widgetId, storyboardFunctions);
1499
1578
  registerStoryboardFunctions(functions);
1500
1579
  }
@@ -1665,7 +1744,7 @@
1665
1744
  }
1666
1745
 
1667
1746
  if (attemptToVisitGlobals.has("IMG")) {
1668
- globalVariables.IMG = imagesFactory(app);
1747
+ globalVariables.IMG = imagesFactory(app.id, app.isBuildPush);
1669
1748
  }
1670
1749
 
1671
1750
  if (attemptToVisitGlobals.has("__WIDGET_IMG__")) {
@@ -1673,7 +1752,11 @@
1673
1752
  }
1674
1753
 
1675
1754
  if (attemptToVisitGlobals.has("I18N")) {
1676
- 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;
1677
1760
  }
1678
1761
 
1679
1762
  if (attemptToVisitGlobals.has("I18N_TEXT")) {
@@ -2465,6 +2548,8 @@
2465
2548
 
2466
2549
  _defineProperty__default["default"](this, "registerWidgetFunctions", registerWidgetFunctions);
2467
2550
 
2551
+ _defineProperty__default["default"](this, "registerWidgetI18n", registerWidgetI18n);
2552
+
2468
2553
  _defineProperty__default["default"](this, "getBasePath", getBasePath);
2469
2554
 
2470
2555
  _defineProperty__default["default"](this, "getCurrentTheme", getCurrentTheme);
@@ -4769,6 +4854,26 @@
4769
4854
  return _ref.apply(this, arguments);
4770
4855
  };
4771
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
+ }();
4772
4877
  /**
4773
4878
  * @description 通过defaultOrg查找单个契约信息
4774
4879
  * @endpoint POST /api/contract/single_search
@@ -5782,6 +5887,18 @@
5782
5887
  };
5783
5888
  }();
5784
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
+
5785
5902
  var getAppStoryboard = /*#__PURE__*/function () {
5786
5903
  var _ref4 = _asyncToGenerator$1(function* (appId, params, options) {
5787
5904
  return (yield brickHttp.http.get("api/auth/bootstrap/".concat(appId), _objectSpread2(_objectSpread2({}, options), {}, {
@@ -6219,12 +6336,17 @@
6219
6336
  var _this3 = this;
6220
6337
 
6221
6338
  return _asyncToGenerator__default["default"](function* () {
6222
- 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"]({
6223
6341
  appFields: "defaultConfig,userConfig,locales,name,homepage,id,currentVersion,installStatus,internal,status",
6224
6342
  ignoreTemplateFields: "templates",
6225
6343
  ignoreBrickFields: "bricks,processors,providers,editors"
6226
6344
  }, params), {
6227
6345
  interceptorParams
6346
+ }) : bootstrap(_objectSpread__default["default"]({
6347
+ brief: true
6348
+ }, params), {
6349
+ interceptorParams
6228
6350
  });
6229
6351
 
6230
6352
  var bootstrapResponse = _objectSpread__default["default"]({
@@ -6271,11 +6393,12 @@
6271
6393
  $$fulfilled: true
6272
6394
  });
6273
6395
  } else {
6396
+ /* istanbul ignore next */
6274
6397
  var {
6275
6398
  routes,
6276
6399
  meta,
6277
6400
  app
6278
- } = yield getAppStoryboard(storyboard.app.id);
6401
+ } = yield localStorage.getItem("__$$use-bootstrap-v2-provider$$__") ? BootstrapV2Api_getAppStoryboardV2(storyboard.app.id, {}) : getAppStoryboard(storyboard.app.id);
6279
6402
  Object.assign(storyboard, {
6280
6403
  routes,
6281
6404
  meta,
@@ -6288,7 +6411,7 @@
6288
6411
 
6289
6412
  if ((_storyboard$meta = storyboard.meta) !== null && _storyboard$meta !== void 0 && _storyboard$meta.i18n) {
6290
6413
  // Prefix to avoid conflict between brick package's i18n namespace.
6291
- 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`.
6292
6415
 
6293
6416
  Object.entries(storyboard.meta.i18n).forEach(_ref => {
6294
6417
  var [lang, resources] = _ref;
@@ -8938,12 +9061,13 @@
8938
9061
  } else {
8939
9062
  var actualArgs = args ? ref ? args // `args` are already computed for `defineResolves`
8940
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
+ }
8941
9068
 
8942
- if (useProvider) {
8943
- actualArgs = yield getArgsOfCustomApi(useProvider, actualArgs);
8944
- }
8945
-
8946
- promise = providerBrick[method](...actualArgs);
9069
+ return providerBrick[method](...actualArgs);
9070
+ })();
8947
9071
 
8948
9072
  _this2.cache.set(cacheKey, promise);
8949
9073
  }
@@ -9011,7 +9135,7 @@
9011
9135
 
9012
9136
  var _loop = function (providerBrick, interval) {
9013
9137
  var request = /*#__PURE__*/function () {
9014
- var _ref = _asyncToGenerator__default["default"](function* () {
9138
+ var _ref2 = _asyncToGenerator__default["default"](function* () {
9015
9139
  yield providerBrick.$refresh({
9016
9140
  ignoreErrors: interval.ignoreErrors,
9017
9141
  throwErrors: true,
@@ -9025,7 +9149,7 @@
9025
9149
  });
9026
9150
 
9027
9151
  return function request() {
9028
- return _ref.apply(this, arguments);
9152
+ return _ref2.apply(this, arguments);
9029
9153
  };
9030
9154
  }();
9031
9155
 
@@ -9267,7 +9391,7 @@
9267
9391
 
9268
9392
  _this3.kernel.registerCustomTemplatesInStoryboard(storyboard);
9269
9393
 
9270
- 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);
9271
9395
  }
9272
9396
 
9273
9397
  var {
@@ -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) {