Catalog npm
Back to packageRELEASE DETAILS

0.1.0-1

npm

5htp-airtable

Integrate Airtable to any 5HTP App

5htpairtabledatabasesyncsynchronisation
Published26 Mar 2024
Direct dependencies4
Transitive dependenciesNot calculated

README

Current package documentation

Airtable Sync for 5HTP

5HTP Service to integrate Airtable API and synchronise it with MySQL tables

npm

Installation

npm install --save 5htp-airtable

Features

  • Initial sync (differential)
  • Realtime sync (websocket)
  • Support for relationships: one to one, one to many, many to many
  • Perfectly integrated with the 5HTP framework

How it works

To be done

How to sync your Airtable table with a MySQL table

1. Create your data provider

/*----------------------------------
- DEPENDANCES
----------------------------------*/

// App
import { Airtable, Hub } from '@app';
import DataProvider, { TAirtableMapper } from '5htp-airtable/provider';

/*----------------------------------
- TYPES
----------------------------------*/

type UserFromAirtable = {

    // Identity
    'First Name': string,
    'Last Name': string,
    'Country': string[],
    'Languages': string[],
    'Password'?: string,

    // Contact Info
    'Email': string,
    'Phone Number': string,
    'LinkedIn URL': string,

    // Synced Table
    'Created': Date,
    'Updated': Date
}

type UserRelations = {
    languages: string[],
}

/*----------------------------------
- PROVIDER
----------------------------------*/
export default class UserProvider extends DataProvider<UserFromAirtable, User, UserRelations> {

    public constructor( public users: UserService, public app = users.app ) {
        super(app, 'users');
        
        // Register to Airtable service + load airtable & db table metadatas
        Airtable.registerProvider(this);
    }

    // Input
    public airtable = Airtable.table('myAirtableBase', 'myAirtableTable');
    // All the required fields in User database table should be mapped here
    // So we ensure that after the mapping, we upsert the minimum required values
    public mapper: TAirtableMapper<UserFromAirtable, User, UserRelations> = {

        // Identoty
        'firstName': {
            airtable: 'First Name',
        },
        'lastName': {
            airtable: 'Last Name',
        },
        'country': {
            airtable: 'Country',
            toOne: () => Hub.geolocations
        },
        'languages': {
            airtable: 'Languages',
            toMany: () => ({
                table: 'UserLanguage',
                pk: {
                    key: 'headhunter',
                },
                fk: {
                    key: 'language',
                    provider: Hub.languages,
                }
            })
        },
        'password': {
            airtable: 'Password',
        },
    }

    // Database table name
    public tableName = 'User';
}

2. How to use your provider

import UserProvider from './provider';

export default class UsersService extends Service {

    // 1. Instanciate Provider
    public provider = new UserProvider(this);

    public async start() {
        // 2. Ensure the database is sync with Airtable
        await this.provider.sync();
    }

    public async signup( newUser: User, request: Request ) {
        // 3. Insert new data on both Airtable and Database
        const inserted = await this.provider.create({
            ...newUser,
            password: sha1(newUser.password),
        });
    }

    public async resetPassword( 
        type: string, 
        token: string, 
        rawPassword: string,
    ) {
        // 4. Update data on both Airtable and Database
        await this.provider.update([{
            airtableId: user.airtableId,
            email: email,
            password: sha1(rawPassword)
        }]);
    }
}

Use it remotely

To be done

Changelog

0.1.0 (26/03/2024)

  • Remote Providers
    • Bug fixes
    • Improve security by requiring a token
  • Writing the sync() method in the provider is now optional (but can be overwritten if you need to call special actions after sync)
  • Simplified readme
  • Fix issue when the DB table pk is airtableId
  • Update database implementation to 5HTP 0.3.8
  • Added more logs

0.0.9 (22/12/2023)

  • Possibility to create RemoteProviders

To be done

[] Fix typings [] Import typings from 5htp-core (peerdeps) [] Tests [] Usage doc

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 4

Native requirements
4 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
dayjs
Environment
{
  "local_name": "dayjs",
  "alias": false,
  "peer_metadata": null
}
^1.11.9runtime
ngrok
Environment
{
  "local_name": "ngrok",
  "alias": false,
  "peer_metadata": null
}
^5.0.0-beta.2runtime
short-unique-id
Environment
{
  "local_name": "short-unique-id",
  "alias": false,
  "peer_metadata": null
}
^4.4.4runtime
5htp-core
Environment
{
  "local_name": "5htp-core",
  "alias": false,
  "peer_metadata": null
}
^0.3.7development

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "shasum": "7e07170a1ac644f16ebe6657e836aae836c9a308",
  "tarball": "https://registry.npmjs.org/5htp-airtable/-/5htp-airtable-0.1.0-1.tgz",
  "fileCount": 13,
  "integrity": "sha512-qlzFyFpD6pfz8iSaeVRPWgQT/HQLcF2Yrv243YopMSdBfRo4STR1C64G0yRqaoaUrnzLpX7qRH1+KOeD+DnKDA==",
  "signatures": [
    {
      "sig": "MEYCIQDXkeCly3dQRMpsfDpP6tr8Lb6sUtsCbJMVCxjd5W135QIhAPUs+hmc3BOuA5rKnJI2shD4dOQ0dJXLdHSNztKoLXSq",
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"
    }
  ],
  "unpackedSize": 112257
}

Repository

PENDING
gaetanlegac/5htp-airtable

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 20:35 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:b99233b51b27d2d9120994182c3f06fae6bbc1dbbf3e22d055fc0e237c0cf2cd

Other collected versions

0.1.2-323 Sept0.1.2-29 Sept0.1.2-19 Sept0.1.29 Sept0.1.16 Sept0.1.021 MarView all collected versions →