@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/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
declare module '@adtrackify/at-service-common/clients/dynamodb-client' {
|
|
1
|
+
declare module '@adtrackify/at-service-common/clients/generic/dynamodb-client' {
|
|
2
2
|
import AWS from 'aws-sdk';
|
|
3
3
|
export class DynamoDbClient {
|
|
4
4
|
static safeGet: (tableName: string, keyName: string, keyValue: any) => Promise<AWS.DynamoDB.DocumentClient.AttributeMap | null>;
|
|
5
5
|
static safePut: (tableName: string, data: any) => Promise<import("aws-sdk/lib/request").PromiseResult<AWS.DynamoDB.DocumentClient.PutItemOutput, AWS.AWSError> | null>;
|
|
6
|
+
static safeDelete: (tableName: string, keyName: string, keyValue: any) => Promise<import("aws-sdk/lib/request").PromiseResult<AWS.DynamoDB.DocumentClient.DeleteItemOutput, AWS.AWSError> | null>;
|
|
6
7
|
static safeBatchGet: (tableName: string, keys: any) => Promise<AWS.DynamoDB.DocumentClient.ItemList>;
|
|
7
8
|
static queryAll: (params: any) => Promise<any[] | null>;
|
|
8
9
|
static batchGet: (params: any) => Promise<import("aws-sdk/lib/request").PromiseResult<AWS.DynamoDB.DocumentClient.BatchGetItemOutput, AWS.AWSError>>;
|
|
@@ -15,7 +16,7 @@ declare module '@adtrackify/at-service-common/clients/dynamodb-client' {
|
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
}
|
|
18
|
-
declare module '@adtrackify/at-service-common/clients/eventbridge-client' {
|
|
19
|
+
declare module '@adtrackify/at-service-common/clients/generic/eventbridge-client' {
|
|
19
20
|
import { EventBridge } from 'aws-sdk';
|
|
20
21
|
export class EventBridgeClient {
|
|
21
22
|
eventBridge: EventBridge;
|
|
@@ -31,7 +32,7 @@ declare module '@adtrackify/at-service-common/clients/eventbridge-client' {
|
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
}
|
|
34
|
-
declare module '@adtrackify/at-service-common/clients/http-client' {
|
|
35
|
+
declare module '@adtrackify/at-service-common/clients/generic/http-client' {
|
|
35
36
|
export const axiosHttpService: (config?: any) => {
|
|
36
37
|
instance: () => import("axios").AxiosInstance;
|
|
37
38
|
get: (url: string, config?: any) => Promise<{
|
|
@@ -62,11 +63,74 @@ declare module '@adtrackify/at-service-common/clients/http-client' {
|
|
|
62
63
|
setBaseUrl: (url: string) => boolean;
|
|
63
64
|
};
|
|
64
65
|
|
|
66
|
+
}
|
|
67
|
+
declare module '@adtrackify/at-service-common/clients/generic/index' {
|
|
68
|
+
export * from '@adtrackify/at-service-common/clients/generic/dynamodb-client';
|
|
69
|
+
export * from '@adtrackify/at-service-common/clients/generic/eventbridge-client';
|
|
70
|
+
export * from '@adtrackify/at-service-common/clients/generic/http-client';
|
|
71
|
+
|
|
65
72
|
}
|
|
66
73
|
declare module '@adtrackify/at-service-common/clients/index' {
|
|
67
|
-
export * from '@adtrackify/at-service-common/clients/
|
|
68
|
-
export * from '@adtrackify/at-service-common/clients/
|
|
69
|
-
|
|
74
|
+
export * from '@adtrackify/at-service-common/clients/generic/index';
|
|
75
|
+
export * from '@adtrackify/at-service-common/clients/internal-api/index';
|
|
76
|
+
|
|
77
|
+
}
|
|
78
|
+
declare module '@adtrackify/at-service-common/clients/internal-api/destinations-client' {
|
|
79
|
+
import { Destination } from 'aws-sdk/clients/lexmodelbuildingservice';
|
|
80
|
+
import { ApiResponse } from '@adtrackify/at-service-common/types/api-response';
|
|
81
|
+
export class DestinationsClient {
|
|
82
|
+
BASE_API_URL: string;
|
|
83
|
+
DESTINATIONS_API_KEY: string;
|
|
84
|
+
constructor(baseApiUrl: string, destinationsApiKey: string);
|
|
85
|
+
getConfig: () => {
|
|
86
|
+
baseURL: string;
|
|
87
|
+
headers: {
|
|
88
|
+
common: {
|
|
89
|
+
'x-api-key': string;
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
getClient: () => Promise<{
|
|
94
|
+
instance: () => import("axios").AxiosInstance;
|
|
95
|
+
get: (url: string, config?: any) => Promise<{
|
|
96
|
+
headers: any;
|
|
97
|
+
data: any;
|
|
98
|
+
status: any;
|
|
99
|
+
}>;
|
|
100
|
+
post: (url: string, data?: any, config?: any) => Promise<{
|
|
101
|
+
headers: any;
|
|
102
|
+
data: any;
|
|
103
|
+
status: any;
|
|
104
|
+
}>;
|
|
105
|
+
delete: (url: string, config?: any) => Promise<{
|
|
106
|
+
headers: any;
|
|
107
|
+
data: any;
|
|
108
|
+
status: any;
|
|
109
|
+
}>;
|
|
110
|
+
put: (url: string, data?: any, config?: any) => Promise<{
|
|
111
|
+
headers: any;
|
|
112
|
+
data: any;
|
|
113
|
+
status: any;
|
|
114
|
+
}>;
|
|
115
|
+
patch: (url: string, data?: any, config?: any) => Promise<{
|
|
116
|
+
headers: any;
|
|
117
|
+
data: any;
|
|
118
|
+
status: any;
|
|
119
|
+
}>;
|
|
120
|
+
setBaseUrl: (url: string) => boolean;
|
|
121
|
+
}>;
|
|
122
|
+
createDestination: (createDestinationRequest: any) => Promise<ApiResponse<{
|
|
123
|
+
destination: Destination;
|
|
124
|
+
} | any>>;
|
|
125
|
+
getPixelDestinations: (pixelId: string) => Promise<ApiResponse<{
|
|
126
|
+
destinations: Destination[];
|
|
127
|
+
} | any>>;
|
|
128
|
+
}
|
|
129
|
+
export default DestinationsClient;
|
|
130
|
+
|
|
131
|
+
}
|
|
132
|
+
declare module '@adtrackify/at-service-common/clients/internal-api/index' {
|
|
133
|
+
export * from '@adtrackify/at-service-common/clients/internal-api/destinations-client';
|
|
70
134
|
|
|
71
135
|
}
|
|
72
136
|
declare module '@adtrackify/at-service-common/helpers/index' {
|
|
@@ -231,9 +295,65 @@ declare module '@adtrackify/at-service-common/libs/index' {
|
|
|
231
295
|
export * from '@adtrackify/at-service-common/libs/http-error';
|
|
232
296
|
export * from '@adtrackify/at-service-common/libs/http-status-codes';
|
|
233
297
|
|
|
298
|
+
}
|
|
299
|
+
declare module '@adtrackify/at-service-common/types/api-response' {
|
|
300
|
+
import { AxiosResponseHeaders } from 'axios';
|
|
301
|
+
export interface ApiResponse<T> {
|
|
302
|
+
data: T;
|
|
303
|
+
status: number;
|
|
304
|
+
headers?: AxiosResponseHeaders;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
}
|
|
308
|
+
declare module '@adtrackify/at-service-common/types/db/destination' {
|
|
309
|
+
export interface Destination {
|
|
310
|
+
id: string;
|
|
311
|
+
accountId: string;
|
|
312
|
+
pixelId: string;
|
|
313
|
+
destination: string;
|
|
314
|
+
displayName?: string;
|
|
315
|
+
enabled: boolean;
|
|
316
|
+
configuration: any;
|
|
317
|
+
createdAt: string;
|
|
318
|
+
updatedAt: string;
|
|
319
|
+
}
|
|
320
|
+
export interface DestinationCatalogItem {
|
|
321
|
+
id: string;
|
|
322
|
+
active: boolean;
|
|
323
|
+
destinationKey: string;
|
|
324
|
+
destinationType: string;
|
|
325
|
+
displayName: string;
|
|
326
|
+
shortName: string;
|
|
327
|
+
description?: string;
|
|
328
|
+
url: string;
|
|
329
|
+
fields?: any;
|
|
330
|
+
createdAt: string;
|
|
331
|
+
updatedAt: string;
|
|
332
|
+
}
|
|
333
|
+
export interface DestinationCatalogFields {
|
|
334
|
+
component_type: string;
|
|
335
|
+
name: string;
|
|
336
|
+
description: string;
|
|
337
|
+
label: string;
|
|
338
|
+
type: string;
|
|
339
|
+
required: boolean;
|
|
340
|
+
order: number;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
}
|
|
344
|
+
declare module '@adtrackify/at-service-common/types/db/destinations' {
|
|
345
|
+
export enum DESTINATIONS {
|
|
346
|
+
FACEBOOK = "facebook",
|
|
347
|
+
TIKTOK = "tiktok",
|
|
348
|
+
GOOGLE_ADS = "googleAds",
|
|
349
|
+
GOOGLE_ANALYTICS_4 = "googleAnalytics4"
|
|
350
|
+
}
|
|
351
|
+
|
|
234
352
|
}
|
|
235
353
|
declare module '@adtrackify/at-service-common/types/db/index' {
|
|
236
354
|
export * from '@adtrackify/at-service-common/types/db/shopify-app-install';
|
|
355
|
+
export * from '@adtrackify/at-service-common/types/db/destination';
|
|
356
|
+
export * from '@adtrackify/at-service-common/types/db/destinations';
|
|
237
357
|
|
|
238
358
|
}
|
|
239
359
|
declare module '@adtrackify/at-service-common/types/db/shopify-app-install' {
|
package/dist/index.js
CHANGED
|
@@ -240268,22 +240268,22 @@ var require_managed_upload = __commonJS({
|
|
|
240268
240268
|
data.Bucket = this.request.params.Bucket;
|
|
240269
240269
|
upload.callback(err, data);
|
|
240270
240270
|
},
|
|
240271
|
-
progress: function progress(
|
|
240271
|
+
progress: function progress(info4) {
|
|
240272
240272
|
var upload = this._managedUpload;
|
|
240273
240273
|
if (this.operation === "putObject") {
|
|
240274
|
-
|
|
240275
|
-
|
|
240274
|
+
info4.part = 1;
|
|
240275
|
+
info4.key = this.params.Key;
|
|
240276
240276
|
} else {
|
|
240277
|
-
upload.totalUploadedBytes +=
|
|
240278
|
-
this._lastUploadedBytes =
|
|
240279
|
-
|
|
240277
|
+
upload.totalUploadedBytes += info4.loaded - this._lastUploadedBytes;
|
|
240278
|
+
this._lastUploadedBytes = info4.loaded;
|
|
240279
|
+
info4 = {
|
|
240280
240280
|
loaded: upload.totalUploadedBytes,
|
|
240281
240281
|
total: upload.totalBytes,
|
|
240282
240282
|
part: this.params.PartNumber,
|
|
240283
240283
|
key: this.params.Key
|
|
240284
240284
|
};
|
|
240285
240285
|
}
|
|
240286
|
-
upload.emit("httpUploadProgress", [
|
|
240286
|
+
upload.emit("httpUploadProgress", [info4]);
|
|
240287
240287
|
}
|
|
240288
240288
|
});
|
|
240289
240289
|
AWS3.util.mixin(AWS3.S3.ManagedUpload, AWS3.SequentialExecutor);
|
|
@@ -627932,7 +627932,7 @@ var require_dist2 = __commonJS({
|
|
|
627932
627932
|
}
|
|
627933
627933
|
});
|
|
627934
627934
|
|
|
627935
|
-
// src/clients/dynamodb-client.ts
|
|
627935
|
+
// src/clients/generic/dynamodb-client.ts
|
|
627936
627936
|
var import_aws_sdk = __toESM(require_aws());
|
|
627937
627937
|
import * as log from "lambda-log";
|
|
627938
627938
|
var client = new import_aws_sdk.default.DynamoDB.DocumentClient();
|
|
@@ -627966,6 +627966,21 @@ __publicField(DynamoDbClient, "safePut", async (tableName, data) => {
|
|
|
627966
627966
|
return null;
|
|
627967
627967
|
}
|
|
627968
627968
|
});
|
|
627969
|
+
__publicField(DynamoDbClient, "safeDelete", async (tableName, keyName, keyValue) => {
|
|
627970
|
+
try {
|
|
627971
|
+
const params = {
|
|
627972
|
+
TableName: tableName,
|
|
627973
|
+
Key: {
|
|
627974
|
+
[keyName]: keyValue
|
|
627975
|
+
}
|
|
627976
|
+
};
|
|
627977
|
+
const res = await client.delete(params).promise();
|
|
627978
|
+
return res;
|
|
627979
|
+
} catch (e) {
|
|
627980
|
+
log.error(e, { message: "Dynamo failed safeDelete" });
|
|
627981
|
+
return null;
|
|
627982
|
+
}
|
|
627983
|
+
});
|
|
627969
627984
|
__publicField(DynamoDbClient, "safeBatchGet", async (tableName, keys) => {
|
|
627970
627985
|
try {
|
|
627971
627986
|
const params = {
|
|
@@ -628013,7 +628028,7 @@ __publicField(DynamoDbClient, "scan", (params) => client.scan(params).promise())
|
|
|
628013
628028
|
__publicField(DynamoDbClient, "update", (params) => client.update(params).promise());
|
|
628014
628029
|
__publicField(DynamoDbClient, "delete", (params) => client.delete(params).promise());
|
|
628015
628030
|
|
|
628016
|
-
// src/clients/eventbridge-client.ts
|
|
628031
|
+
// src/clients/generic/eventbridge-client.ts
|
|
628017
628032
|
var import_aws_sdk2 = __toESM(require_aws());
|
|
628018
628033
|
|
|
628019
628034
|
// node_modules/uuid/wrapper.mjs
|
|
@@ -628040,7 +628055,7 @@ var getCurrentDate = () => {
|
|
|
628040
628055
|
return getDateFromTimestamp(getCurrentTimestamp());
|
|
628041
628056
|
};
|
|
628042
628057
|
|
|
628043
|
-
// src/clients/eventbridge-client.ts
|
|
628058
|
+
// src/clients/generic/eventbridge-client.ts
|
|
628044
628059
|
var EventBridgeClient = class {
|
|
628045
628060
|
eventBridge;
|
|
628046
628061
|
EVENT_BUS_NAME;
|
|
@@ -628070,7 +628085,7 @@ var EventBridgeClient = class {
|
|
|
628070
628085
|
};
|
|
628071
628086
|
};
|
|
628072
628087
|
|
|
628073
|
-
// src/clients/http-client.ts
|
|
628088
|
+
// src/clients/generic/http-client.ts
|
|
628074
628089
|
import axios from "axios";
|
|
628075
628090
|
import axiosRetry from "axios-retry";
|
|
628076
628091
|
import https from "https";
|
|
@@ -628082,16 +628097,16 @@ var httpResponse = (res = {}) => {
|
|
|
628082
628097
|
status: res?.status || 0
|
|
628083
628098
|
};
|
|
628084
628099
|
};
|
|
628100
|
+
var handleAxiosError = (error2) => {
|
|
628101
|
+
if (!error2?.response && !error2?.request)
|
|
628102
|
+
throw error2;
|
|
628103
|
+
return error2.response ? httpResponse(error2.response) : httpResponse({ status: 500, data: { error: error2.request } });
|
|
628104
|
+
};
|
|
628085
628105
|
var axiosHttpService = (config = {}) => {
|
|
628086
628106
|
config.adapter = httpAdapter;
|
|
628087
628107
|
config.httpsAgent = new https.Agent({ keepAlive: true });
|
|
628088
628108
|
const axiosService = axios.create(config);
|
|
628089
628109
|
axiosRetry(axiosService, { retryDelay: axiosRetry.exponentialDelay, retries: 3 });
|
|
628090
|
-
const handleAxiosError = (error2) => {
|
|
628091
|
-
if (!error2?.response && !error2?.request)
|
|
628092
|
-
throw error2;
|
|
628093
|
-
return error2.response ? httpResponse(error2.response) : httpResponse({ status: 500, data: { error: error2.request } });
|
|
628094
|
-
};
|
|
628095
628110
|
return {
|
|
628096
628111
|
instance: () => axiosService,
|
|
628097
628112
|
get: (url, config2) => axiosService.get(url, config2).then(httpResponse, handleAxiosError),
|
|
@@ -628103,6 +628118,43 @@ var axiosHttpService = (config = {}) => {
|
|
|
628103
628118
|
};
|
|
628104
628119
|
};
|
|
628105
628120
|
|
|
628121
|
+
// src/clients/internal-api/destinations-client.ts
|
|
628122
|
+
import * as log2 from "lambda-log";
|
|
628123
|
+
var DestinationsClient = class {
|
|
628124
|
+
BASE_API_URL;
|
|
628125
|
+
DESTINATIONS_API_KEY;
|
|
628126
|
+
constructor(baseApiUrl, destinationsApiKey) {
|
|
628127
|
+
this.BASE_API_URL = baseApiUrl;
|
|
628128
|
+
this.DESTINATIONS_API_KEY = destinationsApiKey;
|
|
628129
|
+
}
|
|
628130
|
+
getConfig = () => {
|
|
628131
|
+
const SERVICE_API_ROOT_URL = `${this.BASE_API_URL}/destinations`;
|
|
628132
|
+
return {
|
|
628133
|
+
baseURL: SERVICE_API_ROOT_URL,
|
|
628134
|
+
headers: {
|
|
628135
|
+
common: {
|
|
628136
|
+
"x-api-key": this.DESTINATIONS_API_KEY
|
|
628137
|
+
}
|
|
628138
|
+
}
|
|
628139
|
+
};
|
|
628140
|
+
};
|
|
628141
|
+
getClient = async () => {
|
|
628142
|
+
return axiosHttpService(this.getConfig());
|
|
628143
|
+
};
|
|
628144
|
+
createDestination = async (createDestinationRequest) => {
|
|
628145
|
+
const client2 = await this.getClient();
|
|
628146
|
+
const createDestinationResponse = await client2.post("/", createDestinationRequest);
|
|
628147
|
+
log2.info("createDestinationResponse", { createDestinationResponse });
|
|
628148
|
+
return createDestinationResponse;
|
|
628149
|
+
};
|
|
628150
|
+
getPixelDestinations = async (pixelId) => {
|
|
628151
|
+
const client2 = await this.getClient();
|
|
628152
|
+
const pixelDestinationsResponse = await client2.get(`/?pixelId=${pixelId}`);
|
|
628153
|
+
log2.info("pixelDestinationsResponse", { pixelDestinationsResponse });
|
|
628154
|
+
return pixelDestinationsResponse;
|
|
628155
|
+
};
|
|
628156
|
+
};
|
|
628157
|
+
|
|
628106
628158
|
// src/libs/http-error.ts
|
|
628107
628159
|
import { strict as assert } from "assert";
|
|
628108
628160
|
var deepClone = (o = {}) => JSON.parse(JSON.stringify(o));
|
|
@@ -628185,11 +628237,11 @@ __publicField(HttpError, "serviceUnavailable", (headers) => new _HttpError(503,
|
|
|
628185
628237
|
__publicField(HttpError, "gatewayTimeout", () => new _HttpError(504));
|
|
628186
628238
|
|
|
628187
628239
|
// src/helpers/input-validation-helper.ts
|
|
628188
|
-
import * as
|
|
628240
|
+
import * as log3 from "lambda-log";
|
|
628189
628241
|
var validateInput = (schema, input) => {
|
|
628190
628242
|
const { error: error2, value } = schema.validate(input);
|
|
628191
628243
|
if (error2) {
|
|
628192
|
-
|
|
628244
|
+
log3.info("", { error: error2 });
|
|
628193
628245
|
const httperr = HttpError.badRequest("Input Validation Failure", {
|
|
628194
628246
|
errors: error2.details.map((detail) => ({
|
|
628195
628247
|
message: detail?.message,
|
|
@@ -628197,21 +628249,21 @@ var validateInput = (schema, input) => {
|
|
|
628197
628249
|
path: detail?.path
|
|
628198
628250
|
}))
|
|
628199
628251
|
});
|
|
628200
|
-
|
|
628252
|
+
log3.info("", { httperr });
|
|
628201
628253
|
throw httperr;
|
|
628202
628254
|
}
|
|
628203
628255
|
return value;
|
|
628204
628256
|
};
|
|
628205
628257
|
|
|
628206
628258
|
// src/helpers/logging-helper.ts
|
|
628207
|
-
import * as
|
|
628259
|
+
import * as log4 from "lambda-log";
|
|
628208
628260
|
var stage = process?.env?.STAGE;
|
|
628209
628261
|
var configureLogger = (event, context, debug = true) => {
|
|
628210
|
-
|
|
628211
|
-
|
|
628212
|
-
|
|
628213
|
-
|
|
628214
|
-
|
|
628262
|
+
log4.options.meta.stage = stage;
|
|
628263
|
+
log4.options.meta.source_name = context?.functionName || "unknown";
|
|
628264
|
+
log4.options.meta.awsRequestId = context?.awsRequestId || "unknown";
|
|
628265
|
+
log4.options.meta.lambdaEvent = event;
|
|
628266
|
+
log4.options.debug = debug;
|
|
628215
628267
|
};
|
|
628216
628268
|
|
|
628217
628269
|
// src/helpers/response-helper.ts
|
|
@@ -628316,7 +628368,18 @@ var HttpStatusCodes = /* @__PURE__ */ ((HttpStatusCodes2) => {
|
|
|
628316
628368
|
HttpStatusCodes2[HttpStatusCodes2["NETWORK_AUTHENTICATION_REQUIRED"] = 511] = "NETWORK_AUTHENTICATION_REQUIRED";
|
|
628317
628369
|
return HttpStatusCodes2;
|
|
628318
628370
|
})(HttpStatusCodes || {});
|
|
628371
|
+
|
|
628372
|
+
// src/types/db/destinations.ts
|
|
628373
|
+
var DESTINATIONS = /* @__PURE__ */ ((DESTINATIONS2) => {
|
|
628374
|
+
DESTINATIONS2["FACEBOOK"] = "facebook";
|
|
628375
|
+
DESTINATIONS2["TIKTOK"] = "tiktok";
|
|
628376
|
+
DESTINATIONS2["GOOGLE_ADS"] = "googleAds";
|
|
628377
|
+
DESTINATIONS2["GOOGLE_ANALYTICS_4"] = "googleAnalytics4";
|
|
628378
|
+
return DESTINATIONS2;
|
|
628379
|
+
})(DESTINATIONS || {});
|
|
628319
628380
|
export {
|
|
628381
|
+
DESTINATIONS,
|
|
628382
|
+
DestinationsClient,
|
|
628320
628383
|
DynamoDbClient,
|
|
628321
628384
|
EventBridgeClient,
|
|
628322
628385
|
HttpError,
|