apify-client 2.23.5-beta.3 → 2.23.5-beta.30
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/apify_api_error.js +37 -84
- package/dist/apify_client.js +6 -36
- package/dist/base/api_client.js +10 -56
- package/dist/bundle.js +118 -27
- package/dist/bundle.js.map +1 -1
- package/dist/http_client.js +16 -78
- package/dist/interceptors.js +11 -23
- package/dist/resource_clients/actor.d.ts +53 -3
- package/dist/resource_clients/actor.js +58 -7
- package/dist/resource_clients/actor_collection.d.ts +2 -0
- package/dist/resource_clients/dataset.js +3 -5
- package/dist/resource_clients/dataset_collection.js +1 -1
- package/dist/resource_clients/key_value_store.js +2 -2
- package/dist/resource_clients/key_value_store_collection.js +1 -1
- package/dist/resource_clients/log.js +7 -42
- package/dist/resource_clients/request_queue.js +14 -36
- package/dist/resource_clients/run.js +5 -7
- package/dist/resource_clients/task.d.ts +2 -4
- package/dist/statistics.js +13 -30
- package/dist/utils.d.ts +7 -2
- package/dist/utils.js +56 -48
- package/package.json +6 -6
package/dist/apify_api_error.js
CHANGED
|
@@ -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 =
|
|
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
|
-
|
|
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);
|
package/dist/apify_client.js
CHANGED
|
@@ -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,
|
package/dist/base/api_client.js
CHANGED
|
@@ -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 =
|
|
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
|
@@ -13019,7 +13019,7 @@ class HttpClient {
|
|
|
13019
13019
|
this.axios.defaults.httpsAgent = this.httpsAgent;
|
|
13020
13020
|
// Works only in Node. Cannot be set in browser
|
|
13021
13021
|
const isAtHome = !!process.env[_apify_consts__rspack_import_1.APIFY_ENV_VARS.IS_AT_HOME];
|
|
13022
|
-
let userAgent = `ApifyClient/${version} (${os.
|
|
13022
|
+
let userAgent = `ApifyClient/${version} (${os.platform()}; Node/${process.version}); isAtHome/${isAtHome}`;
|
|
13023
13023
|
if (this.userAgentSuffix) {
|
|
13024
13024
|
userAgent += `; ${(0,_utils__rspack_import_4.asArray)(this.userAgentSuffix).join('; ')}`;
|
|
13025
13025
|
}
|
|
@@ -13221,13 +13221,13 @@ function ensureHeadersPrototype(config) {
|
|
|
13221
13221
|
return typeof value === 'function' ? value.toString() : value;
|
|
13222
13222
|
});
|
|
13223
13223
|
}
|
|
13224
|
-
async function
|
|
13224
|
+
async function maybeCompressRequest(config) {
|
|
13225
13225
|
if (config.headers?.['content-encoding']) return config;
|
|
13226
|
-
const
|
|
13227
|
-
if (
|
|
13226
|
+
const maybeCompressed = await (0,_utils__rspack_import_2.maybeCompressValue)(config.data);
|
|
13227
|
+
if (maybeCompressed) {
|
|
13228
13228
|
config.headers ??= {};
|
|
13229
|
-
config.headers['content-encoding'] =
|
|
13230
|
-
config.data =
|
|
13229
|
+
config.headers['content-encoding'] = maybeCompressed.encoding;
|
|
13230
|
+
config.data = maybeCompressed.data;
|
|
13231
13231
|
}
|
|
13232
13232
|
return config;
|
|
13233
13233
|
}
|
|
@@ -13253,7 +13253,7 @@ function parseResponseData(response) {
|
|
|
13253
13253
|
return response;
|
|
13254
13254
|
}
|
|
13255
13255
|
const requestInterceptors = [
|
|
13256
|
-
|
|
13256
|
+
maybeCompressRequest,
|
|
13257
13257
|
serializeRequest,
|
|
13258
13258
|
ensureHeadersPrototype
|
|
13259
13259
|
];
|
|
@@ -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-validate-input-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.
|
|
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({
|
|
@@ -17908,7 +17961,7 @@ let _computedKey;
|
|
|
17908
17961
|
const NOT_FOUND_STATUS_CODE = 404;
|
|
17909
17962
|
const RECORD_NOT_FOUND_TYPE = 'record-not-found';
|
|
17910
17963
|
const RECORD_OR_TOKEN_NOT_FOUND_TYPE = 'record-or-token-not-found';
|
|
17911
|
-
const
|
|
17964
|
+
const MIN_COMPRESS_BYTES = 1024;
|
|
17912
17965
|
/**
|
|
17913
17966
|
* Returns object's 'data' property or throws if parameter is not an object,
|
|
17914
17967
|
* or an object without a 'data' property.
|
|
@@ -17978,23 +18031,61 @@ const MIN_GZIP_BYTES = 1024;
|
|
|
17978
18031
|
}
|
|
17979
18032
|
let gzipPromisified;
|
|
17980
18033
|
/**
|
|
17981
|
-
* Gzip provided value
|
|
17982
|
-
*/ async function
|
|
17983
|
-
if (!
|
|
17984
|
-
|
|
17985
|
-
|
|
17986
|
-
|
|
17987
|
-
|
|
17988
|
-
|
|
17989
|
-
|
|
17990
|
-
|
|
17991
|
-
|
|
17992
|
-
|
|
18034
|
+
* Gzip-compress the provided value.
|
|
18035
|
+
*/ async function gzipValue(value) {
|
|
18036
|
+
if (!gzipPromisified) {
|
|
18037
|
+
const { promisify } = await Promise.resolve(/* import() */).then(__webpack_require__.t.bind(__webpack_require__, 6029, 23));
|
|
18038
|
+
const { gzip } = await Promise.resolve(/* import() */).then(__webpack_require__.t.bind(__webpack_require__, 1134, 23));
|
|
18039
|
+
gzipPromisified = promisify(gzip);
|
|
18040
|
+
}
|
|
18041
|
+
return gzipPromisified(value);
|
|
18042
|
+
}
|
|
18043
|
+
// null = confirmed unavailable; undefined = not yet checked
|
|
18044
|
+
let brotliCompressPromisified;
|
|
18045
|
+
/**
|
|
18046
|
+
* Brotli-compress the provided value, or return undefined if brotli is unavailable
|
|
18047
|
+
* (Node.js < v10.16.0), this is a strict defensive guard.
|
|
18048
|
+
*/ async function maybeBrotliValue(value) {
|
|
18049
|
+
if (brotliCompressPromisified === undefined) {
|
|
18050
|
+
const { promisify } = await Promise.resolve(/* import() */).then(__webpack_require__.t.bind(__webpack_require__, 6029, 23));
|
|
18051
|
+
const { brotliCompress, constants } = await Promise.resolve(/* import() */).then(__webpack_require__.t.bind(__webpack_require__, 1134, 23));
|
|
18052
|
+
if (typeof brotliCompress === 'function') {
|
|
18053
|
+
const compress = promisify(brotliCompress);
|
|
18054
|
+
brotliCompressPromisified = async (value)=>compress(value, {
|
|
18055
|
+
params: {
|
|
18056
|
+
[constants.BROTLI_PARAM_QUALITY]: 6
|
|
18057
|
+
}
|
|
18058
|
+
});
|
|
18059
|
+
} else {
|
|
18060
|
+
brotliCompressPromisified = null;
|
|
17993
18061
|
}
|
|
17994
|
-
|
|
18062
|
+
}
|
|
18063
|
+
if (brotliCompressPromisified !== null) {
|
|
18064
|
+
return brotliCompressPromisified(value);
|
|
17995
18065
|
}
|
|
17996
18066
|
return undefined;
|
|
17997
18067
|
}
|
|
18068
|
+
/**
|
|
18069
|
+
* Compress the passed value using brotli if available or using gzip as a fallback. Returns undefined
|
|
18070
|
+
* if the data is too small / wrong type.
|
|
18071
|
+
*/ async function maybeCompressValue(value) {
|
|
18072
|
+
if (!isNode()) return undefined;
|
|
18073
|
+
// Request compression is not that important so let's
|
|
18074
|
+
// skip it instead of throwing for unsupported types.
|
|
18075
|
+
if (typeof value !== 'string' && !Buffer.isBuffer(value)) return undefined;
|
|
18076
|
+
const areDataLargeEnough = Buffer.byteLength(value) >= MIN_COMPRESS_BYTES;
|
|
18077
|
+
if (!areDataLargeEnough) return undefined;
|
|
18078
|
+
const brotli = await maybeBrotliValue(value);
|
|
18079
|
+
if (brotli) return {
|
|
18080
|
+
data: brotli,
|
|
18081
|
+
encoding: 'br'
|
|
18082
|
+
};
|
|
18083
|
+
const gzipped = await gzipValue(value);
|
|
18084
|
+
return {
|
|
18085
|
+
data: gzipped,
|
|
18086
|
+
encoding: 'gzip'
|
|
18087
|
+
};
|
|
18088
|
+
}
|
|
17998
18089
|
/**
|
|
17999
18090
|
* Helper function slice the items from array to fit the max byte length.
|
|
18000
18091
|
*/ function sliceArrayByByteLength(array, maxByteLength, startIndex) {
|
|
@@ -18031,7 +18122,7 @@ function isStream(value) {
|
|
|
18031
18122
|
function getVersionData() {
|
|
18032
18123
|
if (true) {
|
|
18033
18124
|
return {
|
|
18034
|
-
version: "2.23.5-beta.
|
|
18125
|
+
version: "2.23.5-beta.30"
|
|
18035
18126
|
};
|
|
18036
18127
|
}
|
|
18037
18128
|
// eslint-disable-next-line
|
|
@@ -18126,7 +18217,7 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
18126
18217
|
isBuffer: () => (isBuffer),
|
|
18127
18218
|
isNode: () => (isNode),
|
|
18128
18219
|
isStream: () => (isStream),
|
|
18129
|
-
|
|
18220
|
+
maybeCompressValue: () => (maybeCompressValue),
|
|
18130
18221
|
parseDateFields: () => (parseDateFields),
|
|
18131
18222
|
pluckData: () => (pluckData),
|
|
18132
18223
|
sliceArrayByByteLength: () => (sliceArrayByByteLength),
|