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

brandibble

v1.13.7

Published

API Wrapper for Brandibble.co

Downloads

61

Readme

Brandibble.JS

npm CircleCI Status Open Source Love

An API wrapper for communicating with the Brandibble API in the browser. Currently not compatible with Node.JS environments (but could easily, we'd just need two build targets, and an isomorphic fetch library).

Usage

import Brandibble from 'brandibble';
import localforage from 'localforage'; // or another storage library

// Build a global Brandibble Ref
localforage.config({name: 'sanctu', storeName: 'compu'});
let BrandibbleRef = new Brandibble({
  apiKey: '12345',
  brandId: 23,
  storage: localforage,
});

// You'll need to set it up like so:
BrandibbleRef.setup().then(() => {
  // ... do stuff
});
// Create A Customer
let password = 'password';

Brandibble.customers.create({
  first_name: 'Sanctuary',
  last_name: 'Computer',
  email: '[email protected]',
  password
}).then(response => {
  // Authenticate that new customer
  return BrandibbleRef.customers.authenticate({ response.email, password });
});

// Now your client will be authenticated (that state is persisted over
// page refreshes in localStorage), which you can check like so:

let isAuthenticated = !!BrandibbleRef.adapter.customerToken;

// Now you can fetch the current user
Brandibble.customers.current().then(currentCustomer => {
  console.log(`Welcome to Brandibble ${currentCustomer.first_name}!`);
})

Detailed Usage

Every method returns a promise (unless otherwise noted).

A note on statefulness:

Brandibble.JS provides a slew of both stateful (dependent on the adapter's state), and stateless (simple, 'dumb' methods). It's totally up to the developer how to use these - but generally the stateful methods are simply composed of a few stateless methods.


Adapter

Used for serializing and deserializing JSON, and making requests. The adapter is also responsible for restoring data from LocalStorage (or Cookies, for Safari Private Browsing). Check the object for more info (lib/adapter.js).


Customers

Stateful Methods

  • Brandibble.customers.authenticate({ email, password })
  • Brandibble.customers.invalidate()
  • Brandibble.customers.current()
  • Brandibble.customers.updateCurrent({ email, password, first_name, last_name, phone })

Stateless Methods

  • Brandibble.customers.create({ email, password, first_name, last_name, phone })
  • Brandibble.customers.resetPassword({ email })
  • Brandibble.customers.token({ email, password })
    • Not necessary with authenticate.
  • Brandibble.customers.show(customerId)
    • Not necessary with current.
  • Brandibble.customers.update({ email, password, first_name, last_name, phone }, customerId)
    • Not necessary with updateCurrent.

Addresses

All Address Methods are dependent on the authenticated customer (stateful).

Stateful Methods

  • Brandibble.addresses.all()

  • Brandibble.addresses.create(AddressObject)

    Your address object should look something like this:

    let AddressObject = {
      street_address: '110 Bowery',
      unit: '4 FL',
      city: 'New York',
      state_code: 'NY',
      zip_code: 10013,
      latitude: 40.755912,
      longitude: -73.9709333,
      company: 'Sanctuary Computer, Inc.',
      contact_name: 'Hugh Francis',
      contact_phone: '5512213610'
    }

Locations
  • Brandibble.locations.index()

    TODO: Menus

Orders
// Assemble an Order first!

BrandibbleRef.orders.create(location, 'pickup');
let newOrder = BrandibbleRef.orders.current();

let lineItem = newOrder.addLineItem(product, 1);

newOrder.isValid(); // false
lineItem.isValid(); // false
lineItem.errors(); // error details, formatted as an array

let bases = lineItem.optionGroups()[0];

// Configure Line Item
lineItem.addOption(bases, bases.option_items[2]);
lineItem.removeOption(bases, bases.option_items[2]);
lineItem.addOption(bases, bases.option_items[1]);

lineItem.setLineItemQuantity(lineItem, 7);

lineItem.isValid() // true
newOrder.isValid() // true

BrandibbleRef.orders.validate(newOrder);

// Now Setup The order for Submission, assu

newOrder.setCustomer(customer);
newOrder.setAddress(address);
newOrder.setCard(card);
BrandibbleRef.orders.submit(newOrder);

There are only three methods that you can do on an Order:

  • Brandibble.orders.validateCart(BrandibbleOrderModel)
  • Brandibble.orders.validate(BrandibbleOrderModel)
  • Brandibble.orders.submit(BrandibbleOrderModel)

Testing

  • IMPORTANT: Set an environment variable called BRANDIBBLE_API_KEY with your Brandibble API key before running tests.
  • npm test