Skip to main content

stackless_integrations/providers/supermemory/
memory.rs

1//! `supermemory/memory` 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};
12use crate::registry;
13
14pub const RESOURCE_KIND: &str = "integration-supermemory";
15
16#[derive(Debug, Serialize)]
17pub struct SupermemoryMemoryConfig {
18    pub plan: String,
19}
20
21impl CatalogService for SupermemoryMemoryConfig {
22    const REFERENCE: &'static str = "supermemory/memory";
23}
24
25#[derive(Debug)]
26pub struct SupermemoryMemory;
27
28impl Hostable for SupermemoryMemory {
29    const PROVIDER: &'static str = "supermemory";
30    const HOSTING: IntegrationHosting = IntegrationHosting::Managed;
31    const CONFIG_SCOPE: ConfigScope = ConfigScope::GlobalOnly;
32    const RESOURCE_KIND: &'static str = RESOURCE_KIND;
33    const OUTPUTS: &'static [&'static str] = &["api_key", "project_id"];
34}
35
36impl FamilyResource for SupermemoryMemory {
37    type Config = SupermemoryMemoryConfig;
38    const PROVIDER_PREFIX: &'static str = "SUPERMEMORY";
39    const OUTPUT_FIELDS: &'static [(&'static str, &'static str, bool)] = &[
40        ("API_KEY", "api_key", true),
41        ("PROJECT_ID", "project_id", true),
42    ];
43
44    fn build_config(
45        ctx: &ProvisionContext<'_>,
46    ) -> Result<SupermemoryMemoryConfig, IntegrationError> {
47        let config = super::integration_config(ctx)?;
48        Ok(SupermemoryMemoryConfig {
49            plan: super::interp_required(ctx, &config, "plan")?,
50        })
51    }
52}
53
54pub fn validate_config(
55    name: &str,
56    config: &BTreeMap<String, toml::Value>,
57) -> Result<(), IntegrationError> {
58    registry::config_string(config, "plan").map_err(|err| IntegrationError::ConfigInvalid {
59        location: format!("integrations.{name}.plan"),
60        detail: err.to_string(),
61    })?;
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 = stackless_stripe_projects::verify_service(
83            &catalog,
84            &SupermemoryMemoryConfig {
85                plan: "free".into(),
86            },
87        );
88        assert!(
89            failures.is_empty(),
90            "supermemory/memory 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_memory","object":"v2.provisioning.provider_service_detail","provider_id":"prvdr_supermemory","provider_name":"Supermemory","service_id":"memory","categories":["database"],"kind":"deployable","scope":"project","availability":"available","development":false,"livemode":true,"pricing":{"type":"paid"},"configuration_schema":{"properties":{"plan":{"description":"Subscription tier","enum":["free","pro","max","scale"],"type":"string"}},"required":["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 = "supermemory"
106plan = "free"
107[services.api]
108source = { repo = "r", ref = "main" }
109env = { OUT = "${integrations.res.api_key}" }
110health = { path = "/health" }
111[services.api.local]
112run = "true"
113"#,
114        )
115        .unwrap()
116    }
117
118    #[tokio::test]
119    async fn provision_records_outputs() {
120        let runner = test_support::provision_script(
121            CATALOG_ENVELOPE,
122            serde_json::json!({"SUPERMEMORY_API_KEY": "val_api_key", "SUPERMEMORY_PROJECT_ID": "val_project_id"}),
123            0,
124        );
125        let dir = tempfile::tempdir().unwrap();
126        std::fs::write(
127            dir.path().join("stackless.toml"),
128            "[stack]\nname=\"atto\"\n",
129        )
130        .unwrap();
131        let stripe = StripeProjects::new(&runner, dir.path());
132
133        let resource = SupermemoryMemory
134            .provision(
135                &stripe.as_dyn(),
136                &test_def(),
137                dir.path(),
138                "demo",
139                "res",
140                "local",
141                false,
142            )
143            .await
144            .unwrap();
145        assert_eq!(resource.resource_kind, "integration-supermemory");
146        let payload: ResourcePayload = serde_json::from_str(&resource.payload).unwrap();
147        assert_eq!(payload.outputs["api_key"], "val_api_key");
148        assert_eq!(payload.outputs["project_id"], "val_project_id");
149    }
150}