apify-client 2.23.5-beta.24 → 2.23.5-beta.26
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.
- package/dist/bundle.js +62 -24
- package/dist/bundle.js.map +1 -1
- package/dist/http_client.js +1 -1
- package/dist/interceptors.js +6 -6
- package/dist/resource_clients/actor.d.ts +1 -1
- package/dist/resource_clients/actor.js +1 -1
- package/dist/utils.d.ts +7 -2
- package/dist/utils.js +50 -17
- package/package.json +1 -1
package/dist/http_client.js
CHANGED
|
@@ -122,7 +122,7 @@ class HttpClient {
|
|
|
122
122
|
this.axios.defaults.httpsAgent = this.httpsAgent;
|
|
123
123
|
// Works only in Node. Cannot be set in browser
|
|
124
124
|
const isAtHome = !!process.env[consts_1.APIFY_ENV_VARS.IS_AT_HOME];
|
|
125
|
-
let userAgent = `ApifyClient/${version} (${os.
|
|
125
|
+
let userAgent = `ApifyClient/${version} (${os.platform()}; Node/${process.version}); isAtHome/${isAtHome}`;
|
|
126
126
|
if (this.userAgentSuffix) {
|
|
127
127
|
userAgent += `; ${(0, utils_1.asArray)(this.userAgentSuffix).join('; ')}`;
|
|
128
128
|
}
|
package/dist/interceptors.js
CHANGED
|
@@ -69,14 +69,14 @@ function stringifyWithFunctions(obj) {
|
|
|
69
69
|
return typeof value === 'function' ? value.toString() : value;
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
|
-
async function
|
|
72
|
+
async function maybeCompressRequest(config) {
|
|
73
73
|
if (config.headers?.['content-encoding'])
|
|
74
74
|
return config;
|
|
75
|
-
const
|
|
76
|
-
if (
|
|
75
|
+
const maybeCompressed = await (0, utils_1.maybeCompressValue)(config.data);
|
|
76
|
+
if (maybeCompressed) {
|
|
77
77
|
config.headers ??= {};
|
|
78
|
-
config.headers['content-encoding'] =
|
|
79
|
-
config.data =
|
|
78
|
+
config.headers['content-encoding'] = maybeCompressed.encoding;
|
|
79
|
+
config.data = maybeCompressed.data;
|
|
80
80
|
}
|
|
81
81
|
return config;
|
|
82
82
|
}
|
|
@@ -103,7 +103,7 @@ function parseResponseData(response) {
|
|
|
103
103
|
return response;
|
|
104
104
|
}
|
|
105
105
|
exports.requestInterceptors = [
|
|
106
|
-
|
|
106
|
+
maybeCompressRequest,
|
|
107
107
|
serializeRequest,
|
|
108
108
|
ensureHeadersPrototype,
|
|
109
109
|
];
|
|
@@ -149,7 +149,7 @@ export declare class ActorClient extends ResourceClient {
|
|
|
149
149
|
* (e.g., `'latest'` or `'1.2.345'`). If not provided, uses the default build.
|
|
150
150
|
* @param options.contentType - Content type of the input. If specified, input must be a string or Buffer.
|
|
151
151
|
* @returns `true` if the input is valid. Invalid input causes the underlying API call to throw an `ApifyApiError`.
|
|
152
|
-
* @see https://docs.apify.com/api/v2/act-input-
|
|
152
|
+
* @see https://docs.apify.com/api/v2/act-validate-input-post
|
|
153
153
|
*
|
|
154
154
|
* @example
|
|
155
155
|
* ```javascript
|
|
@@ -234,7 +234,7 @@ class ActorClient extends resource_client_1.ResourceClient {
|
|
|
234
234
|
* (e.g., `'latest'` or `'1.2.345'`). If not provided, uses the default build.
|
|
235
235
|
* @param options.contentType - Content type of the input. If specified, input must be a string or Buffer.
|
|
236
236
|
* @returns `true` if the input is valid. Invalid input causes the underlying API call to throw an `ApifyApiError`.
|
|
237
|
-
* @see https://docs.apify.com/api/v2/act-input-
|
|
237
|
+
* @see https://docs.apify.com/api/v2/act-validate-input-post
|
|
238
238
|
*
|
|
239
239
|
* @example
|
|
240
240
|
* ```javascript
|
package/dist/utils.d.ts
CHANGED
|
@@ -41,10 +41,15 @@ export declare function parseDateFields(input: JsonValue, shouldParseField?: ((k
|
|
|
41
41
|
* Helper function that converts array of webhooks to base64 string
|
|
42
42
|
*/
|
|
43
43
|
export declare function stringifyWebhooksToBase64(webhooks: WebhookUpdateData[]): string | undefined;
|
|
44
|
+
export interface CompressedValue {
|
|
45
|
+
data: Buffer;
|
|
46
|
+
encoding: 'br' | 'gzip';
|
|
47
|
+
}
|
|
44
48
|
/**
|
|
45
|
-
*
|
|
49
|
+
* Compress the passed value using brotli if available or using gzip as a fallback. Returns undefined
|
|
50
|
+
* if the data is too small / wrong type.
|
|
46
51
|
*/
|
|
47
|
-
export declare function
|
|
52
|
+
export declare function maybeCompressValue(value: unknown): Promise<CompressedValue | undefined>;
|
|
48
53
|
/**
|
|
49
54
|
* Helper function slice the items from array to fit the max byte length.
|
|
50
55
|
*/
|
package/dist/utils.js
CHANGED
|
@@ -5,7 +5,7 @@ exports.pluckData = pluckData;
|
|
|
5
5
|
exports.catchNotFoundOrThrow = catchNotFoundOrThrow;
|
|
6
6
|
exports.parseDateFields = parseDateFields;
|
|
7
7
|
exports.stringifyWebhooksToBase64 = stringifyWebhooksToBase64;
|
|
8
|
-
exports.
|
|
8
|
+
exports.maybeCompressValue = maybeCompressValue;
|
|
9
9
|
exports.sliceArrayByByteLength = sliceArrayByByteLength;
|
|
10
10
|
exports.isNode = isNode;
|
|
11
11
|
exports.isBuffer = isBuffer;
|
|
@@ -19,7 +19,7 @@ const ow_1 = tslib_1.__importDefault(require("ow"));
|
|
|
19
19
|
const NOT_FOUND_STATUS_CODE = 404;
|
|
20
20
|
const RECORD_NOT_FOUND_TYPE = 'record-not-found';
|
|
21
21
|
const RECORD_OR_TOKEN_NOT_FOUND_TYPE = 'record-or-token-not-found';
|
|
22
|
-
const
|
|
22
|
+
const MIN_COMPRESS_BYTES = 1024;
|
|
23
23
|
/**
|
|
24
24
|
* Returns object's 'data' property or throws if parameter is not an object,
|
|
25
25
|
* or an object without a 'data' property.
|
|
@@ -99,26 +99,59 @@ function stringifyWebhooksToBase64(webhooks) {
|
|
|
99
99
|
}
|
|
100
100
|
let gzipPromisified;
|
|
101
101
|
/**
|
|
102
|
-
* Gzip provided value
|
|
102
|
+
* Gzip-compress the provided value.
|
|
103
103
|
*/
|
|
104
|
-
async function
|
|
105
|
-
if (!
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
104
|
+
async function gzipValue(value) {
|
|
105
|
+
if (!gzipPromisified) {
|
|
106
|
+
const { promisify } = await import('node:util');
|
|
107
|
+
const { gzip } = await import('node:zlib');
|
|
108
|
+
gzipPromisified = promisify(gzip);
|
|
109
|
+
}
|
|
110
|
+
return gzipPromisified(value);
|
|
111
|
+
}
|
|
112
|
+
// null = confirmed unavailable; undefined = not yet checked
|
|
113
|
+
let brotliCompressPromisified;
|
|
114
|
+
/**
|
|
115
|
+
* Brotli-compress the provided value, or return undefined if brotli is unavailable
|
|
116
|
+
* (Node.js < v10.16.0), this is a strict defensive guard.
|
|
117
|
+
*/
|
|
118
|
+
async function maybeBrotliValue(value) {
|
|
119
|
+
if (brotliCompressPromisified === undefined) {
|
|
120
|
+
const { promisify } = await import('node:util');
|
|
121
|
+
const { brotliCompress, constants } = await import('node:zlib');
|
|
122
|
+
if (typeof brotliCompress === 'function') {
|
|
123
|
+
const compress = promisify(brotliCompress);
|
|
124
|
+
brotliCompressPromisified = async (value) => compress(value, { params: { [constants.BROTLI_PARAM_QUALITY]: 6 } });
|
|
117
125
|
}
|
|
118
|
-
|
|
126
|
+
else {
|
|
127
|
+
brotliCompressPromisified = null;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (brotliCompressPromisified !== null) {
|
|
131
|
+
return brotliCompressPromisified(value);
|
|
119
132
|
}
|
|
120
133
|
return undefined;
|
|
121
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Compress the passed value using brotli if available or using gzip as a fallback. Returns undefined
|
|
137
|
+
* if the data is too small / wrong type.
|
|
138
|
+
*/
|
|
139
|
+
async function maybeCompressValue(value) {
|
|
140
|
+
if (!isNode())
|
|
141
|
+
return undefined;
|
|
142
|
+
// Request compression is not that important so let's
|
|
143
|
+
// skip it instead of throwing for unsupported types.
|
|
144
|
+
if (typeof value !== 'string' && !Buffer.isBuffer(value))
|
|
145
|
+
return undefined;
|
|
146
|
+
const areDataLargeEnough = Buffer.byteLength(value) >= MIN_COMPRESS_BYTES;
|
|
147
|
+
if (!areDataLargeEnough)
|
|
148
|
+
return undefined;
|
|
149
|
+
const brotli = await maybeBrotliValue(value);
|
|
150
|
+
if (brotli)
|
|
151
|
+
return { data: brotli, encoding: 'br' };
|
|
152
|
+
const gzipped = await gzipValue(value);
|
|
153
|
+
return { data: gzipped, encoding: 'gzip' };
|
|
154
|
+
}
|
|
122
155
|
/**
|
|
123
156
|
* Helper function slice the items from array to fit the max byte length.
|
|
124
157
|
*/
|