@adtrackify/at-service-common 1.0.15 → 1.0.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.
- package/dist/index.d.ts +126 -6
- package/dist/index.js +88 -25
- package/dist/index.js.map +4 -4
- package/package.json +1 -1
- package/src/clients/{axios.d.ts → generic/axios.d.ts} +8 -12
- package/src/clients/{dynamodb-client.ts → generic/dynamodb-client.ts} +16 -0
- package/src/clients/{eventbridge-client.ts → generic/eventbridge-client.ts} +1 -1
- package/src/clients/{http-client.ts → generic/http-client.ts} +5 -5
- package/src/clients/generic/index.ts +3 -0
- package/src/clients/index.ts +2 -3
- package/src/clients/internal-api/destinations-client.ts +51 -0
- package/src/clients/internal-api/index.ts +1 -0
- package/src/types/api-response.ts +6 -0
- package/src/types/db/destination.ts +35 -0
- package/src/types/db/destinations.ts +6 -0
- package/src/types/db/index.ts +3 -1
package/package.json
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export = httpAdapter;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
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
|
+
}
|
|
@@ -34,6 +34,22 @@ export class DynamoDbClient {
|
|
|
34
34
|
}
|
|
35
35
|
};
|
|
36
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
|
+
|
|
37
53
|
static safeBatchGet = async (tableName: string, keys: any) => {
|
|
38
54
|
try {
|
|
39
55
|
const params: BatchGetItemInput = {
|
|
@@ -11,6 +11,11 @@ const httpResponse = (res: any = {}) => {
|
|
|
11
11
|
};
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
+
const handleAxiosError = (error: any) => {
|
|
15
|
+
if (!error?.response && !error?.request) throw error;
|
|
16
|
+
return error.response ? httpResponse(error.response) : httpResponse({ status: 500, data: { error: error.request } });
|
|
17
|
+
};
|
|
18
|
+
|
|
14
19
|
export const axiosHttpService = (config: any = {}) => {
|
|
15
20
|
config.adapter = httpAdapter;
|
|
16
21
|
config.httpsAgent = new https.Agent({ keepAlive: true });
|
|
@@ -18,11 +23,6 @@ export const axiosHttpService = (config: any = {}) => {
|
|
|
18
23
|
|
|
19
24
|
axiosRetry(axiosService, { retryDelay: axiosRetry.exponentialDelay, retries: 3 });
|
|
20
25
|
|
|
21
|
-
const handleAxiosError = (error: any) => {
|
|
22
|
-
if (!error?.response && !error?.request) throw error;
|
|
23
|
-
return error.response ? httpResponse(error.response) : httpResponse({ status: 500, data: { error: error.request } });
|
|
24
|
-
};
|
|
25
|
-
|
|
26
26
|
return {
|
|
27
27
|
instance: () => axiosService,
|
|
28
28
|
get: (url: string, config?: any) => axiosService.get(url, config).then(httpResponse, handleAxiosError),
|
package/src/clients/index.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './http-client';
|
|
1
|
+
export * from './generic';
|
|
2
|
+
export * from './internal-api';
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Destination } from 'aws-sdk/clients/lexmodelbuildingservice';
|
|
2
|
+
import * as log from 'lambda-log';
|
|
3
|
+
import { ApiResponse } from '../../types/api-response';
|
|
4
|
+
import { axiosHttpService } from '../generic/http-client';
|
|
5
|
+
|
|
6
|
+
//const BASE_API_URL = process.env.BASE_API_URL;
|
|
7
|
+
//const DESTINATIONS_API_KEY = process.env.DESTINATIONS_API_KEY;
|
|
8
|
+
|
|
9
|
+
export class DestinationsClient {
|
|
10
|
+
|
|
11
|
+
public BASE_API_URL: string;
|
|
12
|
+
public DESTINATIONS_API_KEY: string;
|
|
13
|
+
|
|
14
|
+
constructor (baseApiUrl: string, destinationsApiKey: string) {
|
|
15
|
+
this.BASE_API_URL = baseApiUrl;
|
|
16
|
+
this.DESTINATIONS_API_KEY = destinationsApiKey;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
getConfig = () => {
|
|
20
|
+
const SERVICE_API_ROOT_URL = `${this.BASE_API_URL}/destinations`;
|
|
21
|
+
return {
|
|
22
|
+
baseURL: SERVICE_API_ROOT_URL,
|
|
23
|
+
headers: {
|
|
24
|
+
common: {
|
|
25
|
+
'x-api-key': this.DESTINATIONS_API_KEY
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
getClient = async () => {
|
|
32
|
+
return axiosHttpService(this.getConfig());
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
createDestination = async (createDestinationRequest: any): Promise<ApiResponse<{ destination: Destination; } | any>> => {
|
|
36
|
+
const client = await this.getClient();
|
|
37
|
+
const createDestinationResponse = await client.post('/', createDestinationRequest);
|
|
38
|
+
log.info('createDestinationResponse', { createDestinationResponse });
|
|
39
|
+
return createDestinationResponse;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
getPixelDestinations = async (pixelId: string): Promise<ApiResponse<{ destinations: Destination[]; } | any>> => {
|
|
43
|
+
const client = await this.getClient();
|
|
44
|
+
const pixelDestinationsResponse = await client.get(`/?pixelId=${pixelId}`);
|
|
45
|
+
log.info('pixelDestinationsResponse', { pixelDestinationsResponse });
|
|
46
|
+
return pixelDestinationsResponse;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
export default DestinationsClient;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './destinations-client';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export interface Destination {
|
|
2
|
+
id: string,
|
|
3
|
+
accountId: string,
|
|
4
|
+
pixelId: string,
|
|
5
|
+
destination: string;
|
|
6
|
+
displayName?: string,
|
|
7
|
+
enabled: boolean;
|
|
8
|
+
configuration: any,
|
|
9
|
+
createdAt: string,
|
|
10
|
+
updatedAt: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface DestinationCatalogItem {
|
|
14
|
+
id: string,
|
|
15
|
+
active: boolean,
|
|
16
|
+
destinationKey: string,
|
|
17
|
+
destinationType: string,
|
|
18
|
+
displayName: string,
|
|
19
|
+
shortName: string;
|
|
20
|
+
description?: string,
|
|
21
|
+
url: string,
|
|
22
|
+
fields?: any,
|
|
23
|
+
createdAt: string,
|
|
24
|
+
updatedAt: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface DestinationCatalogFields {
|
|
28
|
+
component_type: string,
|
|
29
|
+
name: string,
|
|
30
|
+
description: string,
|
|
31
|
+
label: string,
|
|
32
|
+
type: string,
|
|
33
|
+
required: boolean,
|
|
34
|
+
order: number;
|
|
35
|
+
}
|
package/src/types/db/index.ts
CHANGED