Files
OmniRoute/src/lib/oauth/kiroConnectionIdentity.ts
nguyenha935 d4b9ce6016 fix(kiro): harden auth flows, quota lookup, and model discovery (#8565)
* fix(kiro): fetch builder id quota without profile arn

* fix(kiro): harden auth imports polling and model discovery

* fix(kiro): preserve auth identity and OAuth polling semantics

* docs(changelog): add Kiro auth and model discovery fix

---------

Co-authored-by: Nguyễn Thanh Hà <nguyenha@Mac-mini-M4.local>
Co-authored-by: nguyenha935 <208228297+nguyenha935@users.noreply.github.com>
2026-07-26 03:53:47 -03:00

73 lines
1.9 KiB
TypeScript

export type KiroConnectionLike = {
id?: unknown;
authType?: unknown;
name?: unknown;
email?: unknown;
providerSpecificData?: unknown;
[key: string]: unknown;
};
export type KiroConnectionIdentity = {
authType?: unknown;
profileArn?: unknown;
clientId?: unknown;
email?: unknown;
name?: unknown;
};
function trimmed(value: unknown): string {
return typeof value === "string" ? value.trim() : "";
}
function folded(value: unknown): string {
return trimmed(value).toLowerCase();
}
function providerData(connection: KiroConnectionLike): Record<string, unknown> {
const value = connection.providerSpecificData;
return value && typeof value === "object" && !Array.isArray(value)
? (value as Record<string, unknown>)
: {};
}
/** Find an existing Kiro account without comparing OAuth tokens or API keys. */
export function findKiroConnectionByIdentity(
connections: KiroConnectionLike[],
identity: KiroConnectionIdentity
): KiroConnectionLike | null {
const authType = folded(identity.authType);
const candidates = authType
? connections.filter((connection) => folded(connection.authType) === authType)
: connections;
const profileArn = trimmed(identity.profileArn);
if (profileArn) {
const match = candidates.find(
(connection) => trimmed(providerData(connection).profileArn) === profileArn
);
if (match) return match;
}
const clientId = trimmed(identity.clientId);
if (clientId) {
const match = candidates.find(
(connection) => trimmed(providerData(connection).clientId) === clientId
);
if (match) return match;
}
const email = folded(identity.email);
if (email) {
const match = candidates.find((connection) => folded(connection.email) === email);
if (match) return match;
}
const name = folded(identity.name);
if (name) {
const match = candidates.find((connection) => folded(connection.name) === name);
if (match) return match;
}
return null;
}