@hortiview/modulebase 0.0.16348 → 0.0.20524

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 (65) hide show
  1. package/README.md +3 -2
  2. package/dist/IsRestoringProvider-CBSZo7ur.js +312 -0
  3. package/dist/ModuleCore-DuJVrj6v.js +11828 -0
  4. package/dist/QueryClientProvider-DyiNrPkn.js +514 -0
  5. package/dist/_commonjsHelpers-ByX85dGu.js +33 -0
  6. package/dist/api-COabZnyn.js +147 -0
  7. package/dist/assets/ModuleCore.css +1 -1
  8. package/dist/chunk-LFPYN7LY-D1ls8FXf.js +8643 -0
  9. package/dist/components/ModuleBase.js +9 -9
  10. package/dist/components/ModuleCore.js +9 -14698
  11. package/dist/constants.js +2 -3
  12. package/dist/enum/ActionStorage.js +4 -0
  13. package/dist/hooks/useCustom.js +15 -18
  14. package/dist/hooks/useCustomMutation.js +12 -11
  15. package/dist/hooks/useEntity.js +48 -60
  16. package/dist/hooks/useOffline.js +57 -0
  17. package/dist/hooks/useOption.js +19 -19
  18. package/dist/hooks/useServiceBus.js +1 -1
  19. package/dist/hooks/useStores.js +1 -1
  20. package/dist/{_baseGet-B7FwMMGI.js → isTypedArray-SkhznY1k.js} +496 -496
  21. package/dist/lib/constants.d.ts +0 -1
  22. package/dist/lib/enum/ActionStorage.d.ts +7 -0
  23. package/dist/lib/hooks/useCustom.d.ts +6 -3
  24. package/dist/lib/hooks/useCustomMutation.d.ts +9 -3
  25. package/dist/lib/hooks/useEntity.d.ts +15 -23
  26. package/dist/lib/hooks/useOffline.d.ts +15 -0
  27. package/dist/lib/hooks/useStores.d.ts +10 -2
  28. package/dist/lib/main.d.ts +4 -0
  29. package/dist/lib/types/ActionStorage.d.ts +8 -0
  30. package/dist/lib/types/BaseProps.d.ts +10 -1
  31. package/dist/lib/types/Deprecated.d.ts +4 -0
  32. package/dist/lib/types/Entities.d.ts +22 -0
  33. package/dist/lib/types/Requests.d.ts +0 -17
  34. package/dist/lib/utils/IndexedDbService.d.ts +33 -0
  35. package/dist/lib/utils/api.d.ts +7 -14
  36. package/dist/lib/utils/baseFetches.d.ts +4 -3
  37. package/dist/lib/utils/fetches.d.ts +2 -2
  38. package/dist/lib/utils/helper.d.ts +1 -0
  39. package/dist/main.js +233 -144
  40. package/dist/module-router.js +2322 -121
  41. package/dist/{mutation-CnKIetRs.js → mutation-CmhiEgfA.js} +101 -56
  42. package/dist/{omit-B7MWDtHq.js → omit-Do6MFRwA.js} +240 -223
  43. package/dist/provider/SignalR/SignalRProvider.js +2389 -2824
  44. package/dist/react-c9FSfB30.js +27 -0
  45. package/dist/stores/BasePropsStore.js +1 -1
  46. package/dist/stores/EnvironmentStore.js +1 -1
  47. package/dist/types/ActionStorage.js +1 -0
  48. package/dist/types/Entities.js +25 -0
  49. package/dist/useMutation-Aoachkw_.js +139 -0
  50. package/dist/useQuery-DEU_AUtf.js +392 -0
  51. package/dist/utils/IndexedDbService.js +43 -0
  52. package/dist/utils/api.js +3 -4
  53. package/dist/utils/baseFetches.js +18 -14
  54. package/dist/utils/fetches.js +12 -13
  55. package/dist/utils/helper.js +30 -25
  56. package/package.json +19 -12
  57. package/dist/QueryClientProvider-VtJdNkDw.js +0 -435
  58. package/dist/_commonjsHelpers-BkfeUUK-.js +0 -28
  59. package/dist/api-D9Lmqe6S.js +0 -458
  60. package/dist/chunk-IR6S3I6Y-BmDdD3SP.js +0 -8162
  61. package/dist/query-CFoO2uy7.js +0 -277
  62. package/dist/react-QiIgv49H.js +0 -27
  63. package/dist/useMutation-Num57Ulc.js +0 -97
  64. package/dist/useQuery-XBGd5Kep.js +0 -395
  65. package/dist/utils-DxRR_XLb.js +0 -9
@@ -1,6 +1,5 @@
1
1
  import { BaseProps } from './types/BaseProps';
2
2
  export declare const REQUIRED_PROPS: (keyof BaseProps)[];
3
- export declare const RETRIES = 1;
4
3
  export declare const RETRY_HTTP_STATUS_CODES: {
5
4
  /**
6
5
  * The server timed out waiting for the request.
@@ -0,0 +1,7 @@
1
+ export declare enum ActionState {
2
+ ENQUEUED = "ENQUEUED",
3
+ PENDING = "PENDING",
4
+ RESOLVING = "RESOLVING",
5
+ SUCCESS = "RESOLVED",
6
+ ERROR = "REJECTED"
7
+ }
@@ -1,7 +1,10 @@
1
- export declare const useCustom: <T>({ endpoint, queryKey, token, selector, enabled, }: {
1
+ type UseCustomParams<T> = {
2
2
  endpoint: string;
3
3
  queryKey: (string | undefined)[];
4
4
  token?: string;
5
- selector?: (data: any) => T;
5
+ selector?: (data: unknown) => T;
6
6
  enabled?: boolean;
7
- }) => import('@tanstack/react-query').UseQueryResult<T, Error>;
7
+ noAuth?: boolean;
8
+ };
9
+ export declare const useCustom: <T>({ endpoint, queryKey, token, selector, enabled, noAuth, }: UseCustomParams<T>) => import('@tanstack/react-query').UseQueryResult<import('@tanstack/query-core').NoInfer<T>, Error>;
10
+ export {};
@@ -1,8 +1,14 @@
1
1
  import { UseMutationResult } from '@tanstack/react-query';
2
2
  import { BaseResponse, httpMethod } from '../types/Requests';
3
- export declare const useCustomMutation: <Input, Output>({ endpoint, method, token, headers, }: {
3
+ export type UseCustomMutationParams = {
4
4
  endpoint: string;
5
- method: Omit<httpMethod, "GET">;
5
+ method: Omit<httpMethod, 'GET'>;
6
6
  token?: string;
7
7
  headers?: Headers;
8
- }) => UseMutationResult<BaseResponse<Output>, Error, Input, unknown>;
8
+ noAuth?: boolean;
9
+ };
10
+ export type CustomMutationInput<Input> = {
11
+ input: Input;
12
+ replaceEndpointWith?: string;
13
+ };
14
+ export declare const useCustomMutation: <Input, Output>({ endpoint, method, token, headers, noAuth, }: UseCustomMutationParams) => UseMutationResult<BaseResponse<Output>, Error, CustomMutationInput<Input>, unknown>;
@@ -1,25 +1,5 @@
1
- import { Block, BlockPlantLayout, Farm, FarmAlertRule, FarmOrganization, FarmOrgEntity, Field, IrrigationStation, ModuleEntity, Season } from '../types/ModuleApi';
2
- type HortiviewDataAreaGroup = 'FarmOrganization' | 'FarmMember';
3
- type ModuleDataAreaGroup = 'ModuleDepended';
4
- type FarmOrganizationEntities = 'farms' | 'fields' | 'zones' | 'irrigation_stations' | 'farm_organizations' | 'alert_rules';
5
- type FarmMemberEntities = 'farm_members';
6
- type ModuleDependendEntities = 'Season' | 'BlockPlantLayout' | (string & {});
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' ? IrrigationStation : T extends 'farm_organizations' ? FarmOrganization : T extends 'alert_rules' ? FarmAlertRule : T extends 'Season' ? Season : T extends 'BlockPlantLayout' ? BlockPlantLayout : unknown;
9
- export declare const FarmOrgEntitiesTypeResultMap: Record<FarmOrganizationEntities, string>;
10
- export declare const FarmMemberEntitiesTypeResultMap: Record<FarmMemberEntities, string>;
11
- export declare const ModuleDependedEntityTypeResultMap: Record<ModuleDependendEntities, string>;
12
- export declare const AllEntitiesTypeResultMap: {
13
- Season: string;
14
- BlockPlantLayout: string;
15
- farm_members: string;
16
- farms: string;
17
- fields: string;
18
- zones: string;
19
- irrigation_stations: string;
20
- farm_organizations: string;
21
- alert_rules: string;
22
- };
1
+ import { HortiviewDataAreaEntity, HortiviewDataAreaGroup, ModuleDataAreaGroup, ResultMap } from '../types/Entities';
2
+ import { FarmOrgEntity, ModuleEntity } from '../types/ModuleApi';
23
3
  export declare const useEntity: <K extends HortiviewDataAreaGroup | ModuleDataAreaGroup, E extends HortiviewDataAreaEntity<K>>(group: K, entity: E, enabled?: boolean, shouldGetRawData?: boolean) => {
24
4
  data: ResultMap<E>[];
25
5
  error: Error;
@@ -43,6 +23,7 @@ export declare const useEntity: <K extends HortiviewDataAreaGroup | ModuleDataAr
43
23
  isPaused: boolean;
44
24
  isRefetching: boolean;
45
25
  isStale: boolean;
26
+ isEnabled: boolean;
46
27
  refetch: (options?: import('@tanstack/query-core').RefetchOptions) => Promise<import('@tanstack/query-core').QueryObserverResult<FarmOrgEntity[] | ModuleEntity[], Error>>;
47
28
  fetchStatus: import('@tanstack/query-core').FetchStatus;
48
29
  promise: Promise<FarmOrgEntity[] | ModuleEntity[]>;
@@ -69,6 +50,7 @@ export declare const useEntity: <K extends HortiviewDataAreaGroup | ModuleDataAr
69
50
  isPaused: boolean;
70
51
  isRefetching: boolean;
71
52
  isStale: boolean;
53
+ isEnabled: boolean;
72
54
  refetch: (options?: import('@tanstack/query-core').RefetchOptions) => Promise<import('@tanstack/query-core').QueryObserverResult<FarmOrgEntity[] | ModuleEntity[], Error>>;
73
55
  fetchStatus: import('@tanstack/query-core').FetchStatus;
74
56
  promise: Promise<FarmOrgEntity[] | ModuleEntity[]>;
@@ -95,6 +77,7 @@ export declare const useEntity: <K extends HortiviewDataAreaGroup | ModuleDataAr
95
77
  isPaused: boolean;
96
78
  isRefetching: boolean;
97
79
  isStale: boolean;
80
+ isEnabled: boolean;
98
81
  refetch: (options?: import('@tanstack/query-core').RefetchOptions) => Promise<import('@tanstack/query-core').QueryObserverResult<FarmOrgEntity[] | ModuleEntity[], Error>>;
99
82
  fetchStatus: import('@tanstack/query-core').FetchStatus;
100
83
  promise: Promise<FarmOrgEntity[] | ModuleEntity[]>;
@@ -121,6 +104,7 @@ export declare const useEntity: <K extends HortiviewDataAreaGroup | ModuleDataAr
121
104
  isPaused: boolean;
122
105
  isRefetching: boolean;
123
106
  isStale: boolean;
107
+ isEnabled: boolean;
124
108
  refetch: (options?: import('@tanstack/query-core').RefetchOptions) => Promise<import('@tanstack/query-core').QueryObserverResult<FarmOrgEntity[] | ModuleEntity[], Error>>;
125
109
  fetchStatus: import('@tanstack/query-core').FetchStatus;
126
110
  promise: Promise<FarmOrgEntity[] | ModuleEntity[]>;
@@ -147,6 +131,7 @@ export declare const useEntity: <K extends HortiviewDataAreaGroup | ModuleDataAr
147
131
  isPaused: boolean;
148
132
  isRefetching: boolean;
149
133
  isStale: boolean;
134
+ isEnabled: boolean;
150
135
  refetch: (options?: import('@tanstack/query-core').RefetchOptions) => Promise<import('@tanstack/query-core').QueryObserverResult<FarmOrgEntity[] | ModuleEntity[], Error>>;
151
136
  fetchStatus: import('@tanstack/query-core').FetchStatus;
152
137
  promise: Promise<FarmOrgEntity[] | ModuleEntity[]>;
@@ -173,8 +158,15 @@ export declare const useEntity: <K extends HortiviewDataAreaGroup | ModuleDataAr
173
158
  isPaused: boolean;
174
159
  isRefetching: boolean;
175
160
  isStale: boolean;
161
+ isEnabled: boolean;
176
162
  refetch: (options?: import('@tanstack/query-core').RefetchOptions) => Promise<import('@tanstack/query-core').QueryObserverResult<FarmOrgEntity[] | ModuleEntity[], Error>>;
177
163
  fetchStatus: import('@tanstack/query-core').FetchStatus;
178
164
  promise: Promise<FarmOrgEntity[] | ModuleEntity[]>;
179
165
  };
180
- export {};
166
+ /**
167
+ * Returns a function to get the entity id based on the group and entity name.
168
+ * Needs to return a function to get an entity id out of a list of entities, see useOffline
169
+ * @param group
170
+ * @returns
171
+ */
172
+ export declare const useEntityId: (group: HortiviewDataAreaGroup | ModuleDataAreaGroup) => ((entity: HortiviewDataAreaEntity<typeof group>) => string | undefined);
@@ -0,0 +1,15 @@
1
+ import { HortiviewDataAreaEntity, HortiviewDataAreaGroup, ModuleDataAreaGroup } from '../types/Entities';
2
+ export declare const useOffline: () => {
3
+ prefetchCustom: <T>({ queryKey, endpoint, token, noAuth, }: {
4
+ queryKey: (string | undefined)[];
5
+ endpoint: string;
6
+ token?: string;
7
+ noAuth?: boolean;
8
+ selector?: (data: unknown) => T;
9
+ }) => Promise<void>;
10
+ prefetch: <T>({ queryKey, queryFn, }: {
11
+ queryKey: (string | undefined)[];
12
+ queryFn: () => Promise<T>;
13
+ }) => Promise<void>;
14
+ usePrefetchEntity: <K extends HortiviewDataAreaGroup | ModuleDataAreaGroup, E extends HortiviewDataAreaEntity<K>>(group: K, ...entities: E[]) => "Prefetch failed: no moduleId" | undefined;
15
+ };
@@ -1,4 +1,5 @@
1
1
  export declare const useBaseProps: () => Pick<import('../main').DeprecatedBaseProps & {
2
+ isOnline?: boolean;
2
3
  modulePermissionToken?: string;
3
4
  moduleId?: string;
4
5
  organizationId?: string;
@@ -7,8 +8,8 @@ export declare const useBaseProps: () => Pick<import('../main').DeprecatedBasePr
7
8
  sourcePath?: string | null;
8
9
  currentLanguage?: string;
9
10
  currentLanguageId?: string;
10
- alertRules?: string;
11
11
  commonOptions?: import('../main').AllDropdownsData<import('../main').CommonOption>["items"];
12
+ refreshModulePermissionToken?: () => Promise<string | undefined>;
12
13
  riseNotification?: (message: import('../main').AlertServiceBusMessage) => Promise<unknown>;
13
14
  navigateInHortiview?: (path: string) => void;
14
15
  addBreadcrumbTranslation?: (translation: {
@@ -17,13 +18,20 @@ export declare const useBaseProps: () => Pick<import('../main').DeprecatedBasePr
17
18
  }, hide?: boolean) => void;
18
19
  showSnackbar?: (message: string, icon?: string) => void;
19
20
  showMessage?: (message: import('../main').SystemMessage) => void;
21
+ pendingActions?: import('../main').ActionItem[];
22
+ getPendingActions?: () => import('../main').ActionItem[];
23
+ resolveAction?: (key: string, result?: string) => void;
24
+ startResolvingAction?: (key: string) => void;
25
+ addAction?: (functionName: string, args: unknown[], key?: string) => void;
26
+ getActions?: () => import('../main').ActionItem[];
27
+ getActionByKey?: (key: string) => import('../main').ActionItem | undefined;
20
28
  logEvent?: (event: import('../main').AppInsightsEvent, customProperties?: import('../main').AppInsightsProperties) => void;
21
29
  logError?: (exception: import('../main').AppInsightsException) => void;
22
30
  throwError?: (message: string, code: number) => void;
23
31
  environmentVariables?: import('../main').EnvironmentVariable[];
24
32
  } & {
25
33
  setBaseProps: (props: import('../main').BaseProps) => void;
26
- }, keyof import('../main').DeprecatedBaseProps | "modulePermissionToken" | "moduleId" | "organizationId" | "basePath" | "currentNavigationPath" | "sourcePath" | "currentLanguage" | "currentLanguageId" | "alertRules" | "commonOptions" | "riseNotification" | "navigateInHortiview" | "addBreadcrumbTranslation" | "showSnackbar" | "showMessage" | "logEvent" | "logError" | "throwError" | "environmentVariables">;
34
+ }, keyof import('../main').DeprecatedBaseProps | "isOnline" | "modulePermissionToken" | "moduleId" | "organizationId" | "basePath" | "currentNavigationPath" | "sourcePath" | "currentLanguage" | "currentLanguageId" | "commonOptions" | "refreshModulePermissionToken" | "riseNotification" | "navigateInHortiview" | "addBreadcrumbTranslation" | "showSnackbar" | "showMessage" | "pendingActions" | "getPendingActions" | "resolveAction" | "startResolvingAction" | "addAction" | "getActions" | "getActionByKey" | "logEvent" | "logError" | "throwError" | "environmentVariables">;
27
35
  export declare const useConfig: () => Pick<{
28
36
  environment: import('../main').HortiViewEnvironments;
29
37
  setEnvironment: (environment: import('../main').HortiViewEnvironments) => void;
@@ -10,7 +10,10 @@ export type * from './types/ModuleApi';
10
10
  export type * from './types/Requests';
11
11
  export type * from './types/ServiceBus';
12
12
  export type * from './types/SystemMessage';
13
+ export type * from './types/ActionStorage';
14
+ export * from './enum/ActionStorage';
13
15
  export { useBreadcrumbTranslation } from './hooks/useBreadcrumbTranslation';
16
+ export { useOffline } from './hooks/useOffline';
14
17
  export { useSignalRMessages } from './hooks/useSignalRMessages';
15
18
  export * from './module-router';
16
19
  export { useNavigate } from './module-router';
@@ -20,5 +23,6 @@ export { useCustomMutation } from './hooks/useCustomMutation';
20
23
  export { useEntity } from './hooks/useEntity';
21
24
  export { useOption } from './hooks/useOption';
22
25
  export { useNotification, useServiceBus } from './hooks/useServiceBus';
26
+ export { QueryClient, useInfiniteQuery, useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
23
27
  export { mutateOnCustomApi } from './utils/fetches';
24
28
  export * from './utils/helper';
@@ -0,0 +1,8 @@
1
+ import { ActionState } from '../enum/ActionStorage';
2
+ export type ActionItem = {
3
+ functionName: string;
4
+ args: unknown[];
5
+ dateAdded: string;
6
+ state: ActionState;
7
+ key: string;
8
+ };
@@ -1,3 +1,4 @@
1
+ import { ActionItem } from './ActionStorage';
1
2
  import { AppInsightsEvent, AppInsightsException, AppInsightsProperties } from './AppInsights';
2
3
  import { AllDropdownsData, CommonOption } from './CommonOptions';
3
4
  import { DeprecatedBaseProps } from './Deprecated';
@@ -17,6 +18,7 @@ import { SystemMessage } from './SystemMessage';
17
18
  * @param currentNavigationPath current path of the route, that is changed, when the host application navigates
18
19
  */
19
20
  export type BaseProps = DeprecatedBaseProps & {
21
+ isOnline?: boolean;
20
22
  modulePermissionToken?: string;
21
23
  moduleId?: string;
22
24
  organizationId?: string;
@@ -25,8 +27,8 @@ export type BaseProps = DeprecatedBaseProps & {
25
27
  sourcePath?: string | null;
26
28
  currentLanguage?: string;
27
29
  currentLanguageId?: string;
28
- alertRules?: string;
29
30
  commonOptions?: AllDropdownsData<CommonOption>['items'];
31
+ refreshModulePermissionToken?: () => Promise<string | undefined>;
30
32
  riseNotification?: (message: AlertServiceBusMessage) => Promise<unknown>;
31
33
  navigateInHortiview?: (path: string) => void;
32
34
  addBreadcrumbTranslation?: (translation: {
@@ -35,6 +37,13 @@ export type BaseProps = DeprecatedBaseProps & {
35
37
  }, hide?: boolean) => void;
36
38
  showSnackbar?: (message: string, icon?: string) => void;
37
39
  showMessage?: (message: SystemMessage) => void;
40
+ pendingActions?: ActionItem[];
41
+ getPendingActions?: () => ActionItem[];
42
+ resolveAction?: (key: string, result?: string) => void;
43
+ startResolvingAction?: (key: string) => void;
44
+ addAction?: (functionName: string, args: unknown[], key?: string) => void;
45
+ getActions?: () => ActionItem[];
46
+ getActionByKey?: (key: string) => ActionItem | undefined;
38
47
  logEvent?: (event: AppInsightsEvent, customProperties?: AppInsightsProperties) => void;
39
48
  logError?: (exception: AppInsightsException) => void;
40
49
  throwError?: (message: string, code: number) => void;
@@ -42,6 +42,10 @@ export type DeprecatedBaseProps = {
42
42
  * @deprecated Use `navigateInHortiview` instead
43
43
  */
44
44
  navigateTo?: (path: string) => void;
45
+ /**
46
+ * @deprecated modules need to call their own rules directly
47
+ */
48
+ alertRules?: string;
45
49
  };
46
50
  /**
47
51
  * @deprecated should not be used anymore
@@ -0,0 +1,22 @@
1
+ import { Block, BlockPlantLayout, Farm, FarmAlertRule, FarmOrganization, Field, IrrigationStation, Season } from '../types/ModuleApi';
2
+ export type HortiviewDataAreaGroup = 'FarmOrganization' | 'FarmMember';
3
+ export type ModuleDataAreaGroup = 'ModuleDepended';
4
+ export type FarmOrganizationEntities = 'farms' | 'fields' | 'zones' | 'irrigation_stations' | 'farm_organizations' | 'alert_rules';
5
+ export type FarmMemberEntities = 'farm_members';
6
+ export type ModuleDependendEntities = 'Season' | 'BlockPlantLayout' | (string & {});
7
+ export type HortiviewDataAreaEntity<T extends HortiviewDataAreaGroup | ModuleDataAreaGroup> = T extends 'FarmOrganization' ? FarmOrganizationEntities : T extends 'FarmMember' ? FarmMemberEntities : T extends 'ModuleDepended' ? ModuleDependendEntities : never;
8
+ export 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;
9
+ export declare const FarmOrgEntitiesTypeResultMap: Record<FarmOrganizationEntities, string>;
10
+ export declare const FarmMemberEntitiesTypeResultMap: Record<FarmMemberEntities, string>;
11
+ export declare const ModuleDependedEntityTypeResultMap: Record<ModuleDependendEntities, string>;
12
+ export declare const AllEntitiesTypeResultMap: {
13
+ Season: string;
14
+ BlockPlantLayout: string;
15
+ farm_members: string;
16
+ farms: string;
17
+ fields: string;
18
+ zones: string;
19
+ irrigation_stations: string;
20
+ farm_organizations: string;
21
+ alert_rules: string;
22
+ };
@@ -1,4 +1,3 @@
1
- import { Expand, Filter, Select } from 'odata-query';
2
1
  export type RequestConfig = {
3
2
  redirect: 'follow';
4
3
  credentials: 'omit';
@@ -20,22 +19,6 @@ export type InternalError = {
20
19
  detail: string;
21
20
  stack?: string;
22
21
  };
23
- export type Query = {
24
- filter?: Filter<unknown>;
25
- orderBy?: string[];
26
- expand?: string | string[] | Expand<unknown>;
27
- select?: Select<unknown>;
28
- count?: boolean | Filter<unknown>;
29
- pagination?: Pagination;
30
- top?: number;
31
- skip?: number;
32
- overwrite?: string;
33
- };
34
- export type Pagination = {
35
- top?: number;
36
- skip?: number;
37
- pageSize?: number;
38
- };
39
22
  export type BaseResponse<T> = T | T[] | {
40
23
  value: T | T[];
41
24
  } | {
@@ -0,0 +1,33 @@
1
+ /**
2
+ * The interface for the IndexedDb communication object.
3
+ * It is used in the TanstackQuery Persistent Query Provider.
4
+ *
5
+ * @see TanstackQuery {@link https://tanstack.com/query}
6
+ */
7
+ interface IndexedDbStorage {
8
+ /**
9
+ * the getter takes a key and returns the value behind the key from the IndexedDB
10
+ * @param key
11
+ * @returns a Promise containing the data behind the key or null
12
+ */
13
+ getItem: (key: string) => Promise<string | undefined | null>;
14
+ /**
15
+ * the setter adds some values to the IndexedDB with the given key as the key in the IndexedDB.
16
+ * @param key
17
+ * @returns
18
+ */
19
+ setItem: (key: string, value: string) => Promise<unknown>;
20
+ /**
21
+ * the remove fundtion takes a key and deletes the value behind the key from the IndexedDB
22
+ * @param key
23
+ * @returns
24
+ */
25
+ removeItem: (key: string) => Promise<void>;
26
+ }
27
+ /**
28
+ * This object is the implementation of the {@link IndexedDbStorage} interface using the idb-keyval package
29
+ *
30
+ * @see idb-keyval {@link https://www.npmjs.com/package/idb-keyval?activeTab=readme}
31
+ */
32
+ export declare const indexedDbStorage: IndexedDbStorage;
33
+ export {};
@@ -1,20 +1,13 @@
1
- import { BaseResponse, httpMethod, Query, RequestConfig } from '../types/Requests';
2
- export declare const getConfig: (token: string, organizationId?: string, languageId?: string, method?: httpMethod, customHeaders?: Headers) => RequestConfig;
1
+ import { BaseResponse, httpMethod, RequestConfig } from '../types/Requests';
2
+ export declare const getConfig: (token?: string, organizationId?: string, languageId?: string, method?: httpMethod, customHeaders?: Headers) => RequestConfig;
3
3
  /**
4
- * a fetch function to handle requests and returns the response. if the response is unauthorized, it tries to refresh the token and retries the request
4
+ * a fetch function to handle requests and returns the response. if the response is unauthorized, it tries to refresh the module permission token and retries the request.
5
+ * During the refresh process, all the incoming requests will be put on hold (sleep) until the process is finished to prevent multiple parallel token refresh calls.
6
+ * if the token refresh fails, all the incoming requests will throw an unauthorized error until a successful token refresh happens.
5
7
  * @param url - the complete url build by {@link prependBaseUrl}
6
8
  * @param config - the request config including auth headers
7
- * @param throwFullMessage - if the full error message should be thrown or only the message behind the status code
8
- * @param withResponseHandling - if the response should be handled by the {@link handleResponse} method or not ("hide" the error)
9
- * @param tries - the number of retries, default is 1
9
+ * @param isRetryEnabled - if the request should be retried on network errors or specific HTTP status codes
10
10
  * @returns
11
11
  */
12
- export declare const fetchWithErrorHandling: <T>(url: string, config: RequestConfig, tries?: number, withResponseHandling?: boolean) => Promise<BaseResponse<T>>;
12
+ export declare const fetchWithErrorHandling: <T>(url: string, config: RequestConfig, isRetryEnabled?: boolean) => Promise<BaseResponse<T>>;
13
13
  export declare const handleResponse: (response: Response) => Promise<any>;
14
- /**
15
- * a helper function to format the query string
16
- * @param query - the query object to format
17
- * @param withApiVersion - if the api version should be added to the query string
18
- * @returns
19
- */
20
- export declare const formatQuery: (query?: Query, withApiVersion?: boolean) => string;
@@ -1,4 +1,4 @@
1
- import { BaseResponse, httpMethod, Query } from '../types/Requests';
1
+ import { BaseResponse, httpMethod } from '../types/Requests';
2
2
  /**
3
3
  * a fetch function to handle CUD requests and returns the response.
4
4
  * @param url endpoint to fetch (CUD) data from
@@ -8,7 +8,7 @@ import { BaseResponse, httpMethod, Query } from '../types/Requests';
8
8
  * @param headers (optional) custom headers to use
9
9
  * @returns Promise<BaseResponse<R>> response from the fetch
10
10
  */
11
- export declare const baseMutation: <T, R>(url: string, data: T, method: Omit<httpMethod, "GET">, customToken?: string, headers?: Headers) => Promise<BaseResponse<R>>;
11
+ export declare const baseMutation: <T, R>(url: string, data: T, method: Omit<httpMethod, "GET">, customToken?: string, headers?: Headers, noAuth?: boolean) => Promise<BaseResponse<R>>;
12
12
  /**
13
13
  * a fetch function to handle GET requests and returns the response.
14
14
  * @param url url to GET data from
@@ -16,4 +16,5 @@ export declare const baseMutation: <T, R>(url: string, data: T, method: Omit<htt
16
16
  * @param customToken token to use (default is the modulePermissionToken)
17
17
  * @returns Promise<BaseResponse<T>> response from the fetch
18
18
  */
19
- export declare const baseFetch: <T>(url: string, query: Query, customToken?: string) => Promise<BaseResponse<T>>;
19
+ export declare const baseFetch: <T>(url: string, //endpoint to fetch modulApi/getEntities/{moduleId}
20
+ customToken?: string, noAuth?: boolean) => Promise<BaseResponse<T>>;
@@ -1,5 +1,5 @@
1
1
  import { httpMethod } from '../types/Requests';
2
- export declare const mutateOnCustomApi: <T, R>(endpoint: string, data: T, method?: Omit<httpMethod, "GET">, token?: string, headers?: Headers) => Promise<import('../main').BaseResponse<R>>;
2
+ export declare const mutateOnCustomApi: <T, R>(endpoint: string, data: T, method?: Omit<httpMethod, "GET">, token?: string, headers?: Headers, noAuth?: boolean) => Promise<import('../main').BaseResponse<R>>;
3
3
  /**
4
4
  * a fetch function to get a certain farmorganization entity from the moduleApi (will be used in useEntity)
5
5
  * @param moduleId moduleID to get the entity from
@@ -28,7 +28,7 @@ export declare const getModuleDependedEntitiesRaw: <T>(moduleId: string, entityI
28
28
  * @param token token to use (default is the modulePermissionToken)
29
29
  * @returns Promise<BaseResponse<T>> response from the fetch
30
30
  */
31
- export declare const fetchFromCustomApi: <T>(endpoint: string, token?: string) => Promise<import('../main').BaseResponse<T>>;
31
+ export declare const fetchFromCustomApi: <T>(endpoint: string, token?: string, noAuth?: boolean) => Promise<import('../main').BaseResponse<T>>;
32
32
  /**
33
33
  * a fetch function to handle GET requests and returns the response.
34
34
  * @param endpoint endpoint of moduleApi to fetch data from
@@ -26,3 +26,4 @@ export declare const checkVersion: (environmentVariables?: HortiViewEnvironments
26
26
  */
27
27
  export declare const universalSelector: <T>(data: BaseResponse<T>) => T | T[];
28
28
  export declare const checkConfig: <T extends EnvConfig>(config: T & Record<Exclude<keyof T, Environments>, never>) => T;
29
+ export declare const getModuleQueryKey: (queryKey: (string | undefined)[]) => (string | undefined)[];