Socket
Socket
Sign inDemoInstall

airtable-dnd

Package Overview
Dependencies
23
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    airtable-dnd

Unofficial Airtable Client for Node.js ported from `airtable-deno` 🦕


Version published
Maintainers
1
Created

Readme

Source

airtable-dnd

release



Install

Install airtable-dnd using npm or yarn

# install using npm
npm install airtable-dnd

# install using yarn
yarn add airtable-dnd

⚠ Important note: airtable-dnd internally uses fetch and assumes it exists ⚠

If you're on an environment that already has fetch (Next.js runtimes, browsers, etc.), airtable-dnd will use that.

If you're on an environment that does not have fetch, refer to the "Polyfilling fetch" section on how to implement or bring your own fetch.

Comparison

airtable-dnd vs. Deno version

  • Accepts custom fetch on instantiation options (see "Polyfilling fetch")
  • Instance options are exposed unlike airtable-deno where it's using private identifiers (#options)

airtable-dnd vs. first-party Node.js version

  • Does not ship with fetch implementation (see "Polyfilling fetch")
  • First-class support for generic field types with extra field types (Collaborators, MultipleSelect<T>, etc.)
  • Single object instance (new Airtable() instead of new Airtable().base()().select()...)

Basic examples

Instantiate Airtable client

import { Airtable } from "airtable-dnd";

const airtable = new Airtable({
  apiKey: "keyXXXXXXXXXXXXXX",
  baseId: "appXXXXXXXXXXXXXX",
  tableName: "Some table name",
});

Select record(s)

const results = await airtable.select();

Creating record(s)

const createOne = await airtable.create({
  Name: "Griko Nibras",
  Age: 25,
});

import { Field } from "airtable-dnd";

type Fields = {
  Name: string;
  Age: number;
  Active?: Field.Checkbox;
};

const createMultiple = await airtable.create<Fields>(
  [
    { Name: "Foo", Age: 20 },
    { Name: "Bar", Age: 15 },
  ],
  { typecast: true },
);

Updating record(s)

const updateOne = await airtable.update<Fields>("recXXXXXXXXXXXXXX", {
  Name: "Adult boi",
  Age: 30,
});

const updateMultiple = await airtable.update<Fields>(
  [
    {
      id: "recXXXXXXXXXXXXXX",
      fields: { Name: "Adult boi", Age: 30 },
    },
    {
      id: "recXXXXXXXXXXXXXX",
      fields: { Name: "Yung boi", Age: 15 },
    },
  ],
  { typecast: true },
);

Delete record(s)

const deleteOne = await airtable.delete("recXXXXXXXXXXXXXX");

const deleteMultiple = await airtable.delete([
  "recXXXXXXXXXXXXXX",
  "recXXXXXXXXXXXXXX",
]);

Advanced examples

For advanced examples, refer to the airtable-deno examples file.

Polyfilling fetch

Since Node.js does not have built-in fetch implementation unlike Deno, airtable-dnd has two ways to implement/polyfill fetch.

Polyfill methods

  • Pass fetch compliant object to client instantiation

    airtable-dnd has cross-fetch as a peer dependency for polyfilling, but you can use other fetch compliant packages (node-fetch, whatwg-fetch, isomorphic-fetch, etc.), you can import and pass the fetch object on client instantiation.

    import fetch from "node-fetch";
    
    const airtable = new Airtable({
      fetch,
    });
    
  • Polyfill fetch globally

    Alternatively, you can do a global polyfill with cross-fetch/polyfill or other fetch compliant packages that supports global polyfilling before instantiating or calling the Airtable client.

    import "cross-fetch/polyfill";
    
    const airtable = new Airtable({
      // no need to pass `fetch` since it's polyfilled globally
    });
    

Polyfill prioritization

By default, airtable-dnd will use the fetch object passed from the instantiation option, then fallbacks to the global fetch object.

Further reading

All options, parameters, errors, and responses are the same as on the Airtable API documentation.

Dependencies

License

MIT License Copyright (c) 2020 Griko Nibras




dnd = deno to node :p

FAQs

Last updated on 08 Sep 2020

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc