stackless_integrations/providers/shopify/
store.rs1use std::collections::BTreeMap;
4
5use serde::Serialize;
6use stackless_stripe_projects::catalog::verify::CatalogService;
7use stackless_stripe_projects::provision::ProvisionContext;
8
9use super::FamilyResource;
10use crate::error::IntegrationError;
11use crate::hostable::{ConfigScope, Hostable, IntegrationHosting};
12
13pub const RESOURCE_KIND: &str = "integration-shopify";
14
15#[derive(Debug, Serialize)]
16pub struct ShopifyStoreConfig {
17 #[serde(skip_serializing_if = "Option::is_none")]
18 pub plan: Option<String>,
19 #[serde(skip_serializing_if = "Option::is_none")]
20 pub store_name: Option<String>,
21}
22
23impl CatalogService for ShopifyStoreConfig {
24 const REFERENCE: &'static str = "shopify/store";
25}
26
27#[derive(Debug)]
28pub struct ShopifyStore;
29
30impl Hostable for ShopifyStore {
31 const PROVIDER: &'static str = "shopify";
32 const HOSTING: IntegrationHosting = IntegrationHosting::Managed;
33 const CONFIG_SCOPE: ConfigScope = ConfigScope::GlobalOnly;
34 const RESOURCE_KIND: &'static str = RESOURCE_KIND;
35 const OUTPUTS: &'static [&'static str] = &["shop_domain", "shop_login_url", "signup_token"];
36}
37
38impl FamilyResource for ShopifyStore {
39 type Config = ShopifyStoreConfig;
40 const PROVIDER_PREFIX: &'static str = "SHOPIFY";
41 const OUTPUT_FIELDS: &'static [(&'static str, &'static str, bool)] = &[
43 ("SHOP_DOMAIN", "shop_domain", true),
44 ("SHOP_LOGIN_URL", "shop_login_url", true),
45 ("SIGNUP_TOKEN", "signup_token", true),
46 ];
47
48 fn build_config(ctx: &ProvisionContext<'_>) -> Result<ShopifyStoreConfig, IntegrationError> {
49 let config = super::integration_config(ctx)?;
50 Ok(ShopifyStoreConfig {
51 plan: super::interp_optional(ctx, &config, "plan")?,
52 store_name: super::interp_optional(ctx, &config, "store_name")?,
53 })
54 }
55}
56
57pub fn validate_config(
58 name: &str,
59 config: &BTreeMap<String, toml::Value>,
60) -> Result<(), IntegrationError> {
61 let _ = (name, config);
62 Ok(())
63}
64
65#[cfg(test)]
66mod tests {
67 use super::*;
68 use crate::ProviderOps;
69 use crate::resource::ResourcePayload;
70 use stackless_core::def::StackDef;
71 use stackless_stripe_projects::stripe::StripeProjects;
72 use stackless_stripe_projects::test_support;
73
74 #[test]
75 fn config_matches_catalog() {
76 const FIXTURE: &str = include_str!(concat!(
77 env!("CARGO_MANIFEST_DIR"),
78 "/../stackless-stripe-projects/tests/fixtures/catalog.json"
79 ));
80 let catalog = stackless_stripe_projects::Catalog::from_json_envelope(FIXTURE).unwrap();
81 let failures = stackless_stripe_projects::verify_service(
82 &catalog,
83 &ShopifyStoreConfig {
84 plan: None,
85 store_name: None,
86 },
87 );
88 assert!(
89 failures.is_empty(),
90 "shopify/store catalog gaps:\n{}",
91 failures.join("\n")
92 );
93 }
94
95 const CATALOG_ENVELOPE: &str = r##"{"ok":true,"command":"projects catalog","data":{"last_updated":"2026-07-11T00:00:00Z","services":[{"id":"prvsvc_store","object":"v2.provisioning.provider_service_detail","provider_id":"prvdr_shopify","provider_name":"Shopify","service_id":"store","categories":["ecommerce"],"kind":"deployable","scope":"project","availability":"available","development":false,"livemode":true,"pricing":{"type":"paid"},"configuration_schema":{"additionalProperties":false,"properties":{"plan":{"enum":["trial","basic","grow","advanced"],"type":"string"},"store_name":{"maxLength":50,"minLength":1,"type":"string"}},"optional":["store_name","plan"],"type":"object"}}]}}"##;
96
97 fn test_def() -> StackDef {
98 StackDef::parse(
99 r#"
100[stack]
101name = "atto"
102[stack.projects.stripe]
103project = "project_1"
104[integrations.res]
105provider = "shopify"
106[services.api]
107source = { repo = "r", ref = "main" }
108env = { OUT = "${integrations.res.shop_domain}" }
109health = { path = "/health" }
110[services.api.local]
111run = "true"
112"#,
113 )
114 .unwrap()
115 }
116
117 #[tokio::test]
118 async fn provision_records_outputs() {
119 let runner = test_support::provision_script(
120 CATALOG_ENVELOPE,
121 serde_json::json!({
122 "SHOPIFY_SHOP_DOMAIN": "val_shop_domain",
123 "SHOPIFY_SHOP_LOGIN_URL": "val_shop_login_url",
124 "SHOPIFY_SIGNUP_TOKEN": "val_signup_token"
125 }),
126 0,
127 );
128 let dir = tempfile::tempdir().unwrap();
129 std::fs::write(
130 dir.path().join("stackless.toml"),
131 "[stack]\nname=\"atto\"\n",
132 )
133 .unwrap();
134 let stripe = StripeProjects::new(&runner, dir.path());
135
136 let resource = ShopifyStore
137 .provision(
138 &stripe.as_dyn(),
139 &test_def(),
140 dir.path(),
141 "demo",
142 "res",
143 "local",
144 false,
145 )
146 .await
147 .unwrap();
148 assert_eq!(resource.resource_kind, "integration-shopify");
149 let payload: ResourcePayload = serde_json::from_str(&resource.payload).unwrap();
150 assert_eq!(payload.outputs["shop_domain"], "val_shop_domain");
151 assert_eq!(payload.outputs["shop_login_url"], "val_shop_login_url");
152 assert_eq!(payload.outputs["signup_token"], "val_signup_token");
153 }
154}