@urnetwork/sdk-js 0.0.1-beta.1 → 0.0.1-beta.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 CHANGED
@@ -7,8 +7,7 @@ npm install @urnetwork/sdk-js
7
7
 
8
8
  ## Deployment
9
9
  - In sdk/build, run `make build_js`. This will generate all the types we need and build sdk/sdk-js/dist.
10
- - Make sure everything is committed and pushed to the main branch.
10
+ - Make sure the new version in package.json is bumped and everything is committed and pushed to the main branch.
11
11
  - If you're not already, login to npm with `npm login`.
12
12
  - Run `npm pack --dry-run` to see what will be included in the package.
13
- - If everything looks good, run `npm run release:patch` to publish the package. There are also `release:beta`, `release:minor`, and `release:major` scripts available for versioning.
14
- - Tag it on Github after publishing like `git tag vx.y.z` and `git push --tags`.
13
+ - If everything looks good, run `npm publish`.
@@ -0,0 +1,2 @@
1
+ export declare const tokenRequiredError = "Admin JWT is required for verification";
2
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,2CAA2C,CAAC"}
@@ -0,0 +1,7 @@
1
+ export * from "./useProviderList";
2
+ export * from "./useRemoveNetworkClient";
3
+ export * from "./useAuthNetworkClient";
4
+ export * from "./useAuthCodeLogin";
5
+ export * from "./useCheckNetwork";
6
+ export * from "./useVerifyUserAuth";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { AuthCodeLoginResult } from "../../generated";
2
+ export declare function useAuthCodeLogin(): {
3
+ loading: boolean;
4
+ error: Error | null;
5
+ authCodeLogin: (authCode: string) => Promise<AuthCodeLoginResult>;
6
+ };
7
+ //# sourceMappingURL=useAuthCodeLogin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAuthCodeLogin.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useAuthCodeLogin.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD,wBAAgB,gBAAgB;;;8BAMX,MAAM,KAAG,OAAO,CAAC,mBAAmB,CAAC;EA+BzD"}
@@ -0,0 +1,7 @@
1
+ import { AuthNetworkClientArgs, AuthNetworkClientResult } from "../../generated";
2
+ export declare function useAuthNetworkClient(): {
3
+ loading: boolean;
4
+ error: Error | null;
5
+ authNetworkClient: (params: AuthNetworkClientArgs) => Promise<AuthNetworkClientResult>;
6
+ };
7
+ //# sourceMappingURL=useAuthNetworkClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAuthNetworkClient.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useAuthNetworkClient.tsx"],"names":[],"mappings":"AAEA,OAAO,EACL,qBAAqB,EACrB,uBAAuB,EACxB,MAAM,iBAAiB,CAAC;AAGzB,wBAAgB,oBAAoB;;;gCAQjB,qBAAqB,KAAG,OAAO,CAAC,uBAAuB,CAAC;EAyF1E"}
@@ -0,0 +1,13 @@
1
+ import { NetworkCheckResult } from "../../generated";
2
+ export declare function useCheckNetwork(options?: {
3
+ debounceMs?: number;
4
+ minLength?: number;
5
+ }): {
6
+ checkNetwork: (params: {
7
+ network_name: string;
8
+ }) => void;
9
+ loading: boolean;
10
+ error: Error | null;
11
+ result: NetworkCheckResult | null;
12
+ };
13
+ //# sourceMappingURL=useCheckNetwork.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useCheckNetwork.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useCheckNetwork.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAKrD,wBAAgB,eAAe,CAAC,OAAO,CAAC,EAAE;IACxC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;2BA2CY;QAAE,YAAY,EAAE,MAAM,CAAA;KAAE;;;;EAiCpC"}
@@ -0,0 +1,9 @@
1
+ import { FilteredLocations } from "../../generated";
2
+ export declare function useProviderList(): {
3
+ loading: boolean;
4
+ error: Error | null;
5
+ filteredLocations: FilteredLocations;
6
+ query: string;
7
+ setQuery: import("react").Dispatch<import("react").SetStateAction<string>>;
8
+ };
9
+ //# sourceMappingURL=useProviderList.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useProviderList.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useProviderList.tsx"],"names":[],"mappings":"AAEA,OAAO,EAEL,iBAAiB,EAGlB,MAAM,iBAAiB,CAAC;AAWzB,wBAAgB,eAAe;;;;;;EA4M9B"}
@@ -0,0 +1,6 @@
1
+ export declare function useRemoveNetworkClient(): {
2
+ loading: boolean;
3
+ error: Error | null;
4
+ removeNetworkClient: (clientId: string) => Promise<import("../../generated").RemoveNetworkClientResult>;
5
+ };
6
+ //# sourceMappingURL=useRemoveNetworkClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRemoveNetworkClient.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useRemoveNetworkClient.tsx"],"names":[],"mappings":"AAIA,wBAAgB,sBAAsB;;;oCAOjB,MAAM;EA4C1B"}
@@ -0,0 +1,7 @@
1
+ import { AuthVerifyResult } from "../../generated";
2
+ export declare function useVerifyUserAuth(): {
3
+ verifyUserAuth: (userAuth: string, code: string) => Promise<AuthVerifyResult>;
4
+ loading: boolean;
5
+ error: Error | null;
6
+ };
7
+ //# sourceMappingURL=useVerifyUserAuth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useVerifyUserAuth.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useVerifyUserAuth.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAMnD,wBAAgB,iBAAiB;+BAOZ,MAAM,QAAQ,MAAM,KAAG,OAAO,CAAC,gBAAgB,CAAC;;;EA0CpE"}
@@ -640,249 +640,6 @@ function useAuth() {
640
640
  return context;
641
641
  }
642
642
 
643
- const tokenRequiredError = "Admin JWT is required for verification";
644
- function useURNetwork(options) {
645
- const [sdk, setSdk] = React.useState(null);
646
- const [loading, setLoading] = React.useState(true);
647
- const [error, setError] = React.useState(null);
648
- React.useEffect(() => {
649
- let mounted = true;
650
- const initSdk = async () => {
651
- try {
652
- const instance = await URNetwork.init(options);
653
- if (mounted) {
654
- setSdk(instance);
655
- setLoading(false);
656
- }
657
- }
658
- catch (err) {
659
- if (mounted) {
660
- setError(err);
661
- setLoading(false);
662
- }
663
- }
664
- };
665
- initSdk();
666
- return () => {
667
- mounted = false;
668
- };
669
- }, []);
670
- return { sdk, loading, error };
671
- }
672
- function useCheckNetwork(options) {
673
- const api = useAPI();
674
- const [loading, setLoading] = React.useState(false);
675
- const [error, setError] = React.useState(null);
676
- const [result, setResult] = React.useState(null);
677
- const debounceMs = options?.debounceMs ?? 300;
678
- const minLength = options?.minLength ?? 6;
679
- const timeoutRef = React.useRef(null);
680
- const checkNetwork = React.useCallback(async (params) => {
681
- if (params.network_name.length < minLength) {
682
- setResult(null);
683
- setError(null);
684
- setLoading(false);
685
- return null;
686
- }
687
- setLoading(true);
688
- setError(null);
689
- try {
690
- const result = await api.networkCheck(params);
691
- if (!result) {
692
- const err = new Error("Network check failed");
693
- setError(err);
694
- setResult(null);
695
- return null;
696
- }
697
- setResult(result);
698
- return result;
699
- }
700
- catch (err) {
701
- setError(err);
702
- throw err;
703
- }
704
- finally {
705
- setLoading(false);
706
- }
707
- }, [api, minLength]);
708
- const debouncedCheckNetwork = React.useCallback((params) => {
709
- if (timeoutRef.current) {
710
- clearTimeout(timeoutRef.current);
711
- }
712
- if (params.network_name.length < minLength) {
713
- setResult(null);
714
- setError(null);
715
- setLoading(false);
716
- return;
717
- }
718
- timeoutRef.current = setTimeout(() => {
719
- checkNetwork(params);
720
- }, debounceMs);
721
- }, [checkNetwork, debounceMs, minLength]);
722
- React.useEffect(() => {
723
- return () => {
724
- if (timeoutRef.current) {
725
- clearTimeout(timeoutRef.current);
726
- }
727
- };
728
- }, []);
729
- return {
730
- checkNetwork: debouncedCheckNetwork,
731
- loading,
732
- error,
733
- result,
734
- };
735
- }
736
- function useVerifyUserAuth() {
737
- const api = useAPI();
738
- const { token } = useAuth();
739
- const [loading, setLoading] = React.useState(false);
740
- const [error, setError] = React.useState(null);
741
- const verifyUserAuth = React.useCallback(async (userAuth, code) => {
742
- if (!token) {
743
- const err = new Error(tokenRequiredError);
744
- setError(err);
745
- return {
746
- error: {
747
- message: err.message,
748
- },
749
- };
750
- }
751
- setLoading(true);
752
- setError(null);
753
- try {
754
- const result = await api.verifyUserAuth({
755
- user_auth: userAuth,
756
- verify_code: code,
757
- }, token);
758
- return result;
759
- }
760
- catch (err) {
761
- setError(err);
762
- return {
763
- error: {
764
- message: err instanceof Error ? err.message : "Verification failed",
765
- },
766
- };
767
- }
768
- finally {
769
- setLoading(false);
770
- }
771
- }, [api]);
772
- return {
773
- verifyUserAuth,
774
- loading,
775
- error,
776
- };
777
- }
778
- function useAuthCodeLogin() {
779
- const api = useAPI();
780
- const [loading, setLoading] = React.useState(false);
781
- const [error, setError] = React.useState(null);
782
- const authCodeLogin = React.useCallback(async (authCode) => {
783
- setLoading(true);
784
- setError(null);
785
- try {
786
- const result = await api.authCodeLogin({
787
- auth_code: authCode,
788
- });
789
- if (result.error) {
790
- const err = new Error(result.error.message);
791
- setError(err);
792
- }
793
- return result;
794
- }
795
- catch (err) {
796
- setError(err);
797
- return {
798
- by_jwt: "",
799
- error: {
800
- message: err instanceof Error ? err.message : "Auth code login failed",
801
- },
802
- };
803
- }
804
- finally {
805
- setLoading(false);
806
- }
807
- }, [api]);
808
- return { loading, error, authCodeLogin };
809
- }
810
- function useAuthNetworkClient() {
811
- const api = useAPI();
812
- const { token } = useAuth();
813
- const [loading, setLoading] = React.useState(false);
814
- const [error, setError] = React.useState(null);
815
- const abortControllerRef = React.useRef(null);
816
- const authNetworkClient = React.useCallback(async (params) => {
817
- if (abortControllerRef.current) {
818
- abortControllerRef.current.abort();
819
- }
820
- const abortController = new AbortController();
821
- abortControllerRef.current = abortController;
822
- if (!token) {
823
- const err = new Error(tokenRequiredError);
824
- setError(err);
825
- return {
826
- proxy_config_result: null,
827
- error: {
828
- message: err.message,
829
- client_limit_exceeded: false,
830
- },
831
- };
832
- }
833
- setLoading(true);
834
- setError(null);
835
- try {
836
- const result = await api.authNetworkClient(params, token, abortController.signal);
837
- if (abortController.signal.aborted) {
838
- return {
839
- proxy_config_result: null,
840
- error: {
841
- message: "Request was cancelled",
842
- client_limit_exceeded: false,
843
- },
844
- };
845
- }
846
- return result;
847
- }
848
- catch (err) {
849
- if (err instanceof Error && err.name === "AbortError") {
850
- return {
851
- proxy_config_result: null,
852
- error: {
853
- message: "Request was cancelled",
854
- client_limit_exceeded: false,
855
- },
856
- };
857
- }
858
- setError(err);
859
- return {
860
- proxy_config_result: null,
861
- error: {
862
- message: err instanceof Error ? err.message : "Auth code login failed",
863
- client_limit_exceeded: false,
864
- },
865
- };
866
- }
867
- finally {
868
- if (!abortController.signal.aborted) {
869
- setLoading(false);
870
- }
871
- }
872
- }, [api, token]);
873
- React.useEffect(() => {
874
- return () => {
875
- if (abortControllerRef.current) {
876
- abortControllerRef.current.abort();
877
- }
878
- };
879
- }, []);
880
- return {
881
- loading,
882
- error,
883
- authNetworkClient,
884
- };
885
- }
886
643
  const initialFilteredLocations = {
887
644
  best_matches: [],
888
645
  promoted: [],
@@ -893,7 +650,7 @@ const initialFilteredLocations = {
893
650
  };
894
651
  function useProviderList() {
895
652
  const api = useAPI();
896
- const [loading, setLoading] = React.useState(false);
653
+ const [loading, setLoading] = React.useState(true);
897
654
  const [error, setError] = React.useState(null);
898
655
  const [filteredLocations, setFilteredLocations] = React.useState(initialFilteredLocations);
899
656
  const [query, setQuery] = React.useState("");
@@ -1056,6 +813,9 @@ function useProviderList() {
1056
813
  setQuery,
1057
814
  };
1058
815
  }
816
+
817
+ const tokenRequiredError = "Admin JWT is required for verification";
818
+
1059
819
  function useRemoveNetworkClient() {
1060
820
  const api = useAPI();
1061
821
  const [loading, setLoading] = React.useState(false);
@@ -1100,6 +860,224 @@ function useRemoveNetworkClient() {
1100
860
  };
1101
861
  }
1102
862
 
863
+ function useAuthNetworkClient() {
864
+ const api = useAPI();
865
+ const { token } = useAuth();
866
+ const [loading, setLoading] = React.useState(false);
867
+ const [error, setError] = React.useState(null);
868
+ const abortControllerRef = React.useRef(null);
869
+ const authNetworkClient = React.useCallback(async (params) => {
870
+ if (abortControllerRef.current) {
871
+ abortControllerRef.current.abort();
872
+ }
873
+ const abortController = new AbortController();
874
+ abortControllerRef.current = abortController;
875
+ if (!token) {
876
+ const err = new Error(tokenRequiredError);
877
+ setError(err);
878
+ return {
879
+ proxy_config_result: null,
880
+ error: {
881
+ message: err.message,
882
+ client_limit_exceeded: false,
883
+ },
884
+ };
885
+ }
886
+ setLoading(true);
887
+ setError(null);
888
+ try {
889
+ const result = await api.authNetworkClient(params, token, abortController.signal);
890
+ if (abortController.signal.aborted) {
891
+ return {
892
+ proxy_config_result: null,
893
+ error: {
894
+ message: "Request was cancelled",
895
+ client_limit_exceeded: false,
896
+ },
897
+ };
898
+ }
899
+ return result;
900
+ }
901
+ catch (err) {
902
+ if (err instanceof Error && err.name === "AbortError") {
903
+ return {
904
+ proxy_config_result: null,
905
+ error: {
906
+ message: "Request was cancelled",
907
+ client_limit_exceeded: false,
908
+ },
909
+ };
910
+ }
911
+ setError(err);
912
+ return {
913
+ proxy_config_result: null,
914
+ error: {
915
+ message: err instanceof Error ? err.message : "Auth code login failed",
916
+ client_limit_exceeded: false,
917
+ },
918
+ };
919
+ }
920
+ finally {
921
+ if (!abortController.signal.aborted) {
922
+ setLoading(false);
923
+ }
924
+ }
925
+ }, [api, token]);
926
+ React.useEffect(() => {
927
+ return () => {
928
+ if (abortControllerRef.current) {
929
+ abortControllerRef.current.abort();
930
+ }
931
+ };
932
+ }, []);
933
+ return {
934
+ loading,
935
+ error,
936
+ authNetworkClient,
937
+ };
938
+ }
939
+
940
+ function useAuthCodeLogin() {
941
+ const api = useAPI();
942
+ const [loading, setLoading] = React.useState(false);
943
+ const [error, setError] = React.useState(null);
944
+ const authCodeLogin = React.useCallback(async (authCode) => {
945
+ setLoading(true);
946
+ setError(null);
947
+ try {
948
+ const result = await api.authCodeLogin({
949
+ auth_code: authCode,
950
+ });
951
+ if (result.error) {
952
+ const err = new Error(result.error.message);
953
+ setError(err);
954
+ }
955
+ return result;
956
+ }
957
+ catch (err) {
958
+ setError(err);
959
+ return {
960
+ by_jwt: "",
961
+ error: {
962
+ message: err instanceof Error ? err.message : "Auth code login failed",
963
+ },
964
+ };
965
+ }
966
+ finally {
967
+ setLoading(false);
968
+ }
969
+ }, [api]);
970
+ return { loading, error, authCodeLogin };
971
+ }
972
+
973
+ function useCheckNetwork(options) {
974
+ const api = useAPI();
975
+ const [loading, setLoading] = React.useState(false);
976
+ const [error, setError] = React.useState(null);
977
+ const [result, setResult] = React.useState(null);
978
+ const debounceMs = options?.debounceMs ?? 300;
979
+ const minLength = options?.minLength ?? 6;
980
+ const timeoutRef = React.useRef(null);
981
+ const checkNetwork = React.useCallback(async (params) => {
982
+ if (params.network_name.length < minLength) {
983
+ setResult(null);
984
+ setError(null);
985
+ setLoading(false);
986
+ return null;
987
+ }
988
+ setLoading(true);
989
+ setError(null);
990
+ try {
991
+ const result = await api.networkCheck(params);
992
+ if (!result) {
993
+ const err = new Error("Network check failed");
994
+ setError(err);
995
+ setResult(null);
996
+ return null;
997
+ }
998
+ setResult(result);
999
+ return result;
1000
+ }
1001
+ catch (err) {
1002
+ setError(err);
1003
+ throw err;
1004
+ }
1005
+ finally {
1006
+ setLoading(false);
1007
+ }
1008
+ }, [api, minLength]);
1009
+ const debouncedCheckNetwork = React.useCallback((params) => {
1010
+ if (timeoutRef.current) {
1011
+ clearTimeout(timeoutRef.current);
1012
+ }
1013
+ if (params.network_name.length < minLength) {
1014
+ setResult(null);
1015
+ setError(null);
1016
+ setLoading(false);
1017
+ return;
1018
+ }
1019
+ timeoutRef.current = setTimeout(() => {
1020
+ checkNetwork(params);
1021
+ }, debounceMs);
1022
+ }, [checkNetwork, debounceMs, minLength]);
1023
+ React.useEffect(() => {
1024
+ return () => {
1025
+ if (timeoutRef.current) {
1026
+ clearTimeout(timeoutRef.current);
1027
+ }
1028
+ };
1029
+ }, []);
1030
+ return {
1031
+ checkNetwork: debouncedCheckNetwork,
1032
+ loading,
1033
+ error,
1034
+ result,
1035
+ };
1036
+ }
1037
+
1038
+ function useVerifyUserAuth() {
1039
+ const api = useAPI();
1040
+ const { token } = useAuth();
1041
+ const [loading, setLoading] = React.useState(false);
1042
+ const [error, setError] = React.useState(null);
1043
+ const verifyUserAuth = React.useCallback(async (userAuth, code) => {
1044
+ if (!token) {
1045
+ const err = new Error(tokenRequiredError);
1046
+ setError(err);
1047
+ return {
1048
+ error: {
1049
+ message: err.message,
1050
+ },
1051
+ };
1052
+ }
1053
+ setLoading(true);
1054
+ setError(null);
1055
+ try {
1056
+ const result = await api.verifyUserAuth({
1057
+ user_auth: userAuth,
1058
+ verify_code: code,
1059
+ }, token);
1060
+ return result;
1061
+ }
1062
+ catch (err) {
1063
+ setError(err);
1064
+ return {
1065
+ error: {
1066
+ message: err instanceof Error ? err.message : "Verification failed",
1067
+ },
1068
+ };
1069
+ }
1070
+ finally {
1071
+ setLoading(false);
1072
+ }
1073
+ }, [api]);
1074
+ return {
1075
+ verifyUserAuth,
1076
+ loading,
1077
+ error,
1078
+ };
1079
+ }
1080
+
1103
1081
  exports.AuthProvider = AuthProvider;
1104
1082
  exports.URNetwork = URNetwork;
1105
1083
  exports.URNetworkAPI = URNetworkAPI;
@@ -1113,6 +1091,5 @@ exports.useAuthNetworkClient = useAuthNetworkClient;
1113
1091
  exports.useCheckNetwork = useCheckNetwork;
1114
1092
  exports.useProviderList = useProviderList;
1115
1093
  exports.useRemoveNetworkClient = useRemoveNetworkClient;
1116
- exports.useURNetwork = useURNetwork;
1117
1094
  exports.useVerifyUserAuth = useVerifyUserAuth;
1118
1095
  //# sourceMappingURL=index.cjs.map