@coderifts/sdk 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,86 @@
1
+ # @coderifts/sdk
2
+
3
+ TypeScript client for the [CodeRifts](https://coderifts.com) API — detect breaking changes, score API agent-readiness, and monitor API stability.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @coderifts/sdk
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```ts
14
+ import { CodeRifts } from '@coderifts/sdk';
15
+
16
+ const client = new CodeRifts({ apiKey: 'cr_live_...' });
17
+
18
+ // Diff two OpenAPI specs
19
+ const diff = await client.diff({
20
+ old_spec: oldYaml,
21
+ new_spec: newYaml,
22
+ });
23
+ console.log(diff.breaking_changes_count, diff.risk_level);
24
+
25
+ // Score an MCP manifest for agent readiness
26
+ const score = await client.agentReadinessScore({
27
+ spec: mcpManifest,
28
+ spec_type: 'mcp',
29
+ });
30
+ console.log(score.score, score.band); // 100 STRONG
31
+
32
+ // Get API stability analytics
33
+ const analytics = await client.stability({
34
+ repo: 'myorg/api-service',
35
+ days: 30,
36
+ });
37
+ console.log(analytics.summary.block_rate);
38
+ ```
39
+
40
+ ## API Reference
41
+
42
+ ### `new CodeRifts(options)`
43
+
44
+ | Option | Type | Default | Description |
45
+ |---|---|---|---|
46
+ | `apiKey` | `string` | *required* | Your API key (`cr_live_...` or `cr_test_...`) |
47
+ | `baseUrl` | `string` | `https://app.coderifts.com` | API base URL |
48
+ | `timeout` | `number` | `30000` | Request timeout in ms |
49
+
50
+ ### Methods
51
+
52
+ | Method | Description | Auth Required |
53
+ |---|---|---|
54
+ | `diff(req)` | Compare two OpenAPI specs | Yes |
55
+ | `agentReadinessScore(req)` | Score a spec for agent readiness | Yes |
56
+ | `scoreMcp(url)` | Score an MCP manifest by URL | No |
57
+ | `stability(req)` | Get API stability analytics | Yes |
58
+ | `agentPreflight(req)` | Generate tool schemas from a spec | Yes |
59
+
60
+ ### Error Handling
61
+
62
+ ```ts
63
+ import { ApiError, AuthError, RateLimitError, TimeoutError } from '@coderifts/sdk';
64
+
65
+ try {
66
+ await client.diff({ old_spec, new_spec });
67
+ } catch (err) {
68
+ if (err instanceof RateLimitError) {
69
+ console.log('Rate limited, retry later');
70
+ } else if (err instanceof AuthError) {
71
+ console.log('Invalid API key');
72
+ } else if (err instanceof TimeoutError) {
73
+ console.log('Request timed out');
74
+ } else if (err instanceof ApiError) {
75
+ console.log(err.status, err.code, err.body);
76
+ }
77
+ }
78
+ ```
79
+
80
+ ## Get an API Key
81
+
82
+ Sign up at [app.coderifts.com/api/signup](https://app.coderifts.com/api/signup) — the free tier includes 50 requests/month.
83
+
84
+ ## License
85
+
86
+ MIT
@@ -0,0 +1,70 @@
1
+ /**
2
+ * @coderifts/sdk — Client
3
+ *
4
+ * TypeScript client for the CodeRifts API.
5
+ * Uses native fetch (Node 18+).
6
+ */
7
+ import type { CodeRiftsOptions, DiffRequest, DiffResponse, ReadinessRequest, ReadinessResponse, McpScoreResponse, StabilityRequest, StabilityResponse, PreflightRequest, PreflightResponse } from './types';
8
+ export declare class CodeRifts {
9
+ private readonly apiKey;
10
+ private readonly baseUrl;
11
+ private readonly timeout;
12
+ constructor(options: CodeRiftsOptions);
13
+ private request;
14
+ /**
15
+ * Compare two OpenAPI specs and detect breaking changes.
16
+ *
17
+ * ```ts
18
+ * const result = await client.diff({
19
+ * old_spec: oldYaml,
20
+ * new_spec: newYaml,
21
+ * });
22
+ * console.log(result.breaking_changes_count);
23
+ * ```
24
+ */
25
+ diff(req: DiffRequest): Promise<DiffResponse>;
26
+ /**
27
+ * Score an OpenAPI or MCP manifest for agent readiness.
28
+ *
29
+ * ```ts
30
+ * const result = await client.agentReadinessScore({
31
+ * spec: manifestJson,
32
+ * spec_type: 'mcp',
33
+ * });
34
+ * console.log(result.score, result.band);
35
+ * ```
36
+ */
37
+ agentReadinessScore(req: ReadinessRequest): Promise<ReadinessResponse>;
38
+ /**
39
+ * Score an MCP manifest by URL (public, no auth required).
40
+ * Note: This method does NOT use the API key.
41
+ *
42
+ * ```ts
43
+ * const result = await client.scoreMcp('https://example.com/mcp.json');
44
+ * console.log(result.score, result.band);
45
+ * ```
46
+ */
47
+ scoreMcp(url: string): Promise<McpScoreResponse>;
48
+ /**
49
+ * Get API stability analytics for a repository.
50
+ *
51
+ * ```ts
52
+ * const analytics = await client.stability({
53
+ * repo: 'myorg/api-service',
54
+ * days: 30,
55
+ * });
56
+ * console.log(analytics.summary.block_rate);
57
+ * ```
58
+ */
59
+ stability(req: StabilityRequest): Promise<StabilityResponse>;
60
+ /**
61
+ * Generate agent-consumable tool schemas from an OpenAPI spec.
62
+ *
63
+ * ```ts
64
+ * const preflight = await client.agentPreflight({ spec: specYaml });
65
+ * console.log(preflight.tools);
66
+ * ```
67
+ */
68
+ agentPreflight(req: PreflightRequest): Promise<PreflightResponse>;
69
+ }
70
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,gBAAgB,EAChB,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,SAAS,CAAC;AAOjB,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;gBAErB,OAAO,EAAE,gBAAgB;YAavB,OAAO;IAyCrB;;;;;;;;;;OAUG;IACG,IAAI,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;IAInD;;;;;;;;;;OAUG;IACG,mBAAmB,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAI5E;;;;;;;;OAQG;IACG,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAwBtD;;;;;;;;;;OAUG;IACG,SAAS,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAMlE;;;;;;;OAOG;IACG,cAAc,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,iBAAiB,CAAC;CAGxE"}
package/dist/client.js ADDED
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+ /**
3
+ * @coderifts/sdk — Client
4
+ *
5
+ * TypeScript client for the CodeRifts API.
6
+ * Uses native fetch (Node 18+).
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.CodeRifts = void 0;
10
+ const errors_1 = require("./errors");
11
+ const DEFAULT_BASE_URL = 'https://app.coderifts.com';
12
+ const DEFAULT_TIMEOUT = 30_000;
13
+ class CodeRifts {
14
+ apiKey;
15
+ baseUrl;
16
+ timeout;
17
+ constructor(options) {
18
+ if (!options.apiKey) {
19
+ throw new Error('apiKey is required');
20
+ }
21
+ this.apiKey = options.apiKey;
22
+ this.baseUrl = (options.baseUrl || DEFAULT_BASE_URL).replace(/\/+$/, '');
23
+ this.timeout = options.timeout || DEFAULT_TIMEOUT;
24
+ }
25
+ // ---------------------------------------------------------------
26
+ // Internal HTTP helper
27
+ // ---------------------------------------------------------------
28
+ async request(method, path, body) {
29
+ const url = `${this.baseUrl}${path}`;
30
+ const controller = new AbortController();
31
+ const timer = setTimeout(() => controller.abort(), this.timeout);
32
+ try {
33
+ const res = await fetch(url, {
34
+ method,
35
+ headers: {
36
+ 'Content-Type': 'application/json',
37
+ 'Authorization': `Bearer ${this.apiKey}`,
38
+ },
39
+ body: body ? JSON.stringify(body) : undefined,
40
+ signal: controller.signal,
41
+ });
42
+ const json = await res.json();
43
+ if (!res.ok) {
44
+ const errorBody = { error: json.error || 'unknown', message: json.message || res.statusText };
45
+ if (res.status === 401)
46
+ throw new errors_1.AuthError(errorBody);
47
+ if (res.status === 429)
48
+ throw new errors_1.RateLimitError(errorBody);
49
+ throw new errors_1.ApiError(res.status, errorBody);
50
+ }
51
+ return json;
52
+ }
53
+ catch (err) {
54
+ if (err instanceof errors_1.ApiError)
55
+ throw err;
56
+ if (err.name === 'AbortError') {
57
+ throw new errors_1.TimeoutError(this.timeout);
58
+ }
59
+ throw err;
60
+ }
61
+ finally {
62
+ clearTimeout(timer);
63
+ }
64
+ }
65
+ // ---------------------------------------------------------------
66
+ // Public methods
67
+ // ---------------------------------------------------------------
68
+ /**
69
+ * Compare two OpenAPI specs and detect breaking changes.
70
+ *
71
+ * ```ts
72
+ * const result = await client.diff({
73
+ * old_spec: oldYaml,
74
+ * new_spec: newYaml,
75
+ * });
76
+ * console.log(result.breaking_changes_count);
77
+ * ```
78
+ */
79
+ async diff(req) {
80
+ return this.request('POST', '/api/v1/diff', req);
81
+ }
82
+ /**
83
+ * Score an OpenAPI or MCP manifest for agent readiness.
84
+ *
85
+ * ```ts
86
+ * const result = await client.agentReadinessScore({
87
+ * spec: manifestJson,
88
+ * spec_type: 'mcp',
89
+ * });
90
+ * console.log(result.score, result.band);
91
+ * ```
92
+ */
93
+ async agentReadinessScore(req) {
94
+ return this.request('POST', '/api/v1/agent-readiness-score', req);
95
+ }
96
+ /**
97
+ * Score an MCP manifest by URL (public, no auth required).
98
+ * Note: This method does NOT use the API key.
99
+ *
100
+ * ```ts
101
+ * const result = await client.scoreMcp('https://example.com/mcp.json');
102
+ * console.log(result.score, result.band);
103
+ * ```
104
+ */
105
+ async scoreMcp(url) {
106
+ const fullUrl = `${this.baseUrl}/api/v1/score-mcp?url=${encodeURIComponent(url)}`;
107
+ const controller = new AbortController();
108
+ const timer = setTimeout(() => controller.abort(), this.timeout);
109
+ try {
110
+ const res = await fetch(fullUrl, { signal: controller.signal });
111
+ const json = await res.json();
112
+ if (!res.ok) {
113
+ const errorBody = { error: json.error || 'unknown', message: json.message || res.statusText };
114
+ throw new errors_1.ApiError(res.status, errorBody);
115
+ }
116
+ return json;
117
+ }
118
+ catch (err) {
119
+ if (err instanceof errors_1.ApiError)
120
+ throw err;
121
+ if (err.name === 'AbortError')
122
+ throw new errors_1.TimeoutError(this.timeout);
123
+ throw err;
124
+ }
125
+ finally {
126
+ clearTimeout(timer);
127
+ }
128
+ }
129
+ /**
130
+ * Get API stability analytics for a repository.
131
+ *
132
+ * ```ts
133
+ * const analytics = await client.stability({
134
+ * repo: 'myorg/api-service',
135
+ * days: 30,
136
+ * });
137
+ * console.log(analytics.summary.block_rate);
138
+ * ```
139
+ */
140
+ async stability(req) {
141
+ const params = new URLSearchParams({ repo: req.repo });
142
+ if (req.days)
143
+ params.set('days', String(req.days));
144
+ return this.request('GET', `/api/v1/analytics/stability?${params}`);
145
+ }
146
+ /**
147
+ * Generate agent-consumable tool schemas from an OpenAPI spec.
148
+ *
149
+ * ```ts
150
+ * const preflight = await client.agentPreflight({ spec: specYaml });
151
+ * console.log(preflight.tools);
152
+ * ```
153
+ */
154
+ async agentPreflight(req) {
155
+ return this.request('POST', '/api/v1/agent/preflight', req);
156
+ }
157
+ }
158
+ exports.CodeRifts = CodeRifts;
159
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAeH,qCAA6E;AAE7E,MAAM,gBAAgB,GAAG,2BAA2B,CAAC;AACrD,MAAM,eAAe,GAAG,MAAM,CAAC;AAE/B,MAAa,SAAS;IACH,MAAM,CAAS;IACf,OAAO,CAAS;IAChB,OAAO,CAAS;IAEjC,YAAY,OAAyB;QACnC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;YACpB,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;QACxC,CAAC;QACD,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MA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AC,OAAO,CAAoB,MAAM,EAAE,yBAAyB,EAAE,GAAG,CAAC,CAAC;IACjF,CAAC;CACF;AAtJD,8BAsJC"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @coderifts/sdk — Error classes
3
+ */
4
+ import type { ApiErrorBody } from './types';
5
+ /**
6
+ * Base error for all CodeRifts API errors.
7
+ */
8
+ export declare class CodeRiftsError extends Error {
9
+ constructor(message: string);
10
+ }
11
+ /**
12
+ * Thrown when the API returns a non-2xx status code.
13
+ */
14
+ export declare class ApiError extends CodeRiftsError {
15
+ readonly status: number;
16
+ readonly code: string;
17
+ readonly body: ApiErrorBody;
18
+ constructor(status: number, body: ApiErrorBody);
19
+ }
20
+ /**
21
+ * Thrown when the request times out.
22
+ */
23
+ export declare class TimeoutError extends CodeRiftsError {
24
+ constructor(timeoutMs: number);
25
+ }
26
+ /**
27
+ * Thrown when rate limited (429).
28
+ */
29
+ export declare class RateLimitError extends ApiError {
30
+ constructor(body: ApiErrorBody);
31
+ }
32
+ /**
33
+ * Thrown when authentication fails (401).
34
+ */
35
+ export declare class AuthError extends ApiError {
36
+ constructor(body: ApiErrorBody);
37
+ }
38
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C;;GAEG;AACH,qBAAa,cAAe,SAAQ,KAAK;gBAC3B,OAAO,EAAE,MAAM;CAI5B;AAED;;GAEG;AACH,qBAAa,QAAS,SAAQ,cAAc;IAC1C,SAAgB,MAAM,EAAE,MAAM,CAAC;IAC/B,SAAgB,IAAI,EAAE,MAAM,CAAC;IAC7B,SAAgB,IAAI,EAAE,YAAY,CAAC;gBAEvB,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY;CAO/C;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,cAAc;gBAClC,SAAS,EAAE,MAAM;CAI9B;AAED;;GAEG;AACH,qBAAa,cAAe,SAAQ,QAAQ;gBAC9B,IAAI,EAAE,YAAY;CAI/B;AAED;;GAEG;AACH,qBAAa,SAAU,SAAQ,QAAQ;gBACzB,IAAI,EAAE,YAAY;CAI/B"}
package/dist/errors.js ADDED
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ /**
3
+ * @coderifts/sdk — Error classes
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.AuthError = exports.RateLimitError = exports.TimeoutError = exports.ApiError = exports.CodeRiftsError = void 0;
7
+ /**
8
+ * Base error for all CodeRifts API errors.
9
+ */
10
+ class CodeRiftsError extends Error {
11
+ constructor(message) {
12
+ super(message);
13
+ this.name = 'CodeRiftsError';
14
+ }
15
+ }
16
+ exports.CodeRiftsError = CodeRiftsError;
17
+ /**
18
+ * Thrown when the API returns a non-2xx status code.
19
+ */
20
+ class ApiError extends CodeRiftsError {
21
+ status;
22
+ code;
23
+ body;
24
+ constructor(status, body) {
25
+ super(`[${status}] ${body.error}: ${body.message}`);
26
+ this.name = 'ApiError';
27
+ this.status = status;
28
+ this.code = body.error;
29
+ this.body = body;
30
+ }
31
+ }
32
+ exports.ApiError = ApiError;
33
+ /**
34
+ * Thrown when the request times out.
35
+ */
36
+ class TimeoutError extends CodeRiftsError {
37
+ constructor(timeoutMs) {
38
+ super(`Request timed out after ${timeoutMs}ms`);
39
+ this.name = 'TimeoutError';
40
+ }
41
+ }
42
+ exports.TimeoutError = TimeoutError;
43
+ /**
44
+ * Thrown when rate limited (429).
45
+ */
46
+ class RateLimitError extends ApiError {
47
+ constructor(body) {
48
+ super(429, body);
49
+ this.name = 'RateLimitError';
50
+ }
51
+ }
52
+ exports.RateLimitError = RateLimitError;
53
+ /**
54
+ * Thrown when authentication fails (401).
55
+ */
56
+ class AuthError extends ApiError {
57
+ constructor(body) {
58
+ super(401, body);
59
+ this.name = 'AuthError';
60
+ }
61
+ }
62
+ exports.AuthError = AuthError;
63
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAIH;;GAEG;AACH,MAAa,cAAe,SAAQ,KAAK;IACvC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF;AALD,wCAKC;AAED;;GAEG;AACH,MAAa,QAAS,SAAQ,cAAc;IAC1B,MAAM,CAAS;IACf,IAAI,CAAS;IACb,IAAI,CAAe;IAEnC,YAAY,MAAc,EAAE,IAAkB;QAC5C,KAAK,CAAC,IAAI,MAAM,KAAK,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;QACpD,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;QACvB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;CACF;AAZD,4BAYC;AAED;;GAEG;AACH,MAAa,YAAa,SAAQ,cAAc;IAC9C,YAAY,SAAiB;QAC3B,KAAK,CAAC,2BAA2B,SAAS,IAAI,CAAC,CAAC;QAChD,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;IAC7B,CAAC;CACF;AALD,oCAKC;AAED;;GAEG;AACH,MAAa,cAAe,SAAQ,QAAQ;IAC1C,YAAY,IAAkB;QAC5B,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF;AALD,wCAKC;AAED;;GAEG;AACH,MAAa,SAAU,SAAQ,QAAQ;IACrC,YAAY,IAAkB;QAC5B,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;IAC1B,CAAC;CACF;AALD,8BAKC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @coderifts/sdk
3
+ *
4
+ * TypeScript client for the CodeRifts API.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import { CodeRifts } from '@coderifts/sdk';
9
+ *
10
+ * const client = new CodeRifts({ apiKey: 'cr_live_...' });
11
+ * const result = await client.diff({ old_spec: oldYaml, new_spec: newYaml });
12
+ * ```
13
+ */
14
+ export { CodeRifts } from './client';
15
+ export { CodeRiftsError, ApiError, AuthError, RateLimitError, TimeoutError } from './errors';
16
+ export type { CodeRiftsOptions, DiffRequest, DiffResponse, BreakingChange, ReadinessRequest, ReadinessResponse, ReadinessSignal, McpScoreResponse, StabilityRequest, StabilityResponse, StabilitySummary, TrendPoint, PatternEntry, OmegaDistribution, PreflightRequest, PreflightResponse, PreflightTool, ApiErrorBody, } from './types';
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,SAAS,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7F,YAAY,EACV,gBAAgB,EAChB,WAAW,EACX,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,UAAU,EACV,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,aAAa,EACb,YAAY,GACb,MAAM,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ /**
3
+ * @coderifts/sdk
4
+ *
5
+ * TypeScript client for the CodeRifts API.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { CodeRifts } from '@coderifts/sdk';
10
+ *
11
+ * const client = new CodeRifts({ apiKey: 'cr_live_...' });
12
+ * const result = await client.diff({ old_spec: oldYaml, new_spec: newYaml });
13
+ * ```
14
+ */
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ exports.TimeoutError = exports.RateLimitError = exports.AuthError = exports.ApiError = exports.CodeRiftsError = exports.CodeRifts = void 0;
17
+ var client_1 = require("./client");
18
+ Object.defineProperty(exports, "CodeRifts", { enumerable: true, get: function () { return client_1.CodeRifts; } });
19
+ var errors_1 = require("./errors");
20
+ Object.defineProperty(exports, "CodeRiftsError", { enumerable: true, get: function () { return errors_1.CodeRiftsError; } });
21
+ Object.defineProperty(exports, "ApiError", { enumerable: true, get: function () { return errors_1.ApiError; } });
22
+ Object.defineProperty(exports, "AuthError", { enumerable: true, get: function () { return errors_1.AuthError; } });
23
+ Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return errors_1.RateLimitError; } });
24
+ Object.defineProperty(exports, "TimeoutError", { enumerable: true, get: function () { return errors_1.TimeoutError; } });
25
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;AAEH,mCAAqC;AAA5B,mGAAA,SAAS,OAAA;AAClB,mCAA6F;AAApF,wGAAA,cAAc,OAAA;AAAE,kGAAA,QAAQ,OAAA;AAAE,mGAAA,SAAS,OAAA;AAAE,wGAAA,cAAc,OAAA;AAAE,sGAAA,YAAY,OAAA"}
@@ -0,0 +1,119 @@
1
+ /**
2
+ * @coderifts/sdk — Type definitions
3
+ */
4
+ export interface CodeRiftsOptions {
5
+ /** API key (cr_live_... or cr_test_...) */
6
+ apiKey: string;
7
+ /** Base URL override. Defaults to https://app.coderifts.com */
8
+ baseUrl?: string;
9
+ /** Request timeout in milliseconds. Defaults to 30000 */
10
+ timeout?: number;
11
+ }
12
+ export interface DiffRequest {
13
+ old_spec: string;
14
+ new_spec: string;
15
+ }
16
+ export interface BreakingChange {
17
+ id: string;
18
+ type: string;
19
+ severity: string;
20
+ path: string;
21
+ method: string;
22
+ description: string;
23
+ }
24
+ export interface DiffResponse {
25
+ breaking_changes: BreakingChange[];
26
+ breaking_changes_count: number;
27
+ non_breaking_changes_count: number;
28
+ risk_score: number;
29
+ risk_level: string;
30
+ semver_suggestion: string;
31
+ should_block: boolean;
32
+ omega_api?: number;
33
+ omega_decision?: string;
34
+ summary: string;
35
+ }
36
+ export interface ReadinessSignal {
37
+ signal: string;
38
+ severity: string;
39
+ deduction: number;
40
+ detail: string;
41
+ }
42
+ export interface ReadinessResponse {
43
+ name: string;
44
+ score: number;
45
+ band: string;
46
+ label: string;
47
+ signals: ReadinessSignal[];
48
+ tool_count?: number;
49
+ spec_type: 'openapi' | 'mcp';
50
+ }
51
+ export interface ReadinessRequest {
52
+ spec: string | object;
53
+ spec_type?: 'openapi' | 'mcp';
54
+ }
55
+ export interface McpScoreResponse {
56
+ name: string;
57
+ score: number;
58
+ band: string;
59
+ label: string;
60
+ signals: ReadinessSignal[];
61
+ tool_count: number;
62
+ spec_type: 'mcp';
63
+ }
64
+ export interface StabilityRequest {
65
+ repo: string;
66
+ days?: 7 | 14 | 30 | 90;
67
+ }
68
+ export interface StabilitySummary {
69
+ total_analyses: number;
70
+ blocked_prs: number;
71
+ block_rate: number;
72
+ avg_omega_api: number;
73
+ avg_breaking_changes: number;
74
+ v_api_level: string;
75
+ }
76
+ export interface TrendPoint {
77
+ date: string;
78
+ analyses: number;
79
+ blocked: number;
80
+ avg_omega: number;
81
+ }
82
+ export interface PatternEntry {
83
+ pattern: string;
84
+ count: number;
85
+ pct: number;
86
+ }
87
+ export interface OmegaDistribution {
88
+ allow: number;
89
+ warn: number;
90
+ require_approval: number;
91
+ block: number;
92
+ }
93
+ export interface StabilityResponse {
94
+ repo: string;
95
+ period_days: number;
96
+ summary: StabilitySummary;
97
+ trend: TrendPoint[];
98
+ top_patterns: PatternEntry[];
99
+ omega_distribution: OmegaDistribution;
100
+ }
101
+ export interface PreflightRequest {
102
+ spec: string | object;
103
+ }
104
+ export interface PreflightTool {
105
+ name: string;
106
+ description: string;
107
+ input_schema: object;
108
+ endpoint?: string;
109
+ method?: string;
110
+ }
111
+ export interface PreflightResponse {
112
+ tools: PreflightTool[];
113
+ tool_count: number;
114
+ }
115
+ export interface ApiErrorBody {
116
+ error: string;
117
+ message: string;
118
+ }
119
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,MAAM,WAAW,gBAAgB;IAC/B,2CAA2C;IAC3C,MAAM,EAAE,MAAM,CAAC;IACf,+DAA+D;IAC/D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,yDAAyD;IACzD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAMD,MAAM,WAAW,WAAW;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,YAAY;IAC3B,gBAAgB,EAAE,cAAc,EAAE,CAAC;IACnC,sBAAsB,EAAE,MAAM,CAAC;IAC/B,0BAA0B,EAAE,MAAM,CAAC;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,YAAY,EAAE,OAAO,CAAC;IACtB,SAAS,CA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AED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,gBAAgB,EAAE,MAAM,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,gBAAgB,CAAC;IAC1B,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,YAAY,EAAE,YAAY,EAAE,CAAC;IAC7B,kBAAkB,EAAE,iBAAiB,CAAC;CACvC;AAMD,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,aAAa,EAAE,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;CACpB;AAMD,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;CACjB"}
package/dist/types.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ /**
3
+ * @coderifts/sdk — Type definitions
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA;;GAEG"}
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@coderifts/sdk",
3
+ "version": "0.7.0",
4
+ "description": "TypeScript client for the CodeRifts API — diff, score, analyze, and govern API changes.",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "test": "node --test dist/**/*.test.js",
13
+ "prepublishOnly": "npm run build"
14
+ },
15
+ "keywords": [
16
+ "coderifts",
17
+ "api",
18
+ "openapi",
19
+ "breaking-changes",
20
+ "mcp",
21
+ "sdk"
22
+ ],
23
+ "author": "CodeRifts <hello@coderifts.com>",
24
+ "license": "MIT",
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "https://github.com/coderifts/sdk.git"
28
+ },
29
+ "homepage": "https://coderifts.com",
30
+ "engines": {
31
+ "node": ">=18"
32
+ },
33
+ "devDependencies": {
34
+ "typescript": "^5.4.0"
35
+ }
36
+ }