Skip to main content

stackless_integrations/providers/customerio/
workspace.rs

1//! `customerio/workspace` 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-customerio";
14
15#[derive(Debug, Serialize)]
16pub struct CustomerioWorkspaceConfig {}
17
18impl CatalogService for CustomerioWorkspaceConfig {
19    const REFERENCE: &'static str = "customerio/workspace";
20}
21
22#[derive(Debug)]
23pub struct CustomerioWorkspace;
24
25impl Hostable for CustomerioWorkspace {
26    const PROVIDER: &'static str = "customerio";
27    const HOSTING: IntegrationHosting = IntegrationHosting::Managed;
28    const CONFIG_SCOPE: ConfigScope = ConfigScope::GlobalOnly;
29    const RESOURCE_KIND: &'static str = RESOURCE_KIND;
30    const OUTPUTS: &'static [&'static str] = &[
31        "account_id",
32        "api_key",
33        "sa_token",
34        "site_id",
35        "workspace_id",
36    ];
37}
38
39impl FamilyResource for CustomerioWorkspace {
40    type Config = CustomerioWorkspaceConfig;
41    const PROVIDER_PREFIX: &'static str = "CUSTOMERIO";
42    const OUTPUT_FIELDS: &'static [(&'static str, &'static str, bool)] = &[
43        ("ACCOUNT_ID", "account_id", true),
44        ("API_KEY", "api_key", true),
45        ("SA_TOKEN", "sa_token", true),
46        ("SITE_ID", "site_id", true),
47        ("WORKSPACE_ID", "workspace_id", true),
48    ];
49
50    fn build_config(
51        ctx: &ProvisionContext<'_>,
52    ) -> Result<CustomerioWorkspaceConfig, IntegrationError> {
53        let _ = super::integration_config(ctx)?;
54        Ok(CustomerioWorkspaceConfig {})
55    }
56}
57
58pub fn validate_config(
59    name: &str,
60    config: &BTreeMap<String, toml::Value>,
61) -> Result<(), IntegrationError> {
62    let _ = (name, config);
63    Ok(())
64}
65
66#[cfg(test)]
67mod tests {
68    use super::*;
69    use crate::ProviderOps;
70    use crate::resource::ResourcePayload;
71    use stackless_core::def::StackDef;
72    use stackless_stripe_projects::stripe::StripeProjects;
73    use stackless_stripe_projects::test_support;
74
75    #[test]
76    fn config_matches_catalog() {
77        const FIXTURE: &str = include_str!(concat!(
78            env!("CARGO_MANIFEST_DIR"),
79            "/../stackless-stripe-projects/tests/fixtures/catalog.json"
80        ));
81        let catalog = stackless_stripe_projects::Catalog::from_json_envelope(FIXTURE).unwrap();
82        let failures =
83            stackless_stripe_projects::verify_service(&catalog, &CustomerioWorkspaceConfig {});
84        assert!(
85            failures.is_empty(),
86            "customerio/workspace catalog gaps:\n{}",
87            failures.join("\n")
88        );
89    }
90
91    const CATALOG_ENVELOPE: &str = r##"{"ok":true,"command":"projects catalog","data":{"last_updated":"2026-07-11T00:00:00Z","services":[{"id":"prvsvc_workspace","object":"v2.provisioning.provider_service_detail","provider_id":"prvdr_customerio","provider_name":"customerio","service_id":"workspace","categories":["database"],"kind":"deployable","scope":"project","availability":"available","development":false,"livemode":true,"pricing":{"type":"component"},"configuration_schema":{}}]}}"##;
92
93    fn test_def() -> StackDef {
94        StackDef::parse(
95            r#"
96[stack]
97name = "atto"
98[stack.projects.stripe]
99project = "project_1"
100[integrations.res]
101provider = "customerio"
102[services.api]
103source = { repo = "r", ref = "main" }
104env = { OUT = "${integrations.res.api_key}" }
105health = { path = "/health" }
106[services.api.local]
107run = "true"
108"#,
109        )
110        .unwrap()
111    }
112
113    #[tokio::test]
114    async fn provision_records_outputs() {
115        let runner = test_support::provision_script(
116            CATALOG_ENVELOPE,
117            serde_json::json!({"CUSTOMERIO_ACCOUNT_ID": "val_account_id", "CUSTOMERIO_API_KEY": "val_api_key", "CUSTOMERIO_SA_TOKEN": "val_sa_token", "CUSTOMERIO_SITE_ID": "val_site_id", "CUSTOMERIO_WORKSPACE_ID": "val_workspace_id"}),
118            0,
119        );
120        let dir = tempfile::tempdir().unwrap();
121        std::fs::write(
122            dir.path().join("stackless.toml"),
123            "[stack]\nname=\"atto\"\n",
124        )
125        .unwrap();
126        let stripe = StripeProjects::new(&runner, dir.path());
127
128        let resource = CustomerioWorkspace
129            .provision(
130                &stripe.as_dyn(),
131                &test_def(),
132                dir.path(),
133                "demo",
134                "res",
135                "local",
136                false,
137            )
138            .await
139            .unwrap();
140        assert_eq!(resource.resource_kind, "integration-customerio");
141        let payload: ResourcePayload = serde_json::from_str(&resource.payload).unwrap();
142        assert_eq!(payload.outputs["api_key"], "val_api_key");
143    }
144}