apify-client 3.0.0-beta.96 → 3.0.0-beta.97
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.
|
@@ -384,3 +384,8 @@ export declare abstract class HttpClient {
|
|
|
384
384
|
*/
|
|
385
385
|
protected computeTimeoutMillis(attempt: number, timeoutSecs?: Timeout): number | undefined;
|
|
386
386
|
}
|
|
387
|
+
/**
|
|
388
|
+
* Merges two header records, header names compared case-insensitively. A header from `override` replaces a
|
|
389
|
+
* same-named header in `base` whatever the casing of either, and keeps the casing it was passed with.
|
|
390
|
+
*/
|
|
391
|
+
export declare function mergeHeaders(base: Record<string, string>, override?: Record<string, string>): Record<string, string>;
|
|
@@ -481,7 +481,7 @@ function getHeader(headers, name) {
|
|
|
481
481
|
* Merges two header records, header names compared case-insensitively. A header from `override` replaces a
|
|
482
482
|
* same-named header in `base` whatever the casing of either, and keeps the casing it was passed with.
|
|
483
483
|
*/
|
|
484
|
-
function mergeHeaders(base, override) {
|
|
484
|
+
export function mergeHeaders(base, override) {
|
|
485
485
|
const merged = { ...base };
|
|
486
486
|
for (const [key, value] of Object.entries(override ?? {})) {
|
|
487
487
|
for (const existing of Object.keys(merged)) {
|
|
@@ -85,6 +85,8 @@ export declare class ActorServerClient extends ResourceClient {
|
|
|
85
85
|
* @param options.headers - Additional headers of the request.
|
|
86
86
|
* @param options.data - Request body, serialized the same way as for API calls: a plain object or array is sent
|
|
87
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.
|
|
88
90
|
* @param options.compression - Compression algorithm for the request body, as a name or an {@link HttpCompressor}.
|
|
89
91
|
* The body is compressed under the same conditions as for API calls. Set it only if the Actor's server decodes
|
|
90
92
|
* the resulting `Content-Encoding`.
|
|
@@ -127,6 +129,12 @@ export interface ActorServerRequestOptions extends TimeoutOptions {
|
|
|
127
129
|
* or binary value as it is.
|
|
128
130
|
*/
|
|
129
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;
|
|
130
138
|
/**
|
|
131
139
|
* Compression algorithm for the request body, as a name or an {@link HttpCompressor}. The body is sent
|
|
132
140
|
* uncompressed when it's not set, since the Actor's server may not decode a compressed body.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { ApifyClientError } from '../apify_client_error.js';
|
|
3
3
|
import { ResourceClient } from '../base/resource_client.js';
|
|
4
|
+
import { mergeHeaders } from '../http_clients/base.js';
|
|
4
5
|
import { compressionSchema, resolveCompressor } from '../http_compressors/resolve.js';
|
|
5
6
|
import * as schemas from '../schemas.js';
|
|
6
7
|
import { timeoutOptionsSchema, timeoutOptionsShape } from '../timeouts.js';
|
|
@@ -38,6 +39,7 @@ const requestOptionsSchema = z.strictObject({
|
|
|
38
39
|
params: z.record(z.string(), z.unknown()).optional(),
|
|
39
40
|
headers: z.record(z.string(), z.string()).optional(),
|
|
40
41
|
data: z.unknown().optional(),
|
|
42
|
+
parentRequestId: z.string().optional(),
|
|
41
43
|
compression: compressionSchema.optional(),
|
|
42
44
|
responseType: z.enum(['parsed', 'buffer', 'stream']).optional(),
|
|
43
45
|
...timeoutOptionsShape,
|
|
@@ -151,7 +153,7 @@ export class ActorServerClient extends ResourceClient {
|
|
|
151
153
|
}
|
|
152
154
|
async request(path = '/', options = {}) {
|
|
153
155
|
parseArgument(path, z.string());
|
|
154
|
-
const { method = 'GET', params, headers, data, compression, responseType, timeoutSecs = 'long', signal, } = parseArgument(options, requestOptionsSchema, 'ActorServerRequestOptions');
|
|
156
|
+
const { method = 'GET', params, headers, data, parentRequestId, compression, responseType, timeoutSecs = 'long', signal, } = parseArgument(options, requestOptionsSchema, 'ActorServerRequestOptions');
|
|
155
157
|
if (responseType === 'stream' && !runtime.isNode) {
|
|
156
158
|
throw new Error("The 'stream' response type can only be used in Node.js environment.");
|
|
157
159
|
}
|
|
@@ -161,7 +163,9 @@ export class ActorServerClient extends ResourceClient {
|
|
|
161
163
|
url: `${serverUrl.replace(/\/+$/, '')}/${serverPath}`,
|
|
162
164
|
method,
|
|
163
165
|
params,
|
|
164
|
-
headers
|
|
166
|
+
headers: parentRequestId === undefined
|
|
167
|
+
? headers
|
|
168
|
+
: mergeHeaders(headers ?? {}, { 'X-Actor-Request-ID': parentRequestId }),
|
|
165
169
|
data,
|
|
166
170
|
compression: compression === undefined ? false : resolveCompressor(compression),
|
|
167
171
|
authorizationHeader: 'X-Apify-Authorization',
|