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.
- package/dist/auth/index.cjs.js +6 -5
- package/dist/auth/index.d.mts +1 -1
- package/dist/auth/index.d.ts +1 -1
- package/dist/auth/index.esm.js +5 -5
- package/dist/auth/instagram/client.cjs.js +4 -4
- package/dist/auth/instagram/client.d.mts +11 -9
- package/dist/auth/instagram/client.d.ts +11 -9
- package/dist/auth/instagram/client.esm.js +3 -3
- package/dist/auth/instagram/index.cjs.js +6 -5
- package/dist/auth/instagram/index.d.mts +3 -6
- package/dist/auth/instagram/index.d.ts +3 -6
- package/dist/auth/instagram/index.esm.js +5 -5
- package/dist/auth/instagram/route.cjs.js +2 -2
- package/dist/auth/instagram/route.d.mts +1 -1
- package/dist/auth/instagram/route.d.ts +1 -1
- package/dist/auth/instagram/route.esm.js +2 -2
- package/dist/auth/instagram/utils.cjs.js +3 -3
- package/dist/auth/instagram/utils.d.mts +2 -2
- package/dist/auth/instagram/utils.d.ts +2 -2
- package/dist/auth/instagram/utils.esm.js +2 -2
- package/dist/file/index.cjs.js +30 -16
- package/dist/file/index.d.mts +2 -0
- package/dist/file/index.d.ts +2 -0
- package/dist/file/index.esm.js +25 -15
- package/dist/file/put.cjs.js +18 -3
- package/dist/file/put.d.mts +1 -3
- package/dist/file/put.d.ts +1 -3
- package/dist/file/put.esm.js +18 -3
- package/dist/file/setup.cjs.js +13 -48
- package/dist/file/setup.d.mts +0 -7
- package/dist/file/setup.d.ts +0 -7
- package/dist/file/setup.esm.js +13 -48
- package/dist/file/utils.cjs.js +14 -8
- package/dist/file/utils.d.mts +22 -26
- package/dist/file/utils.d.ts +22 -26
- package/dist/file/utils.esm.js +14 -7
- package/package.json +1 -1
package/dist/file/utils.d.ts
CHANGED
|
@@ -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
|
-
*
|
|
6
|
-
*
|
|
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
|
|
15
|
-
* @returns
|
|
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: (
|
|
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
|
-
*
|
|
21
|
+
* Uploads a file to S3 at the given key(s), either from a Blob or a remote URL.
|
|
29
22
|
*
|
|
30
|
-
* @param
|
|
31
|
-
* @
|
|
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: (
|
|
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
|
-
*
|
|
34
|
+
* Deletes an S3 object identified by its full public URL.
|
|
40
35
|
*
|
|
41
|
-
* @param
|
|
42
|
-
* @returns `
|
|
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: (
|
|
40
|
+
declare const deleteFile: (url: string) => Promise<boolean | undefined>;
|
|
46
41
|
/**
|
|
47
|
-
*
|
|
42
|
+
* Uploads a Blob or File to S3 at the given key with public-read ACL.
|
|
48
43
|
*
|
|
49
|
-
* @param
|
|
50
|
-
* @
|
|
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: (
|
|
49
|
+
declare const uploadBlob: (file: File | Blob, key: string) => Promise<_aws_sdk_client_s3.PutObjectCommandOutput | undefined>;
|
|
54
50
|
|
|
55
|
-
export { deleteFile, getDownloadURL,
|
|
51
|
+
export { deleteFile, getDownloadURL, getUploadURL, uploadBlob, uploadFile };
|
package/dist/file/utils.esm.js
CHANGED
|
@@ -56,7 +56,7 @@ function getEnv(key, skipCheck) {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
// src/file/utils.ts
|
|
59
|
-
var
|
|
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 = (
|
|
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 =
|
|
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(
|
|
93
|
+
await uploadBlob(fileBlob, key);
|
|
92
94
|
return getDownloadURL(key);
|
|
93
95
|
}
|
|
94
96
|
return null;
|
|
95
97
|
};
|
|
96
|
-
var deleteFile =
|
|
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
|
-
|
|
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
|