ag-common 0.0.359 → 0.0.360

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.
@@ -2,7 +2,7 @@ import { TGetAndValidateToken } from './validations';
2
2
  import { User } from '../../ui/helpers/jwt';
3
3
  import { TLang } from '../../common/helpers/i18n';
4
4
  import { APIGatewayEvent, APIGatewayProxyResult } from '../types';
5
- export declare type NextType<T> = ({ event, body, params, userProfile, lang, }: {
5
+ export type NextType<T> = ({ event, body, params, userProfile, lang, }: {
6
6
  params: Record<string, string>;
7
7
  event: APIGatewayEvent;
8
8
  body: T;
@@ -8,7 +8,7 @@ export interface IGetAndValidateToken {
8
8
  tokenRaw?: string;
9
9
  COGNITO_USER_POOL_ID: string;
10
10
  }
11
- export declare type TGetAndValidateToken = (p: IGetAndValidateToken) => Promise<{
11
+ export type TGetAndValidateToken = (p: IGetAndValidateToken) => Promise<{
12
12
  error?: APIGatewayProxyResult;
13
13
  token?: string;
14
14
  userProfile?: User;
@@ -4,28 +4,34 @@
4
4
  /* eslint-disable no-console */
5
5
  const fs = require('fs');
6
6
  const process = require('process');
7
- var pathV = require('path');
8
- var cwd = process.cwd();
9
- var resolvePath = (p) => pathV.resolve(cwd, p);
7
+ const pathV = require('path');
8
+ const cwd = process.cwd();
9
+ const resolvePath = (p) => pathV.resolve(cwd, p);
10
10
  function run() {
11
- var files = fs
11
+ const files = fs
12
12
  .readdirSync(resolvePath('./dist/api'))
13
- .filter((r) => r.endsWith('.js'))
14
- .map((s) => `./dist/api/${s}`);
15
- var found = false;
16
- files.filter(fs.existsSync).forEach((f) => {
17
- var c = fs.readFileSync(f).toString();
18
- if (c.includes('url_1')) {
19
- console.log('removing url_1 from ' + f);
20
- c = c.replace(/url_1\./gim, '');
13
+ .filter((r) => r.endsWith('.js') || r.endsWith('.d.ts'))
14
+ .map((s) => `./dist/api/${s}`)
15
+ .filter(fs.existsSync)
16
+ .map((file) => ({ file, content: fs.readFileSync(file).toString() }));
17
+ let found = false;
18
+ files.forEach(({ file, content }) => {
19
+ if (content.includes('url_1')) {
20
+ console.log('removing url_1 from ' + file);
21
+ content = content.replace(/url_1\./gim, '');
21
22
  found = true;
22
23
  }
23
- if (c.includes('this.configuration.queryParamsStringify(')) {
24
- console.log('fixing queryparams default from ' + f);
25
- c = c.replace(/this.configuration.queryParamsStringify\(/gim, '(this.configuration.queryParamsStringify||querystring)(');
24
+ if (content.includes('this.configuration.queryParamsStringify(')) {
25
+ console.log('fixing queryparams default from ' + file);
26
+ content = content.replace(/this.configuration.queryParamsStringify\(/gim, '(this.configuration.queryParamsStringify||querystring)(');
26
27
  found = true;
27
28
  }
28
- fs.writeFileSync(f, c);
29
+ if (content.includes(`import("axios").`)) {
30
+ console.log('fixing axios import from ' + file);
31
+ content = content.replace(/import\("axios"\)\./gim, '');
32
+ found = true;
33
+ }
34
+ fs.writeFileSync(file, content);
29
35
  });
30
36
  if (!found) {
31
37
  console.log('error: no files were fixed');
@@ -97,7 +97,7 @@ export interface DynamoDBStreamEvent {
97
97
  userIdentity?: any;
98
98
  }[];
99
99
  }
100
- export declare type Key = {
100
+ export type Key = {
101
101
  [key: string]: AttributeValue;
102
102
  };
103
103
  export {};
@@ -50,7 +50,7 @@ export interface ILambdaConfigs {
50
50
  default?: ILambdaConfig;
51
51
  };
52
52
  }
53
- export declare type TSkOperator = 'BETWEEN' | '<' | '<=' | '=' | '>=' | '>' | '<>' | 'BEGINS_WITH';
53
+ export type TSkOperator = 'BETWEEN' | '<' | '<=' | '=' | '>=' | '>' | '<>' | 'BEGINS_WITH';
54
54
  export interface IQueryDynamo {
55
55
  pkName: string;
56
56
  pkValue: string | number;
@@ -1,10 +1,10 @@
1
- declare type TLangExceptEn = 'id' | 'vi' | 'pt';
2
- export declare type TLang = TLangExceptEn | 'en';
1
+ type TLangExceptEn = 'id' | 'vi' | 'pt';
2
+ export type TLang = TLangExceptEn | 'en';
3
3
  export declare const AllLang: TLang[];
4
4
  /**
5
5
  * null = wont translate. undefined = fallback to eng
6
6
  */
7
- export declare type TResource = {
7
+ export type TResource = {
8
8
  [k in TLangExceptEn]?: string | null;
9
9
  } & {
10
10
  en: string;
@@ -1,4 +1,4 @@
1
- export declare type TLogType = 'TRACE' | 'DEBUG' | 'INFO' | 'WARN' | 'ERROR' | 'FATAL';
1
+ export type TLogType = 'TRACE' | 'DEBUG' | 'INFO' | 'WARN' | 'ERROR' | 'FATAL';
2
2
  export declare const GetLogLevel: (l: TLogType) => number;
3
3
  export declare const SetLogLevel: (l: TLogType) => void;
4
4
  export declare const debug: (...args: unknown[]) => void;
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- declare type IOnClick = React.MouseEvent<HTMLDivElement, MouseEvent> | React.MouseEvent<HTMLAnchorElement, MouseEvent>;
2
+ type IOnClick = React.MouseEvent<HTMLDivElement, MouseEvent> | React.MouseEvent<HTMLAnchorElement, MouseEvent>;
3
3
  export interface IBorderGradient {
4
4
  canClick?: boolean;
5
5
  noGrow?: boolean;
@@ -8,6 +8,6 @@ export interface IRowOrColumn {
8
8
  title?: string;
9
9
  enableOverflow?: boolean;
10
10
  }
11
- export declare type IFlexColumn = IRowOrColumn;
12
- export declare type IFlexRow = IRowOrColumn;
11
+ export type IFlexColumn = IRowOrColumn;
12
+ export type IFlexRow = IRowOrColumn;
13
13
  export declare const RowOrColumn: (props: IRowOrColumn) => JSX.Element;
@@ -29,9 +29,9 @@ export interface ISearchDialog<T> {
29
29
  totalItems?: (showing: number, outof: number) => string;
30
30
  };
31
31
  }
32
- export declare type TSearchModalRes<T> = undefined | {
32
+ export type TSearchModalRes<T> = undefined | {
33
33
  foundItem: T;
34
34
  searchText: string;
35
35
  };
36
- export declare type ISearchModal<T> = ISearchDialog<T>;
37
- export declare type ISearchInline<T> = ISearchDialog<T>;
36
+ export type ISearchModal<T> = ISearchDialog<T>;
37
+ export type ISearchInline<T> = ISearchDialog<T>;
@@ -9,7 +9,7 @@ export interface ISparkLine {
9
9
  pointTitleF?: (p: TSparkLineData) => string;
10
10
  title?: string;
11
11
  }
12
- export declare type TSparkLineData = {
12
+ export type TSparkLineData = {
13
13
  x: number;
14
14
  y: number;
15
15
  };
@@ -39,23 +39,23 @@ const axiosHelper = ({ verb, url, body, headers, timeout = 30000, retryMax = 0,
39
39
  }
40
40
  let noBody = false;
41
41
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
42
- let axios = axios_1.default.post;
42
+ let axiosV = axios_1.default.post;
43
43
  if (verb === 'put') {
44
- axios = axios_1.default.put;
44
+ axiosV = axios_1.default.put;
45
45
  }
46
46
  else if (verb === 'post') {
47
- axios = axios_1.default.post;
47
+ axiosV = axios_1.default.post;
48
48
  }
49
49
  else if (verb === 'patch') {
50
- axios = axios_1.default.patch;
50
+ axiosV = axios_1.default.patch;
51
51
  }
52
52
  else if (verb === 'delete') {
53
53
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
54
- axios = axios_1.default.delete;
54
+ axiosV = axios_1.default.delete;
55
55
  noBody = true;
56
56
  }
57
57
  if (noBody) {
58
- ret = yield axios(url, {
58
+ ret = yield axiosV(url, {
59
59
  headers: setHeaders,
60
60
  timeout,
61
61
  timeoutErrorMessage: `${url} timeout`,
@@ -66,7 +66,7 @@ const axiosHelper = ({ verb, url, body, headers, timeout = 30000, retryMax = 0,
66
66
  setHeaders['Content-Type'] =
67
67
  setHeaders['Content-Type'] || 'application/json';
68
68
  }
69
- ret = yield axios(url, body, { headers: setHeaders });
69
+ ret = yield axiosV(url, body, { headers: setHeaders });
70
70
  }
71
71
  return ret;
72
72
  }
@@ -1,7 +1,7 @@
1
1
  import { ICallOpenApi, OverrideAuth } from './types';
2
2
  import { CacheItems } from '../routes';
3
3
  import { AxiosWrapperLite } from '../jwt';
4
- export declare type TCallOpenApiCached<T, TDefaultApi> = ICallOpenApi<T, TDefaultApi> & {
4
+ export type TCallOpenApiCached<T, TDefaultApi> = ICallOpenApi<T, TDefaultApi> & {
5
5
  /**
6
6
  * if falsey, will run callOpenApi directly
7
7
  */
@@ -1,3 +1,9 @@
1
1
  import { AxiosResponse } from 'axios';
2
2
  import { 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
+ */
3
9
  export declare const apiResponseToAxiosResponse: <T>(p: () => Promise<ApiResponse<T>>) => Promise<AxiosResponse<T, any>>;
@@ -11,6 +11,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.apiResponseToAxiosResponse = void 0;
13
13
  const array_1 = require("../../../common/helpers/array");
14
+ /**
15
+ * shim to convert raw response to an axios style response.
16
+ * must convert all DefaultClass requests to the Raw equivalent
17
+ * @param p
18
+ * @returns
19
+ */
14
20
  const apiResponseToAxiosResponse = (p) => __awaiter(void 0, void 0, void 0, function* () {
15
21
  return p()
16
22
  .then((r) => __awaiter(void 0, void 0, void 0, function* () {
@@ -1,13 +1,13 @@
1
1
  import { ICallOpenApi } from './types';
2
2
  import { CacheItems } from '../routes';
3
3
  import { AxiosWrapper } from '../jwt';
4
- export declare type TUseCallOpenApiDispatch<A> = (value: A) => A;
5
- export declare type TUseCallOpenApi<T> = AxiosWrapper<T> & {
4
+ export type TUseCallOpenApiDispatch<A> = (value: A) => A;
5
+ export type TUseCallOpenApi<T> = AxiosWrapper<T> & {
6
6
  loaded: boolean;
7
7
  loadcount: number;
8
8
  setData: (d: TUseCallOpenApiDispatch<T | undefined>) => void;
9
9
  };
10
- declare type TUseCallOpenApiInt<T, TDefaultApi> = ICallOpenApi<T, TDefaultApi> & {
10
+ type TUseCallOpenApiInt<T, TDefaultApi> = ICallOpenApi<T, TDefaultApi> & {
11
11
  cacheKey: string;
12
12
  /**
13
13
  * will shortcut and return the appropriate axioswrapper data if cachekey is found
@@ -1,4 +1,4 @@
1
- export declare type TOnMessage = (m: string, options?: {
1
+ export type TOnMessage = (m: string, options?: {
2
2
  appearance: 'error' | 'success';
3
3
  }) => void;
4
4
  export interface ICognitoAuth {
@@ -1,6 +1,6 @@
1
1
  export declare const expireDate = "Thu, 01 Jan 1970 00:00:00 UTC";
2
2
  export declare const maxCookieLen = 4000;
3
- export declare type Dispatch<A> = (value: A) => void;
4
- export declare type SetStateAction<S> = S | ((prevState: S) => S);
5
- export declare type ReturnType<T> = [T, Dispatch<SetStateAction<T>>];
6
- export declare type TParse<T> = (s: string | null | undefined) => T;
3
+ export type Dispatch<A> = (value: A) => void;
4
+ export type SetStateAction<S> = S | ((prevState: S) => S);
5
+ export type ReturnType<T> = [T, Dispatch<SetStateAction<T>>];
6
+ export type TParse<T> = (s: string | null | undefined) => T;
@@ -1,7 +1,7 @@
1
1
  import { ICognitoAuth } from './cognito';
2
2
  import { AxiosWrapperLite } from './jwt';
3
3
  import { TLang } from '../../common/helpers/i18n';
4
- export declare type TProtocol = 'http:' | 'https:';
4
+ export type TProtocol = 'http:' | 'https:';
5
5
  export interface LocationSubset {
6
6
  /**
7
7
  * slash only path eg /aaa/bbb
@@ -33,7 +33,7 @@ export interface LocationSubset {
33
33
  */
34
34
  path: string;
35
35
  }
36
- export declare type CacheItems = CacheItem<any>[];
36
+ export type CacheItems = CacheItem<any>[];
37
37
  export interface CacheItem<T> {
38
38
  cacheKey: string;
39
39
  prefillData: AxiosWrapperLite<T>;
@@ -1,5 +1,5 @@
1
1
  import { DependencyList, EffectCallback } from 'react';
2
- declare type HookWithDependencies<C, R> = (callback: C, deps: DependencyList) => R;
2
+ type HookWithDependencies<C, R> = (callback: C, deps: DependencyList) => R;
3
3
  export declare const useGranularHook: <T extends HookWithDependencies<C, ReturnType<T>>, C>(hook: T, callback: C, primaryDeps: DependencyList, secondaryDeps: DependencyList) => ReturnType<T>;
4
4
  export declare const useGranularEffect: (effect: EffectCallback, primaryDeps: DependencyList, secondaryDeps: DependencyList) => void;
5
5
  export {};
@@ -1,5 +1,5 @@
1
1
  import { RefObject } from 'react';
2
- declare type Event = MouseEvent | TouchEvent;
2
+ type Event = MouseEvent | TouchEvent;
3
3
  export declare function useOnClickOutside<T extends HTMLElement = HTMLElement>(p: {
4
4
  /**
5
5
  * default false
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "ag-common",
3
- "version": "0.0.359",
3
+ "version": "0.0.360",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Andrei Gec <@andreigec> (https://gec.dev/)",
7
7
  "repository": "github:andreigec/ag-common",
8
8
  "license": "ISC",
9
- "packageManager": "yarn@3.3.0",
10
9
  "scripts": {
10
+ "preinstall": "npx only-allow pnpm",
11
11
  "format": "npx eslint --ext .ts,.tsx ./src --fix",
12
- "build": "rimraf dist && yarn lint && tsc",
12
+ "build": "rimraf dist && npm run lint && tsc",
13
13
  "lint": "npx eslint --ext .ts,.tsx ./src",
14
14
  "start": "cross-env BROWSER=none start-storybook -p 6006",
15
15
  "build-storybook": "build-storybook -o docs --quiet"