@next-core/brick-kit 2.116.1 → 2.117.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,22 @@
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.117.0](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.116.1...@next-core/brick-kit@2.117.0) (2022-04-06)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * contract refactor ([a506766](https://github.com/easyops-cn/next-core/commit/a5067664253a51a007b8fea96ddf7efefd7da7d8))
12
+
13
+
14
+ ### Features
15
+
16
+ * support previewing template by settings ([b1fa0f9](https://github.com/easyops-cn/next-core/commit/b1fa0f9e4d774a6b4162643348ca49402bde1479))
17
+
18
+
19
+
20
+
21
+
6
22
  ## [2.116.1](https://github.com/easyops-cn/next-core/compare/@next-core/brick-kit@2.116.0...@next-core/brick-kit@2.116.1) (2022-04-06)
7
23
 
8
24
  **Note:** Version bump only for package @next-core/brick-kit
@@ -3175,6 +3175,11 @@
3175
3175
  function _dev_only_updateStoryboard(appId, storyboardPatch) {
3176
3176
  kernel._dev_only_updateStoryboard(appId, storyboardPatch);
3177
3177
  }
3178
+ /* istanbul ignore next */
3179
+
3180
+ function _dev_only_updateTemplatePreviewSettings(appId, templateId, settings) {
3181
+ kernel._dev_only_updateTemplatePreviewSettings(appId, templateId, settings);
3182
+ }
3178
3183
  class Runtime {
3179
3184
  constructor() {
3180
3185
  _defineProperty__default["default"](this, "registerBrickTemplate", registerBrickTemplate);
@@ -5590,6 +5595,16 @@
5590
5595
  return;
5591
5596
  };
5592
5597
 
5598
+ var contractsMap = new Map();
5599
+ function collectContract(contracts) {
5600
+ contracts === null || contracts === void 0 ? void 0 : contracts.forEach(contract => {
5601
+ contractsMap.set("".concat(contract.namespaceId, ".").concat(contract.name), contract);
5602
+ });
5603
+ }
5604
+ function getContract(name) {
5605
+ return contractsMap.get(name);
5606
+ }
5607
+
5593
5608
  var flowApiDefinitionPromiseMap = new Map(); // Legacy Custom API: `${namespace}@${name}`
5594
5609
  // Flow API: `${namespace}@${name}:${version}`
5595
5610
 
@@ -5623,6 +5638,7 @@
5623
5638
  var {
5624
5639
  uri,
5625
5640
  method,
5641
+ ext_fields,
5626
5642
  name,
5627
5643
  namespace,
5628
5644
  responseWrapper,
@@ -5642,12 +5658,14 @@
5642
5658
  return isFileType ? [fileName, {
5643
5659
  url,
5644
5660
  method,
5661
+ ext_fields,
5645
5662
  responseWrapper: false
5646
5663
  }, ...args, {
5647
5664
  responseType: "blob"
5648
5665
  }] : [{
5649
5666
  url,
5650
5667
  method,
5668
+ ext_fields,
5651
5669
  responseWrapper
5652
5670
  }, ...args];
5653
5671
  }
@@ -5671,7 +5689,8 @@
5671
5689
  }) : api.contract;
5672
5690
  var {
5673
5691
  uri,
5674
- method = "GET"
5692
+ method = "GET",
5693
+ ext_fields
5675
5694
  } = (_contract$endpoint = contract === null || contract === void 0 ? void 0 : contract.endpoint) !== null && _contract$endpoint !== void 0 ? _contract$endpoint : {};
5676
5695
  var responseWrapper = contract !== null && contract !== void 0 && contract.response ? contract.response.wrapper !== false : false;
5677
5696
 
@@ -5682,6 +5701,7 @@
5682
5701
  return {
5683
5702
  uri,
5684
5703
  method: method.toLowerCase() === "list" ? "get" : method,
5704
+ ext_fields,
5685
5705
  name: api.name,
5686
5706
  namespace: api.namespace,
5687
5707
  version: api.version,
@@ -5742,25 +5762,39 @@
5742
5762
  };
5743
5763
  }
5744
5764
  } else {
5745
- var {
5746
- contractData
5747
- } = yield ContractApi_searchSingleContract({
5748
- contractName: "".concat(namespaceName, ".").concat(name),
5749
- version
5750
- }); // return undefined if don't found contract
5751
-
5752
- if (contractData) {
5753
- var _contractData$namespa, _contractData$namespa2;
5765
+ var contract;
5754
5766
 
5767
+ if (contract = getContract("".concat(namespaceName, ".").concat(name))) {
5755
5768
  return {
5756
- name: contractData.name,
5757
- namespace: (_contractData$namespa = contractData.namespace) === null || _contractData$namespa === void 0 ? void 0 : (_contractData$namespa2 = _contractData$namespa[0]) === null || _contractData$namespa2 === void 0 ? void 0 : _contractData$namespa2.name,
5758
- version: contractData.version,
5769
+ name: contract.name,
5770
+ namespace: contract.namespaceId,
5771
+ version: contract.version,
5759
5772
  contract: {
5760
- endpoint: contractData.endpoint,
5761
- response: contractData.response
5773
+ endpoint: contract.endpoint,
5774
+ response: contract.response
5762
5775
  }
5763
5776
  };
5777
+ } else {
5778
+ var {
5779
+ contractData
5780
+ } = yield ContractApi_searchSingleContract({
5781
+ contractName: "".concat(namespaceName, ".").concat(name),
5782
+ version
5783
+ }); // return undefined if don't found contract
5784
+
5785
+ if (contractData) {
5786
+ var _contractData$namespa, _contractData$namespa2;
5787
+
5788
+ return {
5789
+ name: contractData.name,
5790
+ namespace: (_contractData$namespa = contractData.namespace) === null || _contractData$namespa === void 0 ? void 0 : (_contractData$namespa2 = _contractData$namespa[0]) === null || _contractData$namespa2 === void 0 ? void 0 : _contractData$namespa2.name,
5791
+ version: contractData.version,
5792
+ contract: {
5793
+ endpoint: contractData.endpoint,
5794
+ response: contractData.response
5795
+ }
5796
+ };
5797
+ }
5764
5798
  }
5765
5799
  }
5766
5800
  });
@@ -6639,26 +6673,74 @@
6639
6673
  }
6640
6674
 
6641
6675
  var CUSTOM_API_PROVIDER = "brick-kit.provider-custom-api";
6642
- function CustomApi(_x, _x2, _x3) {
6676
+ function processExtFields(ext_fields) {
6677
+
6678
+ var hasFields = type => {
6679
+ return ext_fields.some(item => item.source === type);
6680
+ };
6681
+
6682
+ var hasQueryParams = hasFields("query");
6683
+ var HasBodyParams = hasFields("body");
6684
+
6685
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
6686
+ args[_key - 1] = arguments[_key];
6687
+ }
6688
+
6689
+ if (hasQueryParams && HasBodyParams) {
6690
+ var [_data, params, _options] = args;
6691
+ return {
6692
+ data: _data,
6693
+ options: _objectSpread__default["default"]({
6694
+ params: params
6695
+ }, _options)
6696
+ };
6697
+ }
6698
+
6699
+ if (hasQueryParams) {
6700
+ var [_params, _options2] = args;
6701
+ return {
6702
+ data: {},
6703
+ options: _objectSpread__default["default"]({
6704
+ params: _params
6705
+ }, _options2)
6706
+ };
6707
+ } // only hasBodyParams or default
6708
+
6709
+
6710
+ var [data, options] = args;
6711
+ return {
6712
+ data,
6713
+ options
6714
+ };
6715
+ }
6716
+ function CustomApi(_x) {
6643
6717
  return _CustomApi.apply(this, arguments);
6644
6718
  }
6645
6719
 
6646
6720
  function _CustomApi() {
6647
- _CustomApi = _asyncToGenerator__default["default"](function* (_ref, data, options) {
6721
+ _CustomApi = _asyncToGenerator__default["default"](function* (_ref) {
6648
6722
  var {
6649
6723
  url,
6650
6724
  method = "GET",
6651
- responseWrapper = true
6725
+ responseWrapper = true,
6726
+ ext_fields = []
6652
6727
  } = _ref;
6653
6728
  var isSimpleRequest = ["get", "delete", "head"].includes(method.toLowerCase());
6654
6729
 
6730
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
6731
+ args[_key2 - 1] = arguments[_key2];
6732
+ }
6733
+
6655
6734
  if (isSimpleRequest) {
6735
+ var [data, options] = args;
6656
6736
  var response = yield brickHttp.http.simpleRequest(method, url, _objectSpread__default["default"]({
6657
6737
  params: data
6658
6738
  }, options));
6659
6739
  return responseWrapper ? response.data : response;
6660
6740
  } else {
6661
- var _response = yield brickHttp.http.requestWithBody(method, url, data, options);
6741
+ var result = processExtFields(ext_fields, ...args);
6742
+
6743
+ var _response = yield brickHttp.http.requestWithBody(method, url, result.data, result.options);
6662
6744
 
6663
6745
  return responseWrapper ? _response.data : _response;
6664
6746
  }
@@ -7910,6 +7992,26 @@
7910
7992
  this.postProcessStoryboard(storyboard);
7911
7993
  }
7912
7994
 
7995
+ _dev_only_updateTemplatePreviewSettings(appId, templateId, settings) {
7996
+ var {
7997
+ routes
7998
+ } = this.bootstrapData.storyboards.find(item => item.app.id === appId);
7999
+ var previewPath = "${APP.homepage}/_dev_only_/template-preview/".concat(templateId);
8000
+ var previewRouteIndex = routes.findIndex(route => route.path === previewPath);
8001
+ var newPreviewRoute = {
8002
+ path: previewPath,
8003
+ bricks: [_objectSpread__default["default"]({
8004
+ brick: templateId
8005
+ }, lodash.pick(settings, "properties"))]
8006
+ };
8007
+
8008
+ if (previewRouteIndex === -1) {
8009
+ routes.push(newPreviewRoute);
8010
+ } else {
8011
+ routes.splice(previewRouteIndex, 1, newPreviewRoute);
8012
+ }
8013
+ }
8014
+
7913
8015
  loadDepsOfStoryboard(storyboard) {
7914
8016
  var _this6 = this;
7915
8017
 
@@ -9984,7 +10086,7 @@
9984
10086
  var storyboard = locationContext.matchStoryboard(_this3.kernel.bootstrapData.storyboards);
9985
10087
 
9986
10088
  if (storyboard) {
9987
- var _storyboard$meta, _storyboard$meta2;
10089
+ var _storyboard$meta, _storyboard$meta2, _storyboard$meta3;
9988
10090
 
9989
10091
  yield _this3.kernel.fulfilStoryboard(storyboard); // 将动态解析后的模板还原,以便重新动态解析。
9990
10092
 
@@ -10003,6 +10105,7 @@
10003
10105
 
10004
10106
  registerStoryboardFunctions((_storyboard$meta = storyboard.meta) === null || _storyboard$meta === void 0 ? void 0 : _storyboard$meta.functions, storyboard.app);
10005
10107
  registerMock((_storyboard$meta2 = storyboard.meta) === null || _storyboard$meta2 === void 0 ? void 0 : _storyboard$meta2.mocks);
10108
+ collectContract((_storyboard$meta3 = storyboard.meta) === null || _storyboard$meta3 === void 0 ? void 0 : _storyboard$meta3.contracts);
10006
10109
  }
10007
10110
 
10008
10111
  var {
@@ -10055,7 +10158,13 @@
10055
10158
  };
10056
10159
 
10057
10160
  try {
10058
- yield locationContext.mountRoutes(storyboard.routes, undefined, mountRoutesResult);
10161
+ yield locationContext.mountRoutes( // Concat with a placeholder when loading template preview settings.
10162
+ storyboard.routes.concat({
10163
+ path: "${APP.homepage}/_dev_only_/template-preview/:templateId",
10164
+ bricks: [{
10165
+ brick: "next-previewer.template-preview-loader"
10166
+ }]
10167
+ }), undefined, mountRoutesResult);
10059
10168
  } catch (error) {
10060
10169
  // eslint-disable-next-line no-console
10061
10170
  console.error(error); // Redirect to login page if not logged in.
@@ -12968,7 +13077,8 @@
12968
13077
 
12969
13078
  /** @deprecated Keep it for backward-compatibility. */
12970
13079
  checkoutTplContext: lodash.noop,
12971
- updateStoryboard: _dev_only_updateStoryboard
13080
+ updateStoryboard: _dev_only_updateStoryboard,
13081
+ updateTemplatePreviewSettings: _dev_only_updateTemplatePreviewSettings
12972
13082
  };
12973
13083
 
12974
13084
  var _excluded$2 = ["type"];