@posthog/core 1.29.0 → 1.29.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/gzip.d.ts +2 -0
- package/dist/gzip.d.ts.map +1 -1
- package/dist/gzip.js +21 -4
- package/dist/gzip.mjs +13 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +30 -12
- package/dist/index.mjs +2 -2
- package/package.json +2 -2
- package/src/gzip.ts +26 -1
- package/src/index.ts +1 -1
package/dist/gzip.d.ts
CHANGED
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
* This API (as of 2025-05-07) is not available on React Native.
|
|
4
4
|
*/
|
|
5
5
|
export declare function isGzipSupported(): boolean;
|
|
6
|
+
export declare const isGzipData: (body: unknown) => boolean;
|
|
7
|
+
export declare const isGzipRequest: (compression?: unknown, urlCompression?: unknown) => boolean;
|
|
6
8
|
export declare const isNativeAsyncGzipReadError: (error: unknown) => boolean;
|
|
7
9
|
export declare const isNativeAsyncGzipError: (error: unknown) => boolean;
|
|
8
10
|
export type GzipCompressOptions = {
|
package/dist/gzip.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gzip.d.ts","sourceRoot":"","sources":["../src/gzip.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"gzip.d.ts","sourceRoot":"","sources":["../src/gzip.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,wBAAgB,eAAe,IAAI,OAAO,CAOzC;AAWD,eAAO,MAAM,UAAU,GAAI,MAAM,OAAO,KAAG,OAU1C,CAAA;AAED,eAAO,MAAM,aAAa,GAAI,cAAc,OAAO,EAAE,iBAAiB,OAAO,KAAG,OAE/E,CAAA;AAED,eAAO,MAAM,0BAA0B,GAAI,OAAO,OAAO,KAAG,OAQ3D,CAAA;AAED,eAAO,MAAM,sBAAsB,GAAI,OAAO,OAAO,KAAG,OAQvD,CAAA;AA0DD,MAAM,MAAM,mBAAmB,GAAG;IAChC;;;;;OAKG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,CAAA;AAED;;GAEG;AACH,wBAAsB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,UAAO,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAgCrH"}
|
package/dist/gzip.js
CHANGED
|
@@ -24,15 +24,28 @@ var __webpack_require__ = {};
|
|
|
24
24
|
var __webpack_exports__ = {};
|
|
25
25
|
__webpack_require__.r(__webpack_exports__);
|
|
26
26
|
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
-
gzipCompress: ()=>gzipCompress,
|
|
28
|
-
isGzipSupported: ()=>isGzipSupported,
|
|
29
27
|
isNativeAsyncGzipError: ()=>isNativeAsyncGzipError,
|
|
30
|
-
isNativeAsyncGzipReadError: ()=>isNativeAsyncGzipReadError
|
|
28
|
+
isNativeAsyncGzipReadError: ()=>isNativeAsyncGzipReadError,
|
|
29
|
+
isGzipRequest: ()=>isGzipRequest,
|
|
30
|
+
isGzipSupported: ()=>isGzipSupported,
|
|
31
|
+
gzipCompress: ()=>gzipCompress,
|
|
32
|
+
isGzipData: ()=>isGzipData
|
|
31
33
|
});
|
|
34
|
+
const external_types_js_namespaceObject = require("./types.js");
|
|
32
35
|
function isGzipSupported() {
|
|
33
36
|
return 'CompressionStream' in globalThis && 'TextEncoder' in globalThis && 'Response' in globalThis && 'function' == typeof Response.prototype.blob;
|
|
34
37
|
}
|
|
35
38
|
const NATIVE_GZIP_VALIDATION_ERROR = 'NativeGzipValidationError';
|
|
39
|
+
const GZIP_MAGIC_FIRST_BYTE = 0x1f;
|
|
40
|
+
const GZIP_MAGIC_SECOND_BYTE = 0x8b;
|
|
41
|
+
const GZIP_DEFLATE_METHOD = 0x08;
|
|
42
|
+
const hasGzipMagic = (bytes)=>bytes.length >= 2 && bytes[0] === GZIP_MAGIC_FIRST_BYTE && bytes[1] === GZIP_MAGIC_SECOND_BYTE;
|
|
43
|
+
const isGzipData = (body)=>{
|
|
44
|
+
if (body instanceof ArrayBuffer) return hasGzipMagic(new Uint8Array(body));
|
|
45
|
+
if (ArrayBuffer.isView(body)) return hasGzipMagic(new Uint8Array(body.buffer, body.byteOffset, body.byteLength));
|
|
46
|
+
return false;
|
|
47
|
+
};
|
|
48
|
+
const isGzipRequest = (compression, urlCompression)=>compression === external_types_js_namespaceObject.Compression.GZipJS || urlCompression === external_types_js_namespaceObject.Compression.GZipJS || 'gzip' === urlCompression;
|
|
36
49
|
const isNativeAsyncGzipReadError = (error)=>{
|
|
37
50
|
if (!error || 'object' != typeof error) return false;
|
|
38
51
|
const name = 'name' in error ? String(error.name) : '';
|
|
@@ -68,7 +81,7 @@ const throwNativeGzipValidationError = (reason)=>{
|
|
|
68
81
|
const validateNativeGzip = async (compressed, inputBytes)=>{
|
|
69
82
|
if (compressed.size < 18) throwNativeGzipValidationError('too-short');
|
|
70
83
|
const header = new Uint8Array(await compressed.slice(0, 10).arrayBuffer());
|
|
71
|
-
if (
|
|
84
|
+
if (!hasGzipMagic(header) || header[2] !== GZIP_DEFLATE_METHOD) throwNativeGzipValidationError('invalid-header');
|
|
72
85
|
const trailer = new DataView(await compressed.slice(compressed.size - 8).arrayBuffer());
|
|
73
86
|
if (trailer.getUint32(0, true) !== crc32(inputBytes)) throwNativeGzipValidationError('invalid-crc');
|
|
74
87
|
const inputSize = inputBytes.length >>> 0;
|
|
@@ -99,11 +112,15 @@ async function gzipCompress(input, isDebug = true, options) {
|
|
|
99
112
|
}
|
|
100
113
|
}
|
|
101
114
|
exports.gzipCompress = __webpack_exports__.gzipCompress;
|
|
115
|
+
exports.isGzipData = __webpack_exports__.isGzipData;
|
|
116
|
+
exports.isGzipRequest = __webpack_exports__.isGzipRequest;
|
|
102
117
|
exports.isGzipSupported = __webpack_exports__.isGzipSupported;
|
|
103
118
|
exports.isNativeAsyncGzipError = __webpack_exports__.isNativeAsyncGzipError;
|
|
104
119
|
exports.isNativeAsyncGzipReadError = __webpack_exports__.isNativeAsyncGzipReadError;
|
|
105
120
|
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
106
121
|
"gzipCompress",
|
|
122
|
+
"isGzipData",
|
|
123
|
+
"isGzipRequest",
|
|
107
124
|
"isGzipSupported",
|
|
108
125
|
"isNativeAsyncGzipError",
|
|
109
126
|
"isNativeAsyncGzipReadError"
|
package/dist/gzip.mjs
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
|
+
import { Compression } from "./types.mjs";
|
|
1
2
|
function isGzipSupported() {
|
|
2
3
|
return 'CompressionStream' in globalThis && 'TextEncoder' in globalThis && 'Response' in globalThis && 'function' == typeof Response.prototype.blob;
|
|
3
4
|
}
|
|
4
5
|
const NATIVE_GZIP_VALIDATION_ERROR = 'NativeGzipValidationError';
|
|
6
|
+
const GZIP_MAGIC_FIRST_BYTE = 0x1f;
|
|
7
|
+
const GZIP_MAGIC_SECOND_BYTE = 0x8b;
|
|
8
|
+
const GZIP_DEFLATE_METHOD = 0x08;
|
|
9
|
+
const hasGzipMagic = (bytes)=>bytes.length >= 2 && bytes[0] === GZIP_MAGIC_FIRST_BYTE && bytes[1] === GZIP_MAGIC_SECOND_BYTE;
|
|
10
|
+
const isGzipData = (body)=>{
|
|
11
|
+
if (body instanceof ArrayBuffer) return hasGzipMagic(new Uint8Array(body));
|
|
12
|
+
if (ArrayBuffer.isView(body)) return hasGzipMagic(new Uint8Array(body.buffer, body.byteOffset, body.byteLength));
|
|
13
|
+
return false;
|
|
14
|
+
};
|
|
15
|
+
const isGzipRequest = (compression, urlCompression)=>compression === Compression.GZipJS || urlCompression === Compression.GZipJS || 'gzip' === urlCompression;
|
|
5
16
|
const isNativeAsyncGzipReadError = (error)=>{
|
|
6
17
|
if (!error || 'object' != typeof error) return false;
|
|
7
18
|
const name = 'name' in error ? String(error.name) : '';
|
|
@@ -37,7 +48,7 @@ const throwNativeGzipValidationError = (reason)=>{
|
|
|
37
48
|
const validateNativeGzip = async (compressed, inputBytes)=>{
|
|
38
49
|
if (compressed.size < 18) throwNativeGzipValidationError('too-short');
|
|
39
50
|
const header = new Uint8Array(await compressed.slice(0, 10).arrayBuffer());
|
|
40
|
-
if (
|
|
51
|
+
if (!hasGzipMagic(header) || header[2] !== GZIP_DEFLATE_METHOD) throwNativeGzipValidationError('invalid-header');
|
|
41
52
|
const trailer = new DataView(await compressed.slice(compressed.size - 8).arrayBuffer());
|
|
42
53
|
if (trailer.getUint32(0, true) !== crc32(inputBytes)) throwNativeGzipValidationError('invalid-crc');
|
|
43
54
|
const inputSize = inputBytes.length >>> 0;
|
|
@@ -67,4 +78,4 @@ async function gzipCompress(input, isDebug = true, options) {
|
|
|
67
78
|
return null;
|
|
68
79
|
}
|
|
69
80
|
}
|
|
70
|
-
export { gzipCompress, isGzipSupported, isNativeAsyncGzipError, isNativeAsyncGzipReadError };
|
|
81
|
+
export { gzipCompress, isGzipData, isGzipRequest, isGzipSupported, isNativeAsyncGzipError, isNativeAsyncGzipReadError };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { getFeatureFlagValue } from './featureFlagUtils';
|
|
2
|
-
export { gzipCompress, isNativeAsyncGzipError, isNativeAsyncGzipReadError } from './gzip';
|
|
2
|
+
export { gzipCompress, isGzipData, isGzipRequest, isNativeAsyncGzipError, isNativeAsyncGzipReadError } from './gzip';
|
|
3
3
|
export * from './utils';
|
|
4
4
|
export * as ErrorTracking from './error-tracking';
|
|
5
5
|
export { buildOtlpLogRecord, buildOtlpLogsPayload, getOtlpSeverityNumber, getOtlpSeverityText, toOtlpAnyValue, toOtlpKeyValueList, } from './logs/logs-utils';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,EAAE,YAAY,EAAE,sBAAsB,EAAE,0BAA0B,EAAE,MAAM,QAAQ,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AACxD,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,sBAAsB,EAAE,0BAA0B,EAAE,MAAM,QAAQ,CAAA;AACpH,cAAc,SAAS,CAAA;AACvB,OAAO,KAAK,aAAa,MAAM,kBAAkB,CAAA;AACjD,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,qBAAqB,EACrB,mBAAmB,EACnB,cAAc,EACd,kBAAkB,GACnB,MAAM,mBAAmB,CAAA;AAC1B,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AACpC,YAAY,EACV,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,aAAa,EACb,iBAAiB,EACjB,yBAAyB,GAC1B,MAAM,cAAc,CAAA;AAIrB,YAAY,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AACzG,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AACxC,cAAc,UAAU,CAAA;AACxB,cAAc,gBAAgB,CAAA;AAC9B,cAAc,0BAA0B,CAAA;AACxC,cAAc,mBAAmB,CAAA;AACjC,cAAc,SAAS,CAAA;AACvB,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -95,6 +95,8 @@ var __webpack_exports__ = {};
|
|
|
95
95
|
getRequirementsHint: ()=>_surveys_validation__WEBPACK_IMPORTED_MODULE_12__.getRequirementsHint,
|
|
96
96
|
getValidationError: ()=>_surveys_validation__WEBPACK_IMPORTED_MODULE_12__.getValidationError,
|
|
97
97
|
gzipCompress: ()=>_gzip__WEBPACK_IMPORTED_MODULE_1__.gzipCompress,
|
|
98
|
+
isGzipData: ()=>_gzip__WEBPACK_IMPORTED_MODULE_1__.isGzipData,
|
|
99
|
+
isGzipRequest: ()=>_gzip__WEBPACK_IMPORTED_MODULE_1__.isGzipRequest,
|
|
98
100
|
isNativeAsyncGzipError: ()=>_gzip__WEBPACK_IMPORTED_MODULE_1__.isNativeAsyncGzipError,
|
|
99
101
|
isNativeAsyncGzipReadError: ()=>_gzip__WEBPACK_IMPORTED_MODULE_1__.isNativeAsyncGzipReadError,
|
|
100
102
|
toOtlpAnyValue: ()=>_logs_logs_utils__WEBPACK_IMPORTED_MODULE_4__.toOtlpAnyValue,
|
|
@@ -112,12 +114,14 @@ var __webpack_exports__ = {};
|
|
|
112
114
|
"getOtlpSeverityText",
|
|
113
115
|
"isNativeAsyncGzipReadError",
|
|
114
116
|
"getFeatureFlagValue",
|
|
117
|
+
"isGzipRequest",
|
|
118
|
+
"gzipCompress",
|
|
115
119
|
"uuidv7",
|
|
116
|
-
"getValidationError",
|
|
117
120
|
"ErrorTracking",
|
|
118
|
-
"
|
|
121
|
+
"getValidationError",
|
|
119
122
|
"default",
|
|
120
123
|
"getRequirementsHint",
|
|
124
|
+
"isGzipData",
|
|
121
125
|
"getOtlpSeverityNumber",
|
|
122
126
|
"getLengthFromRules",
|
|
123
127
|
"buildOtlpLogsPayload",
|
|
@@ -140,12 +144,14 @@ var __webpack_exports__ = {};
|
|
|
140
144
|
"getOtlpSeverityText",
|
|
141
145
|
"isNativeAsyncGzipReadError",
|
|
142
146
|
"getFeatureFlagValue",
|
|
147
|
+
"isGzipRequest",
|
|
148
|
+
"gzipCompress",
|
|
143
149
|
"uuidv7",
|
|
144
|
-
"getValidationError",
|
|
145
150
|
"ErrorTracking",
|
|
146
|
-
"
|
|
151
|
+
"getValidationError",
|
|
147
152
|
"default",
|
|
148
153
|
"getRequirementsHint",
|
|
154
|
+
"isGzipData",
|
|
149
155
|
"getOtlpSeverityNumber",
|
|
150
156
|
"getLengthFromRules",
|
|
151
157
|
"buildOtlpLogsPayload",
|
|
@@ -164,12 +170,14 @@ var __webpack_exports__ = {};
|
|
|
164
170
|
"getOtlpSeverityText",
|
|
165
171
|
"isNativeAsyncGzipReadError",
|
|
166
172
|
"getFeatureFlagValue",
|
|
173
|
+
"isGzipRequest",
|
|
174
|
+
"gzipCompress",
|
|
167
175
|
"uuidv7",
|
|
168
|
-
"getValidationError",
|
|
169
176
|
"ErrorTracking",
|
|
170
|
-
"
|
|
177
|
+
"getValidationError",
|
|
171
178
|
"default",
|
|
172
179
|
"getRequirementsHint",
|
|
180
|
+
"isGzipData",
|
|
173
181
|
"getOtlpSeverityNumber",
|
|
174
182
|
"getLengthFromRules",
|
|
175
183
|
"buildOtlpLogsPayload",
|
|
@@ -188,12 +196,14 @@ var __webpack_exports__ = {};
|
|
|
188
196
|
"getOtlpSeverityText",
|
|
189
197
|
"isNativeAsyncGzipReadError",
|
|
190
198
|
"getFeatureFlagValue",
|
|
199
|
+
"isGzipRequest",
|
|
200
|
+
"gzipCompress",
|
|
191
201
|
"uuidv7",
|
|
192
|
-
"getValidationError",
|
|
193
202
|
"ErrorTracking",
|
|
194
|
-
"
|
|
203
|
+
"getValidationError",
|
|
195
204
|
"default",
|
|
196
205
|
"getRequirementsHint",
|
|
206
|
+
"isGzipData",
|
|
197
207
|
"getOtlpSeverityNumber",
|
|
198
208
|
"getLengthFromRules",
|
|
199
209
|
"buildOtlpLogsPayload",
|
|
@@ -212,12 +222,14 @@ var __webpack_exports__ = {};
|
|
|
212
222
|
"getOtlpSeverityText",
|
|
213
223
|
"isNativeAsyncGzipReadError",
|
|
214
224
|
"getFeatureFlagValue",
|
|
225
|
+
"isGzipRequest",
|
|
226
|
+
"gzipCompress",
|
|
215
227
|
"uuidv7",
|
|
216
|
-
"getValidationError",
|
|
217
228
|
"ErrorTracking",
|
|
218
|
-
"
|
|
229
|
+
"getValidationError",
|
|
219
230
|
"default",
|
|
220
231
|
"getRequirementsHint",
|
|
232
|
+
"isGzipData",
|
|
221
233
|
"getOtlpSeverityNumber",
|
|
222
234
|
"getLengthFromRules",
|
|
223
235
|
"buildOtlpLogsPayload",
|
|
@@ -236,12 +248,14 @@ var __webpack_exports__ = {};
|
|
|
236
248
|
"getOtlpSeverityText",
|
|
237
249
|
"isNativeAsyncGzipReadError",
|
|
238
250
|
"getFeatureFlagValue",
|
|
251
|
+
"isGzipRequest",
|
|
252
|
+
"gzipCompress",
|
|
239
253
|
"uuidv7",
|
|
240
|
-
"getValidationError",
|
|
241
254
|
"ErrorTracking",
|
|
242
|
-
"
|
|
255
|
+
"getValidationError",
|
|
243
256
|
"default",
|
|
244
257
|
"getRequirementsHint",
|
|
258
|
+
"isGzipData",
|
|
245
259
|
"getOtlpSeverityNumber",
|
|
246
260
|
"getLengthFromRules",
|
|
247
261
|
"buildOtlpLogsPayload",
|
|
@@ -264,6 +278,8 @@ exports.getOtlpSeverityText = __webpack_exports__.getOtlpSeverityText;
|
|
|
264
278
|
exports.getRequirementsHint = __webpack_exports__.getRequirementsHint;
|
|
265
279
|
exports.getValidationError = __webpack_exports__.getValidationError;
|
|
266
280
|
exports.gzipCompress = __webpack_exports__.gzipCompress;
|
|
281
|
+
exports.isGzipData = __webpack_exports__.isGzipData;
|
|
282
|
+
exports.isGzipRequest = __webpack_exports__.isGzipRequest;
|
|
267
283
|
exports.isNativeAsyncGzipError = __webpack_exports__.isNativeAsyncGzipError;
|
|
268
284
|
exports.isNativeAsyncGzipReadError = __webpack_exports__.isNativeAsyncGzipReadError;
|
|
269
285
|
exports.toOtlpAnyValue = __webpack_exports__.toOtlpAnyValue;
|
|
@@ -281,6 +297,8 @@ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
|
281
297
|
"getRequirementsHint",
|
|
282
298
|
"getValidationError",
|
|
283
299
|
"gzipCompress",
|
|
300
|
+
"isGzipData",
|
|
301
|
+
"isGzipRequest",
|
|
284
302
|
"isNativeAsyncGzipError",
|
|
285
303
|
"isNativeAsyncGzipReadError",
|
|
286
304
|
"toOtlpAnyValue",
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getFeatureFlagValue } from "./featureFlagUtils.mjs";
|
|
2
|
-
import { gzipCompress, isNativeAsyncGzipError, isNativeAsyncGzipReadError } from "./gzip.mjs";
|
|
2
|
+
import { gzipCompress, isGzipData, isGzipRequest, isNativeAsyncGzipError, isNativeAsyncGzipReadError } from "./gzip.mjs";
|
|
3
3
|
import { buildOtlpLogRecord, buildOtlpLogsPayload, getOtlpSeverityNumber, getOtlpSeverityText, toOtlpAnyValue, toOtlpKeyValueList } from "./logs/logs-utils.mjs";
|
|
4
4
|
import { PostHogLogs } from "./logs/index.mjs";
|
|
5
5
|
import { uuidv7 } from "./vendor/uuidv7.mjs";
|
|
@@ -11,4 +11,4 @@ export * from "./posthog-core-stateless.mjs";
|
|
|
11
11
|
export * from "./tracing-headers.mjs";
|
|
12
12
|
export * from "./types.mjs";
|
|
13
13
|
import * as __WEBPACK_EXTERNAL_MODULE__error_tracking_index_mjs_b3406d6f__ from "./error-tracking/index.mjs";
|
|
14
|
-
export { __WEBPACK_EXTERNAL_MODULE__error_tracking_index_mjs_b3406d6f__ as ErrorTracking, PostHogLogs, buildOtlpLogRecord, buildOtlpLogsPayload, getFeatureFlagValue, getLengthFromRules, getOtlpSeverityNumber, getOtlpSeverityText, getRequirementsHint, getValidationError, gzipCompress, isNativeAsyncGzipError, isNativeAsyncGzipReadError, toOtlpAnyValue, toOtlpKeyValueList, uuidv7 };
|
|
14
|
+
export { __WEBPACK_EXTERNAL_MODULE__error_tracking_index_mjs_b3406d6f__ as ErrorTracking, PostHogLogs, buildOtlpLogRecord, buildOtlpLogsPayload, getFeatureFlagValue, getLengthFromRules, getOtlpSeverityNumber, getOtlpSeverityText, getRequirementsHint, getValidationError, gzipCompress, isGzipData, isGzipRequest, isNativeAsyncGzipError, isNativeAsyncGzipReadError, toOtlpAnyValue, toOtlpKeyValueList, uuidv7 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@posthog/core",
|
|
3
|
-
"version": "1.29.
|
|
3
|
+
"version": "1.29.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
}
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@posthog/types": "1.373.
|
|
70
|
+
"@posthog/types": "1.373.5"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@rslib/core": "0.10.6",
|
package/src/gzip.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Compression } from './types'
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Older browsers and some runtimes don't support this yet
|
|
3
5
|
* This API (as of 2025-05-07) is not available on React Native.
|
|
@@ -12,6 +14,29 @@ export function isGzipSupported(): boolean {
|
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
const NATIVE_GZIP_VALIDATION_ERROR = 'NativeGzipValidationError'
|
|
17
|
+
const GZIP_MAGIC_FIRST_BYTE = 0x1f
|
|
18
|
+
const GZIP_MAGIC_SECOND_BYTE = 0x8b
|
|
19
|
+
const GZIP_DEFLATE_METHOD = 0x08
|
|
20
|
+
|
|
21
|
+
const hasGzipMagic = (bytes: Uint8Array): boolean => {
|
|
22
|
+
return bytes.length >= 2 && bytes[0] === GZIP_MAGIC_FIRST_BYTE && bytes[1] === GZIP_MAGIC_SECOND_BYTE
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const isGzipData = (body: unknown): boolean => {
|
|
26
|
+
if (body instanceof ArrayBuffer) {
|
|
27
|
+
return hasGzipMagic(new Uint8Array(body))
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (ArrayBuffer.isView(body)) {
|
|
31
|
+
return hasGzipMagic(new Uint8Array(body.buffer, body.byteOffset, body.byteLength))
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return false
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export const isGzipRequest = (compression?: unknown, urlCompression?: unknown): boolean => {
|
|
38
|
+
return compression === Compression.GZipJS || urlCompression === Compression.GZipJS || urlCompression === 'gzip'
|
|
39
|
+
}
|
|
15
40
|
|
|
16
41
|
export const isNativeAsyncGzipReadError = (error: unknown): boolean => {
|
|
17
42
|
if (!error || typeof error !== 'object') {
|
|
@@ -74,7 +99,7 @@ const validateNativeGzip = async (compressed: Blob, inputBytes: Uint8Array): Pro
|
|
|
74
99
|
}
|
|
75
100
|
|
|
76
101
|
const header = new Uint8Array(await compressed.slice(0, 10).arrayBuffer())
|
|
77
|
-
if (header
|
|
102
|
+
if (!hasGzipMagic(header) || header[2] !== GZIP_DEFLATE_METHOD) {
|
|
78
103
|
throwNativeGzipValidationError('invalid-header')
|
|
79
104
|
}
|
|
80
105
|
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { getFeatureFlagValue } from './featureFlagUtils'
|
|
2
|
-
export { gzipCompress, isNativeAsyncGzipError, isNativeAsyncGzipReadError } from './gzip'
|
|
2
|
+
export { gzipCompress, isGzipData, isGzipRequest, isNativeAsyncGzipError, isNativeAsyncGzipReadError } from './gzip'
|
|
3
3
|
export * from './utils'
|
|
4
4
|
export * as ErrorTracking from './error-tracking'
|
|
5
5
|
export {
|