Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@shopify/koa-shopify-webhooks

Package Overview
Dependencies
Maintainers
19
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@shopify/koa-shopify-webhooks - npm Package Compare versions

Comparing version 2.6.4 to 3.0.0

LICENSE.md

51

build/cjs/index.js

@@ -1,35 +0,24 @@

"use strict";
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "receiveWebhook", {
enumerable: true,
get: function () {
return _receive.receiveWebhook;
}
});
Object.defineProperty(exports, "registerWebhook", {
enumerable: true,
get: function () {
return _register.registerWebhook;
}
});
Object.defineProperty(exports, "DeliveryMethod", {
enumerable: true,
get: function () {
return _register.DeliveryMethod;
}
});
Object.defineProperty(exports, "WebhookHeader", {
enumerable: true,
get: function () {
return _types.WebhookHeader;
}
});
Object.defineProperty(exports, '__esModule', { value: true });
var _receive = require("./receive.js");
var receive = require('./receive.js');
var register = require('./register.js');
var types = require('./types.js');
var _register = require("./register.js");
var _types = require("./types.js");
exports.receiveWebhook = receive.receiveWebhook;
Object.defineProperty(exports, 'DeliveryMethod', {
enumerable: true,
get: function () {
return register.DeliveryMethod;
}
});
exports.registerWebhook = register.registerWebhook;
Object.defineProperty(exports, 'WebhookHeader', {
enumerable: true,
get: function () {
return types.WebhookHeader;
}
});

@@ -1,24 +0,20 @@

"use strict";
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.receiveWebhook = receiveWebhook;
Object.defineProperty(exports, '__esModule', { value: true });
var _crypto = require("crypto");
var crypto = require('crypto');
var safeCompare = require('safe-compare');
var bodyParser = require('koa-bodyparser');
var mount = require('koa-mount');
var compose = require('koa-compose');
var network = require('@shopify/network');
var types = require('./types.js');
var _safeCompare = _interopRequireDefault(require("safe-compare"));
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var _koaBodyparser = _interopRequireDefault(require("koa-bodyparser"));
var safeCompare__default = /*#__PURE__*/_interopDefaultLegacy(safeCompare);
var bodyParser__default = /*#__PURE__*/_interopDefaultLegacy(bodyParser);
var mount__default = /*#__PURE__*/_interopDefaultLegacy(mount);
var compose__default = /*#__PURE__*/_interopDefaultLegacy(compose);
var _koaMount = _interopRequireDefault(require("koa-mount"));
var _koaCompose = _interopRequireDefault(require("koa-compose"));
var _network = require("@shopify/network");
var _types = require("./types.js");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function receiveWebhook({

@@ -30,13 +26,13 @@ secret,

async function receiveWebhookMiddleware(ctx, next) {
const hmac = ctx.get(_types.WebhookHeader.Hmac);
const topic = ctx.get(_types.WebhookHeader.Topic);
const domain = ctx.get(_types.WebhookHeader.Domain);
const hmac = ctx.get(types.WebhookHeader.Hmac);
const topic = ctx.get(types.WebhookHeader.Topic);
const domain = ctx.get(types.WebhookHeader.Domain);
const {
rawBody
} = ctx.request;
const generatedHash = (0, _crypto.createHmac)('sha256', secret).update(rawBody, 'utf8').digest('base64');
const generatedHash = crypto.createHmac('sha256', secret).update(rawBody, 'utf8').digest('base64');
const graphqlTopic = topic.toUpperCase().replace(/\//g, '_');
if ((0, _safeCompare.default)(generatedHash, hmac)) {
ctx.res.statusCode = _network.StatusCode.Accepted;
if (safeCompare__default['default'](generatedHash, hmac)) {
ctx.res.statusCode = network.StatusCode.Accepted;
ctx.state.webhook = {

@@ -50,10 +46,12 @@ topic: graphqlTopic,

} else {
ctx.res.statusCode = _network.StatusCode.Forbidden;
ctx.res.statusCode = network.StatusCode.Forbidden;
}
}
const middleware = (0, _koaCompose.default)([(0, _koaBodyparser.default)(), receiveWebhookMiddleware]);
return path ? (0, _koaMount.default)(path, middleware) : middleware;
const middleware = compose__default['default']([bodyParser__default['default'](), receiveWebhookMiddleware]);
return path ? mount__default['default'](path, middleware) : middleware;
}
function noop() {}
function noop() {}
exports.receiveWebhook = receiveWebhook;

@@ -1,16 +0,10 @@

"use strict";
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.registerWebhook = registerWebhook;
exports.DeliveryMethod = exports.ApiVersion = void 0;
Object.defineProperty(exports, '__esModule', { value: true });
var _network = require("@shopify/network");
var network = require('@shopify/network');
var types = require('./types.js');
var _types = require("./types.js");
exports.ApiVersion = void 0;
let ApiVersion;
exports.ApiVersion = ApiVersion;
(function (ApiVersion) {

@@ -26,6 +20,5 @@ ApiVersion["April19"] = "2019-04";

ApiVersion["Unversioned"] = "unversioned";
})(ApiVersion || (exports.ApiVersion = ApiVersion = {}));
})(exports.ApiVersion || (exports.ApiVersion = {}));
let DeliveryMethod;
exports.DeliveryMethod = DeliveryMethod;
exports.DeliveryMethod = void 0;

@@ -35,3 +28,3 @@ (function (DeliveryMethod) {

DeliveryMethod["EventBridge"] = "eventbridge";
})(DeliveryMethod || (exports.DeliveryMethod = DeliveryMethod = {}));
})(exports.DeliveryMethod || (exports.DeliveryMethod = {}));

@@ -44,10 +37,10 @@ async function registerWebhook({

apiVersion,
deliveryMethod = DeliveryMethod.Http
deliveryMethod = exports.DeliveryMethod.Http
}) {
const response = await fetch(`https://${shop}/admin/api/${apiVersion}/graphql.json`, {
method: _network.Method.Post,
method: network.Method.Post,
body: buildQuery(topic, address, deliveryMethod),
headers: {
[_types.WebhookHeader.AccessToken]: accessToken,
[_network.Header.ContentType]: 'application/graphql'
[types.WebhookHeader.AccessToken]: accessToken,
[network.Header.ContentType]: 'application/graphql'
}

@@ -64,6 +57,6 @@ });

switch (deliveryMethod) {
case DeliveryMethod.Http:
case exports.DeliveryMethod.Http:
return Boolean(result.data && result.data.webhookSubscriptionCreate && result.data.webhookSubscriptionCreate.webhookSubscription);
case DeliveryMethod.EventBridge:
case exports.DeliveryMethod.EventBridge:
return Boolean(result.data && result.data.eventBridgeWebhookSubscriptionCreate && result.data.eventBridgeWebhookSubscriptionCreate.webhookSubscription);

@@ -78,3 +71,3 @@ }

switch (deliveryMethod) {
case DeliveryMethod.Http:
case exports.DeliveryMethod.Http:
mutationName = 'webhookSubscriptionCreate';

@@ -84,3 +77,3 @@ webhookSubscriptionArgs = `{callbackUrl: "${address}"}`;

case DeliveryMethod.EventBridge:
case exports.DeliveryMethod.EventBridge:
mutationName = 'eventBridgeWebhookSubscriptionCreate';

@@ -104,2 +97,4 @@ webhookSubscriptionArgs = `{arn: "${address}"}`;

`;
}
}
exports.registerWebhook = registerWebhook;

@@ -1,9 +0,6 @@

"use strict";
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, '__esModule', { value: true });
exports.WebhookHeader = void 0;
let WebhookHeader;
exports.WebhookHeader = WebhookHeader;

@@ -15,2 +12,2 @@ (function (WebhookHeader) {

WebhookHeader["Domain"] = "X-Shopify-Shop-Domain";
})(WebhookHeader || (exports.WebhookHeader = WebhookHeader = {}));
})(exports.WebhookHeader || (exports.WebhookHeader = {}));

@@ -10,2 +10,8 @@ # Changelog

## 3.0.0 - 2021-05-21
### Breaking Change
- Update minimum supported node version to 12.14.0. Add engines field to help enforce usage of this version. [#1906](https://github.com/Shopify/quilt/pull/1906)
## 2.6.4 - 2021-04-13

@@ -12,0 +18,0 @@

{
"name": "@shopify/koa-shopify-webhooks",
"version": "2.6.4",
"version": "3.0.0",
"license": "MIT",

@@ -23,4 +23,7 @@ "description": "Receive webhooks from Shopify with ease",

"homepage": "https://github.com/Shopify/quilt/blob/main/packages/koa-shopify-webhooks/README.md",
"engines": {
"node": ">=12.14.0"
},
"dependencies": {
"@shopify/network": "^1.6.4",
"@shopify/network": "^2.0.0",
"@types/koa": "^2.0.0",

@@ -56,3 +59,4 @@ "koa-bodyparser": "^4.2.1",

}
}
},
"gitHead": "40de4af181104f298cbab42d2d3d68e228a9a31a"
}

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

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc