naystack 1.8.10 → 1.8.11

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.
@@ -231,8 +231,9 @@ var getFileUploadPutRoute = (options) => async (req) => {
231
231
  };
232
232
  const fileKey = options.getKey ? await options.getKey(inputData) : (0, import_uuid.v4)();
233
233
  const url = getDownloadURL(fileKey);
234
- if (async) (0, import_functions.waitUntil)(uploadBlob(file, fileKey));
235
- else await uploadBlob(file, fileKey);
234
+ const blob = options.processFile ? await options.processFile(file, inputData) : file;
235
+ if (async) (0, import_functions.waitUntil)(uploadBlob(blob, fileKey));
236
+ else await uploadBlob(blob, fileKey);
236
237
  const onUploadResponse = await options.onUpload({
237
238
  ...inputData,
238
239
  url
@@ -205,8 +205,9 @@ var getFileUploadPutRoute = (options) => async (req) => {
205
205
  };
206
206
  const fileKey = options.getKey ? await options.getKey(inputData) : v4();
207
207
  const url = getDownloadURL(fileKey);
208
- if (async) waitUntil(uploadBlob(file, fileKey));
209
- else await uploadBlob(file, fileKey);
208
+ const blob = options.processFile ? await options.processFile(file, inputData) : file;
209
+ if (async) waitUntil(uploadBlob(blob, fileKey));
210
+ else await uploadBlob(blob, fileKey);
210
211
  const onUploadResponse = await options.onUpload({
211
212
  ...inputData,
212
213
  url
@@ -184,8 +184,9 @@ var getFileUploadPutRoute = (options) => async (req) => {
184
184
  };
185
185
  const fileKey = options.getKey ? await options.getKey(inputData) : (0, import_uuid.v4)();
186
186
  const url = getDownloadURL(fileKey);
187
- if (async) (0, import_functions.waitUntil)(uploadBlob(file, fileKey));
188
- else await uploadBlob(file, fileKey);
187
+ const blob = options.processFile ? await options.processFile(file, inputData) : file;
188
+ if (async) (0, import_functions.waitUntil)(uploadBlob(blob, fileKey));
189
+ else await uploadBlob(blob, fileKey);
189
190
  const onUploadResponse = await options.onUpload({
190
191
  ...inputData,
191
192
  url
@@ -7,7 +7,7 @@ import { SetupFileUploadOptions } from './setup.mjs';
7
7
  * Requires authentication (Bearer token, not refresh cookie).
8
8
  * Expects multipart form data with fields: `file` (File), `type` (string), and optional `data` (JSON string).
9
9
  *
10
- * @param options - `SetupFileUploadOptions` (getKey, onUpload).
10
+ * @param options - `SetupFileUploadOptions` (getKey, processFile, onUpload).
11
11
  * @returns Async Next.js route handler for PUT requests.
12
12
  * @category File
13
13
  */
@@ -7,7 +7,7 @@ import { SetupFileUploadOptions } from './setup.js';
7
7
  * Requires authentication (Bearer token, not refresh cookie).
8
8
  * Expects multipart form data with fields: `file` (File), `type` (string), and optional `data` (JSON string).
9
9
  *
10
- * @param options - `SetupFileUploadOptions` (getKey, onUpload).
10
+ * @param options - `SetupFileUploadOptions` (getKey, processFile, onUpload).
11
11
  * @returns Async Next.js route handler for PUT requests.
12
12
  * @category File
13
13
  */
@@ -164,8 +164,9 @@ var getFileUploadPutRoute = (options) => async (req) => {
164
164
  };
165
165
  const fileKey = options.getKey ? await options.getKey(inputData) : v4();
166
166
  const url = getDownloadURL(fileKey);
167
- if (async) waitUntil(uploadBlob(file, fileKey));
168
- else await uploadBlob(file, fileKey);
167
+ const blob = options.processFile ? await options.processFile(file, inputData) : file;
168
+ if (async) waitUntil(uploadBlob(blob, fileKey));
169
+ else await uploadBlob(blob, fileKey);
169
170
  const onUploadResponse = await options.onUpload({
170
171
  ...inputData,
171
172
  url
@@ -186,8 +186,9 @@ var getFileUploadPutRoute = (options) => async (req) => {
186
186
  };
187
187
  const fileKey = options.getKey ? await options.getKey(inputData) : (0, import_uuid.v4)();
188
188
  const url = getDownloadURL(fileKey);
189
- if (async) (0, import_functions.waitUntil)(uploadBlob(file, fileKey));
190
- else await uploadBlob(file, fileKey);
189
+ const blob = options.processFile ? await options.processFile(file, inputData) : file;
190
+ if (async) (0, import_functions.waitUntil)(uploadBlob(blob, fileKey));
191
+ else await uploadBlob(blob, fileKey);
191
192
  const onUploadResponse = await options.onUpload({
192
193
  ...inputData,
193
194
  url
@@ -4,6 +4,10 @@ import * as next_server from 'next/server';
4
4
  * Options for setting up file upload via {@link setupFileUpload}.
5
5
  *
6
6
  * @property getKey - Optional. Given `{ type, userId, data }`, returns the S3 object key for the upload. If omitted, a UUID is generated.
7
+ * @property processFile - Optional. Given the uploaded `file` and `{ type, userId, data }`, returns the blob to
8
+ * store in its place — e.g. re-encoding an image, or stripping metadata. Runs after authentication and before the
9
+ * S3 write, so only the returned bytes are ever stored. The blob's `type` becomes the object's `Content-Type`,
10
+ * so change it when the format changes. Return the file unchanged to leave it alone. Throwing fails the upload.
7
11
  * @property onUpload - **Required.** Called after each successful upload with `{ url, type, userId, data }`.
8
12
  * The return value is included in the API response as `onUploadResponse` (e.g. save metadata to your database and return it).
9
13
  *
@@ -15,6 +19,11 @@ interface SetupFileUploadOptions {
15
19
  userId: number;
16
20
  data: object;
17
21
  }) => Promise<string>;
22
+ processFile?: (file: File, data: {
23
+ type: string;
24
+ userId: number;
25
+ data: object;
26
+ }) => Promise<Blob>;
18
27
  onUpload: (data: {
19
28
  url: string | null;
20
29
  type: string;
@@ -4,6 +4,10 @@ import * as next_server from 'next/server';
4
4
  * Options for setting up file upload via {@link setupFileUpload}.
5
5
  *
6
6
  * @property getKey - Optional. Given `{ type, userId, data }`, returns the S3 object key for the upload. If omitted, a UUID is generated.
7
+ * @property processFile - Optional. Given the uploaded `file` and `{ type, userId, data }`, returns the blob to
8
+ * store in its place — e.g. re-encoding an image, or stripping metadata. Runs after authentication and before the
9
+ * S3 write, so only the returned bytes are ever stored. The blob's `type` becomes the object's `Content-Type`,
10
+ * so change it when the format changes. Return the file unchanged to leave it alone. Throwing fails the upload.
7
11
  * @property onUpload - **Required.** Called after each successful upload with `{ url, type, userId, data }`.
8
12
  * The return value is included in the API response as `onUploadResponse` (e.g. save metadata to your database and return it).
9
13
  *
@@ -15,6 +19,11 @@ interface SetupFileUploadOptions {
15
19
  userId: number;
16
20
  data: object;
17
21
  }) => Promise<string>;
22
+ processFile?: (file: File, data: {
23
+ type: string;
24
+ userId: number;
25
+ data: object;
26
+ }) => Promise<Blob>;
18
27
  onUpload: (data: {
19
28
  url: string | null;
20
29
  type: string;
@@ -164,8 +164,9 @@ var getFileUploadPutRoute = (options) => async (req) => {
164
164
  };
165
165
  const fileKey = options.getKey ? await options.getKey(inputData) : v4();
166
166
  const url = getDownloadURL(fileKey);
167
- if (async) waitUntil(uploadBlob(file, fileKey));
168
- else await uploadBlob(file, fileKey);
167
+ const blob = options.processFile ? await options.processFile(file, inputData) : file;
168
+ if (async) waitUntil(uploadBlob(blob, fileKey));
169
+ else await uploadBlob(blob, fileKey);
169
170
  const onUploadResponse = await options.onUpload({
170
171
  ...inputData,
171
172
  url
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "naystack",
3
- "version": "1.8.10",
3
+ "version": "1.8.11",
4
4
  "description": "A stack built with Next + GraphQL + S3 + Auth",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",