Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #126

Merged
merged 26 commits into from
Oct 17, 2023
Merged

Dev #126

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
dd0c7f0
Point readme to correct location of swagger.yaml
Jan 28, 2022
cf5646b
Increase debounce for data loads to 15 seconds and trigger a data-loa…
sulkaharo May 29, 2023
93ffb25
Upgrade Mongo driver to latest legacy-API compatible version
sulkaharo Jun 1, 2023
32163a0
* Fix storage so tests pass with new Mongo driver
sulkaharo Jun 1, 2023
ea56b79
Fix authorization storage
sulkaharo Jun 2, 2023
b4ab7ce
New translations en.json (Greek)
sulkaharo Aug 21, 2023
203f16f
README.md: use shareous1 for Nightscout connect using Dexcom share
bjornoleh Aug 13, 2023
2ba788d
Merge branch 'dev' into crowdin_incoming
sulkaharo Sep 13, 2023
c591292
New translations en.json (Chinese Simplified)
sulkaharo Sep 14, 2023
b0756cc
New translations en.json (Chinese Simplified)
sulkaharo Sep 15, 2023
0b44d5d
New translations en.json (Spanish)
sulkaharo Sep 15, 2023
ed10ca1
New translations en.json (Chinese Simplified)
sulkaharo Sep 15, 2023
10cd789
Merge branch 'dev' into shareous
bjornoleh Oct 6, 2023
b1eb27e
Merge pull request #8073 from bjornoleh/shareous
bewest Oct 6, 2023
6e1c69f
Merge branch 'dev' into readme-swagger-link
bewest Oct 12, 2023
4a461e5
Merge pull request #7312 from jakobsandberg/readme-swagger-link
bewest Oct 12, 2023
3893eb4
allow running any version of LTS
bewest Oct 12, 2023
ebece1b
n 14 && npm install
bewest Oct 12, 2023
48dfa22
set expectation to take around 15 seconds for first load
bewest Oct 12, 2023
c6c0a0a
Merge remote-tracking branch 'official/dev' into less_frequent_db_upd…
bewest Oct 12, 2023
7819223
Allow any LTS version.
bewest Oct 12, 2023
6964916
n 14 && npm install
bewest Oct 12, 2023
97a603f
upgrade nightscout-connect@^0.0.12, npm install
bewest Oct 12, 2023
2757fe5
Merge pull request #8026 from nightscout/less_frequent_db_updates
bewest Oct 12, 2023
2d18433
Merge branch 'dev' into crowdin_incoming
bewest Oct 12, 2023
5d83048
Merge pull request #8082 from nightscout/crowdin_incoming
bewest Oct 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ Once you've installed Nightscout, you can access API documentation by loading `/
* Boluses over 2U: `http://localhost:1337/api/v1/treatments.json?find[insulin][$gte]=2`

The API is Swagger enabled, so you can generate client code to make working with the API easy.
To learn more about the Nightscout API, visit https://YOUR-SITE.com/api-docs/ or review [swagger.yaml](swagger.yaml).
To learn more about the Nightscout API, visit https://YOUR-SITE.com/api-docs/ or review [swagger.yaml](lib/server/swagger.yaml).

## Environment

Expand Down Expand Up @@ -525,7 +525,7 @@ To synchronize from Dexcom Share use the following variables.
Optional, `CONNECT_SHARE_REGION` and `CONNECT_SHARE_SERVER` do the same thing, only specify one.
* `CONNECT_SHARE_REGION=` `ous` or `us`. `us` is the default if nothing is
provided. Selecting `us` sets `CONNECT_SHARE_SERVER` to `share2.dexcom.com`.
Selecting `ous` here sets `CONNECT_SHARE_SERVER` to `shareous2.dexcom.com`.
Selecting `ous` here sets `CONNECT_SHARE_SERVER` to `shareous1.dexcom.com`.
* `CONNECT_SHARE_SERVER=` set the server domain to use.


Expand Down
2 changes: 1 addition & 1 deletion lib/api/activity/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function configure(app, wares, ctx) {
api.post('/activity/', ctx.authorization.isPermitted('api:activity:create'), post_response);

api.delete('/activity/:_id', ctx.authorization.isPermitted('api:activity:delete'), function(req, res) {
ctx.activity.remove(req.params._id, function() {
ctx.activity.deleteOne(req.params._id, function() {
res.json({});
});
});
Expand Down
2 changes: 1 addition & 1 deletion lib/api/food/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function configure (app, wares, ctx) {
});
// delete record
api.delete('/food/:_id', ctx.authorization.isPermitted('api:food:delete'), function(req, res) {
ctx.food.remove(req.params._id, function ( ) {
ctx.food.deleteOne(req.params._id, function ( ) {
res.json({ });
});
});
Expand Down
2 changes: 1 addition & 1 deletion lib/api/profile/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function configure (app, wares, ctx) {
});

api.delete('/profile/:_id', ctx.authorization.isPermitted('api:profile:delete'), function(req, res) {
ctx.profile.remove(req.params._id, function ( ) {
ctx.profile.deleteOne(req.params._id, function ( ) {
res.json({ });
});
});
Expand Down
4 changes: 2 additions & 2 deletions lib/api3/storage/mongoCollection/modify.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function updateOne (col, identifier, setFields) {
if (err) {
reject(err);
} else {
resolve({ updated: result.result.nModified });
resolve({ updated: result.modifiedCount });
}
});
});
Expand All @@ -91,7 +91,7 @@ function deleteOne (col, identifier) {
if (err) {
reject(err);
} else {
resolve({ deleted: result.result.n });
resolve({ deleted: result.deletedCount });
}
});
});
Expand Down
6 changes: 3 additions & 3 deletions lib/api3/storage/mongoCollection/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const _ = require('lodash')
, checkForHexRegExp = new RegExp("^[0-9a-fA-F]{24}$")
, ObjectID = require('mongodb').ObjectID
, ObjectID = require('mongodb-legacy').ObjectId
;


Expand Down Expand Up @@ -112,7 +112,7 @@ function filterForOne (identifier) {

// fallback to "identifier = _id"
if (checkForHexRegExp.test(identifier)) {
filterOpts.push({ _id: ObjectID(identifier) });
filterOpts.push({ _id: new ObjectID(identifier) });
}

return { $or: filterOpts };
Expand All @@ -137,7 +137,7 @@ function identifyingFilter (identifier, doc, dedupFallbackFields) {

// fallback to "identifier = _id" (APIv1)
if (checkForHexRegExp.test(identifier)) {
filterItems.push({ identifier: { $exists: false }, _id: ObjectID(identifier) });
filterItems.push({ identifier: { $exists: false }, _id: new ObjectID(identifier) });
}
}

Expand Down
21 changes: 15 additions & 6 deletions lib/authorization/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var _ = require('lodash');
var crypto = require('crypto');
var shiroTrie = require('shiro-trie');
var ObjectID = require('mongodb').ObjectID;
var ObjectID = require('mongodb-legacy').ObjectId;

var find_options = require('../server/query');

Expand All @@ -27,22 +27,22 @@ function init (env, ctx) {
if (!Object.prototype.hasOwnProperty.call(obj, 'created_at')) {
obj.created_at = (new Date()).toISOString();
}
collection.insert(obj, function (err, doc) {
collection.insertOne(obj, function (err, doc) {
if (err != null && err.message) {
console.log('Data insertion error', err.message);
fn(err.message, null);
return;
}
storage.reload(function loaded() {
fn(null, doc.ops);
fn(null, obj);
});
});
}
return doCreate;
}

function list (collection) {
function doList(opts, fn) {
function doList(opts, fn) {
// these functions, find, sort, and limit, are used to
// dynamically configure the request, based on the options we've
// been given
Expand All @@ -65,6 +65,8 @@ function init (env, ctx) {
fn(err, entries);
}

console.log('Loading',opts);

// now just stitch them all together
limit.call(collection
.find(query_for(opts))
Expand All @@ -77,7 +79,7 @@ function init (env, ctx) {

function remove (collection) {
function doRemove (_id, callback) {
collection.remove({ '_id': new ObjectID(_id) }, function (err) {
collection.deleteOne({ '_id': new ObjectID(_id) }, function (err) {
storage.reload(function loaded() {
callback(err, null);
});
Expand All @@ -92,7 +94,7 @@ function init (env, ctx) {
if (!obj.created_at) {
obj.created_at = (new Date()).toISOString();
}
collection.save(obj, function (err) {
collection.insertOne(obj, function (err) {
//id should be added for new docs
storage.reload(function loaded() {
callback(err, obj);
Expand Down Expand Up @@ -135,8 +137,14 @@ function init (env, ctx) {

storage.reload = function reload (callback) {

console.log('Reloading auth data');

storage.listRoles({sort: {name: 1}}, function listResults (err, results) {

console.log('Roles listed');

if (err) {
console.log('Problem listing roles', err);
return callback && callback(err);
}

Expand All @@ -152,6 +160,7 @@ function init (env, ctx) {

storage.listSubjects({sort: {name: 1}}, function listResults (err, results) {
if (err) {
console.log('Problem listing subjects', err);
return callback && callback(err);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ client.init = function init (callback) {
}).done(function success (serverSettings) {
if (serverSettings.runtimeState !== 'loaded') {
console.log('Server is still loading data');
$('#loadingMessageText').html('Server is starting and still loading data, retrying load in 5 seconds');
$('#loadingMessageText').html('Nightscout is still starting and should be available within about 15 seconds.');
window.setTimeout(window.Nightscout.client.init, 5000);
return;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/server/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var find_options = require('./query');


function storage (env, ctx) {
var ObjectID = require('mongodb').ObjectID;
var ObjectID = require('mongodb-legacy').ObjectId;

function create (obj, fn) {
obj.created_at = (new Date( )).toISOString( );
Expand Down Expand Up @@ -62,7 +62,7 @@ function storage (env, ctx) {

function remove (_id, fn) {
var objId = new ObjectID(_id);
return api( ).remove({ '_id': objId }, fn);
return api( ).deleteOne({ '_id': objId }, fn);
}

function api ( ) {
Expand Down
20 changes: 6 additions & 14 deletions lib/server/bootevent.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
'use strict';

const _ = require('lodash');
const UPDATE_THROTTLE = 5000;
const UPDATE_THROTTLE = 15000;

function boot (env, language) {

function startBoot(ctx, next) {

console.log('Executing startBoot');
console.log('++++++++++++++++++++++++++++++');
console.log('Nightscout Executing startBoot');
console.log('++++++++++++++++++++++++++++++');

ctx.bootErrors = [ ];
ctx.moment = require('moment-timezone');
Expand Down Expand Up @@ -38,7 +40,7 @@ function boot (env, language) {

const isLTS = process.release.lts ? true : false;

if (isLTS && (semver.satisfies(nodeVersion, '^20.0.0') || semver.satisfies(nodeVersion, '^18.0.0') || semver.satisfies(nodeVersion, '^16.0.0') || semver.satisfies(nodeVersion, '^14.0.0'))) {
if (isLTS || (semver.satisfies(nodeVersion, '^20.0.0') || semver.satisfies(nodeVersion, '^18.0.0') || semver.satisfies(nodeVersion, '^16.0.0') || semver.satisfies(nodeVersion, '^14.0.0'))) {
//Latest Node 14 LTS and Node 16 LTS are recommended and supported.
//Require at least Node 14 without known security issues
console.debug('Node LTS version ' + nodeVersion + ' is supported');
Expand Down Expand Up @@ -148,16 +150,6 @@ function boot (env, language) {
}

try {
if (_.startsWith(env.storageURI, 'openaps://')) {
require('../storage/openaps-storage')(env, function ready (err, store) {
if (err) {
throw err;
}
ctx.store = store;
console.log('OpenAPS Storage system ready');
next();
});
} else {
//TODO assume mongo for now, when there are more storage options add a lookup
require('../storage/mongo-storage')(env, function ready(err, store) {
// FIXME, error is always null, if there is an error, the index.js will throw an exception
Expand All @@ -170,7 +162,6 @@ function boot (env, language) {
ctx.store = store;
next();
});
}
} catch (err) {
console.info('ERROR CONNECTING TO MONGO', err);
ctx.bootErrors = ctx.bootErrors || [ ];
Expand Down Expand Up @@ -295,6 +286,7 @@ function boot (env, language) {

ctx.bus.on('data-received', function forceReloadData ( ) {
console.info('got data-received event, requesting reload');
ctx.bus.emit('data-loaded'); // Since we update local sandbox instantly, process data-loaded right away in case this gets debounced
updateData();
});

Expand Down
19 changes: 13 additions & 6 deletions lib/server/devicestatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ function storage (collection, ctx) {
obj.utcOffset = d.utcOffset();

api().insertOne(obj, function(err, results) {
if (err !== null && err.message) {

if (err) {
console.log('Error inserting the device status object', err.message);
errorOccurred = true;
fn(err.message, null);
return;
}

if (!err) {

if (!obj._id) obj._id = results.insertedIds[0]._id;
if (results) {
if (!obj._id) obj._id = results.insertedId;
r.push(obj);

ctx.bus.emit('data-update', {
Expand All @@ -47,6 +47,11 @@ function storage (collection, ctx) {
fn(null, r);
ctx.bus.emit('data-received');
}
} else {
console.log('Error inserting the device status object', err.message);
errorOccurred = true;
fn(err.message, null);
return;
}
});
};
Expand Down Expand Up @@ -100,17 +105,19 @@ function storage (collection, ctx) {

function removed (err, stat) {

console.log('removed', err, stat);

ctx.bus.emit('data-update', {
type: 'devicestatus'
, op: 'remove'
, count: stat.result.n
, count: stat.deletedCount
, changes: opts.find._id
});

fn(err, stat);
}

return api().remove(
return api().deleteMany(
query_for(opts), removed);
}

Expand Down
16 changes: 8 additions & 8 deletions lib/server/entries.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

var es = require('event-stream');
var find_options = require('./query');
var ObjectID = require('mongodb').ObjectID;
var ObjectId = require('mongodb-legacy').ObjectId;
var moment = require('moment');

/**********\
Expand Down Expand Up @@ -46,12 +46,12 @@ function storage (env, ctx) {
}

function remove (opts, fn) {
api().remove(query_for(opts), function(err, stat) {
api().deleteMany(query_for(opts), function(err, stat) {

ctx.bus.emit('data-update', {
type: 'entries'
, op: 'remove'
, count: stat.result.n
, count: stat.deletedCount
, changes: opts.find._id
});

Expand Down Expand Up @@ -110,12 +110,12 @@ function storage (env, ctx) {
if (doc.dateString) doc.dateString = doc.sysTime;

var query = (doc.sysTime && doc.type) ? { sysTime: doc.sysTime, type: doc.type } : doc;
api().update(query, doc, { upsert: true }, function(err, updateResults) {
api().replaceOne(query, doc, { upsert: true }, function(err, updateResults) {
firstErr = firstErr || err;

if (!err) {
if (updateResults.result.upserted) {
doc._id = updateResults.result.upserted[0]._id
if (updateResults) {
if (updateResults.upsertedCount == 1) {
doc._id = updateResults.upsertedId
}

ctx.bus.emit('data-update', {
Expand All @@ -135,7 +135,7 @@ function storage (env, ctx) {
}

function getEntry (id, fn) {
api().findOne({ _id: ObjectID(id) }, function(err, entry) {
api().findOne({ "_id": new ObjectId(id) }, function(err, entry) {
if (err) {
fn(err);
} else {
Expand Down
4 changes: 2 additions & 2 deletions lib/server/food.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

function storage (env, ctx) {
var ObjectID = require('mongodb').ObjectID;
var ObjectID = require('mongodb-legacy').ObjectId;

function create (obj, fn) {
obj.created_at = (new Date( )).toISOString( );
Expand Down Expand Up @@ -42,7 +42,7 @@ function storage (env, ctx) {

function remove (_id, fn) {
var objId = new ObjectID(_id);
return api( ).remove({ '_id': objId }, fn);
return api( ).deleteOne({ '_id': objId }, fn);
}


Expand Down
Loading