dosyadev 0.1.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/dist/index.js ADDED
@@ -0,0 +1,986 @@
1
+ // src/errors.ts
2
+ var DosyaError = class extends Error {
3
+ constructor(message) {
4
+ super(message);
5
+ this.name = "DosyaError";
6
+ }
7
+ };
8
+ var DosyaApiError = class extends DosyaError {
9
+ status;
10
+ errorMessage;
11
+ raw;
12
+ constructor(status, errorMessage, raw) {
13
+ super(`[${status}] ${errorMessage}`);
14
+ this.name = "DosyaApiError";
15
+ this.status = status;
16
+ this.errorMessage = errorMessage;
17
+ this.raw = raw;
18
+ }
19
+ };
20
+ var DosyaNetworkError = class extends DosyaError {
21
+ cause;
22
+ constructor(message, options) {
23
+ super(message);
24
+ this.name = "DosyaNetworkError";
25
+ this.cause = options?.cause;
26
+ }
27
+ };
28
+ var DosyaUploadError = class extends DosyaError {
29
+ sessionId;
30
+ partNumber;
31
+ constructor(message, sessionId, partNumber) {
32
+ super(message);
33
+ this.name = "DosyaUploadError";
34
+ this.sessionId = sessionId;
35
+ this.partNumber = partNumber;
36
+ }
37
+ };
38
+
39
+ // src/http.ts
40
+ function camelToSnake(str) {
41
+ return str.replace(/[A-Z]/g, (m) => `_${m.toLowerCase()}`);
42
+ }
43
+ function snakeToCamel(str) {
44
+ return str.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
45
+ }
46
+ function convertKeys(obj, fn) {
47
+ if (Array.isArray(obj)) return obj.map((v) => convertKeys(v, fn));
48
+ if (obj !== null && typeof obj === "object" && !(obj instanceof Date)) {
49
+ const out = {};
50
+ for (const [k, v] of Object.entries(obj)) {
51
+ out[fn(k)] = convertKeys(v, fn);
52
+ }
53
+ return out;
54
+ }
55
+ return obj;
56
+ }
57
+ var HttpClient = class {
58
+ baseUrl;
59
+ apiKey;
60
+ fetchFn;
61
+ maxRetries;
62
+ baseDelay;
63
+ maxDelay;
64
+ onRateLimit;
65
+ constructor(options) {
66
+ this.baseUrl = (options.baseUrl ?? "https://dosya.dev").replace(/\/+$/, "");
67
+ this.apiKey = options.apiKey;
68
+ this.fetchFn = options.fetch ?? globalThis.fetch.bind(globalThis);
69
+ this.maxRetries = options.retry?.maxRetries ?? 3;
70
+ this.baseDelay = options.retry?.baseDelay ?? 500;
71
+ this.maxDelay = options.retry?.maxDelay ?? 3e4;
72
+ this.onRateLimit = options.onRateLimit;
73
+ }
74
+ async request(opts) {
75
+ const res = await this.doFetch(opts);
76
+ if (opts.rawResponse) {
77
+ return res;
78
+ }
79
+ const text = await res.text();
80
+ let json;
81
+ try {
82
+ json = JSON.parse(text);
83
+ } catch {
84
+ throw new DosyaApiError(res.status, `Invalid JSON response: ${text.slice(0, 200)}`);
85
+ }
86
+ if (!json.ok) {
87
+ throw new DosyaApiError(
88
+ res.status,
89
+ json.error ?? "Unknown error",
90
+ json
91
+ );
92
+ }
93
+ const { ok: _, ...payload } = json;
94
+ return convertKeys(payload, snakeToCamel);
95
+ }
96
+ async requestRaw(opts) {
97
+ return this.doFetch(opts);
98
+ }
99
+ async doFetch(opts) {
100
+ const url = this.buildUrl(opts.path, opts.query);
101
+ const headers = {
102
+ Authorization: `Bearer ${this.apiKey}`,
103
+ ...opts.headers
104
+ };
105
+ let fetchBody;
106
+ if (opts.rawBody !== void 0) {
107
+ fetchBody = opts.rawBody;
108
+ } else if (opts.body !== void 0) {
109
+ headers["Content-Type"] = "application/json";
110
+ fetchBody = JSON.stringify(convertKeys(opts.body, camelToSnake));
111
+ }
112
+ let lastError;
113
+ for (let attempt = 0; attempt <= this.maxRetries; attempt++) {
114
+ try {
115
+ const res = await this.fetchFn(url, {
116
+ method: opts.method,
117
+ headers,
118
+ body: fetchBody,
119
+ signal: opts.signal,
120
+ redirect: opts.rawResponse ? "manual" : "follow"
121
+ });
122
+ this.extractRateLimit(res);
123
+ if (res.status === 429) {
124
+ const retryAfter = res.headers.get("Retry-After");
125
+ const delay = retryAfter ? parseInt(retryAfter, 10) * 1e3 : this.getDelay(attempt);
126
+ if (attempt < this.maxRetries) {
127
+ await this.sleep(delay);
128
+ continue;
129
+ }
130
+ }
131
+ if (res.status >= 500 && attempt < this.maxRetries) {
132
+ await this.sleep(this.getDelay(attempt));
133
+ continue;
134
+ }
135
+ return res;
136
+ } catch (err) {
137
+ lastError = err;
138
+ if (err instanceof DOMException && err.name === "AbortError") throw err;
139
+ if (attempt < this.maxRetries) {
140
+ await this.sleep(this.getDelay(attempt));
141
+ continue;
142
+ }
143
+ }
144
+ }
145
+ throw new DosyaNetworkError(
146
+ `Request to ${opts.method} ${opts.path} failed after ${this.maxRetries + 1} attempts`,
147
+ { cause: lastError }
148
+ );
149
+ }
150
+ buildUrl(path, query) {
151
+ const url = new URL(path, this.baseUrl);
152
+ if (query) {
153
+ for (const [key, value] of Object.entries(query)) {
154
+ if (value != null && value !== "") {
155
+ url.searchParams.set(camelToSnake(key), String(value));
156
+ }
157
+ }
158
+ }
159
+ return url.toString();
160
+ }
161
+ extractRateLimit(res) {
162
+ if (!this.onRateLimit) return;
163
+ const limit = res.headers.get("X-RateLimit-Limit");
164
+ const remaining = res.headers.get("X-RateLimit-Remaining");
165
+ const reset = res.headers.get("X-RateLimit-Reset");
166
+ if (limit && remaining && reset) {
167
+ this.onRateLimit({
168
+ limit: parseInt(limit, 10),
169
+ remaining: parseInt(remaining, 10),
170
+ resetAt: parseInt(reset, 10)
171
+ });
172
+ }
173
+ }
174
+ getDelay(attempt) {
175
+ const delay = this.baseDelay * 2 ** attempt;
176
+ const jitter = delay * 0.2 * Math.random();
177
+ return Math.min(delay + jitter, this.maxDelay);
178
+ }
179
+ sleep(ms) {
180
+ return new Promise((resolve) => setTimeout(resolve, ms));
181
+ }
182
+ };
183
+
184
+ // src/resources/files.ts
185
+ var FilesResource = class {
186
+ constructor(http) {
187
+ this.http = http;
188
+ }
189
+ http;
190
+ async list(params) {
191
+ return this.http.request({
192
+ method: "GET",
193
+ path: "/api/files",
194
+ query: {
195
+ workspace_id: params.workspaceId,
196
+ folder_id: params.folderId,
197
+ filter: params.filter,
198
+ sort: params.sort,
199
+ q: params.q,
200
+ deleted: params.deleted,
201
+ hidden: params.hidden,
202
+ page: params.page,
203
+ per_page: params.perPage
204
+ }
205
+ });
206
+ }
207
+ async get(fileId) {
208
+ return this.http.request({
209
+ method: "GET",
210
+ path: `/api/files/${fileId}`
211
+ });
212
+ }
213
+ async delete(fileId) {
214
+ return this.http.request({
215
+ method: "DELETE",
216
+ path: `/api/files/${fileId}`
217
+ });
218
+ }
219
+ async restore(fileId) {
220
+ await this.http.request({
221
+ method: "PUT",
222
+ path: `/api/files/${fileId}`
223
+ });
224
+ }
225
+ async rename(fileId, name) {
226
+ return this.http.request({
227
+ method: "PUT",
228
+ path: `/api/files/${fileId}/rename`,
229
+ body: { name }
230
+ });
231
+ }
232
+ async move(fileId, folderId) {
233
+ await this.http.request({
234
+ method: "PUT",
235
+ path: `/api/files/${fileId}/move`,
236
+ body: { folderId }
237
+ });
238
+ }
239
+ async copy(fileId, options) {
240
+ return this.http.request({
241
+ method: "POST",
242
+ path: `/api/files/${fileId}/copy`,
243
+ body: {
244
+ newName: options?.newName,
245
+ folderId: options?.folderId
246
+ }
247
+ });
248
+ }
249
+ async lock(fileId, params) {
250
+ await this.http.request({
251
+ method: "POST",
252
+ path: `/api/files/${fileId}/lock`,
253
+ body: { lockMode: params.lockMode, password: params.password }
254
+ });
255
+ }
256
+ async unlock(fileId) {
257
+ await this.http.request({
258
+ method: "POST",
259
+ path: `/api/files/${fileId}/unlock`
260
+ });
261
+ }
262
+ async hide(fileId, params) {
263
+ await this.http.request({
264
+ method: "POST",
265
+ path: `/api/files/${fileId}/hide`,
266
+ body: {
267
+ hiddenMode: params?.hiddenMode,
268
+ targetIds: params?.targetIds
269
+ }
270
+ });
271
+ }
272
+ async listVersions(fileId) {
273
+ return this.http.request({
274
+ method: "GET",
275
+ path: `/api/files/${fileId}/versions`
276
+ });
277
+ }
278
+ async restoreVersion(fileId, versionNumber) {
279
+ return this.http.request({
280
+ method: "POST",
281
+ path: `/api/files/${fileId}/versions/restore`,
282
+ body: { versionNumber }
283
+ });
284
+ }
285
+ async getShareLinks(fileId) {
286
+ return this.http.request({
287
+ method: "GET",
288
+ path: `/api/files/${fileId}/share`
289
+ });
290
+ }
291
+ async createShareLink(fileId, params) {
292
+ return this.http.request({
293
+ method: "POST",
294
+ path: `/api/files/${fileId}/share`,
295
+ body: {
296
+ expiresInDays: params?.expiresInDays,
297
+ password: params?.password,
298
+ lockMode: params?.lockMode
299
+ }
300
+ });
301
+ }
302
+ async shareByEmail(fileId, params) {
303
+ await this.http.request({
304
+ method: "POST",
305
+ path: `/api/files/${fileId}/share-email`,
306
+ body: { emails: params.emails, message: params.message }
307
+ });
308
+ }
309
+ async createShareBundle(params) {
310
+ return this.http.request({
311
+ method: "POST",
312
+ path: "/api/files/share-bundle",
313
+ body: {
314
+ fileIds: params.fileIds,
315
+ expiresInDays: params.expiresInDays,
316
+ password: params.password
317
+ }
318
+ });
319
+ }
320
+ };
321
+
322
+ // src/resources/folders.ts
323
+ var FoldersResource = class {
324
+ constructor(http) {
325
+ this.http = http;
326
+ }
327
+ http;
328
+ async create(params) {
329
+ return this.http.request({
330
+ method: "POST",
331
+ path: "/api/folders",
332
+ body: {
333
+ workspaceId: params.workspaceId,
334
+ parentId: params.parentId,
335
+ name: params.name
336
+ }
337
+ });
338
+ }
339
+ async get(folderId) {
340
+ return this.http.request({
341
+ method: "GET",
342
+ path: `/api/folders/${folderId}`
343
+ });
344
+ }
345
+ async rename(folderId, name) {
346
+ return this.http.request({
347
+ method: "PUT",
348
+ path: `/api/folders/${folderId}`,
349
+ body: { name }
350
+ });
351
+ }
352
+ async delete(folderId) {
353
+ return this.http.request({
354
+ method: "DELETE",
355
+ path: `/api/folders/${folderId}`
356
+ });
357
+ }
358
+ async move(folderId, parentId) {
359
+ await this.http.request({
360
+ method: "PUT",
361
+ path: `/api/folders/${folderId}/move`,
362
+ body: { parentId }
363
+ });
364
+ }
365
+ async tree(workspaceId) {
366
+ return this.http.request({
367
+ method: "GET",
368
+ path: "/api/folders/tree",
369
+ query: { workspace_id: workspaceId }
370
+ });
371
+ }
372
+ async lock(folderId, params) {
373
+ await this.http.request({
374
+ method: "POST",
375
+ path: `/api/folders/${folderId}/lock`,
376
+ body: { lockMode: params.lockMode, password: params.password }
377
+ });
378
+ }
379
+ async unlock(folderId) {
380
+ await this.http.request({
381
+ method: "POST",
382
+ path: `/api/folders/${folderId}/unlock`
383
+ });
384
+ }
385
+ };
386
+
387
+ // src/resources/upload.ts
388
+ var CONCURRENCY = 3;
389
+ var UploadResource = class {
390
+ constructor(http) {
391
+ this.http = http;
392
+ }
393
+ http;
394
+ async file(params) {
395
+ params.onProgress?.({
396
+ bytesUploaded: 0,
397
+ totalBytes: params.fileSize,
398
+ percent: 0,
399
+ status: "initializing"
400
+ });
401
+ const session = await this.init({
402
+ workspaceId: params.workspaceId,
403
+ fileName: params.fileName,
404
+ fileSize: params.fileSize,
405
+ mimeType: params.mimeType,
406
+ region: params.region,
407
+ folderId: params.folderId,
408
+ fileId: params.fileId
409
+ });
410
+ if (session.resumable) {
411
+ return this.uploadMultipart(
412
+ session.sessionId,
413
+ session.resumable,
414
+ params.body,
415
+ params.fileSize,
416
+ session.mimeType,
417
+ params.onProgress,
418
+ params.abortSignal
419
+ );
420
+ }
421
+ return this.uploadSingle(
422
+ session.sessionId,
423
+ session.uploadUrl,
424
+ params.body,
425
+ session.mimeType,
426
+ params.fileSize,
427
+ params.onProgress,
428
+ params.abortSignal
429
+ );
430
+ }
431
+ async resume(sessionId, body, options) {
432
+ const st = await this.status(sessionId);
433
+ if (st.status === "complete") {
434
+ throw new DosyaUploadError("Upload session is already complete", sessionId);
435
+ }
436
+ if (!st.hasMultipart || !st.partSize || !st.totalParts) {
437
+ throw new DosyaUploadError(
438
+ "Cannot resume a non-multipart upload session",
439
+ sessionId
440
+ );
441
+ }
442
+ return this.uploadMultipart(
443
+ sessionId,
444
+ {
445
+ partSize: st.partSize,
446
+ totalParts: st.totalParts,
447
+ partUploadUrl: `/api/upload/${sessionId}/part`,
448
+ completeUrl: `/api/upload/${sessionId}/complete`,
449
+ statusUrl: `/api/upload/${sessionId}/status`
450
+ },
451
+ body,
452
+ st.sizeBytes,
453
+ "application/octet-stream",
454
+ options?.onProgress,
455
+ options?.abortSignal,
456
+ st.uploadedParts
457
+ );
458
+ }
459
+ async init(params) {
460
+ return this.http.request({
461
+ method: "POST",
462
+ path: "/api/upload/init",
463
+ body: {
464
+ workspaceId: params.workspaceId,
465
+ fileName: params.fileName,
466
+ fileSize: params.fileSize,
467
+ mimeType: params.mimeType,
468
+ region: params.region,
469
+ folderId: params.folderId,
470
+ fileId: params.fileId
471
+ }
472
+ });
473
+ }
474
+ async status(sessionId) {
475
+ return this.http.request({
476
+ method: "GET",
477
+ path: `/api/upload/${sessionId}/status`
478
+ });
479
+ }
480
+ // ── Private ──
481
+ async uploadSingle(sessionId, uploadUrl, body, mimeType, totalBytes, onProgress, signal) {
482
+ onProgress?.({
483
+ bytesUploaded: 0,
484
+ totalBytes,
485
+ percent: 0,
486
+ status: "uploading"
487
+ });
488
+ const buf = await this.sourceToBuffer(body);
489
+ const result = await this.http.request({
490
+ method: "PUT",
491
+ path: uploadUrl,
492
+ rawBody: buf,
493
+ headers: { "Content-Type": mimeType },
494
+ signal
495
+ });
496
+ onProgress?.({
497
+ bytesUploaded: totalBytes,
498
+ totalBytes,
499
+ percent: 100,
500
+ status: "complete"
501
+ });
502
+ return { file: result.file, sessionId };
503
+ }
504
+ async uploadMultipart(sessionId, resumable, body, totalBytes, mimeType, onProgress, signal, alreadyUploaded = []) {
505
+ const { partSize, totalParts, partUploadUrl, completeUrl } = resumable;
506
+ const uploadedSet = new Set(alreadyUploaded);
507
+ let bytesUploaded = alreadyUploaded.length * partSize;
508
+ if (bytesUploaded > totalBytes) bytesUploaded = totalBytes;
509
+ onProgress?.({
510
+ bytesUploaded,
511
+ totalBytes,
512
+ percent: Math.round(bytesUploaded / totalBytes * 100),
513
+ partsCompleted: uploadedSet.size,
514
+ totalParts,
515
+ status: "uploading"
516
+ });
517
+ const allBytes = await this.sourceToBuffer(body);
518
+ const parts = [];
519
+ for (let i = 1; i <= totalParts; i++) {
520
+ if (uploadedSet.has(i)) continue;
521
+ const start = (i - 1) * partSize;
522
+ const end = Math.min(start + partSize, allBytes.byteLength);
523
+ parts.push({
524
+ partNumber: i,
525
+ chunk: new Uint8Array(allBytes.slice(start, end))
526
+ });
527
+ }
528
+ let partIdx = 0;
529
+ const uploadPart = async () => {
530
+ while (partIdx < parts.length) {
531
+ if (signal?.aborted) throw new DOMException("Upload aborted", "AbortError");
532
+ const idx = partIdx++;
533
+ const part = parts[idx];
534
+ let lastErr;
535
+ for (let attempt = 0; attempt < 3; attempt++) {
536
+ try {
537
+ await this.http.request({
538
+ method: "PUT",
539
+ path: `${partUploadUrl}/${part.partNumber}`,
540
+ rawBody: part.chunk,
541
+ headers: { "Content-Type": mimeType },
542
+ signal
543
+ });
544
+ break;
545
+ } catch (err) {
546
+ lastErr = err;
547
+ if (err instanceof DOMException && err.name === "AbortError") throw err;
548
+ if (attempt === 2) {
549
+ throw new DosyaUploadError(
550
+ `Failed to upload part ${part.partNumber} after 3 attempts: ${lastErr}`,
551
+ sessionId,
552
+ part.partNumber
553
+ );
554
+ }
555
+ await new Promise((r) => setTimeout(r, 500 * 2 ** attempt));
556
+ }
557
+ }
558
+ uploadedSet.add(part.partNumber);
559
+ bytesUploaded = Math.min(uploadedSet.size * partSize, totalBytes);
560
+ onProgress?.({
561
+ bytesUploaded,
562
+ totalBytes,
563
+ percent: Math.round(bytesUploaded / totalBytes * 100),
564
+ partsCompleted: uploadedSet.size,
565
+ totalParts,
566
+ status: "uploading"
567
+ });
568
+ }
569
+ };
570
+ const workers = Array.from(
571
+ { length: Math.min(CONCURRENCY, parts.length) },
572
+ () => uploadPart()
573
+ );
574
+ await Promise.all(workers);
575
+ onProgress?.({
576
+ bytesUploaded: totalBytes,
577
+ totalBytes,
578
+ percent: 99,
579
+ partsCompleted: totalParts,
580
+ totalParts,
581
+ status: "completing"
582
+ });
583
+ const result = await this.http.request({
584
+ method: "POST",
585
+ path: completeUrl,
586
+ signal
587
+ });
588
+ onProgress?.({
589
+ bytesUploaded: totalBytes,
590
+ totalBytes,
591
+ percent: 100,
592
+ partsCompleted: totalParts,
593
+ totalParts,
594
+ status: "complete"
595
+ });
596
+ return { file: result.file, sessionId };
597
+ }
598
+ async sourceToBuffer(source) {
599
+ if (source instanceof ArrayBuffer) return source;
600
+ if (source instanceof Uint8Array) {
601
+ const copy = new ArrayBuffer(source.byteLength);
602
+ new Uint8Array(copy).set(source);
603
+ return copy;
604
+ }
605
+ if (typeof Blob !== "undefined" && source instanceof Blob) {
606
+ return source.arrayBuffer();
607
+ }
608
+ if (source instanceof ReadableStream) {
609
+ return this.streamToBuffer(source);
610
+ }
611
+ if ("arrayBuffer" in source && typeof source.arrayBuffer === "function") {
612
+ return source.arrayBuffer();
613
+ }
614
+ throw new Error(`Unsupported upload source type: ${typeof source}`);
615
+ }
616
+ async streamToBuffer(stream) {
617
+ const reader = stream.getReader();
618
+ const chunks = [];
619
+ let totalLength = 0;
620
+ while (true) {
621
+ const { done, value } = await reader.read();
622
+ if (done) break;
623
+ chunks.push(value);
624
+ totalLength += value.byteLength;
625
+ }
626
+ const result = new Uint8Array(totalLength);
627
+ let offset = 0;
628
+ for (const chunk of chunks) {
629
+ result.set(chunk, offset);
630
+ offset += chunk.byteLength;
631
+ }
632
+ return result.buffer;
633
+ }
634
+ };
635
+
636
+ // src/resources/download.ts
637
+ var DownloadResource = class {
638
+ constructor(http) {
639
+ this.http = http;
640
+ }
641
+ http;
642
+ async getUrl(fileId, options) {
643
+ const res = await this.http.requestRaw({
644
+ method: "GET",
645
+ path: `/api/files/${fileId}/download`,
646
+ query: {
647
+ version: options?.version,
648
+ ut: options?.unlockToken
649
+ },
650
+ rawResponse: true
651
+ });
652
+ const location = res.headers.get("Location");
653
+ if (location) return location;
654
+ if (res.url) return res.url;
655
+ throw new Error("Could not extract download URL from response");
656
+ }
657
+ async arrayBuffer(fileId, options) {
658
+ const url = await this.getUrl(fileId, options);
659
+ const res = await fetch(url);
660
+ if (!res.ok) {
661
+ throw new Error(`Download failed with status ${res.status}`);
662
+ }
663
+ return res.arrayBuffer();
664
+ }
665
+ async stream(fileId, options) {
666
+ const url = await this.getUrl(fileId, options);
667
+ const res = await fetch(url);
668
+ if (!res.ok) {
669
+ throw new Error(`Download failed with status ${res.status}`);
670
+ }
671
+ if (!res.body) {
672
+ throw new Error("Response body is null \u2014 streaming not supported");
673
+ }
674
+ return res.body;
675
+ }
676
+ async raw(fileId, options) {
677
+ return this.http.requestRaw({
678
+ method: "GET",
679
+ path: `/api/files/${fileId}/raw`,
680
+ query: {
681
+ version: options?.version,
682
+ ut: options?.unlockToken
683
+ }
684
+ });
685
+ }
686
+ };
687
+
688
+ // src/resources/shares.ts
689
+ var SharesResource = class {
690
+ constructor(http) {
691
+ this.http = http;
692
+ }
693
+ http;
694
+ async list(workspaceId) {
695
+ return this.http.request({
696
+ method: "GET",
697
+ path: "/api/shares",
698
+ query: { workspace_id: workspaceId }
699
+ });
700
+ }
701
+ async revoke(linkId) {
702
+ await this.http.request({
703
+ method: "POST",
704
+ path: `/api/shares/${linkId}/revoke`
705
+ });
706
+ }
707
+ };
708
+
709
+ // src/resources/workspaces.ts
710
+ var WorkspacesResource = class {
711
+ constructor(http) {
712
+ this.http = http;
713
+ }
714
+ http;
715
+ async list() {
716
+ return this.http.request({
717
+ method: "GET",
718
+ path: "/api/workspaces"
719
+ });
720
+ }
721
+ async get(workspaceId) {
722
+ return this.http.request({
723
+ method: "GET",
724
+ path: `/api/workspaces/${workspaceId}`
725
+ });
726
+ }
727
+ async create(params) {
728
+ return this.http.request({
729
+ method: "POST",
730
+ path: "/api/workspaces",
731
+ body: {
732
+ name: params.name,
733
+ iconInitials: params.iconInitials,
734
+ iconColor: params.iconColor,
735
+ defaultRegion: params.defaultRegion
736
+ }
737
+ });
738
+ }
739
+ async update(workspaceId, params) {
740
+ await this.http.request({
741
+ method: "PUT",
742
+ path: `/api/workspaces/${workspaceId}`,
743
+ body: {
744
+ name: params.name,
745
+ iconInitials: params.iconInitials,
746
+ iconColor: params.iconColor,
747
+ defaultRegion: params.defaultRegion
748
+ }
749
+ });
750
+ }
751
+ async updateSettings(workspaceId, settings) {
752
+ await this.http.request({
753
+ method: "PUT",
754
+ path: `/api/workspaces/${workspaceId}/settings`,
755
+ body: settings
756
+ });
757
+ }
758
+ async delete(workspaceId) {
759
+ await this.http.request({
760
+ method: "DELETE",
761
+ path: `/api/workspaces/${workspaceId}`
762
+ });
763
+ }
764
+ };
765
+
766
+ // src/resources/file-requests.ts
767
+ var FileRequestsResource = class {
768
+ constructor(http) {
769
+ this.http = http;
770
+ }
771
+ http;
772
+ async create(params) {
773
+ return this.http.request({
774
+ method: "POST",
775
+ path: "/api/file-requests/create",
776
+ body: {
777
+ workspaceId: params.workspaceId,
778
+ folderId: params.folderId,
779
+ title: params.title,
780
+ message: params.message,
781
+ password: params.password,
782
+ expiresInDays: params.expiresInDays,
783
+ allowedExtensions: params.allowedExtensions,
784
+ maxFileSizeMb: params.maxFileSizeMb,
785
+ maxFiles: params.maxFiles,
786
+ emails: params.emails
787
+ }
788
+ });
789
+ }
790
+ async get(requestId) {
791
+ return this.http.request({
792
+ method: "GET",
793
+ path: `/api/file-requests/${requestId}`
794
+ });
795
+ }
796
+ async update(requestId, params) {
797
+ await this.http.request({
798
+ method: "PUT",
799
+ path: `/api/file-requests/${requestId}`,
800
+ body: { title: params.title, message: params.message }
801
+ });
802
+ }
803
+ async delete(requestId) {
804
+ await this.http.request({
805
+ method: "DELETE",
806
+ path: `/api/file-requests/${requestId}`
807
+ });
808
+ }
809
+ async listUploads(requestId) {
810
+ return this.http.request({
811
+ method: "GET",
812
+ path: `/api/file-requests/${requestId}/uploads`
813
+ });
814
+ }
815
+ async listRecipients(requestId) {
816
+ return this.http.request({
817
+ method: "GET",
818
+ path: `/api/file-requests/${requestId}/recipients`
819
+ });
820
+ }
821
+ async resend(requestId, recipientIds) {
822
+ await this.http.request({
823
+ method: "POST",
824
+ path: `/api/file-requests/${requestId}/resend`,
825
+ body: { recipientIds }
826
+ });
827
+ }
828
+ };
829
+
830
+ // src/resources/search.ts
831
+ var SearchResource = class {
832
+ constructor(http) {
833
+ this.http = http;
834
+ }
835
+ http;
836
+ async query(params) {
837
+ return this.http.request({
838
+ method: "GET",
839
+ path: "/api/search",
840
+ query: {
841
+ workspace_id: params.workspaceId,
842
+ q: params.q,
843
+ page: params.page,
844
+ per_page: params.perPage
845
+ }
846
+ });
847
+ }
848
+ };
849
+
850
+ // src/resources/comments.ts
851
+ var CommentsResource = class {
852
+ constructor(http) {
853
+ this.http = http;
854
+ }
855
+ http;
856
+ async list(params) {
857
+ return this.http.request({
858
+ method: "GET",
859
+ path: "/api/comments",
860
+ query: {
861
+ workspace_id: params.workspaceId,
862
+ file_id: params.fileId,
863
+ folder_id: params.folderId
864
+ }
865
+ });
866
+ }
867
+ async create(params) {
868
+ return this.http.request({
869
+ method: "POST",
870
+ path: "/api/comments",
871
+ body: {
872
+ workspaceId: params.workspaceId,
873
+ fileId: params.fileId,
874
+ folderId: params.folderId,
875
+ parentId: params.parentId,
876
+ body: params.body
877
+ }
878
+ });
879
+ }
880
+ async edit(commentId, body) {
881
+ return this.http.request({
882
+ method: "PUT",
883
+ path: `/api/comments/${commentId}`,
884
+ body: { body }
885
+ });
886
+ }
887
+ async delete(commentId) {
888
+ await this.http.request({
889
+ method: "DELETE",
890
+ path: `/api/comments/${commentId}`
891
+ });
892
+ }
893
+ };
894
+
895
+ // src/resources/me.ts
896
+ var MeResource = class {
897
+ constructor(http) {
898
+ this.http = http;
899
+ }
900
+ http;
901
+ async profile() {
902
+ return this.http.request({
903
+ method: "GET",
904
+ path: "/api/me"
905
+ });
906
+ }
907
+ async listApiKeys() {
908
+ return this.http.request({
909
+ method: "GET",
910
+ path: "/api/me/api-keys"
911
+ });
912
+ }
913
+ async createApiKey(params) {
914
+ return this.http.request({
915
+ method: "POST",
916
+ path: "/api/me/api-keys",
917
+ body: {
918
+ name: params.name,
919
+ scope: params.scope,
920
+ expiresInDays: params.expiresInDays
921
+ }
922
+ });
923
+ }
924
+ async deleteApiKey(keyId) {
925
+ await this.http.request({
926
+ method: "DELETE",
927
+ path: `/api/me/api-keys/${keyId}`
928
+ });
929
+ }
930
+ };
931
+
932
+ // src/resources/activity.ts
933
+ var ActivityResource = class {
934
+ constructor(http) {
935
+ this.http = http;
936
+ }
937
+ http;
938
+ async list(params) {
939
+ return this.http.request({
940
+ method: "GET",
941
+ path: "/api/activity",
942
+ query: {
943
+ workspace_id: params.workspaceId,
944
+ page: params.page,
945
+ per_page: params.perPage,
946
+ category: params.category,
947
+ action: params.action,
948
+ user_id: params.userId
949
+ }
950
+ });
951
+ }
952
+ };
953
+
954
+ // src/client.ts
955
+ var DosyaClient = class {
956
+ files;
957
+ folders;
958
+ upload;
959
+ download;
960
+ shares;
961
+ workspaces;
962
+ fileRequests;
963
+ search;
964
+ comments;
965
+ me;
966
+ activity;
967
+ constructor(options) {
968
+ if (!options.apiKey?.startsWith("dos_")) {
969
+ throw new Error("API key must start with 'dos_'");
970
+ }
971
+ const http = new HttpClient(options);
972
+ this.files = new FilesResource(http);
973
+ this.folders = new FoldersResource(http);
974
+ this.upload = new UploadResource(http);
975
+ this.download = new DownloadResource(http);
976
+ this.shares = new SharesResource(http);
977
+ this.workspaces = new WorkspacesResource(http);
978
+ this.fileRequests = new FileRequestsResource(http);
979
+ this.search = new SearchResource(http);
980
+ this.comments = new CommentsResource(http);
981
+ this.me = new MeResource(http);
982
+ this.activity = new ActivityResource(http);
983
+ }
984
+ };
985
+
986
+ export { DosyaApiError, DosyaClient, DosyaError, DosyaNetworkError, DosyaUploadError };