@resultdev/sdk 0.1.0 → 0.3.0

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.
@@ -0,0 +1,672 @@
1
+ /**
2
+ * Web analytics module for the Result SDK.
3
+ *
4
+ * Full parity with the Result `wa.js` script tracker, so apps that install
5
+ * the SDK need no <script> tag. No cookies and no fingerprinting: a random
6
+ * visitor id in localStorage and a session id that rotates after 30 idle
7
+ * minutes. Tracks pageviews (SPA route changes included), pageleaves, and
8
+ * custom events.
9
+ *
10
+ * The wire format is shared with wa.js — do not change field names or
11
+ * storage keys without updating the ingest endpoint.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * const client = createClient({
16
+ * baseUrl,
17
+ * anonKey,
18
+ * analytics: { siteId: 'YOUR_SITE_ID' },
19
+ * });
20
+ *
21
+ * // Pageviews are automatic (SPA navigation included). Custom events:
22
+ * client.analytics.track('Signup', { plan: 'pro' });
23
+ * client.analytics.identify('user-123');
24
+ * ```
25
+ */
26
+ interface AnalyticsOptions {
27
+ /** The site id from your Result analytics dashboard. */
28
+ siteId: string;
29
+ /**
30
+ * Ingest endpoint. Only needed when self-hosting the dashboard.
31
+ * @default "https://beta.result.dev/api/wa"
32
+ */
33
+ endpoint?: string;
34
+ /**
35
+ * Automatically track pageviews and SPA route changes.
36
+ * @default true
37
+ */
38
+ autoTrack?: boolean;
39
+ /** Only track on these hostnames (www. is ignored). */
40
+ domains?: string[];
41
+ /** Drop ?query from tracked URLs. */
42
+ excludeSearch?: boolean;
43
+ /** Drop #hash from tracked URLs. */
44
+ excludeHash?: boolean;
45
+ }
46
+ interface RwaGlobal {
47
+ track: (name: string, props?: Record<string, unknown>) => void;
48
+ identify: (id: string) => void;
49
+ }
50
+ declare global {
51
+ interface Window {
52
+ /** Set by wa.js or by this module — whichever loads first wins. */
53
+ rwa?: RwaGlobal;
54
+ }
55
+ }
56
+ declare class Analytics {
57
+ private siteId;
58
+ private endpoint;
59
+ private options;
60
+ private active;
61
+ private lastUrl;
62
+ private left;
63
+ private referrer;
64
+ private mem;
65
+ constructor(options: AnalyticsOptions | undefined);
66
+ /** Send a custom event. No-op outside the browser or when inactive. */
67
+ track(name: string, props?: Record<string, unknown>): void;
68
+ /** Attach your own user id to subsequent events. */
69
+ identify(id: string): void;
70
+ private read;
71
+ private write;
72
+ private visitor;
73
+ private session;
74
+ private pageUrl;
75
+ private post;
76
+ private pageview;
77
+ private pageleave;
78
+ private start;
79
+ }
80
+
81
+ /**
82
+ * Customer support module for the Result SDK (visitor side).
83
+ *
84
+ * Lets an app embed a contact/support flow whose conversations land in the
85
+ * owner's Result support inbox. There are no visitor accounts: starting a
86
+ * thread returns a per-thread access key, which this module persists in
87
+ * localStorage (browser) or in memory (server) and uses to read the thread
88
+ * and send replies. Visitors also get email notifications with a deep link
89
+ * to the owner's public support page.
90
+ *
91
+ * @example
92
+ * ```typescript
93
+ * const client = createClient({
94
+ * baseUrl,
95
+ * anonKey,
96
+ * support: { handle: 'acme' }, // your Result @handle
97
+ * });
98
+ *
99
+ * const { data: thread } = await client.support.startThread({
100
+ * email: 'visitor@example.com',
101
+ * message: 'Hi, I need help with my order.',
102
+ * });
103
+ *
104
+ * const { data } = await client.support.getThread(thread.id);
105
+ * await client.support.sendMessage(thread.id, 'Any update?');
106
+ * ```
107
+ */
108
+ interface SupportOptions {
109
+ /** The business @handle on Result (without the @). */
110
+ handle: string;
111
+ /**
112
+ * Support API origin. Only needed when self-hosting.
113
+ * @default "https://beta.result.dev"
114
+ */
115
+ endpoint?: string;
116
+ }
117
+ interface StartThreadOptions {
118
+ /** Visitor email — used for reply notifications. */
119
+ email: string;
120
+ /** Visitor display name. */
121
+ name?: string;
122
+ /** The first message. */
123
+ message: string;
124
+ }
125
+ interface SupportMessage {
126
+ id: string;
127
+ body: string;
128
+ authorType: "visitor" | "owner";
129
+ createdAt: number;
130
+ }
131
+ interface SupportThread {
132
+ id: string;
133
+ status: "open" | "closed";
134
+ visitorEmail: string;
135
+ visitorName?: string;
136
+ createdAt: number;
137
+ lastMessageAt: number;
138
+ owner: {
139
+ name?: string;
140
+ username?: string;
141
+ };
142
+ messages: SupportMessage[];
143
+ }
144
+ interface StartedThread {
145
+ id: string;
146
+ /** Per-thread credential. Persisted by the SDK; keep it if you store threads yourself. */
147
+ accessKey: string;
148
+ }
149
+ type SupportResult<T> = Promise<{
150
+ data: T | null;
151
+ error: ResultError | null;
152
+ }>;
153
+ declare class Support {
154
+ private handle;
155
+ private endpoint;
156
+ private mem;
157
+ constructor(options: SupportOptions | undefined);
158
+ /**
159
+ * Start a new support conversation. The returned access key is stored
160
+ * locally so `getThread`/`sendMessage` work without passing it around.
161
+ */
162
+ startThread(options: StartThreadOptions): SupportResult<StartedThread>;
163
+ /** Fetch a thread (status + full message history) with its stored access key. */
164
+ getThread(threadId: string, accessKey?: string): SupportResult<SupportThread>;
165
+ /** Send a visitor reply on an existing thread (reopens it if closed). */
166
+ sendMessage(threadId: string, message: string, accessKey?: string): SupportResult<{
167
+ ok: true;
168
+ }>;
169
+ /** Threads started from this browser (ids only; fetch each with getThread). */
170
+ listThreads(): {
171
+ id: string;
172
+ }[];
173
+ /** The contact details used when this browser last started a thread. */
174
+ getContact(): {
175
+ email?: string;
176
+ name?: string;
177
+ } | undefined;
178
+ private requireHandle;
179
+ private missingKey;
180
+ private request;
181
+ private storageKey;
182
+ private load;
183
+ private save;
184
+ private keyFor;
185
+ private remember;
186
+ }
187
+
188
+ /**
189
+ * API payload types for the Result SDK.
190
+ *
191
+ * These mirror the backend's wire formats exactly. Keep the public string
192
+ * values stable — they are part of the HTTP contract.
193
+ */
194
+ declare const ERROR_CODE_VALUES: readonly ["AUTH_INVALID_EMAIL", "AUTH_WEAK_PASSWORD", "AUTH_INVALID_CREDENTIALS", "AUTH_INVALID_API_KEY", "AUTH_EMAIL_EXISTS", "AUTH_USER_NOT_FOUND", "AUTH_OAUTH_CONFIG_ALREADY_EXISTS", "AUTH_OAUTH_CONFIG_ERROR", "AUTH_OAUTH_CONFIG_NOT_FOUND", "AUTH_UNSUPPORTED_PROVIDER", "AUTH_TOKEN_EXPIRED", "AUTH_UNAUTHORIZED", "AUTH_NEED_VERIFICATION", "AUTH_SIGNUP_DISABLED", "AUTH_VERIFICATION_EMAIL_DELIVERY_FAILED", "DATABASE_INVALID_PARAMETER", "DATABASE_VALIDATION_ERROR", "DATABASE_CONSTRAINT_VIOLATION", "DATABASE_NOT_FOUND", "DATABASE_DUPLICATE", "DATABASE_MIGRATION_ALREADY_EXISTS", "DATABASE_PERMISSION_DENIED", "DATABASE_INTERNAL_ERROR", "DATABASE_FORBIDDEN", "STORAGE_ALREADY_EXISTS", "STORAGE_INVALID_PARAMETER", "STORAGE_INVALID_FILE_TYPE", "STORAGE_INSUFFICIENT_QUOTA", "STORAGE_NOT_FOUND", "STORAGE_PERMISSION_DENIED", "S3_ACCESS_KEY_LIMIT_EXCEEDED", "S3_ACCESS_KEY_NOT_FOUND", "S3_PROTOCOL_UNAVAILABLE", "REALTIME_CHANNEL_NOT_FOUND", "REALTIME_CONNECTION_FAILED", "REALTIME_INVALID_CHANNEL_REQUEST", "REALTIME_INVALID_CHANNEL_PATTERN", "REALTIME_INVALID_EVENT", "REALTIME_NOT_SUBSCRIBED", "REALTIME_UNAUTHORIZED", "AI_INVALID_API_KEY", "AI_INVALID_MODEL", "AI_UPSTREAM_UNAVAILABLE", "ANALYTICS_NOT_CONNECTED", "ANALYTICS_UNAVAILABLE", "LOGS_AWS_NOT_CONFIGURED", "LOG_NOT_FOUND", "COMPUTE_CLOUD_UNAVAILABLE", "COMPUTE_NOT_CONFIGURED", "COMPUTE_PROVIDER_ERROR", "COMPUTE_SERVICE_NOT_FOUND", "COMPUTE_MACHINE_NOT_FOUND", "COMPUTE_SERVICE_NOT_CONFIGURED", "COMPUTE_SERVICE_DEPLOY_FAILED", "COMPUTE_SERVICE_ALREADY_EXISTS", "COMPUTE_SERVICE_START_FAILED", "COMPUTE_SERVICE_STOP_FAILED", "COMPUTE_SERVICE_DELETE_FAILED", "COMPUTE_REGION_CHANGE_NOT_SUPPORTED", "COMPUTE_QUOTA_EXCEEDED", "BILLING_INSUFFICIENT_BALANCE", "EMAIL_PROVIDER_NOT_CONFIGURED", "EMAIL_SMTP_CONNECTION_FAILED", "EMAIL_SMTP_SEND_FAILED", "EMAIL_TEMPLATE_NOT_FOUND", "DEPLOYMENT_ALREADY_EXISTS", "DEPLOYMENT_INVALID_FILE", "DEPLOYMENT_NOT_FOUND", "DEPLOYMENT_UPLOAD_CANCELED", "DOMAIN_ALREADY_EXISTS", "DOMAIN_INVALID", "DOMAIN_NOT_FOUND", "ENVIRONMENT_VARIABLE_NOT_FOUND", "DOCS_NOT_FOUND", "FUNCTION_ALREADY_EXISTS", "FUNCTION_DEPLOYMENT_NOT_FOUND", "FUNCTION_NOT_FOUND", "SCHEDULE_INVALID_CRON", "SCHEDULE_NOT_FOUND", "PAYMENT_CHECKOUT_ALREADY_EXISTS", "PAYMENT_CONFIG_INVALID", "PAYMENT_CONFIG_NOT_FOUND", "PAYMENT_NOT_FOUND", "PAYMENT_METHOD_DECLINED", "PAYMENT_PRICE_NOT_FOUND", "PAYMENT_PRODUCT_NOT_FOUND", "SECRET_ALREADY_EXISTS", "SECRET_NOT_FOUND", "MISSING_FIELD", "ALREADY_EXISTS", "INVALID_INPUT", "NOT_FOUND", "UNKNOWN_ERROR", "INTERNAL_ERROR", "TOO_MANY_REQUESTS", "FORBIDDEN", "RATE_LIMITED", "NOT_IMPLEMENTED", "UPSTREAM_FAILURE"];
195
+ type ErrorCode = (typeof ERROR_CODE_VALUES)[number];
196
+ declare const ERROR_CODES: { readonly [K in ErrorCode]: K; };
197
+ interface ProfileSchema {
198
+ name?: string;
199
+ avatar_url?: string;
200
+ [key: string]: unknown;
201
+ }
202
+ interface UserSchema {
203
+ id: string;
204
+ email: string;
205
+ emailVerified: boolean;
206
+ providers?: string[];
207
+ createdAt: string;
208
+ updatedAt: string;
209
+ profile: ProfileSchema | null;
210
+ metadata: Record<string, unknown> | null;
211
+ }
212
+ declare const OAUTH_PROVIDERS: readonly ["google", "github", "discord", "linkedin", "facebook", "instagram", "tiktok", "apple", "x", "spotify", "microsoft"];
213
+ type OAuthProvidersSchema = (typeof OAUTH_PROVIDERS)[number];
214
+ interface CreateUserRequest {
215
+ email: string;
216
+ password: string;
217
+ name?: string;
218
+ redirectTo?: string;
219
+ autoConfirm?: boolean;
220
+ }
221
+ interface CreateSessionRequest {
222
+ email: string;
223
+ password: string;
224
+ }
225
+ interface SendVerificationEmailRequest {
226
+ email: string;
227
+ redirectTo?: string;
228
+ }
229
+ interface VerifyEmailRequest {
230
+ email: string;
231
+ otp: string;
232
+ }
233
+ interface SendResetPasswordEmailRequest {
234
+ email: string;
235
+ redirectTo?: string;
236
+ }
237
+ interface ExchangeResetPasswordTokenRequest {
238
+ email: string;
239
+ code: string;
240
+ }
241
+ interface CreateUserResponse {
242
+ user?: UserSchema;
243
+ accessToken: string | null;
244
+ requireEmailVerification?: boolean;
245
+ csrfToken?: string | null;
246
+ refreshToken?: string;
247
+ }
248
+ interface CreateSessionResponse {
249
+ user: UserSchema;
250
+ accessToken: string;
251
+ csrfToken?: string | null;
252
+ refreshToken?: string;
253
+ }
254
+ interface VerifyEmailResponse {
255
+ user: UserSchema;
256
+ accessToken: string;
257
+ csrfToken?: string | null;
258
+ refreshToken?: string;
259
+ }
260
+ interface RefreshSessionResponse {
261
+ accessToken: string;
262
+ user: UserSchema;
263
+ csrfToken?: string;
264
+ refreshToken?: string;
265
+ }
266
+ interface ExchangeResetPasswordTokenResponse {
267
+ token: string;
268
+ expiresAt: string;
269
+ }
270
+ interface ResetPasswordResponse {
271
+ message: string;
272
+ }
273
+ interface GetProfileResponse {
274
+ id: string;
275
+ profile: ProfileSchema | null;
276
+ }
277
+ type VerificationMethod = "code" | "link";
278
+ /** Response for GET /api/auth/public-config (unauthenticated). */
279
+ interface GetPublicAuthConfigResponse {
280
+ oAuthProviders: OAuthProvidersSchema[];
281
+ customOAuthProviders: string[];
282
+ requireEmailVerification: boolean;
283
+ passwordMinLength: number;
284
+ requireNumber: boolean;
285
+ requireLowercase: boolean;
286
+ requireUppercase: boolean;
287
+ requireSpecialChar: boolean;
288
+ verifyEmailMethod: VerificationMethod;
289
+ resetPasswordMethod: VerificationMethod;
290
+ disableSignup: boolean;
291
+ }
292
+ interface AuthErrorResponse {
293
+ error: string;
294
+ message: string;
295
+ statusCode: number;
296
+ nextActions?: string;
297
+ }
298
+ interface StorageFileSchema {
299
+ key: string;
300
+ bucket: string;
301
+ size: number;
302
+ mimeType?: string;
303
+ uploadedAt: string;
304
+ url: string;
305
+ }
306
+ interface ListObjectsResponseSchema {
307
+ objects: StorageFileSchema[];
308
+ pagination: {
309
+ offset: number;
310
+ limit: number;
311
+ total: number;
312
+ };
313
+ }
314
+ interface DeleteObjectResult {
315
+ key: string;
316
+ status: "deleted" | "notFound" | "failed";
317
+ message?: string;
318
+ }
319
+ interface DeleteObjectsResponse {
320
+ results: DeleteObjectResult[];
321
+ }
322
+ interface SendRawEmailRequest {
323
+ to: string | string[];
324
+ subject: string;
325
+ html: string;
326
+ cc?: string | string[];
327
+ bcc?: string | string[];
328
+ from?: string;
329
+ replyTo?: string;
330
+ }
331
+ /** Empty on success — extend with optional fields later if needed. */
332
+ type SendEmailResponse = Record<string, never>;
333
+ interface TextContentSchema {
334
+ type: "text";
335
+ text: string;
336
+ }
337
+ interface ImageContentSchema {
338
+ type: "image_url";
339
+ image_url: {
340
+ /** Public URL or base64 data URI. */
341
+ url: string;
342
+ detail?: "auto" | "low" | "high";
343
+ };
344
+ }
345
+ interface AudioContentSchema {
346
+ type: "input_audio";
347
+ input_audio: {
348
+ /** Base64-encoded audio data (direct URLs not supported for audio). */
349
+ data: string;
350
+ format: "wav" | "mp3" | "aiff" | "aac" | "ogg" | "flac" | "m4a";
351
+ };
352
+ }
353
+ interface FileContentSchema {
354
+ type: "file";
355
+ file: {
356
+ filename: string;
357
+ /** Public URL or base64 data URL. */
358
+ file_data: string;
359
+ };
360
+ }
361
+ type ContentSchema = TextContentSchema | ImageContentSchema | AudioContentSchema | FileContentSchema;
362
+ interface ToolFunction {
363
+ name: string;
364
+ description?: string;
365
+ parameters?: Record<string, unknown>;
366
+ }
367
+ interface Tool {
368
+ type: "function";
369
+ function: ToolFunction;
370
+ }
371
+ type ToolChoice = "auto" | "none" | "required" | {
372
+ type: "function";
373
+ function: {
374
+ name: string;
375
+ };
376
+ };
377
+ interface ToolCall {
378
+ id: string;
379
+ type: "function";
380
+ function: {
381
+ name: string;
382
+ arguments: string;
383
+ };
384
+ }
385
+ interface ChatMessageSchema {
386
+ role: "user" | "assistant" | "system" | "tool";
387
+ /**
388
+ * String or content-part array (OpenAI-compatible). Assistant tool-call
389
+ * messages may omit it; other roles must carry the field (null allowed).
390
+ */
391
+ content?: string | ContentSchema[] | null;
392
+ /** @deprecated Legacy separate-images field, still accepted. */
393
+ images?: {
394
+ url: string;
395
+ }[];
396
+ tool_calls?: ToolCall[];
397
+ tool_call_id?: string;
398
+ }
399
+ interface WebSearchPlugin {
400
+ enabled: boolean;
401
+ engine?: "native" | "exa";
402
+ maxResults?: number;
403
+ searchPrompt?: string;
404
+ }
405
+ interface FileParserPlugin {
406
+ enabled: boolean;
407
+ pdf?: {
408
+ engine?: "pdf-text" | "mistral-ocr" | "native";
409
+ };
410
+ }
411
+ interface ChatCompletionRequest {
412
+ model: string;
413
+ messages: ChatMessageSchema[];
414
+ temperature?: number;
415
+ maxTokens?: number;
416
+ topP?: number;
417
+ stream?: boolean;
418
+ webSearch?: WebSearchPlugin;
419
+ fileParser?: FileParserPlugin;
420
+ thinking?: boolean;
421
+ tools?: Tool[];
422
+ toolChoice?: ToolChoice;
423
+ parallelToolCalls?: boolean;
424
+ }
425
+ interface UrlCitationAnnotation {
426
+ type: "url_citation";
427
+ urlCitation: {
428
+ url: string;
429
+ title?: string;
430
+ content?: string;
431
+ startIndex?: number;
432
+ endIndex?: number;
433
+ };
434
+ }
435
+ interface FileAnnotation {
436
+ type: "file";
437
+ file: {
438
+ filename: string;
439
+ parsedContent?: string;
440
+ metadata?: Record<string, unknown>;
441
+ };
442
+ }
443
+ type Annotation = UrlCitationAnnotation | FileAnnotation;
444
+ interface EmbeddingsRequest {
445
+ model: string;
446
+ input: string | string[];
447
+ encoding_format?: "float" | "base64";
448
+ dimensions?: number;
449
+ }
450
+ interface EmbeddingObject {
451
+ object: "embedding";
452
+ /** number[] for float format, string for base64 format. */
453
+ embedding: number[] | string;
454
+ index: number;
455
+ }
456
+ interface ImageGenerationRequest {
457
+ model: string;
458
+ prompt: string;
459
+ images?: {
460
+ url: string;
461
+ }[];
462
+ }
463
+ type SenderType = "system" | "user";
464
+ /**
465
+ * A member present in a realtime channel. Presence is ephemeral — tracked
466
+ * in-memory, not persisted. `presenceId` is the user ID for `type: 'user'`
467
+ * and the socket ID for `type: 'anonymous'`.
468
+ */
469
+ type PresenceMember = {
470
+ type: "user";
471
+ presenceId: string;
472
+ joinedAt: string;
473
+ } | {
474
+ type: "anonymous";
475
+ presenceId: string;
476
+ joinedAt: string;
477
+ };
478
+ interface PresenceSnapshot {
479
+ members: PresenceMember[];
480
+ }
481
+ /** Response for subscribe operations (Socket.IO ack callbacks). */
482
+ type SubscribeResponse = {
483
+ ok: true;
484
+ channel: string;
485
+ presence: PresenceSnapshot;
486
+ } | {
487
+ ok: false;
488
+ channel: string;
489
+ error: {
490
+ code: string;
491
+ message: string;
492
+ };
493
+ };
494
+ /** Payload for unsolicited server errors (e.g. publish failures). */
495
+ interface RealtimeErrorPayload {
496
+ channel?: string;
497
+ code: string;
498
+ message: string;
499
+ }
500
+ interface SocketMessageMeta {
501
+ /**
502
+ * Present for room broadcasts. Matches the exact channel name passed to
503
+ * subscribe() - the SDK strips the server's transport prefix on delivery.
504
+ */
505
+ channel?: string;
506
+ messageId: string;
507
+ senderType: SenderType;
508
+ senderId?: string;
509
+ timestamp: string;
510
+ }
511
+ /**
512
+ * A received realtime message. The published payload's fields arrive spread
513
+ * onto this object next to `meta` (publish `{ text: "hi" }`, read
514
+ * `msg.text`) - there is no `payload` wrapper key.
515
+ */
516
+ interface SocketMessage {
517
+ meta: SocketMessageMeta;
518
+ [key: string]: unknown;
519
+ }
520
+
521
+ /**
522
+ * Result SDK Types - only SDK-specific types here
523
+ * API payload types live in ./types/api
524
+ */
525
+
526
+ type ResultErrorCode = ErrorCode | (string & {});
527
+ interface ResultConfig {
528
+ /**
529
+ * The base URL of the Result backend API
530
+ * @default "http://localhost:7130"
531
+ */
532
+ baseUrl?: string;
533
+ /**
534
+ * Anonymous API key (optional)
535
+ * Used for public/unauthenticated requests when no user token is set
536
+ */
537
+ anonKey?: string;
538
+ /**
539
+ * Static access token (optional)
540
+ * Seeds the client with a fixed bearer token used for all authenticated
541
+ * requests — e.g. a user JWT inside an edge function, or a server-signed
542
+ * JWT from an external auth provider. Disables automatic token refresh
543
+ * and implies server mode unless `isServerMode` is set explicitly.
544
+ */
545
+ accessToken?: string;
546
+ /**
547
+ * @deprecated Use `accessToken` instead. Same behavior; `accessToken`
548
+ * takes precedence when both are provided.
549
+ */
550
+ edgeFunctionToken?: string;
551
+ /**
552
+ * Direct URL to Deno Subhosting functions (optional)
553
+ * When provided, SDK will try this URL first for function invocations.
554
+ * Falls back to proxy URL if subhosting returns 404.
555
+ * @example "https://{appKey}.functions.<platform-functions-domain>"
556
+ */
557
+ functionsUrl?: string;
558
+ /**
559
+ * Custom fetch implementation (useful for Node.js environments)
560
+ */
561
+ fetch?: typeof fetch;
562
+ /**
563
+ * Enable server-side auth mode (SSR/Node runtime)
564
+ * In this mode auth endpoints use `client_type=mobile` and refresh_token body flow.
565
+ *
566
+ * @deprecated Use `createServerClient()`, `createBrowserClient()`, and
567
+ * `updateSession()` from `@resultdev/sdk/ssr` for SSR apps.
568
+ * @default false
569
+ */
570
+ isServerMode?: boolean;
571
+ /**
572
+ * Advanced auth module options.
573
+ */
574
+ auth?: {
575
+ /**
576
+ * Detect and exchange OAuth callback parameters on browser client
577
+ * initialization. SSR browser clients disable this so auth mutations can
578
+ * stay server-owned.
579
+ * @default true
580
+ */
581
+ detectOAuthCallback?: boolean;
582
+ };
583
+ /**
584
+ * Database module options.
585
+ */
586
+ db?: {
587
+ /**
588
+ * Default Postgres schema for database queries. Maps to PostgREST's
589
+ * `Accept-Profile`/`Content-Profile` headers. Override per-query with
590
+ * `client.database.schema('other')`.
591
+ * @default "public"
592
+ */
593
+ schema?: string;
594
+ };
595
+ /**
596
+ * Web analytics options. When `siteId` is set and the client runs in a
597
+ * browser, pageviews are tracked automatically (SPA routes included) and
598
+ * `client.analytics.track()` sends custom events. No script tag needed.
599
+ */
600
+ analytics?: AnalyticsOptions;
601
+ /**
602
+ * Customer support options. Set your business @handle to let visitors
603
+ * start conversations that land in your Result support inbox via
604
+ * `client.support`.
605
+ */
606
+ support?: SupportOptions;
607
+ /**
608
+ * Custom headers to include with every request
609
+ */
610
+ headers?: Record<string, string>;
611
+ /**
612
+ * Enable debug logging for HTTP requests and responses.
613
+ * When true, request/response details are logged to the console.
614
+ * Can also be a custom log function for advanced use cases.
615
+ * @default false
616
+ */
617
+ debug?: boolean | ((message: string, ...args: unknown[]) => void);
618
+ /**
619
+ * Request timeout in milliseconds.
620
+ * Requests that exceed this duration will be aborted.
621
+ * Set to 0 to disable timeout.
622
+ * @default 30000
623
+ */
624
+ timeout?: number;
625
+ /**
626
+ * Maximum number of retry attempts for failed requests.
627
+ * Retries are triggered on network errors and server errors (5xx).
628
+ * Client errors (4xx) are never retried.
629
+ * Set to 0 to disable retries.
630
+ * @default 3
631
+ */
632
+ retryCount?: number;
633
+ /**
634
+ * Initial delay in milliseconds before the first retry.
635
+ * The delay doubles with each subsequent attempt (exponential backoff)
636
+ * with ±15% jitter to prevent thundering herd.
637
+ * @default 500
638
+ */
639
+ retryDelay?: number;
640
+ }
641
+ type ResultAdminConfig = Omit<ResultConfig, "anonKey" | "accessToken" | "edgeFunctionToken" | "isServerMode"> & {
642
+ /**
643
+ * Project admin API key. Keep this server-side only.
644
+ */
645
+ apiKey: string;
646
+ };
647
+ interface AuthSession {
648
+ user: UserSchema;
649
+ accessToken: string;
650
+ expiresAt?: Date;
651
+ }
652
+ interface AuthRefreshResponse {
653
+ user: UserSchema;
654
+ accessToken: string;
655
+ csrfToken?: string;
656
+ refreshToken?: string;
657
+ }
658
+ interface ApiError {
659
+ error: ResultErrorCode;
660
+ message: string;
661
+ statusCode: number;
662
+ nextActions?: string;
663
+ }
664
+ declare class ResultError extends Error {
665
+ statusCode: number;
666
+ error: ResultErrorCode;
667
+ nextActions?: string;
668
+ constructor(message: string, statusCode: number, error: ResultErrorCode, nextActions?: string);
669
+ static fromApiError(apiError: ApiError): ResultError;
670
+ }
671
+
672
+ export { type GetPublicAuthConfigResponse as $, Analytics as A, type ToolCall as B, type ChatCompletionRequest as C, type DeleteObjectResult as D, ERROR_CODES as E, type ToolChoice as F, type AuthRefreshResponse as G, type Annotation as H, type ImageGenerationRequest as I, type EmbeddingObject as J, type CreateUserResponse as K, type CreateSessionResponse as L, type RefreshSessionResponse as M, type GetProfileResponse as N, OAUTH_PROVIDERS as O, type PresenceMember as P, type SendVerificationEmailRequest as Q, type ResultAdminConfig as R, type SendRawEmailRequest as S, type Tool as T, type UserSchema as U, type VerifyEmailRequest as V, type VerifyEmailResponse as W, type SendResetPasswordEmailRequest as X, type ExchangeResetPasswordTokenRequest as Y, type ExchangeResetPasswordTokenResponse as Z, type ResetPasswordResponse as _, type ResultConfig as a, type ListObjectsResponseSchema as a0, type AnalyticsOptions as b, type ApiError as c, type AuthErrorResponse as d, type AuthSession as e, type ChatMessageSchema as f, type CreateSessionRequest as g, type CreateUserRequest as h, type DeleteObjectsResponse as i, type EmbeddingsRequest as j, type ErrorCode as k, type OAuthProvidersSchema as l, type ProfileSchema as m, type RealtimeErrorPayload as n, ResultError as o, type ResultErrorCode as p, type SendEmailResponse as q, type SocketMessage as r, type StartThreadOptions as s, type StartedThread as t, type StorageFileSchema as u, type SubscribeResponse as v, Support as w, type SupportMessage as x, type SupportOptions as y, type SupportThread as z };