@opengeoweb/api 9.22.0 → 9.24.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
@@ -3,6 +3,29 @@ import axios from 'axios';
3
3
  import { useIsMounted, useDebounce } from '@opengeoweb/shared';
4
4
  import { jsx } from 'react/jsx-runtime';
5
5
 
6
+ var en = {
7
+ "api-role-title-user": "User",
8
+ "api-role-title-preset-admin": "Preset-admin"
9
+ };
10
+ var fi = {
11
+ "api-role-title-user": "Käyttäjä",
12
+ "api-role-title-preset-admin": "Preset-pääkäyttäjä"
13
+ };
14
+ var no = {
15
+ "api-role-title-user": "Bruker",
16
+ "api-role-title-preset-admin": "Preset-admin"
17
+ };
18
+ var nl = {
19
+ "api-role-title-user": "Gebruiker",
20
+ "api-role-title-preset-admin": "Preset-beheerder"
21
+ };
22
+ var api = {
23
+ en: en,
24
+ fi: fi,
25
+ no: no,
26
+ nl: nl
27
+ };
28
+
6
29
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
7
30
 
8
31
  var fails$s = function (exec) {
@@ -5019,19 +5042,43 @@ if (DESCRIPTORS && !('size' in URLSearchParamsPrototype)) {
5019
5042
  });
5020
5043
  }
5021
5044
 
5045
+ /* *
5046
+ * Licensed under the Apache License, Version 2.0 (the "License");
5047
+ * you may not use this file except in compliance with the License.
5048
+ * You may obtain a copy of the License at
5049
+ *
5050
+ * http://www.apache.org/licenses/LICENSE-2.0
5051
+ *
5052
+ * Unless required by applicable law or agreed to in writing, software
5053
+ * distributed under the License is distributed on an "AS IS" BASIS,
5054
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5055
+ * See the License for the specific language governing permissions and
5056
+ * limitations under the License.
5057
+ *
5058
+ * Copyright 2024 - Koninklijk Nederlands Meteorologisch Instituut (KNMI)
5059
+ * Copyright 2024 - Finnish Meteorological Institute (FMI)
5060
+ * */
5061
+ const API_NAMESPACE = 'api';
5062
+ // Initialize and create provider if needed
5063
+
5022
5064
  const DEFAULT_TIMEOUT = 15000;
5023
5065
  const KEEP_ALIVE_IN_SECONDS = 60; // Number of seconds in between intervals to check with the token request if connection is stil intact
5024
5066
  const KEEP_ALIVE_POLLER_IN_SECONDS = 10; // Number of milliseconds to check if connection is restored or to check if KEEP_ALIVE_IN_SECONDS has passed
5025
5067
  const REFRESH_TOKEN_WHEN_PCT_EXPIRED = 75; // Refresh token when 75% expired. Set to (10 / 3600) * 100 = 0.2777778% to test with 10 second interval.
5026
5068
  const DEFAULT_TOKEN_EXPIRES_IN = 3600; // Number of seconds a token expires by default
5027
5069
  const MILLISECOND_TO_SECOND = 1 / 1000;
5070
+ const ns = API_NAMESPACE;
5028
5071
  const GEOWEB_ROLE_PRESETS_ADMIN = {
5029
5072
  name: 'ROLE_PRESET_ADMIN',
5030
- title: 'Preset-admin'
5073
+ getTitle: t => t('api-role-title-preset-admin', {
5074
+ ns
5075
+ })
5031
5076
  };
5032
5077
  const GEOWEB_ROLE_USER = {
5033
5078
  name: 'ROLE_USER',
5034
- title: 'User'
5079
+ getTitle: t => t('api-role-title-user', {
5080
+ ns
5081
+ })
5035
5082
  };
5036
5083
  /**
5037
5084
  * Creates a Credentials object based on the axios response from the token service.
@@ -5051,6 +5098,7 @@ const makeCredentialsFromTokenResponse = (tokenResponse, authConfig) => {
5051
5098
  expires_in
5052
5099
  } = token;
5053
5100
  if (!access_token || !id_token) {
5101
+ // message is not user-facing
5054
5102
  throw new Error('Login failed');
5055
5103
  }
5056
5104
  const userInfoString = atob(
@@ -5261,4 +5309,4 @@ const groupsToRoles = (groups, authConfig) => {
5261
5309
  return roles;
5262
5310
  };
5263
5311
 
5264
- export { ApiProvider, GEOWEB_ROLE_PRESETS_ADMIN, GEOWEB_ROLE_USER, KEEP_ALIVE_IN_SECONDS, KEEP_ALIVE_POLLER_IN_SECONDS, MILLISECOND_TO_SECOND, REFRESH_TOKEN_WHEN_PCT_EXPIRED, createApiInstance, createFakeApiInstance, createNonAuthApiInstance, fakeApiRequest, getApi, getCurrentTimeInSeconds, groupsToRoles, makeCredentialsFromTokenResponse, refreshAccessToken, refreshAccessTokenAndSetAuthContext, useApi, useApiContext };
5312
+ export { API_NAMESPACE, ApiProvider, GEOWEB_ROLE_PRESETS_ADMIN, GEOWEB_ROLE_USER, KEEP_ALIVE_IN_SECONDS, KEEP_ALIVE_POLLER_IN_SECONDS, MILLISECOND_TO_SECOND, REFRESH_TOKEN_WHEN_PCT_EXPIRED, api as apiTranslations, createApiInstance, createFakeApiInstance, createNonAuthApiInstance, fakeApiRequest, getApi, getCurrentTimeInSeconds, groupsToRoles, makeCredentialsFromTokenResponse, refreshAccessToken, refreshAccessTokenAndSetAuthContext, useApi, useApiContext };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengeoweb/api",
3
- "version": "9.22.0",
3
+ "version": "9.24.0",
4
4
  "description": "GeoWeb API library for the opengeoweb project",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -9,7 +9,8 @@
9
9
  },
10
10
  "dependencies": {
11
11
  "axios": "1.5.0",
12
- "@opengeoweb/shared": "*"
12
+ "@opengeoweb/shared": "*",
13
+ "i18next": "^23.11.5"
13
14
  },
14
15
  "peerDependencies": {
15
16
  "react": "18"
package/src/i18n.d.ts ADDED
@@ -0,0 +1 @@
1
+ export declare const API_NAMESPACE = "api";
package/src/index.d.ts CHANGED
@@ -1,2 +1,5 @@
1
+ import apiTranslations from '../locales/api.json';
1
2
  export * from './lib/components/apihooks';
2
3
  export * from './lib/components/ApiContext';
4
+ export { API_NAMESPACE } from './i18n';
5
+ export { apiTranslations };
@@ -1,3 +1,4 @@
1
+ import { TFunction } from 'i18next';
1
2
  export interface GeoWebJWT {
2
3
  access_token: string;
3
4
  refresh_token?: string;
@@ -31,5 +32,5 @@ export interface CreateApiProps extends ApiModule {
31
32
  export type CreateApiFn = (props: CreateApiProps) => void;
32
33
  export interface Role {
33
34
  name: string;
34
- title: string;
35
+ getTitle: (t: TFunction) => string;
35
36
  }
@@ -5,14 +5,8 @@ export declare const KEEP_ALIVE_IN_SECONDS = 60;
5
5
  export declare const KEEP_ALIVE_POLLER_IN_SECONDS = 10;
6
6
  export declare const REFRESH_TOKEN_WHEN_PCT_EXPIRED = 75;
7
7
  export declare const MILLISECOND_TO_SECOND: number;
8
- export declare const GEOWEB_ROLE_PRESETS_ADMIN: {
9
- name: string;
10
- title: string;
11
- };
12
- export declare const GEOWEB_ROLE_USER: {
13
- name: string;
14
- title: string;
15
- };
8
+ export declare const GEOWEB_ROLE_PRESETS_ADMIN: Role;
9
+ export declare const GEOWEB_ROLE_USER: Role;
16
10
  /**
17
11
  * Creates a Credentials object based on the axios response from the token service.
18
12
  *