/**
* @exports Session
* Represents a users session.
*/
exports.Session = {
/**
* @enum {string}
*/
EventName : {
ON_RECORD_SUBMIT: "validicOnRecordSubmitted",
ON_RECORD_SUBMIT_FAIL: "validicOnRecordSubmitFailed"
},
/**
* Starts a session with a User's credentials.
* @param {string} userId - Id of the user.
* @param {string} orgId - Organization Id.
* @param {string} accessToken - Security Access Token.
* @param {Callback} success - Callback. No parameters passed.
* @param {FailCallback} fail - Callback if parameters are invalid types or are missing. This function does
* NOT verify that the credentials are valid.
*/
startSession : function(userId, orgId, accessToken, success, fail) {
cordova.exec(success, fail, "ValidicMobileSession", "startSession", [userId, orgId, accessToken]);
},
/**
* Ends a user's session
* @param {Callback} success - Callback function indicating method invoked.
*/
endSession : function(success) {
cordova.exec(success, null, "ValidicMobileSession", "endSession", []);
},
/**
* Registers listeners for record upload success and failure callbacks. It is recommended to use event listeners instead.
* @param {EventCallback} success - Function invoked for each record successfully uploaded to the server. The uploaded
* record is included in the payload.
* @param {EventCallback} fail - Callback invoked for each record which experiences a non-recoverable upload error.
*/
setSessionListener : function(success, fail) {
var successful = function(obj) {
if (success != null && success != 'undefined') {
success(obj);
}
if (obj.hasOwnProperty("event")) {
cordova.fireWindowEvent(obj.event, obj.payload);
}
};
var error = function(obj) {
if (fail != null && fail != 'undefined') {
fail(obj);
}
if (obj.hasOwnProperty("event")) {
cordova.fireWindowEvent(obj.event, obj.payload);
}
};
cordova.exec(successful, error, "ValidicMobileSession", "setSessionListener", []);
},
/**
* Submits a record to the validic backend
* @param {Record} record - Record to upload.
* @param {string} [img] - Base64 encoded image associated with a record.
* @param {Callback} successValidate - Invoked on successful submission (not upload).
* @param {FailCallback} errorValidate - Invoked on invalid record or other record submission issues.
*/
submitRecord : function(record, img, successValidate, errorValidate) {
cordova.exec(successValidate, errorValidate, "ValidicMobileSession", "submitRecord", [record, img]);
},
/**
* Submits an array of records to the Validic backend
* @param {Record[]} records - Array of records to be submitted.
* @param {Callback} successValidate - Callback acknowledging record submission.
* @param {FailCallback} errorValidate - Invoked on submission error. Invalid parameters, etc.
*/
submitRecords : function(records, successValidate, errorValidate) {
cordova.exec(successValidate, errorValidate, "ValidicMobileSession", "submitRecords", [records]);
},
/**
* Indicates there is an active Session with a user
* @param {IsActiveCallback} success - Callback function indicating whether an active session is available
*/
isSessionActive : function(success) {
cordova.exec(success, null, "ValidicMobileSession", "isSessionActive", []);
},
/**
* returns a string representation of the sdk version. 1.3 currently.
* @param {VersionCallback} success - Callback passed the version number of the native library the plugin is
* interacting with.
*/
getVersion: function(success) {
cordova.exec(success, null, "ValidicMobileSession", "getVersion", []);
},
/**
* Records returned from read operations include a record type value. Records submitted to the session
* requires the record type property to be set to one of these values.
* @enum {string}
*/
RecordTypeString : {
BIOMETRICS: "biometrics",
DIABETES: "diabetes",
WEIGHT: "weight",
ROUTINE: "routine",
NUTRITION: "nutrition",
FITNESS: "fitness",
SLEEP: "sleep"
},
/**
* For use with HealthKit.getSampleTypesForRecordType
* @enum {number}
*/
RecordType : {
NONE: 0,
BIOMETRICS: 1,
DIABETES: 2,
WEIGHT: 3,
ROUTINE: 4,
NUTRITION: 5,
FITNESS: 6,
SLEEP: 7
},
/**
* @enum {number}
*/
PeripheralType : {
NONE: 0,
THERMOMETER: 1,
BLOOD_PRESSURE: 2,
HEART_RATE: 3,
GLUCOSE: 4,
WEIGHT_SCALE: 5,
PULSE_OXIMETER: 6
}
}
exports.Logger = {
enable : function(){
cordova.exec(null,null,"ValidicMobileSession", "enableLog");
},
disable: function(){
cordova.exec(null,null,"ValidicMobileSession", "disableLog");
}
}