@opengeoweb/api 14.0.1 → 14.2.1

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/index.esm.js CHANGED
@@ -1,8 +1,12 @@
1
1
  import { useAuthenticationContext } from '@opengeoweb/authentication';
2
2
  export * from '@opengeoweb/authentication';
3
- import { useQuery } from '@tanstack/react-query';
3
+ import { useQuery, QueryClientProvider } from '@tanstack/react-query';
4
4
  import { omit } from 'lodash';
5
5
  import { HttpResponse, delay } from 'msw';
6
+ import { jsxs, jsx } from 'react/jsx-runtime';
7
+ import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
8
+ import React from 'react';
9
+ import { QueryClient, keepPreviousData } from '@tanstack/query-core';
6
10
 
7
11
  function _OverloadYield(e, d) {
8
12
  this.v = e, this.k = d;
@@ -283,33 +287,51 @@ var getHeaders = function getHeaders(auth) {
283
287
  Accept: 'application/json'
284
288
  }, auth ? [] : ['Authorization']);
285
289
  };
286
- // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
287
- var handleResponse = function handleResponse(response) {
288
- if (response.ok) {
289
- return response.json().then(function (json) {
290
- return json || response.headers;
291
- })["catch"](function () {
292
- // No JSON response
293
- });
294
- }
295
- return response.json()["catch"](function () {
296
- // Couldn't parse the JSON
297
- throw new Error("" + response.status);
298
- }).then(function (json) {
299
- // Got valid JSON with error response, use it
300
- if (json) {
301
- var message = json.message;
302
- if (message) {
303
- throw new Error(message, {
304
- cause: response.status
305
- });
290
+ // This function has a copy in libs/webmap-react/src/lib/edr-layer-api/api.ts. This cannot be used there due to circular dependency
291
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
292
+ var handleResponse = /*#__PURE__*/function () {
293
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(response) {
294
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
295
+ while (1) switch (_context.prev = _context.next) {
296
+ case 0:
297
+ if (!response.ok) {
298
+ _context.next = 2;
299
+ break;
300
+ }
301
+ return _context.abrupt("return", response.json().then(function (json) {
302
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
303
+ return json != null ? json : response.headers;
304
+ })["catch"](function () {
305
+ // No JSON response
306
+ }));
307
+ case 2:
308
+ return _context.abrupt("return", response.json()["catch"](function () {
309
+ // Couldn't parse the JSON
310
+ throw new Error("" + response.status);
311
+ }).then(function (json) {
312
+ // Got valid JSON with error response, use it
313
+ if (json) {
314
+ var message = json.message;
315
+ if (message) {
316
+ throw new Error(message, {
317
+ cause: response.status
318
+ });
319
+ }
320
+ var result = JSON.stringify(json);
321
+ throw new Error(result);
322
+ }
323
+ throw new Error("" + response.status);
324
+ }));
325
+ case 3:
326
+ case "end":
327
+ return _context.stop();
306
328
  }
307
- var result = JSON.stringify(json);
308
- throw new Error(result);
309
- }
310
- throw new Error("" + response.status);
311
- });
312
- };
329
+ }, _callee);
330
+ }));
331
+ return function handleResponse(_x) {
332
+ return _ref.apply(this, arguments);
333
+ };
334
+ }();
313
335
  var useAuthQuery = function useAuthQuery(queryKey, _queryFn, disabled, refetchInterval) {
314
336
  if (disabled === void 0) {
315
337
  disabled = false;
@@ -322,9 +344,23 @@ var useAuthQuery = function useAuthQuery(queryKey, _queryFn, disabled, refetchIn
322
344
  var enabled = !!auth && !disabled;
323
345
  return useQuery({
324
346
  queryKey: queryKey,
325
- queryFn: function queryFn() {
326
- return _queryFn(auth);
327
- },
347
+ queryFn: function () {
348
+ var _queryFn2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
349
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
350
+ while (1) switch (_context2.prev = _context2.next) {
351
+ case 0:
352
+ return _context2.abrupt("return", _queryFn(auth));
353
+ case 1:
354
+ case "end":
355
+ return _context2.stop();
356
+ }
357
+ }, _callee2);
358
+ }));
359
+ function queryFn() {
360
+ return _queryFn2.apply(this, arguments);
361
+ }
362
+ return queryFn;
363
+ }(),
328
364
  enabled: enabled,
329
365
  refetchInterval: refetchInterval
330
366
  });
@@ -332,10 +368,10 @@ var useAuthQuery = function useAuthQuery(queryKey, _queryFn, disabled, refetchIn
332
368
  var optimisticUpdate = function optimisticUpdate(updatedQueryKey, queryClient, _optimisticUpdate, errorCallback) {
333
369
  return {
334
370
  onMutate: function () {
335
- var _onMutate = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(variables) {
371
+ var _onMutate = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(variables) {
336
372
  var oldData;
337
- return _regeneratorRuntime().wrap(function _callee$(_context) {
338
- while (1) switch (_context.prev = _context.next) {
373
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
374
+ while (1) switch (_context3.prev = _context3.next) {
339
375
  case 0:
340
376
  void queryClient.cancelQueries({
341
377
  queryKey: updatedQueryKey
@@ -348,16 +384,16 @@ var optimisticUpdate = function optimisticUpdate(updatedQueryKey, queryClient, _
348
384
  });
349
385
  });
350
386
  }
351
- return _context.abrupt("return", {
387
+ return _context3.abrupt("return", {
352
388
  oldData: oldData
353
389
  });
354
390
  case 4:
355
391
  case "end":
356
- return _context.stop();
392
+ return _context3.stop();
357
393
  }
358
- }, _callee);
394
+ }, _callee3);
359
395
  }));
360
- function onMutate(_x) {
396
+ function onMutate(_x2) {
361
397
  return _onMutate.apply(this, arguments);
362
398
  }
363
399
  return onMutate;
@@ -393,9 +429,17 @@ var makeMockApiCall = function makeMockApiCall(response, responseInit, delayDura
393
429
  }, _callee);
394
430
  })));
395
431
  }
396
- return jest.fn().mockImplementation(function () {
397
- return Promise.resolve(HttpResponse.json(response, responseInit));
398
- });
432
+ return jest.fn().mockImplementation(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
433
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
434
+ while (1) switch (_context2.prev = _context2.next) {
435
+ case 0:
436
+ return _context2.abrupt("return", Promise.resolve(HttpResponse.json(response, responseInit)));
437
+ case 1:
438
+ case "end":
439
+ return _context2.stop();
440
+ }
441
+ }, _callee2);
442
+ })));
399
443
  };
400
444
 
401
445
  /* *
@@ -542,6 +586,92 @@ var VisibilityCause;
542
586
  VisibilityCause["VA"] = "Volcanic Ash";
543
587
  })(VisibilityCause || (VisibilityCause = {}));
544
588
 
589
+ /* *
590
+ * Licensed under the Apache License, Version 2.0 (the "License");
591
+ * you may not use this file except in compliance with the License.
592
+ * You may obtain a copy of the License at
593
+ *
594
+ * http://www.apache.org/licenses/LICENSE-2.0
595
+ *
596
+ * Unless required by applicable law or agreed to in writing, software
597
+ * distributed under the License is distributed on an "AS IS" BASIS,
598
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
599
+ * See the License for the specific language governing permissions and
600
+ * limitations under the License.
601
+ *
602
+ * Copyright 2025 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
603
+ * Copyright 2025 - Finnish Meteorological Institute (FMI)
604
+ * Copyright 2025 - The Norwegian Meteorological Institute (MET Norway)
605
+ * */
606
+ var queryClientInstance = null;
607
+ var getQueryClient = function getQueryClient() {
608
+ var _queryClientInstance;
609
+ (_queryClientInstance = queryClientInstance) != null ? _queryClientInstance : queryClientInstance = new QueryClient({
610
+ defaultOptions: {
611
+ queries: {
612
+ refetchOnWindowFocus: false,
613
+ refetchOnMount: false,
614
+ refetchOnReconnect: false,
615
+ refetchInterval: false,
616
+ placeholderData: keepPreviousData,
617
+ staleTime: 1000 * 60 * 5
618
+ }
619
+ }
620
+ });
621
+ return queryClientInstance;
622
+ };
623
+ var setQueryClient = function setQueryClient(client) {
624
+ queryClientInstance = client;
625
+ };
626
+ var configureLibraryDefaults = function configureLibraryDefaults(queryKeyPrefix, options) {
627
+ var client = getQueryClient();
628
+ client.setQueryDefaults(queryKeyPrefix, options);
629
+ };
630
+ var createTestQueryClient = function createTestQueryClient(overrides) {
631
+ var client = new QueryClient({
632
+ defaultOptions: {
633
+ queries: Object.assign({
634
+ retry: false,
635
+ staleTime: 0,
636
+ refetchOnWindowFocus: false,
637
+ refetchOnMount: false,
638
+ refetchOnReconnect: false,
639
+ refetchInterval: false
640
+ }, overrides == null ? void 0 : overrides.queries),
641
+ mutations: Object.assign({
642
+ retry: false
643
+ }, overrides == null ? void 0 : overrides.mutations)
644
+ }
645
+ });
646
+ setQueryClient(client);
647
+ return client;
648
+ };
649
+ var resetQueryClient = function resetQueryClient() {
650
+ var _queryClientInstance2;
651
+ (_queryClientInstance2 = queryClientInstance) == null || _queryClientInstance2.clear();
652
+ queryClientInstance = null;
653
+ };
654
+
655
+ var QueryClientProviderWrapper = function QueryClientProviderWrapper(_ref) {
656
+ var client = _ref.client,
657
+ children = _ref.children,
658
+ _ref$mode = _ref.mode,
659
+ mode = _ref$mode === void 0 ? 'production' : _ref$mode;
660
+ var queryClient = React.useMemo(function () {
661
+ if (client) {
662
+ setQueryClient(client);
663
+ return client;
664
+ }
665
+ return mode === 'test' ? createTestQueryClient() : getQueryClient();
666
+ }, [client, mode]);
667
+ return jsxs(QueryClientProvider, {
668
+ client: queryClient,
669
+ children: [children, jsx(ReactQueryDevtools, {
670
+ initialIsOpen: false
671
+ })]
672
+ });
673
+ };
674
+
545
675
  /* *
546
676
  * Licensed under the Apache License, Version 2.0 (the "License");
547
677
  * you may not use this file except in compliance with the License.
@@ -562,4 +692,4 @@ var VisibilityCause;
562
692
  var API_NAMESPACE = 'api';
563
693
  // Initialize and create provider if needed
564
694
 
565
- export { API_NAMESPACE, AirmetPhenomena, CloudLevelUnits, Direction, LevelUnits, MovementUnit, ProductStatus, SigmetPhenomena, VisibilityCause, WindUnit, getHeaders, handleResponse, makeMockApiCall, optimisticUpdate, useAuthQuery };
695
+ export { API_NAMESPACE, AirmetPhenomena, CloudLevelUnits, Direction, LevelUnits, MovementUnit, ProductStatus, QueryClientProviderWrapper, SigmetPhenomena, VisibilityCause, WindUnit, configureLibraryDefaults, createTestQueryClient, getHeaders, getQueryClient, handleResponse, makeMockApiCall, optimisticUpdate, resetQueryClient, setQueryClient, useAuthQuery };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengeoweb/api",
3
- "version": "14.0.1",
3
+ "version": "14.2.1",
4
4
  "description": "GeoWeb API library for the opengeoweb project",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -8,10 +8,13 @@
8
8
  "url": "git@gitlab.com:opengeoweb/opengeoweb.git"
9
9
  },
10
10
  "dependencies": {
11
- "@opengeoweb/authentication": "14.0.1",
12
- "@opengeoweb/store": "14.0.1",
11
+ "@opengeoweb/authentication": "14.2.1",
12
+ "@opengeoweb/store": "14.2.1",
13
13
  "lodash": "^4.17.21",
14
- "@tanstack/react-query": "^5.85.5"
14
+ "@tanstack/react-query": "^5.85.5",
15
+ "@tanstack/query-core": "^5.79.0",
16
+ "react": "^18.3.1",
17
+ "@tanstack/react-query-devtools": "5.90.2"
15
18
  },
16
19
  "module": "./index.esm.js",
17
20
  "type": "module",
package/src/fakeApi.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { HttpResponseInit, JsonBodyType } from 'msw';
1
+ import type { HttpResponseInit, JsonBodyType } from 'msw';
2
2
  export declare const makeMockApiCall: (response: JsonBodyType, responseInit?: HttpResponseInit, delayDuration?: number) => jest.Mock;
package/src/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  export * from '@opengeoweb/authentication';
2
2
  export * from './utils';
3
3
  export * from './fakeApi';
4
- export * from './sigmet-airmet-api/types';
4
+ export type * from './sigmet-airmet-api/types';
5
5
  export * from './sigmet-airmet-api/definitions';
6
- export * from './sigmet-airmet-api/config-types';
6
+ export type * from './sigmet-airmet-api/config-types';
7
+ export * from './query-client';
7
8
  export { API_NAMESPACE } from './i18n';
@@ -0,0 +1,9 @@
1
+ import type { QueryClient } from '@tanstack/query-core';
2
+ import React from 'react';
3
+ interface QueryClientProviderWrapperProps {
4
+ client?: QueryClient;
5
+ children: React.ReactNode;
6
+ mode?: 'test' | 'production';
7
+ }
8
+ export declare const QueryClientProviderWrapper: ({ client, children, mode, }: QueryClientProviderWrapperProps) => React.ReactElement;
9
+ export {};
@@ -0,0 +1,2 @@
1
+ export * from './QueryClientProviderWrapper';
2
+ export * from './queryClient';
@@ -0,0 +1,10 @@
1
+ import type { DefaultOptions } from '@tanstack/query-core';
2
+ import { QueryClient } from '@tanstack/query-core';
3
+ export declare const getQueryClient: () => QueryClient;
4
+ export declare const setQueryClient: (client: QueryClient) => void;
5
+ export declare const configureLibraryDefaults: (queryKeyPrefix: string[], options: DefaultOptions["queries"]) => void;
6
+ export declare const createTestQueryClient: (overrides?: {
7
+ queries?: DefaultOptions["queries"];
8
+ mutations?: DefaultOptions["mutations"];
9
+ }) => QueryClient;
10
+ export declare const resetQueryClient: () => void;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,4 @@
1
- import { MapPreset } from '@opengeoweb/store';
1
+ import type { MapPreset } from '@opengeoweb/store';
2
2
  export interface AllowedUnits {
3
3
  unit_type: string;
4
4
  allowed_units: string[];
@@ -1,4 +1,4 @@
1
- import { AirmetMovementType, AirmetPhenomena, ATSRLocation, ATSULocation, Change, CloudLevelInfoMode, CloudLevelUnits, DateType, Direction, ICAOLocation, LevelInfoMode, LevelUnits, MovementUnit, MWOLocation, ObservationOrForcast, ProductCanbe, ProductSequenceId, ProductStatus, SigmetMovementType, SigmetPhenomena, VisibilityCause, VisibilityUnit, WindUnit } from './definitions';
1
+ import type { AirmetMovementType, AirmetPhenomena, ATSRLocation, ATSULocation, Change, CloudLevelInfoMode, CloudLevelUnits, DateType, Direction, ICAOLocation, LevelInfoMode, LevelUnits, MovementUnit, MWOLocation, ObservationOrForcast, ProductCanbe, ProductSequenceId, ProductStatus, SigmetMovementType, SigmetPhenomena, VisibilityCause, VisibilityUnit, WindUnit } from './definitions';
2
2
  export interface LevelType {
3
3
  value: number;
4
4
  unit: LevelUnits;
package/src/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { MutationOptions, QueryClient, UseQueryResult } from '@tanstack/react-query';
2
- import { Credentials } from '@opengeoweb/authentication';
1
+ import type { MutationOptions, QueryClient, UseQueryResult } from '@tanstack/react-query';
2
+ import type { Credentials } from '@opengeoweb/authentication';
3
3
  export declare const getHeaders: (auth?: Credentials) => HeadersInit;
4
4
  export declare const handleResponse: (response: Response) => Promise<any>;
5
5
  export declare const useAuthQuery: <T>(queryKey: string[], queryFn: (auth: Credentials) => Promise<T>, disabled?: boolean, refetchInterval?: number | false) => UseQueryResult<T>;