wingbot-mongodb 2.22.0-alpha.1 → 2.22.0-alpha.2
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/28ee104d-8ece-4824-bb02-ada068f4d2d3.json +1 -0
- package/.nyc_output/processinfo/28ee104d-8ece-4824-bb02-ada068f4d2d3.json +1 -0
- package/.nyc_output/processinfo/index.json +1 -1
- package/package.json +1 -1
- package/src/AttachmentCache.js +5 -4
- package/src/AuditLogStorage.js +3 -2
- package/src/BaseStorage.js +5 -4
- package/src/BotConfigStorage.js +2 -2
- package/src/BotTokenStorage.js +8 -8
- package/src/ChatLogStorage.js +1 -1
- package/src/StateStorage.js +7 -4
- package/.nyc_output/9818b26b-1122-4466-80dd-e8cd02a9c4cf.json +0 -1
- package/.nyc_output/processinfo/9818b26b-1122-4466-80dd-e8cd02a9c4cf.json +0 -1
package/package.json
CHANGED
package/src/AttachmentCache.js
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
'use strict';
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
/** @typedef {import('mongodb').Db} Db */
|
|
7
|
+
/** @typedef {import('mongodb').Collection} Collection */
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Cache storage for Facebook attachments
|
|
@@ -14,7 +15,7 @@ class AttachmentCache {
|
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
*
|
|
17
|
-
* @param {
|
|
18
|
+
* @param {Db|{():Promise<Db>}} mongoDb
|
|
18
19
|
* @param {string} collectionName
|
|
19
20
|
*/
|
|
20
21
|
constructor (mongoDb, collectionName = 'attachments') {
|
|
@@ -22,13 +23,13 @@ class AttachmentCache {
|
|
|
22
23
|
this._collectionName = collectionName;
|
|
23
24
|
|
|
24
25
|
/**
|
|
25
|
-
* @type {
|
|
26
|
+
* @type {Collection}
|
|
26
27
|
*/
|
|
27
28
|
this._collection = null;
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
/**
|
|
31
|
-
* @returns {Promise<
|
|
32
|
+
* @returns {Promise<Collection>}
|
|
32
33
|
*/
|
|
33
34
|
async _getCollection () {
|
|
34
35
|
if (this._collection === null) {
|
package/src/AuditLogStorage.js
CHANGED
|
@@ -6,8 +6,6 @@
|
|
|
6
6
|
const jsonwebtoken = require('jsonwebtoken');
|
|
7
7
|
const BaseStorage = require('./BaseStorage');
|
|
8
8
|
|
|
9
|
-
/** @typedef {import('mongodb/lib/db')} Db */
|
|
10
|
-
|
|
11
9
|
const LEVEL_CRITICAL = 'Critical';
|
|
12
10
|
const LEVEL_IMPORTANT = 'Important';
|
|
13
11
|
const LEVEL_DEBUG = 'Debug';
|
|
@@ -91,6 +89,9 @@ const TYPE_INFO = 'Info';
|
|
|
91
89
|
* @returns {Promise}
|
|
92
90
|
*/
|
|
93
91
|
|
|
92
|
+
/** @typedef {import('mongodb').Db} Db */
|
|
93
|
+
/** @typedef {import('mongodb').Collection} Collection */
|
|
94
|
+
|
|
94
95
|
/**
|
|
95
96
|
* Storage for audit logs with signatures chain
|
|
96
97
|
*/
|
package/src/BaseStorage.js
CHANGED
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
const mongodb = require('mongodb'); // eslint-disable-line no-unused-vars
|
|
7
7
|
const crypto = require('crypto');
|
|
8
8
|
|
|
9
|
-
/** @typedef {import('mongodb
|
|
10
|
-
/** @typedef {import('mongodb
|
|
9
|
+
/** @typedef {import('mongodb').Db} Db */
|
|
10
|
+
/** @typedef {import('mongodb').Collection} Collection */
|
|
11
|
+
/** @typedef {import('mongodb').CreateIndexesOptions} CreateIndexesOptions */
|
|
11
12
|
|
|
12
13
|
class BaseStorage {
|
|
13
14
|
|
|
@@ -76,7 +77,7 @@ class BaseStorage {
|
|
|
76
77
|
* Add custom indexing rule
|
|
77
78
|
*
|
|
78
79
|
* @param {object} index
|
|
79
|
-
* @param {
|
|
80
|
+
* @param {CreateIndexesOptions} options
|
|
80
81
|
*/
|
|
81
82
|
addIndex (index, options) {
|
|
82
83
|
if (!options.name) {
|
|
@@ -209,7 +210,7 @@ class BaseStorage {
|
|
|
209
210
|
|
|
210
211
|
/**
|
|
211
212
|
*
|
|
212
|
-
* @
|
|
213
|
+
* @protected
|
|
213
214
|
* @template T
|
|
214
215
|
* @param {T} object
|
|
215
216
|
* @returns {T}
|
package/src/BotConfigStorage.js
CHANGED
|
@@ -11,8 +11,8 @@ try {
|
|
|
11
11
|
// noop
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
/** @typedef {import('mongodb
|
|
15
|
-
/** @typedef {import('mongodb
|
|
14
|
+
/** @typedef {import('mongodb').Db} Db */
|
|
15
|
+
/** @typedef {import('mongodb').Collection} Collection */
|
|
16
16
|
|
|
17
17
|
const CONFIG_ID = 'config';
|
|
18
18
|
|
package/src/BotTokenStorage.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
'use strict';
|
|
5
5
|
|
|
6
|
-
const mongodb = require('mongodb'); // eslint-disable-line no-unused-vars
|
|
7
6
|
const tokenFactory = require('./tokenFactory');
|
|
8
7
|
|
|
9
8
|
const TOKEN_INDEX = 'token-index';
|
|
@@ -16,6 +15,9 @@ const USER_INDEX = 'user-page-index';
|
|
|
16
15
|
* @prop {string} token
|
|
17
16
|
*/
|
|
18
17
|
|
|
18
|
+
/** @typedef {import('mongodb').Db} Db */
|
|
19
|
+
/** @typedef {import('mongodb').Collection} Collection */
|
|
20
|
+
|
|
19
21
|
/**
|
|
20
22
|
* Storage for webview tokens
|
|
21
23
|
*
|
|
@@ -25,7 +27,7 @@ class BotTokenStorage {
|
|
|
25
27
|
|
|
26
28
|
/**
|
|
27
29
|
*
|
|
28
|
-
* @param {
|
|
30
|
+
* @param {Db|{():Promise<Db>}} mongoDb
|
|
29
31
|
* @param {string} collectionName
|
|
30
32
|
*/
|
|
31
33
|
constructor (mongoDb, collectionName = 'tokens') {
|
|
@@ -33,13 +35,13 @@ class BotTokenStorage {
|
|
|
33
35
|
this._collectionName = collectionName;
|
|
34
36
|
|
|
35
37
|
/**
|
|
36
|
-
* @type {
|
|
38
|
+
* @type {Collection}
|
|
37
39
|
*/
|
|
38
40
|
this._collection = null;
|
|
39
41
|
}
|
|
40
42
|
|
|
41
43
|
/**
|
|
42
|
-
* @returns {Promise<
|
|
44
|
+
* @returns {Promise<Collection>}
|
|
43
45
|
*/
|
|
44
46
|
async _getCollection () {
|
|
45
47
|
if (this._collection === null) {
|
|
@@ -60,8 +62,7 @@ class BotTokenStorage {
|
|
|
60
62
|
token: 1
|
|
61
63
|
}, {
|
|
62
64
|
unique: true,
|
|
63
|
-
name: TOKEN_INDEX
|
|
64
|
-
dropDups: true
|
|
65
|
+
name: TOKEN_INDEX
|
|
65
66
|
});
|
|
66
67
|
}
|
|
67
68
|
try {
|
|
@@ -75,8 +76,7 @@ class BotTokenStorage {
|
|
|
75
76
|
pageId: 1
|
|
76
77
|
}, {
|
|
77
78
|
unique: true,
|
|
78
|
-
name: USER_INDEX
|
|
79
|
-
dropDups: true
|
|
79
|
+
name: USER_INDEX
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
82
|
}
|
package/src/ChatLogStorage.js
CHANGED
|
@@ -8,7 +8,7 @@ const BaseStorage = require('./BaseStorage');
|
|
|
8
8
|
const PAGE_SENDER_TIMESTAMP = 'pageId_1_senderId_1_timestamp_-1';
|
|
9
9
|
const TIMESTAMP = 'timestamp_1';
|
|
10
10
|
|
|
11
|
-
/** @typedef {import('mongodb
|
|
11
|
+
/** @typedef {import('mongodb').Db} Db */
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Storage for conversation logs
|
package/src/StateStorage.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
'use strict';
|
|
5
5
|
|
|
6
|
-
const mongodb = require('mongodb'); // eslint-disable-line no-unused-vars
|
|
7
6
|
const BaseStorage = require('./BaseStorage');
|
|
8
7
|
|
|
9
8
|
const USER_INDEX = 'senderId_1_pageId_1';
|
|
@@ -22,6 +21,8 @@ const SEARCH = 'search-text';
|
|
|
22
21
|
* @prop {string} [search]
|
|
23
22
|
*/
|
|
24
23
|
|
|
24
|
+
/** @typedef {import('mongodb').Db} Db */
|
|
25
|
+
|
|
25
26
|
/**
|
|
26
27
|
* Storage for chat states
|
|
27
28
|
*
|
|
@@ -31,7 +32,7 @@ class StateStorage extends BaseStorage {
|
|
|
31
32
|
|
|
32
33
|
/**
|
|
33
34
|
*
|
|
34
|
-
* @param {
|
|
35
|
+
* @param {Db|{():Promise<Db>}} mongoDb
|
|
35
36
|
* @param {string} collectionName
|
|
36
37
|
* @param {{error:Function,log:Function}} [log] - console like logger
|
|
37
38
|
* @param {boolean} isCosmo
|
|
@@ -41,7 +42,7 @@ class StateStorage extends BaseStorage {
|
|
|
41
42
|
|
|
42
43
|
this.addIndex(
|
|
43
44
|
{ senderId: 1, pageId: 1 },
|
|
44
|
-
{ name: USER_INDEX, unique: true
|
|
45
|
+
{ name: USER_INDEX, unique: true }
|
|
45
46
|
);
|
|
46
47
|
this.addIndex(
|
|
47
48
|
{ lastInteraction: isCosmo ? 1 : -1 },
|
|
@@ -77,7 +78,9 @@ class StateStorage extends BaseStorage {
|
|
|
77
78
|
*/
|
|
78
79
|
async getState (senderId, pageId) {
|
|
79
80
|
const c = await this._getCollection();
|
|
80
|
-
|
|
81
|
+
const doc = await c.findOne({ senderId, pageId }, { projection: { _id: 0 } });
|
|
82
|
+
// @ts-ignore
|
|
83
|
+
return doc;
|
|
81
84
|
}
|
|
82
85
|
|
|
83
86
|
/**
|