@ragable/sdk 0.6.8 → 0.6.10
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 +14 -7
- package/dist/index.d.ts +14 -7
- package/dist/index.js +27 -33
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -33
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -1
package/dist/index.d.mts
CHANGED
|
@@ -76,11 +76,10 @@ type ColumnValue<D extends RagableDatabase, T extends RagableTableNames<D>, C ex
|
|
|
76
76
|
* or the browser throws **Illegal invocation**. Use this for defaults and for `options.fetch`.
|
|
77
77
|
*/
|
|
78
78
|
declare function bindFetch(custom?: typeof fetch): typeof fetch;
|
|
79
|
-
/**
|
|
79
|
+
/** Hosted Ragable HTTP API base (`…/api`) — used by all SDK clients (not configurable). */
|
|
80
80
|
declare const DEFAULT_RAGABLE_API_BASE = "https://ragable-341305259977.asia-southeast1.run.app/api";
|
|
81
81
|
interface RagableClientOptions {
|
|
82
82
|
apiKey: string;
|
|
83
|
-
baseUrl?: string;
|
|
84
83
|
fetch?: typeof fetch;
|
|
85
84
|
headers?: HeadersInit;
|
|
86
85
|
}
|
|
@@ -581,7 +580,6 @@ interface AuthOptions {
|
|
|
581
580
|
debug?: boolean;
|
|
582
581
|
}
|
|
583
582
|
interface RagableAuthConfig {
|
|
584
|
-
baseUrl: string;
|
|
585
583
|
authGroupId: string;
|
|
586
584
|
fetch?: typeof fetch;
|
|
587
585
|
headers?: HeadersInit;
|
|
@@ -766,17 +764,27 @@ declare class Transport {
|
|
|
766
764
|
}
|
|
767
765
|
declare function parseTransportResponse<T>(response: Response): Promise<T>;
|
|
768
766
|
|
|
769
|
-
|
|
767
|
+
/** Canonical browser/server API base (`…/api`, no trailing slash). */
|
|
768
|
+
declare function normalizeBrowserApiBase(): string;
|
|
770
769
|
type BrowserDataAuthMode = "user" | "publicAnon" | "admin";
|
|
770
|
+
/**
|
|
771
|
+
* Resolves how database requests are authorized. If `dataAuth` is omitted and a
|
|
772
|
+
* static browser SQL key is configured (`dataStaticKey` / `getDataStaticKey`),
|
|
773
|
+
* defaults to **`publicAnon`** so read-only public apps work without sign-in.
|
|
774
|
+
* Use explicit **`dataAuth: "user"`** when you need JWT sessions; use **`"admin"`**
|
|
775
|
+
* when the static key is a data-admin key (writes) — do not rely on inference for admin keys.
|
|
776
|
+
*/
|
|
777
|
+
declare function effectiveDataAuth(options: RagableBrowserClientOptions): BrowserDataAuthMode;
|
|
771
778
|
interface RagableBrowserClientOptions {
|
|
772
779
|
organizationId: string;
|
|
773
780
|
authGroupId?: string;
|
|
774
781
|
databaseInstanceId?: string;
|
|
782
|
+
/** When omitted, inferred from static keys — see {@link effectiveDataAuth}. */
|
|
775
783
|
dataAuth?: BrowserDataAuthMode;
|
|
784
|
+
/** Public anon or data-admin key from the dashboard (Browser SQL API keys). */
|
|
776
785
|
dataStaticKey?: string;
|
|
777
786
|
getDataStaticKey?: () => string | null | Promise<string | null>;
|
|
778
787
|
getAccessToken?: () => string | null | Promise<string | null>;
|
|
779
|
-
baseUrl?: string;
|
|
780
788
|
fetch?: typeof fetch;
|
|
781
789
|
headers?: HeadersInit;
|
|
782
790
|
auth?: AuthOptions;
|
|
@@ -1003,9 +1011,8 @@ declare class Ragable {
|
|
|
1003
1011
|
};
|
|
1004
1012
|
constructor(options: RagableClientOptions);
|
|
1005
1013
|
}
|
|
1006
|
-
declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends Record<string, unknown> = Record<string, unknown>>(url: string, options: Omit<RagableBrowserClientOptions, "baseUrl">): RagableBrowser<Database, AuthUser>;
|
|
1007
1014
|
declare function createClient(options: RagableClientOptions): Ragable;
|
|
1008
1015
|
declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends Record<string, unknown> = Record<string, unknown>>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
|
|
1009
1016
|
declare function createRagableServerClient(options: RagableClientOptions): Ragable;
|
|
1010
1017
|
|
|
1011
|
-
export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentPublicChatParams, type AgentStreamEvent, type AgentSummary, AgentsClient, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, type AuthSession, type BrowserAuthSession, type BrowserAuthTokens, type BrowserDataAuthMode, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultRagableDatabase, type FormatContextOptions, type HttpMethod, type Json, LocalStorageAdapter, MemoryStorageAdapter, type PostgRESTFetch, type PostgRESTFetchParams, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, PostgrestInsertSdkErrorReturning, PostgrestInsertSdkErrorRoot, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, type RagClientForPipeline, type RagPipeline, type RagPipelineOptions, Ragable, RagableAbortError, RagableAuth, type RagableAuthConfig, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, type RagableClientOptions, type RagableDatabase, RagableError, RagableNetworkError, RagableRequestClient, RagableSdkError, type RagableTableDefinition, type RagableTableNames, RagableTimeoutError, type RequestOptions, type RetrieveParams, type RetryOptions, type RunQuery, type SessionStorage, SessionStorageAdapter, 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, Transport, type TransportOptions, type TransportRequest, asPostgrestResponse, bindFetch, createBrowserClient, createClient, createRagPipeline, createRagableBrowserClient, createRagableServerClient, detectStorage, extractErrorMessage, formatPostgrestError, formatRetrievalContext, formatSdkError, generateIdempotencyKey, normalizeBrowserApiBase, parseSseDataLine, parseTransportResponse, readSseStream };
|
|
1018
|
+
export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentPublicChatParams, type AgentStreamEvent, type AgentSummary, AgentsClient, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, type AuthSession, type BrowserAuthSession, type BrowserAuthTokens, type BrowserDataAuthMode, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultRagableDatabase, type FormatContextOptions, type HttpMethod, type Json, LocalStorageAdapter, MemoryStorageAdapter, type PostgRESTFetch, type PostgRESTFetchParams, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, PostgrestInsertSdkErrorReturning, PostgrestInsertSdkErrorRoot, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, type RagClientForPipeline, type RagPipeline, type RagPipelineOptions, Ragable, RagableAbortError, RagableAuth, type RagableAuthConfig, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, type RagableClientOptions, type RagableDatabase, RagableError, RagableNetworkError, RagableRequestClient, RagableSdkError, type RagableTableDefinition, type RagableTableNames, RagableTimeoutError, type RequestOptions, type RetrieveParams, type RetryOptions, type RunQuery, type SessionStorage, SessionStorageAdapter, 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, Transport, type TransportOptions, type TransportRequest, asPostgrestResponse, bindFetch, createBrowserClient, createClient, createRagPipeline, createRagableBrowserClient, createRagableServerClient, detectStorage, effectiveDataAuth, extractErrorMessage, formatPostgrestError, formatRetrievalContext, formatSdkError, generateIdempotencyKey, normalizeBrowserApiBase, parseSseDataLine, parseTransportResponse, readSseStream };
|
package/dist/index.d.ts
CHANGED
|
@@ -76,11 +76,10 @@ type ColumnValue<D extends RagableDatabase, T extends RagableTableNames<D>, C ex
|
|
|
76
76
|
* or the browser throws **Illegal invocation**. Use this for defaults and for `options.fetch`.
|
|
77
77
|
*/
|
|
78
78
|
declare function bindFetch(custom?: typeof fetch): typeof fetch;
|
|
79
|
-
/**
|
|
79
|
+
/** Hosted Ragable HTTP API base (`…/api`) — used by all SDK clients (not configurable). */
|
|
80
80
|
declare const DEFAULT_RAGABLE_API_BASE = "https://ragable-341305259977.asia-southeast1.run.app/api";
|
|
81
81
|
interface RagableClientOptions {
|
|
82
82
|
apiKey: string;
|
|
83
|
-
baseUrl?: string;
|
|
84
83
|
fetch?: typeof fetch;
|
|
85
84
|
headers?: HeadersInit;
|
|
86
85
|
}
|
|
@@ -581,7 +580,6 @@ interface AuthOptions {
|
|
|
581
580
|
debug?: boolean;
|
|
582
581
|
}
|
|
583
582
|
interface RagableAuthConfig {
|
|
584
|
-
baseUrl: string;
|
|
585
583
|
authGroupId: string;
|
|
586
584
|
fetch?: typeof fetch;
|
|
587
585
|
headers?: HeadersInit;
|
|
@@ -766,17 +764,27 @@ declare class Transport {
|
|
|
766
764
|
}
|
|
767
765
|
declare function parseTransportResponse<T>(response: Response): Promise<T>;
|
|
768
766
|
|
|
769
|
-
|
|
767
|
+
/** Canonical browser/server API base (`…/api`, no trailing slash). */
|
|
768
|
+
declare function normalizeBrowserApiBase(): string;
|
|
770
769
|
type BrowserDataAuthMode = "user" | "publicAnon" | "admin";
|
|
770
|
+
/**
|
|
771
|
+
* Resolves how database requests are authorized. If `dataAuth` is omitted and a
|
|
772
|
+
* static browser SQL key is configured (`dataStaticKey` / `getDataStaticKey`),
|
|
773
|
+
* defaults to **`publicAnon`** so read-only public apps work without sign-in.
|
|
774
|
+
* Use explicit **`dataAuth: "user"`** when you need JWT sessions; use **`"admin"`**
|
|
775
|
+
* when the static key is a data-admin key (writes) — do not rely on inference for admin keys.
|
|
776
|
+
*/
|
|
777
|
+
declare function effectiveDataAuth(options: RagableBrowserClientOptions): BrowserDataAuthMode;
|
|
771
778
|
interface RagableBrowserClientOptions {
|
|
772
779
|
organizationId: string;
|
|
773
780
|
authGroupId?: string;
|
|
774
781
|
databaseInstanceId?: string;
|
|
782
|
+
/** When omitted, inferred from static keys — see {@link effectiveDataAuth}. */
|
|
775
783
|
dataAuth?: BrowserDataAuthMode;
|
|
784
|
+
/** Public anon or data-admin key from the dashboard (Browser SQL API keys). */
|
|
776
785
|
dataStaticKey?: string;
|
|
777
786
|
getDataStaticKey?: () => string | null | Promise<string | null>;
|
|
778
787
|
getAccessToken?: () => string | null | Promise<string | null>;
|
|
779
|
-
baseUrl?: string;
|
|
780
788
|
fetch?: typeof fetch;
|
|
781
789
|
headers?: HeadersInit;
|
|
782
790
|
auth?: AuthOptions;
|
|
@@ -1003,9 +1011,8 @@ declare class Ragable {
|
|
|
1003
1011
|
};
|
|
1004
1012
|
constructor(options: RagableClientOptions);
|
|
1005
1013
|
}
|
|
1006
|
-
declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends Record<string, unknown> = Record<string, unknown>>(url: string, options: Omit<RagableBrowserClientOptions, "baseUrl">): RagableBrowser<Database, AuthUser>;
|
|
1007
1014
|
declare function createClient(options: RagableClientOptions): Ragable;
|
|
1008
1015
|
declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends Record<string, unknown> = Record<string, unknown>>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
|
|
1009
1016
|
declare function createRagableServerClient(options: RagableClientOptions): Ragable;
|
|
1010
1017
|
|
|
1011
|
-
export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentPublicChatParams, type AgentStreamEvent, type AgentSummary, AgentsClient, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, type AuthSession, type BrowserAuthSession, type BrowserAuthTokens, type BrowserDataAuthMode, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultRagableDatabase, type FormatContextOptions, type HttpMethod, type Json, LocalStorageAdapter, MemoryStorageAdapter, type PostgRESTFetch, type PostgRESTFetchParams, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, PostgrestInsertSdkErrorReturning, PostgrestInsertSdkErrorRoot, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, type RagClientForPipeline, type RagPipeline, type RagPipelineOptions, Ragable, RagableAbortError, RagableAuth, type RagableAuthConfig, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, type RagableClientOptions, type RagableDatabase, RagableError, RagableNetworkError, RagableRequestClient, RagableSdkError, type RagableTableDefinition, type RagableTableNames, RagableTimeoutError, type RequestOptions, type RetrieveParams, type RetryOptions, type RunQuery, type SessionStorage, SessionStorageAdapter, 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, Transport, type TransportOptions, type TransportRequest, asPostgrestResponse, bindFetch, createBrowserClient, createClient, createRagPipeline, createRagableBrowserClient, createRagableServerClient, detectStorage, extractErrorMessage, formatPostgrestError, formatRetrievalContext, formatSdkError, generateIdempotencyKey, normalizeBrowserApiBase, parseSseDataLine, parseTransportResponse, readSseStream };
|
|
1018
|
+
export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentPublicChatParams, type AgentStreamEvent, type AgentSummary, AgentsClient, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, type AuthSession, type BrowserAuthSession, type BrowserAuthTokens, type BrowserDataAuthMode, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultRagableDatabase, type FormatContextOptions, type HttpMethod, type Json, LocalStorageAdapter, MemoryStorageAdapter, type PostgRESTFetch, type PostgRESTFetchParams, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, PostgrestInsertSdkErrorReturning, PostgrestInsertSdkErrorRoot, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, type RagClientForPipeline, type RagPipeline, type RagPipelineOptions, Ragable, RagableAbortError, RagableAuth, type RagableAuthConfig, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, type RagableClientOptions, type RagableDatabase, RagableError, RagableNetworkError, RagableRequestClient, RagableSdkError, type RagableTableDefinition, type RagableTableNames, RagableTimeoutError, type RequestOptions, type RetrieveParams, type RetryOptions, type RunQuery, type SessionStorage, SessionStorageAdapter, 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, Transport, type TransportOptions, type TransportRequest, asPostgrestResponse, bindFetch, createBrowserClient, createClient, createRagPipeline, createRagableBrowserClient, createRagableServerClient, detectStorage, effectiveDataAuth, extractErrorMessage, formatPostgrestError, formatRetrievalContext, formatSdkError, generateIdempotencyKey, normalizeBrowserApiBase, parseSseDataLine, parseTransportResponse, readSseStream };
|
package/dist/index.js
CHANGED
|
@@ -63,6 +63,7 @@ __export(index_exports, {
|
|
|
63
63
|
createRagableBrowserClient: () => createRagableBrowserClient,
|
|
64
64
|
createRagableServerClient: () => createRagableServerClient,
|
|
65
65
|
detectStorage: () => detectStorage,
|
|
66
|
+
effectiveDataAuth: () => effectiveDataAuth,
|
|
66
67
|
extractErrorMessage: () => extractErrorMessage,
|
|
67
68
|
formatPostgrestError: () => formatPostgrestError,
|
|
68
69
|
formatRetrievalContext: () => formatRetrievalContext,
|
|
@@ -211,7 +212,7 @@ var RagableRequestClient = class {
|
|
|
211
212
|
__publicField(this, "fetchImpl");
|
|
212
213
|
__publicField(this, "defaultHeaders");
|
|
213
214
|
this.apiKey = options.apiKey;
|
|
214
|
-
this.baseUrl =
|
|
215
|
+
this.baseUrl = DEFAULT_RAGABLE_API_BASE.replace(/\/+$/, "");
|
|
215
216
|
this.fetchImpl = bindFetch(options.fetch);
|
|
216
217
|
this.defaultHeaders = options.headers;
|
|
217
218
|
}
|
|
@@ -1762,7 +1763,7 @@ var RagableAuth = class {
|
|
|
1762
1763
|
__publicField(this, "broadcast", null);
|
|
1763
1764
|
__publicField(this, "visibilityHandler", null);
|
|
1764
1765
|
__publicField(this, "initialized", false);
|
|
1765
|
-
this.baseUrl =
|
|
1766
|
+
this.baseUrl = DEFAULT_RAGABLE_API_BASE.replace(/\/+$/, "");
|
|
1766
1767
|
this.authGroupId = config.authGroupId;
|
|
1767
1768
|
this.fetchImpl = bindFetch(config.fetch);
|
|
1768
1769
|
this.defaultHeaders = config.headers;
|
|
@@ -2115,9 +2116,14 @@ function decodeJwtExpiry(jwt) {
|
|
|
2115
2116
|
}
|
|
2116
2117
|
|
|
2117
2118
|
// src/browser.ts
|
|
2118
|
-
function normalizeBrowserApiBase(
|
|
2119
|
-
|
|
2120
|
-
|
|
2119
|
+
function normalizeBrowserApiBase() {
|
|
2120
|
+
return DEFAULT_RAGABLE_API_BASE.replace(/\/+$/, "");
|
|
2121
|
+
}
|
|
2122
|
+
function effectiveDataAuth(options) {
|
|
2123
|
+
if (options.dataAuth) return options.dataAuth;
|
|
2124
|
+
const hasStatic = Boolean(options.dataStaticKey?.trim()) || typeof options.getDataStaticKey === "function";
|
|
2125
|
+
if (hasStatic) return "publicAnon";
|
|
2126
|
+
return "user";
|
|
2121
2127
|
}
|
|
2122
2128
|
function requireAuthGroupId(options) {
|
|
2123
2129
|
const id = options.authGroupId?.trim();
|
|
@@ -2147,7 +2153,7 @@ async function requireAccessToken(options, ragableAuth) {
|
|
|
2147
2153
|
);
|
|
2148
2154
|
}
|
|
2149
2155
|
async function resolveDatabaseAuthBearer(options, ragableAuth) {
|
|
2150
|
-
const mode = options
|
|
2156
|
+
const mode = effectiveDataAuth(options);
|
|
2151
2157
|
if (mode === "user") {
|
|
2152
2158
|
return requireAccessToken(options, ragableAuth);
|
|
2153
2159
|
}
|
|
@@ -2283,9 +2289,9 @@ var RagableBrowserDatabaseClient = class {
|
|
|
2283
2289
|
}
|
|
2284
2290
|
const gid = requireAuthGroupId(opts);
|
|
2285
2291
|
const token = await resolveDatabaseAuthBearer(opts, ragableAuth);
|
|
2286
|
-
const
|
|
2292
|
+
const apiBase = normalizeBrowserApiBase();
|
|
2287
2293
|
const qs = params.searchParams.toString();
|
|
2288
|
-
const url = `${
|
|
2294
|
+
const url = `${apiBase}/auth-groups/${gid}/data/rest/${params.table}${qs ? `?${qs}` : ""}`;
|
|
2289
2295
|
const headers = new Headers(opts.headers);
|
|
2290
2296
|
headers.set("Authorization", `Bearer ${token}`);
|
|
2291
2297
|
headers.set("X-Database-Instance-Id", params.databaseInstanceId);
|
|
@@ -2331,7 +2337,7 @@ var RagableBrowserDatabaseClient = class {
|
|
|
2331
2337
|
const headers = this.baseHeaders();
|
|
2332
2338
|
headers.set("Authorization", `Bearer ${token}`);
|
|
2333
2339
|
headers.set("Content-Type", "application/json");
|
|
2334
|
-
const readOnly = (this.options
|
|
2340
|
+
const readOnly = effectiveDataAuth(this.options) === "publicAnon" ? true : params.readOnly !== false;
|
|
2335
2341
|
const response = await this.fetchImpl(
|
|
2336
2342
|
this.toUrl(`/auth-groups/${gid}/data/query`),
|
|
2337
2343
|
{
|
|
@@ -2362,7 +2368,7 @@ var RagableBrowserDatabaseClient = class {
|
|
|
2362
2368
|
this._transport = transport;
|
|
2363
2369
|
}
|
|
2364
2370
|
toUrl(path) {
|
|
2365
|
-
return `${normalizeBrowserApiBase(
|
|
2371
|
+
return `${normalizeBrowserApiBase()}${path.startsWith("/") ? path : `/${path}`}`;
|
|
2366
2372
|
}
|
|
2367
2373
|
baseHeaders() {
|
|
2368
2374
|
return new Headers(this.options.headers);
|
|
@@ -2375,7 +2381,7 @@ var RagableBrowserAgentsClient = class {
|
|
|
2375
2381
|
this.fetchImpl = bindFetch(options.fetch);
|
|
2376
2382
|
}
|
|
2377
2383
|
toUrl(path) {
|
|
2378
|
-
return `${normalizeBrowserApiBase(
|
|
2384
|
+
return `${normalizeBrowserApiBase()}${path.startsWith("/") ? path : `/${path}`}`;
|
|
2379
2385
|
}
|
|
2380
2386
|
async *chatStream(agentId, params) {
|
|
2381
2387
|
const orgId = this.options.organizationId;
|
|
@@ -2425,19 +2431,19 @@ var RagableBrowser = class {
|
|
|
2425
2431
|
});
|
|
2426
2432
|
if (options.authGroupId) {
|
|
2427
2433
|
this._ragableAuth = new RagableAuth({
|
|
2428
|
-
baseUrl: normalizeBrowserApiBase(options.baseUrl),
|
|
2429
2434
|
authGroupId: options.authGroupId,
|
|
2430
2435
|
fetch: options.fetch,
|
|
2431
2436
|
headers: options.headers,
|
|
2432
2437
|
auth: options.auth
|
|
2433
2438
|
});
|
|
2434
2439
|
this.transport.setRefreshHandler(async () => {
|
|
2440
|
+
if (effectiveDataAuth(options) !== "user") return null;
|
|
2435
2441
|
const session = await this._ragableAuth.singleFlightRefresh(
|
|
2436
2442
|
this._ragableAuth.getCurrentSession()?.refresh_token ?? ""
|
|
2437
2443
|
);
|
|
2438
2444
|
return session?.access_token ?? null;
|
|
2439
2445
|
});
|
|
2440
|
-
if (!options.getAccessToken) {
|
|
2446
|
+
if (!options.getAccessToken && effectiveDataAuth(options) === "user") {
|
|
2441
2447
|
this._ragableAuth.initialize().catch(() => {
|
|
2442
2448
|
});
|
|
2443
2449
|
}
|
|
@@ -2520,31 +2526,18 @@ var Ragable = class {
|
|
|
2520
2526
|
function isServerClientOptions(o) {
|
|
2521
2527
|
return typeof o === "object" && o !== null && "apiKey" in o && typeof o.apiKey === "string" && o.apiKey.length > 0;
|
|
2522
2528
|
}
|
|
2523
|
-
function createClient(
|
|
2524
|
-
if (
|
|
2525
|
-
if (
|
|
2526
|
-
throw new Error(
|
|
2527
|
-
"createClient(url, options) requires options with at least organizationId"
|
|
2528
|
-
);
|
|
2529
|
-
}
|
|
2530
|
-
const raw = urlOrOptions.trim().replace(/\/+$/, "");
|
|
2531
|
-
const baseUrl = raw.endsWith("/api") ? raw : `${raw}/api`;
|
|
2532
|
-
return createBrowserClient({
|
|
2533
|
-
...browserOptions,
|
|
2534
|
-
baseUrl: normalizeBrowserApiBase(baseUrl)
|
|
2535
|
-
});
|
|
2536
|
-
}
|
|
2537
|
-
if (isServerClientOptions(urlOrOptions)) {
|
|
2538
|
-
if (typeof urlOrOptions === "object" && urlOrOptions !== null && "organizationId" in urlOrOptions && typeof urlOrOptions.organizationId === "string") {
|
|
2529
|
+
function createClient(options) {
|
|
2530
|
+
if (isServerClientOptions(options)) {
|
|
2531
|
+
if (typeof options === "object" && options !== null && "organizationId" in options && typeof options.organizationId === "string") {
|
|
2539
2532
|
console.warn(
|
|
2540
|
-
"[@ragable/sdk] createClient: `apiKey` is set, so the server client is returned. It has no `database` or `auth` \u2014 only `agents` and `shift`. For `database.from()` / `auth.*`, use the browser client without `apiKey` (e.g. createClient(
|
|
2533
|
+
"[@ragable/sdk] createClient: `apiKey` is set, so the server client is returned. It has no `database` or `auth` \u2014 only `agents` and `shift`. For `database.from()` / `auth.*`, use the browser client without `apiKey` (e.g. createClient({ organizationId, authGroupId, databaseInstanceId, ... }))."
|
|
2541
2534
|
);
|
|
2542
2535
|
}
|
|
2543
|
-
return new Ragable(
|
|
2536
|
+
return new Ragable(options);
|
|
2544
2537
|
}
|
|
2545
|
-
if (typeof
|
|
2538
|
+
if (typeof options === "object" && options !== null && "organizationId" in options && typeof options.organizationId === "string") {
|
|
2546
2539
|
return createBrowserClient(
|
|
2547
|
-
|
|
2540
|
+
options
|
|
2548
2541
|
);
|
|
2549
2542
|
}
|
|
2550
2543
|
throw new Error(
|
|
@@ -2597,6 +2590,7 @@ function createRagableServerClient(options) {
|
|
|
2597
2590
|
createRagableBrowserClient,
|
|
2598
2591
|
createRagableServerClient,
|
|
2599
2592
|
detectStorage,
|
|
2593
|
+
effectiveDataAuth,
|
|
2600
2594
|
extractErrorMessage,
|
|
2601
2595
|
formatPostgrestError,
|
|
2602
2596
|
formatRetrievalContext,
|