@kilocode/sdk 7.5.5 → 7.5.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.
- package/dist/v2/gen/client/client.gen.js +107 -125
- package/dist/v2/gen/client/types.gen.d.ts +7 -4
- package/dist/v2/gen/client/utils.gen.d.ts +7 -3
- package/dist/v2/gen/client/utils.gen.js +4 -4
- package/dist/v2/gen/core/bodySerializer.gen.d.ts +4 -4
- package/dist/v2/gen/core/params.gen.js +5 -5
- package/dist/v2/gen/core/serverSentEvents.gen.d.ts +1 -1
- package/dist/v2/gen/core/serverSentEvents.gen.js +3 -4
- package/dist/v2/gen/core/types.gen.d.ts +1 -1
- package/dist/v2/gen/core/utils.gen.js +1 -1
- package/dist/v2/gen/sdk.gen.d.ts +196 -174
- package/dist/v2/gen/sdk.gen.js +60 -6
- package/dist/v2/gen/types.gen.d.ts +60 -7
- package/package.json +2 -2
|
@@ -19,10 +19,7 @@ export const createClient = (config = {}) => {
|
|
|
19
19
|
serializedBody: undefined,
|
|
20
20
|
};
|
|
21
21
|
if (opts.security) {
|
|
22
|
-
await setAuthParams(
|
|
23
|
-
...opts,
|
|
24
|
-
security: opts.security,
|
|
25
|
-
});
|
|
22
|
+
await setAuthParams(opts);
|
|
26
23
|
}
|
|
27
24
|
if (opts.requestValidator) {
|
|
28
25
|
await opts.requestValidator(opts);
|
|
@@ -34,152 +31,137 @@ export const createClient = (config = {}) => {
|
|
|
34
31
|
if (opts.body === undefined || opts.serializedBody === "") {
|
|
35
32
|
opts.headers.delete("Content-Type");
|
|
36
33
|
}
|
|
37
|
-
const
|
|
38
|
-
|
|
34
|
+
const resolvedOpts = opts;
|
|
35
|
+
const url = buildUrl(resolvedOpts);
|
|
36
|
+
return { opts: resolvedOpts, url };
|
|
39
37
|
};
|
|
40
38
|
const request = async (options) => {
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
redirect: "follow",
|
|
45
|
-
...opts,
|
|
46
|
-
body: getValidRequestBody(opts),
|
|
47
|
-
};
|
|
48
|
-
let request = new Request(url, requestInit);
|
|
49
|
-
for (const fn of interceptors.request.fns) {
|
|
50
|
-
if (fn) {
|
|
51
|
-
request = await fn(request, opts);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
// fetch must be assigned here, otherwise it would throw the error:
|
|
55
|
-
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
|
|
56
|
-
const _fetch = opts.fetch;
|
|
39
|
+
const throwOnError = options.throwOnError ?? _config.throwOnError;
|
|
40
|
+
const responseStyle = options.responseStyle ?? _config.responseStyle;
|
|
41
|
+
let request;
|
|
57
42
|
let response;
|
|
58
43
|
try {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
44
|
+
const { opts, url } = await beforeRequest(options);
|
|
45
|
+
const requestInit = {
|
|
46
|
+
redirect: "follow",
|
|
47
|
+
...opts,
|
|
48
|
+
body: getValidRequestBody(opts),
|
|
49
|
+
};
|
|
50
|
+
request = new Request(url, requestInit);
|
|
51
|
+
for (const fn of interceptors.request.fns) {
|
|
65
52
|
if (fn) {
|
|
66
|
-
|
|
53
|
+
request = await fn(request, opts);
|
|
67
54
|
}
|
|
68
55
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
error: finalError,
|
|
78
|
-
request,
|
|
79
|
-
response: undefined,
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
for (const fn of interceptors.response.fns) {
|
|
83
|
-
if (fn) {
|
|
84
|
-
response = await fn(response, request, opts);
|
|
56
|
+
// fetch must be assigned here, otherwise it would throw the error:
|
|
57
|
+
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
|
|
58
|
+
const _fetch = opts.fetch;
|
|
59
|
+
response = await _fetch(request);
|
|
60
|
+
for (const fn of interceptors.response.fns) {
|
|
61
|
+
if (fn) {
|
|
62
|
+
response = await fn(response, request, opts);
|
|
63
|
+
}
|
|
85
64
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
65
|
+
const result = {
|
|
66
|
+
request,
|
|
67
|
+
response,
|
|
68
|
+
};
|
|
69
|
+
if (response.ok) {
|
|
70
|
+
const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
|
|
71
|
+
if (response.status === 204 || response.headers.get("Content-Length") === "0") {
|
|
72
|
+
let emptyData;
|
|
73
|
+
switch (parseAs) {
|
|
74
|
+
case "arrayBuffer":
|
|
75
|
+
case "blob":
|
|
76
|
+
case "text":
|
|
77
|
+
emptyData = await response[parseAs]();
|
|
78
|
+
break;
|
|
79
|
+
case "formData":
|
|
80
|
+
emptyData = new FormData();
|
|
81
|
+
break;
|
|
82
|
+
case "stream":
|
|
83
|
+
emptyData = response.body;
|
|
84
|
+
break;
|
|
85
|
+
case "json":
|
|
86
|
+
default:
|
|
87
|
+
emptyData = {};
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
return opts.responseStyle === "data"
|
|
91
|
+
? emptyData
|
|
92
|
+
: {
|
|
93
|
+
data: emptyData,
|
|
94
|
+
...result,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
let data;
|
|
95
98
|
switch (parseAs) {
|
|
96
99
|
case "arrayBuffer":
|
|
97
100
|
case "blob":
|
|
101
|
+
case "formData":
|
|
98
102
|
case "text":
|
|
99
|
-
|
|
103
|
+
data = await response[parseAs]();
|
|
100
104
|
break;
|
|
101
|
-
case "
|
|
102
|
-
|
|
105
|
+
case "json": {
|
|
106
|
+
// Some servers return 200 with no Content-Length and empty body.
|
|
107
|
+
// response.json() would throw; read as text and parse if non-empty.
|
|
108
|
+
const text = await response.text();
|
|
109
|
+
data = text ? JSON.parse(text) : {};
|
|
103
110
|
break;
|
|
111
|
+
}
|
|
104
112
|
case "stream":
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
113
|
+
return opts.responseStyle === "data"
|
|
114
|
+
? response.body
|
|
115
|
+
: {
|
|
116
|
+
data: response.body,
|
|
117
|
+
...result,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
if (parseAs === "json") {
|
|
121
|
+
if (opts.responseValidator) {
|
|
122
|
+
await opts.responseValidator(data);
|
|
123
|
+
}
|
|
124
|
+
if (opts.responseTransformer) {
|
|
125
|
+
data = await opts.responseTransformer(data);
|
|
126
|
+
}
|
|
111
127
|
}
|
|
112
128
|
return opts.responseStyle === "data"
|
|
113
|
-
?
|
|
129
|
+
? data
|
|
114
130
|
: {
|
|
115
|
-
data
|
|
131
|
+
data,
|
|
116
132
|
...result,
|
|
117
133
|
};
|
|
118
134
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
case "formData":
|
|
124
|
-
case "text":
|
|
125
|
-
data = await response[parseAs]();
|
|
126
|
-
break;
|
|
127
|
-
case "json": {
|
|
128
|
-
// Some servers return 200 with no Content-Length and empty body.
|
|
129
|
-
// response.json() would throw; read as text and parse if non-empty.
|
|
130
|
-
const text = await response.text();
|
|
131
|
-
data = text ? JSON.parse(text) : {};
|
|
132
|
-
break;
|
|
133
|
-
}
|
|
134
|
-
case "stream":
|
|
135
|
-
return opts.responseStyle === "data"
|
|
136
|
-
? response.body
|
|
137
|
-
: {
|
|
138
|
-
data: response.body,
|
|
139
|
-
...result,
|
|
140
|
-
};
|
|
135
|
+
const textError = await response.text();
|
|
136
|
+
let jsonError;
|
|
137
|
+
try {
|
|
138
|
+
jsonError = JSON.parse(textError);
|
|
141
139
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
140
|
+
catch {
|
|
141
|
+
// noop
|
|
142
|
+
}
|
|
143
|
+
throw jsonError ?? textError;
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
let finalError = error;
|
|
147
|
+
for (const fn of interceptors.error.fns) {
|
|
148
|
+
if (fn) {
|
|
149
|
+
finalError = await fn(finalError, response, request, options);
|
|
148
150
|
}
|
|
149
151
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
+
finalError = finalError || {};
|
|
153
|
+
if (throwOnError) {
|
|
154
|
+
throw finalError;
|
|
155
|
+
}
|
|
156
|
+
// TODO: we probably want to return error and improve types
|
|
157
|
+
return responseStyle === "data"
|
|
158
|
+
? undefined
|
|
152
159
|
: {
|
|
153
|
-
|
|
154
|
-
|
|
160
|
+
error: finalError,
|
|
161
|
+
request,
|
|
162
|
+
response,
|
|
155
163
|
};
|
|
156
164
|
}
|
|
157
|
-
const textError = await response.text();
|
|
158
|
-
let jsonError;
|
|
159
|
-
try {
|
|
160
|
-
jsonError = JSON.parse(textError);
|
|
161
|
-
}
|
|
162
|
-
catch {
|
|
163
|
-
// noop
|
|
164
|
-
}
|
|
165
|
-
const error = jsonError ?? textError;
|
|
166
|
-
let finalError = error;
|
|
167
|
-
for (const fn of interceptors.error.fns) {
|
|
168
|
-
if (fn) {
|
|
169
|
-
finalError = (await fn(error, response, request, opts));
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
finalError = finalError || {};
|
|
173
|
-
if (opts.throwOnError) {
|
|
174
|
-
throw finalError;
|
|
175
|
-
}
|
|
176
|
-
// TODO: we probably want to return error and improve types
|
|
177
|
-
return opts.responseStyle === "data"
|
|
178
|
-
? undefined
|
|
179
|
-
: {
|
|
180
|
-
error: finalError,
|
|
181
|
-
...result,
|
|
182
|
-
};
|
|
183
165
|
};
|
|
184
166
|
const makeMethodFn = (method) => (options) => request({ ...options, method });
|
|
185
167
|
const makeSseFn = (method) => async (options) => {
|
|
@@ -187,7 +169,6 @@ export const createClient = (config = {}) => {
|
|
|
187
169
|
return createSseClient({
|
|
188
170
|
...opts,
|
|
189
171
|
body: opts.body,
|
|
190
|
-
headers: opts.headers,
|
|
191
172
|
method,
|
|
192
173
|
onRequest: async (url, init) => {
|
|
193
174
|
let request = new Request(url, init);
|
|
@@ -202,8 +183,9 @@ export const createClient = (config = {}) => {
|
|
|
202
183
|
url,
|
|
203
184
|
});
|
|
204
185
|
};
|
|
186
|
+
const _buildUrl = (options) => buildUrl({ ..._config, ...options });
|
|
205
187
|
return {
|
|
206
|
-
buildUrl,
|
|
188
|
+
buildUrl: _buildUrl,
|
|
207
189
|
connect: makeMethodFn("CONNECT"),
|
|
208
190
|
delete: makeMethodFn("DELETE"),
|
|
209
191
|
get: makeMethodFn("GET"),
|
|
@@ -47,7 +47,7 @@ export interface Config<T extends ClientOptions = ClientOptions> extends Omit<Re
|
|
|
47
47
|
export interface RequestOptions<TData = unknown, TResponseStyle extends ResponseStyle = "fields", ThrowOnError extends boolean = boolean, Url extends string = string> extends Config<{
|
|
48
48
|
responseStyle: TResponseStyle;
|
|
49
49
|
throwOnError: ThrowOnError;
|
|
50
|
-
}>, Pick<ServerSentEventsOptions<TData>, "onSseError" | "onSseEvent" | "sseDefaultRetryDelay" | "sseMaxRetryAttempts" | "sseMaxRetryDelay"> {
|
|
50
|
+
}>, Pick<ServerSentEventsOptions<TData>, "onRequest" | "onSseError" | "onSseEvent" | "sseDefaultRetryDelay" | "sseMaxRetryAttempts" | "sseMaxRetryDelay"> {
|
|
51
51
|
/**
|
|
52
52
|
* Any body that you want to add to your request.
|
|
53
53
|
*
|
|
@@ -63,6 +63,7 @@ export interface RequestOptions<TData = unknown, TResponseStyle extends Response
|
|
|
63
63
|
url: Url;
|
|
64
64
|
}
|
|
65
65
|
export interface ResolvedRequestOptions<TResponseStyle extends ResponseStyle = "fields", ThrowOnError extends boolean = boolean, Url extends string = string> extends RequestOptions<unknown, TResponseStyle, ThrowOnError, Url> {
|
|
66
|
+
headers: Headers;
|
|
66
67
|
serializedBody?: string;
|
|
67
68
|
}
|
|
68
69
|
export type RequestResult<TData = unknown, TError = unknown, ThrowOnError extends boolean = boolean, TResponseStyle extends ResponseStyle = "fields"> = ThrowOnError extends true ? Promise<TResponseStyle extends "data" ? TData extends Record<string, unknown> ? TData[keyof TData] : TData : {
|
|
@@ -76,8 +77,10 @@ export type RequestResult<TData = unknown, TError = unknown, ThrowOnError extend
|
|
|
76
77
|
data: undefined;
|
|
77
78
|
error: TError extends Record<string, unknown> ? TError[keyof TError] : TError;
|
|
78
79
|
}) & {
|
|
79
|
-
request
|
|
80
|
-
|
|
80
|
+
/** request may be undefined, because error may be from building the request object itself */
|
|
81
|
+
request?: Request;
|
|
82
|
+
/** response may be undefined, because error may be from building the request object itself or from a network error */
|
|
83
|
+
response?: Response;
|
|
81
84
|
}>;
|
|
82
85
|
export interface ClientOptions {
|
|
83
86
|
baseUrl?: string;
|
|
@@ -85,7 +88,7 @@ export interface ClientOptions {
|
|
|
85
88
|
throwOnError?: boolean;
|
|
86
89
|
}
|
|
87
90
|
type MethodFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = "fields">(options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, "method">) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
|
88
|
-
type SseFn = <TData = unknown,
|
|
91
|
+
type SseFn = <TData = unknown, _TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = "fields">(options: Omit<RequestOptions<never, TResponseStyle, ThrowOnError>, "method">) => Promise<ServerSentEventsResult<TData>>;
|
|
89
92
|
type RequestFn = <TData = unknown, TError = unknown, ThrowOnError extends boolean = false, TResponseStyle extends ResponseStyle = "fields">(options: Omit<RequestOptions<TData, TResponseStyle, ThrowOnError>, "method"> & Pick<Required<RequestOptions<TData, TResponseStyle, ThrowOnError>>, "method">) => RequestResult<TData, TError, ThrowOnError, TResponseStyle>;
|
|
90
93
|
type BuildUrlFn = <TData extends {
|
|
91
94
|
body?: unknown;
|
|
@@ -5,13 +5,17 @@ export declare const createQuerySerializer: <T = unknown>({ parameters, ...args
|
|
|
5
5
|
* Infers parseAs value from provided Content-Type header.
|
|
6
6
|
*/
|
|
7
7
|
export declare const getParseAs: (contentType: string | null) => Exclude<Config["parseAs"], "auto">;
|
|
8
|
-
export declare
|
|
8
|
+
export declare function setAuthParams(options: Pick<RequestOptions, "auth" | "query" | "security"> & {
|
|
9
9
|
headers: Headers;
|
|
10
|
-
})
|
|
10
|
+
}): Promise<void>;
|
|
11
11
|
export declare const buildUrl: Client["buildUrl"];
|
|
12
12
|
export declare const mergeConfigs: (a: Config, b: Config) => Config;
|
|
13
13
|
export declare const mergeHeaders: (...headers: Array<Required<Config>["headers"] | undefined>) => Headers;
|
|
14
|
-
type ErrInterceptor<Err, Res, Req, Options> = (error: Err,
|
|
14
|
+
type ErrInterceptor<Err, Res, Req, Options> = (error: Err,
|
|
15
|
+
/** response may be undefined due to a network error where no response object is produced */
|
|
16
|
+
response: Res | undefined,
|
|
17
|
+
/** request may be undefined, because error may be from building the request object itself */
|
|
18
|
+
request: Req | undefined, options: Options) => Err | Promise<Err>;
|
|
15
19
|
type ReqInterceptor<Req, Options> = (request: Req, options: Options) => Req | Promise<Req>;
|
|
16
20
|
type ResInterceptor<Res, Req, Options> = (response: Res, request: Req, options: Options) => Res | Promise<Res>;
|
|
17
21
|
declare class Interceptors<Interceptor> {
|
|
@@ -88,8 +88,8 @@ const checkForExistence = (options, name) => {
|
|
|
88
88
|
}
|
|
89
89
|
return false;
|
|
90
90
|
};
|
|
91
|
-
export
|
|
92
|
-
for (const auth of security) {
|
|
91
|
+
export async function setAuthParams(options) {
|
|
92
|
+
for (const auth of options.security ?? []) {
|
|
93
93
|
if (checkForExistence(options, auth.name)) {
|
|
94
94
|
continue;
|
|
95
95
|
}
|
|
@@ -114,7 +114,7 @@ export const setAuthParams = async ({ security, ...options }) => {
|
|
|
114
114
|
break;
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
|
-
}
|
|
117
|
+
}
|
|
118
118
|
export const buildUrl = (options) => getUrl({
|
|
119
119
|
baseUrl: options.baseUrl,
|
|
120
120
|
path: options.path,
|
|
@@ -156,7 +156,7 @@ export const mergeHeaders = (...headers) => {
|
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
158
|
else if (value !== undefined) {
|
|
159
|
-
// assume object headers are meant to be JSON stringified, i.e
|
|
159
|
+
// assume object headers are meant to be JSON stringified, i.e., their
|
|
160
160
|
// content value in OpenAPI specification is 'application/json'
|
|
161
161
|
mergedHeaders.set(key, typeof value === "object" ? JSON.stringify(value) : value);
|
|
162
162
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ArrayStyle, ObjectStyle, SerializerOptions } from "./pathSerializer.gen.js";
|
|
2
2
|
export type QuerySerializer = (query: Record<string, unknown>) => string;
|
|
3
|
-
export type BodySerializer = (body:
|
|
3
|
+
export type BodySerializer = (body: unknown) => unknown;
|
|
4
4
|
type QuerySerializerOptionsObject = {
|
|
5
5
|
allowReserved?: boolean;
|
|
6
6
|
array?: Partial<SerializerOptions<ArrayStyle>>;
|
|
@@ -14,12 +14,12 @@ export type QuerySerializerOptions = QuerySerializerOptionsObject & {
|
|
|
14
14
|
parameters?: Record<string, QuerySerializerOptionsObject>;
|
|
15
15
|
};
|
|
16
16
|
export declare const formDataBodySerializer: {
|
|
17
|
-
bodySerializer:
|
|
17
|
+
bodySerializer: (body: unknown) => FormData;
|
|
18
18
|
};
|
|
19
19
|
export declare const jsonBodySerializer: {
|
|
20
|
-
bodySerializer:
|
|
20
|
+
bodySerializer: (body: unknown) => string;
|
|
21
21
|
};
|
|
22
22
|
export declare const urlSearchParamsBodySerializer: {
|
|
23
|
-
bodySerializer:
|
|
23
|
+
bodySerializer: (body: unknown) => string;
|
|
24
24
|
};
|
|
25
25
|
export {};
|
|
@@ -32,17 +32,17 @@ const buildKeyMap = (fields, map) => {
|
|
|
32
32
|
};
|
|
33
33
|
const stripEmptySlots = (params) => {
|
|
34
34
|
for (const [slot, value] of Object.entries(params)) {
|
|
35
|
-
if (value && typeof value === "object" && !Object.keys(value).length) {
|
|
35
|
+
if (value && typeof value === "object" && !Array.isArray(value) && !Object.keys(value).length) {
|
|
36
36
|
delete params[slot];
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
};
|
|
40
40
|
export const buildClientParams = (args, fields) => {
|
|
41
41
|
const params = {
|
|
42
|
-
body:
|
|
43
|
-
headers:
|
|
44
|
-
path:
|
|
45
|
-
query:
|
|
42
|
+
body: Object.create(null),
|
|
43
|
+
headers: Object.create(null),
|
|
44
|
+
path: Object.create(null),
|
|
45
|
+
query: Object.create(null),
|
|
46
46
|
};
|
|
47
47
|
const map = buildKeyMap(fields);
|
|
48
48
|
let config;
|
|
@@ -68,4 +68,4 @@ export interface StreamEvent<TData = unknown> {
|
|
|
68
68
|
export type ServerSentEventsResult<TData = unknown, TReturn = void, TNext = unknown> = {
|
|
69
69
|
stream: AsyncGenerator<TData extends Record<string, unknown> ? TData[keyof TData] : TData, TReturn, TNext>;
|
|
70
70
|
};
|
|
71
|
-
export declare
|
|
71
|
+
export declare function createSseClient<TData = unknown>({ onRequest, onSseError, onSseEvent, responseTransformer, responseValidator, sseDefaultRetryDelay, sseMaxRetryAttempts, sseMaxRetryDelay, sseSleepFn, url, ...options }: ServerSentEventsOptions): ServerSentEventsResult<TData>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
-
export
|
|
2
|
+
export function createSseClient({ onRequest, onSseError, onSseEvent, responseTransformer, responseValidator, sseDefaultRetryDelay, sseMaxRetryAttempts, sseMaxRetryDelay, sseSleepFn, url, ...options }) {
|
|
3
3
|
let lastEventId;
|
|
4
4
|
const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
5
5
|
const createStream = async function* () {
|
|
@@ -53,8 +53,7 @@ export const createSseClient = ({ onRequest, onSseError, onSseEvent, responseTra
|
|
|
53
53
|
if (done)
|
|
54
54
|
break;
|
|
55
55
|
buffer += value;
|
|
56
|
-
|
|
57
|
-
buffer = buffer.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
|
|
56
|
+
buffer = buffer.replace(/\r\n?/g, "\n"); // normalize line endings
|
|
58
57
|
const chunks = buffer.split("\n\n");
|
|
59
58
|
buffer = chunks.pop() ?? "";
|
|
60
59
|
for (const chunk of chunks) {
|
|
@@ -130,4 +129,4 @@ export const createSseClient = ({ onRequest, onSseError, onSseEvent, responseTra
|
|
|
130
129
|
};
|
|
131
130
|
const stream = createStream();
|
|
132
131
|
return { stream };
|
|
133
|
-
}
|
|
132
|
+
}
|
|
@@ -61,7 +61,7 @@ export interface Config {
|
|
|
61
61
|
requestValidator?: (data: unknown) => Promise<unknown>;
|
|
62
62
|
/**
|
|
63
63
|
* A function transforming response data before it's returned. This is useful
|
|
64
|
-
* for post-processing data, e.g
|
|
64
|
+
* for post-processing data, e.g., converting ISO strings into Date objects.
|
|
65
65
|
*/
|
|
66
66
|
responseTransformer?: (data: unknown) => Promise<unknown>;
|
|
67
67
|
/**
|
|
@@ -75,7 +75,7 @@ export function getValidRequestBody(options) {
|
|
|
75
75
|
const hasSerializedBody = options.serializedBody !== undefined && options.serializedBody !== "";
|
|
76
76
|
return hasSerializedBody ? options.serializedBody : null;
|
|
77
77
|
}
|
|
78
|
-
// not all clients implement a serializedBody property (i.e
|
|
78
|
+
// not all clients implement a serializedBody property (i.e., client-axios)
|
|
79
79
|
return options.body !== "" ? options.body : null;
|
|
80
80
|
}
|
|
81
81
|
// plain/text body
|