awsAuthStatusManager.ts
utils/awsAuthStatusManager.ts
No strong subsystem tag
82
Lines
2043
Bytes
2
Exports
1
Imports
10
Keywords
What this is
This page documents one file from the repository and includes its full source so you can read it without leaving the docs site.
Beginner explanation
This file is one piece of the larger system. Its name, directory, imports, and exports show where it fits. Start by reading the exports and related files first.
How it is used
Start from the exports list and related files. Those are the easiest clues for where this file fits into the system.
Expert explanation
Architecturally, this file intersects with general runtime concerns. It contains 82 lines, 1 detected imports, and 2 detected exports.
Important relationships
Detected exports
AwsAuthStatusAwsAuthStatusManager
Keywords
statusawsauthstatusmanageroutputinstancechangedisauthenticatinggetstatusvoidawsauthstatusemit
Detected imports
./signal.js
Source notes
This page embeds the full file contents. Small or leaf files are still indexed honestly instead of being over-explained.
Full source
/**
* Singleton manager for cloud-provider authentication status (AWS Bedrock,
* GCP Vertex). Communicates auth refresh state between auth utilities and
* React components / SDK output. The SDK 'auth_status' message shape is
* provider-agnostic, so a single manager serves all providers.
*
* Legacy name: originally AWS-only; now used by all cloud auth refresh flows.
*/
import { createSignal } from './signal.js'
export type AwsAuthStatus = {
isAuthenticating: boolean
output: string[]
error?: string
}
export class AwsAuthStatusManager {
private static instance: AwsAuthStatusManager | null = null
private status: AwsAuthStatus = {
isAuthenticating: false,
output: [],
}
private changed = createSignal<[status: AwsAuthStatus]>()
static getInstance(): AwsAuthStatusManager {
if (!AwsAuthStatusManager.instance) {
AwsAuthStatusManager.instance = new AwsAuthStatusManager()
}
return AwsAuthStatusManager.instance
}
getStatus(): AwsAuthStatus {
return {
...this.status,
output: [...this.status.output],
}
}
startAuthentication(): void {
this.status = {
isAuthenticating: true,
output: [],
}
this.changed.emit(this.getStatus())
}
addOutput(line: string): void {
this.status.output.push(line)
this.changed.emit(this.getStatus())
}
setError(error: string): void {
this.status.error = error
this.changed.emit(this.getStatus())
}
endAuthentication(success: boolean): void {
if (success) {
// Clear the status completely on success
this.status = {
isAuthenticating: false,
output: [],
}
} else {
// Keep the output visible on failure
this.status.isAuthenticating = false
}
this.changed.emit(this.getStatus())
}
subscribe = this.changed.subscribe
// Clean up for testing
static reset(): void {
if (AwsAuthStatusManager.instance) {
AwsAuthStatusManager.instance.changed.clear()
AwsAuthStatusManager.instance = null
}
}
}