shopify-webhook-schemas 0.1.2 → 0.1.3
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/dist/src/index.js +9 -3
- package/package.json +1 -1
package/dist/src/index.js
CHANGED
|
@@ -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;
|