apify-client 2.23.5-beta.2 → 2.23.5-beta.20

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.
@@ -43,6 +43,8 @@ const SAFETY_BUFFER_PERCENT = 0.01 / 100; // 0.01%
43
43
  * @see https://docs.apify.com/platform/storage/request-queue
44
44
  */
45
45
  class RequestQueueClient extends resource_client_1.ResourceClient {
46
+ clientKey;
47
+ timeoutMillis;
46
48
  /**
47
49
  * @hidden
48
50
  */
@@ -51,18 +53,6 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
51
53
  resourcePath: 'request-queues',
52
54
  ...options,
53
55
  });
54
- Object.defineProperty(this, "clientKey", {
55
- enumerable: true,
56
- configurable: true,
57
- writable: true,
58
- value: void 0
59
- });
60
- Object.defineProperty(this, "timeoutMillis", {
61
- enumerable: true,
62
- configurable: true,
63
- writable: true,
64
- value: void 0
65
- });
66
56
  this.clientKey = userOptions.clientKey;
67
57
  this.timeoutMillis = userOptions.timeoutSecs ? userOptions.timeoutSecs * 1e3 : undefined;
68
58
  }
@@ -105,14 +95,13 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
105
95
  * @see https://docs.apify.com/api/v2/request-queue-head-get
106
96
  */
107
97
  async listHead(options = {}) {
108
- var _a;
109
98
  (0, ow_1.default)(options, ow_1.default.object.exactShape({
110
99
  limit: ow_1.default.optional.number.not.negative,
111
100
  }));
112
101
  const response = await this.httpClient.call({
113
102
  url: this._url('head'),
114
103
  method: 'GET',
115
- timeout: Math.min(resource_client_1.SMALL_TIMEOUT_MILLIS, (_a = this.timeoutMillis) !== null && _a !== void 0 ? _a : Infinity),
104
+ timeout: Math.min(resource_client_1.SMALL_TIMEOUT_MILLIS, this.timeoutMillis ?? Infinity),
116
105
  params: this._params({
117
106
  limit: options.limit,
118
107
  clientKey: this.clientKey,
@@ -153,7 +142,6 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
153
142
  * ```
154
143
  */
155
144
  async listAndLockHead(options) {
156
- var _a;
157
145
  (0, ow_1.default)(options, ow_1.default.object.exactShape({
158
146
  lockSecs: ow_1.default.number,
159
147
  limit: ow_1.default.optional.number.not.negative,
@@ -161,7 +149,7 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
161
149
  const response = await this.httpClient.call({
162
150
  url: this._url('head/lock'),
163
151
  method: 'POST',
164
- timeout: Math.min(resource_client_1.MEDIUM_TIMEOUT_MILLIS, (_a = this.timeoutMillis) !== null && _a !== void 0 ? _a : Infinity),
152
+ timeout: Math.min(resource_client_1.MEDIUM_TIMEOUT_MILLIS, this.timeoutMillis ?? Infinity),
165
153
  params: this._params({
166
154
  limit: options.limit,
167
155
  lockSecs: options.lockSecs,
@@ -209,7 +197,6 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
209
197
  * ```
210
198
  */
211
199
  async addRequest(request, options = {}) {
212
- var _a;
213
200
  (0, ow_1.default)(request, ow_1.default.object.partialShape({
214
201
  id: ow_1.default.undefined,
215
202
  }));
@@ -219,7 +206,7 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
219
206
  const response = await this.httpClient.call({
220
207
  url: this._url('requests'),
221
208
  method: 'POST',
222
- timeout: Math.min(resource_client_1.SMALL_TIMEOUT_MILLIS, (_a = this.timeoutMillis) !== null && _a !== void 0 ? _a : Infinity),
209
+ timeout: Math.min(resource_client_1.SMALL_TIMEOUT_MILLIS, this.timeoutMillis ?? Infinity),
223
210
  data: request,
224
211
  params: this._params({
225
212
  forefront: options.forefront,
@@ -234,7 +221,6 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
234
221
  * @private
235
222
  */
236
223
  async _batchAddRequests(requests, options = {}) {
237
- var _a;
238
224
  (0, ow_1.default)(requests, ow_1.default.array
239
225
  .ofType(ow_1.default.object.partialShape({
240
226
  id: ow_1.default.undefined,
@@ -247,7 +233,7 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
247
233
  const { data } = await this.httpClient.call({
248
234
  url: this._url('requests/batch'),
249
235
  method: 'POST',
250
- timeout: Math.min(resource_client_1.MEDIUM_TIMEOUT_MILLIS, (_a = this.timeoutMillis) !== null && _a !== void 0 ? _a : Infinity),
236
+ timeout: Math.min(resource_client_1.MEDIUM_TIMEOUT_MILLIS, this.timeoutMillis ?? Infinity),
251
237
  data: requests,
252
238
  params: this._params({
253
239
  forefront: options.forefront,
@@ -395,7 +381,6 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
395
381
  * @see https://docs.apify.com/api/v2/request-queue-requests-batch-delete
396
382
  */
397
383
  async batchDeleteRequests(requests) {
398
- var _a;
399
384
  (0, ow_1.default)(requests, ow_1.default.array
400
385
  .ofType(ow_1.default.any(ow_1.default.object.partialShape({ id: ow_1.default.string }), ow_1.default.object.partialShape({ uniqueKey: ow_1.default.string })))
401
386
  .minLength(1)
@@ -403,7 +388,7 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
403
388
  const { data } = await this.httpClient.call({
404
389
  url: this._url('requests/batch'),
405
390
  method: 'DELETE',
406
- timeout: Math.min(resource_client_1.SMALL_TIMEOUT_MILLIS, (_a = this.timeoutMillis) !== null && _a !== void 0 ? _a : Infinity),
391
+ timeout: Math.min(resource_client_1.SMALL_TIMEOUT_MILLIS, this.timeoutMillis ?? Infinity),
407
392
  data: requests,
408
393
  params: this._params({
409
394
  clientKey: this.clientKey,
@@ -419,12 +404,11 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
419
404
  * @see https://docs.apify.com/api/v2/request-queue-request-get
420
405
  */
421
406
  async getRequest(id) {
422
- var _a;
423
407
  (0, ow_1.default)(id, ow_1.default.string);
424
408
  const requestOpts = {
425
409
  url: this._url(`requests/${id}`),
426
410
  method: 'GET',
427
- timeout: Math.min(resource_client_1.SMALL_TIMEOUT_MILLIS, (_a = this.timeoutMillis) !== null && _a !== void 0 ? _a : Infinity),
411
+ timeout: Math.min(resource_client_1.SMALL_TIMEOUT_MILLIS, this.timeoutMillis ?? Infinity),
428
412
  params: this._params(),
429
413
  };
430
414
  try {
@@ -445,7 +429,6 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
445
429
  * @see https://docs.apify.com/api/v2/request-queue-request-put
446
430
  */
447
431
  async updateRequest(request, options = {}) {
448
- var _a;
449
432
  (0, ow_1.default)(request, ow_1.default.object.partialShape({
450
433
  id: ow_1.default.string,
451
434
  }));
@@ -455,7 +438,7 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
455
438
  const response = await this.httpClient.call({
456
439
  url: this._url(`requests/${request.id}`),
457
440
  method: 'PUT',
458
- timeout: Math.min(resource_client_1.MEDIUM_TIMEOUT_MILLIS, (_a = this.timeoutMillis) !== null && _a !== void 0 ? _a : Infinity),
441
+ timeout: Math.min(resource_client_1.MEDIUM_TIMEOUT_MILLIS, this.timeoutMillis ?? Infinity),
459
442
  data: request,
460
443
  params: this._params({
461
444
  forefront: options.forefront,
@@ -470,12 +453,11 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
470
453
  * @param id - Request ID
471
454
  */
472
455
  async deleteRequest(id) {
473
- var _a;
474
456
  (0, ow_1.default)(id, ow_1.default.string);
475
457
  await this.httpClient.call({
476
458
  url: this._url(`requests/${id}`),
477
459
  method: 'DELETE',
478
- timeout: Math.min(resource_client_1.SMALL_TIMEOUT_MILLIS, (_a = this.timeoutMillis) !== null && _a !== void 0 ? _a : Infinity),
460
+ timeout: Math.min(resource_client_1.SMALL_TIMEOUT_MILLIS, this.timeoutMillis ?? Infinity),
479
461
  params: this._params({
480
462
  clientKey: this.clientKey,
481
463
  }),
@@ -506,7 +488,6 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
506
488
  * ```
507
489
  */
508
490
  async prolongRequestLock(id, options) {
509
- var _a;
510
491
  (0, ow_1.default)(id, ow_1.default.string);
511
492
  (0, ow_1.default)(options, ow_1.default.object.exactShape({
512
493
  lockSecs: ow_1.default.number,
@@ -515,7 +496,7 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
515
496
  const response = await this.httpClient.call({
516
497
  url: this._url(`requests/${id}/lock`),
517
498
  method: 'PUT',
518
- timeout: Math.min(resource_client_1.MEDIUM_TIMEOUT_MILLIS, (_a = this.timeoutMillis) !== null && _a !== void 0 ? _a : Infinity),
499
+ timeout: Math.min(resource_client_1.MEDIUM_TIMEOUT_MILLIS, this.timeoutMillis ?? Infinity),
519
500
  params: this._params({
520
501
  forefront: options.forefront,
521
502
  lockSecs: options.lockSecs,
@@ -535,7 +516,6 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
535
516
  * @see https://docs.apify.com/api/v2/request-queue-request-lock-delete
536
517
  */
537
518
  async deleteRequestLock(id, options = {}) {
538
- var _a;
539
519
  (0, ow_1.default)(id, ow_1.default.string);
540
520
  (0, ow_1.default)(options, ow_1.default.object.exactShape({
541
521
  forefront: ow_1.default.optional.boolean,
@@ -543,7 +523,7 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
543
523
  await this.httpClient.call({
544
524
  url: this._url(`requests/${id}/lock`),
545
525
  method: 'DELETE',
546
- timeout: Math.min(resource_client_1.SMALL_TIMEOUT_MILLIS, (_a = this.timeoutMillis) !== null && _a !== void 0 ? _a : Infinity),
526
+ timeout: Math.min(resource_client_1.SMALL_TIMEOUT_MILLIS, this.timeoutMillis ?? Infinity),
547
527
  params: this._params({
548
528
  forefront: options.forefront,
549
529
  clientKey: this.clientKey,
@@ -570,11 +550,10 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
570
550
  })
571
551
  .validate((0, utils_1.mutuallyExclusive)('exclusiveStartId', 'cursor')));
572
552
  const getPaginatedList = async (rqListOptions = {}) => {
573
- var _a;
574
553
  const response = await this.httpClient.call({
575
554
  url: this._url('requests'),
576
555
  method: 'GET',
577
- timeout: Math.min(resource_client_1.MEDIUM_TIMEOUT_MILLIS, (_a = this.timeoutMillis) !== null && _a !== void 0 ? _a : Infinity),
556
+ timeout: Math.min(resource_client_1.MEDIUM_TIMEOUT_MILLIS, this.timeoutMillis ?? Infinity),
578
557
  params: this._params({
579
558
  ...rqListOptions,
580
559
  filter: rqListOptions.filter ? rqListOptions.filter.join(',') : undefined,
@@ -622,11 +601,10 @@ class RequestQueueClient extends resource_client_1.ResourceClient {
622
601
  * @see https://docs.apify.com/api/v2/request-queue-requests-unlock-post
623
602
  */
624
603
  async unlockRequests() {
625
- var _a;
626
604
  const response = await this.httpClient.call({
627
605
  url: this._url('requests/unlock'),
628
606
  method: 'POST',
629
- timeout: Math.min(resource_client_1.MEDIUM_TIMEOUT_MILLIS, (_a = this.timeoutMillis) !== null && _a !== void 0 ? _a : Infinity),
607
+ timeout: Math.min(resource_client_1.MEDIUM_TIMEOUT_MILLIS, this.timeoutMillis ?? Infinity),
630
608
  params: this._params({
631
609
  clientKey: this.clientKey,
632
610
  }),
@@ -254,16 +254,15 @@ class RunClient extends resource_client_1.ResourceClient {
254
254
  * @see https://docs.apify.com/api/v2/post-charge-run
255
255
  */
256
256
  async charge(options) {
257
- var _a, _b;
258
257
  (0, ow_1.default)(options, ow_1.default.object.exactShape({
259
258
  eventName: ow_1.default.string,
260
259
  count: ow_1.default.optional.number,
261
260
  idempotencyKey: ow_1.default.optional.string,
262
261
  }));
263
- const count = (_a = options.count) !== null && _a !== void 0 ? _a : 1;
262
+ const count = options.count ?? 1;
264
263
  /** To avoid duplicates during the same milisecond, doesn't need to by crypto-secure. */
265
264
  const randomSuffix = (Math.random() + 1).toString(36).slice(3, 8);
266
- const idempotencyKey = (_b = options.idempotencyKey) !== null && _b !== void 0 ? _b : `${this.id}-${options.eventName}-${Date.now()}-${randomSuffix}`;
265
+ const idempotencyKey = options.idempotencyKey ?? `${this.id}-${options.eventName}-${Date.now()}-${randomSuffix}`;
267
266
  const request = {
268
267
  url: this._url('charge'),
269
268
  method: 'POST',
@@ -385,7 +384,6 @@ class RunClient extends resource_client_1.ResourceClient {
385
384
  * Get StreamedLog for convenient streaming of the run log and their redirection.
386
385
  */
387
386
  async getStreamedLog(options = {}) {
388
- var _a, _b, _c;
389
387
  const { fromStart = true } = options;
390
388
  let { toLog } = options;
391
389
  if (toLog === null || !(0, utils_1.isNode)()) {
@@ -396,10 +394,10 @@ class RunClient extends resource_client_1.ResourceClient {
396
394
  // Create default StreamedLog
397
395
  // Get actor name and run id
398
396
  const runData = await this.get();
399
- const runId = (_a = runData === null || runData === void 0 ? void 0 : runData.id) !== null && _a !== void 0 ? _a : '';
400
- const actorId = (_b = runData === null || runData === void 0 ? void 0 : runData.actId) !== null && _b !== void 0 ? _b : '';
397
+ const runId = runData?.id ?? '';
398
+ const actorId = runData?.actId ?? '';
401
399
  const actorData = (await this.apifyClient.actor(actorId).get()) || { name: '' };
402
- const actorName = (_c = actorData === null || actorData === void 0 ? void 0 : actorData.name) !== null && _c !== void 0 ? _c : '';
400
+ const actorName = actorData?.name ?? '';
403
401
  const name = [actorName, `runId:${runId}`].filter(Boolean).join(' ');
404
402
  toLog = new log_1.Log({ level: log_1.LEVELS.DEBUG, prefix: `${name} -> `, logger: new log_2.LoggerActorRedirect() });
405
403
  }
@@ -1,8 +1,7 @@
1
- import { ACT_JOB_STATUSES } from '@apify/consts';
2
1
  import type { ApiClientSubResourceOptions } from '../base/api_client';
3
2
  import { ResourceClient } from '../base/resource_client';
4
3
  import type { Dictionary } from '../utils';
5
- import type { ActorRun, ActorStandby, ActorStartOptions } from './actor';
4
+ import type { ActorLastRunOptions, ActorRun, ActorStandby, ActorStartOptions } from './actor';
6
5
  import { RunClient } from './run';
7
6
  import { RunCollectionClient } from './run_collection';
8
7
  import { WebhookCollectionClient } from './webhook_collection';
@@ -170,8 +169,7 @@ export type TaskUpdateData = Partial<Pick<Task, 'name' | 'title' | 'description'
170
169
  /**
171
170
  * Options for filtering the last run of a Task.
172
171
  */
173
- export interface TaskLastRunOptions {
174
- status?: keyof typeof ACT_JOB_STATUSES;
172
+ export interface TaskLastRunOptions extends ActorLastRunOptions {
175
173
  }
176
174
  /**
177
175
  * Options for starting a Task.
@@ -4,36 +4,19 @@ exports.Statistics = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const ow_1 = tslib_1.__importDefault(require("ow"));
6
6
  class Statistics {
7
- constructor() {
8
- /**
9
- * Number of Apify client function calls
10
- */
11
- Object.defineProperty(this, "calls", {
12
- enumerable: true,
13
- configurable: true,
14
- writable: true,
15
- value: 0
16
- });
17
- /**
18
- * Number of Apify API requests
19
- */
20
- Object.defineProperty(this, "requests", {
21
- enumerable: true,
22
- configurable: true,
23
- writable: true,
24
- value: 0
25
- });
26
- /**
27
- * Number of times the API returned 429 error. Errors on first attempt are
28
- * counted at index 0. First retry error counts are on index 1 and so on.
29
- */
30
- Object.defineProperty(this, "rateLimitErrors", {
31
- enumerable: true,
32
- configurable: true,
33
- writable: true,
34
- value: []
35
- });
36
- }
7
+ /**
8
+ * Number of Apify client function calls
9
+ */
10
+ calls = 0;
11
+ /**
12
+ * Number of Apify API requests
13
+ */
14
+ requests = 0;
15
+ /**
16
+ * Number of times the API returned 429 error. Errors on first attempt are
17
+ * counted at index 0. First retry error counts are on index 1 and so on.
18
+ */
19
+ rateLimitErrors = [];
37
20
  addRateLimitError(attempt) {
38
21
  (0, ow_1.default)(attempt, ow_1.default.number.greaterThan(0));
39
22
  // attempt is never 0,
package/dist/utils.js CHANGED
@@ -165,37 +165,12 @@ function getVersionData() {
165
165
  * Helper class to create async iterators from paginated list endpoints with exclusive start key.
166
166
  */
167
167
  class RequestQueuePaginationIterator {
168
+ maxPageLimit;
169
+ getPage;
170
+ limit;
171
+ exclusiveStartId;
172
+ cursor;
168
173
  constructor(options) {
169
- Object.defineProperty(this, "maxPageLimit", {
170
- enumerable: true,
171
- configurable: true,
172
- writable: true,
173
- value: void 0
174
- });
175
- Object.defineProperty(this, "getPage", {
176
- enumerable: true,
177
- configurable: true,
178
- writable: true,
179
- value: void 0
180
- });
181
- Object.defineProperty(this, "limit", {
182
- enumerable: true,
183
- configurable: true,
184
- writable: true,
185
- value: void 0
186
- });
187
- Object.defineProperty(this, "exclusiveStartId", {
188
- enumerable: true,
189
- configurable: true,
190
- writable: true,
191
- value: void 0
192
- });
193
- Object.defineProperty(this, "cursor", {
194
- enumerable: true,
195
- configurable: true,
196
- writable: true,
197
- value: void 0
198
- });
199
174
  this.maxPageLimit = options.maxPageLimit;
200
175
  this.limit = options.limit;
201
176
  this.exclusiveStartId = options.exclusiveStartId;
@@ -243,7 +218,7 @@ function asArray(value) {
243
218
  * Adds query parameters to a given URL based on the provided options object.
244
219
  */
245
220
  function applyQueryParamsToUrl(url, options) {
246
- for (const [key, value] of Object.entries(options !== null && options !== void 0 ? options : {})) {
221
+ for (const [key, value] of Object.entries(options ?? {})) {
247
222
  // skip undefined values
248
223
  if (value === undefined)
249
224
  continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apify-client",
3
- "version": "2.23.5-beta.2",
3
+ "version": "2.23.5-beta.20",
4
4
  "description": "Apify API client for JavaScript",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -63,8 +63,8 @@
63
63
  "type-fest": "^4.0.0"
64
64
  },
65
65
  "devDependencies": {
66
- "@apify/oxlint-config": "^0.2.5",
67
- "@apify/tsconfig": "^0.1.2",
66
+ "@apify/oxlint-config": "^0.3.0",
67
+ "@apify/tsconfig": "^0.2.0",
68
68
  "@crawlee/puppeteer": "^3.2.2",
69
69
  "@rsbuild/core": "^2.0.0",
70
70
  "@rsbuild/plugin-node-polyfill": "^1.3.0",
@@ -78,12 +78,12 @@
78
78
  "ajv": "^8.17.1",
79
79
  "body-parser": "^2.0.0",
80
80
  "compression": "^1.7.4",
81
- "esbuild": "0.28.0",
81
+ "esbuild": "0.28.1",
82
82
  "express": "^5.0.0",
83
83
  "gen-esm-wrapper": "^1.1.2",
84
- "oxfmt": "0.53.0",
85
- "oxlint": "1.69.0",
86
- "oxlint-tsgolint": "0.23.0",
84
+ "oxfmt": "0.57.0",
85
+ "oxlint": "1.71.0",
86
+ "oxlint-tsgolint": "0.24.0",
87
87
  "puppeteer": "^25.0.0",
88
88
  "rimraf": "^6.0.0",
89
89
  "rolldown": "^1.0.0-rc.4",