@bluedot-innovation/models 7.8.0 → 7.10.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,5 +1,8 @@
1
- ## 7.8.0
2
- - Add oneSignal integration to project
1
+ ## 7.10.0
2
+ - Add Bbot Integration to Project
3
+
4
+ ## 7.9.0
5
+ - Add helloOrder webhook
3
6
 
4
7
  ## 7.7.1
5
8
  - Add Hyrbid-mode configurations to IosConfig
@@ -63,6 +63,9 @@
63
63
  "wave": true,
64
64
  "trigger": true,
65
65
  "tempo": false
66
+ },
67
+ "bbot": {
68
+ "nowReadyEnabled": true
66
69
  }
67
70
  },
68
71
  "tempo": {
@@ -509,6 +509,27 @@ describe('Project', () => {
509
509
  })
510
510
  })
511
511
 
512
+ it(`should not validate if the type is hellOrder and the structure is not default`, (done) => {
513
+ project.webhooks[0].type = "helloOrder"
514
+ project.webhooks[0].structure = "standard"
515
+ let Project = new ProjectModel(project)
516
+ Project.validate((err, res) => {
517
+ assert.exists(err)
518
+ assert.match(err.message, /type "helloOrder" can only have structure "default"/)
519
+ done()
520
+ })
521
+ })
522
+ it(`should not validate if structure is default and the type is not helloOrder`, (done) => {
523
+ project.webhooks[0].type = "trigger"
524
+ project.webhooks[0].structure = "default"
525
+ let Project = new ProjectModel(project)
526
+ Project.validate((err, res) => {
527
+ assert.exists(err)
528
+ assert.match(err.message, /type "helloOrder" can only have structure "default"/)
529
+ done()
530
+ })
531
+ })
532
+
512
533
  it("should not validate webhook if body contains keys with spaces", (done) => {
513
534
  project.webhooks[0].body = { "key with spaces": "value" }
514
535
  let Project = new ProjectModel(project)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bluedot-innovation/models",
3
- "version": "7.8.0",
3
+ "version": "7.10.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
+ const mongoose = require('mongoose');
2
+
3
+ let BbotIntegrationSchema = new mongoose.Schema({
4
+ nowReadyEnabled: {type: Boolean, default: false}
5
+ }, {
6
+ _id: false
7
+ })
8
+
9
+ module.exports = BbotIntegrationSchema
@@ -2,6 +2,7 @@ let mongoose = require("mongoose");
2
2
  const oloIntegrationSchema = require('./OloIntegration')
3
3
  const segmentIntegrationSchema = require('./SegmentIntegration')
4
4
  const oneSignalIntegrationSchema = require('./OneSignalIntegration')
5
+ const bbotIntegrationSchema = require('./BbotIntegration')
5
6
 
6
7
 
7
8
  const MParticleSchema = new mongoose.Schema({
@@ -52,7 +53,8 @@ const IntegrationSchema = new mongoose.Schema({
52
53
  },
53
54
  olo: { type: oloIntegrationSchema },
54
55
  segment: { type: segmentIntegrationSchema },
55
- oneSignal: { type: oneSignalIntegrationSchema }
56
+ oneSignal: { type: oneSignalIntegrationSchema },
57
+ bbot: { type: bbotIntegrationSchema }
56
58
  },{ _id : false });
57
59
  function apiKeyValidator(value){
58
60
  // check if the value is a non-empty string
@@ -30,18 +30,21 @@ function validateMobivityRequiredFields(structure){
30
30
  function validateTypeAndStructure(type) {
31
31
  if ((type === "register" && !['mobivity', 'attentive'].includes(this.structure))
32
32
  || (type !== "register" && ['mobivity', 'attentive'].includes(this.structure))) {
33
- return false
33
+ throw new Error('type "register" can only have structure "mobivity" or "attentive"')
34
+ } else if ((type === "helloOrder" && this.structure !== 'default')
35
+ || (type !== "helloOrder" && this.structure === 'default')) {
36
+ throw new Error('type "helloOrder" can only have structure "default"')
34
37
  }
35
38
  }
36
39
 
37
40
  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" or "attentive"'}},
41
+ type: {type: String, enum: ['tempo', 'wave', 'trigger', 'register', 'helloOrder'], required: [true, 'webhook type is required'], validate: {validator: validateTypeAndStructure, msg: 'Invalid webhook type and structure'}},
39
42
  url: {type: String, required: [true, 'URL is required'], validate: {validator: validators.validateUrl, msg: 'Please enter a valid URL'}},
40
43
  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
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' }]},
42
45
  structure: {
43
46
  type: String,
44
- enum: ['standard', 'tealium', 'mobivity', 'attentive'],
47
+ enum: ['standard', 'tealium', 'mobivity', 'attentive', 'default'],
45
48
  default: 'standard',
46
49
  validate: [
47
50
  {validator: validateTealiumRequiredFields, msg: 'tealium webhooks require "tealium_account" and "tealium_profile" body fields to be present'},