Command: list-versions
Relevant source files
The following files were used as context for generating this wiki page:
The list-versions command is a core component of the IPATool CLI, designed to retrieve and display all available external version identifiers for a specific iOS application hosted on the Apple App Store. This command is essential for users who wish to download specific older versions of an app rather than just the latest release.
The command operates by interacting with Apple's private App Store APIs. It requires a valid authenticated session (see auth) and can target an application using either its numeric App ID or its bundle identifier. The output includes a list of all historical version strings (external identifiers) and identifies which one is currently the latest.
Sources: README.md:94-105, cmd/list_versions.go:21-35
Command Implementation and CLI Interface
The command is implemented using the Cobra library and is registered as a subcommand of the root ipatool command. It supports both interactive and non-interactive execution modes.
Flags and Configuration
The command accepts several flags to specify the target application and control the execution environment:
| Flag | Shorthand | Type | Description |
|---|---|---|---|
--app-id | -i | int64 | The unique numerical ID of the target iOS app. |
--bundle-identifier | -b | string | The bundle identifier of the app (e.g., com.example.app). Overrides app-id. |
--format | string | Sets output format: text or json (Default: text). | |
--keychain-passphrase | string | Passphrase for unlocking the local keychain. |
Sources: cmd/list_versions.go:85-89, cmd/root.go:38-46, README.md:100-112
Execution Logic
The execution flow starts in cmd/list_versions.go. The command first validates that either an App ID or a Bundle Identifier is provided. It then retrieves account information from the App Store module and, if necessary, attempts to re-authenticate if the password token has expired.
Sources: cmd/list_versions.go:27-70
Internal Architecture and Data Flow
The list-versions feature is split between the CLI command layer and the appstore package, which handles the low-level communication with Apple's servers.
The AppStore ListVersions Method
The appstore package implements the ListVersions logic. It constructs a POST request to the iTunes download API, simulating a request from a physical device by including a GUID derived from the machine's MAC address.
Key Components:
- GUID Generation: The tool reads the machine's MAC address and formats it as an uppercase string without colons to serve as a device identifier.
- Request Construction: It uses a private App Store API endpoint (
PrivateAppStoreAPIPathDownload) with a payload containing thesalableAdamId(App ID). - Metadata Parsing: The response is a Plist containing an item list. The method extracts
softwareVersionExternalIdentifiers(an array of all version IDs) andsoftwareVersionExternalIdentifier(the latest ID).
Sources: pkg/appstore/appstore_list_versions.go:20-68
Sequence Diagram: Version Retrieval
The following diagram illustrates the interaction between the CLI, the AppStore service, and the HTTP client during a version listing request.
Data Structures
The command utilizes specific data structures to pass information between the CLI and the App Store logic.
ListVersionsInput
Used to provide the necessary context for the request.
Sources: pkg/appstore/appstore_list_versions.go:10-13
| Field | Type | Description |
|---|---|---|
Account | Account | Contains DSID and authentication tokens. |
App | App | Contains the target App ID. |
ListVersionsOutput
Contains the parsed results from the App Store response.
Sources: pkg/appstore/appstore_list_versions.go:15-18
| Field | Type | Description |
|---|---|---|
ExternalVersionIdentifiers | []string | A list of all historical version IDs available for download. |
LatestExternalVersionID | string | The identifier for the most recent version of the app. |
Error Handling and Retries
The command implements a robust error handling strategy using the avast/retry-go library.
- Token Expiration: If the API returns a
FailureTypePasswordTokenExpired, the command catches this error and attempts to perform a login refresh before retrying the version listing once. - License Missing: If the app has not been "purchased" (linked to the account), the API returns
FailureTypeLicenseNotFound. The command returnsErrLicenseRequired, signaling the user to run thepurchasecommand. - Customer Messages: If Apple's API returns a specific error message intended for the user, IPATool wraps this in a
NewErrorWithMetadataand displays it.
Sources: cmd/list_versions.go:40-81, pkg/appstore/appstore_list_versions.go:34-45
Conclusion
The list-versions command acts as a discovery mechanism within IPATool. By exposing the internal version identifiers that Apple uses to track releases, it enables the specific version targeting required by the download command's --external-version-id flag. It bridges the gap between the high-level user request and the low-level technical metadata required for historical IPA retrieval.