@shaunlwm/pickle.ts 1.9.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 +78 -8
- package/dist/index.d.ts +476 -89
- 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,8 +44,9 @@ 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
|
+
| `options.connectionProfile` | `"chrome" \| "node" \| ConnectionProfile` | Controls HTTP/WebSocket headers. Defaults to browser-like Chrome headers; use `"node"` to preserve Node defaults |
|
|
49
50
|
|
|
50
51
|
```typescript
|
|
51
52
|
// default console.log
|
|
@@ -55,9 +56,23 @@ const client = new Client("CPJourney", { debug: true })
|
|
|
55
56
|
const client = new Client("CPJourney", {
|
|
56
57
|
debug: (msg, ...args) => myLogger.info(msg, ...args)
|
|
57
58
|
})
|
|
59
|
+
|
|
60
|
+
// opt out of browser-like headers
|
|
61
|
+
const nodeClient = new Client("CPJourney", {
|
|
62
|
+
connectionProfile: "node"
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
// override browser profile fields
|
|
66
|
+
const profiledClient = new Client("CPJourney", {
|
|
67
|
+
connectionProfile: {
|
|
68
|
+
userAgent: "Mozilla/5.0 ...",
|
|
69
|
+
origin: "https://play.cpjourney.net",
|
|
70
|
+
referer: "https://play.cpjourney.net/"
|
|
71
|
+
}
|
|
72
|
+
})
|
|
58
73
|
```
|
|
59
74
|
|
|
60
|
-
### `client.login(options)`
|
|
75
|
+
### `client.login(options, operationOptions?)`
|
|
61
76
|
|
|
62
77
|
Authenticates and returns the server list with populations.
|
|
63
78
|
|
|
@@ -65,6 +80,9 @@ Authenticates and returns the server list with populations.
|
|
|
65
80
|
const servers = await client.login({
|
|
66
81
|
username: "user",
|
|
67
82
|
password: "pass",
|
|
83
|
+
}, {
|
|
84
|
+
timeoutMs: 20_000,
|
|
85
|
+
signal: abortController.signal,
|
|
68
86
|
})
|
|
69
87
|
// servers: ServerInfo[] = [{ name: string, population: number }]
|
|
70
88
|
```
|
|
@@ -95,6 +113,28 @@ await client.connect("Blizzard", {
|
|
|
95
113
|
|
|
96
114
|
After `connect()` resolves, `client.player`, `client.room`, and `client.users` are populated.
|
|
97
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
|
+
|
|
98
138
|
### State
|
|
99
139
|
|
|
100
140
|
| Property | Type | Description |
|
|
@@ -150,6 +190,25 @@ client.getStamps(userId) // view stampbook
|
|
|
150
190
|
client.getIglooOpen(userId) // check if igloo is open
|
|
151
191
|
client.joinIgloo(userId) // enter igloo
|
|
152
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
|
+
|
|
153
212
|
// Animation
|
|
154
213
|
client.sendFrame(frameId)
|
|
155
214
|
|
|
@@ -164,6 +223,13 @@ client.disconnect()
|
|
|
164
223
|
|
|
165
224
|
All events are fully typed via `ServerMessages`.
|
|
166
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
|
+
|
|
167
233
|
```typescript
|
|
168
234
|
client.on("send_message", ({ id, message }) => {
|
|
169
235
|
const user = client.users.get(id)
|
|
@@ -218,8 +284,8 @@ client.on("stamps_result", ({ stamps, username }) => {
|
|
|
218
284
|
console.log(`${username} has ${stamps.length} stamps`)
|
|
219
285
|
})
|
|
220
286
|
|
|
221
|
-
client.on("disconnect", () => {
|
|
222
|
-
console.log("Connection lost")
|
|
287
|
+
client.on("disconnect", ({ intentional, reason }) => {
|
|
288
|
+
console.log(intentional ? "Connection closed" : "Connection lost", reason)
|
|
223
289
|
})
|
|
224
290
|
```
|
|
225
291
|
|
|
@@ -242,9 +308,13 @@ import type {
|
|
|
242
308
|
TokenLoginOptions,// username + token login
|
|
243
309
|
LoginResult, // login response (servers, key, username)
|
|
244
310
|
QueueUpdate, // queue position update
|
|
311
|
+
ClientOperationError,
|
|
312
|
+
ClientOperationOptions,
|
|
313
|
+
ClientLifecycleUpdate,
|
|
314
|
+
ClientDisconnectInfo,
|
|
245
315
|
ClientMessages, // all client -> server message types
|
|
246
316
|
ServerMessages, // all server -> client message types
|
|
247
|
-
} from "pickle.ts"
|
|
317
|
+
} from "@shaunlwm/pickle.ts"
|
|
248
318
|
```
|
|
249
319
|
|
|
250
320
|
## Custom Adapters
|
|
@@ -252,7 +322,7 @@ import type {
|
|
|
252
322
|
To support a different CPPS, extend `BaseAdapter`:
|
|
253
323
|
|
|
254
324
|
```typescript
|
|
255
|
-
import { BaseAdapter } from "pickle.ts"
|
|
325
|
+
import { BaseAdapter } from "@shaunlwm/pickle.ts"
|
|
256
326
|
|
|
257
327
|
export class MyServerAdapter extends BaseAdapter {
|
|
258
328
|
readonly id = "MyServer"
|