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:
parent
f99a97e53e
commit
85baa8e6e1
@ -7743,7 +7743,7 @@
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<script id="floCloudAPI" version="2.1.1">
|
||||
<script id="floCloudAPI" version="2.1.2">
|
||||
/* FLO Cloud operations to send/request application data*/
|
||||
const floCloudAPI = {
|
||||
|
||||
@ -7987,37 +7987,55 @@
|
||||
},
|
||||
|
||||
liveRequest: function(floID, request, callback) {
|
||||
const checkFilter = (v, d, r) =>
|
||||
(!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.senderIDs || r.senderIDs.includes(d.senderID));
|
||||
let self = this;
|
||||
const filterData = typeof request.status !== 'undefined' ?
|
||||
data => {
|
||||
if (request.status)
|
||||
return data;
|
||||
else {
|
||||
let filtered = {};
|
||||
for (let i in data)
|
||||
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) => {
|
||||
this.ws_activeConnect(floID).then(node => {
|
||||
self.ws_activeConnect(floID).then(node => {
|
||||
let randID = floCrypto.randString(5);
|
||||
node.send(JSON.stringify(request));
|
||||
node.onmessage = (evt) => {
|
||||
let d = e = null;
|
||||
try {
|
||||
let data = this.objectifier(JSON.parse(evt.data)),
|
||||
filter = {};
|
||||
for (let v in data)
|
||||
if (checkFilter(v, data[v], request))
|
||||
filter[v] = data[v];
|
||||
d = filter;
|
||||
d = filterData(JSON.parse(evt.data));
|
||||
} catch (error) {
|
||||
e = evt.data
|
||||
} finally {
|
||||
callback(d, e)
|
||||
}
|
||||
}
|
||||
this.liveRequest[randID] = node;
|
||||
this.liveRequest[randID].request = request;
|
||||
resolve(randID)
|
||||
self.liveRequest[randID] = node;
|
||||
self.liveRequest[randID].request = request;
|
||||
resolve(randID);
|
||||
}).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 = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
var data = {
|
||||
@ -8111,7 +8163,7 @@
|
||||
}
|
||||
let hashcontent = ["receiverID", "time", "application", "type", "message", "comment"]
|
||||
.map(d => data[d]).join("|")
|
||||
data.sign = floCrypto.signData(hashcontent, myPrivKey)
|
||||
data.sign = floCrypto.signData(hashcontent, myPrivKey);
|
||||
this.util.singleRequest(data.receiverID, data)
|
||||
.then(result => resolve(result))
|
||||
.catch(error => reject(error))
|
||||
@ -8123,7 +8175,7 @@
|
||||
return new Promise((resolve, reject) => {
|
||||
var request = {
|
||||
receiverID: options.receiverID || floGlobals.adminID,
|
||||
senderIDs: options.senderIDs || undefined,
|
||||
senderID: options.senderID || undefined,
|
||||
application: options.application || floGlobals.application,
|
||||
type: type,
|
||||
comment: options.comment || undefined,
|
||||
@ -8217,45 +8269,47 @@
|
||||
})
|
||||
},
|
||||
|
||||
//mark data in supernode cloud (subAdmin access only)
|
||||
markApplicationData: function(mark, options = {}) {
|
||||
//tag data in supernode cloud (subAdmin access only)
|
||||
tagApplicationData: function(vectorClock, tag, options = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!floGlobals.subAdmins.includes(myFloID))
|
||||
return reject("Only subAdmins can mark data")
|
||||
if (Array.isArray(mark))
|
||||
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 = {
|
||||
return reject("Only subAdmins can tag data")
|
||||
var request = {
|
||||
receiverID: options.receiverID || floGlobals.adminID,
|
||||
requestorID: myFloID,
|
||||
pubKey: myPubKey,
|
||||
time: Date.now(),
|
||||
mark: mark,
|
||||
application: options.application || floGlobals.application
|
||||
vectorClock: vectorClock,
|
||||
tag: tag,
|
||||
}
|
||||
let hashcontent = ["time", "application"]
|
||||
.map(d => markreq[d]).join("|") + JSON.stringify(markreq.mark)
|
||||
markreq.sign = floCrypto.signData(hashcontent, myPrivKey)
|
||||
this.util.singleRequest(markreq.receiverID, markreq).then(result => {
|
||||
let success = [],
|
||||
failed = [];
|
||||
result.forEach(r => r.status === 'fulfilled' ?
|
||||
success.push(r.value) : failed.push(r.reason));
|
||||
resolve({
|
||||
success,
|
||||
failed
|
||||
})
|
||||
}).catch(error => reject(error))
|
||||
let hashcontent = ["time", "vectorClock", 'tag'].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
|
||||
//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 = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (options.encrypt) {
|
||||
@ -8272,7 +8326,7 @@
|
||||
})
|
||||
},
|
||||
|
||||
//request General Data
|
||||
//request general data
|
||||
requestGeneralData: function(type, options = {}) {
|
||||
return new Promise((resolve, reject) => {
|
||||
var fk = this.util.filterKey(type, options)
|
||||
@ -8300,8 +8354,8 @@
|
||||
return new Promise((resolve, reject) => {
|
||||
options.lowerVectorClock = options.lowerVectorClock || floGlobals.lastVC[objectName] +
|
||||
1;
|
||||
options.senderIDs = [false, null].includes(options.senderIDs) ? null :
|
||||
options.senderIDs || floGlobals.subAdmins;
|
||||
options.senderID = [false, null].includes(options.senderID) ? null :
|
||||
options.senderID || floGlobals.subAdmins;
|
||||
options.mostRecent = true;
|
||||
options.comment = 'RESET';
|
||||
let callback = null;
|
||||
@ -9411,7 +9465,7 @@
|
||||
return new Promise((resolve, reject) => {
|
||||
var options = {
|
||||
receiverID: myFloID,
|
||||
senderIDs: myFloID,
|
||||
senderID: myFloID,
|
||||
application: "floDapps",
|
||||
mostRecent: true,
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user