Skip to content

Commit 85101e4

Browse files
chore(client): drop support for EOL node versions
1 parent b5f3ba5 commit 85101e4

File tree

11 files changed

+29
-135
lines changed

11 files changed

+29
-135
lines changed

.github/workflows/ci.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Set up Node
2020
uses: actions/setup-node@v4
2121
with:
22-
node-version: '18'
22+
node-version: '20'
2323

2424
- name: Bootstrap
2525
run: ./scripts/bootstrap
@@ -40,7 +40,7 @@ jobs:
4040
- name: Set up Node
4141
uses: actions/setup-node@v4
4242
with:
43-
node-version: '18'
43+
node-version: '20'
4444

4545
- name: Bootstrap
4646
run: ./scripts/bootstrap
@@ -72,7 +72,7 @@ jobs:
7272
- name: Set up Node
7373
uses: actions/setup-node@v4
7474
with:
75-
node-version: '18'
75+
node-version: '20'
7676

7777
- name: Bootstrap
7878
run: ./scripts/bootstrap

.github/workflows/publish-npm.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Set up Node
2020
uses: actions/setup-node@v3
2121
with:
22-
node-version: '18'
22+
node-version: '20'
2323

2424
- name: Install dependencies
2525
run: |

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ TypeScript >= 4.9 is supported.
355355
The following runtimes are supported:
356356

357357
- Web browsers (Up-to-date Chrome, Firefox, Safari, Edge, and more)
358-
- Node.js 18 LTS or later ([non-EOL](https://endoflife.date/nodejs)) versions.
358+
- Node.js 20 LTS or later ([non-EOL](https://endoflife.date/nodejs)) versions.
359359
- Deno v1.28.0 or higher.
360360
- Bun 1.0 or later.
361361
- Cloudflare Workers.

package.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@
4949
"resolutions": {
5050
"synckit": "0.8.8"
5151
},
52-
"browser": {
53-
"./internal/shims/getBuiltinModule.mjs": "./internal/shims/nullGetBuiltinModule.mjs",
54-
"./internal/shims/getBuiltinModule.js": "./internal/shims/nullGetBuiltinModule.js"
55-
},
5652
"imports": {
5753
"@openint/sdk": ".",
5854
"@openint/sdk/*": "./src/*"
@@ -72,5 +68,8 @@
7268
"import": "./dist/*.mjs",
7369
"require": "./dist/*.js"
7470
}
71+
},
72+
"engines": {
73+
"node": ">= 20"
7574
}
7675
}

src/internal/shims/crypto.ts

-18
This file was deleted.

src/internal/shims/file.ts

-32
This file was deleted.

src/internal/shims/getBuiltinModule.ts

-66
This file was deleted.

src/internal/shims/nullGetBuiltinModule.ts

-1
This file was deleted.

src/internal/to-file.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { type File, getFile } from './shims/file';
21
import { BlobPart, getName, makeFile, isAsyncIterable } from './uploads';
32
import type { FilePropertyBag } from './builtin-types';
3+
import { checkFileSupport } from './uploads';
44

55
type BlobLikePart = string | ArrayBuffer | ArrayBufferView | BlobLike | DataView;
66

@@ -85,12 +85,14 @@ export async function toFile(
8585
name?: string | null | undefined,
8686
options?: FilePropertyBag | undefined,
8787
): Promise<File> {
88+
checkFileSupport();
89+
8890
// If it's a promise, resolve it.
8991
value = await value;
9092

9193
// If we've been given a `File` we don't need to do anything
9294
if (isFileLike(value)) {
93-
if (value instanceof getFile()) {
95+
if (value instanceof File) {
9496
return value;
9597
}
9698
return makeFile([await value.arrayBuffer()], value.name);

src/internal/uploads.ts

+16-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { type RequestOptions } from './request-options';
22
import type { FilePropertyBag, Fetch } from './builtin-types';
33
import type { Openint } from '../client';
4-
import { type File, getFile } from './shims/file';
54
import { ReadableStreamFrom } from './shims';
65

76
export type BlobPart = string | ArrayBuffer | ArrayBufferView | Blob | DataView;
@@ -12,6 +11,20 @@ interface BunFile extends Blob {
1211
readonly name?: string | undefined;
1312
}
1413

14+
export const checkFileSupport = () => {
15+
if (typeof File === 'undefined') {
16+
const { process } = globalThis as any;
17+
const isOldNode =
18+
typeof process?.versions?.node === 'string' && parseInt(process.versions.node.split('.')) < 20;
19+
throw new Error(
20+
'`File` is not defined as a global, which is required for file uploads.' +
21+
(isOldNode ?
22+
" Update to Node 20 LTS or newer, or set `globalThis.File` to `import('node:buffer').File`."
23+
: ''),
24+
);
25+
}
26+
};
27+
1528
/**
1629
* Typically, this is a native "File" class.
1730
*
@@ -32,7 +45,7 @@ export function makeFile(
3245
fileName: string | undefined,
3346
options?: FilePropertyBag,
3447
): File {
35-
const File = getFile();
48+
checkFileSupport();
3649
return new File(fileBits as any, fileName ?? 'unknown_file', options);
3750
}
3851

@@ -125,8 +138,7 @@ export const createForm = async <T = Record<string, unknown>>(
125138

126139
// We check for Blob not File because Bun.File doesn't inherit from File,
127140
// but they both inherit from Blob and have a `name` property at runtime.
128-
const isNamedBlob = (value: object) =>
129-
value instanceof getFile() || (value instanceof Blob && 'name' in value);
141+
const isNamedBlob = (value: object) => value instanceof Blob && 'name' in value;
130142

131143
const isUploadable = (value: unknown) =>
132144
typeof value === 'object' &&

src/internal/utils/uuid.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
22

3-
import { getCrypto } from '../shims/crypto';
4-
53
/**
64
* https://stackoverflow.com/a/2117523
75
*/
86
export let uuid4 = function () {
9-
const crypto = getCrypto();
7+
const { crypto } = globalThis as any;
108
if (crypto?.randomUUID) {
119
uuid4 = crypto.randomUUID.bind(crypto);
1210
return crypto.randomUUID();

0 commit comments

Comments
 (0)