@shopify/shopify-api
Advanced tools
Comparing version 1.3.0 to 1.4.0
@@ -10,2 +10,7 @@ # Changelog | ||
## [1.4.0] - 2021-05-21 | ||
### Added | ||
- Add support for registering Google Pub/Sub webhooks [#181](https://github.com/Shopify/shopify-node-api/pull/181) | ||
- Added `July21` to `ApiVersion` [#181](https://github.com/Shopify/shopify-node-api/pull/181) | ||
## [1.3.0] - 2021-05-12 | ||
@@ -12,0 +17,0 @@ ### Added |
@@ -26,2 +26,3 @@ import { AuthScopes } from './auth/scopes'; | ||
April21 = "2021-04", | ||
July21 = "2021-07", | ||
Unstable = "unstable", | ||
@@ -28,0 +29,0 @@ Unversioned = "unversioned" |
@@ -15,2 +15,3 @@ "use strict"; | ||
ApiVersion["April21"] = "2021-04"; | ||
ApiVersion["July21"] = "2021-07"; | ||
ApiVersion["Unstable"] = "unstable"; | ||
@@ -17,0 +18,0 @@ ApiVersion["Unversioned"] = "unversioned"; |
@@ -1,2 +0,2 @@ | ||
export declare const SHOPIFY_API_LIBRARY_VERSION = "1.3.0"; | ||
export declare const SHOPIFY_API_LIBRARY_VERSION = "1.4.0"; | ||
//# sourceMappingURL=version.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SHOPIFY_API_LIBRARY_VERSION = void 0; | ||
exports.SHOPIFY_API_LIBRARY_VERSION = '1.3.0'; | ||
exports.SHOPIFY_API_LIBRARY_VERSION = '1.4.0'; |
@@ -14,28 +14,20 @@ "use strict"; | ||
function isSuccess(result, deliveryMethod, webhookId) { | ||
var endpoint; | ||
switch (deliveryMethod) { | ||
case types_1.DeliveryMethod.Http: | ||
if (webhookId) { | ||
return Boolean(result.data && | ||
result.data.webhookSubscriptionUpdate && | ||
result.data.webhookSubscriptionUpdate.webhookSubscription); | ||
} | ||
else { | ||
return Boolean(result.data && | ||
result.data.webhookSubscriptionCreate && | ||
result.data.webhookSubscriptionCreate.webhookSubscription); | ||
} | ||
endpoint = 'webhookSubscription'; | ||
break; | ||
case types_1.DeliveryMethod.EventBridge: | ||
if (webhookId) { | ||
return Boolean(result.data && | ||
result.data.eventBridgeWebhookSubscriptionUpdate && | ||
result.data.eventBridgeWebhookSubscriptionUpdate.webhookSubscription); | ||
} | ||
else { | ||
return Boolean(result.data && | ||
result.data.eventBridgeWebhookSubscriptionCreate && | ||
result.data.eventBridgeWebhookSubscriptionCreate.webhookSubscription); | ||
} | ||
endpoint = 'eventBridgeWebhookSubscription'; | ||
break; | ||
case types_1.DeliveryMethod.PubSub: | ||
endpoint = 'pubSubWebhookSubscription'; | ||
break; | ||
default: | ||
return false; | ||
} | ||
endpoint += webhookId ? 'Update' : 'Create'; | ||
return Boolean(result.data && | ||
result.data[endpoint] && | ||
result.data[endpoint].webhookSubscription); | ||
} | ||
@@ -46,2 +38,5 @@ // 2020-07 onwards | ||
} | ||
function versionSupportsPubSub() { | ||
return utils_1.default.versionCompatible(base_types_1.ApiVersion.July21); | ||
} | ||
function validateDeliveryMethod(deliveryMethod) { | ||
@@ -51,5 +46,13 @@ if (deliveryMethod === types_1.DeliveryMethod.EventBridge && !versionSupportsEndpointField()) { | ||
} | ||
else if (deliveryMethod === types_1.DeliveryMethod.PubSub && !versionSupportsPubSub()) { | ||
throw new ShopifyErrors.UnsupportedClientType("Pub/Sub webhooks are not supported in API version \"" + context_1.Context.API_VERSION + "\"."); | ||
} | ||
} | ||
function buildCheckQuery(topic) { | ||
var query = "{\n webhookSubscriptions(first: 1, topics: " + topic + ") {\n edges {\n node {\n id\n endpoint {\n __typename\n ... on WebhookHttpEndpoint {\n callbackUrl\n }\n ... on WebhookEventBridgeEndpoint {\n arn\n }\n }\n }\n }\n }\n }"; | ||
var query = "{\n webhookSubscriptions(first: 1, topics: " + topic + ") {\n edges {\n node {\n id\n endpoint {\n __typename\n ... on WebhookHttpEndpoint {\n callbackUrl\n }\n ... on WebhookEventBridgeEndpoint {\n arn\n }\n " + (versionSupportsPubSub() | ||
? '... on WebhookPubSubEndpoint { \ | ||
pubSubProject \ | ||
pubSubTopic \ | ||
}' | ||
: '') + "\n }\n }\n }\n }\n }"; | ||
var legacyQuery = "{\n webhookSubscriptions(first: 1, topics: " + topic + ") {\n edges {\n node {\n id\n callbackUrl\n }\n }\n }\n }"; | ||
@@ -60,2 +63,3 @@ return versionSupportsEndpointField() ? query : legacyQuery; | ||
function buildQuery(topic, address, deliveryMethod, webhookId) { | ||
var _a; | ||
if (deliveryMethod === void 0) { deliveryMethod = types_1.DeliveryMethod.Http; } | ||
@@ -72,2 +76,4 @@ validateDeliveryMethod(deliveryMethod); | ||
var webhookSubscriptionArgs; | ||
var pubSubProject; | ||
var pubSubTopic; | ||
switch (deliveryMethod) { | ||
@@ -82,2 +88,7 @@ case types_1.DeliveryMethod.Http: | ||
break; | ||
case types_1.DeliveryMethod.PubSub: | ||
mutationName = webhookId ? 'pubSubWebhookSubscriptionUpdate' : 'pubSubWebhookSubscriptionCreate'; | ||
_a = tslib_1.__read(address.replace(/^pubsub:\/\//, '').split(':'), 2), pubSubProject = _a[0], pubSubTopic = _a[1]; | ||
webhookSubscriptionArgs = "{pubSubProject: \"" + pubSubProject + "\",\n pubSubTopic: \"" + pubSubTopic + "\"}"; | ||
break; | ||
} | ||
@@ -98,5 +109,5 @@ return "\n mutation webhookSubscription {\n " + mutationName + "(" + identifier + ", webhookSubscription: " + webhookSubscriptionArgs + ") {\n userErrors {\n field\n message\n }\n webhookSubscription {\n id\n }\n }\n }\n "; | ||
client = new graphql_client_1.GraphqlClient(shop, accessToken); | ||
address = deliveryMethod === types_1.DeliveryMethod.EventBridge | ||
? path | ||
: "https://" + context_1.Context.HOST_NAME + path; | ||
address = deliveryMethod === types_1.DeliveryMethod.Http | ||
? "https://" + context_1.Context.HOST_NAME + path | ||
: path; | ||
return [4 /*yield*/, client.query({ | ||
@@ -112,5 +123,8 @@ data: buildCheckQuery(topic), | ||
if ('endpoint' in node) { | ||
endpointAddress = node.endpoint.__typename === 'WebhookHttpEndpoint' | ||
? node.endpoint.callbackUrl | ||
: node.endpoint.arn; | ||
if (node.endpoint.__typename === 'WebhookHttpEndpoint') { | ||
endpointAddress = node.endpoint.callbackUrl; | ||
} | ||
else if (node.endpoint.__typename === 'WebhookEventBridgeEndpoint') { | ||
endpointAddress = node.endpoint.arn; | ||
} | ||
} | ||
@@ -117,0 +131,0 @@ else { |
export declare enum DeliveryMethod { | ||
Http = "http", | ||
EventBridge = "eventbridge" | ||
EventBridge = "eventbridge", | ||
PubSub = "pubsub" | ||
} | ||
@@ -30,2 +31,6 @@ declare type WebhookHandlerFunction = (topic: string, shop_domain: string, body: string) => Promise<void>; | ||
arn: string; | ||
} | { | ||
__typename: 'WebhookPubSubEndpoint'; | ||
pubSubProject: string; | ||
pubSubTopic: string; | ||
}; | ||
@@ -32,0 +37,0 @@ }> { |
@@ -8,2 +8,3 @@ "use strict"; | ||
DeliveryMethod["EventBridge"] = "eventbridge"; | ||
DeliveryMethod["PubSub"] = "pubsub"; | ||
})(DeliveryMethod = exports.DeliveryMethod || (exports.DeliveryMethod = {})); |
{ | ||
"name": "@shopify/shopify-api", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "Shopify API Library for Node - accelerate development with support for authentication, graphql proxy, webhooks", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
160488
2730