@doist/comms-sdk 0.4.2 → 0.4.3

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.
@@ -96,19 +96,30 @@ async function createDefaultDispatcher() {
96
96
  // undici into their bundle. `isNodeEnvironment()` above already gated this
97
97
  // branch, so undici is safe to load when we get here.
98
98
  const { EnvHttpProxyAgent, interceptors } = await Promise.resolve().then(() => __importStar(require('undici')));
99
- // `allowH2: true` opts into HTTP/2 via ALPN; undici falls back to h1.1
100
- // when the server doesn't negotiate h2. Without this flag undici
101
- // defaults to h1.1 even when the server supports h2.
102
- //
103
- // `interceptors.decompress()` decodes gzip/deflate/br/zstd bodies. On
104
- // Node 24+, attaching any custom dispatcher to global `fetch` strips
105
- // `content-encoding` without actually decompressing the body.
106
- // See https://github.com/Doist/todoist-cli/issues/318.
107
- //
108
- // Both emit ExperimentalWarning on first use; suppressed during init.
99
+ // `EnvHttpProxyAgent` (with `allowH2`) and `interceptors.decompress()` both
100
+ // emit an ExperimentalWarning on first use, so build the whole dispatcher
101
+ // inside the suppression block.
109
102
  return suppressExperimentalWarningsSync(() => {
103
+ // `allowH2: true` opts into HTTP/2 via ALPN; undici falls back to h1.1
104
+ // when the server doesn't negotiate h2. Without this flag undici
105
+ // defaults to h1.1 even when the server supports h2.
106
+ const agent = new EnvHttpProxyAgent({ allowH2: true });
107
+ // Some runtimes report `process.versions.node` (so `isNodeEnvironment()`
108
+ // passes) but ship only a partial undici: `interceptors.decompress` is
109
+ // absent and dispatchers have no `.compose`. Bun is the common case.
110
+ // There the proxy agent alone is enough — Bun's `fetch` decompresses
111
+ // gzip/deflate/br/zstd natively — so skip the interceptor instead of
112
+ // crashing on the missing API. Optional chaining also guards a runtime
113
+ // that omits the `interceptors` export entirely.
114
+ if (typeof interceptors?.decompress !== 'function') {
115
+ return agent;
116
+ }
117
+ // `interceptors.decompress()` decodes gzip/deflate/br/zstd bodies. On
118
+ // Node 24+, attaching any custom dispatcher to global `fetch` strips
119
+ // `content-encoding` without actually decompressing the body.
120
+ // See https://github.com/Doist/todoist-cli/issues/318.
110
121
  const decompress = interceptors.decompress();
111
- return new EnvHttpProxyAgent({ allowH2: true }).compose(decompress);
122
+ return agent.compose(decompress);
112
123
  });
113
124
  }
114
125
  // `suppressExperimentalWarningsSync` is exported for direct unit testing —
@@ -57,19 +57,30 @@ async function createDefaultDispatcher() {
57
57
  // undici into their bundle. `isNodeEnvironment()` above already gated this
58
58
  // branch, so undici is safe to load when we get here.
59
59
  const { EnvHttpProxyAgent, interceptors } = await import('undici');
60
- // `allowH2: true` opts into HTTP/2 via ALPN; undici falls back to h1.1
61
- // when the server doesn't negotiate h2. Without this flag undici
62
- // defaults to h1.1 even when the server supports h2.
63
- //
64
- // `interceptors.decompress()` decodes gzip/deflate/br/zstd bodies. On
65
- // Node 24+, attaching any custom dispatcher to global `fetch` strips
66
- // `content-encoding` without actually decompressing the body.
67
- // See https://github.com/Doist/todoist-cli/issues/318.
68
- //
69
- // Both emit ExperimentalWarning on first use; suppressed during init.
60
+ // `EnvHttpProxyAgent` (with `allowH2`) and `interceptors.decompress()` both
61
+ // emit an ExperimentalWarning on first use, so build the whole dispatcher
62
+ // inside the suppression block.
70
63
  return suppressExperimentalWarningsSync(() => {
64
+ // `allowH2: true` opts into HTTP/2 via ALPN; undici falls back to h1.1
65
+ // when the server doesn't negotiate h2. Without this flag undici
66
+ // defaults to h1.1 even when the server supports h2.
67
+ const agent = new EnvHttpProxyAgent({ allowH2: true });
68
+ // Some runtimes report `process.versions.node` (so `isNodeEnvironment()`
69
+ // passes) but ship only a partial undici: `interceptors.decompress` is
70
+ // absent and dispatchers have no `.compose`. Bun is the common case.
71
+ // There the proxy agent alone is enough — Bun's `fetch` decompresses
72
+ // gzip/deflate/br/zstd natively — so skip the interceptor instead of
73
+ // crashing on the missing API. Optional chaining also guards a runtime
74
+ // that omits the `interceptors` export entirely.
75
+ if (typeof interceptors?.decompress !== 'function') {
76
+ return agent;
77
+ }
78
+ // `interceptors.decompress()` decodes gzip/deflate/br/zstd bodies. On
79
+ // Node 24+, attaching any custom dispatcher to global `fetch` strips
80
+ // `content-encoding` without actually decompressing the body.
81
+ // See https://github.com/Doist/todoist-cli/issues/318.
71
82
  const decompress = interceptors.decompress();
72
- return new EnvHttpProxyAgent({ allowH2: true }).compose(decompress);
83
+ return agent.compose(decompress);
73
84
  });
74
85
  }
75
86
  // `suppressExperimentalWarningsSync` is exported for direct unit testing —
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@doist/comms-sdk",
3
- "version": "0.4.2",
3
+ "version": "0.4.3",
4
4
  "description": "A TypeScript wrapper for the Comms REST API.",
5
5
  "author": "Doist developers",
6
6
  "homepage": "https://doist.github.io/comms-sdk-typescript/",