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
get document short id call (#1789)
Will Hutchinson3e6725a116fc
diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/index.ts b/js/app/packages/service-clients/service-storage/generated/schemas/index.tsindex 0155fff73f..c64737ec34 100644--- a/js/app/packages/service-clients/service-storage/generated/schemas/index.ts+++ b/js/app/packages/service-clients/service-storage/generated/schemas/index.ts@@ -500,6 +500,7 @@ export * from './setPropertyValueOneOfType';export * from './sharePermissionV2';export * from './sharePermissionV2ChannelSharePermissions';export * from './sharePermissionV2PublicAccessLevel';+export * from './shortIdResponse';export * from './soupApiItem';export * from './soupApiItemAllOf';export * from './soupApiSort';diff --git a/js/app/packages/service-clients/service-storage/generated/schemas/shortIdResponse.ts b/js/app/packages/service-clients/service-storage/generated/schemas/shortIdResponse.tsnew file mode 100644index 0000000000..49058b1bff--- /dev/null+++ b/js/app/packages/service-clients/service-storage/generated/schemas/shortIdResponse.ts@@ -0,0 +1,14 @@+/**+ * Generated by orval v7.13.0 🍺+ * Do not edit manually.+ * document_storage_service+ * OpenAPI spec version: 0.1.0+ */++/**+ * Short ID response+ */+export interface ShortIdResponse {+ /** The short id of the document */+ shortId: string;+}diff --git a/js/app/packages/service-clients/service-storage/generated/zod.ts b/js/app/packages/service-clients/service-storage/generated/zod.tsindex f4093b60ef..6573e8bd6b 100644--- a/js/app/packages/service-clients/service-storage/generated/zod.ts+++ b/js/app/packages/service-clients/service-storage/generated/zod.ts@@ -2305,6 +2305,14 @@ export const revertDeleteDocumentResponse = zod.object({error: zod.boolean().describe('Indicates if an error occurred'),});+/**+ * Returns the short UUID for a document.+ * @summary Handler for `GET /documents/:document_id/short_id`.+ */+export const getDocumentShortIdParams = zod.object({+ document_id: zod.string().describe('Document ID'),+});+/*** @summary For any file that isn't PDF or DOCX, use this endpoint for saving.This endpoint will allow you to save the document by providing the file content as part of a multipart request. Use key 'file' along with the file bytes.diff --git a/js/app/packages/service-clients/service-storage/openapi.json b/js/app/packages/service-clients/service-storage/openapi.jsonindex 3bbe52c0f6..b66c0d6e21 100644--- a/js/app/packages/service-clients/service-storage/openapi.json+++ b/js/app/packages/service-clients/service-storage/openapi.json@@ -2260,6 +2260,67 @@}}},+ "/documents/{document_id}/short_id": {+ "get": {+ "tags": ["document"],+ "summary": "Handler for `GET /documents/:document_id/short_id`.",+ "description": "Returns the short UUID for a document.",+ "operationId": "get_document_short_id",+ "parameters": [+ {+ "name": "document_id",+ "in": "path",+ "description": "Document ID",+ "required": true,+ "schema": {+ "type": "string"+ }+ }+ ],+ "responses": {+ "200": {+ "description": "",+ "content": {+ "text/plain": {+ "schema": {+ "type": "string"+ }+ }+ }+ },+ "401": {+ "description": "",+ "content": {+ "application/json": {+ "schema": {+ "$ref": "#/components/schemas/ErrorResponse"+ }+ }+ }+ },+ "404": {+ "description": "",+ "content": {+ "application/json": {+ "schema": {+ "$ref": "#/components/schemas/ErrorResponse"+ }+ }+ }+ },+ "500": {+ "description": "",+ "content": {+ "application/json": {+ "schema": {+ "$ref": "#/components/schemas/ErrorResponse"+ }+ }+ }+ }+ }+ }+ },"/documents/{document_id}/simple_save": {"put": {"tags": ["document"],@@ -9453,6 +9514,17 @@}}},+ "ShortIdResponse": {+ "type": "object",+ "description": "Short ID response",+ "required": ["shortId"],+ "properties": {+ "shortId": {+ "type": "string",+ "description": "The short id of the document"+ }+ }+ },"SoupApiItem": {"allOf": [{diff --git a/rust/cloud-storage/document_storage_service/src/api/swagger.rs b/rust/cloud-storage/document_storage_service/src/api/swagger.rsindex 4508cf8702..5bb5c556b9 100644--- a/rust/cloud-storage/document_storage_service/src/api/swagger.rs+++ b/rust/cloud-storage/document_storage_service/src/api/swagger.rs@@ -71,6 +71,7 @@ use channels::inbound::axum_router::{ApiThreadInfo, ApiThreadReply,};use document_sub_type::DocumentSubType;+use documents_hex::inbound::axum_router::ShortIdResponse;use model::document::response::{CreateDocumentRequest, CreateDocumentResponse, CreateDocumentResponseData,DocumentResponseMetadata,@@ -153,6 +154,7 @@ use utoipa::OpenApi;documents::get_document_views::get_document_views_handler,documents::location::get_location_handler,documents_hex::inbound::axum_router::get_location_v3_handler,+ documents_hex::inbound::axum_router::get_short_id_handler,documents::simple_save::handler,documents::initialize_user_documents::handler,documents::get_batch_preview::get_batch_preview_handler,@@ -376,6 +378,7 @@ use utoipa::OpenApi;CreateViewRequest,ExcludeDefaultViewRequest,+ ShortIdResponse,),),tags(diff --git a/rust/cloud-storage/documents/src/domain/ports.rs b/rust/cloud-storage/documents/src/domain/ports.rsindex 3cf4ba56e6..efdff7d0e5 100644--- a/rust/cloud-storage/documents/src/domain/ports.rs+++ b/rust/cloud-storage/documents/src/domain/ports.rs@@ -186,6 +186,12 @@ pub trait DocumentService: Send + Sync + 'static {job_id: Option<String>,) -> impl Future<Output = Result<CreateDocumentResponseData, DocumentError>> + Send;+ /// Convert a document's entity_id to a short UUID.+ fn get_short_id(+ &self,+ entity_access_receipt: EntityAccessReceipt<ViewAccessLevel>,+ ) -> impl Future<Output = Result<String, DocumentError>> + Send;+/// Updates the tasks status to what is providedfn update_task_status(&self,diff --git a/rust/cloud-storage/documents/src/domain/service.rs b/rust/cloud-storage/documents/src/domain/service.rsindex 6b3524fdb3..1a06feec6d 100644--- a/rust/cloud-storage/documents/src/domain/service.rs+++ b/rust/cloud-storage/documents/src/domain/service.rs@@ -441,6 +441,17 @@ impl<R: DocumentRepo, U: PresignedUploadUrlPort, T: TaskPropertiesPort> Document.map_err(|e| DocumentError::Internal(e.into()))}+ async fn get_short_id(+ &self,+ entity_access_receipt: EntityAccessReceipt<ViewAccessLevel>,+ ) -> Result<String, DocumentError> {+ let entity_id = &entity_access_receipt.entity().entity_id;+ let uuid = macro_uuid::string_to_uuid(entity_id)+ .map_err(|e| DocumentError::BadRequest(format!("invalid entity_id: {e}")))?;+ let short_id = macro_uuid::ShortUuidConverter::default().from_uuid(&uuid);+ Ok(short_id)+ }+#[tracing::instrument(err, skip(self, args))]async fn create_document(&self,diff --git a/rust/cloud-storage/documents/src/inbound/axum_router.rs b/rust/cloud-storage/documents/src/inbound/axum_router.rsindex 7ab431eb91..0ab3edc42c 100644--- a/rust/cloud-storage/documents/src/inbound/axum_router.rs+++ b/rust/cloud-storage/documents/src/inbound/axum_router.rs@@ -112,6 +112,10 @@ where"/:document_id/location_v3",axum::routing::get(get_location_v3_handler::<T, Svc>),)+ .route(+ "/:document_id/short_id",+ axum::routing::get(get_short_id_handler::<T, Svc>),+ ).layer(middleware::from_fn_with_state(state.clone(),ensure_document_exists,@@ -257,6 +261,46 @@ pub async fn get_location_v3_handler<T: DocumentService, Svc: EntityAccessServicOk((header_map, Json(response_data)))}+/// Short ID response+#[derive(serde::Serialize, utoipa::ToSchema)]+#[serde(rename_all = "camelCase")]+pub struct ShortIdResponse {+ /// The short id of the document+ short_id: String,+}++/// Handler for `GET /documents/:document_id/short_id`.+///+/// Returns the short UUID for a document.+#[utoipa::path(+ tag = "document",+ get,+ path = "/documents/{document_id}/short_id",+ operation_id = "get_document_short_id",+ params(+ ("document_id" = String, Path, description = "Document ID")+ ),+ responses(+ (status = 200, body = String),+ (status = 401, body = ErrorResponse),+ (status = 404, body = ErrorResponse),+ (status = 500, body = ErrorResponse),+ )+)]+#[tracing::instrument(skip(state, access), err)]+pub async fn get_short_id_handler<T: DocumentService, Svc: EntityAccessService>(+ State(state): State<DocumentRouterState<T, Svc>>,+ access: DocumentAccessExtractor<ViewAccessLevel, Svc>,+ Path(Params { document_id }): Path<Params>,+) -> Result<Json<ShortIdResponse>, DocumentError> {+ let short_id = state+ .service+ .get_short_id(access.entity_access_receipt)+ .await?;++ Ok(Json(ShortIdResponse { short_id }))+}+/// Handler for `DELETE /documents/:document_id`.////// Soft-deletes a document (only owners can delete).diff --git a/rust/cloud-storage/github/src/domain/service/sync/test.rs b/rust/cloud-storage/github/src/domain/service/sync/test.rsindex 21eea4d131..685fde6586 100644--- a/rust/cloud-storage/github/src/domain/service/sync/test.rs+++ b/rust/cloud-storage/github/src/domain/service/sync/test.rs@@ -106,6 +106,12 @@ impl DocumentService for StubDocumentService {) -> Result<DocumentBasic, DocumentError> {unimplemented!()}+ async fn get_short_id(+ &self,+ _receipt: EntityAccessReceipt<ViewAccessLevel>,+ ) -> Result<String, DocumentError> {+ unimplemented!()+ }async fn get_document(&self,receipt: EntityAccessReceipt<ViewAccessLevel>,diff --git a/rust/cloud-storage/macro_uuid/src/lib.rs b/rust/cloud-storage/macro_uuid/src/lib.rsindex 751447da72..2d89958588 100644--- a/rust/cloud-storage/macro_uuid/src/lib.rs+++ b/rust/cloud-storage/macro_uuid/src/lib.rs@@ -97,38 +97,4 @@ impl ShortUuidConverter {}#[cfg(test)]-mod tests {- use super::*;-- #[test]- fn test_bidirectional_conversion() {- let converter = ShortUuidConverter::default();-- // Start with a known UUID- let original_uuid = Uuid::parse_str("550e8400-e29b-41d4-a716-446655440000").unwrap();-- // Convert to short UUID- let short = converter.from_uuid(&original_uuid);-- // Convert back to UUID- let recovered_uuid = converter.to_uuid(&short).unwrap();-- // They should match- assert_eq!(original_uuid, recovered_uuid);- }- #[test]- fn test_specific_conversion() {- let converter = ShortUuidConverter::default();- // TODO: add more tests- let uuids = vec![(- "0d0dc589-f301-43f1-8b11-4ab448ca4bb4",- "2BuyvtY3aeEvHx4uG8iD51",- )];-- for (uuid, short) in uuids {- let converted_uuid = Uuid::parse_str(uuid).unwrap();- let converted_short = converter.from_uuid(&converted_uuid);- assert_eq!((uuid, converted_short.as_str()), (uuid, short));- }- }-}+mod test;diff --git a/rust/cloud-storage/macro_uuid/src/test.rs b/rust/cloud-storage/macro_uuid/src/test.rsnew file mode 100644index 0000000000..e49a5e8901--- /dev/null+++ b/rust/cloud-storage/macro_uuid/src/test.rs@@ -0,0 +1,49 @@+use super::*;++#[test]+fn test_bidirectional_conversion() {+ let converter = ShortUuidConverter::default();++ // Start with a known UUID+ let original_uuid = Uuid::parse_str("550e8400-e29b-41d4-a716-446655440000").unwrap();++ // Convert to short UUID+ let short = converter.from_uuid(&original_uuid);++ // Convert back to UUID+ let recovered_uuid = converter.to_uuid(&short).unwrap();++ // They should match+ assert_eq!(original_uuid, recovered_uuid);+}++#[test]+fn test_short_id_is_shorter_than_uuid() {+ let uuid_str = "550e8400-e29b-41d4-a716-446655440000";+ let uuid = string_to_uuid(uuid_str).unwrap();+ let short_id = ShortUuidConverter::default().from_uuid(&uuid);+ assert!(!short_id.is_empty());+ assert!(short_id.len() < uuid_str.len());+}++#[test]+fn test_string_to_uuid_invalid_input() {+ let result = string_to_uuid("not-a-uuid");+ assert!(result.is_err());+}++#[test]+fn test_specific_conversion() {+ let converter = ShortUuidConverter::default();+ // TODO: add more tests+ let uuids = vec![(+ "0d0dc589-f301-43f1-8b11-4ab448ca4bb4",+ "2BuyvtY3aeEvHx4uG8iD51",+ )];++ for (uuid, short) in uuids {+ let converted_uuid = Uuid::parse_str(uuid).unwrap();+ let converted_short = converter.from_uuid(&converted_uuid);+ assert_eq!((uuid, converted_short.as_str()), (uuid, short));+ }+}