Skip to main content

stackless_integrations/providers/inngest/
app.rs

1//! `inngest/app` 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-inngest";
15
16#[derive(Debug, Serialize)]
17pub struct InngestAppConfig {
18    #[serde(rename = "id")]
19    pub r#id: String,
20}
21
22impl CatalogService for InngestAppConfig {
23    const REFERENCE: &'static str = "inngest/app";
24}
25
26#[derive(Debug)]
27pub struct InngestApp;
28
29impl Hostable for InngestApp {
30    const PROVIDER: &'static str = "inngest";
31    const HOSTING: IntegrationHosting = IntegrationHosting::Managed;
32    const CONFIG_SCOPE: ConfigScope = ConfigScope::GlobalOnly;
33    const RESOURCE_KIND: &'static str = RESOURCE_KIND;
34    const OUTPUTS: &'static [&'static str] = &["event_key", "signing_key"];
35}
36
37impl FamilyResource for InngestApp {
38    type Config = InngestAppConfig;
39    const PROVIDER_PREFIX: &'static str = "INNGEST";
40    // Provisional until pinned by `mise run discover inngest/app`.
41    const OUTPUT_FIELDS: &'static [(&'static str, &'static str, bool)] = &[
42        ("EVENT_KEY", "event_key", true),
43        ("SIGNING_KEY", "signing_key", false),
44    ];
45
46    fn build_config(ctx: &ProvisionContext<'_>) -> Result<InngestAppConfig, IntegrationError> {
47        let config = super::integration_config(ctx)?;
48        Ok(InngestAppConfig {
49            r#id: super::interp_required(ctx, &config, "id")?,
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, "id").map_err(|err| IntegrationError::ConfigInvalid {
59        location: format!("integrations.{name}.id"),
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            &InngestAppConfig {
85                r#id: "test-id".into(),
86            },
87        );
88        assert!(
89            failures.is_empty(),
90            "inngest/app 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_app","object":"v2.provisioning.provider_service_detail","provider_id":"prvdr_inngest","provider_name":"Inngest","service_id":"app","categories":["database"],"kind":"deployable","scope":"project","availability":"available","development":false,"livemode":true,"pricing":{"type":"component"},"configuration_schema":{"properties":{"id":{"description":"Inngest app ID. This should match the id passed to your Inngest SDK client, e.g. new Inngest({ id: \"my-app\" }).","minLength":1,"type":"string"}},"required":["id"],"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 = "inngest"
106id = "test-id"
107[services.api]
108source = { repo = "r", ref = "main" }
109env = { OUT = "${integrations.res.event_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!({"INNGEST_EVENT_KEY": "val_event_key", "INNGEST_SIGNING_KEY": "val_signing_key"}),
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 = InngestApp
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-inngest");
146        let payload: ResourcePayload = serde_json::from_str(&resource.payload).unwrap();
147        assert_eq!(payload.outputs["event_key"], "val_event_key");
148    }
149}