apify-client 3.0.0-beta.10 → 3.0.0-beta.12

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.
@@ -67,8 +67,7 @@ export declare class ActorClient extends ResourceClient {
67
67
  * asynchronously and this method returns immediately without waiting for completion.
68
68
  * Use the {@link call} method if you want to wait for the Actor to finish.
69
69
  *
70
- * @param input - Input for the Actor. Can be any JSON-serializable value (object, array, string, number).
71
- * If `contentType` is specified in options, input should be a string or Buffer.
70
+ * @param input - Input for the Actor, serialized to JSON. Omit it to run the Actor without input.
72
71
  * @param options - Run configuration options
73
72
  * @param options.build - Tag or number of the build to run (e.g., `'beta'` or `'1.2.345'`). If not provided, uses the default build.
74
73
  * @param options.memory - Memory in megabytes allocated for the run. If not provided, uses the Actor's default memory setting.
@@ -77,7 +76,6 @@ export declare class ActorClient extends ResourceClient {
77
76
  * @param options.webhooks - Webhooks to trigger when the Actor run reaches a specific state (e.g., `SUCCEEDED`, `FAILED`).
78
77
  * @param options.maxItems - Maximum number of dataset items that will be charged (only for pay-per-result Actors).
79
78
  * @param options.maxTotalChargeUsd - Maximum cost in USD (only for pay-per-event Actors).
80
- * @param options.contentType - Content type of the input. If specified, input must be a string or Buffer.
81
79
  * @returns The Actor run object with status, usage, and storage IDs
82
80
  * @see https://docs.apify.com/api/v2/act-runs-post
83
81
  *
@@ -94,7 +92,7 @@ export declare class ActorClient extends ResourceClient {
94
92
  * );
95
93
  * ```
96
94
  */
97
- start(input?: unknown, options?: ActorStartOptions): Promise<ActorRun>;
95
+ start(input?: ActorInput, options?: ActorStartOptions): Promise<ActorRun>;
98
96
  /**
99
97
  * Starts the Actor and waits for it to finish before returning the Run object.
100
98
  *
@@ -102,8 +100,7 @@ export declare class ActorClient extends ResourceClient {
102
100
  * by polling the run status. It optionally streams logs to the console or a custom Log instance.
103
101
  * By default, it waits indefinitely unless the `waitSecs` option is provided.
104
102
  *
105
- * @param input - Input for the Actor. Can be any JSON-serializable value (object, array, string, number).
106
- * If `contentType` is specified in options, input should be a string or Buffer.
103
+ * @param input - Input for the Actor, serialized to JSON. Omit it to run the Actor without input.
107
104
  * @param options - Run configuration options (extends all options from {@link start})
108
105
  * @param options.waitSecs - Maximum time to wait for the run to finish, in seconds. If omitted, waits indefinitely.
109
106
  * @param options.log - Log instance for streaming run logs. Use `'default'` for console output, `null` to disable logging, or provide a custom Log instance.
@@ -132,7 +129,7 @@ export declare class ActorClient extends ResourceClient {
132
129
  * const run = await client.actor('my-actor').call({ url: 'https://example.com' }, { log });
133
130
  * ```
134
131
  */
135
- call(input?: unknown, options?: ActorCallOptions): Promise<ActorRun>;
132
+ call(input?: ActorInput, options?: ActorCallOptions): Promise<ActorRun>;
136
133
  /**
137
134
  * Validates the provided input for the Actor against its input schema.
138
135
  *
@@ -141,13 +138,10 @@ export declare class ActorClient extends ResourceClient {
141
138
  * invalid, the API responds with an error that is thrown as an `ApifyApiError` describing the
142
139
  * validation problem.
143
140
  *
144
- * @param input - Input to validate against the Actor's input schema. Can be any JSON-serializable
145
- * value (object, array, string, number). If `contentType` is specified in options,
146
- * input should be a string or Buffer.
141
+ * @param input - Input to validate against the Actor's input schema, serialized to JSON.
147
142
  * @param options - Validation options
148
143
  * @param options.build - Tag or number of the build whose input schema the input is validated against
149
144
  * (e.g., `'latest'` or `'1.2.345'`). If not provided, uses the default build.
150
- * @param options.contentType - Content type of the input. If specified, input must be a string or Buffer.
151
145
  * @returns `true` if the input is valid. Invalid input causes the underlying API call to throw an `ApifyApiError`.
152
146
  * @see https://docs.apify.com/api/v2/act-validate-input-post
153
147
  *
@@ -164,7 +158,7 @@ export declare class ActorClient extends ResourceClient {
164
158
  * ```
165
159
  * @since Added in 2.24.0
166
160
  */
167
- validateInput(input?: unknown, options?: ActorValidateInputOptions): Promise<boolean>;
161
+ validateInput(input?: ActorInput, options?: ActorValidateInputOptions): Promise<boolean>;
168
162
  /**
169
163
  * Builds the Actor.
170
164
  *
@@ -280,6 +274,14 @@ export declare class ActorClient extends ResourceClient {
280
274
  * Fields that can be updated when modifying an Actor.
281
275
  */
282
276
  export type ActorUpdateOptions = Partial<Pick<Actor, 'name' | 'description' | 'isPublic' | 'isDeprecated' | 'seoTitle' | 'seoDescription' | 'title' | 'restartOnError' | 'versions' | 'categories' | 'defaultRunOptions' | 'actorStandby' | 'actorPermissionLevel' | 'taggedBuilds'>>;
277
+ /**
278
+ * Input for an Actor run, as taken by {@link ActorClient.start}, {@link ActorClient.call},
279
+ * {@link ActorClient.validateInput} and {@link RunClient.metamorph}.
280
+ *
281
+ * An object or an array. Declared as `object` rather than an index-signature type such as
282
+ * `Dictionary`, which would reject a caller's own `interface`.
283
+ */
284
+ export type ActorInput = object;
283
285
  export interface ActorStartOptions {
284
286
  /**
285
287
  * Tag or number of the Actor build to run (e.g. `beta` or `1.2.345`).
@@ -287,10 +289,9 @@ export interface ActorStartOptions {
287
289
  */
288
290
  build?: string;
289
291
  /**
290
- * Content type for the `input`. If not specified,
291
- * `input` is expected to be an object that will be stringified to JSON and content type set to
292
- * `application/json; charset=utf-8`. If `options.contentType` is specified, then `input` must be a
293
- * `String` or `Buffer`.
292
+ * Content type of the request body, which becomes the content type of the run's `INPUT` record.
293
+ * Without it, an input is serialized to JSON and sent as `application/json`. Pairing an object
294
+ * with `application/x-www-form-urlencoded` form-encodes it instead.
294
295
  */
295
296
  contentType?: string;
296
297
  /**
@@ -376,10 +377,9 @@ export interface ActorValidateInputOptions {
376
377
  */
377
378
  build?: string;
378
379
  /**
379
- * Content type for the `input`. If not specified,
380
- * `input` is expected to be an object that will be stringified to JSON and content type set to
381
- * `application/json; charset=utf-8`. If `options.contentType` is specified, then `input` must be a
382
- * `String` or `Buffer`.
380
+ * Content type of the request body carrying the input to validate. Without it, the input is
381
+ * serialized to JSON and sent as `application/json`. Pairing an object with
382
+ * `application/x-www-form-urlencoded` form-encodes it instead.
383
383
  */
384
384
  contentType?: string;
385
385
  }
@@ -40,7 +40,7 @@ const validateInputOptionsSchema = z.strictObject({
40
40
  build: z.string().optional(),
41
41
  contentType: z.string().optional(),
42
42
  });
43
- const versionNumberSchema = z.string();
43
+ const versionNumberSchema = z.string().min(1);
44
44
  const buildOptionsSchema = z.strictObject({
45
45
  betaPackages: z.boolean().optional(),
46
46
  tag: z.string().optional(),
@@ -116,8 +116,7 @@ export class ActorClient extends ResourceClient {
116
116
  * asynchronously and this method returns immediately without waiting for completion.
117
117
  * Use the {@link call} method if you want to wait for the Actor to finish.
118
118
  *
119
- * @param input - Input for the Actor. Can be any JSON-serializable value (object, array, string, number).
120
- * If `contentType` is specified in options, input should be a string or Buffer.
119
+ * @param input - Input for the Actor, serialized to JSON. Omit it to run the Actor without input.
121
120
  * @param options - Run configuration options
122
121
  * @param options.build - Tag or number of the build to run (e.g., `'beta'` or `'1.2.345'`). If not provided, uses the default build.
123
122
  * @param options.memory - Memory in megabytes allocated for the run. If not provided, uses the Actor's default memory setting.
@@ -126,7 +125,6 @@ export class ActorClient extends ResourceClient {
126
125
  * @param options.webhooks - Webhooks to trigger when the Actor run reaches a specific state (e.g., `SUCCEEDED`, `FAILED`).
127
126
  * @param options.maxItems - Maximum number of dataset items that will be charged (only for pay-per-result Actors).
128
127
  * @param options.maxTotalChargeUsd - Maximum cost in USD (only for pay-per-event Actors).
129
- * @param options.contentType - Content type of the input. If specified, input must be a string or Buffer.
130
128
  * @returns The Actor run object with status, usage, and storage IDs
131
129
  * @see https://docs.apify.com/api/v2/act-runs-post
132
130
  *
@@ -144,8 +142,6 @@ export class ActorClient extends ResourceClient {
144
142
  * ```
145
143
  */
146
144
  async start(input, options = {}) {
147
- // input can be anything, so no point in validating it. E.g. if you set content-type to application/pdf
148
- // then it will process input as a buffer.
149
145
  const parsed = parseArgument(options, startOptionsSchema, 'ActorStartOptions');
150
146
  const { waitForFinish, timeout, memory, build, maxItems, maxTotalChargeUsd, restartOnError, forcePermissionLevel, } = parsed;
151
147
  const params = {
@@ -183,8 +179,7 @@ export class ActorClient extends ResourceClient {
183
179
  * by polling the run status. It optionally streams logs to the console or a custom Log instance.
184
180
  * By default, it waits indefinitely unless the `waitSecs` option is provided.
185
181
  *
186
- * @param input - Input for the Actor. Can be any JSON-serializable value (object, array, string, number).
187
- * If `contentType` is specified in options, input should be a string or Buffer.
182
+ * @param input - Input for the Actor, serialized to JSON. Omit it to run the Actor without input.
188
183
  * @param options - Run configuration options (extends all options from {@link start})
189
184
  * @param options.waitSecs - Maximum time to wait for the run to finish, in seconds. If omitted, waits indefinitely.
190
185
  * @param options.log - Log instance for streaming run logs. Use `'default'` for console output, `null` to disable logging, or provide a custom Log instance.
@@ -214,8 +209,6 @@ export class ActorClient extends ResourceClient {
214
209
  * ```
215
210
  */
216
211
  async call(input, options = {}) {
217
- // input can be anything, so no point in validating it. E.g. if you set content-type to application/pdf
218
- // then it will process input as a buffer.
219
212
  const parsed = parseArgument(options, callOptionsSchema, 'ActorCallOptions');
220
213
  const { waitSecs, log, ...startOptions } = parsed;
221
214
  const { id } = await this.start(input, startOptions);
@@ -240,13 +233,10 @@ export class ActorClient extends ResourceClient {
240
233
  * invalid, the API responds with an error that is thrown as an `ApifyApiError` describing the
241
234
  * validation problem.
242
235
  *
243
- * @param input - Input to validate against the Actor's input schema. Can be any JSON-serializable
244
- * value (object, array, string, number). If `contentType` is specified in options,
245
- * input should be a string or Buffer.
236
+ * @param input - Input to validate against the Actor's input schema, serialized to JSON.
246
237
  * @param options - Validation options
247
238
  * @param options.build - Tag or number of the build whose input schema the input is validated against
248
239
  * (e.g., `'latest'` or `'1.2.345'`). If not provided, uses the default build.
249
- * @param options.contentType - Content type of the input. If specified, input must be a string or Buffer.
250
240
  * @returns `true` if the input is valid. Invalid input causes the underlying API call to throw an `ApifyApiError`.
251
241
  * @see https://docs.apify.com/api/v2/act-validate-input-post
252
242
  *
@@ -264,8 +254,6 @@ export class ActorClient extends ResourceClient {
264
254
  * @since Added in 2.24.0
265
255
  */
266
256
  async validateInput(input, options = {}) {
267
- // input can be anything, so no point in validating it. E.g. if you set content-type to application/pdf
268
- // then it will process input as a buffer.
269
257
  const parsed = parseArgument(options, validateInputOptionsSchema, 'ActorValidateInputOptions');
270
258
  const request = {
271
259
  url: this._url('validate-input'),
@@ -4,7 +4,7 @@ import * as schemas from '../schemas.js';
4
4
  import { anyObjectSchema, parseArgument } from '../utils.js';
5
5
  import { ActorEnvVarClient } from './actor_env_var.js';
6
6
  import { ActorEnvVarCollectionClient } from './actor_env_var_collection.js';
7
- const envVarNameSchema = z.string();
7
+ const envVarNameSchema = z.string().min(1);
8
8
  export { ActorSourceType } from '../models.js';
9
9
  /**
10
10
  * Client for managing a specific Actor version.
@@ -113,6 +113,8 @@ export declare class BuildClient extends ResourceClient {
113
113
  /**
114
114
  * Returns a client for accessing the log of this Actor build.
115
115
  *
116
+ * A 404 from this client throws an `ApifyApiError`, since the build itself may be what is missing.
117
+ *
116
118
  * @returns A client for accessing the build's log
117
119
  * @see https://docs.apify.com/api/v2/actor-build-log-get
118
120
  *
@@ -142,6 +142,8 @@ export class BuildClient extends ResourceClient {
142
142
  /**
143
143
  * Returns a client for accessing the log of this Actor build.
144
144
  *
145
+ * A 404 from this client throws an `ApifyApiError`, since the build itself may be what is missing.
146
+ *
145
147
  * @returns A client for accessing the build's log
146
148
  * @see https://docs.apify.com/api/v2/actor-build-log-get
147
149
  *
@@ -184,11 +184,11 @@ export declare class DatasetClient<Data extends Record<string | number, any> = R
184
184
  * Returns statistics for each field in the dataset, including information about
185
185
  * data types, null counts, and value ranges.
186
186
  *
187
- * @returns Dataset statistics, or `undefined` if not available
187
+ * @returns Dataset statistics
188
188
  * @see https://docs.apify.com/api/v2/dataset-statistics-get
189
189
  * @since Added in 2.11.2
190
190
  */
191
- getStatistics(): Promise<DatasetStatistics | undefined>;
191
+ getStatistics(): Promise<DatasetStatistics>;
192
192
  /**
193
193
  * Generates a public URL for accessing dataset items.
194
194
  *
@@ -2,7 +2,7 @@ import { z } from 'zod';
2
2
  import { createStorageContentSignatureAsync } from '@apify/utilities';
3
3
  import { DEFAULT_TIMEOUT_MILLIS, MEDIUM_TIMEOUT_MILLIS, ResourceClient, SMALL_TIMEOUT_MILLIS, } from '../base/resource_client.js';
4
4
  import * as schemas from '../schemas.js';
5
- import { anyObjectSchema, applyQueryParamsToUrl, cast, catchNotFoundOrThrow, isNonArrayObject, paginationOptionsShape, parseArgument, parseResponse, } from '../utils.js';
5
+ import { anyObjectSchema, applyQueryParamsToUrl, cast, isNonArrayObject, paginationOptionsShape, parseArgument, parseResponse, } from '../utils.js';
6
6
  // A predicate, not a `z.object()` arm, which would walk and copy every key of every pushed item.
7
7
  const itemSchema = z.custom(isNonArrayObject, 'Expected an object');
8
8
  const listItemsOptionsSchema = z.strictObject({
@@ -288,25 +288,18 @@ export class DatasetClient extends ResourceClient {
288
288
  * Returns statistics for each field in the dataset, including information about
289
289
  * data types, null counts, and value ranges.
290
290
  *
291
- * @returns Dataset statistics, or `undefined` if not available
291
+ * @returns Dataset statistics
292
292
  * @see https://docs.apify.com/api/v2/dataset-statistics-get
293
293
  * @since Added in 2.11.2
294
294
  */
295
295
  async getStatistics() {
296
- const requestOpts = {
296
+ const response = await this.httpClient.call({
297
297
  url: this._url('statistics'),
298
298
  method: 'GET',
299
299
  params: this._params(),
300
300
  timeout: SMALL_TIMEOUT_MILLIS,
301
- };
302
- try {
303
- const response = await this.httpClient.call(requestOpts);
304
- return parseResponse(response, schemas.DatasetStatistics());
305
- }
306
- catch (err) {
307
- catchNotFoundOrThrow(err);
308
- }
309
- return undefined;
301
+ });
302
+ return parseResponse(response, schemas.DatasetStatistics());
310
303
  }
311
304
  /**
312
305
  * Generates a public URL for accessing dataset items.
@@ -35,7 +35,8 @@ export declare class LogClient extends ResourceClient {
35
35
  *
36
36
  * @param options - Log retrieval options.
37
37
  * @param options.raw - If `true`, returns raw log content without any processing. Default is `false`.
38
- * @returns The log content as a string, or `undefined` if it does not exist.
38
+ * @returns The log content as a string, or `undefined` if it does not exist. A chained client such as
39
+ * `run.log()` throws an `ApifyApiError` on a 404, since the run itself may be what is missing.
39
40
  * @see https://docs.apify.com/api/v2/log-get
40
41
  */
41
42
  get(options?: LogOptions): Promise<string | undefined>;
@@ -44,7 +45,8 @@ export declare class LogClient extends ResourceClient {
44
45
  *
45
46
  * @param options - Log retrieval options.
46
47
  * @param options.raw - If `true`, returns raw log content without any processing. Default is `false`.
47
- * @returns The log content as a Readable stream, or `undefined` if it does not exist.
48
+ * @returns The log content as a Readable stream, or `undefined` if it does not exist. A chained client such as
49
+ * `run.log()` throws an `ApifyApiError` on a 404, since the run itself may be what is missing.
48
50
  * @see https://docs.apify.com/api/v2/log-get
49
51
  */
50
52
  stream(options?: LogOptions): Promise<Readable | undefined>;
@@ -1,7 +1,7 @@
1
1
  import c from 'ansi-colors';
2
2
  import log, { Logger, LogLevel } from '@apify/log';
3
3
  import { ResourceClient } from '../base/resource_client.js';
4
- import { cast, catchNotFoundOrThrow } from '../utils.js';
4
+ import { cast, catchNotFoundForResourceOrThrow } from '../utils.js';
5
5
  /**
6
6
  * Client for accessing Actor run or build logs.
7
7
  *
@@ -39,7 +39,8 @@ export class LogClient extends ResourceClient {
39
39
  *
40
40
  * @param options - Log retrieval options.
41
41
  * @param options.raw - If `true`, returns raw log content without any processing. Default is `false`.
42
- * @returns The log content as a string, or `undefined` if it does not exist.
42
+ * @returns The log content as a string, or `undefined` if it does not exist. A chained client such as
43
+ * `run.log()` throws an `ApifyApiError` on a 404, since the run itself may be what is missing.
43
44
  * @see https://docs.apify.com/api/v2/log-get
44
45
  */
45
46
  async get(options = {}) {
@@ -53,7 +54,7 @@ export class LogClient extends ResourceClient {
53
54
  return cast(response.data);
54
55
  }
55
56
  catch (err) {
56
- catchNotFoundOrThrow(err);
57
+ catchNotFoundForResourceOrThrow(err, this.id);
57
58
  }
58
59
  return undefined;
59
60
  }
@@ -62,7 +63,8 @@ export class LogClient extends ResourceClient {
62
63
  *
63
64
  * @param options - Log retrieval options.
64
65
  * @param options.raw - If `true`, returns raw log content without any processing. Default is `false`.
65
- * @returns The log content as a Readable stream, or `undefined` if it does not exist.
66
+ * @returns The log content as a Readable stream, or `undefined` if it does not exist. A chained client such as
67
+ * `run.log()` throws an `ApifyApiError` on a 404, since the run itself may be what is missing.
66
68
  * @see https://docs.apify.com/api/v2/log-get
67
69
  */
68
70
  async stream(options = {}) {
@@ -81,7 +83,7 @@ export class LogClient extends ResourceClient {
81
83
  return cast(response.data);
82
84
  }
83
85
  catch (err) {
84
- catchNotFoundOrThrow(err);
86
+ catchNotFoundForResourceOrThrow(err, this.id);
85
87
  }
86
88
  return undefined;
87
89
  }
@@ -166,11 +168,11 @@ export class StreamedLog {
166
168
  * Get log stream from response and redirect it to another log.
167
169
  */
168
170
  async streamLog() {
169
- const logStream = await this.logClient.stream({ raw: true });
170
- if (!logStream) {
171
- return;
172
- }
173
171
  try {
172
+ const logStream = await this.logClient.stream({ raw: true });
173
+ if (!logStream) {
174
+ return;
175
+ }
174
176
  const lastChunkRemainder = await this.logStreamChunks(logStream);
175
177
  // Process whatever is left when exiting. Maybe it is incomplete, maybe it is last log without EOL.
176
178
  const lastMessage = Buffer.from(lastChunkRemainder).toString().trim();
@@ -3,7 +3,7 @@ import { Log } from '@apify/log';
3
3
  import type { ApiClientOptionsWithOptionalResourcePath } from '../base/api_client.js';
4
4
  import { ResourceClient } from '../base/resource_client.js';
5
5
  import type { ApifyResponse } from '../http_client.js';
6
- import type { ActorRun } from './actor.js';
6
+ import type { ActorInput, ActorRun } from './actor.js';
7
7
  import { DatasetClient } from './dataset.js';
8
8
  import { KeyValueStoreClient } from './key_value_store.js';
9
9
  import { LogClient, StreamedLog } from './log.js';
@@ -88,10 +88,9 @@ export declare class RunClient extends ResourceClient {
88
88
  * This is useful for chaining Actor executions or implementing complex workflows.
89
89
  *
90
90
  * @param targetActorId - ID or username/name of the target Actor
91
- * @param input - Input for the target Actor. Can be any JSON-serializable value.
91
+ * @param input - Input for the target Actor, serialized to JSON. Omit it to metamorph without input.
92
92
  * @param options - Metamorph options
93
93
  * @param options.build - Tag or number of the target Actor's build to run. Default is the target Actor's default build.
94
- * @param options.contentType - Content type of the input. If specified, input must be a string or Buffer.
95
94
  * @returns The metamorphed ActorRun object (same ID, but now running the target Actor)
96
95
  * @see https://docs.apify.com/api/v2/actor-run-metamorph-post
97
96
  *
@@ -105,7 +104,7 @@ export declare class RunClient extends ResourceClient {
105
104
  * console.log(`Run ${metamorphedRun.id} is now running ${metamorphedRun.actId}`);
106
105
  * ```
107
106
  */
108
- metamorph(targetActorId: string, input: unknown, options?: RunMetamorphOptions): Promise<ActorRun>;
107
+ metamorph(targetActorId: string, input?: ActorInput, options?: RunMetamorphOptions): Promise<ActorRun>;
109
108
  /**
110
109
  * Reboots the Actor run.
111
110
  *
@@ -210,6 +209,8 @@ export declare class RunClient extends ResourceClient {
210
209
  /**
211
210
  * Returns a client for the default dataset of this Actor run.
212
211
  *
212
+ * A 404 from this client throws an `ApifyApiError`, since the run itself may be what is missing.
213
+ *
213
214
  * @returns A client for accessing the run's default dataset
214
215
  * @see https://docs.apify.com/api/v2/actor-run-get
215
216
  *
@@ -223,6 +224,9 @@ export declare class RunClient extends ResourceClient {
223
224
  /**
224
225
  * Returns a client for the default key-value store of this Actor run.
225
226
  *
227
+ * `get()` and `delete()` throw an `ApifyApiError` on a 404, since the run itself may be what is missing. Record
228
+ * lookups such as `getRecord()` read a 404 as a missing record.
229
+ *
226
230
  * @returns A client for accessing the run's default key-value store
227
231
  * @see https://docs.apify.com/api/v2/actor-run-get
228
232
  *
@@ -236,6 +240,9 @@ export declare class RunClient extends ResourceClient {
236
240
  /**
237
241
  * Returns a client for the default Request queue of this Actor run.
238
242
  *
243
+ * `get()` and `delete()` throw an `ApifyApiError` on a 404, since the run itself may be what is missing.
244
+ * `getRequest()` reads a 404 as a missing request.
245
+ *
239
246
  * @returns A client for accessing the run's default Request queue
240
247
  * @see https://docs.apify.com/api/v2/actor-run-get
241
248
  *
@@ -249,6 +256,8 @@ export declare class RunClient extends ResourceClient {
249
256
  /**
250
257
  * Returns a client for accessing the log of this Actor run.
251
258
  *
259
+ * A 404 from this client throws an `ApifyApiError`, since the run itself may be what is missing.
260
+ *
252
261
  * @returns A client for accessing the run's log
253
262
  * @see https://docs.apify.com/api/v2/actor-run-get
254
263
  *
@@ -290,6 +299,11 @@ export interface RunAbortOptions {
290
299
  * Options for metamorphing a Run into another Actor.
291
300
  */
292
301
  export interface RunMetamorphOptions {
302
+ /**
303
+ * Content type of the request body, which becomes the content type of the run's `INPUT` record.
304
+ * Without it, an input is serialized to JSON and sent as `application/json`. Pairing an object
305
+ * with `application/x-www-form-urlencoded` form-encodes it instead.
306
+ */
293
307
  contentType?: string;
294
308
  build?: string;
295
309
  }
@@ -127,10 +127,9 @@ export class RunClient extends ResourceClient {
127
127
  * This is useful for chaining Actor executions or implementing complex workflows.
128
128
  *
129
129
  * @param targetActorId - ID or username/name of the target Actor
130
- * @param input - Input for the target Actor. Can be any JSON-serializable value.
130
+ * @param input - Input for the target Actor, serialized to JSON. Omit it to metamorph without input.
131
131
  * @param options - Metamorph options
132
132
  * @param options.build - Tag or number of the target Actor's build to run. Default is the target Actor's default build.
133
- * @param options.contentType - Content type of the input. If specified, input must be a string or Buffer.
134
133
  * @returns The metamorphed ActorRun object (same ID, but now running the target Actor)
135
134
  * @see https://docs.apify.com/api/v2/actor-run-metamorph-post
136
135
  *
@@ -146,7 +145,6 @@ export class RunClient extends ResourceClient {
146
145
  */
147
146
  async metamorph(targetActorId, input, options = {}) {
148
147
  parseArgument(targetActorId, targetActorIdSchema);
149
- // input can be anything, pointless to validate
150
148
  const parsed = parseArgument(options, metamorphOptionsSchema, 'RunMetamorphOptions');
151
149
  const safeTargetActorId = this._toSafeId(targetActorId);
152
150
  const params = {
@@ -315,6 +313,8 @@ export class RunClient extends ResourceClient {
315
313
  /**
316
314
  * Returns a client for the default dataset of this Actor run.
317
315
  *
316
+ * A 404 from this client throws an `ApifyApiError`, since the run itself may be what is missing.
317
+ *
318
318
  * @returns A client for accessing the run's default dataset
319
319
  * @see https://docs.apify.com/api/v2/actor-run-get
320
320
  *
@@ -332,6 +332,9 @@ export class RunClient extends ResourceClient {
332
332
  /**
333
333
  * Returns a client for the default key-value store of this Actor run.
334
334
  *
335
+ * `get()` and `delete()` throw an `ApifyApiError` on a 404, since the run itself may be what is missing. Record
336
+ * lookups such as `getRecord()` read a 404 as a missing record.
337
+ *
335
338
  * @returns A client for accessing the run's default key-value store
336
339
  * @see https://docs.apify.com/api/v2/actor-run-get
337
340
  *
@@ -349,6 +352,9 @@ export class RunClient extends ResourceClient {
349
352
  /**
350
353
  * Returns a client for the default Request queue of this Actor run.
351
354
  *
355
+ * `get()` and `delete()` throw an `ApifyApiError` on a 404, since the run itself may be what is missing.
356
+ * `getRequest()` reads a 404 as a missing request.
357
+ *
352
358
  * @returns A client for accessing the run's default Request queue
353
359
  * @see https://docs.apify.com/api/v2/actor-run-get
354
360
  *
@@ -366,6 +372,8 @@ export class RunClient extends ResourceClient {
366
372
  /**
367
373
  * Returns a client for accessing the log of this Actor run.
368
374
  *
375
+ * A 404 from this client throws an `ApifyApiError`, since the run itself may be what is missing.
376
+ *
369
377
  * @returns A client for accessing the run's log
370
378
  * @see https://docs.apify.com/api/v2/actor-run-get
371
379
  *
@@ -398,7 +406,8 @@ export class RunClient extends ResourceClient {
398
406
  const runData = await this.get();
399
407
  const runId = runData?.id ?? '';
400
408
  const actorId = runData?.actId ?? '';
401
- const actorData = (await this.apifyClient.actor(actorId).get()) || { name: '' };
409
+ // `apifyClient.actor()` rejects an empty ID, which is what a run that could not be read leaves here.
410
+ const actorData = actorId ? await this.apifyClient.actor(actorId).get() : undefined;
402
411
  const actorName = actorData?.name ?? '';
403
412
  const name = [actorName, `runId:${runId}`].filter(Boolean).join(' ');
404
413
  toLog = new Log({ level: LEVELS.DEBUG, prefix: `${name} -> `, logger: new LoggerActorRedirect() });
@@ -56,10 +56,10 @@ export declare class ScheduleClient extends ResourceClient {
56
56
  /**
57
57
  * Retrieves the schedule's log.
58
58
  *
59
- * @returns The schedule log, one entry per invocation, or `undefined` if the schedule does not exist.
59
+ * @returns The schedule log, one entry per invocation.
60
60
  * @see https://docs.apify.com/api/v2/schedule-log-get
61
61
  */
62
- getLog(): Promise<ScheduleInvoked[] | undefined>;
62
+ getLog(): Promise<ScheduleInvoked[]>;
63
63
  }
64
64
  /**
65
65
  * Data for creating or updating a Schedule.
@@ -1,7 +1,7 @@
1
1
  import { z } from 'zod';
2
2
  import { ResourceClient } from '../base/resource_client.js';
3
3
  import * as schemas from '../schemas.js';
4
- import { anyObjectSchema, catchNotFoundOrThrow, parseArgument, parseResponse } from '../utils.js';
4
+ import { anyObjectSchema, parseArgument, parseResponse } from '../utils.js';
5
5
  export { ScheduleActions } from '../models.js';
6
6
  const scheduleLogSchema = z.array(schemas.ScheduleInvoked());
7
7
  /**
@@ -68,22 +68,15 @@ export class ScheduleClient extends ResourceClient {
68
68
  /**
69
69
  * Retrieves the schedule's log.
70
70
  *
71
- * @returns The schedule log, one entry per invocation, or `undefined` if the schedule does not exist.
71
+ * @returns The schedule log, one entry per invocation.
72
72
  * @see https://docs.apify.com/api/v2/schedule-log-get
73
73
  */
74
74
  async getLog() {
75
- const requestOpts = {
75
+ const response = await this.httpClient.call({
76
76
  url: this._url('log'),
77
77
  method: 'GET',
78
78
  params: this._params(),
79
- };
80
- try {
81
- const response = await this.httpClient.call(requestOpts);
82
- return parseResponse(response, scheduleLogSchema);
83
- }
84
- catch (err) {
85
- catchNotFoundOrThrow(err);
86
- }
87
- return undefined;
79
+ });
80
+ return parseResponse(response, scheduleLogSchema);
88
81
  }
89
82
  }
@@ -117,10 +117,10 @@ export declare class TaskClient extends ResourceClient {
117
117
  /**
118
118
  * Retrieves the Actor task's input object.
119
119
  *
120
- * @returns The Task's input, or `undefined` if it does not exist.
120
+ * @returns The Task's input.
121
121
  * @see https://docs.apify.com/api/v2/actor-task-input-get
122
122
  */
123
- getInput(): Promise<Dictionary | Dictionary[] | undefined>;
123
+ getInput(): Promise<Dictionary | Dictionary[]>;
124
124
  /**
125
125
  * Updates the Actor task's input object.
126
126
  *
@@ -2,7 +2,7 @@ import { z } from 'zod';
2
2
  import { ACT_JOB_STATUSES, META_ORIGINS } from '@apify/consts';
3
3
  import { ResourceClient } from '../base/resource_client.js';
4
4
  import * as schemas from '../schemas.js';
5
- import { anyObjectSchema, cast, catchNotFoundOrThrow, parseArgument, parseResponse, stringifyWebhooksToBase64, } from '../utils.js';
5
+ import { anyObjectSchema, cast, parseArgument, parseResponse, stringifyWebhooksToBase64 } from '../utils.js';
6
6
  import { RunClient } from './run.js';
7
7
  import { RunCollectionClient } from './run_collection.js';
8
8
  import { WebhookCollectionClient } from './webhook_collection.js';
@@ -194,23 +194,16 @@ export class TaskClient extends ResourceClient {
194
194
  /**
195
195
  * Retrieves the Actor task's input object.
196
196
  *
197
- * @returns The Task's input, or `undefined` if it does not exist.
197
+ * @returns The Task's input.
198
198
  * @see https://docs.apify.com/api/v2/actor-task-input-get
199
199
  */
200
200
  async getInput() {
201
- const requestOpts = {
201
+ const response = await this.httpClient.call({
202
202
  url: this._url('input'),
203
203
  method: 'GET',
204
204
  params: this._params(),
205
- };
206
- try {
207
- const response = await this.httpClient.call(requestOpts);
208
- return cast(response.data);
209
- }
210
- catch (err) {
211
- catchNotFoundOrThrow(err);
212
- }
213
- return undefined;
205
+ });
206
+ return cast(response.data);
214
207
  }
215
208
  /**
216
209
  * Updates the Actor task's input object.
@@ -38,26 +38,26 @@ export declare class UserClient extends ResourceClient {
38
38
  * Depending on whether ApifyClient was created with a token,
39
39
  * the method will either return public or private user data.
40
40
  *
41
- * @returns The user object.
41
+ * @returns The user object, or `undefined` if it does not exist.
42
42
  * @see https://docs.apify.com/api/v2/user-get
43
43
  */
44
- get(): Promise<User>;
44
+ get(): Promise<User | undefined>;
45
45
  /**
46
46
  * Retrieves the user's monthly usage data.
47
47
  *
48
- * @returns The monthly usage object, or `undefined` if it does not exist.
48
+ * @returns The monthly usage object.
49
49
  * @see https://docs.apify.com/api/v2/users-me-usage-monthly-get
50
50
  * @since Added in 2.9.2
51
51
  */
52
- monthlyUsage(): Promise<MonthlyUsage | undefined>;
52
+ monthlyUsage(): Promise<MonthlyUsage>;
53
53
  /**
54
54
  * Retrieves the user's account and usage limits.
55
55
  *
56
- * @returns The account and usage limits object, or `undefined` if it does not exist.
56
+ * @returns The account and usage limits object.
57
57
  * @see https://docs.apify.com/api/v2/users-me-limits-get
58
58
  * @since Added in 2.9.2
59
59
  */
60
- limits(): Promise<AccountAndUsageLimits | undefined>;
60
+ limits(): Promise<AccountAndUsageLimits>;
61
61
  /**
62
62
  * Updates the user's account and usage limits.
63
63
  *