@djangocfg/monitor 2.1.322 → 2.1.331

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 (79) hide show
  1. package/dist/client.cjs +945 -1136
  2. package/dist/client.cjs.map +1 -1
  3. package/dist/client.d.cts +32 -46
  4. package/dist/client.d.ts +32 -46
  5. package/dist/client.mjs +945 -1147
  6. package/dist/client.mjs.map +1 -1
  7. package/dist/index.cjs +908 -1108
  8. package/dist/index.cjs.map +1 -1
  9. package/dist/index.d.cts +32 -46
  10. package/dist/index.d.ts +32 -46
  11. package/dist/index.mjs +901 -1112
  12. package/dist/index.mjs.map +1 -1
  13. package/dist/server.cjs +904 -1102
  14. package/dist/server.cjs.map +1 -1
  15. package/dist/server.d.cts +32 -46
  16. package/dist/server.d.ts +32 -46
  17. package/dist/server.mjs +896 -1105
  18. package/dist/server.mjs.map +1 -1
  19. package/package.json +7 -2
  20. package/src/_api/BaseClient.ts +1 -1
  21. package/src/_api/generated/_cfg_monitor/api.ts +120 -0
  22. package/src/_api/generated/_cfg_monitor/events.ts +198 -0
  23. package/src/_api/generated/_cfg_monitor/hooks/index.ts +4 -0
  24. package/src/_api/generated/_cfg_monitor/hooks/useCfgMonitorIngestCreate.ts +24 -0
  25. package/src/_api/generated/_cfg_monitor/index.ts +29 -0
  26. package/src/_api/generated/_cfg_monitor/schemas/EventTypeEnum.ts +9 -0
  27. package/src/_api/generated/_cfg_monitor/schemas/FrontendEventIngestRequest.ts +27 -0
  28. package/src/_api/generated/_cfg_monitor/schemas/IngestBatchRequest.ts +12 -0
  29. package/src/_api/generated/_cfg_monitor/schemas/LevelEnum.ts +9 -0
  30. package/src/_api/generated/_cfg_monitor/schemas/index.ts +7 -0
  31. package/src/_api/generated/_cfg_monitor/sdk.gen.ts +5 -0
  32. package/src/_api/generated/_cfg_monitor/types.gen.ts +5 -0
  33. package/src/_api/generated/client/client.gen.ts +280 -0
  34. package/src/_api/generated/client/index.ts +25 -0
  35. package/src/_api/generated/client/types.gen.ts +217 -0
  36. package/src/_api/generated/client/utils.gen.ts +318 -0
  37. package/src/_api/generated/client.gen.ts +16 -0
  38. package/src/_api/generated/core/auth.gen.ts +41 -0
  39. package/src/_api/generated/core/bodySerializer.gen.ts +82 -0
  40. package/src/_api/generated/core/params.gen.ts +169 -0
  41. package/src/_api/generated/core/pathSerializer.gen.ts +171 -0
  42. package/src/_api/generated/core/queryKeySerializer.gen.ts +117 -0
  43. package/src/_api/generated/core/serverSentEvents.gen.ts +242 -0
  44. package/src/_api/generated/core/types.gen.ts +104 -0
  45. package/src/_api/generated/core/utils.gen.ts +140 -0
  46. package/src/_api/generated/helpers/errors.ts +70 -0
  47. package/src/_api/generated/helpers/index.ts +25 -0
  48. package/src/_api/generated/helpers/logger.ts +123 -0
  49. package/src/_api/generated/helpers/storage.ts +83 -0
  50. package/src/_api/generated/helpers/validation-events.ts +52 -0
  51. package/src/_api/generated/index.ts +22 -0
  52. package/src/_api/generated/sdk.gen.ts +55 -0
  53. package/src/_api/generated/types.gen.ts +79 -0
  54. package/src/_api/index.ts +2 -2
  55. package/src/client/capture/console.ts +2 -3
  56. package/src/client/transport/ingest.ts +21 -17
  57. package/src/server/index.ts +3 -2
  58. package/src/_api/generated/cfg_monitor/CLAUDE.md +0 -60
  59. package/src/_api/generated/cfg_monitor/_utils/fetchers/index.ts +0 -30
  60. package/src/_api/generated/cfg_monitor/_utils/fetchers/monitor.ts +0 -51
  61. package/src/_api/generated/cfg_monitor/_utils/hooks/index.ts +0 -30
  62. package/src/_api/generated/cfg_monitor/_utils/hooks/monitor.ts +0 -43
  63. package/src/_api/generated/cfg_monitor/_utils/schemas/FrontendEventIngestRequest.schema.ts +0 -34
  64. package/src/_api/generated/cfg_monitor/_utils/schemas/IngestBatchRequest.schema.ts +0 -20
  65. package/src/_api/generated/cfg_monitor/_utils/schemas/index.ts +0 -22
  66. package/src/_api/generated/cfg_monitor/api-instance.ts +0 -181
  67. package/src/_api/generated/cfg_monitor/client.ts +0 -330
  68. package/src/_api/generated/cfg_monitor/enums.ts +0 -34
  69. package/src/_api/generated/cfg_monitor/errors.ts +0 -123
  70. package/src/_api/generated/cfg_monitor/http.ts +0 -160
  71. package/src/_api/generated/cfg_monitor/index.ts +0 -317
  72. package/src/_api/generated/cfg_monitor/logger.ts +0 -261
  73. package/src/_api/generated/cfg_monitor/monitor/client.ts +0 -26
  74. package/src/_api/generated/cfg_monitor/monitor/index.ts +0 -4
  75. package/src/_api/generated/cfg_monitor/monitor/models.ts +0 -47
  76. package/src/_api/generated/cfg_monitor/retry.ts +0 -177
  77. package/src/_api/generated/cfg_monitor/schema.json +0 -181
  78. package/src/_api/generated/cfg_monitor/storage.ts +0 -163
  79. package/src/_api/generated/cfg_monitor/validation-events.ts +0 -135
@@ -0,0 +1,198 @@
1
+ // AUTO-GENERATED by cmdop_server / devtools.generator.ts_extras.events
2
+ // Hooks Hey API client interceptors → typed CustomEvents on `window`.
3
+ // DO NOT EDIT — re-run `make gen-clients`.
4
+ //
5
+ // Usage:
6
+ // import "./generated/events" // side-effect: registers interceptors
7
+ //
8
+ // window.addEventListener("cmdop:network-error", (e) => {
9
+ // console.log(e.detail.status, e.detail.method, e.detail.url);
10
+ // });
11
+
12
+ import { client } from "../client.gen";
13
+
14
+ // ─────────────────────────────────────────────────────────────────────────────
15
+ // Event names + detail types
16
+ // ─────────────────────────────────────────────────────────────────────────────
17
+
18
+ export const NETWORK_ERROR_EVENT = "cmdop:network-error" as const;
19
+ export const VALIDATION_ERROR_EVENT = "cmdop:validation-error" as const;
20
+ export const RUNTIME_ERROR_EVENT = "cmdop:runtime-error" as const;
21
+
22
+ export interface NetworkErrorDetail {
23
+ /** HTTP method (GET/POST/...). */
24
+ method: string;
25
+ /** Request URL. */
26
+ url: string;
27
+ /** HTTP status if response arrived; null on transport failure. */
28
+ status: number | null;
29
+ /** Response body parsed as text (best-effort, may be empty). */
30
+ body?: string;
31
+ /** Underlying error message (network failures, abort, etc.). */
32
+ error?: string;
33
+ /** Heuristic: did the request likely fail due to CORS? */
34
+ possiblyCors: boolean;
35
+ timestamp: Date;
36
+ }
37
+
38
+ export interface ValidationErrorDetail {
39
+ /** Operation ID this validation applies to (from the OpenAPI spec). */
40
+ operation: string;
41
+ /** Schema name that failed (if known). */
42
+ schema?: string;
43
+ /** Issues array — shape mirrors zod's ZodIssue but kept opaque here to
44
+ * avoid forcing a hard zod dep on consumers that don't use schemas. */
45
+ issues: unknown;
46
+ /** Raw response data that failed validation. */
47
+ data: unknown;
48
+ timestamp: Date;
49
+ }
50
+
51
+ export interface RuntimeErrorDetail {
52
+ /** Free-form source identifier — component name, hook name, etc. */
53
+ source: string;
54
+ message: string;
55
+ /** Original Error object (may be undefined when caller lacks one). */
56
+ error?: Error;
57
+ /** Arbitrary context payload from the caller. */
58
+ context?: Record<string, unknown>;
59
+ timestamp: Date;
60
+ }
61
+
62
+ // Augment the global WindowEventMap so addEventListener gets typed details.
63
+ declare global {
64
+ interface WindowEventMap {
65
+ "cmdop:network-error": CustomEvent<NetworkErrorDetail>;
66
+ "cmdop:validation-error": CustomEvent<ValidationErrorDetail>;
67
+ "cmdop:runtime-error": CustomEvent<RuntimeErrorDetail>;
68
+ }
69
+ }
70
+
71
+ // ─────────────────────────────────────────────────────────────────────────────
72
+ // Dispatch helpers
73
+ // ─────────────────────────────────────────────────────────────────────────────
74
+
75
+ function _dispatch<T>(name: string, detail: T): void {
76
+ if (typeof window === "undefined") return;
77
+ try {
78
+ window.dispatchEvent(new CustomEvent(name, { detail, bubbles: true }));
79
+ } catch {
80
+ // Event dispatch must never crash the app.
81
+ }
82
+ }
83
+
84
+ /** Emit a runtime error from anywhere in app code. */
85
+ export function emitRuntimeError(
86
+ source: string,
87
+ message: string,
88
+ error?: Error,
89
+ context?: Record<string, unknown>,
90
+ ): void {
91
+ _dispatch<RuntimeErrorDetail>(RUNTIME_ERROR_EVENT, {
92
+ source,
93
+ message,
94
+ error,
95
+ context,
96
+ timestamp: new Date(),
97
+ });
98
+ }
99
+
100
+ /** Emit a zod validation failure. Called by hooks when `validate` is provided. */
101
+ export function dispatchValidationError(
102
+ operation: string,
103
+ data: unknown,
104
+ issues: unknown,
105
+ schema?: string,
106
+ ): void {
107
+ _dispatch<ValidationErrorDetail>(VALIDATION_ERROR_EVENT, {
108
+ operation,
109
+ schema,
110
+ issues,
111
+ data,
112
+ timestamp: new Date(),
113
+ });
114
+ }
115
+
116
+ // ─────────────────────────────────────────────────────────────────────────────
117
+ // Listen helpers — typed wrappers over addEventListener, return cleanup fn.
118
+ // ─────────────────────────────────────────────────────────────────────────────
119
+
120
+ export function onNetworkError(
121
+ cb: (detail: NetworkErrorDetail) => void,
122
+ ): () => void {
123
+ if (typeof window === "undefined") return () => {};
124
+ const handler = (e: CustomEvent<NetworkErrorDetail>) => cb(e.detail);
125
+ window.addEventListener(NETWORK_ERROR_EVENT, handler);
126
+ return () => window.removeEventListener(NETWORK_ERROR_EVENT, handler);
127
+ }
128
+
129
+ export function onValidationError(
130
+ cb: (detail: ValidationErrorDetail) => void,
131
+ ): () => void {
132
+ if (typeof window === "undefined") return () => {};
133
+ const handler = (e: CustomEvent<ValidationErrorDetail>) => cb(e.detail);
134
+ window.addEventListener(VALIDATION_ERROR_EVENT, handler);
135
+ return () => window.removeEventListener(VALIDATION_ERROR_EVENT, handler);
136
+ }
137
+
138
+ export function onRuntimeError(
139
+ cb: (detail: RuntimeErrorDetail) => void,
140
+ ): () => void {
141
+ if (typeof window === "undefined") return () => {};
142
+ const handler = (e: CustomEvent<RuntimeErrorDetail>) => cb(e.detail);
143
+ window.addEventListener(RUNTIME_ERROR_EVENT, handler);
144
+ return () => window.removeEventListener(RUNTIME_ERROR_EVENT, handler);
145
+ }
146
+
147
+ // ─────────────────────────────────────────────────────────────────────────────
148
+ // Hey API interceptors — wire once, emit on response/error.
149
+ // ─────────────────────────────────────────────────────────────────────────────
150
+
151
+ let _wired = false;
152
+
153
+ function _wire(): void {
154
+ if (_wired) return;
155
+ _wired = true;
156
+
157
+ // response interceptor: every response, OK or not, lets us see status.
158
+ // We only emit for non-2xx — successful requests are silent.
159
+ client.interceptors.response.use(async (response, request) => {
160
+ if (!response.ok) {
161
+ let body: string | undefined;
162
+ try {
163
+ body = await response.clone().text();
164
+ if (body.length > 4000) body = body.slice(0, 4000) + "…";
165
+ } catch {
166
+ // ignore — body inaccessible
167
+ }
168
+ _dispatch<NetworkErrorDetail>(NETWORK_ERROR_EVENT, {
169
+ method: request.method,
170
+ url: request.url,
171
+ status: response.status,
172
+ body,
173
+ possiblyCors: false,
174
+ timestamp: new Date(),
175
+ });
176
+ }
177
+ return response;
178
+ });
179
+
180
+ // error interceptor: transport-level failures (abort, DNS, CORS, offline).
181
+ client.interceptors.error.use((error, _response, request) => {
182
+ const msg = error instanceof Error ? error.message : String(error);
183
+ // Heuristic: CORS-blocked fetches usually surface as "Failed to fetch"
184
+ // without a status. Not perfect, but catches the common case.
185
+ const possiblyCors = /failed to fetch|network error|cors/i.test(msg);
186
+ _dispatch<NetworkErrorDetail>(NETWORK_ERROR_EVENT, {
187
+ method: request?.method ?? "UNKNOWN",
188
+ url: request?.url ?? "",
189
+ status: null,
190
+ error: msg,
191
+ possiblyCors,
192
+ timestamp: new Date(),
193
+ });
194
+ return error;
195
+ });
196
+ }
197
+
198
+ _wire();
@@ -0,0 +1,4 @@
1
+ // AUTO-GENERATED — barrel for all hooks.
2
+ // DO NOT EDIT.
3
+
4
+ export { useCfgMonitorIngestCreate } from "./useCfgMonitorIngestCreate";
@@ -0,0 +1,24 @@
1
+ // AUTO-GENERATED by openapi_processor / ts.hooks
2
+ // Ingest browser events
3
+ // DO NOT EDIT — re-run `make gen`.
4
+
5
+ import useSWRMutation from "swr/mutation";
6
+ import type { SWRMutationConfiguration } from "swr/mutation";
7
+ import { Cfg } from "../../sdk.gen";
8
+ import type { CfgMonitorIngestCreateData, CfgMonitorIngestCreateResponses } from "../../types.gen";
9
+
10
+ type Args = Omit<CfgMonitorIngestCreateData, "url">;
11
+ type Result = CfgMonitorIngestCreateResponses[keyof CfgMonitorIngestCreateResponses];
12
+
13
+ export function useCfgMonitorIngestCreate(
14
+ config?: SWRMutationConfiguration<Result, Error, readonly ["cfg_monitor_ingest_create"], Args>,
15
+ ) {
16
+ return useSWRMutation<Result, Error, readonly ["cfg_monitor_ingest_create"], Args>(
17
+ ["cfg_monitor_ingest_create"] as const,
18
+ async (_key, { arg }: { arg: Args }) => {
19
+ const res = await Cfg.cfgMonitorIngestCreate({ ...arg, throwOnError: true } as never);
20
+ return res.data as Result;
21
+ },
22
+ config,
23
+ );
24
+ }
@@ -0,0 +1,29 @@
1
+ // AUTO-GENERATED by django_generator / ts_extras.wrapper
2
+ // Group barrel. DO NOT EDIT — re-run `make gen`.
3
+
4
+ // Wrapper class + per-group SDK re-exports
5
+ export { API, type APIOptions, } from './api';
6
+
7
+ // Shared utilities (storage / errors / logger / validation events)
8
+ export {
9
+ type StorageAdapter,
10
+ LocalStorageAdapter,
11
+ MemoryStorageAdapter,
12
+ CookieStorageAdapter,
13
+ APIError,
14
+ NetworkError,
15
+ APILogger,
16
+ defaultLogger,
17
+ type LoggerConfig,
18
+ type RequestLog,
19
+ type ResponseLog,
20
+ type ErrorLog,
21
+ dispatchValidationError,
22
+ onValidationError,
23
+ formatZodError,
24
+ type ValidationErrorDetail,
25
+ type ValidationErrorEvent,
26
+ } from '../helpers';
27
+
28
+ // Generated artifacts (Hey API)
29
+ export type * from '../types.gen';
@@ -0,0 +1,9 @@
1
+ // AUTO-GENERATED by cmdop_server / devtools.generator.ts_extras
2
+ // Source: OpenAPI 3.1 components.schemas
3
+ // DO NOT EDIT — re-run `make gen-clients`.
4
+
5
+ import { z } from "zod";
6
+
7
+ export const EventTypeEnumSchema = z.enum(["JS_ERROR", "NETWORK_ERROR", "ERROR", "WARNING", "PAGE_VIEW", "PERFORMANCE", "CONSOLE"]);
8
+
9
+ export type EventTypeEnum = z.infer<typeof EventTypeEnumSchema>;
@@ -0,0 +1,27 @@
1
+ // AUTO-GENERATED by cmdop_server / devtools.generator.ts_extras
2
+ // Source: OpenAPI 3.1 components.schemas
3
+ // DO NOT EDIT — re-run `make gen-clients`.
4
+
5
+ import { z } from "zod";
6
+ import { EventTypeEnumSchema } from "./EventTypeEnum";
7
+ import { LevelEnumSchema } from "./LevelEnum";
8
+
9
+ export const FrontendEventIngestRequestSchema = z.object({
10
+ build_id: z.string().max(100).default("").optional(),
11
+ environment: z.string().max(20).default("").optional(),
12
+ event_type: EventTypeEnumSchema,
13
+ extra: z.unknown().optional(),
14
+ fingerprint: z.string().max(64).default("").optional(),
15
+ http_method: z.string().max(10).default("").optional(),
16
+ http_status: z.number().int().nullable().optional(),
17
+ http_url: z.string().max(2000).default("").optional(),
18
+ level: LevelEnumSchema.optional(),
19
+ message: z.string().min(1).max(5000),
20
+ project_name: z.string().max(100).default("").optional(),
21
+ session_id: z.string().max(64).default("").optional(),
22
+ stack_trace: z.string().max(10000).default("").optional(),
23
+ url: z.string().max(2000).default("").optional(),
24
+ user_agent: z.string().max(500).default("").optional(),
25
+ });
26
+
27
+ export type FrontendEventIngestRequest = z.infer<typeof FrontendEventIngestRequestSchema>;
@@ -0,0 +1,12 @@
1
+ // AUTO-GENERATED by cmdop_server / devtools.generator.ts_extras
2
+ // Source: OpenAPI 3.1 components.schemas
3
+ // DO NOT EDIT — re-run `make gen-clients`.
4
+
5
+ import { z } from "zod";
6
+ import { FrontendEventIngestRequestSchema } from "./FrontendEventIngestRequest";
7
+
8
+ export const IngestBatchRequestSchema = z.object({
9
+ events: z.array(FrontendEventIngestRequestSchema),
10
+ });
11
+
12
+ export type IngestBatchRequest = z.infer<typeof IngestBatchRequestSchema>;
@@ -0,0 +1,9 @@
1
+ // AUTO-GENERATED by cmdop_server / devtools.generator.ts_extras
2
+ // Source: OpenAPI 3.1 components.schemas
3
+ // DO NOT EDIT — re-run `make gen-clients`.
4
+
5
+ import { z } from "zod";
6
+
7
+ export const LevelEnumSchema = z.enum(["error", "warning", "info", "debug"]);
8
+
9
+ export type LevelEnum = z.infer<typeof LevelEnumSchema>;
@@ -0,0 +1,7 @@
1
+ // AUTO-GENERATED — barrel for zod schemas.
2
+ // DO NOT EDIT.
3
+
4
+ export * from "./EventTypeEnum";
5
+ export * from "./FrontendEventIngestRequest";
6
+ export * from "./IngestBatchRequest";
7
+ export * from "./LevelEnum";
@@ -0,0 +1,5 @@
1
+ // AUTO-GENERATED by openapi_processor / ts.tool
2
+ // Re-exports the top-level Hey API SDK so group-scoped imports work:
3
+ // import { Foo } from "@api/generated/_<group>/sdk.gen";
4
+ // DO NOT EDIT — re-run `make gen`.
5
+ export * from "../sdk.gen";
@@ -0,0 +1,5 @@
1
+ // AUTO-GENERATED by openapi_processor / ts.tool
2
+ // Re-exports the top-level Hey API types so group-scoped imports work:
3
+ // import type { Foo } from "@api/generated/_<group>/types.gen";
4
+ // DO NOT EDIT — re-run `make gen`.
5
+ export * from "../types.gen";
@@ -0,0 +1,280 @@
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 { getValidRequestBody } from '../core/utils.gen';
6
+ import type { Client, Config, RequestOptions, ResolvedRequestOptions } from './types.gen';
7
+ import {
8
+ buildUrl,
9
+ createConfig,
10
+ createInterceptors,
11
+ getParseAs,
12
+ mergeConfigs,
13
+ mergeHeaders,
14
+ setAuthParams,
15
+ } from './utils.gen';
16
+
17
+ type ReqInit = Omit<RequestInit, 'body' | 'headers'> & {
18
+ body?: any;
19
+ headers: ReturnType<typeof mergeHeaders>;
20
+ };
21
+
22
+ export const createClient = (config: Config = {}): Client => {
23
+ let _config = mergeConfigs(createConfig(), config);
24
+
25
+ const getConfig = (): Config => ({ ..._config });
26
+
27
+ const setConfig = (config: Config): Config => {
28
+ _config = mergeConfigs(_config, config);
29
+ return getConfig();
30
+ };
31
+
32
+ const interceptors = createInterceptors<Request, Response, unknown, ResolvedRequestOptions>();
33
+
34
+ const beforeRequest = async <
35
+ TData = unknown,
36
+ TResponseStyle extends 'data' | 'fields' = 'fields',
37
+ ThrowOnError extends boolean = boolean,
38
+ Url extends string = string,
39
+ >(
40
+ options: RequestOptions<TData, TResponseStyle, ThrowOnError, Url>,
41
+ ) => {
42
+ const opts = {
43
+ ..._config,
44
+ ...options,
45
+ fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
46
+ headers: mergeHeaders(_config.headers, options.headers),
47
+ serializedBody: undefined as string | undefined,
48
+ };
49
+
50
+ if (opts.security) {
51
+ await setAuthParams({
52
+ ...opts,
53
+ security: opts.security,
54
+ });
55
+ }
56
+
57
+ if (opts.requestValidator) {
58
+ await opts.requestValidator(opts);
59
+ }
60
+
61
+ if (opts.body !== undefined && opts.bodySerializer) {
62
+ opts.serializedBody = opts.bodySerializer(opts.body) as string | undefined;
63
+ }
64
+
65
+ // remove Content-Type header if body is empty to avoid sending invalid requests
66
+ if (opts.body === undefined || opts.serializedBody === '') {
67
+ opts.headers.delete('Content-Type');
68
+ }
69
+
70
+ const resolvedOpts = opts as typeof opts &
71
+ ResolvedRequestOptions<TResponseStyle, ThrowOnError, Url>;
72
+ const url = buildUrl(resolvedOpts);
73
+
74
+ return { opts: resolvedOpts, url };
75
+ };
76
+
77
+ const request: Client['request'] = async (options) => {
78
+ const throwOnError = options.throwOnError ?? _config.throwOnError;
79
+ const responseStyle = options.responseStyle ?? _config.responseStyle;
80
+
81
+ let request: Request | undefined;
82
+ let response: Response | undefined;
83
+
84
+ try {
85
+ const { opts, url } = await beforeRequest(options);
86
+ const requestInit: ReqInit = {
87
+ redirect: 'follow',
88
+ ...opts,
89
+ body: getValidRequestBody(opts),
90
+ };
91
+
92
+ request = new Request(url, requestInit);
93
+
94
+ for (const fn of interceptors.request.fns) {
95
+ if (fn) {
96
+ request = await fn(request, opts);
97
+ }
98
+ }
99
+
100
+ // fetch must be assigned here, otherwise it would throw the error:
101
+ // TypeError: Failed to execute 'fetch' on 'Window': Illegal invocation
102
+ const _fetch = opts.fetch!;
103
+
104
+ response = await _fetch(request);
105
+
106
+ for (const fn of interceptors.response.fns) {
107
+ if (fn) {
108
+ response = await fn(response, request, opts);
109
+ }
110
+ }
111
+
112
+ const result = {
113
+ request,
114
+ response,
115
+ };
116
+
117
+ if (response.ok) {
118
+ const parseAs =
119
+ (opts.parseAs === 'auto'
120
+ ? getParseAs(response.headers.get('Content-Type'))
121
+ : opts.parseAs) ?? 'json';
122
+
123
+ if (response.status === 204 || response.headers.get('Content-Length') === '0') {
124
+ let emptyData: any;
125
+ switch (parseAs) {
126
+ case 'arrayBuffer':
127
+ case 'blob':
128
+ case 'text':
129
+ emptyData = await response[parseAs]();
130
+ break;
131
+ case 'formData':
132
+ emptyData = new FormData();
133
+ break;
134
+ case 'stream':
135
+ emptyData = response.body;
136
+ break;
137
+ case 'json':
138
+ default:
139
+ emptyData = {};
140
+ break;
141
+ }
142
+ return opts.responseStyle === 'data'
143
+ ? emptyData
144
+ : {
145
+ data: emptyData,
146
+ ...result,
147
+ };
148
+ }
149
+
150
+ let data: any;
151
+ switch (parseAs) {
152
+ case 'arrayBuffer':
153
+ case 'blob':
154
+ case 'formData':
155
+ case 'text':
156
+ data = await response[parseAs]();
157
+ break;
158
+ case 'json': {
159
+ // Some servers return 200 with no Content-Length and empty body.
160
+ // response.json() would throw; read as text and parse if non-empty.
161
+ const text = await response.text();
162
+ data = text ? JSON.parse(text) : {};
163
+ break;
164
+ }
165
+ case 'stream':
166
+ return opts.responseStyle === 'data'
167
+ ? response.body
168
+ : {
169
+ data: response.body,
170
+ ...result,
171
+ };
172
+ }
173
+
174
+ if (parseAs === 'json') {
175
+ if (opts.responseValidator) {
176
+ await opts.responseValidator(data);
177
+ }
178
+
179
+ if (opts.responseTransformer) {
180
+ data = await opts.responseTransformer(data);
181
+ }
182
+ }
183
+
184
+ return opts.responseStyle === 'data'
185
+ ? data
186
+ : {
187
+ data,
188
+ ...result,
189
+ };
190
+ }
191
+
192
+ const textError = await response.text();
193
+ let jsonError: unknown;
194
+
195
+ try {
196
+ jsonError = JSON.parse(textError);
197
+ } catch {
198
+ // noop
199
+ }
200
+
201
+ throw jsonError ?? textError;
202
+ } catch (error) {
203
+ let finalError = error;
204
+
205
+ for (const fn of interceptors.error.fns) {
206
+ if (fn) {
207
+ finalError = await fn(finalError, response, request, options as ResolvedRequestOptions);
208
+ }
209
+ }
210
+
211
+ finalError = finalError || {};
212
+
213
+ if (throwOnError) {
214
+ throw finalError;
215
+ }
216
+
217
+ // TODO: we probably want to return error and improve types
218
+ return responseStyle === 'data'
219
+ ? undefined
220
+ : {
221
+ error: finalError,
222
+ request,
223
+ response,
224
+ };
225
+ }
226
+ };
227
+
228
+ const makeMethodFn = (method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
229
+ request({ ...options, method });
230
+
231
+ const makeSseFn = (method: Uppercase<HttpMethod>) => async (options: RequestOptions) => {
232
+ const { opts, url } = await beforeRequest(options);
233
+ return createSseClient({
234
+ ...opts,
235
+ body: opts.body as BodyInit | null | undefined,
236
+ method,
237
+ onRequest: async (url, init) => {
238
+ let request = new Request(url, init);
239
+ for (const fn of interceptors.request.fns) {
240
+ if (fn) {
241
+ request = await fn(request, opts);
242
+ }
243
+ }
244
+ return request;
245
+ },
246
+ serializedBody: getValidRequestBody(opts) as BodyInit | null | undefined,
247
+ url,
248
+ });
249
+ };
250
+
251
+ const _buildUrl: Client['buildUrl'] = (options) => buildUrl({ ..._config, ...options });
252
+
253
+ return {
254
+ buildUrl: _buildUrl,
255
+ connect: makeMethodFn('CONNECT'),
256
+ delete: makeMethodFn('DELETE'),
257
+ get: makeMethodFn('GET'),
258
+ getConfig,
259
+ head: makeMethodFn('HEAD'),
260
+ interceptors,
261
+ options: makeMethodFn('OPTIONS'),
262
+ patch: makeMethodFn('PATCH'),
263
+ post: makeMethodFn('POST'),
264
+ put: makeMethodFn('PUT'),
265
+ request,
266
+ setConfig,
267
+ sse: {
268
+ connect: makeSseFn('CONNECT'),
269
+ delete: makeSseFn('DELETE'),
270
+ get: makeSseFn('GET'),
271
+ head: makeSseFn('HEAD'),
272
+ options: makeSseFn('OPTIONS'),
273
+ patch: makeSseFn('PATCH'),
274
+ post: makeSseFn('POST'),
275
+ put: makeSseFn('PUT'),
276
+ trace: makeSseFn('TRACE'),
277
+ },
278
+ trace: makeMethodFn('TRACE'),
279
+ } as Client;
280
+ };
@@ -0,0 +1,25 @@
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';
5
+ export {
6
+ formDataBodySerializer,
7
+ jsonBodySerializer,
8
+ urlSearchParamsBodySerializer,
9
+ } from '../core/bodySerializer.gen';
10
+ export { buildClientParams } from '../core/params.gen';
11
+ export { serializeQueryKeyValue } from '../core/queryKeySerializer.gen';
12
+ export { createClient } from './client.gen';
13
+ export type {
14
+ Client,
15
+ ClientOptions,
16
+ Config,
17
+ CreateClientConfig,
18
+ Options,
19
+ RequestOptions,
20
+ RequestResult,
21
+ ResolvedRequestOptions,
22
+ ResponseStyle,
23
+ TDataShape,
24
+ } from './types.gen';
25
+ export { createConfig, mergeHeaders } from './utils.gen';