Skip to content

feat: add App API Assets methods + multipart upload#241

Merged
mike-engel merged 3 commits into
cdp-6273from
cdp-6274
Jul 14, 2026
Merged

feat: add App API Assets methods + multipart upload#241
mike-engel merged 3 commits into
cdp-6273from
cdp-6274

Conversation

@mike-engel

@mike-engel mike-engel commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Another set of the App API backfill on top of #240 which adds 10 methods plus a multipart/form-data upload path in the request layer.

Method Endpoint
listAssets GET /v1/assets
createAsset POST /v1/assets/files (multipart upload)
getAsset GET /v1/assets/files/{id}
updateAsset PUT /v1/assets/files/{id} (204)
deleteAsset DELETE /v1/assets/files/{id} (204)
listAssetFolders GET /v1/assets/folders
createAssetFolder POST /v1/assets/folders
getAssetFolder GET /v1/assets/folders/{id}
updateAssetFolder PUT /v1/assets/folders/{id} (204)
deleteAssetFolder DELETE /v1/assets/folders/{id} (200)

⚠️ The upload is multipart, not base64

The issue assumed the SendEmailRequest.attach base64 approach. Asset creation, however, is multipart/form-data; form field file plus optional name / parent_folder_id form values. The JSON mode that exists there only records metadata for an already-uploaded path; it never carries bytes. So base64-in-JSON would not work.

To support it, the transport gained a small, isolated multipart path:

  • CIORequest.postForm(uri, form) + formOptions(...) (lib/request.ts): builds the request with a FormData body and deliberately omits the JSON Content-Type so fetch sets multipart/form-data with the correct boundary; no Content-Length is computed. Retries/redirects reuse the same handler/execute path unchanged (RequestHandlerOptions.body widened to string | FormData | null).
  • createAsset builds FormData from a Blob (setting the blob's type when contentType is given, else letting the API derive it from the filename).

Assisted by AI 🤖


Note

Medium Risk
Touches the shared HTTP client (RequestHandlerOptions, execute) for FormData, but the multipart path is isolated; main risk is upload MIME handling and regressions on JSON requests.

Overview
Adds Assets coverage to APIClient: list/upload/get/update/delete files and the same CRUD for asset folders (integer ids, page-based listing with optional folder filters).

createAsset posts multipart/form-data via a new postForm / formOptions path on the shared request layer. Request bodies can be FormData; JSON Content-Type and Content-Length are omitted so fetch sets the multipart boundary. The SDK derives MIME types from filename (or explicit contentType / Blob type) so uploads are not sent as application/octet-stream.

Public types (AssetListOptions, CreateAssetInput, etc.), docs/app.md reference, unit tests, request-layer tests, and live integration round-trips are included.

Reviewed by Cursor Bugbot for commit 0941010. Bugbot is set up for automated code reviews on this repo. Configure here.

Batch 10 (stacked on Batch 9). Adds the 10 asset file/folder endpoints to
APIClient, plus a multipart/form-data upload path in the request layer.

Verified against the services backend (ext_api/assets/*), not the OpenAPI
spec. Notable backend truths the issue's base64 assumption missed:
- POST /v1/assets/files is multipart/form-data (form field 'file' + optional
  name/parent_folder_id), NOT base64 JSON. Added CIORequest.postForm +
  formOptions, which omit the JSON Content-Type so fetch sets the multipart
  boundary. createAsset builds a FormData from a Blob.
- Asset/folder ids are integers; parent_folder_id on update is tri-state.
- File DELETE returns 204; folder DELETE returns 200 (null body).
- Uploads: images + PDF, <=2MB, images <=4096px/side.

Includes unit tests (100% coverage, incl. the new transport path), live
round-trip coverage with a real 1x1 PNG upload, and docs.
Comment thread lib/request.ts
@mike-engel mike-engel changed the title feat: add App API Assets methods + multipart upload (CDP-6274) feat: add App API Assets methods + multipart upload Jul 14, 2026
@mike-engel mike-engel self-assigned this Jul 14, 2026
Narrow the file-upload data field from `any` to
`Uint8Array | ArrayBuffer | Blob | string` — the set `new Blob([...])`
actually accepts (a Node `Buffer` is a `Uint8Array`). Avoids the DOM-only
`BlobPart` alias, which isn't in this project's lib.
Comment thread lib/api.ts Outdated
Comment thread test/api.ts Outdated
Comment thread docs/app.md Outdated
mike-engel added a commit that referenced this pull request Jul 14, 2026
…in formOptions (CDP-6274)

Addresses PR #241 review:
- createAsset without an explicit contentType would always 400: an untyped
  Blob part is serialized as application/octet-stream, which the Assets API
  rejects, and its filename fallback (mime.TypeByExtension) only runs when the
  part carries no Content-Type. Derive the MIME type from the filename
  extension client-side (bmp/jpg/jpeg/png/gif/pdf) so the part is correctly
  typed. Verified against ext_api/assets/create_asset.go + domains/assets.
- formOptions now strips any Content-Type coming from defaults.headers, so a
  stray custom Content-Type can't break the multipart boundary.
- Docs + tests updated; live round-trip now omits contentType to exercise the
  derivation end-to-end.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 5b26bc7. Configure here.

Comment thread lib/api.ts
Comment thread lib/api.ts
…in formOptions (CDP-6274)

Addresses PR #241 review:
- createAsset without an explicit contentType would always 400: an untyped
  Blob part is serialized as application/octet-stream, which the Assets API
  rejects, and its filename fallback (mime.TypeByExtension) only runs when the
  part carries no Content-Type. Derive the MIME type from the filename
  extension client-side (bmp/jpg/jpeg/png/gif/pdf) so the part is correctly
  typed. Verified against ext_api/assets/create_asset.go + domains/assets.
- formOptions now strips any Content-Type coming from defaults.headers, so a
  stray custom Content-Type can't break the multipart boundary.
- Docs + tests updated; live round-trip now omits contentType to exercise the
  derivation end-to-end.
@mike-engel
mike-engel merged commit a703381 into cdp-6273 Jul 14, 2026
11 checks passed
@mike-engel
mike-engel deleted the cdp-6274 branch July 14, 2026 11:30
@mike-engel mike-engel mentioned this pull request Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants