Modules@robinpath/firebase
firebase

@robinpath/firebase

0.1.1Node.jsPublic

Firebase module for RobinPath.

Firebase

Firebase module for RobinPath.

Package: @robinpath/firebase | Category: Database | Type: Utility

Authentication

firebase.setCredentials "my-project-id" "AIzaSy..."

Call this once at the start of your script before using any other function. Credentials persist for the duration of the script execution.

Use Cases

Use the firebase module when you need to:

  • Get a Firestore document by collection and document ID -- Use firebase.getDocument to perform this operation
  • List Firestore documents in a collection -- Use firebase.listDocuments to perform this operation
  • Create a Firestore document with auto or specified ID -- Use firebase.createDocument to perform this operation
  • Update a Firestore document's fields -- Use firebase.updateDocument to perform this operation
  • Delete a Firestore document -- Use firebase.deleteDocument to perform this operation

Quick Reference

FunctionDescriptionReturns
setCredentialsSet Firebase project ID and API key for client-side REST operations{configured, projectId}
setServiceTokenSet Firebase project ID and OAuth2 access token for admin operations{configured, projectId, hasAccessToken}
getDocumentGet a Firestore document by collection and document IDDocument with _id, _path, and fields
listDocumentsList Firestore documents in a collection{documents, nextPageToken}
createDocumentCreate a Firestore document with auto or specified IDCreated document with _id and fields
updateDocumentUpdate a Firestore document's fieldsUpdated document
deleteDocumentDelete a Firestore document{deleted, collection, documentId}
queryDocumentsQuery Firestore documents with structured query (where, orderBy, limit)Array of matching documents
batchGetGet multiple Firestore documents by IDsArray of documents (or {_missing: true} for not found)
signUpCreate a new user with email and password{idToken, email, localId, refreshToken, expiresIn}
signInSign in a user with email and password{idToken, email, localId, refreshToken, expiresIn, registered}
signInAnonymouslySign in anonymously{idToken, localId, refreshToken, expiresIn}
sendPasswordResetSend a password reset email{email, sent}
verifyEmailSend an email verification to the user{email, sent}
getUserByTokenGet user data from an ID token{localId, email, emailVerified, displayName, ...}
deleteAccountDelete a user account{deleted}
rtdbGetRead data from Realtime Database at a pathData at the path
rtdbSetWrite data to Realtime Database at a path (overwrites)Written data
rtdbUpdateUpdate data at a Realtime Database path (merge)Updated data
rtdbPushPush a new child to a Realtime Database path{name} with the generated key
rtdbDeleteDelete data at a Realtime Database path{deleted, path}

Functions

setCredentials

Set Firebase project ID and API key for client-side REST operations

Module: firebase | Returns: object -- {configured, projectId}

firebase.setCredentials "my-project-id" "AIzaSy..."
ParameterTypeRequiredDescription
projectIdstringYesFirebase project ID
apiKeystringYesFirebase Web API key

setServiceToken

Set Firebase project ID and OAuth2 access token for admin operations

Module: firebase | Returns: object -- {configured, projectId, hasAccessToken}

firebase.setServiceToken "my-project-id" "ya29.a0..."
ParameterTypeRequiredDescription
projectIdstringYesFirebase project ID
accessTokenstringYesOAuth2 access token

getDocument

Get a Firestore document by collection and document ID

Module: firebase | Returns: object -- Document with _id, _path, and fields

firebase.getDocument "users" "user123"
ParameterTypeRequiredDescription
collectionstringYesCollection name
documentIdstringYesDocument ID

listDocuments

List Firestore documents in a collection

Module: firebase | Returns: object -- {documents, nextPageToken}

firebase.listDocuments "users" {"pageSize": 10}
ParameterTypeRequiredDescription
collectionstringYesCollection name
optionsobjectNo{pageSize, pageToken, orderBy}

createDocument

Create a Firestore document with auto or specified ID

Module: firebase | Returns: object -- Created document with _id and fields

firebase.createDocument "users" {"name": "Alice", "age": 30}
ParameterTypeRequiredDescription
collectionstringYesCollection name
fieldsobjectYesDocument fields
documentIdstringNoOptional document ID (auto-generated if omitted)

updateDocument

Update a Firestore document's fields

Module: firebase | Returns: object -- Updated document

firebase.updateDocument "users" "user123" {"name": "Bob"}
ParameterTypeRequiredDescription
collectionstringYesCollection name
documentIdstringYesDocument ID
fieldsobjectYesFields to update
updateMaskarrayNoSpecific field paths to update (optional)

deleteDocument

Delete a Firestore document

Module: firebase | Returns: object -- {deleted, collection, documentId}

firebase.deleteDocument "users" "user123"
ParameterTypeRequiredDescription
collectionstringYesCollection name
documentIdstringYesDocument ID

queryDocuments

Query Firestore documents with structured query (where, orderBy, limit)

Module: firebase | Returns: array -- Array of matching documents

firebase.queryDocuments "users" {"where": {"age": {">=": 18}}, "limit": 10}
ParameterTypeRequiredDescription
collectionstringYesCollection name
queryobjectYes{where, orderBy, limit, offset}

batchGet

Get multiple Firestore documents by IDs

Module: firebase | Returns: array -- Array of documents (or {_missing: true} for not found)

firebase.batchGet "users" ["user1", "user2", "user3"]
ParameterTypeRequiredDescription
collectionstringYesCollection name
documentIdsarrayYesArray of document IDs

signUp

Create a new user with email and password

Module: firebase | Returns: object -- {idToken, email, localId, refreshToken, expiresIn}

firebase.signUp "user@example.com" "securePass123"
ParameterTypeRequiredDescription
emailstringYesUser email
passwordstringYesUser password

signIn

Sign in a user with email and password

Module: firebase | Returns: object -- {idToken, email, localId, refreshToken, expiresIn, registered}

firebase.signIn "user@example.com" "securePass123"
ParameterTypeRequiredDescription
emailstringYesUser email
passwordstringYesUser password

signInAnonymously

Sign in anonymously

Module: firebase | Returns: object -- {idToken, localId, refreshToken, expiresIn}

firebase.signInAnonymously
ParameterTypeRequiredDescription
(none)NoCall with no arguments

sendPasswordReset

Send a password reset email

Module: firebase | Returns: object -- {email, sent}

firebase.sendPasswordReset "user@example.com"
ParameterTypeRequiredDescription
emailstringYesUser email

verifyEmail

Send an email verification to the user

Module: firebase | Returns: object -- {email, sent}

firebase.verifyEmail "eyJhbGciOi..."
ParameterTypeRequiredDescription
idTokenstringYesUser ID token from sign in

getUserByToken

Get user data from an ID token

Module: firebase | Returns: object -- {localId, email, emailVerified, displayName, ...}

firebase.getUserByToken "eyJhbGciOi..."
ParameterTypeRequiredDescription
idTokenstringYesUser ID token from sign in

deleteAccount

Delete a user account

Module: firebase | Returns: object -- {deleted}

firebase.deleteAccount "eyJhbGciOi..."
ParameterTypeRequiredDescription
idTokenstringYesUser ID token from sign in

rtdbGet

Read data from Realtime Database at a path

Module: firebase | Returns: any -- Data at the path

firebase.rtdbGet "users/user123"
ParameterTypeRequiredDescription
pathstringYesDatabase path

rtdbSet

Write data to Realtime Database at a path (overwrites)

Module: firebase | Returns: any -- Written data

firebase.rtdbSet "users/user123" {"name": "Alice", "age": 30}
ParameterTypeRequiredDescription
pathstringYesDatabase path
dataanyYesData to write

rtdbUpdate

Update data at a Realtime Database path (merge)

Module: firebase | Returns: any -- Updated data

firebase.rtdbUpdate "users/user123" {"age": 31}
ParameterTypeRequiredDescription
pathstringYesDatabase path
dataobjectYesFields to update

rtdbPush

Push a new child to a Realtime Database path

Module: firebase | Returns: object -- {name} with the generated key

firebase.rtdbPush "messages" {"text": "Hello", "sender": "Alice"}
ParameterTypeRequiredDescription
pathstringYesDatabase path
dataanyYesData for the new child

rtdbDelete

Delete data at a Realtime Database path

Module: firebase | Returns: object -- {deleted, path}

firebase.rtdbDelete "users/user123"
ParameterTypeRequiredDescription
pathstringYesDatabase path

Error Handling

All functions throw on failure. Common errors:

ErrorCause
Firebase not configured. Call firebase.setCredentials or firebase.setServiceToken first.Check the error message for details
API key not set. Call firebase.setCredentials with projectId and apiKey.Check the error message for details
Access token not set. Call firebase.setServiceToken with projectId and accessToken.Check the error message for details
Firebase API error (${response.status}): ${errMsg}Check the error message for details
projectId is requiredCheck the error message for details
apiKey is requiredCheck the error message for details
accessToken is requiredCheck the error message for details
collection and documentId are requiredCheck the error message for details
@desc "Get document and validate result"
do
  set $result as firebase.getDocument "users" "user123"
  if $result != null
    print "Success"
  else
    print "No result"
  end
enddo

Recipes

1. List and iterate Document

Retrieve all items and loop through them.

@desc "Setup authentication"
do
  firebase.setCredentials $token
enddo

@desc "Get document and iterate results"
do
  set $result as firebase.getDocument "users" "user123"
  each $item in $result
    print $item
  end
enddo

2. Create a new item with createDocument

Create a new resource and capture the result.

@desc "Setup authentication"
do
  firebase.setCredentials $token
enddo

@desc "Create document"
do
  set $result as firebase.createDocument "users" {"name": "Alice", "age": 30}
  print "Created: " + $result
enddo

3. Create and update workflow

Create an item and then update it.

@desc "Setup authentication"
do
  firebase.setCredentials $token
enddo

@desc "Create document and update document"
do
  set $created as firebase.createDocument "users" {"name": "Alice", "age": 30}
  # Update the created item
  firebase.updateDocument "users" "user123" {"name": "Bob"}
enddo

4. Check before creating

List existing items and only create if needed.

@desc "Setup authentication"
do
  firebase.setCredentials $token
enddo

@desc "Get document and create document"
do
  set $existing as firebase.getDocument "users" "user123"
  if $existing == null
    firebase.createDocument "users" {"name": "Alice", "age": 30}
    print "Item created"
  else
    print "Item already exists"
  end
enddo

5. Multi-step Firebase workflow

Chain multiple firebase operations together.

@desc "Setup authentication"
do
  firebase.setCredentials $token
enddo

@desc "Get document, list documents, and more"
do
  set $r_getDocument as firebase.getDocument "users" "user123"
  set $r_listDocuments as firebase.listDocuments "users" {"pageSize": 10}
  set $r_createDocument as firebase.createDocument "users" {"name": "Alice", "age": 30}
  print "All operations complete"
enddo

6. Safe getDocument with validation

Check results before proceeding.

@desc "Setup authentication"
do
  firebase.setCredentials $token
enddo

@desc "Get document and validate result"
do
  set $result as firebase.getDocument "users" "user123"
  if $result != null
    print "Success: " + $result
  else
    print "Operation returned no data"
  end
enddo

Related Modules

  • mysql -- MySQL module for complementary functionality
  • postgres -- PostgreSQL module for complementary functionality
  • mongo -- Mongo module for complementary functionality
  • redis -- Redis module for complementary functionality
  • supabase -- Supabase module for complementary functionality

Versions (1)

VersionTagPublished
0.1.1latest1 months ago
Install
$ robinpath add @robinpath/firebase

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.1
LicenseMIT
Unpacked Size9.5 KB
Versions1
Weekly Downloads26
Total Downloads26
Stars0
Last Publish1 months ago
Created1 months ago

Category

data