Skip to main content

stackless_integrations/providers/wix/
headless.rs

1//! `wix/headless` integration.
2
3use 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] = &["app_id"];
36}
37
38impl FamilyResource for WixHeadless {
39    type Config = WixHeadlessConfig;
40    const PROVIDER_PREFIX: &'static str = "WIX";
41    // Provisional until pinned by `mise run discover wix/headless`.
42    const OUTPUT_FIELDS: &'static [(&'static str, &'static str, bool)] =
43        &[("APP_ID", "app_id", true)];
44
45    fn build_config(ctx: &ProvisionContext<'_>) -> Result<WixHeadlessConfig, IntegrationError> {
46        let config = super::integration_config(ctx)?;
47        Ok(WixHeadlessConfig {
48            plan: super::interp_optional(ctx, &config, "plan")?,
49            wix_project_name: super::interp_optional(ctx, &config, "wix_project_name")?,
50        })
51    }
52}
53
54pub fn validate_config(
55    name: &str,
56    config: &BTreeMap<String, toml::Value>,
57) -> Result<(), IntegrationError> {
58    let _ = (name, config);
59    Ok(())
60}
61
62#[cfg(test)]
63mod tests {
64    use super::*;
65    use crate::ProviderOps;
66    use crate::resource::ResourcePayload;
67    use stackless_core::def::StackDef;
68    use stackless_stripe_projects::stripe::StripeProjects;
69    use stackless_stripe_projects::test_support;
70
71    #[test]
72    fn config_matches_catalog() {
73        const FIXTURE: &str = include_str!(concat!(
74            env!("CARGO_MANIFEST_DIR"),
75            "/../stackless-stripe-projects/tests/fixtures/catalog.json"
76        ));
77        let catalog = stackless_stripe_projects::Catalog::from_json_envelope(FIXTURE).unwrap();
78        let failures = stackless_stripe_projects::verify_service(
79            &catalog,
80            &WixHeadlessConfig {
81                plan: None,
82                wix_project_name: None,
83            },
84        );
85        assert!(
86            failures.is_empty(),
87            "wix/headless catalog gaps:\n{}",
88            failures.join("\n")
89        );
90    }
91
92    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"}}]}}"##;
93
94    fn test_def() -> StackDef {
95        StackDef::parse(
96            r#"
97[stack]
98name = "atto"
99[stack.projects.stripe]
100project = "project_1"
101[integrations.res]
102provider = "wix"
103[services.api]
104source = { repo = "r", ref = "main" }
105env = { OUT = "${integrations.res.app_id}" }
106health = { path = "/health" }
107[services.api.local]
108run = "true"
109"#,
110        )
111        .unwrap()
112    }
113
114    #[tokio::test]
115    async fn provision_records_outputs() {
116        let runner = test_support::provision_script(
117            CATALOG_ENVELOPE,
118            serde_json::json!({"WIX_APP_ID": "val_app_id"}),
119            0,
120        );
121        let dir = tempfile::tempdir().unwrap();
122        std::fs::write(
123            dir.path().join("stackless.toml"),
124            "[stack]\nname=\"atto\"\n",
125        )
126        .unwrap();
127        let stripe = StripeProjects::new(&runner, dir.path());
128
129        let resource = WixHeadless
130            .provision(
131                &stripe.as_dyn(),
132                &test_def(),
133                dir.path(),
134                "demo",
135                "res",
136                "local",
137                false,
138            )
139            .await
140            .unwrap();
141        assert_eq!(resource.resource_kind, "integration-wix");
142        let payload: ResourcePayload = serde_json::from_str(&resource.payload).unwrap();
143        assert_eq!(payload.outputs["app_id"], "val_app_id");
144    }
145}