Skip to content

Commit 257dfb2

Browse files
authored
Merge pull request #6445 from nightscout/dev
Release 14.0.7
2 parents 5f59c1d + e7d080a commit 257dfb2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+3442
-386
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ To learn more about the Nightscout API, visit https://YOUR-SITE.com/api-docs/ or
305305
* `SHOW_PLUGINS` - enabled plugins that should have their visualizations shown, defaults to all enabled
306306
* `SHOW_FORECAST` (`ar2`) - plugin forecasts that should be shown by default, supports space delimited values such as `"ar2 openaps"`
307307
* `LANGUAGE` (`en`) - language of Nightscout. If not available english is used
308-
* Currently supported language codes are: bg (Български), cs (Čeština), de (Deutsch), dk (Dansk), el (Ελληνικά), en (English), es (Español), fi (Suomi), fr (Français), he (עברית), hr (Hrvatski), it (Italiano), ko (한국어), nb (Norsk (Bokmål)), nl (Nederlands), pl (Polski), pt (Português (Brasil)), ro (Română), ru (Русский), sk (Slovenčina), sv (Svenska), tr (Turkish), zh_cn (中文(简体)), zh_tw (中文(繁體))
308+
* Currently supported language codes are: bg (Български), cs (Čeština), de (Deutsch), dk (Dansk), el (Ελληνικά), en (English), es (Español), fi (Suomi), fr (Français), he (עברית), hr (Hrvatski), hu (magyar), it (Italiano), ko (한국어), nb (Norsk (Bokmål)), nl (Nederlands), pl (Polski), pt (Português (Brasil)), ro (Română), ru (Русский), sk (Slovenčina), sv (Svenska), tr (Turkish), zh_cn (中文(简体)), zh_tw (中文(繁體))
309309
* `SCALE_Y` (`log`) - The type of scaling used for the Y axis of the charts system wide.
310310
* The default `log` (logarithmic) option will let you see more detail towards the lower range, while still showing the full CGM range.
311311
* The `linear` option has equidistant tick marks; the range used is dynamic so that space at the top of chart isn't wasted.

app.js

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,7 @@ function create (env, ctx) {
2929

3030
const enableCSP = env.secureCsp ? true : false;
3131

32-
console.info('Enabled SECURE_HSTS_HEADER (HTTP Strict Transport Security)');
33-
const helmet = require('helmet');
34-
var includeSubDomainsValue = env.secureHstsHeaderIncludeSubdomains;
35-
var preloadValue = env.secureHstsHeaderPreload;
36-
app.use(helmet({
37-
hsts: {
38-
maxAge: 31536000
39-
, includeSubDomains: includeSubDomainsValue
40-
, preload: preloadValue
41-
}
42-
, frameguard: false
43-
, contentSecurityPolicy: enableCSP
44-
}));
32+
let cspPolicy = false;
4533

4634
if (enableCSP) {
4735
var secureCspReportOnly = env.secureCspReportOnly;
@@ -60,7 +48,7 @@ function create (env, ctx) {
6048
}
6149
}
6250

63-
app.use(helmet.contentSecurityPolicy({ //TODO make NS work without 'unsafe-inline'
51+
cspPolicy = { //TODO make NS work without 'unsafe-inline'
6452
directives: {
6553
defaultSrc: ["'self'"]
6654
, styleSrc: ["'self'", 'https://fonts.googleapis.com/', 'https://fonts.gstatic.com/', "'unsafe-inline'"]
@@ -76,7 +64,26 @@ function create (env, ctx) {
7664
, frameAncestors: frameAncestors
7765
}
7866
, reportOnly: secureCspReportOnly
79-
}));
67+
};
68+
}
69+
70+
71+
console.info('Enabled SECURE_HSTS_HEADER (HTTP Strict Transport Security)');
72+
const helmet = require('helmet');
73+
var includeSubDomainsValue = env.secureHstsHeaderIncludeSubdomains;
74+
var preloadValue = env.secureHstsHeaderPreload;
75+
app.use(helmet({
76+
hsts: {
77+
maxAge: 31536000
78+
, includeSubDomains: includeSubDomainsValue
79+
, preload: preloadValue
80+
}
81+
, frameguard: false
82+
, contentSecurityPolicy: cspPolicy
83+
}));
84+
85+
if (enableCSP) {
86+
8087
app.use(helmet.referrerPolicy({ policy: 'no-referrer' }));
8188
app.use(bodyParser.json({ type: ['json', 'application/csp-report'] }));
8289
app.post('/report-violation', (req, res) => {
@@ -276,9 +283,12 @@ function create (env, ctx) {
276283
// API docs
277284

278285
const swaggerUi = require('swagger-ui-express');
286+
const swaggerUseSchema = schema => (...args) => swaggerUi.setup(schema)(...args);
279287
const swaggerDocument = require('./swagger.json');
288+
const swaggerDocumentApiV3 = require('./lib/api3/swagger.json');
280289

281-
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
290+
app.use('/api-docs', swaggerUi.serve, swaggerUseSchema(swaggerDocument));
291+
app.use('/api3-docs', swaggerUi.serve, swaggerUseSchema(swaggerDocumentApiV3));
282292

283293
app.use('/swagger-ui-dist', (req, res) => {
284294
res.redirect(307, '/api-docs');

docs/plugins/add-virtual-assistant-support-to-plugin.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ There are 2 types of handlers that you can supply:
3636

3737
A plugin can expose multiple intent handlers (e.g. useful when it can supply multiple kinds of metrics). Each intent handler should be structured as follows:
3838
+ `intent` - This is the intent this handler is built for. Right now, the templates used by both Alexa and Google Home use only the `"MetricNow"` intent (used for getting the present value of the requested metric)
39-
+ `metrics` - An array of metric name(s) the handler will supply. e.g. "What is my `metric`" - iob, bg, cob, etc. Make sure to add the metric name and its synonyms to the list of metrics used by the virtual assistant(s).
40-
- **IMPORTANT NOTE:** There is no protection against overlapping metric names, so PLEASE make sure your metric name is unique!
41-
- Note: Although this value *is* an array, you really should only supply one (unique) value, and then add aliases or synonyms to that value in the list of metrics for the virtual assistant. We keep this value as an array for backwards compatibility.
39+
+ `metrics` - An array of metric name(s) the handler will supply. e.g. "What is my `metric`" - iob, bg, cob, etc. Although this value *is* an array, you really should only supply one (unique) value, and then add aliases or synonyms to that value in the list of metrics for the virtual assistant. We keep this value as an array for backwards compatibility.
40+
- **IMPORTANT NOTE:** There is no protection against overlapping metric names, so PLEASE make sure your metric name is unique!
4241
+ `intenthandler` - This is a callback function that receives 3 arguments:
4342
- `callback` Call this at the end of your function. It requires 2 arguments:
4443
- `title` - Title of the handler. This is the value that will be displayed on the Alexa card (for devices with a screen). The Google Home response doesn't currently display a card, so it doesn't use this value.

docs/plugins/alexa-templates/en-us.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@
6868
{
6969
"name": "AMAZON.StopIntent",
7070
"samples": []
71+
},
72+
{
73+
"name": "AMAZON.CancelIntent",
74+
"samples": []
75+
},
76+
{
77+
"name": "AMAZON.HelpIntent",
78+
"samples": []
7179
}
7280
],
7381
"types": [
@@ -233,6 +241,16 @@
233241
"name": {
234242
"value": "cgm mode"
235243
}
244+
},
245+
{
246+
"name": {
247+
"value": "db size",
248+
"synonyms": [
249+
"database size",
250+
"data size",
251+
"file size"
252+
]
253+
}
236254
}
237255
]
238256
}
182 Bytes
Binary file not shown.

docs/plugins/googlehome-plugin.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ To add Google Home support for your Nightscout site, here's what you need to do:
4141
1. Click on the "New Project" button.
4242
1. If prompted, agree to the Terms of Service.
4343
1. Give your project a name (e.g. "Nightscout") and then click "Create project".
44-
1. For the "development experience", select "Conversational" at the bottom of the list.
44+
1. When asked what kind of Action you want to build, select "Custom" and then click the "Next" button.
45+
1. When selecting how you want to build the project, scroll down to the bottom of the screen and click the link to build it using DialogFlow.
4546
1. Click on the "Develop" tab at the top of the sreen.
4647
1. Click on "Invocation" in the left navigation pane.
4748
1. Set the display name (e.g. "Night Scout") of your Action and set your Google Assistant voice.

lib/api/alexa/index.js

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
var _ = require('lodash');
34
var moment = require('moment');
45

56
function configure (app, wares, ctx, env) {
@@ -18,7 +19,7 @@ function configure (app, wares, ctx, env) {
1819

1920
api.post('/alexa', ctx.authorization.isPermitted('api:*:read'), function (req, res, next) {
2021
console.log('Incoming request from Alexa');
21-
var locale = req.body.request.locale;
22+
var locale = _.get(req, 'body.request.locale');
2223
if(locale){
2324
if(locale.length > 2) {
2425
locale = locale.substr(0, 2);
@@ -78,19 +79,10 @@ function configure (app, wares, ctx, env) {
7879
function handleIntent(intentName, slots, next) {
7980
var metric;
8081
if (slots) {
81-
if (slots.metric
82-
&& slots.metric.resolutions
83-
&& slots.metric.resolutions.resolutionsPerAuthority
84-
&& slots.metric.resolutions.resolutionsPerAuthority.length
85-
&& slots.metric.resolutions.resolutionsPerAuthority[0].status
86-
&& slots.metric.resolutions.resolutionsPerAuthority[0].status.code
87-
&& slots.metric.resolutions.resolutionsPerAuthority[0].status.code == "ER_SUCCESS_MATCH"
88-
&& slots.metric.resolutions.resolutionsPerAuthority[0].values
89-
&& slots.metric.resolutions.resolutionsPerAuthority[0].values.length
90-
&& slots.metric.resolutions.resolutionsPerAuthority[0].values[0].value
91-
&& slots.metric.resolutions.resolutionsPerAuthority[0].values[0].value.name
92-
){
93-
metric = slots.metric.resolutions.resolutionsPerAuthority[0].values[0].value.name;
82+
var slotStatus = _.get(slots, 'metric.resolutions.resolutionsPerAuthority[0].status.code');
83+
var slotName = _.get(slots, 'metric.resolutions.resolutionsPerAuthority[0].values[0].value.name');
84+
if (slotStatus == "ER_SUCCESS_MATCH" && slotName) {
85+
metric = slotName;
9486
} else {
9587
next(translate('virtAsstUnknownIntentTitle'), translate('virtAsstUnknownIntentText'));
9688
return;

lib/api/googlehome/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict';
22

3+
var _ = require('lodash');
34
var moment = require('moment');
45

56
function configure (app, wares, ctx, env) {
@@ -18,7 +19,7 @@ function configure (app, wares, ctx, env) {
1819

1920
api.post('/googlehome', ctx.authorization.isPermitted('api:*:read'), function (req, res, next) {
2021
console.log('Incoming request from Google Home');
21-
var locale = req.body.queryResult.languageCode;
22+
var locale = _.get(req, 'body.queryResult.languageCode');
2223
if(locale){
2324
if(locale.length > 2) {
2425
locale = locale.substr(0, 2);

lib/api/status.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ function configure (app, wares, env, ctx) {
3232
, settings: settings
3333
, extendedSettings: extended
3434
, authorized: ctx.authorization.authorize(authToken)
35+
, runtimeState: ctx.runtimeState
3536
};
3637

3738
var badge = 'http://img.shields.io/badge/Nightscout-OK-green';

lib/api3/doc/tutorial.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Each NS instance with API v3 contains self-included OpenAPI specification at [/a
1111
---
1212
### VERSION
1313

14-
[VERSION](https://nsapiv3.herokuapp.com/api/v3/swagger-ui-dist/#/other/get_version) operation gets you basic information about software packages versions.
14+
[VERSION](https://nsapiv3.herokuapp.com/api3-docs/#/other/get_version) operation gets you basic information about software packages versions.
1515
It is public (there is no need to add authorization parameters/headers).
1616

1717
Sample GET `/version` client code (to get actual versions):
@@ -38,7 +38,7 @@ Sample result:
3838
---
3939
### STATUS
4040

41-
[STATUS](https://nsapiv3.herokuapp.com/api/v3/swagger-ui-dist/#/other/get_status) operation gets you basic information about software packages versions.
41+
[STATUS](https://nsapiv3.herokuapp.com/api3-docs/#/other/get_status) operation gets you basic information about software packages versions.
4242
It is public (there is no need to add authorization parameters/headers).
4343

4444
Sample GET `/status` client code (to get my actual permissions):
@@ -75,7 +75,7 @@ Sample result:
7575
---
7676
### SEARCH
7777

78-
[SEARCH](https://nsapiv3insecure.herokuapp.com/api/v3/swagger-ui-dist/index.html#/generic/SEARCH) operation filters, sorts, paginates and projects documents from the collection.
78+
[SEARCH](https://nsapiv3insecure.herokuapp.com/api3-docs/#/generic/SEARCH) operation filters, sorts, paginates and projects documents from the collection.
7979

8080
Sample GET `/entries` client code (to retrieve last 3 BG values):
8181
```javascript
@@ -110,7 +110,7 @@ Sample result:
110110
---
111111
### CREATE
112112

113-
[CREATE](https://nsapiv3.herokuapp.com/api/v3/swagger-ui-dist/#/generic/post__collection_) operation inserts a new document into the collection.
113+
[CREATE](https://nsapiv3.herokuapp.com/api3-docs/#/generic/post__collection_) operation inserts a new document into the collection.
114114

115115
Sample POST `/treatments` client code:
116116
```javascript
@@ -140,7 +140,7 @@ Sample result:
140140
---
141141
### READ
142142

143-
[READ](https://nsapiv3.herokuapp.com/api/v3/swagger-ui-dist/#/generic/get__collection___identifier_) operation retrieves you a single document from the collection by its identifier.
143+
[READ](https://nsapiv3.herokuapp.com/api3-docs/#/generic/get__collection___identifier_) operation retrieves you a single document from the collection by its identifier.
144144

145145
Sample GET `/treatments/{identifier}` client code:
146146
```javascript
@@ -172,7 +172,7 @@ Sample result:
172172
---
173173
### LAST MODIFIED
174174

175-
[LAST MODIFIED](https://nsapiv3insecure.herokuapp.com/api/v3/swagger-ui-dist/index.html#/other/LAST-MODIFIED) operation finds the date of last modification for each collection.
175+
[LAST MODIFIED](https://nsapiv3insecure.herokuapp.com/api3-docs/#/other/LAST-MODIFIED) operation finds the date of last modification for each collection.
176176

177177
Sample GET `/lastModified` client code (to get latest modification dates):
178178
```javascript
@@ -199,7 +199,7 @@ Sample result:
199199
---
200200
### UPDATE
201201

202-
[UPDATE](https://nsapiv3insecure.herokuapp.com/api/v3/swagger-ui-dist/index.html#/generic/put__collection___identifier_) operation updates existing document in the collection.
202+
[UPDATE](https://nsapiv3insecure.herokuapp.com/api3-docs/#/generic/put__collection___identifier_) operation updates existing document in the collection.
203203

204204
Sample PUT `/treatments/{identifier}` client code (to update `insulin` from 0.3 to 0.4):
205205
```javascript
@@ -231,7 +231,7 @@ Sample result:
231231
---
232232
### PATCH
233233

234-
[PATCH](https://nsapiv3insecure.herokuapp.com/api/v3/swagger-ui-dist/index.html#/generic/patch__collection___identifier_) operation partially updates existing document in the collection.
234+
[PATCH](https://nsapiv3insecure.herokuapp.com/api3-docs/#/generic/patch__collection___identifier_) operation partially updates existing document in the collection.
235235

236236
Sample PATCH `/treatments/{identifier}` client code (to update `insulin` from 0.4 to 0.5):
237237
```javascript
@@ -259,7 +259,7 @@ Sample result:
259259
---
260260
### DELETE
261261

262-
[DELETE](https://nsapiv3insecure.herokuapp.com/api/v3/swagger-ui-dist/index.html#/generic/delete__collection___identifier_) operation deletes existing document from the collection.
262+
[DELETE](https://nsapiv3insecure.herokuapp.com/api3-docs/#/generic/delete__collection___identifier_) operation deletes existing document from the collection.
263263

264264
Sample DELETE `/treatments/{identifier}` client code (to update `insulin` from 0.4 to 0.5):
265265
```javascript
@@ -282,7 +282,7 @@ Sample result:
282282
---
283283
### HISTORY
284284

285-
[HISTORY](https://nsapiv3insecure.herokuapp.com/api/v3/swagger-ui-dist/index.html#/generic/HISTORY2) operation queries all changes since the timestamp.
285+
[HISTORY](https://nsapiv3insecure.herokuapp.com/api3-docs/#/generic/HISTORY2) operation queries all changes since the timestamp.
286286

287287
Sample HISTORY `/treatments/history/{lastModified}` client code:
288288
```javascript
@@ -326,4 +326,4 @@ Sample result:
326326
}
327327
]
328328
```
329-
Notice the `"isValid":false` field marking the deletion of the document.
329+
Notice the `"isValid":false` field marking the deletion of the document.

0 commit comments

Comments
 (0)