@adtrackify/at-service-common 1.1.16 → 1.1.17

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,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
  });
@@ -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
  }
@@ -0,0 +1,153 @@
1
+ /* eslint-disable no-useless-escape */
2
+ import { AdminConfirmSignUpCommandInput, AdminDeleteUserCommandInput, AdminUpdateUserAttributesCommandInput, CognitoIdentityProvider, ConfirmSignUpCommandInput, ForgotPasswordCommandInput, ListUsersCommandInput, ResendConfirmationCodeCommandInput, SignUpCommandInput } from '@aws-sdk/client-cognito-identity-provider';
3
+ import * as log from 'lambda-log';
4
+ const cognitoClient = new CognitoIdentityProvider({});
5
+
6
+ let USER_POOL_NO_SECRET_CLIENT_ID: string;
7
+ let USER_POOL_ID: string;
8
+
9
+ export function dictToAwsAttributes(input: any) {
10
+ delete input.email;
11
+ delete input.password;
12
+ const output = [];
13
+ for (const att in input) {
14
+ if (Object.prototype.hasOwnProperty.call(input, att)) {
15
+ output.push({ Name: att, Value: input[ att ] });
16
+ }
17
+ }
18
+ return output;
19
+ }
20
+
21
+ const buildAttributes = (data: any) => {
22
+ const attributes = {
23
+ name: data.givenName,
24
+ family_name: data.familyName,
25
+ };
26
+ return dictToAwsAttributes(attributes);
27
+ };
28
+
29
+ export class CognitoService {
30
+ static setCredentials = (userPoolId: string, userPoolNoSecretClientId: string) => {
31
+ USER_POOL_ID = userPoolId;
32
+ USER_POOL_NO_SECRET_CLIENT_ID = userPoolNoSecretClientId;
33
+ }
34
+
35
+ static signupUser = async (data: any) => {
36
+ const params: SignUpCommandInput = {
37
+ ClientId: USER_POOL_NO_SECRET_CLIENT_ID,
38
+ Password: data.password,
39
+ Username: data.email,
40
+ UserAttributes: buildAttributes(data),
41
+ };
42
+ const cognitoResponse = await cognitoClient.signUp(params);
43
+ log.debug('Successfully Registered User', { cognitoResponse });
44
+ return cognitoResponse;
45
+ }
46
+
47
+ static forgotPassword = async (email: string) => {
48
+ await CognitoService.adminEmailVerify(email);
49
+ const params: ForgotPasswordCommandInput = {
50
+ ClientId: USER_POOL_NO_SECRET_CLIENT_ID,
51
+ Username: email,
52
+ };
53
+ const cognitoResponse = await cognitoClient.forgotPassword(params);
54
+ log.debug('Sent Forgot Password', { cognitoResponse });
55
+ return cognitoResponse;
56
+ }
57
+
58
+ static adminEmailVerify = async (email: string) => {
59
+ try {
60
+ const user: any = await CognitoService.getUserByEmail(email);
61
+ if (user && user?.UserStatus === 'CONFIRMED' && user?.email_verified !== 'true') {
62
+ await CognitoService.forceValidateEmail(email);
63
+ }
64
+ } catch (error) {
65
+ log.error('Failed admin email verify', { error });
66
+ }
67
+ }
68
+
69
+ static forceValidateEmail = async (email: string) => {
70
+ try {
71
+ const params: AdminUpdateUserAttributesCommandInput = {
72
+ UserPoolId: USER_POOL_ID,
73
+ Username: email,
74
+ UserAttributes: [
75
+ {
76
+ Name: 'email_verified',
77
+ Value: 'true',
78
+ },
79
+ ],
80
+ };
81
+ await cognitoClient.adminUpdateUserAttributes(params);
82
+ } catch (error) {
83
+ log.error('Failed force validate email', { email, error });
84
+ }
85
+ }
86
+
87
+ static adminConfirmUser = async (data: any) => {
88
+ const params: AdminConfirmSignUpCommandInput = {
89
+ UserPoolId: USER_POOL_ID,
90
+ Username: data.email,
91
+ };
92
+ const cognitoResponse = await cognitoClient.adminConfirmSignUp(params);
93
+ await CognitoService.forceValidateEmail(data.email);
94
+ log.debug('Admin Successfully Confirmed User', { cognitoResponse });
95
+ return cognitoResponse;
96
+ }
97
+
98
+ static confirmUser = async (data: any) => {
99
+ const params: ConfirmSignUpCommandInput = {
100
+ ClientId: USER_POOL_NO_SECRET_CLIENT_ID,
101
+ ConfirmationCode: data.confirmationCode,
102
+ Username: data.email,
103
+ };
104
+ const cognitoResponse = await cognitoClient.confirmSignUp(params);
105
+ log.debug('Successfully Confirmed User', { cognitoResponse });
106
+ return cognitoResponse;
107
+ }
108
+
109
+ static resendCode = async (email: string) => {
110
+ const params: ResendConfirmationCodeCommandInput = {
111
+ ClientId: USER_POOL_NO_SECRET_CLIENT_ID,
112
+ Username: email,
113
+ };
114
+ await cognitoClient.resendConfirmationCode(params);
115
+ log.debug('Successfully Resend Confirmation Code', { email });
116
+ return;
117
+ }
118
+
119
+ static adminDeleteUser = async (userId: string) => {
120
+ const params: AdminDeleteUserCommandInput = {
121
+ UserPoolId: USER_POOL_ID,
122
+ Username: userId,
123
+ };
124
+ await cognitoClient.adminDeleteUser(params);
125
+ return true;
126
+ }
127
+
128
+ static getUserByEmail = async (email: string) => {
129
+ const params: ListUsersCommandInput = {
130
+ UserPoolId: USER_POOL_ID,
131
+ Filter: `email=\"${email}\"`,
132
+ Limit: 1,
133
+ };
134
+ const cognitoResponse: any = await cognitoClient.listUsers(params);
135
+ log.debug('Get Users by Email', { cognitoResponse });
136
+
137
+ if (cognitoResponse?.Users && cognitoResponse?.Users.length > 0) {
138
+ const attributes = cognitoResponse.Users[ 0 ].Attributes;
139
+
140
+ const user = {
141
+ ...cognitoResponse.Users[ 0 ],
142
+ Attributes: undefined,
143
+ id: cognitoResponse.Users[ 0 ].sub,
144
+ };
145
+
146
+ attributes.forEach((attr: any) => {
147
+ user[ attr.Name ] = attr?.Value;
148
+ });
149
+ return user;
150
+ }
151
+ return null;
152
+ }
153
+ }
@@ -1,17 +1,21 @@
1
- import { ObjectCannedACL, S3 } from '@aws-sdk/client-s3';
1
+ import { S3 } from '@aws-sdk/client-s3';
2
2
  import * as log from 'lambda-log';
3
3
 
4
4
  export class S3Client {
5
5
  s3: S3;
6
6
 
7
- constructor (region = 'us-west-2') {
8
- this.s3 = new S3({ region });
7
+ constructor(accessKeyId: string, secretAccessKey: string){
8
+ this.s3 = new S3({
9
+ credentials: {
10
+ accessKeyId,
11
+ secretAccessKey
12
+ }
13
+ })
9
14
  }
10
15
 
11
- async uploadJson(path: string, bucket: string, jsonData: any, ACL: ObjectCannedACL | string = ObjectCannedACL.private) {
16
+ async uploadJson(path: string, bucket: string, jsonData: any){
12
17
  try {
13
18
  const res = await this.s3.putObject({
14
- ACL,
15
19
  Bucket: bucket,
16
20
  ContentType: 'application/json; charset=utf-8',
17
21
  Body: JSON.stringify(jsonData),
@@ -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
- 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,66 +1,66 @@
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
-
60
- getShopifyAppInstallByShop = async (shop: string): Promise<ApiResponse<ShopifyAppInstallResponseData>> => {
61
- const client = await this.getClient();
62
- const response = await client.get(`/?shop=${shop}`);
63
- log.info('getShopifyAppInstallByShop', { response });
64
- return response as ApiResponse<ShopifyAppInstallResponseData>;
65
- }
66
- }
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
+
60
+ getShopifyAppInstallByShop = async (shop: string): Promise<ApiResponse<ShopifyAppInstallResponseData>> => {
61
+ const client = await this.getClient();
62
+ const response = await client.get(`/?shop=${shop}`);
63
+ log.info('getShopifyAppInstallByShop', { response });
64
+ return response as ApiResponse<ShopifyAppInstallResponseData>;
65
+ }
66
+ }