use super::*; impl SpacetimeClient { pub async fn get_creation_entry_config( &self, ) -> Result { self.call_after_connect(move |connection, sender| { connection .procedures() .get_creation_entry_config_then(move |_, result| { let mapped = result .map_err(SpacetimeClientError::from_sdk_error) .and_then(map_creation_entry_config_procedure_result); send_once(&sender, mapped); }); }) .await } pub async fn upsert_creation_entry_type_config( &self, input: module_runtime::CreationEntryTypeAdminUpsertInput, ) -> Result { let procedure_input: CreationEntryTypeAdminUpsertInput = input.into(); self.call_after_connect(move |connection, sender| { connection .procedures() .upsert_creation_entry_type_config_then(procedure_input, move |_, result| { let mapped = result .map_err(SpacetimeClientError::from_sdk_error) .and_then(map_creation_entry_config_procedure_result); send_once(&sender, mapped); }); }) .await } pub async fn get_runtime_settings( &self, user_id: String, ) -> Result { let procedure_input = build_runtime_setting_get_input(user_id) .map_err(SpacetimeClientError::validation_failed)? .into(); self.call_after_connect(move |connection, sender| { connection.procedures().get_runtime_setting_or_default_then( procedure_input, move |_, result| { let mapped = result .map_err(SpacetimeClientError::from_sdk_error) .and_then(map_runtime_setting_procedure_result); send_once(&sender, mapped); }, ); }) .await } pub async fn list_platform_browse_history( &self, user_id: String, ) -> Result, SpacetimeClientError> { let procedure_input = build_runtime_browse_history_list_input(user_id) .map_err(SpacetimeClientError::validation_failed)? .into(); self.call_after_connect(move |connection, sender| { connection.procedures().list_platform_browse_history_then( procedure_input, move |_, result| { let mapped = result .map_err(SpacetimeClientError::from_sdk_error) .and_then(map_runtime_browse_history_procedure_result); send_once(&sender, mapped); }, ); }) .await } pub async fn get_profile_dashboard( &self, user_id: String, ) -> Result { let procedure_input = build_runtime_profile_dashboard_get_input(user_id) .map_err(SpacetimeClientError::validation_failed)? .into(); self.call_after_connect(move |connection, sender| { connection.procedures().get_profile_dashboard_then( procedure_input, move |_, result| { let mapped = result .map_err(SpacetimeClientError::from_sdk_error) .and_then(map_runtime_profile_dashboard_procedure_result); send_once(&sender, mapped); }, ); }) .await } pub async fn list_profile_wallet_ledger( &self, user_id: String, ) -> Result, SpacetimeClientError> { let procedure_input = build_runtime_profile_wallet_ledger_list_input(user_id) .map_err(SpacetimeClientError::validation_failed)? .into(); self.call_after_connect(move |connection, sender| { connection.procedures().list_profile_wallet_ledger_then( procedure_input, move |_, result| { let mapped = result .map_err(SpacetimeClientError::from_sdk_error) .and_then(map_runtime_profile_wallet_ledger_procedure_result); send_once(&sender, mapped); }, ); }) .await } pub async fn grant_new_user_registration_wallet_reward( &self, user_id: String, ) -> Result { let procedure_input = build_runtime_profile_dashboard_get_input(user_id) .map_err(|error| SpacetimeClientError::Runtime(error.to_string()))? .into(); self.call_after_connect(move |connection, sender| { connection .procedures() .grant_new_user_registration_wallet_reward_then( procedure_input, move |_, result| { let mapped = result .map_err(|error| SpacetimeClientError::Procedure(error.to_string())) .and_then(map_runtime_profile_wallet_adjustment_procedure_result); send_once(&sender, mapped); }, ); }) .await } pub async fn consume_profile_wallet_points( &self, user_id: String, amount: u64, ledger_id: String, created_at_micros: i64, ) -> Result { let procedure_input = build_runtime_profile_wallet_adjustment_input( user_id, amount, ledger_id, created_at_micros, ) .map_err(SpacetimeClientError::validation_failed)? .into(); self.call_after_connect(move |connection, sender| { connection .procedures() .consume_profile_wallet_points_and_return_then( procedure_input, move |_, result| { let mapped = result .map_err(SpacetimeClientError::from_sdk_error) .and_then(map_runtime_profile_wallet_adjustment_procedure_result); send_once(&sender, mapped); }, ); }) .await } pub async fn refund_profile_wallet_points( &self, user_id: String, amount: u64, ledger_id: String, created_at_micros: i64, ) -> Result { let procedure_input = build_runtime_profile_wallet_adjustment_input( user_id, amount, ledger_id, created_at_micros, ) .map_err(SpacetimeClientError::validation_failed)? .into(); self.call_after_connect(move |connection, sender| { connection .procedures() .refund_profile_wallet_points_and_return_then(procedure_input, move |_, result| { let mapped = result .map_err(SpacetimeClientError::from_sdk_error) .and_then(map_runtime_profile_wallet_adjustment_procedure_result); send_once(&sender, mapped); }); }) .await } pub async fn get_profile_recharge_center( &self, user_id: String, ) -> Result { let procedure_input = build_runtime_profile_recharge_center_get_input(user_id) .map_err(SpacetimeClientError::validation_failed)? .into(); self.call_after_connect(move |connection, sender| { connection.procedures().get_profile_recharge_center_then( procedure_input, move |_, result| { let mapped = result .map_err(SpacetimeClientError::from_sdk_error) .and_then(map_runtime_profile_recharge_center_procedure_result); send_once(&sender, mapped); }, ); }) .await } pub async fn create_profile_recharge_order( &self, user_id: String, product_id: String, payment_channel: String, created_at_micros: i64, ) -> Result< ( RuntimeProfileRechargeCenterRecord, RuntimeProfileRechargeOrderRecord, ), SpacetimeClientError, > { let procedure_input = build_runtime_profile_recharge_order_create_input( user_id, product_id, payment_channel, created_at_micros, ) .map_err(SpacetimeClientError::validation_failed)? .into(); self.call_after_connect(move |connection, sender| { connection .procedures() .create_profile_recharge_order_and_return_then( procedure_input, move |_, result| { let mapped = result .map_err(SpacetimeClientError::from_sdk_error) .and_then(map_runtime_profile_recharge_order_procedure_result); send_once(&sender, mapped); }, ); }) .await } pub async fn get_profile_recharge_order( &self, order_id: String, ) -> Result< ( RuntimeProfileRechargeCenterRecord, RuntimeProfileRechargeOrderRecord, ), SpacetimeClientError, > { let procedure_input = build_runtime_profile_recharge_order_get_input(order_id) .map_err(SpacetimeClientError::validation_failed)? .into(); self.call_after_connect(move |connection, sender| { connection .procedures() .get_profile_recharge_order_and_return_then(procedure_input, move |_, result| { let mapped = result .map_err(SpacetimeClientError::from_sdk_error) .and_then(map_runtime_profile_recharge_order_procedure_result); send_once(&sender, mapped); }); }) .await } pub async fn mark_profile_recharge_order_paid( &self, order_id: String, paid_at_micros: i64, provider_transaction_id: Option, ) -> Result< ( RuntimeProfileRechargeCenterRecord, RuntimeProfileRechargeOrderRecord, ), SpacetimeClientError, > { let procedure_input = module_runtime::build_runtime_profile_recharge_order_paid_input( order_id, paid_at_micros, provider_transaction_id, ) .map_err(SpacetimeClientError::validation_failed)? .into(); self.call_after_connect(move |connection, sender| { connection .procedures() .mark_profile_recharge_order_paid_and_return_then( procedure_input, move |_, result| { let mapped = result .map_err(SpacetimeClientError::from_sdk_error) .and_then(map_runtime_profile_recharge_order_procedure_result); send_once(&sender, mapped); }, ); }) .await } pub async fn submit_profile_feedback( &self, user_id: String, description: String, contact_phone: Option, evidence_items: Vec, created_at_micros: i64, ) -> Result { let procedure_input = build_runtime_profile_feedback_submission_input( user_id, description, contact_phone, evidence_items, created_at_micros, ) .map_err(SpacetimeClientError::validation_failed)? .into(); self.call_after_connect(move |connection, sender| { connection .procedures() .submit_profile_feedback_and_return_then(procedure_input, move |_, result| { let mapped = result .map_err(SpacetimeClientError::from_sdk_error) .and_then(map_runtime_profile_feedback_submission_procedure_result); send_once(&sender, mapped); }); }) .await } pub async fn get_profile_referral_invite_center( &self, user_id: String, ) -> Result { let procedure_input = build_runtime_referral_invite_center_get_input(user_id) .map_err(SpacetimeClientError::validation_failed)? .into(); self.call_after_connect(move |connection, sender| { connection .procedures() .get_profile_referral_invite_center_then(procedure_input, move |_, result| { let mapped = result .map_err(SpacetimeClientError::from_sdk_error) .and_then(map_runtime_referral_invite_center_procedure_result); send_once(&sender, mapped); }); }) .await } pub async fn redeem_profile_referral_invite_code( &self, user_id: String, invite_code: String, updated_at_micros: i64, ) -> Result { let procedure_input = build_runtime_referral_redeem_input(user_id, invite_code, updated_at_micros) .map_err(SpacetimeClientError::validation_failed)? .into(); self.call_after_connect(move |connection, sender| { connection .procedures() .redeem_profile_referral_invite_code_then(procedure_input, move |_, result| { let mapped = result .map_err(SpacetimeClientError::from_sdk_error) .and_then(map_runtime_referral_redeem_procedure_result); send_once(&sender, mapped); }); }) .await } pub async fn redeem_profile_reward_code( &self, user_id: String, code: String, redeemed_at_micros: i64, ) -> Result { let procedure_input = build_runtime_profile_reward_code_redeem_input(user_id, code, redeemed_at_micros) .map_err(SpacetimeClientError::validation_failed)? .into(); self.call_after_connect(move |connection, sender| { connection.procedures().redeem_profile_reward_code_then( procedure_input, move |_, result| { let mapped = result .map_err(SpacetimeClientError::from_sdk_error) .and_then(map_runtime_profile_reward_code_redeem_procedure_result); send_once(&sender, mapped); }, ); }) .await } pub async fn record_daily_login_tracking_event( &self, user_id: String, ) -> Result<(), SpacetimeClientError> { let normalized_user_id = user_id.trim().to_string(); let occurred_at_micros = shared_kernel::offset_datetime_to_unix_micros(time::OffsetDateTime::now_utc()); let day_key = runtime_profile_beijing_day_key(occurred_at_micros); self.record_tracking_event( format!("daily-login:{}:{}", normalized_user_id, day_key), "daily_login".to_string(), DomainRuntimeTrackingScopeKind::User, normalized_user_id.clone(), Some(normalized_user_id.clone()), Some(normalized_user_id), None, Some("profile".to_string()), "{}".to_string(), occurred_at_micros, ) .await } pub async fn record_tracking_event( &self, event_id: String, event_key: String, scope_kind: DomainRuntimeTrackingScopeKind, scope_id: String, user_id: Option, owner_user_id: Option, profile_id: Option, module_key: Option, metadata_json: String, occurred_at_micros: i64, ) -> Result<(), SpacetimeClientError> { let procedure_input = crate::module_bindings::RuntimeTrackingEventInput { event_id, event_key, scope_kind: map_runtime_tracking_scope_kind(scope_kind), scope_id, user_id, owner_user_id, profile_id, module_key, metadata_json, occurred_at_micros, }; self.call_after_connect(move |connection, sender| { connection .procedures() .record_tracking_event_and_return_then(procedure_input, move |_, result| { let mapped = result .map_err(SpacetimeClientError::from_sdk_error) .and_then(map_runtime_tracking_event_procedure_result); send_once(&sender, mapped); }); }) .await } pub async fn get_profile_task_center( &self, user_id: String, ) -> Result { let procedure_input = build_runtime_profile_task_center_get_input(user_id) .map_err(SpacetimeClientError::validation_failed)? .into(); self.call_after_connect(move |connection, sender| { connection.procedures().get_profile_task_center_then( procedure_input, move |_, result| { let mapped = result .map_err(SpacetimeClientError::from_sdk_error) .and_then(map_runtime_profile_task_center_procedure_result); send_once(&sender, mapped); }, ); }) .await } pub async fn claim_profile_task_reward( &self, user_id: String, task_id: String, ) -> Result { let procedure_input = build_runtime_profile_task_claim_input(user_id, task_id) .map_err(SpacetimeClientError::validation_failed)? .into(); self.call_after_connect(move |connection, sender| { connection .procedures() .claim_profile_task_reward_and_return_then(procedure_input, move |_, result| { let mapped = result .map_err(SpacetimeClientError::from_sdk_error) .and_then(map_runtime_profile_task_claim_procedure_result); send_once(&sender, mapped); }); }) .await } pub async fn query_analytics_metric( &self, event_key: String, scope_kind: DomainRuntimeTrackingScopeKind, scope_id: String, granularity: module_runtime::AnalyticsGranularity, ) -> Result { let procedure_input = build_analytics_metric_query_input(event_key, scope_kind, scope_id, granularity) .map_err(SpacetimeClientError::validation_failed)? .into(); self.call_after_connect(move |connection, sender| { connection.procedures().query_analytics_metric_then( procedure_input, move |_, result| { let mapped = result .map_err(SpacetimeClientError::from_sdk_error) .and_then(map_analytics_metric_query_procedure_result); send_once(&sender, mapped); }, ); }) .await } pub async fn admin_list_profile_task_configs( &self, admin_user_id: String, ) -> Result, SpacetimeClientError> { let procedure_input = build_runtime_profile_task_config_admin_list_input(admin_user_id) .map_err(SpacetimeClientError::validation_failed)? .into(); self.call_after_connect(move |connection, sender| { connection .procedures() .admin_list_profile_task_configs_then(procedure_input, move |_, result| { let mapped = result .map_err(SpacetimeClientError::from_sdk_error) .and_then(map_runtime_profile_task_config_admin_list_procedure_result); send_once(&sender, mapped); }); }) .await } pub async fn admin_upsert_profile_task_config( &self, admin_user_id: String, task_id: String, title: String, description: String, event_key: String, cycle: DomainRuntimeProfileTaskCycle, scope_kind: DomainRuntimeTrackingScopeKind, threshold: u32, reward_points: u64, enabled: bool, sort_order: i32, updated_at_micros: i64, ) -> Result { let procedure_input = build_runtime_profile_task_config_admin_upsert_input( admin_user_id, task_id, title, description, event_key, cycle, scope_kind, threshold, reward_points, enabled, sort_order, updated_at_micros, ) .map_err(SpacetimeClientError::validation_failed)? .into(); self.call_after_connect(move |connection, sender| { connection .procedures() .admin_upsert_profile_task_config_then(procedure_input, move |_, result| { let mapped = result .map_err(SpacetimeClientError::from_sdk_error) .and_then(map_runtime_profile_task_config_admin_procedure_result); send_once(&sender, mapped); }); }) .await } pub async fn admin_disable_profile_task_config( &self, admin_user_id: String, task_id: String, updated_at_micros: i64, ) -> Result { let procedure_input = build_runtime_profile_task_config_admin_disable_input( admin_user_id, task_id, updated_at_micros, ) .map_err(SpacetimeClientError::validation_failed)? .into(); self.call_after_connect(move |connection, sender| { connection .procedures() .admin_disable_profile_task_config_then(procedure_input, move |_, result| { let mapped = result .map_err(SpacetimeClientError::from_sdk_error) .and_then(map_runtime_profile_task_config_admin_procedure_result); send_once(&sender, mapped); }); }) .await } pub async fn admin_upsert_profile_redeem_code( &self, admin_user_id: String, code: String, mode: DomainRuntimeProfileRedeemCodeMode, reward_points: u64, max_uses: u32, enabled: bool, allowed_user_ids: Vec, allowed_public_user_codes: Vec, updated_at_micros: i64, ) -> Result { let procedure_input = build_runtime_profile_redeem_code_admin_upsert_input( admin_user_id, code, mode, reward_points, max_uses, enabled, allowed_user_ids, allowed_public_user_codes, updated_at_micros, ) .map_err(SpacetimeClientError::validation_failed)? .into(); self.call_after_connect(move |connection, sender| { connection .procedures() .admin_upsert_profile_redeem_code_then(procedure_input, move |_, result| { let mapped = result .map_err(SpacetimeClientError::from_sdk_error) .and_then(map_runtime_profile_redeem_code_admin_procedure_result); send_once(&sender, mapped); }); }) .await } pub async fn admin_list_profile_redeem_codes( &self, admin_user_id: String, ) -> Result, SpacetimeClientError> { let procedure_input = build_runtime_profile_redeem_code_admin_list_input(admin_user_id) .map_err(SpacetimeClientError::validation_failed)? .into(); self.call_after_connect(move |connection, sender| { connection .procedures() .admin_list_profile_redeem_codes_then(procedure_input, move |_, result| { let mapped = result .map_err(SpacetimeClientError::from_sdk_error) .and_then(map_runtime_profile_redeem_code_admin_list_procedure_result); send_once(&sender, mapped); }); }) .await } pub async fn admin_disable_profile_redeem_code( &self, admin_user_id: String, code: String, updated_at_micros: i64, ) -> Result { let procedure_input = build_runtime_profile_redeem_code_admin_disable_input( admin_user_id, code, updated_at_micros, ) .map_err(SpacetimeClientError::validation_failed)? .into(); self.call_after_connect(move |connection, sender| { connection .procedures() .admin_disable_profile_redeem_code_then(procedure_input, move |_, result| { let mapped = result .map_err(SpacetimeClientError::from_sdk_error) .and_then(map_runtime_profile_redeem_code_admin_procedure_result); send_once(&sender, mapped); }); }) .await } pub async fn admin_upsert_profile_invite_code( &self, admin_user_id: String, invite_code: String, metadata_json: String, starts_at_micros: Option, expires_at_micros: Option, updated_at_micros: i64, ) -> Result { let procedure_input = build_runtime_profile_invite_code_admin_upsert_input( admin_user_id, invite_code, metadata_json, starts_at_micros, expires_at_micros, updated_at_micros, ) .map_err(|error| SpacetimeClientError::Runtime(error.to_string()))? .into(); self.call_after_connect(move |connection, sender| { connection .procedures() .admin_upsert_profile_invite_code_then(procedure_input, move |_, result| { let mapped = result .map_err(|error| SpacetimeClientError::Procedure(error.to_string())) .and_then(map_runtime_profile_invite_code_admin_procedure_result); send_once(&sender, mapped); }); }) .await } pub async fn admin_list_profile_invite_codes( &self, admin_user_id: String, ) -> Result, SpacetimeClientError> { let procedure_input = build_runtime_profile_invite_code_admin_list_input(admin_user_id) .map_err(SpacetimeClientError::validation_failed)? .into(); self.call_after_connect(move |connection, sender| { connection .procedures() .admin_list_profile_invite_codes_then(procedure_input, move |_, result| { let mapped = result .map_err(SpacetimeClientError::from_sdk_error) .and_then(map_runtime_profile_invite_code_admin_list_procedure_result); send_once(&sender, mapped); }); }) .await } pub async fn get_profile_play_stats( &self, user_id: String, ) -> Result { let procedure_input = build_runtime_profile_play_stats_get_input(user_id) .map_err(SpacetimeClientError::validation_failed)? .into(); self.call_after_connect(move |connection, sender| { connection.procedures().get_profile_play_stats_then( procedure_input, move |_, result| { let mapped = result .map_err(SpacetimeClientError::from_sdk_error) .and_then(map_runtime_profile_play_stats_procedure_result); send_once(&sender, mapped); }, ); }) .await } pub async fn get_runtime_snapshot( &self, user_id: String, ) -> Result, SpacetimeClientError> { let procedure_input = build_runtime_snapshot_get_input(user_id) .map_err(SpacetimeClientError::validation_failed)? .into(); self.call_after_connect(move |connection, sender| { connection .procedures() .get_runtime_snapshot_then(procedure_input, move |_, result| { let mapped = result .map_err(SpacetimeClientError::from_sdk_error) .and_then(map_runtime_snapshot_procedure_result); send_once(&sender, mapped); }); }) .await } pub async fn put_runtime_snapshot( &self, user_id: String, saved_at_micros: i64, bottom_tab: String, game_state: serde_json::Value, current_story: Option, updated_at_micros: i64, ) -> Result { let procedure_input = build_runtime_snapshot_upsert_input( user_id, saved_at_micros, bottom_tab, game_state, current_story, updated_at_micros, ) .map_err(SpacetimeClientError::validation_failed)? .into(); self.call_after_connect(move |connection, sender| { connection .procedures() .upsert_runtime_snapshot_and_return_then(procedure_input, move |_, result| { let mapped = result .map_err(SpacetimeClientError::from_sdk_error) .and_then(map_runtime_snapshot_required_procedure_result); send_once(&sender, mapped); }); }) .await } pub async fn delete_runtime_snapshot( &self, user_id: String, ) -> Result { let procedure_input = build_runtime_snapshot_delete_input(user_id) .map_err(SpacetimeClientError::validation_failed)? .into(); self.call_after_connect(move |connection, sender| { connection .procedures() .delete_runtime_snapshot_and_return_then(procedure_input, move |_, result| { let mapped = result .map_err(SpacetimeClientError::from_sdk_error) .and_then(map_runtime_snapshot_delete_procedure_result); send_once(&sender, mapped); }); }) .await } pub async fn list_profile_save_archives( &self, user_id: String, ) -> Result, SpacetimeClientError> { let procedure_input = build_runtime_profile_save_archive_list_input(user_id) .map_err(SpacetimeClientError::validation_failed)? .into(); self.call_after_connect(move |connection, sender| { connection.procedures().list_profile_save_archives_then( procedure_input, move |_, result| { let mapped = result .map_err(SpacetimeClientError::from_sdk_error) .and_then(map_runtime_profile_save_archive_list_procedure_result); send_once(&sender, mapped); }, ); }) .await } pub async fn resume_profile_save_archive( &self, user_id: String, world_key: String, ) -> Result<(RuntimeProfileSaveArchiveRecord, RuntimeSnapshotRecord), SpacetimeClientError> { let procedure_input = build_runtime_profile_save_archive_resume_input(user_id, world_key) .map_err(SpacetimeClientError::validation_failed)? .into(); self.call_after_connect(move |connection, sender| { connection .procedures() .resume_profile_save_archive_and_return_then(procedure_input, move |_, result| { let mapped = result .map_err(SpacetimeClientError::from_sdk_error) .and_then(map_runtime_profile_save_archive_resume_procedure_result); send_once(&sender, mapped); }); }) .await } pub async fn put_runtime_settings( &self, user_id: String, music_volume: f32, platform_theme: DomainRuntimePlatformTheme, updated_at_micros: i64, ) -> Result { let procedure_input = build_runtime_setting_upsert_input( user_id, music_volume, platform_theme, updated_at_micros, ) .map_err(SpacetimeClientError::validation_failed)? .into(); self.call_after_connect(move |connection, sender| { connection .procedures() .upsert_runtime_setting_and_return_then(procedure_input, move |_, result| { let mapped = result .map_err(SpacetimeClientError::from_sdk_error) .and_then(map_runtime_setting_procedure_result); send_once(&sender, mapped); }); }) .await } pub async fn upsert_platform_browse_history_entries( &self, user_id: String, entries: Vec, updated_at_micros: i64, ) -> Result, SpacetimeClientError> { let procedure_input = build_runtime_browse_history_sync_input(user_id, entries, updated_at_micros) .map_err(SpacetimeClientError::validation_failed)? .into(); self.call_after_connect(move |connection, sender| { connection .procedures() .upsert_platform_browse_history_and_return_then( procedure_input, move |_, result| { let mapped = result .map_err(SpacetimeClientError::from_sdk_error) .and_then(map_runtime_browse_history_procedure_result); send_once(&sender, mapped); }, ); }) .await } pub async fn clear_platform_browse_history( &self, user_id: String, ) -> Result, SpacetimeClientError> { let procedure_input = build_runtime_browse_history_clear_input(user_id) .map_err(SpacetimeClientError::validation_failed)? .into(); self.call_after_connect(move |connection, sender| { connection .procedures() .clear_platform_browse_history_and_return_then( procedure_input, move |_, result| { let mapped = result .map_err(SpacetimeClientError::from_sdk_error) .and_then(map_runtime_browse_history_procedure_result); send_once(&sender, mapped); }, ); }) .await } } fn runtime_profile_beijing_day_key(occurred_at_micros: i64) -> i64 { const PROFILE_TASK_BEIJING_OFFSET_MICROS: i64 = 28_800_000_000; const PROFILE_RUNTIME_DAY_MICROS: i64 = 86_400_000_000; (occurred_at_micros + PROFILE_TASK_BEIJING_OFFSET_MICROS).div_euclid(PROFILE_RUNTIME_DAY_MICROS) }