* Fetch policy limits (single attempt, no retries)
( cachedChecksum?: string, )
| 298 | * Fetch policy limits (single attempt, no retries) |
| 299 | */ |
| 300 | async function fetchPolicyLimits( |
| 301 | cachedChecksum?: string, |
| 302 | ): Promise<PolicyLimitsFetchResult> { |
| 303 | try { |
| 304 | await checkAndRefreshOAuthTokenIfNeeded() |
| 305 | |
| 306 | const authHeaders = getAuthHeaders() |
| 307 | if (authHeaders.error) { |
| 308 | return { |
| 309 | success: false, |
| 310 | error: 'Authentication required for policy limits', |
| 311 | skipRetry: true, |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | const endpoint = getPolicyLimitsEndpoint() |
| 316 | const headers: Record<string, string> = { |
| 317 | ...authHeaders.headers, |
| 318 | 'User-Agent': getClaudeCodeUserAgent(), |
| 319 | } |
| 320 | |
| 321 | if (cachedChecksum) { |
| 322 | headers['If-None-Match'] = `"${cachedChecksum}"` |
| 323 | } |
| 324 | |
| 325 | const response = await axios.get(endpoint, { |
| 326 | headers, |
| 327 | timeout: FETCH_TIMEOUT_MS, |
| 328 | validateStatus: status => |
| 329 | status === 200 || status === 304 || status === 404, |
| 330 | }) |
| 331 | |
| 332 | // Handle 304 Not Modified - cached version is still valid |
| 333 | if (response.status === 304) { |
| 334 | logForDebugging('Policy limits: Using cached restrictions (304)') |
| 335 | return { |
| 336 | success: true, |
| 337 | restrictions: null, // Signal that cache is valid |
| 338 | etag: cachedChecksum, |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | // Handle 404 Not Found - no policy limits exist or feature not enabled |
| 343 | if (response.status === 404) { |
| 344 | logForDebugging('Policy limits: No restrictions found (404)') |
| 345 | return { |
| 346 | success: true, |
| 347 | restrictions: {}, |
| 348 | etag: undefined, |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | const parsed = PolicyLimitsResponseSchema().safeParse(response.data) |
| 353 | if (!parsed.success) { |
| 354 | logForDebugging( |
| 355 | `Policy limits: Invalid response format - ${parsed.error.message}`, |
| 356 | ) |
| 357 | return { |
no test coverage detected