@timio23/directus-firebase-api-operation
v1.0.7
Published
Please enter a description for your extension
Maintainers
Readme
Directus Firebase API Operation
A Directus operation extension that exposes Firebase APIs inside Directus Flows.
Supported services
firestoremessagingstorageremoteConfig
What this extension does
This operation lets you:
- choose a Firebase service
- choose a method for that service
- provide Firebase service account credentials or environment variables
- optionally provide a resource identifier
- optionally provide a JSON payload
- return the Firebase API response back to the flow
The operation is intentionally generic so it stays simple and future-proof.
Installation
Install dependencies and build the extension:
npm install @timio23/directus-firebase-operation
Then link or load it into Directus using your normal extension workflow.
Credentials
The operation supports two credential sources:
1. Environment variables
If your Directus instance already has Firebase credentials in environment variables, you can leave the Auth JSON field empty.
Supported environment variables:
FIREBASE_SDK_AUTH_TYPEFIREBASE_SDK_AUTH_PROJECT_IDFIREBASE_SDK_AUTH_PRIVATE_KEY_IDFIREBASE_SDK_AUTH_PRIVATE_KEYFIREBASE_SDK_AUTH_CLIENT_EMAILFIREBASE_SDK_AUTH_CLIENT_IDFIREBASE_SDK_AUTH_AUTH_URIFIREBASE_SDK_AUTH_TOKEN_URIFIREBASE_SDK_AUTH_PROVIDER_X509_CERT_URLFIREBASE_SDK_AUTH_CLIENT_X509_CERT_URLFIREBASE_SDK_AUTH_UNIVERSAL_DOMAIN
2. Auth JSON field
If env vars are not present, paste the Firebase service account JSON into Auth JSON.
Example:
{
"type": "service_account",
"project_id": "my-project",
"private_key_id": "abc123",
"private_key": "-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n",
"client_email": "[email protected]",
"client_id": "1234567890",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/...",
"universe_domain": "googleapis.com"
}If both env vars and Auth JSON are supplied, the JSON values override env values.
These credentials are used to mint short-lived Google OAuth access tokens for Firebase and Google APIs.
Operation fields
Service
A dropdown for the Firebase service.
Allowed values:
firestoremessagingstorageremoteConfig
Method
A dropdown that changes based on the selected service.
Auth JSON
Optional JSON string containing Firebase service account credentials.
Resource
A generic string input used for the primary identifier required by the selected method.
Examples:
- Firestore document path
- Storage file path
Secondary Resource
Optional second identifier.
Currently used by storage methods as the bucket name.
Example:
my-project.appspot.com
Payload JSON
Optional JSON string passed to the selected Firebase Admin SDK method.
Supported methods
Firestore
get
Get a Firestore document.
Inputs
Resource: document path, for exampleusers/123Payload JSON: not used
Response
Returns the Firestore REST document mapped into a simpler JSON object with name, timestamps, and converted field values.
create
Create a Firestore document in a collection.
Inputs
Resource: collection path, for exampleusersSecondary Resource: optional document IDPayload JSON: object to write
Response
- created document object
set
Set a Firestore document.
Inputs
Resource: document pathPayload JSON: object to write
Response
- updated document object
update
Update a Firestore document.
Inputs
Resource: document pathPayload JSON: object to update
Response
- updated document object
batchGet
Fetch multiple Firestore documents.
Inputs
Payload JSON: array of document paths or{ "documents": [...] }
Example payload
[
"users/123",
"users/456"
]Response
- raw Firestore batch get response
commit
Execute a Firestore commit request.
Inputs
Payload JSON: Firestore commit request body
Response
- raw Firestore commit response
runQuery
Run a Firestore structured query.
Inputs
Payload JSON: Firestore structured query request body
Response
- raw Firestore runQuery response
delete
Delete a Firestore document.
Inputs
Resource: document pathPayload JSON: not used
Response
{
"success": true
}listCollections
List subcollections for a document.
Inputs
Resource: document pathPayload JSON: not used
Response
- Firestore
listCollectionIdsresponse object
Messaging
send
Send a single Firebase Cloud Messaging HTTP v1 message.
Inputs
Resource: not usedPayload JSON: FirebaseMessage
Example payload
{
"token": "device-token",
"notification": {
"title": "Hello",
"body": "World"
},
"data": {
"type": "example"
}
}Response
- Firebase HTTP v1 send response object, typically containing
name
Tip: set Secondary Resource to validateOnly to validate without sending.
sendValidate
Validate a single Firebase Cloud Messaging message without sending it.
Inputs
Payload JSON: FirebaseMessage
Response
- Firebase validation response object
sendEach
Send multiple Firebase Cloud Messaging messages one by one.
Inputs
Resource: not usedPayload JSON: array of FirebaseMessageobjects
Response
- object containing
successCountandresponses
Tip: set Secondary Resource to validateOnly to validate each message without sending.
Storage
list
List files in a bucket.
Inputs
Secondary Resource: bucket nameResource: optional prefix
Response
- storage objects list response
getMetadata
Get metadata for a file.
Inputs
Resource: file pathSecondary Resource: bucket namePayload JSON: not used
Response
- file metadata object
setMetadata
Set metadata for a file.
Inputs
Resource: file pathSecondary Resource: bucket namePayload JSON: metadata object
Response
- updated file metadata object
rewrite
Copy or move an object by rewriting it to a new destination.
Inputs
Resource: source file pathSecondary Resource: source bucket namePayload JSON:{ "destination": "new/path/file.ext", "destinationBucket": "optional-bucket" }
Response
- storage rewrite response
delete
Delete a file.
Inputs
Resource: file pathSecondary Resource: bucket namePayload JSON: not used
Response
{
"success": true
}Remote Config
getTemplate
Get the current Remote Config template.
Inputs
Payload JSON: not used
Response
- object containing
etagandtemplate
validateTemplate
Validate a Remote Config template without publishing it.
Inputs
Payload JSON: Remote Config template object
Response
- object containing
etagand validatedtemplate
publishTemplate
Publish a Remote Config template.
Inputs
Payload JSON: Remote Config template object
Response
- object containing
etagand publishedtemplate
rollback
Rollback Remote Config to a specific version.
Inputs
Resource: version number
Response
- Remote Config rollback response
Error behavior
The operation throws errors when:
- JSON fields are invalid
- required credentials are incomplete
- a required
Resourcevalue is missing - the chosen method does not match the selected service
- a payload shape is invalid for certain methods
- a sandbox-incompatible method is requested
Examples:
Auth JSON must contain valid JSONPayload JSON must contain valid JSONMissing Firebase credentials: ...UID is required for this Firebase call.
Notes and limitations
- This extension no longer uses
firebase-admin. - It is designed for Directus sandbox mode and uses outbound HTTP requests only.
- The dropdowns are static, not dynamically generated from Firebase APIs.
- The operation only supports the methods currently wired in
src/api.ts. - Some responses are raw Google API responses.
authwas removed because the old Admin SDK behavior is not equivalent in simple sandbox-safe REST form.- Storage signed URL generation is not included in sandbox mode.
- Messaging topic subscription methods are not included in sandbox mode.
- Some Firestore methods return raw Google API response shapes.
Secondary Resourceis overloaded for some methods to keep the form simple.
