naystack 1.2.16 → 1.2.19

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.
Files changed (59) hide show
  1. package/dist/auth/email/client.cjs.js +35 -7
  2. package/dist/auth/email/client.d.mts +13 -1
  3. package/dist/auth/email/client.d.ts +13 -1
  4. package/dist/auth/email/client.esm.js +34 -4
  5. package/dist/auth/email/index.cjs.js +23 -18
  6. package/dist/auth/email/index.d.mts +4 -12
  7. package/dist/auth/email/index.d.ts +4 -12
  8. package/dist/auth/email/index.esm.js +23 -18
  9. package/dist/auth/email/routes/delete.cjs.js +45 -1
  10. package/dist/auth/email/routes/delete.esm.js +45 -1
  11. package/dist/auth/email/routes/get.cjs.js +6 -2
  12. package/dist/auth/email/routes/get.d.mts +2 -2
  13. package/dist/auth/email/routes/get.d.ts +2 -2
  14. package/dist/auth/email/routes/get.esm.js +6 -2
  15. package/dist/auth/email/routes/post.cjs.js +3 -1
  16. package/dist/auth/email/routes/post.esm.js +3 -1
  17. package/dist/auth/email/routes/put.cjs.js +3 -0
  18. package/dist/auth/email/routes/put.esm.js +3 -0
  19. package/dist/auth/email/types.d.mts +5 -3
  20. package/dist/auth/email/types.d.ts +5 -3
  21. package/dist/auth/email/utils.cjs.js +8 -8
  22. package/dist/auth/email/utils.d.mts +3 -5
  23. package/dist/auth/email/utils.d.ts +3 -5
  24. package/dist/auth/email/utils.esm.js +7 -7
  25. package/dist/auth/index.cjs.js +23 -18
  26. package/dist/auth/index.d.mts +1 -0
  27. package/dist/auth/index.d.ts +1 -0
  28. package/dist/auth/index.esm.js +23 -18
  29. package/dist/client/hooks.d.mts +2 -2
  30. package/dist/client/hooks.d.ts +2 -2
  31. package/dist/file/client.cjs.js +20 -23
  32. package/dist/file/client.d.mts +4 -10
  33. package/dist/file/client.d.ts +4 -10
  34. package/dist/file/client.esm.js +19 -22
  35. package/dist/file/index.cjs.js +47 -55
  36. package/dist/file/index.d.mts +0 -1
  37. package/dist/file/index.d.ts +0 -1
  38. package/dist/file/index.esm.js +47 -55
  39. package/dist/file/put.cjs.js +29 -58
  40. package/dist/file/put.d.mts +2 -1
  41. package/dist/file/put.d.ts +2 -1
  42. package/dist/file/put.esm.js +29 -58
  43. package/dist/file/setup.cjs.js +47 -55
  44. package/dist/file/setup.d.mts +16 -12
  45. package/dist/file/setup.d.ts +16 -12
  46. package/dist/file/setup.esm.js +47 -55
  47. package/dist/file/utils.cjs.js +29 -27
  48. package/dist/file/utils.d.mts +9 -6
  49. package/dist/file/utils.d.ts +9 -6
  50. package/dist/file/utils.esm.js +24 -22
  51. package/dist/graphql/client.cjs.js +11 -34
  52. package/dist/graphql/client.d.mts +3 -9
  53. package/dist/graphql/client.d.ts +3 -9
  54. package/dist/graphql/client.esm.js +8 -30
  55. package/dist/graphql/server.d.mts +2 -2
  56. package/dist/graphql/server.d.ts +2 -2
  57. package/dist/graphql/types.d.mts +2 -0
  58. package/dist/graphql/types.d.ts +2 -0
  59. package/package.json +1 -1
@@ -25,7 +25,6 @@ __export(setup_exports, {
25
25
  module.exports = __toCommonJS(setup_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
 
@@ -53,33 +52,31 @@ function getUserIdFromRefreshToken(refreshKey, refreshToken) {
53
52
  var import_server2 = require("next/server");
54
53
 
55
54
  // src/auth/email/utils.ts
56
- var getUserContext = (refreshKey, signingKey, req) => {
55
+ var getContext = (refreshKey, signingKey, req) => {
57
56
  const bearer = req.headers.get("authorization");
58
57
  if (!bearer) {
59
58
  const refresh = req.cookies.get("refresh")?.value;
60
59
  const userId = getUserIdFromRefreshToken(refreshKey, refresh);
61
- if (userId) return { refreshUserID: userId };
62
- return null;
60
+ if (userId) return { userId, isRefreshID: true };
61
+ return { userId: null };
63
62
  }
64
63
  const token = bearer.slice(7);
65
64
  try {
66
65
  const res = (0, import_jsonwebtoken2.verify)(token, signingKey);
67
66
  if (typeof res === "string") {
68
- return null;
67
+ return { userId: null };
69
68
  }
70
69
  return {
71
- accessUserId: res.id
70
+ userId: res.id
72
71
  };
73
72
  } catch {
74
73
  }
75
- return null;
74
+ return { userId: null };
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({
@@ -144,37 +145,29 @@ var uploadFile = (client, Bucket) => async (file, key) => {
144
145
 
145
146
  // src/file/put.ts
146
147
  var getFileUploadPutRoute = (options, client) => async (req) => {
147
- const ctx = getUserContext(options.refreshKey, options.signingKey, req);
148
- if (!ctx?.accessUserId)
148
+ const ctx = getContext(options.refreshKey, options.signingKey, req);
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.accessUserId) return;
160
- const { deleteURL, response } = await options.processFile({
161
- url,
162
- type,
163
- userId: ctx.accessUserId,
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,4 +1,3 @@
1
- import * as _aws_sdk_client_s3 from '@aws-sdk/client-s3';
2
1
  import * as next_server from 'next/server';
3
2
 
4
3
  interface SetupFileUploadOptions {
@@ -8,27 +7,32 @@ interface SetupFileUploadOptions {
8
7
  bucket: string;
9
8
  awsSecret: string;
10
9
  awsKey: string;
11
- processFile: (data: {
10
+ getKey?: (data: {
11
+ type: string;
12
+ userId: number;
13
+ data: object;
14
+ }) => Promise<string>;
15
+ onUpload: (data: {
12
16
  url: string | null;
13
17
  type: string;
14
18
  userId: number;
15
19
  data: object;
16
- }) => Promise<{
17
- deleteURL?: string;
18
- response?: object;
19
- }>;
20
+ }) => Promise<object>;
20
21
  }
21
22
  declare function setupFileUpload(options: SetupFileUploadOptions): {
22
23
  PUT: (req: next_server.NextRequest) => Promise<next_server.NextResponse<{
23
24
  error: string;
24
25
  }> | next_server.NextResponse<{
25
- url: string | null;
26
+ url: string;
27
+ onUploadResponse: object;
26
28
  }>>;
27
- getUploadFileURL: (keys: string[], isPublic?: boolean) => Promise<string>;
28
- uploadImage: (url: string, key: string[], blob?: Blob) => Promise<string | null>;
29
- deleteImage: (url: string) => Promise<boolean>;
30
- getFileURL: (keys: string | string[]) => string;
31
- uploadFile: (file: File | Blob, key: string) => Promise<_aws_sdk_client_s3.PutObjectCommandOutput>;
29
+ uploadFile: (keys: string | string[], { url, blob, }: {
30
+ blob?: Blob;
31
+ url?: string;
32
+ }) => Promise<string | null>;
33
+ deleteFile: (url: string) => Promise<boolean>;
34
+ getUploadURL: (keys: string | string[]) => Promise<string>;
35
+ getDownloadURL: (keys: string | string[]) => string;
32
36
  };
33
37
 
34
38
  export { type SetupFileUploadOptions, setupFileUpload };
@@ -1,4 +1,3 @@
1
- import * as _aws_sdk_client_s3 from '@aws-sdk/client-s3';
2
1
  import * as next_server from 'next/server';
3
2
 
4
3
  interface SetupFileUploadOptions {
@@ -8,27 +7,32 @@ interface SetupFileUploadOptions {
8
7
  bucket: string;
9
8
  awsSecret: string;
10
9
  awsKey: string;
11
- processFile: (data: {
10
+ getKey?: (data: {
11
+ type: string;
12
+ userId: number;
13
+ data: object;
14
+ }) => Promise<string>;
15
+ onUpload: (data: {
12
16
  url: string | null;
13
17
  type: string;
14
18
  userId: number;
15
19
  data: object;
16
- }) => Promise<{
17
- deleteURL?: string;
18
- response?: object;
19
- }>;
20
+ }) => Promise<object>;
20
21
  }
21
22
  declare function setupFileUpload(options: SetupFileUploadOptions): {
22
23
  PUT: (req: next_server.NextRequest) => Promise<next_server.NextResponse<{
23
24
  error: string;
24
25
  }> | next_server.NextResponse<{
25
- url: string | null;
26
+ url: string;
27
+ onUploadResponse: object;
26
28
  }>>;
27
- getUploadFileURL: (keys: string[], isPublic?: boolean) => Promise<string>;
28
- uploadImage: (url: string, key: string[], blob?: Blob) => Promise<string | null>;
29
- deleteImage: (url: string) => Promise<boolean>;
30
- getFileURL: (keys: string | string[]) => string;
31
- uploadFile: (file: File | Blob, key: string) => Promise<_aws_sdk_client_s3.PutObjectCommandOutput>;
29
+ uploadFile: (keys: string | string[], { url, blob, }: {
30
+ blob?: Blob;
31
+ url?: string;
32
+ }) => Promise<string | null>;
33
+ deleteFile: (url: string) => Promise<boolean>;
34
+ getUploadURL: (keys: string | string[]) => Promise<string>;
35
+ getDownloadURL: (keys: string | string[]) => string;
32
36
  };
33
37
 
34
38
  export { type SetupFileUploadOptions, setupFileUpload };
@@ -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
 
@@ -27,37 +26,35 @@ function getUserIdFromRefreshToken(refreshKey, refreshToken) {
27
26
  import { NextResponse as NextResponse2 } from "next/server";
28
27
 
29
28
  // src/auth/email/utils.ts
30
- var getUserContext = (refreshKey, signingKey, req) => {
29
+ var getContext = (refreshKey, signingKey, req) => {
31
30
  const bearer = req.headers.get("authorization");
32
31
  if (!bearer) {
33
32
  const refresh = req.cookies.get("refresh")?.value;
34
33
  const userId = getUserIdFromRefreshToken(refreshKey, refresh);
35
- if (userId) return { refreshUserID: userId };
36
- return null;
34
+ if (userId) return { userId, isRefreshID: true };
35
+ return { userId: null };
37
36
  }
38
37
  const token = bearer.slice(7);
39
38
  try {
40
39
  const res = verify2(token, signingKey);
41
40
  if (typeof res === "string") {
42
- return null;
41
+ return { userId: null };
43
42
  }
44
43
  return {
45
- accessUserId: res.id
44
+ userId: res.id
46
45
  };
47
46
  } catch {
48
47
  }
49
- return null;
48
+ return { userId: null };
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({
@@ -122,37 +123,29 @@ var uploadFile = (client, Bucket) => async (file, key) => {
122
123
 
123
124
  // src/file/put.ts
124
125
  var getFileUploadPutRoute = (options, client) => async (req) => {
125
- const ctx = getUserContext(options.refreshKey, options.signingKey, req);
126
- if (!ctx?.accessUserId)
126
+ const ctx = getContext(options.refreshKey, options.signingKey, req);
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.accessUserId) return;
138
- const { deleteURL, response } = await options.processFile({
139
- url,
140
- type,
141
- userId: ctx.accessUserId,
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 {
@@ -20,18 +20,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/file/utils.ts
21
21
  var utils_exports = {};
22
22
  __export(utils_exports, {
23
- deleteImage: () => deleteImage,
24
- getFileURL: () => getFileURL,
23
+ deleteFile: () => deleteFile,
24
+ getDownloadURL: () => getDownloadURL,
25
25
  getS3Client: () => getS3Client,
26
- getUploadFileURL: () => getUploadFileURL,
27
- uploadFile: () => uploadFile,
28
- uploadImage: () => uploadImage
26
+ getUploadURL: () => getUploadURL,
27
+ uploadBlob: () => uploadBlob,
28
+ uploadFile: () => uploadFile
29
29
  });
30
30
  module.exports = __toCommonJS(utils_exports);
31
- var import_node_crypto = require("crypto");
32
31
  var import_client_s3 = require("@aws-sdk/client-s3");
33
32
  var import_s3_request_presigner = require("@aws-sdk/s3-request-presigner");
34
- var import_functions = require("@vercel/functions");
35
33
  var getS3Client = (options) => new import_client_s3.S3Client({
36
34
  region: options.region,
37
35
  credentials: {
@@ -40,30 +38,34 @@ var getS3Client = (options) => new import_client_s3.S3Client({
40
38
  }
41
39
  });
42
40
  var getURLPrefix = (options) => `https://${options.bucket}.s3.${options.region}.amazonaws.com/`;
43
- function getHash(keys) {
44
- return (0, import_node_crypto.createHash)("sha256").update(keys.join("/")).digest("hex");
41
+ function getKey(keys) {
42
+ return typeof keys === "string" ? keys : keys.join("/");
45
43
  }
46
- var getUploadFileURL = (client, Bucket) => (keys, isPublic) => {
44
+ var getUploadURL = (client, Bucket) => (keys) => {
47
45
  const command = new import_client_s3.PutObjectCommand({
48
46
  Bucket,
49
- Key: getHash(keys),
50
- ACL: isPublic ? "public-read" : void 0
47
+ Key: getKey(keys),
48
+ ACL: "public-read"
51
49
  });
52
50
  return (0, import_s3_request_presigner.getSignedUrl)(client, command, { expiresIn: 300 });
53
51
  };
54
- var getFileURL = (options) => (keys) => {
55
- if (typeof keys === "string") return `${getURLPrefix(options)}${keys}`;
56
- return `${getURLPrefix(options)}${getHash(keys)}`;
52
+ var getDownloadURL = (options) => (keys) => {
53
+ return `${getURLPrefix(options)}${getKey(keys)}`;
57
54
  };
58
- var uploadImage = (client, options) => async (url, key, blob) => {
59
- const photoBlob = blob || await fetch(url).then((file) => file.blob());
60
- if (photoBlob) {
61
- (0, import_functions.waitUntil)(uploadFile(client, options.bucket)(photoBlob, getHash(key)));
62
- return getFileURL(options)(key);
55
+ var uploadFile = (client, options) => async (keys, {
56
+ url,
57
+ blob
58
+ }) => {
59
+ if (!blob && !url) return null;
60
+ const fileBlob = blob || await fetch(url).then((file) => file.blob());
61
+ if (fileBlob) {
62
+ const key = getKey(keys);
63
+ await uploadBlob(client, options.bucket)(fileBlob, key);
64
+ return getDownloadURL(options)(key);
63
65
  }
64
66
  return null;
65
67
  };
66
- var deleteImage = (client, options) => async (url) => {
68
+ var deleteFile = (client, options) => async (url) => {
67
69
  const key = url.split(getURLPrefix(options))[1];
68
70
  if (key) {
69
71
  try {
@@ -80,7 +82,7 @@ var deleteImage = (client, options) => async (url) => {
80
82
  }
81
83
  return false;
82
84
  };
83
- var uploadFile = (client, Bucket) => async (file, key) => {
85
+ var uploadBlob = (client, Bucket) => async (file, key) => {
84
86
  const fileBuffer = await file.arrayBuffer();
85
87
  return client.send(
86
88
  new import_client_s3.PutObjectCommand({
@@ -95,10 +97,10 @@ var uploadFile = (client, Bucket) => async (file, key) => {
95
97
  };
96
98
  // Annotate the CommonJS export names for ESM import in node:
97
99
  0 && (module.exports = {
98
- deleteImage,
99
- getFileURL,
100
+ deleteFile,
101
+ getDownloadURL,
100
102
  getS3Client,
101
- getUploadFileURL,
102
- uploadFile,
103
- uploadImage
103
+ getUploadURL,
104
+ uploadBlob,
105
+ uploadFile
104
106
  });
@@ -4,10 +4,13 @@ import { SetupFileUploadOptions } from './setup.mjs';
4
4
  import 'next/server';
5
5
 
6
6
  declare const getS3Client: (options: SetupFileUploadOptions) => S3Client;
7
- declare const getUploadFileURL: (client: S3Client, Bucket: string) => (keys: string[], isPublic?: boolean) => Promise<string>;
8
- declare const getFileURL: (options: SetupFileUploadOptions) => (keys: string | string[]) => string;
9
- declare const uploadImage: (client: S3Client, options: SetupFileUploadOptions) => (url: string, key: string[], blob?: Blob) => Promise<string | null>;
10
- declare const deleteImage: (client: S3Client, options: SetupFileUploadOptions) => (url: string) => Promise<boolean>;
11
- declare const uploadFile: (client: S3Client, Bucket: string) => (file: File | Blob, key: string) => Promise<_aws_sdk_client_s3.PutObjectCommandOutput>;
7
+ declare const getUploadURL: (client: S3Client, Bucket: string) => (keys: string | string[]) => Promise<string>;
8
+ declare const getDownloadURL: (options: SetupFileUploadOptions) => (keys: string | string[]) => string;
9
+ declare const uploadFile: (client: S3Client, options: SetupFileUploadOptions) => (keys: string | string[], { url, blob, }: {
10
+ blob?: Blob;
11
+ url?: string;
12
+ }) => Promise<string | null>;
13
+ declare const deleteFile: (client: S3Client, options: SetupFileUploadOptions) => (url: string) => Promise<boolean>;
14
+ declare const uploadBlob: (client: S3Client, Bucket: string) => (file: File | Blob, key: string) => Promise<_aws_sdk_client_s3.PutObjectCommandOutput>;
12
15
 
13
- export { deleteImage, getFileURL, getS3Client, getUploadFileURL, uploadFile, uploadImage };
16
+ export { deleteFile, getDownloadURL, getS3Client, getUploadURL, uploadBlob, uploadFile };
@@ -4,10 +4,13 @@ import { SetupFileUploadOptions } from './setup.js';
4
4
  import 'next/server';
5
5
 
6
6
  declare const getS3Client: (options: SetupFileUploadOptions) => S3Client;
7
- declare const getUploadFileURL: (client: S3Client, Bucket: string) => (keys: string[], isPublic?: boolean) => Promise<string>;
8
- declare const getFileURL: (options: SetupFileUploadOptions) => (keys: string | string[]) => string;
9
- declare const uploadImage: (client: S3Client, options: SetupFileUploadOptions) => (url: string, key: string[], blob?: Blob) => Promise<string | null>;
10
- declare const deleteImage: (client: S3Client, options: SetupFileUploadOptions) => (url: string) => Promise<boolean>;
11
- declare const uploadFile: (client: S3Client, Bucket: string) => (file: File | Blob, key: string) => Promise<_aws_sdk_client_s3.PutObjectCommandOutput>;
7
+ declare const getUploadURL: (client: S3Client, Bucket: string) => (keys: string | string[]) => Promise<string>;
8
+ declare const getDownloadURL: (options: SetupFileUploadOptions) => (keys: string | string[]) => string;
9
+ declare const uploadFile: (client: S3Client, options: SetupFileUploadOptions) => (keys: string | string[], { url, blob, }: {
10
+ blob?: Blob;
11
+ url?: string;
12
+ }) => Promise<string | null>;
13
+ declare const deleteFile: (client: S3Client, options: SetupFileUploadOptions) => (url: string) => Promise<boolean>;
14
+ declare const uploadBlob: (client: S3Client, Bucket: string) => (file: File | Blob, key: string) => Promise<_aws_sdk_client_s3.PutObjectCommandOutput>;
12
15
 
13
- export { deleteImage, getFileURL, getS3Client, getUploadFileURL, uploadFile, uploadImage };
16
+ export { deleteFile, getDownloadURL, getS3Client, getUploadURL, uploadBlob, uploadFile };