Supabase client initialization and encapsulation in fastify framework

Overview

fastify-supabase

NPM version GitHub CI Coverage Status js-standard-style

Supabase client initialization and encapsulation in fastify framework.

Install

Install the package with:

npm i fastify-supabase --save

Usage

The package needs to be added to your project with register and you must at least configure your Supabase API key and your Supabase URL wich are available in your Supabase project settings then call the Supabase API and you are done.

const fastify = require('fastify')({ logger: true })

fastify.register(require('fastify-supabase'), {
  supabaseKey: 'public-anon-key',
  supabaseUrl: 'https://xyzcompany.supabase.co'
})

fastify.get('/read', async (request, reply) => {
  const { supabase } = fastify

  const { data, error } = await supabase.from('cities').select()

  return { data, error }
})

fastify.listen(3000, err => {
  if (err) {
    fastify.log.error(err)
    process.exit(1)
  }
})

Options

  • supabaseKey [ required ] : The unique Supabase Key which is supplied when you create a new project in your project dashboard.

  • supabaseUrl [ required ] : The unique Supabase URL which is supplied when you create a new project in your project dashboard.

  • namespace [ optional ] : Through this option fastify-supabase lets you define multiple Supabase singular instances (with different options parameters if you wish) that you can later use in your application.

const fastify = require('fastify')({ logger: true })

fastify.register(require('fastify-supabase'), {
  namespace: 'one',
  supabaseKey: 'public-anon-key-one',
  supabaseUrl: 'https://xyzcompanyprojectone.supabase.co'
})

fastify.register(require('fastify-supabase'), {
  namespace: 'two',
  supabaseKey: 'public-anon-key-two',
  supabaseUrl: 'https://xyzcompanyprojecttwo.supabase.co'
})

fastify.get('/fetch-from-one', async (request, reply) => {
  const { supabase } = fastify

  const { data, error } = await supabase.one.from('project_one_table').select()

  return { data, error }
})

fastify.get('/fetch-from-two', async (request, reply) => {
  const { supabase } = fastify

  const { data, error } = await supabase.two.from('project_two_table').select()

  return { data, error }
})

fastify.listen(3000, err => {
  if (err) {
    fastify.log.error(err)
    process.exit(1)
  }
})
  • schema [ optional ] : The Postgres schema which your tables belong to. Must be on the list of exposed schemas in Supabase. Defaults to 'public'.

  • headers [ optional ] <{ [key: string]: string }>: Optional headers for initializing the client.

  • autoRefreshToken [ optional ] : Automatically refreshes the token for logged in users.

  • persistSession [ optional ] : Whether to persist a logged in session to storage.

  • detectSessionInUrl [ optional ] : Detect a session from the URL. Used for OAuth login callbacks.

  • localStorage [ optional ] : A storage provider. Used to store the logged in session.

  • realtime [ optional ] : Options passed to the realtime-js instance.

Note for TypeScript users: If you are a TypeScript user, take a look at Supabase Generating Types documentation.

Documentation

See the Supabase reference documentation.

Testing

  • Create a test table in your Supabase project database with:
CREATE TABLE "public"."fastify_supabase_test" (
  "id" uuid DEFAULT GEN_RANDOM_UUID() NOT NULL,
  "job" uuid NOT NULL,
  "name" character varying NOT NULL,
  "created_at" timestamptz DEFAULT CURRENT_TIMESTAMP NOT NULL,
  CONSTRAINT "fastify_supabase_test_id__pkey" PRIMARY KEY ("id")
) WITH (oids = false);
  • Create a file named .env (at the root of this project) providing your supabaseKey and supabaseUrl:
SUPABASE_API_KEY=public-anon-key-of-your-project
SUPABASE_PROJECT_URL=https://xyzcompany.supabase.co
  • Finally run tests with:
npm run test

Acknowledgements

  • Ruan Martinelli for kindly transferring the ownership of the package name.
  • This project is kindly sponsored by coopflow.

License

Licensed under MIT

Comments
Releases(1.2.1)
  • 1.2.1(Mar 2, 2022)

    What's Changed

    • chore: update package by @coopflow in https://github.com/coopflow/fastify-supabase/pull/18

    Full Changelog: https://github.com/coopflow/fastify-supabase/compare/1.2.0...1.2.1

    Source code(tar.gz)
    Source code(zip)
  • 1.2.0(Feb 16, 2022)

    What's Changed

    • chore(deps-dev): bump dotenv from 14.3.2 to 16.0.0 by @dependabot in https://github.com/coopflow/fastify-supabase/pull/14
    • chore: update ci and package dependencies by @coopflow in https://github.com/coopflow/fastify-supabase/pull/15
    • docs: fix typo by @coopflow in https://github.com/coopflow/fastify-supabase/pull/17
    • test: improve test suite by @coopflow in https://github.com/coopflow/fastify-supabase/pull/16

    Full Changelog: https://github.com/coopflow/fastify-supabase/compare/1.1.0...1.2.0

    Source code(tar.gz)
    Source code(zip)
  • 1.1.0(Jan 21, 2022)

    What's Changed

    • chore(deps-dev): bump tsd from 0.18.0 to 0.19.0 by @dependabot in https://github.com/coopflow/fastify-supabase/pull/5
    • chore: upgrade package dependencies by @coopflow in https://github.com/coopflow/fastify-supabase/pull/6
    • ci: add macOS and Windows runners by @coopflow in https://github.com/coopflow/fastify-supabase/pull/7
    • chore: upgrade package dependencies by @coopflow in https://github.com/coopflow/fastify-supabase/pull/8
    • chore(deps-dev): bump dotenv from 10.0.0 to 14.2.0 by @dependabot in https://github.com/coopflow/fastify-supabase/pull/11
    • chore (ci): add Node.js 17 and run CI linting only once by @coopflow in https://github.com/coopflow/fastify-supabase/pull/12

    Full Changelog: https://github.com/coopflow/fastify-supabase/compare/1.0.2...1.1.0

    Source code(tar.gz)
    Source code(zip)
  • 1.0.2(Nov 17, 2021)

    What's Changed

    • chore: bump @supabase/supabase-js from 1.24.0 to 1.28.0
    • chore: upgrade package dependencies
    • chore(deps-dev): bump tsd from 0.17.0 to 0.18.0 by @dependabot in https://github.com/coopflow/fastify-supabase/pull/3

    New Contributors

    • @dependabot made their first contribution in https://github.com/coopflow/fastify-supabase/pull/3
    Source code(tar.gz)
    Source code(zip)
  • 1.0.1(Oct 1, 2021)

    • Avoid npm error Cannot publish over previously published version "1.0.0": bumped v1.0.1
    • docs: rephrase
    • docs: explain how to run package tests
    • refactor (test): change the table used for tests
    • chore: upgrade package dependencies
    • refactor (test): rework tests to avoid CI collisions
    • docs: add npm badge
    Source code(tar.gz)
    Source code(zip)
  • 1.0.0(Oct 1, 2021)

    • docs: explain how to run package tests
    • refactor (test): change the table used for tests
    • chore: upgrade package dependencies
    • refactor (test): rework tests to avoid CI collisions
    • docs: add npm badge
    Source code(tar.gz)
    Source code(zip)
  • 0.0.1(Sep 29, 2021)

Owner
null
🌟 DataFormsJS 🌟 A minimal JavaScript Framework and standalone React and Web Components for rapid development of high quality websites and single page applications.

?? Welcome to DataFormsJS! Thanks for visiting! ?? ?? ?? ?? ?? ?? 中文 (简体) 欢迎来到 DataFormsJS Español Bienvenido a DataFormsJS Português (do Brasil) Bem

DataFormsJS 156 Dec 8, 2022
An HTML5/CSS3 framework used at SAPO for fast and efficient website design and prototyping

Welcome to Ink Ink is an interface kit for quick development of web interfaces, simple to use and expand on. It uses a combination of HTML, CSS and Ja

SAPO 1.9k Dec 15, 2022
A framework for real-time applications and REST APIs with JavaScript and TypeScript

A framework for real-time applications and REST APIs with JavaScript and TypeScript Feathers is a lightweight web-framework for creating real-time app

Feathers 14.2k Dec 28, 2022
MVC framework making it easy to write realtime, collaborative applications that run in both Node.js and browsers

Derby The Derby MVC framework makes it easy to write realtime, collaborative applications that run in both Node.js and browsers. Derby includes a powe

DerbyJS 4.7k Dec 31, 2022
The most popular HTML, CSS, and JavaScript framework for developing responsive, mobile first projects on the web.

Bootstrap Sleek, intuitive, and powerful front-end framework for faster and easier web development. Explore Bootstrap docs » Report bug · Request feat

Bootstrap 161.1k Jan 4, 2023
An open-source, self-hosted, low-code framework to build internal tools, web apps, admin panels, BI dashboards, workflows, and CRUD apps with YAML or JSON.

An open-source, self-hosted, low-code framework to build internal tools, web apps, admin panels, BI dashboards, workflows, and CRUD apps with YAML or JSON.

Lowdefy 2k Jan 4, 2023
Brail is a framework built on NextJS for developing email templates in React, and returning HTML that is compatible with major email clients.

Brail is a framework built on NextJS for developing email templates in React, and returning HTML that is compatible with major email clients. It aims to seperate the concerns of generating the emails and delivering them.

null 121 Jan 2, 2023
The worlds smallest fully-responsive css framework

FLUIDITY A fully responsive css framework that is impossibly small HTML is almost 100% responsive out of the box. This stylesheet patches the remainin

murmurs 1.1k Sep 24, 2022
HTML Framework that allows you not to write JavaScript code.

EHTML (or Extended HTML) can be described as a set of custom elements that you can put on HTML page for different purposes and use cases. The main ide

Guseyn Ismayylov 171 Dec 29, 2022
One framework. Mobile & desktop.

Angular - One framework. Mobile & desktop. Angular is a development platform for building mobile and desktop web applications using Typescript/JavaScr

Angular 85.7k Jan 4, 2023
Ember.js - A JavaScript framework for creating ambitious web applications

Ember.js is a JavaScript framework that greatly reduces the time, effort and resources needed to build any web application. It is focused on making yo

Ember.js 22.4k Jan 8, 2023
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

Supporting Vue.js Vue.js is an MIT-licensed open source project with its ongoing development made possible entirely by the support of these awesome ba

vuejs 201.7k Jan 8, 2023
The tiny framework for building hypertext applications.

Hyperapp The tiny framework for building hypertext applications. Do more with less—We have minimized the concepts you need to learn to get stuff done.

Jorge Bucaran 18.9k Jan 4, 2023
A framework for building native apps with React.

React Native Learn once, write anywhere: Build mobile apps with React. Getting Started · Learn the Basics · Showcase · Contribute · Community · Suppor

Facebook 106.8k Jan 3, 2023
The Backbone Framework

Marionette.js The Backbone Framework Marionette v5 Marionette is dropping its dependency on Backbone. That library is available here: https://github.c

Marionette.js 7.1k Jan 5, 2023
A JavaScript Framework for Building Brilliant Applications

mithril.js What is Mithril? Installation Documentation Getting Help Contributing What is Mithril? A modern client-side JavaScript framework for buildi

null 13.5k Dec 26, 2022
Better MV-ish Framework

❗ I started working on this project in 2012. React didn't exist, Angular didn't have a stable 1.0 release, Internet Explorer 7, 8, 9 was used by 35% o

Antonio Stoilkov 2.8k Jan 1, 2023
A rugged, minimal framework for composing JavaScript behavior in your markup.

Alpine.js Alpine.js offers you the reactive and declarative nature of big frameworks like Vue or React at a much lower cost. You get to keep your DOM,

Alpine.js 22.5k Dec 30, 2022