@bluedot-innovation/models 7.0.2 → 7.0.4
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/CHANGELOG.md +5 -4
- package/__tests__/geofeature/circle/circle.spec.js +12 -0
- package/__tests__/project/project.data.json +18 -1
- package/__tests__/project/project.remote.config.json +1 -1
- package/__tests__/project/project.spec.js +21 -2
- package/__tests__/zone/zone.spec.js +73 -0
- package/helpers.js +29 -1
- package/models/Zone.js +16 -0
- package/models/geofeatures/Circle.js +11 -1
- package/package.json +1 -1
- package/schemas/ProjectTempo.js +11 -0
- package/schemas/Webhook.js +2 -1
- package/schemas/ZoneTempo.js +15 -0
- package/utils/DbInitialiser/indexInitialiser.js +12 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
## 7.0.
|
|
2
|
-
-
|
|
3
|
-
- Removed tempo destinationId for post doorbell migration deployment
|
|
4
|
-
- Removed geoTrigger type from webhooks
|
|
1
|
+
## 7.0.4
|
|
2
|
+
- Re-added Circle radius to be > 5m
|
|
5
3
|
|
|
6
4
|
## 7.0.1
|
|
7
5
|
- Added tempo webhooks array back for migration
|
|
@@ -13,6 +11,9 @@
|
|
|
13
11
|
- BREAKING CHANGE - Moved zone destinationId to object root and removed tempo object from zone
|
|
14
12
|
- Added 'doorbell' type to project webhooks
|
|
15
13
|
|
|
14
|
+
## 6.2.12
|
|
15
|
+
- Re-added Circle radius to be > 5m
|
|
16
|
+
|
|
16
17
|
## 6.2.11
|
|
17
18
|
- Replace `isAsync` validators with Mongoose 5.x validators
|
|
18
19
|
|
|
@@ -51,6 +51,18 @@ testCase('Circle', () => {
|
|
|
51
51
|
})
|
|
52
52
|
|
|
53
53
|
testCase('Invalid Circle', () => {
|
|
54
|
+
// BD2571
|
|
55
|
+
assertions('should not validate a Circle with radius <5 meters', (done) => {
|
|
56
|
+
circle.radius = 3
|
|
57
|
+
let Circle = new CircleModelBuiltInMongoose(circle)
|
|
58
|
+
Circle.validate((err, res) => {
|
|
59
|
+
assert.exists(err)
|
|
60
|
+
assert.isObject(err.errors)
|
|
61
|
+
assert.strictEqual(err.errors.radius.message, `radius [3m] must be greater than 5m`)
|
|
62
|
+
done()
|
|
63
|
+
})
|
|
64
|
+
})
|
|
65
|
+
|
|
54
66
|
assertions('should not validate a Circle with no radius', (done) => {
|
|
55
67
|
delete circle.radius
|
|
56
68
|
let Circle = new CircleModel(circle)
|
|
@@ -6,6 +6,13 @@
|
|
|
6
6
|
"name": "A New Project",
|
|
7
7
|
"accountId":"b0824b76-ce73-4fcf-81f8-1b63edb1114e",
|
|
8
8
|
"webhooks": [
|
|
9
|
+
{
|
|
10
|
+
"type": "geoTrigger",
|
|
11
|
+
"url": "https://webhooklistener.bluedotinnovation.com",
|
|
12
|
+
"headers" : {
|
|
13
|
+
"securityToken" : "value"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
9
16
|
{
|
|
10
17
|
"type": "tempo",
|
|
11
18
|
"url": "https://webhooklistener.bluedotinnovation.com",
|
|
@@ -40,6 +47,16 @@
|
|
|
40
47
|
}
|
|
41
48
|
},
|
|
42
49
|
"tempo": {
|
|
43
|
-
"isochroneBracketInterval": [60, 120, 300]
|
|
50
|
+
"isochroneBracketInterval": [60, 120, 300],
|
|
51
|
+
"webhooks": [
|
|
52
|
+
{
|
|
53
|
+
"type": "tempo",
|
|
54
|
+
"url": "https://webhooklistener.bluedotinnovation.com",
|
|
55
|
+
"headers" : {
|
|
56
|
+
"securityToken" : "value"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
]
|
|
60
|
+
|
|
44
61
|
}
|
|
45
62
|
}
|
|
@@ -91,7 +91,8 @@ testCase('Project', () => {
|
|
|
91
91
|
})
|
|
92
92
|
})
|
|
93
93
|
|
|
94
|
-
|
|
94
|
+
// TODO: Remove trigger type after migration
|
|
95
|
+
assertions(`should not validate if one of webhooks have a type other than 'geoTrigger', 'tempo', 'doorbell' or 'trigger'`, (done) => {
|
|
95
96
|
project.webhooks.push({
|
|
96
97
|
"type": "sandwich",
|
|
97
98
|
"url": "https://webhooklistener.bluedotinnovation.com",
|
|
@@ -279,7 +280,8 @@ testCase('Project', () => {
|
|
|
279
280
|
})
|
|
280
281
|
|
|
281
282
|
testCase('should not validate if webhooks contains two webhooks of the same type', () => {
|
|
282
|
-
|
|
283
|
+
// TODO: Remove trigger type after migration
|
|
284
|
+
const webhookTypes = ['geoTrigger', 'tempo', 'doorbell', 'trigger']
|
|
283
285
|
|
|
284
286
|
webhookTypes.map(webhookType => {
|
|
285
287
|
assertions(`should not validate if there are duplicate ${webhookType} webhooks`, (done) => {
|
|
@@ -301,6 +303,23 @@ testCase('Project', () => {
|
|
|
301
303
|
})
|
|
302
304
|
})
|
|
303
305
|
|
|
306
|
+
// TODO: Remove this test after migration
|
|
307
|
+
assertions(`should not validate if one of tempo webhooks have a type other than 'tempo'`, (done) => {
|
|
308
|
+
project.tempo.webhooks.push({
|
|
309
|
+
"type": "trigger",
|
|
310
|
+
"url": "https://webhooklistener.bluedotinnovation.com",
|
|
311
|
+
"headers" : {
|
|
312
|
+
"securityToken" : "value"
|
|
313
|
+
}
|
|
314
|
+
})
|
|
315
|
+
let Project = new ProjectModel(project)
|
|
316
|
+
Project.validate((err, res) => {
|
|
317
|
+
assert.exists(err)
|
|
318
|
+
assert.match(err.message, /tempo.webhooks should contain tempo webhooks only/)
|
|
319
|
+
done()
|
|
320
|
+
})
|
|
321
|
+
})
|
|
322
|
+
|
|
304
323
|
|
|
305
324
|
describe('should throw an error when any of the values of the array contains a falsy value', () => {
|
|
306
325
|
let arrayTypeFields = rules.arrayTypeFields
|
|
@@ -450,4 +450,77 @@ describe('Zone', () => {
|
|
|
450
450
|
})
|
|
451
451
|
})
|
|
452
452
|
})
|
|
453
|
+
|
|
454
|
+
// TODO: Remove all tests in below describe block after migration
|
|
455
|
+
describe("tempo.destinationId tests", () => {
|
|
456
|
+
it('should save without errors when tempo.destinationId is null', (done) => {
|
|
457
|
+
zone.tempo = {
|
|
458
|
+
destinationId: null
|
|
459
|
+
}
|
|
460
|
+
let Zone = new ZoneModel(zone)
|
|
461
|
+
Zone.validate((err, res) => {
|
|
462
|
+
assert.notExists(res)
|
|
463
|
+
assert.notExists(err)
|
|
464
|
+
done()
|
|
465
|
+
})
|
|
466
|
+
})
|
|
467
|
+
|
|
468
|
+
const validTempoGeofeatureTypes = ['boundingBox', 'circle', 'polygon']
|
|
469
|
+
|
|
470
|
+
validTempoGeofeatureTypes.map(type => {
|
|
471
|
+
it(`should save without errors when tempo.destinationId is set and there is a single ${type} geofeature`, (done) => {
|
|
472
|
+
zone.tempo = {
|
|
473
|
+
"destinationId": "test-destination-id"
|
|
474
|
+
}
|
|
475
|
+
zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(new RegExp(type)))
|
|
476
|
+
let Zone = new ZoneModel(zone)
|
|
477
|
+
Zone.validate((err, res) => {
|
|
478
|
+
assert.notExists(res)
|
|
479
|
+
assert.notExists(err)
|
|
480
|
+
done()
|
|
481
|
+
})
|
|
482
|
+
})
|
|
483
|
+
})
|
|
484
|
+
|
|
485
|
+
it('should throw an error when tempo.destinationId is longer than 128 characters', (done) => {
|
|
486
|
+
zone.tempo = {
|
|
487
|
+
"destinationId": 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry standard dummy text ever since the 1500s'
|
|
488
|
+
}
|
|
489
|
+
let Zone = new ZoneModel(zone)
|
|
490
|
+
Zone.validate((err, res) => {
|
|
491
|
+
assert.exists(err, 'err object should exist')
|
|
492
|
+
assert.match(err.message, /(destinationId must be less than 129 characters long)/i)
|
|
493
|
+
done()
|
|
494
|
+
})
|
|
495
|
+
})
|
|
496
|
+
|
|
497
|
+
const invalidTempoGeofeatures = ['geoline', 'beacon']
|
|
498
|
+
|
|
499
|
+
invalidTempoGeofeatures.map(type => {
|
|
500
|
+
it(`should throw an error when tempo.destinationId is set and there is a single ${type} geofeature`, (done) => {
|
|
501
|
+
zone.tempo = {
|
|
502
|
+
"destinationId": "test-destination-id"
|
|
503
|
+
}
|
|
504
|
+
zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(new RegExp(type)))
|
|
505
|
+
let Zone = new ZoneModel(zone)
|
|
506
|
+
Zone.validate((err, res) => {
|
|
507
|
+
assert.exists(err, 'err object should exist')
|
|
508
|
+
assert.match(err.message, /(destinationId cannot be set on zones with a geoline or beacon)/i)
|
|
509
|
+
done()
|
|
510
|
+
})
|
|
511
|
+
})
|
|
512
|
+
})
|
|
513
|
+
|
|
514
|
+
it('should throw an error when tempo.destinationId is set and there is more than one geofeature', (done) => {
|
|
515
|
+
zone.tempo = {
|
|
516
|
+
"destinationId": "test-destination-id"
|
|
517
|
+
}
|
|
518
|
+
let Zone = new ZoneModel(zone)
|
|
519
|
+
Zone.validate((err, res) => {
|
|
520
|
+
assert.exists(err, 'err object should exist')
|
|
521
|
+
assert.match(err.message, /(destinationId can only be set on zones with a single geofeature)/i)
|
|
522
|
+
done()
|
|
523
|
+
})
|
|
524
|
+
})
|
|
525
|
+
})
|
|
453
526
|
})
|
package/helpers.js
CHANGED
|
@@ -267,7 +267,8 @@ helpers.validateDestinationIdGeofeatureType = function(destinationId) {
|
|
|
267
267
|
}
|
|
268
268
|
|
|
269
269
|
helpers.validateNoDuplicateWebhookTypes = function(webhookArray) {
|
|
270
|
-
|
|
270
|
+
// TODO: Remove trigger type after migration
|
|
271
|
+
const webhookTypes = ['geoTrigger', 'tempo', 'doorbell', 'trigger']
|
|
271
272
|
const webhookCounts = {};
|
|
272
273
|
webhookTypes.forEach(webhookType => webhookCounts[webhookType] = 0);
|
|
273
274
|
let duplicateFound = false
|
|
@@ -280,5 +281,32 @@ helpers.validateNoDuplicateWebhookTypes = function(webhookArray) {
|
|
|
280
281
|
return !duplicateFound;
|
|
281
282
|
}
|
|
282
283
|
|
|
284
|
+
// TODO: Remove below three methods after migration
|
|
285
|
+
helpers.validateTempoWebhooks = function(webhooks) {
|
|
286
|
+
const notTempo = webhooks.some(webhook => {
|
|
287
|
+
return webhook.type && webhook.type != 'tempo'
|
|
288
|
+
})
|
|
289
|
+
return !notTempo
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
helpers.validateTempoDestinationSingleGeofeature = function(destinationId) {
|
|
293
|
+
if(destinationId){
|
|
294
|
+
const geofeatures = this.ownerDocument().geofeatures
|
|
295
|
+
if(!geofeatures.length){
|
|
296
|
+
return false
|
|
297
|
+
}
|
|
298
|
+
return geofeatures.length === 1
|
|
299
|
+
}
|
|
300
|
+
return true
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
helpers.validateTempoDestinationIdGeofeatureType = function(destinationId) {
|
|
304
|
+
const geofeatures = this.ownerDocument().geofeatures
|
|
305
|
+
if(destinationId && geofeatures.length){
|
|
306
|
+
return !(geofeatures[0].type === 'geoline' || geofeatures[0].type === 'beacon')
|
|
307
|
+
}
|
|
308
|
+
return true
|
|
309
|
+
}
|
|
310
|
+
|
|
283
311
|
|
|
284
312
|
module.exports = helpers
|
package/models/Zone.js
CHANGED
|
@@ -22,6 +22,8 @@ let travelDirectionRawSchema = require('./conditions/TravelDirection').rawSchema
|
|
|
22
22
|
let travelPathRawSchema = require('./conditions/TravelPath').rawSchema
|
|
23
23
|
let timeActiveRawSchema = require('./conditions/TimeActive').rawSchema
|
|
24
24
|
|
|
25
|
+
let zoneTempoSchema = require('../schemas/ZoneTempo')
|
|
26
|
+
|
|
25
27
|
let uuidv4 = require('uuid/v4')
|
|
26
28
|
let patcher = require('@bluedot-innovation/mongoose-json-patch')
|
|
27
29
|
let helpers = require('../helpers')
|
|
@@ -123,6 +125,8 @@ let zoneSchema = new Schema({
|
|
|
123
125
|
{ validator: helpers.validateDestinationSingleGeofeature, msg: 'destinationId can only be set on zones with a single geofeature' },
|
|
124
126
|
{ validator: helpers.validateDestinationIdGeofeatureType, msg: 'destinationId cannot be set on zones with a geoline or beacon' }
|
|
125
127
|
]},
|
|
128
|
+
// TODO: Remove tempo object after migration
|
|
129
|
+
tempo: zoneTempoSchema
|
|
126
130
|
}, {collection: 'zone', autoIndex: false})
|
|
127
131
|
|
|
128
132
|
zoneSchema.index(
|
|
@@ -136,6 +140,18 @@ zoneSchema.index(
|
|
|
136
140
|
name: "destinationUniqueWithinProject"
|
|
137
141
|
})
|
|
138
142
|
|
|
143
|
+
// TODO: Remove below index after migration
|
|
144
|
+
zoneSchema.index(
|
|
145
|
+
{
|
|
146
|
+
projectId: 1,
|
|
147
|
+
'tempo.destinationId': 1
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
unique: true,
|
|
151
|
+
partialFilterExpression: { 'tempo.destinationId': { $exists:true, $type:"string" } },
|
|
152
|
+
name: "tempoDestinationUniqueWithinProject"
|
|
153
|
+
})
|
|
154
|
+
|
|
139
155
|
// Mongoose-json-patch
|
|
140
156
|
// https://www.npmjs.com/package/mongoose-json-patch
|
|
141
157
|
// plugin for PATCH operations
|
|
@@ -10,7 +10,17 @@ let schema = {
|
|
|
10
10
|
name: {type: String, required: [true, 'name is required. ']},
|
|
11
11
|
color: String,
|
|
12
12
|
accuracy: {type: String, enum: Object.values(ZoneEnum.fenceAccuracy)},
|
|
13
|
-
radius: {
|
|
13
|
+
radius: {
|
|
14
|
+
type: Double,
|
|
15
|
+
required: [true, 'radius is required. '],
|
|
16
|
+
validate: {
|
|
17
|
+
validator: function(v) {
|
|
18
|
+
return (v >= 5) ;
|
|
19
|
+
},
|
|
20
|
+
message: props => `radius [${props.value}m] must be greater than 5m`
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
},
|
|
14
24
|
center: {type: Point, required: [true, 'center is required. ']}
|
|
15
25
|
}
|
|
16
26
|
|
package/package.json
CHANGED
package/schemas/ProjectTempo.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
let mongoose = require('mongoose')
|
|
2
|
+
// TODO: Remove below imports after migration
|
|
3
|
+
let WebhookSchema = require('./Webhook')
|
|
4
|
+
let helpers = require('../helpers')
|
|
2
5
|
|
|
3
6
|
function validateIsochroneBracketInterval (brackets) {
|
|
4
7
|
const isInteger = brackets.every((bracket) => {
|
|
@@ -8,8 +11,16 @@ function validateIsochroneBracketInterval (brackets) {
|
|
|
8
11
|
return isInteger
|
|
9
12
|
}
|
|
10
13
|
|
|
14
|
+
// TODO: Remove below validators after migration
|
|
15
|
+
let webhooksValidators = [
|
|
16
|
+
{validator: helpers.validateNotNull},
|
|
17
|
+
{validator: helpers.validateTempoWebhooks, msg: 'tempo.webhooks should contain tempo webhooks only'}
|
|
18
|
+
];
|
|
19
|
+
|
|
11
20
|
let ProjectTempoSchema = new mongoose.Schema({
|
|
12
21
|
isochroneBracketInterval: {type: [Number], validate: { validator: validateIsochroneBracketInterval, msg: 'tempo.isochroneBracketInterval should contain integer numbers only' }},
|
|
22
|
+
// TODO: Remove webhooks after migration
|
|
23
|
+
webhooks: {type:[WebhookSchema], validate: webhooksValidators}
|
|
13
24
|
}, {
|
|
14
25
|
_id: false
|
|
15
26
|
})
|
package/schemas/Webhook.js
CHANGED
|
@@ -2,7 +2,8 @@ let mongoose = require('mongoose')
|
|
|
2
2
|
let validators = require('../utils/validators')
|
|
3
3
|
|
|
4
4
|
let WebhookSchema = new mongoose.Schema({
|
|
5
|
-
|
|
5
|
+
// TODO: Remove trigger type after migration
|
|
6
|
+
type: {type: String, enum: ['geoTrigger', 'tempo', 'doorbell', 'trigger'], required: [true, 'webhook type is required']},
|
|
6
7
|
url: {type: String, required: [true, 'URL is required'], validate: {validator: validators.validateUrl, msg: 'Please enter a valid URL'}},
|
|
7
8
|
headers: {type: mongoose.Schema.Types.Mixed, validate: { validator: validateHeaderlength, msg: 'Header object can only have 1 key <-> value pair' }}
|
|
8
9
|
}, {
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// TODO: Remove this file after migration
|
|
2
|
+
let mongoose = require('mongoose')
|
|
3
|
+
let helpers = require('../helpers')
|
|
4
|
+
|
|
5
|
+
let ZoneTempoSchema = new mongoose.Schema({
|
|
6
|
+
destinationId: {type: String, validate: [
|
|
7
|
+
{ validator: helpers.validateDestinationIdLength, msg: 'destinationId must be less than 129 characters long' },
|
|
8
|
+
{ validator: helpers.validateTempoDestinationSingleGeofeature, msg: 'destinationId can only be set on zones with a single geofeature' },
|
|
9
|
+
{ validator: helpers.validateTempoDestinationIdGeofeatureType, msg: 'destinationId cannot be set on zones with a geoline or beacon' }
|
|
10
|
+
]}
|
|
11
|
+
}, {
|
|
12
|
+
_id: false
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
module.exports = ZoneTempoSchema
|
|
@@ -17,6 +17,18 @@ const indexes = {
|
|
|
17
17
|
partialFilterExpression: { destinationId: { $exists:true, $type:"string" } },
|
|
18
18
|
name: "destinationUniqueWithinProject"
|
|
19
19
|
}
|
|
20
|
+
},
|
|
21
|
+
// TODO: Remove below index after migration
|
|
22
|
+
{
|
|
23
|
+
fields: {
|
|
24
|
+
projectId: 1,
|
|
25
|
+
'tempo.destinationId': 1
|
|
26
|
+
},
|
|
27
|
+
options: {
|
|
28
|
+
unique: true,
|
|
29
|
+
partialFilterExpression: { 'tempo.destinationId': { $exists:true, $type:"string" } },
|
|
30
|
+
name: "tempoDestinationUniqueWithinProject"
|
|
31
|
+
}
|
|
20
32
|
}
|
|
21
33
|
]
|
|
22
34
|
}
|