@bluedot-innovation/models 6.0.2 → 6.0.6

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,12 @@
1
+ ## 6.0.6
2
+ - Add validations to User fields
3
+
4
+ ## 6.0.4
5
+ - Update mparticle fieldnames
6
+
7
+ ## 6.0.3
8
+ - fix headers not validating when provided a single-character primitive value
9
+
1
10
  ## 5.1.53
2
11
  - change validation mesages of mParticle
3
12
 
@@ -16,10 +16,10 @@
16
16
  "firebaseApiKey": "88888888-4444-4444-4444-121212121212",
17
17
  "apiKey": "88888888-4444-4444-4444-123412341234",
18
18
  "integrations":{
19
- "mParticle": {
19
+ "mparticle": {
20
20
  "androidApiKey": "us1-c5e6eefe90fe704aba0a7d2daa00baaa",
21
- "androidSecret": "eZqphc1Vh2dqaIQEvz4APNbErZkW_AaaRmwE8BCmYpHZFc3n_ZKajTLgJgFqLNNN",
22
- "iOSApiKey": "us1-a5e6eefe90fe704aba0a7d2daa00baaa",
23
- "iOSSecret": "fZqphc1Vh2dqaIQEvz4APNbErZkW_AaaRmwE8BCmYpHZFc3n_ZKajTLgJgFqLNNN"
21
+ "androidSecretKey": "eZqphc1Vh2dqaIQEvz4APNbErZkW_AaaRmwE8BCmYpHZFc3n_ZKajTLgJgFqLNNN",
22
+ "iosApiKey": "us1-a5e6eefe90fe704aba0a7d2daa00baaa",
23
+ "iosSecretKey": "fZqphc1Vh2dqaIQEvz4APNbErZkW_AaaRmwE8BCmYpHZFc3n_ZKajTLgJgFqLNNN"
24
24
  }
25
25
  }}
@@ -22,7 +22,7 @@ beforeEach(() => {
22
22
 
23
23
  testCase('Project', () => {
24
24
  testCase('Valid Project ', () => {
25
- assertions('should validate a valid project ', (done) => {
25
+ assertions('should validate a valid project ', (done) => {
26
26
  let Project = new ProjectModel(project)
27
27
  Project.validate((err, res) => {
28
28
  assert.notExists(res)
@@ -82,7 +82,7 @@ testCase('Project', () => {
82
82
  testCase('mparticle integration check', () => {
83
83
  assertions('should throw an error if the mparticle integration has empty key ', (done) => {
84
84
 
85
- project.integrations.mParticle.androidApiKey = null
85
+ project.integrations.mparticle.androidApiKey = null
86
86
 
87
87
  let Project = new ProjectModel(project)
88
88
  Project.validate((err, res) => {
@@ -93,27 +93,27 @@ testCase('Project', () => {
93
93
  })
94
94
  assertions('should throw an error if the mparticle integration has a key with empty string ', (done) => {
95
95
 
96
- project.integrations.mParticle.iOSApiKey = ''
96
+ project.integrations.mparticle.iosApiKey = ''
97
97
  let Project = new ProjectModel(project)
98
98
  Project.validate((err, res) => {
99
99
  assert.exists(err)
100
- assert.match(err.message, /iOSApiKey should be a non-empty string/)
100
+ assert.match(err.message, /iosApiKey should be a non-empty string/)
101
101
  done()
102
102
  })
103
103
  })
104
104
  assertions('should throw an error if the mparticle integration has a secret key with empty string ', (done) => {
105
105
 
106
- project.integrations.mParticle.iOSSecret = ''
106
+ project.integrations.mparticle.iosSecretKey = ''
107
107
  let Project = new ProjectModel(project)
108
108
  Project.validate((err, res) => {
109
109
  assert.exists(err)
110
- assert.match(err.message, /iOSSecret should be a non-empty string/)
110
+ assert.match(err.message, /iosSecretKey should be a non-empty string/)
111
111
  done()
112
112
  })
113
113
  })
114
114
  assertions('should throw an error if the mparticle integration misses all keys ', (done) => {
115
115
 
116
- project.integrations.mParticle = {}
116
+ project.integrations.mparticle = {}
117
117
 
118
118
  let Project = new ProjectModel(project)
119
119
  Project.validate((err, res) => {
@@ -124,8 +124,8 @@ testCase('Project', () => {
124
124
  })
125
125
  assertions('should throw an error if the mparticle integration misses both keys ', (done) => {
126
126
 
127
- delete project.integrations.mParticle.iOSApiKey
128
- delete project.integrations.mParticle.androidApiKey
127
+ delete project.integrations.mparticle.iosApiKey
128
+ delete project.integrations.mparticle.androidApiKey
129
129
 
130
130
  let Project = new ProjectModel(project)
131
131
  Project.validate((err, res) => {
@@ -136,8 +136,8 @@ testCase('Project', () => {
136
136
  })
137
137
  assertions('should throw an error if the mparticle integration misses both secret keys ', (done) => {
138
138
 
139
- delete project.integrations.mParticle.iOSSecret
140
- delete project.integrations.mParticle.androidSecret
139
+ delete project.integrations.mparticle.iosSecretKey
140
+ delete project.integrations.mparticle.androidSecretKey
141
141
 
142
142
  let Project = new ProjectModel(project)
143
143
  Project.validate((err, res) => {
@@ -148,30 +148,30 @@ testCase('Project', () => {
148
148
  })
149
149
  assertions('should throw an error if the mparticle integration has valid android key pair, but no Ios secret ', (done) => {
150
150
 
151
- delete project.integrations.mParticle.iOSSecret
151
+ delete project.integrations.mparticle.iosSecretKey
152
152
 
153
153
  let Project = new ProjectModel(project)
154
154
  Project.validate((err, res) => {
155
155
  assert.exists(err)
156
- assert.match(err.message, /both iOSSecret and iOSApiKey are required/)
156
+ assert.match(err.message, /both iosSecretKey and iosApiKey are required/)
157
157
  done()
158
158
  })
159
159
  })
160
160
  assertions('should throw an error if the mparticle integration has valid Ios key pair, but no android secret ', (done) => {
161
161
 
162
- delete project.integrations.mParticle.androidSecret
162
+ delete project.integrations.mparticle.androidSecretKey
163
163
 
164
164
  let Project = new ProjectModel(project)
165
165
  Project.validate((err, res) => {
166
166
  assert.exists(err)
167
- assert.match(err.message, /both androidSecret and androidApiKey are required/)
167
+ assert.match(err.message, /both androidSecretKey and androidApiKey are required/)
168
168
  done()
169
169
  })
170
170
  })
171
171
  assertions('should validate if the mparticle integration has only Android key ', (done) => {
172
172
 
173
- delete project.integrations.mParticle.androidApiKey
174
- delete project.integrations.mParticle.androidSecret
173
+ delete project.integrations.mparticle.androidApiKey
174
+ delete project.integrations.mparticle.androidSecretKey
175
175
 
176
176
  let Project = new ProjectModel(project)
177
177
  Project.validate((err, res) => {
@@ -224,6 +224,17 @@ testCase('Project', () => {
224
224
  helpers.testNullValue(project, ProjectModel, done)
225
225
  })
226
226
 
227
+ it(`should throw an error when webhooks has primitive value in headers`, (done) => {
228
+ project = JSON.parse(JSON.stringify(project))
229
+ project.webhooks.headers = 'primitive'
230
+ helpers.testNullValue(project, ProjectModel, done)
231
+ })
232
+ it(`should throw an error when webhooks has array in headers`, (done) => {
233
+ project = JSON.parse(JSON.stringify(project))
234
+ project.webhooks.headers = ['array']
235
+ helpers.testNullValue(project, ProjectModel, done)
236
+ })
237
+
227
238
  it(`should throw an error when firebaseApiKey is null`, (done) => {
228
239
  project = JSON.parse(JSON.stringify(project))
229
240
  project.firebaseApiKey = null
@@ -1,7 +1,9 @@
1
1
  module.exports = {
2
2
  requiredFields: ['username', 'firstName', 'lastName', 'isAdmin', 'accountId'],
3
3
  customValidators: [
4
- {name: 'phoneNumber', invalidInputs: ['409203492039284232034398']},
4
+ {name: 'phoneNumber', invalidInputs: ['409203492039284232034398','1','1234']},
5
+ {name: 'firstName', invalidInputs: ['F']},
6
+ {name: 'lastName', invalidInputs: ['L']},
5
7
  {name: 'creationTime', invalidInputs: ['21/07/2017', 'thursday']},
6
8
  {name: 'lastUpdateTime', invalidInputs: ['21/07/2017', 'saturday']}
7
9
  ],
package/models/User.js CHANGED
@@ -26,9 +26,9 @@ let UserSchema = new mongoose.Schema({
26
26
  message: '{VALUE} is not a valid email'
27
27
  }
28
28
  },
29
- firstName: {type: String, required: true},
30
- lastName: {type: String, required: true},
31
- phoneNumber: {type: String, maxlength: 20, validate: helpers.validateNotNull},
29
+ firstName: {type: String, required: true, minlength:2, maxlength:120},
30
+ lastName: {type: String, required: true, minlength:2, maxlength:120},
31
+ phoneNumber: {type: String, minlength:8, maxlength: 20, validate: helpers.validateNotNull},
32
32
  state: {type: String, default: StateEnum.ACTIVE},
33
33
  creationTime: {type: Date, default: Date.now},
34
34
  lastUpdateTime: {type: Date, default: Date.now},
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bluedot-innovation/models",
3
- "version": "6.0.2",
3
+ "version": "6.0.6",
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",
@@ -10,41 +10,41 @@ const MParticleSchema = new mongoose.Schema({
10
10
  msg:'androidApiKey should be a non-empty string, found ${VALUE}'
11
11
  }
12
12
  },
13
- androidSecret: {
13
+ androidSecretKey: {
14
14
  type: String,
15
15
  validate:{
16
16
  validator:apiKeyValidator,
17
- msg:'androidSecret should be a non-empty string, found ${VALUE}'
17
+ msg:'androidSecretKey should be a non-empty string, found ${VALUE}'
18
18
  }
19
19
  },
20
- iOSApiKey:{
20
+ iosApiKey:{
21
21
  type:String,
22
22
  validate:{
23
23
  validator:apiKeyValidator,
24
- msg:'iOSApiKey should be a non-empty string, found ${VALUE}'
24
+ msg:'iosApiKey should be a non-empty string, found ${VALUE}'
25
25
  }
26
26
  },
27
- iOSSecret:{
27
+ iosSecretKey:{
28
28
  type:String,
29
29
  validate:{
30
30
  validator:apiKeyValidator,
31
- msg:'iOSSecret should be a non-empty string, found ${VALUE}'
31
+ msg:'iosSecretKey should be a non-empty string, found ${VALUE}'
32
32
  }
33
33
  }
34
34
  },{ _id : false })
35
35
 
36
36
  const IntegrationSchema = new mongoose.Schema({
37
- mParticle: {
37
+ mparticle: {
38
38
  type: MParticleSchema,
39
39
  validate: [{
40
40
  validator: mParticleValidator,
41
- msg: 'either of the two field combinations is mandatory: androidApiKey & androidSecret OR iOSApiKey & iOSSecret'
41
+ msg: 'either of the two field combinations is mandatory: androidApiKey & androidSecretKey OR iosApiKey & iosSecretKey'
42
42
  },{
43
43
  validator:iOSPairValidator,
44
- msg: 'both iOSSecret and iOSApiKey are required'
44
+ msg: 'both iosSecretKey and iosApiKey are required'
45
45
  },{
46
46
  validator:androidPairValidator,
47
- msg: 'both androidSecret and androidApiKey are required'
47
+ msg: 'both androidSecretKey and androidApiKey are required'
48
48
  }
49
49
  ],
50
50
  required: true
@@ -55,25 +55,25 @@ function apiKeyValidator(value){
55
55
  return !(typeof value !=='string' || value.trim() === '')
56
56
  }
57
57
  function iOSPairValidator(value){
58
- const {iOSApiKey,iOSSecret} = value
59
- const isIOSApiKeyProvided = (iOSApiKey !== undefined)
60
- const isIOSSecretProvided = (iOSSecret !== undefined)
58
+ const {iosApiKey,iosSecretKey} = value
59
+ const isIOSApiKeyProvided = (iosApiKey !== undefined)
60
+ const isIOSSecretProvided = (iosSecretKey !== undefined)
61
61
 
62
62
  return isIOSApiKeyProvided === isIOSSecretProvided
63
63
  }
64
64
 
65
65
  function androidPairValidator(value){
66
- const {androidApiKey,androidSecret} = value
66
+ const {androidApiKey,androidSecretKey} = value
67
67
  const isAndroidApiKeyProvided = (androidApiKey !== undefined)
68
- const isAndroidSecretProvided = (androidSecret !== undefined)
68
+ const isAndroidSecretProvided = (androidSecretKey !== undefined)
69
69
 
70
70
  return isAndroidApiKeyProvided === isAndroidSecretProvided
71
71
  }
72
72
 
73
73
  function mParticleValidator(value) {
74
- const { androidApiKey,androidSecret, iOSApiKey,iOSSecret } = value;
75
- const isAndroidPairProvided = ((androidApiKey !== undefined)&&(androidSecret !==undefined))
76
- const isIosPairProvided = ((iOSApiKey !== undefined)&&(iOSSecret !==undefined))
74
+ const { androidApiKey,androidSecretKey, iosApiKey,iosSecretKey } = value;
75
+ const isAndroidPairProvided = ((androidApiKey !== undefined)&&(androidSecretKey !==undefined))
76
+ const isIosPairProvided = ((iosApiKey !== undefined)&&(iosSecretKey !==undefined))
77
77
 
78
78
  return isIosPairProvided || isAndroidPairProvided;
79
79
  }
@@ -16,7 +16,18 @@ let WebhookSchema = new mongoose.Schema({
16
16
 
17
17
  // https://bluedotinnovation.atlassian.net/browse/BP-1500 -- Limiting headers to 1
18
18
  function validateHeaderlength (headers) {
19
- return Object.keys(headers).length <= 1
19
+ // handles the case of headers being a primitive value
20
+ if(typeof headers !== 'object' || Array.isArray(headers)){
21
+ return false
22
+ }
23
+ const headerKeys = Object.keys(headers)
24
+ // only one key-value pair is allowed
25
+ if(headerKeys.length > 1){
26
+ return false
27
+ }
28
+ const key = headerKeys[0]
29
+ // the value should be present
30
+ return headers[key]
20
31
  }
21
32
 
22
33
  module.exports = WebhookSchema