Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/javascript/bh-shared-ui/src/hooks/useConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import {
ConfigurationPayload,
parseAPITokenExpirationConfiguration,
parseAPITokensConfiguration,
parseTieringConfiguration,
parseTimeoutLimitConfiguration,
Expand Down Expand Up @@ -53,6 +54,16 @@ export const useAPITokensConfiguration = () => {
return apiTokensConfig;
};

export const useAPITokenExpirationConfiguration = () => {
const { data } = useGetConfiguration();
const apiTokenExpirationConfig = parseAPITokenExpirationConfiguration(data)?.value;

return {
enabled: apiTokenExpirationConfig?.enabled ?? false,
expiration_period: apiTokenExpirationConfig?.expiration_period ?? '90',
};
};
Comment on lines +57 to +65
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Don't collapse loading state into { enabled: false, days: '90' }.

This makes “query still loading” look identical to a real config value. Any form that snapshots this hook into local state on first render can save 90 over an existing server value before the fetch resolves. Keep the fallback for the “loaded but missing” case only, or surface loading explicitly.

💡 Suggested fix
 export const useAPITokenExpirationConfiguration = () => {
-    const { data } = useGetConfiguration();
+    const { data, isLoading } = useGetConfiguration();
     const apiTokenExpirationConfig = parseAPITokenExpirationConfiguration(data)?.value;
+
+    if (isLoading) return undefined;
 
     return {
         enabled: apiTokenExpirationConfig?.enabled ?? false,
         days: apiTokenExpirationConfig?.days ?? '90',
     };
 };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/javascript/bh-shared-ui/src/hooks/useConfiguration.ts` around lines
57 - 65, The hook useAPITokenExpirationConfiguration is collapsing the "still
loading" state into the default {enabled: false, days: '90'}, which makes
loading indistinguishable from an actual server value; change it to preserve
loading explicitly (or return undefined for fields while loading) by checking
the query status from useGetConfiguration() before applying defaults from
parseAPITokenExpirationConfiguration(data) — for example, return a structure
that includes a loading flag (or leaves days undefined) when the query is not
settled, and only apply the fallback defaults ('90' and false) when the
configuration is loaded or known-missing; update callers to handle the explicit
loading/undefined state.


export const useTimeoutLimitConfiguration = () => {
const { data } = useGetConfiguration();
const timeoutLimitConfig = parseTimeoutLimitConfiguration(data)?.value.enabled;
Expand Down
19 changes: 19 additions & 0 deletions packages/javascript/js-client-library/src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export enum ConfigurationKey {
Tiering = 'analysis.tiering',
TimeoutLimit = 'api.timeout_limit',
APITokens = 'auth.api_tokens',
APITokenExpiration = 'auth.api_token_expiration',
ScheduledAnalysis = 'analysis.scheduled',
}

Expand Down Expand Up @@ -110,6 +111,14 @@ export type APITokensConfiguration = {
};
};

export type APITokenExpirationConfiguration = {
key: ConfigurationKey.APITokenExpiration;
value: {
enabled: boolean;
expiration_period: string;
};
};

export type ConfigurationPayload =
| PasswordExpirationConfiguration
| Neo4jConfiguration
Expand All @@ -118,6 +127,7 @@ export type ConfigurationPayload =
| PruneTTLConfiguration
| TieringConfiguration
| APITokensConfiguration
| APITokenExpirationConfiguration
| ScheduledAnalysisConfiguration
| TimeoutLimitConfiguration;

Expand Down Expand Up @@ -197,6 +207,15 @@ export const parseAPITokensConfiguration = (
return config?.key === key ? config : undefined;
};

export const parseAPITokenExpirationConfiguration = (
response: GetConfigurationResponse | undefined
): ConfigurationWithMetadata<APITokenExpirationConfiguration> | undefined => {
const key = ConfigurationKey.APITokenExpiration;
const config = getConfigurationFromKey(response, key);

return config?.key === key ? config : undefined;
};

export const parseScheduledAnalysisConfiguration = (
response: GetConfigurationResponse | undefined
): ConfigurationWithMetadata<ScheduledAnalysisConfiguration> | undefined => {
Expand Down
Loading