@ragable/sdk 0.6.18 → 0.6.20

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
@@ -590,7 +590,18 @@ declare class AuthBroadcastChannel {
590
590
  }
591
591
 
592
592
  type AuthChangeEvent = "INITIAL_SESSION" | "SIGNED_IN" | "SIGNED_OUT" | "TOKEN_REFRESHED" | "USER_UPDATED";
593
- interface AuthSession<U extends Record<string, unknown> = Record<string, unknown>> {
593
+ type AuthUserMetadata = Record<string, unknown>;
594
+ interface DefaultAuthUser<Metadata extends AuthUserMetadata = AuthUserMetadata> {
595
+ id: string;
596
+ email: string;
597
+ name: string | null;
598
+ status: "active" | "disabled" | (string & {});
599
+ metadata: Metadata;
600
+ createdAt?: string;
601
+ updatedAt?: string;
602
+ lastSignInAt?: string | null;
603
+ }
604
+ interface AuthSession<U extends object = DefaultAuthUser> {
594
605
  access_token: string;
595
606
  refresh_token: string;
596
607
  expires_in: number;
@@ -612,12 +623,31 @@ interface RagableAuthConfig {
612
623
  headers?: HeadersInit;
613
624
  auth?: AuthOptions;
614
625
  }
615
- type AuthListener<U extends Record<string, unknown>> = (event: AuthChangeEvent, session: AuthSession<U> | null) => void;
626
+ type AuthSignUpCredentials<Metadata extends AuthUserMetadata = AuthUserMetadata> = {
627
+ email: string;
628
+ password: string;
629
+ options?: {
630
+ data?: Partial<Metadata> & {
631
+ name?: string | null;
632
+ };
633
+ };
634
+ };
635
+ type AuthUpdateUserAttributes<Metadata extends AuthUserMetadata = AuthUserMetadata> = {
636
+ email?: string;
637
+ password?: string;
638
+ data?: Partial<Metadata> & {
639
+ name?: string | null;
640
+ };
641
+ };
642
+ type MetadataForUser<U extends object> = U extends {
643
+ metadata: infer Metadata;
644
+ } ? Metadata extends AuthUserMetadata ? Metadata : AuthUserMetadata : AuthUserMetadata;
645
+ type AuthListener<U extends object> = (event: AuthChangeEvent, session: AuthSession<U> | null) => void;
616
646
  interface Subscription {
617
647
  id: string;
618
648
  unsubscribe: () => void;
619
649
  }
620
- declare class RagableAuth<U extends Record<string, unknown> = Record<string, unknown>> {
650
+ declare class RagableAuth<U extends object = DefaultAuthUser> {
621
651
  private readonly fetchImpl;
622
652
  private readonly baseUrl;
623
653
  private readonly authGroupId;
@@ -638,13 +668,7 @@ declare class RagableAuth<U extends Record<string, unknown> = Record<string, unk
638
668
  constructor(config: RagableAuthConfig);
639
669
  private log;
640
670
  initialize(): Promise<AuthSession<U> | null>;
641
- signUp(credentials: {
642
- email: string;
643
- password: string;
644
- options?: {
645
- data?: Record<string, unknown>;
646
- };
647
- }): Promise<PostgrestResult<{
671
+ signUp(credentials: AuthSignUpCredentials<MetadataForUser<U>>): Promise<PostgrestResult<{
648
672
  user: U;
649
673
  session: AuthSession<U>;
650
674
  }>>;
@@ -680,9 +704,9 @@ declare class RagableAuth<U extends Record<string, unknown> = Record<string, unk
680
704
  updateUser(attributes: {
681
705
  email?: string;
682
706
  password?: string;
683
- data?: {
707
+ data?: (Partial<MetadataForUser<U>> & {
684
708
  name?: string | null;
685
- };
709
+ });
686
710
  }): Promise<PostgrestResult<{
687
711
  user: U;
688
712
  }>>;
@@ -692,11 +716,15 @@ declare class RagableAuth<U extends Record<string, unknown> = Record<string, unk
692
716
  };
693
717
  };
694
718
  getAccessToken(): string | null;
719
+ getValidAccessToken(): Promise<string | null>;
695
720
  getCurrentSession(): AuthSession<U> | null;
696
721
  register(body: {
697
722
  email: string;
698
723
  password: string;
699
724
  name?: string;
725
+ data?: Partial<MetadataForUser<U>> & {
726
+ name?: string | null;
727
+ };
700
728
  }): Promise<{
701
729
  user: U;
702
730
  accessToken: string;
@@ -723,8 +751,12 @@ declare class RagableAuth<U extends Record<string, unknown> = Record<string, unk
723
751
  user: U;
724
752
  }>;
725
753
  updateMe(body: {
754
+ email?: string;
726
755
  name?: string | null;
727
756
  password?: string;
757
+ data?: Partial<MetadataForUser<U>> & {
758
+ name?: string | null;
759
+ };
728
760
  }): Promise<{
729
761
  user: U;
730
762
  }>;
@@ -817,7 +849,7 @@ interface RagableBrowserClientOptions {
817
849
  auth?: AuthOptions;
818
850
  transport?: Partial<TransportOptions>;
819
851
  }
820
- interface BrowserAuthSession<AuthUser extends Record<string, unknown> = Record<string, unknown>> {
852
+ interface BrowserAuthSession<AuthUser extends object = DefaultAuthUser> {
821
853
  user: AuthUser;
822
854
  accessToken: string;
823
855
  refreshToken: string;
@@ -828,7 +860,7 @@ interface BrowserAuthTokens {
828
860
  refreshToken: string;
829
861
  expiresIn: string;
830
862
  }
831
- interface SupabaseCompatSession<AuthUser extends Record<string, unknown> = Record<string, unknown>> {
863
+ interface SupabaseCompatSession<AuthUser extends object = DefaultAuthUser> {
832
864
  access_token: string;
833
865
  refresh_token: string;
834
866
  expires_in: number;
@@ -836,17 +868,13 @@ interface SupabaseCompatSession<AuthUser extends Record<string, unknown> = Recor
836
868
  user: AuthUser;
837
869
  }
838
870
 
839
- declare class RagableBrowserAuthClient<AuthUser extends Record<string, unknown> = Record<string, unknown>> {
871
+ declare class RagableBrowserAuthClient<AuthUser extends object = DefaultAuthUser> {
840
872
  private readonly ragableAuth;
841
873
  constructor(_options: RagableBrowserClientOptions, ragableAuth?: RagableAuth<AuthUser> | null);
842
874
  private get auth();
843
- signUp(credentials: {
844
- email: string;
845
- password: string;
846
- options?: {
847
- data?: Record<string, unknown>;
848
- };
849
- }): Promise<PostgrestResult<{
875
+ signUp(credentials: AuthSignUpCredentials<AuthUser extends {
876
+ metadata: infer Metadata;
877
+ } ? Metadata extends AuthUserMetadata ? Metadata : AuthUserMetadata : AuthUserMetadata>): Promise<PostgrestResult<{
850
878
  user: AuthUser;
851
879
  session: SupabaseCompatSession<AuthUser>;
852
880
  }>>;
@@ -864,13 +892,9 @@ declare class RagableBrowserAuthClient<AuthUser extends Record<string, unknown>
864
892
  getUser(): Promise<PostgrestResult<{
865
893
  user: AuthUser;
866
894
  }>>;
867
- updateUser(attributes: {
868
- email?: string;
869
- password?: string;
870
- data?: {
871
- name?: string | null;
872
- };
873
- }): Promise<PostgrestResult<{
895
+ updateUser(attributes: AuthUpdateUserAttributes<AuthUser extends {
896
+ metadata: infer Metadata;
897
+ } ? Metadata extends AuthUserMetadata ? Metadata : AuthUserMetadata : AuthUserMetadata>): Promise<PostgrestResult<{
874
898
  user: AuthUser;
875
899
  }>>;
876
900
  signOut(_options?: {
@@ -882,6 +906,11 @@ declare class RagableBrowserAuthClient<AuthUser extends Record<string, unknown>
882
906
  email: string;
883
907
  password: string;
884
908
  name?: string;
909
+ data?: AuthUser extends {
910
+ metadata: infer Metadata;
911
+ } ? Metadata extends AuthUserMetadata ? Partial<Metadata> & {
912
+ name?: string | null;
913
+ } : Record<string, unknown> : Record<string, unknown>;
885
914
  }): Promise<BrowserAuthSession<AuthUser>>;
886
915
  login(body: {
887
916
  email: string;
@@ -894,8 +923,14 @@ declare class RagableBrowserAuthClient<AuthUser extends Record<string, unknown>
894
923
  user: AuthUser;
895
924
  }>;
896
925
  updateMe(body: {
926
+ email?: string;
897
927
  name?: string | null;
898
928
  password?: string;
929
+ data?: AuthUser extends {
930
+ metadata: infer Metadata;
931
+ } ? Metadata extends AuthUserMetadata ? Partial<Metadata> & {
932
+ name?: string | null;
933
+ } : Record<string, unknown> : Record<string, unknown>;
899
934
  }): Promise<{
900
935
  user: AuthUser;
901
936
  }>;
@@ -926,11 +961,29 @@ interface BrowserSqlQueryResult<Row extends Record<string, unknown> = Record<str
926
961
  rows: Row[];
927
962
  }
928
963
  interface BrowserCollectionRecord<Row extends Record<string, unknown> = Record<string, unknown>> {
964
+ [key: string]: unknown;
929
965
  id: string;
930
966
  data: Row;
931
967
  createdAt: string;
932
968
  updatedAt: string;
933
969
  }
970
+ /**
971
+ * Collection APIs return record envelopes, but user schema `Row` types should be
972
+ * the JSON row inside `record.data`. If generated app types accidentally use the
973
+ * envelope as `Row`, unwrap it so consumers still get `record.data.<field>`.
974
+ */
975
+ type BrowserCollectionRowData<Row extends Record<string, unknown> = Record<string, unknown>> = Row extends {
976
+ id: string;
977
+ data: infer Data;
978
+ createdAt: string;
979
+ updatedAt: string;
980
+ } ? Data extends Record<string, unknown> ? Data : Row : Row;
981
+ type BrowserCollectionInsertData<Row extends Record<string, unknown>, Insert extends Record<string, unknown>> = BrowserCollectionRowData<Row> extends Row ? Insert : Insert extends {
982
+ data: infer Data;
983
+ } ? Data extends Record<string, unknown> ? Data : BrowserCollectionRowData<Row> : BrowserCollectionRowData<Row>;
984
+ type BrowserCollectionUpdateData<Row extends Record<string, unknown>, Update extends Record<string, unknown>> = BrowserCollectionRowData<Row> extends Row ? Update : Update extends {
985
+ data?: infer Data;
986
+ } ? Data extends Record<string, unknown> ? Partial<Data> : Partial<BrowserCollectionRowData<Row>> : Partial<BrowserCollectionRowData<Row>>;
934
987
  interface BrowserCollectionDefinition {
935
988
  id: string;
936
989
  name: string;
@@ -963,16 +1016,16 @@ declare class BrowserCollectionApi<Row extends Record<string, unknown> = Record<
963
1016
  private readonly name;
964
1017
  private readonly databaseInstanceId?;
965
1018
  constructor(database: RagableBrowserDatabaseClient<any>, name: string, databaseInstanceId?: string | undefined);
966
- find: (whereOrParams?: CollectionWhere<Row> | BrowserCollectionFindParams<Row>) => Promise<PostgrestResult<BrowserCollectionRecord<Row>[]>>;
967
- insert: (data: Insert) => Promise<PostgrestResult<BrowserCollectionRecord<Row>>>;
968
- update: (where: CollectionWhere<Row>, patch: Update, options?: {
1019
+ find: (whereOrParams?: CollectionWhere<BrowserCollectionRowData<Row>> | BrowserCollectionFindParams<BrowserCollectionRowData<Row>>) => Promise<PostgrestResult<BrowserCollectionRecord<BrowserCollectionRowData<Row>>[]>>;
1020
+ insert: (data: BrowserCollectionInsertData<Row, Insert>) => Promise<PostgrestResult<BrowserCollectionRecord<BrowserCollectionRowData<Row>>>>;
1021
+ update: (where: CollectionWhere<BrowserCollectionRowData<Row>>, patch: BrowserCollectionUpdateData<Row, Update>, options?: {
969
1022
  limit?: number;
970
- }) => Promise<PostgrestResult<BrowserCollectionRecord<Row>[]>>;
971
- delete: (where: CollectionWhere<Row>, options?: {
1023
+ }) => Promise<PostgrestResult<BrowserCollectionRecord<BrowserCollectionRowData<Row>>[]>>;
1024
+ delete: (where: CollectionWhere<BrowserCollectionRowData<Row>>, options?: {
972
1025
  limit?: number;
973
1026
  }) => Promise<PostgrestResult<{
974
1027
  deleted: number;
975
- records: BrowserCollectionRecord<Row>[];
1028
+ records: BrowserCollectionRecord<BrowserCollectionRowData<Row>>[];
976
1029
  }>>;
977
1030
  }
978
1031
  type BrowserCollections<Database extends RagableDatabase = DefaultRagableDatabase> = [keyof Database["public"]["Tables"]] extends [never] ? Record<string, BrowserCollectionApi<Record<string, unknown>>> : {
@@ -1099,7 +1152,7 @@ interface AgentPublicChatParams extends AgentChatParams {
1099
1152
  triggerSubtype?: string;
1100
1153
  triggerNodeId?: string;
1101
1154
  }
1102
- declare class RagableBrowser<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends Record<string, unknown> = Record<string, unknown>> {
1155
+ declare class RagableBrowser<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser> {
1103
1156
  readonly agents: RagableBrowserAgentsClient;
1104
1157
  readonly auth: RagableBrowserAuthClient<AuthUser>;
1105
1158
  readonly database: RagableBrowserDatabaseClient<Database>;
@@ -1111,7 +1164,7 @@ declare class RagableBrowser<Database extends RagableDatabase = DefaultRagableDa
1111
1164
  from: <TableName extends RagableTableNames<Database>>(table: TableName, databaseInstanceId?: string) => PostgrestTableApi<Database, TableName>;
1112
1165
  destroy(): void;
1113
1166
  }
1114
- declare function createBrowserClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends Record<string, unknown> = Record<string, unknown>>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
1167
+ declare function createBrowserClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
1115
1168
  declare const createRagableBrowserClient: typeof createBrowserClient;
1116
1169
 
1117
1170
  /**
@@ -1186,7 +1239,7 @@ declare class Ragable {
1186
1239
  constructor(options: RagableClientOptions);
1187
1240
  }
1188
1241
  declare function createClient(options: RagableClientOptions): Ragable;
1189
- declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends Record<string, unknown> = Record<string, unknown>>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
1242
+ declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
1190
1243
  declare function createRagableServerClient(options: RagableClientOptions): Ragable;
1191
1244
 
1192
- export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentPublicChatParams, type AgentStreamEvent, type AgentSummary, AgentsClient, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, type AuthSession, type BrowserAuthSession, type BrowserAuthTokens, BrowserCollectionApi, type BrowserCollectionDefinition, type BrowserCollectionFactory, type BrowserCollectionFindParams, type BrowserCollectionRecord, type BrowserCollections, type BrowserDataAuthMode, type BrowserRealtimeNotification, type BrowserRealtimeStatus, type BrowserRealtimeSubscribeParams, type BrowserRealtimeSubscription, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultRagableDatabase, type FormatContextOptions, type HttpMethod, type Json, LocalStorageAdapter, MemoryStorageAdapter, type PostgRESTFetch, type PostgRESTFetchParams, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, PostgrestInsertSdkErrorReturning, PostgrestInsertSdkErrorRoot, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, type RagClientForPipeline, type RagPipeline, type RagPipelineOptions, Ragable, RagableAbortError, RagableAuth, type RagableAuthConfig, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, type RagableClientOptions, type RagableDatabase, RagableError, RagableNetworkError, RagableRequestClient, RagableSdkError, type RagableTableDefinition, type RagableTableNames, RagableTimeoutError, type RequestOptions, type RetrieveParams, type RetryOptions, type RunQuery, type SessionStorage, SessionStorageAdapter, type ShiftAddDocumentParams, ShiftClient, type ShiftCreateIndexParams, type ShiftEntry, type ShiftIndex, type ShiftIngestResponse, type ShiftListEntriesParams, type ShiftListEntriesResponse, type ShiftSearchParams, type ShiftSearchResult, type ShiftUpdateIndexParams, type ShiftUploadFileParams, type ShiftUploadableFile, type SseJsonEvent, type SupabaseCompatSession, type TableInsertRow, type TableRow, type TableUpdatePatch, type Tables, type TablesInsert, type TablesUpdate, Transport, type TransportOptions, type TransportRequest, asPostgrestResponse, bindFetch, createBrowserClient, createClient, createRagPipeline, createRagableBrowserClient, createRagableServerClient, detectStorage, effectiveDataAuth, extractErrorMessage, formatPostgrestError, formatRetrievalContext, formatSdkError, generateIdempotencyKey, normalizeBrowserApiBase, parseSseDataLine, parseTransportResponse, readSseStream };
1245
+ export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentPublicChatParams, type AgentStreamEvent, type AgentSummary, AgentsClient, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, type AuthSession, type AuthSignUpCredentials, type AuthUpdateUserAttributes, type AuthUserMetadata, type BrowserAuthSession, type BrowserAuthTokens, BrowserCollectionApi, type BrowserCollectionDefinition, type BrowserCollectionFactory, type BrowserCollectionFindParams, type BrowserCollectionRecord, type BrowserCollections, type BrowserDataAuthMode, type BrowserRealtimeNotification, type BrowserRealtimeStatus, type BrowserRealtimeSubscribeParams, type BrowserRealtimeSubscription, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultAuthUser, type DefaultRagableDatabase, type FormatContextOptions, type HttpMethod, type Json, LocalStorageAdapter, MemoryStorageAdapter, type PostgRESTFetch, type PostgRESTFetchParams, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, PostgrestInsertSdkErrorReturning, PostgrestInsertSdkErrorRoot, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, type RagClientForPipeline, type RagPipeline, type RagPipelineOptions, Ragable, RagableAbortError, RagableAuth, type RagableAuthConfig, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, type RagableClientOptions, type RagableDatabase, RagableError, RagableNetworkError, RagableRequestClient, RagableSdkError, type RagableTableDefinition, type RagableTableNames, RagableTimeoutError, type RequestOptions, type RetrieveParams, type RetryOptions, type RunQuery, type SessionStorage, SessionStorageAdapter, type ShiftAddDocumentParams, ShiftClient, type ShiftCreateIndexParams, type ShiftEntry, type ShiftIndex, type ShiftIngestResponse, type ShiftListEntriesParams, type ShiftListEntriesResponse, type ShiftSearchParams, type ShiftSearchResult, type ShiftUpdateIndexParams, type ShiftUploadFileParams, type ShiftUploadableFile, type SseJsonEvent, type SupabaseCompatSession, type TableInsertRow, type TableRow, type TableUpdatePatch, type Tables, type TablesInsert, type TablesUpdate, Transport, type TransportOptions, type TransportRequest, asPostgrestResponse, bindFetch, createBrowserClient, createClient, createRagPipeline, createRagableBrowserClient, createRagableServerClient, detectStorage, effectiveDataAuth, extractErrorMessage, formatPostgrestError, formatRetrievalContext, formatSdkError, generateIdempotencyKey, normalizeBrowserApiBase, parseSseDataLine, parseTransportResponse, readSseStream };
package/dist/index.d.ts CHANGED
@@ -590,7 +590,18 @@ declare class AuthBroadcastChannel {
590
590
  }
591
591
 
592
592
  type AuthChangeEvent = "INITIAL_SESSION" | "SIGNED_IN" | "SIGNED_OUT" | "TOKEN_REFRESHED" | "USER_UPDATED";
593
- interface AuthSession<U extends Record<string, unknown> = Record<string, unknown>> {
593
+ type AuthUserMetadata = Record<string, unknown>;
594
+ interface DefaultAuthUser<Metadata extends AuthUserMetadata = AuthUserMetadata> {
595
+ id: string;
596
+ email: string;
597
+ name: string | null;
598
+ status: "active" | "disabled" | (string & {});
599
+ metadata: Metadata;
600
+ createdAt?: string;
601
+ updatedAt?: string;
602
+ lastSignInAt?: string | null;
603
+ }
604
+ interface AuthSession<U extends object = DefaultAuthUser> {
594
605
  access_token: string;
595
606
  refresh_token: string;
596
607
  expires_in: number;
@@ -612,12 +623,31 @@ interface RagableAuthConfig {
612
623
  headers?: HeadersInit;
613
624
  auth?: AuthOptions;
614
625
  }
615
- type AuthListener<U extends Record<string, unknown>> = (event: AuthChangeEvent, session: AuthSession<U> | null) => void;
626
+ type AuthSignUpCredentials<Metadata extends AuthUserMetadata = AuthUserMetadata> = {
627
+ email: string;
628
+ password: string;
629
+ options?: {
630
+ data?: Partial<Metadata> & {
631
+ name?: string | null;
632
+ };
633
+ };
634
+ };
635
+ type AuthUpdateUserAttributes<Metadata extends AuthUserMetadata = AuthUserMetadata> = {
636
+ email?: string;
637
+ password?: string;
638
+ data?: Partial<Metadata> & {
639
+ name?: string | null;
640
+ };
641
+ };
642
+ type MetadataForUser<U extends object> = U extends {
643
+ metadata: infer Metadata;
644
+ } ? Metadata extends AuthUserMetadata ? Metadata : AuthUserMetadata : AuthUserMetadata;
645
+ type AuthListener<U extends object> = (event: AuthChangeEvent, session: AuthSession<U> | null) => void;
616
646
  interface Subscription {
617
647
  id: string;
618
648
  unsubscribe: () => void;
619
649
  }
620
- declare class RagableAuth<U extends Record<string, unknown> = Record<string, unknown>> {
650
+ declare class RagableAuth<U extends object = DefaultAuthUser> {
621
651
  private readonly fetchImpl;
622
652
  private readonly baseUrl;
623
653
  private readonly authGroupId;
@@ -638,13 +668,7 @@ declare class RagableAuth<U extends Record<string, unknown> = Record<string, unk
638
668
  constructor(config: RagableAuthConfig);
639
669
  private log;
640
670
  initialize(): Promise<AuthSession<U> | null>;
641
- signUp(credentials: {
642
- email: string;
643
- password: string;
644
- options?: {
645
- data?: Record<string, unknown>;
646
- };
647
- }): Promise<PostgrestResult<{
671
+ signUp(credentials: AuthSignUpCredentials<MetadataForUser<U>>): Promise<PostgrestResult<{
648
672
  user: U;
649
673
  session: AuthSession<U>;
650
674
  }>>;
@@ -680,9 +704,9 @@ declare class RagableAuth<U extends Record<string, unknown> = Record<string, unk
680
704
  updateUser(attributes: {
681
705
  email?: string;
682
706
  password?: string;
683
- data?: {
707
+ data?: (Partial<MetadataForUser<U>> & {
684
708
  name?: string | null;
685
- };
709
+ });
686
710
  }): Promise<PostgrestResult<{
687
711
  user: U;
688
712
  }>>;
@@ -692,11 +716,15 @@ declare class RagableAuth<U extends Record<string, unknown> = Record<string, unk
692
716
  };
693
717
  };
694
718
  getAccessToken(): string | null;
719
+ getValidAccessToken(): Promise<string | null>;
695
720
  getCurrentSession(): AuthSession<U> | null;
696
721
  register(body: {
697
722
  email: string;
698
723
  password: string;
699
724
  name?: string;
725
+ data?: Partial<MetadataForUser<U>> & {
726
+ name?: string | null;
727
+ };
700
728
  }): Promise<{
701
729
  user: U;
702
730
  accessToken: string;
@@ -723,8 +751,12 @@ declare class RagableAuth<U extends Record<string, unknown> = Record<string, unk
723
751
  user: U;
724
752
  }>;
725
753
  updateMe(body: {
754
+ email?: string;
726
755
  name?: string | null;
727
756
  password?: string;
757
+ data?: Partial<MetadataForUser<U>> & {
758
+ name?: string | null;
759
+ };
728
760
  }): Promise<{
729
761
  user: U;
730
762
  }>;
@@ -817,7 +849,7 @@ interface RagableBrowserClientOptions {
817
849
  auth?: AuthOptions;
818
850
  transport?: Partial<TransportOptions>;
819
851
  }
820
- interface BrowserAuthSession<AuthUser extends Record<string, unknown> = Record<string, unknown>> {
852
+ interface BrowserAuthSession<AuthUser extends object = DefaultAuthUser> {
821
853
  user: AuthUser;
822
854
  accessToken: string;
823
855
  refreshToken: string;
@@ -828,7 +860,7 @@ interface BrowserAuthTokens {
828
860
  refreshToken: string;
829
861
  expiresIn: string;
830
862
  }
831
- interface SupabaseCompatSession<AuthUser extends Record<string, unknown> = Record<string, unknown>> {
863
+ interface SupabaseCompatSession<AuthUser extends object = DefaultAuthUser> {
832
864
  access_token: string;
833
865
  refresh_token: string;
834
866
  expires_in: number;
@@ -836,17 +868,13 @@ interface SupabaseCompatSession<AuthUser extends Record<string, unknown> = Recor
836
868
  user: AuthUser;
837
869
  }
838
870
 
839
- declare class RagableBrowserAuthClient<AuthUser extends Record<string, unknown> = Record<string, unknown>> {
871
+ declare class RagableBrowserAuthClient<AuthUser extends object = DefaultAuthUser> {
840
872
  private readonly ragableAuth;
841
873
  constructor(_options: RagableBrowserClientOptions, ragableAuth?: RagableAuth<AuthUser> | null);
842
874
  private get auth();
843
- signUp(credentials: {
844
- email: string;
845
- password: string;
846
- options?: {
847
- data?: Record<string, unknown>;
848
- };
849
- }): Promise<PostgrestResult<{
875
+ signUp(credentials: AuthSignUpCredentials<AuthUser extends {
876
+ metadata: infer Metadata;
877
+ } ? Metadata extends AuthUserMetadata ? Metadata : AuthUserMetadata : AuthUserMetadata>): Promise<PostgrestResult<{
850
878
  user: AuthUser;
851
879
  session: SupabaseCompatSession<AuthUser>;
852
880
  }>>;
@@ -864,13 +892,9 @@ declare class RagableBrowserAuthClient<AuthUser extends Record<string, unknown>
864
892
  getUser(): Promise<PostgrestResult<{
865
893
  user: AuthUser;
866
894
  }>>;
867
- updateUser(attributes: {
868
- email?: string;
869
- password?: string;
870
- data?: {
871
- name?: string | null;
872
- };
873
- }): Promise<PostgrestResult<{
895
+ updateUser(attributes: AuthUpdateUserAttributes<AuthUser extends {
896
+ metadata: infer Metadata;
897
+ } ? Metadata extends AuthUserMetadata ? Metadata : AuthUserMetadata : AuthUserMetadata>): Promise<PostgrestResult<{
874
898
  user: AuthUser;
875
899
  }>>;
876
900
  signOut(_options?: {
@@ -882,6 +906,11 @@ declare class RagableBrowserAuthClient<AuthUser extends Record<string, unknown>
882
906
  email: string;
883
907
  password: string;
884
908
  name?: string;
909
+ data?: AuthUser extends {
910
+ metadata: infer Metadata;
911
+ } ? Metadata extends AuthUserMetadata ? Partial<Metadata> & {
912
+ name?: string | null;
913
+ } : Record<string, unknown> : Record<string, unknown>;
885
914
  }): Promise<BrowserAuthSession<AuthUser>>;
886
915
  login(body: {
887
916
  email: string;
@@ -894,8 +923,14 @@ declare class RagableBrowserAuthClient<AuthUser extends Record<string, unknown>
894
923
  user: AuthUser;
895
924
  }>;
896
925
  updateMe(body: {
926
+ email?: string;
897
927
  name?: string | null;
898
928
  password?: string;
929
+ data?: AuthUser extends {
930
+ metadata: infer Metadata;
931
+ } ? Metadata extends AuthUserMetadata ? Partial<Metadata> & {
932
+ name?: string | null;
933
+ } : Record<string, unknown> : Record<string, unknown>;
899
934
  }): Promise<{
900
935
  user: AuthUser;
901
936
  }>;
@@ -926,11 +961,29 @@ interface BrowserSqlQueryResult<Row extends Record<string, unknown> = Record<str
926
961
  rows: Row[];
927
962
  }
928
963
  interface BrowserCollectionRecord<Row extends Record<string, unknown> = Record<string, unknown>> {
964
+ [key: string]: unknown;
929
965
  id: string;
930
966
  data: Row;
931
967
  createdAt: string;
932
968
  updatedAt: string;
933
969
  }
970
+ /**
971
+ * Collection APIs return record envelopes, but user schema `Row` types should be
972
+ * the JSON row inside `record.data`. If generated app types accidentally use the
973
+ * envelope as `Row`, unwrap it so consumers still get `record.data.<field>`.
974
+ */
975
+ type BrowserCollectionRowData<Row extends Record<string, unknown> = Record<string, unknown>> = Row extends {
976
+ id: string;
977
+ data: infer Data;
978
+ createdAt: string;
979
+ updatedAt: string;
980
+ } ? Data extends Record<string, unknown> ? Data : Row : Row;
981
+ type BrowserCollectionInsertData<Row extends Record<string, unknown>, Insert extends Record<string, unknown>> = BrowserCollectionRowData<Row> extends Row ? Insert : Insert extends {
982
+ data: infer Data;
983
+ } ? Data extends Record<string, unknown> ? Data : BrowserCollectionRowData<Row> : BrowserCollectionRowData<Row>;
984
+ type BrowserCollectionUpdateData<Row extends Record<string, unknown>, Update extends Record<string, unknown>> = BrowserCollectionRowData<Row> extends Row ? Update : Update extends {
985
+ data?: infer Data;
986
+ } ? Data extends Record<string, unknown> ? Partial<Data> : Partial<BrowserCollectionRowData<Row>> : Partial<BrowserCollectionRowData<Row>>;
934
987
  interface BrowserCollectionDefinition {
935
988
  id: string;
936
989
  name: string;
@@ -963,16 +1016,16 @@ declare class BrowserCollectionApi<Row extends Record<string, unknown> = Record<
963
1016
  private readonly name;
964
1017
  private readonly databaseInstanceId?;
965
1018
  constructor(database: RagableBrowserDatabaseClient<any>, name: string, databaseInstanceId?: string | undefined);
966
- find: (whereOrParams?: CollectionWhere<Row> | BrowserCollectionFindParams<Row>) => Promise<PostgrestResult<BrowserCollectionRecord<Row>[]>>;
967
- insert: (data: Insert) => Promise<PostgrestResult<BrowserCollectionRecord<Row>>>;
968
- update: (where: CollectionWhere<Row>, patch: Update, options?: {
1019
+ find: (whereOrParams?: CollectionWhere<BrowserCollectionRowData<Row>> | BrowserCollectionFindParams<BrowserCollectionRowData<Row>>) => Promise<PostgrestResult<BrowserCollectionRecord<BrowserCollectionRowData<Row>>[]>>;
1020
+ insert: (data: BrowserCollectionInsertData<Row, Insert>) => Promise<PostgrestResult<BrowserCollectionRecord<BrowserCollectionRowData<Row>>>>;
1021
+ update: (where: CollectionWhere<BrowserCollectionRowData<Row>>, patch: BrowserCollectionUpdateData<Row, Update>, options?: {
969
1022
  limit?: number;
970
- }) => Promise<PostgrestResult<BrowserCollectionRecord<Row>[]>>;
971
- delete: (where: CollectionWhere<Row>, options?: {
1023
+ }) => Promise<PostgrestResult<BrowserCollectionRecord<BrowserCollectionRowData<Row>>[]>>;
1024
+ delete: (where: CollectionWhere<BrowserCollectionRowData<Row>>, options?: {
972
1025
  limit?: number;
973
1026
  }) => Promise<PostgrestResult<{
974
1027
  deleted: number;
975
- records: BrowserCollectionRecord<Row>[];
1028
+ records: BrowserCollectionRecord<BrowserCollectionRowData<Row>>[];
976
1029
  }>>;
977
1030
  }
978
1031
  type BrowserCollections<Database extends RagableDatabase = DefaultRagableDatabase> = [keyof Database["public"]["Tables"]] extends [never] ? Record<string, BrowserCollectionApi<Record<string, unknown>>> : {
@@ -1099,7 +1152,7 @@ interface AgentPublicChatParams extends AgentChatParams {
1099
1152
  triggerSubtype?: string;
1100
1153
  triggerNodeId?: string;
1101
1154
  }
1102
- declare class RagableBrowser<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends Record<string, unknown> = Record<string, unknown>> {
1155
+ declare class RagableBrowser<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser> {
1103
1156
  readonly agents: RagableBrowserAgentsClient;
1104
1157
  readonly auth: RagableBrowserAuthClient<AuthUser>;
1105
1158
  readonly database: RagableBrowserDatabaseClient<Database>;
@@ -1111,7 +1164,7 @@ declare class RagableBrowser<Database extends RagableDatabase = DefaultRagableDa
1111
1164
  from: <TableName extends RagableTableNames<Database>>(table: TableName, databaseInstanceId?: string) => PostgrestTableApi<Database, TableName>;
1112
1165
  destroy(): void;
1113
1166
  }
1114
- declare function createBrowserClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends Record<string, unknown> = Record<string, unknown>>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
1167
+ declare function createBrowserClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
1115
1168
  declare const createRagableBrowserClient: typeof createBrowserClient;
1116
1169
 
1117
1170
  /**
@@ -1186,7 +1239,7 @@ declare class Ragable {
1186
1239
  constructor(options: RagableClientOptions);
1187
1240
  }
1188
1241
  declare function createClient(options: RagableClientOptions): Ragable;
1189
- declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends Record<string, unknown> = Record<string, unknown>>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
1242
+ declare function createClient<Database extends RagableDatabase = DefaultRagableDatabase, AuthUser extends object = DefaultAuthUser>(options: RagableBrowserClientOptions): RagableBrowser<Database, AuthUser>;
1190
1243
  declare function createRagableServerClient(options: RagableClientOptions): Ragable;
1191
1244
 
1192
- export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentPublicChatParams, type AgentStreamEvent, type AgentSummary, AgentsClient, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, type AuthSession, type BrowserAuthSession, type BrowserAuthTokens, BrowserCollectionApi, type BrowserCollectionDefinition, type BrowserCollectionFactory, type BrowserCollectionFindParams, type BrowserCollectionRecord, type BrowserCollections, type BrowserDataAuthMode, type BrowserRealtimeNotification, type BrowserRealtimeStatus, type BrowserRealtimeSubscribeParams, type BrowserRealtimeSubscription, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultRagableDatabase, type FormatContextOptions, type HttpMethod, type Json, LocalStorageAdapter, MemoryStorageAdapter, type PostgRESTFetch, type PostgRESTFetchParams, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, PostgrestInsertSdkErrorReturning, PostgrestInsertSdkErrorRoot, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, type RagClientForPipeline, type RagPipeline, type RagPipelineOptions, Ragable, RagableAbortError, RagableAuth, type RagableAuthConfig, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, type RagableClientOptions, type RagableDatabase, RagableError, RagableNetworkError, RagableRequestClient, RagableSdkError, type RagableTableDefinition, type RagableTableNames, RagableTimeoutError, type RequestOptions, type RetrieveParams, type RetryOptions, type RunQuery, type SessionStorage, SessionStorageAdapter, type ShiftAddDocumentParams, ShiftClient, type ShiftCreateIndexParams, type ShiftEntry, type ShiftIndex, type ShiftIngestResponse, type ShiftListEntriesParams, type ShiftListEntriesResponse, type ShiftSearchParams, type ShiftSearchResult, type ShiftUpdateIndexParams, type ShiftUploadFileParams, type ShiftUploadableFile, type SseJsonEvent, type SupabaseCompatSession, type TableInsertRow, type TableRow, type TableUpdatePatch, type Tables, type TablesInsert, type TablesUpdate, Transport, type TransportOptions, type TransportRequest, asPostgrestResponse, bindFetch, createBrowserClient, createClient, createRagPipeline, createRagableBrowserClient, createRagableServerClient, detectStorage, effectiveDataAuth, extractErrorMessage, formatPostgrestError, formatRetrievalContext, formatSdkError, generateIdempotencyKey, normalizeBrowserApiBase, parseSseDataLine, parseTransportResponse, readSseStream };
1245
+ export { type AgentChatMessage, type AgentChatParams, type AgentChatResult, type AgentPublicChatParams, type AgentStreamEvent, type AgentSummary, AgentsClient, AuthBroadcastChannel, type AuthBroadcastMessage, type AuthChangeEvent, type AuthOptions, type AuthSession, type AuthSignUpCredentials, type AuthUpdateUserAttributes, type AuthUserMetadata, type BrowserAuthSession, type BrowserAuthTokens, BrowserCollectionApi, type BrowserCollectionDefinition, type BrowserCollectionFactory, type BrowserCollectionFindParams, type BrowserCollectionRecord, type BrowserCollections, type BrowserDataAuthMode, type BrowserRealtimeNotification, type BrowserRealtimeStatus, type BrowserRealtimeSubscribeParams, type BrowserRealtimeSubscription, type BrowserSqlExecParams, type BrowserSqlExecResult, type BrowserSqlQueryParams, type BrowserSqlQueryResult, type ColumnName, type ColumnValue, CookieStorageAdapter, DEFAULT_RAGABLE_API_BASE, type DefaultAuthUser, type DefaultRagableDatabase, type FormatContextOptions, type HttpMethod, type Json, LocalStorageAdapter, MemoryStorageAdapter, type PostgRESTFetch, type PostgRESTFetchParams, PostgrestDeleteReturningBuilder, PostgrestDeleteRootBuilder, PostgrestInsertReturningBuilder, PostgrestInsertRootBuilder, PostgrestInsertSdkErrorReturning, PostgrestInsertSdkErrorRoot, type PostgrestResult, PostgrestSelectBuilder, PostgrestTableApi, PostgrestUpdateReturningBuilder, PostgrestUpdateRootBuilder, type PostgrestUpsertOptions, PostgrestUpsertReturningBuilder, PostgrestUpsertRootBuilder, type RagClientForPipeline, type RagPipeline, type RagPipelineOptions, Ragable, RagableAbortError, RagableAuth, type RagableAuthConfig, RagableBrowser, RagableBrowserAgentsClient, RagableBrowserAuthClient, type RagableBrowserClientOptions, RagableBrowserDatabaseClient, type RagableClientOptions, type RagableDatabase, RagableError, RagableNetworkError, RagableRequestClient, RagableSdkError, type RagableTableDefinition, type RagableTableNames, RagableTimeoutError, type RequestOptions, type RetrieveParams, type RetryOptions, type RunQuery, type SessionStorage, SessionStorageAdapter, type ShiftAddDocumentParams, ShiftClient, type ShiftCreateIndexParams, type ShiftEntry, type ShiftIndex, type ShiftIngestResponse, type ShiftListEntriesParams, type ShiftListEntriesResponse, type ShiftSearchParams, type ShiftSearchResult, type ShiftUpdateIndexParams, type ShiftUploadFileParams, type ShiftUploadableFile, type SseJsonEvent, type SupabaseCompatSession, type TableInsertRow, type TableRow, type TableUpdatePatch, type Tables, type TablesInsert, type TablesUpdate, Transport, type TransportOptions, type TransportRequest, asPostgrestResponse, bindFetch, createBrowserClient, createClient, createRagPipeline, createRagableBrowserClient, createRagableServerClient, detectStorage, effectiveDataAuth, extractErrorMessage, formatPostgrestError, formatRetrievalContext, formatSdkError, generateIdempotencyKey, normalizeBrowserApiBase, parseSseDataLine, parseTransportResponse, readSseStream };
package/dist/index.js CHANGED
@@ -1820,6 +1820,8 @@ var RagableAuth = class {
1820
1820
  const refreshed = await this._doRefresh(session.refresh_token);
1821
1821
  if (refreshed) {
1822
1822
  this.currentSession = refreshed;
1823
+ } else {
1824
+ await this.storage.removeItem(this.storageKey);
1823
1825
  }
1824
1826
  }
1825
1827
  }
@@ -1837,7 +1839,8 @@ var RagableAuth = class {
1837
1839
  const raw = await this.fetchAuth("/register", "POST", {
1838
1840
  email: credentials.email,
1839
1841
  password: credentials.password,
1840
- ...name !== void 0 ? { name } : {}
1842
+ ...name !== void 0 ? { name } : {},
1843
+ ...credentials.options?.data !== void 0 ? { data: credentials.options.data } : {}
1841
1844
  });
1842
1845
  const session = this.rawToSession(raw);
1843
1846
  await this.setSessionInternal(session, "SIGNED_IN");
@@ -1907,7 +1910,9 @@ var RagableAuth = class {
1907
1910
  const token = this.currentSession?.access_token;
1908
1911
  if (!token) throw new RagableError("Not authenticated", 401, null);
1909
1912
  const result = await this.fetchAuthWithBearer("/me", "PATCH", token, {
1913
+ ...attributes.email !== void 0 ? { email: attributes.email } : {},
1910
1914
  ...attributes.password !== void 0 ? { password: attributes.password } : {},
1915
+ ...attributes.data !== void 0 ? { data: attributes.data } : {},
1911
1916
  ...attributes.data?.name !== void 0 ? { name: attributes.data.name } : {}
1912
1917
  });
1913
1918
  if (this.currentSession) {
@@ -1932,6 +1937,17 @@ var RagableAuth = class {
1932
1937
  getAccessToken() {
1933
1938
  return this.currentSession?.access_token ?? null;
1934
1939
  }
1940
+ async getValidAccessToken() {
1941
+ if (!this.initialized) await this.initialize();
1942
+ const session = this.currentSession;
1943
+ if (!session) return null;
1944
+ const secondsUntilExpiry = session.expires_at - nowSeconds();
1945
+ if (secondsUntilExpiry <= this.refreshSkewSeconds) {
1946
+ const refreshed = await this.singleFlightRefresh(session.refresh_token);
1947
+ return refreshed?.access_token ?? null;
1948
+ }
1949
+ return session.access_token;
1950
+ }
1935
1951
  getCurrentSession() {
1936
1952
  return this.currentSession;
1937
1953
  }
@@ -2145,7 +2161,7 @@ function requireAuthGroupId(options) {
2145
2161
  }
2146
2162
  async function requireAccessToken(options, ragableAuth) {
2147
2163
  if (ragableAuth) {
2148
- const token = ragableAuth.getAccessToken();
2164
+ const token = await ragableAuth.getValidAccessToken();
2149
2165
  if (token) return token;
2150
2166
  }
2151
2167
  const getter = options.getAccessToken;
@@ -2764,10 +2780,7 @@ var RagableBrowser = class {
2764
2780
  });
2765
2781
  this.transport.setRefreshHandler(async () => {
2766
2782
  if (effectiveDataAuth(options) !== "user") return null;
2767
- const session = await this._ragableAuth.singleFlightRefresh(
2768
- this._ragableAuth.getCurrentSession()?.refresh_token ?? ""
2769
- );
2770
- return session?.access_token ?? null;
2783
+ return this._ragableAuth.getValidAccessToken();
2771
2784
  });
2772
2785
  if (!options.getAccessToken && effectiveDataAuth(options) === "user") {
2773
2786
  this._ragableAuth.initialize().catch(() => {