@aphexcms/cms-core 9.9.0 → 10.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (324) hide show
  1. package/dist/api/assets.d.ts +62 -7
  2. package/dist/api/assets.d.ts.map +1 -1
  3. package/dist/api/assets.js +116 -9
  4. package/dist/api/client.d.ts +1 -1
  5. package/dist/api/client.d.ts.map +1 -1
  6. package/dist/api/client.js +39 -9
  7. package/dist/api/limits.d.ts +55 -0
  8. package/dist/api/limits.d.ts.map +1 -0
  9. package/dist/api/limits.js +58 -0
  10. package/dist/api/schemas/assets.d.ts +94 -4
  11. package/dist/api/schemas/assets.d.ts.map +1 -1
  12. package/dist/api/schemas/assets.js +82 -5
  13. package/dist/api/schemas/documents.d.ts +1 -0
  14. package/dist/api/schemas/documents.d.ts.map +1 -1
  15. package/dist/api/schemas/documents.js +1 -0
  16. package/dist/api/types.d.ts +25 -0
  17. package/dist/api/types.d.ts.map +1 -1
  18. package/dist/api/upload-timeout.d.ts +17 -0
  19. package/dist/api/upload-timeout.d.ts.map +1 -0
  20. package/dist/api/upload-timeout.js +35 -0
  21. package/dist/api/upload.d.ts +42 -0
  22. package/dist/api/upload.d.ts.map +1 -0
  23. package/dist/api/upload.js +144 -0
  24. package/dist/components/AdminApp.svelte +213 -32
  25. package/dist/components/AdminApp.svelte.d.ts.map +1 -1
  26. package/dist/components/admin/AssetBrowserModal.svelte +4 -3
  27. package/dist/components/admin/AssetBrowserModal.svelte.d.ts +2 -1
  28. package/dist/components/admin/AssetBrowserModal.svelte.d.ts.map +1 -1
  29. package/dist/components/admin/MediaBrowser.svelte +1859 -281
  30. package/dist/components/admin/MediaBrowser.svelte.d.ts +21 -1
  31. package/dist/components/admin/MediaBrowser.svelte.d.ts.map +1 -1
  32. package/dist/components/admin/fields/ArrayField.svelte +21 -10
  33. package/dist/components/admin/fields/ArrayField.svelte.d.ts.map +1 -1
  34. package/dist/components/admin/fields/FileField.svelte +9 -2
  35. package/dist/components/admin/fields/FileField.svelte.d.ts.map +1 -1
  36. package/dist/components/admin/fields/ImageField.svelte +47 -12
  37. package/dist/components/admin/fields/ImageField.svelte.d.ts.map +1 -1
  38. package/dist/config.d.ts.map +1 -1
  39. package/dist/config.js +14 -0
  40. package/dist/db/interfaces/asset.d.ts +114 -5
  41. package/dist/db/interfaces/asset.d.ts.map +1 -1
  42. package/dist/db/interfaces/document.d.ts +107 -3
  43. package/dist/db/interfaces/document.d.ts.map +1 -1
  44. package/dist/hooks.d.ts.map +1 -1
  45. package/dist/hooks.js +2 -1
  46. package/dist/image/Image.svelte +72 -0
  47. package/dist/image/Image.svelte.d.ts +40 -0
  48. package/dist/image/Image.svelte.d.ts.map +1 -0
  49. package/dist/image/index.d.ts +3 -0
  50. package/dist/image/index.d.ts.map +1 -0
  51. package/dist/image/index.js +11 -0
  52. package/dist/image/types.d.ts +28 -0
  53. package/dist/image/types.d.ts.map +1 -0
  54. package/dist/image/types.js +1 -0
  55. package/dist/images/generate.d.ts +55 -0
  56. package/dist/images/generate.d.ts.map +1 -0
  57. package/dist/images/generate.js +243 -0
  58. package/dist/images/index.d.ts +2 -0
  59. package/dist/images/index.d.ts.map +1 -0
  60. package/dist/images/index.js +7 -0
  61. package/dist/images/variants.d.ts +82 -0
  62. package/dist/images/variants.d.ts.map +1 -0
  63. package/dist/images/variants.js +124 -0
  64. package/dist/jobs/asset-reference-jobs.d.ts +49 -0
  65. package/dist/jobs/asset-reference-jobs.d.ts.map +1 -0
  66. package/dist/jobs/asset-reference-jobs.js +74 -0
  67. package/dist/jobs/run-batch.d.ts.map +1 -1
  68. package/dist/jobs/run-batch.js +5 -0
  69. package/dist/lib/api/assets.d.ts +62 -7
  70. package/dist/lib/api/assets.d.ts.map +1 -1
  71. package/dist/lib/api/assets.js +116 -9
  72. package/dist/lib/api/assets.js.map +1 -1
  73. package/dist/lib/api/client.d.ts +1 -1
  74. package/dist/lib/api/client.d.ts.map +1 -1
  75. package/dist/lib/api/client.js +39 -9
  76. package/dist/lib/api/client.js.map +1 -1
  77. package/dist/lib/api/limits.d.ts +55 -0
  78. package/dist/lib/api/limits.d.ts.map +1 -0
  79. package/dist/lib/api/limits.js +59 -0
  80. package/dist/lib/api/limits.js.map +1 -0
  81. package/dist/lib/api/schemas/assets.d.ts +94 -4
  82. package/dist/lib/api/schemas/assets.d.ts.map +1 -1
  83. package/dist/lib/api/schemas/assets.js +82 -5
  84. package/dist/lib/api/schemas/assets.js.map +1 -1
  85. package/dist/lib/api/schemas/documents.d.ts +1 -0
  86. package/dist/lib/api/schemas/documents.d.ts.map +1 -1
  87. package/dist/lib/api/schemas/documents.js +1 -0
  88. package/dist/lib/api/schemas/documents.js.map +1 -1
  89. package/dist/lib/api/types.d.ts +25 -0
  90. package/dist/lib/api/types.d.ts.map +1 -1
  91. package/dist/lib/api/upload-timeout.d.ts +17 -0
  92. package/dist/lib/api/upload-timeout.d.ts.map +1 -0
  93. package/dist/lib/api/upload-timeout.js +36 -0
  94. package/dist/lib/api/upload-timeout.js.map +1 -0
  95. package/dist/lib/api/upload.d.ts +42 -0
  96. package/dist/lib/api/upload.d.ts.map +1 -0
  97. package/dist/lib/api/upload.js +145 -0
  98. package/dist/lib/api/upload.js.map +1 -0
  99. package/dist/lib/config.d.ts.map +1 -1
  100. package/dist/lib/config.js +14 -0
  101. package/dist/lib/config.js.map +1 -1
  102. package/dist/lib/db/interfaces/asset.d.ts +114 -5
  103. package/dist/lib/db/interfaces/asset.d.ts.map +1 -1
  104. package/dist/lib/db/interfaces/document.d.ts +107 -3
  105. package/dist/lib/db/interfaces/document.d.ts.map +1 -1
  106. package/dist/lib/hooks.d.ts.map +1 -1
  107. package/dist/lib/hooks.js +2 -1
  108. package/dist/lib/hooks.js.map +1 -1
  109. package/dist/lib/image/index.d.ts +3 -0
  110. package/dist/lib/image/index.d.ts.map +1 -0
  111. package/dist/lib/image/index.js +12 -0
  112. package/dist/lib/image/index.js.map +1 -0
  113. package/dist/lib/image/types.d.ts +28 -0
  114. package/dist/lib/image/types.d.ts.map +1 -0
  115. package/dist/lib/image/types.js +2 -0
  116. package/dist/lib/image/types.js.map +1 -0
  117. package/dist/lib/images/generate.d.ts +55 -0
  118. package/dist/lib/images/generate.d.ts.map +1 -0
  119. package/dist/lib/images/generate.js +244 -0
  120. package/dist/lib/images/generate.js.map +1 -0
  121. package/dist/lib/images/index.d.ts +2 -0
  122. package/dist/lib/images/index.d.ts.map +1 -0
  123. package/dist/lib/images/index.js +8 -0
  124. package/dist/lib/images/index.js.map +1 -0
  125. package/dist/lib/images/variants.d.ts +82 -0
  126. package/dist/lib/images/variants.d.ts.map +1 -0
  127. package/dist/lib/images/variants.js +125 -0
  128. package/dist/lib/images/variants.js.map +1 -0
  129. package/dist/lib/jobs/asset-reference-jobs.d.ts +49 -0
  130. package/dist/lib/jobs/asset-reference-jobs.d.ts.map +1 -0
  131. package/dist/lib/jobs/asset-reference-jobs.js +75 -0
  132. package/dist/lib/jobs/asset-reference-jobs.js.map +1 -0
  133. package/dist/lib/jobs/run-batch.d.ts.map +1 -1
  134. package/dist/lib/jobs/run-batch.js +5 -0
  135. package/dist/lib/jobs/run-batch.js.map +1 -1
  136. package/dist/lib/local-api/collection-api.d.ts +25 -2
  137. package/dist/lib/local-api/collection-api.d.ts.map +1 -1
  138. package/dist/lib/local-api/collection-api.js +107 -20
  139. package/dist/lib/local-api/collection-api.js.map +1 -1
  140. package/dist/lib/preview/assets.d.ts +19 -0
  141. package/dist/lib/preview/assets.d.ts.map +1 -1
  142. package/dist/lib/preview/assets.js +6 -0
  143. package/dist/lib/preview/assets.js.map +1 -1
  144. package/dist/lib/routes/assets-cdn.d.ts +19 -0
  145. package/dist/lib/routes/assets-cdn.d.ts.map +1 -1
  146. package/dist/lib/routes/assets-cdn.js +295 -17
  147. package/dist/lib/routes/assets-cdn.js.map +1 -1
  148. package/dist/lib/schema-utils/utils.d.ts +31 -1
  149. package/dist/lib/schema-utils/utils.d.ts.map +1 -1
  150. package/dist/lib/schema-utils/utils.js +68 -0
  151. package/dist/lib/schema-utils/utils.js.map +1 -1
  152. package/dist/lib/server/api/index.d.ts.map +1 -1
  153. package/dist/lib/server/api/index.js +87 -8
  154. package/dist/lib/server/api/index.js.map +1 -1
  155. package/dist/lib/server/api/routes/assets-bulk.d.ts.map +1 -1
  156. package/dist/lib/server/api/routes/assets-bulk.js +36 -7
  157. package/dist/lib/server/api/routes/assets-bulk.js.map +1 -1
  158. package/dist/lib/server/api/routes/assets-by-id.d.ts.map +1 -1
  159. package/dist/lib/server/api/routes/assets-by-id.js +32 -15
  160. package/dist/lib/server/api/routes/assets-by-id.js.map +1 -1
  161. package/dist/lib/server/api/routes/assets-direct-upload.d.ts +4 -0
  162. package/dist/lib/server/api/routes/assets-direct-upload.d.ts.map +1 -0
  163. package/dist/lib/server/api/routes/assets-direct-upload.js +164 -0
  164. package/dist/lib/server/api/routes/assets-direct-upload.js.map +1 -0
  165. package/dist/lib/server/api/routes/assets-poster.d.ts +4 -0
  166. package/dist/lib/server/api/routes/assets-poster.d.ts.map +1 -0
  167. package/dist/lib/server/api/routes/assets-poster.js +120 -0
  168. package/dist/lib/server/api/routes/assets-poster.js.map +1 -0
  169. package/dist/lib/server/api/routes/assets-references.d.ts.map +1 -1
  170. package/dist/lib/server/api/routes/assets-references.js +64 -5
  171. package/dist/lib/server/api/routes/assets-references.js.map +1 -1
  172. package/dist/lib/server/api/routes/assets.d.ts.map +1 -1
  173. package/dist/lib/server/api/routes/assets.js +116 -12
  174. package/dist/lib/server/api/routes/assets.js.map +1 -1
  175. package/dist/lib/server/api/routes/clear-asset-references.d.ts +18 -0
  176. package/dist/lib/server/api/routes/clear-asset-references.d.ts.map +1 -0
  177. package/dist/lib/server/api/routes/clear-asset-references.js +32 -0
  178. package/dist/lib/server/api/routes/clear-asset-references.js.map +1 -0
  179. package/dist/lib/server/api/routes/documents.d.ts.map +1 -1
  180. package/dist/lib/server/api/routes/documents.js +28 -1
  181. package/dist/lib/server/api/routes/documents.js.map +1 -1
  182. package/dist/lib/server/index.d.ts +2 -0
  183. package/dist/lib/server/index.d.ts.map +1 -1
  184. package/dist/lib/server/index.js +4 -0
  185. package/dist/lib/server/index.js.map +1 -1
  186. package/dist/lib/services/asset-references-service.d.ts +93 -0
  187. package/dist/lib/services/asset-references-service.d.ts.map +1 -0
  188. package/dist/lib/services/asset-references-service.js +198 -0
  189. package/dist/lib/services/asset-references-service.js.map +1 -0
  190. package/dist/lib/services/asset-service.d.ts +115 -14
  191. package/dist/lib/services/asset-service.d.ts.map +1 -1
  192. package/dist/lib/services/asset-service.js +312 -31
  193. package/dist/lib/services/asset-service.js.map +1 -1
  194. package/dist/lib/services/references-service.d.ts +19 -15
  195. package/dist/lib/services/references-service.d.ts.map +1 -1
  196. package/dist/lib/services/references-service.js +59 -31
  197. package/dist/lib/services/references-service.js.map +1 -1
  198. package/dist/lib/services/version-service.d.ts +10 -1
  199. package/dist/lib/services/version-service.d.ts.map +1 -1
  200. package/dist/lib/services/version-service.js +26 -4
  201. package/dist/lib/services/version-service.js.map +1 -1
  202. package/dist/lib/storage/adapters/local-storage-adapter.d.ts +38 -0
  203. package/dist/lib/storage/adapters/local-storage-adapter.d.ts.map +1 -1
  204. package/dist/lib/storage/adapters/local-storage-adapter.js +86 -19
  205. package/dist/lib/storage/adapters/local-storage-adapter.js.map +1 -1
  206. package/dist/lib/storage/index.d.ts +1 -0
  207. package/dist/lib/storage/index.d.ts.map +1 -1
  208. package/dist/lib/storage/index.js +2 -0
  209. package/dist/lib/storage/index.js.map +1 -1
  210. package/dist/lib/storage/interfaces/storage.d.ts +135 -5
  211. package/dist/lib/storage/interfaces/storage.d.ts.map +1 -1
  212. package/dist/lib/storage/keys.d.ts +96 -0
  213. package/dist/lib/storage/keys.d.ts.map +1 -0
  214. package/dist/lib/storage/keys.js +160 -0
  215. package/dist/lib/storage/keys.js.map +1 -0
  216. package/dist/lib/type-gen.d.ts.map +1 -1
  217. package/dist/lib/type-gen.js +11 -5
  218. package/dist/lib/type-gen.js.map +1 -1
  219. package/dist/lib/types/asset.d.ts +92 -12
  220. package/dist/lib/types/asset.d.ts.map +1 -1
  221. package/dist/lib/types/capabilities.d.ts +11 -0
  222. package/dist/lib/types/capabilities.d.ts.map +1 -1
  223. package/dist/lib/types/capabilities.js +20 -6
  224. package/dist/lib/types/capabilities.js.map +1 -1
  225. package/dist/lib/types/config.d.ts +127 -0
  226. package/dist/lib/types/config.d.ts.map +1 -1
  227. package/dist/lib/types/filters.d.ts +31 -0
  228. package/dist/lib/types/filters.d.ts.map +1 -1
  229. package/dist/lib/types/schemas.d.ts +14 -0
  230. package/dist/lib/types/schemas.d.ts.map +1 -1
  231. package/dist/lib/utils/asset-reference-walk.d.ts +44 -0
  232. package/dist/lib/utils/asset-reference-walk.d.ts.map +1 -0
  233. package/dist/lib/utils/asset-reference-walk.js +144 -0
  234. package/dist/lib/utils/asset-reference-walk.js.map +1 -0
  235. package/dist/lib/utils/image-url.d.ts +61 -26
  236. package/dist/lib/utils/image-url.d.ts.map +1 -1
  237. package/dist/lib/utils/image-url.js +143 -26
  238. package/dist/lib/utils/image-url.js.map +1 -1
  239. package/dist/lib/utils/video-metadata.d.ts +39 -0
  240. package/dist/lib/utils/video-metadata.d.ts.map +1 -0
  241. package/dist/lib/utils/video-metadata.js +161 -0
  242. package/dist/lib/utils/video-metadata.js.map +1 -0
  243. package/dist/local-api/collection-api.d.ts +25 -2
  244. package/dist/local-api/collection-api.d.ts.map +1 -1
  245. package/dist/local-api/collection-api.js +107 -20
  246. package/dist/preview/assets.d.ts +19 -0
  247. package/dist/preview/assets.d.ts.map +1 -1
  248. package/dist/preview/assets.js +6 -0
  249. package/dist/routes/assets-cdn.d.ts +19 -0
  250. package/dist/routes/assets-cdn.d.ts.map +1 -1
  251. package/dist/routes/assets-cdn.js +295 -17
  252. package/dist/schema-utils/utils.d.ts +31 -1
  253. package/dist/schema-utils/utils.d.ts.map +1 -1
  254. package/dist/schema-utils/utils.js +68 -0
  255. package/dist/server/api/index.d.ts.map +1 -1
  256. package/dist/server/api/index.js +87 -8
  257. package/dist/server/api/routes/assets-bulk.d.ts.map +1 -1
  258. package/dist/server/api/routes/assets-bulk.js +36 -7
  259. package/dist/server/api/routes/assets-by-id.d.ts.map +1 -1
  260. package/dist/server/api/routes/assets-by-id.js +32 -15
  261. package/dist/server/api/routes/assets-direct-upload.d.ts +4 -0
  262. package/dist/server/api/routes/assets-direct-upload.d.ts.map +1 -0
  263. package/dist/server/api/routes/assets-direct-upload.js +163 -0
  264. package/dist/server/api/routes/assets-poster.d.ts +4 -0
  265. package/dist/server/api/routes/assets-poster.d.ts.map +1 -0
  266. package/dist/server/api/routes/assets-poster.js +119 -0
  267. package/dist/server/api/routes/assets-references.d.ts.map +1 -1
  268. package/dist/server/api/routes/assets-references.js +64 -5
  269. package/dist/server/api/routes/assets.d.ts.map +1 -1
  270. package/dist/server/api/routes/assets.js +116 -12
  271. package/dist/server/api/routes/clear-asset-references.d.ts +18 -0
  272. package/dist/server/api/routes/clear-asset-references.d.ts.map +1 -0
  273. package/dist/server/api/routes/clear-asset-references.js +31 -0
  274. package/dist/server/api/routes/documents.d.ts.map +1 -1
  275. package/dist/server/api/routes/documents.js +28 -1
  276. package/dist/server/index.d.ts +2 -0
  277. package/dist/server/index.d.ts.map +1 -1
  278. package/dist/server/index.js +4 -0
  279. package/dist/services/asset-references-service.d.ts +93 -0
  280. package/dist/services/asset-references-service.d.ts.map +1 -0
  281. package/dist/services/asset-references-service.js +197 -0
  282. package/dist/services/asset-service.d.ts +115 -14
  283. package/dist/services/asset-service.d.ts.map +1 -1
  284. package/dist/services/asset-service.js +312 -31
  285. package/dist/services/references-service.d.ts +19 -15
  286. package/dist/services/references-service.d.ts.map +1 -1
  287. package/dist/services/references-service.js +59 -31
  288. package/dist/services/version-service.d.ts +10 -1
  289. package/dist/services/version-service.d.ts.map +1 -1
  290. package/dist/services/version-service.js +26 -4
  291. package/dist/storage/adapters/local-storage-adapter.d.ts +38 -0
  292. package/dist/storage/adapters/local-storage-adapter.d.ts.map +1 -1
  293. package/dist/storage/adapters/local-storage-adapter.js +86 -19
  294. package/dist/storage/index.d.ts +1 -0
  295. package/dist/storage/index.d.ts.map +1 -1
  296. package/dist/storage/index.js +2 -0
  297. package/dist/storage/interfaces/storage.d.ts +135 -5
  298. package/dist/storage/interfaces/storage.d.ts.map +1 -1
  299. package/dist/storage/keys.d.ts +96 -0
  300. package/dist/storage/keys.d.ts.map +1 -0
  301. package/dist/storage/keys.js +159 -0
  302. package/dist/type-gen.d.ts.map +1 -1
  303. package/dist/type-gen.js +11 -5
  304. package/dist/types/asset.d.ts +92 -12
  305. package/dist/types/asset.d.ts.map +1 -1
  306. package/dist/types/capabilities.d.ts +11 -0
  307. package/dist/types/capabilities.d.ts.map +1 -1
  308. package/dist/types/capabilities.js +20 -6
  309. package/dist/types/config.d.ts +127 -0
  310. package/dist/types/config.d.ts.map +1 -1
  311. package/dist/types/filters.d.ts +31 -0
  312. package/dist/types/filters.d.ts.map +1 -1
  313. package/dist/types/schemas.d.ts +14 -0
  314. package/dist/types/schemas.d.ts.map +1 -1
  315. package/dist/utils/asset-reference-walk.d.ts +44 -0
  316. package/dist/utils/asset-reference-walk.d.ts.map +1 -0
  317. package/dist/utils/asset-reference-walk.js +143 -0
  318. package/dist/utils/image-url.d.ts +61 -26
  319. package/dist/utils/image-url.d.ts.map +1 -1
  320. package/dist/utils/image-url.js +143 -26
  321. package/dist/utils/video-metadata.d.ts +39 -0
  322. package/dist/utils/video-metadata.d.ts.map +1 -0
  323. package/dist/utils/video-metadata.js +160 -0
  324. package/package.json +6 -1
@@ -1,37 +1,90 @@
1
+ import { type UploadOptions } from './upload.js';
1
2
  import type { ApiResponse } from './types.js';
2
3
  import type { Asset } from '../types/asset.js';
3
- import type { AssetReference, ListAssetsQuery, UpdateAssetRequest } from './schemas/assets.js';
4
+ import type { AssetDeleteConflict, BulkAssetDeleteConflict, AssetReference, ListAssetsQuery, UpdateAssetRequest } from './schemas/assets.js';
4
5
  export type AssetFilters = ListAssetsQuery;
5
6
  export type UpdateAssetData = UpdateAssetRequest;
6
- export type { AssetReference };
7
+ export type { AssetReference, AssetDeleteConflict, BulkAssetDeleteConflict };
7
8
  export declare class AssetsApi {
8
9
  /**
9
10
  * List assets with optional filters
10
11
  */
12
+ /**
13
+ * Attach a poster frame to an existing video.
14
+ *
15
+ * Separate from the upload because the frame's storage key derives from an
16
+ * asset id that doesn't exist until the row does: upload the video, learn the
17
+ * id, then send the frame here.
18
+ */
19
+ static uploadPoster(assetId: string, poster: Blob | undefined, info?: {
20
+ duration?: number;
21
+ width?: number;
22
+ height?: number;
23
+ }): Promise<ApiResponse<unknown>>;
11
24
  static list(filters?: ListAssetsQuery): Promise<ApiResponse<Asset[]>>;
12
25
  /**
13
26
  * Get asset by ID
14
27
  */
15
28
  static getById(id: string): Promise<ApiResponse<Asset>>;
29
+ /**
30
+ * Upload a file, choosing the transport.
31
+ *
32
+ * Direct-to-storage when the server reports it available, otherwise through
33
+ * the app. The choice is the server's to report, not the client's to guess:
34
+ * it depends on whether the adapter can sign, whether an encryption key is
35
+ * configured, and whether the operator opted in — the last of which implies
36
+ * bucket CORS that nothing here can detect.
37
+ */
38
+ static uploadFile(file: File, opts?: {
39
+ direct?: boolean;
40
+ schemaType?: string;
41
+ fieldPath?: string;
42
+ /** Read from the file in the browser; absent for non-video or an undecodable codec. */
43
+ videoDuration?: number;
44
+ videoWidth?: number;
45
+ videoHeight?: number;
46
+ } & UploadOptions): Promise<ApiResponse<Asset>>;
47
+ /**
48
+ * Three-step direct upload: get a signed URL, PUT to storage, confirm.
49
+ *
50
+ * Progress covers only the PUT — it is the whole transfer, and reporting the
51
+ * two bookkeeping calls would just make the bar jump.
52
+ */
53
+ private static uploadDirect;
16
54
  /**
17
55
  * Upload a new asset (multipart/form-data)
18
56
  * Note: Use FormData for file uploads
19
57
  */
20
- static upload(formData: FormData): Promise<ApiResponse<Asset>>;
58
+ static upload(formData: FormData, options?: UploadOptions): Promise<ApiResponse<Asset>>;
21
59
  /**
22
60
  * Update asset metadata
23
61
  */
24
62
  static update(id: string, data: UpdateAssetRequest): Promise<ApiResponse<Asset>>;
25
63
  /**
26
- * Delete an asset
64
+ * Delete an asset.
65
+ *
66
+ * Throws `ApiError` with status 409 and an {@link AssetDeleteConflict} body when
67
+ * the asset is still referenced. Pass `{ force: true }` to delete anyway —
68
+ * necessary when the reference is held by a document whose schema type is no
69
+ * longer registered, since that document can't be opened to remove it by hand.
27
70
  */
28
- static delete(id: string): Promise<ApiResponse<{
71
+ static delete(id: string, options?: {
72
+ force?: boolean;
73
+ }): Promise<ApiResponse<{
29
74
  success: boolean;
30
75
  }>>;
31
76
  /**
32
- * Bulk delete assets
77
+ * Bulk delete assets.
78
+ *
79
+ * Rejects with a 409 carrying {@link BulkAssetDeleteConflict} when any of them
80
+ * is still referenced. `{ force: true }` deletes anyway — the same escape the
81
+ * single-asset delete has, and for the same reason: a reference held by a
82
+ * document whose schema type is no longer registered cannot be removed by
83
+ * hand, so without it those assets are undeletable.
33
84
  */
34
- static deleteBulk(ids: string[]): Promise<ApiResponse<{
85
+ static deleteBulk(ids: string[], options?: {
86
+ force?: boolean;
87
+ }): Promise<ApiResponse<{
35
88
  deleted: number;
36
89
  failed: number;
37
90
  }>>;
@@ -49,8 +102,10 @@ export declare class AssetsApi {
49
102
  }
50
103
  export declare const assets: {
51
104
  list: typeof AssetsApi.list;
105
+ uploadPoster: typeof AssetsApi.uploadPoster;
52
106
  getById: typeof AssetsApi.getById;
53
107
  upload: typeof AssetsApi.upload;
108
+ uploadFile: typeof AssetsApi.uploadFile;
54
109
  update: typeof AssetsApi.update;
55
110
  delete: typeof AssetsApi.delete;
56
111
  deleteBulk: typeof AssetsApi.deleteBulk;
@@ -1 +1 @@
1
- {"version":3,"file":"assets.d.ts","sourceRoot":"","sources":["../../src/lib/api/assets.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,C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O,CAAC,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CAG5F;AAGD,eAAO,MAAM,MAAM;;;;;;;;;;;CAWlB,CAAC"}
@@ -1,9 +1,34 @@
1
1
  // Assets API client - manage uploaded files and images
2
- import { apiClient } from './client.js';
2
+ import { apiClient, ApiError } from './client.js';
3
+ import { putToStorage, uploadFormData } from './upload.js';
4
+ import { uploadTimeoutFor, uploadTimeoutForBytes } from './upload-timeout.js';
3
5
  export class AssetsApi {
4
6
  /**
5
7
  * List assets with optional filters
6
8
  */
9
+ /**
10
+ * Attach a poster frame to an existing video.
11
+ *
12
+ * Separate from the upload because the frame's storage key derives from an
13
+ * asset id that doesn't exist until the row does: upload the video, learn the
14
+ * id, then send the frame here.
15
+ */
16
+ static async uploadPoster(assetId,
17
+ // Optional: audio has a duration worth storing and no frame to store.
18
+ poster, info = {}) {
19
+ const body = new FormData();
20
+ if (poster)
21
+ body.append('poster', new File([poster], 'poster.webp', { type: 'image/webp' }));
22
+ // Sent with the frame because the browser reads them from the same
23
+ // `loadedmetadata`; decoding a second time to fetch them would be waste.
24
+ if (info.duration != null)
25
+ body.append('duration', String(info.duration));
26
+ if (info.width != null)
27
+ body.append('width', String(info.width));
28
+ if (info.height != null)
29
+ body.append('height', String(info.height));
30
+ return apiClient.post(`/assets/${assetId}/poster`, body);
31
+ }
7
32
  static async list(filters) {
8
33
  return apiClient.get('/assets', filters);
9
34
  }
@@ -13,12 +38,79 @@ export class AssetsApi {
13
38
  static async getById(id) {
14
39
  return apiClient.get(`/assets/${id}`);
15
40
  }
41
+ /**
42
+ * Upload a file, choosing the transport.
43
+ *
44
+ * Direct-to-storage when the server reports it available, otherwise through
45
+ * the app. The choice is the server's to report, not the client's to guess:
46
+ * it depends on whether the adapter can sign, whether an encryption key is
47
+ * configured, and whether the operator opted in — the last of which implies
48
+ * bucket CORS that nothing here can detect.
49
+ */
50
+ static async uploadFile(file, opts = {}) {
51
+ const { direct, schemaType, fieldPath, videoDuration, videoWidth, videoHeight, ...uploadOptions } = opts;
52
+ if (direct) {
53
+ try {
54
+ return await AssetsApi.uploadDirect(file, { schemaType, fieldPath }, uploadOptions);
55
+ }
56
+ catch (err) {
57
+ // Only a missing endpoint justifies retrying the other way. A CORS
58
+ // failure or a rejected signature must surface: silently proxying a
59
+ // file the platform will refuse turns a fixable misconfiguration
60
+ // into a confusing size error.
61
+ if (!(err instanceof ApiError) || err.status !== 404)
62
+ throw err;
63
+ }
64
+ }
65
+ const formData = new FormData();
66
+ formData.append('file', file);
67
+ if (schemaType)
68
+ formData.append('schemaType', schemaType);
69
+ if (fieldPath)
70
+ formData.append('fieldPath', fieldPath);
71
+ // Browser-read video facts. Claims, not proof — the server clamps them, since
72
+ // nothing stops a caller posting a duration of a billion seconds.
73
+ if (videoDuration != null)
74
+ formData.append('videoDuration', String(videoDuration));
75
+ if (videoWidth != null)
76
+ formData.append('videoWidth', String(videoWidth));
77
+ if (videoHeight != null)
78
+ formData.append('videoHeight', String(videoHeight));
79
+ return AssetsApi.upload(formData, uploadOptions);
80
+ }
81
+ /**
82
+ * Three-step direct upload: get a signed URL, PUT to storage, confirm.
83
+ *
84
+ * Progress covers only the PUT — it is the whole transfer, and reporting the
85
+ * two bookkeeping calls would just make the bar jump.
86
+ */
87
+ static async uploadDirect(file, meta, options) {
88
+ const grant = (await apiClient.post('/assets/upload-url', {
89
+ filename: file.name,
90
+ mimeType: file.type || 'application/octet-stream',
91
+ size: file.size,
92
+ ...meta
93
+ })).data;
94
+ if (!grant)
95
+ throw new ApiError(500, null, 'Malformed upload grant');
96
+ await putToStorage(grant.uploadUrl, file, grant.headers, {
97
+ ...options,
98
+ timeoutMs: options.timeoutMs ?? uploadTimeoutForBytes(file.size)
99
+ });
100
+ return apiClient.post('/assets/confirm', { assetId: grant.assetId }, { 'x-upload-ticket': grant.ticket });
101
+ }
16
102
  /**
17
103
  * Upload a new asset (multipart/form-data)
18
104
  * Note: Use FormData for file uploads
19
105
  */
20
- static async upload(formData) {
21
- return apiClient.post('/assets', formData);
106
+ static async upload(formData, options) {
107
+ return uploadFormData('/api/assets', formData, {
108
+ ...options,
109
+ // Derived from the payload rather than configured: a fixed deadline
110
+ // either aborts large uploads that were succeeding or waits far too
111
+ // long on small ones that have genuinely died.
112
+ timeoutMs: options?.timeoutMs ?? uploadTimeoutFor(formData)
113
+ });
22
114
  }
23
115
  /**
24
116
  * Update asset metadata
@@ -27,16 +119,29 @@ export class AssetsApi {
27
119
  return apiClient.patch(`/assets/${id}`, data);
28
120
  }
29
121
  /**
30
- * Delete an asset
122
+ * Delete an asset.
123
+ *
124
+ * Throws `ApiError` with status 409 and an {@link AssetDeleteConflict} body when
125
+ * the asset is still referenced. Pass `{ force: true }` to delete anyway —
126
+ * necessary when the reference is held by a document whose schema type is no
127
+ * longer registered, since that document can't be opened to remove it by hand.
31
128
  */
32
- static async delete(id) {
33
- return apiClient.delete(`/assets/${id}`);
129
+ static async delete(id, options) {
130
+ const query = options?.force ? '?force=true' : '';
131
+ return apiClient.delete(`/assets/${id}${query}`);
34
132
  }
35
133
  /**
36
- * Bulk delete assets
134
+ * Bulk delete assets.
135
+ *
136
+ * Rejects with a 409 carrying {@link BulkAssetDeleteConflict} when any of them
137
+ * is still referenced. `{ force: true }` deletes anyway — the same escape the
138
+ * single-asset delete has, and for the same reason: a reference held by a
139
+ * document whose schema type is no longer registered cannot be removed by
140
+ * hand, so without it those assets are undeletable.
37
141
  */
38
- static async deleteBulk(ids) {
39
- return apiClient.delete('/assets/bulk', { ids });
142
+ static async deleteBulk(ids, options) {
143
+ const query = options?.force ? '?force=true' : '';
144
+ return apiClient.delete(`/assets/bulk${query}`, { ids });
40
145
  }
41
146
  /**
42
147
  * Get documents that reference a specific asset
@@ -54,8 +159,10 @@ export class AssetsApi {
54
159
  // Export convenience functions for direct use
55
160
  export const assets = {
56
161
  list: AssetsApi.list.bind(AssetsApi),
162
+ uploadPoster: AssetsApi.uploadPoster.bind(AssetsApi),
57
163
  getById: AssetsApi.getById.bind(AssetsApi),
58
164
  upload: AssetsApi.upload.bind(AssetsApi),
165
+ uploadFile: AssetsApi.uploadFile.bind(AssetsApi),
59
166
  update: AssetsApi.update.bind(AssetsApi),
60
167
  delete: AssetsApi.delete.bind(AssetsApi),
61
168
  deleteBulk: AssetsApi.deleteBulk.bind(AssetsApi),
@@ -19,7 +19,7 @@ export declare class ApiClient {
19
19
  /**
20
20
  * POST request
21
21
  */
22
- post<T>(endpoint: string, body?: any): Promise<ApiResponse<T>>;
22
+ post<T>(endpoint: string, body?: any, headers?: Record<string, string>): Promise<ApiResponse<T>>;
23
23
  /**
24
24
  * PUT request
25
25
  */
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/lib/api/client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAM3C,qBAAa,QAAS,SAAQ,KAAK;IAE1B,MAAM,EAAE,MAAM;IACd,QAAQ,EAAE,GAAG;gBADb,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,GAAG,EACpB,OAAO,CAAC,EAAE,MAAM;CAKjB;AAED,qBAAa,SAAS;IACrB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,OAAO,CAAS;gBAEZ,OAAO,SAAmB,EAAE,OAAO,SAAkB;IAKjE;;OAEG;YACW,OAAO;IAoDrB;;OAEG;IACG,GAAG,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAwBrF;;OAEG;IACG,IAAI,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAQpE;;OAEG;IACG,GAAG,CAAC,CAAC,EAAE,QAAQ,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kB1B;;OAEG;IACG,GAAG,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAQnE;;OAEG;IACG,MAAM,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IAOtE;;OAEG;IACG,KAAK,CAAC,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;CAOrE;AAGD,eAAO,MAAM,SAAS,WAAkB,CAAC"}
@@ -1,6 +1,9 @@
1
1
  // Default configuration
2
2
  const DEFAULT_BASE_URL = '/api';
3
3
  const DEFAULT_TIMEOUT = 10000; // 10 seconds
4
+ // Uploads have their own transport (see ./upload), but a FormData body can
5
+ // still reach this client from elsewhere, and it needs the same deadline.
6
+ import { uploadTimeoutFor } from './upload-timeout.js';
4
7
  export class ApiError extends Error {
5
8
  status;
6
9
  response;
@@ -21,7 +24,7 @@ export class ApiClient {
21
24
  /**
22
25
  * Make HTTP request with proper error handling
23
26
  */
24
- async request(endpoint, options = {}) {
27
+ async request(endpoint, options = {}, timeoutMs) {
25
28
  const url = `${this.baseUrl}${endpoint}`;
26
29
  // Set up request with defaults
27
30
  // Don't set Content-Type for FormData (browser will set it with boundary)
@@ -29,24 +32,44 @@ export class ApiClient {
29
32
  if (!(options.body instanceof FormData)) {
30
33
  headers['Content-Type'] = 'application/json';
31
34
  }
35
+ // `options` spreads first so its own `headers` can't overwrite the merged
36
+ // object below. The other order silently dropped the JSON Content-Type
37
+ // for any caller that passed a header of its own.
32
38
  const requestOptions = {
39
+ ...options,
33
40
  headers: {
34
41
  ...headers,
35
42
  ...options.headers
36
- },
37
- ...options
43
+ }
38
44
  };
39
45
  // Add timeout
40
46
  const controller = new AbortController();
41
- const timeoutId = setTimeout(() => controller.abort(), this.timeout);
47
+ const timeoutId = setTimeout(() => controller.abort(), timeoutMs ?? this.timeout);
42
48
  requestOptions.signal = controller.signal;
43
49
  try {
44
50
  const response = await fetch(url, requestOptions);
45
51
  clearTimeout(timeoutId);
46
- const data = await response.json();
52
+ // Parse defensively. Not every error response is ours: a proxy, load
53
+ // balancer or serverless platform can reject a request before it
54
+ // reaches the app and answer with HTML or nothing at all. Parsing
55
+ // first threw a JSON syntax error that buried the real status, so a
56
+ // platform 413 surfaced to the user as "Unexpected token '<'" rather
57
+ // than as "too large".
58
+ let data = null;
59
+ try {
60
+ data = (await response.json());
61
+ }
62
+ catch {
63
+ if (response.ok) {
64
+ throw new ApiError(response.status, null, 'Malformed response from server');
65
+ }
66
+ }
47
67
  // Handle HTTP errors
48
68
  if (!response.ok) {
49
- throw new ApiError(response.status, data, data.message || data.error);
69
+ throw new ApiError(response.status, data, data?.message || data?.error || `Request failed (${response.status})`);
70
+ }
71
+ if (!data) {
72
+ throw new ApiError(response.status, null, 'Malformed response from server');
50
73
  }
51
74
  // Handle API-level errors
52
75
  if (!data.success) {
@@ -90,12 +113,19 @@ export class ApiClient {
90
113
  /**
91
114
  * POST request
92
115
  */
93
- async post(endpoint, body) {
116
+ async post(endpoint, body, headers) {
117
+ const isUpload = body instanceof FormData;
94
118
  return this.request(endpoint, {
95
119
  method: 'POST',
120
+ ...(headers ? { headers } : {}),
96
121
  // Don't stringify FormData - pass it directly
97
- body: body instanceof FormData ? body : body ? JSON.stringify(body) : undefined
98
- });
122
+ body: isUpload ? body : body ? JSON.stringify(body) : undefined
123
+ },
124
+ // The default timeout is sized for a JSON round trip and aborts a
125
+ // perfectly healthy upload: 10 seconds is not enough to push several
126
+ // megabytes over a phone connection, and the failure looks to the user
127
+ // like the server rejected the file rather than like a deadline.
128
+ isUpload ? uploadTimeoutFor(body) : undefined);
99
129
  }
100
130
  /**
101
131
  * PUT request
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Upload size limits, shared by the server that enforces them and the client
3
+ * that pre-checks against them.
4
+ *
5
+ * Deliberately its own tiny module rather than a constant in either place: the
6
+ * client check is only useful if it agrees with the server, and two copies of a
7
+ * number agree right up until someone changes one of them. Plain values, no
8
+ * imports, so both a Svelte component and the Hono app can take it without
9
+ * dragging anything else along.
10
+ */
11
+ /**
12
+ * Maximum accepted HTTP request body, in bytes.
13
+ *
14
+ * Enforced by the `bodyLimit` middleware on every `/api` route, which rejects
15
+ * with 413 before the body is buffered.
16
+ *
17
+ * Note this is a limit on the *request*, not on the file: a multipart upload
18
+ * also carries part headers and boundary markers, so the largest uploadable
19
+ * file is slightly smaller. See {@link MULTIPART_OVERHEAD_BYTES}.
20
+ */
21
+ export declare const MAX_UPLOAD_BYTES: number;
22
+ /**
23
+ * Headroom reserved for multipart framing when checking a file client-side.
24
+ *
25
+ * Without it a file of exactly {@link MAX_UPLOAD_BYTES} passes the client check
26
+ * and is then rejected by the server — the worst outcome, since the pre-check
27
+ * exists precisely so the user doesn't upload something doomed. Generous
28
+ * relative to real framing (a few hundred bytes) because being slightly
29
+ * conservative costs nothing and being slightly optimistic costs an upload.
30
+ */
31
+ export declare const MULTIPART_OVERHEAD_BYTES: number;
32
+ /** Largest file that can be expected to survive the request body limit. */
33
+ export declare const MAX_UPLOAD_FILE_BYTES: number;
34
+ /**
35
+ * The configured request body limit, or the default when unset.
36
+ *
37
+ * Takes the whole CMS instances bag rather than the number so every call site
38
+ * resolves it the same way — a route reading `config.upload.maxFileSize` itself
39
+ * is how the enforced limit and the reported limit drift apart.
40
+ *
41
+ * A non-positive or non-finite value is treated as unset: it would otherwise
42
+ * reject every request, including the ones that would tell an operator why.
43
+ */
44
+ export declare function resolveMaxUploadBytes(instances?: {
45
+ config?: {
46
+ upload?: {
47
+ maxFileSize?: number;
48
+ };
49
+ };
50
+ }): number;
51
+ /** Largest file expected to fit within `maxUploadBytes` once multipart framing is counted. */
52
+ export declare function maxUploadFileBytes(maxUploadBytes: number): number;
53
+ /** Render a byte count as whole megabytes for an error message. */
54
+ export declare function formatMegabytes(bytes: number): string;
55
+ //# sourceMappingURL=limits.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"limits.d.ts","sourceRoot":"","sources":["../../src/lib/api/limits.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;;;;;;;;GASG;AACH,eAAO,MAAM,gBAAgB,QAAmB,CAAC;AAEjD;;;;;;;;GAQG;AACH,eAAO,MAAM,wBAAwB,QAAY,CAAC;AAElD,2EAA2E;AAC3E,eAAO,MAAM,qBAAqB,QAA8C,CAAC;AAEjF;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,CAAC,EAAE;IACjD,MAAM,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE;YAAE,WAAW,CAAC,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE,CAAC;CAC/C,GAAG,MAAM,CAMT;AAED,8FAA8F;AAC9F,wBAAgB,kBAAkB,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM,CAEjE;AAED,mEAAmE;AACnE,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAErD"}
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Upload size limits, shared by the server that enforces them and the client
3
+ * that pre-checks against them.
4
+ *
5
+ * Deliberately its own tiny module rather than a constant in either place: the
6
+ * client check is only useful if it agrees with the server, and two copies of a
7
+ * number agree right up until someone changes one of them. Plain values, no
8
+ * imports, so both a Svelte component and the Hono app can take it without
9
+ * dragging anything else along.
10
+ */
11
+ /**
12
+ * Maximum accepted HTTP request body, in bytes.
13
+ *
14
+ * Enforced by the `bodyLimit` middleware on every `/api` route, which rejects
15
+ * with 413 before the body is buffered.
16
+ *
17
+ * Note this is a limit on the *request*, not on the file: a multipart upload
18
+ * also carries part headers and boundary markers, so the largest uploadable
19
+ * file is slightly smaller. See {@link MULTIPART_OVERHEAD_BYTES}.
20
+ */
21
+ export const MAX_UPLOAD_BYTES = 10 * 1024 * 1024;
22
+ /**
23
+ * Headroom reserved for multipart framing when checking a file client-side.
24
+ *
25
+ * Without it a file of exactly {@link MAX_UPLOAD_BYTES} passes the client check
26
+ * and is then rejected by the server — the worst outcome, since the pre-check
27
+ * exists precisely so the user doesn't upload something doomed. Generous
28
+ * relative to real framing (a few hundred bytes) because being slightly
29
+ * conservative costs nothing and being slightly optimistic costs an upload.
30
+ */
31
+ export const MULTIPART_OVERHEAD_BYTES = 64 * 1024;
32
+ /** Largest file that can be expected to survive the request body limit. */
33
+ export const MAX_UPLOAD_FILE_BYTES = MAX_UPLOAD_BYTES - MULTIPART_OVERHEAD_BYTES;
34
+ /**
35
+ * The configured request body limit, or the default when unset.
36
+ *
37
+ * Takes the whole CMS instances bag rather than the number so every call site
38
+ * resolves it the same way — a route reading `config.upload.maxFileSize` itself
39
+ * is how the enforced limit and the reported limit drift apart.
40
+ *
41
+ * A non-positive or non-finite value is treated as unset: it would otherwise
42
+ * reject every request, including the ones that would tell an operator why.
43
+ */
44
+ export function resolveMaxUploadBytes(instances) {
45
+ const configured = instances?.config?.upload?.maxFileSize;
46
+ if (typeof configured === 'number' && Number.isFinite(configured) && configured > 0) {
47
+ return configured;
48
+ }
49
+ return MAX_UPLOAD_BYTES;
50
+ }
51
+ /** Largest file expected to fit within `maxUploadBytes` once multipart framing is counted. */
52
+ export function maxUploadFileBytes(maxUploadBytes) {
53
+ return Math.max(0, maxUploadBytes - MULTIPART_OVERHEAD_BYTES);
54
+ }
55
+ /** Render a byte count as whole megabytes for an error message. */
56
+ export function formatMegabytes(bytes) {
57
+ return `${Math.floor(bytes / (1024 * 1024))}MB`;
58
+ }
@@ -26,6 +26,7 @@ export declare const assetReferenceSchema: z.ZodObject<{
26
26
  type: z.ZodString;
27
27
  title: z.ZodString;
28
28
  status: z.ZodNullable<z.ZodString>;
29
+ fieldPaths: z.ZodOptional<z.ZodArray<z.ZodString>>;
29
30
  }, z.core.$strip>;
30
31
  export declare const listAssetsQuery: z.ZodObject<{
31
32
  assetType: z.ZodOptional<z.ZodEnum<{
@@ -33,11 +34,28 @@ export declare const listAssetsQuery: z.ZodObject<{
33
34
  file: "file";
34
35
  }>>;
35
36
  mimeType: z.ZodOptional<z.ZodString>;
37
+ category: z.ZodOptional<z.ZodEnum<{
38
+ image: "image";
39
+ document: "document";
40
+ svg: "svg";
41
+ video: "video";
42
+ audio: "audio";
43
+ }>>;
36
44
  search: z.ZodOptional<z.ZodString>;
45
+ usage: z.ZodOptional<z.ZodEnum<{
46
+ "in-use": "in-use";
47
+ unused: "unused";
48
+ }>>;
37
49
  includeSystem: z.ZodOptional<z.ZodUnion<readonly [z.ZodBoolean, z.ZodPipe<z.ZodEnum<{
38
50
  true: "true";
39
51
  false: "false";
40
52
  }>, z.ZodTransform<boolean, "true" | "false">>]>>;
53
+ sort: z.ZodOptional<z.ZodEnum<{
54
+ newest: "newest";
55
+ oldest: "oldest";
56
+ "name-asc": "name-asc";
57
+ "name-desc": "name-desc";
58
+ }>>;
41
59
  limit: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
42
60
  offset: z.ZodOptional<z.ZodCoercedNumber<unknown>>;
43
61
  }, z.core.$strip>;
@@ -99,11 +117,20 @@ export declare const getAssetResponse: z.ZodObject<{
99
117
  updatedAt: z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodDate]>>;
100
118
  }, z.core.$loose>;
101
119
  }, z.core.$strip>;
120
+ /**
121
+ * Metadata patch. Every field is a tri-state: omitted leaves the column alone,
122
+ * `null` clears it, a string sets it.
123
+ *
124
+ * `.nullable()` is the load-bearing part. Without it an emptied input could only
125
+ * be sent as `undefined`, which `JSON.stringify` drops from the body entirely —
126
+ * so metadata could be added but never removed.
127
+ */
102
128
  export declare const updateAssetRequest: z.ZodObject<{
103
- title: z.ZodOptional<z.ZodString>;
104
- description: z.ZodOptional<z.ZodString>;
105
- alt: z.ZodOptional<z.ZodString>;
106
- creditLine: z.ZodOptional<z.ZodString>;
129
+ originalFilename: z.ZodOptional<z.ZodString>;
130
+ title: z.ZodOptional<z.ZodNullable<z.ZodString>>;
131
+ description: z.ZodOptional<z.ZodNullable<z.ZodString>>;
132
+ alt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
133
+ creditLine: z.ZodOptional<z.ZodNullable<z.ZodString>>;
107
134
  }, z.core.$strip>;
108
135
  export declare const updateAssetResponse: z.ZodObject<{
109
136
  success: z.ZodLiteral<true>;
@@ -133,6 +160,22 @@ export declare const updateAssetResponse: z.ZodObject<{
133
160
  export declare const deleteAssetResponse: z.ZodObject<{
134
161
  success: z.ZodLiteral<true>;
135
162
  }, z.core.$strip>;
163
+ /**
164
+ * Body of the 409 returned when an asset is still referenced. Hand-written
165
+ * rather than zod because it's a response shape (see the API-contracts note in
166
+ * CLAUDE.md), and it arrives on the client as `ApiError.response`.
167
+ *
168
+ * `unregisteredTypes` lists the schema types among `references` that are no
169
+ * longer registered in `schemaTypes`. Those documents cannot be opened in the
170
+ * admin, so the reference cannot be removed by hand — a non-empty array means
171
+ * force-delete is the user's only route.
172
+ */
173
+ export interface AssetDeleteConflict {
174
+ success: false;
175
+ error: string;
176
+ references: AssetReference[];
177
+ unregisteredTypes: string[];
178
+ }
136
179
  export declare const bulkDeleteAssetsRequest: z.ZodObject<{
137
180
  ids: z.ZodArray<z.ZodString>;
138
181
  }, z.core.$strip>;
@@ -143,6 +186,22 @@ export declare const bulkDeleteAssetsResponse: z.ZodObject<{
143
186
  failed: z.ZodNumber;
144
187
  }, z.core.$strip>;
145
188
  }, z.core.$strip>;
189
+ /**
190
+ * Body of the 409 from a bulk delete blocked by references — the batch sibling
191
+ * of {@link AssetDeleteConflict}.
192
+ *
193
+ * It reports ids rather than the references themselves: a batch of a hundred
194
+ * assets could carry thousands of referencing documents, and the caller's next
195
+ * move is to narrow the selection or force, not to read them all. Same
196
+ * `unregisteredTypes` meaning, and the same implication — non-empty means force
197
+ * is the only route, because those documents cannot be opened in the admin.
198
+ */
199
+ export interface BulkAssetDeleteConflict {
200
+ success: false;
201
+ error: string;
202
+ referencedIds: string[];
203
+ unregisteredTypes: string[];
204
+ }
146
205
  export declare const getAssetReferencesResponse: z.ZodObject<{
147
206
  success: z.ZodLiteral<true>;
148
207
  data: z.ZodObject<{
@@ -151,6 +210,7 @@ export declare const getAssetReferencesResponse: z.ZodObject<{
151
210
  type: z.ZodString;
152
211
  title: z.ZodString;
153
212
  status: z.ZodNullable<z.ZodString>;
213
+ fieldPaths: z.ZodOptional<z.ZodArray<z.ZodString>>;
154
214
  }, z.core.$strip>>;
155
215
  total: z.ZodNumber;
156
216
  }, z.core.$strip>;
@@ -162,6 +222,34 @@ export declare const assetReferenceCountsResponse: z.ZodObject<{
162
222
  success: z.ZodLiteral<true>;
163
223
  data: z.ZodRecord<z.ZodString, z.ZodNumber>;
164
224
  }, z.core.$strip>;
225
+ /**
226
+ * Ask for a URL the browser can upload directly to.
227
+ *
228
+ * Deliberately carries no key or path. The server mints the asset id and
229
+ * derives the destination from it, because a caller-supplied key would let
230
+ * anyone holding `asset.upload` write anywhere in the bucket — including over
231
+ * an existing asset's original.
232
+ */
233
+ export declare const createUploadUrlRequest: z.ZodObject<{
234
+ filename: z.ZodString;
235
+ mimeType: z.ZodString;
236
+ size: z.ZodNumber;
237
+ schemaType: z.ZodOptional<z.ZodString>;
238
+ fieldPath: z.ZodOptional<z.ZodString>;
239
+ }, z.core.$strip>;
240
+ /**
241
+ * Report that a direct upload finished, so the asset row can be created.
242
+ *
243
+ * Only the id is trusted. Everything describing the object — that it exists,
244
+ * how large it is — is read back from storage, never taken from the client.
245
+ */
246
+ export declare const confirmUploadRequest: z.ZodObject<{
247
+ assetId: z.ZodString;
248
+ title: z.ZodOptional<z.ZodString>;
249
+ description: z.ZodOptional<z.ZodString>;
250
+ alt: z.ZodOptional<z.ZodString>;
251
+ creditLine: z.ZodOptional<z.ZodString>;
252
+ }, z.core.$strip>;
165
253
  export type AssetDTO = z.infer<typeof assetSchema>;
166
254
  export type AssetReference = z.infer<typeof assetReferenceSchema>;
167
255
  export type ListAssetsQuery = z.input<typeof listAssetsQuery>;
@@ -175,4 +263,6 @@ export type BulkDeleteAssetsResponse = z.infer<typeof bulkDeleteAssetsResponse>;
175
263
  export type GetAssetReferencesResponse = z.infer<typeof getAssetReferencesResponse>;
176
264
  export type AssetReferenceCountsRequest = z.infer<typeof assetReferenceCountsRequest>;
177
265
  export type AssetReferenceCountsResponse = z.infer<typeof assetReferenceCountsResponse>;
266
+ export type CreateUploadUrlRequest = z.infer<typeof createUploadUrlRequest>;
267
+ export type ConfirmUploadRequest = z.infer<typeof confirmUploadRequest>;
178
268
  //# sourceMappingURL=assets.d.ts.map