04 · Documentation

API reference

The SDK exposes a single class, X2YSdk, with four public methods and two optional configuration objects. All types ship with the package for full TypeScript IntelliSense.

new X2YSdk(apiConfig?, refactorConfig?)constructor

Creates an SDK instance. Both arguments are optional; omitted values fall back to documented defaults. The constructor performs no I/O and makes no network calls. Exposes sdk.version and sdk.config for diagnostics.

Constructor parameters
ParameterTypeDefaultDescription
apiConfig.rateLimitThresholdnumber80Percentage of quota consumed before an endpoint is flagged rateLimitApproaching.
apiConfig.predictionWindownumber60000Time window (ms) of recorded traffic considered by the prediction engine.
apiConfig.apiUrlstringBase URL used to scope traffic records and predictions.
refactorConfig.targetLanguagestring'typescript'Language assumed when parsing refactoring input.
refactorConfig.rulesstring[]['performance','idiom','async']Enabled rule sets: performance, idiom, async.
sdk.recordAPITraffic(record: TrafficRecord): voidmonitor

Records a single API interaction into the append-only in-memory index. Synchronous and allocation-light; safe to call on every request. Capable of ingesting thousands of records per second without blocking the event loop.

TrafficRecord fields
FieldTypeDescription
endpointstringRequest path or URL, e.g. '/api/users'.
methodstringHTTP method, e.g. 'GET', 'POST'.
timestampnumberEpoch milliseconds, typically Date.now().
responseTimenumberObserved latency in milliseconds.
statusCodenumberHTTP status code returned.
headersRecord<string,string>Raw response headers; rate-limit headers parsed when present.
sdk.predictAPIIssues(endpoint: string): Promise<Prediction>predict

Analyses recorded traffic for the given endpoint using standard deviation and coefficient-of-variation statistics over response times, and returns a Prediction object.

Prediction fields
FieldTypeDescription
endpointstringThe queried endpoint.
riskLevel'low' | 'medium' | 'high'Composite risk classification from CV analysis.
predictedFailurebooleanWhether a failure is anticipated within the prediction window.
rateLimitApproachingbooleanTrue when usage% exceeds rateLimitThreshold.
suggestedAlternativesstring[]Fallback strategies, e.g. cached endpoints.
confidencenumberDynamic confidence score, 50–98, penalized by CV.
Returns — Promise resolving to the Prediction object; see the playground release-gate sample for an exact payload.
sdk.refactorCode(code: string): Promise<RefactorSuggestion[]>refactor

Parses a raw code string with stateful, line-by-line traversal and brace-matching scope heuristics. Returns line-level suggestions carrying the exact corrected snippet, the offending line and a severity of low | medium | high | critical.

Returns — Array of { type, description, originalCode, suggestedCode, line, severity } . Rule categories: performance (N+1, DOM thrashing, repeated allocations), idiom, async.
sdk.refactorFile(path: string): Promise<RefactorSuggestion[]>refactor

Reads a local JavaScript or TypeScript file from disk and runs the full refactoring engine over it. The file is read locally and never transmitted; results are identical in shape to refactorCode.

const fileSuggestions = await sdk.refactorFile('./src/example.js');
console.log(`${fileSuggestions.length} suggestions found`);
type RefactorSuggestiontypes
RefactorSuggestion fields
FieldTypeDescription
type'performance' | 'idiom' | 'async'Rule category that produced the suggestion.
descriptionstringHuman-readable explanation of the issue and fix.
originalCodestringThe offending code fragment.
suggestedCodestringThe exact corrected snippet.
linenumber1-based line number of the finding.
severity'low' | 'medium' | 'high' | 'critical'Severity classification; N+1 queries are critical.
env X2Y_AUTO_REFACTORenvironment

Set X2Y_AUTO_REFACTOR=true to automatically apply high-severity refactoring suggestions during build steps. Disabled by default. Review diffs first in production pipelines.

history Changelogreleases
Changelog
VersionDateNotes
v1.0.42026Current stable. Statistical predictive analytics (μ, σ, CV) with dynamic confidence scoring; heuristic static analysis with scoped context tracking; N+1, DOM-thrashing and repeated-allocation detection; async modernization; rate-limit heuristics with fallback routing; append-only in-memory telemetry. Release gate validated via the unified playground suite.
v0.9.x2026Public beta. Refactoring engine hardening, severity calibration, X2Y_AUTO_REFACTOR flag.
v0.5.x2025Internal alpha. Core monitor and refactor prototypes developed within the x2y suite.

Ready to integrate

Ship safer API integrations and cleaner code reviews.

Start with the installation guide, inspect the full API reference, or audit the release-gate playground before deploying x2y SDK into your own Node.js or TypeScript stack.