
Security News
Node.js Homepage Adds Paid Support Link, Prompting Contributor Pushback
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
pusher-feeds-server
Advanced tools
This is a server side Node.js library for [Feeds](https://pusher.com/feeds) service. See the full documentation [here](http://docs.pusher.com/feeds/)
This is a server side Node.js library for Feeds service. See the full documentation here
Please note that the reference is annotated with a statically typed dialect like Flow
Add as a dependency using Yarn or npm.
yarn add pusher-feeds-server
Then import the Feeds
constructor.
// The default export is a Feeds class.
import Feeds from 'pusher-feeds-server';
// The default export is a Feeds class.
var Feeds = require('pusher-feeds-server');
Constructor Feeds
takes a single options object with the following properties:
instanceLocator
:string [required] your instance locator; get this
from your dashboard
key
:string [required] your key; get this from your
dashboard
const feeds = new Feeds({
instanceLocator: your_instance_locator,
key: your_key,
});
Publish an item to a feed, and broadcast the item to all subscribers.
feeds.publish(feedId: string, item: any): Promise<any>
feedId
: The feed ID to publish to. If you publish to a feed that does not
exist, it is lazily created.item
: Arbitrary JSON representing the item data.Promise with Node.js http.request IncomingMessage
.
feeds
.publish(feed_id, {message: 'Hello World!'})
.then(() => console.log('Succesfully published!'))
.catch((err) => console.log(err));
feeds.publishBatch(feedId: string, items: Array<any>): Promise<any>
feedId
: The feed ID to publish to. If you publish to a feed that does not
exist, it is lazily created.items
: An array of the data of each item. Items are published into the feed
in order from the start of the array.Promise with Node.js http.request IncomingMessage
.
feeds
.publishBatch(feed_id, [{message: 'Hello A!'}, {message: 'Hello B!'}])
.then(() => console.log('Succesfully published!'))
.catch((err) => console.log(err));
Query a feed for pages of previously published items. Items are returned in descending order of item ID.
feeds.paginate(feedId: string, options: ?PaginateOptions)
feedId
: The feed ID to fetch items from.options
: An object with the following keys
cursor: ?number
: the ID of the first item in the page – if not provided,
retrieves the most recently published itemslimit: ?number
: the number of items to retrieve, defaults to 50Promise of type Promise<PaginateResponse>
where PaginateResponse
is
items: [Item];
next_cursor: ?string;
and Item
is
id: string;
created: number;
data: any;
Get a page containing the last 25 items of the feed "my-feed"
.
feeds.paginate("my-feed", { limit: 25 }).then(({ items }) => {
// Do something with each of the items
items.forEach(...);
});
feeds.delete(feedId: string): Promise<any>
feedId
: The feed ID to delete items in.Promise with Node.js http.request IncomingMessage
.
feeds.delete('newsfeed')
.then(() => console.log('Succesfully deleted!'))
.catch((err) => console.log(err));
This method allows you to authorize your clients for access to a certain feed. Please see auth process diagram and example how to implement this method with collaboration with one of our client side libraries.
feeds.authorizeFeed(
payload: AuthorizePayload,
hasPermissionCallback: (action: ActionType, feedId: string) => Promise<bool> | bool
): Promise<Object>
payload
param is essentially POST request payload (or body) object of type
AuthorizePayload
(You can use
body-parser to parse the POST
request body for you). The object must have the following format: (Please note
that if you using one of our client libraries they will handle this format for
you)type AuthorizePayload = {
path: string;
action: string;
grant_type: string;
};
hasPermissionCallback
parameter allows you to grant or deny permission to
access a feed based on any information you have in scope (e.g. session data).
It should either return a bool
, or a promise
of one. See the
auth-docs
for more details.A Promise
with an authResponse
object with the properties listed below which
can then be used for client authorization.
{
access_token: token,
token_type: token_type,
expires_in: token_expiry,
refresh_token: refresh_token
}
Using Express.js
and body-parser
:
// .... Init express js server
// Register auth endpoint
app.post('/feeds/tokens', (req, res) => {
// Define hasPermission to be used in authorizeFeed function
const hasPermission = (action, feedId) => (
db.find(req.session.userId)
.then(userId => userId === 'abcd')
);
// Authorize user with request payload and hasPermission callback.
feeds.authorizeFeed(req, hasPermission)
.then(data => res.send(data))
.catch(err => {
res.status(400).send(`${err.name}: ${err.message}`)
});
});
considering that we have the Express.js
http server running on http://localhost:5000
then we can test the auth endpoint with curl
:
curl -X POST \
-d "action"="READ" \
-d "path"="feeds/private-my-feed-name/items" \
-d "grant_type"="client_credentials" \
http://localhost:5000/feeds/tokens
Since all the public methods on Feeds
class returns Promise
you should
always call .catch()
on it to handle Error
properly. pusher-feeds-server
library is using some custom Errors which extends standart JS Error
object.
You can import them to your project if would like to use them.
import Feeds, {
UnsupportedGrantTypeError,
InvalidGrantTypeError,
ClientError
} from 'pusher-feeds-server';
var Feeds = require('pusher-feeds-server');
var UnsupportedGrantTypeError = Feeds.UnsupportedGrantTypeError;
var InvalidGrantTypeError = Feeds.InvalidGrantTypeError;
var ClientError = Feeds.ClientError;
FAQs
This is a server side Node.js library for [Feeds](https://pusher.com/feeds) service. See the full documentation [here](http://docs.pusher.com/feeds/)
The npm package pusher-feeds-server receives a total of 14 weekly downloads. As such, pusher-feeds-server popularity was classified as not popular.
We found that pusher-feeds-server demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.
Research
Security News
The Socket Research Team investigates a malicious Python typosquat of a popular password library that forces Windows shutdowns when input is incorrect.