51
pub copyright: Option<String>,
52
pub created_date: Option<String>,
53
pub downloadable: Option<bool>,
54
+ /// `MANUAL`, `AFTER_APPROVAL` or `SCHEDULED`. Kept as the string Apple
55
+ /// sent, so a value added later still parses.
56
+ pub release_type: Option<String>,
57
+ pub earliest_release_date: Option<String>,
58
}
59
60
pub type AppStoreVersion = Resource<AppStoreVersionAttributes>;
87
pub version_string: Option<String>,
88
#[serde(skip_serializing_if = "Option::is_none")]
89
pub copyright: Option<String>,
90
+ /// How the approved version goes live.
91
+ #[serde(skip_serializing_if = "Option::is_none")]
92
+ pub release_type: Option<ReleaseType>,
93
+ /// When a `SCHEDULED` version may go live, ISO 8601 with an offset,
94
+ /// e.g. `2026-11-10T09:00:00+01:00`.
95
+ #[serde(skip_serializing_if = "Option::is_none")]
96
+ pub earliest_release_date: Option<String>,
97
+}
98
+
99
+/// How an approved version is released.
100
+#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
101
+pub enum ReleaseType {
102
+ /// Wait for the developer: the version sits in `PENDING_DEVELOPER_RELEASE`
103
+ /// until a release request is made.
104
+ #[serde(rename = "MANUAL")]
105
+ Manual,
106
+ /// Go live as soon as App Review approves.
107
+ #[serde(rename = "AFTER_APPROVAL")]
108
+ AfterApproval,
109
+ /// Go live on or after `earliestReleaseDate`.
110
+ #[serde(rename = "SCHEDULED")]
111
+ Scheduled,
112
+}
113
+
114
+impl ReleaseType {
115
+ pub fn as_str(self) -> &'static str {
116
+ match self {
117
+ ReleaseType::Manual => "MANUAL",
118
+ ReleaseType::AfterApproval => "AFTER_APPROVAL",
119
+ ReleaseType::Scheduled => "SCHEDULED",
120
+ }
121
+ }
122
+}
123
+
124
+pub const RELEASE_REQUEST_RESOURCE_TYPE: &str = "appStoreVersionReleaseRequests";
125
+pub const PHASED_RELEASE_RESOURCE_TYPE: &str = "appStoreVersionPhasedReleases";
126
+
127
+/// The state `app_version_state` reports for an approved version that waits
128
+/// for a release request.
129
+pub const PENDING_DEVELOPER_RELEASE: &str = "PENDING_DEVELOPER_RELEASE";
130
+
131
+/// `POST /v1/appStoreVersionReleaseRequests`. Apple wants the version as a
132
+/// relationship and no attributes.
133
+#[derive(Debug, Clone, Serialize)]
134
+pub struct ReleaseRequestBody {
135
+ pub data: ReleaseRequestData,
136
+}
137
+
138
+#[derive(Debug, Clone, Serialize)]
139
+pub struct ReleaseRequestData {
140
+ #[serde(rename = "type")]
141
+ pub resource_type: &'static str,
142
+ pub relationships: ReleaseRequestRelationships,
143
+}
144
+
145
+#[derive(Debug, Clone, Serialize)]
146
+#[serde(rename_all = "camelCase")]
147
+pub struct ReleaseRequestRelationships {
148
+ pub app_store_version: ToOne,
149
+}
150
+
151
+impl ReleaseRequestBody {
152
+ pub fn for_version(version_id: &str) -> Self {
153
+ Self {
154
+ data: ReleaseRequestData {
155
+ resource_type: RELEASE_REQUEST_RESOURCE_TYPE,
156
+ relationships: ReleaseRequestRelationships {
157
+ app_store_version: ToOne {
158
+ data: ResourceId {
159
+ resource_type: RESOURCE_TYPE,
160
+ id: version_id.to_string(),
161
+ },
162
+ },
163
+ },
164
+ },
165
+ }
166
+ }
167
+}
168
+
169
+/// A phased release of a version: Apple rolls the update out to a growing
170
+/// share of automatic-update users over seven days.
171
+#[derive(Debug, Clone, Serialize, Deserialize)]
172
+#[serde(rename_all = "camelCase")]
173
+pub struct PhasedReleaseAttributes {
174
+ /// `INACTIVE`, `ACTIVE`, `PAUSED` or `COMPLETE`.
175
+ pub phased_release_state: Option<String>,
176
+ pub start_date: Option<String>,
177
+ pub current_day_number: Option<i64>,
178
+ pub total_pause_duration: Option<i64>,
179
+}
180
+
181
+pub type PhasedRelease = Resource<PhasedReleaseAttributes>;
182
+
183
+/// What `phased-release` does to a version's phased release.
184
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
185
+pub enum PhasedReleaseAction {
186
+ Create,
187
+ Pause,
188
+ Resume,
189
+ Complete,
190
+}
191
+
192
+impl PhasedReleaseAction {
193
+ /// The state the phased release ends in.
194
+ pub fn target_state(self) -> &'static str {
195
+ match self {
196
+ PhasedReleaseAction::Create => "INACTIVE",
197
+ PhasedReleaseAction::Pause => "PAUSED",
198
+ PhasedReleaseAction::Resume => "ACTIVE",
199
+ PhasedReleaseAction::Complete => "COMPLETE",
200
+ }
201
+ }
202
+
203
+ /// Whether `current` (`None` when the version has no phased release)
204
+ /// lets this action run. `Err` says why not, `Ok(true)` that the release
205
+ /// is already in the target state and nothing needs sending.
206
+ pub fn check(self, current: Option<&str>) -> std::result::Result<bool, String> {
207
+ match (self, current) {
208
+ (PhasedReleaseAction::Create, None) => Ok(false),
209
+ (PhasedReleaseAction::Create, Some(state)) => Err(format!(
210
+ "the version already has a phased release ({state})"
211
+ )),
212
+ (_, None) => Err("the version has no phased release; create one first".to_string()),
213
+ (PhasedReleaseAction::Pause, Some("ACTIVE")) => Ok(false),
214
+ (PhasedReleaseAction::Resume, Some("PAUSED")) => Ok(false),
215
+ (PhasedReleaseAction::Complete, Some("ACTIVE" | "PAUSED")) => Ok(false),
216
+ (action, Some(state)) if state == action.target_state() => Ok(true),
217
+ (action, Some(state)) => Err(format!(
218
+ "cannot go from {state} to {}; pause needs ACTIVE, resume needs PAUSED, complete needs ACTIVE or PAUSED",
219
+ action.target_state()
220
+ )),
221
+ }
222
+ }
223
}
224
225
/// Per-platform version records, the unit the store reviews.
277
/// itself only carries a link to it, so this is how to confirm what a
278
/// submission would send.
279
async fn get_app_store_version_build(&self, id: &str) -> Result<Option<Build>>;
280
+
281
+ /// `POST /v1/appStoreVersionReleaseRequests` — release an approved
282
+ /// version that waits in `PENDING_DEVELOPER_RELEASE`. Apple answers with
283
+ /// a resource that carries no state, so read the version back to see it.
284
+ async fn release_app_store_version(&self, id: &str) -> Result<()>;
285
+
286
+ /// `GET /v1/appStoreVersions/{id}/appStoreVersionPhasedRelease` — the
287
+ /// version's phased release, or `None` when it has none.
288
+ async fn get_app_store_version_phased_release(&self, id: &str)
289
+ -> Result<Option<PhasedRelease>>;
290
+
291
+ /// `POST /v1/appStoreVersionPhasedReleases` — start a phased release for
292
+ /// a version that has none. It is created `INACTIVE` and turns `ACTIVE`
293
+ /// when the version is released.
294
+ async fn create_phased_release(&self, version_id: &str) -> Result<PhasedRelease>;
295
+
296
+ /// `PATCH /v1/appStoreVersionPhasedReleases/{id}` with a
297
+ /// `phasedReleaseState`: `ACTIVE` resumes, `PAUSED` pauses, `COMPLETE`
298
+ /// releases to everyone now.
299
+ async fn update_phased_release(&self, id: &str, state: &str) -> Result<PhasedRelease>;
300
}
301
302
#[async_trait]
402
self.request(Method::GET, &path, &[], None::<&()>).await?;
403
Ok(doc.data)
404
}
405
+
406
+ async fn release_app_store_version(&self, id: &str) -> Result<()> {
407
+ self.request_no_content(
408
+ Method::POST,
409
+ "/v1/appStoreVersionReleaseRequests",
410
+ &[],
411
+ Some(&ReleaseRequestBody::for_version(id)),
412
+ )
413
+ .await
414
+ }
415
+
416
+ async fn get_app_store_version_phased_release(
417
+ &self,
418
+ id: &str,
419
+ ) -> Result<Option<PhasedRelease>> {
420
+ let path = format!("/v1/appStoreVersions/{id}/appStoreVersionPhasedRelease");
421
+ let doc: OptionalDocument<PhasedReleaseAttributes> =
422
+ self.request(Method::GET, &path, &[], None::<&()>).await?;
423
+ Ok(doc.data)
424
+ }
425
+
426
+ async fn create_phased_release(&self, version_id: &str) -> Result<PhasedRelease> {
427
+ let body = phased_release_create_body(version_id);
428
+ let doc: Document<PhasedReleaseAttributes> = self
429
+ .request(
430
+ Method::POST,
431
+ "/v1/appStoreVersionPhasedReleases",
432
+ &[],
433
+ Some(&body),
434
+ )
435
+ .await?;
436
+ Ok(doc.data)
437
+ }
438
+
439
+ async fn update_phased_release(&self, id: &str, state: &str) -> Result<PhasedRelease> {
440
+ let path = format!("/v1/appStoreVersionPhasedReleases/{id}");
441
+ let doc: Document<PhasedReleaseAttributes> = self
442
+ .request(
443
+ Method::PATCH,
444
+ &path,
445
+ &[],
446
+ Some(&phased_release_update_body(id, state)),
447
+ )
448
+ .await?;
449
+ Ok(doc.data)
450
+ }
451
+}
452
+
453
+#[derive(Debug, Clone, Serialize)]
454
+#[serde(rename_all = "camelCase")]
455
+pub struct PhasedReleaseStateAttributes {
456
+ pub phased_release_state: String,
457
+}
458
+
459
+#[derive(Debug, Clone, Serialize)]
460
+#[serde(rename_all = "camelCase")]
461
+pub struct PhasedReleaseRelationships {
462
+ pub app_store_version: ToOne,
463
+}
464
+
465
+/// The body that starts a phased release for `version_id`.
466
+pub fn phased_release_create_body(
467
+ version_id: &str,
468
+) -> CreateBody<PhasedReleaseStateAttributes, PhasedReleaseRelationships> {
469
+ CreateBody {
470
+ data: CreateData {
471
+ resource_type: PHASED_RELEASE_RESOURCE_TYPE,
472
+ attributes: PhasedReleaseStateAttributes {
473
+ phased_release_state: PhasedReleaseAction::Create.target_state().to_string(),
474
+ },
475
+ relationships: Some(PhasedReleaseRelationships {
476
+ app_store_version: ToOne {
477
+ data: ResourceId {
478
+ resource_type: RESOURCE_TYPE,
479
+ id: version_id.to_string(),
480
+ },
481
+ },
482
+ }),
483
+ },
484
+ }
485
+}
486
+
487
+/// The body that moves phased release `id` to `state`.
488
+pub fn phased_release_update_body(
489
+ id: &str,
490
+ state: &str,
491
+) -> UpdateBody<PhasedReleaseStateAttributes> {
492
+ UpdateBody {
493
+ data: UpdateData {
494
+ resource_type: PHASED_RELEASE_RESOURCE_TYPE,
495
+ id: id.to_string(),
496
+ attributes: PhasedReleaseStateAttributes {
497
+ phased_release_state: state.to_string(),
498
+ },
499
+ },
500
+ }
501
}
502
503
/// The `relationships` payload for pointing an App Store Version at a
592
assert_eq!(build.attributes.version.as_deref(), Some("42"));
593
assert_eq!(build.attributes.uses_non_exempt_encryption, Some(false));
594
}
595
+
596
+ #[test]
597
+ fn an_update_sends_only_the_release_fields_that_are_set() {
598
+ let fields = AppStoreVersionUpdateFields {
599
+ release_type: Some(ReleaseType::Scheduled),
600
+ earliest_release_date: Some("2026-11-10T09:00:00+01:00".to_string()),
601
+ ..Default::default()
602
+ };
603
+ assert_eq!(
604
+ serde_json::to_value(&fields).unwrap(),
605
+ json!({
606
+ "releaseType": "SCHEDULED",
607
+ "earliestReleaseDate": "2026-11-10T09:00:00+01:00"
608
+ })
609
+ );
610
+ let manual = AppStoreVersionUpdateFields {
611
+ release_type: Some(ReleaseType::Manual),
612
+ ..Default::default()
613
+ };
614
+ assert_eq!(
615
+ serde_json::to_value(&manual).unwrap(),
616
+ json!({ "releaseType": "MANUAL" })
617
+ );
618
+ }
619
+
620
+ #[test]
621
+ fn a_release_request_names_the_version_and_sends_no_attributes() {
622
+ assert_eq!(
623
+ serde_json::to_value(ReleaseRequestBody::for_version("V1")).unwrap(),
624
+ json!({
625
+ "data": {
626
+ "type": "appStoreVersionReleaseRequests",
627
+ "relationships": {
628
+ "appStoreVersion": {
629
+ "data": { "type": "appStoreVersions", "id": "V1" }
630
+ }
631
+ }
632
+ }
633
+ })
634
+ );
635
+ }
636
+
637
+ #[test]
638
+ fn phased_release_bodies_match_the_api() {
639
+ assert_eq!(
640
+ serde_json::to_value(phased_release_create_body("V1")).unwrap(),
641
+ json!({
642
+ "data": {
643
+ "type": "appStoreVersionPhasedReleases",
644
+ "attributes": { "phasedReleaseState": "INACTIVE" },
645
+ "relationships": {
646
+ "appStoreVersion": {
647
+ "data": { "type": "appStoreVersions", "id": "V1" }
648
+ }
649
+ }
650
+ }
651
+ })
652
+ );
653
+ assert_eq!(
654
+ serde_json::to_value(phased_release_update_body("P1", "PAUSED")).unwrap(),
655
+ json!({
656
+ "data": {
657
+ "type": "appStoreVersionPhasedReleases",
658
+ "id": "P1",
659
+ "attributes": { "phasedReleaseState": "PAUSED" }
660
+ }
661
+ })
662
+ );
663
+ }
664
+
665
+ #[test]
666
+ fn phased_release_actions_only_run_from_a_state_that_allows_them() {
667
+ use PhasedReleaseAction::*;
668
+ assert_eq!(Create.check(None), Ok(false));
669
+ assert!(Create.check(Some("INACTIVE")).is_err());
670
+ assert!(Pause.check(None).is_err());
671
+ assert_eq!(Pause.check(Some("ACTIVE")), Ok(false));
672
+ assert_eq!(Pause.check(Some("PAUSED")), Ok(true));
673
+ assert!(Pause.check(Some("INACTIVE")).is_err());
674
+ assert_eq!(Resume.check(Some("PAUSED")), Ok(false));
675
+ assert_eq!(Resume.check(Some("ACTIVE")), Ok(true));
676
+ assert!(Resume.check(Some("COMPLETE")).is_err());
677
+ assert_eq!(Complete.check(Some("ACTIVE")), Ok(false));
678
+ assert_eq!(Complete.check(Some("PAUSED")), Ok(false));
679
+ assert_eq!(Complete.check(Some("COMPLETE")), Ok(true));
680
+ assert!(Complete.check(Some("INACTIVE")).is_err());
681
+ }
682
+
683
+ #[test]
684
+ fn a_phased_release_response_parses() {
685
+ let doc: OptionalDocument<PhasedReleaseAttributes> = serde_json::from_value(json!({
686
+ "data": {
687
+ "id": "P1",
688
+ "type": "appStoreVersionPhasedReleases",
689
+ "attributes": {
690
+ "phasedReleaseState": "ACTIVE",
691
+ "startDate": "2026-11-10T08:00:00Z",
692
+ "currentDayNumber": 2,
693
+ "totalPauseDuration": 0
694
+ }
695
+ }
696
+ }))
697
+ .unwrap();
698
+ let release = doc.data.unwrap();
699
+ assert_eq!(
700
+ release.attributes.phased_release_state.as_deref(),
701
+ Some("ACTIVE")
702
+ );
703
+ assert_eq!(release.attributes.current_day_number, Some(2));
704
+ let none: OptionalDocument<PhasedReleaseAttributes> =
705
+ serde_json::from_value(json!({ "data": null })).unwrap();
706
+ assert!(none.data.is_none());
707
+ }
708
}