npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bw-js-sdk

v0.0.11

Published

The BrightWork platform provides a complete backend solution for your apps. Our goal is to increase developer productivity and reduce the time it takes for you to build a complete application. Our Javascript SDK accelerates the time it takes to integrate

Downloads

2

Readme

Getting Started

The BrightWork platform provides a complete backend solution for your apps. Our goal is to increase developer productivity and reduce the time it takes for you to build a complete application.

Our Javascript SDK accelerates the time it takes to integrate your backend API with your Javascript application.

Adding the SDK to your app

Static

[https://cdn.jsdelivr.net/bw-js-sdk/0.0.7/index.js](https://cdn.jsdelivr.net/bw-js-sdk/0.0.7/index.js)

Bower

    bower install --save bw-js-sdk

Connecting to your API

Setting you your app to connect to your backend BrightWork API is quick and easy.

    BrightWork.initialize('YOUR_API_KEY', 'YOUR_APP_NAME').then(function() {
        // BrightWork is now attached to window.bw
        // so you can query your data or do anything else you need now

        // like fetch all albums
        bw.models.album.find().then(function(albums) {
            console.log(album);
        });
    );

All of your models and services are available now via bw.models.MODELNAME and bw.services.SERVICE_NAME respectively.

Examples

Let's assume we are working off the default BW generated manifest for a photo album. This manifest contains two models, album & photo.

Create a new album

    bw.models.album.create({ name: "My Photo Album"}).then(function(newAlbum) {
        console.log('A new album was created.');
        console.log(newAlbum);
    });

Get an album from the server

    bw.models.album.get(1).then(function(existingAlbum) {
        console.log('Album with id: 1 is...');
        console.log(newAlbum);
    });

Update an existing album

Assumes that you have have fetched an existing ablum using get and saved to existingAlbum variable.

    bw.models.album.save(existingAlbum).then(function(savedAlbum) {
        console.log('Album saved...');
        console.log(savedAlbum);
    });

Delete an existing album

    bw.models.album.delete(1).then(function() {
        console.log('Album 1 has been deleted');
    });

Search for an album

    var query = BrightWork.Query().equalTo('name', 'My Photo Album');

    console.log('searching for all albums named "My Photo Album"...');
    bw.models.album.find(query).then(function(albums) {
        console.log('...results', albums);
    });

Advanced Query

For this example let's assume you have an e-commerce system with Order and LineItem models. You need to find all line items where the amount is above $50 and the item is in a "pending" or "paid" status. You want the results sorted first in decending order by date and then sorted in ascending order by line number.

    var query = BrightWork.Query()
        .greaterThan('amount', 50)
        .oneOf('status', ['pending', 'paid'])
        .descending('order_date')
        .ascending('line_number');

    bw.models.lineitem.find(query).then(function(items) {
        console.log('items found...', items);
    });

Running the Demo

There is a demo photo app in the ./demo folder. Follow the steps below to get it running and play around.

  1. Deploy your BrightWork demo app backend API Follow the steps in Getting Started to setup and deploy the sample API. Get your API key by running the bw list command once you have successfuly deployed.

  2. Configure and run the demo web app

    • Setup your API credentials (edit ./demo/public/js/main.js)
        console.log('initializing SDK...');
        BrightWork.initialize('YOUR-API-KEY', 'YOUR-APP-NAME').then(function(){
            console.log('...SDK initialized');
            bw.models.album.find().then(function(albums) {
                $("#albumContent").append(renderTable({albums: albums}));
            });
        });
    • Install dependencies and start the server
        cd ./demo
        npm install && bower install
        grunt server