@onlyworlds/sdk 2.2.3 → 3.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.
package/README.md CHANGED
@@ -5,22 +5,77 @@
5
5
 
6
6
  A type-safe TypeScript SDK for building world-building applications with the OnlyWorlds API.
7
7
 
8
+ The SDK speaks two dialects of the same API:
9
+
10
+ - **v2 (`OwV2Client`)** -- the current, recommended default. Local-first shape: one-shape read/write (no `_ids` suffix), an opaque `/changes` sync feed, atomic bulk writes, and client-side UUID minting for safe retries. Base URL `https://www.onlyworlds.com/api/v2`.
11
+ - **v1 (`OnlyWorldsClient`)** -- the original resource-style client. Fully served forever; kept below as the legacy section. Existing 2.x code keeps working unchanged -- v2 is purely additive.
12
+
8
13
  ## Installation
9
14
 
10
15
  ```bash
11
16
  npm install @onlyworlds/sdk
12
17
  ```
13
18
 
14
- ## Quick Start
19
+ ## Quick Start (v2 -- recommended)
20
+
21
+ ```typescript
22
+ import { OwV2Client } from '@onlyworlds/sdk';
23
+
24
+ const client = new OwV2Client({
25
+ apiKey: 'ow_w_your_world_key', // ow_w_ write / ow_r_ read / ow_a_ account / 10-digit legacy
26
+ apiPin: '1234', // needed for writes on a PIN-protected world
27
+ });
28
+ // baseUrl defaults to https://www.onlyworlds.com/api/v2
29
+
30
+ // Read a page, or walk every page of a type
31
+ const page = await client.list('character'); // { data, has_more, next_cursor }
32
+ for await (const character of client.listAll('character')) {
33
+ // ...
34
+ }
35
+
36
+ // Create -- id is minted client-side when omitted (retries stay idempotent)
37
+ const location = await client.create('location', {
38
+ name: 'Dragon Peak',
39
+ description: 'A treacherous mountain peak where dragons nest',
40
+ });
41
+
42
+ // Partial update (arrays replace wholesale -- for links prefer editLinks)
43
+ await client.patch('character', location.id, { name: 'Updated Name' });
44
+
45
+ // Atomic link merge -- returns the full updated element
46
+ await client.editLinks('event', eventId, 'objects', { add: [swordId], remove: [] });
47
+
48
+ // Bulk write (up to ~1000; partial success by default, atomic:true for all-or-nothing)
49
+ const res = await client.bulk([
50
+ { type: 'character', element: { name: 'A' } },
51
+ { type: 'event', element: { name: 'B' } },
52
+ ]);
53
+ // res.items[i].status is the per-slot HTTP status; res.errors flags any failure
54
+
55
+ // Sync: walk the opaque change feed and persist the final cursor
56
+ let cursor;
57
+ for await (const change of client.changesAll(cursor)) {
58
+ // apply change in order
59
+ }
60
+ ```
61
+
62
+ ### AI-assistant access (MCP)
63
+
64
+ An MCP server exists at `https://www.onlyworlds.com/mcp` for AI assistants (Claude and other MCP clients) to read and write worlds directly -- no SDK code required. See the [docs](https://onlyworlds.github.io) for setup.
65
+
66
+ ## Legacy: v1 client (`OnlyWorldsClient`)
67
+
68
+ The v1 resource-style client remains fully supported and served forever. Prefer `OwV2Client` for new code.
15
69
 
16
70
  ```typescript
17
71
  import { OnlyWorldsClient } from '@onlyworlds/sdk';
18
72
 
19
73
  const client = new OnlyWorldsClient({
20
74
  apiKey: 'your-api-key',
21
- apiPin: '1234',
22
- baseUrl: 'https://onlyworlds.com'
75
+ apiPin: '1234'
23
76
  });
77
+ // baseUrl defaults to https://www.onlyworlds.com/api/worldapi — only override it
78
+ // when pointing at a different host (it must include the full API path)
24
79
 
25
80
  // Get your world (API keys are world-scoped)
26
81
  const world = await client.worlds.get();