nuxt-media-library 0.0.50 → 0.0.51

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
@@ -47,8 +47,11 @@ export default defineNuxtConfig({
47
47
  mediaLibrary: {
48
48
  // Auto-register Vue components from src/runtime/components
49
49
  components: true,
50
- // Chunk uploader config (used by MlFileUpload)
51
- baseURL: 'https://api.example.com',
50
+ // Where the Nuxt server reaches the media library (with /v1). Server-side
51
+ // only, never sent to browsers; prefer NUXT_MEDIA_LIBRARY_BASE_URL.
52
+ baseURL: 'http://media-library.internal/v1',
53
+ // Only for direct browser uploads (proxyUploads: false): a public address.
54
+ // publicBaseURL: 'https://media.example.com/v1',
52
55
  // Uploads always go through Nuxt server (/api/media-library/uploads/*)
53
56
  routes: {
54
57
  createSession: '/uploads/sessions',
@@ -60,11 +63,18 @@ export default defineNuxtConfig({
60
63
  partSize: 8 * 1024 * 1024,
61
64
  concurrency: 3,
62
65
  checksum: { algorithm: 'SHA-256', perPart: true, final: true },
63
- headers: {},
66
+ // Sent to browsers too, except credentials: Authorization, Cookie,
67
+ // Proxy-Authorization and X-Api-Key stay server-side (the proxies add them).
68
+ headers: { 'X-Tenant': 'acme' },
64
69
  },
65
70
  })
66
71
  ```
67
72
 
73
+ Nuxt puts the public runtime config in every page, so the module never copies
74
+ `baseURL` or credential headers there. Set the media library's internal
75
+ address and any service token only server-side
76
+ (`NUXT_MEDIA_LIBRARY_BASE_URL`, `NUXT_MEDIA_LIBRARY_SERVICE_TOKEN`).
77
+
68
78
  ### Nuxt usage
69
79
 
70
80
  ```vue
@@ -164,7 +174,7 @@ app's decision, not the service's:
164
174
  // nuxt.config.ts
165
175
  export default defineNuxtConfig({
166
176
  mediaLibrary: {
167
- baseURL: process.env.MEDIA_LIBRARY_URL, // server side, e.g. http://media-library.internal/v1
177
+ // server side only: set NUXT_MEDIA_LIBRARY_BASE_URL (e.g. http://media-library.internal/v1)
168
178
  serviceUploads: { proxy: true }, // parts go through /api/media-library/service-uploads
169
179
  // or, direct to the media library (needs CORS for the site):
170
180
  // serviceUploads: { baseURL: 'https://media.example.com/v1' },
package/dist/module.d.mts CHANGED
@@ -14,7 +14,17 @@ interface ChunkUploaderRoutesConfig {
14
14
  }
15
15
  interface ModuleOptions {
16
16
  components?: boolean;
17
+ /**
18
+ * Where the Nuxt server reaches the media library, with `/v1` (often an
19
+ * internal address). Server-side only: never sent to browsers. Prefer
20
+ * NUXT_MEDIA_LIBRARY_BASE_URL at runtime.
21
+ */
17
22
  baseURL?: string;
23
+ /**
24
+ * The media library address browsers use for direct uploads
25
+ * (`proxyUploads: false`), with `/v1`. Public: only set a public address.
26
+ */
27
+ publicBaseURL?: string;
18
28
  routes?: ChunkUploaderRoutesConfig;
19
29
  partSize?: number;
20
30
  concurrency?: number;
package/dist/module.d.ts CHANGED
@@ -14,7 +14,17 @@ interface ChunkUploaderRoutesConfig {
14
14
  }
15
15
  interface ModuleOptions {
16
16
  components?: boolean;
17
+ /**
18
+ * Where the Nuxt server reaches the media library, with `/v1` (often an
19
+ * internal address). Server-side only: never sent to browsers. Prefer
20
+ * NUXT_MEDIA_LIBRARY_BASE_URL at runtime.
21
+ */
17
22
  baseURL?: string;
23
+ /**
24
+ * The media library address browsers use for direct uploads
25
+ * (`proxyUploads: false`), with `/v1`. Public: only set a public address.
26
+ */
27
+ publicBaseURL?: string;
18
28
  routes?: ChunkUploaderRoutesConfig;
19
29
  partSize?: number;
20
30
  concurrency?: number;
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "media-library",
3
3
  "configKey": "mediaLibrary",
4
- "version": "0.0.50",
4
+ "version": "0.0.51",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -1,9 +1,24 @@
1
- import { defineNuxtModule, createResolver, addImportsDir, addComponentsDir, addServerHandler, addPlugin } from '@nuxt/kit';
1
+ import { defineNuxtModule, createResolver, addImportsDir, addComponentsDir, addServerHandler, useLogger, addPlugin } from '@nuxt/kit';
2
2
  export * from '../dist/runtime/types/resourcePolicy.js';
3
3
  export * from '../dist/runtime/types/uploader.js';
4
4
  export * from '../dist/runtime/types/preview.js';
5
5
  export * from '../dist/runtime/types/asset.js';
6
6
 
7
+ const CREDENTIAL_HEADERS = ["authorization", "proxy-authorization", "cookie", "x-api-key"];
8
+ function browserHeaders(headers) {
9
+ if (!headers || typeof headers !== "object") return { headers: {}, dropped: [] };
10
+ const kept = {};
11
+ const dropped = [];
12
+ for (const [name, value] of Object.entries(headers)) {
13
+ if (CREDENTIAL_HEADERS.includes(name.toLowerCase())) dropped.push(name);
14
+ else kept[name] = value;
15
+ }
16
+ return { headers: kept, dropped };
17
+ }
18
+ function browserBaseURL(existingPublic, publicBaseURL) {
19
+ return existingPublic ?? publicBaseURL ?? "";
20
+ }
21
+
7
22
  const SERVICE_UPLOADS_ROUTE = "/api/media-library/service-uploads";
8
23
  const module$1 = defineNuxtModule({
9
24
  meta: {
@@ -38,7 +53,10 @@ const module$1 = defineNuxtModule({
38
53
  const envTenantHeader = process.env.NUXT_MEDIA_LIBRARY_HEADERS_X_TENANT;
39
54
  const envHeaders = envTenantHeader ? { "X-tenant": envTenantHeader } : {};
40
55
  const existingHeaders = typeof existingPrivate.headers === "object" ? existingPrivate.headers : {};
41
- const resolvedHeaders = { ...existingHeaders };
56
+ const optionCredentials = Object.fromEntries(
57
+ browserHeaders(options.headers).dropped.map((name) => [name, options.headers[name]])
58
+ );
59
+ const resolvedHeaders = { ...optionCredentials, ...existingHeaders };
42
60
  for (const [key, value] of Object.entries(envHeaders)) {
43
61
  if (!resolvedHeaders[key]) {
44
62
  resolvedHeaders[key] = value;
@@ -105,9 +123,17 @@ const module$1 = defineNuxtModule({
105
123
  // grants). Declared so NUXT_MEDIA_LIBRARY_SERVICE_TOKEN applies.
106
124
  serviceToken: existingPrivate.serviceToken ?? ""
107
125
  };
126
+ const logger = useLogger("media-library");
127
+ const publicHeaders = browserHeaders(existingPublic.headers ?? options.headers);
128
+ if (publicHeaders.dropped.length) {
129
+ logger.warn(`mediaLibrary.headers: ${publicHeaders.dropped.join(", ")} kept server-side, not sent to browsers.`);
130
+ }
131
+ if (existingPublic.proxyUploads === false && !existingPublic.baseURL && !options.publicBaseURL) {
132
+ logger.warn("proxyUploads is false but no public media library address is set: set mediaLibrary.publicBaseURL. baseURL is server-side only.");
133
+ }
108
134
  nuxt.options.runtimeConfig.public.mediaLibrary = {
109
135
  ...existingPublic,
110
- baseURL: existingPublic.baseURL ?? options.baseURL ?? "",
136
+ baseURL: browserBaseURL(existingPublic.baseURL, options.publicBaseURL),
111
137
  routes: existingPublic.routes ?? routes,
112
138
  proxyUploads: existingPublic.proxyUploads ?? true,
113
139
  partSize: existingPublic.partSize ?? options.partSize ?? 8 * 1024 * 1024,
@@ -117,7 +143,7 @@ const module$1 = defineNuxtModule({
117
143
  perPart: existingPublic.checksum?.perPart ?? options.checksum?.perPart ?? true,
118
144
  final: existingPublic.checksum?.final ?? options.checksum?.final ?? true
119
145
  },
120
- headers: existingPublic.headers ?? options.headers ?? {},
146
+ headers: publicHeaders.headers,
121
147
  // Where useMLServiceUpload sends parts (NUXT_PUBLIC_MEDIA_LIBRARY_SERVICE_UPLOAD_BASE_URL).
122
148
  serviceUploadBaseURL: existingPublic.serviceUploadBaseURL || options.serviceUploads?.baseURL || (options.serviceUploads?.proxy ? SERVICE_UPLOADS_ROUTE : "")
123
149
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-media-library",
3
- "version": "0.0.50",
3
+ "version": "0.0.51",
4
4
  "description": "Nuxt module for media library management — chunked uploads, asset previews, and resource policies",
5
5
  "repository": {
6
6
  "type": "git",