@bluedot-innovation/models 7.5.7 → 7.6.0

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,9 @@
1
+ ## 7.6.0
2
+ - Add Attentive Integration to account and webhook
3
+
4
+ ## 7.5.8
5
+ - Add CEMD Persistencce feature
6
+
1
7
  ## 7.5.7
2
8
  - Add Olo integration
3
9
 
@@ -21,6 +21,12 @@
21
21
  },
22
22
  "insights": {
23
23
  "enabled": true
24
+ },
25
+ "cemdPersistence": {
26
+ "whitelistedFields": [
27
+ "hs_field1",
28
+ "hs_field2"
29
+ ]
24
30
  }
25
31
  },
26
32
  "integrations": {
@@ -36,6 +42,9 @@
36
42
  "enterpriseId": 1234567,
37
43
  "organizationId": 12345,
38
44
  "allowedFields": ["example-allowed-fields"]
45
+ },
46
+ "attentive": {
47
+ "enabled": true
39
48
  }
40
49
  }
41
50
  }
@@ -39,6 +39,28 @@ testCase('Account', () => {
39
39
  done()
40
40
  })
41
41
  })
42
+
43
+ it('Should valid the account when CEMD whitelistedFields is null', (done) => {
44
+ account = JSON.parse(JSON.stringify(account))
45
+ account.features.cemdPersistence.whitelistedFields = null
46
+ const Account = new AccountModel(account)
47
+ Account.validate((err, res) => {
48
+ assert.notExists(res)
49
+ assert(err === null, 'err equals null')
50
+ done()
51
+ })
52
+ })
53
+
54
+ it('Should valid the account when CEMD whitelistedFields is undefined', (done) => {
55
+ account = JSON.parse(JSON.stringify(account))
56
+ delete account.features.cemdPersistence.whitelistedFields
57
+ const Account = new AccountModel(account)
58
+ Account.validate((err, res) => {
59
+ assert.notExists(res)
60
+ assert(err === null, 'err equals null')
61
+ done()
62
+ })
63
+ })
42
64
  })
43
65
 
44
66
  testCase('Invalid Account', () => {
@@ -450,17 +450,27 @@ describe('Project', () => {
450
450
  let Project = new ProjectModel(project)
451
451
  Project.validate((err, res) => {
452
452
  assert.exists(err)
453
- assert.match(err.message, /type "register" can only have structure "mobivity"/)
453
+ assert.match(err.message, /type "register" can only have structure "mobivity" or "attentive"/)
454
454
  done()
455
455
  })
456
456
  })
457
- it(`should not validate if the type is register and the structure is not mobivity`, (done) => {
457
+ it(`should not validate if the type is register and the structure is not mobivity or attentive`, (done) => {
458
458
  project.webhooks[0].type = "register"
459
459
  project.webhooks[0].structure = "standard"
460
460
  let Project = new ProjectModel(project)
461
461
  Project.validate((err, res) => {
462
462
  assert.exists(err)
463
- assert.match(err.message, /type "register" can only have structure "mobivity"/)
463
+ assert.match(err.message, /type "register" can only have structure "mobivity" or "attentive"/)
464
+ done()
465
+ })
466
+ })
467
+ it(`should not validate if structure is attentive and the type is not register`, (done) => {
468
+ project.webhooks[0].type = "trigger"
469
+ project.webhooks[0].structure = "attentive"
470
+ let Project = new ProjectModel(project)
471
+ Project.validate((err, res) => {
472
+ assert.exists(err)
473
+ assert.match(err.message, /type "register" can only have structure "mobivity" or "attentive"/)
464
474
  done()
465
475
  })
466
476
  })
package/models/Account.js CHANGED
@@ -7,6 +7,7 @@ let mongoose = require('mongoose')
7
7
  let StateEnum = require('@bluedot-innovation/enums').StateEnum
8
8
  let accountFeatures = require('../schemas/AccountFeatures')
9
9
  const SfmcIntegration = require('../schemas/SfmcIntegration')
10
+ const AttentiveIntegration = require('../schemas/AttentiveIntegration')
10
11
  let uuidv4 = require('uuid/v4')
11
12
  let patcher = require('@bluedot-innovation/mongoose-json-patch')
12
13
  const helpers = require('../helpers')
@@ -29,7 +30,8 @@ let AccountSchema = new mongoose.Schema({
29
30
  creationTime: {type: Date, default: Date.now},
30
31
  lastUpdateTime: {type: Date, default: Date.now},
31
32
  integrations: {
32
- sfmc: {type: SfmcIntegration}
33
+ sfmc: {type: SfmcIntegration},
34
+ attentive: {type: AttentiveIntegration}
33
35
  }
34
36
  },
35
37
  {collection: 'account'})
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bluedot-innovation/models",
3
- "version": "7.5.7",
3
+ "version": "7.6.0",
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",
@@ -0,0 +1,9 @@
1
+ let mongoose = require('mongoose')
2
+
3
+ let AccountCemdPersistenceSchema = new mongoose.Schema({
4
+ whitelistedFields: {type: [String]}
5
+ }, {
6
+ _id: false
7
+ })
8
+
9
+ module.exports = AccountCemdPersistenceSchema
@@ -2,12 +2,14 @@ let mongoose = require('mongoose')
2
2
  let AccountTempoSchema = require('./AccountTempo')
3
3
  let AccountBasicFeatureSchema = require('./AccountBasicFeature')
4
4
  let AccountScreensSchema = require('./AccountScreens')
5
+ let AccountCemdPersistenceSchema = require('./AccountCemdPersistence')
5
6
 
6
7
  let AccountFeaturesSchema = new mongoose.Schema({
7
8
  tempo: AccountTempoSchema,
8
9
  realTimeDashboard: AccountBasicFeatureSchema,
9
10
  screens: AccountScreensSchema,
10
- insights: AccountBasicFeatureSchema
11
+ insights: AccountBasicFeatureSchema,
12
+ cemdPersistence: AccountCemdPersistenceSchema
11
13
  }, {
12
14
  _id: false
13
15
  })
@@ -0,0 +1,9 @@
1
+ let mongoose = require('mongoose')
2
+
3
+ let AttentiveIntegrationSchema = new mongoose.Schema({
4
+ enabled: {type: Boolean}
5
+ }, {
6
+ _id: false
7
+ })
8
+
9
+ module.exports = AttentiveIntegrationSchema
@@ -28,20 +28,20 @@ function validateMobivityRequiredFields(structure){
28
28
  }
29
29
 
30
30
  function validateTypeAndStructure(type) {
31
- if ((type === "register" && this.structure !== "mobivity")
32
- || (type !== "register" && this.structure === "mobivity")) {
31
+ if ((type === "register" && !['mobivity', 'attentive'].includes(this.structure))
32
+ || (type !== "register" && ['mobivity', 'attentive'].includes(this.structure))) {
33
33
  return false
34
34
  }
35
35
  }
36
36
 
37
37
  let WebhookSchema = new mongoose.Schema({
38
- type: {type: String, enum: ['tempo', 'wave', 'trigger', 'register'], required: [true, 'webhook type is required'], validate: {validator: validateTypeAndStructure, msg: 'type "register" can only have structure "mobivity"'}},
38
+ type: {type: String, enum: ['tempo', 'wave', 'trigger', 'register'], required: [true, 'webhook type is required'], validate: {validator: validateTypeAndStructure, msg: 'type "register" can only have structure "mobivity" or "attentive"'}},
39
39
  url: {type: String, required: [true, 'URL is required'], validate: {validator: validators.validateUrl, msg: 'Please enter a valid URL'}},
40
40
  headers: {type: mongoose.Schema.Types.Mixed, validate: [{ validator: validators.validateNonEmptyStringKeyValuePairsOnly, msg: 'webhook header keys and values must be strings' }, { validator: validators.validateNoSpacesInObjectKeys, msg: 'webhook header keys cannot contain spaces' }]},
41
41
  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' }]},
42
42
  structure: {
43
43
  type: String,
44
- enum: ['standard', 'tealium', 'mobivity'],
44
+ enum: ['standard', 'tealium', 'mobivity', 'attentive'],
45
45
  default: 'standard',
46
46
  validate: [
47
47
  {validator: validateTealiumRequiredFields, msg: 'tealium webhooks require "tealium_account" and "tealium_profile" body fields to be present'},