@adtrackify/at-service-common 1.1.19 → 1.1.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +12 -12
- package/.eslintignore +3 -0
- package/.vscode/settings.json +9 -9
- package/build.js +27 -10
- package/dist/index.d.ts +41 -41
- package/dist/index.esm.js +1335 -0
- package/dist/index.esm.js.map +7 -0
- package/dist/index.js +249 -122
- package/dist/index.js.map +4 -4
- package/jest.config.ts +40 -40
- package/package.json +25 -29
- package/src/__tests__/helpers/subscription-helper.spec.ts +1 -1
- package/src/clients/generic/axios.d.ts +7 -7
- package/src/clients/generic/eventbridge-client.ts +1 -1
- package/src/clients/generic/http-client.ts +2 -3
- package/src/clients/generic/index.ts +5 -5
- package/src/clients/index.ts +3 -3
- package/src/clients/internal-api/accounts-client.ts +2 -2
- package/src/clients/internal-api/destinations-client.ts +2 -2
- package/src/clients/internal-api/index.ts +4 -4
- package/src/clients/internal-api/shopify-app-install-client.ts +4 -4
- package/src/clients/internal-api/users-auth-client.ts +4 -3
- package/src/clients/third-party/index.ts +1 -1
- package/src/clients/third-party/shopify-client.ts +1 -1
- package/src/helpers/index.ts +5 -5
- package/src/helpers/input-validation-helper.ts +1 -1
- package/src/helpers/shopify-helper.ts +2 -2
- package/src/index.ts +5 -5
- package/src/libs/index.ts +6 -6
- package/src/libs/url.ts +9 -9
- package/src/services/eventbridge-integration-service.ts +1 -1
- package/src/services/index.ts +1 -1
- package/src/types/index.ts +1 -1
- package/src/types/internal-events/event-detail-types.ts +9 -9
- package/src/types/internal-events/index.ts +1 -1
- package/tsconfig.json +2 -3
package/dist/index.js
CHANGED
|
@@ -1,14 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
1
3
|
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
2
8
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
3
30
|
var __publicField = (obj, key, value) => {
|
|
4
31
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
32
|
return value;
|
|
6
33
|
};
|
|
7
34
|
|
|
35
|
+
// src/index.ts
|
|
36
|
+
var src_exports = {};
|
|
37
|
+
__export(src_exports, {
|
|
38
|
+
ADTRACKIFY_EVENT_BRIDGE_EVENTS: () => ADTRACKIFY_EVENT_BRIDGE_EVENTS,
|
|
39
|
+
ADTRACKIFY_EVENT_SOURCES: () => ADTRACKIFY_EVENT_SOURCES,
|
|
40
|
+
ADTRACKIFY_EVENT_TYPES: () => ADTRACKIFY_EVENT_TYPES,
|
|
41
|
+
AccountsClient: () => AccountsClient,
|
|
42
|
+
CognitoClient: () => CognitoClient,
|
|
43
|
+
CommonPlanInfo: () => CommonPlanInfo,
|
|
44
|
+
DestinationsClient: () => DestinationsClient,
|
|
45
|
+
DynamoDbClient: () => DynamoDbClient,
|
|
46
|
+
EventBridgeClient: () => EventBridgeClient,
|
|
47
|
+
EventBridgeIntegrationService: () => EventBridgeIntegrationService,
|
|
48
|
+
HttpError: () => HttpError,
|
|
49
|
+
HttpStatusCodes: () => HttpStatusCodes,
|
|
50
|
+
PostmarkRequestType: () => PostmarkRequestType,
|
|
51
|
+
S3Client: () => S3Client,
|
|
52
|
+
ShopifyAppInstallClient: () => ShopifyAppInstallClient,
|
|
53
|
+
ShopifyClient: () => ShopifyClient,
|
|
54
|
+
StripeBillingMap: () => StripeBillingMap,
|
|
55
|
+
SubscriptionPlanSeedItems: () => SubscriptionPlanSeedItems,
|
|
56
|
+
UsersAuthClient: () => UsersAuthClient,
|
|
57
|
+
axiosHttpService: () => axiosHttpService,
|
|
58
|
+
buildResponse: () => buildResponse,
|
|
59
|
+
configureLogger: () => configureLogger,
|
|
60
|
+
dictToAwsAttributes: () => dictToAwsAttributes,
|
|
61
|
+
failure: () => failure,
|
|
62
|
+
generatePublicKey: () => generatePublicKey,
|
|
63
|
+
getCurrentDate: () => getCurrentDate,
|
|
64
|
+
getCurrentTimestamp: () => getCurrentTimestamp,
|
|
65
|
+
getDateFromTimestamp: () => getDateFromTimestamp,
|
|
66
|
+
getPlanByStripePriceId: () => getPlanByStripePriceId,
|
|
67
|
+
getPlanDetails: () => getPlanDetails,
|
|
68
|
+
isShopifyRequestValid: () => isShopifyRequestValid,
|
|
69
|
+
mapObjectToQueryString: () => mapObjectToQueryString,
|
|
70
|
+
success: () => success,
|
|
71
|
+
validateInput: () => validateInput,
|
|
72
|
+
validateShopifyRequest: () => validateShopifyRequest
|
|
73
|
+
});
|
|
74
|
+
module.exports = __toCommonJS(src_exports);
|
|
75
|
+
|
|
8
76
|
// src/clients/generic/dynamodb-client.ts
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
77
|
+
var import_client_dynamodb = require("@aws-sdk/client-dynamodb");
|
|
78
|
+
var import_lib_dynamodb = require("@aws-sdk/lib-dynamodb");
|
|
79
|
+
var log = __toESM(require("lambda-log"), 1);
|
|
12
80
|
var marshallOptions = {
|
|
13
81
|
convertEmptyValues: false,
|
|
14
82
|
removeUndefinedValues: false,
|
|
@@ -18,8 +86,8 @@ var unmarshallOptions = {
|
|
|
18
86
|
wrapNumbers: false
|
|
19
87
|
};
|
|
20
88
|
var translateConfig = { marshallOptions, unmarshallOptions };
|
|
21
|
-
var ddbClient = new DynamoDBClient({});
|
|
22
|
-
var client = DynamoDBDocument.from(ddbClient, translateConfig);
|
|
89
|
+
var ddbClient = new import_client_dynamodb.DynamoDBClient({});
|
|
90
|
+
var client = import_lib_dynamodb.DynamoDBDocument.from(ddbClient, translateConfig);
|
|
23
91
|
var _DynamoDbClient = class {
|
|
24
92
|
};
|
|
25
93
|
var DynamoDbClient = _DynamoDbClient;
|
|
@@ -126,13 +194,13 @@ __publicField(DynamoDbClient, "update", (params) => client.update(params));
|
|
|
126
194
|
__publicField(DynamoDbClient, "delete", (params) => client.delete(params));
|
|
127
195
|
|
|
128
196
|
// src/clients/generic/eventbridge-client.ts
|
|
129
|
-
|
|
130
|
-
|
|
197
|
+
var import_client_eventbridge = require("@aws-sdk/client-eventbridge");
|
|
198
|
+
var import_uuid = require("uuid");
|
|
131
199
|
|
|
132
200
|
// src/libs/dates.ts
|
|
133
|
-
|
|
201
|
+
var import_luxon = require("luxon");
|
|
134
202
|
var getCurrentTimestamp = () => {
|
|
135
|
-
return DateTime.utc().toJSDate().toISOString();
|
|
203
|
+
return import_luxon.DateTime.utc().toJSDate().toISOString();
|
|
136
204
|
};
|
|
137
205
|
var getDateFromTimestamp = (timestamp) => {
|
|
138
206
|
return timestamp.split("T")[0];
|
|
@@ -142,19 +210,19 @@ var getCurrentDate = () => {
|
|
|
142
210
|
};
|
|
143
211
|
|
|
144
212
|
// src/clients/generic/eventbridge-client.ts
|
|
145
|
-
|
|
213
|
+
var log2 = __toESM(require("lambda-log"), 1);
|
|
146
214
|
var EventBridgeClient = class {
|
|
147
215
|
eventBridge;
|
|
148
216
|
EVENT_BUS_NAME;
|
|
149
217
|
constructor(eventBusName) {
|
|
150
|
-
this.eventBridge = new
|
|
218
|
+
this.eventBridge = new import_client_eventbridge.EventBridgeClient({});
|
|
151
219
|
this.EVENT_BUS_NAME = eventBusName;
|
|
152
220
|
}
|
|
153
221
|
buildAndSendEvent = async (eventSource, eventType, eventData) => {
|
|
154
222
|
const event = this.buildEvent(eventType, eventData);
|
|
155
223
|
return await this.putEvent(eventSource, eventType, event);
|
|
156
224
|
};
|
|
157
|
-
buildEvent = (eventType, eventData, eventId =
|
|
225
|
+
buildEvent = (eventType, eventData, eventId = (0, import_uuid.v4)(), eventTime = getCurrentTimestamp()) => {
|
|
158
226
|
return {
|
|
159
227
|
eventId,
|
|
160
228
|
eventType,
|
|
@@ -169,10 +237,10 @@ var EventBridgeClient = class {
|
|
|
169
237
|
DetailType: detailType,
|
|
170
238
|
EventBusName: this.EVENT_BUS_NAME,
|
|
171
239
|
Source: source,
|
|
172
|
-
Time: new Date()
|
|
240
|
+
Time: /* @__PURE__ */ new Date()
|
|
173
241
|
}]
|
|
174
242
|
};
|
|
175
|
-
const putEventscommand = new PutEventsCommand(params);
|
|
243
|
+
const putEventscommand = new import_client_eventbridge.PutEventsCommand(params);
|
|
176
244
|
const response = await this.eventBridge.send(putEventscommand);
|
|
177
245
|
log2.debug(
|
|
178
246
|
"EventBus Event Published",
|
|
@@ -189,10 +257,9 @@ var EventBridgeClient = class {
|
|
|
189
257
|
};
|
|
190
258
|
|
|
191
259
|
// src/clients/generic/http-client.ts
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
import httpAdapter from "axios/lib/adapters/http";
|
|
260
|
+
var import_axios = __toESM(require("axios"), 1);
|
|
261
|
+
var import_https = __toESM(require("https"), 1);
|
|
262
|
+
var import_http = __toESM(require("axios/lib/adapters/http"), 1);
|
|
196
263
|
var httpResponse = (res = {}) => {
|
|
197
264
|
return {
|
|
198
265
|
headers: res?.header || {},
|
|
@@ -206,10 +273,9 @@ var handleAxiosError = (error7) => {
|
|
|
206
273
|
return error7.response ? httpResponse(error7.response) : httpResponse({ status: 500, data: { error: error7.request } });
|
|
207
274
|
};
|
|
208
275
|
var axiosHttpService = (config = {}) => {
|
|
209
|
-
config.adapter =
|
|
210
|
-
config.httpsAgent = new
|
|
211
|
-
const axiosService =
|
|
212
|
-
axiosRetry(axiosService, { retryDelay: axiosRetry.exponentialDelay, retries: 3 });
|
|
276
|
+
config.adapter = import_http.default;
|
|
277
|
+
config.httpsAgent = new import_https.default.Agent({ keepAlive: true });
|
|
278
|
+
const axiosService = import_axios.default.create(config);
|
|
213
279
|
return {
|
|
214
280
|
instance: () => axiosService,
|
|
215
281
|
get: (url, config2) => axiosService.get(url, config2).then(httpResponse, handleAxiosError),
|
|
@@ -222,14 +288,14 @@ var axiosHttpService = (config = {}) => {
|
|
|
222
288
|
};
|
|
223
289
|
|
|
224
290
|
// src/clients/generic/s3-client.ts
|
|
225
|
-
|
|
226
|
-
|
|
291
|
+
var import_client_s3 = require("@aws-sdk/client-s3");
|
|
292
|
+
var log3 = __toESM(require("lambda-log"), 1);
|
|
227
293
|
var S3Client = class {
|
|
228
294
|
s3;
|
|
229
295
|
constructor(region = "us-west-2") {
|
|
230
|
-
this.s3 = new S3({ region });
|
|
296
|
+
this.s3 = new import_client_s3.S3({ region });
|
|
231
297
|
}
|
|
232
|
-
async uploadJson(path, bucket, jsonData, ACL = ObjectCannedACL.private) {
|
|
298
|
+
async uploadJson(path, bucket, jsonData, ACL = import_client_s3.ObjectCannedACL.private) {
|
|
233
299
|
try {
|
|
234
300
|
const res = await this.s3.putObject({
|
|
235
301
|
ACL,
|
|
@@ -247,8 +313,8 @@ var S3Client = class {
|
|
|
247
313
|
};
|
|
248
314
|
|
|
249
315
|
// src/clients/generic/cognito-client.ts
|
|
250
|
-
|
|
251
|
-
|
|
316
|
+
var import_client_cognito_identity_provider = require("@aws-sdk/client-cognito-identity-provider");
|
|
317
|
+
var log4 = __toESM(require("lambda-log"), 1);
|
|
252
318
|
function dictToAwsAttributes(input) {
|
|
253
319
|
delete input.email;
|
|
254
320
|
delete input.password;
|
|
@@ -272,7 +338,7 @@ var CognitoClient = class {
|
|
|
272
338
|
USER_POOL_ID;
|
|
273
339
|
USER_POOL_NO_SECRET_CLIENT_ID;
|
|
274
340
|
constructor(userPoolId, userPoolNoSecretClientId) {
|
|
275
|
-
this.cognitoClient = new CognitoIdentityProvider({});
|
|
341
|
+
this.cognitoClient = new import_client_cognito_identity_provider.CognitoIdentityProvider({});
|
|
276
342
|
this.USER_POOL_ID = userPoolId;
|
|
277
343
|
this.USER_POOL_NO_SECRET_CLIENT_ID = userPoolNoSecretClientId;
|
|
278
344
|
}
|
|
@@ -386,7 +452,7 @@ var CognitoClient = class {
|
|
|
386
452
|
};
|
|
387
453
|
|
|
388
454
|
// src/clients/internal-api/destinations-client.ts
|
|
389
|
-
|
|
455
|
+
var log5 = __toESM(require("lambda-log"), 1);
|
|
390
456
|
var DestinationsClient = class {
|
|
391
457
|
BASE_API_URL;
|
|
392
458
|
DESTINATIONS_API_KEY;
|
|
@@ -423,7 +489,7 @@ var DestinationsClient = class {
|
|
|
423
489
|
};
|
|
424
490
|
|
|
425
491
|
// src/clients/internal-api/accounts-client.ts
|
|
426
|
-
|
|
492
|
+
var log6 = __toESM(require("lambda-log"), 1);
|
|
427
493
|
var AccountsClient = class {
|
|
428
494
|
BASE_API_URL;
|
|
429
495
|
ACCOUNTS_API_KEY;
|
|
@@ -501,54 +567,19 @@ var AccountsClient = class {
|
|
|
501
567
|
log6.info("add user account response", { response });
|
|
502
568
|
return response;
|
|
503
569
|
};
|
|
570
|
+
// setAccountSubscriptionId = async (accountId: string, subscriptionId: string): Promise<ApiResponse<any>> => {
|
|
571
|
+
// const client = await this.getClient();
|
|
572
|
+
// const pixelResponse = await client.get(`/px/${pixelId}/config`);
|
|
573
|
+
// log.debug('pixelResponse', { pixelResponse });
|
|
574
|
+
// return pixelResponse;
|
|
575
|
+
// };
|
|
504
576
|
};
|
|
505
577
|
|
|
506
578
|
// src/clients/internal-api/users-auth-client.ts
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
// src/helpers/shopify-helper.ts
|
|
510
|
-
import { createHmac } from "crypto";
|
|
511
|
-
import * as log7 from "lambda-log";
|
|
512
|
-
|
|
513
|
-
// src/libs/url.ts
|
|
514
|
-
var mapObjectToQueryString = (inputObj) => {
|
|
515
|
-
const qsp = Object.entries(inputObj).sort((a2, b) => a2[0] < b[0] ? -1 : 1);
|
|
516
|
-
const urlParams = new URLSearchParams();
|
|
517
|
-
qsp.map((p2) => {
|
|
518
|
-
urlParams.append(p2[0], p2[1]);
|
|
519
|
-
});
|
|
520
|
-
const qs = urlParams.toString();
|
|
521
|
-
return qs;
|
|
522
|
-
};
|
|
523
|
-
|
|
524
|
-
// src/helpers/shopify-helper.ts
|
|
525
|
-
var isShopifyRequestValid = (validationParams, validationHmac, shopifyAppApiSecret) => {
|
|
526
|
-
delete validationParams.hmac;
|
|
527
|
-
const hmacString = mapObjectToQueryString(validationParams);
|
|
528
|
-
const generatedHash = createHmac("sha256", shopifyAppApiSecret).update(hmacString).digest("hex");
|
|
529
|
-
return generatedHash === validationHmac;
|
|
530
|
-
};
|
|
531
|
-
var validateShopifyRequest = (validationParams, validationHmac, shopifyAppApiSecret) => {
|
|
532
|
-
log7.info("Validating shopify request is authentic", { validationParams });
|
|
533
|
-
const isValid = isShopifyRequestValid(validationParams, validationHmac, shopifyAppApiSecret);
|
|
534
|
-
if (!isValid) {
|
|
535
|
-
const message = "Failed: Shopify Request hmac validation";
|
|
536
|
-
log7.error(message);
|
|
537
|
-
throw HttpError.badRequest(message);
|
|
538
|
-
}
|
|
539
|
-
log7.info("Sucess: Shopify Request hmac validation");
|
|
540
|
-
return true;
|
|
541
|
-
};
|
|
542
|
-
|
|
543
|
-
// src/libs/crypto.ts
|
|
544
|
-
import crypto from "crypto";
|
|
545
|
-
var generatePublicKey = () => {
|
|
546
|
-
const publicKey = crypto.randomBytes(26);
|
|
547
|
-
return publicKey.toString("utf8");
|
|
548
|
-
};
|
|
579
|
+
var log7 = __toESM(require("lambda-log"), 1);
|
|
549
580
|
|
|
550
581
|
// src/libs/http-error.ts
|
|
551
|
-
|
|
582
|
+
var import_assert = require("assert");
|
|
552
583
|
var deepClone = (o = {}) => JSON.parse(JSON.stringify(o));
|
|
553
584
|
var containsStackTrace = (text = "") => /at.+\.js:\d+:\d+/.test(text);
|
|
554
585
|
var objectContainsStackTrace = (obj) => !obj ? false : containsStackTrace(JSON.stringify(obj));
|
|
@@ -577,18 +608,18 @@ var _HttpError = class extends Error {
|
|
|
577
608
|
statusCode;
|
|
578
609
|
isServerError;
|
|
579
610
|
constructor(statusCode, message, body, headers) {
|
|
580
|
-
|
|
611
|
+
(0, import_assert.strict)(statusCode in supportedStatusCodes, supportedStatusCodesMessage);
|
|
581
612
|
const isServerError = statusCode > 499;
|
|
582
|
-
|
|
613
|
+
(0, import_assert.strict)(
|
|
583
614
|
body === void 0 || typeof body === "object",
|
|
584
615
|
"body must be an object or omitted"
|
|
585
616
|
);
|
|
586
|
-
|
|
617
|
+
(0, import_assert.strict)(
|
|
587
618
|
headers === void 0 || typeof headers === "object",
|
|
588
619
|
"headers must be an object or omitted"
|
|
589
620
|
);
|
|
590
621
|
message = message ?? supportedStatusCodes[statusCode];
|
|
591
|
-
|
|
622
|
+
(0, import_assert.strict)(
|
|
592
623
|
!containsStackTrace(message) && !objectContainsStackTrace(body),
|
|
593
624
|
"the message or data parameters may not contain errors or stack traces"
|
|
594
625
|
);
|
|
@@ -706,19 +737,20 @@ var UsersAuthClient = class {
|
|
|
706
737
|
return user;
|
|
707
738
|
};
|
|
708
739
|
signupUser = async (userSignupRequest) => {
|
|
709
|
-
|
|
740
|
+
log7.info("Attempting to signup user", { email: userSignupRequest.email });
|
|
710
741
|
const client2 = await this.getClient();
|
|
711
742
|
const response = await client2.post("/signup", userSignupRequest);
|
|
712
743
|
if (response.status !== 200 || !response?.data?.user) {
|
|
713
744
|
const message = "User Signup Failed";
|
|
714
|
-
|
|
745
|
+
log7.error(message, { response });
|
|
715
746
|
throw new HttpError(500 /* INTERNAL_SERVER_ERROR */, message);
|
|
716
747
|
}
|
|
717
|
-
|
|
748
|
+
log7.info("User Signup Successful", { response });
|
|
718
749
|
return response.data.user;
|
|
719
750
|
};
|
|
751
|
+
//userName is same as user id
|
|
720
752
|
adminConfirmUser = async (email) => {
|
|
721
|
-
|
|
753
|
+
log7.info("Attempting to admin confirm user", { email });
|
|
722
754
|
const client2 = await this.getClient();
|
|
723
755
|
const response = await client2.post(
|
|
724
756
|
"/admin/confirm",
|
|
@@ -733,10 +765,10 @@ var UsersAuthClient = class {
|
|
|
733
765
|
);
|
|
734
766
|
if (response.status !== 200) {
|
|
735
767
|
const message = "Admin User Confirmation Failed";
|
|
736
|
-
|
|
768
|
+
log7.error(message, { response });
|
|
737
769
|
throw new HttpError(500 /* INTERNAL_SERVER_ERROR */, message);
|
|
738
770
|
}
|
|
739
|
-
|
|
771
|
+
log7.info("Admin User Confirmation Successful", { response });
|
|
740
772
|
return response;
|
|
741
773
|
};
|
|
742
774
|
getUserByEmail = async (email) => {
|
|
@@ -749,13 +781,13 @@ var UsersAuthClient = class {
|
|
|
749
781
|
email
|
|
750
782
|
}
|
|
751
783
|
});
|
|
752
|
-
|
|
784
|
+
log7.info("getUserResponse", { getUserResponse });
|
|
753
785
|
return getUserResponse;
|
|
754
786
|
};
|
|
755
787
|
};
|
|
756
788
|
|
|
757
789
|
// src/clients/internal-api/shopify-app-install-client.ts
|
|
758
|
-
|
|
790
|
+
var import_lambda_log = __toESM(require("lambda-log"), 1);
|
|
759
791
|
var ShopifyAppInstallClient = class {
|
|
760
792
|
BASE_API_URL;
|
|
761
793
|
SHOPIFY_APP_INSTALL_API_KEY;
|
|
@@ -780,25 +812,25 @@ var ShopifyAppInstallClient = class {
|
|
|
780
812
|
updateShopifyAppInstall = async (shopifyAppInstallId, updateShopifyAppInstallRequest) => {
|
|
781
813
|
const client2 = await this.getClient();
|
|
782
814
|
const response = await client2.put(`/${shopifyAppInstallId}`, updateShopifyAppInstallRequest);
|
|
783
|
-
|
|
815
|
+
import_lambda_log.default.info("updateShopifyAppInstall", { response });
|
|
784
816
|
return response;
|
|
785
817
|
};
|
|
786
818
|
getShopifyAppInstall = async (shopifyAppInstallId) => {
|
|
787
819
|
const client2 = await this.getClient();
|
|
788
820
|
const response = await client2.get(`/${shopifyAppInstallId}`);
|
|
789
|
-
|
|
821
|
+
import_lambda_log.default.info("getShopifyAppInstall", { response });
|
|
790
822
|
return response;
|
|
791
823
|
};
|
|
792
824
|
getShopifyAppInstallByShop = async (shop) => {
|
|
793
825
|
const client2 = await this.getClient();
|
|
794
826
|
const response = await client2.get(`/?shop=${shop}`);
|
|
795
|
-
|
|
827
|
+
import_lambda_log.default.info("getShopifyAppInstallByShop", { response });
|
|
796
828
|
return response;
|
|
797
829
|
};
|
|
798
830
|
};
|
|
799
831
|
|
|
800
832
|
// src/clients/third-party/shopify-client.ts
|
|
801
|
-
|
|
833
|
+
var log9 = __toESM(require("lambda-log"), 1);
|
|
802
834
|
var _ShopifyClient = class {
|
|
803
835
|
};
|
|
804
836
|
var ShopifyClient = _ShopifyClient;
|
|
@@ -842,9 +874,9 @@ __publicField(ShopifyClient, "registerWebhookTopic", async (shop, accessToken, e
|
|
|
842
874
|
};
|
|
843
875
|
const res = await client2.post(url, payload, { headers: { "X-Shopify-Access-Token": accessToken } });
|
|
844
876
|
if (res.status >= 400) {
|
|
845
|
-
|
|
877
|
+
log9.error("Failed to register Webhook Topic", { shop, accessToken, eventBridgeArn, topic, url, payload });
|
|
846
878
|
}
|
|
847
|
-
|
|
879
|
+
log9.debug("Shopify Client Webhook Registration Response", { registrationResponse: res });
|
|
848
880
|
return res;
|
|
849
881
|
});
|
|
850
882
|
__publicField(ShopifyClient, "updateShopifyAppMetafield", async (shop, accessToken, pixelId) => {
|
|
@@ -859,7 +891,7 @@ __publicField(ShopifyClient, "updateShopifyAppMetafield", async (shop, accessTok
|
|
|
859
891
|
};
|
|
860
892
|
const res = await _ShopifyClient.genericShopifyPost(url, accessToken, payload);
|
|
861
893
|
if (res.status >= 400) {
|
|
862
|
-
|
|
894
|
+
log9.error("Failed to update Shopify app Metafield ", { shop, accessToken, url, payload });
|
|
863
895
|
}
|
|
864
896
|
return res;
|
|
865
897
|
});
|
|
@@ -867,7 +899,7 @@ __publicField(ShopifyClient, "getShopifyStoreProperties", async (shop, accessTok
|
|
|
867
899
|
const url = `https://${shop}/admin/api/${_ShopifyClient._shopify_api_version}/shop.json`;
|
|
868
900
|
const res = await _ShopifyClient.genericShopifyGet(url, accessToken);
|
|
869
901
|
if (res.status >= 400) {
|
|
870
|
-
|
|
902
|
+
log9.error("Failed to get Shopify Store Properties", { shop, accessToken, url });
|
|
871
903
|
}
|
|
872
904
|
return res;
|
|
873
905
|
});
|
|
@@ -882,7 +914,7 @@ __publicField(ShopifyClient, "createAppSubscription", async (shop, accessToken,
|
|
|
882
914
|
};
|
|
883
915
|
const res = await _ShopifyClient.genericShopifyPost(url, accessToken, { recurring_application_charge });
|
|
884
916
|
if (res.status >= 400) {
|
|
885
|
-
|
|
917
|
+
log9.error("Failed to create App Subscription", { shop, accessToken, url });
|
|
886
918
|
}
|
|
887
919
|
return res;
|
|
888
920
|
});
|
|
@@ -891,7 +923,7 @@ __publicField(ShopifyClient, "cancelAppSubscription", async (shop, accessToken,
|
|
|
891
923
|
const client2 = axiosHttpService();
|
|
892
924
|
const res = await client2.delete(url, { headers: { "X-Shopify-Access-Token": accessToken } });
|
|
893
925
|
if (res.status !== 200) {
|
|
894
|
-
|
|
926
|
+
log9.error("Failed to cancel recurring App billing", { shop, accessToken, url });
|
|
895
927
|
}
|
|
896
928
|
return res;
|
|
897
929
|
});
|
|
@@ -899,35 +931,35 @@ __publicField(ShopifyClient, "listAppSubscriptions", async (shop, accessToken) =
|
|
|
899
931
|
const url = `https://${shop}/admin/api/${_ShopifyClient._shopify_api_version}/recurring_application_charges.json`;
|
|
900
932
|
const res = await _ShopifyClient.genericShopifyGet(url, accessToken);
|
|
901
933
|
if (res.status >= 400) {
|
|
902
|
-
|
|
934
|
+
log9.error("Failed to get App Subscriptions", { shop, accessToken, url });
|
|
903
935
|
}
|
|
904
936
|
return res;
|
|
905
937
|
});
|
|
906
938
|
__publicField(ShopifyClient, "genericShopifyPost", async (url, accessToken, payload) => {
|
|
907
939
|
const client2 = axiosHttpService();
|
|
908
940
|
const res = await client2.post(url, payload, { headers: { "X-Shopify-Access-Token": accessToken, "Content-Type": "application/json" } });
|
|
909
|
-
|
|
941
|
+
log9.debug("Shopify Client Response", { res });
|
|
910
942
|
return res;
|
|
911
943
|
});
|
|
912
944
|
__publicField(ShopifyClient, "genericShopifyGet", async (url, accessToken) => {
|
|
913
945
|
const client2 = axiosHttpService();
|
|
914
946
|
const res = await client2.get(url, { headers: { "X-Shopify-Access-Token": accessToken } });
|
|
915
|
-
|
|
947
|
+
log9.debug("Shopify Client Response", { res });
|
|
916
948
|
return res;
|
|
917
949
|
});
|
|
918
950
|
__publicField(ShopifyClient, "genericShopifyPut", async (url, accessToken, payload) => {
|
|
919
951
|
const client2 = axiosHttpService();
|
|
920
952
|
const res = await client2.put(url, payload, { headers: { "X-Shopify-Access-Token": accessToken } });
|
|
921
|
-
|
|
953
|
+
log9.debug("Shopify Client Response", { res });
|
|
922
954
|
return res;
|
|
923
955
|
});
|
|
924
956
|
|
|
925
957
|
// src/helpers/input-validation-helper.ts
|
|
926
|
-
|
|
958
|
+
var log10 = __toESM(require("lambda-log"), 1);
|
|
927
959
|
var validateInput = (schema, input) => {
|
|
928
960
|
const { error: error7, value } = schema.validate(input);
|
|
929
961
|
if (error7) {
|
|
930
|
-
|
|
962
|
+
log10.info("", { error: error7 });
|
|
931
963
|
const httperr = HttpError.badRequest("Bad Request", {
|
|
932
964
|
errors: error7.details.map((detail) => ({
|
|
933
965
|
message: detail?.message,
|
|
@@ -935,21 +967,21 @@ var validateInput = (schema, input) => {
|
|
|
935
967
|
path: detail?.path
|
|
936
968
|
}))
|
|
937
969
|
});
|
|
938
|
-
|
|
970
|
+
log10.info("", { httperr });
|
|
939
971
|
throw httperr;
|
|
940
972
|
}
|
|
941
973
|
return value;
|
|
942
974
|
};
|
|
943
975
|
|
|
944
976
|
// src/helpers/logging-helper.ts
|
|
945
|
-
|
|
977
|
+
var log11 = __toESM(require("lambda-log"), 1);
|
|
946
978
|
var stage = process?.env?.STAGE;
|
|
947
979
|
var configureLogger = (event, context, debug5 = true) => {
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
980
|
+
log11.options.meta.stage = stage;
|
|
981
|
+
log11.options.meta.source_name = context?.functionName || "unknown";
|
|
982
|
+
log11.options.meta.awsRequestId = context?.awsRequestId || "unknown";
|
|
983
|
+
log11.options.meta.lambdaEvent = event;
|
|
984
|
+
log11.options.debug = debug5;
|
|
953
985
|
};
|
|
954
986
|
|
|
955
987
|
// src/helpers/response-helper.ts
|
|
@@ -979,25 +1011,60 @@ var buildResponse = (statusCode, body = {}) => {
|
|
|
979
1011
|
"Access-Control-Allow-Origin": "*",
|
|
980
1012
|
"Access-Control-Allow-Credentials": true,
|
|
981
1013
|
"cache-control": "max-age=86400",
|
|
982
|
-
Date: new Date(),
|
|
983
|
-
"Last-Modified": new Date(),
|
|
1014
|
+
Date: /* @__PURE__ */ new Date(),
|
|
1015
|
+
"Last-Modified": /* @__PURE__ */ new Date(),
|
|
984
1016
|
"Access-Control-Allow-Headers": "Content-Type, Content-Encoding"
|
|
985
1017
|
},
|
|
986
1018
|
body: JSON.stringify(body)
|
|
987
1019
|
};
|
|
988
1020
|
};
|
|
989
1021
|
|
|
1022
|
+
// src/helpers/shopify-helper.ts
|
|
1023
|
+
var import_crypto = require("crypto");
|
|
1024
|
+
var log12 = __toESM(require("lambda-log"), 1);
|
|
1025
|
+
|
|
1026
|
+
// src/libs/url.ts
|
|
1027
|
+
var mapObjectToQueryString = (inputObj) => {
|
|
1028
|
+
const qsp = Object.entries(inputObj).sort((a, b) => a[0] < b[0] ? -1 : 1);
|
|
1029
|
+
const urlParams = new URLSearchParams();
|
|
1030
|
+
qsp.map((p2) => {
|
|
1031
|
+
urlParams.append(p2[0], p2[1]);
|
|
1032
|
+
});
|
|
1033
|
+
const qs = urlParams.toString();
|
|
1034
|
+
return qs;
|
|
1035
|
+
};
|
|
1036
|
+
|
|
1037
|
+
// src/helpers/shopify-helper.ts
|
|
1038
|
+
var isShopifyRequestValid = (validationParams, validationHmac, shopifyAppApiSecret) => {
|
|
1039
|
+
delete validationParams.hmac;
|
|
1040
|
+
const hmacString = mapObjectToQueryString(validationParams);
|
|
1041
|
+
const generatedHash = (0, import_crypto.createHmac)("sha256", shopifyAppApiSecret).update(hmacString).digest("hex");
|
|
1042
|
+
return generatedHash === validationHmac;
|
|
1043
|
+
};
|
|
1044
|
+
var validateShopifyRequest = (validationParams, validationHmac, shopifyAppApiSecret) => {
|
|
1045
|
+
log12.info("Validating shopify request is authentic", { validationParams });
|
|
1046
|
+
const isValid = isShopifyRequestValid(validationParams, validationHmac, shopifyAppApiSecret);
|
|
1047
|
+
if (!isValid) {
|
|
1048
|
+
const message = "Failed: Shopify Request hmac validation";
|
|
1049
|
+
log12.error(message);
|
|
1050
|
+
throw HttpError.badRequest(message);
|
|
1051
|
+
}
|
|
1052
|
+
log12.info("Sucess: Shopify Request hmac validation");
|
|
1053
|
+
return true;
|
|
1054
|
+
};
|
|
1055
|
+
|
|
990
1056
|
// node_modules/@adtrackify/at-tracking-event-types/dist/index.js
|
|
991
|
-
var
|
|
1057
|
+
var s = ((n) => (n.PENDING = "pending", n.ACTIVE = "active", n.INACTIVE = "inactive", n))(s || {});
|
|
992
1058
|
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 || {});
|
|
993
|
-
var c = ((
|
|
994
|
-
var p = ((
|
|
995
|
-
var d = ((
|
|
996
|
-
var f = ((
|
|
997
|
-
var
|
|
998
|
-
var
|
|
999
|
-
var
|
|
1000
|
-
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))(x || {});
|
|
1059
|
+
var c = ((n) => (n.HEADER = "header", n.FOOTER = "footer", n.BODY = "body", n))(c || {});
|
|
1060
|
+
var p = ((o) => (o.STARTED = "started", o.COMPLETED = "completed", o.UNINSTALLED = "uninstalled", o.FAILED = "failed", o.NONE = "none", o))(p || {});
|
|
1061
|
+
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 || {});
|
|
1062
|
+
var f = ((a) => (a.MONTHLY = "monthly", a.YEARLY = "yearly", a))(f || {});
|
|
1063
|
+
var m = ((r) => (r.CURRENT = "current", r.PAST_DUE = "past_due", r.CANCELLED = "cancelled", r.FAILED = "failed", r))(m || {});
|
|
1064
|
+
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 || {});
|
|
1065
|
+
var u = ((n) => (n.STRIPE = "stripe", n.PAYPAL = "paypal", n.SHOPIFY = "shopify", n))(u || {});
|
|
1066
|
+
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 || {});
|
|
1067
|
+
var C = ((r) => (r.TRACKING = "tracking", r.METRIC = "metric", r.IDENTIFY = "identify", r.LOG = "log", r))(C || {});
|
|
1001
1068
|
|
|
1002
1069
|
// src/helpers/subscription-helper.ts
|
|
1003
1070
|
var StripeBillingMap = {
|
|
@@ -1057,6 +1124,7 @@ var StripeBillingMap = {
|
|
|
1057
1124
|
}
|
|
1058
1125
|
};
|
|
1059
1126
|
var CommonPlanInfo = [
|
|
1127
|
+
//'60-day Risk Free Trial',
|
|
1060
1128
|
"Free Server Side Tracking & Conversion API",
|
|
1061
1129
|
"MultiPixel Support (Multiple facebook, tiktok, etc)",
|
|
1062
1130
|
"Corrects Facebook Conversion Tracking post IOS14",
|
|
@@ -1086,6 +1154,7 @@ var SubscriptionPlanSeedItems = {
|
|
|
1086
1154
|
isHighlighted: false,
|
|
1087
1155
|
isBanner: false
|
|
1088
1156
|
},
|
|
1157
|
+
// STARTER PLANS
|
|
1089
1158
|
{
|
|
1090
1159
|
id: 2,
|
|
1091
1160
|
planName: "starter_monthly",
|
|
@@ -1129,6 +1198,7 @@ var SubscriptionPlanSeedItems = {
|
|
|
1129
1198
|
bannerColor: "blue",
|
|
1130
1199
|
bannerText: "MOST POPULAR"
|
|
1131
1200
|
},
|
|
1201
|
+
// SCALE PLANS
|
|
1132
1202
|
{
|
|
1133
1203
|
id: 4,
|
|
1134
1204
|
planName: "scale_monthly",
|
|
@@ -1169,6 +1239,55 @@ var SubscriptionPlanSeedItems = {
|
|
|
1169
1239
|
isHighlighted: false,
|
|
1170
1240
|
isBanner: false
|
|
1171
1241
|
}
|
|
1242
|
+
// // GROWTH PLANS
|
|
1243
|
+
// {
|
|
1244
|
+
// id: 6,
|
|
1245
|
+
// planName: 'growth_monthly',
|
|
1246
|
+
// displayName: 'Growth',
|
|
1247
|
+
// sku: 'ADT-006',
|
|
1248
|
+
// description: 'Growth Plan - Monthly',
|
|
1249
|
+
// price: '199.99',
|
|
1250
|
+
// displayPrice: '$199.99',
|
|
1251
|
+
// billingFrequency: PLAN_BILLING_FREQUENCY.MONTHLY,
|
|
1252
|
+
// trialLengthDays: 60,
|
|
1253
|
+
// trialRequiresCreditCard: false,
|
|
1254
|
+
// planDesc: [
|
|
1255
|
+
// '60-day Risk Free Trial',
|
|
1256
|
+
// ...CommonPlanInfo,
|
|
1257
|
+
// '250,000 tracking events/mo'
|
|
1258
|
+
// ],
|
|
1259
|
+
// unitPriceText: 'billed yearly ($540) - 25% savings',
|
|
1260
|
+
// isHighlighted: false,
|
|
1261
|
+
// isBanner: true,
|
|
1262
|
+
// bannerColor: 'orange',
|
|
1263
|
+
// bannerText: 'BEST VALUE'
|
|
1264
|
+
// }, {
|
|
1265
|
+
// id: 7,
|
|
1266
|
+
// planName: 'growth_yearly',
|
|
1267
|
+
// displayName: 'Growth',
|
|
1268
|
+
// sku: 'ADT-007',
|
|
1269
|
+
// description: 'Growth Plan - Yearly',
|
|
1270
|
+
// price: '1799.91',
|
|
1271
|
+
// displayPrice: '$149.99',
|
|
1272
|
+
// billingFrequency: PLAN_BILLING_FREQUENCY.YEARLY,
|
|
1273
|
+
// trialLengthDays: 60,
|
|
1274
|
+
// trialRequiresCreditCard: false,
|
|
1275
|
+
// planDesc: [
|
|
1276
|
+
// '30-day Risk Free Trial',
|
|
1277
|
+
// 'Fixes IOS14.5 tracking',
|
|
1278
|
+
// 'Multi Pixel Support',
|
|
1279
|
+
// 'Enhanced Tracking / Attribution',
|
|
1280
|
+
// 'Unlimited Facebook Conversion API',
|
|
1281
|
+
// 'Unlimited Integrations',
|
|
1282
|
+
// 'Easy no code setup',
|
|
1283
|
+
// '100,000 tracking events/mo'
|
|
1284
|
+
// ],
|
|
1285
|
+
// unitPriceText: 'billed yearly ($1799.91) - 25% savings',
|
|
1286
|
+
// isHighlighted: false,
|
|
1287
|
+
// isBanner: true,
|
|
1288
|
+
// bannerColor: 'orange',
|
|
1289
|
+
// bannerText: 'BEST VALUE'
|
|
1290
|
+
// },
|
|
1172
1291
|
]
|
|
1173
1292
|
};
|
|
1174
1293
|
var getPlanDetails = (planId, stage2) => {
|
|
@@ -1184,6 +1303,13 @@ var getPlanByStripePriceId = (stripePriceId, stage2) => {
|
|
|
1184
1303
|
return plan;
|
|
1185
1304
|
};
|
|
1186
1305
|
|
|
1306
|
+
// src/libs/crypto.ts
|
|
1307
|
+
var import_crypto2 = __toESM(require("crypto"), 1);
|
|
1308
|
+
var generatePublicKey = () => {
|
|
1309
|
+
const publicKey = import_crypto2.default.randomBytes(26);
|
|
1310
|
+
return publicKey.toString("utf8");
|
|
1311
|
+
};
|
|
1312
|
+
|
|
1187
1313
|
// src/types/internal-events/event-detail-types.ts
|
|
1188
1314
|
var ADTRACKIFY_EVENT_TYPES = /* @__PURE__ */ ((ADTRACKIFY_EVENT_TYPES2) => {
|
|
1189
1315
|
ADTRACKIFY_EVENT_TYPES2["NOTIFY_SHOPIFY_SUBSCRIPTION_CREATED"] = "shopifySubscriptionCreated";
|
|
@@ -1237,7 +1363,8 @@ var EventBridgeIntegrationService = class {
|
|
|
1237
1363
|
);
|
|
1238
1364
|
};
|
|
1239
1365
|
};
|
|
1240
|
-
export
|
|
1366
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1367
|
+
0 && (module.exports = {
|
|
1241
1368
|
ADTRACKIFY_EVENT_BRIDGE_EVENTS,
|
|
1242
1369
|
ADTRACKIFY_EVENT_SOURCES,
|
|
1243
1370
|
ADTRACKIFY_EVENT_TYPES,
|
|
@@ -1273,5 +1400,5 @@ export {
|
|
|
1273
1400
|
success,
|
|
1274
1401
|
validateInput,
|
|
1275
1402
|
validateShopifyRequest
|
|
1276
|
-
};
|
|
1403
|
+
});
|
|
1277
1404
|
//# sourceMappingURL=index.js.map
|