1use origin_accounts::AccountService;
2use origin_connector::ConnectorRegistry;
3use origin_domain::{AppError, Clock, Result};
4use origin_events::EventBus;
5use origin_http::HttpClient;
6use origin_jobs::Jobs;
7use origin_platform::{NotificationService, Opener};
8use origin_secrets::SecretStore;
9use origin_settings::Settings;
10use origin_storage::{Cache, Storage};
11use origin_sync::SyncEngine;
12use std::sync::Arc;
13
14#[derive(Debug, Clone)]
22pub struct Platform {
23 pub clock: Arc<dyn Clock>,
24 pub events: EventBus,
25 pub storage: Arc<dyn Storage>,
26 pub cache: Cache,
27 pub secrets: Arc<dyn SecretStore>,
28 pub settings: Settings,
29 pub notifications: Arc<dyn NotificationService>,
30 pub jobs: Jobs,
32 pub sync: SyncEngine,
34 pub accounts: AccountService,
36 pub connectors: ConnectorRegistry,
38 pub opener: Option<Arc<dyn Opener>>,
40 pub http: Option<Arc<dyn HttpClient>>,
42}
43
44impl Platform {
45 pub fn http(&self) -> Result<Arc<dyn HttpClient>> {
50 self.http.clone().ok_or_else(|| {
51 AppError::configuration(
52 "this application has no http client — add `.http_client(...)` to its \
53 composition root",
54 )
55 })
56 }
57
58 pub fn opener(&self) -> Result<Arc<dyn Opener>> {
60 self.opener.clone().ok_or_else(|| {
61 AppError::Permission("this application cannot open external urls".to_owned())
62 })
63 }
64}