wingbot-mongodb 2.20.1 → 2.21.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/.nyc_output/{f60575da-064f-476a-a3be-be7e864d586d.json → 32821199-22af-42bd-8e0d-c255510f3efa.json} +1 -1
- package/.nyc_output/processinfo/{f60575da-064f-476a-a3be-be7e864d586d.json → 32821199-22af-42bd-8e0d-c255510f3efa.json} +1 -1
- package/.nyc_output/processinfo/index.json +1 -1
- package/package.json +4 -4
- package/src/BaseStorage.js +24 -0
- package/src/NotificationsStorage.js +17 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"parent":null,"pid":
|
|
1
|
+
{"parent":null,"pid":53887,"argv":["/usr/local/bin/node","/Users/david/Downloads/wingbot-mongodb/node_modules/.bin/mocha","./test"],"execArgv":[],"cwd":"/Users/david/Downloads/wingbot-mongodb","time":1647606468681,"ppid":53884,"coverageFilename":"/Users/david/Downloads/wingbot-mongodb/.nyc_output/32821199-22af-42bd-8e0d-c255510f3efa.json","externalId":"","uuid":"32821199-22af-42bd-8e0d-c255510f3efa","files":["/Users/david/Downloads/wingbot-mongodb/src/AttachmentCache.js","/Users/david/Downloads/wingbot-mongodb/src/AuditLogStorage.js","/Users/david/Downloads/wingbot-mongodb/src/BaseStorage.js","/Users/david/Downloads/wingbot-mongodb/src/BotConfigStorage.js","/Users/david/Downloads/wingbot-mongodb/src/BotTokenStorage.js","/Users/david/Downloads/wingbot-mongodb/src/tokenFactory.js","/Users/david/Downloads/wingbot-mongodb/src/ChatLogStorage.js","/Users/david/Downloads/wingbot-mongodb/src/NotificationsStorage.js","/Users/david/Downloads/wingbot-mongodb/src/StateStorage.js"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"processes":{"
|
|
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":{}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wingbot-mongodb",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.21.0",
|
|
4
4
|
"description": "MongoDB storage for wingbot.ai",
|
|
5
5
|
"main": "src/main.js",
|
|
6
6
|
"scripts": {
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
"eslint-plugin-jsx-a11y": "^6.4.1",
|
|
43
43
|
"eslint-plugin-mocha": "^9.0.0",
|
|
44
44
|
"eslint-plugin-react": "^7.26.1",
|
|
45
|
-
"jsdoc-to-markdown": "^7.1.
|
|
45
|
+
"jsdoc-to-markdown": "^7.1.1",
|
|
46
46
|
"jsdoc-tsimport-plugin": "^1.0.5",
|
|
47
|
-
"mocha": "^9.
|
|
47
|
+
"mocha": "^9.2.2",
|
|
48
48
|
"mongodb": "^3.7.3",
|
|
49
49
|
"nyc": "^15.1.0",
|
|
50
|
-
"wingbot": "^3.
|
|
50
|
+
"wingbot": "^3.30.0"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"mongodb": "^3.0.0"
|
package/src/BaseStorage.js
CHANGED
|
@@ -122,6 +122,7 @@ class BaseStorage {
|
|
|
122
122
|
/**
|
|
123
123
|
* Returns the collection to operate with
|
|
124
124
|
*
|
|
125
|
+
* @protected
|
|
125
126
|
* @returns {Promise<Collection>}
|
|
126
127
|
*/
|
|
127
128
|
async _getCollection () {
|
|
@@ -186,6 +187,13 @@ class BaseStorage {
|
|
|
186
187
|
}
|
|
187
188
|
}
|
|
188
189
|
|
|
190
|
+
/**
|
|
191
|
+
*
|
|
192
|
+
* @template T
|
|
193
|
+
* @protected
|
|
194
|
+
* @param {T} object
|
|
195
|
+
* @returns {Promise<T>}
|
|
196
|
+
*/
|
|
189
197
|
async _sign (object) {
|
|
190
198
|
if (!this._secret) {
|
|
191
199
|
return object;
|
|
@@ -199,12 +207,20 @@ class BaseStorage {
|
|
|
199
207
|
});
|
|
200
208
|
}
|
|
201
209
|
|
|
210
|
+
/**
|
|
211
|
+
*
|
|
212
|
+
* @private
|
|
213
|
+
* @template T
|
|
214
|
+
* @param {T} object
|
|
215
|
+
* @returns {T}
|
|
216
|
+
*/
|
|
202
217
|
_objectToSign (object) {
|
|
203
218
|
const entries = Object.keys(object)
|
|
204
219
|
.filter((key) => !this.ignoredSignatureKeys.includes(key));
|
|
205
220
|
|
|
206
221
|
entries.sort();
|
|
207
222
|
|
|
223
|
+
// @ts-ignore
|
|
208
224
|
return entries.reduce((o, key) => {
|
|
209
225
|
let val = object[key];
|
|
210
226
|
if (val instanceof Date) {
|
|
@@ -214,6 +230,14 @@ class BaseStorage {
|
|
|
214
230
|
}, {});
|
|
215
231
|
}
|
|
216
232
|
|
|
233
|
+
/**
|
|
234
|
+
*
|
|
235
|
+
* @template T
|
|
236
|
+
* @param {T} objToSign
|
|
237
|
+
* @param {string} secret
|
|
238
|
+
* @param {string} [previous]
|
|
239
|
+
* @returns {string}
|
|
240
|
+
*/
|
|
217
241
|
_signWithSecret (objToSign, secret, previous = null) {
|
|
218
242
|
const h = crypto.createHmac('sha3-224', secret)
|
|
219
243
|
.update(JSON.stringify(objToSign));
|
|
@@ -771,21 +771,29 @@ class NotificationsStorage {
|
|
|
771
771
|
|
|
772
772
|
/**
|
|
773
773
|
*
|
|
774
|
-
* @param {string} senderId
|
|
774
|
+
* @param {string|string[]} senderId
|
|
775
775
|
* @param {string} pageId
|
|
776
776
|
* @param {string} tag
|
|
777
|
+
* @param {boolean} [upsert]
|
|
777
778
|
* @returns {Promise}
|
|
778
779
|
*/
|
|
779
|
-
async subscribe (senderId, pageId, tag) {
|
|
780
|
+
async subscribe (senderId, pageId, tag, upsert = true) {
|
|
781
|
+
const senderIds = Array.isArray(senderId) ? senderId : [senderId];
|
|
782
|
+
|
|
783
|
+
if (senderIds.length === 0) {
|
|
784
|
+
return;
|
|
785
|
+
}
|
|
780
786
|
const c = await this._getCollection(this.subscribtionsCollection);
|
|
781
787
|
|
|
782
|
-
await c.
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
788
|
+
await c.bulkWrite(
|
|
789
|
+
senderIds.map((sid) => ({
|
|
790
|
+
updateOne: {
|
|
791
|
+
filter: { senderId: sid, pageId },
|
|
792
|
+
update: { $addToSet: { subs: tag } },
|
|
793
|
+
upsert
|
|
794
|
+
}
|
|
795
|
+
}))
|
|
796
|
+
);
|
|
789
797
|
}
|
|
790
798
|
|
|
791
799
|
/**
|