// 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 AddOnsApi<'a> {
pub(crate) client: &'a Client,
}
#[derive(Debug, Clone, Serialize)]
pub struct ListParams {
/// Number of items to return per page.
///
/// Defaults to `15`.
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<i64>,
/// Page number to return.
///
/// Defaults to `1`.
#[serde(skip_serializing_if = "Option::is_none")]
pub page: Option<i64>,
/// Set to false to return at most 100 matching items in one data array without pagination links or metadata.
///
/// Defaults to `true`.
#[serde(skip_serializing_if = "Option::is_none")]
pub pagination: Option<bool>,
/// Include draft add-ons alongside published add-ons.
#[serde(skip_serializing_if = "Option::is_none")]
pub with_drafts: Option<bool>,
/// Return only draft add-ons.
#[serde(skip_serializing_if = "Option::is_none")]
pub only_drafts: Option<bool>,
/// 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.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "X-STORE")]
pub x_store: Option<String>,
}
impl Default for ListParams {
#[allow(deprecated)]
fn default() -> Self {
Self {
limit: Some(15),
page: Some(1),
pagination: Some(true),
with_drafts: Default::default(),
only_drafts: Default::default(),
x_store: Default::default(),
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct CreateParams {
/// 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.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "X-STORE")]
pub x_store: Option<String>,
/// Request body sent with this call.
///
/// Required.
#[serde(skip)]
pub body: SdkCreateAddOnDraftRequestApplicationJson,
}
impl CreateParams {
/// Construct a new `CreateParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: SdkCreateAddOnDraftRequestApplicationJson) -> Self {
Self {
x_store: Default::default(),
body,
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct SearchParams {
/// Number of items to return per page.
///
/// Defaults to `15`.
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<i64>,
/// Page number to return.
///
/// Defaults to `1`.
#[serde(skip_serializing_if = "Option::is_none")]
pub page: Option<i64>,
/// Set to false to return at most 100 matching items in one data array without pagination links or metadata.
///
/// Defaults to `true`.
#[serde(skip_serializing_if = "Option::is_none")]
pub pagination: Option<bool>,
/// Include draft add-ons alongside published add-ons.
#[serde(skip_serializing_if = "Option::is_none")]
pub with_drafts: Option<bool>,
/// Return only draft add-ons.
#[serde(skip_serializing_if = "Option::is_none")]
pub only_drafts: Option<bool>,
/// 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.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "X-STORE")]
pub x_store: Option<String>,
/// Request body sent with this call.
///
/// Required.
#[serde(skip)]
pub body: SdkSearchAddOnsRequestApplicationJson,
}
impl SearchParams {
/// Construct a new `SearchParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: SdkSearchAddOnsRequestApplicationJson) -> Self {
Self {
limit: Some(15),
page: Some(1),
pagination: Some(true),
with_drafts: Default::default(),
only_drafts: Default::default(),
x_store: Default::default(),
body,
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct GetParams {
/// Set to false to return at most 100 matching items in one data array without pagination links or metadata.
///
/// Defaults to `true`.
#[serde(skip_serializing_if = "Option::is_none")]
pub pagination: Option<bool>,
/// Include draft add-ons alongside published add-ons.
#[serde(skip_serializing_if = "Option::is_none")]
pub with_drafts: Option<bool>,
/// Return only draft add-ons.
#[serde(skip_serializing_if = "Option::is_none")]
pub only_drafts: Option<bool>,
/// 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.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "X-STORE")]
pub x_store: Option<String>,
}
impl Default for GetParams {
#[allow(deprecated)]
fn default() -> Self {
Self {
pagination: Some(true),
with_drafts: Default::default(),
only_drafts: Default::default(),
x_store: Default::default(),
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct ReplaceParams {
/// 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.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "X-STORE")]
pub x_store: Option<String>,
/// Request body sent with this call.
///
/// Required.
#[serde(skip)]
pub body: SdkReplaceAddOnRequestApplicationJson,
}
impl ReplaceParams {
/// Construct a new `ReplaceParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: SdkReplaceAddOnRequestApplicationJson) -> Self {
Self {
x_store: Default::default(),
body,
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct UpdateParams {
/// 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.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "X-STORE")]
pub x_store: Option<String>,
/// Request body sent with this call.
///
/// Required.
#[serde(skip)]
pub body: SdkReplaceAddOnRequestApplicationJson,
}
impl UpdateParams {
/// Construct a new `UpdateParams` with the required fields set.
#[allow(deprecated)]
pub fn new(body: SdkReplaceAddOnRequestApplicationJson) -> Self {
Self {
x_store: Default::default(),
body,
}
}
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct DeleteParams {
/// 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.
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(rename = "X-STORE")]
pub x_store: Option<String>,
}
impl<'a> AddOnsApi<'a> {
/// List add-ons
///
/// Retrieve the store's add-ons with compact variant references and ordered parent-product assignments. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request.
pub async fn list(
&self,
params: ListParams,
) -> Result<SdkListAddOnsResponseValue200ApplicationJson, Error> {
self.list_with_options(params, None).await
}
/// Variant of [`Self::list`] that accepts per-request [`crate::RequestOptions`].
pub async fn list_with_options(
&self,
params: ListParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkListAddOnsResponseValue200ApplicationJson, Error> {
self.list_raw(params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn list_raw(
&self,
params: ListParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkListAddOnsResponseValue200ApplicationJson>, Error> {
let path = "/v2/addons".to_string();
let method = http::Method::GET;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("listAddOns".to_string());
let options = Some(&merged);
self.client
.request_with_query_schema_opts_raw(method, &path, ¶ms, options, "GET /v2/addons")
.await
}
/// Create an add-on draft
///
/// Create an add-on, optionally including its variant and parent_product_ids in one transaction. Set is_draft false with variant to publish immediately. Without variant, new add-ons remain drafts. Requires the listing API-key ability and store listing permission. Invalid variants or parent products roll back the complete creation. This call does not have response-replay idempotency; check for the created add-on before retrying a request whose response was lost. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request.
pub async fn create(
&self,
params: CreateParams,
) -> Result<SdkCreateAddOnDraftResponseValue201ApplicationJson, Error> {
self.create_with_options(params, None).await
}
/// Variant of [`Self::create`] that accepts per-request [`crate::RequestOptions`].
pub async fn create_with_options(
&self,
params: CreateParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkCreateAddOnDraftResponseValue201ApplicationJson, Error> {
self.create_raw(params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn create_raw(
&self,
params: CreateParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkCreateAddOnDraftResponseValue201ApplicationJson>, Error> {
let path = "/v2/addons".to_string();
let method = http::Method::POST;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("createAddOnDraft".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"POST /v2/addons",
)
.await
}
/// Search add-ons
///
/// Search add-ons by title, slug, or description and optionally filter or sort the result set. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request.
pub async fn search(
&self,
params: SearchParams,
) -> Result<SdkSearchAddOnsResponseValue200ApplicationJson, Error> {
self.search_with_options(params, None).await
}
/// Variant of [`Self::search`] that accepts per-request [`crate::RequestOptions`].
pub async fn search_with_options(
&self,
params: SearchParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkSearchAddOnsResponseValue200ApplicationJson, Error> {
self.search_raw(params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn search_raw(
&self,
params: SearchParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkSearchAddOnsResponseValue200ApplicationJson>, Error> {
let path = "/v2/addons/search".to_string();
let method = http::Method::POST;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("searchAddOns".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"POST /v2/addons/search",
)
.await
}
/// Retrieve an add-on
///
/// Retrieve one add-on owned by the authenticated store. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request.
pub async fn get(
&self,
addon: &str,
params: GetParams,
) -> Result<SdkGetAddOnResponseValue200ApplicationJson, Error> {
self.get_with_options(addon, params, None).await
}
/// Variant of [`Self::get`] that accepts per-request [`crate::RequestOptions`].
pub async fn get_with_options(
&self,
addon: &str,
params: GetParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkGetAddOnResponseValue200ApplicationJson, Error> {
self.get_raw(addon, params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn get_raw(
&self,
addon: &str,
params: GetParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkGetAddOnResponseValue200ApplicationJson>, Error> {
let addon = crate::client::path_segment(addon);
let path = format!("/v2/addons/{addon}");
let method = http::Method::GET;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("getAddOn".to_string());
let options = Some(&merged);
self.client
.request_with_query_schema_opts_raw(
method,
&path,
¶ms,
options,
"GET /v2/addons/{addon}",
)
.await
}
/// Update an add-on
///
/// Update an add-on and optionally replace its ordered parent-product assignments. Publication is rejected unless the add-on has exactly one published, fixed-price, single-payment variant. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request.
pub async fn replace(
&self,
addon: &str,
params: ReplaceParams,
) -> Result<SdkReplaceAddOnResponseValue200ApplicationJson, Error> {
self.replace_with_options(addon, params, None).await
}
/// Variant of [`Self::replace`] that accepts per-request [`crate::RequestOptions`].
pub async fn replace_with_options(
&self,
addon: &str,
params: ReplaceParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkReplaceAddOnResponseValue200ApplicationJson, Error> {
self.replace_raw(addon, params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn replace_raw(
&self,
addon: &str,
params: ReplaceParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkReplaceAddOnResponseValue200ApplicationJson>, Error> {
let addon = crate::client::path_segment(addon);
let path = format!("/v2/addons/{addon}");
let method = http::Method::PUT;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("replaceAddOn".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"PUT /v2/addons/{addon}",
)
.await
}
/// Update an add-on
///
/// Update an add-on and optionally replace its ordered parent-product assignments. Publication is rejected unless the add-on has exactly one published, fixed-price, single-payment variant. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request.
pub async fn update(
&self,
addon: &str,
params: UpdateParams,
) -> Result<SdkUpdateAddOnResponseValue200ApplicationJson, Error> {
self.update_with_options(addon, params, None).await
}
/// Variant of [`Self::update`] that accepts per-request [`crate::RequestOptions`].
pub async fn update_with_options(
&self,
addon: &str,
params: UpdateParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkUpdateAddOnResponseValue200ApplicationJson, Error> {
self.update_raw(addon, params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn update_raw(
&self,
addon: &str,
params: UpdateParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkUpdateAddOnResponseValue200ApplicationJson>, Error> {
let addon = crate::client::path_segment(addon);
let path = format!("/v2/addons/{addon}");
let method = http::Method::PATCH;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("updateAddOn".to_string());
let options = Some(&merged);
self.client
.request_with_body_schema_opts_raw(
method,
&path,
¶ms,
Some(¶ms.body),
options,
"PATCH /v2/addons/{addon}",
)
.await
}
/// Delete an add-on
///
/// Soft-delete an add-on and remove its product assignments. The deleted resource is returned for audit and reconciliation workflows. OAuth callers use the admin grant and select a store with X-STORE. Current membership and role permissions apply to every request.
pub async fn delete(
&self,
addon: &str,
params: DeleteParams,
) -> Result<SdkDeleteAddOnResponseValue200ApplicationJson, Error> {
self.delete_with_options(addon, params, None).await
}
/// Variant of [`Self::delete`] that accepts per-request [`crate::RequestOptions`].
pub async fn delete_with_options(
&self,
addon: &str,
params: DeleteParams,
options: Option<&crate::RequestOptions>,
) -> Result<SdkDeleteAddOnResponseValue200ApplicationJson, Error> {
self.delete_raw(addon, params, options)
.await
.map(|response| response.data)
}
/// Returns the typed result together with status, headers, and request ID.
pub async fn delete_raw(
&self,
addon: &str,
params: DeleteParams,
options: Option<&crate::RequestOptions>,
) -> Result<crate::RawResponse<SdkDeleteAddOnResponseValue200ApplicationJson>, Error> {
let addon = crate::client::path_segment(addon);
let path = format!("/v2/addons/{addon}");
let method = http::Method::DELETE;
let mut merged = options.cloned().unwrap_or_default();
merged.idempotency_supported = false;
merged.operation_id = Some("deleteAddOn".to_string());
let options = Some(&merged);
self.client
.request_with_query_schema_opts_raw(
method,
&path,
¶ms,
options,
"DELETE /v2/addons/{addon}",
)
.await
}
}