@bluedot-innovation/models 3.1.0 → 4.0.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/Models.js +10 -55
- package/models/AdminPortalUser.js +11 -10
- package/models/AdminUser.js +10 -0
- package/models/Application.js +38 -0
- package/models/ApplicationNotificationAction.js +30 -0
- package/models/ApplicationUsage.js +11 -0
- package/models/Beacon.js +32 -84
- package/models/BeaconFilter.js +23 -0
- package/models/BearingFilter.js +19 -0
- package/models/BoundingBox.js +17 -0
- package/models/Circle.js +21 -0
- package/models/ConfigurationParameters.js +20 -0
- package/models/Contract.js +38 -37
- package/models/Customer.js +38 -0
- package/models/CustomerLogin.js +10 -9
- package/models/DBEvent.js +14 -13
- package/models/DailyStats.js +7 -7
- package/models/DateRangeFilter.js +20 -0
- package/models/DeviceRulesRequest.js +28 -27
- package/models/Fence.js +21 -0
- package/models/FormattedBeacon.js +16 -0
- package/models/FormattedCircle.js +12 -0
- package/models/FormattedConditions.js +11 -0
- package/models/FormattedDateRange.js +11 -0
- package/models/FormattedPercentageCrossed.js +12 -0
- package/models/FormattedPoint.js +10 -0
- package/models/FormattedPolygon.js +11 -0
- package/models/FormattedPolyline.js +11 -0
- package/models/FormattedRectangle.js +12 -0
- package/models/FormattedTimeActive.js +17 -0
- package/models/FormattedZone.js +28 -0
- package/models/GeoFence.js +23 -0
- package/models/Geofeature.js +26 -0
- package/models/MessageAction.js +26 -28
- package/models/MonthlyStats.js +19 -35
- package/models/NotificationLogEntry.js +8 -7
- package/models/POILocation.js +7 -6
- package/models/POILookup.js +9 -8
- package/models/POIResult.js +8 -7
- package/models/PartnerCustomer.js +13 -12
- package/models/PartnerPasswordReset.js +9 -8
- package/models/PartnerUser.js +11 -10
- package/models/Partners.js +12 -11
- package/models/PercentageCrossedFilter.js +19 -0
- package/models/Point.js +20 -0
- package/models/Polygon.js +18 -0
- package/models/Polyline.js +18 -0
- package/models/PropertyMapping.js +17 -0
- package/models/Reference.js +19 -0
- package/models/RuleRequestAggregation.js +17 -33
- package/models/SequenceFilter.js +18 -0
- package/models/SimpleCheckInZone.js +29 -0
- package/models/SingleUseToken.js +8 -7
- package/models/SoundAction.js +28 -0
- package/models/SpeedFilter.js +19 -0
- package/models/TestDevice.js +12 -11
- package/models/TestDeviceCluster.js +10 -9
- package/models/TestInstance.js +10 -9
- package/models/TestScenario.js +10 -9
- package/models/TimeOfDayRange.js +16 -16
- package/models/TimeOfDayRangeFilter.js +19 -0
- package/models/URLAction.js +31 -0
- package/models/VibrationAction.js +28 -0
- package/models/ZoneUIState.js +18 -18
- package/models/property.js +25 -0
- package/package-lock.json.bak +170 -0
- package/package.json +6 -30
- package/.eslintrc.js +0 -42
- package/.gitlab-ci.yml +0 -43
- package/CHANGELOG.md +0 -148
- package/README.MD +0 -36
- package/__tests__/account/account.data.json +0 -12
- package/__tests__/account/account.rules.js +0 -8
- package/__tests__/account/account.spec.js +0 -83
- package/__tests__/action/message/messageAction.data.json +0 -5
- package/__tests__/action/message/messageAction.rules.json +0 -3
- package/__tests__/action/message/messageAction.spec.js +0 -61
- package/__tests__/action/url/urlAction.data.json +0 -4
- package/__tests__/action/url/urlAction.rules.json +0 -3
- package/__tests__/action/url/urlAction.spec.js +0 -74
- package/__tests__/beacon/beacon.data.json +0 -15
- package/__tests__/beacon/beacon.rules.json +0 -13
- package/__tests__/beacon/beacon.spec.js +0 -104
- package/__tests__/condition/beacon/beaconFilter.data.json +0 -1
- package/__tests__/condition/beacon/beaconFilter.rules.json +0 -3
- package/__tests__/condition/beacon/beaconFilter.spec.js +0 -1
- package/__tests__/condition/dayRange/dayRange.data.json +0 -5
- package/__tests__/condition/dayRange/dayRange.rules.json +0 -3
- package/__tests__/condition/dayRange/dayRange.spec.js +0 -74
- package/__tests__/condition/percentageCrossed/travelPath.data.json +0 -5
- package/__tests__/condition/percentageCrossed/travelPath.rules.json +0 -3
- package/__tests__/condition/percentageCrossed/travelPath.spec.js +0 -62
- package/__tests__/condition/speed/speed.data.json +0 -5
- package/__tests__/condition/speed/speed.rules.json +0 -3
- package/__tests__/condition/speed/speed.spec.js +0 -73
- package/__tests__/condition/timeActive/timeActive.data.json +0 -5
- package/__tests__/condition/timeActive/timeActive.rules.json +0 -7
- package/__tests__/condition/timeActive/timeActive.spec.js +0 -94
- package/__tests__/condition/travelDirection/travelDirection.data.json +0 -5
- package/__tests__/condition/travelDirection/travelDirection.rules.json +0 -3
- package/__tests__/condition/travelDirection/travelDirection.spec.js +0 -132
- package/__tests__/dailyStats/checkDailyStats.js +0 -31
- package/__tests__/geofeature/boundingBox/boundingBox.data.json +0 -12
- package/__tests__/geofeature/boundingBox/boundingBox.rules.json +0 -3
- package/__tests__/geofeature/boundingBox/boundingBox.spec.js +0 -78
- package/__tests__/geofeature/circle/circle.data.json +0 -9
- package/__tests__/geofeature/circle/circle.rules.json +0 -3
- package/__tests__/geofeature/circle/circle.spec.js +0 -71
- package/__tests__/geofeature/polygon/polygon.data.json +0 -46
- package/__tests__/geofeature/polygon/polygon.rules.json +0 -3
- package/__tests__/geofeature/polygon/polygon.spec.js +0 -127
- package/__tests__/geofeature/polyline/polyline.data.json +0 -46
- package/__tests__/geofeature/polyline/polyline.rules.json +0 -3
- package/__tests__/geofeature/polyline/polyline.spec.js +0 -70
- package/__tests__/geofeature/zoneBeacon/zoneBeacon.data.json +0 -16
- package/__tests__/geofeature/zoneBeacon/zoneBeacon.rules.json +0 -13
- package/__tests__/geofeature/zoneBeacon/zoneBeacon.spec.js +0 -62
- package/__tests__/monthlyStats/monthlyStats.data.json +0 -29
- package/__tests__/monthlyStats/monthlyStats.spec.js +0 -66
- package/__tests__/project/project.data.json +0 -18
- package/__tests__/project/project.rules.json +0 -9
- package/__tests__/project/project.spec.js +0 -81
- package/__tests__/ruleRequestAggregation/ruleRequestAggregation.data.json +0 -8
- package/__tests__/ruleRequestAggregation/ruleRequestAggregation.spec.js +0 -69
- package/__tests__/setup.js +0 -7
- package/__tests__/user/user.data.js +0 -19
- package/__tests__/user/user.rules.js +0 -8
- package/__tests__/user/user.spec.js +0 -130
- package/__tests__/utils/utils.spec.js +0 -24
- package/__tests__/zone/zone.action.spec.js +0 -50
- package/__tests__/zone/zone.condition.spec.js +0 -76
- package/__tests__/zone/zone.data.json +0 -157
- package/__tests__/zone/zone.geofeatures.spec.js +0 -75
- package/__tests__/zone/zone.spec.js +0 -134
- package/constants/errorMessages.js +0 -2
- package/helpers.js +0 -102
- package/models/Account.js +0 -50
- package/models/Project.js +0 -55
- package/models/UrlAction.js +0 -46
- package/models/User.js +0 -61
- package/models/Zone.js +0 -123
- package/models/conditions/DayRange.js +0 -52
- package/models/conditions/Speed.js +0 -42
- package/models/conditions/TimeActive.js +0 -50
- package/models/conditions/TravelDirection.js +0 -67
- package/models/conditions/TravelPath.js +0 -36
- package/models/geofeatures/BoundingBox.js +0 -44
- package/models/geofeatures/Circle.js +0 -39
- package/models/geofeatures/Polygon.js +0 -45
- package/models/geofeatures/Polyline.js +0 -34
- package/models/geofeatures/ZoneBeacon.js +0 -28
- package/schemas/MultiLineStringGeometry.js +0 -14
- package/schemas/Point.js +0 -13
- package/schemas/PointGeometry.js +0 -14
- package/schemas/PolygonGeometry.js +0 -14
- package/schemas/ProjectPermission.js +0 -21
- package/schemas/Webhook.js +0 -22
- package/utils/index.js +0 -39
- package/validators/checkDistanceBetweenVertices.js +0 -21
- package/yarn.lock +0 -2796
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "TDD zone",
|
|
3
|
-
"minimumRetriggerTime": "60",
|
|
4
|
-
"checkout": true,
|
|
5
|
-
"lastUpdateTime": "2018-02-14T04:12:02.103Z",
|
|
6
|
-
"creationTime": "2018-02-14T04:12:02.103Z",
|
|
7
|
-
"projectId": "c7058934-f1e6-4176-8730-a0bd28e8e0a9",
|
|
8
|
-
"accountId": "23a01af0-232a-4518-9c0e-323fb773f5ef",
|
|
9
|
-
"customData": {
|
|
10
|
-
"name1": "A Custom action1",
|
|
11
|
-
"name2": "A Custom action2"
|
|
12
|
-
},
|
|
13
|
-
"actions": [
|
|
14
|
-
{
|
|
15
|
-
"type": "message",
|
|
16
|
-
"message": "hello",
|
|
17
|
-
"title": "hello"
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
"type": "url",
|
|
21
|
-
"url": "https://www.google.com"
|
|
22
|
-
}
|
|
23
|
-
],
|
|
24
|
-
"beacons": [],
|
|
25
|
-
"conditions": [
|
|
26
|
-
{
|
|
27
|
-
"type" : "dayRange",
|
|
28
|
-
"startDate" : "2017-11-14",
|
|
29
|
-
"endDate" : "2030-11-15"
|
|
30
|
-
}
|
|
31
|
-
],
|
|
32
|
-
"geofeatures": [{
|
|
33
|
-
"type": "beacon",
|
|
34
|
-
"name": "create beacon",
|
|
35
|
-
"proximityUUID": "23a01af0-232a-4518-9c0e-323fb773f5ef",
|
|
36
|
-
"location": {
|
|
37
|
-
"latitude": -37.8159544565362,
|
|
38
|
-
"longitude": 144.9723565578461
|
|
39
|
-
},
|
|
40
|
-
"beaconType": "Both",
|
|
41
|
-
"major": 10000,
|
|
42
|
-
"phone": 123123123123,
|
|
43
|
-
"minor": 56466,
|
|
44
|
-
"txPower": -77,
|
|
45
|
-
"macAddress": "01:17:c5:31:84:19",
|
|
46
|
-
"accountId": "90a2ed18-86be-48e7-948b-393b8b679ef6"
|
|
47
|
-
},{
|
|
48
|
-
"type": "circle",
|
|
49
|
-
"name": "Test Circle",
|
|
50
|
-
"radius": 10,
|
|
51
|
-
"center": {
|
|
52
|
-
"latitude": -37.8159544565362,
|
|
53
|
-
"longitude": 144.9723565578461
|
|
54
|
-
}
|
|
55
|
-
},{
|
|
56
|
-
"type": "boundingBox",
|
|
57
|
-
"name": "Test BoundingBox",
|
|
58
|
-
"northEast": {
|
|
59
|
-
"latitude": -37.81794619852986,
|
|
60
|
-
"longitude": 144.97999548912048
|
|
61
|
-
},
|
|
62
|
-
"southWest": {
|
|
63
|
-
"latitude": -37.81846319511329,
|
|
64
|
-
"longitude": 144.97921228408813
|
|
65
|
-
}
|
|
66
|
-
},{
|
|
67
|
-
"type": "polygon",
|
|
68
|
-
"name": "Test Polygon",
|
|
69
|
-
"vertices": [
|
|
70
|
-
{
|
|
71
|
-
"latitude": -37.81902680201739,
|
|
72
|
-
"longitude": 144.9821037054062
|
|
73
|
-
},
|
|
74
|
-
{
|
|
75
|
-
"latitude": -37.8196878692931,
|
|
76
|
-
"longitude": 144.98161554336548
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
"latitude": -37.82052267015026,
|
|
80
|
-
"longitude": 144.9816906452179
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
"latitude": -37.82128118660006,
|
|
84
|
-
"longitude": 144.98312830924988
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
"latitude": -37.82102693614463,
|
|
88
|
-
"longitude": 144.98458743095398
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
"latitude": -37.820196378553405,
|
|
92
|
-
"longitude": 144.98524725437164
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
"latitude": -37.81895899991077,
|
|
96
|
-
"longitude": 144.9847161769867
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
"latitude": -37.81865812731128,
|
|
100
|
-
"longitude": 144.9839222431183
|
|
101
|
-
},
|
|
102
|
-
{
|
|
103
|
-
"latitude": -37.81866660261256,
|
|
104
|
-
"longitude": 144.98308539390564
|
|
105
|
-
},
|
|
106
|
-
{
|
|
107
|
-
"latitude": -37.81902680201739,
|
|
108
|
-
"longitude": 144.9821037054062
|
|
109
|
-
}
|
|
110
|
-
]
|
|
111
|
-
},{
|
|
112
|
-
"type": "polyline",
|
|
113
|
-
"name": "Test Polygon",
|
|
114
|
-
"vertices": [
|
|
115
|
-
{
|
|
116
|
-
"latitude": -37.81902680201739,
|
|
117
|
-
"longitude": 144.9821037054062
|
|
118
|
-
},
|
|
119
|
-
{
|
|
120
|
-
"latitude": -37.8196878692931,
|
|
121
|
-
"longitude": 144.98161554336548
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
"latitude": -37.82052267015026,
|
|
125
|
-
"longitude": 144.9816906452179
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
"latitude": -37.82128118660006,
|
|
129
|
-
"longitude": 144.98312830924988
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
"latitude": -37.82102693614463,
|
|
133
|
-
"longitude": 144.98458743095398
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
"latitude": -37.820196378553405,
|
|
137
|
-
"longitude": 144.98524725437164
|
|
138
|
-
},
|
|
139
|
-
{
|
|
140
|
-
"latitude": -37.81895899991077,
|
|
141
|
-
"longitude": 144.9847161769867
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
"latitude": -37.81865812731128,
|
|
145
|
-
"longitude": 144.9839222431183
|
|
146
|
-
},
|
|
147
|
-
{
|
|
148
|
-
"latitude": -37.81866660261256,
|
|
149
|
-
"longitude": 144.98308539390564
|
|
150
|
-
},
|
|
151
|
-
{
|
|
152
|
-
"latitude": -37.81902680201739,
|
|
153
|
-
"longitude": 144.9821037054062
|
|
154
|
-
}
|
|
155
|
-
]
|
|
156
|
-
}]
|
|
157
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
let mongoose = require('mongoose')
|
|
2
|
-
|
|
3
|
-
mongoose.Promise = global.Promise
|
|
4
|
-
|
|
5
|
-
let ZoneModel = require('../../Models').Zone(mongoose)
|
|
6
|
-
let testCase = require('mocha').describe
|
|
7
|
-
let assertions = require('mocha').it
|
|
8
|
-
let chai = require('chai')
|
|
9
|
-
let assert = chai.assert
|
|
10
|
-
let mocha = require('mocha')
|
|
11
|
-
let beforeEach = mocha.beforeEach
|
|
12
|
-
|
|
13
|
-
let zone
|
|
14
|
-
|
|
15
|
-
beforeEach(() => {
|
|
16
|
-
zone = JSON.parse(JSON.stringify(require('./zone.data.json')))
|
|
17
|
-
// remove conditions as it's not tested
|
|
18
|
-
delete zone.conditions
|
|
19
|
-
|
|
20
|
-
// geofeatures are tested individually so we only need to try one in Zones' test
|
|
21
|
-
zone.geofeatures = zone.geofeatures.filter(x => x.type.match(/beacon/i))
|
|
22
|
-
|
|
23
|
-
// remove customData
|
|
24
|
-
delete zone.customData
|
|
25
|
-
|
|
26
|
-
// remove actions
|
|
27
|
-
delete zone.actions
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
testCase('Zone - Action', () => {
|
|
31
|
-
testCase('Valid Zone - Action', () => {
|
|
32
|
-
assertions('should not throw an error when a valid geofeature is instantiated within a zone', (done) => {
|
|
33
|
-
let Zone = new ZoneModel(zone)
|
|
34
|
-
Zone.validate((err, res) => {
|
|
35
|
-
console.log(err)
|
|
36
|
-
assert.notExists(res)
|
|
37
|
-
assert(err === null, 'err should be null')
|
|
38
|
-
done()
|
|
39
|
-
})
|
|
40
|
-
})
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
testCase('Invalid Zone - Action', () => {
|
|
44
|
-
assertions('should throw an error when an invalid geofeature is instantiated within a zone', (done) => {
|
|
45
|
-
delete zone.geofeatures[0].name
|
|
46
|
-
let Zone = new ZoneModel(zone)
|
|
47
|
-
Zone.validate((err, res) => {
|
|
48
|
-
assert.exists(err, 'err object should exist')
|
|
49
|
-
assert.isObject(err)
|
|
50
|
-
assert('geofeatures.0.name' in err.errors)
|
|
51
|
-
done()
|
|
52
|
-
})
|
|
53
|
-
})
|
|
54
|
-
assertions('should throw an error when an invalid geofeature (complex validation) is instantiated within a zone', (done) => {
|
|
55
|
-
delete zone.geofeatures[0].minor
|
|
56
|
-
let Zone = new ZoneModel(zone)
|
|
57
|
-
Zone.validate((err, res) => {
|
|
58
|
-
assert.exists(err, 'err object should exist')
|
|
59
|
-
assert.isObject(err)
|
|
60
|
-
assert('geofeatures.0.beaconType' in err.errors)
|
|
61
|
-
done()
|
|
62
|
-
})
|
|
63
|
-
})
|
|
64
|
-
assertions('should throw an error when an no geofeature is instantiated within a zone', (done) => {
|
|
65
|
-
zone.geofeatures = []
|
|
66
|
-
let Zone = new ZoneModel(zone)
|
|
67
|
-
Zone.validate((err, res) => {
|
|
68
|
-
assert.exists(err, 'err object should exist')
|
|
69
|
-
assert.isObject(err)
|
|
70
|
-
assert('geofeatures' in err.errors)
|
|
71
|
-
done()
|
|
72
|
-
})
|
|
73
|
-
})
|
|
74
|
-
})
|
|
75
|
-
})
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
let ZoneModel = require('../../Models').Zone(mongoose)
|
|
2
|
-
let ZoneModelBuiltInMongoose = require('../../Models').Zone()
|
|
3
|
-
|
|
4
|
-
let zone
|
|
5
|
-
|
|
6
|
-
beforeEach(() => {
|
|
7
|
-
zone = JSON.parse(JSON.stringify(require('./zone.data.json')))
|
|
8
|
-
})
|
|
9
|
-
|
|
10
|
-
describe('Zone', () => {
|
|
11
|
-
describe('Valid Zone ', () => {
|
|
12
|
-
it('should validate a valid zone ', (done) => {
|
|
13
|
-
let Zone = new ZoneModel(zone)
|
|
14
|
-
Zone.validate((err, res) => {
|
|
15
|
-
assert.notExists(res)
|
|
16
|
-
assert(err === null, 'err equals null')
|
|
17
|
-
done()
|
|
18
|
-
})
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
it('should validate a valid zone ', (done) => {
|
|
22
|
-
let Zone = new ZoneModelBuiltInMongoose(zone)
|
|
23
|
-
Zone.validate((err, res) => {
|
|
24
|
-
assert.notExists(res)
|
|
25
|
-
assert(err === null, 'err equals null')
|
|
26
|
-
done()
|
|
27
|
-
})
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
it('should instantiate a circle', (done) => {
|
|
31
|
-
zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(/^circle$/))
|
|
32
|
-
let Zone = new ZoneModel(zone)
|
|
33
|
-
Zone.validate((err, res) => {
|
|
34
|
-
assert.notExists(res)
|
|
35
|
-
assert(err === null, 'err equals null')
|
|
36
|
-
done()
|
|
37
|
-
})
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
it('should instantiate a bounding box', (done) => {
|
|
41
|
-
zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(/^boundingBox$/))
|
|
42
|
-
let Zone = new ZoneModel(zone)
|
|
43
|
-
Zone.validate((err, res) => {
|
|
44
|
-
assert.notExists(res)
|
|
45
|
-
assert(err === null, 'err equals null')
|
|
46
|
-
done()
|
|
47
|
-
})
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
it('should instantiate a polygon', (done) => {
|
|
51
|
-
zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(/^polygon$/))
|
|
52
|
-
let Zone = new ZoneModel(zone)
|
|
53
|
-
Zone.validate((err, res) => {
|
|
54
|
-
assert.notExists(res)
|
|
55
|
-
assert(err === null, 'err equals null')
|
|
56
|
-
done()
|
|
57
|
-
})
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
it('should instantiate a polyline', (done) => {
|
|
61
|
-
zone.geofeatures = zone.geofeatures.filter(gf => gf.type.match(/^polyline$/))
|
|
62
|
-
let Zone = new ZoneModel(zone)
|
|
63
|
-
Zone.validate((err, res) => {
|
|
64
|
-
assert.notExists(res)
|
|
65
|
-
assert(err === null, 'err equals null')
|
|
66
|
-
done()
|
|
67
|
-
})
|
|
68
|
-
})
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
describe('Invalid Zone ', () => {
|
|
72
|
-
it('should throw an error when validating an invalid zone ', (done) => {
|
|
73
|
-
delete zone.name
|
|
74
|
-
let Zone = new ZoneModel(zone)
|
|
75
|
-
Zone.validate((err, res) => {
|
|
76
|
-
assert.exists(err, 'err object should exist')
|
|
77
|
-
assert.isObject(err)
|
|
78
|
-
done()
|
|
79
|
-
})
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
it('should throw an error when action is invalid', (done) => {
|
|
83
|
-
delete zone.actions[1].url
|
|
84
|
-
let Zone = new ZoneModel(zone)
|
|
85
|
-
Zone.validate((err, res) => {
|
|
86
|
-
assert.exists(err, 'err object should exist')
|
|
87
|
-
assert.isObject(err)
|
|
88
|
-
assert('actions.1.url' in err.errors, `errors should have a 'actions.1.url' property`)
|
|
89
|
-
done()
|
|
90
|
-
})
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
it('should throw an error when a condition is invalid', (done) => {
|
|
94
|
-
zone.conditions[0].startDate = 'abc'
|
|
95
|
-
let Zone = new ZoneModel(zone)
|
|
96
|
-
Zone.validate((err, res) => {
|
|
97
|
-
assert.exists(err, 'err object should exist')
|
|
98
|
-
assert.isObject(err)
|
|
99
|
-
assert('conditions.0.startDate' in err.errors, `errors should have a 'conditions.0.startDate' property`)
|
|
100
|
-
done()
|
|
101
|
-
})
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
it('should throw an error when validating an invalid customData key ', (done) => {
|
|
105
|
-
zone.customData["name#3"] = "A Custom action3"
|
|
106
|
-
let Zone = new ZoneModel(zone)
|
|
107
|
-
Zone.validate((err, res) => {
|
|
108
|
-
assert.exists(err, 'err object should exist')
|
|
109
|
-
assert.isObject(err)
|
|
110
|
-
done()
|
|
111
|
-
})
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
it('should throw an error when it contains both a beacon and a travelDirection condition', (done) => {
|
|
115
|
-
zone.conditions.push(require('../condition/travelDirection/travelDirection.data.json'));
|
|
116
|
-
let Zone = new ZoneModel(zone)
|
|
117
|
-
Zone.validate((err, res) => {
|
|
118
|
-
assert.exists(err, 'err object should exist')
|
|
119
|
-
assert(err instanceof Error, "Should throw error.")
|
|
120
|
-
done()
|
|
121
|
-
})
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
it('should throw an error when it contains both a beacon and a speed condition', (done) => {
|
|
125
|
-
zone.conditions.push(require('../condition/speed/speed.data.json'));
|
|
126
|
-
let Zone = new ZoneModel(zone)
|
|
127
|
-
Zone.validate((err, res) => {
|
|
128
|
-
assert.exists(err, 'err object should exist')
|
|
129
|
-
assert(err instanceof Error, "Should throw error.")
|
|
130
|
-
done()
|
|
131
|
-
})
|
|
132
|
-
})
|
|
133
|
-
})
|
|
134
|
-
})
|
package/helpers.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
var equal = require('deep-equal');
|
|
2
|
-
const { clean } = require('./utils');
|
|
3
|
-
|
|
4
|
-
let helpers = {}
|
|
5
|
-
|
|
6
|
-
helpers.validateUUIDv4 = function (id) {
|
|
7
|
-
const expression = '^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$'
|
|
8
|
-
const regex = new RegExp(expression, 'i')
|
|
9
|
-
return regex.test(id)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
helpers.validateEmail = function (value) {
|
|
13
|
-
const regex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
|
|
14
|
-
return regex.test(value);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
helpers.threeOrMoreVertices = function(vertices) {
|
|
18
|
-
return vertices.length >= 3;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
helpers.validateCustomData = function (data) {
|
|
22
|
-
const customDataKeys = Object.keys(data)
|
|
23
|
-
let hasValidationErrors = false
|
|
24
|
-
|
|
25
|
-
customDataKeys.forEach(key => {
|
|
26
|
-
const alphaNumericValidation = new RegExp(/^[\w\s]+$/)
|
|
27
|
-
if(!alphaNumericValidation.test(key)){
|
|
28
|
-
hasValidationErrors = true
|
|
29
|
-
}
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
const checkDuplicateKeys = [...new Set(customDataKeys)]
|
|
33
|
-
if(customDataKeys.length > checkDuplicateKeys.length) {
|
|
34
|
-
hasValidationErrors = true
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return !hasValidationErrors
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
helpers.checkDuplicateKeys = function (data) {
|
|
41
|
-
const customDataKeys = Object.keys(data)
|
|
42
|
-
let hasValidationErrors = false
|
|
43
|
-
|
|
44
|
-
const duplicateKeys = [...new Set(customDataKeys)]
|
|
45
|
-
if(customDataKeys.length > duplicateKeys.length) {
|
|
46
|
-
hasValidationErrors = true
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return !hasValidationErrors
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
helpers.checkIsDifferent = function(propertyName) {
|
|
53
|
-
return function(propertyA) {
|
|
54
|
-
const propertyB = this[propertyName];
|
|
55
|
-
|
|
56
|
-
if (equal(clean(propertyA), clean(propertyB))) {
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return true
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
helpers.checkConditionsSuitableForBeacon = function(zone, next) {
|
|
65
|
-
let hasBeacons = false;
|
|
66
|
-
if( zone.geofeatures && zone.geofeatures.length ) {
|
|
67
|
-
for( let geofeature of zone.geofeatures ) {
|
|
68
|
-
if( geofeature.type === "beacon" ) {
|
|
69
|
-
hasBeacons = true;
|
|
70
|
-
break;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
if( !hasBeacons )
|
|
75
|
-
return next(); // No beacons.
|
|
76
|
-
if( !zone.conditions || !zone.conditions.length )
|
|
77
|
-
return next(); // No conditions.
|
|
78
|
-
for( let condition of zone.conditions ) {
|
|
79
|
-
if( condition.type === "travelDirection" ) {
|
|
80
|
-
return next(new Error("Zone cannot both contain a beacon and have a Travel Direction condition."))
|
|
81
|
-
}
|
|
82
|
-
if( condition.type === "speed" ) {
|
|
83
|
-
return next(new Error("Zone cannot both contain a beacon and have a Speed condition."))
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
next();
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
helpers.checkMinimumGeofeaturesValidForZone = function(zone, next) {
|
|
90
|
-
if( !zone.geofeatures )
|
|
91
|
-
return next();
|
|
92
|
-
if( !zone.conditions || !zone.conditions.length )
|
|
93
|
-
return next(); // No conditions.
|
|
94
|
-
for( let condition of zone.conditions ) {
|
|
95
|
-
if( condition.type === "travelPath" && condition.minimumGeofeaturesCrossed > zone.geofeatures.length ) {
|
|
96
|
-
return next(new Error("Zone must not have minimumGeofeaturesCrossed higher than geofeatures count"))
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
next();
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
module.exports = helpers
|
package/models/Account.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Richard Tan on 27/02/18.
|
|
3
|
-
* Copyright : Bluedot Innovation.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
let mongoose = require('mongoose')
|
|
7
|
-
// let Schema = mongoose.Schema
|
|
8
|
-
let StateEnum = require('@bluedot-innovation/enums').StateEnum
|
|
9
|
-
let uuidv4 = require('uuid/v4')
|
|
10
|
-
let patcher = require('mongoose-json-patch')
|
|
11
|
-
const helpers = require('../helpers')
|
|
12
|
-
|
|
13
|
-
let AccountSchema = new mongoose.Schema({
|
|
14
|
-
_id: {type: String, default: uuidv4},
|
|
15
|
-
customerApiKey: {type: String, default: uuidv4}, // Backwards compatability
|
|
16
|
-
name: {type: String, required: true},
|
|
17
|
-
createdBy: {
|
|
18
|
-
// type: Schema.Types.ObjectId,
|
|
19
|
-
type: String,
|
|
20
|
-
validator: helpers.validateUUIDv4,
|
|
21
|
-
required: true,
|
|
22
|
-
// Adding a default to allow the lambdas to pass until we know who
|
|
23
|
-
// the createdBy will be.
|
|
24
|
-
default: uuidv4
|
|
25
|
-
},
|
|
26
|
-
state: {type: String, default: StateEnum.active},
|
|
27
|
-
poiCredits: Number,
|
|
28
|
-
integrations: Object,
|
|
29
|
-
features: Object,
|
|
30
|
-
creationTime: {type: Date, default: Date.now},
|
|
31
|
-
lastUpdateTime: {type: Date, default: Date.now}
|
|
32
|
-
},
|
|
33
|
-
{collection: 'account'})
|
|
34
|
-
|
|
35
|
-
AccountSchema.plugin(patcher)
|
|
36
|
-
|
|
37
|
-
// optional mongoose
|
|
38
|
-
let model = (mongooseInstance) => {
|
|
39
|
-
let Account
|
|
40
|
-
if (mongooseInstance) {
|
|
41
|
-
Account = mongooseInstance.model('Account', AccountSchema)
|
|
42
|
-
} else {
|
|
43
|
-
Account = mongoose.model('Account', AccountSchema)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return Account
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
50
|
-
module.exports = { Model: model, Schema: AccountSchema }
|
package/models/Project.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Ryan W. Kan on 14/02/2018.
|
|
3
|
-
* Copyright : Bluedot Innovations.
|
|
4
|
-
* Owner :
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
let mongoose = require('mongoose')
|
|
8
|
-
let Schema = mongoose.Schema
|
|
9
|
-
let StateEnum = require('@bluedot-innovation/enums').StateEnum
|
|
10
|
-
let uuidv4 = require('uuid/v4')
|
|
11
|
-
let patcher = require('mongoose-json-patch')
|
|
12
|
-
let helpers = require('../helpers')
|
|
13
|
-
|
|
14
|
-
let WebhookSchema = require('../schemas/Webhook')
|
|
15
|
-
|
|
16
|
-
let ProjectSchema = new mongoose.Schema({
|
|
17
|
-
_id: {type: String, default: uuidv4},
|
|
18
|
-
nextRuleUpdateInterval: {
|
|
19
|
-
type: Number,
|
|
20
|
-
required: [true, 'nextRuleUpdateInterval is required'],
|
|
21
|
-
min: 5,
|
|
22
|
-
max: 172800,
|
|
23
|
-
validate: {
|
|
24
|
-
validator: Number.isInteger,
|
|
25
|
-
message: '{VALUE} is not a number'
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
creationTime: {type: Date, default: Date.now},
|
|
29
|
-
lastUpdateTime: {type: Date, default: Date.now},
|
|
30
|
-
lastSyncTime: {type: Date, default: Date.now},
|
|
31
|
-
name: {type: String, required: [true, 'name is required']},
|
|
32
|
-
accountId: {type: String, required: true, validate: {isAsync: false, validator: helpers.validateUUIDv4, msg: 'default error message'}},
|
|
33
|
-
webhooks: [WebhookSchema],
|
|
34
|
-
configurationParameters: {type: Schema.Types.Mixed, default: null}, // http://collab.bluedot.io/display/PD/Remote+configuration
|
|
35
|
-
firebaseApiKey: {type: String},
|
|
36
|
-
apiKey: {type: String}
|
|
37
|
-
},
|
|
38
|
-
{collection: 'project'})
|
|
39
|
-
|
|
40
|
-
ProjectSchema.plugin(patcher)
|
|
41
|
-
|
|
42
|
-
// optional mongoose
|
|
43
|
-
let model = (mongooseInstance) => {
|
|
44
|
-
let Project
|
|
45
|
-
if (mongooseInstance) {
|
|
46
|
-
Project = mongooseInstance.model('Project', ProjectSchema)
|
|
47
|
-
} else {
|
|
48
|
-
Project = mongoose.model('Project', ProjectSchema)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return Project
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
55
|
-
module.exports = { Model: model, Schema: ProjectSchema }
|
package/models/UrlAction.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
let mongoose = require('mongoose')
|
|
2
|
-
let StateEnum = require('@bluedot-innovation/enums').StateEnum
|
|
3
|
-
let uuidv4 = require('uuid/v4')
|
|
4
|
-
|
|
5
|
-
let schema = {
|
|
6
|
-
url: {
|
|
7
|
-
type: String,
|
|
8
|
-
required: [true, 'url is required. '],
|
|
9
|
-
validate: {
|
|
10
|
-
isAsync: true,
|
|
11
|
-
validator: validateURL
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
let URLActionSchema = new mongoose.Schema(schema, {
|
|
17
|
-
_id: false,
|
|
18
|
-
__v: false
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
URLActionSchema.add({
|
|
22
|
-
type: {type: String, required: true}
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
function validateURL (url, magicCallback) {
|
|
26
|
-
let urlRegex = new RegExp('^(http[s]?:\\/\\/(www\\.)?|ftp:\\/\\/(www\\.)?|www\\.){1}([0-9A-Za-z-\\.@:%_+~#=]+)+((\\.[a-zA-Z]{2,3})+)(/(.)*)?(\\?(.)*)?')
|
|
27
|
-
if (!urlRegex.test(url)) {
|
|
28
|
-
return magicCallback(false, `${url} is not a valid URL`)
|
|
29
|
-
}
|
|
30
|
-
magicCallback(true)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// optional mongoose
|
|
34
|
-
const model = (mongooseInstance) => {
|
|
35
|
-
let Urlaction
|
|
36
|
-
if (mongooseInstance) {
|
|
37
|
-
Urlaction = mongooseInstance.model('Urlaction', URLActionSchema)
|
|
38
|
-
} else {
|
|
39
|
-
Urlaction = mongoose.model('Urlaction', URLActionSchema)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return Urlaction
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
46
|
-
module.exports = { Model: model, Schema: URLActionSchema, urlActionSchema: schema }
|
package/models/User.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Richard Tan on 27/02/18.
|
|
3
|
-
* Copyright : Bluedot Innovation.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
const StateEnum = require('@bluedot-innovation/enums').StateEnum
|
|
7
|
-
const mongoose = require('mongoose')
|
|
8
|
-
const patcher = require('mongoose-json-patch')
|
|
9
|
-
const helpers = require('../helpers')
|
|
10
|
-
const ProjectPermission = require('../schemas/ProjectPermission')
|
|
11
|
-
const uuidv4 = require('uuid/v4')
|
|
12
|
-
|
|
13
|
-
let UserSchema = new mongoose.Schema({
|
|
14
|
-
_id: {type: String, default: uuidv4},
|
|
15
|
-
username: {
|
|
16
|
-
type: String,
|
|
17
|
-
required: true,
|
|
18
|
-
maxlength: 100,
|
|
19
|
-
unique: true
|
|
20
|
-
},
|
|
21
|
-
email: {
|
|
22
|
-
type: String,
|
|
23
|
-
required: true,
|
|
24
|
-
validate: {
|
|
25
|
-
validator: helpers.validateEmail,
|
|
26
|
-
message: '{VALUE} is not a valid email'
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
firstName: {type: String, required: true},
|
|
30
|
-
lastName: {type: String, required: true},
|
|
31
|
-
phoneNumber: {type: String, maxlength: 20},
|
|
32
|
-
state: {type: String, default: StateEnum.active},
|
|
33
|
-
creationTime: {type: Date, default: Date.now},
|
|
34
|
-
lastUpdateTime: {type: Date, default: Date.now},
|
|
35
|
-
isAdmin: {type: Boolean, required: true},
|
|
36
|
-
secret: String,
|
|
37
|
-
projectPermissions: [ProjectPermission],
|
|
38
|
-
accountId: {
|
|
39
|
-
type: String,
|
|
40
|
-
required: true,
|
|
41
|
-
validator: helpers.validateUUIDv4
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
{collection: 'user'})
|
|
45
|
-
|
|
46
|
-
UserSchema.plugin(patcher)
|
|
47
|
-
|
|
48
|
-
// optional mongoose
|
|
49
|
-
let model = (mongooseInstance) => {
|
|
50
|
-
let User
|
|
51
|
-
if (mongooseInstance) {
|
|
52
|
-
User = mongooseInstance.model('User', UserSchema)
|
|
53
|
-
} else {
|
|
54
|
-
User = mongoose.model('User', UserSchema)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return User
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Exports Mongoose Model, Mongoose Schema, JSON schema (required locally for discriminators)
|
|
61
|
-
module.exports = { Model: model, Schema: UserSchema }
|