codelesslyCloudServices function

Services codelesslyCloudServices({
  1. required String projectId,
  2. required FirebaseFirestore firestore,
  3. FirebaseAuth? auth,
  4. FirebaseStorage? storage,
  5. FirebaseFunctions? functions,
  6. LocalStorage? localStorage,
  7. TestStoreMode testStore = TestStoreMode.auto,
})

The Services of project projectId on Firebase: its cloud data on firestore (under data/{projectId}, with the project's data rules), app user accounts on auth, cloud files on storage and managed paywalls on functions (codelesslyPaywalls), each only when given. localStorage is where the app keeps storage values (default: memory; PreferencesLocalStorage keeps them between runs) and the store purchases waiting for verification. testStore is when paywalls run on the test store instead (Services.testStore: by default, on the web for a paywall published with "testStore": true).

Everything else keeps Services' defaults.

Implementation

Services codelesslyCloudServices({
  required String projectId,
  required FirebaseFirestore firestore,
  FirebaseAuth? auth,
  FirebaseStorage? storage,
  FirebaseFunctions? functions,
  LocalStorage? localStorage,
  TestStoreMode testStore = TestStoreMode.auto,
}) {
  final root = firestoreRoot(projectId);
  final local = localStorage ?? MemoryLocalStorage();
  final managed = functions == null ? null : codelesslyPaywalls(projectId: projectId, functions: functions, storage: local);
  final users = auth == null ? null : FirebaseAuthService(auth, storage: local);
  final backend = FirestoreDocumentBackend(firestore);
  // The role in the user's profile (users/{uid}), as the rules read it.
  final audience = users == null
      ? null
      : AuthAudience(
          users: users.userChanges,
          currentUser: () => users.currentUser,
          profile: (uid) => backend.watch('$root/${AuthProfiles.collection}', uid),
        );
  final cloud = BackendCloudDatabase(
    backend: backend,
    root: root,
    rulesSource: firestoreDataRules(firestore, projectId),
    userId: () => auth?.currentUser?.uid,
    // Live owner-only and audience queries follow sign in and out, and a
    // change of the user's role.
    userChanges: audience?.changes,
    audience: audience?.call,
  );
  return Services(
    storage: local,
    paywalls: managed?.paywalls,
    purchases: managed?.purchases,
    testStore: testStore,
    auth: users,
    cloud: cloud,
    files: storage == null ? null : FirebaseFileStorage(storage, root: root),
  );
}