notte-sdk 1.10.12 → 1.10.14
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 +1966 -1674
- package/dist/index.d.ts +1966 -1674
- package/dist/index.js +194 -57
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +191 -57
- package/dist/index.mjs.map +1 -1
- package/dist/proxy/core.js +10 -2
- package/dist/proxy/core.js.map +1 -1
- package/dist/proxy/core.mjs +10 -2
- package/dist/proxy/core.mjs.map +1 -1
- package/dist/proxy/next.d.mts +2 -2
- package/dist/proxy/next.d.ts +2 -2
- package/dist/proxy/next.js +10 -2
- package/dist/proxy/next.js.map +1 -1
- package/dist/proxy/next.mjs +10 -2
- package/dist/proxy/next.mjs.map +1 -1
- package/dist/{types-DM7HUU9V.d.mts → types-oOBIGqNh.d.mts} +3 -1
- package/dist/{types-DM7HUU9V.d.ts → types-oOBIGqNh.d.ts} +3 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -35,6 +35,7 @@ __export(index_exports, {
|
|
|
35
35
|
CAPTCHA_SOLVE_TIMEOUT_MS: () => CAPTCHA_SOLVE_TIMEOUT_MS,
|
|
36
36
|
CLUSTER_OVERLOAD_RETRY_DELAY_MS: () => CLUSTER_OVERLOAD_RETRY_DELAY_MS,
|
|
37
37
|
CREDENTIAL_FIELDS: () => CREDENTIAL_FIELDS,
|
|
38
|
+
CaptchaRejectedError: () => CaptchaRejectedError,
|
|
38
39
|
DEFAULT_MAX_RETRIES: () => DEFAULT_MAX_RETRIES,
|
|
39
40
|
DEFAULT_NOTTE_API_URL: () => DEFAULT_NOTTE_API_URL,
|
|
40
41
|
DEFAULT_REQUEST_TIMEOUT_MS: () => DEFAULT_REQUEST_TIMEOUT_MS,
|
|
@@ -46,6 +47,7 @@ __export(index_exports, {
|
|
|
46
47
|
FetchResponseDecodeError: () => FetchResponseDecodeError,
|
|
47
48
|
FileExistsError: () => FileExistsError,
|
|
48
49
|
FileNotFoundError: () => FileNotFoundError,
|
|
50
|
+
FunctionRunRejectedError: () => FunctionRunRejectedError,
|
|
49
51
|
InvalidRequestError: () => InvalidRequestError,
|
|
50
52
|
ManagedAuthError: () => ManagedAuthError,
|
|
51
53
|
NotteAPIError: () => NotteAPIError,
|
|
@@ -222,6 +224,7 @@ __export(index_exports, {
|
|
|
222
224
|
sessionResume: () => sessionResume,
|
|
223
225
|
sessionStart: () => sessionStart,
|
|
224
226
|
sessionStatus: () => sessionStatus,
|
|
227
|
+
sessionSteps: () => sessionSteps,
|
|
225
228
|
sessionStop: () => sessionStop,
|
|
226
229
|
startVersionCheck: () => startVersionCheck,
|
|
227
230
|
storeSecret: () => storeSecret,
|
|
@@ -247,7 +250,7 @@ __export(index_exports, {
|
|
|
247
250
|
module.exports = __toCommonJS(index_exports);
|
|
248
251
|
|
|
249
252
|
// src/version.ts
|
|
250
|
-
var SDK_VERSION = true ? "1.10.
|
|
253
|
+
var SDK_VERSION = true ? "1.10.14" : "dev";
|
|
251
254
|
var SDK_PACKAGE_NAME = true ? "notte-sdk" : "notte-sdk";
|
|
252
255
|
|
|
253
256
|
// src/version-check.ts
|
|
@@ -1209,6 +1212,11 @@ var sessionStatus = (options) => (options.client ?? client).get({
|
|
|
1209
1212
|
url: "/sessions/{session_id}",
|
|
1210
1213
|
...options
|
|
1211
1214
|
});
|
|
1215
|
+
var sessionSteps = (options) => (options.client ?? client).get({
|
|
1216
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
1217
|
+
url: "/sessions/{session_id}/steps",
|
|
1218
|
+
...options
|
|
1219
|
+
});
|
|
1212
1220
|
var sessionProfilePreview = (options) => (options.client ?? client).get({
|
|
1213
1221
|
security: [{ scheme: "bearer", type: "http" }],
|
|
1214
1222
|
url: "/sessions/{session_id}/profile-preview",
|
|
@@ -1714,49 +1722,6 @@ var profileList = (options) => (options?.client ?? client).get({
|
|
|
1714
1722
|
url: "/profiles",
|
|
1715
1723
|
...options
|
|
1716
1724
|
});
|
|
1717
|
-
var personaCreate = (options) => (options.client ?? client).post({
|
|
1718
|
-
security: [{ scheme: "bearer", type: "http" }],
|
|
1719
|
-
url: "/personas/create",
|
|
1720
|
-
...options,
|
|
1721
|
-
headers: {
|
|
1722
|
-
"Content-Type": "application/json",
|
|
1723
|
-
...options.headers
|
|
1724
|
-
}
|
|
1725
|
-
});
|
|
1726
|
-
var personaDelete = (options) => (options.client ?? client).delete({
|
|
1727
|
-
security: [{ scheme: "bearer", type: "http" }],
|
|
1728
|
-
url: "/personas/{persona_id}",
|
|
1729
|
-
...options
|
|
1730
|
-
});
|
|
1731
|
-
var personaGet = (options) => (options.client ?? client).get({
|
|
1732
|
-
security: [{ scheme: "bearer", type: "http" }],
|
|
1733
|
-
url: "/personas/{persona_id}",
|
|
1734
|
-
...options
|
|
1735
|
-
});
|
|
1736
|
-
var personaUpdate = (options) => (options.client ?? client).patch({
|
|
1737
|
-
security: [{ scheme: "bearer", type: "http" }],
|
|
1738
|
-
url: "/personas/{persona_id}",
|
|
1739
|
-
...options,
|
|
1740
|
-
headers: {
|
|
1741
|
-
"Content-Type": "application/json",
|
|
1742
|
-
...options.headers
|
|
1743
|
-
}
|
|
1744
|
-
});
|
|
1745
|
-
var personaEmailsList = (options) => (options.client ?? client).get({
|
|
1746
|
-
security: [{ scheme: "bearer", type: "http" }],
|
|
1747
|
-
url: "/personas/{persona_id}/emails",
|
|
1748
|
-
...options
|
|
1749
|
-
});
|
|
1750
|
-
var listPersonas = (options) => (options?.client ?? client).get({
|
|
1751
|
-
security: [{ scheme: "bearer", type: "http" }],
|
|
1752
|
-
url: "/personas",
|
|
1753
|
-
...options
|
|
1754
|
-
});
|
|
1755
|
-
var personaSmsList = (options) => (options.client ?? client).get({
|
|
1756
|
-
security: [{ scheme: "bearer", type: "http" }],
|
|
1757
|
-
url: "/personas/{persona_id}/sms",
|
|
1758
|
-
...options
|
|
1759
|
-
});
|
|
1760
1725
|
var mailboxConnectToken = (options) => (options.client ?? client).post({
|
|
1761
1726
|
security: [{ scheme: "bearer", type: "http" }],
|
|
1762
1727
|
url: "/mailboxes/connect-token",
|
|
@@ -1868,11 +1833,6 @@ var deleteSecret = (options) => (options.client ?? client).delete({
|
|
|
1868
1833
|
url: "/secrets/{secret_id}",
|
|
1869
1834
|
...options
|
|
1870
1835
|
});
|
|
1871
|
-
var listSecretProxyHostPresets = (options) => (options?.client ?? client).get({
|
|
1872
|
-
security: [{ scheme: "bearer", type: "http" }],
|
|
1873
|
-
url: "/secret-proxy/host-presets",
|
|
1874
|
-
...options
|
|
1875
|
-
});
|
|
1876
1836
|
var healthCheck = (options) => (options?.client ?? client).get({ url: "/health", ...options });
|
|
1877
1837
|
var readyCheck = (options) => (options?.client ?? client).get({ url: "/ready", ...options });
|
|
1878
1838
|
var scrapeWebpage = (options) => (options.client ?? client).post({
|
|
@@ -2116,6 +2076,54 @@ var listAuditEvents = (options) => (options?.client ?? client).get({
|
|
|
2116
2076
|
url: "/audit-events",
|
|
2117
2077
|
...options
|
|
2118
2078
|
});
|
|
2079
|
+
var listPersonas = (options) => (options?.client ?? client).get({
|
|
2080
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
2081
|
+
url: "/personas",
|
|
2082
|
+
...options
|
|
2083
|
+
});
|
|
2084
|
+
var personaCreate = (options) => (options.client ?? client).post({
|
|
2085
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
2086
|
+
url: "/personas/create",
|
|
2087
|
+
...options,
|
|
2088
|
+
headers: {
|
|
2089
|
+
"Content-Type": "application/json",
|
|
2090
|
+
...options.headers
|
|
2091
|
+
}
|
|
2092
|
+
});
|
|
2093
|
+
var personaDelete = (options) => (options.client ?? client).delete({
|
|
2094
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
2095
|
+
url: "/personas/{persona_id}",
|
|
2096
|
+
...options
|
|
2097
|
+
});
|
|
2098
|
+
var personaGet = (options) => (options.client ?? client).get({
|
|
2099
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
2100
|
+
url: "/personas/{persona_id}",
|
|
2101
|
+
...options
|
|
2102
|
+
});
|
|
2103
|
+
var personaUpdate = (options) => (options.client ?? client).patch({
|
|
2104
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
2105
|
+
url: "/personas/{persona_id}",
|
|
2106
|
+
...options,
|
|
2107
|
+
headers: {
|
|
2108
|
+
"Content-Type": "application/json",
|
|
2109
|
+
...options.headers
|
|
2110
|
+
}
|
|
2111
|
+
});
|
|
2112
|
+
var personaEmailsList = (options) => (options.client ?? client).get({
|
|
2113
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
2114
|
+
url: "/personas/{persona_id}/emails",
|
|
2115
|
+
...options
|
|
2116
|
+
});
|
|
2117
|
+
var personaSmsList = (options) => (options.client ?? client).get({
|
|
2118
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
2119
|
+
url: "/personas/{persona_id}/sms",
|
|
2120
|
+
...options
|
|
2121
|
+
});
|
|
2122
|
+
var listSecretProxyHostPresets = (options) => (options?.client ?? client).get({
|
|
2123
|
+
security: [{ scheme: "bearer", type: "http" }],
|
|
2124
|
+
url: "/secret-proxy/host-presets",
|
|
2125
|
+
...options
|
|
2126
|
+
});
|
|
2119
2127
|
var getUsage = (options) => (options?.client ?? client).get({
|
|
2120
2128
|
security: [{ scheme: "bearer", type: "http" }],
|
|
2121
2129
|
url: "/usage",
|
|
@@ -2161,6 +2169,9 @@ var getSessionScript = (options) => (options.client ?? client).get({
|
|
|
2161
2169
|
...options
|
|
2162
2170
|
});
|
|
2163
2171
|
|
|
2172
|
+
// src/run-statuses.ts
|
|
2173
|
+
var ACCEPT_RUN_STATUSES_HEADER = "x-notte-accept-run-statuses";
|
|
2174
|
+
|
|
2164
2175
|
// src/managed-auth.ts
|
|
2165
2176
|
var import_promises = require("timers/promises");
|
|
2166
2177
|
|
|
@@ -2221,15 +2232,32 @@ var FailedToRunCloudFunctionError = class extends NotteError {
|
|
|
2221
2232
|
functionId;
|
|
2222
2233
|
functionRunId;
|
|
2223
2234
|
response;
|
|
2224
|
-
constructor(functionId, functionRunId, response) {
|
|
2235
|
+
constructor(functionId, functionRunId, response, message) {
|
|
2225
2236
|
super(
|
|
2226
|
-
`Function ${functionId} run ${functionRunId} failed: ${typeof response === "string" ? response : describeBody(response ?? {})}`
|
|
2237
|
+
message ?? `Function ${functionId} run ${functionRunId} failed: ${typeof response === "string" ? response : describeBody(response ?? {})}`
|
|
2227
2238
|
);
|
|
2228
2239
|
this.functionId = functionId;
|
|
2229
2240
|
this.functionRunId = functionRunId;
|
|
2230
2241
|
this.response = response;
|
|
2231
2242
|
}
|
|
2232
2243
|
};
|
|
2244
|
+
var FunctionRunRejectedError = class extends FailedToRunCloudFunctionError {
|
|
2245
|
+
error;
|
|
2246
|
+
code;
|
|
2247
|
+
constructor(functionId, functionRunId, response) {
|
|
2248
|
+
const error = response.error ?? null;
|
|
2249
|
+
const code = typeof error?.code === "string" && error.code ? error.code : null;
|
|
2250
|
+
const detail2 = typeof error?.message === "string" && error.message ? error.message : `result '${typeof response.result === "string" ? response.result : JSON.stringify(response.result)}'`;
|
|
2251
|
+
super(
|
|
2252
|
+
functionId,
|
|
2253
|
+
functionRunId,
|
|
2254
|
+
response,
|
|
2255
|
+
`Function ${functionId} with run_id=${functionRunId} was rejected${code ? ` (${code})` : ""}: ${detail2}`
|
|
2256
|
+
);
|
|
2257
|
+
this.error = error;
|
|
2258
|
+
this.code = code;
|
|
2259
|
+
}
|
|
2260
|
+
};
|
|
2233
2261
|
var ScrapeFailedError = class extends NotteError {
|
|
2234
2262
|
structuredError;
|
|
2235
2263
|
constructor(error) {
|
|
@@ -2262,6 +2290,11 @@ var ActionExecutionError = class _ActionExecutionError extends NotteError {
|
|
|
2262
2290
|
});
|
|
2263
2291
|
}
|
|
2264
2292
|
};
|
|
2293
|
+
var CaptchaRejectedError = class extends ActionExecutionError {
|
|
2294
|
+
constructor(message) {
|
|
2295
|
+
super({ error_type: "CaptchaRejectedError", dev_message: message, user_message: message, agent_message: message });
|
|
2296
|
+
}
|
|
2297
|
+
};
|
|
2265
2298
|
var EvaluateJsNoDataError = class extends NotteError {
|
|
2266
2299
|
constructor() {
|
|
2267
2300
|
super("evaluate_js returned no data. Upgrade the Notte API to a build that returns the evaluated value.");
|
|
@@ -2670,6 +2703,7 @@ function createResources(client2, getApiKey) {
|
|
|
2670
2703
|
},
|
|
2671
2704
|
/** functionRunStart: /functions/{function_id}/runs/start. Returns the API response body. */
|
|
2672
2705
|
runStart: async (functionId, body, requestOptions = {}) => {
|
|
2706
|
+
if (typeof functionId !== "string" || !functionId.trim()) throw new TypeError("runStart requires a non-empty functionId.");
|
|
2673
2707
|
const response = await functionRunStart({ client: client2, throwOnError: true, signal: requestOptions.signal, headers: { ...requestOptions.headers, "x-notte-api-key": getApiKey() }, path: { "function_id": functionId }, body });
|
|
2674
2708
|
return response.data;
|
|
2675
2709
|
},
|
|
@@ -2905,6 +2939,9 @@ async function executeWithCaptcha(action, budgetSeconds, request) {
|
|
|
2905
2939
|
await pause();
|
|
2906
2940
|
continue;
|
|
2907
2941
|
}
|
|
2942
|
+
if (status.state === "failed" && status.failure_reason === "rejected") {
|
|
2943
|
+
return failure(status.message || "CAPTCHA rejected by the site", "captcha_rejected");
|
|
2944
|
+
}
|
|
2908
2945
|
if (status.state === "failed" || status.state === "cancelled") {
|
|
2909
2946
|
return failure(status.message || `CAPTCHA ${status.state}`, `captcha_${status.state}`);
|
|
2910
2947
|
}
|
|
@@ -3516,6 +3553,25 @@ function abortableSleep(ms, signal) {
|
|
|
3516
3553
|
});
|
|
3517
3554
|
}
|
|
3518
3555
|
|
|
3556
|
+
// src/session-steps.ts
|
|
3557
|
+
async function getSessionSteps(client2, sessionId, options = {}) {
|
|
3558
|
+
const response = await client2.getClient().get({
|
|
3559
|
+
url: `/sessions/${encodeURIComponent(sessionId)}/steps`,
|
|
3560
|
+
query: { cursor: options.cursor, limit: options.limit },
|
|
3561
|
+
throwOnError: true
|
|
3562
|
+
});
|
|
3563
|
+
return { steps: response.data.steps ?? [], next_cursor: response.data.next_cursor ?? null };
|
|
3564
|
+
}
|
|
3565
|
+
async function* iterSessionSteps(client2, sessionId, options = {}) {
|
|
3566
|
+
let cursor;
|
|
3567
|
+
while (true) {
|
|
3568
|
+
const page = await getSessionSteps(client2, sessionId, { cursor, limit: options.limit });
|
|
3569
|
+
yield* page.steps;
|
|
3570
|
+
if (page.next_cursor === null) return;
|
|
3571
|
+
cursor = page.next_cursor;
|
|
3572
|
+
}
|
|
3573
|
+
}
|
|
3574
|
+
|
|
3519
3575
|
// src/session.ts
|
|
3520
3576
|
var SESSION_START_TRIES = 3;
|
|
3521
3577
|
var CLUSTER_OVERLOAD_RETRY_DELAY_MS = 3e4;
|
|
@@ -4026,6 +4082,36 @@ var Session = class {
|
|
|
4026
4082
|
});
|
|
4027
4083
|
return response.data;
|
|
4028
4084
|
}
|
|
4085
|
+
/**
|
|
4086
|
+
* Get one page of the session's steps. Each step has the shape of an item of
|
|
4087
|
+
* `status().steps`. Pass the page's `next_cursor` back as `cursor`, as is, to
|
|
4088
|
+
* get the next page; it is `null` on the last page. Works after `stop()`.
|
|
4089
|
+
*
|
|
4090
|
+
* @throws NotteAPIError with status 400 when `cursor` is no longer valid: restart from the first page (no `cursor`).
|
|
4091
|
+
* @example
|
|
4092
|
+
* let page = await session.steps({ limit: 50 });
|
|
4093
|
+
* while (page.next_cursor !== null) {
|
|
4094
|
+
* page = await session.steps({ cursor: page.next_cursor, limit: 50 });
|
|
4095
|
+
* }
|
|
4096
|
+
*/
|
|
4097
|
+
async steps(options = {}) {
|
|
4098
|
+
return getSessionSteps(this.client, this.lastSessionId(), options);
|
|
4099
|
+
}
|
|
4100
|
+
/**
|
|
4101
|
+
* Iterate over all of the session's steps, following `next_cursor` page by page.
|
|
4102
|
+
* A cursor that is no longer valid stops the iteration with a `NotteAPIError`
|
|
4103
|
+
* with status 400, after the steps already yielded; it is not restarted here,
|
|
4104
|
+
* since that would yield those steps again. To read the steps again, start a
|
|
4105
|
+
* new iteration. Works after `stop()`.
|
|
4106
|
+
*
|
|
4107
|
+
* @example
|
|
4108
|
+
* for await (const step of session.iterSteps({ limit: 50 })) {
|
|
4109
|
+
* console.log(step);
|
|
4110
|
+
* }
|
|
4111
|
+
*/
|
|
4112
|
+
async *iterSteps(options = {}) {
|
|
4113
|
+
yield* iterSessionSteps(this.client, this.lastSessionId(), options);
|
|
4114
|
+
}
|
|
4029
4115
|
// #######################################################################
|
|
4030
4116
|
// ############################# Debug / CDP #############################
|
|
4031
4117
|
// #######################################################################
|
|
@@ -4185,6 +4271,9 @@ var Session = class {
|
|
|
4185
4271
|
);
|
|
4186
4272
|
if (raiseOnFailure && !result.success) {
|
|
4187
4273
|
console.error(`\u{1F6A8} Execution failed with message: '${result.message}'`);
|
|
4274
|
+
if (result.code === "captcha_rejected") {
|
|
4275
|
+
throw new CaptchaRejectedError(String(result.message ?? "").trim() || "CAPTCHA rejected by the site");
|
|
4276
|
+
}
|
|
4188
4277
|
if (result.exception_detail) {
|
|
4189
4278
|
throw new ActionExecutionError(result.exception_detail);
|
|
4190
4279
|
}
|
|
@@ -4439,15 +4528,19 @@ var NotteVault = class {
|
|
|
4439
4528
|
_vaultId = null;
|
|
4440
4529
|
initPromise = null;
|
|
4441
4530
|
createData = null;
|
|
4531
|
+
// Only a vault this object created is deleted by stop().
|
|
4532
|
+
created;
|
|
4442
4533
|
constructor(client2, options = {}) {
|
|
4443
4534
|
this.client = client2;
|
|
4444
4535
|
if (options && "vault_id" in options && options.vault_id !== void 0) {
|
|
4536
|
+
this.created = false;
|
|
4445
4537
|
if (options.vault_id.length === 0) {
|
|
4446
4538
|
throw new InvalidRequestError("Vault ID cannot be empty");
|
|
4447
4539
|
}
|
|
4448
4540
|
this.initPromise = this.initExistingVault(options.vault_id);
|
|
4449
4541
|
this.initPromise.catch(() => void 0);
|
|
4450
4542
|
} else {
|
|
4543
|
+
this.created = true;
|
|
4451
4544
|
const { vault_id: _ignored, ...createData } = options ?? {};
|
|
4452
4545
|
this.createData = createData;
|
|
4453
4546
|
}
|
|
@@ -4503,13 +4596,17 @@ var NotteVault = class {
|
|
|
4503
4596
|
start() {
|
|
4504
4597
|
}
|
|
4505
4598
|
/**
|
|
4506
|
-
* Stop the vault: deletes it together with every credential it holds
|
|
4599
|
+
* Stop the vault: deletes it together with every credential it holds, if
|
|
4600
|
+
* this object created it. A vault opened by `vault_id` is kept.
|
|
4507
4601
|
*
|
|
4508
4602
|
* ```ts
|
|
4509
4603
|
* await vault.stop();
|
|
4510
4604
|
* ```
|
|
4511
4605
|
*/
|
|
4512
4606
|
async stop() {
|
|
4607
|
+
if (!this.created) {
|
|
4608
|
+
return;
|
|
4609
|
+
}
|
|
4513
4610
|
const vaultId = await this.ensureInitialized();
|
|
4514
4611
|
console.info(`[Vault] ${vaultId} deleted. All credentials have been deleted.`);
|
|
4515
4612
|
await this.delete();
|
|
@@ -5085,7 +5182,7 @@ var FUNCTION_RUN_ENDPOINTS = {
|
|
|
5085
5182
|
start: "/functions/{function_id}/runs/{run_id}"
|
|
5086
5183
|
};
|
|
5087
5184
|
var RUN_API_KEY_HEADER = "x-notte-api-key";
|
|
5088
|
-
var FUNCTION_RUN_STATUSES = ["closed", "active", "failed"];
|
|
5185
|
+
var FUNCTION_RUN_STATUSES = ["closed", "active", "failed", "rejected"];
|
|
5089
5186
|
var NotteFunction = class {
|
|
5090
5187
|
client;
|
|
5091
5188
|
_functionId = null;
|
|
@@ -5404,13 +5501,15 @@ var NotteFunction = class {
|
|
|
5404
5501
|
* to execute a record returned by `createRun()`; otherwise a new run record
|
|
5405
5502
|
* is created first, exactly like Python. Pass `version` to run a saved
|
|
5406
5503
|
* version instead of the latest one. A failed execution throws
|
|
5407
|
-
* `FailedToRunCloudFunctionError`
|
|
5408
|
-
*
|
|
5504
|
+
* `FailedToRunCloudFunctionError` and a rejected one (the function raised an
|
|
5505
|
+
* `ExpectedFunctionError`) its subclass `FunctionRunRejectedError`, unless
|
|
5506
|
+
* `raiseOnFailure` is false; the wait is aborted with `NotteTimeoutError` after `timeoutMs`.
|
|
5409
5507
|
*
|
|
5410
5508
|
* @param variables - JSON-serializable keyword arguments passed to the Python function's `run` entry point.
|
|
5411
5509
|
* @param options - Log streaming, failure handling, runtime, run ID, version, and timeout settings.
|
|
5412
5510
|
* @returns The completed execution response. The function's return value is in `result`. Disabling streaming still waits for completion.
|
|
5413
5511
|
* @throws FailedToRunCloudFunctionError if execution fails and `raiseOnFailure` is true.
|
|
5512
|
+
* @throws FunctionRunRejectedError if the run is rejected and `raiseOnFailure` is true.
|
|
5414
5513
|
* @throws NotteTimeoutError if the execution request exceeds `timeoutMs`.
|
|
5415
5514
|
* @throws InvalidRequestError if the run options are invalid.
|
|
5416
5515
|
* @example
|
|
@@ -5463,6 +5562,9 @@ var NotteFunction = class {
|
|
|
5463
5562
|
signal: controller.signal
|
|
5464
5563
|
});
|
|
5465
5564
|
const result = stream ? await readFunctionStream(raw, options.onLog ?? console.log, endpointPath, controller.signal) : parseFunctionRunResult(raw, endpointPath);
|
|
5565
|
+
if (result.status === "rejected" && (options.raiseOnFailure ?? true)) {
|
|
5566
|
+
throw new FunctionRunRejectedError(functionId, result.function_run_id, result);
|
|
5567
|
+
}
|
|
5466
5568
|
if (result.status === "failed" && (options.raiseOnFailure ?? true)) {
|
|
5467
5569
|
throw new FailedToRunCloudFunctionError(functionId, result.function_run_id, result);
|
|
5468
5570
|
}
|
|
@@ -5615,12 +5717,15 @@ function parseFunctionRunResult(value, path) {
|
|
|
5615
5717
|
if (typeof candidate.function_run_id !== "string" || typeof candidate.function_id !== "string" || typeof status !== "string" || !FUNCTION_RUN_STATUSES.includes(status) || !("result" in candidate)) {
|
|
5616
5718
|
throw new NotteError("Invalid function result: missing function_id, function_run_id, status or result");
|
|
5617
5719
|
}
|
|
5720
|
+
const error = candidate.error;
|
|
5618
5721
|
return {
|
|
5619
5722
|
function_id: candidate.function_id,
|
|
5620
5723
|
function_run_id: candidate.function_run_id,
|
|
5621
5724
|
session_id: typeof candidate.session_id === "string" ? candidate.session_id : null,
|
|
5622
5725
|
result: candidate.result,
|
|
5623
|
-
status
|
|
5726
|
+
status,
|
|
5727
|
+
// Kept as the API sent it; absent when the run reported no typed error.
|
|
5728
|
+
...typeof error === "object" && error !== null && !Array.isArray(error) ? { error } : {}
|
|
5624
5729
|
};
|
|
5625
5730
|
}
|
|
5626
5731
|
async function readFunctionStream(body, onLog, path, signal) {
|
|
@@ -6192,6 +6297,12 @@ var EXECUTION_ERROR_CLASS = "NotteApiExecutionError";
|
|
|
6192
6297
|
function isRelativeProxyUrl(baseUrl) {
|
|
6193
6298
|
return /^\/(?!\/)/.test(baseUrl);
|
|
6194
6299
|
}
|
|
6300
|
+
function isFunctionsRequest(requestUrl, baseUrl) {
|
|
6301
|
+
const url = new URL(requestUrl);
|
|
6302
|
+
const api = new URL(baseUrl, url);
|
|
6303
|
+
const prefix = `${api.pathname.replace(/\/$/, "")}/functions`;
|
|
6304
|
+
return url.origin === api.origin && (url.pathname === prefix || url.pathname.startsWith(`${prefix}/`));
|
|
6305
|
+
}
|
|
6195
6306
|
var NotteClient3 = class {
|
|
6196
6307
|
config;
|
|
6197
6308
|
client = createClient();
|
|
@@ -6250,6 +6361,9 @@ var NotteClient3 = class {
|
|
|
6250
6361
|
headers.set("x-notte-request-origin", REQUEST_ORIGIN);
|
|
6251
6362
|
headers.set("x-notte-sdk-version", SDK_VERSION);
|
|
6252
6363
|
if (this.config.dbPreview) headers.set(DB_PREVIEW_HEADER, this.config.dbPreview);
|
|
6364
|
+
if (!headers.has(ACCEPT_RUN_STATUSES_HEADER) && isFunctionsRequest(request.url, this.config.baseUrl)) {
|
|
6365
|
+
headers.set(ACCEPT_RUN_STATUSES_HEADER, "rejected");
|
|
6366
|
+
}
|
|
6253
6367
|
const override = headers.get(TIMEOUT_HEADER);
|
|
6254
6368
|
headers.delete(TIMEOUT_HEADER);
|
|
6255
6369
|
const retriesOverride = headers.get(MAX_RETRIES_HEADER);
|
|
@@ -6465,7 +6579,27 @@ var NotteClient3 = class {
|
|
|
6465
6579
|
list: async (options = {}) => {
|
|
6466
6580
|
const response = await listSessions({ client: this.getClient(), query: options });
|
|
6467
6581
|
return response.data?.items ?? [];
|
|
6468
|
-
}
|
|
6582
|
+
},
|
|
6583
|
+
/**
|
|
6584
|
+
* One page of the session's steps (`{ steps, next_cursor }`), from
|
|
6585
|
+
* `GET /sessions/{session_id}/steps`. Each step has the shape of an item of
|
|
6586
|
+
* `status().steps`. Pass `next_cursor` back as `cursor`, as is, for the next
|
|
6587
|
+
* page; it is `null` on the last page. A `NotteAPIError` with status 400 means
|
|
6588
|
+
* the cursor is no longer valid: restart from the first page (no `cursor`).
|
|
6589
|
+
*/
|
|
6590
|
+
steps: (sessionId, options = {}) => getSessionSteps(this, sessionId, options),
|
|
6591
|
+
/**
|
|
6592
|
+
* Every step of the session, following `next_cursor` page by page. A cursor
|
|
6593
|
+
* that is no longer valid stops the iteration with the 400 `NotteAPIError`,
|
|
6594
|
+
* after the steps already yielded; start a new iteration to read them again.
|
|
6595
|
+
*
|
|
6596
|
+
* ```ts
|
|
6597
|
+
* for await (const step of client.sessions.iterSteps(sessionId, { limit: 50 })) {
|
|
6598
|
+
* console.log(step);
|
|
6599
|
+
* }
|
|
6600
|
+
* ```
|
|
6601
|
+
*/
|
|
6602
|
+
iterSteps: (sessionId, options = {}) => iterSessionSteps(this, sessionId, options)
|
|
6469
6603
|
};
|
|
6470
6604
|
}
|
|
6471
6605
|
/** Client-bound vault API operations. `list()` retains its array return value. */
|
|
@@ -6709,6 +6843,7 @@ var createClient2 = (config) => {
|
|
|
6709
6843
|
CAPTCHA_SOLVE_TIMEOUT_MS,
|
|
6710
6844
|
CLUSTER_OVERLOAD_RETRY_DELAY_MS,
|
|
6711
6845
|
CREDENTIAL_FIELDS,
|
|
6846
|
+
CaptchaRejectedError,
|
|
6712
6847
|
DEFAULT_MAX_RETRIES,
|
|
6713
6848
|
DEFAULT_NOTTE_API_URL,
|
|
6714
6849
|
DEFAULT_REQUEST_TIMEOUT_MS,
|
|
@@ -6720,6 +6855,7 @@ var createClient2 = (config) => {
|
|
|
6720
6855
|
FetchResponseDecodeError,
|
|
6721
6856
|
FileExistsError,
|
|
6722
6857
|
FileNotFoundError,
|
|
6858
|
+
FunctionRunRejectedError,
|
|
6723
6859
|
InvalidRequestError,
|
|
6724
6860
|
ManagedAuthError,
|
|
6725
6861
|
NotteAPIError,
|
|
@@ -6895,6 +7031,7 @@ var createClient2 = (config) => {
|
|
|
6895
7031
|
sessionResume,
|
|
6896
7032
|
sessionStart,
|
|
6897
7033
|
sessionStatus,
|
|
7034
|
+
sessionSteps,
|
|
6898
7035
|
sessionStop,
|
|
6899
7036
|
startVersionCheck,
|
|
6900
7037
|
storeSecret,
|