Skip to content

Commit 5ab950d

Browse files
committed
Update MIGRATION.md
1 parent dc05485 commit 5ab950d

1 file changed

Lines changed: 29 additions & 61 deletions

File tree

MIGRATION.md

Lines changed: 29 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,27 @@
1-
# Migration Guide: SDK v3.x to v4.x
1+
# Migration Guide: v3 → v4
22

3-
This guide summarizes key changes and migration steps from SDK v3.x to v4.x, focusing on enhanced type safety, improved error handling, and Zod schema validation.
3+
v4 focuses on type-safety, clearer errors, and modern Node support. Most changes are mechanical.
44

5-
## Key Changes in v4.x
5+
## Breaking changes (quick scan)
66

7-
- Renamed `TransloaditClient` to `Transloadit`
8-
- Use named export for `Transloadit`, instead of default export.
9-
- Dropped support for Node.js < 20.
10-
- **Type Safety with Zod:** Assembly creation parameters and API responses are now validated using Zod schemas, providing accurate TypeScript types and IDE autocompletion. The main benefit for customers is less trips to the documentation as they are typing Assembly Instructions. Robot names and their available parameters are now all autocompleted.
11-
- **Improved Error Reporting:** Clearer client-side and API errors (`ApiError`, `InconsistentResponseError`) help quickly identify issues.
12-
- **Exported Schemas and Types:** Core schemas (`assemblyInstructionsSchema`, `assemblyStatusSchema`, etc.) and inferred types (`AssemblyInstructionsInput`, `AssemblyIndexItem`) are exported for reuse.
13-
- **Modernized Codebase:** Fully transitioned to TypeScript, removing manual `.d.ts` files.
7+
- `TransloaditClient` (default export) ➜ **`{ Transloadit }`** (named export)
8+
- Requires **Node >= 20**
9+
- `createAssembly` input validated by `assemblyInstructionsSchema`
10+
- `listAssemblies()` now returns `PaginationListWithCount<AssemblyIndexItem>` (was `ListedAssembly`)
11+
- New errors: `ApiError`, `InconsistentResponseError`, `PollingTimeoutError`
1412

15-
## Migration Steps
13+
## Upgrade in 4 steps
1614

17-
### 1. Assembly Creation (`createAssembly`)
15+
1. Update imports
1816

19-
- Parameters are strictly validated against `assemblyInstructionsSchema`.
20-
- Incorrect Robot names, parameters, or types now cause immediate client-side errors or detailed API errors.
21-
22-
**Migration Steps:**
23-
24-
- Review and update all `createAssembly` calls to match the schema.
25-
- Use exported types for better IDE support:
26-
27-
```typescript
28-
import { Transloadit, AssemblyInstructionsInput } from 'transloadit'
17+
```ts
18+
-import TransloaditClient from 'transloadit'
19+
+import { Transloadit, AssemblyInstructionsInput, AssemblyIndexItem } from 'transloadit'
20+
```
2921

30-
const transloadit = new Transloadit({ authKey: 'YOUR_KEY', authSecret: 'YOUR_SECRET' })
22+
2. Adapt assembly creation (now type-checked)
3123

24+
```ts
3225
const params: AssemblyInstructionsInput = {
3326
steps: {
3427
resize: {
@@ -40,51 +33,26 @@ const params: AssemblyInstructionsInput = {
4033
},
4134
}
4235

43-
const assembly = await transloadit.createAssembly(params)
36+
await transloadit.createAssembly(params)
4437
```
4538

46-
### 2. Assembly Status Methods (`getAssembly`, `cancelAssembly`, `awaitAssemblyCompletion`)
47-
48-
- Methods now return strictly typed `AssemblyStatus` objects.
49-
- Schema mismatches trigger an `InconsistentResponseError` (logged, not thrown yet).
50-
51-
### 3. Listing Assemblies (`listAssemblies`)
39+
3. Update list & status handling
5240

53-
- Returns `PaginationListWithCount<AssemblyIndexItem>` instead of `ListedAssembly`.
54-
- Items validated against `assemblyIndexItemSchema`.
55-
56-
**Migration Steps:**
57-
58-
- Update type annotations from `ListedAssembly` to `AssemblyIndexItem`.
59-
60-
```typescript
61-
const result = await transloadit.listAssemblies()
62-
result.items.forEach((item: AssemblyIndexItem) => {
63-
console.log(item.id, item.ok, item.created)
64-
})
41+
```ts
42+
const { items } = await transloadit.listAssemblies()
43+
items.forEach((a: AssemblyIndexItem) => console.log(a.id, a.created))
6544
```
6645

67-
### 4. General Changes
68-
69-
- New custom errors (`ApiError`, `InconsistentResponseError`, `PollingTimeoutError`).
70-
- Modernized build system and testing (`vitest`).
71-
- Make sure you are on Node.js 20 or higher.
72-
73-
## Benefits of Upgrading
74-
75-
- **Increased Reliability:** Early detection of errors through schema validation.
76-
- **Improved Developer Experience:** Accurate types and autocompletion reduce guesswork.
77-
- **Clearer Diagnostics:** Specific errors pinpoint exact issues.
46+
4. Run your code on **Node 20+**.
7847

79-
## Closing Thoughts
48+
## Why upgrade?
8049

81-
Transloadit is retrofitting types on an 15 year old codebase. The path we chose is to:
50+
- IDE autocomplete for every Robot & parameter, as well as the API response
51+
- Local schema validation catches mistakes before the request
52+
- Improved error objects simplify debugging
8253

83-
1. create schemas that model closely what the API currently outputs, and allows as inputs
84-
2. roll out the schemas in clients, and our test suite, even though they are not as narrow as we would like yet
85-
3. gradually narrow the schemas, our test suite will raise red flags, so we can adjust the API (unless it would break backwards compatibility)
86-
4. we rinse and repeat, until our API is as narrow as we like our schemas/types to be
54+
## Heads-up
8755

88-
We are currently at step 2, this means you'll find fairly wide types, but at least they do not lie, so that you should be able to build your integration on them without runtime type errors.
56+
Schemas are still bit wider than we would like as the first priority when retrofitting our API with schemas/types, was modeling its behavior exactly, or we'd risk the types being a lie, and hence runtime type errors.
8957

90-
Please Test your integration thoroughly after upgrading. For issues or unexpected behavior, consult the SDK documentation or raise an issue.
58+
We'll also outfit our API's testsuite with these schemas, and this will allow us to gradually, over time, narrow what our API can respond, along with the schemas.

0 commit comments

Comments
 (0)