|
1 | 1 | import { DeliveryMethod } from "@shopify/shopify-api";
|
2 |
| -import shopify from "./shopify.js"; |
3 | 2 |
|
4 |
| -export async function setupGDPRWebHooks(path) { |
| 3 | +export default { |
5 | 4 | /**
|
6 | 5 | * Customers can request their data from a store owner. When this happens,
|
7 | 6 | * Shopify invokes this webhook.
|
8 | 7 | *
|
9 | 8 | * https://shopify.dev/apps/webhooks/configuration/mandatory-webhooks#customers-data_request
|
10 | 9 | */
|
11 |
| - await shopify.webhooks.addHandlers({ |
12 |
| - CUSTOMERS_DATA_REQUEST: { |
13 |
| - deliveryMethod: DeliveryMethod.Http, |
14 |
| - callbackUrl: path, |
15 |
| - callback: async (topic, shop, body) => { |
16 |
| - const payload = JSON.parse(body); |
17 |
| - // Payload has the following shape: |
18 |
| - // { |
19 |
| - // "shop_id": 954889, |
20 |
| - // "shop_domain": "{shop}.myshopify.com", |
21 |
| - // "orders_requested": [ |
22 |
| - // 299938, |
23 |
| - // 280263, |
24 |
| - // 220458 |
25 |
| - // ], |
26 |
| - // "customer": { |
27 |
| - // "id": 191167, |
28 |
| - // "email": "john@example.com", |
29 |
| - // "phone": "555-625-1199" |
30 |
| - // }, |
31 |
| - // "data_request": { |
32 |
| - // "id": 9999 |
33 |
| - // } |
34 |
| - // } |
35 |
| - }, |
| 10 | + CUSTOMERS_DATA_REQUEST: { |
| 11 | + deliveryMethod: DeliveryMethod.Http, |
| 12 | + callback: async (topic, shop, body) => { |
| 13 | + const payload = JSON.parse(body); |
| 14 | + // Payload has the following shape: |
| 15 | + // { |
| 16 | + // "shop_id": 954889, |
| 17 | + // "shop_domain": "{shop}.myshopify.com", |
| 18 | + // "orders_requested": [ |
| 19 | + // 299938, |
| 20 | + // 280263, |
| 21 | + // 220458 |
| 22 | + // ], |
| 23 | + // "customer": { |
| 24 | + // "id": 191167, |
| 25 | + // "email": "john@example.com", |
| 26 | + // "phone": "555-625-1199" |
| 27 | + // }, |
| 28 | + // "data_request": { |
| 29 | + // "id": 9999 |
| 30 | + // } |
| 31 | + // } |
36 | 32 | },
|
37 |
| - }); |
| 33 | + }, |
38 | 34 |
|
39 | 35 | /**
|
40 | 36 | * Store owners can request that data is deleted on behalf of a customer. When
|
41 | 37 | * this happens, Shopify invokes this webhook.
|
42 | 38 | *
|
43 | 39 | * https://shopify.dev/apps/webhooks/configuration/mandatory-webhooks#customers-redact
|
44 | 40 | */
|
45 |
| - await shopify.webhooks.addHandlers({ |
46 |
| - CUSTOMERS_REDACT: { |
47 |
| - deliveryMethod: DeliveryMethod.Http, |
48 |
| - callbackUrl: path, |
49 |
| - callback: async (topic, shop, body) => { |
50 |
| - const payload = JSON.parse(body); |
51 |
| - // Payload has the following shape: |
52 |
| - // { |
53 |
| - // "shop_id": 954889, |
54 |
| - // "shop_domain": "{shop}.myshopify.com", |
55 |
| - // "customer": { |
56 |
| - // "id": 191167, |
57 |
| - // "email": "john@example.com", |
58 |
| - // "phone": "555-625-1199" |
59 |
| - // }, |
60 |
| - // "orders_to_redact": [ |
61 |
| - // 299938, |
62 |
| - // 280263, |
63 |
| - // 220458 |
64 |
| - // ] |
65 |
| - // } |
66 |
| - }, |
| 41 | + CUSTOMERS_REDACT: { |
| 42 | + deliveryMethod: DeliveryMethod.Http, |
| 43 | + callback: async (topic, shop, body) => { |
| 44 | + const payload = JSON.parse(body); |
| 45 | + // Payload has the following shape: |
| 46 | + // { |
| 47 | + // "shop_id": 954889, |
| 48 | + // "shop_domain": "{shop}.myshopify.com", |
| 49 | + // "customer": { |
| 50 | + // "id": 191167, |
| 51 | + // "email": "john@example.com", |
| 52 | + // "phone": "555-625-1199" |
| 53 | + // }, |
| 54 | + // "orders_to_redact": [ |
| 55 | + // 299938, |
| 56 | + // 280263, |
| 57 | + // 220458 |
| 58 | + // ] |
| 59 | + // } |
67 | 60 | },
|
68 |
| - }); |
| 61 | + }, |
69 | 62 |
|
70 | 63 | /**
|
71 | 64 | * 48 hours after a store owner uninstalls your app, Shopify invokes this
|
72 | 65 | * webhook.
|
73 | 66 | *
|
74 | 67 | * https://shopify.dev/apps/webhooks/configuration/mandatory-webhooks#shop-redact
|
75 | 68 | */
|
76 |
| - await shopify.webhooks.addHandlers({ |
77 |
| - SHOP_REDACT: { |
78 |
| - deliveryMethod: DeliveryMethod.Http, |
79 |
| - callbackUrl: path, |
80 |
| - callback: async (topic, shop, body) => { |
81 |
| - const payload = JSON.parse(body); |
82 |
| - // Payload has the following shape: |
83 |
| - // { |
84 |
| - // "shop_id": 954889, |
85 |
| - // "shop_domain": "{shop}.myshopify.com" |
86 |
| - // } |
87 |
| - }, |
| 69 | + SHOP_REDACT: { |
| 70 | + deliveryMethod: DeliveryMethod.Http, |
| 71 | + callback: async (topic, shop, body) => { |
| 72 | + const payload = JSON.parse(body); |
| 73 | + // Payload has the following shape: |
| 74 | + // { |
| 75 | + // "shop_id": 954889, |
| 76 | + // "shop_domain": "{shop}.myshopify.com" |
| 77 | + // } |
88 | 78 | },
|
89 |
| - }); |
90 |
| -} |
| 79 | + }, |
| 80 | +}; |
0 commit comments