pub struct ShopifyConfigBuilder { /* private fields */ }Expand description
Builder for constructing ShopifyConfig instances.
This builder provides a fluent API for configuring the SDK. Required fields
are api_key and api_secret_key. All other fields have sensible defaults.
§Defaults
api_version: Latest stable versionis_embedded:truescopes: Emptyhost:Noneuser_agent_prefix:Noneold_api_secret_key:Nonereject_deprecated_versions:false
§Example
use shopify_sdk::{ShopifyConfig, ApiKey, ApiSecretKey, ApiVersion, HostUrl};
let config = ShopifyConfig::builder()
.api_key(ApiKey::new("key").unwrap())
.api_secret_key(ApiSecretKey::new("secret").unwrap())
.api_version(ApiVersion::V2024_10)
.host(HostUrl::new("https://myapp.example.com").unwrap())
.is_embedded(false)
.user_agent_prefix("MyApp/1.0")
.build()
.unwrap();Implementations§
Source§impl ShopifyConfigBuilder
impl ShopifyConfigBuilder
Sourcepub fn api_secret_key(self, key: ApiSecretKey) -> Self
pub fn api_secret_key(self, key: ApiSecretKey) -> Self
Sets the API secret key (required).
Sourcepub fn old_api_secret_key(self, key: ApiSecretKey) -> Self
pub fn old_api_secret_key(self, key: ApiSecretKey) -> Self
Sets the old API secret key for key rotation support.
When validating OAuth HMAC signatures, the SDK will try the primary secret key first, then fall back to this old key if validation fails. This allows in-flight OAuth flows to complete during key rotation.
§Example
use shopify_sdk::{ShopifyConfig, ApiKey, ApiSecretKey};
// During key rotation, configure both keys
let config = ShopifyConfig::builder()
.api_key(ApiKey::new("key").unwrap())
.api_secret_key(ApiSecretKey::new("new-secret").unwrap())
.old_api_secret_key(ApiSecretKey::new("old-secret").unwrap())
.build()
.unwrap();Sourcepub fn scopes(self, scopes: AuthScopes) -> Self
pub fn scopes(self, scopes: AuthScopes) -> Self
Sets the OAuth scopes.
Sourcepub fn api_version(self, version: ApiVersion) -> Self
pub fn api_version(self, version: ApiVersion) -> Self
Sets the API version.
Sourcepub const fn is_embedded(self, embedded: bool) -> Self
pub const fn is_embedded(self, embedded: bool) -> Self
Sets whether the app is embedded in the Shopify admin.
Sourcepub fn user_agent_prefix(self, prefix: impl Into<String>) -> Self
pub fn user_agent_prefix(self, prefix: impl Into<String>) -> Self
Sets the user agent prefix for HTTP requests.
Sourcepub const fn reject_deprecated_versions(self, reject: bool) -> Self
pub const fn reject_deprecated_versions(self, reject: bool) -> Self
Sets whether to reject deprecated API versions.
When true, build() will return a
ConfigError::DeprecatedApiVersion error if the configured API version
is past Shopify’s support window.
When false (the default), deprecated versions will log a warning via
tracing but the configuration will still be created.
§Example
use shopify_api::{ShopifyConfig, ApiKey, ApiSecretKey, ApiVersion, ConfigError};
// This will fail because V2024_01 is deprecated
let result = ShopifyConfig::builder()
.api_key(ApiKey::new("key").unwrap())
.api_secret_key(ApiSecretKey::new("secret").unwrap())
.api_version(ApiVersion::V2024_01)
.reject_deprecated_versions(true)
.build();
assert!(matches!(result, Err(ConfigError::DeprecatedApiVersion { .. })));Sourcepub fn on_deprecation<F>(self, callback: F) -> Self
pub fn on_deprecation<F>(self, callback: F) -> Self
Sets a callback to be invoked when API deprecation notices are received.
The callback is called whenever the SDK receives a response with the
X-Shopify-API-Deprecated-Reason header. This allows you to track
deprecated API usage in your monitoring systems.
§Example
use shopify_api::{ShopifyConfig, ApiKey, ApiSecretKey};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
let deprecation_count = Arc::new(AtomicUsize::new(0));
let count_clone = Arc::clone(&deprecation_count);
let config = ShopifyConfig::builder()
.api_key(ApiKey::new("key").unwrap())
.api_secret_key(ApiSecretKey::new("secret").unwrap())
.on_deprecation(move |info| {
count_clone.fetch_add(1, Ordering::SeqCst);
eprintln!("Deprecated: {} at {:?}", info.reason, info.path);
})
.build()
.unwrap();Sourcepub fn build(self) -> Result<ShopifyConfig, ConfigError>
pub fn build(self) -> Result<ShopifyConfig, ConfigError>
Builds the ShopifyConfig, validating that required fields are set.
§Errors
Returns ConfigError::MissingRequiredField if api_key or
api_secret_key are not set.
Returns ConfigError::DeprecatedApiVersion if
reject_deprecated_versions(true) is set
and the configured API version is deprecated.