@bisondesk/commons-sdk 1.0.0
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/package.json +17 -0
- package/src/constants.ts +16 -0
- package/src/ids.ts +36 -0
- package/src/types.ts +49 -0
- package/tsconfig.json +12 -0
package/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@bisondesk/commons-sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"scripts": {
|
|
5
|
+
"build": "npx tsc --build",
|
|
6
|
+
"clean": "rm -rf lib *.tsbuildinfo",
|
|
7
|
+
"unittest": "echo \"No test specified\"",
|
|
8
|
+
"integrationtest": "echo \"No test specified\""
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"nanoid": "3.1.22"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@types/nanoid": "2.1.0",
|
|
15
|
+
"typescript": "4.2.3"
|
|
16
|
+
}
|
|
17
|
+
}
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//
|
|
2
|
+
// STATIC ROLES
|
|
3
|
+
//
|
|
4
|
+
export const ADMINS_ROLE = 'admins';
|
|
5
|
+
|
|
6
|
+
//
|
|
7
|
+
// CLOUDFORMATION
|
|
8
|
+
//
|
|
9
|
+
export const INFRA_STACK_NAME = 'infra';
|
|
10
|
+
export const RDS_MASTER_SECRET_ID_OUTPUT_NAME = 'RDSMasterSecretId';
|
|
11
|
+
export const RDS_DEFAULT_SECRET_ID_OUTPUT_NAME = 'RDSSecretId';
|
|
12
|
+
|
|
13
|
+
//
|
|
14
|
+
// I18N
|
|
15
|
+
//
|
|
16
|
+
export const SUPPORTED_LANGUAGES = ['en', 'fr', 'nl'];
|
package/src/ids.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { customAlphabet } from 'nanoid';
|
|
2
|
+
|
|
3
|
+
export enum Alphabet {
|
|
4
|
+
Full = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_',
|
|
5
|
+
Alphanumeric = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',
|
|
6
|
+
Lowercase = 'abcdefghijklmnopqrstuvwxyz',
|
|
7
|
+
LowerAlphanumeric = '0123456789abcdefghijklmnopqrstuvwxyz',
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// The ID can contain only alphabets and numbers and underscore.
|
|
11
|
+
// The ID should start with an alphabet and should not have two consecutive underscores or end with an underscore.
|
|
12
|
+
export const generateId = (idLength: number = 15, alphabet: Alphabet = Alphabet.Full): string => {
|
|
13
|
+
const nanoid = customAlphabet(alphabet, idLength);
|
|
14
|
+
while (true) {
|
|
15
|
+
const id = nanoid();
|
|
16
|
+
if (isValid(id)) {
|
|
17
|
+
return id;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const isValid = (id: string): boolean => {
|
|
23
|
+
if (!Number.isNaN(Number.parseInt(id[0]))) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (id.endsWith('_') || id.startsWith('_')) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (id.includes('__')) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return true;
|
|
36
|
+
};
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export type PaginatedList<T, M = {}> = {
|
|
2
|
+
results: T[];
|
|
3
|
+
totalCount: number;
|
|
4
|
+
meta: M;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
export type Requester = {
|
|
8
|
+
lang: string;
|
|
9
|
+
roles: string[];
|
|
10
|
+
tenantId: string;
|
|
11
|
+
tenantLang: string;
|
|
12
|
+
userAgent?: string;
|
|
13
|
+
sourceIp: string;
|
|
14
|
+
userId: string;
|
|
15
|
+
isApi: boolean;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type Option = {
|
|
19
|
+
value: string | number;
|
|
20
|
+
label: string;
|
|
21
|
+
color?: string;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export enum Region {
|
|
25
|
+
euWest1 = 'eu-west-1',
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type ErrorResponse = {
|
|
29
|
+
message?: string;
|
|
30
|
+
data?: unknown;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type MultiLangValue = { key?: string } & { [languageCode: string]: string };
|
|
34
|
+
|
|
35
|
+
export type CognitoInfo = {
|
|
36
|
+
userPoolId: string;
|
|
37
|
+
appClientId: string;
|
|
38
|
+
region: Region;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export enum SortOrder {
|
|
42
|
+
asc = 'asc',
|
|
43
|
+
desc = 'desc',
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export type SortFilter = {
|
|
47
|
+
fieldId: string;
|
|
48
|
+
order: SortOrder;
|
|
49
|
+
};
|