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

reshuffle-airtable-connector

v0.0.3

Published

A Reshuffle Airtable connector

Downloads

3

Readme

reshuffle-airtable-connector

Code | npm | Code sample

npm install reshuffle-airtable-connector

Reshuffle Airtable Connector

This package contains a Reshuffle connector to connect Airtable APIs.

The following example exposes an endpoint to return the first page of Airtable tab 'Design projects' with view 'All projects'. After running the example go to http://localhost:8000/projects to view the results.

const { HttpConnector, Reshuffle } = require('reshuffle')
const { AirtableConnector } = require('reshuffle-airtable-connector')

const app = new Reshuffle()

const airtableConnector = new AirtableConnector(app, {
  endpointUrl: 'AIRPOINT_ENDPOINT_URL', // 'https://api.airtable.com'
  apiKey: 'YOUR_API_KEY',
  base: 'YOUR_BASE'
})

const httpConnector = new HttpConnector(app)
const base = airtableConnector.base()

httpConnector.on({ method: 'GET', path: '/projects' }, async (event, app) => {
  base('Design projects').select({
    view: 'All projects'
  }).firstPage(function(err, records) {
    if (err) {
      event.res.json(err)
      return
    }
    event.res.json(records.map(record => record.get('Name')))
  })
})

app.start()

The official Airtable JavaScript library can be found [here]](https://github.com/Airtable/airtable.js)

Table of Contents

Configuration Options

Connector Events

Listening to Airtable events

Connector Actions

Base - Retrieve a base Airtable object

SDK - Retrieve a full Airtable sdk object

Configuration options

const app = new Reshuffle()
const airtableConnector = new AirtableConnector(app, {
  endpointUrl: 'AIRPOINT_ENDPOINT_URL',
  apiKey: 'YOUR_API_KEY',
  base: 'YOUR_BASE'
})

endpointUrlis optional, the default is https://api.airtable.com.

Get your apiKey by following the steps in this article.

More details about the APIs are described in Airtable API documentation.

Events

Listening to Airtable events

In order to listen to events happening in Airtable, you'll need to capture them with the connector's on function, providing an AirtableConnectorEventOptions to it.

Events are specific to an Airtable table/tab, for example in order to define all three events (added, modified, deleted) on two tables you have to define six events.

interface AirtableConnectorEventOptions {
  type: AirtableEventType // See bellow 
  table: string           // Airtable table/tab name
  fireWhileTyping?: boolean // How to manage `RecordModified` events for text fields, check the explanation below. The default value is false.
}

// Where...
type AirtableEventType =
  | 'RecordAdded'
  | 'RecordModified'
  | 'RecordDeleted'

* 'RecordAdded' - For a Grid View, when adding a new record there is no 'Create New' button that opens a dialog that enables populating and saving the record's fields. Instead Airtable stores the new record at the time you click the create the new record, at this stage all the record's fields are empty. Due to that, a 'RecordAdded' event for a Grid View will end up having an empty record.

** fireWhileTyping - Airtable persists every keystroke as the user is typing text. This may result in several 'RecordModified' events firing for a single field change. When fireWhileTyping is false (the default value) the connector will fire an event only when the user stops typing. When fireWhileTyping is true there will be number of events, similar to the way that Airtable persisted the change.

Example:

airtableConnector.on({ type: 'RecordModified', table: 'Design projects' }, async (event, app) => {
  console.log('RecordModified on Design projects table event')
  console.log(event.id)
  console.log(event.fields)
})

Actions

base

Returns a base object providing an access to the Airtable APIs. Usually you will use base in order to execute all the Airtable APIs.

const base = airtableConnector.base()

Example:

const base = airtableConnector.base()

base('Design projects').select({
    view: 'All projects'
  }).firstPage(function(err, records) {
    if (err) {
      event.res.json(err)
      return
    }
    event.res.json(records.map(record => record.get('Name')))
  })

sdk

Usually base will be the main access to the Airtable APIs but if you need the SDK it is available by using this action.

const sdk = airtableConnector.sdk()

Example:

const base = airtableConnector.sdk().base('YOUR_BASE')

base('Design projects').select({
    view: 'All projects'
  }).firstPage(function(err, records) {
    if (err) {
      event.res.json(err)
      return
    }
    event.res.json(records.map(record => record.get('Name')))
  })