@safercity/sdk-react 0.0.1
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 +196 -0
- package/dist/index.cjs +505 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +571 -0
- package/dist/index.d.ts +571 -0
- package/dist/index.js +473 -0
- package/dist/index.js.map +1 -0
- package/package.json +62 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,571 @@
|
|
|
1
|
+
import { SaferCityClientOptions, SaferCityClient, ApiResponse, SaferCityApiError, ServerSentEvent } from '@safercity/sdk';
|
|
2
|
+
export * from '@safercity/sdk';
|
|
3
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
+
import { ReactNode } from 'react';
|
|
5
|
+
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
6
|
+
import { QueryClient, UseQueryOptions, UseMutationOptions } from '@tanstack/react-query';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Context value for SaferCity provider
|
|
10
|
+
*/
|
|
11
|
+
interface SaferCityContextValue {
|
|
12
|
+
client: SaferCityClient;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Props for SaferCityProvider
|
|
16
|
+
*/
|
|
17
|
+
interface SaferCityProviderProps extends SaferCityClientOptions {
|
|
18
|
+
children: ReactNode;
|
|
19
|
+
/**
|
|
20
|
+
* Custom QueryClient instance (optional)
|
|
21
|
+
* If not provided, a new QueryClient will be created
|
|
22
|
+
*/
|
|
23
|
+
queryClient?: QueryClient;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Provider component for SaferCity SDK
|
|
27
|
+
*
|
|
28
|
+
* Wraps your app with the SaferCity client context and TanStack Query provider.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```tsx
|
|
32
|
+
* import { SaferCityProvider } from '@safercity/sdk-react';
|
|
33
|
+
*
|
|
34
|
+
* function App() {
|
|
35
|
+
* return (
|
|
36
|
+
* <SaferCityProvider
|
|
37
|
+
* baseUrl="https://api.safercity.com"
|
|
38
|
+
* token={userToken}
|
|
39
|
+
* tenantId="tenant-123"
|
|
40
|
+
* >
|
|
41
|
+
* <YourApp />
|
|
42
|
+
* </SaferCityProvider>
|
|
43
|
+
* );
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
declare function SaferCityProvider({ children, queryClient: externalQueryClient, ...clientOptions }: SaferCityProviderProps): react_jsx_runtime.JSX.Element;
|
|
48
|
+
/**
|
|
49
|
+
* Hook to access the SaferCity client
|
|
50
|
+
*
|
|
51
|
+
* Must be used within a SaferCityProvider.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```tsx
|
|
55
|
+
* function MyComponent() {
|
|
56
|
+
* const { client } = useSaferCity();
|
|
57
|
+
*
|
|
58
|
+
* const handleClick = async () => {
|
|
59
|
+
* const { data } = await client.health.check();
|
|
60
|
+
* console.log(data);
|
|
61
|
+
* };
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
declare function useSaferCity(): SaferCityContextValue;
|
|
66
|
+
/**
|
|
67
|
+
* Hook to access just the SaferCity client
|
|
68
|
+
*
|
|
69
|
+
* Convenience wrapper around useSaferCity().
|
|
70
|
+
*/
|
|
71
|
+
declare function useSaferCityClient(): SaferCityClient;
|
|
72
|
+
|
|
73
|
+
declare const saferCityKeys: {
|
|
74
|
+
all: readonly ["safercity"];
|
|
75
|
+
health: () => readonly ["safercity", "health"];
|
|
76
|
+
auth: () => readonly ["safercity", "auth"];
|
|
77
|
+
authWhoami: () => readonly ["safercity", "auth", "whoami"];
|
|
78
|
+
users: () => readonly ["safercity", "users"];
|
|
79
|
+
usersList: (filters?: Record<string, unknown>) => readonly ["safercity", "users", "list", Record<string, unknown> | undefined];
|
|
80
|
+
usersDetail: (userId: string) => readonly ["safercity", "users", "detail", string];
|
|
81
|
+
panics: () => readonly ["safercity", "panics"];
|
|
82
|
+
panicsList: (filters?: Record<string, unknown>) => readonly ["safercity", "panics", "list", Record<string, unknown> | undefined];
|
|
83
|
+
panicsDetail: (panicId: string) => readonly ["safercity", "panics", "detail", string];
|
|
84
|
+
subscriptions: () => readonly ["safercity", "subscriptions"];
|
|
85
|
+
subscriptionsList: (filters?: Record<string, unknown>) => readonly ["safercity", "subscriptions", "list", Record<string, unknown> | undefined];
|
|
86
|
+
subscriptionsTypes: () => readonly ["safercity", "subscriptions", "types"];
|
|
87
|
+
subscriptionsStats: () => readonly ["safercity", "subscriptions", "stats"];
|
|
88
|
+
locationSafety: (lat: number, lng: number) => readonly ["safercity", "location-safety", number, number];
|
|
89
|
+
crimes: () => readonly ["safercity", "crimes"];
|
|
90
|
+
crimesList: (filters?: Record<string, unknown>) => readonly ["safercity", "crimes", "list", Record<string, unknown> | undefined];
|
|
91
|
+
crimesCategories: () => readonly ["safercity", "crimes", "categories"];
|
|
92
|
+
crimesTypes: () => readonly ["safercity", "crimes", "types"];
|
|
93
|
+
};
|
|
94
|
+
declare function useHealthCheck(options?: Omit<UseQueryOptions<ApiResponse<{
|
|
95
|
+
status: string;
|
|
96
|
+
timestamp: string;
|
|
97
|
+
}>, SaferCityApiError>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseQueryResult<ApiResponse<{
|
|
98
|
+
status: string;
|
|
99
|
+
timestamp: string;
|
|
100
|
+
}>, SaferCityApiError>;
|
|
101
|
+
declare function useWhoAmI(options?: Omit<UseQueryOptions<ApiResponse<{
|
|
102
|
+
tenantId: string | null;
|
|
103
|
+
environment: string;
|
|
104
|
+
scopes: string[];
|
|
105
|
+
sessionId: string;
|
|
106
|
+
}>, SaferCityApiError>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseQueryResult<ApiResponse<{
|
|
107
|
+
tenantId: string | null;
|
|
108
|
+
environment: string;
|
|
109
|
+
scopes: string[];
|
|
110
|
+
sessionId: string;
|
|
111
|
+
}>, SaferCityApiError>;
|
|
112
|
+
declare function useUsers(filters?: {
|
|
113
|
+
limit?: number;
|
|
114
|
+
cursor?: string;
|
|
115
|
+
status?: string;
|
|
116
|
+
}, options?: Omit<UseQueryOptions<ApiResponse<{
|
|
117
|
+
users: Array<{
|
|
118
|
+
id: string;
|
|
119
|
+
email?: string;
|
|
120
|
+
phone?: string;
|
|
121
|
+
status: string;
|
|
122
|
+
}>;
|
|
123
|
+
hasNext: boolean;
|
|
124
|
+
cursor?: string;
|
|
125
|
+
}>, SaferCityApiError>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseQueryResult<ApiResponse<{
|
|
126
|
+
users: Array<{
|
|
127
|
+
id: string;
|
|
128
|
+
email?: string;
|
|
129
|
+
phone?: string;
|
|
130
|
+
status: string;
|
|
131
|
+
}>;
|
|
132
|
+
hasNext: boolean;
|
|
133
|
+
cursor?: string;
|
|
134
|
+
}>, SaferCityApiError>;
|
|
135
|
+
declare function useUser(userId: string, options?: Omit<UseQueryOptions<ApiResponse<{
|
|
136
|
+
id: string;
|
|
137
|
+
email?: string;
|
|
138
|
+
phone?: string;
|
|
139
|
+
firstName?: string;
|
|
140
|
+
lastName?: string;
|
|
141
|
+
status: string;
|
|
142
|
+
metadata?: Record<string, unknown>;
|
|
143
|
+
}>, SaferCityApiError>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseQueryResult<ApiResponse<{
|
|
144
|
+
id: string;
|
|
145
|
+
email?: string;
|
|
146
|
+
phone?: string;
|
|
147
|
+
firstName?: string;
|
|
148
|
+
lastName?: string;
|
|
149
|
+
status: string;
|
|
150
|
+
metadata?: Record<string, unknown>;
|
|
151
|
+
}>, SaferCityApiError>;
|
|
152
|
+
declare function useCreateUser(options?: UseMutationOptions<ApiResponse<{
|
|
153
|
+
id: string;
|
|
154
|
+
email?: string;
|
|
155
|
+
phone?: string;
|
|
156
|
+
}>, SaferCityApiError, {
|
|
157
|
+
email?: string;
|
|
158
|
+
phone?: string;
|
|
159
|
+
firstName?: string;
|
|
160
|
+
lastName?: string;
|
|
161
|
+
metadata?: Record<string, unknown>;
|
|
162
|
+
}>): _tanstack_react_query.UseMutationResult<ApiResponse<{
|
|
163
|
+
id: string;
|
|
164
|
+
email?: string;
|
|
165
|
+
phone?: string;
|
|
166
|
+
}>, SaferCityApiError, {
|
|
167
|
+
email?: string;
|
|
168
|
+
phone?: string;
|
|
169
|
+
firstName?: string;
|
|
170
|
+
lastName?: string;
|
|
171
|
+
metadata?: Record<string, unknown>;
|
|
172
|
+
}, unknown>;
|
|
173
|
+
declare function useUpdateUser(options?: UseMutationOptions<ApiResponse<{
|
|
174
|
+
id: string;
|
|
175
|
+
}>, SaferCityApiError, {
|
|
176
|
+
userId: string;
|
|
177
|
+
data: {
|
|
178
|
+
email?: string;
|
|
179
|
+
phone?: string;
|
|
180
|
+
firstName?: string;
|
|
181
|
+
lastName?: string;
|
|
182
|
+
metadata?: Record<string, unknown>;
|
|
183
|
+
};
|
|
184
|
+
}>): _tanstack_react_query.UseMutationResult<ApiResponse<{
|
|
185
|
+
id: string;
|
|
186
|
+
}>, SaferCityApiError, {
|
|
187
|
+
userId: string;
|
|
188
|
+
data: {
|
|
189
|
+
email?: string;
|
|
190
|
+
phone?: string;
|
|
191
|
+
firstName?: string;
|
|
192
|
+
lastName?: string;
|
|
193
|
+
metadata?: Record<string, unknown>;
|
|
194
|
+
};
|
|
195
|
+
}, unknown>;
|
|
196
|
+
declare function useDeleteUser(options?: UseMutationOptions<ApiResponse<{
|
|
197
|
+
success: boolean;
|
|
198
|
+
}>, SaferCityApiError, string>): _tanstack_react_query.UseMutationResult<ApiResponse<{
|
|
199
|
+
success: boolean;
|
|
200
|
+
}>, SaferCityApiError, string, unknown>;
|
|
201
|
+
declare function usePanics(filters?: {
|
|
202
|
+
userId?: string;
|
|
203
|
+
status?: string;
|
|
204
|
+
limit?: number;
|
|
205
|
+
cursor?: string;
|
|
206
|
+
}, options?: Omit<UseQueryOptions<ApiResponse<{
|
|
207
|
+
panics: Array<{
|
|
208
|
+
id: string;
|
|
209
|
+
userId: string;
|
|
210
|
+
status: string;
|
|
211
|
+
createdAt: string;
|
|
212
|
+
}>;
|
|
213
|
+
hasNext: boolean;
|
|
214
|
+
cursor?: string;
|
|
215
|
+
}>, SaferCityApiError>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseQueryResult<ApiResponse<{
|
|
216
|
+
panics: Array<{
|
|
217
|
+
id: string;
|
|
218
|
+
userId: string;
|
|
219
|
+
status: string;
|
|
220
|
+
createdAt: string;
|
|
221
|
+
}>;
|
|
222
|
+
hasNext: boolean;
|
|
223
|
+
cursor?: string;
|
|
224
|
+
}>, SaferCityApiError>;
|
|
225
|
+
declare function usePanic(panicId: string, query?: {
|
|
226
|
+
userId?: string;
|
|
227
|
+
}, options?: Omit<UseQueryOptions<ApiResponse<{
|
|
228
|
+
id: string;
|
|
229
|
+
userId: string;
|
|
230
|
+
status: string;
|
|
231
|
+
latitude: number;
|
|
232
|
+
longitude: number;
|
|
233
|
+
createdAt: string;
|
|
234
|
+
updatedAt?: string;
|
|
235
|
+
}>, SaferCityApiError>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseQueryResult<ApiResponse<{
|
|
236
|
+
id: string;
|
|
237
|
+
userId: string;
|
|
238
|
+
status: string;
|
|
239
|
+
latitude: number;
|
|
240
|
+
longitude: number;
|
|
241
|
+
createdAt: string;
|
|
242
|
+
updatedAt?: string;
|
|
243
|
+
}>, SaferCityApiError>;
|
|
244
|
+
declare function useCreatePanic(options?: UseMutationOptions<ApiResponse<{
|
|
245
|
+
id: string;
|
|
246
|
+
status: string;
|
|
247
|
+
createdAt: string;
|
|
248
|
+
}>, SaferCityApiError, {
|
|
249
|
+
userId: string;
|
|
250
|
+
panicTypeId?: string;
|
|
251
|
+
latitude: number;
|
|
252
|
+
longitude: number;
|
|
253
|
+
accuracy?: number;
|
|
254
|
+
metadata?: Record<string, unknown>;
|
|
255
|
+
}>): _tanstack_react_query.UseMutationResult<ApiResponse<{
|
|
256
|
+
id: string;
|
|
257
|
+
status: string;
|
|
258
|
+
createdAt: string;
|
|
259
|
+
}>, SaferCityApiError, {
|
|
260
|
+
userId: string;
|
|
261
|
+
panicTypeId?: string;
|
|
262
|
+
latitude: number;
|
|
263
|
+
longitude: number;
|
|
264
|
+
accuracy?: number;
|
|
265
|
+
metadata?: Record<string, unknown>;
|
|
266
|
+
}, unknown>;
|
|
267
|
+
declare function useUpdatePanicLocation(options?: UseMutationOptions<ApiResponse<{
|
|
268
|
+
id: string;
|
|
269
|
+
latitude: number;
|
|
270
|
+
longitude: number;
|
|
271
|
+
}>, SaferCityApiError, {
|
|
272
|
+
panicId: string;
|
|
273
|
+
data: {
|
|
274
|
+
userId: string;
|
|
275
|
+
latitude: number;
|
|
276
|
+
longitude: number;
|
|
277
|
+
accuracy?: number;
|
|
278
|
+
};
|
|
279
|
+
}>): _tanstack_react_query.UseMutationResult<ApiResponse<{
|
|
280
|
+
id: string;
|
|
281
|
+
latitude: number;
|
|
282
|
+
longitude: number;
|
|
283
|
+
}>, SaferCityApiError, {
|
|
284
|
+
panicId: string;
|
|
285
|
+
data: {
|
|
286
|
+
userId: string;
|
|
287
|
+
latitude: number;
|
|
288
|
+
longitude: number;
|
|
289
|
+
accuracy?: number;
|
|
290
|
+
};
|
|
291
|
+
}, unknown>;
|
|
292
|
+
declare function useCancelPanic(options?: UseMutationOptions<ApiResponse<{
|
|
293
|
+
id: string;
|
|
294
|
+
status: string;
|
|
295
|
+
cancelledAt: string;
|
|
296
|
+
}>, SaferCityApiError, {
|
|
297
|
+
panicId: string;
|
|
298
|
+
data: {
|
|
299
|
+
userId: string;
|
|
300
|
+
reason?: string;
|
|
301
|
+
};
|
|
302
|
+
}>): _tanstack_react_query.UseMutationResult<ApiResponse<{
|
|
303
|
+
id: string;
|
|
304
|
+
status: string;
|
|
305
|
+
cancelledAt: string;
|
|
306
|
+
}>, SaferCityApiError, {
|
|
307
|
+
panicId: string;
|
|
308
|
+
data: {
|
|
309
|
+
userId: string;
|
|
310
|
+
reason?: string;
|
|
311
|
+
};
|
|
312
|
+
}, unknown>;
|
|
313
|
+
declare function useSubscriptionTypes(options?: Omit<UseQueryOptions<ApiResponse<{
|
|
314
|
+
types: Array<{
|
|
315
|
+
id: string;
|
|
316
|
+
name: string;
|
|
317
|
+
description?: string;
|
|
318
|
+
price?: number;
|
|
319
|
+
}>;
|
|
320
|
+
}>, SaferCityApiError>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseQueryResult<ApiResponse<{
|
|
321
|
+
types: Array<{
|
|
322
|
+
id: string;
|
|
323
|
+
name: string;
|
|
324
|
+
description?: string;
|
|
325
|
+
price?: number;
|
|
326
|
+
}>;
|
|
327
|
+
}>, SaferCityApiError>;
|
|
328
|
+
declare function useSubscriptions(filters?: {
|
|
329
|
+
userId?: string;
|
|
330
|
+
status?: string;
|
|
331
|
+
limit?: number;
|
|
332
|
+
}, options?: Omit<UseQueryOptions<ApiResponse<{
|
|
333
|
+
subscriptions: Array<{
|
|
334
|
+
id: string;
|
|
335
|
+
userId: string;
|
|
336
|
+
subscriptionTypeId: string;
|
|
337
|
+
status: string;
|
|
338
|
+
}>;
|
|
339
|
+
}>, SaferCityApiError>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseQueryResult<ApiResponse<{
|
|
340
|
+
subscriptions: Array<{
|
|
341
|
+
id: string;
|
|
342
|
+
userId: string;
|
|
343
|
+
subscriptionTypeId: string;
|
|
344
|
+
status: string;
|
|
345
|
+
}>;
|
|
346
|
+
}>, SaferCityApiError>;
|
|
347
|
+
declare function useSubscriptionStats(options?: Omit<UseQueryOptions<ApiResponse<{
|
|
348
|
+
total: number;
|
|
349
|
+
active: number;
|
|
350
|
+
byType: Record<string, number>;
|
|
351
|
+
}>, SaferCityApiError>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseQueryResult<ApiResponse<{
|
|
352
|
+
total: number;
|
|
353
|
+
active: number;
|
|
354
|
+
byType: Record<string, number>;
|
|
355
|
+
}>, SaferCityApiError>;
|
|
356
|
+
declare function useCreateSubscription(options?: UseMutationOptions<ApiResponse<{
|
|
357
|
+
id: string;
|
|
358
|
+
userId: string;
|
|
359
|
+
subscriptionTypeId: string;
|
|
360
|
+
status: string;
|
|
361
|
+
}>, SaferCityApiError, {
|
|
362
|
+
userId: string;
|
|
363
|
+
subscriptionTypeId: string;
|
|
364
|
+
status?: string;
|
|
365
|
+
}>): _tanstack_react_query.UseMutationResult<ApiResponse<{
|
|
366
|
+
id: string;
|
|
367
|
+
userId: string;
|
|
368
|
+
subscriptionTypeId: string;
|
|
369
|
+
status: string;
|
|
370
|
+
}>, SaferCityApiError, {
|
|
371
|
+
userId: string;
|
|
372
|
+
subscriptionTypeId: string;
|
|
373
|
+
status?: string;
|
|
374
|
+
}, unknown>;
|
|
375
|
+
declare function useLocationSafety(latitude: number, longitude: number, radius?: number, options?: Omit<UseQueryOptions<ApiResponse<{
|
|
376
|
+
safetyScore: number;
|
|
377
|
+
riskLevel: string;
|
|
378
|
+
factors: Array<{
|
|
379
|
+
type: string;
|
|
380
|
+
impact: number;
|
|
381
|
+
}>;
|
|
382
|
+
}>, SaferCityApiError>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseQueryResult<ApiResponse<{
|
|
383
|
+
safetyScore: number;
|
|
384
|
+
riskLevel: string;
|
|
385
|
+
factors: Array<{
|
|
386
|
+
type: string;
|
|
387
|
+
impact: number;
|
|
388
|
+
}>;
|
|
389
|
+
}>, SaferCityApiError>;
|
|
390
|
+
declare function useCrimes(filters?: {
|
|
391
|
+
latitude?: number;
|
|
392
|
+
longitude?: number;
|
|
393
|
+
radius?: number;
|
|
394
|
+
type?: string;
|
|
395
|
+
from?: string;
|
|
396
|
+
to?: string;
|
|
397
|
+
limit?: number;
|
|
398
|
+
}, options?: Omit<UseQueryOptions<ApiResponse<{
|
|
399
|
+
crimes: Array<{
|
|
400
|
+
id: string;
|
|
401
|
+
type: string;
|
|
402
|
+
latitude: number;
|
|
403
|
+
longitude: number;
|
|
404
|
+
occurredAt: string;
|
|
405
|
+
}>;
|
|
406
|
+
}>, SaferCityApiError>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseQueryResult<ApiResponse<{
|
|
407
|
+
crimes: Array<{
|
|
408
|
+
id: string;
|
|
409
|
+
type: string;
|
|
410
|
+
latitude: number;
|
|
411
|
+
longitude: number;
|
|
412
|
+
occurredAt: string;
|
|
413
|
+
}>;
|
|
414
|
+
}>, SaferCityApiError>;
|
|
415
|
+
declare function useCrimeCategories(options?: Omit<UseQueryOptions<ApiResponse<{
|
|
416
|
+
categories: Array<{
|
|
417
|
+
id: string;
|
|
418
|
+
name: string;
|
|
419
|
+
}>;
|
|
420
|
+
}>, SaferCityApiError>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseQueryResult<ApiResponse<{
|
|
421
|
+
categories: Array<{
|
|
422
|
+
id: string;
|
|
423
|
+
name: string;
|
|
424
|
+
}>;
|
|
425
|
+
}>, SaferCityApiError>;
|
|
426
|
+
declare function useCrimeTypes(options?: Omit<UseQueryOptions<ApiResponse<{
|
|
427
|
+
types: Array<{
|
|
428
|
+
id: string;
|
|
429
|
+
name: string;
|
|
430
|
+
categoryId: string;
|
|
431
|
+
}>;
|
|
432
|
+
}>, SaferCityApiError>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseQueryResult<ApiResponse<{
|
|
433
|
+
types: Array<{
|
|
434
|
+
id: string;
|
|
435
|
+
name: string;
|
|
436
|
+
categoryId: string;
|
|
437
|
+
}>;
|
|
438
|
+
}>, SaferCityApiError>;
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* State for streaming hooks
|
|
442
|
+
*/
|
|
443
|
+
interface StreamState<T = ServerSentEvent> {
|
|
444
|
+
/**
|
|
445
|
+
* Latest event received
|
|
446
|
+
*/
|
|
447
|
+
data: T | null;
|
|
448
|
+
/**
|
|
449
|
+
* All events received (if keepHistory is true)
|
|
450
|
+
*/
|
|
451
|
+
events: T[];
|
|
452
|
+
/**
|
|
453
|
+
* Whether the stream is currently connected
|
|
454
|
+
*/
|
|
455
|
+
isConnected: boolean;
|
|
456
|
+
/**
|
|
457
|
+
* Whether the stream is connecting
|
|
458
|
+
*/
|
|
459
|
+
isConnecting: boolean;
|
|
460
|
+
/**
|
|
461
|
+
* Error if connection failed
|
|
462
|
+
*/
|
|
463
|
+
error: Error | null;
|
|
464
|
+
}
|
|
465
|
+
interface UseStreamOptions<T = ServerSentEvent> {
|
|
466
|
+
/**
|
|
467
|
+
* Whether to automatically connect on mount
|
|
468
|
+
* @default true
|
|
469
|
+
*/
|
|
470
|
+
autoConnect?: boolean;
|
|
471
|
+
/**
|
|
472
|
+
* Keep history of all events
|
|
473
|
+
* @default false
|
|
474
|
+
*/
|
|
475
|
+
keepHistory?: boolean;
|
|
476
|
+
/**
|
|
477
|
+
* Maximum number of events to keep in history
|
|
478
|
+
* @default 100
|
|
479
|
+
*/
|
|
480
|
+
maxHistory?: number;
|
|
481
|
+
/**
|
|
482
|
+
* Transform raw SSE event to custom type
|
|
483
|
+
*/
|
|
484
|
+
transform?: (event: ServerSentEvent) => T;
|
|
485
|
+
/**
|
|
486
|
+
* Callback when connected
|
|
487
|
+
*/
|
|
488
|
+
onOpen?: () => void;
|
|
489
|
+
/**
|
|
490
|
+
* Callback on each event
|
|
491
|
+
*/
|
|
492
|
+
onEvent?: (event: T) => void;
|
|
493
|
+
/**
|
|
494
|
+
* Callback on error
|
|
495
|
+
*/
|
|
496
|
+
onError?: (error: Error) => void;
|
|
497
|
+
/**
|
|
498
|
+
* Callback when disconnected
|
|
499
|
+
*/
|
|
500
|
+
onClose?: () => void;
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Hook for streaming panic updates
|
|
504
|
+
*
|
|
505
|
+
* @example
|
|
506
|
+
* ```tsx
|
|
507
|
+
* function PanicTracker({ panicId }: { panicId: string }) {
|
|
508
|
+
* const { data, isConnected, error } = usePanicStream(panicId, {
|
|
509
|
+
* onEvent: (event) => console.log('Update:', event),
|
|
510
|
+
* });
|
|
511
|
+
*
|
|
512
|
+
* if (error) return <div>Error: {error.message}</div>;
|
|
513
|
+
* if (!isConnected) return <div>Connecting...</div>;
|
|
514
|
+
*
|
|
515
|
+
* return <div>Latest: {data?.data}</div>;
|
|
516
|
+
* }
|
|
517
|
+
* ```
|
|
518
|
+
*/
|
|
519
|
+
declare function usePanicStream<T = ServerSentEvent>(panicId: string | null | undefined, options?: UseStreamOptions<T>): {
|
|
520
|
+
connect: () => Promise<void>;
|
|
521
|
+
disconnect: () => void;
|
|
522
|
+
/**
|
|
523
|
+
* Latest event received
|
|
524
|
+
*/
|
|
525
|
+
data: T | null;
|
|
526
|
+
/**
|
|
527
|
+
* All events received (if keepHistory is true)
|
|
528
|
+
*/
|
|
529
|
+
events: T[];
|
|
530
|
+
/**
|
|
531
|
+
* Whether the stream is currently connected
|
|
532
|
+
*/
|
|
533
|
+
isConnected: boolean;
|
|
534
|
+
/**
|
|
535
|
+
* Whether the stream is connecting
|
|
536
|
+
*/
|
|
537
|
+
isConnecting: boolean;
|
|
538
|
+
/**
|
|
539
|
+
* Error if connection failed
|
|
540
|
+
*/
|
|
541
|
+
error: Error | null;
|
|
542
|
+
};
|
|
543
|
+
/**
|
|
544
|
+
* Generic hook for any SSE stream
|
|
545
|
+
*/
|
|
546
|
+
declare function useStream<T = ServerSentEvent>(createStream: () => AsyncIterable<ServerSentEvent>, options?: UseStreamOptions<T>): {
|
|
547
|
+
connect: () => Promise<void>;
|
|
548
|
+
disconnect: () => void;
|
|
549
|
+
/**
|
|
550
|
+
* Latest event received
|
|
551
|
+
*/
|
|
552
|
+
data: T | null;
|
|
553
|
+
/**
|
|
554
|
+
* All events received (if keepHistory is true)
|
|
555
|
+
*/
|
|
556
|
+
events: T[];
|
|
557
|
+
/**
|
|
558
|
+
* Whether the stream is currently connected
|
|
559
|
+
*/
|
|
560
|
+
isConnected: boolean;
|
|
561
|
+
/**
|
|
562
|
+
* Whether the stream is connecting
|
|
563
|
+
*/
|
|
564
|
+
isConnecting: boolean;
|
|
565
|
+
/**
|
|
566
|
+
* Error if connection failed
|
|
567
|
+
*/
|
|
568
|
+
error: Error | null;
|
|
569
|
+
};
|
|
570
|
+
|
|
571
|
+
export { SaferCityProvider, type SaferCityProviderProps, type StreamState, type UseStreamOptions, saferCityKeys, useCancelPanic, useCreatePanic, useCreateSubscription, useCreateUser, useCrimeCategories, useCrimeTypes, useCrimes, useDeleteUser, useHealthCheck, useLocationSafety, usePanic, usePanicStream, usePanics, useSaferCity, useSaferCityClient, useStream, useSubscriptionStats, useSubscriptionTypes, useSubscriptions, useUpdatePanicLocation, useUpdateUser, useUser, useUsers, useWhoAmI };
|