ag-common 0.0.419 → 0.0.421

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.
Files changed (178) hide show
  1. package/dist/api/helpers/api.js +35 -34
  2. package/dist/api/helpers/aws.js +13 -9
  3. package/dist/api/helpers/cloudfront.js +24 -7
  4. package/dist/api/helpers/dynamo.js +134 -85
  5. package/dist/api/helpers/dynamoInfra.js +19 -14
  6. package/dist/api/helpers/enforceDynamoProvisionCap.js +18 -14
  7. package/dist/api/helpers/index.js +30 -14
  8. package/dist/api/helpers/openApiHelpers.js +37 -34
  9. package/dist/api/helpers/s3.js +126 -81
  10. package/dist/api/helpers/ses.js +28 -9
  11. package/dist/api/helpers/sqs.js +26 -9
  12. package/dist/api/helpers/ssm.js +14 -8
  13. package/dist/api/helpers/sts.js +34 -16
  14. package/dist/api/helpers/validateOpenApi.js +103 -92
  15. package/dist/api/helpers/validations.js +46 -29
  16. package/dist/api/index.js +18 -2
  17. package/dist/api/openapi-prefix.js +38 -25
  18. package/dist/api/types/aws.js +2 -1
  19. package/dist/api/types/index.js +17 -1
  20. package/dist/common/const.js +5 -2
  21. package/dist/common/helpers/array.js +19 -8
  22. package/dist/common/helpers/async.js +28 -10
  23. package/dist/common/helpers/binary.js +10 -5
  24. package/dist/common/helpers/date.js +25 -14
  25. package/dist/common/helpers/email.js +11 -5
  26. package/dist/common/helpers/func.js +7 -3
  27. package/dist/common/helpers/generator.js +24 -9
  28. package/dist/common/helpers/groupBy.js +9 -3
  29. package/dist/common/helpers/hashCode.js +9 -3
  30. package/dist/common/helpers/i18n.js +17 -9
  31. package/dist/common/helpers/index.js +34 -18
  32. package/dist/common/helpers/log.js +28 -16
  33. package/dist/common/helpers/math.js +21 -9
  34. package/dist/common/helpers/memo.js +7 -3
  35. package/dist/common/helpers/object.js +35 -20
  36. package/dist/common/helpers/random.js +10 -4
  37. package/dist/common/helpers/secondsInNearest.js +7 -2
  38. package/dist/common/helpers/sleep.js +5 -1
  39. package/dist/common/helpers/string/base64.js +7 -2
  40. package/dist/common/helpers/string/chunk.js +5 -1
  41. package/dist/common/helpers/string/contains.js +7 -2
  42. package/dist/common/helpers/string/getExtendedStringSegment.js +9 -5
  43. package/dist/common/helpers/string/index.js +26 -10
  44. package/dist/common/helpers/string/json.js +5 -1
  45. package/dist/common/helpers/string/object.js +5 -1
  46. package/dist/common/helpers/string/surround.js +5 -1
  47. package/dist/common/helpers/string/trim.js +7 -2
  48. package/dist/common/helpers/string/truncate.js +5 -1
  49. package/dist/common/helpers/string/url.js +9 -4
  50. package/dist/common/index.js +18 -2
  51. package/dist/index.js +19 -3
  52. package/dist/ui/components/BorderGradient/index.js +25 -18
  53. package/dist/ui/components/Button/index.js +25 -17
  54. package/dist/ui/components/Chevron/index.js +16 -9
  55. package/dist/ui/components/Close/index.js +13 -6
  56. package/dist/ui/components/Confirm/Dialog.js +25 -9
  57. package/dist/ui/components/Confirm/Modal.js +27 -20
  58. package/dist/ui/components/Confirm/index.js +19 -3
  59. package/dist/ui/components/Confirm/types.js +2 -1
  60. package/dist/ui/components/DropdownList/Base.js +64 -33
  61. package/dist/ui/components/DropdownList/Dialog.js +24 -8
  62. package/dist/ui/components/DropdownList/index.js +18 -2
  63. package/dist/ui/components/DropdownList/types.js +2 -1
  64. package/dist/ui/components/FlexColumn/index.js +14 -4
  65. package/dist/ui/components/FlexRow/index.js +14 -4
  66. package/dist/ui/components/HeadersRaw/index.js +27 -20
  67. package/dist/ui/components/HorizontalScrollBar/index.js +34 -6
  68. package/dist/ui/components/Icon/index.js +16 -9
  69. package/dist/ui/components/Image/index.js +28 -10
  70. package/dist/ui/components/InfiniteScroll/index.js +50 -18
  71. package/dist/ui/components/KebabDots/index.js +13 -6
  72. package/dist/ui/components/Loader/index.js +39 -9
  73. package/dist/ui/components/Modal/Dialog.js +23 -7
  74. package/dist/ui/components/Modal/Modal.js +49 -19
  75. package/dist/ui/components/Modal/index.js +19 -3
  76. package/dist/ui/components/Modal/types.js +2 -1
  77. package/dist/ui/components/OpenApiCodeBlock/OpenApiCodeBlock.js +34 -26
  78. package/dist/ui/components/OpenApiCodeBlock/curl/helpers/body.js +19 -12
  79. package/dist/ui/components/OpenApiCodeBlock/curl/helpers/getCurlLines.js +11 -6
  80. package/dist/ui/components/OpenApiCodeBlock/curl/helpers/security.js +15 -8
  81. package/dist/ui/components/OpenApiCodeBlock/curl/index.js +21 -14
  82. package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/call.js +15 -8
  83. package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/getFetchLines.js +8 -3
  84. package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/req.js +34 -27
  85. package/dist/ui/components/OpenApiCodeBlock/fetch/index.js +18 -11
  86. package/dist/ui/components/OpenApiCodeBlock/helpers/common.js +17 -7
  87. package/dist/ui/components/OpenApiCodeBlock/helpers/joinJsx.js +15 -6
  88. package/dist/ui/components/OpenApiCodeBlock/index.js +18 -2
  89. package/dist/ui/components/OpenApiCodeBlock/types.js +2 -1
  90. package/dist/ui/components/PieChart/index.js +18 -11
  91. package/dist/ui/components/ProgressBar/index.js +45 -15
  92. package/dist/ui/components/Prompt/Dialog.js +23 -7
  93. package/dist/ui/components/Prompt/Modal.js +55 -25
  94. package/dist/ui/components/Prompt/index.js +18 -2
  95. package/dist/ui/components/RowOrColumn/index.js +17 -7
  96. package/dist/ui/components/Search/AutoHideSearchBox.js +56 -24
  97. package/dist/ui/components/Search/Base.js +52 -21
  98. package/dist/ui/components/Search/Dialog.js +26 -10
  99. package/dist/ui/components/Search/Inline.js +10 -3
  100. package/dist/ui/components/Search/Modal.js +17 -10
  101. package/dist/ui/components/Search/SearchBox.js +58 -26
  102. package/dist/ui/components/Search/index.js +23 -7
  103. package/dist/ui/components/Search/types.js +2 -1
  104. package/dist/ui/components/Sidebar/index.js +25 -18
  105. package/dist/ui/components/SparkLine/index.js +27 -17
  106. package/dist/ui/components/Table/index.js +22 -15
  107. package/dist/ui/components/TextEdit/CheckboxEdit.js +51 -21
  108. package/dist/ui/components/TextEdit/ColourEdit.js +44 -17
  109. package/dist/ui/components/TextEdit/LengthBox.js +12 -5
  110. package/dist/ui/components/TextEdit/ListboxEdit.js +42 -15
  111. package/dist/ui/components/TextEdit/RadioGroup.js +43 -13
  112. package/dist/ui/components/TextEdit/TextEdit.js +78 -48
  113. package/dist/ui/components/TextEdit/common.js +17 -11
  114. package/dist/ui/components/TextEdit/index.js +22 -6
  115. package/dist/ui/components/TextEdit/types.js +2 -1
  116. package/dist/ui/components/TextWithButton/index.js +40 -10
  117. package/dist/ui/components/TimelineChart/index.js +24 -14
  118. package/dist/ui/components/Toast/Cross.js +16 -9
  119. package/dist/ui/components/Toast/Tick.js +11 -4
  120. package/dist/ui/components/Toast/Warning.js +15 -8
  121. package/dist/ui/components/Toast/base.js +65 -33
  122. package/dist/ui/components/Toast/index.js +18 -2
  123. package/dist/ui/components/Toast/types.js +2 -1
  124. package/dist/ui/components/UserImage/index.js +48 -17
  125. package/dist/ui/components/index.js +46 -30
  126. package/dist/ui/helpers/axiosHelper.js +39 -25
  127. package/dist/ui/helpers/browserHelpers.js +22 -7
  128. package/dist/ui/helpers/callOpenApi/cached.js +37 -18
  129. package/dist/ui/helpers/callOpenApi/direct.js +59 -46
  130. package/dist/ui/helpers/callOpenApi/helpers.js +40 -25
  131. package/dist/ui/helpers/callOpenApi/hook.js +36 -47
  132. package/dist/ui/helpers/callOpenApi/index.js +21 -5
  133. package/dist/ui/helpers/callOpenApi/types.js +2 -1
  134. package/dist/ui/helpers/cognito.js +2 -1
  135. package/dist/ui/helpers/cookie/const.js +5 -2
  136. package/dist/ui/helpers/cookie/get.js +14 -13
  137. package/dist/ui/helpers/cookie/index.js +21 -5
  138. package/dist/ui/helpers/cookie/raw.js +16 -9
  139. package/dist/ui/helpers/cookie/set.js +15 -10
  140. package/dist/ui/helpers/cookie/use.js +16 -23
  141. package/dist/ui/helpers/date.js +15 -10
  142. package/dist/ui/helpers/debounce.js +10 -5
  143. package/dist/ui/helpers/dom.js +13 -6
  144. package/dist/ui/helpers/extractAttributes.js +7 -2
  145. package/dist/ui/helpers/index.js +41 -25
  146. package/dist/ui/helpers/jwt.js +2 -1
  147. package/dist/ui/helpers/plural.js +5 -1
  148. package/dist/ui/helpers/routes.js +24 -17
  149. package/dist/ui/helpers/serviceWorker.js +23 -8
  150. package/dist/ui/helpers/useContextMenu.js +14 -9
  151. package/dist/ui/helpers/useElementAttribute.js +7 -3
  152. package/dist/ui/helpers/useGranularHook.js +10 -5
  153. package/dist/ui/helpers/useInterval.js +12 -8
  154. package/dist/ui/helpers/useLocalStorage.js +32 -24
  155. package/dist/ui/helpers/useLockBodyScroll.js +7 -3
  156. package/dist/ui/helpers/useOnClickOutside.js +12 -7
  157. package/dist/ui/helpers/useOnScroll.js +21 -15
  158. package/dist/ui/helpers/useOverloadPageSearch.js +7 -3
  159. package/dist/ui/helpers/useQueryString.js +20 -14
  160. package/dist/ui/helpers/useResize.js +19 -17
  161. package/dist/ui/helpers/useTimeout.js +9 -5
  162. package/dist/ui/icons/ChevronRight.js +9 -3
  163. package/dist/ui/icons/CrossIcon.js +12 -5
  164. package/dist/ui/icons/Door.js +10 -4
  165. package/dist/ui/icons/HorizontalDots.js +9 -3
  166. package/dist/ui/icons/Magnify.js +10 -3
  167. package/dist/ui/icons/Pencil.js +12 -5
  168. package/dist/ui/icons/Save.js +11 -4
  169. package/dist/ui/icons/Undo.js +12 -5
  170. package/dist/ui/icons/UserOutline.js +9 -3
  171. package/dist/ui/icons/index.js +25 -9
  172. package/dist/ui/index.js +20 -4
  173. package/dist/ui/styles/colours.js +12 -7
  174. package/dist/ui/styles/common.js +22 -14
  175. package/dist/ui/styles/index.js +20 -4
  176. package/dist/ui/styles/media.js +10 -7
  177. package/dist/ui/styles/standaloneStyles.js +16 -10
  178. package/package.json +2 -2
@@ -1,7 +1,22 @@
1
- import NodeCache from 'node-cache';
2
- import { hashCode } from '../../../common/helpers/hashCode';
3
- import { toBase64 } from '../../../common/helpers/string/base64';
4
- import { callOpenApi, getIdTokenAuthHeaderRaw } from './direct';
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.callOpenApiCached = exports.callOpenApiCachedRaw = exports.setOpenApiCacheRaw = void 0;
16
+ const node_cache_1 = __importDefault(require("node-cache"));
17
+ const hashCode_1 = require("../../../common/helpers/hashCode");
18
+ const base64_1 = require("../../../common/helpers/string/base64");
19
+ const direct_1 = require("./direct");
5
20
  let callOpenApiCache;
6
21
  /**
7
22
  * cache differs per user and per SSR provided data
@@ -9,44 +24,46 @@ let callOpenApiCache;
9
24
  * @returns
10
25
  */
11
26
  function getCacheKey({ cacheKey, overrideAuth, ssrCacheItems, }) {
12
- const authkeyPrefix1 = getIdTokenAuthHeaderRaw({
27
+ const authkeyPrefix1 = (0, direct_1.getIdTokenAuthHeaderRaw)({
13
28
  overrideAuth: overrideAuth,
14
29
  });
15
- const authPref = !authkeyPrefix1 ? '' : hashCode(toBase64(authkeyPrefix1));
30
+ const authPref = !authkeyPrefix1 ? '' : (0, hashCode_1.hashCode)((0, base64_1.toBase64)(authkeyPrefix1));
16
31
  const ssrCachePref = !ssrCacheItems
17
32
  ? ''
18
- : hashCode(toBase64(JSON.stringify(ssrCacheItems)));
33
+ : (0, hashCode_1.hashCode)((0, base64_1.toBase64)(JSON.stringify(ssrCacheItems)));
19
34
  let cacheKeyRet;
20
35
  if (cacheKey) {
21
36
  cacheKeyRet = `${cacheKey}||${authPref}||${ssrCachePref}`;
22
37
  }
23
38
  return cacheKeyRet;
24
39
  }
25
- export const setOpenApiCacheRaw = async (p, data) => {
40
+ const setOpenApiCacheRaw = (p, data) => __awaiter(void 0, void 0, void 0, function* () {
26
41
  const userPrefixedCacheKey = getCacheKey(p);
27
42
  if (!userPrefixedCacheKey) {
28
43
  return;
29
44
  }
30
45
  if (!callOpenApiCache) {
31
- callOpenApiCache = new NodeCache({ stdTTL: p.cacheTtl || 120 });
46
+ callOpenApiCache = new node_cache_1.default({ stdTTL: p.cacheTtl || 120 });
32
47
  }
33
48
  callOpenApiCache.set(userPrefixedCacheKey, data);
34
- };
49
+ });
50
+ exports.setOpenApiCacheRaw = setOpenApiCacheRaw;
35
51
  /**
36
52
  * sync call to callOpenApiCache.
37
53
  * @param p
38
54
  * @returns undefined if no cache item
39
55
  */
40
- export const callOpenApiCachedRaw = (p) => {
56
+ const callOpenApiCachedRaw = (p) => {
57
+ var _a, _b, _c;
41
58
  const userPrefixedCacheKey = getCacheKey(p);
42
59
  if (!userPrefixedCacheKey) {
43
60
  return undefined;
44
61
  }
45
62
  if (!callOpenApiCache) {
46
- callOpenApiCache = new NodeCache({ stdTTL: p.cacheTtl || 120 });
63
+ callOpenApiCache = new node_cache_1.default({ stdTTL: p.cacheTtl || 120 });
47
64
  }
48
65
  //get ssr cache value
49
- const ssrCached = p.ssrCacheItems?.find((s) => s.cacheKey === p.cacheKey)?.prefillData?.data;
66
+ const ssrCached = (_c = (_b = (_a = p.ssrCacheItems) === null || _a === void 0 ? void 0 : _a.find((s) => s.cacheKey === p.cacheKey)) === null || _b === void 0 ? void 0 : _b.prefillData) === null || _c === void 0 ? void 0 : _c.data;
50
67
  //if we have ssr cache and there is no existing cache then set
51
68
  if (!callOpenApiCache.get(userPrefixedCacheKey) && ssrCached) {
52
69
  callOpenApiCache.set(userPrefixedCacheKey, ssrCached);
@@ -58,15 +75,17 @@ export const callOpenApiCachedRaw = (p) => {
58
75
  }
59
76
  return { data };
60
77
  };
61
- export const callOpenApiCached = async (p) => {
62
- const raw = callOpenApiCachedRaw(p);
78
+ exports.callOpenApiCachedRaw = callOpenApiCachedRaw;
79
+ const callOpenApiCached = (p) => __awaiter(void 0, void 0, void 0, function* () {
80
+ const raw = (0, exports.callOpenApiCachedRaw)(p);
63
81
  if (raw) {
64
82
  return raw;
65
83
  }
66
- const resp = await callOpenApi(p);
84
+ const resp = yield (0, direct_1.callOpenApi)(p);
67
85
  if (resp.error) {
68
86
  return { error: resp.error, data: undefined };
69
87
  }
70
- await setOpenApiCacheRaw(p, resp.data);
88
+ yield (0, exports.setOpenApiCacheRaw)(p, resp.data);
71
89
  return resp;
72
- };
90
+ });
91
+ exports.callOpenApiCached = callOpenApiCached;
@@ -1,47 +1,65 @@
1
- import { AxiosError } from 'axios';
2
- import { retryHttpCodes, retryHttpMs } from '../../../common/const';
3
- import { notEmpty } from '../../../common/helpers/array';
4
- import { sleep } from '../../../common/helpers/sleep';
5
- import { getCookieString } from '../cookie';
6
- import { getLocalStorageItem } from '../useLocalStorage';
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.callOpenApi = exports.getIdTokenAuthHeaderRaw = void 0;
13
+ const axios_1 = require("axios");
14
+ const const_1 = require("../../../common/const");
15
+ const array_1 = require("../../../common/helpers/array");
16
+ const sleep_1 = require("../../../common/helpers/sleep");
17
+ const cookie_1 = require("../cookie");
18
+ const useLocalStorage_1 = require("../useLocalStorage");
7
19
  /**
8
20
  * get the id_token from provided value, or cookie, or LS
9
21
  */
10
- export function getIdTokenAuthHeaderRaw({ overrideAuth, }) {
22
+ function getIdTokenAuthHeaderRaw({ overrideAuth, }) {
23
+ var _a;
11
24
  let idToken;
12
25
  //if override supplied will only use that and not refresh
13
- if (overrideAuth?.id_token) {
14
- idToken = overrideAuth?.id_token;
26
+ if (overrideAuth === null || overrideAuth === void 0 ? void 0 : overrideAuth.id_token) {
27
+ idToken = overrideAuth === null || overrideAuth === void 0 ? void 0 : overrideAuth.id_token;
15
28
  }
16
29
  else {
17
- idToken = getCookieString({
30
+ idToken = (0, cookie_1.getCookieString)({
18
31
  name: 'id_token',
19
32
  defaultValue: '',
20
33
  });
21
34
  if (!idToken) {
22
- const userLs = getLocalStorageItem('user', undefined);
23
- if (userLs?.jwt?.id_token) {
35
+ const userLs = (0, useLocalStorage_1.getLocalStorageItem)('user', undefined);
36
+ if ((_a = userLs === null || userLs === void 0 ? void 0 : userLs.jwt) === null || _a === void 0 ? void 0 : _a.id_token) {
24
37
  idToken = userLs.jwt.id_token;
25
38
  }
26
39
  }
27
40
  }
28
41
  return idToken;
29
42
  }
43
+ exports.getIdTokenAuthHeaderRaw = getIdTokenAuthHeaderRaw;
30
44
  /**
31
45
  * get id_token, and then refresh
32
46
  */
33
- async function getIdTokenAuthHeader({ overrideAuth, refreshToken, }) {
34
- let idToken = getIdTokenAuthHeaderRaw({ overrideAuth });
35
- //if we have a cookie token, can try to refresh
36
- if (idToken) {
37
- const updated = await refreshToken();
38
- if (updated?.jwt?.id_token) {
39
- idToken = updated?.jwt?.id_token;
47
+ function getIdTokenAuthHeader({ overrideAuth, refreshToken, }) {
48
+ var _a, _b;
49
+ return __awaiter(this, void 0, void 0, function* () {
50
+ let idToken = getIdTokenAuthHeaderRaw({ overrideAuth });
51
+ //if we have a cookie token, can try to refresh
52
+ if (idToken) {
53
+ const updated = yield refreshToken();
54
+ if ((_a = updated === null || updated === void 0 ? void 0 : updated.jwt) === null || _a === void 0 ? void 0 : _a.id_token) {
55
+ idToken = (_b = updated === null || updated === void 0 ? void 0 : updated.jwt) === null || _b === void 0 ? void 0 : _b.id_token;
56
+ }
40
57
  }
41
- }
42
- return idToken;
58
+ return idToken;
59
+ });
43
60
  }
44
- export const callOpenApi = async (p) => {
61
+ const callOpenApi = (p) => __awaiter(void 0, void 0, void 0, function* () {
62
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
45
63
  const { func, apiUrl, logout, newDefaultApi, headers } = p;
46
64
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
65
  let error;
@@ -52,11 +70,11 @@ export const callOpenApi = async (p) => {
52
70
  middleware: [],
53
71
  };
54
72
  //comes from either id_token cookie OR auth override param
55
- const idToken = await getIdTokenAuthHeader(p);
56
- if (headers?.authorization) {
73
+ const idToken = yield getIdTokenAuthHeader(p);
74
+ if (headers === null || headers === void 0 ? void 0 : headers.authorization) {
57
75
  config.baseOptions.headers.authorization = headers.authorization.toString();
58
76
  }
59
- else if (headers?.authorization === undefined && idToken) {
77
+ else if ((headers === null || headers === void 0 ? void 0 : headers.authorization) === undefined && idToken) {
60
78
  config.baseOptions.headers.authorization = `Bearer ${idToken}`;
61
79
  }
62
80
  if (config.baseOptions.headers.authorization) {
@@ -64,10 +82,7 @@ export const callOpenApi = async (p) => {
64
82
  {
65
83
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
66
84
  pre: (oldFetchParams) => {
67
- oldFetchParams.init.headers = {
68
- authorization: config.baseOptions.headers.authorization,
69
- ...oldFetchParams.init.headers,
70
- };
85
+ oldFetchParams.init.headers = Object.assign({ authorization: config.baseOptions.headers.authorization }, oldFetchParams.init.headers);
71
86
  },
72
87
  },
73
88
  ];
@@ -79,26 +94,26 @@ export const callOpenApi = async (p) => {
79
94
  errorCount += 1;
80
95
  try {
81
96
  // eslint-disable-next-line no-await-in-loop
82
- const resp = await func(cl);
97
+ const resp = yield func(cl);
83
98
  if (resp.status < 400) {
84
99
  data = resp.data;
85
100
  break;
86
101
  }
87
- throw new AxiosError(resp.statusText, resp.status?.toString() || '500');
102
+ throw new axios_1.AxiosError(resp.statusText, ((_a = resp.status) === null || _a === void 0 ? void 0 : _a.toString()) || '500');
88
103
  }
89
104
  catch (e) {
90
105
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
91
106
  const ae = e;
92
- const status = Number(ae.code ?? ae.response?.status ?? 500);
107
+ const status = Number((_d = (_b = ae.code) !== null && _b !== void 0 ? _b : (_c = ae.response) === null || _c === void 0 ? void 0 : _c.status) !== null && _d !== void 0 ? _d : 500);
93
108
  const errorMessage = [
94
- ae.status ?? '',
109
+ (_e = ae.status) !== null && _e !== void 0 ? _e : '',
95
110
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
96
- ae.response?.data?.toString() ?? '',
97
- ae.response?.statusText?.toString() ?? '',
98
- ae.response?.status?.toString() ?? '',
99
- ae.message?.toString() ?? '',
111
+ (_h = (_g = (_f = ae.response) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.toString()) !== null && _h !== void 0 ? _h : '',
112
+ (_l = (_k = (_j = ae.response) === null || _j === void 0 ? void 0 : _j.statusText) === null || _k === void 0 ? void 0 : _k.toString()) !== null && _l !== void 0 ? _l : '',
113
+ (_p = (_o = (_m = ae.response) === null || _m === void 0 ? void 0 : _m.status) === null || _o === void 0 ? void 0 : _o.toString()) !== null && _p !== void 0 ? _p : '',
114
+ (_r = (_q = ae.message) === null || _q === void 0 ? void 0 : _q.toString()) !== null && _r !== void 0 ? _r : '',
100
115
  ]
101
- .filter(notEmpty)
116
+ .filter(array_1.notEmpty)
102
117
  .sort((a, b) => (a.length < b.length ? -1 : 1))
103
118
  .join('\n');
104
119
  if (status === 403 || status === 401) {
@@ -108,15 +123,13 @@ export const callOpenApi = async (p) => {
108
123
  data: undefined,
109
124
  };
110
125
  }
111
- if (!retryHttpCodes.includes(status) || errorCount === errorMax) {
112
- error = { ...ae, message: errorMessage };
126
+ if (!const_1.retryHttpCodes.includes(status) || errorCount === errorMax) {
127
+ error = Object.assign(Object.assign({}, ae), { message: errorMessage });
113
128
  break;
114
129
  }
115
130
  }
116
- await sleep(retryHttpMs);
131
+ yield (0, sleep_1.sleep)(const_1.retryHttpMs);
117
132
  }
118
- return {
119
- data,
120
- ...(error && { error }),
121
- };
122
- };
133
+ return Object.assign({ data }, (error && { error }));
134
+ });
135
+ exports.callOpenApi = callOpenApi;
@@ -1,32 +1,47 @@
1
- import { arrayToObject } from '../../../common/helpers/array';
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.apiResponseToAxiosResponse = void 0;
13
+ const array_1 = require("../../../common/helpers/array");
2
14
  /**
3
15
  * shim to convert raw response to an axios style response.
4
16
  * must convert all DefaultClass requests to the Raw equivalent
5
17
  * @param p
6
18
  * @returns
7
19
  */
8
- export const apiResponseToAxiosResponse = async (p) => p()
9
- .then(async (r) => {
10
- const r1 = {
11
- status: r.raw.status,
12
- statusText: r.raw.statusText,
13
- data: await r.value(),
14
- headers: arrayToObject(Object.entries(r.raw.headers), (s) => s[0], (s) => s[1]),
15
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
- config: {},
17
- };
18
- return r1;
19
- })
20
- .catch((e) => {
21
- const er = e;
22
- const ret = {
23
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
24
- data: undefined,
25
- status: er.status,
26
- statusText: er.statusText,
27
- headers: arrayToObject(Object.entries(er.headers), (s) => s[0], (s) => s[1]),
28
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
- config: {},
30
- };
31
- return ret;
20
+ const apiResponseToAxiosResponse = (p) => __awaiter(void 0, void 0, void 0, function* () {
21
+ return p()
22
+ .then((r) => __awaiter(void 0, void 0, void 0, function* () {
23
+ const r1 = {
24
+ status: r.raw.status,
25
+ statusText: r.raw.statusText,
26
+ data: yield r.value(),
27
+ headers: (0, array_1.arrayToObject)(Object.entries(r.raw.headers), (s) => s[0], (s) => s[1]),
28
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
+ config: {},
30
+ };
31
+ return r1;
32
+ }))
33
+ .catch((e) => {
34
+ const er = e;
35
+ const ret = {
36
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
37
+ data: undefined,
38
+ status: er.status,
39
+ statusText: er.statusText,
40
+ headers: (0, array_1.arrayToObject)(Object.entries(er.headers), (s) => s[0], (s) => s[1]),
41
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
42
+ config: {},
43
+ };
44
+ return ret;
45
+ });
32
46
  });
47
+ exports.apiResponseToAxiosResponse = apiResponseToAxiosResponse;
@@ -1,57 +1,53 @@
1
- import { useCallback, useEffect, useState } from 'react';
2
- import { useGranularEffect } from '../useGranularHook';
3
- import { callOpenApiCachedRaw, setOpenApiCacheRaw } from './cached';
4
- import { callOpenApi } from './direct';
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.useCallOpenApi = void 0;
13
+ const react_1 = require("react");
14
+ const useGranularHook_1 = require("../useGranularHook");
15
+ const cached_1 = require("./cached");
16
+ const direct_1 = require("./direct");
5
17
  const defaultState = (p,
6
18
  /**
7
19
  * default false
8
20
  */
9
21
  noSsr = false) => {
22
+ var _a;
10
23
  const cachedData = noSsr
11
24
  ? undefined
12
- : callOpenApiCachedRaw({ ...p, onlyCached: true })?.data;
13
- return {
14
- data: undefined,
15
- datetime: 0,
16
- loadcount: 0,
17
- loading: false,
18
- ...(cachedData && { data: cachedData }),
19
- loaded: !!cachedData,
20
- };
25
+ : (_a = (0, cached_1.callOpenApiCachedRaw)(Object.assign(Object.assign({}, p), { onlyCached: true }))) === null || _a === void 0 ? void 0 : _a.data;
26
+ return Object.assign(Object.assign({ data: undefined, datetime: 0, loadcount: 0, loading: false }, (cachedData && { data: cachedData })), { loaded: !!cachedData });
21
27
  };
22
28
  /**
23
29
  * hooks+cached call to callOpenApi
24
30
  * @param p
25
31
  * @returns
26
32
  */
27
- export const useCallOpenApi = (inConfig) => {
33
+ const useCallOpenApi = (inConfig) => {
28
34
  /** response from hook */
29
- const [resp, setResp] = useState(defaultState(inConfig));
35
+ const [resp, setResp] = (0, react_1.useState)(defaultState(inConfig));
30
36
  /** config about hook*/
31
- const [config, setConfig] = useState(inConfig);
32
- useGranularEffect(() => {
37
+ const [config, setConfig] = (0, react_1.useState)(inConfig);
38
+ (0, useGranularHook_1.useGranularEffect)(() => {
33
39
  if (JSON.stringify(config) !== JSON.stringify(inConfig)) {
34
40
  setConfig(inConfig);
35
41
  setResp(defaultState(inConfig, true));
36
42
  }
37
43
  }, [inConfig], [resp, setResp, config, setConfig]);
38
- const reFetch = useCallback(async () => {
44
+ const reFetch = (0, react_1.useCallback)(() => __awaiter(void 0, void 0, void 0, function* () {
39
45
  const newdate = new Date().getTime();
40
- const newresp = await callOpenApi(config);
46
+ const newresp = yield (0, direct_1.callOpenApi)(config);
41
47
  setResp((d) => {
42
- let newState = {
43
- ...d,
44
- loaded: true,
45
- loading: false,
46
- };
48
+ let newState = Object.assign(Object.assign({}, d), { loaded: true, loading: false });
47
49
  if (newdate > d.datetime) {
48
- newState = {
49
- ...newresp,
50
- loaded: true,
51
- loading: false,
52
- loadcount: d.loadcount + 1,
53
- datetime: newdate,
54
- };
50
+ newState = Object.assign(Object.assign({}, newresp), { loaded: true, loading: false, loadcount: d.loadcount + 1, datetime: newdate });
55
51
  }
56
52
  if (JSON.stringify(d) !== JSON.stringify(newState)) {
57
53
  return newState;
@@ -60,30 +56,23 @@ export const useCallOpenApi = (inConfig) => {
60
56
  return d;
61
57
  }
62
58
  });
63
- }, [config]);
64
- useEffect(() => {
59
+ }), [config]);
60
+ (0, react_1.useEffect)(() => {
65
61
  const { error, loaded, loading, loadcount } = resp;
66
62
  const ng = config.disabled || loaded || loading || (error && loadcount > 2);
67
63
  if (ng) {
68
64
  return;
69
65
  }
70
- setResp((d) => ({ ...d, loading: true }));
66
+ setResp((d) => (Object.assign(Object.assign({}, d), { loading: true })));
71
67
  void reFetch();
72
68
  }, [config.disabled, reFetch, resp]);
73
- return {
74
- ...resp,
75
- reFetch,
76
- setData: async (p) => {
69
+ return Object.assign(Object.assign({}, resp), { reFetch, setData: (p) => __awaiter(void 0, void 0, void 0, function* () {
77
70
  //wipe cache, or might revert
78
- await setOpenApiCacheRaw(config, undefined);
71
+ yield (0, cached_1.setOpenApiCacheRaw)(config, undefined);
79
72
  //ensure datetime is changed, or might get overwritten
80
- setResp((x) => ({
81
- ...x,
82
- datetime: new Date().getTime(),
83
- data: typeof p === 'function'
73
+ setResp((x) => (Object.assign(Object.assign({}, x), { datetime: new Date().getTime(), data: typeof p === 'function'
84
74
  ? p(x.data)
85
- : p,
86
- }));
87
- },
88
- };
75
+ : p })));
76
+ }) });
89
77
  };
78
+ exports.useCallOpenApi = useCallOpenApi;
@@ -1,5 +1,21 @@
1
- export * from './cached';
2
- export * from './direct';
3
- export * from './helpers';
4
- export * from './hook';
5
- export * from './types';
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./cached"), exports);
18
+ __exportStar(require("./direct"), exports);
19
+ __exportStar(require("./helpers"), exports);
20
+ __exportStar(require("./hook"), exports);
21
+ __exportStar(require("./types"), exports);
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +1,5 @@
1
- export const expireDate = 'Thu, 01 Jan 1970 00:00:00 UTC';
2
- export const maxCookieLen = 4000;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.maxCookieLen = exports.expireDate = void 0;
4
+ exports.expireDate = 'Thu, 01 Jan 1970 00:00:00 UTC';
5
+ exports.maxCookieLen = 4000;
@@ -1,13 +1,16 @@
1
- import { warn } from '../../../common/helpers/log';
2
- import { fromBase64 } from '../../../common/helpers/string/base64';
3
- import { getCookie, wipeCookies } from './raw';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCookieString = exports.getCookieRawWrapper = void 0;
4
+ const log_1 = require("../../../common/helpers/log");
5
+ const base64_1 = require("../../../common/helpers/string/base64");
6
+ const raw_1 = require("./raw");
4
7
  /**
5
8
  * read chunks. json parse+unb64
6
9
  * parse defaults to JSON.parse. must change if want if type is not an object!
7
10
  * @param param0
8
11
  * @returns
9
12
  */
10
- export function getCookieRawWrapper({ name, cookieDocument, defaultValue, parse: parseRaw, }) {
13
+ function getCookieRawWrapper({ name, cookieDocument, defaultValue, parse: parseRaw, }) {
11
14
  const parse = (s) => {
12
15
  if (!s) {
13
16
  return defaultValue;
@@ -21,7 +24,7 @@ export function getCookieRawWrapper({ name, cookieDocument, defaultValue, parse:
21
24
  let currentCount = 0;
22
25
  // eslint-disable-next-line no-constant-condition
23
26
  while (true) {
24
- const newv = getCookie({
27
+ const newv = (0, raw_1.getCookie)({
25
28
  name: name + currentCount,
26
29
  cookieDocument,
27
30
  });
@@ -32,16 +35,14 @@ export function getCookieRawWrapper({ name, cookieDocument, defaultValue, parse:
32
35
  currentCount += 1;
33
36
  }
34
37
  try {
35
- return parse(fromBase64(raw));
38
+ return parse((0, base64_1.fromBase64)(raw));
36
39
  }
37
40
  catch (e) {
38
- warn('cookie error:', e);
39
- wipeCookies(name);
41
+ (0, log_1.warn)('cookie error:', e);
42
+ (0, raw_1.wipeCookies)(name);
40
43
  return defaultValue;
41
44
  }
42
45
  }
43
- export const getCookieString = (p) => getCookieRawWrapper({
44
- ...p,
45
- parse: (s) => s,
46
- defaultValue: p.defaultValue || '',
47
- });
46
+ exports.getCookieRawWrapper = getCookieRawWrapper;
47
+ const getCookieString = (p) => getCookieRawWrapper(Object.assign(Object.assign({}, p), { parse: (s) => s, defaultValue: p.defaultValue || '' }));
48
+ exports.getCookieString = getCookieString;
@@ -1,5 +1,21 @@
1
- export * from './const';
2
- export * from './get';
3
- export * from './raw';
4
- export * from './set';
5
- export * from './use';
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./const"), exports);
18
+ __exportStar(require("./get"), exports);
19
+ __exportStar(require("./raw"), exports);
20
+ __exportStar(require("./set"), exports);
21
+ __exportStar(require("./use"), exports);