wingbot-mongodb 2.22.0-alpha.2 → 2.22.0-alpha.5
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/1f0c249b-861d-4ebb-a415-267bb18646dd.json +1 -0
- package/.nyc_output/processinfo/{28ee104d-8ece-4824-bb02-ada068f4d2d3.json → 1f0c249b-861d-4ebb-a415-267bb18646dd.json} +1 -1
- package/.nyc_output/processinfo/index.json +1 -1
- package/package.json +1 -1
- package/src/AuditLogStorage.js +2 -1
- package/src/BaseStorage.js +37 -2
- package/src/ChatLogStorage.js +2 -1
- package/src/NotificationsStorage.js +10 -9
- package/src/StateStorage.js +2 -1
- package/src/defaultLogger.js +19 -0
- package/.nyc_output/28ee104d-8ece-4824-bb02-ada068f4d2d3.json +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"parent":null,"pid":
|
|
1
|
+
{"parent":null,"pid":83585,"argv":["/usr/local/bin/node","/Users/david/Development/wingbot-mongodb/node_modules/.bin/mocha","./test"],"execArgv":[],"cwd":"/Users/david/Development/wingbot-mongodb","time":1650546848107,"ppid":83584,"coverageFilename":"/Users/david/Development/wingbot-mongodb/.nyc_output/1f0c249b-861d-4ebb-a415-267bb18646dd.json","externalId":"","uuid":"1f0c249b-861d-4ebb-a415-267bb18646dd","files":["/Users/david/Development/wingbot-mongodb/src/AttachmentCache.js","/Users/david/Development/wingbot-mongodb/src/AuditLogStorage.js","/Users/david/Development/wingbot-mongodb/src/BaseStorage.js","/Users/david/Development/wingbot-mongodb/src/defaultLogger.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":{"1f0c249b-861d-4ebb-a415-267bb18646dd":{"parent":null,"children":[]}},"files":{"/Users/david/Development/wingbot-mongodb/src/AttachmentCache.js":["1f0c249b-861d-4ebb-a415-267bb18646dd"],"/Users/david/Development/wingbot-mongodb/src/AuditLogStorage.js":["1f0c249b-861d-4ebb-a415-267bb18646dd"],"/Users/david/Development/wingbot-mongodb/src/BaseStorage.js":["1f0c249b-861d-4ebb-a415-267bb18646dd"],"/Users/david/Development/wingbot-mongodb/src/defaultLogger.js":["1f0c249b-861d-4ebb-a415-267bb18646dd"],"/Users/david/Development/wingbot-mongodb/src/BotConfigStorage.js":["1f0c249b-861d-4ebb-a415-267bb18646dd"],"/Users/david/Development/wingbot-mongodb/src/BotTokenStorage.js":["1f0c249b-861d-4ebb-a415-267bb18646dd"],"/Users/david/Development/wingbot-mongodb/src/tokenFactory.js":["1f0c249b-861d-4ebb-a415-267bb18646dd"],"/Users/david/Development/wingbot-mongodb/src/ChatLogStorage.js":["1f0c249b-861d-4ebb-a415-267bb18646dd"],"/Users/david/Development/wingbot-mongodb/src/NotificationsStorage.js":["1f0c249b-861d-4ebb-a415-267bb18646dd"],"/Users/david/Development/wingbot-mongodb/src/StateStorage.js":["1f0c249b-861d-4ebb-a415-267bb18646dd"]},"externalIds":{}}
|
package/package.json
CHANGED
package/src/AuditLogStorage.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
const jsonwebtoken = require('jsonwebtoken');
|
|
7
7
|
const BaseStorage = require('./BaseStorage');
|
|
8
|
+
const defaultLogger = require('./defaultLogger');
|
|
8
9
|
|
|
9
10
|
const LEVEL_CRITICAL = 'Critical';
|
|
10
11
|
const LEVEL_IMPORTANT = 'Important';
|
|
@@ -106,7 +107,7 @@ class AuditLogStorage extends BaseStorage {
|
|
|
106
107
|
* @param {string|Promise<string>} [secret]
|
|
107
108
|
* @param {string|Promise<string>} [jwtVerifier]
|
|
108
109
|
*/
|
|
109
|
-
constructor (mongoDb, collectionName = 'auditlog', log =
|
|
110
|
+
constructor (mongoDb, collectionName = 'auditlog', log = defaultLogger, isCosmo = false, secret = null, jwtVerifier = null) {
|
|
110
111
|
super(mongoDb, collectionName, log, isCosmo);
|
|
111
112
|
|
|
112
113
|
this.addIndex({
|
package/src/BaseStorage.js
CHANGED
|
@@ -3,8 +3,9 @@
|
|
|
3
3
|
*/
|
|
4
4
|
'use strict';
|
|
5
5
|
|
|
6
|
-
const
|
|
6
|
+
const { ObjectId } = require('mongodb');
|
|
7
7
|
const crypto = require('crypto');
|
|
8
|
+
const defaultLogger = require('./defaultLogger');
|
|
8
9
|
|
|
9
10
|
/** @typedef {import('mongodb').Db} Db */
|
|
10
11
|
/** @typedef {import('mongodb').Collection} Collection */
|
|
@@ -43,7 +44,7 @@ class BaseStorage {
|
|
|
43
44
|
*
|
|
44
45
|
* }
|
|
45
46
|
*/
|
|
46
|
-
constructor (mongoDb, collectionName, log =
|
|
47
|
+
constructor (mongoDb, collectionName, log = defaultLogger, isCosmo = false) {
|
|
47
48
|
this._mongoDb = mongoDb;
|
|
48
49
|
this._collectionName = collectionName;
|
|
49
50
|
this._isCosmo = isCosmo;
|
|
@@ -89,6 +90,40 @@ class BaseStorage {
|
|
|
89
90
|
});
|
|
90
91
|
}
|
|
91
92
|
|
|
93
|
+
/**
|
|
94
|
+
* @example
|
|
95
|
+
* {
|
|
96
|
+
* _id: ObjectId.isValid(id) ? new ObjectId(input) : input
|
|
97
|
+
* }
|
|
98
|
+
*
|
|
99
|
+
* @protected
|
|
100
|
+
* @param {string} id
|
|
101
|
+
* @returns {string|ObjectId}
|
|
102
|
+
*/
|
|
103
|
+
_id (id) {
|
|
104
|
+
return ObjectId.isValid(id) && `${id}`.length === 24
|
|
105
|
+
? new ObjectId(id)
|
|
106
|
+
: id;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
*
|
|
111
|
+
* @protected
|
|
112
|
+
* @param {string} attr
|
|
113
|
+
* @param {{[key: string]: any}} obj
|
|
114
|
+
* @returns {{[key: string]: any}}
|
|
115
|
+
*/
|
|
116
|
+
_expandObjectToSet (attr, obj) {
|
|
117
|
+
const keys = Object.keys(obj);
|
|
118
|
+
if (keys.length === 0) {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
return keys
|
|
122
|
+
.reduce((o, key) => Object.assign(o, {
|
|
123
|
+
[`${attr}.${key}`]: obj[key]
|
|
124
|
+
}), {});
|
|
125
|
+
}
|
|
126
|
+
|
|
92
127
|
async _getOrCreateCollection (name) {
|
|
93
128
|
const db = typeof this._mongoDb === 'function'
|
|
94
129
|
? await this._mongoDb()
|
package/src/ChatLogStorage.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
'use strict';
|
|
5
5
|
|
|
6
6
|
const BaseStorage = require('./BaseStorage');
|
|
7
|
+
const defaultLogger = require('./defaultLogger');
|
|
7
8
|
|
|
8
9
|
const PAGE_SENDER_TIMESTAMP = 'pageId_1_senderId_1_timestamp_-1';
|
|
9
10
|
const TIMESTAMP = 'timestamp_1';
|
|
@@ -25,7 +26,7 @@ class ChatLogStorage extends BaseStorage {
|
|
|
25
26
|
* @param {boolean} [isCosmo]
|
|
26
27
|
* @param {string|Promise<string>} [secret]
|
|
27
28
|
*/
|
|
28
|
-
constructor (mongoDb, collectionName = 'chatlogs', log =
|
|
29
|
+
constructor (mongoDb, collectionName = 'chatlogs', log = defaultLogger, isCosmo = false, secret = null) {
|
|
29
30
|
super(mongoDb, collectionName, log, isCosmo);
|
|
30
31
|
|
|
31
32
|
this.addIndex({
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
'use strict';
|
|
5
5
|
|
|
6
6
|
const mongodb = require('mongodb');
|
|
7
|
+
const defaultLogger = require('./defaultLogger');
|
|
7
8
|
|
|
8
|
-
const {
|
|
9
|
+
const { ObjectId } = mongodb;
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* @typedef Target {Object}
|
|
@@ -84,7 +85,7 @@ class NotificationsStorage {
|
|
|
84
85
|
* @param {{error:Function,log:Function}} [log] - console like logger
|
|
85
86
|
* @param {boolean} isCosmo
|
|
86
87
|
*/
|
|
87
|
-
constructor (mongoDb, collectionsPrefix = '', log =
|
|
88
|
+
constructor (mongoDb, collectionsPrefix = '', log = defaultLogger, isCosmo = false) {
|
|
88
89
|
this._mongoDb = mongoDb;
|
|
89
90
|
|
|
90
91
|
this.taksCollection = `${collectionsPrefix}notification-tasks`;
|
|
@@ -452,8 +453,8 @@ class NotificationsStorage {
|
|
|
452
453
|
const c = await this._getCollection(this.taksCollection);
|
|
453
454
|
|
|
454
455
|
const res = await c.findOne({
|
|
455
|
-
_id:
|
|
456
|
-
?
|
|
456
|
+
_id: ObjectId.isValid(taskId)
|
|
457
|
+
? ObjectId.createFromHexString(taskId)
|
|
457
458
|
: taskId
|
|
458
459
|
});
|
|
459
460
|
|
|
@@ -469,8 +470,8 @@ class NotificationsStorage {
|
|
|
469
470
|
const c = await this._getCollection(this.taksCollection);
|
|
470
471
|
|
|
471
472
|
const res = await c.findOneAndUpdate({
|
|
472
|
-
_id:
|
|
473
|
-
?
|
|
473
|
+
_id: ObjectId.isValid(taskId)
|
|
474
|
+
? ObjectId.createFromHexString(taskId)
|
|
474
475
|
: taskId
|
|
475
476
|
}, {
|
|
476
477
|
$set: data
|
|
@@ -606,7 +607,7 @@ class NotificationsStorage {
|
|
|
606
607
|
});
|
|
607
608
|
ret = this._mapCampaign(res.value);
|
|
608
609
|
} else {
|
|
609
|
-
const id = new
|
|
610
|
+
const id = new ObjectId();
|
|
610
611
|
ret = { id: id.toHexString(), _id: id, ...campaign };
|
|
611
612
|
if (updateCampaign) {
|
|
612
613
|
Object.assign(ret, updateCampaign);
|
|
@@ -739,7 +740,7 @@ class NotificationsStorage {
|
|
|
739
740
|
useCondition = {
|
|
740
741
|
...useCondition,
|
|
741
742
|
_id: {
|
|
742
|
-
$lt:
|
|
743
|
+
$lt: ObjectId.createFromHexString(key._id)
|
|
743
744
|
}
|
|
744
745
|
};
|
|
745
746
|
}
|
|
@@ -898,7 +899,7 @@ class NotificationsStorage {
|
|
|
898
899
|
condition = {
|
|
899
900
|
...condition,
|
|
900
901
|
_id: {
|
|
901
|
-
$gt:
|
|
902
|
+
$gt: ObjectId.createFromHexString(key._id)
|
|
902
903
|
}
|
|
903
904
|
};
|
|
904
905
|
}
|
package/src/StateStorage.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
'use strict';
|
|
5
5
|
|
|
6
6
|
const BaseStorage = require('./BaseStorage');
|
|
7
|
+
const defaultLogger = require('./defaultLogger');
|
|
7
8
|
|
|
8
9
|
const USER_INDEX = 'senderId_1_pageId_1';
|
|
9
10
|
const LAST_INTERACTION_INDEX = 'lastInteraction_1';
|
|
@@ -37,7 +38,7 @@ class StateStorage extends BaseStorage {
|
|
|
37
38
|
* @param {{error:Function,log:Function}} [log] - console like logger
|
|
38
39
|
* @param {boolean} isCosmo
|
|
39
40
|
*/
|
|
40
|
-
constructor (mongoDb, collectionName = 'states', log =
|
|
41
|
+
constructor (mongoDb, collectionName = 'states', log = defaultLogger, isCosmo = false) {
|
|
41
42
|
super(mongoDb, collectionName, log, isCosmo);
|
|
42
43
|
|
|
43
44
|
this.addIndex(
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @author {David Menger}
|
|
3
|
+
*/
|
|
4
|
+
'use strict';
|
|
5
|
+
|
|
6
|
+
function log (...args) {
|
|
7
|
+
const mapped = args.map((a) => (typeof a === 'string' ? a : JSON.stringify(a, null, 2)));
|
|
8
|
+
process.stderr.write(` + ${mapped.join(' ')}\n`);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const defaultLogger = {
|
|
12
|
+
log,
|
|
13
|
+
error: (...args) => log('ERROR:', ...args),
|
|
14
|
+
info: log,
|
|
15
|
+
warn: (...args) => log('WARN:', ...args),
|
|
16
|
+
debug: log
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
module.exports = defaultLogger;
|