@arke-institute/sdk 0.1.2 → 2.0.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 (64) hide show
  1. package/README.md +126 -184
  2. package/dist/generated/index.cjs +19 -0
  3. package/dist/generated/index.cjs.map +1 -0
  4. package/dist/generated/index.d.cts +6192 -0
  5. package/dist/generated/index.d.ts +6192 -0
  6. package/dist/generated/index.js +1 -0
  7. package/dist/generated/index.js.map +1 -0
  8. package/dist/index-BrXke2kI.d.ts +302 -0
  9. package/dist/index-FHcLPBSV.d.cts +302 -0
  10. package/dist/index.cjs +188 -3654
  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 +168 -3626
  15. package/dist/index.js.map +1 -1
  16. package/dist/operations/index.cjs +113 -0
  17. package/dist/operations/index.cjs.map +1 -0
  18. package/dist/operations/index.d.cts +3 -0
  19. package/dist/operations/index.d.ts +3 -0
  20. package/dist/operations/index.js +84 -0
  21. package/dist/operations/index.js.map +1 -0
  22. package/package.json +44 -53
  23. package/dist/client-dAk3E64p.d.cts +0 -183
  24. package/dist/client-dAk3E64p.d.ts +0 -183
  25. package/dist/collections/index.cjs +0 -233
  26. package/dist/collections/index.cjs.map +0 -1
  27. package/dist/collections/index.d.cts +0 -9
  28. package/dist/collections/index.d.ts +0 -9
  29. package/dist/collections/index.js +0 -205
  30. package/dist/collections/index.js.map +0 -1
  31. package/dist/content/index.cjs +0 -506
  32. package/dist/content/index.cjs.map +0 -1
  33. package/dist/content/index.d.cts +0 -403
  34. package/dist/content/index.d.ts +0 -403
  35. package/dist/content/index.js +0 -473
  36. package/dist/content/index.js.map +0 -1
  37. package/dist/edit/index.cjs +0 -1029
  38. package/dist/edit/index.cjs.map +0 -1
  39. package/dist/edit/index.d.cts +0 -78
  40. package/dist/edit/index.d.ts +0 -78
  41. package/dist/edit/index.js +0 -983
  42. package/dist/edit/index.js.map +0 -1
  43. package/dist/errors-3L7IiHcr.d.cts +0 -480
  44. package/dist/errors-B82BMmRP.d.cts +0 -343
  45. package/dist/errors-B82BMmRP.d.ts +0 -343
  46. package/dist/errors-BTe8GKRQ.d.ts +0 -480
  47. package/dist/graph/index.cjs +0 -433
  48. package/dist/graph/index.cjs.map +0 -1
  49. package/dist/graph/index.d.cts +0 -456
  50. package/dist/graph/index.d.ts +0 -456
  51. package/dist/graph/index.js +0 -402
  52. package/dist/graph/index.js.map +0 -1
  53. package/dist/query/index.cjs +0 -289
  54. package/dist/query/index.cjs.map +0 -1
  55. package/dist/query/index.d.cts +0 -541
  56. package/dist/query/index.d.ts +0 -541
  57. package/dist/query/index.js +0 -261
  58. package/dist/query/index.js.map +0 -1
  59. package/dist/upload/index.cjs +0 -1634
  60. package/dist/upload/index.cjs.map +0 -1
  61. package/dist/upload/index.d.cts +0 -150
  62. package/dist/upload/index.d.ts +0 -150
  63. package/dist/upload/index.js +0 -1597
  64. package/dist/upload/index.js.map +0 -1
package/README.md CHANGED
@@ -1,258 +1,200 @@
1
- # Arke SDK
1
+ # @arke-institute/sdk
2
2
 
3
- TypeScript SDK for building applications on the Arke platform.
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 { createClient } from '@arke/sdk';
14
+ import { ArkeClient } from '@arke-institute/sdk';
15
15
 
16
- const arke = createClient({
16
+ const arke = new ArkeClient({
17
17
  authToken: 'your-jwt-token',
18
18
  });
19
19
 
20
- // Create a collection
21
- const collection = await arke.collections.create({
22
- title: 'My Archive',
23
- slug: 'my-archive',
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
- // Query the knowledge graph
36
- const results = await arke.query.natural(
37
- 'Who are the people in photographs from Hawaii?'
38
- );
29
+ if (error) {
30
+ console.error('Failed:', error);
31
+ } else {
32
+ console.log('Created:', data.id);
33
+ }
39
34
  ```
40
35
 
41
- ## Packages
36
+ ## Configuration
42
37
 
43
- The SDK contains five packages:
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
- | Package | Purpose | Auth Required |
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
- ### Package Dependency Graph
46
+ // Network: 'main' or 'test' (default: 'main')
47
+ network: 'test',
54
48
 
55
- ```
56
- collections (foundational)
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
- ## Package Details
56
+ ## API Access
68
57
 
69
- ### collections
58
+ All API calls are made through the `arke.api` property, which provides full type safety:
70
59
 
71
60
  ```typescript
72
- // Create collection
73
- await arke.collections.create({ title, slug, description, visibility });
74
-
75
- // List collections
76
- const collections = await arke.collections.list({ page: 1 });
77
-
78
- // Manage members
79
- await arke.members.updateRole(collectionId, userId, 'editor');
80
-
81
- // Invitations
82
- await arke.invitations.create(collectionId, { email, role: 'editor' });
83
- await arke.invitations.accept(invitationId);
84
- ```
61
+ // GET request
62
+ const { data } = await arke.api.GET('/entities/{id}', {
63
+ params: { path: { id: '01XYZ...' } },
64
+ });
85
65
 
86
- ### upload
66
+ // POST request
67
+ const { data } = await arke.api.POST('/entities', {
68
+ body: { collection_id: '...', type: 'document', properties: {} },
69
+ });
87
70
 
88
- ```typescript
89
- // Create new collection from files (anyone authenticated)
90
- await arke.upload.createCollection({
91
- files: './photos',
92
- collectionMetadata: { title: 'My Archive', slug: 'my-archive' },
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' } },
93
75
  });
94
76
 
95
- // Add to existing collection (requires membership)
96
- await arke.upload.addToCollection({
97
- files: './more-photos',
98
- parentPi: 'pi:existing-root',
77
+ // DELETE request
78
+ await arke.api.DELETE('/relationships', {
79
+ body: { source_id: '...', target_id: '...', predicate: 'contains' },
99
80
  });
100
81
  ```
101
82
 
102
- ### edit
83
+ ## Available Endpoints
103
84
 
104
- ```typescript
105
- // Edit entity
106
- const session = await arke.edit.createSession('pi:abc123');
107
- session.setPrompt('Update the description');
108
- const result = await session.submit();
85
+ The SDK provides typed access to all Arke API endpoints:
109
86
 
110
- // Trigger AI regeneration
111
- await arke.edit.regenerate('pi:abc123');
112
- ```
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 |
113
99
 
114
- ### query
100
+ ## Error Handling
115
101
 
116
102
  ```typescript
117
- // Direct path query (requires knowing syntax)
118
- await arke.query.path('"Hawaii" -[depicts]-> type:person');
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' } },
112
+ });
119
113
 
120
- // Natural language (LLM translates to path query)
121
- await arke.query.natural('Who photographed Pearl Harbor?');
114
+ if (error) {
115
+ // Parse into typed error
116
+ const arkeError = parseApiError(response.status, error);
122
117
 
123
- // Collection search
124
- await arke.query.searchCollection(collectionId, 'family portraits');
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
+ }
125
124
  ```
126
125
 
127
- ### content
126
+ ## Authentication Management
128
127
 
129
128
  ```typescript
130
- // Get entity
131
- const entity = await arke.content.get('pi:abc123');
129
+ const arke = new ArkeClient();
132
130
 
133
- // Download content
134
- const blob = await arke.content.download('pi:abc123');
131
+ // Set token after login
132
+ arke.setAuthToken('new-token');
135
133
 
136
- // Get version history
137
- const versions = await arke.content.versions('pi:abc123');
138
- ```
134
+ // Check auth status
135
+ if (arke.isAuthenticated) {
136
+ // Make authenticated requests
137
+ }
139
138
 
140
- ## Documentation
139
+ // Clear token on logout
140
+ arke.clearAuthToken();
141
+ ```
141
142
 
142
- - [Architecture Overview](./ARCHITECTURE.md)
143
- - [collections package](./packages/collections/PLAN.md)
144
- - [upload package](./packages/upload/PLAN.md)
145
- - [edit package](./packages/edit/PLAN.md)
146
- - [query package](./packages/query/PLAN.md)
147
- - [content package](./packages/content/PLAN.md)
143
+ ## Test Network
148
144
 
149
- ## Project Structure
145
+ Use the test network for development (uses 'II' prefixed IDs):
150
146
 
151
- ```
152
- arke-sdk/
153
- ├── src/
154
- │ ├── index.ts # Main entry, createClient()
155
- │ ├── client.ts # Base HTTP client
156
- │ └── types.ts # Shared types
157
- ├── packages/
158
- │ ├── collections/
159
- │ │ ├── index.ts # Package entry
160
- │ │ ├── collections.ts # Collection CRUD
161
- │ │ ├── members.ts # Membership operations
162
- │ │ ├── invitations.ts # Invitation operations
163
- │ │ └── types.ts
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
147
+ ```typescript
148
+ const arke = new ArkeClient({
149
+ authToken: 'your-token',
150
+ network: 'test',
151
+ });
189
152
  ```
190
153
 
191
- ## Distribution
154
+ ## Development
192
155
 
193
- The SDK is published to npm as `@arke/sdk`.
156
+ ### Regenerate Types
194
157
 
195
- ### Building
158
+ When the API changes, regenerate the types:
196
159
 
197
160
  ```bash
198
- npm run build
161
+ # From production API
162
+ npm run generate
163
+
164
+ # From local dev server
165
+ npm run generate:local
199
166
  ```
200
167
 
201
- ### Publishing
168
+ ### Build
202
169
 
203
170
  ```bash
204
- npm version patch|minor|major
205
- npm publish
171
+ npm run build
206
172
  ```
207
173
 
208
- ### Imports
209
-
210
- Users can import the full SDK or specific packages:
174
+ ### Test
211
175
 
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';
176
+ ```bash
177
+ npm test
221
178
  ```
222
179
 
223
- ## Implementation Order
180
+ ### Publish
224
181
 
225
- ### Backend (Workers)
226
- 1. GraphDB Gateway - Add `is_collection_root` field + update endpoint
227
- 2. Query Links - Add filter support for `is_collection_root`
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
182
+ ```bash
183
+ # Dry run
184
+ npm run publish-all:dry
236
185
 
237
- ### Consumers
238
- 9. CLI (`arke-cli/`)
239
- 10. Web Frontend
186
+ # Actual publish
187
+ npm run publish-all
188
+ ```
240
189
 
241
- ## Backend Architecture
190
+ ## Future Operations (TODO)
242
191
 
243
- The SDK calls the Arke Gateway (`api.arke.institute`), which routes to workers:
192
+ The SDK includes placeholder modules for high-level operations:
244
193
 
245
- | Route | Worker |
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 |
194
+ - **FolderOperations**: Recursive directory upload
195
+ - **BatchOperations**: Bulk entity/relationship creation
196
+ - **CryptoOperations**: Ed25519 key generation, CID computation
253
197
 
254
- ## Related Repositories
198
+ ## License
255
199
 
256
- - **Collections Worker** - Backend for collection management (new)
257
- - **Arke CLI** (`arke-cli/`) - Command-line interface using this SDK
258
- - **Arke Gateway** (`arke-gateway/`) - API gateway routing
200
+ MIT
@@ -0,0 +1,19 @@
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 __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+
16
+ // src/generated/index.ts
17
+ var generated_exports = {};
18
+ module.exports = __toCommonJS(generated_exports);
19
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/generated/index.ts"],"sourcesContent":["/**\n * Auto-generated types from OpenAPI spec\n *\n * Run `npm run generate` to regenerate these types from the API spec.\n */\n\nexport type { paths, components, operations } from './types.js';\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}