@nuxt-atelier/storage-s3 0.0.0-stage → 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ano Rebel
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,7 @@
1
- # Temporary Holding Version
1
+ # @nuxt-atelier/storage-s3
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ S3-compatible and R2 media storage driver for Nuxt Atelier
4
+
5
+ Part of [Nuxt Atelier](https://nuxt-atelier.anorebel.net), a visual CMS for Nuxt. See the [documentation](https://nuxt-atelier.anorebel.net) to get started, or try the [live demo](https://nuxt-atelier-demo.anorebel.net).
6
+
7
+ MIT License
@@ -0,0 +1,5 @@
1
+ import { NuxtModule } from '@nuxt/schema';
2
+
3
+ declare const module$1: NuxtModule;
4
+
5
+ export { module$1 as default };
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "@nuxt-atelier/storage-s3",
3
+ "compatibility": {
4
+ "nuxt": ">=4.6.0"
5
+ },
6
+ "configKey": "@nuxt-atelier/storage-s3",
7
+ "version": "0.1.0",
8
+ "builder": {
9
+ "@nuxt/module-builder": "1.0.3",
10
+ "unbuild": "unknown"
11
+ }
12
+ }
@@ -0,0 +1,24 @@
1
+ import { defineNuxtModule, createResolver, addServerPlugin } from '@nuxt/kit';
2
+
3
+ const module$1 = defineNuxtModule({
4
+ meta: {
5
+ name: "@nuxt-atelier/storage-s3",
6
+ compatibility: {
7
+ nuxt: ">=4.6.0"
8
+ }
9
+ },
10
+ setup(_, nuxt) {
11
+ const { resolve } = createResolver(import.meta.url);
12
+ nuxt.options.runtimeConfig.atelierS3 = {
13
+ endpoint: "",
14
+ bucket: "",
15
+ region: "auto",
16
+ accessKeyId: "",
17
+ secretAccessKey: "",
18
+ ...nuxt.options.runtimeConfig.atelierS3
19
+ };
20
+ addServerPlugin(resolve("./runtime/plugin"));
21
+ }
22
+ });
23
+
24
+ export { module$1 as default };
@@ -0,0 +1,13 @@
1
+ import type { StorageDriver } from 'nuxt-atelier/storage';
2
+ export interface S3Options {
3
+ /** The bucket's endpoint, path-style: `https://<account>.r2.cloudflarestorage.com`, `https://s3.<region>.amazonaws.com`. */
4
+ endpoint: string;
5
+ bucket: string;
6
+ /** `auto` for R2. */
7
+ region: string;
8
+ accessKeyId: string;
9
+ secretAccessKey: string;
10
+ /** Bytes per multipart part, at least 5 MB (S3's minimum). */
11
+ partSize?: number;
12
+ }
13
+ export declare function createS3Driver(options: S3Options): StorageDriver;
@@ -0,0 +1,101 @@
1
+ import { AwsClient } from "aws4fetch";
2
+ const PART = 5 * 1024 * 1024;
3
+ export function createS3Driver(options) {
4
+ const client = new AwsClient({ accessKeyId: options.accessKeyId, secretAccessKey: options.secretAccessKey, region: options.region, service: "s3" });
5
+ const base = `${options.endpoint.replace(/\/$/, "")}/${encodeURIComponent(options.bucket)}`;
6
+ const url = (key, query = "") => `${base}/${key.split("/").map(encodeURIComponent).join("/")}${query}`;
7
+ const partSize = Math.max(options.partSize ?? PART, PART);
8
+ async function send(target, init, ok = (status) => status >= 200 && status < 300) {
9
+ const response = await client.fetch(target, init);
10
+ if (!ok(response.status))
11
+ throw new Error(`S3 ${init.method ?? "GET"} ${new URL(target).pathname} answered ${response.status}: ${(await response.text()).slice(0, 300)}`);
12
+ return response;
13
+ }
14
+ async function nextPart(reader, carry) {
15
+ const chunks = carry.splice(0);
16
+ let length = chunks.reduce((n, c) => n + c.length, 0);
17
+ let done = false;
18
+ while (length < partSize) {
19
+ const next = await reader.read();
20
+ if (next.done) {
21
+ done = true;
22
+ break;
23
+ }
24
+ chunks.push(next.value);
25
+ length += next.value.length;
26
+ }
27
+ const part = new Uint8Array(Math.min(length, partSize));
28
+ let offset = 0;
29
+ for (const chunk of chunks) {
30
+ const room = part.length - offset;
31
+ if (chunk.length <= room) {
32
+ part.set(chunk, offset);
33
+ offset += chunk.length;
34
+ } else {
35
+ part.set(chunk.subarray(0, room), offset);
36
+ carry.push(chunk.subarray(room));
37
+ offset += room;
38
+ }
39
+ }
40
+ return { part, done: done && !carry.length };
41
+ }
42
+ return {
43
+ name: "s3",
44
+ async put(key, body, info) {
45
+ const reader = body.getReader();
46
+ const carry = [];
47
+ const first = await nextPart(reader, carry);
48
+ if (first.done)
49
+ return void await send(url(key), { method: "PUT", body: first.part, headers: { "content-type": info.contentType } });
50
+ const created = await (await send(url(key, "?uploads"), { method: "POST", headers: { "content-type": info.contentType } })).text();
51
+ const uploadId = /<UploadId>([^<]+)<\/UploadId>/.exec(created)?.[1];
52
+ if (!uploadId)
53
+ throw new Error("S3 didn't start the multipart upload");
54
+ const etags = [];
55
+ try {
56
+ let part = first;
57
+ for (let n = 1; ; n++) {
58
+ const response = await send(url(key, `?partNumber=${n}&uploadId=${encodeURIComponent(uploadId)}`), { method: "PUT", body: part.part });
59
+ etags.push(response.headers.get("etag"));
60
+ if (part.done)
61
+ break;
62
+ part = await nextPart(reader, carry);
63
+ if (!part.part.length)
64
+ break;
65
+ }
66
+ const parts = etags.map((etag, i) => `<Part><PartNumber>${i + 1}</PartNumber><ETag>${etag}</ETag></Part>`).join("");
67
+ await send(url(key, `?uploadId=${encodeURIComponent(uploadId)}`), { method: "POST", body: `<CompleteMultipartUpload>${parts}</CompleteMultipartUpload>`, headers: { "content-type": "application/xml" } });
68
+ } catch (error) {
69
+ await reader.cancel().catch(() => {
70
+ });
71
+ await client.fetch(url(key, `?uploadId=${encodeURIComponent(uploadId)}`), { method: "DELETE" }).catch(() => {
72
+ });
73
+ throw error;
74
+ }
75
+ },
76
+ async get(key) {
77
+ const response = await send(url(key), { method: "GET" }, (s) => s >= 200 && s < 300 || s === 404);
78
+ if (response.status === 404 || !response.body)
79
+ return void 0;
80
+ return { stream: response.body, size: Number(response.headers.get("content-length") ?? 0) };
81
+ },
82
+ async head(key) {
83
+ const response = await send(url(key), { method: "HEAD" }, (s) => s >= 200 && s < 300 || s === 404);
84
+ return response.status === 404 ? void 0 : { size: Number(response.headers.get("content-length") ?? 0) };
85
+ },
86
+ async delete(key) {
87
+ await send(url(key), { method: "DELETE" }, (s) => s >= 200 && s < 300 || s === 404);
88
+ },
89
+ async deletePrefix(prefix) {
90
+ for (let token, page = 0; page < 100; page++) {
91
+ const list = await (await send(`${base}?list-type=2&prefix=${encodeURIComponent(prefix)}${token ? `&continuation-token=${encodeURIComponent(token)}` : ""}`, { method: "GET" })).text();
92
+ const keys = [...list.matchAll(/<Key>([^<]+)<\/Key>/g)].map((m) => m[1].replaceAll("&amp;", "&"));
93
+ for (const key of keys)
94
+ await this.delete(key);
95
+ token = /<NextContinuationToken>([^<]+)<\/NextContinuationToken>/.exec(list)?.[1];
96
+ if (!token)
97
+ return;
98
+ }
99
+ }
100
+ };
101
+ }
@@ -0,0 +1,2 @@
1
+ declare const _default: () => void;
2
+ export default _default;
@@ -0,0 +1,12 @@
1
+ import { registerStorageDriver } from "#atelier/server";
2
+ import { useRuntimeConfig } from "nuxt/server";
3
+ import { createS3Driver } from "./driver.js";
4
+ export default () => {
5
+ registerStorageDriver(() => {
6
+ const options = useRuntimeConfig().atelierS3;
7
+ const missing = ["endpoint", "bucket", "accessKeyId", "secretAccessKey"].filter((key) => !options[key]);
8
+ if (missing.length)
9
+ throw new Error(`[@nuxt-atelier/storage-s3] Set ${missing.map((key) => `NUXT_ATELIER_S3_${key.replace(/[A-Z]/g, (c) => `_${c}`).toUpperCase()}`).join(", ")}`);
10
+ return createS3Driver(options);
11
+ });
12
+ };
@@ -0,0 +1,7 @@
1
+ import type { NuxtModule } from '@nuxt/schema'
2
+
3
+ import type { default as Module } from './module.mjs'
4
+
5
+ export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
6
+
7
+ export { default } from './module.mjs'
package/package.json CHANGED
@@ -1,6 +1,46 @@
1
1
  {
2
2
  "name": "@nuxt-atelier/storage-s3",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "license": "MIT",
5
+ "type": "module",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/AnoRebel/nuxt-atelier.git",
9
+ "directory": "packages/storage-s3"
10
+ },
11
+ "homepage": "https://nuxt-atelier.anorebel.net",
12
+ "description": "S3-compatible and R2 media storage driver for Nuxt Atelier",
13
+ "exports": {
14
+ ".": {
15
+ "types": "./dist/types.d.mts",
16
+ "import": "./dist/module.mjs"
17
+ }
18
+ },
19
+ "main": "./dist/module.mjs",
20
+ "typesVersions": {
21
+ "*": {
22
+ ".": [
23
+ "./dist/types.d.mts"
24
+ ]
25
+ }
26
+ },
27
+ "files": [
28
+ "dist"
29
+ ],
30
+ "scripts": {
31
+ "build": "nuxt-module-build build",
32
+ "prepack": "nuxt-module-build build",
33
+ "check:pkg": "publint --pack bun && attw --pack . --profile esm-only"
34
+ },
35
+ "peerDependencies": {
36
+ "nuxt": ">=4.6.0"
37
+ },
38
+ "dependencies": {
39
+ "@nuxt/kit": "^4.6.3",
40
+ "aws4fetch": "1.0.20",
41
+ "nuxt-atelier": "0.1.0"
42
+ },
43
+ "devDependencies": {
44
+ "@nuxt/schema": "4.6.3"
45
+ }
46
+ }