@arke-institute/sdk 0.1.3 → 2.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.
Files changed (66) hide show
  1. package/README.md +222 -176
  2. package/dist/crypto-CQnwqWQn.d.ts +459 -0
  3. package/dist/crypto-iYgzUi77.d.cts +459 -0
  4. package/dist/generated/index.cjs +19 -0
  5. package/dist/generated/index.cjs.map +1 -0
  6. package/dist/generated/index.d.cts +6545 -0
  7. package/dist/generated/index.d.ts +6545 -0
  8. package/dist/generated/index.js +1 -0
  9. package/dist/generated/index.js.map +1 -0
  10. package/dist/index.cjs +725 -4248
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +62 -7
  13. package/dist/index.d.ts +62 -7
  14. package/dist/index.js +706 -4221
  15. package/dist/index.js.map +1 -1
  16. package/dist/operations/index.cjs +806 -0
  17. package/dist/operations/index.cjs.map +1 -0
  18. package/dist/operations/index.d.cts +157 -0
  19. package/dist/operations/index.d.ts +157 -0
  20. package/dist/operations/index.js +759 -0
  21. package/dist/operations/index.js.map +1 -0
  22. package/openapi/spec.json +8648 -0
  23. package/openapi/version.json +7 -0
  24. package/package.json +51 -52
  25. package/dist/client-dAk3E64p.d.cts +0 -183
  26. package/dist/client-dAk3E64p.d.ts +0 -183
  27. package/dist/collections/index.cjs +0 -233
  28. package/dist/collections/index.cjs.map +0 -1
  29. package/dist/collections/index.d.cts +0 -9
  30. package/dist/collections/index.d.ts +0 -9
  31. package/dist/collections/index.js +0 -205
  32. package/dist/collections/index.js.map +0 -1
  33. package/dist/content/index.cjs +0 -591
  34. package/dist/content/index.cjs.map +0 -1
  35. package/dist/content/index.d.cts +0 -516
  36. package/dist/content/index.d.ts +0 -516
  37. package/dist/content/index.js +0 -558
  38. package/dist/content/index.js.map +0 -1
  39. package/dist/edit/index.cjs +0 -1503
  40. package/dist/edit/index.cjs.map +0 -1
  41. package/dist/edit/index.d.cts +0 -78
  42. package/dist/edit/index.d.ts +0 -78
  43. package/dist/edit/index.js +0 -1447
  44. package/dist/edit/index.js.map +0 -1
  45. package/dist/errors-3L7IiHcr.d.cts +0 -480
  46. package/dist/errors-BTe8GKRQ.d.ts +0 -480
  47. package/dist/errors-CT7yzKkU.d.cts +0 -874
  48. package/dist/errors-CT7yzKkU.d.ts +0 -874
  49. package/dist/graph/index.cjs +0 -427
  50. package/dist/graph/index.cjs.map +0 -1
  51. package/dist/graph/index.d.cts +0 -485
  52. package/dist/graph/index.d.ts +0 -485
  53. package/dist/graph/index.js +0 -396
  54. package/dist/graph/index.js.map +0 -1
  55. package/dist/query/index.cjs +0 -356
  56. package/dist/query/index.cjs.map +0 -1
  57. package/dist/query/index.d.cts +0 -636
  58. package/dist/query/index.d.ts +0 -636
  59. package/dist/query/index.js +0 -328
  60. package/dist/query/index.js.map +0 -1
  61. package/dist/upload/index.cjs +0 -1634
  62. package/dist/upload/index.cjs.map +0 -1
  63. package/dist/upload/index.d.cts +0 -150
  64. package/dist/upload/index.d.ts +0 -150
  65. package/dist/upload/index.js +0 -1597
  66. package/dist/upload/index.js.map +0 -1
@@ -0,0 +1,459 @@
1
+ import { Client } from 'openapi-fetch';
2
+ import { paths } from './generated/index.js';
3
+
4
+ /**
5
+ * SDK configuration types
6
+ */
7
+ interface ArkeClientConfig {
8
+ /**
9
+ * Base URL for the Arke API
10
+ * @default 'https://arke-v1.arke.institute'
11
+ */
12
+ baseUrl?: string;
13
+ /**
14
+ * Authentication token (JWT or API key)
15
+ */
16
+ authToken?: string;
17
+ /**
18
+ * Network to use ('main' or 'test')
19
+ * Test network uses 'II' prefixed IDs and isolated data
20
+ * @default 'main'
21
+ */
22
+ network?: 'main' | 'test';
23
+ /**
24
+ * Callback to refresh auth token when expired
25
+ * Called automatically on 401 responses
26
+ */
27
+ onTokenRefresh?: () => Promise<string>;
28
+ /**
29
+ * Custom headers to include in all requests
30
+ */
31
+ headers?: Record<string, string>;
32
+ }
33
+ declare const DEFAULT_CONFIG: Required<Pick<ArkeClientConfig, 'baseUrl' | 'network'>>;
34
+
35
+ /**
36
+ * Main Arke SDK Client
37
+ *
38
+ * Provides type-safe access to the Arke API using openapi-fetch.
39
+ */
40
+
41
+ type ArkeApiClient = Client<paths>;
42
+ /**
43
+ * Type-safe client for the Arke API
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * const arke = new ArkeClient({ authToken: 'your-jwt-token' });
48
+ *
49
+ * // Create an entity
50
+ * const { data, error } = await arke.api.POST('/entities', {
51
+ * body: {
52
+ * collection_id: '01ABC...',
53
+ * type: 'document',
54
+ * properties: { title: 'My Document' }
55
+ * }
56
+ * });
57
+ *
58
+ * // Get an entity
59
+ * const { data } = await arke.api.GET('/entities/{id}', {
60
+ * params: { path: { id: '01XYZ...' } }
61
+ * });
62
+ * ```
63
+ */
64
+ declare class ArkeClient {
65
+ /**
66
+ * The underlying openapi-fetch client with full type safety
67
+ * Use this for all API calls: arke.api.GET, arke.api.POST, etc.
68
+ */
69
+ api: ArkeApiClient;
70
+ private config;
71
+ constructor(config?: ArkeClientConfig);
72
+ private createClient;
73
+ /**
74
+ * Update the authentication token
75
+ * Recreates the underlying client with new headers
76
+ */
77
+ setAuthToken(token: string): void;
78
+ /**
79
+ * Clear the authentication token
80
+ */
81
+ clearAuthToken(): void;
82
+ /**
83
+ * Get the current configuration
84
+ */
85
+ getConfig(): Readonly<ArkeClientConfig>;
86
+ /**
87
+ * Get the base URL
88
+ */
89
+ get baseUrl(): string;
90
+ /**
91
+ * Check if client is authenticated
92
+ */
93
+ get isAuthenticated(): boolean;
94
+ }
95
+ /**
96
+ * Create a new ArkeClient instance
97
+ * Convenience function for those who prefer functional style
98
+ */
99
+ declare function createArkeClient(config?: ArkeClientConfig): ArkeClient;
100
+
101
+ /**
102
+ * Upload Types
103
+ *
104
+ * Type definitions for the folder/file upload system.
105
+ */
106
+ /**
107
+ * Represents a file to be uploaded.
108
+ * Platform-agnostic - works with browser File API or Node.js buffers.
109
+ */
110
+ interface UploadFile {
111
+ /** Filename (e.g., "document.pdf") */
112
+ name: string;
113
+ /** Relative path from upload root (e.g., "docs/reports/document.pdf") */
114
+ relativePath: string;
115
+ /** File size in bytes */
116
+ size: number;
117
+ /** MIME type (e.g., "application/pdf") */
118
+ mimeType: string;
119
+ /**
120
+ * Function to retrieve the file data.
121
+ * Called during upload phase.
122
+ */
123
+ getData: () => Promise<ArrayBuffer | Blob | Uint8Array>;
124
+ }
125
+ /**
126
+ * Represents a folder in the upload tree.
127
+ */
128
+ interface UploadFolder {
129
+ /** Folder name (e.g., "reports") */
130
+ name: string;
131
+ /** Relative path from upload root (e.g., "docs/reports") */
132
+ relativePath: string;
133
+ }
134
+ /**
135
+ * Complete tree structure to upload.
136
+ * Built by platform-specific scanners.
137
+ */
138
+ interface UploadTree {
139
+ /** All files to upload */
140
+ files: UploadFile[];
141
+ /** All folders to create (sorted by depth for correct ordering) */
142
+ folders: UploadFolder[];
143
+ }
144
+ /**
145
+ * Target specification for upload.
146
+ * Determines where items will be placed.
147
+ */
148
+ interface UploadTarget {
149
+ /**
150
+ * Collection ID - required for permissions.
151
+ * If not provided and createCollection is not set, upload will fail.
152
+ */
153
+ collectionId?: string;
154
+ /**
155
+ * Parent folder/collection ID where items will be added.
156
+ * If not provided, items go to collection root.
157
+ * Can be the same as collectionId (collection acts as folder).
158
+ */
159
+ parentId?: string;
160
+ /**
161
+ * Create a new collection for this upload.
162
+ * If set, collectionId is ignored.
163
+ */
164
+ createCollection?: {
165
+ /** Collection display name (required) */
166
+ label: string;
167
+ /** Collection description */
168
+ description?: string;
169
+ /** Custom roles (uses defaults if not provided) */
170
+ roles?: Record<string, string[]>;
171
+ };
172
+ }
173
+ /**
174
+ * Upload progress tracking.
175
+ */
176
+ interface UploadProgress$1 {
177
+ /** Current phase of the upload */
178
+ phase: 'scanning' | 'computing-cids' | 'creating-folders' | 'creating-files' | 'uploading-content' | 'linking' | 'complete' | 'error';
179
+ /** Total number of files to upload */
180
+ totalFiles: number;
181
+ /** Number of files completed */
182
+ completedFiles: number;
183
+ /** Total number of folders to create */
184
+ totalFolders: number;
185
+ /** Number of folders completed */
186
+ completedFolders: number;
187
+ /** Current file being processed */
188
+ currentFile?: string;
189
+ /** Current folder being processed */
190
+ currentFolder?: string;
191
+ /** Error message if phase is 'error' */
192
+ error?: string;
193
+ /** Bytes uploaded so far (for content upload phase) */
194
+ bytesUploaded?: number;
195
+ /** Total bytes to upload */
196
+ totalBytes?: number;
197
+ }
198
+ /**
199
+ * Configuration options for upload.
200
+ */
201
+ interface UploadOptions {
202
+ /** Where to upload */
203
+ target: UploadTarget;
204
+ /** Progress callback */
205
+ onProgress?: (progress: UploadProgress$1) => void;
206
+ /** Maximum concurrent operations (default: 5) */
207
+ concurrency?: number;
208
+ /** Continue uploading even if some files fail (default: false) */
209
+ continueOnError?: boolean;
210
+ /** Custom note to add to created entities */
211
+ note?: string;
212
+ }
213
+ /**
214
+ * Information about a created entity.
215
+ */
216
+ interface CreatedEntity {
217
+ /** Entity ID (ULID) */
218
+ id: string;
219
+ /** Entity CID */
220
+ cid: string;
221
+ /** Entity type */
222
+ type: 'file' | 'folder' | 'collection';
223
+ /** Original path in upload tree */
224
+ relativePath: string;
225
+ }
226
+ /**
227
+ * Result of an upload operation.
228
+ */
229
+ interface UploadResult {
230
+ /** Whether upload completed successfully */
231
+ success: boolean;
232
+ /** Collection used or created */
233
+ collection: {
234
+ id: string;
235
+ cid: string;
236
+ created: boolean;
237
+ };
238
+ /** Created folder entities */
239
+ folders: CreatedEntity[];
240
+ /** Created file entities */
241
+ files: CreatedEntity[];
242
+ /** Errors encountered (if continueOnError was true) */
243
+ errors: Array<{
244
+ path: string;
245
+ error: string;
246
+ }>;
247
+ }
248
+
249
+ /**
250
+ * Folder Operations (Legacy)
251
+ *
252
+ * @deprecated Use the new upload module instead:
253
+ * ```typescript
254
+ * import { uploadTree, scanDirectory } from '@arke-institute/sdk/operations';
255
+ *
256
+ * const tree = await scanDirectory('/path/to/folder');
257
+ * const result = await uploadTree(client, tree, {
258
+ * target: { collectionId: '...' },
259
+ * });
260
+ * ```
261
+ */
262
+
263
+ /**
264
+ * @deprecated Use UploadProgress from upload module
265
+ */
266
+ interface UploadProgress {
267
+ phase: 'scanning' | 'creating-folders' | 'uploading-files' | 'linking' | 'complete';
268
+ totalFiles: number;
269
+ completedFiles: number;
270
+ totalFolders: number;
271
+ completedFolders: number;
272
+ currentFile?: string;
273
+ }
274
+ /**
275
+ * @deprecated Use UploadOptions from upload module
276
+ */
277
+ interface UploadDirectoryOptions {
278
+ /** Collection to upload into */
279
+ collectionId: string;
280
+ /** Parent folder ID (optional - creates at root if not provided) */
281
+ parentFolderId?: string;
282
+ /** Progress callback */
283
+ onProgress?: (progress: UploadProgress) => void;
284
+ /** Max concurrent uploads */
285
+ concurrency?: number;
286
+ }
287
+ /**
288
+ * @deprecated Use UploadResult from upload module
289
+ */
290
+ interface UploadDirectoryResult {
291
+ /** Root folder entity */
292
+ rootFolder: unknown;
293
+ /** All created folder entities */
294
+ folders: unknown[];
295
+ /** All created file entities */
296
+ files: unknown[];
297
+ }
298
+ /**
299
+ * Folder operations helper
300
+ *
301
+ * @deprecated Use uploadTree and scanDirectory functions instead:
302
+ * ```typescript
303
+ * import { uploadTree, scanDirectory } from '@arke-institute/sdk/operations';
304
+ *
305
+ * const tree = await scanDirectory('/path/to/folder');
306
+ * const result = await uploadTree(client, tree, {
307
+ * target: { collectionId: '...' },
308
+ * onProgress: (p) => console.log(`${p.completedFiles}/${p.totalFiles} files`),
309
+ * });
310
+ * ```
311
+ */
312
+ declare class FolderOperations {
313
+ private client;
314
+ constructor(client: ArkeClient);
315
+ /**
316
+ * Upload a local directory to Arke
317
+ *
318
+ * @deprecated Use uploadTree and scanDirectory instead
319
+ */
320
+ uploadDirectory(localPath: string, options: UploadDirectoryOptions): Promise<UploadDirectoryResult>;
321
+ }
322
+
323
+ /**
324
+ * Batch Operations
325
+ *
326
+ * High-level operations for bulk entity and relationship management.
327
+ *
328
+ * TODO: Implement batch operations
329
+ * - createEntities: Create multiple entities in parallel
330
+ * - updateEntities: Update multiple entities in parallel
331
+ * - createRelationships: Create multiple relationships in parallel
332
+ */
333
+
334
+ interface BatchCreateOptions {
335
+ /** Max concurrent operations */
336
+ concurrency?: number;
337
+ /** Continue on individual failures */
338
+ continueOnError?: boolean;
339
+ /** Progress callback */
340
+ onProgress?: (completed: number, total: number) => void;
341
+ }
342
+ interface BatchResult<T> {
343
+ /** Successfully completed operations */
344
+ succeeded: T[];
345
+ /** Failed operations with errors */
346
+ failed: Array<{
347
+ input: unknown;
348
+ error: Error;
349
+ }>;
350
+ }
351
+ /**
352
+ * Batch operations helper
353
+ *
354
+ * @example
355
+ * ```typescript
356
+ * const batch = new BatchOperations(arkeClient);
357
+ * const result = await batch.createEntities([
358
+ * { type: 'document', properties: { title: 'Doc 1' } },
359
+ * { type: 'document', properties: { title: 'Doc 2' } },
360
+ * ], { concurrency: 5 });
361
+ * ```
362
+ */
363
+ declare class BatchOperations {
364
+ private client;
365
+ constructor(client: ArkeClient);
366
+ /**
367
+ * Create multiple entities in parallel
368
+ *
369
+ * TODO: Implement this method
370
+ */
371
+ createEntities(_entities: Array<{
372
+ collectionId: string;
373
+ type: string;
374
+ properties?: Record<string, unknown>;
375
+ }>, _options?: BatchCreateOptions): Promise<BatchResult<unknown>>;
376
+ /**
377
+ * Create multiple relationships in parallel
378
+ *
379
+ * TODO: Implement this method
380
+ */
381
+ createRelationships(_relationships: Array<{
382
+ sourceId: string;
383
+ targetId: string;
384
+ predicate: string;
385
+ bidirectional?: boolean;
386
+ properties?: Record<string, unknown>;
387
+ }>, _options?: BatchCreateOptions): Promise<BatchResult<unknown>>;
388
+ }
389
+
390
+ /**
391
+ * Crypto Operations
392
+ *
393
+ * Cryptographic utilities for agents and content addressing.
394
+ *
395
+ * TODO: Implement crypto operations
396
+ * - generateKeyPair: Generate Ed25519 key pair for agent authentication
397
+ * - signPayload: Sign a payload with agent private key
398
+ * - computeCID: Compute IPFS CID for content
399
+ */
400
+ /**
401
+ * Ed25519 key pair for agent authentication
402
+ */
403
+ interface KeyPair {
404
+ /** Public key in base64 */
405
+ publicKey: string;
406
+ /** Private key in base64 (keep secret!) */
407
+ privateKey: string;
408
+ }
409
+ /**
410
+ * Signed payload with signature
411
+ */
412
+ interface SignedPayload {
413
+ /** Original payload */
414
+ payload: string;
415
+ /** Ed25519 signature in base64 */
416
+ signature: string;
417
+ /** Timestamp of signature */
418
+ timestamp: number;
419
+ }
420
+ /**
421
+ * Crypto operations helper
422
+ *
423
+ * @example
424
+ * ```typescript
425
+ * // Generate key pair for a new agent
426
+ * const { publicKey, privateKey } = await CryptoOperations.generateKeyPair();
427
+ *
428
+ * // Sign a payload
429
+ * const signed = await CryptoOperations.signPayload(privateKey, payload);
430
+ * ```
431
+ */
432
+ declare class CryptoOperations {
433
+ /**
434
+ * Generate an Ed25519 key pair for agent authentication
435
+ *
436
+ * TODO: Implement using Node.js crypto or Web Crypto API
437
+ */
438
+ static generateKeyPair(): Promise<KeyPair>;
439
+ /**
440
+ * Sign a payload with an Ed25519 private key
441
+ *
442
+ * TODO: Implement signature generation
443
+ */
444
+ static signPayload(_privateKey: string, _payload: string): Promise<SignedPayload>;
445
+ /**
446
+ * Verify an Ed25519 signature
447
+ *
448
+ * TODO: Implement signature verification
449
+ */
450
+ static verifySignature(_publicKey: string, _payload: string, _signature: string): Promise<boolean>;
451
+ /**
452
+ * Compute IPFS CID for content
453
+ *
454
+ * TODO: Implement using multiformats library
455
+ */
456
+ static computeCID(_content: Uint8Array): Promise<string>;
457
+ }
458
+
459
+ export { ArkeClient as A, BatchOperations as B, CryptoOperations as C, DEFAULT_CONFIG as D, FolderOperations as F, type KeyPair as K, type SignedPayload as S, type UploadProgress$1 as U, type ArkeApiClient as a, type ArkeClientConfig as b, createArkeClient as c, type UploadDirectoryOptions as d, type UploadDirectoryResult as e, type BatchCreateOptions as f, type BatchResult as g, type UploadTree as h, type UploadOptions as i, type UploadResult as j, type UploadFile as k, type UploadFolder as l, type UploadTarget as m, type CreatedEntity as n };