@povio/openapi-codegen-cli 2.0.8-rc.16 → 2.0.8-rc.18
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/acl.d.mts +12 -1
- package/dist/acl.mjs +13 -3
- package/dist/auth.context-HV1I5QMx.mjs +244 -0
- package/dist/{config-Cu_GYfai.d.mts → config-B4HK4BLi.d.mts} +1 -1
- package/dist/error-handling-p69GkKGP.d.mts +38 -0
- package/dist/{generate.runner-DF2eZ4P-.mjs → generate.runner-C93djZ78.mjs} +1 -1
- package/dist/{generateCodeFromOpenAPIDoc-ao1R1u57.mjs → generateCodeFromOpenAPIDoc-BP7F6YJP.mjs} +46 -214
- package/dist/generator.d.mts +1 -1
- package/dist/generator.mjs +1 -1
- package/dist/index.d.mts +43 -59
- package/dist/index.mjs +74 -189
- package/dist/sh.mjs +3 -3
- package/dist/vite.d.mts +2 -2
- package/dist/vite.mjs +2 -2
- package/package.json +5 -1
- package/dist/auth.context-DKjzWiaA.mjs +0 -59
- package/src/assets/useCrossTabQueryInvalidation.ts +0 -40
- package/src/assets/useMutationEffects.ts +0 -94
- /package/dist/{options-DBz5YE3s.d.mts → options-Bvmh6rai.d.mts} +0 -0
package/dist/acl.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { r as ErrorHandler } from "./error-handling-p69GkKGP.mjs";
|
|
1
2
|
import * as react from "react";
|
|
2
3
|
import { PropsWithChildren } from "react";
|
|
3
4
|
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
@@ -45,4 +46,14 @@ declare const Can: <TAppAbilities extends AppAbilities = AppAbilities>({
|
|
|
45
46
|
...props
|
|
46
47
|
}: CanProps<TAppAbilities>) => react_jsx_runtime0.JSX.Element;
|
|
47
48
|
//#endregion
|
|
48
|
-
|
|
49
|
+
//#region src/lib/acl/useAclCheck.d.ts
|
|
50
|
+
interface UseAclCheckProps {
|
|
51
|
+
errorHandler?: ErrorHandler<never>;
|
|
52
|
+
}
|
|
53
|
+
declare function useAclCheck<TAppAbilities extends AppAbilities = AppAbilities>({
|
|
54
|
+
errorHandler
|
|
55
|
+
}?: UseAclCheckProps): {
|
|
56
|
+
checkAcl: (appAbility: TAppAbilities) => void;
|
|
57
|
+
};
|
|
58
|
+
//#endregion
|
|
59
|
+
export { AbilityContext, type AppAbilities, type AppAbility, Can, createAclGuard, useAclCheck };
|
package/dist/acl.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as OpenApiRouter, t as AuthContext } from "./auth.context-
|
|
2
|
-
import { createContext, useEffect, useState } from "react";
|
|
1
|
+
import { a as SharedErrorHandler, n as OpenApiRouter, t as AuthContext } from "./auth.context-HV1I5QMx.mjs";
|
|
2
|
+
import { createContext, useCallback, useEffect, useState } from "react";
|
|
3
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
4
|
import { AbilityBuilder, createMongoAbility } from "@casl/ability";
|
|
5
5
|
import { unpackRules } from "@casl/ability/extra";
|
|
@@ -60,4 +60,14 @@ const Can = ({ use, ...props }) => {
|
|
|
60
60
|
};
|
|
61
61
|
|
|
62
62
|
//#endregion
|
|
63
|
-
|
|
63
|
+
//#region src/lib/acl/useAclCheck.ts
|
|
64
|
+
function useAclCheck({ errorHandler } = {}) {
|
|
65
|
+
const ability = AbilityContext.useAbility();
|
|
66
|
+
return { checkAcl: useCallback((appAbility) => {
|
|
67
|
+
const can = ability.can;
|
|
68
|
+
if (!can(...appAbility)) (errorHandler ?? SharedErrorHandler).rethrowError(/* @__PURE__ */ new Error("ACL check failed"));
|
|
69
|
+
}, [ability, errorHandler]) };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
//#endregion
|
|
73
|
+
export { AbilityContext, Can, createAclGuard, useAclCheck };
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { isAxiosError, isCancel } from "axios";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import i18next from "i18next";
|
|
4
|
+
import { createContext, use, useMemo } from "react";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
|
|
7
|
+
//#region src/lib/assets/locales/en/translation.json
|
|
8
|
+
var translation_default$1 = { openapi: { "sharedErrors": {
|
|
9
|
+
"dataValidation": "An error occurred while validating the data",
|
|
10
|
+
"internalError": "An internal error occurred. This is most likely a bug on our end. Please try again later.",
|
|
11
|
+
"networkError": "A network error occurred. Are you connected to the internet?",
|
|
12
|
+
"canceledError": "The request was canceled.",
|
|
13
|
+
"unknownError": "An unknown error occurred. Please try again later.",
|
|
14
|
+
"unknownErrorWithCode": "An unknown error occurred. Error code: \"{{code}}\""
|
|
15
|
+
} } };
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
//#region src/lib/assets/locales/sl/translation.json
|
|
19
|
+
var translation_default = { openapi: { "sharedErrors": {
|
|
20
|
+
"dataValidation": "Pri preverjanju podatkov je prišlo do napake",
|
|
21
|
+
"internalError": "Prišlo je do notranje napake.",
|
|
22
|
+
"networkError": "Prišlo je do napake v omrežju.",
|
|
23
|
+
"canceledError": "Zahteva je bila preklicana.",
|
|
24
|
+
"unknownError": "Prišlo je do neznane napake.",
|
|
25
|
+
"unknownErrorWithCode": "Prišlo je do neznane napake. Koda napake: \"{{code}}\""
|
|
26
|
+
} } };
|
|
27
|
+
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/lib/config/i18n.ts
|
|
30
|
+
const ns = "openapi";
|
|
31
|
+
const resources = {
|
|
32
|
+
en: { [ns]: translation_default$1 },
|
|
33
|
+
sl: { [ns]: translation_default }
|
|
34
|
+
};
|
|
35
|
+
const defaultLanguage = "en";
|
|
36
|
+
const i18n = i18next.createInstance();
|
|
37
|
+
i18n.init({
|
|
38
|
+
compatibilityJSON: "v4",
|
|
39
|
+
lng: defaultLanguage,
|
|
40
|
+
fallbackLng: defaultLanguage,
|
|
41
|
+
resources,
|
|
42
|
+
ns: Object.keys(resources.en),
|
|
43
|
+
defaultNS: ns,
|
|
44
|
+
interpolation: { escapeValue: false }
|
|
45
|
+
});
|
|
46
|
+
const defaultT = i18n.t.bind(i18n);
|
|
47
|
+
|
|
48
|
+
//#endregion
|
|
49
|
+
//#region src/lib/rest/rest.utils.ts
|
|
50
|
+
let RestUtils;
|
|
51
|
+
(function(_RestUtils) {
|
|
52
|
+
_RestUtils.extractServerResponseCode = (e) => {
|
|
53
|
+
if (e instanceof z.ZodError) return "validation-exception";
|
|
54
|
+
if (!isAxiosError(e)) return null;
|
|
55
|
+
if (!e.response) return null;
|
|
56
|
+
const data = e.response.data;
|
|
57
|
+
if (typeof data?.code === "string") return data.code;
|
|
58
|
+
return null;
|
|
59
|
+
};
|
|
60
|
+
_RestUtils.doesServerErrorMessageContain = (e, text) => {
|
|
61
|
+
const message = extractServerErrorMessage(e);
|
|
62
|
+
if (message === null || message === void 0) return false;
|
|
63
|
+
return message.toLowerCase().includes(text.toLowerCase());
|
|
64
|
+
};
|
|
65
|
+
const extractServerErrorMessage = _RestUtils.extractServerErrorMessage = (e) => {
|
|
66
|
+
if (e instanceof z.ZodError) return e.message;
|
|
67
|
+
if (!isAxiosError(e)) return null;
|
|
68
|
+
if (!e.response) return null;
|
|
69
|
+
const data = e.response.data;
|
|
70
|
+
if (typeof data?.message === "string") return data.message;
|
|
71
|
+
return null;
|
|
72
|
+
};
|
|
73
|
+
_RestUtils.extractContentDispositionFilename = (headers) => {
|
|
74
|
+
const contentDisposition = headers["content-disposition"];
|
|
75
|
+
return contentDisposition ? /filename=["']?([^"';]+)/i.exec(contentDisposition)?.[1] : void 0;
|
|
76
|
+
};
|
|
77
|
+
})(RestUtils || (RestUtils = {}));
|
|
78
|
+
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region src/lib/rest/error-handling.ts
|
|
81
|
+
var ApplicationException = class extends Error {
|
|
82
|
+
code;
|
|
83
|
+
serverMessage = null;
|
|
84
|
+
constructor(message, code, serverMessage) {
|
|
85
|
+
super(message);
|
|
86
|
+
this.code = code;
|
|
87
|
+
this.serverMessage = serverMessage;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
var ErrorHandler = class {
|
|
91
|
+
entries = [];
|
|
92
|
+
t;
|
|
93
|
+
onRethrowError;
|
|
94
|
+
constructor({ entries, t = defaultT, onRethrowError }) {
|
|
95
|
+
this.t = t;
|
|
96
|
+
this.onRethrowError = onRethrowError;
|
|
97
|
+
const dataValidationError = {
|
|
98
|
+
code: "DATA_VALIDATION_ERROR",
|
|
99
|
+
condition: (e) => {
|
|
100
|
+
return e instanceof z.ZodError;
|
|
101
|
+
},
|
|
102
|
+
getMessage: () => this.t("openapi.sharedErrors.dataValidation")
|
|
103
|
+
};
|
|
104
|
+
const internalError = {
|
|
105
|
+
code: "INTERNAL_ERROR",
|
|
106
|
+
condition: (e) => {
|
|
107
|
+
if (isAxiosError(e)) return e.response?.status != null && e.response.status >= 500 && e.response.status < 600;
|
|
108
|
+
return false;
|
|
109
|
+
},
|
|
110
|
+
getMessage: () => this.t("openapi.sharedErrors.internalError")
|
|
111
|
+
};
|
|
112
|
+
const networkError = {
|
|
113
|
+
code: "NETWORK_ERROR",
|
|
114
|
+
condition: (e) => {
|
|
115
|
+
if (isAxiosError(e)) return e.code === "ERR_NETWORK";
|
|
116
|
+
return false;
|
|
117
|
+
},
|
|
118
|
+
getMessage: () => this.t("openapi.sharedErrors.networkError")
|
|
119
|
+
};
|
|
120
|
+
const canceledError = {
|
|
121
|
+
code: "CANCELED_ERROR",
|
|
122
|
+
condition: (e) => {
|
|
123
|
+
if (isCancel(e)) return true;
|
|
124
|
+
if (isAxiosError(e) && e.code === "ECONNABORTED") return true;
|
|
125
|
+
return false;
|
|
126
|
+
},
|
|
127
|
+
getMessage: () => this.t("openapi.sharedErrors.canceledError")
|
|
128
|
+
};
|
|
129
|
+
const unknownError = {
|
|
130
|
+
code: "UNKNOWN_ERROR",
|
|
131
|
+
condition: () => true,
|
|
132
|
+
getMessage: (_, e) => {
|
|
133
|
+
const code = RestUtils.extractServerResponseCode(e);
|
|
134
|
+
const serverMessage = RestUtils.extractServerErrorMessage(e);
|
|
135
|
+
if (code) {
|
|
136
|
+
let message = `Unknown error, message from server: ${code}`;
|
|
137
|
+
if (serverMessage) message += ` ${serverMessage}`;
|
|
138
|
+
return message;
|
|
139
|
+
}
|
|
140
|
+
return this.t("openapi.sharedErrors.unknownError");
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
this.entries = [
|
|
144
|
+
...entries,
|
|
145
|
+
dataValidationError,
|
|
146
|
+
internalError,
|
|
147
|
+
networkError,
|
|
148
|
+
canceledError,
|
|
149
|
+
unknownError
|
|
150
|
+
];
|
|
151
|
+
}
|
|
152
|
+
matchesEntry(error, entry, code) {
|
|
153
|
+
if (entry.condition) return entry.condition(error);
|
|
154
|
+
return code === entry.code;
|
|
155
|
+
}
|
|
156
|
+
setTranslateFunction(t) {
|
|
157
|
+
this.t = t;
|
|
158
|
+
}
|
|
159
|
+
rethrowError(error) {
|
|
160
|
+
const code = RestUtils.extractServerResponseCode(error);
|
|
161
|
+
const errorEntry = this.entries.find((entry) => this.matchesEntry(error, entry, code));
|
|
162
|
+
const serverMessage = RestUtils.extractServerErrorMessage(error);
|
|
163
|
+
const exception = new ApplicationException(errorEntry.getMessage(this.t, error), errorEntry.code, serverMessage);
|
|
164
|
+
this.onRethrowError?.(error, exception);
|
|
165
|
+
throw exception;
|
|
166
|
+
}
|
|
167
|
+
getError(error) {
|
|
168
|
+
if (error instanceof ApplicationException) return error;
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
getErrorCode(error) {
|
|
172
|
+
if (error instanceof ApplicationException) return error.code;
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
static getErrorMessage(error, fallbackToUnknown = true) {
|
|
176
|
+
if (typeof error === "string") return error;
|
|
177
|
+
if (error instanceof Error) return error.message;
|
|
178
|
+
if (error instanceof ApplicationException) {
|
|
179
|
+
if (error.serverMessage != null) return error.serverMessage;
|
|
180
|
+
return error.message;
|
|
181
|
+
}
|
|
182
|
+
if (fallbackToUnknown) return defaultT("openapi.sharedErrors.unknownError");
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
const SharedErrorHandler = new ErrorHandler({ entries: [] });
|
|
187
|
+
|
|
188
|
+
//#endregion
|
|
189
|
+
//#region src/lib/config/router.context.tsx
|
|
190
|
+
let OpenApiRouter;
|
|
191
|
+
(function(_OpenApiRouter) {
|
|
192
|
+
const Context = createContext(null);
|
|
193
|
+
_OpenApiRouter.Provider = ({ children, replace }) => {
|
|
194
|
+
return /* @__PURE__ */ jsx(Context, {
|
|
195
|
+
value: useMemo(() => ({ replace }), [replace]),
|
|
196
|
+
children
|
|
197
|
+
});
|
|
198
|
+
};
|
|
199
|
+
_OpenApiRouter.useRouter = () => {
|
|
200
|
+
const context = use(Context);
|
|
201
|
+
if (!context) throw new Error("useRouter must be used within an OpenApiRouter.Provider");
|
|
202
|
+
return context;
|
|
203
|
+
};
|
|
204
|
+
})(OpenApiRouter || (OpenApiRouter = {}));
|
|
205
|
+
|
|
206
|
+
//#endregion
|
|
207
|
+
//#region src/lib/auth/auth.context.tsx
|
|
208
|
+
let AuthContext;
|
|
209
|
+
(function(_AuthContext) {
|
|
210
|
+
const Context = createContext({});
|
|
211
|
+
_AuthContext.Provider = ({ isAuthenticated, isInitializing, logout, updateTokens, accessToken, user, userPromise, routes, loadingState, children }) => {
|
|
212
|
+
const value = useMemo(() => ({
|
|
213
|
+
isAuthenticated,
|
|
214
|
+
isInitializing,
|
|
215
|
+
logout,
|
|
216
|
+
updateTokens,
|
|
217
|
+
accessToken,
|
|
218
|
+
user,
|
|
219
|
+
userPromise,
|
|
220
|
+
routes,
|
|
221
|
+
loadingState
|
|
222
|
+
}), [
|
|
223
|
+
isAuthenticated,
|
|
224
|
+
isInitializing,
|
|
225
|
+
logout,
|
|
226
|
+
updateTokens,
|
|
227
|
+
accessToken,
|
|
228
|
+
user,
|
|
229
|
+
userPromise,
|
|
230
|
+
routes,
|
|
231
|
+
loadingState
|
|
232
|
+
]);
|
|
233
|
+
return /* @__PURE__ */ jsx(Context.Provider, {
|
|
234
|
+
value,
|
|
235
|
+
children
|
|
236
|
+
});
|
|
237
|
+
};
|
|
238
|
+
_AuthContext.useAuth = () => {
|
|
239
|
+
return use(Context);
|
|
240
|
+
};
|
|
241
|
+
})(AuthContext || (AuthContext = {}));
|
|
242
|
+
|
|
243
|
+
//#endregion
|
|
244
|
+
export { SharedErrorHandler as a, resources as c, ErrorHandler as i, OpenApiRouter as n, RestUtils as o, ApplicationException as r, ns as s, AuthContext as t };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { TFunction } from "i18next";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/rest/error-handling.d.ts
|
|
4
|
+
type GeneralErrorCodes = "DATA_VALIDATION_ERROR" | "NETWORK_ERROR" | "CANCELED_ERROR" | "INTERNAL_ERROR" | "UNKNOWN_ERROR";
|
|
5
|
+
declare class ApplicationException<CodeT> extends Error {
|
|
6
|
+
code: CodeT;
|
|
7
|
+
serverMessage: string | null;
|
|
8
|
+
constructor(message: string, code: CodeT, serverMessage: string | null);
|
|
9
|
+
}
|
|
10
|
+
interface ErrorEntry<CodeT> {
|
|
11
|
+
code: CodeT;
|
|
12
|
+
condition?: (error: unknown) => boolean;
|
|
13
|
+
getMessage: (t: TFunction, error: unknown) => string;
|
|
14
|
+
}
|
|
15
|
+
interface ErrorHandlerOptions<CodeT extends string> {
|
|
16
|
+
entries: ErrorEntry<CodeT>[];
|
|
17
|
+
t?: TFunction;
|
|
18
|
+
onRethrowError?: (error: unknown, exception: ApplicationException<CodeT | GeneralErrorCodes>) => void;
|
|
19
|
+
}
|
|
20
|
+
declare class ErrorHandler<CodeT extends string> {
|
|
21
|
+
entries: ErrorEntry<CodeT | GeneralErrorCodes>[];
|
|
22
|
+
private t;
|
|
23
|
+
private onRethrowError?;
|
|
24
|
+
constructor({
|
|
25
|
+
entries,
|
|
26
|
+
t,
|
|
27
|
+
onRethrowError
|
|
28
|
+
}: ErrorHandlerOptions<CodeT>);
|
|
29
|
+
private matchesEntry;
|
|
30
|
+
setTranslateFunction(t: TFunction): void;
|
|
31
|
+
rethrowError(error: unknown): ApplicationException<CodeT | GeneralErrorCodes>;
|
|
32
|
+
getError(error: unknown): ApplicationException<CodeT | GeneralErrorCodes> | null;
|
|
33
|
+
getErrorCode(error: unknown): CodeT | GeneralErrorCodes | null;
|
|
34
|
+
static getErrorMessage(error: unknown, fallbackToUnknown?: boolean): string | null;
|
|
35
|
+
}
|
|
36
|
+
declare const SharedErrorHandler: ErrorHandler<never>;
|
|
37
|
+
//#endregion
|
|
38
|
+
export { GeneralErrorCodes as a, ErrorHandlerOptions as i, ErrorEntry as n, SharedErrorHandler as o, ErrorHandler as r, ApplicationException as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as deepMerge, p as DEFAULT_GENERATE_OPTIONS, r as writeGenerateFileData, t as generateCodeFromOpenAPIDoc, x as Profiler } from "./generateCodeFromOpenAPIDoc-
|
|
1
|
+
import { a as deepMerge, p as DEFAULT_GENERATE_OPTIONS, r as writeGenerateFileData, t as generateCodeFromOpenAPIDoc, x as Profiler } from "./generateCodeFromOpenAPIDoc-BP7F6YJP.mjs";
|
|
2
2
|
import fs from "fs";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import SwaggerParser from "@apidevtools/swagger-parser";
|