@posthog/core 1.27.4 → 1.27.6

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.
@@ -1 +1 @@
1
- {"version":3,"file":"gzip.d.ts","sourceRoot":"","sources":["../src/gzip.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,eAAe,IAAI,OAAO,CAEzC;AAED,eAAO,MAAM,0BAA0B,GAAI,OAAO,OAAO,KAAG,OAQ3D,CAAA;AAED,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,CAqBrH"}
1
+ {"version":3,"file":"gzip.d.ts","sourceRoot":"","sources":["../src/gzip.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,eAAe,IAAI,OAAO,CAOzC;AAED,eAAO,MAAM,0BAA0B,GAAI,OAAO,OAAO,KAAG,OAQ3D,CAAA;AAED,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,CA8BrH"}
package/dist/gzip.js CHANGED
@@ -29,7 +29,7 @@ __webpack_require__.d(__webpack_exports__, {
29
29
  isNativeAsyncGzipReadError: ()=>isNativeAsyncGzipReadError
30
30
  });
31
31
  function isGzipSupported() {
32
- return 'CompressionStream' in globalThis;
32
+ return 'CompressionStream' in globalThis && 'TextEncoder' in globalThis && 'Response' in globalThis && 'function' == typeof Response.prototype.blob;
33
33
  }
34
34
  const isNativeAsyncGzipReadError = (error)=>{
35
35
  if (!error || 'object' != typeof error) return false;
@@ -38,13 +38,20 @@ const isNativeAsyncGzipReadError = (error)=>{
38
38
  };
39
39
  async function gzipCompress(input, isDebug = true, options) {
40
40
  try {
41
- const dataStream = new Blob([
42
- input
43
- ], {
44
- type: 'text/plain'
45
- }).stream();
46
- const compressedStream = dataStream.pipeThrough(new CompressionStream('gzip'));
47
- return await new Response(compressedStream).blob();
41
+ const compressedStream = new CompressionStream('gzip');
42
+ const writer = compressedStream.writable.getWriter();
43
+ const writePromise = writer.write(new TextEncoder().encode(input)).then(()=>writer.close()).catch(async (err)=>{
44
+ try {
45
+ await writer.abort(err);
46
+ } catch {}
47
+ throw err;
48
+ });
49
+ const responsePromise = new Response(compressedStream.readable).blob();
50
+ const [compressed] = await Promise.all([
51
+ responsePromise,
52
+ writePromise
53
+ ]);
54
+ return compressed;
48
55
  } catch (error) {
49
56
  if (options?.rethrow) throw error;
50
57
  if (isDebug) console.error('Failed to gzip compress data', error);
package/dist/gzip.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  function isGzipSupported() {
2
- return 'CompressionStream' in globalThis;
2
+ return 'CompressionStream' in globalThis && 'TextEncoder' in globalThis && 'Response' in globalThis && 'function' == typeof Response.prototype.blob;
3
3
  }
4
4
  const isNativeAsyncGzipReadError = (error)=>{
5
5
  if (!error || 'object' != typeof error) return false;
@@ -8,13 +8,20 @@ const isNativeAsyncGzipReadError = (error)=>{
8
8
  };
9
9
  async function gzipCompress(input, isDebug = true, options) {
10
10
  try {
11
- const dataStream = new Blob([
12
- input
13
- ], {
14
- type: 'text/plain'
15
- }).stream();
16
- const compressedStream = dataStream.pipeThrough(new CompressionStream('gzip'));
17
- return await new Response(compressedStream).blob();
11
+ const compressedStream = new CompressionStream('gzip');
12
+ const writer = compressedStream.writable.getWriter();
13
+ const writePromise = writer.write(new TextEncoder().encode(input)).then(()=>writer.close()).catch(async (err)=>{
14
+ try {
15
+ await writer.abort(err);
16
+ } catch {}
17
+ throw err;
18
+ });
19
+ const responsePromise = new Response(compressedStream.readable).blob();
20
+ const [compressed] = await Promise.all([
21
+ responsePromise,
22
+ writePromise
23
+ ]);
24
+ return compressed;
18
25
  } catch (error) {
19
26
  if (options?.rethrow) throw error;
20
27
  if (isDebug) console.error('Failed to gzip compress data', error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@posthog/core",
3
- "version": "1.27.4",
3
+ "version": "1.27.6",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -43,7 +43,7 @@
43
43
  }
44
44
  },
45
45
  "dependencies": {
46
- "@posthog/types": "1.372.0"
46
+ "@posthog/types": "1.372.2"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@rslib/core": "0.10.6",
package/src/gzip.ts CHANGED
@@ -3,7 +3,12 @@
3
3
  * This API (as of 2025-05-07) is not available on React Native.
4
4
  */
5
5
  export function isGzipSupported(): boolean {
6
- return 'CompressionStream' in globalThis
6
+ return (
7
+ 'CompressionStream' in globalThis &&
8
+ 'TextEncoder' in globalThis &&
9
+ 'Response' in globalThis &&
10
+ typeof Response.prototype.blob === 'function'
11
+ )
7
12
  }
8
13
 
9
14
  export const isNativeAsyncGzipReadError = (error: unknown): boolean => {
@@ -31,15 +36,24 @@ export type GzipCompressOptions = {
31
36
  */
32
37
  export async function gzipCompress(input: string, isDebug = true, options?: GzipCompressOptions): Promise<Blob | null> {
33
38
  try {
34
- // Turn the string into a stream using a Blob, and then compress it
35
- const dataStream = new Blob([input], {
36
- type: 'text/plain',
37
- }).stream()
39
+ const compressedStream = new CompressionStream('gzip')
40
+ const writer = compressedStream.writable.getWriter()
38
41
 
39
- const compressedStream = dataStream.pipeThrough(new CompressionStream('gzip'))
42
+ const writePromise = writer
43
+ .write(new TextEncoder().encode(input))
44
+ .then(() => writer.close())
45
+ .catch(async (err) => {
46
+ try {
47
+ await writer.abort(err)
48
+ } catch {
49
+ // Ignore abort failures and rethrow the original compression error below.
50
+ }
51
+ throw err
52
+ })
53
+ const responsePromise = new Response(compressedStream.readable).blob()
40
54
 
41
- // Using a Response to easily extract the readablestream value. Decoding into a string for fetch
42
- return await new Response(compressedStream).blob()
55
+ const [compressed] = await Promise.all([responsePromise, writePromise])
56
+ return compressed
43
57
  } catch (error) {
44
58
  if (options?.rethrow) {
45
59
  throw error