ag-common 0.0.418 → 0.0.419

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