@bluedot-innovation/models 8.2.3 → 8.2.4

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,6 @@
1
+ ## 8.2.4
2
+ - Add webApiKey and event flags for mParticle integration
3
+
1
4
  ## 8.2.3
2
5
  - Move helloSsoCode from destination to project model
3
6
 
@@ -47,9 +47,13 @@
47
47
  "integrations":{
48
48
  "mparticle": {
49
49
  "androidApiKey": "us1-c5e6eefe90fe704aba0a7d2daa00baaa",
50
- "androidSecretKey": "eZqphc1Vh2dqaIQEvz4APNbErZkW_AaaRmwE8BCmYpHZFc3n_ZKajTLgJgFqLNNN",
51
50
  "iosApiKey": "us1-a5e6eefe90fe704aba0a7d2daa00baaa",
52
- "iosSecretKey": "fZqphc1Vh2dqaIQEvz4APNbErZkW_AaaRmwE8BCmYpHZFc3n_ZKajTLgJgFqLNNN"
51
+ "webApiKey": "us1-a5e6eefe90fe704aba0a7d2daa00baaa",
52
+ "trigger": true,
53
+ "tempo": true,
54
+ "wave": true,
55
+ "hello": true,
56
+ "environment": "production"
53
57
  },
54
58
  "olo": {
55
59
  "sharedSecret": "jhFGJHKJhkHIjklJ",
@@ -157,16 +157,7 @@ describe('Project', () => {
157
157
  done()
158
158
  })
159
159
  })
160
- assertions('should throw an error if the mparticle integration has a secret key with empty string ', (done) => {
161
-
162
- project.integrations.mparticle.iosSecretKey = ''
163
- let Project = new ProjectModel(project)
164
- Project.validate((err, res) => {
165
- assert.exists(err)
166
- assert.match(err.message, /iosSecretKey should be a non-empty string/)
167
- done()
168
- })
169
- })
160
+
170
161
  assertions('should throw an error if the mparticle integration misses all keys ', (done) => {
171
162
 
172
163
  project.integrations.mparticle = {}
@@ -174,64 +165,55 @@ describe('Project', () => {
174
165
  let Project = new ProjectModel(project)
175
166
  Project.validate((err, res) => {
176
167
  assert.exists(err)
177
- assert.match(err.message, /either of the two field combinations is mandatory/)
168
+ assert.match(err.message, /At least one of Android, iOS or Web keys need to be provided/)
178
169
  done()
179
170
  })
180
171
  })
181
- assertions('should throw an error if the mparticle integration misses both keys ', (done) => {
172
+
173
+ assertions('should throw an error if trigger is selected but no android or ios keys provided', (done) => {
182
174
 
183
- delete project.integrations.mparticle.iosApiKey
184
175
  delete project.integrations.mparticle.androidApiKey
176
+ delete project.integrations.mparticle.iosApiKey
185
177
 
186
178
  let Project = new ProjectModel(project)
187
179
  Project.validate((err, res) => {
188
180
  assert.exists(err)
189
- assert.match(err.message, /either of the two field combinations is mandatory/)
181
+ assert.match(err.message, /Either Android or iOS keys need to be provided/)
190
182
  done()
191
183
  })
192
184
  })
193
- assertions('should throw an error if the mparticle integration misses both secret keys ', (done) => {
185
+ assertions('should throw an error if tempo is selected but no android or ios keys provided', (done) => {
194
186
 
195
- delete project.integrations.mparticle.iosSecretKey
196
- delete project.integrations.mparticle.androidSecretKey
187
+ delete project.integrations.mparticle.androidApiKey
188
+ delete project.integrations.mparticle.iosApiKey
197
189
 
198
190
  let Project = new ProjectModel(project)
199
191
  Project.validate((err, res) => {
200
192
  assert.exists(err)
201
- assert.match(err.message, /either of the two field combinations is mandatory/)
193
+ assert.match(err.message, /Either Android or iOS keys need to be provided/)
202
194
  done()
203
195
  })
204
196
  })
205
- assertions('should throw an error if the mparticle integration has valid android key pair, but no Ios secret ', (done) => {
206
197
 
207
- delete project.integrations.mparticle.iosSecretKey
198
+ assertions('should throw an error if wave is selected but no web keys provided', (done) => {
208
199
 
209
- let Project = new ProjectModel(project)
210
- Project.validate((err, res) => {
211
- assert.exists(err)
212
- assert.match(err.message, /both iosSecretKey and iosApiKey are required/)
213
- done()
214
- })
215
- })
216
- assertions('should throw an error if the mparticle integration has valid Ios key pair, but no android secret ', (done) => {
217
-
218
- delete project.integrations.mparticle.androidSecretKey
200
+ delete project.integrations.mparticle.webApiKey
219
201
 
220
202
  let Project = new ProjectModel(project)
221
203
  Project.validate((err, res) => {
222
204
  assert.exists(err)
223
- assert.match(err.message, /both androidSecretKey and androidApiKey are required/)
205
+ assert.match(err.message, /Web keys need to be provided/)
224
206
  done()
225
207
  })
226
208
  })
227
- assertions('should validate if the mparticle integration has only Android key ', (done) => {
209
+ assertions('should throw an error if hello is selected but no web keys provided', (done) => {
228
210
 
229
- delete project.integrations.mparticle.androidApiKey
230
- delete project.integrations.mparticle.androidSecretKey
211
+ delete project.integrations.mparticle.webApiKey
231
212
 
232
213
  let Project = new ProjectModel(project)
233
214
  Project.validate((err, res) => {
234
- assert.notExists(res)
215
+ assert.exists(err)
216
+ assert.match(err.message, /Web keys need to be provided/)
235
217
  done()
236
218
  })
237
219
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bluedot-innovation/models",
3
- "version": "8.2.3",
3
+ "version": "8.2.4",
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",
@@ -6,54 +6,15 @@ const bbotIntegrationSchema = require('./BbotIntegration')
6
6
  const flipdishIntegrationSchema = require('./FlipdishIntegration')
7
7
  const projectAttentiveIntegrationSchema = require('./ProjectAttentiveIntegration')
8
8
  const incentivioIntegrationSchema = require('./IncentivioIntegration')
9
+ const mparticleIntegrationSchema = require('./MparticleIntegration')
9
10
 
10
-
11
- const MParticleSchema = new mongoose.Schema({
12
- androidApiKey: {
13
- type: String,
14
- validate:{
15
- validator:apiKeyValidator,
16
- msg:'androidApiKey should be a non-empty string, found ${VALUE}'
17
- }
18
- },
19
- androidSecretKey: {
20
- type: String,
21
- validate:{
22
- validator:apiKeyValidator,
23
- msg:'androidSecretKey should be a non-empty string, found ${VALUE}'
24
- }
25
- },
26
- iosApiKey:{
27
- type:String,
28
- validate:{
29
- validator:apiKeyValidator,
30
- msg:'iosApiKey should be a non-empty string, found ${VALUE}'
31
- }
32
- },
33
- iosSecretKey:{
34
- type:String,
35
- validate:{
36
- validator:apiKeyValidator,
37
- msg:'iosSecretKey should be a non-empty string, found ${VALUE}'
38
- }
39
- }
40
- },{ _id : false })
11
+ function mParticleValidator(value) {
12
+ const { androidApiKey, iosApiKey, webApiKey } = value;
13
+ return (!!androidApiKey || !!iosApiKey || !!webApiKey)
14
+ }
41
15
 
42
16
  const IntegrationSchema = new mongoose.Schema({
43
- mparticle: {
44
- type: MParticleSchema,
45
- validate: [{
46
- validator: mParticleValidator,
47
- msg: 'either of the two field combinations is mandatory: androidApiKey & androidSecretKey OR iosApiKey & iosSecretKey'
48
- },{
49
- validator:iOSPairValidator,
50
- msg: 'both iosSecretKey and iosApiKey are required'
51
- },{
52
- validator:androidPairValidator,
53
- msg: 'both androidSecretKey and androidApiKey are required'
54
- }
55
- ]
56
- },
17
+ mparticle: { type: mparticleIntegrationSchema, validate:{ validator: mParticleValidator, msg:'At least one of Android, iOS or Web keys need to be provided'} },
57
18
  olo: { type: oloIntegrationSchema },
58
19
  segment: { type: segmentIntegrationSchema },
59
20
  oneSignal: { type: oneSignalIntegrationSchema },
@@ -62,32 +23,5 @@ const IntegrationSchema = new mongoose.Schema({
62
23
  attentive: { type: projectAttentiveIntegrationSchema },
63
24
  incentivio: { type: incentivioIntegrationSchema }
64
25
  },{ _id : false });
65
- function apiKeyValidator(value){
66
- // check if the value is a non-empty string
67
- return !(typeof value !=='string' || value.trim() === '')
68
- }
69
- function iOSPairValidator(value){
70
- const {iosApiKey,iosSecretKey} = value
71
- const isIOSApiKeyProvided = (iosApiKey !== undefined)
72
- const isIOSSecretProvided = (iosSecretKey !== undefined)
73
-
74
- return isIOSApiKeyProvided === isIOSSecretProvided
75
- }
76
-
77
- function androidPairValidator(value){
78
- const {androidApiKey,androidSecretKey} = value
79
- const isAndroidApiKeyProvided = (androidApiKey !== undefined)
80
- const isAndroidSecretProvided = (androidSecretKey !== undefined)
81
-
82
- return isAndroidApiKeyProvided === isAndroidSecretProvided
83
- }
84
-
85
- function mParticleValidator(value) {
86
- const { androidApiKey,androidSecretKey, iosApiKey,iosSecretKey } = value;
87
- const isAndroidPairProvided = ((androidApiKey !== undefined)&&(androidSecretKey !==undefined))
88
- const isIosPairProvided = ((iosApiKey !== undefined)&&(iosSecretKey !==undefined))
89
-
90
- return isIosPairProvided || isAndroidPairProvided;
91
- }
92
26
 
93
27
  module.exports = IntegrationSchema
@@ -0,0 +1,82 @@
1
+ const mongoose = require('mongoose');
2
+
3
+ function apiKeyValidator(value){
4
+ // check if the value is a non-empty string
5
+ return !(typeof value !=='string' || value.trim() === '')
6
+ }
7
+
8
+ function mobileValidator() {
9
+ if (!this.androidApiKey && !this.iosApiKey) {
10
+ return false
11
+ } else {
12
+ return true
13
+ }
14
+ }
15
+
16
+ function webValidator() {
17
+ if (!this.webApiKey) {
18
+ return false
19
+ } else {
20
+ return true
21
+ }
22
+ }
23
+
24
+ //TODO: remove androidSecretKey & iosSecretKey after mparticle BD-5008 released
25
+ let MparticleIntegrationSchema = new mongoose.Schema({
26
+ androidApiKey: {
27
+ type: String,
28
+ validate:{
29
+ validator:apiKeyValidator,
30
+ msg:'androidApiKey should be a non-empty string, found ${VALUE}'
31
+ }
32
+ },
33
+ androidSecretKey: { type: String },
34
+ iosApiKey:{
35
+ type:String,
36
+ validate:{
37
+ validator:apiKeyValidator,
38
+ msg:'iosApiKey should be a non-empty string, found ${VALUE}'
39
+ }
40
+ },
41
+ iosSecretKey:{ type:String },
42
+ webApiKey:{
43
+ type:String,
44
+ validate:{
45
+ validator:apiKeyValidator,
46
+ msg:'iosApiKey should be a non-empty string, found ${VALUE}'
47
+ }
48
+ },
49
+ trigger: {
50
+ type: Boolean,
51
+ validate:{
52
+ validator:mobileValidator,
53
+ msg:'Either Android or iOS keys need to be provided'
54
+ }
55
+ },
56
+ tempo: {
57
+ type: Boolean,
58
+ validate:{
59
+ validator:mobileValidator,
60
+ msg:'Either Android or iOS keys need to be provided'
61
+ }
62
+ },
63
+ wave: {
64
+ type: Boolean,
65
+ validate:{
66
+ validator:webValidator,
67
+ msg:'Web keys need to be provided'
68
+ }
69
+ },
70
+ hello: {
71
+ type: Boolean,
72
+ validate:{
73
+ validator:webValidator,
74
+ msg:'Web keys need to be provided'
75
+ }
76
+ },
77
+ environment: { type: String, default: "production" }
78
+ }, {
79
+ _id: false
80
+ })
81
+
82
+ module.exports = MparticleIntegrationSchema