Expand description
§Firebase Installations Module
The Installations module issues Firebase Installation IDs (FIDs) and scoped auth tokens used by other Firebase services. This Rust port mirrors the public JS API while speaking directly to the official Firebase Installations REST endpoints.
§Porting status
- installations 45%
[##### ]
==As of October 20th, 2025==
Prompt: Compare the original JS/Typescript files in ./packages/installations and the ported files in Rust in ./src/installations, and give me an estimated guess, in percentage, of how much of the features/code of the Firebase JS SDK has been ported to Rust
I’m reviewing the Rust and JS implementations to compare their feature coverage. The Rust code now performs real Installation registration and token refresh via the REST API, replacing the previous stub. Persistence, concurrency coordination, and secondary APIs (delete, onIdChange) still need to be ported. Given the new network integration, coverage increases from ~5 % to roughly 15 %. I’ll reference specific file paths and lines to support this analysis and highlight the biggest gaps before crafting the final summary.
Coverage is around 35 %.
- Network registration and token refresh mirror the JS helpers (
packages/installations/src/functions/create-installation-request.ts,generate-auth-token-request.ts) through a blockingreqwestclient (src/installations/rest.rs:1). get_idandget_tokencall through the REST client and cache the resulting FID/token pair like the JSgetInstallationEntryflow (src/installations/api.rs:23).- Configuration extraction (
src/installations/config.rs:6) validates required app options, similar to JSextractAppConfig. - Installation entries (FID + refresh/auth tokens) persist to disk between runs using the default file-backed cache (
src/installations/persistence.rs:1). delete_installationsmirrors the JS delete flow, issuing the REST delete call and clearing cached state (src/installations/api.rs:200).- onIdChange callbacks, IndexedDB-style concurrency guards, richer retry/backoff policies, and emulator/diagnostics features remain outstanding.
§Quick Start Example
use firebase_rs_sdk::app::{initialize_app, FirebaseAppSettings, FirebaseOptions};
use firebase_rs_sdk::installations::{get_installations, InstallationToken};
#[tokio::main(flavor = "current_thread")]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let app = initialize_app(
FirebaseOptions {
api_key: Some("AIza...".into()),
project_id: Some("my-project".into()),
app_id: Some("1:123:web:abc".into()),
..Default::default()
},
Some(FirebaseAppSettings::default()),
).await?;
let installations = get_installations(Some(app.clone()))?;
let fid = installations.get_id().await?;
let InstallationToken { token, expires_at } = installations.get_token(false).await?;
println!("FID={fid}, token={token}, expires={expires_at:?}");
Ok(())
}§Implemented
- Component registration exposing
get_installationswith per-app caching (src/installations/api.rs:146). - App config extraction and validation mirroring the JS helper (
src/installations/config.rs:6). - Async REST client with a native
reqwestimplementation and a WASMfetchbackend behind thewasm-webfeature (src/installations/rest/native.rs:1,src/installations/rest/wasm.rs:1). Installationspublic/internal APIs are now async, performing registration, token refresh, and delete operations without blocking (src/installations/api.rs:112).- File-backed persistence for native targets and IndexedDB + BroadcastChannel-backed persistence for wasm builds, including wasm-bindgen tests that verify round-trips when
wasm-webandexperimental-indexed-dbare enabled (src/installations/persistence.rs). - Internal helper that surfaces the full installation entry (FID, refresh token, auth token) for other modules such as Messaging (
src/installations/api.rs:185). - Unit tests covering config validation, async REST flows, persistence round-trips, delete behaviour, and service behaviour for forced refreshes (
src/installations/rest/tests.rs:1,src/installations/api.rs:472,src/installations/persistence.rs:80). - Private
installations-internalcomponent provides sharedget_id/get_tokenhelpers (src/installations/api.rs:210). Installations::on_id_changeexposes the JSonIdChangelistener semantics, returning an unsubscribe handle and notifying when new Installation IDs are registered (src/installations/api.rs).
§WASM Notes
- Enable the
wasm-webfeature to pull in the fetch-based REST client and browser-specific glue. - Add
experimental-indexed-dbalongsidewasm-webto persist installations to IndexedDB; without it, wasm builds fall back to in-memory persistence while keeping the same API surface. - IndexedDB persistence now has wasm-bindgen tests that validate round-trip storage and BroadcastChannel propagation (
src/installations/persistence.rs).
§Still to do
- Add concurrency coordination and migrations for the persistence layer (IndexedDB-style pending markers, multi-process guards).
- Implement additional JS parity APIs (heartbeat headers, emulator tooling, diagnostics hooks) and surface richer telemetry for downstream modules.
- Add ETag handling, heartbeat/X-Firebase-Client integration, and exponential backoff policies for REST requests.
- Provide emulator support, diagnostics logging, and richer error mapping from REST responses.
- Expand integration tests and shared fixtures to cover retry paths and error propagation.
§Next steps - Detailed completion plan
- Document & test the shared messaging flow
- Add an example (and wasm doc snippets) that shows messaging awaiting
InstallationsInternal::get_installation_entrybefore contacting FCM. - Port the key
token-managertests from the JS SDK to ensure retry/backoff behaviour matches expectations.
- Add an example (and wasm doc snippets) that shows messaging awaiting
- Strengthen persistence coordination
- Extend the new pending-registration markers with structured telemetry/backoff so repeated failures remain observable.
- Add retry/backoff policies on IndexedDB opening failures and consider exposing metrics to consumers.
- Follow-on parity work
- Revisit JS parity items (heartbeat headers, emulator tooling) once the messaging integration settles.
- Expand structured logging and diagnostics so native and wasm targets surface actionable errors to consuming modules.
Structs§
- AppConfig
- Extracted configuration required to contact the Firebase Installations REST API.
- File
Persistence - Installation
Entry Data - Public data describing a cached Firebase Installation entry.
- Installation
Token - Represents an authentication token produced by the Firebase Installations service.
- Installations
- Installations
Error - Installations
Internal - Persisted
Auth Token - Persisted
Installation - Registered
Installation
Enums§
Constants§
Traits§
Functions§
- delete_
installations - Deletes the cached Firebase Installation for the given instance.
- extract_
app_ config - Mirrors the JavaScript helper
extractAppConfigfrompackages/installations/src/helpers/extract-app-config.ts. - get_
installations - get_
installations_ internal - internal_
error - invalid_
argument - register_
installations_ component - request_
failed