sellapp-sdk 0.1.1

Official Rust SDK for the SellApp API: manage products, orders, subscriptions, and customers.
// This file is auto-generated by oagen. Do not edit.

use crate::client::Client;
#[allow(unused_imports)]
use crate::enums::*;
use crate::error::Error;
#[allow(unused_imports)]
use crate::models::*;
#[allow(unused_imports)]
use serde::Serialize;

pub struct AccountApi<'a> {
    pub(crate) client: &'a Client,
}

#[derive(Debug, Clone, Serialize)]
pub struct CreateStoreParams {
    /// Request body sent with this call.
    ///
    /// Required.
    #[serde(skip)]
    pub body: SdkCreateStoreRequestApplicationJson,
}

impl CreateStoreParams {
    /// Construct a new `CreateStoreParams` with the required fields set.
    #[allow(deprecated)]
    pub fn new(body: SdkCreateStoreRequestApplicationJson) -> Self {
        Self { body }
    }
}

#[derive(Debug, Clone, Serialize)]
pub struct GetStorePermissionsParams {
    /// Store slug. Required for OAuth access tokens. API keys may omit it to use their current store, or the first accessible store when no current store is selected.
    ///
    /// Required.
    #[serde(rename = "X-STORE")]
    pub x_store: String,
}

impl GetStorePermissionsParams {
    /// Construct a new `GetStorePermissionsParams` with the required fields set.
    #[allow(deprecated)]
    pub fn new(x_store: impl Into<String>) -> Self {
        Self {
            x_store: x_store.into(),
        }
    }
}

impl<'a> AccountApi<'a> {
    /// Read your profile
    ///
    /// Read your account identity and credential type with account:read on an API key or the official CLI OAuth grant. No store or X-STORE is needed, including before creating your first store. Browser and customer sessions are rejected.
    pub async fn get_account(&self) -> Result<SdkGetAccountResponseValue200ApplicationJson, Error> {
        self.get_account_with_options(None).await
    }

    /// Variant of [`Self::get_account`] that accepts per-request [`crate::RequestOptions`].
    pub async fn get_account_with_options(
        &self,
        options: Option<&crate::RequestOptions>,
    ) -> Result<SdkGetAccountResponseValue200ApplicationJson, Error> {
        self.get_account_raw(options)
            .await
            .map(|response| response.data)
    }

    /// Returns the typed result together with status, headers, and request ID.
    pub async fn get_account_raw(
        &self,
        options: Option<&crate::RequestOptions>,
    ) -> Result<crate::RawResponse<SdkGetAccountResponseValue200ApplicationJson>, Error> {
        let path = "/v2/me".to_string();
        let method = http::Method::GET;
        let mut merged = options.cloned().unwrap_or_default();
        merged.idempotency_supported = false;
        merged.operation_id = Some("getAccount".to_string());
        let options = Some(&merged);
        self.client
            .request_with_query_schema_opts_raw(method, &path, &(), options, "GET /v2/me")
            .await
    }

    /// List accessible stores
    ///
    /// List all stores you can currently access, including stores created or joined after login. API keys require account:read; selected-store keys see only the intersection of current membership and their fixed store list. An empty list is a successful result. Use a returned slug in X-STORE for store operations.
    pub async fn list_stores(&self) -> Result<SdkListStoresResponseValue200ApplicationJson, Error> {
        self.list_stores_with_options(None).await
    }

    /// Variant of [`Self::list_stores`] that accepts per-request [`crate::RequestOptions`].
    pub async fn list_stores_with_options(
        &self,
        options: Option<&crate::RequestOptions>,
    ) -> Result<SdkListStoresResponseValue200ApplicationJson, Error> {
        self.list_stores_raw(options)
            .await
            .map(|response| response.data)
    }

    /// Returns the typed result together with status, headers, and request ID.
    pub async fn list_stores_raw(
        &self,
        options: Option<&crate::RequestOptions>,
    ) -> Result<crate::RawResponse<SdkListStoresResponseValue200ApplicationJson>, Error> {
        let path = "/v2/stores".to_string();
        let method = http::Method::GET;
        let mut merged = options.cloned().unwrap_or_default();
        merged.idempotency_supported = false;
        merged.operation_id = Some("listStores".to_string());
        let options = Some(&merged);
        self.client
            .request_with_query_schema_opts_raw(method, &path, &(), options, "GET /v2/stores")
            .await
    }

    /// Create a store
    ///
    /// Create a store owned by the authenticated user, with the same defaults as dashboard creation. Requires stores:create on an unrestricted user-owned API key, or the official CLI OAuth admin grant. Customer and browser sessions and direct MCP bearer tokens are rejected; MCP uses reviewed server delegation. Selected-store keys cannot create stores. No existing store or X-STORE header is needed; Name and slug are required; slug is normalized to lowercase. Visibility defaults to PUBLIC. This does not change your dashboard's selected store. Idempotency-Key is required and retained for 24 hours: reuse the same key and identical body after a lost response. A conflicting request returns 409; invalid or duplicate slugs return 422. Retries are bound to the user and operation across token rotation and supported credential types; current authorization is checked before replay. Store defaults and the successful retry receipt commit together. You can create one new store per user every 60 seconds, across all credentials. A new creation during that interval returns 429 with Retry-After and rate-limit headers. Wait for that delay and retry the same key and body. Replaying a successful original key recovers its store without creating another or consuming another creation allowance.
    pub async fn create_store(
        &self,
        params: CreateStoreParams,
    ) -> Result<SdkCreateStoreResponseValue201ApplicationJson, Error> {
        self.create_store_with_options(params, None).await
    }

    /// Variant of [`Self::create_store`] that accepts per-request [`crate::RequestOptions`].
    pub async fn create_store_with_options(
        &self,
        params: CreateStoreParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<SdkCreateStoreResponseValue201ApplicationJson, Error> {
        self.create_store_raw(params, options)
            .await
            .map(|response| response.data)
    }

    /// Returns the typed result together with status, headers, and request ID.
    pub async fn create_store_raw(
        &self,
        params: CreateStoreParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<crate::RawResponse<SdkCreateStoreResponseValue201ApplicationJson>, Error> {
        let path = "/v2/stores".to_string();
        let method = http::Method::POST;
        let mut merged = options.cloned().unwrap_or_default();
        merged.idempotency_supported = true;
        merged.operation_id = Some("createStore".to_string());
        let options = Some(&merged);
        self.client
            .request_with_body_schema_opts_raw(
                method,
                &path,
                &params,
                Some(&params.body),
                options,
                "POST /v2/stores",
            )
            .await
    }

    /// Read an accessible store
    ///
    /// Read a currently accessible store by numeric ID with account:read on an API key or official CLI OAuth. No X-STORE is needed. Keys with selected stores must include this ID. Inaccessible stores return 404.
    pub async fn get_store(
        &self,
        store: &str,
    ) -> Result<SdkGetStoreResponseValue200ApplicationJson, Error> {
        self.get_store_with_options(store, None).await
    }

    /// Variant of [`Self::get_store`] that accepts per-request [`crate::RequestOptions`].
    pub async fn get_store_with_options(
        &self,
        store: &str,
        options: Option<&crate::RequestOptions>,
    ) -> Result<SdkGetStoreResponseValue200ApplicationJson, Error> {
        self.get_store_raw(store, options)
            .await
            .map(|response| response.data)
    }

    /// Returns the typed result together with status, headers, and request ID.
    pub async fn get_store_raw(
        &self,
        store: &str,
        options: Option<&crate::RequestOptions>,
    ) -> Result<crate::RawResponse<SdkGetStoreResponseValue200ApplicationJson>, Error> {
        let store = crate::client::path_segment(store);
        let path = format!("/v2/stores/{store}");
        let method = http::Method::GET;
        let mut merged = options.cloned().unwrap_or_default();
        merged.idempotency_supported = false;
        merged.operation_id = Some("getStore".to_string());
        let options = Some(&merged);
        self.client
            .request_with_query_schema_opts_raw(
                method,
                &path,
                &(),
                options,
                "GET /v2/stores/{store}",
            )
            .await
    }

    /// Inspect effective permissions
    ///
    /// Inspect authorization for the explicit X-STORE slug. API keys require account:read and return key_abilities, store_permissions, effective_abilities and store_access. OAuth returns its granted scopes and reviewed permission categories. The credential_type identifies the typed response. These checks do not establish record-state, provider or financial eligibility.
    pub async fn get_store_permissions(
        &self,
        params: GetStorePermissionsParams,
    ) -> Result<SdkGetStorePermissionsResponseValue200ApplicationJson, Error> {
        self.get_store_permissions_with_options(params, None).await
    }

    /// Variant of [`Self::get_store_permissions`] that accepts per-request [`crate::RequestOptions`].
    pub async fn get_store_permissions_with_options(
        &self,
        params: GetStorePermissionsParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<SdkGetStorePermissionsResponseValue200ApplicationJson, Error> {
        self.get_store_permissions_raw(params, options)
            .await
            .map(|response| response.data)
    }

    /// Returns the typed result together with status, headers, and request ID.
    pub async fn get_store_permissions_raw(
        &self,
        params: GetStorePermissionsParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<crate::RawResponse<SdkGetStorePermissionsResponseValue200ApplicationJson>, Error>
    {
        let path = "/v2/permissions".to_string();
        let method = http::Method::GET;
        let mut merged = options.cloned().unwrap_or_default();
        merged.idempotency_supported = false;
        merged.operation_id = Some("getStorePermissions".to_string());
        let options = Some(&merged);
        self.client
            .request_with_query_schema_opts_raw(
                method,
                &path,
                &params,
                options,
                "GET /v2/permissions",
            )
            .await
    }
}