nothing-browser 0.0.4 → 0.0.6
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 +462 -3
- package/dist/cache/memory.js +35 -0
- package/dist/client/index.js +1054 -0
- package/dist/human/index.js +58 -0
- package/dist/launch/detect.js +769 -0
- package/dist/launch/spawn.js +902 -0
- package/dist/logger/index.js +733 -0
- package/dist/piggy.js +21602 -0
- package/dist/register/index.js +17020 -0
- package/dist/server/index.js +20658 -0
- package/nothing_browser_pig_pink.svg +59 -0
- package/package.json +53 -42
- package/piggy/client/index.ts +6 -5
- package/piggy/launch/spawn.ts +104 -38
|
@@ -0,0 +1,1054 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
function __accessProp(key) {
|
|
8
|
+
return this[key];
|
|
9
|
+
}
|
|
10
|
+
var __toESMCache_node;
|
|
11
|
+
var __toESMCache_esm;
|
|
12
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
13
|
+
var canCache = mod != null && typeof mod === "object";
|
|
14
|
+
if (canCache) {
|
|
15
|
+
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
|
|
16
|
+
var cached = cache.get(mod);
|
|
17
|
+
if (cached)
|
|
18
|
+
return cached;
|
|
19
|
+
}
|
|
20
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
21
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
22
|
+
for (let key of __getOwnPropNames(mod))
|
|
23
|
+
if (!__hasOwnProp.call(to, key))
|
|
24
|
+
__defProp(to, key, {
|
|
25
|
+
get: __accessProp.bind(mod, key),
|
|
26
|
+
enumerable: true
|
|
27
|
+
});
|
|
28
|
+
if (canCache)
|
|
29
|
+
cache.set(mod, to);
|
|
30
|
+
return to;
|
|
31
|
+
};
|
|
32
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
33
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
34
|
+
|
|
35
|
+
// node_modules/ernest-logger/colors/colors.js
|
|
36
|
+
var require_colors = __commonJS((exports, module) => {
|
|
37
|
+
var colors = {
|
|
38
|
+
black: "\x1B[30m",
|
|
39
|
+
red: "\x1B[31m",
|
|
40
|
+
green: "\x1B[32m",
|
|
41
|
+
yellow: "\x1B[33m",
|
|
42
|
+
blue: "\x1B[34m",
|
|
43
|
+
magenta: "\x1B[35m",
|
|
44
|
+
cyan: "\x1B[36m",
|
|
45
|
+
white: "\x1B[37m",
|
|
46
|
+
brightBlack: "\x1B[90m",
|
|
47
|
+
brightRed: "\x1B[91m",
|
|
48
|
+
brightGreen: "\x1B[92m",
|
|
49
|
+
brightYellow: "\x1B[93m",
|
|
50
|
+
brightBlue: "\x1B[94m",
|
|
51
|
+
brightMagenta: "\x1B[95m",
|
|
52
|
+
brightCyan: "\x1B[96m",
|
|
53
|
+
brightWhite: "\x1B[97m",
|
|
54
|
+
bgBlack: "\x1B[40m",
|
|
55
|
+
bgRed: "\x1B[41m",
|
|
56
|
+
bgGreen: "\x1B[42m",
|
|
57
|
+
bgYellow: "\x1B[43m",
|
|
58
|
+
bgBlue: "\x1B[44m",
|
|
59
|
+
bgMagenta: "\x1B[45m",
|
|
60
|
+
bgCyan: "\x1B[46m",
|
|
61
|
+
bgWhite: "\x1B[47m",
|
|
62
|
+
bgBrightBlack: "\x1B[100m",
|
|
63
|
+
bgBrightRed: "\x1B[101m",
|
|
64
|
+
bgBrightGreen: "\x1B[102m",
|
|
65
|
+
bgBrightYellow: "\x1B[103m",
|
|
66
|
+
bgBrightBlue: "\x1B[104m",
|
|
67
|
+
bgBrightMagenta: "\x1B[105m",
|
|
68
|
+
bgBrightCyan: "\x1B[106m",
|
|
69
|
+
bgBrightWhite: "\x1B[107m",
|
|
70
|
+
reset: "\x1B[0m",
|
|
71
|
+
bold: "\x1B[1m",
|
|
72
|
+
dim: "\x1B[2m",
|
|
73
|
+
italic: "\x1B[3m",
|
|
74
|
+
underline: "\x1B[4m",
|
|
75
|
+
blink: "\x1B[5m",
|
|
76
|
+
reverse: "\x1B[7m",
|
|
77
|
+
hidden: "\x1B[8m",
|
|
78
|
+
strikethrough: "\x1B[9m",
|
|
79
|
+
success: "\x1B[32m",
|
|
80
|
+
error: "\x1B[31m",
|
|
81
|
+
warning: "\x1B[33m",
|
|
82
|
+
info: "\x1B[34m",
|
|
83
|
+
debug: "\x1B[36m",
|
|
84
|
+
primary: "\x1B[94m",
|
|
85
|
+
secondary: "\x1B[90m",
|
|
86
|
+
danger: "\x1B[91m",
|
|
87
|
+
muted: "\x1B[2m"
|
|
88
|
+
};
|
|
89
|
+
colors.combine = (...codes) => {
|
|
90
|
+
return codes.map((code) => colors[code] || "").join("");
|
|
91
|
+
};
|
|
92
|
+
colors.wrap = (text, color) => {
|
|
93
|
+
return (colors[color] || "") + text + colors.reset;
|
|
94
|
+
};
|
|
95
|
+
colors.gradient = (text, colorSequence = ["cyan", "blue", "magenta"]) => {
|
|
96
|
+
const chars = text.split("");
|
|
97
|
+
const colorCount = colorSequence.length;
|
|
98
|
+
return chars.map((char, i) => {
|
|
99
|
+
const colorName = colorSequence[i % colorCount];
|
|
100
|
+
return colors[colorName] + char;
|
|
101
|
+
}).join("") + colors.reset;
|
|
102
|
+
};
|
|
103
|
+
colors.rainbow = (text) => {
|
|
104
|
+
const rainbowColors = ["red", "yellow", "green", "cyan", "blue", "magenta"];
|
|
105
|
+
return colors.gradient(text, rainbowColors);
|
|
106
|
+
};
|
|
107
|
+
module.exports = colors;
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
// node_modules/ernest-logger/emojis/emojis.js
|
|
111
|
+
var require_emojis = __commonJS((exports, module) => {
|
|
112
|
+
var emojis = {
|
|
113
|
+
trace: "\uD83D\uDD0D",
|
|
114
|
+
debug: "\uD83D\uDC1E",
|
|
115
|
+
info: "ℹ️",
|
|
116
|
+
success: "✅",
|
|
117
|
+
warn: "⚠️",
|
|
118
|
+
error: "❌",
|
|
119
|
+
fatal: "\uD83D\uDC80",
|
|
120
|
+
start: "▶️",
|
|
121
|
+
stop: "⏹️",
|
|
122
|
+
pause: "⏸️",
|
|
123
|
+
resume: "⏯️",
|
|
124
|
+
restart: "\uD83D\uDD04",
|
|
125
|
+
shutdown: "\uD83D\uDED1",
|
|
126
|
+
boot: "\uD83D\uDE80",
|
|
127
|
+
network: "\uD83C\uDF10",
|
|
128
|
+
api: "\uD83D\uDD0C",
|
|
129
|
+
request: "\uD83D\uDCE4",
|
|
130
|
+
response: "\uD83D\uDCE5",
|
|
131
|
+
webhook: "\uD83E\uDE9D",
|
|
132
|
+
socket: "\uD83D\uDD17",
|
|
133
|
+
upload: "⬆️",
|
|
134
|
+
download: "⬇️",
|
|
135
|
+
sync: "\uD83D\uDD04",
|
|
136
|
+
db: "\uD83D\uDCBE",
|
|
137
|
+
database: "\uD83D\uDDC4️",
|
|
138
|
+
cache: "\uD83D\uDCA8",
|
|
139
|
+
storage: "\uD83D\uDCE6",
|
|
140
|
+
backup: "\uD83D\uDCBF",
|
|
141
|
+
restore: "♻️",
|
|
142
|
+
query: "\uD83D\uDD0E",
|
|
143
|
+
migration: "\uD83D\uDD00",
|
|
144
|
+
security: "\uD83D\uDD12",
|
|
145
|
+
unlock: "\uD83D\uDD13",
|
|
146
|
+
auth: "\uD83D\uDD10",
|
|
147
|
+
key: "\uD83D\uDD11",
|
|
148
|
+
token: "\uD83C\uDFAB",
|
|
149
|
+
encrypt: "\uD83D\uDEE1️",
|
|
150
|
+
decrypt: "\uD83D\uDD13",
|
|
151
|
+
firewall: "\uD83E\uDDF1",
|
|
152
|
+
scan: "\uD83D\uDD2C",
|
|
153
|
+
file: "\uD83D\uDCC4",
|
|
154
|
+
folder: "\uD83D\uDCC1",
|
|
155
|
+
document: "\uD83D\uDCC3",
|
|
156
|
+
archive: "\uD83D\uDDDC️",
|
|
157
|
+
zip: "\uD83E\uDD10",
|
|
158
|
+
pdf: "\uD83D\uDCD5",
|
|
159
|
+
csv: "\uD83D\uDCCA",
|
|
160
|
+
json: "\uD83D\uDCCB",
|
|
161
|
+
xml: "\uD83D\uDCF0",
|
|
162
|
+
config: "⚙️",
|
|
163
|
+
cloud: "☁️",
|
|
164
|
+
server: "\uD83D\uDDA5️",
|
|
165
|
+
deploy: "\uD83D\uDE80",
|
|
166
|
+
build: "\uD83D\uDD28",
|
|
167
|
+
compile: "⚒️",
|
|
168
|
+
package: "\uD83D\uDCE6",
|
|
169
|
+
publish: "\uD83D\uDCE2",
|
|
170
|
+
release: "\uD83C\uDF89",
|
|
171
|
+
rollback: "⏮️",
|
|
172
|
+
test: "\uD83E\uDDEA",
|
|
173
|
+
unittest: "\uD83D\uDD2C",
|
|
174
|
+
integration: "\uD83D\uDD17",
|
|
175
|
+
coverage: "\uD83D\uDCCA",
|
|
176
|
+
benchmark: "⏱️",
|
|
177
|
+
performance: "⚡",
|
|
178
|
+
profiling: "\uD83D\uDCC8",
|
|
179
|
+
bugFix: "\uD83D\uDC1B",
|
|
180
|
+
feature: "✨",
|
|
181
|
+
refactor: "♻️",
|
|
182
|
+
cleanup: "\uD83E\uDDF9",
|
|
183
|
+
user: "\uD83D\uDC64",
|
|
184
|
+
users: "\uD83D\uDC65",
|
|
185
|
+
admin: "\uD83D\uDC51",
|
|
186
|
+
robot: "\uD83E\uDD16",
|
|
187
|
+
human: "\uD83D\uDC68\uD83D\uDC69\uD83D\uDC67\uD83D\uDC66",
|
|
188
|
+
team: "\uD83D\uDC68\uD83D\uDC69\uD83D\uDC67\uD83D\uDC66",
|
|
189
|
+
chat: "\uD83D\uDCAC",
|
|
190
|
+
message: "✉️",
|
|
191
|
+
notification: "\uD83D\uDD14",
|
|
192
|
+
alert: "\uD83D\uDEA8",
|
|
193
|
+
money: "\uD83D\uDCB0",
|
|
194
|
+
payment: "\uD83D\uDCB3",
|
|
195
|
+
invoice: "\uD83E\uDDFE",
|
|
196
|
+
chart: "\uD83D\uDCCA",
|
|
197
|
+
analytics: "\uD83D\uDCC8",
|
|
198
|
+
metrics: "\uD83D\uDCC9",
|
|
199
|
+
dashboard: "\uD83C\uDF9B️",
|
|
200
|
+
report: "\uD83D\uDCC4",
|
|
201
|
+
online: "\uD83D\uDFE2",
|
|
202
|
+
offline: "\uD83D\uDD34",
|
|
203
|
+
pending: "\uD83D\uDFE1",
|
|
204
|
+
processing: "⏳",
|
|
205
|
+
loading: "⌛",
|
|
206
|
+
complete: "✔️",
|
|
207
|
+
incomplete: "❌",
|
|
208
|
+
progress: "\uD83D\uDCCA",
|
|
209
|
+
idea: "\uD83D\uDCA1",
|
|
210
|
+
lightning: "⚡",
|
|
211
|
+
fire: "\uD83D\uDD25",
|
|
212
|
+
star: "⭐",
|
|
213
|
+
trophy: "\uD83C\uDFC6",
|
|
214
|
+
medal: "\uD83C\uDFC5",
|
|
215
|
+
gift: "\uD83C\uDF81",
|
|
216
|
+
celebrate: "\uD83C\uDF89",
|
|
217
|
+
party: "\uD83C\uDF8A",
|
|
218
|
+
rocket: "\uD83D\uDE80",
|
|
219
|
+
ship: "\uD83D\uDEA2",
|
|
220
|
+
airplane: "✈️",
|
|
221
|
+
train: "\uD83D\uDE86",
|
|
222
|
+
calendar: "\uD83D\uDCC5",
|
|
223
|
+
clock: "\uD83D\uDD50",
|
|
224
|
+
timer: "⏲️",
|
|
225
|
+
bell: "\uD83D\uDD14",
|
|
226
|
+
flag: "\uD83D\uDEA9",
|
|
227
|
+
bookmark: "\uD83D\uDD16",
|
|
228
|
+
tag: "\uD83C\uDFF7️",
|
|
229
|
+
pin: "\uD83D\uDCCC",
|
|
230
|
+
magnet: "\uD83E\uDDF2",
|
|
231
|
+
crystal: "\uD83D\uDD2E",
|
|
232
|
+
gem: "\uD83D\uDC8E",
|
|
233
|
+
target: "\uD83C\uDFAF",
|
|
234
|
+
dart: "\uD83C\uDFAF",
|
|
235
|
+
compass: "\uD83E\uDDED",
|
|
236
|
+
map: "\uD83D\uDDFA️",
|
|
237
|
+
globe: "\uD83C\uDF0D",
|
|
238
|
+
satellite: "\uD83D\uDEF0️",
|
|
239
|
+
telescope: "\uD83D\uDD2D",
|
|
240
|
+
microscope: "\uD83D\uDD2C",
|
|
241
|
+
magGlass: "\uD83D\uDD0D",
|
|
242
|
+
wrench: "\uD83D\uDD27",
|
|
243
|
+
hammer: "\uD83D\uDD28",
|
|
244
|
+
screwdriver: "\uD83E\uDE9B",
|
|
245
|
+
gear: "⚙️",
|
|
246
|
+
nut: "\uD83D\uDD29",
|
|
247
|
+
link: "\uD83D\uDD17",
|
|
248
|
+
chain: "⛓️",
|
|
249
|
+
bridge: "\uD83C\uDF09",
|
|
250
|
+
door: "\uD83D\uDEAA",
|
|
251
|
+
window: "\uD83E\uDE9F",
|
|
252
|
+
shield: "\uD83D\uDEE1️",
|
|
253
|
+
sword: "⚔️",
|
|
254
|
+
bomb: "\uD83D\uDCA3",
|
|
255
|
+
explosion: "\uD83D\uDCA5",
|
|
256
|
+
spark: "✨",
|
|
257
|
+
dizzy: "\uD83D\uDCAB",
|
|
258
|
+
wave: "\uD83C\uDF0A",
|
|
259
|
+
droplet: "\uD83D\uDCA7",
|
|
260
|
+
snowflake: "❄️",
|
|
261
|
+
sun: "☀️",
|
|
262
|
+
moon: "\uD83C\uDF19",
|
|
263
|
+
rainbow: "\uD83C\uDF08",
|
|
264
|
+
seedling: "\uD83C\uDF31",
|
|
265
|
+
tree: "\uD83C\uDF32",
|
|
266
|
+
leaf: "\uD83C\uDF43",
|
|
267
|
+
recycle: "♻️"
|
|
268
|
+
};
|
|
269
|
+
emojis.get = (name, fallback = "") => {
|
|
270
|
+
return emojis[name] || fallback;
|
|
271
|
+
};
|
|
272
|
+
emojis.has = (name) => {
|
|
273
|
+
return emojis.hasOwnProperty(name);
|
|
274
|
+
};
|
|
275
|
+
emojis.list = () => {
|
|
276
|
+
return Object.keys(emojis).filter((key) => typeof emojis[key] === "string" && !["get", "has", "list"].includes(key));
|
|
277
|
+
};
|
|
278
|
+
module.exports = emojis;
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
// node_modules/ernest-logger/utils/timestamp.js
|
|
282
|
+
var require_timestamp = __commonJS((exports, module) => {
|
|
283
|
+
var getTimestamp = () => {
|
|
284
|
+
const date = new Date;
|
|
285
|
+
const hours = String(date.getHours()).padStart(2, "0");
|
|
286
|
+
const minutes = String(date.getMinutes()).padStart(2, "0");
|
|
287
|
+
const seconds = String(date.getSeconds()).padStart(2, "0");
|
|
288
|
+
return `${hours}:${minutes}:${seconds}`;
|
|
289
|
+
};
|
|
290
|
+
var getTimestampWithMs = () => {
|
|
291
|
+
const date = new Date;
|
|
292
|
+
const hours = String(date.getHours()).padStart(2, "0");
|
|
293
|
+
const minutes = String(date.getMinutes()).padStart(2, "0");
|
|
294
|
+
const seconds = String(date.getSeconds()).padStart(2, "0");
|
|
295
|
+
const ms = String(date.getMilliseconds()).padStart(3, "0");
|
|
296
|
+
return `${hours}:${minutes}:${seconds}.${ms}`;
|
|
297
|
+
};
|
|
298
|
+
var getFullTimestamp = () => {
|
|
299
|
+
const date = new Date;
|
|
300
|
+
const year = date.getFullYear();
|
|
301
|
+
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
302
|
+
const day = String(date.getDate()).padStart(2, "0");
|
|
303
|
+
const hours = String(date.getHours()).padStart(2, "0");
|
|
304
|
+
const minutes = String(date.getMinutes()).padStart(2, "0");
|
|
305
|
+
const seconds = String(date.getSeconds()).padStart(2, "0");
|
|
306
|
+
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
|
307
|
+
};
|
|
308
|
+
var getISOTimestamp = () => {
|
|
309
|
+
return new Date().toISOString();
|
|
310
|
+
};
|
|
311
|
+
var getUnixTimestamp = () => {
|
|
312
|
+
return Math.floor(Date.now() / 1000);
|
|
313
|
+
};
|
|
314
|
+
var getRelativeTime = (date) => {
|
|
315
|
+
const now = Date.now();
|
|
316
|
+
const timestamp = date instanceof Date ? date.getTime() : date;
|
|
317
|
+
const diff = now - timestamp;
|
|
318
|
+
const seconds = Math.floor(diff / 1000);
|
|
319
|
+
const minutes = Math.floor(seconds / 60);
|
|
320
|
+
const hours = Math.floor(minutes / 60);
|
|
321
|
+
const days = Math.floor(hours / 24);
|
|
322
|
+
if (seconds < 60)
|
|
323
|
+
return `${seconds} second${seconds !== 1 ? "s" : ""} ago`;
|
|
324
|
+
if (minutes < 60)
|
|
325
|
+
return `${minutes} minute${minutes !== 1 ? "s" : ""} ago`;
|
|
326
|
+
if (hours < 24)
|
|
327
|
+
return `${hours} hour${hours !== 1 ? "s" : ""} ago`;
|
|
328
|
+
return `${days} day${days !== 1 ? "s" : ""} ago`;
|
|
329
|
+
};
|
|
330
|
+
var formatCustom = (format, date = new Date) => {
|
|
331
|
+
const tokens = {
|
|
332
|
+
YYYY: date.getFullYear(),
|
|
333
|
+
MM: String(date.getMonth() + 1).padStart(2, "0"),
|
|
334
|
+
DD: String(date.getDate()).padStart(2, "0"),
|
|
335
|
+
HH: String(date.getHours()).padStart(2, "0"),
|
|
336
|
+
mm: String(date.getMinutes()).padStart(2, "0"),
|
|
337
|
+
ss: String(date.getSeconds()).padStart(2, "0"),
|
|
338
|
+
SSS: String(date.getMilliseconds()).padStart(3, "0")
|
|
339
|
+
};
|
|
340
|
+
let result = format;
|
|
341
|
+
Object.entries(tokens).forEach(([token, value]) => {
|
|
342
|
+
result = result.replace(token, value);
|
|
343
|
+
});
|
|
344
|
+
return result;
|
|
345
|
+
};
|
|
346
|
+
module.exports = getTimestamp;
|
|
347
|
+
module.exports.getTimestamp = getTimestamp;
|
|
348
|
+
module.exports.getTimestampWithMs = getTimestampWithMs;
|
|
349
|
+
module.exports.getFullTimestamp = getFullTimestamp;
|
|
350
|
+
module.exports.getISOTimestamp = getISOTimestamp;
|
|
351
|
+
module.exports.getUnixTimestamp = getUnixTimestamp;
|
|
352
|
+
module.exports.getRelativeTime = getRelativeTime;
|
|
353
|
+
module.exports.formatCustom = formatCustom;
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
// node_modules/ernest-logger/utils/formatter.js
|
|
357
|
+
var require_formatter = __commonJS((exports, module) => {
|
|
358
|
+
var colors = require_colors();
|
|
359
|
+
var createBadge = (text, color) => {
|
|
360
|
+
const bg = "bg" + color.charAt(0).toUpperCase() + color.slice(1);
|
|
361
|
+
const bgColor = colors[bg] || colors.bgBlue;
|
|
362
|
+
const textColor = colors.white + colors.bold;
|
|
363
|
+
return bgColor + textColor + ` ${text} ` + colors.reset;
|
|
364
|
+
};
|
|
365
|
+
var createBox = (message, color, emoji = "") => {
|
|
366
|
+
const lines = message.split(`
|
|
367
|
+
`);
|
|
368
|
+
const maxLength = Math.max(...lines.map((line) => stripAnsi(line).length));
|
|
369
|
+
const topLeft = "╔";
|
|
370
|
+
const topRight = "╗";
|
|
371
|
+
const bottomLeft = "╚";
|
|
372
|
+
const bottomRight = "╝";
|
|
373
|
+
const horizontal = "═";
|
|
374
|
+
const vertical = "║";
|
|
375
|
+
const colorCode = colors[color] || colors.blue;
|
|
376
|
+
const horizontalLine = horizontal.repeat(maxLength + 4);
|
|
377
|
+
let box = colorCode + topLeft + horizontalLine + topRight + colors.reset + `
|
|
378
|
+
`;
|
|
379
|
+
if (emoji) {
|
|
380
|
+
const emojiPadding = " ".repeat(maxLength + 2 - emoji.length);
|
|
381
|
+
box += colorCode + vertical + colors.reset + ` ${emoji}${emojiPadding} ` + colorCode + vertical + colors.reset + `
|
|
382
|
+
`;
|
|
383
|
+
box += colorCode + vertical + horizontal.repeat(maxLength + 4) + vertical + colors.reset + `
|
|
384
|
+
`;
|
|
385
|
+
}
|
|
386
|
+
lines.forEach((line) => {
|
|
387
|
+
const stripped = stripAnsi(line);
|
|
388
|
+
const padding = " ".repeat(maxLength - stripped.length);
|
|
389
|
+
box += colorCode + vertical + colors.reset + ` ${line}${padding} ` + colorCode + vertical + colors.reset + `
|
|
390
|
+
`;
|
|
391
|
+
});
|
|
392
|
+
box += colorCode + bottomLeft + horizontalLine + bottomRight + colors.reset;
|
|
393
|
+
return box;
|
|
394
|
+
};
|
|
395
|
+
var createBanner = (text, char = "=") => {
|
|
396
|
+
const length = stripAnsi(text).length;
|
|
397
|
+
const line = char.repeat(length + 4);
|
|
398
|
+
return `${line}
|
|
399
|
+
${text}
|
|
400
|
+
${line}`;
|
|
401
|
+
};
|
|
402
|
+
var stripAnsi = (text) => {
|
|
403
|
+
return text.replace(/\x1b\[[0-9;]*m/g, "");
|
|
404
|
+
};
|
|
405
|
+
var truncate = (text, maxLength) => {
|
|
406
|
+
if (text.length <= maxLength)
|
|
407
|
+
return text;
|
|
408
|
+
return text.substring(0, maxLength - 3) + "...";
|
|
409
|
+
};
|
|
410
|
+
var center = (text, width) => {
|
|
411
|
+
const stripped = stripAnsi(text);
|
|
412
|
+
const padding = Math.max(0, width - stripped.length);
|
|
413
|
+
const leftPad = Math.floor(padding / 2);
|
|
414
|
+
const rightPad = padding - leftPad;
|
|
415
|
+
return " ".repeat(leftPad) + text + " ".repeat(rightPad);
|
|
416
|
+
};
|
|
417
|
+
var padRight = (text, width) => {
|
|
418
|
+
const stripped = stripAnsi(text);
|
|
419
|
+
const padding = Math.max(0, width - stripped.length);
|
|
420
|
+
return text + " ".repeat(padding);
|
|
421
|
+
};
|
|
422
|
+
var padLeft = (text, width) => {
|
|
423
|
+
const stripped = stripAnsi(text);
|
|
424
|
+
const padding = Math.max(0, width - stripped.length);
|
|
425
|
+
return " ".repeat(padding) + text;
|
|
426
|
+
};
|
|
427
|
+
var createProgressBar = (current, total, width = 20) => {
|
|
428
|
+
const percentage = Math.min(100, Math.max(0, current / total * 100));
|
|
429
|
+
const filled = Math.round(percentage / 100 * width);
|
|
430
|
+
const empty = width - filled;
|
|
431
|
+
const bar = colors.green + "█".repeat(filled) + colors.dim + "░".repeat(empty) + colors.reset;
|
|
432
|
+
const percent = `${percentage.toFixed(1)}%`;
|
|
433
|
+
return `${bar} ${percent}`;
|
|
434
|
+
};
|
|
435
|
+
var createSeparator = (length = 50, char = "-", color = "dim") => {
|
|
436
|
+
const colorCode = colors[color] || colors.dim;
|
|
437
|
+
return colorCode + char.repeat(length) + colors.reset;
|
|
438
|
+
};
|
|
439
|
+
var formatKeyValue = (key, value, keyWidth = 20) => {
|
|
440
|
+
const paddedKey = padRight(colors.cyan + key + colors.reset, keyWidth + 9);
|
|
441
|
+
return `${paddedKey}: ${colors.white}${value}${colors.reset}`;
|
|
442
|
+
};
|
|
443
|
+
var createList = (items, bullet = "•") => {
|
|
444
|
+
return items.map((item) => ` ${colors.dim}${bullet}${colors.reset} ${item}`).join(`
|
|
445
|
+
`);
|
|
446
|
+
};
|
|
447
|
+
var highlight = (text, bgColor = "bgYellow") => {
|
|
448
|
+
const bg = colors[bgColor] || colors.bgYellow;
|
|
449
|
+
return bg + colors.black + text + colors.reset;
|
|
450
|
+
};
|
|
451
|
+
module.exports = {
|
|
452
|
+
createBadge,
|
|
453
|
+
createBox,
|
|
454
|
+
createBanner,
|
|
455
|
+
stripAnsi,
|
|
456
|
+
truncate,
|
|
457
|
+
center,
|
|
458
|
+
padRight,
|
|
459
|
+
padLeft,
|
|
460
|
+
createProgressBar,
|
|
461
|
+
createSeparator,
|
|
462
|
+
formatKeyValue,
|
|
463
|
+
createList,
|
|
464
|
+
highlight
|
|
465
|
+
};
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
// node_modules/ernest-logger/index.js
|
|
469
|
+
var require_ernest_logger = __commonJS((exports, module) => {
|
|
470
|
+
var fs = __require("fs");
|
|
471
|
+
var path = __require("path");
|
|
472
|
+
var colors = require_colors();
|
|
473
|
+
var emojis = require_emojis();
|
|
474
|
+
var getTimestamp = require_timestamp();
|
|
475
|
+
var formatter = require_formatter();
|
|
476
|
+
var levelPriority = {
|
|
477
|
+
trace: 0,
|
|
478
|
+
debug: 1,
|
|
479
|
+
info: 2,
|
|
480
|
+
success: 3,
|
|
481
|
+
warn: 4,
|
|
482
|
+
error: 5,
|
|
483
|
+
fatal: 6
|
|
484
|
+
};
|
|
485
|
+
var globalConfig = {
|
|
486
|
+
time: true,
|
|
487
|
+
emoji: true,
|
|
488
|
+
level: "debug",
|
|
489
|
+
file: false,
|
|
490
|
+
filePath: path.join(process.cwd(), "ernest.log"),
|
|
491
|
+
colorize: true,
|
|
492
|
+
prefix: "",
|
|
493
|
+
maxFileSize: 5 * 1024 * 1024,
|
|
494
|
+
customLevels: {}
|
|
495
|
+
};
|
|
496
|
+
var rotateLogFile = (filePath, maxSize) => {
|
|
497
|
+
try {
|
|
498
|
+
const stats = fs.statSync(filePath);
|
|
499
|
+
if (stats.size > maxSize) {
|
|
500
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
|
|
501
|
+
const rotatedPath = filePath.replace(".log", `-${timestamp}.log`);
|
|
502
|
+
fs.renameSync(filePath, rotatedPath);
|
|
503
|
+
}
|
|
504
|
+
} catch (err) {}
|
|
505
|
+
};
|
|
506
|
+
var createLogger = (options = {}) => {
|
|
507
|
+
const config = { ...globalConfig, ...options };
|
|
508
|
+
const formatMessage = (level, message, color) => {
|
|
509
|
+
if (levelPriority[level] < levelPriority[config.level])
|
|
510
|
+
return null;
|
|
511
|
+
let output = "";
|
|
512
|
+
if (config.time) {
|
|
513
|
+
const timestamp = getTimestamp();
|
|
514
|
+
output += config.colorize ? colors.dim + `[${timestamp}]` + colors.reset + " " : `[${timestamp}] `;
|
|
515
|
+
}
|
|
516
|
+
if (config.prefix) {
|
|
517
|
+
output += config.colorize ? colors.dim + config.prefix + colors.reset + " " : config.prefix + " ";
|
|
518
|
+
}
|
|
519
|
+
if (config.emoji && emojis[level]) {
|
|
520
|
+
output += `${emojis[level]} `;
|
|
521
|
+
}
|
|
522
|
+
const levelBadge = formatter.createBadge(level.toUpperCase(), color);
|
|
523
|
+
output += config.colorize ? levelBadge + " " : `[${level.toUpperCase()}] `;
|
|
524
|
+
output += config.colorize ? colors[color] + message + colors.reset : message;
|
|
525
|
+
return output;
|
|
526
|
+
};
|
|
527
|
+
const writeToFile = (message) => {
|
|
528
|
+
if (!config.file)
|
|
529
|
+
return;
|
|
530
|
+
try {
|
|
531
|
+
rotateLogFile(config.filePath, config.maxFileSize);
|
|
532
|
+
const plainMessage = message.replace(/\x1b\[[0-9;]*m/g, "");
|
|
533
|
+
fs.appendFileSync(config.filePath, plainMessage + `
|
|
534
|
+
`);
|
|
535
|
+
} catch (err) {
|
|
536
|
+
console.error("Failed to write to log file:", err.message);
|
|
537
|
+
}
|
|
538
|
+
};
|
|
539
|
+
const logMessage = (level, color, message) => {
|
|
540
|
+
const formatted = formatMessage(level, message, color);
|
|
541
|
+
if (!formatted)
|
|
542
|
+
return;
|
|
543
|
+
console.log(formatted);
|
|
544
|
+
writeToFile(formatted);
|
|
545
|
+
};
|
|
546
|
+
const logger = {
|
|
547
|
+
trace: (msg) => logMessage("trace", "dim", msg),
|
|
548
|
+
debug: (msg) => logMessage("debug", "cyan", msg),
|
|
549
|
+
info: (msg) => logMessage("info", "blue", msg),
|
|
550
|
+
success: (msg) => logMessage("success", "green", msg),
|
|
551
|
+
warn: (msg) => logMessage("warn", "yellow", msg),
|
|
552
|
+
error: (msg) => logMessage("error", "red", msg),
|
|
553
|
+
fatal: (msg) => logMessage("fatal", "brightRed", msg),
|
|
554
|
+
start: (msg) => logMessage("info", "brightGreen", `▶️ ${msg}`),
|
|
555
|
+
stop: (msg) => logMessage("info", "brightRed", `⏹️ ${msg}`),
|
|
556
|
+
network: (msg) => logMessage("info", "brightCyan", `\uD83C\uDF10 ${msg}`),
|
|
557
|
+
db: (msg) => logMessage("info", "brightMagenta", `\uD83D\uDCBE ${msg}`),
|
|
558
|
+
api: (msg) => logMessage("info", "brightBlue", `\uD83D\uDD0C ${msg}`),
|
|
559
|
+
security: (msg) => logMessage("warn", "brightYellow", `\uD83D\uDD12 ${msg}`),
|
|
560
|
+
bigLog: (message, options2 = {}) => {
|
|
561
|
+
const color = options2.color || "blue";
|
|
562
|
+
const emoji = options2.emoji || "\uD83D\uDCE3";
|
|
563
|
+
const boxed = formatter.createBox(message, color, emoji);
|
|
564
|
+
console.log(boxed);
|
|
565
|
+
if (config.file)
|
|
566
|
+
writeToFile(boxed);
|
|
567
|
+
},
|
|
568
|
+
table: (data) => {
|
|
569
|
+
console.table(data);
|
|
570
|
+
if (config.file) {
|
|
571
|
+
writeToFile(`
|
|
572
|
+
[TABLE DATA]
|
|
573
|
+
` + JSON.stringify(data, null, 2));
|
|
574
|
+
}
|
|
575
|
+
},
|
|
576
|
+
group: (label) => console.group(label),
|
|
577
|
+
groupEnd: () => console.groupEnd(),
|
|
578
|
+
time: (label) => console.time(label),
|
|
579
|
+
timeEnd: (label) => console.timeEnd(label),
|
|
580
|
+
json: (obj, label = "") => {
|
|
581
|
+
const output = label ? `${label}:
|
|
582
|
+
` : "";
|
|
583
|
+
const formatted = output + JSON.stringify(obj, null, 2);
|
|
584
|
+
console.log(config.colorize ? colors.cyan + formatted + colors.reset : formatted);
|
|
585
|
+
if (config.file)
|
|
586
|
+
writeToFile(formatted);
|
|
587
|
+
},
|
|
588
|
+
log: {
|
|
589
|
+
trace: {
|
|
590
|
+
dim: (msg) => logMessage("trace", "dim", msg),
|
|
591
|
+
white: (msg) => logMessage("trace", "white", msg)
|
|
592
|
+
},
|
|
593
|
+
debug: {
|
|
594
|
+
cyan: (msg) => logMessage("debug", "cyan", msg),
|
|
595
|
+
blue: (msg) => logMessage("debug", "blue", msg),
|
|
596
|
+
magenta: (msg) => logMessage("debug", "magenta", msg)
|
|
597
|
+
},
|
|
598
|
+
info: {
|
|
599
|
+
blue: (msg) => logMessage("info", "blue", msg),
|
|
600
|
+
cyan: (msg) => logMessage("info", "cyan", msg),
|
|
601
|
+
white: (msg) => logMessage("info", "white", msg)
|
|
602
|
+
},
|
|
603
|
+
success: {
|
|
604
|
+
green: (msg) => logMessage("success", "green", msg),
|
|
605
|
+
brightGreen: (msg) => logMessage("success", "brightGreen", msg)
|
|
606
|
+
},
|
|
607
|
+
warn: {
|
|
608
|
+
yellow: (msg) => logMessage("warn", "yellow", msg),
|
|
609
|
+
brightYellow: (msg) => logMessage("warn", "brightYellow", msg)
|
|
610
|
+
},
|
|
611
|
+
error: {
|
|
612
|
+
red: (msg) => logMessage("error", "red", msg),
|
|
613
|
+
brightRed: (msg) => logMessage("error", "brightRed", msg),
|
|
614
|
+
magenta: (msg) => logMessage("error", "magenta", msg)
|
|
615
|
+
},
|
|
616
|
+
fatal: {
|
|
617
|
+
brightRed: (msg) => logMessage("fatal", "brightRed", msg),
|
|
618
|
+
bgRed: (msg) => logMessage("fatal", "bgRed", msg)
|
|
619
|
+
}
|
|
620
|
+
},
|
|
621
|
+
configure: (newConfig) => {
|
|
622
|
+
Object.assign(config, newConfig);
|
|
623
|
+
return logger;
|
|
624
|
+
},
|
|
625
|
+
getConfig: () => ({ ...config }),
|
|
626
|
+
enableTime: () => {
|
|
627
|
+
config.time = true;
|
|
628
|
+
return logger;
|
|
629
|
+
},
|
|
630
|
+
disableTime: () => {
|
|
631
|
+
config.time = false;
|
|
632
|
+
return logger;
|
|
633
|
+
},
|
|
634
|
+
enableEmoji: () => {
|
|
635
|
+
config.emoji = true;
|
|
636
|
+
return logger;
|
|
637
|
+
},
|
|
638
|
+
disableEmoji: () => {
|
|
639
|
+
config.emoji = false;
|
|
640
|
+
return logger;
|
|
641
|
+
},
|
|
642
|
+
enableFile: () => {
|
|
643
|
+
config.file = true;
|
|
644
|
+
return logger;
|
|
645
|
+
},
|
|
646
|
+
disableFile: () => {
|
|
647
|
+
config.file = false;
|
|
648
|
+
return logger;
|
|
649
|
+
},
|
|
650
|
+
setLevel: (level) => {
|
|
651
|
+
config.level = level;
|
|
652
|
+
return logger;
|
|
653
|
+
}
|
|
654
|
+
};
|
|
655
|
+
if (config.customLevels && Object.keys(config.customLevels).length > 0) {
|
|
656
|
+
Object.entries(config.customLevels).forEach(([level, { color, emoji, priority }]) => {
|
|
657
|
+
if (emoji)
|
|
658
|
+
emojis[level] = emoji;
|
|
659
|
+
if (priority !== undefined)
|
|
660
|
+
levelPriority[level] = priority;
|
|
661
|
+
logger[level] = (msg) => logMessage(level, color, msg);
|
|
662
|
+
logger.log[level] = {
|
|
663
|
+
[color]: (msg) => logMessage(level, color, msg)
|
|
664
|
+
};
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
return logger;
|
|
668
|
+
};
|
|
669
|
+
var defaultLogger = createLogger();
|
|
670
|
+
module.exports = defaultLogger;
|
|
671
|
+
module.exports.createLogger = createLogger;
|
|
672
|
+
module.exports.setGlobalConfig = (config) => {
|
|
673
|
+
Object.assign(globalConfig, config);
|
|
674
|
+
};
|
|
675
|
+
});
|
|
676
|
+
|
|
677
|
+
// piggy/client/index.ts
|
|
678
|
+
import { connect } from "net";
|
|
679
|
+
import { writeFileSync, mkdirSync } from "fs";
|
|
680
|
+
import { dirname } from "path";
|
|
681
|
+
import { platform } from "os";
|
|
682
|
+
|
|
683
|
+
// piggy/logger/index.ts
|
|
684
|
+
var import_ernest_logger = __toESM(require_ernest_logger(), 1);
|
|
685
|
+
var logger = import_ernest_logger.createLogger({
|
|
686
|
+
time: true,
|
|
687
|
+
file: true,
|
|
688
|
+
filePath: "./piggy.log",
|
|
689
|
+
prefix: "[PIGGY]",
|
|
690
|
+
emoji: true,
|
|
691
|
+
level: "trace",
|
|
692
|
+
customLevels: {
|
|
693
|
+
info: {
|
|
694
|
+
color: "blue",
|
|
695
|
+
emoji: "ℹ️",
|
|
696
|
+
priority: 2
|
|
697
|
+
},
|
|
698
|
+
success: {
|
|
699
|
+
color: "green",
|
|
700
|
+
emoji: "✅",
|
|
701
|
+
priority: 2
|
|
702
|
+
},
|
|
703
|
+
error: {
|
|
704
|
+
color: "red",
|
|
705
|
+
emoji: "❌",
|
|
706
|
+
priority: 5
|
|
707
|
+
},
|
|
708
|
+
warn: {
|
|
709
|
+
color: "yellow",
|
|
710
|
+
emoji: "⚠️",
|
|
711
|
+
priority: 4
|
|
712
|
+
},
|
|
713
|
+
debug: {
|
|
714
|
+
color: "magenta",
|
|
715
|
+
emoji: "\uD83D\uDC1E",
|
|
716
|
+
priority: 1
|
|
717
|
+
},
|
|
718
|
+
network: {
|
|
719
|
+
color: "brightCyan",
|
|
720
|
+
emoji: "\uD83C\uDF10",
|
|
721
|
+
priority: 2
|
|
722
|
+
},
|
|
723
|
+
db: {
|
|
724
|
+
color: "brightMagenta",
|
|
725
|
+
emoji: "\uD83D\uDDC4️",
|
|
726
|
+
priority: 2
|
|
727
|
+
},
|
|
728
|
+
security: {
|
|
729
|
+
color: "brightRed",
|
|
730
|
+
emoji: "\uD83D\uDD12",
|
|
731
|
+
priority: 3
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
});
|
|
735
|
+
logger.info("logger initialized");
|
|
736
|
+
var logger_default = logger;
|
|
737
|
+
|
|
738
|
+
// piggy/client/index.ts
|
|
739
|
+
var SOCKET_PATH = platform() === "win32" ? "\\\\.\\pipe\\piggy" : "/tmp/piggy";
|
|
740
|
+
|
|
741
|
+
class PiggyClient {
|
|
742
|
+
socketPath;
|
|
743
|
+
socket = null;
|
|
744
|
+
reqId = 0;
|
|
745
|
+
pending = new Map;
|
|
746
|
+
buf = "";
|
|
747
|
+
eventBuffer = "";
|
|
748
|
+
eventHandlers = new Map;
|
|
749
|
+
constructor(socketPath = SOCKET_PATH) {
|
|
750
|
+
this.socketPath = socketPath;
|
|
751
|
+
this.eventHandlers.set("default", new Map);
|
|
752
|
+
}
|
|
753
|
+
connect() {
|
|
754
|
+
return new Promise((resolve, reject) => {
|
|
755
|
+
logger_default.info(`Connecting to socket: ${this.socketPath}`);
|
|
756
|
+
const sock = connect(this.socketPath);
|
|
757
|
+
sock.setEncoding("utf8");
|
|
758
|
+
sock.on("connect", () => {
|
|
759
|
+
this.socket = sock;
|
|
760
|
+
logger_default.success("Connected to Piggy server");
|
|
761
|
+
resolve();
|
|
762
|
+
});
|
|
763
|
+
sock.on("data", (chunk) => {
|
|
764
|
+
this.eventBuffer += chunk;
|
|
765
|
+
const lines = this.eventBuffer.split(`
|
|
766
|
+
`);
|
|
767
|
+
this.eventBuffer = lines.pop();
|
|
768
|
+
for (const line of lines) {
|
|
769
|
+
if (!line.trim())
|
|
770
|
+
continue;
|
|
771
|
+
try {
|
|
772
|
+
const msg = JSON.parse(line);
|
|
773
|
+
if (msg.type === "event") {
|
|
774
|
+
this.handleEvent(msg);
|
|
775
|
+
continue;
|
|
776
|
+
}
|
|
777
|
+
const p = this.pending.get(msg.id);
|
|
778
|
+
if (p) {
|
|
779
|
+
this.pending.delete(msg.id);
|
|
780
|
+
msg.ok ? p.resolve(msg.data) : p.reject(new Error(msg.data ?? "command failed"));
|
|
781
|
+
}
|
|
782
|
+
} catch {
|
|
783
|
+
logger_default.error(`Bad JSON from server: ${line}`);
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
});
|
|
787
|
+
sock.on("error", (e) => {
|
|
788
|
+
for (const p of this.pending.values())
|
|
789
|
+
p.reject(e);
|
|
790
|
+
this.pending.clear();
|
|
791
|
+
reject(e);
|
|
792
|
+
});
|
|
793
|
+
sock.on("close", () => {
|
|
794
|
+
for (const p of this.pending.values())
|
|
795
|
+
p.reject(new Error("Socket closed"));
|
|
796
|
+
this.pending.clear();
|
|
797
|
+
});
|
|
798
|
+
});
|
|
799
|
+
}
|
|
800
|
+
handleEvent(event) {
|
|
801
|
+
if (event.event === "exposed_call") {
|
|
802
|
+
const { tabId, name, callId, data } = event;
|
|
803
|
+
const effectiveTabId = tabId || "default";
|
|
804
|
+
const handlers = this.eventHandlers.get(effectiveTabId);
|
|
805
|
+
const handler = handlers?.get(name);
|
|
806
|
+
if (handler) {
|
|
807
|
+
Promise.resolve(handler(JSON.parse(data || "null"))).then((response) => {
|
|
808
|
+
if (response && typeof response === "object" && "success" in response) {
|
|
809
|
+
if (response.success) {
|
|
810
|
+
this.send("exposed.result", {
|
|
811
|
+
tabId: effectiveTabId,
|
|
812
|
+
callId,
|
|
813
|
+
result: JSON.stringify(response.result),
|
|
814
|
+
isError: false
|
|
815
|
+
}).catch((e) => logger_default.error(`Failed to send exposed result: ${e}`));
|
|
816
|
+
} else {
|
|
817
|
+
this.send("exposed.result", {
|
|
818
|
+
tabId: effectiveTabId,
|
|
819
|
+
callId,
|
|
820
|
+
result: response.error || "Unknown error",
|
|
821
|
+
isError: true
|
|
822
|
+
}).catch((e) => logger_default.error(`Failed to send exposed error: ${e}`));
|
|
823
|
+
}
|
|
824
|
+
} else {
|
|
825
|
+
this.send("exposed.result", {
|
|
826
|
+
tabId: effectiveTabId,
|
|
827
|
+
callId,
|
|
828
|
+
result: JSON.stringify(response),
|
|
829
|
+
isError: false
|
|
830
|
+
}).catch((e) => logger_default.error(`Failed to send exposed result: ${e}`));
|
|
831
|
+
}
|
|
832
|
+
}).catch((err) => {
|
|
833
|
+
this.send("exposed.result", {
|
|
834
|
+
tabId: effectiveTabId,
|
|
835
|
+
callId,
|
|
836
|
+
result: err.message || "Handler error",
|
|
837
|
+
isError: true
|
|
838
|
+
}).catch((e) => logger_default.error(`Failed to send exposed error: ${e}`));
|
|
839
|
+
});
|
|
840
|
+
} else {
|
|
841
|
+
logger_default.warn(`No handler for exposed function: ${name} in tab ${effectiveTabId}`);
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
disconnect() {
|
|
846
|
+
this.socket?.destroy();
|
|
847
|
+
this.socket = null;
|
|
848
|
+
}
|
|
849
|
+
send(cmd, payload = {}) {
|
|
850
|
+
return new Promise((resolve, reject) => {
|
|
851
|
+
if (!this.socket)
|
|
852
|
+
return reject(new Error("Not connected"));
|
|
853
|
+
const id = String(++this.reqId);
|
|
854
|
+
this.pending.set(id, { resolve, reject });
|
|
855
|
+
this.socket.write(JSON.stringify({ id, cmd, payload }) + `
|
|
856
|
+
`);
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
async newTab() {
|
|
860
|
+
return this.send("tab.new", {});
|
|
861
|
+
}
|
|
862
|
+
async closeTab(tabId) {
|
|
863
|
+
await this.send("tab.close", { tabId });
|
|
864
|
+
}
|
|
865
|
+
async listTabs() {
|
|
866
|
+
return this.send("tab.list", {});
|
|
867
|
+
}
|
|
868
|
+
async navigate(url, tabId = "default") {
|
|
869
|
+
await this.send("navigate", { url, tabId });
|
|
870
|
+
}
|
|
871
|
+
async reload(tabId = "default") {
|
|
872
|
+
await this.send("reload", { tabId });
|
|
873
|
+
}
|
|
874
|
+
async goBack(tabId = "default") {
|
|
875
|
+
await this.send("go.back", { tabId });
|
|
876
|
+
}
|
|
877
|
+
async goForward(tabId = "default") {
|
|
878
|
+
await this.send("go.forward", { tabId });
|
|
879
|
+
}
|
|
880
|
+
async getTitle(tabId = "default") {
|
|
881
|
+
return this.send("page.title", { tabId });
|
|
882
|
+
}
|
|
883
|
+
async getUrl(tabId = "default") {
|
|
884
|
+
return this.send("page.url", { tabId });
|
|
885
|
+
}
|
|
886
|
+
async content(tabId = "default") {
|
|
887
|
+
return this.send("page.content", { tabId });
|
|
888
|
+
}
|
|
889
|
+
async evaluate(js, tabId = "default") {
|
|
890
|
+
return this.send("evaluate", { js, tabId });
|
|
891
|
+
}
|
|
892
|
+
async click(selector, tabId = "default") {
|
|
893
|
+
return this.send("click", { selector, tabId });
|
|
894
|
+
}
|
|
895
|
+
async doubleClick(selector, tabId = "default") {
|
|
896
|
+
return this.send("dblclick", { selector, tabId });
|
|
897
|
+
}
|
|
898
|
+
async hover(selector, tabId = "default") {
|
|
899
|
+
return this.send("hover", { selector, tabId });
|
|
900
|
+
}
|
|
901
|
+
async type(selector, text, tabId = "default") {
|
|
902
|
+
return this.send("type", { selector, text, tabId });
|
|
903
|
+
}
|
|
904
|
+
async select(selector, value, tabId = "default") {
|
|
905
|
+
return this.send("select", { selector, value, tabId });
|
|
906
|
+
}
|
|
907
|
+
async keyPress(key, tabId = "default") {
|
|
908
|
+
return this.send("keyboard.press", { key, tabId });
|
|
909
|
+
}
|
|
910
|
+
async keyCombo(combo, tabId = "default") {
|
|
911
|
+
return this.send("keyboard.combo", { combo, tabId });
|
|
912
|
+
}
|
|
913
|
+
async mouseMove(x, y, tabId = "default") {
|
|
914
|
+
return this.send("mouse.move", { x, y, tabId });
|
|
915
|
+
}
|
|
916
|
+
async mouseDrag(from, to, tabId = "default") {
|
|
917
|
+
return this.send("mouse.drag", { from, to, tabId });
|
|
918
|
+
}
|
|
919
|
+
async scrollTo(selector, tabId = "default") {
|
|
920
|
+
return this.send("scroll.to", { selector, tabId });
|
|
921
|
+
}
|
|
922
|
+
async scrollBy(px, tabId = "default") {
|
|
923
|
+
return this.send("scroll.by", { px, tabId });
|
|
924
|
+
}
|
|
925
|
+
async fetchText(query, tabId = "default") {
|
|
926
|
+
return this.send("fetch.text", { query, tabId });
|
|
927
|
+
}
|
|
928
|
+
async fetchLinks(query, tabId = "default") {
|
|
929
|
+
if (query === "a" || query === "body") {
|
|
930
|
+
const result2 = await this.send("fetch.links.all", { tabId });
|
|
931
|
+
return Array.isArray(result2) ? result2 : [];
|
|
932
|
+
}
|
|
933
|
+
const result = await this.send("fetch.links", { query, tabId });
|
|
934
|
+
return Array.isArray(result) ? result : [];
|
|
935
|
+
}
|
|
936
|
+
async fetchImages(query, tabId = "default") {
|
|
937
|
+
const result = await this.send("fetch.image", { query, tabId });
|
|
938
|
+
return Array.isArray(result) ? result : [];
|
|
939
|
+
}
|
|
940
|
+
async searchCss(query, tabId = "default") {
|
|
941
|
+
return this.send("search.css", { query, tabId });
|
|
942
|
+
}
|
|
943
|
+
async searchId(query, tabId = "default") {
|
|
944
|
+
return this.send("search.id", { query, tabId });
|
|
945
|
+
}
|
|
946
|
+
async waitForSelector(selector, timeout = 30000, tabId = "default") {
|
|
947
|
+
await this.send("wait.selector", { selector, timeout, tabId });
|
|
948
|
+
}
|
|
949
|
+
async waitForNavigation(tabId = "default") {
|
|
950
|
+
await this.send("wait.navigation", { tabId });
|
|
951
|
+
}
|
|
952
|
+
async waitForResponse(urlPattern, timeout = 30000, tabId = "default") {
|
|
953
|
+
await this.send("wait.response", { url: urlPattern, timeout, tabId });
|
|
954
|
+
}
|
|
955
|
+
async screenshot(filePath, tabId = "default") {
|
|
956
|
+
const b64 = await this.send("screenshot", { tabId });
|
|
957
|
+
if (filePath) {
|
|
958
|
+
mkdirSync(dirname(filePath), { recursive: true });
|
|
959
|
+
writeFileSync(filePath, Buffer.from(b64, "base64"));
|
|
960
|
+
}
|
|
961
|
+
return filePath ?? b64;
|
|
962
|
+
}
|
|
963
|
+
async pdf(filePath, tabId = "default") {
|
|
964
|
+
const b64 = await this.send("pdf", { tabId });
|
|
965
|
+
if (filePath) {
|
|
966
|
+
mkdirSync(dirname(filePath), { recursive: true });
|
|
967
|
+
writeFileSync(filePath, Buffer.from(b64, "base64"));
|
|
968
|
+
}
|
|
969
|
+
return filePath ?? b64;
|
|
970
|
+
}
|
|
971
|
+
async blockImages(tabId = "default") {
|
|
972
|
+
await this.send("intercept.block.images", { tabId });
|
|
973
|
+
}
|
|
974
|
+
async unblockImages(tabId = "default") {
|
|
975
|
+
await this.send("intercept.unblock.images", { tabId });
|
|
976
|
+
}
|
|
977
|
+
async setCookie(name, value, domain, path = "/", tabId = "default") {
|
|
978
|
+
await this.send("cookie.set", { name, value, domain, path, tabId });
|
|
979
|
+
}
|
|
980
|
+
async getCookie(name, tabId = "default") {
|
|
981
|
+
return this.send("cookie.get", { name, tabId });
|
|
982
|
+
}
|
|
983
|
+
async deleteCookie(name, tabId = "default") {
|
|
984
|
+
await this.send("cookie.delete", { name, tabId });
|
|
985
|
+
}
|
|
986
|
+
async listCookies(tabId = "default") {
|
|
987
|
+
return this.send("cookie.list", { tabId });
|
|
988
|
+
}
|
|
989
|
+
async addInterceptRule(action, pattern, options = {}, tabId = "default") {
|
|
990
|
+
await this.send("intercept.rule.add", { action, pattern, ...options, tabId });
|
|
991
|
+
}
|
|
992
|
+
async clearInterceptRules(tabId = "default") {
|
|
993
|
+
await this.send("intercept.rule.clear", { tabId });
|
|
994
|
+
}
|
|
995
|
+
async captureStart(tabId = "default") {
|
|
996
|
+
await this.send("capture.start", { tabId });
|
|
997
|
+
}
|
|
998
|
+
async captureStop(tabId = "default") {
|
|
999
|
+
await this.send("capture.stop", { tabId });
|
|
1000
|
+
}
|
|
1001
|
+
async captureRequests(tabId = "default") {
|
|
1002
|
+
return this.send("capture.requests", { tabId });
|
|
1003
|
+
}
|
|
1004
|
+
async captureWs(tabId = "default") {
|
|
1005
|
+
return this.send("capture.ws", { tabId });
|
|
1006
|
+
}
|
|
1007
|
+
async captureCookies(tabId = "default") {
|
|
1008
|
+
return this.send("capture.cookies", { tabId });
|
|
1009
|
+
}
|
|
1010
|
+
async captureStorage(tabId = "default") {
|
|
1011
|
+
return this.send("capture.storage", { tabId });
|
|
1012
|
+
}
|
|
1013
|
+
async captureClear(tabId = "default") {
|
|
1014
|
+
await this.send("capture.clear", { tabId });
|
|
1015
|
+
}
|
|
1016
|
+
async sessionExport(tabId = "default") {
|
|
1017
|
+
return this.send("session.export", { tabId });
|
|
1018
|
+
}
|
|
1019
|
+
async sessionImport(data, tabId = "default") {
|
|
1020
|
+
await this.send("session.import", { data, tabId });
|
|
1021
|
+
}
|
|
1022
|
+
async exposeFunction(name, handler, tabId = "default") {
|
|
1023
|
+
if (!this.eventHandlers.has(tabId)) {
|
|
1024
|
+
this.eventHandlers.set(tabId, new Map);
|
|
1025
|
+
}
|
|
1026
|
+
this.eventHandlers.get(tabId).set(name, async (data) => {
|
|
1027
|
+
try {
|
|
1028
|
+
const result = await handler(data);
|
|
1029
|
+
if (result && typeof result === "object" && (("success" in result) || ("error" in result))) {
|
|
1030
|
+
return result;
|
|
1031
|
+
}
|
|
1032
|
+
return { success: true, result };
|
|
1033
|
+
} catch (err) {
|
|
1034
|
+
return { success: false, error: err.message || String(err) };
|
|
1035
|
+
}
|
|
1036
|
+
});
|
|
1037
|
+
await this.send("expose.function", { name, tabId });
|
|
1038
|
+
logger_default.success(`[${tabId}] exposed function: ${name}`);
|
|
1039
|
+
}
|
|
1040
|
+
async unexposeFunction(name, tabId = "default") {
|
|
1041
|
+
const handlers = this.eventHandlers.get(tabId);
|
|
1042
|
+
if (handlers) {
|
|
1043
|
+
handlers.delete(name);
|
|
1044
|
+
}
|
|
1045
|
+
logger_default.info(`[${tabId}] unexposed function: ${name}`);
|
|
1046
|
+
}
|
|
1047
|
+
async clearExposedFunctions(tabId = "default") {
|
|
1048
|
+
this.eventHandlers.set(tabId, new Map);
|
|
1049
|
+
logger_default.info(`[${tabId}] cleared all exposed functions`);
|
|
1050
|
+
}
|
|
1051
|
+
}
|
|
1052
|
+
export {
|
|
1053
|
+
PiggyClient
|
|
1054
|
+
};
|