naystack 1.2.17 → 1.2.20

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.
@@ -17,16 +17,40 @@ var __copyProps = (to, from, except, desc) => {
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
- // src/auth/email/client.ts
20
+ // src/auth/email/client.tsx
21
21
  var client_exports = {};
22
22
  __export(client_exports, {
23
- getEmailAuthUtils: () => getEmailAuthUtils
23
+ TokenContext: () => TokenContext,
24
+ getApolloWrapper: () => getApolloWrapper,
25
+ getEmailAuthUtils: () => getEmailAuthUtils,
26
+ useSetToken: () => useSetToken,
27
+ useToken: () => useToken
24
28
  });
25
29
  module.exports = __toCommonJS(client_exports);
26
- var import_client = require("naystack/graphql/client");
27
30
  var import_react = require("react");
31
+ var TokenContext = (0, import_react.createContext)({
32
+ token: null,
33
+ setToken: () => null
34
+ });
35
+ var getApolloWrapper = (endpoint) => ({ children }) => {
36
+ const [token, setToken] = (0, import_react.useState)(null);
37
+ (0, import_react.useEffect)(() => {
38
+ fetch(endpoint, {
39
+ credentials: "include"
40
+ }).then((res) => res.json()).then((data) => setToken(data.accessToken));
41
+ }, []);
42
+ return /* @__PURE__ */ React.createElement(TokenContext.Provider, { value: { token, setToken } }, children);
43
+ };
44
+ function useToken() {
45
+ const { token } = (0, import_react.useContext)(TokenContext);
46
+ return token;
47
+ }
48
+ function useSetToken() {
49
+ const { setToken } = (0, import_react.useContext)(TokenContext);
50
+ return setToken;
51
+ }
28
52
  function useSignUpWithEmail(endpoint) {
29
- const setToken = (0, import_client.useSetToken)();
53
+ const setToken = useSetToken();
30
54
  return (0, import_react.useCallback)(
31
55
  async (data) => {
32
56
  const res = await fetch(endpoint, {
@@ -45,7 +69,7 @@ function useSignUpWithEmail(endpoint) {
45
69
  );
46
70
  }
47
71
  function useLoginWithEmail(endpoint) {
48
- const setToken = (0, import_client.useSetToken)();
72
+ const setToken = useSetToken();
49
73
  return (0, import_react.useCallback)(
50
74
  async (data) => {
51
75
  const res = await fetch(endpoint, {
@@ -64,7 +88,7 @@ function useLoginWithEmail(endpoint) {
64
88
  );
65
89
  }
66
90
  function useLogout(endpoint) {
67
- const setToken = (0, import_client.useSetToken)();
91
+ const setToken = useSetToken();
68
92
  return (0, import_react.useCallback)(
69
93
  async (data) => {
70
94
  setToken(null);
@@ -86,5 +110,9 @@ function getEmailAuthUtils(endpoint) {
86
110
  }
87
111
  // Annotate the CommonJS export names for ESM import in node:
88
112
  0 && (module.exports = {
89
- getEmailAuthUtils
113
+ TokenContext,
114
+ getApolloWrapper,
115
+ getEmailAuthUtils,
116
+ useSetToken,
117
+ useToken
90
118
  });
@@ -1,7 +1,19 @@
1
+ import * as react from 'react';
2
+ import { Dispatch, SetStateAction } from 'react';
3
+
4
+ declare const TokenContext: react.Context<{
5
+ token: string | null;
6
+ setToken: Dispatch<SetStateAction<string | null>>;
7
+ }>;
8
+ declare const getApolloWrapper: (endpoint: string) => ({ children }: {
9
+ children: React.ReactNode;
10
+ }) => react.JSX.Element;
11
+ declare function useToken(): string | null;
12
+ declare function useSetToken(): Dispatch<SetStateAction<string | null>>;
1
13
  declare function getEmailAuthUtils(endpoint: string): {
2
14
  useSignUp: () => (data: object) => Promise<string | null>;
3
15
  useLogin: () => (data: object) => Promise<string | null>;
4
16
  useLogout: () => (data?: object) => Promise<void>;
5
17
  };
6
18
 
7
- export { getEmailAuthUtils };
19
+ export { TokenContext, getApolloWrapper, getEmailAuthUtils, useSetToken, useToken };
@@ -1,7 +1,19 @@
1
+ import * as react from 'react';
2
+ import { Dispatch, SetStateAction } from 'react';
3
+
4
+ declare const TokenContext: react.Context<{
5
+ token: string | null;
6
+ setToken: Dispatch<SetStateAction<string | null>>;
7
+ }>;
8
+ declare const getApolloWrapper: (endpoint: string) => ({ children }: {
9
+ children: React.ReactNode;
10
+ }) => react.JSX.Element;
11
+ declare function useToken(): string | null;
12
+ declare function useSetToken(): Dispatch<SetStateAction<string | null>>;
1
13
  declare function getEmailAuthUtils(endpoint: string): {
2
14
  useSignUp: () => (data: object) => Promise<string | null>;
3
15
  useLogin: () => (data: object) => Promise<string | null>;
4
16
  useLogout: () => (data?: object) => Promise<void>;
5
17
  };
6
18
 
7
- export { getEmailAuthUtils };
19
+ export { TokenContext, getApolloWrapper, getEmailAuthUtils, useSetToken, useToken };
@@ -1,6 +1,32 @@
1
- // src/auth/email/client.ts
2
- import { useSetToken } from "naystack/graphql/client";
3
- import { useCallback } from "react";
1
+ // src/auth/email/client.tsx
2
+ import {
3
+ createContext,
4
+ useCallback,
5
+ useContext,
6
+ useEffect,
7
+ useState
8
+ } from "react";
9
+ var TokenContext = createContext({
10
+ token: null,
11
+ setToken: () => null
12
+ });
13
+ var getApolloWrapper = (endpoint) => ({ children }) => {
14
+ const [token, setToken] = useState(null);
15
+ useEffect(() => {
16
+ fetch(endpoint, {
17
+ credentials: "include"
18
+ }).then((res) => res.json()).then((data) => setToken(data.accessToken));
19
+ }, []);
20
+ return /* @__PURE__ */ React.createElement(TokenContext.Provider, { value: { token, setToken } }, children);
21
+ };
22
+ function useToken() {
23
+ const { token } = useContext(TokenContext);
24
+ return token;
25
+ }
26
+ function useSetToken() {
27
+ const { setToken } = useContext(TokenContext);
28
+ return setToken;
29
+ }
4
30
  function useSignUpWithEmail(endpoint) {
5
31
  const setToken = useSetToken();
6
32
  return useCallback(
@@ -61,5 +87,9 @@ function getEmailAuthUtils(endpoint) {
61
87
  };
62
88
  }
63
89
  export {
64
- getEmailAuthUtils
90
+ TokenContext,
91
+ getApolloWrapper,
92
+ getEmailAuthUtils,
93
+ useSetToken,
94
+ useToken
65
95
  };
@@ -1,6 +1,6 @@
1
- import * as React from 'react';
1
+ import * as react from 'react';
2
2
 
3
- declare function useVisibility(onVisible?: () => void): React.RefObject<null>;
3
+ declare function useVisibility(onVisible?: () => void): react.RefObject<null>;
4
4
  declare function useBreakpoint(query: string): boolean | null;
5
5
 
6
6
  export { useBreakpoint, useVisibility };
@@ -1,6 +1,6 @@
1
- import * as React from 'react';
1
+ import * as react from 'react';
2
2
 
3
- declare function useVisibility(onVisible?: () => void): React.RefObject<null>;
3
+ declare function useVisibility(onVisible?: () => void): react.RefObject<null>;
4
4
  declare function useBreakpoint(query: string): boolean | null;
5
5
 
6
6
  export { useBreakpoint, useVisibility };
@@ -20,32 +20,29 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/file/client.ts
21
21
  var client_exports = {};
22
22
  __export(client_exports, {
23
- getHandleImageUpload: () => getHandleImageUpload
23
+ getUseFileUpload: () => getUseFileUpload
24
24
  });
25
25
  module.exports = __toCommonJS(client_exports);
26
- var getHandleImageUpload = (route) => ({
27
- file,
28
- type,
29
- token,
30
- data,
31
- sync
32
- }) => {
33
- const formData = new FormData();
34
- formData.append("type", type);
35
- if (file) formData.append("file", file);
36
- if (sync) formData.append("sync", sync.toString());
37
- if (data) formData.append("data", JSON.stringify(data));
38
- return fetch(route, {
39
- method: "PUT",
40
- body: formData,
41
- headers: {
42
- Authorization: `Bearer ${token}`
43
- }
44
- }).then(
45
- async (res) => await res.json() || null
46
- );
26
+ var import_client = require("naystack/auth/email/client");
27
+ var getUseFileUpload = (route) => () => {
28
+ const token = (0, import_client.useToken)();
29
+ return (file, type, data) => {
30
+ const formData = new FormData();
31
+ formData.append("type", type);
32
+ formData.append("file", file);
33
+ if (data) formData.append("data", JSON.stringify(data));
34
+ return fetch(route, {
35
+ method: "PUT",
36
+ body: formData,
37
+ headers: {
38
+ Authorization: `Bearer ${token}`
39
+ }
40
+ }).then(
41
+ async (res) => await res.json() || null
42
+ );
43
+ };
47
44
  };
48
45
  // Annotate the CommonJS export names for ESM import in node:
49
46
  0 && (module.exports = {
50
- getHandleImageUpload
47
+ getUseFileUpload
51
48
  });
@@ -1,13 +1,7 @@
1
- declare const getHandleImageUpload: (route: string) => ({ file, type, token, data, sync, }: {
2
- file?: File | Blob;
3
- token: string;
4
- type: string;
5
- sync?: boolean;
6
- data?: object;
7
- }) => Promise<ImageUploadResponseType>;
8
- interface ImageUploadResponseType {
1
+ declare const getUseFileUpload: (route: string) => () => (file: File | Blob, type: string, data?: object) => Promise<FileUploadResponseType>;
2
+ interface FileUploadResponseType {
9
3
  url?: string;
10
- response?: object;
4
+ onUploadResponse?: object;
11
5
  }
12
6
 
13
- export { type ImageUploadResponseType, getHandleImageUpload };
7
+ export { getUseFileUpload };
@@ -1,13 +1,7 @@
1
- declare const getHandleImageUpload: (route: string) => ({ file, type, token, data, sync, }: {
2
- file?: File | Blob;
3
- token: string;
4
- type: string;
5
- sync?: boolean;
6
- data?: object;
7
- }) => Promise<ImageUploadResponseType>;
8
- interface ImageUploadResponseType {
1
+ declare const getUseFileUpload: (route: string) => () => (file: File | Blob, type: string, data?: object) => Promise<FileUploadResponseType>;
2
+ interface FileUploadResponseType {
9
3
  url?: string;
10
- response?: object;
4
+ onUploadResponse?: object;
11
5
  }
12
6
 
13
- export { type ImageUploadResponseType, getHandleImageUpload };
7
+ export { getUseFileUpload };
@@ -1,26 +1,23 @@
1
1
  // src/file/client.ts
2
- var getHandleImageUpload = (route) => ({
3
- file,
4
- type,
5
- token,
6
- data,
7
- sync
8
- }) => {
9
- const formData = new FormData();
10
- formData.append("type", type);
11
- if (file) formData.append("file", file);
12
- if (sync) formData.append("sync", sync.toString());
13
- if (data) formData.append("data", JSON.stringify(data));
14
- return fetch(route, {
15
- method: "PUT",
16
- body: formData,
17
- headers: {
18
- Authorization: `Bearer ${token}`
19
- }
20
- }).then(
21
- async (res) => await res.json() || null
22
- );
2
+ import { useToken } from "naystack/auth/email/client";
3
+ var getUseFileUpload = (route) => () => {
4
+ const token = useToken();
5
+ return (file, type, data) => {
6
+ const formData = new FormData();
7
+ formData.append("type", type);
8
+ formData.append("file", file);
9
+ if (data) formData.append("data", JSON.stringify(data));
10
+ return fetch(route, {
11
+ method: "PUT",
12
+ body: formData,
13
+ headers: {
14
+ Authorization: `Bearer ${token}`
15
+ }
16
+ }).then(
17
+ async (res) => await res.json() || null
18
+ );
19
+ };
23
20
  };
24
21
  export {
25
- getHandleImageUpload
22
+ getUseFileUpload
26
23
  };
@@ -25,7 +25,6 @@ __export(file_exports, {
25
25
  module.exports = __toCommonJS(file_exports);
26
26
 
27
27
  // src/file/put.ts
28
- var import_functions2 = require("@vercel/functions");
29
28
  var import_server3 = require("next/server");
30
29
  var import_uuid = require("uuid");
31
30
 
@@ -76,10 +75,8 @@ var getContext = (refreshKey, signingKey, req) => {
76
75
  };
77
76
 
78
77
  // src/file/utils.ts
79
- var import_node_crypto = require("crypto");
80
78
  var import_client_s3 = require("@aws-sdk/client-s3");
81
79
  var import_s3_request_presigner = require("@aws-sdk/s3-request-presigner");
82
- var import_functions = require("@vercel/functions");
83
80
  var getS3Client = (options) => new import_client_s3.S3Client({
84
81
  region: options.region,
85
82
  credentials: {
@@ -88,30 +85,34 @@ var getS3Client = (options) => new import_client_s3.S3Client({
88
85
  }
89
86
  });
90
87
  var getURLPrefix = (options) => `https://${options.bucket}.s3.${options.region}.amazonaws.com/`;
91
- function getHash(keys) {
92
- return (0, import_node_crypto.createHash)("sha256").update(keys.join("/")).digest("hex");
88
+ function getKey(keys) {
89
+ return typeof keys === "string" ? keys : keys.join("/");
93
90
  }
94
- var getUploadFileURL = (client, Bucket) => (keys, isPublic) => {
91
+ var getUploadURL = (client, Bucket) => (keys) => {
95
92
  const command = new import_client_s3.PutObjectCommand({
96
93
  Bucket,
97
- Key: getHash(keys),
98
- ACL: isPublic ? "public-read" : void 0
94
+ Key: getKey(keys),
95
+ ACL: "public-read"
99
96
  });
100
97
  return (0, import_s3_request_presigner.getSignedUrl)(client, command, { expiresIn: 300 });
101
98
  };
102
- var getFileURL = (options) => (keys) => {
103
- if (typeof keys === "string") return `${getURLPrefix(options)}${keys}`;
104
- return `${getURLPrefix(options)}${getHash(keys)}`;
99
+ var getDownloadURL = (options) => (keys) => {
100
+ return `${getURLPrefix(options)}${getKey(keys)}`;
105
101
  };
106
- var uploadImage = (client, options) => async (url, key, blob) => {
107
- const photoBlob = blob || await fetch(url).then((file) => file.blob());
108
- if (photoBlob) {
109
- (0, import_functions.waitUntil)(uploadFile(client, options.bucket)(photoBlob, getHash(key)));
110
- return getFileURL(options)(key);
102
+ var uploadFile = (client, options) => async (keys, {
103
+ url,
104
+ blob
105
+ }) => {
106
+ if (!blob && !url) return null;
107
+ const fileBlob = blob || await fetch(url).then((file) => file.blob());
108
+ if (fileBlob) {
109
+ const key = getKey(keys);
110
+ await uploadBlob(client, options.bucket)(fileBlob, key);
111
+ return getDownloadURL(options)(key);
111
112
  }
112
113
  return null;
113
114
  };
114
- var deleteImage = (client, options) => async (url) => {
115
+ var deleteFile = (client, options) => async (url) => {
115
116
  const key = url.split(getURLPrefix(options))[1];
116
117
  if (key) {
117
118
  try {
@@ -128,7 +129,7 @@ var deleteImage = (client, options) => async (url) => {
128
129
  }
129
130
  return false;
130
131
  };
131
- var uploadFile = (client, Bucket) => async (file, key) => {
132
+ var uploadBlob = (client, Bucket) => async (file, key) => {
132
133
  const fileBuffer = await file.arrayBuffer();
133
134
  return client.send(
134
135
  new import_client_s3.PutObjectCommand({
@@ -148,33 +149,25 @@ var getFileUploadPutRoute = (options, client) => async (req) => {
148
149
  if (!ctx?.userId || ctx.isRefreshID)
149
150
  return import_server3.NextResponse.json({ error: "unauthorized" }, { status: 401 });
150
151
  const formData = await req.formData();
151
- const type = formData.get("type");
152
- const sync = Boolean(formData.get("sync"));
153
152
  const file = formData.get("file");
153
+ if (!file) return import_server3.NextResponse.json({ error: "no file" }, { status: 400 });
154
154
  const data = formData.get("data");
155
- const imageKey = (0, import_uuid.v4)();
156
- const url = file ? getFileURL(options)(imageKey) : null;
157
- const handleKeyProcessing = async () => {
158
- if (file) await uploadFile(client, options.bucket)(file, imageKey);
159
- if (!type || !ctx.userId || ctx.isRefreshID) return;
160
- const { deleteURL, response } = await options.processFile({
161
- url,
162
- type,
163
- userId: ctx.userId,
164
- data: typeof data === "string" ? JSON.parse(data) : void 0
165
- });
166
- if (deleteURL) await deleteImage(client, options)(deleteURL);
167
- return response;
155
+ const inputData = {
156
+ type: formData.get("type") + "",
157
+ userId: ctx.userId,
158
+ data: typeof data === "string" ? JSON.parse(data) : void 0
168
159
  };
169
- if (!sync) {
170
- (0, import_functions2.waitUntil)(handleKeyProcessing());
171
- return import_server3.NextResponse.json({ url });
172
- } else {
173
- return import_server3.NextResponse.json({
174
- url,
175
- response: await handleKeyProcessing()
176
- });
177
- }
160
+ const fileKey = options.getKey ? await options.getKey(inputData) : (0, import_uuid.v4)();
161
+ const url = getDownloadURL(options)(fileKey);
162
+ await uploadBlob(client, options.bucket)(file, fileKey);
163
+ const onUploadResponse = await options.onUpload({
164
+ ...inputData,
165
+ url
166
+ });
167
+ return import_server3.NextResponse.json({
168
+ url,
169
+ onUploadResponse
170
+ });
178
171
  };
179
172
 
180
173
  // src/file/setup.ts
@@ -182,11 +175,10 @@ function setupFileUpload(options) {
182
175
  const client = getS3Client(options);
183
176
  return {
184
177
  PUT: getFileUploadPutRoute(options, client),
185
- getUploadFileURL: getUploadFileURL(client, options.bucket),
186
- uploadImage: uploadImage(client, options),
187
- deleteImage: deleteImage(client, options),
188
- getFileURL: getFileURL(options),
189
- uploadFile: uploadFile(client, options.bucket)
178
+ uploadFile: uploadFile(client, options),
179
+ deleteFile: deleteFile(client, options),
180
+ getUploadURL: getUploadURL(client, options.bucket),
181
+ getDownloadURL: getDownloadURL(options)
190
182
  };
191
183
  }
192
184
  // Annotate the CommonJS export names for ESM import in node:
@@ -1,3 +1,2 @@
1
1
  export { setupFileUpload } from './setup.mjs';
2
- import '@aws-sdk/client-s3';
3
2
  import 'next/server';
@@ -1,3 +1,2 @@
1
1
  export { setupFileUpload } from './setup.js';
2
- import '@aws-sdk/client-s3';
3
2
  import 'next/server';
@@ -1,5 +1,4 @@
1
1
  // src/file/put.ts
2
- import { waitUntil as waitUntil2 } from "@vercel/functions";
3
2
  import { NextResponse as NextResponse3 } from "next/server";
4
3
  import { v4 } from "uuid";
5
4
 
@@ -50,14 +49,12 @@ var getContext = (refreshKey, signingKey, req) => {
50
49
  };
51
50
 
52
51
  // src/file/utils.ts
53
- import { createHash } from "crypto";
54
52
  import {
55
53
  DeleteObjectCommand,
56
54
  PutObjectCommand,
57
55
  S3Client
58
56
  } from "@aws-sdk/client-s3";
59
57
  import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
60
- import { waitUntil } from "@vercel/functions";
61
58
  var getS3Client = (options) => new S3Client({
62
59
  region: options.region,
63
60
  credentials: {
@@ -66,30 +63,34 @@ var getS3Client = (options) => new S3Client({
66
63
  }
67
64
  });
68
65
  var getURLPrefix = (options) => `https://${options.bucket}.s3.${options.region}.amazonaws.com/`;
69
- function getHash(keys) {
70
- return createHash("sha256").update(keys.join("/")).digest("hex");
66
+ function getKey(keys) {
67
+ return typeof keys === "string" ? keys : keys.join("/");
71
68
  }
72
- var getUploadFileURL = (client, Bucket) => (keys, isPublic) => {
69
+ var getUploadURL = (client, Bucket) => (keys) => {
73
70
  const command = new PutObjectCommand({
74
71
  Bucket,
75
- Key: getHash(keys),
76
- ACL: isPublic ? "public-read" : void 0
72
+ Key: getKey(keys),
73
+ ACL: "public-read"
77
74
  });
78
75
  return getSignedUrl(client, command, { expiresIn: 300 });
79
76
  };
80
- var getFileURL = (options) => (keys) => {
81
- if (typeof keys === "string") return `${getURLPrefix(options)}${keys}`;
82
- return `${getURLPrefix(options)}${getHash(keys)}`;
77
+ var getDownloadURL = (options) => (keys) => {
78
+ return `${getURLPrefix(options)}${getKey(keys)}`;
83
79
  };
84
- var uploadImage = (client, options) => async (url, key, blob) => {
85
- const photoBlob = blob || await fetch(url).then((file) => file.blob());
86
- if (photoBlob) {
87
- waitUntil(uploadFile(client, options.bucket)(photoBlob, getHash(key)));
88
- return getFileURL(options)(key);
80
+ var uploadFile = (client, options) => async (keys, {
81
+ url,
82
+ blob
83
+ }) => {
84
+ if (!blob && !url) return null;
85
+ const fileBlob = blob || await fetch(url).then((file) => file.blob());
86
+ if (fileBlob) {
87
+ const key = getKey(keys);
88
+ await uploadBlob(client, options.bucket)(fileBlob, key);
89
+ return getDownloadURL(options)(key);
89
90
  }
90
91
  return null;
91
92
  };
92
- var deleteImage = (client, options) => async (url) => {
93
+ var deleteFile = (client, options) => async (url) => {
93
94
  const key = url.split(getURLPrefix(options))[1];
94
95
  if (key) {
95
96
  try {
@@ -106,7 +107,7 @@ var deleteImage = (client, options) => async (url) => {
106
107
  }
107
108
  return false;
108
109
  };
109
- var uploadFile = (client, Bucket) => async (file, key) => {
110
+ var uploadBlob = (client, Bucket) => async (file, key) => {
110
111
  const fileBuffer = await file.arrayBuffer();
111
112
  return client.send(
112
113
  new PutObjectCommand({
@@ -126,33 +127,25 @@ var getFileUploadPutRoute = (options, client) => async (req) => {
126
127
  if (!ctx?.userId || ctx.isRefreshID)
127
128
  return NextResponse3.json({ error: "unauthorized" }, { status: 401 });
128
129
  const formData = await req.formData();
129
- const type = formData.get("type");
130
- const sync = Boolean(formData.get("sync"));
131
130
  const file = formData.get("file");
131
+ if (!file) return NextResponse3.json({ error: "no file" }, { status: 400 });
132
132
  const data = formData.get("data");
133
- const imageKey = v4();
134
- const url = file ? getFileURL(options)(imageKey) : null;
135
- const handleKeyProcessing = async () => {
136
- if (file) await uploadFile(client, options.bucket)(file, imageKey);
137
- if (!type || !ctx.userId || ctx.isRefreshID) return;
138
- const { deleteURL, response } = await options.processFile({
139
- url,
140
- type,
141
- userId: ctx.userId,
142
- data: typeof data === "string" ? JSON.parse(data) : void 0
143
- });
144
- if (deleteURL) await deleteImage(client, options)(deleteURL);
145
- return response;
133
+ const inputData = {
134
+ type: formData.get("type") + "",
135
+ userId: ctx.userId,
136
+ data: typeof data === "string" ? JSON.parse(data) : void 0
146
137
  };
147
- if (!sync) {
148
- waitUntil2(handleKeyProcessing());
149
- return NextResponse3.json({ url });
150
- } else {
151
- return NextResponse3.json({
152
- url,
153
- response: await handleKeyProcessing()
154
- });
155
- }
138
+ const fileKey = options.getKey ? await options.getKey(inputData) : v4();
139
+ const url = getDownloadURL(options)(fileKey);
140
+ await uploadBlob(client, options.bucket)(file, fileKey);
141
+ const onUploadResponse = await options.onUpload({
142
+ ...inputData,
143
+ url
144
+ });
145
+ return NextResponse3.json({
146
+ url,
147
+ onUploadResponse
148
+ });
156
149
  };
157
150
 
158
151
  // src/file/setup.ts
@@ -160,11 +153,10 @@ function setupFileUpload(options) {
160
153
  const client = getS3Client(options);
161
154
  return {
162
155
  PUT: getFileUploadPutRoute(options, client),
163
- getUploadFileURL: getUploadFileURL(client, options.bucket),
164
- uploadImage: uploadImage(client, options),
165
- deleteImage: deleteImage(client, options),
166
- getFileURL: getFileURL(options),
167
- uploadFile: uploadFile(client, options.bucket)
156
+ uploadFile: uploadFile(client, options),
157
+ deleteFile: deleteFile(client, options),
158
+ getUploadURL: getUploadURL(client, options.bucket),
159
+ getDownloadURL: getDownloadURL(options)
168
160
  };
169
161
  }
170
162
  export {