stackless_integrations/providers/inngest/
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};
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] = &[
35 "api_origin",
36 "dashboard_url",
37 "event_api_origin",
38 "event_key",
39 "signing_key",
40 ];
41}
42
43impl FamilyResource for InngestApp {
44 type Config = InngestAppConfig;
45 const PROVIDER_PREFIX: &'static str = "INNGEST";
46 const OUTPUT_FIELDS: &'static [(&'static str, &'static str, bool)] = &[
47 ("API_ORIGIN", "api_origin", true),
48 ("DASHBOARD_URL", "dashboard_url", true),
49 ("EVENT_API_ORIGIN", "event_api_origin", true),
50 ("EVENT_KEY", "event_key", true),
51 ("SIGNING_KEY", "signing_key", true),
52 ];
53
54 fn build_config(ctx: &ProvisionContext<'_>) -> Result<InngestAppConfig, IntegrationError> {
55 let config = super::integration_config(ctx)?;
56 Ok(InngestAppConfig {
57 r#id: super::interp_required(ctx, &config, "id")?,
58 })
59 }
60}
61
62pub fn validate_config(
63 name: &str,
64 config: &BTreeMap<String, toml::Value>,
65) -> Result<(), IntegrationError> {
66 registry::config_string(config, "id").map_err(|err| IntegrationError::ConfigInvalid {
67 location: format!("integrations.{name}.id"),
68 detail: err.to_string(),
69 })?;
70 let _ = (name, config);
71 Ok(())
72}
73
74#[cfg(test)]
75mod tests {
76 use super::*;
77 use crate::ProviderOps;
78 use crate::resource::ResourcePayload;
79 use stackless_core::def::StackDef;
80 use stackless_stripe_projects::stripe::StripeProjects;
81 use stackless_stripe_projects::test_support;
82
83 #[test]
84 fn config_matches_catalog() {
85 const FIXTURE: &str = include_str!(concat!(
86 env!("CARGO_MANIFEST_DIR"),
87 "/../stackless-stripe-projects/tests/fixtures/catalog.json"
88 ));
89 let catalog = stackless_stripe_projects::Catalog::from_json_envelope(FIXTURE).unwrap();
90 let failures = stackless_stripe_projects::verify_service(
91 &catalog,
92 &InngestAppConfig {
93 r#id: "test-id".into(),
94 },
95 );
96 assert!(
97 failures.is_empty(),
98 "inngest/app catalog gaps:\n{}",
99 failures.join("\n")
100 );
101 }
102
103 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"}}]}}"##;
104
105 fn test_def() -> StackDef {
106 StackDef::parse(
107 r#"
108[stack]
109name = "atto"
110[stack.projects.stripe]
111project = "project_1"
112[integrations.res]
113provider = "inngest"
114id = "test-id"
115[services.api]
116source = { repo = "r", ref = "main" }
117env = { OUT = "${integrations.res.event_key}" }
118health = { path = "/health" }
119[services.api.local]
120run = "true"
121"#,
122 )
123 .unwrap()
124 }
125
126 #[tokio::test]
127 async fn provision_records_outputs() {
128 let runner = test_support::provision_script(
129 CATALOG_ENVELOPE,
130 serde_json::json!({"INNGEST_API_ORIGIN": "val_api_origin", "INNGEST_DASHBOARD_URL": "val_dashboard_url", "INNGEST_EVENT_API_ORIGIN": "val_event_api_origin", "INNGEST_EVENT_KEY": "val_event_key", "INNGEST_SIGNING_KEY": "val_signing_key"}),
131 0,
132 );
133 let dir = tempfile::tempdir().unwrap();
134 std::fs::write(
135 dir.path().join("stackless.toml"),
136 "[stack]\nname=\"atto\"\n",
137 )
138 .unwrap();
139 let stripe = StripeProjects::new(&runner, dir.path());
140
141 let resource = InngestApp
142 .provision(
143 &stripe.as_dyn(),
144 &test_def(),
145 dir.path(),
146 "demo",
147 "res",
148 "local",
149 false,
150 )
151 .await
152 .unwrap();
153 assert_eq!(resource.resource_kind, "integration-inngest");
154 let payload: ResourcePayload = serde_json::from_str(&resource.payload).unwrap();
155 assert_eq!(payload.outputs["api_origin"], "val_api_origin");
156 assert_eq!(payload.outputs["dashboard_url"], "val_dashboard_url");
157 assert_eq!(payload.outputs["event_api_origin"], "val_event_api_origin");
158 assert_eq!(payload.outputs["event_key"], "val_event_key");
159 assert_eq!(payload.outputs["signing_key"], "val_signing_key");
160 }
161}