@bluedot-innovation/models 6.2.0 → 6.2.1-alpha.1
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.
|
@@ -8,5 +8,21 @@
|
|
|
8
8
|
"features": {
|
|
9
9
|
"tags": true,
|
|
10
10
|
"beacons": false
|
|
11
|
+
},
|
|
12
|
+
"integrations": {
|
|
13
|
+
"sfmc": {
|
|
14
|
+
"activeToken": "example-active-token",
|
|
15
|
+
"activeTokenExpiry": "2018-02-14T04:12:02.103Z",
|
|
16
|
+
"refreshToken": "example-refresh-token",
|
|
17
|
+
"userId": "example-user-id",
|
|
18
|
+
"userEmail": "example@emai1.com",
|
|
19
|
+
"dataExtensionVersion": 2,
|
|
20
|
+
"dataExtensionsId": "example-data-extension-id",
|
|
21
|
+
"stackKey": "example-stack-key",
|
|
22
|
+
"activated": true,
|
|
23
|
+
"enterpriseId": 1234567,
|
|
24
|
+
"organizationId": 12345,
|
|
25
|
+
"allowedFields": ["example-allowed-fields"]
|
|
26
|
+
}
|
|
11
27
|
}
|
|
12
28
|
}
|
|
@@ -4,5 +4,8 @@ module.exports = {
|
|
|
4
4
|
{name: 'poiCredits', invalidInputs: ['a string']},
|
|
5
5
|
{name: 'creationTime', invalidInputs: ['21/07/2017', 'thursday']},
|
|
6
6
|
{name: 'lastUpdateTime', invalidInputs: ['21/07/2017', 'saturday']}
|
|
7
|
-
]
|
|
7
|
+
],
|
|
8
|
+
sfmcIntegration: {
|
|
9
|
+
requiredFields: ['activeToken', 'activeTokenExpiry', 'refreshToken', 'userId', 'userEmail', 'dataExtensionsId', 'dataExtensionVersion', 'enterpriseId', 'organizationId']
|
|
10
|
+
}
|
|
8
11
|
}
|
|
@@ -9,6 +9,7 @@ let chai = require('chai')
|
|
|
9
9
|
let assert = chai.assert
|
|
10
10
|
let mocha = require('mocha')
|
|
11
11
|
let beforeEach = mocha.beforeEach
|
|
12
|
+
let helpers = require("../../helpers");
|
|
12
13
|
|
|
13
14
|
let account
|
|
14
15
|
|
|
@@ -80,4 +81,37 @@ testCase('Account', () => {
|
|
|
80
81
|
})
|
|
81
82
|
})
|
|
82
83
|
})
|
|
84
|
+
|
|
85
|
+
testCase('Salesforce Marketing Cloud Integration', () => {
|
|
86
|
+
assertions("check email validator", () => {
|
|
87
|
+
const sfmc = account.integrations.sfmc;
|
|
88
|
+
sfmc.userEmail = "invalid email"
|
|
89
|
+
let Account = new AccountModel(account)
|
|
90
|
+
|
|
91
|
+
Account.validate((err, res) => {
|
|
92
|
+
assert.notExists(res)
|
|
93
|
+
assert.exists(err, 'err object should exist')
|
|
94
|
+
assert.isObject(err)
|
|
95
|
+
done()
|
|
96
|
+
})
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
testCase("check required fields", () => {
|
|
100
|
+
const { requiredFields } = rules.sfmcIntegration;
|
|
101
|
+
|
|
102
|
+
requiredFields.forEach((requiredField) => {
|
|
103
|
+
assertions(`should throw an error with property '${requiredField}' if '${requiredField}' is not present`, (done) => {
|
|
104
|
+
account = JSON.parse(JSON.stringify(account))
|
|
105
|
+
const sfmc = account.integrations.sfmc;
|
|
106
|
+
delete sfmc[requiredField]
|
|
107
|
+
let Account = new AccountModel(account)
|
|
108
|
+
Account.validate((err, res) => {
|
|
109
|
+
assert.notExists(res)
|
|
110
|
+
assert.exists(err, 'err object should exist')
|
|
111
|
+
done()
|
|
112
|
+
})
|
|
113
|
+
})
|
|
114
|
+
})
|
|
115
|
+
})
|
|
116
|
+
})
|
|
83
117
|
})
|
package/models/Account.js
CHANGED
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
let mongoose = require('mongoose')
|
|
7
|
-
// let Schema = mongoose.Schema
|
|
8
7
|
let StateEnum = require('@bluedot-innovation/enums').StateEnum
|
|
9
8
|
let accountFeatures = require('../schemas/AccountFeatures')
|
|
9
|
+
const SfmcIntegration = require('../schemas/SfmcIntegration')
|
|
10
10
|
let uuidv4 = require('uuid/v4')
|
|
11
11
|
let patcher = require('@bluedot-innovation/mongoose-json-patch')
|
|
12
12
|
const helpers = require('../helpers')
|
|
@@ -29,7 +29,10 @@ let AccountSchema = new mongoose.Schema({
|
|
|
29
29
|
integrations: Object,
|
|
30
30
|
features: accountFeatures,
|
|
31
31
|
creationTime: {type: Date, default: Date.now},
|
|
32
|
-
lastUpdateTime: {type: Date, default: Date.now}
|
|
32
|
+
lastUpdateTime: {type: Date, default: Date.now},
|
|
33
|
+
integrations: {
|
|
34
|
+
sfmc: {type: SfmcIntegration}
|
|
35
|
+
}
|
|
33
36
|
},
|
|
34
37
|
{collection: 'account'})
|
|
35
38
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
let mongoose = require("mongoose");
|
|
2
|
+
const helpers = require("../helpers");
|
|
3
|
+
|
|
4
|
+
const SfmcIntegrationSchema = new mongoose.Schema({
|
|
5
|
+
activeToken: {
|
|
6
|
+
type: String,
|
|
7
|
+
required: true
|
|
8
|
+
},
|
|
9
|
+
activeTokenExpiry: {
|
|
10
|
+
type: Date,
|
|
11
|
+
required: true
|
|
12
|
+
},
|
|
13
|
+
refreshToken: {
|
|
14
|
+
type: String,
|
|
15
|
+
required: true
|
|
16
|
+
},
|
|
17
|
+
userId: {
|
|
18
|
+
type: String,
|
|
19
|
+
required: true
|
|
20
|
+
},
|
|
21
|
+
userEmail: {
|
|
22
|
+
type: String,
|
|
23
|
+
required: true,
|
|
24
|
+
validate: {
|
|
25
|
+
validator: helpers.validateEmail,
|
|
26
|
+
message: '{VALUE} is not a valid email'
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
dataExtensionsId: {
|
|
30
|
+
type: String,
|
|
31
|
+
required: true
|
|
32
|
+
},
|
|
33
|
+
dataExtensionVersion: {
|
|
34
|
+
type: Number,
|
|
35
|
+
required: true
|
|
36
|
+
},
|
|
37
|
+
stackKey: {
|
|
38
|
+
type: String
|
|
39
|
+
},
|
|
40
|
+
activated: {
|
|
41
|
+
type: Boolean,
|
|
42
|
+
default: false
|
|
43
|
+
},
|
|
44
|
+
enterpriseId: {
|
|
45
|
+
type: Number,
|
|
46
|
+
required: true
|
|
47
|
+
},
|
|
48
|
+
organizationId: {
|
|
49
|
+
type: Number,
|
|
50
|
+
required: true
|
|
51
|
+
},
|
|
52
|
+
allowedFields: {
|
|
53
|
+
type: [String]
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
module.exports = SfmcIntegrationSchema
|