Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
aor-realtime
Advanced tools
A custom saga enabling realtime update inside Admin-on-rest.
Install with:
npm install --save aor-realtime
or
yarn add aor-realtime
Define an observeRequest
function which will be called by the realtime saga whenever a CRUD_GET_LIST
or CRUD_GET_ONE
fetch
is triggered by Admin-on-rest (documentation about those).
This function will be called with the following parameters:
fetchType
: either CRUD_GET_LIST
or CRUD_GET_ONE
resource
: the resource's nameparams
: the fetch parameters
CRUD_GET_LIST
: { pagination: { page: {int} , perPage: {int} }, sort: { field: {string}, order: {string} }, filter: {Object} }
CRUD_GET_ONE
: { id: {mixed} }
This function must return an object with a subscribe
method which will be called with an observer
.
The observer
have the following methods:
next(data)
: Call this method each time new data is received so that the Admin-on-rest views are updated.complete()
: Call this method to indicates this subscription won't receive any new data.error(error)
: Call this method when an error occurs.The subscribe
method must return a subscription
object. The subscription
object must have an unsubscribe
method which will be called by the realtime saga when the query will not need to be observed anymore. This will happen each time the current route change and will give you the opportunity to clean up related sockets, apollo observable queries, etc. When called and after you cleaned up whatever needed cleaning, you must call the observer.complete
method so that the realtime saga is notified about it.
Here is a very naive example using an interval to fetch data every 5 seconds:
import realtimeSaga from 'aor-realtime';
const observeRequest = (fetchType, resource, params) => {
// Use your apollo client methods here or sockets or whatever else including the following very naive polling mechanism
return {
subscribe(observer) {
const intervalId = setInterval(() => {
fetchData(fetchType, resource, params)
.then(results => observer.next(results)) // New data received, notify the observer
.catch(error => observer.error(error)); // Ouch, an error occured, notify the observer
}, 5000);
const subscription = {
unsubscribe() {
// Clean up after ourselves
clearInterval(intervalId);
// Notify the saga that we cleaned up everything
observer.complete();
}
};
return subscription;
},
};
};
const customSaga = realtimeSaga(observeRequest);
For a more realistic usage example, please refer to the realtime saga provided by the aor-simple-graphql-client.
FAQs
A saga enabling realtime updates for Admin-on-rest
The npm package aor-realtime receives a total of 3 weekly downloads. As such, aor-realtime popularity was classified as not popular.
We found that aor-realtime demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.