@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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 ArchiCore
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,221 @@
1
+ # @archicore/sdk
2
+
3
+ Official TypeScript/JavaScript SDK for the [ArchiCore](https://archicore.io) Architecture Analysis API.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @archicore/sdk
9
+ # or
10
+ yarn add @archicore/sdk
11
+ # or
12
+ pnpm add @archicore/sdk
13
+ ```
14
+
15
+ ## Quick Start
16
+
17
+ ```typescript
18
+ import { ArchiCore } from '@archicore/sdk';
19
+
20
+ // Initialize client
21
+ const client = new ArchiCore({ apiKey: 'your-api-key' });
22
+
23
+ // List projects
24
+ const projects = await client.projects.list();
25
+ console.log(projects);
26
+
27
+ // Search code semantically
28
+ const results = await client.projects.search('project-id', {
29
+ query: 'authentication middleware'
30
+ });
31
+
32
+ // Ask AI assistant
33
+ const answer = await client.projects.ask('project-id', {
34
+ question: 'How does the authentication system work?'
35
+ });
36
+ console.log(answer.response);
37
+ ```
38
+
39
+ ## Features
40
+
41
+ - **Full TypeScript Support**: Complete type definitions included
42
+ - **Projects**: Create, list, delete, and manage projects
43
+ - **Semantic Search**: Search code using natural language
44
+ - **AI Assistant**: Ask questions about your codebase
45
+ - **Impact Analysis**: Analyze how changes affect your codebase
46
+ - **Code Metrics**: Get code quality metrics
47
+ - **Security Scanning**: Identify vulnerabilities
48
+ - **Webhooks**: Subscribe to events
49
+
50
+ ## API Reference
51
+
52
+ ### Projects
53
+
54
+ ```typescript
55
+ // List all projects
56
+ const projects = await client.projects.list();
57
+
58
+ // Get a specific project
59
+ const project = await client.projects.get('project-id');
60
+
61
+ // Create a project
62
+ const project = await client.projects.create({
63
+ name: 'my-project',
64
+ githubUrl: 'https://github.com/user/repo'
65
+ });
66
+
67
+ // Delete a project
68
+ await client.projects.delete('project-id');
69
+
70
+ // Trigger indexing
71
+ await client.projects.index('project-id', { force: true });
72
+ ```
73
+
74
+ ### Search & AI
75
+
76
+ ```typescript
77
+ // Semantic search
78
+ const results = await client.projects.search('project-id', {
79
+ query: 'error handling',
80
+ limit: 20,
81
+ threshold: 0.8
82
+ });
83
+
84
+ // Ask AI assistant
85
+ const answer = await client.projects.ask('project-id', {
86
+ question: 'What design patterns are used?',
87
+ context: 'Focus on the authentication module'
88
+ });
89
+ ```
90
+
91
+ ### Analysis
92
+
93
+ ```typescript
94
+ // Get code metrics
95
+ const metrics = await client.projects.metrics('project-id');
96
+ console.log(`Total files: ${metrics.totalFiles}`);
97
+ console.log(`Total lines: ${metrics.totalLines}`);
98
+
99
+ // Get security scan results
100
+ const security = await client.projects.security('project-id');
101
+ for (const vuln of security.vulnerabilities) {
102
+ console.log(`[${vuln.severity}] ${vuln.message}`);
103
+ }
104
+
105
+ // Impact analysis
106
+ const impact = await client.projects.analyze('project-id', {
107
+ files: ['src/auth/login.ts', 'src/auth/middleware.ts']
108
+ });
109
+ console.log(`Affected files: ${impact.affectedFiles.length}`);
110
+ ```
111
+
112
+ ### Webhooks
113
+
114
+ ```typescript
115
+ // List webhooks
116
+ const webhooks = await client.webhooks.list();
117
+
118
+ // Create a webhook
119
+ const webhook = await client.webhooks.create({
120
+ url: 'https://example.com/webhook',
121
+ events: ['project.indexed', 'analysis.complete'],
122
+ secret: 'your-webhook-secret'
123
+ });
124
+
125
+ // Delete a webhook
126
+ await client.webhooks.delete('webhook-id');
127
+ ```
128
+
129
+ ## Error Handling
130
+
131
+ ```typescript
132
+ import {
133
+ ArchiCore,
134
+ AuthenticationError,
135
+ RateLimitError,
136
+ NotFoundError,
137
+ ValidationError
138
+ } from '@archicore/sdk';
139
+
140
+ const client = new ArchiCore({ apiKey: 'your-api-key' });
141
+
142
+ try {
143
+ const project = await client.projects.get('non-existent-id');
144
+ } catch (error) {
145
+ if (error instanceof NotFoundError) {
146
+ console.log('Project not found');
147
+ } else if (error instanceof AuthenticationError) {
148
+ console.log('Invalid API key');
149
+ } else if (error instanceof RateLimitError) {
150
+ console.log(`Rate limited. Retry after ${error.retryAfter} seconds`);
151
+ } else if (error instanceof ValidationError) {
152
+ console.log(`Invalid request: ${error.message}`);
153
+ }
154
+ }
155
+ ```
156
+
157
+ ## Configuration
158
+
159
+ ### Custom Base URL
160
+
161
+ For self-hosted instances:
162
+
163
+ ```typescript
164
+ const client = new ArchiCore({
165
+ apiKey: 'your-api-key',
166
+ baseUrl: 'https://your-instance.com/api/v1'
167
+ });
168
+ ```
169
+
170
+ ### Timeout
171
+
172
+ ```typescript
173
+ const client = new ArchiCore({
174
+ apiKey: 'your-api-key',
175
+ timeout: 60000 // milliseconds
176
+ });
177
+ ```
178
+
179
+ ## Browser Support
180
+
181
+ This SDK works in both Node.js and browser environments. It uses the native `fetch` API.
182
+
183
+ For Node.js < 18, you may need to polyfill `fetch`:
184
+
185
+ ```typescript
186
+ import fetch from 'node-fetch';
187
+ globalThis.fetch = fetch;
188
+ ```
189
+
190
+ ## TypeScript
191
+
192
+ Full TypeScript support is included. All types are exported:
193
+
194
+ ```typescript
195
+ import type {
196
+ Project,
197
+ SearchResult,
198
+ AskResponse,
199
+ Metrics,
200
+ SecurityReport,
201
+ ImpactAnalysis,
202
+ Webhook,
203
+ ArchiCoreConfig
204
+ } from '@archicore/sdk';
205
+ ```
206
+
207
+ ## Requirements
208
+
209
+ - Node.js >= 16 (for native fetch) or polyfill
210
+ - Modern browsers with fetch support
211
+
212
+ ## License
213
+
214
+ MIT License - see [LICENSE](LICENSE) for details.
215
+
216
+ ## Links
217
+
218
+ - [Documentation](https://docs.archicore.io)
219
+ - [API Reference](https://docs.archicore.io/docs/api/overview)
220
+ - [ArchiCore Website](https://archicore.io)
221
+ - [Report Issues](https://archicore.io/report-issue)
@@ -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 };