@adtrackify/at-service-common 1.0.41 → 1.0.43

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@adtrackify/at-service-common",
3
- "version": "1.0.41",
3
+ "version": "1.0.43",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -38,7 +38,7 @@
38
38
  "@types/axios": "^0.14.0"
39
39
  },
40
40
  "devDependencies": {
41
- "@adtrackify/at-tracking-event-types": "^1.0.22",
41
+ "@adtrackify/at-tracking-event-types": "^1.0.24",
42
42
  "@babel/cli": "^7.13.16",
43
43
  "@babel/core": "^7.13.10",
44
44
  "@babel/plugin-proposal-optional-chaining": "^7.13.8",
@@ -1,8 +1,8 @@
1
- declare module 'axios/lib/adapters/http' {
2
- import { AxiosAdapter } from 'axios';
3
-
4
- const httpAdapter: AxiosAdapter;
5
- namespace httpAdapter { }
6
-
7
- export = httpAdapter;
1
+ declare module 'axios/lib/adapters/http' {
2
+ import { AxiosAdapter } from 'axios';
3
+
4
+ const httpAdapter: AxiosAdapter;
5
+ namespace httpAdapter { }
6
+
7
+ export = httpAdapter;
8
8
  }
@@ -1,6 +1,6 @@
1
1
  import * as log from 'lambda-log';
2
2
  import { ApiResponse } from '../../types/api-response';
3
- import { Destination } from '@adtrackify/at-tracking-event-types';
3
+ import { ACCOUNT_STATUS, Destination } from '@adtrackify/at-tracking-event-types';
4
4
  import { axiosHttpService } from '../generic/http-client';
5
5
 
6
6
  //const BASE_API_URL = process.env.BASE_API_URL;
@@ -8,6 +8,10 @@ import { axiosHttpService } from '../generic/http-client';
8
8
  //const SERVICE_API_ROOT_URL = `${BASE_API_URL}/accounts`;
9
9
  //const ACCOUNTS_API_KEY = process.env.ACCOUNTS_API_KEY;
10
10
 
11
+ export interface AccountResponseData {
12
+ account: boolean;
13
+ [ key: string ]: any;
14
+ }
11
15
 
12
16
  export interface IsAuthorizedUserResponseData {
13
17
  isAccountUser: boolean;
@@ -19,6 +23,15 @@ export interface PixelConfigResponseData {
19
23
  [ key: string ]: any;
20
24
  }
21
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
+
22
35
  export class AccountsClient {
23
36
  public BASE_API_URL: string;
24
37
  public ACCOUNTS_API_KEY?: string;
@@ -53,6 +66,12 @@ export class AccountsClient {
53
66
  log.info('createAccountResponse', { createAccountResponse });
54
67
  return createAccountResponse;
55
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
+ };
56
75
  addOwner = async (accountId: string, userId: string) => {
57
76
  const client = await this.getClient();
58
77
  const addOwnerResponse = await client.post('/addOwner', { accountId, userId });
@@ -80,4 +99,10 @@ export class AccountsClient {
80
99
  log.debug('pixelResponse', { pixelResponse });
81
100
  return pixelResponse;
82
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
+ // };
83
108
  }
@@ -0,0 +1,51 @@
1
+ import * as 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
+ isAppEnabled?: boolean;
17
+ }
18
+
19
+ export class ShopifyAppInstallClient {
20
+
21
+ public BASE_API_URL: string;
22
+ public SHOPIFY_APP_INSTALL_API_KEY: string;
23
+
24
+ constructor (baseApiUrl: string, shopifyAppInstallApiKey: string) {
25
+ this.BASE_API_URL = baseApiUrl;
26
+ this.SHOPIFY_APP_INSTALL_API_KEY = shopifyAppInstallApiKey;
27
+ }
28
+
29
+ getConfig = () => {
30
+ const SERVICE_API_ROOT_URL = `${this.BASE_API_URL}/shopify-app-installs`;
31
+ return {
32
+ baseURL: SERVICE_API_ROOT_URL,
33
+ headers: {
34
+ common: {
35
+ 'x-api-key': this.SHOPIFY_APP_INSTALL_API_KEY
36
+ }
37
+ }
38
+ };
39
+ };
40
+
41
+ getClient = async () => {
42
+ return axiosHttpService(this.getConfig());
43
+ };
44
+
45
+ updateShopifyAppInstall = async (shopifyAppInstallId: string, updateShopifyAppInstallRequest: UpdateShopifyAppInstallRequest): Promise<ApiResponse<ShopifyAppInstallResponseData>> => {
46
+ const client = await this.getClient();
47
+ const response = await client.put(`/${shopifyAppInstallId}`, updateShopifyAppInstallRequest);
48
+ log.info('updateShopifyAppInstall', { response });
49
+ return response as ApiResponse<ShopifyAppInstallResponseData>;
50
+ };
51
+ }
@@ -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
- signupUser = async (userSignupRequest: any) => {
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 signupUserResponse = await client.post('/signup', userSignupRequest);
39
- log.info('signupUser response', { signupUserResponse });
40
- return signupUserResponse;
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>> => {