wingbot-mongodb 2.19.1 → 2.21.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/.nyc_output/32821199-22af-42bd-8e0d-c255510f3efa.json +1 -0
- package/.nyc_output/processinfo/{8e3ceac5-95c5-4bf9-a069-da51cccc2525.json → 32821199-22af-42bd-8e0d-c255510f3efa.json} +1 -1
- package/.nyc_output/processinfo/index.json +1 -1
- package/README.md +257 -20
- package/package.json +5 -4
- package/src/BaseStorage.js +61 -10
- package/src/NotificationsStorage.js +17 -9
- package/src/StateStorage.js +1 -1
- package/.nyc_output/8e3ceac5-95c5-4bf9-a069-da51cccc2525.json +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"processes":{"
|
|
1
|
+
{"processes":{"32821199-22af-42bd-8e0d-c255510f3efa":{"parent":null,"children":[]}},"files":{"/Users/david/Downloads/wingbot-mongodb/src/AttachmentCache.js":["32821199-22af-42bd-8e0d-c255510f3efa"],"/Users/david/Downloads/wingbot-mongodb/src/AuditLogStorage.js":["32821199-22af-42bd-8e0d-c255510f3efa"],"/Users/david/Downloads/wingbot-mongodb/src/BaseStorage.js":["32821199-22af-42bd-8e0d-c255510f3efa"],"/Users/david/Downloads/wingbot-mongodb/src/BotConfigStorage.js":["32821199-22af-42bd-8e0d-c255510f3efa"],"/Users/david/Downloads/wingbot-mongodb/src/BotTokenStorage.js":["32821199-22af-42bd-8e0d-c255510f3efa"],"/Users/david/Downloads/wingbot-mongodb/src/tokenFactory.js":["32821199-22af-42bd-8e0d-c255510f3efa"],"/Users/david/Downloads/wingbot-mongodb/src/ChatLogStorage.js":["32821199-22af-42bd-8e0d-c255510f3efa"],"/Users/david/Downloads/wingbot-mongodb/src/NotificationsStorage.js":["32821199-22af-42bd-8e0d-c255510f3efa"],"/Users/david/Downloads/wingbot-mongodb/src/StateStorage.js":["32821199-22af-42bd-8e0d-c255510f3efa"]},"externalIds":{}}
|
package/README.md
CHANGED
|
@@ -23,6 +23,9 @@ Contains storage for tokens, chat states, bot config and chat logs.
|
|
|
23
23
|
<dt><a href="#AttachmentCache">AttachmentCache</a></dt>
|
|
24
24
|
<dd><p>Cache storage for Facebook attachments</p>
|
|
25
25
|
</dd>
|
|
26
|
+
<dt><a href="#AuditLogStorage">AuditLogStorage</a></dt>
|
|
27
|
+
<dd><p>Storage for audit logs with signatures chain</p>
|
|
28
|
+
</dd>
|
|
26
29
|
<dt><a href="#NotificationsStorage">NotificationsStorage</a></dt>
|
|
27
30
|
<dd></dd>
|
|
28
31
|
<dt><a href="#BaseStorage">BaseStorage</a></dt>
|
|
@@ -38,6 +41,30 @@ Contains storage for tokens, chat states, bot config and chat logs.
|
|
|
38
41
|
<dd></dd>
|
|
39
42
|
<dt><a href="#Token">Token</a> : <code>object</code></dt>
|
|
40
43
|
<dd></dd>
|
|
44
|
+
<dt><a href="#Db">Db</a> : <code>module:mongodb/lib/db</code></dt>
|
|
45
|
+
<dd></dd>
|
|
46
|
+
<dt><a href="#Db">Db</a> : <code>module:mongodb/lib/db</code></dt>
|
|
47
|
+
<dd></dd>
|
|
48
|
+
<dt><a href="#Collection">Collection</a> : <code>module:mongodb/lib/collection</code></dt>
|
|
49
|
+
<dd></dd>
|
|
50
|
+
<dt><a href="#Db">Db</a> : <code>module:mongodb/lib/db</code></dt>
|
|
51
|
+
<dd></dd>
|
|
52
|
+
<dt><a href="#TrackingEvent">TrackingEvent</a> : <code>object</code></dt>
|
|
53
|
+
<dd></dd>
|
|
54
|
+
<dt><a href="#User">User</a> : <code>object</code></dt>
|
|
55
|
+
<dd></dd>
|
|
56
|
+
<dt><a href="#Meta">Meta</a> : <code>object</code></dt>
|
|
57
|
+
<dd></dd>
|
|
58
|
+
<dt><a href="#LogEntry">LogEntry</a> : <code>object</code></dt>
|
|
59
|
+
<dd></dd>
|
|
60
|
+
<dt><a href="#JwtVerifier">JwtVerifier</a> ⇒ <code>Promise.<boolean></code></dt>
|
|
61
|
+
<dd><p>JWT Verifier</p>
|
|
62
|
+
</dd>
|
|
63
|
+
<dt><a href="#AuditLogEntry">AuditLogEntry</a> : <code>object</code></dt>
|
|
64
|
+
<dd></dd>
|
|
65
|
+
<dt><a href="#AuditLogCallback">AuditLogCallback</a> ⇒ <code>Promise</code></dt>
|
|
66
|
+
<dd><p>Audit Log Callback</p>
|
|
67
|
+
</dd>
|
|
41
68
|
<dt><a href="#Target">Target</a> : <code>Object</code></dt>
|
|
42
69
|
<dd></dd>
|
|
43
70
|
<dt><a href="#Subscribtion">Subscribtion</a> : <code>Object</code></dt>
|
|
@@ -46,6 +73,10 @@ Contains storage for tokens, chat states, bot config and chat logs.
|
|
|
46
73
|
<dd></dd>
|
|
47
74
|
<dt><a href="#Task">Task</a> : <code>Object</code></dt>
|
|
48
75
|
<dd></dd>
|
|
76
|
+
<dt><a href="#Db">Db</a> : <code>module:mongodb/lib/db</code></dt>
|
|
77
|
+
<dd></dd>
|
|
78
|
+
<dt><a href="#Collection">Collection</a> : <code>module:mongodb/lib/collection</code></dt>
|
|
79
|
+
<dd></dd>
|
|
49
80
|
</dl>
|
|
50
81
|
|
|
51
82
|
<a name="StateStorage"></a>
|
|
@@ -70,7 +101,7 @@ Storage for chat states
|
|
|
70
101
|
| Param | Type | Default | Description |
|
|
71
102
|
| --- | --- | --- | --- |
|
|
72
103
|
| mongoDb | <code>mongodb.Db</code> \| <code>Object</code> | | |
|
|
73
|
-
| collectionName | <code>string</code> | <code>"
|
|
104
|
+
| collectionName | <code>string</code> | <code>"states"</code> | |
|
|
74
105
|
| [log] | <code>Object</code> | | console like logger |
|
|
75
106
|
| isCosmo | <code>boolean</code> | <code>false</code> | |
|
|
76
107
|
|
|
@@ -195,24 +226,25 @@ Storage for conversation logs
|
|
|
195
226
|
**Kind**: global class
|
|
196
227
|
|
|
197
228
|
* [ChatLogStorage](#ChatLogStorage)
|
|
198
|
-
* [new ChatLogStorage(mongoDb, collectionName, [log], isCosmo)](#new_ChatLogStorage_new)
|
|
199
|
-
* [.getInteractions(senderId, pageId, [limit], [endAt], [startAt])](#ChatLogStorage+getInteractions)
|
|
229
|
+
* [new ChatLogStorage(mongoDb, collectionName, [log], [isCosmo], [secret])](#new_ChatLogStorage_new)
|
|
230
|
+
* [.getInteractions(senderId, pageId, [limit], [endAt], [startAt])](#ChatLogStorage+getInteractions) ⇒ <code>Promise.<Array.<object>></code>
|
|
200
231
|
* [.log(senderId, responses, request, [metadata])](#ChatLogStorage+log) ⇒ <code>Promise</code>
|
|
201
232
|
|
|
202
233
|
<a name="new_ChatLogStorage_new"></a>
|
|
203
234
|
|
|
204
|
-
### new ChatLogStorage(mongoDb, collectionName, [log], isCosmo)
|
|
235
|
+
### new ChatLogStorage(mongoDb, collectionName, [log], [isCosmo], [secret])
|
|
205
236
|
|
|
206
237
|
| Param | Type | Default | Description |
|
|
207
238
|
| --- | --- | --- | --- |
|
|
208
|
-
| mongoDb | <code>
|
|
239
|
+
| mongoDb | [<code>Db</code>](#Db) \| <code>Object</code> | | |
|
|
209
240
|
| collectionName | <code>string</code> | <code>"chatlogs"</code> | |
|
|
210
241
|
| [log] | <code>Object</code> | | console like logger |
|
|
211
|
-
| isCosmo | <code>boolean</code> | <code>false</code> | |
|
|
242
|
+
| [isCosmo] | <code>boolean</code> | <code>false</code> | |
|
|
243
|
+
| [secret] | <code>string</code> \| <code>Promise.<string></code> | <code>null</code> | |
|
|
212
244
|
|
|
213
245
|
<a name="ChatLogStorage+getInteractions"></a>
|
|
214
246
|
|
|
215
|
-
### chatLogStorage.getInteractions(senderId, pageId, [limit], [endAt], [startAt])
|
|
247
|
+
### chatLogStorage.getInteractions(senderId, pageId, [limit], [endAt], [startAt]) ⇒ <code>Promise.<Array.<object>></code>
|
|
216
248
|
Interate history
|
|
217
249
|
all limits are inclusive
|
|
218
250
|
|
|
@@ -249,8 +281,8 @@ Storage for wingbot.ai conversation config
|
|
|
249
281
|
|
|
250
282
|
* [BotConfigStorage](#BotConfigStorage)
|
|
251
283
|
* [new BotConfigStorage(mongoDb, collectionName)](#new_BotConfigStorage_new)
|
|
252
|
-
* [._collection](#BotConfigStorage+_collection) : <code>
|
|
253
|
-
* [._getCollection()](#BotConfigStorage+_getCollection) ⇒ <code>Promise.<
|
|
284
|
+
* [._collection](#BotConfigStorage+_collection) : [<code>Collection</code>](#Collection)
|
|
285
|
+
* [._getCollection()](#BotConfigStorage+_getCollection) ⇒ [<code>Promise.<Collection></code>](#Collection)
|
|
254
286
|
* [.api([onUpdate], [acl])](#BotConfigStorage+api) ⇒ <code>Object</code>
|
|
255
287
|
* [.invalidateConfig()](#BotConfigStorage+invalidateConfig) ⇒ <code>Promise</code>
|
|
256
288
|
* [.getConfigTimestamp()](#BotConfigStorage+getConfigTimestamp) ⇒ <code>Promise.<number></code>
|
|
@@ -264,16 +296,16 @@ Storage for wingbot.ai conversation config
|
|
|
264
296
|
|
|
265
297
|
| Param | Type | Default |
|
|
266
298
|
| --- | --- | --- |
|
|
267
|
-
| mongoDb | <code>
|
|
299
|
+
| mongoDb | [<code>Db</code>](#Db) \| <code>Object</code> | |
|
|
268
300
|
| collectionName | <code>string</code> | <code>"botconfig"</code> |
|
|
269
301
|
|
|
270
302
|
<a name="BotConfigStorage+_collection"></a>
|
|
271
303
|
|
|
272
|
-
### botConfigStorage.\_collection : <code>
|
|
304
|
+
### botConfigStorage.\_collection : [<code>Collection</code>](#Collection)
|
|
273
305
|
**Kind**: instance property of [<code>BotConfigStorage</code>](#BotConfigStorage)
|
|
274
306
|
<a name="BotConfigStorage+_getCollection"></a>
|
|
275
307
|
|
|
276
|
-
### botConfigStorage.\_getCollection() ⇒ <code>Promise.<
|
|
308
|
+
### botConfigStorage.\_getCollection() ⇒ [<code>Promise.<Collection></code>](#Collection)
|
|
277
309
|
**Kind**: instance method of [<code>BotConfigStorage</code>](#BotConfigStorage)
|
|
278
310
|
<a name="BotConfigStorage+api"></a>
|
|
279
311
|
|
|
@@ -376,6 +408,69 @@ Cache storage for Facebook attachments
|
|
|
376
408
|
| url | <code>string</code> |
|
|
377
409
|
| attachmentId | <code>number</code> |
|
|
378
410
|
|
|
411
|
+
<a name="AuditLogStorage"></a>
|
|
412
|
+
|
|
413
|
+
## AuditLogStorage
|
|
414
|
+
Storage for audit logs with signatures chain
|
|
415
|
+
|
|
416
|
+
**Kind**: global class
|
|
417
|
+
|
|
418
|
+
* [AuditLogStorage](#AuditLogStorage)
|
|
419
|
+
* [new AuditLogStorage(mongoDb, collectionName, [log], [isCosmo], [secret], [jwtVerifier])](#new_AuditLogStorage_new)
|
|
420
|
+
* [._jwtVerify](#AuditLogStorage+_jwtVerify) : [<code>JwtVerifier</code>](#JwtVerifier)
|
|
421
|
+
* [.callback](#AuditLogStorage+callback) : [<code>AuditLogCallback</code>](#AuditLogCallback)
|
|
422
|
+
* [.log(event, user, [meta], [wid], [type], [level], [date])](#AuditLogStorage+log) ⇒ <code>Promise</code>
|
|
423
|
+
* [.list([wid], [fromSeq], [limit])](#AuditLogStorage+list) ⇒ <code>Promise.<Array.<LogEntry>></code>
|
|
424
|
+
|
|
425
|
+
<a name="new_AuditLogStorage_new"></a>
|
|
426
|
+
|
|
427
|
+
### new AuditLogStorage(mongoDb, collectionName, [log], [isCosmo], [secret], [jwtVerifier])
|
|
428
|
+
|
|
429
|
+
| Param | Type | Default | Description |
|
|
430
|
+
| --- | --- | --- | --- |
|
|
431
|
+
| mongoDb | [<code>Db</code>](#Db) \| <code>Object</code> | | |
|
|
432
|
+
| collectionName | <code>string</code> | <code>"auditlog"</code> | |
|
|
433
|
+
| [log] | <code>Object</code> | | console like logger |
|
|
434
|
+
| [isCosmo] | <code>boolean</code> | <code>false</code> | |
|
|
435
|
+
| [secret] | <code>string</code> \| <code>Promise.<string></code> | <code>null</code> | |
|
|
436
|
+
| [jwtVerifier] | <code>string</code> \| <code>Promise.<string></code> | <code>null</code> | |
|
|
437
|
+
|
|
438
|
+
<a name="AuditLogStorage+_jwtVerify"></a>
|
|
439
|
+
|
|
440
|
+
### auditLogStorage.\_jwtVerify : [<code>JwtVerifier</code>](#JwtVerifier)
|
|
441
|
+
**Kind**: instance property of [<code>AuditLogStorage</code>](#AuditLogStorage)
|
|
442
|
+
<a name="AuditLogStorage+callback"></a>
|
|
443
|
+
|
|
444
|
+
### auditLogStorage.callback : [<code>AuditLogCallback</code>](#AuditLogCallback)
|
|
445
|
+
**Kind**: instance property of [<code>AuditLogStorage</code>](#AuditLogStorage)
|
|
446
|
+
<a name="AuditLogStorage+log"></a>
|
|
447
|
+
|
|
448
|
+
### auditLogStorage.log(event, user, [meta], [wid], [type], [level], [date]) ⇒ <code>Promise</code>
|
|
449
|
+
Add a log
|
|
450
|
+
|
|
451
|
+
**Kind**: instance method of [<code>AuditLogStorage</code>](#AuditLogStorage)
|
|
452
|
+
|
|
453
|
+
| Param | Type | Description |
|
|
454
|
+
| --- | --- | --- |
|
|
455
|
+
| event | [<code>TrackingEvent</code>](#TrackingEvent) | |
|
|
456
|
+
| user | [<code>User</code>](#User) | |
|
|
457
|
+
| [meta] | [<code>Meta</code>](#Meta) | |
|
|
458
|
+
| [wid] | <code>string</code> | workspace ID |
|
|
459
|
+
| [type] | <code>string</code> | |
|
|
460
|
+
| [level] | <code>string</code> | |
|
|
461
|
+
| [date] | <code>Date</code> | |
|
|
462
|
+
|
|
463
|
+
<a name="AuditLogStorage+list"></a>
|
|
464
|
+
|
|
465
|
+
### auditLogStorage.list([wid], [fromSeq], [limit]) ⇒ <code>Promise.<Array.<LogEntry>></code>
|
|
466
|
+
**Kind**: instance method of [<code>AuditLogStorage</code>](#AuditLogStorage)
|
|
467
|
+
|
|
468
|
+
| Param | Type | Default | Description |
|
|
469
|
+
| --- | --- | --- | --- |
|
|
470
|
+
| [wid] | <code>string</code> | | workspace id |
|
|
471
|
+
| [fromSeq] | <code>number</code> | <code>0</code> | for paging |
|
|
472
|
+
| [limit] | <code>number</code> | <code>40</code> | |
|
|
473
|
+
|
|
379
474
|
<a name="NotificationsStorage"></a>
|
|
380
475
|
|
|
381
476
|
## NotificationsStorage
|
|
@@ -647,21 +742,22 @@ Get last sent task from campaign
|
|
|
647
742
|
**Kind**: global class
|
|
648
743
|
|
|
649
744
|
* [BaseStorage](#BaseStorage)
|
|
650
|
-
* [new BaseStorage(mongoDb, collectionName, [log], isCosmo)](#new_BaseStorage_new)
|
|
651
|
-
* [._collection](#BaseStorage+_collection) : <code>Promise.<
|
|
745
|
+
* [new BaseStorage(mongoDb, collectionName, [log], [isCosmo])](#new_BaseStorage_new)
|
|
746
|
+
* [._collection](#BaseStorage+_collection) : [<code>Collection</code>](#Collection) \| [<code>Promise.<Collection></code>](#Collection)
|
|
747
|
+
* [.addFixtureDoc(...objects)](#BaseStorage+addFixtureDoc)
|
|
652
748
|
* [.addIndex(index, options)](#BaseStorage+addIndex)
|
|
653
|
-
* [._getCollection()](#BaseStorage+_getCollection) ⇒ <code>Promise.<
|
|
749
|
+
* [._getCollection()](#BaseStorage+_getCollection) ⇒ [<code>Promise.<Collection></code>](#Collection)
|
|
654
750
|
|
|
655
751
|
<a name="new_BaseStorage_new"></a>
|
|
656
752
|
|
|
657
|
-
### new BaseStorage(mongoDb, collectionName, [log], isCosmo)
|
|
753
|
+
### new BaseStorage(mongoDb, collectionName, [log], [isCosmo])
|
|
658
754
|
|
|
659
755
|
| Param | Type | Default | Description |
|
|
660
756
|
| --- | --- | --- | --- |
|
|
661
|
-
| mongoDb | <code>
|
|
757
|
+
| mongoDb | [<code>Db</code>](#Db) \| <code>Object</code> | | |
|
|
662
758
|
| collectionName | <code>string</code> | | |
|
|
663
759
|
| [log] | <code>Object</code> | | console like logger |
|
|
664
|
-
| isCosmo | <code>boolean</code> | <code>false</code> | |
|
|
760
|
+
| [isCosmo] | <code>boolean</code> | <code>false</code> | |
|
|
665
761
|
|
|
666
762
|
**Example**
|
|
667
763
|
```javascript
|
|
@@ -690,8 +786,19 @@ class MyCoolDataStorage extends BaseStorage {
|
|
|
690
786
|
```
|
|
691
787
|
<a name="BaseStorage+_collection"></a>
|
|
692
788
|
|
|
693
|
-
### baseStorage.\_collection : <code>Promise.<
|
|
789
|
+
### baseStorage.\_collection : [<code>Collection</code>](#Collection) \| [<code>Promise.<Collection></code>](#Collection)
|
|
694
790
|
**Kind**: instance property of [<code>BaseStorage</code>](#BaseStorage)
|
|
791
|
+
<a name="BaseStorage+addFixtureDoc"></a>
|
|
792
|
+
|
|
793
|
+
### baseStorage.addFixtureDoc(...objects)
|
|
794
|
+
Insert defalt document to DB
|
|
795
|
+
|
|
796
|
+
**Kind**: instance method of [<code>BaseStorage</code>](#BaseStorage)
|
|
797
|
+
|
|
798
|
+
| Param | Type |
|
|
799
|
+
| --- | --- |
|
|
800
|
+
| ...objects | <code>any</code> |
|
|
801
|
+
|
|
695
802
|
<a name="BaseStorage+addIndex"></a>
|
|
696
803
|
|
|
697
804
|
### baseStorage.addIndex(index, options)
|
|
@@ -706,7 +813,7 @@ Add custom indexing rule
|
|
|
706
813
|
|
|
707
814
|
<a name="BaseStorage+_getCollection"></a>
|
|
708
815
|
|
|
709
|
-
### baseStorage.\_getCollection() ⇒ <code>Promise.<
|
|
816
|
+
### baseStorage.\_getCollection() ⇒ [<code>Promise.<Collection></code>](#Collection)
|
|
710
817
|
Returns the collection to operate with
|
|
711
818
|
|
|
712
819
|
**Kind**: instance method of [<code>BaseStorage</code>](#BaseStorage)
|
|
@@ -744,6 +851,128 @@ Returns the collection to operate with
|
|
|
744
851
|
| pageId | <code>string</code> |
|
|
745
852
|
| token | <code>string</code> |
|
|
746
853
|
|
|
854
|
+
<a name="Db"></a>
|
|
855
|
+
|
|
856
|
+
## Db : <code>module:mongodb/lib/db</code>
|
|
857
|
+
**Kind**: global typedef
|
|
858
|
+
<a name="Db"></a>
|
|
859
|
+
|
|
860
|
+
## Db : <code>module:mongodb/lib/db</code>
|
|
861
|
+
**Kind**: global typedef
|
|
862
|
+
<a name="Collection"></a>
|
|
863
|
+
|
|
864
|
+
## Collection : <code>module:mongodb/lib/collection</code>
|
|
865
|
+
**Kind**: global typedef
|
|
866
|
+
<a name="Db"></a>
|
|
867
|
+
|
|
868
|
+
## Db : <code>module:mongodb/lib/db</code>
|
|
869
|
+
**Kind**: global typedef
|
|
870
|
+
<a name="TrackingEvent"></a>
|
|
871
|
+
|
|
872
|
+
## TrackingEvent : <code>object</code>
|
|
873
|
+
**Kind**: global typedef
|
|
874
|
+
**Properties**
|
|
875
|
+
|
|
876
|
+
| Name | Type | Default |
|
|
877
|
+
| --- | --- | --- |
|
|
878
|
+
| [type] | <code>string</code> | <code>"'audit'"</code> |
|
|
879
|
+
| category | <code>string</code> | |
|
|
880
|
+
| action | <code>string</code> | |
|
|
881
|
+
| [label] | <code>string</code> | |
|
|
882
|
+
| [payload] | <code>object</code> | |
|
|
883
|
+
|
|
884
|
+
<a name="User"></a>
|
|
885
|
+
|
|
886
|
+
## User : <code>object</code>
|
|
887
|
+
**Kind**: global typedef
|
|
888
|
+
**Properties**
|
|
889
|
+
|
|
890
|
+
| Name | Type | Description |
|
|
891
|
+
| --- | --- | --- |
|
|
892
|
+
| [id] | <code>string</code> | |
|
|
893
|
+
| [senderId] | <code>string</code> | |
|
|
894
|
+
| [pageId] | <code>string</code> | |
|
|
895
|
+
| [jwt] | <code>string</code> | jwt to check the authorship |
|
|
896
|
+
|
|
897
|
+
<a name="Meta"></a>
|
|
898
|
+
|
|
899
|
+
## Meta : <code>object</code>
|
|
900
|
+
**Kind**: global typedef
|
|
901
|
+
**Properties**
|
|
902
|
+
|
|
903
|
+
| Name | Type | Description |
|
|
904
|
+
| --- | --- | --- |
|
|
905
|
+
| [ip] | <code>string</code> | |
|
|
906
|
+
| [ua] | <code>string</code> | |
|
|
907
|
+
| [ro] | <code>string</code> | referrer || origin |
|
|
908
|
+
|
|
909
|
+
<a name="LogEntry"></a>
|
|
910
|
+
|
|
911
|
+
## LogEntry : <code>object</code>
|
|
912
|
+
**Kind**: global typedef
|
|
913
|
+
**Properties**
|
|
914
|
+
|
|
915
|
+
| Name | Type | Default | Description |
|
|
916
|
+
| --- | --- | --- | --- |
|
|
917
|
+
| date | <code>string</code> | | ISO date |
|
|
918
|
+
| delta | <code>number</code> | | time skew in ms if there was a write conflict |
|
|
919
|
+
| [eventType] | <code>string</code> | <code>"'audit'"</code> | |
|
|
920
|
+
| category | <code>string</code> | | |
|
|
921
|
+
| action | <code>string</code> | | |
|
|
922
|
+
| [label] | <code>string</code> | | |
|
|
923
|
+
| [payload] | <code>object</code> | | |
|
|
924
|
+
| level | <code>string</code> | | (Critical|Important|Debug) |
|
|
925
|
+
| ok | <code>boolean</code> | | signature matches |
|
|
926
|
+
| seq | <code>number</code> | | sequence number |
|
|
927
|
+
| type | <code>string</code> | | (Error|Warn|Info) |
|
|
928
|
+
| user | [<code>User</code>](#User) | | |
|
|
929
|
+
| wid | <code>string</code> | | workspace id |
|
|
930
|
+
| meta | [<code>Meta</code>](#Meta) | | |
|
|
931
|
+
|
|
932
|
+
<a name="JwtVerifier"></a>
|
|
933
|
+
|
|
934
|
+
## JwtVerifier ⇒ <code>Promise.<boolean></code>
|
|
935
|
+
JWT Verifier
|
|
936
|
+
|
|
937
|
+
**Kind**: global typedef
|
|
938
|
+
|
|
939
|
+
| Param | Type |
|
|
940
|
+
| --- | --- |
|
|
941
|
+
| token | <code>string</code> |
|
|
942
|
+
| userId | <code>string</code> |
|
|
943
|
+
| [user] | [<code>User</code>](#User) |
|
|
944
|
+
|
|
945
|
+
<a name="AuditLogEntry"></a>
|
|
946
|
+
|
|
947
|
+
## AuditLogEntry : <code>object</code>
|
|
948
|
+
**Kind**: global typedef
|
|
949
|
+
**Properties**
|
|
950
|
+
|
|
951
|
+
| Name | Type | Default | Description |
|
|
952
|
+
| --- | --- | --- | --- |
|
|
953
|
+
| date | <code>string</code> | | ISO date |
|
|
954
|
+
| [eventType] | <code>string</code> | <code>"'audit'"</code> | |
|
|
955
|
+
| category | <code>string</code> | | |
|
|
956
|
+
| action | <code>string</code> | | |
|
|
957
|
+
| [label] | <code>string</code> | | |
|
|
958
|
+
| [payload] | <code>object</code> | | |
|
|
959
|
+
| level | <code>string</code> | | (Critical|Important|Debug) |
|
|
960
|
+
| type | <code>string</code> | | (Error|Warn|Info) |
|
|
961
|
+
| user | [<code>User</code>](#User) | | |
|
|
962
|
+
| wid | <code>string</code> | | workspace id |
|
|
963
|
+
| meta | [<code>Meta</code>](#Meta) | | |
|
|
964
|
+
|
|
965
|
+
<a name="AuditLogCallback"></a>
|
|
966
|
+
|
|
967
|
+
## AuditLogCallback ⇒ <code>Promise</code>
|
|
968
|
+
Audit Log Callback
|
|
969
|
+
|
|
970
|
+
**Kind**: global typedef
|
|
971
|
+
|
|
972
|
+
| Param | Type |
|
|
973
|
+
| --- | --- |
|
|
974
|
+
| entry | [<code>AuditLogEntry</code>](#AuditLogEntry) |
|
|
975
|
+
|
|
747
976
|
<a name="Target"></a>
|
|
748
977
|
|
|
749
978
|
## Target : <code>Object</code>
|
|
@@ -817,3 +1046,11 @@ Returns the collection to operate with
|
|
|
817
1046
|
| [reaction] | <code>boolean</code> | user reacted |
|
|
818
1047
|
| [leaved] | <code>number</code> | time the event was not sent because user left |
|
|
819
1048
|
|
|
1049
|
+
<a name="Db"></a>
|
|
1050
|
+
|
|
1051
|
+
## Db : <code>module:mongodb/lib/db</code>
|
|
1052
|
+
**Kind**: global typedef
|
|
1053
|
+
<a name="Collection"></a>
|
|
1054
|
+
|
|
1055
|
+
## Collection : <code>module:mongodb/lib/collection</code>
|
|
1056
|
+
**Kind**: global typedef
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wingbot-mongodb",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.21.0",
|
|
4
4
|
"description": "MongoDB storage for wingbot.ai",
|
|
5
5
|
"main": "src/main.js",
|
|
6
6
|
"scripts": {
|
|
@@ -42,11 +42,12 @@
|
|
|
42
42
|
"eslint-plugin-jsx-a11y": "^6.4.1",
|
|
43
43
|
"eslint-plugin-mocha": "^9.0.0",
|
|
44
44
|
"eslint-plugin-react": "^7.26.1",
|
|
45
|
-
"jsdoc-to-markdown": "^7.1.
|
|
46
|
-
"
|
|
45
|
+
"jsdoc-to-markdown": "^7.1.1",
|
|
46
|
+
"jsdoc-tsimport-plugin": "^1.0.5",
|
|
47
|
+
"mocha": "^9.2.2",
|
|
47
48
|
"mongodb": "^3.7.3",
|
|
48
49
|
"nyc": "^15.1.0",
|
|
49
|
-
"wingbot": "^3.
|
|
50
|
+
"wingbot": "^3.30.0"
|
|
50
51
|
},
|
|
51
52
|
"peerDependencies": {
|
|
52
53
|
"mongodb": "^3.0.0"
|
package/src/BaseStorage.js
CHANGED
|
@@ -57,6 +57,19 @@ class BaseStorage {
|
|
|
57
57
|
|
|
58
58
|
this.ignoredSignatureKeys = ['_id', 'sign'];
|
|
59
59
|
this._secret = null;
|
|
60
|
+
|
|
61
|
+
this.systemIndexes = ['_id_', '_id'];
|
|
62
|
+
|
|
63
|
+
this._fixtures = [];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Insert defalt document to DB
|
|
68
|
+
*
|
|
69
|
+
* @param {...any} objects
|
|
70
|
+
*/
|
|
71
|
+
addFixtureDoc (...objects) {
|
|
72
|
+
this._fixtures.push(...objects);
|
|
60
73
|
}
|
|
61
74
|
|
|
62
75
|
/**
|
|
@@ -83,6 +96,7 @@ class BaseStorage {
|
|
|
83
96
|
let collection;
|
|
84
97
|
|
|
85
98
|
if (this._isCosmo) {
|
|
99
|
+
// @ts-ignore
|
|
86
100
|
const collections = await db.collections();
|
|
87
101
|
|
|
88
102
|
collection = collections
|
|
@@ -108,6 +122,7 @@ class BaseStorage {
|
|
|
108
122
|
/**
|
|
109
123
|
* Returns the collection to operate with
|
|
110
124
|
*
|
|
125
|
+
* @protected
|
|
111
126
|
* @returns {Promise<Collection>}
|
|
112
127
|
*/
|
|
113
128
|
async _getCollection () {
|
|
@@ -134,31 +149,51 @@ class BaseStorage {
|
|
|
134
149
|
}
|
|
135
150
|
|
|
136
151
|
await existing
|
|
137
|
-
.filter((e) => !
|
|
152
|
+
.filter((e) => !this.systemIndexes.includes(e.name)
|
|
138
153
|
&& !indexes.some((i) => e.name === i.options.name))
|
|
139
154
|
.reduce((p, e) => {
|
|
140
|
-
|
|
141
|
-
this._log.log(`dropping index ${e.name}`);
|
|
155
|
+
this._log.log(`DB.${this._collectionName} dropping index ${e.name}`);
|
|
142
156
|
return p
|
|
143
157
|
.then(() => collection.dropIndex(e.name))
|
|
144
158
|
.catch((err) => {
|
|
145
|
-
|
|
146
|
-
this._log.error(`dropping index ${e.name} FAILED`, err);
|
|
159
|
+
this._log.error(`DB.${this._collectionName} dropping index ${e.name} FAILED`, err);
|
|
147
160
|
});
|
|
148
161
|
}, Promise.resolve());
|
|
149
162
|
|
|
150
|
-
await indexes
|
|
163
|
+
const updated = await indexes
|
|
151
164
|
.filter((i) => !existing.some((e) => e.name === i.options.name))
|
|
152
165
|
.reduce((p, i) => {
|
|
153
|
-
this._log.log(`creating index ${i.name}`);
|
|
166
|
+
this._log.log(`DB.${this._collectionName} creating index ${i.options.name}`);
|
|
154
167
|
return p
|
|
155
168
|
.then(() => collection.createIndex(i.index, i.options))
|
|
156
169
|
.catch((e) => {
|
|
157
|
-
this._log.error(`failed to create index ${i.options.name} on ${collection.collectionName}`, e);
|
|
158
|
-
})
|
|
159
|
-
|
|
170
|
+
this._log.error(`DB.${this._collectionName} failed to create index ${i.options.name} on ${collection.collectionName}`, e);
|
|
171
|
+
})
|
|
172
|
+
.then(() => true);
|
|
173
|
+
}, Promise.resolve(false));
|
|
174
|
+
|
|
175
|
+
if (updated || existing.every((i) => this.systemIndexes.includes(i.name))) {
|
|
176
|
+
// upsert fixtures
|
|
177
|
+
|
|
178
|
+
await this._fixtures.reduce((p, o) => p
|
|
179
|
+
.then(() => collection.insertOne(o))
|
|
180
|
+
.then(() => this._log.log(`DB.${this._collectionName} Inserted fixture doc to "${this._collectionName}"`))
|
|
181
|
+
.catch((e) => {
|
|
182
|
+
if (e.code !== 11000) {
|
|
183
|
+
this._log.error(`DB.${this._collectionName} failed to insert fixture doc to "${this._collectionName}"`, e);
|
|
184
|
+
}
|
|
185
|
+
}),
|
|
186
|
+
Promise.resolve());
|
|
187
|
+
}
|
|
160
188
|
}
|
|
161
189
|
|
|
190
|
+
/**
|
|
191
|
+
*
|
|
192
|
+
* @template T
|
|
193
|
+
* @protected
|
|
194
|
+
* @param {T} object
|
|
195
|
+
* @returns {Promise<T>}
|
|
196
|
+
*/
|
|
162
197
|
async _sign (object) {
|
|
163
198
|
if (!this._secret) {
|
|
164
199
|
return object;
|
|
@@ -172,12 +207,20 @@ class BaseStorage {
|
|
|
172
207
|
});
|
|
173
208
|
}
|
|
174
209
|
|
|
210
|
+
/**
|
|
211
|
+
*
|
|
212
|
+
* @private
|
|
213
|
+
* @template T
|
|
214
|
+
* @param {T} object
|
|
215
|
+
* @returns {T}
|
|
216
|
+
*/
|
|
175
217
|
_objectToSign (object) {
|
|
176
218
|
const entries = Object.keys(object)
|
|
177
219
|
.filter((key) => !this.ignoredSignatureKeys.includes(key));
|
|
178
220
|
|
|
179
221
|
entries.sort();
|
|
180
222
|
|
|
223
|
+
// @ts-ignore
|
|
181
224
|
return entries.reduce((o, key) => {
|
|
182
225
|
let val = object[key];
|
|
183
226
|
if (val instanceof Date) {
|
|
@@ -187,6 +230,14 @@ class BaseStorage {
|
|
|
187
230
|
}, {});
|
|
188
231
|
}
|
|
189
232
|
|
|
233
|
+
/**
|
|
234
|
+
*
|
|
235
|
+
* @template T
|
|
236
|
+
* @param {T} objToSign
|
|
237
|
+
* @param {string} secret
|
|
238
|
+
* @param {string} [previous]
|
|
239
|
+
* @returns {string}
|
|
240
|
+
*/
|
|
190
241
|
_signWithSecret (objToSign, secret, previous = null) {
|
|
191
242
|
const h = crypto.createHmac('sha3-224', secret)
|
|
192
243
|
.update(JSON.stringify(objToSign));
|
|
@@ -771,21 +771,29 @@ class NotificationsStorage {
|
|
|
771
771
|
|
|
772
772
|
/**
|
|
773
773
|
*
|
|
774
|
-
* @param {string} senderId
|
|
774
|
+
* @param {string|string[]} senderId
|
|
775
775
|
* @param {string} pageId
|
|
776
776
|
* @param {string} tag
|
|
777
|
+
* @param {boolean} [upsert]
|
|
777
778
|
* @returns {Promise}
|
|
778
779
|
*/
|
|
779
|
-
async subscribe (senderId, pageId, tag) {
|
|
780
|
+
async subscribe (senderId, pageId, tag, upsert = true) {
|
|
781
|
+
const senderIds = Array.isArray(senderId) ? senderId : [senderId];
|
|
782
|
+
|
|
783
|
+
if (senderIds.length === 0) {
|
|
784
|
+
return;
|
|
785
|
+
}
|
|
780
786
|
const c = await this._getCollection(this.subscribtionsCollection);
|
|
781
787
|
|
|
782
|
-
await c.
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
788
|
+
await c.bulkWrite(
|
|
789
|
+
senderIds.map((sid) => ({
|
|
790
|
+
updateOne: {
|
|
791
|
+
filter: { senderId: sid, pageId },
|
|
792
|
+
update: { $addToSet: { subs: tag } },
|
|
793
|
+
upsert
|
|
794
|
+
}
|
|
795
|
+
}))
|
|
796
|
+
);
|
|
789
797
|
}
|
|
790
798
|
|
|
791
799
|
/**
|
package/src/StateStorage.js
CHANGED
|
@@ -36,7 +36,7 @@ class StateStorage extends BaseStorage {
|
|
|
36
36
|
* @param {{error:Function,log:Function}} [log] - console like logger
|
|
37
37
|
* @param {boolean} isCosmo
|
|
38
38
|
*/
|
|
39
|
-
constructor (mongoDb, collectionName = '
|
|
39
|
+
constructor (mongoDb, collectionName = 'states', log = console, isCosmo = false) {
|
|
40
40
|
super(mongoDb, collectionName, log, isCosmo);
|
|
41
41
|
|
|
42
42
|
this.addIndex(
|