Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@zenginehq/backend-firebase

Package Overview
Dependencies
Maintainers
6
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zenginehq/backend-firebase

Helper library for working with znFirebase in Zengine backend plugins.

  • 2.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
6
Created
Source

Backend Firebase

Helper module for working with znFirebase in Zengine backend Plugins.

Coverage Status Build Status npm version

Installation

npm i @zenginehq/backend-firebase --save

Usage

var $firebase = require('@zenginehq/backend-firebase')();

var workspaceId = 11111;

// Load data.
$firebase.load(workspaceId).then(function (data) {
  console.log('it works!', data);
  // data fetched from <firebaseRoot>/11111
}).catch(function (err) {
  console.error(err);
});

// Save data.
var dataObj = {
  'childRoute': someData
  // someData could be any data type,
  // but dataObj (2nd argument of .save()) must be an object
}

$firebase.save(workspaceId, dataObj).then(function () {
  console.log('success!');
  // someData was saved at <firebaseRoot>/11111/childRoute
}).catch(function (err) {
  console.error(err);
});

// Delete data.
var recordId = 222
var deleteObj = {}
deleteObj[recordId] = null

$firebase.save(workspaceId, deleteObj).then(function () {
  console.log('success!');
  // the firebase route <firebaseRoot>/11111/222
  // and all data it contained has been deleted
}).catch(function (err) {
  console.error(err);
})

// Use arrays to formulate complex Firebase paths for both loading and saving.
var formId = 222
var recordId = 333

$firebase.load([workspaceId, formId, recordId, 'settings']).then(function (data) {
  // This will expand to: <firebaseRoot>/11111/222/333/settings
  console.log('it works!', data);
}).catch(function (err) {
  console.error(err);
});

// You can also pass a long string if that's your thing.
$firebase.load('foo/bar/baz/' + workspaceId + '/etc');

Note about Deletions

Passing null as the second argument of .save will cause strange and unhelpful behavior. Instead, pass an object with the endpoint(s) as the key(s) and null as the value(s) for the second argument. See Firebase docs for the underlying .update() command that is called.

Ex:

// much regrets
$firebase.save([workspaceId, 'undesiredField'], null).then(function () {
  //etc...
})

// all the good vibes
$firebase.save(workspaceId, {'undesiredField': null}).then(function () {
  // great work, team!
});

Contributing

See contributing doc

API Docs

Full documentation

Keywords

FAQs

Package last updated on 07 Feb 2019

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc