@ragable/sdk 0.8.1 → 0.8.2
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 +112 -1
- package/dist/index.d.ts +112 -1
- package/dist/index.js +89 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +87 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1279,6 +1279,106 @@ declare function streamObjectFromContext<T = unknown>(ctx: InferenceRequestConte
|
|
|
1279
1279
|
*/
|
|
1280
1280
|
declare function wrapStreamTextAsObject<T = unknown>(inner: StreamTextResult): StreamObjectResult<T>;
|
|
1281
1281
|
|
|
1282
|
+
/**
|
|
1283
|
+
* Server-side client — the authenticated SDK for code that runs on a trusted
|
|
1284
|
+
* server (a Ragable backend **function**, an Engine, or your own Node service).
|
|
1285
|
+
*
|
|
1286
|
+
* Unlike the browser client there is **no sign-in / session machinery** here:
|
|
1287
|
+
* a server is not a logged-in user. Instead you provide credentials up front and
|
|
1288
|
+
* the client speaks to the same Ragable data plane the browser uses, so the
|
|
1289
|
+
* semantics (collection security, `{ data, error }` shapes, PostgREST) are
|
|
1290
|
+
* identical — this reuses the exact same fetch-based sub-clients, never a
|
|
1291
|
+
* reimplementation.
|
|
1292
|
+
*
|
|
1293
|
+
* Two privilege levels:
|
|
1294
|
+
* - **caller** (default): acts as the end user who invoked you — uses their
|
|
1295
|
+
* forwarded access token, falling back to the public anon key for anonymous
|
|
1296
|
+
* callers. Collection security applies, exactly as in the browser.
|
|
1297
|
+
* - **admin**: authenticates with the auth group's **data-admin key**, which
|
|
1298
|
+
* bypasses collection security (owner/group/claim grants do not apply) and
|
|
1299
|
+
* can write protected collections. Reach for it deliberately.
|
|
1300
|
+
*
|
|
1301
|
+
* ```ts
|
|
1302
|
+
* // inside /functions/<name>.ts — `context.ragable` is a pre-built server client
|
|
1303
|
+
* export default async function createTask(input, context) {
|
|
1304
|
+
* // as the caller (respects collection security):
|
|
1305
|
+
* const { data, error } = await context.ragable.db.collections.tasks.insert(input);
|
|
1306
|
+
* // privileged work (bypasses collection security):
|
|
1307
|
+
* await context.ragable.asAdmin().db.collections.audit_log.insert({ action: "create" });
|
|
1308
|
+
* return data;
|
|
1309
|
+
* }
|
|
1310
|
+
* ```
|
|
1311
|
+
*/
|
|
1312
|
+
|
|
1313
|
+
/** Which credential a server client authenticates with. */
|
|
1314
|
+
type ServerPrivilege = "caller" | "admin";
|
|
1315
|
+
/**
|
|
1316
|
+
* Inputs to {@link createServerClient}. The IDs and keys are normally supplied by
|
|
1317
|
+
* the runtime (a function's injected `context.ragable`); construct one by hand
|
|
1318
|
+
* only for a standalone server.
|
|
1319
|
+
*/
|
|
1320
|
+
interface RagableServerClientConfig {
|
|
1321
|
+
organizationId: string;
|
|
1322
|
+
websiteId?: string;
|
|
1323
|
+
authGroupId?: string;
|
|
1324
|
+
databaseInstanceId?: string;
|
|
1325
|
+
storageBucketId?: string;
|
|
1326
|
+
mailAccountId?: string;
|
|
1327
|
+
/**
|
|
1328
|
+
* The auth group's **data-admin key**. Required for `admin` privilege; omit it
|
|
1329
|
+
* and `asAdmin()` throws. Server-only — never expose this to the browser.
|
|
1330
|
+
*/
|
|
1331
|
+
adminKey?: string;
|
|
1332
|
+
/**
|
|
1333
|
+
* The invoking end user's access token (a real auth-group JWT), forwarded by
|
|
1334
|
+
* the runtime. `null`/omitted for anonymous callers. Used by `caller`
|
|
1335
|
+
* privilege; the public anon key is the fallback when this is absent.
|
|
1336
|
+
*/
|
|
1337
|
+
callerToken?: string | null;
|
|
1338
|
+
/** Public anon key — the `caller` fallback when no end user is signed in. */
|
|
1339
|
+
publicAnonKey?: string;
|
|
1340
|
+
/** Default privilege for the returned client. Defaults to `"caller"`. */
|
|
1341
|
+
defaultPrivilege?: ServerPrivilege;
|
|
1342
|
+
fetch?: typeof fetch;
|
|
1343
|
+
headers?: HeadersInit;
|
|
1344
|
+
}
|
|
1345
|
+
/**
|
|
1346
|
+
* A trusted, server-side Ragable client. Surface mirrors the browser client
|
|
1347
|
+
* (`db`, `storage`, `mail`, `functions`, `ai`, `agents`) minus `auth` — a server
|
|
1348
|
+
* authenticates with keys, not a session. Switch privilege with {@link asAdmin}
|
|
1349
|
+
* / {@link asCaller}.
|
|
1350
|
+
*/
|
|
1351
|
+
declare class RagableServerClient<Database extends RagableDatabase = DefaultRagableDatabase, Functions extends RagableFunctions = DefaultRagableFunctions> {
|
|
1352
|
+
private readonly config;
|
|
1353
|
+
readonly database: RagableBrowserDatabaseClient<Database>;
|
|
1354
|
+
readonly db: RagableBrowserDatabaseClient<Database>;
|
|
1355
|
+
readonly storage: RagableBrowserStorageClient;
|
|
1356
|
+
readonly mail: RagableBrowserMailClient;
|
|
1357
|
+
readonly functions: FunctionInvoker<Functions>;
|
|
1358
|
+
readonly ai: RagableBrowserAiClient;
|
|
1359
|
+
readonly agents: RagableBrowserAgentsClient;
|
|
1360
|
+
/** Which credential this client is using. */
|
|
1361
|
+
readonly privilege: ServerPrivilege;
|
|
1362
|
+
constructor(config: RagableServerClientConfig, privilege: ServerPrivilege);
|
|
1363
|
+
/**
|
|
1364
|
+
* A client authenticated with the **data-admin key** — bypasses collection
|
|
1365
|
+
* security (owner/group/claim grants do not apply) and can write protected
|
|
1366
|
+
* collections. Throws `SDK_ADMIN_KEY_REQUIRED` when no admin key is configured.
|
|
1367
|
+
*/
|
|
1368
|
+
asAdmin(): RagableServerClient<Database, Functions>;
|
|
1369
|
+
/**
|
|
1370
|
+
* A client scoped to the invoking end user's identity (respects collection
|
|
1371
|
+
* security). This is already the default; use it to drop back from `asAdmin()`.
|
|
1372
|
+
*/
|
|
1373
|
+
asCaller(): RagableServerClient<Database, Functions>;
|
|
1374
|
+
}
|
|
1375
|
+
/**
|
|
1376
|
+
* Create a server-side Ragable client. Defaults to **caller** privilege (acts as
|
|
1377
|
+
* the invoking end user, respecting collection security); call `.asAdmin()` for
|
|
1378
|
+
* privileged, security-bypassing access.
|
|
1379
|
+
*/
|
|
1380
|
+
declare function createServerClient<Database extends RagableDatabase = DefaultRagableDatabase, Functions extends RagableFunctions = DefaultRagableFunctions>(config: RagableServerClientConfig): RagableServerClient<Database, Functions>;
|
|
1381
|
+
|
|
1282
1382
|
/**
|
|
1283
1383
|
* Backend "edge functions".
|
|
1284
1384
|
*
|
|
@@ -1307,6 +1407,7 @@ declare function wrapStreamTextAsObject<T = unknown>(inner: StreamTextResult): S
|
|
|
1307
1407
|
* The handler's second argument (`context`) is injected by the server; callers
|
|
1308
1408
|
* pass only `input`.
|
|
1309
1409
|
*/
|
|
1410
|
+
|
|
1310
1411
|
/**
|
|
1311
1412
|
* Server-injected second argument to every function handler. Never constructed
|
|
1312
1413
|
* on the client — the values come from the backend at invocation time.
|
|
@@ -1331,6 +1432,16 @@ interface RagableFunctionContext {
|
|
|
1331
1432
|
auth: {
|
|
1332
1433
|
token: string | null;
|
|
1333
1434
|
};
|
|
1435
|
+
/**
|
|
1436
|
+
* A pre-authenticated {@link RagableServerClient} for talking back to your
|
|
1437
|
+
* Ragable Cloud (db / storage / mail / functions / ai / agents) — already
|
|
1438
|
+
* wired to this project, no setup or keys to manage.
|
|
1439
|
+
*
|
|
1440
|
+
* Defaults to the **caller's** identity, so collection security applies just
|
|
1441
|
+
* like in the browser. Call `context.ragable.asAdmin()` for privileged work
|
|
1442
|
+
* that must bypass collection security (e.g. owner-only writes, audit logs).
|
|
1443
|
+
*/
|
|
1444
|
+
ragable: RagableServerClient;
|
|
1334
1445
|
}
|
|
1335
1446
|
/**
|
|
1336
1447
|
* The shape a `/functions/<name>.ts` default export must satisfy. Type the
|
|
@@ -2271,4 +2382,4 @@ declare function tryParsePartialJson(text: string): unknown | undefined;
|
|
|
2271
2382
|
|
|
2272
2383
|
declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser, Functions extends RagableFunctions = DefaultRagableFunctions>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser, Functions>;
|
|
2273
2384
|
|
|
2274
|
-
export { type AgentChatMessage, type AgentChatParams, type AgentChatStreamDonePayload, type AgentChatStreamHandlers, type AgentChatStreamResult, type AgentChatStreamUiHandlers, type AgentChatUiAssistantMessage, type AgentChatUiSegment, type AgentChatUiStreamResult, type AgentConversation, type AgentConversationMessage, type AgentConversationSubscription, type AgentPublicChatParams, type AgentStreamAgentInfoEvent, type AgentStreamEvent, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, type AuthSession, type AuthSignUpCredentials, type AuthUpdateUserAttributes, type AuthUserMetadata, type BrowserAuthSession, type BrowserAuthTokens, BrowserCollectionApi, type BrowserCollectionDefinition, type BrowserCollectionFactory, type BrowserCollectionFindParams, type BrowserCollectionRecord, type BrowserCollections, type BrowserDataAuthMode, type BrowserRealtimeNotification, type BrowserRealtimeStatus, type BrowserRealtimeSubscribeParams, type BrowserRealtimeSubscription, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, BrowserStorageBucketClient, type BrowserStorageBulkDeleteResult, type BrowserStorageDownloadResult, type BrowserStorageItem, type BrowserStorageListResult, type BrowserStorageSignedUrlResult, type BrowserStorageUploadResult, type CollectionReturnMode, type CollectionRowData, type CollectionRowWithMeta, type CollectionWhere, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultAuthUser, type DefaultRagableDatabase, type DefaultRagableFunctions, type FinishReason, type FunctionInvoker, type GenerateObjectResult, type GenerateTextResult, type HttpMethod, type Json, type JsonSchema, LocalStorageAdapter, type MailMessageDetail, type MailMessagePreview, type MailSearchParams, type MailSendParams, type MailSendResult, MemoryStorageAdapter, type Message, type PostgRESTFetch, type PostgRESTFetchParams, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, PostgrestInsertSdkErrorReturning, PostgrestInsertSdkErrorRoot, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, RagableAbortError, RagableAuth, type RagableAuthConfig, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAiClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, RagableBrowserFunctionsClient, RagableBrowserMailClient, RagableBrowserStorageClient, type RagableDatabase, RagableError, type RagableFunctionCall, type RagableFunctionContext, type RagableFunctionHandler, type RagableFunctionInvokeOptions, type RagableFunctions, RagableNetworkError, type RagableResult, RagableSdkError, type RagableTableDefinition, type RagableTableNames, RagableTimeoutError, type RequestOptions, type RetryOptions, type RunAgentChatStreamOptions, type RunQuery, type SessionStorage, SessionStorageAdapter, type SseJsonEvent, type StreamObjectParams, type StreamObjectResult, type StreamPart, type StreamTextParams, type StreamTextResult, type SupabaseCompatSession, type TableInsertRow, type TableRow, type TableUpdatePatch, type Tables, type TablesInsert, type TablesUpdate, type TokenUsage, type ToolCallRecord, Transport, type TransportOptions, type TransportRequest, type WhereInput, type WhereOperatorObject, asPostgrestResponse, assertPostgrestSuccess, bindFetch, buildInferenceRequestBody, buildResponseFormat, collectAssistantTextFromUiSegments, collectionRecordToRowWithMeta, collectionRecordsToRowWithMeta, createBrowserClient, createClient, createRagableBrowserClient, createStreamResultFromParts, detectStorage, effectiveDataAuth, extractErrorMessage, finalizeAgentChatUiTurn, foldAgentStreamIntoUiSegments, formatPostgrestError, formatSdkError, generateIdempotencyKey, isIncompleteAgentStreamError, mapAgentEvent, mapFireworksChunk, normalizeBrowserApiBase, parseAgentStreamAgentInfo, parseAgentStreamDone, parseSseDataLine, parseTransportResponse, readSseStream, runAgentChatStream, runAgentChatStreamForUi, runAgentChatStreamLenient, streamObjectFromContext, toRagableResult, tryParsePartialJson, unwrapPostgrest, wrapStreamTextAsObject };
|
|
2385
|
+
export { type AgentChatMessage, type AgentChatParams, type AgentChatStreamDonePayload, type AgentChatStreamHandlers, type AgentChatStreamResult, type AgentChatStreamUiHandlers, type AgentChatUiAssistantMessage, type AgentChatUiSegment, type AgentChatUiStreamResult, type AgentConversation, type AgentConversationMessage, type AgentConversationSubscription, type AgentPublicChatParams, type AgentStreamAgentInfoEvent, type AgentStreamEvent, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, type AuthSession, type AuthSignUpCredentials, type AuthUpdateUserAttributes, type AuthUserMetadata, type BrowserAuthSession, type BrowserAuthTokens, BrowserCollectionApi, type BrowserCollectionDefinition, type BrowserCollectionFactory, type BrowserCollectionFindParams, type BrowserCollectionRecord, type BrowserCollections, type BrowserDataAuthMode, type BrowserRealtimeNotification, type BrowserRealtimeStatus, type BrowserRealtimeSubscribeParams, type BrowserRealtimeSubscription, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, BrowserStorageBucketClient, type BrowserStorageBulkDeleteResult, type BrowserStorageDownloadResult, type BrowserStorageItem, type BrowserStorageListResult, type BrowserStorageSignedUrlResult, type BrowserStorageUploadResult, type CollectionReturnMode, type CollectionRowData, type CollectionRowWithMeta, type CollectionWhere, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultAuthUser, type DefaultRagableDatabase, type DefaultRagableFunctions, type FinishReason, type FunctionInvoker, type GenerateObjectResult, type GenerateTextResult, type HttpMethod, type Json, type JsonSchema, LocalStorageAdapter, type MailMessageDetail, type MailMessagePreview, type MailSearchParams, type MailSendParams, type MailSendResult, MemoryStorageAdapter, type Message, type PostgRESTFetch, type PostgRESTFetchParams, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, PostgrestInsertSdkErrorReturning, PostgrestInsertSdkErrorRoot, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, RagableAbortError, RagableAuth, type RagableAuthConfig, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAiClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, RagableBrowserFunctionsClient, RagableBrowserMailClient, RagableBrowserStorageClient, type RagableDatabase, RagableError, type RagableFunctionCall, type RagableFunctionContext, type RagableFunctionHandler, type RagableFunctionInvokeOptions, type RagableFunctions, RagableNetworkError, type RagableResult, RagableSdkError, RagableServerClient, type RagableServerClientConfig, type RagableTableDefinition, type RagableTableNames, RagableTimeoutError, type RequestOptions, type RetryOptions, type RunAgentChatStreamOptions, type RunQuery, type ServerPrivilege, type SessionStorage, SessionStorageAdapter, type SseJsonEvent, type StreamObjectParams, type StreamObjectResult, type StreamPart, type StreamTextParams, type StreamTextResult, type SupabaseCompatSession, type TableInsertRow, type TableRow, type TableUpdatePatch, type Tables, type TablesInsert, type TablesUpdate, type TokenUsage, type ToolCallRecord, Transport, type TransportOptions, type TransportRequest, type WhereInput, type WhereOperatorObject, asPostgrestResponse, assertPostgrestSuccess, bindFetch, buildInferenceRequestBody, buildResponseFormat, collectAssistantTextFromUiSegments, collectionRecordToRowWithMeta, collectionRecordsToRowWithMeta, createBrowserClient, createClient, createRagableBrowserClient, createServerClient, createStreamResultFromParts, detectStorage, effectiveDataAuth, extractErrorMessage, finalizeAgentChatUiTurn, foldAgentStreamIntoUiSegments, formatPostgrestError, formatSdkError, generateIdempotencyKey, isIncompleteAgentStreamError, mapAgentEvent, mapFireworksChunk, normalizeBrowserApiBase, parseAgentStreamAgentInfo, parseAgentStreamDone, parseSseDataLine, parseTransportResponse, readSseStream, runAgentChatStream, runAgentChatStreamForUi, runAgentChatStreamLenient, streamObjectFromContext, toRagableResult, tryParsePartialJson, unwrapPostgrest, wrapStreamTextAsObject };
|
package/dist/index.d.ts
CHANGED
|
@@ -1279,6 +1279,106 @@ declare function streamObjectFromContext<T = unknown>(ctx: InferenceRequestConte
|
|
|
1279
1279
|
*/
|
|
1280
1280
|
declare function wrapStreamTextAsObject<T = unknown>(inner: StreamTextResult): StreamObjectResult<T>;
|
|
1281
1281
|
|
|
1282
|
+
/**
|
|
1283
|
+
* Server-side client — the authenticated SDK for code that runs on a trusted
|
|
1284
|
+
* server (a Ragable backend **function**, an Engine, or your own Node service).
|
|
1285
|
+
*
|
|
1286
|
+
* Unlike the browser client there is **no sign-in / session machinery** here:
|
|
1287
|
+
* a server is not a logged-in user. Instead you provide credentials up front and
|
|
1288
|
+
* the client speaks to the same Ragable data plane the browser uses, so the
|
|
1289
|
+
* semantics (collection security, `{ data, error }` shapes, PostgREST) are
|
|
1290
|
+
* identical — this reuses the exact same fetch-based sub-clients, never a
|
|
1291
|
+
* reimplementation.
|
|
1292
|
+
*
|
|
1293
|
+
* Two privilege levels:
|
|
1294
|
+
* - **caller** (default): acts as the end user who invoked you — uses their
|
|
1295
|
+
* forwarded access token, falling back to the public anon key for anonymous
|
|
1296
|
+
* callers. Collection security applies, exactly as in the browser.
|
|
1297
|
+
* - **admin**: authenticates with the auth group's **data-admin key**, which
|
|
1298
|
+
* bypasses collection security (owner/group/claim grants do not apply) and
|
|
1299
|
+
* can write protected collections. Reach for it deliberately.
|
|
1300
|
+
*
|
|
1301
|
+
* ```ts
|
|
1302
|
+
* // inside /functions/<name>.ts — `context.ragable` is a pre-built server client
|
|
1303
|
+
* export default async function createTask(input, context) {
|
|
1304
|
+
* // as the caller (respects collection security):
|
|
1305
|
+
* const { data, error } = await context.ragable.db.collections.tasks.insert(input);
|
|
1306
|
+
* // privileged work (bypasses collection security):
|
|
1307
|
+
* await context.ragable.asAdmin().db.collections.audit_log.insert({ action: "create" });
|
|
1308
|
+
* return data;
|
|
1309
|
+
* }
|
|
1310
|
+
* ```
|
|
1311
|
+
*/
|
|
1312
|
+
|
|
1313
|
+
/** Which credential a server client authenticates with. */
|
|
1314
|
+
type ServerPrivilege = "caller" | "admin";
|
|
1315
|
+
/**
|
|
1316
|
+
* Inputs to {@link createServerClient}. The IDs and keys are normally supplied by
|
|
1317
|
+
* the runtime (a function's injected `context.ragable`); construct one by hand
|
|
1318
|
+
* only for a standalone server.
|
|
1319
|
+
*/
|
|
1320
|
+
interface RagableServerClientConfig {
|
|
1321
|
+
organizationId: string;
|
|
1322
|
+
websiteId?: string;
|
|
1323
|
+
authGroupId?: string;
|
|
1324
|
+
databaseInstanceId?: string;
|
|
1325
|
+
storageBucketId?: string;
|
|
1326
|
+
mailAccountId?: string;
|
|
1327
|
+
/**
|
|
1328
|
+
* The auth group's **data-admin key**. Required for `admin` privilege; omit it
|
|
1329
|
+
* and `asAdmin()` throws. Server-only — never expose this to the browser.
|
|
1330
|
+
*/
|
|
1331
|
+
adminKey?: string;
|
|
1332
|
+
/**
|
|
1333
|
+
* The invoking end user's access token (a real auth-group JWT), forwarded by
|
|
1334
|
+
* the runtime. `null`/omitted for anonymous callers. Used by `caller`
|
|
1335
|
+
* privilege; the public anon key is the fallback when this is absent.
|
|
1336
|
+
*/
|
|
1337
|
+
callerToken?: string | null;
|
|
1338
|
+
/** Public anon key — the `caller` fallback when no end user is signed in. */
|
|
1339
|
+
publicAnonKey?: string;
|
|
1340
|
+
/** Default privilege for the returned client. Defaults to `"caller"`. */
|
|
1341
|
+
defaultPrivilege?: ServerPrivilege;
|
|
1342
|
+
fetch?: typeof fetch;
|
|
1343
|
+
headers?: HeadersInit;
|
|
1344
|
+
}
|
|
1345
|
+
/**
|
|
1346
|
+
* A trusted, server-side Ragable client. Surface mirrors the browser client
|
|
1347
|
+
* (`db`, `storage`, `mail`, `functions`, `ai`, `agents`) minus `auth` — a server
|
|
1348
|
+
* authenticates with keys, not a session. Switch privilege with {@link asAdmin}
|
|
1349
|
+
* / {@link asCaller}.
|
|
1350
|
+
*/
|
|
1351
|
+
declare class RagableServerClient<Database extends RagableDatabase = DefaultRagableDatabase, Functions extends RagableFunctions = DefaultRagableFunctions> {
|
|
1352
|
+
private readonly config;
|
|
1353
|
+
readonly database: RagableBrowserDatabaseClient<Database>;
|
|
1354
|
+
readonly db: RagableBrowserDatabaseClient<Database>;
|
|
1355
|
+
readonly storage: RagableBrowserStorageClient;
|
|
1356
|
+
readonly mail: RagableBrowserMailClient;
|
|
1357
|
+
readonly functions: FunctionInvoker<Functions>;
|
|
1358
|
+
readonly ai: RagableBrowserAiClient;
|
|
1359
|
+
readonly agents: RagableBrowserAgentsClient;
|
|
1360
|
+
/** Which credential this client is using. */
|
|
1361
|
+
readonly privilege: ServerPrivilege;
|
|
1362
|
+
constructor(config: RagableServerClientConfig, privilege: ServerPrivilege);
|
|
1363
|
+
/**
|
|
1364
|
+
* A client authenticated with the **data-admin key** — bypasses collection
|
|
1365
|
+
* security (owner/group/claim grants do not apply) and can write protected
|
|
1366
|
+
* collections. Throws `SDK_ADMIN_KEY_REQUIRED` when no admin key is configured.
|
|
1367
|
+
*/
|
|
1368
|
+
asAdmin(): RagableServerClient<Database, Functions>;
|
|
1369
|
+
/**
|
|
1370
|
+
* A client scoped to the invoking end user's identity (respects collection
|
|
1371
|
+
* security). This is already the default; use it to drop back from `asAdmin()`.
|
|
1372
|
+
*/
|
|
1373
|
+
asCaller(): RagableServerClient<Database, Functions>;
|
|
1374
|
+
}
|
|
1375
|
+
/**
|
|
1376
|
+
* Create a server-side Ragable client. Defaults to **caller** privilege (acts as
|
|
1377
|
+
* the invoking end user, respecting collection security); call `.asAdmin()` for
|
|
1378
|
+
* privileged, security-bypassing access.
|
|
1379
|
+
*/
|
|
1380
|
+
declare function createServerClient<Database extends RagableDatabase = DefaultRagableDatabase, Functions extends RagableFunctions = DefaultRagableFunctions>(config: RagableServerClientConfig): RagableServerClient<Database, Functions>;
|
|
1381
|
+
|
|
1282
1382
|
/**
|
|
1283
1383
|
* Backend "edge functions".
|
|
1284
1384
|
*
|
|
@@ -1307,6 +1407,7 @@ declare function wrapStreamTextAsObject<T = unknown>(inner: StreamTextResult): S
|
|
|
1307
1407
|
* The handler's second argument (`context`) is injected by the server; callers
|
|
1308
1408
|
* pass only `input`.
|
|
1309
1409
|
*/
|
|
1410
|
+
|
|
1310
1411
|
/**
|
|
1311
1412
|
* Server-injected second argument to every function handler. Never constructed
|
|
1312
1413
|
* on the client — the values come from the backend at invocation time.
|
|
@@ -1331,6 +1432,16 @@ interface RagableFunctionContext {
|
|
|
1331
1432
|
auth: {
|
|
1332
1433
|
token: string | null;
|
|
1333
1434
|
};
|
|
1435
|
+
/**
|
|
1436
|
+
* A pre-authenticated {@link RagableServerClient} for talking back to your
|
|
1437
|
+
* Ragable Cloud (db / storage / mail / functions / ai / agents) — already
|
|
1438
|
+
* wired to this project, no setup or keys to manage.
|
|
1439
|
+
*
|
|
1440
|
+
* Defaults to the **caller's** identity, so collection security applies just
|
|
1441
|
+
* like in the browser. Call `context.ragable.asAdmin()` for privileged work
|
|
1442
|
+
* that must bypass collection security (e.g. owner-only writes, audit logs).
|
|
1443
|
+
*/
|
|
1444
|
+
ragable: RagableServerClient;
|
|
1334
1445
|
}
|
|
1335
1446
|
/**
|
|
1336
1447
|
* The shape a `/functions/<name>.ts` default export must satisfy. Type the
|
|
@@ -2271,4 +2382,4 @@ declare function tryParsePartialJson(text: string): unknown | undefined;
|
|
|
2271
2382
|
|
|
2272
2383
|
declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser, Functions extends RagableFunctions = DefaultRagableFunctions>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser, Functions>;
|
|
2273
2384
|
|
|
2274
|
-
export { type AgentChatMessage, type AgentChatParams, type AgentChatStreamDonePayload, type AgentChatStreamHandlers, type AgentChatStreamResult, type AgentChatStreamUiHandlers, type AgentChatUiAssistantMessage, type AgentChatUiSegment, type AgentChatUiStreamResult, type AgentConversation, type AgentConversationMessage, type AgentConversationSubscription, type AgentPublicChatParams, type AgentStreamAgentInfoEvent, type AgentStreamEvent, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, type AuthSession, type AuthSignUpCredentials, type AuthUpdateUserAttributes, type AuthUserMetadata, type BrowserAuthSession, type BrowserAuthTokens, BrowserCollectionApi, type BrowserCollectionDefinition, type BrowserCollectionFactory, type BrowserCollectionFindParams, type BrowserCollectionRecord, type BrowserCollections, type BrowserDataAuthMode, type BrowserRealtimeNotification, type BrowserRealtimeStatus, type BrowserRealtimeSubscribeParams, type BrowserRealtimeSubscription, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, BrowserStorageBucketClient, type BrowserStorageBulkDeleteResult, type BrowserStorageDownloadResult, type BrowserStorageItem, type BrowserStorageListResult, type BrowserStorageSignedUrlResult, type BrowserStorageUploadResult, type CollectionReturnMode, type CollectionRowData, type CollectionRowWithMeta, type CollectionWhere, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultAuthUser, type DefaultRagableDatabase, type DefaultRagableFunctions, type FinishReason, type FunctionInvoker, type GenerateObjectResult, type GenerateTextResult, type HttpMethod, type Json, type JsonSchema, LocalStorageAdapter, type MailMessageDetail, type MailMessagePreview, type MailSearchParams, type MailSendParams, type MailSendResult, MemoryStorageAdapter, type Message, type PostgRESTFetch, type PostgRESTFetchParams, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, PostgrestInsertSdkErrorReturning, PostgrestInsertSdkErrorRoot, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, RagableAbortError, RagableAuth, type RagableAuthConfig, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAiClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, RagableBrowserFunctionsClient, RagableBrowserMailClient, RagableBrowserStorageClient, type RagableDatabase, RagableError, type RagableFunctionCall, type RagableFunctionContext, type RagableFunctionHandler, type RagableFunctionInvokeOptions, type RagableFunctions, RagableNetworkError, type RagableResult, RagableSdkError, type RagableTableDefinition, type RagableTableNames, RagableTimeoutError, type RequestOptions, type RetryOptions, type RunAgentChatStreamOptions, type RunQuery, type SessionStorage, SessionStorageAdapter, type SseJsonEvent, type StreamObjectParams, type StreamObjectResult, type StreamPart, type StreamTextParams, type StreamTextResult, type SupabaseCompatSession, type TableInsertRow, type TableRow, type TableUpdatePatch, type Tables, type TablesInsert, type TablesUpdate, type TokenUsage, type ToolCallRecord, Transport, type TransportOptions, type TransportRequest, type WhereInput, type WhereOperatorObject, asPostgrestResponse, assertPostgrestSuccess, bindFetch, buildInferenceRequestBody, buildResponseFormat, collectAssistantTextFromUiSegments, collectionRecordToRowWithMeta, collectionRecordsToRowWithMeta, createBrowserClient, createClient, createRagableBrowserClient, createStreamResultFromParts, detectStorage, effectiveDataAuth, extractErrorMessage, finalizeAgentChatUiTurn, foldAgentStreamIntoUiSegments, formatPostgrestError, formatSdkError, generateIdempotencyKey, isIncompleteAgentStreamError, mapAgentEvent, mapFireworksChunk, normalizeBrowserApiBase, parseAgentStreamAgentInfo, parseAgentStreamDone, parseSseDataLine, parseTransportResponse, readSseStream, runAgentChatStream, runAgentChatStreamForUi, runAgentChatStreamLenient, streamObjectFromContext, toRagableResult, tryParsePartialJson, unwrapPostgrest, wrapStreamTextAsObject };
|
|
2385
|
+
export { type AgentChatMessage, type AgentChatParams, type AgentChatStreamDonePayload, type AgentChatStreamHandlers, type AgentChatStreamResult, type AgentChatStreamUiHandlers, type AgentChatUiAssistantMessage, type AgentChatUiSegment, type AgentChatUiStreamResult, type AgentConversation, type AgentConversationMessage, type AgentConversationSubscription, type AgentPublicChatParams, type AgentStreamAgentInfoEvent, type AgentStreamEvent, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, type AuthSession, type AuthSignUpCredentials, type AuthUpdateUserAttributes, type AuthUserMetadata, type BrowserAuthSession, type BrowserAuthTokens, BrowserCollectionApi, type BrowserCollectionDefinition, type BrowserCollectionFactory, type BrowserCollectionFindParams, type BrowserCollectionRecord, type BrowserCollections, type BrowserDataAuthMode, type BrowserRealtimeNotification, type BrowserRealtimeStatus, type BrowserRealtimeSubscribeParams, type BrowserRealtimeSubscription, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, BrowserStorageBucketClient, type BrowserStorageBulkDeleteResult, type BrowserStorageDownloadResult, type BrowserStorageItem, type BrowserStorageListResult, type BrowserStorageSignedUrlResult, type BrowserStorageUploadResult, type CollectionReturnMode, type CollectionRowData, type CollectionRowWithMeta, type CollectionWhere, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultAuthUser, type DefaultRagableDatabase, type DefaultRagableFunctions, type FinishReason, type FunctionInvoker, type GenerateObjectResult, type GenerateTextResult, type HttpMethod, type Json, type JsonSchema, LocalStorageAdapter, type MailMessageDetail, type MailMessagePreview, type MailSearchParams, type MailSendParams, type MailSendResult, MemoryStorageAdapter, type Message, type PostgRESTFetch, type PostgRESTFetchParams, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, PostgrestInsertSdkErrorReturning, PostgrestInsertSdkErrorRoot, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, RagableAbortError, RagableAuth, type RagableAuthConfig, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAiClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, RagableBrowserFunctionsClient, RagableBrowserMailClient, RagableBrowserStorageClient, type RagableDatabase, RagableError, type RagableFunctionCall, type RagableFunctionContext, type RagableFunctionHandler, type RagableFunctionInvokeOptions, type RagableFunctions, RagableNetworkError, type RagableResult, RagableSdkError, RagableServerClient, type RagableServerClientConfig, type RagableTableDefinition, type RagableTableNames, RagableTimeoutError, type RequestOptions, type RetryOptions, type RunAgentChatStreamOptions, type RunQuery, type ServerPrivilege, type SessionStorage, SessionStorageAdapter, type SseJsonEvent, type StreamObjectParams, type StreamObjectResult, type StreamPart, type StreamTextParams, type StreamTextResult, type SupabaseCompatSession, type TableInsertRow, type TableRow, type TableUpdatePatch, type Tables, type TablesInsert, type TablesUpdate, type TokenUsage, type ToolCallRecord, Transport, type TransportOptions, type TransportRequest, type WhereInput, type WhereOperatorObject, asPostgrestResponse, assertPostgrestSuccess, bindFetch, buildInferenceRequestBody, buildResponseFormat, collectAssistantTextFromUiSegments, collectionRecordToRowWithMeta, collectionRecordsToRowWithMeta, createBrowserClient, createClient, createRagableBrowserClient, createServerClient, createStreamResultFromParts, detectStorage, effectiveDataAuth, extractErrorMessage, finalizeAgentChatUiTurn, foldAgentStreamIntoUiSegments, formatPostgrestError, formatSdkError, generateIdempotencyKey, isIncompleteAgentStreamError, mapAgentEvent, mapFireworksChunk, normalizeBrowserApiBase, parseAgentStreamAgentInfo, parseAgentStreamDone, parseSseDataLine, parseTransportResponse, readSseStream, runAgentChatStream, runAgentChatStreamForUi, runAgentChatStreamLenient, streamObjectFromContext, toRagableResult, tryParsePartialJson, unwrapPostgrest, wrapStreamTextAsObject };
|
package/dist/index.js
CHANGED
|
@@ -53,6 +53,7 @@ __export(index_exports, {
|
|
|
53
53
|
RagableError: () => RagableError,
|
|
54
54
|
RagableNetworkError: () => RagableNetworkError,
|
|
55
55
|
RagableSdkError: () => RagableSdkError,
|
|
56
|
+
RagableServerClient: () => RagableServerClient,
|
|
56
57
|
RagableTimeoutError: () => RagableTimeoutError,
|
|
57
58
|
SessionStorageAdapter: () => SessionStorageAdapter,
|
|
58
59
|
Transport: () => Transport,
|
|
@@ -67,6 +68,7 @@ __export(index_exports, {
|
|
|
67
68
|
createBrowserClient: () => createBrowserClient,
|
|
68
69
|
createClient: () => createClient,
|
|
69
70
|
createRagableBrowserClient: () => createRagableBrowserClient,
|
|
71
|
+
createServerClient: () => createServerClient,
|
|
70
72
|
createStreamResultFromParts: () => createStreamResultFromParts,
|
|
71
73
|
detectStorage: () => detectStorage,
|
|
72
74
|
effectiveDataAuth: () => effectiveDataAuth,
|
|
@@ -4650,6 +4652,91 @@ function createBrowserClient(options) {
|
|
|
4650
4652
|
}
|
|
4651
4653
|
var createRagableBrowserClient = createBrowserClient;
|
|
4652
4654
|
|
|
4655
|
+
// src/server.ts
|
|
4656
|
+
function optionsForPrivilege(config, privilege) {
|
|
4657
|
+
const base = {
|
|
4658
|
+
organizationId: config.organizationId,
|
|
4659
|
+
...config.websiteId !== void 0 ? { websiteId: config.websiteId } : {},
|
|
4660
|
+
...config.authGroupId !== void 0 ? { authGroupId: config.authGroupId } : {},
|
|
4661
|
+
...config.databaseInstanceId !== void 0 ? { databaseInstanceId: config.databaseInstanceId } : {},
|
|
4662
|
+
...config.fetch !== void 0 ? { fetch: config.fetch } : {},
|
|
4663
|
+
...config.headers !== void 0 ? { headers: config.headers } : {}
|
|
4664
|
+
};
|
|
4665
|
+
if (privilege === "admin") {
|
|
4666
|
+
const key = config.adminKey?.trim();
|
|
4667
|
+
if (!key) {
|
|
4668
|
+
throw new RagableError(
|
|
4669
|
+
"Admin privilege requires `adminKey` (the auth group's data-admin key). It is not available \u2014 admin functions may be disabled for this project.",
|
|
4670
|
+
403,
|
|
4671
|
+
{ code: "SDK_ADMIN_KEY_REQUIRED" }
|
|
4672
|
+
);
|
|
4673
|
+
}
|
|
4674
|
+
return { ...base, dataAuth: "admin", dataStaticKey: key };
|
|
4675
|
+
}
|
|
4676
|
+
return {
|
|
4677
|
+
...base,
|
|
4678
|
+
dataAuth: "auto",
|
|
4679
|
+
getAccessToken: () => config.callerToken ?? null,
|
|
4680
|
+
...config.publicAnonKey !== void 0 ? { dataStaticKey: config.publicAnonKey } : {}
|
|
4681
|
+
};
|
|
4682
|
+
}
|
|
4683
|
+
var RagableServerClient = class _RagableServerClient {
|
|
4684
|
+
constructor(config, privilege) {
|
|
4685
|
+
this.config = config;
|
|
4686
|
+
__publicField(this, "database");
|
|
4687
|
+
__publicField(this, "db");
|
|
4688
|
+
__publicField(this, "storage");
|
|
4689
|
+
__publicField(this, "mail");
|
|
4690
|
+
__publicField(this, "functions");
|
|
4691
|
+
__publicField(this, "ai");
|
|
4692
|
+
__publicField(this, "agents");
|
|
4693
|
+
/** Which credential this client is using. */
|
|
4694
|
+
__publicField(this, "privilege");
|
|
4695
|
+
this.privilege = privilege;
|
|
4696
|
+
const options = optionsForPrivilege(config, privilege);
|
|
4697
|
+
const transport = new Transport({
|
|
4698
|
+
...options.fetch !== void 0 ? { fetch: options.fetch } : {},
|
|
4699
|
+
...options.headers !== void 0 ? { headers: options.headers } : {},
|
|
4700
|
+
...options.transport
|
|
4701
|
+
});
|
|
4702
|
+
this.database = new RagableBrowserDatabaseClient(options, null);
|
|
4703
|
+
this.database._setTransport(transport);
|
|
4704
|
+
this.db = this.database;
|
|
4705
|
+
this.storage = new RagableBrowserStorageClient(options, bindFetch(options.fetch), null);
|
|
4706
|
+
this.mail = new RagableBrowserMailClient(options, null);
|
|
4707
|
+
this.functions = new RagableBrowserFunctionsClient(options, null).asInvoker();
|
|
4708
|
+
this.ai = new RagableBrowserAiClient({
|
|
4709
|
+
organizationId: options.organizationId,
|
|
4710
|
+
...options.websiteId !== void 0 ? { websiteId: options.websiteId } : {},
|
|
4711
|
+
...options.fetch !== void 0 ? { fetch: options.fetch } : {},
|
|
4712
|
+
...options.headers !== void 0 ? { headers: options.headers } : {},
|
|
4713
|
+
apiBase: normalizeBrowserApiBase()
|
|
4714
|
+
});
|
|
4715
|
+
this.agents = new RagableBrowserAgentsClient(options);
|
|
4716
|
+
}
|
|
4717
|
+
/**
|
|
4718
|
+
* A client authenticated with the **data-admin key** — bypasses collection
|
|
4719
|
+
* security (owner/group/claim grants do not apply) and can write protected
|
|
4720
|
+
* collections. Throws `SDK_ADMIN_KEY_REQUIRED` when no admin key is configured.
|
|
4721
|
+
*/
|
|
4722
|
+
asAdmin() {
|
|
4723
|
+
return new _RagableServerClient(this.config, "admin");
|
|
4724
|
+
}
|
|
4725
|
+
/**
|
|
4726
|
+
* A client scoped to the invoking end user's identity (respects collection
|
|
4727
|
+
* security). This is already the default; use it to drop back from `asAdmin()`.
|
|
4728
|
+
*/
|
|
4729
|
+
asCaller() {
|
|
4730
|
+
return new _RagableServerClient(this.config, "caller");
|
|
4731
|
+
}
|
|
4732
|
+
};
|
|
4733
|
+
function createServerClient(config) {
|
|
4734
|
+
return new RagableServerClient(
|
|
4735
|
+
config,
|
|
4736
|
+
config.defaultPrivilege ?? "caller"
|
|
4737
|
+
);
|
|
4738
|
+
}
|
|
4739
|
+
|
|
4653
4740
|
// src/index.ts
|
|
4654
4741
|
function createClient(options) {
|
|
4655
4742
|
return createBrowserClient(options);
|
|
@@ -4687,6 +4774,7 @@ function createClient(options) {
|
|
|
4687
4774
|
RagableError,
|
|
4688
4775
|
RagableNetworkError,
|
|
4689
4776
|
RagableSdkError,
|
|
4777
|
+
RagableServerClient,
|
|
4690
4778
|
RagableTimeoutError,
|
|
4691
4779
|
SessionStorageAdapter,
|
|
4692
4780
|
Transport,
|
|
@@ -4701,6 +4789,7 @@ function createClient(options) {
|
|
|
4701
4789
|
createBrowserClient,
|
|
4702
4790
|
createClient,
|
|
4703
4791
|
createRagableBrowserClient,
|
|
4792
|
+
createServerClient,
|
|
4704
4793
|
createStreamResultFromParts,
|
|
4705
4794
|
detectStorage,
|
|
4706
4795
|
effectiveDataAuth,
|