Skip to content

Commit 20de540

Browse files
committed
unknown types bug
1 parent e3d80f9 commit 20de540

File tree

2 files changed

+74
-5
lines changed

2 files changed

+74
-5
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "medusa-plugin-sendgrid-typescript",
3-
"version": "2.2.0",
3+
"version": "2.2.1",
44
"description": "SendGrid transactional emails typescript",
55
"repository": {
66
"type": "git",
@@ -13,7 +13,7 @@
1313
"files": [
1414
"dist"
1515
],
16-
"author": "Lucjan Grzesik | Oliver Juhl ",
16+
"author": "Lucjan Grzesik | Oliver Juhl",
1717
"license": "MIT",
1818
"devDependencies": {
1919
"@babel/plugin-proposal-class-properties": "^7.18.6",

src/services/sendgrid.ts

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,13 @@ export class SendGridService extends AbstractNotificationService {
382382
}
383383

384384
async orderShipmentCreatedData({ id, fulfillment_id }: Record<string, unknown>, attachmentGenerator?: any) {
385+
if (!id || typeof id !== "string") {
386+
throw new MedusaError(
387+
MedusaError.Types.INVALID_DATA,
388+
`Sendgrid service: No order_id was set for event: order.shipment_created
389+
`
390+
)
391+
}
385392
const order = await this.orderService_.retrieve(id, {
386393
select: [
387394
"shipping_total",
@@ -434,6 +441,13 @@ export class SendGridService extends AbstractNotificationService {
434441
}
435442

436443
async orderCanceledData({ id }: Record<string, unknown>) {
444+
if (!id || typeof id !== "string") {
445+
throw new MedusaError(
446+
MedusaError.Types.INVALID_DATA,
447+
`Sendgrid service: No order_id was set for event: order.shipment_created
448+
`
449+
)
450+
}
437451
const order = await this.orderService_.retrieve(id, {
438452
select: [
439453
"shipping_total",
@@ -542,6 +556,13 @@ export class SendGridService extends AbstractNotificationService {
542556
}
543557

544558
async orderPlacedData({ id }: Record<string, unknown>) {
559+
if (!id || typeof id !== "string") {
560+
throw new MedusaError(
561+
MedusaError.Types.INVALID_DATA,
562+
`Sendgrid service: No order_id was set for event: order.shipment_created
563+
`
564+
)
565+
}
545566
const order = await this.orderService_.retrieve(id, {
546567
select: [
547568
"shipping_total",
@@ -690,6 +711,13 @@ export class SendGridService extends AbstractNotificationService {
690711
}
691712

692713
async gcCreatedData({ id }: Record<string, unknown>) {
714+
if (!id || typeof id !== "string") {
715+
throw new MedusaError(
716+
MedusaError.Types.INVALID_DATA,
717+
`Sendgrid service: No order_id was set for event: order.shipment_created
718+
`
719+
)
720+
}
693721
const giftCard = await this.giftCardService_.retrieve(id, {
694722
relations: ["region", "order"],
695723
})
@@ -716,7 +744,7 @@ export class SendGridService extends AbstractNotificationService {
716744

717745
async returnRequestedData({ id, return_id }: Record<string, unknown>) {
718746
// Fetch the return request
719-
if (!return_id) {
747+
if (!return_id || typeof return_id !== "string") {
720748
throw new MedusaError(
721749
MedusaError.Types.INVALID_DATA,
722750
`Sendgrid service: No return_id was set for event: order.return_requested`
@@ -740,7 +768,13 @@ export class SendGridService extends AbstractNotificationService {
740768
relations: ["tax_lines", "variant", "variant.product.profiles"],
741769
}
742770
)
743-
771+
if (!id || typeof id !== "string") {
772+
throw new MedusaError(
773+
MedusaError.Types.INVALID_DATA,
774+
`Sendgrid service: No order_id was set for event: order.shipment_created
775+
`
776+
)
777+
}
744778
// Fetch the order
745779
const order = await this.orderService_.retrieve(id, {
746780
select: ["total"],
@@ -861,6 +895,13 @@ export class SendGridService extends AbstractNotificationService {
861895
}
862896

863897
async swapReceivedData({ id }: Record<string, unknown>) {
898+
if (!id || typeof id !== "string") {
899+
throw new MedusaError(
900+
MedusaError.Types.INVALID_DATA,
901+
`Sendgrid service: No order_id was set for event: order.shipment_created
902+
`
903+
)
904+
}
864905
const store = await this.storeService_.retrieve()
865906

866907
const swap = await this.swapService_.retrieve(id, {
@@ -1003,6 +1044,13 @@ export class SendGridService extends AbstractNotificationService {
10031044
}
10041045

10051046
async swapCreatedData({ id }: Record<string, unknown>) {
1047+
if (!id || typeof id !== "string") {
1048+
throw new MedusaError(
1049+
MedusaError.Types.INVALID_DATA,
1050+
`Sendgrid service: No order_id was set for event: order.shipment_created
1051+
`
1052+
)
1053+
}
10061054
const store = await this.storeService_.retrieve()
10071055
const swap = await this.swapService_.retrieve(id, {
10081056
relations: [
@@ -1154,6 +1202,13 @@ export class SendGridService extends AbstractNotificationService {
11541202
}
11551203

11561204
async swapShipmentCreatedData({ id, fulfillment_id }: Record<string, unknown>) {
1205+
if (!id || typeof id !== "string") {
1206+
throw new MedusaError(
1207+
MedusaError.Types.INVALID_DATA,
1208+
`Sendgrid service: No order_id was set for event: order.shipment_created
1209+
`
1210+
)
1211+
}
11571212
const swap = await this.swapService_.retrieve(id, {
11581213
relations: [
11591214
"shipping_address",
@@ -1313,6 +1368,13 @@ export class SendGridService extends AbstractNotificationService {
13131368
}
13141369

13151370
async claimShipmentCreatedData({ id, fulfillment_id }: Record<string, unknown>) {
1371+
if (!id || typeof id !== "string") {
1372+
throw new MedusaError(
1373+
MedusaError.Types.INVALID_DATA,
1374+
`Sendgrid service: No order_id was set for event: order.shipment_created
1375+
`
1376+
)
1377+
}
13161378
const claim = await this.claimService_.retrieve(id, {
13171379
relations: [
13181380
"order.items.variant.product.profiles",
@@ -1344,7 +1406,7 @@ export class SendGridService extends AbstractNotificationService {
13441406
}
13451407

13461408
async restockNotificationData({ variant_id, emails }: Record<string, unknown>) {
1347-
if (!variant_id) {
1409+
if (!variant_id || typeof variant_id !== "string") {
13481410
throw new MedusaError(
13491411
MedusaError.Types.INVALID_DATA,
13501412
`Sendgrid service: No variant_id was set for event: restock-notification.restocked`
@@ -1379,6 +1441,13 @@ export class SendGridService extends AbstractNotificationService {
13791441
}
13801442

13811443
async orderRefundCreatedData({ id, refund_id }: Record<string, unknown>) {
1444+
if (!id || typeof id !== "string") {
1445+
throw new MedusaError(
1446+
MedusaError.Types.INVALID_DATA,
1447+
`Sendgrid service: No order_id was set for event: order.shipment_created
1448+
`
1449+
)
1450+
}
13821451
const order = await this.orderService_.retrieveWithTotals(id, {
13831452
relations: ["refunds", "items"],
13841453
})

0 commit comments

Comments
 (0)