@launchdarkly/js-sdk-common 2.29.0 → 2.30.0

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/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  All notable changes to `@launchdarkly/js-sdk-common` will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org).
4
4
 
5
+ ## [2.30.0](https://github.com/launchdarkly/js-core/compare/js-sdk-common-v2.29.0...js-sdk-common-v2.30.0) (2026-10-14)
6
+
7
+
8
+ ### Features
9
+
10
+ * Add optional streaming members to the platform fetch types ([#2092](https://github.com/launchdarkly/js-core/issues/2092)) ([4137805](https://github.com/launchdarkly/js-core/commit/4137805723e14f1f21c07b45039c4eeda9889519))
11
+
5
12
  ## [2.29.0](https://github.com/launchdarkly/js-core/compare/js-sdk-common-v2.28.1...js-sdk-common-v2.29.0) (2026-10-06)
6
13
 
7
14
 
@@ -38,6 +38,41 @@ export interface Headers {
38
38
  * @param name The name of the header to check.
39
39
  */
40
40
  has(name: string): boolean;
41
+ /**
42
+ * Executes the callback once for each header, with the value first. Optional so existing
43
+ * implementations remain valid. The streaming client reads response headers through this
44
+ * method, or through {@link Headers.entries} when this method is absent.
45
+ *
46
+ * https://developer.mozilla.org/en-US/docs/Web/API/Headers/forEach
47
+ */
48
+ forEach?(callback: (value: string, key: string) => void): void;
49
+ }
50
+ /**
51
+ * A reader over a response body stream.
52
+ */
53
+ export interface BodyReader {
54
+ /**
55
+ * Resolves with the next chunk, or with `done: true` when the server ends the stream.
56
+ * Rejects when the connection terminates before the server ends the stream.
57
+ */
58
+ read(): Promise<{
59
+ done: boolean;
60
+ value?: Uint8Array;
61
+ }>;
62
+ /**
63
+ * Releases the reader and its connection.
64
+ */
65
+ cancel?(): Promise<unknown> | void;
66
+ }
67
+ /**
68
+ * A response body stream.
69
+ */
70
+ export interface ResponseBody {
71
+ getReader(): BodyReader;
72
+ /**
73
+ * Releases the body.
74
+ */
75
+ cancel?(): Promise<unknown> | void;
41
76
  }
42
77
  /**
43
78
  * Interface for fetch responses.
@@ -45,6 +80,20 @@ export interface Headers {
45
80
  export interface Response {
46
81
  headers: Headers;
47
82
  status: number;
83
+ /**
84
+ * The HTTP status message of the response. Optional so existing implementations remain
85
+ * valid.
86
+ *
87
+ * https://developer.mozilla.org/en-US/docs/Web/API/Response/statusText
88
+ */
89
+ statusText?: string;
90
+ /**
91
+ * The response body stream. An implementation provides it for a request made with
92
+ * {@link Options.streaming}. It can also provide it for other requests.
93
+ *
94
+ * https://developer.mozilla.org/en-US/docs/Web/API/Response/body
95
+ */
96
+ body?: ResponseBody | null;
48
97
  /**
49
98
  * Read the response and provide it as a string.
50
99
  */
@@ -54,6 +103,25 @@ export interface Response {
54
103
  */
55
104
  json(): Promise<any>;
56
105
  }
106
+ /**
107
+ * The platform's own `AbortSignal` type when the platform declares one as a global
108
+ * variable. An implementation that passes {@link Options} to a native `fetch` then
109
+ * type-checks against its platform's `RequestInit`. A platform that declares
110
+ * `AbortSignal` as a lexical class resolves to the fallback instead. The fallback is
111
+ * the minimal structural subset an implementation consumes. It keeps these declarations
112
+ * valid on a platform without the global.
113
+ */
114
+ export type AbortSignalLike = typeof globalThis extends {
115
+ AbortSignal: {
116
+ prototype: infer T;
117
+ };
118
+ } ? T : {
119
+ readonly aborted: boolean;
120
+ addEventListener(type: 'abort', listener: () => void, options?: {
121
+ once?: boolean;
122
+ }): void;
123
+ removeEventListener(type: 'abort', listener: () => void): void;
124
+ };
57
125
  export interface Options {
58
126
  headers?: Record<string, string>;
59
127
  method?: string;
@@ -69,6 +137,23 @@ export interface Options {
69
137
  * https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#keepalive
70
138
  */
71
139
  keepalive?: boolean;
140
+ /**
141
+ * An abort signal for the request. When the signal aborts, the implementation stops the
142
+ * request and rejects any pending read. Platform support for this field is best effort.
143
+ *
144
+ * https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#signal
145
+ */
146
+ signal?: AbortSignalLike;
147
+ /**
148
+ * True for a streaming request. The implementation does not buffer the response body,
149
+ * it does not request compressed content, and it ignores {@link Options.timeout}. The
150
+ * response exposes its body through
151
+ * {@link Response.body}. An SDK must use a fetch as a streaming transport only when the
152
+ * implementation honors this field. A streaming implementation must provide at least one
153
+ * release path. It honors {@link Options.signal}, or it provides the body cancel. It
154
+ * preferably provides both.
155
+ */
156
+ streaming?: boolean;
72
157
  }
73
158
  export interface EventSourceCapabilities {
74
159
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"Requests.d.ts","sourceRoot":"","sources":["../../../src/api/platform/Requests.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAOtE;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB;;;;;;OAMG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAEjC;;;;;;OAMG;IACH,IAAI,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;IAEzB;;;;;OAKG;IACH,MAAM,IAAI,QAAQ,CAAC,MAAM,CAAC,CAAC;IAE3B;;;;;OAKG;IACH,OAAO,IAAI,QAAQ,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAEtC;;;OAGG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IAExB;;OAEG;IACH,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC;CACtB;AAED,MAAM,WAAW,OAAO;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,MAAM,CAAC,EAAE,MAAM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CAC5B;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC"}
@@ -3661,6 +3661,136 @@ class PayloadStreamReader {
3661
3661
  }
3662
3662
  }
3663
3663
 
3664
+ /**
3665
+ * Wraps the raw headers in the fetch `Headers` shape. Lookups are case-insensitive.
3666
+ * Multi-value headers are joined with ", ", names that differ only by case merge into one
3667
+ * joined value, and names without a value are skipped.
3668
+ */
3669
+ function wrapRawHeaders(headers) {
3670
+ const normalized = new Map();
3671
+ Object.keys(headers).forEach((key) => {
3672
+ const val = headers[key];
3673
+ if (val !== undefined && val !== null) {
3674
+ const name = key.toLowerCase();
3675
+ const joined = Array.isArray(val) ? val.join(', ') : val;
3676
+ const existing = normalized.get(name);
3677
+ normalized.set(name, existing === undefined ? joined : `${existing}, ${joined}`);
3678
+ }
3679
+ });
3680
+ return {
3681
+ get: (name) => normalized.get(name.toLowerCase()) ?? null,
3682
+ keys: () => normalized.keys(),
3683
+ values: () => normalized.values(),
3684
+ entries: () => normalized.entries(),
3685
+ forEach: (callback) => {
3686
+ normalized.forEach((value, key) => callback(value, key));
3687
+ },
3688
+ has: (name) => normalized.has(name.toLowerCase()),
3689
+ };
3690
+ }
3691
+ /**
3692
+ * Creates a response for a streaming request. The response does not buffer the body. Each
3693
+ * read hands out the next chunk from the source iterator. The body does not enforce a
3694
+ * consumer lock: every `getReader`, `text`, and `json` call reads from the same iterator,
3695
+ * so the caller uses one consumer per response. The `cancel` methods on the body and the
3696
+ * reader call every release function the source provides: they destroy the source when it
3697
+ * has a `destroy` method, and they also call the iterator's `return` method when one
3698
+ * exists. The body passes through as-is, so the caller decodes any content encoding first.
3699
+ *
3700
+ * @param source The raw platform response, for example a Node `IncomingMessage`. A missing
3701
+ * status code maps to 0, and a missing status message maps to an empty string.
3702
+ */
3703
+ function createStreamingResponse(source) {
3704
+ // A consumer compiled without `Symbol.asyncIterator` in its lib can pass a source that
3705
+ // lacks the iterator without a compile error. The check turns that mistake into a named
3706
+ // failure instead of a bare member-access TypeError.
3707
+ if (typeof source[Symbol.asyncIterator] !== 'function') {
3708
+ throw new TypeError('the streaming response source does not provide an async iterator');
3709
+ }
3710
+ const iterator = source[Symbol.asyncIterator]();
3711
+ const cancel = async () => {
3712
+ // Destroy the stream first. That rejects a pending read and unblocks a queued return
3713
+ // call. A Node readable iterator queues the return call behind a pending read, and on
3714
+ // a stream that was never read it completes without a destroy, so the return call
3715
+ // alone cannot release the connection. Do not await it for the same reason. Each
3716
+ // release call is guarded on its own, so a release function that throws, or a return
3717
+ // that resolves synchronously, does not skip the other release path or reject cancel.
3718
+ try {
3719
+ source.destroy?.();
3720
+ }
3721
+ catch {
3722
+ // A throwing destroy has nothing left to release.
3723
+ }
3724
+ try {
3725
+ Promise.resolve(iterator.return?.()).catch(() => { });
3726
+ }
3727
+ catch {
3728
+ // A throwing return has nothing left to release.
3729
+ }
3730
+ };
3731
+ async function text() {
3732
+ const decoder = new TextDecoder();
3733
+ let result = '';
3734
+ try {
3735
+ let next = await iterator.next();
3736
+ while (!next.done) {
3737
+ if (next.value !== undefined) {
3738
+ try {
3739
+ result += decoder.decode(next.value, { stream: true });
3740
+ }
3741
+ catch {
3742
+ // decode() rejects a chunk that is not a BufferSource. The fixed message keeps
3743
+ // chunk contents out of error messages.
3744
+ throw new TypeError('the source supplied a chunk that is not a BufferSource');
3745
+ }
3746
+ }
3747
+ // The stream provides the chunks in sequence, so the reads cannot run in parallel.
3748
+ // oxlint-disable-next-line no-await-in-loop
3749
+ next = await iterator.next();
3750
+ }
3751
+ }
3752
+ catch (err) {
3753
+ // text() owns the body, so any failed read must release the source itself. This
3754
+ // covers a rejecting next() as well as a bad chunk.
3755
+ cancel();
3756
+ throw err;
3757
+ }
3758
+ // The final decode flushes a trailing partial multi-byte sequence.
3759
+ return result + decoder.decode();
3760
+ }
3761
+ return {
3762
+ headers: wrapRawHeaders(source.headers),
3763
+ status: source.statusCode ?? 0,
3764
+ statusText: source.statusMessage ?? '',
3765
+ body: {
3766
+ getReader: () => ({
3767
+ read: async () => {
3768
+ const next = await iterator.next();
3769
+ if (next.done) {
3770
+ return { done: true };
3771
+ }
3772
+ return { done: false, value: next.value };
3773
+ },
3774
+ cancel,
3775
+ }),
3776
+ cancel,
3777
+ },
3778
+ text,
3779
+ json: async () => JSON.parse(await text()),
3780
+ };
3781
+ }
3782
+
3783
+ /**
3784
+ * Converts the request options into the init shape a platform's native `fetch` accepts. A
3785
+ * platform can declare its `AbortSignal` as a lexical class, which `AbortSignalLike`
3786
+ * cannot resolve to, so the `signal` member widens here. The caller must pass a signal
3787
+ * created by the running platform. The widening then only restores the type the runtime
3788
+ * already has.
3789
+ */
3790
+ function toRequestInit(options) {
3791
+ return options;
3792
+ }
3793
+
3664
3794
  /**
3665
3795
  * Creates an InitMetadata object from initialization headers.
3666
3796
  *
@@ -3736,6 +3866,7 @@ var index = /*#__PURE__*/Object.freeze({
3736
3866
  PayloadStreamReader: PayloadStreamReader,
3737
3867
  canonicalize: canonicalize,
3738
3868
  createProtocolHandler: createProtocolHandler,
3869
+ createStreamingResponse: createStreamingResponse,
3739
3870
  initMetadataFromHeaders: initMetadataFromHeaders,
3740
3871
  isLegacyUser: isLegacyUser,
3741
3872
  isMultiKind: isMultiKind,
@@ -3745,7 +3876,8 @@ var index = /*#__PURE__*/Object.freeze({
3745
3876
  safeGetHooks: safeGetHooks,
3746
3877
  safeGetName: safeGetName,
3747
3878
  safeRegisterPlugins: safeRegisterPlugins,
3748
- shouldSample: shouldSample
3879
+ shouldSample: shouldSample,
3880
+ toRequestInit: toRequestInit
3749
3881
  });
3750
3882
 
3751
3883
  exports.ApplicationTags = ApplicationTags;