@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.
- package/README.md +222 -176
- package/dist/crypto-CQnwqWQn.d.ts +459 -0
- package/dist/crypto-iYgzUi77.d.cts +459 -0
- package/dist/generated/index.cjs +19 -0
- package/dist/generated/index.cjs.map +1 -0
- package/dist/generated/index.d.cts +6545 -0
- package/dist/generated/index.d.ts +6545 -0
- package/dist/generated/index.js +1 -0
- package/dist/generated/index.js.map +1 -0
- package/dist/index.cjs +725 -4248
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +62 -7
- package/dist/index.d.ts +62 -7
- package/dist/index.js +706 -4221
- package/dist/index.js.map +1 -1
- package/dist/operations/index.cjs +806 -0
- package/dist/operations/index.cjs.map +1 -0
- package/dist/operations/index.d.cts +157 -0
- package/dist/operations/index.d.ts +157 -0
- package/dist/operations/index.js +759 -0
- package/dist/operations/index.js.map +1 -0
- package/openapi/spec.json +8648 -0
- package/openapi/version.json +7 -0
- package/package.json +51 -52
- package/dist/client-dAk3E64p.d.cts +0 -183
- package/dist/client-dAk3E64p.d.ts +0 -183
- package/dist/collections/index.cjs +0 -233
- package/dist/collections/index.cjs.map +0 -1
- package/dist/collections/index.d.cts +0 -9
- package/dist/collections/index.d.ts +0 -9
- package/dist/collections/index.js +0 -205
- package/dist/collections/index.js.map +0 -1
- package/dist/content/index.cjs +0 -591
- package/dist/content/index.cjs.map +0 -1
- package/dist/content/index.d.cts +0 -516
- package/dist/content/index.d.ts +0 -516
- package/dist/content/index.js +0 -558
- package/dist/content/index.js.map +0 -1
- package/dist/edit/index.cjs +0 -1503
- package/dist/edit/index.cjs.map +0 -1
- package/dist/edit/index.d.cts +0 -78
- package/dist/edit/index.d.ts +0 -78
- package/dist/edit/index.js +0 -1447
- package/dist/edit/index.js.map +0 -1
- package/dist/errors-3L7IiHcr.d.cts +0 -480
- package/dist/errors-BTe8GKRQ.d.ts +0 -480
- package/dist/errors-CT7yzKkU.d.cts +0 -874
- package/dist/errors-CT7yzKkU.d.ts +0 -874
- package/dist/graph/index.cjs +0 -427
- package/dist/graph/index.cjs.map +0 -1
- package/dist/graph/index.d.cts +0 -485
- package/dist/graph/index.d.ts +0 -485
- package/dist/graph/index.js +0 -396
- package/dist/graph/index.js.map +0 -1
- package/dist/query/index.cjs +0 -356
- package/dist/query/index.cjs.map +0 -1
- package/dist/query/index.d.cts +0 -636
- package/dist/query/index.d.ts +0 -636
- package/dist/query/index.js +0 -328
- package/dist/query/index.js.map +0 -1
- package/dist/upload/index.cjs +0 -1634
- package/dist/upload/index.cjs.map +0 -1
- package/dist/upload/index.d.cts +0 -150
- package/dist/upload/index.d.ts +0 -150
- package/dist/upload/index.js +0 -1597
- package/dist/upload/index.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,258 +1,304 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @arke-institute/sdk
|
|
2
2
|
|
|
3
|
-
TypeScript SDK for
|
|
3
|
+
TypeScript SDK for the Arke API - auto-generated from OpenAPI spec.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
npm install @arke/sdk
|
|
8
|
+
npm install @arke-institute/sdk
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Quick Start
|
|
12
12
|
|
|
13
13
|
```typescript
|
|
14
|
-
import {
|
|
14
|
+
import { ArkeClient } from '@arke-institute/sdk';
|
|
15
15
|
|
|
16
|
-
const arke =
|
|
16
|
+
const arke = new ArkeClient({
|
|
17
17
|
authToken: 'your-jwt-token',
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
-
// Create
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// Upload files to create a new collection
|
|
27
|
-
const result = await arke.upload.createCollection({
|
|
28
|
-
files: './photos',
|
|
29
|
-
collectionMetadata: {
|
|
30
|
-
title: 'Photo Archive',
|
|
31
|
-
slug: 'photos',
|
|
20
|
+
// Create an entity
|
|
21
|
+
const { data, error } = await arke.api.POST('/entities', {
|
|
22
|
+
body: {
|
|
23
|
+
collection_id: '01ABC...',
|
|
24
|
+
type: 'document',
|
|
25
|
+
properties: { title: 'My Document' },
|
|
32
26
|
},
|
|
33
27
|
});
|
|
34
28
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
);
|
|
29
|
+
if (error) {
|
|
30
|
+
console.error('Failed:', error);
|
|
31
|
+
} else {
|
|
32
|
+
console.log('Created:', data.id);
|
|
33
|
+
}
|
|
39
34
|
```
|
|
40
35
|
|
|
41
|
-
##
|
|
36
|
+
## Configuration
|
|
42
37
|
|
|
43
|
-
|
|
38
|
+
```typescript
|
|
39
|
+
const arke = new ArkeClient({
|
|
40
|
+
// Base URL (default: 'https://arke-v1.arke.institute')
|
|
41
|
+
baseUrl: 'https://arke-v1.arke.institute',
|
|
44
42
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
| **collections** | Create/manage collections, members, invitations | Yes |
|
|
48
|
-
| **upload** | Upload files, create/add to collections | Yes |
|
|
49
|
-
| **edit** | Edit entities, trigger AI regeneration | Yes |
|
|
50
|
-
| **query** | Search and traverse the knowledge graph | No (public) |
|
|
51
|
-
| **content** | Read entities, download content | No (public) |
|
|
43
|
+
// JWT or API key
|
|
44
|
+
authToken: 'your-token',
|
|
52
45
|
|
|
53
|
-
|
|
46
|
+
// Network: 'main' or 'test' (default: 'main')
|
|
47
|
+
network: 'test',
|
|
54
48
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
│ │
|
|
61
|
-
upload edit
|
|
62
|
-
|
|
63
|
-
query (independent)
|
|
64
|
-
content (independent)
|
|
49
|
+
// Custom headers
|
|
50
|
+
headers: {
|
|
51
|
+
'X-Custom-Header': 'value',
|
|
52
|
+
},
|
|
53
|
+
});
|
|
65
54
|
```
|
|
66
55
|
|
|
67
|
-
##
|
|
56
|
+
## API Access
|
|
68
57
|
|
|
69
|
-
|
|
58
|
+
All API calls are made through the `arke.api` property, which provides full type safety:
|
|
70
59
|
|
|
71
60
|
```typescript
|
|
72
|
-
//
|
|
73
|
-
await arke.
|
|
61
|
+
// GET request
|
|
62
|
+
const { data } = await arke.api.GET('/entities/{id}', {
|
|
63
|
+
params: { path: { id: '01XYZ...' } },
|
|
64
|
+
});
|
|
74
65
|
|
|
75
|
-
//
|
|
76
|
-
const
|
|
66
|
+
// POST request
|
|
67
|
+
const { data } = await arke.api.POST('/entities', {
|
|
68
|
+
body: { collection_id: '...', type: 'document', properties: {} },
|
|
69
|
+
});
|
|
77
70
|
|
|
78
|
-
//
|
|
79
|
-
await arke.
|
|
71
|
+
// PUT request (update)
|
|
72
|
+
const { data } = await arke.api.PUT('/entities/{id}', {
|
|
73
|
+
params: { path: { id: '01XYZ...' } },
|
|
74
|
+
body: { expect_tip: 'bafyrei...', properties_merge: { status: 'active' } },
|
|
75
|
+
});
|
|
80
76
|
|
|
81
|
-
//
|
|
82
|
-
await arke.
|
|
83
|
-
|
|
77
|
+
// DELETE request
|
|
78
|
+
await arke.api.DELETE('/relationships', {
|
|
79
|
+
body: { source_id: '...', target_id: '...', predicate: 'contains' },
|
|
80
|
+
});
|
|
84
81
|
```
|
|
85
82
|
|
|
86
|
-
|
|
83
|
+
## Available Endpoints
|
|
84
|
+
|
|
85
|
+
The SDK provides typed access to all Arke API endpoints:
|
|
86
|
+
|
|
87
|
+
| Endpoint Group | Description |
|
|
88
|
+
|----------------|-------------|
|
|
89
|
+
| `/auth/*` | Authentication and registration |
|
|
90
|
+
| `/users/*` | User profile and API keys |
|
|
91
|
+
| `/collections/*` | Collection CRUD, roles, members |
|
|
92
|
+
| `/entities/*` | Entity CRUD |
|
|
93
|
+
| `/relationships` | Relationship management |
|
|
94
|
+
| `/files/*` | File storage and downloads |
|
|
95
|
+
| `/folders/*` | Folder hierarchy |
|
|
96
|
+
| `/versions/*` | Version history |
|
|
97
|
+
| `/agents/*` | Agent management |
|
|
98
|
+
| `/permissions/*` | Permission introspection |
|
|
99
|
+
|
|
100
|
+
## Error Handling
|
|
87
101
|
|
|
88
102
|
```typescript
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
103
|
+
import {
|
|
104
|
+
ArkeError,
|
|
105
|
+
CASConflictError,
|
|
106
|
+
NotFoundError,
|
|
107
|
+
parseApiError
|
|
108
|
+
} from '@arke-institute/sdk';
|
|
109
|
+
|
|
110
|
+
const { data, error, response } = await arke.api.GET('/entities/{id}', {
|
|
111
|
+
params: { path: { id: 'invalid-id' } },
|
|
93
112
|
});
|
|
94
113
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
114
|
+
if (error) {
|
|
115
|
+
// Parse into typed error
|
|
116
|
+
const arkeError = parseApiError(response.status, error);
|
|
117
|
+
|
|
118
|
+
if (arkeError instanceof CASConflictError) {
|
|
119
|
+
console.log('Concurrent modification - expected:', arkeError.expectedTip);
|
|
120
|
+
} else if (arkeError instanceof NotFoundError) {
|
|
121
|
+
console.log('Entity not found');
|
|
122
|
+
}
|
|
123
|
+
}
|
|
100
124
|
```
|
|
101
125
|
|
|
102
|
-
|
|
126
|
+
## Authentication Management
|
|
103
127
|
|
|
104
128
|
```typescript
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
129
|
+
const arke = new ArkeClient();
|
|
130
|
+
|
|
131
|
+
// Set token after login
|
|
132
|
+
arke.setAuthToken('new-token');
|
|
133
|
+
|
|
134
|
+
// Check auth status
|
|
135
|
+
if (arke.isAuthenticated) {
|
|
136
|
+
// Make authenticated requests
|
|
137
|
+
}
|
|
109
138
|
|
|
110
|
-
//
|
|
111
|
-
|
|
139
|
+
// Clear token on logout
|
|
140
|
+
arke.clearAuthToken();
|
|
112
141
|
```
|
|
113
142
|
|
|
114
|
-
|
|
143
|
+
## Test Network
|
|
144
|
+
|
|
145
|
+
Use the test network for development (uses 'II' prefixed IDs):
|
|
115
146
|
|
|
116
147
|
```typescript
|
|
117
|
-
|
|
118
|
-
|
|
148
|
+
const arke = new ArkeClient({
|
|
149
|
+
authToken: 'your-token',
|
|
150
|
+
network: 'test',
|
|
151
|
+
});
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Folder Upload
|
|
155
|
+
|
|
156
|
+
Upload entire folder structures with automatic CID computation and relationship linking:
|
|
157
|
+
|
|
158
|
+
### Node.js
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
import { ArkeClient } from '@arke-institute/sdk';
|
|
162
|
+
import { uploadTree, scanDirectory } from '@arke-institute/sdk/operations';
|
|
163
|
+
|
|
164
|
+
const arke = new ArkeClient({ authToken: 'your-token' });
|
|
119
165
|
|
|
120
|
-
//
|
|
121
|
-
|
|
166
|
+
// Scan a local directory
|
|
167
|
+
const tree = await scanDirectory('/path/to/my-folder');
|
|
122
168
|
|
|
123
|
-
//
|
|
124
|
-
await arke
|
|
169
|
+
// Upload to a new collection
|
|
170
|
+
const result = await uploadTree(arke, tree, {
|
|
171
|
+
target: {
|
|
172
|
+
createCollection: {
|
|
173
|
+
label: 'My Upload',
|
|
174
|
+
description: 'Uploaded folder contents',
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
onProgress: (p) => {
|
|
178
|
+
console.log(`${p.phase}: ${p.completedFiles}/${p.totalFiles} files`);
|
|
179
|
+
},
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
console.log('Collection:', result.collection.id);
|
|
183
|
+
console.log('Files:', result.files.length);
|
|
184
|
+
console.log('Folders:', result.folders.length);
|
|
125
185
|
```
|
|
126
186
|
|
|
127
|
-
###
|
|
187
|
+
### Browser (Drag & Drop)
|
|
128
188
|
|
|
129
189
|
```typescript
|
|
130
|
-
|
|
131
|
-
|
|
190
|
+
import { uploadTree, scanFileSystemEntries } from '@arke-institute/sdk/operations';
|
|
191
|
+
|
|
192
|
+
dropzone.ondrop = async (e) => {
|
|
193
|
+
e.preventDefault();
|
|
194
|
+
const entries = Array.from(e.dataTransfer.items)
|
|
195
|
+
.map(item => item.webkitGetAsEntry())
|
|
196
|
+
.filter(Boolean);
|
|
197
|
+
|
|
198
|
+
const tree = await scanFileSystemEntries(entries);
|
|
199
|
+
const result = await uploadTree(client, tree, {
|
|
200
|
+
target: { collectionId: 'existing-collection-id' },
|
|
201
|
+
});
|
|
202
|
+
};
|
|
203
|
+
```
|
|
132
204
|
|
|
133
|
-
|
|
134
|
-
const blob = await arke.content.download('pi:abc123');
|
|
205
|
+
### Browser (File Input)
|
|
135
206
|
|
|
136
|
-
|
|
137
|
-
|
|
207
|
+
```typescript
|
|
208
|
+
import { uploadTree, scanFileList } from '@arke-institute/sdk/operations';
|
|
209
|
+
|
|
210
|
+
// <input type="file" webkitdirectory multiple />
|
|
211
|
+
input.onchange = async (e) => {
|
|
212
|
+
const tree = await scanFileList(e.target.files);
|
|
213
|
+
const result = await uploadTree(client, tree, {
|
|
214
|
+
target: { parentId: 'existing-folder-id', collectionId: 'collection-id' },
|
|
215
|
+
});
|
|
216
|
+
};
|
|
138
217
|
```
|
|
139
218
|
|
|
140
|
-
|
|
219
|
+
### Upload Options
|
|
141
220
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
- [content package](./packages/content/PLAN.md)
|
|
221
|
+
```typescript
|
|
222
|
+
const result = await uploadTree(client, tree, {
|
|
223
|
+
target: {
|
|
224
|
+
// Option 1: Create new collection
|
|
225
|
+
createCollection: { label: 'New Collection' },
|
|
148
226
|
|
|
149
|
-
|
|
227
|
+
// Option 2: Upload to existing collection root
|
|
228
|
+
collectionId: '01ABC...',
|
|
150
229
|
|
|
230
|
+
// Option 3: Upload to existing folder
|
|
231
|
+
collectionId: '01ABC...',
|
|
232
|
+
parentId: '01XYZ...',
|
|
233
|
+
},
|
|
234
|
+
|
|
235
|
+
// Progress tracking
|
|
236
|
+
onProgress: (p) => console.log(p.phase, p.completedFiles),
|
|
237
|
+
|
|
238
|
+
// Parallel uploads (default: 5)
|
|
239
|
+
concurrency: 10,
|
|
240
|
+
|
|
241
|
+
// Continue if some files fail
|
|
242
|
+
continueOnError: true,
|
|
243
|
+
});
|
|
151
244
|
```
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
│ ├── upload/
|
|
165
|
-
│ │ ├── index.ts
|
|
166
|
-
│ │ ├── uploader.ts # Main uploader class
|
|
167
|
-
│ │ ├── create-collection.ts
|
|
168
|
-
│ │ ├── add-to-collection.ts
|
|
169
|
-
│ │ └── types.ts
|
|
170
|
-
│ ├── edit/
|
|
171
|
-
│ │ ├── index.ts
|
|
172
|
-
│ │ ├── session.ts # Edit session
|
|
173
|
-
│ │ ├── diff.ts # Diff engine
|
|
174
|
-
│ │ └── types.ts
|
|
175
|
-
│ ├── query/
|
|
176
|
-
│ │ ├── index.ts
|
|
177
|
-
│ │ ├── path-query.ts # Direct path queries
|
|
178
|
-
│ │ ├── natural-query.ts # NL queries
|
|
179
|
-
│ │ ├── collection-search.ts
|
|
180
|
-
│ │ └── types.ts
|
|
181
|
-
│ └── content/
|
|
182
|
-
│ ├── index.ts
|
|
183
|
-
│ ├── entities.ts # Entity operations
|
|
184
|
-
│ ├── download.ts # Content download
|
|
185
|
-
│ └── types.ts
|
|
186
|
-
├── package.json
|
|
187
|
-
├── tsconfig.json
|
|
188
|
-
└── README.md
|
|
245
|
+
|
|
246
|
+
### CID Utilities
|
|
247
|
+
|
|
248
|
+
```typescript
|
|
249
|
+
import { computeCid, verifyCid } from '@arke-institute/sdk/operations';
|
|
250
|
+
|
|
251
|
+
// Compute CIDv1 for any content
|
|
252
|
+
const cid = await computeCid(new TextEncoder().encode('hello'));
|
|
253
|
+
// => "bafkreifzjut3te2nhyekklss27nh3k72ysco7y32koao5eei66wof36n5e"
|
|
254
|
+
|
|
255
|
+
// Verify content matches CID
|
|
256
|
+
const isValid = await verifyCid(content, expectedCid);
|
|
189
257
|
```
|
|
190
258
|
|
|
191
|
-
##
|
|
259
|
+
## Development
|
|
192
260
|
|
|
193
|
-
|
|
261
|
+
### Regenerate Types
|
|
194
262
|
|
|
195
|
-
|
|
263
|
+
When the API changes, regenerate the types:
|
|
196
264
|
|
|
197
265
|
```bash
|
|
198
|
-
|
|
266
|
+
# From production API
|
|
267
|
+
npm run generate
|
|
268
|
+
|
|
269
|
+
# From local dev server
|
|
270
|
+
npm run generate:local
|
|
199
271
|
```
|
|
200
272
|
|
|
201
|
-
###
|
|
273
|
+
### Build
|
|
202
274
|
|
|
203
275
|
```bash
|
|
204
|
-
npm
|
|
205
|
-
npm publish
|
|
276
|
+
npm run build
|
|
206
277
|
```
|
|
207
278
|
|
|
208
|
-
###
|
|
279
|
+
### Test
|
|
209
280
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
```typescript
|
|
213
|
-
// Full SDK
|
|
214
|
-
import { createClient } from '@arke/sdk';
|
|
215
|
-
const arke = createClient({ authToken });
|
|
216
|
-
arke.collections.create(...);
|
|
217
|
-
|
|
218
|
-
// Specific packages (tree-shakeable)
|
|
219
|
-
import { CollectionsClient } from '@arke/sdk/collections';
|
|
220
|
-
import { UploadClient } from '@arke/sdk/upload';
|
|
281
|
+
```bash
|
|
282
|
+
npm test
|
|
221
283
|
```
|
|
222
284
|
|
|
223
|
-
|
|
285
|
+
### Publish
|
|
224
286
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
3. **Collections Worker** (new) - Manages collections in Supabase
|
|
229
|
-
|
|
230
|
-
### SDK (This Repo)
|
|
231
|
-
4. collections package
|
|
232
|
-
5. content package
|
|
233
|
-
6. upload package (refactor existing)
|
|
234
|
-
7. edit package (refactor existing)
|
|
235
|
-
8. query package
|
|
287
|
+
```bash
|
|
288
|
+
# Dry run
|
|
289
|
+
npm run publish-all:dry
|
|
236
290
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
291
|
+
# Actual publish
|
|
292
|
+
npm run publish-all
|
|
293
|
+
```
|
|
240
294
|
|
|
241
|
-
##
|
|
295
|
+
## Future Operations
|
|
242
296
|
|
|
243
|
-
The SDK
|
|
297
|
+
The SDK includes placeholder modules for additional high-level operations:
|
|
244
298
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
| `/collections/*`, `/me/*`, `/invitations/*` | Collections Worker |
|
|
248
|
-
| `/ingest/*` | Ingest Worker |
|
|
249
|
-
| `/api/*` | IPFS Wrapper |
|
|
250
|
-
| `/reprocess/*` | Reprocess API |
|
|
251
|
-
| `/query/*` | Query Links |
|
|
252
|
-
| `/translate/*` | Query Translator |
|
|
299
|
+
- **BatchOperations**: Bulk entity/relationship creation
|
|
300
|
+
- **CryptoOperations**: Ed25519 key generation
|
|
253
301
|
|
|
254
|
-
##
|
|
302
|
+
## License
|
|
255
303
|
|
|
256
|
-
|
|
257
|
-
- **Arke CLI** (`arke-cli/`) - Command-line interface using this SDK
|
|
258
|
-
- **Arke Gateway** (`arke-gateway/`) - API gateway routing
|
|
304
|
+
MIT
|