ag-common 0.0.112 → 0.0.116

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.
@@ -1,3 +1,3 @@
1
1
  import { AxiosWrapper } from './jwt';
2
2
  import { ICallOpenApi } from './types';
3
- export declare const callOpenApi: <T, TDefaultApi>({ func, apiUrl, overrideAuth, refreshToken, logout, newDefaultApi, }: ICallOpenApi<T, TDefaultApi>) => Promise<AxiosWrapper<T>>;
3
+ export declare const callOpenApi: <T, TDefaultApi>({ func, apiUrl, overrideAuth, refreshToken, logout, newDefaultApi, headers, }: ICallOpenApi<T, TDefaultApi>) => Promise<AxiosWrapper<T>>;
@@ -13,14 +13,14 @@ exports.callOpenApi = void 0;
13
13
  const cookie_1 = require("./cookie");
14
14
  const sleep_1 = require("../../common/helpers/sleep");
15
15
  const array_1 = require("../../common/helpers/array");
16
- const callOpenApi = ({ func, apiUrl, overrideAuth, refreshToken, logout, newDefaultApi, }) => __awaiter(void 0, void 0, void 0, function* () {
16
+ const callOpenApi = ({ func, apiUrl, overrideAuth, refreshToken, logout, newDefaultApi, headers, }) => __awaiter(void 0, void 0, void 0, function* () {
17
17
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
18
18
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
19
  let error;
20
20
  let data = undefined;
21
21
  const config = {
22
22
  basePath: apiUrl,
23
- baseOptions: { headers: { authorization: '' } },
23
+ baseOptions: { headers: Object.assign({ authorization: '' }, (headers || {})) },
24
24
  };
25
25
  const isAuthed = !!(0, cookie_1.getCookieWrapper)({ cname: 'id_token' });
26
26
  if (overrideAuth === null || overrideAuth === void 0 ? void 0 : overrideAuth.id_token) {
@@ -11,4 +11,5 @@ export interface ICallOpenApi<T, TDefaultApi> {
11
11
  refreshToken: () => Promise<User | undefined>;
12
12
  newDefaultApi: (config: any) => TDefaultApi;
13
13
  disabled?: boolean;
14
+ headers?: Record<string, string | number>;
14
15
  }
@@ -1,8 +1,15 @@
1
1
  import { AxiosWrapper } from './jwt';
2
2
  import { ICallOpenApi } from './types';
3
+ import { CacheItems } from './routes';
3
4
  declare type AxiosWrapperWrap<T> = AxiosWrapper<T | undefined> & {
4
5
  loaded: boolean;
5
6
  loadcount: number;
6
7
  };
7
- export declare const useCallOpenApi: <T, TDefaultApi>(p: ICallOpenApi<T, TDefaultApi>) => AxiosWrapperWrap<T>;
8
+ export declare const useCallOpenApi: <T, TDefaultApi>(p: ICallOpenApi<T, TDefaultApi> & {
9
+ cacheKey: string;
10
+ /**
11
+ * will shortcut and return the appropriate axioswrapper data if cachekey is found
12
+ */
13
+ ssrCacheItems?: CacheItems | undefined;
14
+ }) => AxiosWrapperWrap<T>;
8
15
  export {};
@@ -12,20 +12,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.useCallOpenApi = void 0;
13
13
  const react_1 = require("react");
14
14
  const callOpenApi_1 = require("./callOpenApi");
15
- const defaultV = (def) => ({
16
- loading: false,
17
- data: def,
18
- datetime: new Date().getTime(),
19
- reFetch: () => __awaiter(void 0, void 0, void 0, function* () { }),
20
- error: undefined,
21
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
- url: undefined,
23
- //
24
- loaded: false,
25
- loadcount: 0,
26
- });
27
15
  const useCallOpenApi = (p) => {
28
- const [data, setData] = (0, react_1.useState)(defaultV(undefined));
16
+ var _a, _b;
17
+ const ssrCached = (_a = p.ssrCacheItems) === null || _a === void 0 ? void 0 : _a.find((s) => s.cacheKey === p.cacheKey);
18
+ const defv = {
19
+ data: undefined,
20
+ url: '',
21
+ datetime: 0,
22
+ loadcount: 0,
23
+ loading: false,
24
+ loaded: false,
25
+ reFetch: () => __awaiter(void 0, void 0, void 0, function* () { }),
26
+ };
27
+ const [data, setData] = (0, react_1.useState)(Object.assign(Object.assign({}, defv), { data: ssrCached ? (_b = ssrCached.prefillData) === null || _b === void 0 ? void 0 : _b.data : undefined, loaded: !!ssrCached }));
29
28
  (0, react_1.useEffect)(() => {
30
29
  function run() {
31
30
  return __awaiter(this, void 0, void 0, function* () {
@@ -34,14 +33,15 @@ const useCallOpenApi = (p) => {
34
33
  });
35
34
  }
36
35
  const { error, loaded, loading, loadcount } = data;
37
- if (p.disabled || loaded || loading || (error && loadcount < 2)) {
36
+ const ng = p.disabled || loaded || loading || (error && loadcount > 2);
37
+ if (ng) {
38
38
  return;
39
39
  }
40
40
  setData((d) => (Object.assign(Object.assign({}, d), { loading: true })));
41
41
  void run();
42
42
  }, [data, p, setData]);
43
43
  return Object.assign(Object.assign({}, data), { reFetch: () => __awaiter(void 0, void 0, void 0, function* () {
44
- setData(defaultV(undefined));
44
+ setData(defv);
45
45
  }) });
46
46
  };
47
47
  exports.useCallOpenApi = useCallOpenApi;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ag-common",
3
- "version": "0.0.112",
3
+ "version": "0.0.116",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Andrei Gec <@andreigec> (https://gec.dev/)",
@@ -13,7 +13,7 @@
13
13
  "start": "tsc --watch"
14
14
  },
15
15
  "dependencies": {
16
- "aws-sdk": "2.1064.0",
16
+ "aws-sdk": "2.1066.0",
17
17
  "axios": "0.25.0",
18
18
  "jsonwebtoken": "8.5.1",
19
19
  "jwks-rsa": "2.0.5",
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "devDependencies": {
30
30
  "@types/jsonwebtoken": "8.5.8",
31
- "@types/node": "17.0.12",
31
+ "@types/node": "17.0.13",
32
32
  "@types/react": "17.0.38",
33
33
  "@types/react-dom": "17.0.11",
34
34
  "@types/styled-components": "5.1.21",