ag-common 0.0.8 → 0.0.12
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/dynamo.js +12 -6
- package/dist/api/helpers/index.d.ts +1 -0
- package/dist/api/helpers/index.js +1 -0
- package/dist/api/helpers/validateOpenApi.d.ts +1 -1
- package/dist/api/helpers/validations.d.ts +1 -1
- package/dist/api/helpers/validations.js +1 -1
- package/dist/common/helpers/array.d.ts +1 -1
- package/dist/common/helpers/array.js +4 -6
- package/dist/common/helpers/date.d.ts +8 -0
- package/dist/common/helpers/date.js +47 -0
- package/dist/common/helpers/index.d.ts +1 -0
- package/dist/common/helpers/index.js +1 -0
- package/dist/common/helpers/log.d.ts +5 -2
- package/dist/common/helpers/log.js +144 -16
- package/dist/common/helpers/string.d.ts +1 -1
- package/dist/common/helpers/string.js +2 -2
- package/dist/index.js +0 -1
- package/dist/ui/components/BorderGradient/index.d.ts +19 -0
- package/dist/ui/components/BorderGradient/index.js +111 -0
- package/dist/ui/components/Icon/index.d.ts +21 -0
- package/dist/ui/components/Icon/index.js +86 -0
- package/dist/ui/components/UserImage/index.d.ts +1 -1
- package/dist/ui/components/index.d.ts +2 -0
- package/dist/ui/components/index.js +2 -0
- package/dist/ui/helpers/axiosHelper.d.ts +17 -0
- package/dist/ui/helpers/axiosHelper.js +87 -0
- package/dist/ui/helpers/callOpenApi.d.ts +1 -1
- package/dist/ui/helpers/cognito.d.ts +31 -0
- package/dist/ui/helpers/cognito.js +2 -0
- package/dist/ui/helpers/cookie.js +1 -1
- package/dist/ui/helpers/date.d.ts +2 -0
- package/dist/ui/helpers/date.js +33 -0
- package/dist/ui/helpers/index.d.ts +5 -0
- package/dist/ui/helpers/index.js +5 -0
- package/dist/ui/helpers/jwt.d.ts +78 -0
- package/dist/ui/helpers/jwt.js +5 -0
- package/dist/ui/helpers/mutexData.d.ts +5 -1
- package/dist/ui/helpers/mutexData.js +1 -1
- package/dist/ui/helpers/routes.d.ts +12 -11
- package/dist/ui/helpers/useOpenApiStore.d.ts +9 -2
- package/dist/ui/helpers/useOpenApiStore.js +21 -27
- package/package.json +1 -2
|
@@ -28,7 +28,7 @@ const putDynamo = (item, tableName) => __awaiter(void 0, void 0, void 0, functio
|
|
|
28
28
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
29
|
Item: item,
|
|
30
30
|
};
|
|
31
|
-
(0, log_1.info)(`running dynamo put=${JSON.stringify(params)}`);
|
|
31
|
+
(0, log_1.info)(`running dynamo put=${JSON.stringify(params, null, 2)}`);
|
|
32
32
|
// write the todo to the database
|
|
33
33
|
const put = yield exports.dynamoDb.put(params).promise();
|
|
34
34
|
if (put.$response.error &&
|
|
@@ -138,7 +138,7 @@ const getItemDynamo = ({ tableName, pkName, pkValue, }) => __awaiter(void 0, voi
|
|
|
138
138
|
try {
|
|
139
139
|
const res = yield exports.dynamoDb.get(params).promise();
|
|
140
140
|
const ret = res.Item;
|
|
141
|
-
(0, log_1.debug)(`got dynamo getitem=${JSON.stringify(params)}`);
|
|
141
|
+
(0, log_1.debug)(`got dynamo getitem=${JSON.stringify(params, null, 2)}`);
|
|
142
142
|
return ret;
|
|
143
143
|
}
|
|
144
144
|
catch (e) {
|
|
@@ -158,14 +158,20 @@ const getItemsDynamo = ({ tableName, items, }) => __awaiter(void 0, void 0, void
|
|
|
158
158
|
},
|
|
159
159
|
},
|
|
160
160
|
};
|
|
161
|
+
const dbRaw = new aws_sdk_1.default.DynamoDB({ apiVersion: '2012-10-08' });
|
|
161
162
|
try {
|
|
162
|
-
const res = yield
|
|
163
|
-
(0, log_1.debug)(`got dynamo getitems=${JSON.stringify(res)}`);
|
|
164
|
-
let ret = ((_f = (_e = res.Responses) === null || _e === void 0 ? void 0 : _e[tableName]) === null || _f === void 0 ? void 0 : _f.map((s) => s)) || [];
|
|
163
|
+
const res = yield dbRaw.batchGetItem(params).promise();
|
|
164
|
+
(0, log_1.debug)(`got dynamo getitems=${JSON.stringify(res, null, 2)}`);
|
|
165
|
+
let ret = ((_f = (_e = res.Responses) === null || _e === void 0 ? void 0 : _e[tableName]) === null || _f === void 0 ? void 0 : _f.map((s) => aws_sdk_1.default.DynamoDB.Converter.unmarshall(s))) || [];
|
|
165
166
|
return ret;
|
|
166
167
|
}
|
|
167
168
|
catch (e) {
|
|
168
|
-
|
|
169
|
+
let msg = `error with getitems query:` +
|
|
170
|
+
JSON.stringify(params, null, 2) +
|
|
171
|
+
'\n' +
|
|
172
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
173
|
+
e.toString();
|
|
174
|
+
(0, log_1.error)(msg);
|
|
169
175
|
throw e;
|
|
170
176
|
}
|
|
171
177
|
});
|
|
@@ -11,6 +11,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
__exportStar(require("./api"), exports);
|
|
14
|
+
__exportStar(require("./dynamo"), exports);
|
|
14
15
|
__exportStar(require("./dynamoInfra"), exports);
|
|
15
16
|
__exportStar(require("./openApiHelpers"), exports);
|
|
16
17
|
__exportStar(require("./validateOpenApi"), exports);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { APIGatewayEvent, APIGatewayProxyResult } from 'aws-lambda';
|
|
2
|
-
import { User } from '
|
|
2
|
+
import { User } from '../../ui/helpers/jwt';
|
|
3
3
|
export declare type NextType<T> = ({ event, body, params, userProfile, }: {
|
|
4
4
|
params: Record<string, string>;
|
|
5
5
|
event: APIGatewayEvent;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { APIGatewayProxyResult } from 'aws-lambda';
|
|
2
|
-
import { User } from 'analytica.click';
|
|
3
2
|
import { error } from '../../common/helpers/log';
|
|
3
|
+
import { User } from '../../ui/helpers/jwt';
|
|
4
4
|
export declare const getAndValidateToken: ({ tokenRaw, COGNITO_USER_POOL_ID, }: {
|
|
5
5
|
tokenRaw?: string | undefined;
|
|
6
6
|
COGNITO_USER_POOL_ID: string;
|
|
@@ -73,7 +73,7 @@ const getAndValidateToken = ({ tokenRaw, COGNITO_USER_POOL_ID, }) => __awaiter(v
|
|
|
73
73
|
try {
|
|
74
74
|
yield jwtVerify({ token, COGNITO_USER_POOL_ID });
|
|
75
75
|
const decoded = (0, jsonwebtoken_1.decode)(token);
|
|
76
|
-
(0, log_1.debug)(`decoded=${JSON.stringify(decoded)}`);
|
|
76
|
+
(0, log_1.debug)(`decoded=${JSON.stringify(decoded, null, 2)}`);
|
|
77
77
|
subject = decoded === null || decoded === void 0 ? void 0 : decoded.sub;
|
|
78
78
|
if (!subject) {
|
|
79
79
|
const mess = 'user should have responded with subject (sub) field';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const toObject: <T, Indexer extends string | number>(arr: T[], keyF: (a: T) => Indexer) => { [a in Indexer]: T; }
|
|
1
|
+
export declare const toObject: <T, Indexer extends string | number>(arr: T[], keyF: (a: T) => Indexer) => { [a in Indexer]: T; };
|
|
2
2
|
export declare const flat: <T>(arr: T[][]) => T[];
|
|
3
3
|
export declare const take: <T>(array: T[], num: number) => {
|
|
4
4
|
part: T[];
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.notEmpty = exports.partition = exports.chunk = exports.take = exports.flat = exports.toObject = void 0;
|
|
4
4
|
const toObject = (arr, keyF) => {
|
|
5
|
+
const ret = {};
|
|
5
6
|
if (!arr || !keyF) {
|
|
6
|
-
return
|
|
7
|
+
return ret;
|
|
7
8
|
}
|
|
8
|
-
const ret = {};
|
|
9
9
|
arr.forEach((v) => {
|
|
10
10
|
const k = keyF(v);
|
|
11
11
|
ret[k] = v;
|
|
@@ -27,10 +27,8 @@ const chunk = (array, max) => {
|
|
|
27
27
|
let row = [];
|
|
28
28
|
for (const k in array) {
|
|
29
29
|
const item = array[k];
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
30
|
+
row.push(item);
|
|
31
|
+
if (row.length >= max) {
|
|
34
32
|
rows.push(row);
|
|
35
33
|
row = [];
|
|
36
34
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const getTimeSeconds: () => number;
|
|
2
|
+
export declare const addHours: (d: number, h: number) => Date;
|
|
3
|
+
export declare const addDays: (dIn: Date, count: number) => Date;
|
|
4
|
+
export declare const addMinutes: (date: Date, minutes: number) => Date;
|
|
5
|
+
export declare const lastDayInMonth: (date: Date) => Date;
|
|
6
|
+
export declare const dateDiffDays: (date1: Date, date2: Date) => number;
|
|
7
|
+
export declare const CSharpToJs: (charpTicks: number) => Date;
|
|
8
|
+
export declare const dateTimeToNearestMinute: (minutes: number, date?: Date | undefined) => Date;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.dateTimeToNearestMinute = exports.CSharpToJs = exports.dateDiffDays = exports.lastDayInMonth = exports.addMinutes = exports.addDays = exports.addHours = exports.getTimeSeconds = void 0;
|
|
4
|
+
const getTimeSeconds = () => Math.ceil(new Date().getTime() / 1000);
|
|
5
|
+
exports.getTimeSeconds = getTimeSeconds;
|
|
6
|
+
const addHours = (d, h) => {
|
|
7
|
+
return new Date(d + h * 60 * 60 * 1000);
|
|
8
|
+
};
|
|
9
|
+
exports.addHours = addHours;
|
|
10
|
+
const addDays = (dIn, count) => {
|
|
11
|
+
const d = new Date(dIn);
|
|
12
|
+
d.setDate(d.getDate() + count);
|
|
13
|
+
return d;
|
|
14
|
+
};
|
|
15
|
+
exports.addDays = addDays;
|
|
16
|
+
const addMinutes = (date, minutes) => new Date(date.getTime() + minutes * 60000);
|
|
17
|
+
exports.addMinutes = addMinutes;
|
|
18
|
+
const lastDayInMonth = (date) => new Date(date.getFullYear(), date.getMonth() + 1, 0);
|
|
19
|
+
exports.lastDayInMonth = lastDayInMonth;
|
|
20
|
+
const dateDiffDays = (date1, date2) => {
|
|
21
|
+
const dt1 = new Date(date1);
|
|
22
|
+
const dt2 = new Date(date2);
|
|
23
|
+
return Math.floor((Date.UTC(dt2.getFullYear(), dt2.getMonth(), dt2.getDate()) -
|
|
24
|
+
Date.UTC(dt1.getFullYear(), dt1.getMonth(), dt1.getDate())) /
|
|
25
|
+
1000);
|
|
26
|
+
};
|
|
27
|
+
exports.dateDiffDays = dateDiffDays;
|
|
28
|
+
const CSharpToJs = (charpTicks) => {
|
|
29
|
+
// ticks are in nanotime; convert to microtime
|
|
30
|
+
const ticks = charpTicks / 10000;
|
|
31
|
+
// ticks are recorded from 1/1/1; get microtime difference from 1/1/1/ to 1/1/1970
|
|
32
|
+
const epochMicrotimeDiff = Math.abs(new Date(0, 0, 1).setFullYear(1));
|
|
33
|
+
// new date is ticks, converted to microtime, minus difference from epoch microtime
|
|
34
|
+
const tickDate = new Date(ticks - epochMicrotimeDiff);
|
|
35
|
+
return tickDate;
|
|
36
|
+
};
|
|
37
|
+
exports.CSharpToJs = CSharpToJs;
|
|
38
|
+
const dateTimeToNearestMinute = (minutes, date) => {
|
|
39
|
+
const coeff = 1000 * 60 * minutes;
|
|
40
|
+
if (!date) {
|
|
41
|
+
// eslint-disable-next-line no-param-reassign
|
|
42
|
+
date = new Date();
|
|
43
|
+
}
|
|
44
|
+
const rounded = new Date(Math.round(date.getTime() / coeff) * coeff);
|
|
45
|
+
return rounded;
|
|
46
|
+
};
|
|
47
|
+
exports.dateTimeToNearestMinute = dateTimeToNearestMinute;
|
|
@@ -11,6 +11,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
13
|
__exportStar(require("./array"), exports);
|
|
14
|
+
__exportStar(require("./date"), exports);
|
|
14
15
|
__exportStar(require("./distinctBy"), exports);
|
|
15
16
|
__exportStar(require("./email"), exports);
|
|
16
17
|
__exportStar(require("./groupBy"), exports);
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
export declare type TLogType = 'TRACE' | 'DEBUG' | 'INFO' | 'WARN' | 'ERROR' | 'FATAL';
|
|
2
|
+
export declare const GetLogLevel: (l: TLogType) => number;
|
|
3
|
+
export declare const trace: (...args: any[]) => void;
|
|
4
|
+
export declare const debug: (...args: any[]) => void;
|
|
1
5
|
export declare const info: (...args: any[]) => void;
|
|
2
6
|
export declare const warn: (...args: any[]) => void;
|
|
3
7
|
export declare const error: (...args: any[]) => void;
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const trace: (...args: any[]) => void;
|
|
8
|
+
export declare const fatal: (...args: any[]) => void;
|
|
@@ -1,25 +1,153 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.fatal = exports.error = exports.warn = exports.info = exports.debug = exports.trace = exports.GetLogLevel = void 0;
|
|
4
4
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
5
|
+
const _1 = require(".");
|
|
6
|
+
const GetLogLevel = (l) => ['TRACE', 'DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL'].findIndex((s) => s === l);
|
|
7
|
+
exports.GetLogLevel = GetLogLevel;
|
|
5
8
|
/* eslint-disable no-console */
|
|
6
|
-
|
|
7
|
-
|
|
9
|
+
function dateF() {
|
|
10
|
+
const d = new Date();
|
|
11
|
+
const str = `${d.getHours()}:${d.getMinutes()}:${d.getSeconds()}`;
|
|
12
|
+
return str;
|
|
13
|
+
}
|
|
14
|
+
function nicify(...args) {
|
|
15
|
+
const ret = [];
|
|
16
|
+
args.forEach((a) => {
|
|
17
|
+
a.forEach((v) => {
|
|
18
|
+
if (v !== null &&
|
|
19
|
+
typeof v !== 'undefined' &&
|
|
20
|
+
v.toString().indexOf('Error:') !== -1 &&
|
|
21
|
+
v.stack) {
|
|
22
|
+
ret.push(`${v.stack}`);
|
|
23
|
+
}
|
|
24
|
+
else if (typeof v === 'string') {
|
|
25
|
+
if (v.trim() !== 'undefined') {
|
|
26
|
+
ret.push(`${v.trim()}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
else if (typeof v === 'object') {
|
|
30
|
+
ret.push(JSON.parse(JSON.stringify(v)));
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
ret.push(v);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
return ret;
|
|
38
|
+
}
|
|
39
|
+
function logprocess(type, date, args) {
|
|
40
|
+
var _a;
|
|
41
|
+
const ds = date ? `[${date}]` : '';
|
|
42
|
+
const retm = [ds, type, ...args].filter(_1.notEmpty).join('\t');
|
|
43
|
+
const min = (0, exports.GetLogLevel)((_a = process.env.LOG_LEVEL) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || 'WARN';
|
|
44
|
+
const typesLogLevel = (0, exports.GetLogLevel)(type);
|
|
45
|
+
// env ignores it
|
|
46
|
+
if (typesLogLevel < min) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
switch (type) {
|
|
50
|
+
case 'TRACE': {
|
|
51
|
+
console.trace(retm);
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
case 'DEBUG': {
|
|
55
|
+
console.debug(retm);
|
|
56
|
+
break;
|
|
57
|
+
}
|
|
58
|
+
case 'INFO': {
|
|
59
|
+
console.log(retm);
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
case 'WARN': {
|
|
63
|
+
console.warn(retm);
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
case 'ERROR': {
|
|
67
|
+
console.error(retm);
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
case 'FATAL': {
|
|
71
|
+
console.error(retm);
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
default: {
|
|
75
|
+
console.log(retm);
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function printStackTrace(...args) {
|
|
81
|
+
const callstack = [];
|
|
82
|
+
let isCallstackPopulated = false;
|
|
83
|
+
try {
|
|
84
|
+
throw new Error('Test');
|
|
85
|
+
}
|
|
86
|
+
catch (e) {
|
|
87
|
+
const er = e;
|
|
88
|
+
if (er.stack) {
|
|
89
|
+
// Firefox / chrome
|
|
90
|
+
const lines = er.stack.split('\n');
|
|
91
|
+
for (let i = 0, len = lines.length; i < len; i += 1) {
|
|
92
|
+
callstack.push(` ${lines[i]} `);
|
|
93
|
+
}
|
|
94
|
+
// Remove call to logStackTrace()
|
|
95
|
+
callstack.shift();
|
|
96
|
+
isCallstackPopulated = true;
|
|
97
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
98
|
+
// @ts-ignore
|
|
99
|
+
}
|
|
100
|
+
else if (window.opera && er.message) {
|
|
101
|
+
// Opera
|
|
102
|
+
const lines = er.message.split('\n');
|
|
103
|
+
for (let i = 0, len = lines.length; i < len; i += 1) {
|
|
104
|
+
if (lines[i].match(/^\s*[A-Za-z0-9\-_$]+\(/)) {
|
|
105
|
+
let entry = lines[i];
|
|
106
|
+
// Append next line also since it has the file info
|
|
107
|
+
if (lines[i + 1]) {
|
|
108
|
+
entry += ` at ${lines[i + 1]}`;
|
|
109
|
+
i += 1;
|
|
110
|
+
}
|
|
111
|
+
callstack.push(entry);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// Remove call to logStackTrace()
|
|
115
|
+
callstack.shift();
|
|
116
|
+
isCallstackPopulated = true;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (!isCallstackPopulated) {
|
|
120
|
+
// IE and Safari
|
|
121
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
122
|
+
// @ts-ignore
|
|
123
|
+
let currentFunction = args.callee.caller;
|
|
124
|
+
while (currentFunction) {
|
|
125
|
+
const fn = currentFunction.toString();
|
|
126
|
+
const fname = fn.substring(fn.indexOf('function') + 8, fn.indexOf('(')) ||
|
|
127
|
+
'anonymous';
|
|
128
|
+
callstack.push(fname);
|
|
129
|
+
currentFunction = currentFunction.caller;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return callstack.join('\n');
|
|
133
|
+
}
|
|
134
|
+
const trace = (...args) => {
|
|
135
|
+
const argsNice = nicify(args);
|
|
136
|
+
args.push(printStackTrace());
|
|
137
|
+
logprocess('TRACE', dateF(), argsNice);
|
|
8
138
|
};
|
|
139
|
+
exports.trace = trace;
|
|
140
|
+
const debug = (...args) => logprocess('DEBUG', dateF(), nicify(args));
|
|
141
|
+
exports.debug = debug;
|
|
142
|
+
const info = (...args) => logprocess('INFO', dateF(), nicify(args));
|
|
9
143
|
exports.info = info;
|
|
10
|
-
const warn = (...args) =>
|
|
11
|
-
console.warn(...args);
|
|
12
|
-
};
|
|
144
|
+
const warn = (...args) => logprocess('WARN', dateF(), nicify(args));
|
|
13
145
|
exports.warn = warn;
|
|
14
|
-
const error = (...args) =>
|
|
15
|
-
console.error(...args);
|
|
16
|
-
};
|
|
146
|
+
const error = (...args) => logprocess('ERROR', dateF(), nicify(args));
|
|
17
147
|
exports.error = error;
|
|
18
|
-
const
|
|
19
|
-
|
|
148
|
+
const fatal = (...args) => {
|
|
149
|
+
const argsNice = nicify(args);
|
|
150
|
+
args.push(printStackTrace());
|
|
151
|
+
logprocess('FATAL', dateF(), argsNice);
|
|
20
152
|
};
|
|
21
|
-
exports.
|
|
22
|
-
const trace = (...args) => {
|
|
23
|
-
console.trace(...args);
|
|
24
|
-
};
|
|
25
|
-
exports.trace = trace;
|
|
153
|
+
exports.fatal = fatal;
|
|
@@ -9,7 +9,7 @@ export interface ISite {
|
|
|
9
9
|
/**
|
|
10
10
|
* removes protocol, and trailing slashes
|
|
11
11
|
*/
|
|
12
|
-
export declare const niceUrl: (siteUrl: string) =>
|
|
12
|
+
export declare const niceUrl: (siteUrl: string) => ISite | undefined;
|
|
13
13
|
/**
|
|
14
14
|
* string -> String
|
|
15
15
|
* @param str
|
|
@@ -44,7 +44,7 @@ function truncate(str, n, ellip) {
|
|
|
44
44
|
if (!str) {
|
|
45
45
|
return undefined;
|
|
46
46
|
}
|
|
47
|
-
return str.length > n ? str.
|
|
47
|
+
return str.length > n ? str.substr(0, n - 1) + ellip : str;
|
|
48
48
|
}
|
|
49
49
|
exports.truncate = truncate;
|
|
50
50
|
/**
|
|
@@ -52,7 +52,7 @@ exports.truncate = truncate;
|
|
|
52
52
|
*/
|
|
53
53
|
const niceUrl = (siteUrl) => {
|
|
54
54
|
if (!siteUrl) {
|
|
55
|
-
return
|
|
55
|
+
return undefined;
|
|
56
56
|
}
|
|
57
57
|
let niceSiteUrl = siteUrl
|
|
58
58
|
.substring(siteUrl.indexOf(':') + 1)
|
package/dist/index.js
CHANGED
|
@@ -10,7 +10,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
/* eslint-disable prettier/prettier */
|
|
14
13
|
__exportStar(require("./ui"), exports);
|
|
15
14
|
__exportStar(require("./common"), exports);
|
|
16
15
|
__exportStar(require("./api"), exports);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
declare type IOnClick = React.MouseEvent<HTMLDivElement, MouseEvent> | React.MouseEvent<HTMLAnchorElement, MouseEvent>;
|
|
3
|
+
export declare const BorderGradient: ({ left, right, children, radius, fill, padding, className, onClick, href, target, rel, noGrow, disabled, canClick, }: {
|
|
4
|
+
canClick?: boolean | undefined;
|
|
5
|
+
noGrow?: boolean | undefined;
|
|
6
|
+
className?: string | undefined;
|
|
7
|
+
fill?: boolean | undefined;
|
|
8
|
+
radius?: string | undefined;
|
|
9
|
+
left?: string | undefined;
|
|
10
|
+
right?: string | undefined;
|
|
11
|
+
children: JSX.Element | (JSX.Element | string | number | undefined)[];
|
|
12
|
+
padding?: string | undefined;
|
|
13
|
+
onClick?: ((e: IOnClick) => void) | undefined;
|
|
14
|
+
href?: string | undefined;
|
|
15
|
+
target?: string | undefined;
|
|
16
|
+
rel?: string | undefined;
|
|
17
|
+
disabled?: boolean | undefined;
|
|
18
|
+
}) => JSX.Element;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,111 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.BorderGradient = void 0;
|
|
26
|
+
const styled_components_1 = __importStar(require("styled-components"));
|
|
27
|
+
const react_1 = __importDefault(require("react"));
|
|
28
|
+
const colours_1 = require("../../styles/colours");
|
|
29
|
+
const BGcss = (0, styled_components_1.css) `
|
|
30
|
+
display: flex;
|
|
31
|
+
border: 0;
|
|
32
|
+
padding: 3px;
|
|
33
|
+
border-radius: ${({ radius }) => radius};
|
|
34
|
+
background-image: linear-gradient(white, white),
|
|
35
|
+
linear-gradient(
|
|
36
|
+
to bottom right,
|
|
37
|
+
${({ left }) => left},
|
|
38
|
+
${({ right }) => right}
|
|
39
|
+
);
|
|
40
|
+
background-origin: border-box;
|
|
41
|
+
background-clip: content-box, border-box;
|
|
42
|
+
overflow: hidden;
|
|
43
|
+
${({ noGrow }) => !noGrow &&
|
|
44
|
+
(0, styled_components_1.css) `
|
|
45
|
+
flex-grow: 1;
|
|
46
|
+
`}
|
|
47
|
+
${({ disabled }) => disabled &&
|
|
48
|
+
(0, styled_components_1.css) `
|
|
49
|
+
filter: grayscale(1);
|
|
50
|
+
`}
|
|
51
|
+
|
|
52
|
+
${({ canClick, disabled }) => (0, styled_components_1.css) `
|
|
53
|
+
cursor: ${canClick && !disabled ? 'pointer' : 'default'};
|
|
54
|
+
`}
|
|
55
|
+
|
|
56
|
+
${({ canClick, disabled }) => canClick &&
|
|
57
|
+
!disabled &&
|
|
58
|
+
(0, styled_components_1.css) `
|
|
59
|
+
&:hover {
|
|
60
|
+
filter: saturate(3);
|
|
61
|
+
}
|
|
62
|
+
`}
|
|
63
|
+
`;
|
|
64
|
+
const BGLink = styled_components_1.default.div `
|
|
65
|
+
${BGcss};
|
|
66
|
+
`;
|
|
67
|
+
const BGALink = styled_components_1.default.a `
|
|
68
|
+
${BGcss};
|
|
69
|
+
`;
|
|
70
|
+
const Padding = styled_components_1.default.div `
|
|
71
|
+
justify-content: center;
|
|
72
|
+
align-items: center;
|
|
73
|
+
display: flex;
|
|
74
|
+
flex-flow: column;
|
|
75
|
+
padding: ${({ padding }) => padding};
|
|
76
|
+
border: 0;
|
|
77
|
+
flex-grow: 1;
|
|
78
|
+
`;
|
|
79
|
+
const FeatureBoxFill = (0, styled_components_1.default)(Padding) `
|
|
80
|
+
background-image: linear-gradient(
|
|
81
|
+
to bottom right,
|
|
82
|
+
${({ left }) => left},
|
|
83
|
+
${({ right }) => right}
|
|
84
|
+
);
|
|
85
|
+
color: ${colours_1.colours.mainLight};
|
|
86
|
+
border-radius: ${({ radius }) => radius};
|
|
87
|
+
flex-grow: 1;
|
|
88
|
+
`;
|
|
89
|
+
const BorderGradient = ({ left = colours_1.colours.orange, right = colours_1.colours.orangeRed, children, radius = '2rem', fill = false, padding = '2rem', className, onClick, href, target, rel, noGrow = false, disabled = false, canClick = false, }) => {
|
|
90
|
+
const props = {
|
|
91
|
+
onClick: (e) => !disabled && onClick && onClick(e),
|
|
92
|
+
className,
|
|
93
|
+
left: (!fill && left) || undefined,
|
|
94
|
+
right: (!fill && right) || undefined,
|
|
95
|
+
radius,
|
|
96
|
+
href,
|
|
97
|
+
target,
|
|
98
|
+
rel,
|
|
99
|
+
noGrow,
|
|
100
|
+
disabled,
|
|
101
|
+
canClick: !!onClick || canClick,
|
|
102
|
+
};
|
|
103
|
+
const child = (react_1.default.createElement(react_1.default.Fragment, null,
|
|
104
|
+
!fill && react_1.default.createElement(Padding, { padding: padding }, children),
|
|
105
|
+
fill && (react_1.default.createElement(FeatureBoxFill, { left: left, right: right, radius: radius, padding: padding }, children))));
|
|
106
|
+
if (href) {
|
|
107
|
+
return react_1.default.createElement(BGALink, Object.assign({}, props), child);
|
|
108
|
+
}
|
|
109
|
+
return react_1.default.createElement(BGLink, Object.assign({}, props), child);
|
|
110
|
+
};
|
|
111
|
+
exports.BorderGradient = BorderGradient;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface IIcon {
|
|
3
|
+
disabled?: boolean;
|
|
4
|
+
fill?: string;
|
|
5
|
+
outline?: string;
|
|
6
|
+
width?: string;
|
|
7
|
+
height?: string;
|
|
8
|
+
flip?: boolean;
|
|
9
|
+
canHover?: boolean;
|
|
10
|
+
margin?: string;
|
|
11
|
+
padding?: string;
|
|
12
|
+
onClick?: (e: React.MouseEvent<HTMLSpanElement, MouseEvent>) => void;
|
|
13
|
+
children?: JSX.Element | JSX.Element[];
|
|
14
|
+
role?: string;
|
|
15
|
+
title?: string;
|
|
16
|
+
tabIndex?: number;
|
|
17
|
+
className?: string;
|
|
18
|
+
}
|
|
19
|
+
export declare const IconF: import("styled-components").StyledComponent<"span", any, IIcon, never>;
|
|
20
|
+
export declare const Icon: (pr: IIcon) => JSX.Element;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,86 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.Icon = exports.IconF = void 0;
|
|
26
|
+
const react_1 = __importDefault(require("react"));
|
|
27
|
+
const styled_components_1 = __importStar(require("styled-components"));
|
|
28
|
+
const common_1 = require("../../styles/common");
|
|
29
|
+
exports.IconF = styled_components_1.default.span `
|
|
30
|
+
display: flex;
|
|
31
|
+
justify-content: center;
|
|
32
|
+
align-items: center;
|
|
33
|
+
font-size: 2rem;
|
|
34
|
+
padding: ${({ padding }) => padding || '0'};
|
|
35
|
+
transition: background-color 200ms;
|
|
36
|
+
margin: ${({ margin }) => (!margin ? 'unset' : margin)};
|
|
37
|
+
cursor: ${({ disabled, canHover }) => disabled || !canHover ? 'inherit' : 'pointer'};
|
|
38
|
+
> svg {
|
|
39
|
+
flex-grow: 1;
|
|
40
|
+
}
|
|
41
|
+
${({ disabled }) => disabled &&
|
|
42
|
+
(0, styled_components_1.css) `
|
|
43
|
+
filter: grayscale(1);
|
|
44
|
+
`}
|
|
45
|
+
${({ canHover, disabled }) => canHover &&
|
|
46
|
+
!disabled &&
|
|
47
|
+
(0, styled_components_1.css) `
|
|
48
|
+
&:hover {
|
|
49
|
+
filter: saturate(3);
|
|
50
|
+
}
|
|
51
|
+
`}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
${({ fill }) => fill &&
|
|
56
|
+
(0, styled_components_1.css) `
|
|
57
|
+
fill: ${fill};
|
|
58
|
+
|
|
59
|
+
svg {
|
|
60
|
+
fill: ${fill};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
linearGradient > *,
|
|
64
|
+
radialGradient > * {
|
|
65
|
+
stop-color: ${fill} !important;
|
|
66
|
+
}
|
|
67
|
+
`};
|
|
68
|
+
${({ outline }) => outline && (0, common_1.DropShadow)(outline)};
|
|
69
|
+
|
|
70
|
+
width: ${({ width }) => width || '100%'};
|
|
71
|
+
height: ${({ height }) => height || '100%'};
|
|
72
|
+
${({ flip }) => flip &&
|
|
73
|
+
(0, styled_components_1.css) `
|
|
74
|
+
transform: rotate(180deg);
|
|
75
|
+
`};
|
|
76
|
+
|
|
77
|
+
svg {
|
|
78
|
+
width: 100%;
|
|
79
|
+
height: 100%;
|
|
80
|
+
}
|
|
81
|
+
`;
|
|
82
|
+
const Icon = (pr) => {
|
|
83
|
+
const { className, children, disabled, onClick } = pr;
|
|
84
|
+
return (react_1.default.createElement(exports.IconF, Object.assign({}, pr, { className: className, onClick: (e) => !disabled && (onClick === null || onClick === void 0 ? void 0 : onClick(e)) }), children));
|
|
85
|
+
};
|
|
86
|
+
exports.Icon = Icon;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { AuthedUserContext } from '
|
|
2
|
+
import { AuthedUserContext } from '../../helpers/jwt';
|
|
3
3
|
export declare const UserImage: ({ image, className, showProfilePicture, CognitoAuthContext, }: {
|
|
4
4
|
image?: string | undefined;
|
|
5
5
|
className?: string | undefined;
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
export * from './BorderGradient';
|
|
1
2
|
export * from './Button';
|
|
2
3
|
export * from './Dropdown';
|
|
3
4
|
export * from './DropdownList';
|
|
4
5
|
export * from './FlexColumn';
|
|
5
6
|
export * from './FlexRow';
|
|
6
7
|
export * from './HeadersRaw';
|
|
8
|
+
export * from './Icon';
|
|
7
9
|
export * from './Input';
|
|
8
10
|
export * from './Loader';
|
|
9
11
|
export * from './LoginButton';
|
|
@@ -10,12 +10,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./BorderGradient"), exports);
|
|
13
14
|
__exportStar(require("./Button"), exports);
|
|
14
15
|
__exportStar(require("./Dropdown"), exports);
|
|
15
16
|
__exportStar(require("./DropdownList"), exports);
|
|
16
17
|
__exportStar(require("./FlexColumn"), exports);
|
|
17
18
|
__exportStar(require("./FlexRow"), exports);
|
|
18
19
|
__exportStar(require("./HeadersRaw"), exports);
|
|
20
|
+
__exportStar(require("./Icon"), exports);
|
|
19
21
|
__exportStar(require("./Input"), exports);
|
|
20
22
|
__exportStar(require("./Loader"), exports);
|
|
21
23
|
__exportStar(require("./LoginButton"), exports);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AxiosResponse } from 'axios';
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param body accepts object or json, and passes as-is
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
export declare const axiosHelper: <TOut>({ verb, url, body, headers, timeout, retryMax, onStaleAuth, }: {
|
|
8
|
+
headers?: {
|
|
9
|
+
[a: string]: string;
|
|
10
|
+
} | undefined;
|
|
11
|
+
verb: 'put' | 'post' | 'get' | 'patch' | 'delete';
|
|
12
|
+
url: string;
|
|
13
|
+
body?: unknown;
|
|
14
|
+
timeout?: number | undefined;
|
|
15
|
+
retryMax?: number | undefined;
|
|
16
|
+
onStaleAuth?: (() => void) | undefined;
|
|
17
|
+
}) => Promise<AxiosResponse<TOut, any>>;
|
|
@@ -0,0 +1,87 @@
|
|
|
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.axiosHelper = void 0;
|
|
16
|
+
const axios_1 = __importDefault(require("axios"));
|
|
17
|
+
const object_1 = require("../../common/helpers/object");
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* @param body accepts object or json, and passes as-is
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
const axiosHelper = ({ verb, url, body, headers, timeout = 30000, retryMax = 0, onStaleAuth, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
24
|
+
let retry = 0;
|
|
25
|
+
do {
|
|
26
|
+
try {
|
|
27
|
+
const setHeaders = Object.assign({ accept: 'application/json' }, headers);
|
|
28
|
+
if (verb === 'get') {
|
|
29
|
+
const ret = yield axios_1.default.get(url, {
|
|
30
|
+
headers: setHeaders,
|
|
31
|
+
timeout,
|
|
32
|
+
timeoutErrorMessage: `${url} timeout`,
|
|
33
|
+
});
|
|
34
|
+
return ret;
|
|
35
|
+
}
|
|
36
|
+
let noBody = false;
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
|
+
let axios = axios_1.default.post;
|
|
39
|
+
if (verb === 'put') {
|
|
40
|
+
axios = axios_1.default.put;
|
|
41
|
+
}
|
|
42
|
+
else if (verb === 'post') {
|
|
43
|
+
axios = axios_1.default.post;
|
|
44
|
+
}
|
|
45
|
+
else if (verb === 'patch') {
|
|
46
|
+
axios = axios_1.default.patch;
|
|
47
|
+
}
|
|
48
|
+
else if (verb === 'delete') {
|
|
49
|
+
axios = axios_1.default.delete;
|
|
50
|
+
noBody = true;
|
|
51
|
+
}
|
|
52
|
+
let ret;
|
|
53
|
+
if (noBody) {
|
|
54
|
+
ret = yield axios(url, {
|
|
55
|
+
headers: setHeaders,
|
|
56
|
+
timeout,
|
|
57
|
+
timeoutErrorMessage: `${url} timeout`,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
62
|
+
if (body && (0, object_1.isJson)(body)) {
|
|
63
|
+
setHeaders['Content-Type'] = 'application/json';
|
|
64
|
+
}
|
|
65
|
+
ret = yield axios(url, body, { headers: setHeaders });
|
|
66
|
+
}
|
|
67
|
+
return ret;
|
|
68
|
+
}
|
|
69
|
+
catch (e) {
|
|
70
|
+
const em = e;
|
|
71
|
+
// jwt expired or bad response
|
|
72
|
+
// 403 returned for old token - will be refreshed
|
|
73
|
+
if (em.code === '401' || em.code === '403') {
|
|
74
|
+
// eslint-disable-next-line no-console
|
|
75
|
+
console.log('auth expired');
|
|
76
|
+
onStaleAuth === null || onStaleAuth === void 0 ? void 0 : onStaleAuth();
|
|
77
|
+
retry = retryMax;
|
|
78
|
+
}
|
|
79
|
+
if (retry >= retryMax) {
|
|
80
|
+
throw em;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
retry += 1;
|
|
84
|
+
} while (retry <= retryMax);
|
|
85
|
+
throw new Error('unexpected');
|
|
86
|
+
});
|
|
87
|
+
exports.axiosHelper = axiosHelper;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export declare type TOnMessage = (m: string, options?: {
|
|
3
|
+
appearance: 'error' | 'success';
|
|
4
|
+
}) => void;
|
|
5
|
+
export interface ICognitoAuth {
|
|
6
|
+
AWSRegion: string;
|
|
7
|
+
poolUrl: string;
|
|
8
|
+
identityPool?: string;
|
|
9
|
+
UserPoolId: string;
|
|
10
|
+
ClientId: string;
|
|
11
|
+
cognitoEndpoint: string;
|
|
12
|
+
cognitoRefresh: string;
|
|
13
|
+
vendToken: string;
|
|
14
|
+
}
|
|
15
|
+
export interface ICognitoAuthProviderProps {
|
|
16
|
+
redirectUrl?: string;
|
|
17
|
+
location: {
|
|
18
|
+
pathname: string;
|
|
19
|
+
hash: string;
|
|
20
|
+
search: string;
|
|
21
|
+
origin: string;
|
|
22
|
+
};
|
|
23
|
+
goToPageUrl: ({ url, state, login, }: {
|
|
24
|
+
url: string;
|
|
25
|
+
state?: any;
|
|
26
|
+
login: boolean;
|
|
27
|
+
}) => Promise<void>;
|
|
28
|
+
children: JSX.Element | JSX.Element[];
|
|
29
|
+
config: ICognitoAuth;
|
|
30
|
+
onMessage?: TOnMessage;
|
|
31
|
+
}
|
|
@@ -26,7 +26,7 @@ function getCookie({ cname, cookieDocument, }) {
|
|
|
26
26
|
const ca = ca1.split(';').map((t) => t.trim());
|
|
27
27
|
for (const c of ca) {
|
|
28
28
|
if (c.indexOf(name) === 0) {
|
|
29
|
-
return c.
|
|
29
|
+
return c.substr(name.length, c.length);
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
return undefined;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDMY = exports.daydiffstr = void 0;
|
|
4
|
+
const date_1 = require("../../common/helpers/date");
|
|
5
|
+
const math_1 = require("../../common/helpers/math");
|
|
6
|
+
const plural_1 = require("./plural");
|
|
7
|
+
const daydiffstr = (dayticks) => {
|
|
8
|
+
const ticksSince = new Date().getTime() - dayticks;
|
|
9
|
+
const totalMinutes = (0, math_1.toFixedDown)(ticksSince / 1000 / 60, 0);
|
|
10
|
+
const totalHours = (0, math_1.toFixedDown)(totalMinutes / 60, 0);
|
|
11
|
+
const totalDays = (0, math_1.toFixedDown)(totalHours / 24, 0);
|
|
12
|
+
const totalYears = (0, math_1.toFixedDown)(totalDays / 365, 0);
|
|
13
|
+
let ts = `${totalYears} ${(0, plural_1.plural)('yr', totalYears)} ago `;
|
|
14
|
+
if (totalMinutes < 60) {
|
|
15
|
+
ts = `${totalMinutes} ${(0, plural_1.plural)('min', totalMinutes)} ago `;
|
|
16
|
+
}
|
|
17
|
+
else if (totalHours < 24) {
|
|
18
|
+
ts = `${totalHours} ${(0, plural_1.plural)('hr', totalHours)} ago `;
|
|
19
|
+
}
|
|
20
|
+
else if (totalDays < 365) {
|
|
21
|
+
ts = `${totalDays} ${(0, plural_1.plural)('day', totalDays)} ago `;
|
|
22
|
+
}
|
|
23
|
+
return ts;
|
|
24
|
+
};
|
|
25
|
+
exports.daydiffstr = daydiffstr;
|
|
26
|
+
const getDMY = (date, dayOffset) => {
|
|
27
|
+
const date1 = (0, date_1.addDays)(date, dayOffset || 0);
|
|
28
|
+
const d = String(date1.getDate()).padStart(2, '0');
|
|
29
|
+
const m = String(date1.getMonth() + 1).padStart(2, '0'); // January is 0!
|
|
30
|
+
const y = date1.getFullYear();
|
|
31
|
+
return `${y}-${m}-${d}`;
|
|
32
|
+
};
|
|
33
|
+
exports.getDMY = getDMY;
|
|
@@ -1,13 +1,18 @@
|
|
|
1
|
+
export * from './axiosHelper';
|
|
1
2
|
export * from './browserHelpers';
|
|
2
3
|
export * from './callOpenApi';
|
|
4
|
+
export * from './cognito';
|
|
3
5
|
export * from './cookie';
|
|
6
|
+
export * from './date';
|
|
4
7
|
export * from './debounce';
|
|
5
8
|
export * from './dom';
|
|
6
9
|
export * from './extractAttributes';
|
|
10
|
+
export * from './jwt';
|
|
7
11
|
export * from './lang';
|
|
8
12
|
export * from './mutex';
|
|
9
13
|
export * from './mutexData';
|
|
10
14
|
export * from './plural';
|
|
15
|
+
export * from './routes';
|
|
11
16
|
export * from './useLocalStorage';
|
|
12
17
|
export * from './useLockBodyScroll';
|
|
13
18
|
export * from './useOnClickOutside';
|
package/dist/ui/helpers/index.js
CHANGED
|
@@ -10,16 +10,21 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./axiosHelper"), exports);
|
|
13
14
|
__exportStar(require("./browserHelpers"), exports);
|
|
14
15
|
__exportStar(require("./callOpenApi"), exports);
|
|
16
|
+
__exportStar(require("./cognito"), exports);
|
|
15
17
|
__exportStar(require("./cookie"), exports);
|
|
18
|
+
__exportStar(require("./date"), exports);
|
|
16
19
|
__exportStar(require("./debounce"), exports);
|
|
17
20
|
__exportStar(require("./dom"), exports);
|
|
18
21
|
__exportStar(require("./extractAttributes"), exports);
|
|
22
|
+
__exportStar(require("./jwt"), exports);
|
|
19
23
|
__exportStar(require("./lang"), exports);
|
|
20
24
|
__exportStar(require("./mutex"), exports);
|
|
21
25
|
__exportStar(require("./mutexData"), exports);
|
|
22
26
|
__exportStar(require("./plural"), exports);
|
|
27
|
+
__exportStar(require("./routes"), exports);
|
|
23
28
|
__exportStar(require("./useLocalStorage"), exports);
|
|
24
29
|
__exportStar(require("./useLockBodyScroll"), exports);
|
|
25
30
|
__exportStar(require("./useOnClickOutside"), exports);
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { AxiosError } from 'axios';
|
|
2
|
+
export interface Jwt {
|
|
3
|
+
access_token: string;
|
|
4
|
+
expires_at: number;
|
|
5
|
+
expires_in: number;
|
|
6
|
+
id_token: string;
|
|
7
|
+
refresh_token: string;
|
|
8
|
+
token_type: string;
|
|
9
|
+
}
|
|
10
|
+
export interface Identity {
|
|
11
|
+
dateCreated: string;
|
|
12
|
+
issuer?: string | Array<string>;
|
|
13
|
+
primary: string;
|
|
14
|
+
providerName: string;
|
|
15
|
+
providerType: string;
|
|
16
|
+
userId: string;
|
|
17
|
+
}
|
|
18
|
+
export interface IdJwt {
|
|
19
|
+
at_hash: string;
|
|
20
|
+
aud: string;
|
|
21
|
+
auth_time: number;
|
|
22
|
+
'cognito:groups': Array<string>;
|
|
23
|
+
'cognito:preferred_role': string;
|
|
24
|
+
'cognito:username': string;
|
|
25
|
+
email: string;
|
|
26
|
+
exp: number;
|
|
27
|
+
iat: number;
|
|
28
|
+
identities: Array<Identity>;
|
|
29
|
+
iss: string;
|
|
30
|
+
name: string;
|
|
31
|
+
nickname: string;
|
|
32
|
+
picture: string;
|
|
33
|
+
sub: string;
|
|
34
|
+
token_use: string;
|
|
35
|
+
}
|
|
36
|
+
export interface AwsCreds {
|
|
37
|
+
accessKeyId: string;
|
|
38
|
+
secretAccessKey: string;
|
|
39
|
+
sessionToken: string;
|
|
40
|
+
}
|
|
41
|
+
export interface User {
|
|
42
|
+
userId: string;
|
|
43
|
+
picture: string;
|
|
44
|
+
updatedAt: number;
|
|
45
|
+
nickname: string;
|
|
46
|
+
fullname: string;
|
|
47
|
+
credentials?: AwsCreds;
|
|
48
|
+
idJwt: IdJwt;
|
|
49
|
+
isAdmin: boolean;
|
|
50
|
+
jwt?: Jwt;
|
|
51
|
+
}
|
|
52
|
+
export interface AxiosWrapper<T> {
|
|
53
|
+
data: T;
|
|
54
|
+
error: AxiosError<unknown, any> | undefined;
|
|
55
|
+
loading: boolean;
|
|
56
|
+
reFetch: () => Promise<any>;
|
|
57
|
+
url: string;
|
|
58
|
+
datetime: number;
|
|
59
|
+
}
|
|
60
|
+
export interface AuthedUserContext {
|
|
61
|
+
loading: boolean;
|
|
62
|
+
isAuthenticated: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* @param stateqs: must be base64'd
|
|
65
|
+
*/
|
|
66
|
+
loginWithRedirect: (stateqs?: string) => Promise<void>;
|
|
67
|
+
logout: () => Promise<void>;
|
|
68
|
+
user: AxiosWrapper<User>;
|
|
69
|
+
error: Error | undefined;
|
|
70
|
+
refreshToken: () => Promise<User | undefined>;
|
|
71
|
+
}
|
|
72
|
+
export interface AuthedUser {
|
|
73
|
+
user: AuthedUserContext;
|
|
74
|
+
userLink?: User;
|
|
75
|
+
}
|
|
76
|
+
export declare const getBearerToken: (jwt?: {
|
|
77
|
+
id_token?: string | undefined;
|
|
78
|
+
} | undefined) => string | undefined;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getBearerToken = void 0;
|
|
4
|
+
const getBearerToken = (jwt) => !(jwt === null || jwt === void 0 ? void 0 : jwt.id_token) ? undefined : `Bearer ${jwt.id_token}`;
|
|
5
|
+
exports.getBearerToken = getBearerToken;
|
|
@@ -8,5 +8,9 @@ export declare class MutexData<T> {
|
|
|
8
8
|
unsubscribe(key: string, subId: string): void;
|
|
9
9
|
getData(key: string): T;
|
|
10
10
|
pingSubscribers(key: string): void;
|
|
11
|
-
setData(
|
|
11
|
+
setData({ ttlSeconds, key, data, }: {
|
|
12
|
+
key: string;
|
|
13
|
+
data: T;
|
|
14
|
+
ttlSeconds?: number;
|
|
15
|
+
}): void;
|
|
12
16
|
}
|
|
@@ -36,7 +36,7 @@ class MutexData {
|
|
|
36
36
|
}
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
|
-
setData(key, data,
|
|
39
|
+
setData({ ttlSeconds = 3600, key, data, }) {
|
|
40
40
|
(0, useLocalStorage_1.setLocalStorageItem)(`mutex-${key}`, data, ttlSeconds);
|
|
41
41
|
if (Object.keys(this.subscriptions).length > 0) {
|
|
42
42
|
this.pingSubscribers(key);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import {
|
|
2
|
+
import { ICognitoAuth, ICognitoAuthProviderProps } from './cognito';
|
|
3
|
+
import { AuthedUserContext } from './jwt';
|
|
3
4
|
export interface LocationSubset {
|
|
4
5
|
pathname: string;
|
|
5
6
|
hash: string;
|
|
@@ -7,26 +8,26 @@ export interface LocationSubset {
|
|
|
7
8
|
query: Record<string, string>;
|
|
8
9
|
host: string;
|
|
9
10
|
}
|
|
10
|
-
export interface IRequest {
|
|
11
|
-
darkMode: boolean;
|
|
12
|
-
url: LocationSubset;
|
|
13
|
-
headerTitle?: string;
|
|
14
|
-
seed?: number;
|
|
15
|
-
lang: 'en';
|
|
16
|
-
}
|
|
17
11
|
export declare type CacheItems = CacheItem[];
|
|
18
12
|
export interface CacheItem {
|
|
19
13
|
cacheKey: string;
|
|
20
14
|
prefillData: any;
|
|
21
15
|
ttlSeconds: number;
|
|
22
16
|
}
|
|
23
|
-
export interface
|
|
17
|
+
export interface IInitialStateCommon {
|
|
24
18
|
openApiCache?: CacheItem[];
|
|
25
19
|
headerTitle?: string;
|
|
26
20
|
seed?: number;
|
|
27
21
|
}
|
|
28
|
-
export interface
|
|
29
|
-
|
|
22
|
+
export interface IRequestCommon {
|
|
23
|
+
darkMode: boolean;
|
|
24
|
+
url: LocationSubset;
|
|
25
|
+
headerTitle?: string;
|
|
26
|
+
seed?: number;
|
|
27
|
+
lang: 'en';
|
|
28
|
+
}
|
|
29
|
+
export interface IStateCommon<TRequest extends IRequestCommon> extends IInitialStateCommon {
|
|
30
|
+
request: TRequest;
|
|
30
31
|
auth: ICognitoAuth;
|
|
31
32
|
CognitoAuthContext: React.Context<AuthedUserContext>;
|
|
32
33
|
CognitoAuthProvider: (p: ICognitoAuthProviderProps) => JSX.Element;
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import { AxiosResponse } from 'axios';
|
|
2
|
-
import {
|
|
2
|
+
import { OverrideAuth } from './callOpenApi';
|
|
3
3
|
import { CacheItems } from './routes';
|
|
4
|
+
import { AxiosWrapper, User } from './jwt';
|
|
4
5
|
export declare const setMutexData: ({ key, data, ttlSeconds, }: {
|
|
5
6
|
key: string;
|
|
6
7
|
data: any;
|
|
7
8
|
ttlSeconds: number;
|
|
8
9
|
}) => void;
|
|
9
10
|
export declare const getMutexData: <T>(key: string) => AxiosWrapper<T>;
|
|
10
|
-
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @param overrideAuth - auth automatically picked up from id_token cookie, can override value here, but not required
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
export declare const useOpenApiStore: <T, TDefaultApi>(p: {
|
|
11
17
|
ttlSeconds?: number | undefined;
|
|
12
18
|
func: (f: TDefaultApi) => Promise<AxiosResponse<T, any>>;
|
|
13
19
|
cacheKey: string;
|
|
@@ -16,5 +22,6 @@ export declare const useOpenApiStore: <T, TDefaultApi>({ func, cacheKey, ttlSeco
|
|
|
16
22
|
disabled?: boolean | undefined;
|
|
17
23
|
apiUrl: string;
|
|
18
24
|
newDefaultApi: (config: any) => TDefaultApi;
|
|
25
|
+
overrideAuth?: OverrideAuth | undefined;
|
|
19
26
|
}) => AxiosWrapper<T>;
|
|
20
27
|
export declare const setOpenApiCache: (items: CacheItems) => void;
|
|
@@ -34,15 +34,13 @@ const setMutexData = ({ key, data, ttlSeconds = 3600, }) => {
|
|
|
34
34
|
error: undefined,
|
|
35
35
|
url: '',
|
|
36
36
|
};
|
|
37
|
-
mutexData.setData(key, wrap, ttlSeconds);
|
|
37
|
+
mutexData.setData({ key, data: wrap, ttlSeconds });
|
|
38
38
|
};
|
|
39
39
|
exports.setMutexData = setMutexData;
|
|
40
40
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
41
41
|
const getMutexData = (key) => mutexData.getData(key);
|
|
42
42
|
exports.getMutexData = getMutexData;
|
|
43
|
-
function mLock(key, func, ttlSeconds, logout, refreshToken, apiUrl,
|
|
44
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
45
|
-
newDefaultApi) {
|
|
43
|
+
function mLock({ key, func, ttlSeconds = 3600, logout, refreshToken, apiUrl, newDefaultApi, overrideAuth, }) {
|
|
46
44
|
return __awaiter(this, void 0, void 0, function* () {
|
|
47
45
|
let unlock;
|
|
48
46
|
try {
|
|
@@ -56,6 +54,7 @@ newDefaultApi) {
|
|
|
56
54
|
logout,
|
|
57
55
|
refreshToken,
|
|
58
56
|
newDefaultApi,
|
|
57
|
+
overrideAuth,
|
|
59
58
|
});
|
|
60
59
|
if (!newData) {
|
|
61
60
|
return;
|
|
@@ -64,7 +63,7 @@ newDefaultApi) {
|
|
|
64
63
|
(0, log_1.error)('api error:', newData.error);
|
|
65
64
|
}
|
|
66
65
|
else {
|
|
67
|
-
mutexData.setData(key, newData, ttlSeconds);
|
|
66
|
+
mutexData.setData({ key, data: newData, ttlSeconds });
|
|
68
67
|
}
|
|
69
68
|
mutexData.pingSubscribers(key);
|
|
70
69
|
}
|
|
@@ -81,7 +80,13 @@ newDefaultApi) {
|
|
|
81
80
|
});
|
|
82
81
|
}
|
|
83
82
|
const getTs = () => new Date().getTime();
|
|
84
|
-
|
|
83
|
+
/**
|
|
84
|
+
*
|
|
85
|
+
* @param overrideAuth - auth automatically picked up from id_token cookie, can override value here, but not required
|
|
86
|
+
* @returns
|
|
87
|
+
*/
|
|
88
|
+
const useOpenApiStore = (p) => {
|
|
89
|
+
const { cacheKey, disabled } = p;
|
|
85
90
|
if (!cacheKey) {
|
|
86
91
|
throw new Error('no cache key');
|
|
87
92
|
}
|
|
@@ -98,18 +103,9 @@ const useOpenApiStore = ({ func, cacheKey, ttlSeconds = 3600, logout, refreshTok
|
|
|
98
103
|
(0, react_1.useEffect)(() => {
|
|
99
104
|
if (!disabled && !mutexData.getData(key)) {
|
|
100
105
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
101
|
-
mLock(key
|
|
106
|
+
mLock(Object.assign({ key }, p));
|
|
102
107
|
}
|
|
103
|
-
}, [
|
|
104
|
-
disabled,
|
|
105
|
-
func,
|
|
106
|
-
key,
|
|
107
|
-
ttlSeconds,
|
|
108
|
-
logout,
|
|
109
|
-
refreshToken,
|
|
110
|
-
apiUrl,
|
|
111
|
-
newDefaultApi,
|
|
112
|
-
]);
|
|
108
|
+
}, [disabled, key, p]);
|
|
113
109
|
if (!mutexData.getData(key)) {
|
|
114
110
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
115
111
|
return { loading: true };
|
|
@@ -127,23 +123,21 @@ const useOpenApiStore = ({ func, cacheKey, ttlSeconds = 3600, logout, refreshTok
|
|
|
127
123
|
}
|
|
128
124
|
const current = mutexData.getData(key);
|
|
129
125
|
return Object.assign(Object.assign({}, current), { reFetch: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
130
|
-
mutexData.setData(
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
func,
|
|
135
|
-
logout,
|
|
136
|
-
refreshToken,
|
|
137
|
-
newDefaultApi,
|
|
126
|
+
mutexData.setData({
|
|
127
|
+
key,
|
|
128
|
+
data: Object.assign(Object.assign({}, current), { loading: true }),
|
|
129
|
+
ttlSeconds: p.ttlSeconds,
|
|
138
130
|
});
|
|
139
|
-
mutexData.
|
|
131
|
+
mutexData.pingSubscribers(key);
|
|
132
|
+
const newData = yield (0, callOpenApi_1.callOpenApi)(p);
|
|
133
|
+
mutexData.setData({ key, data: newData, ttlSeconds: p.ttlSeconds });
|
|
140
134
|
mutexData.pingSubscribers(key);
|
|
141
135
|
}) });
|
|
142
136
|
};
|
|
143
137
|
exports.useOpenApiStore = useOpenApiStore;
|
|
144
138
|
const setOpenApiCache = (items) => {
|
|
145
139
|
items.forEach(({ cacheKey, prefillData, ttlSeconds }) => {
|
|
146
|
-
mutexData.setData(cacheKey, prefillData, ttlSeconds);
|
|
140
|
+
mutexData.setData({ key: cacheKey, data: prefillData, ttlSeconds });
|
|
147
141
|
});
|
|
148
142
|
};
|
|
149
143
|
exports.setOpenApiCache = setOpenApiCache;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ag-common",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.12",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"author": "Andrei Gec <@andreigec> (https://gec.dev/)",
|
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
"axios": "0.24.0",
|
|
13
13
|
"typescript": "4.5.4",
|
|
14
14
|
"openapi-request-validator": "10.0.0",
|
|
15
|
-
"analytica.click": "0.0.123",
|
|
16
15
|
"aws-sdk": "2.1048.0",
|
|
17
16
|
"aws-cdk-lib": "2.3.0",
|
|
18
17
|
"constructs": "10.0.17",
|