@adtrackify/at-service-common 1.2.11 → 1.2.13
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/__tests__/helpers/subscription-helper.spec.d.ts +1 -0
- package/dist/__tests__/helpers/subscription-helper.spec.js +28 -0
- package/dist/__tests__/helpers/subscription-helper.spec.js.map +1 -0
- package/dist/clients/generic/cognito-client.d.ts +19 -0
- package/dist/clients/generic/cognito-client.js +140 -0
- package/dist/clients/generic/cognito-client.js.map +1 -0
- package/dist/clients/generic/dynamodb-client.d.ts +15 -0
- package/dist/clients/generic/dynamodb-client.js +123 -0
- package/dist/clients/generic/dynamodb-client.js.map +1 -0
- package/dist/clients/generic/eventbridge-client.d.ts +14 -0
- package/dist/clients/generic/eventbridge-client.js +46 -0
- package/dist/clients/generic/eventbridge-client.js.map +1 -0
- package/dist/clients/generic/http-client.d.ts +30 -0
- package/dist/clients/generic/http-client.js +29 -0
- package/dist/clients/generic/http-client.js.map +1 -0
- package/dist/clients/generic/index.d.ts +6 -0
- package/dist/clients/generic/index.js +7 -0
- package/dist/clients/generic/index.js.map +1 -0
- package/dist/clients/generic/s3-client.d.ts +6 -0
- package/dist/clients/generic/s3-client.js +25 -0
- package/dist/clients/generic/s3-client.js.map +1 -0
- package/dist/clients/generic/sqs-client.d.ts +14 -0
- package/dist/clients/generic/sqs-client.js +35 -0
- package/dist/clients/generic/sqs-client.js.map +1 -0
- package/dist/clients/index.d.ts +3 -0
- package/dist/clients/index.js +4 -0
- package/dist/clients/index.js.map +1 -0
- package/dist/clients/internal-api/accounts-client.d.ts +82 -0
- package/dist/clients/internal-api/accounts-client.js +79 -0
- package/dist/clients/internal-api/accounts-client.js.map +1 -0
- package/dist/clients/internal-api/destinations-client.d.ts +54 -0
- package/dist/clients/internal-api/destinations-client.js +37 -0
- package/dist/clients/internal-api/destinations-client.js.map +1 -0
- package/dist/clients/internal-api/index.d.ts +4 -0
- package/dist/clients/internal-api/index.js +5 -0
- package/dist/clients/internal-api/index.js.map +1 -0
- package/dist/clients/internal-api/shopify-app-install-client.d.ts +57 -0
- package/dist/clients/internal-api/shopify-app-install-client.js +43 -0
- package/dist/clients/internal-api/shopify-app-install-client.js.map +1 -0
- package/dist/clients/internal-api/users-auth-client.d.ts +61 -0
- package/dist/clients/internal-api/users-auth-client.js +74 -0
- package/dist/clients/internal-api/users-auth-client.js.map +1 -0
- package/dist/clients/third-party/index.d.ts +1 -0
- package/dist/clients/third-party/index.js +2 -0
- package/dist/clients/third-party/index.js.map +1 -0
- package/dist/clients/third-party/shopify-client.d.ts +90 -0
- package/dist/clients/third-party/shopify-client.js +122 -0
- package/dist/clients/third-party/shopify-client.js.map +1 -0
- package/dist/helpers/index.d.ts +5 -0
- package/dist/helpers/index.js +6 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/helpers/input-validation-helper.d.ts +2 -0
- package/dist/helpers/input-validation-helper.js +19 -0
- package/dist/helpers/input-validation-helper.js.map +1 -0
- package/dist/helpers/logging-helper.d.ts +1 -0
- package/dist/helpers/logging-helper.js +10 -0
- package/dist/helpers/logging-helper.js.map +1 -0
- package/dist/helpers/response-helper.d.ts +36 -0
- package/dist/helpers/response-helper.js +36 -0
- package/dist/helpers/response-helper.js.map +1 -0
- package/dist/helpers/shopify-helper.d.ts +9 -0
- package/dist/helpers/shopify-helper.js +24 -0
- package/dist/helpers/shopify-helper.js.map +1 -0
- package/dist/helpers/subscription-helper.d.ts +8 -0
- package/dist/helpers/subscription-helper.js +182 -0
- package/dist/helpers/subscription-helper.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.esm.js +1374 -0
- package/dist/index.esm.js.map +7 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/libs/crypto.d.ts +1 -0
- package/dist/libs/crypto.js +6 -0
- package/dist/libs/crypto.js.map +1 -0
- package/dist/libs/dates.d.ts +3 -0
- package/dist/libs/dates.js +11 -0
- package/dist/libs/dates.js.map +1 -0
- package/dist/libs/http-error.d.ts +21 -0
- package/dist/libs/http-error.js +56 -0
- package/dist/libs/http-error.js.map +1 -0
- package/dist/libs/http-status-codes.d.ts +58 -0
- package/dist/libs/http-status-codes.js +60 -0
- package/dist/libs/http-status-codes.js.map +1 -0
- package/dist/libs/index.d.ts +6 -0
- package/dist/libs/index.js +7 -0
- package/dist/libs/index.js.map +1 -0
- package/dist/libs/url.d.ts +1 -0
- package/dist/libs/url.js +10 -0
- package/dist/libs/url.js.map +1 -0
- package/dist/services/eventbridge-integration-service.d.ts +9 -0
- package/dist/services/eventbridge-integration-service.js +25 -0
- package/dist/services/eventbridge-integration-service.js.map +1 -0
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +2 -0
- package/dist/services/index.js.map +1 -0
- package/dist/types/api-response.d.ts +6 -0
- package/dist/types/api-response.js +2 -0
- package/dist/types/api-response.js.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/internal-events/event-detail-types.d.ts +20 -0
- package/dist/types/internal-events/event-detail-types.js +25 -0
- package/dist/types/internal-events/event-detail-types.js.map +1 -0
- package/dist/types/internal-events/index.d.ts +1 -0
- package/dist/types/internal-events/index.js +2 -0
- package/dist/types/internal-events/index.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,1374 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => {
|
|
4
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
+
return value;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
// src/clients/generic/dynamodb-client.ts
|
|
9
|
+
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
|
|
10
|
+
import { DynamoDBDocument } from "@aws-sdk/lib-dynamodb";
|
|
11
|
+
import * as log from "lambda-log";
|
|
12
|
+
var marshallOptions = {
|
|
13
|
+
convertEmptyValues: false,
|
|
14
|
+
removeUndefinedValues: false,
|
|
15
|
+
convertClassInstanceToMap: true
|
|
16
|
+
};
|
|
17
|
+
var unmarshallOptions = {
|
|
18
|
+
wrapNumbers: false
|
|
19
|
+
};
|
|
20
|
+
var translateConfig = { marshallOptions, unmarshallOptions };
|
|
21
|
+
var ddbClient = new DynamoDBClient({});
|
|
22
|
+
var client = DynamoDBDocument.from(ddbClient, translateConfig);
|
|
23
|
+
var _DynamoDbClient = class {
|
|
24
|
+
};
|
|
25
|
+
var DynamoDbClient = _DynamoDbClient;
|
|
26
|
+
__publicField(DynamoDbClient, "safeGet", async (tableName, keyName, keyValue) => {
|
|
27
|
+
try {
|
|
28
|
+
const params = {
|
|
29
|
+
TableName: tableName,
|
|
30
|
+
Key: {
|
|
31
|
+
[keyName]: keyValue
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const res = await client.get(params);
|
|
35
|
+
return res?.Item ?? null;
|
|
36
|
+
} catch (e) {
|
|
37
|
+
log.error(e, { message: "Dynamo Client Get Failed" });
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
__publicField(DynamoDbClient, "safePut", async (tableName, data) => {
|
|
42
|
+
try {
|
|
43
|
+
const params = {
|
|
44
|
+
TableName: tableName,
|
|
45
|
+
Item: data
|
|
46
|
+
};
|
|
47
|
+
const res = await client.put(params);
|
|
48
|
+
return res;
|
|
49
|
+
} catch (e) {
|
|
50
|
+
log.error(e, { message: "Dynamo failed simplePut" });
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
__publicField(DynamoDbClient, "safeDelete", async (tableName, keyName, keyValue) => {
|
|
55
|
+
try {
|
|
56
|
+
const params = {
|
|
57
|
+
TableName: tableName,
|
|
58
|
+
Key: {
|
|
59
|
+
[keyName]: keyValue
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const res = await client.delete(params);
|
|
63
|
+
return res;
|
|
64
|
+
} catch (e) {
|
|
65
|
+
log.error(e, { message: "Dynamo failed safeDelete" });
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
__publicField(DynamoDbClient, "safeQueryByGSI", async (tableName, gsiName, keyName, keyValue) => {
|
|
70
|
+
const query = {
|
|
71
|
+
TableName: tableName,
|
|
72
|
+
IndexName: gsiName,
|
|
73
|
+
KeyConditionExpression: `${keyName} = :value`,
|
|
74
|
+
ExpressionAttributeValues: {
|
|
75
|
+
":value": keyValue
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const results = await _DynamoDbClient.queryAll(query);
|
|
79
|
+
return results;
|
|
80
|
+
});
|
|
81
|
+
__publicField(DynamoDbClient, "safeBatchGet", async (tableName, keys) => {
|
|
82
|
+
try {
|
|
83
|
+
const params = {
|
|
84
|
+
RequestItems: {}
|
|
85
|
+
};
|
|
86
|
+
params.RequestItems[tableName] = {
|
|
87
|
+
Keys: keys
|
|
88
|
+
};
|
|
89
|
+
const res = await client.batchGet(params);
|
|
90
|
+
log.info("batchget res", { batchGetRes: res });
|
|
91
|
+
if (res?.Responses?.[tableName]) {
|
|
92
|
+
return res?.Responses?.[tableName];
|
|
93
|
+
}
|
|
94
|
+
return [];
|
|
95
|
+
} catch (e) {
|
|
96
|
+
log.error(e, { message: "Dynamo failed safeBatchGet" });
|
|
97
|
+
return [];
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
__publicField(DynamoDbClient, "queryAll", async (params) => {
|
|
101
|
+
try {
|
|
102
|
+
log.info("Invoke Query All", { params });
|
|
103
|
+
let currentResult, exclusiveStartKey;
|
|
104
|
+
let accumulatedResults = [];
|
|
105
|
+
do {
|
|
106
|
+
params.ExclusiveStartKey = exclusiveStartKey;
|
|
107
|
+
params.Limit = 200;
|
|
108
|
+
currentResult = await client.query(params);
|
|
109
|
+
if (currentResult.Items) {
|
|
110
|
+
exclusiveStartKey = currentResult.LastEvaluatedKey;
|
|
111
|
+
accumulatedResults = [...accumulatedResults, ...currentResult.Items];
|
|
112
|
+
}
|
|
113
|
+
} while (currentResult.Items && currentResult.Items.length > 0 && currentResult.LastEvaluatedKey);
|
|
114
|
+
return accumulatedResults;
|
|
115
|
+
} catch (e) {
|
|
116
|
+
log.error(e, { message: "Dynamo failed queryAll" });
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
__publicField(DynamoDbClient, "batchGet", (params) => client.batchGet(params));
|
|
121
|
+
__publicField(DynamoDbClient, "get", (params) => client.get(params));
|
|
122
|
+
__publicField(DynamoDbClient, "put", (params) => client.put(params));
|
|
123
|
+
__publicField(DynamoDbClient, "query", (params) => client.query(params));
|
|
124
|
+
__publicField(DynamoDbClient, "scan", (params) => client.scan(params));
|
|
125
|
+
__publicField(DynamoDbClient, "update", (params) => client.update(params));
|
|
126
|
+
__publicField(DynamoDbClient, "delete", (params) => client.delete(params));
|
|
127
|
+
|
|
128
|
+
// src/clients/generic/eventbridge-client.ts
|
|
129
|
+
import { EventBridgeClient as EventBridge, PutEventsCommand } from "@aws-sdk/client-eventbridge";
|
|
130
|
+
import { v4 as uuidv4 } from "uuid";
|
|
131
|
+
|
|
132
|
+
// src/libs/dates.ts
|
|
133
|
+
import { DateTime } from "luxon";
|
|
134
|
+
var getCurrentTimestamp = () => {
|
|
135
|
+
return DateTime.utc().toJSDate().toISOString();
|
|
136
|
+
};
|
|
137
|
+
var getDateFromTimestamp = (timestamp) => {
|
|
138
|
+
return timestamp.split("T")[0];
|
|
139
|
+
};
|
|
140
|
+
var getCurrentDate = () => {
|
|
141
|
+
return getDateFromTimestamp(getCurrentTimestamp());
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
// src/clients/generic/eventbridge-client.ts
|
|
145
|
+
import * as log2 from "lambda-log";
|
|
146
|
+
var EventBridgeClient = class {
|
|
147
|
+
eventBridge;
|
|
148
|
+
EVENT_BUS_NAME;
|
|
149
|
+
constructor(eventBusName) {
|
|
150
|
+
this.eventBridge = new EventBridge({});
|
|
151
|
+
this.EVENT_BUS_NAME = eventBusName;
|
|
152
|
+
}
|
|
153
|
+
buildAndSendEvent = async (eventSource, eventType, eventData) => {
|
|
154
|
+
const event = this.buildEvent(eventType, eventData);
|
|
155
|
+
return await this.putEvent(eventSource, eventType, event);
|
|
156
|
+
};
|
|
157
|
+
buildEvent = (eventType, eventData, eventId = uuidv4(), eventTime = getCurrentTimestamp()) => {
|
|
158
|
+
return {
|
|
159
|
+
eventId,
|
|
160
|
+
eventType,
|
|
161
|
+
eventTime,
|
|
162
|
+
eventData
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
putEvent = async (source, detailType, data, headers = null) => {
|
|
166
|
+
const params = {
|
|
167
|
+
Entries: [{
|
|
168
|
+
Detail: JSON.stringify({ headers, data }),
|
|
169
|
+
DetailType: detailType,
|
|
170
|
+
EventBusName: this.EVENT_BUS_NAME,
|
|
171
|
+
Source: source,
|
|
172
|
+
Time: /* @__PURE__ */ new Date()
|
|
173
|
+
}]
|
|
174
|
+
};
|
|
175
|
+
const putEventscommand = new PutEventsCommand(params);
|
|
176
|
+
const response = await this.eventBridge.send(putEventscommand);
|
|
177
|
+
log2.debug(
|
|
178
|
+
"EventBus Event Published",
|
|
179
|
+
{
|
|
180
|
+
eventBusName: this.EVENT_BUS_NAME,
|
|
181
|
+
eventSource: source,
|
|
182
|
+
eventType: detailType,
|
|
183
|
+
event: data,
|
|
184
|
+
response
|
|
185
|
+
}
|
|
186
|
+
);
|
|
187
|
+
return response;
|
|
188
|
+
};
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
// src/clients/generic/http-client.ts
|
|
192
|
+
import axios from "axios";
|
|
193
|
+
import https from "https";
|
|
194
|
+
var httpResponse = (res = {}) => {
|
|
195
|
+
return {
|
|
196
|
+
headers: res?.headers || {},
|
|
197
|
+
data: res?.data || {},
|
|
198
|
+
status: res?.status || 0
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
var handleAxiosError = (error7) => {
|
|
202
|
+
if (!error7?.response && !error7?.request)
|
|
203
|
+
throw error7;
|
|
204
|
+
return error7.response ? httpResponse(error7.response) : httpResponse({ status: 500, data: { error: error7.request } });
|
|
205
|
+
};
|
|
206
|
+
var axiosHttpService = (config = {}) => {
|
|
207
|
+
config.adapter = "http";
|
|
208
|
+
config.httpsAgent = new https.Agent({ keepAlive: true });
|
|
209
|
+
const axiosService = axios.create(config);
|
|
210
|
+
return {
|
|
211
|
+
instance: () => axiosService,
|
|
212
|
+
get: (url, config2) => axiosService.get(url, config2).then(httpResponse, handleAxiosError),
|
|
213
|
+
post: (url, data, config2) => axiosService.post(url, data, config2).then(httpResponse, handleAxiosError),
|
|
214
|
+
delete: (url, config2) => axiosService.delete(url, config2).then(httpResponse, handleAxiosError),
|
|
215
|
+
put: (url, data, config2) => axiosService.put(url, data, config2).then(httpResponse, handleAxiosError),
|
|
216
|
+
patch: (url, data, config2) => axiosService.patch(url, data, config2).then(httpResponse, handleAxiosError),
|
|
217
|
+
setBaseUrl: (url) => !!(axiosService.defaults.baseURL = url)
|
|
218
|
+
};
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
// src/clients/generic/s3-client.ts
|
|
222
|
+
import { ObjectCannedACL, S3 } from "@aws-sdk/client-s3";
|
|
223
|
+
import * as log3 from "lambda-log";
|
|
224
|
+
var S3Client = class {
|
|
225
|
+
s3;
|
|
226
|
+
constructor(region = "us-west-2") {
|
|
227
|
+
this.s3 = new S3({ region });
|
|
228
|
+
}
|
|
229
|
+
async uploadJson(path, bucket, jsonData, ACL = ObjectCannedACL.private) {
|
|
230
|
+
try {
|
|
231
|
+
const res = await this.s3.putObject({
|
|
232
|
+
ACL,
|
|
233
|
+
Bucket: bucket,
|
|
234
|
+
ContentType: "application/json; charset=utf-8",
|
|
235
|
+
Body: JSON.stringify(jsonData),
|
|
236
|
+
Key: path
|
|
237
|
+
});
|
|
238
|
+
return res;
|
|
239
|
+
} catch (error7) {
|
|
240
|
+
log3.error("Error in s3 upload json", { error: error7 });
|
|
241
|
+
return error7;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
// src/clients/generic/cognito-client.ts
|
|
247
|
+
import { CognitoIdentityProvider } from "@aws-sdk/client-cognito-identity-provider";
|
|
248
|
+
import * as log4 from "lambda-log";
|
|
249
|
+
function dictToAwsAttributes(input) {
|
|
250
|
+
delete input.email;
|
|
251
|
+
delete input.password;
|
|
252
|
+
const output = [];
|
|
253
|
+
for (const att in input) {
|
|
254
|
+
if (Object.prototype.hasOwnProperty.call(input, att)) {
|
|
255
|
+
output.push({ Name: att, Value: input[att] });
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return output;
|
|
259
|
+
}
|
|
260
|
+
var buildAttributes = (data) => {
|
|
261
|
+
const attributes = {
|
|
262
|
+
name: data.givenName,
|
|
263
|
+
family_name: data.familyName
|
|
264
|
+
};
|
|
265
|
+
return dictToAwsAttributes(attributes);
|
|
266
|
+
};
|
|
267
|
+
var CognitoClient = class {
|
|
268
|
+
cognitoClient;
|
|
269
|
+
USER_POOL_ID;
|
|
270
|
+
USER_POOL_NO_SECRET_CLIENT_ID;
|
|
271
|
+
constructor(userPoolId, userPoolNoSecretClientId) {
|
|
272
|
+
this.cognitoClient = new CognitoIdentityProvider({});
|
|
273
|
+
this.USER_POOL_ID = userPoolId;
|
|
274
|
+
this.USER_POOL_NO_SECRET_CLIENT_ID = userPoolNoSecretClientId;
|
|
275
|
+
}
|
|
276
|
+
signupUser = async (data) => {
|
|
277
|
+
const params = {
|
|
278
|
+
ClientId: this.USER_POOL_NO_SECRET_CLIENT_ID,
|
|
279
|
+
Password: data.password,
|
|
280
|
+
Username: data.email,
|
|
281
|
+
UserAttributes: buildAttributes(data)
|
|
282
|
+
};
|
|
283
|
+
const cognitoResponse = await this.cognitoClient.signUp(params);
|
|
284
|
+
log4.debug("Successfully Registered User", { cognitoResponse });
|
|
285
|
+
return cognitoResponse;
|
|
286
|
+
};
|
|
287
|
+
forgotPassword = async (email) => {
|
|
288
|
+
await this.adminEmailVerify(email);
|
|
289
|
+
const params = {
|
|
290
|
+
ClientId: this.USER_POOL_NO_SECRET_CLIENT_ID,
|
|
291
|
+
Username: email
|
|
292
|
+
};
|
|
293
|
+
const cognitoResponse = await this.cognitoClient.forgotPassword(params);
|
|
294
|
+
log4.debug("Sent Forgot Password", { cognitoResponse });
|
|
295
|
+
return cognitoResponse;
|
|
296
|
+
};
|
|
297
|
+
adminEmailVerify = async (email) => {
|
|
298
|
+
try {
|
|
299
|
+
const user = await this.getUserByEmail(email);
|
|
300
|
+
if (user && user?.UserStatus === "CONFIRMED" && user?.email_verified !== "true") {
|
|
301
|
+
await this.forceValidateEmail(email);
|
|
302
|
+
}
|
|
303
|
+
} catch (error7) {
|
|
304
|
+
log4.error("Failed admin email verify", { error: error7 });
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
forceValidateEmail = async (email) => {
|
|
308
|
+
try {
|
|
309
|
+
const params = {
|
|
310
|
+
UserPoolId: this.USER_POOL_ID,
|
|
311
|
+
Username: email,
|
|
312
|
+
UserAttributes: [
|
|
313
|
+
{
|
|
314
|
+
Name: "email_verified",
|
|
315
|
+
Value: "true"
|
|
316
|
+
}
|
|
317
|
+
]
|
|
318
|
+
};
|
|
319
|
+
await this.cognitoClient.adminUpdateUserAttributes(params);
|
|
320
|
+
} catch (error7) {
|
|
321
|
+
log4.error("Failed force validate email", { email, error: error7 });
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
adminConfirmUser = async (data) => {
|
|
325
|
+
const params = {
|
|
326
|
+
UserPoolId: this.USER_POOL_ID,
|
|
327
|
+
Username: data.email
|
|
328
|
+
};
|
|
329
|
+
const cognitoResponse = await this.cognitoClient.adminConfirmSignUp(params);
|
|
330
|
+
await this.forceValidateEmail(data.email);
|
|
331
|
+
log4.debug("Admin Successfully Confirmed User", { cognitoResponse });
|
|
332
|
+
return cognitoResponse;
|
|
333
|
+
};
|
|
334
|
+
confirmUser = async (data) => {
|
|
335
|
+
const params = {
|
|
336
|
+
ClientId: this.USER_POOL_NO_SECRET_CLIENT_ID,
|
|
337
|
+
ConfirmationCode: data.confirmationCode,
|
|
338
|
+
Username: data.email
|
|
339
|
+
};
|
|
340
|
+
const cognitoResponse = await this.cognitoClient.confirmSignUp(params);
|
|
341
|
+
log4.debug("Successfully Confirmed User", { cognitoResponse });
|
|
342
|
+
return cognitoResponse;
|
|
343
|
+
};
|
|
344
|
+
resendCode = async (email) => {
|
|
345
|
+
const params = {
|
|
346
|
+
ClientId: this.USER_POOL_NO_SECRET_CLIENT_ID,
|
|
347
|
+
Username: email
|
|
348
|
+
};
|
|
349
|
+
await this.cognitoClient.resendConfirmationCode(params);
|
|
350
|
+
log4.debug("Successfully Resend Confirmation Code", { email });
|
|
351
|
+
return;
|
|
352
|
+
};
|
|
353
|
+
adminDeleteUser = async (userId) => {
|
|
354
|
+
const params = {
|
|
355
|
+
UserPoolId: this.USER_POOL_ID,
|
|
356
|
+
Username: userId
|
|
357
|
+
};
|
|
358
|
+
await this.cognitoClient.adminDeleteUser(params);
|
|
359
|
+
return true;
|
|
360
|
+
};
|
|
361
|
+
getUserByEmail = async (email) => {
|
|
362
|
+
const params = {
|
|
363
|
+
UserPoolId: this.USER_POOL_ID,
|
|
364
|
+
Filter: `email="${email}"`,
|
|
365
|
+
Limit: 1
|
|
366
|
+
};
|
|
367
|
+
const cognitoResponse = await this.cognitoClient.listUsers(params);
|
|
368
|
+
log4.debug("Get Users by Email", { cognitoResponse });
|
|
369
|
+
if (cognitoResponse?.Users && cognitoResponse?.Users.length > 0) {
|
|
370
|
+
const attributes = cognitoResponse.Users[0].Attributes;
|
|
371
|
+
const user = {
|
|
372
|
+
...cognitoResponse.Users[0],
|
|
373
|
+
Attributes: void 0,
|
|
374
|
+
id: cognitoResponse.Users[0].sub
|
|
375
|
+
};
|
|
376
|
+
attributes.forEach((attr) => {
|
|
377
|
+
user[attr.Name] = attr?.Value;
|
|
378
|
+
});
|
|
379
|
+
return user;
|
|
380
|
+
}
|
|
381
|
+
return null;
|
|
382
|
+
};
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
// src/clients/generic/sqs-client.ts
|
|
386
|
+
import { SQS } from "@aws-sdk/client-sqs";
|
|
387
|
+
import { v4 as uuidv42 } from "uuid";
|
|
388
|
+
import * as log5 from "lambda-log";
|
|
389
|
+
var SQSClient = class {
|
|
390
|
+
sqs;
|
|
391
|
+
queueUrl;
|
|
392
|
+
constructor(region, accountId, queueName) {
|
|
393
|
+
this.sqs = new SQS({ region });
|
|
394
|
+
this.queueUrl = `https://sqs.${region}.amazonaws.com/${accountId}/${queueName}`;
|
|
395
|
+
}
|
|
396
|
+
buildAndSendMessage = async (messageType, messageBody, deplaySeconds = 0) => {
|
|
397
|
+
const message = this.buildMessage(messageType, messageBody);
|
|
398
|
+
return await this.sendMessage(message, deplaySeconds);
|
|
399
|
+
};
|
|
400
|
+
buildMessage = (messageType, messageBody, messageId = uuidv42(), messageTime = getCurrentTimestamp()) => {
|
|
401
|
+
return {
|
|
402
|
+
messageId,
|
|
403
|
+
messageType,
|
|
404
|
+
messageTime,
|
|
405
|
+
messageBody
|
|
406
|
+
};
|
|
407
|
+
};
|
|
408
|
+
sendMessage = async (messageBody, delaySeconds = 0) => {
|
|
409
|
+
const params = {
|
|
410
|
+
QueueUrl: this.queueUrl,
|
|
411
|
+
DelaySeconds: delaySeconds,
|
|
412
|
+
MessageBody: JSON.stringify(messageBody)
|
|
413
|
+
};
|
|
414
|
+
const response = await this.sqs.sendMessage(params);
|
|
415
|
+
log5.debug("SQS Message Sent", { queueUrl: this.queueUrl, messageBody, delaySeconds, response });
|
|
416
|
+
return response;
|
|
417
|
+
};
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
// src/clients/internal-api/destinations-client.ts
|
|
421
|
+
import * as log6 from "lambda-log";
|
|
422
|
+
var DestinationsClient = class {
|
|
423
|
+
BASE_API_URL;
|
|
424
|
+
DESTINATIONS_API_KEY;
|
|
425
|
+
constructor(baseApiUrl, destinationsApiKey) {
|
|
426
|
+
this.BASE_API_URL = baseApiUrl;
|
|
427
|
+
this.DESTINATIONS_API_KEY = destinationsApiKey;
|
|
428
|
+
}
|
|
429
|
+
getConfig = () => {
|
|
430
|
+
const SERVICE_API_ROOT_URL = `${this.BASE_API_URL}/destinations`;
|
|
431
|
+
return {
|
|
432
|
+
baseURL: SERVICE_API_ROOT_URL,
|
|
433
|
+
headers: {
|
|
434
|
+
common: {
|
|
435
|
+
"x-api-key": this.DESTINATIONS_API_KEY
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
};
|
|
439
|
+
};
|
|
440
|
+
getClient = async () => {
|
|
441
|
+
return axiosHttpService(this.getConfig());
|
|
442
|
+
};
|
|
443
|
+
createDestination = async (createDestinationRequest) => {
|
|
444
|
+
const client2 = await this.getClient();
|
|
445
|
+
const response = await client2.post("/", createDestinationRequest);
|
|
446
|
+
log6.info("createDestinationResponse", { response });
|
|
447
|
+
return response;
|
|
448
|
+
};
|
|
449
|
+
getPixelDestinations = async (pixelId) => {
|
|
450
|
+
const client2 = await this.getClient();
|
|
451
|
+
const response = await client2.get(`/?pixelId=${pixelId}`);
|
|
452
|
+
log6.info("getPixelResponse", { response });
|
|
453
|
+
return response;
|
|
454
|
+
};
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
// src/clients/internal-api/accounts-client.ts
|
|
458
|
+
import * as log7 from "lambda-log";
|
|
459
|
+
var AccountsClient = class {
|
|
460
|
+
BASE_API_URL;
|
|
461
|
+
ACCOUNTS_API_KEY;
|
|
462
|
+
constructor(baseApiUrl, accountsApiKey) {
|
|
463
|
+
this.BASE_API_URL = baseApiUrl;
|
|
464
|
+
this.ACCOUNTS_API_KEY = accountsApiKey;
|
|
465
|
+
}
|
|
466
|
+
getConfig = () => {
|
|
467
|
+
const SERVICE_API_ROOT_URL = `${this.BASE_API_URL}/accounts`;
|
|
468
|
+
const params = {
|
|
469
|
+
baseURL: SERVICE_API_ROOT_URL
|
|
470
|
+
};
|
|
471
|
+
if (this.ACCOUNTS_API_KEY) {
|
|
472
|
+
params.headers = {
|
|
473
|
+
common: {
|
|
474
|
+
"x-api-key": this.ACCOUNTS_API_KEY
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
return params;
|
|
479
|
+
};
|
|
480
|
+
getClient = async () => {
|
|
481
|
+
return axiosHttpService(this.getConfig());
|
|
482
|
+
};
|
|
483
|
+
createAccount = async (createAccountRequest) => {
|
|
484
|
+
const client2 = await this.getClient();
|
|
485
|
+
const createAccountResponse = await client2.post("", createAccountRequest);
|
|
486
|
+
log7.info("createAccountResponse", { createAccountResponse });
|
|
487
|
+
return createAccountResponse;
|
|
488
|
+
};
|
|
489
|
+
updateAccount = async (accountId, body) => {
|
|
490
|
+
const client2 = await this.getClient();
|
|
491
|
+
const response = await client2.patch(`/${accountId}/`, body);
|
|
492
|
+
log7.info("update Account response", { response });
|
|
493
|
+
return response;
|
|
494
|
+
};
|
|
495
|
+
addOwner = async (accountId, userId) => {
|
|
496
|
+
const client2 = await this.getClient();
|
|
497
|
+
const addOwnerResponse = await client2.post("/addOwner", { accountId, userId });
|
|
498
|
+
log7.info("addOwnerResponse", { addOwnerResponse });
|
|
499
|
+
return addOwnerResponse;
|
|
500
|
+
};
|
|
501
|
+
isAuthorizedUser = async (userId, accountId, pixelId) => {
|
|
502
|
+
const client2 = await this.getClient();
|
|
503
|
+
const body = {
|
|
504
|
+
userId,
|
|
505
|
+
accountId,
|
|
506
|
+
pixelId
|
|
507
|
+
};
|
|
508
|
+
const response = await client2.post("/checkUserAuthorization", body);
|
|
509
|
+
log7.info("checkUserAuthorization", { response });
|
|
510
|
+
return response;
|
|
511
|
+
};
|
|
512
|
+
adminDeleteAccount = async (accountId) => {
|
|
513
|
+
const client2 = await this.getClient();
|
|
514
|
+
const success2 = await client2.delete(`/${accountId}`);
|
|
515
|
+
log7.info("adminDeleteAccount");
|
|
516
|
+
return success2;
|
|
517
|
+
};
|
|
518
|
+
getPixelConfigById = async (pixelId) => {
|
|
519
|
+
const client2 = await this.getClient();
|
|
520
|
+
const pixelResponse = await client2.get(`/px/${pixelId}/config`);
|
|
521
|
+
log7.debug("get pixelResponse", { pixelResponse });
|
|
522
|
+
return pixelResponse;
|
|
523
|
+
};
|
|
524
|
+
getAccount = async (accountId) => {
|
|
525
|
+
const client2 = await this.getClient();
|
|
526
|
+
const response = await client2.get(`/${accountId}/`);
|
|
527
|
+
log7.info("get account response", { response });
|
|
528
|
+
return response;
|
|
529
|
+
};
|
|
530
|
+
addUserToAccount = async (accountId, userId) => {
|
|
531
|
+
const client2 = await this.getClient();
|
|
532
|
+
const response = await client2.post("/addUser", { accountId, userId });
|
|
533
|
+
log7.info("add user account response", { response });
|
|
534
|
+
return response;
|
|
535
|
+
};
|
|
536
|
+
// setAccountSubscriptionId = async (accountId: string, subscriptionId: string): Promise<ApiResponse<any>> => {
|
|
537
|
+
// const client = await this.getClient();
|
|
538
|
+
// const pixelResponse = await client.get(`/px/${pixelId}/config`);
|
|
539
|
+
// log.debug('pixelResponse', { pixelResponse });
|
|
540
|
+
// return pixelResponse;
|
|
541
|
+
// };
|
|
542
|
+
};
|
|
543
|
+
|
|
544
|
+
// src/clients/internal-api/users-auth-client.ts
|
|
545
|
+
import * as log8 from "lambda-log";
|
|
546
|
+
|
|
547
|
+
// src/libs/http-error.ts
|
|
548
|
+
import { strict as assert } from "assert";
|
|
549
|
+
var deepClone = (o = {}) => JSON.parse(JSON.stringify(o));
|
|
550
|
+
var containsStackTrace = (text = "") => /at.+\.js:\d+:\d+/.test(text);
|
|
551
|
+
var objectContainsStackTrace = (obj) => !obj ? false : containsStackTrace(JSON.stringify(obj));
|
|
552
|
+
var supportedStatusCodes = {
|
|
553
|
+
400: "Bad Request",
|
|
554
|
+
401: "Unauthorized",
|
|
555
|
+
403: "Forbidden",
|
|
556
|
+
404: "Not Found",
|
|
557
|
+
405: "Method Not Allowed",
|
|
558
|
+
409: "Conflict",
|
|
559
|
+
412: "Precondition Failed",
|
|
560
|
+
413: "Payload Too Large",
|
|
561
|
+
415: "Unsupported Media Type",
|
|
562
|
+
428: "Precondition Required",
|
|
563
|
+
429: "Too Many Requests",
|
|
564
|
+
500: "Internal Server Error",
|
|
565
|
+
501: "Not Implemented",
|
|
566
|
+
502: "Bad Gateway",
|
|
567
|
+
503: "Service Unavailable",
|
|
568
|
+
504: "Gateway Timeout"
|
|
569
|
+
};
|
|
570
|
+
var supportedStatusCodesMessage = `statusCode must be one of the following: ${JSON.stringify(Object.keys(supportedStatusCodes))}`;
|
|
571
|
+
var _HttpError = class extends Error {
|
|
572
|
+
body;
|
|
573
|
+
headers;
|
|
574
|
+
statusCode;
|
|
575
|
+
isServerError;
|
|
576
|
+
constructor(statusCode, message, body, headers) {
|
|
577
|
+
assert(statusCode in supportedStatusCodes, supportedStatusCodesMessage);
|
|
578
|
+
const isServerError = statusCode > 499;
|
|
579
|
+
assert(
|
|
580
|
+
body === void 0 || typeof body === "object",
|
|
581
|
+
"body must be an object or omitted"
|
|
582
|
+
);
|
|
583
|
+
assert(
|
|
584
|
+
headers === void 0 || typeof headers === "object",
|
|
585
|
+
"headers must be an object or omitted"
|
|
586
|
+
);
|
|
587
|
+
message = message ?? supportedStatusCodes[statusCode];
|
|
588
|
+
assert(
|
|
589
|
+
!containsStackTrace(message) && !objectContainsStackTrace(body),
|
|
590
|
+
"the message or data parameters may not contain errors or stack traces"
|
|
591
|
+
);
|
|
592
|
+
super(message);
|
|
593
|
+
this.body = deepClone(body);
|
|
594
|
+
this.headers = deepClone(headers);
|
|
595
|
+
this.statusCode = statusCode;
|
|
596
|
+
this.isServerError = isServerError;
|
|
597
|
+
if (!this?.body?.message) {
|
|
598
|
+
this.body.message = this.message;
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
static get supportedStatusCodes() {
|
|
602
|
+
return supportedStatusCodes;
|
|
603
|
+
}
|
|
604
|
+
};
|
|
605
|
+
var HttpError = _HttpError;
|
|
606
|
+
__publicField(HttpError, "badRequest", (message, body, headers) => {
|
|
607
|
+
return new _HttpError(400, message, body, headers);
|
|
608
|
+
});
|
|
609
|
+
__publicField(HttpError, "unauthorized", (message, body, headers) => new _HttpError(401, message, body, headers));
|
|
610
|
+
__publicField(HttpError, "forbidden", (message, body, headers) => new _HttpError(403, message, body, headers));
|
|
611
|
+
__publicField(HttpError, "notFound", (message, body, headers) => new _HttpError(404, message, body, headers));
|
|
612
|
+
__publicField(HttpError, "internal", (message, body, headers) => new _HttpError(500, message, body, headers));
|
|
613
|
+
__publicField(HttpError, "notImplemented", () => new _HttpError(501));
|
|
614
|
+
__publicField(HttpError, "badGateway", () => new _HttpError(502));
|
|
615
|
+
__publicField(HttpError, "serviceUnavailable", (headers) => new _HttpError(503, void 0, void 0, headers));
|
|
616
|
+
__publicField(HttpError, "gatewayTimeout", () => new _HttpError(504));
|
|
617
|
+
|
|
618
|
+
// src/libs/http-status-codes.ts
|
|
619
|
+
var HttpStatusCodes = /* @__PURE__ */ ((HttpStatusCodes2) => {
|
|
620
|
+
HttpStatusCodes2[HttpStatusCodes2["CONTINUE"] = 100] = "CONTINUE";
|
|
621
|
+
HttpStatusCodes2[HttpStatusCodes2["SWITCHING_PROTOCOLS"] = 101] = "SWITCHING_PROTOCOLS";
|
|
622
|
+
HttpStatusCodes2[HttpStatusCodes2["PROCESSING"] = 102] = "PROCESSING";
|
|
623
|
+
HttpStatusCodes2[HttpStatusCodes2["OK"] = 200] = "OK";
|
|
624
|
+
HttpStatusCodes2[HttpStatusCodes2["CREATED"] = 201] = "CREATED";
|
|
625
|
+
HttpStatusCodes2[HttpStatusCodes2["ACCEPTED"] = 202] = "ACCEPTED";
|
|
626
|
+
HttpStatusCodes2[HttpStatusCodes2["NON_AUTHORITATIVE_INFORMATION"] = 203] = "NON_AUTHORITATIVE_INFORMATION";
|
|
627
|
+
HttpStatusCodes2[HttpStatusCodes2["NO_CONTENT"] = 204] = "NO_CONTENT";
|
|
628
|
+
HttpStatusCodes2[HttpStatusCodes2["RESET_CONTENT"] = 205] = "RESET_CONTENT";
|
|
629
|
+
HttpStatusCodes2[HttpStatusCodes2["PARTIAL_CONTENT"] = 206] = "PARTIAL_CONTENT";
|
|
630
|
+
HttpStatusCodes2[HttpStatusCodes2["MULTI_STATUS"] = 207] = "MULTI_STATUS";
|
|
631
|
+
HttpStatusCodes2[HttpStatusCodes2["MULTIPLE_CHOICES"] = 300] = "MULTIPLE_CHOICES";
|
|
632
|
+
HttpStatusCodes2[HttpStatusCodes2["MOVED_PERMANENTLY"] = 301] = "MOVED_PERMANENTLY";
|
|
633
|
+
HttpStatusCodes2[HttpStatusCodes2["MOVED_TEMPORARILY"] = 302] = "MOVED_TEMPORARILY";
|
|
634
|
+
HttpStatusCodes2[HttpStatusCodes2["SEE_OTHER"] = 303] = "SEE_OTHER";
|
|
635
|
+
HttpStatusCodes2[HttpStatusCodes2["NOT_MODIFIED"] = 304] = "NOT_MODIFIED";
|
|
636
|
+
HttpStatusCodes2[HttpStatusCodes2["USE_PROXY"] = 305] = "USE_PROXY";
|
|
637
|
+
HttpStatusCodes2[HttpStatusCodes2["TEMPORARY_REDIRECT"] = 307] = "TEMPORARY_REDIRECT";
|
|
638
|
+
HttpStatusCodes2[HttpStatusCodes2["PERMANENT_REDIRECT"] = 308] = "PERMANENT_REDIRECT";
|
|
639
|
+
HttpStatusCodes2[HttpStatusCodes2["BAD_REQUEST"] = 400] = "BAD_REQUEST";
|
|
640
|
+
HttpStatusCodes2[HttpStatusCodes2["UNAUTHORIZED"] = 401] = "UNAUTHORIZED";
|
|
641
|
+
HttpStatusCodes2[HttpStatusCodes2["PAYMENT_REQUIRED"] = 402] = "PAYMENT_REQUIRED";
|
|
642
|
+
HttpStatusCodes2[HttpStatusCodes2["FORBIDDEN"] = 403] = "FORBIDDEN";
|
|
643
|
+
HttpStatusCodes2[HttpStatusCodes2["NOT_FOUND"] = 404] = "NOT_FOUND";
|
|
644
|
+
HttpStatusCodes2[HttpStatusCodes2["METHOD_NOT_ALLOWED"] = 405] = "METHOD_NOT_ALLOWED";
|
|
645
|
+
HttpStatusCodes2[HttpStatusCodes2["NOT_ACCEPTABLE"] = 406] = "NOT_ACCEPTABLE";
|
|
646
|
+
HttpStatusCodes2[HttpStatusCodes2["PROXY_AUTHENTICATION_REQUIRED"] = 407] = "PROXY_AUTHENTICATION_REQUIRED";
|
|
647
|
+
HttpStatusCodes2[HttpStatusCodes2["REQUEST_TIMEOUT"] = 408] = "REQUEST_TIMEOUT";
|
|
648
|
+
HttpStatusCodes2[HttpStatusCodes2["CONFLICT"] = 409] = "CONFLICT";
|
|
649
|
+
HttpStatusCodes2[HttpStatusCodes2["GONE"] = 410] = "GONE";
|
|
650
|
+
HttpStatusCodes2[HttpStatusCodes2["LENGTH_REQUIRED"] = 411] = "LENGTH_REQUIRED";
|
|
651
|
+
HttpStatusCodes2[HttpStatusCodes2["PRECONDITION_FAILED"] = 412] = "PRECONDITION_FAILED";
|
|
652
|
+
HttpStatusCodes2[HttpStatusCodes2["REQUEST_TOO_LONG"] = 413] = "REQUEST_TOO_LONG";
|
|
653
|
+
HttpStatusCodes2[HttpStatusCodes2["REQUEST_URI_TOO_LONG"] = 414] = "REQUEST_URI_TOO_LONG";
|
|
654
|
+
HttpStatusCodes2[HttpStatusCodes2["UNSUPPORTED_MEDIA_TYPE"] = 415] = "UNSUPPORTED_MEDIA_TYPE";
|
|
655
|
+
HttpStatusCodes2[HttpStatusCodes2["REQUESTED_RANGE_NOT_SATISFIABLE"] = 416] = "REQUESTED_RANGE_NOT_SATISFIABLE";
|
|
656
|
+
HttpStatusCodes2[HttpStatusCodes2["EXPECTATION_FAILED"] = 417] = "EXPECTATION_FAILED";
|
|
657
|
+
HttpStatusCodes2[HttpStatusCodes2["IM_A_TEAPOT"] = 418] = "IM_A_TEAPOT";
|
|
658
|
+
HttpStatusCodes2[HttpStatusCodes2["INSUFFICIENT_SPACE_ON_RESOURCE"] = 419] = "INSUFFICIENT_SPACE_ON_RESOURCE";
|
|
659
|
+
HttpStatusCodes2[HttpStatusCodes2["METHOD_FAILURE"] = 420] = "METHOD_FAILURE";
|
|
660
|
+
HttpStatusCodes2[HttpStatusCodes2["MISDIRECTED_REQUEST"] = 421] = "MISDIRECTED_REQUEST";
|
|
661
|
+
HttpStatusCodes2[HttpStatusCodes2["UNPROCESSABLE_ENTITY"] = 422] = "UNPROCESSABLE_ENTITY";
|
|
662
|
+
HttpStatusCodes2[HttpStatusCodes2["LOCKED"] = 423] = "LOCKED";
|
|
663
|
+
HttpStatusCodes2[HttpStatusCodes2["FAILED_DEPENDENCY"] = 424] = "FAILED_DEPENDENCY";
|
|
664
|
+
HttpStatusCodes2[HttpStatusCodes2["PRECONDITION_REQUIRED"] = 428] = "PRECONDITION_REQUIRED";
|
|
665
|
+
HttpStatusCodes2[HttpStatusCodes2["TOO_MANY_REQUESTS"] = 429] = "TOO_MANY_REQUESTS";
|
|
666
|
+
HttpStatusCodes2[HttpStatusCodes2["REQUEST_HEADER_FIELDS_TOO_LARGE"] = 431] = "REQUEST_HEADER_FIELDS_TOO_LARGE";
|
|
667
|
+
HttpStatusCodes2[HttpStatusCodes2["UNAVAILABLE_FOR_LEGAL_REASONS"] = 451] = "UNAVAILABLE_FOR_LEGAL_REASONS";
|
|
668
|
+
HttpStatusCodes2[HttpStatusCodes2["INTERNAL_SERVER_ERROR"] = 500] = "INTERNAL_SERVER_ERROR";
|
|
669
|
+
HttpStatusCodes2[HttpStatusCodes2["NOT_IMPLEMENTED"] = 501] = "NOT_IMPLEMENTED";
|
|
670
|
+
HttpStatusCodes2[HttpStatusCodes2["BAD_GATEWAY"] = 502] = "BAD_GATEWAY";
|
|
671
|
+
HttpStatusCodes2[HttpStatusCodes2["SERVICE_UNAVAILABLE"] = 503] = "SERVICE_UNAVAILABLE";
|
|
672
|
+
HttpStatusCodes2[HttpStatusCodes2["GATEWAY_TIMEOUT"] = 504] = "GATEWAY_TIMEOUT";
|
|
673
|
+
HttpStatusCodes2[HttpStatusCodes2["HTTP_VERSION_NOT_SUPPORTED"] = 505] = "HTTP_VERSION_NOT_SUPPORTED";
|
|
674
|
+
HttpStatusCodes2[HttpStatusCodes2["INSUFFICIENT_STORAGE"] = 507] = "INSUFFICIENT_STORAGE";
|
|
675
|
+
HttpStatusCodes2[HttpStatusCodes2["NETWORK_AUTHENTICATION_REQUIRED"] = 511] = "NETWORK_AUTHENTICATION_REQUIRED";
|
|
676
|
+
return HttpStatusCodes2;
|
|
677
|
+
})(HttpStatusCodes || {});
|
|
678
|
+
|
|
679
|
+
// src/clients/internal-api/users-auth-client.ts
|
|
680
|
+
var UsersAuthClient = class {
|
|
681
|
+
SERVICE_API_ROOT_URL;
|
|
682
|
+
BASE_API_URL;
|
|
683
|
+
USERS_AUTH_API_KEY;
|
|
684
|
+
constructor(baseApiUrl, usersAuthApiKey) {
|
|
685
|
+
this.BASE_API_URL = baseApiUrl;
|
|
686
|
+
this.USERS_AUTH_API_KEY = usersAuthApiKey;
|
|
687
|
+
this.SERVICE_API_ROOT_URL = `${this.BASE_API_URL}/auth`;
|
|
688
|
+
}
|
|
689
|
+
getConfig = () => {
|
|
690
|
+
return {
|
|
691
|
+
baseURL: this.SERVICE_API_ROOT_URL,
|
|
692
|
+
headers: {
|
|
693
|
+
common: {}
|
|
694
|
+
}
|
|
695
|
+
};
|
|
696
|
+
};
|
|
697
|
+
getClient = async () => {
|
|
698
|
+
return axiosHttpService(this.getConfig());
|
|
699
|
+
};
|
|
700
|
+
signupAndConfirmUser = async (userSignupRequest) => {
|
|
701
|
+
const user = await this.signupUser(userSignupRequest);
|
|
702
|
+
await this.adminConfirmUser(user.email);
|
|
703
|
+
return user;
|
|
704
|
+
};
|
|
705
|
+
signupUser = async (userSignupRequest) => {
|
|
706
|
+
log8.info("Attempting to signup user", { email: userSignupRequest.email });
|
|
707
|
+
const client2 = await this.getClient();
|
|
708
|
+
const response = await client2.post("/signup", userSignupRequest);
|
|
709
|
+
if (response.status !== 200 || !response?.data?.user) {
|
|
710
|
+
const message = "User Signup Failed";
|
|
711
|
+
log8.error(message, { response });
|
|
712
|
+
throw new HttpError(500 /* INTERNAL_SERVER_ERROR */, message);
|
|
713
|
+
}
|
|
714
|
+
log8.info("User Signup Successful", { response });
|
|
715
|
+
return response.data.user;
|
|
716
|
+
};
|
|
717
|
+
//userName is same as user id
|
|
718
|
+
adminConfirmUser = async (email) => {
|
|
719
|
+
log8.info("Attempting to admin confirm user", { email });
|
|
720
|
+
const client2 = await this.getClient();
|
|
721
|
+
const response = await client2.post(
|
|
722
|
+
"/admin/confirm",
|
|
723
|
+
{
|
|
724
|
+
email
|
|
725
|
+
},
|
|
726
|
+
{
|
|
727
|
+
headers: {
|
|
728
|
+
"x-api-key": this.USERS_AUTH_API_KEY
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
);
|
|
732
|
+
if (response.status !== 200) {
|
|
733
|
+
const message = "Admin User Confirmation Failed";
|
|
734
|
+
log8.error(message, { response });
|
|
735
|
+
throw new HttpError(500 /* INTERNAL_SERVER_ERROR */, message);
|
|
736
|
+
}
|
|
737
|
+
log8.info("Admin User Confirmation Successful", { response });
|
|
738
|
+
return response;
|
|
739
|
+
};
|
|
740
|
+
getUserByEmail = async (email) => {
|
|
741
|
+
const client2 = await this.getClient();
|
|
742
|
+
const getUserResponse = await client2.get("/lookup", {
|
|
743
|
+
headers: {
|
|
744
|
+
"x-api-key": this.USERS_AUTH_API_KEY
|
|
745
|
+
},
|
|
746
|
+
params: {
|
|
747
|
+
email
|
|
748
|
+
}
|
|
749
|
+
});
|
|
750
|
+
log8.info("getUserResponse", { getUserResponse });
|
|
751
|
+
return getUserResponse;
|
|
752
|
+
};
|
|
753
|
+
};
|
|
754
|
+
|
|
755
|
+
// src/clients/internal-api/shopify-app-install-client.ts
|
|
756
|
+
import log9 from "lambda-log";
|
|
757
|
+
var ShopifyAppInstallClient = class {
|
|
758
|
+
BASE_API_URL;
|
|
759
|
+
SHOPIFY_APP_INSTALL_API_KEY;
|
|
760
|
+
constructor(baseApiUrl, shopifyAppInstallApiKey) {
|
|
761
|
+
this.BASE_API_URL = baseApiUrl;
|
|
762
|
+
this.SHOPIFY_APP_INSTALL_API_KEY = shopifyAppInstallApiKey;
|
|
763
|
+
}
|
|
764
|
+
getConfig = () => {
|
|
765
|
+
const SERVICE_API_ROOT_URL = `${this.BASE_API_URL}/shopify-app-installs`;
|
|
766
|
+
return {
|
|
767
|
+
baseURL: SERVICE_API_ROOT_URL,
|
|
768
|
+
headers: {
|
|
769
|
+
common: {
|
|
770
|
+
"x-api-key": this.SHOPIFY_APP_INSTALL_API_KEY
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
};
|
|
774
|
+
};
|
|
775
|
+
getClient = async () => {
|
|
776
|
+
return axiosHttpService(this.getConfig());
|
|
777
|
+
};
|
|
778
|
+
updateShopifyAppInstall = async (shopifyAppInstallId, updateShopifyAppInstallRequest) => {
|
|
779
|
+
const client2 = await this.getClient();
|
|
780
|
+
const response = await client2.put(`/${shopifyAppInstallId}`, updateShopifyAppInstallRequest);
|
|
781
|
+
log9.info("updateShopifyAppInstall", { response });
|
|
782
|
+
return response;
|
|
783
|
+
};
|
|
784
|
+
getShopifyAppInstall = async (shopifyAppInstallId) => {
|
|
785
|
+
const client2 = await this.getClient();
|
|
786
|
+
const response = await client2.get(`/${shopifyAppInstallId}`);
|
|
787
|
+
log9.info("getShopifyAppInstall", { response });
|
|
788
|
+
return response;
|
|
789
|
+
};
|
|
790
|
+
getShopifyAppInstallByShop = async (shop) => {
|
|
791
|
+
const client2 = await this.getClient();
|
|
792
|
+
const response = await client2.get(`/?shop=${shop}`);
|
|
793
|
+
log9.info("getShopifyAppInstallByShop", { response });
|
|
794
|
+
return response;
|
|
795
|
+
};
|
|
796
|
+
};
|
|
797
|
+
|
|
798
|
+
// src/clients/third-party/shopify-client.ts
|
|
799
|
+
import * as log10 from "lambda-log";
|
|
800
|
+
var _ShopifyClient = class {
|
|
801
|
+
};
|
|
802
|
+
var ShopifyClient = _ShopifyClient;
|
|
803
|
+
__publicField(ShopifyClient, "_shopify_api_version", process.env.SHOPIFY_API_VERSION);
|
|
804
|
+
__publicField(ShopifyClient, "getConfig", (shopifyDomain, accessToken) => {
|
|
805
|
+
const config = {
|
|
806
|
+
baseURL: `https://${shopifyDomain}/admin/api/${_ShopifyClient._shopify_api_version}`,
|
|
807
|
+
headers: {
|
|
808
|
+
common: {
|
|
809
|
+
"X-Shopify-Access-Token": accessToken
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
};
|
|
813
|
+
return config;
|
|
814
|
+
});
|
|
815
|
+
__publicField(ShopifyClient, "getClient", (shopifyDomain, accessToken) => {
|
|
816
|
+
return axiosHttpService(
|
|
817
|
+
_ShopifyClient.getConfig(shopifyDomain, accessToken)
|
|
818
|
+
);
|
|
819
|
+
});
|
|
820
|
+
__publicField(ShopifyClient, "registerApp", async (shop, code, appKey, appSecret) => {
|
|
821
|
+
const client2 = axiosHttpService();
|
|
822
|
+
const url = "https://" + shop + "/admin/oauth/access_token";
|
|
823
|
+
const payload = {
|
|
824
|
+
client_id: appKey,
|
|
825
|
+
client_secret: appSecret,
|
|
826
|
+
code
|
|
827
|
+
};
|
|
828
|
+
const res = await client2.post(url, payload);
|
|
829
|
+
return res;
|
|
830
|
+
});
|
|
831
|
+
__publicField(ShopifyClient, "registerWebhookTopic", async (shop, accessToken, eventBridgeArn, topic) => {
|
|
832
|
+
const client2 = axiosHttpService();
|
|
833
|
+
const url = `https://${shop}/admin/api/${_ShopifyClient._shopify_api_version}/webhooks.json`;
|
|
834
|
+
const payload = {
|
|
835
|
+
webhook: {
|
|
836
|
+
topic,
|
|
837
|
+
address: eventBridgeArn,
|
|
838
|
+
format: "json"
|
|
839
|
+
}
|
|
840
|
+
};
|
|
841
|
+
const res = await client2.post(url, payload, { headers: { "X-Shopify-Access-Token": accessToken } });
|
|
842
|
+
if (res.status >= 400) {
|
|
843
|
+
log10.error("Failed to register Webhook Topic", { shop, accessToken, eventBridgeArn, topic, url, payload });
|
|
844
|
+
}
|
|
845
|
+
log10.debug("Shopify Client Webhook Registration Response", { registrationResponse: res });
|
|
846
|
+
return res;
|
|
847
|
+
});
|
|
848
|
+
__publicField(ShopifyClient, "updateShopifyAppMetafield", async (shop, accessToken, pixelId) => {
|
|
849
|
+
const url = `https://${shop}/admin/api/${_ShopifyClient._shopify_api_version}/metafields.json`;
|
|
850
|
+
const payload = {
|
|
851
|
+
metafield: {
|
|
852
|
+
namespace: "adtr",
|
|
853
|
+
key: "adtr.config",
|
|
854
|
+
value: pixelId,
|
|
855
|
+
type: "single_line_text_field"
|
|
856
|
+
}
|
|
857
|
+
};
|
|
858
|
+
const res = await _ShopifyClient.genericShopifyPost(url, accessToken, payload);
|
|
859
|
+
if (res.status >= 400) {
|
|
860
|
+
log10.error("Failed to update Shopify app Metafield ", { shop, accessToken, url, payload });
|
|
861
|
+
}
|
|
862
|
+
return res;
|
|
863
|
+
});
|
|
864
|
+
__publicField(ShopifyClient, "getShopifyStoreProperties", async (shop, accessToken) => {
|
|
865
|
+
const url = `https://${shop}/admin/api/${_ShopifyClient._shopify_api_version}/shop.json`;
|
|
866
|
+
const res = await _ShopifyClient.genericShopifyGet(url, accessToken);
|
|
867
|
+
if (res.status >= 400) {
|
|
868
|
+
log10.error("Failed to get Shopify Store Properties", { shop, accessToken, url });
|
|
869
|
+
}
|
|
870
|
+
return res;
|
|
871
|
+
});
|
|
872
|
+
__publicField(ShopifyClient, "createAppSubscription", async (shop, accessToken, planName, price, returnUrl, trialDays, test) => {
|
|
873
|
+
const url = `https://${shop}/admin/api/${_ShopifyClient._shopify_api_version}/recurring_application_charges.json`;
|
|
874
|
+
const recurring_application_charge = {
|
|
875
|
+
name: planName,
|
|
876
|
+
price,
|
|
877
|
+
return_url: returnUrl,
|
|
878
|
+
trial_days: trialDays,
|
|
879
|
+
test
|
|
880
|
+
};
|
|
881
|
+
const res = await _ShopifyClient.genericShopifyPost(url, accessToken, { recurring_application_charge });
|
|
882
|
+
if (res.status >= 400) {
|
|
883
|
+
log10.error("Failed to create App Subscription", { shop, accessToken, url });
|
|
884
|
+
}
|
|
885
|
+
return res;
|
|
886
|
+
});
|
|
887
|
+
__publicField(ShopifyClient, "cancelAppSubscription", async (shop, accessToken, chargeId) => {
|
|
888
|
+
const url = `https://${shop}/admin/api/${_ShopifyClient._shopify_api_version}/recurring_application_charges/${chargeId}.json`;
|
|
889
|
+
const client2 = axiosHttpService();
|
|
890
|
+
const res = await client2.delete(url, { headers: { "X-Shopify-Access-Token": accessToken } });
|
|
891
|
+
if (res.status !== 200) {
|
|
892
|
+
log10.error("Failed to cancel recurring App billing", { shop, accessToken, url });
|
|
893
|
+
}
|
|
894
|
+
return res;
|
|
895
|
+
});
|
|
896
|
+
__publicField(ShopifyClient, "listAppSubscriptions", async (shop, accessToken) => {
|
|
897
|
+
const url = `https://${shop}/admin/api/${_ShopifyClient._shopify_api_version}/recurring_application_charges.json`;
|
|
898
|
+
const res = await _ShopifyClient.genericShopifyGet(url, accessToken);
|
|
899
|
+
if (res.status >= 400) {
|
|
900
|
+
log10.error("Failed to get App Subscriptions", { shop, accessToken, url });
|
|
901
|
+
}
|
|
902
|
+
return res;
|
|
903
|
+
});
|
|
904
|
+
__publicField(ShopifyClient, "genericShopifyPost", async (url, accessToken, payload) => {
|
|
905
|
+
const client2 = axiosHttpService();
|
|
906
|
+
const res = await client2.post(url, payload, { headers: { "X-Shopify-Access-Token": accessToken, "Content-Type": "application/json" } });
|
|
907
|
+
log10.debug("Shopify Client Response", { res });
|
|
908
|
+
return res;
|
|
909
|
+
});
|
|
910
|
+
__publicField(ShopifyClient, "genericShopifyGet", async (url, accessToken) => {
|
|
911
|
+
const client2 = axiosHttpService();
|
|
912
|
+
const res = await client2.get(url, { headers: { "X-Shopify-Access-Token": accessToken } });
|
|
913
|
+
log10.debug("Shopify Client Response", { res });
|
|
914
|
+
return res;
|
|
915
|
+
});
|
|
916
|
+
__publicField(ShopifyClient, "genericShopifyPut", async (url, accessToken, payload) => {
|
|
917
|
+
const client2 = axiosHttpService();
|
|
918
|
+
const res = await client2.put(url, payload, { headers: { "X-Shopify-Access-Token": accessToken } });
|
|
919
|
+
log10.debug("Shopify Client Response", { res });
|
|
920
|
+
return res;
|
|
921
|
+
});
|
|
922
|
+
|
|
923
|
+
// src/helpers/input-validation-helper.ts
|
|
924
|
+
import * as log11 from "lambda-log";
|
|
925
|
+
var validateInput = (schema, input) => {
|
|
926
|
+
const { error: error7, value } = schema.validate(input);
|
|
927
|
+
if (error7) {
|
|
928
|
+
log11.info("", { error: error7 });
|
|
929
|
+
const httperr = HttpError.badRequest("Bad Request", {
|
|
930
|
+
errors: error7.details.map((detail) => ({
|
|
931
|
+
message: detail?.message,
|
|
932
|
+
key: detail?.context?.key,
|
|
933
|
+
path: detail?.path
|
|
934
|
+
}))
|
|
935
|
+
});
|
|
936
|
+
log11.info("", { httperr });
|
|
937
|
+
throw httperr;
|
|
938
|
+
}
|
|
939
|
+
return value;
|
|
940
|
+
};
|
|
941
|
+
|
|
942
|
+
// src/helpers/logging-helper.ts
|
|
943
|
+
import * as log12 from "lambda-log";
|
|
944
|
+
var stage = process?.env?.STAGE;
|
|
945
|
+
var configureLogger = (event, context, debug6 = true) => {
|
|
946
|
+
log12.options.meta.stage = stage;
|
|
947
|
+
log12.options.meta.source_name = context?.functionName || "unknown";
|
|
948
|
+
log12.options.meta.awsRequestId = context?.awsRequestId || "unknown";
|
|
949
|
+
log12.options.meta.lambdaEvent = event;
|
|
950
|
+
log12.options.debug = debug6;
|
|
951
|
+
};
|
|
952
|
+
|
|
953
|
+
// src/helpers/response-helper.ts
|
|
954
|
+
var success = (body) => {
|
|
955
|
+
return buildResponse(200, body);
|
|
956
|
+
};
|
|
957
|
+
var defaultError = {
|
|
958
|
+
message: "internalServerError"
|
|
959
|
+
};
|
|
960
|
+
var failure = (error7, statusCode = 500) => {
|
|
961
|
+
statusCode = error7?.statusCode ?? statusCode;
|
|
962
|
+
let body = defaultError;
|
|
963
|
+
if (error7?.body) {
|
|
964
|
+
body = error7.body;
|
|
965
|
+
} else if (error7?.message) {
|
|
966
|
+
body = { message: error7.message };
|
|
967
|
+
} else if (statusCode === 500) {
|
|
968
|
+
body = defaultError;
|
|
969
|
+
}
|
|
970
|
+
return buildResponse(statusCode, body);
|
|
971
|
+
};
|
|
972
|
+
var buildResponse = (statusCode, body = {}) => {
|
|
973
|
+
delete body.stack;
|
|
974
|
+
return {
|
|
975
|
+
statusCode,
|
|
976
|
+
headers: {
|
|
977
|
+
"Access-Control-Allow-Origin": "*",
|
|
978
|
+
"Access-Control-Allow-Credentials": true,
|
|
979
|
+
"cache-control": "max-age=86400",
|
|
980
|
+
Date: /* @__PURE__ */ new Date(),
|
|
981
|
+
"Last-Modified": /* @__PURE__ */ new Date(),
|
|
982
|
+
"Access-Control-Allow-Headers": "Content-Type, Content-Encoding"
|
|
983
|
+
},
|
|
984
|
+
body: JSON.stringify(body)
|
|
985
|
+
};
|
|
986
|
+
};
|
|
987
|
+
|
|
988
|
+
// src/helpers/shopify-helper.ts
|
|
989
|
+
import { createHmac } from "crypto";
|
|
990
|
+
import * as log13 from "lambda-log";
|
|
991
|
+
|
|
992
|
+
// src/libs/url.ts
|
|
993
|
+
var mapObjectToQueryString = (inputObj) => {
|
|
994
|
+
const qsp = Object.entries(inputObj).sort((a, b) => a[0] < b[0] ? -1 : 1);
|
|
995
|
+
const urlParams = new URLSearchParams();
|
|
996
|
+
qsp.map((p2) => {
|
|
997
|
+
urlParams.append(p2[0], p2[1]);
|
|
998
|
+
});
|
|
999
|
+
const qs = urlParams.toString();
|
|
1000
|
+
return qs;
|
|
1001
|
+
};
|
|
1002
|
+
|
|
1003
|
+
// src/helpers/shopify-helper.ts
|
|
1004
|
+
var isShopifyRequestValid = (validationParams, validationHmac, shopifyAppApiSecret) => {
|
|
1005
|
+
delete validationParams.hmac;
|
|
1006
|
+
const hmacString = mapObjectToQueryString(validationParams);
|
|
1007
|
+
const generatedHash = createHmac("sha256", shopifyAppApiSecret).update(hmacString).digest("hex");
|
|
1008
|
+
return generatedHash === validationHmac;
|
|
1009
|
+
};
|
|
1010
|
+
var validateShopifyRequest = (validationParams, validationHmac, shopifyAppApiSecret) => {
|
|
1011
|
+
log13.info("Validating shopify request is authentic", { validationParams });
|
|
1012
|
+
const isValid = isShopifyRequestValid(validationParams, validationHmac, shopifyAppApiSecret);
|
|
1013
|
+
if (!isValid) {
|
|
1014
|
+
const message = "Failed: Shopify Request hmac validation";
|
|
1015
|
+
log13.error(message);
|
|
1016
|
+
throw HttpError.badRequest(message);
|
|
1017
|
+
}
|
|
1018
|
+
log13.info("Sucess: Shopify Request hmac validation");
|
|
1019
|
+
return true;
|
|
1020
|
+
};
|
|
1021
|
+
|
|
1022
|
+
// node_modules/@adtrackify/at-tracking-event-types/dist/index.js
|
|
1023
|
+
var s = ((n) => (n.PENDING = "pending", n.ACTIVE = "active", n.INACTIVE = "inactive", n))(s || {});
|
|
1024
|
+
var g = ((i) => (i.FACEBOOK = "facebook", i.TIKTOK = "tiktok", i.GOOGLE_ADS = "googleAds", i.GOOGLE_ANALYTICS_4 = "googleAnalytics4", i.HUBSPOT = "hubspot", i.WEBHOOK = "webhook", i.CUSTOM_HTML = "customHTML", i.CUSTOM_JS = "customJS", i.SNAPCHAT = "snapchat", i.TWITTER = "twitter", i.REDDIT = "reddit", i))(g || {});
|
|
1025
|
+
var c = ((n) => (n.HEADER = "header", n.FOOTER = "footer", n.BODY = "body", n))(c || {});
|
|
1026
|
+
var p = ((o) => (o.STARTED = "started", o.COMPLETED = "completed", o.UNINSTALLED = "uninstalled", o.FAILED = "failed", o.NONE = "none", o))(p || {});
|
|
1027
|
+
var d = ((e) => (e.ACTIVE = "active", e.CANCELLED = "cancelled", e.DECLINED = "declined", e.EXPIRED = "expired", e.FROZEN = "frozen", e.PENDING = "pending", e.NOT_SUBMITTED = "na", e))(d || {});
|
|
1028
|
+
var f = ((a) => (a.MONTHLY = "monthly", a.YEARLY = "yearly", a))(f || {});
|
|
1029
|
+
var m = ((r) => (r.CURRENT = "current", r.PAST_DUE = "past_due", r.CANCELLED = "cancelled", r.FAILED = "failed", r))(m || {});
|
|
1030
|
+
var l = ((e) => (e.ACTIVE = "active", e.CANCELLED = "cancelled", e.DECLINED = "declined", e.EXPIRED = "expired", e.FROZEN = "frozen", e.PENDING = "pending", e.NOT_SUBMITTED = "na", e))(l || {});
|
|
1031
|
+
var u = ((n) => (n.STRIPE = "stripe", n.PAYPAL = "paypal", n.SHOPIFY = "shopify", n))(u || {});
|
|
1032
|
+
var x = ((t) => (t.ADD_PAYMENT_INFO = "add_payment_info", t.ADD_SHIPPING_INFO = "add_shipping_info", t.ADD_TO_CART = "add_to_cart", t.ADD_TO_WISHLIST = "add_to_wishlist", t.INITIATE_CHECKOUT = "initiate_checkout", t.LEAD = "lead", t.LOGIN = "login", t.PAGE_VIEW = "page_view", t.PURCHASE = "purchase", t.REFUND = "refund", t.SEARCH = "search", t.SIGN_UP = "sign_up", t.VIEW_CART = "view_cart", t.VIEW_CONTENT = "view_content", t.SELECT_SHIPPING_METHOD = "select_shipping_method", t.VIRTUALIZED_VIEWED_PAYMENT_FORM = "virtualized_viewd_payment_form", t.METRIC = "metric", t.WEB_VITAL = "web_vital", t))(x || {});
|
|
1033
|
+
var C = ((r) => (r.TRACKING = "tracking", r.METRIC = "metric", r.IDENTIFY = "identify", r.LOG = "log", r))(C || {});
|
|
1034
|
+
|
|
1035
|
+
// src/helpers/subscription-helper.ts
|
|
1036
|
+
var StripeBillingMap = {
|
|
1037
|
+
dev2: {
|
|
1038
|
+
"free": "price_1JzjbKK7krGh4037ezNbGJEm",
|
|
1039
|
+
"starter_monthly": "price_1JwzsGK7krGh4037Li0hPpsZ",
|
|
1040
|
+
"starter_yearly": "price_1JwzsGK7krGh4037Li0hPpsZ",
|
|
1041
|
+
"scale_monthly": "price_1JzjcSK7krGh4037yh34LPk3",
|
|
1042
|
+
"scale_yearly": "price_1JzjcSK7krGh4037QiBJYfnD",
|
|
1043
|
+
"growth_monthly": "price_1Jzje1K7krGh4037KErHBp5N",
|
|
1044
|
+
"growth_yearly": "price_1Jzje1K7krGh4037MhCUhTDh"
|
|
1045
|
+
},
|
|
1046
|
+
qa2: {
|
|
1047
|
+
"free": "price_1JzjbKK7krGh4037ezNbGJEm",
|
|
1048
|
+
"starter_monthly": "price_1JwzsGK7krGh4037Li0hPpsZ",
|
|
1049
|
+
"starter_yearly": "price_1JwzsGK7krGh4037Li0hPpsZ",
|
|
1050
|
+
"scale_monthly": "price_1JzjcSK7krGh4037yh34LPk3",
|
|
1051
|
+
"scale_yearly": "price_1JzjcSK7krGh4037QiBJYfnD",
|
|
1052
|
+
"growth_monthly": "price_1Jzje1K7krGh4037KErHBp5N",
|
|
1053
|
+
"growth_yearly": "price_1Jzje1K7krGh4037MhCUhTDh"
|
|
1054
|
+
},
|
|
1055
|
+
prod2: {
|
|
1056
|
+
"free": "price_1KAFsIK7krGh4037RsaAYMEl",
|
|
1057
|
+
"starter_monthly": "price_1KAFsMK7krGh4037Lz3P0ksU",
|
|
1058
|
+
"starter_yearly": "price_1KAFsMK7krGh4037Dj1WmSi8",
|
|
1059
|
+
"scale_monthly": "price_1KAFrxK7krGh4037zWCdaTly",
|
|
1060
|
+
"scale_yearly": "price_1KAFrxK7krGh40375fhymyWP",
|
|
1061
|
+
"growth_monthly": "price_1KAFs7K7krGh4037JChjz5Cr",
|
|
1062
|
+
"growth_yearly": "price_1KAFs7K7krGh4037rZElg12s"
|
|
1063
|
+
},
|
|
1064
|
+
dev: {
|
|
1065
|
+
"free": "price_1JzjbKK7krGh4037ezNbGJEm",
|
|
1066
|
+
"starter_monthly": "price_1JwzsGK7krGh4037Li0hPpsZ",
|
|
1067
|
+
"starter_yearly": "price_1JwzsGK7krGh4037Li0hPpsZ",
|
|
1068
|
+
"scale_monthly": "price_1JzjcSK7krGh4037yh34LPk3",
|
|
1069
|
+
"scale_yearly": "price_1JzjcSK7krGh4037QiBJYfnD",
|
|
1070
|
+
"growth_monthly": "price_1Jzje1K7krGh4037KErHBp5N",
|
|
1071
|
+
"growth_yearly": "price_1Jzje1K7krGh4037MhCUhTDh"
|
|
1072
|
+
},
|
|
1073
|
+
qa: {
|
|
1074
|
+
"free": "price_1JzjbKK7krGh4037ezNbGJEm",
|
|
1075
|
+
"starter_monthly": "price_1JwzsGK7krGh4037Li0hPpsZ",
|
|
1076
|
+
"starter_yearly": "price_1JwzsGK7krGh4037Li0hPpsZ",
|
|
1077
|
+
"scale_monthly": "price_1JzjcSK7krGh4037yh34LPk3",
|
|
1078
|
+
"scale_yearly": "price_1JzjcSK7krGh4037QiBJYfnD",
|
|
1079
|
+
"growth_monthly": "price_1Jzje1K7krGh4037KErHBp5N",
|
|
1080
|
+
"growth_yearly": "price_1Jzje1K7krGh4037MhCUhTDh"
|
|
1081
|
+
},
|
|
1082
|
+
prod: {
|
|
1083
|
+
"free": "price_1KAFsIK7krGh4037RsaAYMEl",
|
|
1084
|
+
"starter_monthly": "price_1KAFsMK7krGh4037Lz3P0ksU",
|
|
1085
|
+
"starter_yearly": "price_1KAFsMK7krGh4037Dj1WmSi8",
|
|
1086
|
+
"scale_monthly": "price_1KAFrxK7krGh4037zWCdaTly",
|
|
1087
|
+
"scale_yearly": "price_1KAFrxK7krGh40375fhymyWP",
|
|
1088
|
+
"growth_monthly": "price_1KAFs7K7krGh4037JChjz5Cr",
|
|
1089
|
+
"growth_yearly": "price_1KAFs7K7krGh4037rZElg12s"
|
|
1090
|
+
}
|
|
1091
|
+
};
|
|
1092
|
+
var CommonPlanInfo = [
|
|
1093
|
+
//'60-day Risk Free Trial',
|
|
1094
|
+
"Free Server Side Tracking & Conversion API",
|
|
1095
|
+
"MultiPixel Support (Multiple facebook, tiktok, etc)",
|
|
1096
|
+
"Corrects Facebook Conversion Tracking post IOS14",
|
|
1097
|
+
"Increase ROAS & Attribution Data",
|
|
1098
|
+
"Enhanced Fingerprinting & Identity Resolution",
|
|
1099
|
+
"Unlimited Integrations",
|
|
1100
|
+
"Advanced Integrations (Webhooks, Custom JS/HTML, Hubspot)"
|
|
1101
|
+
];
|
|
1102
|
+
var SubscriptionPlanSeedItems = {
|
|
1103
|
+
items: [
|
|
1104
|
+
{
|
|
1105
|
+
id: 1,
|
|
1106
|
+
planName: "free",
|
|
1107
|
+
displayName: "Free",
|
|
1108
|
+
sku: "ADT-001",
|
|
1109
|
+
description: "Free Plan - Monthly",
|
|
1110
|
+
price: "0",
|
|
1111
|
+
displayPrice: "$0",
|
|
1112
|
+
billingFrequency: f.MONTHLY,
|
|
1113
|
+
trialLengthDays: 0,
|
|
1114
|
+
trialRequiresCreditCard: false,
|
|
1115
|
+
planDesc: [
|
|
1116
|
+
...CommonPlanInfo,
|
|
1117
|
+
"Free Up to 500 orders/month (50,000 events)*"
|
|
1118
|
+
],
|
|
1119
|
+
unitPriceText: "try now - free forever",
|
|
1120
|
+
isHighlighted: false,
|
|
1121
|
+
isBanner: false
|
|
1122
|
+
},
|
|
1123
|
+
// STARTER PLANS
|
|
1124
|
+
{
|
|
1125
|
+
id: 2,
|
|
1126
|
+
planName: "starter_monthly",
|
|
1127
|
+
displayName: "Starter",
|
|
1128
|
+
sku: "ADT-002",
|
|
1129
|
+
description: "Starter Plan - Monthly",
|
|
1130
|
+
price: "79.99",
|
|
1131
|
+
displayPrice: "$79.99",
|
|
1132
|
+
billingFrequency: f.MONTHLY,
|
|
1133
|
+
trialLengthDays: 60,
|
|
1134
|
+
trialRequiresCreditCard: false,
|
|
1135
|
+
planDesc: [
|
|
1136
|
+
"60-day Risk Free Trial",
|
|
1137
|
+
...CommonPlanInfo,
|
|
1138
|
+
"Up to 2,000 orders/month (250,000 events)*"
|
|
1139
|
+
],
|
|
1140
|
+
isHighlighted: true,
|
|
1141
|
+
isBanner: true,
|
|
1142
|
+
bannerColor: "blue",
|
|
1143
|
+
bannerText: "MOST POPULAR"
|
|
1144
|
+
},
|
|
1145
|
+
{
|
|
1146
|
+
id: 3,
|
|
1147
|
+
planName: "starter_yearly",
|
|
1148
|
+
displayName: "Starter",
|
|
1149
|
+
sku: "ADT-003",
|
|
1150
|
+
description: "Starter Plan - Yearly",
|
|
1151
|
+
price: "767.90",
|
|
1152
|
+
displayPrice: "$63.99",
|
|
1153
|
+
billingFrequency: f.YEARLY,
|
|
1154
|
+
trialLengthDays: 30,
|
|
1155
|
+
trialRequiresCreditCard: false,
|
|
1156
|
+
planDesc: [
|
|
1157
|
+
"60-day Risk Free Trial",
|
|
1158
|
+
...CommonPlanInfo,
|
|
1159
|
+
"Up to 2,000 orders/month (250,000 events)*"
|
|
1160
|
+
],
|
|
1161
|
+
unitPriceText: "billed yearly ($767.90) - 20% savings",
|
|
1162
|
+
isHighlighted: true,
|
|
1163
|
+
isBanner: true,
|
|
1164
|
+
bannerColor: "blue",
|
|
1165
|
+
bannerText: "MOST POPULAR"
|
|
1166
|
+
},
|
|
1167
|
+
// SCALE PLANS
|
|
1168
|
+
{
|
|
1169
|
+
id: 4,
|
|
1170
|
+
planName: "scale_monthly",
|
|
1171
|
+
displayName: "Scale",
|
|
1172
|
+
sku: "ADT-004",
|
|
1173
|
+
description: "Scale Plan - Monthly",
|
|
1174
|
+
price: "199.99",
|
|
1175
|
+
displayPrice: "$199.99",
|
|
1176
|
+
billingFrequency: f.MONTHLY,
|
|
1177
|
+
trialLengthDays: 60,
|
|
1178
|
+
trialRequiresCreditCard: false,
|
|
1179
|
+
planDesc: [
|
|
1180
|
+
"60-day Risk Free Trial",
|
|
1181
|
+
...CommonPlanInfo,
|
|
1182
|
+
"Up to 7,500 orders/month (750,000 events)*"
|
|
1183
|
+
],
|
|
1184
|
+
unitPriceText: "",
|
|
1185
|
+
isHighlighted: false,
|
|
1186
|
+
isBanner: false
|
|
1187
|
+
},
|
|
1188
|
+
{
|
|
1189
|
+
id: 5,
|
|
1190
|
+
planName: "scale_yearly",
|
|
1191
|
+
displayName: "Scale",
|
|
1192
|
+
sku: "ADT-005",
|
|
1193
|
+
description: "Scale Plan - Yearly",
|
|
1194
|
+
price: "1823.91",
|
|
1195
|
+
displayPrice: "$151.99",
|
|
1196
|
+
billingFrequency: f.YEARLY,
|
|
1197
|
+
trialLengthDays: 60,
|
|
1198
|
+
trialRequiresCreditCard: false,
|
|
1199
|
+
planDesc: [
|
|
1200
|
+
"60-day Risk Free Trial",
|
|
1201
|
+
...CommonPlanInfo,
|
|
1202
|
+
"Up to 7,500 orders/month (750,000 events)*"
|
|
1203
|
+
],
|
|
1204
|
+
unitPriceText: "billed yearly ($1823.91) - 24% savings",
|
|
1205
|
+
isHighlighted: false,
|
|
1206
|
+
isBanner: false
|
|
1207
|
+
}
|
|
1208
|
+
// // GROWTH PLANS
|
|
1209
|
+
// {
|
|
1210
|
+
// id: 6,
|
|
1211
|
+
// planName: 'growth_monthly',
|
|
1212
|
+
// displayName: 'Growth',
|
|
1213
|
+
// sku: 'ADT-006',
|
|
1214
|
+
// description: 'Growth Plan - Monthly',
|
|
1215
|
+
// price: '199.99',
|
|
1216
|
+
// displayPrice: '$199.99',
|
|
1217
|
+
// billingFrequency: PLAN_BILLING_FREQUENCY.MONTHLY,
|
|
1218
|
+
// trialLengthDays: 60,
|
|
1219
|
+
// trialRequiresCreditCard: false,
|
|
1220
|
+
// planDesc: [
|
|
1221
|
+
// '60-day Risk Free Trial',
|
|
1222
|
+
// ...CommonPlanInfo,
|
|
1223
|
+
// '250,000 tracking events/mo'
|
|
1224
|
+
// ],
|
|
1225
|
+
// unitPriceText: 'billed yearly ($540) - 25% savings',
|
|
1226
|
+
// isHighlighted: false,
|
|
1227
|
+
// isBanner: true,
|
|
1228
|
+
// bannerColor: 'orange',
|
|
1229
|
+
// bannerText: 'BEST VALUE'
|
|
1230
|
+
// }, {
|
|
1231
|
+
// id: 7,
|
|
1232
|
+
// planName: 'growth_yearly',
|
|
1233
|
+
// displayName: 'Growth',
|
|
1234
|
+
// sku: 'ADT-007',
|
|
1235
|
+
// description: 'Growth Plan - Yearly',
|
|
1236
|
+
// price: '1799.91',
|
|
1237
|
+
// displayPrice: '$149.99',
|
|
1238
|
+
// billingFrequency: PLAN_BILLING_FREQUENCY.YEARLY,
|
|
1239
|
+
// trialLengthDays: 60,
|
|
1240
|
+
// trialRequiresCreditCard: false,
|
|
1241
|
+
// planDesc: [
|
|
1242
|
+
// '30-day Risk Free Trial',
|
|
1243
|
+
// 'Fixes IOS14.5 tracking',
|
|
1244
|
+
// 'Multi Pixel Support',
|
|
1245
|
+
// 'Enhanced Tracking / Attribution',
|
|
1246
|
+
// 'Unlimited Facebook Conversion API',
|
|
1247
|
+
// 'Unlimited Integrations',
|
|
1248
|
+
// 'Easy no code setup',
|
|
1249
|
+
// '100,000 tracking events/mo'
|
|
1250
|
+
// ],
|
|
1251
|
+
// unitPriceText: 'billed yearly ($1799.91) - 25% savings',
|
|
1252
|
+
// isHighlighted: false,
|
|
1253
|
+
// isBanner: true,
|
|
1254
|
+
// bannerColor: 'orange',
|
|
1255
|
+
// bannerText: 'BEST VALUE'
|
|
1256
|
+
// },
|
|
1257
|
+
]
|
|
1258
|
+
};
|
|
1259
|
+
var getPlanDetails = (planId, stage2) => {
|
|
1260
|
+
const plan = SubscriptionPlanSeedItems.items.filter((x2) => x2.id === planId)[0];
|
|
1261
|
+
plan.stripePriceId = StripeBillingMap[stage2][plan.planName];
|
|
1262
|
+
return plan;
|
|
1263
|
+
};
|
|
1264
|
+
var getPlanByStripePriceId = (stripePriceId, stage2) => {
|
|
1265
|
+
const stripePriceIds = StripeBillingMap[stage2];
|
|
1266
|
+
const planName = Object.keys(stripePriceIds).find((key) => stripePriceIds[key] === stripePriceId);
|
|
1267
|
+
const plan = SubscriptionPlanSeedItems.items.filter((x2) => x2.planName === planName)[0];
|
|
1268
|
+
plan.stripePriceId = stripePriceId;
|
|
1269
|
+
return plan;
|
|
1270
|
+
};
|
|
1271
|
+
|
|
1272
|
+
// src/libs/crypto.ts
|
|
1273
|
+
import crypto from "crypto";
|
|
1274
|
+
var generatePublicKey = () => {
|
|
1275
|
+
const publicKey = crypto.randomBytes(26);
|
|
1276
|
+
return publicKey.toString("utf8");
|
|
1277
|
+
};
|
|
1278
|
+
|
|
1279
|
+
// src/types/internal-events/event-detail-types.ts
|
|
1280
|
+
var ADTRACKIFY_EVENT_TYPES = /* @__PURE__ */ ((ADTRACKIFY_EVENT_TYPES2) => {
|
|
1281
|
+
ADTRACKIFY_EVENT_TYPES2["NOTIFY_SHOPIFY_SUBSCRIPTION_CREATED"] = "shopifySubscriptionCreated";
|
|
1282
|
+
ADTRACKIFY_EVENT_TYPES2["NOTIFY_SUBSCRIPTION_SIGNUP_COMPLETED"] = "subscription.signupCompleted";
|
|
1283
|
+
ADTRACKIFY_EVENT_TYPES2["REQUEST_SET_ACCOUNT_OWNER"] = "setAccountOwner";
|
|
1284
|
+
ADTRACKIFY_EVENT_TYPES2["REQUEST_SET_ACCOUNT_SUBSCRIPTION_ID"] = "setAccountSubscriptionId";
|
|
1285
|
+
return ADTRACKIFY_EVENT_TYPES2;
|
|
1286
|
+
})(ADTRACKIFY_EVENT_TYPES || {});
|
|
1287
|
+
var ADTRACKIFY_EVENT_SOURCES = /* @__PURE__ */ ((ADTRACKIFY_EVENT_SOURCES2) => {
|
|
1288
|
+
ADTRACKIFY_EVENT_SOURCES2["SUBSCRIPTIONS"] = "subscriptions";
|
|
1289
|
+
return ADTRACKIFY_EVENT_SOURCES2;
|
|
1290
|
+
})(ADTRACKIFY_EVENT_SOURCES || {});
|
|
1291
|
+
var PostmarkRequestType = /* @__PURE__ */ ((PostmarkRequestType2) => {
|
|
1292
|
+
PostmarkRequestType2["SINGLE_EMAIL"] = "single_email";
|
|
1293
|
+
PostmarkRequestType2["TEMPLATE_EMAIL"] = "template_email";
|
|
1294
|
+
return PostmarkRequestType2;
|
|
1295
|
+
})(PostmarkRequestType || {});
|
|
1296
|
+
var ADTRACKIFY_EVENT_BRIDGE_EVENTS = /* @__PURE__ */ ((ADTRACKIFY_EVENT_BRIDGE_EVENTS2) => {
|
|
1297
|
+
ADTRACKIFY_EVENT_BRIDGE_EVENTS2["SEND_POSTMARK_EMAIL"] = "integration.sendPostmarkEmail";
|
|
1298
|
+
ADTRACKIFY_EVENT_BRIDGE_EVENTS2["NOTIFY_SHOPIFY_SUBSCRIPTION_CREATED"] = "shopifySubscriptionCreated";
|
|
1299
|
+
ADTRACKIFY_EVENT_BRIDGE_EVENTS2["NOTIFY_SUBSCRIPTION_SIGNUP_COMPLETED"] = "subscription.signupCompleted";
|
|
1300
|
+
ADTRACKIFY_EVENT_BRIDGE_EVENTS2["REQUEST_SET_ACCOUNT_OWNER"] = "setAccountOwner";
|
|
1301
|
+
ADTRACKIFY_EVENT_BRIDGE_EVENTS2["REQUEST_SET_ACCOUNT_SUBSCRIPTION_ID"] = "setAccountSubscriptionId";
|
|
1302
|
+
return ADTRACKIFY_EVENT_BRIDGE_EVENTS2;
|
|
1303
|
+
})(ADTRACKIFY_EVENT_BRIDGE_EVENTS || {});
|
|
1304
|
+
|
|
1305
|
+
// src/services/eventbridge-integration-service.ts
|
|
1306
|
+
var EventBridgeIntegrationService = class {
|
|
1307
|
+
eventBridgeClient;
|
|
1308
|
+
EVENT_BUS_NAME;
|
|
1309
|
+
constructor(eventBusName) {
|
|
1310
|
+
this.eventBridgeClient = new EventBridgeClient(eventBusName);
|
|
1311
|
+
this.EVENT_BUS_NAME = eventBusName;
|
|
1312
|
+
}
|
|
1313
|
+
sendPostmarkEmailEvent = async (eventSource, postmarkMessage, postmarkServerToken) => {
|
|
1314
|
+
return await this.eventBridgeClient.buildAndSendEvent(
|
|
1315
|
+
eventSource,
|
|
1316
|
+
"integration.sendPostmarkEmail" /* SEND_POSTMARK_EMAIL */,
|
|
1317
|
+
{
|
|
1318
|
+
postmarkMessage,
|
|
1319
|
+
postmarkRequestType: "single_email" /* SINGLE_EMAIL */,
|
|
1320
|
+
postmarkServerToken
|
|
1321
|
+
}
|
|
1322
|
+
);
|
|
1323
|
+
};
|
|
1324
|
+
sendPostmarkTemplatedEmailEvent = async (eventSource, postmarkMessage, postmarkServerToken) => {
|
|
1325
|
+
return await this.eventBridgeClient.buildAndSendEvent(
|
|
1326
|
+
eventSource,
|
|
1327
|
+
"integration.sendPostmarkEmail" /* SEND_POSTMARK_EMAIL */,
|
|
1328
|
+
{
|
|
1329
|
+
postmarkMessage,
|
|
1330
|
+
postmarkRequestType: "template_email" /* TEMPLATE_EMAIL */,
|
|
1331
|
+
postmarkServerToken
|
|
1332
|
+
}
|
|
1333
|
+
);
|
|
1334
|
+
};
|
|
1335
|
+
};
|
|
1336
|
+
export {
|
|
1337
|
+
ADTRACKIFY_EVENT_BRIDGE_EVENTS,
|
|
1338
|
+
ADTRACKIFY_EVENT_SOURCES,
|
|
1339
|
+
ADTRACKIFY_EVENT_TYPES,
|
|
1340
|
+
AccountsClient,
|
|
1341
|
+
CognitoClient,
|
|
1342
|
+
CommonPlanInfo,
|
|
1343
|
+
DestinationsClient,
|
|
1344
|
+
DynamoDbClient,
|
|
1345
|
+
EventBridgeClient,
|
|
1346
|
+
EventBridgeIntegrationService,
|
|
1347
|
+
HttpError,
|
|
1348
|
+
HttpStatusCodes,
|
|
1349
|
+
PostmarkRequestType,
|
|
1350
|
+
S3Client,
|
|
1351
|
+
SQSClient,
|
|
1352
|
+
ShopifyAppInstallClient,
|
|
1353
|
+
ShopifyClient,
|
|
1354
|
+
StripeBillingMap,
|
|
1355
|
+
SubscriptionPlanSeedItems,
|
|
1356
|
+
UsersAuthClient,
|
|
1357
|
+
axiosHttpService,
|
|
1358
|
+
buildResponse,
|
|
1359
|
+
configureLogger,
|
|
1360
|
+
dictToAwsAttributes,
|
|
1361
|
+
failure,
|
|
1362
|
+
generatePublicKey,
|
|
1363
|
+
getCurrentDate,
|
|
1364
|
+
getCurrentTimestamp,
|
|
1365
|
+
getDateFromTimestamp,
|
|
1366
|
+
getPlanByStripePriceId,
|
|
1367
|
+
getPlanDetails,
|
|
1368
|
+
isShopifyRequestValid,
|
|
1369
|
+
mapObjectToQueryString,
|
|
1370
|
+
success,
|
|
1371
|
+
validateInput,
|
|
1372
|
+
validateShopifyRequest
|
|
1373
|
+
};
|
|
1374
|
+
//# sourceMappingURL=index.esm.js.map
|