@adtrackify/at-service-common 1.1.16 → 1.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +12 -12
- package/.vscode/settings.json +9 -9
- package/bitbucket-pipelines.yml +20 -20
- package/build.js +1 -1
- package/dist/index.d.ts +27 -7
- package/dist/index.js +215 -70
- package/dist/index.js.map +4 -4
- package/jest.config.ts +40 -40
- package/package.json +3 -2
- package/src/__tests__/helpers/subscription-helper.spec.ts +40 -40
- package/src/clients/generic/axios.d.ts +7 -7
- package/src/clients/generic/cognito-client.ts +153 -0
- package/src/clients/generic/index.ts +1 -0
- package/src/clients/generic/s3-client.ts +9 -5
- package/src/clients/internal-api/destinations-client.ts +58 -58
- package/src/clients/internal-api/index.ts +4 -4
- package/src/clients/internal-api/shopify-app-install-client.ts +66 -66
- package/src/clients/third-party/shopify-client.ts +139 -139
- package/src/helpers/index.ts +5 -5
- package/src/helpers/input-validation-helper.ts +21 -21
- package/src/helpers/shopify-helper.ts +39 -39
- package/src/index.ts +4 -4
- package/src/libs/index.ts +7 -7
- package/src/libs/url.ts +9 -9
- package/src/services/eventbridge-integration-service.ts +44 -44
- package/src/types/internal-events/event-detail-types.ts +9 -9
package/dist/index.js
CHANGED
|
@@ -200,10 +200,10 @@ var httpResponse = (res = {}) => {
|
|
|
200
200
|
status: res?.status || 0
|
|
201
201
|
};
|
|
202
202
|
};
|
|
203
|
-
var handleAxiosError = (
|
|
204
|
-
if (!
|
|
205
|
-
throw
|
|
206
|
-
return
|
|
203
|
+
var handleAxiosError = (error7) => {
|
|
204
|
+
if (!error7?.response && !error7?.request)
|
|
205
|
+
throw error7;
|
|
206
|
+
return error7.response ? httpResponse(error7.response) : httpResponse({ status: 500, data: { error: error7.request } });
|
|
207
207
|
};
|
|
208
208
|
var axiosHttpService = (config = {}) => {
|
|
209
209
|
config.adapter = httpAdapter;
|
|
@@ -222,32 +222,175 @@ var axiosHttpService = (config = {}) => {
|
|
|
222
222
|
};
|
|
223
223
|
|
|
224
224
|
// src/clients/generic/s3-client.ts
|
|
225
|
-
import {
|
|
225
|
+
import { S3 } from "@aws-sdk/client-s3";
|
|
226
226
|
import * as log3 from "lambda-log";
|
|
227
227
|
var S3Client = class {
|
|
228
228
|
s3;
|
|
229
|
-
constructor(
|
|
230
|
-
this.s3 = new S3({
|
|
229
|
+
constructor(accessKeyId, secretAccessKey) {
|
|
230
|
+
this.s3 = new S3({
|
|
231
|
+
credentials: {
|
|
232
|
+
accessKeyId,
|
|
233
|
+
secretAccessKey
|
|
234
|
+
}
|
|
235
|
+
});
|
|
231
236
|
}
|
|
232
|
-
async uploadJson(path, bucket, jsonData
|
|
237
|
+
async uploadJson(path, bucket, jsonData) {
|
|
233
238
|
try {
|
|
234
239
|
const res = await this.s3.putObject({
|
|
235
|
-
ACL,
|
|
236
240
|
Bucket: bucket,
|
|
237
241
|
ContentType: "application/json; charset=utf-8",
|
|
238
242
|
Body: JSON.stringify(jsonData),
|
|
239
243
|
Key: path
|
|
240
244
|
});
|
|
241
245
|
return res;
|
|
242
|
-
} catch (
|
|
243
|
-
log3.error("Error in s3 upload json", { error:
|
|
244
|
-
return
|
|
246
|
+
} catch (error7) {
|
|
247
|
+
log3.error("Error in s3 upload json", { error: error7 });
|
|
248
|
+
return error7;
|
|
245
249
|
}
|
|
246
250
|
}
|
|
247
251
|
};
|
|
248
252
|
|
|
249
|
-
// src/clients/
|
|
253
|
+
// src/clients/generic/cognito-client.ts
|
|
254
|
+
import { CognitoIdentityProvider } from "@aws-sdk/client-cognito-identity-provider";
|
|
250
255
|
import * as log4 from "lambda-log";
|
|
256
|
+
var cognitoClient = new CognitoIdentityProvider({});
|
|
257
|
+
var USER_POOL_NO_SECRET_CLIENT_ID;
|
|
258
|
+
var USER_POOL_ID;
|
|
259
|
+
function dictToAwsAttributes(input) {
|
|
260
|
+
delete input.email;
|
|
261
|
+
delete input.password;
|
|
262
|
+
const output = [];
|
|
263
|
+
for (const att in input) {
|
|
264
|
+
if (Object.prototype.hasOwnProperty.call(input, att)) {
|
|
265
|
+
output.push({ Name: att, Value: input[att] });
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return output;
|
|
269
|
+
}
|
|
270
|
+
var buildAttributes = (data) => {
|
|
271
|
+
const attributes = {
|
|
272
|
+
name: data.givenName,
|
|
273
|
+
family_name: data.familyName
|
|
274
|
+
};
|
|
275
|
+
return dictToAwsAttributes(attributes);
|
|
276
|
+
};
|
|
277
|
+
var _CognitoClient = class {
|
|
278
|
+
};
|
|
279
|
+
var CognitoClient = _CognitoClient;
|
|
280
|
+
__publicField(CognitoClient, "setCredentials", (userPoolId, userPoolNoSecretClientId) => {
|
|
281
|
+
USER_POOL_ID = userPoolId;
|
|
282
|
+
USER_POOL_NO_SECRET_CLIENT_ID = userPoolNoSecretClientId;
|
|
283
|
+
});
|
|
284
|
+
__publicField(CognitoClient, "signupUser", async (data) => {
|
|
285
|
+
const params = {
|
|
286
|
+
ClientId: USER_POOL_NO_SECRET_CLIENT_ID,
|
|
287
|
+
Password: data.password,
|
|
288
|
+
Username: data.email,
|
|
289
|
+
UserAttributes: buildAttributes(data)
|
|
290
|
+
};
|
|
291
|
+
const cognitoResponse = await cognitoClient.signUp(params);
|
|
292
|
+
log4.debug("Successfully Registered User", { cognitoResponse });
|
|
293
|
+
return cognitoResponse;
|
|
294
|
+
});
|
|
295
|
+
__publicField(CognitoClient, "forgotPassword", async (email) => {
|
|
296
|
+
await _CognitoClient.adminEmailVerify(email);
|
|
297
|
+
const params = {
|
|
298
|
+
ClientId: USER_POOL_NO_SECRET_CLIENT_ID,
|
|
299
|
+
Username: email
|
|
300
|
+
};
|
|
301
|
+
const cognitoResponse = await cognitoClient.forgotPassword(params);
|
|
302
|
+
log4.debug("Sent Forgot Password", { cognitoResponse });
|
|
303
|
+
return cognitoResponse;
|
|
304
|
+
});
|
|
305
|
+
__publicField(CognitoClient, "adminEmailVerify", async (email) => {
|
|
306
|
+
try {
|
|
307
|
+
const user = await _CognitoClient.getUserByEmail(email);
|
|
308
|
+
if (user && user?.UserStatus === "CONFIRMED" && user?.email_verified !== "true") {
|
|
309
|
+
await _CognitoClient.forceValidateEmail(email);
|
|
310
|
+
}
|
|
311
|
+
} catch (error7) {
|
|
312
|
+
log4.error("Failed admin email verify", { error: error7 });
|
|
313
|
+
}
|
|
314
|
+
});
|
|
315
|
+
__publicField(CognitoClient, "forceValidateEmail", async (email) => {
|
|
316
|
+
try {
|
|
317
|
+
const params = {
|
|
318
|
+
UserPoolId: USER_POOL_ID,
|
|
319
|
+
Username: email,
|
|
320
|
+
UserAttributes: [
|
|
321
|
+
{
|
|
322
|
+
Name: "email_verified",
|
|
323
|
+
Value: "true"
|
|
324
|
+
}
|
|
325
|
+
]
|
|
326
|
+
};
|
|
327
|
+
await cognitoClient.adminUpdateUserAttributes(params);
|
|
328
|
+
} catch (error7) {
|
|
329
|
+
log4.error("Failed force validate email", { email, error: error7 });
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
__publicField(CognitoClient, "adminConfirmUser", async (data) => {
|
|
333
|
+
const params = {
|
|
334
|
+
UserPoolId: USER_POOL_ID,
|
|
335
|
+
Username: data.email
|
|
336
|
+
};
|
|
337
|
+
const cognitoResponse = await cognitoClient.adminConfirmSignUp(params);
|
|
338
|
+
await _CognitoClient.forceValidateEmail(data.email);
|
|
339
|
+
log4.debug("Admin Successfully Confirmed User", { cognitoResponse });
|
|
340
|
+
return cognitoResponse;
|
|
341
|
+
});
|
|
342
|
+
__publicField(CognitoClient, "confirmUser", async (data) => {
|
|
343
|
+
const params = {
|
|
344
|
+
ClientId: USER_POOL_NO_SECRET_CLIENT_ID,
|
|
345
|
+
ConfirmationCode: data.confirmationCode,
|
|
346
|
+
Username: data.email
|
|
347
|
+
};
|
|
348
|
+
const cognitoResponse = await cognitoClient.confirmSignUp(params);
|
|
349
|
+
log4.debug("Successfully Confirmed User", { cognitoResponse });
|
|
350
|
+
return cognitoResponse;
|
|
351
|
+
});
|
|
352
|
+
__publicField(CognitoClient, "resendCode", async (email) => {
|
|
353
|
+
const params = {
|
|
354
|
+
ClientId: USER_POOL_NO_SECRET_CLIENT_ID,
|
|
355
|
+
Username: email
|
|
356
|
+
};
|
|
357
|
+
await cognitoClient.resendConfirmationCode(params);
|
|
358
|
+
log4.debug("Successfully Resend Confirmation Code", { email });
|
|
359
|
+
return;
|
|
360
|
+
});
|
|
361
|
+
__publicField(CognitoClient, "adminDeleteUser", async (userId) => {
|
|
362
|
+
const params = {
|
|
363
|
+
UserPoolId: USER_POOL_ID,
|
|
364
|
+
Username: userId
|
|
365
|
+
};
|
|
366
|
+
await cognitoClient.adminDeleteUser(params);
|
|
367
|
+
return true;
|
|
368
|
+
});
|
|
369
|
+
__publicField(CognitoClient, "getUserByEmail", async (email) => {
|
|
370
|
+
const params = {
|
|
371
|
+
UserPoolId: USER_POOL_ID,
|
|
372
|
+
Filter: `email="${email}"`,
|
|
373
|
+
Limit: 1
|
|
374
|
+
};
|
|
375
|
+
const cognitoResponse = await cognitoClient.listUsers(params);
|
|
376
|
+
log4.debug("Get Users by Email", { cognitoResponse });
|
|
377
|
+
if (cognitoResponse?.Users && cognitoResponse?.Users.length > 0) {
|
|
378
|
+
const attributes = cognitoResponse.Users[0].Attributes;
|
|
379
|
+
const user = {
|
|
380
|
+
...cognitoResponse.Users[0],
|
|
381
|
+
Attributes: void 0,
|
|
382
|
+
id: cognitoResponse.Users[0].sub
|
|
383
|
+
};
|
|
384
|
+
attributes.forEach((attr) => {
|
|
385
|
+
user[attr.Name] = attr?.Value;
|
|
386
|
+
});
|
|
387
|
+
return user;
|
|
388
|
+
}
|
|
389
|
+
return null;
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
// src/clients/internal-api/destinations-client.ts
|
|
393
|
+
import * as log5 from "lambda-log";
|
|
251
394
|
var DestinationsClient = class {
|
|
252
395
|
BASE_API_URL;
|
|
253
396
|
DESTINATIONS_API_KEY;
|
|
@@ -272,19 +415,19 @@ var DestinationsClient = class {
|
|
|
272
415
|
createDestination = async (createDestinationRequest) => {
|
|
273
416
|
const client2 = await this.getClient();
|
|
274
417
|
const response = await client2.post("/", createDestinationRequest);
|
|
275
|
-
|
|
418
|
+
log5.info("createDestinationResponse", { response });
|
|
276
419
|
return response;
|
|
277
420
|
};
|
|
278
421
|
getPixelDestinations = async (pixelId) => {
|
|
279
422
|
const client2 = await this.getClient();
|
|
280
423
|
const response = await client2.get(`/?pixelId=${pixelId}`);
|
|
281
|
-
|
|
424
|
+
log5.info("getPixelResponse", { response });
|
|
282
425
|
return response;
|
|
283
426
|
};
|
|
284
427
|
};
|
|
285
428
|
|
|
286
429
|
// src/clients/internal-api/accounts-client.ts
|
|
287
|
-
import * as
|
|
430
|
+
import * as log6 from "lambda-log";
|
|
288
431
|
var AccountsClient = class {
|
|
289
432
|
BASE_API_URL;
|
|
290
433
|
ACCOUNTS_API_KEY;
|
|
@@ -312,19 +455,19 @@ var AccountsClient = class {
|
|
|
312
455
|
createAccount = async (createAccountRequest) => {
|
|
313
456
|
const client2 = await this.getClient();
|
|
314
457
|
const createAccountResponse = await client2.post("", createAccountRequest);
|
|
315
|
-
|
|
458
|
+
log6.info("createAccountResponse", { createAccountResponse });
|
|
316
459
|
return createAccountResponse;
|
|
317
460
|
};
|
|
318
461
|
updateAccount = async (accountId, body) => {
|
|
319
462
|
const client2 = await this.getClient();
|
|
320
463
|
const response = await client2.patch(`/${accountId}/`, body);
|
|
321
|
-
|
|
464
|
+
log6.info("update Account response", { response });
|
|
322
465
|
return response;
|
|
323
466
|
};
|
|
324
467
|
addOwner = async (accountId, userId) => {
|
|
325
468
|
const client2 = await this.getClient();
|
|
326
469
|
const addOwnerResponse = await client2.post("/addOwner", { accountId, userId });
|
|
327
|
-
|
|
470
|
+
log6.info("addOwnerResponse", { addOwnerResponse });
|
|
328
471
|
return addOwnerResponse;
|
|
329
472
|
};
|
|
330
473
|
isAuthorizedUser = async (userId, accountId, pixelId) => {
|
|
@@ -335,41 +478,41 @@ var AccountsClient = class {
|
|
|
335
478
|
pixelId
|
|
336
479
|
};
|
|
337
480
|
const response = await client2.post("/checkUserAuthorization", body);
|
|
338
|
-
|
|
481
|
+
log6.info("checkUserAuthorization", { response });
|
|
339
482
|
return response;
|
|
340
483
|
};
|
|
341
484
|
adminDeleteAccount = async (accountId) => {
|
|
342
485
|
const client2 = await this.getClient();
|
|
343
486
|
const success2 = await client2.delete(`/${accountId}`);
|
|
344
|
-
|
|
487
|
+
log6.info("adminDeleteAccount");
|
|
345
488
|
return success2;
|
|
346
489
|
};
|
|
347
490
|
getPixelConfigById = async (pixelId) => {
|
|
348
491
|
const client2 = await this.getClient();
|
|
349
492
|
const pixelResponse = await client2.get(`/px/${pixelId}/config`);
|
|
350
|
-
|
|
493
|
+
log6.debug("get pixelResponse", { pixelResponse });
|
|
351
494
|
return pixelResponse;
|
|
352
495
|
};
|
|
353
496
|
getAccount = async (accountId) => {
|
|
354
497
|
const client2 = await this.getClient();
|
|
355
498
|
const response = await client2.get(`/${accountId}/`);
|
|
356
|
-
|
|
499
|
+
log6.info("get account response", { response });
|
|
357
500
|
return response;
|
|
358
501
|
};
|
|
359
502
|
addUserToAccount = async (accountId, userId) => {
|
|
360
503
|
const client2 = await this.getClient();
|
|
361
504
|
const response = await client2.post("/addUser", { accountId, userId });
|
|
362
|
-
|
|
505
|
+
log6.info("add user account response", { response });
|
|
363
506
|
return response;
|
|
364
507
|
};
|
|
365
508
|
};
|
|
366
509
|
|
|
367
510
|
// src/clients/internal-api/users-auth-client.ts
|
|
368
|
-
import * as
|
|
511
|
+
import * as log8 from "lambda-log";
|
|
369
512
|
|
|
370
513
|
// src/helpers/shopify-helper.ts
|
|
371
514
|
import { createHmac } from "crypto";
|
|
372
|
-
import * as
|
|
515
|
+
import * as log7 from "lambda-log";
|
|
373
516
|
|
|
374
517
|
// src/libs/url.ts
|
|
375
518
|
var mapObjectToQueryString = (inputObj) => {
|
|
@@ -390,14 +533,14 @@ var isShopifyRequestValid = (validationParams, validationHmac, shopifyAppApiSecr
|
|
|
390
533
|
return generatedHash === validationHmac;
|
|
391
534
|
};
|
|
392
535
|
var validateShopifyRequest = (validationParams, validationHmac, shopifyAppApiSecret) => {
|
|
393
|
-
|
|
536
|
+
log7.info("Validating shopify request is authentic", { validationParams });
|
|
394
537
|
const isValid = isShopifyRequestValid(validationParams, validationHmac, shopifyAppApiSecret);
|
|
395
538
|
if (!isValid) {
|
|
396
539
|
const message = "Failed: Shopify Request hmac validation";
|
|
397
|
-
|
|
540
|
+
log7.error(message);
|
|
398
541
|
throw HttpError.badRequest(message);
|
|
399
542
|
}
|
|
400
|
-
|
|
543
|
+
log7.info("Sucess: Shopify Request hmac validation");
|
|
401
544
|
return true;
|
|
402
545
|
};
|
|
403
546
|
|
|
@@ -567,19 +710,19 @@ var UsersAuthClient = class {
|
|
|
567
710
|
return user;
|
|
568
711
|
};
|
|
569
712
|
signupUser = async (userSignupRequest) => {
|
|
570
|
-
|
|
713
|
+
log8.info("Attempting to signup user", { email: userSignupRequest.email });
|
|
571
714
|
const client2 = await this.getClient();
|
|
572
715
|
const response = await client2.post("/signup", userSignupRequest);
|
|
573
716
|
if (response.status !== 200 || !response?.data?.user) {
|
|
574
717
|
const message = "User Signup Failed";
|
|
575
|
-
|
|
718
|
+
log8.error(message, { response });
|
|
576
719
|
throw new HttpError(500 /* INTERNAL_SERVER_ERROR */, message);
|
|
577
720
|
}
|
|
578
|
-
|
|
721
|
+
log8.info("User Signup Successful", { response });
|
|
579
722
|
return response.data.user;
|
|
580
723
|
};
|
|
581
724
|
adminConfirmUser = async (email) => {
|
|
582
|
-
|
|
725
|
+
log8.info("Attempting to admin confirm user", { email });
|
|
583
726
|
const client2 = await this.getClient();
|
|
584
727
|
const response = await client2.post(
|
|
585
728
|
"/admin/confirm",
|
|
@@ -594,10 +737,10 @@ var UsersAuthClient = class {
|
|
|
594
737
|
);
|
|
595
738
|
if (response.status !== 200) {
|
|
596
739
|
const message = "Admin User Confirmation Failed";
|
|
597
|
-
|
|
740
|
+
log8.error(message, { response });
|
|
598
741
|
throw new HttpError(500 /* INTERNAL_SERVER_ERROR */, message);
|
|
599
742
|
}
|
|
600
|
-
|
|
743
|
+
log8.info("Admin User Confirmation Successful", { response });
|
|
601
744
|
return response;
|
|
602
745
|
};
|
|
603
746
|
getUserByEmail = async (email) => {
|
|
@@ -610,13 +753,13 @@ var UsersAuthClient = class {
|
|
|
610
753
|
email
|
|
611
754
|
}
|
|
612
755
|
});
|
|
613
|
-
|
|
756
|
+
log8.info("getUserResponse", { getUserResponse });
|
|
614
757
|
return getUserResponse;
|
|
615
758
|
};
|
|
616
759
|
};
|
|
617
760
|
|
|
618
761
|
// src/clients/internal-api/shopify-app-install-client.ts
|
|
619
|
-
import
|
|
762
|
+
import log9 from "lambda-log";
|
|
620
763
|
var ShopifyAppInstallClient = class {
|
|
621
764
|
BASE_API_URL;
|
|
622
765
|
SHOPIFY_APP_INSTALL_API_KEY;
|
|
@@ -641,25 +784,25 @@ var ShopifyAppInstallClient = class {
|
|
|
641
784
|
updateShopifyAppInstall = async (shopifyAppInstallId, updateShopifyAppInstallRequest) => {
|
|
642
785
|
const client2 = await this.getClient();
|
|
643
786
|
const response = await client2.put(`/${shopifyAppInstallId}`, updateShopifyAppInstallRequest);
|
|
644
|
-
|
|
787
|
+
log9.info("updateShopifyAppInstall", { response });
|
|
645
788
|
return response;
|
|
646
789
|
};
|
|
647
790
|
getShopifyAppInstall = async (shopifyAppInstallId) => {
|
|
648
791
|
const client2 = await this.getClient();
|
|
649
792
|
const response = await client2.get(`/${shopifyAppInstallId}`);
|
|
650
|
-
|
|
793
|
+
log9.info("getShopifyAppInstall", { response });
|
|
651
794
|
return response;
|
|
652
795
|
};
|
|
653
796
|
getShopifyAppInstallByShop = async (shop) => {
|
|
654
797
|
const client2 = await this.getClient();
|
|
655
798
|
const response = await client2.get(`/?shop=${shop}`);
|
|
656
|
-
|
|
799
|
+
log9.info("getShopifyAppInstallByShop", { response });
|
|
657
800
|
return response;
|
|
658
801
|
};
|
|
659
802
|
};
|
|
660
803
|
|
|
661
804
|
// src/clients/third-party/shopify-client.ts
|
|
662
|
-
import * as
|
|
805
|
+
import * as log10 from "lambda-log";
|
|
663
806
|
var _ShopifyClient = class {
|
|
664
807
|
};
|
|
665
808
|
var ShopifyClient = _ShopifyClient;
|
|
@@ -703,9 +846,9 @@ __publicField(ShopifyClient, "registerWebhookTopic", async (shop, accessToken, e
|
|
|
703
846
|
};
|
|
704
847
|
const res = await client2.post(url, payload, { headers: { "X-Shopify-Access-Token": accessToken } });
|
|
705
848
|
if (res.status >= 400) {
|
|
706
|
-
|
|
849
|
+
log10.error("Failed to register Webhook Topic", { shop, accessToken, eventBridgeArn, topic, url, payload });
|
|
707
850
|
}
|
|
708
|
-
|
|
851
|
+
log10.debug("Shopify Client Webhook Registration Response", { registrationResponse: res });
|
|
709
852
|
return res;
|
|
710
853
|
});
|
|
711
854
|
__publicField(ShopifyClient, "updateShopifyAppMetafield", async (shop, accessToken, pixelId) => {
|
|
@@ -720,7 +863,7 @@ __publicField(ShopifyClient, "updateShopifyAppMetafield", async (shop, accessTok
|
|
|
720
863
|
};
|
|
721
864
|
const res = await _ShopifyClient.genericShopifyPost(url, accessToken, payload);
|
|
722
865
|
if (res.status >= 400) {
|
|
723
|
-
|
|
866
|
+
log10.error("Failed to update Shopify app Metafield ", { shop, accessToken, url, payload });
|
|
724
867
|
}
|
|
725
868
|
return res;
|
|
726
869
|
});
|
|
@@ -728,7 +871,7 @@ __publicField(ShopifyClient, "getShopifyStoreProperties", async (shop, accessTok
|
|
|
728
871
|
const url = `https://${shop}/admin/api/${_ShopifyClient._shopify_api_version}/shop.json`;
|
|
729
872
|
const res = await _ShopifyClient.genericShopifyGet(url, accessToken);
|
|
730
873
|
if (res.status >= 400) {
|
|
731
|
-
|
|
874
|
+
log10.error("Failed to get Shopify Store Properties", { shop, accessToken, url });
|
|
732
875
|
}
|
|
733
876
|
return res;
|
|
734
877
|
});
|
|
@@ -743,7 +886,7 @@ __publicField(ShopifyClient, "createAppSubscription", async (shop, accessToken,
|
|
|
743
886
|
};
|
|
744
887
|
const res = await _ShopifyClient.genericShopifyPost(url, accessToken, { recurring_application_charge });
|
|
745
888
|
if (res.status >= 400) {
|
|
746
|
-
|
|
889
|
+
log10.error("Failed to create App Subscription", { shop, accessToken, url });
|
|
747
890
|
}
|
|
748
891
|
return res;
|
|
749
892
|
});
|
|
@@ -752,7 +895,7 @@ __publicField(ShopifyClient, "cancelAppSubscription", async (shop, accessToken,
|
|
|
752
895
|
const client2 = axiosHttpService();
|
|
753
896
|
const res = await client2.delete(url, { headers: { "X-Shopify-Access-Token": accessToken } });
|
|
754
897
|
if (res.status !== 200) {
|
|
755
|
-
|
|
898
|
+
log10.error("Failed to cancel recurring App billing", { shop, accessToken, url });
|
|
756
899
|
}
|
|
757
900
|
return res;
|
|
758
901
|
});
|
|
@@ -760,57 +903,57 @@ __publicField(ShopifyClient, "listAppSubscriptions", async (shop, accessToken) =
|
|
|
760
903
|
const url = `https://${shop}/admin/api/${_ShopifyClient._shopify_api_version}/recurring_application_charges.json`;
|
|
761
904
|
const res = await _ShopifyClient.genericShopifyGet(url, accessToken);
|
|
762
905
|
if (res.status >= 400) {
|
|
763
|
-
|
|
906
|
+
log10.error("Failed to get App Subscriptions", { shop, accessToken, url });
|
|
764
907
|
}
|
|
765
908
|
return res;
|
|
766
909
|
});
|
|
767
910
|
__publicField(ShopifyClient, "genericShopifyPost", async (url, accessToken, payload) => {
|
|
768
911
|
const client2 = axiosHttpService();
|
|
769
912
|
const res = await client2.post(url, payload, { headers: { "X-Shopify-Access-Token": accessToken, "Content-Type": "application/json" } });
|
|
770
|
-
|
|
913
|
+
log10.debug("Shopify Client Response", { res });
|
|
771
914
|
return res;
|
|
772
915
|
});
|
|
773
916
|
__publicField(ShopifyClient, "genericShopifyGet", async (url, accessToken) => {
|
|
774
917
|
const client2 = axiosHttpService();
|
|
775
918
|
const res = await client2.get(url, { headers: { "X-Shopify-Access-Token": accessToken } });
|
|
776
|
-
|
|
919
|
+
log10.debug("Shopify Client Response", { res });
|
|
777
920
|
return res;
|
|
778
921
|
});
|
|
779
922
|
__publicField(ShopifyClient, "genericShopifyPut", async (url, accessToken, payload) => {
|
|
780
923
|
const client2 = axiosHttpService();
|
|
781
924
|
const res = await client2.put(url, payload, { headers: { "X-Shopify-Access-Token": accessToken } });
|
|
782
|
-
|
|
925
|
+
log10.debug("Shopify Client Response", { res });
|
|
783
926
|
return res;
|
|
784
927
|
});
|
|
785
928
|
|
|
786
929
|
// src/helpers/input-validation-helper.ts
|
|
787
|
-
import * as
|
|
930
|
+
import * as log11 from "lambda-log";
|
|
788
931
|
var validateInput = (schema, input) => {
|
|
789
|
-
const { error:
|
|
790
|
-
if (
|
|
791
|
-
|
|
932
|
+
const { error: error7, value } = schema.validate(input);
|
|
933
|
+
if (error7) {
|
|
934
|
+
log11.info("", { error: error7 });
|
|
792
935
|
const httperr = HttpError.badRequest("Bad Request", {
|
|
793
|
-
errors:
|
|
936
|
+
errors: error7.details.map((detail) => ({
|
|
794
937
|
message: detail?.message,
|
|
795
938
|
key: detail?.context?.key,
|
|
796
939
|
path: detail?.path
|
|
797
940
|
}))
|
|
798
941
|
});
|
|
799
|
-
|
|
942
|
+
log11.info("", { httperr });
|
|
800
943
|
throw httperr;
|
|
801
944
|
}
|
|
802
945
|
return value;
|
|
803
946
|
};
|
|
804
947
|
|
|
805
948
|
// src/helpers/logging-helper.ts
|
|
806
|
-
import * as
|
|
949
|
+
import * as log12 from "lambda-log";
|
|
807
950
|
var stage = process?.env?.STAGE;
|
|
808
|
-
var configureLogger = (event, context,
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
951
|
+
var configureLogger = (event, context, debug5 = true) => {
|
|
952
|
+
log12.options.meta.stage = stage;
|
|
953
|
+
log12.options.meta.source_name = context?.functionName || "unknown";
|
|
954
|
+
log12.options.meta.awsRequestId = context?.awsRequestId || "unknown";
|
|
955
|
+
log12.options.meta.lambdaEvent = event;
|
|
956
|
+
log12.options.debug = debug5;
|
|
814
957
|
};
|
|
815
958
|
|
|
816
959
|
// src/helpers/response-helper.ts
|
|
@@ -820,13 +963,13 @@ var success = (body) => {
|
|
|
820
963
|
var defaultError = {
|
|
821
964
|
message: "internalServerError"
|
|
822
965
|
};
|
|
823
|
-
var failure = (
|
|
824
|
-
statusCode =
|
|
966
|
+
var failure = (error7, statusCode = 500) => {
|
|
967
|
+
statusCode = error7?.statusCode ?? statusCode;
|
|
825
968
|
let body = defaultError;
|
|
826
|
-
if (
|
|
827
|
-
body =
|
|
828
|
-
} else if (
|
|
829
|
-
body = { message:
|
|
969
|
+
if (error7?.body) {
|
|
970
|
+
body = error7.body;
|
|
971
|
+
} else if (error7?.message) {
|
|
972
|
+
body = { message: error7.message };
|
|
830
973
|
} else if (statusCode === 500) {
|
|
831
974
|
body = defaultError;
|
|
832
975
|
}
|
|
@@ -1103,6 +1246,7 @@ export {
|
|
|
1103
1246
|
ADTRACKIFY_EVENT_SOURCES,
|
|
1104
1247
|
ADTRACKIFY_EVENT_TYPES,
|
|
1105
1248
|
AccountsClient,
|
|
1249
|
+
CognitoClient,
|
|
1106
1250
|
CommonPlanInfo,
|
|
1107
1251
|
DestinationsClient,
|
|
1108
1252
|
DynamoDbClient,
|
|
@@ -1120,6 +1264,7 @@ export {
|
|
|
1120
1264
|
axiosHttpService,
|
|
1121
1265
|
buildResponse,
|
|
1122
1266
|
configureLogger,
|
|
1267
|
+
dictToAwsAttributes,
|
|
1123
1268
|
failure,
|
|
1124
1269
|
generatePublicKey,
|
|
1125
1270
|
getCurrentDate,
|