archicore-sdk 0.1.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.
@@ -0,0 +1,258 @@
1
+ /**
2
+ * ArchiCore JavaScript/TypeScript SDK
3
+ *
4
+ * Official client for the ArchiCore Architecture Analysis API.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * import { ArchiCore } from '@archicore/sdk';
9
+ *
10
+ * const client = new ArchiCore({ apiKey: 'your-api-key' });
11
+ * const projects = await client.projects.list();
12
+ * ```
13
+ */
14
+ interface ArchiCoreConfig {
15
+ apiKey: string;
16
+ baseUrl?: string;
17
+ timeout?: number;
18
+ }
19
+ interface Project {
20
+ id: string;
21
+ name: string;
22
+ path?: string;
23
+ status?: 'pending' | 'indexing' | 'ready' | 'error';
24
+ createdAt?: string;
25
+ updatedAt?: string;
26
+ stats?: {
27
+ files: number;
28
+ lines: number;
29
+ symbols: number;
30
+ };
31
+ }
32
+ interface SearchResult {
33
+ file: string;
34
+ line: number;
35
+ code: string;
36
+ score: number;
37
+ context?: string;
38
+ }
39
+ interface AskResponse {
40
+ response: string;
41
+ sources?: Array<{
42
+ file: string;
43
+ line: number;
44
+ code: string;
45
+ }>;
46
+ confidence?: number;
47
+ }
48
+ interface Metrics {
49
+ totalFiles: number;
50
+ totalLines: number;
51
+ totalSymbols: number;
52
+ languages: Record<string, number>;
53
+ complexity?: {
54
+ average: number;
55
+ max: number;
56
+ };
57
+ }
58
+ interface SecurityReport {
59
+ vulnerabilities: Array<{
60
+ severity: 'critical' | 'high' | 'medium' | 'low';
61
+ type: string;
62
+ message: string;
63
+ file: string;
64
+ line: number;
65
+ }>;
66
+ summary: {
67
+ critical: number;
68
+ high: number;
69
+ medium: number;
70
+ low: number;
71
+ };
72
+ }
73
+ interface ImpactAnalysis {
74
+ affectedFiles: string[];
75
+ affectedSymbols: string[];
76
+ riskLevel: 'low' | 'medium' | 'high';
77
+ suggestions?: string[];
78
+ }
79
+ interface Webhook {
80
+ id: string;
81
+ url: string;
82
+ events: string[];
83
+ projectId?: string;
84
+ createdAt: string;
85
+ active: boolean;
86
+ }
87
+ interface ApiResponse<T> {
88
+ success: boolean;
89
+ data?: T;
90
+ error?: string;
91
+ code?: string;
92
+ }
93
+ declare class ArchiCoreError extends Error {
94
+ code?: string;
95
+ statusCode?: number;
96
+ constructor(message: string, code?: string, statusCode?: number);
97
+ }
98
+ declare class AuthenticationError extends ArchiCoreError {
99
+ constructor(message?: string);
100
+ }
101
+ declare class RateLimitError extends ArchiCoreError {
102
+ retryAfter?: number;
103
+ limit?: number;
104
+ remaining?: number;
105
+ constructor(message?: string, retryAfter?: number, limit?: number, remaining?: number);
106
+ }
107
+ declare class NotFoundError extends ArchiCoreError {
108
+ constructor(message?: string);
109
+ }
110
+ declare class ValidationError extends ArchiCoreError {
111
+ constructor(message?: string);
112
+ }
113
+ declare class ProjectsResource {
114
+ private client;
115
+ constructor(client: ArchiCore);
116
+ /**
117
+ * List all projects.
118
+ */
119
+ list(): Promise<Project[]>;
120
+ /**
121
+ * Get a specific project by ID.
122
+ */
123
+ get(projectId: string): Promise<Project>;
124
+ /**
125
+ * Create a new project.
126
+ */
127
+ create(options: {
128
+ name: string;
129
+ source?: string;
130
+ githubUrl?: string;
131
+ gitlabUrl?: string;
132
+ }): Promise<Project>;
133
+ /**
134
+ * Delete a project.
135
+ */
136
+ delete(projectId: string): Promise<void>;
137
+ /**
138
+ * Trigger project indexing.
139
+ */
140
+ index(projectId: string, options?: {
141
+ force?: boolean;
142
+ }): Promise<{
143
+ status: string;
144
+ }>;
145
+ /**
146
+ * Semantic search in project code.
147
+ *
148
+ * @example
149
+ * ```typescript
150
+ * const results = await client.projects.search('project-id', {
151
+ * query: 'authentication middleware'
152
+ * });
153
+ * ```
154
+ */
155
+ search(projectId: string, options: {
156
+ query: string;
157
+ limit?: number;
158
+ threshold?: number;
159
+ }): Promise<SearchResult[]>;
160
+ /**
161
+ * Ask AI assistant about the project.
162
+ *
163
+ * @example
164
+ * ```typescript
165
+ * const answer = await client.projects.ask('project-id', {
166
+ * question: 'How does the auth system work?'
167
+ * });
168
+ * console.log(answer.response);
169
+ * ```
170
+ */
171
+ ask(projectId: string, options: {
172
+ question: string;
173
+ context?: string;
174
+ }): Promise<AskResponse>;
175
+ /**
176
+ * Get code metrics for a project.
177
+ */
178
+ metrics(projectId: string): Promise<Metrics>;
179
+ /**
180
+ * Get security scan results.
181
+ */
182
+ security(projectId: string): Promise<SecurityReport>;
183
+ /**
184
+ * Perform impact analysis.
185
+ *
186
+ * @example
187
+ * ```typescript
188
+ * const impact = await client.projects.analyze('project-id', {
189
+ * files: ['src/auth/login.ts']
190
+ * });
191
+ * console.log(`Affected: ${impact.affectedFiles.length} files`);
192
+ * ```
193
+ */
194
+ analyze(projectId: string, options?: {
195
+ changes?: Array<{
196
+ file: string;
197
+ content: string;
198
+ }>;
199
+ files?: string[];
200
+ }): Promise<ImpactAnalysis>;
201
+ }
202
+ declare class WebhooksResource {
203
+ private client;
204
+ constructor(client: ArchiCore);
205
+ /**
206
+ * List all webhooks.
207
+ */
208
+ list(): Promise<Webhook[]>;
209
+ /**
210
+ * Create a new webhook.
211
+ *
212
+ * @example
213
+ * ```typescript
214
+ * const webhook = await client.webhooks.create({
215
+ * url: 'https://example.com/webhook',
216
+ * events: ['project.indexed', 'analysis.complete']
217
+ * });
218
+ * ```
219
+ */
220
+ create(options: {
221
+ url: string;
222
+ events: string[];
223
+ projectId?: string;
224
+ secret?: string;
225
+ }): Promise<Webhook>;
226
+ /**
227
+ * Delete a webhook.
228
+ */
229
+ delete(webhookId: string): Promise<void>;
230
+ }
231
+ declare class ArchiCore {
232
+ private apiKey;
233
+ private baseUrl;
234
+ private timeout;
235
+ projects: ProjectsResource;
236
+ webhooks: WebhooksResource;
237
+ /**
238
+ * Create a new ArchiCore client.
239
+ *
240
+ * @param config - Client configuration
241
+ *
242
+ * @example
243
+ * ```typescript
244
+ * const client = new ArchiCore({
245
+ * apiKey: 'your-api-key',
246
+ * baseUrl: 'https://api.archicore.io/api/v1' // optional
247
+ * });
248
+ * ```
249
+ */
250
+ constructor(config: ArchiCoreConfig);
251
+ /**
252
+ * Make an API request.
253
+ * @internal
254
+ */
255
+ request<T>(method: string, endpoint: string, data?: Record<string, unknown>): Promise<T>;
256
+ }
257
+
258
+ export { type ApiResponse, ArchiCore, type ArchiCoreConfig, ArchiCoreError, type AskResponse, AuthenticationError, type ImpactAnalysis, type Metrics, NotFoundError, type Project, RateLimitError, type SearchResult, type SecurityReport, ValidationError, type Webhook, ArchiCore as default };
package/dist/index.js ADDED
@@ -0,0 +1,337 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ ArchiCore: () => ArchiCore,
24
+ ArchiCoreError: () => ArchiCoreError,
25
+ AuthenticationError: () => AuthenticationError,
26
+ NotFoundError: () => NotFoundError,
27
+ RateLimitError: () => RateLimitError,
28
+ ValidationError: () => ValidationError,
29
+ default: () => index_default
30
+ });
31
+ module.exports = __toCommonJS(index_exports);
32
+ var ArchiCoreError = class extends Error {
33
+ constructor(message, code, statusCode) {
34
+ super(message);
35
+ this.name = "ArchiCoreError";
36
+ this.code = code;
37
+ this.statusCode = statusCode;
38
+ }
39
+ };
40
+ var AuthenticationError = class extends ArchiCoreError {
41
+ constructor(message = "Invalid or missing API key") {
42
+ super(message, "UNAUTHORIZED", 401);
43
+ this.name = "AuthenticationError";
44
+ }
45
+ };
46
+ var RateLimitError = class extends ArchiCoreError {
47
+ constructor(message = "Rate limit exceeded", retryAfter, limit, remaining) {
48
+ super(message, "RATE_LIMITED", 429);
49
+ this.name = "RateLimitError";
50
+ this.retryAfter = retryAfter;
51
+ this.limit = limit;
52
+ this.remaining = remaining;
53
+ }
54
+ };
55
+ var NotFoundError = class extends ArchiCoreError {
56
+ constructor(message = "Resource not found") {
57
+ super(message, "NOT_FOUND", 404);
58
+ this.name = "NotFoundError";
59
+ }
60
+ };
61
+ var ValidationError = class extends ArchiCoreError {
62
+ constructor(message = "Invalid request parameters") {
63
+ super(message, "VALIDATION_ERROR", 400);
64
+ this.name = "ValidationError";
65
+ }
66
+ };
67
+ async function httpRequest(url, options) {
68
+ const controller = new AbortController();
69
+ const timeout = options.timeout || 3e4;
70
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
71
+ try {
72
+ const response = await fetch(url, {
73
+ ...options,
74
+ signal: controller.signal
75
+ });
76
+ clearTimeout(timeoutId);
77
+ return handleResponse(response);
78
+ } catch (error) {
79
+ clearTimeout(timeoutId);
80
+ if (error instanceof Error && error.name === "AbortError") {
81
+ throw new ArchiCoreError("Request timed out", "TIMEOUT");
82
+ }
83
+ throw error;
84
+ }
85
+ }
86
+ async function handleResponse(response) {
87
+ const rateLimitInfo = {
88
+ limit: response.headers.get("X-RateLimit-Limit"),
89
+ remaining: response.headers.get("X-RateLimit-Remaining"),
90
+ reset: response.headers.get("X-RateLimit-Reset")
91
+ };
92
+ if (response.ok) {
93
+ if (response.status === 204) {
94
+ return { success: true };
95
+ }
96
+ const text = await response.text();
97
+ return text ? JSON.parse(text) : { success: true };
98
+ }
99
+ let errorMessage = "Unknown error";
100
+ let errorCode;
101
+ try {
102
+ const errorData = await response.json();
103
+ errorMessage = errorData.error || errorData.message || errorMessage;
104
+ errorCode = errorData.code;
105
+ } catch {
106
+ errorMessage = response.statusText || errorMessage;
107
+ }
108
+ switch (response.status) {
109
+ case 401:
110
+ throw new AuthenticationError(errorMessage);
111
+ case 403:
112
+ throw new ArchiCoreError(errorMessage, "FORBIDDEN", 403);
113
+ case 404:
114
+ throw new NotFoundError(errorMessage);
115
+ case 429:
116
+ throw new RateLimitError(
117
+ errorMessage,
118
+ parseInt(response.headers.get("Retry-After") || "60", 10),
119
+ rateLimitInfo.limit ? parseInt(rateLimitInfo.limit, 10) : void 0,
120
+ rateLimitInfo.remaining ? parseInt(rateLimitInfo.remaining, 10) : void 0
121
+ );
122
+ case 400:
123
+ throw new ValidationError(errorMessage);
124
+ default:
125
+ if (response.status >= 500) {
126
+ throw new ArchiCoreError(errorMessage, "SERVER_ERROR", response.status);
127
+ }
128
+ throw new ArchiCoreError(errorMessage, errorCode, response.status);
129
+ }
130
+ }
131
+ var ProjectsResource = class {
132
+ constructor(client) {
133
+ this.client = client;
134
+ }
135
+ /**
136
+ * List all projects.
137
+ */
138
+ async list() {
139
+ const response = await this.client.request("GET", "/projects");
140
+ return response.data || response.projects || [];
141
+ }
142
+ /**
143
+ * Get a specific project by ID.
144
+ */
145
+ async get(projectId) {
146
+ const response = await this.client.request("GET", `/projects/${projectId}`);
147
+ return response.data || response.project || response;
148
+ }
149
+ /**
150
+ * Create a new project.
151
+ */
152
+ async create(options) {
153
+ const response = await this.client.request("POST", "/projects", options);
154
+ return response.data || response.project || response;
155
+ }
156
+ /**
157
+ * Delete a project.
158
+ */
159
+ async delete(projectId) {
160
+ await this.client.request("DELETE", `/projects/${projectId}`);
161
+ }
162
+ /**
163
+ * Trigger project indexing.
164
+ */
165
+ async index(projectId, options) {
166
+ const response = await this.client.request(
167
+ "POST",
168
+ `/projects/${projectId}/index`,
169
+ options
170
+ );
171
+ return response.data || response;
172
+ }
173
+ /**
174
+ * Semantic search in project code.
175
+ *
176
+ * @example
177
+ * ```typescript
178
+ * const results = await client.projects.search('project-id', {
179
+ * query: 'authentication middleware'
180
+ * });
181
+ * ```
182
+ */
183
+ async search(projectId, options) {
184
+ const response = await this.client.request(
185
+ "POST",
186
+ `/projects/${projectId}/search`,
187
+ options
188
+ );
189
+ return response.data || response.results || [];
190
+ }
191
+ /**
192
+ * Ask AI assistant about the project.
193
+ *
194
+ * @example
195
+ * ```typescript
196
+ * const answer = await client.projects.ask('project-id', {
197
+ * question: 'How does the auth system work?'
198
+ * });
199
+ * console.log(answer.response);
200
+ * ```
201
+ */
202
+ async ask(projectId, options) {
203
+ const response = await this.client.request(
204
+ "POST",
205
+ `/projects/${projectId}/ask`,
206
+ options
207
+ );
208
+ return response.data || response;
209
+ }
210
+ /**
211
+ * Get code metrics for a project.
212
+ */
213
+ async metrics(projectId) {
214
+ const response = await this.client.request(
215
+ "GET",
216
+ `/projects/${projectId}/metrics`
217
+ );
218
+ return response.data || response.metrics || response;
219
+ }
220
+ /**
221
+ * Get security scan results.
222
+ */
223
+ async security(projectId) {
224
+ const response = await this.client.request(
225
+ "GET",
226
+ `/projects/${projectId}/security`
227
+ );
228
+ return response.data || response.security || response;
229
+ }
230
+ /**
231
+ * Perform impact analysis.
232
+ *
233
+ * @example
234
+ * ```typescript
235
+ * const impact = await client.projects.analyze('project-id', {
236
+ * files: ['src/auth/login.ts']
237
+ * });
238
+ * console.log(`Affected: ${impact.affectedFiles.length} files`);
239
+ * ```
240
+ */
241
+ async analyze(projectId, options) {
242
+ const response = await this.client.request(
243
+ "POST",
244
+ `/projects/${projectId}/analyze`,
245
+ options
246
+ );
247
+ return response.data || response;
248
+ }
249
+ };
250
+ var WebhooksResource = class {
251
+ constructor(client) {
252
+ this.client = client;
253
+ }
254
+ /**
255
+ * List all webhooks.
256
+ */
257
+ async list() {
258
+ const response = await this.client.request("GET", "/webhooks");
259
+ return response.data || response.webhooks || [];
260
+ }
261
+ /**
262
+ * Create a new webhook.
263
+ *
264
+ * @example
265
+ * ```typescript
266
+ * const webhook = await client.webhooks.create({
267
+ * url: 'https://example.com/webhook',
268
+ * events: ['project.indexed', 'analysis.complete']
269
+ * });
270
+ * ```
271
+ */
272
+ async create(options) {
273
+ const response = await this.client.request("POST", "/webhooks", options);
274
+ return response.data || response.webhook || response;
275
+ }
276
+ /**
277
+ * Delete a webhook.
278
+ */
279
+ async delete(webhookId) {
280
+ await this.client.request("DELETE", `/webhooks/${webhookId}`);
281
+ }
282
+ };
283
+ var ArchiCore = class {
284
+ /**
285
+ * Create a new ArchiCore client.
286
+ *
287
+ * @param config - Client configuration
288
+ *
289
+ * @example
290
+ * ```typescript
291
+ * const client = new ArchiCore({
292
+ * apiKey: 'your-api-key',
293
+ * baseUrl: 'https://api.archicore.io/api/v1' // optional
294
+ * });
295
+ * ```
296
+ */
297
+ constructor(config) {
298
+ if (!config.apiKey) {
299
+ throw new Error("apiKey is required");
300
+ }
301
+ this.apiKey = config.apiKey;
302
+ this.baseUrl = (config.baseUrl || "https://api.archicore.io/api/v1").replace(/\/+$/, "");
303
+ this.timeout = config.timeout || 3e4;
304
+ this.projects = new ProjectsResource(this);
305
+ this.webhooks = new WebhooksResource(this);
306
+ }
307
+ /**
308
+ * Make an API request.
309
+ * @internal
310
+ */
311
+ async request(method, endpoint, data) {
312
+ const url = `${this.baseUrl}${endpoint}`;
313
+ const options = {
314
+ method,
315
+ headers: {
316
+ "Authorization": `Bearer ${this.apiKey}`,
317
+ "Content-Type": "application/json",
318
+ "User-Agent": "@archicore/sdk/0.1.0"
319
+ },
320
+ timeout: this.timeout
321
+ };
322
+ if (data && ["POST", "PUT", "PATCH"].includes(method)) {
323
+ options.body = JSON.stringify(data);
324
+ }
325
+ return httpRequest(url, options);
326
+ }
327
+ };
328
+ var index_default = ArchiCore;
329
+ // Annotate the CommonJS export names for ESM import in node:
330
+ 0 && (module.exports = {
331
+ ArchiCore,
332
+ ArchiCoreError,
333
+ AuthenticationError,
334
+ NotFoundError,
335
+ RateLimitError,
336
+ ValidationError
337
+ });