Files
Genarrative/server-rs/crates/spacetime-client/src/active/runtime.rs
T
kdletters 458371a73d
Project CI / Repository checks (push) Successful in 4m11s
Project CI / Frontend tests (push) Successful in 8m38s
Project CI / Backend tests (push) Successful in 10m42s
Project CI / Native shell tests (push) Successful in 32m11s
将退款 outbox 主路径迁入 SpacetimeDB (#204)
## 变更内容

- 新增 `profile_wallet_refund_outbox` 表与 enqueue/process procedure,退款主路径进入 SpacetimeDB。
- 外部生成失败事务、inline 资产失败和跨节点 worker 统一使用库内 outbox,按 ledger 幂等并在事务内完成退款与删除。
- SpacetimeDB 完全不可达时才写本机 emergency spool,恢复时重新入库;兼容旧 spool 文件并保留 attempt 追踪。
- 更新 SpacetimeDB migration、生成 bindings、架构文档、运维恢复说明和项目决策记录。

## 验证

- `cargo check -p spacetime-module -p spacetime-client -p api-server --manifest-path server-rs/Cargo.toml`
- api-server / spacetime-client / spacetime-module / module-runtime 定向测试
- `npm run check:spacetime-schema`
- `npm run check:spacetime-runtime-access`
- `npm run check:server-rs-ddd`
- `npm run check:encoding`
- `git diff --check`

Reviewed-on: http://192.168.35.82/git/GenarrativeAI/Genarrative/pulls/204
Co-authored-by: kdletters <kdletters@qq.com>
Co-committed-by: kdletters <kdletters@qq.com>
2026-08-27 22:04:50 +08:00

1874 lines
70 KiB
Rust

use super::*;
impl SpacetimeClient {
pub async fn get_runtime_settings(
&self,
user_id: String,
) -> Result<module_runtime::RuntimeSettingsRecord, SpacetimeClientError> {
let procedure_input = module_runtime::build_runtime_setting_get_input(user_id)
.map_err(SpacetimeClientError::validation_failed)?
.into();
self.call_after_connect(
"get_runtime_setting_or_default",
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 put_runtime_settings(
&self,
user_id: String,
music_volume: f32,
platform_theme: module_runtime::RuntimePlatformTheme,
updated_at_micros: i64,
) -> Result<module_runtime::RuntimeSettingsRecord, SpacetimeClientError> {
let procedure_input = module_runtime::build_runtime_setting_upsert_input(
user_id,
music_volume,
platform_theme,
updated_at_micros,
)
.map_err(SpacetimeClientError::validation_failed)?
.into();
self.call_after_connect(
"upsert_runtime_setting_and_return",
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 get_feature_gate_config(
&self,
) -> Result<Vec<FeatureGateConfigRecord>, SpacetimeClientError> {
match self.fetch_feature_gate_config_via_procedure().await {
Ok(config) => {
self.cache_feature_gate_config(config.clone()).await;
Ok(config)
}
Err(error) => {
if let Some(config) = self.read_cached_feature_gate_config().await {
return Ok(config);
}
Err(error)
}
}
}
async fn fetch_feature_gate_config_via_procedure(
&self,
) -> Result<Vec<FeatureGateConfigRecord>, SpacetimeClientError> {
self.call_after_connect("get_feature_gate_config", move |connection, sender| {
connection
.procedures()
.get_feature_gate_config_then(move |_, result| {
let mapped = result
.map_err(SpacetimeClientError::from_sdk_error)
.and_then(map_feature_gate_config_procedure_result);
send_once(&sender, mapped);
});
})
.await
}
pub async fn upsert_feature_gate_config(
&self,
input: module_runtime::FeatureGateConfigAdminUpsertInput,
) -> Result<Vec<FeatureGateConfigRecord>, SpacetimeClientError> {
let procedure_input: FeatureGateConfigAdminUpsertInput = input.into();
let config = self
.call_after_connect("upsert_feature_gate_config", move |connection, sender| {
connection.procedures().upsert_feature_gate_config_then(
procedure_input,
move |_, result| {
let mapped = result
.map_err(SpacetimeClientError::from_sdk_error)
.and_then(map_feature_gate_config_procedure_result);
send_once(&sender, mapped);
},
);
})
.await?;
self.cache_feature_gate_config(config.clone()).await;
Ok(config)
}
pub async fn get_user_tags(
&self,
user_id: String,
) -> Result<Vec<String>, SpacetimeClientError> {
let user_id = user_id.trim().to_string();
if user_id.is_empty() {
return Ok(vec![]);
}
self.read_after_connect("get_user_tags", move |connection| {
Ok(connection
.db()
.user_account()
.user_id()
.find(&user_id)
.and_then(|row| row.user_tags)
.unwrap_or_default())
})
.await
}
pub async fn get_profile_dashboard(
&self,
user_id: String,
) -> Result<RuntimeProfileDashboardRecord, SpacetimeClientError> {
let procedure_input = build_runtime_profile_dashboard_get_input(user_id)
.map_err(SpacetimeClientError::validation_failed)?
.into();
self.call_after_connect("get_profile_dashboard", 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<Vec<RuntimeProfileWalletLedgerEntryRecord>, SpacetimeClientError> {
let procedure_input = build_runtime_profile_wallet_ledger_list_input(user_id)
.map_err(SpacetimeClientError::validation_failed)?
.into();
self.call_after_connect("list_profile_wallet_ledger", 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<RuntimeProfileDashboardRecord, SpacetimeClientError> {
let procedure_input = build_runtime_profile_dashboard_get_input(user_id)
.map_err(|error| SpacetimeClientError::Runtime(error.to_string()))?
.into();
self.call_after_connect(
"grant_new_user_registration_wallet_reward",
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<RuntimeProfileDashboardRecord, SpacetimeClientError> {
self.consume_profile_wallet_points_with_metadata(
user_id,
amount,
ledger_id,
created_at_micros,
module_runtime::PROFILE_INVITE_CODE_METADATA_DEFAULT_JSON.to_string(),
)
.await
}
pub async fn consume_profile_wallet_points_with_metadata(
&self,
user_id: String,
amount: u64,
ledger_id: String,
created_at_micros: i64,
metadata_json: String,
) -> Result<RuntimeProfileDashboardRecord, SpacetimeClientError> {
let procedure_input = build_runtime_profile_wallet_adjustment_input_with_metadata(
user_id,
amount,
ledger_id,
created_at_micros,
metadata_json,
)
.map_err(SpacetimeClientError::validation_failed)?
.into();
self.call_after_connect(
"consume_profile_wallet_points_and_return",
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<RuntimeProfileDashboardRecord, SpacetimeClientError> {
self.refund_profile_wallet_points_with_metadata(
user_id,
amount,
ledger_id,
created_at_micros,
module_runtime::PROFILE_INVITE_CODE_METADATA_DEFAULT_JSON.to_string(),
)
.await
}
pub async fn refund_profile_wallet_points_with_metadata(
&self,
user_id: String,
amount: u64,
ledger_id: String,
created_at_micros: i64,
metadata_json: String,
) -> Result<RuntimeProfileDashboardRecord, SpacetimeClientError> {
let procedure_input = build_runtime_profile_wallet_adjustment_input_with_metadata(
user_id,
amount,
ledger_id,
created_at_micros,
metadata_json,
)
.map_err(SpacetimeClientError::validation_failed)?
.into();
self.call_after_connect(
"refund_profile_wallet_points_and_return",
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 enqueue_profile_wallet_refund_outbox(
&self,
input: module_runtime::RuntimeProfileWalletRefundOutboxEnqueueInput,
) -> Result<module_runtime::RuntimeProfileWalletRefundOutboxProcedureResult, SpacetimeClientError>
{
let procedure_input: RuntimeProfileWalletRefundOutboxEnqueueInput = input.into();
self.call_after_connect(
"enqueue_profile_wallet_refund_outbox_and_return",
move |connection, sender| {
connection
.procedures()
.enqueue_profile_wallet_refund_outbox_and_return_then(
procedure_input,
move |_, result| {
let mapped = result
.map_err(SpacetimeClientError::from_sdk_error)
.and_then(
map_runtime_profile_wallet_refund_outbox_procedure_result,
);
send_once(&sender, mapped);
},
);
},
)
.await
}
pub async fn process_profile_wallet_refund_outbox(
&self,
worker_id: String,
limit: u32,
) -> Result<module_runtime::RuntimeProfileWalletRefundOutboxProcedureResult, SpacetimeClientError>
{
let procedure_input =
module_runtime::build_runtime_profile_wallet_refund_outbox_process_input(
worker_id, limit,
)
.map_err(SpacetimeClientError::validation_failed)?
.into();
self.call_after_connect(
"process_profile_wallet_refund_outbox_and_return",
move |connection, sender| {
connection
.procedures()
.process_profile_wallet_refund_outbox_and_return_then(
procedure_input,
move |_, result| {
let mapped = result
.map_err(SpacetimeClientError::from_sdk_error)
.and_then(
map_runtime_profile_wallet_refund_outbox_procedure_result,
);
send_once(&sender, mapped);
},
);
},
)
.await
}
pub async fn get_profile_recharge_center(
&self,
user_id: String,
) -> Result<RuntimeProfileRechargeCenterRecord, SpacetimeClientError> {
let procedure_input = build_runtime_profile_recharge_center_get_input(user_id)
.map_err(SpacetimeClientError::validation_failed)?
.into();
self.call_after_connect("get_profile_recharge_center", 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(
"create_profile_recharge_order_and_return",
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(
"get_profile_recharge_order_and_return",
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<String>,
) -> 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(
"mark_profile_recharge_order_paid_and_return",
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 record_profile_recharge_refund_observation(
&self,
input: module_runtime::RuntimeProfileRechargeRefundObservationInput,
) -> Result<
(
module_runtime::RuntimeProfileRechargeRefundSnapshot,
Option<module_runtime::RuntimeProfileRechargeOrderRefundSettlementSnapshot>,
bool,
String,
),
SpacetimeClientError,
> {
let procedure_input =
module_runtime::build_runtime_profile_recharge_refund_observation_input(
input.observation_id,
input.source,
input.notification_ref,
input.payload_fingerprint,
input.out_refund_no,
input.provider_refund_id,
input.order_id,
input.provider_transaction_id,
input.provider_status,
input.total_cents,
input.refund_cents,
input.payer_total_cents,
input.payer_refund_cents,
input.success_at_micros,
input.observed_at_micros,
)
.map_err(SpacetimeClientError::validation_failed)?
.into();
self.call_after_connect(
"record_profile_recharge_refund_observation_and_return",
move |connection, sender| {
connection
.procedures()
.record_profile_recharge_refund_observation_and_return_then(
procedure_input,
move |_, result| {
let mapped = result
.map_err(SpacetimeClientError::from_sdk_error)
.and_then(map_runtime_profile_recharge_refund_procedure_result);
send_once(&sender, mapped);
},
);
},
)
.await
}
pub async fn get_profile_recharge_refund(
&self,
out_refund_no: String,
) -> Result<
(
module_runtime::RuntimeProfileRechargeRefundSnapshot,
Option<module_runtime::RuntimeProfileRechargeOrderRefundSettlementSnapshot>,
bool,
String,
),
SpacetimeClientError,
> {
let procedure_input =
module_runtime::build_runtime_profile_recharge_refund_get_input(out_refund_no)
.map_err(SpacetimeClientError::validation_failed)?
.into();
self.call_after_connect(
"get_profile_recharge_refund_and_return",
move |connection, sender| {
connection
.procedures()
.get_profile_recharge_refund_and_return_then(
procedure_input,
move |_, result| {
let mapped = result
.map_err(SpacetimeClientError::from_sdk_error)
.and_then(map_runtime_profile_recharge_refund_procedure_result);
send_once(&sender, mapped);
},
);
},
)
.await
}
pub async fn list_profile_recharge_refunds_for_reconciliation(
&self,
limit: u32,
) -> Result<Vec<module_runtime::RuntimeProfileRechargeRefundSnapshot>, SpacetimeClientError>
{
let procedure_input =
module_runtime::build_runtime_profile_recharge_refund_reconciliation_list_input(limit)
.into();
self.call_after_connect(
"list_profile_recharge_refunds_for_reconciliation",
move |connection, sender| {
connection
.procedures()
.list_profile_recharge_refunds_for_reconciliation_then(
procedure_input,
move |_, result| {
let mapped = result
.map_err(SpacetimeClientError::from_sdk_error)
.and_then(
map_runtime_profile_recharge_refund_list_procedure_result,
);
send_once(&sender, mapped);
},
);
},
)
.await
}
pub async fn get_profile_recharge_refund_bill_checkpoint(
&self,
checkpoint_id: String,
) -> Result<
Option<module_runtime::RuntimeProfileRechargeRefundBillCheckpointSnapshot>,
SpacetimeClientError,
> {
let procedure_input =
module_runtime::build_runtime_profile_recharge_refund_bill_checkpoint_get_input(
checkpoint_id,
)
.map_err(SpacetimeClientError::validation_failed)?
.into();
self.call_after_connect(
"get_profile_recharge_refund_bill_checkpoint_and_return",
move |connection, sender| {
connection
.procedures()
.get_profile_recharge_refund_bill_checkpoint_and_return_then(
procedure_input,
move |_, result| {
let mapped = result
.map_err(SpacetimeClientError::from_sdk_error)
.and_then(
map_runtime_profile_recharge_refund_bill_checkpoint_optional_result,
);
send_once(&sender, mapped);
},
);
},
)
.await
}
pub async fn advance_profile_recharge_refund_bill_checkpoint(
&self,
checkpoint_id: String,
bill_date: String,
bill_hash: String,
processed_refund_count: u32,
completed_at_micros: i64,
) -> Result<
module_runtime::RuntimeProfileRechargeRefundBillCheckpointSnapshot,
SpacetimeClientError,
> {
let procedure_input =
module_runtime::build_runtime_profile_recharge_refund_bill_checkpoint_advance_input(
checkpoint_id,
bill_date,
bill_hash,
processed_refund_count,
completed_at_micros,
)
.map_err(SpacetimeClientError::validation_failed)?
.into();
self.call_after_connect(
"advance_profile_recharge_refund_bill_checkpoint_and_return",
move |connection, sender| {
connection
.procedures()
.advance_profile_recharge_refund_bill_checkpoint_and_return_then(
procedure_input,
move |_, result| {
let mapped = result
.map_err(SpacetimeClientError::from_sdk_error)
.and_then(
map_runtime_profile_recharge_refund_bill_checkpoint_required_result,
);
send_once(&sender, mapped);
},
);
},
)
.await
}
pub async fn admin_list_profile_recharge_orders(
&self,
input: module_runtime::RuntimeProfileRechargeOrderAdminListInput,
) -> Result<
Vec<module_runtime::RuntimeProfileRechargeOrderAdminEntrySnapshot>,
SpacetimeClientError,
> {
let procedure_input: RuntimeProfileRechargeOrderAdminListInput = input.into();
self.call_after_connect(
"admin_list_profile_recharge_orders_and_return",
move |connection, sender| {
connection
.procedures()
.admin_list_profile_recharge_orders_and_return_then(
procedure_input,
move |_, result| {
let mapped = result
.map_err(SpacetimeClientError::from_sdk_error)
.and_then(
map_runtime_profile_recharge_order_admin_list_procedure_result,
);
send_once(&sender, mapped);
},
);
},
)
.await
}
pub async fn preview_profile_recharge_refund_hold(
&self,
input: module_runtime::RuntimeProfileRechargeRefundHoldPreviewInput,
) -> Result<module_runtime::RuntimeProfileRechargeRefundHoldSnapshot, SpacetimeClientError>
{
let procedure_input: RuntimeProfileRechargeRefundHoldPreviewInput = input.into();
self.call_after_connect(
"preview_profile_recharge_refund_hold_and_return",
move |connection, sender| {
connection
.procedures()
.preview_profile_recharge_refund_hold_and_return_then(
procedure_input,
move |_, result| {
let mapped = result
.map_err(SpacetimeClientError::from_sdk_error)
.and_then(
map_runtime_profile_recharge_refund_hold_procedure_result,
);
send_once(&sender, mapped);
},
);
},
)
.await
}
pub async fn prepare_profile_recharge_refund_hold(
&self,
input: module_runtime::RuntimeProfileRechargeRefundHoldPrepareInput,
) -> Result<module_runtime::RuntimeProfileRechargeRefundHoldSnapshot, SpacetimeClientError>
{
let procedure_input: RuntimeProfileRechargeRefundHoldPrepareInput = input.into();
self.call_after_connect(
"prepare_profile_recharge_refund_hold_and_return",
move |connection, sender| {
connection
.procedures()
.prepare_profile_recharge_refund_hold_and_return_then(
procedure_input,
move |_, result| {
let mapped = result
.map_err(SpacetimeClientError::from_sdk_error)
.and_then(
map_runtime_profile_recharge_refund_hold_procedure_result,
);
send_once(&sender, mapped);
},
);
},
)
.await
}
pub async fn release_profile_recharge_refund_hold(
&self,
input: module_runtime::RuntimeProfileRechargeRefundHoldReleaseInput,
) -> Result<module_runtime::RuntimeProfileRechargeRefundHoldSnapshot, SpacetimeClientError>
{
let procedure_input: RuntimeProfileRechargeRefundHoldReleaseInput = input.into();
self.call_after_connect(
"release_profile_recharge_refund_hold_and_return",
move |connection, sender| {
connection
.procedures()
.release_profile_recharge_refund_hold_and_return_then(
procedure_input,
move |_, result| {
let mapped = result
.map_err(SpacetimeClientError::from_sdk_error)
.and_then(
map_runtime_profile_recharge_refund_hold_procedure_result,
);
send_once(&sender, mapped);
},
);
},
)
.await
}
pub async fn list_profile_recharge_refund_holds_for_reconciliation(
&self,
input: module_runtime::RuntimeProfileRechargeRefundHoldListInput,
) -> Result<Vec<module_runtime::RuntimeProfileRechargeRefundHoldSnapshot>, SpacetimeClientError>
{
let procedure_input: RuntimeProfileRechargeRefundHoldListInput = input.into();
self.call_after_connect(
"list_profile_recharge_refund_holds_for_reconciliation",
move |connection, sender| {
connection
.procedures()
.list_profile_recharge_refund_holds_for_reconciliation_then(
procedure_input,
move |_, result| {
let mapped = result
.map_err(SpacetimeClientError::from_sdk_error)
.and_then(
map_runtime_profile_recharge_refund_hold_list_procedure_result,
);
send_once(&sender, mapped);
},
);
},
)
.await
}
pub async fn resolve_profile_recharge_refund_manual_review(
&self,
input: module_runtime::RuntimeProfileRechargeRefundManualReviewResolveInput,
) -> Result<
(
module_runtime::RuntimeProfileRechargeRefundSnapshot,
Option<module_runtime::RuntimeProfileRechargeOrderRefundSettlementSnapshot>,
bool,
String,
),
SpacetimeClientError,
> {
let procedure_input: RuntimeProfileRechargeRefundManualReviewResolveInput = input.into();
self.call_after_connect(
"resolve_profile_recharge_refund_manual_review_and_return",
move |connection, sender| {
connection
.procedures()
.resolve_profile_recharge_refund_manual_review_and_return_then(
procedure_input,
move |_, result| {
let mapped = result
.map_err(SpacetimeClientError::from_sdk_error)
.and_then(map_runtime_profile_recharge_refund_procedure_result);
send_once(&sender, mapped);
},
);
},
)
.await
}
pub async fn admin_get_profile_wallet(
&self,
input: module_runtime::RuntimeProfileAdminWalletGetInput,
) -> Result<module_runtime::RuntimeProfileAdminWalletSnapshot, SpacetimeClientError> {
let procedure_input: RuntimeProfileAdminWalletGetInput = input.into();
self.call_after_connect(
"admin_get_profile_wallet_and_return",
move |connection, sender| {
connection
.procedures()
.admin_get_profile_wallet_and_return_then(procedure_input, move |_, result| {
let mapped = result
.map_err(SpacetimeClientError::from_sdk_error)
.and_then(map_runtime_profile_admin_wallet_procedure_result);
send_once(&sender, mapped);
});
},
)
.await
}
pub async fn admin_get_profile_wallet_detail(
&self,
input: module_runtime::RuntimeProfileAdminWalletGetInput,
) -> Result<module_runtime::RuntimeProfileAdminWalletDetailRecord, SpacetimeClientError> {
let procedure_input: RuntimeProfileAdminWalletGetInput = input.into();
self.call_after_connect(
"admin_get_profile_wallet_detail_and_return",
move |connection, sender| {
connection
.procedures()
.admin_get_profile_wallet_detail_and_return_then(
procedure_input,
move |_, result| {
let mapped = result
.map_err(SpacetimeClientError::from_sdk_error)
.and_then(map_runtime_profile_admin_wallet_detail_procedure_result);
send_once(&sender, mapped);
},
);
},
)
.await
}
pub async fn admin_reconcile_profile_wallet_consumption(
&self,
input: module_runtime::RuntimeProfileWalletConsumptionReconcileInput,
) -> Result<module_runtime::RuntimeProfileWalletConsumptionReconcileRecord, SpacetimeClientError>
{
let procedure_input: RuntimeProfileWalletConsumptionReconcileInput = input.into();
self.call_after_connect(
"admin_reconcile_profile_wallet_consumption_and_return",
move |connection, sender| {
connection
.procedures()
.admin_reconcile_profile_wallet_consumption_and_return_then(
procedure_input,
move |_, result| {
let mapped = result
.map_err(SpacetimeClientError::from_sdk_error)
.and_then(
map_runtime_profile_wallet_consumption_reconcile_procedure_result,
);
send_once(&sender, mapped);
},
);
},
)
.await
}
pub async fn admin_initialize_profile_wallet_consumption_projections(
&self,
input: module_runtime::RuntimeProfileWalletConsumptionProjectionInitializeInput,
) -> Result<
module_runtime::RuntimeProfileWalletConsumptionProjectionInitializeRecord,
SpacetimeClientError,
> {
let procedure_input: RuntimeProfileWalletConsumptionProjectionInitializeInput =
input.into();
self.call_after_connect(
"admin_initialize_profile_wallet_consumption_projections_and_return",
move |connection, sender| {
connection
.procedures()
.admin_initialize_profile_wallet_consumption_projections_and_return_then(
procedure_input,
move |_, result| {
let mapped = result
.map_err(SpacetimeClientError::from_sdk_error)
.and_then(
map_runtime_profile_wallet_consumption_projection_initialize_procedure_result,
);
send_once(&sender, mapped);
},
);
},
)
.await
}
pub async fn admin_upsert_profile_wallet_manual_restriction(
&self,
input: module_runtime::RuntimeProfileWalletManualRestrictionUpsertInput,
) -> Result<module_runtime::RuntimeProfileAdminWalletSnapshot, SpacetimeClientError> {
let procedure_input: RuntimeProfileWalletManualRestrictionUpsertInput = input.into();
self.call_after_connect(
"admin_upsert_profile_wallet_manual_restriction_and_return",
move |connection, sender| {
connection
.procedures()
.admin_upsert_profile_wallet_manual_restriction_and_return_then(
procedure_input,
move |_, result| {
let mapped = result
.map_err(SpacetimeClientError::from_sdk_error)
.and_then(map_runtime_profile_admin_wallet_procedure_result);
send_once(&sender, mapped);
},
);
},
)
.await
}
pub async fn claim_profile_recharge_order_expiration_schedules(
&self,
worker_id: String,
now_micros: i64,
lease_expires_at_micros: i64,
limit: u32,
) -> Result<
Vec<module_runtime::RuntimeProfileRechargeOrderExpirationScheduleSnapshot>,
SpacetimeClientError,
> {
let procedure_input = build_runtime_profile_recharge_order_expiration_claim_input(
worker_id,
now_micros,
lease_expires_at_micros,
limit,
)
.map_err(SpacetimeClientError::validation_failed)?
.into();
self.call_after_connect(
"claim_profile_recharge_order_expiration_schedule_and_return",
move |connection, sender| {
connection
.procedures()
.claim_profile_recharge_order_expiration_schedule_and_return_then(
procedure_input,
move |_, result| {
let mapped = result.map_err(SpacetimeClientError::from_sdk_error).and_then(
map_runtime_profile_recharge_order_expiration_claim_procedure_result,
);
send_once(&sender, mapped);
},
);
},
)
.await
}
pub async fn complete_profile_recharge_order_expiration_schedule(
&self,
order_id: String,
) -> Result<(), SpacetimeClientError> {
let procedure_input =
build_runtime_profile_recharge_order_expiration_complete_input(order_id)
.map_err(SpacetimeClientError::validation_failed)?
.into();
self.call_after_connect(
"complete_profile_recharge_order_expiration_schedule_and_return",
move |connection, sender| {
connection
.procedures()
.complete_profile_recharge_order_expiration_schedule_and_return_then(
procedure_input,
move |_, result| {
let mapped = result.map_err(SpacetimeClientError::from_sdk_error).and_then(
map_runtime_profile_recharge_order_expiration_complete_procedure_result,
);
send_once(&sender, mapped);
},
);
},
)
.await
}
pub async fn list_unchecked_expired_profile_recharge_orders(
&self,
limit: u32,
) -> Result<Vec<RuntimeProfileRechargeOrderRecord>, SpacetimeClientError> {
let procedure_input =
module_runtime::build_runtime_profile_recharge_order_expiration_check_list_input(limit)
.map_err(SpacetimeClientError::validation_failed)?
.into();
self.call_after_connect(
"list_unchecked_expired_profile_recharge_orders",
move |connection, sender| {
connection
.procedures()
.list_unchecked_expired_profile_recharge_orders_then(
procedure_input,
move |_, result| {
let mapped = result.map_err(SpacetimeClientError::from_sdk_error).and_then(
map_runtime_profile_recharge_order_expiration_check_list_procedure_result,
);
send_once(&sender, mapped);
},
);
},
)
.await
}
pub async fn mark_profile_recharge_order_expiration_checked(
&self,
order_id: String,
checked_at_micros: Option<i64>,
provider_state: Option<String>,
last_error: Option<String>,
) -> Result<RuntimeProfileRechargeOrderRecord, SpacetimeClientError> {
let procedure_input =
module_runtime::build_runtime_profile_recharge_order_expiration_check_input(
order_id,
checked_at_micros,
provider_state,
last_error,
)
.map_err(SpacetimeClientError::validation_failed)?
.into();
self.call_after_connect(
"mark_profile_recharge_order_expiration_checked",
move |connection, sender| {
connection
.procedures()
.mark_profile_recharge_order_expiration_checked_then(
procedure_input,
move |_, result| {
let mapped = result.map_err(SpacetimeClientError::from_sdk_error).and_then(
map_runtime_profile_recharge_order_expiration_check_procedure_result,
);
send_once(&sender, mapped);
},
);
},
)
.await
}
pub async fn close_profile_recharge_order(
&self,
order_id: String,
closed_at_micros: i64,
) -> Result<
(
RuntimeProfileRechargeCenterRecord,
RuntimeProfileRechargeOrderRecord,
),
SpacetimeClientError,
> {
let procedure_input =
build_runtime_profile_recharge_order_close_input(order_id, closed_at_micros)
.map_err(SpacetimeClientError::validation_failed)?
.into();
self.call_after_connect(
"close_profile_recharge_order_and_return",
move |connection, sender| {
connection
.procedures()
.close_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 submit_profile_feedback(
&self,
user_id: String,
description: String,
contact_phone: Option<String>,
evidence_items: Vec<module_runtime::RuntimeProfileFeedbackEvidenceSnapshot>,
created_at_micros: i64,
) -> Result<RuntimeProfileFeedbackSubmissionRecord, SpacetimeClientError> {
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(
"submit_profile_feedback_and_return",
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<RuntimeReferralInviteCenterRecord, SpacetimeClientError> {
let procedure_input = build_runtime_referral_invite_center_get_input(user_id)
.map_err(SpacetimeClientError::validation_failed)?
.into();
self.call_after_connect(
"get_profile_referral_invite_center",
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<RuntimeReferralRedeemRecord, SpacetimeClientError> {
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(
"redeem_profile_referral_invite_code",
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<RuntimeProfileRewardCodeRedeemRecord, SpacetimeClientError> {
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("redeem_profile_reward_code", 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<String>,
owner_user_id: Option<String>,
profile_id: Option<String>,
module_key: Option<String>,
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(
"record_tracking_event_and_return",
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 record_tracking_events(
&self,
events: Vec<module_runtime::RuntimeTrackingEventInput>,
) -> Result<u32, SpacetimeClientError> {
if events.is_empty() {
return Ok(0);
}
let procedure_inputs = events
.into_iter()
.map(|event| crate::module_bindings::RuntimeTrackingEventInput {
event_id: event.event_id,
event_key: event.event_key,
scope_kind: map_runtime_tracking_scope_kind(event.scope_kind),
scope_id: event.scope_id,
user_id: event.user_id,
owner_user_id: event.owner_user_id,
profile_id: event.profile_id,
module_key: event.module_key,
metadata_json: event.metadata_json,
occurred_at_micros: event.occurred_at_micros,
})
.collect::<Vec<_>>();
self.call_after_connect(
"record_tracking_events_and_return",
move |connection, sender| {
connection
.procedures()
.record_tracking_events_and_return_then(procedure_inputs, move |_, result| {
let mapped = result
.map_err(SpacetimeClientError::from_sdk_error)
.and_then(map_runtime_tracking_event_batch_procedure_result);
send_once(&sender, mapped);
});
},
)
.await
}
pub async fn get_profile_task_center(
&self,
user_id: String,
) -> Result<RuntimeProfileTaskCenterRecord, SpacetimeClientError> {
let procedure_input = build_runtime_profile_task_center_get_input(user_id)
.map_err(SpacetimeClientError::validation_failed)?
.into();
self.call_after_connect("get_profile_task_center", 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<RuntimeProfileTaskClaimRecord, SpacetimeClientError> {
let procedure_input = build_runtime_profile_task_claim_input(user_id, task_id)
.map_err(SpacetimeClientError::validation_failed)?
.into();
self.call_after_connect(
"claim_profile_task_reward_and_return",
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<DomainAnalyticsMetricQueryResponse, SpacetimeClientError> {
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("query_analytics_metric", 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<Vec<RuntimeProfileTaskConfigRecord>, 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(
"admin_list_profile_task_configs",
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<RuntimeProfileTaskConfigRecord, SpacetimeClientError> {
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(
"admin_upsert_profile_task_config",
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<RuntimeProfileTaskConfigRecord, SpacetimeClientError> {
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(
"admin_disable_profile_task_config",
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_get_profile_wallet_config(
&self,
admin_user_id: String,
) -> Result<RuntimeProfileWalletConfigRecord, SpacetimeClientError> {
let procedure_input = build_runtime_profile_wallet_config_admin_get_input(admin_user_id)
.map_err(SpacetimeClientError::validation_failed)?
.into();
self.call_after_connect(
"admin_get_profile_wallet_config",
move |connection, sender| {
connection
.procedures()
.admin_get_profile_wallet_config_then(procedure_input, move |_, result| {
let mapped = result
.map_err(SpacetimeClientError::from_sdk_error)
.and_then(map_runtime_profile_wallet_config_admin_procedure_result);
send_once(&sender, mapped);
});
},
)
.await
}
pub async fn admin_upsert_profile_wallet_config(
&self,
admin_user_id: String,
initial_mud_points: u64,
updated_at_micros: i64,
daily_free_points_per_day: u64,
) -> Result<RuntimeProfileWalletConfigRecord, SpacetimeClientError> {
let procedure_input = build_runtime_profile_wallet_config_admin_upsert_input(
admin_user_id,
initial_mud_points,
updated_at_micros,
daily_free_points_per_day,
)
.map_err(SpacetimeClientError::validation_failed)?
.into();
self.call_after_connect(
"admin_upsert_profile_wallet_config",
move |connection, sender| {
connection
.procedures()
.admin_upsert_profile_wallet_config_then(procedure_input, move |_, result| {
let mapped = result
.map_err(SpacetimeClientError::from_sdk_error)
.and_then(map_runtime_profile_wallet_config_admin_procedure_result);
send_once(&sender, mapped);
});
},
)
.await
}
pub async fn admin_list_profile_recharge_products(
&self,
admin_user_id: String,
) -> Result<Vec<RuntimeProfileRechargeProductConfigRecord>, SpacetimeClientError> {
let procedure_input =
build_runtime_profile_recharge_product_admin_list_input(admin_user_id)
.map_err(SpacetimeClientError::validation_failed)?
.into();
self.call_after_connect(
"admin_list_profile_recharge_products",
move |connection, sender| {
connection
.procedures()
.admin_list_profile_recharge_products_then(
procedure_input,
move |_, result| {
let mapped = result
.map_err(SpacetimeClientError::from_sdk_error)
.and_then(
map_runtime_profile_recharge_product_admin_list_procedure_result,
);
send_once(&sender, mapped);
},
);
},
)
.await
}
#[allow(clippy::too_many_arguments)]
pub async fn admin_upsert_profile_recharge_product(
&self,
admin_user_id: String,
product_id: String,
title: String,
price_cents: u64,
kind: module_runtime::RuntimeProfileRechargeProductKind,
points_amount: u64,
bonus_points: u64,
duration_days: u32,
badge_label: String,
description: String,
tier: module_runtime::RuntimeProfileMembershipTier,
membership_period_points: u64,
membership_period_days: u32,
membership_queue_limit: u32,
membership_discount_bps: u32,
enabled: bool,
sort_order: i32,
updated_at_micros: i64,
) -> Result<RuntimeProfileRechargeProductConfigRecord, SpacetimeClientError> {
let procedure_input = build_runtime_profile_recharge_product_admin_upsert_input(
admin_user_id,
product_id,
title,
price_cents,
kind,
points_amount,
bonus_points,
duration_days,
badge_label,
description,
tier,
membership_period_points,
membership_period_days,
membership_queue_limit,
membership_discount_bps,
enabled,
sort_order,
updated_at_micros,
)
.map_err(SpacetimeClientError::validation_failed)?
.into();
self.call_after_connect(
"admin_upsert_profile_recharge_product",
move |connection, sender| {
connection
.procedures()
.admin_upsert_profile_recharge_product_then(
procedure_input,
move |_, result| {
let mapped = result
.map_err(SpacetimeClientError::from_sdk_error)
.and_then(
map_runtime_profile_recharge_product_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<String>,
allowed_public_user_codes: Vec<String>,
starts_at_micros: Option<i64>,
expires_at_micros: Option<i64>,
updated_at_micros: i64,
) -> Result<RuntimeProfileRedeemCodeRecord, SpacetimeClientError> {
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,
starts_at_micros,
expires_at_micros,
updated_at_micros,
)
.map_err(SpacetimeClientError::validation_failed)?
.into();
self.call_after_connect(
"admin_upsert_profile_redeem_code",
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<RuntimeProfileRedeemCodeAdminListRecord, 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(
"admin_list_profile_redeem_codes",
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<RuntimeProfileRedeemCodeRecord, SpacetimeClientError> {
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(
"admin_disable_profile_redeem_code",
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<i64>,
expires_at_micros: Option<i64>,
updated_at_micros: i64,
) -> Result<RuntimeProfileInviteCodeRecord, SpacetimeClientError> {
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(
"admin_upsert_profile_invite_code",
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<RuntimeProfileInviteCodeAdminListRecord, 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(
"admin_list_profile_invite_codes",
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
}
}
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)
}