@povio/openapi-codegen-cli 3.3.0-rc.1 → 3.3.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.
- package/README.md +125 -9
- package/dist/AuthGuard-GbtTDXs0.d.mts +32 -0
- package/dist/AuthGuard-qpAtHaBz.mjs +24 -0
- package/dist/acl.d.mts +6 -19
- package/dist/acl.mjs +7 -7
- package/dist/{auth.context-BAz8frX9.mjs → auth.context-COWO6ssl.mjs} +1 -18
- package/dist/auth.d.mts +2 -0
- package/dist/auth.mjs +3 -0
- package/dist/axios.d.mts +2 -0
- package/dist/axios.mjs +2 -0
- package/dist/{config-BQqze8rU.d.mts → config-FD2Y872S.d.mts} +1 -2
- package/dist/config.d.mts +4 -0
- package/dist/config.mjs +5 -0
- package/dist/{error-handling-D6ZYITQ3.d.mts → error-handling-LPEPQV1V.d.mts} +3 -42
- package/dist/{error-handling-CsnufAil.mjs → error-handling-uS0DgYUR.mjs} +23 -47
- package/dist/errors.d.mts +3 -0
- package/dist/errors.mjs +2 -0
- package/dist/generate.runner-CLK1FoLT.mjs +1669 -0
- package/dist/generate.utils-BSDYGp-0.cjs +2270 -0
- package/dist/{generateCodeFromOpenAPIDoc-KQT4kYxY.mjs → generateCodeFromOpenAPIDoc-BypeVKIE.cjs} +1497 -2258
- package/dist/generateCodeFromOpenAPIDoc-CDyGSv2w.mjs +2242 -0
- package/dist/generator.d.mts +3 -10
- package/dist/generator.mjs +6 -4
- package/dist/getDataFromOpenAPIDoc-DYiCTWno.mjs +2016 -0
- package/dist/i18n-B_brQh4X.d.mts +38 -0
- package/dist/i18n-D-FesqFb.mjs +36 -0
- package/dist/index.d.mts +12 -198
- package/dist/index.mjs +12 -256
- package/dist/metro.cjs +118 -4861
- package/dist/metro.d.mts +3 -4
- package/dist/metro.mjs +3 -3
- package/dist/native-rest-interceptor-Np4Ov54n.mjs +215 -0
- package/dist/native-rest-interceptor-PgziZt1f.d.mts +49 -0
- package/dist/native.d.mts +3 -0
- package/dist/native.mjs +3 -0
- package/dist/openapi-codegen-native-darwin-arm64.node +0 -0
- package/dist/openapi-codegen-native-linux-x64.node +0 -0
- package/dist/openapi-codegen-native-win32-x64.node +0 -0
- package/dist/{openapi-codegen.runner-nPBssrBL.mjs → openapi-codegen.runner-DUqQD2B5.mjs} +2 -2
- package/dist/{openapi-source.runner-B6KKrXw7.d.mts → openapi-source.runner-Bje-tMOV.d.mts} +2 -8
- package/dist/{openapi-source.runner-8kCe-g9S.mjs → openapi-source.runner-DPUNTduQ.mjs} +25 -11
- package/dist/{options-DdQJ9BSc.d.mts → options-rz2bcsaN.d.mts} +10 -1
- package/dist/query.d.mts +3 -0
- package/dist/query.mjs +3 -0
- package/dist/queryConfig.context-CRJOgf19.d.mts +22 -0
- package/dist/queryConfig.context-CldQ5YL9.mjs +34 -0
- package/dist/rest-client-CQyFvqYC.d.mts +55 -0
- package/dist/rest-interceptor-Dm9DFErh.mjs +115 -0
- package/dist/rest-transport.types-DM5-qyOJ.d.mts +66 -0
- package/dist/rest-transport.types-DxitRtsB.mjs +11 -0
- package/dist/rest.d.mts +2 -0
- package/dist/rest.mjs +2 -0
- package/dist/rest.utils-DpiFIdhF.d.mts +9 -0
- package/dist/router.context-EPlMBk3G.mjs +21 -0
- package/dist/sh.d.mts +1 -1
- package/dist/sh.mjs +50 -55
- package/dist/tiny.d.mts +1 -1
- package/dist/tiny.mjs +1 -1
- package/dist/useMutationEffects-DIdL8tlx.d.mts +29 -0
- package/dist/useMutationEffects-PB1fvKWM.mjs +68 -0
- package/dist/vite.d.mts +3 -4
- package/dist/vite.mjs +5 -4
- package/dist/workspace.context-XWvQ_7Hg.mjs +26 -0
- package/dist/workspace.context-isVY9ves.d.mts +23 -0
- package/dist/zod.d.mts +2 -7
- package/dist/zod.mjs +1 -1
- package/package.json +67 -19
- package/dist/generate.runner-BeCGJ1ar.mjs +0 -87
package/README.md
CHANGED
|
@@ -4,9 +4,11 @@
|
|
|
4
4
|
|
|
5
5
|
**NOTE:** Version 1+ requires zod v4 and is not compatible with zod v3.
|
|
6
6
|
|
|
7
|
-
**NOTE:**
|
|
7
|
+
**NOTE:** The package includes supporting classes, types, components, and auth utilities. Zod is a required peer dependency. Axios, @tanstack/react-query, react, i18next, @casl/ability, @casl/react, and Vite are optional peers; install the ones used by your chosen features.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Axios is required when using the Axios transport (the default) or the `/axios` entry point. Projects using the native transport can omit Axios: generate with `--restClient native` and import `NativeRestClient` from `@povio/openapi-codegen-cli/native`. The root exports remain available for compatibility and support tree-shaking in consumer bundles. For direct runtime imports without bundling, use `/native` and `/errors` to avoid loading the Axios client. The `/axios` entry point is also available for Axios-specific imports. CLI-only usage and the `/generator`, `/tiny`, `/vite`, and `/metro` entry points do not require Axios.
|
|
10
|
+
|
|
11
|
+
Use this tool to generate code (Zod schemas, TypeScript types, API definitions, and React queries) from an OpenAPI v3 specification. API definitions use a REST client wrapper with either Axios or the native transport. React queries are generated in alignment with our code standards, without the need for explicit types.
|
|
10
12
|
|
|
11
13
|
The tool partially leverages code from [openapi-zod-client](https://github.com/astahmer/openapi-zod-client) repository.
|
|
12
14
|
|
|
@@ -22,6 +24,43 @@ bun add @povio/openapi-codegen-cli
|
|
|
22
24
|
bunx openapi-codegen generate --input http://localhost:3001/docs-json
|
|
23
25
|
```
|
|
24
26
|
|
|
27
|
+
## Schema compilation
|
|
28
|
+
|
|
29
|
+
Generated models use ordinary Zod schemas by default, preserving validation without the startup work of explicit `z.compile(...)` calls. Regenerate existing clients to remove previously emitted compilation calls. A frontend entry-point `import "zod/compile"` used solely for these generated models can then be removed.
|
|
30
|
+
|
|
31
|
+
Set `compileSchemas: true` in your generator configuration (or pass `--compileSchemas`) to opt into eager compilation for non-recursive schemas. This trades initialization time for potential validation throughput improvements. Recursive schemas remain uncompiled. Both the TypeScript and native generators honor this option.
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
export default {
|
|
35
|
+
compileSchemas: false, // Default; normal Zod validation stays enabled.
|
|
36
|
+
};
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Lazy schemas
|
|
40
|
+
|
|
41
|
+
With `tsNamespaces` enabled, every schema of a models namespace is built the moment the module is imported, even when the importer only needs one of them. Set `lazySchemas: true` (or pass `--lazySchemas`) to build each schema on first access instead:
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
// Generated with lazySchemas: true
|
|
45
|
+
const once = <T>(create: () => T) => {
|
|
46
|
+
let value: T | undefined;
|
|
47
|
+
return () => (value ??= create());
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const PetSchema = once(() => z.object({ id: z.int(), category: CategorySchema() }));
|
|
51
|
+
|
|
52
|
+
export const PetModels = {
|
|
53
|
+
get PetSchema() {
|
|
54
|
+
return PetSchema();
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
export declare namespace PetModels {
|
|
58
|
+
export type Pet = z.infer<typeof PetModels.PetSchema>;
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
`PetModels.PetSchema` stays a regular Zod schema (`.extend`, `.shape`, `.pick` all work and return the same instance on every access), `PetModels.Pet` keeps resolving as a type, and `modelsInCommon` proxies forward to the shared namespace lazily as well. The option requires `tsNamespaces` and is honored by both the TypeScript and native generators. It helps cold starts of apps that import large model modules but render only a slice of them.
|
|
63
|
+
|
|
25
64
|
## Configuration Files
|
|
26
65
|
|
|
27
66
|
The CLI supports TypeScript configuration files to simplify command execution and provide consistent settings with full type safety. Configuration files are automatically discovered in your project root.
|
|
@@ -33,7 +72,7 @@ The CLI supports TypeScript configuration files to simplify command execution an
|
|
|
33
72
|
Create an `openapi-codegen.config.ts` file:
|
|
34
73
|
|
|
35
74
|
```typescript
|
|
36
|
-
import { OpenAPICodegenConfig } from "@povio/openapi-codegen-cli";
|
|
75
|
+
import type { OpenAPICodegenConfig } from "@povio/openapi-codegen-cli";
|
|
37
76
|
|
|
38
77
|
const config: OpenAPICodegenConfig = {
|
|
39
78
|
input: "http://localhost:4000/docs-json/",
|
|
@@ -85,11 +124,14 @@ bunx openapi-codegen generate --config my-config.ts
|
|
|
85
124
|
--importPath Module import style for generated files (default: 'ts'; options: 'ts' | 'relative' | 'absolute')
|
|
86
125
|
--tsPath (Requires `--importPath` to be 'ts') Typescript import path (default: '@/data')
|
|
87
126
|
--removeOperationPrefixEndingWith Remove operation name prefixes that end with the specified string (default: 'Controller_')
|
|
127
|
+
--compileSchemas Eagerly compile non-recursive Zod schemas (default: false)
|
|
128
|
+
--lazySchemas Build namespace model schemas on first access instead of at import; requires `--tsNamespaces` (default: false)
|
|
88
129
|
--extractEnums Extract enums into separate Zod schemas (default: true)
|
|
89
130
|
--modelsInCommon Keep all schema declarations in defaultTag models and emit per-module proxy exports (default: false)
|
|
90
131
|
--replaceOptionalWithNullish Replace `.optional()` chains with `.nullish()` in generated Zod schemas (default: false)
|
|
91
132
|
|
|
92
|
-
--
|
|
133
|
+
--restClient REST transport to generate: 'axios' or 'native' (default: 'axios')
|
|
134
|
+
--axiosRequestConfig Include transport request config parameters in query hooks (default: false)
|
|
93
135
|
--infiniteQueries Generate infinite queries for paginated API endpoints (default: false)
|
|
94
136
|
--mutationEffects Add mutation effects options to mutation hooks (default: true)
|
|
95
137
|
--mutationScope Serialize mutations for the same path-param resource via TanStack scope.id (default: false).
|
|
@@ -138,7 +180,7 @@ bun install
|
|
|
138
180
|
# run tests
|
|
139
181
|
bun run test
|
|
140
182
|
|
|
141
|
-
# run sources with
|
|
183
|
+
# run TypeScript sources directly with Bun
|
|
142
184
|
bun run start --help
|
|
143
185
|
bun run start generate --input ./test/petstore.yaml --verbose
|
|
144
186
|
|
|
@@ -150,14 +192,66 @@ bun run start --help
|
|
|
150
192
|
bun run start:dist generate --input ./test/petstore.yaml --verbose
|
|
151
193
|
```
|
|
152
194
|
|
|
195
|
+
### Native Bun code generation
|
|
196
|
+
|
|
197
|
+
The Bun and Node.js CLIs and the Vite plugin automatically use the bundled Rust code-generation core when a compatible native binary is available. Generated files remain byte-for-byte compatible with the TypeScript implementation, which is retained as the fallback when the addon cannot be loaded.
|
|
198
|
+
|
|
199
|
+
Set `OPENAPI_CODEGEN_NATIVE=0` to force the TypeScript path, or `OPENAPI_CODEGEN_NATIVE=1` to require the native path and fail when its binary is unavailable.
|
|
200
|
+
|
|
201
|
+
Release packages include native binaries for Linux x64, macOS arm64, and Windows x64. Build a binary for the current platform with `bun run build:native`.
|
|
202
|
+
|
|
203
|
+
Run `bun run test:parity` after building the addon to compare every generated file across 64 layout combinations and representative values for every other renderer option. The matrix uses both `test/petstore.yaml` and `test/configuration.yaml`, exercises complete native and hybrid native generation, and loads generated models to check runtime references. The contradictory combination `modelsInCommon: true` with `modelsInModules: true` is rejected explicitly. Arbitrary strings and lists are covered by representative cases, not every possible value.
|
|
204
|
+
|
|
205
|
+
The separate Renderer parity workflow generates this matrix with JavaScript and native on Linux and macOS, then compares exact file lists and SHA-256 hashes. Artifacts include route reports identifying complete versus hybrid native generation. Runner integration tests cover input/output, stale-file cleanup, and unchanged files; `incremental` is currently retained as a compatibility option and does not change the writer's unchanged-file optimization.
|
|
206
|
+
|
|
153
207
|
## Common Issues
|
|
154
208
|
|
|
155
209
|
### App REST Client Interceptors
|
|
156
210
|
|
|
211
|
+
Select the fetch-based client without changing endpoint and query APIs:
|
|
212
|
+
|
|
213
|
+
```ts
|
|
214
|
+
import type { OpenAPICodegenConfig } from "@povio/openapi-codegen-cli";
|
|
215
|
+
|
|
216
|
+
export default {
|
|
217
|
+
restClient: "native",
|
|
218
|
+
} satisfies OpenAPICodegenConfig;
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
Native mode imports common request/response contracts from `@povio/openapi-codegen-cli/rest` and the concrete
|
|
222
|
+
`NativeRestClient` from `@povio/openapi-codegen-cli/native`. It uses `fetch` for normal requests and uploads, switching
|
|
223
|
+
to `XMLHttpRequest` in browsers only when an upload progress callback is provided.
|
|
224
|
+
|
|
225
|
+
Native interceptors use the common transport interface:
|
|
226
|
+
|
|
227
|
+
```ts
|
|
228
|
+
import { NativeRestClient } from "@povio/openapi-codegen-cli/native";
|
|
229
|
+
import type { RestTransportInterceptor } from "@povio/openapi-codegen-cli/rest";
|
|
230
|
+
|
|
231
|
+
const authorizationInterceptor: RestTransportInterceptor = {
|
|
232
|
+
onRequest(request) {
|
|
233
|
+
request.headers.set("Authorization", `Bearer ${localStorage.getItem("accessToken")}`);
|
|
234
|
+
return request;
|
|
235
|
+
},
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
export const AppRestClient = new NativeRestClient({
|
|
239
|
+
config: { baseURL: "https://api.example.com" },
|
|
240
|
+
interceptors: [authorizationInterceptor],
|
|
241
|
+
});
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
Axios remains the default for backward compatibility. The existing Axios interceptor API remains available in Axios
|
|
245
|
+
mode.
|
|
246
|
+
|
|
247
|
+
Native mode does not run the library `ErrorHandler` or create `ApplicationException` values. It throws `HttpError` for
|
|
248
|
+
non-success HTTP responses and preserves Zod, network, cancellation, and timeout errors so applications can handle them
|
|
249
|
+
directly in query callbacks, error boundaries, or their own normalization layer.
|
|
250
|
+
|
|
157
251
|
In order to add interceptors to the used REST client, you must create your own instance of a RestClient and pass your implemented interceptors into the constructor. Make sure to set `restClientImportPath` in your openapi generation configuration too.
|
|
158
252
|
|
|
159
253
|
```ts
|
|
160
|
-
import { RestInterceptor } from "@povio/openapi-codegen-cli";
|
|
254
|
+
import { RestInterceptor } from "@povio/openapi-codegen-cli/axios";
|
|
161
255
|
|
|
162
256
|
import { ACCESS_TOKEN_KEY } from "@/config/jwt.config";
|
|
163
257
|
|
|
@@ -174,7 +268,7 @@ export const AuthorizationHeaderInterceptor = new RestInterceptor((client) => {
|
|
|
174
268
|
```
|
|
175
269
|
|
|
176
270
|
```ts
|
|
177
|
-
import { RestClient } from "@povio/openapi-codegen-cli";
|
|
271
|
+
import { RestClient } from "@povio/openapi-codegen-cli/axios";
|
|
178
272
|
|
|
179
273
|
import { AuthorizationHeaderInterceptor } from "@/clients/rest/interceptors/authorization-header.interceptor";
|
|
180
274
|
import { AppConfig } from "@/config/app.config";
|
|
@@ -203,7 +297,8 @@ export default config;
|
|
|
203
297
|
Set `mutationDefaultOnError: true` in codegen config (or pass `--mutationDefaultOnError`) to let generated mutation hooks fall back to `OpenApiQueryConfig.Provider` when a mutation call does not define its own `onError`.
|
|
204
298
|
|
|
205
299
|
```tsx
|
|
206
|
-
import { ErrorHandler
|
|
300
|
+
import { ErrorHandler } from "@povio/openapi-codegen-cli/errors";
|
|
301
|
+
import { OpenApiQueryConfig } from "@povio/openapi-codegen-cli/query";
|
|
207
302
|
|
|
208
303
|
<OpenApiQueryConfig.Provider
|
|
209
304
|
onError={(error) => {
|
|
@@ -229,7 +324,7 @@ Use `OpenApiQueryConfig.Provider` to allow generated GET query hooks to return i
|
|
|
229
324
|
Set `workspaceContext` to a list of param names in codegen config (or pass `--workspaceContext officeId,projectId`) and wrap your app subtree with `OpenApiWorkspaceContext.Provider` if generated hooks frequently repeat workspace-scoped params.
|
|
230
325
|
|
|
231
326
|
```tsx
|
|
232
|
-
import { OpenApiWorkspaceContext } from "@povio/openapi-codegen-cli";
|
|
327
|
+
import { OpenApiWorkspaceContext } from "@povio/openapi-codegen-cli/config";
|
|
233
328
|
// openapi-codegen.config.ts -> { workspaceContext: ["officeId", "projectId"] }
|
|
234
329
|
|
|
235
330
|
<OpenApiWorkspaceContext.Provider values={{ officeId: "office_123" }}>
|
|
@@ -256,6 +351,8 @@ const config: OpenAPICodegenConfig = {
|
|
|
256
351
|
// modelsOnly: true,
|
|
257
352
|
// 4) Keep all model declarations in common.models and generate per-module model proxies
|
|
258
353
|
// modelsInCommon: true,
|
|
354
|
+
// 5) Build each namespace schema on first access instead of at import (requires tsNamespaces)
|
|
355
|
+
// lazySchemas: true,
|
|
259
356
|
};
|
|
260
357
|
```
|
|
261
358
|
|
|
@@ -501,3 +598,22 @@ export class JSONDto {
|
|
|
501
598
|
nested: NestedDto;
|
|
502
599
|
}
|
|
503
600
|
```
|
|
601
|
+
|
|
602
|
+
### Runtime import paths
|
|
603
|
+
|
|
604
|
+
Use package subpaths for runtime imports. Pure `import type` imports may use the package root.
|
|
605
|
+
|
|
606
|
+
| Runtime exports | Subpath |
|
|
607
|
+
| -------------------------------------------------------------------------------------------- | --------- |
|
|
608
|
+
| `AuthContext`, `AuthGuard` | `/auth` |
|
|
609
|
+
| `AbilityContext`, `useAclCheck`, `Can`, `createAclGuard` | `/acl` |
|
|
610
|
+
| `ErrorHandler`, `SharedErrorHandler`, `ApplicationException`, `DomainErrorRegistry` | `/errors` |
|
|
611
|
+
| `useMutationEffects`, `OpenApiQueryConfig` | `/query` |
|
|
612
|
+
| `OpenApiRouter`, `OpenApiWorkspaceContext`, `useWorkspaceContext`, translation configuration | `/config` |
|
|
613
|
+
| `ZodExtended` | `/zod` |
|
|
614
|
+
| `HttpError`, transport types | `/rest` |
|
|
615
|
+
| `NativeRestClient` | `/native` |
|
|
616
|
+
| `RestClient`, `RestInterceptor` (Axios transport) | `/axios` |
|
|
617
|
+
|
|
618
|
+
For example: `import { AuthContext, AuthGuard } from "@povio/openapi-codegen-cli/auth"`.
|
|
619
|
+
Custom application helpers should import error helpers from `/errors`, `AbilityContext` from `/acl`, and mutation effects from `/query`.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { PropsWithChildren, ReactNode } from "react";
|
|
2
|
+
//#region src/lib/auth/auth.context.d.ts
|
|
3
|
+
declare namespace AuthContext {
|
|
4
|
+
export interface Routes {
|
|
5
|
+
authenticated?: string;
|
|
6
|
+
unauthenticated?: string;
|
|
7
|
+
}
|
|
8
|
+
interface Type<TUser = unknown> {
|
|
9
|
+
isAuthenticated: boolean;
|
|
10
|
+
isInitializing: boolean;
|
|
11
|
+
logout: () => void;
|
|
12
|
+
updateTokens?: (accessToken: string | null, refreshToken?: string | null) => void;
|
|
13
|
+
accessToken?: string | null;
|
|
14
|
+
user?: TUser | null;
|
|
15
|
+
userPromise?: () => Promise<TUser | null>;
|
|
16
|
+
routes?: Routes;
|
|
17
|
+
loadingState?: ReactNode;
|
|
18
|
+
}
|
|
19
|
+
type ProviderProps<TUser = unknown> = Type<TUser>;
|
|
20
|
+
export const Provider: <TUser>({ isAuthenticated, isInitializing, logout, updateTokens, accessToken, user, userPromise, routes, loadingState, children }: PropsWithChildren<ProviderProps<TUser>>) => import("react").JSX.Element;
|
|
21
|
+
export const useAuth: <TUser>() => Type<TUser>;
|
|
22
|
+
export {};
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/lib/auth/AuthGuard.d.ts
|
|
26
|
+
interface AuthGuardProps {
|
|
27
|
+
type: "public-only" | "private";
|
|
28
|
+
redirectTo?: string;
|
|
29
|
+
}
|
|
30
|
+
declare const AuthGuard: ({ type, redirectTo, children }: PropsWithChildren<AuthGuardProps>) => import("react").ReactNode;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { AuthGuardProps as n, AuthContext as r, AuthGuard as t };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { t as OpenApiRouter } from "./router.context-EPlMBk3G.mjs";
|
|
2
|
+
import { t as AuthContext } from "./auth.context-COWO6ssl.mjs";
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
//#region src/lib/auth/AuthGuard.tsx
|
|
5
|
+
const AuthGuard = ({ type, redirectTo, children }) => {
|
|
6
|
+
const { isAuthenticated, routes, loadingState } = AuthContext.useAuth();
|
|
7
|
+
const { replace } = OpenApiRouter.useRouter();
|
|
8
|
+
const [hasMounted, setHasMounted] = useState(false);
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
setHasMounted(true);
|
|
11
|
+
}, []);
|
|
12
|
+
if (!hasMounted) return loadingState;
|
|
13
|
+
if (type === "private" && !isAuthenticated) {
|
|
14
|
+
replace(redirectTo || routes?.unauthenticated || "/");
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
if (type === "public-only" && isAuthenticated) {
|
|
18
|
+
replace(redirectTo || routes?.authenticated || "/");
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
return children;
|
|
22
|
+
};
|
|
23
|
+
//#endregion
|
|
24
|
+
export { AuthGuard as t };
|
package/dist/acl.d.mts
CHANGED
|
@@ -1,25 +1,21 @@
|
|
|
1
|
-
import { a as ErrorHandler } from "./error-handling-
|
|
2
|
-
import * as _$react from "react";
|
|
1
|
+
import { a as ErrorHandler } from "./error-handling-LPEPQV1V.mjs";
|
|
3
2
|
import { PropsWithChildren } from "react";
|
|
4
3
|
import { AbilityTuple, PureAbility, RawRuleOf, Subject } from "@casl/ability";
|
|
5
4
|
import { PackRule } from "@casl/ability/extra";
|
|
6
5
|
import { BoundCanProps } from "@casl/react";
|
|
7
|
-
|
|
8
6
|
//#region src/lib/acl/appAbility.types.d.ts
|
|
9
7
|
type AppAbilities = AbilityTuple<string, Subject>;
|
|
10
8
|
type AppAbility = PureAbility<AppAbilities>;
|
|
11
9
|
//#endregion
|
|
12
10
|
//#region src/lib/acl/ability.context.d.ts
|
|
13
11
|
declare namespace AbilityContext {
|
|
14
|
-
export const Consumer:
|
|
12
|
+
export const Consumer: import("react").Consumer<AppAbility>;
|
|
15
13
|
interface ProviderProps {
|
|
16
14
|
user?: {
|
|
17
15
|
aclRules?: PackRule<RawRuleOf<AppAbility>>[];
|
|
18
16
|
} | null;
|
|
19
17
|
}
|
|
20
|
-
export const Provider: ({
|
|
21
|
-
children
|
|
22
|
-
}: PropsWithChildren<ProviderProps>) => _$react.JSX.Element;
|
|
18
|
+
export const Provider: ({ children }: PropsWithChildren<ProviderProps>) => import("react").JSX.Element;
|
|
23
19
|
export const useAbility: <TAppAbilities extends AppAbilities = AppAbilities>() => PureAbility<TAppAbilities>;
|
|
24
20
|
export {};
|
|
25
21
|
}
|
|
@@ -29,29 +25,20 @@ interface AclGuardProps<TAppAbilities extends AppAbilities = AppAbilities> {
|
|
|
29
25
|
canUse: TAppAbilities;
|
|
30
26
|
redirectTo?: string;
|
|
31
27
|
}
|
|
32
|
-
declare const createAclGuard: <TAppAbilities extends AppAbilities = AppAbilities>() => ({
|
|
33
|
-
canUse,
|
|
34
|
-
redirectTo,
|
|
35
|
-
children
|
|
36
|
-
}: PropsWithChildren<AclGuardProps<TAppAbilities>>) => _$react.ReactNode;
|
|
28
|
+
declare const createAclGuard: <TAppAbilities extends AppAbilities = AppAbilities>() => ({ canUse, redirectTo, children }: PropsWithChildren<AclGuardProps<TAppAbilities>>) => import("react").ReactNode;
|
|
37
29
|
//#endregion
|
|
38
30
|
//#region src/lib/acl/Can.d.ts
|
|
39
31
|
type CanAbility = PureAbility<AbilityTuple<AppAbilities[0], AppAbilities[1]>>;
|
|
40
32
|
type CanProps<TAppAbilities extends AppAbilities = AppAbilities> = {
|
|
41
33
|
use: TAppAbilities;
|
|
42
34
|
} & Omit<BoundCanProps<CanAbility>, "do" | "I" | "on" | "a" | "an" | "this">;
|
|
43
|
-
declare const Can: <TAppAbilities extends AppAbilities = AppAbilities>({
|
|
44
|
-
use,
|
|
45
|
-
...props
|
|
46
|
-
}: CanProps<TAppAbilities>) => _$react.JSX.Element;
|
|
35
|
+
declare const Can: <TAppAbilities extends AppAbilities = AppAbilities>({ use, ...props }: CanProps<TAppAbilities>) => import("react").JSX.Element;
|
|
47
36
|
//#endregion
|
|
48
37
|
//#region src/lib/acl/useAclCheck.d.ts
|
|
49
38
|
interface UseAclCheckProps {
|
|
50
39
|
errorHandler?: ErrorHandler<never>;
|
|
51
40
|
}
|
|
52
|
-
declare function useAclCheck<TAppAbilities extends AppAbilities = AppAbilities>({
|
|
53
|
-
errorHandler
|
|
54
|
-
}?: UseAclCheckProps): {
|
|
41
|
+
declare function useAclCheck<TAppAbilities extends AppAbilities = AppAbilities>({ errorHandler }?: UseAclCheckProps): {
|
|
55
42
|
checkAcl: (appAbility: TAppAbilities) => void;
|
|
56
43
|
};
|
|
57
44
|
//#endregion
|
package/dist/acl.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { i as SharedErrorHandler } from "./error-handling-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { i as SharedErrorHandler } from "./error-handling-uS0DgYUR.mjs";
|
|
2
|
+
import { t as OpenApiRouter } from "./router.context-EPlMBk3G.mjs";
|
|
3
|
+
import { t as AuthContext } from "./auth.context-COWO6ssl.mjs";
|
|
4
|
+
import { createContext, useCallback, useMemo } from "react";
|
|
4
5
|
import { jsx } from "react/jsx-runtime";
|
|
5
6
|
import { AbilityBuilder, createMongoAbility } from "@casl/ability";
|
|
6
7
|
import { unpackRules } from "@casl/ability/extra";
|
|
@@ -14,16 +15,15 @@ let AbilityContext;
|
|
|
14
15
|
const { Consumer } = Context;
|
|
15
16
|
_AbilityContext.Consumer = Consumer;
|
|
16
17
|
_AbilityContext.Provider = ({ children }) => {
|
|
17
|
-
const [ability, setAbility] = useState(initialAppAbility);
|
|
18
18
|
const { user } = AuthContext.useAuth();
|
|
19
|
-
|
|
20
|
-
if (!user || !("aclRules" in user)) return;
|
|
19
|
+
const ability = useMemo(() => {
|
|
20
|
+
if (!user || !("aclRules" in user)) return initialAppAbility;
|
|
21
21
|
const { can, build } = createAppAbilityBuilder();
|
|
22
22
|
const packedRules = user.aclRules;
|
|
23
23
|
unpackRules(packedRules).forEach(({ action, subject, conditions }) => {
|
|
24
24
|
can(action, subject, conditions);
|
|
25
25
|
});
|
|
26
|
-
|
|
26
|
+
return build();
|
|
27
27
|
}, [user]);
|
|
28
28
|
return /* @__PURE__ */ jsx(Context.Provider, {
|
|
29
29
|
value: ability,
|
|
@@ -1,22 +1,5 @@
|
|
|
1
1
|
import { createContext, use, useMemo } from "react";
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
|
-
//#region src/lib/config/router.context.tsx
|
|
4
|
-
let OpenApiRouter;
|
|
5
|
-
(function(_OpenApiRouter) {
|
|
6
|
-
const Context = createContext(null);
|
|
7
|
-
_OpenApiRouter.Provider = ({ children, replace }) => {
|
|
8
|
-
return /* @__PURE__ */ jsx(Context, {
|
|
9
|
-
value: useMemo(() => ({ replace }), [replace]),
|
|
10
|
-
children
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
_OpenApiRouter.useRouter = () => {
|
|
14
|
-
const context = use(Context);
|
|
15
|
-
if (!context) throw new Error("useRouter must be used within an OpenApiRouter.Provider");
|
|
16
|
-
return context;
|
|
17
|
-
};
|
|
18
|
-
})(OpenApiRouter || (OpenApiRouter = {}));
|
|
19
|
-
//#endregion
|
|
20
3
|
//#region src/lib/auth/auth.context.tsx
|
|
21
4
|
let AuthContext;
|
|
22
5
|
(function(_AuthContext) {
|
|
@@ -53,4 +36,4 @@ let AuthContext;
|
|
|
53
36
|
};
|
|
54
37
|
})(AuthContext || (AuthContext = {}));
|
|
55
38
|
//#endregion
|
|
56
|
-
export {
|
|
39
|
+
export { AuthContext as t };
|
package/dist/auth.d.mts
ADDED
package/dist/auth.mjs
ADDED
package/dist/axios.d.mts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as RestClient, i as Response, n as RequestConfig, o as RestInterceptor, r as RequestInfo, t as RestClient$1 } from "./rest-client-CQyFvqYC.mjs";
|
|
2
|
+
export { type RestClient as IRestClient, type RequestConfig, type RequestInfo, type Response, RestClient$1 as RestClient, RestInterceptor };
|
package/dist/axios.mjs
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { i as resources, n as configureTranslations, r as ns, t as TranslateFunction } from "./i18n-B_brQh4X.mjs";
|
|
2
|
+
import { n as useWorkspaceContext, r as OpenApiRouter, t as OpenApiWorkspaceContext } from "./workspace.context-isVY9ves.mjs";
|
|
3
|
+
import { i as QueryModule, n as InvalidationMapFunc, r as OpenApiQueryConfig, t as InvalidationMap } from "./queryConfig.context-CRJOgf19.mjs";
|
|
4
|
+
export { type InvalidationMap, type InvalidationMapFunc, OpenApiQueryConfig, OpenApiRouter, OpenApiWorkspaceContext, type QueryModule, type TranslateFunction, configureTranslations, ns, resources, useWorkspaceContext };
|
package/dist/config.mjs
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { i as resources, n as ns, t as configureTranslations } from "./i18n-D-FesqFb.mjs";
|
|
2
|
+
import { t as OpenApiQueryConfig } from "./queryConfig.context-CldQ5YL9.mjs";
|
|
3
|
+
import { t as OpenApiRouter } from "./router.context-EPlMBk3G.mjs";
|
|
4
|
+
import { n as useWorkspaceContext, t as OpenApiWorkspaceContext } from "./workspace.context-XWvQ_7Hg.mjs";
|
|
5
|
+
export { OpenApiQueryConfig, OpenApiRouter, OpenApiWorkspaceContext, configureTranslations, ns, resources, useWorkspaceContext };
|
|
@@ -1,40 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
declare const ns = "openapi";
|
|
3
|
-
declare const resources: {
|
|
4
|
-
readonly en: {
|
|
5
|
-
readonly openapi: {
|
|
6
|
-
openapi: {
|
|
7
|
-
sharedErrors: {
|
|
8
|
-
dataValidation: string;
|
|
9
|
-
internalError: string;
|
|
10
|
-
networkError: string;
|
|
11
|
-
canceledError: string;
|
|
12
|
-
unknownError: string;
|
|
13
|
-
unknownErrorWithCode: string;
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
readonly sl: {
|
|
19
|
-
readonly openapi: {
|
|
20
|
-
openapi: {
|
|
21
|
-
sharedErrors: {
|
|
22
|
-
dataValidation: string;
|
|
23
|
-
internalError: string;
|
|
24
|
-
networkError: string;
|
|
25
|
-
canceledError: string;
|
|
26
|
-
unknownError: string;
|
|
27
|
-
unknownErrorWithCode: string;
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
type TranslateFunction = (key: string, options?: {
|
|
34
|
-
ns?: string;
|
|
35
|
-
}) => string;
|
|
36
|
-
declare function configureTranslations<T>(getter: () => T): void;
|
|
37
|
-
//#endregion
|
|
1
|
+
import { t as TranslateFunction } from "./i18n-B_brQh4X.mjs";
|
|
38
2
|
//#region src/lib/rest/error-handling.d.ts
|
|
39
3
|
type GeneralErrorCodes = "DATA_VALIDATION_ERROR" | "NETWORK_ERROR" | "CANCELED_ERROR" | "INTERNAL_ERROR" | "UNKNOWN_ERROR";
|
|
40
4
|
declare class ApplicationException<CodeT> extends Error {
|
|
@@ -69,10 +33,7 @@ declare class ErrorHandler<CodeT extends string | number> {
|
|
|
69
33
|
private readonly userEntries;
|
|
70
34
|
private readonly generalEntries;
|
|
71
35
|
private onRethrowError?;
|
|
72
|
-
constructor({
|
|
73
|
-
entries,
|
|
74
|
-
onRethrowError
|
|
75
|
-
}: ErrorHandlerOptions<CodeT>);
|
|
36
|
+
constructor({ entries, onRethrowError }: ErrorHandlerOptions<CodeT>);
|
|
76
37
|
private matchesEntry;
|
|
77
38
|
/** Lazy so resolveT() only runs when getMessage actually uses `t`. */
|
|
78
39
|
private static lazyT;
|
|
@@ -83,4 +44,4 @@ declare class ErrorHandler<CodeT extends string | number> {
|
|
|
83
44
|
}
|
|
84
45
|
declare const SharedErrorHandler: ErrorHandler<never>;
|
|
85
46
|
//#endregion
|
|
86
|
-
export { ErrorHandler as a, SharedErrorHandler as c,
|
|
47
|
+
export { ErrorHandler as a, SharedErrorHandler as c, ErrorEntry as i, DomainErrorEntry as n, ErrorHandlerOptions as o, DomainErrorRegistry as r, GeneralErrorCodes as s, ApplicationException as t };
|
|
@@ -1,48 +1,26 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as ns, r as resolveT } from "./i18n-D-FesqFb.mjs";
|
|
2
|
+
import { t as HttpError } from "./rest-transport.types-DxitRtsB.mjs";
|
|
2
3
|
import { z } from "zod";
|
|
3
|
-
//#region src/lib/
|
|
4
|
-
|
|
5
|
-
"
|
|
6
|
-
"internalError": "An internal error occurred. This is most likely a bug on our end. Please try again later.",
|
|
7
|
-
"networkError": "A network error occurred. Are you connected to the internet?",
|
|
8
|
-
"canceledError": "The request was canceled.",
|
|
9
|
-
"unknownError": "An unknown error occurred. Please try again later.",
|
|
10
|
-
"unknownErrorWithCode": "An unknown error occurred. Error code: \"{{code}}\""
|
|
11
|
-
} } };
|
|
12
|
-
//#endregion
|
|
13
|
-
//#region src/lib/assets/locales/sl/translation.json
|
|
14
|
-
var translation_default = { openapi: { "sharedErrors": {
|
|
15
|
-
"dataValidation": "Pri preverjanju podatkov je prišlo do napake",
|
|
16
|
-
"internalError": "Prišlo je do notranje napake.",
|
|
17
|
-
"networkError": "Prišlo je do napake v omrežju.",
|
|
18
|
-
"canceledError": "Zahteva je bila preklicana.",
|
|
19
|
-
"unknownError": "Prišlo je do neznane napake.",
|
|
20
|
-
"unknownErrorWithCode": "Prišlo je do neznane napake. Koda napake: \"{{code}}\""
|
|
21
|
-
} } };
|
|
22
|
-
//#endregion
|
|
23
|
-
//#region src/lib/config/i18n.ts
|
|
24
|
-
const ns = "openapi";
|
|
25
|
-
const resources = {
|
|
26
|
-
en: { [ns]: translation_default$1 },
|
|
27
|
-
sl: { [ns]: translation_default }
|
|
28
|
-
};
|
|
29
|
-
let getT = null;
|
|
30
|
-
function configureTranslations(getter) {
|
|
31
|
-
getT = () => getter();
|
|
4
|
+
//#region src/lib/rest/http-error.utils.ts
|
|
5
|
+
function isAxiosErrorLike(error) {
|
|
6
|
+
return typeof error === "object" && error !== null && "isAxiosError" in error;
|
|
32
7
|
}
|
|
33
|
-
function
|
|
34
|
-
if (
|
|
35
|
-
|
|
8
|
+
function isCanceledRequest(error) {
|
|
9
|
+
if (error instanceof DOMException && ["AbortError", "TimeoutError"].includes(error.name)) return true;
|
|
10
|
+
if (isAxiosErrorLike(error)) return error.code === "ERR_CANCELED" || error.code === "ECONNABORTED";
|
|
11
|
+
return false;
|
|
36
12
|
}
|
|
37
13
|
//#endregion
|
|
38
14
|
//#region src/lib/rest/rest.utils.ts
|
|
15
|
+
function getResponseData(error) {
|
|
16
|
+
if (error instanceof HttpError) return error.response.data;
|
|
17
|
+
return isAxiosErrorLike(error) ? error.response?.data : void 0;
|
|
18
|
+
}
|
|
39
19
|
let RestUtils;
|
|
40
20
|
(function(_RestUtils) {
|
|
41
21
|
_RestUtils.extractServerResponseCode = (e) => {
|
|
42
22
|
if (e instanceof z.ZodError) return "validation-exception";
|
|
43
|
-
|
|
44
|
-
if (!e.response) return null;
|
|
45
|
-
const data = e.response.data;
|
|
23
|
+
const data = getResponseData(e);
|
|
46
24
|
if (typeof data?.code === "string") return data.code;
|
|
47
25
|
if (typeof data?.code === "number") return data.code;
|
|
48
26
|
return null;
|
|
@@ -54,15 +32,13 @@ let RestUtils;
|
|
|
54
32
|
};
|
|
55
33
|
const extractServerErrorMessage = _RestUtils.extractServerErrorMessage = (e) => {
|
|
56
34
|
if (e instanceof z.ZodError) return e.message;
|
|
57
|
-
|
|
58
|
-
if (!e.response) return null;
|
|
59
|
-
const data = e.response.data;
|
|
35
|
+
const data = getResponseData(e);
|
|
60
36
|
if (typeof data?.message === "string") return data.message;
|
|
61
37
|
return null;
|
|
62
38
|
};
|
|
63
39
|
_RestUtils.extractContentDispositionFilename = (headers) => {
|
|
64
|
-
const contentDisposition = headers["content-disposition"];
|
|
65
|
-
return contentDisposition ? /filename=["']?([^"';]+)/i.exec(contentDisposition)?.[1] : void 0;
|
|
40
|
+
const contentDisposition = headers instanceof Headers ? headers.get("content-disposition") : headers["content-disposition"];
|
|
41
|
+
return typeof contentDisposition === "string" ? /filename=["']?([^"';]+)/i.exec(contentDisposition)?.[1] : void 0;
|
|
66
42
|
};
|
|
67
43
|
})(RestUtils || (RestUtils = {}));
|
|
68
44
|
//#endregion
|
|
@@ -109,7 +85,8 @@ var ErrorHandler = class ErrorHandler {
|
|
|
109
85
|
const internalError = {
|
|
110
86
|
code: "INTERNAL_ERROR",
|
|
111
87
|
condition: (e) => {
|
|
112
|
-
if (
|
|
88
|
+
if (isAxiosErrorLike(e)) return e.response?.status != null && e.response.status >= 500 && e.response.status < 600;
|
|
89
|
+
if (e instanceof HttpError) return e.response.status >= 500 && e.response.status < 600;
|
|
113
90
|
return false;
|
|
114
91
|
},
|
|
115
92
|
getMessage: () => resolveT()("openapi.sharedErrors.internalError", { ns })
|
|
@@ -117,7 +94,8 @@ var ErrorHandler = class ErrorHandler {
|
|
|
117
94
|
const networkError = {
|
|
118
95
|
code: "NETWORK_ERROR",
|
|
119
96
|
condition: (e) => {
|
|
120
|
-
if (
|
|
97
|
+
if (isAxiosErrorLike(e)) return e.code === "ERR_NETWORK";
|
|
98
|
+
if (e instanceof TypeError) return true;
|
|
121
99
|
return false;
|
|
122
100
|
},
|
|
123
101
|
getMessage: () => resolveT()("openapi.sharedErrors.networkError", { ns })
|
|
@@ -125,9 +103,7 @@ var ErrorHandler = class ErrorHandler {
|
|
|
125
103
|
const canceledError = {
|
|
126
104
|
code: "CANCELED_ERROR",
|
|
127
105
|
condition: (e) => {
|
|
128
|
-
|
|
129
|
-
if (isAxiosError(e) && e.code === "ECONNABORTED") return true;
|
|
130
|
-
return false;
|
|
106
|
+
return isCanceledRequest(e);
|
|
131
107
|
},
|
|
132
108
|
getMessage: () => resolveT()("openapi.sharedErrors.canceledError", { ns })
|
|
133
109
|
};
|
|
@@ -205,4 +181,4 @@ var ErrorHandler = class ErrorHandler {
|
|
|
205
181
|
};
|
|
206
182
|
const SharedErrorHandler = new ErrorHandler({ entries: [] });
|
|
207
183
|
//#endregion
|
|
208
|
-
export { RestUtils as a,
|
|
184
|
+
export { RestUtils as a, SharedErrorHandler as i, DomainErrorRegistry as n, ErrorHandler as r, ApplicationException as t };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { a as ErrorHandler, c as SharedErrorHandler, i as ErrorEntry, n as DomainErrorEntry, o as ErrorHandlerOptions, r as DomainErrorRegistry, s as GeneralErrorCodes, t as ApplicationException } from "./error-handling-LPEPQV1V.mjs";
|
|
2
|
+
import { t as RestUtils } from "./rest.utils-DpiFIdhF.mjs";
|
|
3
|
+
export { ApplicationException, type DomainErrorEntry, DomainErrorRegistry, type ErrorEntry, ErrorHandler, type ErrorHandlerOptions, type GeneralErrorCodes, RestUtils, SharedErrorHandler };
|
package/dist/errors.mjs
ADDED