@bluedot-innovation/models 7.0.0 → 7.0.2
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 +10 -0
- package/__tests__/project/project.data.json +3 -3
- package/__tests__/project/project.remote.config.json +1 -1
- package/__tests__/project/project.spec.js +26 -1
- package/helpers.js +15 -0
- package/models/Project.js +2 -1
- package/models/Zone.js +1 -3
- package/package.json +1 -1
- package/schemas/ProjectTempo.js +1 -1
- package/schemas/Webhook.js +1 -1
- package/schemas/ZoneTempo.js +0 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
## 7.0.2
|
|
2
|
+
- Removed tempo webhooks array for post doorbell migration deployment
|
|
3
|
+
- Removed tempo destinationId for post doorbell migration deployment
|
|
4
|
+
- Removed geoTrigger type from webhooks
|
|
5
|
+
|
|
6
|
+
## 7.0.1
|
|
7
|
+
- Added tempo webhooks array back for migration
|
|
8
|
+
- Added tempo destinationId back for migration
|
|
9
|
+
- Added no duplicate webhooks of same type validation
|
|
10
|
+
|
|
1
11
|
## 7.0.0
|
|
2
12
|
- BREAKING CHANGE - Moved tempo webhooks to within main project webhooks array
|
|
3
13
|
- BREAKING CHANGE - Moved zone destinationId to object root and removed tempo object from zone
|
|
@@ -7,21 +7,21 @@
|
|
|
7
7
|
"accountId":"b0824b76-ce73-4fcf-81f8-1b63edb1114e",
|
|
8
8
|
"webhooks": [
|
|
9
9
|
{
|
|
10
|
-
"type": "
|
|
10
|
+
"type": "tempo",
|
|
11
11
|
"url": "https://webhooklistener.bluedotinnovation.com",
|
|
12
12
|
"headers" : {
|
|
13
13
|
"securityToken" : "value"
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
{
|
|
17
|
-
"type": "
|
|
17
|
+
"type": "doorbell",
|
|
18
18
|
"url": "https://webhooklistener.bluedotinnovation.com",
|
|
19
19
|
"headers" : {
|
|
20
20
|
"securityToken" : "value"
|
|
21
21
|
}
|
|
22
22
|
},
|
|
23
23
|
{
|
|
24
|
-
"type": "
|
|
24
|
+
"type": "trigger",
|
|
25
25
|
"url": "https://webhooklistener.bluedotinnovation.com",
|
|
26
26
|
"headers" : {
|
|
27
27
|
"securityToken" : "value"
|
|
@@ -90,7 +90,8 @@ testCase('Project', () => {
|
|
|
90
90
|
done()
|
|
91
91
|
})
|
|
92
92
|
})
|
|
93
|
-
|
|
93
|
+
|
|
94
|
+
assertions(`should not validate if one of webhooks have a type other than 'tempo', 'doorbell' or 'trigger'`, (done) => {
|
|
94
95
|
project.webhooks.push({
|
|
95
96
|
"type": "sandwich",
|
|
96
97
|
"url": "https://webhooklistener.bluedotinnovation.com",
|
|
@@ -277,6 +278,30 @@ testCase('Project', () => {
|
|
|
277
278
|
})
|
|
278
279
|
})
|
|
279
280
|
|
|
281
|
+
testCase('should not validate if webhooks contains two webhooks of the same type', () => {
|
|
282
|
+
const webhookTypes = ['tempo', 'doorbell', 'trigger']
|
|
283
|
+
|
|
284
|
+
webhookTypes.map(webhookType => {
|
|
285
|
+
assertions(`should not validate if there are duplicate ${webhookType} webhooks`, (done) => {
|
|
286
|
+
project.webhooks.push({
|
|
287
|
+
"type": webhookType,
|
|
288
|
+
"url": "https://webhooklistener.bluedotinnovation.com",
|
|
289
|
+
"headers" : {
|
|
290
|
+
"securityToken" : "value"
|
|
291
|
+
}
|
|
292
|
+
})
|
|
293
|
+
|
|
294
|
+
let Project = new ProjectModel(project)
|
|
295
|
+
Project.validate((err, res) => {
|
|
296
|
+
assert.exists(err)
|
|
297
|
+
assert.match(err.message, /Duplicate webhooks found. Only have one webhook of each type is allowed/)
|
|
298
|
+
done()
|
|
299
|
+
})
|
|
300
|
+
})
|
|
301
|
+
})
|
|
302
|
+
})
|
|
303
|
+
|
|
304
|
+
|
|
280
305
|
describe('should throw an error when any of the values of the array contains a falsy value', () => {
|
|
281
306
|
let arrayTypeFields = rules.arrayTypeFields
|
|
282
307
|
|
package/helpers.js
CHANGED
|
@@ -266,4 +266,19 @@ helpers.validateDestinationIdGeofeatureType = function(destinationId) {
|
|
|
266
266
|
return true
|
|
267
267
|
}
|
|
268
268
|
|
|
269
|
+
helpers.validateNoDuplicateWebhookTypes = function(webhookArray) {
|
|
270
|
+
const webhookTypes = ['tempo', 'doorbell', 'trigger']
|
|
271
|
+
const webhookCounts = {};
|
|
272
|
+
webhookTypes.forEach(webhookType => webhookCounts[webhookType] = 0);
|
|
273
|
+
let duplicateFound = false
|
|
274
|
+
webhookArray.forEach(webhook => {
|
|
275
|
+
if(webhookCounts[webhook.type] > 0){
|
|
276
|
+
duplicateFound = true
|
|
277
|
+
}
|
|
278
|
+
webhookCounts[webhook.type]++
|
|
279
|
+
})
|
|
280
|
+
return !duplicateFound;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
|
|
269
284
|
module.exports = helpers
|
package/models/Project.js
CHANGED
|
@@ -18,7 +18,8 @@ let androidConfig = require('../schemas/AndroidConfig')
|
|
|
18
18
|
let projectTempoSchema = require('../schemas/ProjectTempo')
|
|
19
19
|
|
|
20
20
|
let webhooksValidators = [
|
|
21
|
-
{validator: helpers.validateNotNull}
|
|
21
|
+
{validator: helpers.validateNotNull},
|
|
22
|
+
{validator: helpers.validateNoDuplicateWebhookTypes, msg: "Duplicate webhooks found. Only have one webhook of each type is allowed"}
|
|
22
23
|
];
|
|
23
24
|
|
|
24
25
|
let ProjectSchema = new mongoose.Schema({
|
package/models/Zone.js
CHANGED
|
@@ -22,8 +22,6 @@ 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
|
-
|
|
27
25
|
let uuidv4 = require('uuid/v4')
|
|
28
26
|
let patcher = require('@bluedot-innovation/mongoose-json-patch')
|
|
29
27
|
let helpers = require('../helpers')
|
|
@@ -124,7 +122,7 @@ let zoneSchema = new Schema({
|
|
|
124
122
|
{ validator: helpers.validateDestinationIdLength, msg: 'destinationId must be less than 129 characters long' },
|
|
125
123
|
{ validator: helpers.validateDestinationSingleGeofeature, msg: 'destinationId can only be set on zones with a single geofeature' },
|
|
126
124
|
{ validator: helpers.validateDestinationIdGeofeatureType, msg: 'destinationId cannot be set on zones with a geoline or beacon' }
|
|
127
|
-
]}
|
|
125
|
+
]},
|
|
128
126
|
}, {collection: 'zone', autoIndex: false})
|
|
129
127
|
|
|
130
128
|
zoneSchema.index(
|
package/package.json
CHANGED
package/schemas/ProjectTempo.js
CHANGED
|
@@ -9,7 +9,7 @@ function validateIsochroneBracketInterval (brackets) {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
let ProjectTempoSchema = new mongoose.Schema({
|
|
12
|
-
isochroneBracketInterval: {type: [Number], validate: { validator: validateIsochroneBracketInterval, msg: 'tempo.isochroneBracketInterval should contain integer numbers only' }}
|
|
12
|
+
isochroneBracketInterval: {type: [Number], validate: { validator: validateIsochroneBracketInterval, msg: 'tempo.isochroneBracketInterval should contain integer numbers only' }},
|
|
13
13
|
}, {
|
|
14
14
|
_id: false
|
|
15
15
|
})
|
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: ['tempo', 'doorbell', 'trigger'], 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
|
}, {
|