@bluedot-innovation/models 6.2.0-alpha.3 → 6.2.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/CHANGELOG.md CHANGED
@@ -1,6 +1,8 @@
1
+ ## 6.2.0
2
+ - Renamed all references to eta to tempo
3
+
1
4
  ## 6.1.4
2
5
  - Added eta fields to androidConfig and iosConfig
3
- - Created mobileConfigInitialiser for updated config profiles in dbs
4
6
 
5
7
  ## 6.1.3
6
8
  - Add `beaconDiscoveyCycleSecs` and `beaconCooloffCycleSecs` to AndroidConfig schema
package/README.MD CHANGED
@@ -47,13 +47,3 @@ CI/CD pipeline. If you need to add a new index, just add it to the indexes objec
47
47
 
48
48
  Indexes should still be added to the mongoose schemas as well, as these can be used in tests by triggering index creation with
49
49
  mockgoose using model.ensureIndexes(), and it provides another level of documentation.
50
-
51
-
52
- ##### On Updating Mobile Config Use Case Profiles
53
-
54
- The default mobile profiles for androidConfig and iosConfig are now defined in the utils/DbInitialiser/mobileConfigInitialiser
55
- file. The mobileConfigProfiles object stores these values for each profile. If you need to add a new profile or change any of the
56
- default values then update the mobileConfigProfiles object and these values will be updated in the dev environment on merge to
57
- master, and updated in production when the manual release pipeline is triggered.
58
-
59
- You can see what values have been added or updated by viewing the logs for the pipeline job after it has finished.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bluedot-innovation/models",
3
- "version": "6.2.0-alpha.3",
4
- "main": "dist/Models.js",
3
+ "version": "6.2.0",
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",
7
7
  "test": "mocha --require __tests__/setup __tests__/**/*.spec.js __tests__/**/**/*.spec.js",
@@ -26,12 +26,9 @@
26
26
  "mongodb": "^3.5.8",
27
27
  "nyc": "^11.3.0",
28
28
  "prettier": "^1.13.5",
29
- "rollup": "^2.16.1",
30
- "rollup-plugin-babel": "^4.4.0",
31
29
  "sinon": "^4.1.2"
32
30
  },
33
31
  "dependencies": {
34
- "@babel/core": "^7.10.2",
35
32
  "@bluedot-innovation/enums": "^2.1.5",
36
33
  "@bluedot-innovation/mongoose-json-patch": "0.0.8",
37
34
  "@mongoosejs/double": "^0.2.0",
@@ -1,6 +1,5 @@
1
1
  const MongoClient = require('mongodb').MongoClient
2
2
  const {createAllIndexesIfNotExists} = require("./indexInitialiser");
3
- const {updateMobileConfigParametersProfiles} = require("./mobileConfigInitialiser");
4
3
 
5
4
  const MONGO_DB_URI = process.env.MONGO_DB_URI
6
5
  const DB_NAME = process.env.DB_NAME
@@ -20,7 +19,6 @@ client.connect(async error => {
20
19
 
21
20
  try{
22
21
  await createAllIndexesIfNotExists(db)
23
- await updateMobileConfigParametersProfiles(db)
24
22
  }catch(error){
25
23
  console.log(error)
26
24
  await client.close()
@@ -1,98 +0,0 @@
1
- const mongoose = require('mongoose')
2
- const {mobileConfigProfiles} = require('../../utils/DbInitialiser/mobileConfigInitialiser')
3
- const {identifyDifferences} = require('../../utils/DbInitialiser/helpers')
4
- const iosConfigSchema = require('../../schemas/IosConfig')
5
- const androidConfigSchema = require('../../schemas/AndroidConfig')
6
- const ConfigurationParametersSchema = require('../../models/ConfigurationParameters').Schema
7
- const assert = require('chai').assert
8
-
9
- describe("dbInitialiser settings", () => {
10
- describe("mobileConfig profiles", () => {
11
- Object.values(mobileConfigProfiles).map(profile => {
12
- it(`should successfully validate ${profile.name} profile`, async () => {
13
- const ConfigurationParameters = new mongoose.Document(profile, ConfigurationParametersSchema);
14
- let validationError = await ConfigurationParameters.validate()
15
- assert.notExists(validationError, "there should be no validation error")
16
- })
17
- })
18
- })
19
-
20
- describe("helper functions", () => {
21
- describe("identifyDifferences function", () => {
22
- it("should identify no differences for identical objects", () => {
23
- const mockObjectToUpdate = {
24
- testObjectProp: {
25
- testInnerProp: "test"
26
- },
27
- testArrayProp: ['test1', 'test6'],
28
- testNullProp: null
29
- }
30
- const mockDefaultObject = {
31
- testObjectProp: {
32
- testInnerProp: "test"
33
- },
34
- testArrayProp: ['test1', 'test6'],
35
- testNullProp: null
36
- }
37
- const {
38
- newFieldsToAdd,
39
- existingFieldsToUpdate,
40
- existingFieldsNotFoundInDefault
41
- } = identifyDifferences(mockObjectToUpdate, mockDefaultObject);
42
- assert.lengthOf(newFieldsToAdd, 0, "no new fields should be present")
43
- assert.lengthOf(existingFieldsToUpdate, 0, "no existing fields should be updated")
44
- assert.lengthOf(existingFieldsNotFoundInDefault, 0, "no existing fields should be found that don't exist in default")
45
- })
46
-
47
- it("should identify fields to update for objects with same keys and different values", () => {
48
- const mockObjectToUpdate = {
49
- testObjectProp: {
50
- testInnerProp: "test"
51
- },
52
- testArrayProp: ['test1', 'test6'],
53
- testNullProp: null
54
- }
55
-
56
- const mockDefaultObject = {
57
- testObjectProp: {
58
- testInnerProp: "different-value"
59
- },
60
- testArrayProp: ['test1', 'different-value'],
61
- testNullProp: null
62
- }
63
- const {
64
- newFieldsToAdd,
65
- existingFieldsToUpdate,
66
- existingFieldsNotFoundInDefault
67
- } = identifyDifferences(mockObjectToUpdate, mockDefaultObject);
68
- assert.lengthOf(newFieldsToAdd, 0, "no new fields should be present")
69
- assert.lengthOf(existingFieldsToUpdate, 2, "two existing fields should be updated")
70
- assert.lengthOf(existingFieldsNotFoundInDefault, 0, "no existing fields should be found that don't exist in default")
71
- })
72
-
73
- it("should identify existing fields not in default object when values are present in objectToUpdate but not default object", () => {
74
- const mockObjectToUpdate = {
75
- testObjectProp: {
76
- testInnerProp: "test"
77
- },
78
- testArrayProp: ['test1', 'test6'],
79
- testNullProp: null
80
- }
81
-
82
- const mockDefaultObject = {
83
- testObjectProp: {
84
- testInnerProp: "test"
85
- }
86
- }
87
- const {
88
- newFieldsToAdd,
89
- existingFieldsToUpdate,
90
- existingFieldsNotFoundInDefault
91
- } = identifyDifferences(mockObjectToUpdate, mockDefaultObject);
92
- assert.lengthOf(newFieldsToAdd, 0, "no new fields should be present")
93
- assert.lengthOf(existingFieldsToUpdate, 0, "no existing fields should be updated")
94
- assert.lengthOf(existingFieldsNotFoundInDefault, 2, "two existing fields should be found that don't exist in default")
95
- })
96
- })
97
- })
98
- })
package/dist/Models.js DELETED
@@ -1,75 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- * Created by andrewstirling on 22/12/16.
5
- */
6
- const mongoose = require('mongoose');
7
-
8
- let Models = {};
9
- Models.Account = require('./models/Account').Model;
10
- Models.Beacon = require('./models/Beacon').Model;
11
- Models.MessageAction = require('./models/MessageAction').Model;
12
- Models.Project = require('./models/Project').Model;
13
- Models.UrlAction = require('./models/UrlAction').Model;
14
- Models.User = require('./models/User').Model;
15
- Models.Zone = require('./models/Zone').Model; // Geofeatures
16
-
17
- Models.BoundingBox = require('./models/geofeatures/BoundingBox').Model;
18
- Models.Circle = require('./models/geofeatures/Circle').Model;
19
- Models.Polygon = require('./models/geofeatures/Polygon').Model;
20
- Models.Geoline = require('./models/geofeatures/Geoline').Model;
21
- Models.ZoneBeacon = require('./models/geofeatures/ZoneBeacon').Model; // Conditions
22
-
23
- Models.DayRange = require('./models/conditions/DayRange').Model;
24
- Models.TimeActive = require('./models/conditions/TimeActive').Model;
25
- Models.TravelPath = require('./models/conditions/TravelPath').Model;
26
- Models.Speed = require('./models/conditions/Speed').Model;
27
- Models.TravelDirection = require('./models/conditions/TravelDirection').Model; // Test Management Portal
28
-
29
- Models.TestDevice = require('./models/TestDevice').Model;
30
- Models.TestDeviceCluster = require('./models/TestDeviceCluster').Model;
31
- Models.TestInstance = require('./models/TestInstance').Model;
32
- Models.TestScenario = require('./models/TestScenario').Model; // Added V1 Application model to get Remote Config details for Test Management Portal.
33
- // This model can be removed once we start using V2 models.
34
-
35
- Models.Application = require('./models/Application').Model; // Blue Connect
36
-
37
- Models.AdminPortalUser = require('./models/AdminPortalUser').Model;
38
- Models.CustomerLogin = require('./models/CustomerLogin').Model;
39
- Models.NotificationLogEntry = require('./models/NotificationLogEntry').Model;
40
- Models.DBEvent = require('./models/DBEvent').Model;
41
- Models.SingleUseToken = require('./models/SingleUseToken').Model;
42
- Models.Contract = require('./models/Contract').Model;
43
- Models.ConfigurationParameters = require('./models/ConfigurationParameters').Model; // Stats Aggregator
44
-
45
- Models.CumulativeRulesRequests = require('./models/CumulativeRulesRequests').Model;
46
- Models.MonthlyStats = require('./models/MonthlyStats').Model;
47
- Models.DailyStats = require('./models/DailyStats').Model;
48
- let Schemas = {};
49
- Schemas.Account = require('./models/Account').Schema;
50
- Schemas.Beacon = require('./models/Beacon').Schema;
51
- Schemas.MessageAction = require('./models/MessageAction').Schema;
52
- Schemas.Application = require('./models/Application').Schema;
53
- Schemas.Project = require('./models/Project').Schema;
54
- Schemas.UrlAction = require('./models/UrlAction').Schema;
55
- Schemas.User = require('./models/User').Schema;
56
- Schemas.Zone = require('./models/Zone').Schema; // Stats Aggregator Schemas
57
-
58
- Schemas.DailyStats = require('./models/DailyStats').Schema;
59
- Schemas.MonthlyStats = require('./models/MonthlyStats').Schema;
60
- Schemas.CumulativeRulesRequests = require('./models/ConfigurationParameters').Schema; // Geofeatures
61
-
62
- Schemas.BoundingBox = require('./models/geofeatures/BoundingBox').Schema;
63
- Schemas.Circle = require('./models/geofeatures/Circle').Schema;
64
- Schemas.Polygon = require('./models/geofeatures/Polygon').Schema;
65
- Schemas.Geoline = require('./models/geofeatures/Geoline').Schema;
66
- Schemas.ZoneBeacon = require('./models/geofeatures/ZoneBeacon').Schema; // Conditions
67
-
68
- Schemas.DayRange = require('./models/conditions/DayRange').Schema;
69
- Schemas.Speed = require('./models/conditions/Speed').Schema;
70
- Schemas.TimeActive = require('./models/conditions/TimeActive').Schema;
71
- Schemas.TravelPath = require('./models/conditions/TravelPath').Schema;
72
- Schemas.TravelDirection = require('./models/conditions/TravelDirection').Schema;
73
- Models.Schemas = Schemas;
74
- Models.mongoose = mongoose;
75
- module.exports = Models;
package/rollup.config.js DELETED
@@ -1,20 +0,0 @@
1
- import pkg from './package.json';
2
- import babel from 'rollup-plugin-babel';
3
-
4
- export default {
5
- input: 'Models.js',
6
- output: [
7
- {
8
- file: pkg.main,
9
- format: 'cjs'
10
- }
11
- ],
12
- external: [
13
- ...Object.keys(pkg.dependencies || {}),
14
- ],
15
- plugins: [
16
- babel({
17
- exclude: 'utils/DbInitialiser',
18
- }),
19
- ],
20
- }
@@ -1,58 +0,0 @@
1
- const deepEqual = require('deep-equal')
2
-
3
- /*
4
- This function identifies differences between a stored object and the saved values that should be applied
5
- Allows you to identify what changes are being made when updating default values in the DB, for example for
6
- androidConfig or iosConfig settings. Also warns of any fields present in the db that are not in the saved
7
- default values as these should all be present.
8
- */
9
- const identifyDifferences = (objectToUpdate, defaultObject, path = "") => {
10
- const fieldsToUpdate = [];
11
- const fieldsToAdd = [];
12
- const fieldsNotFoundInDefault = [];
13
- Object.entries(objectToUpdate).forEach(([key, value]) => {
14
- if(key === "_id"){
15
- return
16
- }
17
- const newDefaultValue = defaultObject[key];
18
- const newPath = path ? path + "." + key : key
19
- if(newDefaultValue !== undefined){
20
- if(newDefaultValue !== null && typeof newDefaultValue === 'object'){
21
- if(Array.isArray(newDefaultValue)){
22
- const previousArrayValue = objectToUpdate[key];
23
- if(!deepEqual(newDefaultValue, previousArrayValue)){
24
- fieldsToUpdate.push({key: newPath, value: newDefaultValue, previousValue: previousArrayValue});
25
- }
26
- }else{
27
- const {
28
- newFieldsToAdd,
29
- existingFieldsToUpdate,
30
- existingFieldsNotFoundInDefault
31
- } = identifyDifferences(objectToUpdate[key], newDefaultValue, newPath)
32
- fieldsToUpdate.push(...existingFieldsToUpdate);
33
- fieldsToAdd.push(...newFieldsToAdd);
34
- fieldsNotFoundInDefault.push(...existingFieldsNotFoundInDefault);
35
- }
36
- }else if(objectToUpdate[key] !== defaultObject[key]){
37
- fieldsToUpdate.push({key: newPath, value: defaultObject[key], previousValue: objectToUpdate[key]});
38
- }
39
- }else{
40
- fieldsNotFoundInDefault.push({key: newPath, value: objectToUpdate[key]});
41
- }
42
- });
43
- Object.entries(defaultObject).forEach(([key, value]) => {
44
- const newPath = path ? path + "." + key : key
45
- if(objectToUpdate[key] === undefined){
46
- fieldsToAdd.push({key: newPath, value})
47
- }
48
- });
49
- return {
50
- newFieldsToAdd: fieldsToAdd,
51
- existingFieldsToUpdate: fieldsToUpdate,
52
- existingFieldsNotFoundInDefault: fieldsNotFoundInDefault
53
- }
54
- }
55
-
56
- module.exports = {
57
- identifyDifferences
58
- }
@@ -1,173 +0,0 @@
1
- const {identifyDifferences} = require("./helpers");
2
-
3
- const defaultAndroidConfig = {
4
- maximumPageSize: 256,
5
- useCaseType: 'Default',
6
- applicationLoggingEnabled: false,
7
- filteringEnabled: false,
8
- endpointUrl: 'https://www.pointapi.bluedot.com.au/pointapi-v1/',
9
- beaconCooloffCycleSecs: 10,
10
- beaconDiscoveyCycleSecs: 20, // Typo intentional to match typo in SDK
11
- beaconActivationDistance: 30,
12
- beaconActivationCoefficient: 0.5,
13
- beaconReevaluationDistance: 25,
14
- checkoutDistanceAccuracy: 50,
15
- checkoutTimeAccuracy: 60,
16
- trackingOnGpsAccuracyThreshold: 200,
17
- triggeringOnGpsAccuracyThreshold: 20,
18
- triggeringOnWifiAccuracyThreshold: 100,
19
- enableAlarmClock: false,
20
- tempo: {
21
- tempoUpdateInterval: 30,
22
- tempoTimeoutPeriod: 1800
23
- }
24
- };
25
-
26
- const defaultIosConfig = {
27
- useCaseType: 'Default',
28
- triggerEngine: 'BD',
29
- maximumPageSize: 256,
30
- starvationDetector: {
31
- starvationDetectorMinAllowedStarvationTimeInterval: 30,
32
- starvationDetectorSecsAllowedPerMetre: 0.0225,
33
- starvationDetectorEnabled: false
34
- },
35
- accuracySuppression: {
36
- accuracySuppressionGracePeriod: 600,
37
- accuracySuppressionMinAccuracyTimeInterval: 60,
38
- accuracySuppressionMinAccuracy: 3000,
39
- accuracySuppressionMaxAccuracyTimeInterval: 30,
40
- accuracySuppressionMaxAccuracy: 5,
41
- accuracySuppressionEnabled: false
42
- },
43
- applicationLoggingEnabled: false,
44
- filteringEnabled: false,
45
- endpointUrl: 'https://www.pointapi.bluedot.com.au/pointapi-v1/',
46
- triggeringOnPollingLocationFarthestThreshold: 5000,
47
- triggeringOnPollingLocationFurtherThreshold: 3000,
48
- triggeringOnPollingLocationBasicThreshold: 1000,
49
- focalDistanceAccuracyCoefficient: 0.9,
50
- periodicPollingEnabled: true,
51
- beaconActivationDistance: 30,
52
- beaconActivationCoefficient: 0.5,
53
- beaconReevaluationDistance: 10,
54
- checkoutDistanceAccuracy: 50,
55
- checkoutTimeAccuracy: 60,
56
- trackingOnGpsAccuracyThreshold: 400,
57
- triggeringOnGpsAccuracyThreshold: 30,
58
- triggeringOnWifiAccuracyThreshold: 70,
59
- tempo: {
60
- tempoUpdateInterval: 30,
61
- tempoTimeoutPeriod: 1800
62
- },
63
- accelerometerEnablementThreshold: 1000
64
- }
65
-
66
- const mobileConfigProfiles = {
67
- default: {
68
- name: 'default',
69
- androidConfig: defaultAndroidConfig,
70
- iosConfig: defaultIosConfig
71
- },
72
- retail: {
73
- name: 'retail',
74
- androidConfig: {
75
- ...defaultAndroidConfig,
76
- useCaseType: `Retail`
77
- },
78
- iosConfig: {
79
- ...defaultIosConfig,
80
- useCaseType: `Retail`,
81
- triggerEngine: `Hybrid`,
82
- trackingOnGpsAccuracyThreshold: 200,
83
- //accelerometerEnablementThreshold: undefined //TODO: Check this
84
- }
85
- },
86
- automotive: {
87
- name: 'automotive',
88
- androidConfig: {
89
- ...defaultAndroidConfig,
90
- useCaseType: "Automotive",
91
- maximumPageSize: 512,
92
- trackingOnGpsAccuracyThreshold: 1111
93
- },
94
- iosConfig: {
95
- ...defaultIosConfig,
96
- useCaseType: 'Automotive',
97
- maximumPageSize: 512,
98
- triggeringOnPollingLocationFarthestThreshold: 120000,
99
- triggeringOnPollingLocationFurtherThreshold: 110000,
100
- triggeringOnPollingLocationBasicThreshold: 99000,
101
- periodicPollingEnabled: false,
102
- trackingOnGpsAccuracyThreshold: 3000,
103
- //accelerometerEnablementThreshold: undefined //TODO: Check this
104
- }
105
- }
106
- }
107
-
108
- const updateConfigParams = async (configurationParametersCollection, profileToUpdate, existingProfile) => {
109
- console.log(`Checking profile: ${profileToUpdate.name}`)
110
- const {newFieldsToAdd, existingFieldsToUpdate, existingFieldsNotFoundInDefault} = identifyDifferences(existingProfile, profileToUpdate)
111
- if(existingFieldsToUpdate.length){
112
- console.log(`Fields to update: ${JSON.stringify(existingFieldsToUpdate)}`)
113
- }
114
- if(newFieldsToAdd.length){
115
- console.log(`Fields to add: ${JSON.stringify(newFieldsToAdd)}`)
116
- }
117
- // Any values present in the DB but not found in this profile will not be overwritten but should be added
118
- // to the profile to ensure they are kept common across all environments
119
- if(existingFieldsNotFoundInDefault.length){
120
- console.log(`Fields not found in default: ${JSON.stringify(existingFieldsNotFoundInDefault)}`)
121
- }
122
- if(existingFieldsToUpdate.length || newFieldsToAdd.length){
123
- console.log(`Need to update: ${profileToUpdate.name}`)
124
- const setModifications = {};
125
- existingFieldsToUpdate.forEach(({key, value}) => {
126
- setModifications[key] = value
127
- })
128
- newFieldsToAdd.forEach(({key, value}) => {
129
- setModifications[key] = value
130
- })
131
- const updateModifications = {
132
- $set: setModifications
133
- }
134
- console.log(`Update query: ${JSON.stringify(updateModifications)}`)
135
- await configurationParametersCollection.updateOne({name: profileToUpdate.name}, updateModifications)
136
- console.log(`Profile ${profileToUpdate.name} has been updated`)
137
- }else{
138
- console.log(`Profile ${profileToUpdate.name} already matches saved settings`)
139
- }
140
- }
141
-
142
- const createConfigParams = async (configurationParametersCollection, profileToCreate) => {
143
- console.log(`Need to create: ${profileToCreate.name}`)
144
- await configurationParametersCollection.insertOne(profileToCreate)
145
- console.log(`Profile ${profileToCreate.name} created`)
146
- }
147
-
148
- const updateMobileConfigParametersProfiles = db => {
149
- const configCollection = db.collection('configurationParameters');
150
- const updateConfigPromises = Object.values(mobileConfigProfiles).map(async useCaseSettings => {
151
- const foundProfile = await configCollection.find({name: useCaseSettings.name}).toArray()
152
- if(foundProfile.length === 0){
153
- return createConfigParams(configCollection, useCaseSettings)
154
- }else if(foundProfile.length === 1){
155
- return updateConfigParams(configCollection, useCaseSettings, foundProfile[0])
156
- }else{
157
- throw new Error(`Multiple configuration profiles (${foundProfile.length}) found with target name: ${useCaseSettings.name}`)
158
- }
159
- })
160
-
161
- // We want to execute all profile update promises, then if there are any errors throw an error
162
- return Promise.allSettled(updateConfigPromises).then(results => {
163
- const hasErrors = results.find(result => result.status === "rejected")
164
- if(hasErrors){
165
- throw new Error("An error occurred updating mobile config profiles")
166
- }
167
- })
168
- }
169
-
170
- module.exports = {
171
- mobileConfigProfiles,
172
- updateMobileConfigParametersProfiles
173
- }