@ragable/sdk 0.6.23 → 0.7.5

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.mjs CHANGED
@@ -3484,15 +3484,171 @@ function createRagPipeline(client, options) {
3484
3484
  };
3485
3485
  }
3486
3486
 
3487
+ // src/storage.ts
3488
+ function normalizeUploadFile2(file, contentType) {
3489
+ if (file instanceof Blob) return file;
3490
+ const u8 = file instanceof ArrayBuffer ? new Uint8Array(file) : new Uint8Array(file);
3491
+ return new Blob([u8.buffer], contentType ? { type: contentType } : {});
3492
+ }
3493
+ var StorageClient = class {
3494
+ constructor(client) {
3495
+ this.client = client;
3496
+ /**
3497
+ * Bucket-level CRUD — list, create and delete buckets for this organisation.
3498
+ */
3499
+ __publicField(this, "buckets");
3500
+ this.buckets = {
3501
+ list: async (params) => {
3502
+ const qs = new URLSearchParams();
3503
+ if (params?.q) qs.set("q", params.q);
3504
+ if (params?.status) qs.set("status", params.status);
3505
+ if (params?.sort) qs.set("sort", params.sort);
3506
+ const query = qs.toString();
3507
+ return this.client.request(
3508
+ `/v1/storage/buckets${query ? `?${query}` : ""}`
3509
+ );
3510
+ },
3511
+ create: async (name) => {
3512
+ return this.client.request("/v1/storage/buckets", {
3513
+ method: "POST",
3514
+ body: { name }
3515
+ });
3516
+ },
3517
+ delete: async (bucketId) => {
3518
+ return this.client.request(
3519
+ `/v1/storage/buckets/${encodeURIComponent(bucketId)}`,
3520
+ { method: "DELETE" }
3521
+ );
3522
+ }
3523
+ };
3524
+ }
3525
+ /**
3526
+ * Returns a {@link StorageBucketClient} scoped to the given bucket ID.
3527
+ *
3528
+ * All object operations (upload, download, list, copy, move, signed URLs, …)
3529
+ * are performed through the returned client.
3530
+ *
3531
+ * @param bucketId The Ragable bucket ID obtained from `buckets.list()` or `buckets.create()`.
3532
+ */
3533
+ from(bucketId) {
3534
+ const { client } = this;
3535
+ const base = `/v1/storage/buckets/${encodeURIComponent(bucketId)}`;
3536
+ return {
3537
+ list: async (params) => {
3538
+ const qs = new URLSearchParams();
3539
+ if (params?.prefix) qs.set("prefix", params.prefix);
3540
+ if (params?.delimiter) qs.set("delimiter", params.delimiter);
3541
+ if (params?.maxResults != null)
3542
+ qs.set("maxResults", String(params.maxResults));
3543
+ if (params?.pageToken) qs.set("pageToken", params.pageToken);
3544
+ const query = qs.toString();
3545
+ return client.request(
3546
+ `${base}/contents${query ? `?${query}` : ""}`
3547
+ );
3548
+ },
3549
+ createFolder: async (folderPath) => {
3550
+ return client.request(
3551
+ `${base}/folders`,
3552
+ { method: "POST", body: { folderPath } }
3553
+ );
3554
+ },
3555
+ deleteFolder: async (folderPath) => {
3556
+ return client.request(
3557
+ `${base}/folders`,
3558
+ { method: "DELETE", body: { folderPath } }
3559
+ );
3560
+ },
3561
+ upload: async (params) => {
3562
+ const formData = new FormData();
3563
+ const blob = normalizeUploadFile2(params.file, params.contentType);
3564
+ const fileName = params.fileName ?? "upload";
3565
+ formData.set("file", blob, fileName);
3566
+ formData.set("objectPath", params.objectPath);
3567
+ if (params.cacheControl) {
3568
+ formData.set("cacheControl", params.cacheControl);
3569
+ }
3570
+ return client.request(`${base}/upload`, {
3571
+ method: "POST",
3572
+ body: formData
3573
+ });
3574
+ },
3575
+ delete: async (objectPath) => {
3576
+ return client.request(
3577
+ `${base}/objects`,
3578
+ { method: "DELETE", body: { objectPath } }
3579
+ );
3580
+ },
3581
+ bulkDelete: async (objectPaths) => {
3582
+ return client.request(
3583
+ `${base}/objects/delete-bulk`,
3584
+ { method: "POST", body: { objectPaths } }
3585
+ );
3586
+ },
3587
+ getMetadata: async (objectPath) => {
3588
+ const qs = new URLSearchParams({ objectPath });
3589
+ return client.request(
3590
+ `${base}/objects/metadata?${qs}`
3591
+ );
3592
+ },
3593
+ updateMetadata: async (params) => {
3594
+ return client.request(
3595
+ `${base}/objects/metadata`,
3596
+ { method: "PATCH", body: params }
3597
+ );
3598
+ },
3599
+ download: async (params) => {
3600
+ const qs = new URLSearchParams({ objectPath: params.objectPath });
3601
+ if (params.asText != null) qs.set("asText", String(params.asText));
3602
+ if (params.maxTextBytes != null)
3603
+ qs.set("maxTextBytes", String(params.maxTextBytes));
3604
+ return client.request(
3605
+ `${base}/objects/download?${qs}`
3606
+ );
3607
+ },
3608
+ copy: async (params) => {
3609
+ return client.request(`${base}/objects/copy`, { method: "POST", body: params });
3610
+ },
3611
+ move: async (params) => {
3612
+ return client.request(`${base}/objects/move`, { method: "POST", body: params });
3613
+ },
3614
+ getSignedUploadUrl: async (params) => {
3615
+ return client.request(
3616
+ `${base}/signed-upload-url`,
3617
+ { method: "POST", body: params }
3618
+ );
3619
+ },
3620
+ getSignedDownloadUrl: async (params) => {
3621
+ const qs = new URLSearchParams({ objectPath: params.objectPath });
3622
+ if (params.expiresInSeconds != null)
3623
+ qs.set("expiresInSeconds", String(params.expiresInSeconds));
3624
+ return client.request(
3625
+ `${base}/signed-download-url?${qs}`
3626
+ );
3627
+ },
3628
+ getSettings: async () => {
3629
+ return client.request(`${base}/settings`);
3630
+ },
3631
+ updateSettings: async (params) => {
3632
+ return client.request(`${base}/settings`, {
3633
+ method: "PATCH",
3634
+ body: params
3635
+ });
3636
+ }
3637
+ };
3638
+ }
3639
+ };
3640
+
3487
3641
  // src/index.ts
3488
3642
  var Ragable = class {
3489
3643
  constructor(options) {
3490
3644
  __publicField(this, "shift");
3491
3645
  __publicField(this, "agents");
3646
+ __publicField(this, "storage");
3492
3647
  __publicField(this, "infrastructure");
3493
3648
  const client = new RagableRequestClient(options);
3494
3649
  this.shift = new ShiftClient(client);
3495
3650
  this.agents = new AgentsClient(client);
3651
+ this.storage = new StorageClient(client);
3496
3652
  this.infrastructure = {
3497
3653
  shift: this.shift
3498
3654
  };
@@ -3555,6 +3711,7 @@ export {
3555
3711
  RagableTimeoutError,
3556
3712
  SessionStorageAdapter,
3557
3713
  ShiftClient,
3714
+ StorageClient,
3558
3715
  Transport,
3559
3716
  asPostgrestResponse,
3560
3717
  assertPostgrestSuccess,