naystack 1.8.11 → 1.8.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/README.md +189 -31
- package/dist/auth/index.cjs.js +158 -18
- package/dist/auth/index.d.mts +3 -1
- package/dist/auth/index.d.ts +3 -1
- package/dist/auth/index.esm.js +158 -18
- package/dist/auth/instagram/index.cjs.js +158 -18
- package/dist/auth/instagram/index.d.mts +6 -1
- package/dist/auth/instagram/index.d.ts +6 -1
- package/dist/auth/instagram/index.esm.js +158 -18
- package/dist/auth/instagram/route.cjs.js +158 -18
- package/dist/auth/instagram/route.d.mts +3 -1
- package/dist/auth/instagram/route.d.ts +3 -1
- package/dist/auth/instagram/route.esm.js +158 -18
- package/dist/auth/instagram/utils.cjs.js +2 -2
- package/dist/auth/instagram/utils.d.mts +13 -2
- package/dist/auth/instagram/utils.d.ts +13 -2
- package/dist/auth/instagram/utils.esm.js +2 -2
- package/dist/file/index.cjs.js +9 -6
- package/dist/file/index.d.mts +1 -1
- package/dist/file/index.d.ts +1 -1
- package/dist/file/index.esm.js +9 -6
- package/dist/file/put.cjs.js +6 -4
- package/dist/file/put.d.mts +2 -0
- package/dist/file/put.d.ts +2 -0
- package/dist/file/put.esm.js +6 -4
- package/dist/file/setup.cjs.js +6 -4
- package/dist/file/setup.d.mts +22 -4
- package/dist/file/setup.d.ts +22 -4
- package/dist/file/setup.esm.js +6 -4
- package/dist/file/utils.cjs.js +6 -4
- package/dist/file/utils.d.mts +19 -3
- package/dist/file/utils.d.ts +19 -3
- package/dist/file/utils.esm.js +6 -4
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/socials/index.cjs.js +298 -72
- package/dist/socials/index.d.mts +6 -4
- package/dist/socials/index.d.ts +6 -4
- package/dist/socials/index.esm.js +296 -72
- package/dist/socials/instagram/getters.cjs.js +76 -25
- package/dist/socials/instagram/getters.d.mts +56 -6
- package/dist/socials/instagram/getters.d.ts +56 -6
- package/dist/socials/instagram/getters.esm.js +74 -25
- package/dist/socials/instagram/setters.cjs.js +192 -14
- package/dist/socials/instagram/setters.d.mts +43 -3
- package/dist/socials/instagram/setters.d.ts +43 -3
- package/dist/socials/instagram/setters.esm.js +191 -14
- package/dist/socials/instagram/types.d.mts +48 -11
- package/dist/socials/instagram/types.d.ts +48 -11
- package/dist/socials/instagram/utils.cjs.js +28 -15
- package/dist/socials/instagram/utils.d.mts +7 -18
- package/dist/socials/instagram/utils.d.ts +7 -18
- package/dist/socials/instagram/utils.esm.js +26 -14
- package/dist/socials/instagram/webhook.cjs.js +1 -1
- package/dist/socials/instagram/webhook.esm.js +1 -1
- package/dist/socials/meta/container.cjs.js +82 -0
- package/dist/socials/meta/container.d.mts +38 -0
- package/dist/socials/meta/container.d.ts +38 -0
- package/dist/socials/meta/container.esm.js +57 -0
- package/dist/socials/meta/request.cjs.js +60 -0
- package/dist/socials/meta/request.d.mts +50 -0
- package/dist/socials/meta/request.d.ts +50 -0
- package/dist/socials/meta/request.esm.js +34 -0
- package/dist/socials/meta/types.cjs.js +18 -0
- package/dist/socials/meta/types.d.mts +47 -0
- package/dist/socials/meta/types.d.ts +47 -0
- package/dist/socials/meta/types.esm.js +0 -0
- package/dist/socials/{meta-webhook.cjs.js → meta/webhook.cjs.js} +4 -4
- package/dist/socials/{meta-webhook.esm.js → meta/webhook.esm.js} +1 -1
- package/dist/socials/threads/getters.cjs.js +36 -11
- package/dist/socials/threads/getters.d.mts +23 -2
- package/dist/socials/threads/getters.d.ts +23 -2
- package/dist/socials/threads/getters.esm.js +35 -11
- package/dist/socials/threads/setters.cjs.js +150 -44
- package/dist/socials/threads/setters.d.mts +25 -34
- package/dist/socials/threads/setters.d.ts +25 -34
- package/dist/socials/threads/setters.esm.js +149 -41
- package/dist/socials/threads/types.d.mts +40 -1
- package/dist/socials/threads/types.d.ts +40 -1
- package/dist/socials/threads/utils.cjs.js +29 -11
- package/dist/socials/threads/utils.d.mts +8 -17
- package/dist/socials/threads/utils.d.ts +8 -17
- package/dist/socials/threads/utils.esm.js +27 -10
- package/dist/socials/threads/webhook.cjs.js +1 -1
- package/dist/socials/threads/webhook.esm.js +1 -1
- package/package.json +1 -1
- /package/dist/socials/{meta-webhook.d.mts → meta/webhook.d.mts} +0 -0
- /package/dist/socials/{meta-webhook.d.ts → meta/webhook.d.ts} +0 -0
package/dist/file/put.cjs.js
CHANGED
|
@@ -152,7 +152,7 @@ function checkClient(client2) {
|
|
|
152
152
|
if (!client2) throw new Error("Client does not exist");
|
|
153
153
|
return true;
|
|
154
154
|
}
|
|
155
|
-
var uploadBlob = async (file, key) => {
|
|
155
|
+
var uploadBlob = async (file, key, overrides) => {
|
|
156
156
|
if (!checkClient(client)) return;
|
|
157
157
|
const fileBuffer = await file.arrayBuffer();
|
|
158
158
|
return client.send(
|
|
@@ -162,7 +162,8 @@ var uploadBlob = async (file, key) => {
|
|
|
162
162
|
ACL: "public-read",
|
|
163
163
|
Body: Buffer.from(fileBuffer),
|
|
164
164
|
ContentType: file.type,
|
|
165
|
-
ContentLength: file.size
|
|
165
|
+
ContentLength: file.size,
|
|
166
|
+
...overrides
|
|
166
167
|
})
|
|
167
168
|
);
|
|
168
169
|
};
|
|
@@ -185,8 +186,9 @@ var getFileUploadPutRoute = (options) => async (req) => {
|
|
|
185
186
|
const fileKey = options.getKey ? await options.getKey(inputData) : (0, import_uuid.v4)();
|
|
186
187
|
const url = getDownloadURL(fileKey);
|
|
187
188
|
const blob = options.processFile ? await options.processFile(file, inputData) : file;
|
|
188
|
-
|
|
189
|
-
|
|
189
|
+
const put = options.putOptions?.(inputData);
|
|
190
|
+
if (async) (0, import_functions.waitUntil)(uploadBlob(blob, fileKey, put));
|
|
191
|
+
else await uploadBlob(blob, fileKey, put);
|
|
190
192
|
const onUploadResponse = await options.onUpload({
|
|
191
193
|
...inputData,
|
|
192
194
|
url
|
package/dist/file/put.d.mts
CHANGED
package/dist/file/put.d.ts
CHANGED
package/dist/file/put.esm.js
CHANGED
|
@@ -132,7 +132,7 @@ function checkClient(client2) {
|
|
|
132
132
|
if (!client2) throw new Error("Client does not exist");
|
|
133
133
|
return true;
|
|
134
134
|
}
|
|
135
|
-
var uploadBlob = async (file, key) => {
|
|
135
|
+
var uploadBlob = async (file, key, overrides) => {
|
|
136
136
|
if (!checkClient(client)) return;
|
|
137
137
|
const fileBuffer = await file.arrayBuffer();
|
|
138
138
|
return client.send(
|
|
@@ -142,7 +142,8 @@ var uploadBlob = async (file, key) => {
|
|
|
142
142
|
ACL: "public-read",
|
|
143
143
|
Body: Buffer.from(fileBuffer),
|
|
144
144
|
ContentType: file.type,
|
|
145
|
-
ContentLength: file.size
|
|
145
|
+
ContentLength: file.size,
|
|
146
|
+
...overrides
|
|
146
147
|
})
|
|
147
148
|
);
|
|
148
149
|
};
|
|
@@ -165,8 +166,9 @@ var getFileUploadPutRoute = (options) => async (req) => {
|
|
|
165
166
|
const fileKey = options.getKey ? await options.getKey(inputData) : v4();
|
|
166
167
|
const url = getDownloadURL(fileKey);
|
|
167
168
|
const blob = options.processFile ? await options.processFile(file, inputData) : file;
|
|
168
|
-
|
|
169
|
-
|
|
169
|
+
const put = options.putOptions?.(inputData);
|
|
170
|
+
if (async) waitUntil(uploadBlob(blob, fileKey, put));
|
|
171
|
+
else await uploadBlob(blob, fileKey, put);
|
|
170
172
|
const onUploadResponse = await options.onUpload({
|
|
171
173
|
...inputData,
|
|
172
174
|
url
|
package/dist/file/setup.cjs.js
CHANGED
|
@@ -154,7 +154,7 @@ function checkClient(client2) {
|
|
|
154
154
|
if (!client2) throw new Error("Client does not exist");
|
|
155
155
|
return true;
|
|
156
156
|
}
|
|
157
|
-
var uploadBlob = async (file, key) => {
|
|
157
|
+
var uploadBlob = async (file, key, overrides) => {
|
|
158
158
|
if (!checkClient(client)) return;
|
|
159
159
|
const fileBuffer = await file.arrayBuffer();
|
|
160
160
|
return client.send(
|
|
@@ -164,7 +164,8 @@ var uploadBlob = async (file, key) => {
|
|
|
164
164
|
ACL: "public-read",
|
|
165
165
|
Body: Buffer.from(fileBuffer),
|
|
166
166
|
ContentType: file.type,
|
|
167
|
-
ContentLength: file.size
|
|
167
|
+
ContentLength: file.size,
|
|
168
|
+
...overrides
|
|
168
169
|
})
|
|
169
170
|
);
|
|
170
171
|
};
|
|
@@ -187,8 +188,9 @@ var getFileUploadPutRoute = (options) => async (req) => {
|
|
|
187
188
|
const fileKey = options.getKey ? await options.getKey(inputData) : (0, import_uuid.v4)();
|
|
188
189
|
const url = getDownloadURL(fileKey);
|
|
189
190
|
const blob = options.processFile ? await options.processFile(file, inputData) : file;
|
|
190
|
-
|
|
191
|
-
|
|
191
|
+
const put = options.putOptions?.(inputData);
|
|
192
|
+
if (async) (0, import_functions.waitUntil)(uploadBlob(blob, fileKey, put));
|
|
193
|
+
else await uploadBlob(blob, fileKey, put);
|
|
192
194
|
const onUploadResponse = await options.onUpload({
|
|
193
195
|
...inputData,
|
|
194
196
|
url
|
package/dist/file/setup.d.mts
CHANGED
|
@@ -1,13 +1,24 @@
|
|
|
1
1
|
import * as next_server from 'next/server';
|
|
2
|
+
import { PutOverrides } from './utils.mjs';
|
|
3
|
+
import '@aws-sdk/client-s3';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Options for setting up file upload via {@link setupFileUpload}.
|
|
5
7
|
*
|
|
8
|
+
* Every callback receives the same `{ type, userId, data }` context. **`data` is
|
|
9
|
+
* optional** — it is whatever the caller passed as `config.data` to
|
|
10
|
+
* `useFileUpload`, and the client only appends the form field when a value is
|
|
11
|
+
* given, so the route parses it to `undefined` otherwise. Narrow it before use;
|
|
12
|
+
* destructuring it unguarded throws at runtime.
|
|
13
|
+
*
|
|
6
14
|
* @property getKey - Optional. Given `{ type, userId, data }`, returns the S3 object key for the upload. If omitted, a UUID is generated.
|
|
7
15
|
* @property processFile - Optional. Given the uploaded `file` and `{ type, userId, data }`, returns the blob to
|
|
8
16
|
* store in its place — e.g. re-encoding an image, or stripping metadata. Runs after authentication and before the
|
|
9
17
|
* S3 write, so only the returned bytes are ever stored. The blob's `type` becomes the object's `Content-Type`,
|
|
10
18
|
* so change it when the format changes. Return the file unchanged to leave it alone. Throwing fails the upload.
|
|
19
|
+
* @property putOptions - Optional. Given `{ type, userId, data }`, returns fields to set on the S3 put —
|
|
20
|
+
* `CacheControl`, `ContentDisposition`, `Metadata` and so on. A function rather than a static object so
|
|
21
|
+
* headers can differ per upload kind. See {@link PutOverrides}.
|
|
11
22
|
* @property onUpload - **Required.** Called after each successful upload with `{ url, type, userId, data }`.
|
|
12
23
|
* The return value is included in the API response as `onUploadResponse` (e.g. save metadata to your database and return it).
|
|
13
24
|
*
|
|
@@ -17,18 +28,23 @@ interface SetupFileUploadOptions {
|
|
|
17
28
|
getKey?: (data: {
|
|
18
29
|
type: string;
|
|
19
30
|
userId: number;
|
|
20
|
-
data
|
|
31
|
+
data?: object;
|
|
21
32
|
}) => Promise<string>;
|
|
22
33
|
processFile?: (file: File, data: {
|
|
23
34
|
type: string;
|
|
24
35
|
userId: number;
|
|
25
|
-
data
|
|
36
|
+
data?: object;
|
|
26
37
|
}) => Promise<Blob>;
|
|
38
|
+
putOptions?: (data: {
|
|
39
|
+
type: string;
|
|
40
|
+
userId: number;
|
|
41
|
+
data?: object;
|
|
42
|
+
}) => PutOverrides;
|
|
27
43
|
onUpload: (data: {
|
|
28
44
|
url: string | null;
|
|
29
45
|
type: string;
|
|
30
46
|
userId: number;
|
|
31
|
-
data
|
|
47
|
+
data?: object;
|
|
32
48
|
}) => Promise<object>;
|
|
33
49
|
}
|
|
34
50
|
/**
|
|
@@ -55,7 +71,9 @@ interface SetupFileUploadOptions {
|
|
|
55
71
|
* export const { PUT } = setupFileUpload({
|
|
56
72
|
* onUpload: async ({ url, type, userId, data }) => {
|
|
57
73
|
* if (type === "DealDocument" && url) {
|
|
58
|
-
*
|
|
74
|
+
* // `data` is absent unless the client sent one — check before reading it.
|
|
75
|
+
* const payload = data as { dealId?: number; fileName?: string } | undefined;
|
|
76
|
+
* if (!payload?.dealId) return {};
|
|
59
77
|
* const [row] = await db.insert(DocumentsTable).values({
|
|
60
78
|
* dealId: payload.dealId, fileURL: url, fileName: payload.fileName,
|
|
61
79
|
* }).returning();
|
package/dist/file/setup.d.ts
CHANGED
|
@@ -1,13 +1,24 @@
|
|
|
1
1
|
import * as next_server from 'next/server';
|
|
2
|
+
import { PutOverrides } from './utils.js';
|
|
3
|
+
import '@aws-sdk/client-s3';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Options for setting up file upload via {@link setupFileUpload}.
|
|
5
7
|
*
|
|
8
|
+
* Every callback receives the same `{ type, userId, data }` context. **`data` is
|
|
9
|
+
* optional** — it is whatever the caller passed as `config.data` to
|
|
10
|
+
* `useFileUpload`, and the client only appends the form field when a value is
|
|
11
|
+
* given, so the route parses it to `undefined` otherwise. Narrow it before use;
|
|
12
|
+
* destructuring it unguarded throws at runtime.
|
|
13
|
+
*
|
|
6
14
|
* @property getKey - Optional. Given `{ type, userId, data }`, returns the S3 object key for the upload. If omitted, a UUID is generated.
|
|
7
15
|
* @property processFile - Optional. Given the uploaded `file` and `{ type, userId, data }`, returns the blob to
|
|
8
16
|
* store in its place — e.g. re-encoding an image, or stripping metadata. Runs after authentication and before the
|
|
9
17
|
* S3 write, so only the returned bytes are ever stored. The blob's `type` becomes the object's `Content-Type`,
|
|
10
18
|
* so change it when the format changes. Return the file unchanged to leave it alone. Throwing fails the upload.
|
|
19
|
+
* @property putOptions - Optional. Given `{ type, userId, data }`, returns fields to set on the S3 put —
|
|
20
|
+
* `CacheControl`, `ContentDisposition`, `Metadata` and so on. A function rather than a static object so
|
|
21
|
+
* headers can differ per upload kind. See {@link PutOverrides}.
|
|
11
22
|
* @property onUpload - **Required.** Called after each successful upload with `{ url, type, userId, data }`.
|
|
12
23
|
* The return value is included in the API response as `onUploadResponse` (e.g. save metadata to your database and return it).
|
|
13
24
|
*
|
|
@@ -17,18 +28,23 @@ interface SetupFileUploadOptions {
|
|
|
17
28
|
getKey?: (data: {
|
|
18
29
|
type: string;
|
|
19
30
|
userId: number;
|
|
20
|
-
data
|
|
31
|
+
data?: object;
|
|
21
32
|
}) => Promise<string>;
|
|
22
33
|
processFile?: (file: File, data: {
|
|
23
34
|
type: string;
|
|
24
35
|
userId: number;
|
|
25
|
-
data
|
|
36
|
+
data?: object;
|
|
26
37
|
}) => Promise<Blob>;
|
|
38
|
+
putOptions?: (data: {
|
|
39
|
+
type: string;
|
|
40
|
+
userId: number;
|
|
41
|
+
data?: object;
|
|
42
|
+
}) => PutOverrides;
|
|
27
43
|
onUpload: (data: {
|
|
28
44
|
url: string | null;
|
|
29
45
|
type: string;
|
|
30
46
|
userId: number;
|
|
31
|
-
data
|
|
47
|
+
data?: object;
|
|
32
48
|
}) => Promise<object>;
|
|
33
49
|
}
|
|
34
50
|
/**
|
|
@@ -55,7 +71,9 @@ interface SetupFileUploadOptions {
|
|
|
55
71
|
* export const { PUT } = setupFileUpload({
|
|
56
72
|
* onUpload: async ({ url, type, userId, data }) => {
|
|
57
73
|
* if (type === "DealDocument" && url) {
|
|
58
|
-
*
|
|
74
|
+
* // `data` is absent unless the client sent one — check before reading it.
|
|
75
|
+
* const payload = data as { dealId?: number; fileName?: string } | undefined;
|
|
76
|
+
* if (!payload?.dealId) return {};
|
|
59
77
|
* const [row] = await db.insert(DocumentsTable).values({
|
|
60
78
|
* dealId: payload.dealId, fileURL: url, fileName: payload.fileName,
|
|
61
79
|
* }).returning();
|
package/dist/file/setup.esm.js
CHANGED
|
@@ -132,7 +132,7 @@ function checkClient(client2) {
|
|
|
132
132
|
if (!client2) throw new Error("Client does not exist");
|
|
133
133
|
return true;
|
|
134
134
|
}
|
|
135
|
-
var uploadBlob = async (file, key) => {
|
|
135
|
+
var uploadBlob = async (file, key, overrides) => {
|
|
136
136
|
if (!checkClient(client)) return;
|
|
137
137
|
const fileBuffer = await file.arrayBuffer();
|
|
138
138
|
return client.send(
|
|
@@ -142,7 +142,8 @@ var uploadBlob = async (file, key) => {
|
|
|
142
142
|
ACL: "public-read",
|
|
143
143
|
Body: Buffer.from(fileBuffer),
|
|
144
144
|
ContentType: file.type,
|
|
145
|
-
ContentLength: file.size
|
|
145
|
+
ContentLength: file.size,
|
|
146
|
+
...overrides
|
|
146
147
|
})
|
|
147
148
|
);
|
|
148
149
|
};
|
|
@@ -165,8 +166,9 @@ var getFileUploadPutRoute = (options) => async (req) => {
|
|
|
165
166
|
const fileKey = options.getKey ? await options.getKey(inputData) : v4();
|
|
166
167
|
const url = getDownloadURL(fileKey);
|
|
167
168
|
const blob = options.processFile ? await options.processFile(file, inputData) : file;
|
|
168
|
-
|
|
169
|
-
|
|
169
|
+
const put = options.putOptions?.(inputData);
|
|
170
|
+
if (async) waitUntil(uploadBlob(blob, fileKey, put));
|
|
171
|
+
else await uploadBlob(blob, fileKey, put);
|
|
170
172
|
const onUploadResponse = await options.onUpload({
|
|
171
173
|
...inputData,
|
|
172
174
|
url
|
package/dist/file/utils.cjs.js
CHANGED
|
@@ -107,14 +107,15 @@ var getDownloadURL = (keys) => {
|
|
|
107
107
|
};
|
|
108
108
|
var uploadFile = async (keys, {
|
|
109
109
|
url,
|
|
110
|
-
blob
|
|
110
|
+
blob,
|
|
111
|
+
put
|
|
111
112
|
}) => {
|
|
112
113
|
if (!checkClient(client)) return;
|
|
113
114
|
if (!blob && !url) return null;
|
|
114
115
|
const fileBlob = blob || await fetch(url).then((file) => file.blob());
|
|
115
116
|
if (fileBlob) {
|
|
116
117
|
const key = getKey(keys);
|
|
117
|
-
await uploadBlob(fileBlob, key);
|
|
118
|
+
await uploadBlob(fileBlob, key, put);
|
|
118
119
|
return getDownloadURL(key);
|
|
119
120
|
}
|
|
120
121
|
return null;
|
|
@@ -141,7 +142,7 @@ function checkClient(client2) {
|
|
|
141
142
|
if (!client2) throw new Error("Client does not exist");
|
|
142
143
|
return true;
|
|
143
144
|
}
|
|
144
|
-
var uploadBlob = async (file, key) => {
|
|
145
|
+
var uploadBlob = async (file, key, overrides) => {
|
|
145
146
|
if (!checkClient(client)) return;
|
|
146
147
|
const fileBuffer = await file.arrayBuffer();
|
|
147
148
|
return client.send(
|
|
@@ -151,7 +152,8 @@ var uploadBlob = async (file, key) => {
|
|
|
151
152
|
ACL: "public-read",
|
|
152
153
|
Body: Buffer.from(fileBuffer),
|
|
153
154
|
ContentType: file.type,
|
|
154
|
-
ContentLength: file.size
|
|
155
|
+
ContentLength: file.size,
|
|
156
|
+
...overrides
|
|
155
157
|
})
|
|
156
158
|
);
|
|
157
159
|
};
|
package/dist/file/utils.d.mts
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import * as _aws_sdk_client_s3 from '@aws-sdk/client-s3';
|
|
2
|
+
import { PutObjectCommandInput } from '@aws-sdk/client-s3';
|
|
2
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Fields a caller may set on the underlying S3 put — `CacheControl`,
|
|
6
|
+
* `ContentDisposition`, `Metadata`, `StorageClass`, and so on. Spread over the
|
|
7
|
+
* defaults, so anything given here wins.
|
|
8
|
+
*
|
|
9
|
+
* What identifies the upload — `Bucket`, `Key`, `Body` — is deliberately not
|
|
10
|
+
* overridable: those are naystack's to set, and replacing them would silently
|
|
11
|
+
* write the wrong bytes or the wrong object rather than fail.
|
|
12
|
+
*
|
|
13
|
+
* @category File
|
|
14
|
+
*/
|
|
15
|
+
type PutOverrides = Omit<PutObjectCommandInput, "Bucket" | "Key" | "Body">;
|
|
3
16
|
/**
|
|
4
17
|
* Generates a presigned PUT URL for uploading a file to the given S3 key(s).
|
|
5
18
|
* The URL expires after 5 minutes.
|
|
@@ -23,12 +36,14 @@ declare const getDownloadURL: (keys: string | string[]) => string;
|
|
|
23
36
|
* @param keys - S3 key or key path segments (array joined by `/`).
|
|
24
37
|
* @param options.blob - A Blob/File to upload directly.
|
|
25
38
|
* @param options.url - A remote URL to fetch and upload. Ignored if `blob` is provided.
|
|
39
|
+
* @param options.put - Fields to set on the S3 put. See {@link PutOverrides}.
|
|
26
40
|
* @returns The public download URL of the uploaded file, or `null` if neither `blob` nor `url` was provided.
|
|
27
41
|
* @category File
|
|
28
42
|
*/
|
|
29
|
-
declare const uploadFile: (keys: string | string[], { url, blob, }: {
|
|
43
|
+
declare const uploadFile: (keys: string | string[], { url, blob, put, }: {
|
|
30
44
|
blob?: Blob;
|
|
31
45
|
url?: string;
|
|
46
|
+
put?: PutOverrides;
|
|
32
47
|
}) => Promise<string | null | undefined>;
|
|
33
48
|
/**
|
|
34
49
|
* Deletes an S3 object identified by its full public URL.
|
|
@@ -43,9 +58,10 @@ declare const deleteFile: (url: string) => Promise<boolean | undefined>;
|
|
|
43
58
|
*
|
|
44
59
|
* @param file - The Blob or File to upload.
|
|
45
60
|
* @param key - The S3 object key.
|
|
61
|
+
* @param overrides - Fields to set on the put, spread over the defaults below. See {@link PutOverrides}.
|
|
46
62
|
* @returns The `PutObjectCommandOutput` from S3.
|
|
47
63
|
* @category File
|
|
48
64
|
*/
|
|
49
|
-
declare const uploadBlob: (file: File | Blob, key: string) => Promise<_aws_sdk_client_s3.PutObjectCommandOutput | undefined>;
|
|
65
|
+
declare const uploadBlob: (file: File | Blob, key: string, overrides?: PutOverrides) => Promise<_aws_sdk_client_s3.PutObjectCommandOutput | undefined>;
|
|
50
66
|
|
|
51
|
-
export { deleteFile, getDownloadURL, getUploadURL, uploadBlob, uploadFile };
|
|
67
|
+
export { type PutOverrides, deleteFile, getDownloadURL, getUploadURL, uploadBlob, uploadFile };
|
package/dist/file/utils.d.ts
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import * as _aws_sdk_client_s3 from '@aws-sdk/client-s3';
|
|
2
|
+
import { PutObjectCommandInput } from '@aws-sdk/client-s3';
|
|
2
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Fields a caller may set on the underlying S3 put — `CacheControl`,
|
|
6
|
+
* `ContentDisposition`, `Metadata`, `StorageClass`, and so on. Spread over the
|
|
7
|
+
* defaults, so anything given here wins.
|
|
8
|
+
*
|
|
9
|
+
* What identifies the upload — `Bucket`, `Key`, `Body` — is deliberately not
|
|
10
|
+
* overridable: those are naystack's to set, and replacing them would silently
|
|
11
|
+
* write the wrong bytes or the wrong object rather than fail.
|
|
12
|
+
*
|
|
13
|
+
* @category File
|
|
14
|
+
*/
|
|
15
|
+
type PutOverrides = Omit<PutObjectCommandInput, "Bucket" | "Key" | "Body">;
|
|
3
16
|
/**
|
|
4
17
|
* Generates a presigned PUT URL for uploading a file to the given S3 key(s).
|
|
5
18
|
* The URL expires after 5 minutes.
|
|
@@ -23,12 +36,14 @@ declare const getDownloadURL: (keys: string | string[]) => string;
|
|
|
23
36
|
* @param keys - S3 key or key path segments (array joined by `/`).
|
|
24
37
|
* @param options.blob - A Blob/File to upload directly.
|
|
25
38
|
* @param options.url - A remote URL to fetch and upload. Ignored if `blob` is provided.
|
|
39
|
+
* @param options.put - Fields to set on the S3 put. See {@link PutOverrides}.
|
|
26
40
|
* @returns The public download URL of the uploaded file, or `null` if neither `blob` nor `url` was provided.
|
|
27
41
|
* @category File
|
|
28
42
|
*/
|
|
29
|
-
declare const uploadFile: (keys: string | string[], { url, blob, }: {
|
|
43
|
+
declare const uploadFile: (keys: string | string[], { url, blob, put, }: {
|
|
30
44
|
blob?: Blob;
|
|
31
45
|
url?: string;
|
|
46
|
+
put?: PutOverrides;
|
|
32
47
|
}) => Promise<string | null | undefined>;
|
|
33
48
|
/**
|
|
34
49
|
* Deletes an S3 object identified by its full public URL.
|
|
@@ -43,9 +58,10 @@ declare const deleteFile: (url: string) => Promise<boolean | undefined>;
|
|
|
43
58
|
*
|
|
44
59
|
* @param file - The Blob or File to upload.
|
|
45
60
|
* @param key - The S3 object key.
|
|
61
|
+
* @param overrides - Fields to set on the put, spread over the defaults below. See {@link PutOverrides}.
|
|
46
62
|
* @returns The `PutObjectCommandOutput` from S3.
|
|
47
63
|
* @category File
|
|
48
64
|
*/
|
|
49
|
-
declare const uploadBlob: (file: File | Blob, key: string) => Promise<_aws_sdk_client_s3.PutObjectCommandOutput | undefined>;
|
|
65
|
+
declare const uploadBlob: (file: File | Blob, key: string, overrides?: PutOverrides) => Promise<_aws_sdk_client_s3.PutObjectCommandOutput | undefined>;
|
|
50
66
|
|
|
51
|
-
export { deleteFile, getDownloadURL, getUploadURL, uploadBlob, uploadFile };
|
|
67
|
+
export { type PutOverrides, deleteFile, getDownloadURL, getUploadURL, uploadBlob, uploadFile };
|
package/dist/file/utils.esm.js
CHANGED
|
@@ -83,14 +83,15 @@ var getDownloadURL = (keys) => {
|
|
|
83
83
|
};
|
|
84
84
|
var uploadFile = async (keys, {
|
|
85
85
|
url,
|
|
86
|
-
blob
|
|
86
|
+
blob,
|
|
87
|
+
put
|
|
87
88
|
}) => {
|
|
88
89
|
if (!checkClient(client)) return;
|
|
89
90
|
if (!blob && !url) return null;
|
|
90
91
|
const fileBlob = blob || await fetch(url).then((file) => file.blob());
|
|
91
92
|
if (fileBlob) {
|
|
92
93
|
const key = getKey(keys);
|
|
93
|
-
await uploadBlob(fileBlob, key);
|
|
94
|
+
await uploadBlob(fileBlob, key, put);
|
|
94
95
|
return getDownloadURL(key);
|
|
95
96
|
}
|
|
96
97
|
return null;
|
|
@@ -117,7 +118,7 @@ function checkClient(client2) {
|
|
|
117
118
|
if (!client2) throw new Error("Client does not exist");
|
|
118
119
|
return true;
|
|
119
120
|
}
|
|
120
|
-
var uploadBlob = async (file, key) => {
|
|
121
|
+
var uploadBlob = async (file, key, overrides) => {
|
|
121
122
|
if (!checkClient(client)) return;
|
|
122
123
|
const fileBuffer = await file.arrayBuffer();
|
|
123
124
|
return client.send(
|
|
@@ -127,7 +128,8 @@ var uploadBlob = async (file, key) => {
|
|
|
127
128
|
ACL: "public-read",
|
|
128
129
|
Body: Buffer.from(fileBuffer),
|
|
129
130
|
ContentType: file.type,
|
|
130
|
-
ContentLength: file.size
|
|
131
|
+
ContentLength: file.size,
|
|
132
|
+
...overrides
|
|
131
133
|
})
|
|
132
134
|
);
|
|
133
135
|
};
|
package/dist/index.d.mts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* - `naystack/file` — S3 file upload setup
|
|
11
11
|
* - `naystack/file/client` — Client-side file upload hook (useFileUpload)
|
|
12
12
|
* - `naystack/client` — Client hooks (useVisibility, useBreakpoint) and SEO (setupSEO)
|
|
13
|
-
* - `naystack/socials` — Instagram and Threads
|
|
13
|
+
* - `naystack/socials` — publish to and read from Instagram and Threads
|
|
14
14
|
*
|
|
15
15
|
* @module
|
|
16
16
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* - `naystack/file` — S3 file upload setup
|
|
11
11
|
* - `naystack/file/client` — Client-side file upload hook (useFileUpload)
|
|
12
12
|
* - `naystack/client` — Client hooks (useVisibility, useBreakpoint) and SEO (setupSEO)
|
|
13
|
-
* - `naystack/socials` — Instagram and Threads
|
|
13
|
+
* - `naystack/socials` — publish to and read from Instagram and Threads
|
|
14
14
|
*
|
|
15
15
|
* @module
|
|
16
16
|
*/
|