notte-sdk 0.0.6 → 0.0.8
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 +2 -1
- package/dist/index.d.mts +16 -3
- package/dist/index.d.ts +16 -3
- package/dist/index.js +151 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +151 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -5,6 +5,104 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
|
|
|
5
5
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
6
|
});
|
|
7
7
|
|
|
8
|
+
// src/version.ts
|
|
9
|
+
var SDK_VERSION = true ? "0.0.8" : "dev";
|
|
10
|
+
var SDK_PACKAGE_NAME = true ? "notte-sdk" : "notte-sdk";
|
|
11
|
+
|
|
12
|
+
// src/version-check.ts
|
|
13
|
+
var DISABLE_ENV = "NOTTE_SDK_DISABLE_VERSION_CHECK";
|
|
14
|
+
var VERSION_CHECK_TIMEOUT_MS = 1500;
|
|
15
|
+
var hasStartedVersionCheck = false;
|
|
16
|
+
function startVersionCheck() {
|
|
17
|
+
if (hasStartedVersionCheck || !shouldCheckVersion()) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
hasStartedVersionCheck = true;
|
|
21
|
+
const timer = setTimeout(() => {
|
|
22
|
+
void checkForLatestVersion().catch(() => void 0);
|
|
23
|
+
}, 0);
|
|
24
|
+
timer.unref?.();
|
|
25
|
+
}
|
|
26
|
+
async function checkForLatestVersion(options = {}) {
|
|
27
|
+
const currentVersion = options.currentVersion ?? SDK_VERSION;
|
|
28
|
+
const packageName = options.packageName ?? SDK_PACKAGE_NAME;
|
|
29
|
+
const fetchFn = options.fetchFn ?? globalThis.fetch;
|
|
30
|
+
const warnFn = options.warnFn ?? console.warn;
|
|
31
|
+
const env = options.env ?? getEnv();
|
|
32
|
+
if (!shouldCheckVersion(currentVersion, fetchFn, env)) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const latestVersion = await fetchLatestVersion(packageName, fetchFn);
|
|
36
|
+
if (!latestVersion || !isVersionGreater(latestVersion, currentVersion)) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
warnFn(
|
|
40
|
+
`[${packageName}] A newer version is available: ${currentVersion} -> ${latestVersion}. Update with: npm install ${packageName}@latest`
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
function shouldCheckVersion(currentVersion = SDK_VERSION, fetchFn = globalThis.fetch, env = getEnv()) {
|
|
44
|
+
if (!fetchFn || !env || env[DISABLE_ENV] || env.NODE_ENV === "test" || env.VITEST || env.CI) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
return isPublishedVersion(currentVersion);
|
|
48
|
+
}
|
|
49
|
+
async function fetchLatestVersion(packageName, fetchFn) {
|
|
50
|
+
const controller = typeof AbortController !== "undefined" ? new AbortController() : void 0;
|
|
51
|
+
const timeout = controller ? setTimeout(() => controller.abort(), VERSION_CHECK_TIMEOUT_MS) : void 0;
|
|
52
|
+
timeout?.unref?.();
|
|
53
|
+
try {
|
|
54
|
+
const response = await fetchFn(`https://registry.npmjs.org/${encodeURIComponent(packageName)}/latest`, {
|
|
55
|
+
headers: {
|
|
56
|
+
accept: "application/json"
|
|
57
|
+
},
|
|
58
|
+
signal: controller?.signal
|
|
59
|
+
});
|
|
60
|
+
if (!response.ok) {
|
|
61
|
+
return void 0;
|
|
62
|
+
}
|
|
63
|
+
const payload = await response.json();
|
|
64
|
+
return typeof payload.version === "string" ? payload.version : void 0;
|
|
65
|
+
} catch {
|
|
66
|
+
return void 0;
|
|
67
|
+
} finally {
|
|
68
|
+
if (timeout) {
|
|
69
|
+
clearTimeout(timeout);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function isPublishedVersion(version) {
|
|
74
|
+
return /^\d+\.\d+\.\d+/.test(version) && !version.includes("dev");
|
|
75
|
+
}
|
|
76
|
+
function isVersionGreater(candidate, current) {
|
|
77
|
+
const candidateVersion = parseSemver(candidate);
|
|
78
|
+
const currentVersion = parseSemver(current);
|
|
79
|
+
if (!candidateVersion || !currentVersion) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
for (let index = 0; index < 3; index += 1) {
|
|
83
|
+
if (candidateVersion.parts[index] > currentVersion.parts[index]) {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
if (candidateVersion.parts[index] < currentVersion.parts[index]) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return currentVersion.prerelease.length > 0 && candidateVersion.prerelease.length === 0;
|
|
91
|
+
}
|
|
92
|
+
function parseSemver(version) {
|
|
93
|
+
const match = version.match(/^(\d+)\.(\d+)\.(\d+)(?:-([^+]+))?/);
|
|
94
|
+
if (!match) {
|
|
95
|
+
return void 0;
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
parts: [Number(match[1]), Number(match[2]), Number(match[3])],
|
|
99
|
+
prerelease: match[4] ?? ""
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function getEnv() {
|
|
103
|
+
return typeof process !== "undefined" ? process.env : void 0;
|
|
104
|
+
}
|
|
105
|
+
|
|
8
106
|
// src/lib/client/core/bodySerializer.gen.ts
|
|
9
107
|
var serializeFormDataPair = (data, key, value) => {
|
|
10
108
|
if (typeof value === "string" || value instanceof Blob) {
|
|
@@ -1303,6 +1401,7 @@ var scrapeFromHtml = (options) => (options.client ?? client).post({
|
|
|
1303
1401
|
});
|
|
1304
1402
|
|
|
1305
1403
|
// src/utils.ts
|
|
1404
|
+
import { spawn } from "child_process";
|
|
1306
1405
|
function formatError(error) {
|
|
1307
1406
|
if (typeof error === "object" && error !== null) {
|
|
1308
1407
|
if ("message" in error && typeof error.message === "string") {
|
|
@@ -1319,6 +1418,28 @@ function formatError(error) {
|
|
|
1319
1418
|
}
|
|
1320
1419
|
return String(error);
|
|
1321
1420
|
}
|
|
1421
|
+
function openBrowser(url) {
|
|
1422
|
+
const platform = process.platform;
|
|
1423
|
+
let command;
|
|
1424
|
+
let args;
|
|
1425
|
+
if (platform === "darwin") {
|
|
1426
|
+
command = "open";
|
|
1427
|
+
args = [url];
|
|
1428
|
+
} else if (platform === "win32") {
|
|
1429
|
+
command = "rundll32";
|
|
1430
|
+
args = ["url.dll,FileProtocolHandler", url];
|
|
1431
|
+
} else {
|
|
1432
|
+
command = "xdg-open";
|
|
1433
|
+
args = [url];
|
|
1434
|
+
}
|
|
1435
|
+
const child = spawn(command, args, {
|
|
1436
|
+
detached: true,
|
|
1437
|
+
stdio: "ignore"
|
|
1438
|
+
});
|
|
1439
|
+
child.on("error", () => {
|
|
1440
|
+
});
|
|
1441
|
+
child.unref();
|
|
1442
|
+
}
|
|
1322
1443
|
|
|
1323
1444
|
// src/session.ts
|
|
1324
1445
|
import { z } from "zod";
|
|
@@ -1363,7 +1484,9 @@ var Session = class {
|
|
|
1363
1484
|
this.isActive = false;
|
|
1364
1485
|
this.response = null;
|
|
1365
1486
|
this.client = client2;
|
|
1366
|
-
|
|
1487
|
+
const { open_viewer = false, ...sessionOptions } = options;
|
|
1488
|
+
this.options = sessionOptions;
|
|
1489
|
+
this.openViewer = open_viewer;
|
|
1367
1490
|
}
|
|
1368
1491
|
/**
|
|
1369
1492
|
* Start the session - creates a new session on the server
|
|
@@ -1372,6 +1495,7 @@ var Session = class {
|
|
|
1372
1495
|
if (this.isActive) {
|
|
1373
1496
|
throw new Error("Session is already active");
|
|
1374
1497
|
}
|
|
1498
|
+
let shouldOpenViewer = false;
|
|
1375
1499
|
try {
|
|
1376
1500
|
const response = await sessionStart({
|
|
1377
1501
|
client: this.client.getClient(),
|
|
@@ -1384,9 +1508,13 @@ var Session = class {
|
|
|
1384
1508
|
this.sessionId = sessionData.session_id;
|
|
1385
1509
|
this.isActive = true;
|
|
1386
1510
|
this.response = sessionData;
|
|
1511
|
+
shouldOpenViewer = this.openViewer;
|
|
1387
1512
|
} catch (error) {
|
|
1388
1513
|
throw new Error(`Failed to start session: ${error instanceof Error ? error.message : String(error)}`);
|
|
1389
1514
|
}
|
|
1515
|
+
if (shouldOpenViewer) {
|
|
1516
|
+
this.openViewerInBrowser();
|
|
1517
|
+
}
|
|
1390
1518
|
}
|
|
1391
1519
|
/**
|
|
1392
1520
|
* Stop the session - terminates the session on the server
|
|
@@ -1444,6 +1572,27 @@ var Session = class {
|
|
|
1444
1572
|
getResponse() {
|
|
1445
1573
|
return this.response;
|
|
1446
1574
|
}
|
|
1575
|
+
/**
|
|
1576
|
+
* Open the live viewer for this session in the local default browser.
|
|
1577
|
+
*/
|
|
1578
|
+
viewer() {
|
|
1579
|
+
if (!this.sessionId) {
|
|
1580
|
+
throw new Error("Session not started");
|
|
1581
|
+
}
|
|
1582
|
+
const viewerUrl = this.response?.viewer_url;
|
|
1583
|
+
if (!viewerUrl) {
|
|
1584
|
+
throw new Error("No viewer URL available for this session");
|
|
1585
|
+
}
|
|
1586
|
+
openBrowser(viewerUrl);
|
|
1587
|
+
}
|
|
1588
|
+
openViewerInBrowser() {
|
|
1589
|
+
const viewerUrl = this.response?.viewer_url;
|
|
1590
|
+
if (!viewerUrl) {
|
|
1591
|
+
console.warn("[Session] No viewer URL available; session started without opening a viewer.");
|
|
1592
|
+
return;
|
|
1593
|
+
}
|
|
1594
|
+
openBrowser(viewerUrl);
|
|
1595
|
+
}
|
|
1447
1596
|
/**
|
|
1448
1597
|
* Set cookies for the session
|
|
1449
1598
|
*/
|
|
@@ -2523,9 +2672,6 @@ var NottePersona = class {
|
|
|
2523
2672
|
}
|
|
2524
2673
|
};
|
|
2525
2674
|
|
|
2526
|
-
// src/version.ts
|
|
2527
|
-
var SDK_VERSION = true ? "0.0.6" : "dev";
|
|
2528
|
-
|
|
2529
2675
|
// src/functions.ts
|
|
2530
2676
|
var NotteFunction = class {
|
|
2531
2677
|
constructor(client2, options) {
|
|
@@ -2756,6 +2902,7 @@ var NotteProxyAuthError = class extends Error {
|
|
|
2756
2902
|
};
|
|
2757
2903
|
|
|
2758
2904
|
// src/index.ts
|
|
2905
|
+
startVersionCheck();
|
|
2759
2906
|
var createClient2 = (config) => {
|
|
2760
2907
|
if (config?.baseUrl) {
|
|
2761
2908
|
client.setConfig({ baseUrl: config.baseUrl });
|