You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP

@sensebox/opensensemap-api-models

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sensebox/opensensemap-api-models - npm Package Compare versions

Comparing version

to
1.2.0

@@ -35,2 +35,6 @@ 'use strict';

},
'claims_ttl': {
'amount': 1,
'unit': 'd'
},
'image_folder': './userimages/',

@@ -43,2 +47,3 @@ });

{ model: User } = require('./src/user/user'),
{ model: Claim } = require('./src/box/claim'),
utils = require('./src/utils'),

@@ -50,2 +55,3 @@ decoding = require('./src/measurement/decoding'),

Box,
Claim,
Measurement,

@@ -52,0 +58,0 @@ Sensor,

{
"name": "@sensebox/opensensemap-api-models",
"description": "openSenseMap data models and database connection",
"version": "1.1.2",
"version": "1.2.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"@grpc/grpc-js": "^1.3.7",
"@grpc/proto-loader": "^0.6.4",
"@sensebox/osem-protos": "^1.1.0",
"@sensebox/sketch-templater": "^1.10.5",
"@sensebox/sketch-templater": "1.12.1",
"bcrypt": "^5.0.1",

@@ -14,3 +16,2 @@ "bunyan": "^1.8.15",

"got": "^11.8.2",
"grpc": "^1.24.7",
"isemail": "^3.0.0",

@@ -17,0 +18,0 @@ "jsonpath": "^1.1.1",

@@ -68,3 +68,3 @@ 'use strict';

grouptag: {
type: String,
type: [String], // Default value for array is [] (empty array)
trim: true,

@@ -236,5 +236,2 @@ required: false

} = {},
gsm: {
imsi, secret_code
} = {},
useAuth

@@ -260,5 +257,2 @@ }) {

if (model) {
if (model === 'homeV2GSM' && (!imsi || !secret_code)) {
return Promise.reject(new ModelError('homeV2GSM can not be created without imsi or secret code', { type: 'UnprocessableEntityError' }));
}
//activate useAuth only for certain models until all sketches are updated

@@ -279,10 +273,3 @@ if (['homeV2Lora', 'homeV2Ethernet', 'homeV2EthernetFeinstaub', 'homeV2Wifi', 'homeV2WifiFeinstaub', 'homeEthernet', 'homeWifi', 'homeEthernetFeinstaub', 'homeWifiFeinstaub', 'hackair_home_v2'].indexOf(model) !== -1) {

}
if (imsi && secret_code) {
integrations.gsm = { imsi, secret_code };
}
if (imsi && secret_code) {
integrations.gsm = { imsi, secret_code };
}
const boxLocation = {

@@ -900,3 +887,3 @@ coordinates: location,

if (typeof args[prop] !== 'undefined') {
box.set(prop, (args[prop] === '' ? undefined : args[prop]));
box.set(prop, ((args[prop] === '' || (Array.isArray(args[prop]) && args[prop].length === 0)) ? undefined : args[prop]));
}

@@ -959,7 +946,7 @@ }

const buildFindBoxesQuery = function buildFindBoxesQuery (opts = {}) {
const { phenomenon, fromDate, toDate, bbox, near, maxDistance } = opts,
const { phenomenon, fromDate, toDate, bbox, near, maxDistance, grouptag } = opts,
query = {};
// simple string parameters
for (const param of ['exposure', 'model', 'grouptag']) {
for (const param of ['exposure', 'model']) {
if (opts[param]) {

@@ -970,2 +957,6 @@ query[param] = { '$in': opts[param] };

if (grouptag) {
query['grouptag'] = { '$all': grouptag };
}
// bbox search parameter

@@ -999,2 +990,18 @@ if (bbox) {

// return boxes that match the name paramter
boxSchema.statics.findBoxes = function findBoxes (opts = {}) {
const { name, limit } = opts;
const filter = {
name: { '$regex': name, '$options': 'i' }
};
const projection = {
_id: 1,
name: 1,
currentLocation: 1
};
return Promise.resolve(this.find(filter, projection).limit(limit)
.cursor({ lean: true }));
};
// returns a minimal subset of the box documents for speed

@@ -1001,0 +1008,0 @@ boxSchema.statics.findBoxesMinimal = function findBoxesMinimal (opts = {}) {

@@ -10,3 +10,9 @@ 'use strict';

enabled: { type: Boolean, default: false, required: true },
url: { type: String, trim: true, validate: [function validMqttUri (url) { return url === '' || url.startsWith('mqtt://') || url.startsWith('ws://'); }, '{PATH} must be either empty or start with mqtt:// or ws://'] },
url: { type: String, trim: true, validate: [function validMqttUri (url) { return (
url === '' ||
url.startsWith('mqtt://') ||
url.startsWith('mqtts://') ||
url.startsWith('ws://') ||
url.startsWith('wss://')
); }, '{PATH} must be either empty or start with mqtt(s):// or ws(s)://'] },
topic: { type: String, trim: true },

@@ -26,7 +32,2 @@ messageFormat: { type: String, trim: true, enum: ['json', 'csv', 'application/json', 'text/csv', 'debug_plain', ''] },

const tinggSchema = new mongoose.Schema({
imsi: { type: String, trim: true, required: true },
secret_code: { type: String, trim: true, required: true }
}, { _id: false, usePushEach: true });
const integrationSchema = new mongoose.Schema({

@@ -66,9 +67,2 @@ mqtt: {

}]
},
gsm: {
type: tinggSchema,
required: false,
validate: function validate () {
return true;
}, msg: 'Something went wrong with GSM creds'
}

@@ -75,0 +69,0 @@ }, { _id: false, usePushEach: true });

'use strict';
const grpc = require('grpc'),
const protoLoader = require('@grpc/proto-loader'),
grpcLibrary = require('@grpc/grpc-js'),
{ mqttProto } = require('@sensebox/osem-protos'),

@@ -25,5 +26,16 @@ log = require('../log'),

const { MqttService } = grpc.load(mqttProto);
const packageDefinition = protoLoader.loadSync(mqttProto, {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true,
});
const MqttService = grpcLibrary.loadPackageDefinition(packageDefinition).MqttService;
const credentials = grpc.credentials.createSsl(Buffer.from(ca_cert), Buffer.from(key), Buffer.from(cert));
const credentials = grpcLibrary.credentials.createSsl(
Buffer.from(ca_cert),
Buffer.from(key),
Buffer.from(cert)
);

@@ -30,0 +42,0 @@ const client = new MqttService(url, credentials);

@@ -33,3 +33,2 @@ 'use strict';

const modelDefinitions = {
'homeV2GSM': senseboxhome_v2,
'homeV2Lora': senseboxhome_v2,

@@ -36,0 +35,0 @@ 'homeV2Ethernet': senseboxhome_v2,

@@ -21,3 +21,4 @@ 'use strict';

windspeed,
scd30_co2
scd30_co2,
dps310_pressure
} = sensorDefinitions;

@@ -41,3 +42,4 @@

windspeed,
scd30_co2
scd30_co2,
dps310_pressure,
];

@@ -43,3 +43,5 @@ 'use strict';

windspeed = require('./windspeed'),
scd30_co2 = require('./scd30_co2');
scd30_co2 = require('./scd30_co2'),
dps310_temperature = require('./dps310_temperature'),
dps310_pressure = require('./dps310_pressure');

@@ -87,3 +89,5 @@ module.exports = {

windspeed,
scd30_co2
scd30_co2,
dps310_temperature,
dps310_pressure
};

@@ -66,8 +66,21 @@ 'use strict';

p0: ['pm01', 'pm0', 'p1.0', 'p0'],
p01: ['pm0.1', 'p0.1'],
p03: ['pm0.3', 'pm03', 'p0.3', 'p03'],
p05: ['pm0.5', 'pm05', 'p0.5', 'p05'],
p1: ['pm10', 'p10', 'p1'],
p2: ['pm2.5', 'pm25', 'p2.5', 'p25', 'p2'],
p4: ['pm4', 'p4'],
p5: ['pm5', 'p5'],
n1: ['nc1.0', 'nc1', 'n1.0', 'n1'],
n01: ['nc0.1', 'n0.1', 'nc01', 'n01'],
n03: ['nc0.3', 'n0.3', 'nc03', 'n03'],
n05: ['nc0.5', 'n0.5', 'nc05', 'n05'],
n4: ['nc4.0', 'n4.0', 'nc4', 'n4'],
n5: ['nc5', 'n5'],
n10: ['nc10', 'n10'],
n25: ['nc2.5', 'n2.5'],
temperature: ['temperatur'],
humidity: ['rel. luftfeuchte', 'luftfeuchtigkeit', 'luftfeuchte'],
pressure: ['luftdruck', 'druck'],
signal: ['stärke', 'signal']
signal: ['stärke', 'signal'],
};

@@ -162,2 +175,1 @@

};

@@ -17,2 +17,3 @@ 'use strict';

{ model: Box } = require('../box/box'),
{ model: Claim } = require('../box/claim'),
mails = require('./mails'),

@@ -356,2 +357,76 @@ moment = require('moment'),

userSchema.methods.transferBox = function transferBox (boxId, date) {
const user = this;
// checkBoxOwner throws ModelError
user.checkBoxOwner(boxId);
return Claim.initClaim(boxId, date)
.then(function (claim) {
return claim;
});
};
userSchema.methods.updateTransfer = function updateTransfer (boxId, token, date) {
const user = this;
// checkBoxOwner throws ModelError
user.checkBoxOwner(boxId);
return Claim.findClaimByToken(token)
.exec()
.then(function (claim) {
if (!claim) {
return Promise.reject(
new ModelError('Coudn\'t update, token not found', {
type: 'NotFoundError',
})
);
}
claim.set('expiresAt', date);
return claim.save();
});
};
userSchema.methods.removeTransfer = function removeTransfer (boxId, token) {
const user = this;
// checkBoxOwner throws ModelError
user.checkBoxOwner(boxId);
return Claim.findClaimByToken(token)
.exec()
.then(function (claim) {
if (!claim) {
return Promise.reject(new ModelError('Coudn\'t remove, token not found', { type: 'NotFoundError' }));
}
// remove token
return claim.remove();
});
};
userSchema.methods.claimBox = function claimBox (token) {
const user = this;
return Claim.findClaimByToken(token)
.exec()
.then(function (claim) {
if (!claim) {
return Promise.reject(new ModelError('Token was not found', { type: 'NotFoundError' }));
}
return {
owner: user.id,
claim
};
})
.catch(function (error) {
throw new ModelError(error.message, token);
});
};
userSchema.methods.destroyUser = function destroyUser ({ sendMail } = { sendMail: true }) {

@@ -358,0 +433,0 @@ return this