@adtrackify/at-service-common 1.0.76 → 1.0.77

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
  }
@@ -1,114 +1,114 @@
1
- import AWS from 'aws-sdk';
2
- import { BatchGetItemInput, QueryOutput } from 'aws-sdk/clients/dynamodb';
3
- import * as log from 'lambda-log';
4
- const client = new AWS.DynamoDB.DocumentClient();
5
-
6
- export class DynamoDbClient {
7
- static safeGet = async (tableName: string, keyName: string, keyValue: any) => {
8
- try {
9
- const params = {
10
- TableName: tableName,
11
- Key: {
12
- [ keyName ]: keyValue
13
- }
14
- };
15
- const res = await client.get(params).promise();
16
- return res?.Item ?? null;
17
- } catch (e: any) {
18
- log.error(e, { message: 'Dynamo Client Get Failed' });
19
- return null;
20
- }
21
- };
22
-
23
- static safePut = async (tableName: string, data: any) => {
24
- try {
25
- const params = {
26
- TableName: tableName,
27
- Item: data
28
- };
29
- const res = await client.put(params).promise();
30
- return res;
31
- } catch (e: any) {
32
- log.error(e, { message: 'Dynamo failed simplePut' });
33
- return null;
34
- }
35
- };
36
-
37
- static safeDelete = async (tableName: string, keyName: string, keyValue: any) => {
38
- try {
39
- const params = {
40
- TableName: tableName,
41
- Key: {
42
- [ keyName ]: keyValue
43
- }
44
- };
45
- const res = await client.delete(params).promise();
46
- return res;
47
- } catch (e: any) {
48
- log.error(e, { message: 'Dynamo failed safeDelete' });
49
- return null;
50
- }
51
- };
52
-
53
- static safeQueryByGSI = async (tableName: string, gsiName: string, keyName: string, keyValue: any) => {
54
- const query = {
55
- TableName: tableName,
56
- IndexName: gsiName,
57
- KeyConditionExpression: `${keyName} = :value`,
58
- ExpressionAttributeValues: {
59
- ':value': keyValue
60
- }
61
- };
62
- const results = await DynamoDbClient.queryAll(query);
63
- return results;
64
- };
65
-
66
- static safeBatchGet = async (tableName: string, keys: any) => {
67
- try {
68
- const params: BatchGetItemInput = {
69
- RequestItems: {}
70
- };
71
- params.RequestItems[ tableName ] = {
72
- Keys: keys
73
- };
74
- const res = await client.batchGet(params).promise();
75
- log.info('batchget res', { batchGetRes: res });
76
- if (res?.Responses?.[ tableName ]) {
77
- return res?.Responses?.[ tableName ];
78
- }
79
- return [];
80
- } catch (e: any) {
81
- log.error(e, { message: 'Dynamo failed safeBatchGet' });
82
- return [];
83
- }
84
- };
85
-
86
- static queryAll = async (params: any) => {
87
- try {
88
- log.info('Invoke Query All', { params });
89
- let currentResult: QueryOutput, exclusiveStartKey;
90
- let accumulatedResults: any[] = [];
91
- do {
92
- params.ExclusiveStartKey = exclusiveStartKey;
93
- params.Limit = 200;
94
- currentResult = await client.query(params).promise();
95
- if (currentResult.Items) {
96
- exclusiveStartKey = currentResult.LastEvaluatedKey;
97
- accumulatedResults = [ ...accumulatedResults, ...currentResult.Items ];
98
- }
99
- } while (currentResult.Items && currentResult.Items.length > 0 && currentResult.LastEvaluatedKey);
100
- return accumulatedResults;
101
- } catch (e: any) {
102
- log.error(e, { message: 'Dynamo failed queryAll' });
103
- return null;
104
- }
105
- };
106
-
107
- static batchGet = (params: any) => client.batchGet(params).promise();
108
- static get = (params: any) => client.get(params).promise();
109
- static put = (params: any) => client.put(params).promise();
110
- static query = (params: any) => client.query(params).promise();
111
- static scan = (params: any) => client.scan(params).promise();
112
- static update = (params: any) => client.update(params).promise();
113
- static delete = (params: any) => client.delete(params).promise();
1
+ import AWS from 'aws-sdk';
2
+ import { BatchGetItemInput, QueryOutput } from 'aws-sdk/clients/dynamodb';
3
+ import * as log from 'lambda-log';
4
+ const client = new AWS.DynamoDB.DocumentClient();
5
+
6
+ export class DynamoDbClient {
7
+ static safeGet = async (tableName: string, keyName: string, keyValue: any) => {
8
+ try {
9
+ const params = {
10
+ TableName: tableName,
11
+ Key: {
12
+ [ keyName ]: keyValue
13
+ }
14
+ };
15
+ const res = await client.get(params).promise();
16
+ return res?.Item ?? null;
17
+ } catch (e: any) {
18
+ log.error(e, { message: 'Dynamo Client Get Failed' });
19
+ return null;
20
+ }
21
+ };
22
+
23
+ static safePut = async (tableName: string, data: any) => {
24
+ try {
25
+ const params = {
26
+ TableName: tableName,
27
+ Item: data
28
+ };
29
+ const res = await client.put(params).promise();
30
+ return res;
31
+ } catch (e: any) {
32
+ log.error(e, { message: 'Dynamo failed simplePut' });
33
+ return null;
34
+ }
35
+ };
36
+
37
+ static safeDelete = async (tableName: string, keyName: string, keyValue: any) => {
38
+ try {
39
+ const params = {
40
+ TableName: tableName,
41
+ Key: {
42
+ [ keyName ]: keyValue
43
+ }
44
+ };
45
+ const res = await client.delete(params).promise();
46
+ return res;
47
+ } catch (e: any) {
48
+ log.error(e, { message: 'Dynamo failed safeDelete' });
49
+ return null;
50
+ }
51
+ };
52
+
53
+ static safeQueryByGSI = async (tableName: string, gsiName: string, keyName: string, keyValue: any) => {
54
+ const query = {
55
+ TableName: tableName,
56
+ IndexName: gsiName,
57
+ KeyConditionExpression: `${keyName} = :value`,
58
+ ExpressionAttributeValues: {
59
+ ':value': keyValue
60
+ }
61
+ };
62
+ const results = await DynamoDbClient.queryAll(query);
63
+ return results;
64
+ };
65
+
66
+ static safeBatchGet = async (tableName: string, keys: any) => {
67
+ try {
68
+ const params: BatchGetItemInput = {
69
+ RequestItems: {}
70
+ };
71
+ params.RequestItems[ tableName ] = {
72
+ Keys: keys
73
+ };
74
+ const res = await client.batchGet(params).promise();
75
+ log.info('batchget res', { batchGetRes: res });
76
+ if (res?.Responses?.[ tableName ]) {
77
+ return res?.Responses?.[ tableName ];
78
+ }
79
+ return [];
80
+ } catch (e: any) {
81
+ log.error(e, { message: 'Dynamo failed safeBatchGet' });
82
+ return [];
83
+ }
84
+ };
85
+
86
+ static queryAll = async (params: any) => {
87
+ try {
88
+ log.info('Invoke Query All', { params });
89
+ let currentResult: QueryOutput, exclusiveStartKey;
90
+ let accumulatedResults: any[] = [];
91
+ do {
92
+ params.ExclusiveStartKey = exclusiveStartKey;
93
+ params.Limit = 200;
94
+ currentResult = await client.query(params).promise();
95
+ if (currentResult.Items) {
96
+ exclusiveStartKey = currentResult.LastEvaluatedKey;
97
+ accumulatedResults = [ ...accumulatedResults, ...currentResult.Items ];
98
+ }
99
+ } while (currentResult.Items && currentResult.Items.length > 0 && currentResult.LastEvaluatedKey);
100
+ return accumulatedResults;
101
+ } catch (e: any) {
102
+ log.error(e, { message: 'Dynamo failed queryAll' });
103
+ return null;
104
+ }
105
+ };
106
+
107
+ static batchGet = (params: any) => client.batchGet(params).promise();
108
+ static get = (params: any) => client.get(params).promise();
109
+ static put = (params: any) => client.put(params).promise();
110
+ static query = (params: any) => client.query(params).promise();
111
+ static scan = (params: any) => client.scan(params).promise();
112
+ static update = (params: any) => client.update(params).promise();
113
+ static delete = (params: any) => client.delete(params).promise();
114
114
  }
@@ -1,52 +1,52 @@
1
- import { EventBridge } from 'aws-sdk';
2
- import { v4 as uuidv4 } from 'uuid';
3
- import { getCurrentTimestamp } from '../../libs/dates';
4
- import * as log from 'lambda-log';
5
-
6
- export class EventBridgeClient {
7
- public eventBridge: EventBridge;
8
- public EVENT_BUS_NAME: string;
9
-
10
- constructor (eventBusName: string) {
11
- this.eventBridge = new EventBridge();
12
- this.EVENT_BUS_NAME = eventBusName;
13
- }
14
-
15
- public buildAndSendEvent = async (eventSource: string, eventType: string, eventData: any) => {
16
- const event = this.buildEvent(eventType, eventData);
17
- return await this.putEvent(eventSource, eventType, event);
18
- };
19
-
20
- public buildEvent = (eventType: string, eventData: any, eventId: string = uuidv4(), eventTime: string = getCurrentTimestamp()) => {
21
- return {
22
- eventId,
23
- eventType,
24
- eventTime,
25
- eventData
26
- };
27
- };
28
-
29
- public putEvent = async (source: string, detailType: string, data: any, headers: any = null) => {
30
- const params = {
31
- Entries: [ {
32
- Detail: JSON.stringify({ headers, data }),
33
- DetailType: detailType,
34
- EventBusName: this.EVENT_BUS_NAME,
35
- Source: source,
36
- Time: new Date(),
37
- } ],
38
- };
39
- const response = await this.eventBridge.putEvents(params).promise();
40
- log.debug('EventBus Event Published',
41
- {
42
- eventBusName: this.EVENT_BUS_NAME,
43
- eventSource: source,
44
- eventType: detailType,
45
- event: data,
46
- response
47
- });
48
- return response;
49
- };
50
-
51
- }
52
-
1
+ import { EventBridge } from 'aws-sdk';
2
+ import { v4 as uuidv4 } from 'uuid';
3
+ import { getCurrentTimestamp } from '../../libs/dates';
4
+ import * as log from 'lambda-log';
5
+
6
+ export class EventBridgeClient {
7
+ public eventBridge: EventBridge;
8
+ public EVENT_BUS_NAME: string;
9
+
10
+ constructor (eventBusName: string) {
11
+ this.eventBridge = new EventBridge();
12
+ this.EVENT_BUS_NAME = eventBusName;
13
+ }
14
+
15
+ public buildAndSendEvent = async (eventSource: string, eventType: string, eventData: any) => {
16
+ const event = this.buildEvent(eventType, eventData);
17
+ return await this.putEvent(eventSource, eventType, event);
18
+ };
19
+
20
+ public buildEvent = (eventType: string, eventData: any, eventId: string = uuidv4(), eventTime: string = getCurrentTimestamp()) => {
21
+ return {
22
+ eventId,
23
+ eventType,
24
+ eventTime,
25
+ eventData
26
+ };
27
+ };
28
+
29
+ public putEvent = async (source: string, detailType: string, data: any, headers: any = null) => {
30
+ const params = {
31
+ Entries: [ {
32
+ Detail: JSON.stringify({ headers, data }),
33
+ DetailType: detailType,
34
+ EventBusName: this.EVENT_BUS_NAME,
35
+ Source: source,
36
+ Time: new Date(),
37
+ } ],
38
+ };
39
+ const response = await this.eventBridge.putEvents(params).promise();
40
+ log.debug('EventBus Event Published',
41
+ {
42
+ eventBusName: this.EVENT_BUS_NAME,
43
+ eventSource: source,
44
+ eventType: detailType,
45
+ event: data,
46
+ response
47
+ });
48
+ return response;
49
+ };
50
+
51
+ }
52
+
@@ -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';