@bluedot-innovation/models 7.16.0 → 7.17.0-alpha

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
+ ## 7.16.1
2
+ - Remove attentive webhook and add Attentive project integration
3
+
1
4
  ## 7.16.0
2
5
  - Remove support for beacons and bump json patch dependency for vulnerability
3
6
 
@@ -72,6 +72,10 @@
72
72
  },
73
73
  "flipdish": {
74
74
  "nowReadyEnabled": true
75
+ },
76
+ "attentive": {
77
+ "helloRegister": true,
78
+ "trigger": true
75
79
  }
76
80
  },
77
81
  "tempo": {
@@ -485,27 +485,17 @@ describe('Project', () => {
485
485
  let Project = new ProjectModel(project)
486
486
  Project.validate((err, res) => {
487
487
  assert.exists(err)
488
- assert.match(err.message, /type "register" can only have structure "mobivity" or "attentive"/)
488
+ assert.match(err.message, /type "register" can only have structure "mobivity"/)
489
489
  done()
490
490
  })
491
491
  })
492
- it(`should not validate if the type is register and the structure is not mobivity or attentive`, (done) => {
492
+ it(`should not validate if the type is register and the structure is not mobivity`, (done) => {
493
493
  project.webhooks[0].type = "register"
494
494
  project.webhooks[0].structure = "standard"
495
495
  let Project = new ProjectModel(project)
496
496
  Project.validate((err, res) => {
497
497
  assert.exists(err)
498
- assert.match(err.message, /type "register" can only have structure "mobivity" or "attentive"/)
499
- done()
500
- })
501
- })
502
- it(`should not validate if structure is attentive and the type is not register`, (done) => {
503
- project.webhooks[0].type = "trigger"
504
- project.webhooks[0].structure = "attentive"
505
- let Project = new ProjectModel(project)
506
- Project.validate((err, res) => {
507
- assert.exists(err)
508
- assert.match(err.message, /type "register" can only have structure "mobivity" or "attentive"/)
498
+ assert.match(err.message, /type "register" can only have structure "mobivity"/)
509
499
  done()
510
500
  })
511
501
  })
@@ -609,6 +599,27 @@ describe('Project', () => {
609
599
  })
610
600
  })
611
601
  })
602
+ describe("Attentive integration validation", () => {
603
+ it('should throw an error when trigger is non boolean', (done) => {
604
+ project.integrations.attentive.trigger = "invalid"
605
+ let Project = new ProjectModel(project)
606
+ Project.validate((err, res) => {
607
+ assert.exists(err)
608
+ assert.match(err.message, /Cast to Boolean failed for value "invalid" .* at path "trigger"/)
609
+ done()
610
+ })
611
+ })
612
+
613
+ it('should throw an error when helloRegister is non boolean', (done) => {
614
+ project.integrations.attentive.helloRegister = "invalid"
615
+ let Project = new ProjectModel(project)
616
+ Project.validate((err, res) => {
617
+ assert.exists(err)
618
+ assert.match(err.message, /Cast to Boolean failed for value "invalid" .* at path "helloRegister"/)
619
+ done()
620
+ })
621
+ })
622
+ })
612
623
  })
613
624
 
614
625
  describe('should throw an error when any of the values of the array contains a falsy value', () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bluedot-innovation/models",
3
- "version": "7.16.0",
3
+ "version": "7.17.0-alpha",
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",
@@ -23,7 +23,7 @@
23
23
  "eslint-plugin-promise": "^3.6.0",
24
24
  "eslint-plugin-standard": "^3.0.1",
25
25
  "mocha": "^4.0.1",
26
- "mongodb": "^3.6.3",
26
+ "mongodb": "^5.1.0",
27
27
  "nyc": "^11.3.0",
28
28
  "prettier": "^1.13.5",
29
29
  "sinon": "^4.1.2"
@@ -37,7 +37,7 @@
37
37
  "deep-equal": "^1.0.1",
38
38
  "fast-deep-equal": "^2.0.1",
39
39
  "lodash.clonedeep": "4.5.0",
40
- "mongoose": "^5.11.4",
40
+ "mongoose": "^6.10.4",
41
41
  "uuid": "^3.1.0"
42
42
  }
43
43
  }
@@ -4,6 +4,7 @@ const segmentIntegrationSchema = require('./SegmentIntegration')
4
4
  const oneSignalIntegrationSchema = require('./OneSignalIntegration')
5
5
  const bbotIntegrationSchema = require('./BbotIntegration')
6
6
  const flipdishIntegrationSchema = require('./FlipdishIntegration')
7
+ const projectAttentiveIntegrationSchema = require('./ProjectAttentiveIntegration')
7
8
 
8
9
 
9
10
  const MParticleSchema = new mongoose.Schema({
@@ -56,7 +57,8 @@ const IntegrationSchema = new mongoose.Schema({
56
57
  segment: { type: segmentIntegrationSchema },
57
58
  oneSignal: { type: oneSignalIntegrationSchema },
58
59
  bbot: { type: bbotIntegrationSchema },
59
- flipdish: { type: flipdishIntegrationSchema }
60
+ flipdish: { type: flipdishIntegrationSchema },
61
+ attentive: { type: projectAttentiveIntegrationSchema }
60
62
  },{ _id : false });
61
63
  function apiKeyValidator(value){
62
64
  // check if the value is a non-empty string
@@ -0,0 +1,10 @@
1
+ const mongoose = require('mongoose');
2
+
3
+ let ProjectAttentiveIntegrationSchema = new mongoose.Schema({
4
+ helloRegister: {type: Boolean, required: true},
5
+ trigger: {type: Boolean, required: true}
6
+ }, {
7
+ _id: false
8
+ })
9
+
10
+ module.exports = ProjectAttentiveIntegrationSchema
@@ -28,9 +28,9 @@ function validateMobivityRequiredFields(structure){
28
28
  }
29
29
 
30
30
  function validateTypeAndStructure(type) {
31
- if ((type === "register" && !['mobivity', 'attentive'].includes(this.structure))
32
- || (type !== "register" && ['mobivity', 'attentive'].includes(this.structure))) {
33
- throw new Error('type "register" can only have structure "mobivity" or "attentive"')
31
+ if ((type === "register" && !['mobivity'].includes(this.structure))
32
+ || (type !== "register" && ['mobivity'].includes(this.structure))) {
33
+ throw new Error('type "register" can only have structure "mobivity"')
34
34
  } else if ((type === "helloOrder" && this.structure !== 'default')
35
35
  || (type !== "helloOrder" && this.structure === 'default')) {
36
36
  throw new Error('type "helloOrder" can only have structure "default"')
@@ -44,7 +44,7 @@ let WebhookSchema = new mongoose.Schema({
44
44
  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' }]},
45
45
  structure: {
46
46
  type: String,
47
- enum: ['standard', 'tealium', 'mobivity', 'attentive', 'default'],
47
+ enum: ['standard', 'tealium', 'mobivity', 'default'],
48
48
  default: 'standard',
49
49
  validate: [
50
50
  {validator: validateTealiumRequiredFields, msg: 'tealium webhooks require "tealium_account" and "tealium_profile" body fields to be present'},
@@ -4,26 +4,27 @@ const {createAllIndexesIfNotExists} = require("./indexInitialiser");
4
4
  const MONGO_DB_URI = process.env.MONGO_DB_URI
5
5
  const DB_NAME = process.env.DB_NAME
6
6
  const ENVIRONMENT = process.env.ENVIRONMENT
7
- const client = new MongoClient(MONGO_DB_URI, { useUnifiedTopology: true })
7
+ const client = new MongoClient(MONGO_DB_URI)
8
8
 
9
9
  console.log(`Using DB_NAME:${DB_NAME} in ENVIRONMENT:${ENVIRONMENT}`)
10
10
 
11
- client.connect(async error => {
12
- if(error){
13
- console.log("Failed to connect to Mongo DB", error)
14
- process.exit(1)
15
- }
16
- console.log("Connected to Mongo DB")
11
+ try {
12
+ await client.connect()
13
+ } catch (error) {
14
+ console.log("Failed to connect to Mongo DB", error)
15
+ process.exit(1)
16
+ }
17
17
 
18
- const db = client.db(DB_NAME)
18
+ console.log("Connected to Mongo DB")
19
19
 
20
- try{
21
- await createAllIndexesIfNotExists(db)
22
- }catch(error){
23
- console.log(error)
24
- await client.close()
25
- process.exit(1)
26
- }
20
+ const db = client.db(DB_NAME)
27
21
 
22
+ try{
23
+ await createAllIndexesIfNotExists(db)
24
+ } catch(error) {
25
+ console.log(error)
28
26
  await client.close()
29
- })
27
+ process.exit(1)
28
+ }
29
+
30
+ await client.close()