@ceki/sdk 1.9.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.
@@ -0,0 +1,420 @@
1
+ interface ConnectOptions {
2
+ apiUrl?: string;
3
+ relayUrl?: string;
4
+ chatUrl?: string;
5
+ basicAuth?: [string, string];
6
+ reconnect?: boolean;
7
+ }
8
+ interface BrowserOption {
9
+ schedule_id: number;
10
+ user_id?: number | null;
11
+ geo?: string | null;
12
+ language?: string | null;
13
+ languages?: string[];
14
+ domain_allowed?: string[] | null;
15
+ skills?: string[];
16
+ price_per_min: number;
17
+ rating?: number | null;
18
+ online: boolean;
19
+ currency?: string | null;
20
+ kal_id?: number | null;
21
+ profile_mode?: 'main' | 'incognito' | null;
22
+ allowed_domains?: string[] | null;
23
+ }
24
+ interface Match {
25
+ session_id: string;
26
+ schedule_id: number;
27
+ event_id?: string | null;
28
+ chat_topic_id?: string | null;
29
+ provider_user_id?: number | null;
30
+ started_at?: number;
31
+ browser_info?: Record<string, unknown>;
32
+ }
33
+ interface ChatMessage {
34
+ id: string;
35
+ topic_id: string;
36
+ sender_id?: number | null;
37
+ text?: string | null;
38
+ media?: Record<string, unknown>[] | null;
39
+ type: string;
40
+ created_at: string;
41
+ edited_at?: string | null;
42
+ deleted_at?: string | null;
43
+ action?: {
44
+ kind: string;
45
+ event_id: number;
46
+ data?: Record<string, unknown>;
47
+ } | null;
48
+ }
49
+ interface ReadReceipt {
50
+ topic_id: string;
51
+ last_read_message_id: string;
52
+ read_at: number;
53
+ }
54
+ interface Snapshot {
55
+ screenshot: string;
56
+ chat: ChatMessage[];
57
+ ts: Date;
58
+ }
59
+ interface Profile {
60
+ schema_version: number;
61
+ fingerprint?: Record<string, unknown> | null;
62
+ origin?: string;
63
+ cookies?: Record<string, unknown>[];
64
+ localStorage?: Record<string, string>;
65
+ sessionStorage?: Record<string, string>;
66
+ }
67
+ interface RentOptions {
68
+ human?: 'natural' | 'careful' | null;
69
+ maskingMode?: boolean;
70
+ fingerprint?: boolean | Record<string, unknown>;
71
+ mode?: 'incognito' | 'main';
72
+ }
73
+ interface ScreenshotOptions {
74
+ format?: 'base64' | 'png';
75
+ fullPage?: boolean;
76
+ }
77
+ interface ScrollOptions {
78
+ x?: number;
79
+ y?: number;
80
+ deltaX?: number;
81
+ deltaY?: number;
82
+ }
83
+ interface ProfileExportOptions {
84
+ domains?: string[];
85
+ includeSessionStorage?: boolean;
86
+ }
87
+ interface ChatHistoryOptions {
88
+ limit?: number;
89
+ beforeId?: string;
90
+ since?: string;
91
+ }
92
+ interface SessionInfo {
93
+ id: number;
94
+ schedule_id: number;
95
+ started_at: string | null;
96
+ ended_at: string | null;
97
+ status: string;
98
+ duration: number;
99
+ earned: number;
100
+ price_per_min: number;
101
+ renter: Record<string, unknown>;
102
+ provider: Record<string, unknown>;
103
+ data: Record<string, unknown>;
104
+ }
105
+ interface CaptchaOptions {
106
+ acceptanceTimeout?: number;
107
+ completionTimeout?: number;
108
+ autoAccept?: boolean;
109
+ }
110
+ interface CaptchaResult {
111
+ solved: boolean;
112
+ proofMessageId: string | null;
113
+ cancelReason: string | null;
114
+ childEventId: number;
115
+ correctionId: number | null;
116
+ acceptWork: () => Promise<void>;
117
+ rejectWork: (reason?: string) => Promise<void>;
118
+ }
119
+
120
+ type MessageHandler = (msg: ChatMessage) => void | Promise<void>;
121
+ type ReadHandler = (receipt: ReadReceipt) => void | Promise<void>;
122
+ declare class BrowserChat {
123
+ private _browser;
124
+ private _topicId;
125
+ private _messageHandlers;
126
+ private _readHandlers;
127
+ private _pendingSends;
128
+ /** @internal */ _actionCallbacks: Map<number, (action: Record<string, unknown>) => void>;
129
+ constructor(browser: Browser);
130
+ get topicId(): string | null;
131
+ send(text: string): Promise<{
132
+ messageId: string;
133
+ sentAt: string;
134
+ }>;
135
+ sendImage(source: string | Buffer, text?: string): Promise<{
136
+ messageId: string;
137
+ sentAt: string;
138
+ }>;
139
+ onMessage(cb: MessageHandler): void;
140
+ onRead(cb: ReadHandler): void;
141
+ history(opts?: ChatHistoryOptions): Promise<ChatMessage[]>;
142
+ /** @internal */
143
+ _onMessage(payload: Record<string, unknown>): void;
144
+ /** @internal */
145
+ _onRead(payload: Record<string, unknown>): void;
146
+ /** @internal */
147
+ _onSendAck(msg: Record<string, unknown>): void;
148
+ /** @internal */
149
+ _onSendError(msg: Record<string, unknown>): void;
150
+ }
151
+
152
+ declare class BrowserProfile {
153
+ private _browser;
154
+ constructor(browser: Browser);
155
+ export(opts?: ProfileExportOptions): Promise<Profile>;
156
+ import(profile: Profile): Promise<void>;
157
+ }
158
+
159
+ interface HumanProfileRaw {
160
+ version?: number;
161
+ name?: string;
162
+ typing?: {
163
+ wpm?: number;
164
+ jitter?: number;
165
+ thinking_pause_prob?: number;
166
+ thinking_pause_ms?: [number, number];
167
+ typo_prob?: number;
168
+ };
169
+ pre_action_ms?: Record<string, [number, number]>;
170
+ post_action_ms?: Record<string, [number, number]>;
171
+ mouse?: {
172
+ move_before_click?: boolean;
173
+ trajectory?: string;
174
+ };
175
+ rng_seed?: number | null;
176
+ }
177
+ declare class HumanProfile {
178
+ readonly name: string;
179
+ readonly raw: HumanProfileRaw;
180
+ constructor(name: string, raw: HumanProfileRaw);
181
+ static fromDict(d: Record<string, unknown>): HumanProfile;
182
+ static load(filePath: string): HumanProfile;
183
+ static loadPreset(name: string): HumanProfile;
184
+ getRange(action: string, phase: 'pre' | 'post'): [number, number];
185
+ typingInterval(): number;
186
+ toDict(): HumanProfileRaw;
187
+ toJSON(indent?: number): string;
188
+ }
189
+
190
+ declare class Humanizer {
191
+ readonly profile: HumanProfile;
192
+ private _rng;
193
+ constructor(profile: HumanProfile);
194
+ before(action: string): Promise<void>;
195
+ after(action: string): Promise<void>;
196
+ typeDelay(): number;
197
+ }
198
+
199
+ interface PendingCdp {
200
+ resolve: (value: unknown) => void;
201
+ reject: (err: Error) => void;
202
+ timer: ReturnType<typeof setTimeout>;
203
+ }
204
+ type EventHandler = (method: string, params: Record<string, unknown>) => void;
205
+ type TabHandler = (url: string) => void;
206
+ type VoidHandler = () => void;
207
+ type UserEventHandler = (events: Record<string, unknown>[]) => void;
208
+ declare class Browser {
209
+ readonly sessionId: string;
210
+ readonly browserId: number;
211
+ readonly scheduleId: number;
212
+ readonly chatTopicId: string | null;
213
+ readonly browserInfo: Record<string, unknown>;
214
+ readonly providerUserId: number | null;
215
+ /** @internal */ _eventId: string | null;
216
+ readonly chat: BrowserChat;
217
+ readonly profile: BrowserProfile;
218
+ /** @internal */ _client: Client;
219
+ /** @internal */ _humanizer: Humanizer | null;
220
+ /** @internal */ _lastPointer: [number, number] | null;
221
+ /** @internal */ _lastSeenTs: string | null;
222
+ /** @internal */ _cdpCounter: number;
223
+ /** @internal */ _pendingCdp: Map<number, PendingCdp>;
224
+ /** @internal */ _ended: Promise<string>;
225
+ /** @internal */ _endedReason: string | null;
226
+ /** @internal */ _resolveEnded: (reason: string) => void;
227
+ private _eventHandlers;
228
+ private _tabHandlers;
229
+ private _disconnectHandlers;
230
+ private _reconnectHandlers;
231
+ private _userEventHandlers;
232
+ /** @internal */
233
+ get _apiKey(): string;
234
+ /** @internal */
235
+ get _chatUrl(): string;
236
+ /** @internal */
237
+ get _basicAuth(): [string, string] | undefined;
238
+ constructor(client: Client, match: Match, humanizer?: Humanizer | null);
239
+ /** @internal — send raw message via client WS */
240
+ _sendRaw(msg: Record<string, unknown>): void;
241
+ send(cdp: {
242
+ method: string;
243
+ params?: Record<string, unknown>;
244
+ }, timeout?: number): Promise<unknown>;
245
+ navigate(url: string, timeout?: number): Promise<{
246
+ url: string;
247
+ frameId?: string;
248
+ }>;
249
+ click(x: number, y: number): Promise<void>;
250
+ private _sendKeystroke;
251
+ type(text: string): Promise<void>;
252
+ scroll(opts?: ScrollOptions): Promise<void>;
253
+ screenshot(opts?: ScreenshotOptions): Promise<{
254
+ data: string;
255
+ } | Buffer>;
256
+ snapshot(): Promise<Snapshot>;
257
+ upload(selector: string, source: string | Buffer, filename?: string): Promise<{
258
+ ok: boolean;
259
+ filename: string;
260
+ size: number;
261
+ }>;
262
+ switchTab(): Promise<void>;
263
+ configure(opts: {
264
+ maskingMode?: boolean;
265
+ fingerprint?: boolean | Record<string, unknown>;
266
+ }): Promise<void>;
267
+ close(timeout?: number): Promise<void>;
268
+ release(timeout?: number): Promise<void>;
269
+ waitUntilEnded(): Promise<string>;
270
+ onEvent(cb: EventHandler): void;
271
+ onTabOpened(cb: TabHandler): void;
272
+ onProviderDisconnected(cb: VoidHandler): void;
273
+ onProviderReconnected(cb: VoidHandler): void;
274
+ onUserEvent(cb: UserEventHandler): void;
275
+ private _apiHeaders;
276
+ requestCaptcha(opts?: CaptchaOptions): Promise<CaptchaResult>;
277
+ private _createCaptchaEvent;
278
+ private _expireCaptchaEvent;
279
+ /** @internal */
280
+ _onCdpResponse(msg: Record<string, unknown>): void;
281
+ /** @internal */
282
+ _onCdpEvent(msg: Record<string, unknown>): void;
283
+ /** @internal */
284
+ _onTabOpened(msg: Record<string, unknown>): void;
285
+ /** @internal */
286
+ _onSessionEnded(msg: Record<string, unknown>): void;
287
+ /** @internal */
288
+ _onProviderDisconnected(): void;
289
+ /** @internal */
290
+ _onProviderReconnected(): void;
291
+ /** @internal */
292
+ _onError(msg: Record<string, unknown>): void;
293
+ /** @internal */
294
+ _onUserEvents(msg: Record<string, unknown>): void;
295
+ /** @internal */
296
+ _onChatMessage(payload: Record<string, unknown>): void;
297
+ /** @internal */
298
+ _onChatRead(payload: Record<string, unknown>): void;
299
+ /** @internal */
300
+ _onChatSendAck(msg: Record<string, unknown>): void;
301
+ /** @internal */
302
+ _onChatSendError(msg: Record<string, unknown>): void;
303
+ private _rejectAllPending;
304
+ private _cleanup;
305
+ }
306
+
307
+ declare class Client {
308
+ /** @internal */ _apiKey: string;
309
+ /** @internal */ _chatUrl: string;
310
+ /** @internal */ _basicAuth: [string, string] | undefined;
311
+ /** @internal */ _activeBrowsers: Map<string, Browser>;
312
+ private _ws;
313
+ /** @internal */ _apiUrl: string;
314
+ private _relayUrl;
315
+ private _reconnect;
316
+ private _reconnectAttempt;
317
+ private _reconnecting;
318
+ private _closed;
319
+ private _pingTimer;
320
+ private _pongTimer;
321
+ private _lastPongAt;
322
+ private _pendingRents;
323
+ private _pendingResumes;
324
+ private _connectResolve;
325
+ private _connectReject;
326
+ constructor(apiKey: string, opts?: Partial<ConnectOptions>);
327
+ /** Factory: create client and connect */
328
+ static create(apiKey: string, opts?: Partial<ConnectOptions>): Promise<Client>;
329
+ /** @internal */
330
+ _wsSend(msg: Record<string, unknown>): void;
331
+ search(filters?: Record<string, unknown>, limit?: number): Promise<BrowserOption[]>;
332
+ listSessions(opts?: {
333
+ active?: boolean;
334
+ limit?: number;
335
+ }): Promise<SessionInfo[]>;
336
+ myBrowsers(): Promise<BrowserOption[]>;
337
+ rent(scheduleId: number, opts?: RentOptions): Promise<Browser>;
338
+ resume(sessionId: string, opts?: RentOptions): Promise<Browser>;
339
+ close(): Promise<void>;
340
+ disconnect(): Promise<void>;
341
+ private _connect;
342
+ private _openWs;
343
+ private _closeWs;
344
+ private _scheduleReconnect;
345
+ private _startHeartbeat;
346
+ private _stopHeartbeat;
347
+ private _checkPongTimeout;
348
+ private _handleMessage;
349
+ private _onRentPending;
350
+ private _onMatch;
351
+ private _onRentError;
352
+ private _onResumeOk;
353
+ private _onResumeFailed;
354
+ private _onError;
355
+ private _rejectFirstPendingRent;
356
+ private _rejectAllPending;
357
+ private _resolveHumanizer;
358
+ }
359
+ /** Factory function: create a connected Client */
360
+ declare function connect(apiKey: string, opts?: Partial<ConnectOptions>): Promise<Client>;
361
+
362
+ declare class CekiBrowserError extends Error {
363
+ constructor(message: string);
364
+ }
365
+ declare class AuthError extends CekiBrowserError {
366
+ constructor(message?: string);
367
+ }
368
+ declare class SessionNotFound extends CekiBrowserError {
369
+ constructor(message?: string);
370
+ }
371
+ declare class SessionExpired extends SessionNotFound {
372
+ constructor(message?: string);
373
+ }
374
+ declare class NotOwner extends CekiBrowserError {
375
+ constructor(message?: string);
376
+ }
377
+ declare class TransportError extends CekiBrowserError {
378
+ constructor(message?: string);
379
+ }
380
+ declare class TimeoutError extends CekiBrowserError {
381
+ constructor(message?: string);
382
+ }
383
+ declare class SessionEnded extends CekiBrowserError {
384
+ reason: string;
385
+ constructor(reason: string);
386
+ }
387
+ declare class InsufficientFunds extends CekiBrowserError {
388
+ constructor(message?: string);
389
+ }
390
+ declare class RateLimitExceeded extends CekiBrowserError {
391
+ retryAfter: number;
392
+ constructor(retryAfter?: number, message?: string);
393
+ }
394
+ declare class ConnectionLost extends CekiBrowserError {
395
+ constructor(message?: string);
396
+ }
397
+ declare class ProviderOffline extends CekiBrowserError {
398
+ constructor(message?: string);
399
+ }
400
+ declare class ProviderDisconnected extends CekiBrowserError {
401
+ constructor(message?: string);
402
+ }
403
+ declare class CdpUnrecoverable extends CekiBrowserError {
404
+ lastError: string;
405
+ constructor(lastError: string);
406
+ }
407
+ declare class CaptchaError extends CekiBrowserError {
408
+ constructor(message?: string);
409
+ }
410
+ declare class CaptchaTimeoutError extends CaptchaError {
411
+ phase: 'acceptance' | 'completion';
412
+ constructor(phase: 'acceptance' | 'completion');
413
+ }
414
+ declare class ChatSendFailed extends CekiBrowserError {
415
+ status: number;
416
+ messageText: string;
417
+ constructor(status: number, messageText: string);
418
+ }
419
+
420
+ export { AuthError, Browser, BrowserChat, type BrowserOption, BrowserProfile, CaptchaError, type CaptchaOptions, type CaptchaResult, CaptchaTimeoutError, CdpUnrecoverable, CekiBrowserError, type ChatHistoryOptions, type ChatMessage, ChatSendFailed, Client, type ConnectOptions, ConnectionLost, HumanProfile, Humanizer, InsufficientFunds, type Match, NotOwner, type Profile, type ProfileExportOptions, ProviderDisconnected, ProviderOffline, RateLimitExceeded, type ReadReceipt, type RentOptions, type ScreenshotOptions, type ScrollOptions, SessionEnded, SessionExpired, type SessionInfo, SessionNotFound, type Snapshot, TimeoutError, TransportError, connect };