Skip to content

Commit

Permalink
v1.1.0 ✨Fully functional + Public release
Browse files Browse the repository at this point in the history
Merge pull request #7 from Sharks-Interactive/staging
  • Loading branch information
Sharkgamedev authored Nov 26, 2021
2 parents e2d470e + c2f86a7 commit 8cdef9e
Show file tree
Hide file tree
Showing 6 changed files with 244 additions and 95 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/CI-CD.yml → .github/workflows/CD.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: CI-CD
name: CD

on:
# Triggers the workflow on push or pull request events but only for the prod branch
push:
branches: [ prod ]
# Triggers the workflow when new releases are created
release:
types: [published]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand Down
41 changes: 41 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: CI

on:
# Triggers the workflow when new PRS or commits are created on Prod
push:
branches:
- prod
pull_request:
branches:
- prod

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

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.3.4
- uses: actions/setup-node@v1
with:
node-version: 12
registry-url: https://registry.npmjs.org/

- name: Setup
run: yarn install
- name: Format
run: npm run format
- name: Fix
run: npm run lint-fix

- name: Auto committing styled files
uses: stefanzweifel/git-auto-commit-action@v4
with:
repository: 'src/'
commit_message: "Github Action: Auto styled TS files"
branch: ${{ github.ref }}
add_options: '-f'

- name: Build
run: npm run build
119 changes: 91 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,98 @@
# Workers Firebase RTDB Client
A Firebase RealTime Database Client library for use specifically with CloudFlare Workers.
Does not set or mutate global state.

# Usage:
### NPM:
``npm i @sharks-interactive/workers-firebase-rtdb-rest-client``
### CDN:
#### JSDELIVER:
``https://www.jsdelivr.com/package/npm/@sharks-interactive/workers-firebase-rtdb-rest-client``
#### UNPKG:
``https://unpkg.com/@sharks-interactive/workers-firebase-rtdb-rest-client``
### GITHUB:
``https://github.com/Sharks-Interactive/releases``
<p align='center'>
<img src="https://i.imgur.com/7svMXLi.png" />
</p>
![npm version](https://img.shields.io/npm/v/@sharks-interactive/workers-firebase-rtdb-rest-client)
![npm downloads](https://img.shields.io/npm/dm/@sharks-interactive/workers-firebase-rtdb-rest-client)
![npm types](https://img.shields.io/npm/types/@sharks-interactive/workers-firebase-rtdb-rest-client)

## How it works:
This client library is a simplified layer between your code and the Firebase REST API.
In the background it uses the Workers FETCH API to send HTTP requests to your Database.
# Workers Firebase RTDB Client
**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.

## Functionality
- Easily create, edit, update, and delete json from your database
- Easy authentication with your database and it rules
- Supports conditional requests and ETag's
- Subscribe to data change events
### All in vanilla js with _no_ dependencies and in only **KB [for minified version]
- Easily **create, edit, update, and delete** json from your database
- Easy **authentication** with your database and its rules
- Supports **conditional requests**/ETag's
- **Follows Workers guidelines**, such as not mutating global state
- **Thorough documentation** and easy to understand functions

## Usage:
```
npm i --save @sharks-interactive/workers-firebase-rtdb-rest-client
```

## Quick Examples:
#### Writing Data
```ts
import Database from '@sharks-interactive/workers-firebase-rtdb';

addEventListener('fetch', (event) => {
const db = new Database({
databaseUrl: 'https://example-db-default-rtdb.firebaseio.com/',
authentication: 'bearer ya29.[YOUR-OAUTH-TOKEN-HERE]',
tokenAuthentication: true,
});
event.respondWith(async () => {
const success = await db.update(
'user/settings',
JSON.stringify({theme: 'dark'}),
true,
new Headers(), // Optional
);

if (success) return new Response('Ok', {status: 200, statusText: 'OK'});
else return new Response('Something went wrong', {status: 500, statusText: 'Internal Server Error'});
});
});

```

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

### Read the wiki for documentation.
addEventListener('fetch', (event) => {
const db = new Database({
databaseUrl: 'https://example-db-default-rtdb.firebaseio.com/',
authentication: 'bearer ya29.[YOUR-OAUTH-TOKEN-HERE]',
tokenAuthentication: true,
});
event.respondWith(async () => {
const response = await db.read(
'user/settings',
true,
new Headers(), // Optional
);

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

## dist /
- Contains js code
```

## Features:
- **.update()** updates data with a PATCH request
- **.push()** pushes data with a POST request
- **.write()** writes data with a PUT request
- **.read()** reads data with a GET request
- **.delete()** deletes data with a DELETE request
- **.appendGetEtagHeader()** appends to a list of headers the header required to get the ETag of data in the database
- **.appendEtagIfHeader()** appends to a list of headers the header required to submit a conditional ETag request to the database
- **tokenAuthentication** supports OAUTH token authentication as well as Firebase ID authentication

## Options (Required)

| Option | Type | Description |
| ------ | ---- | ----------- |
| 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 |
| 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 |
| tokenAuthentication | boolean | Whether the ``authentication`` string is an OAUTH token or Firebase ID. See: https://firebase.google.com/docs/database/rest/auth

## How it works:
This client library is a simplified layer between your code and the Firebase REST API.
In the background it uses the Workers FETCH API to send HTTP requests to your Database.

**Read the wiki for extra documentation.**

Project created and maintained by Sharks Interactive.

Expand All @@ -42,3 +102,6 @@ Project created and maintained by Sharks Interactive.
### Code Style:
- Continious Integration will handle formatting for you
- Use ESLINT locally to catch errors pre-pr

## Acknowledgements:
**README.MD and general SDK structure, styling, practices etc, modelled after and taken from the excellent [Toucan-JS](https://github.com/robertcepa/toucan-js)**
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sharks-interactive/workers-firebase-rtdb-rest-client",
"version": "1.0.1",
"version": "1.1.0",
"description": "Firebase RTDB Client for CloudFlare Workers.",
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
Expand Down
Loading

0 comments on commit 8cdef9e

Please sign in to comment.