@povio/openapi-codegen-cli 3.2.0-rc.7 → 3.2.0-rc.8

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/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { a as ErrorHandler, c as SharedErrorHandler, d as ns, f as resources, i as ErrorEntry, l as TranslateFunction, n as DomainErrorEntry, o as ErrorHandlerOptions, r as DomainErrorRegistry, s as GeneralErrorCodes, t as ApplicationException, u as configureTranslations } from "./error-handling-CNOHs4Fc.mjs";
2
2
  import { t as OpenAPICodegenConfig } from "./config-DgrOddSC.mjs";
3
- import { c as TransportRequestConfig, d as UploadProgress, l as TransportResponse, n as HttpError, s as TransportRequest } from "./rest-transport.types-D0R9mvGH.mjs";
4
- import { n as NativeRestInterceptor, r as NativeRestClient, t as NativeInterceptor } from "./native-rest-interceptor-CTBBx6B3.mjs";
3
+ import { d as TransportResponse, l as TransportRequest, n as HttpError, p as UploadProgress, u as TransportRequestConfig } from "./rest-transport.types-DM5-qyOJ.mjs";
4
+ import { n as NativeRestInterceptor, r as NativeRestClient, t as NativeInterceptor } from "./native-rest-interceptor-Cz6saoq5.mjs";
5
5
  import { AxiosError, AxiosInstance, AxiosRequestConfig, AxiosResponse, AxiosResponseHeaders, CreateAxiosDefaults } from "axios";
6
6
  import { z } from "zod";
7
7
  import { PropsWithChildren, ReactNode } from "react";
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { a as RestUtils, c as resources, i as SharedErrorHandler, n as DomainErrorRegistry, o as configureTranslations, r as ErrorHandler, s as ns, t as ApplicationException } from "./error-handling-BMXC5P08.mjs";
2
2
  import { t as HttpError } from "./rest-transport.types-DxitRtsB.mjs";
3
- import { n as NativeRestClient, t as NativeRestInterceptor } from "./native-rest-interceptor-Bcc2jx4e.mjs";
3
+ import { n as NativeRestClient, t as NativeRestInterceptor } from "./native-rest-interceptor-CAWR8H5Y.mjs";
4
4
  import { n as OpenApiRouter, t as AuthContext } from "./auth.context-YFWzkwoN.mjs";
5
5
  import axios from "axios";
6
6
  import { z } from "zod";
@@ -7,11 +7,13 @@ var NativeRestClient = class {
7
7
  this.baseURL = config?.baseURL ?? "";
8
8
  this.headers = config?.headers;
9
9
  this.credentials = config?.credentials;
10
+ this.fetch = config?.fetch ?? globalThis.fetch.bind(globalThis);
10
11
  this.interceptors = [...interceptors];
11
12
  }
12
13
  baseURL;
13
14
  headers;
14
15
  credentials;
16
+ fetch;
15
17
  attachInterceptor(interceptor) {
16
18
  this.interceptors.push(interceptor);
17
19
  }
@@ -94,7 +96,7 @@ var NativeRestClient = class {
94
96
  else next.signal.addEventListener("abort", () => timeoutController.abort(next.signal?.reason), { once: true });
95
97
  const signal = timeoutController?.signal ?? next.signal;
96
98
  try {
97
- const res = await fetch(next.url, {
99
+ const res = await this.fetch(next.url, {
98
100
  method: next.method,
99
101
  headers: next.headers,
100
102
  body: next.body,
@@ -111,6 +113,19 @@ var NativeRestClient = class {
111
113
  if (!res.ok) throw new HttpError(`Request failed with status ${res.status}`, response);
112
114
  if (applyInterceptors) for (const interceptor of this.interceptors) response = await interceptor.onResponse?.(response) ?? response;
113
115
  return response;
116
+ } catch (error) {
117
+ if (!applyInterceptors) throw error;
118
+ const context = {
119
+ request: next,
120
+ response: error instanceof HttpError ? error.response : void 0,
121
+ retry: (request = next) => this.execute({
122
+ ...request,
123
+ retryCount: (next.retryCount ?? 0) + 1
124
+ }, config, true)
125
+ };
126
+ const transformed = await this.runErrorInterceptors(error, context);
127
+ if (this.isTransportResponse(transformed)) return transformed;
128
+ throw transformed;
114
129
  } finally {
115
130
  if (timer) clearTimeout(timer);
116
131
  }
@@ -139,15 +154,19 @@ var NativeRestClient = class {
139
154
  }
140
155
  return url.toString();
141
156
  }
142
- async runErrorInterceptors(error) {
157
+ async runErrorInterceptors(error, context) {
143
158
  let next = error;
159
+ if (!context) return next;
144
160
  for (const interceptor of [...this.interceptors].reverse()) if (interceptor.onError) try {
145
- next = await interceptor.onError(next);
161
+ next = await interceptor.onError(next, context);
146
162
  } catch (transformed) {
147
163
  next = transformed;
148
164
  }
149
165
  return next;
150
166
  }
167
+ isTransportResponse(value) {
168
+ return !!value && typeof value === "object" && "status" in value && "headers" in value && "data" in value;
169
+ }
151
170
  uploadWithXhr(url, data, config, method) {
152
171
  return new Promise((resolve, reject) => {
153
172
  const xhr = new XMLHttpRequest();
@@ -180,9 +199,9 @@ var NativeRestInterceptor = class {
180
199
  onResponse(response) {
181
200
  return this.interceptor.onResponse?.(response) ?? response;
182
201
  }
183
- onError(error) {
202
+ onError(error, context) {
184
203
  if (!this.interceptor.onError) throw error;
185
- return this.interceptor.onError(error);
204
+ return this.interceptor.onError(error, context);
186
205
  }
187
206
  };
188
207
  //#endregion
@@ -1,4 +1,4 @@
1
- import { a as RestTransport, c as TransportRequestConfig, l as TransportResponse, o as RestTransportInterceptor, r as RestRequestInfo, s as TransportRequest, t as GeneralTransportErrorCode } from "./rest-transport.types-D0R9mvGH.mjs";
1
+ import { a as RestTransport, c as TransportFetch, d as TransportResponse, l as TransportRequest, o as RestTransportInterceptor, r as RestRequestInfo, s as TransportErrorContext, t as GeneralTransportErrorCode, u as TransportRequestConfig } from "./rest-transport.types-DM5-qyOJ.mjs";
2
2
  //#region src/lib/rest/native-rest-client.d.ts
3
3
  type NativeResult<T, IsRawRes extends boolean> = IsRawRes extends true ? TransportResponse<T> : T;
4
4
  declare class NativeRestClient implements RestTransport {
@@ -8,12 +8,14 @@ declare class NativeRestClient implements RestTransport {
8
8
  baseURL?: string;
9
9
  headers?: HeadersInit;
10
10
  credentials?: RequestCredentials;
11
+ fetch?: TransportFetch;
11
12
  };
12
13
  interceptors?: RestTransportInterceptor[];
13
14
  });
14
15
  private readonly baseURL;
15
16
  private readonly headers?;
16
17
  private readonly credentials?;
18
+ private readonly fetch;
17
19
  attachInterceptor(interceptor: RestTransportInterceptor): void;
18
20
  ejectInterceptor(interceptor: RestTransportInterceptor): void;
19
21
  get<T, E extends string = GeneralTransportErrorCode, R extends boolean = false>(info: RestRequestInfo<T, E>, url: string, config?: TransportRequestConfig<R>): Promise<NativeResult<T, R>>;
@@ -27,6 +29,7 @@ declare class NativeRestClient implements RestTransport {
27
29
  private readResponse;
28
30
  private resolveUrl;
29
31
  private runErrorInterceptors;
32
+ private isTransportResponse;
30
33
  private uploadWithXhr;
31
34
  }
32
35
  //#endregion
@@ -37,7 +40,7 @@ declare class NativeRestInterceptor implements RestTransportInterceptor {
37
40
  constructor(interceptor: RestTransportInterceptor);
38
41
  onRequest(request: TransportRequest): Promise<TransportRequest> | TransportRequest;
39
42
  onResponse<T>(response: TransportResponse<T>): Promise<TransportResponse<T>> | TransportResponse<T>;
40
- onError(error: unknown): unknown;
43
+ onError(error: unknown, context: TransportErrorContext): unknown;
41
44
  }
42
45
  //#endregion
43
46
  export { NativeRestInterceptor as n, NativeRestClient as r, NativeInterceptor as t };
package/dist/native.d.mts CHANGED
@@ -1,3 +1,3 @@
1
- import { a as RestTransport, c as TransportRequestConfig, d as UploadProgress, i as RestResponseType, l as TransportResponse, n as HttpError, o as RestTransportInterceptor, r as RestRequestInfo, s as TransportRequest, t as GeneralTransportErrorCode, u as TransportResult } from "./rest-transport.types-D0R9mvGH.mjs";
2
- import { n as NativeRestInterceptor, r as NativeRestClient, t as NativeInterceptor } from "./native-rest-interceptor-CTBBx6B3.mjs";
1
+ import { a as RestTransport, d as TransportResponse, f as TransportResult, i as RestResponseType, l as TransportRequest, n as HttpError, o as RestTransportInterceptor, p as UploadProgress, r as RestRequestInfo, t as GeneralTransportErrorCode, u as TransportRequestConfig } from "./rest-transport.types-DM5-qyOJ.mjs";
2
+ import { n as NativeRestInterceptor, r as NativeRestClient, t as NativeInterceptor } from "./native-rest-interceptor-Cz6saoq5.mjs";
3
3
  export { type GeneralTransportErrorCode, HttpError, HttpError as NativeHttpError, type NativeInterceptor, type TransportRequest as NativeRequest, type TransportRequest, type TransportRequestConfig as NativeRequestConfig, type TransportRequestConfig, type TransportResponse as NativeResponse, type TransportResponse, NativeRestClient, NativeRestInterceptor, type UploadProgress as NativeUploadProgress, type UploadProgress, type RestRequestInfo, type RestResponseType, type RestTransport, type RestTransportInterceptor, type TransportResult };
package/dist/native.mjs CHANGED
@@ -1,3 +1,3 @@
1
1
  import { t as HttpError } from "./rest-transport.types-DxitRtsB.mjs";
2
- import { n as NativeRestClient, t as NativeRestInterceptor } from "./native-rest-interceptor-Bcc2jx4e.mjs";
2
+ import { n as NativeRestClient, t as NativeRestInterceptor } from "./native-rest-interceptor-CAWR8H5Y.mjs";
3
3
  export { HttpError, HttpError as NativeHttpError, NativeRestClient, NativeRestInterceptor };
@@ -2,6 +2,7 @@ import { z } from "zod";
2
2
  //#region src/lib/rest/rest-transport.types.d.ts
3
3
  type GeneralTransportErrorCode = "DATA_VALIDATION_ERROR" | "NETWORK_ERROR" | "CANCELED_ERROR" | "INTERNAL_ERROR" | "UNKNOWN_ERROR";
4
4
  type RestResponseType = "json" | "text" | "blob" | "arrayBuffer";
5
+ type TransportFetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
5
6
  interface UploadProgress {
6
7
  loaded: number;
7
8
  total: number;
@@ -34,11 +35,17 @@ interface TransportRequest {
34
35
  body?: BodyInit | null;
35
36
  signal?: AbortSignal;
36
37
  credentials?: RequestCredentials;
38
+ retryCount?: number;
39
+ }
40
+ interface TransportErrorContext {
41
+ request: TransportRequest;
42
+ response?: TransportResponse<unknown>;
43
+ retry(request?: TransportRequest): Promise<TransportResponse<unknown>>;
37
44
  }
38
45
  interface RestTransportInterceptor {
39
46
  onRequest?(request: TransportRequest): TransportRequest | Promise<TransportRequest>;
40
47
  onResponse?<T>(response: TransportResponse<T>): TransportResponse<T> | Promise<TransportResponse<T>>;
41
- onError?(error: unknown): unknown | Promise<unknown>;
48
+ onError?(error: unknown, context: TransportErrorContext): unknown | Promise<unknown>;
42
49
  }
43
50
  type TransportResult<T, IsRawRes extends boolean> = IsRawRes extends true ? TransportResponse<T> : T;
44
51
  interface RestTransport {
@@ -56,4 +63,4 @@ declare class HttpError<T = unknown> extends Error {
56
63
  constructor(message: string, response: TransportResponse<T>);
57
64
  }
58
65
  //#endregion
59
- export { RestTransport as a, TransportRequestConfig as c, UploadProgress as d, RestResponseType as i, TransportResponse as l, HttpError as n, RestTransportInterceptor as o, RestRequestInfo as r, TransportRequest as s, GeneralTransportErrorCode as t, TransportResult as u };
66
+ export { RestTransport as a, TransportFetch as c, TransportResponse as d, TransportResult as f, RestResponseType as i, TransportRequest as l, HttpError as n, RestTransportInterceptor as o, UploadProgress as p, RestRequestInfo as r, TransportErrorContext as s, GeneralTransportErrorCode as t, TransportRequestConfig as u };
package/dist/rest.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as RestTransport, c as TransportRequestConfig, d as UploadProgress, i as RestResponseType, l as TransportResponse, n as HttpError, o as RestTransportInterceptor, r as RestRequestInfo, s as TransportRequest, t as GeneralTransportErrorCode, u as TransportResult } from "./rest-transport.types-D0R9mvGH.mjs";
1
+ import { a as RestTransport, d as TransportResponse, f as TransportResult, i as RestResponseType, l as TransportRequest, n as HttpError, o as RestTransportInterceptor, p as UploadProgress, r as RestRequestInfo, t as GeneralTransportErrorCode, u as TransportRequestConfig } from "./rest-transport.types-DM5-qyOJ.mjs";
2
2
  export { type GeneralTransportErrorCode, HttpError, type RestRequestInfo, type RestResponseType, type RestTransport, type RestTransportInterceptor, type TransportRequest, type TransportRequestConfig, type TransportResponse, type TransportResult, type UploadProgress };
package/dist/sh.mjs CHANGED
@@ -31,7 +31,7 @@ function logBanner(message) {
31
31
  * Fetch the version from package.json
32
32
  */
33
33
  function getVersion() {
34
- return "3.2.0-rc.7";
34
+ return "3.2.0-rc.8";
35
35
  }
36
36
  //#endregion
37
37
  //#region src/helpers/yargs.helper.ts
package/package.json CHANGED
@@ -149,5 +149,5 @@
149
149
  "node": ">= 18"
150
150
  },
151
151
  "packageManager": "bun@1.3.14",
152
- "version": "3.2.0-rc.7"
152
+ "version": "3.2.0-rc.8"
153
153
  }