Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(webhooks): add webhook secret to create webhook response (#4744)

Will Hutchinson17ed4a15c707
diff --git a/apps/web/src/lib/service-clients/service-storage/generated/schemas/createWebhookResponse.ts b/apps/web/src/lib/service-clients/service-storage/generated/schemas/createWebhookResponse.ts
new file mode 100644
index 0000000000..1ecc54b6a3
--- /dev/null
+++ b/apps/web/src/lib/service-clients/service-storage/generated/schemas/createWebhookResponse.ts
@@ -0,0 +1,44 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * document_storage_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+import type { BTreeMap } from './bTreeMap';
+import type { CreateWebhookResponseDeletedAt } from './createWebhookResponseDeletedAt';
+import type { String } from './string';
+import type { Vec } from './vec';
+import type { WebhookStatus } from './webhookStatus';
+
+/**
+ * Webhook returned after creation, including its signing secret.
+ */
+export interface CreateWebhookResponse {
+ /** Creation timestamp. */
+ created_at: string;
+ /** User that created the webhook. */
+ created_by_user_id: string;
+ /** Soft-delete timestamp. */
+ deleted_at?: CreateWebhookResponseDeletedAt;
+ /** Endpoint URL. HTTPS is required outside local environments. */
+ endpoint_url: string;
+ /** Typed filters used to match events and optional entity ids. */
+ filters: Vec;
+ /** Custom delivery headers, after decryption by the repository. */
+ headers: BTreeMap;
+ /** Webhook id. */
+ id: String;
+ /** Whether the current endpoint configuration has passed validation. */
+ is_valid: boolean;
+ /** Display name. */
+ name: string;
+ /** Signing secret used to verify webhook delivery signatures. */
+ signing_secret: string;
+ /** Webhook lifecycle status. */
+ status: WebhookStatus;
+ /** Update timestamp. */
+ updated_at: string;
+ /** Owning workspace id. */
+ workspace_id: string;
+}
diff --git a/apps/web/src/lib/service-clients/service-storage/generated/schemas/createWebhookResponseDeletedAt.ts b/apps/web/src/lib/service-clients/service-storage/generated/schemas/createWebhookResponseDeletedAt.ts
new file mode 100644
index 0000000000..496c9ca274
--- /dev/null
+++ b/apps/web/src/lib/service-clients/service-storage/generated/schemas/createWebhookResponseDeletedAt.ts
@@ -0,0 +1,11 @@
+/**
+ * Generated by orval v7.21.0 🍺
+ * Do not edit manually.
+ * document_storage_service
+ * OpenAPI spec version: 0.1.0
+ */
+
+/**
+ * Soft-delete timestamp.
+ */
+export type CreateWebhookResponseDeletedAt = string | null;
diff --git a/apps/web/src/lib/service-clients/service-storage/generated/schemas/index.ts b/apps/web/src/lib/service-clients/service-storage/generated/schemas/index.ts
index de2eaed799..7f7727acce 100644
--- a/apps/web/src/lib/service-clients/service-storage/generated/schemas/index.ts
+++ b/apps/web/src/lib/service-clients/service-storage/generated/schemas/index.ts
@@ -320,6 +320,8 @@ export * from './createUnthreadedPdfAnchorRequestOneOfAllOfAnchorType';
export * from './createViewRequest';
export * from './createWebhookRequest';
export * from './createWebhookRequestHeaders';
+export * from './createWebhookResponse';
+export * from './createWebhookResponseDeletedAt';
export * from './crmComment';
export * from './crmCommentDeletedAt';
export * from './crmCommentEntityType';
diff --git a/apps/web/src/lib/service-clients/service-storage/openapi.json b/apps/web/src/lib/service-clients/service-storage/openapi.json
index 3d329b1e4f..cac2302cdd 100644
--- a/apps/web/src/lib/service-clients/service-storage/openapi.json
+++ b/apps/web/src/lib/service-clients/service-storage/openapi.json
@@ -9264,7 +9264,7 @@
"content": {
"application/json": {
"schema": {
- "$ref": "#/components/schemas/Webhook"
+ "$ref": "#/components/schemas/CreateWebhookResponse"
}
}
}
@@ -12654,6 +12654,81 @@
}
}
},
+ "CreateWebhookResponse": {
+ "type": "object",
+ "description": "Webhook returned after creation, including its signing secret.",
+ "required": [
+ "id",
+ "workspace_id",
+ "name",
+ "endpoint_url",
+ "signing_secret",
+ "headers",
+ "status",
+ "is_valid",
+ "created_by_user_id",
+ "created_at",
+ "updated_at",
+ "filters"
+ ],
+ "properties": {
+ "created_at": {
+ "type": "string",
+ "format": "date-time",
+ "description": "Creation timestamp."
+ },
+ "created_by_user_id": {
+ "type": "string",
+ "description": "User that created the webhook."
+ },
+ "deleted_at": {
+ "type": ["string", "null"],
+ "format": "date-time",
+ "description": "Soft-delete timestamp."
+ },
+ "endpoint_url": {
+ "type": "string",
+ "description": "Endpoint URL. HTTPS is required outside local environments."
+ },
+ "filters": {
+ "$ref": "#/components/schemas/Vec",
+ "description": "Typed filters used to match events and optional entity ids."
+ },
+ "headers": {
+ "$ref": "#/components/schemas/BTreeMap",
+ "description": "Custom delivery headers, after decryption by the repository."
+ },
+ "id": {
+ "$ref": "#/components/schemas/String",
+ "description": "Webhook id."
+ },
+ "is_valid": {
+ "type": "boolean",
+ "description": "Whether the current endpoint configuration has passed validation."
+ },
+ "name": {
+ "type": "string",
+ "description": "Display name."
+ },
+ "signing_secret": {
+ "type": "string",
+ "description": "Signing secret used to verify webhook delivery signatures."
+ },
+ "status": {
+ "$ref": "#/components/schemas/WebhookStatus",
+ "description": "Webhook lifecycle status."
+ },
+ "updated_at": {
+ "type": "string",
+ "format": "date-time",
+ "description": "Update timestamp."
+ },
+ "workspace_id": {
+ "type": "string",
+ "description": "Owning workspace id."
+ }
+ }
+ },
"CrmComment": {
"type": "object",
"description": "A single comment within a [`CrmThread`].",
diff --git a/crates/webhook/src/domain/models.rs b/crates/webhook/src/domain/models.rs
index f0ddf469bb..12980e40d5 100644
--- a/crates/webhook/src/domain/models.rs
+++ b/crates/webhook/src/domain/models.rs
@@ -394,7 +394,8 @@ pub struct Webhook {
pub name: String,
/// Endpoint URL. HTTPS is required outside local environments.
pub endpoint_url: String,
- /// Signing secret used by outbound adapters. This is never serialized by APIs.
+ /// Signing secret used by outbound adapters. Generic webhook API responses omit it;
+ /// creation exposes it separately through [`CreateWebhookResponse`].
#[serde(default, skip_serializing)]
pub signing_secret: String,
/// Custom delivery headers, after decryption by the repository.
@@ -415,6 +416,58 @@ pub struct Webhook {
pub filters: WebhookFilters,
}
+/// Webhook returned after creation, including its signing secret.
+#[derive(Debug, Clone, Serialize, Deserialize)]
+#[cfg_attr(feature = "inbound", derive(utoipa::ToSchema))]
+pub struct CreateWebhookResponse {
+ /// Webhook id.
+ pub id: WebhookId,
+ /// Owning workspace id.
+ pub workspace_id: String,
+ /// Display name.
+ pub name: String,
+ /// Endpoint URL. HTTPS is required outside local environments.
+ pub endpoint_url: String,
+ /// Signing secret used to verify webhook delivery signatures.
+ pub signing_secret: String,
+ /// Custom delivery headers, after decryption by the repository.
+ pub headers: WebhookHeaders,
+ /// Webhook lifecycle status.
+ pub status: WebhookStatus,
+ /// Whether the current endpoint configuration has passed validation.
+ pub is_valid: bool,
+ /// User that created the webhook.
+ pub created_by_user_id: String,
+ /// Creation timestamp.
+ pub created_at: DateTime<Utc>,
+ /// Update timestamp.
+ pub updated_at: DateTime<Utc>,
+ /// Soft-delete timestamp.
+ pub deleted_at: Option<DateTime<Utc>>,
+ /// Typed filters used to match events and optional entity ids.
+ pub filters: WebhookFilters,
+}
+
+impl From<Webhook> for CreateWebhookResponse {
+ fn from(webhook: Webhook) -> Self {
+ Self {
+ id: webhook.id,
+ workspace_id: webhook.workspace_id,
+ name: webhook.name,
+ endpoint_url: webhook.endpoint_url,
+ signing_secret: webhook.signing_secret,
+ headers: webhook.headers,
+ status: webhook.status,
+ is_valid: webhook.is_valid,
+ created_by_user_id: webhook.created_by_user_id,
+ created_at: webhook.created_at,
+ updated_at: webhook.updated_at,
+ deleted_at: webhook.deleted_at,
+ filters: webhook.filters,
+ }
+ }
+}
+
/// Sanitized result of validating a webhook endpoint.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "inbound", derive(utoipa::ToSchema))]
diff --git a/crates/webhook/src/inbound/axum_router.rs b/crates/webhook/src/inbound/axum_router.rs
index e8585db1b7..ad5e2430f2 100644
--- a/crates/webhook/src/inbound/axum_router.rs
+++ b/crates/webhook/src/inbound/axum_router.rs
@@ -2,7 +2,8 @@
use crate::domain::{
models::{
- CreateWebhookRequest, PatchWebhookRequest, ValidateWebhookResponse, Webhook, WebhookId,
+ CreateWebhookRequest, CreateWebhookResponse, PatchWebhookRequest, ValidateWebhookResponse,
+ Webhook, WebhookId,
},
ports::{WebhookError, WebhookService},
};
@@ -143,7 +144,7 @@ where
path = "/webhook/webhooks",
request_body = CreateWebhookRequest,
responses(
- (status = 201, description = "Webhook created", body = Webhook),
+ (status = 201, description = "Webhook created", body = CreateWebhookResponse),
(status = 400, description = "Bad request", body = ErrorResponse),
(status = 403, description = "Forbidden", body = ErrorResponse),
(status = 500, description = "Internal server error", body = ErrorResponse),
@@ -154,9 +155,9 @@ pub async fn create_webhook<S: WebhookService>(
State(service): State<Arc<S>>,
user: MacroUserExtractor,
Json(request): Json<CreateWebhookRequest>,
-) -> Result<(StatusCode, Json<Webhook>), WebhookHandlerError> {
+) -> Result<(StatusCode, Json<CreateWebhookResponse>), WebhookHandlerError> {
let webhook = service.create_webhook(user.macro_user_id, request).await?;
- Ok((StatusCode::CREATED, Json(webhook)))
+ Ok((StatusCode::CREATED, Json(webhook.into())))
}
/// Patch a webhook.
diff --git a/crates/webhook/src/inbound/axum_router_test.rs b/crates/webhook/src/inbound/axum_router_test.rs
index edb95914d9..2892099c5f 100644
--- a/crates/webhook/src/inbound/axum_router_test.rs
+++ b/crates/webhook/src/inbound/axum_router_test.rs
@@ -199,7 +199,11 @@ async fn create_passes_authenticated_user_and_body_to_service() {
)
.await;
- assert_eq!(response.status(), StatusCode::CREATED);
+ let status = response.status();
+ let body = response_json(response).await;
+
+ assert_eq!(status, StatusCode::CREATED);
+ assert_eq!(body["signing_secret"], "whsec_test");
match &service.calls()[0] {
ServiceCall::Create(user, request) => {
assert_eq!(user.as_ref(), user_id());
@@ -221,7 +225,11 @@ async fn patch_passes_authenticated_user_path_and_body_to_service() {
)
.await;
- assert_eq!(response.status(), StatusCode::OK);
+ let status = response.status();
+ let body = response_json(response).await;
+
+ assert_eq!(status, StatusCode::OK);
+ assert!(body.get("signing_secret").is_none());
match &service.calls()[0] {
ServiceCall::Patch(user, webhook_id, request) => {
assert_eq!(user.as_ref(), user_id());
@@ -418,6 +426,7 @@ fn webhook() -> Webhook {
"workspace_id": "workspace_1",
"name": "Events",
"endpoint_url": "https://example.com/webhook",
+ "signing_secret": "whsec_test",
"headers": {},
"status": "active",
"is_valid": false,
diff --git a/services/document_storage_service/src/api/swagger.rs b/services/document_storage_service/src/api/swagger.rs
index 06d6a4d63c..72e01974c3 100644
--- a/services/document_storage_service/src/api/swagger.rs
+++ b/services/document_storage_service/src/api/swagger.rs
@@ -524,6 +524,7 @@ use utoipa::OpenApi;
// Webhooks
webhook::domain::models::CreateWebhookRequest,
+ webhook::domain::models::CreateWebhookResponse,
webhook::domain::models::PatchWebhookRequest,
webhook::domain::models::ValidateWebhookResponse,
webhook::domain::models::Webhook,