@darseen/vaze 2.1.0 → 2.2.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,6 +223,12 @@ 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
  }
@@ -242,6 +252,14 @@ var Files = class extends Base {
242
252
  id
243
253
  });
244
254
  }
255
+ /** Delete several files in one request; each id reports its own outcome. */
256
+ async deleteMany(ids) {
257
+ return await this.request(
258
+ "DELETE",
259
+ this.apiUrl("/api/files"),
260
+ { ids }
261
+ );
262
+ }
245
263
  };
246
264
 
247
265
  // src/folders.ts
@@ -260,6 +278,12 @@ var Folders = class extends Base {
260
278
  } : null
261
279
  };
262
280
  }
281
+ /** Download a folder and everything below it as a zip; the root by default. */
282
+ async download(options) {
283
+ return await this.requestBlob(
284
+ this.apiUrl("/api/folders/download", options)
285
+ );
286
+ }
263
287
  async create(folder) {
264
288
  return await this.request(
265
289
  "POST",
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;
@@ -798,6 +804,8 @@ declare class Files extends Base {
798
804
  } | null;
799
805
  }>;
800
806
  delete(id: string): Promise<ApiResponse<null>>;
807
+ /** Delete several files in one request; each id reports its own outcome. */
808
+ deleteMany(ids: string[]): Promise<ApiResponse<BulkDeleteResult>>;
801
809
  }
802
810
 
803
811
  declare class Folders extends Base {
@@ -814,6 +822,15 @@ declare class Folders extends Base {
814
822
  folders: Folder[];
815
823
  } | null;
816
824
  }>;
825
+ /** Download a folder and everything below it as a zip; the root by default. */
826
+ download(options?: {
827
+ id?: string;
828
+ key?: string;
829
+ }): Promise<ApiResponse<{
830
+ blob: Blob;
831
+ filename: string | null;
832
+ contentType: string;
833
+ }>>;
817
834
  create(folder: string): Promise<ApiResponse<{
818
835
  folder: Folder;
819
836
  }>>;
@@ -853,6 +870,13 @@ type SignedUrl = {
853
870
  url: string;
854
871
  expiresAt: string;
855
872
  };
873
+ type BulkDeleteResult = {
874
+ deleted: string[];
875
+ failed: {
876
+ id: string;
877
+ message: string;
878
+ }[];
879
+ };
856
880
 
857
881
  declare class Base {
858
882
  private apiKey;
@@ -860,7 +884,7 @@ declare class Base {
860
884
  constructor(options?: VazeOptions);
861
885
  protected apiUrl(path: string, params?: Record<string, string | number | undefined>): string;
862
886
  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<{
887
+ protected requestBlob(url: string, method?: string, body?: Record<string, any>): Promise<ApiResponse<{
864
888
  blob: Blob;
865
889
  filename: string | null;
866
890
  contentType: string;
@@ -876,4 +900,4 @@ declare class Vaze extends Base implements IVaze {
876
900
  }>>;
877
901
  }
878
902
 
879
- export { type ApiResponse, type FileWithUrl as File, type Folder, type ListOptions, type SignOptions, type SignedUrl, type VazeOptions, type Visibility, Vaze as default };
903
+ export { type ApiResponse, type BulkDeleteResult, type FileWithUrl as File, type Folder, type ListOptions, 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;
@@ -798,6 +804,8 @@ declare class Files extends Base {
798
804
  } | null;
799
805
  }>;
800
806
  delete(id: string): Promise<ApiResponse<null>>;
807
+ /** Delete several files in one request; each id reports its own outcome. */
808
+ deleteMany(ids: string[]): Promise<ApiResponse<BulkDeleteResult>>;
801
809
  }
802
810
 
803
811
  declare class Folders extends Base {
@@ -814,6 +822,15 @@ declare class Folders extends Base {
814
822
  folders: Folder[];
815
823
  } | null;
816
824
  }>;
825
+ /** Download a folder and everything below it as a zip; the root by default. */
826
+ download(options?: {
827
+ id?: string;
828
+ key?: string;
829
+ }): Promise<ApiResponse<{
830
+ blob: Blob;
831
+ filename: string | null;
832
+ contentType: string;
833
+ }>>;
817
834
  create(folder: string): Promise<ApiResponse<{
818
835
  folder: Folder;
819
836
  }>>;
@@ -853,6 +870,13 @@ type SignedUrl = {
853
870
  url: string;
854
871
  expiresAt: string;
855
872
  };
873
+ type BulkDeleteResult = {
874
+ deleted: string[];
875
+ failed: {
876
+ id: string;
877
+ message: string;
878
+ }[];
879
+ };
856
880
 
857
881
  declare class Base {
858
882
  private apiKey;
@@ -860,7 +884,7 @@ declare class Base {
860
884
  constructor(options?: VazeOptions);
861
885
  protected apiUrl(path: string, params?: Record<string, string | number | undefined>): string;
862
886
  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<{
887
+ protected requestBlob(url: string, method?: string, body?: Record<string, any>): Promise<ApiResponse<{
864
888
  blob: Blob;
865
889
  filename: string | null;
866
890
  contentType: string;
@@ -876,4 +900,4 @@ declare class Vaze extends Base implements IVaze {
876
900
  }>>;
877
901
  }
878
902
 
879
- export { type ApiResponse, type FileWithUrl as File, type Folder, type ListOptions, type SignOptions, type SignedUrl, type VazeOptions, type Visibility, Vaze as default };
903
+ export { type ApiResponse, type BulkDeleteResult, type FileWithUrl as File, type Folder, type ListOptions, 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,6 +223,12 @@ 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
  }
@@ -242,6 +252,14 @@ var Files = class extends Base {
242
252
  id
243
253
  });
244
254
  }
255
+ /** Delete several files in one request; each id reports its own outcome. */
256
+ async deleteMany(ids) {
257
+ return await this.request(
258
+ "DELETE",
259
+ this.apiUrl("/api/files"),
260
+ { ids }
261
+ );
262
+ }
245
263
  };
246
264
 
247
265
  // src/folders.ts
@@ -260,6 +278,12 @@ var Folders = class extends Base {
260
278
  } : null
261
279
  };
262
280
  }
281
+ /** Download a folder and everything below it as a zip; the root by default. */
282
+ async download(options) {
283
+ return await this.requestBlob(
284
+ this.apiUrl("/api/folders/download", options)
285
+ );
286
+ }
263
287
  async create(folder) {
264
288
  return await this.request(
265
289
  "POST",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@darseen/vaze",
3
- "version": "2.1.0",
3
+ "version": "2.2.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",