@banch0u/core-project-test-repository 2.3.16 → 2.3.17

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.
@@ -6,8 +6,8 @@ import style from "./index.module.scss";
6
6
  import { Select as AntdSelect, Divider } from "antd";
7
7
  import { FormItemInputContext } from "antd/es/form/context";
8
8
  import Button from "../Button";
9
+ import DisabledContext from "antd/es/config-provider/DisabledContext";
9
10
  var Select = function Select(_ref) {
10
- var _ref2;
11
11
  var children = _ref.children,
12
12
  className = _ref.className,
13
13
  size = _ref.size,
@@ -27,7 +27,8 @@ var Select = function Select(_ref) {
27
27
  width = _ref.width,
28
28
  rest = _objectWithoutProperties(_ref, _excluded);
29
29
  var formItemContext = useContext(FormItemInputContext);
30
- var mergedDisabled = (_ref2 = customDisabled !== null && customDisabled !== void 0 ? customDisabled : formItemContext === null || formItemContext === void 0 ? void 0 : formItemContext.disabled) !== null && _ref2 !== void 0 ? _ref2 : false;
30
+ var configDisabled = useContext(DisabledContext);
31
+ var mergedDisabled = Boolean(customDisabled || (formItemContext === null || formItemContext === void 0 ? void 0 : formItemContext.disabled) || configDisabled);
31
32
  var getClassName = function getClassName() {
32
33
  if (className) return className;
33
34
  switch (size) {
@@ -1,8 +1,5 @@
1
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
- import _typeof from "@babel/runtime/helpers/typeof";
3
1
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
4
2
  import _regeneratorRuntime from "@babel/runtime/regenerator";
5
- // store/slices/policies.js
6
3
  import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
7
4
  import Services from "./service";
8
5
  import { setLoading } from "../global";
@@ -19,99 +16,49 @@ export var checkPolicies = createAsyncThunk("policies/checkPolicies",
19
16
  /*#__PURE__*/
20
17
  // policies: array of policy strings
21
18
  function () {
22
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(policies, _ref) {
23
- var dispatch, rejectWithValue, results, promises, settled, errMsg, _t2;
24
- return _regeneratorRuntime.wrap(function (_context2) {
25
- while (1) switch (_context2.prev = _context2.next) {
19
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(policies, _ref) {
20
+ var dispatch, rejectWithValue, response, results, items, errMsg, _t;
21
+ return _regeneratorRuntime.wrap(function (_context) {
22
+ while (1) switch (_context.prev = _context.next) {
26
23
  case 0:
27
24
  dispatch = _ref.dispatch, rejectWithValue = _ref.rejectWithValue;
28
- _context2.prev = 1;
25
+ _context.prev = 1;
29
26
  dispatch(setLoading(true));
30
-
31
- // If Services provides a bulk check endpoint you can use it here instead.
32
- // Otherwise we call Services.checkPolicy for each policy.
33
- results = {}; // run requests in parallel (faster) but you can change to sequential if
34
- // backend requires rate limiting / ordering
35
- promises = policies.map(/*#__PURE__*/function () {
36
- var _ref3 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee(policyName) {
37
- var res, _t;
38
- return _regeneratorRuntime.wrap(function (_context) {
39
- while (1) switch (_context.prev = _context.next) {
40
- case 0:
41
- _context.prev = 0;
42
- _context.next = 1;
43
- return Services.checkPolicy(policyName);
44
- case 1:
45
- res = _context.sent;
46
- if (!(res && _typeof(res) === "object")) {
47
- _context.next = 5;
48
- break;
49
- }
50
- if (!("allowed" in res)) {
51
- _context.next = 2;
52
- break;
53
- }
54
- return _context.abrupt("return", [policyName, !!res.allowed]);
55
- case 2:
56
- if (!("data" in res && _typeof(res.data) === "object")) {
57
- _context.next = 3;
58
- break;
59
- }
60
- if (!(typeof res.data === "boolean")) {
61
- _context.next = 3;
62
- break;
63
- }
64
- return _context.abrupt("return", [policyName, res.data]);
65
- case 3:
66
- if (!("status" in res)) {
67
- _context.next = 4;
68
- break;
69
- }
70
- return _context.abrupt("return", [policyName, res.status === 200 || !!res.status]);
71
- case 4:
72
- return _context.abrupt("return", [policyName, !!res]);
73
- case 5:
74
- return _context.abrupt("return", [policyName, !!res]);
75
- case 6:
76
- _context.prev = 6;
77
- _t = _context["catch"](0);
78
- // treat failures as false, but you may want to rethrow or store error
79
- console.error("checkPolicy error for", policyName, _t);
80
- return _context.abrupt("return", [policyName, false]);
81
- case 7:
82
- case "end":
83
- return _context.stop();
84
- }
85
- }, _callee, null, [[0, 6]]);
86
- }));
87
- return function (_x3) {
88
- return _ref3.apply(this, arguments);
89
- };
90
- }());
91
- _context2.next = 2;
92
- return Promise.all(promises);
27
+ _context.next = 2;
28
+ return Services.checkPolicies(policies);
93
29
  case 2:
94
- settled = _context2.sent;
95
- settled.forEach(function (_ref4) {
96
- var _ref5 = _slicedToArray(_ref4, 2),
97
- name = _ref5[0],
98
- allowed = _ref5[1];
99
- results[name] = allowed;
30
+ response = _context.sent;
31
+ // normalize into the same { [policyName]: boolean } shape the old
32
+ // per-policy implementation produced
33
+ results = {};
34
+ items = Array.isArray(response === null || response === void 0 ? void 0 : response.data) ? response.data : [];
35
+ items.forEach(function (item) {
36
+ if (item && typeof item.name === "string") {
37
+ results[item.name] = !!item.hasAccess;
38
+ }
39
+ });
40
+
41
+ // make sure every requested policy is present in the map even if the
42
+ // backend omitted it, so consumers can rely on the key existing
43
+ policies.forEach(function (name) {
44
+ if (!(name in results)) {
45
+ results[name] = false;
46
+ }
100
47
  });
101
48
  dispatch(setLoading(false));
102
- return _context2.abrupt("return", results);
49
+ return _context.abrupt("return", results);
103
50
  case 3:
104
- _context2.prev = 3;
105
- _t2 = _context2["catch"](1);
51
+ _context.prev = 3;
52
+ _t = _context["catch"](1);
106
53
  dispatch(setLoading(false));
107
- errMsg = _t2 && _t2.response && _t2.response.data && _t2.response.data.message || _t2.message || "Policy check failed";
54
+ errMsg = _t && _t.response && _t.response.data && _t.response.data.message || _t.message || "Policy check failed";
108
55
  errorMessage(errMsg);
109
- return _context2.abrupt("return", rejectWithValue(errMsg));
56
+ return _context.abrupt("return", rejectWithValue(errMsg));
110
57
  case 4:
111
58
  case "end":
112
- return _context2.stop();
59
+ return _context.stop();
113
60
  }
114
- }, _callee2, null, [[1, 3]]);
61
+ }, _callee, null, [[1, 3]]);
115
62
  }));
116
63
  return function (_x, _x2) {
117
64
  return _ref2.apply(this, arguments);
@@ -53,4 +53,27 @@ _defineProperty(Services, "checkPolicy", /*#__PURE__*/function () {
53
53
  return _ref.apply(this, arguments);
54
54
  };
55
55
  }());
56
+ _defineProperty(Services, "checkPolicies", /*#__PURE__*/function () {
57
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime.mark(function _callee2(policies) {
58
+ var response;
59
+ return _regeneratorRuntime.wrap(function (_context2) {
60
+ while (1) switch (_context2.prev = _context2.next) {
61
+ case 0:
62
+ _context2.next = 1;
63
+ return api.post("/profile/policiescheck", {
64
+ policies: policies
65
+ });
66
+ case 1:
67
+ response = _context2.sent;
68
+ return _context2.abrupt("return", response === null || response === void 0 ? void 0 : response.data);
69
+ case 2:
70
+ case "end":
71
+ return _context2.stop();
72
+ }
73
+ }, _callee2);
74
+ }));
75
+ return function (_x2) {
76
+ return _ref2.apply(this, arguments);
77
+ };
78
+ }());
56
79
  export default Services;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@banch0u/core-project-test-repository",
3
- "version": "2.3.16",
3
+ "version": "2.3.17",
4
4
  "description": "Shared core features for all projects",
5
5
  "main": "dist/index.js",
6
6
  "files": [