@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.js CHANGED
@@ -54,6 +54,7 @@ __export(index_exports, {
54
54
  RagableTimeoutError: () => RagableTimeoutError,
55
55
  SessionStorageAdapter: () => SessionStorageAdapter,
56
56
  ShiftClient: () => ShiftClient,
57
+ StorageClient: () => StorageClient,
57
58
  Transport: () => Transport,
58
59
  asPostgrestResponse: () => asPostgrestResponse,
59
60
  assertPostgrestSuccess: () => assertPostgrestSuccess,
@@ -3572,15 +3573,171 @@ function createRagPipeline(client, options) {
3572
3573
  };
3573
3574
  }
3574
3575
 
3576
+ // src/storage.ts
3577
+ function normalizeUploadFile2(file, contentType) {
3578
+ if (file instanceof Blob) return file;
3579
+ const u8 = file instanceof ArrayBuffer ? new Uint8Array(file) : new Uint8Array(file);
3580
+ return new Blob([u8.buffer], contentType ? { type: contentType } : {});
3581
+ }
3582
+ var StorageClient = class {
3583
+ constructor(client) {
3584
+ this.client = client;
3585
+ /**
3586
+ * Bucket-level CRUD — list, create and delete buckets for this organisation.
3587
+ */
3588
+ __publicField(this, "buckets");
3589
+ this.buckets = {
3590
+ list: async (params) => {
3591
+ const qs = new URLSearchParams();
3592
+ if (params?.q) qs.set("q", params.q);
3593
+ if (params?.status) qs.set("status", params.status);
3594
+ if (params?.sort) qs.set("sort", params.sort);
3595
+ const query = qs.toString();
3596
+ return this.client.request(
3597
+ `/v1/storage/buckets${query ? `?${query}` : ""}`
3598
+ );
3599
+ },
3600
+ create: async (name) => {
3601
+ return this.client.request("/v1/storage/buckets", {
3602
+ method: "POST",
3603
+ body: { name }
3604
+ });
3605
+ },
3606
+ delete: async (bucketId) => {
3607
+ return this.client.request(
3608
+ `/v1/storage/buckets/${encodeURIComponent(bucketId)}`,
3609
+ { method: "DELETE" }
3610
+ );
3611
+ }
3612
+ };
3613
+ }
3614
+ /**
3615
+ * Returns a {@link StorageBucketClient} scoped to the given bucket ID.
3616
+ *
3617
+ * All object operations (upload, download, list, copy, move, signed URLs, …)
3618
+ * are performed through the returned client.
3619
+ *
3620
+ * @param bucketId The Ragable bucket ID obtained from `buckets.list()` or `buckets.create()`.
3621
+ */
3622
+ from(bucketId) {
3623
+ const { client } = this;
3624
+ const base = `/v1/storage/buckets/${encodeURIComponent(bucketId)}`;
3625
+ return {
3626
+ list: async (params) => {
3627
+ const qs = new URLSearchParams();
3628
+ if (params?.prefix) qs.set("prefix", params.prefix);
3629
+ if (params?.delimiter) qs.set("delimiter", params.delimiter);
3630
+ if (params?.maxResults != null)
3631
+ qs.set("maxResults", String(params.maxResults));
3632
+ if (params?.pageToken) qs.set("pageToken", params.pageToken);
3633
+ const query = qs.toString();
3634
+ return client.request(
3635
+ `${base}/contents${query ? `?${query}` : ""}`
3636
+ );
3637
+ },
3638
+ createFolder: async (folderPath) => {
3639
+ return client.request(
3640
+ `${base}/folders`,
3641
+ { method: "POST", body: { folderPath } }
3642
+ );
3643
+ },
3644
+ deleteFolder: async (folderPath) => {
3645
+ return client.request(
3646
+ `${base}/folders`,
3647
+ { method: "DELETE", body: { folderPath } }
3648
+ );
3649
+ },
3650
+ upload: async (params) => {
3651
+ const formData = new FormData();
3652
+ const blob = normalizeUploadFile2(params.file, params.contentType);
3653
+ const fileName = params.fileName ?? "upload";
3654
+ formData.set("file", blob, fileName);
3655
+ formData.set("objectPath", params.objectPath);
3656
+ if (params.cacheControl) {
3657
+ formData.set("cacheControl", params.cacheControl);
3658
+ }
3659
+ return client.request(`${base}/upload`, {
3660
+ method: "POST",
3661
+ body: formData
3662
+ });
3663
+ },
3664
+ delete: async (objectPath) => {
3665
+ return client.request(
3666
+ `${base}/objects`,
3667
+ { method: "DELETE", body: { objectPath } }
3668
+ );
3669
+ },
3670
+ bulkDelete: async (objectPaths) => {
3671
+ return client.request(
3672
+ `${base}/objects/delete-bulk`,
3673
+ { method: "POST", body: { objectPaths } }
3674
+ );
3675
+ },
3676
+ getMetadata: async (objectPath) => {
3677
+ const qs = new URLSearchParams({ objectPath });
3678
+ return client.request(
3679
+ `${base}/objects/metadata?${qs}`
3680
+ );
3681
+ },
3682
+ updateMetadata: async (params) => {
3683
+ return client.request(
3684
+ `${base}/objects/metadata`,
3685
+ { method: "PATCH", body: params }
3686
+ );
3687
+ },
3688
+ download: async (params) => {
3689
+ const qs = new URLSearchParams({ objectPath: params.objectPath });
3690
+ if (params.asText != null) qs.set("asText", String(params.asText));
3691
+ if (params.maxTextBytes != null)
3692
+ qs.set("maxTextBytes", String(params.maxTextBytes));
3693
+ return client.request(
3694
+ `${base}/objects/download?${qs}`
3695
+ );
3696
+ },
3697
+ copy: async (params) => {
3698
+ return client.request(`${base}/objects/copy`, { method: "POST", body: params });
3699
+ },
3700
+ move: async (params) => {
3701
+ return client.request(`${base}/objects/move`, { method: "POST", body: params });
3702
+ },
3703
+ getSignedUploadUrl: async (params) => {
3704
+ return client.request(
3705
+ `${base}/signed-upload-url`,
3706
+ { method: "POST", body: params }
3707
+ );
3708
+ },
3709
+ getSignedDownloadUrl: async (params) => {
3710
+ const qs = new URLSearchParams({ objectPath: params.objectPath });
3711
+ if (params.expiresInSeconds != null)
3712
+ qs.set("expiresInSeconds", String(params.expiresInSeconds));
3713
+ return client.request(
3714
+ `${base}/signed-download-url?${qs}`
3715
+ );
3716
+ },
3717
+ getSettings: async () => {
3718
+ return client.request(`${base}/settings`);
3719
+ },
3720
+ updateSettings: async (params) => {
3721
+ return client.request(`${base}/settings`, {
3722
+ method: "PATCH",
3723
+ body: params
3724
+ });
3725
+ }
3726
+ };
3727
+ }
3728
+ };
3729
+
3575
3730
  // src/index.ts
3576
3731
  var Ragable = class {
3577
3732
  constructor(options) {
3578
3733
  __publicField(this, "shift");
3579
3734
  __publicField(this, "agents");
3735
+ __publicField(this, "storage");
3580
3736
  __publicField(this, "infrastructure");
3581
3737
  const client = new RagableRequestClient(options);
3582
3738
  this.shift = new ShiftClient(client);
3583
3739
  this.agents = new AgentsClient(client);
3740
+ this.storage = new StorageClient(client);
3584
3741
  this.infrastructure = {
3585
3742
  shift: this.shift
3586
3743
  };
@@ -3644,6 +3801,7 @@ function createRagableServerClient(options) {
3644
3801
  RagableTimeoutError,
3645
3802
  SessionStorageAdapter,
3646
3803
  ShiftClient,
3804
+ StorageClient,
3647
3805
  Transport,
3648
3806
  asPostgrestResponse,
3649
3807
  assertPostgrestSuccess,