@bluedot-innovation/models 6.2.11 → 7.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.
- package/CHANGELOG.md +5 -0
- package/__tests__/project/project.data.json +23 -15
- package/__tests__/project/project.remote.config.json +2 -3
- package/__tests__/project/project.spec.js +3 -18
- package/__tests__/zone/zone.spec.js +10 -20
- package/helpers.js +9 -23
- package/models/Project.js +1 -2
- package/models/Zone.js +8 -4
- package/package.json +1 -1
- package/schemas/ProjectTempo.js +0 -8
- package/schemas/Webhook.js +1 -1
- package/schemas/ZoneTempo.js +1 -5
- package/utils/DbInitialiser/indexInitialiser.js +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
## 7.0.0
|
|
2
|
+
- BREAKING CHANGE - Moved tempo webhooks to within main project webhooks array
|
|
3
|
+
- BREAKING CHANGE - Moved zone destinationId to object root and removed tempo object from zone
|
|
4
|
+
- Added 'doorbell' type to project webhooks
|
|
5
|
+
|
|
1
6
|
## 6.2.11
|
|
2
7
|
- Replace `isAsync` validators with Mongoose 5.x validators
|
|
3
8
|
|
|
@@ -5,13 +5,29 @@
|
|
|
5
5
|
"creationTime": "2018-02-14T04:12:02.103Z",
|
|
6
6
|
"name": "A New Project",
|
|
7
7
|
"accountId":"b0824b76-ce73-4fcf-81f8-1b63edb1114e",
|
|
8
|
-
"webhooks": [
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"
|
|
8
|
+
"webhooks": [
|
|
9
|
+
{
|
|
10
|
+
"type": "geoTrigger",
|
|
11
|
+
"url": "https://webhooklistener.bluedotinnovation.com",
|
|
12
|
+
"headers" : {
|
|
13
|
+
"securityToken" : "value"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"type": "tempo",
|
|
18
|
+
"url": "https://webhooklistener.bluedotinnovation.com",
|
|
19
|
+
"headers" : {
|
|
20
|
+
"securityToken" : "value"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"type": "doorbell",
|
|
25
|
+
"url": "https://webhooklistener.bluedotinnovation.com",
|
|
26
|
+
"headers" : {
|
|
27
|
+
"securityToken" : "value"
|
|
28
|
+
}
|
|
13
29
|
}
|
|
14
|
-
|
|
30
|
+
],
|
|
15
31
|
"shouldSync": true,
|
|
16
32
|
"firebaseApiKey": "88888888-4444-4444-4444-121212121212",
|
|
17
33
|
"apiKey": "88888888-4444-4444-4444-123412341234",
|
|
@@ -24,14 +40,6 @@
|
|
|
24
40
|
}
|
|
25
41
|
},
|
|
26
42
|
"tempo": {
|
|
27
|
-
"
|
|
28
|
-
{
|
|
29
|
-
"type": "tempo",
|
|
30
|
-
"url": "https://webhooklistener.bluedotinnovation.com",
|
|
31
|
-
"headers" : {
|
|
32
|
-
"securityToken" : "value"
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
]
|
|
43
|
+
"isochroneBracketInterval": [60, 120, 300]
|
|
36
44
|
}
|
|
37
45
|
}
|
|
@@ -6,9 +6,8 @@
|
|
|
6
6
|
"name": "A New Project",
|
|
7
7
|
"accountId":"b0824b76-ce73-4fcf-81f8-1b63edb1114e",
|
|
8
8
|
"webhooks": {
|
|
9
|
-
"type": "
|
|
9
|
+
"type": "geoTrigger",
|
|
10
10
|
"url": "https://webhooklistener.bluedotinnovation.com",
|
|
11
|
-
"enabled": true,
|
|
12
11
|
"headers" : {
|
|
13
12
|
"securityToken" : "value"
|
|
14
13
|
}
|
|
@@ -120,4 +119,4 @@
|
|
|
120
119
|
"triggerEngine": "BD"
|
|
121
120
|
}
|
|
122
121
|
}
|
|
123
|
-
}
|
|
122
|
+
}
|
|
@@ -90,9 +90,9 @@ testCase('Project', () => {
|
|
|
90
90
|
done()
|
|
91
91
|
})
|
|
92
92
|
})
|
|
93
|
-
assertions(`should not validate if one of webhooks have a type
|
|
93
|
+
assertions(`should not validate if one of webhooks have a type other than 'geoTrigger', 'tempo' or 'doorbell'`, (done) => {
|
|
94
94
|
project.webhooks.push({
|
|
95
|
-
"type": "
|
|
95
|
+
"type": "sandwich",
|
|
96
96
|
"url": "https://webhooklistener.bluedotinnovation.com",
|
|
97
97
|
"headers" : {
|
|
98
98
|
"securityToken" : "value"
|
|
@@ -101,22 +101,7 @@ testCase('Project', () => {
|
|
|
101
101
|
let Project = new ProjectModel(project)
|
|
102
102
|
Project.validate((err, res) => {
|
|
103
103
|
assert.exists(err)
|
|
104
|
-
assert.match(err.message,
|
|
105
|
-
done()
|
|
106
|
-
})
|
|
107
|
-
})
|
|
108
|
-
assertions(`should not validate if one of tempo webhooks have a type orther than 'tempo'`, (done) => {
|
|
109
|
-
project.tempo.webhooks.push({
|
|
110
|
-
"type": "trigger",
|
|
111
|
-
"url": "https://webhooklistener.bluedotinnovation.com",
|
|
112
|
-
"headers" : {
|
|
113
|
-
"securityToken" : "value"
|
|
114
|
-
}
|
|
115
|
-
})
|
|
116
|
-
let Project = new ProjectModel(project)
|
|
117
|
-
Project.validate((err, res) => {
|
|
118
|
-
assert.exists(err)
|
|
119
|
-
assert.match(err.message, /tempo.webhooks should contain tempo webhooks only/)
|
|
104
|
+
assert.match(err.message, /`sandwich` is not a valid enum value for path `type`/)
|
|
120
105
|
done()
|
|
121
106
|
})
|
|
122
107
|
})
|
|
@@ -94,10 +94,8 @@ describe('Zone', () => {
|
|
|
94
94
|
assert.strictEqual(zone.tags[1], "1")
|
|
95
95
|
})
|
|
96
96
|
|
|
97
|
-
it('should save without errors when
|
|
98
|
-
zone.
|
|
99
|
-
"destinationId": null
|
|
100
|
-
}
|
|
97
|
+
it('should save without errors when destinationId is null', (done) => {
|
|
98
|
+
zone.destinationId = null;
|
|
101
99
|
let Zone = new ZoneModel(zone)
|
|
102
100
|
Zone.validate((err, res) => {
|
|
103
101
|
assert.notExists(res)
|
|
@@ -109,10 +107,8 @@ describe('Zone', () => {
|
|
|
109
107
|
const validTempoGeofeatureTypes = ['boundingBox', 'circle', 'polygon']
|
|
110
108
|
|
|
111
109
|
validTempoGeofeatureTypes.map(type => {
|
|
112
|
-
it(`should save without errors when
|
|
113
|
-
zone.
|
|
114
|
-
"destinationId": "test-destination-id"
|
|
115
|
-
}
|
|
110
|
+
it(`should save without errors when destinationId is set and there is a single ${type} geofeature`, (done) => {
|
|
111
|
+
zone.destinationId = "test-destination-id";
|
|
116
112
|
zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(new RegExp(type)))
|
|
117
113
|
let Zone = new ZoneModel(zone)
|
|
118
114
|
Zone.validate((err, res) => {
|
|
@@ -419,10 +415,8 @@ describe('Zone', () => {
|
|
|
419
415
|
})
|
|
420
416
|
})
|
|
421
417
|
|
|
422
|
-
it('should throw an error when
|
|
423
|
-
zone.
|
|
424
|
-
"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'
|
|
425
|
-
}
|
|
418
|
+
it('should throw an error when destinationId is longer than 128 characters', (done) => {
|
|
419
|
+
zone.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';
|
|
426
420
|
let Zone = new ZoneModel(zone)
|
|
427
421
|
Zone.validate((err, res) => {
|
|
428
422
|
assert.exists(err, 'err object should exist')
|
|
@@ -434,10 +428,8 @@ describe('Zone', () => {
|
|
|
434
428
|
const invalidTempoGeofeatures = ['geoline', 'beacon']
|
|
435
429
|
|
|
436
430
|
invalidTempoGeofeatures.map(type => {
|
|
437
|
-
it(`should throw an error when
|
|
438
|
-
zone.
|
|
439
|
-
"destinationId": "test-destination-id"
|
|
440
|
-
}
|
|
431
|
+
it(`should throw an error when destinationId is set and there is a single ${type} geofeature`, (done) => {
|
|
432
|
+
zone.destinationId = "test-destination-id";
|
|
441
433
|
zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(new RegExp(type)))
|
|
442
434
|
let Zone = new ZoneModel(zone)
|
|
443
435
|
Zone.validate((err, res) => {
|
|
@@ -448,10 +440,8 @@ describe('Zone', () => {
|
|
|
448
440
|
})
|
|
449
441
|
})
|
|
450
442
|
|
|
451
|
-
it('should throw an error when
|
|
452
|
-
zone.
|
|
453
|
-
"destinationId": "test-destination-id"
|
|
454
|
-
}
|
|
443
|
+
it('should throw an error when destinationId is set and there is more than one geofeature', (done) => {
|
|
444
|
+
zone.destinationId = "test-destination-id";
|
|
455
445
|
let Zone = new ZoneModel(zone)
|
|
456
446
|
Zone.validate((err, res) => {
|
|
457
447
|
assert.exists(err, 'err object should exist')
|
package/helpers.js
CHANGED
|
@@ -240,16 +240,16 @@ helpers.ensureNonEmptyGeofeatures = function(zone, next){
|
|
|
240
240
|
next()
|
|
241
241
|
}
|
|
242
242
|
|
|
243
|
-
helpers.
|
|
244
|
-
if(
|
|
245
|
-
return !(
|
|
243
|
+
helpers.validateDestinationIdLength = function(destinationId) {
|
|
244
|
+
if(destinationId){
|
|
245
|
+
return !(destinationId.length > 128)
|
|
246
246
|
}
|
|
247
247
|
return true
|
|
248
248
|
}
|
|
249
249
|
|
|
250
|
-
helpers.
|
|
251
|
-
if(
|
|
252
|
-
const geofeatures = this.
|
|
250
|
+
helpers.validateDestinationSingleGeofeature = function(destinationId) {
|
|
251
|
+
if(destinationId){
|
|
252
|
+
const geofeatures = this.geofeatures
|
|
253
253
|
if(!geofeatures.length){
|
|
254
254
|
return false
|
|
255
255
|
}
|
|
@@ -258,26 +258,12 @@ helpers.validateTempoDestinationSingleGeofeature = function(tempoDestinationId)
|
|
|
258
258
|
return true
|
|
259
259
|
}
|
|
260
260
|
|
|
261
|
-
helpers.
|
|
262
|
-
const geofeatures = this.
|
|
263
|
-
if(
|
|
261
|
+
helpers.validateDestinationIdGeofeatureType = function(destinationId) {
|
|
262
|
+
const geofeatures = this.geofeatures
|
|
263
|
+
if(destinationId && geofeatures.length){
|
|
264
264
|
return !(geofeatures[0].type === 'geoline' || geofeatures[0].type === 'beacon')
|
|
265
265
|
}
|
|
266
266
|
return true
|
|
267
267
|
}
|
|
268
268
|
|
|
269
|
-
helpers.validateTriggerWebhooks = function(webhooks) {
|
|
270
|
-
const notTrigger = webhooks.some(webhook => {
|
|
271
|
-
return webhook.type && webhook.type != 'trigger'
|
|
272
|
-
})
|
|
273
|
-
return !notTrigger
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
helpers.validateTempoWebhooks = function(webhooks) {
|
|
277
|
-
const notTempo = webhooks.some(webhook => {
|
|
278
|
-
return webhook.type && webhook.type != 'tempo'
|
|
279
|
-
})
|
|
280
|
-
return !notTempo
|
|
281
|
-
}
|
|
282
|
-
|
|
283
269
|
module.exports = helpers
|
package/models/Project.js
CHANGED
|
@@ -18,8 +18,7 @@ let androidConfig = require('../schemas/AndroidConfig')
|
|
|
18
18
|
let projectTempoSchema = require('../schemas/ProjectTempo')
|
|
19
19
|
|
|
20
20
|
let webhooksValidators = [
|
|
21
|
-
{validator: helpers.validateNotNull}
|
|
22
|
-
{validator: helpers.validateTriggerWebhooks, msg: 'webhooks should contain trigger webhooks only'}
|
|
21
|
+
{validator: helpers.validateNotNull}
|
|
23
22
|
];
|
|
24
23
|
|
|
25
24
|
let ProjectSchema = new mongoose.Schema({
|
package/models/Zone.js
CHANGED
|
@@ -120,18 +120,22 @@ let zoneSchema = new Schema({
|
|
|
120
120
|
projectId: {type: String, required: true, validate: {validator: helpers.validateUUIDv4, message: 'Invalid Project Id.'}},
|
|
121
121
|
state: {type: String, default: StateEnum.ACTIVE, select: false},
|
|
122
122
|
accountId: {type: String, required: true, validate: {validator: helpers.validateUUIDv4, msg: 'default error message'}},
|
|
123
|
-
|
|
123
|
+
destinationId: {type: String, validate: [
|
|
124
|
+
{ validator: helpers.validateDestinationIdLength, msg: 'destinationId must be less than 129 characters long' },
|
|
125
|
+
{ validator: helpers.validateDestinationSingleGeofeature, msg: 'destinationId can only be set on zones with a single geofeature' },
|
|
126
|
+
{ validator: helpers.validateDestinationIdGeofeatureType, msg: 'destinationId cannot be set on zones with a geoline or beacon' }
|
|
127
|
+
]}
|
|
124
128
|
}, {collection: 'zone', autoIndex: false})
|
|
125
129
|
|
|
126
130
|
zoneSchema.index(
|
|
127
131
|
{
|
|
128
132
|
projectId: 1,
|
|
129
|
-
|
|
133
|
+
destinationId: 1
|
|
130
134
|
},
|
|
131
135
|
{
|
|
132
136
|
unique: true,
|
|
133
|
-
partialFilterExpression: { '
|
|
134
|
-
name: "
|
|
137
|
+
partialFilterExpression: { 'destinationId': { $exists:true, $type:"string" } },
|
|
138
|
+
name: "destinationUniqueWithinProject"
|
|
135
139
|
})
|
|
136
140
|
|
|
137
141
|
// Mongoose-json-patch
|
package/package.json
CHANGED
package/schemas/ProjectTempo.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
let mongoose = require('mongoose')
|
|
2
|
-
let WebhookSchema = require('./Webhook')
|
|
3
|
-
let helpers = require('../helpers')
|
|
4
2
|
|
|
5
3
|
function validateIsochroneBracketInterval (brackets) {
|
|
6
4
|
const isInteger = brackets.every((bracket) => {
|
|
@@ -10,13 +8,7 @@ function validateIsochroneBracketInterval (brackets) {
|
|
|
10
8
|
return isInteger
|
|
11
9
|
}
|
|
12
10
|
|
|
13
|
-
let webhooksValidators = [
|
|
14
|
-
{validator: helpers.validateNotNull},
|
|
15
|
-
{validator: helpers.validateTempoWebhooks, msg: 'tempo.webhooks should contain tempo webhooks only'}
|
|
16
|
-
];
|
|
17
|
-
|
|
18
11
|
let ProjectTempoSchema = new mongoose.Schema({
|
|
19
|
-
webhooks: {type:[WebhookSchema], validate: webhooksValidators},
|
|
20
12
|
isochroneBracketInterval: {type: [Number], validate: { validator: validateIsochroneBracketInterval, msg: 'tempo.isochroneBracketInterval should contain integer numbers only' }}
|
|
21
13
|
}, {
|
|
22
14
|
_id: false
|
package/schemas/Webhook.js
CHANGED
|
@@ -2,7 +2,7 @@ let mongoose = require('mongoose')
|
|
|
2
2
|
let validators = require('../utils/validators')
|
|
3
3
|
|
|
4
4
|
let WebhookSchema = new mongoose.Schema({
|
|
5
|
-
type: {type: String, enum: ['
|
|
5
|
+
type: {type: String, enum: ['geoTrigger', 'tempo', 'doorbell'], required: [true, 'webhook type is required']},
|
|
6
6
|
url: {type: String, required: [true, 'URL is required'], validate: {validator: validators.validateUrl, msg: 'Please enter a valid URL'}},
|
|
7
7
|
headers: {type: mongoose.Schema.Types.Mixed, validate: { validator: validateHeaderlength, msg: 'Header object can only have 1 key <-> value pair' }}
|
|
8
8
|
}, {
|
package/schemas/ZoneTempo.js
CHANGED
|
@@ -2,11 +2,7 @@ let mongoose = require('mongoose')
|
|
|
2
2
|
let helpers = require('../helpers')
|
|
3
3
|
|
|
4
4
|
let ZoneTempoSchema = new mongoose.Schema({
|
|
5
|
-
|
|
6
|
-
{ validator: helpers.validateTempoDestinationIdLength, msg: 'destinationId must be less than 129 characters long' },
|
|
7
|
-
{ validator: helpers.validateTempoDestinationSingleGeofeature, msg: 'destinationId can only be set on zones with a single geofeature' },
|
|
8
|
-
{ validator: helpers.validateTempoDestinationIdGeofeatureType, msg: 'destinationId cannot be set on zones with a geoline or beacon' }
|
|
9
|
-
]}
|
|
5
|
+
|
|
10
6
|
}, {
|
|
11
7
|
_id: false
|
|
12
8
|
})
|
|
@@ -10,12 +10,12 @@ const indexes = {
|
|
|
10
10
|
{
|
|
11
11
|
fields: {
|
|
12
12
|
projectId: 1,
|
|
13
|
-
|
|
13
|
+
destinationId: 1
|
|
14
14
|
},
|
|
15
15
|
options: {
|
|
16
16
|
unique: true,
|
|
17
|
-
partialFilterExpression: {
|
|
18
|
-
name: "
|
|
17
|
+
partialFilterExpression: { destinationId: { $exists:true, $type:"string" } },
|
|
18
|
+
name: "destinationUniqueWithinProject"
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
]
|