@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.d.mts CHANGED
@@ -1520,6 +1520,132 @@ interface BrowserRealtimeSubscription {
1520
1520
  unsubscribe: () => void;
1521
1521
  readonly status: BrowserRealtimeStatus;
1522
1522
  }
1523
+ interface BrowserStorageItem {
1524
+ type: "file" | "folder";
1525
+ path: string;
1526
+ name: string;
1527
+ size?: string | null;
1528
+ contentType?: string | null;
1529
+ updated?: string | null;
1530
+ }
1531
+ interface BrowserStorageListResult {
1532
+ bucket: string;
1533
+ prefix: string;
1534
+ items: BrowserStorageItem[];
1535
+ nextPageToken: string | null;
1536
+ }
1537
+ interface BrowserStorageUploadResult {
1538
+ success: true;
1539
+ path: string;
1540
+ size: string | null;
1541
+ contentType: string | null;
1542
+ updated: string | null;
1543
+ }
1544
+ interface BrowserStorageDownloadResult {
1545
+ path: string;
1546
+ size: string | null;
1547
+ contentType: string | null;
1548
+ updated: string | null;
1549
+ encoding: string;
1550
+ contentsBase64: string;
1551
+ text: string | null;
1552
+ textIncluded: boolean;
1553
+ }
1554
+ interface BrowserStorageSignedUrlResult {
1555
+ url: string;
1556
+ method: string;
1557
+ expiresInSeconds: number;
1558
+ objectPath: string;
1559
+ }
1560
+ interface BrowserStorageBulkDeleteResult {
1561
+ success: boolean;
1562
+ totalRequested: number;
1563
+ uniquePaths: number;
1564
+ deleted: string[];
1565
+ errors: Array<{
1566
+ path: string;
1567
+ error: string;
1568
+ }>;
1569
+ }
1570
+ declare class BrowserStorageBucketClient {
1571
+ private readonly options;
1572
+ private readonly fetchImpl;
1573
+ private readonly bucketId;
1574
+ constructor(options: RagableBrowserClientOptions, fetchImpl: typeof fetch, bucketId: string);
1575
+ private get authGroupId();
1576
+ private base;
1577
+ private bearerToken;
1578
+ private req;
1579
+ list(params?: {
1580
+ prefix?: string;
1581
+ delimiter?: string;
1582
+ maxResults?: number;
1583
+ pageToken?: string;
1584
+ }): Promise<BrowserStorageListResult>;
1585
+ upload(params: {
1586
+ objectPath: string;
1587
+ file: Blob | ArrayBuffer | Uint8Array;
1588
+ fileName?: string;
1589
+ contentType?: string;
1590
+ cacheControl?: string;
1591
+ }): Promise<BrowserStorageUploadResult>;
1592
+ download(params: {
1593
+ objectPath: string;
1594
+ asText?: boolean;
1595
+ maxTextBytes?: number;
1596
+ }): Promise<BrowserStorageDownloadResult>;
1597
+ delete(objectPath: string): Promise<{
1598
+ success: true;
1599
+ path: string;
1600
+ }>;
1601
+ bulkDelete(objectPaths: string[]): Promise<BrowserStorageBulkDeleteResult>;
1602
+ getSignedUploadUrl(params: {
1603
+ objectPath: string;
1604
+ contentType?: string;
1605
+ expiresInSeconds?: number;
1606
+ }): Promise<BrowserStorageSignedUrlResult>;
1607
+ getSignedDownloadUrl(params: {
1608
+ objectPath: string;
1609
+ expiresInSeconds?: number;
1610
+ }): Promise<BrowserStorageSignedUrlResult>;
1611
+ copy(params: {
1612
+ sourcePath: string;
1613
+ destinationPath: string;
1614
+ }): Promise<{
1615
+ success: true;
1616
+ sourcePath: string;
1617
+ destinationPath: string;
1618
+ }>;
1619
+ move(params: {
1620
+ sourcePath: string;
1621
+ destinationPath: string;
1622
+ }): Promise<{
1623
+ success: true;
1624
+ sourcePath: string;
1625
+ destinationPath: string;
1626
+ }>;
1627
+ createFolder(folderPath: string): Promise<{
1628
+ success: true;
1629
+ folderPath: string;
1630
+ }>;
1631
+ deleteFolder(folderPath: string): Promise<{
1632
+ success: true;
1633
+ folderPath: string;
1634
+ }>;
1635
+ getMetadata(objectPath: string): Promise<{
1636
+ name: string;
1637
+ contentType: string | null;
1638
+ size: string | null;
1639
+ updated: string | null;
1640
+ metadata?: Record<string, string>;
1641
+ }>;
1642
+ }
1643
+ declare class RagableBrowserStorageClient {
1644
+ private readonly options;
1645
+ private readonly fetchImpl;
1646
+ constructor(options: RagableBrowserClientOptions, fetchImpl: typeof fetch);
1647
+ from(bucketId: string): BrowserStorageBucketClient;
1648
+ }
1523
1649
  interface AgentConversationMessage {
1524
1650
  role: "user" | "assistant";
1525
1651
  content: string;
@@ -1588,6 +1714,7 @@ declare class RagableBrowser<Database extends RagableDatabase = DefaultRagableDa
1588
1714
  readonly auth: RagableBrowserAuthClient<AuthUser>;
1589
1715
  readonly database: RagableBrowserDatabaseClient<Database>;
1590
1716
  readonly db: RagableBrowserDatabaseClient<Database>;
1717
+ readonly storage: RagableBrowserStorageClient;
1591
1718
  readonly transport: Transport;
1592
1719
  private readonly _ragableAuth;
1593
1720
  constructor(options: RagableBrowserClientOptions);
package/dist/index.d.ts CHANGED
@@ -1520,6 +1520,132 @@ interface BrowserRealtimeSubscription {
1520
1520
  unsubscribe: () => void;
1521
1521
  readonly status: BrowserRealtimeStatus;
1522
1522
  }
1523
+ interface BrowserStorageItem {
1524
+ type: "file" | "folder";
1525
+ path: string;
1526
+ name: string;
1527
+ size?: string | null;
1528
+ contentType?: string | null;
1529
+ updated?: string | null;
1530
+ }
1531
+ interface BrowserStorageListResult {
1532
+ bucket: string;
1533
+ prefix: string;
1534
+ items: BrowserStorageItem[];
1535
+ nextPageToken: string | null;
1536
+ }
1537
+ interface BrowserStorageUploadResult {
1538
+ success: true;
1539
+ path: string;
1540
+ size: string | null;
1541
+ contentType: string | null;
1542
+ updated: string | null;
1543
+ }
1544
+ interface BrowserStorageDownloadResult {
1545
+ path: string;
1546
+ size: string | null;
1547
+ contentType: string | null;
1548
+ updated: string | null;
1549
+ encoding: string;
1550
+ contentsBase64: string;
1551
+ text: string | null;
1552
+ textIncluded: boolean;
1553
+ }
1554
+ interface BrowserStorageSignedUrlResult {
1555
+ url: string;
1556
+ method: string;
1557
+ expiresInSeconds: number;
1558
+ objectPath: string;
1559
+ }
1560
+ interface BrowserStorageBulkDeleteResult {
1561
+ success: boolean;
1562
+ totalRequested: number;
1563
+ uniquePaths: number;
1564
+ deleted: string[];
1565
+ errors: Array<{
1566
+ path: string;
1567
+ error: string;
1568
+ }>;
1569
+ }
1570
+ declare class BrowserStorageBucketClient {
1571
+ private readonly options;
1572
+ private readonly fetchImpl;
1573
+ private readonly bucketId;
1574
+ constructor(options: RagableBrowserClientOptions, fetchImpl: typeof fetch, bucketId: string);
1575
+ private get authGroupId();
1576
+ private base;
1577
+ private bearerToken;
1578
+ private req;
1579
+ list(params?: {
1580
+ prefix?: string;
1581
+ delimiter?: string;
1582
+ maxResults?: number;
1583
+ pageToken?: string;
1584
+ }): Promise<BrowserStorageListResult>;
1585
+ upload(params: {
1586
+ objectPath: string;
1587
+ file: Blob | ArrayBuffer | Uint8Array;
1588
+ fileName?: string;
1589
+ contentType?: string;
1590
+ cacheControl?: string;
1591
+ }): Promise<BrowserStorageUploadResult>;
1592
+ download(params: {
1593
+ objectPath: string;
1594
+ asText?: boolean;
1595
+ maxTextBytes?: number;
1596
+ }): Promise<BrowserStorageDownloadResult>;
1597
+ delete(objectPath: string): Promise<{
1598
+ success: true;
1599
+ path: string;
1600
+ }>;
1601
+ bulkDelete(objectPaths: string[]): Promise<BrowserStorageBulkDeleteResult>;
1602
+ getSignedUploadUrl(params: {
1603
+ objectPath: string;
1604
+ contentType?: string;
1605
+ expiresInSeconds?: number;
1606
+ }): Promise<BrowserStorageSignedUrlResult>;
1607
+ getSignedDownloadUrl(params: {
1608
+ objectPath: string;
1609
+ expiresInSeconds?: number;
1610
+ }): Promise<BrowserStorageSignedUrlResult>;
1611
+ copy(params: {
1612
+ sourcePath: string;
1613
+ destinationPath: string;
1614
+ }): Promise<{
1615
+ success: true;
1616
+ sourcePath: string;
1617
+ destinationPath: string;
1618
+ }>;
1619
+ move(params: {
1620
+ sourcePath: string;
1621
+ destinationPath: string;
1622
+ }): Promise<{
1623
+ success: true;
1624
+ sourcePath: string;
1625
+ destinationPath: string;
1626
+ }>;
1627
+ createFolder(folderPath: string): Promise<{
1628
+ success: true;
1629
+ folderPath: string;
1630
+ }>;
1631
+ deleteFolder(folderPath: string): Promise<{
1632
+ success: true;
1633
+ folderPath: string;
1634
+ }>;
1635
+ getMetadata(objectPath: string): Promise<{
1636
+ name: string;
1637
+ contentType: string | null;
1638
+ size: string | null;
1639
+ updated: string | null;
1640
+ metadata?: Record<string, string>;
1641
+ }>;
1642
+ }
1643
+ declare class RagableBrowserStorageClient {
1644
+ private readonly options;
1645
+ private readonly fetchImpl;
1646
+ constructor(options: RagableBrowserClientOptions, fetchImpl: typeof fetch);
1647
+ from(bucketId: string): BrowserStorageBucketClient;
1648
+ }
1523
1649
  interface AgentConversationMessage {
1524
1650
  role: "user" | "assistant";
1525
1651
  content: string;
@@ -1588,6 +1714,7 @@ declare class RagableBrowser<Database extends RagableDatabase = DefaultRagableDa
1588
1714
  readonly auth: RagableBrowserAuthClient<AuthUser>;
1589
1715
  readonly database: RagableBrowserDatabaseClient<Database>;
1590
1716
  readonly db: RagableBrowserDatabaseClient<Database>;
1717
+ readonly storage: RagableBrowserStorageClient;
1591
1718
  readonly transport: Transport;
1592
1719
  private readonly _ragableAuth;
1593
1720
  constructor(options: RagableBrowserClientOptions);
package/dist/index.js CHANGED
@@ -3291,6 +3291,113 @@ async function subscribeBrowserRealtime(options, ragableAuth, fetchImpl, params)
3291
3291
  })();
3292
3292
  return subscription;
3293
3293
  }
3294
+ var BrowserStorageBucketClient = class {
3295
+ constructor(options, fetchImpl, bucketId) {
3296
+ this.options = options;
3297
+ this.fetchImpl = fetchImpl;
3298
+ this.bucketId = bucketId;
3299
+ }
3300
+ get authGroupId() {
3301
+ const id = this.options.authGroupId?.trim();
3302
+ if (!id) throw new RagableError("authGroupId is required for storage", 400, { code: "SDK_MISSING_AUTH_GROUP_ID" });
3303
+ return id;
3304
+ }
3305
+ base() {
3306
+ return `${normalizeBrowserApiBase()}/auth-groups/${this.authGroupId}/storage/buckets/${encodeURIComponent(this.bucketId)}`;
3307
+ }
3308
+ async bearerToken() {
3309
+ const staticKey = this.options.dataStaticKey?.trim() || (this.options.getDataStaticKey ? await this.options.getDataStaticKey() : null)?.trim() || null;
3310
+ if (staticKey) return staticKey;
3311
+ if (this.options.getAccessToken) {
3312
+ const tok = await this.options.getAccessToken();
3313
+ if (tok?.trim()) return tok.trim();
3314
+ }
3315
+ throw new RagableError("No auth token for storage. Provide dataStaticKey or getAccessToken.", 401, { code: "SDK_NO_ACCESS_TOKEN" });
3316
+ }
3317
+ async req(method, path, body) {
3318
+ const token = await this.bearerToken();
3319
+ const headers = new Headers(this.options.headers);
3320
+ headers.set("Authorization", `Bearer ${token}`);
3321
+ if (body !== void 0 && !(body instanceof FormData)) headers.set("Content-Type", "application/json");
3322
+ const res = await this.fetchImpl(`${this.base()}${path}`, {
3323
+ method,
3324
+ headers,
3325
+ body: body instanceof FormData ? body : body !== void 0 ? JSON.stringify(body) : void 0
3326
+ });
3327
+ const payload = await res.json().catch(() => ({}));
3328
+ if (!res.ok) throw new RagableError(payload?.error ?? res.statusText, res.status, payload);
3329
+ return payload;
3330
+ }
3331
+ list(params = {}) {
3332
+ const qs = new URLSearchParams();
3333
+ if (params.prefix) qs.set("prefix", params.prefix);
3334
+ if (params.delimiter) qs.set("delimiter", params.delimiter);
3335
+ if (params.maxResults != null) qs.set("maxResults", String(params.maxResults));
3336
+ if (params.pageToken) qs.set("pageToken", params.pageToken);
3337
+ const q = qs.toString();
3338
+ return this.req("GET", `/contents${q ? `?${q}` : ""}`);
3339
+ }
3340
+ async upload(params) {
3341
+ const token = await this.bearerToken();
3342
+ const headers = new Headers(this.options.headers);
3343
+ headers.set("Authorization", `Bearer ${token}`);
3344
+ const form = new FormData();
3345
+ 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 } : {});
3346
+ const blob = raw;
3347
+ form.set("file", blob, params.fileName ?? "upload");
3348
+ form.set("objectPath", params.objectPath);
3349
+ if (params.cacheControl) form.set("cacheControl", params.cacheControl);
3350
+ const res = await this.fetchImpl(`${this.base()}/upload`, { method: "POST", headers, body: form });
3351
+ const payload = await res.json().catch(() => ({}));
3352
+ if (!res.ok) throw new RagableError(payload?.error ?? res.statusText, res.status, payload);
3353
+ return payload;
3354
+ }
3355
+ download(params) {
3356
+ const qs = new URLSearchParams({ objectPath: params.objectPath });
3357
+ if (params.asText != null) qs.set("asText", String(params.asText));
3358
+ if (params.maxTextBytes != null) qs.set("maxTextBytes", String(params.maxTextBytes));
3359
+ return this.req("GET", `/objects/download?${qs}`);
3360
+ }
3361
+ delete(objectPath) {
3362
+ return this.req("DELETE", "/objects", { objectPath });
3363
+ }
3364
+ bulkDelete(objectPaths) {
3365
+ return this.req("POST", "/objects/delete-bulk", { objectPaths });
3366
+ }
3367
+ getSignedUploadUrl(params) {
3368
+ return this.req("POST", "/signed-upload-url", params);
3369
+ }
3370
+ getSignedDownloadUrl(params) {
3371
+ const qs = new URLSearchParams({ objectPath: params.objectPath });
3372
+ if (params.expiresInSeconds != null) qs.set("expiresInSeconds", String(params.expiresInSeconds));
3373
+ return this.req("GET", `/signed-download-url?${qs}`);
3374
+ }
3375
+ copy(params) {
3376
+ return this.req("POST", "/objects/copy", params);
3377
+ }
3378
+ move(params) {
3379
+ return this.req("POST", "/objects/move", params);
3380
+ }
3381
+ createFolder(folderPath) {
3382
+ return this.req("POST", "/folders", { folderPath });
3383
+ }
3384
+ deleteFolder(folderPath) {
3385
+ return this.req("DELETE", "/folders", { folderPath });
3386
+ }
3387
+ getMetadata(objectPath) {
3388
+ const qs = new URLSearchParams({ objectPath });
3389
+ return this.req("GET", `/objects/metadata?${qs}`);
3390
+ }
3391
+ };
3392
+ var RagableBrowserStorageClient = class {
3393
+ constructor(options, fetchImpl) {
3394
+ this.options = options;
3395
+ this.fetchImpl = fetchImpl;
3396
+ }
3397
+ from(bucketId) {
3398
+ return new BrowserStorageBucketClient(this.options, this.fetchImpl, bucketId);
3399
+ }
3400
+ };
3294
3401
  var RagableBrowserAgentsClient = class {
3295
3402
  constructor(options) {
3296
3403
  this.options = options;
@@ -3484,6 +3591,7 @@ var RagableBrowser = class {
3484
3591
  __publicField(this, "auth");
3485
3592
  __publicField(this, "database");
3486
3593
  __publicField(this, "db");
3594
+ __publicField(this, "storage");
3487
3595
  __publicField(this, "transport");
3488
3596
  __publicField(this, "_ragableAuth");
3489
3597
  /** Delegates to `database.from()`. Kept for back-compat — prefer `database.from()`. */
@@ -3521,6 +3629,7 @@ var RagableBrowser = class {
3521
3629
  );
3522
3630
  this.database._setTransport(this.transport);
3523
3631
  this.db = this.database;
3632
+ this.storage = new RagableBrowserStorageClient(options, bindFetch(options.fetch));
3524
3633
  }
3525
3634
  destroy() {
3526
3635
  this._ragableAuth?.destroy();