@realtimex/sdk 1.3.5-rc.2 → 1.3.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
@@ -1383,6 +1383,88 @@ declare class ContractRuntime implements ContractRuntimeInterface {
1383
1383
  private toFailedResult;
1384
1384
  }
1385
1385
 
1386
+ /**
1387
+ * Database Module - Retrieve Supabase config from RealtimeX Main App
1388
+ *
1389
+ * Allows Local Apps to fetch their database configuration (URL, anonKey, mode)
1390
+ * without hardcoding them.
1391
+ */
1392
+ interface DatabaseConfig {
1393
+ url: string;
1394
+ anonKey: string;
1395
+ mode: 'compatible' | 'custom';
1396
+ tables: string[];
1397
+ max_concurrent_tasks: number;
1398
+ }
1399
+ declare class DatabaseModule {
1400
+ private baseUrl;
1401
+ private appId;
1402
+ private apiKey?;
1403
+ constructor(realtimexUrl: string, appId: string, apiKey?: string);
1404
+ private getHeaders;
1405
+ /**
1406
+ * Get the Supabase database configuration for this app.
1407
+ * Returns URL, anonKey, mode, and tables.
1408
+ *
1409
+ * @example
1410
+ * ```ts
1411
+ * const config = await sdk.database.getConfig();
1412
+ * const supabase = createClient(config.url, config.anonKey);
1413
+ * ```
1414
+ */
1415
+ getConfig(): Promise<DatabaseConfig>;
1416
+ }
1417
+
1418
+ /**
1419
+ * Auth Module - Authentication helpers for RealtimeX SDK
1420
+ *
1421
+ * Provides:
1422
+ * - syncSupabaseToken(): Push Supabase JWT to Main App for RLS-aware operations
1423
+ * - getAccessToken(): Retrieve the Keycloak access token from Main App (existing endpoint)
1424
+ */
1425
+ interface AuthTokenResponse {
1426
+ token: string;
1427
+ hasToken: boolean;
1428
+ syncedAt: string | null;
1429
+ source: string | null;
1430
+ }
1431
+ interface SyncTokenResponse {
1432
+ success: boolean;
1433
+ message: string;
1434
+ hasToken: boolean;
1435
+ syncedAt: string | null;
1436
+ source: string | null;
1437
+ }
1438
+ declare class AuthModule {
1439
+ private baseUrl;
1440
+ private appId;
1441
+ private apiKey?;
1442
+ constructor(realtimexUrl: string, appId: string, apiKey?: string);
1443
+ private getHeaders;
1444
+ /**
1445
+ * Push a Supabase access token to the Main App.
1446
+ * This enables Main App to use the token for:
1447
+ * - Realtime subscriptions (bypass RLS)
1448
+ * - CRUD operations on rtx_activities (bypass RLS)
1449
+ *
1450
+ * @param token - Supabase JWT from supabase.auth.signIn()
1451
+ *
1452
+ * @example
1453
+ * ```ts
1454
+ * const { data } = await supabase.auth.signInWithPassword({ email, password });
1455
+ * await sdk.auth.syncSupabaseToken(data.session.access_token);
1456
+ * ```
1457
+ */
1458
+ syncSupabaseToken(token: string): Promise<SyncTokenResponse>;
1459
+ /**
1460
+ * Retrieve the current Keycloak access token from Main App.
1461
+ * This is the existing Token Vending Machine endpoint.
1462
+ *
1463
+ * @returns The access token info, or null if no token is available.
1464
+ */
1465
+ getAccessToken(): Promise<AuthTokenResponse | null>;
1466
+ }
1467
+
1386
1468
  interface ContractHttpClientConfig {
1387
1469
  baseUrl: string;
1388
1470
  appId?: string;
@@ -1707,6 +1789,8 @@ declare class RealtimeXSDK {
1707
1789
  mcp: MCPModule;
1708
1790
  contract: ContractModule;
1709
1791
  contractRuntime: ContractRuntime;
1792
+ database: DatabaseModule;
1793
+ auth: AuthModule;
1710
1794
  readonly appId: string;
1711
1795
  readonly appName: string | undefined;
1712
1796
  readonly apiKey: string | undefined;
@@ -1741,4 +1825,4 @@ declare class RealtimeXSDK {
1741
1825
  getAppDataDir(): Promise<string>;
1742
1826
  }
1743
1827
 
1744
- export { type ACPAdapterContext, type ACPAdapterTelemetryEvent, type ACPAdapterTelemetrySink, ACPContractAdapter, type ACPContractAdapterOptions, type ACPContractRuntime, ACPEventMapper, type ACPExecutionReference, type ACPNotifier, ACPPermissionBridge, type ACPSessionToolUpdate, type ACPSessionUpdateParams, ACPTelemetry, type ACPTextContent, type ACPToolInvocation, type ACPToolKind, type ACPToolStatus, ActivitiesModule, type Activity, type Agent, type AgentChatOptions, type AgentChatResponse, AgentModule, type AgentSession, type AgentSessionInfo, type AgentSessionOptions, ApiModule, type AuthProvider, CONTRACT_ATTEMPT_PREFIX, CONTRACT_EVENT_ID_HEADER, CONTRACT_SIGNATURE_ALGORITHM, CONTRACT_SIGNATURE_HEADER, type CanonicalToolDefinition, type ChatContentBlock, type ChatCustomBlock, type ChatFileBlock, type ChatImageUrlBlock, type ChatMessage, type ChatMessageContent, type ChatOptions, type ChatResponse, type ChatTextBlock, ClaudeToolAdapter, type ClaudeToolCall, type ClaudeToolDefinition, type ClaudeToolResult, CodexToolAdapter, type CodexToolCall, type CodexToolDefinition, type CodexToolResult, ContractCache, type ContractCallbackMetadata, type ContractCallbackRules, type ContractCapability, type ContractCapabilityTrigger, ContractClient, type ContractClientOptions, type ContractDiscoveryResponse, ContractError, type ContractEventType, ContractHttpClient, type ContractHttpClientConfig, ContractModule, ContractRuntime, type ContractRuntimeInterface, type ContractRuntimeOptions, type ContractSignInput, type ContractStrictness, ContractValidationError, type EmbedOptions, type EmbedResponse, type ExecutionContext, type ExecutionResult, type GeminiFunctionDeclaration, GeminiToolAdapter, type GeminiToolCall, type GeminiToolResult, type GetToolsInput, type HostToolAdapter, type IngestExecutionEventInput, LLMModule, LLMPermissionError, LLMProviderError, LOCAL_APP_CONTRACT_VERSION, type LegacyLocalAppContractShape, type LifecycleEventType, type LocalAppContractDefinition, type LocalAppContractResponse, type LocalAppContractV1, MCPModule, type MCPServer, type MCPTool, type MCPToolResult, PermissionDeniedError, type PermissionOption, PermissionRequiredError, PortModule, type ProjectToolsInput, type Provider, type ProviderKind, type ProvidersResponse, RealtimeXSDK, RetryPolicy, type RetryPolicyOptions, type RuntimeExecutionEvent, RuntimeTransportError, type SDKConfig, type STTListenOptions, type STTModel, type STTModelsResponse, STTModule, type STTProvider, type STTProvidersResponse, type STTResponse, ScopeDeniedError, ScopeGuard, StaticAuthProvider, type StaticAuthProviderOptions, type StreamChunk, type StreamChunkEvent, type TTSChunk, type TTSChunkEvent, TTSModule, type TTSOptions, type TTSProvider, type TTSProviderConfig, type TTSProvidersResponse, type Task, TaskModule, type TaskRun, type Thread, type ToolCall, ToolNotFoundError, ToolProjector, ToolValidationError, type TriggerAgentPayload, type TriggerAgentResponse, type VectorDeleteOptions, type VectorDeleteResponse, type VectorQueryOptions, type VectorQueryResponse, type VectorQueryResult, type VectorRecord, VectorStore, type VectorUpsertOptions, type VectorUpsertResponse, WebhookModule, type Workspace, buildContractIdempotencyKey, buildContractSignatureMessage, canonicalEventToLegacyAction, createContractEventId, hashContractPayload, normalizeAttemptId, normalizeContractEvent, normalizeLocalAppContractV1, normalizeSchema, parseAttemptRunId, signContractEvent, toStableToolName };
1828
+ export { type ACPAdapterContext, type ACPAdapterTelemetryEvent, type ACPAdapterTelemetrySink, ACPContractAdapter, type ACPContractAdapterOptions, type ACPContractRuntime, ACPEventMapper, type ACPExecutionReference, type ACPNotifier, ACPPermissionBridge, type ACPSessionToolUpdate, type ACPSessionUpdateParams, ACPTelemetry, type ACPTextContent, type ACPToolInvocation, type ACPToolKind, type ACPToolStatus, ActivitiesModule, type Activity, type Agent, type AgentChatOptions, type AgentChatResponse, AgentModule, type AgentSession, type AgentSessionInfo, type AgentSessionOptions, ApiModule, AuthModule, type AuthProvider, type AuthTokenResponse, CONTRACT_ATTEMPT_PREFIX, CONTRACT_EVENT_ID_HEADER, CONTRACT_SIGNATURE_ALGORITHM, CONTRACT_SIGNATURE_HEADER, type CanonicalToolDefinition, type ChatContentBlock, type ChatCustomBlock, type ChatFileBlock, type ChatImageUrlBlock, type ChatMessage, type ChatMessageContent, type ChatOptions, type ChatResponse, type ChatTextBlock, ClaudeToolAdapter, type ClaudeToolCall, type ClaudeToolDefinition, type ClaudeToolResult, CodexToolAdapter, type CodexToolCall, type CodexToolDefinition, type CodexToolResult, ContractCache, type ContractCallbackMetadata, type ContractCallbackRules, type ContractCapability, type ContractCapabilityTrigger, ContractClient, type ContractClientOptions, type ContractDiscoveryResponse, ContractError, type ContractEventType, ContractHttpClient, type ContractHttpClientConfig, ContractModule, ContractRuntime, type ContractRuntimeInterface, type ContractRuntimeOptions, type ContractSignInput, type ContractStrictness, ContractValidationError, type DatabaseConfig, DatabaseModule, type EmbedOptions, type EmbedResponse, type ExecutionContext, type ExecutionResult, type GeminiFunctionDeclaration, GeminiToolAdapter, type GeminiToolCall, type GeminiToolResult, type GetToolsInput, type HostToolAdapter, type IngestExecutionEventInput, LLMModule, LLMPermissionError, LLMProviderError, LOCAL_APP_CONTRACT_VERSION, type LegacyLocalAppContractShape, type LifecycleEventType, type LocalAppContractDefinition, type LocalAppContractResponse, type LocalAppContractV1, MCPModule, type MCPServer, type MCPTool, type MCPToolResult, PermissionDeniedError, type PermissionOption, PermissionRequiredError, PortModule, type ProjectToolsInput, type Provider, type ProviderKind, type ProvidersResponse, RealtimeXSDK, RetryPolicy, type RetryPolicyOptions, type RuntimeExecutionEvent, RuntimeTransportError, type SDKConfig, type STTListenOptions, type STTModel, type STTModelsResponse, STTModule, type STTProvider, type STTProvidersResponse, type STTResponse, ScopeDeniedError, ScopeGuard, StaticAuthProvider, type StaticAuthProviderOptions, type StreamChunk, type StreamChunkEvent, type SyncTokenResponse, type TTSChunk, type TTSChunkEvent, TTSModule, type TTSOptions, type TTSProvider, type TTSProviderConfig, type TTSProvidersResponse, type Task, TaskModule, type TaskRun, type Thread, type ToolCall, ToolNotFoundError, ToolProjector, ToolValidationError, type TriggerAgentPayload, type TriggerAgentResponse, type VectorDeleteOptions, type VectorDeleteResponse, type VectorQueryOptions, type VectorQueryResponse, type VectorQueryResult, type VectorRecord, VectorStore, type VectorUpsertOptions, type VectorUpsertResponse, WebhookModule, type Workspace, buildContractIdempotencyKey, buildContractSignatureMessage, canonicalEventToLegacyAction, createContractEventId, hashContractPayload, normalizeAttemptId, normalizeContractEvent, normalizeLocalAppContractV1, normalizeSchema, parseAttemptRunId, signContractEvent, toStableToolName };
package/dist/index.d.ts CHANGED
@@ -1383,6 +1383,88 @@ declare class ContractRuntime implements ContractRuntimeInterface {
1383
1383
  private toFailedResult;
1384
1384
  }
1385
1385
 
1386
+ /**
1387
+ * Database Module - Retrieve Supabase config from RealtimeX Main App
1388
+ *
1389
+ * Allows Local Apps to fetch their database configuration (URL, anonKey, mode)
1390
+ * without hardcoding them.
1391
+ */
1392
+ interface DatabaseConfig {
1393
+ url: string;
1394
+ anonKey: string;
1395
+ mode: 'compatible' | 'custom';
1396
+ tables: string[];
1397
+ max_concurrent_tasks: number;
1398
+ }
1399
+ declare class DatabaseModule {
1400
+ private baseUrl;
1401
+ private appId;
1402
+ private apiKey?;
1403
+ constructor(realtimexUrl: string, appId: string, apiKey?: string);
1404
+ private getHeaders;
1405
+ /**
1406
+ * Get the Supabase database configuration for this app.
1407
+ * Returns URL, anonKey, mode, and tables.
1408
+ *
1409
+ * @example
1410
+ * ```ts
1411
+ * const config = await sdk.database.getConfig();
1412
+ * const supabase = createClient(config.url, config.anonKey);
1413
+ * ```
1414
+ */
1415
+ getConfig(): Promise<DatabaseConfig>;
1416
+ }
1417
+
1418
+ /**
1419
+ * Auth Module - Authentication helpers for RealtimeX SDK
1420
+ *
1421
+ * Provides:
1422
+ * - syncSupabaseToken(): Push Supabase JWT to Main App for RLS-aware operations
1423
+ * - getAccessToken(): Retrieve the Keycloak access token from Main App (existing endpoint)
1424
+ */
1425
+ interface AuthTokenResponse {
1426
+ token: string;
1427
+ hasToken: boolean;
1428
+ syncedAt: string | null;
1429
+ source: string | null;
1430
+ }
1431
+ interface SyncTokenResponse {
1432
+ success: boolean;
1433
+ message: string;
1434
+ hasToken: boolean;
1435
+ syncedAt: string | null;
1436
+ source: string | null;
1437
+ }
1438
+ declare class AuthModule {
1439
+ private baseUrl;
1440
+ private appId;
1441
+ private apiKey?;
1442
+ constructor(realtimexUrl: string, appId: string, apiKey?: string);
1443
+ private getHeaders;
1444
+ /**
1445
+ * Push a Supabase access token to the Main App.
1446
+ * This enables Main App to use the token for:
1447
+ * - Realtime subscriptions (bypass RLS)
1448
+ * - CRUD operations on rtx_activities (bypass RLS)
1449
+ *
1450
+ * @param token - Supabase JWT from supabase.auth.signIn()
1451
+ *
1452
+ * @example
1453
+ * ```ts
1454
+ * const { data } = await supabase.auth.signInWithPassword({ email, password });
1455
+ * await sdk.auth.syncSupabaseToken(data.session.access_token);
1456
+ * ```
1457
+ */
1458
+ syncSupabaseToken(token: string): Promise<SyncTokenResponse>;
1459
+ /**
1460
+ * Retrieve the current Keycloak access token from Main App.
1461
+ * This is the existing Token Vending Machine endpoint.
1462
+ *
1463
+ * @returns The access token info, or null if no token is available.
1464
+ */
1465
+ getAccessToken(): Promise<AuthTokenResponse | null>;
1466
+ }
1467
+
1386
1468
  interface ContractHttpClientConfig {
1387
1469
  baseUrl: string;
1388
1470
  appId?: string;
@@ -1707,6 +1789,8 @@ declare class RealtimeXSDK {
1707
1789
  mcp: MCPModule;
1708
1790
  contract: ContractModule;
1709
1791
  contractRuntime: ContractRuntime;
1792
+ database: DatabaseModule;
1793
+ auth: AuthModule;
1710
1794
  readonly appId: string;
1711
1795
  readonly appName: string | undefined;
1712
1796
  readonly apiKey: string | undefined;
@@ -1741,4 +1825,4 @@ declare class RealtimeXSDK {
1741
1825
  getAppDataDir(): Promise<string>;
1742
1826
  }
1743
1827
 
1744
- export { type ACPAdapterContext, type ACPAdapterTelemetryEvent, type ACPAdapterTelemetrySink, ACPContractAdapter, type ACPContractAdapterOptions, type ACPContractRuntime, ACPEventMapper, type ACPExecutionReference, type ACPNotifier, ACPPermissionBridge, type ACPSessionToolUpdate, type ACPSessionUpdateParams, ACPTelemetry, type ACPTextContent, type ACPToolInvocation, type ACPToolKind, type ACPToolStatus, ActivitiesModule, type Activity, type Agent, type AgentChatOptions, type AgentChatResponse, AgentModule, type AgentSession, type AgentSessionInfo, type AgentSessionOptions, ApiModule, type AuthProvider, CONTRACT_ATTEMPT_PREFIX, CONTRACT_EVENT_ID_HEADER, CONTRACT_SIGNATURE_ALGORITHM, CONTRACT_SIGNATURE_HEADER, type CanonicalToolDefinition, type ChatContentBlock, type ChatCustomBlock, type ChatFileBlock, type ChatImageUrlBlock, type ChatMessage, type ChatMessageContent, type ChatOptions, type ChatResponse, type ChatTextBlock, ClaudeToolAdapter, type ClaudeToolCall, type ClaudeToolDefinition, type ClaudeToolResult, CodexToolAdapter, type CodexToolCall, type CodexToolDefinition, type CodexToolResult, ContractCache, type ContractCallbackMetadata, type ContractCallbackRules, type ContractCapability, type ContractCapabilityTrigger, ContractClient, type ContractClientOptions, type ContractDiscoveryResponse, ContractError, type ContractEventType, ContractHttpClient, type ContractHttpClientConfig, ContractModule, ContractRuntime, type ContractRuntimeInterface, type ContractRuntimeOptions, type ContractSignInput, type ContractStrictness, ContractValidationError, type EmbedOptions, type EmbedResponse, type ExecutionContext, type ExecutionResult, type GeminiFunctionDeclaration, GeminiToolAdapter, type GeminiToolCall, type GeminiToolResult, type GetToolsInput, type HostToolAdapter, type IngestExecutionEventInput, LLMModule, LLMPermissionError, LLMProviderError, LOCAL_APP_CONTRACT_VERSION, type LegacyLocalAppContractShape, type LifecycleEventType, type LocalAppContractDefinition, type LocalAppContractResponse, type LocalAppContractV1, MCPModule, type MCPServer, type MCPTool, type MCPToolResult, PermissionDeniedError, type PermissionOption, PermissionRequiredError, PortModule, type ProjectToolsInput, type Provider, type ProviderKind, type ProvidersResponse, RealtimeXSDK, RetryPolicy, type RetryPolicyOptions, type RuntimeExecutionEvent, RuntimeTransportError, type SDKConfig, type STTListenOptions, type STTModel, type STTModelsResponse, STTModule, type STTProvider, type STTProvidersResponse, type STTResponse, ScopeDeniedError, ScopeGuard, StaticAuthProvider, type StaticAuthProviderOptions, type StreamChunk, type StreamChunkEvent, type TTSChunk, type TTSChunkEvent, TTSModule, type TTSOptions, type TTSProvider, type TTSProviderConfig, type TTSProvidersResponse, type Task, TaskModule, type TaskRun, type Thread, type ToolCall, ToolNotFoundError, ToolProjector, ToolValidationError, type TriggerAgentPayload, type TriggerAgentResponse, type VectorDeleteOptions, type VectorDeleteResponse, type VectorQueryOptions, type VectorQueryResponse, type VectorQueryResult, type VectorRecord, VectorStore, type VectorUpsertOptions, type VectorUpsertResponse, WebhookModule, type Workspace, buildContractIdempotencyKey, buildContractSignatureMessage, canonicalEventToLegacyAction, createContractEventId, hashContractPayload, normalizeAttemptId, normalizeContractEvent, normalizeLocalAppContractV1, normalizeSchema, parseAttemptRunId, signContractEvent, toStableToolName };
1828
+ export { type ACPAdapterContext, type ACPAdapterTelemetryEvent, type ACPAdapterTelemetrySink, ACPContractAdapter, type ACPContractAdapterOptions, type ACPContractRuntime, ACPEventMapper, type ACPExecutionReference, type ACPNotifier, ACPPermissionBridge, type ACPSessionToolUpdate, type ACPSessionUpdateParams, ACPTelemetry, type ACPTextContent, type ACPToolInvocation, type ACPToolKind, type ACPToolStatus, ActivitiesModule, type Activity, type Agent, type AgentChatOptions, type AgentChatResponse, AgentModule, type AgentSession, type AgentSessionInfo, type AgentSessionOptions, ApiModule, AuthModule, type AuthProvider, type AuthTokenResponse, CONTRACT_ATTEMPT_PREFIX, CONTRACT_EVENT_ID_HEADER, CONTRACT_SIGNATURE_ALGORITHM, CONTRACT_SIGNATURE_HEADER, type CanonicalToolDefinition, type ChatContentBlock, type ChatCustomBlock, type ChatFileBlock, type ChatImageUrlBlock, type ChatMessage, type ChatMessageContent, type ChatOptions, type ChatResponse, type ChatTextBlock, ClaudeToolAdapter, type ClaudeToolCall, type ClaudeToolDefinition, type ClaudeToolResult, CodexToolAdapter, type CodexToolCall, type CodexToolDefinition, type CodexToolResult, ContractCache, type ContractCallbackMetadata, type ContractCallbackRules, type ContractCapability, type ContractCapabilityTrigger, ContractClient, type ContractClientOptions, type ContractDiscoveryResponse, ContractError, type ContractEventType, ContractHttpClient, type ContractHttpClientConfig, ContractModule, ContractRuntime, type ContractRuntimeInterface, type ContractRuntimeOptions, type ContractSignInput, type ContractStrictness, ContractValidationError, type DatabaseConfig, DatabaseModule, type EmbedOptions, type EmbedResponse, type ExecutionContext, type ExecutionResult, type GeminiFunctionDeclaration, GeminiToolAdapter, type GeminiToolCall, type GeminiToolResult, type GetToolsInput, type HostToolAdapter, type IngestExecutionEventInput, LLMModule, LLMPermissionError, LLMProviderError, LOCAL_APP_CONTRACT_VERSION, type LegacyLocalAppContractShape, type LifecycleEventType, type LocalAppContractDefinition, type LocalAppContractResponse, type LocalAppContractV1, MCPModule, type MCPServer, type MCPTool, type MCPToolResult, PermissionDeniedError, type PermissionOption, PermissionRequiredError, PortModule, type ProjectToolsInput, type Provider, type ProviderKind, type ProvidersResponse, RealtimeXSDK, RetryPolicy, type RetryPolicyOptions, type RuntimeExecutionEvent, RuntimeTransportError, type SDKConfig, type STTListenOptions, type STTModel, type STTModelsResponse, STTModule, type STTProvider, type STTProvidersResponse, type STTResponse, ScopeDeniedError, ScopeGuard, StaticAuthProvider, type StaticAuthProviderOptions, type StreamChunk, type StreamChunkEvent, type SyncTokenResponse, type TTSChunk, type TTSChunkEvent, TTSModule, type TTSOptions, type TTSProvider, type TTSProviderConfig, type TTSProvidersResponse, type Task, TaskModule, type TaskRun, type Thread, type ToolCall, ToolNotFoundError, ToolProjector, ToolValidationError, type TriggerAgentPayload, type TriggerAgentResponse, type VectorDeleteOptions, type VectorDeleteResponse, type VectorQueryOptions, type VectorQueryResponse, type VectorQueryResult, type VectorRecord, VectorStore, type VectorUpsertOptions, type VectorUpsertResponse, WebhookModule, type Workspace, buildContractIdempotencyKey, buildContractSignatureMessage, canonicalEventToLegacyAction, createContractEventId, hashContractPayload, normalizeAttemptId, normalizeContractEvent, normalizeLocalAppContractV1, normalizeSchema, parseAttemptRunId, signContractEvent, toStableToolName };
package/dist/index.js CHANGED
@@ -37,6 +37,7 @@ __export(index_exports, {
37
37
  ActivitiesModule: () => ActivitiesModule,
38
38
  AgentModule: () => AgentModule,
39
39
  ApiModule: () => ApiModule,
40
+ AuthModule: () => AuthModule,
40
41
  CONTRACT_ATTEMPT_PREFIX: () => CONTRACT_ATTEMPT_PREFIX,
41
42
  CONTRACT_EVENT_ID_HEADER: () => CONTRACT_EVENT_ID_HEADER,
42
43
  CONTRACT_SIGNATURE_ALGORITHM: () => CONTRACT_SIGNATURE_ALGORITHM,
@@ -50,6 +51,7 @@ __export(index_exports, {
50
51
  ContractModule: () => ContractModule,
51
52
  ContractRuntime: () => ContractRuntime,
52
53
  ContractValidationError: () => ContractValidationError,
54
+ DatabaseModule: () => DatabaseModule,
53
55
  GeminiToolAdapter: () => GeminiToolAdapter,
54
56
  LLMModule: () => LLMModule,
55
57
  LLMPermissionError: () => LLMPermissionError,
@@ -2621,6 +2623,118 @@ var ContractRuntime = class {
2621
2623
  }
2622
2624
  };
2623
2625
 
2626
+ // src/modules/database.ts
2627
+ var DatabaseModule = class {
2628
+ constructor(realtimexUrl, appId, apiKey) {
2629
+ this.baseUrl = realtimexUrl.replace(/\/$/, "");
2630
+ this.appId = appId;
2631
+ this.apiKey = apiKey;
2632
+ }
2633
+ getHeaders() {
2634
+ const headers = {
2635
+ "Content-Type": "application/json"
2636
+ };
2637
+ if (this.apiKey) {
2638
+ headers["Authorization"] = `Bearer ${this.apiKey}`;
2639
+ }
2640
+ if (this.appId) {
2641
+ headers["x-app-id"] = this.appId;
2642
+ }
2643
+ return headers;
2644
+ }
2645
+ /**
2646
+ * Get the Supabase database configuration for this app.
2647
+ * Returns URL, anonKey, mode, and tables.
2648
+ *
2649
+ * @example
2650
+ * ```ts
2651
+ * const config = await sdk.database.getConfig();
2652
+ * const supabase = createClient(config.url, config.anonKey);
2653
+ * ```
2654
+ */
2655
+ async getConfig() {
2656
+ const response = await fetch(`${this.baseUrl}/sdk/database/config`, {
2657
+ method: "GET",
2658
+ headers: this.getHeaders()
2659
+ });
2660
+ const data = await response.json();
2661
+ if (!response.ok) {
2662
+ throw new Error(data.error || "Failed to get database config");
2663
+ }
2664
+ return data.config;
2665
+ }
2666
+ };
2667
+
2668
+ // src/modules/auth.ts
2669
+ var AuthModule = class {
2670
+ constructor(realtimexUrl, appId, apiKey) {
2671
+ this.baseUrl = realtimexUrl.replace(/\/$/, "");
2672
+ this.appId = appId;
2673
+ this.apiKey = apiKey;
2674
+ }
2675
+ getHeaders() {
2676
+ const headers = {
2677
+ "Content-Type": "application/json"
2678
+ };
2679
+ if (this.apiKey) {
2680
+ headers["Authorization"] = `Bearer ${this.apiKey}`;
2681
+ }
2682
+ if (this.appId) {
2683
+ headers["x-app-id"] = this.appId;
2684
+ }
2685
+ return headers;
2686
+ }
2687
+ /**
2688
+ * Push a Supabase access token to the Main App.
2689
+ * This enables Main App to use the token for:
2690
+ * - Realtime subscriptions (bypass RLS)
2691
+ * - CRUD operations on rtx_activities (bypass RLS)
2692
+ *
2693
+ * @param token - Supabase JWT from supabase.auth.signIn()
2694
+ *
2695
+ * @example
2696
+ * ```ts
2697
+ * const { data } = await supabase.auth.signInWithPassword({ email, password });
2698
+ * await sdk.auth.syncSupabaseToken(data.session.access_token);
2699
+ * ```
2700
+ */
2701
+ async syncSupabaseToken(token) {
2702
+ if (!token || typeof token !== "string") {
2703
+ throw new Error("Token must be a non-empty string");
2704
+ }
2705
+ const response = await fetch(`${this.baseUrl}/sdk/auth/sync-supabase-token`, {
2706
+ method: "POST",
2707
+ headers: this.getHeaders(),
2708
+ body: JSON.stringify({ token })
2709
+ });
2710
+ const data = await response.json();
2711
+ if (!response.ok) {
2712
+ throw new Error(data.error || "Failed to sync Supabase token");
2713
+ }
2714
+ return data;
2715
+ }
2716
+ /**
2717
+ * Retrieve the current Keycloak access token from Main App.
2718
+ * This is the existing Token Vending Machine endpoint.
2719
+ *
2720
+ * @returns The access token info, or null if no token is available.
2721
+ */
2722
+ async getAccessToken() {
2723
+ const response = await fetch(`${this.baseUrl}/sdk/auth/token`, {
2724
+ method: "GET",
2725
+ headers: this.getHeaders()
2726
+ });
2727
+ const data = await response.json();
2728
+ if (response.status === 404) {
2729
+ return null;
2730
+ }
2731
+ if (!response.ok) {
2732
+ throw new Error(data.error || "Failed to get access token");
2733
+ }
2734
+ return data;
2735
+ }
2736
+ };
2737
+
2624
2738
  // src/core/auth/AuthProvider.ts
2625
2739
  var StaticAuthProvider = class {
2626
2740
  constructor(options = {}) {
@@ -3315,6 +3429,8 @@ var _RealtimeXSDK = class _RealtimeXSDK {
3315
3429
  apiKey: this.apiKey,
3316
3430
  permissions: this.permissions
3317
3431
  });
3432
+ this.database = new DatabaseModule(this.realtimexUrl, this.appId, this.apiKey);
3433
+ this.auth = new AuthModule(this.realtimexUrl, this.appId, this.apiKey);
3318
3434
  if (this.permissions.length > 0 && this.appId && !this.apiKey) {
3319
3435
  this.register().catch((err) => {
3320
3436
  console.error("[RealtimeX SDK] Auto-registration failed:", err.message);
@@ -3423,6 +3539,7 @@ var RealtimeXSDK = _RealtimeXSDK;
3423
3539
  ActivitiesModule,
3424
3540
  AgentModule,
3425
3541
  ApiModule,
3542
+ AuthModule,
3426
3543
  CONTRACT_ATTEMPT_PREFIX,
3427
3544
  CONTRACT_EVENT_ID_HEADER,
3428
3545
  CONTRACT_SIGNATURE_ALGORITHM,
@@ -3436,6 +3553,7 @@ var RealtimeXSDK = _RealtimeXSDK;
3436
3553
  ContractModule,
3437
3554
  ContractRuntime,
3438
3555
  ContractValidationError,
3556
+ DatabaseModule,
3439
3557
  GeminiToolAdapter,
3440
3558
  LLMModule,
3441
3559
  LLMPermissionError,
package/dist/index.mjs CHANGED
@@ -2531,6 +2531,118 @@ var ContractRuntime = class {
2531
2531
  }
2532
2532
  };
2533
2533
 
2534
+ // src/modules/database.ts
2535
+ var DatabaseModule = class {
2536
+ constructor(realtimexUrl, appId, apiKey) {
2537
+ this.baseUrl = realtimexUrl.replace(/\/$/, "");
2538
+ this.appId = appId;
2539
+ this.apiKey = apiKey;
2540
+ }
2541
+ getHeaders() {
2542
+ const headers = {
2543
+ "Content-Type": "application/json"
2544
+ };
2545
+ if (this.apiKey) {
2546
+ headers["Authorization"] = `Bearer ${this.apiKey}`;
2547
+ }
2548
+ if (this.appId) {
2549
+ headers["x-app-id"] = this.appId;
2550
+ }
2551
+ return headers;
2552
+ }
2553
+ /**
2554
+ * Get the Supabase database configuration for this app.
2555
+ * Returns URL, anonKey, mode, and tables.
2556
+ *
2557
+ * @example
2558
+ * ```ts
2559
+ * const config = await sdk.database.getConfig();
2560
+ * const supabase = createClient(config.url, config.anonKey);
2561
+ * ```
2562
+ */
2563
+ async getConfig() {
2564
+ const response = await fetch(`${this.baseUrl}/sdk/database/config`, {
2565
+ method: "GET",
2566
+ headers: this.getHeaders()
2567
+ });
2568
+ const data = await response.json();
2569
+ if (!response.ok) {
2570
+ throw new Error(data.error || "Failed to get database config");
2571
+ }
2572
+ return data.config;
2573
+ }
2574
+ };
2575
+
2576
+ // src/modules/auth.ts
2577
+ var AuthModule = class {
2578
+ constructor(realtimexUrl, appId, apiKey) {
2579
+ this.baseUrl = realtimexUrl.replace(/\/$/, "");
2580
+ this.appId = appId;
2581
+ this.apiKey = apiKey;
2582
+ }
2583
+ getHeaders() {
2584
+ const headers = {
2585
+ "Content-Type": "application/json"
2586
+ };
2587
+ if (this.apiKey) {
2588
+ headers["Authorization"] = `Bearer ${this.apiKey}`;
2589
+ }
2590
+ if (this.appId) {
2591
+ headers["x-app-id"] = this.appId;
2592
+ }
2593
+ return headers;
2594
+ }
2595
+ /**
2596
+ * Push a Supabase access token to the Main App.
2597
+ * This enables Main App to use the token for:
2598
+ * - Realtime subscriptions (bypass RLS)
2599
+ * - CRUD operations on rtx_activities (bypass RLS)
2600
+ *
2601
+ * @param token - Supabase JWT from supabase.auth.signIn()
2602
+ *
2603
+ * @example
2604
+ * ```ts
2605
+ * const { data } = await supabase.auth.signInWithPassword({ email, password });
2606
+ * await sdk.auth.syncSupabaseToken(data.session.access_token);
2607
+ * ```
2608
+ */
2609
+ async syncSupabaseToken(token) {
2610
+ if (!token || typeof token !== "string") {
2611
+ throw new Error("Token must be a non-empty string");
2612
+ }
2613
+ const response = await fetch(`${this.baseUrl}/sdk/auth/sync-supabase-token`, {
2614
+ method: "POST",
2615
+ headers: this.getHeaders(),
2616
+ body: JSON.stringify({ token })
2617
+ });
2618
+ const data = await response.json();
2619
+ if (!response.ok) {
2620
+ throw new Error(data.error || "Failed to sync Supabase token");
2621
+ }
2622
+ return data;
2623
+ }
2624
+ /**
2625
+ * Retrieve the current Keycloak access token from Main App.
2626
+ * This is the existing Token Vending Machine endpoint.
2627
+ *
2628
+ * @returns The access token info, or null if no token is available.
2629
+ */
2630
+ async getAccessToken() {
2631
+ const response = await fetch(`${this.baseUrl}/sdk/auth/token`, {
2632
+ method: "GET",
2633
+ headers: this.getHeaders()
2634
+ });
2635
+ const data = await response.json();
2636
+ if (response.status === 404) {
2637
+ return null;
2638
+ }
2639
+ if (!response.ok) {
2640
+ throw new Error(data.error || "Failed to get access token");
2641
+ }
2642
+ return data;
2643
+ }
2644
+ };
2645
+
2534
2646
  // src/core/auth/AuthProvider.ts
2535
2647
  var StaticAuthProvider = class {
2536
2648
  constructor(options = {}) {
@@ -3225,6 +3337,8 @@ var _RealtimeXSDK = class _RealtimeXSDK {
3225
3337
  apiKey: this.apiKey,
3226
3338
  permissions: this.permissions
3227
3339
  });
3340
+ this.database = new DatabaseModule(this.realtimexUrl, this.appId, this.apiKey);
3341
+ this.auth = new AuthModule(this.realtimexUrl, this.appId, this.apiKey);
3228
3342
  if (this.permissions.length > 0 && this.appId && !this.apiKey) {
3229
3343
  this.register().catch((err) => {
3230
3344
  console.error("[RealtimeX SDK] Auto-registration failed:", err.message);
@@ -3332,6 +3446,7 @@ export {
3332
3446
  ActivitiesModule,
3333
3447
  AgentModule,
3334
3448
  ApiModule,
3449
+ AuthModule,
3335
3450
  CONTRACT_ATTEMPT_PREFIX,
3336
3451
  CONTRACT_EVENT_ID_HEADER,
3337
3452
  CONTRACT_SIGNATURE_ALGORITHM,
@@ -3345,6 +3460,7 @@ export {
3345
3460
  ContractModule,
3346
3461
  ContractRuntime,
3347
3462
  ContractValidationError,
3463
+ DatabaseModule,
3348
3464
  GeminiToolAdapter,
3349
3465
  LLMModule,
3350
3466
  LLMPermissionError,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@realtimex/sdk",
3
- "version": "1.3.5-rc.2",
3
+ "version": "1.3.6",
4
4
  "description": "SDK for building Local Apps that integrate with RealtimeX",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",