@easy-cms/storage-vercel-blob 0.37.0 → 0.37.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.
Files changed (2) hide show
  1. package/dist/index.js +14 -5
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  // src/index.ts
2
+ import { EasyCMSError } from "@easy-cms/core";
2
3
  import { del, get, put } from "@vercel/blob";
3
4
  function storeIdOf(token) {
4
5
  const id = token.split("_")[3] ?? "";
@@ -8,9 +9,14 @@ function storeIdOf(token) {
8
9
  function vercelBlobStorage(options = {}, client = { put, del, get }) {
9
10
  const access = options.access ?? "public";
10
11
  const prefix = options.prefix ?? "";
12
+ const configured = () => options.token ?? process.env.BLOB_READ_WRITE_TOKEN;
11
13
  const token = () => {
12
- const value = options.token ?? process.env.BLOB_READ_WRITE_TOKEN;
13
- if (!value) throw new Error("Vercel Blob: set BLOB_READ_WRITE_TOKEN (connect a Blob store)");
14
+ const value = configured();
15
+ if (!value)
16
+ throw new EasyCMSError(
17
+ "Uploads need a Vercel Blob store: connect one to the project (Storage \u2192 Blob), which sets BLOB_READ_WRITE_TOKEN, then redeploy",
18
+ 503
19
+ );
14
20
  return value;
15
21
  };
16
22
  return {
@@ -24,7 +30,9 @@ function vercelBlobStorage(options = {}, client = { put, del, get }) {
24
30
  });
25
31
  },
26
32
  async get(key) {
27
- const found = await client.get(`${prefix}${key}`, { access, token: token() });
33
+ const value = configured();
34
+ if (!value) return null;
35
+ const found = await client.get(`${prefix}${key}`, { access, token: value });
28
36
  if (found?.statusCode !== 200) return null;
29
37
  const body = new Uint8Array(await new Response(found.stream).arrayBuffer());
30
38
  return { body, size: body.byteLength };
@@ -33,8 +41,9 @@ function vercelBlobStorage(options = {}, client = { put, del, get }) {
33
41
  await client.del(`${prefix}${key}`, { token: token() });
34
42
  },
35
43
  url(key) {
36
- if (access !== "public") return void 0;
37
- return `https://${storeIdOf(token())}.public.blob.vercel-storage.com/${prefix}${key}`;
44
+ const value = configured();
45
+ if (access !== "public" || !value) return void 0;
46
+ return `https://${storeIdOf(value)}.public.blob.vercel-storage.com/${prefix}${key}`;
38
47
  }
39
48
  };
40
49
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easy-cms/storage-vercel-blob",
3
- "version": "0.37.0",
3
+ "version": "0.37.1",
4
4
  "description": "Vercel Blob upload storage for Easy CMS",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -19,10 +19,10 @@
19
19
  "@vercel/blob": "^2.8.0"
20
20
  },
21
21
  "peerDependencies": {
22
- "@easy-cms/core": "^0.37.0"
22
+ "@easy-cms/core": "^0.37.1"
23
23
  },
24
24
  "devDependencies": {
25
- "@easy-cms/core": "^0.37.0"
25
+ "@easy-cms/core": "^0.37.1"
26
26
  },
27
27
  "engines": {
28
28
  "node": ">=22.12"