@opengeoweb/api 12.0.0 → 12.1.0

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,6 +1,7 @@
1
1
  import { useAuthenticationContext } from '@opengeoweb/authentication';
2
2
  export * from '@opengeoweb/authentication';
3
3
  import { useQuery } from '@tanstack/react-query';
4
+ import { HttpResponse, delay } from 'msw';
4
5
 
5
6
  function asyncGeneratorStep(n, t, e, r, o, a, c) {
6
7
  try {
@@ -338,18 +339,27 @@ var getHeaders = function getHeaders(auth) {
338
339
  };
339
340
  // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
340
341
  var handleResponse = function handleResponse(response) {
341
- if (response.status === 200) {
342
+ if (response.ok) {
342
343
  return response.json().then(function (json) {
343
344
  return json || response.headers;
345
+ })["catch"](function () {
346
+ // No JSON response
344
347
  });
345
348
  }
346
349
  return response.json()["catch"](function () {
347
350
  // Couldn't parse the JSON
348
351
  throw new Error("" + response.status);
349
- }).then(function (_ref) {
350
- var message = _ref.message;
352
+ }).then(function (json) {
351
353
  // Got valid JSON with error response, use it
352
- throw new Error(message || response.status);
354
+ if (json) {
355
+ var message = json.message;
356
+ if (message) {
357
+ throw new Error(message);
358
+ }
359
+ var result = JSON.stringify(json);
360
+ throw new Error(result);
361
+ }
362
+ throw new Error("" + response.status);
353
363
  });
354
364
  };
355
365
  var useAuthQuery = function useAuthQuery(queryKey, _queryFn, disabled, refetchInterval) {
@@ -415,6 +425,30 @@ var optimisticUpdate = function optimisticUpdate(updatedQueryKey, queryClient, _
415
425
  };
416
426
  };
417
427
 
428
+ var makeMockApiCall = function makeMockApiCall(response, responseInit, delayDuration) {
429
+ if (delayDuration === void 0) {
430
+ delayDuration = 0;
431
+ }
432
+ var result = HttpResponse.json(response, responseInit);
433
+ if (delayDuration) {
434
+ return jest.fn().mockImplementation( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
435
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
436
+ while (1) switch (_context.prev = _context.next) {
437
+ case 0:
438
+ _context.next = 2;
439
+ return delay(delayDuration);
440
+ case 2:
441
+ return _context.abrupt("return", result);
442
+ case 3:
443
+ case "end":
444
+ return _context.stop();
445
+ }
446
+ }, _callee);
447
+ })));
448
+ }
449
+ return jest.fn().mockResolvedValue(result);
450
+ };
451
+
418
452
  /* *
419
453
  * Licensed under the Apache License, Version 2.0 (the "License");
420
454
  * you may not use this file except in compliance with the License.
@@ -579,4 +613,4 @@ var VisibilityCause;
579
613
  var API_NAMESPACE = 'api';
580
614
  // Initialize and create provider if needed
581
615
 
582
- export { API_NAMESPACE, AirmetPhenomena, CloudLevelUnits, Direction, LevelUnits, MovementUnit, ProductStatus, SigmetPhenomena, VisibilityCause, WindUnit, getHeaders, handleResponse, optimisticUpdate, useAuthQuery };
616
+ export { API_NAMESPACE, AirmetPhenomena, CloudLevelUnits, Direction, LevelUnits, MovementUnit, ProductStatus, SigmetPhenomena, VisibilityCause, WindUnit, getHeaders, handleResponse, makeMockApiCall, optimisticUpdate, useAuthQuery };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengeoweb/api",
3
- "version": "12.0.0",
3
+ "version": "12.1.0",
4
4
  "description": "GeoWeb API library for the opengeoweb project",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -8,39 +8,9 @@
8
8
  "url": "git@gitlab.com:opengeoweb/opengeoweb.git"
9
9
  },
10
10
  "dependencies": {
11
- "@emotion/react": "11.14.0",
12
- "@emotion/styled": "11.14.0",
13
- "@mui/material": "6.4.1",
14
- "@mui/system": "6.4.6",
15
- "@mui/x-date-pickers": "7.27.1",
16
- "@reduxjs/toolkit": "1.9.7",
17
- "@sentry/react": "8.54.0",
18
- "@storybook/core-events": "8.4.2",
19
- "@storybook/preview-api": "8.4.2",
20
- "@storybook/react": "8.4.2",
21
- "@tanstack/query-core": "5.67.1",
22
- "@tanstack/react-query": "^5.52.1",
23
- "@testing-library/react": "16.0.1",
24
- "@testing-library/user-event": "14.5.2",
25
- "@turf/turf": "7.2.0",
26
- "axios": "1.8.1",
27
- "date-fns": "4.1.0",
28
- "dompurify": "3.2.4",
29
- "i18next": "23.11.5",
30
- "immer": "10.1.1",
31
- "jest-canvas-mock": "2.5.2",
32
- "jest-date-mock": "1.0.10",
33
- "lodash": "4.17.21",
34
- "msw": "2.7.3",
35
- "ol": "10.4.0",
36
- "proj4": "2.15.0",
37
- "re-resizable": "6.11.2",
38
- "react": "18.3.1",
39
- "react-draggable": "4.4.6",
40
- "react-i18next": "15.1.1",
41
- "react-redux": "8.1.3",
42
- "react-resize-detector": "9.1.1",
43
- "react-router-dom": "6.23.1"
11
+ "@opengeoweb/authentication": "12.1.0",
12
+ "@opengeoweb/store": "12.1.0",
13
+ "@tanstack/react-query": "^5.52.1"
44
14
  },
45
15
  "module": "./index.esm.js",
46
16
  "type": "module",
@@ -0,0 +1,3 @@
1
+ /// <reference types="jest" />
2
+ import { HttpResponseInit, JsonBodyType } from 'msw';
3
+ export declare const makeMockApiCall: (response: JsonBodyType, responseInit?: HttpResponseInit, delayDuration?: number) => jest.Mock;
package/src/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from '@opengeoweb/authentication';
2
2
  export * from './utils';
3
+ export * from './fakeApi';
3
4
  export * from './sigmet-airmet-api/types';
4
5
  export * from './sigmet-airmet-api/definitions';
5
6
  export * from './sigmet-airmet-api/config-types';
@@ -0,0 +1 @@
1
+ export {};