nylas 6.9.0 → 6.10.0

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.
@@ -1,3 +1,4 @@
1
+ /// <reference types="node" />
1
2
  import Model from './model';
2
3
  import { Attribute } from './attributes';
3
4
  export declare type LinkClickProperties = {
@@ -121,4 +122,12 @@ export default class WebhookNotification extends Model implements WebhookNotific
121
122
  deltas: WebhookDelta[];
122
123
  static attributes: Record<string, Attribute>;
123
124
  constructor(props?: WebhookNotificationProperties);
125
+ /**
126
+ * Verify incoming webhook signature came from Nylas
127
+ * @param xNylasSignature The signature to verify
128
+ * @param rawBody The raw body from the payload
129
+ * @param clientSecret Overriding client secret of the app receiving the webhook
130
+ * @return true if the webhook signature was verified from Nylas
131
+ */
132
+ static verifyWebhookSignature(xNylasSignature: string, rawBody: Buffer, clientSecret?: string): boolean;
124
133
  }
@@ -15,9 +15,18 @@ var __extends = (this && this.__extends) || (function () {
15
15
  var __importDefault = (this && this.__importDefault) || function (mod) {
16
16
  return (mod && mod.__esModule) ? mod : { "default": mod };
17
17
  };
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
22
+ result["default"] = mod;
23
+ return result;
24
+ };
18
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
+ var crypto_1 = __importDefault(require("crypto"));
19
27
  var model_1 = __importDefault(require("./model"));
20
28
  var attributes_1 = __importDefault(require("./attributes"));
29
+ var config = __importStar(require("../config"));
21
30
  var LinkClick = /** @class */ (function (_super) {
22
31
  __extends(LinkClick, _super);
23
32
  function LinkClick(props) {
@@ -276,6 +285,24 @@ var WebhookNotification = /** @class */ (function (_super) {
276
285
  _this.initAttributes(props);
277
286
  return _this;
278
287
  }
288
+ /**
289
+ * Verify incoming webhook signature came from Nylas
290
+ * @param xNylasSignature The signature to verify
291
+ * @param rawBody The raw body from the payload
292
+ * @param clientSecret Overriding client secret of the app receiving the webhook
293
+ * @return true if the webhook signature was verified from Nylas
294
+ */
295
+ WebhookNotification.verifyWebhookSignature = function (xNylasSignature, rawBody, clientSecret) {
296
+ var clientSecretToUse = clientSecret || config.clientSecret;
297
+ if (!clientSecretToUse) {
298
+ throw new Error('Client secret is required to verify webhook signature');
299
+ }
300
+ var digest = crypto_1.default
301
+ .createHmac('sha256', clientSecretToUse)
302
+ .update(rawBody)
303
+ .digest('hex');
304
+ return digest === xNylasSignature;
305
+ };
279
306
  WebhookNotification.attributes = {
280
307
  deltas: attributes_1.default.Collection({
281
308
  modelKey: 'deltas',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nylas",
3
- "version": "6.9.0",
3
+ "version": "6.10.0",
4
4
  "description": "A NodeJS wrapper for the Nylas REST API for email, contacts, and calendar.",
5
5
  "main": "lib/nylas.js",
6
6
  "types": "lib/nylas.d.ts",