seneca-counter-firebase

1.2.0 • Public • Published

Build Status Coverage Status js-standard-style

seneca-counter-firebase

A counter plugin for the Seneca microservices toolkit with a firebase backend.

Installation

From npm

$ npm i --save seneca-counter-firebase

Messages handled

role:counter, cmd:add

Adds a value to the given key. Uses value as key if no key supplied. Defaults to 1 if no value is presented.

Seneca.act('role:counter, cmd:add', {key: 'test', value: 2}, (error, data) => {})

role:counter, cmd:subtract

Subtracts a value from the given key. Uses value as key if no key supplied. Defaults to 1 if no value is presented.

Seneca.act('role:counter, cmd:subtract', {key: 'test', value: 2}, (error, data) => {})

role:counter, cmd:get

Get the value from a given key. Uses value as key if no key supplied.

Seneca.act('role:counter, cmd:get', {key: 'test'}, (error, data) => {})

Messages emitted

None

Example

If your Firebase database is completely open (rules) you can drop apiKey, authDomain, authEmail and authPassword from your config.

If yoy want restrictions this module supports Firebase's email/password sign-in.

'use strict'
 
const Seneca = require('seneca')()
const senecaCounter = require('seneca-counter-firebase')
const senecaCounterOptions = {
  tag: 'seneca-counter-firebase',
  apiKey: '<your-firebase-api-key>',
  authDomain: '<your-firebase-auth-domain>',
  databaseURL: '<your-firebase-database-url>', // Required
  appName: '<your-firebase-app-name>',
  authEmail: '<your-firebase-user-email>',
  authPassword: '<your-firebase-user-password>'
}
 
Seneca.use(senecaCounter, senecaCounterOptions)
 
Seneca.listen(1337)
 

Curl

Call the service to add a value for a given key

$ curl -d '{"role":"counter", "cmd":"add", "key": "test", "value": 2}' -v http://localhost:1337/act

or to subtract a value for a given key

$ curl -d '{"role":"counter", "cmd":"subtract", "key": "test", "value": 2}' -v http://localhost:1337/act

Lookup a key

$ curl -d '{"role":"counter", "cmd":"get", "key": "test"}' -v http://localhost:1337/act

returns

{success: true, key: 'test', value: 0} 

if no key is supplied it will use value as key

License

MIT

alt text

Package Sidebar

Install

npm i seneca-counter-firebase

Weekly Downloads

4

Version

1.2.0

License

MIT

Last publish

Collaborators

  • zrrrzzt