@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.js CHANGED
@@ -2891,15 +2891,21 @@ function useActionService() {
2891
2891
  const loadAction = (0, import_react2.useCallback)(
2892
2892
  async ({
2893
2893
  idAction,
2894
- context
2894
+ context,
2895
+ service
2895
2896
  }) => {
2896
2897
  const jsonData = {
2897
2898
  action_id: idAction,
2898
2899
  with_context: { ...context }
2899
2900
  };
2900
- return env.requests.post("/load_action" /* LOAD_ACTION */, jsonData, {
2901
- headers: { "Content-Type": "application/json" }
2902
- });
2901
+ return env.requests.post(
2902
+ "/load_action" /* LOAD_ACTION */,
2903
+ jsonData,
2904
+ {
2905
+ headers: { "Content-Type": "application/json" }
2906
+ },
2907
+ service
2908
+ );
2903
2909
  },
2904
2910
  [env]
2905
2911
  );
@@ -2908,7 +2914,8 @@ function useActionService() {
2908
2914
  model,
2909
2915
  ids = [],
2910
2916
  context,
2911
- method
2917
+ method,
2918
+ service
2912
2919
  }) => {
2913
2920
  try {
2914
2921
  const jsonData = {
@@ -2917,9 +2924,14 @@ function useActionService() {
2917
2924
  ids,
2918
2925
  with_context: context
2919
2926
  };
2920
- return env.requests.post("/call" /* CALL_PATH */, jsonData, {
2921
- headers: { "Content-Type": "application/json" }
2922
- });
2927
+ return env.requests.post(
2928
+ "/call" /* CALL_PATH */,
2929
+ jsonData,
2930
+ {
2931
+ headers: { "Content-Type": "application/json" }
2932
+ },
2933
+ service
2934
+ );
2923
2935
  } catch (error) {
2924
2936
  console.error("Error when calling button action:", error);
2925
2937
  throw error;
@@ -2931,7 +2943,8 @@ function useActionService() {
2931
2943
  async ({
2932
2944
  model,
2933
2945
  ids,
2934
- context
2946
+ context,
2947
+ service
2935
2948
  }) => {
2936
2949
  const jsonData = {
2937
2950
  model,
@@ -2939,9 +2952,14 @@ function useActionService() {
2939
2952
  ids,
2940
2953
  with_context: context
2941
2954
  };
2942
- return env.requests.post("/call" /* CALL_PATH */, jsonData, {
2943
- headers: { "Content-Type": "application/json" }
2944
- });
2955
+ return env.requests.post(
2956
+ "/call" /* CALL_PATH */,
2957
+ jsonData,
2958
+ {
2959
+ headers: { "Content-Type": "application/json" }
2960
+ },
2961
+ service
2962
+ );
2945
2963
  },
2946
2964
  [env]
2947
2965
  );
@@ -2949,7 +2967,8 @@ function useActionService() {
2949
2967
  async ({
2950
2968
  model,
2951
2969
  id,
2952
- context
2970
+ context,
2971
+ service
2953
2972
  }) => {
2954
2973
  const jsonData = {
2955
2974
  model,
@@ -2957,9 +2976,14 @@ function useActionService() {
2957
2976
  ids: id,
2958
2977
  with_context: context
2959
2978
  };
2960
- return env.requests.post("/call" /* CALL_PATH */, jsonData, {
2961
- headers: { "Content-Type": "application/json" }
2962
- });
2979
+ return env.requests.post(
2980
+ "/call" /* CALL_PATH */,
2981
+ jsonData,
2982
+ {
2983
+ headers: { "Content-Type": "application/json" }
2984
+ },
2985
+ service
2986
+ );
2963
2987
  },
2964
2988
  [env]
2965
2989
  );
@@ -3002,15 +3026,21 @@ function useActionService() {
3002
3026
  const runAction = (0, import_react2.useCallback)(
3003
3027
  async ({
3004
3028
  idAction,
3005
- context
3029
+ context,
3030
+ service
3006
3031
  }) => {
3007
3032
  const jsonData = {
3008
3033
  action_id: idAction,
3009
3034
  with_context: { ...context }
3010
3035
  };
3011
- return env.requests.post("/run_action" /* RUN_ACTION_PATH */, jsonData, {
3012
- headers: { "Content-Type": "application/json" }
3013
- });
3036
+ return env.requests.post(
3037
+ "/run_action" /* RUN_ACTION_PATH */,
3038
+ jsonData,
3039
+ {
3040
+ headers: { "Content-Type": "application/json" }
3041
+ },
3042
+ service
3043
+ );
3014
3044
  },
3015
3045
  [env]
3016
3046
  );
@@ -3725,7 +3755,7 @@ function useModelService() {
3725
3755
  });
3726
3756
  }, [env]);
3727
3757
  const getAll = (0, import_react8.useCallback)(
3728
- async ({ data }) => {
3758
+ async ({ data, service }) => {
3729
3759
  const jsonReadGroup = data.type == "calendar" ? { fields: data?.fields } : data.fields && data.fields.length > 0 && data.groupby && data.groupby.length > 0 && data.groupby[0] ? {
3730
3760
  fields: data.fields,
3731
3761
  groupby: data.groupby
@@ -3746,11 +3776,16 @@ function useModelService() {
3746
3776
  ...jsonReadGroup
3747
3777
  }
3748
3778
  };
3749
- return env.requests.post("/call" /* CALL_PATH */, jsonData, {
3750
- headers: {
3751
- "Content-Type": "application/json"
3752
- }
3753
- });
3779
+ return env.requests.post(
3780
+ "/call" /* CALL_PATH */,
3781
+ jsonData,
3782
+ {
3783
+ headers: {
3784
+ "Content-Type": "application/json"
3785
+ }
3786
+ },
3787
+ service
3788
+ );
3754
3789
  },
3755
3790
  [env]
3756
3791
  );
@@ -3818,7 +3853,13 @@ function useModelService() {
3818
3853
  [env]
3819
3854
  );
3820
3855
  const getDetail = (0, import_react8.useCallback)(
3821
- async ({ ids = [], model, specification, context }) => {
3856
+ async ({
3857
+ ids = [],
3858
+ model,
3859
+ specification,
3860
+ context,
3861
+ service
3862
+ }) => {
3822
3863
  const jsonData = {
3823
3864
  model,
3824
3865
  method: "web_read" /* WEB_READ */,
@@ -3828,11 +3869,16 @@ function useModelService() {
3828
3869
  specification
3829
3870
  }
3830
3871
  };
3831
- return env.requests.post("/call" /* CALL_PATH */, jsonData, {
3832
- headers: {
3833
- "Content-Type": "application/json"
3834
- }
3835
- });
3872
+ return env.requests.post(
3873
+ "/call" /* CALL_PATH */,
3874
+ jsonData,
3875
+ {
3876
+ headers: {
3877
+ "Content-Type": "application/json"
3878
+ }
3879
+ },
3880
+ service
3881
+ );
3836
3882
  },
3837
3883
  [env]
3838
3884
  );
@@ -3843,7 +3889,8 @@ function useModelService() {
3843
3889
  data = {},
3844
3890
  specification = {},
3845
3891
  context = {},
3846
- path
3892
+ path,
3893
+ service
3847
3894
  }) => {
3848
3895
  const jsonData = {
3849
3896
  model,
@@ -3855,26 +3902,36 @@ function useModelService() {
3855
3902
  specification
3856
3903
  }
3857
3904
  };
3858
- return env.requests.post(path ?? "/call" /* CALL_PATH */, jsonData, {
3859
- headers: {
3860
- "Content-Type": "application/json"
3861
- }
3862
- });
3905
+ return env.requests.post(
3906
+ path ?? "/call" /* CALL_PATH */,
3907
+ jsonData,
3908
+ {
3909
+ headers: {
3910
+ "Content-Type": "application/json"
3911
+ }
3912
+ },
3913
+ service
3914
+ );
3863
3915
  },
3864
3916
  [env]
3865
3917
  );
3866
3918
  const deleteApi = (0, import_react8.useCallback)(
3867
- async ({ ids = [], model }) => {
3919
+ async ({ ids = [], model, service }) => {
3868
3920
  const jsonData = {
3869
3921
  model,
3870
3922
  method: "unlink" /* UNLINK */,
3871
3923
  ids
3872
3924
  };
3873
- return env.requests.post("/call" /* CALL_PATH */, jsonData, {
3874
- headers: {
3875
- "Content-Type": "application/json"
3876
- }
3877
- });
3925
+ return env.requests.post(
3926
+ "/call" /* CALL_PATH */,
3927
+ jsonData,
3928
+ {
3929
+ headers: {
3930
+ "Content-Type": "application/json"
3931
+ }
3932
+ },
3933
+ service
3934
+ );
3878
3935
  },
3879
3936
  [env]
3880
3937
  );
@@ -3885,7 +3942,8 @@ function useModelService() {
3885
3942
  object,
3886
3943
  specification,
3887
3944
  context,
3888
- fieldChange
3945
+ fieldChange,
3946
+ service
3889
3947
  }) => {
3890
3948
  const jsonData = {
3891
3949
  model,
@@ -3898,25 +3956,36 @@ function useModelService() {
3898
3956
  specification
3899
3957
  ]
3900
3958
  };
3901
- return env.requests.post("/call" /* CALL_PATH */, jsonData, {
3902
- headers: {
3903
- "Content-Type": "application/json"
3904
- }
3905
- });
3959
+ return env.requests.post(
3960
+ "/call" /* CALL_PATH */,
3961
+ jsonData,
3962
+ {
3963
+ headers: {
3964
+ "Content-Type": "application/json"
3965
+ }
3966
+ },
3967
+ service
3968
+ );
3906
3969
  },
3907
3970
  [env]
3908
3971
  );
3909
3972
  const getListFieldsOnchange = (0, import_react8.useCallback)(
3910
- async ({ model }) => {
3973
+ async ({ model, service }) => {
3974
+ console.log("service", service);
3911
3975
  const jsonData = {
3912
3976
  model,
3913
3977
  method: "get_fields_onchange" /* GET_ONCHANGE_FIELDS */
3914
3978
  };
3915
- return env.requests.post("/call" /* CALL_PATH */, jsonData, {
3916
- headers: {
3917
- "Content-Type": "application/json"
3918
- }
3919
- });
3979
+ return env.requests.post(
3980
+ "/call" /* CALL_PATH */,
3981
+ jsonData,
3982
+ {
3983
+ headers: {
3984
+ "Content-Type": "application/json"
3985
+ }
3986
+ },
3987
+ service
3988
+ );
3920
3989
  },
3921
3990
  [env]
3922
3991
  );
@@ -4076,7 +4145,8 @@ function useViewService() {
4076
4145
  views,
4077
4146
  context = {},
4078
4147
  options = {},
4079
- aid
4148
+ aid,
4149
+ service
4080
4150
  }) => {
4081
4151
  const defaultOptions = {
4082
4152
  load_filters: true,
@@ -4092,11 +4162,16 @@ function useViewService() {
4092
4162
  },
4093
4163
  with_context: context
4094
4164
  };
4095
- return env?.requests?.post("/call" /* CALL_PATH */, jsonDataView, {
4096
- headers: {
4097
- "Content-Type": "application/json"
4098
- }
4099
- });
4165
+ return env?.requests?.post(
4166
+ "/call" /* CALL_PATH */,
4167
+ jsonDataView,
4168
+ {
4169
+ headers: {
4170
+ "Content-Type": "application/json"
4171
+ }
4172
+ },
4173
+ service
4174
+ );
4100
4175
  },
4101
4176
  [env]
4102
4177
  );
@@ -4179,7 +4254,7 @@ function useViewService() {
4179
4254
  [env]
4180
4255
  );
4181
4256
  const getSelectionItem = (0, import_react10.useCallback)(
4182
- async ({ data }) => {
4257
+ async ({ data, service }) => {
4183
4258
  const jsonData = {
4184
4259
  model: data.model,
4185
4260
  ids: [],
@@ -4197,11 +4272,16 @@ function useViewService() {
4197
4272
  }
4198
4273
  }
4199
4274
  };
4200
- return env?.requests.post("/call" /* CALL_PATH */, jsonData, {
4201
- headers: {
4202
- "Content-Type": "application/json"
4203
- }
4204
- });
4275
+ return env?.requests.post(
4276
+ "/call" /* CALL_PATH */,
4277
+ jsonData,
4278
+ {
4279
+ headers: {
4280
+ "Content-Type": "application/json"
4281
+ }
4282
+ },
4283
+ service
4284
+ );
4205
4285
  },
4206
4286
  [env]
4207
4287
  );
@@ -4494,7 +4574,6 @@ var sessionStorageUtils = () => {
4494
4574
  // src/configs/axios-client.ts
4495
4575
  var axiosClient = {
4496
4576
  init(config) {
4497
- console.log("config", config);
4498
4577
  const localStorage2 = config?.localStorageUtils ?? localStorageUtils();
4499
4578
  const sessionStorage2 = config?.sessionStorageUtils ?? sessionStorageUtils();
4500
4579
  const db = config?.db;
@@ -4513,25 +4592,21 @@ var axiosClient = {
4513
4592
  };
4514
4593
  const instance = import_axios.default.create({
4515
4594
  adapter: import_axios.default.defaults.adapter,
4516
- baseURL: config.baseUrl,
4595
+ baseURL: config?.baseUrl,
4517
4596
  timeout: 5e4,
4518
4597
  paramsSerializer: (params) => new URLSearchParams(params).toString()
4519
4598
  });
4520
4599
  instance.interceptors.request.use(async (config2) => {
4521
4600
  const { useRefreshToken, useActionToken, actionToken } = config2;
4522
- let token = null;
4523
4601
  if (useActionToken && actionToken) {
4524
- token = actionToken;
4525
- } else {
4526
- const getToken = useRefreshToken ? localStorage2.getRefreshToken : localStorage2.getAccessToken;
4527
- token = await getToken?.();
4528
- }
4529
- if (token) {
4530
- config2.headers["Authorization"] = `Bearer ${token}`;
4602
+ config2.headers["Action-Token"] = actionToken;
4531
4603
  }
4532
4604
  if (database) {
4533
4605
  config2.headers["DATABASE"] = database;
4534
4606
  }
4607
+ const getToken = useRefreshToken ? localStorage2.getRefreshToken : localStorage2.getAccessToken;
4608
+ const token = await getToken?.();
4609
+ if (token) config2.headers["Authorization"] = `Bearer ${token}`;
4535
4610
  return config2;
4536
4611
  }, Promise.reject);
4537
4612
  instance.interceptors.response.use(
@@ -4586,7 +4661,7 @@ var axiosClient = {
4586
4661
  );
4587
4662
  return new Promise(function(resolve) {
4588
4663
  import_axios.default.post(
4589
- `${config.baseUrl}${config.refreshTokenEndpoint ?? "/authentication/oauth2/token" /* AUTH_TOKEN_PATH */}`,
4664
+ `${config?.baseUrl}${config.refreshTokenEndpoint ?? "/authentication/oauth2/token" /* AUTH_TOKEN_PATH */}`,
4590
4665
  payload,
4591
4666
  {
4592
4667
  headers: {
@@ -4654,20 +4729,47 @@ var axiosClient = {
4654
4729
  function formatUrl(url, db2) {
4655
4730
  return url + (db2 ? "?db=" + db2 : "");
4656
4731
  }
4732
+ const getBaseUrl = (baseUrl, serviceName) => {
4733
+ const service = serviceName || config?.default_service;
4734
+ return `${baseUrl.replace(/\/$/, "")}/${service}/api/v2`;
4735
+ };
4657
4736
  const responseBody = (response) => response;
4658
4737
  const requests = {
4659
- get: (url, headers) => instance.get(formatUrl(url, db), headers).then(responseBody),
4660
- post: (url, body, headers) => instance.post(formatUrl(url, db), body, headers).then(responseBody),
4661
- post_excel: (url, body, headers) => instance.post(formatUrl(url, db), body, {
4662
- responseType: "arraybuffer",
4663
- headers: {
4664
- "Content-Type": typeof window !== "undefined" ? "application/json" : "application/javascript",
4665
- Accept: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
4738
+ get: (url, headers, serviceName) => instance.get(
4739
+ formatUrl(getBaseUrl(config?.baseUrl, serviceName) + url, db),
4740
+ headers
4741
+ ).then(responseBody),
4742
+ post: (url, body, headers, serviceName) => instance.post(
4743
+ formatUrl(getBaseUrl(config?.baseUrl, serviceName) + url, db),
4744
+ body,
4745
+ headers
4746
+ ).then(responseBody),
4747
+ post_excel: (url, body, headers, serviceName) => instance.post(
4748
+ formatUrl(getBaseUrl(config?.baseUrl, serviceName) + url, db),
4749
+ body,
4750
+ {
4751
+ responseType: "arraybuffer",
4752
+ headers: {
4753
+ "Content-Type": typeof window !== "undefined" ? "application/json" : "application/javascript",
4754
+ Accept: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
4755
+ ...headers
4756
+ }
4666
4757
  }
4667
- }).then(responseBody),
4668
- put: (url, body, headers) => instance.put(formatUrl(url, db), body, headers).then(responseBody),
4669
- patch: (url, body) => instance.patch(formatUrl(url, db), body).then(responseBody),
4670
- delete: (url, body) => instance.delete(formatUrl(url, db), body).then(responseBody)
4758
+ ).then(responseBody),
4759
+ put: (url, body, headers, serviceName) => instance.put(
4760
+ formatUrl(getBaseUrl(config?.baseUrl, serviceName) + url, db),
4761
+ body,
4762
+ headers
4763
+ ).then(responseBody),
4764
+ patch: (url, body, headers, serviceName) => instance.patch(
4765
+ formatUrl(getBaseUrl(config?.baseUrl, serviceName) + url, db),
4766
+ body,
4767
+ headers
4768
+ ).then(responseBody),
4769
+ delete: (url, headers, serviceName) => instance.delete(
4770
+ formatUrl(getBaseUrl(config?.baseUrl, serviceName) + url, db),
4771
+ headers
4772
+ ).then(responseBody)
4671
4773
  };
4672
4774
  return requests;
4673
4775
  }
@@ -5263,7 +5365,7 @@ var import_react_query32 = require("@tanstack/react-query");
5263
5365
  var useDelete = () => {
5264
5366
  const { deleteApi } = useModelService();
5265
5367
  return (0, import_react_query32.useMutation)({
5266
- mutationFn: ({ ids, model }) => deleteApi({ ids, model })
5368
+ mutationFn: ({ ids, model, service }) => deleteApi({ ids, model, service })
5267
5369
  });
5268
5370
  };
5269
5371
  var use_delete_default = useDelete;
@@ -5326,12 +5428,14 @@ var useGetDetail = () => {
5326
5428
  model,
5327
5429
  ids,
5328
5430
  specification,
5329
- context
5431
+ context,
5432
+ service
5330
5433
  }) => getDetail({
5331
5434
  model,
5332
5435
  ids,
5333
5436
  specification,
5334
- context
5437
+ context,
5438
+ service
5335
5439
  })
5336
5440
  });
5337
5441
  };
@@ -5339,12 +5443,16 @@ var use_get_detail_default = useGetDetail;
5339
5443
 
5340
5444
  // src/hooks/model/use-get-field-onchange.ts
5341
5445
  var import_react_query37 = require("@tanstack/react-query");
5342
- var useGetFieldOnChange = ({ model }) => {
5446
+ var useGetFieldOnChange = ({
5447
+ model,
5448
+ service
5449
+ }) => {
5343
5450
  const { getListFieldsOnchange } = useModelService();
5344
5451
  return (0, import_react_query37.useQuery)({
5345
5452
  queryKey: [`field-onchange-${model}`, model],
5346
5453
  queryFn: () => getListFieldsOnchange({
5347
- model
5454
+ model,
5455
+ service
5348
5456
  }).then((res) => {
5349
5457
  if (res) {
5350
5458
  return res;
@@ -5527,14 +5635,16 @@ var useOnChangeForm = () => {
5527
5635
  specification,
5528
5636
  context,
5529
5637
  object,
5530
- fieldChange
5638
+ fieldChange,
5639
+ service
5531
5640
  }) => onChange({
5532
5641
  ids,
5533
5642
  model,
5534
5643
  specification,
5535
5644
  context,
5536
5645
  object,
5537
- fieldChange
5646
+ fieldChange,
5647
+ service
5538
5648
  })
5539
5649
  });
5540
5650
  };
@@ -5551,8 +5661,9 @@ var useSave = () => {
5551
5661
  data,
5552
5662
  specification,
5553
5663
  context,
5554
- path
5555
- }) => save({ ids, model, data, specification, context, path })
5664
+ path,
5665
+ service
5666
+ }) => save({ ids, model, data, specification, context, path, service })
5556
5667
  });
5557
5668
  };
5558
5669
  var use_save_default = useSave;
@@ -5604,12 +5715,14 @@ var useButton = () => {
5604
5715
  model,
5605
5716
  ids,
5606
5717
  context,
5607
- method
5718
+ method,
5719
+ service
5608
5720
  }) => callButton({
5609
5721
  model,
5610
5722
  ids,
5611
5723
  context,
5612
- method
5724
+ method,
5725
+ service
5613
5726
  }),
5614
5727
  onSuccess: (response) => {
5615
5728
  return response;
@@ -5626,11 +5739,13 @@ var useDuplicateRecord = () => {
5626
5739
  mutationFn: ({
5627
5740
  id,
5628
5741
  model,
5629
- context
5742
+ context,
5743
+ service
5630
5744
  }) => duplicateRecord({
5631
5745
  id,
5632
5746
  model,
5633
- context
5747
+ context,
5748
+ service
5634
5749
  })
5635
5750
  });
5636
5751
  };
@@ -5713,11 +5828,11 @@ var use_get_groups_default = useGetGroups;
5713
5828
 
5714
5829
  // src/hooks/view/use-get-list-data.ts
5715
5830
  var import_react_query49 = require("@tanstack/react-query");
5716
- var useGetListData = (listDataProps, queryKey, enabled) => {
5831
+ var useGetListData = (listDataProps, queryKey, enabled, service) => {
5717
5832
  const { getAll } = useModelService();
5718
5833
  return (0, import_react_query49.useQuery)({
5719
5834
  queryKey,
5720
- queryFn: () => getAll({ data: listDataProps }).then((res) => {
5835
+ queryFn: () => getAll({ data: listDataProps, service }).then((res) => {
5721
5836
  if (res) {
5722
5837
  return res;
5723
5838
  }
@@ -5793,12 +5908,13 @@ var import_react_query53 = require("@tanstack/react-query");
5793
5908
  var useGetSelection = ({
5794
5909
  data,
5795
5910
  queryKey,
5796
- enabled
5911
+ enabled,
5912
+ service
5797
5913
  }) => {
5798
5914
  const { getSelectionItem } = useViewService();
5799
5915
  return (0, import_react_query53.useQuery)({
5800
5916
  queryKey,
5801
- queryFn: () => getSelectionItem({ data }),
5917
+ queryFn: () => getSelectionItem({ data, service }),
5802
5918
  enabled,
5803
5919
  refetchOnWindowFocus: false
5804
5920
  });
@@ -5826,11 +5942,13 @@ var useLoadAction = () => {
5826
5942
  return (0, import_react_query55.useMutation)({
5827
5943
  mutationFn: ({
5828
5944
  idAction,
5829
- context
5945
+ context,
5946
+ service
5830
5947
  }) => {
5831
5948
  return loadAction({
5832
5949
  idAction,
5833
- context
5950
+ context,
5951
+ service
5834
5952
  });
5835
5953
  }
5836
5954
  });
@@ -5871,11 +5989,13 @@ var useRemoveRow = () => {
5871
5989
  mutationFn: ({
5872
5990
  model,
5873
5991
  ids,
5874
- context
5992
+ context,
5993
+ service
5875
5994
  }) => removeRows({
5876
5995
  model,
5877
5996
  ids,
5878
- context
5997
+ context,
5998
+ service
5879
5999
  })
5880
6000
  });
5881
6001
  };
@@ -5906,10 +6026,12 @@ var useRunAction = () => {
5906
6026
  return (0, import_react_query60.useMutation)({
5907
6027
  mutationFn: ({
5908
6028
  idAction,
5909
- context
6029
+ context,
6030
+ service
5910
6031
  }) => runAction({
5911
6032
  idAction,
5912
- context
6033
+ context,
6034
+ service
5913
6035
  })
5914
6036
  });
5915
6037
  };