wingbot-mongodb 3.0.0-alpha.9 → 3.0.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.
@@ -1 +1 @@
1
- {"parent":null,"pid":52036,"argv":["/usr/local/bin/node","/Users/david/Development/wingbot-mongodb/node_modules/.bin/mocha","./test"],"execArgv":[],"cwd":"/Users/david/Development/wingbot-mongodb","time":1655802879208,"ppid":52035,"coverageFilename":"/Users/david/Development/wingbot-mongodb/.nyc_output/38fa2b60-0502-4dbc-9c7f-c478802fb2de.json","externalId":"","uuid":"38fa2b60-0502-4dbc-9c7f-c478802fb2de","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
+ {"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":{"38fa2b60-0502-4dbc-9c7f-c478802fb2de":{"parent":null,"children":[]}},"files":{"/Users/david/Development/wingbot-mongodb/src/BaseStorage.js":["38fa2b60-0502-4dbc-9c7f-c478802fb2de"],"/Users/david/Development/wingbot-mongodb/src/defaultLogger.js":["38fa2b60-0502-4dbc-9c7f-c478802fb2de"],"/Users/david/Development/wingbot-mongodb/src/AttachmentCache.js":["38fa2b60-0502-4dbc-9c7f-c478802fb2de"],"/Users/david/Development/wingbot-mongodb/src/AuditLogStorage.js":["38fa2b60-0502-4dbc-9c7f-c478802fb2de"],"/Users/david/Development/wingbot-mongodb/src/BotConfigStorage.js":["38fa2b60-0502-4dbc-9c7f-c478802fb2de"],"/Users/david/Development/wingbot-mongodb/src/BotTokenStorage.js":["38fa2b60-0502-4dbc-9c7f-c478802fb2de"],"/Users/david/Development/wingbot-mongodb/src/tokenFactory.js":["38fa2b60-0502-4dbc-9c7f-c478802fb2de"],"/Users/david/Development/wingbot-mongodb/src/ChatLogStorage.js":["38fa2b60-0502-4dbc-9c7f-c478802fb2de"],"/Users/david/Development/wingbot-mongodb/src/NotificationsStorage.js":["38fa2b60-0502-4dbc-9c7f-c478802fb2de"],"/Users/david/Development/wingbot-mongodb/src/StateStorage.js":["38fa2b60-0502-4dbc-9c7f-c478802fb2de"]},"externalIds":{}}
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.0.0-alpha.9",
3
+ "version": "3.0.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 79 --branches 75",
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": "^7.2.0",
39
- "eslint-config-airbnb": "^18.2.1",
40
- "eslint-plugin-import": "^2.25.2",
41
- "eslint-plugin-jsdoc": "^37.0.3",
42
- "eslint-plugin-jsx-a11y": "^6.4.1",
43
- "eslint-plugin-mocha": "^9.0.0",
44
- "eslint-plugin-react": "^7.26.1",
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": "^9.2.2",
48
- "mongodb": "^4.7.0",
47
+ "mocha": "^10.1.0",
48
+ "mongodb": "^4.12.1",
49
49
  "nyc": "^15.1.0",
50
50
  "wingbot": "^3.34.0"
51
51
  },
@@ -303,7 +303,7 @@ class AuditLogStorage extends BaseStorage {
303
303
  }
304
304
 
305
305
  _wait (ms) {
306
- return new Promise((r) => setTimeout(r, ms));
306
+ return new Promise((r) => { setTimeout(r, ms); });
307
307
  }
308
308
 
309
309
  async _storeWithRetry (secret, entry, delta = 0, i = 1) {
@@ -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
 
@@ -238,15 +238,17 @@ class BaseStorage {
238
238
  if (updated || existing.every((i) => this.systemIndexes.includes(i.name))) {
239
239
  // upsert fixtures
240
240
 
241
- await this._fixtures.reduce((p, o) => p
242
- .then(() => collection.insertOne(o))
243
- .then(() => this._log.log(`DB.${this._collectionName} Inserted fixture doc to "${this._collectionName}"`))
244
- .catch((e) => {
245
- if (e.code !== 11000) {
246
- this._log.error(`DB.${this._collectionName} failed to insert fixture doc to "${this._collectionName}"`, e);
247
- }
248
- }),
249
- Promise.resolve());
241
+ await this._fixtures.reduce(
242
+ (p, o) => p
243
+ .then(() => collection.insertOne(o))
244
+ .then(() => this._log.log(`DB.${this._collectionName} Inserted fixture doc to "${this._collectionName}"`))
245
+ .catch((e) => {
246
+ if (e.code !== 11000) {
247
+ this._log.error(`DB.${this._collectionName} failed to insert fixture doc to "${this._collectionName}"`, e);
248
+ }
249
+ }),
250
+ Promise.resolve()
251
+ );
250
252
  }
251
253
  }
252
254
 
@@ -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) {
@@ -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
  }
@@ -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) => crypto.randomBytes(
10
- 255,
11
- (err, buf) => (err ? rej(err) : res(buf.toString('base64')))
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;