(
&self,
doc: &mut DurableStateDoc,
only_id: Option<&str>,
)
| 713 | } |
| 714 | |
| 715 | async fn build_usage_payload( |
| 716 | &self, |
| 717 | doc: &mut DurableStateDoc, |
| 718 | only_id: Option<&str>, |
| 719 | ) -> Vec<serde_json::Value> { |
| 720 | let now = now_unix_ms(); |
| 721 | let mut items = Vec::new(); |
| 722 | let credential_ids = doc |
| 723 | .credentials |
| 724 | .iter() |
| 725 | .filter(|item| item.channel == ACTIVE_CHANNEL) |
| 726 | .filter(|item| only_id.is_none_or(|id| item.id == id)) |
| 727 | .map(|item| item.id.clone()) |
| 728 | .collect::<Vec<_>>(); |
| 729 | for credential_id in credential_ids { |
| 730 | let Some(credential) = current_credential(doc, &credential_id) else { |
| 731 | continue; |
| 732 | }; |
| 733 | let (view_credential, usage) = self.fetch_usage_snapshot(doc, &credential).await; |
| 734 | let view = build_usage_view(&view_credential, usage, now); |
| 735 | items.push(json!({ |
| 736 | "id": view.id, |
| 737 | "user_email": view.user_email, |
| 738 | "enabled": view.enabled, |
| 739 | "order": view.order, |
| 740 | "status": view.status, |
| 741 | "cooldown_until_unix_ms": view.cooldown_until_unix_ms, |
| 742 | "last_error": view.last_error, |
| 743 | "last_used_at_unix_ms": view.last_used_at_unix_ms, |
| 744 | "usage": view.usage, |
| 745 | "json": credential.json_view(), |
| 746 | })); |
| 747 | } |
| 748 | items |
| 749 | } |
| 750 | } |
| 751 | |
| 752 | fn apply_refreshed_credential( |
no test coverage detected