@safercity/sdk 0.1.1 → 0.1.3
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 +17 -3
- package/dist/index.cjs +252 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +456 -48
- package/dist/index.d.ts +456 -48
- package/dist/index.js +252 -13
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -265,24 +265,6 @@ declare function createSaferCityClient(options: SaferCityClientOptions): {
|
|
|
265
265
|
createdAt: string;
|
|
266
266
|
updatedAt?: string;
|
|
267
267
|
}>>;
|
|
268
|
-
/**
|
|
269
|
-
* List panics
|
|
270
|
-
*/
|
|
271
|
-
list: (query?: {
|
|
272
|
-
userId?: string;
|
|
273
|
-
status?: string;
|
|
274
|
-
limit?: number;
|
|
275
|
-
cursor?: string;
|
|
276
|
-
}) => Promise<_safercity_sdk_core.ApiResponse<{
|
|
277
|
-
panics: Array<{
|
|
278
|
-
id: string;
|
|
279
|
-
userId: string;
|
|
280
|
-
status: string;
|
|
281
|
-
createdAt: string;
|
|
282
|
-
}>;
|
|
283
|
-
hasNext: boolean;
|
|
284
|
-
cursor?: string;
|
|
285
|
-
}>>;
|
|
286
268
|
/**
|
|
287
269
|
* Update panic location
|
|
288
270
|
*/
|
|
@@ -352,14 +334,6 @@ declare function createSaferCityClient(options: SaferCityClientOptions): {
|
|
|
352
334
|
status: string;
|
|
353
335
|
}>;
|
|
354
336
|
}>>;
|
|
355
|
-
/**
|
|
356
|
-
* Get subscription stats
|
|
357
|
-
*/
|
|
358
|
-
stats: () => Promise<_safercity_sdk_core.ApiResponse<{
|
|
359
|
-
total: number;
|
|
360
|
-
active: number;
|
|
361
|
-
byType: Record<string, number>;
|
|
362
|
-
}>>;
|
|
363
337
|
};
|
|
364
338
|
notifications: {
|
|
365
339
|
/**
|
|
@@ -460,19 +434,7 @@ declare function createSaferCityClient(options: SaferCityClientOptions): {
|
|
|
460
434
|
};
|
|
461
435
|
type SaferCityClient = ReturnType<typeof createSaferCityClient>;
|
|
462
436
|
|
|
463
|
-
|
|
464
|
-
* Server-side SaferCity Client
|
|
465
|
-
*
|
|
466
|
-
* For backend applications that need to authenticate with OAuth client credentials.
|
|
467
|
-
* Handles automatic token management and refresh.
|
|
468
|
-
*/
|
|
469
|
-
|
|
470
|
-
interface ServerClientConfig {
|
|
471
|
-
/**
|
|
472
|
-
* SaferCity API base URL
|
|
473
|
-
* @default "https://api.safercity.com"
|
|
474
|
-
*/
|
|
475
|
-
baseUrl?: string;
|
|
437
|
+
interface ServerClientConfig extends Pick<SaferCityConfig, 'baseUrl' | 'timeout' | 'fetch'> {
|
|
476
438
|
/**
|
|
477
439
|
* OAuth credentials for authentication
|
|
478
440
|
*/
|
|
@@ -481,15 +443,6 @@ interface ServerClientConfig {
|
|
|
481
443
|
* Custom token storage (defaults to in-memory)
|
|
482
444
|
*/
|
|
483
445
|
tokenStore?: TokenStorage;
|
|
484
|
-
/**
|
|
485
|
-
* Request timeout in milliseconds
|
|
486
|
-
* @default 30000
|
|
487
|
-
*/
|
|
488
|
-
timeout?: number;
|
|
489
|
-
/**
|
|
490
|
-
* Custom fetch implementation
|
|
491
|
-
*/
|
|
492
|
-
fetch?: typeof fetch;
|
|
493
446
|
}
|
|
494
447
|
/**
|
|
495
448
|
* Server client that wraps the base client with automatic OAuth token management
|
|
@@ -518,6 +471,461 @@ declare class ServerClient extends BaseClient {
|
|
|
518
471
|
status: number;
|
|
519
472
|
headers: Headers;
|
|
520
473
|
}>;
|
|
474
|
+
/**
|
|
475
|
+
* Check API health status
|
|
476
|
+
*/
|
|
477
|
+
get health(): {
|
|
478
|
+
check: () => Promise<_safercity_sdk_core.ApiResponse<{
|
|
479
|
+
status: string;
|
|
480
|
+
timestamp: string;
|
|
481
|
+
panicProviders?: {
|
|
482
|
+
healthy: boolean;
|
|
483
|
+
stats?: unknown;
|
|
484
|
+
providers?: unknown;
|
|
485
|
+
};
|
|
486
|
+
}>>;
|
|
487
|
+
};
|
|
488
|
+
/**
|
|
489
|
+
* Authentication helpers
|
|
490
|
+
*/
|
|
491
|
+
get auth(): {
|
|
492
|
+
/**
|
|
493
|
+
* Get current authentication context
|
|
494
|
+
*/
|
|
495
|
+
whoami: () => Promise<_safercity_sdk_core.ApiResponse<{
|
|
496
|
+
tenantId: string | null;
|
|
497
|
+
environment: string;
|
|
498
|
+
scopes: string[];
|
|
499
|
+
sessionId: string;
|
|
500
|
+
}>>;
|
|
501
|
+
/**
|
|
502
|
+
* Check if authenticated (optional auth)
|
|
503
|
+
*/
|
|
504
|
+
check: () => Promise<_safercity_sdk_core.ApiResponse<{
|
|
505
|
+
authenticated: boolean;
|
|
506
|
+
tenantId: string | null;
|
|
507
|
+
}>>;
|
|
508
|
+
};
|
|
509
|
+
/**
|
|
510
|
+
* OAuth helpers
|
|
511
|
+
*/
|
|
512
|
+
get oauth(): {
|
|
513
|
+
/**
|
|
514
|
+
* Get access token
|
|
515
|
+
*/
|
|
516
|
+
token: (body: {
|
|
517
|
+
grant_type: "client_credentials" | "refresh_token";
|
|
518
|
+
tenantId?: string;
|
|
519
|
+
userId?: string;
|
|
520
|
+
refresh_token?: string;
|
|
521
|
+
}) => Promise<_safercity_sdk_core.ApiResponse<{
|
|
522
|
+
access_token: string;
|
|
523
|
+
token_type: string;
|
|
524
|
+
expires_in: number;
|
|
525
|
+
refresh_token?: string;
|
|
526
|
+
}>>;
|
|
527
|
+
/**
|
|
528
|
+
* Refresh access token
|
|
529
|
+
*/
|
|
530
|
+
refresh: (body: {
|
|
531
|
+
refresh_token: string;
|
|
532
|
+
}) => Promise<_safercity_sdk_core.ApiResponse<{
|
|
533
|
+
access_token: string;
|
|
534
|
+
token_type: string;
|
|
535
|
+
expires_in: number;
|
|
536
|
+
refresh_token?: string;
|
|
537
|
+
}>>;
|
|
538
|
+
/**
|
|
539
|
+
* Introspect token
|
|
540
|
+
*/
|
|
541
|
+
introspect: (body: {
|
|
542
|
+
token: string;
|
|
543
|
+
}) => Promise<_safercity_sdk_core.ApiResponse<{
|
|
544
|
+
active: boolean;
|
|
545
|
+
tenantId?: string;
|
|
546
|
+
sub?: string;
|
|
547
|
+
scope?: string;
|
|
548
|
+
exp?: number;
|
|
549
|
+
}>>;
|
|
550
|
+
/**
|
|
551
|
+
* Revoke token
|
|
552
|
+
*/
|
|
553
|
+
revoke: (body: {
|
|
554
|
+
token: string;
|
|
555
|
+
}) => Promise<_safercity_sdk_core.ApiResponse<{
|
|
556
|
+
success: boolean;
|
|
557
|
+
}>>;
|
|
558
|
+
};
|
|
559
|
+
/**
|
|
560
|
+
* Tenant helpers
|
|
561
|
+
*/
|
|
562
|
+
get tenants(): {
|
|
563
|
+
/**
|
|
564
|
+
* Create a new tenant
|
|
565
|
+
*/
|
|
566
|
+
create: (body: {
|
|
567
|
+
name: string;
|
|
568
|
+
domain?: string;
|
|
569
|
+
}) => Promise<_safercity_sdk_core.ApiResponse<{
|
|
570
|
+
tenantId: string;
|
|
571
|
+
name: string;
|
|
572
|
+
setupToken: string;
|
|
573
|
+
}>>;
|
|
574
|
+
/**
|
|
575
|
+
* List tenants (admin)
|
|
576
|
+
*/
|
|
577
|
+
list: (query?: {
|
|
578
|
+
limit?: number;
|
|
579
|
+
cursor?: string;
|
|
580
|
+
}) => Promise<_safercity_sdk_core.ApiResponse<{
|
|
581
|
+
tenants: Array<{
|
|
582
|
+
id: string;
|
|
583
|
+
name: string;
|
|
584
|
+
}>;
|
|
585
|
+
hasNext: boolean;
|
|
586
|
+
cursor?: string;
|
|
587
|
+
}>>;
|
|
588
|
+
};
|
|
589
|
+
/**
|
|
590
|
+
* Credential helpers
|
|
591
|
+
*/
|
|
592
|
+
get credentials(): {
|
|
593
|
+
/**
|
|
594
|
+
* Exchange setup token for credentials
|
|
595
|
+
*/
|
|
596
|
+
setup: (body: {
|
|
597
|
+
setupToken: string;
|
|
598
|
+
}) => Promise<_safercity_sdk_core.ApiResponse<{
|
|
599
|
+
clientId: string;
|
|
600
|
+
clientSecret: string;
|
|
601
|
+
tenantId: string;
|
|
602
|
+
}>>;
|
|
603
|
+
/**
|
|
604
|
+
* List credentials
|
|
605
|
+
*/
|
|
606
|
+
list: () => Promise<_safercity_sdk_core.ApiResponse<{
|
|
607
|
+
credentials: Array<{
|
|
608
|
+
id: string;
|
|
609
|
+
clientId: string;
|
|
610
|
+
createdAt: string;
|
|
611
|
+
lastUsed?: string;
|
|
612
|
+
}>;
|
|
613
|
+
}>>;
|
|
614
|
+
/**
|
|
615
|
+
* Revoke credential
|
|
616
|
+
*/
|
|
617
|
+
revoke: (credentialId: string) => Promise<_safercity_sdk_core.ApiResponse<{
|
|
618
|
+
success: boolean;
|
|
619
|
+
}>>;
|
|
620
|
+
};
|
|
621
|
+
/**
|
|
622
|
+
* User helpers
|
|
623
|
+
*/
|
|
624
|
+
get users(): {
|
|
625
|
+
/**
|
|
626
|
+
* Create user
|
|
627
|
+
*/
|
|
628
|
+
create: (body: {
|
|
629
|
+
email?: string;
|
|
630
|
+
phone?: string;
|
|
631
|
+
firstName?: string;
|
|
632
|
+
lastName?: string;
|
|
633
|
+
metadata?: Record<string, unknown>;
|
|
634
|
+
}) => Promise<_safercity_sdk_core.ApiResponse<{
|
|
635
|
+
id: string;
|
|
636
|
+
email?: string;
|
|
637
|
+
phone?: string;
|
|
638
|
+
}>>;
|
|
639
|
+
/**
|
|
640
|
+
* List users
|
|
641
|
+
*/
|
|
642
|
+
list: (query?: {
|
|
643
|
+
limit?: number;
|
|
644
|
+
cursor?: string;
|
|
645
|
+
status?: string;
|
|
646
|
+
}) => Promise<_safercity_sdk_core.ApiResponse<{
|
|
647
|
+
users: Array<{
|
|
648
|
+
id: string;
|
|
649
|
+
email?: string;
|
|
650
|
+
phone?: string;
|
|
651
|
+
status: string;
|
|
652
|
+
}>;
|
|
653
|
+
hasNext: boolean;
|
|
654
|
+
cursor?: string;
|
|
655
|
+
}>>;
|
|
656
|
+
/**
|
|
657
|
+
* Get user by ID
|
|
658
|
+
*/
|
|
659
|
+
get: (userId: string) => Promise<_safercity_sdk_core.ApiResponse<{
|
|
660
|
+
id: string;
|
|
661
|
+
email?: string;
|
|
662
|
+
phone?: string;
|
|
663
|
+
firstName?: string;
|
|
664
|
+
lastName?: string;
|
|
665
|
+
status: string;
|
|
666
|
+
metadata?: Record<string, unknown>;
|
|
667
|
+
}>>;
|
|
668
|
+
/**
|
|
669
|
+
* Update user
|
|
670
|
+
*/
|
|
671
|
+
update: (userId: string, body: {
|
|
672
|
+
email?: string;
|
|
673
|
+
phone?: string;
|
|
674
|
+
firstName?: string;
|
|
675
|
+
lastName?: string;
|
|
676
|
+
metadata?: Record<string, unknown>;
|
|
677
|
+
}) => Promise<_safercity_sdk_core.ApiResponse<{
|
|
678
|
+
id: string;
|
|
679
|
+
}>>;
|
|
680
|
+
/**
|
|
681
|
+
* Update user status
|
|
682
|
+
*/
|
|
683
|
+
updateStatus: (userId: string, body: {
|
|
684
|
+
status: string;
|
|
685
|
+
}) => Promise<_safercity_sdk_core.ApiResponse<{
|
|
686
|
+
id: string;
|
|
687
|
+
status: string;
|
|
688
|
+
}>>;
|
|
689
|
+
/**
|
|
690
|
+
* Delete user
|
|
691
|
+
*/
|
|
692
|
+
delete: (userId: string) => Promise<_safercity_sdk_core.ApiResponse<{
|
|
693
|
+
success: boolean;
|
|
694
|
+
}>>;
|
|
695
|
+
};
|
|
696
|
+
/**
|
|
697
|
+
* Panic helpers (streaming not available in server client)
|
|
698
|
+
*/
|
|
699
|
+
get panics(): {
|
|
700
|
+
/**
|
|
701
|
+
* Create panic
|
|
702
|
+
*/
|
|
703
|
+
create: (body: {
|
|
704
|
+
userId: string;
|
|
705
|
+
panicTypeId?: string;
|
|
706
|
+
latitude: number;
|
|
707
|
+
longitude: number;
|
|
708
|
+
accuracy?: number;
|
|
709
|
+
metadata?: Record<string, unknown>;
|
|
710
|
+
}) => Promise<_safercity_sdk_core.ApiResponse<{
|
|
711
|
+
id: string;
|
|
712
|
+
status: string;
|
|
713
|
+
createdAt: string;
|
|
714
|
+
}>>;
|
|
715
|
+
/**
|
|
716
|
+
* Get panic by ID
|
|
717
|
+
*/
|
|
718
|
+
get: (panicId: string, query?: {
|
|
719
|
+
userId?: string;
|
|
720
|
+
}) => Promise<_safercity_sdk_core.ApiResponse<{
|
|
721
|
+
id: string;
|
|
722
|
+
userId: string;
|
|
723
|
+
status: string;
|
|
724
|
+
latitude: number;
|
|
725
|
+
longitude: number;
|
|
726
|
+
createdAt: string;
|
|
727
|
+
updatedAt?: string;
|
|
728
|
+
}>>;
|
|
729
|
+
/**
|
|
730
|
+
* List panics
|
|
731
|
+
*/
|
|
732
|
+
list: (query?: {
|
|
733
|
+
userId?: string;
|
|
734
|
+
status?: string;
|
|
735
|
+
limit?: number;
|
|
736
|
+
cursor?: string;
|
|
737
|
+
}) => Promise<_safercity_sdk_core.ApiResponse<{
|
|
738
|
+
panics: Array<{
|
|
739
|
+
id: string;
|
|
740
|
+
userId: string;
|
|
741
|
+
status: string;
|
|
742
|
+
createdAt: string;
|
|
743
|
+
}>;
|
|
744
|
+
hasNext: boolean;
|
|
745
|
+
cursor?: string;
|
|
746
|
+
}>>;
|
|
747
|
+
/**
|
|
748
|
+
* Update panic location
|
|
749
|
+
*/
|
|
750
|
+
updateLocation: (panicId: string, body: {
|
|
751
|
+
userId: string;
|
|
752
|
+
latitude: number;
|
|
753
|
+
longitude: number;
|
|
754
|
+
accuracy?: number;
|
|
755
|
+
}) => Promise<_safercity_sdk_core.ApiResponse<{
|
|
756
|
+
id: string;
|
|
757
|
+
latitude: number;
|
|
758
|
+
longitude: number;
|
|
759
|
+
}>>;
|
|
760
|
+
/**
|
|
761
|
+
* Cancel panic
|
|
762
|
+
*/
|
|
763
|
+
cancel: (panicId: string, body: {
|
|
764
|
+
userId: string;
|
|
765
|
+
reason?: string;
|
|
766
|
+
}) => Promise<_safercity_sdk_core.ApiResponse<{
|
|
767
|
+
id: string;
|
|
768
|
+
status: string;
|
|
769
|
+
cancelledAt: string;
|
|
770
|
+
}>>;
|
|
771
|
+
};
|
|
772
|
+
/**
|
|
773
|
+
* Subscription helpers
|
|
774
|
+
*/
|
|
775
|
+
get subscriptions(): {
|
|
776
|
+
/**
|
|
777
|
+
* List subscription types
|
|
778
|
+
*/
|
|
779
|
+
listTypes: () => Promise<_safercity_sdk_core.ApiResponse<{
|
|
780
|
+
types: Array<{
|
|
781
|
+
id: string;
|
|
782
|
+
name: string;
|
|
783
|
+
description?: string;
|
|
784
|
+
price?: number;
|
|
785
|
+
}>;
|
|
786
|
+
}>>;
|
|
787
|
+
/**
|
|
788
|
+
* Create subscription
|
|
789
|
+
*/
|
|
790
|
+
create: (body: {
|
|
791
|
+
userId: string;
|
|
792
|
+
subscriptionTypeId: string;
|
|
793
|
+
status?: string;
|
|
794
|
+
}) => Promise<_safercity_sdk_core.ApiResponse<{
|
|
795
|
+
id: string;
|
|
796
|
+
userId: string;
|
|
797
|
+
subscriptionTypeId: string;
|
|
798
|
+
status: string;
|
|
799
|
+
}>>;
|
|
800
|
+
/**
|
|
801
|
+
* List subscriptions
|
|
802
|
+
*/
|
|
803
|
+
list: (query?: {
|
|
804
|
+
userId?: string;
|
|
805
|
+
status?: string;
|
|
806
|
+
limit?: number;
|
|
807
|
+
}) => Promise<_safercity_sdk_core.ApiResponse<{
|
|
808
|
+
subscriptions: Array<{
|
|
809
|
+
id: string;
|
|
810
|
+
userId: string;
|
|
811
|
+
subscriptionTypeId: string;
|
|
812
|
+
status: string;
|
|
813
|
+
}>;
|
|
814
|
+
}>>;
|
|
815
|
+
/**
|
|
816
|
+
* Get subscription stats
|
|
817
|
+
*/
|
|
818
|
+
stats: () => Promise<_safercity_sdk_core.ApiResponse<{
|
|
819
|
+
total: number;
|
|
820
|
+
active: number;
|
|
821
|
+
byType: Record<string, number>;
|
|
822
|
+
}>>;
|
|
823
|
+
};
|
|
824
|
+
/**
|
|
825
|
+
* Notification helpers
|
|
826
|
+
*/
|
|
827
|
+
get notifications(): {
|
|
828
|
+
/**
|
|
829
|
+
* Create subscriber
|
|
830
|
+
*/
|
|
831
|
+
createSubscriber: (body: {
|
|
832
|
+
userId: string;
|
|
833
|
+
email?: string;
|
|
834
|
+
phone?: string;
|
|
835
|
+
data?: Record<string, unknown>;
|
|
836
|
+
}) => Promise<_safercity_sdk_core.ApiResponse<{
|
|
837
|
+
subscriberId: string;
|
|
838
|
+
}>>;
|
|
839
|
+
/**
|
|
840
|
+
* Trigger notification
|
|
841
|
+
*/
|
|
842
|
+
trigger: (body: {
|
|
843
|
+
userId: string;
|
|
844
|
+
workflowId: string;
|
|
845
|
+
payload?: Record<string, unknown>;
|
|
846
|
+
}) => Promise<_safercity_sdk_core.ApiResponse<{
|
|
847
|
+
transactionId: string;
|
|
848
|
+
status: string;
|
|
849
|
+
}>>;
|
|
850
|
+
/**
|
|
851
|
+
* Get user preferences
|
|
852
|
+
*/
|
|
853
|
+
getPreferences: (userId: string) => Promise<_safercity_sdk_core.ApiResponse<{
|
|
854
|
+
preferences: Record<string, unknown>;
|
|
855
|
+
}>>;
|
|
856
|
+
/**
|
|
857
|
+
* Update user preferences
|
|
858
|
+
*/
|
|
859
|
+
updatePreferences: (userId: string, body: {
|
|
860
|
+
preferences: Record<string, unknown>;
|
|
861
|
+
}) => Promise<_safercity_sdk_core.ApiResponse<{
|
|
862
|
+
success: boolean;
|
|
863
|
+
}>>;
|
|
864
|
+
};
|
|
865
|
+
/**
|
|
866
|
+
* Location safety helpers
|
|
867
|
+
*/
|
|
868
|
+
get locationSafety(): {
|
|
869
|
+
/**
|
|
870
|
+
* Check location safety
|
|
871
|
+
*/
|
|
872
|
+
check: (query: {
|
|
873
|
+
latitude: number;
|
|
874
|
+
longitude: number;
|
|
875
|
+
radius?: number;
|
|
876
|
+
}) => Promise<_safercity_sdk_core.ApiResponse<{
|
|
877
|
+
safetyScore: number;
|
|
878
|
+
riskLevel: string;
|
|
879
|
+
factors: Array<{
|
|
880
|
+
type: string;
|
|
881
|
+
impact: number;
|
|
882
|
+
}>;
|
|
883
|
+
}>>;
|
|
884
|
+
};
|
|
885
|
+
/**
|
|
886
|
+
* Crime helpers
|
|
887
|
+
*/
|
|
888
|
+
get crimes(): {
|
|
889
|
+
/**
|
|
890
|
+
* List crimes
|
|
891
|
+
*/
|
|
892
|
+
list: (query?: {
|
|
893
|
+
latitude?: number;
|
|
894
|
+
longitude?: number;
|
|
895
|
+
radius?: number;
|
|
896
|
+
type?: string;
|
|
897
|
+
from?: string;
|
|
898
|
+
to?: string;
|
|
899
|
+
limit?: number;
|
|
900
|
+
}) => Promise<_safercity_sdk_core.ApiResponse<{
|
|
901
|
+
crimes: Array<{
|
|
902
|
+
id: string;
|
|
903
|
+
type: string;
|
|
904
|
+
latitude: number;
|
|
905
|
+
longitude: number;
|
|
906
|
+
occurredAt: string;
|
|
907
|
+
}>;
|
|
908
|
+
}>>;
|
|
909
|
+
/**
|
|
910
|
+
* Get crime categories
|
|
911
|
+
*/
|
|
912
|
+
categories: () => Promise<_safercity_sdk_core.ApiResponse<{
|
|
913
|
+
categories: Array<{
|
|
914
|
+
id: string;
|
|
915
|
+
name: string;
|
|
916
|
+
}>;
|
|
917
|
+
}>>;
|
|
918
|
+
/**
|
|
919
|
+
* Get crime types
|
|
920
|
+
*/
|
|
921
|
+
types: () => Promise<_safercity_sdk_core.ApiResponse<{
|
|
922
|
+
types: Array<{
|
|
923
|
+
id: string;
|
|
924
|
+
name: string;
|
|
925
|
+
categoryId: string;
|
|
926
|
+
}>;
|
|
927
|
+
}>>;
|
|
928
|
+
};
|
|
521
929
|
}
|
|
522
930
|
/**
|
|
523
931
|
* Create a server-side SaferCity client with automatic OAuth token management
|