19#ifndef CPPREALM_APP_HPP
20#define CPPREALM_APP_HPP
22#include <cpprealm/bson.hpp>
23#include <cpprealm/db.hpp>
25#include <cpprealm/internal/bridge/realm.hpp>
26#include <cpprealm/internal/bridge/sync_error.hpp>
27#include <cpprealm/internal/bridge/sync_manager.hpp>
28#include <cpprealm/internal/bridge/sync_session.hpp>
29#include <cpprealm/internal/bridge/utils.hpp>
30#include <cpprealm/networking/http.hpp>
31#include <cpprealm/networking/websocket.hpp>
38 using proxy_config = sync_config::proxy_config;
39 using sync_session = internal::bridge::sync_session;
46 namespace internal::bridge {
62 [[nodiscard]] std::string_view message()
const;
64 [[nodiscard]] std::string_view link_to_server_logs()
const;
66 [[nodiscard]]
bool is_json_error()
const;
68 [[nodiscard]]
bool is_service_error()
const;
70 [[nodiscard]]
bool is_http_error()
const;
72 [[nodiscard]]
bool is_custom_error()
const;
74 [[nodiscard]]
bool is_client_error()
const;
76#ifdef CPPREALM_HAVE_GENERATED_BRIDGE_TYPES
77 internal::bridge::storage::AppError m_error[1];
79 std::shared_ptr<realm::app::AppError> m_error;
96 user& operator=(
const user&) =
default;
98 explicit user(std::shared_ptr<app::User>
user);
99 bool is_logged_in()
const;
139 [[nodiscard]]
db_config flexible_sync_configuration()
const;
148 void log_out(std::function<
void(std::optional<app_error>)>&& callback)
const;
150 [[nodiscard]] std::future<void> log_out()
const;
153 [[deprecated(
"Replaced by `get_custom_data()`. This method will be removed in a future release.")]]
154 [[nodiscard]] std::optional<std::string> custom_data()
const;
160 [[nodiscard]] std::optional<bsoncxx::document>
get_custom_data()
const;
170 [[deprecated(
"This function is deprecated and will replaced by the BSON based call_function API.")]]
171 void call_function(
const std::string& name,
const std::string& args_ejson,
172 std::function<
void(std::optional<std::string>, std::optional<app_error>)> callback)
const;
182 [[deprecated(
"This function is deprecated and will replaced by the BSON based call_function API.")]]
183 [[nodiscard]] std::future<std::optional<std::string>>
call_function(
const std::string& name,
184 const std::string& args_ejson)
const;
194 void call_function(
const std::string& name,
const std::vector<bsoncxx>& args_bson,
195 std::function<
void(std::optional<bsoncxx>, std::optional<app_error>)> callback)
const;
204 [[nodiscard]] std::future<std::optional<bsoncxx>>
call_function(
const std::string& name,
const std::vector<bsoncxx>& args_bson)
const;
216 std::shared_ptr<app::User> m_user;
219bool operator==(
const user& lhs,
const user& rhs);
220bool operator!=(
const user& lhs,
const user& rhs);
223 struct AppCredentials;
242 std::optional<std::string>
path;
243 [[deprecated(
"Network options must be supplied via custom network implementations.")]]
244 std::optional<std::map<std::string, std::string>> custom_http_headers;
249 [[deprecated(
"Network options must be supplied via custom network implementations.")]]
250 std::optional<sync_config::proxy_config> proxy_configuration;
270 static credentials api_key(
const std::string& key);
271 static credentials facebook(
const std::string& access_token);
272 static credentials apple(
const std::string& id_token);
273 static credentials google_auth_code(
const std::string& auth_code);
274 static credentials google_id_token(
const std::string& id_token);
275 static credentials custom(
const std::string& token);
276 static credentials username_password(
const std::string& username,
const std::string& password);
277 static credentials function(
const std::string& payload);
286 operator app::AppCredentials()
const;
289#ifdef CPPREALM_HAVE_GENERATED_BRIDGE_TYPES
290 internal::bridge::storage::AppCredentials m_credentials[1];
292 std::shared_ptr<app::AppCredentials> m_credentials;
296 std::future<void> register_user(
const std::string& username,
const std::string& password);
300 [[nodiscard]] std::optional<user> get_current_user()
const;
301 void clear_cached_apps();
302 std::optional<App> get_cached_app(
const std::string& app_id,
const std::optional<std::string>& base_url);
303 std::string get_base_url()
const;
305#ifdef REALM_ENABLE_EXPERIMENTAL
314 [[nodiscard]] std::future<void> update_base_url(std::string base_url)
const;
319 std::shared_ptr<app::App> m_app;
320 App(std::shared_ptr<app::App>&& a) : m_app(std::move(a)) { }
bool enable_caching
Caches an App and its configuration for a given App ID. On by default.
Definition: app.hpp:248
std::optional< std::string > base_url
A custom base URL to request against. If not set or set to nil, the default base url for app services...
Definition: app.hpp:240
std::optional< std::string > path
Custom location for Realm files.
Definition: app.hpp:242
std::optional< std::array< char, 64 > > metadata_encryption_key
Custom encryption key for the metadata Realm.
Definition: app.hpp:246
std::shared_ptr< networking::sync_socket_provider > sync_socket_provider
Definition: app.hpp:261
std::shared_ptr< networking::http_transport_client > http_transport_client
Definition: app.hpp:257
std::string app_id
The App ID for your Atlas Device Sync Application.
Definition: app.hpp:238
Definition: sync_manager.hpp:33
std::string refresh_token() const
Definition: app.cpp:181
void call_function(const std::string &name, const std::string &args_ejson, std::function< void(std::optional< std::string >, std::optional< app_error >)> callback) const
Definition: app.cpp:245
std::optional< bsoncxx::document > get_custom_data() const
Definition: app.cpp:236
state
Definition: app.hpp:104
std::string access_token() const
Definition: app.cpp:170
std::future< void > refresh_custom_user_data() const
Definition: app.cpp:311
std::string identifier() const
Definition: app.cpp:151