@adtrackify/at-service-common 1.0.58 → 1.0.60

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.
@@ -1,108 +1,108 @@
1
- import * as log from 'lambda-log';
2
- import { ApiResponse } from '../../types/api-response';
3
- import { ACCOUNT_STATUS, Destination } from '@adtrackify/at-tracking-event-types';
4
- import { axiosHttpService } from '../generic/http-client';
5
-
6
- //const BASE_API_URL = process.env.BASE_API_URL;
7
-
8
- //const SERVICE_API_ROOT_URL = `${BASE_API_URL}/accounts`;
9
- //const ACCOUNTS_API_KEY = process.env.ACCOUNTS_API_KEY;
10
-
11
- export interface AccountResponseData {
12
- account: boolean;
13
- [ key: string ]: any;
14
- }
15
-
16
- export interface IsAuthorizedUserResponseData {
17
- isAccountUser: boolean;
18
- [ key: string ]: any;
19
- }
20
- export interface PixelConfigResponseData {
21
- id: string;
22
- destinations: Destination[];
23
- [ key: string ]: any;
24
- }
25
-
26
- export interface UpdateAccountRequest {
27
- accountName?: string,
28
- companyName?: string,
29
- primaryEmail?: string,
30
- ownerId?: string,
31
- subscriptionId?: string,
32
- accountStatus?: ACCOUNT_STATUS;
33
- }
34
-
35
- export class AccountsClient {
36
- public BASE_API_URL: string;
37
- public ACCOUNTS_API_KEY?: string;
38
-
39
- constructor (baseApiUrl: string, accountsApiKey?: string) {
40
- this.BASE_API_URL = baseApiUrl;
41
- this.ACCOUNTS_API_KEY = accountsApiKey;
42
- }
43
-
44
- getConfig = () => {
45
- const SERVICE_API_ROOT_URL = `${this.BASE_API_URL}/accounts`;
46
- const params: any = {
47
- baseURL: SERVICE_API_ROOT_URL
48
- };
49
- if (this.ACCOUNTS_API_KEY) {
50
- params.headers = {
51
- common: {
52
- 'x-api-key': this.ACCOUNTS_API_KEY
53
- }
54
- };
55
- }
56
- return params;
57
- };
58
-
59
- getClient = async () => {
60
- return axiosHttpService(this.getConfig());
61
- };
62
-
63
- createAccount = async (createAccountRequest: any) => {
64
- const client = await this.getClient();
65
- const createAccountResponse = await client.post('', createAccountRequest);
66
- log.info('createAccountResponse', { createAccountResponse });
67
- return createAccountResponse;
68
- };
69
- updateAccount = async (accountId: string, body: any): Promise<ApiResponse<AccountResponseData>> => {
70
- const client = await this.getClient();
71
- const response = await client.patch(`/${accountId}/`, body);
72
- log.info('update Account response', { response });
73
- return response as ApiResponse<AccountResponseData>;
74
- };
75
- addOwner = async (accountId: string, userId: string) => {
76
- const client = await this.getClient();
77
- const addOwnerResponse = await client.post('/addOwner', { accountId, userId });
78
- log.info('addOwnerResponse', { addOwnerResponse });
79
- return addOwnerResponse;
80
- };
81
- isAuthorizedUser = async (userId: string, accountId: string, pixelId?: string): Promise<ApiResponse<IsAuthorizedUserResponseData>> => {
82
- const client = await this.getClient();
83
- const body = {
84
- userId, accountId, pixelId
85
- };
86
- const response = await client.post('/checkUserAuthorization', body);
87
- log.info('checkUserAuthorization', { response });
88
- return response as ApiResponse<IsAuthorizedUserResponseData>;
89
- };
90
- adminDeleteAccount = async (accountId: string) => {
91
- const client = await this.getClient();
92
- const success = await client.delete(`/${accountId}`);
93
- log.info('adminDeleteAccount');
94
- return success;
95
- };
96
- getPixelConfigById = async (pixelId: string): Promise<ApiResponse<PixelConfigResponseData>> => {
97
- const client = await this.getClient();
98
- const pixelResponse = await client.get(`/px/${pixelId}/config`);
99
- log.debug('pixelResponse', { pixelResponse });
100
- return pixelResponse;
101
- };
102
- // setAccountSubscriptionId = async (accountId: string, subscriptionId: string): Promise<ApiResponse<any>> => {
103
- // const client = await this.getClient();
104
- // const pixelResponse = await client.get(`/px/${pixelId}/config`);
105
- // log.debug('pixelResponse', { pixelResponse });
106
- // return pixelResponse;
107
- // };
1
+ import * as log from 'lambda-log';
2
+ import { ApiResponse } from '../../types/api-response';
3
+ import { ACCOUNT_STATUS, Destination } from '@adtrackify/at-tracking-event-types';
4
+ import { axiosHttpService } from '../generic/http-client';
5
+
6
+ //const BASE_API_URL = process.env.BASE_API_URL;
7
+
8
+ //const SERVICE_API_ROOT_URL = `${BASE_API_URL}/accounts`;
9
+ //const ACCOUNTS_API_KEY = process.env.ACCOUNTS_API_KEY;
10
+
11
+ export interface AccountResponseData {
12
+ account: boolean;
13
+ [ key: string ]: any;
14
+ }
15
+
16
+ export interface IsAuthorizedUserResponseData {
17
+ isAccountUser: boolean;
18
+ [ key: string ]: any;
19
+ }
20
+ export interface PixelConfigResponseData {
21
+ id: string;
22
+ destinations: Destination[];
23
+ [ key: string ]: any;
24
+ }
25
+
26
+ export interface UpdateAccountRequest {
27
+ accountName?: string,
28
+ companyName?: string,
29
+ primaryEmail?: string,
30
+ ownerId?: string,
31
+ subscriptionId?: string,
32
+ accountStatus?: ACCOUNT_STATUS;
33
+ }
34
+
35
+ export class AccountsClient {
36
+ public BASE_API_URL: string;
37
+ public ACCOUNTS_API_KEY?: string;
38
+
39
+ constructor (baseApiUrl: string, accountsApiKey?: string) {
40
+ this.BASE_API_URL = baseApiUrl;
41
+ this.ACCOUNTS_API_KEY = accountsApiKey;
42
+ }
43
+
44
+ getConfig = () => {
45
+ const SERVICE_API_ROOT_URL = `${this.BASE_API_URL}/accounts`;
46
+ const params: any = {
47
+ baseURL: SERVICE_API_ROOT_URL
48
+ };
49
+ if (this.ACCOUNTS_API_KEY) {
50
+ params.headers = {
51
+ common: {
52
+ 'x-api-key': this.ACCOUNTS_API_KEY
53
+ }
54
+ };
55
+ }
56
+ return params;
57
+ };
58
+
59
+ getClient = async () => {
60
+ return axiosHttpService(this.getConfig());
61
+ };
62
+
63
+ createAccount = async (createAccountRequest: any) => {
64
+ const client = await this.getClient();
65
+ const createAccountResponse = await client.post('', createAccountRequest);
66
+ log.info('createAccountResponse', { createAccountResponse });
67
+ return createAccountResponse;
68
+ };
69
+ updateAccount = async (accountId: string, body: any): Promise<ApiResponse<AccountResponseData>> => {
70
+ const client = await this.getClient();
71
+ const response = await client.patch(`/${accountId}/`, body);
72
+ log.info('update Account response', { response });
73
+ return response as ApiResponse<AccountResponseData>;
74
+ };
75
+ addOwner = async (accountId: string, userId: string) => {
76
+ const client = await this.getClient();
77
+ const addOwnerResponse = await client.post('/addOwner', { accountId, userId });
78
+ log.info('addOwnerResponse', { addOwnerResponse });
79
+ return addOwnerResponse;
80
+ };
81
+ isAuthorizedUser = async (userId: string, accountId: string, pixelId?: string): Promise<ApiResponse<IsAuthorizedUserResponseData>> => {
82
+ const client = await this.getClient();
83
+ const body = {
84
+ userId, accountId, pixelId
85
+ };
86
+ const response = await client.post('/checkUserAuthorization', body);
87
+ log.info('checkUserAuthorization', { response });
88
+ return response as ApiResponse<IsAuthorizedUserResponseData>;
89
+ };
90
+ adminDeleteAccount = async (accountId: string) => {
91
+ const client = await this.getClient();
92
+ const success = await client.delete(`/${accountId}`);
93
+ log.info('adminDeleteAccount');
94
+ return success;
95
+ };
96
+ getPixelConfigById = async (pixelId: string): Promise<ApiResponse<PixelConfigResponseData>> => {
97
+ const client = await this.getClient();
98
+ const pixelResponse = await client.get(`/px/${pixelId}/config`);
99
+ log.debug('pixelResponse', { pixelResponse });
100
+ return pixelResponse;
101
+ };
102
+ // setAccountSubscriptionId = async (accountId: string, subscriptionId: string): Promise<ApiResponse<any>> => {
103
+ // const client = await this.getClient();
104
+ // const pixelResponse = await client.get(`/px/${pixelId}/config`);
105
+ // log.debug('pixelResponse', { pixelResponse });
106
+ // return pixelResponse;
107
+ // };
108
108
  }
@@ -1,58 +1,58 @@
1
- import * as log from 'lambda-log';
2
- //const log = require('lambda-log');
3
- import { ApiResponse } from '../../types/api-response';
4
- import { axiosHttpService } from '../generic/http-client';
5
- import { Destination } from '@adtrackify/at-tracking-event-types';
6
- //const BASE_API_URL = process.env.BASE_API_URL;
7
- //const DESTINATIONS_API_KEY = process.env.DESTINATIONS_API_KEY;
8
-
9
- export interface GetDestinationsResponseData {
10
- destinations: Destination[];
11
- [ key: string ]: any;
12
- }
13
- export interface CreateDestinationResponseData {
14
- destination: Destination;
15
- [ key: string ]: any;
16
- }
17
-
18
-
19
- export class DestinationsClient {
20
-
21
- public BASE_API_URL: string;
22
- public DESTINATIONS_API_KEY: string;
23
-
24
- constructor (baseApiUrl: string, destinationsApiKey: string) {
25
- this.BASE_API_URL = baseApiUrl;
26
- this.DESTINATIONS_API_KEY = destinationsApiKey;
27
- }
28
-
29
- getConfig = () => {
30
- const SERVICE_API_ROOT_URL = `${this.BASE_API_URL}/destinations`;
31
- return {
32
- baseURL: SERVICE_API_ROOT_URL,
33
- headers: {
34
- common: {
35
- 'x-api-key': this.DESTINATIONS_API_KEY
36
- }
37
- }
38
- };
39
- };
40
-
41
- getClient = async () => {
42
- return axiosHttpService(this.getConfig());
43
- };
44
-
45
- createDestination = async (createDestinationRequest: any): Promise<ApiResponse<CreateDestinationResponseData>> => {
46
- const client = await this.getClient();
47
- const response = await client.post('/', createDestinationRequest);
48
- log.info('createDestinationResponse', { response });
49
- return response as ApiResponse<CreateDestinationResponseData>;
50
- };
51
-
52
- getPixelDestinations = async (pixelId: string): Promise<ApiResponse<GetDestinationsResponseData>> => {
53
- const client = await this.getClient();
54
- const response = await client.get(`/?pixelId=${pixelId}`);
55
- log.info('getPixelResponse', { response });
56
- return response as ApiResponse<GetDestinationsResponseData>;
57
- };
58
- }
1
+ import * as log from 'lambda-log';
2
+ //const log = require('lambda-log');
3
+ import { ApiResponse } from '../../types/api-response';
4
+ import { axiosHttpService } from '../generic/http-client';
5
+ import { Destination } from '@adtrackify/at-tracking-event-types';
6
+ //const BASE_API_URL = process.env.BASE_API_URL;
7
+ //const DESTINATIONS_API_KEY = process.env.DESTINATIONS_API_KEY;
8
+
9
+ export interface GetDestinationsResponseData {
10
+ destinations: Destination[];
11
+ [ key: string ]: any;
12
+ }
13
+ export interface CreateDestinationResponseData {
14
+ destination: Destination;
15
+ [ key: string ]: any;
16
+ }
17
+
18
+
19
+ export class DestinationsClient {
20
+
21
+ public BASE_API_URL: string;
22
+ public DESTINATIONS_API_KEY: string;
23
+
24
+ constructor (baseApiUrl: string, destinationsApiKey: string) {
25
+ this.BASE_API_URL = baseApiUrl;
26
+ this.DESTINATIONS_API_KEY = destinationsApiKey;
27
+ }
28
+
29
+ getConfig = () => {
30
+ const SERVICE_API_ROOT_URL = `${this.BASE_API_URL}/destinations`;
31
+ return {
32
+ baseURL: SERVICE_API_ROOT_URL,
33
+ headers: {
34
+ common: {
35
+ 'x-api-key': this.DESTINATIONS_API_KEY
36
+ }
37
+ }
38
+ };
39
+ };
40
+
41
+ getClient = async () => {
42
+ return axiosHttpService(this.getConfig());
43
+ };
44
+
45
+ createDestination = async (createDestinationRequest: any): Promise<ApiResponse<CreateDestinationResponseData>> => {
46
+ const client = await this.getClient();
47
+ const response = await client.post('/', createDestinationRequest);
48
+ log.info('createDestinationResponse', { response });
49
+ return response as ApiResponse<CreateDestinationResponseData>;
50
+ };
51
+
52
+ getPixelDestinations = async (pixelId: string): Promise<ApiResponse<GetDestinationsResponseData>> => {
53
+ const client = await this.getClient();
54
+ const response = await client.get(`/?pixelId=${pixelId}`);
55
+ log.info('getPixelResponse', { response });
56
+ return response as ApiResponse<GetDestinationsResponseData>;
57
+ };
58
+ }
@@ -1,4 +1,4 @@
1
1
  export * from './destinations-client';
2
2
  export * from './accounts-client';
3
3
  export * from './users-auth-client';
4
- export * from './shopify-app-install-client';
4
+ export * from './shopify-app-install-client';
@@ -1,110 +1,110 @@
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 (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;
93
- };
94
-
95
- getUserByEmail = async (email: string): Promise<ApiResponse<UserResponseData>> => {
96
- const client = await this.getClient();
97
- const getUserResponse = await client.get('/lookup', {
98
- headers: {
99
- 'x-api-key': this.USERS_AUTH_API_KEY
100
- },
101
- params: {
102
- email
103
- }
104
- });
105
- log.info('getUserResponse', { getUserResponse });
106
- return getUserResponse;
107
- };
108
-
109
- }
110
-
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 (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;
93
+ };
94
+
95
+ getUserByEmail = async (email: string): Promise<ApiResponse<UserResponseData>> => {
96
+ const client = await this.getClient();
97
+ const getUserResponse = await client.get('/lookup', {
98
+ headers: {
99
+ 'x-api-key': this.USERS_AUTH_API_KEY
100
+ },
101
+ params: {
102
+ email
103
+ }
104
+ });
105
+ log.info('getUserResponse', { getUserResponse });
106
+ return getUserResponse;
107
+ };
108
+
109
+ }
110
+