Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(email): stop delegates tearing down the owner's inbox via DELETE/email/sync (#8430)
gbirman4a95f0e9283b
diff --git a/apps/web/src/lib/service-clients/service-email/generated/client.ts b/apps/web/src/lib/service-clients/service-email/generated/client.tsindex 44d6fa6081..6e05fafb96 100644--- a/apps/web/src/lib/service-clients/service-email/generated/client.ts+++ b/apps/web/src/lib/service-clients/service-email/generated/client.ts@@ -3010,7 +3010,12 @@ export const mailboxSettingsOperations = async (};/**- * @summary Disables inbox syncing for user.+ * The inbox is the caller's primary, or the one named by `X-Email-Link-Id`,+which may be an inbox the caller only reaches through delegation. Removal+therefore follows the same policy as `DELETE /email/links/{link_id}`: an+owner's inbox is torn down, while a delegate only loses their+`macro_user_links` edge and the owner's data stays intact.+ * @summary Disables inbox syncing for the selected inbox.*/export type disableSyncResponse204 = {data: EmptyResponse;@@ -3027,6 +3032,21 @@ export type disableSyncResponse401 = {status: 401;};+export type disableSyncResponse403 = {+ data: ErrorResponse;+ status: 403;+};++export type disableSyncResponse404 = {+ data: ErrorResponse;+ status: 404;+};++export type disableSyncResponse409 = {+ data: ErrorResponse;+ status: 409;+};+export type disableSyncResponse500 = {data: ErrorResponse;status: 500;@@ -3038,6 +3058,9 @@ export type disableSyncResponseSuccess = disableSyncResponse204 & {export type disableSyncResponseError = (| disableSyncResponse400| disableSyncResponse401+ | disableSyncResponse403+ | disableSyncResponse404+ | disableSyncResponse409| disableSyncResponse500) & {headers: Headers;diff --git a/apps/web/src/lib/service-clients/service-email/openapi.json b/apps/web/src/lib/service-clients/service-email/openapi.jsonindex a9be7c28e4..16e211a997 100644--- a/apps/web/src/lib/service-clients/service-email/openapi.json+++ b/apps/web/src/lib/service-clients/service-email/openapi.json@@ -2722,8 +2722,21 @@"/email/sync": {"delete": {"tags": ["Sync"],- "summary": "Disables inbox syncing for user.",+ "summary": "Disables inbox syncing for the selected inbox.",+ "description": "The inbox is the caller's primary, or the one named by `X-Email-Link-Id`,\nwhich may be an inbox the caller only reaches through delegation. Removal\ntherefore follows the same policy as `DELETE /email/links/{link_id}`: an\nowner's inbox is torn down, while a delegate only loses their\n`macro_user_links` edge and the owner's data stays intact.","operationId": "disable_sync",+ "parameters": [+ {+ "name": "X-Email-Link-Id",+ "in": "header",+ "description": "Inbox link ID to act on instead of the caller's primary inbox; may name a delegated inbox.",+ "required": false,+ "schema": {+ "type": ["string", "null"],+ "format": "uuid"+ }+ }+ ],"responses": {"204": {"description": "",@@ -2755,6 +2768,36 @@}}},+ "403": {+ "description": "",+ "content": {+ "application/json": {+ "schema": {+ "$ref": "#/components/schemas/ErrorResponse"+ }+ }+ }+ },+ "404": {+ "description": "",+ "content": {+ "application/json": {+ "schema": {+ "$ref": "#/components/schemas/ErrorResponse"+ }+ }+ }+ },+ "409": {+ "description": "",+ "content": {+ "application/json": {+ "schema": {+ "$ref": "#/components/schemas/ErrorResponse"+ }+ }+ }+ },"500": {"description": "","content": {diff --git a/packages/sdk-docs/reference/generated/email/types.gen/type-aliases/DisableSyncData.md b/packages/sdk-docs/reference/generated/email/types.gen/type-aliases/DisableSyncData.mdindex b174ad7f6e..e003f99ca4 100644--- a/packages/sdk-docs/reference/generated/email/types.gen/type-aliases/DisableSyncData.md+++ b/packages/sdk-docs/reference/generated/email/types.gen/type-aliases/DisableSyncData.md@@ -1,12 +1,14 @@# Type Alias: DisableSyncData-> **DisableSyncData** = \{ `body?`: `never`; `path?`: `never`; `query?`: `never`; `url`: `"/email/sync"`; \}+> **DisableSyncData** = \{ `body?`: `never`; `headers?`: \{ `X-Email-Link-Id?`: `string` \| `null`; \}; `path?`: `never`; `query?`: `never`; `url`: `"/email/sync"`; \}## Properties-| Property | Type |-| ------ | ------ |-| <a id="property-body"></a> `body?` | `never` |-| <a id="property-path"></a> `path?` | `never` |-| <a id="property-query"></a> `query?` | `never` |-| <a id="property-url"></a> `url` | `"/email/sync"` |+| Property | Type | Description |+| ------ | ------ | ------ |+| <a id="property-body"></a> `body?` | `never` | - |+| <a id="property-headers"></a> `headers?` | \{ `X-Email-Link-Id?`: `string` \| `null`; \} | - |+| `headers.X-Email-Link-Id?` | `string` \| `null` | Inbox link ID to act on instead of the caller's primary inbox; may name a delegated inbox. |+| <a id="property-path"></a> `path?` | `never` | - |+| <a id="property-query"></a> `query?` | `never` | - |+| <a id="property-url"></a> `url` | `"/email/sync"` | - |diff --git a/packages/sdk-docs/reference/generated/email/types.gen/type-aliases/DisableSyncErrors.md b/packages/sdk-docs/reference/generated/email/types.gen/type-aliases/DisableSyncErrors.mdindex 06a47feecd..b0eb0dab57 100644--- a/packages/sdk-docs/reference/generated/email/types.gen/type-aliases/DisableSyncErrors.md+++ b/packages/sdk-docs/reference/generated/email/types.gen/type-aliases/DisableSyncErrors.md@@ -1,6 +1,6 @@# Type Alias: DisableSyncErrors-> **DisableSyncErrors** = \{ `400`: [`ErrorResponse`](ErrorResponse.md); `401`: [`ErrorResponse`](ErrorResponse.md); `500`: [`ErrorResponse`](ErrorResponse.md); \}+> **DisableSyncErrors** = \{ `400`: [`ErrorResponse`](ErrorResponse.md); `401`: [`ErrorResponse`](ErrorResponse.md); `403`: [`ErrorResponse`](ErrorResponse.md); `404`: [`ErrorResponse`](ErrorResponse.md); `409`: [`ErrorResponse`](ErrorResponse.md); `500`: [`ErrorResponse`](ErrorResponse.md); \}## Properties@@ -8,4 +8,7 @@| ------ | ------ || <a id="property-400"></a> `400` | [`ErrorResponse`](ErrorResponse.md) || <a id="property-401"></a> `401` | [`ErrorResponse`](ErrorResponse.md) |+| <a id="property-403"></a> `403` | [`ErrorResponse`](ErrorResponse.md) |+| <a id="property-404"></a> `404` | [`ErrorResponse`](ErrorResponse.md) |+| <a id="property-409"></a> `409` | [`ErrorResponse`](ErrorResponse.md) || <a id="property-500"></a> `500` | [`ErrorResponse`](ErrorResponse.md) |diff --git a/packages/sdk/generated/email/sdk.gen.ts b/packages/sdk/generated/email/sdk.gen.tsindex 58f38e6a46..1a6c974464 100644--- a/packages/sdk/generated/email/sdk.gen.ts+++ b/packages/sdk/generated/email/sdk.gen.ts@@ -471,7 +471,13 @@ export class Sdk extends HeyApiClient {}/**- * Disables inbox syncing for user.+ * Disables inbox syncing for the selected inbox.+ *+ * The inbox is the caller's primary, or the one named by `X-Email-Link-Id`,+ * which may be an inbox the caller only reaches through delegation. Removal+ * therefore follows the same policy as `DELETE /email/links/{link_id}`: an+ * owner's inbox is torn down, while a delegate only loses their+ * `macro_user_links` edge and the owner's data stays intact.*/public disableSync<ThrowOnError extends boolean = false>(options?: Options<DisableSyncData, ThrowOnError>): RequestResult<DisableSyncResponses, DisableSyncErrors, ThrowOnError> {return (options?.client ?? this.client).delete<DisableSyncResponses, DisableSyncErrors, ThrowOnError>({ url: '/email/sync', ...options });diff --git a/packages/sdk/generated/email/types.gen.ts b/packages/sdk/generated/email/types.gen.tsindex 357e99536d..0437be2d65 100644--- a/packages/sdk/generated/email/types.gen.ts+++ b/packages/sdk/generated/email/types.gen.ts@@ -2967,6 +2967,12 @@ export type MailboxSettingsOperationsResponse = MailboxSettingsOperationsResponsexport type DisableSyncData = {body?: never;+ headers?: {+ /**+ * Inbox link ID to act on instead of the caller's primary inbox; may name a delegated inbox.+ */+ 'X-Email-Link-Id'?: string | null;+ };path?: never;query?: never;url: '/email/sync';@@ -2975,6 +2981,9 @@ export type DisableSyncData = {export type DisableSyncErrors = {400: ErrorResponse;401: ErrorResponse;+ 403: ErrorResponse;+ 404: ErrorResponse;+ 409: ErrorResponse;500: ErrorResponse;};diff --git a/packages/sdk/specs/email.json b/packages/sdk/specs/email.jsonindex a9be7c28e4..16e211a997 100644--- a/packages/sdk/specs/email.json+++ b/packages/sdk/specs/email.json@@ -2722,8 +2722,21 @@"/email/sync": {"delete": {"tags": ["Sync"],- "summary": "Disables inbox syncing for user.",+ "summary": "Disables inbox syncing for the selected inbox.",+ "description": "The inbox is the caller's primary, or the one named by `X-Email-Link-Id`,\nwhich may be an inbox the caller only reaches through delegation. Removal\ntherefore follows the same policy as `DELETE /email/links/{link_id}`: an\nowner's inbox is torn down, while a delegate only loses their\n`macro_user_links` edge and the owner's data stays intact.","operationId": "disable_sync",+ "parameters": [+ {+ "name": "X-Email-Link-Id",+ "in": "header",+ "description": "Inbox link ID to act on instead of the caller's primary inbox; may name a delegated inbox.",+ "required": false,+ "schema": {+ "type": ["string", "null"],+ "format": "uuid"+ }+ }+ ],"responses": {"204": {"description": "",@@ -2755,6 +2768,36 @@}}},+ "403": {+ "description": "",+ "content": {+ "application/json": {+ "schema": {+ "$ref": "#/components/schemas/ErrorResponse"+ }+ }+ }+ },+ "404": {+ "description": "",+ "content": {+ "application/json": {+ "schema": {+ "$ref": "#/components/schemas/ErrorResponse"+ }+ }+ }+ },+ "409": {+ "description": "",+ "content": {+ "application/json": {+ "schema": {+ "$ref": "#/components/schemas/ErrorResponse"+ }+ }+ }+ },"500": {"description": "","content": {diff --git a/services/email_service/src/api/email/sync/disable.rs b/services/email_service/src/api/email/sync/disable.rsindex fc97a9a197..8eb1985455 100644--- a/services/email_service/src/api/email/sync/disable.rs+++ b/services/email_service/src/api/email/sync/disable.rs@@ -1,71 +1,55 @@use crate::api::context::{ApiContext, AuthorizationService};+use crate::api::email::links::access::InboxActionError;+use axum::Extension;use axum::extract::State;use axum::http::StatusCode;use axum::response::{IntoResponse, Response};-use axum::{Extension, Json};+use email::domain::mailbox::lifecycle::InboxActor;use macro_authorization::{MacroAuthorizationExtractor, UserOrInternal};use model::response::{EmptyResponse, ErrorResponse};use models_email::email::service::link::Link;-use models_email::email::service::pubsub::LinkManagerMessage;-use strum_macros::AsRefStr;-use thiserror::Error;-#[derive(Debug, Error, AsRefStr)]-pub enum DisableSyncError {- #[error("Failed to enqueue delete notification")]- EnqueueError(#[from] anyhow::Error),-}--impl IntoResponse for DisableSyncError {- fn into_response(self) -> Response {- let status_code = match &self {- DisableSyncError::EnqueueError(_) => StatusCode::INTERNAL_SERVER_ERROR,- };-- let message = self.to_string();- (- status_code,- Json(ErrorResponse {- message: message.into(),- }),- )- .into_response()- }-}--/// Disables inbox syncing for user.+/// Disables inbox syncing for the selected inbox.+///+/// The inbox is the caller's primary, or the one named by `X-Email-Link-Id`,+/// which may be an inbox the caller only reaches through delegation. Removal+/// therefore follows the same policy as `DELETE /email/links/{link_id}`: an+/// owner's inbox is torn down, while a delegate only loses their+/// `macro_user_links` edge and the owner's data stays intact.#[utoipa::path(delete,tag = "Sync",path = "/email/sync",operation_id = "disable_sync",+ params(+ ("X-Email-Link-Id" = Option<uuid::Uuid>, Header, description = "Inbox link ID to act on instead of the caller's primary inbox; may name a delegated inbox."),+ ),responses((status = 204, body=EmptyResponse),(status = 400, body=ErrorResponse),(status = 401, body=ErrorResponse),+ (status = 403, body=ErrorResponse),+ (status = 404, body=ErrorResponse),+ (status = 409, body=ErrorResponse),(status = 500, body=ErrorResponse),))]-#[tracing::instrument(skip(ctx, authorization, link), fields(user_id=authorization.authorization.user.user_context.user_id, fusionauth_user_id=authorization.authorization.user.user_context.fusion_user_id), err)]+#[tracing::instrument(skip(ctx, authorization, link), fields(user_id=authorization.authorization.user.user_context.user_id, fusionauth_user_id=authorization.authorization.user.user_context.fusion_user_id, link_id=%link.id), err)]pub async fn disable_handler(State(ctx): State<ApiContext>,authorization: MacroAuthorizationExtractor<AuthorizationService, UserOrInternal>,- link: Extension<Link>,-) -> Result<Response, DisableSyncError> {- tracing::info!(user_id = %authorization.authorization.user.user_context.user_id, "Disable called");-- // Enqueue the delete operation to handle cleanup asynchronously- let message = LinkManagerMessage::DeleteLink {- link_id: link.id,- deletion_reason: models_email::email::service::pubsub::DeletionReason::ManuallyDisabled,+ Extension(link): Extension<Link>,+) -> Result<Response, InboxActionError> {+ let actor = InboxActor {+ macro_id: authorization.authorization.user.macro_user_id.clone(),+ credential_owner: authorization+ .authorization+ .user+ .user_context+ .fusion_user_id+ .to_string(),};-- ctx.sqs_client- .enqueue_link_manager_notification(message)- .await- .inspect_err(|e| {- tracing::error!(error=?e, link_id=?link.id, "Failed to enqueue delete notification");- })?;+ ctx.inbox_lifecycle.remove(&actor, link.id).await?;Ok(StatusCode::NO_CONTENT.into_response())}