crisp-api 6.2.0 → 6.3.1

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,22 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ ## v6.3.1
5
+
6
+ ### Breaking Changes
7
+
8
+ * Support for NodeJS 8 has been removed. The minimum version is now NodeJS 10.
9
+
10
+ ### Changes
11
+
12
+ * Upgraded dependencies (closes [#30](https://github.com/crisp-im/node-crisp-api/issues/30).
13
+
14
+ ## v6.3.0
15
+
16
+ ### New Features
17
+
18
+ * Added the new `CrispClient.rebind` method, which requests the RTM API to rebind to newly installed/subscribed websites (depending on the authentication tier).
19
+
4
20
  ## v6.2.0
5
21
 
6
22
  ### New Features
package/README.md CHANGED
@@ -6,7 +6,7 @@ The Crisp API Node wrapper. Authenticate, send messages, fetch conversations, ac
6
6
 
7
7
  Copyright 2022 Crisp IM SAS. See LICENSE for copying information.
8
8
 
9
- * **📝 Implements**: [REST API Reference (V1)](https://docs.crisp.chat/references/rest-api/v1/) at revision: 22/07/2022
9
+ * **📝 Implements**: [REST API Reference (V1)](https://docs.crisp.chat/references/rest-api/v1/) at revision: 29/07/2022
10
10
  * **😘 Maintainers**: [@baptistejamin](https://github.com/baptistejamin), [@eliottvincent](https://github.com/eliottvincent), [@valeriansaliou](https://github.com/valeriansaliou)
11
11
 
12
12
  ## Installation
@@ -2217,7 +2217,7 @@ _👉 Notice: The `peopleID` argument can be an email or the `peopleID`._
2217
2217
  ```
2218
2218
  </details>
2219
2219
 
2220
- * **Get Subscription Details** [`user`]: [Reference](https://docs.crisp.chat/references/rest-api/v1/#get-subscription-details)
2220
+ * **Get Subscription Details** [`user`, `plugin`]: [Reference](https://docs.crisp.chat/references/rest-api/v1/#get-subscription-details)
2221
2221
  * `CrispClient.plugin.getSubscriptionDetails(websiteID, pluginID)`
2222
2222
  * <details>
2223
2223
  <summary>See Example</summary>
@@ -2386,7 +2386,10 @@ _👉 Notice: The `peopleID` argument can be an email or the `peopleID`._
2386
2386
 
2387
2387
  You can bind to realtime events from Crisp, in order to get notified of incoming messages and updates in websites.
2388
2388
 
2389
- You won't receive any event if you don't explicitly subscribe to realtime events using `CrispClient.on()`, as the library doesn't connect to the realtime backend automatically. This method returns a `Promise` object.
2389
+ Before you start with RTM events, please consider the following:
2390
+
2391
+ * You won't receive any event if you don't explicitly subscribe to realtime events using `CrispClient.on()`, as the library doesn't connect to the realtime backend automatically. This method returns a `Promise` object.
2392
+ * Whenever the list of websites that your authentication token is entitled to receive events for changes, you will need to call `CrispClient.rebind()`. This method also returns a `Promise` object.
2390
2393
 
2391
2394
  Available events are listed below:
2392
2395
 
package/lib/crisp.js CHANGED
@@ -24,6 +24,7 @@ Crisp.DEFAULT_SOCKET_RECONNECT_DELAY = 5000;
24
24
  Crisp.DEFAULT_SOCKET_RECONNECT_DELAY_MAX = 10000;
25
25
  Crisp.DEFAULT_SOCKET_RECONNECT_FACTOR = 0.75;
26
26
  Crisp.DEFAULT_SOCKET_SCHEDULE = 500;
27
+ Crisp.DEFAULT_EVENT_REBIND_INTERVAL_MIN = 2500;
27
28
  Crisp.DEFAULT_USERAGENT_PREFIX = "node-crisp-api/";
28
29
 
29
30
 
@@ -176,6 +177,9 @@ function Crisp() {
176
177
  /** @private */
177
178
  this._socketScheduler = null;
178
179
 
180
+ /** @private */
181
+ this._lastEventRebind = null;
182
+
179
183
  /** @private */
180
184
  this._socketBindHooks = [];
181
185
 
@@ -408,7 +412,7 @@ Crisp.prototype = {
408
412
  return this._prepareSocket(
409
413
  function(socket, emitter) {
410
414
  // Listen for event (once socket is bound)
411
- socket.on(event, function(data) {
415
+ socket.on(event, function(data) {
412
416
  emitter.emit(event, data);
413
417
  });
414
418
  }
@@ -418,6 +422,38 @@ Crisp.prototype = {
418
422
  return Promise.resolve();
419
423
  },
420
424
 
425
+ /**
426
+ * Rebind socket events
427
+ * @memberof Crisp
428
+ * @method rebind
429
+ */
430
+ rebind : function() {
431
+ if (!this._socket) {
432
+ throw new Error(
433
+ "[Crisp] rebind: cannot rebind a socket that is not yet bound"
434
+ );
435
+ }
436
+
437
+ // Make sure that the library user is not rebinding too frequently (which \
438
+ // is illegal)
439
+ var nowTime = Date.now();
440
+
441
+ if (this._lastEventRebind !== null &&
442
+ ((nowTime - this._lastEventRebind) <
443
+ Crisp.DEFAULT_EVENT_REBIND_INTERVAL_MIN)) {
444
+ throw new Error(
445
+ "[Crisp] rebind: cannot rebind, last rebind was requested too recently"
446
+ );
447
+ }
448
+
449
+ // Rebind to socket events (eg. newly bound websites)
450
+ this._lastEventRebind = nowTime;
451
+
452
+ this._socket.emit("socket:bind", {});
453
+
454
+ return Promise.resolve();
455
+ },
456
+
421
457
  /**
422
458
  * Prepare a URI based from path segments
423
459
  * @memberof Crisp
@@ -631,10 +667,10 @@ Crisp.prototype = {
631
667
  */
632
668
  _request : function(resource, method, query, body, resolve, reject) {
633
669
  var requestParameters = {
634
- json : true,
635
- timeout : Crisp.DEFAULT_REQUEST_TIMEOUT,
670
+ responseType : "json",
671
+ timeout : Crisp.DEFAULT_REQUEST_TIMEOUT,
636
672
 
637
- headers : {
673
+ headers : {
638
674
  "User-Agent" : this._useragent,
639
675
  "X-Crisp-Tier" : this._tier
640
676
  }
@@ -652,7 +688,7 @@ Crisp.prototype = {
652
688
 
653
689
  // Add query?
654
690
  if (query) {
655
- requestParameters.query = query;
691
+ requestParameters.searchParams = query;
656
692
  }
657
693
 
658
694
  // Proceed request
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": "6.2.0",
4
+ "version": "6.3.1",
5
5
  "homepage": "https://github.com/crisp-im/node-crisp-api",
6
6
  "license": "MIT",
7
7
  "author": {
@@ -25,7 +25,7 @@
25
25
  "main": "./lib/crisp",
26
26
  "types": "./types/crisp.d.ts",
27
27
  "engines": {
28
- "node": ">= 8.0.0"
28
+ "node": ">= 10.19.0"
29
29
  },
30
30
  "scripts": {
31
31
  "test": "check-build",
@@ -37,8 +37,8 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "socket.io-client": "4.4.1",
40
- "fbemitter": "3.0.0",
41
- "got": "9.6.0"
40
+ "fbemitter": "git+https://github.com/crisp-dev/emitter.git#695f60594bdca0c876e5c232de57702ab3151b6f",
41
+ "got": "11.8.5"
42
42
  },
43
43
  "keywords": [
44
44
  "crisp",
package/types/crisp.d.ts CHANGED
@@ -25,6 +25,8 @@ declare class Crisp {
25
25
  /** @private */
26
26
  private _socketScheduler;
27
27
  /** @private */
28
+ private _lastEventRebind;
29
+ /** @private */
28
30
  private _socketBindHooks;
29
31
  /** @private */
30
32
  private _boundEvents;
@@ -40,6 +42,7 @@ declare class Crisp {
40
42
  put: (resource: string, query: object, body: object) => any;
41
43
  delete: (resource: string, query: object, body: object) => any;
42
44
  on: (event: string, callback: Function) => void;
45
+ rebind: () => void;
43
46
  _prepareRestUrl: (paths: any[]) => string;
44
47
  _prepareServices: () => void;
45
48
  _prepareResources: (serviceInstance: object, resources: any[]) => void;
@@ -48,7 +51,7 @@ declare class Crisp {
48
51
  _emitAuthenticate: () => void;
49
52
  }
50
53
  declare namespace Crisp {
51
- export { DEFAULT_REQUEST_TIMEOUT, DEFAULT_SOCKET_TIMEOUT, DEFAULT_SOCKET_RECONNECT_DELAY, DEFAULT_SOCKET_RECONNECT_DELAY_MAX, DEFAULT_SOCKET_RECONNECT_FACTOR, DEFAULT_SOCKET_SCHEDULE, DEFAULT_USERAGENT_PREFIX, DEFAULT_REST_HOST, DEFAULT_REST_BASE_PATH, DEFAULT_RTM_EVENTS, Crisp };
54
+ export { DEFAULT_REQUEST_TIMEOUT, DEFAULT_SOCKET_TIMEOUT, DEFAULT_SOCKET_RECONNECT_DELAY, DEFAULT_SOCKET_RECONNECT_DELAY_MAX, DEFAULT_SOCKET_RECONNECT_FACTOR, DEFAULT_SOCKET_SCHEDULE, DEFAULT_EVENT_REBIND_INTERVAL_MIN, DEFAULT_USERAGENT_PREFIX, DEFAULT_REST_HOST, DEFAULT_REST_BASE_PATH, DEFAULT_RTM_EVENTS, Crisp };
52
55
  }
53
56
  declare var DEFAULT_REQUEST_TIMEOUT: number;
54
57
  declare var DEFAULT_SOCKET_TIMEOUT: number;
@@ -56,6 +59,7 @@ declare var DEFAULT_SOCKET_RECONNECT_DELAY: number;
56
59
  declare var DEFAULT_SOCKET_RECONNECT_DELAY_MAX: number;
57
60
  declare var DEFAULT_SOCKET_RECONNECT_FACTOR: number;
58
61
  declare var DEFAULT_SOCKET_SCHEDULE: number;
62
+ declare var DEFAULT_EVENT_REBIND_INTERVAL_MIN: number;
59
63
  declare var DEFAULT_USERAGENT_PREFIX: string;
60
64
  declare var DEFAULT_REST_HOST: string;
61
65
  declare var DEFAULT_REST_BASE_PATH: string;