@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 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
- "type": "trigger",
10
- "url": "https://webhooklistener.bluedotinnovation.com",
11
- "headers" : {
12
- "securityToken" : "value"
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
- "webhooks": [
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": "trigger",
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 orther than 'trigger'`, (done) => {
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": "tempo",
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, /webhooks should contain trigger webhooks only/)
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 tempo.destinationId is null', (done) => {
98
- zone.tempo = {
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 tempo.destinationId is set and there is a single ${type} geofeature`, (done) => {
113
- zone.tempo = {
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 tempo.destinationId is longer than 128 characters', (done) => {
423
- zone.tempo = {
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 tempo.destinationId is set and there is a single ${type} geofeature`, (done) => {
438
- zone.tempo = {
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 tempo.destinationId is set and there is more than one geofeature', (done) => {
452
- zone.tempo = {
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.validateTempoDestinationIdLength = function(tempoDestinationId) {
244
- if(tempoDestinationId){
245
- return !(tempoDestinationId.length > 128)
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.validateTempoDestinationSingleGeofeature = function(tempoDestinationId) {
251
- if(tempoDestinationId){
252
- const geofeatures = this.ownerDocument().geofeatures
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.validateTempoDestinationIdGeofeatureType = function(tempoDestinationId) {
262
- const geofeatures = this.ownerDocument().geofeatures
263
- if(tempoDestinationId && geofeatures.length){
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
- tempo: zoneTempoSchema
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
- 'tempo.destinationId': 1
133
+ destinationId: 1
130
134
  },
131
135
  {
132
136
  unique: true,
133
- partialFilterExpression: { 'tempo.destinationId': { $exists:true, $type:"string" } },
134
- name: "tempoDestinationUniqueWithinProject"
137
+ partialFilterExpression: { 'destinationId': { $exists:true, $type:"string" } },
138
+ name: "destinationUniqueWithinProject"
135
139
  })
136
140
 
137
141
  // Mongoose-json-patch
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bluedot-innovation/models",
3
- "version": "6.2.11",
3
+ "version": "7.0.0",
4
4
  "main": "Models.js",
5
5
  "scripts": {
6
6
  "lint": "./node_modules/.bin/eslint -c .eslintrc.js ./models/*.js ./__tests__/**/*.js ./__tests__/**/**/*.js ./schemas/*.js",
@@ -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
@@ -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: ['trigger', 'tempo'], required: [true, 'webhook type is required']}, // configurationChanged, trigger
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
  }, {
@@ -2,11 +2,7 @@ let mongoose = require('mongoose')
2
2
  let helpers = require('../helpers')
3
3
 
4
4
  let ZoneTempoSchema = new mongoose.Schema({
5
- destinationId: {type: String, validate: [
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
- 'tempo.destinationId': 1
13
+ destinationId: 1
14
14
  },
15
15
  options: {
16
16
  unique: true,
17
- partialFilterExpression: { 'tempo.destinationId': { $exists:true, $type:"string" } },
18
- name: "tempoDestinationUniqueWithinProject"
17
+ partialFilterExpression: { destinationId: { $exists:true, $type:"string" } },
18
+ name: "destinationUniqueWithinProject"
19
19
  }
20
20
  }
21
21
  ]