wrc-ts 0.1.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,15 @@
1
+ import type { Transport, UnaryResponse, StreamResponse, ContextValues } from "@connectrpc/connect";
2
+ import type { DescMessage, DescMethodUnary, DescMethodStreaming, MessageInitShape } from "@bufbuild/protobuf";
3
+ export declare class WebSocketTransport implements Transport {
4
+ private ws;
5
+ private pending;
6
+ private queue;
7
+ private connected;
8
+ private url;
9
+ constructor(url: string);
10
+ private connect;
11
+ private send;
12
+ unary<I extends DescMessage, O extends DescMessage>(method: DescMethodUnary<I, O>, signal: AbortSignal | undefined, _timeoutMs: number | undefined, _header: HeadersInit | undefined, input: MessageInitShape<I>, _contextValues?: ContextValues): Promise<UnaryResponse<I, O>>;
13
+ stream<I extends DescMessage, O extends DescMessage>(_method: DescMethodStreaming<I, O>, _signal: AbortSignal | undefined, _timeoutMs: number | undefined, _header: HeadersInit | undefined, _input: AsyncIterable<MessageInitShape<I>>, _contextValues?: ContextValues): Promise<StreamResponse<I, O>>;
14
+ close(): void;
15
+ }
@@ -0,0 +1,99 @@
1
+ import { create, toBinary, fromBinary } from "@bufbuild/protobuf";
2
+ let nextId = 0;
3
+ export class WebSocketTransport {
4
+ constructor(url) {
5
+ this.ws = null;
6
+ this.pending = new Map();
7
+ this.queue = [];
8
+ this.connected = false;
9
+ this.url = url;
10
+ this.connect();
11
+ }
12
+ connect() {
13
+ this.ws = new WebSocket(this.url);
14
+ this.ws.binaryType = "arraybuffer";
15
+ this.ws.onopen = () => {
16
+ this.connected = true;
17
+ for (const msg of this.queue) {
18
+ this.ws.send(msg);
19
+ }
20
+ this.queue = [];
21
+ };
22
+ this.ws.onmessage = (ev) => {
23
+ const buf = new Uint8Array(ev.data);
24
+ if (buf.length < 5)
25
+ return;
26
+ const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
27
+ const id = view.getUint32(0, true);
28
+ const status = buf[4];
29
+ const payload = buf.slice(5);
30
+ const call = this.pending.get(id);
31
+ if (!call)
32
+ return;
33
+ this.pending.delete(id);
34
+ if (status === 0) {
35
+ call.resolve(payload);
36
+ }
37
+ else {
38
+ call.reject(new Error(new TextDecoder().decode(payload)));
39
+ }
40
+ };
41
+ this.ws.onclose = () => {
42
+ this.connected = false;
43
+ for (const [, call] of this.pending) {
44
+ call.reject(new Error("WebSocket closed"));
45
+ }
46
+ this.pending.clear();
47
+ setTimeout(() => this.connect(), 1000);
48
+ };
49
+ this.ws.onerror = () => {
50
+ this.ws?.close();
51
+ };
52
+ }
53
+ send(data) {
54
+ if (this.connected && this.ws?.readyState === WebSocket.OPEN) {
55
+ this.ws.send(data);
56
+ }
57
+ else {
58
+ this.queue.push(data);
59
+ }
60
+ }
61
+ async unary(method, signal, _timeoutMs, _header, input, _contextValues) {
62
+ const id = ++nextId;
63
+ const methodName = `${method.parent.typeName}/${method.name}`;
64
+ const inputMsg = create(method.input, input);
65
+ const payload = toBinary(method.input, inputMsg);
66
+ const methodBytes = new TextEncoder().encode(methodName);
67
+ const frame = new Uint8Array(6 + methodBytes.length + payload.length);
68
+ const view = new DataView(frame.buffer);
69
+ view.setUint32(0, id, true);
70
+ view.setUint16(4, methodBytes.length, true);
71
+ frame.set(methodBytes, 6);
72
+ frame.set(payload, 6 + methodBytes.length);
73
+ const responsePayload = await new Promise((resolve, reject) => {
74
+ this.pending.set(id, { resolve, reject });
75
+ this.send(frame);
76
+ if (signal) {
77
+ signal.addEventListener("abort", () => {
78
+ this.pending.delete(id);
79
+ reject(signal.reason ?? new Error("aborted"));
80
+ }, { once: true });
81
+ }
82
+ });
83
+ const output = fromBinary(method.output, responsePayload);
84
+ return {
85
+ stream: false,
86
+ service: method.parent,
87
+ method,
88
+ header: new Headers(),
89
+ trailer: new Headers(),
90
+ message: output,
91
+ };
92
+ }
93
+ async stream(_method, _signal, _timeoutMs, _header, _input, _contextValues) {
94
+ throw new Error("Streaming not supported over WebSocket transport");
95
+ }
96
+ close() {
97
+ this.ws?.close();
98
+ }
99
+ }
package/package.json ADDED
@@ -0,0 +1,80 @@
1
+ {
2
+ "name": "wrc-ts",
3
+ "version": "0.1.0",
4
+ "description": "Official SDK for WebRobot Cloud — undetected stealth browsers in the cloud. Rent real Chromium sessions with unique fingerprints, built-in proxies, captcha solving, human-like input and live video — scale web scraping and automation without running a single browser yourself.",
5
+ "main": "dist/index.js",
6
+ "type": "module",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js",
12
+ "default": "./dist/index.js"
13
+ },
14
+ "./browser": {
15
+ "types": "./dist/browser.d.ts",
16
+ "import": "./dist/wrc.browser.js",
17
+ "default": "./dist/wrc.browser.js"
18
+ }
19
+ },
20
+ "files": [
21
+ "dist",
22
+ "README.md",
23
+ "LICENSE"
24
+ ],
25
+ "scripts": {
26
+ "build:proto": "npx buf generate",
27
+ "build:node": "tsc -p tsconfig.json",
28
+ "build:browser": "npx esbuild src/browser.ts --bundle --format=esm --outfile=dist/wrc.browser.js",
29
+ "build": "npm run build:proto && npm run build:node && npm run build:browser",
30
+ "prepublishOnly": "npm run build"
31
+ },
32
+ "keywords": [
33
+ "puppeteer",
34
+ "playwright",
35
+ "stealth",
36
+ "undetected",
37
+ "undetected-browser",
38
+ "anti-detect",
39
+ "bot-detection",
40
+ "fingerprint",
41
+ "cloudflare",
42
+ "cloudflare-bypass",
43
+ "perimeterx",
44
+ "perimeterx-bypass",
45
+ "datadome",
46
+ "datadome-bypass",
47
+ "captcha",
48
+ "headless",
49
+ "chrome",
50
+ "chromium",
51
+ "cloud-browser",
52
+ "browser-use"
53
+ ],
54
+ "author": "webrobot-dev",
55
+ "license": "MIT",
56
+ "homepage": "https://webrobot.cloud/docs",
57
+ "repository": {
58
+ "type": "git",
59
+ "url": "git+https://github.com/webrobot-dev/wrc-ts.git"
60
+ },
61
+ "bugs": {
62
+ "url": "https://github.com/webrobot-dev/wrc-ts/issues"
63
+ },
64
+ "sideEffects": false,
65
+ "engines": {
66
+ "node": ">=18"
67
+ },
68
+ "dependencies": {
69
+ "@bufbuild/protobuf": "^2.11.0",
70
+ "@connectrpc/connect": "^2.1.1",
71
+ "@connectrpc/connect-node": "^2.1.1"
72
+ },
73
+ "devDependencies": {
74
+ "@bufbuild/buf": "^1.66.1",
75
+ "@bufbuild/protoc-gen-es": "^2.11.0",
76
+ "@types/node": "^22.0.0",
77
+ "esbuild": "^0.27.4",
78
+ "typescript": "^5.9.3"
79
+ }
80
+ }