Skip to content

Commit

Permalink
Merge pull request #22 from nightscout/dev
Browse files Browse the repository at this point in the history
new release
  • Loading branch information
bewest authored Oct 12, 2023
2 parents 3f9ed7a + 20ee2b1 commit 1e63c53
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 21 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ point.
* [x] fetch data
* [x] translate data (likely needs work)
* [x] LibreLinkUp (needs testing)
* [x] Medtronic
* [x] ~~Medtronic~~
* [x] hello world
* [x] glucose, stub devicestatus
* [ ] treatments, profiles, devicestatus
* [ ] Tidepool
* [ ] Tandem
* [ ] Diasend - obsolete
* [ ] ~~Diasend - obsolete~~

## Lower priority
* Better UI integration, diagnostics, test connection, fix errors, manage plugin...
Expand Down
2 changes: 1 addition & 1 deletion lib/sources/dexcomshare.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ function dexcomshareSource (opts, axios) {
dataFromSesssion(session, last_known) {
var two_days_ago = new Date( ).getTime( ) - (2 * 24 * 60 * 60 * 1000);
// var last_mills = Math.max(two_days_ago, last_known.sgvs ? last_known.sgvs.mills : two_days_ago);
var last_mills = Math.max(two_days_ago, last_known.entries ? last_known.entries.getTime( ) : two_days_ago);
var last_mills = Math.max(two_days_ago, (last_known && last_known.entries) ? last_known.entries.getTime( ) : two_days_ago);
var last_glucose_at = new Date(last_mills);
var maxCount = Math.ceil(((new Date( )).getTime( ) - last_mills) / (1000 * 60 * 5));
var minutes = 5 * maxCount;
Expand Down
2 changes: 1 addition & 1 deletion lib/sources/glooko/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function glookoSource (opts, axios) {
},
dataFromSesssion (session, last_known) {
var two_days_ago = new Date( ).getTime( ) - (2 * 24 * 60 * 60 * 1000);
var last_mills = Math.max(two_days_ago, last_known.entries ? last_known.entries.getTime( ) : two_days_ago);
var last_mills = Math.max(two_days_ago, (last_known && last_known.entries) ? last_known.entries.getTime( ) : two_days_ago);
var last_glucose_at = new Date(last_mills);
var maxCount = Math.ceil(((new Date( )).getTime( ) - last_mills) / (1000 * 60 * 5));
var minutes = 5 * maxCount;
Expand Down
2 changes: 1 addition & 1 deletion lib/sources/librelinkup.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function linkUpSource (opts, axios) {
},
dataFromSesssion (session, last_known) {
var two_days_ago = new Date( ).getTime( ) - (2 * 24 * 60 * 60 * 1000);
var last_mills = Math.max(two_days_ago, last_known.entries ? last_known.entries.getTime( ) : two_days_ago);
var last_mills = Math.max(two_days_ago, (last_known && last_known.entries) ? last_known.entries.getTime( ) : two_days_ago);
var last_glucose_at = new Date(last_mills);
var maxCount = Math.ceil(((new Date( )).getTime( ) - last_mills) / (1000 * 60 * 5));
var minutes = 5 * maxCount;
Expand Down
55 changes: 41 additions & 14 deletions lib/sources/minimedcarelink/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,23 @@ function carelinkSource (opts, axios) {
, password: opts.carelinkPassword
, actionButton: 'Log In'
};
var query = {
country: opts.countryCode
, locale: 'en'
, 'g-recaptcha-response': Buffer.from('YWJj', 'base64').toString( )
};
delete payload.endpoint;
var headers = {
'content-type': 'application/x-www-form-urlencoded'
, ...html_headers
...html_headers
, 'content-type': 'application/x-www-form-urlencoded'
};
var params = { };
console.log("SUBMITTING LOGIN", loginFlow.endpoint, payload, params, headers);
return http.post(loginFlow.endpoint, qs.stringify(payload), { params, headers }).then((resp) => {
var params = { ...query };
var loginEndpoint = loginFlow.endpoint;
// var loginEndpoint = url.parse(loginFlow.endpoint);
// query = { ...qs.parse(loginEndpoint.query), ...query };
// loginEndpoint = url.format({ ...loginEndpoint, search: null, query });
console.log("SUBMITTING LOGIN", loginEndpoint, payload, params, headers);
return http.post(loginEndpoint, qs.stringify(payload), { params, headers }).then((resp) => {
console.log("SUCCESS LOGGING IN", resp.headers, resp.data);
var regex = /(<form action=")(.*)" method="POST"/gm;
var endpoint = (regex.exec(resp.data) || [])[2] || '';
Expand Down Expand Up @@ -428,6 +437,7 @@ function carelinkSource (opts, axios) {
return resp.data;
}).catch((error) => {
console.log("ERROR FETCHING COUNTRY SETTINGS", error);
return Promise.reject(error);
});
}

Expand All @@ -441,6 +451,7 @@ function carelinkSource (opts, axios) {
return resp.data;
}).catch((error) => {
console.log("ERROR FETCHING M2M SETTINGS", error);
return Promise.reject(error);
});
}

Expand Down Expand Up @@ -468,8 +479,13 @@ function carelinkSource (opts, axios) {
}

function summarize ( ) {
return Promise.allSettled([getUser( ).then(getM2M).then(fetchPatientList), getProfile( ), getCountrySettings( ) ]).then((results) => {
var inputs = [getUser( ).then(getM2M).then(fetchPatientList), getProfile( ), getCountrySettings( ) ];
return Promise.allSettled(inputs).then((results) => {
console.log("FINAL", results);
var fulfilled = results.filter((result) => 'fulfilled' == result.status);
if (fulfilled.length < inputs.length) {
return Promise.reject(new Error("unable to fulfill session specifications"));
}
var isPatient = [ null, 'PATIENT', 'PATIENT_OUS', 'PATIENT_US' ].indexOf(account.user.role) > 0;
account.isPatient = isPatient;
if (isPatient) {
Expand Down Expand Up @@ -512,6 +528,7 @@ function carelinkSource (opts, axios) {
return resp.data;
}).catch((error) => {
console.log("ERROR DATA FETCH", error);
return Promise.reject(error);
});
}

Expand All @@ -536,6 +553,7 @@ function carelinkSource (opts, axios) {
return resp.data;
}).catch((error) => {
console.log("BLE PERIODIC ENDPOINT ERROR", error, error.response ? error.response.headers : "", error.response ? error.response.data : "");
return Promise.reject(error);
});
}

Expand All @@ -551,6 +569,7 @@ function carelinkSource (opts, axios) {
return resp.data;
}).catch((error) => {
console.log("MONITOR DATA ENDPOINT ERROR", error, error.response ? error.response.headers : "", error.response ? error.response.data : "");
return Promise.reject(error);
});
}

Expand All @@ -566,6 +585,7 @@ function carelinkSource (opts, axios) {
return resp.data;
}).catch((error) => {
console.log("RECENT UPLOADS ERROR", error, error.response ? error.response.headers : "", error.response ? error.response.data : "");
return Promise.reject(error);
});
}

Expand All @@ -580,20 +600,26 @@ function carelinkSource (opts, axios) {
function summarize (results) {
console.log("RESULTS", results);
// return result that has sgs
return results
var outputs = results
.filter(({status, value: payload }) => status == 'fulfilled' && payload && payload.sgs)
;
if (outputs.length < 1) {
return Promise.reject(new Error("unable to fulfill data for dataFromSesssion"));
}
return outputs
.map((fulfilled) => fulfilled.value)
.pop( )
;
}

return Promise.allSettled([
var inputs = [
getMonitorData( ).then(fetch_payload)
, getRecentUploads( )
]).then(summarize);
];
return Promise.allSettled(inputs).then(summarize);
},
refreshSession (authInfo, session) {
console.log("REFRESH REFRESH REFRESH");
console.log("REFRESH REFRESH REFRESH", authInfo, session);
var authed_headers = {
Authorization: `Bearer ${session.token}`
};
Expand Down Expand Up @@ -626,7 +652,8 @@ function carelinkSource (opts, axios) {
} else {
console.error(error);
}
return session;

return Promise.reject(error);
});
},
align_to_glucose (last_known) {
Expand Down Expand Up @@ -751,10 +778,10 @@ function carelinkSource (opts, axios) {
authorize: impl.sessionFromAuth,
// TODO: have never seen refreshSession work, disabling until further
// notice
refresh: impl.refreshSession,
// refresh: impl.refreshSession,
delays: {
REFRESH_AFTER_SESSSION_DELAY: (1000 * 60 * 12),
EXPIRE_SESSION_DELAY: 1000 * 60 * 13,
REFRESH_AFTER_SESSSION_DELAY: (1000 * 60 * 7),
EXPIRE_SESSION_DELAY: 1000 * 60 * 9,
}
});

Expand Down
2 changes: 1 addition & 1 deletion lib/sources/nightscout.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function nightscoutSource (opts, axios) {
dataFromSesssion(session, last_known) {
var two_days_ago = new Date( ).getTime( ) - (2 * 24 * 60 * 60 * 1000);
// var last_mills = Math.max(two_days_ago, last_known.sgvs ? last_known.sgvs.mills : two_days_ago);
var last_mills = Math.max(two_days_ago, last_known.entries ? last_known.entries.getTime( ) : two_days_ago);
var last_mills = Math.max(two_days_ago, (last_known && last_known.entries) ? last_known.entries.getTime( ) : two_days_ago);
var last_glucose_at = new Date(last_mills);
var count = Math.ceil(((new Date( )).getTime( ) - last_mills) / (1000 * 60 * 5));
var query = { find: { dateString: { $gt: last_glucose_at.toISOString( ) } }, count };
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nightscout-connect",
"version": "0.0.11",
"version": "0.0.12",
"description": "Connect common cloud platforms to Nightscout.",
"main": "index.js",
"directories": {
Expand Down

0 comments on commit 1e63c53

Please sign in to comment.