naystack 1.5.11 → 1.5.13

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 (37) hide show
  1. package/dist/auth/index.cjs.js +6 -5
  2. package/dist/auth/index.d.mts +1 -1
  3. package/dist/auth/index.d.ts +1 -1
  4. package/dist/auth/index.esm.js +5 -5
  5. package/dist/auth/instagram/client.cjs.js +4 -4
  6. package/dist/auth/instagram/client.d.mts +11 -9
  7. package/dist/auth/instagram/client.d.ts +11 -9
  8. package/dist/auth/instagram/client.esm.js +3 -3
  9. package/dist/auth/instagram/index.cjs.js +6 -5
  10. package/dist/auth/instagram/index.d.mts +3 -6
  11. package/dist/auth/instagram/index.d.ts +3 -6
  12. package/dist/auth/instagram/index.esm.js +5 -5
  13. package/dist/auth/instagram/route.cjs.js +2 -2
  14. package/dist/auth/instagram/route.d.mts +1 -1
  15. package/dist/auth/instagram/route.d.ts +1 -1
  16. package/dist/auth/instagram/route.esm.js +2 -2
  17. package/dist/auth/instagram/utils.cjs.js +3 -3
  18. package/dist/auth/instagram/utils.d.mts +2 -2
  19. package/dist/auth/instagram/utils.d.ts +2 -2
  20. package/dist/auth/instagram/utils.esm.js +2 -2
  21. package/dist/file/index.cjs.js +30 -16
  22. package/dist/file/index.d.mts +2 -0
  23. package/dist/file/index.d.ts +2 -0
  24. package/dist/file/index.esm.js +25 -15
  25. package/dist/file/put.cjs.js +18 -3
  26. package/dist/file/put.d.mts +1 -3
  27. package/dist/file/put.d.ts +1 -3
  28. package/dist/file/put.esm.js +18 -3
  29. package/dist/file/setup.cjs.js +13 -48
  30. package/dist/file/setup.d.mts +0 -7
  31. package/dist/file/setup.d.ts +0 -7
  32. package/dist/file/setup.esm.js +13 -48
  33. package/dist/file/utils.cjs.js +14 -8
  34. package/dist/file/utils.d.mts +22 -26
  35. package/dist/file/utils.d.ts +22 -26
  36. package/dist/file/utils.esm.js +14 -7
  37. package/package.json +1 -1
@@ -1,21 +1,14 @@
1
1
  import * as _aws_sdk_client_s3 from '@aws-sdk/client-s3';
2
- import { S3Client } from '@aws-sdk/client-s3';
3
2
 
4
3
  /**
5
- * Creates an S3 client using env credentials (`AWS_ACCESS_KEY_ID`, `AWS_ACCESS_KEY_SECRET`, `AWS_REGION`).
6
- * @returns Configured `S3Client` instance.
7
- * @category File
8
- */
9
- declare const getS3Client: () => S3Client;
10
- /**
11
- * Returns a function that generates a presigned PUT URL for uploading to the given S3 key(s).
12
- * The presigned URL expires after 5 minutes.
4
+ * Generates a presigned PUT URL for uploading a file to the given S3 key(s).
5
+ * The URL expires after 5 minutes.
13
6
  *
14
- * @param client - S3 client instance.
15
- * @returns `(keys: string | string[]) => Promise<string>` — the presigned upload URL.
7
+ * @param keys - S3 key or key path segments (array joined by `/`).
8
+ * @returns A presigned upload URL.
16
9
  * @category File
17
10
  */
18
- declare const getUploadURL: (client: S3Client) => (keys: string | string[]) => Promise<string>;
11
+ declare const getUploadURL: (keys: string | string[]) => Promise<string> | undefined;
19
12
  /**
20
13
  * Builds the public download URL for one or more keys in the configured S3 bucket.
21
14
  *
@@ -25,31 +18,34 @@ declare const getUploadURL: (client: S3Client) => (keys: string | string[]) => P
25
18
  */
26
19
  declare const getDownloadURL: (keys: string | string[]) => string;
27
20
  /**
28
- * Returns a function that uploads a file (by URL or Blob) to the given S3 key(s).
21
+ * Uploads a file to S3 at the given key(s), either from a Blob or a remote URL.
29
22
  *
30
- * @param client - S3 client instance.
31
- * @returns `(keys, { url?, blob? }) => Promise<string | null>` — the download URL on success, or `null` if no input.
23
+ * @param keys - S3 key or key path segments (array joined by `/`).
24
+ * @param options.blob - A Blob/File to upload directly.
25
+ * @param options.url - A remote URL to fetch and upload. Ignored if `blob` is provided.
26
+ * @returns The public download URL of the uploaded file, or `null` if neither `blob` nor `url` was provided.
32
27
  * @category File
33
28
  */
34
- declare const uploadFile: (client: S3Client) => (keys: string | string[], { url, blob, }: {
29
+ declare const uploadFile: (keys: string | string[], { url, blob, }: {
35
30
  blob?: Blob;
36
31
  url?: string;
37
- }) => Promise<string | null>;
32
+ }) => Promise<string | null | undefined>;
38
33
  /**
39
- * Returns a function that deletes an S3 object by its full URL.
34
+ * Deletes an S3 object identified by its full public URL.
40
35
  *
41
- * @param client - S3 client instance.
42
- * @returns `(url: string) => Promise<boolean>` `true` if deleted successfully, `false` otherwise.
36
+ * @param url - The full public URL of the S3 object to delete.
37
+ * @returns `true` if the object was deleted successfully, `false` otherwise.
43
38
  * @category File
44
39
  */
45
- declare const deleteFile: (client: S3Client) => (url: string) => Promise<boolean>;
40
+ declare const deleteFile: (url: string) => Promise<boolean | undefined>;
46
41
  /**
47
- * Returns a function that uploads a Blob/File to S3 at the given key.
42
+ * Uploads a Blob or File to S3 at the given key with public-read ACL.
48
43
  *
49
- * @param client - S3 client instance.
50
- * @returns `(file: File | Blob, key: string) => Promise<PutObjectCommandOutput>`.
44
+ * @param file - The Blob or File to upload.
45
+ * @param key - The S3 object key.
46
+ * @returns The `PutObjectCommandOutput` from S3.
51
47
  * @category File
52
48
  */
53
- declare const uploadBlob: (client: S3Client) => (file: File | Blob, key: string) => Promise<_aws_sdk_client_s3.PutObjectCommandOutput>;
49
+ declare const uploadBlob: (file: File | Blob, key: string) => Promise<_aws_sdk_client_s3.PutObjectCommandOutput | undefined>;
54
50
 
55
- export { deleteFile, getDownloadURL, getS3Client, getUploadURL, uploadBlob, uploadFile };
51
+ export { deleteFile, getDownloadURL, getUploadURL, uploadBlob, uploadFile };
@@ -56,7 +56,7 @@ function getEnv(key, skipCheck) {
56
56
  }
57
57
 
58
58
  // src/file/utils.ts
59
- var getS3Client = () => new S3Client({
59
+ var client = new S3Client({
60
60
  region: getEnv("AWS_REGION" /* AWS_REGION */),
61
61
  credentials: {
62
62
  accessKeyId: getEnv("AWS_ACCESS_KEY_ID" /* AWS_ACCESS_KEY_ID */),
@@ -69,7 +69,8 @@ var URL_PREFIX = `https://${getEnv("AWS_BUCKET" /* AWS_BUCKET */)}.s3.${getEnv(
69
69
  function getKey(keys) {
70
70
  return typeof keys === "string" ? keys : keys.join("/");
71
71
  }
72
- var getUploadURL = (client) => (keys) => {
72
+ var getUploadURL = (keys) => {
73
+ if (!checkClient(client)) return;
73
74
  const command = new PutObjectCommand({
74
75
  Bucket: getEnv("AWS_BUCKET" /* AWS_BUCKET */),
75
76
  Key: getKey(keys),
@@ -80,21 +81,23 @@ var getUploadURL = (client) => (keys) => {
80
81
  var getDownloadURL = (keys) => {
81
82
  return `${URL_PREFIX}${getKey(keys)}`;
82
83
  };
83
- var uploadFile = (client) => async (keys, {
84
+ var uploadFile = async (keys, {
84
85
  url,
85
86
  blob
86
87
  }) => {
88
+ if (!checkClient(client)) return;
87
89
  if (!blob && !url) return null;
88
90
  const fileBlob = blob || await fetch(url).then((file) => file.blob());
89
91
  if (fileBlob) {
90
92
  const key = getKey(keys);
91
- await uploadBlob(client)(fileBlob, key);
93
+ await uploadBlob(fileBlob, key);
92
94
  return getDownloadURL(key);
93
95
  }
94
96
  return null;
95
97
  };
96
- var deleteFile = (client) => async (url) => {
98
+ var deleteFile = async (url) => {
97
99
  const key = url.split(URL_PREFIX)[1];
100
+ if (!checkClient(client)) return;
98
101
  if (key) {
99
102
  try {
100
103
  await client.send(
@@ -110,7 +113,12 @@ var deleteFile = (client) => async (url) => {
110
113
  }
111
114
  return false;
112
115
  };
113
- var uploadBlob = (client) => async (file, key) => {
116
+ function checkClient(client2) {
117
+ if (!client2) throw new Error("Client does not exist");
118
+ return true;
119
+ }
120
+ var uploadBlob = async (file, key) => {
121
+ if (!checkClient(client)) return;
114
122
  const fileBuffer = await file.arrayBuffer();
115
123
  return client.send(
116
124
  new PutObjectCommand({
@@ -126,7 +134,6 @@ var uploadBlob = (client) => async (file, key) => {
126
134
  export {
127
135
  deleteFile,
128
136
  getDownloadURL,
129
- getS3Client,
130
137
  getUploadURL,
131
138
  uploadBlob,
132
139
  uploadFile
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "naystack",
3
- "version": "1.5.11",
3
+ "version": "1.5.13",
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",