Skip to content

Commit e018d10

Browse files
sxlijinseawatts
andauthored
feat: add stripe and propel webhook types (#1762)
Also bump our Rust toolchain version to 1.86.0. <!-- ELLIPSIS_HIDDEN --> ---- > [!IMPORTANT] > Add Stripe and PropelAuth webhook types, update Rust toolchain, and enhance S3 and trace event upload functionalities. > > - **Webhooks**: > - Add `StripeWebhook` and `PropelAuthWebhook` modules with request and response structs in `ui_webhook_stripe.rs` and `ui_webhook_propelauth.rs`. > - Implement `ApiEndpoint` for both webhooks with paths `/v1/webhooks/stripe` and `/v1/webhooks/propelauth`. > - **S3 Upload**: > - Add `S3UploadMetadata` struct in `s3.rs` with serialization and deserialization support. > - Add `to_map()` method and corresponding tests. > - **Trace Event Upload**: > - Add `CreateTraceEventUploadUrl` struct and implement `ApiEndpoint` in `trace_event_upload.rs`. > - Add request and response structs for `CreateTraceEventUploadUrl`. > - **Organization and Project Updates**: > - Add `stripe_subscription_status` to `Organization` and `UpdateOrganizationRequest` in `ui_control_plane_orgs.rs`. > - Change `project_id` type to `ProjectId` in `Project` and `UpdateProjectRequest` in `ui_control_plane_projects.rs`. > - **Misc**: > - Add `TraceBatchId` to `define_id.rs`. > - Update Rust toolchain to version 1.86.0 in `rust-toolchain.toml`. > > <sup>This description was created by </sup>[<img alt="Ellipsis" src="https://img.shields.io/badge/Ellipsis-blue?color=175173">](https://www.ellipsis.dev?ref=BoundaryML%2Fbaml&utm_source=github&utm_medium=referral)<sup> for 0c43564. It will automatically update as commits are pushed.</sup> <!-- ELLIPSIS_HIDDEN --> --------- Co-authored-by: Chris Watts <chris@boundaryml.com>
1 parent 5d21c75 commit e018d10

9 files changed

Lines changed: 160 additions & 6 deletions

engine/baml-rpc/src/define_id.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@ use type_safe_id::{StaticType, TypeSafeId};
22

33
macro_rules! define_id {
44
($name:ident, $inner_name:ident, $type_str:expr) => {
5-
#[derive(Default, Clone)]
5+
#[derive(Default, Clone, PartialEq, Eq, Hash)]
66
struct $inner_name;
77

88
impl StaticType for $inner_name {
99
const TYPE: &'static str = $type_str;
1010
}
1111

12-
#[derive(Debug, Clone)]
12+
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1313
pub struct $name(TypeSafeId<$inner_name>);
1414

1515
impl $name {
16+
#[allow(dead_code)]
1617
pub fn new() -> Self {
1718
Self(TypeSafeId::<$inner_name>::new())
1819
}
@@ -53,3 +54,4 @@ define_id!(SpanId, Span_, "bspan");
5354
define_id!(TraceEventId, TraceEvent_, "bevent");
5455
define_id!(HttpRequestId, HttpRequest_, "breq");
5556
define_id!(ProjectId, Project_, "proj");
57+
define_id!(TraceBatchId, TraceBatch_, "tracebatch");

engine/baml-rpc/src/lib.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,30 @@ mod baml_src_upload;
44
mod base;
55
mod define_id;
66
mod rpc;
7+
mod s3;
78
mod trace;
89
mod trace_event_upload;
910
mod ui_control_plane_orgs;
1011
mod ui_control_plane_projects;
1112
mod ui_dashboard;
1213
mod ui_function_spans;
14+
mod ui_webhook_propelauth;
15+
mod ui_webhook_stripe;
1316

1417
pub use ast::{BamlClassDefinition, BamlFunctionDefinition, BamlTypeDefinition, BamlTypeReference};
1518
pub use ast_node_id::AstNodeId;
1619
pub use rpc::{ApiEndpoint, GetEndpoint};
20+
pub use s3::S3UploadMetadata;
1721

1822
pub use baml_src_upload::{
1923
BamlSrcUploadStatus, CreateBamlSrcUpload, CreateBamlSrcUploadRequest,
2024
CreateBamlSrcUploadResponse, GetBamlSrcUploadStatusRequest, GetBamlSrcUploadStatusResponse,
2125
};
22-
pub use define_id::{HttpRequestId, ProjectId, SpanId, TraceEventId};
26+
pub use define_id::{HttpRequestId, ProjectId, SpanId, TraceBatchId, TraceEventId};
2327
pub use trace::{TraceData, TraceEvent, TraceEventBatch};
2428
pub use trace_event_upload::{
2529
CreateTraceEventUpload, CreateTraceEventUploadRequest, CreateTraceEventUploadResponse,
30+
CreateTraceEventUploadUrl, CreateTraceEventUploadUrlRequest, CreateTraceEventUploadUrlResponse,
2631
};
2732

2833
pub use ui_control_plane_orgs::{
@@ -37,3 +42,8 @@ pub use ui_control_plane_projects::{
3742
pub use ui_function_spans::{
3843
ListFunctionSpans, ListFunctionSpansRequest, ListFunctionSpansResponse,
3944
};
45+
46+
pub use ui_webhook_propelauth::{
47+
PropelAuthWebhook, PropelAuthWebhookRequest, PropelAuthWebhookResponse,
48+
};
49+
pub use ui_webhook_stripe::{StripeWebhook, StripeWebhookRequest, StripeWebhookResponse};

engine/baml-rpc/src/s3.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
use indexmap::IndexMap;
2+
use serde::{Deserialize, Serialize};
3+
4+
use crate::ProjectId;
5+
6+
#[derive(Debug, Serialize, Deserialize)]
7+
pub struct S3UploadMetadata {
8+
pub project_id: ProjectId,
9+
pub api_key_name: String,
10+
pub env_name: String,
11+
}
12+
13+
impl S3UploadMetadata {
14+
pub fn to_map(&self) -> IndexMap<String, String> {
15+
let mut map = IndexMap::new();
16+
map.insert("project_id".to_string(), self.project_id.to_string());
17+
map.insert("api_key_name".to_string(), self.api_key_name.clone());
18+
map.insert("env_name".to_string(), self.env_name.clone());
19+
map
20+
}
21+
}
22+
23+
#[cfg(test)]
24+
mod tests {
25+
use super::*;
26+
use anyhow::Result;
27+
use serde_json::{self, json};
28+
29+
#[test]
30+
fn test_s3_upload_metadata_deserialization() -> Result<()> {
31+
let project_id = ProjectId::new();
32+
let example = json!({
33+
"project_id": project_id.to_string(),
34+
"api_key_name": "test-api-key",
35+
"env_name": "test-env"
36+
});
37+
38+
let metadata: S3UploadMetadata = serde_json::from_value(example)?;
39+
40+
assert_eq!(metadata.project_id, project_id);
41+
assert_eq!(metadata.api_key_name, "test-api-key");
42+
assert_eq!(metadata.env_name, "test-env");
43+
44+
Ok(())
45+
}
46+
47+
#[test]
48+
fn test_s3_upload_metadata_to_map() -> Result<()> {
49+
let metadata = S3UploadMetadata {
50+
project_id: ProjectId::new(),
51+
api_key_name: "test-api-key".to_string(),
52+
env_name: "test-env".to_string(),
53+
};
54+
55+
assert_eq!(
56+
serde_json::to_value(metadata.to_map())?,
57+
serde_json::to_value(metadata)?
58+
);
59+
60+
Ok(())
61+
}
62+
}

engine/baml-rpc/src/trace_event_upload.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,29 @@
11
use serde::{Deserialize, Serialize};
22

33
use crate::rpc::ApiEndpoint;
4+
use crate::s3::S3UploadMetadata;
45
use crate::trace::TraceEvent;
56

7+
#[derive(Debug, Serialize, Deserialize)]
8+
pub struct CreateTraceEventUploadUrlRequest {
9+
pub upload_metadata: S3UploadMetadata,
10+
}
11+
12+
#[derive(Debug, Serialize, Deserialize)]
13+
pub struct CreateTraceEventUploadUrlResponse {
14+
pub upload_url: String,
15+
}
16+
17+
pub struct CreateTraceEventUploadUrl;
18+
19+
// POST /v1/baml-trace/create-upload-url
20+
impl ApiEndpoint for CreateTraceEventUploadUrl {
21+
type Request = CreateTraceEventUploadUrlRequest;
22+
type Response = CreateTraceEventUploadUrlResponse;
23+
24+
const PATH: &'static str = "/v1/baml-trace/create-upload-url";
25+
}
26+
627
#[derive(Debug, Serialize, Deserialize)]
728
pub struct CreateTraceEventUploadRequest {
829
pub trace_event_batch: Vec<TraceEvent>,

engine/baml-rpc/src/ui_control_plane_orgs.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub struct Organization {
1010
pub org_display_name: String,
1111
pub stripe_customer_id: Option<String>,
1212
pub stripe_subscription_id: Option<String>,
13+
pub stripe_subscription_status: Option<String>,
1314
}
1415

1516
#[derive(Debug, Serialize, Deserialize, TS)]
@@ -43,6 +44,7 @@ pub struct UpdateOrganizationRequest {
4344
pub org_display_name: Option<String>,
4445
pub stripe_customer_id: Option<String>,
4546
pub stripe_subscription_id: Option<String>,
47+
pub stripe_subscription_status: Option<String>,
4648
}
4749

4850
#[derive(Debug, Serialize, Deserialize, TS)]

engine/baml-rpc/src/ui_control_plane_projects.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
use crate::rpc::ApiEndpoint;
1+
use crate::{rpc::ApiEndpoint, ProjectId};
22
use serde::{Deserialize, Serialize};
33
use ts_rs::TS;
44

55
#[derive(Debug, Serialize, Deserialize, TS)]
66
#[ts(export)]
77
pub struct Project {
8-
pub project_id: String,
8+
#[ts(type = "string")]
9+
pub project_id: ProjectId,
910
pub project_slug: String,
1011
pub org_id: String,
1112
pub environments: Vec<String>,
@@ -60,7 +61,8 @@ impl ApiEndpoint for CreateProject {
6061
#[derive(Debug, Serialize, Deserialize, TS)]
6162
#[ts(export)]
6263
pub struct UpdateProjectRequest {
63-
pub project_id: String,
64+
#[ts(type = "string")]
65+
pub project_id: ProjectId,
6466
pub project_slug: Option<String>,
6567
pub environments: Option<Vec<String>>,
6668
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
use crate::rpc::ApiEndpoint;
2+
use serde::{Deserialize, Serialize};
3+
use ts_rs::TS;
4+
5+
#[derive(Debug, Serialize, Deserialize, TS)]
6+
#[ts(export)]
7+
pub struct PropelAuthWebhookRequest {
8+
// PropelAuth webhooks typically send a JSON payload
9+
#[ts(type = "any")]
10+
payload: serde_json::Value,
11+
}
12+
13+
#[derive(Debug, Serialize, Deserialize, TS)]
14+
#[ts(export)]
15+
pub struct PropelAuthWebhookResponse {
16+
received: bool,
17+
}
18+
19+
pub struct PropelAuthWebhook;
20+
21+
impl ApiEndpoint for PropelAuthWebhook {
22+
type Request = PropelAuthWebhookRequest;
23+
type Response = PropelAuthWebhookResponse;
24+
25+
const PATH: &'static str = "/v1/webhooks/propelauth";
26+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use crate::rpc::ApiEndpoint;
2+
use serde::{Deserialize, Serialize};
3+
use ts_rs::TS;
4+
5+
#[derive(Debug, Serialize, Deserialize, TS)]
6+
#[ts(export)]
7+
pub struct StripeWebhookRequest {
8+
#[ts(type = "any")]
9+
event: serde_json::Value,
10+
}
11+
12+
#[derive(Debug, Serialize, Deserialize, TS)]
13+
#[ts(export)]
14+
pub struct StripeWebhookResponse {
15+
received: bool,
16+
}
17+
18+
pub struct StripeWebhook;
19+
20+
impl ApiEndpoint for StripeWebhook {
21+
type Request = StripeWebhookRequest;
22+
type Response = StripeWebhookResponse;
23+
24+
const PATH: &'static str = "/v1/webhooks/stripe";
25+
}

engine/rust-toolchain.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[toolchain]
2+
channel = "1.86.0"
3+
targets = ["wasm32-unknown-unknown"]
4+
profile = "default"

0 commit comments

Comments
 (0)