Skip to content

Commit e117572

Browse files
committed
fix: revert ReadableStream change
1 parent 4c2d1ec commit e117572

File tree

9 files changed

+39
-31
lines changed

9 files changed

+39
-31
lines changed

MIGRATION.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,19 @@
1212
To upgrade to the latest version of `contentful-management`, use your package manager and then make any necessary changes outlined in the migration guides below.
1313

1414
**npm:**
15+
1516
```bash
1617
npm install contentful-management@latest
1718
```
19+
1820
**yarn:**
21+
1922
```bash
2023
yarn upgrade contentful-management@latest
2124
```
25+
2226
**pnpm:**
27+
2328
```bash
2429
pnpm update contentful-management@latest
2530
```
@@ -49,6 +54,7 @@ If you are affected by any of the items below, follow the upgrade guides in the
4954
The library now targets ECMAScript 2021, and Babel transpilation for older JavaScript versions has been removed. This means modern JavaScript features like optional chaining (`?.`), nullish coalescing (`??`), and `Promise.any()` are used directly without transpilation.
5055

5156
**Affected environments:**
57+
5258
- Internet Explorer (all versions)
5359
- Chrome < 85
5460
- Firefox < 79
@@ -63,6 +69,7 @@ Browser and Node environments that do not support ES2021 might need an additiona
6369
We dropped support for versions of Node that were no longer LTS and now support Node v20+.
6470

6571
**Compatibility:**
72+
6673
- ✅ Node.js v20+
6774
- ❌ Node.js v18 and below
6875

@@ -85,22 +92,24 @@ And have been replaced with an ESM build for use in modern environments, a Commo
8592
If you were accessing any of the previous bundles directly, you will need to update to pull from one of the new bundles.
8693

8794
**import example:**
95+
8896
```javascript
8997
// Before
90-
import contentful from './node_modules/contentful-management/dist/contentful-management.node.js';
98+
import contentful from './node_modules/contentful-management/dist/contentful-management.node.js'
9199

92100
// After (ESM)
93-
import contentful from 'contentful-management';
101+
import contentful from 'contentful-management'
94102

95103
// After (CommonJS) - still works
96-
const contentful = require('contentful-management');
104+
const contentful = require('contentful-management')
97105
```
98106

99107
#### Changes to browser bundle
100108

101109
Browser bundle methods must now be accessed from the `contentfulManagement` object which is added to `window` on load (e.g., `window.contentfulManagement.createClient()`). If you were using methods directly, update your code to destructure them from the `contentfulManagement` object (e.g., `const { createClient } = contentfulManagement`).
102110

103111
**JSDelivr usage:**
112+
104113
```html
105114
<!-- Before -->
106115
<script src="https://cdn.jsdelivr.net/npm/contentful-management@11/dist/contentful-management.browser.min.js"></script>
@@ -122,35 +131,23 @@ All types are exported from both `contentful-management` and `contentful-managem
122131
**Migration options:**
123132

124133
Option 1 - Update tsconfig.json:
134+
125135
```json
126136
{
127137
"compilerOptions": {
128-
"moduleResolution": "node16" // or "bundler" or "nodenext"
138+
"moduleResolution": "node16" // or "bundler" or "nodenext"
129139
}
130140
}
131141
```
132142

133143
Option 2 - Import from main package:
144+
134145
```typescript
135146
// Instead of
136-
import type { Space } from 'contentful-management/types';
147+
import type { Space } from 'contentful-management/types'
137148

138149
// Use
139-
import type { Space } from 'contentful-management';
140-
```
141-
142-
##### Replaced the `Stream` type with `ReadableStream`
143-
144-
The `Stream` type was specific to Node.js environments and could cause issues in browsers. It has been replaced with `ReadableStream`, which is a global type available in both Node.js and browser environments.
145-
146-
**Migration example:**
147-
```typescript
148-
// Before
149-
import type { Stream } from 'stream';
150-
function processStream(stream: Stream) { ... }
151-
152-
// After
153-
function processStream(stream: ReadableStream) { ... }
150+
import type { Space } from 'contentful-management'
154151
```
155152

156153
### Troubleshooting
@@ -166,6 +163,7 @@ function processStream(stream: ReadableStream) { ... }
166163
**Cause:** Your TypeScript configuration uses an older module resolution strategy.
167164

168165
**Solution:** Update your `tsconfig.json`:
166+
169167
```json
170168
{
171169
"compilerOptions": {
@@ -180,19 +178,22 @@ Or import types directly from `contentful-management` instead of `contentful-man
180178

181179
**Cause:** Your environment doesn't support ES2021.
182180

183-
**Solution:**
181+
**Solution:**
182+
184183
- For Node.js: Upgrade to Node.js v20 or higher
185184
- For browsers: Ensure you're targeting modern browsers that support ES2021 (Chrome 85+, Firefox 79+, Safari 14+, Edge 85+)
186185
- Consider using a transpilation tool like Babel if you must support older environments
187186

188187
#### Types not resolving correctly
189188

190189
**Possible causes:**
190+
191191
- Outdated module resolution in `tsconfig.json`
192192
- IDE needs to be restarted after upgrade
193193
- Type cache needs to be cleared
194194

195195
**Solutions:**
196+
196197
1. Update `moduleResolution` to `node16` or higher
197198
2. Restart your IDE/TypeScript server
198199
3. Delete `node_modules` and reinstall: `rm -rf node_modules && npm install`
@@ -202,4 +203,3 @@ Or import types directly from `contentful-management` instead of `contentful-man
202203
- Review the [CHANGELOG](CHANGELOG.md) for all changes
203204
- Check the [README](README.md) for updated usage examples
204205
- [File an issue](https://github.com/contentful/contentful-management.js/issues) if you encounter problems
205-

lib/adapters/REST/endpoints/app-upload.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { AxiosInstance } from 'contentful-sdk-core'
2+
import type Stream from 'stream'
23
import * as raw from './raw'
34
import type { GetAppUploadParams, GetOrganizationParams } from '../../../common-types'
45
import type { RestEndpoint } from '../types'
@@ -32,7 +33,7 @@ export const del: RestEndpoint<'AppUpload', 'delete'> = (
3233
export const create: RestEndpoint<'AppUpload', 'create'> = (
3334
http: AxiosInstance,
3435
params: GetOrganizationParams,
35-
payload: { file: string | ArrayBuffer | ReadableStream },
36+
payload: { file: string | ArrayBuffer | Stream },
3637
) => {
3738
const httpUpload = getUploadHttpClient(http)
3839

lib/adapters/REST/endpoints/upload.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { AxiosInstance } from 'contentful-sdk-core'
2+
import type Stream from 'stream'
23
import type {
34
GetSpaceEnvironmentParams,
45
GetSpaceEnvironmentUploadParams,
@@ -22,7 +23,7 @@ const getEntityUploadUrl = (params: GetSpaceEnvironmentUploadParams) => {
2223
export const create: RestEndpoint<'Upload', 'create'> = (
2324
http: AxiosInstance,
2425
params: GetSpaceEnvironmentParams,
25-
data: { file: string | ArrayBuffer | ReadableStream },
26+
data: { file: string | ArrayBuffer | Stream },
2627
) => {
2728
const httpUpload = getUploadHttpClient(http)
2829

lib/common-types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { RawAxiosRequestConfig, RawAxiosRequestHeaders } from 'axios'
22
import type { OpPatch } from 'json-patch'
3+
import type Stream from 'stream'
34
import type {
45
AccessTokenProps,
56
CreatePersonalAccessTokenProps as CreatePATProps,
@@ -1140,7 +1141,7 @@ export type MRActions = {
11401141
}
11411142
create: {
11421143
params: GetOrganizationParams
1143-
payload: { file: string | ArrayBuffer | ReadableStream }
1144+
payload: { file: string | ArrayBuffer | Stream }
11441145
return: AppUploadProps
11451146
}
11461147
}
@@ -2226,7 +2227,7 @@ export type MRActions = {
22262227
get: { params: GetSpaceEnvironmentUploadParams; return: any }
22272228
create: {
22282229
params: GetSpaceEnvironmentParams
2229-
payload: { file: string | ArrayBuffer | ReadableStream }
2230+
payload: { file: string | ArrayBuffer | Stream }
22302231
return: any
22312232
}
22322233
delete: { params: GetSpaceEnvironmentUploadParams; return: any }

lib/create-environment-api.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ import type { CreateAppAccessTokenProps } from './entities/app-access-token'
6060
import type { ResourceQueryOptions } from './entities/resource'
6161
import type { AiActionInvocationType } from './entities/ai-action-invocation'
6262
import { wrapAiActionInvocation } from './entities/ai-action-invocation'
63+
import type Stream from 'stream'
6364

6465
/**
6566
* @private
@@ -1195,7 +1196,7 @@ export default function createEnvironmentApi(makeRequest: MakeRequest) {
11951196
* .catch(console.error)
11961197
* ```
11971198
*/
1198-
createUpload: function createUpload(data: { file: string | ArrayBuffer | ReadableStream }) {
1199+
createUpload: function createUpload(data: { file: string | ArrayBuffer | Stream }) {
11991200
const raw = this.toPlainObject() as EnvironmentProps
12001201
return makeRequest({
12011202
entityType: 'Upload',

lib/create-organization-api.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { createRequestConfig } from 'contentful-sdk-core'
2+
import type Stream from 'stream'
23
import entities from './entities'
34
import type { CreateTeamMembershipProps } from './entities/team-membership'
45
import type { CreateTeamProps } from './entities/team'
@@ -663,7 +664,7 @@ export default function createOrganizationApi(makeRequest: MakeRequest) {
663664
* .catch(console.error)
664665
* ```
665666
*/
666-
createAppUpload(file: string | ArrayBuffer | ReadableStream) {
667+
createAppUpload(file: string | ArrayBuffer | Stream) {
667668
const raw = this.toPlainObject() as OrganizationProps
668669

669670
return makeRequest({

lib/entities/asset.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import copy from 'fast-copy'
22
import { freezeSys, toPlainObject } from 'contentful-sdk-core'
3+
import type Stream from 'stream'
34
import enhanceWithMethods from '../enhance-with-methods'
45
import type {
56
MetaSysProps,
@@ -47,7 +48,7 @@ export interface AssetFileProp {
4748
description: { [key: string]: string }
4849
file: {
4950
[key: string]: {
50-
file: string | ArrayBuffer | ReadableStream
51+
file: string | ArrayBuffer | Stream
5152
contentType: string
5253
fileName: string
5354
}

lib/plain/entities/app-upload.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { GetAppUploadParams, GetOrganizationParams } from '../../common-types'
22
import type { AppUploadProps } from '../../entities/app-upload'
33
import type { OptionalDefaults } from '../wrappers/wrap'
4+
import type Stream from 'stream'
45

56
export type AppUploadPlainClientAPI = {
67
/**
@@ -51,6 +52,6 @@ export type AppUploadPlainClientAPI = {
5152
*/
5253
create(
5354
params: OptionalDefaults<GetOrganizationParams>,
54-
payload: { file: string | ArrayBuffer | ReadableStream },
55+
payload: { file: string | ArrayBuffer | Stream },
5556
): Promise<AppUploadProps>
5657
}

lib/plain/entities/upload.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type Stream from 'stream'
12
import type { OptionalDefaults } from '../wrappers/wrap'
23
import type { GetSpaceEnvironmentParams, GetSpaceEnvironmentUploadParams } from '../../common-types'
34

@@ -39,7 +40,7 @@ export type UploadPlainClientAPI = {
3940
*/
4041
create(
4142
params: OptionalDefaults<GetSpaceEnvironmentParams>,
42-
data: { file: string | ArrayBuffer | ReadableStream },
43+
data: { file: string | ArrayBuffer | Stream },
4344
): Promise<any>
4445
/** Deletes the Space Environment Upload
4546
*

0 commit comments

Comments
 (0)