Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
vvo authored Jan 17, 2025
2 parents 50db6b4 + 0c98feb commit 8efc013
Show file tree
Hide file tree
Showing 112 changed files with 9,977 additions and 5,285 deletions.
10 changes: 10 additions & 0 deletions .changeset/three-rockets-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@vercel/blob': patch
---

fix(blob): allow client uploads in web workers

Before this change, we had guards so client uploads could only be used in
browser environments, this prevented customers to use Vercel Blob in Web
Workers, sometimes React Native or in general anywhere window is not really what
we think it is.
10 changes: 7 additions & 3 deletions .github/workflows/release-snapshot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,17 @@ jobs:
- name: Add SHORT_SHA env property with commit short sha
run: echo "SHORT_SHA=`echo ${{ github.sha }} | cut -c1-8`" >> $GITHUB_ENV

- name: Version Packages
run: pnpm changeset version --snapshot ${SHORT_SHA}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN_ELEVATED }}

- name: Build
run: pnpm build

- name: Create Snapshot Release
run: |
pnpm changeset version --snapshot ${SHORT_SHA}
pnpm changeset publish --no-git-tag --tag snapshot
run: pnpm changeset publish --no-git-tag --tag snapshot
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN_ELEVATED }}
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x, 20.x]
node-version: [18.x, 20.x, 22.x]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pnpm lint-staged
pnpm lint-staged
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@
},
"prettier": "@vercel/style-guide/prettier",
"devDependencies": {
"@changesets/cli": "2.27.7",
"@changesets/cli": "2.27.11",
"@vercel/style-guide": "5.2.0",
"eslint": "8.56.0",
"eslint-config-custom": "workspace:*",
"husky": "9.0.11",
"husky": "9.1.7",
"jest": "29.7.0",
"lint-staged": "15.2.9",
"prettier": "3.3.2",
"publint": "0.2.8",
"ts-jest": "29.1.5",
"lint-staged": "15.4.1",
"prettier": "3.4.2",
"publint": "0.3.2",
"ts-jest": "29.2.5",
"turbo": "1.12.4",
"typescript": "5.3.3"
"typescript": "5.7.3"
},
"packageManager": "pnpm@8.15.3",
"packageManager": "pnpm@9.13.0",
"engines": {
"node": ">=18"
}
Expand Down
60 changes: 60 additions & 0 deletions packages/blob/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,65 @@
# @vercel/blob

## 0.27.0

### Minor Changes

- 7872e61: contentType default is now 'application/octet-stream' instead of `undefined`

## 0.26.0

### Minor Changes

- c3afec3: Add onUploadProgress feature to put/upload

You can now track the upload progress in Node.js and all major browsers when
using put/upload in multipart, non-multipart and client upload modes. Basically
anywhere in our API you can upload a file, then you can follow the upload
progress.

Here's a basic usage example:

```
const blob = await put('big-file.pdf', file, {
access: 'public',
onUploadProgress(event) {
console.log(event.loaded, event.total, event.percentage);
}
});
```

Fixes #543
Fixes #642

## 0.25.1

### Patch Changes

- d58f9de: fix(blob): provide custom errors for expired client tokens and pathname mismatch

## 0.25.0

### Minor Changes

- 61b5939: BREAKING CHANGE, we're no more accepting non-encoded versions of ?, # and // in pathnames. If you want to use such characters in your pathnames then you will need to encode them.

## 0.24.1

### Patch Changes

- 37d84ef: Throw specific error (BlobContentTypeNotAllowed) when file type doesn't match
- da87e89: Fix bad detection of Request being a plain object

## 0.24.0

### Minor Changes

- 8098803: Add createFolder method. Warning, if you were using the standard put() method to created fodlers, this will now fail and you must move to createFolder() instead.

### Patch Changes

- 8d7e8b9: Limit pathname length to 950 to respect internal limitations and provide better early DX.

## 0.23.4

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/blob/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ npm install @vercel/blob
We have examples on the vercel.com documentation, there are two ways to upload files to Vercel Blob:

1. [Server uploads](https://vercel.com/docs/storage/vercel-blob/quickstart#server-uploads): This is the most common way to upload files. The file is first sent to your server and then to Vercel Blob. It's straightforward to implement, but you are limited to the request body your server can handle. Which in case of a Vercel-hosted website is 4.5 MB. **This means you can't upload files larger than 4.5 MB on Vercel when using this method.**
2. [Client uploads](https://vercel.com/docs/storage/vercel-blob/quickstart#client-uploads): This is a more advanced solution for when you need to upload larger files. The file is securely sent directly from the client (a browser for example) to Vercel Blob. This requires a bit more work to implement, but it allows you to upload files up to 500 MB.
2. [Client uploads](https://vercel.com/docs/storage/vercel-blob/quickstart#client-uploads): This is a more advanced solution for when you need to upload larger files. The file is securely sent directly from the client (a browser for example) to Vercel Blob. This requires a bit more work to implement, but it allows you to upload files up to 5 TB.

## Releasing

Expand Down
8 changes: 7 additions & 1 deletion packages/blob/jest/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,11 @@
// but they are available everywhere else.
// See https://stackoverflow.com/questions/68468203/why-am-i-getting-textencoder-is-not-defined-in-jest
const { TextEncoder, TextDecoder } = require('node:util');
// eslint-disable-next-line import/order -- On purpose to make requiring undici work
const { ReadableStream } = require('node:stream/web');

Object.assign(global, { TextDecoder, TextEncoder });
Object.assign(global, { TextDecoder, TextEncoder, ReadableStream });

const { Request, Response } = require('undici');

Object.assign(global, { Request, Response });
17 changes: 8 additions & 9 deletions packages/blob/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vercel/blob",
"version": "0.23.4",
"version": "0.27.0",
"description": "The Vercel Blob JavaScript API client",
"homepage": "https://vercel.com/storage/blob",
"repository": {
Expand Down Expand Up @@ -61,25 +61,24 @@
},
"dependencies": {
"async-retry": "^1.3.3",
"bytes": "^3.1.2",
"is-buffer": "^2.0.5",
"is-plain-object": "^5.0.0",
"is-node-process": "^1.2.0",
"throttleit": "^2.1.0",
"undici": "^5.28.4"
},
"devDependencies": {
"@edge-runtime/jest-environment": "2.3.10",
"@edge-runtime/types": "2.2.9",
"@types/async-retry": "1.4.8",
"@types/bytes": "3.1.4",
"@types/jest": "29.5.12",
"@types/node": "20.14.15",
"@types/async-retry": "1.4.9",
"@types/jest": "29.5.14",
"@types/node": "22.10.7",
"eslint": "8.56.0",
"eslint-config-custom": "workspace:*",
"jest": "29.7.0",
"jest-environment-jsdom": "29.7.0",
"ts-jest": "29.1.5",
"ts-jest": "29.2.5",
"tsconfig": "workspace:*",
"tsup": "8.1.0"
"tsup": "8.3.5"
},
"engines": {
"node": ">=16.14"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
BlobStoreNotFoundError,
BlobStoreSuspendedError,
BlobUnknownError,
BlobContentTypeNotAllowedError,
requestApi,
} from './api';
import { BlobError } from './helpers';
Expand Down Expand Up @@ -64,8 +65,8 @@ describe('api', () => {
headers: {
authorization: 'Bearer 123',
'x-api-blob-request-attempt': '0',
'x-api-blob-request-id': ':1715951788049:b3a681154d83b',
'x-api-version': '7',
'x-api-blob-request-id': expect.any(String) as string,
'x-api-version': '8',
},
method: 'POST',
},
Expand Down Expand Up @@ -103,18 +104,25 @@ describe('api', () => {
it.each([
[300, 'store_suspended', BlobStoreSuspendedError],
[400, 'forbidden', BlobAccessError],
[
400,
'forbidden',
BlobContentTypeNotAllowedError,
'"contentType" text/plain is not allowed',
],
[500, 'not_found', BlobNotFoundError],
[600, 'bad_request', BlobError],
[700, 'store_not_found', BlobStoreNotFoundError],
[800, 'not_allowed', BlobUnknownError],
[800, 'not_allowed', BlobUnknownError],
])(
`should not retry '%s %s' response error response`,
async (status, code, error) => {
async (status, code, error, message = '') => {
const fetchMock = jest.spyOn(undici, 'fetch').mockImplementation(
jest.fn().mockResolvedValue({
status,
ok: false,
json: () => Promise.resolve({ error: { code } }),
json: () => Promise.resolve({ error: { code, message } }),
}),
);

Expand Down
Loading

0 comments on commit 8efc013

Please sign in to comment.