@fctc/interface-logic 1.8.9 → 1.8.10

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/dist/hooks.js CHANGED
@@ -4776,6 +4776,231 @@ var import_jsx_runtime4 = require("react/jsx-runtime");
4776
4776
  var import_react4 = require("react");
4777
4777
  var import_jsx_runtime5 = require("react/jsx-runtime");
4778
4778
  var EnvContext = (0, import_react4.createContext)(null);
4779
+ function useEnv() {
4780
+ const context = (0, import_react4.useContext)(EnvContext);
4781
+ if (!context) {
4782
+ throw new Error("useEnv must be used within an EnvProvider");
4783
+ }
4784
+ return context;
4785
+ }
4786
+
4787
+ // src/services/auth-service/backup.ts
4788
+ function useAuthService() {
4789
+ const { env: env2 } = useEnv();
4790
+ const login = (0, import_react5.useCallback)(
4791
+ async (body) => {
4792
+ const payload = Object.fromEntries(
4793
+ Object.entries({
4794
+ username: body.email,
4795
+ password: body.password,
4796
+ grant_type: env2?.config?.grantType || "",
4797
+ client_id: env2?.config?.clientId || "",
4798
+ client_secret: env2?.config?.clientSecret || ""
4799
+ }).filter(([_, value]) => !!value)
4800
+ );
4801
+ const encodedData = new URLSearchParams(payload).toString();
4802
+ return env2?.requests?.post(body.path, encodedData, {
4803
+ headers: {
4804
+ "Content-Type": "application/x-www-form-urlencoded"
4805
+ }
4806
+ });
4807
+ },
4808
+ [env2]
4809
+ );
4810
+ const forgotPassword = (0, import_react5.useCallback)(
4811
+ async (email) => {
4812
+ const bodyData = {
4813
+ login: email,
4814
+ url: `${window.location.origin}/reset-password`
4815
+ };
4816
+ return env2?.requests?.post("/reset_password" /* RESET_PASSWORD_PATH */, bodyData, {
4817
+ headers: {
4818
+ "Content-Type": "application/json"
4819
+ }
4820
+ });
4821
+ },
4822
+ [env2]
4823
+ );
4824
+ const forgotPasswordSSO = (0, import_react5.useCallback)(
4825
+ async ({
4826
+ email,
4827
+ with_context,
4828
+ method
4829
+ }) => {
4830
+ const body = {
4831
+ method,
4832
+ kwargs: {
4833
+ vals: {
4834
+ email
4835
+ }
4836
+ },
4837
+ with_context
4838
+ };
4839
+ return env2?.requests?.post("/call" /* CALL_PATH */, body, {
4840
+ headers: {
4841
+ "Content-Type": "application/json"
4842
+ }
4843
+ });
4844
+ },
4845
+ [env2]
4846
+ );
4847
+ const resetPassword = (0, import_react5.useCallback)(
4848
+ async (data, token) => {
4849
+ const bodyData = {
4850
+ token,
4851
+ password: data.password,
4852
+ new_password: data.confirmPassword
4853
+ };
4854
+ return env2?.requests?.post("/change_password" /* CHANGE_PASSWORD_PATH */, bodyData, {
4855
+ headers: {
4856
+ "Content-Type": "application/json"
4857
+ }
4858
+ });
4859
+ },
4860
+ [env2]
4861
+ );
4862
+ const resetPasswordSSO = (0, import_react5.useCallback)(
4863
+ async ({
4864
+ method,
4865
+ password,
4866
+ with_context
4867
+ }) => {
4868
+ const bodyData = {
4869
+ method,
4870
+ kwargs: {
4871
+ vals: {
4872
+ password
4873
+ }
4874
+ },
4875
+ with_context
4876
+ };
4877
+ return env2?.requests?.post("/call" /* CALL_PATH */, bodyData, {
4878
+ headers: {
4879
+ "Content-Type": "application/json"
4880
+ }
4881
+ });
4882
+ },
4883
+ [env2]
4884
+ );
4885
+ const updatePassword = (0, import_react5.useCallback)(
4886
+ async (data, token) => {
4887
+ const bodyData = {
4888
+ token,
4889
+ old_password: data.oldPassword,
4890
+ new_password: data.newPassword
4891
+ };
4892
+ return env2?.requests?.post("/change_password_parent" /* UPDATE_PASSWORD_PATH */, bodyData, {
4893
+ headers: {
4894
+ "Content-Type": "application/json"
4895
+ }
4896
+ });
4897
+ },
4898
+ [env2]
4899
+ );
4900
+ const isValidToken = (0, import_react5.useCallback)(
4901
+ async (token) => {
4902
+ const bodyData = {
4903
+ token
4904
+ };
4905
+ return env2?.requests?.post("/check_token" /* TOKEN */, bodyData, {
4906
+ headers: {
4907
+ "Content-Type": "application/json"
4908
+ }
4909
+ });
4910
+ },
4911
+ [env2]
4912
+ );
4913
+ const isValidActionToken = (0, import_react5.useCallback)(
4914
+ async (actionToken, path) => {
4915
+ return env2?.requests?.post(
4916
+ path,
4917
+ {},
4918
+ {
4919
+ headers: {
4920
+ "Content-Type": "application/json"
4921
+ },
4922
+ useActionToken: true,
4923
+ actionToken
4924
+ }
4925
+ );
4926
+ },
4927
+ [env2]
4928
+ );
4929
+ const loginSocial = (0, import_react5.useCallback)(
4930
+ async ({
4931
+ db,
4932
+ state,
4933
+ access_token
4934
+ }) => {
4935
+ return env2?.requests?.post(
4936
+ "/token/generate" /* GENTOKEN_SOCIAL */,
4937
+ { state, access_token },
4938
+ {
4939
+ headers: {
4940
+ "Content-Type": "application/json"
4941
+ }
4942
+ }
4943
+ );
4944
+ },
4945
+ [env2]
4946
+ );
4947
+ const getProviders = (0, import_react5.useCallback)(
4948
+ async (db) => {
4949
+ return env2?.requests?.get("/oauth/providers", { params: { db } });
4950
+ },
4951
+ [env2]
4952
+ );
4953
+ const getAccessByCode = (0, import_react5.useCallback)(
4954
+ async (code) => {
4955
+ const data = new URLSearchParams();
4956
+ data.append("code", code);
4957
+ data.append("grant_type", "authorization_code");
4958
+ data.append("client_id", env2?.config?.clientId || "");
4959
+ data.append("redirect_uri", env2?.config?.redirectUri || "");
4960
+ return env2?.requests?.post(
4961
+ `${env2?.baseUrl?.replace("/mms/", "/id/")}/${"/token" /* TOKEN_BY_CODE */}`,
4962
+ data,
4963
+ {
4964
+ headers: {
4965
+ "Content-Type": "application/x-www-form-urlencoded"
4966
+ }
4967
+ }
4968
+ );
4969
+ },
4970
+ [env2]
4971
+ );
4972
+ const logout = (0, import_react5.useCallback)(
4973
+ async (data) => {
4974
+ console.log(data);
4975
+ return env2?.requests?.post(
4976
+ "/logout" /* LOGOUT */,
4977
+ {},
4978
+ {
4979
+ headers: {
4980
+ "Content-Type": "application/json"
4981
+ },
4982
+ withCredentials: true,
4983
+ useRefreshToken: true
4984
+ }
4985
+ );
4986
+ },
4987
+ [env2]
4988
+ );
4989
+ return {
4990
+ login,
4991
+ forgotPassword,
4992
+ forgotPasswordSSO,
4993
+ resetPassword,
4994
+ resetPasswordSSO,
4995
+ updatePassword,
4996
+ isValidToken,
4997
+ isValidActionToken,
4998
+ loginSocial,
4999
+ getProviders,
5000
+ getAccessByCode,
5001
+ logout
5002
+ };
5003
+ }
4779
5004
 
4780
5005
  // src/hooks/auth/use-forgot-password.ts
4781
5006
  var useForgotPassword = () => {
@@ -4827,9 +5052,10 @@ var use_isvalid_token_default = useIsValidToken;
4827
5052
  // src/hooks/auth/use-login-credential.ts
4828
5053
  var import_react_query7 = require("@tanstack/react-query");
4829
5054
  var useLoginCredential = () => {
5055
+ const { login } = useAuthService();
4830
5056
  return (0, import_react_query7.useMutation)({
4831
5057
  mutationFn: (data) => {
4832
- return auth_service_default.login(data);
5058
+ return login(data);
4833
5059
  }
4834
5060
  });
4835
5061
  };
package/dist/hooks.mjs CHANGED
@@ -4672,6 +4672,231 @@ import { Fragment, jsx as jsx4 } from "react/jsx-runtime";
4672
4672
  import { createContext, useContext, useState as useState3, useCallback as useCallback2 } from "react";
4673
4673
  import { jsx as jsx5 } from "react/jsx-runtime";
4674
4674
  var EnvContext = createContext(null);
4675
+ function useEnv() {
4676
+ const context = useContext(EnvContext);
4677
+ if (!context) {
4678
+ throw new Error("useEnv must be used within an EnvProvider");
4679
+ }
4680
+ return context;
4681
+ }
4682
+
4683
+ // src/services/auth-service/backup.ts
4684
+ function useAuthService() {
4685
+ const { env: env2 } = useEnv();
4686
+ const login = useCallback3(
4687
+ async (body) => {
4688
+ const payload = Object.fromEntries(
4689
+ Object.entries({
4690
+ username: body.email,
4691
+ password: body.password,
4692
+ grant_type: env2?.config?.grantType || "",
4693
+ client_id: env2?.config?.clientId || "",
4694
+ client_secret: env2?.config?.clientSecret || ""
4695
+ }).filter(([_, value]) => !!value)
4696
+ );
4697
+ const encodedData = new URLSearchParams(payload).toString();
4698
+ return env2?.requests?.post(body.path, encodedData, {
4699
+ headers: {
4700
+ "Content-Type": "application/x-www-form-urlencoded"
4701
+ }
4702
+ });
4703
+ },
4704
+ [env2]
4705
+ );
4706
+ const forgotPassword = useCallback3(
4707
+ async (email) => {
4708
+ const bodyData = {
4709
+ login: email,
4710
+ url: `${window.location.origin}/reset-password`
4711
+ };
4712
+ return env2?.requests?.post("/reset_password" /* RESET_PASSWORD_PATH */, bodyData, {
4713
+ headers: {
4714
+ "Content-Type": "application/json"
4715
+ }
4716
+ });
4717
+ },
4718
+ [env2]
4719
+ );
4720
+ const forgotPasswordSSO = useCallback3(
4721
+ async ({
4722
+ email,
4723
+ with_context,
4724
+ method
4725
+ }) => {
4726
+ const body = {
4727
+ method,
4728
+ kwargs: {
4729
+ vals: {
4730
+ email
4731
+ }
4732
+ },
4733
+ with_context
4734
+ };
4735
+ return env2?.requests?.post("/call" /* CALL_PATH */, body, {
4736
+ headers: {
4737
+ "Content-Type": "application/json"
4738
+ }
4739
+ });
4740
+ },
4741
+ [env2]
4742
+ );
4743
+ const resetPassword = useCallback3(
4744
+ async (data, token) => {
4745
+ const bodyData = {
4746
+ token,
4747
+ password: data.password,
4748
+ new_password: data.confirmPassword
4749
+ };
4750
+ return env2?.requests?.post("/change_password" /* CHANGE_PASSWORD_PATH */, bodyData, {
4751
+ headers: {
4752
+ "Content-Type": "application/json"
4753
+ }
4754
+ });
4755
+ },
4756
+ [env2]
4757
+ );
4758
+ const resetPasswordSSO = useCallback3(
4759
+ async ({
4760
+ method,
4761
+ password,
4762
+ with_context
4763
+ }) => {
4764
+ const bodyData = {
4765
+ method,
4766
+ kwargs: {
4767
+ vals: {
4768
+ password
4769
+ }
4770
+ },
4771
+ with_context
4772
+ };
4773
+ return env2?.requests?.post("/call" /* CALL_PATH */, bodyData, {
4774
+ headers: {
4775
+ "Content-Type": "application/json"
4776
+ }
4777
+ });
4778
+ },
4779
+ [env2]
4780
+ );
4781
+ const updatePassword = useCallback3(
4782
+ async (data, token) => {
4783
+ const bodyData = {
4784
+ token,
4785
+ old_password: data.oldPassword,
4786
+ new_password: data.newPassword
4787
+ };
4788
+ return env2?.requests?.post("/change_password_parent" /* UPDATE_PASSWORD_PATH */, bodyData, {
4789
+ headers: {
4790
+ "Content-Type": "application/json"
4791
+ }
4792
+ });
4793
+ },
4794
+ [env2]
4795
+ );
4796
+ const isValidToken = useCallback3(
4797
+ async (token) => {
4798
+ const bodyData = {
4799
+ token
4800
+ };
4801
+ return env2?.requests?.post("/check_token" /* TOKEN */, bodyData, {
4802
+ headers: {
4803
+ "Content-Type": "application/json"
4804
+ }
4805
+ });
4806
+ },
4807
+ [env2]
4808
+ );
4809
+ const isValidActionToken = useCallback3(
4810
+ async (actionToken, path) => {
4811
+ return env2?.requests?.post(
4812
+ path,
4813
+ {},
4814
+ {
4815
+ headers: {
4816
+ "Content-Type": "application/json"
4817
+ },
4818
+ useActionToken: true,
4819
+ actionToken
4820
+ }
4821
+ );
4822
+ },
4823
+ [env2]
4824
+ );
4825
+ const loginSocial = useCallback3(
4826
+ async ({
4827
+ db,
4828
+ state,
4829
+ access_token
4830
+ }) => {
4831
+ return env2?.requests?.post(
4832
+ "/token/generate" /* GENTOKEN_SOCIAL */,
4833
+ { state, access_token },
4834
+ {
4835
+ headers: {
4836
+ "Content-Type": "application/json"
4837
+ }
4838
+ }
4839
+ );
4840
+ },
4841
+ [env2]
4842
+ );
4843
+ const getProviders = useCallback3(
4844
+ async (db) => {
4845
+ return env2?.requests?.get("/oauth/providers", { params: { db } });
4846
+ },
4847
+ [env2]
4848
+ );
4849
+ const getAccessByCode = useCallback3(
4850
+ async (code) => {
4851
+ const data = new URLSearchParams();
4852
+ data.append("code", code);
4853
+ data.append("grant_type", "authorization_code");
4854
+ data.append("client_id", env2?.config?.clientId || "");
4855
+ data.append("redirect_uri", env2?.config?.redirectUri || "");
4856
+ return env2?.requests?.post(
4857
+ `${env2?.baseUrl?.replace("/mms/", "/id/")}/${"/token" /* TOKEN_BY_CODE */}`,
4858
+ data,
4859
+ {
4860
+ headers: {
4861
+ "Content-Type": "application/x-www-form-urlencoded"
4862
+ }
4863
+ }
4864
+ );
4865
+ },
4866
+ [env2]
4867
+ );
4868
+ const logout = useCallback3(
4869
+ async (data) => {
4870
+ console.log(data);
4871
+ return env2?.requests?.post(
4872
+ "/logout" /* LOGOUT */,
4873
+ {},
4874
+ {
4875
+ headers: {
4876
+ "Content-Type": "application/json"
4877
+ },
4878
+ withCredentials: true,
4879
+ useRefreshToken: true
4880
+ }
4881
+ );
4882
+ },
4883
+ [env2]
4884
+ );
4885
+ return {
4886
+ login,
4887
+ forgotPassword,
4888
+ forgotPasswordSSO,
4889
+ resetPassword,
4890
+ resetPasswordSSO,
4891
+ updatePassword,
4892
+ isValidToken,
4893
+ isValidActionToken,
4894
+ loginSocial,
4895
+ getProviders,
4896
+ getAccessByCode,
4897
+ logout
4898
+ };
4899
+ }
4675
4900
 
4676
4901
  // src/hooks/auth/use-forgot-password.ts
4677
4902
  var useForgotPassword = () => {
@@ -4723,9 +4948,10 @@ var use_isvalid_token_default = useIsValidToken;
4723
4948
  // src/hooks/auth/use-login-credential.ts
4724
4949
  import { useMutation as useMutation5 } from "@tanstack/react-query";
4725
4950
  var useLoginCredential = () => {
4951
+ const { login } = useAuthService();
4726
4952
  return useMutation5({
4727
4953
  mutationFn: (data) => {
4728
- return auth_service_default.login(data);
4954
+ return login(data);
4729
4955
  }
4730
4956
  });
4731
4957
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fctc/interface-logic",
3
- "version": "1.8.9",
3
+ "version": "1.8.10",
4
4
  "types": "dist/index.d.ts",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",