Skip to content

Commit e26e3c4

Browse files
committed
upgrade deps
1 parent 99a6e17 commit e26e3c4

File tree

14 files changed

+2110
-1317
lines changed

14 files changed

+2110
-1317
lines changed

package-lock.json

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

package.json

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@
3232
"homepage": "https://github.com/Short-io/client-node#readme",
3333
"prettier": "@short.io/eslint-config/prettier",
3434
"devDependencies": {
35-
"@eslint/js": "^9.16.0",
36-
"@hey-api/openapi-ts": "^0.59.0",
37-
"@types/node": "^22.10.1",
38-
"eslint": "^9.16.0",
39-
"globals": "^15.13.0",
40-
"tsc-alias": "^1.8.10",
41-
"typescript": "^5.7.2",
42-
"typescript-eslint": "^8.17.0"
35+
"@eslint/js": "^9.31.0",
36+
"@hey-api/openapi-ts": "^0.80.0",
37+
"@types/node": "^24.1.0",
38+
"eslint": "^9.31.0",
39+
"globals": "^16.3.0",
40+
"tsc-alias": "^1.8.16",
41+
"typescript": "^5.8.3",
42+
"typescript-eslint": "^8.38.0"
4343
},
4444
"dependencies": {
45-
"@hey-api/client-fetch": "^0.5.1"
45+
"@hey-api/client-fetch": "^0.13.1"
4646
},
4747
"packageManager": "yarn@1.22.22+sha256.c17d3797fb9a9115bf375e31bfd30058cac6bc9c3b8807a3d8cb2094794b51ca"
4848
}

src/generated/client.gen.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// This file is auto-generated by @hey-api/openapi-ts
2+
3+
import type { ClientOptions } from './types.gen';
4+
import { type Config, type ClientOptions as DefaultClientOptions, createClient, createConfig } from './client';
5+
6+
/**
7+
* The `createClientConfig()` function will be called on client initialization
8+
* and the returned object will become the client's initial configuration.
9+
*
10+
* You may want to initialize your client this way instead of calling
11+
* `setConfig()`. This is useful for example if you're using Next.js
12+
* to ensure your client always has the correct values.
13+
*/
14+
export type CreateClientConfig<T extends DefaultClientOptions = ClientOptions> = (override?: Config<DefaultClientOptions & T>) => Config<Required<DefaultClientOptions> & T>;
15+
16+
export const client = createClient(createConfig<ClientOptions>({
17+
baseUrl: 'https://api.short.io'
18+
}));

src/generated/client/client.ts

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
import type { Client, Config, RequestOptions } from './types';
2+
import {
3+
buildUrl,
4+
createConfig,
5+
createInterceptors,
6+
getParseAs,
7+
mergeConfigs,
8+
mergeHeaders,
9+
setAuthParams,
10+
} from './utils';
11+
12+
type ReqInit = Omit<RequestInit, 'body' | 'headers'> & {
13+
body?: any;
14+
headers: ReturnType<typeof mergeHeaders>;
15+
};
16+
17+
export const createClient = (config: Config = {}): Client => {
18+
let _config = mergeConfigs(createConfig(), config);
19+
20+
const getConfig = (): Config => ({ ..._config });
21+
22+
const setConfig = (config: Config): Config => {
23+
_config = mergeConfigs(_config, config);
24+
return getConfig();
25+
};
26+
27+
const interceptors = createInterceptors<
28+
Request,
29+
Response,
30+
unknown,
31+
RequestOptions
32+
>();
33+
34+
const request: Client['request'] = async (options) => {
35+
const opts = {
36+
..._config,
37+
...options,
38+
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
39+
headers: mergeHeaders(_config.headers, options.headers),
40+
};
41+
42+
if (opts.security) {
43+
await setAuthParams({
44+
...opts,
45+
security: opts.security,
46+
});
47+
}
48+
49+
if (opts.requestValidator) {
50+
await opts.requestValidator(opts);
51+
}
52+
53+
if (opts.body && opts.bodySerializer) {
54+
opts.body = opts.bodySerializer(opts.body);
55+
}
56+
57+
// remove Content-Type header if body is empty to avoid sending invalid requests
58+
if (opts.body === undefined || opts.body === '') {
59+
opts.headers.delete('Content-Type');
60+
}
61+
62+
const url = buildUrl(opts);
63+
const requestInit: ReqInit = {
64+
redirect: 'follow',
65+
...opts,
66+
};
67+
68+
let request = new Request(url, requestInit);
69+
70+
for (const fn of interceptors.request._fns) {
71+
if (fn) {
72+
request = await fn(request, opts);
73+
}
74+
}
75+
76+
// fetch must be assigned here, otherwise it would throw the error:
77+
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
78+
const _fetch = opts.fetch!;
79+
let response = await _fetch(request);
80+
81+
for (const fn of interceptors.response._fns) {
82+
if (fn) {
83+
response = await fn(response, request, opts);
84+
}
85+
}
86+
87+
const result = {
88+
request,
89+
response,
90+
};
91+
92+
if (response.ok) {
93+
if (
94+
response.status === 204 ||
95+
response.headers.get('Content-Length') === '0'
96+
) {
97+
return opts.responseStyle === 'data'
98+
? {}
99+
: {
100+
data: {},
101+
...result,
102+
};
103+
}
104+
105+
const parseAs =
106+
(opts.parseAs === 'auto'
107+
? getParseAs(response.headers.get('Content-Type'))
108+
: opts.parseAs) ?? 'json';
109+
110+
let data: any;
111+
switch (parseAs) {
112+
case 'arrayBuffer':
113+
case 'blob':
114+
case 'formData':
115+
case 'json':
116+
case 'text':
117+
data = await response[parseAs]();
118+
break;
119+
case 'stream':
120+
return opts.responseStyle === 'data'
121+
? response.body
122+
: {
123+
data: response.body,
124+
...result,
125+
};
126+
}
127+
128+
if (parseAs === 'json') {
129+
if (opts.responseValidator) {
130+
await opts.responseValidator(data);
131+
}
132+
133+
if (opts.responseTransformer) {
134+
data = await opts.responseTransformer(data);
135+
}
136+
}
137+
138+
return opts.responseStyle === 'data'
139+
? data
140+
: {
141+
data,
142+
...result,
143+
};
144+
}
145+
146+
const textError = await response.text();
147+
let jsonError: unknown;
148+
149+
try {
150+
jsonError = JSON.parse(textError);
151+
} catch {
152+
// noop
153+
}
154+
155+
const error = jsonError ?? textError;
156+
let finalError = error;
157+
158+
for (const fn of interceptors.error._fns) {
159+
if (fn) {
160+
finalError = (await fn(error, response, request, opts)) as string;
161+
}
162+
}
163+
164+
finalError = finalError || ({} as string);
165+
166+
if (opts.throwOnError) {
167+
throw finalError;
168+
}
169+
170+
// TODO: we probably want to return error and improve types
171+
return opts.responseStyle === 'data'
172+
? undefined
173+
: {
174+
error: finalError,
175+
...result,
176+
};
177+
};
178+
179+
return {
180+
buildUrl,
181+
connect: (options) => request({ ...options, method: 'CONNECT' }),
182+
delete: (options) => request({ ...options, method: 'DELETE' }),
183+
get: (options) => request({ ...options, method: 'GET' }),
184+
getConfig,
185+
head: (options) => request({ ...options, method: 'HEAD' }),
186+
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' }),
191+
request,
192+
setConfig,
193+
trace: (options) => request({ ...options, method: 'TRACE' }),
194+
};
195+
};

0 commit comments

Comments
 (0)