@darseen/vaze 2.1.0 → 2.3.0

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 CHANGED
@@ -109,6 +109,17 @@ if (data) {
109
109
  }
110
110
  ```
111
111
 
112
+ `downloadMany(ids)` Download several files as one zip. Entries keep their paths below the folder the files share.
113
+
114
+ ```ts
115
+ const { data, error } = await vaze.files.downloadMany(["file-id-123", "file-id-456"]);
116
+
117
+ if (data) {
118
+ console.log(data.filename); // e.g. "photos.zip"
119
+ const buffer = Buffer.from(await data.blob.arrayBuffer());
120
+ }
121
+ ```
122
+
112
123
  `rename(data)` Rename an existing file.
113
124
 
114
125
  - data:
@@ -171,6 +182,17 @@ const { data, error } = await vaze.folders.rename({
171
182
  });
172
183
  ```
173
184
 
185
+ `download(options?)` Download a folder and everything below it as one zip. With no `id` or `key`, the root folder is archived.
186
+
187
+ ```ts
188
+ const { data, error } = await vaze.folders.download({ key: "projects/work" });
189
+
190
+ if (data) {
191
+ console.log(data.filename); // "work.zip", with every entry under work/
192
+ const buffer = Buffer.from(await data.blob.arrayBuffer());
193
+ }
194
+ ```
195
+
174
196
  `delete(id)` Delete a folder by its ID.
175
197
 
176
198
  ```ts
package/dist/index.cjs CHANGED
@@ -92,10 +92,14 @@ var Base = class {
92
92
  };
93
93
  }
94
94
  }
95
- async requestBlob(url) {
95
+ async requestBlob(url, method = "GET", body) {
96
96
  try {
97
+ const headers = { "API-Key": this.apiKey };
98
+ if (body !== void 0) headers["Content-Type"] = "application/json";
97
99
  const response = await fetch(url, {
98
- headers: { "API-Key": this.apiKey }
100
+ method,
101
+ headers,
102
+ body: body !== void 0 ? JSON.stringify(body) : null
99
103
  });
100
104
  const contentType = _nullishCoalesce(response.headers.get("content-type"), () => ( ""));
101
105
  if (!response.ok) {
@@ -219,12 +223,49 @@ var Files = class extends Base {
219
223
  const url = this.apiUrl(`/api/files/download/${encodeURIComponent(id)}`);
220
224
  return await this.requestBlob(url);
221
225
  }
226
+ /** Download several files as one zip, with paths below their shared folder. */
227
+ async downloadMany(ids) {
228
+ return await this.requestBlob(this.apiUrl("/api/files/download"), "POST", {
229
+ ids
230
+ });
231
+ }
222
232
  async rename(data) {
223
233
  return await this.request("PUT", this.apiUrl("/api/files"), data);
224
234
  }
225
235
  async setVisibility(data) {
226
236
  return await this.request("PUT", this.apiUrl("/api/files"), data);
227
237
  }
238
+ /** Move a file into another folder; its key and URL change with it. */
239
+ async move(data) {
240
+ const { data: responseData, error } = await this.request("POST", this.apiUrl("/api/files/move"), data);
241
+ return {
242
+ error,
243
+ data: responseData ? {
244
+ file: constructFileUrls({
245
+ vazeUrl: this.vazeUrl,
246
+ files: [responseData.file]
247
+ })[0]
248
+ } : null
249
+ };
250
+ }
251
+ /** Move several files into one folder; each id reports its own outcome. */
252
+ async moveMany(ids, destination) {
253
+ const { data, error } = await this.request(
254
+ "POST",
255
+ this.apiUrl("/api/files/move"),
256
+ { ids, ...destination }
257
+ );
258
+ return {
259
+ error,
260
+ data: data ? {
261
+ files: constructFileUrls({
262
+ vazeUrl: this.vazeUrl,
263
+ files: data.files
264
+ }),
265
+ failed: data.failed
266
+ } : null
267
+ };
268
+ }
228
269
  /** Mint a time-limited URL that reads a file without an API key. */
229
270
  async sign(options) {
230
271
  const { data, error } = await this.request(
@@ -242,6 +283,14 @@ var Files = class extends Base {
242
283
  id
243
284
  });
244
285
  }
286
+ /** Delete several files in one request; each id reports its own outcome. */
287
+ async deleteMany(ids) {
288
+ return await this.request(
289
+ "DELETE",
290
+ this.apiUrl("/api/files"),
291
+ { ids }
292
+ );
293
+ }
245
294
  };
246
295
 
247
296
  // src/folders.ts
@@ -260,6 +309,12 @@ var Folders = class extends Base {
260
309
  } : null
261
310
  };
262
311
  }
312
+ /** Download a folder and everything below it as a zip; the root by default. */
313
+ async download(options) {
314
+ return await this.requestBlob(
315
+ this.apiUrl("/api/folders/download", options)
316
+ );
317
+ }
263
318
  async create(folder) {
264
319
  return await this.request(
265
320
  "POST",
@@ -270,6 +325,14 @@ var Folders = class extends Base {
270
325
  async rename(data) {
271
326
  return await this.request("PUT", this.apiUrl("/api/folders"), data);
272
327
  }
328
+ /** Move a folder, and everything inside it, into another folder. */
329
+ async move(data) {
330
+ return await this.request(
331
+ "POST",
332
+ this.apiUrl("/api/folders/move"),
333
+ data
334
+ );
335
+ }
273
336
  /** Apply a visibility to every file at or below this folder. */
274
337
  async setVisibility(data) {
275
338
  return await this.request("PUT", this.apiUrl("/api/folders"), data);
package/dist/index.d.cts CHANGED
@@ -779,6 +779,12 @@ declare class Files extends Base {
779
779
  filename: string | null;
780
780
  contentType: string;
781
781
  }>>;
782
+ /** Download several files as one zip, with paths below their shared folder. */
783
+ downloadMany(ids: string[]): Promise<ApiResponse<{
784
+ blob: Blob;
785
+ filename: string | null;
786
+ contentType: string;
787
+ }>>;
782
788
  rename(data: {
783
789
  id: string;
784
790
  name: string;
@@ -787,6 +793,30 @@ declare class Files extends Base {
787
793
  id: string;
788
794
  visibility: Visibility;
789
795
  }): Promise<ApiResponse<null>>;
796
+ /** Move a file into another folder; its key and URL change with it. */
797
+ move(data: {
798
+ id: string;
799
+ } & MoveDestination): Promise<{
800
+ error: {
801
+ message: string;
802
+ } | null;
803
+ data: {
804
+ file: any;
805
+ } | null;
806
+ }>;
807
+ /** Move several files into one folder; each id reports its own outcome. */
808
+ moveMany(ids: string[], destination: MoveDestination): Promise<{
809
+ error: {
810
+ message: string;
811
+ } | null;
812
+ data: {
813
+ files: any[];
814
+ failed: {
815
+ id: string;
816
+ message: string;
817
+ }[];
818
+ } | null;
819
+ }>;
790
820
  /** Mint a time-limited URL that reads a file without an API key. */
791
821
  sign(options: SignOptions): Promise<{
792
822
  error: {
@@ -798,6 +828,8 @@ declare class Files extends Base {
798
828
  } | null;
799
829
  }>;
800
830
  delete(id: string): Promise<ApiResponse<null>>;
831
+ /** Delete several files in one request; each id reports its own outcome. */
832
+ deleteMany(ids: string[]): Promise<ApiResponse<BulkDeleteResult>>;
801
833
  }
802
834
 
803
835
  declare class Folders extends Base {
@@ -814,6 +846,15 @@ declare class Folders extends Base {
814
846
  folders: Folder[];
815
847
  } | null;
816
848
  }>;
849
+ /** Download a folder and everything below it as a zip; the root by default. */
850
+ download(options?: {
851
+ id?: string;
852
+ key?: string;
853
+ }): Promise<ApiResponse<{
854
+ blob: Blob;
855
+ filename: string | null;
856
+ contentType: string;
857
+ }>>;
817
858
  create(folder: string): Promise<ApiResponse<{
818
859
  folder: Folder;
819
860
  }>>;
@@ -821,6 +862,12 @@ declare class Folders extends Base {
821
862
  id: string;
822
863
  name: string;
823
864
  }): Promise<ApiResponse<null>>;
865
+ /** Move a folder, and everything inside it, into another folder. */
866
+ move(data: {
867
+ id: string;
868
+ } & MoveDestination): Promise<ApiResponse<{
869
+ folder: Folder;
870
+ }>>;
824
871
  /** Apply a visibility to every file at or below this folder. */
825
872
  setVisibility(data: {
826
873
  id: string;
@@ -853,6 +900,26 @@ type SignedUrl = {
853
900
  url: string;
854
901
  expiresAt: string;
855
902
  };
903
+ type MoveDestination = {
904
+ /** The destination folder's id. Either this or `folder` is required. */
905
+ folderId?: string;
906
+ /** The destination folder's key, created if missing; `""` is the root. */
907
+ folder?: string;
908
+ };
909
+ type BulkMoveResult = {
910
+ files: FileWithUrl[];
911
+ failed: {
912
+ id: string;
913
+ message: string;
914
+ }[];
915
+ };
916
+ type BulkDeleteResult = {
917
+ deleted: string[];
918
+ failed: {
919
+ id: string;
920
+ message: string;
921
+ }[];
922
+ };
856
923
 
857
924
  declare class Base {
858
925
  private apiKey;
@@ -860,7 +927,7 @@ declare class Base {
860
927
  constructor(options?: VazeOptions);
861
928
  protected apiUrl(path: string, params?: Record<string, string | number | undefined>): string;
862
929
  protected request<T>(method: string, url: string, body?: Record<string, any> | FormData, headers?: Record<string, string>): Promise<ApiResponse<T>>;
863
- protected requestBlob(url: string): Promise<ApiResponse<{
930
+ protected requestBlob(url: string, method?: string, body?: Record<string, any>): Promise<ApiResponse<{
864
931
  blob: Blob;
865
932
  filename: string | null;
866
933
  contentType: string;
@@ -876,4 +943,4 @@ declare class Vaze extends Base implements IVaze {
876
943
  }>>;
877
944
  }
878
945
 
879
- export { type ApiResponse, type FileWithUrl as File, type Folder, type ListOptions, type SignOptions, type SignedUrl, type VazeOptions, type Visibility, Vaze as default };
946
+ export { type ApiResponse, type BulkDeleteResult, type BulkMoveResult, type FileWithUrl as File, type Folder, type ListOptions, type MoveDestination, type SignOptions, type SignedUrl, type VazeOptions, type Visibility, Vaze as default };
package/dist/index.d.ts CHANGED
@@ -779,6 +779,12 @@ declare class Files extends Base {
779
779
  filename: string | null;
780
780
  contentType: string;
781
781
  }>>;
782
+ /** Download several files as one zip, with paths below their shared folder. */
783
+ downloadMany(ids: string[]): Promise<ApiResponse<{
784
+ blob: Blob;
785
+ filename: string | null;
786
+ contentType: string;
787
+ }>>;
782
788
  rename(data: {
783
789
  id: string;
784
790
  name: string;
@@ -787,6 +793,30 @@ declare class Files extends Base {
787
793
  id: string;
788
794
  visibility: Visibility;
789
795
  }): Promise<ApiResponse<null>>;
796
+ /** Move a file into another folder; its key and URL change with it. */
797
+ move(data: {
798
+ id: string;
799
+ } & MoveDestination): Promise<{
800
+ error: {
801
+ message: string;
802
+ } | null;
803
+ data: {
804
+ file: any;
805
+ } | null;
806
+ }>;
807
+ /** Move several files into one folder; each id reports its own outcome. */
808
+ moveMany(ids: string[], destination: MoveDestination): Promise<{
809
+ error: {
810
+ message: string;
811
+ } | null;
812
+ data: {
813
+ files: any[];
814
+ failed: {
815
+ id: string;
816
+ message: string;
817
+ }[];
818
+ } | null;
819
+ }>;
790
820
  /** Mint a time-limited URL that reads a file without an API key. */
791
821
  sign(options: SignOptions): Promise<{
792
822
  error: {
@@ -798,6 +828,8 @@ declare class Files extends Base {
798
828
  } | null;
799
829
  }>;
800
830
  delete(id: string): Promise<ApiResponse<null>>;
831
+ /** Delete several files in one request; each id reports its own outcome. */
832
+ deleteMany(ids: string[]): Promise<ApiResponse<BulkDeleteResult>>;
801
833
  }
802
834
 
803
835
  declare class Folders extends Base {
@@ -814,6 +846,15 @@ declare class Folders extends Base {
814
846
  folders: Folder[];
815
847
  } | null;
816
848
  }>;
849
+ /** Download a folder and everything below it as a zip; the root by default. */
850
+ download(options?: {
851
+ id?: string;
852
+ key?: string;
853
+ }): Promise<ApiResponse<{
854
+ blob: Blob;
855
+ filename: string | null;
856
+ contentType: string;
857
+ }>>;
817
858
  create(folder: string): Promise<ApiResponse<{
818
859
  folder: Folder;
819
860
  }>>;
@@ -821,6 +862,12 @@ declare class Folders extends Base {
821
862
  id: string;
822
863
  name: string;
823
864
  }): Promise<ApiResponse<null>>;
865
+ /** Move a folder, and everything inside it, into another folder. */
866
+ move(data: {
867
+ id: string;
868
+ } & MoveDestination): Promise<ApiResponse<{
869
+ folder: Folder;
870
+ }>>;
824
871
  /** Apply a visibility to every file at or below this folder. */
825
872
  setVisibility(data: {
826
873
  id: string;
@@ -853,6 +900,26 @@ type SignedUrl = {
853
900
  url: string;
854
901
  expiresAt: string;
855
902
  };
903
+ type MoveDestination = {
904
+ /** The destination folder's id. Either this or `folder` is required. */
905
+ folderId?: string;
906
+ /** The destination folder's key, created if missing; `""` is the root. */
907
+ folder?: string;
908
+ };
909
+ type BulkMoveResult = {
910
+ files: FileWithUrl[];
911
+ failed: {
912
+ id: string;
913
+ message: string;
914
+ }[];
915
+ };
916
+ type BulkDeleteResult = {
917
+ deleted: string[];
918
+ failed: {
919
+ id: string;
920
+ message: string;
921
+ }[];
922
+ };
856
923
 
857
924
  declare class Base {
858
925
  private apiKey;
@@ -860,7 +927,7 @@ declare class Base {
860
927
  constructor(options?: VazeOptions);
861
928
  protected apiUrl(path: string, params?: Record<string, string | number | undefined>): string;
862
929
  protected request<T>(method: string, url: string, body?: Record<string, any> | FormData, headers?: Record<string, string>): Promise<ApiResponse<T>>;
863
- protected requestBlob(url: string): Promise<ApiResponse<{
930
+ protected requestBlob(url: string, method?: string, body?: Record<string, any>): Promise<ApiResponse<{
864
931
  blob: Blob;
865
932
  filename: string | null;
866
933
  contentType: string;
@@ -876,4 +943,4 @@ declare class Vaze extends Base implements IVaze {
876
943
  }>>;
877
944
  }
878
945
 
879
- export { type ApiResponse, type FileWithUrl as File, type Folder, type ListOptions, type SignOptions, type SignedUrl, type VazeOptions, type Visibility, Vaze as default };
946
+ export { type ApiResponse, type BulkDeleteResult, type BulkMoveResult, type FileWithUrl as File, type Folder, type ListOptions, type MoveDestination, type SignOptions, type SignedUrl, type VazeOptions, type Visibility, Vaze as default };
package/dist/index.js CHANGED
@@ -92,10 +92,14 @@ var Base = class {
92
92
  };
93
93
  }
94
94
  }
95
- async requestBlob(url) {
95
+ async requestBlob(url, method = "GET", body) {
96
96
  try {
97
+ const headers = { "API-Key": this.apiKey };
98
+ if (body !== void 0) headers["Content-Type"] = "application/json";
97
99
  const response = await fetch(url, {
98
- headers: { "API-Key": this.apiKey }
100
+ method,
101
+ headers,
102
+ body: body !== void 0 ? JSON.stringify(body) : null
99
103
  });
100
104
  const contentType = response.headers.get("content-type") ?? "";
101
105
  if (!response.ok) {
@@ -219,12 +223,49 @@ var Files = class extends Base {
219
223
  const url = this.apiUrl(`/api/files/download/${encodeURIComponent(id)}`);
220
224
  return await this.requestBlob(url);
221
225
  }
226
+ /** Download several files as one zip, with paths below their shared folder. */
227
+ async downloadMany(ids) {
228
+ return await this.requestBlob(this.apiUrl("/api/files/download"), "POST", {
229
+ ids
230
+ });
231
+ }
222
232
  async rename(data) {
223
233
  return await this.request("PUT", this.apiUrl("/api/files"), data);
224
234
  }
225
235
  async setVisibility(data) {
226
236
  return await this.request("PUT", this.apiUrl("/api/files"), data);
227
237
  }
238
+ /** Move a file into another folder; its key and URL change with it. */
239
+ async move(data) {
240
+ const { data: responseData, error } = await this.request("POST", this.apiUrl("/api/files/move"), data);
241
+ return {
242
+ error,
243
+ data: responseData ? {
244
+ file: constructFileUrls({
245
+ vazeUrl: this.vazeUrl,
246
+ files: [responseData.file]
247
+ })[0]
248
+ } : null
249
+ };
250
+ }
251
+ /** Move several files into one folder; each id reports its own outcome. */
252
+ async moveMany(ids, destination) {
253
+ const { data, error } = await this.request(
254
+ "POST",
255
+ this.apiUrl("/api/files/move"),
256
+ { ids, ...destination }
257
+ );
258
+ return {
259
+ error,
260
+ data: data ? {
261
+ files: constructFileUrls({
262
+ vazeUrl: this.vazeUrl,
263
+ files: data.files
264
+ }),
265
+ failed: data.failed
266
+ } : null
267
+ };
268
+ }
228
269
  /** Mint a time-limited URL that reads a file without an API key. */
229
270
  async sign(options) {
230
271
  const { data, error } = await this.request(
@@ -242,6 +283,14 @@ var Files = class extends Base {
242
283
  id
243
284
  });
244
285
  }
286
+ /** Delete several files in one request; each id reports its own outcome. */
287
+ async deleteMany(ids) {
288
+ return await this.request(
289
+ "DELETE",
290
+ this.apiUrl("/api/files"),
291
+ { ids }
292
+ );
293
+ }
245
294
  };
246
295
 
247
296
  // src/folders.ts
@@ -260,6 +309,12 @@ var Folders = class extends Base {
260
309
  } : null
261
310
  };
262
311
  }
312
+ /** Download a folder and everything below it as a zip; the root by default. */
313
+ async download(options) {
314
+ return await this.requestBlob(
315
+ this.apiUrl("/api/folders/download", options)
316
+ );
317
+ }
263
318
  async create(folder) {
264
319
  return await this.request(
265
320
  "POST",
@@ -270,6 +325,14 @@ var Folders = class extends Base {
270
325
  async rename(data) {
271
326
  return await this.request("PUT", this.apiUrl("/api/folders"), data);
272
327
  }
328
+ /** Move a folder, and everything inside it, into another folder. */
329
+ async move(data) {
330
+ return await this.request(
331
+ "POST",
332
+ this.apiUrl("/api/folders/move"),
333
+ data
334
+ );
335
+ }
273
336
  /** Apply a visibility to every file at or below this folder. */
274
337
  async setVisibility(data) {
275
338
  return await this.request("PUT", this.apiUrl("/api/folders"), data);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@darseen/vaze",
3
- "version": "2.1.0",
3
+ "version": "2.3.0",
4
4
  "description": "Vaze Self-Hosted file storage and hosting service SDK.",
5
5
  "keywords": [
6
6
  "api",
@@ -42,10 +42,10 @@
42
42
  "dist"
43
43
  ],
44
44
  "devDependencies": {
45
- "@types/node": "^25.5.0",
45
+ "@repo/types": "1.0.0",
46
+ "@types/node": "^26.6.2",
46
47
  "rimraf": "^6.1.3",
47
- "tsup": "^8.5.1",
48
- "@repo/types": "1.0.0"
48
+ "tsup": "^8.5.1"
49
49
  },
50
50
  "scripts": {
51
51
  "lint": "tsc --noEmit",