Skip to content

Commit fce3b0c

Browse files
authored
fix: update policy domain for regenerated types (#123)
## Summary Update the policy subclient and tests for regenerated types. ### Core library changes: - **src/subclients/policies.rs** — Fully rewritten subclient: - Delete/delete_rule now return `SuccessResponse` instead of `()` - `update_rule` returns `PolicyRuleResponse` - All methods pass `None` for `privy_request_expiry` parameter ### Test changes: - **tests/policies.rs** — Key type changes: - `PolicyChainType` consolidated into `WalletChainType` - `CreatePolicyBodyRulesItem` used for policy creation (not `PolicyRuleRequestBody`) - `PolicyRuleRequestBody` used for `update_rule` calls ## Key breaking changes addressed | Before | After | |--------|-------| | `PolicyChainType::Solana` | `WalletChainType::Solana` | | Delete returns `()` | Delete returns `SuccessResponse` | | `update_rule` returns `Policy` | `update_rule` returns `PolicyRuleResponse` | | `PolicyRuleRequestBody` for create | `CreatePolicyBodyRulesItem` for create | ## Test plan - [ ] `cargo clippy --all-targets --all-features -- -D warnings` passes (on full stack) - [ ] Policy tests pass against staging API 🤖 Generated with [Claude Code](https://claude.com/claude-code)
2 parents a582fe1 + 5a635ec commit fce3b0c

2 files changed

Lines changed: 41 additions & 25 deletions

File tree

src/subclients/policies.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl PoliciesClient {
2929
)
3030
.await?;
3131

32-
Ok(self._update(policy_id, Some(&sig), body).await?)
32+
Ok(self._update(policy_id, Some(&sig), None, body).await?)
3333
}
3434

3535
/// Delete a policy
@@ -43,7 +43,7 @@ impl PoliciesClient {
4343
&'a self,
4444
policy_id: &'a crate::generated::types::DeletePolicyPolicyId,
4545
ctx: &'a AuthorizationContext,
46-
) -> Result<ResponseValue<crate::generated::types::DeletePolicyResponse>, PrivySignedApiError>
46+
) -> Result<ResponseValue<crate::generated::types::SuccessResponse>, PrivySignedApiError>
4747
{
4848
let sig = generate_authorization_signatures(
4949
ctx,
@@ -55,7 +55,7 @@ impl PoliciesClient {
5555
)
5656
.await?;
5757

58-
Ok(self._delete(policy_id, Some(&sig)).await?)
58+
Ok(self._delete(policy_id, Some(&sig), None).await?)
5959
}
6060

6161
/// Create a rule for a policy
@@ -82,7 +82,7 @@ impl PoliciesClient {
8282
)
8383
.await?;
8484

85-
Ok(self._create_rule(policy_id, Some(&sig), body).await?)
85+
Ok(self._create_rule(policy_id, Some(&sig), None, body).await?)
8686
}
8787

8888
/// Update a rule for a policy
@@ -98,7 +98,7 @@ impl PoliciesClient {
9898
rule_id: &'a crate::generated::types::UpdateRuleRuleId,
9999
ctx: &'a AuthorizationContext,
100100
body: &'a crate::generated::types::PolicyRuleRequestBody,
101-
) -> Result<ResponseValue<crate::generated::types::UpdateRuleResponse>, PrivySignedApiError>
101+
) -> Result<ResponseValue<crate::generated::types::PolicyRuleResponse>, PrivySignedApiError>
102102
{
103103
let sig = generate_authorization_signatures(
104104
ctx,
@@ -116,7 +116,7 @@ impl PoliciesClient {
116116
.await?;
117117

118118
Ok(self
119-
._update_rule(policy_id, rule_id, Some(&sig), body)
119+
._update_rule(policy_id, rule_id, Some(&sig), None, body)
120120
.await?)
121121
}
122122

@@ -132,7 +132,7 @@ impl PoliciesClient {
132132
policy_id: &'a crate::generated::types::DeleteRulePolicyId,
133133
rule_id: &'a crate::generated::types::DeleteRuleRuleId,
134134
ctx: &'a AuthorizationContext,
135-
) -> Result<ResponseValue<crate::generated::types::DeleteRuleResponse>, PrivySignedApiError>
135+
) -> Result<ResponseValue<crate::generated::types::SuccessResponse>, PrivySignedApiError>
136136
{
137137
let sig = generate_authorization_signatures(
138138
ctx,
@@ -149,6 +149,6 @@ impl PoliciesClient {
149149
)
150150
.await?;
151151

152-
Ok(self._delete_rule(policy_id, rule_id, Some(&sig)).await?)
152+
Ok(self._delete_rule(policy_id, rule_id, Some(&sig), None).await?)
153153
}
154154
}

tests/policies.rs

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ async fn test_policies_create() -> Result<()> {
1111

1212
let unique_name = format!("test-policy-{}", chrono::Utc::now().timestamp());
1313
let policy_body = CreatePolicyBody {
14-
chain_type: PolicyChainType::Solana,
14+
chain_type: WalletChainType::Solana,
1515
name: CreatePolicyBodyName::try_from(unique_name).unwrap(),
1616
owner: None,
1717
owner_id: None,
18-
rules: vec![PolicyRuleRequestBody {
18+
rules: vec![CreatePolicyBodyRulesItem {
1919
action: PolicyAction::Allow,
2020
conditions: vec![PolicyCondition::SolanaSystemProgramInstructionCondition(
2121
SolanaSystemProgramInstructionCondition {
@@ -25,8 +25,9 @@ async fn test_policies_create() -> Result<()> {
2525
value: ConditionValue::String("1000000".to_string()),
2626
}
2727
)],
28+
id: None,
2829
method: PolicyMethod::SignTransaction,
29-
name: PolicyRuleRequestBodyName::try_from("test-rule").unwrap(),
30+
name: CreatePolicyBodyRulesItemName::try_from("test-rule").unwrap(),
3031
}],
3132
version: CreatePolicyBodyVersion::try_from("1.0").unwrap(),
3233
};
@@ -61,7 +62,7 @@ async fn test_policies_get() -> Result<()> {
6162
async fn test_policies_get_rule() {
6263
let client = common::get_test_client().unwrap();
6364
let policy = common::ensure_test_policy(&client, vec![
64-
PolicyRuleRequestBody {
65+
CreatePolicyBodyRulesItem {
6566
action: PolicyAction::Allow,
6667
conditions: vec![PolicyCondition::SolanaSystemProgramInstructionCondition(
6768
SolanaSystemProgramInstructionCondition {
@@ -71,9 +72,9 @@ async fn test_policies_get_rule() {
7172
value: ConditionValue::String("2000000".to_string()),
7273
}
7374
)],
74-
75+
id: None,
7576
method: PolicyMethod::SignTransaction,
76-
name: PolicyRuleRequestBodyName::try_from("updated-rule").unwrap(),
77+
name: CreatePolicyBodyRulesItemName::try_from("updated-rule").unwrap(),
7778
}
7879
]).await.unwrap();
7980

@@ -98,15 +99,15 @@ async fn test_policies_update_with_auth_context() {
9899
let policy = common::ensure_test_policy_with_user(
99100
&client,
100101
vec![],
101-
Some(OwnerInput::PublicKey(pubkey.to_string())),
102+
Some(OwnerInput::Variant1(OwnerInputPublicKey { public_key: P256PublicKey(pubkey.to_string()) })),
102103
)
103104
.await
104105
.unwrap();
105106

106107
let ctx = AuthorizationContext::new().push(key);
107108

108109
let update_body = UpdatePolicyBody {
109-
owner: Some(OwnerInput::PublicKey(pubkey.to_string())),
110+
owner: Some(OwnerInput::Variant1(OwnerInputPublicKey { public_key: P256PublicKey(pubkey.to_string()) })),
110111
owner_id: None,
111112
name: Some(UpdatePolicyBodyName::try_from("my-owned-policy").unwrap()),
112113
rules: vec![PolicyRuleRequestBody {
@@ -151,12 +152,12 @@ async fn test_policies_delete() {
151152
// First create a policy to delete
152153
let unique_name = format!("delete-policy-{}", chrono::Utc::now().timestamp());
153154
let policy_body = CreatePolicyBody {
154-
chain_type: PolicyChainType::Solana,
155+
chain_type: WalletChainType::Solana,
155156
name: CreatePolicyBodyName::try_from(unique_name).unwrap(),
156157
// TODO: set the owner here once we have a JWT
157158
owner: None,
158159
owner_id: None,
159-
rules: vec![PolicyRuleRequestBody {
160+
rules: vec![CreatePolicyBodyRulesItem {
160161
action: PolicyAction::Allow,
161162
conditions: vec![PolicyCondition::SolanaSystemProgramInstructionCondition(
162163
SolanaSystemProgramInstructionCondition {
@@ -166,8 +167,9 @@ async fn test_policies_delete() {
166167
value: ConditionValue::String("1000000".to_string()),
167168
}
168169
)],
170+
id: None,
169171
method: PolicyMethod::SignTransaction,
170-
name: PolicyRuleRequestBodyName::try_from("test-rule").unwrap(),
172+
name: CreatePolicyBodyRulesItemName::try_from("test-rule").unwrap(),
171173
}],
172174
version: CreatePolicyBodyVersion::try_from("1.0").unwrap(),
173175
};
@@ -230,7 +232,7 @@ async fn test_policies_create_rule() {
230232
async fn test_policies_update_rule() {
231233
let client = common::get_test_client().unwrap();
232234

233-
let mut rule = PolicyRuleRequestBody {
235+
let create_rule = CreatePolicyBodyRulesItem {
234236
action: PolicyAction::Deny,
235237
conditions: vec![PolicyCondition::SolanaSystemProgramInstructionCondition(
236238
SolanaSystemProgramInstructionCondition {
@@ -240,15 +242,28 @@ async fn test_policies_update_rule() {
240242
value: ConditionValue::String("10000000".to_string()),
241243
}
242244
)],
245+
id: None,
243246
method: PolicyMethod::SignTransaction,
244-
name: PolicyRuleRequestBodyName::try_from("my-great-rule").unwrap(),
247+
name: CreatePolicyBodyRulesItemName::try_from("my-great-rule").unwrap(),
245248
};
246249

247-
let policy = common::ensure_test_policy(&client, vec![rule.clone()])
250+
let policy = common::ensure_test_policy(&client, vec![create_rule])
248251
.await
249252
.unwrap();
250253

251-
rule.action = PolicyAction::Allow;
254+
let rule = PolicyRuleRequestBody {
255+
action: PolicyAction::Allow,
256+
conditions: vec![PolicyCondition::SolanaSystemProgramInstructionCondition(
257+
SolanaSystemProgramInstructionCondition {
258+
field: SolanaSystemProgramInstructionConditionField::TransferLamports,
259+
field_source: SolanaSystemProgramInstructionConditionFieldSource::SolanaSystemProgramInstruction,
260+
operator: ConditionOperator::Gt,
261+
value: ConditionValue::String("10000000".to_string()),
262+
}
263+
)],
264+
method: PolicyMethod::SignTransaction,
265+
name: PolicyRuleRequestBodyName::try_from("my-great-rule").unwrap(),
266+
};
252267

253268
let private_key = include_str!("./test_private_key.pem");
254269
let ctx = AuthorizationContext::new().push(PrivateKey::new(private_key.into()));
@@ -271,7 +286,7 @@ async fn test_policies_update_rule() {
271286
#[tokio::test]
272287
async fn test_policies_delete_rule() {
273288
let client = common::get_test_client().unwrap();
274-
let policy = common::ensure_test_policy(&client, vec![PolicyRuleRequestBody {
289+
let policy = common::ensure_test_policy(&client, vec![CreatePolicyBodyRulesItem {
275290
action: PolicyAction::Allow,
276291
conditions: vec![PolicyCondition::SolanaSystemProgramInstructionCondition(
277292
SolanaSystemProgramInstructionCondition {
@@ -281,8 +296,9 @@ async fn test_policies_delete_rule() {
281296
value: ConditionValue::String("1000000".to_string()),
282297
}
283298
)],
299+
id: None,
284300
method: PolicyMethod::SignTransaction,
285-
name: PolicyRuleRequestBodyName::try_from("my-unique-rule").unwrap(),
301+
name: CreatePolicyBodyRulesItemName::try_from("my-unique-rule").unwrap(),
286302
}]).await.unwrap();
287303

288304
let private_key = include_str!("./test_private_key.pem");

0 commit comments

Comments
 (0)