ag-common 0.0.3

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.
Files changed (145) hide show
  1. package/dist/api/helpers/api.d.ts +16 -0
  2. package/dist/api/helpers/api.js +67 -0
  3. package/dist/api/helpers/dynamo.d.ts +44 -0
  4. package/dist/api/helpers/dynamo.js +307 -0
  5. package/dist/api/helpers/dynamoInfra.d.ts +15 -0
  6. package/dist/api/helpers/dynamoInfra.js +64 -0
  7. package/dist/api/helpers/index.d.ts +3 -0
  8. package/dist/api/helpers/index.js +15 -0
  9. package/dist/api/helpers/openApiHelpers.d.ts +14 -0
  10. package/dist/api/helpers/openApiHelpers.js +131 -0
  11. package/dist/api/index.d.ts +2 -0
  12. package/dist/api/index.js +14 -0
  13. package/dist/api/types.d.ts +45 -0
  14. package/dist/api/types.js +2 -0
  15. package/dist/common/helpers/array.d.ts +9 -0
  16. package/dist/common/helpers/array.js +51 -0
  17. package/dist/common/helpers/distinctBy.d.ts +8 -0
  18. package/dist/common/helpers/distinctBy.js +35 -0
  19. package/dist/common/helpers/email.d.ts +7 -0
  20. package/dist/common/helpers/email.js +35 -0
  21. package/dist/common/helpers/groupBy.d.ts +22 -0
  22. package/dist/common/helpers/groupBy.js +53 -0
  23. package/dist/common/helpers/hashCode.d.ts +2 -0
  24. package/dist/common/helpers/hashCode.js +27 -0
  25. package/dist/common/helpers/i18n.d.ts +11 -0
  26. package/dist/common/helpers/i18n.js +14 -0
  27. package/dist/common/helpers/index.d.ts +12 -0
  28. package/dist/common/helpers/index.js +24 -0
  29. package/dist/common/helpers/log.d.ts +5 -0
  30. package/dist/common/helpers/log.js +25 -0
  31. package/dist/common/helpers/math.d.ts +11 -0
  32. package/dist/common/helpers/math.js +65 -0
  33. package/dist/common/helpers/object.d.ts +17 -0
  34. package/dist/common/helpers/object.js +54 -0
  35. package/dist/common/helpers/random.d.ts +1 -0
  36. package/dist/common/helpers/random.js +26 -0
  37. package/dist/common/helpers/secondsInNearest.d.ts +8 -0
  38. package/dist/common/helpers/secondsInNearest.js +39 -0
  39. package/dist/common/helpers/string.d.ts +9 -0
  40. package/dist/common/helpers/string.js +62 -0
  41. package/dist/common/index.d.ts +1 -0
  42. package/dist/common/index.js +13 -0
  43. package/dist/index.d.ts +3 -0
  44. package/dist/index.js +15 -0
  45. package/dist/ui/components/Button/index.d.ts +11 -0
  46. package/dist/ui/components/Button/index.js +45 -0
  47. package/dist/ui/components/Dropdown/index.d.ts +10 -0
  48. package/dist/ui/components/Dropdown/index.js +61 -0
  49. package/dist/ui/components/DropdownList/index.d.ts +9 -0
  50. package/dist/ui/components/DropdownList/index.js +124 -0
  51. package/dist/ui/components/FlexColumn/index.d.ts +6 -0
  52. package/dist/ui/components/FlexColumn/index.js +31 -0
  53. package/dist/ui/components/FlexRow/index.d.ts +7 -0
  54. package/dist/ui/components/FlexRow/index.js +42 -0
  55. package/dist/ui/components/HeadersRaw/index.d.ts +10 -0
  56. package/dist/ui/components/HeadersRaw/index.js +44 -0
  57. package/dist/ui/components/Input/index.d.ts +15 -0
  58. package/dist/ui/components/Input/index.js +54 -0
  59. package/dist/ui/components/Loader/index.d.ts +4 -0
  60. package/dist/ui/components/Loader/index.js +69 -0
  61. package/dist/ui/components/LoginButton/index.d.ts +12 -0
  62. package/dist/ui/components/LoginButton/index.js +32 -0
  63. package/dist/ui/components/LoginButton/text.d.ts +3 -0
  64. package/dist/ui/components/LoginButton/text.js +9 -0
  65. package/dist/ui/components/Modal/Close.d.ts +5 -0
  66. package/dist/ui/components/Modal/Close.js +37 -0
  67. package/dist/ui/components/Modal/index.d.ts +21 -0
  68. package/dist/ui/components/Modal/index.js +93 -0
  69. package/dist/ui/components/RowOrColumn/index.d.ts +6 -0
  70. package/dist/ui/components/RowOrColumn/index.js +40 -0
  71. package/dist/ui/components/Table/index.d.ts +9 -0
  72. package/dist/ui/components/Table/index.js +31 -0
  73. package/dist/ui/components/TextEdit/CheckboxEdit.d.ts +5 -0
  74. package/dist/ui/components/TextEdit/CheckboxEdit.js +59 -0
  75. package/dist/ui/components/TextEdit/ColourEdit.d.ts +5 -0
  76. package/dist/ui/components/TextEdit/ColourEdit.js +48 -0
  77. package/dist/ui/components/TextEdit/ListboxEdit.d.ts +6 -0
  78. package/dist/ui/components/TextEdit/ListboxEdit.js +41 -0
  79. package/dist/ui/components/TextEdit/TextEdit.d.ts +13 -0
  80. package/dist/ui/components/TextEdit/TextEdit.js +95 -0
  81. package/dist/ui/components/TextEdit/common.d.ts +5 -0
  82. package/dist/ui/components/TextEdit/common.js +70 -0
  83. package/dist/ui/components/TextEdit/images.d.ts +4 -0
  84. package/dist/ui/components/TextEdit/images.js +21 -0
  85. package/dist/ui/components/TextEdit/index.d.ts +4 -0
  86. package/dist/ui/components/TextEdit/index.js +16 -0
  87. package/dist/ui/components/TextInput/index.d.ts +12 -0
  88. package/dist/ui/components/TextInput/index.js +30 -0
  89. package/dist/ui/components/Toast/index.d.ts +11 -0
  90. package/dist/ui/components/Toast/index.js +42 -0
  91. package/dist/ui/components/UserImage/index.d.ts +8 -0
  92. package/dist/ui/components/UserImage/index.js +66 -0
  93. package/dist/ui/components/index.d.ts +16 -0
  94. package/dist/ui/components/index.js +28 -0
  95. package/dist/ui/helpers/browserHelpers.d.ts +1 -0
  96. package/dist/ui/helpers/browserHelpers.js +23 -0
  97. package/dist/ui/helpers/callOpenApi.d.ts +13 -0
  98. package/dist/ui/helpers/callOpenApi.js +85 -0
  99. package/dist/ui/helpers/cookie.d.ts +14 -0
  100. package/dist/ui/helpers/cookie.js +110 -0
  101. package/dist/ui/helpers/debounce.d.ts +6 -0
  102. package/dist/ui/helpers/debounce.js +33 -0
  103. package/dist/ui/helpers/dom.d.ts +1 -0
  104. package/dist/ui/helpers/dom.js +10 -0
  105. package/dist/ui/helpers/extractAttributes.d.ts +3 -0
  106. package/dist/ui/helpers/extractAttributes.js +17 -0
  107. package/dist/ui/helpers/index.d.ts +17 -0
  108. package/dist/ui/helpers/index.js +29 -0
  109. package/dist/ui/helpers/lang.d.ts +5 -0
  110. package/dist/ui/helpers/lang.js +23 -0
  111. package/dist/ui/helpers/mutex.d.ts +22 -0
  112. package/dist/ui/helpers/mutex.js +53 -0
  113. package/dist/ui/helpers/mutexData.d.ts +12 -0
  114. package/dist/ui/helpers/mutexData.js +46 -0
  115. package/dist/ui/helpers/plural.d.ts +1 -0
  116. package/dist/ui/helpers/plural.js +13 -0
  117. package/dist/ui/helpers/routes.d.ts +34 -0
  118. package/dist/ui/helpers/routes.js +2 -0
  119. package/dist/ui/helpers/useLocalStorage.d.ts +5 -0
  120. package/dist/ui/helpers/useLocalStorage.js +80 -0
  121. package/dist/ui/helpers/useLockBodyScroll.d.ts +1 -0
  122. package/dist/ui/helpers/useLockBodyScroll.js +19 -0
  123. package/dist/ui/helpers/useOnClickOutside.d.ts +7 -0
  124. package/dist/ui/helpers/useOnClickOutside.js +28 -0
  125. package/dist/ui/helpers/useOnScroll.d.ts +6 -0
  126. package/dist/ui/helpers/useOnScroll.js +33 -0
  127. package/dist/ui/helpers/useOpenApiStore.d.ts +14 -0
  128. package/dist/ui/helpers/useOpenApiStore.js +145 -0
  129. package/dist/ui/helpers/useQueryString.d.ts +8 -0
  130. package/dist/ui/helpers/useQueryString.js +38 -0
  131. package/dist/ui/helpers/useResize.d.ts +8 -0
  132. package/dist/ui/helpers/useResize.js +33 -0
  133. package/dist/ui/index.d.ts +3 -0
  134. package/dist/ui/index.js +15 -0
  135. package/dist/ui/styles/colours.d.ts +25 -0
  136. package/dist/ui/styles/colours.js +51 -0
  137. package/dist/ui/styles/common.d.ts +13 -0
  138. package/dist/ui/styles/common.js +94 -0
  139. package/dist/ui/styles/index.d.ts +4 -0
  140. package/dist/ui/styles/index.js +16 -0
  141. package/dist/ui/styles/media.d.ts +5 -0
  142. package/dist/ui/styles/media.js +8 -0
  143. package/dist/ui/styles/standaloneStyles.d.ts +6 -0
  144. package/dist/ui/styles/standaloneStyles.js +69 -0
  145. package/package.json +40 -0
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.openApiImpl = void 0;
4
+ /* eslint-disable no-new */
5
+ const aws_cdk_lib_1 = require("aws-cdk-lib");
6
+ const distinctBy_1 = require("../../common/helpers/distinctBy");
7
+ const log_1 = require("../../common/helpers/log");
8
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
9
+ const getPaths = (schema) => Object.entries(schema.paths).map(([fullPath, verbs]) => ({
10
+ fullPath,
11
+ pathList: fullPath.split('/').filter((s) => s),
12
+ verbs: Object.keys(verbs),
13
+ }));
14
+ const setUpApiGw = ({ stack, NODE_ENV, baseUrl, certificate, hostedZone, shortStackName, }) => {
15
+ const api = new aws_cdk_lib_1.aws_apigateway.RestApi(stack, `${shortStackName}-api-${NODE_ENV}`, {
16
+ defaultCorsPreflightOptions: {
17
+ allowOrigins: aws_cdk_lib_1.aws_apigateway.Cors.ALL_ORIGINS,
18
+ },
19
+ });
20
+ const dn = new aws_cdk_lib_1.aws_apigateway.DomainName(stack, 'domain', {
21
+ domainName: `api.${baseUrl}`,
22
+ certificate,
23
+ endpointType: aws_cdk_lib_1.aws_apigateway.EndpointType.EDGE,
24
+ securityPolicy: aws_cdk_lib_1.aws_apigateway.SecurityPolicy.TLS_1_2,
25
+ mapping: api,
26
+ });
27
+ new aws_cdk_lib_1.aws_route53.ARecord(stack, 'ARecord', {
28
+ comment: '(cdk)',
29
+ recordName: 'api',
30
+ zone: hostedZone,
31
+ target: aws_cdk_lib_1.aws_route53.RecordTarget.fromAlias(new aws_cdk_lib_1.aws_route53_targets.ApiGatewayDomain(dn)),
32
+ });
33
+ return api;
34
+ };
35
+ const getDynamoPermissions = ({ lambdaPermissions, pathV, verb, seenPermissions, }) => {
36
+ const pathCompute = pathV + '-' + verb;
37
+ const lp = lambdaPermissions === null || lambdaPermissions === void 0 ? void 0 : lambdaPermissions[pathCompute];
38
+ if (lp) {
39
+ seenPermissions[pathCompute] = true;
40
+ }
41
+ else {
42
+ seenPermissions[pathCompute] = false;
43
+ }
44
+ const def = lambdaPermissions === null || lambdaPermissions === void 0 ? void 0 : lambdaPermissions.default;
45
+ if (def) {
46
+ seenPermissions.default = true;
47
+ }
48
+ //
49
+ const readTables = (0, distinctBy_1.distinctBy)([...((def === null || def === void 0 ? void 0 : def.reads) || []), ...((lp === null || lp === void 0 ? void 0 : lp.reads) || [])], (s) => s.shortName);
50
+ const writeTables = (0, distinctBy_1.distinctBy)([...((def === null || def === void 0 ? void 0 : def.writes) || []), ...((lp === null || lp === void 0 ? void 0 : lp.writes) || [])], (s) => s.shortName);
51
+ const tables = [...readTables, ...writeTables];
52
+ const environment = {};
53
+ Object.values(tables).forEach((v) => {
54
+ environment[v.shortName] = v.table.tableName;
55
+ });
56
+ return { environment, readTables, writeTables };
57
+ };
58
+ const addApiPaths = (api, subs, apiRoots) => {
59
+ let apiPath;
60
+ subs.forEach((s, i) => {
61
+ if (i === 0) {
62
+ if (apiRoots[s]) {
63
+ apiPath = apiRoots[s];
64
+ }
65
+ else {
66
+ apiPath = api.root.addResource(s);
67
+ apiRoots[s] = apiPath;
68
+ }
69
+ }
70
+ else {
71
+ if (!apiPath) {
72
+ throw new Error('no apipath');
73
+ }
74
+ apiPath = apiPath.addResource(s);
75
+ }
76
+ });
77
+ if (!apiPath) {
78
+ throw new Error('no apipath');
79
+ }
80
+ return apiPath;
81
+ };
82
+ const lambdaNameSafe = (raw) => raw.replace(/[^a-zA-Z0-9-.]/gim, '-').replace(/(-){2,}/gim, '-');
83
+ const openApiImpl = (p) => {
84
+ if (!p.schema) {
85
+ throw new Error('no openapi schema found');
86
+ }
87
+ const { stack, NODE_ENV, endpointsBase, lambdaPermissions } = p;
88
+ const paths = getPaths(p.schema);
89
+ const api = setUpApiGw(p);
90
+ const apiRoots = {};
91
+ const seenPermissions = {};
92
+ paths.forEach(({ fullPath, verbs, pathList }) => {
93
+ const apiPath = addApiPaths(api, pathList, apiRoots);
94
+ verbs.forEach((verb) => {
95
+ const { environment, readTables, writeTables } = getDynamoPermissions({
96
+ lambdaPermissions,
97
+ pathV: fullPath,
98
+ verb,
99
+ seenPermissions,
100
+ });
101
+ const lambdaName = lambdaNameSafe(`${p.shortStackName}-${fullPath}-${verb}-${NODE_ENV}`);
102
+ const lambdaV = new aws_cdk_lib_1.aws_lambda_nodejs.NodejsFunction(stack, lambdaName, {
103
+ functionName: lambdaName,
104
+ runtime: aws_cdk_lib_1.aws_lambda.Runtime.NODEJS_14_X,
105
+ handler: 'handler',
106
+ environment,
107
+ memorySize: 128,
108
+ timeout: aws_cdk_lib_1.Duration.seconds(30),
109
+ description: '(cdk)',
110
+ entry: `${endpointsBase}${fullPath}/${verb.toUpperCase()}.ts`,
111
+ bundling: {
112
+ externalModules: ['aws-sdk', 'aws-lambda'],
113
+ },
114
+ });
115
+ readTables.forEach((t) => t.table.grantReadData(lambdaV));
116
+ writeTables.forEach((t) => t.table.grantReadWriteData(lambdaV));
117
+ //
118
+ apiPath.addMethod(verb.toUpperCase(), new aws_cdk_lib_1.aws_apigateway.LambdaIntegration(lambdaV, {}));
119
+ });
120
+ });
121
+ Object.keys(lambdaPermissions).forEach((k) => {
122
+ if (!seenPermissions[k] || seenPermissions[k] === false) {
123
+ (0, log_1.warn)(`unused permissions for '${k}', did you mean one of these paths?=`, Object.entries(seenPermissions)
124
+ .filter(([, b]) => !b)
125
+ .map(([f]) => f)
126
+ .join('\n'));
127
+ throw new Error('unused permissions!:' + k);
128
+ }
129
+ });
130
+ };
131
+ exports.openApiImpl = openApiImpl;
@@ -0,0 +1,2 @@
1
+ export * from './types';
2
+ export * from './helpers';
@@ -0,0 +1,14 @@
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("./types"), exports);
14
+ __exportStar(require("./helpers"), exports);
@@ -0,0 +1,45 @@
1
+ import { aws_dynamodb as dynamodb } from 'aws-cdk-lib';
2
+ import { Key } from 'aws-sdk/clients/dynamodb';
3
+ export interface DYNAMOKEYS {
4
+ type: string;
5
+ L1: string;
6
+ L2?: string;
7
+ L3?: string;
8
+ L4?: string;
9
+ L5?: string;
10
+ PK: string;
11
+ PK1: string;
12
+ PK2: string;
13
+ PK3?: string;
14
+ PK4?: string;
15
+ }
16
+ export interface IGeneratedDynamoData {
17
+ table: dynamodb.ITable;
18
+ shortName: string;
19
+ }
20
+ export interface ILambdaPermissions {
21
+ [pathHyphenVerb: string]: {
22
+ reads?: IGeneratedDynamoData[];
23
+ writes?: IGeneratedDynamoData[];
24
+ } & {
25
+ default?: {
26
+ reads?: IGeneratedDynamoData[];
27
+ writes?: IGeneratedDynamoData[];
28
+ };
29
+ };
30
+ }
31
+ export interface IQueryDynamo {
32
+ pkName: string;
33
+ pkValue: string | number;
34
+ pkOperator?: string;
35
+ skName?: string;
36
+ skValue?: string | number | string[] | number[];
37
+ skOperator?: string;
38
+ tableName: string;
39
+ indexName?: string;
40
+ count?: number;
41
+ startKey?: Key;
42
+ filterName?: string;
43
+ filterValue?: string | number;
44
+ filterOperator?: string;
45
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,9 @@
1
+ export declare const toObject: <T, Indexer extends string | number>(arr: T[], keyF: (a: T) => Indexer) => { [a in Indexer]: T; } | null;
2
+ export declare const flat: <T>(arr: T[][]) => T[];
3
+ export declare const take: <T>(array: T[], num: number) => {
4
+ part: T[];
5
+ rest: T[];
6
+ };
7
+ export declare const chunk: <T>(array: T[], max: number) => T[][];
8
+ export declare const partition: <T>(array: T[], func: (v: T) => boolean) => T[][] | null;
9
+ export declare function notEmpty<TValue>(value: TValue | null | undefined | false): value is TValue;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.notEmpty = exports.partition = exports.chunk = exports.take = exports.flat = exports.toObject = void 0;
4
+ const toObject = (arr, keyF) => {
5
+ if (!arr || !keyF) {
6
+ return null;
7
+ }
8
+ const ret = {};
9
+ arr.forEach((v) => {
10
+ const k = keyF(v);
11
+ ret[k] = v;
12
+ });
13
+ return ret;
14
+ };
15
+ exports.toObject = toObject;
16
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
17
+ // @ts-ignore
18
+ const flat = (arr) => [].concat(...arr);
19
+ exports.flat = flat;
20
+ const take = (array, num) => {
21
+ const ret = JSON.parse(JSON.stringify(array));
22
+ return { part: ret.slice(0, num), rest: ret.slice(num) };
23
+ };
24
+ exports.take = take;
25
+ const chunk = (array, max) => {
26
+ const rows = [];
27
+ let row = [];
28
+ for (const k in array) {
29
+ const item = array[k];
30
+ if (row.length < max) {
31
+ row = [...row, item];
32
+ }
33
+ else {
34
+ rows.push(row);
35
+ row = [];
36
+ }
37
+ }
38
+ if (row.length > 0) {
39
+ rows.push(row);
40
+ }
41
+ return rows;
42
+ };
43
+ exports.chunk = chunk;
44
+ const partition = (array, func) => !(array === null || array === void 0 ? void 0 : array.length)
45
+ ? null
46
+ : [array.filter((r) => func(r)), array.filter((r) => !func(r))];
47
+ exports.partition = partition;
48
+ function notEmpty(value) {
49
+ return value !== null && value !== undefined && value !== false;
50
+ }
51
+ exports.notEmpty = notEmpty;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * return a distinct array of items determined by a key function
3
+ * @param data
4
+ * @param key
5
+ * @param ignoreEmpty
6
+ */
7
+ export declare function distinctBy<T, TY>(data: T[], key: (item: T) => TY, ignoreEmpty?: boolean): T[];
8
+ export declare const distinct: <T>(arr: readonly T[]) => T[];
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.distinct = exports.distinctBy = void 0;
4
+ /**
5
+ * return a distinct array of items determined by a key function
6
+ * @param data
7
+ * @param key
8
+ * @param ignoreEmpty
9
+ */
10
+ function distinctBy(data, key, ignoreEmpty) {
11
+ if (!data || data.length === 0) {
12
+ return data;
13
+ }
14
+ const hashSet = new Set();
15
+ return data.filter((x) => {
16
+ let keyVal;
17
+ if (typeof key === 'string') {
18
+ keyVal = x[key];
19
+ }
20
+ else {
21
+ keyVal = key(x);
22
+ }
23
+ if (!keyVal && ignoreEmpty) {
24
+ return false;
25
+ }
26
+ if (!hashSet.has(keyVal)) {
27
+ hashSet.add(keyVal);
28
+ return true;
29
+ }
30
+ return false;
31
+ });
32
+ }
33
+ exports.distinctBy = distinctBy;
34
+ const distinct = (arr) => [...new Set(arr)];
35
+ exports.distinct = distinct;
@@ -0,0 +1,7 @@
1
+ export declare const isEmailValid: (email: string) => boolean;
2
+ export declare const getEmailErrors: (email: string, event: {
3
+ creatorId: string;
4
+ }) => string | undefined;
5
+ export declare const getEmailsErrors: (emails: string[], event: {
6
+ creatorId: string;
7
+ }) => string[];
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEmailsErrors = exports.getEmailErrors = exports.isEmailValid = void 0;
4
+ const array_1 = require("./array");
5
+ const regex = /^[-!#$%&'*+/0-9=?A-Z^_a-z{|}~](\.?[-!#$%&'*+/0-9=?A-Z^_a-z`{|}~])*@[a-zA-Z0-9](-*\.?[a-zA-Z0-9])*\.[a-zA-Z](-?[a-zA-Z0-9])+$/;
6
+ const isEmailValid = (email) => {
7
+ if (!email)
8
+ return false;
9
+ if (email.length > 256)
10
+ return false;
11
+ const valid = regex.test(email);
12
+ if (!valid)
13
+ return false;
14
+ const parts = email.split('@');
15
+ if (parts[0].length > 64)
16
+ return false;
17
+ const domainParts = parts[1].split('.');
18
+ if (domainParts.some((part) => part.length > 64)) {
19
+ return false;
20
+ }
21
+ return true;
22
+ };
23
+ exports.isEmailValid = isEmailValid;
24
+ const getEmailErrors = (email, event) => {
25
+ if (!(0, exports.isEmailValid)(email)) {
26
+ return `email not valid:${email}`;
27
+ }
28
+ if (event.creatorId === email) {
29
+ return `You cannot add the creator of this event as an admin`;
30
+ }
31
+ return undefined;
32
+ };
33
+ exports.getEmailErrors = getEmailErrors;
34
+ const getEmailsErrors = (emails, event) => emails.map((email) => (0, exports.getEmailErrors)(email, event)).filter(array_1.notEmpty);
35
+ exports.getEmailsErrors = getEmailsErrors;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * group an array of items by the output of a key function
3
+ * @param arr
4
+ * @param getKey
5
+ */
6
+ export declare function groupBy<T, TY extends string | number>(arr: T[], getKey: (i: T) => TY): {
7
+ [key in TY]: T[];
8
+ };
9
+ /**
10
+ * group an array of items by the output of a key function
11
+ * @param arr
12
+ * @param getKey
13
+ */
14
+ export declare function groupByList<T, TY>(arr: T[], getKey: (i: T) => TY): {
15
+ key: TY;
16
+ items: T[];
17
+ }[];
18
+ export declare function groupByTwice<T>(arr: T[], getKey: (i: T) => string | number, getSubKey: (i: T) => string | number): {
19
+ [key in string | number]: {
20
+ [a in string | number]: T;
21
+ };
22
+ };
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.groupByTwice = exports.groupByList = exports.groupBy = void 0;
4
+ /**
5
+ * group an array of items by the output of a key function
6
+ * @param arr
7
+ * @param getKey
8
+ */
9
+ function groupBy(arr, getKey) {
10
+ const ret = {};
11
+ arr.forEach((item) => {
12
+ const key = getKey(item);
13
+ if (!ret[key]) {
14
+ ret[key] = [];
15
+ }
16
+ ret[key].push(item);
17
+ });
18
+ return ret;
19
+ }
20
+ exports.groupBy = groupBy;
21
+ /**
22
+ * group an array of items by the output of a key function
23
+ * @param arr
24
+ * @param getKey
25
+ */
26
+ function groupByList(arr, getKey) {
27
+ const ret = [];
28
+ arr.forEach((item) => {
29
+ const key = getKey(item);
30
+ const i = ret.find((r) => r.key === key);
31
+ if (!i) {
32
+ ret.push({ key, items: [item] });
33
+ }
34
+ else {
35
+ i.items.push(item);
36
+ }
37
+ });
38
+ return ret;
39
+ }
40
+ exports.groupByList = groupByList;
41
+ function groupByTwice(arr, getKey, getSubKey) {
42
+ const ret = {};
43
+ arr.forEach((item) => {
44
+ const key = getKey(item);
45
+ const subkey = getSubKey(item);
46
+ if (!ret[key]) {
47
+ ret[key] = {};
48
+ }
49
+ ret[key][subkey] = item;
50
+ });
51
+ return ret;
52
+ }
53
+ exports.groupByTwice = groupByTwice;
@@ -0,0 +1,2 @@
1
+ export declare const hashCode: (str: string, seed?: number) => string;
2
+ export declare const generateNewPK: () => string;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateNewPK = exports.hashCode = void 0;
4
+ /* eslint-disable no-bitwise */
5
+ const hashCode = (str, seed = 0) => {
6
+ if (!str) {
7
+ return '';
8
+ }
9
+ let h1 = 0xdeadbeef ^ seed;
10
+ let h2 = 0x41c6ce57 ^ seed;
11
+ for (let i = 0, ch; i < str.length; i += 1) {
12
+ ch = str.charCodeAt(i);
13
+ h1 = Math.imul(h1 ^ ch, 2654435761);
14
+ h2 = Math.imul(h2 ^ ch, 1597334677);
15
+ }
16
+ h1 =
17
+ Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^
18
+ Math.imul(h2 ^ (h2 >>> 13), 3266489909);
19
+ h2 =
20
+ Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^
21
+ Math.imul(h1 ^ (h1 >>> 13), 3266489909);
22
+ const ret = 4294967296 * (2097151 & h2) + (h1 >>> 0);
23
+ return ret.toString();
24
+ };
25
+ exports.hashCode = hashCode;
26
+ const generateNewPK = () => (0, exports.hashCode)(new Date().getTime().toString());
27
+ exports.generateNewPK = generateNewPK;
@@ -0,0 +1,11 @@
1
+ declare type TLangExceptEn = 'id' | 'vi';
2
+ export declare type TLang = TLangExceptEn | 'en';
3
+ export declare const AllLang: TLang[];
4
+ export declare type TResource = {
5
+ [k in TLangExceptEn]: string | null;
6
+ } & {
7
+ en: string;
8
+ };
9
+ export declare const getValidatedLang: (raw: string) => TLang;
10
+ export declare const t: (res: TResource, lang: TLang) => string;
11
+ export {};
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.t = exports.getValidatedLang = exports.AllLang = void 0;
4
+ exports.AllLang = ['en', 'id', 'vi'];
5
+ const getValidatedLang = (raw) => {
6
+ const f = exports.AllLang.find((l) => l === raw);
7
+ if (!f) {
8
+ return 'en';
9
+ }
10
+ return f;
11
+ };
12
+ exports.getValidatedLang = getValidatedLang;
13
+ const t = (res, lang) => { var _a; return (_a = res[lang]) !== null && _a !== void 0 ? _a : res.en; };
14
+ exports.t = t;
@@ -0,0 +1,12 @@
1
+ export * from './array';
2
+ export * from './distinctBy';
3
+ export * from './email';
4
+ export * from './groupBy';
5
+ export * from './hashCode';
6
+ export * from './i18n';
7
+ export * from './log';
8
+ export * from './math';
9
+ export * from './object';
10
+ export * from './random';
11
+ export * from './secondsInNearest';
12
+ export * from './string';
@@ -0,0 +1,24 @@
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("./array"), exports);
14
+ __exportStar(require("./distinctBy"), exports);
15
+ __exportStar(require("./email"), exports);
16
+ __exportStar(require("./groupBy"), exports);
17
+ __exportStar(require("./hashCode"), exports);
18
+ __exportStar(require("./i18n"), exports);
19
+ __exportStar(require("./log"), exports);
20
+ __exportStar(require("./math"), exports);
21
+ __exportStar(require("./object"), exports);
22
+ __exportStar(require("./random"), exports);
23
+ __exportStar(require("./secondsInNearest"), exports);
24
+ __exportStar(require("./string"), exports);
@@ -0,0 +1,5 @@
1
+ export declare const info: (...args: any[]) => void;
2
+ export declare const warn: (...args: any[]) => void;
3
+ export declare const error: (...args: any[]) => void;
4
+ export declare const debug: (...args: any[]) => void;
5
+ export declare const trace: (...args: any[]) => void;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.trace = exports.debug = exports.error = exports.warn = exports.info = void 0;
4
+ /* eslint-disable @typescript-eslint/no-explicit-any */
5
+ /* eslint-disable no-console */
6
+ const info = (...args) => {
7
+ console.log(...args);
8
+ };
9
+ exports.info = info;
10
+ const warn = (...args) => {
11
+ console.warn(...args);
12
+ };
13
+ exports.warn = warn;
14
+ const error = (...args) => {
15
+ console.error(...args);
16
+ };
17
+ exports.error = error;
18
+ const debug = (...args) => {
19
+ console.debug(...args);
20
+ };
21
+ exports.debug = debug;
22
+ const trace = (...args) => {
23
+ console.trace(...args);
24
+ };
25
+ exports.trace = trace;
@@ -0,0 +1,11 @@
1
+ export declare const toFixed: (num: number, fixed: number) => number;
2
+ export declare function roundToHalf(converted: number): number;
3
+ export declare function clamp({ value, min, max, }: {
4
+ value: number;
5
+ min: number;
6
+ max: number;
7
+ }): number;
8
+ export declare function sumArray(array: number[]): number;
9
+ export declare const getRandomInt: (max: number) => number;
10
+ export declare function isNumber(val: string): boolean;
11
+ export declare function toFixedDown(num: number, scale: number): number;
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toFixedDown = exports.isNumber = exports.getRandomInt = exports.sumArray = exports.clamp = exports.roundToHalf = exports.toFixed = void 0;
4
+ const toFixed = (num, fixed) => {
5
+ var _a, _b;
6
+ const re = new RegExp(`^-?\\d+(?:.\\d{0,${fixed || -1}})?`);
7
+ const x = (_b = (_a = num === null || num === void 0 ? void 0 : num.toString()) === null || _a === void 0 ? void 0 : _a.match(re)) === null || _b === void 0 ? void 0 : _b[0];
8
+ if (!x) {
9
+ return num;
10
+ }
11
+ return Number.parseFloat(x);
12
+ };
13
+ exports.toFixed = toFixed;
14
+ function roundToHalf(converted) {
15
+ let decimal = converted - parseInt(converted.toString(), 10);
16
+ decimal = Math.round(decimal * 10);
17
+ if (decimal === 5) {
18
+ return parseInt(converted.toString(), 10) + 0.5;
19
+ }
20
+ if (decimal < 3 || decimal > 7) {
21
+ return Math.round(converted);
22
+ }
23
+ return parseInt(converted.toString(), 10) + 0.5;
24
+ }
25
+ exports.roundToHalf = roundToHalf;
26
+ function clamp({ value, min, max, }) {
27
+ if (value < min) {
28
+ return min;
29
+ }
30
+ if (value > max) {
31
+ return max;
32
+ }
33
+ return value;
34
+ }
35
+ exports.clamp = clamp;
36
+ function sumArray(array) {
37
+ return array.reduce((a, b) => a + b);
38
+ }
39
+ exports.sumArray = sumArray;
40
+ const getRandomInt = (max) => {
41
+ return Math.floor(Math.random() * Math.floor(max));
42
+ };
43
+ exports.getRandomInt = getRandomInt;
44
+ function isNumber(val) {
45
+ const re = new RegExp(`(\\d+\\.?\\d*)(\\d)`);
46
+ const m = val.toString().match(re);
47
+ return !!m;
48
+ }
49
+ exports.isNumber = isNumber;
50
+ function toFixedDown(num, scale) {
51
+ if (!`${num}`.includes('e')) {
52
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
53
+ // @ts-ignore
54
+ return +`${Math.round(`${num}e+${scale}`)}e-${scale}`;
55
+ }
56
+ const arr = `${num}`.split('e');
57
+ let sig = '';
58
+ if (+arr[1] + scale > 0) {
59
+ sig = '+';
60
+ }
61
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
62
+ // @ts-ignore
63
+ return +`${Math.round(`${+arr[0]}e${sig}${+arr[1] + scale}`)}e-${scale}`;
64
+ }
65
+ exports.toFixedDown = toFixedDown;
@@ -0,0 +1,17 @@
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;
3
+ export declare const objectKeysToLowerCase: <T>(origObj: {
4
+ [a: string]: T;
5
+ }) => {
6
+ [a: string]: T;
7
+ };
8
+ export declare const getObjectKeysAsNumber: (o: {
9
+ [a: number]: unknown;
10
+ }) => number[];
11
+ export interface IArrayType<T> {
12
+ key: string;
13
+ value: T;
14
+ }
15
+ export declare function objectToArray<T>(obj: {
16
+ [a: string]: T;
17
+ }): IArrayType<T>[];