Skip to content

Add typed app environment runtime config#131

Merged
AhmedNMahran merged 1 commit intomainfrom
enhance-environment-setup
Mar 10, 2026
Merged

Add typed app environment runtime config#131
AhmedNMahran merged 1 commit intomainfrom
enhance-environment-setup

Conversation

@AhmedNMahran
Copy link
Collaborator

Summary

This refactors environment selection so mobile-sync can be published once and configured at runtime for either prelive or production.

What changed

  • added a typed top-level AppEnvironment API in sync-pipelines
  • made AppEnvironment drive both auth and sync defaults together
  • kept the lower-level override path for custom endpoints and tests
  • refactored auth config to use runtime environment selection instead of relying on BuildKonfig.IS_DEBUG
  • updated Android and iOS demo integration to use the new app-level environment API
  • added tests for auth environment mapping and app environment sync endpoint mapping
  • updated README usage examples and environment guidance

Why

Before this change:

  • auth environment was effectively fixed at publish time through buildkonfig.flavor
  • sync environment was runtime-configurable through SynchronizationEnvironment
  • that mismatch meant one published artifact could not cleanly support both prelive and production auth
  • consumers also had to reason about auth and sync environment knobs separately, which made mixed-environment misconfiguration possible

With this change:

  • a single published artifact can target either environment at runtime
  • AppEnvironment.PRELIVE forces both auth and sync to prelive
  • AppEnvironment.PRODUCTION forces both auth and sync to production
  • advanced consumers can still use the explicit SynchronizationEnvironment + AuthEnvironment overload if needed

API

Primary API:

val graph = SharedDependencyGraph.init(
    driverFactory = DriverFactory(context = applicationContext),
    appEnvironment = AppEnvironment.PRELIVE
)

Swift:

graph = SharedDependencyGraph.shared.doInit(
    driverFactory: driverFactory,
    appEnvironment: AppEnvironment.prelive
)

Advanced override path remains available:

val graph = SharedDependencyGraph.init(
    driverFactory = DriverFactory(context = applicationContext),
    environment = SynchronizationEnvironment(
        endPointURL = "https://custom-sync.example.com/auth"
    ),
    authEnvironment = AuthEnvironment.PRELIVE
)

Environment behavior
AppEnvironment keeps auth and sync aligned by default:

PRELIVE

  • auth: https://prelive-oauth2.quran.foundation
  • sync: https://apis-prelive.quran.foundation/auth

PRODUCTION

  • auth: https://oauth2.quran.foundation
  • sync: https://apis.quran.foundation/auth
  • buildkonfig.flavor is now only the fallback default when the app does not pass an explicit app environment.

Validation
Ran successfully:

./gradlew \
  :auth:allTests \
  :sync-pipelines:allTests \
  :sync-pipelines:compileKotlinJvm \
  :sync-pipelines:compileKotlinIosSimulatorArm64 \
  --no-configuration-cache \
  --stacktrace
xcodebuild \
  -project demo/apple/QuranSyncDemo/QuranSyncDemo.xcodeproj \
  -scheme QuranSyncDemo \
  -destination 'generic/platform=iOS Simulator' \
  CODE_SIGNING_ALLOWED=NO \
  build

Impact
This is the right shape for downstream consumers such as quran_android and quran-ios:

  • one artifact
  • one app-level environment selection
  • no need to republish separate prelive/prod auth variants
  • lower risk of auth/sync environment drift

@AhmedNMahran AhmedNMahran self-assigned this Mar 10, 2026
@AhmedNMahran AhmedNMahran merged commit d0a3479 into main Mar 10, 2026
1 check passed
@AhmedNMahran AhmedNMahran deleted the enhance-environment-setup branch March 10, 2026 05:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant