ag-common 0.0.136 → 0.0.141

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 { aws_certificatemanager as certmgr, aws_route53 as route53 } from 'aws-c
2
2
  import { Construct } from 'constructs';
3
3
  import { ILambdaConfigs } from '../types';
4
4
  export declare const openApiImpl: (p: {
5
- schema: any;
5
+ schema: unknown;
6
6
  stack: Construct;
7
7
  NODE_ENV: string;
8
8
  baseUrl: string;
@@ -1,9 +1,9 @@
1
1
  export declare type TLogType = 'TRACE' | 'DEBUG' | 'INFO' | 'WARN' | 'ERROR' | 'FATAL';
2
2
  export declare const GetLogLevel: (l: TLogType) => number;
3
3
  export declare const SetLogLevel: (l: string) => void;
4
- export declare const debug: (...args: any[]) => void;
5
- export declare const info: (...args: any[]) => void;
6
- export declare const warn: (...args: any[]) => void;
7
- export declare const trace: (...args: any[]) => void;
8
- export declare const error: (...args: any[]) => void;
9
- export declare const fatal: (...args: any[]) => void;
4
+ export declare const debug: (...args: unknown[]) => void;
5
+ export declare const info: (...args: unknown[]) => void;
6
+ export declare const warn: (...args: unknown[]) => void;
7
+ export declare const trace: (...args: unknown[]) => void;
8
+ export declare const error: (...args: unknown[]) => void;
9
+ export declare const fatal: (...args: unknown[]) => void;
@@ -1,8 +1,7 @@
1
1
  "use strict";
2
+ /* eslint-disable no-console */
2
3
  Object.defineProperty(exports, "__esModule", { value: true });
3
4
  exports.fatal = exports.error = exports.trace = exports.warn = exports.info = exports.debug = exports.SetLogLevel = exports.GetLogLevel = void 0;
4
- /* eslint-disable no-console */
5
- /* eslint-disable @typescript-eslint/no-explicit-any */
6
5
  const _1 = require(".");
7
6
  const GetLogLevel = (l) => ['TRACE', 'DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL'].findIndex((s) => s === l);
8
7
  exports.GetLogLevel = GetLogLevel;
@@ -1,5 +1,5 @@
1
1
  export declare const tryJsonParse: <T>(str: string | undefined | null, defaultValue: T | null | undefined) => T | null | undefined;
2
- export declare function isJson(str: string | Record<string, unknown>): boolean;
2
+ export declare function isJson(str: unknown): boolean;
3
3
  export declare const objectKeysToLowerCase: <T>(origObj: {
4
4
  [a: string]: T;
5
5
  }) => {
@@ -1 +1 @@
1
- export declare function shuffle(array: any[], seed: number): any[];
1
+ export declare function shuffle<T>(array: T[], seed: number): T[];
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.shuffle = void 0;
4
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
5
4
  function shuffle(array, seed) {
6
5
  let currentIndex = array.length;
7
6
  let temporaryValue;
@@ -32,5 +32,12 @@ export declare function containsInsensitive(str: string, ...args: string[]): boo
32
32
  * @param indent
33
33
  * @returns
34
34
  */
35
- export declare const safeStringify: (obj: any, indent?: number) => string;
35
+ export declare const safeStringify: (obj: unknown, indent?: number) => string;
36
36
  export declare const chunkString: (str: string, length: number) => string[];
37
+ /**
38
+ * object to string - can be used for querystring a=b&c=d etc
39
+ * @param raw eg a=b&c=d
40
+ * @param splitKeyValue eg =
41
+ * @param splitKeys eg &
42
+ */
43
+ export declare function stringToObject(raw: string, splitKeyValue: string, splitKeys: string): Record<string, string>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.chunkString = exports.safeStringify = exports.containsInsensitive = exports.replaceRemove = exports.toTitleCase = exports.niceUrl = exports.truncate = exports.trim = exports.trimSide = exports.csvJSON = exports.fromBase64 = exports.toBase64 = void 0;
3
+ exports.stringToObject = exports.chunkString = exports.safeStringify = exports.containsInsensitive = exports.replaceRemove = exports.toTitleCase = exports.niceUrl = exports.truncate = exports.trim = exports.trimSide = exports.csvJSON = exports.fromBase64 = exports.toBase64 = void 0;
4
4
  const toBase64 = (str) => Buffer.from(str).toString('base64');
5
5
  exports.toBase64 = toBase64;
6
6
  const fromBase64 = (str) => Buffer.from(decodeURIComponent(str), 'base64').toString();
@@ -127,7 +127,6 @@ exports.containsInsensitive = containsInsensitive;
127
127
  * @param indent
128
128
  * @returns
129
129
  */
130
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
131
130
  const safeStringify = (obj, indent = 2) => {
132
131
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
133
132
  let cache = [];
@@ -142,3 +141,18 @@ const safeStringify = (obj, indent = 2) => {
142
141
  exports.safeStringify = safeStringify;
143
142
  const chunkString = (str, length) => str.match(new RegExp(`.{1,${length}}`, 'g'));
144
143
  exports.chunkString = chunkString;
144
+ /**
145
+ * object to string - can be used for querystring a=b&c=d etc
146
+ * @param raw eg a=b&c=d
147
+ * @param splitKeyValue eg =
148
+ * @param splitKeys eg &
149
+ */
150
+ function stringToObject(raw, splitKeyValue, splitKeys) {
151
+ const ret = {};
152
+ raw.split(splitKeys).forEach((set) => {
153
+ const [k, v] = set.split(splitKeyValue);
154
+ ret[k] = v;
155
+ });
156
+ return ret;
157
+ }
158
+ exports.stringToObject = stringToObject;
@@ -53,15 +53,14 @@ const UserImage = ({ image, className, }) => {
53
53
  };
54
54
  exports.UserImage = UserImage;
55
55
  const UserProfileImage = ({ className, user, }) => {
56
- var _a, _b, _c, _d;
57
- let image = (_a = user === null || user === void 0 ? void 0 : user.data) === null || _a === void 0 ? void 0 : _a.picture;
58
- if ((_b = user === null || user === void 0 ? void 0 : user.data) === null || _b === void 0 ? void 0 : _b.picture) {
59
- if (!images.domains.find((i) => user.data.picture.includes(i))) {
60
- image = image || '';
61
- (0, log_1.warn)(`bad domain:${user.data.picture}`);
56
+ var _a, _b, _c;
57
+ const image = (_a = user === null || user === void 0 ? void 0 : user.data) === null || _a === void 0 ? void 0 : _a.picture;
58
+ if (image) {
59
+ if (!images.domains.find((i) => image.includes(i))) {
60
+ (0, log_1.warn)(`bad domain:${image}`);
62
61
  }
63
62
  }
64
- const titleA = [(_c = user === null || user === void 0 ? void 0 : user.data) === null || _c === void 0 ? void 0 : _c.fullname, (_d = user === null || user === void 0 ? void 0 : user.data) === null || _d === void 0 ? void 0 : _d.userId].filter(array_1.notEmpty);
63
+ const titleA = [(_b = user === null || user === void 0 ? void 0 : user.data) === null || _b === void 0 ? void 0 : _b.fullname, (_c = user === null || user === void 0 ? void 0 : user.data) === null || _c === void 0 ? void 0 : _c.userId].filter(array_1.notEmpty);
65
64
  const title = titleA.length === 0 ? '' : titleA.join(' - ');
66
65
  return (react_1.default.createElement(Base, { className: className, title: title },
67
66
  image && react_1.default.createElement(Img, { alt: "user", src: image }),
@@ -59,7 +59,6 @@ const axiosHelper = ({ verb, url, body, headers, timeout = 30000, retryMax = 0,
59
59
  });
60
60
  }
61
61
  else {
62
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
63
62
  if (body && (0, object_1.isJson)(body)) {
64
63
  setHeaders['Content-Type'] =
65
64
  setHeaders['Content-Type'] || 'application/json';
@@ -25,4 +25,4 @@ export declare type TCallOpenApiCached<T, TDefaultApi> = ICallOpenApi<T, TDefaul
25
25
  * @returns undefined if no cache item
26
26
  */
27
27
  export declare const callOpenApiCachedRaw: <T, TDefaultApi>(p: TCallOpenApiCached<T, TDefaultApi>) => AxiosWrapperLite<T> | undefined;
28
- export declare const callOpenApiCached: <T, TDefaultApi>(p: TCallOpenApiCached<T, TDefaultApi>) => Promise<AxiosWrapperLite<T>>;
28
+ export declare const callOpenApiCached: <T, TDefaultApi>(p: TCallOpenApiCached<T, TDefaultApi>) => Promise<AxiosWrapperLite<T | undefined>>;
@@ -66,7 +66,6 @@ const callOpenApiCached = (p) => __awaiter(void 0, void 0, void 0, function* ()
66
66
  }
67
67
  const resp = yield (0, direct_1.callOpenApi)(p);
68
68
  if (resp.error) {
69
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
70
69
  return { error: resp.error, data: undefined };
71
70
  }
72
71
  const userPrefixedCacheKey = getCacheKey(p);
@@ -1,9 +1,11 @@
1
1
  import { AxiosWrapper } from '../jwt';
2
2
  import { ICallOpenApi } from './types';
3
3
  import { CacheItems } from '../routes';
4
- declare type AxiosWrapperWrap<T> = AxiosWrapper<T | undefined> & {
4
+ export declare type TUseCallOpenApiDispatch<A> = (value: A) => A;
5
+ export declare type TUseCallOpenApi<T> = AxiosWrapper<T> & {
5
6
  loaded: boolean;
6
7
  loadcount: number;
8
+ setData: (d: TUseCallOpenApiDispatch<T | undefined>) => void;
7
9
  };
8
10
  /**
9
11
  * hooks+cached call to callOpenApi
@@ -20,5 +22,4 @@ export declare const useCallOpenApi: <T, TDefaultApi>(p: ICallOpenApi<T, TDefaul
20
22
  * default ttl in seconds for cache - default 120s
21
23
  */
22
24
  cacheTtl?: number | undefined;
23
- }) => AxiosWrapperWrap<T>;
24
- export {};
25
+ }) => TUseCallOpenApi<T>;
@@ -28,6 +28,7 @@ const useCallOpenApi = (p) => {
28
28
  loading: false,
29
29
  loaded: false,
30
30
  reFetch: () => __awaiter(void 0, void 0, void 0, function* () { }),
31
+ setData: () => { },
31
32
  };
32
33
  const cachedData = (_a = (0, cached_1.callOpenApiCachedRaw)(Object.assign(Object.assign({}, p), { onlyCached: true }))) === null || _a === void 0 ? void 0 : _a.data;
33
34
  const [data, setData] = (0, react_1.useState)(Object.assign(Object.assign(Object.assign({}, defv), (cachedData && { data: cachedData })), { loaded: !!cachedData }));
@@ -35,7 +36,7 @@ const useCallOpenApi = (p) => {
35
36
  function run() {
36
37
  return __awaiter(this, void 0, void 0, function* () {
37
38
  const resp = yield (0, direct_1.callOpenApi)(p);
38
- setData((d) => (Object.assign(Object.assign({}, resp), { loaded: true, loading: false, loadcount: d.loadcount + 1, reFetch: () => __awaiter(this, void 0, void 0, function* () { }), url: '', datetime: new Date().getTime() })));
39
+ setData((d) => (Object.assign(Object.assign({}, resp), { loaded: true, loading: false, loadcount: d.loadcount + 1, reFetch: () => __awaiter(this, void 0, void 0, function* () { }), url: '', datetime: new Date().getTime(), setData: () => { } })));
39
40
  });
40
41
  }
41
42
  const { error, loaded, loading, loadcount } = data;
@@ -48,6 +49,8 @@ const useCallOpenApi = (p) => {
48
49
  }, [data, p, setData]);
49
50
  return Object.assign(Object.assign({}, data), { reFetch: () => __awaiter(void 0, void 0, void 0, function* () {
50
51
  setData(defv);
51
- }) });
52
+ }), setData: (d) => {
53
+ setData(Object.assign(Object.assign({}, data), { data: d(data.data), datetime: new Date().getTime() }));
54
+ } });
52
55
  };
53
56
  exports.useCallOpenApi = useCallOpenApi;
@@ -19,7 +19,10 @@ export declare function getCookieRawWrapper<T>({ name, cookieDocument, defaultVa
19
19
  parse?: (s: string) => T;
20
20
  }): T;
21
21
  export declare const getCookieString: (p: {
22
- defaultValue: string;
22
+ /**
23
+ * default value. default ''
24
+ */
25
+ defaultValue?: string;
23
26
  name: string;
24
27
  cookieDocument?: string;
25
28
  }) => string;
@@ -59,5 +59,5 @@ function getCookieRawWrapper({ name, cookieDocument, defaultValue, parse: parseR
59
59
  }
60
60
  }
61
61
  exports.getCookieRawWrapper = getCookieRawWrapper;
62
- const getCookieString = (p) => getCookieRawWrapper(Object.assign(Object.assign({}, p), { parse: (s) => s }));
62
+ const getCookieString = (p) => getCookieRawWrapper(Object.assign(Object.assign({}, p), { parse: (s) => s, defaultValue: p.defaultValue || '' }));
63
63
  exports.getCookieString = getCookieString;
@@ -13,3 +13,8 @@ export declare function setCookieRawWrapper<T>(p: {
13
13
  */
14
14
  stringify?: (s: T) => string;
15
15
  }): void;
16
+ export declare const setCookieString: (p: {
17
+ value: string;
18
+ name: string;
19
+ cookieDocument?: string;
20
+ }) => void;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setCookieRawWrapper = exports.wipeCookies = void 0;
3
+ exports.setCookieString = exports.setCookieRawWrapper = exports.wipeCookies = void 0;
4
4
  const log_1 = require("../../../common/helpers/log");
5
5
  const string_1 = require("../../../common/helpers/string");
6
6
  const const_1 = require("./const");
@@ -64,3 +64,5 @@ function setCookieRawWrapper(p) {
64
64
  }
65
65
  }
66
66
  exports.setCookieRawWrapper = setCookieRawWrapper;
67
+ const setCookieString = (p) => setCookieRawWrapper(Object.assign(Object.assign({}, p), { stringify: (s) => s }));
68
+ exports.setCookieString = setCookieString;
@@ -13,12 +13,18 @@ export declare function useCookie<T>(p: {
13
13
  stringify?: (v: T) => string;
14
14
  }): ReturnType<T>;
15
15
  export declare const useCookieString: (p: {
16
- defaultValue: string;
16
+ /**
17
+ * default value. default ""
18
+ */
19
+ defaultValue?: string;
17
20
  name: string;
18
21
  cookieDocument?: string;
19
22
  }) => ReturnType<string>;
20
23
  export declare const useCookieNumber: (p: {
21
- defaultValue: number | undefined;
24
+ /**
25
+ * default value. default undefined
26
+ */
27
+ defaultValue?: number | undefined;
22
28
  name: string;
23
29
  cookieDocument?: string;
24
30
  }) => ReturnType<number | undefined>;
@@ -4,7 +4,6 @@ exports.useCookieBoolean = exports.useCookieNumber = exports.useCookieString = e
4
4
  const react_1 = require("react");
5
5
  const get_1 = require("./get");
6
6
  const set_1 = require("./set");
7
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
8
7
  function useCookie(p) {
9
8
  const parse = (s) => {
10
9
  if (!s) {
@@ -30,9 +29,9 @@ function useCookie(p) {
30
29
  return [cookie, setState];
31
30
  }
32
31
  exports.useCookie = useCookie;
33
- const useCookieString = (p) => useCookie(Object.assign(Object.assign({}, p), { parse: (s) => s || '', stringify: (s) => s }));
32
+ const useCookieString = (p) => useCookie(Object.assign(Object.assign({}, p), { parse: (s) => s || '', stringify: (s) => s, defaultValue: p.defaultValue || '' }));
34
33
  exports.useCookieString = useCookieString;
35
- const useCookieNumber = (p) => useCookie(Object.assign(Object.assign({}, p), { parse: (s) => (!s ? undefined : Number.parseFloat(s)), stringify: (s) => (!s ? '' : s.toString()) }));
34
+ const useCookieNumber = (p) => useCookie(Object.assign(Object.assign({}, p), { parse: (s) => (!s ? undefined : Number.parseFloat(s)), stringify: (s) => (!s ? '' : s.toString()), defaultValue: p.defaultValue }));
36
35
  exports.useCookieNumber = useCookieNumber;
37
36
  const useCookieBoolean = (p) => useCookie(Object.assign(Object.assign({}, p), { parse: (s) => s === 'true', stringify: (s) => s.toString() }));
38
37
  exports.useCookieBoolean = useCookieBoolean;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.debounce = exports.useDebounce = void 0;
4
- /* eslint-disable @typescript-eslint/no-explicit-any */
5
4
  const react_1 = require("react");
6
5
  function useDebounce(value, delay) {
7
6
  const [debouncedValue, setDebouncedValue] = (0, react_1.useState)(value);
@@ -50,7 +50,7 @@ export interface User {
50
50
  jwt?: Jwt;
51
51
  }
52
52
  export interface AxiosWrapper<T> {
53
- data: T;
53
+ data: T | undefined;
54
54
  error?: AxiosError<unknown, any>;
55
55
  loading: boolean;
56
56
  reFetch: () => Promise<any>;
@@ -58,7 +58,7 @@ export interface AxiosWrapper<T> {
58
58
  datetime: number;
59
59
  }
60
60
  export interface AxiosWrapperLite<T> {
61
- data: T;
61
+ data: T | undefined;
62
62
  error?: AxiosError;
63
63
  }
64
64
  export interface AuthedUserContext {
@@ -2,11 +2,38 @@ import { TLang } from '../../common/helpers/i18n';
2
2
  import { ICognitoAuth } from './cognito';
3
3
  import { AxiosWrapperLite } from './jwt';
4
4
  export interface LocationSubset {
5
+ /**
6
+ * slash only path eg /aaa/bbb
7
+ */
5
8
  pathname: string;
9
+ /**
10
+ * eg #aaa
11
+ */
6
12
  hash: string;
13
+ /**
14
+ * up to first slash eg http://aaa.com:1111
15
+ */
7
16
  origin: string;
17
+ /**
18
+ * parse querystring keyvalues
19
+ */
8
20
  query: Record<string, string>;
21
+ /**
22
+ * protocol less up to first slash eg aaa.com:1111
23
+ */
9
24
  host: string;
25
+ /**
26
+ * eg http: or https:
27
+ */
28
+ protocol: string;
29
+ /**
30
+ * full url
31
+ */
32
+ href: string;
33
+ /**
34
+ * url from first slash eg /aaa/bbb?q=a#111
35
+ */
36
+ path: string;
10
37
  }
11
38
  export declare type CacheItems = CacheItem<any>[];
12
39
  export interface CacheItem<T> {
@@ -29,5 +29,8 @@ export declare const useQueryStringArray: ({ name, queryValues, defaultValue, }:
29
29
  export declare const useQueryStringSingle: ({ name, queryValues, defaultValue, }: {
30
30
  name: string;
31
31
  queryValues?: Record<string, string> | undefined;
32
- defaultValue: string | undefined;
32
+ /**
33
+ * default value. default undefined
34
+ */
35
+ defaultValue?: string | undefined;
33
36
  }) => [string | undefined, (v: string | undefined) => void];
@@ -13,8 +13,7 @@ const useQueryStringRaw = ({ name, queryValues, defaultValue, stringify, parse,
13
13
  // eslint-disable-next-line react-hooks/exhaustive-deps
14
14
  const qv = exports.isServer
15
15
  ? queryValues || {}
16
- : // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
- (0, object_1.paramsToObject)(new URLSearchParams(window.location.search));
16
+ : (0, object_1.paramsToObject)(new URLSearchParams(window.location.search));
18
17
  const qsv = parse(qv[name]) || defaultValue;
19
18
  const [state, setStateRaw] = (0, react_1.useState)(qsv);
20
19
  //
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ag-common",
3
- "version": "0.0.136",
3
+ "version": "0.0.141",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Andrei Gec <@andreigec> (https://gec.dev/)",