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

fieldbook-promise

v1.0.1

Published

Promise wrapper for Fieldbook API

Downloads

2

Readme

An unofficial npm module to use the Fieldbook API using native javascript promises.

Useful links

  1. Jake Archibald's guide to native JS promises
  2. Fieldbook API Reference (BETA)
  3. node-fieldbook - unofficial JS library using callbacks

Installation

npm install fieldbook-promise

Documentation

The module exports an object with the following objects. They all return native JS promises.

module

The module exports a function, which given a valid configuration for a Fieldbook book, will return a book object with methods to read and write to the book.

The configuration parameter is an object which must have the following three properties (otherwise an Error will be thrown:

  • book (string): the id of the book (it is the last part of the "API URL")
  • user (string): the username field (e.g. key-1)
  • password (string): the API key password

All the information can be found by navigating to your book's page, pressing the downward arrow/triangle next to the name of the book, and clicking "Manage API" (see picture).

Example:

var Fieldbook = require('fieldbook-promise');
var book = Fieldbook({
	book: '{bookid}',
	user: '{username}',
	password: '{password}'
});

The returned book object (note just a regular object, not a class TODO) exposes the following methods:

Note: The methods all return promises and correspond directly with the Fieldbook REST API which is currently at v1.

getSheets()
  • returns Promise
  • fulfilled with: array

Fulfills with the array of sheets associated with the book.

getSheet(sheetId)
  • returns Promise
  • fulfilled with: array

Fulfills with the array of records (object) for the sheet. Sheet IDs are lowercase, stripped of original punctuation, spaces replaced by underscores. More detail in Fieldbook's API Docs.

getRecord(sheetId, recordId)
  • returns Promise
  • fulfilled with: object

Fulfills with the retrieved record object from the given sheet. Properties of the object correspond with the column headers (NOTE: the initial column is given the default name {sheet_name}_name_or_identifier).

addRecord(sheetId)
  • returns Promise
  • fulfilled with: object

Fulfills with the added record object.

updateRecord(sheetId, recordId, data)
  • returns Promise
  • fulfilled with: object

Fulfills with the updated record object after patching it with data.

deleteRecord(sheetId, recordId)
  • returns Promise
  • fulfilled with: object

Fulfills with an empty object.

Errors

Errors are forwarded from Fieldbook's REST API. Additional errors (such as for invalid or missing configuration object) have messages defined in constants.js in the project root directory, under the errors property.

See the Fieldbook documentation for further discussion on HTTP errors.

Testing

Testing uses the tape testing framework, and exist in the tests directory.

It currently uses a test book whose API keys are stored in config.js in the root project folder, which is not included as part of the repo.

Set-Up

  1. Create a new book using Fieldbook
  2. Store the book, user and password in config
  3. Create a new sheet called Fixed
  4. Create a new sheet called Sheet 1
  5. Put the following columns/record:

Fixed

Columns:

  • Fixed name or identifier
  • Field1 (number)
  • Date (date)
  • Field 3 (text)

Records:

1 row

  • Fixed name or identifier:Fixed 1 (should be default)
  • Field1:1
  • Date:2/10/2015
  • Field 3:Test string

Sheet1

Columns:

  • Sheet1 name or identifier
  • Number
  • Date
  • Text

Records:

empty (no rows)