waldur-js-client 8.0.9-dev.30 → 8.0.9-dev.32
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/client/{client.d.ts → client.gen.d.ts} +1 -1
- package/dist/client/client.gen.js +216 -0
- package/dist/client/index.d.ts +8 -7
- package/dist/client/index.js +6 -4
- package/dist/client/{types.d.ts → types.gen.d.ts} +22 -21
- package/dist/client/types.gen.js +2 -0
- package/dist/client/{utils.d.ts → utils.gen.d.ts} +16 -24
- package/dist/client/{utils.js → utils.gen.js} +65 -121
- package/dist/client.gen.d.ts +3 -3
- package/dist/core/{auth.js → auth.gen.js} +1 -0
- package/dist/core/bodySerializer.gen.d.ts +25 -0
- package/dist/core/{bodySerializer.js → bodySerializer.gen.js} +5 -1
- package/dist/core/{params.d.ts → params.gen.d.ts} +20 -0
- package/dist/core/{params.js → params.gen.js} +23 -10
- package/dist/core/{pathSerializer.js → pathSerializer.gen.js} +4 -11
- package/dist/core/queryKeySerializer.gen.d.ts +18 -0
- package/dist/core/queryKeySerializer.gen.js +92 -0
- package/dist/core/serverSentEvents.gen.d.ts +71 -0
- package/dist/core/serverSentEvents.gen.js +132 -0
- package/dist/core/{types.d.ts → types.gen.d.ts} +20 -15
- package/dist/core/types.gen.js +2 -0
- package/dist/core/utils.gen.d.ts +19 -0
- package/dist/core/utils.gen.js +87 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -2
- package/dist/sdk.gen.d.ts +1061 -4
- package/dist/sdk.gen.js +28375 -55513
- package/dist/types.gen.d.ts +604 -422
- package/package.json +1 -1
- package/dist/client/client.js +0 -143
- package/dist/client/types.js +0 -1
- package/dist/core/bodySerializer.d.ts +0 -17
- package/dist/core/types.js +0 -1
- /package/dist/core/{auth.d.ts → auth.gen.d.ts} +0 -0
- /package/dist/core/{pathSerializer.d.ts → pathSerializer.gen.d.ts} +0 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
export function createSseClient({ onRequest, onSseError, onSseEvent, responseTransformer, responseValidator, sseDefaultRetryDelay, sseMaxRetryAttempts, sseMaxRetryDelay, sseSleepFn, url, ...options }) {
|
|
3
|
+
let lastEventId;
|
|
4
|
+
const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
5
|
+
const createStream = async function* () {
|
|
6
|
+
let retryDelay = sseDefaultRetryDelay ?? 3000;
|
|
7
|
+
let attempt = 0;
|
|
8
|
+
const signal = options.signal ?? new AbortController().signal;
|
|
9
|
+
while (true) {
|
|
10
|
+
if (signal.aborted)
|
|
11
|
+
break;
|
|
12
|
+
attempt++;
|
|
13
|
+
const headers = options.headers instanceof Headers
|
|
14
|
+
? options.headers
|
|
15
|
+
: new Headers(options.headers);
|
|
16
|
+
if (lastEventId !== undefined) {
|
|
17
|
+
headers.set('Last-Event-ID', lastEventId);
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
const requestInit = {
|
|
21
|
+
redirect: 'follow',
|
|
22
|
+
...options,
|
|
23
|
+
body: options.serializedBody,
|
|
24
|
+
headers,
|
|
25
|
+
signal,
|
|
26
|
+
};
|
|
27
|
+
let request = new Request(url, requestInit);
|
|
28
|
+
if (onRequest) {
|
|
29
|
+
request = await onRequest(url, requestInit);
|
|
30
|
+
}
|
|
31
|
+
// fetch must be assigned here, otherwise it would throw the error:
|
|
32
|
+
// TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
|
|
33
|
+
const _fetch = options.fetch ?? globalThis.fetch;
|
|
34
|
+
const response = await _fetch(request);
|
|
35
|
+
if (!response.ok)
|
|
36
|
+
throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
|
|
37
|
+
if (!response.body)
|
|
38
|
+
throw new Error('No body in SSE response');
|
|
39
|
+
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
40
|
+
let buffer = '';
|
|
41
|
+
const abortHandler = () => {
|
|
42
|
+
try {
|
|
43
|
+
reader.cancel();
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
// noop
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
signal.addEventListener('abort', abortHandler);
|
|
50
|
+
try {
|
|
51
|
+
while (true) {
|
|
52
|
+
const { done, value } = await reader.read();
|
|
53
|
+
if (done)
|
|
54
|
+
break;
|
|
55
|
+
buffer += value;
|
|
56
|
+
buffer = buffer.replace(/\r\n?/g, '\n'); // normalize line endings
|
|
57
|
+
const chunks = buffer.split('\n\n');
|
|
58
|
+
buffer = chunks.pop() ?? '';
|
|
59
|
+
for (const chunk of chunks) {
|
|
60
|
+
const lines = chunk.split('\n');
|
|
61
|
+
const dataLines = [];
|
|
62
|
+
let eventName;
|
|
63
|
+
for (const line of lines) {
|
|
64
|
+
if (line.startsWith('data:')) {
|
|
65
|
+
dataLines.push(line.replace(/^data:\s*/, ''));
|
|
66
|
+
}
|
|
67
|
+
else if (line.startsWith('event:')) {
|
|
68
|
+
eventName = line.replace(/^event:\s*/, '');
|
|
69
|
+
}
|
|
70
|
+
else if (line.startsWith('id:')) {
|
|
71
|
+
lastEventId = line.replace(/^id:\s*/, '');
|
|
72
|
+
}
|
|
73
|
+
else if (line.startsWith('retry:')) {
|
|
74
|
+
const parsed = Number.parseInt(line.replace(/^retry:\s*/, ''), 10);
|
|
75
|
+
if (!Number.isNaN(parsed)) {
|
|
76
|
+
retryDelay = parsed;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
let data;
|
|
81
|
+
let parsedJson = false;
|
|
82
|
+
if (dataLines.length) {
|
|
83
|
+
const rawData = dataLines.join('\n');
|
|
84
|
+
try {
|
|
85
|
+
data = JSON.parse(rawData);
|
|
86
|
+
parsedJson = true;
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
data = rawData;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
if (parsedJson) {
|
|
93
|
+
if (responseValidator) {
|
|
94
|
+
await responseValidator(data);
|
|
95
|
+
}
|
|
96
|
+
if (responseTransformer) {
|
|
97
|
+
data = await responseTransformer(data);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
onSseEvent?.({
|
|
101
|
+
data,
|
|
102
|
+
event: eventName,
|
|
103
|
+
id: lastEventId,
|
|
104
|
+
retry: retryDelay,
|
|
105
|
+
});
|
|
106
|
+
if (dataLines.length) {
|
|
107
|
+
yield data;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
finally {
|
|
113
|
+
signal.removeEventListener('abort', abortHandler);
|
|
114
|
+
reader.releaseLock();
|
|
115
|
+
}
|
|
116
|
+
break; // exit loop on normal completion
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
// connection failed or aborted; retry after delay
|
|
120
|
+
onSseError?.(error);
|
|
121
|
+
if (sseMaxRetryAttempts !== undefined && attempt >= sseMaxRetryAttempts) {
|
|
122
|
+
break; // stop after firing error
|
|
123
|
+
}
|
|
124
|
+
// exponential backoff: double retry each attempt, cap at 30s
|
|
125
|
+
const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 30000);
|
|
126
|
+
await sleep(backoff);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
const stream = createStream();
|
|
131
|
+
return { stream };
|
|
132
|
+
}
|
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import type { Auth, AuthToken } from './auth';
|
|
2
|
-
import type { BodySerializer, QuerySerializer, QuerySerializerOptions } from './bodySerializer';
|
|
3
|
-
export
|
|
1
|
+
import type { Auth, AuthToken } from './auth.gen';
|
|
2
|
+
import type { BodySerializer, QuerySerializer, QuerySerializerOptions } from './bodySerializer.gen';
|
|
3
|
+
export type HttpMethod = 'connect' | 'delete' | 'get' | 'head' | 'options' | 'patch' | 'post' | 'put' | 'trace';
|
|
4
|
+
export type Client<RequestFn = never, Config = unknown, MethodFn = never, BuildUrlFn = never, SseFn = never> = {
|
|
4
5
|
/**
|
|
5
6
|
* Returns the final request URL.
|
|
6
7
|
*/
|
|
7
8
|
buildUrl: BuildUrlFn;
|
|
8
|
-
connect: MethodFn;
|
|
9
|
-
delete: MethodFn;
|
|
10
|
-
get: MethodFn;
|
|
11
9
|
getConfig: () => Config;
|
|
12
|
-
head: MethodFn;
|
|
13
|
-
options: MethodFn;
|
|
14
|
-
patch: MethodFn;
|
|
15
|
-
post: MethodFn;
|
|
16
|
-
put: MethodFn;
|
|
17
10
|
request: RequestFn;
|
|
18
11
|
setConfig: (config: Config) => Config;
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
} & {
|
|
13
|
+
[K in HttpMethod]: MethodFn;
|
|
14
|
+
} & ([SseFn] extends [never] ? {
|
|
15
|
+
sse?: never;
|
|
16
|
+
} : {
|
|
17
|
+
sse: {
|
|
18
|
+
[K in HttpMethod]: SseFn;
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
21
|
export interface Config {
|
|
22
22
|
/**
|
|
23
23
|
* Auth token or a function returning auth token. The resolved value will be
|
|
@@ -41,7 +41,7 @@ export interface Config {
|
|
|
41
41
|
*
|
|
42
42
|
* {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more}
|
|
43
43
|
*/
|
|
44
|
-
method?:
|
|
44
|
+
method?: Uppercase<HttpMethod>;
|
|
45
45
|
/**
|
|
46
46
|
* A function for serializing request query parameters. By default, arrays
|
|
47
47
|
* will be exploded in form style, objects will be exploded in deepObject
|
|
@@ -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
|
/**
|
|
@@ -71,3 +71,8 @@ export interface Config {
|
|
|
71
71
|
*/
|
|
72
72
|
responseValidator?: (data: unknown) => Promise<unknown>;
|
|
73
73
|
}
|
|
74
|
+
type IsExactlyNeverOrNeverUndefined<T> = [T] extends [never] ? true : [T] extends [never | undefined] ? [undefined] extends [T] ? false : true : false;
|
|
75
|
+
export type OmitNever<T extends Record<string, unknown>> = {
|
|
76
|
+
[K in keyof T as IsExactlyNeverOrNeverUndefined<T[K]> extends true ? never : K]: T[K];
|
|
77
|
+
};
|
|
78
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { BodySerializer, QuerySerializer } from './bodySerializer.gen';
|
|
2
|
+
export interface PathSerializer {
|
|
3
|
+
path: Record<string, unknown>;
|
|
4
|
+
url: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const PATH_PARAM_RE: RegExp;
|
|
7
|
+
export declare const defaultPathSerializer: ({ path, url: _url }: PathSerializer) => string;
|
|
8
|
+
export declare const getUrl: ({ baseUrl, path, query, querySerializer, url: _url, }: {
|
|
9
|
+
baseUrl?: string;
|
|
10
|
+
path?: Record<string, unknown>;
|
|
11
|
+
query?: Record<string, unknown>;
|
|
12
|
+
querySerializer: QuerySerializer;
|
|
13
|
+
url: string;
|
|
14
|
+
}) => string;
|
|
15
|
+
export declare function getValidRequestBody(options: {
|
|
16
|
+
body?: unknown;
|
|
17
|
+
bodySerializer?: BodySerializer | null;
|
|
18
|
+
serializedBody?: unknown;
|
|
19
|
+
}): unknown;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// This file is auto-generated by @hey-api/openapi-ts
|
|
2
|
+
import { serializeArrayParam, serializeObjectParam, serializePrimitiveParam, } from './pathSerializer.gen';
|
|
3
|
+
export const PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
4
|
+
export const defaultPathSerializer = ({ path, url: _url }) => {
|
|
5
|
+
let url = _url;
|
|
6
|
+
const matches = _url.match(PATH_PARAM_RE);
|
|
7
|
+
if (matches) {
|
|
8
|
+
for (const match of matches) {
|
|
9
|
+
let explode = false;
|
|
10
|
+
let name = match.substring(1, match.length - 1);
|
|
11
|
+
let style = 'simple';
|
|
12
|
+
if (name.endsWith('*')) {
|
|
13
|
+
explode = true;
|
|
14
|
+
name = name.substring(0, name.length - 1);
|
|
15
|
+
}
|
|
16
|
+
if (name.startsWith('.')) {
|
|
17
|
+
name = name.substring(1);
|
|
18
|
+
style = 'label';
|
|
19
|
+
}
|
|
20
|
+
else if (name.startsWith(';')) {
|
|
21
|
+
name = name.substring(1);
|
|
22
|
+
style = 'matrix';
|
|
23
|
+
}
|
|
24
|
+
const value = path[name];
|
|
25
|
+
if (value === undefined || value === null) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (Array.isArray(value)) {
|
|
29
|
+
url = url.replace(match, serializeArrayParam({ explode, name, style, value }));
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (typeof value === 'object') {
|
|
33
|
+
url = url.replace(match, serializeObjectParam({
|
|
34
|
+
explode,
|
|
35
|
+
name,
|
|
36
|
+
style,
|
|
37
|
+
value: value,
|
|
38
|
+
valueOnly: true,
|
|
39
|
+
}));
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
if (style === 'matrix') {
|
|
43
|
+
url = url.replace(match, `;${serializePrimitiveParam({
|
|
44
|
+
name,
|
|
45
|
+
value: value,
|
|
46
|
+
})}`);
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
const replaceValue = encodeURIComponent(style === 'label' ? `.${value}` : value);
|
|
50
|
+
url = url.replace(match, replaceValue);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return url;
|
|
54
|
+
};
|
|
55
|
+
export const getUrl = ({ baseUrl, path, query, querySerializer, url: _url, }) => {
|
|
56
|
+
const pathUrl = _url.startsWith('/') ? _url : `/${_url}`;
|
|
57
|
+
let url = (baseUrl ?? '') + pathUrl;
|
|
58
|
+
if (path) {
|
|
59
|
+
url = defaultPathSerializer({ path, url });
|
|
60
|
+
}
|
|
61
|
+
let search = query ? querySerializer(query) : '';
|
|
62
|
+
if (search.startsWith('?')) {
|
|
63
|
+
search = search.substring(1);
|
|
64
|
+
}
|
|
65
|
+
if (search) {
|
|
66
|
+
url += `?${search}`;
|
|
67
|
+
}
|
|
68
|
+
return url;
|
|
69
|
+
};
|
|
70
|
+
export function getValidRequestBody(options) {
|
|
71
|
+
const hasBody = options.body !== undefined;
|
|
72
|
+
const isSerializedBody = hasBody && options.bodySerializer;
|
|
73
|
+
if (isSerializedBody) {
|
|
74
|
+
if ('serializedBody' in options) {
|
|
75
|
+
const hasSerializedBody = options.serializedBody !== undefined && options.serializedBody !== '';
|
|
76
|
+
return hasSerializedBody ? options.serializedBody : null;
|
|
77
|
+
}
|
|
78
|
+
// not all clients implement a serializedBody property (i.e., client-axios)
|
|
79
|
+
return options.body !== '' ? options.body : null;
|
|
80
|
+
}
|
|
81
|
+
// plain/text body
|
|
82
|
+
if (hasBody) {
|
|
83
|
+
return options.body;
|
|
84
|
+
}
|
|
85
|
+
// no body was provided
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|