@bluedot-innovation/models 7.7.1 → 7.9.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/.gitlab-ci.yml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Official framework image. Look for the different tagged releases at:
|
|
2
2
|
# https://hub.docker.com/r/library/node/tags/
|
|
3
|
-
image: node:
|
|
3
|
+
image: node:16
|
|
4
4
|
|
|
5
5
|
# This folder is cached between builds
|
|
6
6
|
# http://docs.gitlab.com/ce/ci/yaml/README.html#cache
|
|
@@ -11,7 +11,7 @@ cache:
|
|
|
11
11
|
before_script:
|
|
12
12
|
- whoami
|
|
13
13
|
- node --version
|
|
14
|
-
- npm
|
|
14
|
+
- npm ci
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
|
|
@@ -20,7 +20,7 @@ stages:
|
|
|
20
20
|
- deploy
|
|
21
21
|
- release
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
lint:
|
|
24
24
|
stage: test
|
|
25
25
|
tags:
|
|
26
26
|
- infrastructure
|
|
@@ -31,7 +31,7 @@ test:lint:
|
|
|
31
31
|
# https://github.com/nodejs/LTS#lts_schedule
|
|
32
32
|
# jest does not support node < 4
|
|
33
33
|
# https://facebook.github.io/jest/docs/troubleshooting.html#compatibility-issues
|
|
34
|
-
test:
|
|
34
|
+
test:
|
|
35
35
|
stage: test
|
|
36
36
|
tags:
|
|
37
37
|
- infrastructure
|
package/CHANGELOG.md
CHANGED
|
@@ -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)
|
|
@@ -565,6 +586,28 @@ describe('Project', () => {
|
|
|
565
586
|
})
|
|
566
587
|
})
|
|
567
588
|
})
|
|
589
|
+
|
|
590
|
+
describe("oneSignal integration validation", () => {
|
|
591
|
+
it('should throw an error when appId is missing', (done) => {
|
|
592
|
+
delete project.integrations.oneSignal.appId
|
|
593
|
+
let Project = new ProjectModel(project)
|
|
594
|
+
Project.validate((err, res) => {
|
|
595
|
+
assert.exists(err)
|
|
596
|
+
assert.match(err.message, /`appId` is required/)
|
|
597
|
+
done()
|
|
598
|
+
})
|
|
599
|
+
})
|
|
600
|
+
|
|
601
|
+
it('should throw an error when wave is non boolean', (done) => {
|
|
602
|
+
project.integrations.oneSignal.wave = "invalid"
|
|
603
|
+
let Project = new ProjectModel(project)
|
|
604
|
+
Project.validate((err, res) => {
|
|
605
|
+
assert.exists(err)
|
|
606
|
+
assert.match(err.message, /Cast to Boolean failed for value "invalid" .* at path "wave"/)
|
|
607
|
+
done()
|
|
608
|
+
})
|
|
609
|
+
})
|
|
610
|
+
})
|
|
568
611
|
})
|
|
569
612
|
|
|
570
613
|
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
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
let mongoose = require("mongoose");
|
|
2
2
|
const oloIntegrationSchema = require('./OloIntegration')
|
|
3
3
|
const segmentIntegrationSchema = require('./SegmentIntegration')
|
|
4
|
+
const oneSignalIntegrationSchema = require('./OneSignalIntegration')
|
|
4
5
|
|
|
5
6
|
|
|
6
7
|
const MParticleSchema = new mongoose.Schema({
|
|
@@ -50,7 +51,8 @@ const IntegrationSchema = new mongoose.Schema({
|
|
|
50
51
|
]
|
|
51
52
|
},
|
|
52
53
|
olo: { type: oloIntegrationSchema },
|
|
53
|
-
segment: { type: segmentIntegrationSchema }
|
|
54
|
+
segment: { type: segmentIntegrationSchema },
|
|
55
|
+
oneSignal: { type: oneSignalIntegrationSchema }
|
|
54
56
|
},{ _id : false });
|
|
55
57
|
function apiKeyValidator(value){
|
|
56
58
|
// check if the value is a non-empty string
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
let OneSignalIntegrationSchema = new mongoose.Schema({
|
|
4
|
+
appId: {type: String, required: true},
|
|
5
|
+
trigger: {type: Boolean, required: true},
|
|
6
|
+
tempo: {type: Boolean, required: true},
|
|
7
|
+
wave: {type: Boolean, required: true},
|
|
8
|
+
}, {
|
|
9
|
+
_id: false
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
module.exports = OneSignalIntegrationSchema
|
package/schemas/Webhook.js
CHANGED
|
@@ -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
|
-
|
|
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: '
|
|
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'},
|