Skip to content

Commit da87e89

Browse files
authored
fix(blob): Allow for Request object to be a body of objects (#767)
* fix(blob): Allow for Request object to be a body of objects Before this commit, you could not pass Request objects because of a bug in the module we used to detect plain objects. This is now fixed. * lockfile
1 parent d7b5153 commit da87e89

File tree

7 files changed

+30
-14
lines changed

7 files changed

+30
-14
lines changed

.changeset/pretty-tomatoes-jump.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@vercel/blob': patch
3+
---
4+
5+
Fix bad detection of Request being a plain object

packages/blob/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
"async-retry": "^1.3.3",
6464
"bytes": "^3.1.2",
6565
"is-buffer": "^2.0.5",
66-
"is-plain-object": "^5.0.0",
6766
"undici": "^5.28.4"
6867
},
6968
"devDependencies": {

packages/blob/src/helpers.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,21 @@ export function getDownloadUrl(blobUrl: string): string {
6363

6464
return url.toString();
6565
}
66+
67+
// Extracted from https://github.com/sindresorhus/is-plain-obj/blob/main/index.js
68+
// It's just nearly impossible to use ESM modules with our current setup
69+
export function isPlainObject(value: unknown): boolean {
70+
if (typeof value !== 'object' || value === null) {
71+
return false;
72+
}
73+
74+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- ok
75+
const prototype = Object.getPrototypeOf(value);
76+
return (
77+
(prototype === null ||
78+
prototype === Object.prototype ||
79+
Object.getPrototypeOf(prototype) === null) &&
80+
!(Symbol.toStringTag in value) &&
81+
!(Symbol.iterator in value)
82+
);
83+
}

packages/blob/src/multipart/create-uploader.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
import { isPlainObject } from 'is-plain-object';
2-
import { BlobError, type CommonCreateBlobOptions } from '../helpers';
1+
import {
2+
BlobError,
3+
isPlainObject,
4+
type CommonCreateBlobOptions,
5+
} from '../helpers';
36
import type { CreatePutMethodOptions, PutBody } from '../put-helpers';
47
import { createPutHeaders, createPutOptions } from '../put-helpers';
58
import { completeMultipartUpload } from './complete';

packages/blob/src/multipart/upload.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import bytes from 'bytes';
22
import type { BodyInit } from 'undici';
3-
import { isPlainObject } from 'is-plain-object';
43
import { BlobServiceNotAvailable, requestApi } from '../api';
54
import { debug } from '../debug';
65
import {
76
type CommonCreateBlobOptions,
87
type BlobCommandOptions,
98
BlobError,
9+
isPlainObject,
1010
} from '../helpers';
1111
import { createPutHeaders, createPutOptions } from '../put-helpers';
1212
import type { PutBody, CreatePutMethodOptions } from '../put-helpers';

packages/blob/src/put.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import type { BodyInit } from 'undici';
2-
import { isPlainObject } from 'is-plain-object';
32
import { requestApi } from './api';
43
import type { CommonCreateBlobOptions } from './helpers';
5-
import { BlobError } from './helpers';
4+
import { BlobError, isPlainObject } from './helpers';
65
import { uncontrolledMultipartUpload } from './multipart/uncontrolled';
76
import type {
87
CreatePutMethodOptions,

pnpm-lock.yaml

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)