Skip to content

Commit 8cdef9e

Browse files
authored
v1.1.0 ✨Fully functional + Public release
Merge pull request #7 from Sharks-Interactive/staging
2 parents e2d470e + c2f86a7 commit 8cdef9e

File tree

6 files changed

+244
-95
lines changed

6 files changed

+244
-95
lines changed

.github/workflows/CI-CD.yml renamed to .github/workflows/CD.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
name: CI-CD
1+
name: CD
22

33
on:
4-
# Triggers the workflow on push or pull request events but only for the prod branch
5-
push:
6-
branches: [ prod ]
4+
# Triggers the workflow when new releases are created
5+
release:
6+
types: [published]
77

88
# Allows you to run this workflow manually from the Actions tab
99
workflow_dispatch:

.github/workflows/CI.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: CI
2+
3+
on:
4+
# Triggers the workflow when new PRS or commits are created on Prod
5+
push:
6+
branches:
7+
- prod
8+
pull_request:
9+
branches:
10+
- prod
11+
12+
# Allows you to run this workflow manually from the Actions tab
13+
workflow_dispatch:
14+
15+
jobs:
16+
check:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v2.3.4
20+
- uses: actions/setup-node@v1
21+
with:
22+
node-version: 12
23+
registry-url: https://registry.npmjs.org/
24+
25+
- name: Setup
26+
run: yarn install
27+
- name: Format
28+
run: npm run format
29+
- name: Fix
30+
run: npm run lint-fix
31+
32+
- name: Auto committing styled files
33+
uses: stefanzweifel/git-auto-commit-action@v4
34+
with:
35+
repository: 'src/'
36+
commit_message: "Github Action: Auto styled TS files"
37+
branch: ${{ github.ref }}
38+
add_options: '-f'
39+
40+
- name: Build
41+
run: npm run build

README.md

Lines changed: 91 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,98 @@
1-
# Workers Firebase RTDB Client
2-
A Firebase RealTime Database Client library for use specifically with CloudFlare Workers.
3-
Does not set or mutate global state.
4-
5-
# Usage:
6-
### NPM:
7-
``npm i @sharks-interactive/workers-firebase-rtdb-rest-client``
8-
### CDN:
9-
#### JSDELIVER:
10-
``https://www.jsdelivr.com/package/npm/@sharks-interactive/workers-firebase-rtdb-rest-client``
11-
#### UNPKG:
12-
``https://unpkg.com/@sharks-interactive/workers-firebase-rtdb-rest-client``
13-
### GITHUB:
14-
``https://github.com/Sharks-Interactive/releases``
1+
<p align='center'>
2+
<img src="https://i.imgur.com/7svMXLi.png" />
3+
</p>
4+
![npm version](https://img.shields.io/npm/v/@sharks-interactive/workers-firebase-rtdb-rest-client)
5+
![npm downloads](https://img.shields.io/npm/dm/@sharks-interactive/workers-firebase-rtdb-rest-client)
6+
![npm types](https://img.shields.io/npm/types/@sharks-interactive/workers-firebase-rtdb-rest-client)
157

16-
## How it works:
17-
This client library is a simplified layer between your code and the Firebase REST API.
18-
In the background it uses the Workers FETCH API to send HTTP requests to your Database.
8+
# Workers Firebase RTDB Client
9+
**Workers Firebase RTDB** is a [Firebase Realtime Database](https://firebase.google.com/docs/database) client library for use specifically with [Cloudflare Workers](https://developers.cloudflare.com/workers/) written in TypeScript.
1910

2011
## Functionality
21-
- Easily create, edit, update, and delete json from your database
22-
- Easy authentication with your database and it rules
23-
- Supports conditional requests and ETag's
24-
- Subscribe to data change events
25-
### All in vanilla js with _no_ dependencies and in only **KB [for minified version]
12+
- Easily **create, edit, update, and delete** json from your database
13+
- Easy **authentication** with your database and its rules
14+
- Supports **conditional requests**/ETag's
15+
- **Follows Workers guidelines**, such as not mutating global state
16+
- **Thorough documentation** and easy to understand functions
17+
18+
## Usage:
19+
```
20+
npm i --save @sharks-interactive/workers-firebase-rtdb-rest-client
21+
```
22+
23+
## Quick Examples:
24+
#### Writing Data
25+
```ts
26+
import Database from '@sharks-interactive/workers-firebase-rtdb';
27+
28+
addEventListener('fetch', (event) => {
29+
const db = new Database({
30+
databaseUrl: 'https://example-db-default-rtdb.firebaseio.com/',
31+
authentication: 'bearer ya29.[YOUR-OAUTH-TOKEN-HERE]',
32+
tokenAuthentication: true,
33+
});
34+
event.respondWith(async () => {
35+
const success = await db.update(
36+
'user/settings',
37+
JSON.stringify({theme: 'dark'}),
38+
true,
39+
new Headers(), // Optional
40+
);
41+
42+
if (success) return new Response('Ok', {status: 200, statusText: 'OK'});
43+
else return new Response('Something went wrong', {status: 500, statusText: 'Internal Server Error'});
44+
});
45+
});
46+
47+
```
2648

27-
###### (The dependencies listed are devDeps)
49+
### Reading Data
50+
```ts
51+
import Database from '@sharks-interactive/workers-firebase-rtdb';
2852

29-
### Read the wiki for documentation.
53+
addEventListener('fetch', (event) => {
54+
const db = new Database({
55+
databaseUrl: 'https://example-db-default-rtdb.firebaseio.com/',
56+
authentication: 'bearer ya29.[YOUR-OAUTH-TOKEN-HERE]',
57+
tokenAuthentication: true,
58+
});
59+
event.respondWith(async () => {
60+
const response = await db.read(
61+
'user/settings',
62+
true,
63+
new Headers(), // Optional
64+
);
3065

31-
## src /
32-
- Contains the source code
66+
if (response != '') return new Response(response, {status: 200, statusText: 'OK'});
67+
else return new Response('Something went wrong', {status: 500, statusText: 'Internal Server Error'});
68+
});
69+
});
3370

34-
## dist /
35-
- Contains js code
71+
```
72+
73+
## Features:
74+
- **.update()** updates data with a PATCH request
75+
- **.push()** pushes data with a POST request
76+
- **.write()** writes data with a PUT request
77+
- **.read()** reads data with a GET request
78+
- **.delete()** deletes data with a DELETE request
79+
- **.appendGetEtagHeader()** appends to a list of headers the header required to get the ETag of data in the database
80+
- **.appendEtagIfHeader()** appends to a list of headers the header required to submit a conditional ETag request to the database
81+
- **tokenAuthentication** supports OAUTH token authentication as well as Firebase ID authentication
82+
83+
## Options (Required)
84+
85+
| Option | Type | Description |
86+
| ------ | ---- | ----------- |
87+
| databaseUrl | string | A string containing the base URL of your database. It **SHOULD** end in a ``/`` and it **MUST** start with ``https://``. See: https://firebase.google.com/docs/database/rest/start |
88+
| authentication | string | Your authentication information. This should be a OAUTH token if ``tokenAuthentication`` is true, and an ID token if if is false. See: https://firebase.google.com/docs/database/rest/auth |
89+
| tokenAuthentication | boolean | Whether the ``authentication`` string is an OAUTH token or Firebase ID. See: https://firebase.google.com/docs/database/rest/auth
90+
91+
## How it works:
92+
This client library is a simplified layer between your code and the Firebase REST API.
93+
In the background it uses the Workers FETCH API to send HTTP requests to your Database.
94+
95+
**Read the wiki for extra documentation.**
3696

3797
Project created and maintained by Sharks Interactive.
3898

@@ -42,3 +102,6 @@ Project created and maintained by Sharks Interactive.
42102
### Code Style:
43103
- Continious Integration will handle formatting for you
44104
- Use ESLINT locally to catch errors pre-pr
105+
106+
## Acknowledgements:
107+
**README.MD and general SDK structure, styling, practices etc, modelled after and taken from the excellent [Toucan-JS](https://github.com/robertcepa/toucan-js)**

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sharks-interactive/workers-firebase-rtdb-rest-client",
3-
"version": "1.0.1",
3+
"version": "1.1.0",
44
"description": "Firebase RTDB Client for CloudFlare Workers.",
55
"main": "dist/index.cjs.js",
66
"module": "dist/index.esm.js",

0 commit comments

Comments
 (0)