@opengeoweb/authentication 9.25.0 → 9.25.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opengeoweb/authentication",
3
- "version": "9.25.0",
3
+ "version": "9.25.2",
4
4
  "description": "GeoWeb authentication library for the opengeoweb project",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -9,13 +9,12 @@
9
9
  },
10
10
  "dependencies": {
11
11
  "axios": "1.5.0",
12
- "@opengeoweb/api": "*",
13
12
  "react-router-dom": "^6.23.1",
14
13
  "@opengeoweb/shared": "*",
15
14
  "@opengeoweb/theme": "*",
16
15
  "i18next": "^23.11.5",
17
16
  "react-i18next": "^14.1.2",
18
- "@opengeoweb/snackbar": "9.25.0",
17
+ "@opengeoweb/snackbar": "9.25.2",
19
18
  "react-redux": "^8.1.3",
20
19
  "@reduxjs/toolkit": "^1.9.7",
21
20
  "@mui/material": "^5.16.0"
package/src/index.d.ts CHANGED
@@ -1,11 +1,14 @@
1
1
  import authTranslations from '../locales/authentication.json';
2
+ import apiTranslations from '../locales/api.json';
2
3
  export { default as Code } from './lib/components/pages/Code';
3
4
  export { default as Login } from './lib/components/pages/Login';
4
5
  export { default as Logout } from './lib/components/pages/Logout';
5
6
  export * from './lib/components/UserMenuRoles';
6
7
  export * from './lib/components/AuthenticationContext';
7
8
  export * from './lib/components/PrivateRoute';
9
+ export * from './lib/components/ApiContext';
10
+ export * from './lib/components/apiHooks';
8
11
  export * from './lib/utils/session';
9
12
  export * from './lib/utils/utils';
10
13
  export { AUTH_NAMESPACE } from './lib/utils/i18n';
11
- export { authTranslations };
14
+ export { authTranslations, apiTranslations };
@@ -0,0 +1,16 @@
1
+ import * as React from 'react';
2
+ import { ApiModule, CreateApiFn } from './types';
3
+ interface ApiContextState<ApiType> {
4
+ api: ApiType;
5
+ }
6
+ declare const ApiContext: React.Context<{
7
+ api: never;
8
+ }>;
9
+ interface ApiProviderProps extends ApiModule {
10
+ children: React.ReactNode;
11
+ createApi: CreateApiFn;
12
+ }
13
+ export declare function getApi<Type>(name: string): Type;
14
+ export declare const ApiProvider: React.FC<ApiProviderProps>;
15
+ export declare function useApiContext<ApiType>(): ApiContextState<ApiType>;
16
+ export default ApiContext;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ export * from './ApiContext';
2
+ export * from './utils';
3
+ export * from './types';
@@ -0,0 +1,36 @@
1
+ import { TFunction } from 'i18next';
2
+ export interface GeoWebJWT {
3
+ access_token: string;
4
+ refresh_token?: string;
5
+ id_token: string;
6
+ expires_in: number;
7
+ }
8
+ export interface Credentials {
9
+ username: string;
10
+ roles?: Role[];
11
+ token: string;
12
+ refresh_token: string;
13
+ expires_at?: number;
14
+ keep_session_alive_at?: number;
15
+ has_connection_issue?: boolean;
16
+ }
17
+ export interface ApiUrls {
18
+ baseURL?: string;
19
+ appURL?: string;
20
+ authTokenURL?: string;
21
+ authClientId?: string;
22
+ }
23
+ export interface ApiModule {
24
+ auth?: Credentials;
25
+ onSetAuth?: (cred: Credentials) => void;
26
+ config?: ApiUrls;
27
+ name?: string;
28
+ }
29
+ export interface CreateApiProps extends ApiModule {
30
+ timeout?: number;
31
+ }
32
+ export type CreateApiFn = (props: CreateApiProps) => void;
33
+ export interface Role {
34
+ name: string;
35
+ getTitle: (t: TFunction) => string;
36
+ }
@@ -0,0 +1,26 @@
1
+ import { AxiosInstance, AxiosResponse } from 'axios';
2
+ import { ConfigType } from '@opengeoweb/shared';
3
+ import { CreateApiProps, Credentials, Role } from './types';
4
+ export declare const KEEP_ALIVE_IN_SECONDS = 60;
5
+ export declare const KEEP_ALIVE_POLLER_IN_SECONDS = 10;
6
+ export declare const REFRESH_TOKEN_WHEN_PCT_EXPIRED = 75;
7
+ export declare const MILLISECOND_TO_SECOND: number;
8
+ export declare const GEOWEB_ROLE_PRESETS_ADMIN: Role;
9
+ export declare const GEOWEB_ROLE_USER: Role;
10
+ /**
11
+ * Creates a Credentials object based on the axios response from the token service.
12
+ *
13
+ * It will calculate the expires_at attribute based on the expires_in property found in the JWT.
14
+ *
15
+ * @param tokenResponse Response of the tokenservice as axios response object.
16
+ * @returns Credentials object.
17
+ */
18
+ export declare const makeCredentialsFromTokenResponse: (tokenResponse: AxiosResponse, authConfig?: ConfigType) => Credentials;
19
+ export declare const refreshAccessToken: ({ auth, config: { authTokenURL, authClientId, appURL }, timeout, }: CreateApiProps) => Promise<AxiosResponse>;
20
+ export declare const refreshAccessTokenAndSetAuthContext: ({ auth, onSetAuth, config, timeout, }: CreateApiProps) => Promise<void>;
21
+ export declare const createApiInstance: ({ auth, onSetAuth, config: { baseURL, authTokenURL, authClientId, appURL }, timeout, }: CreateApiProps) => AxiosInstance;
22
+ export declare const createNonAuthApiInstance: ({ config: { baseURL }, timeout, }: CreateApiProps) => AxiosInstance;
23
+ export declare const fakeApiRequest: (signal?: AbortController) => Promise<void>;
24
+ export declare const createFakeApiInstance: () => AxiosInstance;
25
+ export declare const getCurrentTimeInSeconds: () => number;
26
+ export declare const groupsToRoles: (groups: string[] | undefined, authConfig?: ConfigType) => Role[];
@@ -0,0 +1 @@
1
+ export {};
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { Credentials } from '@opengeoweb/api';
2
+ import { Credentials } from '../ApiContext/types';
3
3
  interface AuthenticationRenderTestComponentProps {
4
4
  auth: Credentials | null;
5
5
  newAuth: Credentials;
@@ -1,5 +1,5 @@
1
- import { Credentials } from '@opengeoweb/api';
2
1
  import { SessionStorageProvider } from '../../utils/session';
2
+ import { Credentials } from '../ApiContext/types';
3
3
  export interface AuthenticationConfig {
4
4
  GW_AUTH_LOGIN_URL: string;
5
5
  GW_AUTH_LOGOUT_URL: string;
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { Role } from '@opengeoweb/api';
2
+ import { Role } from '../ApiContext/types';
3
3
  export declare const UserMenuRoles: React.FC<{
4
4
  roles?: Role[];
5
5
  currentRole?: string;
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { Role } from '@opengeoweb/api';
2
+ import { Role } from '../ApiContext/types';
3
3
  export declare const UserMenuRolesConnect: React.FC<{
4
4
  temporaryOnChangeRoleForDemo?: (role: Role) => void;
5
5
  roles?: Role[];
@@ -0,0 +1 @@
1
+ export { useApi } from './useApi';
@@ -0,0 +1,36 @@
1
+ import { ConfigType } from '@opengeoweb/shared';
2
+ export type ApiParams = string | ConfigType | Record<string, string | undefined> | null;
3
+ interface BaseApiHookProps {
4
+ fetchApiData?: (params: ApiParams) => Promise<void>;
5
+ clearResults?: () => void;
6
+ }
7
+ type PendingApiHookProps = BaseApiHookProps & {
8
+ isLoading: true;
9
+ result: null;
10
+ error: null;
11
+ };
12
+ type DoneApiHookProps<R> = BaseApiHookProps & {
13
+ isLoading: false;
14
+ result: R;
15
+ error: null;
16
+ };
17
+ type ErrorApiHookProps = BaseApiHookProps & {
18
+ isLoading: false;
19
+ result: null;
20
+ error: Error;
21
+ };
22
+ export type ApiHookProps<TData> = ErrorApiHookProps | PendingApiHookProps | DoneApiHookProps<TData>;
23
+ interface Callbacks<TData> {
24
+ onSuccess?: (data: TData) => void;
25
+ onError?: (e: Error) => void;
26
+ }
27
+ export declare const useApi: <TResponse extends {
28
+ data: unknown;
29
+ } | {
30
+ data: unknown;
31
+ }[], TResult = TResponse extends {
32
+ data: infer TData;
33
+ }[] ? TData[] : TResponse extends {
34
+ data: infer TData_1;
35
+ } ? TData_1 : never>(apiCall?: ((params?: ApiParams, id?: string) => Promise<TResponse>) | undefined, params?: ApiParams, callbacks?: Callbacks<TResult> | undefined) => ApiHookProps<TResult>;
36
+ export {};
@@ -0,0 +1 @@
1
+ export {};