Skip to main content

Crate storekit

Crate storekit 

Source
Expand description

§storekit-rs

Safe Rust bindings for Apple’s StoreKit framework on macOS.

Status: v0.3.0 adds an async_api module gated on --features async, wrapping StoreKit 2’s Swift async APIs as Rust Futures via doom_fish_utils::completion.

§Quick start

use storekit::prelude::*;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let products = Product::products_for(["com.example.pro.monthly"])?;
    for product in products {
        println!("{} — {}", product.display_name, product.display_price);
    }

    println!("payments enabled: {}", AppStore::can_make_payments()?);
    Ok(())
}

§Highlights

  • Product::products_for(...), Product::purchase(...), Product::purchase_in_window(...), Product::latest_transaction(), and Product::current_entitlements()
  • Product formatting/localization helpers expose StoreKit format styles, SubscriptionPeriod convenience constructors, and enum/unit localized_description() helpers
  • PurchaseOption covers quantity, app-account tokens, custom payloads, promotional offers, win-back offers, and storefront-change policies
  • Transaction exposes all, current_entitlements, updates, unfinished, filtered product streams, latest_for, current_entitlement_for, verification, finishing, refund helpers, and advanced-commerce info
  • SubscriptionInfo::status_for(...), status_for_transaction(...), SubscriptionStatus::updates(), and SubscriptionStatus::all() surface renewal state plus status streams
  • PurchaseIntent::intents() and ExternalPurchase{,Link,CustomLink} cover the newer StoreKit purchase-intent and regulatory-link families
  • AppStore now includes merchandising presentation, age-rating lookups, and advanced-commerce product purchase support
  • StoreKitError::typed() recovers typed StoreKit, purchase, refund-request, and invalid-request framework errors
  • Storefront::current() and Storefront::updates() wrap the StoreKit storefront APIs
  • AppTransaction::shared() and AppTransaction::refresh() expose app-level verification results
  • ReceiptValidator reads the local app receipt and decodes JWS payloads without publishing or mutating store state
  • StoreContext::current() summarizes bundle, receipt, payment, and device-verification context for headless tooling

§Examples

The crate ships with numbered examples for each logical area:

  • 01_product_lookup
  • 02_transaction_stream
  • 03_app_store_context
  • 04_storefront_current
  • 05_subscription_types
  • 06_subscription_info_status
  • 07_refund_request
  • 08_receipt_validator
  • 09_message_support
  • 10_app_transaction
  • 11_store_context
  • 12_renewal_info
  • 13_renewal_state
  • 14_purchase_option
  • 15_verification_result
  • 16_purchase_intent
  • 17_external_purchase
  • 18_advanced_commerce
  • 19_typed_errors
  • 20_async_products (requires --features async)
  • 21_async_app_transaction (requires --features async)
  • 22_async_storefront (requires --features async)

Run them all with:

for ex in examples/*.rs; do cargo run --example "$(basename "$ex" .rs)"; done

§Async API

Enable the async feature to access StoreKit 2’s async Swift APIs as standard Rust Futures:

[dependencies]
storekit = { version = "0.3", features = ["async"] }
pollster = "0.3"  # or any async runtime
use storekit::async_api::AsyncProducts;

fn main() {
    let products = pollster::block_on(async {
        AsyncProducts::fetch(["com.example.pro"])
            .expect("invalid identifier")
            .await
    });
    println!("{:?}", products);
}

The following async types are available: [AsyncProducts], [AsyncPurchase], [AsyncAppStore], [AsyncAppTransaction], [AsyncStorefront].

§Notes

  • StoreKit.Message is unavailable on macOS, so the message module reports NotSupported there.
  • Refund, review, and offer-code presentation helpers still require an NSViewController-backed window; headless callers get NotSupported instead of hanging.
  • Window-based purchase and merchandising APIs accept caller-owned NSWindowHandle values when the host app has an AppKit window to lend to StoreKit.
  • The crate does not publish or call cargo publish; release tagging is separate from drip-publisher rollout.

§License

Licensed under either of Apache-2.0 or MIT at your option.

Re-exports§

pub use advanced_commerce::AdvancedCommerceProduct;
pub use advanced_commerce::AdvancedCommercePurchaseOption;
pub use advanced_commerce::AppStoreMerchandisingKind;
pub use advanced_commerce::AppStoreMerchandisingPresentationResult;
pub use advanced_commerce::RenewalInfoAdvancedCommerceInfo;
pub use advanced_commerce::RenewalInfoAdvancedCommerceItem;
pub use advanced_commerce::RenewalInfoAdvancedCommercePriceIncreaseInfo;
pub use advanced_commerce::RenewalInfoAdvancedCommercePriceIncreaseStatus;
pub use advanced_commerce::TransactionAdvancedCommerceInfo;
pub use advanced_commerce::TransactionAdvancedCommerceItem;
pub use advanced_commerce::TransactionAdvancedCommerceItemDetails;
pub use advanced_commerce::TransactionAdvancedCommerceOffer;
pub use advanced_commerce::TransactionAdvancedCommerceOfferReason;
pub use advanced_commerce::TransactionAdvancedCommerceRefund;
pub use advanced_commerce::TransactionAdvancedCommerceRefundReason;
pub use advanced_commerce::TransactionAdvancedCommerceRefundType;
pub use app_store::AppStore;
pub use app_store::AppStoreEnvironment;
pub use app_store::AppStorePlatform;
pub use app_transaction::AppTransaction;
pub use error::InvalidRequestError;
pub use error::ProductPurchaseError;
pub use error::ProductPurchaseErrorCode;
pub use error::RefundRequestError;
pub use error::RefundRequestErrorCode;
pub use error::StoreKitApiError;
pub use error::StoreKitApiErrorCode;
pub use error::StoreKitError;
pub use error::StoreKitFrameworkError;
pub use error::TypedStoreKitError;
pub use error::VerificationErrorCode;
pub use error::VerificationFailure;
pub use external_purchase::ExternalPurchase;
pub use external_purchase::ExternalPurchaseCustomLinkNoticeResult;
pub use external_purchase::ExternalPurchaseCustomLinkNoticeType;
pub use external_purchase::ExternalPurchaseCustomLinkToken;
pub use external_purchase::ExternalPurchaseNoticeResult;
pub use message::Message;
pub use message::MessageReason;
pub use message::MessageStream;
pub use product::Product;
pub use product::ProductType;
pub use purchase_intent::PurchaseIntent;
pub use purchase_intent::PurchaseIntentStream;
pub use purchase_option::PurchaseOption;
pub use purchase_option::PurchaseResult;
pub use receipt_validator::AppReceipt;
pub use receipt_validator::ReceiptValidator;
pub use refund::Refund;
pub use refund::RefundRequestStatus;
pub use renewal_info::ExpirationReason;
pub use renewal_info::PriceIncreaseStatus;
pub use renewal_info::RenewalInfo;
pub use renewal_state::RenewalState;
pub use store_context::StoreContext;
pub use storefront::Storefront;
pub use storefront::StorefrontStream;
pub use subscription::SubscriptionOffer;
pub use subscription::SubscriptionOfferType;
pub use subscription::SubscriptionPaymentMode;
pub use subscription::SubscriptionPeriod;
pub use subscription::SubscriptionPeriodUnit;
pub use subscription_info::SubscriptionInfo;
pub use subscription_info::SubscriptionStatus;
pub use transaction::OfferPaymentMode;
pub use transaction::OfferType;
pub use transaction::OwnershipType;
pub use transaction::RevocationReason;
pub use transaction::Transaction;
pub use transaction::TransactionData;
pub use transaction::TransactionOffer;
pub use transaction::TransactionReason;
pub use transaction::TransactionStream;
pub use verification_result::VerificationMetadata;
pub use verification_result::VerificationResult;
pub use window::NSWindowHandle;

Modules§

advanced_commerce
StoreKit advanced-commerce wrappers and related value types.
app_store
Wrappers for StoreKit.AppStore APIs.
app_transaction
Wrappers for StoreKit.AppTransaction.
async_apiasync
Async API for StoreKit — Tier 1 Future wrappers.
error
Typed errors surfaced by the StoreKit framework.
external_purchase
Wrappers for StoreKit external purchase APIs.
message
Wrappers for StoreKit.Message and related APIs.
prelude
Common imports.
product
Wrappers for StoreKit.Product and related value types.
purchase_intent
Wrappers for StoreKit.PurchaseIntent and its stream APIs.
purchase_option
Purchase options and results used with StoreKit.Product.purchase.
receipt_validator
Helpers for StoreKit receipts, app transactions, and JWS payloads.
refund
Helpers for StoreKit refund request APIs.
renewal_info
Wrappers for StoreKit.RenewalInfo and related enums.
renewal_state
Wrappers for StoreKit.Product.SubscriptionInfo.RenewalState.
store_context
Helpers that collect bundle context used alongside StoreKit APIs.
storefront
Wrappers for StoreKit.Storefront and storefront streams.
subscription
Wrappers for StoreKit.Product.SubscriptionInfo value types.
subscription_info
Wrappers for StoreKit.Product.SubscriptionInfo.Status and related APIs.
transaction
Wrappers for StoreKit.Transaction and transaction streams.
verification_result
Wrappers for StoreKit.VerificationResult and verification metadata.
window
Opaque NSWindow handles used with StoreKit APIs that present UI.

Structs§

ProductFormatting
Carries localized formatting derived from StoreKit.Product.
SubscriptionGroupStatusStream
Wraps the StoreKit subscription-group status stream.
SubscriptionGroupStatuses
Carries the StoreKit statuses for a subscription group.
SubscriptionStatusStream
Wraps the StoreKit subscription status update stream.