shopify-webhook-schemas 0.1.2 → 0.1.4

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.
Files changed (155) hide show
  1. package/Readme.md +14 -2
  2. package/dist/src/anonymize-exemplars.d.ts +1 -0
  3. package/dist/src/anonymize-exemplars.js +51 -0
  4. package/dist/src/index.js +11 -5
  5. package/dist/src/scrape.js +501 -182
  6. package/metadatas/2024-07/app_purchases_one_time/update.json +1 -1
  7. package/metadatas/2024-07/app_subscriptions/approaching_capped_amount.json +1 -1
  8. package/metadatas/2024-07/app_subscriptions/update.json +1 -1
  9. package/metadatas/2024-07/bulk_operations/finish.json +2 -2
  10. package/metadatas/2024-07/checkouts/create.json +6 -6
  11. package/metadatas/2024-07/checkouts/update.json +6 -6
  12. package/metadatas/2024-07/draft_orders/create.json +20 -20
  13. package/metadatas/2024-07/draft_orders/update.json +20 -20
  14. package/metadatas/2024-07/orders/edited.json +1 -0
  15. package/metadatas/2024-07/product_listings/add.json +1 -13
  16. package/metadatas/2024-07/product_listings/update.json +1 -13
  17. package/metadatas/2024-07/scheduled_product_listings/add.json +1 -13
  18. package/metadatas/2024-07/scheduled_product_listings/update.json +1 -13
  19. package/metadatas/2024-07/selling_plan_groups/create.json +2 -2
  20. package/metadatas/2024-07/selling_plan_groups/delete.json +2 -2
  21. package/metadatas/2024-07/selling_plan_groups/update.json +2 -2
  22. package/metadatas/2024-07/subscription_billing_attempts/challenged.json +2 -2
  23. package/metadatas/2024-07/subscription_billing_attempts/failure.json +2 -2
  24. package/metadatas/2024-07/subscription_billing_attempts/success.json +2 -2
  25. package/metadatas/2024-07/subscription_billing_cycle_edits/create.json +1 -1
  26. package/metadatas/2024-07/subscription_billing_cycle_edits/delete.json +1 -1
  27. package/metadatas/2024-07/subscription_billing_cycle_edits/update.json +1 -1
  28. package/metadatas/2024-07/subscription_billing_cycles/skip.json +1 -1
  29. package/metadatas/2024-07/subscription_billing_cycles/unskip.json +1 -1
  30. package/metadatas/2024-07/subscription_contracts/activate.json +3 -3
  31. package/metadatas/2024-07/subscription_contracts/cancel.json +3 -3
  32. package/metadatas/2024-07/subscription_contracts/create.json +3 -3
  33. package/metadatas/2024-07/subscription_contracts/expire.json +3 -3
  34. package/metadatas/2024-07/subscription_contracts/fail.json +3 -3
  35. package/metadatas/2024-07/subscription_contracts/pause.json +3 -3
  36. package/metadatas/2024-07/subscription_contracts/update.json +3 -3
  37. package/package.json +9 -1
  38. package/schemas/2023-07/checkouts/create.json +578 -102
  39. package/schemas/2023-07/checkouts/delete.json +26 -4
  40. package/schemas/2023-07/checkouts/update.json +578 -102
  41. package/schemas/2023-07/collection_listings/add.json +9 -2
  42. package/schemas/2023-07/collection_listings/remove.json +7 -0
  43. package/schemas/2023-07/collection_listings/update.json +9 -2
  44. package/schemas/2023-07/company_locations/create.json +8 -2
  45. package/schemas/2023-07/company_locations/delete.json +8 -2
  46. package/schemas/2023-07/company_locations/update.json +8 -2
  47. package/schemas/2023-07/draft_orders/create.json +729 -126
  48. package/schemas/2023-07/draft_orders/update.json +729 -126
  49. package/schemas/2023-07/fulfillments/create.json +149 -30
  50. package/schemas/2023-07/fulfillments/update.json +149 -30
  51. package/schemas/2023-07/order_transactions/create.json +31 -9
  52. package/schemas/2023-07/orders/cancelled.json +966 -48
  53. package/schemas/2023-07/orders/create.json +966 -48
  54. package/schemas/2023-07/orders/fulfilled.json +966 -48
  55. package/schemas/2023-07/orders/paid.json +966 -48
  56. package/schemas/2023-07/orders/partially_fulfilled.json +966 -48
  57. package/schemas/2023-07/orders/updated.json +966 -48
  58. package/schemas/2023-07/products/create.json +191 -17
  59. package/schemas/2023-07/products/update.json +191 -17
  60. package/schemas/2023-10/checkouts/create.json +578 -102
  61. package/schemas/2023-10/checkouts/delete.json +26 -4
  62. package/schemas/2023-10/checkouts/update.json +578 -102
  63. package/schemas/2023-10/collection_listings/add.json +9 -2
  64. package/schemas/2023-10/collection_listings/remove.json +7 -0
  65. package/schemas/2023-10/collection_listings/update.json +9 -2
  66. package/schemas/2023-10/company_locations/create.json +8 -2
  67. package/schemas/2023-10/company_locations/delete.json +8 -2
  68. package/schemas/2023-10/company_locations/update.json +8 -2
  69. package/schemas/2023-10/draft_orders/create.json +729 -126
  70. package/schemas/2023-10/draft_orders/update.json +729 -126
  71. package/schemas/2023-10/fulfillments/create.json +149 -30
  72. package/schemas/2023-10/fulfillments/update.json +149 -30
  73. package/schemas/2023-10/order_transactions/create.json +28 -9
  74. package/schemas/2023-10/orders/cancelled.json +966 -48
  75. package/schemas/2023-10/orders/create.json +966 -48
  76. package/schemas/2023-10/orders/fulfilled.json +966 -48
  77. package/schemas/2023-10/orders/paid.json +966 -48
  78. package/schemas/2023-10/orders/partially_fulfilled.json +966 -48
  79. package/schemas/2023-10/orders/updated.json +966 -48
  80. package/schemas/2023-10/products/create.json +191 -17
  81. package/schemas/2023-10/products/update.json +191 -17
  82. package/schemas/2024-01/checkouts/create.json +585 -100
  83. package/schemas/2024-01/checkouts/delete.json +26 -4
  84. package/schemas/2024-01/checkouts/update.json +585 -100
  85. package/schemas/2024-01/collection_listings/add.json +9 -2
  86. package/schemas/2024-01/collection_listings/remove.json +7 -0
  87. package/schemas/2024-01/collection_listings/update.json +9 -2
  88. package/schemas/2024-01/company_locations/create.json +8 -2
  89. package/schemas/2024-01/company_locations/delete.json +8 -2
  90. package/schemas/2024-01/company_locations/update.json +8 -2
  91. package/schemas/2024-01/draft_orders/create.json +733 -124
  92. package/schemas/2024-01/draft_orders/update.json +733 -124
  93. package/schemas/2024-01/fulfillment_orders/split.json +237 -2
  94. package/schemas/2024-01/fulfillments/create.json +149 -30
  95. package/schemas/2024-01/fulfillments/update.json +149 -30
  96. package/schemas/2024-01/order_transactions/create.json +28 -9
  97. package/schemas/2024-01/orders/cancelled.json +970 -50
  98. package/schemas/2024-01/orders/create.json +970 -50
  99. package/schemas/2024-01/orders/fulfilled.json +970 -50
  100. package/schemas/2024-01/orders/paid.json +970 -50
  101. package/schemas/2024-01/orders/partially_fulfilled.json +970 -50
  102. package/schemas/2024-01/orders/updated.json +970 -50
  103. package/schemas/2024-01/products/create.json +191 -17
  104. package/schemas/2024-01/products/update.json +191 -17
  105. package/schemas/2024-04/checkouts/create.json +585 -100
  106. package/schemas/2024-04/checkouts/delete.json +26 -4
  107. package/schemas/2024-04/checkouts/update.json +585 -100
  108. package/schemas/2024-04/collection_listings/add.json +9 -2
  109. package/schemas/2024-04/collection_listings/remove.json +7 -0
  110. package/schemas/2024-04/collection_listings/update.json +9 -2
  111. package/schemas/2024-04/company_locations/create.json +8 -2
  112. package/schemas/2024-04/company_locations/delete.json +8 -2
  113. package/schemas/2024-04/company_locations/update.json +8 -2
  114. package/schemas/2024-04/draft_orders/create.json +733 -124
  115. package/schemas/2024-04/draft_orders/update.json +733 -124
  116. package/schemas/2024-04/fulfillment_orders/split.json +237 -2
  117. package/schemas/2024-04/fulfillments/create.json +149 -30
  118. package/schemas/2024-04/fulfillments/update.json +149 -30
  119. package/schemas/2024-04/order_transactions/create.json +28 -9
  120. package/schemas/2024-04/orders/cancelled.json +967 -50
  121. package/schemas/2024-04/orders/create.json +967 -50
  122. package/schemas/2024-04/orders/fulfilled.json +967 -50
  123. package/schemas/2024-04/orders/paid.json +967 -50
  124. package/schemas/2024-04/orders/partially_fulfilled.json +967 -50
  125. package/schemas/2024-04/orders/updated.json +967 -50
  126. package/schemas/2024-04/products/create.json +191 -17
  127. package/schemas/2024-04/products/update.json +191 -17
  128. package/schemas/2024-07/checkouts/create.json +585 -100
  129. package/schemas/2024-07/checkouts/delete.json +26 -4
  130. package/schemas/2024-07/checkouts/update.json +585 -100
  131. package/schemas/2024-07/collection_listings/add.json +9 -2
  132. package/schemas/2024-07/collection_listings/remove.json +7 -0
  133. package/schemas/2024-07/collection_listings/update.json +9 -2
  134. package/schemas/2024-07/company_locations/create.json +8 -2
  135. package/schemas/2024-07/company_locations/delete.json +8 -2
  136. package/schemas/2024-07/company_locations/update.json +8 -2
  137. package/schemas/2024-07/draft_orders/create.json +733 -124
  138. package/schemas/2024-07/draft_orders/update.json +733 -124
  139. package/schemas/2024-07/fulfillment_orders/split.json +237 -2
  140. package/schemas/2024-07/fulfillments/create.json +149 -30
  141. package/schemas/2024-07/fulfillments/update.json +149 -30
  142. package/schemas/2024-07/order_transactions/create.json +28 -9
  143. package/schemas/2024-07/orders/cancelled.json +967 -50
  144. package/schemas/2024-07/orders/create.json +967 -50
  145. package/schemas/2024-07/orders/edited.json +5 -0
  146. package/schemas/2024-07/orders/fulfilled.json +967 -50
  147. package/schemas/2024-07/orders/paid.json +967 -50
  148. package/schemas/2024-07/orders/partially_fulfilled.json +967 -50
  149. package/schemas/2024-07/orders/updated.json +967 -50
  150. package/schemas/2024-07/product_listings/add.json +1 -44
  151. package/schemas/2024-07/product_listings/update.json +1 -44
  152. package/schemas/2024-07/products/create.json +191 -17
  153. package/schemas/2024-07/products/update.json +191 -17
  154. package/schemas/2024-07/scheduled_product_listings/add.json +1 -44
  155. package/schemas/2024-07/scheduled_product_listings/update.json +1 -44
package/Readme.md CHANGED
@@ -2,15 +2,20 @@
2
2
 
3
3
  This repo contains inferred JSONSchemas for each Shopify webhook topic payload. Find them all in the `schemas` directory.
4
4
 
5
- ### Usage from JavaScript
5
+ They're built by scraping Shopify's example payloads in their docs as well as comparing to a bunch of anonymized example payloads in this repo.
6
6
 
7
- If you want to load the metadata or the json schemas programmatically from JS, you can do so with the exported functions from this library.
7
+ Contributions to correct the types or add new examples of rare payloads are welcome!
8
+
9
+ ## Usage from JavaScript
10
+
11
+ If you want to load the json schemas programmatically from JS, or the metadata objects that Shopify exposes under the hood, you can do so with the exported functions from this library.
8
12
 
9
13
  ```typescript
10
14
  import { metadataForWebhook, schemaForWebhook } from "shopify-webhook-schemas";
11
15
 
12
16
  // get the JSONSchema for a webhook payload
13
17
  const schema = schemaForWebhook("2024-04", "products/update");
18
+
14
19
  // returns {
15
20
  // "$schema": "https://json-schema.org/draft/2020-12/schema",
16
21
  // "type": "object",
@@ -26,6 +31,7 @@ const schema = schemaForWebhook("2024-04", "products/update");
26
31
 
27
32
  // get the metadata blob with an description and example payload that shopify puts in their docs
28
33
  const metadata = metadataForWebhook("2024-04", "products/update");
34
+
29
35
  // returns {
30
36
  // "access_scopes": [
31
37
  // "products"
@@ -53,6 +59,12 @@ const topics = allTopicsForVersion("2024-04");
53
59
  // ...
54
60
  ```
55
61
 
62
+ ### Editorialization
63
+
64
+ This repo includes some inferred types beyond what Shopify's docs offer based on observed data in the wild. Shopify's example payloads are the ground truth, but they often include `null` for field values, so we have to guess what the real type of the value is. If you believe there to be an error, please open a PR adjusting the overrides in `src/scrape.ts`.
65
+
56
66
  ### Refreshing
57
67
 
58
68
  Run `pnpm x src/scrape.ts` to re-scrape Shopify's docs. See `src/scrape.ts` for the logic and the overrides.
69
+
70
+ Add new exemplars in in the `exemplars/` directory, and then run `pnpm x src/anonymize-exemplars.ts` to remove any PII.
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const path_1 = __importDefault(require("path"));
7
+ const json_infer_types_1 = require("@jsonhero/json-infer-types");
8
+ const globby_1 = require("globby");
9
+ const fs_extra_1 = __importDefault(require("fs-extra"));
10
+ const traverse_1 = __importDefault(require("traverse"));
11
+ const main = async () => {
12
+ const files = await (0, globby_1.globby)(path_1.default.join(__dirname, "../exemplars/**/*.json"));
13
+ console.log(`anonymizing ${files.length} files`);
14
+ for (const file of files) {
15
+ let json = await fs_extra_1.default.readJSON(file);
16
+ json = (0, traverse_1.default)(json).map(function (value) {
17
+ if (typeof value == "number") {
18
+ return Math.round(value) == value ? 123 : 123.456;
19
+ }
20
+ else if (typeof value == "string") {
21
+ const type = (0, json_infer_types_1.inferType)(value);
22
+ if ('format' in type && type.format) {
23
+ switch (type.format.name) {
24
+ case "email": {
25
+ return "eallam@example.com";
26
+ }
27
+ case "date": {
28
+ return "2016-05-25";
29
+ }
30
+ case "datetime": {
31
+ return "2019-01-01 00:00:00.000Z";
32
+ }
33
+ case "uri": {
34
+ return "https://www.example.com/";
35
+ }
36
+ case "ip": {
37
+ return "192.168.0.1";
38
+ }
39
+ }
40
+ }
41
+ return "example string";
42
+ }
43
+ else {
44
+ return value;
45
+ }
46
+ });
47
+ await fs_extra_1.default.writeJSON(file, json, { spaces: 2 });
48
+ }
49
+ console.log("done");
50
+ };
51
+ void main();
package/dist/src/index.js CHANGED
@@ -10,8 +10,8 @@ const fast_glob_1 = __importDefault(require("fast-glob"));
10
10
  const loaded = { metadatas: {}, schemas: {} };
11
11
  function getPackageRootDir() {
12
12
  let currentDir = __dirname;
13
- while (!fs_1.default.existsSync(path_1.default.join(currentDir, 'package.json'))) {
14
- currentDir = path_1.default.join(currentDir, '..');
13
+ while (!fs_1.default.existsSync(path_1.default.join(currentDir, "package.json"))) {
14
+ currentDir = path_1.default.join(currentDir, "..");
15
15
  }
16
16
  return currentDir;
17
17
  }
@@ -29,18 +29,24 @@ for (const kind of ["metadatas", "schemas"]) {
29
29
  }
30
30
  }
31
31
  }
32
+ const getVersion = (obj, version) => {
33
+ const value = obj[version];
34
+ if (value)
35
+ return value;
36
+ throw new Error(`Unknown shopify api version ${version} in shopify-webhook-schemas package -- please pass a real version or regenerate the metadata`);
37
+ };
32
38
  /** Return a metadata blob from Shopify's docs describing a webhook topic */
33
39
  function metadataForWebhook(apiVersion, topic) {
34
- return loaded.metadatas[apiVersion][topic];
40
+ return getVersion(loaded.metadatas, apiVersion)[topic];
35
41
  }
36
42
  exports.metadataForWebhook = metadataForWebhook;
37
43
  /** Return the inferred JSON schema describing a webhook payload */
38
44
  function schemaForWebhook(apiVersion, topic) {
39
- return loaded.schemas[apiVersion][topic];
45
+ return getVersion(loaded.schemas, apiVersion)[topic];
40
46
  }
41
47
  exports.schemaForWebhook = schemaForWebhook;
42
48
  /** Return all the known webhook topics */
43
49
  function allTopicsForVersion(apiVersion) {
44
- return Object.keys(loaded.schemas[apiVersion]);
50
+ return Object.keys(getVersion(loaded.schemas, apiVersion));
45
51
  }
46
52
  exports.allTopicsForVersion = allTopicsForVersion;