@hortiview/modulebase 0.0.12119 → 0.0.12550

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.
Files changed (38) hide show
  1. package/dist/QueryClientProvider-Q_mWQTzQ.js +435 -0
  2. package/dist/{_baseGet-Bh5zJ_C8.js → _baseGet-B7FwMMGI.js} +9 -9
  3. package/dist/api-D9Lmqe6S.js +458 -0
  4. package/dist/components/ModuleBase.js +127 -312
  5. package/dist/hooks/useCustom.d.ts +2 -1
  6. package/dist/hooks/useCustom.js +15 -13
  7. package/dist/hooks/useCustomMutation.d.ts +8 -0
  8. package/dist/hooks/useCustomMutation.js +21 -0
  9. package/dist/hooks/useEntity.d.ts +3 -9
  10. package/dist/hooks/useEntity.js +36 -30
  11. package/dist/hooks/useOption.d.ts +1 -1
  12. package/dist/hooks/useOption.js +20 -18
  13. package/dist/hooks/useServiceBus.d.ts +15 -0
  14. package/dist/hooks/useServiceBus.js +17 -0
  15. package/dist/hooks/useStores.d.ts +2 -1
  16. package/dist/hooks/useStores.js +11 -841
  17. package/dist/main.d.ts +3 -0
  18. package/dist/main.js +121 -115
  19. package/dist/mutation-X73nm7Df.js +192 -0
  20. package/dist/omit-B7MWDtHq.js +835 -0
  21. package/dist/query-CRIVoEP7.js +277 -0
  22. package/dist/types/BaseProps.d.ts +3 -0
  23. package/dist/types/ModuleApi.d.ts +77 -4
  24. package/dist/types/Requests.d.ts +2 -1
  25. package/dist/types/ServiceBus.d.ts +17 -0
  26. package/dist/types/ServiceBus.js +1 -0
  27. package/dist/useMutation-3rykrmeD.js +97 -0
  28. package/dist/{useQuery-znAyMQW1.js → useQuery-CwwWze9O.js} +96 -98
  29. package/dist/utils/api.d.ts +20 -0
  30. package/dist/utils/api.js +9 -0
  31. package/dist/utils/baseFetches.d.ts +19 -0
  32. package/dist/utils/baseFetches.js +19 -0
  33. package/dist/utils/fetches.d.ts +31 -22
  34. package/dist/utils/fetches.js +19 -14
  35. package/dist/utils-DxRR_XLb.js +9 -0
  36. package/package.json +2 -2
  37. package/dist/QueryClientProvider-DQv4Y3Qu.js +0 -707
  38. package/dist/fetches-DUCQo_6B.js +0 -477
@@ -1,6 +1,7 @@
1
- export declare const useCustom: <T>({ endpoint, queryKey, token, selector, }: {
1
+ export declare const useCustom: <T>({ endpoint, queryKey, token, selector, enabled }: {
2
2
  endpoint: string;
3
3
  queryKey: (string | undefined)[];
4
4
  token?: string;
5
5
  selector?: (data: any) => T;
6
+ enabled?: boolean;
6
7
  }) => import('@tanstack/react-query').UseQueryResult<T, Error>;
@@ -1,20 +1,22 @@
1
- import { u as m } from "../useQuery-znAyMQW1.js";
2
- import { useBasePropsStore as i } from "../stores/BasePropsStore.js";
3
- import { universalSelector as n } from "../types/Requests.js";
4
- import { d as p } from "../fetches-DUCQo_6B.js";
5
- const d = ({
1
+ import { u as i } from "../useQuery-CwwWze9O.js";
2
+ import { useBasePropsStore as n } from "../stores/BasePropsStore.js";
3
+ import { universalSelector as p } from "../types/Requests.js";
4
+ import { fetchFromCustomApi as a } from "../utils/fetches.js";
5
+ const l = ({
6
6
  endpoint: e,
7
7
  queryKey: t,
8
- token: s,
9
- selector: o
8
+ token: u,
9
+ selector: o,
10
+ enabled: m = !0
10
11
  }) => {
11
- const u = i((r) => r.organizationId);
12
- return m({
13
- queryKey: [...t, u],
14
- queryFn: () => p(e, s),
15
- select: (r) => o ? o(r) : n(r)
12
+ const s = n((r) => r.organizationId);
13
+ return i({
14
+ queryKey: [...t, s],
15
+ queryFn: () => a(e, u),
16
+ select: (r) => o ? o(r) : p(r),
17
+ enabled: m
16
18
  });
17
19
  };
18
20
  export {
19
- d as useCustom
21
+ l as useCustom
20
22
  };
@@ -0,0 +1,8 @@
1
+ import { UseMutationResult } from '@tanstack/react-query';
2
+ import { BaseResponse, httpMethod } from '../types/Requests';
3
+ export declare const useCustomMutation: <Input, Output>({ endpoint, method, token, headers, }: {
4
+ endpoint: string;
5
+ method: Omit<httpMethod, "GET">;
6
+ token?: string;
7
+ headers?: Headers;
8
+ }) => UseMutationResult<BaseResponse<Output>, Error, Input, unknown>;
@@ -0,0 +1,21 @@
1
+ import { u } from "../useMutation-3rykrmeD.js";
2
+ import "../components/ModuleBase.js";
3
+ import "react";
4
+ import "../stores/BasePropsStore.js";
5
+ import "../provider/SignalR/SignalRProvider.js";
6
+ import "../omit-B7MWDtHq.js";
7
+ import "../stores/EnvironmentStore.js";
8
+ import { mutateOnCustomApi as n } from "../utils/fetches.js";
9
+ import "./useEntity.js";
10
+ import "../api-D9Lmqe6S.js";
11
+ const O = ({
12
+ endpoint: t,
13
+ method: o,
14
+ token: m,
15
+ headers: r
16
+ }) => u({
17
+ mutationFn: (i, p) => n(p ?? t, i, o, m, r)
18
+ });
19
+ export {
20
+ O as useCustomMutation
21
+ };
@@ -1,17 +1,11 @@
1
- import { Block, BlockPlantLayout, Farm, FarmOrgEntity, Field, ModuleEntity, Season } from '../types/ModuleApi';
1
+ import { Block, BlockPlantLayout, Farm, FarmAlertRule, FarmOrganization, FarmOrgEntity, Field, IrrigationStation, ModuleEntity, Season } from '../types/ModuleApi';
2
2
  type HortiviewDataAreaGroup = 'FarmOrganization' | 'FarmMember';
3
3
  type ModuleDataAreaGroup = 'ModuleDepended';
4
4
  type FarmOrganizationEntities = 'farms' | 'fields' | 'zones' | 'irrigation_stations' | 'farm_organizations' | 'alert_rules';
5
5
  type FarmMemberEntities = 'farm_members';
6
6
  type ModuleDependendEntities = 'Season' | 'BlockPlantLayout' | (string & {});
7
7
  type HortiviewDataAreaEntity<T extends HortiviewDataAreaGroup | ModuleDataAreaGroup> = T extends 'FarmOrganization' ? FarmOrganizationEntities : T extends 'FarmMember' ? FarmMemberEntities : T extends 'ModuleDepended' ? ModuleDependendEntities : never;
8
- type ResultMap<T extends FarmMemberEntities | FarmOrganizationEntities | ModuleDependendEntities> = T extends 'zones' ? Block : T extends 'fields' ? Field : T extends 'farms' ? Farm : T extends 'irrigation_stations' ? {
9
- id: string;
10
- } : T extends 'farm_organizations' ? {
11
- id: string;
12
- } : T extends 'alert_rules' ? {
13
- id: string;
14
- } : T extends 'Season' ? Season : T extends 'BlockPlantLayout' ? BlockPlantLayout : never;
8
+ type ResultMap<T extends FarmMemberEntities | FarmOrganizationEntities | ModuleDependendEntities> = T extends 'zones' ? Block : T extends 'fields' ? Field : T extends 'farms' ? Farm : T extends 'irrigation_stations' ? IrrigationStation : T extends 'farm_organizations' ? FarmOrganization : T extends 'alert_rules' ? FarmAlertRule : T extends 'Season' ? Season : T extends 'BlockPlantLayout' ? BlockPlantLayout : unknown;
15
9
  export declare const FarmOrgEntitiesTypeResultMap: Record<FarmOrganizationEntities, string>;
16
10
  export declare const FarmMemberEntitiesTypeResultMap: Record<FarmMemberEntities, string>;
17
11
  export declare const ModuleDependedEntityTypeResultMap: Record<ModuleDependendEntities, string>;
@@ -26,7 +20,7 @@ export declare const AllEntitiesTypeResultMap: {
26
20
  farm_organizations: string;
27
21
  alert_rules: string;
28
22
  };
29
- export declare const useEntity: <K extends HortiviewDataAreaGroup | ModuleDataAreaGroup, E extends HortiviewDataAreaEntity<K>>(group: K, entity: E) => {
23
+ export declare const useEntity: <K extends HortiviewDataAreaGroup | ModuleDataAreaGroup, E extends HortiviewDataAreaEntity<K>>(group: K, entity: E, enabled?: boolean) => {
30
24
  data: ResultMap<E>[];
31
25
  error: Error;
32
26
  isError: true;
@@ -1,9 +1,9 @@
1
- import { u as f } from "../useQuery-znAyMQW1.js";
1
+ import { u as l } from "../useQuery-CwwWze9O.js";
2
2
  import { useMemo as g } from "react";
3
- import { useBasePropsStore as l } from "../stores/BasePropsStore.js";
4
- import { universalSelector as p } from "../types/Requests.js";
5
- import { g as b, a as R } from "../fetches-DUCQo_6B.js";
6
- import { useOption as y, useModuleDependency as k } from "./useOption.js";
3
+ import { useBasePropsStore as p } from "../stores/BasePropsStore.js";
4
+ import { universalSelector as y } from "../types/Requests.js";
5
+ import { getModuleDependedEntities as R, getFarmOrgEntities as k } from "../utils/fetches.js";
6
+ import { useOption as E, useModuleDependency as D } from "./useOption.js";
7
7
  const F = {
8
8
  farms: "farm",
9
9
  fields: "field",
@@ -20,39 +20,45 @@ const F = {
20
20
  ...F,
21
21
  ...Q,
22
22
  ...q
23
- }, B = (t, e) => {
24
- const a = l((r) => r.moduleId), o = l((r) => r.organizationId), { data: i } = y("DataAreaGroup"), { data: u } = y("DataAreaEntity"), { data: n } = k(), d = t === "ModuleDepended", E = g(() => {
25
- if (d)
26
- return n ? n.find((s) => s.registeredEntityName === e)?.id : void 0;
27
- if (!i || !u) return;
28
- const r = i.find((s) => s.key === t)?.id;
29
- return r ? u.find((s) => s.description === r && s.value === e)?.id : void 0;
30
- }, [d, i, u, n, e, t]), c = D(a, E, o, d), M = (c.data ?? []).map((r) => {
31
- const m = A[e];
32
- return r[m];
23
+ }, K = (e, t, a = !0) => {
24
+ const o = p((r) => r.moduleId), d = p((r) => r.organizationId), { data: u } = E("DataAreaGroup"), { data: i } = E("DataAreaEntity"), { data: n } = D(e === "ModuleDepended"), m = e === "ModuleDepended", M = g(() => {
25
+ if (m)
26
+ return n ? n.find((s) => s.registeredEntityName === t)?.id : void 0;
27
+ if (!u || !i) return;
28
+ const r = u.find((s) => s.key === e)?.id;
29
+ return r ? i.find((s) => s.description === r && s.value === t)?.id : void 0;
30
+ }, [m, u, i, n, t, e]), f = O(
31
+ o,
32
+ M,
33
+ d,
34
+ m,
35
+ a
36
+ ), b = (f.data ?? []).map((r) => {
37
+ const c = A[t];
38
+ return r[c];
33
39
  });
34
40
  return {
35
- ...c,
36
- data: M
41
+ ...f,
42
+ data: b
37
43
  };
38
- }, D = (t, e, a, o) => {
39
- const i = f({
40
- queryKey: [t, a, e],
41
- queryFn: () => b(t ?? "", e ?? ""),
42
- enabled: o && !!t && !!e && !!a,
43
- select: (n) => p(n)
44
- }), u = f({
45
- queryKey: [t, a, e],
46
- queryFn: () => R(t ?? "", e ?? ""),
47
- enabled: !o && !!t && !!e && !!a,
48
- select: (n) => p(n)
44
+ }, O = (e, t, a, o, d = !0) => {
45
+ const u = l({
46
+ queryKey: [e, a, t],
47
+ queryFn: () => R(e ?? "", t ?? ""),
48
+ enabled: d && o && !!e && !!t && !!a,
49
+ select: (n) => y(n)
50
+ }), i = l({
51
+ queryKey: [e, a, t],
52
+ queryFn: () => k(e ?? "", t ?? ""),
53
+ enabled: d && !o && !!e && !!t && !!a,
54
+ select: (n) => y(n)
49
55
  });
50
- return o ? i : u;
56
+ return o ? u : i;
51
57
  };
52
58
  export {
53
59
  A as AllEntitiesTypeResultMap,
54
60
  Q as FarmMemberEntitiesTypeResultMap,
55
61
  F as FarmOrgEntitiesTypeResultMap,
56
62
  q as ModuleDependedEntityTypeResultMap,
57
- B as useEntity
63
+ K as useEntity
58
64
  };
@@ -14,4 +14,4 @@ import { RegisterOption } from '../types/ModuleApi';
14
14
  * or fetches it from the API. The result is then processed by a universal selector.
15
15
  */
16
16
  export declare const useOption: (dropdown: keyof typeof CommonOptionType) => UseQueryResult<CommonOption[], Error>;
17
- export declare const useModuleDependency: () => UseQueryResult<RegisterOption[], Error>;
17
+ export declare const useModuleDependency: (enabled?: boolean) => UseQueryResult<RegisterOption[], Error>;
@@ -1,23 +1,25 @@
1
- import { u as s } from "../useQuery-znAyMQW1.js";
2
- import { b as u, f as c, c as i } from "../fetches-DUCQo_6B.js";
3
- import { useBasePropsStore as t } from "../stores/BasePropsStore.js";
4
- import { universalSelector as m } from "../types/Requests.js";
5
- const y = (o) => {
6
- const r = t((n) => n.commonOptions), e = u(r, o);
7
- return s({
8
- queryKey: [o],
9
- queryFn: () => e ? Promise.resolve(e) : c(`${o}/dropdown`),
10
- select: (n) => m(n)
1
+ import { u as m } from "../useQuery-CwwWze9O.js";
2
+ import { g as u } from "../api-D9Lmqe6S.js";
3
+ import { useBasePropsStore as n } from "../stores/BasePropsStore.js";
4
+ import { universalSelector as s } from "../types/Requests.js";
5
+ import { fetchFromCommonApi as i, fetchFromModuleApi as c } from "../utils/fetches.js";
6
+ const f = (e) => {
7
+ const r = n((o) => o.commonOptions), t = u(r, e);
8
+ return m({
9
+ queryKey: [e],
10
+ queryFn: () => t ? Promise.resolve(t) : i(`${e}/dropdown`),
11
+ select: (o) => s(o)
11
12
  });
12
- }, f = () => {
13
- const o = t((e) => e.moduleId), r = t((e) => e.organizationId);
14
- return s({
15
- queryKey: [o, r],
16
- queryFn: () => i(`ModuleDependencies/${o}`),
17
- select: (e) => m(e)
13
+ }, g = (e = !0) => {
14
+ const r = n((o) => o.moduleId), t = n((o) => o.organizationId);
15
+ return m({
16
+ queryKey: [r, t],
17
+ queryFn: () => c(`ModuleDependencies/${r}`),
18
+ select: (o) => s(o),
19
+ enabled: e
18
20
  });
19
21
  };
20
22
  export {
21
- f as useModuleDependency,
22
- y as useOption
23
+ g as useModuleDependency,
24
+ f as useOption
23
25
  };
@@ -0,0 +1,15 @@
1
+ import { UseMutationResult } from '@tanstack/react-query';
2
+ import { AlertServiceBusMessage } from '../types/ServiceBus';
3
+ import { BaseResponse } from '../types/Requests';
4
+ /**
5
+ *
6
+ * @param authenticationKey SASToken, that will be provided by the vendor portal of HortiView
7
+ * @param queue url of the service bus queue
8
+ * @param topic topic of the service bus, where the message will be sent to
9
+ * @returns
10
+ */
11
+ export declare const useServiceBus: ({ authenticationKey, queue, topic, }: {
12
+ authenticationKey: string;
13
+ queue: string;
14
+ topic: string;
15
+ }) => UseMutationResult<BaseResponse<unknown>, Error, AlertServiceBusMessage, unknown>;
@@ -0,0 +1,17 @@
1
+ import { u } from "../useMutation-3rykrmeD.js";
2
+ import { useBasePropsStore as t } from "../stores/BasePropsStore.js";
3
+ const f = ({
4
+ authenticationKey: i,
5
+ queue: e,
6
+ topic: s
7
+ }) => {
8
+ const r = t((o) => o.serviceBusNotification), n = t((o) => o.throwError);
9
+ if (!r)
10
+ throw n?.("serviceBusNotification is not defined", 400);
11
+ return u({
12
+ mutationFn: (o) => r(o, i, e, s)
13
+ });
14
+ };
15
+ export {
16
+ f as useServiceBus
17
+ };
@@ -9,6 +9,7 @@ export declare const useBaseProps: () => Pick<import('../types/Deprecated').Depr
9
9
  currentLanguageId?: string;
10
10
  alertRules?: string;
11
11
  commonOptions?: import('../types/CommonOptions').AllDropdownsData<import('../types/CommonOptions').CommonOption>["items"];
12
+ serviceBusNotification?: (message: import('../types/ServiceBus').AlertServiceBusMessage, apiKey: string, queue: string, topic: string) => Promise<unknown>;
12
13
  navigateInHortiview?: (path: string) => void;
13
14
  addBreadcrumbTranslation?: (translation: {
14
15
  key: string;
@@ -21,7 +22,7 @@ export declare const useBaseProps: () => Pick<import('../types/Deprecated').Depr
21
22
  throwError?: (message: string, code: number) => void;
22
23
  } & {
23
24
  setBaseProps: (props: import('../main').BaseProps) => void;
24
- }, keyof import('../types/Deprecated').DeprecatedBaseProps | "modulePermissionToken" | "moduleId" | "organizationId" | "basePath" | "currentNavigationPath" | "sourcePath" | "currentLanguage" | "currentLanguageId" | "alertRules" | "commonOptions" | "navigateInHortiview" | "addBreadcrumbTranslation" | "showSnackbar" | "showMessage" | "logEvent" | "logError" | "throwError">;
25
+ }, keyof import('../types/Deprecated').DeprecatedBaseProps | "modulePermissionToken" | "moduleId" | "organizationId" | "basePath" | "currentNavigationPath" | "sourcePath" | "currentLanguage" | "currentLanguageId" | "alertRules" | "commonOptions" | "serviceBusNotification" | "navigateInHortiview" | "addBreadcrumbTranslation" | "showSnackbar" | "showMessage" | "logEvent" | "logError" | "throwError">;
25
26
  export declare const useConfig: () => Pick<{
26
27
  environment: import('../types/Environment').HortiViewEnvironments;
27
28
  setEnvironment: (environment: import('../types/Environment').HortiViewEnvironments) => void;