apify-client 2.24.1-beta.0 → 2.24.1-beta.2
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 +39 -38
- package/dist/bundle.js.map +1 -1
- package/dist/utils.d.ts +2 -2
- package/dist/utils.js +31 -30
- package/package.json +2 -2
package/dist/utils.d.ts
CHANGED
|
@@ -46,8 +46,8 @@ export interface CompressedValue {
|
|
|
46
46
|
encoding: 'br' | 'gzip';
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
|
-
* Compress the passed value using brotli
|
|
50
|
-
*
|
|
49
|
+
* Compress the passed value using brotli, falling back to gzip. Returns undefined if the data is
|
|
50
|
+
* too small / wrong type, or if neither algorithm is available.
|
|
51
51
|
*/
|
|
52
52
|
export declare function maybeCompressValue(value: unknown): Promise<CompressedValue | undefined>;
|
|
53
53
|
/**
|
package/dist/utils.js
CHANGED
|
@@ -97,6 +97,20 @@ function stringifyWebhooksToBase64(webhooks) {
|
|
|
97
97
|
const uint8Array = encoder.encode(webhooksJson);
|
|
98
98
|
return btoa(String.fromCharCode(...uint8Array));
|
|
99
99
|
}
|
|
100
|
+
let brotliCompressPromisified;
|
|
101
|
+
/**
|
|
102
|
+
* Brotli-compress the provided value.
|
|
103
|
+
*/
|
|
104
|
+
async function brotliValue(value) {
|
|
105
|
+
if (!brotliCompressPromisified) {
|
|
106
|
+
const { promisify } = await import('node:util');
|
|
107
|
+
const { brotliCompress, constants } = await import('node:zlib');
|
|
108
|
+
const compress = promisify(brotliCompress);
|
|
109
|
+
const options = { params: { [constants.BROTLI_PARAM_QUALITY]: 6 } };
|
|
110
|
+
brotliCompressPromisified = async (input) => compress(input, options);
|
|
111
|
+
}
|
|
112
|
+
return brotliCompressPromisified(value);
|
|
113
|
+
}
|
|
100
114
|
let gzipPromisified;
|
|
101
115
|
/**
|
|
102
116
|
* Gzip-compress the provided value.
|
|
@@ -109,32 +123,9 @@ async function gzipValue(value) {
|
|
|
109
123
|
}
|
|
110
124
|
return gzipPromisified(value);
|
|
111
125
|
}
|
|
112
|
-
// null = confirmed unavailable; undefined = not yet checked
|
|
113
|
-
let brotliCompressPromisified;
|
|
114
126
|
/**
|
|
115
|
-
*
|
|
116
|
-
*
|
|
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 } });
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
brotliCompressPromisified = null;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
if (brotliCompressPromisified !== null) {
|
|
131
|
-
return brotliCompressPromisified(value);
|
|
132
|
-
}
|
|
133
|
-
return undefined;
|
|
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.
|
|
127
|
+
* Compress the passed value using brotli, falling back to gzip. Returns undefined if the data is
|
|
128
|
+
* too small / wrong type, or if neither algorithm is available.
|
|
138
129
|
*/
|
|
139
130
|
async function maybeCompressValue(value) {
|
|
140
131
|
if (!isNode())
|
|
@@ -146,11 +137,21 @@ async function maybeCompressValue(value) {
|
|
|
146
137
|
const areDataLargeEnough = Buffer.byteLength(value) >= MIN_COMPRESS_BYTES;
|
|
147
138
|
if (!areDataLargeEnough)
|
|
148
139
|
return undefined;
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
140
|
+
try {
|
|
141
|
+
return { data: await brotliValue(value), encoding: 'br' };
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
// Runtimes that only provide a partial `node:zlib` (bundler polyfills, edge runtimes with
|
|
145
|
+
// Node compatibility shims) may not implement brotli, but usually do implement gzip.
|
|
146
|
+
}
|
|
147
|
+
try {
|
|
148
|
+
return { data: await gzipValue(value), encoding: 'gzip' };
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
// Same reasoning as above: compression is a best-effort optimization, so skip it instead
|
|
152
|
+
// of failing the request.
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
154
155
|
}
|
|
155
156
|
/**
|
|
156
157
|
* Helper function slice the items from array to fit the max byte length.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "apify-client",
|
|
3
|
-
"version": "2.24.1-beta.
|
|
3
|
+
"version": "2.24.1-beta.2",
|
|
4
4
|
"description": "Apify API client for JavaScript",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"express": "^5.0.0",
|
|
83
83
|
"gen-esm-wrapper": "^1.1.2",
|
|
84
84
|
"oxfmt": "0.61.0",
|
|
85
|
-
"oxlint": "1.
|
|
85
|
+
"oxlint": "1.76.0",
|
|
86
86
|
"oxlint-tsgolint": "7.0.2001",
|
|
87
87
|
"puppeteer": "^25.0.0",
|
|
88
88
|
"rimraf": "^6.0.0",
|