@mereb/web-runtime 0.0.3 → 0.0.5

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/dist/config.d.ts CHANGED
@@ -5,6 +5,7 @@ type ShellRuntimeEnv = {
5
5
  KEYCLOAK_URL?: string;
6
6
  KC_REALM?: string;
7
7
  KC_CLIENT_ID?: string;
8
+ KC_SILENT_CHECK_SSO_PATH?: string;
8
9
  };
9
10
  declare global {
10
11
  interface Window {
@@ -19,6 +20,7 @@ export declare const appConfig: {
19
20
  url: string;
20
21
  realm: string;
21
22
  clientId: string;
23
+ silentCheckSsoPath: string;
22
24
  };
23
25
  };
24
26
  export type AppConfig = typeof appConfig;
package/dist/config.js CHANGED
@@ -4,7 +4,8 @@ const defaultRuntime = {
4
4
  FLAGS_URL: 'http://localhost:8000/flags',
5
5
  KEYCLOAK_URL: 'http://localhost:8081',
6
6
  KC_REALM: 'social',
7
- KC_CLIENT_ID: 'web-shell'
7
+ KC_CLIENT_ID: 'web-shell',
8
+ KC_SILENT_CHECK_SSO_PATH: ''
8
9
  };
9
10
  const runtimeEnv = globalThis.window === undefined ? {} : globalThis.window.__MEREB_ENV__ ?? {};
10
11
  function resolveEnv(metaValue, key) {
@@ -25,7 +26,8 @@ export const appConfig = {
25
26
  keycloak: {
26
27
  url: resolveEnv(import.meta.env.VITE_KEYCLOAK_URL, 'KEYCLOAK_URL'),
27
28
  realm: resolveEnv(import.meta.env.VITE_KC_REALM, 'KC_REALM'),
28
- clientId: resolveEnv(import.meta.env.VITE_KC_CLIENT_ID, 'KC_CLIENT_ID')
29
+ clientId: resolveEnv(import.meta.env.VITE_KC_CLIENT_ID, 'KC_CLIENT_ID'),
30
+ silentCheckSsoPath: resolveEnv(import.meta.env.VITE_KC_SILENT_CHECK_SSO_PATH, 'KC_SILENT_CHECK_SSO_PATH')
29
31
  }
30
32
  };
31
33
  export function resolveKeycloakMissingKeys() {
@@ -9,7 +9,7 @@ export type AuthProfile = {
9
9
  roles: string[];
10
10
  adminAccess: AdminAccessLevel;
11
11
  };
12
- type AuthContextValue = {
12
+ export type AuthContextValue = {
13
13
  isReady: boolean;
14
14
  isAuthConfigured: boolean;
15
15
  isAuthenticated: boolean;
@@ -22,6 +22,7 @@ type AuthContextValue = {
22
22
  hasAnyRole: (roles: string[]) => boolean;
23
23
  missingConfigKeys: readonly string[];
24
24
  };
25
+ export declare const AuthCtx: import("react").Context<AuthContextValue>;
25
26
  export declare function AuthProvider({ children }: Readonly<{
26
27
  children: ReactNode;
27
28
  }>): import("react/jsx-runtime").JSX.Element;
@@ -2,7 +2,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react';
3
3
  import Keycloak from 'keycloak-js';
4
4
  import { appConfig, resolveKeycloakMissingKeys } from '../config.js';
5
- const AuthCtx = createContext({
5
+ export const AuthCtx = createContext({
6
6
  isReady: false,
7
7
  isAuthConfigured: false,
8
8
  isAuthenticated: false,
@@ -99,6 +99,16 @@ function resetPkceState(instance) {
99
99
  ;
100
100
  instance.pkceMethod = undefined;
101
101
  }
102
+ function resolveSilentCheckSsoRedirectUri() {
103
+ if (typeof window === 'undefined' || !window.location?.origin) {
104
+ return undefined;
105
+ }
106
+ const silentCheckSsoPath = appConfig.keycloak.silentCheckSsoPath?.trim();
107
+ if (!silentCheckSsoPath) {
108
+ return undefined;
109
+ }
110
+ return new URL(silentCheckSsoPath, window.location.origin).toString();
111
+ }
102
112
  async function attemptKeycloakInit(instance, options) {
103
113
  try {
104
114
  return await instance.init(options);
@@ -119,7 +129,15 @@ function initKeycloak() {
119
129
  return Promise.resolve(false);
120
130
  if (!keycloakInitPromise) {
121
131
  const instance = getKeycloak();
132
+ const silentCheckSsoRedirectUri = resolveSilentCheckSsoRedirectUri();
122
133
  const options = {
134
+ ...(silentCheckSsoRedirectUri
135
+ ? {
136
+ onLoad: 'check-sso',
137
+ silentCheckSsoRedirectUri,
138
+ silentCheckSsoFallback: false
139
+ }
140
+ : {}),
123
141
  pkceMethod: 'S256',
124
142
  checkLoginIframe: false,
125
143
  useNonce: false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mereb/web-runtime",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -58,9 +58,9 @@
58
58
  "scripts": {
59
59
  "clean": "node -e \"const fs=require('node:fs'); fs.rmSync('dist',{recursive:true,force:true}); fs.rmSync('tsconfig.tsbuildinfo',{force:true});\"",
60
60
  "typecheck": "tsc --noEmit --project tsconfig.json",
61
- "test": "pnpm exec vitest run --config vitest.config.ts",
62
- "test:watch": "pnpm exec vitest --config vitest.config.ts",
63
- "build": "pnpm run clean && tsc --project tsconfig.json",
61
+ "test": "vitest run --config vitest.config.ts",
62
+ "test:watch": "vitest --config vitest.config.ts",
63
+ "build": "node -e \"const fs=require('node:fs'); fs.rmSync('dist',{recursive:true,force:true}); fs.rmSync('tsconfig.tsbuildinfo',{force:true});\" && tsc --project tsconfig.json",
64
64
  "version:bump": "node ./scripts/bump-version.mjs"
65
65
  }
66
66
  }