Skip to content

Commit 68e7b0b

Browse files
committed
chore: update NPM packages
1 parent 8c31330 commit 68e7b0b

File tree

14 files changed

+1576
-1088
lines changed

14 files changed

+1576
-1088
lines changed

src/Umbraco.Community.SimpleDashboards.Client/package-lock.json

Lines changed: 865 additions & 816 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Umbraco.Community.SimpleDashboards.Client/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
},
1212
"devDependencies": {
1313
"lit": "^3.3.1",
14-
"@hey-api/openapi-ts": "^0.80.1",
15-
"@umbraco-cms/backoffice": "^16.1.1",
16-
"typescript": "^5.8.3",
17-
"vite": "^7.0.6"
14+
"@hey-api/openapi-ts": "^0.82.4",
15+
"@umbraco-cms/backoffice": "^16.2.0",
16+
"typescript": "^5.9.2",
17+
"vite": "^7.1.4"
1818
},
1919
"volta": {
20-
"node": "22.14.0"
20+
"node": "22.12.0"
2121
}
2222
}

src/Umbraco.Community.SimpleDashboards.Client/src/api/client/client.ts renamed to src/Umbraco.Community.SimpleDashboards.Client/src/api/client/client.gen.ts

Lines changed: 116 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
import type { Client, Config, RequestOptions } from './types';
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
import { createSseClient } from '../core/serverSentEvents.gen';
4+
import type { HttpMethod } from '../core/types.gen';
5+
import type {
6+
Client,
7+
Config,
8+
RequestOptions,
9+
ResolvedRequestOptions,
10+
} from './types.gen';
211
import {
312
buildUrl,
413
createConfig,
@@ -7,7 +16,7 @@ import {
716
mergeConfigs,
817
mergeHeaders,
918
setAuthParams,
10-
} from './utils';
19+
} from './utils.gen';
1120

1221
type ReqInit = Omit<RequestInit, 'body' | 'headers'> & {
1322
body?: any;
@@ -28,15 +37,16 @@ export const createClient = (config: Config = {}): Client => {
2837
Request,
2938
Response,
3039
unknown,
31-
RequestOptions
40+
ResolvedRequestOptions
3241
>();
3342

34-
const request: Client['request'] = async (options) => {
43+
const beforeRequest = async (options: RequestOptions) => {
3544
const opts = {
3645
..._config,
3746
...options,
3847
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
3948
headers: mergeHeaders(_config.headers, options.headers),
49+
serializedBody: undefined,
4050
};
4151

4252
if (opts.security) {
@@ -50,19 +60,27 @@ export const createClient = (config: Config = {}): Client => {
5060
await opts.requestValidator(opts);
5161
}
5262

53-
if (opts.body && opts.bodySerializer) {
54-
opts.body = opts.bodySerializer(opts.body);
63+
if (opts.body !== undefined && opts.bodySerializer) {
64+
opts.serializedBody = opts.bodySerializer(opts.body);
5565
}
5666

5767
// remove Content-Type header if body is empty to avoid sending invalid requests
58-
if (opts.body === undefined || opts.body === '') {
68+
if (opts.body === undefined || opts.serializedBody === '') {
5969
opts.headers.delete('Content-Type');
6070
}
6171

6272
const url = buildUrl(opts);
73+
74+
return { opts, url };
75+
};
76+
77+
const request: Client['request'] = async (options) => {
78+
// @ts-expect-error
79+
const { opts, url } = await beforeRequest(options);
6380
const requestInit: ReqInit = {
6481
redirect: 'follow',
6582
...opts,
83+
body: getValidRequestBody(opts),
6684
};
6785

6886
let request = new Request(url, requestInit);
@@ -90,23 +108,41 @@ export const createClient = (config: Config = {}): Client => {
90108
};
91109

92110
if (response.ok) {
111+
const parseAs =
112+
(opts.parseAs === 'auto'
113+
? getParseAs(response.headers.get('Content-Type'))
114+
: opts.parseAs) ?? 'json';
115+
93116
if (
94117
response.status === 204 ||
95118
response.headers.get('Content-Length') === '0'
96119
) {
120+
let emptyData: any;
121+
switch (parseAs) {
122+
case 'arrayBuffer':
123+
case 'blob':
124+
case 'text':
125+
emptyData = await response[parseAs]();
126+
break;
127+
case 'formData':
128+
emptyData = new FormData();
129+
break;
130+
case 'stream':
131+
emptyData = response.body;
132+
break;
133+
case 'json':
134+
default:
135+
emptyData = {};
136+
break;
137+
}
97138
return opts.responseStyle === 'data'
98-
? {}
139+
? emptyData
99140
: {
100-
data: {},
141+
data: emptyData,
101142
...result,
102143
};
103144
}
104145

105-
const parseAs =
106-
(opts.parseAs === 'auto'
107-
? getParseAs(response.headers.get('Content-Type'))
108-
: opts.parseAs) ?? 'json';
109-
110146
let data: any;
111147
switch (parseAs) {
112148
case 'arrayBuffer':
@@ -176,20 +212,76 @@ export const createClient = (config: Config = {}): Client => {
176212
};
177213
};
178214

215+
function getValidRequestBody(options: ResolvedRequestOptions) {
216+
const hasBody = options.body !== undefined;
217+
const isSerializedBody = hasBody && options.bodySerializer;
218+
219+
if (isSerializedBody) {
220+
const hasSerializedBody =
221+
options.serializedBody !== undefined && options.serializedBody !== '';
222+
223+
return hasSerializedBody ? options.serializedBody : null;
224+
}
225+
226+
// plain/text body
227+
if (hasBody) {
228+
return options.body;
229+
}
230+
231+
// no body was provided
232+
return undefined;
233+
}
234+
235+
const makeMethodFn =
236+
(method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
237+
request({ ...options, method });
238+
239+
const makeSseFn =
240+
(method: Uppercase<HttpMethod>) => async (options: RequestOptions) => {
241+
const { opts, url } = await beforeRequest(options);
242+
return createSseClient({
243+
...opts,
244+
body: opts.body as BodyInit | null | undefined,
245+
headers: opts.headers as unknown as Record<string, string>,
246+
method,
247+
onRequest: async (url, init) => {
248+
let request = new Request(url, init);
249+
for (const fn of interceptors.request._fns) {
250+
if (fn) {
251+
request = await fn(request, opts);
252+
}
253+
}
254+
return request;
255+
},
256+
url,
257+
});
258+
};
259+
179260
return {
180261
buildUrl,
181-
connect: (options) => request({ ...options, method: 'CONNECT' }),
182-
delete: (options) => request({ ...options, method: 'DELETE' }),
183-
get: (options) => request({ ...options, method: 'GET' }),
262+
connect: makeMethodFn('CONNECT'),
263+
delete: makeMethodFn('DELETE'),
264+
get: makeMethodFn('GET'),
184265
getConfig,
185-
head: (options) => request({ ...options, method: 'HEAD' }),
266+
head: makeMethodFn('HEAD'),
186267
interceptors,
187-
options: (options) => request({ ...options, method: 'OPTIONS' }),
188-
patch: (options) => request({ ...options, method: 'PATCH' }),
189-
post: (options) => request({ ...options, method: 'POST' }),
190-
put: (options) => request({ ...options, method: 'PUT' }),
268+
options: makeMethodFn('OPTIONS'),
269+
patch: makeMethodFn('PATCH'),
270+
post: makeMethodFn('POST'),
271+
put: makeMethodFn('PUT'),
191272
request,
192273
setConfig,
193-
trace: (options) => request({ ...options, method: 'TRACE' }),
194-
};
274+
sse: {
275+
connect: makeSseFn('CONNECT'),
276+
delete: makeSseFn('DELETE'),
277+
get: makeSseFn('GET'),
278+
head: makeSseFn('HEAD'),
279+
options: makeSseFn('OPTIONS'),
280+
patch: makeSseFn('PATCH'),
281+
post: makeSseFn('POST'),
282+
put: makeSseFn('PUT'),
283+
trace: makeSseFn('TRACE'),
284+
},
285+
trace: makeMethodFn('TRACE'),
286+
} as Client;
195287
};
Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
export type { Auth } from '../core/auth';
2-
export type { QuerySerializerOptions } from '../core/bodySerializer';
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
export type { Auth } from '../core/auth.gen';
4+
export type { QuerySerializerOptions } from '../core/bodySerializer.gen';
35
export {
46
formDataBodySerializer,
57
jsonBodySerializer,
68
urlSearchParamsBodySerializer,
7-
} from '../core/bodySerializer';
8-
export { buildClientParams } from '../core/params';
9-
export { createClient } from './client';
9+
} from '../core/bodySerializer.gen';
10+
export { buildClientParams } from '../core/params.gen';
11+
export { createClient } from './client.gen';
1012
export type {
1113
Client,
1214
ClientOptions,
@@ -16,7 +18,8 @@ export type {
1618
OptionsLegacyParser,
1719
RequestOptions,
1820
RequestResult,
21+
ResolvedRequestOptions,
1922
ResponseStyle,
2023
TDataShape,
21-
} from './types';
22-
export { createConfig, mergeHeaders } from './utils';
24+
} from './types.gen';
25+
export { createConfig, mergeHeaders } from './utils.gen';

0 commit comments

Comments
 (0)