Skip to content

Commit

Permalink
feat!: v7 [WIP] (#866)
Browse files Browse the repository at this point in the history
Co-authored-by: Yuval Datner <[email protected]>
Co-authored-by: Mark R. Florkowski <[email protected]>
  • Loading branch information
3 people committed Sep 13, 2024
1 parent f5e080e commit d69dd6e
Show file tree
Hide file tree
Showing 326 changed files with 32,697 additions and 11,624 deletions.
8 changes: 8 additions & 0 deletions .changeset/funny-wombats-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"uploadthing": major
---

refactor: reduce bundle size

We've continued our efforts to reduce the bundle size of the client side javascript. In a previous minor release, we reduced the bundle size by 70%, from 120kB to 40kB. This release continues on that work with a further reduction of 35% down to just over 25kB client side
javascript shipped to the browser from the `uploadthing/client` package.
8 changes: 8 additions & 0 deletions .changeset/honest-rats-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"uploadthing": major
---

feat!: change signature of `genUploader` to return an object with 2 functions, `uploadFiles` and `createUpload`

`createUpload` can be used to create a resumable upload which you can pause and resume as you wish.
See example: https://github.com/pingdotgg/uploadthing/blob/v7/examples/backend-adapters/client-vanilla/src/resumable-upload.ts
10 changes: 10 additions & 0 deletions .changeset/lucky-lobsters-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"uploadthing": major
"@uploadthing/shared": major
---

feat!: use ingest server

Multi Part Uplaods hasve been abstracted away and files are now uploaded as a single stream to UploadThing, reducing the manual steps required to upload files and improves performance.

Polling has been removed in favor of a streaming upload process with instant feedback
8 changes: 8 additions & 0 deletions .changeset/tame-turkeys-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@uploadthing/shared": major
"uploadthing": major
---

chore: update paths to new api domain

Previously the SDK version was just sent in the header which made it cumbersome to make large changes on the API without risking breaking older versions. This change improves our flexibility to make changes to the API without needing to do a major bump on the SDK. It should come with some nice performance wins too!
85 changes: 85 additions & 0 deletions .changeset/violet-melons-matter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
---
"uploadthing": major
---

## 🚨 Breaking Changes

### General

- Change `UPLOADTHING_API_KEY` to `UPLOADTHING_TOKEN`. The token contains both your API key and some other metadata required by the SDK. You can get a token from the [UploadThing dashboard](https://uploadthing.com/dashboard). All options related to `uploadthingSecret` / `apiKey` has now been removed and replaced with `token`:

```diff
- createRouteHandler({ router, config: { uploadthingSecret: 'sk_123' } })
+ createRouteHandler({ router, config: { token: 'MY_TOKEN' } })

- new UTApi({ apiKey: 'sk_123' })
+ new UTApi({ token: 'MY_TOKEN' })
```

- If you relied on the `CUSTOM_INFRA_URL` environment variable override, you will have to change this to `UPLOADTHING_API_URL` or `UPLOADTHING_INGEST_URL` depending on your use case.

### `uploadthing/client`

- Change signature of `genUploader` to return an object instead of a single function.

```diff
- const uploadFiles = genUploader(opts)
+ const { uploadFiles } = genUploader(opts)
```

- Remove `uploadFiles.skipPolling` option in favor of a new server-side RouteOption `awaitServerData`. If you want your client callback to run as soon as the file has been uploaded,
without waiting for your server side `onUploadComplete` to run, you can now set `awaitServerData` to `false`.

```diff
// Client option
uploadFiles({
- skipPolling: true
})
// Server option
const router = {
myRoute: f(
{ ... },
+ { awaitServerData: false }
)
}
```

Read more about the new `RouteOptions` in the [📚 Server API Reference docs](https://docs.uploadthing.com/api-reference/server#route-options)

### Adapters

- Change `config.logLevel` levels. Most are now capitalized to match our new logger. Auto-complete should make migrating trivial.

```diff
- logLevel: 'info'
+ logLevel: 'Info'
```

- `uploadthing/server` adapter now returns a single function instead of individual named functions. The handler accepts a request and will handle routing internally.

```diff
- const { GET, POST } = createRouteHandler({ router, config })
+ const handler = createRouteHandler({ router, config })
```

You can re-export the handler as named functions if your framework requires it.

```ts
const handler = createRouteHandler({ router, config })
export { handler as GET, handler as POST }
```

## Features

### General

- Add new configuration provider. All config options (e.g. `UTApi.constructor` options or `createRouteHandler.config` option can now also be set using an environment variable. Setting the option in the constructor is still supported and takes precedence over the environment variable.

```ts
const api = new UTApi({
logLevel: 'Info',
})
// is the same as
process.env.UPLOADTHING_LOG_LEVEL = 'Info'
const api = new UTApi()
```
4 changes: 2 additions & 2 deletions .github/analyze-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ function formatDiff(diff) {
let treemapMain = "_No treemap on forks_";
let treemapPr = "_No treemap on forks_";
if (
typeof process.env.UPLOADTHING_SECRET === "string" &&
process.env.UPLOADTHING_SECRET.length > 0
typeof process.env.UPLOADTHING_TOKEN === "string" &&
process.env.UPLOADTHING_TOKEN.length > 0
) {
const utapi = new UTApi();
const files = await utapi.uploadFiles([
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ name: CI
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
UPLOADTHING_TEST_SECRET: ${{ secrets.UPLOADTHING_TEST_SECRET }}

on:
push:
Expand Down Expand Up @@ -34,6 +33,8 @@ jobs:
run: pnpm turbo build --filter "./packages/*"
- name: Test
run: pnpm run test
env:
UPLOADTHING_TEST_TOKEN: ${{ secrets.UPLOADTHING_TEST_TOKEN }}

lint:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -140,4 +141,4 @@ jobs:
run: node .github/analyze-bundle.js
env:
GITHUB_TOKEN: ${{ github.token }}
UPLOADTHING_SECRET: ${{ secrets.UPLOADTHING_E2E_TEST_SECRET }}
UPLOADTHING_TOKEN: ${{ secrets.UPLOADTHING_E2E_TEST_TOKEN }}
4 changes: 2 additions & 2 deletions .github/workflows/examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ jobs:
- name: Run E2E Tests (if exists)
run: pnpm turbo --filter ./examples/${{ matrix.dir }} test
env:
UPLOADTHING_SECRET: ${{ secrets.UPLOADTHING_E2E_TEST_SECRET }}
UPLOADTHING_TOKEN: ${{ secrets.UPLOADTHING_E2E_TEST_TOKEN }}

- uses: actions/upload-artifact@v4
if: ${{ !cancelled() && matrix.dir == 'backend-adapters' }}
with:
Expand Down
41 changes: 38 additions & 3 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,40 @@
.next
node_modules
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts

# sitemap
public/robots.txt
public/sitemap.xml
public/sitemap-0.xml
public/sitemap-0.xml
Loading

0 comments on commit d69dd6e

Please sign in to comment.