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.
- package/Readme.md +14 -2
- package/dist/src/anonymize-exemplars.d.ts +1 -0
- package/dist/src/anonymize-exemplars.js +51 -0
- package/dist/src/index.js +11 -5
- package/dist/src/scrape.js +501 -182
- package/metadatas/2024-07/app_purchases_one_time/update.json +1 -1
- package/metadatas/2024-07/app_subscriptions/approaching_capped_amount.json +1 -1
- package/metadatas/2024-07/app_subscriptions/update.json +1 -1
- package/metadatas/2024-07/bulk_operations/finish.json +2 -2
- package/metadatas/2024-07/checkouts/create.json +6 -6
- package/metadatas/2024-07/checkouts/update.json +6 -6
- package/metadatas/2024-07/draft_orders/create.json +20 -20
- package/metadatas/2024-07/draft_orders/update.json +20 -20
- package/metadatas/2024-07/orders/edited.json +1 -0
- package/metadatas/2024-07/product_listings/add.json +1 -13
- package/metadatas/2024-07/product_listings/update.json +1 -13
- package/metadatas/2024-07/scheduled_product_listings/add.json +1 -13
- package/metadatas/2024-07/scheduled_product_listings/update.json +1 -13
- package/metadatas/2024-07/selling_plan_groups/create.json +2 -2
- package/metadatas/2024-07/selling_plan_groups/delete.json +2 -2
- package/metadatas/2024-07/selling_plan_groups/update.json +2 -2
- package/metadatas/2024-07/subscription_billing_attempts/challenged.json +2 -2
- package/metadatas/2024-07/subscription_billing_attempts/failure.json +2 -2
- package/metadatas/2024-07/subscription_billing_attempts/success.json +2 -2
- package/metadatas/2024-07/subscription_billing_cycle_edits/create.json +1 -1
- package/metadatas/2024-07/subscription_billing_cycle_edits/delete.json +1 -1
- package/metadatas/2024-07/subscription_billing_cycle_edits/update.json +1 -1
- package/metadatas/2024-07/subscription_billing_cycles/skip.json +1 -1
- package/metadatas/2024-07/subscription_billing_cycles/unskip.json +1 -1
- package/metadatas/2024-07/subscription_contracts/activate.json +3 -3
- package/metadatas/2024-07/subscription_contracts/cancel.json +3 -3
- package/metadatas/2024-07/subscription_contracts/create.json +3 -3
- package/metadatas/2024-07/subscription_contracts/expire.json +3 -3
- package/metadatas/2024-07/subscription_contracts/fail.json +3 -3
- package/metadatas/2024-07/subscription_contracts/pause.json +3 -3
- package/metadatas/2024-07/subscription_contracts/update.json +3 -3
- package/package.json +9 -1
- package/schemas/2023-07/checkouts/create.json +578 -102
- package/schemas/2023-07/checkouts/delete.json +26 -4
- package/schemas/2023-07/checkouts/update.json +578 -102
- package/schemas/2023-07/collection_listings/add.json +9 -2
- package/schemas/2023-07/collection_listings/remove.json +7 -0
- package/schemas/2023-07/collection_listings/update.json +9 -2
- package/schemas/2023-07/company_locations/create.json +8 -2
- package/schemas/2023-07/company_locations/delete.json +8 -2
- package/schemas/2023-07/company_locations/update.json +8 -2
- package/schemas/2023-07/draft_orders/create.json +729 -126
- package/schemas/2023-07/draft_orders/update.json +729 -126
- package/schemas/2023-07/fulfillments/create.json +149 -30
- package/schemas/2023-07/fulfillments/update.json +149 -30
- package/schemas/2023-07/order_transactions/create.json +31 -9
- package/schemas/2023-07/orders/cancelled.json +966 -48
- package/schemas/2023-07/orders/create.json +966 -48
- package/schemas/2023-07/orders/fulfilled.json +966 -48
- package/schemas/2023-07/orders/paid.json +966 -48
- package/schemas/2023-07/orders/partially_fulfilled.json +966 -48
- package/schemas/2023-07/orders/updated.json +966 -48
- package/schemas/2023-07/products/create.json +191 -17
- package/schemas/2023-07/products/update.json +191 -17
- package/schemas/2023-10/checkouts/create.json +578 -102
- package/schemas/2023-10/checkouts/delete.json +26 -4
- package/schemas/2023-10/checkouts/update.json +578 -102
- package/schemas/2023-10/collection_listings/add.json +9 -2
- package/schemas/2023-10/collection_listings/remove.json +7 -0
- package/schemas/2023-10/collection_listings/update.json +9 -2
- package/schemas/2023-10/company_locations/create.json +8 -2
- package/schemas/2023-10/company_locations/delete.json +8 -2
- package/schemas/2023-10/company_locations/update.json +8 -2
- package/schemas/2023-10/draft_orders/create.json +729 -126
- package/schemas/2023-10/draft_orders/update.json +729 -126
- package/schemas/2023-10/fulfillments/create.json +149 -30
- package/schemas/2023-10/fulfillments/update.json +149 -30
- package/schemas/2023-10/order_transactions/create.json +28 -9
- package/schemas/2023-10/orders/cancelled.json +966 -48
- package/schemas/2023-10/orders/create.json +966 -48
- package/schemas/2023-10/orders/fulfilled.json +966 -48
- package/schemas/2023-10/orders/paid.json +966 -48
- package/schemas/2023-10/orders/partially_fulfilled.json +966 -48
- package/schemas/2023-10/orders/updated.json +966 -48
- package/schemas/2023-10/products/create.json +191 -17
- package/schemas/2023-10/products/update.json +191 -17
- package/schemas/2024-01/checkouts/create.json +585 -100
- package/schemas/2024-01/checkouts/delete.json +26 -4
- package/schemas/2024-01/checkouts/update.json +585 -100
- package/schemas/2024-01/collection_listings/add.json +9 -2
- package/schemas/2024-01/collection_listings/remove.json +7 -0
- package/schemas/2024-01/collection_listings/update.json +9 -2
- package/schemas/2024-01/company_locations/create.json +8 -2
- package/schemas/2024-01/company_locations/delete.json +8 -2
- package/schemas/2024-01/company_locations/update.json +8 -2
- package/schemas/2024-01/draft_orders/create.json +733 -124
- package/schemas/2024-01/draft_orders/update.json +733 -124
- package/schemas/2024-01/fulfillment_orders/split.json +237 -2
- package/schemas/2024-01/fulfillments/create.json +149 -30
- package/schemas/2024-01/fulfillments/update.json +149 -30
- package/schemas/2024-01/order_transactions/create.json +28 -9
- package/schemas/2024-01/orders/cancelled.json +970 -50
- package/schemas/2024-01/orders/create.json +970 -50
- package/schemas/2024-01/orders/fulfilled.json +970 -50
- package/schemas/2024-01/orders/paid.json +970 -50
- package/schemas/2024-01/orders/partially_fulfilled.json +970 -50
- package/schemas/2024-01/orders/updated.json +970 -50
- package/schemas/2024-01/products/create.json +191 -17
- package/schemas/2024-01/products/update.json +191 -17
- package/schemas/2024-04/checkouts/create.json +585 -100
- package/schemas/2024-04/checkouts/delete.json +26 -4
- package/schemas/2024-04/checkouts/update.json +585 -100
- package/schemas/2024-04/collection_listings/add.json +9 -2
- package/schemas/2024-04/collection_listings/remove.json +7 -0
- package/schemas/2024-04/collection_listings/update.json +9 -2
- package/schemas/2024-04/company_locations/create.json +8 -2
- package/schemas/2024-04/company_locations/delete.json +8 -2
- package/schemas/2024-04/company_locations/update.json +8 -2
- package/schemas/2024-04/draft_orders/create.json +733 -124
- package/schemas/2024-04/draft_orders/update.json +733 -124
- package/schemas/2024-04/fulfillment_orders/split.json +237 -2
- package/schemas/2024-04/fulfillments/create.json +149 -30
- package/schemas/2024-04/fulfillments/update.json +149 -30
- package/schemas/2024-04/order_transactions/create.json +28 -9
- package/schemas/2024-04/orders/cancelled.json +967 -50
- package/schemas/2024-04/orders/create.json +967 -50
- package/schemas/2024-04/orders/fulfilled.json +967 -50
- package/schemas/2024-04/orders/paid.json +967 -50
- package/schemas/2024-04/orders/partially_fulfilled.json +967 -50
- package/schemas/2024-04/orders/updated.json +967 -50
- package/schemas/2024-04/products/create.json +191 -17
- package/schemas/2024-04/products/update.json +191 -17
- package/schemas/2024-07/checkouts/create.json +585 -100
- package/schemas/2024-07/checkouts/delete.json +26 -4
- package/schemas/2024-07/checkouts/update.json +585 -100
- package/schemas/2024-07/collection_listings/add.json +9 -2
- package/schemas/2024-07/collection_listings/remove.json +7 -0
- package/schemas/2024-07/collection_listings/update.json +9 -2
- package/schemas/2024-07/company_locations/create.json +8 -2
- package/schemas/2024-07/company_locations/delete.json +8 -2
- package/schemas/2024-07/company_locations/update.json +8 -2
- package/schemas/2024-07/draft_orders/create.json +733 -124
- package/schemas/2024-07/draft_orders/update.json +733 -124
- package/schemas/2024-07/fulfillment_orders/split.json +237 -2
- package/schemas/2024-07/fulfillments/create.json +149 -30
- package/schemas/2024-07/fulfillments/update.json +149 -30
- package/schemas/2024-07/order_transactions/create.json +28 -9
- package/schemas/2024-07/orders/cancelled.json +967 -50
- package/schemas/2024-07/orders/create.json +967 -50
- package/schemas/2024-07/orders/edited.json +5 -0
- package/schemas/2024-07/orders/fulfilled.json +967 -50
- package/schemas/2024-07/orders/paid.json +967 -50
- package/schemas/2024-07/orders/partially_fulfilled.json +967 -50
- package/schemas/2024-07/orders/updated.json +967 -50
- package/schemas/2024-07/product_listings/add.json +1 -44
- package/schemas/2024-07/product_listings/update.json +1 -44
- package/schemas/2024-07/products/create.json +191 -17
- package/schemas/2024-07/products/update.json +191 -17
- package/schemas/2024-07/scheduled_product_listings/add.json +1 -44
- 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
|
-
|
|
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
|
-
|
|
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,
|
|
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
|
|
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
|
|
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
|
|
50
|
+
return Object.keys(getVersion(loaded.schemas, apiVersion));
|
|
45
51
|
}
|
|
46
52
|
exports.allTopicsForVersion = allTopicsForVersion;
|