@airnauts/comments-storage-vercel-blob 0.1.0 → 0.2.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/README.md CHANGED
@@ -12,11 +12,15 @@ pnpm add @airnauts/comments-storage-vercel-blob
12
12
  ## Usage
13
13
 
14
14
  ```ts
15
- import { VercelBlobStorage } from '@airnauts/comments-storage-vercel-blob'
15
+ import { vercelBlobStorage } from '@airnauts/comments-storage-vercel-blob'
16
16
 
17
- const storage = new VercelBlobStorage() // reads BLOB_READ_WRITE_TOKEN
17
+ const storage = vercelBlobStorage({ token: process.env.BLOB_READ_WRITE_TOKEN! })
18
18
  ```
19
19
 
20
+ The token is passed explicitly — the adapter never reads `process.env` itself. Pass
21
+ an optional `prefix` (e.g. `'staging/'`) to namespace keys. The `VercelBlobStorage`
22
+ class is also exported if you prefer `new VercelBlobStorage(opts)`.
23
+
20
24
  Pass `storage` to `createCommentsServer` from `@airnauts/comments-server`.
21
25
 
22
26
  ## License
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { PutBlob, PutResult, StorageAdapter } from '@airnauts/comments-server';
2
2
  export type VercelBlobStorageOptions = {
3
- /** `BLOB_READ_WRITE_TOKEN`. If omitted, `@vercel/blob` reads it from `process.env`. */
4
- token?: string;
3
+ /** `BLOB_READ_WRITE_TOKEN`, passed explicitly (no ambient `process.env` read). */
4
+ token: string;
5
5
  /**
6
6
  * Optional prefix (e.g. 'staging/') applied to every key. A trailing `/` is
7
7
  * appended automatically if missing, so `'staging'` and `'staging/'` behave
@@ -12,10 +12,10 @@ export type VercelBlobStorageOptions = {
12
12
  export declare class VercelBlobStorage implements StorageAdapter {
13
13
  private readonly opts;
14
14
  private readonly prefix;
15
- constructor(opts?: VercelBlobStorageOptions);
15
+ constructor(opts: VercelBlobStorageOptions);
16
16
  put(blob: PutBlob): Promise<PutResult>;
17
17
  }
18
18
  /** Construct a Vercel Blob `StorageAdapter` (uniform `xxxStorage(config)` shape). */
19
- export declare function vercelBlobStorage(opts?: VercelBlobStorageOptions): StorageAdapter;
19
+ export declare function vercelBlobStorage(opts: VercelBlobStorageOptions): StorageAdapter;
20
20
  export declare const packageName = "@airnauts/comments-storage-vercel-blob";
21
21
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAGnF,MAAM,MAAM,wBAAwB,GAAG;IACrC,uFAAuF;IACvF,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAiCD,qBAAa,iBAAkB,YAAW,cAAc;IAG1C,OAAO,CAAC,QAAQ,CAAC,IAAI;IAFjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;gBAEF,IAAI,GAAE,wBAA6B;IAK1D,GAAG,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC;CAgB7C;AAED,qFAAqF;AACrF,wBAAgB,iBAAiB,CAAC,IAAI,GAAE,wBAA6B,GAAG,cAAc,CAErF;AAED,eAAO,MAAM,WAAW,2CAA2C,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAGnF,MAAM,MAAM,wBAAwB,GAAG;IACrC,kFAAkF;IAClF,KAAK,EAAE,MAAM,CAAA;IACb;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAiCD,qBAAa,iBAAkB,YAAW,cAAc;IAG1C,OAAO,CAAC,QAAQ,CAAC,IAAI;IAFjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;gBAEF,IAAI,EAAE,wBAAwB;IAKrD,GAAG,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC;CAgB7C;AAED,qFAAqF;AACrF,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,wBAAwB,GAAG,cAAc,CAEhF;AAED,eAAO,MAAM,WAAW,2CAA2C,CAAA"}
package/dist/index.js CHANGED
@@ -30,7 +30,7 @@ async function readAllBytes(data) {
30
30
  return out;
31
31
  }
32
32
  var VercelBlobStorage = class {
33
- constructor(opts = {}) {
33
+ constructor(opts) {
34
34
  this.opts = opts;
35
35
  const raw = opts.prefix ?? "";
36
36
  this.prefix = raw === "" || raw.endsWith("/") ? raw : `${raw}/`;
@@ -54,7 +54,7 @@ var VercelBlobStorage = class {
54
54
  };
55
55
  }
56
56
  };
57
- function vercelBlobStorage(opts = {}) {
57
+ function vercelBlobStorage(opts) {
58
58
  return new VercelBlobStorage(opts);
59
59
  }
60
60
  var packageName = "@airnauts/comments-storage-vercel-blob";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { PutBlob, PutResult, StorageAdapter } from '@airnauts/comments-server'\nimport { put } from '@vercel/blob'\n\nexport type VercelBlobStorageOptions = {\n /** `BLOB_READ_WRITE_TOKEN`. If omitted, `@vercel/blob` reads it from `process.env`. */\n token?: string\n /**\n * Optional prefix (e.g. 'staging/') applied to every key. A trailing `/` is\n * appended automatically if missing, so `'staging'` and `'staging/'` behave\n * the same way.\n */\n prefix?: string\n}\n\nfunction sanitizeName(name: string): string {\n const cleaned = name.replace(/[^A-Za-z0-9._-]/g, '_').slice(0, 200)\n return cleaned.length > 0 ? cleaned : 'file'\n}\n\nasync function readAllBytes(data: Uint8Array | ReadableStream<Uint8Array>): Promise<Uint8Array> {\n if (data instanceof Uint8Array) return data\n const reader = data.getReader()\n const chunks: Uint8Array[] = []\n let total = 0\n try {\n for (;;) {\n const { value, done } = await reader.read()\n if (done) break\n if (value) {\n chunks.push(value)\n total += value.byteLength\n }\n }\n } finally {\n reader.releaseLock()\n }\n const out = new Uint8Array(total)\n let offset = 0\n for (const c of chunks) {\n out.set(c, offset)\n offset += c.byteLength\n }\n return out\n}\n\nexport class VercelBlobStorage implements StorageAdapter {\n private readonly prefix: string\n\n constructor(private readonly opts: VercelBlobStorageOptions = {}) {\n const raw = opts.prefix ?? ''\n this.prefix = raw === '' || raw.endsWith('/') ? raw : `${raw}/`\n }\n\n async put(blob: PutBlob): Promise<PutResult> {\n const bytes = await readAllBytes(blob.data)\n const body = new Blob([bytes], { type: blob.contentType })\n const key = `${this.prefix}${sanitizeName(blob.name)}`\n const result = await put(key, body, {\n access: 'public',\n contentType: blob.contentType,\n addRandomSuffix: true,\n token: this.opts.token,\n })\n return {\n key: result.pathname,\n url: result.url,\n size: bytes.byteLength,\n }\n }\n}\n\n/** Construct a Vercel Blob `StorageAdapter` (uniform `xxxStorage(config)` shape). */\nexport function vercelBlobStorage(opts: VercelBlobStorageOptions = {}): StorageAdapter {\n return new VercelBlobStorage(opts)\n}\n\nexport const packageName = '@airnauts/comments-storage-vercel-blob'\n"],"mappings":";AACA,SAAS,WAAW;AAapB,SAAS,aAAa,MAAsB;AAC1C,QAAM,UAAU,KAAK,QAAQ,oBAAoB,GAAG,EAAE,MAAM,GAAG,GAAG;AAClE,SAAO,QAAQ,SAAS,IAAI,UAAU;AACxC;AAEA,eAAe,aAAa,MAAoE;AAC9F,MAAI,gBAAgB,WAAY,QAAO;AACvC,QAAM,SAAS,KAAK,UAAU;AAC9B,QAAM,SAAuB,CAAC;AAC9B,MAAI,QAAQ;AACZ,MAAI;AACF,eAAS;AACP,YAAM,EAAE,OAAO,KAAK,IAAI,MAAM,OAAO,KAAK;AAC1C,UAAI,KAAM;AACV,UAAI,OAAO;AACT,eAAO,KAAK,KAAK;AACjB,iBAAS,MAAM;AAAA,MACjB;AAAA,IACF;AAAA,EACF,UAAE;AACA,WAAO,YAAY;AAAA,EACrB;AACA,QAAM,MAAM,IAAI,WAAW,KAAK;AAChC,MAAI,SAAS;AACb,aAAW,KAAK,QAAQ;AACtB,QAAI,IAAI,GAAG,MAAM;AACjB,cAAU,EAAE;AAAA,EACd;AACA,SAAO;AACT;AAEO,IAAM,oBAAN,MAAkD;AAAA,EAGvD,YAA6B,OAAiC,CAAC,GAAG;AAArC;AAC3B,UAAM,MAAM,KAAK,UAAU;AAC3B,SAAK,SAAS,QAAQ,MAAM,IAAI,SAAS,GAAG,IAAI,MAAM,GAAG,GAAG;AAAA,EAC9D;AAAA,EAH6B;AAAA,EAFZ;AAAA,EAOjB,MAAM,IAAI,MAAmC;AAC3C,UAAM,QAAQ,MAAM,aAAa,KAAK,IAAI;AAC1C,UAAM,OAAO,IAAI,KAAK,CAAC,KAAK,GAAG,EAAE,MAAM,KAAK,YAAY,CAAC;AACzD,UAAM,MAAM,GAAG,KAAK,MAAM,GAAG,aAAa,KAAK,IAAI,CAAC;AACpD,UAAM,SAAS,MAAM,IAAI,KAAK,MAAM;AAAA,MAClC,QAAQ;AAAA,MACR,aAAa,KAAK;AAAA,MAClB,iBAAiB;AAAA,MACjB,OAAO,KAAK,KAAK;AAAA,IACnB,CAAC;AACD,WAAO;AAAA,MACL,KAAK,OAAO;AAAA,MACZ,KAAK,OAAO;AAAA,MACZ,MAAM,MAAM;AAAA,IACd;AAAA,EACF;AACF;AAGO,SAAS,kBAAkB,OAAiC,CAAC,GAAmB;AACrF,SAAO,IAAI,kBAAkB,IAAI;AACnC;AAEO,IAAM,cAAc;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { PutBlob, PutResult, StorageAdapter } from '@airnauts/comments-server'\nimport { put } from '@vercel/blob'\n\nexport type VercelBlobStorageOptions = {\n /** `BLOB_READ_WRITE_TOKEN`, passed explicitly (no ambient `process.env` read). */\n token: string\n /**\n * Optional prefix (e.g. 'staging/') applied to every key. A trailing `/` is\n * appended automatically if missing, so `'staging'` and `'staging/'` behave\n * the same way.\n */\n prefix?: string\n}\n\nfunction sanitizeName(name: string): string {\n const cleaned = name.replace(/[^A-Za-z0-9._-]/g, '_').slice(0, 200)\n return cleaned.length > 0 ? cleaned : 'file'\n}\n\nasync function readAllBytes(data: Uint8Array | ReadableStream<Uint8Array>): Promise<Uint8Array> {\n if (data instanceof Uint8Array) return data\n const reader = data.getReader()\n const chunks: Uint8Array[] = []\n let total = 0\n try {\n for (;;) {\n const { value, done } = await reader.read()\n if (done) break\n if (value) {\n chunks.push(value)\n total += value.byteLength\n }\n }\n } finally {\n reader.releaseLock()\n }\n const out = new Uint8Array(total)\n let offset = 0\n for (const c of chunks) {\n out.set(c, offset)\n offset += c.byteLength\n }\n return out\n}\n\nexport class VercelBlobStorage implements StorageAdapter {\n private readonly prefix: string\n\n constructor(private readonly opts: VercelBlobStorageOptions) {\n const raw = opts.prefix ?? ''\n this.prefix = raw === '' || raw.endsWith('/') ? raw : `${raw}/`\n }\n\n async put(blob: PutBlob): Promise<PutResult> {\n const bytes = await readAllBytes(blob.data)\n const body = new Blob([bytes], { type: blob.contentType })\n const key = `${this.prefix}${sanitizeName(blob.name)}`\n const result = await put(key, body, {\n access: 'public',\n contentType: blob.contentType,\n addRandomSuffix: true,\n token: this.opts.token,\n })\n return {\n key: result.pathname,\n url: result.url,\n size: bytes.byteLength,\n }\n }\n}\n\n/** Construct a Vercel Blob `StorageAdapter` (uniform `xxxStorage(config)` shape). */\nexport function vercelBlobStorage(opts: VercelBlobStorageOptions): StorageAdapter {\n return new VercelBlobStorage(opts)\n}\n\nexport const packageName = '@airnauts/comments-storage-vercel-blob'\n"],"mappings":";AACA,SAAS,WAAW;AAapB,SAAS,aAAa,MAAsB;AAC1C,QAAM,UAAU,KAAK,QAAQ,oBAAoB,GAAG,EAAE,MAAM,GAAG,GAAG;AAClE,SAAO,QAAQ,SAAS,IAAI,UAAU;AACxC;AAEA,eAAe,aAAa,MAAoE;AAC9F,MAAI,gBAAgB,WAAY,QAAO;A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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@airnauts/comments-storage-vercel-blob",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "description": "Vercel Blob attachment-storage adapter for the Airnauts commenting tool server.",
5
5
  "keywords": [
6
6
  "comments",
@@ -41,8 +41,8 @@
41
41
  },
42
42
  "dependencies": {
43
43
  "@vercel/blob": "^1.1.1",
44
- "@airnauts/comments-core": "^0.1.0",
45
- "@airnauts/comments-server": "^0.1.0"
44
+ "@airnauts/comments-core": "^0.2.0",
45
+ "@airnauts/comments-server": "^0.2.0"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@airnauts/comments-test-support": "0.0.0"