@hortiview/modulebase 0.0.12333 → 0.0.12628

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.
@@ -0,0 +1,277 @@
1
+ import { R as d, r as l, a as u, b as f, s as p, t as y, c as v, n as b, e as m, i as h, d as S } from "./QueryClientProvider-Q_mWQTzQ.js";
2
+ var q = class extends d {
3
+ #a;
4
+ #n;
5
+ #e;
6
+ #i;
7
+ #t;
8
+ #o;
9
+ #r;
10
+ constructor(t) {
11
+ super(), this.#r = !1, this.#o = t.defaultOptions, this.setOptions(t.options), this.observers = [], this.#i = t.client, this.#e = this.#i.getQueryCache(), this.queryKey = t.queryKey, this.queryHash = t.queryHash, this.#a = F(this.options), this.state = t.state ?? this.#a, this.scheduleGc();
12
+ }
13
+ get meta() {
14
+ return this.options.meta;
15
+ }
16
+ get promise() {
17
+ return this.#t?.promise;
18
+ }
19
+ setOptions(t) {
20
+ this.options = { ...this.#o, ...t }, this.updateGcTime(this.options.gcTime);
21
+ }
22
+ optionalRemove() {
23
+ !this.observers.length && this.state.fetchStatus === "idle" && this.#e.remove(this);
24
+ }
25
+ setData(t, e) {
26
+ const s = l(this.state.data, t, this.options);
27
+ return this.#s({
28
+ data: s,
29
+ type: "success",
30
+ dataUpdatedAt: e?.updatedAt,
31
+ manual: e?.manual
32
+ }), s;
33
+ }
34
+ setState(t, e) {
35
+ this.#s({ type: "setState", state: t, setStateOptions: e });
36
+ }
37
+ cancel(t) {
38
+ const e = this.#t?.promise;
39
+ return this.#t?.cancel(t), e ? e.then(u).catch(u) : Promise.resolve();
40
+ }
41
+ destroy() {
42
+ super.destroy(), this.cancel({ silent: !0 });
43
+ }
44
+ reset() {
45
+ this.destroy(), this.setState(this.#a);
46
+ }
47
+ isActive() {
48
+ return this.observers.some(
49
+ (t) => f(t.options.enabled, this) !== !1
50
+ );
51
+ }
52
+ isDisabled() {
53
+ return this.getObserversCount() > 0 ? !this.isActive() : this.options.queryFn === p || this.state.dataUpdateCount + this.state.errorUpdateCount === 0;
54
+ }
55
+ isStale() {
56
+ return this.state.isInvalidated ? !0 : this.getObserversCount() > 0 ? this.observers.some(
57
+ (t) => t.getCurrentResult().isStale
58
+ ) : this.state.data === void 0;
59
+ }
60
+ isStaleByTime(t = 0) {
61
+ return this.state.isInvalidated || this.state.data === void 0 || !y(this.state.dataUpdatedAt, t);
62
+ }
63
+ onFocus() {
64
+ this.observers.find((e) => e.shouldFetchOnWindowFocus())?.refetch({ cancelRefetch: !1 }), this.#t?.continue();
65
+ }
66
+ onOnline() {
67
+ this.observers.find((e) => e.shouldFetchOnReconnect())?.refetch({ cancelRefetch: !1 }), this.#t?.continue();
68
+ }
69
+ addObserver(t) {
70
+ this.observers.includes(t) || (this.observers.push(t), this.clearGcTimeout(), this.#e.notify({ type: "observerAdded", query: this, observer: t }));
71
+ }
72
+ removeObserver(t) {
73
+ this.observers.includes(t) && (this.observers = this.observers.filter((e) => e !== t), this.observers.length || (this.#t && (this.#r ? this.#t.cancel({ revert: !0 }) : this.#t.cancelRetry()), this.scheduleGc()), this.#e.notify({ type: "observerRemoved", query: this, observer: t }));
74
+ }
75
+ getObserversCount() {
76
+ return this.observers.length;
77
+ }
78
+ invalidate() {
79
+ this.state.isInvalidated || this.#s({ type: "invalidate" });
80
+ }
81
+ fetch(t, e) {
82
+ if (this.state.fetchStatus !== "idle") {
83
+ if (this.state.data !== void 0 && e?.cancelRefetch)
84
+ this.cancel({ silent: !0 });
85
+ else if (this.#t)
86
+ return this.#t.continueRetry(), this.#t.promise;
87
+ }
88
+ if (t && this.setOptions(t), !this.options.queryFn) {
89
+ const i = this.observers.find((a) => a.options.queryFn);
90
+ i && this.setOptions(i.options);
91
+ }
92
+ process.env.NODE_ENV !== "production" && (Array.isArray(this.options.queryKey) || console.error(
93
+ "As of v4, queryKey needs to be an Array. If you are using a string like 'repoData', please change it to an Array, e.g. ['repoData']"
94
+ ));
95
+ const s = new AbortController(), r = (i) => {
96
+ Object.defineProperty(i, "signal", {
97
+ enumerable: !0,
98
+ get: () => (this.#r = !0, s.signal)
99
+ });
100
+ }, c = () => {
101
+ const i = m(this.options, e), a = {
102
+ client: this.#i,
103
+ queryKey: this.queryKey,
104
+ meta: this.meta
105
+ };
106
+ return r(a), this.#r = !1, this.options.persister ? this.options.persister(
107
+ i,
108
+ a,
109
+ this
110
+ ) : i(a);
111
+ }, n = {
112
+ fetchOptions: e,
113
+ options: this.options,
114
+ queryKey: this.queryKey,
115
+ client: this.#i,
116
+ state: this.state,
117
+ fetchFn: c
118
+ };
119
+ r(n), this.options.behavior?.onFetch(
120
+ n,
121
+ this
122
+ ), this.#n = this.state, (this.state.fetchStatus === "idle" || this.state.fetchMeta !== n.fetchOptions?.meta) && this.#s({ type: "fetch", meta: n.fetchOptions?.meta });
123
+ const o = (i) => {
124
+ h(i) && i.silent || this.#s({
125
+ type: "error",
126
+ error: i
127
+ }), h(i) || (this.#e.config.onError?.(
128
+ i,
129
+ this
130
+ ), this.#e.config.onSettled?.(
131
+ this.state.data,
132
+ i,
133
+ this
134
+ )), this.scheduleGc();
135
+ };
136
+ return this.#t = v({
137
+ initialPromise: e?.initialPromise,
138
+ fn: n.fetchFn,
139
+ abort: s.abort.bind(s),
140
+ onSuccess: (i) => {
141
+ if (i === void 0) {
142
+ process.env.NODE_ENV !== "production" && console.error(
143
+ `Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: ${this.queryHash}`
144
+ ), o(new Error(`${this.queryHash} data is undefined`));
145
+ return;
146
+ }
147
+ try {
148
+ this.setData(i);
149
+ } catch (a) {
150
+ o(a);
151
+ return;
152
+ }
153
+ this.#e.config.onSuccess?.(i, this), this.#e.config.onSettled?.(
154
+ i,
155
+ this.state.error,
156
+ this
157
+ ), this.scheduleGc();
158
+ },
159
+ onError: o,
160
+ onFail: (i, a) => {
161
+ this.#s({ type: "failed", failureCount: i, error: a });
162
+ },
163
+ onPause: () => {
164
+ this.#s({ type: "pause" });
165
+ },
166
+ onContinue: () => {
167
+ this.#s({ type: "continue" });
168
+ },
169
+ retry: n.options.retry,
170
+ retryDelay: n.options.retryDelay,
171
+ networkMode: n.options.networkMode,
172
+ canRun: () => !0
173
+ }), this.#t.start();
174
+ }
175
+ #s(t) {
176
+ const e = (s) => {
177
+ switch (t.type) {
178
+ case "failed":
179
+ return {
180
+ ...s,
181
+ fetchFailureCount: t.failureCount,
182
+ fetchFailureReason: t.error
183
+ };
184
+ case "pause":
185
+ return {
186
+ ...s,
187
+ fetchStatus: "paused"
188
+ };
189
+ case "continue":
190
+ return {
191
+ ...s,
192
+ fetchStatus: "fetching"
193
+ };
194
+ case "fetch":
195
+ return {
196
+ ...s,
197
+ ...C(s.data, this.options),
198
+ fetchMeta: t.meta ?? null
199
+ };
200
+ case "success":
201
+ return {
202
+ ...s,
203
+ data: t.data,
204
+ dataUpdateCount: s.dataUpdateCount + 1,
205
+ dataUpdatedAt: t.dataUpdatedAt ?? Date.now(),
206
+ error: null,
207
+ isInvalidated: !1,
208
+ status: "success",
209
+ ...!t.manual && {
210
+ fetchStatus: "idle",
211
+ fetchFailureCount: 0,
212
+ fetchFailureReason: null
213
+ }
214
+ };
215
+ case "error":
216
+ const r = t.error;
217
+ return h(r) && r.revert && this.#n ? { ...this.#n, fetchStatus: "idle" } : {
218
+ ...s,
219
+ error: r,
220
+ errorUpdateCount: s.errorUpdateCount + 1,
221
+ errorUpdatedAt: Date.now(),
222
+ fetchFailureCount: s.fetchFailureCount + 1,
223
+ fetchFailureReason: r,
224
+ fetchStatus: "idle",
225
+ status: "error"
226
+ };
227
+ case "invalidate":
228
+ return {
229
+ ...s,
230
+ isInvalidated: !0
231
+ };
232
+ case "setState":
233
+ return {
234
+ ...s,
235
+ ...t.state
236
+ };
237
+ }
238
+ };
239
+ this.state = e(this.state), b.batch(() => {
240
+ this.observers.forEach((s) => {
241
+ s.onQueryUpdate();
242
+ }), this.#e.notify({ query: this, type: "updated", action: t });
243
+ });
244
+ }
245
+ };
246
+ function C(t, e) {
247
+ return {
248
+ fetchFailureCount: 0,
249
+ fetchFailureReason: null,
250
+ fetchStatus: S(e.networkMode) ? "fetching" : "paused",
251
+ ...t === void 0 && {
252
+ error: null,
253
+ status: "pending"
254
+ }
255
+ };
256
+ }
257
+ function F(t) {
258
+ const e = typeof t.initialData == "function" ? t.initialData() : t.initialData, s = e !== void 0, r = s ? typeof t.initialDataUpdatedAt == "function" ? t.initialDataUpdatedAt() : t.initialDataUpdatedAt : 0;
259
+ return {
260
+ data: e,
261
+ dataUpdateCount: 0,
262
+ dataUpdatedAt: s ? r ?? Date.now() : 0,
263
+ error: null,
264
+ errorUpdateCount: 0,
265
+ errorUpdatedAt: 0,
266
+ fetchFailureCount: 0,
267
+ fetchFailureReason: null,
268
+ fetchMeta: null,
269
+ isInvalidated: !1,
270
+ status: s ? "success" : "pending",
271
+ fetchStatus: "idle"
272
+ };
273
+ }
274
+ export {
275
+ q as Q,
276
+ C as f
277
+ };
@@ -1,6 +1,7 @@
1
1
  import { AppInsightsEvent, AppInsightsException, AppInsightsProperties } from './AppInsights';
2
2
  import { AllDropdownsData, CommonOption } from './CommonOptions';
3
3
  import { DeprecatedBaseProps } from './Deprecated';
4
+ import { AlertServiceBusMessage } from './ServiceBus';
4
5
  import { SystemMessage } from './SystemMessage';
5
6
  /**
6
7
  * Properties that are passed to the Base component by the host application
@@ -25,6 +26,8 @@ export type BaseProps = DeprecatedBaseProps & {
25
26
  currentLanguageId?: string;
26
27
  alertRules?: string;
27
28
  commonOptions?: AllDropdownsData<CommonOption>['items'];
29
+ serviceBusNotification?: (message: AlertServiceBusMessage, //currently only used for alerts
30
+ apiKey: string, queue: string, topic: string) => Promise<unknown>;
28
31
  navigateInHortiview?: (path: string) => void;
29
32
  addBreadcrumbTranslation?: (translation: {
30
33
  key: string;
@@ -8,10 +8,11 @@ export interface HortiViewEnvironments {
8
8
  export interface CustomWindow extends Window {
9
9
  __env__?: HortiViewEnvironments;
10
10
  }
11
- export type Environments = 'DEVELOPMENT' | 'TEST' | 'Bayer-TEST' | 'Bayer-DEMO' | 'Bayer-PROD';
11
+ export type Environments = 'SDC-DEV' | 'SDC-TEST' | 'SDC-DEMO' | 'BAYER-TES' | 'BAYER-DEM' | 'BAYER-STAG' | 'BAYER-PROD';
12
12
  export type EnvConfig = {
13
- [key in Environments]: CustomEnv;
13
+ [key in Environments]?: CustomEnv;
14
14
  };
15
+ export declare const checkConfig: <T extends EnvConfig>(config: T & Record<Exclude<keyof T, Environments>, never>) => T;
15
16
  export type CustomEnv = {
16
17
  [key: string]: string;
17
18
  };
@@ -1 +1,4 @@
1
-
1
+ const e = (c) => c;
2
+ export {
3
+ e as checkConfig
4
+ };
@@ -25,6 +25,19 @@ export interface FarmOrgEntity {
25
25
  } | undefined;
26
26
  id: string;
27
27
  }
28
+ export interface FarmOrganization {
29
+ parentOrganizationId: string | null;
30
+ organizationName: string;
31
+ legalForm: string | null;
32
+ primaryContactId: string;
33
+ secondaryContactId: string | null;
34
+ creatorId: string;
35
+ addressId: string;
36
+ ownerId: string;
37
+ description: string | null;
38
+ address: Address;
39
+ id: string;
40
+ }
28
41
  export type Block = {
29
42
  id: string;
30
43
  fieldId: string;
@@ -32,7 +45,6 @@ export type Block = {
32
45
  shortName?: string;
33
46
  area?: number;
34
47
  fieldPercentage?: number;
35
- tagID?: string;
36
48
  description?: string;
37
49
  length?: number;
38
50
  width?: number;
@@ -55,14 +67,29 @@ export interface Farm {
55
67
  fields: Field[];
56
68
  longitude: number;
57
69
  latitude: number;
70
+ organizationId: string;
71
+ location: string;
72
+ primaryContactId: string;
73
+ secondaryContactId: string;
74
+ address: Address;
58
75
  }
59
76
  export interface Field {
60
- id: string;
77
+ farmId: string;
61
78
  name: string;
62
79
  description: string;
63
- farmId: string;
80
+ fieldTechnologyId: string;
64
81
  fieldCoverageId: string;
65
- blocks: Block[];
82
+ fieldShadingId: string;
83
+ fieldSowingId: string;
84
+ fieldSubstrateId: string;
85
+ length: number | null;
86
+ width: number | null;
87
+ rows: number | null;
88
+ location: string;
89
+ area: number;
90
+ tag: string | null;
91
+ fieldTypeId: string;
92
+ id: string;
66
93
  }
67
94
  export interface Season {
68
95
  id: string;
@@ -90,3 +117,47 @@ export interface BlockPlantLayout {
90
117
  numberOfRows: number;
91
118
  numberOfPlants: number;
92
119
  }
120
+ export interface IrrigationStation {
121
+ irrigationStationName: string;
122
+ farmId: string;
123
+ totalArea: number;
124
+ totalAreaUnit: string;
125
+ flow: number;
126
+ flowUnit: string;
127
+ irrigationZoneFields: IrrigationZoneField[];
128
+ id: string;
129
+ }
130
+ export interface FarmAlertRule {
131
+ farmOrganizationId: string;
132
+ moduleId: string;
133
+ farmId: string;
134
+ description: string;
135
+ descriptionTranslationsAsJson: string;
136
+ raisesNotification: boolean;
137
+ ruleAsJson: string;
138
+ recipients: string[];
139
+ id: string;
140
+ }
141
+ interface IrrigationZoneField {
142
+ fieldId: string;
143
+ irrigationZoneFieldBlocks: IrrigationZoneFieldBlock[];
144
+ id: string;
145
+ }
146
+ interface IrrigationZoneFieldBlock {
147
+ blockId: string;
148
+ id: string;
149
+ }
150
+ interface Address {
151
+ addressLine1: string;
152
+ addressLine2: string | null;
153
+ addressLine3: string | null;
154
+ directions: string | null;
155
+ city: string;
156
+ postalCode: string;
157
+ state: string;
158
+ countryId: string;
159
+ longitude: number;
160
+ latitude: number;
161
+ id: string;
162
+ }
163
+ export {};
@@ -0,0 +1,17 @@
1
+ export type AlertServiceBusMessage = {
2
+ farmOrganizationId: string;
3
+ alertRulesDefinitionId: string;
4
+ farmId: string;
5
+ fieldId: string;
6
+ blockId: string;
7
+ /**
8
+ * needs to be an ID that can be received from the common data/api
9
+ */
10
+ criteriaId: string;
11
+ moduleId: string;
12
+ description: string;
13
+ };
14
+ export type ServiceBusMessage = AlertServiceBusMessage & {
15
+ deviceId: '62ac8dbc-45bc-407d-9fb4-8efe9747abe0';
16
+ scope: 'FarmOrgMembers';
17
+ };
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,97 @@
1
+ import * as n from "react";
2
+ import { g as l } from "./mutation-X73nm7Df.js";
3
+ import { S as d, f as p, h, n as a, u as b } from "./QueryClientProvider-Q_mWQTzQ.js";
4
+ import { n as m, s as f } from "./utils-DxRR_XLb.js";
5
+ var v = class extends d {
6
+ #e;
7
+ #i = void 0;
8
+ #t;
9
+ #s;
10
+ constructor(t, s) {
11
+ super(), this.#e = t, this.setOptions(s), this.bindMethods(), this.#r();
12
+ }
13
+ bindMethods() {
14
+ this.mutate = this.mutate.bind(this), this.reset = this.reset.bind(this);
15
+ }
16
+ setOptions(t) {
17
+ const s = this.options;
18
+ this.options = this.#e.defaultMutationOptions(t), p(this.options, s) || this.#e.getMutationCache().notify({
19
+ type: "observerOptionsUpdated",
20
+ mutation: this.#t,
21
+ observer: this
22
+ }), s?.mutationKey && this.options.mutationKey && h(s.mutationKey) !== h(this.options.mutationKey) ? this.reset() : this.#t?.state.status === "pending" && this.#t.setOptions(this.options);
23
+ }
24
+ onUnsubscribe() {
25
+ this.hasListeners() || this.#t?.removeObserver(this);
26
+ }
27
+ onMutationUpdate(t) {
28
+ this.#r(), this.#n(t);
29
+ }
30
+ getCurrentResult() {
31
+ return this.#i;
32
+ }
33
+ reset() {
34
+ this.#t?.removeObserver(this), this.#t = void 0, this.#r(), this.#n();
35
+ }
36
+ mutate(t, s) {
37
+ return this.#s = s, this.#t?.removeObserver(this), this.#t = this.#e.getMutationCache().build(this.#e, this.options), this.#t.addObserver(this), this.#t.execute(t);
38
+ }
39
+ #r() {
40
+ const t = this.#t?.state ?? l();
41
+ this.#i = {
42
+ ...t,
43
+ isPending: t.status === "pending",
44
+ isSuccess: t.status === "success",
45
+ isError: t.status === "error",
46
+ isIdle: t.status === "idle",
47
+ mutate: this.mutate,
48
+ reset: this.reset
49
+ };
50
+ }
51
+ #n(t) {
52
+ a.batch(() => {
53
+ if (this.#s && this.hasListeners()) {
54
+ const s = this.#i.variables, i = this.#i.context;
55
+ t?.type === "success" ? (this.#s.onSuccess?.(t.data, s, i), this.#s.onSettled?.(t.data, null, s, i)) : t?.type === "error" && (this.#s.onError?.(t.error, s, i), this.#s.onSettled?.(
56
+ void 0,
57
+ t.error,
58
+ s,
59
+ i
60
+ ));
61
+ }
62
+ this.listeners.forEach((s) => {
63
+ s(this.#i);
64
+ });
65
+ });
66
+ }
67
+ };
68
+ function C(t, s) {
69
+ const i = b(), [e] = n.useState(
70
+ () => new v(
71
+ i,
72
+ t
73
+ )
74
+ );
75
+ n.useEffect(() => {
76
+ e.setOptions(t);
77
+ }, [e, t]);
78
+ const r = n.useSyncExternalStore(
79
+ n.useCallback(
80
+ (o) => e.subscribe(a.batchCalls(o)),
81
+ [e]
82
+ ),
83
+ () => e.getCurrentResult(),
84
+ () => e.getCurrentResult()
85
+ ), u = n.useCallback(
86
+ (o, c) => {
87
+ e.mutate(o, c).catch(m);
88
+ },
89
+ [e]
90
+ );
91
+ if (r.error && f(e.options.throwOnError, [r.error]))
92
+ throw r.error;
93
+ return { ...r, mutate: u, mutateAsync: r.mutate };
94
+ }
95
+ export {
96
+ C as u
97
+ };