(authCode: string)
| 6 | } |
| 7 | |
| 8 | export function parseCliAuthCodeShape(authCode: string): { |
| 9 | fingerprintId: string |
| 10 | expiresAt: string |
| 11 | receivedHash: string |
| 12 | } { |
| 13 | const normalizedAuthCode = authCode.trim() |
| 14 | const hashSeparatorIndex = normalizedAuthCode.lastIndexOf('.') |
| 15 | const expiresSeparatorIndex = normalizedAuthCode.lastIndexOf( |
| 16 | '.', |
| 17 | hashSeparatorIndex - 1, |
| 18 | ) |
| 19 | |
| 20 | if (hashSeparatorIndex === -1 || expiresSeparatorIndex === -1) { |
| 21 | const legacyMatch = normalizedAuthCode.match( |
| 22 | /^(?<fingerprintId>.+)-(?<expiresAt>\d+)-(?<receivedHash>[a-f0-9]{64})$/i, |
| 23 | ) |
| 24 | if (legacyMatch?.groups) { |
| 25 | return { |
| 26 | fingerprintId: legacyMatch.groups.fingerprintId, |
| 27 | expiresAt: legacyMatch.groups.expiresAt, |
| 28 | receivedHash: legacyMatch.groups.receivedHash, |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | return { fingerprintId: '', expiresAt: '', receivedHash: '' } |
| 33 | } |
| 34 | |
| 35 | const fingerprintId = normalizedAuthCode.slice(0, expiresSeparatorIndex) |
| 36 | const expiresAt = normalizedAuthCode.slice( |
| 37 | expiresSeparatorIndex + 1, |
| 38 | hashSeparatorIndex, |
| 39 | ) |
| 40 | const receivedHash = normalizedAuthCode.slice(hashSeparatorIndex + 1) |
| 41 | |
| 42 | return { fingerprintId, expiresAt, receivedHash } |
| 43 | } |
| 44 | |
| 45 | export function isCliAuthCodeCandidate(authCode: string): boolean { |
| 46 | if (isOpaqueCliAuthCodeToken(authCode)) { |
no outgoing calls
no test coverage detected