Dashboard › cli › Distillation
45af91aa-3a02-4339-8cc7-3e443285938f["lore_tm_v1_WShr8geMvHoIF7dmJEP9OlXziYoNxTqdGHAdqNTGTaM"]
packages/cli/src/lib/api/infrastructure.ts lines 462-477 define paginate<T>(options, fetchPage, defaultLimit = 10): computes limit = options.limit ?? defaultLimit, caps perPage with Math.min(limit, API_MAX_PER_PAGE), and calls autoPaginate((cursor) => fetchPage(perPage, cursor), limit, options.cursor).apiRequestToRegion<T> at packages/cli/src/lib/api/infrastructure.ts:489-555 defaults to method = "GET", obtains getSdkConfig(regionUrl), normalizes a leading / from endpoint, and constructs raw regional URLs as ${config.baseUrl}/api/0/${normalizedEndpoint}${queryString} using buildSearchParams(params).apiRequestToRegion<T> sets "Content-Type": "application/json" and JSON-stringifies defined request bodies. If bodyEncoding === "zstd" and zstdCompressAsync is available, it compresses Buffer.from(json) and adds "Content-Encoding": "zstd"; otherwise it sends the JSON string.apiRequestToRegion<T> calls throwRawApiError(response, endpoint).apiRequestToRegion<T> explicitly treats HTTP 204 No Content and 205 Reset Content as errors because response.json() would throw. It raises ApiError with message API returned ${response.status} ${response.statusText} (no body) and detail The server returned no content — the request may have matched no records. Comments note that callers expecting 204, such as a bulk mutate endpoint returning 204 when no IDs match, should catch and handle this ApiError.apiRequestToRegion<T> are logged with logger.debug("Failed to parse JSON response body", parseError) and converted to ApiError with message Invalid JSON in API response from ${endpoint} and detail The server returned a non-JSON response body (possible proxy or CDN issue).schema is supplied, apiRequestToRegion<T> validates response data using safeParse(schema, data). On failure, it begins attaching a Sentry.setContext("schema_validation", ...) context containing endpoint, HTTP status, and at most the first 10 validation issues via result.issues.slice(0, 10); comments specify retaining metadata such as path/type/message while stripping raw failing input values.