flamelink / flamelink-js-sdk

🦊 Official Flamelink JavaScript SDK for both the Firebase Realtime database and Cloud Firestore
https://flamelink.github.io/flamelink-js-sdk
MIT License
42 stars 5 forks source link
browser firebase flamelink javascript nodejs sdk

Flamelink JavaScript SDK

Lerna Conventional Commits NPM version NPM downloads CircleCI jsDelivr

logo

Easily integrate with your Flamelink CMS.

Official Flamelink JavaScript SDK for both the Firebase Realtime Database and Cloud Firestore

This SDK is intended for use in a browser or Node.js environment.

If you are unfamiliar with Flamelink, please visit our flamelink.io website for more info on features, pricing and more.

Prerequisites

It goes without saying that you will need to have a Flamelink project for this SDK to be of any use to you.

Apart from the Flamelink project, the only real hard dependency is either the Firebase JavaScript SDK or Firebase Admin SDK, depending on whether you use Flamelink from a browser or server environment. Take a look at the installation instructions on their README files, but in short, just make sure you add firebase and/or firebase-admin as a dependency to your project.

When running a universal app, you might need to switch been the client and admin SDK depending on where in the stack the code is running.

Once you have firebase installed, you can install flamelink using any of the following options (we recommend npm or yarn):

Installation

Install with npm

npm install --save flamelink@next

or with yarn

yarn add flamelink@next

or with a <script> tag hosted from any of these CDN's

jsDelivr

Add the following script tag to the <body> of your index.html file:

<script src="https://github.com/flamelink/flamelink-js-sdk/raw/master//cdn.jsdelivr.net/npm/flamelink@next/flamelink.js"></script>

This will always load the latest version of this SDK for you. If you want to load a specific version, you can specify the version number as well (1.0.0-rc.2 in the example):

<script src="https://github.com/flamelink/flamelink-js-sdk/raw/master//cdn.jsdelivr.net/npm/flamelink@1.0.0-rc.2/flamelink.js"></script>

See the jsDelivr website for more options

unpkg

Add the following script tag to the <body> of your index.html file:

<script src="https://github.com/flamelink/flamelink-js-sdk/raw/master//unpkg.com/flamelink@next/flamelink.js"></script>

This will always load the latest version of this SDK for you. If you want to load a specific version, you can specify the version number as well (1.0.0-rc.2 in the example):

<script src="https://github.com/flamelink/flamelink-js-sdk/raw/master//unpkg.com/flamelink@1.0.0-rc.2/flamelink.js"></script>

See the unpkg website for more options

Usage

Importing/Adding the dependencies

First ensure that you load the firebase SDK and then the main flamelink app package along with any of the modules you want to you in your project.

The examples below shows you how to quickly get started. Take a look at the Advanced Installation instructions to import only what you need.

In a CommonJS environment:

var flamelink = require('flamelink')

or using ES Modules or TypeScript:

import flamelink from 'flamelink'

Note: You might need to enable the esModuleInterop option in either your tsconfig.json file or provided as a CLI flag when using TypeScript.

Creating your Flamelink app instance

Create your flamelink app instance by passing in an existing firebaseApp instance along with any other flamelink config options:

import * as firebase from 'firebase'
import flamelink from 'flamelink'

const firebaseConfig = {
  apiKey: '<your-api-key>',
  authDomain: '<your-auth-domain>',
  databaseURL: '<your-database-url>',
  projectId: '<your-project-id>',
  storageBucket: '<your-storage-bucket-code>',
  messagingSenderId: '<your-messenger-id>',
}

const firebaseApp = firebase.initializeApp(firebaseConfig)

const app = flamelink({
  firebaseApp, // required
  dbType: 'rtdb', // can be either 'rtdb' or 'cf' for Realtime DB or Cloud Firestore
  env: 'production', // optional, default shown
  locale: 'en-US', // optional, default shown
  precache: true, // optional, default shown. Currently it only precaches "schemas" for better performance
})

Tip: Go to your Firebase console for more info regarding the Firebase app options.

When using the firebase-admin SDK on server-side, it is the same, you only pass in the Firebase admin app instance instead:

const admin = require('firebase-admin')
const flamelink = require('flamelink')
const serviceAccount = require('path/to/serviceAccountKey.json')

const firebaseConfig = {
  credential: admin.credential.cert(serviceAccount),
  databaseURL: '<your-database-url>',
  storageBucket: '<your-storage-bucket-code>', // required if you want to use any Storage Bucket functionality
}

const firebaseApp = admin.initializeApp(config)

const app = flamelink({
  firebaseApp, // required
  // same options as above
})

You can use any of the different ways to create the admin firebaseApp instance.

Using your flamelink app

Once you have an instance of the flamelink app, you can start using it to interact with your data stored in either your Firebase Real-time Database or Cloud Firestore. Suppose you want to retrieve all your products created under the "Content" section in flamelink.

const products = await app.content.get({ schemaKey: 'products' })
console.log('All of your products:', products)

As easy as that. Read our docs for more specifics.

πŸ”₯πŸ”₯πŸ”₯ Flame on!! πŸ”₯πŸ”₯πŸ”₯

History

Discover the release history by heading on over to the HISTORY.md file.

Backers

Maintainers

These amazing people are maintaining this project:

Sponsors

No sponsors yet! Will you be the first?

Contributors

These amazing people have contributed code to this project:

Discover how you can contribute by heading on over to the CONTRIBUTING.md file.

License

Unless stated otherwise all works are:

and licensed under: