@shaunlwm/pickle.ts 1.10.0 → 1.12.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 +68 -10
- package/dist/index.d.ts +550 -69
- 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, CPPS.lol, 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" \| "CPPSlol" \| "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,8 +80,12 @@ 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
|
-
// servers: ServerInfo[] = [{ name: string, population: number }]
|
|
87
|
+
// servers: ServerInfo[] = [{ name: string, population: number, users?: number }]
|
|
88
|
+
// CPPS.lol: population is browser bars; users is the exact penguin count.
|
|
85
89
|
```
|
|
86
90
|
|
|
87
91
|
Also supports token-based login:
|
|
@@ -110,6 +114,28 @@ await client.connect("Blizzard", {
|
|
|
110
114
|
|
|
111
115
|
After `connect()` resolves, `client.player`, `client.room`, and `client.users` are populated.
|
|
112
116
|
|
|
117
|
+
Connection progress can be observed without parsing log strings:
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
await client.connect("Blizzard", {
|
|
121
|
+
signal: abortController.signal,
|
|
122
|
+
timeouts: {
|
|
123
|
+
transportMs: 20_000,
|
|
124
|
+
queueMs: 300_000, // maximum silence between queue updates, not total queue time
|
|
125
|
+
authenticationMs: 20_000,
|
|
126
|
+
initialStateMs: 15_000,
|
|
127
|
+
},
|
|
128
|
+
onLifecycleUpdate: ({ phase, queue }) => {
|
|
129
|
+
console.log(phase, queue?.position)
|
|
130
|
+
},
|
|
131
|
+
})
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Login, connection, and request failures reject with `ClientOperationError`. Its
|
|
135
|
+
`category`, `phase`, and `retryable` fields are safe for supervisor decisions;
|
|
136
|
+
`unsupported_operation` is always non-retryable. Request methods accept
|
|
137
|
+
`{ timeoutMs, signal }`, defaulting to a 15-second response timeout.
|
|
138
|
+
|
|
113
139
|
### State
|
|
114
140
|
|
|
115
141
|
| Property | Type | Description |
|
|
@@ -165,6 +191,25 @@ client.getStamps(userId) // view stampbook
|
|
|
165
191
|
client.getIglooOpen(userId) // check if igloo is open
|
|
166
192
|
client.joinIgloo(userId) // enter igloo
|
|
167
193
|
|
|
194
|
+
// CPJourney igloo editor/store
|
|
195
|
+
client.openIglooEditor()
|
|
196
|
+
client.updateIglooFurniture(furniture)
|
|
197
|
+
client.autoUpdateIglooFurniture(furniture)
|
|
198
|
+
client.updateIglooType(typeId)
|
|
199
|
+
await client.updateIglooMusic(musicId)
|
|
200
|
+
await client.buyFurniture(furnitureId, amount)
|
|
201
|
+
await client.buyMusic(musicId)
|
|
202
|
+
client.closeIglooEditor()
|
|
203
|
+
|
|
204
|
+
// CPJourney puffles
|
|
205
|
+
const { puffles } = await client.getAllPuffles()
|
|
206
|
+
await client.getPuffleWellbeing(puffleId)
|
|
207
|
+
client.playPuffle(puffleId)
|
|
208
|
+
client.restPuffle(puffleId)
|
|
209
|
+
await client.buyPuffleItem(puffleId, itemId)
|
|
210
|
+
await client.walkPuffle(puffleId)
|
|
211
|
+
client.initializePuffleTower() // CPJ sends tower_init after walking acknowledgement
|
|
212
|
+
|
|
168
213
|
// Animation
|
|
169
214
|
client.sendFrame(frameId)
|
|
170
215
|
|
|
@@ -179,6 +224,15 @@ client.disconnect()
|
|
|
179
224
|
|
|
180
225
|
All events are fully typed via `ServerMessages`.
|
|
181
226
|
|
|
227
|
+
`ServerMessages` remains the compatibility aggregate. Server-specific wire
|
|
228
|
+
contracts are also exported separately as `CpjourneyClientMessages`,
|
|
229
|
+
`CpjourneyServerMessages`, `CppslolClientMessages`, and
|
|
230
|
+
`CppslolServerMessages`. CPPS.lol-only operations are available through
|
|
231
|
+
`client.cppslol`; unsupported methods throw or reject with a non-retryable
|
|
232
|
+
`ClientOperationError` whose category is `unsupported_operation`. Shared
|
|
233
|
+
actions should be normalized by each adapter rather than assuming identical
|
|
234
|
+
wire payloads.
|
|
235
|
+
|
|
182
236
|
```typescript
|
|
183
237
|
client.on("send_message", ({ id, message }) => {
|
|
184
238
|
const user = client.users.get(id)
|
|
@@ -233,8 +287,8 @@ client.on("stamps_result", ({ stamps, username }) => {
|
|
|
233
287
|
console.log(`${username} has ${stamps.length} stamps`)
|
|
234
288
|
})
|
|
235
289
|
|
|
236
|
-
client.on("disconnect", () => {
|
|
237
|
-
console.log("Connection lost")
|
|
290
|
+
client.on("disconnect", ({ intentional, reason }) => {
|
|
291
|
+
console.log(intentional ? "Connection closed" : "Connection lost", reason)
|
|
238
292
|
})
|
|
239
293
|
```
|
|
240
294
|
|
|
@@ -252,14 +306,18 @@ import type {
|
|
|
252
306
|
PlayerSettings, // game settings
|
|
253
307
|
Buddy, // buddy list entry
|
|
254
308
|
Mascot, // mascot data
|
|
255
|
-
ServerInfo, // server name + population
|
|
309
|
+
ServerInfo, // server name + population; CPPS.lol also includes users
|
|
256
310
|
LoginOptions, // username + password login
|
|
257
311
|
TokenLoginOptions,// username + token login
|
|
258
312
|
LoginResult, // login response (servers, key, username)
|
|
259
313
|
QueueUpdate, // queue position update
|
|
314
|
+
ClientOperationError,
|
|
315
|
+
ClientOperationOptions,
|
|
316
|
+
ClientLifecycleUpdate,
|
|
317
|
+
ClientDisconnectInfo,
|
|
260
318
|
ClientMessages, // all client -> server message types
|
|
261
319
|
ServerMessages, // all server -> client message types
|
|
262
|
-
} from "pickle.ts"
|
|
320
|
+
} from "@shaunlwm/pickle.ts"
|
|
263
321
|
```
|
|
264
322
|
|
|
265
323
|
## Custom Adapters
|
|
@@ -267,7 +325,7 @@ import type {
|
|
|
267
325
|
To support a different CPPS, extend `BaseAdapter`:
|
|
268
326
|
|
|
269
327
|
```typescript
|
|
270
|
-
import { BaseAdapter } from "pickle.ts"
|
|
328
|
+
import { BaseAdapter } from "@shaunlwm/pickle.ts"
|
|
271
329
|
|
|
272
330
|
export class MyServerAdapter extends BaseAdapter {
|
|
273
331
|
readonly id = "MyServer"
|