@bluedot-innovation/models 9.0.1 → 9.0.3
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
|
@@ -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",
|
|
@@ -96,6 +105,9 @@
|
|
|
96
105
|
"tempo": true,
|
|
97
106
|
"wave": true,
|
|
98
107
|
"hello": true
|
|
108
|
+
},
|
|
109
|
+
"doordash": {
|
|
110
|
+
"authorizationToken": "1986d1de-85ea-4339-93a2-6442d44a31f6"
|
|
99
111
|
}
|
|
100
112
|
},
|
|
101
113
|
"tempo": {
|
|
@@ -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)
|
|
@@ -929,6 +998,18 @@ describe('Project', () => {
|
|
|
929
998
|
})
|
|
930
999
|
})
|
|
931
1000
|
})
|
|
1001
|
+
|
|
1002
|
+
describe("Doordash integration validation", () => {
|
|
1003
|
+
it('should throw an error when authorizationToken is missing', (done) => {
|
|
1004
|
+
delete project.integrations.doordash.authorizationToken
|
|
1005
|
+
let Project = new ProjectModel(project)
|
|
1006
|
+
Project.validate((err, res) => {
|
|
1007
|
+
assert.exists(err)
|
|
1008
|
+
assert.match(err.message, /`authorizationToken` is required/)
|
|
1009
|
+
done()
|
|
1010
|
+
})
|
|
1011
|
+
})
|
|
1012
|
+
})
|
|
932
1013
|
})
|
|
933
1014
|
|
|
934
1015
|
describe('should throw an error when any of the values of the array contains a falsy value', () => {
|
package/package.json
CHANGED
package/schemas/Integration.js
CHANGED
|
@@ -7,7 +7,8 @@ const flipdishIntegrationSchema = require('./FlipdishIntegration')
|
|
|
7
7
|
const projectAttentiveIntegrationSchema = require('./ProjectAttentiveIntegration')
|
|
8
8
|
const incentivioIntegrationSchema = require('./IncentivioIntegration')
|
|
9
9
|
const mparticleIntegrationSchema = require('./MparticleIntegration')
|
|
10
|
-
const klaviyoIntegrationSchema = require('./KlaviyoIntegration')
|
|
10
|
+
const klaviyoIntegrationSchema = require('./KlaviyoIntegration')
|
|
11
|
+
const doordashIntegrationSchema = require('./DoordashIntegration')
|
|
11
12
|
|
|
12
13
|
function mParticleValidator(value) {
|
|
13
14
|
const { androidApiKey, iosApiKey, webApiKey } = value;
|
|
@@ -23,7 +24,8 @@ const IntegrationSchema = new mongoose.Schema({
|
|
|
23
24
|
flipdish: { type: flipdishIntegrationSchema },
|
|
24
25
|
attentive: { type: projectAttentiveIntegrationSchema },
|
|
25
26
|
incentivio: { type: incentivioIntegrationSchema },
|
|
26
|
-
klaviyo: { type: klaviyoIntegrationSchema }
|
|
27
|
+
klaviyo: { type: klaviyoIntegrationSchema },
|
|
28
|
+
doordash: { type: doordashIntegrationSchema }
|
|
27
29
|
},{ _id : false });
|
|
28
30
|
|
|
29
31
|
module.exports = IntegrationSchema
|
package/schemas/Webhook.js
CHANGED
|
@@ -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:
|
|
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'}
|