@opensaas/stack-storage-vercel 0.42.3 → 0.44.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +120 -0
- package/README.md +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -2
- package/dist/index.js.map +1 -1
- package/package.json +17 -6
- package/.turbo/turbo-build.log +0 -4
- package/src/index.ts +0 -312
- package/tests/vercel-blob-provider.test.ts +0 -986
- package/tsconfig.json +0 -9
- package/vitest.config.ts +0 -14
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,125 @@
|
|
|
1
1
|
# @opensaas/stack-storage-vercel
|
|
2
2
|
|
|
3
|
+
## 0.44.0-alpha.1
|
|
4
|
+
|
|
5
|
+
No changes in this release.
|
|
6
|
+
|
|
7
|
+
## 0.44.0-alpha.0
|
|
8
|
+
|
|
9
|
+
### Minor Changes
|
|
10
|
+
|
|
11
|
+
- [#1420](https://github.com/OpenSaasAU/stack/pull/1420) [`7ebd6ee`](https://github.com/OpenSaasAU/stack/commit/7ebd6ee5f78f5773b566dc6cac66d73b640c3c03) Thanks [@borisno2](https://github.com/borisno2)! - Rewrite each package README against the Prisma 8 surface
|
|
12
|
+
|
|
13
|
+
The READMEs now document the API the packages actually ship, replacing the
|
|
14
|
+
Prisma 7 spellings that no longer resolve.
|
|
15
|
+
|
|
16
|
+
Reads compose on `context.db` keyed by the list's PascalCase config key and end
|
|
17
|
+
in a terminal, rather than calling a Prisma delegate:
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
const posts = await context.db.Post.where({ status: { equals: 'published' } })
|
|
21
|
+
.orderBy({ createdAt: 'desc' })
|
|
22
|
+
.limit(20)
|
|
23
|
+
.all()
|
|
24
|
+
|
|
25
|
+
const post = await context.db.Post.where({ id }).first()
|
|
26
|
+
if (!post) return null
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
`findMany`, `findUnique`, `findFirst` and `count()` are gone; the terminals are
|
|
30
|
+
`all()`, `first()`, `aggregate()` and `nearest()`. A denied read is silent, so
|
|
31
|
+
every `first()` result is a null check.
|
|
32
|
+
|
|
33
|
+
Writes take an args object with an identity-only `where`, and a relationship is
|
|
34
|
+
set with `connect` or cleared with `null`:
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
const updated = await context.db.Post.update({
|
|
38
|
+
where: { id },
|
|
39
|
+
data: { title, author: { connect: { id: authorId } } },
|
|
40
|
+
})
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The database config documented in each README is the one `DatabaseConfig`
|
|
44
|
+
carries — `provider: 'postgresql'`, `idField`, `timestamps`, `schemas`,
|
|
45
|
+
`extensions` and `client`. `prismaClientConstructor`, `db.url` and
|
|
46
|
+
`extendPrismaSchema` are gone, and the connection is resolved from the
|
|
47
|
+
environment rather than named in the config.
|
|
48
|
+
|
|
49
|
+
Review round two swept each README against the built `.d.ts` rather than against
|
|
50
|
+
another doc, and corrected what the grep-shaped sweep had missed:
|
|
51
|
+
|
|
52
|
+
- The UI README's theming block documented bare `--background`/`--primary` HSL
|
|
53
|
+
triplets under a `.dark` class. The shipped contract is `--color-*` tokens in
|
|
54
|
+
`oklch()`, resolved through `light-dark()` and switched by `data-theme` — the
|
|
55
|
+
stylesheet's own header says the design exists "without a duplicated `.dark`
|
|
56
|
+
block". Its primitives list also omitted eight real exports (`Textarea`,
|
|
57
|
+
`Popover`, `Calendar`, `TimePicker`, `DateTimePicker`, `Combobox`, `Badge`,
|
|
58
|
+
`Avatar`), and two samples read `config.lists` without awaiting `config`.
|
|
59
|
+
- The tiptap README reused a filter-returning `AccessControl` rule as
|
|
60
|
+
**field-level** `access.update`. `FieldAccess` types those slots as
|
|
61
|
+
boolean-returning, so that is a type error and a runtime
|
|
62
|
+
`InvalidFieldAccessResultError`, not a scoped update.
|
|
63
|
+
- The storage README's upload route was the last copy still casting
|
|
64
|
+
`formData.get(...) as string` / `as 'file' | 'image'` off a
|
|
65
|
+
`FormDataEntryValue | null`.
|
|
66
|
+
- The auth README's Account shape named `providerId: 'credentials'`; better-auth
|
|
67
|
+
1.7 uses `'credential'` for email/password, and the model carries `issuer`.
|
|
68
|
+
- The Vercel Blob README passed `cacheControl` to `vercelBlobStorage()`. The
|
|
69
|
+
provider option is `cacheControlMaxAge` (a number of seconds);
|
|
70
|
+
`VercelBlobStorageConfig` carries an index signature, so the wrong spelling
|
|
71
|
+
type-checked and was silently ignored.
|
|
72
|
+
|
|
73
|
+
Round three corrected what round two's sweeps could not see, each having keyed
|
|
74
|
+
on where a construct sat rather than on what it was:
|
|
75
|
+
|
|
76
|
+
- The Vercel Blob README's **options listing** still named `cacheControl` 112
|
|
77
|
+
lines above the call site round two fixed, so the page contradicted itself and
|
|
78
|
+
the half a reader consults first was the wrong half.
|
|
79
|
+
- Sixteen hook samples across the docs and the core, cli and example READMEs
|
|
80
|
+
destructured a member the `delete` branch of its args union does not carry, so
|
|
81
|
+
the destructure failed before any in-body `operation` guard could narrow. Three
|
|
82
|
+
more named an argument on no branch at all: `value` and `inputValue` on
|
|
83
|
+
`resolveInput`/`afterOperation`, and `session` on `ResolveInputHookArgs`.
|
|
84
|
+
- The core README carried a third instance of the field-access class — a bare
|
|
85
|
+
`text({ access: … })` excerpt with no enclosing `fields: {` — plus
|
|
86
|
+
`query: true` where `OperationAccess.query` takes a function, a
|
|
87
|
+
`ValidationError` built from a string where the constructor takes `string[]`,
|
|
88
|
+
and a stale claim that `password()` is excluded from reads.
|
|
89
|
+
- The cli README's "What it does" block under `opensaas db update` described
|
|
90
|
+
`opensaas dev`, and called `migrate` a command group when it has no
|
|
91
|
+
subcommands.
|
|
92
|
+
|
|
93
|
+
### Patch Changes
|
|
94
|
+
|
|
95
|
+
- [#1729](https://github.com/OpenSaasAU/stack/pull/1729) [`8d8a338`](https://github.com/OpenSaasAU/stack/commit/8d8a338ea4606b03ef859c4128b93b40a5fc9a21) Thanks [@borisno2](https://github.com/borisno2)! - Publish only `dist`, and docs; tarballs no longer include src, tests, compiled test files or build logs.
|
|
96
|
+
|
|
97
|
+
- [#1739](https://github.com/OpenSaasAU/stack/pull/1739) [`97e428b`](https://github.com/OpenSaasAU/stack/commit/97e428b17ad99998c86a354e5a8be4c35a1d6c59) Thanks [@borisno2](https://github.com/borisno2)! - S3 and Vercel Blob providers refuse a filename that is not a single plain segment (`/`, `\`, NUL, `.`, `..`), matching `LocalStorageProvider`.
|
|
98
|
+
|
|
99
|
+
- [#1522](https://github.com/OpenSaasAU/stack/pull/1522) [`c322241`](https://github.com/OpenSaasAU/stack/commit/c322241a7a8a293ce6824df13dcb9765cd9479a2) Thanks [@borisno2](https://github.com/borisno2)! - Add a `typecheck` script to every package, covering `tests/**/*` alongside `src/**/*` (not just what `build` compiles), and fix the type errors it surfaced in existing test files.
|
|
100
|
+
|
|
101
|
+
- [#1420](https://github.com/OpenSaasAU/stack/pull/1420) [`7ebd6ee`](https://github.com/OpenSaasAU/stack/commit/7ebd6ee5f78f5773b566dc6cac66d73b640c3c03) Thanks [@borisno2](https://github.com/borisno2)! - Declare the Node >=22.18.0 floor in `engines`.
|
|
102
|
+
|
|
103
|
+
- [#1532](https://github.com/OpenSaasAU/stack/pull/1532) [`f9b4e2c`](https://github.com/OpenSaasAU/stack/commit/f9b4e2cd5ee2e6db5ad23ca3e13e07635291747d) Thanks [@borisno2](https://github.com/borisno2)! - Fail a package's vitest run with a named, actionable error when its `dist/` was not built from its current `src/`, instead of silently testing stale built output through a cross-package import or a spawned CLI binary.
|
|
104
|
+
|
|
105
|
+
- [#1499](https://github.com/OpenSaasAU/stack/pull/1499) [`bcea6de`](https://github.com/OpenSaasAU/stack/commit/bcea6dea0766f510da59188cb70fb41b2fd2573b) Thanks [@borisno2](https://github.com/borisno2)! - Add the missing `[key: string]: unknown` index member to `S3StorageConfig` so it matches `LocalStorageConfig` and `VercelBlobStorageConfig` and is assignable to core's `BaseStorageConfig`:
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
import type { BaseStorageConfig } from '@opensaas/stack-storage'
|
|
109
|
+
import { s3Storage } from '@opensaas/stack-storage-s3'
|
|
110
|
+
|
|
111
|
+
// Previously a type error: S3StorageConfig was not assignable to BaseStorageConfig.
|
|
112
|
+
const slot: BaseStorageConfig = s3Storage({ bucket: 'my-bucket', region: 'us-east-1' })
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
`@opensaas/stack-storage` and `@opensaas/stack-storage-vercel` each gain a test pinning their own provider config's assignability to `BaseStorageConfig`, alongside the new S3 one, so a future provider can't regress this.
|
|
116
|
+
|
|
117
|
+
- [#1848](https://github.com/OpenSaasAU/stack/pull/1848) [`1c8f2a0`](https://github.com/OpenSaasAU/stack/commit/1c8f2a0b35ca2dd167151c9c68096f9b810981c3) Thanks [@borisno2](https://github.com/borisno2)! - Peer ranges on `@opensaas/stack-core`, `@opensaas/stack-storage` and `@opensaas/stack-ui` now track the release version instead of `^0`, so a mismatched minor is flagged.
|
|
118
|
+
- Updated dependencies [[`f1ed144`](https://github.com/OpenSaasAU/stack/commit/f1ed144dd42fa69023960838b5cc28f046f48aae), [`04f4249`](https://github.com/OpenSaasAU/stack/commit/04f4249576e12894420d0ed469575ffd3bdfb46a), [`59d425f`](https://github.com/OpenSaasAU/stack/commit/59d425ffc0e474a28b540de5511e37e0ad8413a1), [`d94a2e3`](https://github.com/OpenSaasAU/stack/commit/d94a2e3dcd77cb289620818fa862bd3163e5ab59), [`e39a4b5`](https://github.com/OpenSaasAU/stack/commit/e39a4b5f9983fae97738bcba0afe6e59ba1358b4), [`7ebd6ee`](https://github.com/OpenSaasAU/stack/commit/7ebd6ee5f78f5773b566dc6cac66d73b640c3c03), [`8d8a338`](https://github.com/OpenSaasAU/stack/commit/8d8a338ea4606b03ef859c4128b93b40a5fc9a21), [`7ebd6ee`](https://github.com/OpenSaasAU/stack/commit/7ebd6ee5f78f5773b566dc6cac66d73b640c3c03), [`89c9bfe`](https://github.com/OpenSaasAU/stack/commit/89c9bfe4c28569c9f20028ee8c446e061e7d311c), [`5af6f66`](https://github.com/OpenSaasAU/stack/commit/5af6f661b6a17100c9b82952d7f86ab5d1bcde76), [`7a98565`](https://github.com/OpenSaasAU/stack/commit/7a98565c7c64106b3fa7a2a86e4571de1e2c0eaa), [`00c2208`](https://github.com/OpenSaasAU/stack/commit/00c22086b1f33a126b7010f83e8087f937860119), [`8cca21a`](https://github.com/OpenSaasAU/stack/commit/8cca21a2e681a4afed908b93802ed260290ea319), [`c322241`](https://github.com/OpenSaasAU/stack/commit/c322241a7a8a293ce6824df13dcb9765cd9479a2), [`6a843c3`](https://github.com/OpenSaasAU/stack/commit/6a843c353d59a7e228a0e9a39237310fd81d7b89), [`7ebd6ee`](https://github.com/OpenSaasAU/stack/commit/7ebd6ee5f78f5773b566dc6cac66d73b640c3c03), [`7ebd6ee`](https://github.com/OpenSaasAU/stack/commit/7ebd6ee5f78f5773b566dc6cac66d73b640c3c03), [`d118145`](https://github.com/OpenSaasAU/stack/commit/d118145ab7a98afef504d77c15ef0e0fc874b0c1), [`501decb`](https://github.com/OpenSaasAU/stack/commit/501decb746a6b6507ac22dc61dbeb9338b6ef77f), [`fd31be5`](https://github.com/OpenSaasAU/stack/commit/fd31be5389b14c6be82bade01c97d0b9df7b06a9), [`e42307c`](https://github.com/OpenSaasAU/stack/commit/e42307c02372991e8105d537ed1b3ae7c28a59cc), [`7fd56ac`](https://github.com/OpenSaasAU/stack/commit/7fd56ac747df69ecdb65e728006e55cfdc122075), [`28938cd`](https://github.com/OpenSaasAU/stack/commit/28938cde0a12bf9586d8ea0236cc4bcfbcfee093), [`c267d3c`](https://github.com/OpenSaasAU/stack/commit/c267d3c1aa2423374ae1f0b9e24e9b4f8bdf4b7c), [`6323ede`](https://github.com/OpenSaasAU/stack/commit/6323ede4e1bbcd9c6ddb4ad7dd95b0f08c289cf5), [`bb37e04`](https://github.com/OpenSaasAU/stack/commit/bb37e04003946eea4396efc90d42d067de6276e3), [`f9b4e2c`](https://github.com/OpenSaasAU/stack/commit/f9b4e2cd5ee2e6db5ad23ca3e13e07635291747d), [`6cfe96c`](https://github.com/OpenSaasAU/stack/commit/6cfe96c248889a268b9505178db1da9b177dafe6), [`7ebd6ee`](https://github.com/OpenSaasAU/stack/commit/7ebd6ee5f78f5773b566dc6cac66d73b640c3c03), [`bcea6de`](https://github.com/OpenSaasAU/stack/commit/bcea6dea0766f510da59188cb70fb41b2fd2573b), [`1c8f2a0`](https://github.com/OpenSaasAU/stack/commit/1c8f2a0b35ca2dd167151c9c68096f9b810981c3), [`2513063`](https://github.com/OpenSaasAU/stack/commit/2513063606b7ef3f8135c323b24c653415c56740)]:
|
|
119
|
+
- @opensaas/stack-storage@0.44.0-alpha.0
|
|
120
|
+
|
|
121
|
+
## 0.43.0
|
|
122
|
+
|
|
3
123
|
## 0.42.3
|
|
4
124
|
|
|
5
125
|
## 0.42.2
|
package/README.md
CHANGED
|
@@ -48,7 +48,11 @@ vercelBlobStorage({
|
|
|
48
48
|
allowOverwrite?: boolean // Allow overwriting an existing blob at the same pathname
|
|
49
49
|
// (default: true when generateUniqueFilenames is false, false otherwise)
|
|
50
50
|
public?: boolean // Make files publicly accessible (default: true)
|
|
51
|
-
|
|
51
|
+
cacheControlMaxAge?: number // Cache max-age in SECONDS. Left unset the provider sends
|
|
52
|
+
// nothing and @vercel/blob applies its own default of one
|
|
53
|
+
// year. There is no `cacheControl` string option — and
|
|
54
|
+
// because this config carries an index signature, that
|
|
55
|
+
// misspelling type-checks and is silently ignored.
|
|
52
56
|
})
|
|
53
57
|
```
|
|
54
58
|
|
|
@@ -160,7 +164,7 @@ Private blobs aren't fetchable via their plain URL — `provider.download(filena
|
|
|
160
164
|
```typescript
|
|
161
165
|
images: vercelBlobStorage({
|
|
162
166
|
pathPrefix: 'images',
|
|
163
|
-
|
|
167
|
+
cacheControlMaxAge: 86400, // seconds — 1 day
|
|
164
168
|
})
|
|
165
169
|
```
|
|
166
170
|
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAoB3F,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,aAAa,CAAA;IACnB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,2DAA2D;IAC3D,uBAAuB,CAAC,EAAE,OAAO,CAAA;IACjC;;;;;OAKG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,yCAAyC;IACzC,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,kEAAkE;IAClE,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,4EAA4E;IAC5E,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,kCAAkC;IAClC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAA;AAoB3F,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,aAAa,CAAA;IACnB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,2DAA2D;IAC3D,uBAAuB,CAAC,EAAE,OAAO,CAAA;IACjC;;;;;OAKG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,yCAAyC;IACzC,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,kEAAkE;IAClE,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,4EAA4E;IAC5E,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,kCAAkC;IAClC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAOD,qBAAa,yBAA0B,YAAW,eAAe;IAC/D,OAAO,CAAC,MAAM,CAAyB;IAEvC,YAAY,MAAM,EAAE,uBAAuB,EAM1C;IAED;;;;OAIG;IACH,OAAO,CAAC,WAAW;IAQnB,OAAO,CAAC,gBAAgB;IAWxB,OAAO,CAAC,WAAW;IAYnB;;;;;;;OAOG;IACH,OAAO,CAAC,qBAAqB;IAO7B;;;;OAIG;IACH,OAAO,CAAC,SAAS;IAIjB;;;;;;OAMG;IACH,OAAO,CAAC,cAAc;IAmChB,MAAM,CACV,IAAI,EAAE,MAAM,GAAG,UAAU,EACzB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,YAAY,CAAC,CAkCvB;IAEK,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAkBhD;IAEK,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAU5C;IAED,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAM/B;IAEK,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,GAAE,MAAa,GAAG,OAAO,CAAC,MAAM,CAAC,CAyB9E;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,IAAI,CAAC,uBAAuB,EAAE,MAAM,CAAC,GAC5C,uBAAuB,CAOzB"}
|
package/dist/index.js
CHANGED
|
@@ -17,6 +17,11 @@ function parseStoreIdFromToken(token) {
|
|
|
17
17
|
function normalizeStoreId(storeId) {
|
|
18
18
|
return storeId.startsWith('store_') ? storeId.slice('store_'.length) : storeId;
|
|
19
19
|
}
|
|
20
|
+
function isPlainFilename(name) {
|
|
21
|
+
if (name === '' || name === '.' || name === '..')
|
|
22
|
+
return false;
|
|
23
|
+
return !/[/\\\0]/.test(name);
|
|
24
|
+
}
|
|
20
25
|
export class VercelBlobStorageProvider {
|
|
21
26
|
config;
|
|
22
27
|
constructor(config) {
|
|
@@ -43,7 +48,7 @@ export class VercelBlobStorageProvider {
|
|
|
43
48
|
}
|
|
44
49
|
generateFilename(originalFilename) {
|
|
45
50
|
if (this.config.generateUniqueFilenames === false) {
|
|
46
|
-
return originalFilename;
|
|
51
|
+
return originalFilename.replace(/\0/g, '').split(/[/\\]/).pop() ?? '';
|
|
47
52
|
}
|
|
48
53
|
const ext = path.extname(originalFilename);
|
|
49
54
|
const uniqueId = randomBytes(16).toString('hex');
|
|
@@ -51,6 +56,9 @@ export class VercelBlobStorageProvider {
|
|
|
51
56
|
return `${timestamp}-${uniqueId}${ext}`;
|
|
52
57
|
}
|
|
53
58
|
getFullPath(filename) {
|
|
59
|
+
if (!isPlainFilename(filename)) {
|
|
60
|
+
throw new Error(`VercelBlobStorageProvider refused a pathname outside the configured prefix: ${JSON.stringify(filename)}`);
|
|
61
|
+
}
|
|
54
62
|
if (this.config.pathPrefix) {
|
|
55
63
|
return `${this.config.pathPrefix}/${filename}`;
|
|
56
64
|
}
|
|
@@ -167,7 +175,9 @@ export class VercelBlobStorageProvider {
|
|
|
167
175
|
}
|
|
168
176
|
}
|
|
169
177
|
getUrl(filename) {
|
|
170
|
-
|
|
178
|
+
this.getFullPath(filename);
|
|
179
|
+
const encoded = filename.replace(/%/g, '%25');
|
|
180
|
+
const pathname = this.config.pathPrefix ? `${this.config.pathPrefix}/${encoded}` : encoded;
|
|
171
181
|
const storeId = this.resolveStoreId();
|
|
172
182
|
return `https://${storeId}.${this.getAccess()}.blob.vercel-storage.com/${pathname}`;
|
|
173
183
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version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EAAE,aAAa;QACnB,uBAAuB,EAAE,IAAI;QAC7B,MAAM,EAAE,IAAI;QACZ,GAAG,MAAM;KACV,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opensaas/stack-storage-vercel",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.44.0-alpha.1",
|
|
4
4
|
"description": "Vercel Blob storage provider for OpenSaas Stack file uploads",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=22.18.0"
|
|
8
|
+
},
|
|
6
9
|
"exports": {
|
|
7
10
|
".": {
|
|
8
11
|
"types": "./dist/index.d.ts",
|
|
@@ -11,19 +14,26 @@
|
|
|
11
14
|
},
|
|
12
15
|
"main": "./dist/index.js",
|
|
13
16
|
"types": "./dist/index.d.ts",
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"!dist/**/*.test.*",
|
|
20
|
+
"!dist/**/__tests__",
|
|
21
|
+
"README.md",
|
|
22
|
+
"CHANGELOG.md"
|
|
23
|
+
],
|
|
14
24
|
"dependencies": {
|
|
15
25
|
"@vercel/blob": "^2.8.0"
|
|
16
26
|
},
|
|
17
27
|
"devDependencies": {
|
|
18
|
-
"@types/node": "^26.
|
|
28
|
+
"@types/node": "^26.6.3",
|
|
19
29
|
"@typescript/native": "npm:typescript@^7.0.2",
|
|
20
|
-
"@vitest/coverage-v8": "
|
|
30
|
+
"@vitest/coverage-v8": "5.0.5",
|
|
21
31
|
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
22
|
-
"vitest": "
|
|
23
|
-
"@opensaas/stack-storage": "0.
|
|
32
|
+
"vitest": "5.0.5",
|
|
33
|
+
"@opensaas/stack-storage": "0.44.0-alpha.1"
|
|
24
34
|
},
|
|
25
35
|
"peerDependencies": {
|
|
26
|
-
"@opensaas/stack-storage": "^0"
|
|
36
|
+
"@opensaas/stack-storage": "^0.44.0-alpha.1"
|
|
27
37
|
},
|
|
28
38
|
"repository": {
|
|
29
39
|
"type": "git",
|
|
@@ -37,6 +47,7 @@
|
|
|
37
47
|
"scripts": {
|
|
38
48
|
"build": "tsc",
|
|
39
49
|
"dev": "tsc --watch",
|
|
50
|
+
"typecheck": "tsc -p tsconfig.test.json",
|
|
40
51
|
"test": "vitest run",
|
|
41
52
|
"test:ui": "vitest --ui",
|
|
42
53
|
"test:coverage": "vitest run --coverage"
|
package/.turbo/turbo-build.log
DELETED
package/src/index.ts
DELETED
|
@@ -1,312 +0,0 @@
|
|
|
1
|
-
import { put, del, get, issueSignedToken, presignUrl, BlobNotFoundError } from '@vercel/blob'
|
|
2
|
-
import type { PutCommandOptions } from '@vercel/blob'
|
|
3
|
-
import { randomBytes } from 'node:crypto'
|
|
4
|
-
import path from 'node:path'
|
|
5
|
-
import type { StorageProvider, UploadOptions, UploadResult } from '@opensaas/stack-storage'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Derives the store ID embedded in a Vercel Blob read-write token
|
|
9
|
-
* (`vercel_blob_rw_<storeId>_<secret>`), the same way `@vercel/blob` derives
|
|
10
|
-
* it internally to build blob URLs. This format is undocumented and not a
|
|
11
|
-
* stable public API — it's parity with the SDK's internal parsing, not a
|
|
12
|
-
* contract Vercel guarantees. Returns `''` if the token doesn't match the
|
|
13
|
-
* expected shape.
|
|
14
|
-
*/
|
|
15
|
-
function parseStoreIdFromToken(token: string): string {
|
|
16
|
-
const segments = token.split('_')
|
|
17
|
-
return segments.length >= 4 ? segments[3] : ''
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/** Strips the `store_` prefix some store ID values are given with. */
|
|
21
|
-
function normalizeStoreId(storeId: string): string {
|
|
22
|
-
return storeId.startsWith('store_') ? storeId.slice('store_'.length) : storeId
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface VercelBlobStorageConfig {
|
|
26
|
-
type: 'vercel-blob'
|
|
27
|
-
/**
|
|
28
|
-
* Vercel Blob read-write token (can also be set via BLOB_READ_WRITE_TOKEN env var).
|
|
29
|
-
* Optional when using Vercel OIDC auth (`storeId`/`BLOB_STORE_ID`).
|
|
30
|
-
*/
|
|
31
|
-
token?: string
|
|
32
|
-
/**
|
|
33
|
-
* Blob store id for Vercel OIDC auth (overrides the BLOB_STORE_ID env var).
|
|
34
|
-
* When an OIDC token is available (VERCEL_OIDC_TOKEN or `oidcToken`) and a
|
|
35
|
-
* store id is set, no static read-write token is needed.
|
|
36
|
-
*/
|
|
37
|
-
storeId?: string
|
|
38
|
-
/**
|
|
39
|
-
* Explicit Vercel OIDC token (overrides the VERCEL_OIDC_TOKEN env var).
|
|
40
|
-
* Requires `storeId` or BLOB_STORE_ID.
|
|
41
|
-
*/
|
|
42
|
-
oidcToken?: string
|
|
43
|
-
/** Whether to generate unique filenames (default: true) */
|
|
44
|
-
generateUniqueFilenames?: boolean
|
|
45
|
-
/**
|
|
46
|
-
* Whether to allow overwriting an existing blob at the same pathname.
|
|
47
|
-
* The Blob API rejects overwrites unless this is sent. Defaults to `true`
|
|
48
|
-
* when `generateUniqueFilenames` is `false` (stable filenames imply replace
|
|
49
|
-
* semantics), and `false` otherwise. An explicit setting always wins.
|
|
50
|
-
*/
|
|
51
|
-
allowOverwrite?: boolean
|
|
52
|
-
/** Path prefix for all uploaded files */
|
|
53
|
-
pathPrefix?: string
|
|
54
|
-
/** Whether files should be publicly accessible (default: true) */
|
|
55
|
-
public?: boolean
|
|
56
|
-
/** Cache control header (default: 'public, max-age=31536000, immutable') */
|
|
57
|
-
cacheControlMaxAge?: number
|
|
58
|
-
/** Allow additional properties */
|
|
59
|
-
[key: string]: unknown
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export class VercelBlobStorageProvider implements StorageProvider {
|
|
63
|
-
private config: VercelBlobStorageConfig
|
|
64
|
-
|
|
65
|
-
constructor(config: VercelBlobStorageConfig) {
|
|
66
|
-
this.config = config
|
|
67
|
-
// Credential resolution is delegated to the @vercel/blob SDK at call time.
|
|
68
|
-
// Eagerly requiring a static token here would break Vercel OIDC auth, where
|
|
69
|
-
// no token/BLOB_READ_WRITE_TOKEN exists and the SDK resolves credentials
|
|
70
|
-
// from VERCEL_OIDC_TOKEN (or the request context) plus storeId/BLOB_STORE_ID.
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Credential options passed to every SDK call. The SDK's precedence is:
|
|
75
|
-
* explicit `token` → OIDC token + store id → BLOB_READ_WRITE_TOKEN env var;
|
|
76
|
-
* it throws a descriptive error when none of these are available.
|
|
77
|
-
*/
|
|
78
|
-
private authOptions(): { token?: string; storeId?: string; oidcToken?: string } {
|
|
79
|
-
const auth: { token?: string; storeId?: string; oidcToken?: string } = {}
|
|
80
|
-
if (this.config.token) auth.token = this.config.token
|
|
81
|
-
if (this.config.storeId) auth.storeId = this.config.storeId
|
|
82
|
-
if (this.config.oidcToken) auth.oidcToken = this.config.oidcToken
|
|
83
|
-
return auth
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
private generateFilename(originalFilename: string): string {
|
|
87
|
-
if (this.config.generateUniqueFilenames === false) {
|
|
88
|
-
return originalFilename
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const ext = path.extname(originalFilename)
|
|
92
|
-
const uniqueId = randomBytes(16).toString('hex')
|
|
93
|
-
const timestamp = Date.now()
|
|
94
|
-
return `${timestamp}-${uniqueId}${ext}`
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
private getFullPath(filename: string): string {
|
|
98
|
-
if (this.config.pathPrefix) {
|
|
99
|
-
return `${this.config.pathPrefix}/${filename}`
|
|
100
|
-
}
|
|
101
|
-
return filename
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Resolves whether uploads may overwrite an existing blob at the same
|
|
106
|
-
* pathname. An explicit `allowOverwrite` always wins; otherwise stable
|
|
107
|
-
* filenames (`generateUniqueFilenames: false`) imply replace semantics and
|
|
108
|
-
* default to `true`. With generated filenames collisions aren't expected,
|
|
109
|
-
* so the key is left unset and the Blob API's own reject-by-default
|
|
110
|
-
* behavior applies.
|
|
111
|
-
*/
|
|
112
|
-
private resolveAllowOverwrite(): boolean | undefined {
|
|
113
|
-
if (this.config.allowOverwrite !== undefined) {
|
|
114
|
-
return this.config.allowOverwrite
|
|
115
|
-
}
|
|
116
|
-
return this.config.generateUniqueFilenames === false ? true : undefined
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Resolves the blob access level for this provider instance.
|
|
121
|
-
* `public` is a provider-wide config setting, so every blob uploaded
|
|
122
|
-
* (and later read) through this instance uses the same access level.
|
|
123
|
-
*/
|
|
124
|
-
private getAccess(): 'public' | 'private' {
|
|
125
|
-
return this.config.public !== false ? 'public' : 'private'
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Resolves the Vercel Blob store ID used to construct blob URLs, mirroring
|
|
130
|
-
* the SDK's own credential precedence: an explicit read-write token wins
|
|
131
|
-
* (its embedded store ID is authoritative), otherwise an explicit/env store
|
|
132
|
-
* ID is used, otherwise the store ID is parsed from the env read-write
|
|
133
|
-
* token.
|
|
134
|
-
*/
|
|
135
|
-
private resolveStoreId(): string {
|
|
136
|
-
const token = this.config.token ?? process.env.BLOB_READ_WRITE_TOKEN?.trim()
|
|
137
|
-
if (this.config.token) {
|
|
138
|
-
const storeId = parseStoreIdFromToken(this.config.token)
|
|
139
|
-
if (!storeId) {
|
|
140
|
-
throw new Error(
|
|
141
|
-
'Cannot determine the Vercel Blob store ID: the configured `token` does not match the ' +
|
|
142
|
-
'expected "vercel_blob_rw_<storeId>_<secret>" format. Pass `storeId` explicitly to construct blob URLs.',
|
|
143
|
-
)
|
|
144
|
-
}
|
|
145
|
-
return storeId
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
const storeId = this.config.storeId?.trim() || process.env.BLOB_STORE_ID?.trim()
|
|
149
|
-
if (storeId) {
|
|
150
|
-
return normalizeStoreId(storeId)
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if (token) {
|
|
154
|
-
const parsedStoreId = parseStoreIdFromToken(token)
|
|
155
|
-
if (!parsedStoreId) {
|
|
156
|
-
throw new Error(
|
|
157
|
-
'Cannot determine the Vercel Blob store ID: BLOB_READ_WRITE_TOKEN does not match the ' +
|
|
158
|
-
'expected "vercel_blob_rw_<storeId>_<secret>" format. Pass `storeId` explicitly to construct blob URLs.',
|
|
159
|
-
)
|
|
160
|
-
}
|
|
161
|
-
return parsedStoreId
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
throw new Error(
|
|
165
|
-
'Cannot determine the Vercel Blob store ID: configure `token`, `storeId`, BLOB_STORE_ID, or ' +
|
|
166
|
-
'BLOB_READ_WRITE_TOKEN to construct blob URLs.',
|
|
167
|
-
)
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
async upload(
|
|
171
|
-
file: Buffer | Uint8Array,
|
|
172
|
-
filename: string,
|
|
173
|
-
options?: UploadOptions,
|
|
174
|
-
): Promise<UploadResult> {
|
|
175
|
-
const generatedFilename = this.generateFilename(filename)
|
|
176
|
-
const pathname = this.getFullPath(generatedFilename)
|
|
177
|
-
|
|
178
|
-
const buffer = Buffer.isBuffer(file) ? file : Buffer.from(file)
|
|
179
|
-
|
|
180
|
-
const uploadOptions: PutCommandOptions = {
|
|
181
|
-
access: this.getAccess(),
|
|
182
|
-
contentType: options?.contentType,
|
|
183
|
-
...this.authOptions(),
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
if (this.config.cacheControlMaxAge !== undefined) {
|
|
187
|
-
uploadOptions.cacheControlMaxAge = this.config.cacheControlMaxAge
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
const allowOverwrite = this.resolveAllowOverwrite()
|
|
191
|
-
if (allowOverwrite !== undefined) {
|
|
192
|
-
uploadOptions.allowOverwrite = allowOverwrite
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
const blob = await put(pathname, buffer, uploadOptions)
|
|
196
|
-
|
|
197
|
-
return {
|
|
198
|
-
filename: generatedFilename,
|
|
199
|
-
url: blob.url,
|
|
200
|
-
size: file.length,
|
|
201
|
-
contentType: options?.contentType || 'application/octet-stream',
|
|
202
|
-
metadata: {
|
|
203
|
-
...options?.metadata,
|
|
204
|
-
downloadUrl: blob.downloadUrl,
|
|
205
|
-
pathname: blob.pathname,
|
|
206
|
-
},
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
async download(filename: string): Promise<Buffer> {
|
|
211
|
-
const pathname = this.getFullPath(filename)
|
|
212
|
-
|
|
213
|
-
// Fetch the blob content through the SDK's authorized read path. This
|
|
214
|
-
// works for both public and private blobs (private blobs cannot be
|
|
215
|
-
// read via a plain `fetch(url)`, since the request needs a bearer
|
|
216
|
-
// token) and resolves `null` for a missing blob instead of throwing.
|
|
217
|
-
const result = await get(pathname, {
|
|
218
|
-
access: this.getAccess(),
|
|
219
|
-
...this.authOptions(),
|
|
220
|
-
})
|
|
221
|
-
|
|
222
|
-
if (!result) {
|
|
223
|
-
throw new Error(`File not found: ${filename}`)
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
const arrayBuffer = await new Response(result.stream).arrayBuffer()
|
|
227
|
-
return Buffer.from(arrayBuffer)
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
async delete(filename: string): Promise<void> {
|
|
231
|
-
const pathname = this.getFullPath(filename)
|
|
232
|
-
|
|
233
|
-
try {
|
|
234
|
-
await del(pathname, this.authOptions())
|
|
235
|
-
} catch (error) {
|
|
236
|
-
if (!(error instanceof BlobNotFoundError)) {
|
|
237
|
-
throw error
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
getUrl(filename: string): string {
|
|
243
|
-
const pathname = this.getFullPath(filename)
|
|
244
|
-
const storeId = this.resolveStoreId()
|
|
245
|
-
return `https://${storeId}.${this.getAccess()}.blob.vercel-storage.com/${pathname}`
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
async getSignedUrl(filename: string, expiresIn: number = 3600): Promise<string> {
|
|
249
|
-
const pathname = this.getFullPath(filename)
|
|
250
|
-
const validUntil = Date.now() + expiresIn * 1000
|
|
251
|
-
|
|
252
|
-
const signedToken = await issueSignedToken({
|
|
253
|
-
pathname,
|
|
254
|
-
operations: ['get'],
|
|
255
|
-
validUntil,
|
|
256
|
-
...this.authOptions(),
|
|
257
|
-
})
|
|
258
|
-
|
|
259
|
-
const { presignedUrl } = await presignUrl(
|
|
260
|
-
{
|
|
261
|
-
delegationToken: signedToken.delegationToken,
|
|
262
|
-
clientSigningToken: signedToken.clientSigningToken,
|
|
263
|
-
},
|
|
264
|
-
{
|
|
265
|
-
operation: 'get',
|
|
266
|
-
pathname,
|
|
267
|
-
validUntil,
|
|
268
|
-
access: this.getAccess(),
|
|
269
|
-
},
|
|
270
|
-
)
|
|
271
|
-
|
|
272
|
-
return presignedUrl
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* Creates a Vercel Blob storage configuration
|
|
278
|
-
*
|
|
279
|
-
* @example
|
|
280
|
-
* ```typescript
|
|
281
|
-
* // Static read-write token
|
|
282
|
-
* const config = config({
|
|
283
|
-
* storage: {
|
|
284
|
-
* avatars: vercelBlobStorage({
|
|
285
|
-
* token: process.env.BLOB_READ_WRITE_TOKEN,
|
|
286
|
-
* pathPrefix: 'avatars',
|
|
287
|
-
* }),
|
|
288
|
-
* },
|
|
289
|
-
* })
|
|
290
|
-
*
|
|
291
|
-
* // Vercel OIDC auth — no static token; the SDK resolves credentials from
|
|
292
|
-
* // VERCEL_OIDC_TOKEN plus the store id (config.storeId or BLOB_STORE_ID env)
|
|
293
|
-
* const config = config({
|
|
294
|
-
* storage: {
|
|
295
|
-
* avatars: vercelBlobStorage({
|
|
296
|
-
* storeId: process.env.BLOB_STORE_ID,
|
|
297
|
-
* pathPrefix: 'avatars',
|
|
298
|
-
* }),
|
|
299
|
-
* },
|
|
300
|
-
* })
|
|
301
|
-
* ```
|
|
302
|
-
*/
|
|
303
|
-
export function vercelBlobStorage(
|
|
304
|
-
config: Omit<VercelBlobStorageConfig, 'type'>,
|
|
305
|
-
): VercelBlobStorageConfig {
|
|
306
|
-
return {
|
|
307
|
-
type: 'vercel-blob',
|
|
308
|
-
generateUniqueFilenames: true,
|
|
309
|
-
public: true,
|
|
310
|
-
...config,
|
|
311
|
-
}
|
|
312
|
-
}
|