@fctc/interface-logic 2.1.4 → 2.2.0

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/provider.mjs CHANGED
@@ -2848,15 +2848,21 @@ function useActionService() {
2848
2848
  const loadAction = useCallback(
2849
2849
  async ({
2850
2850
  idAction,
2851
- context
2851
+ context,
2852
+ service
2852
2853
  }) => {
2853
2854
  const jsonData = {
2854
2855
  action_id: idAction,
2855
2856
  with_context: { ...context }
2856
2857
  };
2857
- return env.requests.post("/load_action" /* LOAD_ACTION */, jsonData, {
2858
- headers: { "Content-Type": "application/json" }
2859
- });
2858
+ return env.requests.post(
2859
+ "/load_action" /* LOAD_ACTION */,
2860
+ jsonData,
2861
+ {
2862
+ headers: { "Content-Type": "application/json" }
2863
+ },
2864
+ service
2865
+ );
2860
2866
  },
2861
2867
  [env]
2862
2868
  );
@@ -2865,7 +2871,8 @@ function useActionService() {
2865
2871
  model,
2866
2872
  ids = [],
2867
2873
  context,
2868
- method
2874
+ method,
2875
+ service
2869
2876
  }) => {
2870
2877
  try {
2871
2878
  const jsonData = {
@@ -2874,9 +2881,14 @@ function useActionService() {
2874
2881
  ids,
2875
2882
  with_context: context
2876
2883
  };
2877
- return env.requests.post("/call" /* CALL_PATH */, jsonData, {
2878
- headers: { "Content-Type": "application/json" }
2879
- });
2884
+ return env.requests.post(
2885
+ "/call" /* CALL_PATH */,
2886
+ jsonData,
2887
+ {
2888
+ headers: { "Content-Type": "application/json" }
2889
+ },
2890
+ service
2891
+ );
2880
2892
  } catch (error) {
2881
2893
  console.error("Error when calling button action:", error);
2882
2894
  throw error;
@@ -2888,7 +2900,8 @@ function useActionService() {
2888
2900
  async ({
2889
2901
  model,
2890
2902
  ids,
2891
- context
2903
+ context,
2904
+ service
2892
2905
  }) => {
2893
2906
  const jsonData = {
2894
2907
  model,
@@ -2896,9 +2909,14 @@ function useActionService() {
2896
2909
  ids,
2897
2910
  with_context: context
2898
2911
  };
2899
- return env.requests.post("/call" /* CALL_PATH */, jsonData, {
2900
- headers: { "Content-Type": "application/json" }
2901
- });
2912
+ return env.requests.post(
2913
+ "/call" /* CALL_PATH */,
2914
+ jsonData,
2915
+ {
2916
+ headers: { "Content-Type": "application/json" }
2917
+ },
2918
+ service
2919
+ );
2902
2920
  },
2903
2921
  [env]
2904
2922
  );
@@ -2906,7 +2924,8 @@ function useActionService() {
2906
2924
  async ({
2907
2925
  model,
2908
2926
  id,
2909
- context
2927
+ context,
2928
+ service
2910
2929
  }) => {
2911
2930
  const jsonData = {
2912
2931
  model,
@@ -2914,9 +2933,14 @@ function useActionService() {
2914
2933
  ids: id,
2915
2934
  with_context: context
2916
2935
  };
2917
- return env.requests.post("/call" /* CALL_PATH */, jsonData, {
2918
- headers: { "Content-Type": "application/json" }
2919
- });
2936
+ return env.requests.post(
2937
+ "/call" /* CALL_PATH */,
2938
+ jsonData,
2939
+ {
2940
+ headers: { "Content-Type": "application/json" }
2941
+ },
2942
+ service
2943
+ );
2920
2944
  },
2921
2945
  [env]
2922
2946
  );
@@ -2959,15 +2983,21 @@ function useActionService() {
2959
2983
  const runAction = useCallback(
2960
2984
  async ({
2961
2985
  idAction,
2962
- context
2986
+ context,
2987
+ service
2963
2988
  }) => {
2964
2989
  const jsonData = {
2965
2990
  action_id: idAction,
2966
2991
  with_context: { ...context }
2967
2992
  };
2968
- return env.requests.post("/run_action" /* RUN_ACTION_PATH */, jsonData, {
2969
- headers: { "Content-Type": "application/json" }
2970
- });
2993
+ return env.requests.post(
2994
+ "/run_action" /* RUN_ACTION_PATH */,
2995
+ jsonData,
2996
+ {
2997
+ headers: { "Content-Type": "application/json" }
2998
+ },
2999
+ service
3000
+ );
2971
3001
  },
2972
3002
  [env]
2973
3003
  );
@@ -3682,7 +3712,7 @@ function useModelService() {
3682
3712
  });
3683
3713
  }, [env]);
3684
3714
  const getAll = useCallback7(
3685
- async ({ data }) => {
3715
+ async ({ data, service }) => {
3686
3716
  const jsonReadGroup = data.type == "calendar" ? { fields: data?.fields } : data.fields && data.fields.length > 0 && data.groupby && data.groupby.length > 0 && data.groupby[0] ? {
3687
3717
  fields: data.fields,
3688
3718
  groupby: data.groupby
@@ -3703,11 +3733,16 @@ function useModelService() {
3703
3733
  ...jsonReadGroup
3704
3734
  }
3705
3735
  };
3706
- return env.requests.post("/call" /* CALL_PATH */, jsonData, {
3707
- headers: {
3708
- "Content-Type": "application/json"
3709
- }
3710
- });
3736
+ return env.requests.post(
3737
+ "/call" /* CALL_PATH */,
3738
+ jsonData,
3739
+ {
3740
+ headers: {
3741
+ "Content-Type": "application/json"
3742
+ }
3743
+ },
3744
+ service
3745
+ );
3711
3746
  },
3712
3747
  [env]
3713
3748
  );
@@ -3775,7 +3810,13 @@ function useModelService() {
3775
3810
  [env]
3776
3811
  );
3777
3812
  const getDetail = useCallback7(
3778
- async ({ ids = [], model, specification, context }) => {
3813
+ async ({
3814
+ ids = [],
3815
+ model,
3816
+ specification,
3817
+ context,
3818
+ service
3819
+ }) => {
3779
3820
  const jsonData = {
3780
3821
  model,
3781
3822
  method: "web_read" /* WEB_READ */,
@@ -3785,11 +3826,16 @@ function useModelService() {
3785
3826
  specification
3786
3827
  }
3787
3828
  };
3788
- return env.requests.post("/call" /* CALL_PATH */, jsonData, {
3789
- headers: {
3790
- "Content-Type": "application/json"
3791
- }
3792
- });
3829
+ return env.requests.post(
3830
+ "/call" /* CALL_PATH */,
3831
+ jsonData,
3832
+ {
3833
+ headers: {
3834
+ "Content-Type": "application/json"
3835
+ }
3836
+ },
3837
+ service
3838
+ );
3793
3839
  },
3794
3840
  [env]
3795
3841
  );
@@ -3800,7 +3846,8 @@ function useModelService() {
3800
3846
  data = {},
3801
3847
  specification = {},
3802
3848
  context = {},
3803
- path
3849
+ path,
3850
+ service
3804
3851
  }) => {
3805
3852
  const jsonData = {
3806
3853
  model,
@@ -3812,26 +3859,36 @@ function useModelService() {
3812
3859
  specification
3813
3860
  }
3814
3861
  };
3815
- return env.requests.post(path ?? "/call" /* CALL_PATH */, jsonData, {
3816
- headers: {
3817
- "Content-Type": "application/json"
3818
- }
3819
- });
3862
+ return env.requests.post(
3863
+ path ?? "/call" /* CALL_PATH */,
3864
+ jsonData,
3865
+ {
3866
+ headers: {
3867
+ "Content-Type": "application/json"
3868
+ }
3869
+ },
3870
+ service
3871
+ );
3820
3872
  },
3821
3873
  [env]
3822
3874
  );
3823
3875
  const deleteApi = useCallback7(
3824
- async ({ ids = [], model }) => {
3876
+ async ({ ids = [], model, service }) => {
3825
3877
  const jsonData = {
3826
3878
  model,
3827
3879
  method: "unlink" /* UNLINK */,
3828
3880
  ids
3829
3881
  };
3830
- return env.requests.post("/call" /* CALL_PATH */, jsonData, {
3831
- headers: {
3832
- "Content-Type": "application/json"
3833
- }
3834
- });
3882
+ return env.requests.post(
3883
+ "/call" /* CALL_PATH */,
3884
+ jsonData,
3885
+ {
3886
+ headers: {
3887
+ "Content-Type": "application/json"
3888
+ }
3889
+ },
3890
+ service
3891
+ );
3835
3892
  },
3836
3893
  [env]
3837
3894
  );
@@ -3842,7 +3899,8 @@ function useModelService() {
3842
3899
  object,
3843
3900
  specification,
3844
3901
  context,
3845
- fieldChange
3902
+ fieldChange,
3903
+ service
3846
3904
  }) => {
3847
3905
  const jsonData = {
3848
3906
  model,
@@ -3855,25 +3913,36 @@ function useModelService() {
3855
3913
  specification
3856
3914
  ]
3857
3915
  };
3858
- return env.requests.post("/call" /* CALL_PATH */, jsonData, {
3859
- headers: {
3860
- "Content-Type": "application/json"
3861
- }
3862
- });
3916
+ return env.requests.post(
3917
+ "/call" /* CALL_PATH */,
3918
+ jsonData,
3919
+ {
3920
+ headers: {
3921
+ "Content-Type": "application/json"
3922
+ }
3923
+ },
3924
+ service
3925
+ );
3863
3926
  },
3864
3927
  [env]
3865
3928
  );
3866
3929
  const getListFieldsOnchange = useCallback7(
3867
- async ({ model }) => {
3930
+ async ({ model, service }) => {
3931
+ console.log("service", service);
3868
3932
  const jsonData = {
3869
3933
  model,
3870
3934
  method: "get_fields_onchange" /* GET_ONCHANGE_FIELDS */
3871
3935
  };
3872
- return env.requests.post("/call" /* CALL_PATH */, jsonData, {
3873
- headers: {
3874
- "Content-Type": "application/json"
3875
- }
3876
- });
3936
+ return env.requests.post(
3937
+ "/call" /* CALL_PATH */,
3938
+ jsonData,
3939
+ {
3940
+ headers: {
3941
+ "Content-Type": "application/json"
3942
+ }
3943
+ },
3944
+ service
3945
+ );
3877
3946
  },
3878
3947
  [env]
3879
3948
  );
@@ -4033,7 +4102,8 @@ function useViewService() {
4033
4102
  views,
4034
4103
  context = {},
4035
4104
  options = {},
4036
- aid
4105
+ aid,
4106
+ service
4037
4107
  }) => {
4038
4108
  const defaultOptions = {
4039
4109
  load_filters: true,
@@ -4049,11 +4119,16 @@ function useViewService() {
4049
4119
  },
4050
4120
  with_context: context
4051
4121
  };
4052
- return env?.requests?.post("/call" /* CALL_PATH */, jsonDataView, {
4053
- headers: {
4054
- "Content-Type": "application/json"
4055
- }
4056
- });
4122
+ return env?.requests?.post(
4123
+ "/call" /* CALL_PATH */,
4124
+ jsonDataView,
4125
+ {
4126
+ headers: {
4127
+ "Content-Type": "application/json"
4128
+ }
4129
+ },
4130
+ service
4131
+ );
4057
4132
  },
4058
4133
  [env]
4059
4134
  );
@@ -4136,7 +4211,7 @@ function useViewService() {
4136
4211
  [env]
4137
4212
  );
4138
4213
  const getSelectionItem = useCallback9(
4139
- async ({ data }) => {
4214
+ async ({ data, service }) => {
4140
4215
  const jsonData = {
4141
4216
  model: data.model,
4142
4217
  ids: [],
@@ -4154,11 +4229,16 @@ function useViewService() {
4154
4229
  }
4155
4230
  }
4156
4231
  };
4157
- return env?.requests.post("/call" /* CALL_PATH */, jsonData, {
4158
- headers: {
4159
- "Content-Type": "application/json"
4160
- }
4161
- });
4232
+ return env?.requests.post(
4233
+ "/call" /* CALL_PATH */,
4234
+ jsonData,
4235
+ {
4236
+ headers: {
4237
+ "Content-Type": "application/json"
4238
+ }
4239
+ },
4240
+ service
4241
+ );
4162
4242
  },
4163
4243
  [env]
4164
4244
  );
@@ -4451,7 +4531,6 @@ var sessionStorageUtils = () => {
4451
4531
  // src/configs/axios-client.ts
4452
4532
  var axiosClient = {
4453
4533
  init(config) {
4454
- console.log("config", config);
4455
4534
  const localStorage2 = config?.localStorageUtils ?? localStorageUtils();
4456
4535
  const sessionStorage2 = config?.sessionStorageUtils ?? sessionStorageUtils();
4457
4536
  const db = config?.db;
@@ -4470,25 +4549,21 @@ var axiosClient = {
4470
4549
  };
4471
4550
  const instance = axios.create({
4472
4551
  adapter: axios.defaults.adapter,
4473
- baseURL: config.baseUrl,
4552
+ baseURL: config?.baseUrl,
4474
4553
  timeout: 5e4,
4475
4554
  paramsSerializer: (params) => new URLSearchParams(params).toString()
4476
4555
  });
4477
4556
  instance.interceptors.request.use(async (config2) => {
4478
4557
  const { useRefreshToken, useActionToken, actionToken } = config2;
4479
- let token = null;
4480
4558
  if (useActionToken && actionToken) {
4481
- token = actionToken;
4482
- } else {
4483
- const getToken = useRefreshToken ? localStorage2.getRefreshToken : localStorage2.getAccessToken;
4484
- token = await getToken?.();
4485
- }
4486
- if (token) {
4487
- config2.headers["Authorization"] = `Bearer ${token}`;
4559
+ config2.headers["Action-Token"] = actionToken;
4488
4560
  }
4489
4561
  if (database) {
4490
4562
  config2.headers["DATABASE"] = database;
4491
4563
  }
4564
+ const getToken = useRefreshToken ? localStorage2.getRefreshToken : localStorage2.getAccessToken;
4565
+ const token = await getToken?.();
4566
+ if (token) config2.headers["Authorization"] = `Bearer ${token}`;
4492
4567
  return config2;
4493
4568
  }, Promise.reject);
4494
4569
  instance.interceptors.response.use(
@@ -4543,7 +4618,7 @@ var axiosClient = {
4543
4618
  );
4544
4619
  return new Promise(function(resolve) {
4545
4620
  axios.post(
4546
- `${config.baseUrl}${config.refreshTokenEndpoint ?? "/authentication/oauth2/token" /* AUTH_TOKEN_PATH */}`,
4621
+ `${config?.baseUrl}${config.refreshTokenEndpoint ?? "/authentication/oauth2/token" /* AUTH_TOKEN_PATH */}`,
4547
4622
  payload,
4548
4623
  {
4549
4624
  headers: {
@@ -4611,20 +4686,47 @@ var axiosClient = {
4611
4686
  function formatUrl(url, db2) {
4612
4687
  return url + (db2 ? "?db=" + db2 : "");
4613
4688
  }
4689
+ const getBaseUrl = (baseUrl, serviceName) => {
4690
+ const service = serviceName || config?.default_service;
4691
+ return `${baseUrl.replace(/\/$/, "")}/${service}/api/v2`;
4692
+ };
4614
4693
  const responseBody = (response) => response;
4615
4694
  const requests = {
4616
- get: (url, headers) => instance.get(formatUrl(url, db), headers).then(responseBody),
4617
- post: (url, body, headers) => instance.post(formatUrl(url, db), body, headers).then(responseBody),
4618
- post_excel: (url, body, headers) => instance.post(formatUrl(url, db), body, {
4619
- responseType: "arraybuffer",
4620
- headers: {
4621
- "Content-Type": typeof window !== "undefined" ? "application/json" : "application/javascript",
4622
- Accept: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
4695
+ get: (url, headers, serviceName) => instance.get(
4696
+ formatUrl(getBaseUrl(config?.baseUrl, serviceName) + url, db),
4697
+ headers
4698
+ ).then(responseBody),
4699
+ post: (url, body, headers, serviceName) => instance.post(
4700
+ formatUrl(getBaseUrl(config?.baseUrl, serviceName) + url, db),
4701
+ body,
4702
+ headers
4703
+ ).then(responseBody),
4704
+ post_excel: (url, body, headers, serviceName) => instance.post(
4705
+ formatUrl(getBaseUrl(config?.baseUrl, serviceName) + url, db),
4706
+ body,
4707
+ {
4708
+ responseType: "arraybuffer",
4709
+ headers: {
4710
+ "Content-Type": typeof window !== "undefined" ? "application/json" : "application/javascript",
4711
+ Accept: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
4712
+ ...headers
4713
+ }
4623
4714
  }
4624
- }).then(responseBody),
4625
- put: (url, body, headers) => instance.put(formatUrl(url, db), body, headers).then(responseBody),
4626
- patch: (url, body) => instance.patch(formatUrl(url, db), body).then(responseBody),
4627
- delete: (url, body) => instance.delete(formatUrl(url, db), body).then(responseBody)
4715
+ ).then(responseBody),
4716
+ put: (url, body, headers, serviceName) => instance.put(
4717
+ formatUrl(getBaseUrl(config?.baseUrl, serviceName) + url, db),
4718
+ body,
4719
+ headers
4720
+ ).then(responseBody),
4721
+ patch: (url, body, headers, serviceName) => instance.patch(
4722
+ formatUrl(getBaseUrl(config?.baseUrl, serviceName) + url, db),
4723
+ body,
4724
+ headers
4725
+ ).then(responseBody),
4726
+ delete: (url, headers, serviceName) => instance.delete(
4727
+ formatUrl(getBaseUrl(config?.baseUrl, serviceName) + url, db),
4728
+ headers
4729
+ ).then(responseBody)
4628
4730
  };
4629
4731
  return requests;
4630
4732
  }
@@ -5220,7 +5322,7 @@ import { useMutation as useMutation25 } from "@tanstack/react-query";
5220
5322
  var useDelete = () => {
5221
5323
  const { deleteApi } = useModelService();
5222
5324
  return useMutation25({
5223
- mutationFn: ({ ids, model }) => deleteApi({ ids, model })
5325
+ mutationFn: ({ ids, model, service }) => deleteApi({ ids, model, service })
5224
5326
  });
5225
5327
  };
5226
5328
  var use_delete_default = useDelete;
@@ -5283,12 +5385,14 @@ var useGetDetail = () => {
5283
5385
  model,
5284
5386
  ids,
5285
5387
  specification,
5286
- context
5388
+ context,
5389
+ service
5287
5390
  }) => getDetail({
5288
5391
  model,
5289
5392
  ids,
5290
5393
  specification,
5291
- context
5394
+ context,
5395
+ service
5292
5396
  })
5293
5397
  });
5294
5398
  };
@@ -5296,12 +5400,16 @@ var use_get_detail_default = useGetDetail;
5296
5400
 
5297
5401
  // src/hooks/model/use-get-field-onchange.ts
5298
5402
  import { useQuery as useQuery9 } from "@tanstack/react-query";
5299
- var useGetFieldOnChange = ({ model }) => {
5403
+ var useGetFieldOnChange = ({
5404
+ model,
5405
+ service
5406
+ }) => {
5300
5407
  const { getListFieldsOnchange } = useModelService();
5301
5408
  return useQuery9({
5302
5409
  queryKey: [`field-onchange-${model}`, model],
5303
5410
  queryFn: () => getListFieldsOnchange({
5304
- model
5411
+ model,
5412
+ service
5305
5413
  }).then((res) => {
5306
5414
  if (res) {
5307
5415
  return res;
@@ -5484,14 +5592,16 @@ var useOnChangeForm = () => {
5484
5592
  specification,
5485
5593
  context,
5486
5594
  object,
5487
- fieldChange
5595
+ fieldChange,
5596
+ service
5488
5597
  }) => onChange({
5489
5598
  ids,
5490
5599
  model,
5491
5600
  specification,
5492
5601
  context,
5493
5602
  object,
5494
- fieldChange
5603
+ fieldChange,
5604
+ service
5495
5605
  })
5496
5606
  });
5497
5607
  };
@@ -5508,8 +5618,9 @@ var useSave = () => {
5508
5618
  data,
5509
5619
  specification,
5510
5620
  context,
5511
- path
5512
- }) => save({ ids, model, data, specification, context, path })
5621
+ path,
5622
+ service
5623
+ }) => save({ ids, model, data, specification, context, path, service })
5513
5624
  });
5514
5625
  };
5515
5626
  var use_save_default = useSave;
@@ -5561,12 +5672,14 @@ var useButton = () => {
5561
5672
  model,
5562
5673
  ids,
5563
5674
  context,
5564
- method
5675
+ method,
5676
+ service
5565
5677
  }) => callButton({
5566
5678
  model,
5567
5679
  ids,
5568
5680
  context,
5569
- method
5681
+ method,
5682
+ service
5570
5683
  }),
5571
5684
  onSuccess: (response) => {
5572
5685
  return response;
@@ -5583,11 +5696,13 @@ var useDuplicateRecord = () => {
5583
5696
  mutationFn: ({
5584
5697
  id,
5585
5698
  model,
5586
- context
5699
+ context,
5700
+ service
5587
5701
  }) => duplicateRecord({
5588
5702
  id,
5589
5703
  model,
5590
- context
5704
+ context,
5705
+ service
5591
5706
  })
5592
5707
  });
5593
5708
  };
@@ -5670,11 +5785,11 @@ var use_get_groups_default = useGetGroups;
5670
5785
 
5671
5786
  // src/hooks/view/use-get-list-data.ts
5672
5787
  import { useQuery as useQuery14 } from "@tanstack/react-query";
5673
- var useGetListData = (listDataProps, queryKey, enabled) => {
5788
+ var useGetListData = (listDataProps, queryKey, enabled, service) => {
5674
5789
  const { getAll } = useModelService();
5675
5790
  return useQuery14({
5676
5791
  queryKey,
5677
- queryFn: () => getAll({ data: listDataProps }).then((res) => {
5792
+ queryFn: () => getAll({ data: listDataProps, service }).then((res) => {
5678
5793
  if (res) {
5679
5794
  return res;
5680
5795
  }
@@ -5750,12 +5865,13 @@ import { useQuery as useQuery17 } from "@tanstack/react-query";
5750
5865
  var useGetSelection = ({
5751
5866
  data,
5752
5867
  queryKey,
5753
- enabled
5868
+ enabled,
5869
+ service
5754
5870
  }) => {
5755
5871
  const { getSelectionItem } = useViewService();
5756
5872
  return useQuery17({
5757
5873
  queryKey,
5758
- queryFn: () => getSelectionItem({ data }),
5874
+ queryFn: () => getSelectionItem({ data, service }),
5759
5875
  enabled,
5760
5876
  refetchOnWindowFocus: false
5761
5877
  });
@@ -5783,11 +5899,13 @@ var useLoadAction = () => {
5783
5899
  return useMutation35({
5784
5900
  mutationFn: ({
5785
5901
  idAction,
5786
- context
5902
+ context,
5903
+ service
5787
5904
  }) => {
5788
5905
  return loadAction({
5789
5906
  idAction,
5790
- context
5907
+ context,
5908
+ service
5791
5909
  });
5792
5910
  }
5793
5911
  });
@@ -5828,11 +5946,13 @@ var useRemoveRow = () => {
5828
5946
  mutationFn: ({
5829
5947
  model,
5830
5948
  ids,
5831
- context
5949
+ context,
5950
+ service
5832
5951
  }) => removeRows({
5833
5952
  model,
5834
5953
  ids,
5835
- context
5954
+ context,
5955
+ service
5836
5956
  })
5837
5957
  });
5838
5958
  };
@@ -5863,10 +5983,12 @@ var useRunAction = () => {
5863
5983
  return useMutation38({
5864
5984
  mutationFn: ({
5865
5985
  idAction,
5866
- context
5986
+ context,
5987
+ service
5867
5988
  }) => runAction({
5868
5989
  idAction,
5869
- context
5990
+ context,
5991
+ service
5870
5992
  })
5871
5993
  });
5872
5994
  };