Skip to content

Commit b57e430

Browse files
authored
Improve MIGRATION.md (#255)
* Improve MIGRATION.md * Revise CHANGELOG for v4.0.0 release
1 parent 7e965df commit b57e430

File tree

2 files changed

+57
-39
lines changed

2 files changed

+57
-39
lines changed

CHANGELOG.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ Released: 2025-09-18.
1717
[Diff](https://github.com/transloadit/node-sdk/compare/v3.0.2...v4.0.0).
1818

1919
- [x] **Breaking:** Package is now pure ESM, requires Node.js 20+, and exports `{ Transloadit }` instead of a default client.
20-
- [x] **Breaking:** Assembly inputs are validated against rich schemas; migrate to the new `AssemblyInstructionsInput` types and expect `listAssemblies()` to return `{ items, count }`.
21-
- [x] Added end-to-end TypeScript typings for robots, assemblies, templates, and responses, so assembly instructions now autocomplete every robot and its supported parameters.
22-
- [x] Introduced structured error classes (`ApiError`, `InconsistentResponseError`, `PollingTimeoutError`) that preserve assembly IDs and server metadata.
20+
- [x] **Breaking** `TransloaditError` removed in favor of a new, slightly different `ApiError`.
21+
- [x] Added end-to-end TypeScript typings for robots, assemblies, templates, and responses, so assembly instructions now autocomplete every robot and its supported parameters. Notably, Assembly instructions and statuses are validates against rich TypeScript types; migrate to the new `AssemblyInstructionsInput` types and `AssemblyStatus` in responses.
22+
- [x] New rich error stacktraces that aid in debugging issues.
2323
- [x] Added opt-in `validateResponses` safeguard and a `getSignedSmartCDNUrl` helper for generating signed Smart CDN URLs.
24+
- [x] Fix broken rate limiting #217
2425
- [x] Modernized tooling, tests, and examples (Vitest, Biome, TypeScript examples). See [MIGRATION.md](./MIGRATION.md) for a guided upgrade path.
2526

2627
## v3.0.2

MIGRATION.md

Lines changed: 53 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Version 4 focuses on type-safety, clearer errors, and modern Node support. Most
77
- [ ] Ensure your runtime is Node.js **20 or newer**.
88
- [ ] Switch from the v3 default export to the named `{ Transloadit }` ESM export.
99
- [ ] Adopt the new typed assembly instructions (`AssemblyInstructionsInput`) and update code that reads `listAssemblies()` results.
10-
- [ ] Adjust error handling to account for the new `ApiError`, `InconsistentResponseError`, and `PollingTimeoutError` classes.
10+
- [ ] Migrate from `TransloaditError` to `ApiError` signature.
1111
- [ ] (Optional) Opt into `validateResponses` or use `getSignedSmartCDNUrl` if you need the new safeguards and helpers.
1212

1313
## Before you begin
@@ -17,13 +17,13 @@ Version 4 focuses on type-safety, clearer errors, and modern Node support. Most
1717
- The SDK ships with `"type": "module"` and `.d.ts` typings. Pure CommonJS projects will need to either migrate to ESM or load the client via `import()` inside async code.
1818

1919
```js
20-
// CommonJS example
20+
// CommonJS import example
2121
async function getClient() {
22-
const { Transloadit } = await import('transloadit')
22+
const { Transloadit } = await import("transloadit");
2323
return new Transloadit({
24-
authKey: process.env.TRANSLOADIT_KEY ?? '',
25-
authSecret: process.env.TRANSLOADIT_SECRET ?? '',
26-
})
24+
authKey: process.env.TRANSLOADIT_KEY ?? "",
25+
authSecret: process.env.TRANSLOADIT_SECRET ?? "",
26+
});
2727
}
2828
```
2929
@@ -42,80 +42,97 @@ The package also exports `AssemblyInstructionsInput`, `AssemblyIndexItem`, `Asse
4242
4343
## 2. Adopt typed assembly instructions
4444
45-
`createAssembly` now validates its `params` using rich schemas. TypeScript users get autocomplete for every robot and parameter out of the box.
45+
`createAssembly` now validates its `params` using rich TypeScript types, and users get autocomplete for every robot and parameter out of the box.
4646
4747
```ts
4848
const params: AssemblyInstructionsInput = {
4949
steps: {
5050
resize: {
51-
use: ':original',
52-
robot: '/image/resize',
51+
use: ":original",
52+
robot: "/image/resize",
5353
width: 320,
5454
height: 240,
5555
result: true,
5656
},
5757
},
58-
}
58+
};
5959

60-
await transloadit.createAssembly({ params, waitForCompletion: true })
60+
await transloadit.createAssembly({ params, waitForCompletion: true });
6161
```
6262
63-
If validation fails, `createAssembly` throws an `ApiError` before making a network request, helping you catch mistakes locally.
64-
6563
## 3. Adjust API result handling
6664
67-
- `listAssemblies()` now returns a `PaginationListWithCount<AssemblyIndexItem>` instead of the legacy `ListedAssembly` array.
68-
69-
```ts
70-
const { items, count } = await transloadit.listAssemblies()
71-
items.forEach((assembly) => console.log(assembly.id, assembly.status))
72-
```
65+
`AssemblyStatus` objects are now fully typed. Update any custom helpers to use the exported types instead of hand-rolled interfaces.
7366
74-
- `AssemblyStatus` objects are now fully typed. Update any custom helpers to use the exported types instead of hand-rolled interfaces.
75-
- The pagination helpers (`PaginationStream`) are written in TypeScript and ship `.d.ts` files; imports work the same, but you can lean on the IDE for guidance now.
67+
```ts
68+
// `createdAssembly` is fully typed
69+
const createdAssembly = await transloadit.createAssembly(...);
70+
```
7671
7772
## 4. Update error handling
7873
79-
- `ApiError` wraps responses that contain an `error` payload even when the HTTP status code is 2xx. It carries `assemblyId`, `transloaditErrorCode`, and the raw `body`.
80-
- `InconsistentResponseError` is thrown if the Transloadit API omits critical fields (for example, missing assembly URLs).
81-
- `PollingTimeoutError` is thrown when waiting for an assembly to finish via `waitForCompletion` exceeds the timeout.
74+
`TransloaditError` has been renamed to `ApiError`. Key differences between `TransloaditError` and `ApiError`:
75+
76+
- This error is also thrown when `body.error` is set, even if status from server is 2xx.
77+
- `TransloaditError.response.body` can now be found in `ApiError.response`.
78+
- `TransloaditError.assemblyId` can now be found in `ApiError.response.assembly_id`.
79+
- `TransloaditError.transloaditErrorCode` can now be found in `ApiError.response.error`.
80+
- `ApiError` does not inherit from `got.HTTPError`, but `ApiError.cause` will be the `got.HTTPError` instance that caused this error, except for when Tranloadit API responds with HTTP 200 and `error` prop set in JSON response (in which case `cause` will be `undefined`).
81+
- Note that (just like before) when the Transloadit API responds with an error we will always throw an `ApiError` - In all other cases (like request timeout, connection error, TypeError etc.), we don't wrap the error in `ApiError`.
8282
8383
```ts
8484
try {
85-
await transloadit.createAssembly({ params })
85+
await transloadit.createAssembly({ params });
8686
} catch (error) {
87-
if (error instanceof ApiError && error.assemblyId) {
87+
if (error instanceof ApiError && error.response.assembly_id) {
8888
console.error(
89-
'Troubleshoot at https://transloadit.com/c/assemblies/' + error.assemblyId
90-
)
89+
"Troubleshoot at https://transloadit.com/c/assemblies/" +
90+
error.response.assembly_id
91+
);
9192
}
92-
throw error
93+
throw error;
9394
}
9495
```
9596
9697
## 5. Optional enhancements
9798
98-
- `validateResponses` (client option) replays schema validation against responses you receive. Enable it when integrating with new workflows to surface unexpected fields early:
99+
- `validateResponses` (client option) runs schema validation against responses you receive from Transloadit's servers. It will then throw additional `InconsistentResponseError` errors if responses are inconsistent with the schema. This will normally not happen, but enabling this will catch any bugs in Transloadit's API code where the response does not (yet) adhere with the schemas, instead of silently accepting the types as something else than what you expect (which is the case when the value is `false` - the default). We are of course working on making sure all our responses adhere to the schemas. In the future we want to make this option default to `true`.
99100
100101
```ts
101102
const transloadit = new Transloadit({
102103
authKey,
103104
authSecret,
104105
validateResponses: true,
105-
})
106+
});
106107
```
107108
108109
- `getSignedSmartCDNUrl` generates Smart CDN URLs with signatures that match the server-side implementation:
109110
110111
```ts
111112
const signedUrl = transloadit.getSignedSmartCDNUrl({
112-
workspace: 'my-team',
113-
template: 'hero-image',
114-
input: 'landing.jpg',
115-
urlParams: { format: 'webp' },
116-
})
113+
workspace: "my-team",
114+
template: "hero-image",
115+
input: "landing.jpg",
116+
urlParams: { format: "webp" },
117+
});
117118
```
118119
120+
## 6. Removed `createAssembly` callback support
121+
122+
Use the returned promise instead.
123+
124+
## 7. Removed `isResumable` option
125+
126+
Only Tus uploads (which we call resumable uploads) are now supported using the SDK, and this option has therefore been removed.
127+
128+
## 8. `form-data` testing
129+
130+
`form-data` upgraded from 3 to 4 - this might cause some subtle differences in behavior related to file uploads. Be sure to test file uploads.
131+
132+
## 9. `got` upgraded
133+
134+
As a consequence of upgrading `got` to v14, the `gotRetry` option no longer accepts `number`. Instead use `{ limit: 0 }`. See [`got` `retry` object documentation](https://github.com/sindresorhus/got/blob/v14.4.9/documentation/7-retry.md).
135+
119136
## Testing & troubleshooting
120137
121138
- Run your existing integration tests on Node 20+. If you relied on CommonJS `require`, convert those modules or wrap calls in `import()` shims as shown above.

0 commit comments

Comments
 (0)