apify-client 3.0.0-rc.0 → 3.0.0-rc.1

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.
Files changed (52) hide show
  1. package/README.md +6 -0
  2. package/dist/apify_api_error.d.ts +2 -1
  3. package/dist/apify_api_error.js +2 -1
  4. package/dist/apify_client_error.d.ts +10 -0
  5. package/dist/apify_client_error.js +10 -0
  6. package/dist/base/api_client.js +8 -20
  7. package/dist/base/resource_client.js +8 -8
  8. package/dist/bundle.js +13 -13
  9. package/dist/bundle.js.map +1 -1
  10. package/dist/generated/api.d.ts +2300 -690
  11. package/dist/generated/schemas.d.ts +1720 -246
  12. package/dist/generated/schemas.js +416 -75
  13. package/dist/http_clients/axios.d.ts +2 -1
  14. package/dist/http_clients/axios.js +6 -4
  15. package/dist/http_clients/base.d.ts +80 -20
  16. package/dist/http_clients/base.js +127 -40
  17. package/dist/http_compressors/index.d.ts +2 -0
  18. package/dist/http_compressors/index.js +1 -0
  19. package/dist/http_compressors/resolve.d.ts +4 -3
  20. package/dist/http_compressors/resolve.js +4 -1
  21. package/dist/http_compressors/zstd.d.ts +34 -0
  22. package/dist/http_compressors/zstd.js +43 -0
  23. package/dist/index.d.ts +2 -0
  24. package/dist/index.js +2 -0
  25. package/dist/invalid_response_body_error.d.ts +5 -4
  26. package/dist/invalid_response_body_error.js +5 -4
  27. package/dist/models.d.ts +30 -61
  28. package/dist/resource_clients/actor.d.ts +30 -0
  29. package/dist/resource_clients/actor.js +43 -0
  30. package/dist/resource_clients/actor_server.d.ts +149 -0
  31. package/dist/resource_clients/actor_server.js +199 -0
  32. package/dist/resource_clients/actor_version.d.ts +5 -0
  33. package/dist/resource_clients/dataset.d.ts +33 -4
  34. package/dist/resource_clients/dataset.js +16 -54
  35. package/dist/resource_clients/key_value_store.d.ts +51 -11
  36. package/dist/resource_clients/key_value_store.js +59 -15
  37. package/dist/resource_clients/log.d.ts +29 -3
  38. package/dist/resource_clients/log.js +7 -11
  39. package/dist/resource_clients/request_queue.d.ts +9 -0
  40. package/dist/resource_clients/request_queue.js +9 -6
  41. package/dist/resource_clients/run.d.ts +9 -0
  42. package/dist/resource_clients/run.js +6 -3
  43. package/dist/response_validation_error.d.ts +2 -1
  44. package/dist/response_validation_error.js +2 -1
  45. package/dist/runtime/node.js +44 -6
  46. package/dist/runtime/types.d.ts +9 -1
  47. package/dist/runtime/web.js +4 -1
  48. package/dist/schemas.d.ts +369 -3
  49. package/dist/schemas.js +25 -3
  50. package/dist/utils.d.ts +23 -26
  51. package/dist/utils.js +32 -25
  52. package/package.json +23 -23
@@ -0,0 +1,43 @@
1
+ import { z } from 'zod';
2
+ import { runtime } from '#runtime';
3
+ import { parseArgument } from '../utils.js';
4
+ /** Lowest valid zstd quality, the fastest with the least compression. */
5
+ const MIN_QUALITY = 1;
6
+ /**
7
+ * Highest quality the compressor accepts. zstd itself goes up to 22, but levels 20 to 22 use a window above the 8 MB
8
+ * that RFC 9659 requires HTTP decoders to support, so a record stored at those levels could fail to decode in a
9
+ * browser that accepts zstd. Level 19 is the last one within the limit.
10
+ */
11
+ const MAX_QUALITY = 19;
12
+ /** zstd's own default. Fast, with a ratio close to gzip at its best level. */
13
+ const DEFAULT_QUALITY = 3;
14
+ const optionsSchema = z.strictObject({
15
+ quality: z.int().min(MIN_QUALITY).max(MAX_QUALITY).default(DEFAULT_QUALITY),
16
+ });
17
+ /**
18
+ * Compresses request bodies using zstd.
19
+ *
20
+ * Built on the `node:zlib` module, so it works wherever the client runs on Node.js.
21
+ *
22
+ * @example
23
+ * ```javascript
24
+ * import { ApifyClient, ZstdHttpCompressor } from 'apify-client';
25
+ *
26
+ * const client = new ApifyClient({ token: 'my-token', compression: new ZstdHttpCompressor({ quality: 19 }) });
27
+ * ```
28
+ */
29
+ export class ZstdHttpCompressor {
30
+ contentEncoding = 'zstd';
31
+ #quality;
32
+ /**
33
+ * @param options - Compressor options.
34
+ * @throws {ArgumentValidationError} If `quality` is out of the valid range.
35
+ */
36
+ constructor(options = {}) {
37
+ const { quality } = parseArgument(options, optionsSchema, 'ZstdHttpCompressorOptions');
38
+ this.#quality = quality;
39
+ }
40
+ async compress(data) {
41
+ return runtime.compress(data, { algorithm: 'zstd', quality: this.#quality });
42
+ }
43
+ }
package/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export * from './resource_clients/actor.js';
3
3
  export * from './resource_clients/actor_collection.js';
4
4
  export * from './resource_clients/actor_env_var.js';
5
5
  export * from './resource_clients/actor_env_var_collection.js';
6
+ export * from './resource_clients/actor_server.js';
6
7
  export * from './resource_clients/actor_version.js';
7
8
  export * from './resource_clients/actor_version_collection.js';
8
9
  export * from './resource_clients/build.js';
@@ -26,6 +27,7 @@ export * from './resource_clients/webhook.js';
26
27
  export * from './resource_clients/webhook_collection.js';
27
28
  export * from './resource_clients/webhook_dispatch.js';
28
29
  export * from './resource_clients/webhook_dispatch_collection.js';
30
+ export * from './apify_client_error.js';
29
31
  export * from './apify_api_error.js';
30
32
  export { ArgumentValidationError } from '@apify/validations';
31
33
  export * from './response_validation_error.js';
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@ export * from './resource_clients/actor.js';
3
3
  export * from './resource_clients/actor_collection.js';
4
4
  export * from './resource_clients/actor_env_var.js';
5
5
  export * from './resource_clients/actor_env_var_collection.js';
6
+ export * from './resource_clients/actor_server.js';
6
7
  export * from './resource_clients/actor_version.js';
7
8
  export * from './resource_clients/actor_version_collection.js';
8
9
  export * from './resource_clients/build.js';
@@ -26,6 +27,7 @@ export * from './resource_clients/webhook.js';
26
27
  export * from './resource_clients/webhook_collection.js';
27
28
  export * from './resource_clients/webhook_dispatch.js';
28
29
  export * from './resource_clients/webhook_dispatch_collection.js';
30
+ export * from './apify_client_error.js';
29
31
  export * from './apify_api_error.js';
30
32
  export { ArgumentValidationError } from '@apify/validations';
31
33
  export * from './response_validation_error.js';
@@ -1,10 +1,11 @@
1
+ import { ApifyClientError } from './apify_client_error.js';
1
2
  import type { HttpResponse } from './http_clients/base.js';
2
3
  /**
3
- * Thrown when a response body does not parse as its content type claims, typically a JSON document cut short by a
4
- * connection dropped mid-response. The client retries such requests, so the error surfaces once the retries are
5
- * exhausted.
4
+ * Thrown when the body of a successful response does not parse as its content type claims, for example a non-JSON
5
+ * value stored under `application/json`. The response arrived in full, so the request is not retried. An error
6
+ * status with an unparsable body throws {@link ApifyApiError} for its status code.
6
7
  */
7
- export declare class InvalidResponseBodyError extends Error {
8
+ export declare class InvalidResponseBodyError extends ApifyClientError {
8
9
  code: string;
9
10
  /** The response whose body did not parse, with the body as the transport returned it. */
10
11
  response: HttpResponse;
@@ -1,9 +1,10 @@
1
+ import { ApifyClientError } from './apify_client_error.js';
1
2
  /**
2
- * Thrown when a response body does not parse as its content type claims, typically a JSON document cut short by a
3
- * connection dropped mid-response. The client retries such requests, so the error surfaces once the retries are
4
- * exhausted.
3
+ * Thrown when the body of a successful response does not parse as its content type claims, for example a non-JSON
4
+ * value stored under `application/json`. The response arrived in full, so the request is not retried. An error
5
+ * status with an unparsable body throws {@link ApifyApiError} for its status code.
5
6
  */
6
- export class InvalidResponseBodyError extends Error {
7
+ export class InvalidResponseBodyError extends ApifyClientError {
7
8
  code;
8
9
  /** The response whose body did not parse, with the body as the transport returned it. */
9
10
  response;
package/dist/models.d.ts CHANGED
@@ -62,7 +62,6 @@ export type ErrorType = Schemas['ErrorType'];
62
62
  * TODO: Remove once the spec covers them.
63
63
  */
64
64
  export interface DatasetResourceSpecGaps {
65
- title?: string;
66
65
  username?: string;
67
66
  }
68
67
  export interface DatasetResourceRePointed {
@@ -143,14 +142,6 @@ export interface WebhookDispatchEventData extends GeneratedWebhookDispatchEventD
143
142
  }
144
143
  type GeneratedKeyValueStoreStats = Schemas['KeyValueStoreStats'];
145
144
  type GeneratedKeyValueStoreKey = Schemas['KeyValueStoreKey'];
146
- /**
147
- * Fields the API returns on a key-value store that the OpenAPI spec does not describe yet.
148
- *
149
- * TODO: Remove once the spec covers them.
150
- */
151
- export interface KeyValueStoreResourceSpecGaps {
152
- title?: string;
153
- }
154
145
  export interface KeyValueStoreResourceRePointed {
155
146
  stats?: KeyValueStoreStats;
156
147
  generalAccess?: STORAGE_GENERAL_ACCESS | null;
@@ -161,7 +152,7 @@ export interface KeyValueStoreResourceRePointed {
161
152
  * Key-value stores are used to store arbitrary data records or files. Each record is identified
162
153
  * by a unique key and can contain any data - JSON objects, strings, binary files, etc.
163
154
  */
164
- export interface KeyValueStoreResource extends Omit<Schemas['KeyValueStoreResource'], keyof KeyValueStoreResourceRePointed>, KeyValueStoreResourceRePointed, KeyValueStoreResourceSpecGaps {
155
+ export interface KeyValueStoreResource extends Omit<Schemas['KeyValueStoreResource'], keyof KeyValueStoreResourceRePointed>, KeyValueStoreResourceRePointed {
165
156
  }
166
157
  /** Statistics about Key-Value Store usage and storage. */
167
158
  export interface KeyValueStoreStats extends GeneratedKeyValueStoreStats {
@@ -222,6 +213,7 @@ export interface VersionRePointed {
222
213
  }
223
214
  export interface VersionClientNarrowings {
224
215
  sourceType: `${ActorSourceType}`;
216
+ actorPath?: GeneratedVersion['actorPath'];
225
217
  }
226
218
  /**
227
219
  * Fields every Actor version carries, whatever its source type.
@@ -229,6 +221,7 @@ export interface VersionClientNarrowings {
229
221
  * The spec models a version as one flat object with all four source locations optional. This client
230
222
  * keeps a union discriminated on `sourceType` instead, because that narrows the source location down
231
223
  * to the single field which applies -- so the four are dropped here and reinstated per variant.
224
+ * `actorPath` is dropped as well, and only the `SOURCE_FILES` and `TARBALL` variants reinstate it.
232
225
  */
233
226
  export interface BaseVersion<SourceType extends `${ActorSourceType}`> extends Omit<GeneratedVersion, keyof VersionClientNarrowings | keyof VersionRePointed | VersionSourceLocation>, VersionRePointed {
234
227
  sourceType: SourceType;
@@ -239,6 +232,12 @@ export interface BaseVersion<SourceType extends `${ActorSourceType}`> extends Om
239
232
  */
240
233
  export interface VersionSourceFiles extends BaseVersion<`${ActorSourceType.SourceFiles}`> {
241
234
  sourceFiles: (SourceCodeFile | SourceCodeFolder)[];
235
+ /**
236
+ * The Actor's folder inside the uploaded source, as a POSIX path relative to the upload root, such as
237
+ * `actors/typescript-actor`. When absent or `null`, the upload root is the Actor's folder. It has 1 to 255
238
+ * characters, with no leading, trailing, or repeated `/` and no `.` or `..` segment.
239
+ */
240
+ actorPath?: GeneratedVersion['actorPath'];
242
241
  }
243
242
  /** An Actor version built from a Git repository. */
244
243
  export interface VersionGitRepo extends BaseVersion<`${ActorSourceType.GitRepo}`> {
@@ -247,6 +246,12 @@ export interface VersionGitRepo extends BaseVersion<`${ActorSourceType.GitRepo}`
247
246
  /** An Actor version built from a downloadable tarball or ZIP archive. */
248
247
  export interface VersionTarball extends BaseVersion<`${ActorSourceType.Tarball}`> {
249
248
  tarballUrl: NonNullable<GeneratedVersion['tarballUrl']>;
249
+ /**
250
+ * The Actor's folder inside the archive, as a POSIX path relative to the archive root, such as
251
+ * `actors/typescript-actor`. When absent or `null`, the archive root is the Actor's folder. It has 1 to 255
252
+ * characters, with no leading, trailing, or repeated `/` and no `.` or `..` segment.
253
+ */
254
+ actorPath?: GeneratedVersion['actorPath'];
250
255
  }
251
256
  /** An Actor version built from a GitHub Gist. */
252
257
  export interface VersionGitHubGist extends BaseVersion<`${ActorSourceType.GitHubGist}`> {
@@ -303,19 +308,6 @@ export interface DefaultRunOptionsRePointed {
303
308
  /** Default configuration options for Actor runs. */
304
309
  export interface DefaultRunOptions extends Omit<Schemas['DefaultRunOptions'], keyof DefaultRunOptionsRePointed>, DefaultRunOptionsRePointed {
305
310
  }
306
- /**
307
- * Fields of an Actor definition that the OpenAPI spec does not describe yet.
308
- *
309
- * TODO: Remove once the spec covers them.
310
- */
311
- export interface ActorDefinitionSpecGaps {
312
- /**
313
- * Output schema for the Actor.
314
- *
315
- * @see https://docs.apify.com/platform/actors/development/actor-definition/output-schema
316
- */
317
- output?: object | null;
318
- }
319
311
  type GeneratedActorDefinition = Schemas['ActorDefinition'];
320
312
  /**
321
313
  * Actor definition from the `.actor/actor.json` file.
@@ -324,7 +316,7 @@ type GeneratedActorDefinition = Schemas['ActorDefinition'];
324
316
  * @see https://docs.apify.com/platform/actors/development/actor-definition/actor-json
325
317
  * @since Added in 2.11.0
326
318
  */
327
- export interface ActorDefinition extends GeneratedActorDefinition, ActorDefinitionSpecGaps {
319
+ export interface ActorDefinition extends GeneratedActorDefinition {
328
320
  }
329
321
  export interface ActorChargeEventRePointed {
330
322
  eventTieredPricingUsd?: TieredPricingPerEvent;
@@ -437,6 +429,7 @@ export interface ActorListItem extends Omit<Schemas['ActorListItem'], keyof Acto
437
429
  type GeneratedBuildUsage = Schemas['BuildUsage'];
438
430
  type GeneratedBuildStats = Schemas['BuildStats'];
439
431
  type GeneratedBuildOptions = Schemas['BuildOptions'];
432
+ type GeneratedBuildActVersion = NonNullable<Schemas['Build']['actVersion']>;
440
433
  /**
441
434
  * Resource usage for an Actor build.
442
435
  * @since Added in 2.7.2
@@ -463,6 +456,10 @@ export interface BuildRePointed {
463
456
  usageUsd?: BuildUsage | null;
464
457
  actorDefinition?: ActorDefinition | null;
465
458
  status: ValueOf<typeof ACTOR_JOB_STATUSES>;
459
+ /** The API returns `buildTag` as `null` for some builds, which the specification types as a string. */
460
+ actVersion?: Omit<GeneratedBuildActVersion, 'buildTag'> & {
461
+ buildTag?: string | null;
462
+ };
466
463
  }
467
464
  /**
468
465
  * Represents an Actor build.
@@ -519,20 +516,12 @@ export interface RunMetaRePointed {
519
516
  /** Metadata about how an Actor run was initiated. */
520
517
  export interface RunMeta extends Omit<Schemas['RunMeta'], keyof RunMetaRePointed>, RunMetaRePointed {
521
518
  }
522
- /**
523
- * Fields the API returns in an Actor run's options that the OpenAPI spec does not describe yet.
524
- *
525
- * TODO: Remove once the spec covers it.
526
- */
527
- export interface RunOptionsSpecGaps {
528
- restartOnError?: boolean;
529
- }
530
519
  /**
531
520
  * Configuration options used for an Actor run.
532
521
  *
533
522
  * These are the actual options that were applied to the run (may differ from requested options).
534
523
  */
535
- export interface RunOptions extends GeneratedRunOptions, RunOptionsSpecGaps {
524
+ export interface RunOptions extends GeneratedRunOptions {
536
525
  }
537
526
  export interface RunListItemRePointed {
538
527
  meta: RunMeta;
@@ -604,19 +593,8 @@ export interface Task extends Omit<Schemas['Task'], keyof TaskRePointed>, TaskRe
604
593
  export interface TaskListItemRePointed {
605
594
  stats?: TaskStats | null;
606
595
  }
607
- /**
608
- * Fields the API returns on a listed task that the OpenAPI spec does not describe yet.
609
- *
610
- * `description` is deliberately not here, although the spec has it on the full `Task` resource: the
611
- * list endpoint publishes a smaller set of fields, and that is one of the fields it leaves out.
612
- *
613
- * TODO: Remove once the spec covers it.
614
- */
615
- export interface TaskListItemSpecGaps {
616
- title?: string | null;
617
- }
618
596
  /** A task as it appears in a listing, which carries fewer fields than the full resource. */
619
- export interface TaskListItem extends Omit<Schemas['TaskListItem'], keyof TaskListItemRePointed>, TaskListItemRePointed, TaskListItemSpecGaps {
597
+ export interface TaskListItem extends Omit<Schemas['TaskListItem'], keyof TaskListItemRePointed>, TaskListItemRePointed {
620
598
  }
621
599
  export interface StoreActorRePointed {
622
600
  stats: ActorStats;
@@ -675,17 +653,6 @@ export interface WebhookLastDispatchRePointed {
675
653
  /** The summary of a webhook's most recent dispatch that the webhook resource carries. */
676
654
  export interface WebhookLastDispatch extends Omit<Schemas['WebhookLastDispatch'], keyof WebhookLastDispatchRePointed>, WebhookLastDispatchRePointed {
677
655
  }
678
- /**
679
- * Fields the API returns on a webhook that the OpenAPI spec does not describe yet.
680
- *
681
- * The spec does carry `isApifyIntegration` on `WebhookListItem`, the listing shape, and simply omits it
682
- * from the full `WebhookResource` schema.
683
- *
684
- * TODO: Remove once the spec covers it.
685
- */
686
- export interface WebhookResourceSpecGaps {
687
- isApifyIntegration?: boolean;
688
- }
689
656
  export interface WebhookResourceRePointed {
690
657
  condition: WebhookCondition;
691
658
  stats?: WebhookStats | null;
@@ -698,7 +665,7 @@ export interface WebhookResourceRePointed {
698
665
  * Webhooks send HTTP POST requests to specified URLs when certain events occur
699
666
  * (e.g., Actor run succeeds, fails, or times out).
700
667
  */
701
- export interface WebhookResource extends Omit<Schemas['WebhookResource'], keyof WebhookResourceRePointed>, WebhookResourceRePointed, WebhookResourceSpecGaps {
668
+ export interface WebhookResource extends Omit<Schemas['WebhookResource'], keyof WebhookResourceRePointed>, WebhookResourceRePointed {
702
669
  }
703
670
  type GeneratedScheduleActionRunInput = Schemas['ScheduleActionRunInput'];
704
671
  /**
@@ -741,12 +708,15 @@ export interface ScheduleRePointed {
741
708
  export interface ScheduleClientNarrowings {
742
709
  timezone: Timezone;
743
710
  }
711
+ export interface ScheduleSpecNarrowings {
712
+ uiState?: NonNullable<Schemas['Schedule']['uiState']> | null;
713
+ }
744
714
  /**
745
715
  * Represents a schedule for automated Actor or Task runs.
746
716
  *
747
717
  * Schedules use cron expressions to define when Actors or Tasks should run automatically.
748
718
  */
749
- export interface Schedule extends Omit<Schemas['Schedule'], keyof ScheduleRePointed | keyof ScheduleClientNarrowings>, ScheduleRePointed, ScheduleClientNarrowings {
719
+ export interface Schedule extends Omit<Schemas['Schedule'], keyof ScheduleRePointed | keyof ScheduleClientNarrowings | keyof ScheduleSpecNarrowings>, ScheduleRePointed, ScheduleClientNarrowings, ScheduleSpecNarrowings {
750
720
  }
751
721
  type GeneratedUserProfile = Schemas['UserProfile'];
752
722
  type GeneratedProxyGroup = Schemas['ProxyGroup'];
@@ -907,12 +877,11 @@ export interface RequestQueueStats extends GeneratedRequestQueueStats {
907
877
  * Fields the API returns on a request queue that the OpenAPI spec does not describe yet.
908
878
  *
909
879
  * The spec does carry `username` on `RequestQueueListItem`, the listing shape, and simply omits it from the
910
- * full `RequestQueueResource` schema. `title` is absent from either.
880
+ * full `RequestQueueResource` schema.
911
881
  *
912
- * TODO: Remove once the spec covers them.
882
+ * TODO: Remove once the spec covers it.
913
883
  */
914
884
  export interface RequestQueueResourceSpecGaps {
915
- title?: string;
916
885
  username?: string;
917
886
  }
918
887
  export interface RequestQueueResourceRePointed {
@@ -5,6 +5,7 @@ import { ResourceClient } from '../base/resource_client.js';
5
5
  import type { ActorResource, Run } from '../models.js';
6
6
  import type { TimeoutOptions } from '../timeouts.js';
7
7
  import type { Dictionary } from '../utils.js';
8
+ import { ActorServerClient } from './actor_server.js';
8
9
  import { ActorVersionClient } from './actor_version.js';
9
10
  import { ActorVersionCollectionClient } from './actor_version_collection.js';
10
11
  import type { Build, BuildClientGetOptions } from './build.js';
@@ -37,6 +38,7 @@ export type { ActorResource, ActorChargeEvent, ActorChargeEvents, ActorDefinitio
37
38
  * @see https://docs.apify.com/platform/actors
38
39
  */
39
40
  export declare class ActorClient extends ResourceClient {
41
+ #private;
40
42
  /**
41
43
  * @hidden
42
44
  */
@@ -293,6 +295,34 @@ export declare class ActorClient extends ResourceClient {
293
295
  * @see https://docs.apify.com/api/v2/act-webhooks-get
294
296
  */
295
297
  webhooks(): WebhookCollectionClient;
298
+ /**
299
+ * Returns a client for the server interface of this Actor.
300
+ *
301
+ * A Server Actor runs a web server, its server interface, that is called over HTTP without starting a run for
302
+ * each call. Server Actors were formerly called Actor Standby, and {@link standby} is a deprecated alias of this
303
+ * method. Every call returns the same client, so the server URL it fetches is reused.
304
+ *
305
+ * @returns The client for the server interface of this Actor
306
+ * @see https://docs.apify.com/platform/actors/running/standby
307
+ *
308
+ * @example
309
+ * ```javascript
310
+ * const response = await client.actor('username/actor-name').server().request('/search', {
311
+ * params: { q: 'apify' },
312
+ * });
313
+ * ```
314
+ */
315
+ server(): ActorServerClient;
316
+ /**
317
+ * Returns a client for the server interface of this Actor in Standby mode.
318
+ *
319
+ * Named after Actor Standby, the former name of Server Actors.
320
+ *
321
+ * @deprecated Use {@link server} instead. Will be removed in v4.
322
+ * @returns The client for the server interface of this Actor
323
+ * @see https://docs.apify.com/platform/actors/running/standby
324
+ */
325
+ standby(): ActorServerClient;
296
326
  }
297
327
  /**
298
328
  * Fields that can be updated when modifying an Actor.
@@ -6,6 +6,7 @@ import * as schemas from '../schemas.js';
6
6
  import { timeoutOptionsSchema, timeoutOptionsShape } from '../timeouts.js';
7
7
  import { anyObjectSchema, isStream, parseArgument, parseResponse, stringifyWebhooksToBase64 } from '../utils.js';
8
8
  import { startWaitingForResources } from '../wait_for_resources.js';
9
+ import { ActorServerClient } from './actor_server.js';
9
10
  import { ActorVersionClient } from './actor_version.js';
10
11
  import { ActorVersionCollectionClient } from './actor_version_collection.js';
11
12
  import { BuildClient } from './build.js';
@@ -81,6 +82,7 @@ const lastRunOptionsSchema = z.strictObject({
81
82
  * @see https://docs.apify.com/platform/actors
82
83
  */
83
84
  export class ActorClient extends ResourceClient {
85
+ #serverClient;
84
86
  /**
85
87
  * @hidden
86
88
  */
@@ -475,4 +477,45 @@ export class ActorClient extends ResourceClient {
475
477
  webhooks() {
476
478
  return new WebhookCollectionClient(this.subResourceOptions());
477
479
  }
480
+ /**
481
+ * Returns a client for the server interface of this Actor.
482
+ *
483
+ * A Server Actor runs a web server, its server interface, that is called over HTTP without starting a run for
484
+ * each call. Server Actors were formerly called Actor Standby, and {@link standby} is a deprecated alias of this
485
+ * method. Every call returns the same client, so the server URL it fetches is reused.
486
+ *
487
+ * @returns The client for the server interface of this Actor
488
+ * @see https://docs.apify.com/platform/actors/running/standby
489
+ *
490
+ * @example
491
+ * ```javascript
492
+ * const response = await client.actor('username/actor-name').server().request('/search', {
493
+ * params: { q: 'apify' },
494
+ * });
495
+ * ```
496
+ */
497
+ server() {
498
+ this.#serverClient ??= new ActorServerClient({
499
+ baseUrl: this.baseUrl,
500
+ publicBaseUrl: this.publicBaseUrl,
501
+ apifyClient: this.apifyClient,
502
+ httpClient: this.httpClient,
503
+ id: this.id,
504
+ params: this.params,
505
+ });
506
+ return this.#serverClient;
507
+ }
508
+ /**
509
+ * Returns a client for the server interface of this Actor in Standby mode.
510
+ *
511
+ * Named after Actor Standby, the former name of Server Actors.
512
+ *
513
+ * @deprecated Use {@link server} instead. Will be removed in v4.
514
+ * @returns The client for the server interface of this Actor
515
+ * @see https://docs.apify.com/platform/actors/running/standby
516
+ */
517
+ standby() {
518
+ this.httpClient.logger.deprecated('`standby()` is deprecated and will be removed in v4. Use `server()` instead.');
519
+ return this.server();
520
+ }
478
521
  }
@@ -0,0 +1,149 @@
1
+ import type { Readable } from 'node:stream';
2
+ import type { ApiClientSubResourceOptions } from '../base/api_client.js';
3
+ import { ResourceClient } from '../base/resource_client.js';
4
+ import type { ApifyResponse, ApifyResponseType, HttpMethod } from '../http_clients/index.js';
5
+ import type { HttpCompressor } from '../http_compressors/base.js';
6
+ import type { HttpCompressionAlgorithm } from '../http_compressors/resolve.js';
7
+ import type { TimeoutOptions } from '../timeouts.js';
8
+ /**
9
+ * Client for the server interface of a specific Actor.
10
+ *
11
+ * Provides methods to work with the web server of a Server Actor, such as sending it requests or getting its OpenAPI
12
+ * specification. Get an instance with {@link ActorClient.server}.
13
+ *
14
+ * @example
15
+ * ```javascript
16
+ * const client = new ApifyClient({ token: 'my-token' });
17
+ * const actorServerClient = client.actor('username/actor-name').server();
18
+ *
19
+ * const response = await actorServerClient.request('/search', { params: { q: 'apify' } });
20
+ * console.log(response.data);
21
+ * ```
22
+ *
23
+ * @see https://docs.apify.com/platform/actors/running/standby
24
+ */
25
+ export declare class ActorServerClient extends ResourceClient {
26
+ #private;
27
+ /**
28
+ * @hidden
29
+ */
30
+ constructor(options: ApiClientSubResourceOptions);
31
+ /**
32
+ * Returns the URL of the Actor's server.
33
+ *
34
+ * The URL is the Actor's `standbyUrl`, fetched from the API by the first call of this method or
35
+ * {@link getOpenApiSpec} and reused by later calls on this client. Use it to call the server with another HTTP
36
+ * client, for example one generated from the server's OpenAPI specification.
37
+ *
38
+ * @param options - Request options
39
+ * @param options.timeoutSecs - Timeout for the API request. Default is `'short'`.
40
+ * @returns The URL of the Actor's server
41
+ * @throws {ApifyClientError} When the Actor is not a Server Actor.
42
+ * @throws {NotFoundError} When the Actor does not exist.
43
+ * @see https://docs.apify.com/platform/actors/running/standby
44
+ */
45
+ getUrl(options?: TimeoutOptions): Promise<string>;
46
+ /**
47
+ * Returns the OpenAPI specification of the Actor's server.
48
+ *
49
+ * The specification is the web server schema from the Actor's definition, taken from the build that serves the
50
+ * server interface: the build set in `actorStandby.build`, or `latest` if none is set. Use it to generate an HTTP
51
+ * client for the server, and point that client at the URL returned by {@link getUrl}.
52
+ *
53
+ * @param options - Request options
54
+ * @param options.timeoutSecs - Timeout for each API request. Default is `'short'`.
55
+ * @returns The OpenAPI specification of the Actor's server, or `undefined` if the Actor's definition doesn't
56
+ * include one
57
+ * @throws {ApifyClientError} When the Actor is not a Server Actor, or the build that serves its server interface
58
+ * doesn't exist.
59
+ * @throws {NotFoundError} When the Actor does not exist.
60
+ * @see https://docs.apify.com/platform/actors/development/actor-definition/web-server-schema
61
+ */
62
+ getOpenApiSpec(options?: TimeoutOptions): Promise<Record<string, unknown> | undefined>;
63
+ /**
64
+ * Sends an HTTP request to the Actor's server.
65
+ *
66
+ * The request goes to the URL returned by {@link getUrl} and carries the client's token in the
67
+ * `X-Apify-Authorization` header, which the platform consumes, so it never reaches the Actor's code. Headers you
68
+ * pass, `Authorization` included, reach the Actor's server as they are. The first request to an idle Actor waits
69
+ * for the platform to start a server run, which is why the timeout defaults to `'long'`.
70
+ *
71
+ * The method resolves to any response of the server, error statuses included. A rate-limit (429) or Service
72
+ * Unavailable (503) response is retried with the client's retry settings, and the last one is returned once the
73
+ * retries run out. The Actor's code can return these statuses too, and then it gets the request again. A redirect
74
+ * is returned as it is, since following it would send the token to a host the Actor's code picked. A browser
75
+ * follows redirects itself, though, so there the token goes with a redirect. Request bodies are sent uncompressed
76
+ * unless `compression` is set, since the Actor's server may not decode a compressed body.
77
+ *
78
+ * @template T - Type of the parsed response body.
79
+ * @param path - The path on the Actor's server, for example `/search`. It is always resolved against the server
80
+ * URL, so the request, and the token with it, can't be sent to another host. Pass the query in `params`. A
81
+ * fragment (`#...`) is dropped, since it's never sent to the server.
82
+ * @param options - Request options
83
+ * @param options.method - HTTP method of the request. Default is `'GET'`.
84
+ * @param options.params - Query parameters of the request, converted the same way as for API calls.
85
+ * @param options.headers - Additional headers of the request.
86
+ * @param options.data - Request body, serialized the same way as for API calls: a plain object or array is sent
87
+ * as JSON, and a string or binary value as it is.
88
+ * @param options.parentRequestId - The `X-Actor-Request-ID` header of the request your Server Actor is handling,
89
+ * sent on as the same header so the called Actor charges at that request's pricing tier.
90
+ * @param options.compression - Compression algorithm for the request body, as a name or an {@link HttpCompressor}.
91
+ * The body is compressed under the same conditions as for API calls. Set it only if the Actor's server decodes
92
+ * the resulting `Content-Encoding`.
93
+ * @param options.responseType - How to return the response body: `'parsed'` by its content type, `'buffer'` as
94
+ * raw bytes, or `'stream'` as a Readable stream with the body unread. A stream holds its connection open until
95
+ * you consume it to the end or destroy it. Node.js only. Default is `'parsed'`.
96
+ * @param options.timeoutSecs - Timeout for the HTTP request. Default is `'long'`. With `'stream'`, it bounds the
97
+ * wait for the server to start responding.
98
+ * @returns The response of the Actor's server, with the body in the form `responseType` asks for. An error
99
+ * response whose body doesn't parse as its content type comes with the raw bytes in `data`.
100
+ * @throws {ApifyClientError} When the Actor is not a Server Actor.
101
+ * @throws {InvalidResponseBodyError} When a success response's body doesn't parse as its content type, with
102
+ * `responseType: 'parsed'`.
103
+ * @throws {NotFoundError} When the Actor does not exist.
104
+ * @see https://docs.apify.com/platform/actors/running/standby
105
+ */
106
+ request<T = any>(path?: string, options?: ActorServerRequestOptions & {
107
+ responseType?: 'parsed';
108
+ }): Promise<ApifyResponse<T>>;
109
+ request(path: string, options: ActorServerRequestOptions & {
110
+ responseType: 'buffer';
111
+ }): Promise<ApifyResponse<Buffer>>;
112
+ request(path: string, options: ActorServerRequestOptions & {
113
+ responseType: 'stream';
114
+ }): Promise<ApifyResponse<Readable>>;
115
+ request(path?: string, options?: ActorServerRequestOptions): Promise<ApifyResponse>;
116
+ }
117
+ /**
118
+ * Options of {@link ActorServerClient.request}.
119
+ */
120
+ export interface ActorServerRequestOptions extends TimeoutOptions {
121
+ /** HTTP method of the request. @default 'GET' */
122
+ method?: HttpMethod;
123
+ /** Query parameters of the request, converted the same way as for API calls. */
124
+ params?: Record<string, unknown>;
125
+ /** Additional headers of the request. */
126
+ headers?: Record<string, string>;
127
+ /**
128
+ * Request body, serialized the same way as for API calls: a plain object or array is sent as JSON, and a string
129
+ * or binary value as it is.
130
+ */
131
+ data?: unknown;
132
+ /**
133
+ * The `X-Actor-Request-ID` header of the request your Server Actor is handling. It's sent on as the same header,
134
+ * so the called Actor charges at that request's pricing tier.
135
+ * @see https://docs.apify.com/platform/actors/development/programming-interface/standby#compose-server-actors
136
+ */
137
+ parentRequestId?: string;
138
+ /**
139
+ * Compression algorithm for the request body, as a name or an {@link HttpCompressor}. The body is sent
140
+ * uncompressed when it's not set, since the Actor's server may not decode a compressed body.
141
+ */
142
+ compression?: HttpCompressionAlgorithm | HttpCompressor;
143
+ /**
144
+ * How to return the response body: `'parsed'` by its content type, `'buffer'` as raw bytes, or `'stream'` as a
145
+ * Readable stream with the body unread. Node.js only.
146
+ * @default 'parsed'
147
+ */
148
+ responseType?: ApifyResponseType;
149
+ }