crisp-api 6.2.0 → 6.3.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 +6 -0
- package/README.md +6 -3
- package/lib/crisp.js +37 -1
- package/package.json +1 -1
- package/types/crisp.d.ts +5 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
Changelog
|
|
2
2
|
=========
|
|
3
3
|
|
|
4
|
+
## v6.3.0
|
|
5
|
+
|
|
6
|
+
### New Features
|
|
7
|
+
|
|
8
|
+
* Added the new `CrispClient.rebind` method, which requests the RTM API to rebind to newly installed/subscribed websites (depending on the authentication tier).
|
|
9
|
+
|
|
4
10
|
## v6.2.0
|
|
5
11
|
|
|
6
12
|
### 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:
|
|
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
|
-
|
|
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
|
package/package.json
CHANGED
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;
|