firebase library
Codelessly on Firebase. The rest of the SDK never imports Firebase.
A project token is all an app needs (codelesslyWithToken): it opens Codelessly's Firebase project as a secondary app (codelesslyFirebaseApp, CodelesslyFirebaseOptions), authenticates the token and reads the publish from Cloud Firestore, with live updates.
import 'package:codelessly_sdk/codelessly_sdk.dart';
import 'package:codelessly_sdk/firebase.dart';
final codelessly = await codelesslyWithToken('<project token>');
runApp(MaterialApp(home: CodelesslyWidget(codelessly: codelessly)));
The pieces, for apps that assemble them themselves (another Firebase project, their own auth): the published app (FirestorePublishLoader; codelesslyOnFirebase sets a Codelessly up on it), the project's access (FirebaseProjectAuth), app user accounts (FirebaseAuthService), cloud data (FirestoreDocumentBackend), cloud files (FirebaseFileStorage) and the paywall server (FirebasePaywallBackend; codelesslyPaywalls for managed paywalls). codelesslyCloudServices builds the services of a project:
final app = await codelesslyFirebaseApp();
final services = codelesslyCloudServices(
projectId: projectId,
firestore: FirebaseFirestore.instanceFor(app: app),
auth: FirebaseAuth.instanceFor(app: app),
storage: FirebaseStorage.instanceFor(app: app),
);
Classes
- CodelesslyFirebaseOptions
-
The client options of Codelessly's Firebase project (
codeless-app), where the Codelessly Editor publishes. - Firebase
- The entry point for accessing Firebase.
- FirebaseApp
- Represents a single Firebase app instance.
- FirebaseAuth
- The entry point of the Firebase Authentication SDK.
- FirebaseAuthService
- AuthService on Firebase Auth. With anonymousWhenSignedOut (the SDK reads published data as an anonymous user), signing out or deleting the account signs in anonymously again; anonymous users read as signed out.
- FirebaseFileStorage
-
CloudFileStorage on Firebase Storage, under root (the project's
folder,
data/{projectId}, as for its cloud data). A path can't leave root; full URLs (https://,gs://) address files directly. - FirebaseFirestore
- The entry point for accessing a FirebaseFirestore.
- FirebaseFunctions
- The entry point for accessing FirebaseFunctions.
- FirebaseOptions
- The options used to configure a Firebase app.
- FirebasePaywallBackend
- PaywallBackend on the Codelessly backend's callable functions. A resolved placement points at a published layout, never an editor draft.
- FirebaseProjectAuth
- ProjectAuth on Firebase Auth and the Codelessly backend.
- FirebaseStorage
- The entrypoint for FirebaseStorage.
- FirestoreDocumentBackend
- A DocumentBackend on Cloud Firestore.
- FirestoreManagedComponentSource
- A ManagedComponentSource reading firestore (Codelessly's Firebase app, where the editor publishes).
- FirestorePublishLoader
-
A LivePublishLoader on Cloud Firestore: the publish model is the
document PublishSource.modelPath (
publish/{projectId};publish_preview/...for the editor's preview), each layout PublishSource.layoutPath (.../layouts/{layoutId}), each component PublishSource.componentPath (.../components/{type}). watchModel follows the model document: a republished component changes its entry there. - ProjectAuthConfig
- What FirebaseProjectAuth authenticates with.
Enums
- DataSource
- Which published data an app reads.
Constants
- kCodelesslyFirebaseAppName → const String
- The name of the Firebase app codelesslyFirebaseApp creates. It is a secondary app: an app's own default Firebase app (if it has one) is left alone.
Functions
-
activeGrants(
Iterable< (String, Map< grants, int now) → (Set<String, Object?> )>String> , int?) -
The active entitlements in
grantsatnow: active, with a futurevalidUntil(milliseconds); and the soonest expiry, to check again at. -
appUserOf(
User? user) → AppUser? -
useras an AppUser. -
authMessageFor(
Object error) → String -
A readable message for a Firebase Auth
error. -
codelesslyCloudServices(
{required String projectId, required FirebaseFirestore firestore, FirebaseAuth? auth, FirebaseStorage? storage, FirebaseFunctions? functions, LocalStorage? localStorage, TestStoreMode testStore = TestStoreMode.auto}) → Services -
The Services of project
projectIdon Firebase: its cloud data onfirestore(underdata/{projectId}, with the project's data rules), app user accounts onauth, cloud files onstorageand managed paywalls onfunctions(codelesslyPaywalls), each only when given.localStorageis where the app keepsstoragevalues (default: memory; PreferencesLocalStorage keeps them between runs) and the store purchases waiting for verification.testStoreis when paywalls run on the test store instead (Services.testStore: by default, on the web for a paywall published with"testStore": true). -
codelesslyFirebaseApp(
{String name = kCodelesslyFirebaseAppName, FirebaseOptions? options}) → Future< FirebaseApp> -
The Firebase app for Codelessly's backend: the app named
namewhen it exists, else a new one withoptions(default: CodelesslyFirebaseOptions.currentPlatform). Safe to call again. -
codelesslyOnFirebase(
{required FirebaseFirestore firestore, FirebaseAuth? auth, CodelesslyConfig config = const CodelesslyConfig(), ProjectAuth? projectAuth, PublishCache? cache, FontFetcher? fonts, Map< String, Object?> data = const {}}) → Codelessly -
A Codelessly reading its publish from Firestore (
firestore: the Firebase app the project publishes to): -
codelesslyPaywalls(
{required String projectId, required FirebaseFunctions functions, LocalStorage? storage, KeyValueCache? cache, PurchaseService purchases(PurchaseVerifier verify)?, TargetPlatform? platform}) → ({PaywallRuntime paywalls, PurchaseService purchases}) -
Codelessly-managed paywalls of project
projectId, forServices(paywalls:, purchases:): placements resolved by Codelessly's paywall server (FirebasePaywallBackend onfunctions), App Store and Google Play purchases (StorePurchaseService, connected to the store when a paywall first needs it) journaled instorageand verified by that server before they grant an entitlement. -
codelesslyWithToken(
String authToken, {CodelesslyConfig config = const CodelesslyConfig(), bool cloudServices = false, TestStoreMode testStore = TestStoreMode.auto, FirebaseApp? app, FirebaseFirestore? firestore, FirebaseAuth? auth, FirebaseStorage? storage, ProjectAuth? projectAuth, String? functionsBaseUrl, PublishCache? cache, FontFetcher? fonts, Map< String, Object?> data = const {}}) → Future<Codelessly> -
A Codelessly for the project
authTokennames, on Codelessly's Firebase, with live updates: all an app needs is its project token. -
describeCloudError(
Object? error) → String -
A readable message for a cloud
error, with Firestore's code. -
ensureFirestoreRoot(
FirebaseFirestore firestore, String root, String projectId) → Future< void> -
Creates the project's root document (
root) when missing. -
firestoreDataRules(
FirebaseFirestore firestore, String projectId) → Stream< DataRules> -
The project's data rules (
data_rules/{projectId}), now and on every change. -
firestoreRoot(
String projectId, {DataSource source = DataSource.publish}) → String -
The document a project's cloud data is under (
data/{projectId}). -
fromFirestore(
Object? value) → Object? -
Firestore values as the SDK's: timestamps as UTC DateTimes, blobs as
bytes, references as their path, geo points as
{latitude, longitude}. -
idTokenClaims(
IdTokenResult? result, {bool fromToken = false}) → Map< String, Object?> -
The claims of
result: itsclaims, or (where the platform doesn't give them, as on Windows) its token's payload. -
isMissingIndexError(
Object? error) → bool -
Whether
erroris Firestore saying a query needs an index it lacks. -
storedJson(
Map< String, Object?> data) → Map<String, Object?> - A Firestore document's data as plain JSON: timestamps as milliseconds since the epoch (what the publish JSON stores), blobs as bytes, references as their path.
-
toFirestore(
Object? value) → Object? -
The SDK's values as Firestore's: FieldOps as
FieldValues, bytes as blobs. -
watchEntitlementGrants(
FirebaseFirestore firestore, String projectId, String uid, {DateTime now() = DateTime.now}) → Stream< Set< String> > -
User
uid's verified entitlements from Firestore (projects/{projectId}/entitlements/{uid}/grants), now, on every change and as grants expire; none on errors (fail closed).