wingbot-mongodb 2.21.0 → 2.21.3-beta.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.
@@ -1 +1 @@
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":{}}
1
+ {"processes":{"8cd701fd-7d02-4d21-90bc-0f9eafe331ec":{"parent":null,"children":[]}},"files":{"/Users/david/Development/wingbot-mongodb/src/AttachmentCache.js":["8cd701fd-7d02-4d21-90bc-0f9eafe331ec"],"/Users/david/Development/wingbot-mongodb/src/AuditLogStorage.js":["8cd701fd-7d02-4d21-90bc-0f9eafe331ec"],"/Users/david/Development/wingbot-mongodb/src/BaseStorage.js":["8cd701fd-7d02-4d21-90bc-0f9eafe331ec"],"/Users/david/Development/wingbot-mongodb/src/BotConfigStorage.js":["8cd701fd-7d02-4d21-90bc-0f9eafe331ec"],"/Users/david/Development/wingbot-mongodb/src/BotTokenStorage.js":["8cd701fd-7d02-4d21-90bc-0f9eafe331ec"],"/Users/david/Development/wingbot-mongodb/src/tokenFactory.js":["8cd701fd-7d02-4d21-90bc-0f9eafe331ec"],"/Users/david/Development/wingbot-mongodb/src/ChatLogStorage.js":["8cd701fd-7d02-4d21-90bc-0f9eafe331ec"],"/Users/david/Development/wingbot-mongodb/src/NotificationsStorage.js":["8cd701fd-7d02-4d21-90bc-0f9eafe331ec"],"/Users/david/Development/wingbot-mongodb/src/StateStorage.js":["8cd701fd-7d02-4d21-90bc-0f9eafe331ec"]},"externalIds":{}}
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "wingbot-mongodb",
3
- "version": "2.21.0",
3
+ "version": "2.21.3-beta.1",
4
4
  "description": "MongoDB storage for wingbot.ai",
5
5
  "main": "src/main.js",
6
6
  "scripts": {
7
7
  "test": "npm run test:lint && npm run test:coverage && npm run test:coverage:threshold",
8
- "test:unit": "mocha ./test/**/*.test.js",
8
+ "test:unit": "mocha ./test/**/*.js",
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",
@@ -774,10 +774,11 @@ class NotificationsStorage {
774
774
  * @param {string|string[]} senderId
775
775
  * @param {string} pageId
776
776
  * @param {string} tag
777
- * @param {boolean} [upsert]
777
+ * @param {boolean} [onlyToKnown]
778
778
  * @returns {Promise}
779
779
  */
780
- async subscribe (senderId, pageId, tag, upsert = true) {
780
+ async subscribe (senderId, pageId, tag, onlyToKnown) {
781
+ // !IMPORTANT: do not add a default value to the fourth parameter!
781
782
  const senderIds = Array.isArray(senderId) ? senderId : [senderId];
782
783
 
783
784
  if (senderIds.length === 0) {
@@ -790,9 +791,15 @@ class NotificationsStorage {
790
791
  updateOne: {
791
792
  filter: { senderId: sid, pageId },
792
793
  update: { $addToSet: { subs: tag } },
793
- upsert
794
+ upsert: !onlyToKnown
794
795
  }
795
- }))
796
+ })),
797
+ {
798
+ ordered: false,
799
+ writeConcern: {
800
+ w: onlyToKnown ? 0 : 1
801
+ }
802
+ }
796
803
  );
797
804
  }
798
805
 
@@ -9,6 +9,7 @@ const BaseStorage = require('./BaseStorage');
9
9
  const USER_INDEX = 'senderId_1_pageId_1';
10
10
  const LAST_INTERACTION_INDEX = 'lastInteraction_1';
11
11
  const SEARCH = 'search-text';
12
+ const NAME = 'name_1';
12
13
 
13
14
  /**
14
15
  * @typedef {object} State
@@ -48,7 +49,12 @@ class StateStorage extends BaseStorage {
48
49
  { name: LAST_INTERACTION_INDEX }
49
50
  );
50
51
 
51
- if (!isCosmo) {
52
+ if (isCosmo) {
53
+ this.addIndex(
54
+ { name: 1 },
55
+ { name: NAME }
56
+ );
57
+ } else {
52
58
  this.addIndex(
53
59
  { '$**': 'text' },
54
60
  { name: SEARCH }
@@ -156,8 +162,12 @@ class StateStorage extends BaseStorage {
156
162
 
157
163
  if (searchStates) {
158
164
  if (this._isCosmo) {
165
+ const $regex = `^${condition.search}`.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
159
166
  Object.assign(useCondition, {
160
- name: { $regex: condition.search, $options: 'i' }
167
+ $or: [
168
+ { senderId: { $regex } },
169
+ { name: { $regex } }
170
+ ]
161
171
  });
162
172
  } else {
163
173
  Object.assign(useCondition, {