@bluedot-innovation/models 9.0.1 → 9.0.2

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
+ ## 9.0.2
2
+ - Add structure 2.0 for geo-trigger webhook
3
+
1
4
  ## 9.0.1
2
5
  - Add geo-trigger report
3
6
 
@@ -14,6 +14,15 @@
14
14
  },
15
15
  "retryEnabled": true
16
16
  },
17
+ {
18
+ "type": "trigger",
19
+ "url": "https://webhooklistener.bluedotinnovation.com/sdk-16",
20
+ "headers" : {
21
+ "securityToken" : "value"
22
+ },
23
+ "structure": "2.0",
24
+ "retryEnabled": true
25
+ },
17
26
  {
18
27
  "type": "tempo",
19
28
  "url": "https://webhooklistener.bluedotinnovation.com",
@@ -124,6 +124,63 @@ describe('Project', () => {
124
124
  done()
125
125
  })
126
126
  })
127
+
128
+ it(`should set default structure is 2.0 when the type is trigger`, (done) => {
129
+ project.webhooks = [
130
+ {
131
+ "type": "trigger",
132
+ "url": "https://webhooklistener.bluedotinnovation.com",
133
+ "retryEnabled": true,
134
+ "structure": "standard"
135
+ },
136
+ {
137
+ "type": "trigger",
138
+ "url": "https://webhooklistener.bluedotinnovation.com/sdk-16",
139
+ "retryEnabled": true
140
+ },
141
+ {
142
+ "type": "tempo",
143
+ "url": "https://webhooklistener.bluedotinnovation.com",
144
+ "retryEnabled": true
145
+ },
146
+ {
147
+ "type": "wave",
148
+ "url": "https://webhooklistener.bluedotinnovation.com",
149
+ "structure": "standard"
150
+ }
151
+ ]
152
+ let Project = new ProjectModel(project)
153
+ assert.deepEqual(Project.toObject().webhooks, [
154
+ {
155
+ "type": "trigger",
156
+ "url": "https://webhooklistener.bluedotinnovation.com",
157
+ "structure": "standard",
158
+ "retryEnabled": true
159
+ },
160
+ {
161
+ "type": "trigger",
162
+ "url": "https://webhooklistener.bluedotinnovation.com/sdk-16",
163
+ "structure": "2.0",
164
+ "retryEnabled": true
165
+ },
166
+ {
167
+ "type": "tempo",
168
+ "url": "https://webhooklistener.bluedotinnovation.com",
169
+ "structure": "standard",
170
+ "retryEnabled": true
171
+ },
172
+ {
173
+ "type": "wave",
174
+ "url": "https://webhooklistener.bluedotinnovation.com",
175
+ "structure": "standard",
176
+ "retryEnabled": false
177
+ }
178
+ ])
179
+ Project.validate((err, res) => {
180
+ assert.notExists(err)
181
+ done()
182
+ })
183
+ })
127
184
  })
128
185
  testCase('Valid Project ', () => {
129
186
  assertions('should validate a valid project ', (done) => {
@@ -565,6 +622,18 @@ describe('Project', () => {
565
622
  })
566
623
  })
567
624
 
625
+ it(`should not validate if structure is 2.0 and the type is not trigger`, (done) => {
626
+ project.webhooks[0].type = "tempo"
627
+ project.webhooks[0].url = "http://test-url.com"
628
+ project.webhooks[0].structure = "2.0"
629
+ let Project = new ProjectModel(project)
630
+ Project.validate((err, res) => {
631
+ assert.exists(err)
632
+ assert.match(err.message, /Only type "trigger" can have structure 2.0/)
633
+ done()
634
+ })
635
+ })
636
+
568
637
  it("should not validate webhook if body contains keys with spaces", (done) => {
569
638
  project.webhooks[0].body = { "key with spaces": "value" }
570
639
  let Project = new ProjectModel(project)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bluedot-innovation/models",
3
- "version": "9.0.1",
3
+ "version": "9.0.2",
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",
@@ -34,6 +34,8 @@ function validateTypeAndStructure(type) {
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"')
37
+ } else if (type !== 'trigger' && this.structure === '2.0') {
38
+ throw new Error('Only type "trigger" can have structure 2.0')
37
39
  }
38
40
  }
39
41
 
@@ -44,8 +46,10 @@ let WebhookSchema = new mongoose.Schema({
44
46
  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
47
  structure: {
46
48
  type: String,
47
- enum: ['standard', 'tealium', 'mobivity', 'default'],
48
- default: 'standard',
49
+ enum: ['standard', 'tealium', 'mobivity', 'default', '2.0'],
50
+ default: function () {
51
+ return this.type === 'trigger' ? '2.0' : 'standard'
52
+ },
49
53
  validate: [
50
54
  {validator: validateTealiumRequiredFields, msg: 'tealium webhooks require "tealium_account" and "tealium_profile" body fields to be present'},
51
55
  {validator: validateMobivityRequiredFields, msg: 'mobivity webhooks require "username", "target_id" and "message_text" body fields to be present'}