Commit Graph
52 Commits
Author SHA1 Message Date
ba7694055f Fix Server error (#7784)
* check if d1 is not nil before call getTime

Co-authored-by: Sulka Haro <sulka@sulka.net>
2023-01-01 13:05:17 +02:00
Ben West 41fdb8e88f respect per route body-parser configuration
This change allows each route to express policies for interpreting and parsing
the request body.  Before this change uploads to entries or treatments api
would error if they were larger than 100Kb due to the preference being set for
the whole server.  This change removes the global preference in favor of
allowing each route to choose it's own request size limit.

We also refactor usage of body-parser to be more consistent throughout the code
base.  Most routes can use jsonParser, rawPraser, and urlencodedParser provided
by the common wares component.  Anything doing something else should be called
out as such.  For example, treatments, activity, and entries allow uploads up
to 50Mb.  Other v1 endpoints are using the common configuration set to 1Mb.
2021-10-12 22:57:03 -07:00
Sulka Haro ebb58141cd Fix json decoding for some api endpoints 2021-02-09 12:52:23 +02:00
Sulka HaroandGitHub 914ba78f36 Security improvement batch (#6622)
* Adds a new method for the server to push notifies to the client, which require administration privileges from the user. If there are messages in queue but user is not privileged, she is notified of pending messages

* Fix unit tests

* Increase timeouts on tests

* Add translations

* * Aggregate admin messages
* Send admin message on auth fail
* Sending messages over bus
* XSS filtering of objects sent over the REST API

* Warn users if their instance is world readable

* Fix adminnotifies init()

* Fix couple issues from Codacy
2021-01-07 22:46:55 +02:00
Sulka Haro 54008a7122 Remove excess logging 2020-09-22 11:14:13 +03:00
Sulka Haro 1059232f16 * Add cache update events to websocket API
* Remove the validation for created_at in REST API ;(
2020-09-21 20:46:53 +03:00
Sulka Haro 0c7e9bf456 * Require created_at for Treatments on insert
* Refactoring the cache: moved to another file and support flushing from bus events
2020-09-19 18:17:20 +03:00
Sulka Haro a0043ec206 Bump treatments default limit default to 1000 objects for queries that include other query parameters 2020-09-16 16:10:44 +03:00
Sulka HaroandGitHub 801900597a Optimize Nightscout database usage (#5947)
* On periodic polls, only load delta for CGM data, treatments and device statuses
* Serve basic CGM data API queries from in-memory cache. Increases the Nightscout memory footprint but should significantly reduce the Mongo load
* Serve device status, CGM and treatment records from memory cache
* Support count parameter in /profile
2020-09-09 20:11:57 +03:00
JakobandSulka Haro 3a1d9be89d Fix eslint errors and add npm script for eslint (#5427)
* re-enable auth check for device status routes

* Resolve eslint errors

* Add npm script for eslint

* Correct regex for express extension middleware and add tests for expected behaviour

* Resolve lint error in virtual assistant base

* Update index.js

* Update index.js
2020-01-14 15:33:56 +00:00
JakobandSulka Haro 7dc292e056 Resolve unnecessary uses of eslint-ignore (#5436)
* Resolve unnecessary disabling of no-undef eslint rule

* Resolve unnecessary disabling of no-prototype-builtins eslint rule

* Resolve unnecessary disabling of no-unused-vars eslint rule

* Resolve unnecessary disabling of no-empty eslint rule
2020-01-12 20:13:29 +00:00
Sulka HaroandGitHub 35c7dc42ce * Allow users to set DE_NORMALIZE_DATES=false to have the REST API denormalize UTC dates to zoned ISO dates in the API (#4826) 2019-07-29 17:21:05 +03:00
Jeremy Cunningham ada17c8597 Remove old treatments id api path 2018-12-07 17:39:11 -06:00
Jeremy Cunningham 69b73dfc5e Make treatments delete match devicestatus 2018-12-07 17:39:11 -06:00
Jeremy Cunningham b429eef662 Return status to treatments delete by query 2018-12-07 17:39:11 -06:00
Jeremy Cunningham 759dd40dec Add clean treatments admin tool. 2018-12-07 17:39:11 -06:00
PieterGitandSulka Haro 71103bb4b7 resolve npm audit security fixes (#3721)
* upgrade mocha from 3.5.3 to 5.0.5

This resolves these security issues

  Low             Regular Expression Denial of Service
  Package         debug
  Dependency of   mocha [dev]
  Path            mocha > debug
  More info       https://nodesecurity.io/advisories/534

  Critical        Command Injection
  Package         growl
  Dependency of   mocha [dev]
  Path            mocha > growl
  More info       https://nodesecurity.io/advisories/146

* upgrade mocha and start modularizing lodash to make sure tests pass

* more lodash modularization

* upgrade mqtt to 2.18.3

* allow npm 6.2

* upgrade share2nightscout-bridge

* incorporate express-extension-to-accept into Nightscout

the packages seems not maintained (github page is 404) and has a security issue with mime package.  so upgraded and included into Nightscout code.

if somebody knows a more efficient way of programming this with express4 please PR

* update jsdom for security fixes

* prevent wrapping of hour labels by removing the space

* Revert "update jsdom for security fixes"

This reverts commit 04f1f39d636d8d79c6b01b5f298f9a6cea3dc645.

* Revert "more lodash modularization"

This reverts commit c4fa5304db9f16b94f15c2b44793a5a11d595885.

* remove forever dependency

* Revert "Revert "more lodash modularization""

This reverts commit b13c274ebff0b5c3a48ffc0e610ca85a9f8d25bc.

* fix report.test.js with newer packages

sometimes a fix is very easy. This is to prevent:

```
Deprecation warning: value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are discouraged and will be removed in an upcoming major release. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.
Arguments:
[0] _isAMomentObject: true, _isUTC: true, _useUTC: true, _l: undefined, _i: T00:00:00, _f: undefined, _strict: undefined, _locale: [object Object]
Error
    at Function.createFromInputFallback (XXX\cgm-remote-monitor\tmp\js\bundle.js:117408:98)
    at configFromString (XXX\cgm-remote-monitor\tmp\js\bundle.js:119456:15)
```

We must use ISO8601 formatted strings and not use slashes in dates, see https://github.com/moment/moment/issues/1407#issuecomment-155630060

* upgrade webpack to 4.16.2

* Update package.json
2018-07-24 20:25:44 +03:00
Sulka Haro c16ad7b989 Check both created_at and timestamp fields for treatments in if-modified-since logic 2017-10-25 23:48:49 +03:00
Sulka Haro f6f55496d3 Fix a bug with time comparison on if-modified-since support for treatments 2017-10-25 23:16:49 +03:00
Sulka Haro 91f8635fd1 Merge branch 'dev' into wip/if-modified-since
Conflicts:
	lib/api/treatments/index.js
	package.json
2017-07-14 23:15:41 +03:00
Pete Schwamb 722d82b445 Track objects created in upsert, so we can generate response with ids for clients 2017-06-27 14:45:24 -05:00
Sulka Haro 5cf195d125 Removing the validation due to client fragmentation in terms of how this works 2017-01-04 22:38:58 +02:00
Sulka Haro 6018df9c26 Fixing tests 2017-01-02 00:12:28 +02:00
Sulka Haro 44863f9806 One more null check 2017-01-01 22:51:35 +02:00
Sulka Haro e963f28b44 Add null check to treatment loads that don't find anything 2017-01-01 22:48:47 +02:00
Sulka Haro 2afa166a93 Oops, already using upsets to dedupe further down the line 2017-01-01 20:01:46 +02:00
Sulka Haro 14fa83c017 Dedupe treatments against in-memory objects on upload 2017-01-01 18:08:05 +02:00
Sulka Haro 012ba198d1 If-Modified-Since header support for the /entries and /treatments API 2017-01-01 16:34:58 +02:00
Sulka Haro d41ab2c558 Fix API for broken insulin data; treatments data processing when IOB is missing but expected 2016-08-22 22:37:40 +03:00
Ben West e39ab7ad17 isolate effects of middleware from other routers
Using all(...) in this manner allows middleware from router A to
not affect router B.

As a result, sendJSONStatus and ability to optionally end in
.json disappeared, which this patch also restores.

CC: @jasoncalabrese
With this change, I can successfully restrict reads to entries
vs status vs other things without the middleware leakage we
observed earlier.
2016-08-08 13:45:31 -07:00
Jason Calabrese 8b86bfa293 deprecate TREATMENTS_AUTH; for backwards compat setting TREATMENTS_AUTH=off will cause the careportal role to be added to AUTH_DEFAULT_ROLES 2016-08-06 02:42:57 -07:00
Ben West 0f735d0af5 implement read-access against token, mod default
Could see an endpoint changing the global server variable, `defaultRoles` as well.
Seems to work well to disable/enable access really quickly.
2016-08-04 15:40:02 -07:00
Jason Calabrese 3d88bd33a6 replace old wares.verifyAuthorization with ctx.authorization.isPermitted; some refactoring 2016-07-31 20:10:10 -07:00
Jason Calabrese a695a1dd58 upsert treatments based on created_at and eventType
also dedupe and process data within a posted array
more treatment api tests
2016-01-06 00:48:27 -08:00
Ben West cc24cf05e3 squashing 10 commits getting it wrong
* try again
* try with compression
* fix export
* try 1MB limit
* try with different version of body-parser
* try limits again
* try setting limit AGAIN
* keep trying
* try harder-er
* try alternate verisno

None of these attempts appeared fruitful, but hard to tell if they were
required or not.
2015-10-23 16:16:55 -07:00
Ben West 811104d277 increase upload limit 2015-10-23 14:04:18 -07:00
MilosKozak 8728f0bba6 treatments edit/save needed changes, XMLHttp -> $.ajax 2015-08-31 23:20:51 +02:00
MilosKozak 57fe7dc9c3 TREATMENT_AUTH handling, added authentication status to careportal 2015-08-31 15:13:58 +02:00
MilosKozak 2fdb03bece codacy pass 3 2015-08-30 09:37:50 +02:00
MilosKozak 91469499c3 codacy pass 2 2015-08-30 09:37:50 +02:00
MilosKozak 257cb4a58f extracted needed files 2015-08-30 09:37:41 +02:00
Milos Kozak ccd4abba11 fix passing params on treatment api 2015-08-11 23:14:48 +02:00
Jason Calabrese fd585720b8 fix lots of little issues reported by codacy 2015-06-30 23:34:59 -07:00
Jason Calabrese 4dfa2c438c ctx everywhere; fixed security.test.js 2015-06-04 23:20:18 -07:00
Jason Calabrese 2dcc8d4d78 removed settings; fixed profiles/profile mixups; fix current/id queries 2015-05-25 23:19:06 -07:00
Ben West 95746ab5be allow API to search things better
This allows a query such as this to search for events of hypoglycemia for
example:
curl -g localhost:3434 \
     /api/v1/entries   \
     '?find[sgv][$lte]=70&find[sgv][$gte]=20&count=1000

It's possible to construct most mongo queries by url encoding the query string.
In this instance, mongo performs poorly when searching for lte/gte for strings.
In order for ranged queries to perform properly, the query parameters must be
set to integer type.  There is a quick and ugly helper to ensure that some sgv
queries will be respected as integer searches.
2015-03-19 13:22:27 -07:00
Jason Calabrese 24bdc2822d only return the most recent treatment data via websockets; added opts to treatments.list() 2014-11-30 11:24:59 -08:00
Jason Calabrese 9df56fdc6b require careportal to be enabled 2014-09-07 11:01:46 -07:00
Jason Calabrese 0404905e53 Revert "Revert to c1b2988eb0 (Merge branch 'hotfix/0.3.5')"
This reverts commit 1cc9c6127c.
2014-08-31 00:04:11 -07:00
Jason Calabrese 1cc9c6127c Revert to c1b2988eb0 (Merge branch 'hotfix/0.3.5') 2014-08-24 22:22:55 -07:00