crisp-api 7.0.0 → 7.2.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.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,18 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ ## v7.2.0
5
+
6
+ ### New Features
7
+
8
+ * Automated the package release process via GitHub Actions (ie. `npm publish`).
9
+
10
+ ## v7.1.0
11
+
12
+ ### New Features
13
+
14
+ * Added `CrispClient.verifyWidget` to verify Widget Events.
15
+
4
16
  ## v7.0.0
5
17
 
6
18
  ### Breaking Changes
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Crisp API Wrapper
2
2
 
3
- [![Test and Build](https://github.com/crisp-im/node-crisp-api/workflows/Test%20and%20Build/badge.svg?branch=master)](https://github.com/crisp-im/node-crisp-api/actions?query=workflow%3A%22Test+and+Build%22) [![NPM](https://img.shields.io/npm/v/crisp-api.svg)](https://www.npmjs.com/package/crisp-api) [![Downloads](https://img.shields.io/npm/dt/crisp-api.svg)](https://www.npmjs.com/package/crisp-api)
3
+ [![Test and Build](https://github.com/crisp-im/node-crisp-api/workflows/Test%20and%20Build/badge.svg?branch=master)](https://github.com/crisp-im/node-crisp-api/actions?query=workflow%3A%22Test+and+Build%22) [![Build and Release](https://github.com/crisp-im/node-crisp-api/workflows/Build%20and%20Release/badge.svg)](https://github.com/crisp-im/node-crisp-api/actions?query=workflow%3A%22Build+and+Release%22) [![NPM](https://img.shields.io/npm/v/crisp-api.svg)](https://www.npmjs.com/package/crisp-api) [![Downloads](https://img.shields.io/npm/dt/crisp-api.svg)](https://www.npmjs.com/package/crisp-api)
4
4
 
5
5
  The Crisp API Node wrapper. Authenticate, send messages, fetch conversations, access your agent accounts from your JavaScript code.
6
6
 
package/lib/crisp.js CHANGED
@@ -524,33 +524,27 @@ Crisp.prototype = {
524
524
  */
525
525
  verifyHook : function(secret, body, timestamp, signature) {
526
526
  if (this._loopback) {
527
- // Ensure all provided data is valid
528
- if (!secret || !signature || !body || typeof body !== "object" ||
529
- !timestamp || isNaN(timestamp) === true) {
530
- return false;
531
- }
532
-
533
- // Compute local trace
534
- var localTrace = ("[" + timestamp + ";" + JSON.stringify(body) + "]");
535
-
536
- // Create local HMAC
537
- var localMac = Crypto.createHmac("sha256", secret);
538
-
539
- localMac.update(localTrace);
540
-
541
- // Compute local signature, and compare
542
- var localSignature = localMac.digest("hex");
543
-
544
- return (
545
- (signature === localSignature) ? true : false
546
- );
527
+ return this._verifySignature(secret, body, timestamp, signature);
547
528
  }
548
529
 
549
- // Default: not verified (signatures do not match or loopback not /yet?/ \
550
- // bound)
530
+ // Default: not verified (loopback not /yet?/ bound)
551
531
  return false;
552
532
  },
553
533
 
534
+ /**
535
+ * Verifies an event string and checks that signatures match (used for \
536
+ * Widgets)
537
+ * @memberof Crisp
538
+ * @method verifyWidget
539
+ * @param {string} secret
540
+ * @param {object} body
541
+ * @param {string} timestamp
542
+ * @param {string} signature
543
+ */
544
+ verifyWidget : function(secret, body, timestamp, signature) {
545
+ return this._verifySignature(secret, body, timestamp, signature);
546
+ },
547
+
554
548
  /**
555
549
  * Rebinds socket events (used for WebSockets)
556
550
  * @memberof Crisp
@@ -1001,6 +995,39 @@ Crisp.prototype = {
1001
995
  // Other methods must hold a response body, therefore we can fallback on \
1002
996
  // an HTTP error if we fail to acquire any reason at all.
1003
997
  return ((response.body || {}).reason || "http_error");
998
+ },
999
+
1000
+ /**
1001
+ * Verifies an event string and checks that signatures match
1002
+ * @memberof Crisp
1003
+ * @private
1004
+ * @method verifyHook
1005
+ * @param {string} secret
1006
+ * @param {object} body
1007
+ * @param {string} timestamp
1008
+ * @param {string} signature
1009
+ */
1010
+ _verifySignature : function(secret, body, timestamp, signature) {
1011
+ // Ensure all provided data is valid
1012
+ if (!secret || !signature || !body || typeof body !== "object" ||
1013
+ !timestamp || isNaN(timestamp) === true) {
1014
+ return false;
1015
+ }
1016
+
1017
+ // Compute local trace
1018
+ var localTrace = ("[" + timestamp + ";" + JSON.stringify(body) + "]");
1019
+
1020
+ // Create local HMAC
1021
+ var localMac = Crypto.createHmac("sha256", secret);
1022
+
1023
+ localMac.update(localTrace);
1024
+
1025
+ // Compute local signature, and compare
1026
+ var localSignature = localMac.digest("hex");
1027
+
1028
+ return (
1029
+ (signature === localSignature) ? true : false
1030
+ );
1004
1031
  }
1005
1032
  };
1006
1033
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "crisp-api",
3
3
  "description": "Crisp API wrapper for Node - official, maintained by Crisp",
4
- "version": "7.0.0",
4
+ "version": "7.2.0",
5
5
  "homepage": "https://github.com/crisp-im/node-crisp-api",
6
6
  "license": "MIT",
7
7
  "author": {