@adtrackify/at-service-common 1.1.7 → 1.1.8
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/.editorconfig +12 -12
- package/.vscode/settings.json +9 -9
- package/bitbucket-pipelines.yml +20 -20
- package/build.js +1 -1
- package/dist/index.d.ts +22 -22
- package/dist/index.js +28 -21
- package/dist/index.js.map +2 -2
- package/jest.config.ts +40 -40
- package/package.json +4 -3
- package/src/__tests__/helpers/subscription-helper.spec.ts +40 -40
- package/src/clients/generic/axios.d.ts +7 -7
- package/src/clients/generic/dynamodb-client.ts +118 -113
- package/src/clients/generic/eventbridge-client.ts +53 -52
- package/src/clients/internal-api/destinations-client.ts +58 -58
- package/src/clients/internal-api/index.ts +4 -4
- package/src/clients/internal-api/shopify-app-install-client.ts +66 -66
- package/src/clients/third-party/shopify-client.ts +139 -139
- package/src/helpers/index.ts +5 -5
- package/src/helpers/input-validation-helper.ts +21 -21
- package/src/helpers/shopify-helper.ts +39 -39
- package/src/index.ts +4 -4
- package/src/libs/index.ts +7 -7
- package/src/libs/url.ts +9 -9
- package/src/services/eventbridge-integration-service.ts +44 -44
- package/src/types/internal-events/event-detail-types.ts +9 -9
|
@@ -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,119 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const res = await client.
|
|
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
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
static
|
|
113
|
-
static
|
|
1
|
+
import { DynamoDBClient, GetItemCommand, GetItemCommandInput, GetItemCommandOutput, PutItemCommand, PutItemCommandInput, PutItemCommandOutput, DeleteItemCommand, DeleteItemCommandInput, DeleteItemCommandOutput, BatchGetItemCommand, BatchGetItemCommandInput, BatchGetItemCommandOutput, QueryCommand, QueryCommandInput, QueryCommandOutput, ScanCommand, UpdateItemCommand } from '@aws-sdk/client-dynamodb';
|
|
2
|
+
import * as log from 'lambda-log';
|
|
3
|
+
const client = new DynamoDBClient({});
|
|
4
|
+
|
|
5
|
+
export class DynamoDbClient {
|
|
6
|
+
static safeGet = async (tableName: string, keyName: string, keyValue: any) => {
|
|
7
|
+
try {
|
|
8
|
+
const params: GetItemCommandInput = {
|
|
9
|
+
TableName: tableName,
|
|
10
|
+
Key: {
|
|
11
|
+
[ keyName ]: keyValue
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
const getItemCommand = new GetItemCommand(params);
|
|
15
|
+
const res: GetItemCommandOutput = await client.send(getItemCommand);
|
|
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: PutItemCommandInput = {
|
|
26
|
+
TableName: tableName,
|
|
27
|
+
Item: data
|
|
28
|
+
};
|
|
29
|
+
const putItemCommand = new PutItemCommand(params);
|
|
30
|
+
const res: PutItemCommandOutput = await client.send(putItemCommand);
|
|
31
|
+
return res;
|
|
32
|
+
} catch (e: any) {
|
|
33
|
+
log.error(e, { message: 'Dynamo failed simplePut' });
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
static safeDelete = async (tableName: string, keyName: string, keyValue: any) => {
|
|
39
|
+
try {
|
|
40
|
+
const params: DeleteItemCommandInput = {
|
|
41
|
+
TableName: tableName,
|
|
42
|
+
Key: {
|
|
43
|
+
[ keyName ]: keyValue
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const deleteItemCommand = new DeleteItemCommand(params);
|
|
47
|
+
const res: DeleteItemCommandOutput = await client.send(deleteItemCommand);
|
|
48
|
+
return res;
|
|
49
|
+
} catch (e: any) {
|
|
50
|
+
log.error(e, { message: 'Dynamo failed safeDelete' });
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
static safeQueryByGSI = async (tableName: string, gsiName: string, keyName: string, keyValue: any) => {
|
|
56
|
+
const query: QueryCommandInput = {
|
|
57
|
+
TableName: tableName,
|
|
58
|
+
IndexName: gsiName,
|
|
59
|
+
KeyConditionExpression: `${keyName} = :value`,
|
|
60
|
+
ExpressionAttributeValues: {
|
|
61
|
+
':value': keyValue
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const results = await DynamoDbClient.queryAll(query);
|
|
65
|
+
return results;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
static safeBatchGet = async (tableName: string, keys: any) => {
|
|
69
|
+
try {
|
|
70
|
+
const params: BatchGetItemCommandInput = {
|
|
71
|
+
RequestItems: {
|
|
72
|
+
[tableName]: {
|
|
73
|
+
Keys: keys
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const batchGetItemCommand = new BatchGetItemCommand(params);
|
|
78
|
+
const res: BatchGetItemCommandOutput = await client.send(batchGetItemCommand);
|
|
79
|
+
log.info('batchget res', { batchGetRes: res });
|
|
80
|
+
if (res?.Responses?.[ tableName ]) {
|
|
81
|
+
return res?.Responses?.[ tableName ];
|
|
82
|
+
}
|
|
83
|
+
return [];
|
|
84
|
+
} catch (e: any) {
|
|
85
|
+
log.error(e, { message: 'Dynamo failed safeBatchGet' });
|
|
86
|
+
return [];
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
static queryAll = async (params: QueryCommandInput) => {
|
|
91
|
+
try {
|
|
92
|
+
log.info('Invoke Query All', { params });
|
|
93
|
+
let currentResult: QueryCommandOutput, exclusiveStartKey;
|
|
94
|
+
let accumulatedResults: any[] = [];
|
|
95
|
+
do {
|
|
96
|
+
params.ExclusiveStartKey = exclusiveStartKey;
|
|
97
|
+
params.Limit = 200;
|
|
98
|
+
const queryCommand = new QueryCommand(params);
|
|
99
|
+
currentResult = await client.send(queryCommand);
|
|
100
|
+
if (currentResult.Items) {
|
|
101
|
+
exclusiveStartKey = currentResult.LastEvaluatedKey;
|
|
102
|
+
accumulatedResults = [ ...accumulatedResults, ...currentResult.Items ];
|
|
103
|
+
}
|
|
104
|
+
} while (currentResult.Items && currentResult.Items.length > 0 && currentResult.LastEvaluatedKey);
|
|
105
|
+
return accumulatedResults;
|
|
106
|
+
} catch (e: any) {
|
|
107
|
+
log.error(e, { message: 'Dynamo failed queryAll' });
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
static batchGet = (params: any) => client.send(new BatchGetItemCommand(params));
|
|
113
|
+
static get = (params: any) => client.send(new GetItemCommand(params));
|
|
114
|
+
static put = (params: any) => client.send(new PutItemCommand(params));
|
|
115
|
+
static query = (params: any) => client.send(new QueryCommand(params));
|
|
116
|
+
static scan = (params: any) => client.send(new ScanCommand(params));
|
|
117
|
+
static update = (params: any) => client.send(new UpdateItemCommand(params));
|
|
118
|
+
static delete = (params: any) => client.send(new DeleteItemCommand(params));
|
|
114
119
|
}
|
|
@@ -1,52 +1,53 @@
|
|
|
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
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
1
|
+
import { EventBridgeClient as EventBridge, PutEventsCommand, PutEventsCommandInput } from '@aws-sdk/client-eventbridge';
|
|
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: PutEventsCommandInput = {
|
|
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 putEventscommand = new PutEventsCommand(params);
|
|
40
|
+
const response = await this.eventBridge.send(putEventscommand);
|
|
41
|
+
log.debug('EventBus Event Published',
|
|
42
|
+
{
|
|
43
|
+
eventBusName: this.EVENT_BUS_NAME,
|
|
44
|
+
eventSource: source,
|
|
45
|
+
eventType: detailType,
|
|
46
|
+
event: data,
|
|
47
|
+
response
|
|
48
|
+
});
|
|
49
|
+
return response;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
|
|
@@ -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';
|