@adtrackify/at-service-common 1.0.41 → 1.0.42
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
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { User } from '@adtrackify/at-tracking-event-types';
|
|
2
2
|
import * as log from 'lambda-log';
|
|
3
|
+
import { HttpError, HttpStatusCodes } from '../../libs';
|
|
3
4
|
import { ApiResponse } from '../../types/api-response';
|
|
4
5
|
import { axiosHttpService } from '../generic/http-client';
|
|
5
6
|
|
|
@@ -8,6 +9,13 @@ export interface UserResponseData {
|
|
|
8
9
|
[ key: string ]: any;
|
|
9
10
|
}
|
|
10
11
|
|
|
12
|
+
export interface UserSignupRequest {
|
|
13
|
+
email: string,
|
|
14
|
+
password: string,
|
|
15
|
+
givenName: string,
|
|
16
|
+
familyName: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
11
19
|
export class UsersAuthClient {
|
|
12
20
|
|
|
13
21
|
public SERVICE_API_ROOT_URL: string;
|
|
@@ -33,11 +41,55 @@ export class UsersAuthClient {
|
|
|
33
41
|
return axiosHttpService(this.getConfig());
|
|
34
42
|
};
|
|
35
43
|
|
|
36
|
-
|
|
44
|
+
signupAndConfirmUser = async (userSignupRequest: any): Promise<any> => {
|
|
45
|
+
const user = await this.signupUser(userSignupRequest);
|
|
46
|
+
await this.adminConfirmUser(user.email);
|
|
47
|
+
// if fail - delete user and throw error
|
|
48
|
+
return user;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
signupUser = async (userSignupRequest: UserSignupRequest): Promise<any> => {
|
|
52
|
+
log.info('Attempting to signup user', { email: userSignupRequest.email });
|
|
53
|
+
|
|
37
54
|
const client = await this.getClient();
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
55
|
+
const response = await client.post('/signup', userSignupRequest);
|
|
56
|
+
|
|
57
|
+
// Check if Successful or throw error
|
|
58
|
+
if (response.status !== 200 || !response?.data?.user) {
|
|
59
|
+
const message = 'User Signup Failed';
|
|
60
|
+
log.error(message, { response });
|
|
61
|
+
throw new HttpError(HttpStatusCodes.INTERNAL_SERVER_ERROR, message);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
log.info('User Signup Successful', { response });
|
|
65
|
+
return response.data.user;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
//userName is same as user id
|
|
69
|
+
adminConfirmUser = async (userName: string) => {
|
|
70
|
+
//confirm user
|
|
71
|
+
//@TODO update user auth service with admin confirm user endpoint
|
|
72
|
+
log.info('Attempting to admin confirm user', { userName });
|
|
73
|
+
|
|
74
|
+
const client = await this.getClient();
|
|
75
|
+
const response = await client.post('/admin/confirm', {
|
|
76
|
+
headers: {
|
|
77
|
+
'x-api-key': this.USERS_AUTH_API_KEY
|
|
78
|
+
},
|
|
79
|
+
params: {
|
|
80
|
+
userName
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
// Check if Successful or throw error
|
|
85
|
+
if (response.status !== 200) {
|
|
86
|
+
const message = 'Admin User Confirmation Failed';
|
|
87
|
+
log.error(message, { response });
|
|
88
|
+
throw new HttpError(HttpStatusCodes.INTERNAL_SERVER_ERROR, message);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
log.info('Admin User Confirmation Successful', { response });
|
|
92
|
+
return response.data.user;
|
|
41
93
|
};
|
|
42
94
|
|
|
43
95
|
getUserByEmail = async (email: string): Promise<ApiResponse<UserResponseData>> => {
|