asdf
Squash the current repository state back into one baseline commit while preserving the README reframing and repository contents. Constraint: User explicitly requested a single squashed commit with subject "asdf" Confidence: high Scope-risk: broad Reversibility: clean Directive: This commit intentionally rewrites published history; coordinate before future force-pushes Tested: git status clean; local history rewritten to one commit; force-pushed main to origin and instructkr Not-tested: Fresh clone verification after push
This commit is contained in:
commit
d2542c9a62
60
src/services/api/firstTokenDate.ts
Normal file
60
src/services/api/firstTokenDate.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import axios from 'axios'
|
||||
import { getOauthConfig } from '../../constants/oauth.js'
|
||||
import { getGlobalConfig, saveGlobalConfig } from '../../utils/config.js'
|
||||
import { getAuthHeaders } from '../../utils/http.js'
|
||||
import { logError } from '../../utils/log.js'
|
||||
import { getClaudeCodeUserAgent } from '../../utils/userAgent.js'
|
||||
|
||||
/**
|
||||
* Fetch the user's first Claude Code token date and store in config.
|
||||
* This is called after successful login to cache when they started using Claude Code.
|
||||
*/
|
||||
export async function fetchAndStoreClaudeCodeFirstTokenDate(): Promise<void> {
|
||||
try {
|
||||
const config = getGlobalConfig()
|
||||
|
||||
if (config.claudeCodeFirstTokenDate !== undefined) {
|
||||
return
|
||||
}
|
||||
|
||||
const authHeaders = getAuthHeaders()
|
||||
if (authHeaders.error) {
|
||||
logError(new Error(`Failed to get auth headers: ${authHeaders.error}`))
|
||||
return
|
||||
}
|
||||
|
||||
const oauthConfig = getOauthConfig()
|
||||
const url = `${oauthConfig.BASE_API_URL}/api/organization/claude_code_first_token_date`
|
||||
|
||||
const response = await axios.get(url, {
|
||||
headers: {
|
||||
...authHeaders.headers,
|
||||
'User-Agent': getClaudeCodeUserAgent(),
|
||||
},
|
||||
timeout: 10000,
|
||||
})
|
||||
|
||||
const firstTokenDate = response.data?.first_token_date ?? null
|
||||
|
||||
// Validate the date if it's not null
|
||||
if (firstTokenDate !== null) {
|
||||
const dateTime = new Date(firstTokenDate).getTime()
|
||||
if (isNaN(dateTime)) {
|
||||
logError(
|
||||
new Error(
|
||||
`Received invalid first_token_date from API: ${firstTokenDate}`,
|
||||
),
|
||||
)
|
||||
// Don't save invalid dates
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
saveGlobalConfig(current => ({
|
||||
...current,
|
||||
claudeCodeFirstTokenDate: firstTokenDate,
|
||||
}))
|
||||
} catch (error) {
|
||||
logError(error)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user