internetdata-web 0.0.0-stage → 1.0.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.
Files changed (55) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +282 -2
  3. package/dist/bogon.d.ts +31 -0
  4. package/dist/bogon.js +214 -0
  5. package/dist/bogons.gen.d.ts +2 -0
  6. package/dist/bogons.gen.js +87 -0
  7. package/dist/client.d.ts +183 -0
  8. package/dist/client.js +446 -0
  9. package/dist/errors.d.ts +66 -0
  10. package/dist/errors.js +185 -0
  11. package/dist/generated/client/client.gen.d.ts +2 -0
  12. package/dist/generated/client/client.gen.js +216 -0
  13. package/dist/generated/client/index.d.ts +10 -0
  14. package/dist/generated/client/index.js +6 -0
  15. package/dist/generated/client/types.gen.d.ts +120 -0
  16. package/dist/generated/client/types.gen.js +2 -0
  17. package/dist/generated/client/utils.gen.d.ts +37 -0
  18. package/dist/generated/client/utils.gen.js +228 -0
  19. package/dist/generated/client.gen.d.ts +12 -0
  20. package/dist/generated/client.gen.js +3 -0
  21. package/dist/generated/core/auth.gen.d.ts +25 -0
  22. package/dist/generated/core/auth.gen.js +14 -0
  23. package/dist/generated/core/bodySerializer.gen.d.ts +25 -0
  24. package/dist/generated/core/bodySerializer.gen.js +57 -0
  25. package/dist/generated/core/params.gen.d.ts +43 -0
  26. package/dist/generated/core/params.gen.js +109 -0
  27. package/dist/generated/core/pathSerializer.gen.d.ts +33 -0
  28. package/dist/generated/core/pathSerializer.gen.js +106 -0
  29. package/dist/generated/core/queryKeySerializer.gen.d.ts +18 -0
  30. package/dist/generated/core/queryKeySerializer.gen.js +92 -0
  31. package/dist/generated/core/serverSentEvents.gen.d.ts +71 -0
  32. package/dist/generated/core/serverSentEvents.gen.js +132 -0
  33. package/dist/generated/core/types.gen.d.ts +83 -0
  34. package/dist/generated/core/types.gen.js +2 -0
  35. package/dist/generated/core/utils.gen.d.ts +19 -0
  36. package/dist/generated/core/utils.gen.js +87 -0
  37. package/dist/generated/index.d.ts +2 -0
  38. package/dist/generated/index.js +2 -0
  39. package/dist/generated/sdk.gen.d.ts +117 -0
  40. package/dist/generated/sdk.gen.js +251 -0
  41. package/dist/generated/types.gen.d.ts +1523 -0
  42. package/dist/generated/types.gen.js +2 -0
  43. package/dist/index.d.ts +9 -0
  44. package/dist/index.js +4 -0
  45. package/dist/oauth.d.ts +119 -0
  46. package/dist/oauth.js +247 -0
  47. package/dist/shapes.d.ts +68 -0
  48. package/dist/shapes.js +283 -0
  49. package/dist/store.d.ts +39 -0
  50. package/dist/store.js +64 -0
  51. package/dist/transport.d.ts +51 -0
  52. package/dist/transport.js +147 -0
  53. package/dist/types.d.ts +115 -0
  54. package/dist/types.js +46 -0
  55. package/package.json +65 -3
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Why a request failed.
3
+ *
4
+ * `rate_limited` and `quota_exceeded` both arrive as HTTP 429 and are NOT the
5
+ * same thing. A rate limit is the API protecting itself and carries
6
+ * `Retry-After`; retrying works. A spent quota carries no such header and
7
+ * retrying will not help until the window rolls over or the limit is raised.
8
+ * The header is the only thing that distinguishes them.
9
+ */
10
+ export type ErrorKind = 'bad_request' | 'unauthorized' | 'forbidden' | 'rate_limited' | 'quota_exceeded' | 'server_error' | 'network';
11
+ export declare class InternetDataError extends Error {
12
+ readonly kind: ErrorKind;
13
+ readonly status?: number;
14
+ readonly retryAfterSeconds?: number;
15
+ constructor(kind: ErrorKind, message: string, status?: number, retryAfterSeconds?: number);
16
+ /** Whether retrying this exact request could succeed. */
17
+ get retryable(): boolean;
18
+ }
19
+ /**
20
+ * The authorization server refusing an OAuth request: a 4xx whose body names an
21
+ * OAuth error code. Never retryable as it stands.
22
+ *
23
+ * `kind` follows the status like any other failure's. A 401 here means the
24
+ * client ID is not registered, never the API key, which OAuth requests do not
25
+ * carry. The two codes a sign-in ends on have their own subclasses.
26
+ */
27
+ export declare class OauthError extends InternetDataError {
28
+ /** The server's code, such as `invalid_grant` or `invalid_client`, kept as sent. */
29
+ readonly errorCode: string;
30
+ /** The server's explanation, when it sent one. */
31
+ readonly errorDescription?: string;
32
+ constructor(errorCode: string, errorDescription?: string, status?: number);
33
+ get retryable(): boolean;
34
+ }
35
+ /** The person refused the sign-in, so a new attempt starts over. */
36
+ export declare class OauthAccessDeniedError extends OauthError {
37
+ constructor(errorDescription?: string, status?: number);
38
+ }
39
+ /** What was presented is no longer valid: it expired, or was already used or refused. */
40
+ export declare class OauthExpiredTokenError extends OauthError {
41
+ constructor(errorDescription?: string, status?: number);
42
+ }
43
+ export declare function oauthErrorFrom(errorCode: string, errorDescription: string | undefined, status: number): OauthError;
44
+ export declare function errorFromResponse(status: number, headers: {
45
+ get(name: string): string | null;
46
+ }, message?: string): InternetDataError;
47
+ /**
48
+ * A per-entry failure inside a successful batch: the status the single lookup
49
+ * would have answered, and its message, with no headers at all - so a 429 here
50
+ * is a spent allowance, which is the only kind the API puts in an entry.
51
+ */
52
+ export declare function errorFromEntry(entry: {
53
+ status: number;
54
+ error: string;
55
+ }): InternetDataError;
56
+ /**
57
+ * The message an error envelope carries. The lookup and entitlement endpoints
58
+ * answer an error as `error`, while the authorization server's own failure is
59
+ * `{"rc": ...}`. Both are read here so a caller never has to know which one they
60
+ * hit.
61
+ *
62
+ * Deliberately not an enum, in the spec or here: a code added later must stay
63
+ * readable to a client generated today, and the string IS the message a caller
64
+ * wants to see.
65
+ */
66
+ export declare function messageFromBody(body: unknown): string | undefined;
package/dist/errors.js ADDED
@@ -0,0 +1,185 @@
1
+ export class InternetDataError extends Error {
2
+ kind;
3
+ status;
4
+ retryAfterSeconds;
5
+ constructor(kind, message, status, retryAfterSeconds) {
6
+ super(message);
7
+ this.name = 'InternetDataError';
8
+ this.kind = kind;
9
+ this.status = status;
10
+ this.retryAfterSeconds = retryAfterSeconds;
11
+ }
12
+ /** Whether retrying this exact request could succeed. */
13
+ get retryable() {
14
+ return this.kind === 'rate_limited' || this.kind === 'server_error' || this.kind === 'network';
15
+ }
16
+ }
17
+ /**
18
+ * The authorization server refusing an OAuth request: a 4xx whose body names an
19
+ * OAuth error code. Never retryable as it stands.
20
+ *
21
+ * `kind` follows the status like any other failure's. A 401 here means the
22
+ * client ID is not registered, never the API key, which OAuth requests do not
23
+ * carry. The two codes a sign-in ends on have their own subclasses.
24
+ */
25
+ export class OauthError extends InternetDataError {
26
+ /** The server's code, such as `invalid_grant` or `invalid_client`, kept as sent. */
27
+ errorCode;
28
+ /** The server's explanation, when it sent one. */
29
+ errorDescription;
30
+ constructor(errorCode, errorDescription, status) {
31
+ super(status === undefined ? 'bad_request' : errorFromResponse(status, NO_HEADERS).kind, errorDescription === undefined ? errorCode : `${errorCode}: ${errorDescription}`, status);
32
+ this.name = 'OauthError';
33
+ this.errorCode = errorCode;
34
+ this.errorDescription = errorDescription;
35
+ }
36
+ get retryable() {
37
+ return false;
38
+ }
39
+ }
40
+ /** The person refused the sign-in, so a new attempt starts over. */
41
+ export class OauthAccessDeniedError extends OauthError {
42
+ constructor(errorDescription, status) {
43
+ super('access_denied', errorDescription, status);
44
+ this.name = 'OauthAccessDeniedError';
45
+ }
46
+ }
47
+ /** What was presented is no longer valid: it expired, or was already used or refused. */
48
+ export class OauthExpiredTokenError extends OauthError {
49
+ constructor(errorDescription, status) {
50
+ super('expired_token', errorDescription, status);
51
+ this.name = 'OauthExpiredTokenError';
52
+ }
53
+ }
54
+ export function oauthErrorFrom(errorCode, errorDescription, status) {
55
+ if (errorCode === 'access_denied') {
56
+ return new OauthAccessDeniedError(errorDescription, status);
57
+ }
58
+ if (errorCode === 'expired_token') {
59
+ return new OauthExpiredTokenError(errorDescription, status);
60
+ }
61
+ return new OauthError(errorCode, errorDescription, status);
62
+ }
63
+ const NO_HEADERS = { get: () => null };
64
+ export function errorFromResponse(status, headers, message) {
65
+ const text = message ?? `request failed with status ${status}`;
66
+ const retryAfter = parseRetryAfter(headers.get('retry-after'));
67
+ if (status === 429) {
68
+ // Present means transient, absent means an allowance is spent. Nothing
69
+ // else in the response separates the two.
70
+ return retryAfter === undefined
71
+ ? new InternetDataError('quota_exceeded', text, status)
72
+ : new InternetDataError('rate_limited', text, status, retryAfter);
73
+ }
74
+ if (status === 400) {
75
+ return new InternetDataError('bad_request', text, status);
76
+ }
77
+ if (status === 401) {
78
+ return new InternetDataError('unauthorized', text, status);
79
+ }
80
+ if (status === 403) {
81
+ return new InternetDataError('forbidden', text, status);
82
+ }
83
+ // Any other 4xx is a CLIENT error. Falling through to the server_error
84
+ // default would make it retryable. Only 5xx and transport failures are
85
+ // worth a retry.
86
+ if (status < 500) {
87
+ return new InternetDataError('bad_request', text, status);
88
+ }
89
+ return new InternetDataError('server_error', text, status);
90
+ }
91
+ /**
92
+ * A per-entry failure inside a successful batch: the status the single lookup
93
+ * would have answered, and its message, with no headers at all - so a 429 here
94
+ * is a spent allowance, which is the only kind the API puts in an entry.
95
+ */
96
+ export function errorFromEntry(entry) {
97
+ return errorFromResponse(entry.status, NO_HEADERS, entry.error);
98
+ }
99
+ /**
100
+ * The message an error envelope carries. The lookup and entitlement endpoints
101
+ * answer an error as `error`, while the authorization server's own failure is
102
+ * `{"rc": ...}`. Both are read here so a caller never has to know which one they
103
+ * hit.
104
+ *
105
+ * Deliberately not an enum, in the spec or here: a code added later must stay
106
+ * readable to a client generated today, and the string IS the message a caller
107
+ * wants to see.
108
+ */
109
+ export function messageFromBody(body) {
110
+ if (typeof body !== 'object' || body === null) {
111
+ return undefined;
112
+ }
113
+ const b = body;
114
+ if (typeof b.error === 'string') {
115
+ return b.error;
116
+ }
117
+ if (typeof b.rc === 'string') {
118
+ return b.rc;
119
+ }
120
+ return undefined;
121
+ }
122
+ function parseRetryAfter(value) {
123
+ if (value === null) {
124
+ return undefined;
125
+ }
126
+ const text = value.trim();
127
+ // Digits alone, as RFC 9110's delay-seconds is: `Number` would also read `+1`,
128
+ // `0x10`, `1e3` and `1.5` as counts.
129
+ if (/^\d+$/.test(text)) {
130
+ const seconds = Number(text);
131
+ return Number.isFinite(seconds) ? seconds : undefined;
132
+ }
133
+ const when = httpDate(text);
134
+ if (when === undefined) {
135
+ return undefined;
136
+ }
137
+ return Math.max(0, Math.ceil((when - Date.now()) / 1000));
138
+ }
139
+ const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
140
+ const MONTH = MONTHS.join('|');
141
+ const DAY = 'Mon|Tue|Wed|Thu|Fri|Sat|Sun';
142
+ const WEEKDAY = 'Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday';
143
+ const TIME = '(\\d{2}):(\\d{2}):(\\d{2})';
144
+ const IMF_FIXDATE = new RegExp(`^(?:${DAY}), (\\d{2}) (${MONTH}) (\\d{4}) ${TIME} GMT$`);
145
+ const RFC850_DATE = new RegExp(`^(?:${WEEKDAY}), (\\d{2})-(${MONTH})-(\\d{2}) ${TIME} GMT$`);
146
+ const ASCTIME_DATE = new RegExp(`^(?:${DAY}) (${MONTH}) ( \\d|\\d{2}) ${TIME} (\\d{4})$`);
147
+ /**
148
+ * An HTTP date in milliseconds, in exactly the three forms RFC 9110 has a
149
+ * recipient read, all GMT. `Date.parse` takes far more: ISO 8601 and words such
150
+ * as `Jan 1 2099`, a zone such as `PST` or `+0500`, a day the month lacks
151
+ * (`31 Nov`, rolled into December), and an asctime date as LOCAL time, so a
152
+ * throttle five seconds out would wait none in a browser east of GMT.
153
+ */
154
+ function httpDate(text) {
155
+ let parts;
156
+ let m = IMF_FIXDATE.exec(text);
157
+ if (m !== null) {
158
+ parts = [m[1], m[2], Number(m[3]), m[4], m[5], m[6]];
159
+ }
160
+ else if ((m = RFC850_DATE.exec(text)) !== null) {
161
+ // A two-digit year more than 50 years ahead is the last such year past.
162
+ let year = 2000 + Number(m[3]);
163
+ if (year > new Date().getUTCFullYear() + 50) {
164
+ year -= 100;
165
+ }
166
+ parts = [m[1], m[2], year, m[4], m[5], m[6]];
167
+ }
168
+ else if ((m = ASCTIME_DATE.exec(text)) !== null) {
169
+ parts = [m[2].trim(), m[1], Number(m[6]), m[3], m[4], m[5]];
170
+ }
171
+ if (parts === undefined) {
172
+ return undefined;
173
+ }
174
+ const [day, month, year, hour, minute, second] = parts;
175
+ const d = Number(day);
176
+ const mo = MONTHS.indexOf(month);
177
+ const h = Number(hour);
178
+ const mi = Number(minute);
179
+ const s = Number(second);
180
+ const date = new Date(Date.UTC(year, mo, d));
181
+ if (date.getUTCDate() !== d || date.getUTCMonth() !== mo || h > 23 || mi > 59 || s > 60) {
182
+ return undefined;
183
+ }
184
+ return Date.UTC(year, mo, d, h, mi, s);
185
+ }
@@ -0,0 +1,2 @@
1
+ import type { Client, Config } from './types.gen.js';
2
+ export declare const createClient: (config?: Config) => Client;
@@ -0,0 +1,216 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+ import { createSseClient } from '../core/serverSentEvents.gen.js';
3
+ import { getValidRequestBody } from '../core/utils.gen.js';
4
+ import { buildUrl, createConfig, createInterceptors, getParseAs, mergeConfigs, mergeHeaders, setAuthParams, } from './utils.gen.js';
5
+ export const createClient = (config = {}) => {
6
+ let _config = mergeConfigs(createConfig(), config);
7
+ const getConfig = () => ({ ..._config });
8
+ const setConfig = (config) => {
9
+ _config = mergeConfigs(_config, config);
10
+ return getConfig();
11
+ };
12
+ const interceptors = createInterceptors();
13
+ const beforeRequest = async (options) => {
14
+ const opts = {
15
+ ..._config,
16
+ ...options,
17
+ fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
18
+ headers: mergeHeaders(_config.headers, options.headers),
19
+ serializedBody: undefined,
20
+ };
21
+ if (opts.security) {
22
+ await setAuthParams(opts);
23
+ }
24
+ if (opts.requestValidator) {
25
+ await opts.requestValidator(opts);
26
+ }
27
+ if (opts.body !== undefined && opts.bodySerializer) {
28
+ opts.serializedBody = opts.bodySerializer(opts.body);
29
+ }
30
+ // remove Content-Type header if body is empty to avoid sending invalid requests
31
+ if (opts.body === undefined || opts.serializedBody === '') {
32
+ opts.headers.delete('Content-Type');
33
+ }
34
+ const resolvedOpts = opts;
35
+ const url = buildUrl(resolvedOpts);
36
+ return { opts: resolvedOpts, url };
37
+ };
38
+ const request = async (options) => {
39
+ const throwOnError = options.throwOnError ?? _config.throwOnError;
40
+ const responseStyle = options.responseStyle ?? _config.responseStyle;
41
+ let request;
42
+ let response;
43
+ try {
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) {
52
+ if (fn) {
53
+ request = await fn(request, opts);
54
+ }
55
+ }
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
+ }
64
+ }
65
+ const result = {
66
+ request,
67
+ response,
68
+ };
69
+ if (response.ok) {
70
+ const parseAs = (opts.parseAs === 'auto'
71
+ ? getParseAs(response.headers.get('Content-Type'))
72
+ : opts.parseAs) ?? 'json';
73
+ if (response.status === 204 || response.headers.get('Content-Length') === '0') {
74
+ let emptyData;
75
+ switch (parseAs) {
76
+ case 'arrayBuffer':
77
+ case 'blob':
78
+ case 'text':
79
+ emptyData = await response[parseAs]();
80
+ break;
81
+ case 'formData':
82
+ emptyData = new FormData();
83
+ break;
84
+ case 'stream':
85
+ emptyData = response.body;
86
+ break;
87
+ case 'json':
88
+ default:
89
+ emptyData = {};
90
+ break;
91
+ }
92
+ return opts.responseStyle === 'data'
93
+ ? emptyData
94
+ : {
95
+ data: emptyData,
96
+ ...result,
97
+ };
98
+ }
99
+ let data;
100
+ switch (parseAs) {
101
+ case 'arrayBuffer':
102
+ case 'blob':
103
+ case 'formData':
104
+ case 'text':
105
+ data = await response[parseAs]();
106
+ break;
107
+ case 'json': {
108
+ // Some servers return 200 with no Content-Length and empty body.
109
+ // response.json() would throw; read as text and parse if non-empty.
110
+ const text = await response.text();
111
+ data = text ? JSON.parse(text) : {};
112
+ break;
113
+ }
114
+ case 'stream':
115
+ return opts.responseStyle === 'data'
116
+ ? response.body
117
+ : {
118
+ data: response.body,
119
+ ...result,
120
+ };
121
+ }
122
+ if (parseAs === 'json') {
123
+ if (opts.responseValidator) {
124
+ await opts.responseValidator(data);
125
+ }
126
+ if (opts.responseTransformer) {
127
+ data = await opts.responseTransformer(data);
128
+ }
129
+ }
130
+ return opts.responseStyle === 'data'
131
+ ? data
132
+ : {
133
+ data,
134
+ ...result,
135
+ };
136
+ }
137
+ const textError = await response.text();
138
+ let jsonError;
139
+ try {
140
+ jsonError = JSON.parse(textError);
141
+ }
142
+ catch {
143
+ // noop
144
+ }
145
+ throw jsonError ?? textError;
146
+ }
147
+ catch (error) {
148
+ let finalError = error;
149
+ for (const fn of interceptors.error.fns) {
150
+ if (fn) {
151
+ finalError = await fn(finalError, response, request, options);
152
+ }
153
+ }
154
+ finalError = finalError || {};
155
+ if (throwOnError) {
156
+ throw finalError;
157
+ }
158
+ // TODO: we probably want to return error and improve types
159
+ return responseStyle === 'data'
160
+ ? undefined
161
+ : {
162
+ error: finalError,
163
+ request,
164
+ response,
165
+ };
166
+ }
167
+ };
168
+ const makeMethodFn = (method) => (options) => request({ ...options, method });
169
+ const makeSseFn = (method) => async (options) => {
170
+ const { opts, url } = await beforeRequest(options);
171
+ return createSseClient({
172
+ ...opts,
173
+ body: opts.body,
174
+ method,
175
+ onRequest: async (url, init) => {
176
+ let request = new Request(url, init);
177
+ for (const fn of interceptors.request.fns) {
178
+ if (fn) {
179
+ request = await fn(request, opts);
180
+ }
181
+ }
182
+ return request;
183
+ },
184
+ serializedBody: getValidRequestBody(opts),
185
+ url,
186
+ });
187
+ };
188
+ const _buildUrl = (options) => buildUrl({ ..._config, ...options });
189
+ return {
190
+ buildUrl: _buildUrl,
191
+ connect: makeMethodFn('CONNECT'),
192
+ delete: makeMethodFn('DELETE'),
193
+ get: makeMethodFn('GET'),
194
+ getConfig,
195
+ head: makeMethodFn('HEAD'),
196
+ interceptors,
197
+ options: makeMethodFn('OPTIONS'),
198
+ patch: makeMethodFn('PATCH'),
199
+ post: makeMethodFn('POST'),
200
+ put: makeMethodFn('PUT'),
201
+ request,
202
+ setConfig,
203
+ sse: {
204
+ connect: makeSseFn('CONNECT'),
205
+ delete: makeSseFn('DELETE'),
206
+ get: makeSseFn('GET'),
207
+ head: makeSseFn('HEAD'),
208
+ options: makeSseFn('OPTIONS'),
209
+ patch: makeSseFn('PATCH'),
210
+ post: makeSseFn('POST'),
211
+ put: makeSseFn('PUT'),
212
+ trace: makeSseFn('TRACE'),
213
+ },
214
+ trace: makeMethodFn('TRACE'),
215
+ };
216
+ };
@@ -0,0 +1,10 @@
1
+ export type { Auth } from '../core/auth.gen.js';
2
+ export type { QuerySerializerOptions } from '../core/bodySerializer.gen.js';
3
+ export { formDataBodySerializer, jsonBodySerializer, urlSearchParamsBodySerializer, } from '../core/bodySerializer.gen.js';
4
+ export { buildClientParams } from '../core/params.gen.js';
5
+ export { serializeQueryKeyValue } from '../core/queryKeySerializer.gen.js';
6
+ export type { ServerSentEventsResult } from '../core/serverSentEvents.gen.js';
7
+ export type { ClientMeta } from '../core/types.gen.js';
8
+ export { createClient } from './client.gen.js';
9
+ export type { Client, ClientOptions, Config, CreateClientConfig, Options, RequestOptions, RequestResult, ResolvedRequestOptions, ResponseStyle, TDataShape, } from './types.gen.js';
10
+ export { createConfig, mergeHeaders } from './utils.gen.js';
@@ -0,0 +1,6 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+ export { formDataBodySerializer, jsonBodySerializer, urlSearchParamsBodySerializer, } from '../core/bodySerializer.gen.js';
3
+ export { buildClientParams } from '../core/params.gen.js';
4
+ export { serializeQueryKeyValue } from '../core/queryKeySerializer.gen.js';
5
+ export { createClient } from './client.gen.js';
6
+ export { createConfig, mergeHeaders } from './utils.gen.js';
@@ -0,0 +1,120 @@
1
+ import type { Auth } from '../core/auth.gen.js';
2
+ import type { ServerSentEventsOptions, ServerSentEventsResult } from '../core/serverSentEvents.gen.js';
3
+ import type { Client as CoreClient, Config as CoreConfig } from '../core/types.gen.js';
4
+ import type { Middleware } from './utils.gen.js';
5
+ export type ResponseStyle = 'data' | 'fields';
6
+ export interface Config<T extends ClientOptions = ClientOptions> extends Omit<RequestInit, 'body' | 'headers' | 'method'>, CoreConfig {
7
+ /**
8
+ * Base URL for all requests made by this client.
9
+ */
10
+ baseUrl?: T['baseUrl'];
11
+ /**
12
+ * Fetch API implementation. You can use this option to provide a custom
13
+ * fetch instance.
14
+ *
15
+ * @default globalThis.fetch
16
+ */
17
+ fetch?: typeof fetch;
18
+ /**
19
+ * Please don't use the Fetch client for Next.js applications. The `next`
20
+ * options won't have any effect.
21
+ *
22
+ * Install {@link https://www.npmjs.com/package/@hey-api/client-next `@hey-api/client-next`} instead.
23
+ */
24
+ next?: never;
25
+ /**
26
+ * Return the response data parsed in a specified format. By default, `auto`
27
+ * will infer the appropriate method from the `Content-Type` response header.
28
+ * You can override this behavior with any of the {@link Body} methods.
29
+ * Select `stream` if you don't want to parse response data at all.
30
+ *
31
+ * @default 'auto'
32
+ */
33
+ parseAs?: 'arrayBuffer' | 'auto' | 'blob' | 'formData' | 'json' | 'stream' | 'text';
34
+ /**
35
+ * Should we return only data or multiple fields (data, error, response, etc.)?
36
+ *
37
+ * @default 'fields'
38
+ */
39
+ responseStyle?: ResponseStyle;
40
+ /**
41
+ * Throw an error instead of returning it in the response?
42
+ *
43
+ * @default false
44
+ */
45
+ throwOnError?: T['throwOnError'];
46
+ }
47
+ export interface RequestOptions<TData = unknown, TResponseStyle extends ResponseStyle = 'fields', ThrowOnError extends boolean = boolean, Url extends string = string> extends Config<{
48
+ responseStyle: TResponseStyle;
49
+ throwOnError: ThrowOnError;
50
+ }>, Pick<ServerSentEventsOptions<TData>, 'onRequest' | 'onSseError' | 'onSseEvent' | 'sseDefaultRetryDelay' | 'sseMaxRetryAttempts' | 'sseMaxRetryDelay'> {
51
+ /**
52
+ * Any body that you want to add to your request.
53
+ *
54
+ * {@link https://developer.mozilla.org/docs/Web/API/fetch#body}
55
+ */
56
+ body?: unknown;
57
+ path?: Record<string, unknown>;
58
+ query?: Record<string, unknown>;
59
+ /**
60
+ * Security mechanism(s) to use for the request.
61
+ */
62
+ security?: ReadonlyArray<Auth>;
63
+ url: Url;
64
+ }
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;
67
+ serializedBody?: string;
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 : {
70
+ data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
71
+ request: Request;
72
+ response: Response;
73
+ }> : Promise<TResponseStyle extends 'data' ? (TData extends Record<string, unknown> ? TData[keyof TData] : TData) | undefined : ({
74
+ data: TData extends Record<string, unknown> ? TData[keyof TData] : TData;
75
+ error: undefined;
76
+ } | {
77
+ data: undefined;
78
+ error: TError extends Record<string, unknown> ? TError[keyof TError] : TError;
79
+ }) & {
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;
84
+ }>;
85
+ export interface ClientOptions {
86
+ baseUrl?: string;
87
+ responseStyle?: ResponseStyle;
88
+ throwOnError?: boolean;
89
+ }
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>;
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>>;
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>;
93
+ type BuildUrlFn = <TData extends {
94
+ body?: unknown;
95
+ path?: Record<string, unknown>;
96
+ query?: Record<string, unknown>;
97
+ url: string;
98
+ }>(options: TData & Options<TData>) => string;
99
+ export type Client = CoreClient<RequestFn, Config, MethodFn, BuildUrlFn, SseFn> & {
100
+ interceptors: Middleware<Request, Response, unknown, ResolvedRequestOptions>;
101
+ };
102
+ /**
103
+ * The `createClientConfig()` function will be called on client initialization
104
+ * and the returned object will become the client's initial configuration.
105
+ *
106
+ * You may want to initialize your client this way instead of calling
107
+ * `setConfig()`. This is useful for example if you're using Next.js
108
+ * to ensure your client always has the correct values.
109
+ */
110
+ export type CreateClientConfig<T extends ClientOptions = ClientOptions> = (override?: Config<ClientOptions & T>) => Config<Required<ClientOptions> & T>;
111
+ export interface TDataShape {
112
+ body?: unknown;
113
+ headers?: unknown;
114
+ path?: unknown;
115
+ query?: unknown;
116
+ url: string;
117
+ }
118
+ type OmitKeys<T, K> = Pick<T, Exclude<keyof T, K>>;
119
+ export type Options<TData extends TDataShape = TDataShape, ThrowOnError extends boolean = boolean, TResponse = unknown, TResponseStyle extends ResponseStyle = 'fields'> = OmitKeys<RequestOptions<TResponse, TResponseStyle, ThrowOnError>, 'body' | 'path' | 'query' | 'url'> & ([TData] extends [never] ? unknown : Omit<TData, 'url'>);
120
+ export {};
@@ -0,0 +1,2 @@
1
+ // This file is auto-generated by @hey-api/openapi-ts
2
+ export {};
@@ -0,0 +1,37 @@
1
+ import type { QuerySerializerOptions } from '../core/bodySerializer.gen.js';
2
+ import type { Client, ClientOptions, Config, RequestOptions } from './types.gen.js';
3
+ export declare const createQuerySerializer: <T = unknown>({ parameters, ...args }?: QuerySerializerOptions) => ((queryParams: T) => string);
4
+ /**
5
+ * Infers parseAs value from provided Content-Type header.
6
+ */
7
+ export declare const getParseAs: (contentType: string | null) => Exclude<Config["parseAs"], "auto">;
8
+ export declare function setAuthParams(options: Pick<RequestOptions, 'auth' | 'query' | 'security'> & {
9
+ headers: Headers;
10
+ }): Promise<void>;
11
+ export declare const buildUrl: Client['buildUrl'];
12
+ export declare const mergeConfigs: (a: Config, b: Config) => Config;
13
+ export declare const mergeHeaders: (...headers: Array<Required<Config>["headers"] | undefined>) => Headers;
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>;
19
+ type ReqInterceptor<Req, Options> = (request: Req, options: Options) => Req | Promise<Req>;
20
+ type ResInterceptor<Res, Req, Options> = (response: Res, request: Req, options: Options) => Res | Promise<Res>;
21
+ declare class Interceptors<Interceptor> {
22
+ fns: Array<Interceptor | null>;
23
+ clear(): void;
24
+ eject(id: number | Interceptor): void;
25
+ exists(id: number | Interceptor): boolean;
26
+ getInterceptorIndex(id: number | Interceptor): number;
27
+ update(id: number | Interceptor, fn: Interceptor): number | Interceptor | false;
28
+ use(fn: Interceptor): number;
29
+ }
30
+ export interface Middleware<Req, Res, Err, Options> {
31
+ error: Interceptors<ErrInterceptor<Err, Res, Req, Options>>;
32
+ request: Interceptors<ReqInterceptor<Req, Options>>;
33
+ response: Interceptors<ResInterceptor<Res, Req, Options>>;
34
+ }
35
+ export declare const createInterceptors: <Req, Res, Err, Options>() => Middleware<Req, Res, Err, Options>;
36
+ export declare const createConfig: <T extends ClientOptions = ClientOptions>(override?: Config<Omit<ClientOptions, keyof T> & T>) => Config<Omit<ClientOptions, keyof T> & T>;
37
+ export {};