@bluedot-innovation/models 10.9.0 → 10.10.1
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 +9 -1
- package/__tests__/project/project.spec.js +35 -1
- package/__tests__/zone/zone.spec.js +77 -0
- package/helpers.js +8 -0
- package/models/Zone.js +5 -1
- package/package.json +1 -1
- package/schemas/DwellConfiguration.js +19 -0
- package/schemas/ReportConfiguration.js +1 -1
- package/schemas/Webhook.js +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
## 10.
|
|
1
|
+
## 10.10.1
|
|
2
|
+
- Only be able to enbale Dwell when Exit is on
|
|
3
|
+
|
|
4
|
+
## 10.10.0
|
|
5
|
+
- Add Dwell Configuration to Zone
|
|
6
|
+
- Support trigger webhook structure 2.2
|
|
7
|
+
- Add a new Scheduled Report type `geo-trigger-v2`
|
|
8
|
+
|
|
9
|
+
## 10.9.0
|
|
2
10
|
- Add dashboardIdentityProvider to HelloSSO model
|
|
3
11
|
|
|
4
12
|
## 10.8.0
|
|
@@ -190,6 +190,20 @@ describe('Project', () => {
|
|
|
190
190
|
const res = await Project.validate()
|
|
191
191
|
assert.notExists(res)
|
|
192
192
|
})
|
|
193
|
+
|
|
194
|
+
it(`should validate a project when trigger webhook has structure is 2.2`, async () => {
|
|
195
|
+
project.webhooks = [
|
|
196
|
+
{
|
|
197
|
+
"type": "trigger",
|
|
198
|
+
"url": "https://webhooklistener.bluedotinnovation.com",
|
|
199
|
+
"retryEnabled": true,
|
|
200
|
+
"structure": "2.2"
|
|
201
|
+
}
|
|
202
|
+
]
|
|
203
|
+
let Project = new ProjectModel(project)
|
|
204
|
+
const res = await Project.validate()
|
|
205
|
+
assert.notExists(res)
|
|
206
|
+
})
|
|
193
207
|
})
|
|
194
208
|
testCase('Valid Project ', () => {
|
|
195
209
|
assertions('should validate a valid project ', async () => {
|
|
@@ -668,7 +682,20 @@ describe('Project', () => {
|
|
|
668
682
|
await Project.validate()
|
|
669
683
|
} catch (err) {
|
|
670
684
|
assert.exists(err, 'err object should exist')
|
|
671
|
-
assert.match(err.message, /Only type "trigger" can have structure 2.0/)
|
|
685
|
+
assert.match(err.message, /Only type "trigger" can have structure 2.0 or 2.2/)
|
|
686
|
+
}
|
|
687
|
+
})
|
|
688
|
+
|
|
689
|
+
it(`should not validate if structure is 2.2 and the type is not trigger`, async () => {
|
|
690
|
+
project.webhooks[0].type = "tempo"
|
|
691
|
+
project.webhooks[0].url = "http://test-url.com"
|
|
692
|
+
project.webhooks[0].structure = "2.2"
|
|
693
|
+
let Project = new ProjectModel(project)
|
|
694
|
+
try {
|
|
695
|
+
await Project.validate()
|
|
696
|
+
} catch (err) {
|
|
697
|
+
assert.exists(err, 'err object should exist')
|
|
698
|
+
assert.match(err.message, /Only type "trigger" can have structure 2.0 or 2.2/)
|
|
672
699
|
}
|
|
673
700
|
})
|
|
674
701
|
|
|
@@ -1010,6 +1037,13 @@ describe('Project', () => {
|
|
|
1010
1037
|
"timezone": "Australia/Sydney",
|
|
1011
1038
|
"recipients": "xyz@example.com"
|
|
1012
1039
|
})
|
|
1040
|
+
project.reportConfigurations.push({
|
|
1041
|
+
"type": "geo-trigger-v2",
|
|
1042
|
+
"frequency": "monthly",
|
|
1043
|
+
"reportDay": 1,
|
|
1044
|
+
"timezone": "Australia/Sydney",
|
|
1045
|
+
"recipients": "xyz@example.com"
|
|
1046
|
+
})
|
|
1013
1047
|
let Project = new ProjectModel(project)
|
|
1014
1048
|
const res = await Project.validate()
|
|
1015
1049
|
assert.notExists(res)
|
|
@@ -91,6 +91,28 @@ describe('Zone', () => {
|
|
|
91
91
|
assert.notExists(res)
|
|
92
92
|
})
|
|
93
93
|
})
|
|
94
|
+
|
|
95
|
+
it('should set dwell enabled to false by default', async () => {
|
|
96
|
+
zone.dwellConfiguration = {
|
|
97
|
+
threshold: 300
|
|
98
|
+
}
|
|
99
|
+
let Zone = new ZoneModel(zone)
|
|
100
|
+
const res = await Zone.validate()
|
|
101
|
+
assert.isFalse(Zone.dwellConfiguration.enabled)
|
|
102
|
+
assert.notExists(res)
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
it('should successfully enable dwell when triggerOnExit is true', async () => {
|
|
106
|
+
zone.dwellConfiguration = {
|
|
107
|
+
threshold: 300,
|
|
108
|
+
enabled: true
|
|
109
|
+
}
|
|
110
|
+
zone.triggerOnExit = true
|
|
111
|
+
let Zone = new ZoneModel(zone)
|
|
112
|
+
const res = await Zone.validate()
|
|
113
|
+
assert.isTrue(Zone.dwellConfiguration.enabled)
|
|
114
|
+
assert.notExists(res)
|
|
115
|
+
})
|
|
94
116
|
})
|
|
95
117
|
|
|
96
118
|
describe('Invalid Zone ', () => {
|
|
@@ -415,5 +437,60 @@ describe('Zone', () => {
|
|
|
415
437
|
assert.match(err.message, /(destinationId must be less than 129 characters long)/i)
|
|
416
438
|
}
|
|
417
439
|
})
|
|
440
|
+
|
|
441
|
+
it('should fail to enable dwell when triggerOnExit is false', async () => {
|
|
442
|
+
zone.dwellConfiguration = {
|
|
443
|
+
threshold: 300,
|
|
444
|
+
enabled: true
|
|
445
|
+
}
|
|
446
|
+
zone.triggerOnExit = false
|
|
447
|
+
let Zone = new ZoneModel(zone)
|
|
448
|
+
try {
|
|
449
|
+
await Zone.validate()
|
|
450
|
+
} catch (err) {
|
|
451
|
+
assert.exists(err, 'err object should exist')
|
|
452
|
+
assert.match(err.message, /(triggerOnExit must be true when dwellConfiguration is enabled)/i)
|
|
453
|
+
}
|
|
454
|
+
})
|
|
455
|
+
|
|
456
|
+
it('should throw error when dwell threshold is not a number', async () => {
|
|
457
|
+
zone.dwellConfiguration = {
|
|
458
|
+
threshold: 'test'
|
|
459
|
+
}
|
|
460
|
+
let Zone = new ZoneModel(zone)
|
|
461
|
+
try {
|
|
462
|
+
await Zone.validate()
|
|
463
|
+
} catch (err) {
|
|
464
|
+
assert.exists(err, 'err object should exist')
|
|
465
|
+
assert.match(err.message, /dwellConfiguration.threshold: Cast to Number failed/i)
|
|
466
|
+
}
|
|
467
|
+
})
|
|
468
|
+
|
|
469
|
+
it('should throw error when dwell threshold is not an integer number', async () => {
|
|
470
|
+
zone.dwellConfiguration = {
|
|
471
|
+
threshold: 300.5
|
|
472
|
+
}
|
|
473
|
+
let Zone = new ZoneModel(zone)
|
|
474
|
+
try {
|
|
475
|
+
await Zone.validate()
|
|
476
|
+
} catch (err) {
|
|
477
|
+
assert.exists(err, 'err object should exist')
|
|
478
|
+
assert.match(err.message, /dwellConfiguration.threshold: 300.5 is not an integer number/i)
|
|
479
|
+
}
|
|
480
|
+
})
|
|
481
|
+
|
|
482
|
+
it('should throw error when dwell threshold is out of range', async () => {
|
|
483
|
+
zone.dwellConfiguration = {
|
|
484
|
+
threshold: 30
|
|
485
|
+
}
|
|
486
|
+
let Zone = new ZoneModel(zone)
|
|
487
|
+
try {
|
|
488
|
+
await Zone.validate()
|
|
489
|
+
} catch (err) {
|
|
490
|
+
console.log(err)
|
|
491
|
+
assert.exists(err, 'err object should exist')
|
|
492
|
+
assert.match(err.message, /dwellConfiguration.threshold: Path `threshold` \(30\) is less than minimum allowed value \(60\)/i)
|
|
493
|
+
}
|
|
494
|
+
})
|
|
418
495
|
})
|
|
419
496
|
})
|
package/helpers.js
CHANGED
|
@@ -271,4 +271,12 @@ helpers.transformNumbertoDouble = (value) => {
|
|
|
271
271
|
return Number.isInteger(value) ? value + 0.0000001 : value
|
|
272
272
|
}
|
|
273
273
|
|
|
274
|
+
helpers.validateDwellConfigurationTriggerOnExit = function(zone, next) {
|
|
275
|
+
// Validate that if dwellConfiguration.enabled is true, triggerOnExit must also be true
|
|
276
|
+
if (zone.dwellConfiguration && zone.dwellConfiguration.enabled === true && zone.triggerOnExit !== true) {
|
|
277
|
+
return next(new Error('triggerOnExit must be true when dwellConfiguration is enabled'))
|
|
278
|
+
}
|
|
279
|
+
next()
|
|
280
|
+
}
|
|
281
|
+
|
|
274
282
|
module.exports = helpers
|
package/models/Zone.js
CHANGED
|
@@ -19,6 +19,8 @@ let travelDirectionRawSchema = require('./conditions/TravelDirection').rawSchema
|
|
|
19
19
|
let travelPathRawSchema = require('./conditions/TravelPath').rawSchema
|
|
20
20
|
let timeActiveRawSchema = require('./conditions/TimeActive').rawSchema
|
|
21
21
|
|
|
22
|
+
let dwellConfigurationSchema = require('../schemas/DwellConfiguration')
|
|
23
|
+
|
|
22
24
|
let uuidv4 = require('uuid/v4')
|
|
23
25
|
let patcher = require('@bluedot-innovation/mongoose-json-patch')
|
|
24
26
|
let helpers = require('../helpers')
|
|
@@ -99,6 +101,7 @@ let zoneSchema = new Schema({
|
|
|
99
101
|
state: {type: String, default: StateEnum.ACTIVE, select: false},
|
|
100
102
|
accountId: {type: String, required: true, validate: {validator: helpers.validateUUIDv4, msg: 'default error message'}},
|
|
101
103
|
destinationId: {type: String, validate: { validator: helpers.validateDestinationIdLength, msg: 'destinationId must be less than 129 characters long' }},
|
|
104
|
+
dwellConfiguration: dwellConfigurationSchema
|
|
102
105
|
}, {collection: 'zone', autoIndex: false})
|
|
103
106
|
|
|
104
107
|
// Mongoose-json-patch
|
|
@@ -124,7 +127,8 @@ zoneSchema.pre('validate', function(next) {
|
|
|
124
127
|
new Promise((resolve, reject) => helpers.validateTravelPathConditionCount(this, resolve)),
|
|
125
128
|
new Promise((resolve, reject) => helpers.checkValidLowAccuracyFence(this, resolve)),
|
|
126
129
|
new Promise((resolve, reject) => helpers.checkDuplicateGeofeaturesId(this, resolve)),
|
|
127
|
-
new Promise((resolve, reject) => helpers.ensureNonEmptyGeofeatures(this, resolve))
|
|
130
|
+
new Promise((resolve, reject) => helpers.ensureNonEmptyGeofeatures(this, resolve)),
|
|
131
|
+
new Promise((resolve, reject) => helpers.validateDwellConfigurationTriggerOnExit(this, resolve))
|
|
128
132
|
]).then(results => {
|
|
129
133
|
for( let result of results ) {
|
|
130
134
|
if( result )
|
package/package.json
CHANGED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
|
|
3
|
+
let DwellConfigurationSchema = new mongoose.Schema({
|
|
4
|
+
enabled: {type: Boolean, default: false},
|
|
5
|
+
threshold: {
|
|
6
|
+
type: Number,
|
|
7
|
+
required: true,
|
|
8
|
+
min: 60,
|
|
9
|
+
max: 86400,
|
|
10
|
+
validate: {
|
|
11
|
+
validator: Number.isInteger,
|
|
12
|
+
message: '{VALUE} is not an integer number'
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}, {
|
|
16
|
+
_id: false
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
module.exports = DwellConfigurationSchema
|
|
@@ -34,7 +34,7 @@ function validateRecipients(value) {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
let ReportConfigurationSchema = new mongoose.Schema({
|
|
37
|
-
type: {type: String, enum: ['hello', 'geo-trigger'], required: true},
|
|
37
|
+
type: {type: String, enum: ['hello', 'geo-trigger', 'geo-trigger-v2'], required: true},
|
|
38
38
|
frequency: {type: String, enum: ['daily', 'weekly', 'monthly'], required: true},
|
|
39
39
|
reportDay: {type: Number, validate: {validator: validateReportDay}},
|
|
40
40
|
timezone: {type: String, required: true, validate: { validator: validateTimeZone, msg: 'Invalid timezone'}},
|
package/schemas/Webhook.js
CHANGED
|
@@ -34,8 +34,8 @@ function validateTypeAndStructure(type) {
|
|
|
34
34
|
} else if ((type === "helloOrder" && !['default', '2.1'].includes(this.structure))
|
|
35
35
|
|| (type !== "helloOrder" && this.structure === 'default')) {
|
|
36
36
|
throw new Error('type "helloOrder" can only have structure "default" or "2.1"')
|
|
37
|
-
} else if (type !== 'trigger' &&
|
|
38
|
-
throw new Error('Only type "trigger" can have structure 2.0')
|
|
37
|
+
} else if (type !== 'trigger' && ['2.0', '2.2'].includes(this.structure)) {
|
|
38
|
+
throw new Error('Only type "trigger" can have structure 2.0 or 2.2')
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
|
|
@@ -46,7 +46,7 @@ let WebhookSchema = new mongoose.Schema({
|
|
|
46
46
|
body: {type: mongoose.Schema.Types.Mixed, validate: [{ validator: validators.validateNonEmptyStringKeyValuePairsOnly, msg: 'webhook body keys and values must be strings' }, { validator: validators.validateNoSpacesInObjectKeys, msg: 'webhook body keys cannot contain spaces' }]},
|
|
47
47
|
structure: {
|
|
48
48
|
type: String,
|
|
49
|
-
enum: ['standard', 'tealium', 'mobivity', 'default', '2.0', '2.1'],
|
|
49
|
+
enum: ['standard', 'tealium', 'mobivity', 'default', '2.0', '2.1', '2.2'],
|
|
50
50
|
default: function () {
|
|
51
51
|
return this.type === 'trigger' ? '2.0' : 'standard'
|
|
52
52
|
},
|