apify-client 3.0.0-beta.5 → 3.0.0-beta.7

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.
@@ -167,7 +167,7 @@ export class HttpClient {
167
167
  if (response.status === RATE_LIMIT_EXCEEDED_STATUS_CODE) {
168
168
  this.stats.addRateLimitError(attempt);
169
169
  }
170
- const apiError = new ApifyApiError(response, attempt);
170
+ const apiError = ApifyApiError.fromResponse(response, attempt);
171
171
  if (this._isStatusCodeRetryable(response.status)) {
172
172
  if (requestIsStream) {
173
173
  this._informAboutStreamNoRetry();
package/dist/models.d.ts CHANGED
@@ -48,6 +48,12 @@ export declare enum WebhookDispatchStatus {
48
48
  Succeeded = "SUCCEEDED",
49
49
  Failed = "FAILED"
50
50
  }
51
+ /**
52
+ * Machine-readable type of an error returned by the Apify API, carried by `ApifyApiError.type`.
53
+ *
54
+ * Declared here, next to the other spec-derived types, and re-exported from `./apify_api_error`.
55
+ */
56
+ export type ApifyApiErrorType = Schemas['ErrorType'];
51
57
  /**
52
58
  * Fields the API returns on a dataset that the OpenAPI spec does not describe yet.
53
59
  *
@@ -100,8 +100,6 @@ export interface ActorCollectionCreateOptions {
100
100
  isDeprecated?: boolean;
101
101
  isPublic?: boolean;
102
102
  name?: string;
103
- /** @deprecated Use defaultRunOptions.restartOnError instead */
104
- restartOnError?: boolean;
105
103
  /**
106
104
  * @since Added in 2.8.6
107
105
  */
@@ -1,6 +1,6 @@
1
1
  import type { ApiClientSubResourceOptions } from '../base/api_client.js';
2
2
  import { ResourceCollectionClient } from '../base/resource_collection_client.js';
3
- import type { PaginatedList, PaginationOptions } from '../utils.js';
3
+ import type { PaginatedList } from '../utils.js';
4
4
  import type { ActorEnvironmentVariable } from './actor_version.js';
5
5
  /**
6
6
  * Client for managing the collection of environment variables for an Actor version.
@@ -37,23 +37,22 @@ export declare class ActorEnvVarCollectionClient extends ResourceCollectionClien
37
37
  /**
38
38
  * Lists all environment variables of this Actor version.
39
39
  *
40
- * Awaiting the return value (as you would with a Promise) will result in a single API call. The amount of fetched
41
- * items in a single API call is limited.
40
+ * The endpoint returns every environment variable in one response, so awaiting the return value (as you would
41
+ * with a Promise) gets the whole list.
42
42
  * ```javascript
43
- * const paginatedList = await client.list();
44
- *```
43
+ * const { items } = await client.list();
44
+ * ```
45
45
  *
46
- * Asynchronous iteration is also supported. This will fetch additional pages if needed until all items are
47
- * retrieved.
46
+ * Asynchronous iteration is also supported, and yields the environment variables one by one.
48
47
  *
49
48
  * ```javascript
50
49
  * for await (const singleItem of client.list()) {...}
51
50
  * ```
52
51
  *
53
- * @returns A paginated iterator of environment variables.
52
+ * @returns The environment variables, awaitable as a whole list or iterable one by one.
54
53
  * @see https://docs.apify.com/api/v2/act-version-env-vars-get
55
54
  */
56
- list(_options?: ActorEnvVarCollectionListOptions): Promise<ActorEnvVarListResult> & AsyncIterable<ActorEnvironmentVariable>;
55
+ list(): Promise<ActorEnvVarListResult> & AsyncIterable<ActorEnvironmentVariable>;
57
56
  /**
58
57
  * Creates a new environment variable for this Actor version.
59
58
  *
@@ -63,14 +62,6 @@ export declare class ActorEnvVarCollectionClient extends ResourceCollectionClien
63
62
  */
64
63
  create(actorEnvVar: ActorEnvironmentVariable): Promise<ActorEnvironmentVariable>;
65
64
  }
66
- /**
67
- * @deprecated No options are used in the current API implementation.
68
- * https://github.com/apify/apify-client-js/issues/799
69
- * @since Added in 2.1.0
70
- */
71
- export interface ActorEnvVarCollectionListOptions extends PaginationOptions {
72
- desc?: boolean;
73
- }
74
65
  /**
75
66
  * @since Added in 2.1.0
76
67
  */
@@ -42,23 +42,22 @@ export class ActorEnvVarCollectionClient extends ResourceCollectionClient {
42
42
  /**
43
43
  * Lists all environment variables of this Actor version.
44
44
  *
45
- * Awaiting the return value (as you would with a Promise) will result in a single API call. The amount of fetched
46
- * items in a single API call is limited.
45
+ * The endpoint returns every environment variable in one response, so awaiting the return value (as you would
46
+ * with a Promise) gets the whole list.
47
47
  * ```javascript
48
- * const paginatedList = await client.list();
49
- *```
48
+ * const { items } = await client.list();
49
+ * ```
50
50
  *
51
- * Asynchronous iteration is also supported. This will fetch additional pages if needed until all items are
52
- * retrieved.
51
+ * Asynchronous iteration is also supported, and yields the environment variables one by one.
53
52
  *
54
53
  * ```javascript
55
54
  * for await (const singleItem of client.list()) {...}
56
55
  * ```
57
56
  *
58
- * @returns A paginated iterator of environment variables.
57
+ * @returns The environment variables, awaitable as a whole list or iterable one by one.
59
58
  * @see https://docs.apify.com/api/v2/act-version-env-vars-get
60
59
  */
61
- list(_options = {}) {
60
+ list() {
62
61
  return this._listPaginated(schemas.ListOfEnvVars());
63
62
  }
64
63
  /**
@@ -1,6 +1,6 @@
1
1
  import type { ApiClientSubResourceOptions } from '../base/api_client.js';
2
2
  import { ResourceCollectionClient } from '../base/resource_collection_client.js';
3
- import type { PaginatedList, PaginationOptions } from '../utils.js';
3
+ import type { PaginatedList } from '../utils.js';
4
4
  import type { ActorVersion, FinalActorVersion } from './actor_version.js';
5
5
  /**
6
6
  * Client for managing the collection of Actor versions.
@@ -34,23 +34,22 @@ export declare class ActorVersionCollectionClient extends ResourceCollectionClie
34
34
  /**
35
35
  * Lists all Actor versions.
36
36
  *
37
- * Awaiting the return value (as you would with a Promise) will result in a single API call. The amount of fetched
38
- * items in a single API call is limited.
37
+ * The endpoint returns every version in one response, so awaiting the return value (as you would with a Promise)
38
+ * gets the whole list.
39
39
  * ```javascript
40
- * const paginatedList = await client.list();
41
- *```
40
+ * const { items } = await client.list();
41
+ * ```
42
42
  *
43
- * Asynchronous iteration is also supported. This will fetch additional pages if needed until all items are
44
- * retrieved.
43
+ * Asynchronous iteration is also supported, and yields the versions one by one.
45
44
  *
46
45
  * ```javascript
47
46
  * for await (const singleItem of client.list()) {...}
48
47
  * ```
49
48
  *
50
- * @returns A paginated iterator of Actor versions.
49
+ * @returns The Actor versions, awaitable as a whole list or iterable one by one.
51
50
  * @see https://docs.apify.com/api/v2/act-versions-get
52
51
  */
53
- list(_options?: ActorVersionCollectionListOptions): Promise<ActorVersionListResult> & AsyncIterable<FinalActorVersion>;
52
+ list(): Promise<ActorVersionListResult> & AsyncIterable<FinalActorVersion>;
54
53
  /**
55
54
  * Creates a new Actor version.
56
55
  *
@@ -60,11 +59,4 @@ export declare class ActorVersionCollectionClient extends ResourceCollectionClie
60
59
  */
61
60
  create(actorVersion: ActorVersion): Promise<FinalActorVersion>;
62
61
  }
63
- /**
64
- * @deprecated No options are used in the current API implementation.
65
- * https://github.com/apify/apify-client-js/issues/799
66
- */
67
- export interface ActorVersionCollectionListOptions extends PaginationOptions {
68
- desc?: boolean;
69
- }
70
62
  export type ActorVersionListResult = Pick<PaginatedList<FinalActorVersion>, 'total' | 'items'>;
@@ -39,23 +39,22 @@ export class ActorVersionCollectionClient extends ResourceCollectionClient {
39
39
  /**
40
40
  * Lists all Actor versions.
41
41
  *
42
- * Awaiting the return value (as you would with a Promise) will result in a single API call. The amount of fetched
43
- * items in a single API call is limited.
42
+ * The endpoint returns every version in one response, so awaiting the return value (as you would with a Promise)
43
+ * gets the whole list.
44
44
  * ```javascript
45
- * const paginatedList = await client.list();
46
- *```
45
+ * const { items } = await client.list();
46
+ * ```
47
47
  *
48
- * Asynchronous iteration is also supported. This will fetch additional pages if needed until all items are
49
- * retrieved.
48
+ * Asynchronous iteration is also supported, and yields the versions one by one.
50
49
  *
51
50
  * ```javascript
52
51
  * for await (const singleItem of client.list()) {...}
53
52
  * ```
54
53
  *
55
- * @returns A paginated iterator of Actor versions.
54
+ * @returns The Actor versions, awaitable as a whole list or iterable one by one.
56
55
  * @see https://docs.apify.com/api/v2/act-versions-get
57
56
  */
58
- list(_options = {}) {
57
+ list() {
59
58
  return this._listPaginated(schemas.ListOfVersions());
60
59
  }
61
60
  /**
@@ -346,11 +346,6 @@ export type RequestQueueListRequestsFilter = 'locked' | 'pending';
346
346
  */
347
347
  export interface RequestQueueClientListRequestsOptions {
348
348
  limit?: number;
349
- /**
350
- * Using id of request that does not exist in request queue leads to unpredictable results.
351
- * @deprecated Use `cursor` for pagination instead.
352
- */
353
- exclusiveStartId?: string;
354
349
  /**
355
350
  * @since Added in 2.23.2
356
351
  */
@@ -367,8 +362,6 @@ export interface RequestQueueClientListRequestsOptions {
367
362
  export interface RequestQueueClientPaginateRequestsOptions {
368
363
  limit?: number;
369
364
  maxPageLimit?: number;
370
- /** @deprecated Use `cursor` for pagination instead. */
371
- exclusiveStartId?: string;
372
365
  /**
373
366
  * @since Added in 2.23.2
374
367
  */
@@ -4,7 +4,7 @@ import log from '@apify/log';
4
4
  import { MEDIUM_TIMEOUT_MILLIS, ResourceClient, SMALL_TIMEOUT_MILLIS } from '../base/resource_client.js';
5
5
  import { ResponseValidationError } from '../response_validation_error.js';
6
6
  import * as schemas from '../schemas.js';
7
- import { anyObjectSchema, cast, catchNotFoundOrThrow, isNonArrayObject, mutuallyExclusive, parseArgument, parseDateFields, parseResponse, RequestQueuePaginationIterator, sliceArrayByByteLength, } from '../utils.js';
7
+ import { anyObjectSchema, cast, catchNotFoundOrThrow, isNonArrayObject, parseArgument, parseDateFields, parseResponse, RequestQueuePaginationIterator, sliceArrayByByteLength, } from '../utils.js';
8
8
  const DEFAULT_PARALLEL_BATCH_ADD_REQUESTS = 5;
9
9
  const DEFAULT_UNPROCESSED_RETRIES_BATCH_ADD_REQUESTS = 3;
10
10
  const DEFAULT_MIN_DELAY_BETWEEN_UNPROCESSED_REQUESTS_RETRIES_MILLIS = 500;
@@ -35,23 +35,17 @@ const prolongRequestLockOptionsSchema = z.strictObject({
35
35
  forefront: z.boolean().optional(),
36
36
  });
37
37
  const requestFilterSchema = z.array(z.enum(['locked', 'pending'])).min(1);
38
- const listRequestsOptionsSchema = z
39
- .strictObject({
38
+ const listRequestsOptionsSchema = z.strictObject({
40
39
  limit: z.number().min(0).optional(),
41
- exclusiveStartId: z.string().optional(),
42
40
  cursor: z.string().optional(),
43
41
  filter: requestFilterSchema.optional(),
44
- })
45
- .refine(...mutuallyExclusive('exclusiveStartId', 'cursor'));
46
- const paginateRequestsOptionsSchema = z
47
- .strictObject({
42
+ });
43
+ const paginateRequestsOptionsSchema = z.strictObject({
48
44
  limit: z.number().min(0).optional(),
49
45
  maxPageLimit: z.number().default(DEFAULT_REQUEST_QUEUE_REQUEST_PAGE_LIMIT),
50
- exclusiveStartId: z.string().optional(),
51
46
  cursor: z.string().optional(),
52
47
  filter: requestFilterSchema.optional(),
53
- })
54
- .refine(...mutuallyExclusive('exclusiveStartId', 'cursor'));
48
+ });
55
49
  /**
56
50
  * Client for managing a specific Request queue.
57
51
  *
@@ -589,8 +583,6 @@ export class RequestQueueClient extends ResourceClient {
589
583
  const newOptions = {
590
584
  ...parsed,
591
585
  limit: remainingItems,
592
- // remove original exclusiveStartId, if there was any, and use cursor-based pagination
593
- exclusiveStartId: undefined,
594
586
  cursor: currentPage.nextCursor,
595
587
  };
596
588
  currentPage = await getPaginatedList(newOptions);
@@ -644,11 +636,10 @@ export class RequestQueueClient extends ResourceClient {
644
636
  * @since Added in 2.5.1
645
637
  */
646
638
  paginateRequests(options = {}) {
647
- const { limit, exclusiveStartId, cursor, filter, maxPageLimit } = parseArgument(options, paginateRequestsOptionsSchema, 'RequestQueueClientPaginateRequestsOptions');
639
+ const { limit, cursor, filter, maxPageLimit } = parseArgument(options, paginateRequestsOptionsSchema, 'RequestQueueClientPaginateRequestsOptions');
648
640
  return new RequestQueuePaginationIterator({
649
641
  getPage: async (pageOptions) => this.listRequests({ ...pageOptions, filter }),
650
642
  limit,
651
- exclusiveStartId,
652
643
  cursor,
653
644
  maxPageLimit,
654
645
  });
package/dist/utils.d.ts CHANGED
@@ -43,8 +43,7 @@ export declare function parseResponse<R>(response: ApifyResponse, schema: z.ZodT
43
43
  */
44
44
  export declare function pluckData<R>(obj: MaybeData<R>): R;
45
45
  /**
46
- * If given HTTP error has NOT_FOUND_STATUS_CODE status code then returns undefined.
47
- * Otherwise rethrows error.
46
+ * Swallows a 404 Not Found API error and rethrows anything else.
48
47
  */
49
48
  export declare function catchNotFoundOrThrow(err: ApifyApiError): void;
50
49
  type ReturnJsonValue = string | number | boolean | null | Date | ReturnJsonObject | ReturnJsonArray;
@@ -87,13 +86,12 @@ export declare function getVersionData(): {
87
86
  version: string;
88
87
  };
89
88
  /**
90
- * Helper class to create async iterators from paginated list endpoints with exclusive start key.
89
+ * Helper class to create async iterators from paginated list endpoints.
91
90
  */
92
91
  export declare class RequestQueuePaginationIterator {
93
92
  private readonly maxPageLimit;
94
93
  private readonly getPage;
95
94
  private readonly limit?;
96
- private readonly exclusiveStartId?;
97
95
  private readonly cursor?;
98
96
  constructor(options: RequestQueuePaginationIteratorOptions);
99
97
  [Symbol.asyncIterator](): AsyncIterator<RequestQueueClientListRequestsResult>;
@@ -109,7 +107,6 @@ export interface RequestQueuePaginationIteratorOptions {
109
107
  maxPageLimit: number;
110
108
  getPage: (opts: RequestQueueClientListRequestsOptions) => Promise<RequestQueueClientListRequestsResult>;
111
109
  limit?: number;
112
- exclusiveStartId?: string;
113
110
  cursor?: string;
114
111
  }
115
112
  /**
@@ -196,12 +193,6 @@ export type DistributiveOptional<T, K extends keyof T> = T extends any ? Omit<T,
196
193
  * Adds query parameters to a given URL based on the provided options object.
197
194
  */
198
195
  export declare function applyQueryParamsToUrl(url: URL, options?: Record<string, string | number | boolean | string[] | undefined>): URL;
199
- /**
200
- * Builds a `[check, message]` pair to spread into `.refine()`, asserting that at most one of `keys`
201
- * is present. Pass the options interface as `T`, so that a misspelled key is a type error.
202
- * @internal
203
- */
204
- export declare const mutuallyExclusive: <T extends object>(...keys: (keyof T & string)[]) => [(value: T) => boolean, string];
205
196
  /**
206
197
  * Percent-encodes a caller-supplied URL path segment so it cannot restructure the request path.
207
198
  *
package/dist/utils.js CHANGED
@@ -1,11 +1,9 @@
1
1
  import { z } from 'zod';
2
+ import { NotFoundError } from './apify_api_error.js';
2
3
  import { parseArgument } from '@apify/validations';
3
4
  import { ResponseValidationError } from './response_validation_error.js';
4
5
  // @ts-ignore if we enable `resolveJsonModule`, we end up with a `src` folder in `dist`
5
6
  import packageJson from '../package.json' with { type: 'json' };
6
- const NOT_FOUND_STATUS_CODE = 404;
7
- const RECORD_NOT_FOUND_TYPE = 'record-not-found';
8
- const RECORD_OR_TOKEN_NOT_FOUND_TYPE = 'record-or-token-not-found';
9
7
  const MIN_COMPRESS_BYTES = 1024;
10
8
  export { parseArgument };
11
9
  /**
@@ -58,14 +56,10 @@ export function pluckData(obj) {
58
56
  throw new Error(`Expected response object with a "data" property, but received: ${obj}`);
59
57
  }
60
58
  /**
61
- * If given HTTP error has NOT_FOUND_STATUS_CODE status code then returns undefined.
62
- * Otherwise rethrows error.
59
+ * Swallows a 404 Not Found API error and rethrows anything else.
63
60
  */
64
61
  export function catchNotFoundOrThrow(err) {
65
- const isNotFoundStatus = err.statusCode === NOT_FOUND_STATUS_CODE;
66
- const isNotFoundMessage = err.type === RECORD_NOT_FOUND_TYPE || err.type === RECORD_OR_TOKEN_NOT_FOUND_TYPE || err.httpMethod === 'head';
67
- const isNotFoundError = isNotFoundStatus && isNotFoundMessage;
68
- if (!isNotFoundError)
62
+ if (!(err instanceof NotFoundError))
69
63
  throw err;
70
64
  }
71
65
  /**
@@ -237,25 +231,21 @@ export function getVersionData() {
237
231
  return packageJson;
238
232
  }
239
233
  /**
240
- * Helper class to create async iterators from paginated list endpoints with exclusive start key.
234
+ * Helper class to create async iterators from paginated list endpoints.
241
235
  */
242
236
  export class RequestQueuePaginationIterator {
243
237
  maxPageLimit;
244
238
  getPage;
245
239
  limit;
246
- exclusiveStartId;
247
240
  cursor;
248
241
  constructor(options) {
249
242
  this.maxPageLimit = options.maxPageLimit;
250
243
  this.limit = options.limit;
251
- this.exclusiveStartId = options.exclusiveStartId;
252
244
  this.cursor = options.cursor;
253
245
  this.getPage = options.getPage;
254
246
  }
255
247
  async *[Symbol.asyncIterator]() {
256
248
  let nextCursor = this.cursor;
257
- // allow using exclusiveStartId for the first page, but then we'll delete it to avoid using it for any later page
258
- let nextExclusiveStartId = this.exclusiveStartId;
259
249
  let iterateItemCount = 0;
260
250
  while (true) {
261
251
  const pageLimit = this.limit
@@ -264,7 +254,6 @@ export class RequestQueuePaginationIterator {
264
254
  const page = await this.getPage({
265
255
  limit: pageLimit,
266
256
  cursor: nextCursor,
267
- exclusiveStartId: nextExclusiveStartId,
268
257
  });
269
258
  // There are no more pages to iterate
270
259
  if (page.items.length === 0)
@@ -275,7 +264,6 @@ export class RequestQueuePaginationIterator {
275
264
  if ((this.limit && iterateItemCount >= this.limit) || !page.nextCursor)
276
265
  return;
277
266
  nextCursor = page.nextCursor;
278
- nextExclusiveStartId = undefined; // see comment above - delete it for any page after the first one, and paginate with cursor
279
267
  }
280
268
  }
281
269
  }
@@ -315,15 +303,6 @@ export function applyQueryParamsToUrl(url, options) {
315
303
  }
316
304
  return url;
317
305
  }
318
- /**
319
- * Builds a `[check, message]` pair to spread into `.refine()`, asserting that at most one of `keys`
320
- * is present. Pass the options interface as `T`, so that a misspelled key is a type error.
321
- * @internal
322
- */
323
- export const mutuallyExclusive = (...keys) => [
324
- (value) => keys.filter((key) => typeof value[key] !== 'undefined').length <= 1,
325
- `At most one of the following fields is allowed: ${keys.join(', ')}`,
326
- ];
327
306
  const pathSegmentSchema = z
328
307
  .string()
329
308
  .nonempty()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apify-client",
3
- "version": "3.0.0-beta.5",
3
+ "version": "3.0.0-beta.7",
4
4
  "description": "Apify API client for JavaScript",
5
5
  "engines": {
6
6
  "node": ">=22.0.0"