Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add missing "X-Shopify-Triggered-At" in ShopifyHeader #1941

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
15 changes: 15 additions & 0 deletions .changeset/nice-comics-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
'@shopify/shopify-api': minor
---

Update missing Shopify header in webhook

https://shopify.dev/docs/apps/build/webhooks#key-terminology
```ts

enum ShopifyHeader {
...,
TriggeredAt = 'X-Shopify-Triggered-At', // added
EventId = 'X-Shopify-Event-Id', // added
}
```
2 changes: 2 additions & 0 deletions packages/apps/shopify-api/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export enum ShopifyHeader {
Topic = 'X-Shopify-Topic',
SubTopic = 'X-Shopify-Sub-Topic',
WebhookId = 'X-Shopify-Webhook-Id',
TriggeredAt = 'X-Shopify-Triggered-At',
EventId = 'X-Shopify-Event-Id',
StorefrontPrivateToken = 'Shopify-Storefront-Private-Token',
StorefrontSDKVariant = 'X-SDK-Variant',
StorefrontSDKVersion = 'X-SDK-Version',
Expand Down
9 changes: 9 additions & 0 deletions packages/apps/shopify-api/lib/webhooks/__tests__/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export function headers({
hmac = 'fake',
topic = 'products/create',
webhookId = '123456789',
triggeredAt = '2023-01-01T00:00:00Z',
eventId = '123456789',
// must explicitly set to test for presence
subTopic = '',
lowercase = false,
Expand All @@ -37,6 +39,8 @@ export function headers({
topic?: string;
webhookId?: string;
subTopic?: string;
triggeredAt?: string;
eventId?: string;
lowercase?: boolean;
} = {}) {
return {
Expand All @@ -58,6 +62,11 @@ export function headers({
: ShopifyHeader.SubTopic]: subTopic,
}
: {}),
[lowercase
? ShopifyHeader.TriggeredAt.toLowerCase()
: ShopifyHeader.TriggeredAt]: triggeredAt,
[lowercase ? ShopifyHeader.EventId.toLowerCase() : ShopifyHeader.EventId]:
eventId,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ describe('shopify.webhooks.validate', () => {
webhookId: '123456789',
apiVersion: '2023-01',
domain: 'shop1.myshopify.io',
eventId: '123456789',
hmac: 'B23tXN681gZ0qIWNRrgtzBE9XSDo5yaUu6wfmhu3a7g=',
topic: 'PRODUCTS_CREATE',
triggeredAt: '2023-01-01T00:00:00Z',
});
});

Expand Down
2 changes: 2 additions & 0 deletions packages/apps/shopify-api/lib/webhooks/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const HANDLER_PROPERTIES = {
hmac: ShopifyHeader.Hmac,
topic: ShopifyHeader.Topic,
webhookId: ShopifyHeader.WebhookId,
triggeredAt: ShopifyHeader.TriggeredAt,
eventId: ShopifyHeader.EventId,
...OPTIONAL_HANDLER_PROPERTIES,
};

Expand Down
Loading