@hortiview/modulebase 0.0.12109 → 0.0.12333

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.
@@ -53,6 +53,8 @@ export interface Farm {
53
53
  farmName: string;
54
54
  description: string;
55
55
  fields: Field[];
56
+ longitude: number;
57
+ latitude: number;
56
58
  }
57
59
  export interface Field {
58
60
  id: string;
@@ -3,7 +3,7 @@ export type RequestConfig = {
3
3
  redirect: "follow";
4
4
  credentials: "omit";
5
5
  headers: RequestHeader;
6
- method: "GET" | "POST" | "PATCH" | "DELETE" | "PUT";
6
+ method: httpMethod;
7
7
  body?: string | FormData;
8
8
  };
9
9
  export type RequestHeader = Headers & {
@@ -47,3 +47,4 @@ export type BaseResponse<T> = T | T[] | {
47
47
  * @returns
48
48
  */
49
49
  export declare const universalSelector: <T>(data: BaseResponse<T>) => T | T[];
50
+ export type httpMethod = 'POST' | 'PATCH' | 'DELETE' | 'PUT' | 'GET';
@@ -1,7 +1,7 @@
1
- import { S as N, l as U, q as f, t as w, r as O, b as z, u as Q, v as M, w as V, g as q, x as W, y as _, n as B, z as K } from "./QueryClientProvider-DQv4Y3Qu.js";
1
+ import { S as N, q as U, t as f, s as E, r as O, d as H, v as Q, w as M, x as V, i as z, y as W, z as k, n as A, u as $ } from "./QueryClientProvider-QWqHaM3I.js";
2
2
  import * as p from "react";
3
3
  import "react/jsx-runtime";
4
- var $ = class extends N {
4
+ var K = class extends N {
5
5
  constructor(e, t) {
6
6
  super(), this.options = t, this.#s = e, this.#r = null, this.#i = U(), this.options.experimental_prefetchInRender || this.#i.reject(
7
7
  new Error("experimental_prefetchInRender feature flag is not enabled")
@@ -15,20 +15,20 @@ var $ = class extends N {
15
15
  #c;
16
16
  #i;
17
17
  #r;
18
- #b;
18
+ #y;
19
19
  #l;
20
20
  // This property keeps track of the last query with defined data.
21
21
  // It will be used to pass the previous data and query to the placeholder function between renders.
22
22
  #d;
23
- #h;
24
23
  #o;
24
+ #h;
25
25
  #n;
26
26
  #f = /* @__PURE__ */ new Set();
27
27
  bindMethods() {
28
28
  this.refetch = this.refetch.bind(this);
29
29
  }
30
30
  onSubscribe() {
31
- this.listeners.size === 1 && (this.#e.addObserver(this), k(this.#e, this.options) ? this.#u() : this.updateResult(), this.#m());
31
+ this.listeners.size === 1 && (this.#e.addObserver(this), _(this.#e, this.options) ? this.#u() : this.updateResult(), this.#R());
32
32
  }
33
33
  onUnsubscribe() {
34
34
  this.hasListeners() || this.destroy();
@@ -56,20 +56,20 @@ var $ = class extends N {
56
56
  throw new Error(
57
57
  "Expected enabled to be a boolean or a callback that returns a boolean"
58
58
  );
59
- this.#C(), this.#e.setOptions(this.options), s._defaulted && !w(this.options, s) && this.#s.getQueryCache().notify({
59
+ this.#C(), this.#e.setOptions(this.options), s._defaulted && !E(this.options, s) && this.#s.getQueryCache().notify({
60
60
  type: "observerOptionsUpdated",
61
61
  query: this.#e,
62
62
  observer: this
63
63
  });
64
64
  const a = this.hasListeners();
65
- a && L(
65
+ a && q(
66
66
  this.#e,
67
67
  r,
68
68
  this.options,
69
69
  s
70
- ) && this.#u(), this.updateResult(t), a && (this.#e !== r || f(this.options.enabled, this.#e) !== f(s.enabled, this.#e) || O(this.options.staleTime, this.#e) !== O(s.staleTime, this.#e)) && this.#y();
71
- const u = this.#R();
72
- a && (this.#e !== r || f(this.options.enabled, this.#e) !== f(s.enabled, this.#e) || u !== this.#n) && this.#g(u);
70
+ ) && this.#u(), this.updateResult(t), a && (this.#e !== r || f(this.options.enabled, this.#e) !== f(s.enabled, this.#e) || O(this.options.staleTime, this.#e) !== O(s.staleTime, this.#e)) && this.#b();
71
+ const u = this.#g();
72
+ a && (this.#e !== r || f(this.options.enabled, this.#e) !== f(s.enabled, this.#e) || u !== this.#n) && this.#m(u);
73
73
  }
74
74
  getOptimisticResult(e) {
75
75
  const t = this.#s.getQueryCache().build(this.#s, e), s = this.createResult(t, e);
@@ -115,9 +115,9 @@ var $ = class extends N {
115
115
  this.options,
116
116
  e
117
117
  );
118
- return e?.throwOnError || (t = t.catch(z)), t;
118
+ return e?.throwOnError || (t = t.catch(H)), t;
119
119
  }
120
- #y() {
120
+ #b() {
121
121
  this.#v();
122
122
  const e = O(
123
123
  this.options.staleTime,
@@ -126,77 +126,77 @@ var $ = class extends N {
126
126
  if (Q || this.#t.isStale || !M(e))
127
127
  return;
128
128
  const s = V(this.#t.dataUpdatedAt, e) + 1;
129
- this.#h = setTimeout(() => {
129
+ this.#o = setTimeout(() => {
130
130
  this.#t.isStale || this.updateResult();
131
131
  }, s);
132
132
  }
133
- #R() {
133
+ #g() {
134
134
  return (typeof this.options.refetchInterval == "function" ? this.options.refetchInterval(this.#e) : this.options.refetchInterval) ?? !1;
135
135
  }
136
- #g(e) {
137
- this.#O(), this.#n = e, !(Q || f(this.options.enabled, this.#e) === !1 || !M(this.#n) || this.#n === 0) && (this.#o = setInterval(() => {
138
- (this.options.refetchIntervalInBackground || q.isFocused()) && this.#u();
136
+ #m(e) {
137
+ this.#O(), this.#n = e, !(Q || f(this.options.enabled, this.#e) === !1 || !M(this.#n) || this.#n === 0) && (this.#h = setInterval(() => {
138
+ (this.options.refetchIntervalInBackground || z.isFocused()) && this.#u();
139
139
  }, this.#n));
140
140
  }
141
- #m() {
142
- this.#y(), this.#g(this.#R());
141
+ #R() {
142
+ this.#b(), this.#m(this.#g());
143
143
  }
144
144
  #v() {
145
- this.#h && (clearTimeout(this.#h), this.#h = void 0);
145
+ this.#o && (clearTimeout(this.#o), this.#o = void 0);
146
146
  }
147
147
  #O() {
148
- this.#o && (clearInterval(this.#o), this.#o = void 0);
148
+ this.#h && (clearInterval(this.#h), this.#h = void 0);
149
149
  }
150
150
  createResult(e, t) {
151
- const s = this.#e, r = this.options, a = this.#t, u = this.#a, i = this.#c, h = e !== s ? e.state : this.#p, { state: c } = e;
152
- let n = { ...c }, m = !1, l;
151
+ const s = this.#e, r = this.options, a = this.#t, u = this.#a, i = this.#c, o = e !== s ? e.state : this.#p, { state: c } = e;
152
+ let n = { ...c }, R = !1, l;
153
153
  if (t._optimisticResults) {
154
- const o = this.hasListeners(), y = !o && k(e, t), R = o && L(e, s, t, r);
155
- (y || R) && (n = {
154
+ const h = this.hasListeners(), b = !h && _(e, t), g = h && q(e, s, t, r);
155
+ (b || g) && (n = {
156
156
  ...n,
157
157
  ...W(c.data, e.options)
158
158
  }), t._optimisticResults === "isRestoring" && (n.fetchStatus = "idle");
159
159
  }
160
- let { error: x, errorUpdatedAt: F, status: b } = n;
160
+ let { error: x, errorUpdatedAt: F, status: y } = n;
161
161
  if (t.select && n.data !== void 0)
162
- if (a && n.data === u?.data && t.select === this.#b)
162
+ if (a && n.data === u?.data && t.select === this.#y)
163
163
  l = this.#l;
164
164
  else
165
165
  try {
166
- this.#b = t.select, l = t.select(n.data), l = _(a?.data, l, t), this.#l = l, this.#r = null;
167
- } catch (o) {
168
- this.#r = o;
166
+ this.#y = t.select, l = t.select(n.data), l = k(a?.data, l, t), this.#l = l, this.#r = null;
167
+ } catch (h) {
168
+ this.#r = h;
169
169
  }
170
170
  else
171
171
  l = n.data;
172
- if (t.placeholderData !== void 0 && l === void 0 && b === "pending") {
173
- let o;
172
+ if (t.placeholderData !== void 0 && l === void 0 && y === "pending") {
173
+ let h;
174
174
  if (a?.isPlaceholderData && t.placeholderData === i?.placeholderData)
175
- o = a.data;
176
- else if (o = typeof t.placeholderData == "function" ? t.placeholderData(
175
+ h = a.data;
176
+ else if (h = typeof t.placeholderData == "function" ? t.placeholderData(
177
177
  this.#d?.state.data,
178
178
  this.#d
179
- ) : t.placeholderData, t.select && o !== void 0)
179
+ ) : t.placeholderData, t.select && h !== void 0)
180
180
  try {
181
- o = t.select(o), this.#r = null;
182
- } catch (y) {
183
- this.#r = y;
181
+ h = t.select(h), this.#r = null;
182
+ } catch (b) {
183
+ this.#r = b;
184
184
  }
185
- o !== void 0 && (b = "success", l = _(
185
+ h !== void 0 && (y = "success", l = k(
186
186
  a?.data,
187
- o,
187
+ h,
188
188
  t
189
- ), m = !0);
189
+ ), R = !0);
190
190
  }
191
- this.#r && (x = this.#r, l = this.#l, F = Date.now(), b = "error");
192
- const C = n.fetchStatus === "fetching", S = b === "pending", E = b === "error", P = S && C, D = l !== void 0, d = {
193
- status: b,
191
+ this.#r && (x = this.#r, l = this.#l, F = Date.now(), y = "error");
192
+ const C = n.fetchStatus === "fetching", S = y === "pending", w = y === "error", D = S && C, P = l !== void 0, d = {
193
+ status: y,
194
194
  fetchStatus: n.fetchStatus,
195
195
  isPending: S,
196
- isSuccess: b === "success",
197
- isError: E,
198
- isInitialLoading: P,
199
- isLoading: P,
196
+ isSuccess: y === "success",
197
+ isError: w,
198
+ isInitialLoading: D,
199
+ isLoading: D,
200
200
  data: l,
201
201
  dataUpdatedAt: n.dataUpdatedAt,
202
202
  error: x,
@@ -205,33 +205,33 @@ var $ = class extends N {
205
205
  failureReason: n.fetchFailureReason,
206
206
  errorUpdateCount: n.errorUpdateCount,
207
207
  isFetched: n.dataUpdateCount > 0 || n.errorUpdateCount > 0,
208
- isFetchedAfterMount: n.dataUpdateCount > h.dataUpdateCount || n.errorUpdateCount > h.errorUpdateCount,
208
+ isFetchedAfterMount: n.dataUpdateCount > o.dataUpdateCount || n.errorUpdateCount > o.errorUpdateCount,
209
209
  isFetching: C,
210
210
  isRefetching: C && !S,
211
- isLoadingError: E && !D,
211
+ isLoadingError: w && !P,
212
212
  isPaused: n.fetchStatus === "paused",
213
- isPlaceholderData: m,
214
- isRefetchError: E && D,
213
+ isPlaceholderData: R,
214
+ isRefetchError: w && P,
215
215
  isStale: I(e, t),
216
216
  refetch: this.refetch,
217
217
  promise: this.#i
218
218
  };
219
219
  if (this.options.experimental_prefetchInRender) {
220
- const o = (v) => {
220
+ const h = (v) => {
221
221
  d.status === "error" ? v.reject(d.error) : d.data !== void 0 && v.resolve(d.data);
222
- }, y = () => {
222
+ }, b = () => {
223
223
  const v = this.#i = d.promise = U();
224
- o(v);
225
- }, R = this.#i;
226
- switch (R.status) {
224
+ h(v);
225
+ }, g = this.#i;
226
+ switch (g.status) {
227
227
  case "pending":
228
- e.queryHash === s.queryHash && o(R);
228
+ e.queryHash === s.queryHash && h(g);
229
229
  break;
230
230
  case "fulfilled":
231
- (d.status === "error" || d.data !== R.value) && y();
231
+ (d.status === "error" || d.data !== g.value) && b();
232
232
  break;
233
233
  case "rejected":
234
- (d.status !== "error" || d.error !== R.reason) && y();
234
+ (d.status !== "error" || d.error !== g.reason) && b();
235
235
  break;
236
236
  }
237
237
  }
@@ -239,7 +239,7 @@ var $ = class extends N {
239
239
  }
240
240
  updateResult(e) {
241
241
  const t = this.#t, s = this.createResult(this.#e, this.options);
242
- if (this.#a = this.#e.state, this.#c = this.options, this.#a.data !== void 0 && (this.#d = this.#e), w(s, t))
242
+ if (this.#a = this.#e.state, this.#c = this.options, this.#a.data !== void 0 && (this.#d = this.#e), E(s, t))
243
243
  return;
244
244
  this.#t = s;
245
245
  const r = {}, a = () => {
@@ -248,12 +248,12 @@ var $ = class extends N {
248
248
  const { notifyOnChangeProps: u } = this.options, i = typeof u == "function" ? u() : u;
249
249
  if (i === "all" || !i && !this.#f.size)
250
250
  return !0;
251
- const g = new Set(
251
+ const m = new Set(
252
252
  i ?? this.#f
253
253
  );
254
- return this.options.throwOnError && g.add("error"), Object.keys(this.#t).some((h) => {
255
- const c = h;
256
- return this.#t[c] !== t[c] && g.has(c);
254
+ return this.options.throwOnError && m.add("error"), Object.keys(this.#t).some((o) => {
255
+ const c = o;
256
+ return this.#t[c] !== t[c] && m.has(c);
257
257
  });
258
258
  };
259
259
  e?.listeners !== !1 && a() && (r.listeners = !0), this.#S({ ...r, ...e });
@@ -266,10 +266,10 @@ var $ = class extends N {
266
266
  this.#e = e, this.#p = e.state, this.hasListeners() && (t?.removeObserver(this), e.addObserver(this));
267
267
  }
268
268
  onQueryUpdate() {
269
- this.updateResult(), this.hasListeners() && this.#m();
269
+ this.updateResult(), this.hasListeners() && this.#R();
270
270
  }
271
271
  #S(e) {
272
- B.batch(() => {
272
+ A.batch(() => {
273
273
  e.listeners && this.listeners.forEach((t) => {
274
274
  t(this.#t);
275
275
  }), this.#s.getQueryCache().notify({
@@ -282,7 +282,7 @@ var $ = class extends N {
282
282
  function G(e, t) {
283
283
  return f(t.enabled, e) !== !1 && e.state.data === void 0 && !(e.state.status === "error" && t.retryOnMount === !1);
284
284
  }
285
- function k(e, t) {
285
+ function _(e, t) {
286
286
  return G(e, t) || e.state.data !== void 0 && T(e, t, t.refetchOnMount);
287
287
  }
288
288
  function T(e, t, s) {
@@ -292,17 +292,17 @@ function T(e, t, s) {
292
292
  }
293
293
  return !1;
294
294
  }
295
- function L(e, t, s, r) {
295
+ function q(e, t, s, r) {
296
296
  return (e !== t || f(r.enabled, e) === !1) && (!s.suspense || e.state.status !== "error") && I(e, s);
297
297
  }
298
298
  function I(e, t) {
299
299
  return f(t.enabled, e) !== !1 && e.isStaleByTime(O(t.staleTime, e));
300
300
  }
301
301
  function J(e, t) {
302
- return !w(e.getCurrentResult(), t);
302
+ return !E(e.getCurrentResult(), t);
303
303
  }
304
- var H = p.createContext(!1), X = () => p.useContext(H);
305
- H.Provider;
304
+ var B = p.createContext(!1), X = () => p.useContext(B);
305
+ B.Provider;
306
306
  function Y() {
307
307
  let e = !1;
308
308
  return {
@@ -319,7 +319,7 @@ var Z = p.createContext(Y()), ee = () => p.useContext(Z);
319
319
  function te(e, t) {
320
320
  return typeof e == "function" ? e(...t) : !!e;
321
321
  }
322
- function j() {
322
+ function L() {
323
323
  }
324
324
  var se = (e, t) => {
325
325
  (e.suspense || e.throwOnError || e.experimental_prefetchInRender) && (t.isReset() || (e.retryOnMount = !1));
@@ -336,38 +336,40 @@ var se = (e, t) => {
336
336
  }) => e.isError && !t.isReset() && !e.isFetching && r && (a && e.data === void 0 || te(s, [e.error, r])), ne = (e) => {
337
337
  const t = e.staleTime;
338
338
  e.suspense && (e.staleTime = typeof t == "function" ? (...s) => Math.max(t(...s), 1e3) : Math.max(t ?? 1e3, 1e3), typeof e.gcTime == "number" && (e.gcTime = Math.max(e.gcTime, 1e3)));
339
- }, ae = (e, t) => e.isLoading && e.isFetching && !t, he = (e, t) => e?.suspense && t.isPending, A = (e, t, s) => t.fetchOptimistic(e).catch(() => {
339
+ }, ae = (e, t) => e.isLoading && e.isFetching && !t, oe = (e, t) => e?.suspense && t.isPending, j = (e, t, s) => t.fetchOptimistic(e).catch(() => {
340
340
  s.clearReset();
341
341
  });
342
- function oe(e, t, s) {
342
+ function he(e, t, s) {
343
343
  if (process.env.NODE_ENV !== "production" && (typeof e != "object" || Array.isArray(e)))
344
344
  throw new Error(
345
345
  'Bad argument type. Starting with v5, only the "Object" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object'
346
346
  );
347
- const r = K(), a = X(), u = ee(), i = r.defaultQueryOptions(e);
347
+ const r = $(), a = X(), u = ee(), i = r.defaultQueryOptions(e);
348
348
  r.getDefaultOptions().queries?._experimental_beforeQuery?.(
349
349
  i
350
- ), i._optimisticResults = a ? "isRestoring" : "optimistic", ne(i), se(i, u), re(u);
351
- const g = !r.getQueryCache().get(i.queryHash), [h] = p.useState(
350
+ ), process.env.NODE_ENV !== "production" && (i.queryFn || console.error(
351
+ `[${i.queryHash}]: No queryFn was passed as an option, and no default queryFn was found. The queryFn parameter is only optional when using a default queryFn. More info here: https://tanstack.com/query/latest/docs/framework/react/guides/default-query-function`
352
+ )), i._optimisticResults = a ? "isRestoring" : "optimistic", ne(i), se(i, u), re(u);
353
+ const m = !r.getQueryCache().get(i.queryHash), [o] = p.useState(
352
354
  () => new t(
353
355
  r,
354
356
  i
355
357
  )
356
- ), c = h.getOptimisticResult(i), n = !a && e.subscribed !== !1;
358
+ ), c = o.getOptimisticResult(i), n = !a && e.subscribed !== !1;
357
359
  if (p.useSyncExternalStore(
358
360
  p.useCallback(
359
- (m) => {
360
- const l = n ? h.subscribe(B.batchCalls(m)) : j;
361
- return h.updateResult(), l;
361
+ (R) => {
362
+ const l = n ? o.subscribe(A.batchCalls(R)) : L;
363
+ return o.updateResult(), l;
362
364
  },
363
- [h, n]
365
+ [o, n]
364
366
  ),
365
- () => h.getCurrentResult(),
366
- () => h.getCurrentResult()
367
+ () => o.getCurrentResult(),
368
+ () => o.getCurrentResult()
367
369
  ), p.useEffect(() => {
368
- h.setOptions(i, { listeners: !1 });
369
- }, [i, h]), he(i, c))
370
- throw A(i, h, u);
370
+ o.setOptions(i, { listeners: !1 });
371
+ }, [i, o]), oe(i, c))
372
+ throw j(i, o, u);
371
373
  if (ie({
372
374
  result: c,
373
375
  errorResetBoundary: u,
@@ -379,19 +381,21 @@ function oe(e, t, s) {
379
381
  return r.getDefaultOptions().queries?._experimental_afterQuery?.(
380
382
  i,
381
383
  c
382
- ), i.experimental_prefetchInRender && !Q && ae(c, a) && (g ? (
384
+ ), i.experimental_prefetchInRender && !Q && ae(c, a) && (m ? (
383
385
  // Fetch immediately on render in order to ensure `.promise` is resolved even if the component is unmounted
384
- A(i, h, u)
386
+ j(i, o, u)
385
387
  ) : (
386
388
  // subscribe to the "cache promise" so that we can finalize the currentThenable once data comes in
387
389
  r.getQueryCache().get(i.queryHash)?.promise
388
- ))?.catch(j).finally(() => {
389
- h.updateResult();
390
- }), i.notifyOnChangeProps ? c : h.trackResult(c);
390
+ ))?.catch(L).finally(() => {
391
+ o.updateResult();
392
+ }), i.notifyOnChangeProps ? c : o.trackResult(c);
391
393
  }
392
394
  function de(e, t) {
393
- return oe(e, $);
395
+ return he(e, K);
394
396
  }
395
397
  export {
398
+ L as n,
399
+ te as s,
396
400
  de as u
397
401
  };
@@ -0,0 +1,20 @@
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;
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
5
+ * @param url - the complete url build by {@link prependBaseUrl}
6
+ * @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
10
+ * @returns
11
+ */
12
+ export declare const fetchWithErrorHandling: <T>(url: string, config: RequestConfig, tries?: number, withResponseHandling?: boolean) => Promise<BaseResponse<T>>;
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;
@@ -0,0 +1,9 @@
1
+ import { f as t, b as s, a as f, h as i } from "../api-D9Lmqe6S.js";
2
+ import "../constants.js";
3
+ import "../stores/BasePropsStore.js";
4
+ export {
5
+ t as fetchWithErrorHandling,
6
+ s as formatQuery,
7
+ f as getConfig,
8
+ i as handleResponse
9
+ };
@@ -0,0 +1,19 @@
1
+ import { BaseResponse, httpMethod, Query } from '../types/Requests';
2
+ /**
3
+ * a fetch function to handle CUD requests and returns the response.
4
+ * @param url endpoint to fetch (CUD) data from
5
+ * @param data data to send
6
+ * @param method method to use (POST, PUT, DELETE, PATCH)
7
+ * @param customToken token to use (default is the modulePermissionToken)
8
+ * @param headers (optional) custom headers to use
9
+ * @returns Promise<BaseResponse<R>> response from the fetch
10
+ */
11
+ export declare const baseMutation: <T, R>(url: string, data: T, method: Omit<httpMethod, "GET">, customToken?: string, headers?: Headers) => Promise<BaseResponse<R>>;
12
+ /**
13
+ * a fetch function to handle GET requests and returns the response.
14
+ * @param url url to GET data from
15
+ * @param query query to use for the GET request
16
+ * @param customToken token to use (default is the modulePermissionToken)
17
+ * @returns Promise<BaseResponse<T>> response from the fetch
18
+ */
19
+ export declare const baseFetch: <T>(url: string, query: Query, customToken?: string) => Promise<BaseResponse<T>>;
@@ -0,0 +1,19 @@
1
+ import { a as d, f, i as m, b as S } from "../api-D9Lmqe6S.js";
2
+ import { useBasePropsStore as t } from "../stores/BasePropsStore.js";
3
+ const k = (n, o, a, e, s) => {
4
+ const r = e ?? t.getState().modulePermissionToken, g = t.getState().organizationId, i = t.getState().currentLanguageId, c = t.getState().throwError;
5
+ if (!r)
6
+ return c?.("No token found", 404), Promise.reject();
7
+ const u = d(r, g, i, a, s);
8
+ return u.body = JSON.stringify(o), f(n, u);
9
+ }, E = (n, o, a) => {
10
+ const e = a ?? t.getState().modulePermissionToken, s = t.getState().organizationId, r = t.getState().currentLanguageId, g = t.getState().throwError;
11
+ if (!e)
12
+ return g?.("No token found", 404), Promise.reject();
13
+ const i = d(e, s, r), c = m(o) ? "" : S(o);
14
+ return f(`${n}${c}`, i);
15
+ };
16
+ export {
17
+ E as baseFetch,
18
+ k as baseMutation
19
+ };
@@ -1,26 +1,35 @@
1
- import { BaseResponse, Query, RequestConfig } from '../types/Requests';
2
- export declare const getFarmOrgEntities: <T>(moduleId: string, entityId: string) => Promise<BaseResponse<T>>;
3
- export declare const getModuleDependedEntities: <T>(moduleId: string, entityId: string) => Promise<BaseResponse<T>>;
4
- export declare const fetchFromCustomApi: <T>(endpoint: string, token?: string) => Promise<BaseResponse<T>>;
5
- export declare const fetchFromModuleApi: <T>(endpoint: string) => Promise<BaseResponse<T>>;
6
- export declare const fetchFromCommonApi: <T>(endpoint: string) => Promise<BaseResponse<T>>;
7
- export declare const baseFetch: <T>(url: string, query: Query, customToken?: string) => Promise<BaseResponse<T>>;
8
- export declare const getConfig: (token: string, organizationId?: string, languageId?: string, method?: "GET" | "POST" | "PATCH" | "DELETE" | "PUT") => RequestConfig;
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('../types/Requests').BaseResponse<R>>;
9
3
  /**
10
- * 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
11
- * @param url - the complete url build by {@link prependBaseUrl}
12
- * @param config - the request config including auth headers
13
- * @param throwFullMessage - if the full error message should be thrown or only the message behind the status code
14
- * @param withResponseHandling - if the response should be handled by the {@link handleResponse} method or not ("hide" the error)
15
- * @param tries - the number of retries, default is 1
16
- * @returns
4
+ * a fetch function to get a certain farmorganization entity from the moduleApi (will be used in useEntity)
5
+ * @param moduleId moduleID to get the entity from
6
+ * @param entityId entityID of the entity to get
7
+ * @returns entity to get
17
8
  */
18
- export declare const fetchWithErrorHandling: <T>(url: string, config: RequestConfig, tries?: number, withResponseHandling?: boolean) => Promise<BaseResponse<T>>;
19
- export declare const handleResponse: (response: Response) => Promise<any>;
9
+ export declare const getFarmOrgEntities: <T>(moduleId: string, entityId: string) => Promise<import('../types/Requests').BaseResponse<T>>;
20
10
  /**
21
- * a helper function to format the query string
22
- * @param query - the query object to format
23
- * @param withApiVersion - if the api version should be added to the query string
24
- * @returns
11
+ * a fetch function to get a certain MODULEDEPENDED entity from the moduleApi (will be used in useEntity)
12
+ * @param moduleId moduleID to get the entity from
13
+ * @param entityId entityID of the entity to get
14
+ * @returns entity to get
25
15
  */
26
- export declare const formatQuery: (query?: Query, withApiVersion?: boolean) => string;
16
+ export declare const getModuleDependedEntities: <T>(moduleId: string, entityId: string) => Promise<import('../types/Requests').BaseResponse<T>>;
17
+ /**
18
+ * a fetch function to handle GET requests and returns the response.
19
+ * @param endpoint custom endpoint to GET data from
20
+ * @param token token to use (default is the modulePermissionToken)
21
+ * @returns Promise<BaseResponse<T>> response from the fetch
22
+ */
23
+ export declare const fetchFromCustomApi: <T>(endpoint: string, token?: string) => Promise<import('../types/Requests').BaseResponse<T>>;
24
+ /**
25
+ * a fetch function to handle GET requests and returns the response.
26
+ * @param endpoint endpoint of moduleApi to fetch data from
27
+ * @returns Promise<BaseResponse<T>> response from the fetch
28
+ */
29
+ export declare const fetchFromModuleApi: <T>(endpoint: string) => Promise<import('../types/Requests').BaseResponse<T>>;
30
+ /**
31
+ * a fetch function to handle GET requests and returns the response.
32
+ * @param endpoint endpoint of commonApi to fetch data from
33
+ * @returns Promise<BaseResponse<T>> response from the fetch
34
+ */
35
+ export declare const fetchFromCommonApi: <T>(endpoint: string) => Promise<import('../types/Requests').BaseResponse<T>>;
@@ -1,16 +1,21 @@
1
- import { e as r, f as i, d as m, c as n, i as p, k as f, h, a as d, g, j as c } from "../fetches-DUCQo_6B.js";
2
- import "../constants.js";
3
- import "../stores/BasePropsStore.js";
4
- import "../stores/EnvironmentStore.js";
1
+ import { useBasePropsStore as u } from "../stores/BasePropsStore.js";
2
+ import { useEnvironmentStore as r } from "../stores/EnvironmentStore.js";
3
+ import { baseMutation as c, baseFetch as o } from "./baseFetches.js";
4
+ const g = (e, t, n = "POST", m, s) => c(e, t, n, m, s), A = (e, t) => i(`getAllFarmOrgEntities/${e}/${t}`), d = (e, t) => i(`ModuleDependedEntities/${e}/${t}`), E = (e, t) => o(`${e}`, {}, t), i = (e) => {
5
+ const t = r.getState().environment, n = u.getState().organizationId;
6
+ return o(
7
+ `${t?.MODULE_AUTH_API}${t?.API_PREFIX}/${n}/${e}`,
8
+ {}
9
+ );
10
+ }, F = (e) => {
11
+ const t = r.getState().environment;
12
+ return o(`${t?.COMMON_API}${t?.API_PREFIX}/${e}`, {});
13
+ };
5
14
  export {
6
- r as baseFetch,
7
- i as fetchFromCommonApi,
8
- m as fetchFromCustomApi,
9
- n as fetchFromModuleApi,
10
- p as fetchWithErrorHandling,
11
- f as formatQuery,
12
- h as getConfig,
13
- d as getFarmOrgEntities,
14
- g as getModuleDependedEntities,
15
- c as handleResponse
15
+ F as fetchFromCommonApi,
16
+ E as fetchFromCustomApi,
17
+ i as fetchFromModuleApi,
18
+ A as getFarmOrgEntities,
19
+ d as getModuleDependedEntities,
20
+ g as mutateOnCustomApi
16
21
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hortiview/modulebase",
3
3
  "description": "This is a base module for hortiview",
4
- "version": "0.0.12109",
4
+ "version": "0.0.12333",
5
5
  "type": "module",
6
6
  "author": "Falk Menge <falk.menge.ext@bayer.com>",
7
7
  "contributors": [
@@ -24,7 +24,7 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "@microsoft/signalr": "^8.0.7",
27
- "@tanstack/react-query": "^5.66.0",
27
+ "@tanstack/react-query": "^5.67.3",
28
28
  "lodash": "^4.17.21",
29
29
  "odata-query": "^7.0.9",
30
30
  "react": "^18.3.1",