notte-sdk 1.10.17 → 1.10.19
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/dist/index.d.mts +13 -1
- package/dist/index.d.ts +13 -1
- package/dist/index.js +167 -115
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +167 -115
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -252,7 +252,7 @@ __export(index_exports, {
|
|
|
252
252
|
module.exports = __toCommonJS(index_exports);
|
|
253
253
|
|
|
254
254
|
// src/version.ts
|
|
255
|
-
var SDK_VERSION = true ? "1.10.
|
|
255
|
+
var SDK_VERSION = true ? "1.10.19" : "dev";
|
|
256
256
|
var SDK_PACKAGE_NAME = true ? "notte-sdk" : "notte-sdk";
|
|
257
257
|
|
|
258
258
|
// src/version-check.ts
|
|
@@ -372,33 +372,33 @@ function getEnv() {
|
|
|
372
372
|
}
|
|
373
373
|
|
|
374
374
|
// src/lib/client/core/bodySerializer.gen.ts
|
|
375
|
-
var serializeFormDataPair = (data, key,
|
|
376
|
-
if (typeof
|
|
377
|
-
data.append(key,
|
|
378
|
-
} else if (
|
|
379
|
-
data.append(key,
|
|
375
|
+
var serializeFormDataPair = (data, key, value2) => {
|
|
376
|
+
if (typeof value2 === "string" || value2 instanceof Blob) {
|
|
377
|
+
data.append(key, value2);
|
|
378
|
+
} else if (value2 instanceof Date) {
|
|
379
|
+
data.append(key, value2.toISOString());
|
|
380
380
|
} else {
|
|
381
|
-
data.append(key, JSON.stringify(
|
|
381
|
+
data.append(key, JSON.stringify(value2));
|
|
382
382
|
}
|
|
383
383
|
};
|
|
384
384
|
var formDataBodySerializer = {
|
|
385
385
|
bodySerializer: (body) => {
|
|
386
386
|
const data = new FormData();
|
|
387
|
-
Object.entries(body).forEach(([key,
|
|
388
|
-
if (
|
|
387
|
+
Object.entries(body).forEach(([key, value2]) => {
|
|
388
|
+
if (value2 === void 0 || value2 === null) {
|
|
389
389
|
return;
|
|
390
390
|
}
|
|
391
|
-
if (Array.isArray(
|
|
392
|
-
|
|
391
|
+
if (Array.isArray(value2)) {
|
|
392
|
+
value2.forEach((v) => serializeFormDataPair(data, key, v));
|
|
393
393
|
} else {
|
|
394
|
-
serializeFormDataPair(data, key,
|
|
394
|
+
serializeFormDataPair(data, key, value2);
|
|
395
395
|
}
|
|
396
396
|
});
|
|
397
397
|
return data;
|
|
398
398
|
}
|
|
399
399
|
};
|
|
400
400
|
var jsonBodySerializer = {
|
|
401
|
-
bodySerializer: (body) => JSON.stringify(body, (_key,
|
|
401
|
+
bodySerializer: (body) => JSON.stringify(body, (_key, value2) => typeof value2 === "bigint" ? value2.toString() : value2)
|
|
402
402
|
};
|
|
403
403
|
|
|
404
404
|
// src/lib/client/core/params.gen.ts
|
|
@@ -464,9 +464,9 @@ function createSseClient({
|
|
|
464
464
|
signal.addEventListener("abort", abortHandler);
|
|
465
465
|
try {
|
|
466
466
|
while (true) {
|
|
467
|
-
const { done, value } = await reader.read();
|
|
467
|
+
const { done, value: value2 } = await reader.read();
|
|
468
468
|
if (done) break;
|
|
469
|
-
buffer +=
|
|
469
|
+
buffer += value2;
|
|
470
470
|
buffer = buffer.replace(/\r\n?/g, "\n");
|
|
471
471
|
const chunks = buffer.split("\n\n");
|
|
472
472
|
buffer = chunks.pop() ?? "";
|
|
@@ -579,10 +579,10 @@ var serializeArrayParam = ({
|
|
|
579
579
|
explode,
|
|
580
580
|
name,
|
|
581
581
|
style,
|
|
582
|
-
value
|
|
582
|
+
value: value2
|
|
583
583
|
}) => {
|
|
584
584
|
if (!explode) {
|
|
585
|
-
const joinedValues2 = (allowReserved ?
|
|
585
|
+
const joinedValues2 = (allowReserved ? value2 : value2.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
|
|
586
586
|
switch (style) {
|
|
587
587
|
case "label":
|
|
588
588
|
return `.${joinedValues2}`;
|
|
@@ -595,7 +595,7 @@ var serializeArrayParam = ({
|
|
|
595
595
|
}
|
|
596
596
|
}
|
|
597
597
|
const separator = separatorArrayExplode(style);
|
|
598
|
-
const joinedValues =
|
|
598
|
+
const joinedValues = value2.map((v) => {
|
|
599
599
|
if (style === "label" || style === "simple") {
|
|
600
600
|
return allowReserved ? v : encodeURIComponent(v);
|
|
601
601
|
}
|
|
@@ -610,32 +610,32 @@ var serializeArrayParam = ({
|
|
|
610
610
|
var serializePrimitiveParam = ({
|
|
611
611
|
allowReserved,
|
|
612
612
|
name,
|
|
613
|
-
value
|
|
613
|
+
value: value2
|
|
614
614
|
}) => {
|
|
615
|
-
if (
|
|
615
|
+
if (value2 === void 0 || value2 === null) {
|
|
616
616
|
return "";
|
|
617
617
|
}
|
|
618
|
-
if (typeof
|
|
618
|
+
if (typeof value2 === "object") {
|
|
619
619
|
throw new Error(
|
|
620
620
|
"Deeply-nested arrays/objects aren\u2019t supported. Provide your own `querySerializer()` to handle these."
|
|
621
621
|
);
|
|
622
622
|
}
|
|
623
|
-
return `${name}=${allowReserved ?
|
|
623
|
+
return `${name}=${allowReserved ? value2 : encodeURIComponent(value2)}`;
|
|
624
624
|
};
|
|
625
625
|
var serializeObjectParam = ({
|
|
626
626
|
allowReserved,
|
|
627
627
|
explode,
|
|
628
628
|
name,
|
|
629
629
|
style,
|
|
630
|
-
value,
|
|
630
|
+
value: value2,
|
|
631
631
|
valueOnly
|
|
632
632
|
}) => {
|
|
633
|
-
if (
|
|
634
|
-
return valueOnly ?
|
|
633
|
+
if (value2 instanceof Date) {
|
|
634
|
+
return valueOnly ? value2.toISOString() : `${name}=${value2.toISOString()}`;
|
|
635
635
|
}
|
|
636
636
|
if (style !== "deepObject" && !explode) {
|
|
637
637
|
let values = [];
|
|
638
|
-
Object.entries(
|
|
638
|
+
Object.entries(value2).forEach(([key, v]) => {
|
|
639
639
|
values = [...values, key, allowReserved ? v : encodeURIComponent(v)];
|
|
640
640
|
});
|
|
641
641
|
const joinedValues2 = values.join(",");
|
|
@@ -651,7 +651,7 @@ var serializeObjectParam = ({
|
|
|
651
651
|
}
|
|
652
652
|
}
|
|
653
653
|
const separator = separatorObjectExplode(style);
|
|
654
|
-
const joinedValues = Object.entries(
|
|
654
|
+
const joinedValues = Object.entries(value2).map(
|
|
655
655
|
([key, v]) => serializePrimitiveParam({
|
|
656
656
|
allowReserved,
|
|
657
657
|
name: style === "deepObject" ? `${name}[${key}]` : key,
|
|
@@ -682,22 +682,22 @@ var defaultPathSerializer = ({ path, url: _url }) => {
|
|
|
682
682
|
name = name.substring(1);
|
|
683
683
|
style = "matrix";
|
|
684
684
|
}
|
|
685
|
-
const
|
|
686
|
-
if (
|
|
685
|
+
const value2 = path[name];
|
|
686
|
+
if (value2 === void 0 || value2 === null) {
|
|
687
687
|
continue;
|
|
688
688
|
}
|
|
689
|
-
if (Array.isArray(
|
|
690
|
-
url = url.replace(match, serializeArrayParam({ explode, name, style, value }));
|
|
689
|
+
if (Array.isArray(value2)) {
|
|
690
|
+
url = url.replace(match, serializeArrayParam({ explode, name, style, value: value2 }));
|
|
691
691
|
continue;
|
|
692
692
|
}
|
|
693
|
-
if (typeof
|
|
693
|
+
if (typeof value2 === "object") {
|
|
694
694
|
url = url.replace(
|
|
695
695
|
match,
|
|
696
696
|
serializeObjectParam({
|
|
697
697
|
explode,
|
|
698
698
|
name,
|
|
699
699
|
style,
|
|
700
|
-
value,
|
|
700
|
+
value: value2,
|
|
701
701
|
valueOnly: true
|
|
702
702
|
})
|
|
703
703
|
);
|
|
@@ -708,13 +708,13 @@ var defaultPathSerializer = ({ path, url: _url }) => {
|
|
|
708
708
|
match,
|
|
709
709
|
`;${serializePrimitiveParam({
|
|
710
710
|
name,
|
|
711
|
-
value
|
|
711
|
+
value: value2
|
|
712
712
|
})}`
|
|
713
713
|
);
|
|
714
714
|
continue;
|
|
715
715
|
}
|
|
716
716
|
const replaceValue = encodeURIComponent(
|
|
717
|
-
style === "label" ? `.${
|
|
717
|
+
style === "label" ? `.${value2}` : value2
|
|
718
718
|
);
|
|
719
719
|
url = url.replace(match, replaceValue);
|
|
720
720
|
}
|
|
@@ -782,28 +782,28 @@ var createQuerySerializer = ({
|
|
|
782
782
|
const search = [];
|
|
783
783
|
if (queryParams && typeof queryParams === "object") {
|
|
784
784
|
for (const name in queryParams) {
|
|
785
|
-
const
|
|
786
|
-
if (
|
|
785
|
+
const value2 = queryParams[name];
|
|
786
|
+
if (value2 === void 0 || value2 === null) {
|
|
787
787
|
continue;
|
|
788
788
|
}
|
|
789
789
|
const options = parameters[name] || args;
|
|
790
|
-
if (Array.isArray(
|
|
790
|
+
if (Array.isArray(value2)) {
|
|
791
791
|
const serializedArray = serializeArrayParam({
|
|
792
792
|
allowReserved: options.allowReserved,
|
|
793
793
|
explode: true,
|
|
794
794
|
name,
|
|
795
795
|
style: "form",
|
|
796
|
-
value,
|
|
796
|
+
value: value2,
|
|
797
797
|
...options.array
|
|
798
798
|
});
|
|
799
799
|
if (serializedArray) search.push(serializedArray);
|
|
800
|
-
} else if (typeof
|
|
800
|
+
} else if (typeof value2 === "object") {
|
|
801
801
|
const serializedObject = serializeObjectParam({
|
|
802
802
|
allowReserved: options.allowReserved,
|
|
803
803
|
explode: true,
|
|
804
804
|
name,
|
|
805
805
|
style: "deepObject",
|
|
806
|
-
value,
|
|
806
|
+
value: value2,
|
|
807
807
|
...options.object
|
|
808
808
|
});
|
|
809
809
|
if (serializedObject) search.push(serializedObject);
|
|
@@ -811,7 +811,7 @@ var createQuerySerializer = ({
|
|
|
811
811
|
const serializedPrimitive = serializePrimitiveParam({
|
|
812
812
|
allowReserved: options.allowReserved,
|
|
813
813
|
name,
|
|
814
|
-
value
|
|
814
|
+
value: value2
|
|
815
815
|
});
|
|
816
816
|
if (serializedPrimitive) search.push(serializedPrimitive);
|
|
817
817
|
}
|
|
@@ -896,8 +896,8 @@ var mergeConfigs = (a, b) => {
|
|
|
896
896
|
};
|
|
897
897
|
var headersEntries = (headers) => {
|
|
898
898
|
const entries = [];
|
|
899
|
-
headers.forEach((
|
|
900
|
-
entries.push([key,
|
|
899
|
+
headers.forEach((value2, key) => {
|
|
900
|
+
entries.push([key, value2]);
|
|
901
901
|
});
|
|
902
902
|
return entries;
|
|
903
903
|
};
|
|
@@ -908,17 +908,17 @@ var mergeHeaders = (...headers) => {
|
|
|
908
908
|
continue;
|
|
909
909
|
}
|
|
910
910
|
const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
|
|
911
|
-
for (const [key,
|
|
912
|
-
if (
|
|
911
|
+
for (const [key, value2] of iterator) {
|
|
912
|
+
if (value2 === null) {
|
|
913
913
|
mergedHeaders.delete(key);
|
|
914
|
-
} else if (Array.isArray(
|
|
915
|
-
for (const v of
|
|
914
|
+
} else if (Array.isArray(value2)) {
|
|
915
|
+
for (const v of value2) {
|
|
916
916
|
mergedHeaders.append(key, v);
|
|
917
917
|
}
|
|
918
|
-
} else if (
|
|
918
|
+
} else if (value2 !== void 0) {
|
|
919
919
|
mergedHeaders.set(
|
|
920
920
|
key,
|
|
921
|
-
typeof
|
|
921
|
+
typeof value2 === "object" ? JSON.stringify(value2) : value2
|
|
922
922
|
);
|
|
923
923
|
}
|
|
924
924
|
}
|
|
@@ -2405,9 +2405,9 @@ async function pollAuth(read, options) {
|
|
|
2405
2405
|
while (true) {
|
|
2406
2406
|
signal.throwIfAborted();
|
|
2407
2407
|
try {
|
|
2408
|
-
const
|
|
2408
|
+
const value2 = await read(signal);
|
|
2409
2409
|
signal.throwIfAborted();
|
|
2410
|
-
if (
|
|
2410
|
+
if (value2 !== void 0) return value2;
|
|
2411
2411
|
errors = 0;
|
|
2412
2412
|
} catch (error) {
|
|
2413
2413
|
signal.throwIfAborted();
|
|
@@ -2450,10 +2450,10 @@ var NotteManagedAuth = class {
|
|
|
2450
2450
|
}
|
|
2451
2451
|
/** Wait for an accepted operation. Aborting this wait does not cancel the server operation. */
|
|
2452
2452
|
async waitForAuth(operation, options = {}) {
|
|
2453
|
-
const completed = (
|
|
2454
|
-
if (
|
|
2455
|
-
if (
|
|
2456
|
-
throw new ManagedAuthError(
|
|
2453
|
+
const completed = (value2) => {
|
|
2454
|
+
if (value2.status === "succeeded") return value2;
|
|
2455
|
+
if (value2.status === "pending" || value2.status === "running") return void 0;
|
|
2456
|
+
throw new ManagedAuthError(value2.error || "Connection authentication failed");
|
|
2457
2457
|
};
|
|
2458
2458
|
options.signal?.throwIfAborted();
|
|
2459
2459
|
const result = completed(operation);
|
|
@@ -2919,6 +2919,32 @@ var import_promises3 = require("fs/promises");
|
|
|
2919
2919
|
var import_node_path2 = require("path");
|
|
2920
2920
|
var import_promises4 = require("timers/promises");
|
|
2921
2921
|
|
|
2922
|
+
// src/client-info.ts
|
|
2923
|
+
var UNSAFE = /[^A-Za-z0-9._/-]/g;
|
|
2924
|
+
var MAX_VALUE_LENGTH = 100;
|
|
2925
|
+
function value(env, name) {
|
|
2926
|
+
const raw = env[name];
|
|
2927
|
+
return raw ? raw.replace(UNSAFE, "_").slice(0, MAX_VALUE_LENGTH) : void 0;
|
|
2928
|
+
}
|
|
2929
|
+
function githubActionsContext(env) {
|
|
2930
|
+
if (env.GITHUB_ACTIONS !== "true") return void 0;
|
|
2931
|
+
const run = value(env, "GITHUB_RUN_ID");
|
|
2932
|
+
const attempt = value(env, "GITHUB_RUN_ATTEMPT");
|
|
2933
|
+
const fields = [
|
|
2934
|
+
["repo", value(env, "GITHUB_REPOSITORY")],
|
|
2935
|
+
["run", run && attempt ? `${run}/${attempt}` : run],
|
|
2936
|
+
["job", value(env, "GITHUB_JOB")]
|
|
2937
|
+
];
|
|
2938
|
+
const parts = fields.filter(([, v]) => v).map(([k, v]) => `${k}=${v}`);
|
|
2939
|
+
return `github-actions (${parts.join("; ")})`;
|
|
2940
|
+
}
|
|
2941
|
+
function clientUserAgent() {
|
|
2942
|
+
if (typeof process === "undefined" || !process.versions?.node) return void 0;
|
|
2943
|
+
const agent = `notte-sdk-node/${SDK_VERSION} (node ${process.versions.node}; ${process.platform})`;
|
|
2944
|
+
const ci = githubActionsContext(process.env);
|
|
2945
|
+
return ci === void 0 ? agent : `${agent} ${ci}`;
|
|
2946
|
+
}
|
|
2947
|
+
|
|
2922
2948
|
// src/captcha.ts
|
|
2923
2949
|
async function executeWithCaptcha(action, budgetSeconds, request) {
|
|
2924
2950
|
const explicit = action.type === "captcha_solve";
|
|
@@ -3009,11 +3035,11 @@ function hasHeader(headers, name) {
|
|
|
3009
3035
|
}
|
|
3010
3036
|
function urlencode(mapping) {
|
|
3011
3037
|
const search = new URLSearchParams();
|
|
3012
|
-
for (const [key,
|
|
3013
|
-
if (Array.isArray(
|
|
3014
|
-
for (const item of
|
|
3038
|
+
for (const [key, value2] of Object.entries(mapping)) {
|
|
3039
|
+
if (Array.isArray(value2)) {
|
|
3040
|
+
for (const item of value2) search.append(key, String(item));
|
|
3015
3041
|
} else {
|
|
3016
|
-
search.append(key, String(
|
|
3042
|
+
search.append(key, String(value2));
|
|
3017
3043
|
}
|
|
3018
3044
|
}
|
|
3019
3045
|
return search.toString();
|
|
@@ -3153,9 +3179,9 @@ function encodingFor(headers, content) {
|
|
|
3153
3179
|
const contentType = Object.entries(headers).find(([key]) => key.toLowerCase() === CONTENT_TYPE)?.[1] ?? "";
|
|
3154
3180
|
for (const param of contentType.split(";").slice(1)) {
|
|
3155
3181
|
const [name, ...rest] = param.split("=");
|
|
3156
|
-
const
|
|
3157
|
-
if (name?.trim().toLowerCase() === "charset" &&
|
|
3158
|
-
return
|
|
3182
|
+
const value2 = rest.join("=");
|
|
3183
|
+
if (name?.trim().toLowerCase() === "charset" && value2) {
|
|
3184
|
+
return value2.trim().replace(/^["']|["']$/g, "");
|
|
3159
3185
|
}
|
|
3160
3186
|
}
|
|
3161
3187
|
try {
|
|
@@ -3213,11 +3239,11 @@ var PageFetchResponse = class {
|
|
|
3213
3239
|
}
|
|
3214
3240
|
};
|
|
3215
3241
|
var BASE64_PATTERN = /^[A-Za-z0-9+/]*={0,2}$/;
|
|
3216
|
-
function decodeBase64(
|
|
3217
|
-
if (!BASE64_PATTERN.test(
|
|
3242
|
+
function decodeBase64(value2) {
|
|
3243
|
+
if (!BASE64_PATTERN.test(value2) || value2.length % 4 !== 0) {
|
|
3218
3244
|
throw new Error("body_b64 is not valid base64");
|
|
3219
3245
|
}
|
|
3220
|
-
return new Uint8Array(Buffer.from(
|
|
3246
|
+
return new Uint8Array(Buffer.from(value2, "base64"));
|
|
3221
3247
|
}
|
|
3222
3248
|
function responseFromEvaluated(raw) {
|
|
3223
3249
|
let payload;
|
|
@@ -3243,8 +3269,8 @@ function responseFromEvaluated(raw) {
|
|
|
3243
3269
|
throw new Error("headers is not an object");
|
|
3244
3270
|
}
|
|
3245
3271
|
const headers = {};
|
|
3246
|
-
for (const [key,
|
|
3247
|
-
headers[String(key)] = String(
|
|
3272
|
+
for (const [key, value2] of Object.entries(rawHeaders)) {
|
|
3273
|
+
headers[String(key)] = String(value2);
|
|
3248
3274
|
}
|
|
3249
3275
|
const content = decodeBase64(String(envelope.body_b64 ?? ""));
|
|
3250
3276
|
const url = String(envelope.url ?? "");
|
|
@@ -3381,17 +3407,17 @@ var SCHEMA_MAP_KEYWORDS = /* @__PURE__ */ new Set(["properties", "patternPropert
|
|
|
3381
3407
|
function normalizeJsonSchema(schema) {
|
|
3382
3408
|
if (schema === null || typeof schema !== "object" || Array.isArray(schema)) return schema;
|
|
3383
3409
|
const out = {};
|
|
3384
|
-
for (const [key,
|
|
3385
|
-
if (SCHEMA_KEYWORDS.has(key) || key === "items" && Array.isArray(
|
|
3386
|
-
out[key] = Array.isArray(
|
|
3387
|
-
} else if (SCHEMA_ARRAY_KEYWORDS.has(key) && Array.isArray(
|
|
3388
|
-
out[key] =
|
|
3389
|
-
} else if (SCHEMA_MAP_KEYWORDS.has(key) &&
|
|
3410
|
+
for (const [key, value2] of Object.entries(schema)) {
|
|
3411
|
+
if (SCHEMA_KEYWORDS.has(key) || key === "items" && Array.isArray(value2)) {
|
|
3412
|
+
out[key] = Array.isArray(value2) ? value2.map(normalizeJsonSchema) : normalizeJsonSchema(value2);
|
|
3413
|
+
} else if (SCHEMA_ARRAY_KEYWORDS.has(key) && Array.isArray(value2)) {
|
|
3414
|
+
out[key] = value2.map(normalizeJsonSchema);
|
|
3415
|
+
} else if (SCHEMA_MAP_KEYWORDS.has(key) && value2 !== null && typeof value2 === "object" && !Array.isArray(value2)) {
|
|
3390
3416
|
out[key] = Object.fromEntries(
|
|
3391
|
-
Object.entries(
|
|
3417
|
+
Object.entries(value2).map(([name, sub]) => [name, normalizeJsonSchema(sub)])
|
|
3392
3418
|
);
|
|
3393
3419
|
} else {
|
|
3394
|
-
out[key] =
|
|
3420
|
+
out[key] = value2;
|
|
3395
3421
|
}
|
|
3396
3422
|
}
|
|
3397
3423
|
if (Array.isArray(out.type)) {
|
|
@@ -3399,8 +3425,8 @@ function normalizeJsonSchema(schema) {
|
|
|
3399
3425
|
const types = type;
|
|
3400
3426
|
const parent = {};
|
|
3401
3427
|
const scoped = {};
|
|
3402
|
-
for (const [key,
|
|
3403
|
-
(TYPE_SCOPED_KEYWORDS.has(key) ? scoped : parent)[key] =
|
|
3428
|
+
for (const [key, value2] of Object.entries(rest)) {
|
|
3429
|
+
(TYPE_SCOPED_KEYWORDS.has(key) ? scoped : parent)[key] = value2;
|
|
3404
3430
|
}
|
|
3405
3431
|
const typed = (t) => t === "null" ? { type: t } : { type: t, ...scoped };
|
|
3406
3432
|
let branches;
|
|
@@ -3430,8 +3456,8 @@ function normalizeJsonSchema(schema) {
|
|
|
3430
3456
|
}
|
|
3431
3457
|
|
|
3432
3458
|
// src/scrape.ts
|
|
3433
|
-
function isZodSchema(
|
|
3434
|
-
return typeof
|
|
3459
|
+
function isZodSchema(value2) {
|
|
3460
|
+
return typeof value2 === "object" && value2 !== null && typeof value2.parse === "function";
|
|
3435
3461
|
}
|
|
3436
3462
|
function requiresSchema(options) {
|
|
3437
3463
|
return Boolean(options.response_format || options.instructions);
|
|
@@ -3520,9 +3546,9 @@ function networkErrorCode(error, depth = 0) {
|
|
|
3520
3546
|
}
|
|
3521
3547
|
function parseRetryAfter(header, now = Date.now()) {
|
|
3522
3548
|
if (!header) return void 0;
|
|
3523
|
-
const
|
|
3524
|
-
if (/^\d+(\.\d+)?$/.test(
|
|
3525
|
-
const date = Date.parse(
|
|
3549
|
+
const value2 = header.trim();
|
|
3550
|
+
if (/^\d+(\.\d+)?$/.test(value2)) return Number(value2) * 1e3;
|
|
3551
|
+
const date = Date.parse(value2);
|
|
3526
3552
|
return Number.isNaN(date) ? void 0 : Math.max(0, date - now);
|
|
3527
3553
|
}
|
|
3528
3554
|
function backoffDelayMs(attempt, random = Math.random) {
|
|
@@ -3629,6 +3655,30 @@ function cdpTransportFailure(error) {
|
|
|
3629
3655
|
if (reason.startsWith("ws://") || reason.startsWith("wss://")) return void 0;
|
|
3630
3656
|
return CDP_TRANSPORT_FAILURES.some((failure) => reason.includes(failure)) ? reason : void 0;
|
|
3631
3657
|
}
|
|
3658
|
+
function onApiOrigin(cdpUrl, apiUrl) {
|
|
3659
|
+
if (!apiUrl) return false;
|
|
3660
|
+
let target;
|
|
3661
|
+
let api;
|
|
3662
|
+
try {
|
|
3663
|
+
target = new URL(cdpUrl);
|
|
3664
|
+
api = new URL(apiUrl);
|
|
3665
|
+
} catch {
|
|
3666
|
+
return false;
|
|
3667
|
+
}
|
|
3668
|
+
const secure = target.protocol === "wss:" && api.protocol === "https:";
|
|
3669
|
+
const plain = target.protocol === "ws:" && api.protocol === "http:";
|
|
3670
|
+
if (!secure && !plain) return false;
|
|
3671
|
+
const defaultPort = secure ? "443" : "80";
|
|
3672
|
+
return target.hostname === api.hostname && (target.port || defaultPort) === (api.port || defaultPort);
|
|
3673
|
+
}
|
|
3674
|
+
function cdpHeaders(cdpUrl, apiUrl) {
|
|
3675
|
+
const userAgent = onApiOrigin(cdpUrl, apiUrl) ? clientUserAgent() : void 0;
|
|
3676
|
+
return {
|
|
3677
|
+
...userAgent ? { "user-agent": userAgent } : {},
|
|
3678
|
+
"x-notte-request-origin": REQUEST_ORIGIN,
|
|
3679
|
+
"x-notte-sdk-version": SDK_VERSION
|
|
3680
|
+
};
|
|
3681
|
+
}
|
|
3632
3682
|
async function connectOverCdpWithRetry(connect) {
|
|
3633
3683
|
try {
|
|
3634
3684
|
return await connect();
|
|
@@ -4269,7 +4319,7 @@ var Session = class {
|
|
|
4269
4319
|
const cdpUrl = await this.cdpUrl();
|
|
4270
4320
|
this.playwrightBrowser = await connectOverCdpWithRetry(
|
|
4271
4321
|
() => this.options.cdp_url ? playwright.chromium.connectOverCDP(cdpUrl) : playwright.chromium.connectOverCDP(cdpUrl, {
|
|
4272
|
-
headers:
|
|
4322
|
+
headers: cdpHeaders(cdpUrl, this.client.getConfig().baseUrl)
|
|
4273
4323
|
})
|
|
4274
4324
|
);
|
|
4275
4325
|
installServerOwnedDialogPolicy(this.playwrightBrowser);
|
|
@@ -4295,7 +4345,7 @@ var Session = class {
|
|
|
4295
4345
|
}
|
|
4296
4346
|
}
|
|
4297
4347
|
/**
|
|
4298
|
-
* Get the
|
|
4348
|
+
* Get the function code generated from the session steps
|
|
4299
4349
|
* (`GET /sessions/{id}/workflow/code`).
|
|
4300
4350
|
*
|
|
4301
4351
|
* @example
|
|
@@ -4817,9 +4867,9 @@ var NotteVault = class {
|
|
|
4817
4867
|
for (const field of CREDENTIAL_FIELDS) {
|
|
4818
4868
|
const variable = `${prefix}_${field.toUpperCase()}`;
|
|
4819
4869
|
variableNames.push(variable);
|
|
4820
|
-
const
|
|
4821
|
-
if (
|
|
4822
|
-
credentials[field] =
|
|
4870
|
+
const value2 = process.env[variable];
|
|
4871
|
+
if (value2 !== void 0) {
|
|
4872
|
+
credentials[field] = value2;
|
|
4823
4873
|
}
|
|
4824
4874
|
}
|
|
4825
4875
|
if (Object.keys(credentials).length === 0) {
|
|
@@ -4854,9 +4904,9 @@ var NotteVault = class {
|
|
|
4854
4904
|
const limit = Math.floor(4294967296 / size) * size;
|
|
4855
4905
|
const buffer = new Uint32Array(1);
|
|
4856
4906
|
for (; ; ) {
|
|
4857
|
-
const [
|
|
4858
|
-
if (
|
|
4859
|
-
return
|
|
4907
|
+
const [value2] = globalThis.crypto.getRandomValues(buffer);
|
|
4908
|
+
if (value2 < limit) {
|
|
4909
|
+
return value2 % size;
|
|
4860
4910
|
}
|
|
4861
4911
|
}
|
|
4862
4912
|
};
|
|
@@ -5233,12 +5283,12 @@ async function resolveRunPayloads(input) {
|
|
|
5233
5283
|
let size = 0;
|
|
5234
5284
|
try {
|
|
5235
5285
|
while (true) {
|
|
5236
|
-
const { done, value:
|
|
5286
|
+
const { done, value: value3 } = await reader.read();
|
|
5237
5287
|
if (done) break;
|
|
5238
|
-
size +=
|
|
5288
|
+
size += value3.length;
|
|
5239
5289
|
if (size > reference.size_bytes) throw new Error("Run payload exceeds its declared size");
|
|
5240
|
-
hash.update(
|
|
5241
|
-
chunks.push(
|
|
5290
|
+
hash.update(value3);
|
|
5291
|
+
chunks.push(value3);
|
|
5242
5292
|
}
|
|
5243
5293
|
} finally {
|
|
5244
5294
|
await reader.cancel();
|
|
@@ -5247,11 +5297,11 @@ async function resolveRunPayloads(input) {
|
|
|
5247
5297
|
if (size !== reference.size_bytes || hash.digest("base64") !== reference.sha256) {
|
|
5248
5298
|
throw new Error("Run payload failed size/checksum verification");
|
|
5249
5299
|
}
|
|
5250
|
-
const
|
|
5251
|
-
if (field === "result" &&
|
|
5252
|
-
if (field === "logs" && (!Array.isArray(
|
|
5253
|
-
if (field === "variables" &&
|
|
5254
|
-
Object.assign(run, { [field]:
|
|
5300
|
+
const value2 = JSON.parse(Buffer.concat(chunks, size).toString("utf8"));
|
|
5301
|
+
if (field === "result" && value2 !== null && typeof value2 !== "string") throw new Error("Invalid stored result");
|
|
5302
|
+
if (field === "logs" && (!Array.isArray(value2) || !value2.every((line) => typeof line === "string"))) throw new Error("Invalid stored logs");
|
|
5303
|
+
if (field === "variables" && value2 !== null && (typeof value2 !== "object" || Array.isArray(value2))) throw new Error("Invalid stored variables");
|
|
5304
|
+
Object.assign(run, { [field]: value2 });
|
|
5255
5305
|
}
|
|
5256
5306
|
delete run.payloads;
|
|
5257
5307
|
delete run.payload_urls;
|
|
@@ -5758,8 +5808,8 @@ var NotteFunction = class {
|
|
|
5758
5808
|
return response.data;
|
|
5759
5809
|
}
|
|
5760
5810
|
};
|
|
5761
|
-
function isHttpUrl(
|
|
5762
|
-
return
|
|
5811
|
+
function isHttpUrl(value2) {
|
|
5812
|
+
return value2.startsWith("https://") || value2.startsWith("http://");
|
|
5763
5813
|
}
|
|
5764
5814
|
function assertPythonPath(path) {
|
|
5765
5815
|
if (!path.endsWith(".py")) {
|
|
@@ -5793,11 +5843,11 @@ function unwrapRuntimeEnvelope(candidate, path) {
|
|
|
5793
5843
|
}
|
|
5794
5844
|
throw NotteAPIError.fromBody(path, statusCode, parsed);
|
|
5795
5845
|
}
|
|
5796
|
-
function parseFunctionRunResult(
|
|
5797
|
-
if (typeof
|
|
5846
|
+
function parseFunctionRunResult(value2, path) {
|
|
5847
|
+
if (typeof value2 !== "object" || value2 === null) {
|
|
5798
5848
|
throw new NotteError("Invalid function result: expected an object");
|
|
5799
5849
|
}
|
|
5800
|
-
const candidate =
|
|
5850
|
+
const candidate = value2;
|
|
5801
5851
|
unwrapRuntimeEnvelope(candidate, path);
|
|
5802
5852
|
const status = candidate.status;
|
|
5803
5853
|
if (typeof candidate.function_run_id !== "string" || typeof candidate.function_id !== "string" || typeof status !== "string" || !FUNCTION_RUN_STATUSES.includes(status) || !("result" in candidate)) {
|
|
@@ -5843,21 +5893,21 @@ async function readFunctionStream(body, onLog, path, signal) {
|
|
|
5843
5893
|
if (event.type === "log") onLog(String(event.message ?? ""));
|
|
5844
5894
|
if (event.type === "error") throw new NotteError(`Function stream error: ${String(event.message ?? "")}`);
|
|
5845
5895
|
if (event.type === "result") {
|
|
5846
|
-
const
|
|
5847
|
-
result = parseFunctionRunResult(
|
|
5896
|
+
const value2 = typeof event.message === "string" ? JSON.parse(event.message) : event.message;
|
|
5897
|
+
result = parseFunctionRunResult(value2, path);
|
|
5848
5898
|
}
|
|
5849
5899
|
};
|
|
5850
|
-
const line = (
|
|
5851
|
-
if (
|
|
5852
|
-
else if (
|
|
5900
|
+
const line = (value2) => {
|
|
5901
|
+
if (value2 === "") dispatch();
|
|
5902
|
+
else if (value2.startsWith("data:")) {
|
|
5853
5903
|
sawFrame = true;
|
|
5854
|
-
data.push(
|
|
5904
|
+
data.push(value2.slice(5).replace(/^ /, ""));
|
|
5855
5905
|
}
|
|
5856
5906
|
};
|
|
5857
5907
|
try {
|
|
5858
5908
|
while (true) {
|
|
5859
|
-
const { value, done } = await reader.read();
|
|
5860
|
-
const text = decoder.decode(
|
|
5909
|
+
const { value: value2, done } = await reader.read();
|
|
5910
|
+
const text = decoder.decode(value2, { stream: !done });
|
|
5861
5911
|
buffer += text;
|
|
5862
5912
|
if (!sawFrame) raw += text;
|
|
5863
5913
|
let end;
|
|
@@ -6214,8 +6264,8 @@ async function* readAnythingStream(body) {
|
|
|
6214
6264
|
let buffer = "";
|
|
6215
6265
|
try {
|
|
6216
6266
|
while (true) {
|
|
6217
|
-
const { value, done } = await reader.read();
|
|
6218
|
-
buffer += decoder.decode(
|
|
6267
|
+
const { value: value2, done } = await reader.read();
|
|
6268
|
+
buffer += decoder.decode(value2, { stream: !done });
|
|
6219
6269
|
let end;
|
|
6220
6270
|
while ((end = buffer.indexOf("\n")) !== -1) {
|
|
6221
6271
|
const line = buffer.slice(0, end).replace(/\r$/, "");
|
|
@@ -6448,6 +6498,8 @@ var NotteClient3 = class {
|
|
|
6448
6498
|
if (this.config.apiKey) headers.set("Authorization", `Bearer ${this.config.apiKey}`);
|
|
6449
6499
|
headers.set("x-notte-request-origin", REQUEST_ORIGIN);
|
|
6450
6500
|
headers.set("x-notte-sdk-version", SDK_VERSION);
|
|
6501
|
+
const userAgent = clientUserAgent();
|
|
6502
|
+
if (userAgent) headers.set("user-agent", userAgent);
|
|
6451
6503
|
if (this.config.dbPreview) headers.set(DB_PREVIEW_HEADER, this.config.dbPreview);
|
|
6452
6504
|
if (!headers.has(ACCEPT_RUN_STATUSES_HEADER) && isFunctionsRequest(request.url, this.config.baseUrl)) {
|
|
6453
6505
|
headers.set(ACCEPT_RUN_STATUSES_HEADER, "rejected");
|