@axa-fr/react-oidc 7.22.18 → 7.22.19

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.
Files changed (39) hide show
  1. package/README.md +87 -114
  2. package/bin/copy-service-worker-files.mjs +24 -17
  3. package/dist/FetchToken.d.ts.map +1 -1
  4. package/dist/OidcProvider.d.ts +1 -1
  5. package/dist/OidcProvider.d.ts.map +1 -1
  6. package/dist/OidcSecure.d.ts.map +1 -1
  7. package/dist/OidcTrustedDomains.js +13 -10
  8. package/dist/ReactOidc.d.ts.map +1 -1
  9. package/dist/User.d.ts.map +1 -1
  10. package/dist/core/default-component/Authenticating.component.d.ts.map +1 -1
  11. package/dist/core/default-component/Callback.component.d.ts.map +1 -1
  12. package/dist/core/default-component/Loading.component.d.ts.map +1 -1
  13. package/dist/core/default-component/ServiceWorkerNotSupported.component.d.ts.map +1 -1
  14. package/dist/core/default-component/SilentCallback.component.d.ts +5 -2
  15. package/dist/core/default-component/SilentCallback.component.d.ts.map +1 -1
  16. package/dist/core/routes/OidcRoutes.d.ts.map +1 -1
  17. package/dist/core/routes/withRouter.d.ts.map +1 -1
  18. package/dist/index.d.ts +2 -2
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +165 -72
  21. package/dist/index.umd.cjs +1 -1
  22. package/package.json +3 -3
  23. package/src/FetchToken.tsx +36 -13
  24. package/src/OidcProvider.tsx +222 -176
  25. package/src/OidcSecure.tsx +34 -23
  26. package/src/ReactOidc.tsx +181 -142
  27. package/src/User.ts +60 -50
  28. package/src/core/default-component/Authenticating.component.tsx +1 -1
  29. package/src/core/default-component/Callback.component.tsx +18 -11
  30. package/src/core/default-component/Loading.component.tsx +1 -5
  31. package/src/core/default-component/ServiceWorkerNotSupported.component.tsx +5 -2
  32. package/src/core/default-component/SessionLost.component.tsx +1 -1
  33. package/src/core/default-component/SilentCallback.component.tsx +17 -11
  34. package/src/core/default-component/SilentLogin.component.tsx +18 -18
  35. package/src/core/routes/OidcRoutes.spec.tsx +2 -2
  36. package/src/core/routes/OidcRoutes.tsx +12 -5
  37. package/src/core/routes/withRouter.spec.tsx +5 -6
  38. package/src/core/routes/withRouter.tsx +21 -19
  39. package/src/index.ts +8 -3
@@ -2,30 +2,30 @@ import { getParseQueryStringFromLocation, OidcClient } from '@axa-fr/oidc-client
2
2
  import { ComponentType, useEffect } from 'react';
3
3
 
4
4
  const SilentLogin: ComponentType<any> = ({ configurationName }) => {
5
- const queryParams = getParseQueryStringFromLocation(window.location.href);
5
+ const queryParams = getParseQueryStringFromLocation(window.location.href);
6
6
 
7
- const getOidc = OidcClient.get;
8
- const oidc = getOidc(configurationName);
7
+ const getOidc = OidcClient.get;
8
+ const oidc = getOidc(configurationName);
9
9
 
10
- let extras = null;
10
+ let extras = null;
11
11
 
12
- for (const [key, value] of Object.entries(queryParams)) {
13
- if (key === 'state' || key === 'scope') {
14
- continue;
15
- }
16
- if (extras === null) {
17
- extras = {};
18
- }
19
- extras[key] = value;
12
+ for (const [key, value] of Object.entries(queryParams)) {
13
+ if (key === 'state' || key === 'scope') {
14
+ continue;
20
15
  }
16
+ if (extras === null) {
17
+ extras = {};
18
+ }
19
+ extras[key] = value;
20
+ }
21
21
 
22
- useEffect(() => {
23
- if (!oidc.tokens) {
24
- oidc.loginAsync(null, extras, true, queryParams.scope);
25
- }
26
- }, []);
22
+ useEffect(() => {
23
+ if (!oidc.tokens) {
24
+ oidc.loginAsync(null, extras, true, queryParams.scope);
25
+ }
26
+ }, []);
27
27
 
28
- return <></>;
28
+ return <></>;
29
29
  };
30
30
 
31
31
  export default SilentLogin;
@@ -1,6 +1,6 @@
1
- import { render } from "@testing-library/react";
1
+ import { render } from '@testing-library/react';
2
2
  import React from 'react';
3
- import { describe, expect,it } from 'vitest';
3
+ import { describe, expect, it } from 'vitest';
4
4
 
5
5
  import OidcRoutes from './OidcRoutes';
6
6
 
@@ -1,4 +1,4 @@
1
- import {getPath, ILOidcLocation} from '@axa-fr/oidc-client';
1
+ import { getPath, ILOidcLocation } from '@axa-fr/oidc-client';
2
2
  import React, { ComponentType, FC, PropsWithChildren, useEffect, useState } from 'react';
3
3
 
4
4
  import CallbackComponent from '../default-component/Callback.component.js';
@@ -24,9 +24,9 @@ const OidcRoutes: FC<PropsWithChildren<OidcRoutesProps>> = ({
24
24
  redirect_uri,
25
25
  silent_redirect_uri,
26
26
  silent_login_uri,
27
- children, configurationName,
28
- withCustomHistory = null,
29
- location,
27
+ children,
28
+ configurationName,
29
+ withCustomHistory = null,
30
30
  }) => {
31
31
  // This exist because in next.js window outside useEffect is null
32
32
  const pathname = window ? getPath(window.location.href) : '';
@@ -56,7 +56,14 @@ const OidcRoutes: FC<PropsWithChildren<OidcRoutesProps>> = ({
56
56
 
57
57
  switch (path) {
58
58
  case callbackPath:
59
- return <CallbackComponent callBackError={callbackErrorComponent} callBackSuccess={callbackSuccessComponent} configurationName={configurationName} withCustomHistory={withCustomHistory} />;
59
+ return (
60
+ <CallbackComponent
61
+ callBackError={callbackErrorComponent}
62
+ callBackSuccess={callbackSuccessComponent}
63
+ configurationName={configurationName}
64
+ withCustomHistory={withCustomHistory}
65
+ />
66
+ );
60
67
  default:
61
68
  return <>{children}</>;
62
69
  }
@@ -1,10 +1,10 @@
1
- import { beforeEach,describe, expect, it, vi } from 'vitest';
1
+ import { beforeEach, describe, expect, it, vi } from 'vitest';
2
2
 
3
3
  import { CreateEvent, WindowInternal } from './withRouter';
4
4
 
5
5
  describe('WithRouter test Suite', () => {
6
6
  const paramsMock = { bubbles: false, cancelable: false, detail: 'detail' };
7
- beforeEach(() => { });
7
+ beforeEach(() => {});
8
8
  it('should CreateEvent return correct Event if not on IE', () => {
9
9
  const windowMock = {
10
10
  CustomEvent: vi.fn().mockImplementation((event, params) => {
@@ -12,7 +12,7 @@ describe('WithRouter test Suite', () => {
12
12
  }),
13
13
  };
14
14
  const documentMock = {} as Document;
15
- const res = CreateEvent((windowMock as unknown) as WindowInternal, documentMock)(
15
+ const res = CreateEvent(windowMock as unknown as WindowInternal, documentMock)(
16
16
  'event test',
17
17
  paramsMock,
18
18
  );
@@ -34,8 +34,8 @@ describe('WithRouter test Suite', () => {
34
34
  const documentMock = {
35
35
  createEvent: vi.fn(() => evtMock),
36
36
  };
37
- const typedDocumentMock = (documentMock as unknown) as Document;
38
- const res = CreateEvent((windowMock as unknown) as WindowInternal, typedDocumentMock)(
37
+ const typedDocumentMock = documentMock as unknown as Document;
38
+ const res = CreateEvent(windowMock as unknown as WindowInternal, typedDocumentMock)(
39
39
  'event test',
40
40
  paramsMock,
41
41
  );
@@ -43,5 +43,4 @@ describe('WithRouter test Suite', () => {
43
43
  expect(documentMock.createEvent).toHaveBeenCalledWith('CustomEvent');
44
44
  expect(evtMock.initCustomEvent).toHaveBeenCalledWith('event test', false, false, 'detail');
45
45
  });
46
-
47
46
  });
@@ -1,7 +1,4 @@
1
- const generateKey = () =>
2
- Math.random()
3
- .toString(36)
4
- .substr(2, 6);
1
+ const generateKey = () => Math.random().toString(36).slice(2, 8);
5
2
 
6
3
  // Exported only for test
7
4
  export type WindowInternal = Window & {
@@ -20,19 +17,23 @@ type InitCustomEventParams<T = any> = {
20
17
  };
21
18
 
22
19
  // IE Polyfill for CustomEvent
23
- export const CreateEvent = (windowInternal: WindowInternal, documentInternal: Document) => (
24
- event: string,
25
- params: InitCustomEventParams,
26
- ): CustomEvent => {
27
- if (typeof windowInternal.CustomEvent === 'function') {
28
- return new windowInternal.CustomEvent(event, params);
29
- }
30
- const paramsToFunction = params || { bubbles: false, cancelable: false, detail: undefined };
31
- const evt: CustomEvent = documentInternal.createEvent('CustomEvent');
32
- evt.initCustomEvent(event, paramsToFunction.bubbles, paramsToFunction.cancelable, paramsToFunction.detail);
33
- (evt as CustomEvent & IPrototype).prototype = windowInternal.Event.prototype;
34
- return evt;
35
- };
20
+ export const CreateEvent =
21
+ (windowInternal: WindowInternal, documentInternal: Document) =>
22
+ (event: string, params: InitCustomEventParams): CustomEvent => {
23
+ if (typeof windowInternal.CustomEvent === 'function') {
24
+ return new windowInternal.CustomEvent(event, params);
25
+ }
26
+ const paramsToFunction = params || { bubbles: false, cancelable: false, detail: undefined };
27
+ const evt: CustomEvent = documentInternal.createEvent('CustomEvent');
28
+ evt.initCustomEvent(
29
+ event,
30
+ paramsToFunction.bubbles,
31
+ paramsToFunction.cancelable,
32
+ paramsToFunction.detail,
33
+ );
34
+ (evt as CustomEvent & IPrototype).prototype = windowInternal.Event.prototype;
35
+ return evt;
36
+ };
36
37
 
37
38
  type WindowHistoryState = typeof window.history.state;
38
39
 
@@ -42,7 +43,7 @@ export interface ReactOidcHistory {
42
43
 
43
44
  export type CustomHistory = {
44
45
  replaceState(url?: string | null, stateHistory?: WindowHistoryState): void;
45
- }
46
+ };
46
47
 
47
48
  const getHistory = (
48
49
  windowInternal: WindowInternal,
@@ -59,4 +60,5 @@ const getHistory = (
59
60
  };
60
61
  };
61
62
 
62
- export const getCustomHistory = () => getHistory(window, CreateEvent(window, document), generateKey);
63
+ export const getCustomHistory = () =>
64
+ getHistory(window, CreateEvent(window, document), generateKey);
package/src/index.ts CHANGED
@@ -6,9 +6,14 @@ export { OidcUserStatus, useOidcUser } from './User.js';
6
6
  export type {
7
7
  AuthorityConfiguration,
8
8
  Fetch,
9
+ ILOidcLocation,
9
10
  OidcConfiguration,
10
11
  StringMap,
11
- ILOidcLocation
12
12
  } from '@axa-fr/oidc-client';
13
- export { TokenRenewMode, OidcClient, TokenAutomaticRenewMode, OidcLocation } from '@axa-fr/oidc-client';
14
- export type { OidcUserInfo } from '@axa-fr/oidc-client';
13
+ export type { OidcUserInfo } from '@axa-fr/oidc-client';
14
+ export {
15
+ OidcClient,
16
+ OidcLocation,
17
+ TokenAutomaticRenewMode,
18
+ TokenRenewMode,
19
+ } from '@axa-fr/oidc-client';