diff --git a/README.md b/README.md index a269b7c8..f569f08b 100644 --- a/README.md +++ b/README.md @@ -738,7 +738,7 @@ An important note on this approach is that you cannot call `commit()` on transac Assets can be uploaded using the `client.assets.upload(...)` method. ``` -client.assets.upload(type: 'file' | image', body: File | Blob | Buffer | NodeStream, options = {}): Promise +client.assets.upload(type: 'file' | image', body: File | Blob | Buffer | NodeJS.ReadableStream, options = {}): Promise ``` 👉 Read more about [assets in Sanity](https://sanity.io/docs/assets) diff --git a/package-lock.json b/package-lock.json index a81a8c21..ab01ec57 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "license": "MIT", "dependencies": { "@sanity/eventsource": "5", - "get-it": "8", + "get-it": "^8.1", "rxjs": "7" }, "devDependencies": { @@ -19,11 +19,11 @@ "@rollup/plugin-commonjs": "^24.0.1", "@rollup/plugin-node-resolve": "^15.0.1", "@sanity/pkg-utils": "^2.2.13", - "@sanity/semantic-release-preset": "^4.0.1", - "@types/node": "^18.15.3", - "@typescript-eslint/eslint-plugin": "^5.56.0", - "@typescript-eslint/parser": "^5.56.0", - "@vitest/coverage-c8": "^0.29.5", + "@sanity/semantic-release-preset": "^4.1.0", + "@types/node": "^18.15.10", + "@typescript-eslint/eslint-plugin": "^5.57.0", + "@typescript-eslint/parser": "^5.57.0", + "@vitest/coverage-c8": "^0.29.8", "eslint": "^8.36.0", "eslint-config-prettier": "^8.8.0", "eslint-plugin-prettier": "^4.2.1", @@ -32,14 +32,14 @@ "happy-dom": "^8.9.0", "ls-engines": "^0.9.0", "nock": "^13.3.0", - "prettier": "^2.8.5", + "prettier": "^2.8.7", "prettier-plugin-packagejson": "^2.4.3", - "rimraf": "^4.4.0", - "rollup": "^3.20.0", + "rimraf": "^4.4.1", + "rollup": "^3.20.2", "sse-channel": "^4.0.0", - "terser": "^5.16.6", + "terser": "^5.16.8", "typescript": "^5.0.2", - "vitest": "^0.29.6", + "vitest": "^0.29.8", "vitest-github-actions-reporter": "^0.10.0" }, "engines": { diff --git a/package.json b/package.json index c423e5b8..80425cb5 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "import": "./dist/index.browser.js" }, "deno": "./dist/index.browser.js", + "edge-light": "./dist/index.browser.js", "worker": "./dist/index.browser.js", "source": "./src/index.ts", "require": "./dist/index.cjs", @@ -89,7 +90,7 @@ }, "dependencies": { "@sanity/eventsource": "5", - "get-it": "8", + "get-it": "^8.1", "rxjs": "7" }, "devDependencies": { @@ -98,11 +99,11 @@ "@rollup/plugin-commonjs": "^24.0.1", "@rollup/plugin-node-resolve": "^15.0.1", "@sanity/pkg-utils": "^2.2.13", - "@sanity/semantic-release-preset": "^4.0.1", - "@types/node": "^18.15.3", - "@typescript-eslint/eslint-plugin": "^5.56.0", - "@typescript-eslint/parser": "^5.56.0", - "@vitest/coverage-c8": "^0.29.5", + "@sanity/semantic-release-preset": "^4.1.0", + "@types/node": "^18.15.10", + "@typescript-eslint/eslint-plugin": "^5.57.0", + "@typescript-eslint/parser": "^5.57.0", + "@vitest/coverage-c8": "^0.29.8", "eslint": "^8.36.0", "eslint-config-prettier": "^8.8.0", "eslint-plugin-prettier": "^4.2.1", @@ -111,14 +112,14 @@ "happy-dom": "^8.9.0", "ls-engines": "^0.9.0", "nock": "^13.3.0", - "prettier": "^2.8.5", + "prettier": "^2.8.7", "prettier-plugin-packagejson": "^2.4.3", - "rimraf": "^4.4.0", - "rollup": "^3.20.0", + "rimraf": "^4.4.1", + "rollup": "^3.20.2", "sse-channel": "^4.0.0", - "terser": "^5.16.6", + "terser": "^5.16.8", "typescript": "^5.0.2", - "vitest": "^0.29.6", + "vitest": "^0.29.8", "vitest-github-actions-reporter": "^0.10.0" }, "engines": { diff --git a/runtimes/node/test.cjs b/runtimes/node/test.cjs index 89c2ac17..84cdd879 100644 --- a/runtimes/node/test.cjs +++ b/runtimes/node/test.cjs @@ -25,8 +25,8 @@ test('top-level imports', async (t) => { }) await t.test('the same named exports are used as ESM', async () => { - const cjs = Object.keys(require('@sanity/client')) - const esm = Object.keys(await import('@sanity/client')) + const cjs = Object.keys(require('@sanity/client')).sort() + const esm = Object.keys(await import('@sanity/client')).sort() assert.deepEqual(cjs, esm) }) diff --git a/src/assets/AssetsClient.ts b/src/assets/AssetsClient.ts index c9eed542..1ee7eacc 100644 --- a/src/assets/AssetsClient.ts +++ b/src/assets/AssetsClient.ts @@ -178,7 +178,7 @@ function _upload( } function optionsFromFile(opts: Record, file: Any) { - if (typeof window === 'undefined' || !(file instanceof window.File)) { + if (typeof File === 'undefined' || !(file instanceof File)) { return opts } diff --git a/src/index.browser.ts b/src/index.browser.ts index 3a467bea..913d327c 100644 --- a/src/index.browser.ts +++ b/src/index.browser.ts @@ -26,3 +26,6 @@ export default function deprecatedCreateClient(config: ClientConfig) { printNoDefaultExport() return new SanityClient(httpRequest, config) } + +/** @alpha */ +export {adapter as unstable__adapter, environment as unstable__environment} from 'get-it' diff --git a/src/index.ts b/src/index.ts index 67cf69d5..5df81dc5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -26,3 +26,6 @@ export default function deprecatedCreateClient(config: ClientConfig) { printNoDefaultExport() return new SanityClient(httpRequest, config) } + +/** @alpha */ +export {adapter as unstable__adapter, environment as unstable__environment} from 'get-it' diff --git a/vitest.browser.config.ts b/vitest.browser.config.ts index b1f68cd2..10532384 100644 --- a/vitest.browser.config.ts +++ b/vitest.browser.config.ts @@ -13,6 +13,6 @@ export default defineConfig({ alias: {'@sanity/client': pkg.exports['.'].browser.source}, }, resolve: { - conditions: ['browser'], + conditions: ['browser', 'module', 'import'], }, }) diff --git a/vitest.edge.config.ts b/vitest.edge.config.ts index 49988463..44e3e686 100644 --- a/vitest.edge.config.ts +++ b/vitest.edge.config.ts @@ -13,6 +13,7 @@ export default defineConfig({ alias: {'@sanity/client': pkg.exports['.'].browser.source}, }, resolve: { - conditions: ['worker', 'browser'], + // https://github.com/vercel/next.js/blob/95322649ffb2ad0d6423481faed188dd7b1f7ff2/packages/next/src/build/webpack-config.ts#L1079-L1084 + conditions: ['edge-light', 'worker', 'browser', 'module', 'import', 'node'], }, })