stackless_integrations/providers/revenuecat/
app.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-revenuecat";
14
15#[derive(Debug, Serialize)]
16pub struct RevenuecatAppConfig {}
17
18impl CatalogService for RevenuecatAppConfig {
19 const REFERENCE: &'static str = "revenuecat/app";
20}
21
22#[derive(Debug)]
23pub struct RevenuecatApp;
24
25impl Hostable for RevenuecatApp {
26 const PROVIDER: &'static str = "revenuecat";
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] = &["app_uuid", "dashboard_url", "secret_api_key"];
31}
32
33impl FamilyResource for RevenuecatApp {
34 type Config = RevenuecatAppConfig;
35 const PROVIDER_PREFIX: &'static str = "REVENUECAT";
36 const OUTPUT_FIELDS: &'static [(&'static str, &'static str, bool)] = &[
37 ("APP_UUID", "app_uuid", true),
38 ("DASHBOARD_URL", "dashboard_url", true),
39 ("SECRET_API_KEY", "secret_api_key", true),
40 ];
41
42 fn build_config(ctx: &ProvisionContext<'_>) -> Result<RevenuecatAppConfig, IntegrationError> {
43 let _ = super::integration_config(ctx)?;
44 Ok(RevenuecatAppConfig {})
45 }
46}
47
48pub fn validate_config(
49 name: &str,
50 config: &BTreeMap<String, toml::Value>,
51) -> Result<(), IntegrationError> {
52 let _ = (name, config);
53 Ok(())
54}
55
56#[cfg(test)]
57mod tests {
58 use super::*;
59 use crate::ProviderOps;
60 use crate::resource::ResourcePayload;
61 use stackless_core::def::StackDef;
62 use stackless_stripe_projects::stripe::StripeProjects;
63 use stackless_stripe_projects::test_support;
64
65 #[test]
66 fn config_matches_catalog() {
67 const FIXTURE: &str = include_str!(concat!(
68 env!("CARGO_MANIFEST_DIR"),
69 "/../stackless-stripe-projects/tests/fixtures/catalog.json"
70 ));
71 let catalog = stackless_stripe_projects::Catalog::from_json_envelope(FIXTURE).unwrap();
72 let failures = stackless_stripe_projects::verify_service(&catalog, &RevenuecatAppConfig {});
73 assert!(
74 failures.is_empty(),
75 "revenuecat/app catalog gaps:\n{}",
76 failures.join("\n")
77 );
78 }
79
80 const CATALOG_ENVELOPE: &str = r##"{"ok":true,"command":"projects catalog","data":{"last_updated":"2026-07-11T00:00:00Z","services":[{"id":"prvsvc_app","object":"v2.provisioning.provider_service_detail","provider_id":"prvdr_revenuecat","provider_name":"RevenueCat","service_id":"app","categories":["database"],"kind":"deployable","scope":"project","availability":"available","development":false,"livemode":true,"pricing":{"type":"free"},"configuration_schema":{}}]}}"##;
81
82 fn test_def() -> StackDef {
83 StackDef::parse(
84 r#"
85[stack]
86name = "atto"
87[stack.projects.stripe]
88project = "project_1"
89[integrations.res]
90provider = "revenuecat"
91[services.api]
92source = { repo = "r", ref = "main" }
93env = { OUT = "${integrations.res.secret_api_key}" }
94health = { path = "/health" }
95[services.api.local]
96run = "true"
97"#,
98 )
99 .unwrap()
100 }
101
102 #[tokio::test]
103 async fn provision_records_outputs() {
104 let runner = test_support::provision_script(
105 CATALOG_ENVELOPE,
106 serde_json::json!({"REVENUECAT_APP_UUID": "val_app_uuid", "REVENUECAT_DASHBOARD_URL": "val_dashboard_url", "REVENUECAT_SECRET_API_KEY": "val_secret_api_key"}),
107 0,
108 );
109 let dir = tempfile::tempdir().unwrap();
110 std::fs::write(
111 dir.path().join("stackless.toml"),
112 "[stack]\nname=\"atto\"\n",
113 )
114 .unwrap();
115 let stripe = StripeProjects::new(&runner, dir.path());
116
117 let resource = RevenuecatApp
118 .provision(
119 &stripe.as_dyn(),
120 &test_def(),
121 dir.path(),
122 "demo",
123 "res",
124 "local",
125 false,
126 )
127 .await
128 .unwrap();
129 assert_eq!(resource.resource_kind, "integration-revenuecat");
130 let payload: ResourcePayload = serde_json::from_str(&resource.payload).unwrap();
131 assert_eq!(payload.outputs["secret_api_key"], "val_secret_api_key");
132 }
133}