@bluedot-innovation/models 6.0.9 → 6.0.11
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 -0
- package/__tests__/project/project.data.json +15 -4
- package/__tests__/project/project.remote.config.json +2 -1
- package/__tests__/project/project.spec.js +35 -5
- package/helpers.js +14 -0
- package/models/Project.js +9 -2
- package/package.json +1 -1
- package/schemas/AndroidConfig.js +2 -1
- package/schemas/ProjectEta.js +16 -0
- package/schemas/Webhook.js +1 -6
- package/yarn.lock +2796 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,14 +5,13 @@
|
|
|
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": {
|
|
8
|
+
"webhooks": [{
|
|
9
9
|
"type": "trigger",
|
|
10
10
|
"url": "https://webhooklistener.bluedotinnovation.com",
|
|
11
|
-
"enabled": true,
|
|
12
11
|
"headers" : {
|
|
13
12
|
"securityToken" : "value"
|
|
14
13
|
}
|
|
15
|
-
},
|
|
14
|
+
}],
|
|
16
15
|
"firebaseApiKey": "88888888-4444-4444-4444-121212121212",
|
|
17
16
|
"apiKey": "88888888-4444-4444-4444-123412341234",
|
|
18
17
|
"integrations":{
|
|
@@ -22,4 +21,16 @@
|
|
|
22
21
|
"iosApiKey": "us1-a5e6eefe90fe704aba0a7d2daa00baaa",
|
|
23
22
|
"iosSecretKey": "fZqphc1Vh2dqaIQEvz4APNbErZkW_AaaRmwE8BCmYpHZFc3n_ZKajTLgJgFqLNNN"
|
|
24
23
|
}
|
|
25
|
-
}
|
|
24
|
+
},
|
|
25
|
+
"eta": {
|
|
26
|
+
"webhooks": [
|
|
27
|
+
{
|
|
28
|
+
"type": "eta",
|
|
29
|
+
"url": "https://webhooklistener.bluedotinnovation.com",
|
|
30
|
+
"headers" : {
|
|
31
|
+
"securityToken" : "value"
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -52,7 +52,7 @@ testCase('Project', () => {
|
|
|
52
52
|
testCase('Invalid Project ', () => {
|
|
53
53
|
assertions('should not validate if webhook headers have more than 1 key value pair ', (done) => {
|
|
54
54
|
|
|
55
|
-
project.webhooks.headers.anotherKey = 'anotherValue'
|
|
55
|
+
project.webhooks[0].headers.anotherKey = 'anotherValue'
|
|
56
56
|
|
|
57
57
|
let Project = new ProjectModel(project)
|
|
58
58
|
Project.validate((err, res) => {
|
|
@@ -62,7 +62,7 @@ testCase('Project', () => {
|
|
|
62
62
|
})
|
|
63
63
|
})
|
|
64
64
|
assertions(`should not validate if webhook protocol is not valid `, (done) => {
|
|
65
|
-
project.webhooks.url = 'htt://test.com'
|
|
65
|
+
project.webhooks[0].url = 'htt://test.com'
|
|
66
66
|
let Project = new ProjectModel(project)
|
|
67
67
|
Project.validate((err, res) => {
|
|
68
68
|
assert.exists(err)
|
|
@@ -71,7 +71,7 @@ testCase('Project', () => {
|
|
|
71
71
|
})
|
|
72
72
|
})
|
|
73
73
|
assertions(`should not validate if webhook domain is not valid `, (done) => {
|
|
74
|
-
project.webhooks.url = 'https://@'
|
|
74
|
+
project.webhooks[0].url = 'https://@'
|
|
75
75
|
let Project = new ProjectModel(project)
|
|
76
76
|
Project.validate((err, res) => {
|
|
77
77
|
assert.exists(err)
|
|
@@ -79,6 +79,36 @@ testCase('Project', () => {
|
|
|
79
79
|
done()
|
|
80
80
|
})
|
|
81
81
|
})
|
|
82
|
+
assertions(`should not validate if one of webhooks have a type orther than 'trigger'`, (done) => {
|
|
83
|
+
project.webhooks.push({
|
|
84
|
+
"type": "eta",
|
|
85
|
+
"url": "https://webhooklistener.bluedotinnovation.com",
|
|
86
|
+
"headers" : {
|
|
87
|
+
"securityToken" : "value"
|
|
88
|
+
}
|
|
89
|
+
})
|
|
90
|
+
let Project = new ProjectModel(project)
|
|
91
|
+
Project.validate((err, res) => {
|
|
92
|
+
assert.exists(err)
|
|
93
|
+
assert.match(err.message, /webhooks should contain trigger webhooks only/)
|
|
94
|
+
done()
|
|
95
|
+
})
|
|
96
|
+
})
|
|
97
|
+
assertions(`should not validate if one of eta webhooks have a type orther than 'eta'`, (done) => {
|
|
98
|
+
project.eta.webhooks.push({
|
|
99
|
+
"type": "trigger",
|
|
100
|
+
"url": "https://webhooklistener.bluedotinnovation.com",
|
|
101
|
+
"headers" : {
|
|
102
|
+
"securityToken" : "value"
|
|
103
|
+
}
|
|
104
|
+
})
|
|
105
|
+
let Project = new ProjectModel(project)
|
|
106
|
+
Project.validate((err, res) => {
|
|
107
|
+
assert.exists(err)
|
|
108
|
+
assert.match(err.message, /eta.webhooks should contain eta webhooks only/)
|
|
109
|
+
done()
|
|
110
|
+
})
|
|
111
|
+
})
|
|
82
112
|
testCase('mparticle integration check', () => {
|
|
83
113
|
assertions('should throw an error if the mparticle integration has empty key ', (done) => {
|
|
84
114
|
|
|
@@ -226,12 +256,12 @@ testCase('Project', () => {
|
|
|
226
256
|
|
|
227
257
|
it(`should throw an error when webhooks has primitive value in headers`, (done) => {
|
|
228
258
|
project = JSON.parse(JSON.stringify(project))
|
|
229
|
-
project.webhooks.headers = 'primitive'
|
|
259
|
+
project.webhooks[0].headers = 'primitive'
|
|
230
260
|
helpers.testNullValue(project, ProjectModel, done)
|
|
231
261
|
})
|
|
232
262
|
it(`should throw an error when webhooks has array in headers`, (done) => {
|
|
233
263
|
project = JSON.parse(JSON.stringify(project))
|
|
234
|
-
project.webhooks.headers = ['array']
|
|
264
|
+
project.webhooks[0].headers = ['array']
|
|
235
265
|
helpers.testNullValue(project, ProjectModel, done)
|
|
236
266
|
})
|
|
237
267
|
|
package/helpers.js
CHANGED
|
@@ -240,4 +240,18 @@ helpers.ensureNonEmptyGeofeatures = function(zone, next){
|
|
|
240
240
|
next()
|
|
241
241
|
}
|
|
242
242
|
|
|
243
|
+
helpers.validateTriggerWebhooks = function(webhooks) {
|
|
244
|
+
const notTrigger = webhooks.some(webhook => {
|
|
245
|
+
return webhook.type && webhook.type != 'trigger'
|
|
246
|
+
})
|
|
247
|
+
return !notTrigger
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
helpers.validateEtaWebhooks = function(webhooks) {
|
|
251
|
+
const notEta = webhooks.some(webhook => {
|
|
252
|
+
return webhook.type && webhook.type != 'eta'
|
|
253
|
+
})
|
|
254
|
+
return !notEta
|
|
255
|
+
}
|
|
256
|
+
|
|
243
257
|
module.exports = helpers
|
package/models/Project.js
CHANGED
|
@@ -15,6 +15,12 @@ let IntegrationSchema = require('../schemas/Integration')
|
|
|
15
15
|
let WebhookSchema = require('../schemas/Webhook')
|
|
16
16
|
let iosConfig = require('../schemas/IosConfig')
|
|
17
17
|
let androidConfig = require('../schemas/AndroidConfig')
|
|
18
|
+
let projectEtaSchema = require('../schemas/ProjectEta')
|
|
19
|
+
|
|
20
|
+
let webhooksValidators = [
|
|
21
|
+
{validator: helpers.validateNotNull},
|
|
22
|
+
{validator: helpers.validateTriggerWebhooks, msg: 'webhooks should contain trigger webhooks only'}
|
|
23
|
+
];
|
|
18
24
|
|
|
19
25
|
let ProjectSchema = new mongoose.Schema({
|
|
20
26
|
_id: {type: String, default: uuidv4},
|
|
@@ -33,14 +39,15 @@ let ProjectSchema = new mongoose.Schema({
|
|
|
33
39
|
lastSyncTime: {type: Date, default: Date.now},
|
|
34
40
|
name: {type: String, required: [true, 'name is required']},
|
|
35
41
|
accountId: {type: String, required: true, validate: {isAsync: false, validator: helpers.validateUUIDv4, msg: 'default error message'}},
|
|
36
|
-
webhooks: {type:[WebhookSchema], validate:
|
|
42
|
+
webhooks: {type:[WebhookSchema], validate: webhooksValidators},
|
|
37
43
|
configurationParameters: {
|
|
38
44
|
iosConfig: iosConfig, // when we want to enable this {type: iosConfig, required: true}
|
|
39
45
|
androidConfig: androidConfig, // when we want to enable this {type: androidConfig, required: true}
|
|
40
46
|
}, // http://collab.bluedot.io/display/PD/Remote+configuration => https://bluedotinnovation.atlassian.net/wiki/spaces/ENG/pages/223150126/Remote+Config+details
|
|
41
47
|
firebaseApiKey: {type: String, validate: helpers.validateNotNull},
|
|
42
48
|
apiKey: {type: String},
|
|
43
|
-
integrations: IntegrationSchema
|
|
49
|
+
integrations: IntegrationSchema,
|
|
50
|
+
eta: {type: [projectEtaSchema]}
|
|
44
51
|
},
|
|
45
52
|
{collection: 'project'})
|
|
46
53
|
|
package/package.json
CHANGED
package/schemas/AndroidConfig.js
CHANGED
|
@@ -21,7 +21,8 @@ let AndroidSchema = new mongoose.Schema({
|
|
|
21
21
|
applicationLoggingEnabled: {type: Boolean, required: true}, //Local logging on the device
|
|
22
22
|
telemetry : telemetrySchema,
|
|
23
23
|
useCaseType : {type: String, enum: useCaseTypeEnum, required: true},
|
|
24
|
-
maximumPageSize: {type: Number, required: true}
|
|
24
|
+
maximumPageSize: {type: Number, required: true},
|
|
25
|
+
enableAlarmClock: {type: Boolean, default: false}
|
|
25
26
|
}, {
|
|
26
27
|
_id: false
|
|
27
28
|
})
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
let mongoose = require('mongoose')
|
|
2
|
+
let WebhookSchema = require('./Webhook')
|
|
3
|
+
let helpers = require('../helpers')
|
|
4
|
+
|
|
5
|
+
let webhooksValidators = [
|
|
6
|
+
{validator: helpers.validateNotNull},
|
|
7
|
+
{validator: helpers.validateEtaWebhooks, msg: 'eta.webhooks should contain eta webhooks only'}
|
|
8
|
+
];
|
|
9
|
+
|
|
10
|
+
let ProjectEtaSchema = new mongoose.Schema({
|
|
11
|
+
webhooks: {type:[WebhookSchema], validate: webhooksValidators}
|
|
12
|
+
}, {
|
|
13
|
+
_id: false
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
module.exports = ProjectEtaSchema
|
package/schemas/Webhook.js
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
let mongoose = require('mongoose')
|
|
2
2
|
let validators = require('../utils/validators')
|
|
3
3
|
|
|
4
|
-
let typeEnum = {
|
|
5
|
-
values: ['trigger'],
|
|
6
|
-
message: 'enum validator failed for path `{PATH}` with value `{VALUE}`'
|
|
7
|
-
}
|
|
8
|
-
|
|
9
4
|
let WebhookSchema = new mongoose.Schema({
|
|
10
|
-
type: {type: String, enum:
|
|
5
|
+
type: {type: String, enum: ['trigger', 'eta'], required: [true, 'webhook type is required']}, // configurationChanged, trigger
|
|
11
6
|
url: {type: String, required: [true, 'URL is required'], validate: {isAsync: false, validator: validators.validateUrl, msg: 'Please enter a valid URL'}},
|
|
12
7
|
headers: {type: mongoose.Schema.Types.Mixed, validate: { isAsync: false, validator: validateHeaderlength, msg: 'Header object can only have 1 key <-> value pair' }}
|
|
13
8
|
}, {
|