ag-common 0.0.133 → 0.0.138
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.
- package/dist/api/helpers/openApiHelpers.d.ts +1 -1
- package/dist/common/helpers/log.d.ts +6 -6
- package/dist/common/helpers/log.js +1 -2
- package/dist/common/helpers/object.d.ts +1 -1
- package/dist/common/helpers/random.d.ts +1 -1
- package/dist/common/helpers/random.js +0 -1
- package/dist/common/helpers/string.d.ts +1 -1
- package/dist/common/helpers/string.js +0 -1
- package/dist/ui/components/Sidebar/index.js +2 -2
- package/dist/ui/components/UserImage/index.js +6 -7
- package/dist/ui/helpers/axiosHelper.js +0 -1
- package/dist/ui/helpers/callOpenApi/cached.d.ts +1 -1
- package/dist/ui/helpers/callOpenApi/cached.js +1 -3
- package/dist/ui/helpers/callOpenApi/direct.js +1 -2
- package/dist/ui/helpers/cookie/const.d.ts +6 -0
- package/dist/ui/helpers/cookie/const.js +5 -0
- package/dist/ui/helpers/cookie/get.d.ts +28 -0
- package/dist/ui/helpers/cookie/get.js +63 -0
- package/dist/ui/helpers/cookie/index.d.ts +4 -0
- package/dist/ui/helpers/cookie/index.js +16 -0
- package/dist/ui/helpers/cookie/set.d.ts +20 -0
- package/dist/ui/helpers/cookie/set.js +68 -0
- package/dist/ui/helpers/cookie/use.d.ts +35 -0
- package/dist/ui/helpers/cookie/use.js +37 -0
- package/dist/ui/helpers/debounce.js +0 -1
- package/dist/ui/helpers/jwt.d.ts +2 -2
- package/dist/ui/helpers/useQueryString.d.ts +4 -1
- package/dist/ui/helpers/useQueryString.js +1 -2
- package/package.json +5 -5
- package/dist/ui/helpers/cookie.d.ts +0 -62
- package/dist/ui/helpers/cookie.js +0 -155
|
@@ -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:
|
|
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:
|
|
5
|
-
export declare const info: (...args:
|
|
6
|
-
export declare const warn: (...args:
|
|
7
|
-
export declare const trace: (...args:
|
|
8
|
-
export declare const error: (...args:
|
|
9
|
-
export declare const fatal: (...args:
|
|
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:
|
|
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:
|
|
1
|
+
export declare function shuffle(array: unknown[], seed: number): unknown[];
|
|
@@ -32,5 +32,5 @@ export declare function containsInsensitive(str: string, ...args: string[]): boo
|
|
|
32
32
|
* @param indent
|
|
33
33
|
* @returns
|
|
34
34
|
*/
|
|
35
|
-
export declare const safeStringify: (obj:
|
|
35
|
+
export declare const safeStringify: (obj: unknown, indent?: number) => string;
|
|
36
36
|
export declare const chunkString: (str: string, length: number) => string[];
|
|
@@ -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 = [];
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.Sidebar = void 0;
|
|
7
7
|
const react_1 = __importDefault(require("react"));
|
|
8
8
|
const styled_components_1 = __importDefault(require("styled-components"));
|
|
9
|
-
const
|
|
9
|
+
const use_1 = require("../../helpers/cookie/use");
|
|
10
10
|
const common_1 = require("../../styles/common");
|
|
11
11
|
const Chevron_1 = require("../Chevron");
|
|
12
12
|
const Base = styled_components_1.default.div `
|
|
@@ -92,7 +92,7 @@ const ChevronStyled = (0, styled_components_1.default)(Chevron_1.Chevron) `
|
|
|
92
92
|
}
|
|
93
93
|
`;
|
|
94
94
|
const Sidebar = ({ children, className, key = 'sidebar', cookieDocument, }) => {
|
|
95
|
-
const [open, setOpen] = (0,
|
|
95
|
+
const [open, setOpen] = (0, use_1.useCookieBoolean)({
|
|
96
96
|
name: key,
|
|
97
97
|
defaultValue: false,
|
|
98
98
|
cookieDocument: cookieDocument,
|
|
@@ -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
|
|
57
|
-
|
|
58
|
-
if (
|
|
59
|
-
if (!images.domains.find((i) =>
|
|
60
|
-
|
|
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 = [(
|
|
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>>;
|
|
@@ -20,10 +20,9 @@ const string_1 = require("../../../common/helpers/string");
|
|
|
20
20
|
let callOpenApiCache;
|
|
21
21
|
function getCacheKey({ cacheKey, overrideAuth, }) {
|
|
22
22
|
const authkeyPrefix = (overrideAuth === null || overrideAuth === void 0 ? void 0 : overrideAuth.id_token) ||
|
|
23
|
-
(0, cookie_1.
|
|
23
|
+
(0, cookie_1.getCookieString)({
|
|
24
24
|
name: 'id_token',
|
|
25
25
|
defaultValue: '',
|
|
26
|
-
parse: (s) => s,
|
|
27
26
|
});
|
|
28
27
|
let cacheKeyRet;
|
|
29
28
|
if (cacheKey) {
|
|
@@ -67,7 +66,6 @@ const callOpenApiCached = (p) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
67
66
|
}
|
|
68
67
|
const resp = yield (0, direct_1.callOpenApi)(p);
|
|
69
68
|
if (resp.error) {
|
|
70
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
71
69
|
return { error: resp.error, data: undefined };
|
|
72
70
|
}
|
|
73
71
|
const userPrefixedCacheKey = getCacheKey(p);
|
|
@@ -26,10 +26,9 @@ const callOpenApi = ({ func, apiUrl, overrideAuth, refreshToken, logout, newDefa
|
|
|
26
26
|
config.baseOptions.headers.authorization = `Bearer ${overrideAuth === null || overrideAuth === void 0 ? void 0 : overrideAuth.id_token}`;
|
|
27
27
|
}
|
|
28
28
|
else {
|
|
29
|
-
const isAuthed = !!(0, cookie_1.
|
|
29
|
+
const isAuthed = !!(0, cookie_1.getCookieString)({
|
|
30
30
|
name: 'id_token',
|
|
31
31
|
defaultValue: '',
|
|
32
|
-
parse: (s) => s,
|
|
33
32
|
});
|
|
34
33
|
if (isAuthed) {
|
|
35
34
|
const updated = yield refreshToken();
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare const expireDate = "Thu, 01 Jan 1970 00:00:00 UTC";
|
|
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;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export declare function getCookieRaw({ name, cookieDocument, }: {
|
|
2
|
+
name: string;
|
|
3
|
+
cookieDocument?: string;
|
|
4
|
+
}): string | undefined;
|
|
5
|
+
/**
|
|
6
|
+
* read chunks. json parse+unb64
|
|
7
|
+
* parse defaults to JSON.parse. must change if want if type is not an object!
|
|
8
|
+
* @param param0
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
export declare function getCookieRawWrapper<T>({ name, cookieDocument, defaultValue, parse: parseRaw, }: {
|
|
12
|
+
defaultValue: T;
|
|
13
|
+
name: string;
|
|
14
|
+
cookieDocument?: string;
|
|
15
|
+
/**
|
|
16
|
+
* required for objects. defaults to JSON.parse
|
|
17
|
+
* parse defaults to JSON.parse. must change if want if type is not an object!
|
|
18
|
+
*/
|
|
19
|
+
parse?: (s: string) => T;
|
|
20
|
+
}): T;
|
|
21
|
+
export declare const getCookieString: (p: {
|
|
22
|
+
/**
|
|
23
|
+
* default value. default ''
|
|
24
|
+
*/
|
|
25
|
+
defaultValue?: string;
|
|
26
|
+
name: string;
|
|
27
|
+
cookieDocument?: string;
|
|
28
|
+
}) => string;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCookieString = exports.getCookieRawWrapper = exports.getCookieRaw = void 0;
|
|
4
|
+
const log_1 = require("../../../common/helpers/log");
|
|
5
|
+
const string_1 = require("../../../common/helpers/string");
|
|
6
|
+
const set_1 = require("./set");
|
|
7
|
+
function getCookieRaw({ name, cookieDocument, }) {
|
|
8
|
+
const nameeq = `${name}=`;
|
|
9
|
+
const ca1 = cookieDocument || (typeof window !== 'undefined' && document.cookie);
|
|
10
|
+
if (!ca1 || !(ca1 === null || ca1 === void 0 ? void 0 : ca1.trim())) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
const ca = ca1.split(';').map((t) => t.trim());
|
|
14
|
+
const c = ca.find((c2) => c2.startsWith(nameeq));
|
|
15
|
+
if (c) {
|
|
16
|
+
const raw = c.substr(nameeq.length, c.length);
|
|
17
|
+
return raw;
|
|
18
|
+
}
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
exports.getCookieRaw = getCookieRaw;
|
|
22
|
+
/**
|
|
23
|
+
* read chunks. json parse+unb64
|
|
24
|
+
* parse defaults to JSON.parse. must change if want if type is not an object!
|
|
25
|
+
* @param param0
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
function getCookieRawWrapper({ name, cookieDocument, defaultValue, parse: parseRaw, }) {
|
|
29
|
+
const parse = (s) => {
|
|
30
|
+
if (!s) {
|
|
31
|
+
return defaultValue;
|
|
32
|
+
}
|
|
33
|
+
if (parseRaw) {
|
|
34
|
+
return parseRaw(s);
|
|
35
|
+
}
|
|
36
|
+
return JSON.parse(s);
|
|
37
|
+
};
|
|
38
|
+
let raw = '';
|
|
39
|
+
let currentCount = 0;
|
|
40
|
+
// eslint-disable-next-line no-constant-condition
|
|
41
|
+
while (true) {
|
|
42
|
+
const newv = getCookieRaw({
|
|
43
|
+
name: name + currentCount,
|
|
44
|
+
cookieDocument,
|
|
45
|
+
});
|
|
46
|
+
if (!newv) {
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
raw += newv;
|
|
50
|
+
currentCount += 1;
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
return parse((0, string_1.fromBase64)(raw));
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
(0, log_1.warn)('cookie error:', e);
|
|
57
|
+
(0, set_1.wipeCookies)(name);
|
|
58
|
+
return defaultValue;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.getCookieRawWrapper = getCookieRawWrapper;
|
|
62
|
+
const getCookieString = (p) => getCookieRawWrapper(Object.assign(Object.assign({}, p), { parse: (s) => s, defaultValue: p.defaultValue || '' }));
|
|
63
|
+
exports.getCookieString = getCookieString;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./const"), exports);
|
|
14
|
+
__exportStar(require("./get"), exports);
|
|
15
|
+
__exportStar(require("./set"), exports);
|
|
16
|
+
__exportStar(require("./use"), exports);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare function wipeCookies(name: string): void;
|
|
2
|
+
/**
|
|
3
|
+
* json+b64 incoming. chunk. write chunks
|
|
4
|
+
* @param p
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
export declare function setCookieRawWrapper<T>(p: {
|
|
8
|
+
value: T;
|
|
9
|
+
name: string;
|
|
10
|
+
cookieDocument?: string;
|
|
11
|
+
/**
|
|
12
|
+
* required for objects. defaults to JSON.stringify
|
|
13
|
+
*/
|
|
14
|
+
stringify?: (s: T) => string;
|
|
15
|
+
}): void;
|
|
16
|
+
export declare const setCookieString: (p: {
|
|
17
|
+
value: string;
|
|
18
|
+
name: string;
|
|
19
|
+
cookieDocument?: string;
|
|
20
|
+
}) => void;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setCookieString = exports.setCookieRawWrapper = exports.wipeCookies = void 0;
|
|
4
|
+
const log_1 = require("../../../common/helpers/log");
|
|
5
|
+
const string_1 = require("../../../common/helpers/string");
|
|
6
|
+
const const_1 = require("./const");
|
|
7
|
+
const get_1 = require("./get");
|
|
8
|
+
/**
|
|
9
|
+
* expiryDays <0 will delete
|
|
10
|
+
* @param param0
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
function setCookieRaw({ name, value, expiryDays = 1, }) {
|
|
14
|
+
if (typeof window === undefined) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const d = new Date();
|
|
18
|
+
d.setTime(d.getTime() + expiryDays * 24 * 60 * 60 * 1000);
|
|
19
|
+
const expires = `expires=${!value || expiryDays < 0 ? const_1.expireDate : d.toUTCString()}`;
|
|
20
|
+
document.cookie = `${name}=${!value ? '' : value};${expires};path=/`;
|
|
21
|
+
}
|
|
22
|
+
function wipeCookies(name) {
|
|
23
|
+
if (typeof window === 'undefined') {
|
|
24
|
+
(0, log_1.warn)('cant wipe cookies on server');
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
let currentCount = 0;
|
|
28
|
+
// eslint-disable-next-line no-constant-condition
|
|
29
|
+
while (true) {
|
|
30
|
+
if ((0, get_1.getCookieRaw)({
|
|
31
|
+
name: name + currentCount,
|
|
32
|
+
cookieDocument: '',
|
|
33
|
+
})) {
|
|
34
|
+
setCookieRaw({ name: name + currentCount, value: '', expiryDays: -1 });
|
|
35
|
+
currentCount += 1;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.wipeCookies = wipeCookies;
|
|
43
|
+
/**
|
|
44
|
+
* json+b64 incoming. chunk. write chunks
|
|
45
|
+
* @param p
|
|
46
|
+
* @returns
|
|
47
|
+
*/
|
|
48
|
+
function setCookieRawWrapper(p) {
|
|
49
|
+
const stringify = (s) => {
|
|
50
|
+
if (p.stringify) {
|
|
51
|
+
return p.stringify(s);
|
|
52
|
+
}
|
|
53
|
+
return JSON.stringify(s);
|
|
54
|
+
};
|
|
55
|
+
wipeCookies(p.name);
|
|
56
|
+
if (!p.value) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const str = (0, string_1.toBase64)(stringify(p.value));
|
|
60
|
+
const chunks = (0, string_1.chunkString)(str, const_1.maxCookieLen);
|
|
61
|
+
for (const index1 in chunks) {
|
|
62
|
+
const chunk = chunks[index1];
|
|
63
|
+
setCookieRaw(Object.assign(Object.assign({}, p), { name: p.name + index1, value: chunk }));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.setCookieRawWrapper = setCookieRawWrapper;
|
|
67
|
+
const setCookieString = (p) => setCookieRawWrapper(Object.assign(Object.assign({}, p), { stringify: (s) => s }));
|
|
68
|
+
exports.setCookieString = setCookieString;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { TParse, ReturnType } from './const';
|
|
2
|
+
export declare function useCookie<T>(p: {
|
|
3
|
+
defaultValue: T;
|
|
4
|
+
name: string;
|
|
5
|
+
cookieDocument?: string;
|
|
6
|
+
/**
|
|
7
|
+
* required for objects. defaults to JSON.parse
|
|
8
|
+
*/
|
|
9
|
+
parse?: TParse<T>;
|
|
10
|
+
/**
|
|
11
|
+
* required for objects. defaults to JSON.stringify
|
|
12
|
+
*/
|
|
13
|
+
stringify?: (v: T) => string;
|
|
14
|
+
}): ReturnType<T>;
|
|
15
|
+
export declare const useCookieString: (p: {
|
|
16
|
+
/**
|
|
17
|
+
* default value. default ""
|
|
18
|
+
*/
|
|
19
|
+
defaultValue?: string;
|
|
20
|
+
name: string;
|
|
21
|
+
cookieDocument?: string;
|
|
22
|
+
}) => ReturnType<string>;
|
|
23
|
+
export declare const useCookieNumber: (p: {
|
|
24
|
+
/**
|
|
25
|
+
* default value. default undefined
|
|
26
|
+
*/
|
|
27
|
+
defaultValue?: number | undefined;
|
|
28
|
+
name: string;
|
|
29
|
+
cookieDocument?: string;
|
|
30
|
+
}) => ReturnType<number | undefined>;
|
|
31
|
+
export declare const useCookieBoolean: (p: {
|
|
32
|
+
defaultValue: boolean;
|
|
33
|
+
name: string;
|
|
34
|
+
cookieDocument?: string;
|
|
35
|
+
}) => ReturnType<boolean>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useCookieBoolean = exports.useCookieNumber = exports.useCookieString = exports.useCookie = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const get_1 = require("./get");
|
|
6
|
+
const set_1 = require("./set");
|
|
7
|
+
function useCookie(p) {
|
|
8
|
+
const parse = (s) => {
|
|
9
|
+
if (!s) {
|
|
10
|
+
return p.defaultValue;
|
|
11
|
+
}
|
|
12
|
+
if (p.parse) {
|
|
13
|
+
return p.parse(s);
|
|
14
|
+
}
|
|
15
|
+
return JSON.parse(s);
|
|
16
|
+
};
|
|
17
|
+
const stringify = (s) => {
|
|
18
|
+
if (p.stringify) {
|
|
19
|
+
return p.stringify(s);
|
|
20
|
+
}
|
|
21
|
+
return JSON.stringify(s);
|
|
22
|
+
};
|
|
23
|
+
const [cookie, setCookie] = (0, react_1.useState)((0, get_1.getCookieRawWrapper)(Object.assign(Object.assign({}, p), { parse })) || p.defaultValue);
|
|
24
|
+
const setState = (valueRaw) => {
|
|
25
|
+
const value = (valueRaw instanceof Function ? valueRaw(cookie) : valueRaw);
|
|
26
|
+
(0, set_1.setCookieRawWrapper)(Object.assign(Object.assign({}, p), { stringify, value }));
|
|
27
|
+
setCookie(value);
|
|
28
|
+
};
|
|
29
|
+
return [cookie, setState];
|
|
30
|
+
}
|
|
31
|
+
exports.useCookie = useCookie;
|
|
32
|
+
const useCookieString = (p) => useCookie(Object.assign(Object.assign({}, p), { parse: (s) => s || '', stringify: (s) => s, defaultValue: p.defaultValue || '' }));
|
|
33
|
+
exports.useCookieString = useCookieString;
|
|
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 }));
|
|
35
|
+
exports.useCookieNumber = useCookieNumber;
|
|
36
|
+
const useCookieBoolean = (p) => useCookie(Object.assign(Object.assign({}, p), { parse: (s) => s === 'true', stringify: (s) => s.toString() }));
|
|
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);
|
package/dist/ui/helpers/jwt.d.ts
CHANGED
|
@@ -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 {
|
|
@@ -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
|
-
|
|
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
|
-
:
|
|
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.
|
|
3
|
+
"version": "0.0.138",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"author": "Andrei Gec <@andreigec> (https://gec.dev/)",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"aws-cdk-lib": "2.x",
|
|
17
|
-
"aws-sdk": "2.
|
|
17
|
+
"aws-sdk": "2.1072.0",
|
|
18
18
|
"axios": "0.25.0",
|
|
19
19
|
"constructs": "10.x",
|
|
20
20
|
"jsonwebtoken": "8.5.1",
|
|
@@ -29,12 +29,12 @@
|
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/jsonwebtoken": "8.5.8",
|
|
32
|
-
"@types/node": "17.0.
|
|
32
|
+
"@types/node": "17.0.17",
|
|
33
33
|
"@types/react": "17.0.39",
|
|
34
34
|
"@types/react-dom": "17.0.11",
|
|
35
35
|
"@types/styled-components": "5.1.22",
|
|
36
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
37
|
-
"@typescript-eslint/parser": "5.
|
|
36
|
+
"@typescript-eslint/eslint-plugin": "5.11.0",
|
|
37
|
+
"@typescript-eslint/parser": "5.11.0",
|
|
38
38
|
"eslint": "8.8.0",
|
|
39
39
|
"eslint-config-airbnb-typescript": "16.1.0",
|
|
40
40
|
"eslint-config-prettier": "8.3.0",
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
export declare function wipeCookies(name: string): void;
|
|
2
|
-
/**
|
|
3
|
-
* json+b64 incoming. chunk. write chunks
|
|
4
|
-
* @param p
|
|
5
|
-
* @returns
|
|
6
|
-
*/
|
|
7
|
-
export declare function setCookieWrapper<T>(p: {
|
|
8
|
-
value: T;
|
|
9
|
-
name: string;
|
|
10
|
-
cookieDocument?: string;
|
|
11
|
-
/**
|
|
12
|
-
* required for objects. defaults to JSON.stringify
|
|
13
|
-
*/
|
|
14
|
-
stringify?: (s: T) => string;
|
|
15
|
-
}): void;
|
|
16
|
-
/**
|
|
17
|
-
* read chunks. json parse+unb64
|
|
18
|
-
* @param param0
|
|
19
|
-
* @returns
|
|
20
|
-
*/
|
|
21
|
-
export declare function getCookieWrapper<T>({ name, cookieDocument, defaultValue, parse: parseRaw, }: {
|
|
22
|
-
defaultValue: T;
|
|
23
|
-
name: string;
|
|
24
|
-
cookieDocument?: string;
|
|
25
|
-
/**
|
|
26
|
-
* required for objects. defaults to JSON.parse
|
|
27
|
-
*/
|
|
28
|
-
parse?: (s: string) => T;
|
|
29
|
-
}): T;
|
|
30
|
-
declare type Dispatch<A> = (value: A) => void;
|
|
31
|
-
declare type SetStateAction<S> = S | ((prevState: S) => S);
|
|
32
|
-
declare type ReturnType<T> = [T, Dispatch<SetStateAction<T>>];
|
|
33
|
-
declare type TParse<T> = (s: string | null | undefined) => T;
|
|
34
|
-
export declare function useCookie<T>(p: {
|
|
35
|
-
defaultValue: T;
|
|
36
|
-
name: string;
|
|
37
|
-
cookieDocument?: string;
|
|
38
|
-
/**
|
|
39
|
-
* required for objects. defaults to JSON.parse
|
|
40
|
-
*/
|
|
41
|
-
parse?: TParse<T>;
|
|
42
|
-
/**
|
|
43
|
-
* required for objects. defaults to JSON.stringify
|
|
44
|
-
*/
|
|
45
|
-
stringify?: (v: T) => string;
|
|
46
|
-
}): ReturnType<T>;
|
|
47
|
-
export declare const useCookieString: (p: {
|
|
48
|
-
defaultValue: string;
|
|
49
|
-
name: string;
|
|
50
|
-
cookieDocument?: string;
|
|
51
|
-
}) => ReturnType<string>;
|
|
52
|
-
export declare const useCookieNumber: (p: {
|
|
53
|
-
defaultValue: number | undefined;
|
|
54
|
-
name: string;
|
|
55
|
-
cookieDocument?: string;
|
|
56
|
-
}) => ReturnType<number | undefined>;
|
|
57
|
-
export declare const useCookieBoolean: (p: {
|
|
58
|
-
defaultValue: boolean;
|
|
59
|
-
name: string;
|
|
60
|
-
cookieDocument?: string;
|
|
61
|
-
}) => ReturnType<boolean>;
|
|
62
|
-
export {};
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.useCookieBoolean = exports.useCookieNumber = exports.useCookieString = exports.useCookie = exports.getCookieWrapper = exports.setCookieWrapper = exports.wipeCookies = void 0;
|
|
4
|
-
/* eslint-disable guard-for-in */
|
|
5
|
-
/* eslint-disable no-restricted-syntax */
|
|
6
|
-
const react_1 = require("react");
|
|
7
|
-
const log_1 = require("../../common/helpers/log");
|
|
8
|
-
const string_1 = require("../../common/helpers/string");
|
|
9
|
-
const expireDate = 'Thu, 01 Jan 1970 00:00:00 UTC';
|
|
10
|
-
const maxCookieLen = 4000;
|
|
11
|
-
/**
|
|
12
|
-
* expiryDays <0 will delete
|
|
13
|
-
* @param param0
|
|
14
|
-
* @returns
|
|
15
|
-
*/
|
|
16
|
-
function setCookieRaw({ name, value, expiryDays = 1, }) {
|
|
17
|
-
if (typeof window === undefined) {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
const d = new Date();
|
|
21
|
-
d.setTime(d.getTime() + expiryDays * 24 * 60 * 60 * 1000);
|
|
22
|
-
const expires = `expires=${!value || expiryDays < 0 ? expireDate : d.toUTCString()}`;
|
|
23
|
-
document.cookie = `${name}=${!value ? '' : value};${expires};path=/`;
|
|
24
|
-
}
|
|
25
|
-
function getCookieRaw({ name, cookieDocument, }) {
|
|
26
|
-
const nameeq = `${name}=`;
|
|
27
|
-
const ca1 = cookieDocument || (typeof window !== 'undefined' && document.cookie);
|
|
28
|
-
if (!ca1 || !(ca1 === null || ca1 === void 0 ? void 0 : ca1.trim())) {
|
|
29
|
-
return undefined;
|
|
30
|
-
}
|
|
31
|
-
const ca = ca1.split(';').map((t) => t.trim());
|
|
32
|
-
for (const c of ca) {
|
|
33
|
-
if (c.indexOf(nameeq) === 0) {
|
|
34
|
-
const raw = c.substr(nameeq.length, c.length);
|
|
35
|
-
return raw;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return undefined;
|
|
39
|
-
}
|
|
40
|
-
function wipeCookies(name) {
|
|
41
|
-
if (typeof window === 'undefined') {
|
|
42
|
-
(0, log_1.warn)('cant wipe cookies on server');
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
let currentCount = 0;
|
|
46
|
-
// eslint-disable-next-line no-constant-condition
|
|
47
|
-
while (true) {
|
|
48
|
-
if (getCookieRaw({
|
|
49
|
-
name: name + currentCount,
|
|
50
|
-
cookieDocument: '',
|
|
51
|
-
})) {
|
|
52
|
-
setCookieRaw({ name: name + currentCount, value: '', expiryDays: -1 });
|
|
53
|
-
currentCount += 1;
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
exports.wipeCookies = wipeCookies;
|
|
61
|
-
/**
|
|
62
|
-
* json+b64 incoming. chunk. write chunks
|
|
63
|
-
* @param p
|
|
64
|
-
* @returns
|
|
65
|
-
*/
|
|
66
|
-
function setCookieWrapper(p) {
|
|
67
|
-
const stringify = (s) => {
|
|
68
|
-
if (p.stringify) {
|
|
69
|
-
return p.stringify(s);
|
|
70
|
-
}
|
|
71
|
-
return JSON.stringify(s);
|
|
72
|
-
};
|
|
73
|
-
wipeCookies(p.name);
|
|
74
|
-
if (!p.value) {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
const str = (0, string_1.toBase64)(stringify(p.value));
|
|
78
|
-
const chunks = (0, string_1.chunkString)(str, maxCookieLen);
|
|
79
|
-
for (const index1 in chunks) {
|
|
80
|
-
const chunk = chunks[index1];
|
|
81
|
-
setCookieRaw(Object.assign(Object.assign({}, p), { name: p.name + index1, value: chunk }));
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
exports.setCookieWrapper = setCookieWrapper;
|
|
85
|
-
/**
|
|
86
|
-
* read chunks. json parse+unb64
|
|
87
|
-
* @param param0
|
|
88
|
-
* @returns
|
|
89
|
-
*/
|
|
90
|
-
function getCookieWrapper({ name, cookieDocument, defaultValue, parse: parseRaw, }) {
|
|
91
|
-
const parse = (s) => {
|
|
92
|
-
if (!s) {
|
|
93
|
-
return defaultValue;
|
|
94
|
-
}
|
|
95
|
-
if (parseRaw) {
|
|
96
|
-
return parseRaw(s);
|
|
97
|
-
}
|
|
98
|
-
return JSON.parse(s);
|
|
99
|
-
};
|
|
100
|
-
let raw = '';
|
|
101
|
-
let currentCount = 0;
|
|
102
|
-
// eslint-disable-next-line no-constant-condition
|
|
103
|
-
while (true) {
|
|
104
|
-
const newv = getCookieRaw({
|
|
105
|
-
name: name + currentCount,
|
|
106
|
-
cookieDocument,
|
|
107
|
-
});
|
|
108
|
-
if (!newv) {
|
|
109
|
-
break;
|
|
110
|
-
}
|
|
111
|
-
raw += newv;
|
|
112
|
-
currentCount += 1;
|
|
113
|
-
}
|
|
114
|
-
try {
|
|
115
|
-
return parse((0, string_1.fromBase64)(raw));
|
|
116
|
-
}
|
|
117
|
-
catch (e) {
|
|
118
|
-
(0, log_1.warn)('cookie error:', e);
|
|
119
|
-
wipeCookies(name);
|
|
120
|
-
return defaultValue;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
exports.getCookieWrapper = getCookieWrapper;
|
|
124
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
125
|
-
function useCookie(p) {
|
|
126
|
-
const parse = (s) => {
|
|
127
|
-
if (!s) {
|
|
128
|
-
return p.defaultValue;
|
|
129
|
-
}
|
|
130
|
-
if (p.parse) {
|
|
131
|
-
return p.parse(s);
|
|
132
|
-
}
|
|
133
|
-
return JSON.parse(s);
|
|
134
|
-
};
|
|
135
|
-
const stringify = (s) => {
|
|
136
|
-
if (p.stringify) {
|
|
137
|
-
return p.stringify(s);
|
|
138
|
-
}
|
|
139
|
-
return JSON.stringify(s);
|
|
140
|
-
};
|
|
141
|
-
const [cookie, setCookie] = (0, react_1.useState)(getCookieWrapper(Object.assign(Object.assign({}, p), { parse })) || p.defaultValue);
|
|
142
|
-
const setState = (valueRaw) => {
|
|
143
|
-
const value = (valueRaw instanceof Function ? valueRaw(cookie) : valueRaw);
|
|
144
|
-
setCookieWrapper(Object.assign(Object.assign({}, p), { stringify, value }));
|
|
145
|
-
setCookie(value);
|
|
146
|
-
};
|
|
147
|
-
return [cookie, setState];
|
|
148
|
-
}
|
|
149
|
-
exports.useCookie = useCookie;
|
|
150
|
-
const useCookieString = (p) => useCookie(Object.assign(Object.assign({}, p), { parse: (s) => s || '', stringify: (s) => s }));
|
|
151
|
-
exports.useCookieString = useCookieString;
|
|
152
|
-
const useCookieNumber = (p) => useCookie(Object.assign(Object.assign({}, p), { parse: (s) => (!s ? undefined : Number.parseFloat(s)), stringify: (s) => (!s ? '' : s.toString()) }));
|
|
153
|
-
exports.useCookieNumber = useCookieNumber;
|
|
154
|
-
const useCookieBoolean = (p) => useCookie(Object.assign(Object.assign({}, p), { parse: (s) => s === 'true', stringify: (s) => s.toString() }));
|
|
155
|
-
exports.useCookieBoolean = useCookieBoolean;
|