@fctc/interface-logic 1.8.8 → 1.8.9

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.
@@ -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.9",
4
4
  "types": "dist/index.d.ts",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",