-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Expand file tree
/
Copy pathfiles-audit.ts
More file actions
856 lines (849 loc) · 26.8 KB
/
Copy pathfiles-audit.ts
File metadata and controls
856 lines (849 loc) · 26.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
import { z } from 'zod'
import { v2GetAuditLogContract, v2ListAuditLogsContract } from '@/lib/api/contracts/v2/audit-logs'
import {
v2AbortFileUploadContract,
v2BulkDeleteFilesContract,
v2CompleteFileUploadContract,
v2CreateFileContract,
v2CreateFileFolderContract,
v2CreateFileUploadContract,
v2CreateFileUploadPartUrlsContract,
v2DeleteFileContract,
v2DeleteFileFolderContract,
v2DownloadFileContract,
v2GetFileContract,
v2GetFileShareContract,
v2ListFileFoldersContract,
v2ListFilesContract,
v2MoveFileItemsContract,
v2RelocateFileFolderContract,
v2RenameFileContract,
v2UpdateFileContentContract,
v2UpsertFileShareContract,
} from '@/lib/api/contracts/v2/files'
import {
documentedSchema,
ERROR_RESPONSES,
type ErrorResponseId,
RATE_LIMIT_HEADERS,
STANDARD_ERRORS,
V2_API_KEY_SECURITY,
V2_API_KEY_SECURITY_SCHEMES,
V2_COMMON_HEADERS,
V2_ERROR_SCHEMA,
WORKSPACE_ERRORS,
} from '@/lib/api/contracts/v2/openapi/shared'
import {
defineOpenApiDocument,
defineOpenApiRoute,
type OpenApiOperationMetadata,
type OpenApiSuccessMetadata,
} from '@/lib/api/openapi/types'
const FILE_EXAMPLE = {
id: 'wf_V1StGXR8z5jdHi6BmyT91',
name: 'data.csv',
size: 1024,
type: 'text/csv',
key: 'workspace/example/data.csv',
folderPath: '/Engineering',
uploadedByEmail: 'jane@example.com',
uploadedAt: '2026-01-15T10:30:00Z',
updatedAt: '2026-01-15T10:30:00Z',
} as const
const SHARE_EXAMPLE = {
id: 'shr_8Hf3kL9wQ2mNpXr6Tz1Vb',
token: 'share-token-example',
url: 'https://www.sim.ai/f/share-token-example',
isActive: true,
resourceType: 'file',
resourceId: FILE_EXAMPLE.id,
authType: 'public',
hasPassword: false,
allowedEmails: [],
} as const
const AUDIT_LOG_EXAMPLE = {
id: 'audit_2c3d4e5f6g',
workspaceId: 'a91c4b2e-6d3f-4e8a-b5c7-0d9e2f1a8c64',
actorName: 'Jane Smith',
actorEmail: 'jane@example.com',
action: 'file.uploaded',
resourceType: 'file',
resourceId: FILE_EXAMPLE.id,
resourceName: FILE_EXAMPLE.name,
description: 'Uploaded file "data.csv" via API',
metadata: { fileSize: 1024, fileType: 'text/csv' },
createdAt: '2026-01-15T10:30:00Z',
} as const
function filesOperation(
operation: Omit<OpenApiOperationMetadata, 'tags' | 'success' | 'errors'> & {
errors: readonly ErrorResponseId[]
success: OpenApiSuccessMetadata
}
): OpenApiOperationMetadata {
return {
...operation,
tags: ['Files'],
success: {
...operation.success,
headers: [...(operation.success.headers ?? []), ...RATE_LIMIT_HEADERS],
},
}
}
function auditOperation(
operation: Omit<OpenApiOperationMetadata, 'tags' | 'success' | 'errors'> & {
errors: readonly ErrorResponseId[]
success: OpenApiSuccessMetadata
}
): OpenApiOperationMetadata {
return {
...operation,
tags: ['Audit Logs'],
success: {
...operation.success,
headers: [...(operation.success.headers ?? []), ...RATE_LIMIT_HEADERS],
},
}
}
const routes = [
defineOpenApiRoute(
v2ListFilesContract,
filesOperation({
operationId: 'listFiles',
summary: 'List Files',
description:
'List workspace files with search, sorting, folder filtering, and opaque cursor pagination.',
errors: WORKSPACE_ERRORS,
success: { description: 'A page of workspace files.' },
}),
{
query: documentedSchema(
v2ListFilesContract.query,
'ListFilesQuery',
'List files query',
'Filters, sorting, and pagination for a workspace file list.'
),
response: documentedSchema(
v2ListFilesContract.response.schema,
'V2FileListResponse',
'File list response',
'A cursor-paginated page of workspace files.',
[{ data: [FILE_EXAMPLE], nextCursor: null }]
),
}
),
defineOpenApiRoute(
v2CreateFileContract,
filesOperation({
operationId: 'createFile',
summary: 'Create File',
description:
'Create a workspace file from inline UTF-8 or base64 content. Use an upload session for streamed or larger files.',
errors: [...WORKSPACE_ERRORS, 'NotFound', 'Conflict', 'PayloadTooLarge'],
success: { description: 'The created file.' },
}),
{
body: documentedSchema(
v2CreateFileContract.body,
'CreateFileRequest',
'Create file request',
'Inline content and placement for a new workspace file.',
[
{
workspaceId: 'a91c4b2e-6d3f-4e8a-b5c7-0d9e2f1a8c64',
name: 'notes.md',
content: '# Notes',
},
]
),
response: documentedSchema(
v2CreateFileContract.response.schema,
'V2FileResponse',
'File response',
'A single workspace file.',
[{ data: FILE_EXAMPLE }]
),
}
),
defineOpenApiRoute(
v2CreateFileUploadContract,
filesOperation({
operationId: 'createFileUpload',
summary: 'Create File Upload',
description:
'Create a resumable upload session and receive either a signed PUT URL or multipart instructions.',
errors: WORKSPACE_ERRORS,
success: { description: 'The created upload session and transfer instructions.' },
}),
{
body: documentedSchema(
v2CreateFileUploadContract.body,
'CreateFileUploadRequest',
'Create file upload request',
'File metadata required to create an upload session.',
[
{
workspaceId: 'a91c4b2e-6d3f-4e8a-b5c7-0d9e2f1a8c64',
name: 'archive.zip',
contentType: 'application/zip',
size: 1048576,
},
]
),
response: documentedSchema(
v2CreateFileUploadContract.response.schema,
'CreateFileUploadResponse',
'Create file upload response',
'Upload session, signed control token, and transfer strategy.'
),
}
),
defineOpenApiRoute(
v2AbortFileUploadContract,
filesOperation({
operationId: 'abortFileUpload',
summary: 'Abort File Upload',
description: 'Abort an active upload session and release provider-side multipart state.',
errors: [...STANDARD_ERRORS, 'NotFound', 'Conflict'],
success: { description: 'The aborted upload session.' },
}),
{
params: documentedSchema(
v2AbortFileUploadContract.params,
'AbortFileUploadParams',
'Abort upload path parameters',
'Upload session selected for abortion.'
),
query: documentedSchema(
v2AbortFileUploadContract.query,
'AbortFileUploadQuery',
'Abort upload query',
'Workspace scope for the upload session.'
),
headers: documentedSchema(
v2AbortFileUploadContract.headers,
'AbortFileUploadHeaders',
'Abort upload headers',
'Signed upload control token.'
),
response: documentedSchema(
v2AbortFileUploadContract.response.schema,
'FileUploadResponse',
'File upload response',
'Current upload-session state.'
),
}
),
defineOpenApiRoute(
v2CreateFileUploadPartUrlsContract,
filesOperation({
operationId: 'createFileUploadPartUrls',
summary: 'Create File Upload Part URLs',
description: 'Create signed URLs for a bounded set of multipart upload part numbers.',
errors: [...STANDARD_ERRORS, 'BadRequest', 'NotFound', 'Conflict'],
success: { description: 'Signed URLs for the requested upload parts.' },
}),
{
params: documentedSchema(
v2CreateFileUploadPartUrlsContract.params,
'FileUploadPartUrlsParams',
'Upload part URL path parameters',
'Upload session selected for multipart URL creation.'
),
query: documentedSchema(
v2CreateFileUploadPartUrlsContract.query,
'FileUploadPartUrlsQuery',
'Upload part URL query',
'Workspace scope for the upload session.'
),
headers: documentedSchema(
v2CreateFileUploadPartUrlsContract.headers,
'FileUploadPartUrlsHeaders',
'Upload part URL headers',
'Signed upload control token.'
),
body: documentedSchema(
v2CreateFileUploadPartUrlsContract.body,
'CreateFileUploadPartUrlsRequest',
'Create upload part URLs request',
'Multipart part numbers requiring signed URLs.',
[{ partNumbers: [1, 2] }]
),
response: documentedSchema(
v2CreateFileUploadPartUrlsContract.response.schema,
'CreateFileUploadPartUrlsResponse',
'Create upload part URLs response',
'Signed multipart upload URLs.'
),
}
),
defineOpenApiRoute(
v2CompleteFileUploadContract,
filesOperation({
operationId: 'completeFileUpload',
summary: 'Complete File Upload',
description:
'Finalize uploaded bytes, verify provider state, and begin atomic workspace-file registration.',
errors: [...STANDARD_ERRORS, 'BadRequest', 'NotFound', 'Conflict'],
success: { description: 'The completed or finalizing upload session.' },
}),
{
params: documentedSchema(
v2CompleteFileUploadContract.params,
'CompleteFileUploadParams',
'Complete upload path parameters',
'Upload session selected for completion.'
),
query: documentedSchema(
v2CompleteFileUploadContract.query,
'CompleteFileUploadQuery',
'Complete upload query',
'Workspace scope for the upload session.'
),
headers: documentedSchema(
v2CompleteFileUploadContract.headers,
'CompleteFileUploadHeaders',
'Complete upload headers',
'Signed upload control token.'
),
response: documentedSchema(
v2CompleteFileUploadContract.response.schema,
'FileUploadResponse',
'File upload response',
'Current upload-session state.'
),
}
),
defineOpenApiRoute(
v2DownloadFileContract,
filesOperation({
operationId: 'downloadFile',
summary: 'Download File',
description:
'Download the current file bytes from a workspace. A generated document is served as its compiled artifact, so it returns `409` while that artifact is still compiling and `413` if it renders past the size ceiling.',
errors: [...WORKSPACE_ERRORS, 'NotFound', 'Conflict', 'PayloadTooLarge'],
success: {
description: 'The file bytes.',
headers: ['Content-Type', 'Content-Disposition', 'Content-Length'],
contentTypes: ['application/octet-stream'],
},
}),
{
params: documentedSchema(
v2DownloadFileContract.params,
'DownloadFileParams',
'Download file path parameters',
'File selected for download.'
),
query: documentedSchema(
v2DownloadFileContract.query,
'DownloadFileQuery',
'Download file query',
'Workspace scope for the file.'
),
}
),
defineOpenApiRoute(
v2DeleteFileContract,
filesOperation({
operationId: 'deleteFile',
summary: 'Delete File',
description: 'Delete a workspace file and its stored bytes.',
errors: [...WORKSPACE_ERRORS, 'NotFound', 'Conflict'],
success: { description: 'Deletion confirmation.' },
}),
{
params: documentedSchema(
v2DeleteFileContract.params,
'DeleteFileParams',
'Delete file path parameters',
'File selected for deletion.'
),
query: documentedSchema(
v2DeleteFileContract.query,
'DeleteFileQuery',
'Delete file query',
'Workspace scope for the file.'
),
response: documentedSchema(
v2DeleteFileContract.response.schema,
'V2DeleteFileResponse',
'Delete file response',
'Deletion confirmation for one file.'
),
}
),
defineOpenApiRoute(
v2RenameFileContract,
filesOperation({
operationId: 'renameFile',
summary: 'Rename File',
description: 'Rename a workspace file without changing its containing folder.',
errors: [...WORKSPACE_ERRORS, 'NotFound', 'Conflict'],
success: { description: 'The renamed file.' },
}),
{
params: documentedSchema(
v2RenameFileContract.params,
'RenameFileParams',
'Rename file path parameters',
'File selected for renaming.'
),
body: documentedSchema(
v2RenameFileContract.body,
'RenameFileRequest',
'Rename file request',
'Workspace scope and new file name.',
[
{
workspaceId: 'a91c4b2e-6d3f-4e8a-b5c7-0d9e2f1a8c64',
name: 'renamed.csv',
},
]
),
response: documentedSchema(
v2RenameFileContract.response.schema,
'V2FileResponse',
'File response',
'A single workspace file.',
[{ data: FILE_EXAMPLE }]
),
}
),
defineOpenApiRoute(
v2GetFileContract,
filesOperation({
operationId: 'getFile',
summary: 'Get File Metadata',
description: 'Return file metadata together with the nullable current public-share state.',
errors: [...WORKSPACE_ERRORS, 'NotFound'],
success: { description: 'File metadata and public-share state.' },
}),
{
params: documentedSchema(
v2GetFileContract.params,
'GetFileMetadataParams',
'Get file metadata path parameters',
'File whose metadata should be returned.'
),
query: documentedSchema(
v2GetFileContract.query,
'GetFileMetadataQuery',
'Get file metadata query',
'Workspace scope for the file.'
),
response: documentedSchema(
v2GetFileContract.response.schema,
'V2FileMetadataResponse',
'File metadata response',
'File metadata enriched with its current nullable public-share state.',
[
{ data: { ...FILE_EXAMPLE, share: null } },
{ data: { ...FILE_EXAMPLE, share: SHARE_EXAMPLE } },
]
),
}
),
defineOpenApiRoute(
v2ListAuditLogsContract,
auditOperation({
operationId: 'listAuditLogs',
summary: 'List Audit Logs',
description:
'List an organization audit trail with filters and opaque cursor pagination. Requires an Enterprise subscription and organization admin or owner access.',
errors: [...STANDARD_ERRORS, 'BadRequest', 'Forbidden'],
success: { description: 'A page of audit-log entries.' },
}),
{
query: documentedSchema(
v2ListAuditLogsContract.query,
'ListAuditLogsQuery',
'List audit logs query',
'Organization scope, filters, and pagination for the audit trail.'
),
response: documentedSchema(
v2ListAuditLogsContract.response.schema,
'V2AuditLogListResponse',
'Audit-log list response',
'A cursor-paginated page of audit-log entries.',
[{ data: [AUDIT_LOG_EXAMPLE], nextCursor: null }]
),
}
),
defineOpenApiRoute(
v2GetAuditLogContract,
auditOperation({
operationId: 'getAuditLog',
summary: 'Get Audit Log',
description:
'Return one organization audit-log entry. Requires an Enterprise subscription and organization admin or owner access.',
errors: [...STANDARD_ERRORS, 'Forbidden', 'NotFound'],
success: { description: 'The requested audit-log entry.' },
}),
{
params: documentedSchema(
v2GetAuditLogContract.params,
'GetAuditLogParams',
'Get audit log path parameters',
'Audit-log entry selected by identifier.'
),
query: documentedSchema(
v2GetAuditLogContract.query,
'GetAuditLogQuery',
'Get audit log query',
'Organization scope for the audit-log entry.'
),
response: documentedSchema(
v2GetAuditLogContract.response.schema,
'V2AuditLogResponse',
'Audit-log response',
'A single audit-log entry.',
[{ data: AUDIT_LOG_EXAMPLE }]
),
}
),
defineOpenApiRoute(
v2MoveFileItemsContract,
filesOperation({
operationId: 'moveFileItems',
summary: 'Move Files',
description: 'Move up to 1,000 files to a canonical folder path or the workspace root.',
errors: [...WORKSPACE_ERRORS, 'NotFound', 'Conflict'],
success: { description: 'Count of moved files.' },
}),
{
body: documentedSchema(
v2MoveFileItemsContract.body,
'MoveFileItemsRequest',
'Move files request',
'Files and destination selected for a bulk move.',
[
{
workspaceId: 'a91c4b2e-6d3f-4e8a-b5c7-0d9e2f1a8c64',
fileIds: [FILE_EXAMPLE.id],
targetFolderPath: '/Archive',
},
]
),
response: documentedSchema(
v2MoveFileItemsContract.response.schema,
'V2MoveFileItemsResponse',
'Move files response',
'Count of files moved by the operation.',
[{ data: { movedItems: { files: 1 } } }]
),
}
),
defineOpenApiRoute(
v2GetFileShareContract,
filesOperation({
operationId: 'getFileShare',
summary: 'Get File Share',
description: 'Return the current public-share configuration for a file.',
errors: [...WORKSPACE_ERRORS, 'NotFound'],
success: { description: 'Current nullable file-share state.' },
}),
{
params: documentedSchema(
v2GetFileShareContract.params,
'GetFileShareParams',
'Get file share path parameters',
'File whose public-share state should be returned.'
),
query: documentedSchema(
v2GetFileShareContract.query,
'GetFileShareQuery',
'Get file share query',
'Workspace scope for the file.'
),
response: documentedSchema(
v2GetFileShareContract.response.schema,
'V2GetFileShareResponse',
'Get file share response',
'Current public-share state for a file.',
[{ data: { share: SHARE_EXAMPLE } }, { data: { share: null } }]
),
}
),
defineOpenApiRoute(
v2UpsertFileShareContract,
filesOperation({
operationId: 'upsertFileShare',
summary: 'Enable or Disable File Share',
description:
'Create or update a server-tokenized public share. Disabling retains its token and configuration for later re-enablement.',
errors: [...WORKSPACE_ERRORS, 'NotFound'],
success: { description: 'The updated file share.' },
}),
{
params: documentedSchema(
v2UpsertFileShareContract.params,
'UpsertFileShareParams',
'Upsert file share path parameters',
'File whose public-share state should be updated.'
),
body: documentedSchema(
v2UpsertFileShareContract.body,
'UpsertFileShareRequest',
'Upsert file share request',
'Desired public-share state and access policy.',
[
{
workspaceId: 'a91c4b2e-6d3f-4e8a-b5c7-0d9e2f1a8c64',
isActive: true,
authType: 'public',
},
{
workspaceId: 'a91c4b2e-6d3f-4e8a-b5c7-0d9e2f1a8c64',
isActive: false,
},
]
),
response: documentedSchema(
v2UpsertFileShareContract.response.schema,
'V2UpsertFileShareResponse',
'Upsert file share response',
'Updated public-share state for a file.',
[{ data: { share: SHARE_EXAMPLE } }]
),
}
),
defineOpenApiRoute(
v2UpdateFileContentContract,
filesOperation({
operationId: 'updateFileContent',
summary: 'Replace File Content',
description: 'Replace the complete contents of an existing file from UTF-8 or base64 input.',
errors: [...WORKSPACE_ERRORS, 'NotFound', 'PayloadTooLarge'],
success: { description: 'The updated file.' },
}),
{
params: documentedSchema(
v2UpdateFileContentContract.params,
'UpdateFileContentParams',
'Update file content path parameters',
'File whose contents should be replaced.'
),
body: documentedSchema(
v2UpdateFileContentContract.body,
'UpdateFileContentRequest',
'Update file content request',
'Workspace scope and complete replacement content.',
[
{
workspaceId: 'a91c4b2e-6d3f-4e8a-b5c7-0d9e2f1a8c64',
content: 'replacement text',
},
]
),
response: documentedSchema(
v2UpdateFileContentContract.response.schema,
'V2FileResponse',
'File response',
'A single workspace file.',
[{ data: FILE_EXAMPLE }]
),
}
),
defineOpenApiRoute(
v2BulkDeleteFilesContract,
filesOperation({
operationId: 'bulkDeleteFiles',
summary: 'Delete Files',
description: 'Delete up to 1,000 workspace files in one operation.',
errors: [...WORKSPACE_ERRORS, 'NotFound', 'Conflict'],
success: { description: 'Count of deleted files.' },
}),
{
body: documentedSchema(
v2BulkDeleteFilesContract.body,
'BulkDeleteFilesRequest',
'Bulk delete files request',
'Workspace and files selected for deletion.',
[
{
workspaceId: 'a91c4b2e-6d3f-4e8a-b5c7-0d9e2f1a8c64',
fileIds: [FILE_EXAMPLE.id],
},
]
),
response: documentedSchema(
v2BulkDeleteFilesContract.response.schema,
'BulkDeleteFilesResponse',
'Bulk delete files response',
'Count of files deleted by the operation.',
[{ data: { deletedItems: { files: 1 } } }]
),
}
),
defineOpenApiRoute(
v2ListFileFoldersContract,
filesOperation({
operationId: 'listFilesFolders',
summary: 'List Folders',
description: 'List workspace file folders with optional parent-path filtering and sorting.',
errors: [...WORKSPACE_ERRORS, 'NotFound', 'Conflict'],
success: { description: 'Workspace file folders.' },
}),
{
query: documentedSchema(
v2ListFileFoldersContract.query,
'ListFileFoldersQuery',
'List file folders query',
'Workspace scope, filters, and sorting for file folders.'
),
response: documentedSchema(
v2ListFileFoldersContract.response.schema,
'FileFolderListResponse',
'File folder list response',
'Workspace file folders in the current page.'
),
}
),
defineOpenApiRoute(
v2CreateFileFolderContract,
filesOperation({
operationId: 'createFilesFolder',
summary: 'Create Folder',
description: 'Create a canonical folder path in a workspace.',
errors: [...WORKSPACE_ERRORS, 'NotFound', 'Conflict'],
success: { description: 'The created folder.' },
}),
{
body: documentedSchema(
v2CreateFileFolderContract.body,
'CreateFileFolderRequest',
'Create file folder request',
'Workspace and canonical path for a new folder.',
[
{
workspaceId: 'a91c4b2e-6d3f-4e8a-b5c7-0d9e2f1a8c64',
path: '/Engineering',
},
]
),
response: documentedSchema(
v2CreateFileFolderContract.response.schema,
'FileFolderResponse',
'File folder response',
'A single workspace file folder.'
),
}
),
defineOpenApiRoute(
v2RelocateFileFolderContract,
filesOperation({
operationId: 'relocateFilesFolder',
summary: 'Rename or Move Folder',
description: 'Rename or move a folder and atomically rewrite descendant canonical paths.',
errors: [...WORKSPACE_ERRORS, 'NotFound', 'Conflict'],
success: { description: 'The relocated folder.' },
}),
{
body: documentedSchema(
v2RelocateFileFolderContract.body,
'RelocateFileFolderRequest',
'Relocate file folder request',
'Current and destination canonical paths for a folder.',
[
{
workspaceId: 'a91c4b2e-6d3f-4e8a-b5c7-0d9e2f1a8c64',
path: '/Engineering',
destinationPath: '/Archive/Engineering',
},
]
),
response: documentedSchema(
v2RelocateFileFolderContract.response.schema,
'FileFolderResponse',
'File folder response',
'A single workspace file folder.'
),
}
),
defineOpenApiRoute(
v2DeleteFileFolderContract,
filesOperation({
operationId: 'deleteFilesFolder',
summary: 'Delete Folder',
description: 'Delete a folder, optionally including every nested file and folder.',
errors: [...WORKSPACE_ERRORS, 'NotFound', 'Conflict'],
success: { description: 'Folder deletion confirmation and deleted item counts.' },
}),
{
query: documentedSchema(
v2DeleteFileFolderContract.query,
'DeleteFileFolderQuery',
'Delete file folder query',
'Workspace, folder path, and recursive deletion option.'
),
response: documentedSchema(
v2DeleteFileFolderContract.response.schema,
'DeleteFileFolderResponse',
'Delete file folder response',
'Folder deletion confirmation and deleted item counts.'
),
}
),
] as const
export const filesAuditOpenApiDocument = defineOpenApiDocument({
output: 'apps/docs/openapi-v2-files-audit.json',
info: {
title: 'Sim API v2 — Files & Audit Logs',
description:
'Version 2 of the Sim REST API for workspace files and organization audit logs. Every endpoint uses the canonical v2 data, cursor-list, and error envelopes. Lists use opaque cursors, and rate-limit state is returned in response headers.',
version: '2.0.0',
contact: {
name: 'Sim Support',
email: 'help@sim.ai',
url: 'https://www.sim.ai',
},
license: {
name: 'Apache 2.0',
url: 'https://www.apache.org/licenses/LICENSE-2.0.html',
},
},
servers: [{ url: 'https://www.sim.ai', description: 'Production' }],
tags: [
{
name: 'Files',
description: 'Create, upload, download, organize, share, and delete workspace files.',
},
{
name: 'Audit Logs',
description: 'Query the organization audit trail with Enterprise authorization.',
},
],
security: V2_API_KEY_SECURITY,
securitySchemes: V2_API_KEY_SECURITY_SCHEMES,
headers: {
'Content-Type': {
schema: z.string().meta({
id: 'ContentTypeHeader',
title: 'Content type',
description:
'MIME type of the file, defaulting to application/octet-stream when the stored type is unavailable.',
}),
},
'Content-Disposition': {
schema: z.string().meta({
id: 'ContentDispositionHeader',
title: 'Content disposition',
description: 'Attachment disposition containing sanitized and RFC 5987 encoded filenames.',
}),
},
'Content-Length': {
schema: z
.string()
.regex(/^(0|[1-9]\d*)$/)
.meta({
id: 'ContentLengthHeader',
title: 'Content length',
description: 'File size in bytes.',
}),
},
...V2_COMMON_HEADERS,
},
errorSchema: V2_ERROR_SCHEMA,
errorResponses: ERROR_RESPONSES,
routes,
})