@povio/openapi-codegen-cli 2.0.2-rc.5 → 2.0.2

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.
@@ -28,12 +28,12 @@ export declare function getEndpointConfig(endpoint: Endpoint): {
28
28
  params?: {
29
29
  name: string;
30
30
  value: string;
31
- description?: string | undefined;
31
+ description?: string;
32
32
  type: "Query" | "Body" | "Header" | "Path";
33
33
  zodSchema: string;
34
- parameterObject?: import("../../types/openapi").ParameterObject | undefined;
35
- parameterSortingEnumSchemaName?: string | undefined;
36
- bodyObject?: OpenAPIV3.RequestBodyObject | undefined;
34
+ parameterObject?: import("../../types/openapi").ParameterObject;
35
+ parameterSortingEnumSchemaName?: string;
36
+ bodyObject?: OpenAPIV3.RequestBodyObject;
37
37
  }[] | undefined;
38
38
  };
39
39
  export declare function getUpdateQueryEndpoints(endpoint: Endpoint, endpoints: Endpoint[]): Endpoint[];
@@ -1,5 +1,5 @@
1
- import { Get } from "type-fest";
2
1
  import { HasNestedPath, ObjectLiteral } from "src/generators/types/common";
2
+ import { Get } from "type-fest";
3
3
  /** Get a nested property value from a dot-delimited path. */
4
4
  export declare function getNested<Path extends string, From extends ObjectLiteral, Return = HasNestedPath<Path> extends 1 ? From[Path] : Get<From, Path>>(obj: From, path: Path): Return;
5
5
  /** Pick given properties in object */
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- var Z=Object.defineProperty;var L=(a,e,r)=>e in a?Z(a,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):a[e]=r;var n=(a,e)=>Z(a,"name",{value:e,configurable:!0});var c=(a,e,r)=>L(a,typeof e!="symbol"?e+"":e,r);import z from"axios";import{z as K}from"zod";import I from"axios";import{z as V}from"zod";import U from"i18next";var G={openapi:{sharedErrors:{dataValidation:"An error occurred while validating the data",internalError:"An internal error occurred. This is most likely a bug on our end. Please try again later.",networkError:"A network error occurred. Are you connected to the internet?",canceledError:"The request was canceled.",unknownError:"An unknown error occurred. Please try again later.",unknownErrorWithCode:'An unknown error occurred. Error code: "{{code}}"'}}};var S={openapi:{sharedErrors:{dataValidation:"Pri preverjanju podatkov je pri\u0161lo do napake",internalError:"Pri\u0161lo je do notranje napake.",networkError:"Pri\u0161lo je do napake v omre\u017Eju.",canceledError:"Zahteva je bila preklicana.",unknownError:"Pri\u0161lo je do neznane napake.",unknownErrorWithCode:'Pri\u0161lo je do neznane napake. Koda napake: "{{code}}"'}}};var C="openapi",w={en:{[C]:G},sl:{[C]:S}},H="en",y=U.createInstance();y.init({compatibilityJSON:"v4",lng:H,fallbackLng:H,resources:w,ns:Object.keys(w.en),defaultNS:C,interpolation:{escapeValue:!1}});var v=y.t.bind(y);import D from"axios";import{z as W}from"zod";var d;(t=>(t.extractServerResponseCode=n(s=>{if(s instanceof W.ZodError)return"validation-exception";if(!D.isAxiosError(s)||!s.response)return null;let i=s.response.data;return typeof i?.code=="string"?i.code:null},"extractServerResponseCode"),t.doesServerErrorMessageContain=n((s,i)=>{let p=(0,t.extractServerErrorMessage)(s);return p==null?!1:p.toLowerCase().includes(i.toLowerCase())},"doesServerErrorMessageContain"),t.extractServerErrorMessage=n(s=>{if(s instanceof W.ZodError)return s.message;if(!D.isAxiosError(s)||!s.response)return null;let i=s.response.data;return typeof i?.message=="string"?i.message:null},"extractServerErrorMessage"),t.extractContentDispositionFilename=n(s=>{let i=s["content-disposition"];return i?/filename=["']?([^"';]+)/i.exec(i)?.[1]:void 0},"extractContentDispositionFilename")))(d||(d={}));var k=class k extends Error{constructor(r,o,t){super(r);c(this,"code");c(this,"serverMessage",null);this.code=o,this.serverMessage=t}};n(k,"ApplicationException");var l=k,b=class b{constructor({entries:e,t:r=v,onRethrowError:o}){c(this,"entries",[]);c(this,"t");c(this,"onRethrowError");this.t=r,this.onRethrowError=o;let t={code:"DATA_VALIDATION_ERROR",condition:n(u=>u instanceof V.ZodError,"condition"),getMessage:n(()=>this.t("openapi.sharedErrors.dataValidation"),"getMessage")},s={code:"INTERNAL_ERROR",condition:n(u=>I.isAxiosError(u)?u.response?.status!=null&&u.response.status>=500&&u.response.status<600:!1,"condition"),getMessage:n(()=>this.t("openapi.sharedErrors.internalError"),"getMessage")},i={code:"NETWORK_ERROR",condition:n(u=>I.isAxiosError(u)?u.code==="ERR_NETWORK":!1,"condition"),getMessage:n(()=>this.t("openapi.sharedErrors.networkError"),"getMessage")},p={code:"CANCELED_ERROR",condition:n(u=>!!(I.isCancel(u)||I.isAxiosError(u)&&u.code==="ECONNABORTED"),"condition"),getMessage:n(()=>this.t("openapi.sharedErrors.canceledError"),"getMessage")},f={code:"UNKNOWN_ERROR",condition:n(()=>!0,"condition"),getMessage:n((u,E)=>{let R=d.extractServerResponseCode(E),m=d.extractServerErrorMessage(E);if(R){let g=`Unknown error, message from server: ${R}`;return m&&(g+=` ${m}`),g}return this.t("openapi.sharedErrors.unknownError")},"getMessage")};this.entries=[...e,t,s,i,p,f]}matchesEntry(e,r,o){return r.condition?r.condition(e):o===r.code}setTranslateFunction(e){this.t=e}rethrowError(e){let r=d.extractServerResponseCode(e),o=this.entries.find(i=>this.matchesEntry(e,i,r)),t=d.extractServerErrorMessage(e),s=new l(o.getMessage(this.t,e),o.code,t);throw this.onRethrowError?.(e,s),s}getError(e){return e instanceof l?e:null}getErrorCode(e){return e instanceof l?e.code:null}static getErrorMessage(e,r=!0){return typeof e=="string"?e:e instanceof Error||e instanceof l?e.message:r?v("openapi.sharedErrors.unknownError"):null}};n(b,"ErrorHandler");var T=b,A=new T({entries:[]});var O=class O{constructor({config:e,interceptors:r,errorHandler:o}={}){c(this,"client");c(this,"errorHandler");this.client=z.create(e),this.errorHandler=o??A,this.attachInterceptors(r)}attachInterceptors(e,...r){e?.forEach(o=>this.attachInterceptor(o,...r))}attachInterceptor(e,...r){e.addInterceptor(this.client,...r)}ejectInterceptor(e){e.removeInterceptor(this.client)}async get(e,r,o){return this.makeRequest(e,{...o,method:"get",url:r})}async post(e,r,o,t){return this.makeRequest(e,{...t,method:"post",url:r,data:o})}async patch(e,r,o,t){return this.makeRequest(e,{...t,method:"patch",url:r,data:o})}async put(e,r,o,t){return this.makeRequest(e,{...t,method:"put",url:r,data:o})}async delete(e,r,o,t){return this.makeRequest(e,{...t,method:"delete",url:r,data:o})}async makeRequest(e,r){let o=new Error().stack;try{let{rawResponse:t,...s}=r,i=await this.client(s),p=e.resSchema.parse(i.data);return t?{...i,data:p}:p}catch(t){throw t instanceof K.ZodError&&(t.name="BE Response schema mismatch - ZodError",t.stack=[t.stack,...o?.split(`
1
+ var Z=Object.defineProperty;var L=(a,e,r)=>e in a?Z(a,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):a[e]=r;var n=(a,e)=>Z(a,"name",{value:e,configurable:!0});var c=(a,e,r)=>L(a,typeof e!="symbol"?e+"":e,r);import K from"axios";import{z as B}from"zod";import{isAxiosError as v,isCancel as V}from"axios";import{z}from"zod";import U from"i18next";var G={openapi:{sharedErrors:{dataValidation:"An error occurred while validating the data",internalError:"An internal error occurred. This is most likely a bug on our end. Please try again later.",networkError:"A network error occurred. Are you connected to the internet?",canceledError:"The request was canceled.",unknownError:"An unknown error occurred. Please try again later.",unknownErrorWithCode:'An unknown error occurred. Error code: "{{code}}"'}}};var S={openapi:{sharedErrors:{dataValidation:"Pri preverjanju podatkov je pri\u0161lo do napake",internalError:"Pri\u0161lo je do notranje napake.",networkError:"Pri\u0161lo je do napake v omre\u017Eju.",canceledError:"Zahteva je bila preklicana.",unknownError:"Pri\u0161lo je do neznane napake.",unknownErrorWithCode:'Pri\u0161lo je do neznane napake. Koda napake: "{{code}}"'}}};var C="openapi",T={en:{[C]:G},sl:{[C]:S}},H="en",w=U.createInstance();w.init({compatibilityJSON:"v4",lng:H,fallbackLng:H,resources:T,ns:Object.keys(T.en),defaultNS:C,interpolation:{escapeValue:!1}});var y=w.t.bind(w);import{z as D}from"zod";import{isAxiosError as W}from"axios";var d;(t=>(t.extractServerResponseCode=n(s=>{if(s instanceof D.ZodError)return"validation-exception";if(!W(s)||!s.response)return null;let i=s.response.data;return typeof i?.code=="string"?i.code:null},"extractServerResponseCode"),t.doesServerErrorMessageContain=n((s,i)=>{let p=(0,t.extractServerErrorMessage)(s);return p==null?!1:p.toLowerCase().includes(i.toLowerCase())},"doesServerErrorMessageContain"),t.extractServerErrorMessage=n(s=>{if(s instanceof D.ZodError)return s.message;if(!W(s)||!s.response)return null;let i=s.response.data;return typeof i?.message=="string"?i.message:null},"extractServerErrorMessage"),t.extractContentDispositionFilename=n(s=>{let i=s["content-disposition"];return i?/filename=["']?([^"';]+)/i.exec(i)?.[1]:void 0},"extractContentDispositionFilename")))(d||(d={}));var k=class k extends Error{constructor(r,o,t){super(r);c(this,"code");c(this,"serverMessage",null);this.code=o,this.serverMessage=t}};n(k,"ApplicationException");var l=k,b=class b{constructor({entries:e,t:r=y,onRethrowError:o}){c(this,"entries",[]);c(this,"t");c(this,"onRethrowError");this.t=r,this.onRethrowError=o;let t={code:"DATA_VALIDATION_ERROR",condition:n(u=>u instanceof z.ZodError,"condition"),getMessage:n(()=>this.t("openapi.sharedErrors.dataValidation"),"getMessage")},s={code:"INTERNAL_ERROR",condition:n(u=>v(u)?u.response?.status!=null&&u.response.status>=500&&u.response.status<600:!1,"condition"),getMessage:n(()=>this.t("openapi.sharedErrors.internalError"),"getMessage")},i={code:"NETWORK_ERROR",condition:n(u=>v(u)?u.code==="ERR_NETWORK":!1,"condition"),getMessage:n(()=>this.t("openapi.sharedErrors.networkError"),"getMessage")},p={code:"CANCELED_ERROR",condition:n(u=>!!(V(u)||v(u)&&u.code==="ECONNABORTED"),"condition"),getMessage:n(()=>this.t("openapi.sharedErrors.canceledError"),"getMessage")},f={code:"UNKNOWN_ERROR",condition:n(()=>!0,"condition"),getMessage:n((u,E)=>{let R=d.extractServerResponseCode(E),m=d.extractServerErrorMessage(E);if(R){let g=`Unknown error, message from server: ${R}`;return m&&(g+=` ${m}`),g}return this.t("openapi.sharedErrors.unknownError")},"getMessage")};this.entries=[...e,t,s,i,p,f]}matchesEntry(e,r,o){return r.condition?r.condition(e):o===r.code}setTranslateFunction(e){this.t=e}rethrowError(e){let r=d.extractServerResponseCode(e),o=this.entries.find(i=>this.matchesEntry(e,i,r)),t=d.extractServerErrorMessage(e),s=new l(o.getMessage(this.t,e),o.code,t);throw this.onRethrowError?.(e,s),s}getError(e){return e instanceof l?e:null}getErrorCode(e){return e instanceof l?e.code:null}static getErrorMessage(e,r=!0){return typeof e=="string"?e:e instanceof Error||e instanceof l?e.message:r?y("openapi.sharedErrors.unknownError"):null}};n(b,"ErrorHandler");var I=b,A=new I({entries:[]});var O=class O{constructor({config:e,interceptors:r,errorHandler:o}={}){c(this,"client");c(this,"errorHandler");this.client=K.create(e),this.errorHandler=o??A,this.attachInterceptors(r)}attachInterceptors(e,...r){e?.forEach(o=>this.attachInterceptor(o,...r))}attachInterceptor(e,...r){e.addInterceptor(this.client,...r)}ejectInterceptor(e){e.removeInterceptor(this.client)}async get(e,r,o){return this.makeRequest(e,{...o,method:"get",url:r})}async post(e,r,o,t){return this.makeRequest(e,{...t,method:"post",url:r,data:o})}async patch(e,r,o,t){return this.makeRequest(e,{...t,method:"patch",url:r,data:o})}async put(e,r,o,t){return this.makeRequest(e,{...t,method:"put",url:r,data:o})}async delete(e,r,o,t){return this.makeRequest(e,{...t,method:"delete",url:r,data:o})}async makeRequest(e,r){let o=new Error().stack;try{let{rawResponse:t,...s}=r,i=await this.client(s),p=e.resSchema.parse(i.data);return t?{...i,data:p}:p}catch(t){throw t instanceof B.ZodError&&(t.name="BE Response schema mismatch - ZodError",t.stack=[t.stack,...o?.split(`
2
2
  `).slice(2)??[]].join(`
3
- `)),(e.errorHandler??this.errorHandler).rethrowError(t),t}}};n(O,"RestClient");var P=O;var M=class M{constructor(e){this.applyInterceptor=e;c(this,"interceptorIdMap",[])}addInterceptor(e,...r){this.removeInterceptor(e);let o=this.applyInterceptor(e,...r);this.interceptorIdMap.push({client:e,interceptorId:o})}removeInterceptor(e){let r=this.interceptorIdMap.find(o=>o.client===e)?.interceptorId;r!=null&&(e.interceptors.request.eject(r),this.interceptorIdMap=this.interceptorIdMap.filter(o=>o.client!==e))}};n(M,"RestInterceptor");var q=M;import{createContext as B,use as $,useMemo as J}from"react";import{jsx as Q}from"react/jsx-runtime";var x;(o=>{let a=B(null);o.Provider=n(({children:t,replace:s})=>{let i=J(()=>({replace:s}),[s]);return Q(a,{value:i,children:t})},"Provider"),o.useRouter=n(()=>{let t=$(a);if(!t)throw new Error("useRouter must be used within an OpenApiRouter.Provider");return t},"useRouter")})(x||(x={}));import{createContext as X,use as Y,useMemo as ee}from"react";import{jsx as re}from"react/jsx-runtime";var N;(o=>{let a=X({});o.Provider=n(({preferUpdate:t=!0,children:s})=>{let i=ee(()=>({preferUpdate:t}),[t]);return re(a.Provider,{value:i,children:s})},"Provider"),o.useConfig=n(()=>Y(a)??{},"useConfig")})(N||(N={}));import{createContext as te,use as oe,useMemo as ne}from"react";import{jsx as se}from"react/jsx-runtime";var h;(o=>{let a=te({});o.Provider=n(({isAuthenticated:t,isInitializing:s,logout:i,updateTokens:p,accessToken:f,user:u,userPromise:E,routes:R,loadingState:m,children:g})=>{let j=ne(()=>({isAuthenticated:t,isInitializing:s,logout:i,updateTokens:p,accessToken:f,user:u,userPromise:E,routes:R,loadingState:m}),[t,s,i,p,f,u,E,R,m]);return se(a.Provider,{value:j,children:g})},"Provider"),o.useAuth=n(()=>oe(a),"useAuth")})(h||(h={}));import{useEffect as ie,useState as ae}from"react";var ue=n(({type:a,redirectTo:e,children:r})=>{let{isAuthenticated:o,routes:t,loadingState:s}=h.useAuth(),{replace:i}=x.useRouter(),[p,f]=ae(!1);return ie(()=>{f(!0)},[]),p?a==="private"&&!o?(i(e||t?.unauthenticated||"/"),null):a==="public-only"&&o?(i(e||t?.authenticated||"/"),null):r:s},"AuthGuard");export{l as ApplicationException,h as AuthContext,ue as AuthGuard,T as ErrorHandler,N as OpenApiQueryConfig,x as OpenApiRouter,P as RestClient,q as RestInterceptor,d as RestUtils,A as SharedErrorHandler,C as ns,w as resources};
3
+ `)),(e.errorHandler??this.errorHandler).rethrowError(t),t}}};n(O,"RestClient");var P=O;var M=class M{constructor(e){this.applyInterceptor=e;c(this,"interceptorIdMap",[])}addInterceptor(e,...r){this.removeInterceptor(e);let o=this.applyInterceptor(e,...r);this.interceptorIdMap.push({client:e,interceptorId:o})}removeInterceptor(e){let r=this.interceptorIdMap.find(o=>o.client===e)?.interceptorId;r!=null&&(e.interceptors.request.eject(r),this.interceptorIdMap=this.interceptorIdMap.filter(o=>o.client!==e))}};n(M,"RestInterceptor");var q=M;import{createContext as $,use as J,useMemo as Q}from"react";import{jsx as X}from"react/jsx-runtime";var h;(o=>{let a=$(null);o.Provider=n(({children:t,replace:s})=>{let i=Q(()=>({replace:s}),[s]);return X(a,{value:i,children:t})},"Provider"),o.useRouter=n(()=>{let t=J(a);if(!t)throw new Error("useRouter must be used within an OpenApiRouter.Provider");return t},"useRouter")})(h||(h={}));import{createContext as Y,use as ee,useMemo as re}from"react";import{jsx as te}from"react/jsx-runtime";var N;(o=>{let a=Y({});o.Provider=n(({preferUpdate:t=!0,children:s})=>{let i=re(()=>({preferUpdate:t}),[t]);return te(a.Provider,{value:i,children:s})},"Provider"),o.useConfig=n(()=>ee(a)??{},"useConfig")})(N||(N={}));import{createContext as oe,use as ne,useMemo as se}from"react";import{jsx as ie}from"react/jsx-runtime";var x;(o=>{let a=oe({});o.Provider=n(({isAuthenticated:t,isInitializing:s,logout:i,updateTokens:p,accessToken:f,user:u,userPromise:E,routes:R,loadingState:m,children:g})=>{let j=se(()=>({isAuthenticated:t,isInitializing:s,logout:i,updateTokens:p,accessToken:f,user:u,userPromise:E,routes:R,loadingState:m}),[t,s,i,p,f,u,E,R,m]);return ie(a.Provider,{value:j,children:g})},"Provider"),o.useAuth=n(()=>ne(a),"useAuth")})(x||(x={}));import{useEffect as ae,useState as ue}from"react";var pe=n(({type:a,redirectTo:e,children:r})=>{let{isAuthenticated:o,routes:t,loadingState:s}=x.useAuth(),{replace:i}=h.useRouter(),[p,f]=ue(!1);return ae(()=>{f(!0)},[]),p?a==="private"&&!o?(i(e||t?.unauthenticated||"/"),null):a==="public-only"&&o?(i(e||t?.authenticated||"/"),null):r:s},"AuthGuard");export{l as ApplicationException,x as AuthContext,pe as AuthGuard,I as ErrorHandler,N as OpenApiQueryConfig,h as OpenApiRouter,P as RestClient,q as RestInterceptor,d as RestUtils,A as SharedErrorHandler,C as ns,T as resources};
@@ -1,6 +1,6 @@
1
+ import { type PropsWithChildren } from "react";
1
2
  import { type PureAbility, type RawRuleOf } from "@casl/ability";
2
3
  import { type PackRule } from "@casl/ability/extra";
3
- import { type PropsWithChildren } from "react";
4
4
  import type { AppAbilities, AppAbility } from "./appAbility.types";
5
5
  export declare namespace AbilityContext {
6
6
  export const Consumer: import("react").Consumer<AppAbility>;
@@ -10,6 +10,6 @@ export declare namespace AbilityContext {
10
10
  } | null;
11
11
  }
12
12
  export const Provider: ({ children }: PropsWithChildren<ProviderProps>) => import("react/jsx-runtime").JSX.Element;
13
- export const useAbility: <TAppAbilities extends AppAbilities = AppAbilities>() => PureAbility<TAppAbilities, unknown>;
13
+ export const useAbility: <TAppAbilities extends AppAbilities = AppAbilities>() => PureAbility<TAppAbilities>;
14
14
  export {};
15
15
  }
@@ -1,7 +1,7 @@
1
1
  import { AxiosRequestConfig, CreateAxiosDefaults } from "axios";
2
2
  import { ErrorHandler, GeneralErrorCodes } from "./error-handling";
3
- import { RestInterceptor } from "./rest-interceptor";
4
3
  import { RestClient as IRestClient, RequestConfig, RequestInfo, Response } from "./rest-client.types";
4
+ import { RestInterceptor } from "./rest-interceptor";
5
5
  export declare class RestClient implements IRestClient {
6
6
  private readonly client;
7
7
  private readonly errorHandler;