@ragable/sdk 0.5.0 → 0.5.1

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
@@ -72,6 +72,8 @@ type TableUpdatePatch<D extends RagableDatabase, T extends RagableTableNames<D>>
72
72
  * or the browser throws **Illegal invocation**. Use this for defaults and for `options.fetch`.
73
73
  */
74
74
  declare function bindFetch(custom?: typeof fetch): typeof fetch;
75
+ /** Default hosted API (`…/api`) when `baseUrl` is omitted (browser + server clients). */
76
+ declare const DEFAULT_RAGABLE_API_BASE = "https://ragable-341305259977.asia-southeast1.run.app/api";
75
77
  interface RagableClientOptions {
76
78
  apiKey: string;
77
79
  baseUrl?: string;
@@ -449,7 +451,13 @@ declare class PostgrestTableApi<Database extends RagableDatabase = DefaultRagabl
449
451
  upsert(values: TableInsertRow<Database, TableName> | TableInsertRow<Database, TableName>[], options: PostgrestUpsertOptions): PostgrestUpsertRootBuilder<TableRow<Database, TableName>>;
450
452
  }
451
453
 
454
+ /**
455
+ * Ensures the browser SDK hits `/api/...` routes. Accepts either `https://host` or `https://host/api`
456
+ * (same rule as two-arg `createClient(url, opts)` from the package entry).
457
+ */
452
458
  declare function normalizeBrowserApiBase(baseUrl?: string): string;
459
+ /** How {@link RagableBrowserDatabaseClient.query} and `.from()` send `Authorization`. */
460
+ type BrowserDataAuthMode = "user" | "publicAnon" | "admin";
453
461
  interface RagableBrowserClientOptions {
454
462
  /** Organization id (UUID) — public agent chat URLs. */
455
463
  organizationId: string;
@@ -462,14 +470,27 @@ interface RagableBrowserClientOptions {
462
470
  * Default Backspace SQL instance id for {@link RagableBrowser.from} (Supabase-style table API).
463
471
  */
464
472
  databaseInstanceId?: string;
473
+ /**
474
+ * Database SQL auth. Default `user`: Bearer = JWT from {@link getAccessToken}.
475
+ * `publicAnon`: Bearer = public anon key (read-only SQL only). `admin`: Bearer = data admin key
476
+ * (same SQL rules as a logged-in user; **never** expose in browser bundles).
477
+ */
478
+ dataAuth?: BrowserDataAuthMode;
479
+ /**
480
+ * Static key when {@link dataAuth} is `publicAnon` or `admin` (e.g. `import.meta.env.VITE_…`).
481
+ * Ignored when {@link getDataStaticKey} returns a non-empty string.
482
+ */
483
+ dataStaticKey?: string;
484
+ /** Load anon/admin key at runtime; wins over {@link dataStaticKey} when non-empty. */
485
+ getDataStaticKey?: () => string | null | Promise<string | null>;
465
486
  /**
466
487
  * Returns the end-user access JWT (from login/register/refresh).
467
- * Required for `auth.getMe`, `auth.updateMe`, and `database.query`.
488
+ * Required for `auth.getMe`, `auth.updateMe`, and for `database.query` when {@link dataAuth} is `user` (default).
468
489
  */
469
490
  getAccessToken?: () => string | null | Promise<string | null>;
470
491
  /**
471
492
  * API base URL including `/api`, e.g. `https://api.example.com/api`.
472
- * @default "http://localhost:8080/api"
493
+ * @default `https://ragable-341305259977.asia-southeast1.run.app/api` ({@link DEFAULT_RAGABLE_API_BASE})
473
494
  */
474
495
  baseUrl?: string;
475
496
  fetch?: typeof fetch;
@@ -739,4 +760,4 @@ declare function createClient<Database extends RagableDatabase = DefaultRagableD
739
760
  */
740
761
  declare function createRagableServerClient(options: RagableClientOptions): Ragable;
741
762
 
742
- export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentPublicChatParams, type AgentStreamEvent, type AgentSummary, AgentsClient, type BrowserAuthSession, type BrowserAuthTokens, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, type DefaultRagableDatabase, type FormatContextOptions, type Json, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, type RagClientForPipeline, type RagPipeline, type RagPipelineOptions, Ragable, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, type RagableClientOptions, type RagableDatabase, RagableError, RagableRequestClient, type RagableTableDefinition, type RagableTableNames, type RequestOptions, type RetrieveParams, type RunQuery, type ShiftAddDocumentParams, ShiftClient, type ShiftCreateIndexParams, type ShiftEntry, type ShiftIndex, type ShiftIngestResponse, type ShiftListEntriesParams, type ShiftListEntriesResponse, type ShiftSearchParams, type ShiftSearchResult, type ShiftUpdateIndexParams, type ShiftUploadFileParams, type ShiftUploadableFile, type SseJsonEvent, type SupabaseCompatSession, type TableInsertRow, type TableRow, type TableUpdatePatch, type Tables, type TablesInsert, type TablesUpdate, asPostgrestResponse, bindFetch, createBrowserClient, createClient, createRagPipeline, createRagableBrowserClient, createRagableServerClient, extractErrorMessage, formatRetrievalContext, normalizeBrowserApiBase, parseSseDataLine, readSseStream };
763
+ export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentPublicChatParams, type AgentStreamEvent, type AgentSummary, AgentsClient, type BrowserAuthSession, type BrowserAuthTokens, type BrowserDataAuthMode, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, DEFAULT_RAGABLE_API_BASE, type DefaultRagableDatabase, type FormatContextOptions, type Json, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, type RagClientForPipeline, type RagPipeline, type RagPipelineOptions, Ragable, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, type RagableClientOptions, type RagableDatabase, RagableError, RagableRequestClient, type RagableTableDefinition, type RagableTableNames, type RequestOptions, type RetrieveParams, type RunQuery, type ShiftAddDocumentParams, ShiftClient, type ShiftCreateIndexParams, type ShiftEntry, type ShiftIndex, type ShiftIngestResponse, type ShiftListEntriesParams, type ShiftListEntriesResponse, type ShiftSearchParams, type ShiftSearchResult, type ShiftUpdateIndexParams, type ShiftUploadFileParams, type ShiftUploadableFile, type SseJsonEvent, type SupabaseCompatSession, type TableInsertRow, type TableRow, type TableUpdatePatch, type Tables, type TablesInsert, type TablesUpdate, asPostgrestResponse, bindFetch, createBrowserClient, createClient, createRagPipeline, createRagableBrowserClient, createRagableServerClient, extractErrorMessage, formatRetrievalContext, normalizeBrowserApiBase, parseSseDataLine, readSseStream };
package/dist/index.d.ts CHANGED
@@ -72,6 +72,8 @@ type TableUpdatePatch<D extends RagableDatabase, T extends RagableTableNames<D>>
72
72
  * or the browser throws **Illegal invocation**. Use this for defaults and for `options.fetch`.
73
73
  */
74
74
  declare function bindFetch(custom?: typeof fetch): typeof fetch;
75
+ /** Default hosted API (`…/api`) when `baseUrl` is omitted (browser + server clients). */
76
+ declare const DEFAULT_RAGABLE_API_BASE = "https://ragable-341305259977.asia-southeast1.run.app/api";
75
77
  interface RagableClientOptions {
76
78
  apiKey: string;
77
79
  baseUrl?: string;
@@ -449,7 +451,13 @@ declare class PostgrestTableApi<Database extends RagableDatabase = DefaultRagabl
449
451
  upsert(values: TableInsertRow<Database, TableName> | TableInsertRow<Database, TableName>[], options: PostgrestUpsertOptions): PostgrestUpsertRootBuilder<TableRow<Database, TableName>>;
450
452
  }
451
453
 
454
+ /**
455
+ * Ensures the browser SDK hits `/api/...` routes. Accepts either `https://host` or `https://host/api`
456
+ * (same rule as two-arg `createClient(url, opts)` from the package entry).
457
+ */
452
458
  declare function normalizeBrowserApiBase(baseUrl?: string): string;
459
+ /** How {@link RagableBrowserDatabaseClient.query} and `.from()` send `Authorization`. */
460
+ type BrowserDataAuthMode = "user" | "publicAnon" | "admin";
453
461
  interface RagableBrowserClientOptions {
454
462
  /** Organization id (UUID) — public agent chat URLs. */
455
463
  organizationId: string;
@@ -462,14 +470,27 @@ interface RagableBrowserClientOptions {
462
470
  * Default Backspace SQL instance id for {@link RagableBrowser.from} (Supabase-style table API).
463
471
  */
464
472
  databaseInstanceId?: string;
473
+ /**
474
+ * Database SQL auth. Default `user`: Bearer = JWT from {@link getAccessToken}.
475
+ * `publicAnon`: Bearer = public anon key (read-only SQL only). `admin`: Bearer = data admin key
476
+ * (same SQL rules as a logged-in user; **never** expose in browser bundles).
477
+ */
478
+ dataAuth?: BrowserDataAuthMode;
479
+ /**
480
+ * Static key when {@link dataAuth} is `publicAnon` or `admin` (e.g. `import.meta.env.VITE_…`).
481
+ * Ignored when {@link getDataStaticKey} returns a non-empty string.
482
+ */
483
+ dataStaticKey?: string;
484
+ /** Load anon/admin key at runtime; wins over {@link dataStaticKey} when non-empty. */
485
+ getDataStaticKey?: () => string | null | Promise<string | null>;
465
486
  /**
466
487
  * Returns the end-user access JWT (from login/register/refresh).
467
- * Required for `auth.getMe`, `auth.updateMe`, and `database.query`.
488
+ * Required for `auth.getMe`, `auth.updateMe`, and for `database.query` when {@link dataAuth} is `user` (default).
468
489
  */
469
490
  getAccessToken?: () => string | null | Promise<string | null>;
470
491
  /**
471
492
  * API base URL including `/api`, e.g. `https://api.example.com/api`.
472
- * @default "http://localhost:8080/api"
493
+ * @default `https://ragable-341305259977.asia-southeast1.run.app/api` ({@link DEFAULT_RAGABLE_API_BASE})
473
494
  */
474
495
  baseUrl?: string;
475
496
  fetch?: typeof fetch;
@@ -739,4 +760,4 @@ declare function createClient<Database extends RagableDatabase = DefaultRagableD
739
760
  */
740
761
  declare function createRagableServerClient(options: RagableClientOptions): Ragable;
741
762
 
742
- export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentPublicChatParams, type AgentStreamEvent, type AgentSummary, AgentsClient, type BrowserAuthSession, type BrowserAuthTokens, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, type DefaultRagableDatabase, type FormatContextOptions, type Json, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, type RagClientForPipeline, type RagPipeline, type RagPipelineOptions, Ragable, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, type RagableClientOptions, type RagableDatabase, RagableError, RagableRequestClient, type RagableTableDefinition, type RagableTableNames, type RequestOptions, type RetrieveParams, type RunQuery, type ShiftAddDocumentParams, ShiftClient, type ShiftCreateIndexParams, type ShiftEntry, type ShiftIndex, type ShiftIngestResponse, type ShiftListEntriesParams, type ShiftListEntriesResponse, type ShiftSearchParams, type ShiftSearchResult, type ShiftUpdateIndexParams, type ShiftUploadFileParams, type ShiftUploadableFile, type SseJsonEvent, type SupabaseCompatSession, type TableInsertRow, type TableRow, type TableUpdatePatch, type Tables, type TablesInsert, type TablesUpdate, asPostgrestResponse, bindFetch, createBrowserClient, createClient, createRagPipeline, createRagableBrowserClient, createRagableServerClient, extractErrorMessage, formatRetrievalContext, normalizeBrowserApiBase, parseSseDataLine, readSseStream };
763
+ export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentPublicChatParams, type AgentStreamEvent, type AgentSummary, AgentsClient, type BrowserAuthSession, type BrowserAuthTokens, type BrowserDataAuthMode, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, DEFAULT_RAGABLE_API_BASE, type DefaultRagableDatabase, type FormatContextOptions, type Json, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, type RagClientForPipeline, type RagPipeline, type RagPipelineOptions, Ragable, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, type RagableClientOptions, type RagableDatabase, RagableError, RagableRequestClient, type RagableTableDefinition, type RagableTableNames, type RequestOptions, type RetrieveParams, type RunQuery, type ShiftAddDocumentParams, ShiftClient, type ShiftCreateIndexParams, type ShiftEntry, type ShiftIndex, type ShiftIngestResponse, type ShiftListEntriesParams, type ShiftListEntriesResponse, type ShiftSearchParams, type ShiftSearchResult, type ShiftUpdateIndexParams, type ShiftUploadFileParams, type ShiftUploadableFile, type SseJsonEvent, type SupabaseCompatSession, type TableInsertRow, type TableRow, type TableUpdatePatch, type Tables, type TablesInsert, type TablesUpdate, asPostgrestResponse, bindFetch, createBrowserClient, createClient, createRagPipeline, createRagableBrowserClient, createRagableServerClient, extractErrorMessage, formatRetrievalContext, normalizeBrowserApiBase, parseSseDataLine, readSseStream };
package/dist/index.js CHANGED
@@ -23,6 +23,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
23
23
  var index_exports = {};
24
24
  __export(index_exports, {
25
25
  AgentsClient: () => AgentsClient,
26
+ DEFAULT_RAGABLE_API_BASE: () => DEFAULT_RAGABLE_API_BASE,
26
27
  PostgrestDeleteReturningBuilder: () => PostgrestDeleteReturningBuilder,
27
28
  PostgrestDeleteRootBuilder: () => PostgrestDeleteRootBuilder,
28
29
  PostgrestInsertReturningBuilder: () => PostgrestInsertReturningBuilder,
@@ -63,6 +64,7 @@ function bindFetch(custom) {
63
64
  return f.call(globalThis, input, init);
64
65
  };
65
66
  }
67
+ var DEFAULT_RAGABLE_API_BASE = "https://ragable-341305259977.asia-southeast1.run.app/api";
66
68
  var RagableError = class extends Error {
67
69
  constructor(message, status, body) {
68
70
  super(message);
@@ -94,7 +96,7 @@ var RagableRequestClient = class {
94
96
  __publicField(this, "fetchImpl");
95
97
  __publicField(this, "defaultHeaders");
96
98
  this.apiKey = options.apiKey;
97
- this.baseUrl = options.baseUrl ?? "http://localhost:8080/api";
99
+ this.baseUrl = options.baseUrl ?? DEFAULT_RAGABLE_API_BASE;
98
100
  this.fetchImpl = bindFetch(options.fetch);
99
101
  this.defaultHeaders = options.headers;
100
102
  }
@@ -1161,7 +1163,8 @@ var PostgrestTableApi = class {
1161
1163
 
1162
1164
  // src/browser.ts
1163
1165
  function normalizeBrowserApiBase(baseUrl) {
1164
- return (baseUrl ?? "http://localhost:8080/api").replace(/\/+$/, "");
1166
+ const trimmed = (baseUrl ?? DEFAULT_RAGABLE_API_BASE).trim().replace(/\/+$/, "");
1167
+ return trimmed.endsWith("/api") ? trimmed : `${trimmed}/api`;
1165
1168
  }
1166
1169
  function requireAuthGroupId(options) {
1167
1170
  const id = options.authGroupId?.trim();
@@ -1185,6 +1188,20 @@ async function requireAccessToken(options) {
1185
1188
  }
1186
1189
  return token.trim();
1187
1190
  }
1191
+ async function resolveDatabaseAuthBearer(options) {
1192
+ const mode = options.dataAuth ?? "user";
1193
+ if (mode === "user") {
1194
+ return requireAccessToken(options);
1195
+ }
1196
+ const fromGetter = options.getDataStaticKey ? await options.getDataStaticKey() : null;
1197
+ const key = (fromGetter?.trim() || options.dataStaticKey?.trim()) ?? "";
1198
+ if (!key) {
1199
+ throw new Error(
1200
+ mode === "publicAnon" ? "dataAuth publicAnon requires getDataStaticKey or dataStaticKey (rotate key in dashboard)" : "dataAuth admin requires getDataStaticKey or dataStaticKey (server-side only; rotate in dashboard)"
1201
+ );
1202
+ }
1203
+ return key;
1204
+ }
1188
1205
  async function parseJsonOrThrow(response) {
1189
1206
  const payload = await parseMaybeJsonBody(response);
1190
1207
  if (!response.ok) {
@@ -1354,7 +1371,7 @@ var RagableBrowserDatabaseClient = class {
1354
1371
  }
1355
1372
  async query(params) {
1356
1373
  const gid = requireAuthGroupId(this.options);
1357
- const token = await requireAccessToken(this.options);
1374
+ const token = await resolveDatabaseAuthBearer(this.options);
1358
1375
  const databaseInstanceId = params.databaseInstanceId?.trim() || this.options.databaseInstanceId?.trim();
1359
1376
  if (!databaseInstanceId) {
1360
1377
  throw new Error(
@@ -1364,6 +1381,7 @@ var RagableBrowserDatabaseClient = class {
1364
1381
  const headers = this.baseHeaders();
1365
1382
  headers.set("Authorization", `Bearer ${token}`);
1366
1383
  headers.set("Content-Type", "application/json");
1384
+ const readOnly = (this.options.dataAuth ?? "user") === "publicAnon" ? true : params.readOnly !== false;
1367
1385
  const response = await this.fetchImpl(
1368
1386
  this.toUrl(`/auth-groups/${gid}/data/query`),
1369
1387
  {
@@ -1373,7 +1391,7 @@ var RagableBrowserDatabaseClient = class {
1373
1391
  databaseInstanceId,
1374
1392
  sql: params.sql,
1375
1393
  ...params.params !== void 0 ? { params: params.params } : {},
1376
- ...params.readOnly === false ? { readOnly: false } : {},
1394
+ readOnly,
1377
1395
  ...params.timeoutMs !== void 0 ? { timeoutMs: params.timeoutMs } : {},
1378
1396
  ...params.rowLimit !== void 0 ? { rowLimit: params.rowLimit } : {}
1379
1397
  })
@@ -1549,6 +1567,7 @@ function createRagableServerClient(options) {
1549
1567
  // Annotate the CommonJS export names for ESM import in node:
1550
1568
  0 && (module.exports = {
1551
1569
  AgentsClient,
1570
+ DEFAULT_RAGABLE_API_BASE,
1552
1571
  PostgrestDeleteReturningBuilder,
1553
1572
  PostgrestDeleteRootBuilder,
1554
1573
  PostgrestInsertReturningBuilder,