stackless_integrations/providers/wix/
headless.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-wix";
14
15#[derive(Debug, Serialize)]
16pub struct WixHeadlessConfig {
17 #[serde(skip_serializing_if = "Option::is_none")]
18 pub plan: Option<String>,
19 #[serde(skip_serializing_if = "Option::is_none")]
20 pub wix_project_name: Option<String>,
21}
22
23impl CatalogService for WixHeadlessConfig {
24 const REFERENCE: &'static str = "wix/headless";
25}
26
27#[derive(Debug)]
28pub struct WixHeadless;
29
30impl Hostable for WixHeadless {
31 const PROVIDER: &'static str = "wix";
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] =
36 &["wix_client_id", "wix_client_secret", "wix_metasite_id"];
37}
38
39impl FamilyResource for WixHeadless {
40 type Config = WixHeadlessConfig;
41 const PROVIDER_PREFIX: &'static str = "WIX";
42 const OUTPUT_FIELDS: &'static [(&'static str, &'static str, bool)] = &[
43 ("WIX_CLIENT_ID", "wix_client_id", true),
44 ("WIX_CLIENT_SECRET", "wix_client_secret", true),
45 ("WIX_METASITE_ID", "wix_metasite_id", true),
46 ];
47
48 fn build_config(ctx: &ProvisionContext<'_>) -> Result<WixHeadlessConfig, IntegrationError> {
49 let config = super::integration_config(ctx)?;
50 Ok(WixHeadlessConfig {
51 plan: super::interp_optional(ctx, &config, "plan")?,
52 wix_project_name: super::interp_optional(ctx, &config, "wix_project_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 &WixHeadlessConfig {
84 plan: None,
85 wix_project_name: None,
86 },
87 );
88 assert!(
89 failures.is_empty(),
90 "wix/headless 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_headless","object":"v2.provisioning.provider_service_detail","provider_id":"prvdr_wix","provider_name":"Wix","service_id":"headless","categories":["database"],"kind":"deployable","scope":"project","availability":"available","development":false,"livemode":true,"pricing":{"type":"paid"},"configuration_schema":{"additionalProperties":false,"properties":{"plan":{"description":"Pre-filled from the tier selected above; override only if you need to.","enum":["free","premium"],"title":"Plan","type":"string"},"wix_project_name":{"description":"Human-readable name for the Wix site that backs this project. Shown in the Wix dashboard.","maxLength":50,"minLength":1,"title":"Wix project name","type":"string"}},"required":[],"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 = "wix"
106[services.api]
107source = { repo = "r", ref = "main" }
108env = { OUT = "${integrations.res.wix_client_id}" }
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!({"WIX_WIX_CLIENT_ID": "val_wix_client_id", "WIX_WIX_CLIENT_SECRET": "val_wix_client_secret", "WIX_WIX_METASITE_ID": "val_wix_metasite_id"}),
122 0,
123 );
124 let dir = tempfile::tempdir().unwrap();
125 std::fs::write(
126 dir.path().join("stackless.toml"),
127 "[stack]\nname=\"atto\"\n",
128 )
129 .unwrap();
130 let stripe = StripeProjects::new(&runner, dir.path());
131
132 let resource = WixHeadless
133 .provision(
134 &stripe.as_dyn(),
135 &test_def(),
136 dir.path(),
137 "demo",
138 "res",
139 "local",
140 false,
141 )
142 .await
143 .unwrap();
144 assert_eq!(resource.resource_kind, "integration-wix");
145 let payload: ResourcePayload = serde_json::from_str(&resource.payload).unwrap();
146 assert_eq!(payload.outputs["wix_client_id"], "val_wix_client_id");
147 assert_eq!(
148 payload.outputs["wix_client_secret"],
149 "val_wix_client_secret"
150 );
151 assert_eq!(payload.outputs["wix_metasite_id"], "val_wix_metasite_id");
152 }
153}