From 20de54053067d732f74310326aea6c9311ddc32f Mon Sep 17 00:00:00 2001 From: luluhoc Date: Wed, 6 Nov 2024 19:55:57 +0000 Subject: [PATCH] unknown types bug --- package.json | 4 +-- src/services/sendgrid.ts | 75 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 74 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 04a648d..8ace27b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "medusa-plugin-sendgrid-typescript", - "version": "2.2.0", + "version": "2.2.1", "description": "SendGrid transactional emails typescript", "repository": { "type": "git", @@ -13,7 +13,7 @@ "files": [ "dist" ], - "author": "Lucjan Grzesik | Oliver Juhl ", + "author": "Lucjan Grzesik | Oliver Juhl", "license": "MIT", "devDependencies": { "@babel/plugin-proposal-class-properties": "^7.18.6", diff --git a/src/services/sendgrid.ts b/src/services/sendgrid.ts index 5ff8444..d9ad6d6 100644 --- a/src/services/sendgrid.ts +++ b/src/services/sendgrid.ts @@ -382,6 +382,13 @@ export class SendGridService extends AbstractNotificationService { } async orderShipmentCreatedData({ id, fulfillment_id }: Record, attachmentGenerator?: any) { + if (!id || typeof id !== "string") { + throw new MedusaError( + MedusaError.Types.INVALID_DATA, + `Sendgrid service: No order_id was set for event: order.shipment_created + ` + ) + } const order = await this.orderService_.retrieve(id, { select: [ "shipping_total", @@ -434,6 +441,13 @@ export class SendGridService extends AbstractNotificationService { } async orderCanceledData({ id }: Record) { + if (!id || typeof id !== "string") { + throw new MedusaError( + MedusaError.Types.INVALID_DATA, + `Sendgrid service: No order_id was set for event: order.shipment_created + ` + ) + } const order = await this.orderService_.retrieve(id, { select: [ "shipping_total", @@ -542,6 +556,13 @@ export class SendGridService extends AbstractNotificationService { } async orderPlacedData({ id }: Record) { + if (!id || typeof id !== "string") { + throw new MedusaError( + MedusaError.Types.INVALID_DATA, + `Sendgrid service: No order_id was set for event: order.shipment_created + ` + ) + } const order = await this.orderService_.retrieve(id, { select: [ "shipping_total", @@ -690,6 +711,13 @@ export class SendGridService extends AbstractNotificationService { } async gcCreatedData({ id }: Record) { + if (!id || typeof id !== "string") { + throw new MedusaError( + MedusaError.Types.INVALID_DATA, + `Sendgrid service: No order_id was set for event: order.shipment_created + ` + ) + } const giftCard = await this.giftCardService_.retrieve(id, { relations: ["region", "order"], }) @@ -716,7 +744,7 @@ export class SendGridService extends AbstractNotificationService { async returnRequestedData({ id, return_id }: Record) { // Fetch the return request - if (!return_id) { + if (!return_id || typeof return_id !== "string") { throw new MedusaError( MedusaError.Types.INVALID_DATA, `Sendgrid service: No return_id was set for event: order.return_requested` @@ -740,7 +768,13 @@ export class SendGridService extends AbstractNotificationService { relations: ["tax_lines", "variant", "variant.product.profiles"], } ) - + if (!id || typeof id !== "string") { + throw new MedusaError( + MedusaError.Types.INVALID_DATA, + `Sendgrid service: No order_id was set for event: order.shipment_created + ` + ) + } // Fetch the order const order = await this.orderService_.retrieve(id, { select: ["total"], @@ -861,6 +895,13 @@ export class SendGridService extends AbstractNotificationService { } async swapReceivedData({ id }: Record) { + if (!id || typeof id !== "string") { + throw new MedusaError( + MedusaError.Types.INVALID_DATA, + `Sendgrid service: No order_id was set for event: order.shipment_created + ` + ) + } const store = await this.storeService_.retrieve() const swap = await this.swapService_.retrieve(id, { @@ -1003,6 +1044,13 @@ export class SendGridService extends AbstractNotificationService { } async swapCreatedData({ id }: Record) { + if (!id || typeof id !== "string") { + throw new MedusaError( + MedusaError.Types.INVALID_DATA, + `Sendgrid service: No order_id was set for event: order.shipment_created + ` + ) + } const store = await this.storeService_.retrieve() const swap = await this.swapService_.retrieve(id, { relations: [ @@ -1154,6 +1202,13 @@ export class SendGridService extends AbstractNotificationService { } async swapShipmentCreatedData({ id, fulfillment_id }: Record) { + if (!id || typeof id !== "string") { + throw new MedusaError( + MedusaError.Types.INVALID_DATA, + `Sendgrid service: No order_id was set for event: order.shipment_created + ` + ) + } const swap = await this.swapService_.retrieve(id, { relations: [ "shipping_address", @@ -1313,6 +1368,13 @@ export class SendGridService extends AbstractNotificationService { } async claimShipmentCreatedData({ id, fulfillment_id }: Record) { + if (!id || typeof id !== "string") { + throw new MedusaError( + MedusaError.Types.INVALID_DATA, + `Sendgrid service: No order_id was set for event: order.shipment_created + ` + ) + } const claim = await this.claimService_.retrieve(id, { relations: [ "order.items.variant.product.profiles", @@ -1344,7 +1406,7 @@ export class SendGridService extends AbstractNotificationService { } async restockNotificationData({ variant_id, emails }: Record) { - if (!variant_id) { + if (!variant_id || typeof variant_id !== "string") { throw new MedusaError( MedusaError.Types.INVALID_DATA, `Sendgrid service: No variant_id was set for event: restock-notification.restocked` @@ -1379,6 +1441,13 @@ export class SendGridService extends AbstractNotificationService { } async orderRefundCreatedData({ id, refund_id }: Record) { + if (!id || typeof id !== "string") { + throw new MedusaError( + MedusaError.Types.INVALID_DATA, + `Sendgrid service: No order_id was set for event: order.shipment_created + ` + ) + } const order = await this.orderService_.retrieveWithTotals(id, { relations: ["refunds", "items"], })