floCloudAPI v2.1.2

Added support for status feature
1. setStatus(options): set status as online for myFloID
2. requestStatus(trackList, options) : request status of floID(s) in trackList
- Both uses websocket connection
- resolves a reqID (local) that can be used in closeRequest function
- Use callback parameter in options to use the response from cloud

Added support for note feature
1. noteApplicationData(vectorClock, note): add/edit a note for a data in cloud
- Only allows receiverID of the data to add/edit note
- subAdmin can use it as exception, when receiverID is adminID

Other changes
- Fixed issues of tagApplicationData (previously markApplicationData) not working.
- Fixed issue where senderID option not working correctly in requesting data from cloud (new cloud uses 'senderID' parameter for both array of floIDs or a single floID)
*NOTE: change senderIDs to senderID in apps if any*
This commit is contained in:
sairajzero 2022-03-04 06:47:04 +05:30
parent f99a97e53e
commit 85baa8e6e1

View File

@ -7743,7 +7743,7 @@
} }
} }
</script> </script>
<script id="floCloudAPI" version="2.1.1"> <script id="floCloudAPI" version="2.1.2">
/* FLO Cloud operations to send/request application data*/ /* FLO Cloud operations to send/request application data*/
const floCloudAPI = { const floCloudAPI = {
@ -7987,37 +7987,55 @@
}, },
liveRequest: function(floID, request, callback) { liveRequest: function(floID, request, callback) {
const checkFilter = (v, d, r) => let self = this;
(!r.atVectorClock || r.atVectorClock == v) && const filterData = typeof request.status !== 'undefined' ?
(r.atVectorClock || !r.lowerVectorClock || r.lowerVectorClock <= v) && data => {
(r.atVectorClock || !r.upperVectorClock || r.upperVectorClock >= v) && if (request.status)
r.application == d.application && return data;
r.receiverID == d.receiverID && else {
(!r.comment || r.comment == d.comment) && let filtered = {};
(!r.type || r.type == d.type) && for (let i in data)
(!r.senderIDs || r.senderIDs.includes(d.senderID)); if (request.trackList.includes(i))
filtered[i] = data[i];
return filtered;
}
} :
data => {
data = self.objectifier(data);
let filtered = {},
r = request;
for (let v in data) {
let d = data[v];
if ((!r.atVectorClock || r.atVectorClock == v) &&
(r.atVectorClock || !r.lowerVectorClock || r.lowerVectorClock <= v) &&
(r.atVectorClock || !r.upperVectorClock || r.upperVectorClock >= v) &&
r.application == d.application &&
r.receiverID == d.receiverID &&
(!r.comment || r.comment == d.comment) &&
(!r.type || r.type == d.type) &&
(!r.senderID || r.senderID.includes(d.senderID)))
filtered[v] = data[v];
}
return filtered;
};
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.ws_activeConnect(floID).then(node => { self.ws_activeConnect(floID).then(node => {
let randID = floCrypto.randString(5); let randID = floCrypto.randString(5);
node.send(JSON.stringify(request)); node.send(JSON.stringify(request));
node.onmessage = (evt) => { node.onmessage = (evt) => {
let d = e = null; let d = e = null;
try { try {
let data = this.objectifier(JSON.parse(evt.data)), d = filterData(JSON.parse(evt.data));
filter = {};
for (let v in data)
if (checkFilter(v, data[v], request))
filter[v] = data[v];
d = filter;
} catch (error) { } catch (error) {
e = evt.data e = evt.data
} finally { } finally {
callback(d, e) callback(d, e)
} }
} }
this.liveRequest[randID] = node; self.liveRequest[randID] = node;
this.liveRequest[randID].request = request; self.liveRequest[randID].request = request;
resolve(randID) resolve(randID);
}).catch(error => reject(error)); }).catch(error => reject(error));
}); });
}, },
@ -8096,7 +8114,41 @@
} }
}, },
//send Any message to supernode cloud storage //set status as online for myFloID
setStatus: function(options = {}) {
return new Promise((resolve, reject) => {
let callback = options.callback instanceof Function ? options.callback : (d, e) => console.debug(d, e);
var request = {
floID: myFloID,
application: options.application || floGlobals.application,
time: Date.now(),
pubKey: myPubKey
}
let hashcontent = ["time", "application", "floID"].map(d => request[d]).join("|");
request.sign = floCrypto.signData(hashcontent, myPrivKey);
this.util.liveRequest(options.refID || floGlobals.adminID, callback)
.then(result => resolve(result))
.catch(error => reject(error))
})
},
//request status of floID(s) in trackList
requestStatus: function(trackList, options) {
return new Promise((resolve, reject) => {
if (!Array.isArray(trackList))
trackList = [trackList];
let callback = options.callback instanceof Function ? options.callback : (d, e) => console.debug(d, e);
let request = {
application: options.application || floGlobals.application,
trackList: trackList
}
this.util.liveRequest(options.refID || floGlobals.adminID, callback)
.then(result => resolve(result))
.catch(error => reject(error))
})
},
//send any message to supernode cloud storage
sendApplicationData: function(message, type, options = {}) { sendApplicationData: function(message, type, options = {}) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
var data = { var data = {
@ -8111,7 +8163,7 @@
} }
let hashcontent = ["receiverID", "time", "application", "type", "message", "comment"] let hashcontent = ["receiverID", "time", "application", "type", "message", "comment"]
.map(d => data[d]).join("|") .map(d => data[d]).join("|")
data.sign = floCrypto.signData(hashcontent, myPrivKey) data.sign = floCrypto.signData(hashcontent, myPrivKey);
this.util.singleRequest(data.receiverID, data) this.util.singleRequest(data.receiverID, data)
.then(result => resolve(result)) .then(result => resolve(result))
.catch(error => reject(error)) .catch(error => reject(error))
@ -8123,7 +8175,7 @@
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
var request = { var request = {
receiverID: options.receiverID || floGlobals.adminID, receiverID: options.receiverID || floGlobals.adminID,
senderIDs: options.senderIDs || undefined, senderID: options.senderID || undefined,
application: options.application || floGlobals.application, application: options.application || floGlobals.application,
type: type, type: type,
comment: options.comment || undefined, comment: options.comment || undefined,
@ -8217,45 +8269,47 @@
}) })
}, },
//mark data in supernode cloud (subAdmin access only) //tag data in supernode cloud (subAdmin access only)
markApplicationData: function(mark, options = {}) { tagApplicationData: function(vectorClock, tag, options = {}) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (!floGlobals.subAdmins.includes(myFloID)) if (!floGlobals.subAdmins.includes(myFloID))
return reject("Only subAdmins can mark data") return reject("Only subAdmins can tag data")
if (Array.isArray(mark)) var request = {
mark = Object.fromEntries(mark.map(vc => [vc, true]));
/*
if (typeof mark !== "object") {
if (!Array.isArray(mark)) mark = [mark];
let tmp = {}
mark.forEach(vc => tmp[vc] = true)
mark = tmp;
}*/
var markreq = {
receiverID: options.receiverID || floGlobals.adminID, receiverID: options.receiverID || floGlobals.adminID,
requestorID: myFloID, requestorID: myFloID,
pubKey: myPubKey, pubKey: myPubKey,
time: Date.now(), time: Date.now(),
mark: mark, vectorClock: vectorClock,
application: options.application || floGlobals.application tag: tag,
} }
let hashcontent = ["time", "application"] let hashcontent = ["time", "vectorClock", 'tag'].map(d => request[d]).join("|");
.map(d => markreq[d]).join("|") + JSON.stringify(markreq.mark) request.sign = floCrypto.signData(hashcontent, myPrivKey);
markreq.sign = floCrypto.signData(hashcontent, myPrivKey) this.util.singleRequest(request.receiverID, request)
this.util.singleRequest(markreq.receiverID, markreq).then(result => { .then(result => resolve(result))
let success = [], .catch(error => reject(error))
failed = [];
result.forEach(r => r.status === 'fulfilled' ?
success.push(r.value) : failed.push(r.reason));
resolve({
success,
failed
})
}).catch(error => reject(error))
}) })
}, },
//send General Data //note data in supernode cloud (receiver only or subAdmin allowed if receiver is adminID)
noteApplicationData: function(vectorClock, note, options = {}) {
return new Promise((resolve, reject) => {
var request = {
receiverID: options.receiverID || floGlobals.adminID,
requestorID: myFloID,
pubKey: myPubKey,
time: Date.now(),
vectorClock: vectorClock,
note: note,
}
let hashcontent = ["time", "vectorClock", 'note'].map(d => request[d]).join("|");
request.sign = floCrypto.signData(hashcontent, myPrivKey);
this.util.singleRequest(request.receiverID, request)
.then(result => resolve(result))
.catch(error => reject(error))
})
},
//send general data
sendGeneralData: function(message, type, options = {}) { sendGeneralData: function(message, type, options = {}) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
if (options.encrypt) { if (options.encrypt) {
@ -8272,7 +8326,7 @@
}) })
}, },
//request General Data //request general data
requestGeneralData: function(type, options = {}) { requestGeneralData: function(type, options = {}) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
var fk = this.util.filterKey(type, options) var fk = this.util.filterKey(type, options)
@ -8300,8 +8354,8 @@
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
options.lowerVectorClock = options.lowerVectorClock || floGlobals.lastVC[objectName] + options.lowerVectorClock = options.lowerVectorClock || floGlobals.lastVC[objectName] +
1; 1;
options.senderIDs = [false, null].includes(options.senderIDs) ? null : options.senderID = [false, null].includes(options.senderID) ? null :
options.senderIDs || floGlobals.subAdmins; options.senderID || floGlobals.subAdmins;
options.mostRecent = true; options.mostRecent = true;
options.comment = 'RESET'; options.comment = 'RESET';
let callback = null; let callback = null;
@ -9411,7 +9465,7 @@
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
var options = { var options = {
receiverID: myFloID, receiverID: myFloID,
senderIDs: myFloID, senderID: myFloID,
application: "floDapps", application: "floDapps",
mostRecent: true, mostRecent: true,
} }