@reverbia/sdk 1.0.0-next.20251218225706 → 1.0.0-next.20251219154503
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/react/index.cjs +1588 -114
- package/dist/react/index.d.mts +1037 -32
- package/dist/react/index.d.ts +1037 -32
- package/dist/react/index.mjs +1589 -111
- package/package.json +1 -1
package/dist/react/index.d.mts
CHANGED
|
@@ -348,6 +348,295 @@ type LlmapiSearchUsage = {
|
|
|
348
348
|
cost_micro_usd?: number;
|
|
349
349
|
};
|
|
350
350
|
|
|
351
|
+
type AuthToken = string | undefined;
|
|
352
|
+
interface Auth {
|
|
353
|
+
/**
|
|
354
|
+
* Which part of the request do we use to send the auth?
|
|
355
|
+
*
|
|
356
|
+
* @default 'header'
|
|
357
|
+
*/
|
|
358
|
+
in?: 'header' | 'query' | 'cookie';
|
|
359
|
+
/**
|
|
360
|
+
* Header or query parameter name.
|
|
361
|
+
*
|
|
362
|
+
* @default 'Authorization'
|
|
363
|
+
*/
|
|
364
|
+
name?: string;
|
|
365
|
+
scheme?: 'basic' | 'bearer';
|
|
366
|
+
type: 'apiKey' | 'http';
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
interface SerializerOptions<T> {
|
|
370
|
+
/**
|
|
371
|
+
* @default true
|
|
372
|
+
*/
|
|
373
|
+
explode: boolean;
|
|
374
|
+
style: T;
|
|
375
|
+
}
|
|
376
|
+
type ArrayStyle = 'form' | 'spaceDelimited' | 'pipeDelimited';
|
|
377
|
+
type ObjectStyle = 'form' | 'deepObject';
|
|
378
|
+
|
|
379
|
+
type QuerySerializer = (query: Record<string, unknown>) => string;
|
|
380
|
+
type BodySerializer = (body: any) => any;
|
|
381
|
+
type QuerySerializerOptionsObject = {
|
|
382
|
+
allowReserved?: boolean;
|
|
383
|
+
array?: Partial<SerializerOptions<ArrayStyle>>;
|
|
384
|
+
object?: Partial<SerializerOptions<ObjectStyle>>;
|
|
385
|
+
};
|
|
386
|
+
type QuerySerializerOptions = QuerySerializerOptionsObject & {
|
|
387
|
+
/**
|
|
388
|
+
* Per-parameter serialization overrides. When provided, these settings
|
|
389
|
+
* override the global array/object settings for specific parameter names.
|
|
390
|
+
*/
|
|
391
|
+
parameters?: Record<string, QuerySerializerOptionsObject>;
|
|
392
|
+
};
|
|
393
|
+
|
|
394
|
+
type HttpMethod = 'connect' | 'delete' | 'get' | 'head' | 'options' | 'patch' | 'post' | 'put' | 'trace';
|
|
395
|
+
type Client$1<RequestFn = never, Config = unknown, MethodFn = never, BuildUrlFn = never, SseFn = never> = {
|
|
396
|
+
/**
|
|
397
|
+
* Returns the final request URL.
|
|
398
|
+
*/
|
|
399
|
+
buildUrl: BuildUrlFn;
|
|
400
|
+
getConfig: () => Config;
|
|
401
|
+
request: RequestFn;
|
|
402
|
+
setConfig: (config: Config) => Config;
|
|
403
|
+
} & {
|
|
404
|
+
[K in HttpMethod]: MethodFn;
|
|
405
|
+
} & ([SseFn] extends [never] ? {
|
|
406
|
+
sse?: never;
|
|
407
|
+
} : {
|
|
408
|
+
sse: {
|
|
409
|
+
[K in HttpMethod]: SseFn;
|
|
410
|
+
};
|
|
411
|
+
});
|
|
412
|
+
interface Config$1 {
|
|
413
|
+
/**
|
|
414
|
+
* Auth token or a function returning auth token. The resolved value will be
|
|
415
|
+
* added to the request payload as defined by its `security` array.
|
|
416
|
+
*/
|
|
417
|
+
auth?: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken;
|
|
418
|
+
/**
|
|
419
|
+
* A function for serializing request body parameter. By default,
|
|
420
|
+
* {@link JSON.stringify()} will be used.
|
|
421
|
+
*/
|
|
422
|
+
bodySerializer?: BodySerializer | null;
|
|
423
|
+
/**
|
|
424
|
+
* An object containing any HTTP headers that you want to pre-populate your
|
|
425
|
+
* `Headers` object with.
|
|
426
|
+
*
|
|
427
|
+
* {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more}
|
|
428
|
+
*/
|
|
429
|
+
headers?: RequestInit['headers'] | Record<string, string | number | boolean | (string | number | boolean)[] | null | undefined | unknown>;
|
|
430
|
+
/**
|
|
431
|
+
* The request method.
|
|
432
|
+
*
|
|
433
|
+
* {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more}
|
|
434
|
+
*/
|
|
435
|
+
method?: Uppercase<HttpMethod>;
|
|
436
|
+
/**
|
|
437
|
+
* A function for serializing request query parameters. By default, arrays
|
|
438
|
+
* will be exploded in form style, objects will be exploded in deepObject
|
|
439
|
+
* style, and reserved characters are percent-encoded.
|
|
440
|
+
*
|
|
441
|
+
* This method will have no effect if the native `paramsSerializer()` Axios
|
|
442
|
+
* API function is used.
|
|
443
|
+
*
|
|
444
|
+
* {@link https://swagger.io/docs/specification/serialization/#query View examples}
|
|
445
|
+
*/
|
|
446
|
+
querySerializer?: QuerySerializer | QuerySerializerOptions;
|
|
447
|
+
/**
|
|
448
|
+
* A function validating request data. This is useful if you want to ensure
|
|
449
|
+
* the request conforms to the desired shape, so it can be safely sent to
|
|
450
|
+
* the server.
|
|
451
|
+
*/
|
|
452
|
+
requestValidator?: (data: unknown) => Promise<unknown>;
|
|
453
|
+
/**
|
|
454
|
+
* A function transforming response data before it's returned. This is useful
|
|
455
|
+
* for post-processing data, e.g. converting ISO strings into Date objects.
|
|
456
|
+
*/
|
|
457
|
+
responseTransformer?: (data: unknown) => Promise<unknown>;
|
|
458
|
+
/**
|
|
459
|
+
* A function validating response data. This is useful if you want to ensure
|
|
460
|
+
* the response conforms to the desired shape, so it can be safely passed to
|
|
461
|
+
* the transformers and returned to the user.
|
|
462
|
+
*/
|
|
463
|
+
responseValidator?: (data: unknown) => Promise<unknown>;
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
type ServerSentEventsOptions<TData = unknown> = Omit<RequestInit, 'method'> & Pick<Config$1, 'method' | 'responseTransformer' | 'responseValidator'> & {
|
|
467
|
+
/**
|
|
468
|
+
* Fetch API implementation. You can use this option to provide a custom
|
|
469
|
+
* fetch instance.
|
|
470
|
+
*
|
|
471
|
+
* @default globalThis.fetch
|
|
472
|
+
*/
|
|
473
|
+
fetch?: typeof fetch;
|
|
474
|
+
/**
|
|
475
|
+
* Implementing clients can call request interceptors inside this hook.
|
|
476
|
+
*/
|
|
477
|
+
onRequest?: (url: string, init: RequestInit) => Promise<Request>;
|
|
478
|
+
/**
|
|
479
|
+
* Callback invoked when a network or parsing error occurs during streaming.
|
|
480
|
+
*
|
|
481
|
+
* This option applies only if the endpoint returns a stream of events.
|
|
482
|
+
*
|
|
483
|
+
* @param error The error that occurred.
|
|
484
|
+
*/
|
|
485
|
+
onSseError?: (error: unknown) => void;
|
|
486
|
+
/**
|
|
487
|
+
* Callback invoked when an event is streamed from the server.
|
|
488
|
+
*
|
|
489
|
+
* This option applies only if the endpoint returns a stream of events.
|
|
490
|
+
*
|
|
491
|
+
* @param event Event streamed from the server.
|
|
492
|
+
* @returns Nothing (void).
|
|
493
|
+
*/
|
|
494
|
+
onSseEvent?: (event: StreamEvent<TData>) => void;
|
|
495
|
+
serializedBody?: RequestInit['body'];
|
|
496
|
+
/**
|
|
497
|
+
* Default retry delay in milliseconds.
|
|
498
|
+
*
|
|
499
|
+
* This option applies only if the endpoint returns a stream of events.
|
|
500
|
+
*
|
|
501
|
+
* @default 3000
|
|
502
|
+
*/
|
|
503
|
+
sseDefaultRetryDelay?: number;
|
|
504
|
+
/**
|
|
505
|
+
* Maximum number of retry attempts before giving up.
|
|
506
|
+
*/
|
|
507
|
+
sseMaxRetryAttempts?: number;
|
|
508
|
+
/**
|
|
509
|
+
* Maximum retry delay in milliseconds.
|
|
510
|
+
*
|
|
511
|
+
* Applies only when exponential backoff is used.
|
|
512
|
+
*
|
|
513
|
+
* This option applies only if the endpoint returns a stream of events.
|
|
514
|
+
*
|
|
515
|
+
* @default 30000
|
|
516
|
+
*/
|
|
517
|
+
sseMaxRetryDelay?: number;
|
|
518
|
+
/**
|
|
519
|
+
* Optional sleep function for retry backoff.
|
|
520
|
+
*
|
|
521
|
+
* Defaults to using `setTimeout`.
|
|
522
|
+
*/
|
|
523
|
+
sseSleepFn?: (ms: number) => Promise<void>;
|
|
524
|
+
url: string;
|
|
525
|
+
};
|
|
526
|
+
interface StreamEvent<TData = unknown> {
|
|
527
|
+
data: TData;
|
|
528
|
+
event?: string;
|
|
529
|
+
id?: string;
|
|
530
|
+
retry?: number;
|
|
531
|
+
}
|
|
532
|
+
type ServerSentEventsResult<TData = unknown, TReturn = void, TNext = unknown> = {
|
|
533
|
+
stream: AsyncGenerator<TData extends Record<string, unknown> ? TData[keyof TData] : TData, TReturn, TNext>;
|
|
534
|
+
};
|
|
535
|
+
|
|
536
|
+
type ErrInterceptor<Err, Res, Options> = (error: Err, response: Res, options: Options) => Err | Promise<Err>;
|
|
537
|
+
type ReqInterceptor<Options> = (options: Options) => void | Promise<void>;
|
|
538
|
+
type ResInterceptor<Res, Options> = (response: Res, options: Options) => Res | Promise<Res>;
|
|
539
|
+
declare class Interceptors<Interceptor> {
|
|
540
|
+
fns: Array<Interceptor | null>;
|
|
541
|
+
clear(): void;
|
|
542
|
+
eject(id: number | Interceptor): void;
|
|
543
|
+
exists(id: number | Interceptor): boolean;
|
|
544
|
+
getInterceptorIndex(id: number | Interceptor): number;
|
|
545
|
+
update(id: number | Interceptor, fn: Interceptor): number | Interceptor | false;
|
|
546
|
+
use(fn: Interceptor): number;
|
|
547
|
+
}
|
|
548
|
+
interface Middleware<Res, Err, Options> {
|
|
549
|
+
error: Interceptors<ErrInterceptor<Err, Res, Options>>;
|
|
550
|
+
request: Interceptors<ReqInterceptor<Options>>;
|
|
551
|
+
response: Interceptors<ResInterceptor<Res, Options>>;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
interface Config<T extends ClientOptions = ClientOptions> extends Omit<RequestInit, 'body' | 'headers' | 'method'>, Config$1 {
|
|
555
|
+
/**
|
|
556
|
+
* Base URL for all requests made by this client.
|
|
557
|
+
*/
|
|
558
|
+
baseUrl?: T['baseUrl'];
|
|
559
|
+
/**
|
|
560
|
+
* Fetch API implementation. You can use this option to provide a custom
|
|
561
|
+
* fetch instance.
|
|
562
|
+
*
|
|
563
|
+
* @default globalThis.fetch
|
|
564
|
+
*/
|
|
565
|
+
fetch?: typeof fetch;
|
|
566
|
+
/**
|
|
567
|
+
* Return the response data parsed in a specified format. By default, `auto`
|
|
568
|
+
* will infer the appropriate method from the `Content-Type` response header.
|
|
569
|
+
* You can override this behavior with any of the {@link Body} methods.
|
|
570
|
+
* Select `stream` if you don't want to parse response data at all.
|
|
571
|
+
*
|
|
572
|
+
* @default 'auto'
|
|
573
|
+
*/
|
|
574
|
+
parseAs?: 'arrayBuffer' | 'auto' | 'blob' | 'formData' | 'json' | 'stream' | 'text';
|
|
575
|
+
/**
|
|
576
|
+
* Throw an error instead of returning it in the response?
|
|
577
|
+
*
|
|
578
|
+
* @default false
|
|
579
|
+
*/
|
|
580
|
+
throwOnError?: T['throwOnError'];
|
|
581
|
+
}
|
|
582
|
+
interface RequestOptions<TData = unknown, ThrowOnError extends boolean = boolean, Url extends string = string> extends Config<{
|
|
583
|
+
throwOnError: ThrowOnError;
|
|
584
|
+
}>, Pick<ServerSentEventsOptions<TData>, 'onSseError' | 'onSseEvent' | 'sseDefaultRetryDelay' | 'sseMaxRetryAttempts' | 'sseMaxRetryDelay'> {
|
|
585
|
+
/**
|
|
586
|
+
* Any body that you want to add to your request.
|
|
587
|
+
*
|
|
588
|
+
* {@link https://developer.mozilla.org/docs/Web/API/fetch#body}
|
|
589
|
+
*/
|
|
590
|
+
body?: unknown;
|
|
591
|
+
path?: Record<string, unknown>;
|
|
592
|
+
query?: Record<string, unknown>;
|
|
593
|
+
/**
|
|
594
|
+
* Security mechanism(s) to use for the request.
|
|
595
|
+
*/
|
|
596
|
+
security?: ReadonlyArray<Auth>;
|
|
597
|
+
url: Url;
|
|
598
|
+
}
|
|
599
|
+
interface ResolvedRequestOptions<ThrowOnError extends boolean = boolean, Url extends string = string> extends RequestOptions<unknown, ThrowOnError, Url> {
|
|
600
|
+
serializedBody?: string;
|
|
601
|
+
}
|
|
602
|
+
type RequestResult<TData = unknown, TError = unknown, ThrowOnError extends boolean = boolean> = ThrowOnError extends true ? Promise<{
|
|
603
|
+
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
|
|
604
|
+
response: Response;
|
|
605
|
+
}> : Promise<({
|
|
606
|
+
data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
|
|
607
|
+
error: undefined;
|
|
608
|
+
} | {
|
|
609
|
+
data: undefined;
|
|
610
|
+
error: TError extends Record<string, unknown> ? TError[keyof TError] : TError;
|
|
611
|
+
}) & {
|
|
612
|
+
response: Response;
|
|
613
|
+
}>;
|
|
614
|
+
interface ClientOptions {
|
|
615
|
+
baseUrl?: string;
|
|
616
|
+
throwOnError?: boolean;
|
|
617
|
+
}
|
|
618
|
+
type MethodFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(options: Omit<RequestOptions<TData, ThrowOnError>, 'method'>) => RequestResult<TData, TError, ThrowOnError>;
|
|
619
|
+
type SseFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(options: Omit<RequestOptions<TData, ThrowOnError>, 'method'>) => Promise<ServerSentEventsResult<TData, TError>>;
|
|
620
|
+
type RequestFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false>(options: Omit<RequestOptions<TData, ThrowOnError>, 'method'> & Pick<Required<RequestOptions<TData, ThrowOnError>>, 'method'>) => RequestResult<TData, TError, ThrowOnError>;
|
|
621
|
+
type BuildUrlFn = <TData extends {
|
|
622
|
+
body?: unknown;
|
|
623
|
+
path?: Record<string, unknown>;
|
|
624
|
+
query?: Record<string, unknown>;
|
|
625
|
+
url: string;
|
|
626
|
+
}>(options: TData & Options<TData>) => string;
|
|
627
|
+
type Client = Client$1<RequestFn, Config, MethodFn, BuildUrlFn, SseFn> & {
|
|
628
|
+
interceptors: Middleware<Response, unknown, ResolvedRequestOptions>;
|
|
629
|
+
};
|
|
630
|
+
interface TDataShape {
|
|
631
|
+
body?: unknown;
|
|
632
|
+
headers?: unknown;
|
|
633
|
+
path?: unknown;
|
|
634
|
+
query?: unknown;
|
|
635
|
+
url: string;
|
|
636
|
+
}
|
|
637
|
+
type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>;
|
|
638
|
+
type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean, TResponse = unknown> = OmitKeys<RequestOptions<TResponse, ThrowOnError>, 'body' | 'path' | 'query' | 'url'> & ([TData] extends [never] ? unknown : Omit<TData, 'url'>);
|
|
639
|
+
|
|
351
640
|
/**
|
|
352
641
|
* Parameter definition for a client-side tool
|
|
353
642
|
*/
|
|
@@ -1455,7 +1744,7 @@ declare function executeTool(tool: ClientTool, params: Record<string, unknown>):
|
|
|
1455
1744
|
* Dropbox uses OAuth 2.0 with PKCE for browser apps.
|
|
1456
1745
|
*/
|
|
1457
1746
|
/** Default folder path for Dropbox backups */
|
|
1458
|
-
declare const DEFAULT_BACKUP_FOLDER = "/ai-chat-app/conversations";
|
|
1747
|
+
declare const DEFAULT_BACKUP_FOLDER$1 = "/ai-chat-app/conversations";
|
|
1459
1748
|
|
|
1460
1749
|
/**
|
|
1461
1750
|
* Dropbox Backup Implementation
|
|
@@ -1567,26 +1856,23 @@ interface UseDropboxBackupResult {
|
|
|
1567
1856
|
declare function useDropboxBackup(options: UseDropboxBackupOptions): UseDropboxBackupResult;
|
|
1568
1857
|
|
|
1569
1858
|
/**
|
|
1570
|
-
* Dropbox OAuth 2.0
|
|
1859
|
+
* Dropbox OAuth 2.0 Authorization Code Flow
|
|
1571
1860
|
*
|
|
1572
1861
|
* Flow:
|
|
1573
|
-
* 1.
|
|
1574
|
-
* 2.
|
|
1575
|
-
* 3.
|
|
1576
|
-
* 4.
|
|
1862
|
+
* 1. Redirect user to Dropbox authorization URL
|
|
1863
|
+
* 2. User authorizes and is redirected back with authorization code
|
|
1864
|
+
* 3. Exchange code on backend for access + refresh tokens
|
|
1865
|
+
* 4. Use refresh token to get new access tokens silently
|
|
1577
1866
|
*/
|
|
1867
|
+
|
|
1578
1868
|
/**
|
|
1579
|
-
*
|
|
1580
|
-
*/
|
|
1581
|
-
declare function getStoredToken(): string | null;
|
|
1582
|
-
/**
|
|
1583
|
-
* Store access token in session storage
|
|
1869
|
+
* Clear Dropbox token data
|
|
1584
1870
|
*/
|
|
1585
|
-
declare function
|
|
1871
|
+
declare function clearToken(): void;
|
|
1586
1872
|
/**
|
|
1587
|
-
*
|
|
1873
|
+
* Check if we have any stored credentials (including refresh token)
|
|
1588
1874
|
*/
|
|
1589
|
-
declare function
|
|
1875
|
+
declare function hasDropboxCredentials(): boolean;
|
|
1590
1876
|
|
|
1591
1877
|
/**
|
|
1592
1878
|
* Props for DropboxAuthProvider
|
|
@@ -1594,8 +1880,13 @@ declare function clearToken(): void;
|
|
|
1594
1880
|
interface DropboxAuthProviderProps {
|
|
1595
1881
|
/** Dropbox App Key (from Dropbox Developer Console) */
|
|
1596
1882
|
appKey: string | undefined;
|
|
1597
|
-
/** OAuth callback path (
|
|
1883
|
+
/** OAuth callback path (default: "/auth/dropbox/callback") */
|
|
1598
1884
|
callbackPath?: string;
|
|
1885
|
+
/**
|
|
1886
|
+
* API client for backend OAuth requests. Optional - uses the default SDK client if not provided.
|
|
1887
|
+
* Only needed if you have a custom client configuration (e.g., different baseUrl).
|
|
1888
|
+
*/
|
|
1889
|
+
apiClient?: Client;
|
|
1599
1890
|
/** Children to render */
|
|
1600
1891
|
children: ReactNode;
|
|
1601
1892
|
}
|
|
@@ -1612,13 +1903,15 @@ interface DropboxAuthContextValue {
|
|
|
1612
1903
|
/** Request Dropbox access - returns token or redirects to OAuth */
|
|
1613
1904
|
requestAccess: () => Promise<string>;
|
|
1614
1905
|
/** Clear stored token and log out */
|
|
1615
|
-
logout: () => void
|
|
1906
|
+
logout: () => Promise<void>;
|
|
1907
|
+
/** Refresh the access token using the refresh token */
|
|
1908
|
+
refreshToken: () => Promise<string | null>;
|
|
1616
1909
|
}
|
|
1617
1910
|
/**
|
|
1618
1911
|
* Provider component for Dropbox OAuth authentication.
|
|
1619
1912
|
*
|
|
1620
1913
|
* Wrap your app with this provider to enable Dropbox authentication.
|
|
1621
|
-
* It handles the OAuth 2.0
|
|
1914
|
+
* It handles the OAuth 2.0 Authorization Code flow with refresh tokens.
|
|
1622
1915
|
*
|
|
1623
1916
|
* @example
|
|
1624
1917
|
* ```tsx
|
|
@@ -1638,7 +1931,7 @@ interface DropboxAuthContextValue {
|
|
|
1638
1931
|
*
|
|
1639
1932
|
* @category Components
|
|
1640
1933
|
*/
|
|
1641
|
-
declare function DropboxAuthProvider({ appKey, callbackPath, children, }: DropboxAuthProviderProps): JSX.Element;
|
|
1934
|
+
declare function DropboxAuthProvider({ appKey, callbackPath, apiClient, children, }: DropboxAuthProviderProps): JSX.Element;
|
|
1642
1935
|
/**
|
|
1643
1936
|
* Hook to access Dropbox authentication state and methods.
|
|
1644
1937
|
*
|
|
@@ -1667,6 +1960,115 @@ declare function DropboxAuthProvider({ appKey, callbackPath, children, }: Dropbo
|
|
|
1667
1960
|
*/
|
|
1668
1961
|
declare function useDropboxAuth(): DropboxAuthContextValue;
|
|
1669
1962
|
|
|
1963
|
+
/**
|
|
1964
|
+
* Google Drive OAuth 2.0 Authorization Code Flow
|
|
1965
|
+
*
|
|
1966
|
+
* Flow:
|
|
1967
|
+
* 1. Redirect user to Google authorization URL
|
|
1968
|
+
* 2. User authorizes and is redirected back with authorization code
|
|
1969
|
+
* 3. Exchange code on backend for access + refresh tokens
|
|
1970
|
+
* 4. Use refresh token to get new access tokens silently
|
|
1971
|
+
*/
|
|
1972
|
+
|
|
1973
|
+
/**
|
|
1974
|
+
* Get stored token data for Google Drive
|
|
1975
|
+
*/
|
|
1976
|
+
declare function getGoogleDriveStoredToken(): string | null;
|
|
1977
|
+
/**
|
|
1978
|
+
* Clear Google Drive token data
|
|
1979
|
+
*/
|
|
1980
|
+
declare function clearGoogleDriveToken(): void;
|
|
1981
|
+
/**
|
|
1982
|
+
* Check if we have any stored credentials (including refresh token)
|
|
1983
|
+
*/
|
|
1984
|
+
declare function hasGoogleDriveCredentials(): boolean;
|
|
1985
|
+
|
|
1986
|
+
/**
|
|
1987
|
+
* Props for GoogleDriveAuthProvider
|
|
1988
|
+
*/
|
|
1989
|
+
interface GoogleDriveAuthProviderProps {
|
|
1990
|
+
/** Google OAuth Client ID (from Google Cloud Console) */
|
|
1991
|
+
clientId: string | undefined;
|
|
1992
|
+
/** OAuth callback path (default: "/auth/google/callback") */
|
|
1993
|
+
callbackPath?: string;
|
|
1994
|
+
/**
|
|
1995
|
+
* API client for backend OAuth requests. Optional - uses the default SDK client if not provided.
|
|
1996
|
+
* Only needed if you have a custom client configuration (e.g., different baseUrl).
|
|
1997
|
+
*/
|
|
1998
|
+
apiClient?: Client;
|
|
1999
|
+
/** Children to render */
|
|
2000
|
+
children: ReactNode;
|
|
2001
|
+
}
|
|
2002
|
+
/**
|
|
2003
|
+
* Context value for Google Drive authentication
|
|
2004
|
+
*/
|
|
2005
|
+
interface GoogleDriveAuthContextValue {
|
|
2006
|
+
/** Current access token (null if not authenticated) */
|
|
2007
|
+
accessToken: string | null;
|
|
2008
|
+
/** Whether user has authenticated with Google Drive */
|
|
2009
|
+
isAuthenticated: boolean;
|
|
2010
|
+
/** Whether Google Drive is configured (client ID exists) */
|
|
2011
|
+
isConfigured: boolean;
|
|
2012
|
+
/** Request Google Drive access - returns token or redirects to OAuth */
|
|
2013
|
+
requestAccess: () => Promise<string>;
|
|
2014
|
+
/** Clear stored token and log out */
|
|
2015
|
+
logout: () => Promise<void>;
|
|
2016
|
+
/** Refresh the access token using the refresh token */
|
|
2017
|
+
refreshToken: () => Promise<string | null>;
|
|
2018
|
+
}
|
|
2019
|
+
/**
|
|
2020
|
+
* Provider component for Google Drive OAuth authentication.
|
|
2021
|
+
*
|
|
2022
|
+
* Wrap your app with this provider to enable Google Drive authentication.
|
|
2023
|
+
* It handles the OAuth 2.0 Authorization Code flow with refresh tokens.
|
|
2024
|
+
*
|
|
2025
|
+
* @example
|
|
2026
|
+
* ```tsx
|
|
2027
|
+
* import { GoogleDriveAuthProvider } from "@reverbia/sdk/react";
|
|
2028
|
+
*
|
|
2029
|
+
* function App() {
|
|
2030
|
+
* return (
|
|
2031
|
+
* <GoogleDriveAuthProvider
|
|
2032
|
+
* clientId={process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID}
|
|
2033
|
+
* callbackPath="/auth/google/callback"
|
|
2034
|
+
* >
|
|
2035
|
+
* <MyApp />
|
|
2036
|
+
* </GoogleDriveAuthProvider>
|
|
2037
|
+
* );
|
|
2038
|
+
* }
|
|
2039
|
+
* ```
|
|
2040
|
+
*
|
|
2041
|
+
* @category Components
|
|
2042
|
+
*/
|
|
2043
|
+
declare function GoogleDriveAuthProvider({ clientId, callbackPath, apiClient, children, }: GoogleDriveAuthProviderProps): JSX.Element;
|
|
2044
|
+
/**
|
|
2045
|
+
* Hook to access Google Drive authentication state and methods.
|
|
2046
|
+
*
|
|
2047
|
+
* Must be used within a GoogleDriveAuthProvider.
|
|
2048
|
+
*
|
|
2049
|
+
* @example
|
|
2050
|
+
* ```tsx
|
|
2051
|
+
* import { useGoogleDriveAuth } from "@reverbia/sdk/react";
|
|
2052
|
+
*
|
|
2053
|
+
* function GoogleDriveButton() {
|
|
2054
|
+
* const { isAuthenticated, isConfigured, requestAccess, logout } = useGoogleDriveAuth();
|
|
2055
|
+
*
|
|
2056
|
+
* if (!isConfigured) {
|
|
2057
|
+
* return <p>Google Drive not configured</p>;
|
|
2058
|
+
* }
|
|
2059
|
+
*
|
|
2060
|
+
* if (isAuthenticated) {
|
|
2061
|
+
* return <button onClick={logout}>Disconnect Google Drive</button>;
|
|
2062
|
+
* }
|
|
2063
|
+
*
|
|
2064
|
+
* return <button onClick={requestAccess}>Connect Google Drive</button>;
|
|
2065
|
+
* }
|
|
2066
|
+
* ```
|
|
2067
|
+
*
|
|
2068
|
+
* @category Hooks
|
|
2069
|
+
*/
|
|
2070
|
+
declare function useGoogleDriveAuth(): GoogleDriveAuthContextValue;
|
|
2071
|
+
|
|
1670
2072
|
/**
|
|
1671
2073
|
* Google Drive API utilities
|
|
1672
2074
|
*
|
|
@@ -1708,10 +2110,6 @@ interface UseGoogleDriveBackupOptions {
|
|
|
1708
2110
|
database: Database;
|
|
1709
2111
|
/** Current user address (null if not signed in) */
|
|
1710
2112
|
userAddress: string | null;
|
|
1711
|
-
/** Current Google Drive access token (null if not authenticated) */
|
|
1712
|
-
accessToken: string | null;
|
|
1713
|
-
/** Request Google Drive access - returns access token */
|
|
1714
|
-
requestDriveAccess: () => Promise<string>;
|
|
1715
2113
|
/** Request encryption key for the user address */
|
|
1716
2114
|
requestEncryptionKey: (address: string) => Promise<void>;
|
|
1717
2115
|
/** Export a conversation to an encrypted blob */
|
|
@@ -1744,6 +2142,8 @@ interface UseGoogleDriveBackupResult {
|
|
|
1744
2142
|
}) => Promise<GoogleDriveImportResult | {
|
|
1745
2143
|
error: string;
|
|
1746
2144
|
}>;
|
|
2145
|
+
/** Whether Google Drive is configured */
|
|
2146
|
+
isConfigured: boolean;
|
|
1747
2147
|
/** Whether user has a Google Drive token */
|
|
1748
2148
|
isAuthenticated: boolean;
|
|
1749
2149
|
}
|
|
@@ -1752,23 +2152,18 @@ interface UseGoogleDriveBackupResult {
|
|
|
1752
2152
|
*
|
|
1753
2153
|
* This hook provides methods to backup conversations to Google Drive and restore them.
|
|
1754
2154
|
* It handles all the logic for checking timestamps, skipping unchanged files,
|
|
1755
|
-
* and managing the backup/restore process.
|
|
2155
|
+
* authentication, and managing the backup/restore process.
|
|
1756
2156
|
*
|
|
1757
|
-
*
|
|
1758
|
-
* so the auth provider must be implemented in the app. This hook accepts the auth
|
|
1759
|
-
* callbacks as options.
|
|
2157
|
+
* Must be used within a GoogleDriveAuthProvider.
|
|
1760
2158
|
*
|
|
1761
2159
|
* @example
|
|
1762
2160
|
* ```tsx
|
|
1763
2161
|
* import { useGoogleDriveBackup } from "@reverbia/sdk/react";
|
|
1764
2162
|
*
|
|
1765
2163
|
* function BackupButton() {
|
|
1766
|
-
* const {
|
|
1767
|
-
* const { backup, restore, isAuthenticated } = useGoogleDriveBackup({
|
|
2164
|
+
* const { backup, restore, isConfigured, isAuthenticated } = useGoogleDriveBackup({
|
|
1768
2165
|
* database,
|
|
1769
2166
|
* userAddress,
|
|
1770
|
-
* accessToken,
|
|
1771
|
-
* requestDriveAccess,
|
|
1772
2167
|
* requestEncryptionKey,
|
|
1773
2168
|
* exportConversation,
|
|
1774
2169
|
* importConversation,
|
|
@@ -1788,7 +2183,7 @@ interface UseGoogleDriveBackupResult {
|
|
|
1788
2183
|
* }
|
|
1789
2184
|
* };
|
|
1790
2185
|
*
|
|
1791
|
-
* return <button onClick={handleBackup}>Backup</button>;
|
|
2186
|
+
* return <button onClick={handleBackup} disabled={!isConfigured}>Backup</button>;
|
|
1792
2187
|
* }
|
|
1793
2188
|
* ```
|
|
1794
2189
|
*
|
|
@@ -1796,4 +2191,614 @@ interface UseGoogleDriveBackupResult {
|
|
|
1796
2191
|
*/
|
|
1797
2192
|
declare function useGoogleDriveBackup(options: UseGoogleDriveBackupOptions): UseGoogleDriveBackupResult;
|
|
1798
2193
|
|
|
1799
|
-
|
|
2194
|
+
/**
|
|
2195
|
+
* Props for ICloudAuthProvider
|
|
2196
|
+
*/
|
|
2197
|
+
interface ICloudAuthProviderProps {
|
|
2198
|
+
/** CloudKit API token (from Apple Developer Console) */
|
|
2199
|
+
apiToken: string;
|
|
2200
|
+
/** CloudKit container identifier (default: "iCloud.Memoryless") */
|
|
2201
|
+
containerIdentifier?: string;
|
|
2202
|
+
/** CloudKit environment (default: "production") */
|
|
2203
|
+
environment?: "development" | "production";
|
|
2204
|
+
/** Children to render */
|
|
2205
|
+
children: ReactNode;
|
|
2206
|
+
}
|
|
2207
|
+
/**
|
|
2208
|
+
* Context value for iCloud authentication
|
|
2209
|
+
*/
|
|
2210
|
+
interface ICloudAuthContextValue {
|
|
2211
|
+
/** Whether user is authenticated with iCloud */
|
|
2212
|
+
isAuthenticated: boolean;
|
|
2213
|
+
/** Whether iCloud is configured and available */
|
|
2214
|
+
isConfigured: boolean;
|
|
2215
|
+
/** Whether CloudKit JS is loaded */
|
|
2216
|
+
isAvailable: boolean;
|
|
2217
|
+
/** User record name (unique identifier) */
|
|
2218
|
+
userRecordName: string | null;
|
|
2219
|
+
/** Request access - triggers iCloud sign-in if needed */
|
|
2220
|
+
requestAccess: () => Promise<void>;
|
|
2221
|
+
/** Sign out from iCloud */
|
|
2222
|
+
logout: () => void;
|
|
2223
|
+
}
|
|
2224
|
+
/**
|
|
2225
|
+
* Provider component for iCloud authentication.
|
|
2226
|
+
*
|
|
2227
|
+
* Wrap your app with this provider to enable iCloud authentication.
|
|
2228
|
+
* CloudKit JS is loaded automatically when needed.
|
|
2229
|
+
*
|
|
2230
|
+
* @example
|
|
2231
|
+
* ```tsx
|
|
2232
|
+
* import { ICloudAuthProvider } from "@reverbia/sdk/react";
|
|
2233
|
+
*
|
|
2234
|
+
* function App() {
|
|
2235
|
+
* return (
|
|
2236
|
+
* <ICloudAuthProvider
|
|
2237
|
+
* apiToken={process.env.NEXT_PUBLIC_CLOUDKIT_API_TOKEN!}
|
|
2238
|
+
* containerIdentifier="iCloud.Memoryless"
|
|
2239
|
+
* environment="production"
|
|
2240
|
+
* >
|
|
2241
|
+
* <MyApp />
|
|
2242
|
+
* </ICloudAuthProvider>
|
|
2243
|
+
* );
|
|
2244
|
+
* }
|
|
2245
|
+
* ```
|
|
2246
|
+
*
|
|
2247
|
+
* @category Components
|
|
2248
|
+
*/
|
|
2249
|
+
declare function ICloudAuthProvider({ apiToken, containerIdentifier, environment, children, }: ICloudAuthProviderProps): JSX.Element;
|
|
2250
|
+
/**
|
|
2251
|
+
* Hook to access iCloud authentication state and methods.
|
|
2252
|
+
*
|
|
2253
|
+
* Must be used within an ICloudAuthProvider.
|
|
2254
|
+
*
|
|
2255
|
+
* @example
|
|
2256
|
+
* ```tsx
|
|
2257
|
+
* import { useICloudAuth } from "@reverbia/sdk/react";
|
|
2258
|
+
*
|
|
2259
|
+
* function ICloudStatus() {
|
|
2260
|
+
* const { isAuthenticated, isAvailable, requestAccess, logout } = useICloudAuth();
|
|
2261
|
+
*
|
|
2262
|
+
* if (!isAvailable) {
|
|
2263
|
+
* return <p>iCloud is not available. Please load CloudKit JS.</p>;
|
|
2264
|
+
* }
|
|
2265
|
+
*
|
|
2266
|
+
* return (
|
|
2267
|
+
* <div>
|
|
2268
|
+
* {isAuthenticated ? (
|
|
2269
|
+
* <>
|
|
2270
|
+
* <span>Connected to iCloud</span>
|
|
2271
|
+
* <button onClick={logout}>Disconnect</button>
|
|
2272
|
+
* </>
|
|
2273
|
+
* ) : (
|
|
2274
|
+
* <button onClick={requestAccess}>Connect to iCloud</button>
|
|
2275
|
+
* )}
|
|
2276
|
+
* </div>
|
|
2277
|
+
* );
|
|
2278
|
+
* }
|
|
2279
|
+
* ```
|
|
2280
|
+
*
|
|
2281
|
+
* @category Hooks
|
|
2282
|
+
*/
|
|
2283
|
+
declare function useICloudAuth(): ICloudAuthContextValue;
|
|
2284
|
+
/**
|
|
2285
|
+
* Check if iCloud is configured (has API token)
|
|
2286
|
+
*/
|
|
2287
|
+
declare function hasICloudCredentials(): boolean;
|
|
2288
|
+
/**
|
|
2289
|
+
* Clear iCloud authentication state
|
|
2290
|
+
* Note: This only clears local state; user remains signed in to iCloud
|
|
2291
|
+
*/
|
|
2292
|
+
declare function clearICloudAuth(): void;
|
|
2293
|
+
|
|
2294
|
+
/**
|
|
2295
|
+
* iCloud CloudKit API utilities
|
|
2296
|
+
*
|
|
2297
|
+
* Uses Apple CloudKit JS for file operations in iCloud Drive.
|
|
2298
|
+
* Requires CloudKit container configuration and user authentication.
|
|
2299
|
+
*
|
|
2300
|
+
* CloudKit JS is loaded dynamically when needed.
|
|
2301
|
+
*/
|
|
2302
|
+
/** Default folder path for iCloud backups */
|
|
2303
|
+
declare const DEFAULT_BACKUP_FOLDER = "conversations";
|
|
2304
|
+
/** CloudKit record structure */
|
|
2305
|
+
interface CloudKitRecord {
|
|
2306
|
+
recordName: string;
|
|
2307
|
+
recordType: string;
|
|
2308
|
+
fields: {
|
|
2309
|
+
filename?: {
|
|
2310
|
+
value: string;
|
|
2311
|
+
};
|
|
2312
|
+
data?: {
|
|
2313
|
+
value: {
|
|
2314
|
+
downloadURL: string;
|
|
2315
|
+
size: number;
|
|
2316
|
+
};
|
|
2317
|
+
};
|
|
2318
|
+
};
|
|
2319
|
+
modified?: {
|
|
2320
|
+
timestamp: number;
|
|
2321
|
+
};
|
|
2322
|
+
created?: {
|
|
2323
|
+
timestamp: number;
|
|
2324
|
+
};
|
|
2325
|
+
}
|
|
2326
|
+
/** CloudKit response structure */
|
|
2327
|
+
interface CloudKitResponse {
|
|
2328
|
+
records?: CloudKitRecord[];
|
|
2329
|
+
continuationMarker?: string;
|
|
2330
|
+
}
|
|
2331
|
+
declare global {
|
|
2332
|
+
interface Window {
|
|
2333
|
+
CloudKit?: {
|
|
2334
|
+
configure: (config: {
|
|
2335
|
+
containers: Array<{
|
|
2336
|
+
containerIdentifier: string;
|
|
2337
|
+
apiTokenAuth: {
|
|
2338
|
+
apiToken: string;
|
|
2339
|
+
persist: boolean;
|
|
2340
|
+
signInButton?: {
|
|
2341
|
+
id: string;
|
|
2342
|
+
theme?: string;
|
|
2343
|
+
};
|
|
2344
|
+
signOutButton?: {
|
|
2345
|
+
id: string;
|
|
2346
|
+
theme?: string;
|
|
2347
|
+
};
|
|
2348
|
+
};
|
|
2349
|
+
environment: string;
|
|
2350
|
+
}>;
|
|
2351
|
+
}) => void;
|
|
2352
|
+
getDefaultContainer: () => CloudKitContainer;
|
|
2353
|
+
};
|
|
2354
|
+
}
|
|
2355
|
+
}
|
|
2356
|
+
interface CloudKitContainer {
|
|
2357
|
+
containerIdentifier: string;
|
|
2358
|
+
setUpAuth: (options?: {
|
|
2359
|
+
buttonContainer?: HTMLElement;
|
|
2360
|
+
signInButtonId?: string;
|
|
2361
|
+
signOutButtonId?: string;
|
|
2362
|
+
}) => Promise<CloudKitUserIdentity | null>;
|
|
2363
|
+
whenUserSignsIn: () => Promise<CloudKitUserIdentity>;
|
|
2364
|
+
whenUserSignsOut: () => Promise<void>;
|
|
2365
|
+
privateCloudDatabase: CloudKitDatabase;
|
|
2366
|
+
}
|
|
2367
|
+
interface CloudKitUserIdentity {
|
|
2368
|
+
userRecordName: string;
|
|
2369
|
+
isDiscoverable?: boolean;
|
|
2370
|
+
}
|
|
2371
|
+
interface CloudKitDatabase {
|
|
2372
|
+
saveRecords: (records: CloudKitRecordToSave | CloudKitRecordToSave[], options?: {
|
|
2373
|
+
zoneName?: string;
|
|
2374
|
+
}) => Promise<CloudKitResponse>;
|
|
2375
|
+
deleteRecords: (recordNames: {
|
|
2376
|
+
recordName: string;
|
|
2377
|
+
}[], options?: {
|
|
2378
|
+
zoneName?: string;
|
|
2379
|
+
}) => Promise<CloudKitResponse>;
|
|
2380
|
+
performQuery: (query: CloudKitQuery) => Promise<CloudKitResponse>;
|
|
2381
|
+
fetchRecords: (recordNames: Array<{
|
|
2382
|
+
recordName: string;
|
|
2383
|
+
}>, options?: {
|
|
2384
|
+
desiredKeys?: string[];
|
|
2385
|
+
}) => Promise<CloudKitResponse>;
|
|
2386
|
+
}
|
|
2387
|
+
interface CloudKitRecordToSave {
|
|
2388
|
+
recordType: string;
|
|
2389
|
+
recordName?: string;
|
|
2390
|
+
fields: Record<string, {
|
|
2391
|
+
value: unknown;
|
|
2392
|
+
}>;
|
|
2393
|
+
}
|
|
2394
|
+
interface CloudKitQuery {
|
|
2395
|
+
recordType: string;
|
|
2396
|
+
filterBy?: Array<{
|
|
2397
|
+
fieldName: string;
|
|
2398
|
+
comparator: string;
|
|
2399
|
+
fieldValue: {
|
|
2400
|
+
value: unknown;
|
|
2401
|
+
};
|
|
2402
|
+
}>;
|
|
2403
|
+
sortBy?: Array<{
|
|
2404
|
+
fieldName: string;
|
|
2405
|
+
ascending: boolean;
|
|
2406
|
+
}>;
|
|
2407
|
+
}
|
|
2408
|
+
|
|
2409
|
+
/**
|
|
2410
|
+
* iCloud Backup Implementation
|
|
2411
|
+
*
|
|
2412
|
+
* Generic backup/restore functionality for iCloud storage.
|
|
2413
|
+
* Works directly with WatermelonDB database.
|
|
2414
|
+
*/
|
|
2415
|
+
|
|
2416
|
+
interface ICloudExportResult {
|
|
2417
|
+
success: boolean;
|
|
2418
|
+
uploaded: number;
|
|
2419
|
+
skipped: number;
|
|
2420
|
+
total: number;
|
|
2421
|
+
}
|
|
2422
|
+
interface ICloudImportResult {
|
|
2423
|
+
success: boolean;
|
|
2424
|
+
restored: number;
|
|
2425
|
+
failed: number;
|
|
2426
|
+
total: number;
|
|
2427
|
+
/** True if no backups were found in iCloud */
|
|
2428
|
+
noBackupsFound?: boolean;
|
|
2429
|
+
}
|
|
2430
|
+
|
|
2431
|
+
/**
|
|
2432
|
+
* Options for useICloudBackup hook
|
|
2433
|
+
*/
|
|
2434
|
+
interface UseICloudBackupOptions {
|
|
2435
|
+
/** WatermelonDB database instance */
|
|
2436
|
+
database: Database;
|
|
2437
|
+
/** Current user address (null if not signed in) */
|
|
2438
|
+
userAddress: string | null;
|
|
2439
|
+
/** Request encryption key for the user address */
|
|
2440
|
+
requestEncryptionKey: (address: string) => Promise<void>;
|
|
2441
|
+
/** Export a conversation to an encrypted blob */
|
|
2442
|
+
exportConversation: (conversationId: string, userAddress: string) => Promise<{
|
|
2443
|
+
success: boolean;
|
|
2444
|
+
blob?: Blob;
|
|
2445
|
+
}>;
|
|
2446
|
+
/** Import a conversation from an encrypted blob */
|
|
2447
|
+
importConversation: (blob: Blob, userAddress: string) => Promise<{
|
|
2448
|
+
success: boolean;
|
|
2449
|
+
}>;
|
|
2450
|
+
}
|
|
2451
|
+
/**
|
|
2452
|
+
* Result returned by useICloudBackup hook
|
|
2453
|
+
*/
|
|
2454
|
+
interface UseICloudBackupResult {
|
|
2455
|
+
/** Backup all conversations to iCloud */
|
|
2456
|
+
backup: (options?: {
|
|
2457
|
+
onProgress?: (current: number, total: number) => void;
|
|
2458
|
+
}) => Promise<ICloudExportResult | {
|
|
2459
|
+
error: string;
|
|
2460
|
+
}>;
|
|
2461
|
+
/** Restore conversations from iCloud */
|
|
2462
|
+
restore: (options?: {
|
|
2463
|
+
onProgress?: (current: number, total: number) => void;
|
|
2464
|
+
}) => Promise<ICloudImportResult | {
|
|
2465
|
+
error: string;
|
|
2466
|
+
}>;
|
|
2467
|
+
/** Whether iCloud is configured */
|
|
2468
|
+
isConfigured: boolean;
|
|
2469
|
+
/** Whether user has signed in to iCloud */
|
|
2470
|
+
isAuthenticated: boolean;
|
|
2471
|
+
/** Whether CloudKit JS is available */
|
|
2472
|
+
isAvailable: boolean;
|
|
2473
|
+
}
|
|
2474
|
+
/**
|
|
2475
|
+
* React hook for iCloud backup and restore functionality.
|
|
2476
|
+
*
|
|
2477
|
+
* This hook provides methods to backup conversations to iCloud and restore them.
|
|
2478
|
+
* It handles all the logic for checking timestamps, skipping unchanged files,
|
|
2479
|
+
* authentication, and managing the backup/restore process.
|
|
2480
|
+
*
|
|
2481
|
+
* Must be used within an ICloudAuthProvider.
|
|
2482
|
+
*
|
|
2483
|
+
* @example
|
|
2484
|
+
* ```tsx
|
|
2485
|
+
* import { useICloudBackup } from "@reverbia/sdk/react";
|
|
2486
|
+
*
|
|
2487
|
+
* function BackupButton() {
|
|
2488
|
+
* const { backup, restore, isConfigured, isAuthenticated, isAvailable } = useICloudBackup({
|
|
2489
|
+
* database,
|
|
2490
|
+
* userAddress,
|
|
2491
|
+
* requestEncryptionKey,
|
|
2492
|
+
* exportConversation,
|
|
2493
|
+
* importConversation,
|
|
2494
|
+
* });
|
|
2495
|
+
*
|
|
2496
|
+
* if (!isAvailable) {
|
|
2497
|
+
* return <p>CloudKit JS not loaded</p>;
|
|
2498
|
+
* }
|
|
2499
|
+
*
|
|
2500
|
+
* const handleBackup = async () => {
|
|
2501
|
+
* const result = await backup({
|
|
2502
|
+
* onProgress: (current, total) => {
|
|
2503
|
+
* console.log(`Progress: ${current}/${total}`);
|
|
2504
|
+
* },
|
|
2505
|
+
* });
|
|
2506
|
+
*
|
|
2507
|
+
* if ("error" in result) {
|
|
2508
|
+
* console.error(result.error);
|
|
2509
|
+
* } else {
|
|
2510
|
+
* console.log(`Uploaded: ${result.uploaded}, Skipped: ${result.skipped}`);
|
|
2511
|
+
* }
|
|
2512
|
+
* };
|
|
2513
|
+
*
|
|
2514
|
+
* return <button onClick={handleBackup} disabled={!isConfigured}>Backup to iCloud</button>;
|
|
2515
|
+
* }
|
|
2516
|
+
* ```
|
|
2517
|
+
*
|
|
2518
|
+
* @category Hooks
|
|
2519
|
+
*/
|
|
2520
|
+
declare function useICloudBackup(options: UseICloudBackupOptions): UseICloudBackupResult;
|
|
2521
|
+
|
|
2522
|
+
/**
|
|
2523
|
+
* Props for BackupAuthProvider
|
|
2524
|
+
*
|
|
2525
|
+
* At least one of `dropboxAppKey`, `googleClientId`, or `icloudApiToken` should be provided
|
|
2526
|
+
* for the provider to be useful. All are optional to allow using just one backup provider.
|
|
2527
|
+
*/
|
|
2528
|
+
interface BackupAuthProviderProps {
|
|
2529
|
+
/** Dropbox App Key (from Dropbox Developer Console). Optional - omit to disable Dropbox. */
|
|
2530
|
+
dropboxAppKey?: string;
|
|
2531
|
+
/** Dropbox OAuth callback path (default: "/auth/dropbox/callback") */
|
|
2532
|
+
dropboxCallbackPath?: string;
|
|
2533
|
+
/** Google OAuth Client ID (from Google Cloud Console). Optional - omit to disable Google Drive. */
|
|
2534
|
+
googleClientId?: string;
|
|
2535
|
+
/** Google OAuth callback path (default: "/auth/google/callback") */
|
|
2536
|
+
googleCallbackPath?: string;
|
|
2537
|
+
/** CloudKit API token (from Apple Developer Console). Optional - omit to disable iCloud. */
|
|
2538
|
+
icloudApiToken?: string;
|
|
2539
|
+
/** CloudKit container identifier (default: "iCloud.Memoryless") */
|
|
2540
|
+
icloudContainerIdentifier?: string;
|
|
2541
|
+
/** CloudKit environment (default: "production") */
|
|
2542
|
+
icloudEnvironment?: "development" | "production";
|
|
2543
|
+
/**
|
|
2544
|
+
* API client for backend OAuth requests. Optional - uses the default SDK client if not provided.
|
|
2545
|
+
* Only needed if you have a custom client configuration (e.g., different baseUrl).
|
|
2546
|
+
*/
|
|
2547
|
+
apiClient?: Client;
|
|
2548
|
+
/** Children to render */
|
|
2549
|
+
children: ReactNode;
|
|
2550
|
+
}
|
|
2551
|
+
/**
|
|
2552
|
+
* Auth state for a single provider
|
|
2553
|
+
*/
|
|
2554
|
+
interface ProviderAuthState {
|
|
2555
|
+
/** Current access token (null if not authenticated) */
|
|
2556
|
+
accessToken: string | null;
|
|
2557
|
+
/** Whether user has authenticated with this provider */
|
|
2558
|
+
isAuthenticated: boolean;
|
|
2559
|
+
/** Whether this provider is configured */
|
|
2560
|
+
isConfigured: boolean;
|
|
2561
|
+
/** Request access - returns token or redirects to OAuth */
|
|
2562
|
+
requestAccess: () => Promise<string>;
|
|
2563
|
+
/** Clear stored token and log out */
|
|
2564
|
+
logout: () => Promise<void>;
|
|
2565
|
+
/** Refresh the access token using the refresh token */
|
|
2566
|
+
refreshToken: () => Promise<string | null>;
|
|
2567
|
+
}
|
|
2568
|
+
/**
|
|
2569
|
+
* Context value for unified backup authentication
|
|
2570
|
+
*/
|
|
2571
|
+
interface BackupAuthContextValue {
|
|
2572
|
+
/** Dropbox authentication state and methods */
|
|
2573
|
+
dropbox: ProviderAuthState;
|
|
2574
|
+
/** Google Drive authentication state and methods */
|
|
2575
|
+
googleDrive: ProviderAuthState;
|
|
2576
|
+
/** iCloud authentication state and methods */
|
|
2577
|
+
icloud: ProviderAuthState;
|
|
2578
|
+
/** Check if any provider is configured */
|
|
2579
|
+
hasAnyProvider: boolean;
|
|
2580
|
+
/** Check if any provider is authenticated */
|
|
2581
|
+
hasAnyAuthentication: boolean;
|
|
2582
|
+
/** Logout from all providers */
|
|
2583
|
+
logoutAll: () => Promise<void>;
|
|
2584
|
+
}
|
|
2585
|
+
/**
|
|
2586
|
+
* Unified provider component for backup OAuth authentication.
|
|
2587
|
+
*
|
|
2588
|
+
* Wrap your app with this provider to enable both Dropbox and Google Drive
|
|
2589
|
+
* authentication. It handles the OAuth 2.0 Authorization Code flow with
|
|
2590
|
+
* refresh tokens for both providers.
|
|
2591
|
+
*
|
|
2592
|
+
* @example
|
|
2593
|
+
* ```tsx
|
|
2594
|
+
* import { BackupAuthProvider } from "@reverbia/sdk/react";
|
|
2595
|
+
*
|
|
2596
|
+
* function App() {
|
|
2597
|
+
* return (
|
|
2598
|
+
* <BackupAuthProvider
|
|
2599
|
+
* dropboxAppKey={process.env.NEXT_PUBLIC_DROPBOX_APP_KEY}
|
|
2600
|
+
* dropboxCallbackPath="/auth/dropbox/callback"
|
|
2601
|
+
* googleClientId={process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID}
|
|
2602
|
+
* googleCallbackPath="/auth/google/callback"
|
|
2603
|
+
* icloudApiToken={process.env.NEXT_PUBLIC_CLOUDKIT_API_TOKEN}
|
|
2604
|
+
* icloudContainerIdentifier="iCloud.Memoryless"
|
|
2605
|
+
* apiClient={apiClient}
|
|
2606
|
+
* >
|
|
2607
|
+
* <MyApp />
|
|
2608
|
+
* </BackupAuthProvider>
|
|
2609
|
+
* );
|
|
2610
|
+
* }
|
|
2611
|
+
* ```
|
|
2612
|
+
*
|
|
2613
|
+
* @category Components
|
|
2614
|
+
*/
|
|
2615
|
+
declare function BackupAuthProvider({ dropboxAppKey, dropboxCallbackPath, googleClientId, googleCallbackPath, icloudApiToken, icloudContainerIdentifier, icloudEnvironment, apiClient, children, }: BackupAuthProviderProps): JSX.Element;
|
|
2616
|
+
/**
|
|
2617
|
+
* Hook to access unified backup authentication state and methods.
|
|
2618
|
+
*
|
|
2619
|
+
* Must be used within a BackupAuthProvider.
|
|
2620
|
+
*
|
|
2621
|
+
* @example
|
|
2622
|
+
* ```tsx
|
|
2623
|
+
* import { useBackupAuth } from "@reverbia/sdk/react";
|
|
2624
|
+
*
|
|
2625
|
+
* function BackupSettings() {
|
|
2626
|
+
* const { dropbox, googleDrive, logoutAll } = useBackupAuth();
|
|
2627
|
+
*
|
|
2628
|
+
* return (
|
|
2629
|
+
* <div>
|
|
2630
|
+
* <h3>Backup Providers</h3>
|
|
2631
|
+
*
|
|
2632
|
+
* {dropbox.isConfigured && (
|
|
2633
|
+
* <div>
|
|
2634
|
+
* <span>Dropbox: {dropbox.isAuthenticated ? 'Connected' : 'Not connected'}</span>
|
|
2635
|
+
* {dropbox.isAuthenticated ? (
|
|
2636
|
+
* <button onClick={dropbox.logout}>Disconnect</button>
|
|
2637
|
+
* ) : (
|
|
2638
|
+
* <button onClick={dropbox.requestAccess}>Connect</button>
|
|
2639
|
+
* )}
|
|
2640
|
+
* </div>
|
|
2641
|
+
* )}
|
|
2642
|
+
*
|
|
2643
|
+
* {googleDrive.isConfigured && (
|
|
2644
|
+
* <div>
|
|
2645
|
+
* <span>Google Drive: {googleDrive.isAuthenticated ? 'Connected' : 'Not connected'}</span>
|
|
2646
|
+
* {googleDrive.isAuthenticated ? (
|
|
2647
|
+
* <button onClick={googleDrive.logout}>Disconnect</button>
|
|
2648
|
+
* ) : (
|
|
2649
|
+
* <button onClick={googleDrive.requestAccess}>Connect</button>
|
|
2650
|
+
* )}
|
|
2651
|
+
* </div>
|
|
2652
|
+
* )}
|
|
2653
|
+
*
|
|
2654
|
+
* <button onClick={logoutAll}>Disconnect All</button>
|
|
2655
|
+
* </div>
|
|
2656
|
+
* );
|
|
2657
|
+
* }
|
|
2658
|
+
* ```
|
|
2659
|
+
*
|
|
2660
|
+
* @category Hooks
|
|
2661
|
+
*/
|
|
2662
|
+
declare function useBackupAuth(): BackupAuthContextValue;
|
|
2663
|
+
|
|
2664
|
+
/**
|
|
2665
|
+
* Options for useBackup hook
|
|
2666
|
+
*/
|
|
2667
|
+
interface UseBackupOptions {
|
|
2668
|
+
/** WatermelonDB database instance */
|
|
2669
|
+
database: Database;
|
|
2670
|
+
/** Current user address (null if not signed in) */
|
|
2671
|
+
userAddress: string | null;
|
|
2672
|
+
/** Request encryption key for the user address */
|
|
2673
|
+
requestEncryptionKey: (address: string) => Promise<void>;
|
|
2674
|
+
/** Export a conversation to an encrypted blob */
|
|
2675
|
+
exportConversation: (conversationId: string, userAddress: string) => Promise<{
|
|
2676
|
+
success: boolean;
|
|
2677
|
+
blob?: Blob;
|
|
2678
|
+
}>;
|
|
2679
|
+
/** Import a conversation from an encrypted blob */
|
|
2680
|
+
importConversation: (blob: Blob, userAddress: string) => Promise<{
|
|
2681
|
+
success: boolean;
|
|
2682
|
+
}>;
|
|
2683
|
+
/** Dropbox folder path for backups (default: '/ai-chat-app/conversations') */
|
|
2684
|
+
dropboxFolder?: string;
|
|
2685
|
+
/** Google Drive root folder name (default: 'ai-chat-app') */
|
|
2686
|
+
googleRootFolder?: string;
|
|
2687
|
+
/** Google Drive conversations subfolder (default: 'conversations') */
|
|
2688
|
+
googleConversationsFolder?: string;
|
|
2689
|
+
}
|
|
2690
|
+
/**
|
|
2691
|
+
* Progress callback type
|
|
2692
|
+
*/
|
|
2693
|
+
type ProgressCallback = (current: number, total: number) => void;
|
|
2694
|
+
/**
|
|
2695
|
+
* Backup options for individual operations
|
|
2696
|
+
*/
|
|
2697
|
+
interface BackupOperationOptions {
|
|
2698
|
+
onProgress?: ProgressCallback;
|
|
2699
|
+
}
|
|
2700
|
+
/**
|
|
2701
|
+
* Provider-specific backup state
|
|
2702
|
+
*/
|
|
2703
|
+
interface ProviderBackupState {
|
|
2704
|
+
/** Whether the provider is configured */
|
|
2705
|
+
isConfigured: boolean;
|
|
2706
|
+
/** Whether user has authenticated with this provider */
|
|
2707
|
+
isAuthenticated: boolean;
|
|
2708
|
+
/** Backup all conversations to this provider */
|
|
2709
|
+
backup: (options?: BackupOperationOptions) => Promise<DropboxExportResult | GoogleDriveExportResult | ICloudExportResult | {
|
|
2710
|
+
error: string;
|
|
2711
|
+
}>;
|
|
2712
|
+
/** Restore conversations from this provider */
|
|
2713
|
+
restore: (options?: BackupOperationOptions) => Promise<DropboxImportResult | GoogleDriveImportResult | ICloudImportResult | {
|
|
2714
|
+
error: string;
|
|
2715
|
+
}>;
|
|
2716
|
+
/** Request access to this provider (triggers OAuth if needed) */
|
|
2717
|
+
connect: () => Promise<string>;
|
|
2718
|
+
/** Disconnect from this provider */
|
|
2719
|
+
disconnect: () => Promise<void>;
|
|
2720
|
+
}
|
|
2721
|
+
/**
|
|
2722
|
+
* Result returned by useBackup hook
|
|
2723
|
+
*/
|
|
2724
|
+
interface UseBackupResult {
|
|
2725
|
+
/** Dropbox backup state and methods */
|
|
2726
|
+
dropbox: ProviderBackupState;
|
|
2727
|
+
/** Google Drive backup state and methods */
|
|
2728
|
+
googleDrive: ProviderBackupState;
|
|
2729
|
+
/** iCloud backup state and methods */
|
|
2730
|
+
icloud: ProviderBackupState;
|
|
2731
|
+
/** Whether any backup provider is configured */
|
|
2732
|
+
hasAnyProvider: boolean;
|
|
2733
|
+
/** Whether any backup provider is authenticated */
|
|
2734
|
+
hasAnyAuthentication: boolean;
|
|
2735
|
+
/** Disconnect from all providers */
|
|
2736
|
+
disconnectAll: () => Promise<void>;
|
|
2737
|
+
}
|
|
2738
|
+
/**
|
|
2739
|
+
* Unified React hook for backup and restore functionality.
|
|
2740
|
+
*
|
|
2741
|
+
* This hook provides methods to backup conversations to both Dropbox and Google Drive,
|
|
2742
|
+
* and restore them. It handles all the logic for checking timestamps, skipping
|
|
2743
|
+
* unchanged files, authentication, and managing the backup/restore process.
|
|
2744
|
+
*
|
|
2745
|
+
* Must be used within a BackupAuthProvider.
|
|
2746
|
+
*
|
|
2747
|
+
* @example
|
|
2748
|
+
* ```tsx
|
|
2749
|
+
* import { useBackup } from "@reverbia/sdk/react";
|
|
2750
|
+
*
|
|
2751
|
+
* function BackupManager() {
|
|
2752
|
+
* const { dropbox, googleDrive, hasAnyProvider } = useBackup({
|
|
2753
|
+
* database,
|
|
2754
|
+
* userAddress,
|
|
2755
|
+
* requestEncryptionKey,
|
|
2756
|
+
* exportConversation,
|
|
2757
|
+
* importConversation,
|
|
2758
|
+
* });
|
|
2759
|
+
*
|
|
2760
|
+
* if (!hasAnyProvider) {
|
|
2761
|
+
* return <p>No backup providers configured</p>;
|
|
2762
|
+
* }
|
|
2763
|
+
*
|
|
2764
|
+
* return (
|
|
2765
|
+
* <div>
|
|
2766
|
+
* {dropbox.isConfigured && (
|
|
2767
|
+
* <div>
|
|
2768
|
+
* <h3>Dropbox</h3>
|
|
2769
|
+
* {dropbox.isAuthenticated ? (
|
|
2770
|
+
* <>
|
|
2771
|
+
* <button onClick={() => dropbox.backup()}>Backup</button>
|
|
2772
|
+
* <button onClick={() => dropbox.restore()}>Restore</button>
|
|
2773
|
+
* <button onClick={dropbox.disconnect}>Disconnect</button>
|
|
2774
|
+
* </>
|
|
2775
|
+
* ) : (
|
|
2776
|
+
* <button onClick={dropbox.connect}>Connect Dropbox</button>
|
|
2777
|
+
* )}
|
|
2778
|
+
* </div>
|
|
2779
|
+
* )}
|
|
2780
|
+
*
|
|
2781
|
+
* {googleDrive.isConfigured && (
|
|
2782
|
+
* <div>
|
|
2783
|
+
* <h3>Google Drive</h3>
|
|
2784
|
+
* {googleDrive.isAuthenticated ? (
|
|
2785
|
+
* <>
|
|
2786
|
+
* <button onClick={() => googleDrive.backup()}>Backup</button>
|
|
2787
|
+
* <button onClick={() => googleDrive.restore()}>Restore</button>
|
|
2788
|
+
* <button onClick={googleDrive.disconnect}>Disconnect</button>
|
|
2789
|
+
* </>
|
|
2790
|
+
* ) : (
|
|
2791
|
+
* <button onClick={googleDrive.connect}>Connect Google Drive</button>
|
|
2792
|
+
* )}
|
|
2793
|
+
* </div>
|
|
2794
|
+
* )}
|
|
2795
|
+
* </div>
|
|
2796
|
+
* );
|
|
2797
|
+
* }
|
|
2798
|
+
* ```
|
|
2799
|
+
*
|
|
2800
|
+
* @category Hooks
|
|
2801
|
+
*/
|
|
2802
|
+
declare function useBackup(options: UseBackupOptions): UseBackupResult;
|
|
2803
|
+
|
|
2804
|
+
export { DEFAULT_CONVERSATIONS_FOLDER as BACKUP_DRIVE_CONVERSATIONS_FOLDER, DEFAULT_ROOT_FOLDER as BACKUP_DRIVE_ROOT_FOLDER, DEFAULT_BACKUP_FOLDER as BACKUP_ICLOUD_FOLDER, type BackupAuthContextValue, BackupAuthProvider, type BackupAuthProviderProps, type BackupOperationOptions, Conversation as ChatConversation, Message as ChatMessage, type ChatRole, type ClientTool, type CreateConversationOptions, type CreateMemoryOptions, type CreateMessageOptions, type CreateModelPreferenceOptions, DEFAULT_BACKUP_FOLDER$1 as DEFAULT_BACKUP_FOLDER, DEFAULT_CONVERSATIONS_FOLDER as DEFAULT_DRIVE_CONVERSATIONS_FOLDER, DEFAULT_ROOT_FOLDER as DEFAULT_DRIVE_ROOT_FOLDER, DEFAULT_BACKUP_FOLDER$1 as DEFAULT_DROPBOX_FOLDER, DEFAULT_BACKUP_FOLDER as DEFAULT_ICLOUD_BACKUP_FOLDER, DEFAULT_TOOL_SELECTOR_MODEL, type DropboxAuthContextValue, DropboxAuthProvider, type DropboxAuthProviderProps, type DropboxExportResult, type DropboxImportResult, type FileMetadata, type GoogleDriveAuthContextValue, GoogleDriveAuthProvider, type GoogleDriveAuthProviderProps, type GoogleDriveExportResult, type GoogleDriveImportResult, type ICloudAuthContextValue, ICloudAuthProvider, type ICloudAuthProviderProps, type ICloudExportResult, type ICloudImportResult, type MemoryItem, type MemoryType, type OCRFile, type PdfFile, type ProgressCallback, type ProviderAuthState, type ProviderBackupState, type SearchMessagesOptions, type SearchSource, type SendMessageWithStorageArgs, type SendMessageWithStorageResult, type SignMessageFn, type ChatCompletionUsage as StoredChatCompletionUsage, type StoredConversation, type StoredMemory, Memory as StoredMemoryModel, type StoredMemoryWithSimilarity, type StoredMessage, type StoredMessageWithSimilarity, type StoredModelPreference, ModelPreference as StoredModelPreferenceModel, type ToolExecutionResult, type ToolParameter, type ToolSelectionResult, type UpdateMemoryOptions, type UpdateModelPreferenceOptions, type UseBackupOptions, type UseBackupResult, type UseChatStorageOptions, type UseChatStorageResult, type UseDropboxBackupOptions, type UseDropboxBackupResult, type UseGoogleDriveBackupOptions, type UseGoogleDriveBackupResult, type UseICloudBackupOptions, type UseICloudBackupResult, type UseMemoryStorageOptions, type UseMemoryStorageResult, type UseSettingsOptions, type UseSettingsResult, chatStorageMigrations, chatStorageSchema, clearToken as clearDropboxToken, clearGoogleDriveToken, clearICloudAuth, createMemoryContextSystemMessage, decryptData, decryptDataBytes, encryptData, executeTool, extractConversationContext, formatMemoriesForChat, generateCompositeKey, generateConversationId, generateUniqueKey, getGoogleDriveStoredToken, hasDropboxCredentials, hasEncryptionKey, hasGoogleDriveCredentials, hasICloudCredentials, memoryStorageSchema, requestEncryptionKey, sdkMigrations, sdkModelClasses, sdkSchema, selectTool, settingsStorageSchema, useBackup, useBackupAuth, useChat, useChatStorage, useDropboxAuth, useDropboxBackup, useEncryption, useGoogleDriveAuth, useGoogleDriveBackup, useICloudAuth, useICloudBackup, useImageGeneration, useMemoryStorage, useModels, useOCR, usePdf, useSearch, useSettings };
|