@geniehr/utilities 1.0.5
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/apiUtils/api.d.ts +5 -0
- package/dist/apiUtils/api.js +113 -0
- package/dist/apiUtils/httpUtils.d.ts +12 -0
- package/dist/apiUtils/httpUtils.js +106 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +12 -0
- package/dist/logger/LoggerService.d.ts +20 -0
- package/dist/logger/LoggerService.js +121 -0
- package/dist/mq/client.d.ts +57 -0
- package/dist/mq/client.js +143 -0
- package/dist/schema/files/index.d.ts +1 -0
- package/dist/schema/files/index.js +1 -0
- package/dist/schema/files/person/address.d.ts +41 -0
- package/dist/schema/files/person/address.js +15 -0
- package/dist/schema/files/person/emergencyContacts.d.ts +23 -0
- package/dist/schema/files/person/emergencyContacts.js +9 -0
- package/dist/schema/files/person/index.d.ts +7 -0
- package/dist/schema/files/person/index.js +7 -0
- package/dist/schema/files/person/pastExperiences.d.ts +32 -0
- package/dist/schema/files/person/pastExperiences.js +12 -0
- package/dist/schema/files/person/personSchema.d.ts +59 -0
- package/dist/schema/files/person/personSchema.js +21 -0
- package/dist/schema/files/person/primaryContacts.d.ts +23 -0
- package/dist/schema/files/person/primaryContacts.js +9 -0
- package/dist/schema/files/person/qualifications.d.ts +35 -0
- package/dist/schema/files/person/qualifications.js +13 -0
- package/dist/schema/files/person/workDetails.d.ts +53 -0
- package/dist/schema/files/person/workDetails.js +19 -0
- package/dist/schema/index.d.ts +1 -0
- package/dist/schema/index.js +1 -0
- package/dist/schema/schemaMappings.d.ts +2 -0
- package/dist/schema/schemaMappings.js +25 -0
- package/dist/schema/validation.d.ts +2 -0
- package/dist/schema/validation.js +41 -0
- package/dist/secrets/CognitoUserService.d.ts +28 -0
- package/dist/secrets/CognitoUserService.js +121 -0
- package/dist/secrets/aws.d.ts +18 -0
- package/dist/secrets/aws.js +193 -0
- package/dist/shared/context/index.d.ts +6 -0
- package/dist/shared/context/index.js +15 -0
- package/dist/shared/enums/Environments.d.ts +6 -0
- package/dist/shared/enums/Environments.js +7 -0
- package/dist/shared/enums/HttpStatusCodes.d.ts +23 -0
- package/dist/shared/enums/HttpStatusCodes.js +29 -0
- package/dist/shared/exceptions/index.d.ts +13 -0
- package/dist/shared/exceptions/index.js +27 -0
- package/dist/shared/helper/ImageCompressor.d.ts +3 -0
- package/dist/shared/helper/ImageCompressor.js +16 -0
- package/dist/shared/services.d.ts +1 -0
- package/dist/shared/services.js +31 -0
- package/dist/types/GHRContext.d.ts +10 -0
- package/dist/types/GHRContext.js +1 -0
- package/dist/types/logTypes.d.ts +23 -0
- package/dist/types/logTypes.js +1 -0
- package/package.json +55 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const emergencyContactsSchema: z.ZodObject<{
|
|
3
|
+
employeeId: z.ZodNumber;
|
|
4
|
+
name: z.ZodString;
|
|
5
|
+
relationId: z.ZodNumber;
|
|
6
|
+
relationName: z.ZodString;
|
|
7
|
+
mobileNo: z.ZodOptional<z.ZodString>;
|
|
8
|
+
emailAddress: z.ZodOptional<z.ZodString>;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
employeeId: number;
|
|
11
|
+
name: string;
|
|
12
|
+
relationId: number;
|
|
13
|
+
relationName: string;
|
|
14
|
+
mobileNo?: string | undefined;
|
|
15
|
+
emailAddress?: string | undefined;
|
|
16
|
+
}, {
|
|
17
|
+
employeeId: number;
|
|
18
|
+
name: string;
|
|
19
|
+
relationId: number;
|
|
20
|
+
relationName: string;
|
|
21
|
+
mobileNo?: string | undefined;
|
|
22
|
+
emailAddress?: string | undefined;
|
|
23
|
+
}>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export const emergencyContactsSchema = z.object({
|
|
3
|
+
employeeId: z.number().int(),
|
|
4
|
+
name: z.string().trim().min(1).max(100),
|
|
5
|
+
relationId: z.number().int(),
|
|
6
|
+
relationName: z.string().trim().max(100),
|
|
7
|
+
mobileNo: z.string().trim().max(15).optional(),
|
|
8
|
+
emailAddress: z.string().trim().email().max(46).optional()
|
|
9
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const pastExperiencesSchema: z.ZodObject<{
|
|
3
|
+
employeeId: z.ZodNumber;
|
|
4
|
+
company: z.ZodString;
|
|
5
|
+
location: z.ZodOptional<z.ZodString>;
|
|
6
|
+
role: z.ZodString;
|
|
7
|
+
duration: z.ZodOptional<z.ZodString>;
|
|
8
|
+
dateOfJoining: z.ZodOptional<z.ZodDate>;
|
|
9
|
+
dateOfLeaving: z.ZodOptional<z.ZodDate>;
|
|
10
|
+
lastDrawnCTC: z.ZodOptional<z.ZodNumber>;
|
|
11
|
+
reasonForLeaving: z.ZodOptional<z.ZodString>;
|
|
12
|
+
}, "strip", z.ZodTypeAny, {
|
|
13
|
+
employeeId: number;
|
|
14
|
+
company: string;
|
|
15
|
+
role: string;
|
|
16
|
+
dateOfJoining?: Date | undefined;
|
|
17
|
+
location?: string | undefined;
|
|
18
|
+
duration?: string | undefined;
|
|
19
|
+
dateOfLeaving?: Date | undefined;
|
|
20
|
+
lastDrawnCTC?: number | undefined;
|
|
21
|
+
reasonForLeaving?: string | undefined;
|
|
22
|
+
}, {
|
|
23
|
+
employeeId: number;
|
|
24
|
+
company: string;
|
|
25
|
+
role: string;
|
|
26
|
+
dateOfJoining?: Date | undefined;
|
|
27
|
+
location?: string | undefined;
|
|
28
|
+
duration?: string | undefined;
|
|
29
|
+
dateOfLeaving?: Date | undefined;
|
|
30
|
+
lastDrawnCTC?: number | undefined;
|
|
31
|
+
reasonForLeaving?: string | undefined;
|
|
32
|
+
}>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const pastExperiencesSchema = z.object({
|
|
3
|
+
employeeId: z.number().int(),
|
|
4
|
+
company: z.string().trim().min(1).max(100),
|
|
5
|
+
location: z.string().trim().max(100).optional(),
|
|
6
|
+
role: z.string().trim().min(1).max(100),
|
|
7
|
+
duration: z.string().trim().max(50).optional(),
|
|
8
|
+
dateOfJoining: z.coerce.date().optional(),
|
|
9
|
+
dateOfLeaving: z.coerce.date().optional(),
|
|
10
|
+
lastDrawnCTC: z.coerce.number().optional(),
|
|
11
|
+
reasonForLeaving: z.string().trim().optional()
|
|
12
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const personSchema: z.ZodObject<{
|
|
3
|
+
firstName: z.ZodString;
|
|
4
|
+
middleName: z.ZodOptional<z.ZodString>;
|
|
5
|
+
lastName: z.ZodOptional<z.ZodString>;
|
|
6
|
+
dateOfBirth: z.ZodOptional<z.ZodDate>;
|
|
7
|
+
genderId: z.ZodOptional<z.ZodNumber>;
|
|
8
|
+
genderName: z.ZodOptional<z.ZodString>;
|
|
9
|
+
bloodGroupId: z.ZodOptional<z.ZodNumber>;
|
|
10
|
+
bloodGroupName: z.ZodOptional<z.ZodString>;
|
|
11
|
+
maritalStatus: z.ZodOptional<z.ZodString>;
|
|
12
|
+
maritalStatusId: z.ZodOptional<z.ZodNumber>;
|
|
13
|
+
mobileNo: z.ZodOptional<z.ZodString>;
|
|
14
|
+
emailAddress: z.ZodOptional<z.ZodString>;
|
|
15
|
+
about: z.ZodOptional<z.ZodString>;
|
|
16
|
+
iamId: z.ZodOptional<z.ZodString>;
|
|
17
|
+
employeeNo: z.ZodOptional<z.ZodString>;
|
|
18
|
+
ghrId: z.ZodNumber;
|
|
19
|
+
personTypeId: z.ZodNumber;
|
|
20
|
+
personTypeName: z.ZodString;
|
|
21
|
+
}, "strip", z.ZodTypeAny, {
|
|
22
|
+
firstName: string;
|
|
23
|
+
ghrId: number;
|
|
24
|
+
personTypeId: number;
|
|
25
|
+
personTypeName: string;
|
|
26
|
+
middleName?: string | undefined;
|
|
27
|
+
lastName?: string | undefined;
|
|
28
|
+
dateOfBirth?: Date | undefined;
|
|
29
|
+
genderId?: number | undefined;
|
|
30
|
+
genderName?: string | undefined;
|
|
31
|
+
bloodGroupId?: number | undefined;
|
|
32
|
+
bloodGroupName?: string | undefined;
|
|
33
|
+
maritalStatus?: string | undefined;
|
|
34
|
+
maritalStatusId?: number | undefined;
|
|
35
|
+
mobileNo?: string | undefined;
|
|
36
|
+
emailAddress?: string | undefined;
|
|
37
|
+
about?: string | undefined;
|
|
38
|
+
iamId?: string | undefined;
|
|
39
|
+
employeeNo?: string | undefined;
|
|
40
|
+
}, {
|
|
41
|
+
firstName: string;
|
|
42
|
+
ghrId: number;
|
|
43
|
+
personTypeId: number;
|
|
44
|
+
personTypeName: string;
|
|
45
|
+
middleName?: string | undefined;
|
|
46
|
+
lastName?: string | undefined;
|
|
47
|
+
dateOfBirth?: Date | undefined;
|
|
48
|
+
genderId?: number | undefined;
|
|
49
|
+
genderName?: string | undefined;
|
|
50
|
+
bloodGroupId?: number | undefined;
|
|
51
|
+
bloodGroupName?: string | undefined;
|
|
52
|
+
maritalStatus?: string | undefined;
|
|
53
|
+
maritalStatusId?: number | undefined;
|
|
54
|
+
mobileNo?: string | undefined;
|
|
55
|
+
emailAddress?: string | undefined;
|
|
56
|
+
about?: string | undefined;
|
|
57
|
+
iamId?: string | undefined;
|
|
58
|
+
employeeNo?: string | undefined;
|
|
59
|
+
}>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export const personSchema = z.object({
|
|
3
|
+
firstName: z.string().trim().min(1).max(45),
|
|
4
|
+
middleName: z.string().trim().max(45).optional(),
|
|
5
|
+
lastName: z.string().trim().max(45).optional(),
|
|
6
|
+
dateOfBirth: z.coerce.date().optional(),
|
|
7
|
+
genderId: z.number().int().optional(),
|
|
8
|
+
genderName: z.string().trim().max(100).optional(),
|
|
9
|
+
bloodGroupId: z.number().int().optional(),
|
|
10
|
+
bloodGroupName: z.string().trim().max(100).optional(),
|
|
11
|
+
maritalStatus: z.string().trim().max(20).optional(),
|
|
12
|
+
maritalStatusId: z.number().int().optional(),
|
|
13
|
+
mobileNo: z.string().trim().max(15).optional(),
|
|
14
|
+
emailAddress: z.string().trim().email().max(46).optional(),
|
|
15
|
+
about: z.string().trim().optional(),
|
|
16
|
+
iamId: z.string().trim().max(50).optional(),
|
|
17
|
+
employeeNo: z.string().trim().max(45).optional(),
|
|
18
|
+
ghrId: z.number().int(),
|
|
19
|
+
personTypeId: z.number().int(),
|
|
20
|
+
personTypeName: z.string().trim().max(100)
|
|
21
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const primaryContactsSchema: z.ZodObject<{
|
|
3
|
+
employeeId: z.ZodNumber;
|
|
4
|
+
name: z.ZodString;
|
|
5
|
+
relationId: z.ZodNumber;
|
|
6
|
+
relationName: z.ZodString;
|
|
7
|
+
mobileNo: z.ZodOptional<z.ZodString>;
|
|
8
|
+
emailAddress: z.ZodOptional<z.ZodString>;
|
|
9
|
+
}, "strip", z.ZodTypeAny, {
|
|
10
|
+
employeeId: number;
|
|
11
|
+
name: string;
|
|
12
|
+
relationId: number;
|
|
13
|
+
relationName: string;
|
|
14
|
+
mobileNo?: string | undefined;
|
|
15
|
+
emailAddress?: string | undefined;
|
|
16
|
+
}, {
|
|
17
|
+
employeeId: number;
|
|
18
|
+
name: string;
|
|
19
|
+
relationId: number;
|
|
20
|
+
relationName: string;
|
|
21
|
+
mobileNo?: string | undefined;
|
|
22
|
+
emailAddress?: string | undefined;
|
|
23
|
+
}>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const primaryContactsSchema = z.object({
|
|
3
|
+
employeeId: z.number().int(),
|
|
4
|
+
name: z.string().trim().min(1).max(100),
|
|
5
|
+
relationId: z.number().int(),
|
|
6
|
+
relationName: z.string().trim().max(100),
|
|
7
|
+
mobileNo: z.string().trim().max(15).optional(),
|
|
8
|
+
emailAddress: z.string().trim().email().max(46).optional()
|
|
9
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const qualificationsSchema: z.ZodObject<{
|
|
3
|
+
employeeId: z.ZodNumber;
|
|
4
|
+
institution: z.ZodString;
|
|
5
|
+
year: z.ZodNumber;
|
|
6
|
+
percentage: z.ZodNumber;
|
|
7
|
+
courseId: z.ZodNumber;
|
|
8
|
+
specializationId: z.ZodNumber;
|
|
9
|
+
courseName: z.ZodString;
|
|
10
|
+
specializationName: z.ZodString;
|
|
11
|
+
qualification: z.ZodOptional<z.ZodString>;
|
|
12
|
+
qualificationId: z.ZodOptional<z.ZodNumber>;
|
|
13
|
+
}, "strip", z.ZodTypeAny, {
|
|
14
|
+
employeeId: number;
|
|
15
|
+
institution: string;
|
|
16
|
+
year: number;
|
|
17
|
+
percentage: number;
|
|
18
|
+
courseId: number;
|
|
19
|
+
specializationId: number;
|
|
20
|
+
courseName: string;
|
|
21
|
+
specializationName: string;
|
|
22
|
+
qualification?: string | undefined;
|
|
23
|
+
qualificationId?: number | undefined;
|
|
24
|
+
}, {
|
|
25
|
+
employeeId: number;
|
|
26
|
+
institution: string;
|
|
27
|
+
year: number;
|
|
28
|
+
percentage: number;
|
|
29
|
+
courseId: number;
|
|
30
|
+
specializationId: number;
|
|
31
|
+
courseName: string;
|
|
32
|
+
specializationName: string;
|
|
33
|
+
qualification?: string | undefined;
|
|
34
|
+
qualificationId?: number | undefined;
|
|
35
|
+
}>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export const qualificationsSchema = z.object({
|
|
3
|
+
employeeId: z.number().int(),
|
|
4
|
+
institution: z.string().trim().min(1).max(150),
|
|
5
|
+
year: z.number().int(),
|
|
6
|
+
percentage: z.number(),
|
|
7
|
+
courseId: z.number().int(),
|
|
8
|
+
specializationId: z.number().int(),
|
|
9
|
+
courseName: z.string().trim().min(1).max(100),
|
|
10
|
+
specializationName: z.string().trim().min(1).max(100),
|
|
11
|
+
qualification: z.string().trim().max(100).optional(),
|
|
12
|
+
qualificationId: z.number().int().optional()
|
|
13
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const workDetailsSchema: z.ZodObject<{
|
|
3
|
+
employeeId: z.ZodNumber;
|
|
4
|
+
departmentId: z.ZodNumber;
|
|
5
|
+
designationId: z.ZodNumber;
|
|
6
|
+
dateOfJoining: z.ZodOptional<z.ZodDate>;
|
|
7
|
+
location: z.ZodString;
|
|
8
|
+
managerId: z.ZodOptional<z.ZodNumber>;
|
|
9
|
+
departmentName: z.ZodString;
|
|
10
|
+
designationName: z.ZodString;
|
|
11
|
+
managerName: z.ZodString;
|
|
12
|
+
functionalArea: z.ZodOptional<z.ZodString>;
|
|
13
|
+
functionalAreaId: z.ZodOptional<z.ZodNumber>;
|
|
14
|
+
industry: z.ZodOptional<z.ZodString>;
|
|
15
|
+
industryId: z.ZodOptional<z.ZodNumber>;
|
|
16
|
+
hrSpoc: z.ZodOptional<z.ZodString>;
|
|
17
|
+
employeeSkills: z.ZodOptional<z.ZodString>;
|
|
18
|
+
organization: z.ZodOptional<z.ZodString>;
|
|
19
|
+
}, "strip", z.ZodTypeAny, {
|
|
20
|
+
employeeId: number;
|
|
21
|
+
departmentId: number;
|
|
22
|
+
designationId: number;
|
|
23
|
+
location: string;
|
|
24
|
+
departmentName: string;
|
|
25
|
+
designationName: string;
|
|
26
|
+
managerName: string;
|
|
27
|
+
dateOfJoining?: Date | undefined;
|
|
28
|
+
managerId?: number | undefined;
|
|
29
|
+
functionalArea?: string | undefined;
|
|
30
|
+
functionalAreaId?: number | undefined;
|
|
31
|
+
industry?: string | undefined;
|
|
32
|
+
industryId?: number | undefined;
|
|
33
|
+
hrSpoc?: string | undefined;
|
|
34
|
+
employeeSkills?: string | undefined;
|
|
35
|
+
organization?: string | undefined;
|
|
36
|
+
}, {
|
|
37
|
+
employeeId: number;
|
|
38
|
+
departmentId: number;
|
|
39
|
+
designationId: number;
|
|
40
|
+
location: string;
|
|
41
|
+
departmentName: string;
|
|
42
|
+
designationName: string;
|
|
43
|
+
managerName: string;
|
|
44
|
+
dateOfJoining?: Date | undefined;
|
|
45
|
+
managerId?: number | undefined;
|
|
46
|
+
functionalArea?: string | undefined;
|
|
47
|
+
functionalAreaId?: number | undefined;
|
|
48
|
+
industry?: string | undefined;
|
|
49
|
+
industryId?: number | undefined;
|
|
50
|
+
hrSpoc?: string | undefined;
|
|
51
|
+
employeeSkills?: string | undefined;
|
|
52
|
+
organization?: string | undefined;
|
|
53
|
+
}>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export const workDetailsSchema = z.object({
|
|
3
|
+
employeeId: z.number().int(),
|
|
4
|
+
departmentId: z.number().int(),
|
|
5
|
+
designationId: z.number().int(),
|
|
6
|
+
dateOfJoining: z.coerce.date().optional(),
|
|
7
|
+
location: z.string().trim().max(100),
|
|
8
|
+
managerId: z.number().int().optional(),
|
|
9
|
+
departmentName: z.string().trim().max(100),
|
|
10
|
+
designationName: z.string().trim().max(100),
|
|
11
|
+
managerName: z.string().trim().max(100),
|
|
12
|
+
functionalArea: z.string().trim().max(200).optional(),
|
|
13
|
+
functionalAreaId: z.number().int().optional(),
|
|
14
|
+
industry: z.string().trim().max(100).optional(),
|
|
15
|
+
industryId: z.number().int().optional(),
|
|
16
|
+
hrSpoc: z.string().trim().max(100).optional(),
|
|
17
|
+
employeeSkills: z.string().trim().optional(),
|
|
18
|
+
organization: z.string().trim().max(100).optional()
|
|
19
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { validateRequest } from './validation.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { validateRequest } from './validation.js';
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { emergencyContactsSchema, pastExperiencesSchema, personSchema, primaryContactsSchema, qualificationsSchema, workDetailsSchema, addressSchema } from './files/index.js';
|
|
2
|
+
export const mappings = {
|
|
3
|
+
'people-ms': {
|
|
4
|
+
'post': {
|
|
5
|
+
'/people/person/profile': personSchema,
|
|
6
|
+
'/people/work/details': workDetailsSchema,
|
|
7
|
+
'/people/work/past-experience': pastExperiencesSchema,
|
|
8
|
+
'/people/contacts/primary': primaryContactsSchema,
|
|
9
|
+
'/people/contacts/emergency': emergencyContactsSchema,
|
|
10
|
+
'/people/education/qualification': qualificationsSchema,
|
|
11
|
+
'/people/person/address': addressSchema
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
'bff-ms': {
|
|
15
|
+
'post': {
|
|
16
|
+
'/api/employee/profile': personSchema,
|
|
17
|
+
'/api/employee/work/details': workDetailsSchema,
|
|
18
|
+
'/api/employee/work/past-experience': pastExperiencesSchema,
|
|
19
|
+
'/api/employee/contacts/primary': primaryContactsSchema,
|
|
20
|
+
'/api/employee/contacts/emergency': emergencyContactsSchema,
|
|
21
|
+
'/api/employee/education/qualification': qualificationsSchema,
|
|
22
|
+
'/api/employee/address': addressSchema
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { generateErrorMessage } from 'zod-error';
|
|
2
|
+
import { getContext } from '../shared/context/index.js';
|
|
3
|
+
import { mappings } from './schemaMappings.js';
|
|
4
|
+
import { sendResponse } from '../apiUtils/api.js';
|
|
5
|
+
import { HttpStatusCode } from '../shared/enums/HttpStatusCodes.js';
|
|
6
|
+
import { InvalidRequestException } from '../shared/exceptions/index.js';
|
|
7
|
+
const options = {
|
|
8
|
+
transform: (errorComponent) => `${errorComponent.issue.message} for ${errorComponent.issue.path.join('.')}`,
|
|
9
|
+
};
|
|
10
|
+
export const validateRequest = (req, res, next) => {
|
|
11
|
+
const schema = getSchema(req, res);
|
|
12
|
+
const service = getContext().service || '';
|
|
13
|
+
if (!schema) {
|
|
14
|
+
next();
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
const result = schema.safeParse(req.body);
|
|
18
|
+
if (!result.success) {
|
|
19
|
+
const errorMessage = generateErrorMessage(result.error.issues, options);
|
|
20
|
+
sendResponse(req, res, HttpStatusCode.BAD_REQUEST, null, new InvalidRequestException(errorMessage.split("|"), "E-INVALID-REQUEST", {
|
|
21
|
+
service,
|
|
22
|
+
request: req.body,
|
|
23
|
+
params: req.params,
|
|
24
|
+
query: req.query,
|
|
25
|
+
path: req.originalUrl.split('?')[0],
|
|
26
|
+
method: req.method,
|
|
27
|
+
correlationId: res.getHeader('x-correlation-id')
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
next();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const getSchema = ((req, res) => {
|
|
36
|
+
const fullPath = req.originalUrl.split('?')[0];
|
|
37
|
+
const method = req.method.toLowerCase();
|
|
38
|
+
const service = getContext().service || '';
|
|
39
|
+
const schema = mappings?.[service]?.[method]?.[fullPath];
|
|
40
|
+
return schema;
|
|
41
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export declare class CognitoUserService {
|
|
2
|
+
private client;
|
|
3
|
+
private userPoolId;
|
|
4
|
+
constructor(userPoolId: string);
|
|
5
|
+
/**
|
|
6
|
+
* Get user info from Cognito by username (email)
|
|
7
|
+
*/
|
|
8
|
+
getUserInfo(email: string): Promise<{
|
|
9
|
+
username: string | undefined;
|
|
10
|
+
enabled: boolean | undefined;
|
|
11
|
+
userStatus: import("@aws-sdk/client-cognito-identity-provider").UserStatusType | undefined;
|
|
12
|
+
userCreateDate: Date | undefined;
|
|
13
|
+
userLastModifiedDate: Date | undefined;
|
|
14
|
+
attributes: Record<string, string>;
|
|
15
|
+
}>;
|
|
16
|
+
/**
|
|
17
|
+
* Create a new Cognito user
|
|
18
|
+
*/
|
|
19
|
+
createUser(email: string, tempPassword: string, userAttributes?: Record<string, string>): Promise<import("@aws-sdk/client-cognito-identity-provider").AdminCreateUserCommandOutput>;
|
|
20
|
+
/**
|
|
21
|
+
* Update user attributes (like name, phone_number, etc.)
|
|
22
|
+
*/
|
|
23
|
+
updateUserAttributes(email: string, attributes: Record<string, string>): Promise<import("@aws-sdk/client-cognito-identity-provider").AdminUpdateUserAttributesCommandOutput>;
|
|
24
|
+
deleteUser(username: string): Promise<{
|
|
25
|
+
message: string;
|
|
26
|
+
response: import("@aws-sdk/client-cognito-identity-provider").AdminDeleteUserCommandOutput;
|
|
27
|
+
}>;
|
|
28
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { CognitoIdentityProviderClient, AdminCreateUserCommand, AdminUpdateUserAttributesCommand, AdminGetUserCommand, AdminDeleteUserCommand } from "@aws-sdk/client-cognito-identity-provider";
|
|
2
|
+
import { fromIni } from "@aws-sdk/credential-providers";
|
|
3
|
+
export class CognitoUserService {
|
|
4
|
+
client;
|
|
5
|
+
userPoolId;
|
|
6
|
+
constructor(userPoolId) {
|
|
7
|
+
this.userPoolId = userPoolId;
|
|
8
|
+
this.client = new CognitoIdentityProviderClient({
|
|
9
|
+
region: "ap-south-1",
|
|
10
|
+
credentials: process.env.NODE_ENV === "local" ? fromIni({ profile: "ghr-aws-dev-profile" }) : undefined
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Get user info from Cognito by username (email)
|
|
15
|
+
*/
|
|
16
|
+
async getUserInfo(email) {
|
|
17
|
+
try {
|
|
18
|
+
const params = {
|
|
19
|
+
UserPoolId: this.userPoolId,
|
|
20
|
+
Username: email,
|
|
21
|
+
};
|
|
22
|
+
const command = new AdminGetUserCommand(params);
|
|
23
|
+
const response = await this.client.send(command);
|
|
24
|
+
// Safely format attributes into key-value object
|
|
25
|
+
const attributes = response.UserAttributes?.reduce((acc, attr) => {
|
|
26
|
+
if (attr.Name) {
|
|
27
|
+
acc[attr.Name] = attr.Value ?? "";
|
|
28
|
+
}
|
|
29
|
+
return acc;
|
|
30
|
+
}, {}) || {};
|
|
31
|
+
return {
|
|
32
|
+
username: response.Username,
|
|
33
|
+
enabled: response.Enabled,
|
|
34
|
+
userStatus: response.UserStatus,
|
|
35
|
+
userCreateDate: response.UserCreateDate,
|
|
36
|
+
userLastModifiedDate: response.UserLastModifiedDate,
|
|
37
|
+
attributes,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
console.error("Error fetching Cognito user info:", error);
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Create a new Cognito user
|
|
47
|
+
*/
|
|
48
|
+
async createUser(email, tempPassword, userAttributes = {}) {
|
|
49
|
+
try {
|
|
50
|
+
const params = {
|
|
51
|
+
UserPoolId: this.userPoolId,
|
|
52
|
+
Username: email,
|
|
53
|
+
TemporaryPassword: tempPassword,
|
|
54
|
+
UserAttributes: Object.entries(userAttributes).map(([Name, Value]) => ({ Name, Value })),
|
|
55
|
+
MessageAction: "SUPPRESS", // Avoid sending default Cognito email
|
|
56
|
+
};
|
|
57
|
+
const command = new AdminCreateUserCommand(params);
|
|
58
|
+
const response = await this.client.send(command);
|
|
59
|
+
return response;
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
console.error("Error creating Cognito user:", error);
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Update user attributes (like name, phone_number, etc.)
|
|
68
|
+
*/
|
|
69
|
+
async updateUserAttributes(email, attributes) {
|
|
70
|
+
try {
|
|
71
|
+
const params = {
|
|
72
|
+
UserPoolId: this.userPoolId,
|
|
73
|
+
Username: email,
|
|
74
|
+
UserAttributes: Object.entries(attributes).map(([Name, Value]) => ({ Name, Value })),
|
|
75
|
+
};
|
|
76
|
+
const command = new AdminUpdateUserAttributesCommand(params);
|
|
77
|
+
const response = await this.client.send(command);
|
|
78
|
+
return response;
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
console.error("Error updating Cognito user attributes:", error);
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
async deleteUser(username) {
|
|
86
|
+
try {
|
|
87
|
+
const params = {
|
|
88
|
+
UserPoolId: this.userPoolId,
|
|
89
|
+
Username: username,
|
|
90
|
+
};
|
|
91
|
+
const command = new AdminDeleteUserCommand(params);
|
|
92
|
+
const response = await this.client.send(command);
|
|
93
|
+
return {
|
|
94
|
+
message: `User '${username}' deleted successfully`,
|
|
95
|
+
response,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
catch (error) {
|
|
99
|
+
console.error("Error deleting Cognito user:", error);
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/*
|
|
105
|
+
(async () => {
|
|
106
|
+
const userPoolId = "ap-south-1_examplePoolId"; // replace with your actual Cognito User Pool ID
|
|
107
|
+
const cognitoService = new CognitoUserService(userPoolId);
|
|
108
|
+
|
|
109
|
+
// Create user
|
|
110
|
+
await cognitoService.createUser("user@example.com", "Temp@123", {
|
|
111
|
+
email: "user@example.com",
|
|
112
|
+
name: "Deepak Parab",
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// Update user
|
|
116
|
+
await cognitoService.updateUserAttributes("user@example.com", {
|
|
117
|
+
name: "Deepak P.",
|
|
118
|
+
phone_number: "+919999999999",
|
|
119
|
+
});
|
|
120
|
+
})();
|
|
121
|
+
*/
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fetch a single parameter or all parameters under a prefix.
|
|
3
|
+
* @param nameOrPrefix Full name (e.g. /dev/mysql/person) or prefix (e.g. /dev/mysql/)
|
|
4
|
+
*/
|
|
5
|
+
export declare function getAWSParameters(nameOrPrefix: string): Promise<Record<string, string>>;
|
|
6
|
+
export declare function matchFace(imageInBase64: string): Promise<import("@aws-sdk/client-rekognition").SearchFacesByImageCommandOutput>;
|
|
7
|
+
export declare function registerFace(employeeId: string, imageInBase64: string): Promise<import("@aws-sdk/client-rekognition").IndexFacesCommandOutput>;
|
|
8
|
+
export declare function generatePresignedUrl(entity: string, fileName: string, bucketName: string, idToken: string, action: 'put' | 'get', expiresIn?: number): Promise<string>;
|
|
9
|
+
export declare function executeS3Action(action: "put" | "get", bucketName: string, key: string, body?: Buffer, contentType?: string): Promise<import("@aws-sdk/client-s3").PutObjectCommandOutput>;
|
|
10
|
+
export declare function updateCustomAttribute(username: string, userPoolId: string, attributeName: string, attributeValue: string): Promise<{
|
|
11
|
+
success: boolean;
|
|
12
|
+
message: string;
|
|
13
|
+
}>;
|
|
14
|
+
export declare function getCustomAttribute(username: string, userPoolId: string, attributeName: string): Promise<{
|
|
15
|
+
success: boolean;
|
|
16
|
+
value?: string;
|
|
17
|
+
message: string;
|
|
18
|
+
}>;
|