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

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.
@@ -21,11 +21,45 @@ const CLIENT_METHOD_REGEX = /at( async)? ([A-Za-z]+(Collection)?Client)\._?([A-Z
21
21
  * needed.
22
22
  */
23
23
  class ApifyApiError extends Error {
24
+ name;
25
+ /**
26
+ * The invoked resource client and the method. Known issue: Sometimes it displays
27
+ * as `unknown` because it can't be parsed from a stack trace.
28
+ */
29
+ clientMethod;
30
+ /**
31
+ * HTTP status code of the error.
32
+ */
33
+ statusCode;
34
+ /**
35
+ * The type of the error, as returned by the API.
36
+ */
37
+ type;
38
+ /**
39
+ * Number of the API call attempt.
40
+ */
41
+ attempt;
42
+ /**
43
+ * HTTP method of the API call.
44
+ */
45
+ httpMethod;
46
+ /**
47
+ * Full path of the API endpoint (URL excluding origin).
48
+ */
49
+ path;
50
+ /**
51
+ * Original stack trace of the exception. It is replaced
52
+ * by a more informative stack with API call information.
53
+ */
54
+ originalStack;
55
+ /**
56
+ * Additional data provided by the API about the error
57
+ */
58
+ data;
24
59
  /**
25
60
  * @hidden
26
61
  */
27
62
  constructor(response, attempt) {
28
- var _a;
29
63
  let message;
30
64
  let type;
31
65
  let responseData = response.data;
@@ -57,92 +91,12 @@ class ApifyApiError extends Error {
57
91
  message = `Unexpected error: ${dataString}`;
58
92
  }
59
93
  super(message);
60
- Object.defineProperty(this, "name", {
61
- enumerable: true,
62
- configurable: true,
63
- writable: true,
64
- value: void 0
65
- });
66
- /**
67
- * The invoked resource client and the method. Known issue: Sometimes it displays
68
- * as `unknown` because it can't be parsed from a stack trace.
69
- */
70
- Object.defineProperty(this, "clientMethod", {
71
- enumerable: true,
72
- configurable: true,
73
- writable: true,
74
- value: void 0
75
- });
76
- /**
77
- * HTTP status code of the error.
78
- */
79
- Object.defineProperty(this, "statusCode", {
80
- enumerable: true,
81
- configurable: true,
82
- writable: true,
83
- value: void 0
84
- });
85
- /**
86
- * The type of the error, as returned by the API.
87
- */
88
- Object.defineProperty(this, "type", {
89
- enumerable: true,
90
- configurable: true,
91
- writable: true,
92
- value: void 0
93
- });
94
- /**
95
- * Number of the API call attempt.
96
- */
97
- Object.defineProperty(this, "attempt", {
98
- enumerable: true,
99
- configurable: true,
100
- writable: true,
101
- value: void 0
102
- });
103
- /**
104
- * HTTP method of the API call.
105
- */
106
- Object.defineProperty(this, "httpMethod", {
107
- enumerable: true,
108
- configurable: true,
109
- writable: true,
110
- value: void 0
111
- });
112
- /**
113
- * Full path of the API endpoint (URL excluding origin).
114
- */
115
- Object.defineProperty(this, "path", {
116
- enumerable: true,
117
- configurable: true,
118
- writable: true,
119
- value: void 0
120
- });
121
- /**
122
- * Original stack trace of the exception. It is replaced
123
- * by a more informative stack with API call information.
124
- */
125
- Object.defineProperty(this, "originalStack", {
126
- enumerable: true,
127
- configurable: true,
128
- writable: true,
129
- value: void 0
130
- });
131
- /**
132
- * Additional data provided by the API about the error
133
- */
134
- Object.defineProperty(this, "data", {
135
- enumerable: true,
136
- configurable: true,
137
- writable: true,
138
- value: void 0
139
- });
140
94
  this.name = this.constructor.name;
141
95
  this.clientMethod = this._extractClientAndMethodFromStack();
142
96
  this.statusCode = response.status;
143
97
  this.type = type;
144
98
  this.attempt = attempt;
145
- this.httpMethod = (_a = response.config) === null || _a === void 0 ? void 0 : _a.method;
99
+ this.httpMethod = response.config?.method;
146
100
  this.path = this._safelyParsePathFromResponse(response);
147
101
  const stack = this.stack;
148
102
  this.originalStack = stack.slice(stack.indexOf('\n'));
@@ -150,8 +104,7 @@ class ApifyApiError extends Error {
150
104
  this.data = errorData;
151
105
  }
152
106
  _safelyParsePathFromResponse(response) {
153
- var _a;
154
- const urlString = (_a = response.config) === null || _a === void 0 ? void 0 : _a.url;
107
+ const urlString = response.config?.url;
155
108
  let url;
156
109
  try {
157
110
  url = new URL(urlString);
@@ -53,43 +53,13 @@ const DEFAULT_TIMEOUT_SECS = 360;
53
53
  * @see https://docs.apify.com/api/v2
54
54
  */
55
55
  class ApifyClient {
56
+ baseUrl;
57
+ publicBaseUrl;
58
+ token;
59
+ stats;
60
+ logger;
61
+ httpClient;
56
62
  constructor(options = {}) {
57
- Object.defineProperty(this, "baseUrl", {
58
- enumerable: true,
59
- configurable: true,
60
- writable: true,
61
- value: void 0
62
- });
63
- Object.defineProperty(this, "publicBaseUrl", {
64
- enumerable: true,
65
- configurable: true,
66
- writable: true,
67
- value: void 0
68
- });
69
- Object.defineProperty(this, "token", {
70
- enumerable: true,
71
- configurable: true,
72
- writable: true,
73
- value: void 0
74
- });
75
- Object.defineProperty(this, "stats", {
76
- enumerable: true,
77
- configurable: true,
78
- writable: true,
79
- value: void 0
80
- });
81
- Object.defineProperty(this, "logger", {
82
- enumerable: true,
83
- configurable: true,
84
- writable: true,
85
- value: void 0
86
- });
87
- Object.defineProperty(this, "httpClient", {
88
- enumerable: true,
89
- configurable: true,
90
- writable: true,
91
- value: void 0
92
- });
93
63
  (0, ow_1.default)(options, ow_1.default.object.exactShape({
94
64
  baseUrl: ow_1.default.optional.string,
95
65
  publicBaseUrl: ow_1.default.optional.string,
@@ -3,61 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ApiClient = void 0;
4
4
  /** @private */
5
5
  class ApiClient {
6
+ id;
7
+ safeId;
8
+ baseUrl;
9
+ publicBaseUrl;
10
+ resourcePath;
11
+ url;
12
+ apifyClient;
13
+ httpClient;
14
+ params;
6
15
  constructor(options) {
7
- Object.defineProperty(this, "id", {
8
- enumerable: true,
9
- configurable: true,
10
- writable: true,
11
- value: void 0
12
- });
13
- Object.defineProperty(this, "safeId", {
14
- enumerable: true,
15
- configurable: true,
16
- writable: true,
17
- value: void 0
18
- });
19
- Object.defineProperty(this, "baseUrl", {
20
- enumerable: true,
21
- configurable: true,
22
- writable: true,
23
- value: void 0
24
- });
25
- Object.defineProperty(this, "publicBaseUrl", {
26
- enumerable: true,
27
- configurable: true,
28
- writable: true,
29
- value: void 0
30
- });
31
- Object.defineProperty(this, "resourcePath", {
32
- enumerable: true,
33
- configurable: true,
34
- writable: true,
35
- value: void 0
36
- });
37
- Object.defineProperty(this, "url", {
38
- enumerable: true,
39
- configurable: true,
40
- writable: true,
41
- value: void 0
42
- });
43
- Object.defineProperty(this, "apifyClient", {
44
- enumerable: true,
45
- configurable: true,
46
- writable: true,
47
- value: void 0
48
- });
49
- Object.defineProperty(this, "httpClient", {
50
- enumerable: true,
51
- configurable: true,
52
- writable: true,
53
- value: void 0
54
- });
55
- Object.defineProperty(this, "params", {
56
- enumerable: true,
57
- configurable: true,
58
- writable: true,
59
- value: void 0
60
- });
61
16
  const { baseUrl, publicBaseUrl, apifyClient, httpClient, resourcePath, id, params = {} } = options;
62
17
  this.id = id;
63
18
  this.safeId = id && this._toSafeId(id);
@@ -116,10 +71,9 @@ class ApiClient {
116
71
  limit: minForLimitParam(options.limit, options.chunkSize),
117
72
  });
118
73
  async function* asyncGenerator() {
119
- var _a;
120
74
  let currentPage = await paginatedListPromise;
121
75
  yield* currentPage.items;
122
- const offset = (_a = options.offset) !== null && _a !== void 0 ? _a : 0;
76
+ const offset = options.offset ?? 0;
123
77
  const limit = Math.min(options.limit || currentPage.total, currentPage.total);
124
78
  let currentOffset = offset + currentPage.items.length;
125
79
  let remainingItems = Math.min(currentPage.total - offset, limit) - currentPage.items.length;
package/dist/bundle.js CHANGED
@@ -13419,9 +13419,6 @@ __webpack_require__.r(__webpack_exports__);
13419
13419
  params: this._params(params),
13420
13420
  // Apify internal property. Tells the request serialization interceptor
13421
13421
  // to stringify functions to JSON, instead of omitting them.
13422
- // TODO: remove this ts-expect-error once we migrate HttpClient to TS and define Apify
13423
- // extension of Axios configs
13424
- // @ts-expect-error Apify extension
13425
13422
  stringifyFunctions: true
13426
13423
  };
13427
13424
  if (options.contentType) {
@@ -13501,6 +13498,62 @@ __webpack_require__.r(__webpack_exports__);
13501
13498
  await streamedLog?.stop();
13502
13499
  });
13503
13500
  }
13501
+ /**
13502
+ * Validates the provided input for the Actor against its input schema.
13503
+ *
13504
+ * Sends the input to the API, which validates it against the Actor's input schema without
13505
+ * starting a run. If the input is valid, the method resolves with `true`. If the input is
13506
+ * invalid, the API responds with an error that is thrown as an `ApifyApiError` describing the
13507
+ * validation problem.
13508
+ *
13509
+ * @param input - Input to validate against the Actor's input schema. Can be any JSON-serializable
13510
+ * value (object, array, string, number). If `contentType` is specified in options,
13511
+ * input should be a string or Buffer.
13512
+ * @param options - Validation options
13513
+ * @param options.build - Tag or number of the build whose input schema the input is validated against
13514
+ * (e.g., `'latest'` or `'1.2.345'`). If not provided, uses the default build.
13515
+ * @param options.contentType - Content type of the input. If specified, input must be a string or Buffer.
13516
+ * @returns `true` if the input is valid. Invalid input causes the underlying API call to throw an `ApifyApiError`.
13517
+ * @see https://docs.apify.com/api/v2/act-input-validate-post
13518
+ *
13519
+ * @example
13520
+ * ```javascript
13521
+ * // Validate input against the default build's input schema
13522
+ * const isValid = await client.actor('my-actor').validateInput({ url: 'https://example.com' });
13523
+ *
13524
+ * // Validate against a specific build
13525
+ * const isValid = await client.actor('my-actor').validateInput(
13526
+ * { url: 'https://example.com' },
13527
+ * { build: 'beta' },
13528
+ * );
13529
+ * ```
13530
+ */ async validateInput(input) {
13531
+ let options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
13532
+ // input can be anything, so no point in validating it. E.g. if you set content-type to application/pdf
13533
+ // then it will process input as a buffer.
13534
+ ow__rspack_import_11_default()(options, ow__rspack_import_11_default().object.exactShape({
13535
+ build: (ow__rspack_import_11_default().optional.string),
13536
+ contentType: (ow__rspack_import_11_default().optional.string)
13537
+ }));
13538
+ const request = {
13539
+ url: this._url('validate-input'),
13540
+ method: 'POST',
13541
+ data: input,
13542
+ params: this._params({
13543
+ build: options.build
13544
+ }),
13545
+ // Apify internal property. Tells the request serialization interceptor
13546
+ // to stringify functions to JSON, instead of omitting them.
13547
+ stringifyFunctions: true
13548
+ };
13549
+ if (options.contentType) {
13550
+ request.headers = {
13551
+ 'content-type': options.contentType
13552
+ };
13553
+ }
13554
+ const response = await this.httpClient.call(request);
13555
+ return response.data.valid;
13556
+ }
13504
13557
  /**
13505
13558
  * Builds the Actor.
13506
13559
  *
@@ -13606,7 +13659,7 @@ __webpack_require__.r(__webpack_exports__);
13606
13659
  */ lastRun() {
13607
13660
  let options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
13608
13661
  ow__rspack_import_11_default()(options, ow__rspack_import_11_default().object.exactShape({
13609
- status: ow__rspack_import_11_default().optional.string.oneOf(Object.values(_apify_consts__rspack_import_0.ACT_JOB_STATUSES)),
13662
+ status: ow__rspack_import_11_default().optional.string.oneOf(Object.values(_apify_consts__rspack_import_0.ACTOR_JOB_STATUSES)),
13610
13663
  origin: ow__rspack_import_11_default().optional.string.oneOf(Object.values(_apify_consts__rspack_import_0.META_ORIGINS))
13611
13664
  }));
13612
13665
  return new _run__rspack_import_8.RunClient(this._subResourceOptions({
@@ -18031,7 +18084,7 @@ function isStream(value) {
18031
18084
  function getVersionData() {
18032
18085
  if (true) {
18033
18086
  return {
18034
- version: "2.23.5-beta.2"
18087
+ version: "2.23.5-beta.21"
18035
18088
  };
18036
18089
  }
18037
18090
  // eslint-disable-next-line