wingbot-mongodb 2.19.0 → 2.19.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/package.json +4 -2
- package/src/BotConfigStorage.js +15 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wingbot-mongodb",
|
|
3
|
-
"version": "2.19.
|
|
3
|
+
"version": "2.19.1",
|
|
4
4
|
"description": "MongoDB storage for wingbot.ai",
|
|
5
5
|
"main": "src/main.js",
|
|
6
6
|
"scripts": {
|
|
@@ -49,7 +49,9 @@
|
|
|
49
49
|
"wingbot": "^3.25.0"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
|
-
"mongodb": "^3.0.0"
|
|
52
|
+
"mongodb": "^3.0.0"
|
|
53
|
+
},
|
|
54
|
+
"optionalDependencies": {
|
|
53
55
|
"wingbot": "^3.0.0"
|
|
54
56
|
},
|
|
55
57
|
"dependencies": {
|
package/src/BotConfigStorage.js
CHANGED
|
@@ -3,8 +3,16 @@
|
|
|
3
3
|
*/
|
|
4
4
|
'use strict';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
let apiAuthorizer = () => false;
|
|
7
|
+
try {
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
({ apiAuthorizer } = module.require('wingbot'));
|
|
10
|
+
} catch (e) {
|
|
11
|
+
// noop
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** @typedef {import('mongodb/lib/db')} Db */
|
|
15
|
+
/** @typedef {import('mongodb/lib/collection')} Collection */
|
|
8
16
|
|
|
9
17
|
const CONFIG_ID = 'config';
|
|
10
18
|
|
|
@@ -17,7 +25,7 @@ class BotConfigStorage {
|
|
|
17
25
|
|
|
18
26
|
/**
|
|
19
27
|
*
|
|
20
|
-
* @param {
|
|
28
|
+
* @param {Db|{():Promise<Db>}} mongoDb
|
|
21
29
|
* @param {string} collectionName
|
|
22
30
|
*/
|
|
23
31
|
constructor (mongoDb, collectionName = 'botconfig') {
|
|
@@ -25,13 +33,13 @@ class BotConfigStorage {
|
|
|
25
33
|
this._collectionName = collectionName;
|
|
26
34
|
|
|
27
35
|
/**
|
|
28
|
-
* @type {
|
|
36
|
+
* @type {Collection}
|
|
29
37
|
*/
|
|
30
38
|
this._collection = null;
|
|
31
39
|
}
|
|
32
40
|
|
|
33
41
|
/**
|
|
34
|
-
* @returns {Promise<
|
|
42
|
+
* @returns {Promise<Collection>}
|
|
35
43
|
*/
|
|
36
44
|
async _getCollection () {
|
|
37
45
|
if (this._collection === null) {
|
|
@@ -56,6 +64,7 @@ class BotConfigStorage {
|
|
|
56
64
|
const storage = this;
|
|
57
65
|
return {
|
|
58
66
|
async updateBot (args, ctx) {
|
|
67
|
+
// @ts-ignore
|
|
59
68
|
if (!apiAuthorizer(args, ctx, acl)) {
|
|
60
69
|
return null;
|
|
61
70
|
}
|
|
@@ -74,6 +83,7 @@ class BotConfigStorage {
|
|
|
74
83
|
async invalidateConfig () {
|
|
75
84
|
const c = await this._getCollection();
|
|
76
85
|
|
|
86
|
+
// @ts-ignore
|
|
77
87
|
return c.deleteOne({ _id: CONFIG_ID });
|
|
78
88
|
}
|
|
79
89
|
|