UNPKG

2.17 kBMarkdownView Raw
1[![Build Status](https://travis-ci.org/forest-fre/abstracted-client.svg?branch=master)](https://travis-ci.org/forest-fre/abstracted-client.svg?branch=master)
2[![Coverage Status](https://coveralls.io/repos/github/forest-fre/abstracted-client/badge.svg?branch=master)](https://coveralls.io/github/forest-fre/abstracted-client?branch=master)
3[![MIT license](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://opensource.org/licenses/MIT)
4
5![ ](./docs/images/abstracted-client.jpg)
6
7> A minimal abstraction over the Firebase client API
8
9## Basic Usage
10
11Meant for frontend Javascript/Typescript apps which interact with Firebase's client API using the firebase client api.
12
13```ts
14import DB, { IFirebaseConfig } from "abstracted-client";
15const config: IFirebaseClientConfig = {
16 apiKey: "ATzaSyDuimhvBmcV1zeTl4m1MphOgWnzS16QhBM",
17 authDomain: "my-app.firebaseapp.com",
18 databaseURL: "https://my-app.firebaseio.com",
19 projectId: "my-app",
20 storageBucket: "my-app.appspot.com",
21 messagingSenderId: "999999999999"
22};
23const db = new DB({ config });
24// Get a list of records
25const users = await db.getValue<IUser[]>("users");
26// Push a new value onto a list
27const company: ICompany = {
28 name: "Acme",
29 employees: 500
30};
31db.push<ICompany>("/companies", company);
32```
33
34### Authentication
35
36All of the authentication is done via the normal [Firebase API for Auth](https://firebase.google.com/docs/reference/js/firebase.auth) which is accessible as `auth` off the DB class:
37
38```ts
39const db = new DB({ config });
40const auth = db.auth;
41```
42
43### Mocking
44
45This library supports simple redirecting of all operations to the `firemock` mocking library; see [related projects](docs/related.md)) and the ["Mocking" section](docs/mocking.md) of the docs here for more details. In cases where mocking is being used, authentication (and security rights for paths) are not supported and therefore the above ENV variables are not required.
46
47## Documentation
48
49Since this library and **abstracted-admin** share a common implementation for most of their API surface you'll find the documentation here:
50[abstracted-admin](https://forest-fire.gitbooks.io/abstracted-client/content/)