crisp-api 7.2.0 → 7.4.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 +16 -0
- package/EXAMPLES.md +10 -0
- package/LICENSE +1 -1
- package/README.md +17 -3
- package/lib/crisp.js +153 -36
- package/lib/resources/BucketURL.js +3 -1
- package/lib/resources/MediaAnimation.js +5 -1
- package/lib/resources/PluginConnect.js +11 -4
- package/lib/resources/PluginSubscription.js +41 -10
- package/lib/resources/WebsiteAnalytics.js +28 -4
- package/lib/resources/WebsiteAvailability.js +6 -2
- package/lib/resources/WebsiteBase.js +13 -4
- package/lib/resources/WebsiteBatch.js +16 -4
- package/lib/resources/WebsiteCampaign.js +92 -21
- package/lib/resources/WebsiteConversation.js +257 -49
- package/lib/resources/WebsiteOperator.js +33 -8
- package/lib/resources/WebsitePeople.js +112 -25
- package/lib/resources/WebsiteSettings.js +7 -2
- package/lib/resources/WebsiteVerify.js +13 -4
- package/lib/resources/WebsiteVisitors.js +28 -7
- package/package.json +5 -5
- package/tsconfig.json +1 -1
- package/types/crisp.d.ts +98 -40
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
Changelog
|
|
2
2
|
=========
|
|
3
3
|
|
|
4
|
+
## v7.4.0
|
|
5
|
+
|
|
6
|
+
### New Features
|
|
7
|
+
|
|
8
|
+
* Generated up-to-date TypeScript definitions.
|
|
9
|
+
|
|
10
|
+
### Bug Fixes
|
|
11
|
+
|
|
12
|
+
* Fixed the automatic generation of TypeScript definitions.
|
|
13
|
+
|
|
14
|
+
## v7.3.0
|
|
15
|
+
|
|
16
|
+
### New Features
|
|
17
|
+
|
|
18
|
+
* Added the new `CrispClient.website.listConversationFiles` method.
|
|
19
|
+
|
|
4
20
|
## v7.2.0
|
|
5
21
|
|
|
6
22
|
### New Features
|
package/EXAMPLES.md
CHANGED
|
@@ -292,6 +292,16 @@ CrispClient.website.listConversationEvents(websiteID, sessionID, pageNumber);
|
|
|
292
292
|
|
|
293
293
|
=========================
|
|
294
294
|
|
|
295
|
+
https://docs.crisp.chat/references/rest-api/v1/#list-conversation-files
|
|
296
|
+
|
|
297
|
+
var websiteID = "8c842203-7ed8-4e29-a608-7cf78a7d2fcc";
|
|
298
|
+
var sessionID = "session_700c65e1-85e2-465a-b9ac-ecb5ec2c9881";
|
|
299
|
+
var pageNumber = 1;
|
|
300
|
+
|
|
301
|
+
CrispClient.website.listConversationFiles(websiteID, sessionID, pageNumber);
|
|
302
|
+
|
|
303
|
+
=========================
|
|
304
|
+
|
|
295
305
|
https://docs.crisp.chat/references/rest-api/v1/#get-conversation-state
|
|
296
306
|
|
|
297
307
|
var websiteID = "8c842203-7ed8-4e29-a608-7cf78a7d2fcc";
|
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# Crisp API Wrapper
|
|
2
2
|
|
|
3
|
-
[](https://github.com/crisp-im/node-crisp-api/actions?query=workflow%3A%22Test+and+Build%22) [](https://github.com/crisp-im/node-crisp-api/actions?query=workflow%3A%22Build+and+Release%22) [](https://github.com/crisp-im/node-crisp-api/actions?query=workflow%3A%22Test+and+Build%22) [](https://github.com/crisp-im/node-crisp-api/actions?query=workflow%3A%22Build+and+Release%22) [](https://www.npmjs.com/package/crisp-api) [](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
|
|
|
7
|
-
Copyright
|
|
7
|
+
Copyright 2023 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: 16/01/2023
|
|
10
10
|
* **😘 Maintainers**: [@baptistejamin](https://github.com/baptistejamin), [@eliottvincent](https://github.com/eliottvincent), [@valeriansaliou](https://github.com/valeriansaliou)
|
|
11
11
|
|
|
12
12
|
## Installation
|
|
@@ -566,6 +566,20 @@ All methods that you will most likely need when building a Crisp integration are
|
|
|
566
566
|
```
|
|
567
567
|
</details>
|
|
568
568
|
|
|
569
|
+
* **List Conversation Files** [`user`, `plugin`]: [Reference](https://docs.crisp.chat/references/rest-api/v1/#list-conversation-files)
|
|
570
|
+
* `CrispClient.website.listConversationFiles(websiteID, sessionID, pageNumber)`
|
|
571
|
+
* <details>
|
|
572
|
+
<summary>See Example</summary>
|
|
573
|
+
|
|
574
|
+
```javascript
|
|
575
|
+
var websiteID = "8c842203-7ed8-4e29-a608-7cf78a7d2fcc";
|
|
576
|
+
var sessionID = "session_700c65e1-85e2-465a-b9ac-ecb5ec2c9881";
|
|
577
|
+
var pageNumber = 1;
|
|
578
|
+
|
|
579
|
+
CrispClient.website.listConversationFiles(websiteID, sessionID, pageNumber);
|
|
580
|
+
```
|
|
581
|
+
</details>
|
|
582
|
+
|
|
569
583
|
* **Get Conversation State** [`user`, `plugin`]: [Reference](https://docs.crisp.chat/references/rest-api/v1/#get-conversation-state)
|
|
570
584
|
* `CrispClient.website.getConversationState(websiteID, sessionID)`
|
|
571
585
|
* <details>
|
package/lib/crisp.js
CHANGED
|
@@ -161,48 +161,105 @@ var services = {
|
|
|
161
161
|
* @classdesc This is the Crisp Library. Handles REST and RTM operations
|
|
162
162
|
*/
|
|
163
163
|
function Crisp() {
|
|
164
|
-
|
|
164
|
+
/**
|
|
165
|
+
* @public
|
|
166
|
+
* @type {object}
|
|
167
|
+
*/
|
|
168
|
+
this.bucket = {};
|
|
165
169
|
|
|
166
170
|
/**
|
|
167
|
-
* @
|
|
168
|
-
* @type {
|
|
171
|
+
* @public
|
|
172
|
+
* @type {object}
|
|
173
|
+
*/
|
|
174
|
+
this.media = {};
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* @public
|
|
178
|
+
* @type {object}
|
|
179
|
+
*/
|
|
180
|
+
this.plugin = {};
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* @public
|
|
184
|
+
* @type {object}
|
|
185
|
+
*/
|
|
186
|
+
this.website = {};
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* @public
|
|
190
|
+
* @type {object}
|
|
169
191
|
*/
|
|
170
|
-
this.
|
|
192
|
+
this.auth = {
|
|
193
|
+
tier : "user",
|
|
194
|
+
identifier : null,
|
|
195
|
+
key : null,
|
|
196
|
+
token : null
|
|
197
|
+
};
|
|
171
198
|
|
|
172
|
-
/**
|
|
199
|
+
/**
|
|
200
|
+
* @private
|
|
201
|
+
* @type {object}
|
|
202
|
+
*/
|
|
173
203
|
this._rest = {
|
|
174
204
|
host : Crisp.DEFAULT_REST_HOST,
|
|
175
205
|
basePath : Crisp.DEFAULT_REST_BASE_PATH
|
|
176
206
|
};
|
|
177
207
|
|
|
178
|
-
/**
|
|
208
|
+
/**
|
|
209
|
+
* @private
|
|
210
|
+
* @type {object}
|
|
211
|
+
*/
|
|
179
212
|
this._rtm = {
|
|
180
213
|
host : null,
|
|
181
214
|
mode : Crisp.DEFAULT_RTM_MODE
|
|
182
215
|
};
|
|
183
216
|
|
|
184
|
-
/**
|
|
217
|
+
/**
|
|
218
|
+
* @private
|
|
219
|
+
* @type {string}
|
|
220
|
+
*/
|
|
185
221
|
this._useragent = (Crisp.DEFAULT_USERAGENT_PREFIX + pkg.version);
|
|
186
222
|
|
|
187
|
-
/**
|
|
223
|
+
/**
|
|
224
|
+
* @private
|
|
225
|
+
* @type {object}
|
|
226
|
+
*/
|
|
188
227
|
this._emitter = new EventEmitter();
|
|
189
228
|
|
|
190
|
-
/**
|
|
229
|
+
/**
|
|
230
|
+
* @private
|
|
231
|
+
* @type {object|null}
|
|
232
|
+
*/
|
|
191
233
|
this._socket = null;
|
|
192
234
|
|
|
193
|
-
/**
|
|
235
|
+
/**
|
|
236
|
+
* @private
|
|
237
|
+
* @type {object|null}
|
|
238
|
+
*/
|
|
194
239
|
this._loopback = null;
|
|
195
240
|
|
|
196
|
-
/**
|
|
241
|
+
/**
|
|
242
|
+
* @private
|
|
243
|
+
* @type {number|null}
|
|
244
|
+
*/
|
|
197
245
|
this._lastEventRebind = null;
|
|
198
246
|
|
|
199
|
-
/**
|
|
247
|
+
/**
|
|
248
|
+
* @private
|
|
249
|
+
* @type {object|null}
|
|
250
|
+
*/
|
|
200
251
|
this._brokerScheduler = null;
|
|
201
252
|
|
|
202
|
-
/**
|
|
253
|
+
/**
|
|
254
|
+
* @private
|
|
255
|
+
* @type {Array}
|
|
256
|
+
*/
|
|
203
257
|
this._brokerBindHooks = [];
|
|
204
258
|
|
|
205
|
-
/**
|
|
259
|
+
/**
|
|
260
|
+
* @private
|
|
261
|
+
* @type {object}
|
|
262
|
+
*/
|
|
206
263
|
this._boundEvents = {};
|
|
207
264
|
|
|
208
265
|
// Prepare
|
|
@@ -214,8 +271,10 @@ Crisp.prototype = {
|
|
|
214
271
|
/**
|
|
215
272
|
* Sets the REST API host
|
|
216
273
|
* @memberof Crisp
|
|
274
|
+
* @public
|
|
217
275
|
* @method setRestHost
|
|
218
276
|
* @param {string} host - Hostname
|
|
277
|
+
* @return {undefined}
|
|
219
278
|
*/
|
|
220
279
|
setRestHost : function(host) {
|
|
221
280
|
if (typeof host === "string") {
|
|
@@ -228,8 +287,10 @@ Crisp.prototype = {
|
|
|
228
287
|
/**
|
|
229
288
|
* Sets the RTM API host
|
|
230
289
|
* @memberof Crisp
|
|
290
|
+
* @public
|
|
231
291
|
* @method setRtmHost
|
|
232
292
|
* @param {string} host - Hostname
|
|
293
|
+
* @return {undefined}
|
|
233
294
|
*/
|
|
234
295
|
setRtmHost : function(host) {
|
|
235
296
|
if (typeof host === "string") {
|
|
@@ -242,8 +303,10 @@ Crisp.prototype = {
|
|
|
242
303
|
/**
|
|
243
304
|
* Sets the RTM channel mode (ie. WebSockets or Web Hooks)
|
|
244
305
|
* @memberof Crisp
|
|
306
|
+
* @public
|
|
245
307
|
* @method setRtmMode
|
|
246
308
|
* @param {string} mode - RTM mode ('websockets' or 'webhooks')
|
|
309
|
+
* @return {undefined}
|
|
247
310
|
*/
|
|
248
311
|
setRtmMode : function(mode) {
|
|
249
312
|
if (Crisp.AVAILABLE_RTM_MODES.indexOf(mode) !== -1) {
|
|
@@ -257,38 +320,46 @@ Crisp.prototype = {
|
|
|
257
320
|
},
|
|
258
321
|
|
|
259
322
|
/**
|
|
260
|
-
* Sets the tier
|
|
323
|
+
* Sets the authentication tier
|
|
261
324
|
* @memberof Crisp
|
|
325
|
+
* @public
|
|
262
326
|
* @method setTier
|
|
263
327
|
* @param {string} tier
|
|
328
|
+
* @return {undefined}
|
|
264
329
|
*/
|
|
265
330
|
setTier : function(tier) {
|
|
266
|
-
this.
|
|
331
|
+
this.auth.tier = (tier || "user");
|
|
267
332
|
},
|
|
268
333
|
|
|
269
334
|
/**
|
|
270
335
|
* Authenticates
|
|
271
336
|
* @memberof Crisp
|
|
337
|
+
* @public
|
|
272
338
|
* @method authenticate
|
|
273
339
|
* @param {string} identifier
|
|
274
340
|
* @param {string} key
|
|
341
|
+
* @return {undefined}
|
|
275
342
|
*/
|
|
276
343
|
authenticate : function(identifier, key) {
|
|
277
344
|
var auth = this.auth;
|
|
278
345
|
|
|
346
|
+
// Store credentials
|
|
279
347
|
auth.identifier = identifier;
|
|
280
348
|
auth.key = key;
|
|
281
349
|
|
|
282
|
-
|
|
350
|
+
// Assign pre-computed authentication token
|
|
351
|
+
auth.token = Buffer.from(identifier + ":" + key).toString("base64");
|
|
283
352
|
},
|
|
284
353
|
|
|
285
354
|
/**
|
|
286
355
|
* Authenticates (with tier)
|
|
287
356
|
* @memberof Crisp
|
|
357
|
+
* @public
|
|
288
358
|
* @method authenticateTier
|
|
289
359
|
* @param {string} tier
|
|
290
360
|
* @param {string} identifier
|
|
291
361
|
* @param {string} key
|
|
362
|
+
* @return {undefined}
|
|
292
363
|
*/
|
|
293
364
|
authenticateTier : function(tier, identifier, key) {
|
|
294
365
|
this.setTier(tier);
|
|
@@ -298,10 +369,12 @@ Crisp.prototype = {
|
|
|
298
369
|
/**
|
|
299
370
|
* Method wrapper to HEAD a resource
|
|
300
371
|
* @memberof Crisp
|
|
372
|
+
* @public
|
|
301
373
|
* @method head
|
|
302
374
|
* @param {string} resource
|
|
303
375
|
* @param {object} query
|
|
304
376
|
* @param {object} body
|
|
377
|
+
* @return {Promise}
|
|
305
378
|
*/
|
|
306
379
|
head : function(resource, query, body) {
|
|
307
380
|
var self = this;
|
|
@@ -316,10 +389,12 @@ Crisp.prototype = {
|
|
|
316
389
|
/**
|
|
317
390
|
* Method wrapper to GET a resource
|
|
318
391
|
* @memberof Crisp
|
|
392
|
+
* @public
|
|
319
393
|
* @method get
|
|
320
394
|
* @param {string} resource
|
|
321
395
|
* @param {object} query
|
|
322
396
|
* @param {object} body
|
|
397
|
+
* @return {Promise}
|
|
323
398
|
*/
|
|
324
399
|
get : function(resource, query) {
|
|
325
400
|
var self = this;
|
|
@@ -334,10 +409,12 @@ Crisp.prototype = {
|
|
|
334
409
|
/**
|
|
335
410
|
* Method wrapper to POST a resource
|
|
336
411
|
* @memberof Crisp
|
|
412
|
+
* @public
|
|
337
413
|
* @method post
|
|
338
414
|
* @param {string} resource
|
|
339
415
|
* @param {object} query
|
|
340
416
|
* @param {object} body
|
|
417
|
+
* @return {Promise}
|
|
341
418
|
*/
|
|
342
419
|
post : function(resource, query, body) {
|
|
343
420
|
var self = this;
|
|
@@ -352,10 +429,12 @@ Crisp.prototype = {
|
|
|
352
429
|
/**
|
|
353
430
|
* Method wrapper to PATCH a resource
|
|
354
431
|
* @memberof Crisp
|
|
432
|
+
* @public
|
|
355
433
|
* @method patch
|
|
356
434
|
* @param {string} resource
|
|
357
435
|
* @param {object} query
|
|
358
436
|
* @param {object} body
|
|
437
|
+
* @return {Promise}
|
|
359
438
|
*/
|
|
360
439
|
patch : function(resource, query, body) {
|
|
361
440
|
var self = this;
|
|
@@ -370,10 +449,12 @@ Crisp.prototype = {
|
|
|
370
449
|
/**
|
|
371
450
|
* Method wrapper to PUT a resource
|
|
372
451
|
* @memberof Crisp
|
|
452
|
+
* @public
|
|
373
453
|
* @method put
|
|
374
454
|
* @param {string} resource
|
|
375
455
|
* @param {object} query
|
|
376
456
|
* @param {object} body
|
|
457
|
+
* @return {Promise}
|
|
377
458
|
*/
|
|
378
459
|
put : function(resource, query, body) {
|
|
379
460
|
var self = this;
|
|
@@ -388,10 +469,12 @@ Crisp.prototype = {
|
|
|
388
469
|
/**
|
|
389
470
|
* Method wrapper to DELETE a resource
|
|
390
471
|
* @memberof Crisp
|
|
472
|
+
* @public
|
|
391
473
|
* @method delete
|
|
392
474
|
* @param {string} resource
|
|
393
475
|
* @param {object} query
|
|
394
476
|
* @param {object} body
|
|
477
|
+
* @return {Promise}
|
|
395
478
|
*/
|
|
396
479
|
delete : function(resource, query, body) {
|
|
397
480
|
var self = this;
|
|
@@ -406,9 +489,11 @@ Crisp.prototype = {
|
|
|
406
489
|
/**
|
|
407
490
|
* Binds RTM event
|
|
408
491
|
* @memberof Crisp
|
|
492
|
+
* @public
|
|
409
493
|
* @method on
|
|
410
494
|
* @param {string} event
|
|
411
495
|
* @param {function} callback
|
|
496
|
+
* @return {Promise}
|
|
412
497
|
*/
|
|
413
498
|
on : function(event, callback) {
|
|
414
499
|
// Ensure all input arguments are set
|
|
@@ -472,8 +557,10 @@ Crisp.prototype = {
|
|
|
472
557
|
/**
|
|
473
558
|
* Receives a raw event and dispatches it to the listener (used for Web Hooks)
|
|
474
559
|
* @memberof Crisp
|
|
560
|
+
* @public
|
|
475
561
|
* @method receiveHook
|
|
476
562
|
* @param {object} body
|
|
563
|
+
* @return {undefined}
|
|
477
564
|
*/
|
|
478
565
|
receiveHook : function(body) {
|
|
479
566
|
var self = this;
|
|
@@ -516,11 +603,13 @@ Crisp.prototype = {
|
|
|
516
603
|
* Verifies an event string and checks that signatures match (used for Web \
|
|
517
604
|
* Hooks)
|
|
518
605
|
* @memberof Crisp
|
|
606
|
+
* @public
|
|
519
607
|
* @method verifyHook
|
|
520
608
|
* @param {string} secret
|
|
521
609
|
* @param {object} body
|
|
522
610
|
* @param {string} timestamp
|
|
523
611
|
* @param {string} signature
|
|
612
|
+
* @return {boolean}
|
|
524
613
|
*/
|
|
525
614
|
verifyHook : function(secret, body, timestamp, signature) {
|
|
526
615
|
if (this._loopback) {
|
|
@@ -535,11 +624,13 @@ Crisp.prototype = {
|
|
|
535
624
|
* Verifies an event string and checks that signatures match (used for \
|
|
536
625
|
* Widgets)
|
|
537
626
|
* @memberof Crisp
|
|
627
|
+
* @public
|
|
538
628
|
* @method verifyWidget
|
|
539
629
|
* @param {string} secret
|
|
540
630
|
* @param {object} body
|
|
541
631
|
* @param {string} timestamp
|
|
542
632
|
* @param {string} signature
|
|
633
|
+
* @return {boolean}
|
|
543
634
|
*/
|
|
544
635
|
verifyWidget : function(secret, body, timestamp, signature) {
|
|
545
636
|
return this._verifySignature(secret, body, timestamp, signature);
|
|
@@ -548,7 +639,9 @@ Crisp.prototype = {
|
|
|
548
639
|
/**
|
|
549
640
|
* Rebinds socket events (used for WebSockets)
|
|
550
641
|
* @memberof Crisp
|
|
642
|
+
* @public
|
|
551
643
|
* @method rebind
|
|
644
|
+
* @return {Promise}
|
|
552
645
|
*/
|
|
553
646
|
rebindSocket : function() {
|
|
554
647
|
if (!this._socket) {
|
|
@@ -570,12 +663,15 @@ Crisp.prototype = {
|
|
|
570
663
|
);
|
|
571
664
|
}
|
|
572
665
|
|
|
573
|
-
|
|
574
|
-
|
|
666
|
+
return Promise.resolve()
|
|
667
|
+
.then(function() {
|
|
668
|
+
// Rebind to socket events (eg. newly bound websites)
|
|
669
|
+
this._lastEventRebind = nowTime;
|
|
575
670
|
|
|
576
|
-
|
|
671
|
+
this._socket.emit("socket:bind", {});
|
|
577
672
|
|
|
578
|
-
|
|
673
|
+
return Promise.resolve();
|
|
674
|
+
});
|
|
579
675
|
},
|
|
580
676
|
|
|
581
677
|
/**
|
|
@@ -584,6 +680,7 @@ Crisp.prototype = {
|
|
|
584
680
|
* @private
|
|
585
681
|
* @method _prepareRestUrl
|
|
586
682
|
* @param {Array} paths - List of paths ['session', 'login']
|
|
683
|
+
* @return {string}
|
|
587
684
|
*/
|
|
588
685
|
_prepareRestUrl : function(paths) {
|
|
589
686
|
if (Array.isArray(paths) === true) {
|
|
@@ -604,12 +701,23 @@ Crisp.prototype = {
|
|
|
604
701
|
* @memberof Crisp
|
|
605
702
|
* @private
|
|
606
703
|
* @method _prepareServices
|
|
704
|
+
* @return {undefined}
|
|
607
705
|
*/
|
|
608
706
|
_prepareServices : function() {
|
|
609
707
|
// Bind services
|
|
610
708
|
for (var name in services) {
|
|
611
709
|
var serviceInstance = new services[name]();
|
|
612
710
|
|
|
711
|
+
// Acquire service map
|
|
712
|
+
var serviceMap = this[(name[0].toLowerCase() + name.substring(1))];
|
|
713
|
+
|
|
714
|
+
// No service map available?
|
|
715
|
+
if (!serviceMap) {
|
|
716
|
+
throw new Error(
|
|
717
|
+
"[Crisp] prepareServices: service '" + name + "' has no map available"
|
|
718
|
+
);
|
|
719
|
+
}
|
|
720
|
+
|
|
613
721
|
// No resources defined in service?
|
|
614
722
|
if (!serviceInstance._resources ||
|
|
615
723
|
serviceInstance._resources.length === 0) {
|
|
@@ -621,10 +729,8 @@ Crisp.prototype = {
|
|
|
621
729
|
|
|
622
730
|
// Prepare all resources (for service)
|
|
623
731
|
this._prepareResources(
|
|
624
|
-
|
|
732
|
+
serviceMap, serviceInstance._resources
|
|
625
733
|
);
|
|
626
|
-
|
|
627
|
-
this[(name[0].toLowerCase() + name.substring(1))] = serviceInstance;
|
|
628
734
|
}
|
|
629
735
|
},
|
|
630
736
|
|
|
@@ -633,15 +739,16 @@ Crisp.prototype = {
|
|
|
633
739
|
* @memberof Crisp
|
|
634
740
|
* @private
|
|
635
741
|
* @method _prepareResources
|
|
636
|
-
* @param {object}
|
|
742
|
+
* @param {object} serviceMap
|
|
637
743
|
* @param {Array} resources
|
|
744
|
+
* @return {undefined}
|
|
638
745
|
*/
|
|
639
|
-
_prepareResources : function(
|
|
746
|
+
_prepareResources : function(serviceMap, resources) {
|
|
640
747
|
for (var i = 0; i < resources.length; i++) {
|
|
641
748
|
var resourceConstructor = require("./resources/" + resources[i]);
|
|
642
749
|
|
|
643
750
|
// Instanciate resource, which will auto-bind itself to service prototype
|
|
644
|
-
new resourceConstructor(
|
|
751
|
+
new resourceConstructor(serviceMap, this);
|
|
645
752
|
}
|
|
646
753
|
},
|
|
647
754
|
|
|
@@ -651,6 +758,7 @@ Crisp.prototype = {
|
|
|
651
758
|
* @private
|
|
652
759
|
* @method _prepareBroker
|
|
653
760
|
* @param {function} fnBindHook
|
|
761
|
+
* @return {Promise}
|
|
654
762
|
*/
|
|
655
763
|
_prepareBroker : function(fnBindHook) {
|
|
656
764
|
var self = this;
|
|
@@ -717,15 +825,19 @@ Crisp.prototype = {
|
|
|
717
825
|
* @memberof Crisp
|
|
718
826
|
* @private
|
|
719
827
|
* @method _connectLoopback
|
|
828
|
+
* @return {Promise}
|
|
720
829
|
*/
|
|
721
830
|
_connectLoopback : function() {
|
|
722
|
-
|
|
723
|
-
|
|
831
|
+
return Promise.resolve()
|
|
832
|
+
.then(function() {
|
|
833
|
+
// Assign emitter to loopback
|
|
834
|
+
this._loopback = this._emitter;
|
|
724
835
|
|
|
725
|
-
|
|
726
|
-
|
|
836
|
+
// Unstack broker bind hooks immediately
|
|
837
|
+
this._unstackBrokerBindHooks(this._loopback);
|
|
727
838
|
|
|
728
|
-
|
|
839
|
+
return Promise.resolve();
|
|
840
|
+
});
|
|
729
841
|
},
|
|
730
842
|
|
|
731
843
|
/**
|
|
@@ -734,6 +846,7 @@ Crisp.prototype = {
|
|
|
734
846
|
* @private
|
|
735
847
|
* @method _connectSocket
|
|
736
848
|
* @param {string} rtmHostOverride
|
|
849
|
+
* @return {Promise}
|
|
737
850
|
*/
|
|
738
851
|
_connectSocket : function(rtmHostOverride) {
|
|
739
852
|
var self = this;
|
|
@@ -752,7 +865,7 @@ Crisp.prototype = {
|
|
|
752
865
|
// Acquire RTM API URL from remote
|
|
753
866
|
var restUrlSegments;
|
|
754
867
|
|
|
755
|
-
switch (self.
|
|
868
|
+
switch (self.auth.tier) {
|
|
756
869
|
case "plugin": {
|
|
757
870
|
restUrlSegments = ["plugin", "connect", "endpoints"];
|
|
758
871
|
|
|
@@ -823,10 +936,10 @@ Crisp.prototype = {
|
|
|
823
936
|
* @memberof Crisp
|
|
824
937
|
* @private
|
|
825
938
|
* @method _emitAuthenticateSocket
|
|
939
|
+
* @return {undefined}
|
|
826
940
|
*/
|
|
827
941
|
_emitAuthenticateSocket : function() {
|
|
828
942
|
var auth = this.auth,
|
|
829
|
-
tier = this._tier,
|
|
830
943
|
boundEvents = Object.keys(this._boundEvents);
|
|
831
944
|
|
|
832
945
|
if (!this._socket) {
|
|
@@ -851,7 +964,7 @@ Crisp.prototype = {
|
|
|
851
964
|
this._socket.emit("authentication", {
|
|
852
965
|
username : auth.identifier,
|
|
853
966
|
password : auth.key,
|
|
854
|
-
tier : tier,
|
|
967
|
+
tier : auth.tier,
|
|
855
968
|
events : boundEvents
|
|
856
969
|
});
|
|
857
970
|
},
|
|
@@ -862,6 +975,7 @@ Crisp.prototype = {
|
|
|
862
975
|
* @private
|
|
863
976
|
* @method _unstackBrokerBindHooks
|
|
864
977
|
* @param {object} modeInstance
|
|
978
|
+
* @return {undefined}
|
|
865
979
|
*/
|
|
866
980
|
_unstackBrokerBindHooks : function(modeInstance) {
|
|
867
981
|
// Setup user socket event listeners
|
|
@@ -883,6 +997,7 @@ Crisp.prototype = {
|
|
|
883
997
|
* @param {object} body
|
|
884
998
|
* @param {function} resolve
|
|
885
999
|
* @param {function} reject
|
|
1000
|
+
* @return {undefined}
|
|
886
1001
|
*/
|
|
887
1002
|
_request : function(resource, method, query, body, resolve, reject) {
|
|
888
1003
|
var self = this;
|
|
@@ -893,7 +1008,7 @@ Crisp.prototype = {
|
|
|
893
1008
|
|
|
894
1009
|
headers : {
|
|
895
1010
|
"User-Agent" : self._useragent,
|
|
896
|
-
"X-Crisp-Tier" : self.
|
|
1011
|
+
"X-Crisp-Tier" : self.auth.tier
|
|
897
1012
|
},
|
|
898
1013
|
|
|
899
1014
|
throwHttpErrors : false
|
|
@@ -976,6 +1091,7 @@ Crisp.prototype = {
|
|
|
976
1091
|
* @param {string} method
|
|
977
1092
|
* @param {number} statusCode
|
|
978
1093
|
* @param {object} response
|
|
1094
|
+
* @return {string}
|
|
979
1095
|
*/
|
|
980
1096
|
_readErrorResponseReason : function(method, statusCode, response) {
|
|
981
1097
|
// HEAD method? As HEAD requests do not expect any response body, then we \
|
|
@@ -1006,6 +1122,7 @@ Crisp.prototype = {
|
|
|
1006
1122
|
* @param {object} body
|
|
1007
1123
|
* @param {string} timestamp
|
|
1008
1124
|
* @param {string} signature
|
|
1125
|
+
* @return {boolean}
|
|
1009
1126
|
*/
|
|
1010
1127
|
_verifySignature : function(secret, body, timestamp, signature) {
|
|
1011
1128
|
// Ensure all provided data is valid
|
|
@@ -18,8 +18,10 @@ function BucketURL(service, crisp) {
|
|
|
18
18
|
/**
|
|
19
19
|
* Generate Bucket URL
|
|
20
20
|
* @memberof BucketURL
|
|
21
|
+
* @public
|
|
21
22
|
* @method generateBucketURL
|
|
22
|
-
* @
|
|
23
|
+
* @param {object} data
|
|
24
|
+
* @return {Promise}
|
|
23
25
|
*/
|
|
24
26
|
service.generateBucketURL = function(data) {
|
|
25
27
|
return crisp.post(
|
|
@@ -18,8 +18,12 @@ function MediaAnimation(service, crisp) {
|
|
|
18
18
|
/**
|
|
19
19
|
* List Animation Medias
|
|
20
20
|
* @memberof MediaAnimation
|
|
21
|
+
* @public
|
|
21
22
|
* @method listAnimationMedias
|
|
22
|
-
* @
|
|
23
|
+
* @param {number} pageNumber
|
|
24
|
+
* @param {string} listID
|
|
25
|
+
* @param {object} searchQuery
|
|
26
|
+
* @return {Promise}
|
|
23
27
|
*/
|
|
24
28
|
service.listAnimationMedias = function(pageNumber, listID, searchQuery) {
|
|
25
29
|
return crisp.get(
|
|
@@ -18,8 +18,9 @@ function PluginConnect(service, crisp) {
|
|
|
18
18
|
/**
|
|
19
19
|
* Get Connect Account
|
|
20
20
|
* @memberof PluginConnect
|
|
21
|
+
* @public
|
|
21
22
|
* @method getConnectAccount
|
|
22
|
-
* @return Promise
|
|
23
|
+
* @return {Promise}
|
|
23
24
|
*/
|
|
24
25
|
service.getConnectAccount = function() {
|
|
25
26
|
return crisp.get(
|
|
@@ -30,8 +31,9 @@ function PluginConnect(service, crisp) {
|
|
|
30
31
|
/**
|
|
31
32
|
* Check Connect Session Validity
|
|
32
33
|
* @memberof PluginConnect
|
|
34
|
+
* @public
|
|
33
35
|
* @method checkConnectSessionValidity
|
|
34
|
-
* @return Promise
|
|
36
|
+
* @return {Promise}
|
|
35
37
|
*/
|
|
36
38
|
service.checkConnectSessionValidity = function() {
|
|
37
39
|
return crisp.head(
|
|
@@ -42,8 +44,12 @@ function PluginConnect(service, crisp) {
|
|
|
42
44
|
/**
|
|
43
45
|
* List All Connect Websites
|
|
44
46
|
* @memberof PluginConnect
|
|
47
|
+
* @public
|
|
45
48
|
* @method listAllConnectWebsites
|
|
46
|
-
* @
|
|
49
|
+
* @param {number} pageNumber
|
|
50
|
+
* @param {boolean} [filterConfigured]
|
|
51
|
+
* @param {string} [dateSince]
|
|
52
|
+
* @return {Promise}
|
|
47
53
|
*/
|
|
48
54
|
service.listAllConnectWebsites = function(
|
|
49
55
|
pageNumber, filterConfigured, dateSince
|
|
@@ -73,8 +79,9 @@ function PluginConnect(service, crisp) {
|
|
|
73
79
|
/**
|
|
74
80
|
* Get Connect Endpoints
|
|
75
81
|
* @memberof PluginConnect
|
|
82
|
+
* @public
|
|
76
83
|
* @method getConnectEndpoints
|
|
77
|
-
* @return Promise
|
|
84
|
+
* @return {Promise}
|
|
78
85
|
*/
|
|
79
86
|
service.getConnectEndpoints = function() {
|
|
80
87
|
return crisp.get(
|