@shaunlwm/pickle.ts 1.10.0 → 1.11.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 +63 -8
- package/dist/index.d.ts +436 -88
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +6 -5
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Type-safe client library for Club Penguin Private Servers.
|
|
4
4
|
|
|
5
|
-
Built with TypeScript, Socket.IO, and msgpack. Supports
|
|
5
|
+
Built with TypeScript, Socket.IO, and msgpack. Supports CPJourney, CPLegacy, NewCP, and PenguinOrigins through an adapter pattern.
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -13,7 +13,7 @@ npm install @shaunlwm/pickle.ts
|
|
|
13
13
|
## Quick Start
|
|
14
14
|
|
|
15
15
|
```typescript
|
|
16
|
-
import { Client } from "pickle.ts"
|
|
16
|
+
import { Client } from "@shaunlwm/pickle.ts"
|
|
17
17
|
|
|
18
18
|
const client = new Client("CPJourney")
|
|
19
19
|
|
|
@@ -44,7 +44,7 @@ Creates a new client instance.
|
|
|
44
44
|
|
|
45
45
|
| Param | Type | Description |
|
|
46
46
|
|---|---|---|
|
|
47
|
-
| `server` | `"CPJourney" \| "CPLegacy"` | CPPS server identifier (strongly typed) |
|
|
47
|
+
| `server` | `"CPJourney" \| "CPLegacy" \| "NewCP" \| "PenguinOrigins"` | CPPS server identifier (strongly typed) |
|
|
48
48
|
| `options.debug` | `boolean \| LogFn` | Enable debug logging. Pass `true` for console.log, or a custom function |
|
|
49
49
|
| `options.connectionProfile` | `"chrome" \| "node" \| ConnectionProfile` | Controls HTTP/WebSocket headers. Defaults to browser-like Chrome headers; use `"node"` to preserve Node defaults |
|
|
50
50
|
|
|
@@ -72,7 +72,7 @@ const profiledClient = new Client("CPJourney", {
|
|
|
72
72
|
})
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
-
### `client.login(options)`
|
|
75
|
+
### `client.login(options, operationOptions?)`
|
|
76
76
|
|
|
77
77
|
Authenticates and returns the server list with populations.
|
|
78
78
|
|
|
@@ -80,6 +80,9 @@ Authenticates and returns the server list with populations.
|
|
|
80
80
|
const servers = await client.login({
|
|
81
81
|
username: "user",
|
|
82
82
|
password: "pass",
|
|
83
|
+
}, {
|
|
84
|
+
timeoutMs: 20_000,
|
|
85
|
+
signal: abortController.signal,
|
|
83
86
|
})
|
|
84
87
|
// servers: ServerInfo[] = [{ name: string, population: number }]
|
|
85
88
|
```
|
|
@@ -110,6 +113,28 @@ await client.connect("Blizzard", {
|
|
|
110
113
|
|
|
111
114
|
After `connect()` resolves, `client.player`, `client.room`, and `client.users` are populated.
|
|
112
115
|
|
|
116
|
+
Connection progress can be observed without parsing log strings:
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
119
|
+
await client.connect("Blizzard", {
|
|
120
|
+
signal: abortController.signal,
|
|
121
|
+
timeouts: {
|
|
122
|
+
transportMs: 20_000,
|
|
123
|
+
queueMs: 300_000, // maximum silence between queue updates, not total queue time
|
|
124
|
+
authenticationMs: 20_000,
|
|
125
|
+
initialStateMs: 15_000,
|
|
126
|
+
},
|
|
127
|
+
onLifecycleUpdate: ({ phase, queue }) => {
|
|
128
|
+
console.log(phase, queue?.position)
|
|
129
|
+
},
|
|
130
|
+
})
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Login, connection, and request failures reject with `ClientOperationError`. Its
|
|
134
|
+
`category`, `phase`, and `retryable` fields are safe for supervisor decisions;
|
|
135
|
+
`unsupported_operation` is always non-retryable. Request methods accept
|
|
136
|
+
`{ timeoutMs, signal }`, defaulting to a 15-second response timeout.
|
|
137
|
+
|
|
113
138
|
### State
|
|
114
139
|
|
|
115
140
|
| Property | Type | Description |
|
|
@@ -165,6 +190,25 @@ client.getStamps(userId) // view stampbook
|
|
|
165
190
|
client.getIglooOpen(userId) // check if igloo is open
|
|
166
191
|
client.joinIgloo(userId) // enter igloo
|
|
167
192
|
|
|
193
|
+
// CPJourney igloo editor/store
|
|
194
|
+
client.openIglooEditor()
|
|
195
|
+
client.updateIglooFurniture(furniture)
|
|
196
|
+
client.autoUpdateIglooFurniture(furniture)
|
|
197
|
+
client.updateIglooType(typeId)
|
|
198
|
+
await client.updateIglooMusic(musicId)
|
|
199
|
+
await client.buyFurniture(furnitureId, amount)
|
|
200
|
+
await client.buyMusic(musicId)
|
|
201
|
+
client.closeIglooEditor()
|
|
202
|
+
|
|
203
|
+
// CPJourney puffles
|
|
204
|
+
const { puffles } = await client.getAllPuffles()
|
|
205
|
+
await client.getPuffleWellbeing(puffleId)
|
|
206
|
+
client.playPuffle(puffleId)
|
|
207
|
+
client.restPuffle(puffleId)
|
|
208
|
+
await client.buyPuffleItem(puffleId, itemId)
|
|
209
|
+
await client.walkPuffle(puffleId)
|
|
210
|
+
client.initializePuffleTower() // CPJ sends tower_init after walking acknowledgement
|
|
211
|
+
|
|
168
212
|
// Animation
|
|
169
213
|
client.sendFrame(frameId)
|
|
170
214
|
|
|
@@ -179,6 +223,13 @@ client.disconnect()
|
|
|
179
223
|
|
|
180
224
|
All events are fully typed via `ServerMessages`.
|
|
181
225
|
|
|
226
|
+
`ServerMessages` remains the compatibility aggregate. CPJourney-specific wire
|
|
227
|
+
contracts are also exported separately as `CpjourneyClientMessages` and
|
|
228
|
+
`CpjourneyServerMessages`; unsupported methods throw or reject with a
|
|
229
|
+
non-retryable `ClientOperationError` whose category is
|
|
230
|
+
`unsupported_operation`. Shared actions should be normalized by each adapter
|
|
231
|
+
rather than assuming identical wire payloads.
|
|
232
|
+
|
|
182
233
|
```typescript
|
|
183
234
|
client.on("send_message", ({ id, message }) => {
|
|
184
235
|
const user = client.users.get(id)
|
|
@@ -233,8 +284,8 @@ client.on("stamps_result", ({ stamps, username }) => {
|
|
|
233
284
|
console.log(`${username} has ${stamps.length} stamps`)
|
|
234
285
|
})
|
|
235
286
|
|
|
236
|
-
client.on("disconnect", () => {
|
|
237
|
-
console.log("Connection lost")
|
|
287
|
+
client.on("disconnect", ({ intentional, reason }) => {
|
|
288
|
+
console.log(intentional ? "Connection closed" : "Connection lost", reason)
|
|
238
289
|
})
|
|
239
290
|
```
|
|
240
291
|
|
|
@@ -257,9 +308,13 @@ import type {
|
|
|
257
308
|
TokenLoginOptions,// username + token login
|
|
258
309
|
LoginResult, // login response (servers, key, username)
|
|
259
310
|
QueueUpdate, // queue position update
|
|
311
|
+
ClientOperationError,
|
|
312
|
+
ClientOperationOptions,
|
|
313
|
+
ClientLifecycleUpdate,
|
|
314
|
+
ClientDisconnectInfo,
|
|
260
315
|
ClientMessages, // all client -> server message types
|
|
261
316
|
ServerMessages, // all server -> client message types
|
|
262
|
-
} from "pickle.ts"
|
|
317
|
+
} from "@shaunlwm/pickle.ts"
|
|
263
318
|
```
|
|
264
319
|
|
|
265
320
|
## Custom Adapters
|
|
@@ -267,7 +322,7 @@ import type {
|
|
|
267
322
|
To support a different CPPS, extend `BaseAdapter`:
|
|
268
323
|
|
|
269
324
|
```typescript
|
|
270
|
-
import { BaseAdapter } from "pickle.ts"
|
|
325
|
+
import { BaseAdapter } from "@shaunlwm/pickle.ts"
|
|
271
326
|
|
|
272
327
|
export class MyServerAdapter extends BaseAdapter {
|
|
273
328
|
readonly id = "MyServer"
|