@adtrackify/at-service-common 1.0.67 → 1.0.69
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/bitbucket-pipelines.yml +20 -20
- package/dist/index.d.ts +5 -0
- package/dist/index.js +7 -1
- package/dist/index.js.map +2 -2
- package/jest.config.ts +40 -40
- package/package.json +1 -1
- package/src/__tests__/helpers/subscription-helper.spec.ts +40 -40
- package/src/clients/internal-api/accounts-client.ts +13 -1
- package/src/clients/internal-api/index.ts +4 -4
- package/src/clients/internal-api/shopify-app-install-client.ts +59 -59
- package/src/clients/internal-api/users-auth-client.ts +111 -111
- package/src/helpers/index.ts +5 -5
- package/src/index.ts +4 -4
- package/src/libs/http-error.ts +99 -99
- package/src/services/eventbridge-integration-service.ts +44 -44
- package/tsconfig.json +35 -35
package/jest.config.ts
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
/*eslint-disable */
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
globals: {
|
|
5
|
-
'ts-jest': {
|
|
6
|
-
isolatedModules: true
|
|
7
|
-
},
|
|
8
|
-
'@swc/jest': {
|
|
9
|
-
isolatedModules: true
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
},
|
|
13
|
-
roots: [ '<rootDir>/src' ],
|
|
14
|
-
testRegex: '\\.spec\\.(js|ts)$',
|
|
15
|
-
transform: {
|
|
16
|
-
"^.+\\.(t|j)sx?$": [ "@swc/jest" ],
|
|
17
|
-
},
|
|
18
|
-
moduleFileExtensions: [ 'js', 'json', 'ts' ],
|
|
19
|
-
transformIgnorePatterns: [],
|
|
20
|
-
runner: 'groups',
|
|
21
|
-
verbose: false,
|
|
22
|
-
coverageThreshold: {
|
|
23
|
-
global: {
|
|
24
|
-
branches: 0,
|
|
25
|
-
functions: 0,
|
|
26
|
-
lines: 0,
|
|
27
|
-
statements: 0
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
coverageReporters: [ 'html', 'text', 'text-summary', 'cobertura' ],
|
|
31
|
-
reporters: [ 'default', 'jest-junit' ],
|
|
32
|
-
collectCoverageFrom: [
|
|
33
|
-
'src/**/*.ts',
|
|
34
|
-
'!src/**/*.spec.js',
|
|
35
|
-
'src/**/*.js',
|
|
36
|
-
'!src/**/*.spec.ts',
|
|
37
|
-
'!src/**/tests/**'
|
|
38
|
-
],
|
|
39
|
-
setupFilesAfterEnv: [],
|
|
40
|
-
};
|
|
1
|
+
/*eslint-disable */
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
globals: {
|
|
5
|
+
'ts-jest': {
|
|
6
|
+
isolatedModules: true
|
|
7
|
+
},
|
|
8
|
+
'@swc/jest': {
|
|
9
|
+
isolatedModules: true
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
},
|
|
13
|
+
roots: [ '<rootDir>/src' ],
|
|
14
|
+
testRegex: '\\.spec\\.(js|ts)$',
|
|
15
|
+
transform: {
|
|
16
|
+
"^.+\\.(t|j)sx?$": [ "@swc/jest" ],
|
|
17
|
+
},
|
|
18
|
+
moduleFileExtensions: [ 'js', 'json', 'ts' ],
|
|
19
|
+
transformIgnorePatterns: [],
|
|
20
|
+
runner: 'groups',
|
|
21
|
+
verbose: false,
|
|
22
|
+
coverageThreshold: {
|
|
23
|
+
global: {
|
|
24
|
+
branches: 0,
|
|
25
|
+
functions: 0,
|
|
26
|
+
lines: 0,
|
|
27
|
+
statements: 0
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
coverageReporters: [ 'html', 'text', 'text-summary', 'cobertura' ],
|
|
31
|
+
reporters: [ 'default', 'jest-junit' ],
|
|
32
|
+
collectCoverageFrom: [
|
|
33
|
+
'src/**/*.ts',
|
|
34
|
+
'!src/**/*.spec.js',
|
|
35
|
+
'src/**/*.js',
|
|
36
|
+
'!src/**/*.spec.ts',
|
|
37
|
+
'!src/**/tests/**'
|
|
38
|
+
],
|
|
39
|
+
setupFilesAfterEnv: [],
|
|
40
|
+
};
|
|
41
41
|
/*eslint-enable */
|
package/package.json
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* @group unit
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/* eslint-disable */
|
|
7
|
-
|
|
8
|
-
jest.mock('lambda-log');
|
|
9
|
-
import * as Logger from 'lambda-log';
|
|
10
|
-
import { getPlanDetails } from '../../helpers';
|
|
11
|
-
|
|
12
|
-
describe('postmark service email test', () => {
|
|
13
|
-
jest.spyOn(Logger, 'warn').mockImplementation(() => {
|
|
14
|
-
return new Logger.LogMessage({ level: 'null', msg: 'null' }, {});
|
|
15
|
-
});
|
|
16
|
-
jest.spyOn(Logger, 'info').mockImplementation(() => {
|
|
17
|
-
return new Logger.LogMessage({ level: 'null', msg: 'null' }, {});
|
|
18
|
-
});
|
|
19
|
-
jest.spyOn(Logger, 'debug').mockImplementation(() => {
|
|
20
|
-
return new Logger.LogMessage({ level: 'null', msg: 'null' }, {});
|
|
21
|
-
});
|
|
22
|
-
jest.spyOn(Logger, 'error').mockImplementation(() => {
|
|
23
|
-
return new Logger.LogMessage({ level: 'null', msg: 'null' }, {});
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
beforeEach(async () => {
|
|
27
|
-
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
afterEach(() => {
|
|
31
|
-
jest.resetAllMocks();
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
it('should call send email message', async () => {
|
|
36
|
-
const plan = getPlanDetails(2, 'dev');
|
|
37
|
-
console.log(plan);
|
|
38
|
-
expect(plan).not.toEqual(null);
|
|
39
|
-
});
|
|
40
|
-
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @group unit
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/* eslint-disable */
|
|
7
|
+
|
|
8
|
+
jest.mock('lambda-log');
|
|
9
|
+
import * as Logger from 'lambda-log';
|
|
10
|
+
import { getPlanDetails } from '../../helpers';
|
|
11
|
+
|
|
12
|
+
describe('postmark service email test', () => {
|
|
13
|
+
jest.spyOn(Logger, 'warn').mockImplementation(() => {
|
|
14
|
+
return new Logger.LogMessage({ level: 'null', msg: 'null' }, {});
|
|
15
|
+
});
|
|
16
|
+
jest.spyOn(Logger, 'info').mockImplementation(() => {
|
|
17
|
+
return new Logger.LogMessage({ level: 'null', msg: 'null' }, {});
|
|
18
|
+
});
|
|
19
|
+
jest.spyOn(Logger, 'debug').mockImplementation(() => {
|
|
20
|
+
return new Logger.LogMessage({ level: 'null', msg: 'null' }, {});
|
|
21
|
+
});
|
|
22
|
+
jest.spyOn(Logger, 'error').mockImplementation(() => {
|
|
23
|
+
return new Logger.LogMessage({ level: 'null', msg: 'null' }, {});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
beforeEach(async () => {
|
|
27
|
+
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
afterEach(() => {
|
|
31
|
+
jest.resetAllMocks();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
it('should call send email message', async () => {
|
|
36
|
+
const plan = getPlanDetails(2, 'dev');
|
|
37
|
+
console.log(plan);
|
|
38
|
+
expect(plan).not.toEqual(null);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
41
|
});
|
|
@@ -22,6 +22,10 @@ export interface PixelConfigResponseData {
|
|
|
22
22
|
destinations: Destination[];
|
|
23
23
|
[ key: string ]: any;
|
|
24
24
|
}
|
|
25
|
+
export interface AddUserToAccountResponseData {
|
|
26
|
+
userId: string;
|
|
27
|
+
accountId: string;
|
|
28
|
+
}
|
|
25
29
|
|
|
26
30
|
export interface UpdateAccountRequest {
|
|
27
31
|
accountName?: string,
|
|
@@ -96,7 +100,7 @@ export class AccountsClient {
|
|
|
96
100
|
getPixelConfigById = async (pixelId: string): Promise<ApiResponse<PixelConfigResponseData>> => {
|
|
97
101
|
const client = await this.getClient();
|
|
98
102
|
const pixelResponse = await client.get(`/px/${pixelId}/config`);
|
|
99
|
-
log.debug('pixelResponse', { pixelResponse });
|
|
103
|
+
log.debug('get pixelResponse', { pixelResponse });
|
|
100
104
|
return pixelResponse;
|
|
101
105
|
};
|
|
102
106
|
getAccount = async (accountId: string): Promise<ApiResponse<AccountResponseData>> => {
|
|
@@ -105,6 +109,14 @@ export class AccountsClient {
|
|
|
105
109
|
log.info('get account response', { response });
|
|
106
110
|
return response as ApiResponse<AccountResponseData>;
|
|
107
111
|
};
|
|
112
|
+
addUserToAccount = async (accountId: string, userId: string): Promise<ApiResponse<AddUserToAccountResponseData>> => {
|
|
113
|
+
const client = await this.getClient();
|
|
114
|
+
const response = await client.post('/addUser', { accountId, userId });
|
|
115
|
+
log.info('add user account response', { response });
|
|
116
|
+
return response as ApiResponse<AddUserToAccountResponseData>;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
|
|
108
120
|
// setAccountSubscriptionId = async (accountId: string, subscriptionId: string): Promise<ApiResponse<any>> => {
|
|
109
121
|
// const client = await this.getClient();
|
|
110
122
|
// const pixelResponse = await client.get(`/px/${pixelId}/config`);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './destinations-client';
|
|
2
|
-
export * from './accounts-client';
|
|
3
|
-
export * from './users-auth-client';
|
|
4
|
-
export * from './shopify-app-install-client';
|
|
1
|
+
export * from './destinations-client';
|
|
2
|
+
export * from './accounts-client';
|
|
3
|
+
export * from './users-auth-client';
|
|
4
|
+
export * from './shopify-app-install-client';
|
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
import log from 'lambda-log';
|
|
2
|
-
import { ApiResponse } from '../../types/api-response';
|
|
3
|
-
import { axiosHttpService } from '../generic/http-client';
|
|
4
|
-
import { ShopifyAppInstall, ShopifyAppSubscriptionStatus } from '@adtrackify/at-tracking-event-types';
|
|
5
|
-
//const BASE_API_URL = process.env.BASE_API_URL;
|
|
6
|
-
//const DESTINATIONS_API_KEY = process.env.DESTINATIONS_API_KEY;
|
|
7
|
-
|
|
8
|
-
export interface ShopifyAppInstallResponseData {
|
|
9
|
-
shopifyAppInstall: ShopifyAppInstall;
|
|
10
|
-
[ key: string ]: any;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface UpdateShopifyAppInstallRequest {
|
|
14
|
-
appSubscriptionStatus?: ShopifyAppSubscriptionStatus,
|
|
15
|
-
pixelId?: string,
|
|
16
|
-
shopifyAppInstallId: string;
|
|
17
|
-
isAppEnabled?: boolean;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export class ShopifyAppInstallClient {
|
|
21
|
-
|
|
22
|
-
public BASE_API_URL: string;
|
|
23
|
-
public SHOPIFY_APP_INSTALL_API_KEY: string;
|
|
24
|
-
|
|
25
|
-
constructor (baseApiUrl: string, shopifyAppInstallApiKey: string) {
|
|
26
|
-
this.BASE_API_URL = baseApiUrl;
|
|
27
|
-
this.SHOPIFY_APP_INSTALL_API_KEY = shopifyAppInstallApiKey;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
getConfig = () => {
|
|
31
|
-
const SERVICE_API_ROOT_URL = `${this.BASE_API_URL}/shopify-app-installs`;
|
|
32
|
-
return {
|
|
33
|
-
baseURL: SERVICE_API_ROOT_URL,
|
|
34
|
-
headers: {
|
|
35
|
-
common: {
|
|
36
|
-
'x-api-key': this.SHOPIFY_APP_INSTALL_API_KEY
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
getClient = async () => {
|
|
43
|
-
return axiosHttpService(this.getConfig());
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
updateShopifyAppInstall = async (shopifyAppInstallId: string, updateShopifyAppInstallRequest: UpdateShopifyAppInstallRequest): Promise<ApiResponse<ShopifyAppInstallResponseData>> => {
|
|
47
|
-
const client = await this.getClient();
|
|
48
|
-
const response = await client.put(`/${shopifyAppInstallId}`, updateShopifyAppInstallRequest);
|
|
49
|
-
log.info('updateShopifyAppInstall', { response });
|
|
50
|
-
return response as ApiResponse<ShopifyAppInstallResponseData>;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
getShopifyAppInstall = async (shopifyAppInstallId: string): Promise<ApiResponse<ShopifyAppInstallResponseData>> => {
|
|
54
|
-
const client = await this.getClient();
|
|
55
|
-
const response = await client.get(`/${shopifyAppInstallId}`);
|
|
56
|
-
log.info('getShopifyAppInstall', { response });
|
|
57
|
-
return response as ApiResponse<ShopifyAppInstallResponseData>;
|
|
58
|
-
};
|
|
59
|
-
}
|
|
1
|
+
import log from 'lambda-log';
|
|
2
|
+
import { ApiResponse } from '../../types/api-response';
|
|
3
|
+
import { axiosHttpService } from '../generic/http-client';
|
|
4
|
+
import { ShopifyAppInstall, ShopifyAppSubscriptionStatus } from '@adtrackify/at-tracking-event-types';
|
|
5
|
+
//const BASE_API_URL = process.env.BASE_API_URL;
|
|
6
|
+
//const DESTINATIONS_API_KEY = process.env.DESTINATIONS_API_KEY;
|
|
7
|
+
|
|
8
|
+
export interface ShopifyAppInstallResponseData {
|
|
9
|
+
shopifyAppInstall: ShopifyAppInstall;
|
|
10
|
+
[ key: string ]: any;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface UpdateShopifyAppInstallRequest {
|
|
14
|
+
appSubscriptionStatus?: ShopifyAppSubscriptionStatus,
|
|
15
|
+
pixelId?: string,
|
|
16
|
+
shopifyAppInstallId: string;
|
|
17
|
+
isAppEnabled?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export class ShopifyAppInstallClient {
|
|
21
|
+
|
|
22
|
+
public BASE_API_URL: string;
|
|
23
|
+
public SHOPIFY_APP_INSTALL_API_KEY: string;
|
|
24
|
+
|
|
25
|
+
constructor (baseApiUrl: string, shopifyAppInstallApiKey: string) {
|
|
26
|
+
this.BASE_API_URL = baseApiUrl;
|
|
27
|
+
this.SHOPIFY_APP_INSTALL_API_KEY = shopifyAppInstallApiKey;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
getConfig = () => {
|
|
31
|
+
const SERVICE_API_ROOT_URL = `${this.BASE_API_URL}/shopify-app-installs`;
|
|
32
|
+
return {
|
|
33
|
+
baseURL: SERVICE_API_ROOT_URL,
|
|
34
|
+
headers: {
|
|
35
|
+
common: {
|
|
36
|
+
'x-api-key': this.SHOPIFY_APP_INSTALL_API_KEY
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
getClient = async () => {
|
|
43
|
+
return axiosHttpService(this.getConfig());
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
updateShopifyAppInstall = async (shopifyAppInstallId: string, updateShopifyAppInstallRequest: UpdateShopifyAppInstallRequest): Promise<ApiResponse<ShopifyAppInstallResponseData>> => {
|
|
47
|
+
const client = await this.getClient();
|
|
48
|
+
const response = await client.put(`/${shopifyAppInstallId}`, updateShopifyAppInstallRequest);
|
|
49
|
+
log.info('updateShopifyAppInstall', { response });
|
|
50
|
+
return response as ApiResponse<ShopifyAppInstallResponseData>;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
getShopifyAppInstall = async (shopifyAppInstallId: string): Promise<ApiResponse<ShopifyAppInstallResponseData>> => {
|
|
54
|
+
const client = await this.getClient();
|
|
55
|
+
const response = await client.get(`/${shopifyAppInstallId}`);
|
|
56
|
+
log.info('getShopifyAppInstall', { response });
|
|
57
|
+
return response as ApiResponse<ShopifyAppInstallResponseData>;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
@@ -1,111 +1,111 @@
|
|
|
1
|
-
import { User } from '@adtrackify/at-tracking-event-types';
|
|
2
|
-
import * as log from 'lambda-log';
|
|
3
|
-
import { HttpError, HttpStatusCodes } from '../../libs';
|
|
4
|
-
import { ApiResponse } from '../../types/api-response';
|
|
5
|
-
import { axiosHttpService } from '../generic/http-client';
|
|
6
|
-
|
|
7
|
-
export interface UserResponseData {
|
|
8
|
-
user: User;
|
|
9
|
-
[ key: string ]: any;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface UserSignupRequest {
|
|
13
|
-
email: string,
|
|
14
|
-
password: string,
|
|
15
|
-
givenName: string,
|
|
16
|
-
familyName: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export class UsersAuthClient {
|
|
20
|
-
|
|
21
|
-
public SERVICE_API_ROOT_URL: string;
|
|
22
|
-
public BASE_API_URL: string;
|
|
23
|
-
public USERS_AUTH_API_KEY: string;
|
|
24
|
-
constructor (baseApiUrl: string, usersAuthApiKey?: string) {
|
|
25
|
-
this.BASE_API_URL = baseApiUrl;
|
|
26
|
-
this.USERS_AUTH_API_KEY = usersAuthApiKey as string;
|
|
27
|
-
this.SERVICE_API_ROOT_URL = `${this.BASE_API_URL}/auth`;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
getConfig = () => {
|
|
31
|
-
return {
|
|
32
|
-
baseURL: this.SERVICE_API_ROOT_URL,
|
|
33
|
-
headers: {
|
|
34
|
-
common: {
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
getClient = async () => {
|
|
41
|
-
return axiosHttpService(this.getConfig());
|
|
42
|
-
};
|
|
43
|
-
|
|
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
|
-
|
|
54
|
-
const client = await this.getClient();
|
|
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 (email: string) => {
|
|
70
|
-
//confirm user
|
|
71
|
-
//@TODO update user auth service with admin confirm user endpoint
|
|
72
|
-
log.info('Attempting to admin confirm user', { email });
|
|
73
|
-
|
|
74
|
-
const client = await this.getClient();
|
|
75
|
-
const response = await client.post('/admin/confirm',
|
|
76
|
-
{
|
|
77
|
-
email
|
|
78
|
-
}, {
|
|
79
|
-
headers: {
|
|
80
|
-
'x-api-key': this.USERS_AUTH_API_KEY
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
// Check if Successful or throw error
|
|
86
|
-
if (response.status !== 200) {
|
|
87
|
-
const message = 'Admin User Confirmation Failed';
|
|
88
|
-
log.error(message, { response });
|
|
89
|
-
throw new HttpError(HttpStatusCodes.INTERNAL_SERVER_ERROR, message);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
log.info('Admin User Confirmation Successful', { response });
|
|
93
|
-
return response.data.user;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
getUserByEmail = async (email: string): Promise<ApiResponse<UserResponseData>> => {
|
|
97
|
-
const client = await this.getClient();
|
|
98
|
-
const getUserResponse = await client.get('/lookup', {
|
|
99
|
-
headers: {
|
|
100
|
-
'x-api-key': this.USERS_AUTH_API_KEY
|
|
101
|
-
},
|
|
102
|
-
params: {
|
|
103
|
-
email
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
log.info('getUserResponse', { getUserResponse });
|
|
107
|
-
return getUserResponse;
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
|
|
1
|
+
import { User } from '@adtrackify/at-tracking-event-types';
|
|
2
|
+
import * as log from 'lambda-log';
|
|
3
|
+
import { HttpError, HttpStatusCodes } from '../../libs';
|
|
4
|
+
import { ApiResponse } from '../../types/api-response';
|
|
5
|
+
import { axiosHttpService } from '../generic/http-client';
|
|
6
|
+
|
|
7
|
+
export interface UserResponseData {
|
|
8
|
+
user: User;
|
|
9
|
+
[ key: string ]: any;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface UserSignupRequest {
|
|
13
|
+
email: string,
|
|
14
|
+
password: string,
|
|
15
|
+
givenName: string,
|
|
16
|
+
familyName: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class UsersAuthClient {
|
|
20
|
+
|
|
21
|
+
public SERVICE_API_ROOT_URL: string;
|
|
22
|
+
public BASE_API_URL: string;
|
|
23
|
+
public USERS_AUTH_API_KEY: string;
|
|
24
|
+
constructor (baseApiUrl: string, usersAuthApiKey?: string) {
|
|
25
|
+
this.BASE_API_URL = baseApiUrl;
|
|
26
|
+
this.USERS_AUTH_API_KEY = usersAuthApiKey as string;
|
|
27
|
+
this.SERVICE_API_ROOT_URL = `${this.BASE_API_URL}/auth`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
getConfig = () => {
|
|
31
|
+
return {
|
|
32
|
+
baseURL: this.SERVICE_API_ROOT_URL,
|
|
33
|
+
headers: {
|
|
34
|
+
common: {
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
getClient = async () => {
|
|
41
|
+
return axiosHttpService(this.getConfig());
|
|
42
|
+
};
|
|
43
|
+
|
|
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
|
+
|
|
54
|
+
const client = await this.getClient();
|
|
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 (email: string) => {
|
|
70
|
+
//confirm user
|
|
71
|
+
//@TODO update user auth service with admin confirm user endpoint
|
|
72
|
+
log.info('Attempting to admin confirm user', { email });
|
|
73
|
+
|
|
74
|
+
const client = await this.getClient();
|
|
75
|
+
const response = await client.post('/admin/confirm',
|
|
76
|
+
{
|
|
77
|
+
email
|
|
78
|
+
}, {
|
|
79
|
+
headers: {
|
|
80
|
+
'x-api-key': this.USERS_AUTH_API_KEY
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
// Check if Successful or throw error
|
|
86
|
+
if (response.status !== 200) {
|
|
87
|
+
const message = 'Admin User Confirmation Failed';
|
|
88
|
+
log.error(message, { response });
|
|
89
|
+
throw new HttpError(HttpStatusCodes.INTERNAL_SERVER_ERROR, message);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
log.info('Admin User Confirmation Successful', { response });
|
|
93
|
+
return response.data.user;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
getUserByEmail = async (email: string): Promise<ApiResponse<UserResponseData>> => {
|
|
97
|
+
const client = await this.getClient();
|
|
98
|
+
const getUserResponse = await client.get('/lookup', {
|
|
99
|
+
headers: {
|
|
100
|
+
'x-api-key': this.USERS_AUTH_API_KEY
|
|
101
|
+
},
|
|
102
|
+
params: {
|
|
103
|
+
email
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
log.info('getUserResponse', { getUserResponse });
|
|
107
|
+
return getUserResponse;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
}
|
|
111
|
+
|
package/src/helpers/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from './input-validation-helper';
|
|
2
|
-
export * from './logging-helper';
|
|
3
|
-
export * from './response-helper';
|
|
4
|
-
export * from './shopify-helper';
|
|
5
|
-
export * from './subscription-helper';
|
|
1
|
+
export * from './input-validation-helper';
|
|
2
|
+
export * from './logging-helper';
|
|
3
|
+
export * from './response-helper';
|
|
4
|
+
export * from './shopify-helper';
|
|
5
|
+
export * from './subscription-helper';
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from './clients';
|
|
2
|
-
export * from './helpers';
|
|
3
|
-
export * from './libs';
|
|
4
|
-
export * from './types';
|
|
1
|
+
export * from './clients';
|
|
2
|
+
export * from './helpers';
|
|
3
|
+
export * from './libs';
|
|
4
|
+
export * from './types';
|
|
5
5
|
export * from './services';
|