How to pull new data from API using node / electron desktop application? - javascript

I'm creating a private desktop application for my Shopify store and was wondering what the best way to continuously pull new order data down from their API? While the application is open do I query the API for new orders at a set interval? Is there a way to use webhooks with a desktop application (not a server)? Any suggestions would be appreciated!

You definitely need a server to receive webhooks, but if you don't want to manage a server, you can use a serverless solution such as Amazon EventBridge.
For example, you can do something like the following:
EventBridge receives your order data through the Shopify webhook.
The order data is added to an SQS queue.
Your desktop app connects to the SQS queue to receive the order data.
Here is a tutorial from Shopify that explains this approach:
https://shopify.dev/tutorials/manage-webhook-events-with-eventbridge

Related

Getting data from ERP in mobile APP how to do it properly?

I’m building an app and I need to communicate with the ERP that uses webservices and is most of the time reliable.
My backend is a Graphql api I’m wondering how should I get the data from ERP?
The options I’m considering:
Fetch the data from ERP on every request from the app and save it to my separate DB.
Create a cron job and copy the data every X time to separate DB.
Create a microservices server and update the data in the queue on every request.
Or is there another solution I’m not seeing?
The problem is that the ERP web services are not as reliable as my separate DB.
Right now I have the 3 packages the backend the server that gets the data from EPR and react native client.

How to handle offline messages in React-Native using NodeJS and SocketIO

I am currently using SocketIO and NodeJS to handle messages. However the problem is that when the user becomes offline there's no way that the other user will receive the message.
The solution I came up with was to store the message in the database.
But a new problem arise, when fetching the message and push notification.
If I do fetch for "n" minutes in the server when the app is in background/inactive. There will be a lot of request in the server, and I personally think that it is inefficient. and also it drains the battery.
What is the proper way how to handle fetching the messages from database or pushing notification in app without making too much request in "n" minutes and draining too much power?
You need to save the last sync time in the App. And whenever app comes from background/Inactive state. You need to call an API with this time. This API will give you all the messages and the Push notification which has comes after the last sync time. In this way, With one API call, you will be able to get all the messages and push notifications. I had used this approach to syncing my data in one of my app.
My suggestion is to implement a system of background jobs in the API, checking when there is a new notification to be launched, or with the notification already ready waiting to be launched in the queue. You can search for queue manager like Bull, Bee-Queue.
To launch push notification in the closed/inactive app, you can use a service like OneSignal or Firebase.
I implemented this a few weeks ago and did it this way.
API = Node.js, Bull Queue
App = React Native, OneSignal
Going back to this question if somebody stumbled upon this question.
The best way to handle offline messages regardless if you are using NodeJS/MongoDB, etc. is to store it on server's database. Then call an API that fetches the the messages which is equal to user's ID whenever the mobile app comes to foreground.
If your problem is that you needed notification and you are using
react-native-push-notifications / react-native-push-notification-ios
Then you should use the data notification to include the message on notification parameter on the server's side(Assuming that you are using Firebase Cloud Messaging). With this way you can directly save the message on the mobile's database.

Push new data from Node REST API to React-Native

Problem
I've created a REST API using Node and a client app using React-Native.
So far I've configured it so the client app makes HTTP requests to the server.
Now I need to push new data from the server to the client as soon as it is available. I need to push different data to the client app depending on which user is logged in.
I haven't done this before and I've been having trouble finding a good solution online, partially because I don't know the correct terminology.
The server will pull the data from an external API, save it to MongoDB via Mongoose. I then need to push the new data to the client
If anyone has any suggestions that would be great!
Environment
Node.js with Express v4.16.4
React-Native v0.58.0-rc.2
Mongoose v5.4.5
Firebase is already installed in the react-native app. I'm proficient with both Mongoose and Firebase so either one could be good for the push queue if applicable.
Thanks!
1. can use socket.io
Server send data to client using Web socket(socket.io).
2. can use firebase push notification.
Server can create new notification to firebase, and client can received signal from firebase, and get data from server via REST api.

How to send Dynamodb query results to browser encrypted?

I have a tiny table (100 records) that I keep in my Dynamodb backend. My web app will scan table at the beginning of the session. And then users will query this data with different parameters. My intention is not to go my backend for each query and do it on client side(front end) for better performance.
But because I don't want anyone to see my tiny table's data I would like to encrypt it while sending and decrypt it on browser side after arrival. I'm using Nodejs, dynamodb and API gateways as backend (AWS serverless architecture).
I'm a newbie and was wondering if it is possible and what the best practices are.
I'll give an example to describe my concern better. Imagine skyscanner keeps all airline-flight-ticketprice data in one table. they will have 2 options to let everbody to search publicly. First they can let users to query the table everytime they search (which will be slow). Second they can scan the table's data and send it to browser and users can search flights much faste on front end (with arrays etc..). I want to implement the 2nd approach but I also want to keep my data encrypted so nobody can copy my data and create a very similar website :)
Thanks.
Using Cognito Identity Pools
You can achieve this with authentication using AWS Cognito Identity Pool(Granting who can access which DynamoDB Table and even which Partition key) and using AWS JavaScript SDK which uses SSL to encrypt the communication between the browser and DynamoDB.
Note: You can also use AWS Cognito UserPools if you don't have a user store which can be connected to Cognito Identity Pool.
Using API Gateway and Lambda endpoint for Temporary Access Credentials
If you already have an existing authentication mechanism you can use a API Gateway and Lambda endpoint where the Lambda function will have the code to assume an IAM Role and send the temporary access credentials to the browser. Then in the browser you can use AWS SDK for JavaScript to access DynamoDB.
Here's a demo app that does specifically what you're looking for...once logged in, the user has access to his own "row" in dynamoDB...
https://github.com/awslabs/aws-cognito-angular-quickstart
Here's what you get by running the install script (it creates all of the resources for you):
http://cognito.budilov.com

Looking for an azure service to manage web push notifications

I'm implementing a notifications feature in an html5 web app I'm working on.
The feature requirements is to receive push notifications (strings) from the server and display them immediately on the user interface (to all clients), without saving them anywhere else.
I'm looking for a managed service on Azure cloud that allows send/onMessage functionalities very similar to WebSockets, that can be accessed directly by the browser.
I've tried using event-hubs, but that solution requires a node.js/SignalR wrapper which I can't use for this specific feature.
Thanks in advance!
It sounds like you want to implement a real-time notification feature for HTML5 App without any middleware like WebApp in Node/SignalR to connect a message queue like EventHubs. However, there seems to be not any solution for the needs without any backend services as HTTP middleware for browser if using EventHubs or other services like PubSub in Redis.
Per my experience, a only available solution is that using pouchdb within browser to synchronize with CouchDb on Azure to implement a PubSub service as notification service.
There is a opensource project on GitHub which you can refer to, please move to https://github.com/MattCollins84/couch-pubsub.
Hope it helps. Any concern, please feel free to let me know.
Chrome M52 and beyond started supporting the VAPID protocol, refer to https://chromestatus.com/feature/5573539073622016.
It seems that Azure does not yet provide VAPID support. As an alternative you can look into Firebase Cloud Messaging (FCM) which you can connect with Azure Notification Hub.
More on Firebase Cloud Messaging and web push html client: https://firebase.google.com/docs/cloud-messaging/js/client
More on Azure Notification Hub and connecting it with FCM:
https://learn.microsoft.com/en-us/azure/notification-hubs/notification-hubs-android-push-notification-google-fcm-get-started
VAPID stands for: Voluntary Application server Identification for web Push. Refer to https://datatracker.ietf.org/doc/html/rfc8292

Categories

Resources