@fctc/interface-logic 1.8.8 → 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
  };
@@ -253,4 +253,31 @@ declare const ViewService: {
253
253
  }): Promise<any>;
254
254
  };
255
255
 
256
- export { ActionService, AuthService, CompanyService, ExcelService, FormService, KanbanServices as KanbanService, ModelService, UserService, ViewService };
256
+ declare function useAuthService(): {
257
+ login: (body: LoginCredentialBody) => Promise<any>;
258
+ forgotPassword: (email: string) => Promise<any>;
259
+ forgotPasswordSSO: ({ email, with_context, method, }: {
260
+ email: string;
261
+ with_context: any;
262
+ method: string;
263
+ }) => Promise<any>;
264
+ resetPassword: (data: ResetPasswordRequest, token: string | null) => Promise<any>;
265
+ resetPasswordSSO: ({ method, password, with_context, }: {
266
+ method: any;
267
+ password: string;
268
+ with_context: any;
269
+ }) => Promise<any>;
270
+ updatePassword: (data: UpdatePasswordRequest, token: string | null) => Promise<any>;
271
+ isValidToken: (token: string | null) => Promise<any>;
272
+ isValidActionToken: (actionToken: string | null, path: string) => Promise<any>;
273
+ loginSocial: ({ db, state, access_token, }: {
274
+ db: string;
275
+ state: object;
276
+ access_token: string;
277
+ }) => Promise<any>;
278
+ getProviders: (db?: string) => Promise<any>;
279
+ getAccessByCode: (code: string) => Promise<any>;
280
+ logout: (data: string) => Promise<any>;
281
+ };
282
+
283
+ export { ActionService, AuthService, CompanyService, ExcelService, FormService, KanbanServices as KanbanService, ModelService, UserService, ViewService, useAuthService };
@@ -253,4 +253,31 @@ declare const ViewService: {
253
253
  }): Promise<any>;
254
254
  };
255
255
 
256
- export { ActionService, AuthService, CompanyService, ExcelService, FormService, KanbanServices as KanbanService, ModelService, UserService, ViewService };
256
+ declare function useAuthService(): {
257
+ login: (body: LoginCredentialBody) => Promise<any>;
258
+ forgotPassword: (email: string) => Promise<any>;
259
+ forgotPasswordSSO: ({ email, with_context, method, }: {
260
+ email: string;
261
+ with_context: any;
262
+ method: string;
263
+ }) => Promise<any>;
264
+ resetPassword: (data: ResetPasswordRequest, token: string | null) => Promise<any>;
265
+ resetPasswordSSO: ({ method, password, with_context, }: {
266
+ method: any;
267
+ password: string;
268
+ with_context: any;
269
+ }) => Promise<any>;
270
+ updatePassword: (data: UpdatePasswordRequest, token: string | null) => Promise<any>;
271
+ isValidToken: (token: string | null) => Promise<any>;
272
+ isValidActionToken: (actionToken: string | null, path: string) => Promise<any>;
273
+ loginSocial: ({ db, state, access_token, }: {
274
+ db: string;
275
+ state: object;
276
+ access_token: string;
277
+ }) => Promise<any>;
278
+ getProviders: (db?: string) => Promise<any>;
279
+ getAccessByCode: (code: string) => Promise<any>;
280
+ logout: (data: string) => Promise<any>;
281
+ };
282
+
283
+ export { ActionService, AuthService, CompanyService, ExcelService, FormService, KanbanServices as KanbanService, ModelService, UserService, ViewService, useAuthService };
package/dist/services.js CHANGED
@@ -38,7 +38,8 @@ __export(services_exports, {
38
38
  KanbanService: () => kanban_service_default,
39
39
  ModelService: () => model_service_default,
40
40
  UserService: () => user_service_default,
41
- ViewService: () => view_service_default
41
+ ViewService: () => view_service_default,
42
+ useAuthService: () => useAuthService
42
43
  });
43
44
  module.exports = __toCommonJS(services_exports);
44
45
 
@@ -4691,6 +4692,231 @@ var import_jsx_runtime4 = require("react/jsx-runtime");
4691
4692
  var import_react4 = require("react");
4692
4693
  var import_jsx_runtime5 = require("react/jsx-runtime");
4693
4694
  var EnvContext = (0, import_react4.createContext)(null);
4695
+ function useEnv() {
4696
+ const context = (0, import_react4.useContext)(EnvContext);
4697
+ if (!context) {
4698
+ throw new Error("useEnv must be used within an EnvProvider");
4699
+ }
4700
+ return context;
4701
+ }
4702
+
4703
+ // src/services/auth-service/backup.ts
4704
+ function useAuthService() {
4705
+ const { env: env2 } = useEnv();
4706
+ const login = (0, import_react5.useCallback)(
4707
+ async (body) => {
4708
+ const payload = Object.fromEntries(
4709
+ Object.entries({
4710
+ username: body.email,
4711
+ password: body.password,
4712
+ grant_type: env2?.config?.grantType || "",
4713
+ client_id: env2?.config?.clientId || "",
4714
+ client_secret: env2?.config?.clientSecret || ""
4715
+ }).filter(([_, value]) => !!value)
4716
+ );
4717
+ const encodedData = new URLSearchParams(payload).toString();
4718
+ return env2?.requests?.post(body.path, encodedData, {
4719
+ headers: {
4720
+ "Content-Type": "application/x-www-form-urlencoded"
4721
+ }
4722
+ });
4723
+ },
4724
+ [env2]
4725
+ );
4726
+ const forgotPassword = (0, import_react5.useCallback)(
4727
+ async (email) => {
4728
+ const bodyData = {
4729
+ login: email,
4730
+ url: `${window.location.origin}/reset-password`
4731
+ };
4732
+ return env2?.requests?.post("/reset_password" /* RESET_PASSWORD_PATH */, bodyData, {
4733
+ headers: {
4734
+ "Content-Type": "application/json"
4735
+ }
4736
+ });
4737
+ },
4738
+ [env2]
4739
+ );
4740
+ const forgotPasswordSSO = (0, import_react5.useCallback)(
4741
+ async ({
4742
+ email,
4743
+ with_context,
4744
+ method
4745
+ }) => {
4746
+ const body = {
4747
+ method,
4748
+ kwargs: {
4749
+ vals: {
4750
+ email
4751
+ }
4752
+ },
4753
+ with_context
4754
+ };
4755
+ return env2?.requests?.post("/call" /* CALL_PATH */, body, {
4756
+ headers: {
4757
+ "Content-Type": "application/json"
4758
+ }
4759
+ });
4760
+ },
4761
+ [env2]
4762
+ );
4763
+ const resetPassword = (0, import_react5.useCallback)(
4764
+ async (data, token) => {
4765
+ const bodyData = {
4766
+ token,
4767
+ password: data.password,
4768
+ new_password: data.confirmPassword
4769
+ };
4770
+ return env2?.requests?.post("/change_password" /* CHANGE_PASSWORD_PATH */, bodyData, {
4771
+ headers: {
4772
+ "Content-Type": "application/json"
4773
+ }
4774
+ });
4775
+ },
4776
+ [env2]
4777
+ );
4778
+ const resetPasswordSSO = (0, import_react5.useCallback)(
4779
+ async ({
4780
+ method,
4781
+ password,
4782
+ with_context
4783
+ }) => {
4784
+ const bodyData = {
4785
+ method,
4786
+ kwargs: {
4787
+ vals: {
4788
+ password
4789
+ }
4790
+ },
4791
+ with_context
4792
+ };
4793
+ return env2?.requests?.post("/call" /* CALL_PATH */, bodyData, {
4794
+ headers: {
4795
+ "Content-Type": "application/json"
4796
+ }
4797
+ });
4798
+ },
4799
+ [env2]
4800
+ );
4801
+ const updatePassword = (0, import_react5.useCallback)(
4802
+ async (data, token) => {
4803
+ const bodyData = {
4804
+ token,
4805
+ old_password: data.oldPassword,
4806
+ new_password: data.newPassword
4807
+ };
4808
+ return env2?.requests?.post("/change_password_parent" /* UPDATE_PASSWORD_PATH */, bodyData, {
4809
+ headers: {
4810
+ "Content-Type": "application/json"
4811
+ }
4812
+ });
4813
+ },
4814
+ [env2]
4815
+ );
4816
+ const isValidToken = (0, import_react5.useCallback)(
4817
+ async (token) => {
4818
+ const bodyData = {
4819
+ token
4820
+ };
4821
+ return env2?.requests?.post("/check_token" /* TOKEN */, bodyData, {
4822
+ headers: {
4823
+ "Content-Type": "application/json"
4824
+ }
4825
+ });
4826
+ },
4827
+ [env2]
4828
+ );
4829
+ const isValidActionToken = (0, import_react5.useCallback)(
4830
+ async (actionToken, path) => {
4831
+ return env2?.requests?.post(
4832
+ path,
4833
+ {},
4834
+ {
4835
+ headers: {
4836
+ "Content-Type": "application/json"
4837
+ },
4838
+ useActionToken: true,
4839
+ actionToken
4840
+ }
4841
+ );
4842
+ },
4843
+ [env2]
4844
+ );
4845
+ const loginSocial = (0, import_react5.useCallback)(
4846
+ async ({
4847
+ db,
4848
+ state,
4849
+ access_token
4850
+ }) => {
4851
+ return env2?.requests?.post(
4852
+ "/token/generate" /* GENTOKEN_SOCIAL */,
4853
+ { state, access_token },
4854
+ {
4855
+ headers: {
4856
+ "Content-Type": "application/json"
4857
+ }
4858
+ }
4859
+ );
4860
+ },
4861
+ [env2]
4862
+ );
4863
+ const getProviders = (0, import_react5.useCallback)(
4864
+ async (db) => {
4865
+ return env2?.requests?.get("/oauth/providers", { params: { db } });
4866
+ },
4867
+ [env2]
4868
+ );
4869
+ const getAccessByCode = (0, import_react5.useCallback)(
4870
+ async (code) => {
4871
+ const data = new URLSearchParams();
4872
+ data.append("code", code);
4873
+ data.append("grant_type", "authorization_code");
4874
+ data.append("client_id", env2?.config?.clientId || "");
4875
+ data.append("redirect_uri", env2?.config?.redirectUri || "");
4876
+ return env2?.requests?.post(
4877
+ `${env2?.baseUrl?.replace("/mms/", "/id/")}/${"/token" /* TOKEN_BY_CODE */}`,
4878
+ data,
4879
+ {
4880
+ headers: {
4881
+ "Content-Type": "application/x-www-form-urlencoded"
4882
+ }
4883
+ }
4884
+ );
4885
+ },
4886
+ [env2]
4887
+ );
4888
+ const logout = (0, import_react5.useCallback)(
4889
+ async (data) => {
4890
+ console.log(data);
4891
+ return env2?.requests?.post(
4892
+ "/logout" /* LOGOUT */,
4893
+ {},
4894
+ {
4895
+ headers: {
4896
+ "Content-Type": "application/json"
4897
+ },
4898
+ withCredentials: true,
4899
+ useRefreshToken: true
4900
+ }
4901
+ );
4902
+ },
4903
+ [env2]
4904
+ );
4905
+ return {
4906
+ login,
4907
+ forgotPassword,
4908
+ forgotPasswordSSO,
4909
+ resetPassword,
4910
+ resetPasswordSSO,
4911
+ updatePassword,
4912
+ isValidToken,
4913
+ isValidActionToken,
4914
+ loginSocial,
4915
+ getProviders,
4916
+ getAccessByCode,
4917
+ logout
4918
+ };
4919
+ }
4694
4920
  // Annotate the CommonJS export names for ESM import in node:
4695
4921
  0 && (module.exports = {
4696
4922
  ActionService,
@@ -4701,5 +4927,6 @@ var EnvContext = (0, import_react4.createContext)(null);
4701
4927
  KanbanService,
4702
4928
  ModelService,
4703
4929
  UserService,
4704
- ViewService
4930
+ ViewService,
4931
+ useAuthService
4705
4932
  });
package/dist/services.mjs CHANGED
@@ -4647,6 +4647,231 @@ import { Fragment, jsx as jsx4 } from "react/jsx-runtime";
4647
4647
  import { createContext, useContext, useState as useState3, useCallback as useCallback2 } from "react";
4648
4648
  import { jsx as jsx5 } from "react/jsx-runtime";
4649
4649
  var EnvContext = createContext(null);
4650
+ function useEnv() {
4651
+ const context = useContext(EnvContext);
4652
+ if (!context) {
4653
+ throw new Error("useEnv must be used within an EnvProvider");
4654
+ }
4655
+ return context;
4656
+ }
4657
+
4658
+ // src/services/auth-service/backup.ts
4659
+ function useAuthService() {
4660
+ const { env: env2 } = useEnv();
4661
+ const login = useCallback3(
4662
+ async (body) => {
4663
+ const payload = Object.fromEntries(
4664
+ Object.entries({
4665
+ username: body.email,
4666
+ password: body.password,
4667
+ grant_type: env2?.config?.grantType || "",
4668
+ client_id: env2?.config?.clientId || "",
4669
+ client_secret: env2?.config?.clientSecret || ""
4670
+ }).filter(([_, value]) => !!value)
4671
+ );
4672
+ const encodedData = new URLSearchParams(payload).toString();
4673
+ return env2?.requests?.post(body.path, encodedData, {
4674
+ headers: {
4675
+ "Content-Type": "application/x-www-form-urlencoded"
4676
+ }
4677
+ });
4678
+ },
4679
+ [env2]
4680
+ );
4681
+ const forgotPassword = useCallback3(
4682
+ async (email) => {
4683
+ const bodyData = {
4684
+ login: email,
4685
+ url: `${window.location.origin}/reset-password`
4686
+ };
4687
+ return env2?.requests?.post("/reset_password" /* RESET_PASSWORD_PATH */, bodyData, {
4688
+ headers: {
4689
+ "Content-Type": "application/json"
4690
+ }
4691
+ });
4692
+ },
4693
+ [env2]
4694
+ );
4695
+ const forgotPasswordSSO = useCallback3(
4696
+ async ({
4697
+ email,
4698
+ with_context,
4699
+ method
4700
+ }) => {
4701
+ const body = {
4702
+ method,
4703
+ kwargs: {
4704
+ vals: {
4705
+ email
4706
+ }
4707
+ },
4708
+ with_context
4709
+ };
4710
+ return env2?.requests?.post("/call" /* CALL_PATH */, body, {
4711
+ headers: {
4712
+ "Content-Type": "application/json"
4713
+ }
4714
+ });
4715
+ },
4716
+ [env2]
4717
+ );
4718
+ const resetPassword = useCallback3(
4719
+ async (data, token) => {
4720
+ const bodyData = {
4721
+ token,
4722
+ password: data.password,
4723
+ new_password: data.confirmPassword
4724
+ };
4725
+ return env2?.requests?.post("/change_password" /* CHANGE_PASSWORD_PATH */, bodyData, {
4726
+ headers: {
4727
+ "Content-Type": "application/json"
4728
+ }
4729
+ });
4730
+ },
4731
+ [env2]
4732
+ );
4733
+ const resetPasswordSSO = useCallback3(
4734
+ async ({
4735
+ method,
4736
+ password,
4737
+ with_context
4738
+ }) => {
4739
+ const bodyData = {
4740
+ method,
4741
+ kwargs: {
4742
+ vals: {
4743
+ password
4744
+ }
4745
+ },
4746
+ with_context
4747
+ };
4748
+ return env2?.requests?.post("/call" /* CALL_PATH */, bodyData, {
4749
+ headers: {
4750
+ "Content-Type": "application/json"
4751
+ }
4752
+ });
4753
+ },
4754
+ [env2]
4755
+ );
4756
+ const updatePassword = useCallback3(
4757
+ async (data, token) => {
4758
+ const bodyData = {
4759
+ token,
4760
+ old_password: data.oldPassword,
4761
+ new_password: data.newPassword
4762
+ };
4763
+ return env2?.requests?.post("/change_password_parent" /* UPDATE_PASSWORD_PATH */, bodyData, {
4764
+ headers: {
4765
+ "Content-Type": "application/json"
4766
+ }
4767
+ });
4768
+ },
4769
+ [env2]
4770
+ );
4771
+ const isValidToken = useCallback3(
4772
+ async (token) => {
4773
+ const bodyData = {
4774
+ token
4775
+ };
4776
+ return env2?.requests?.post("/check_token" /* TOKEN */, bodyData, {
4777
+ headers: {
4778
+ "Content-Type": "application/json"
4779
+ }
4780
+ });
4781
+ },
4782
+ [env2]
4783
+ );
4784
+ const isValidActionToken = useCallback3(
4785
+ async (actionToken, path) => {
4786
+ return env2?.requests?.post(
4787
+ path,
4788
+ {},
4789
+ {
4790
+ headers: {
4791
+ "Content-Type": "application/json"
4792
+ },
4793
+ useActionToken: true,
4794
+ actionToken
4795
+ }
4796
+ );
4797
+ },
4798
+ [env2]
4799
+ );
4800
+ const loginSocial = useCallback3(
4801
+ async ({
4802
+ db,
4803
+ state,
4804
+ access_token
4805
+ }) => {
4806
+ return env2?.requests?.post(
4807
+ "/token/generate" /* GENTOKEN_SOCIAL */,
4808
+ { state, access_token },
4809
+ {
4810
+ headers: {
4811
+ "Content-Type": "application/json"
4812
+ }
4813
+ }
4814
+ );
4815
+ },
4816
+ [env2]
4817
+ );
4818
+ const getProviders = useCallback3(
4819
+ async (db) => {
4820
+ return env2?.requests?.get("/oauth/providers", { params: { db } });
4821
+ },
4822
+ [env2]
4823
+ );
4824
+ const getAccessByCode = useCallback3(
4825
+ async (code) => {
4826
+ const data = new URLSearchParams();
4827
+ data.append("code", code);
4828
+ data.append("grant_type", "authorization_code");
4829
+ data.append("client_id", env2?.config?.clientId || "");
4830
+ data.append("redirect_uri", env2?.config?.redirectUri || "");
4831
+ return env2?.requests?.post(
4832
+ `${env2?.baseUrl?.replace("/mms/", "/id/")}/${"/token" /* TOKEN_BY_CODE */}`,
4833
+ data,
4834
+ {
4835
+ headers: {
4836
+ "Content-Type": "application/x-www-form-urlencoded"
4837
+ }
4838
+ }
4839
+ );
4840
+ },
4841
+ [env2]
4842
+ );
4843
+ const logout = useCallback3(
4844
+ async (data) => {
4845
+ console.log(data);
4846
+ return env2?.requests?.post(
4847
+ "/logout" /* LOGOUT */,
4848
+ {},
4849
+ {
4850
+ headers: {
4851
+ "Content-Type": "application/json"
4852
+ },
4853
+ withCredentials: true,
4854
+ useRefreshToken: true
4855
+ }
4856
+ );
4857
+ },
4858
+ [env2]
4859
+ );
4860
+ return {
4861
+ login,
4862
+ forgotPassword,
4863
+ forgotPasswordSSO,
4864
+ resetPassword,
4865
+ resetPasswordSSO,
4866
+ updatePassword,
4867
+ isValidToken,
4868
+ isValidActionToken,
4869
+ loginSocial,
4870
+ getProviders,
4871
+ getAccessByCode,
4872
+ logout
4873
+ };
4874
+ }
4650
4875
  export {
4651
4876
  action_service_default as ActionService,
4652
4877
  auth_service_default as AuthService,
@@ -4656,5 +4881,6 @@ export {
4656
4881
  kanban_service_default as KanbanService,
4657
4882
  model_service_default as ModelService,
4658
4883
  user_service_default as UserService,
4659
- view_service_default as ViewService
4884
+ view_service_default as ViewService,
4885
+ useAuthService
4660
4886
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fctc/interface-logic",
3
- "version": "1.8.8",
3
+ "version": "1.8.10",
4
4
  "types": "dist/index.d.ts",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",