ag-common 0.0.761 → 0.0.763

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 (63) hide show
  1. package/dist/api/helpers/apigw.d.ts +1 -1
  2. package/dist/api/helpers/apigw.js +6 -8
  3. package/dist/api/helpers/index.d.ts +0 -2
  4. package/dist/api/helpers/index.js +0 -2
  5. package/dist/api/types/index.d.ts +0 -32
  6. package/dist/ui/components/LineChart/LegendX.js +7 -6
  7. package/dist/ui/components/LineChart/LegendY.js +1 -2
  8. package/dist/ui/components/index.d.ts +0 -1
  9. package/dist/ui/components/index.js +0 -1
  10. package/dist/ui/helpers/dom.js +2 -0
  11. package/dist/ui/helpers/index.d.ts +0 -1
  12. package/dist/ui/helpers/index.js +0 -1
  13. package/dist/ui/helpers/routes.d.ts +0 -11
  14. package/dist/ui/helpers/useContextMenu.js +3 -0
  15. package/dist/ui/helpers/useIsInViewport.js +1 -0
  16. package/dist/ui/helpers/useOnScroll.js +2 -3
  17. package/package.json +1 -2
  18. package/dist/api/helpers/openApiHelpers.d.ts +0 -43
  19. package/dist/api/helpers/openApiHelpers.js +0 -163
  20. package/dist/api/helpers/validateOpenApi.d.ts +0 -25
  21. package/dist/api/helpers/validateOpenApi.js +0 -127
  22. package/dist/api/openapi-postfix.d.ts +0 -1
  23. package/dist/api/openapi-postfix.js +0 -42
  24. package/dist/api/openapi-prefix.d.ts +0 -1
  25. package/dist/api/openapi-prefix.js +0 -88
  26. package/dist/ui/components/OpenApiCodeBlock/OpenApiCodeBlock.d.ts +0 -3
  27. package/dist/ui/components/OpenApiCodeBlock/OpenApiCodeBlock.js +0 -69
  28. package/dist/ui/components/OpenApiCodeBlock/curl/helpers/body.d.ts +0 -6
  29. package/dist/ui/components/OpenApiCodeBlock/curl/helpers/body.js +0 -30
  30. package/dist/ui/components/OpenApiCodeBlock/curl/helpers/getCurlLines.d.ts +0 -2
  31. package/dist/ui/components/OpenApiCodeBlock/curl/helpers/getCurlLines.js +0 -31
  32. package/dist/ui/components/OpenApiCodeBlock/curl/helpers/security.d.ts +0 -11
  33. package/dist/ui/components/OpenApiCodeBlock/curl/helpers/security.js +0 -28
  34. package/dist/ui/components/OpenApiCodeBlock/curl/index.d.ts +0 -6
  35. package/dist/ui/components/OpenApiCodeBlock/curl/index.js +0 -35
  36. package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/call.d.ts +0 -3
  37. package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/call.js +0 -23
  38. package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/getFetchLines.d.ts +0 -2
  39. package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/getFetchLines.js +0 -19
  40. package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/req.d.ts +0 -3
  41. package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/req.js +0 -78
  42. package/dist/ui/components/OpenApiCodeBlock/fetch/index.d.ts +0 -6
  43. package/dist/ui/components/OpenApiCodeBlock/fetch/index.js +0 -24
  44. package/dist/ui/components/OpenApiCodeBlock/helpers/common.d.ts +0 -20
  45. package/dist/ui/components/OpenApiCodeBlock/helpers/common.js +0 -89
  46. package/dist/ui/components/OpenApiCodeBlock/helpers/joinJsx.d.ts +0 -4
  47. package/dist/ui/components/OpenApiCodeBlock/helpers/joinJsx.js +0 -25
  48. package/dist/ui/components/OpenApiCodeBlock/index.d.ts +0 -2
  49. package/dist/ui/components/OpenApiCodeBlock/index.js +0 -17
  50. package/dist/ui/components/OpenApiCodeBlock/types.d.ts +0 -60
  51. package/dist/ui/components/OpenApiCodeBlock/types.js +0 -2
  52. package/dist/ui/helpers/callOpenApi/cached.d.ts +0 -34
  53. package/dist/ui/helpers/callOpenApi/cached.js +0 -92
  54. package/dist/ui/helpers/callOpenApi/direct.d.ts +0 -9
  55. package/dist/ui/helpers/callOpenApi/direct.js +0 -137
  56. package/dist/ui/helpers/callOpenApi/helpers.d.ts +0 -9
  57. package/dist/ui/helpers/callOpenApi/helpers.js +0 -60
  58. package/dist/ui/helpers/callOpenApi/hook.d.ts +0 -27
  59. package/dist/ui/helpers/callOpenApi/hook.js +0 -82
  60. package/dist/ui/helpers/callOpenApi/index.d.ts +0 -5
  61. package/dist/ui/helpers/callOpenApi/index.js +0 -20
  62. package/dist/ui/helpers/callOpenApi/types.d.ts +0 -19
  63. package/dist/ui/helpers/callOpenApi/types.js +0 -2
@@ -1,25 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.joinJsxWithComma = exports.joinJsxWithSlash = exports.joinJsx = void 0;
7
- const react_1 = __importDefault(require("react"));
8
- const array_1 = require("../../../../common/helpers/array");
9
- const joinJsx = (items, sep) => {
10
- const ret = [];
11
- items.filter(array_1.notEmpty).forEach((i, index) => {
12
- ret.push(i);
13
- if (index !== items.length - 1) {
14
- for (const s of sep) {
15
- ret.push(s);
16
- }
17
- }
18
- });
19
- return ret;
20
- };
21
- exports.joinJsx = joinJsx;
22
- const joinJsxWithSlash = (items) => (0, exports.joinJsx)(items, [react_1.default.createElement(react_1.default.Fragment, null, "\u00A0\\"), react_1.default.createElement("br", { key: "br1" })]);
23
- exports.joinJsxWithSlash = joinJsxWithSlash;
24
- const joinJsxWithComma = (items) => (0, exports.joinJsx)(items, [react_1.default.createElement(react_1.default.Fragment, null, ","), react_1.default.createElement("br", { key: "br1" })]);
25
- exports.joinJsxWithComma = joinJsxWithComma;
@@ -1,2 +0,0 @@
1
- export * from './OpenApiCodeBlock';
2
- export type * from './types';
@@ -1,17 +0,0 @@
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("./OpenApiCodeBlock"), exports);
@@ -1,60 +0,0 @@
1
- import type { JSX } from 'react';
2
- export interface IOpenApiOperation {
3
- description?: string;
4
- operationId: string;
5
- security?: {
6
- [name: string]: string;
7
- }[];
8
- }
9
- export interface IOpenApiSecurityScheme {
10
- in: string;
11
- name: string;
12
- }
13
- export interface IOpenApi {
14
- paths: {
15
- [pathname: string]: {
16
- [verb: string]: IOpenApiOperation;
17
- };
18
- };
19
- servers: {
20
- url: string;
21
- }[];
22
- components: {
23
- securitySchemes: {
24
- [name: string]: IOpenApiSecurityScheme;
25
- };
26
- };
27
- }
28
- export interface IOpenApiCodeBlock<TDefaultApi> {
29
- /**
30
- * openapi schema. eg
31
- * const schema: any = require('common/openapi.generated').default;
32
- */
33
- schema: IOpenApi;
34
- apiKey?: string;
35
- funcF: (f: TDefaultApi) => Promise<any>;
36
- }
37
- export interface ICurlLines {
38
- error?: string;
39
- verb?: string;
40
- path?: string;
41
- headerLines?: JSX.Element[];
42
- fullApiUrl?: string;
43
- bodyLine?: JSX.Element;
44
- operation?: IOpenApiOperation;
45
- }
46
- export interface IFetchLines {
47
- error?: string;
48
- verb?: string;
49
- path?: string;
50
- fullApiUrl?: string;
51
- reqContent?: JSX.Element;
52
- operation?: IOpenApiOperation;
53
- }
54
- export interface IOpenApiOperationBlock {
55
- error?: string;
56
- operation: IOpenApiOperation;
57
- verb: string;
58
- path: string;
59
- fullApiUrl: string;
60
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,34 +0,0 @@
1
- import type { AxiosWrapperLite } from '../jwt';
2
- import type { CacheItems } from '../routes';
3
- import type { ICallOpenApi, OverrideAuth } from './types';
4
- export type TCallOpenApiCached<T, TDefaultApi> = ICallOpenApi<T, TDefaultApi> & {
5
- /**
6
- * if falsey, will run callOpenApi directly
7
- */
8
- cacheKey: string;
9
- /**
10
- * will shortcut and return the appropriate axioswrapper data if cachekey is found
11
- */
12
- ssrCacheItems?: CacheItems;
13
- /**
14
- * default ttl in seconds for cache - default 120s
15
- */
16
- cacheTtl?: number;
17
- /**
18
- * (ssr) if true, wont run callopenapi if data is not cached
19
- */
20
- onlyCached?: boolean;
21
- };
22
- export declare const setOpenApiCacheRaw: <T>(p: {
23
- cacheKey: string;
24
- overrideAuth?: OverrideAuth | undefined;
25
- ssrCacheItems?: any;
26
- cacheTtl?: number;
27
- }, data: T) => Promise<void>;
28
- /**
29
- * sync call to callOpenApiCache.
30
- * @param p
31
- * @returns undefined if no cache item
32
- */
33
- export declare const callOpenApiCachedRaw: <T, TDefaultApi>(p: TCallOpenApiCached<T, TDefaultApi>) => AxiosWrapperLite<T> | undefined;
34
- export declare const callOpenApiCached: <T, TDefaultApi>(p: TCallOpenApiCached<T, TDefaultApi>) => Promise<AxiosWrapperLite<T | undefined>>;
@@ -1,92 +0,0 @@
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");
20
- let callOpenApiCache;
21
- /**
22
- * cache differs per user and per SSR provided data
23
- * @param param0
24
- * @returns
25
- */
26
- function getCacheKey({ cacheKey, overrideAuth, ssrCacheItems, }) {
27
- const authkeyPrefix1 = (0, direct_1.getIdTokenAuthHeaderRaw)({
28
- overrideAuth,
29
- });
30
- const authPref = !authkeyPrefix1 ? '' : (0, hashCode_1.hashCode)((0, base64_1.toBase64)(authkeyPrefix1));
31
- const ssrCachePref = !ssrCacheItems
32
- ? ''
33
- : (0, hashCode_1.hashCode)((0, base64_1.toBase64)(JSON.stringify(ssrCacheItems)));
34
- let cacheKeyRet;
35
- if (cacheKey) {
36
- cacheKeyRet = `${cacheKey}||${authPref}||${ssrCachePref}`;
37
- }
38
- return cacheKeyRet;
39
- }
40
- const setOpenApiCacheRaw = (p, data) => __awaiter(void 0, void 0, void 0, function* () {
41
- var _a;
42
- const userPrefixedCacheKey = getCacheKey(p);
43
- if (!userPrefixedCacheKey) {
44
- return;
45
- }
46
- if (!callOpenApiCache) {
47
- callOpenApiCache = new node_cache_1.default({ stdTTL: (_a = p.cacheTtl) !== null && _a !== void 0 ? _a : 120 });
48
- }
49
- callOpenApiCache.set(userPrefixedCacheKey, data);
50
- });
51
- exports.setOpenApiCacheRaw = setOpenApiCacheRaw;
52
- /**
53
- * sync call to callOpenApiCache.
54
- * @param p
55
- * @returns undefined if no cache item
56
- */
57
- const callOpenApiCachedRaw = (p) => {
58
- var _a, _b, _c, _d;
59
- const userPrefixedCacheKey = getCacheKey(p);
60
- if (!userPrefixedCacheKey) {
61
- return undefined;
62
- }
63
- if (!callOpenApiCache) {
64
- callOpenApiCache = new node_cache_1.default({ stdTTL: (_a = p.cacheTtl) !== null && _a !== void 0 ? _a : 120 });
65
- }
66
- //get ssr cache value
67
- const ssrCached = (_c = (_b = p.ssrCacheItems) === null || _b === void 0 ? void 0 : _b.find((s) => s.cacheKey === p.cacheKey)) === null || _c === void 0 ? void 0 : _c.prefillData.data;
68
- //if we have ssr cache and there is no existing cache then set
69
- if (!callOpenApiCache.get(userPrefixedCacheKey) && ssrCached) {
70
- callOpenApiCache.set(userPrefixedCacheKey, ssrCached);
71
- }
72
- //return cached data, or ssr data if that has already expired (ttl <=0)
73
- const data = (_d = callOpenApiCache.get(userPrefixedCacheKey)) !== null && _d !== void 0 ? _d : ssrCached;
74
- if (!data) {
75
- return undefined;
76
- }
77
- return { data };
78
- };
79
- exports.callOpenApiCachedRaw = callOpenApiCachedRaw;
80
- const callOpenApiCached = (p) => __awaiter(void 0, void 0, void 0, function* () {
81
- const raw = (0, exports.callOpenApiCachedRaw)(p);
82
- if (raw) {
83
- return raw;
84
- }
85
- const resp = yield (0, direct_1.callOpenApi)(p);
86
- if (resp.error) {
87
- return { error: resp.error, data: undefined };
88
- }
89
- yield (0, exports.setOpenApiCacheRaw)(p, resp.data);
90
- return resp;
91
- });
92
- exports.callOpenApiCached = callOpenApiCached;
@@ -1,9 +0,0 @@
1
- import type { AxiosWrapperLite } from '../jwt';
2
- import type { ICallOpenApi, OverrideAuth } from './types';
3
- /**
4
- * get the id_token from provided value, or cookie, or LS
5
- */
6
- export declare function getIdTokenAuthHeaderRaw({ overrideAuth, }: {
7
- overrideAuth?: OverrideAuth;
8
- }): string;
9
- export declare const callOpenApi: <T, TDefaultApi>(p: ICallOpenApi<T, TDefaultApi>) => Promise<AxiosWrapperLite<T>>;
@@ -1,137 +0,0 @@
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 = void 0;
13
- exports.getIdTokenAuthHeaderRaw = getIdTokenAuthHeaderRaw;
14
- const const_1 = require("../../../common/const");
15
- const array_1 = require("../../../common/helpers/array");
16
- const log_1 = require("../../../common/helpers/log");
17
- const sleep_1 = require("../../../common/helpers/sleep");
18
- const cookie_1 = require("../cookie");
19
- const useLocalStorage_1 = require("../useLocalStorage");
20
- /**
21
- * get the id_token from provided value, or cookie, or LS
22
- */
23
- function getIdTokenAuthHeaderRaw({ overrideAuth, }) {
24
- var _a;
25
- let idToken;
26
- //if override supplied will only use that and not refresh
27
- if (overrideAuth === null || overrideAuth === void 0 ? void 0 : overrideAuth.id_token) {
28
- idToken = overrideAuth.id_token;
29
- }
30
- else {
31
- idToken = (0, cookie_1.getCookieString)({
32
- name: 'id_token',
33
- defaultValue: '',
34
- });
35
- if (!idToken) {
36
- const userLs = (0, useLocalStorage_1.getLocalStorageItem)('user', undefined);
37
- if ((_a = userLs === null || userLs === void 0 ? void 0 : userLs.jwt) === null || _a === void 0 ? void 0 : _a.id_token) {
38
- idToken = userLs.jwt.id_token;
39
- }
40
- }
41
- }
42
- return idToken;
43
- }
44
- /**
45
- * get id_token, and then refresh
46
- */
47
- function getIdTokenAuthHeader(_a) {
48
- return __awaiter(this, arguments, void 0, function* ({ overrideAuth, refreshToken, }) {
49
- var _b;
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 ((_b = updated === null || updated === void 0 ? void 0 : updated.jwt) === null || _b === void 0 ? void 0 : _b.id_token) {
55
- idToken = updated.jwt.id_token;
56
- }
57
- }
58
- return idToken;
59
- });
60
- }
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;
63
- const { func, apiUrl, logout, newDefaultApi, headers } = p;
64
- let error;
65
- let data = undefined;
66
- const config = {
67
- basePath: apiUrl,
68
- baseOptions: { headers: headers !== null && headers !== void 0 ? headers : {} },
69
- middleware: [],
70
- };
71
- //comes from either id_token cookie OR auth override param
72
- const idToken = yield getIdTokenAuthHeader(p);
73
- if (headers === null || headers === void 0 ? void 0 : headers.authorization) {
74
- config.baseOptions.headers.authorization = headers.authorization.toString();
75
- }
76
- else if ((headers === null || headers === void 0 ? void 0 : headers.authorization) === undefined && idToken) {
77
- config.baseOptions.headers.authorization = `Bearer ${idToken}`;
78
- }
79
- if (config.baseOptions.headers.authorization) {
80
- config.middleware = [
81
- {
82
- pre: (oldFetchParams) => {
83
- var _a, _b, _c;
84
- const url = (_a = oldFetchParams === null || oldFetchParams === void 0 ? void 0 : oldFetchParams.url) !== null && _a !== void 0 ? _a : '(url)';
85
- const verb = (_c = (_b = oldFetchParams === null || oldFetchParams === void 0 ? void 0 : oldFetchParams.init) === null || _b === void 0 ? void 0 : _b.method) !== null && _c !== void 0 ? _c : '(verb)';
86
- (0, log_1.debug)(`callOpenApi: making ${verb} call to ${url}`);
87
- oldFetchParams.init.headers = Object.assign({ authorization: config.baseOptions.headers.authorization }, oldFetchParams.init.headers);
88
- },
89
- },
90
- ];
91
- }
92
- const cl = newDefaultApi(config);
93
- let errorCount = 0;
94
- const errorMax = 3;
95
- while (errorCount <= errorMax) {
96
- errorCount += 1;
97
- try {
98
- const response = yield func(cl);
99
- if (response.status < 400) {
100
- data = response.data;
101
- break;
102
- }
103
- throw { response };
104
- }
105
- catch (e) {
106
- const ae = e;
107
- const status = Number((_c = (_a = ae.code) !== null && _a !== void 0 ? _a : (_b = ae.response) === null || _b === void 0 ? void 0 : _b.status) !== null && _c !== void 0 ? _c : 500);
108
- const errorMessage = [
109
- (_d = ae.status) !== null && _d !== void 0 ? _d : '',
110
- (_g = (_f = (_e = ae.response) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.toString()) !== null && _g !== void 0 ? _g : '',
111
- (_j = (_h = ae.response) === null || _h === void 0 ? void 0 : _h.statusText.toString()) !== null && _j !== void 0 ? _j : '',
112
- (_l = (_k = ae.response) === null || _k === void 0 ? void 0 : _k.status.toString()) !== null && _l !== void 0 ? _l : '',
113
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
114
- (_o = (_m = ae.message) === null || _m === void 0 ? void 0 : _m.toString()) !== null && _o !== void 0 ? _o : '',
115
- ]
116
- .filter(array_1.notEmpty)
117
- .sort((a, b) => (a.length < b.length ? -1 : 1))
118
- .join('\n');
119
- //if auth fail, then quick exit
120
- if (status === 403 || status === 401) {
121
- logout();
122
- return {
123
- error: ae,
124
- data: undefined,
125
- };
126
- }
127
- //if not a potential retriable error, or have retried enough, then exit
128
- if (!const_1.retryHttpCodes.includes(status) || errorCount === errorMax) {
129
- error = Object.assign(Object.assign({}, ae), { message: errorMessage });
130
- break;
131
- }
132
- }
133
- yield (0, sleep_1.sleep)(const_1.retryHttpMs);
134
- }
135
- return Object.assign({ data }, (error && { error }));
136
- });
137
- exports.callOpenApi = callOpenApi;
@@ -1,9 +0,0 @@
1
- import type { AxiosResponse } from 'axios';
2
- import type { ApiResponse } from './types';
3
- /**
4
- * shim to convert raw response to an axios style response.
5
- * must convert all DefaultClass requests to the Raw equivalent
6
- * @param p
7
- * @returns
8
- */
9
- export declare const apiResponseToAxiosResponse: <T>(p: () => Promise<ApiResponse<T>>) => Promise<AxiosResponse<T>>;
@@ -1,60 +0,0 @@
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");
14
- const stream_1 = require("../../../common/helpers/stream");
15
- /**
16
- * shim to convert raw response to an axios style response.
17
- * must convert all DefaultClass requests to the Raw equivalent
18
- * @param p
19
- * @returns
20
- */
21
- const apiResponseToAxiosResponse = (p) => __awaiter(void 0, void 0, void 0, function* () {
22
- try {
23
- const r = yield p();
24
- const r1 = {
25
- status: r.raw.status,
26
- statusText: r.raw.statusText,
27
- data: yield r.value(),
28
- headers: (0, array_1.arrayToObject)(Object.entries(r.raw.headers), (s) => s[0], (s) => s[1]),
29
- config: {},
30
- };
31
- return r1;
32
- }
33
- catch (e) {
34
- const er = e;
35
- //try and get body
36
- let statusText = er.statusText || e.stack || '';
37
- if (er.body) {
38
- try {
39
- const st = yield (0, stream_1.getStringFromStream)(er.body);
40
- statusText = st;
41
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
42
- }
43
- catch (e) {
44
- //
45
- }
46
- }
47
- const ret = {
48
- data: undefined,
49
- status: er.status,
50
- statusText,
51
- headers:
52
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
53
- er.headers &&
54
- (0, array_1.arrayToObject)(Object.entries(er.headers), (s) => s[0], (s) => s[1]),
55
- config: {},
56
- };
57
- return ret;
58
- }
59
- });
60
- exports.apiResponseToAxiosResponse = apiResponseToAxiosResponse;
@@ -1,27 +0,0 @@
1
- import type { AxiosWrapper } from '../jwt';
2
- import type { CacheItems } from '../routes';
3
- import type { ICallOpenApi } from './types';
4
- export type TUseCallOpenApi<T> = AxiosWrapper<T> & {
5
- loaded: boolean;
6
- loadcount: number;
7
- /** internally mutate state, but do not refetch. will automatically bump datetime */
8
- setData: React.Dispatch<React.SetStateAction<T>>;
9
- };
10
- type TUseCallOpenApiInt<T, TDefaultApi> = ICallOpenApi<T, TDefaultApi> & {
11
- cacheKey: string;
12
- /**
13
- * will shortcut and return the appropriate axioswrapper data if cachekey is found
14
- */
15
- ssrCacheItems?: CacheItems;
16
- /**
17
- * default ttl in seconds for cache - default 120s
18
- */
19
- cacheTtl?: number;
20
- };
21
- /**
22
- * hooks+cached call to callOpenApi
23
- * @param p
24
- * @returns
25
- */
26
- export declare const useCallOpenApi: <T, TDefaultApi>(inConfig: TUseCallOpenApiInt<T, TDefaultApi>) => TUseCallOpenApi<T>;
27
- export {};
@@ -1,82 +0,0 @@
1
- "use strict";
2
- 'use client';
3
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
- return new (P || (P = Promise))(function (resolve, reject) {
6
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
- step((generator = generator.apply(thisArg, _arguments || [])).next());
10
- });
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.useCallOpenApi = void 0;
14
- const react_1 = require("react");
15
- const useGranularHook_1 = require("../useGranularHook");
16
- const cached_1 = require("./cached");
17
- const direct_1 = require("./direct");
18
- const defaultState = (p,
19
- /**
20
- * default false
21
- */
22
- noSsr = false) => {
23
- var _a;
24
- const cachedData = noSsr
25
- ? undefined
26
- : (_a = (0, cached_1.callOpenApiCachedRaw)(Object.assign(Object.assign({}, p), { onlyCached: true }))) === null || _a === void 0 ? void 0 : _a.data;
27
- return Object.assign(Object.assign({ data: undefined, datetime: 0, loadcount: 0, loading: false }, (cachedData && { data: cachedData })), { loaded: !!cachedData });
28
- };
29
- /**
30
- * hooks+cached call to callOpenApi
31
- * @param p
32
- * @returns
33
- */
34
- const useCallOpenApi = (inConfig) => {
35
- /** response from hook */
36
- const [resp, setResp] = (0, react_1.useState)(defaultState(inConfig));
37
- /** config about hook*/
38
- const [config, setConfig] = (0, react_1.useState)(inConfig);
39
- (0, useGranularHook_1.useGranularEffect)(() => {
40
- if (JSON.stringify(Object.assign(Object.assign({}, config), { headers: undefined, ssrCacheItems: undefined, overrideAuth: undefined })) !==
41
- JSON.stringify(Object.assign(Object.assign({}, inConfig), { headers: undefined, ssrCacheItems: undefined, overrideAuth: undefined }))) {
42
- setConfig(inConfig);
43
- setResp(Object.assign(Object.assign({}, defaultState(inConfig, true)), { loading: true }));
44
- void (0, direct_1.callOpenApi)(inConfig).then((r) => setResp((r2) => (Object.assign(Object.assign(Object.assign({}, r2), r), { loading: false }))));
45
- }
46
- }, [inConfig], [resp, setResp, config, setConfig]);
47
- const reFetch = (0, react_1.useCallback)(() => __awaiter(void 0, void 0, void 0, function* () {
48
- const newdate = new Date().getTime();
49
- const newresp = yield (0, direct_1.callOpenApi)(config);
50
- setResp((d) => {
51
- let newState = Object.assign(Object.assign({}, d), { loaded: true, loading: false });
52
- if (newdate > d.datetime) {
53
- newState = Object.assign(Object.assign({}, newresp), { loaded: true, loading: false, loadcount: d.loadcount + 1, datetime: newdate });
54
- }
55
- if (JSON.stringify(d) !== JSON.stringify(newState)) {
56
- return newState;
57
- }
58
- else {
59
- return d;
60
- }
61
- });
62
- }), [config]);
63
- (0, react_1.useEffect)(() => {
64
- const { error, loaded, loading, loadcount } = resp;
65
- const ng = config.disabled || loaded || loading || (error && loadcount > 2);
66
- if (ng) {
67
- return;
68
- }
69
- setResp((d) => (Object.assign(Object.assign({}, d), { loading: true })));
70
- void reFetch();
71
- }, [config.disabled, reFetch, resp]);
72
- const ret = Object.assign(Object.assign({}, resp), { reFetch, setData: (p) => __awaiter(void 0, void 0, void 0, function* () {
73
- //wipe cache, or might revert
74
- yield (0, cached_1.setOpenApiCacheRaw)(config, undefined);
75
- //ensure datetime is changed, or might get overwritten
76
- setResp((x) => (Object.assign(Object.assign({}, x), { datetime: new Date().getTime(), data: typeof p === 'function'
77
- ? p(x.data)
78
- : p })));
79
- }) });
80
- return ret;
81
- };
82
- exports.useCallOpenApi = useCallOpenApi;
@@ -1,5 +0,0 @@
1
- export * from './cached';
2
- export * from './direct';
3
- export * from './helpers';
4
- export * from './hook';
5
- export type * from './types';
@@ -1,20 +0,0 @@
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);
@@ -1,19 +0,0 @@
1
- import type { AxiosResponse } from 'axios';
2
- import type { User } from '../jwt';
3
- export interface OverrideAuth {
4
- id_token?: string;
5
- }
6
- export interface ICallOpenApi<T, TDefaultApi> {
7
- func: (f: TDefaultApi) => Promise<AxiosResponse<T>>;
8
- apiUrl: string;
9
- overrideAuth?: OverrideAuth;
10
- logout: () => void;
11
- refreshToken: () => Promise<User | undefined>;
12
- newDefaultApi: (config: any) => TDefaultApi;
13
- disabled?: boolean;
14
- headers?: Record<string, string | number>;
15
- }
16
- export interface ApiResponse<T> {
17
- raw: Response;
18
- value(): Promise<T>;
19
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });