@safercity/sdk-react 0.1.2 → 0.2.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 +57 -12
- package/dist/index.cjs +134 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +226 -64
- package/dist/index.d.ts +226 -64
- package/dist/index.js +124 -39
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ProxyModeConfig, DirectModeConfig, CookieModeConfig, SaferCityClientOptions, SaferCityClient, AuthMode, ApiResponse, SaferCityApiError, ServerSentEvent } from '@safercity/sdk';
|
|
1
|
+
import { ProxyModeConfig, DirectModeConfig, CookieModeConfig, SaferCityClientOptions, SaferCityClient, AuthMode, ApiResponse, SaferCityApiError, PanicInformationRecord, ServerSentEvent } from '@safercity/sdk';
|
|
2
2
|
export * from '@safercity/sdk';
|
|
3
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
4
|
import { ReactNode } from 'react';
|
|
@@ -46,11 +46,13 @@ interface ProxyModeProviderProps extends BaseProviderProps, ProxyModeConfig {
|
|
|
46
46
|
* Props for direct mode
|
|
47
47
|
*/
|
|
48
48
|
interface DirectModeProviderProps extends BaseProviderProps, DirectModeConfig {
|
|
49
|
+
userId?: string;
|
|
49
50
|
}
|
|
50
51
|
/**
|
|
51
52
|
* Props for cookie mode
|
|
52
53
|
*/
|
|
53
54
|
interface CookieModeProviderProps extends BaseProviderProps, CookieModeConfig {
|
|
55
|
+
userId?: string;
|
|
54
56
|
}
|
|
55
57
|
/**
|
|
56
58
|
* Legacy props (for backward compatibility)
|
|
@@ -127,20 +129,34 @@ declare const saferCityKeys: {
|
|
|
127
129
|
auth: () => readonly ["safercity", "auth"];
|
|
128
130
|
authWhoami: () => readonly ["safercity", "auth", "whoami"];
|
|
129
131
|
users: () => readonly ["safercity", "users"];
|
|
130
|
-
usersList: (filters?: Record<string, unknown>) => readonly ["safercity", "users", "list", Record<string, unknown> | undefined];
|
|
131
132
|
usersDetail: (userId: string) => readonly ["safercity", "users", "detail", string];
|
|
132
133
|
panics: () => readonly ["safercity", "panics"];
|
|
133
134
|
panicsList: (filters?: Record<string, unknown>) => readonly ["safercity", "panics", "list", Record<string, unknown> | undefined];
|
|
134
135
|
panicsDetail: (panicId: string) => readonly ["safercity", "panics", "detail", string];
|
|
136
|
+
panicTypes: (userId: string) => readonly ["safercity", "panics", "types", string];
|
|
137
|
+
panicInformation: () => readonly ["safercity", "panicInformation"];
|
|
138
|
+
panicInformationDetail: (id: string) => readonly ["safercity", "panicInformation", "detail", string];
|
|
139
|
+
panicInformationByUser: (userId: string) => readonly ["safercity", "panicInformation", "byUser", string];
|
|
140
|
+
panicEligibility: (userId: string) => readonly ["safercity", "panicInformation", "eligibility", string];
|
|
135
141
|
subscriptions: () => readonly ["safercity", "subscriptions"];
|
|
136
142
|
subscriptionsList: (filters?: Record<string, unknown>) => readonly ["safercity", "subscriptions", "list", Record<string, unknown> | undefined];
|
|
137
143
|
subscriptionsTypes: () => readonly ["safercity", "subscriptions", "types"];
|
|
138
144
|
subscriptionsStats: () => readonly ["safercity", "subscriptions", "stats"];
|
|
139
145
|
locationSafety: (lat: number, lng: number) => readonly ["safercity", "location-safety", number, number];
|
|
146
|
+
banner: (body: {
|
|
147
|
+
latitude: number;
|
|
148
|
+
longitude: number;
|
|
149
|
+
radius?: number;
|
|
150
|
+
}) => readonly ["safercity", "banner", {
|
|
151
|
+
latitude: number;
|
|
152
|
+
longitude: number;
|
|
153
|
+
radius?: number;
|
|
154
|
+
}];
|
|
140
155
|
crimes: () => readonly ["safercity", "crimes"];
|
|
141
156
|
crimesList: (filters?: Record<string, unknown>) => readonly ["safercity", "crimes", "list", Record<string, unknown> | undefined];
|
|
142
157
|
crimesCategories: () => readonly ["safercity", "crimes", "categories"];
|
|
143
158
|
crimesTypes: () => readonly ["safercity", "crimes", "types"];
|
|
159
|
+
crimeCategoriesWithTypes: () => readonly ["safercity", "crimes", "categoriesWithTypes"];
|
|
144
160
|
};
|
|
145
161
|
declare function useHealthCheck(options?: Omit<UseQueryOptions<ApiResponse<{
|
|
146
162
|
status: string;
|
|
@@ -160,29 +176,6 @@ declare function useWhoAmI(options?: Omit<UseQueryOptions<ApiResponse<{
|
|
|
160
176
|
scopes: string[];
|
|
161
177
|
sessionId: string;
|
|
162
178
|
}>, SaferCityApiError>;
|
|
163
|
-
declare function useUsers(filters?: {
|
|
164
|
-
limit?: number;
|
|
165
|
-
cursor?: string;
|
|
166
|
-
status?: string;
|
|
167
|
-
}, options?: Omit<UseQueryOptions<ApiResponse<{
|
|
168
|
-
users: Array<{
|
|
169
|
-
id: string;
|
|
170
|
-
email?: string;
|
|
171
|
-
phone?: string;
|
|
172
|
-
status: string;
|
|
173
|
-
}>;
|
|
174
|
-
hasNext: boolean;
|
|
175
|
-
cursor?: string;
|
|
176
|
-
}>, SaferCityApiError>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseQueryResult<ApiResponse<{
|
|
177
|
-
users: Array<{
|
|
178
|
-
id: string;
|
|
179
|
-
email?: string;
|
|
180
|
-
phone?: string;
|
|
181
|
-
status: string;
|
|
182
|
-
}>;
|
|
183
|
-
hasNext: boolean;
|
|
184
|
-
cursor?: string;
|
|
185
|
-
}>, SaferCityApiError>;
|
|
186
179
|
declare function useUser(userId: string, options?: Omit<UseQueryOptions<ApiResponse<{
|
|
187
180
|
id: string;
|
|
188
181
|
email?: string;
|
|
@@ -244,35 +237,6 @@ declare function useUpdateUser(options?: UseMutationOptions<ApiResponse<{
|
|
|
244
237
|
metadata?: Record<string, unknown>;
|
|
245
238
|
};
|
|
246
239
|
}, unknown>;
|
|
247
|
-
declare function useDeleteUser(options?: UseMutationOptions<ApiResponse<{
|
|
248
|
-
success: boolean;
|
|
249
|
-
}>, SaferCityApiError, string>): _tanstack_react_query.UseMutationResult<ApiResponse<{
|
|
250
|
-
success: boolean;
|
|
251
|
-
}>, SaferCityApiError, string, unknown>;
|
|
252
|
-
declare function usePanics(filters?: {
|
|
253
|
-
userId?: string;
|
|
254
|
-
status?: string;
|
|
255
|
-
limit?: number;
|
|
256
|
-
cursor?: string;
|
|
257
|
-
}, options?: Omit<UseQueryOptions<ApiResponse<{
|
|
258
|
-
panics: Array<{
|
|
259
|
-
id: string;
|
|
260
|
-
userId: string;
|
|
261
|
-
status: string;
|
|
262
|
-
createdAt: string;
|
|
263
|
-
}>;
|
|
264
|
-
hasNext: boolean;
|
|
265
|
-
cursor?: string;
|
|
266
|
-
}>, SaferCityApiError>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseQueryResult<ApiResponse<{
|
|
267
|
-
panics: Array<{
|
|
268
|
-
id: string;
|
|
269
|
-
userId: string;
|
|
270
|
-
status: string;
|
|
271
|
-
createdAt: string;
|
|
272
|
-
}>;
|
|
273
|
-
hasNext: boolean;
|
|
274
|
-
cursor?: string;
|
|
275
|
-
}>, SaferCityApiError>;
|
|
276
240
|
declare function usePanic(panicId: string, query?: {
|
|
277
241
|
userId?: string;
|
|
278
242
|
}, options?: Omit<UseQueryOptions<ApiResponse<{
|
|
@@ -361,6 +325,137 @@ declare function useCancelPanic(options?: UseMutationOptions<ApiResponse<{
|
|
|
361
325
|
reason?: string;
|
|
362
326
|
};
|
|
363
327
|
}, unknown>;
|
|
328
|
+
declare function usePanicTypes(userId: string, options?: Omit<UseQueryOptions<ApiResponse<{
|
|
329
|
+
types: Array<{
|
|
330
|
+
id: string;
|
|
331
|
+
name: string;
|
|
332
|
+
description?: string;
|
|
333
|
+
}>;
|
|
334
|
+
}>, SaferCityApiError>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseQueryResult<ApiResponse<{
|
|
335
|
+
types: Array<{
|
|
336
|
+
id: string;
|
|
337
|
+
name: string;
|
|
338
|
+
description?: string;
|
|
339
|
+
}>;
|
|
340
|
+
}>, SaferCityApiError>;
|
|
341
|
+
declare function usePanicInformation(id: string, options?: Omit<UseQueryOptions<ApiResponse<{
|
|
342
|
+
success: boolean;
|
|
343
|
+
data: PanicInformationRecord;
|
|
344
|
+
}>, SaferCityApiError>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseQueryResult<ApiResponse<{
|
|
345
|
+
success: boolean;
|
|
346
|
+
data: PanicInformationRecord;
|
|
347
|
+
}>, SaferCityApiError>;
|
|
348
|
+
declare function usePanicInformationByUser(userId: string, options?: Omit<UseQueryOptions<ApiResponse<{
|
|
349
|
+
success: boolean;
|
|
350
|
+
data: PanicInformationRecord;
|
|
351
|
+
}>, SaferCityApiError>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseQueryResult<ApiResponse<{
|
|
352
|
+
success: boolean;
|
|
353
|
+
data: PanicInformationRecord;
|
|
354
|
+
}>, SaferCityApiError>;
|
|
355
|
+
declare function usePanicEligibility(userId: string, options?: Omit<UseQueryOptions<ApiResponse<{
|
|
356
|
+
success: boolean;
|
|
357
|
+
data: {
|
|
358
|
+
eligible: boolean;
|
|
359
|
+
subscriptionActive: boolean;
|
|
360
|
+
profileComplete: boolean;
|
|
361
|
+
reasons: string[];
|
|
362
|
+
panicInformation: PanicInformationRecord | null;
|
|
363
|
+
subscriptionDetails: {
|
|
364
|
+
usedSeats: number;
|
|
365
|
+
userHasActiveSubscription: boolean;
|
|
366
|
+
} | null;
|
|
367
|
+
};
|
|
368
|
+
}>, SaferCityApiError>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseQueryResult<ApiResponse<{
|
|
369
|
+
success: boolean;
|
|
370
|
+
data: {
|
|
371
|
+
eligible: boolean;
|
|
372
|
+
subscriptionActive: boolean;
|
|
373
|
+
profileComplete: boolean;
|
|
374
|
+
reasons: string[];
|
|
375
|
+
panicInformation: PanicInformationRecord | null;
|
|
376
|
+
subscriptionDetails: {
|
|
377
|
+
usedSeats: number;
|
|
378
|
+
userHasActiveSubscription: boolean;
|
|
379
|
+
} | null;
|
|
380
|
+
};
|
|
381
|
+
}>, SaferCityApiError>;
|
|
382
|
+
declare function useCreatePanicInformation(options?: UseMutationOptions<ApiResponse<{
|
|
383
|
+
success: boolean;
|
|
384
|
+
data: PanicInformationRecord;
|
|
385
|
+
message: string;
|
|
386
|
+
}>, SaferCityApiError, {
|
|
387
|
+
userId: string;
|
|
388
|
+
phoneNumber: string;
|
|
389
|
+
firstName: string;
|
|
390
|
+
lastName: string;
|
|
391
|
+
idNumber: string;
|
|
392
|
+
duressCode?: string;
|
|
393
|
+
emergencyContacts?: Array<{
|
|
394
|
+
name: string;
|
|
395
|
+
phoneNumber: string;
|
|
396
|
+
relationship?: string;
|
|
397
|
+
}>;
|
|
398
|
+
}>): _tanstack_react_query.UseMutationResult<ApiResponse<{
|
|
399
|
+
success: boolean;
|
|
400
|
+
data: PanicInformationRecord;
|
|
401
|
+
message: string;
|
|
402
|
+
}>, SaferCityApiError, {
|
|
403
|
+
userId: string;
|
|
404
|
+
phoneNumber: string;
|
|
405
|
+
firstName: string;
|
|
406
|
+
lastName: string;
|
|
407
|
+
idNumber: string;
|
|
408
|
+
duressCode?: string;
|
|
409
|
+
emergencyContacts?: Array<{
|
|
410
|
+
name: string;
|
|
411
|
+
phoneNumber: string;
|
|
412
|
+
relationship?: string;
|
|
413
|
+
}>;
|
|
414
|
+
}, unknown>;
|
|
415
|
+
declare function useUpdatePanicInformation(options?: UseMutationOptions<ApiResponse<{
|
|
416
|
+
success: boolean;
|
|
417
|
+
data: PanicInformationRecord;
|
|
418
|
+
message: string;
|
|
419
|
+
}>, SaferCityApiError, {
|
|
420
|
+
id: string;
|
|
421
|
+
data: {
|
|
422
|
+
phoneNumber?: string;
|
|
423
|
+
firstName?: string;
|
|
424
|
+
lastName?: string;
|
|
425
|
+
idNumber?: string;
|
|
426
|
+
duressCode?: string;
|
|
427
|
+
emergencyContacts?: Array<{
|
|
428
|
+
name: string;
|
|
429
|
+
phoneNumber: string;
|
|
430
|
+
relationship?: string;
|
|
431
|
+
}>;
|
|
432
|
+
};
|
|
433
|
+
}>): _tanstack_react_query.UseMutationResult<ApiResponse<{
|
|
434
|
+
success: boolean;
|
|
435
|
+
data: PanicInformationRecord;
|
|
436
|
+
message: string;
|
|
437
|
+
}>, SaferCityApiError, {
|
|
438
|
+
id: string;
|
|
439
|
+
data: {
|
|
440
|
+
phoneNumber?: string;
|
|
441
|
+
firstName?: string;
|
|
442
|
+
lastName?: string;
|
|
443
|
+
idNumber?: string;
|
|
444
|
+
duressCode?: string;
|
|
445
|
+
emergencyContacts?: Array<{
|
|
446
|
+
name: string;
|
|
447
|
+
phoneNumber: string;
|
|
448
|
+
relationship?: string;
|
|
449
|
+
}>;
|
|
450
|
+
};
|
|
451
|
+
}, unknown>;
|
|
452
|
+
declare function useDeletePanicInformation(options?: UseMutationOptions<ApiResponse<{
|
|
453
|
+
success: boolean;
|
|
454
|
+
message: string;
|
|
455
|
+
}>, SaferCityApiError, string>): _tanstack_react_query.UseMutationResult<ApiResponse<{
|
|
456
|
+
success: boolean;
|
|
457
|
+
message: string;
|
|
458
|
+
}>, SaferCityApiError, string, unknown>;
|
|
364
459
|
declare function useSubscriptionTypes(options?: Omit<UseQueryOptions<ApiResponse<{
|
|
365
460
|
types: Array<{
|
|
366
461
|
id: string;
|
|
@@ -395,15 +490,6 @@ declare function useSubscriptions(filters?: {
|
|
|
395
490
|
status: string;
|
|
396
491
|
}>;
|
|
397
492
|
}>, SaferCityApiError>;
|
|
398
|
-
declare function useSubscriptionStats(options?: Omit<UseQueryOptions<ApiResponse<{
|
|
399
|
-
total: number;
|
|
400
|
-
active: number;
|
|
401
|
-
byType: Record<string, number>;
|
|
402
|
-
}>, SaferCityApiError>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseQueryResult<ApiResponse<{
|
|
403
|
-
total: number;
|
|
404
|
-
active: number;
|
|
405
|
-
byType: Record<string, number>;
|
|
406
|
-
}>, SaferCityApiError>;
|
|
407
493
|
declare function useCreateSubscription(options?: UseMutationOptions<ApiResponse<{
|
|
408
494
|
id: string;
|
|
409
495
|
userId: string;
|
|
@@ -423,6 +509,38 @@ declare function useCreateSubscription(options?: UseMutationOptions<ApiResponse<
|
|
|
423
509
|
subscriptionTypeId: string;
|
|
424
510
|
status?: string;
|
|
425
511
|
}, unknown>;
|
|
512
|
+
declare function useSubscribeUser(options?: UseMutationOptions<ApiResponse<{
|
|
513
|
+
id: string;
|
|
514
|
+
userId: string;
|
|
515
|
+
subscriptionTypeId: string;
|
|
516
|
+
status: string;
|
|
517
|
+
}>, SaferCityApiError, {
|
|
518
|
+
userId: string;
|
|
519
|
+
subscriptionTypeId: string;
|
|
520
|
+
}>): _tanstack_react_query.UseMutationResult<ApiResponse<{
|
|
521
|
+
id: string;
|
|
522
|
+
userId: string;
|
|
523
|
+
subscriptionTypeId: string;
|
|
524
|
+
status: string;
|
|
525
|
+
}>, SaferCityApiError, {
|
|
526
|
+
userId: string;
|
|
527
|
+
subscriptionTypeId: string;
|
|
528
|
+
}, unknown>;
|
|
529
|
+
declare function useBulkTriggerNotifications(options?: UseMutationOptions<ApiResponse<{
|
|
530
|
+
transactionIds: string[];
|
|
531
|
+
status: string;
|
|
532
|
+
}>, SaferCityApiError, {
|
|
533
|
+
userIds: string[];
|
|
534
|
+
workflowId: string;
|
|
535
|
+
payload?: Record<string, unknown>;
|
|
536
|
+
}>): _tanstack_react_query.UseMutationResult<ApiResponse<{
|
|
537
|
+
transactionIds: string[];
|
|
538
|
+
status: string;
|
|
539
|
+
}>, SaferCityApiError, {
|
|
540
|
+
userIds: string[];
|
|
541
|
+
workflowId: string;
|
|
542
|
+
payload?: Record<string, unknown>;
|
|
543
|
+
}, unknown>;
|
|
426
544
|
declare function useLocationSafety(latitude: number, longitude: number, radius?: number, options?: Omit<UseQueryOptions<ApiResponse<{
|
|
427
545
|
safetyScore: number;
|
|
428
546
|
riskLevel: string;
|
|
@@ -438,6 +556,31 @@ declare function useLocationSafety(latitude: number, longitude: number, radius?:
|
|
|
438
556
|
impact: number;
|
|
439
557
|
}>;
|
|
440
558
|
}>, SaferCityApiError>;
|
|
559
|
+
declare function useBanner(body: {
|
|
560
|
+
latitude: number;
|
|
561
|
+
longitude: number;
|
|
562
|
+
radius?: number;
|
|
563
|
+
}, options?: Omit<UseQueryOptions<ApiResponse<{
|
|
564
|
+
success: boolean;
|
|
565
|
+
data: {
|
|
566
|
+
totalCrimes: number;
|
|
567
|
+
categories: Array<{
|
|
568
|
+
name: string;
|
|
569
|
+
count: number;
|
|
570
|
+
}>;
|
|
571
|
+
period: string;
|
|
572
|
+
};
|
|
573
|
+
}>, SaferCityApiError>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseQueryResult<ApiResponse<{
|
|
574
|
+
success: boolean;
|
|
575
|
+
data: {
|
|
576
|
+
totalCrimes: number;
|
|
577
|
+
categories: Array<{
|
|
578
|
+
name: string;
|
|
579
|
+
count: number;
|
|
580
|
+
}>;
|
|
581
|
+
period: string;
|
|
582
|
+
};
|
|
583
|
+
}>, SaferCityApiError>;
|
|
441
584
|
declare function useCrimes(filters?: {
|
|
442
585
|
latitude?: number;
|
|
443
586
|
longitude?: number;
|
|
@@ -487,6 +630,25 @@ declare function useCrimeTypes(options?: Omit<UseQueryOptions<ApiResponse<{
|
|
|
487
630
|
categoryId: string;
|
|
488
631
|
}>;
|
|
489
632
|
}>, SaferCityApiError>;
|
|
633
|
+
declare function useCrimeCategoriesWithTypes(options?: Omit<UseQueryOptions<ApiResponse<{
|
|
634
|
+
categories: Array<{
|
|
635
|
+
id: string;
|
|
636
|
+
name: string;
|
|
637
|
+
types: Array<{
|
|
638
|
+
id: string;
|
|
639
|
+
name: string;
|
|
640
|
+
}>;
|
|
641
|
+
}>;
|
|
642
|
+
}>, SaferCityApiError>, 'queryKey' | 'queryFn'>): _tanstack_react_query.UseQueryResult<ApiResponse<{
|
|
643
|
+
categories: Array<{
|
|
644
|
+
id: string;
|
|
645
|
+
name: string;
|
|
646
|
+
types: Array<{
|
|
647
|
+
id: string;
|
|
648
|
+
name: string;
|
|
649
|
+
}>;
|
|
650
|
+
}>;
|
|
651
|
+
}>, SaferCityApiError>;
|
|
490
652
|
|
|
491
653
|
/**
|
|
492
654
|
* State for streaming hooks
|
|
@@ -619,4 +781,4 @@ declare function useStream<T = ServerSentEvent>(createStream: () => AsyncIterabl
|
|
|
619
781
|
error: Error | null;
|
|
620
782
|
};
|
|
621
783
|
|
|
622
|
-
export { type CookieModeProviderProps, type DirectModeProviderProps, type ProxyModeProviderProps, SaferCityProvider, type SaferCityProviderProps, type SessionState, type StreamState, type UseStreamOptions, saferCityKeys, useAuthMode, useCancelPanic, useCreatePanic, useCreateSubscription, useCreateUser, useCrimeCategories, useCrimeTypes, useCrimes,
|
|
784
|
+
export { type CookieModeProviderProps, type DirectModeProviderProps, type ProxyModeProviderProps, SaferCityProvider, type SaferCityProviderProps, type SessionState, type StreamState, type UseStreamOptions, saferCityKeys, useAuthMode, useBanner, useBulkTriggerNotifications, useCancelPanic, useCreatePanic, useCreatePanicInformation, useCreateSubscription, useCreateUser, useCrimeCategories, useCrimeCategoriesWithTypes, useCrimeTypes, useCrimes, useDeletePanicInformation, useHealthCheck, useLocationSafety, usePanic, usePanicEligibility, usePanicInformation, usePanicInformationByUser, usePanicStream, usePanicTypes, useSaferCity, useSaferCityClient, useSession, useSessionManager, useStream, useSubscribeUser, useSubscriptionTypes, useSubscriptions, useUpdatePanicInformation, useUpdatePanicLocation, useUpdateUser, useUser, useWhoAmI };
|
package/dist/index.js
CHANGED
|
@@ -48,13 +48,15 @@ function SaferCityProvider(props) {
|
|
|
48
48
|
if (isDirectMode(props)) {
|
|
49
49
|
return createSaferCityClient({
|
|
50
50
|
baseUrl: props.baseUrl,
|
|
51
|
-
tenantId: props.tenantId
|
|
51
|
+
tenantId: props.tenantId,
|
|
52
|
+
userId: props.userId
|
|
52
53
|
});
|
|
53
54
|
}
|
|
54
55
|
if (isCookieMode(props)) {
|
|
55
56
|
return createSaferCityClient({
|
|
56
57
|
baseUrl: props.baseUrl,
|
|
57
58
|
tenantId: props.tenantId,
|
|
59
|
+
userId: props.userId,
|
|
58
60
|
headers: {
|
|
59
61
|
// Note: cookies are sent automatically with fetch credentials: 'include'
|
|
60
62
|
}
|
|
@@ -91,6 +93,7 @@ function SaferCityProvider(props) {
|
|
|
91
93
|
if (!isMounted) return;
|
|
92
94
|
if (response.ok) {
|
|
93
95
|
const data = await response.json();
|
|
96
|
+
client.setUserId(data.userId);
|
|
94
97
|
setSession({
|
|
95
98
|
isAuthenticated: data.authenticated,
|
|
96
99
|
isLoading: false,
|
|
@@ -117,7 +120,7 @@ function SaferCityProvider(props) {
|
|
|
117
120
|
return () => {
|
|
118
121
|
isMounted = false;
|
|
119
122
|
};
|
|
120
|
-
}, [mode, props]);
|
|
123
|
+
}, [mode, props, client]);
|
|
121
124
|
const createSession = useCallback(async (token, tenantId) => {
|
|
122
125
|
if (mode !== "cookie" || !isCookieMode(props)) {
|
|
123
126
|
throw new Error("createSession is only available in cookie mode");
|
|
@@ -252,12 +255,17 @@ var saferCityKeys = {
|
|
|
252
255
|
authWhoami: () => [...saferCityKeys.auth(), "whoami"],
|
|
253
256
|
// Users
|
|
254
257
|
users: () => [...saferCityKeys.all, "users"],
|
|
255
|
-
usersList: (filters) => [...saferCityKeys.users(), "list", filters],
|
|
256
258
|
usersDetail: (userId) => [...saferCityKeys.users(), "detail", userId],
|
|
257
259
|
// Panics
|
|
258
260
|
panics: () => [...saferCityKeys.all, "panics"],
|
|
259
261
|
panicsList: (filters) => [...saferCityKeys.panics(), "list", filters],
|
|
260
262
|
panicsDetail: (panicId) => [...saferCityKeys.panics(), "detail", panicId],
|
|
263
|
+
panicTypes: (userId) => [...saferCityKeys.panics(), "types", userId],
|
|
264
|
+
// Panic Information
|
|
265
|
+
panicInformation: () => [...saferCityKeys.all, "panicInformation"],
|
|
266
|
+
panicInformationDetail: (id) => [...saferCityKeys.panicInformation(), "detail", id],
|
|
267
|
+
panicInformationByUser: (userId) => [...saferCityKeys.panicInformation(), "byUser", userId],
|
|
268
|
+
panicEligibility: (userId) => [...saferCityKeys.panicInformation(), "eligibility", userId],
|
|
261
269
|
// Subscriptions
|
|
262
270
|
subscriptions: () => [...saferCityKeys.all, "subscriptions"],
|
|
263
271
|
subscriptionsList: (filters) => [...saferCityKeys.subscriptions(), "list", filters],
|
|
@@ -265,11 +273,14 @@ var saferCityKeys = {
|
|
|
265
273
|
subscriptionsStats: () => [...saferCityKeys.subscriptions(), "stats"],
|
|
266
274
|
// Location Safety
|
|
267
275
|
locationSafety: (lat, lng) => [...saferCityKeys.all, "location-safety", lat, lng],
|
|
276
|
+
// Banner
|
|
277
|
+
banner: (body) => [...saferCityKeys.all, "banner", body],
|
|
268
278
|
// Crimes
|
|
269
279
|
crimes: () => [...saferCityKeys.all, "crimes"],
|
|
270
280
|
crimesList: (filters) => [...saferCityKeys.crimes(), "list", filters],
|
|
271
281
|
crimesCategories: () => [...saferCityKeys.crimes(), "categories"],
|
|
272
|
-
crimesTypes: () => [...saferCityKeys.crimes(), "types"]
|
|
282
|
+
crimesTypes: () => [...saferCityKeys.crimes(), "types"],
|
|
283
|
+
crimeCategoriesWithTypes: () => [...saferCityKeys.crimes(), "categoriesWithTypes"]
|
|
273
284
|
};
|
|
274
285
|
function useHealthCheck(options) {
|
|
275
286
|
const client = useSaferCityClient();
|
|
@@ -287,14 +298,6 @@ function useWhoAmI(options) {
|
|
|
287
298
|
...options
|
|
288
299
|
});
|
|
289
300
|
}
|
|
290
|
-
function useUsers(filters, options) {
|
|
291
|
-
const client = useSaferCityClient();
|
|
292
|
-
return useQuery({
|
|
293
|
-
queryKey: saferCityKeys.usersList(filters),
|
|
294
|
-
queryFn: () => client.users.list(filters),
|
|
295
|
-
...options
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
301
|
function useUser(userId, options) {
|
|
299
302
|
const client = useSaferCityClient();
|
|
300
303
|
return useQuery({
|
|
@@ -322,30 +325,10 @@ function useUpdateUser(options) {
|
|
|
322
325
|
mutationFn: ({ userId, data }) => client.users.update(userId, data),
|
|
323
326
|
onSuccess: (_, { userId }) => {
|
|
324
327
|
queryClient.invalidateQueries({ queryKey: saferCityKeys.usersDetail(userId) });
|
|
325
|
-
queryClient.invalidateQueries({ queryKey: saferCityKeys.usersList() });
|
|
326
328
|
},
|
|
327
329
|
...options
|
|
328
330
|
});
|
|
329
331
|
}
|
|
330
|
-
function useDeleteUser(options) {
|
|
331
|
-
const client = useSaferCityClient();
|
|
332
|
-
const queryClient = useQueryClient();
|
|
333
|
-
return useMutation({
|
|
334
|
-
mutationFn: (userId) => client.users.delete(userId),
|
|
335
|
-
onSuccess: () => {
|
|
336
|
-
queryClient.invalidateQueries({ queryKey: saferCityKeys.users() });
|
|
337
|
-
},
|
|
338
|
-
...options
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
function usePanics(filters, options) {
|
|
342
|
-
const client = useSaferCityClient();
|
|
343
|
-
return useQuery({
|
|
344
|
-
queryKey: saferCityKeys.panicsList(filters),
|
|
345
|
-
queryFn: () => client.panics.list(filters),
|
|
346
|
-
...options
|
|
347
|
-
});
|
|
348
|
-
}
|
|
349
332
|
function usePanic(panicId, query, options) {
|
|
350
333
|
const client = useSaferCityClient();
|
|
351
334
|
return useQuery({
|
|
@@ -389,6 +372,77 @@ function useCancelPanic(options) {
|
|
|
389
372
|
...options
|
|
390
373
|
});
|
|
391
374
|
}
|
|
375
|
+
function usePanicTypes(userId, options) {
|
|
376
|
+
const client = useSaferCityClient();
|
|
377
|
+
return useQuery({
|
|
378
|
+
queryKey: saferCityKeys.panicTypes(userId),
|
|
379
|
+
queryFn: () => client.panics.types(userId),
|
|
380
|
+
enabled: !!userId,
|
|
381
|
+
staleTime: 1e3 * 60 * 10,
|
|
382
|
+
// 10 minutes - types don't change often
|
|
383
|
+
...options
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
function usePanicInformation(id, options) {
|
|
387
|
+
const client = useSaferCityClient();
|
|
388
|
+
return useQuery({
|
|
389
|
+
queryKey: saferCityKeys.panicInformationDetail(id),
|
|
390
|
+
queryFn: () => client.panicInformation.get(id),
|
|
391
|
+
enabled: !!id,
|
|
392
|
+
...options
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
function usePanicInformationByUser(userId, options) {
|
|
396
|
+
const client = useSaferCityClient();
|
|
397
|
+
return useQuery({
|
|
398
|
+
queryKey: saferCityKeys.panicInformationByUser(userId),
|
|
399
|
+
queryFn: () => client.panicInformation.getByUser(userId),
|
|
400
|
+
enabled: !!userId,
|
|
401
|
+
...options
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
function usePanicEligibility(userId, options) {
|
|
405
|
+
const client = useSaferCityClient();
|
|
406
|
+
return useQuery({
|
|
407
|
+
queryKey: saferCityKeys.panicEligibility(userId),
|
|
408
|
+
queryFn: () => client.panicInformation.validateEligibility(userId),
|
|
409
|
+
enabled: !!userId,
|
|
410
|
+
...options
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
function useCreatePanicInformation(options) {
|
|
414
|
+
const client = useSaferCityClient();
|
|
415
|
+
const queryClient = useQueryClient();
|
|
416
|
+
return useMutation({
|
|
417
|
+
mutationFn: (data) => client.panicInformation.create(data),
|
|
418
|
+
onSuccess: () => {
|
|
419
|
+
queryClient.invalidateQueries({ queryKey: saferCityKeys.panicInformation() });
|
|
420
|
+
},
|
|
421
|
+
...options
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
function useUpdatePanicInformation(options) {
|
|
425
|
+
const client = useSaferCityClient();
|
|
426
|
+
const queryClient = useQueryClient();
|
|
427
|
+
return useMutation({
|
|
428
|
+
mutationFn: ({ id, data }) => client.panicInformation.update(id, data),
|
|
429
|
+
onSuccess: () => {
|
|
430
|
+
queryClient.invalidateQueries({ queryKey: saferCityKeys.panicInformation() });
|
|
431
|
+
},
|
|
432
|
+
...options
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
function useDeletePanicInformation(options) {
|
|
436
|
+
const client = useSaferCityClient();
|
|
437
|
+
const queryClient = useQueryClient();
|
|
438
|
+
return useMutation({
|
|
439
|
+
mutationFn: (id) => client.panicInformation.delete(id),
|
|
440
|
+
onSuccess: () => {
|
|
441
|
+
queryClient.invalidateQueries({ queryKey: saferCityKeys.panicInformation() });
|
|
442
|
+
},
|
|
443
|
+
...options
|
|
444
|
+
});
|
|
445
|
+
}
|
|
392
446
|
function useSubscriptionTypes(options) {
|
|
393
447
|
const client = useSaferCityClient();
|
|
394
448
|
return useQuery({
|
|
@@ -407,25 +461,35 @@ function useSubscriptions(filters, options) {
|
|
|
407
461
|
...options
|
|
408
462
|
});
|
|
409
463
|
}
|
|
410
|
-
function
|
|
464
|
+
function useCreateSubscription(options) {
|
|
411
465
|
const client = useSaferCityClient();
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
466
|
+
const queryClient = useQueryClient();
|
|
467
|
+
return useMutation({
|
|
468
|
+
mutationFn: (data) => client.subscriptions.create(data),
|
|
469
|
+
onSuccess: () => {
|
|
470
|
+
queryClient.invalidateQueries({ queryKey: saferCityKeys.subscriptions() });
|
|
471
|
+
},
|
|
415
472
|
...options
|
|
416
473
|
});
|
|
417
474
|
}
|
|
418
|
-
function
|
|
475
|
+
function useSubscribeUser(options) {
|
|
419
476
|
const client = useSaferCityClient();
|
|
420
477
|
const queryClient = useQueryClient();
|
|
421
478
|
return useMutation({
|
|
422
|
-
mutationFn: (
|
|
479
|
+
mutationFn: (body) => client.subscriptions.subscribeUser(body),
|
|
423
480
|
onSuccess: () => {
|
|
424
481
|
queryClient.invalidateQueries({ queryKey: saferCityKeys.subscriptions() });
|
|
425
482
|
},
|
|
426
483
|
...options
|
|
427
484
|
});
|
|
428
485
|
}
|
|
486
|
+
function useBulkTriggerNotifications(options) {
|
|
487
|
+
const client = useSaferCityClient();
|
|
488
|
+
return useMutation({
|
|
489
|
+
mutationFn: (body) => client.notifications.bulkTrigger(body),
|
|
490
|
+
...options
|
|
491
|
+
});
|
|
492
|
+
}
|
|
429
493
|
function useLocationSafety(latitude, longitude, radius, options) {
|
|
430
494
|
const client = useSaferCityClient();
|
|
431
495
|
return useQuery({
|
|
@@ -437,6 +501,17 @@ function useLocationSafety(latitude, longitude, radius, options) {
|
|
|
437
501
|
...options
|
|
438
502
|
});
|
|
439
503
|
}
|
|
504
|
+
function useBanner(body, options) {
|
|
505
|
+
const client = useSaferCityClient();
|
|
506
|
+
return useQuery({
|
|
507
|
+
queryKey: saferCityKeys.banner(body),
|
|
508
|
+
queryFn: () => client.banner.get(body),
|
|
509
|
+
enabled: body.latitude !== void 0 && body.longitude !== void 0,
|
|
510
|
+
staleTime: 1e3 * 60 * 5,
|
|
511
|
+
// 5 minutes - location-based, changes moderately
|
|
512
|
+
...options
|
|
513
|
+
});
|
|
514
|
+
}
|
|
440
515
|
function useCrimes(filters, options) {
|
|
441
516
|
const client = useSaferCityClient();
|
|
442
517
|
return useQuery({
|
|
@@ -465,6 +540,16 @@ function useCrimeTypes(options) {
|
|
|
465
540
|
...options
|
|
466
541
|
});
|
|
467
542
|
}
|
|
543
|
+
function useCrimeCategoriesWithTypes(options) {
|
|
544
|
+
const client = useSaferCityClient();
|
|
545
|
+
return useQuery({
|
|
546
|
+
queryKey: saferCityKeys.crimeCategoriesWithTypes(),
|
|
547
|
+
queryFn: () => client.crimes.categoriesWithTypes(),
|
|
548
|
+
staleTime: 1e3 * 60 * 30,
|
|
549
|
+
// 30 minutes - categories rarely change
|
|
550
|
+
...options
|
|
551
|
+
});
|
|
552
|
+
}
|
|
468
553
|
function usePanicStream(panicId, options = {}) {
|
|
469
554
|
const client = useSaferCityClient();
|
|
470
555
|
const {
|
|
@@ -659,6 +744,6 @@ function useStream(createStream, options = {}) {
|
|
|
659
744
|
};
|
|
660
745
|
}
|
|
661
746
|
|
|
662
|
-
export { SaferCityProvider, saferCityKeys, useAuthMode, useCancelPanic, useCreatePanic, useCreateSubscription, useCreateUser, useCrimeCategories, useCrimeTypes, useCrimes,
|
|
747
|
+
export { SaferCityProvider, saferCityKeys, useAuthMode, useBanner, useBulkTriggerNotifications, useCancelPanic, useCreatePanic, useCreatePanicInformation, useCreateSubscription, useCreateUser, useCrimeCategories, useCrimeCategoriesWithTypes, useCrimeTypes, useCrimes, useDeletePanicInformation, useHealthCheck, useLocationSafety, usePanic, usePanicEligibility, usePanicInformation, usePanicInformationByUser, usePanicStream, usePanicTypes, useSaferCity, useSaferCityClient, useSession, useSessionManager, useStream, useSubscribeUser, useSubscriptionTypes, useSubscriptions, useUpdatePanicInformation, useUpdatePanicLocation, useUpdateUser, useUser, useWhoAmI };
|
|
663
748
|
//# sourceMappingURL=index.js.map
|
|
664
749
|
//# sourceMappingURL=index.js.map
|