wingbot-mongodb 3.0.0-alpha.9 → 3.1.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/.github/workflows/test.yml +39 -0
- package/.nyc_output/0d879467-0e5f-4098-bea4-73c520af6dcd.json +1 -0
- package/.nyc_output/processinfo/{38fa2b60-0502-4dbc-9c7f-c478802fb2de.json → 0d879467-0e5f-4098-bea4-73c520af6dcd.json} +1 -1
- package/.nyc_output/processinfo/index.json +1 -1
- package/package.json +11 -11
- package/src/AuditLogStorage.js +1 -1
- package/src/BaseStorage.js +16 -10
- package/src/BotConfigStorage.js +1 -1
- package/src/BotTokenStorage.js +3 -1
- package/src/NotificationsStorage.js +12 -2
- package/src/tokenFactory.js +6 -4
- package/.nyc_output/38fa2b60-0502-4dbc-9c7f-c478802fb2de.json +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"parent":null,"pid":
|
|
1
|
+
{"parent":null,"pid":17347,"argv":["/usr/local/bin/node","/Users/david/Development/wingbot-mongodb/node_modules/.bin/mocha","./test"],"execArgv":[],"cwd":"/Users/david/Development/wingbot-mongodb","time":1669369533432,"ppid":17346,"coverageFilename":"/Users/david/Development/wingbot-mongodb/.nyc_output/0d879467-0e5f-4098-bea4-73c520af6dcd.json","externalId":"","uuid":"0d879467-0e5f-4098-bea4-73c520af6dcd","files":["/Users/david/Development/wingbot-mongodb/src/BaseStorage.js","/Users/david/Development/wingbot-mongodb/src/defaultLogger.js","/Users/david/Development/wingbot-mongodb/src/AttachmentCache.js","/Users/david/Development/wingbot-mongodb/src/AuditLogStorage.js","/Users/david/Development/wingbot-mongodb/src/BotConfigStorage.js","/Users/david/Development/wingbot-mongodb/src/BotTokenStorage.js","/Users/david/Development/wingbot-mongodb/src/tokenFactory.js","/Users/david/Development/wingbot-mongodb/src/ChatLogStorage.js","/Users/david/Development/wingbot-mongodb/src/NotificationsStorage.js","/Users/david/Development/wingbot-mongodb/src/StateStorage.js"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"processes":{"
|
|
1
|
+
{"processes":{"0d879467-0e5f-4098-bea4-73c520af6dcd":{"parent":null,"children":[]}},"files":{"/Users/david/Development/wingbot-mongodb/src/BaseStorage.js":["0d879467-0e5f-4098-bea4-73c520af6dcd"],"/Users/david/Development/wingbot-mongodb/src/defaultLogger.js":["0d879467-0e5f-4098-bea4-73c520af6dcd"],"/Users/david/Development/wingbot-mongodb/src/AttachmentCache.js":["0d879467-0e5f-4098-bea4-73c520af6dcd"],"/Users/david/Development/wingbot-mongodb/src/AuditLogStorage.js":["0d879467-0e5f-4098-bea4-73c520af6dcd"],"/Users/david/Development/wingbot-mongodb/src/BotConfigStorage.js":["0d879467-0e5f-4098-bea4-73c520af6dcd"],"/Users/david/Development/wingbot-mongodb/src/BotTokenStorage.js":["0d879467-0e5f-4098-bea4-73c520af6dcd"],"/Users/david/Development/wingbot-mongodb/src/tokenFactory.js":["0d879467-0e5f-4098-bea4-73c520af6dcd"],"/Users/david/Development/wingbot-mongodb/src/ChatLogStorage.js":["0d879467-0e5f-4098-bea4-73c520af6dcd"],"/Users/david/Development/wingbot-mongodb/src/NotificationsStorage.js":["0d879467-0e5f-4098-bea4-73c520af6dcd"],"/Users/david/Development/wingbot-mongodb/src/StateStorage.js":["0d879467-0e5f-4098-bea4-73c520af6dcd"]},"externalIds":{}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wingbot-mongodb",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "MongoDB storage for wingbot.ai",
|
|
5
5
|
"main": "src/main.js",
|
|
6
6
|
"scripts": {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"test:unit:watch": "npm run test:unit -- --watch",
|
|
10
10
|
"test:cosmos": "cross-env DB_TYPE=cosmos mocha ./test",
|
|
11
11
|
"test:coverage": "nyc --reporter=html mocha ./test && nyc report",
|
|
12
|
-
"test:coverage:threshold": "nyc check-coverage --lines 80 --functions
|
|
12
|
+
"test:coverage:threshold": "nyc check-coverage --lines 80 --functions 78 --branches 75",
|
|
13
13
|
"test:lint": "eslint ./src/**/*.js ./bin/**/*.js ./test/**/*.js ",
|
|
14
14
|
"doc": "node ./bin/makeApiDoc.js"
|
|
15
15
|
},
|
|
@@ -35,17 +35,17 @@
|
|
|
35
35
|
"homepage": "https://github.com/wingbotai/wingbot-mongodb#readme",
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"cross-env": "^7.0.3",
|
|
38
|
-
"eslint": "^
|
|
39
|
-
"eslint-config-airbnb": "^
|
|
40
|
-
"eslint-plugin-import": "^2.
|
|
41
|
-
"eslint-plugin-jsdoc": "^
|
|
42
|
-
"eslint-plugin-jsx-a11y": "^6.
|
|
43
|
-
"eslint-plugin-mocha": "^
|
|
44
|
-
"eslint-plugin-react": "^7.
|
|
38
|
+
"eslint": "^8.28.0",
|
|
39
|
+
"eslint-config-airbnb": "^19.0.4",
|
|
40
|
+
"eslint-plugin-import": "^2.26.0",
|
|
41
|
+
"eslint-plugin-jsdoc": "^39.6.4",
|
|
42
|
+
"eslint-plugin-jsx-a11y": "^6.6.1",
|
|
43
|
+
"eslint-plugin-mocha": "^10.1.0",
|
|
44
|
+
"eslint-plugin-react": "^7.31.11",
|
|
45
45
|
"jsdoc-to-markdown": "^7.1.1",
|
|
46
46
|
"jsdoc-tsimport-plugin": "^1.0.5",
|
|
47
|
-
"mocha": "^
|
|
48
|
-
"mongodb": "^4.
|
|
47
|
+
"mocha": "^10.1.0",
|
|
48
|
+
"mongodb": "^4.12.1",
|
|
49
49
|
"nyc": "^15.1.0",
|
|
50
50
|
"wingbot": "^3.34.0"
|
|
51
51
|
},
|
package/src/AuditLogStorage.js
CHANGED
package/src/BaseStorage.js
CHANGED
|
@@ -84,7 +84,7 @@ class BaseStorage {
|
|
|
84
84
|
|
|
85
85
|
this._fixtures = [];
|
|
86
86
|
|
|
87
|
-
if (isCosmo) {
|
|
87
|
+
if (isCosmo && !process.argv.some((a) => a.endsWith('mocha'))) {
|
|
88
88
|
process.nextTick(() => {
|
|
89
89
|
const hasUniqueIndex = this._indexes.some((i) => i.options.unique);
|
|
90
90
|
|
|
@@ -96,6 +96,10 @@ class BaseStorage {
|
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
+
preHeat () {
|
|
100
|
+
return this._getCollection();
|
|
101
|
+
}
|
|
102
|
+
|
|
99
103
|
/**
|
|
100
104
|
* Insert defalt document to DB
|
|
101
105
|
*
|
|
@@ -238,15 +242,17 @@ class BaseStorage {
|
|
|
238
242
|
if (updated || existing.every((i) => this.systemIndexes.includes(i.name))) {
|
|
239
243
|
// upsert fixtures
|
|
240
244
|
|
|
241
|
-
await this._fixtures.reduce(
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
245
|
+
await this._fixtures.reduce(
|
|
246
|
+
(p, o) => p
|
|
247
|
+
.then(() => collection.insertOne(o))
|
|
248
|
+
.then(() => this._log.log(`DB.${this._collectionName} Inserted fixture doc to "${this._collectionName}"`))
|
|
249
|
+
.catch((e) => {
|
|
250
|
+
if (e.code !== 11000) {
|
|
251
|
+
this._log.error(`DB.${this._collectionName} failed to insert fixture doc to "${this._collectionName}"`, e);
|
|
252
|
+
}
|
|
253
|
+
}),
|
|
254
|
+
Promise.resolve()
|
|
255
|
+
);
|
|
250
256
|
}
|
|
251
257
|
}
|
|
252
258
|
|
package/src/BotConfigStorage.js
CHANGED
|
@@ -60,7 +60,7 @@ class BotConfigStorage {
|
|
|
60
60
|
* @param {Function|string[]} [acl] - acl configuration
|
|
61
61
|
* @returns {{updateBot:Function}}
|
|
62
62
|
*/
|
|
63
|
-
api (onUpdate = () => Promise.resolve(), acl) {
|
|
63
|
+
api (onUpdate = () => Promise.resolve(), acl = undefined) {
|
|
64
64
|
const storage = this;
|
|
65
65
|
return {
|
|
66
66
|
async updateBot (args, ctx) {
|
package/src/BotTokenStorage.js
CHANGED
|
@@ -134,6 +134,7 @@ class BotTokenStorage {
|
|
|
134
134
|
returnDocument: 'after'
|
|
135
135
|
});
|
|
136
136
|
|
|
137
|
+
// @ts-ignore
|
|
137
138
|
res = res.value;
|
|
138
139
|
|
|
139
140
|
// @ts-ignore
|
|
@@ -150,6 +151,7 @@ class BotTokenStorage {
|
|
|
150
151
|
// probably collision, try it again
|
|
151
152
|
await this._wait(400);
|
|
152
153
|
|
|
154
|
+
// @ts-ignore
|
|
153
155
|
res = await c.findOne({ senderId, pageId });
|
|
154
156
|
|
|
155
157
|
if (!res) {
|
|
@@ -166,7 +168,7 @@ class BotTokenStorage {
|
|
|
166
168
|
}
|
|
167
169
|
|
|
168
170
|
_wait (ms) {
|
|
169
|
-
return new Promise((r) => setTimeout(r, ms));
|
|
171
|
+
return new Promise((r) => { setTimeout(r, ms); });
|
|
170
172
|
}
|
|
171
173
|
|
|
172
174
|
}
|
|
@@ -101,6 +101,17 @@ class NotificationsStorage {
|
|
|
101
101
|
* @type {Map<string,Promise<mongodb.Collection>>}
|
|
102
102
|
*/
|
|
103
103
|
this._collections = new Map();
|
|
104
|
+
|
|
105
|
+
if (isCosmo && !process.argv.some((a) => a.endsWith('mocha'))) {
|
|
106
|
+
process.nextTick(() => {
|
|
107
|
+
Promise.all([
|
|
108
|
+
this._getCollection(this.taksCollection),
|
|
109
|
+
this._getCollection(this.campaignsCollection),
|
|
110
|
+
this._getCollection(this.subscribtionsCollection)
|
|
111
|
+
])
|
|
112
|
+
.catch((e) => log.error('DB.<NotificationsStorage> index pre-heat FAILED', e));
|
|
113
|
+
});
|
|
114
|
+
}
|
|
104
115
|
}
|
|
105
116
|
|
|
106
117
|
async _getOrCreateCollection (name) {
|
|
@@ -243,8 +254,7 @@ class NotificationsStorage {
|
|
|
243
254
|
if (i.isTextIndex) {
|
|
244
255
|
this._doesNotSupportTextIndex = true;
|
|
245
256
|
} else {
|
|
246
|
-
this._log.error(`failed to create index ${i.options.name} on ${collection.collectionName}
|
|
247
|
-
throw e;
|
|
257
|
+
this._log.error(`failed to create index ${i.options.name} on ${collection.collectionName}`, e);
|
|
248
258
|
}
|
|
249
259
|
})));
|
|
250
260
|
}
|
package/src/tokenFactory.js
CHANGED
|
@@ -6,10 +6,12 @@ const crypto = require('crypto');
|
|
|
6
6
|
* @returns {Promise.<string>}
|
|
7
7
|
*/
|
|
8
8
|
function tokenFactory () {
|
|
9
|
-
return new Promise((res, rej) =>
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
return new Promise((res, rej) => {
|
|
10
|
+
crypto.randomBytes(
|
|
11
|
+
255,
|
|
12
|
+
(err, buf) => (err ? rej(err) : res(buf.toString('base64')))
|
|
13
|
+
);
|
|
14
|
+
});
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
module.exports = tokenFactory;
|