@ragable/sdk 0.7.5 → 0.7.6

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
@@ -3202,6 +3202,113 @@ async function subscribeBrowserRealtime(options, ragableAuth, fetchImpl, params)
3202
3202
  })();
3203
3203
  return subscription;
3204
3204
  }
3205
+ var BrowserStorageBucketClient = class {
3206
+ constructor(options, fetchImpl, bucketId) {
3207
+ this.options = options;
3208
+ this.fetchImpl = fetchImpl;
3209
+ this.bucketId = bucketId;
3210
+ }
3211
+ get authGroupId() {
3212
+ const id = this.options.authGroupId?.trim();
3213
+ if (!id) throw new RagableError("authGroupId is required for storage", 400, { code: "SDK_MISSING_AUTH_GROUP_ID" });
3214
+ return id;
3215
+ }
3216
+ base() {
3217
+ return `${normalizeBrowserApiBase()}/auth-groups/${this.authGroupId}/storage/buckets/${encodeURIComponent(this.bucketId)}`;
3218
+ }
3219
+ async bearerToken() {
3220
+ const staticKey = this.options.dataStaticKey?.trim() || (this.options.getDataStaticKey ? await this.options.getDataStaticKey() : null)?.trim() || null;
3221
+ if (staticKey) return staticKey;
3222
+ if (this.options.getAccessToken) {
3223
+ const tok = await this.options.getAccessToken();
3224
+ if (tok?.trim()) return tok.trim();
3225
+ }
3226
+ throw new RagableError("No auth token for storage. Provide dataStaticKey or getAccessToken.", 401, { code: "SDK_NO_ACCESS_TOKEN" });
3227
+ }
3228
+ async req(method, path, body) {
3229
+ const token = await this.bearerToken();
3230
+ const headers = new Headers(this.options.headers);
3231
+ headers.set("Authorization", `Bearer ${token}`);
3232
+ if (body !== void 0 && !(body instanceof FormData)) headers.set("Content-Type", "application/json");
3233
+ const res = await this.fetchImpl(`${this.base()}${path}`, {
3234
+ method,
3235
+ headers,
3236
+ body: body instanceof FormData ? body : body !== void 0 ? JSON.stringify(body) : void 0
3237
+ });
3238
+ const payload = await res.json().catch(() => ({}));
3239
+ if (!res.ok) throw new RagableError(payload?.error ?? res.statusText, res.status, payload);
3240
+ return payload;
3241
+ }
3242
+ list(params = {}) {
3243
+ const qs = new URLSearchParams();
3244
+ if (params.prefix) qs.set("prefix", params.prefix);
3245
+ if (params.delimiter) qs.set("delimiter", params.delimiter);
3246
+ if (params.maxResults != null) qs.set("maxResults", String(params.maxResults));
3247
+ if (params.pageToken) qs.set("pageToken", params.pageToken);
3248
+ const q = qs.toString();
3249
+ return this.req("GET", `/contents${q ? `?${q}` : ""}`);
3250
+ }
3251
+ async upload(params) {
3252
+ const token = await this.bearerToken();
3253
+ const headers = new Headers(this.options.headers);
3254
+ headers.set("Authorization", `Bearer ${token}`);
3255
+ const form = new FormData();
3256
+ const raw = params.file instanceof Blob ? params.file : new Blob([new Uint8Array(params.file instanceof ArrayBuffer ? params.file : params.file.buffer)], params.contentType ? { type: params.contentType } : {});
3257
+ const blob = raw;
3258
+ form.set("file", blob, params.fileName ?? "upload");
3259
+ form.set("objectPath", params.objectPath);
3260
+ if (params.cacheControl) form.set("cacheControl", params.cacheControl);
3261
+ const res = await this.fetchImpl(`${this.base()}/upload`, { method: "POST", headers, body: form });
3262
+ const payload = await res.json().catch(() => ({}));
3263
+ if (!res.ok) throw new RagableError(payload?.error ?? res.statusText, res.status, payload);
3264
+ return payload;
3265
+ }
3266
+ download(params) {
3267
+ const qs = new URLSearchParams({ objectPath: params.objectPath });
3268
+ if (params.asText != null) qs.set("asText", String(params.asText));
3269
+ if (params.maxTextBytes != null) qs.set("maxTextBytes", String(params.maxTextBytes));
3270
+ return this.req("GET", `/objects/download?${qs}`);
3271
+ }
3272
+ delete(objectPath) {
3273
+ return this.req("DELETE", "/objects", { objectPath });
3274
+ }
3275
+ bulkDelete(objectPaths) {
3276
+ return this.req("POST", "/objects/delete-bulk", { objectPaths });
3277
+ }
3278
+ getSignedUploadUrl(params) {
3279
+ return this.req("POST", "/signed-upload-url", params);
3280
+ }
3281
+ getSignedDownloadUrl(params) {
3282
+ const qs = new URLSearchParams({ objectPath: params.objectPath });
3283
+ if (params.expiresInSeconds != null) qs.set("expiresInSeconds", String(params.expiresInSeconds));
3284
+ return this.req("GET", `/signed-download-url?${qs}`);
3285
+ }
3286
+ copy(params) {
3287
+ return this.req("POST", "/objects/copy", params);
3288
+ }
3289
+ move(params) {
3290
+ return this.req("POST", "/objects/move", params);
3291
+ }
3292
+ createFolder(folderPath) {
3293
+ return this.req("POST", "/folders", { folderPath });
3294
+ }
3295
+ deleteFolder(folderPath) {
3296
+ return this.req("DELETE", "/folders", { folderPath });
3297
+ }
3298
+ getMetadata(objectPath) {
3299
+ const qs = new URLSearchParams({ objectPath });
3300
+ return this.req("GET", `/objects/metadata?${qs}`);
3301
+ }
3302
+ };
3303
+ var RagableBrowserStorageClient = class {
3304
+ constructor(options, fetchImpl) {
3305
+ this.options = options;
3306
+ this.fetchImpl = fetchImpl;
3307
+ }
3308
+ from(bucketId) {
3309
+ return new BrowserStorageBucketClient(this.options, this.fetchImpl, bucketId);
3310
+ }
3311
+ };
3205
3312
  var RagableBrowserAgentsClient = class {
3206
3313
  constructor(options) {
3207
3314
  this.options = options;
@@ -3395,6 +3502,7 @@ var RagableBrowser = class {
3395
3502
  __publicField(this, "auth");
3396
3503
  __publicField(this, "database");
3397
3504
  __publicField(this, "db");
3505
+ __publicField(this, "storage");
3398
3506
  __publicField(this, "transport");
3399
3507
  __publicField(this, "_ragableAuth");
3400
3508
  /** Delegates to `database.from()`. Kept for back-compat — prefer `database.from()`. */
@@ -3432,6 +3540,7 @@ var RagableBrowser = class {
3432
3540
  );
3433
3541
  this.database._setTransport(this.transport);
3434
3542
  this.db = this.database;
3543
+ this.storage = new RagableBrowserStorageClient(options, bindFetch(options.fetch));
3435
3544
  }
3436
3545
  destroy() {
3437
3546
  this._ragableAuth?.destroy();