@archie/react-sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +792 -0
- package/dist/index.d.ts +246 -0
- package/dist/index.js +483 -0
- package/dist/index.js.map +1 -0
- package/package.json +72 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ArchieClient, Session, User, AuthSignInParams, ArchieError, AuthSignUpParams, AuthConfirmParams, AuthRecoverParams, AuthResetPasswordParams, ConnectionState, FileUploadOptions, FileUploadResult, IRestModule, RestRequestOptions } from '@archie/js-sdk';
|
|
3
|
+
export { ArchieClient, ArchieClientOptions, ArchieError, AuthConfirmParams, AuthError, AuthEvent, AuthEventCallback, AuthRecoverParams, AuthResetPasswordParams, AuthSignInParams, AuthSignUpParams, BrowserLocalStorage, ConnectionState, ConnectionStateCallback, CsvUploadOptions, FileUploadOptions, FileUploadResult, GraphQLError, GraphQLRawRequest, GraphQLRequestOptions, GraphQLResponse, IAuthModule, IFileModule, IGraphQLModule, IHttpClient, IRealtimeModule, IRestModule, Logger, MemoryStorage, NetworkError, RealtimeChannel, RealtimeEvent, RestRequestOptions, Session, StorageAdapter, Subscription, SubscriptionCallbacks, TokenAccessor, User, createClient } from '@archie/js-sdk';
|
|
4
|
+
|
|
5
|
+
interface ArchieContextValue {
|
|
6
|
+
client: ArchieClient;
|
|
7
|
+
session: Session | null;
|
|
8
|
+
isLoading: boolean;
|
|
9
|
+
}
|
|
10
|
+
interface ArchieProviderProps {
|
|
11
|
+
client: ArchieClient;
|
|
12
|
+
children: React.ReactNode;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* ArchieProvider — wraps your React app to provide the Archie client and session state.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```tsx
|
|
19
|
+
* import { createClient } from '@archie/js-sdk'
|
|
20
|
+
* import { ArchieProvider } from '@archie/react-sdk'
|
|
21
|
+
*
|
|
22
|
+
* const archie = createClient({ projectId: '...' })
|
|
23
|
+
*
|
|
24
|
+
* function App() {
|
|
25
|
+
* return (
|
|
26
|
+
* <ArchieProvider client={archie}>
|
|
27
|
+
* <MyApp />
|
|
28
|
+
* </ArchieProvider>
|
|
29
|
+
* )
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
declare function ArchieProvider({ client, children }: ArchieProviderProps): React.FunctionComponentElement<React.ProviderProps<ArchieContextValue | null>>;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Returns the ArchieClient instance from context.
|
|
37
|
+
* Must be used within an ArchieProvider.
|
|
38
|
+
*
|
|
39
|
+
* @throws Error if used outside ArchieProvider
|
|
40
|
+
*/
|
|
41
|
+
declare function useArchieClient(): ArchieClient;
|
|
42
|
+
|
|
43
|
+
interface UseAuthReturn {
|
|
44
|
+
user: User | null;
|
|
45
|
+
session: Session | null;
|
|
46
|
+
isLoading: boolean;
|
|
47
|
+
isAuthenticated: boolean;
|
|
48
|
+
signIn: (params: AuthSignInParams) => Promise<{
|
|
49
|
+
session: Session | null;
|
|
50
|
+
error: ArchieError | null;
|
|
51
|
+
}>;
|
|
52
|
+
signUp: (params: AuthSignUpParams) => Promise<{
|
|
53
|
+
data: {
|
|
54
|
+
userId: string;
|
|
55
|
+
message: string;
|
|
56
|
+
} | null;
|
|
57
|
+
error: ArchieError | null;
|
|
58
|
+
}>;
|
|
59
|
+
signOut: () => Promise<void>;
|
|
60
|
+
confirmSignUp: (params: AuthConfirmParams) => Promise<{
|
|
61
|
+
session: Session | null;
|
|
62
|
+
error: ArchieError | null;
|
|
63
|
+
}>;
|
|
64
|
+
recoverPassword: (params: AuthRecoverParams) => Promise<{
|
|
65
|
+
data: {
|
|
66
|
+
message: string;
|
|
67
|
+
} | null;
|
|
68
|
+
error: ArchieError | null;
|
|
69
|
+
}>;
|
|
70
|
+
resetPassword: (params: AuthResetPasswordParams) => Promise<{
|
|
71
|
+
data: {
|
|
72
|
+
message: string;
|
|
73
|
+
} | null;
|
|
74
|
+
error: ArchieError | null;
|
|
75
|
+
}>;
|
|
76
|
+
refreshSession: () => Promise<{
|
|
77
|
+
session: Session | null;
|
|
78
|
+
error: ArchieError | null;
|
|
79
|
+
}>;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Hook for authentication state and operations.
|
|
83
|
+
* All methods return `{ data/session, error }` (never throws).
|
|
84
|
+
*/
|
|
85
|
+
declare function useAuth(): UseAuthReturn;
|
|
86
|
+
|
|
87
|
+
interface UseQueryOptions<T> {
|
|
88
|
+
enabled?: boolean;
|
|
89
|
+
refetchInterval?: number;
|
|
90
|
+
refetchOnWindowFocus?: boolean;
|
|
91
|
+
onSuccess?: (data: T) => void;
|
|
92
|
+
onError?: (error: ArchieError) => void;
|
|
93
|
+
}
|
|
94
|
+
interface UseQueryReturn<T> {
|
|
95
|
+
data: T | null;
|
|
96
|
+
error: ArchieError | null;
|
|
97
|
+
isLoading: boolean;
|
|
98
|
+
isRefetching: boolean;
|
|
99
|
+
refetch: () => Promise<void>;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Declarative GraphQL query hook with caching and stale-while-revalidate.
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* ```tsx
|
|
106
|
+
* const { data, isLoading } = useQuery<{ users: User[] }>(
|
|
107
|
+
* 'query { users { id email name } }',
|
|
108
|
+
* { limit: 10 }
|
|
109
|
+
* )
|
|
110
|
+
* ```
|
|
111
|
+
*/
|
|
112
|
+
declare function useQuery<T = unknown>(gql: string, variables?: Record<string, unknown>, options?: UseQueryOptions<T>): UseQueryReturn<T>;
|
|
113
|
+
|
|
114
|
+
interface UseMutationOptions<T> {
|
|
115
|
+
onSuccess?: (data: T) => void;
|
|
116
|
+
onError?: (error: ArchieError) => void;
|
|
117
|
+
onSettled?: () => void;
|
|
118
|
+
/** Query substrings to invalidate (forcing refetch) after a successful mutation. */
|
|
119
|
+
invalidateQueries?: string[];
|
|
120
|
+
}
|
|
121
|
+
interface UseMutationReturn<T> {
|
|
122
|
+
mutate: (variables?: Record<string, unknown>) => void;
|
|
123
|
+
mutateAsync: (variables?: Record<string, unknown>) => Promise<T | null>;
|
|
124
|
+
data: T | null;
|
|
125
|
+
error: ArchieError | null;
|
|
126
|
+
isLoading: boolean;
|
|
127
|
+
reset: () => void;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Hook for GraphQL mutations.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```tsx
|
|
134
|
+
* const { mutate, isLoading } = useMutation<{ createUser: User }>(
|
|
135
|
+
* 'mutation($data: CreateUserInput!) { createUser(data: $data) { id email } }',
|
|
136
|
+
* { invalidateQueries: ['users'] }
|
|
137
|
+
* )
|
|
138
|
+
*
|
|
139
|
+
* mutate({ data: { email: 'new@user.com', name: 'John' } })
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
declare function useMutation<T = unknown>(gql: string, options?: UseMutationOptions<T>): UseMutationReturn<T>;
|
|
143
|
+
|
|
144
|
+
interface UseSubscriptionOptions<T> {
|
|
145
|
+
enabled?: boolean;
|
|
146
|
+
onData?: (data: T) => void;
|
|
147
|
+
onError?: (error: ArchieError) => void;
|
|
148
|
+
}
|
|
149
|
+
interface UseSubscriptionReturn<T> {
|
|
150
|
+
data: T | null;
|
|
151
|
+
error: ArchieError | null;
|
|
152
|
+
connectionState: ConnectionState;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Hook for real-time GraphQL subscriptions.
|
|
156
|
+
* Subscribes on mount, unsubscribes on unmount.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* ```tsx
|
|
160
|
+
* const { data } = useSubscription<{ orderUpdated: Order }>(
|
|
161
|
+
* 'subscription { orderUpdated { id status total } }'
|
|
162
|
+
* )
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
declare function useSubscription<T = unknown>(gql: string, variables?: Record<string, unknown>, options?: UseSubscriptionOptions<T>): UseSubscriptionReturn<T>;
|
|
166
|
+
|
|
167
|
+
interface UseFileUploadReturn {
|
|
168
|
+
upload: (file: File | Blob, options?: FileUploadOptions) => Promise<void>;
|
|
169
|
+
progress: number;
|
|
170
|
+
isUploading: boolean;
|
|
171
|
+
data: FileUploadResult | null;
|
|
172
|
+
error: ArchieError | null;
|
|
173
|
+
reset: () => void;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Hook for file uploads with progress tracking.
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```tsx
|
|
180
|
+
* const { upload, progress, isUploading } = useFileUpload()
|
|
181
|
+
*
|
|
182
|
+
* <input type="file" onChange={(e) => upload(e.target.files[0])} />
|
|
183
|
+
* {isUploading && <ProgressBar value={progress} />}
|
|
184
|
+
* ```
|
|
185
|
+
*/
|
|
186
|
+
declare function useFileUpload(): UseFileUploadReturn;
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Returns the REST module from the Archie client.
|
|
190
|
+
* Provides direct access to `get`, `post`, `put`, `patch`, `delete`.
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```tsx
|
|
194
|
+
* const rest = useRest()
|
|
195
|
+
* const data = await rest.get('/api/products')
|
|
196
|
+
* await rest.post('/api/products', { name: 'Widget' })
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
declare function useRest(): IRestModule;
|
|
200
|
+
interface UseRestQueryReturn<T> {
|
|
201
|
+
data: T | null;
|
|
202
|
+
error: ArchieError | null;
|
|
203
|
+
isLoading: boolean;
|
|
204
|
+
refetch: () => Promise<void>;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Declarative hook for GET requests to custom REST APIs.
|
|
208
|
+
*/
|
|
209
|
+
declare function useRestQuery<T = unknown>(path: string, options?: RestRequestOptions & {
|
|
210
|
+
enabled?: boolean;
|
|
211
|
+
}): UseRestQueryReturn<T>;
|
|
212
|
+
interface UseRestMutationReturn<T> {
|
|
213
|
+
execute: (body?: unknown, overrideOptions?: RestRequestOptions) => Promise<T | null>;
|
|
214
|
+
data: T | null;
|
|
215
|
+
error: ArchieError | null;
|
|
216
|
+
isLoading: boolean;
|
|
217
|
+
reset: () => void;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Imperative hook for POST/PUT/PATCH/DELETE requests to custom REST APIs.
|
|
221
|
+
*/
|
|
222
|
+
declare function useRestMutation<T = unknown>(path: string, method?: 'POST' | 'PUT' | 'PATCH' | 'DELETE'): UseRestMutationReturn<T>;
|
|
223
|
+
|
|
224
|
+
interface AuthGuardProps {
|
|
225
|
+
/** Content to show when authenticated (and authorized if roles specified). */
|
|
226
|
+
children: React.ReactNode;
|
|
227
|
+
/** Content to show when NOT authenticated. */
|
|
228
|
+
fallback?: React.ReactNode;
|
|
229
|
+
/** Content to show while session is loading. */
|
|
230
|
+
loadingComponent?: React.ReactNode;
|
|
231
|
+
/** If specified, user must have at least one of these roles. */
|
|
232
|
+
requiredRoles?: string[];
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* AuthGuard component — conditionally renders children based on auth state.
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* ```tsx
|
|
239
|
+
* <AuthGuard fallback={<LoginPage />} requiredRoles={['admin']}>
|
|
240
|
+
* <AdminPanel />
|
|
241
|
+
* </AuthGuard>
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
declare function AuthGuard({ children, fallback, loadingComponent, requiredRoles, }: AuthGuardProps): React.FunctionComponentElement<React.FragmentProps>;
|
|
245
|
+
|
|
246
|
+
export { ArchieProvider, type ArchieProviderProps, AuthGuard, type AuthGuardProps, useArchieClient, useAuth, useFileUpload, useMutation, useQuery, useRest, useRestMutation, useRestQuery, useSubscription };
|