@povio/openapi-codegen-cli 2.0.3-rc.0 → 2.0.3
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.ts +4 -4
- package/dist/acl.mjs +8 -0
- package/dist/commands/check.command.d.ts +1 -1
- package/dist/commands/check.d.ts +1 -1
- package/dist/commands/generate.command.d.ts +1 -1
- package/dist/commands/generate.d.ts +1 -1
- package/dist/generator.d.ts +3 -3
- package/dist/generators/checkOpenAPIDoc.d.ts +3 -3
- package/dist/generators/const/acl.const.d.ts +1 -1
- package/dist/generators/const/deps.const.d.ts +1 -1
- package/dist/generators/const/endpoints.const.d.ts +1 -1
- package/dist/generators/const/openapi.const.d.ts +1 -1
- package/dist/generators/const/options.const.d.ts +1 -1
- package/dist/generators/const/queries.const.d.ts +1 -1
- package/dist/generators/const/validation.const.d.ts +1 -1
- package/dist/generators/const/zod.const.d.ts +1 -1
- package/dist/generators/core/SchemaResolver.class.d.ts +6 -6
- package/dist/generators/core/endpoints/getEndpointAcl.d.ts +3 -3
- package/dist/generators/core/endpoints/getEndpointBody.d.ts +3 -3
- package/dist/generators/core/endpoints/getEndpointParameter.d.ts +4 -4
- package/dist/generators/core/endpoints/getEndpointsFromOpenAPIDoc.d.ts +2 -2
- package/dist/generators/core/getDataFromOpenAPIDoc.d.ts +4 -4
- package/dist/generators/core/getMetadataFromOpenAPIDoc.d.ts +3 -3
- package/dist/generators/core/openapi/getOpenAPISchemaComplexity.d.ts +1 -1
- package/dist/generators/core/openapi/getOpenAPISchemaDependencyGraph.d.ts +1 -1
- package/dist/generators/core/openapi/getSchemaRefObjs.d.ts +2 -2
- package/dist/generators/core/openapi/iterateSchema.d.ts +1 -1
- package/dist/generators/core/resolveConfig.d.ts +1 -1
- package/dist/generators/core/zod/ZodSchema.class.d.ts +4 -4
- package/dist/generators/core/zod/enumExtraction/resolveExtractedEnumZodSchemaNames.d.ts +1 -1
- package/dist/generators/core/zod/enumExtraction/resolveExtractedEnumZodSchemaTags.d.ts +1 -1
- package/dist/generators/core/zod/enumExtraction/updateExtractedEnumZodSchemaData.d.ts +2 -2
- package/dist/generators/core/zod/getZodChain.d.ts +3 -3
- package/dist/generators/core/zod/getZodSchema.d.ts +3 -3
- package/dist/generators/core/zod/getZodSchemaRefs.d.ts +2 -2
- package/dist/generators/core/zod/getZodSchemasFromOpenAPIDoc.d.ts +1 -1
- package/dist/generators/core/zod/resolveZodSchemaName.d.ts +3 -3
- package/dist/generators/core/zod/sortZodSchemasByTopology.d.ts +1 -1
- package/dist/generators/generate/generateAcl.d.ts +1 -1
- package/dist/generators/generate/generateAclCheck.d.ts +1 -1
- package/dist/generators/generate/generateAppRestClient.d.ts +1 -1
- package/dist/generators/generate/generateConfigs.d.ts +1 -1
- package/dist/generators/generate/generateEndpoints.d.ts +1 -1
- package/dist/generators/generate/generateModels.d.ts +1 -1
- package/dist/generators/generate/generateQueries.d.ts +1 -1
- package/dist/generators/generate/generateQueryModules.d.ts +1 -1
- package/dist/generators/generate/generateZodExtended.d.ts +1 -1
- package/dist/generators/generateCodeFromOpenAPIDoc.d.ts +3 -3
- package/dist/generators/types/config.d.ts +1 -1
- package/dist/generators/types/endpoint.d.ts +2 -2
- package/dist/generators/types/generate.d.ts +3 -3
- package/dist/generators/types/metadata.d.ts +2 -2
- package/dist/generators/types/openapi.d.ts +1 -1
- package/dist/generators/types/options.d.ts +1 -1
- package/dist/generators/utils/endpoint.utils.d.ts +2 -2
- package/dist/generators/utils/file.utils.d.ts +1 -1
- package/dist/generators/utils/generate/generate.acl.utils.d.ts +4 -4
- package/dist/generators/utils/generate/generate.configs.utils.d.ts +5 -5
- package/dist/generators/utils/generate/generate.endpoints.utils.d.ts +7 -7
- package/dist/generators/utils/generate/generate.imports.utils.d.ts +4 -4
- package/dist/generators/utils/generate/generate.openapi.utils.d.ts +1 -1
- package/dist/generators/utils/generate/generate.query.utils.d.ts +2 -2
- package/dist/generators/utils/generate/generate.utils.d.ts +2 -2
- package/dist/generators/utils/generate/generate.zod.utils.d.ts +4 -4
- package/dist/generators/utils/generate-files.utils.d.ts +2 -2
- package/dist/generators/utils/hbs/hbs-template.utils.d.ts +1 -1
- package/dist/generators/utils/hbs/hbs.acl.utils.d.ts +1 -1
- package/dist/generators/utils/hbs/hbs.endpoints.utils.d.ts +1 -1
- package/dist/generators/utils/hbs/hbs.partials.utils.d.ts +1 -1
- package/dist/generators/utils/hbs/hbs.query.utils.d.ts +1 -1
- package/dist/generators/utils/hbs/hbs.zod.utils.d.ts +1 -1
- package/dist/generators/utils/namespace.utils.d.ts +2 -2
- package/dist/generators/utils/object.utils.d.ts +2 -2
- package/dist/generators/utils/openapi-schema.utils.d.ts +1 -1
- package/dist/generators/utils/openapi.utils.d.ts +2 -2
- package/dist/generators/utils/operation.utils.d.ts +3 -3
- package/dist/generators/utils/query.utils.d.ts +3 -3
- package/dist/generators/utils/sort.utils.d.ts +1 -1
- package/dist/generators/utils/tag.utils.d.ts +3 -3
- package/dist/generators/utils/ts.utils.d.ts +4 -4
- package/dist/generators/utils/validation.utils.d.ts +4 -4
- package/dist/helpers/config.helper.d.ts +1 -1
- package/dist/helpers/yargs.helper.d.ts +1 -2
- package/dist/index.d.ts +14 -16
- package/dist/index.mjs +23 -0
- package/dist/lib/acl/AclGuard.d.ts +3 -3
- package/dist/lib/acl/AclGuard.mjs +14 -0
- package/dist/lib/acl/Can.d.ts +3 -3
- package/dist/lib/acl/Can.mjs +11 -0
- package/dist/lib/acl/ability.context.d.ts +4 -4
- package/dist/lib/acl/ability.context.mjs +37 -0
- package/dist/lib/acl/appAbility.types.d.ts +1 -1
- package/dist/lib/assets/locales/en/translation.json.mjs +8 -0
- package/dist/lib/assets/locales/sl/translation.json.mjs +8 -0
- package/dist/lib/auth/AuthGuard.d.ts +2 -2
- package/dist/lib/auth/AuthGuard.mjs +26 -0
- package/dist/lib/auth/auth.context.d.ts +1 -1
- package/dist/lib/auth/auth.context.mjs +41 -0
- package/dist/lib/config/i18n.d.ts +1 -1
- package/dist/lib/config/i18n.mjs +31 -0
- package/dist/lib/config/queryConfig.context.mjs +17 -0
- package/dist/lib/config/router.context.d.ts +1 -1
- package/dist/lib/config/router.context.mjs +20 -0
- package/dist/lib/react-query.types.d.ts +2 -2
- package/dist/lib/rest/error-handling.d.ts +1 -1
- package/dist/lib/rest/error-handling.mjs +129 -0
- package/dist/lib/rest/rest-client.d.ts +4 -4
- package/dist/lib/rest/rest-client.mjs +62 -0
- package/dist/lib/rest/rest-client.types.d.ts +4 -4
- package/dist/lib/rest/rest-interceptor.d.ts +1 -1
- package/dist/lib/rest/rest-interceptor.mjs +21 -0
- package/dist/lib/rest/rest.utils.d.ts +1 -1
- package/dist/lib/rest/rest.utils.mjs +51 -0
- package/dist/sh.js +1 -1
- package/package.json +12 -8
- package/dist/acl.js +0 -1
- package/dist/index.js +0 -3
- package/dist/tsconfig.tsbuildinfo +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { SchemaResolver } from
|
|
2
|
-
import { GenerateData, GenerateFileData } from
|
|
1
|
+
import { SchemaResolver } from '../core/SchemaResolver.class';
|
|
2
|
+
import { GenerateData, GenerateFileData } from '../types/generate';
|
|
3
3
|
export declare function getAclFiles(data: GenerateData, resolver: SchemaResolver): GenerateFileData[];
|
|
4
4
|
export declare function getMutationEffectsFiles(data: GenerateData, resolver: SchemaResolver): GenerateFileData[];
|
|
5
5
|
export declare function getZodExtendedFiles(data: GenerateData, resolver: SchemaResolver): GenerateFileData[];
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { SchemaResolver } from
|
|
1
|
+
import { SchemaResolver } from '../../core/SchemaResolver.class';
|
|
2
2
|
export declare function getHbsTemplateDelegate(resolver: SchemaResolver, templateName: string): HandlebarsTemplateDelegate<any>;
|
|
3
3
|
export declare function getHbsPartialTemplateDelegate(templateName: string): HandlebarsTemplateDelegate<any>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { SchemaResolver } from
|
|
1
|
+
import { SchemaResolver } from '../../core/SchemaResolver.class';
|
|
2
2
|
export declare function registerAclHbsHelpers(resolver: SchemaResolver): void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { SchemaResolver } from
|
|
1
|
+
import { SchemaResolver } from '../../core/SchemaResolver.class';
|
|
2
2
|
export declare function registerEndpointsHbsHelpers(resolver: SchemaResolver): void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { SchemaResolver } from
|
|
1
|
+
import { SchemaResolver } from '../../core/SchemaResolver.class';
|
|
2
2
|
export declare function registerPartialsHbsHelpers(resolver: SchemaResolver): void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { SchemaResolver } from
|
|
1
|
+
import { SchemaResolver } from '../../core/SchemaResolver.class';
|
|
2
2
|
export declare function registerQueryHbsHelpers(resolver: SchemaResolver): void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { SchemaResolver } from
|
|
1
|
+
import { SchemaResolver } from '../../core/SchemaResolver.class';
|
|
2
2
|
export declare function registerZodHbsHelpers(resolver: SchemaResolver): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { GenerateType } from
|
|
2
|
-
import { GenerateOptions } from
|
|
1
|
+
import { GenerateType } from '../types/generate';
|
|
2
|
+
import { GenerateOptions } from '../types/options';
|
|
3
3
|
export declare const getNamespaceName: ({ type, tag, options, }: {
|
|
4
4
|
type: GenerateType;
|
|
5
5
|
tag: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { HasNestedPath, ObjectLiteral } from
|
|
2
|
-
import { Get } from
|
|
1
|
+
import { HasNestedPath, ObjectLiteral } from '../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 */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { OpenAPIV3 } from
|
|
1
|
+
import { OpenAPIV3 } from 'openapi-types';
|
|
2
2
|
export declare function isReferenceObject(obj: unknown): obj is OpenAPIV3.ReferenceObject;
|
|
3
3
|
export declare function isSchemaObject(schema: OpenAPIV3.SchemaObject | OpenAPIV3.ReferenceObject): schema is OpenAPIV3.SchemaObject;
|
|
4
4
|
export declare function isArraySchemaObject(schema: OpenAPIV3.SchemaObject): schema is OpenAPIV3.ArraySchemaObject;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ALLOWED_PARAM_MEDIA_TYPES } from
|
|
2
|
-
import { ParameterObject, PrimitiveType, SingleType, SortingParameterObject } from
|
|
1
|
+
import { ALLOWED_PARAM_MEDIA_TYPES } from '../const/openapi.const';
|
|
2
|
+
import { ParameterObject, PrimitiveType, SingleType, SortingParameterObject } from '../types/openapi';
|
|
3
3
|
export declare const getSchemaRef: (schemaName: string) => string;
|
|
4
4
|
export declare const autocorrectRef: (ref: string) => string;
|
|
5
5
|
export declare const getSchemaNameByRef: (ref: string) => string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { OpenAPIV3 } from
|
|
2
|
-
import { OperationObject } from
|
|
3
|
-
import { GenerateOptions } from
|
|
1
|
+
import { OpenAPIV3 } from 'openapi-types';
|
|
2
|
+
import { OperationObject } from '../types/openapi';
|
|
3
|
+
import { GenerateOptions } from '../types/options';
|
|
4
4
|
export declare function isOperationExcluded(operation: OperationObject, options: GenerateOptions): boolean;
|
|
5
5
|
export declare function getOperationName({ path, method, operation, options, tag, keepOperationTag, keepOperationPrefix, }: {
|
|
6
6
|
path: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { SchemaResolver } from
|
|
2
|
-
import { Endpoint } from
|
|
3
|
-
import { GenerateOptions } from
|
|
1
|
+
import { SchemaResolver } from '../core/SchemaResolver.class';
|
|
2
|
+
import { Endpoint } from '../types/endpoint';
|
|
3
|
+
import { GenerateOptions } from '../types/options';
|
|
4
4
|
export declare const isQuery: (endpoint: Endpoint) => boolean;
|
|
5
5
|
export declare const isMutation: (endpoint: Endpoint) => boolean;
|
|
6
6
|
export declare const isInfiniteQuery: (endpoint: Endpoint, options: GenerateOptions) => boolean;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ObjectLiteral } from
|
|
1
|
+
import { ObjectLiteral } from '../types/common';
|
|
2
2
|
/** @see https://gist.github.com/RubyTuesdayDONO/5006455 */
|
|
3
3
|
export declare function topologicalSort(graph: Record<string, Set<string>>): string[];
|
|
4
4
|
/** Sort object keys using a reference order array, sort keys not in reference order in lasts positions */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Endpoint } from
|
|
2
|
-
import { OperationObject } from
|
|
3
|
-
import { GenerateOptions } from
|
|
1
|
+
import { Endpoint } from '../types/endpoint';
|
|
2
|
+
import { OperationObject } from '../types/openapi';
|
|
3
|
+
import { GenerateOptions } from '../types/options';
|
|
4
4
|
export declare function formatTag(tag: string): string;
|
|
5
5
|
export declare function getOperationTag(operation: OperationObject, options: GenerateOptions): string;
|
|
6
6
|
export declare function getEndpointTag(endpoint: Endpoint, options: GenerateOptions): string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { OpenAPIV3 } from
|
|
2
|
-
import { SchemaResolver } from
|
|
3
|
-
import { TsMetaType, TsTypeBase } from
|
|
4
|
-
import { PrimitiveType } from
|
|
1
|
+
import { OpenAPIV3 } from 'openapi-types';
|
|
2
|
+
import { SchemaResolver } from '../core/SchemaResolver.class';
|
|
3
|
+
import { TsMetaType, TsTypeBase } from '../types/metadata';
|
|
4
|
+
import { PrimitiveType } from '../types/openapi';
|
|
5
5
|
export declare function primitiveTypeToTsType(type: PrimitiveType): string;
|
|
6
6
|
export declare function getTsTypeBase({ zodSchemaName, schema, resolver, }: {
|
|
7
7
|
zodSchemaName?: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { HttpStatusCode } from
|
|
2
|
-
import { Endpoint, EndpointParameter } from
|
|
3
|
-
import { OperationObject } from
|
|
4
|
-
import { ValidationError, ValidationErrorType } from
|
|
1
|
+
import { HttpStatusCode } from '../const/validation.const';
|
|
2
|
+
import { Endpoint, EndpointParameter } from '../types/endpoint';
|
|
3
|
+
import { OperationObject } from '../types/openapi';
|
|
4
|
+
import { ValidationError, ValidationErrorType } from '../types/validation';
|
|
5
5
|
export declare function getInvalidSchemaError(message: string): ValidationError;
|
|
6
6
|
export declare function getInvalidOperationIdError(operationId: string): ValidationError;
|
|
7
7
|
export declare function getMissingPathParameterError(params: EndpointParameter[], path: string): ValidationError;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { OpenAPICodegenConfig } from
|
|
1
|
+
import { OpenAPICodegenConfig } from '../generators/types/config';
|
|
2
2
|
export declare function loadConfig(configPath?: string): Promise<OpenAPICodegenConfig | null>;
|
|
3
3
|
export declare const loadJsSync: (filepath: string) => unknown;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export {
|
|
5
|
-
export
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export {
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
14
|
-
export {
|
|
15
|
-
export { AuthGuard } from "./lib/auth/AuthGuard";
|
|
16
|
-
export type { AuthGuardProps } from "./lib/auth/AuthGuard";
|
|
1
|
+
export * from './generators/types/config';
|
|
2
|
+
export { RestClient } from './lib/rest/rest-client';
|
|
3
|
+
export type { RequestInfo, RequestConfig, Response, RestClient as IRestClient } from './lib/rest/rest-client.types';
|
|
4
|
+
export { RestInterceptor } from './lib/rest/rest-interceptor';
|
|
5
|
+
export { RestUtils } from './lib/rest/rest.utils';
|
|
6
|
+
export { ApplicationException, ErrorHandler, SharedErrorHandler } from './lib/rest/error-handling';
|
|
7
|
+
export type { GeneralErrorCodes, ErrorHandlerOptions, ErrorEntry } from './lib/rest/error-handling';
|
|
8
|
+
export type { AppQueryOptions, AppMutationOptions, AppInfiniteQueryOptions } from './lib/react-query.types';
|
|
9
|
+
export { OpenApiRouter } from './lib/config/router.context';
|
|
10
|
+
export { OpenApiQueryConfig } from './lib/config/queryConfig.context';
|
|
11
|
+
export { ns, resources } from './lib/config/i18n';
|
|
12
|
+
export { AuthContext } from './lib/auth/auth.context';
|
|
13
|
+
export { AuthGuard } from './lib/auth/AuthGuard';
|
|
14
|
+
export type { AuthGuardProps } from './lib/auth/AuthGuard';
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { RestClient } from "./lib/rest/rest-client.mjs";
|
|
2
|
+
import { RestInterceptor } from "./lib/rest/rest-interceptor.mjs";
|
|
3
|
+
import { RestUtils } from "./lib/rest/rest.utils.mjs";
|
|
4
|
+
import { ApplicationException, ErrorHandler, SharedErrorHandler } from "./lib/rest/error-handling.mjs";
|
|
5
|
+
import { OpenApiRouter } from "./lib/config/router.context.mjs";
|
|
6
|
+
import { OpenApiQueryConfig } from "./lib/config/queryConfig.context.mjs";
|
|
7
|
+
import { ns, resources } from "./lib/config/i18n.mjs";
|
|
8
|
+
import { AuthContext } from "./lib/auth/auth.context.mjs";
|
|
9
|
+
import { AuthGuard } from "./lib/auth/AuthGuard.mjs";
|
|
10
|
+
export {
|
|
11
|
+
ApplicationException,
|
|
12
|
+
AuthContext,
|
|
13
|
+
AuthGuard,
|
|
14
|
+
ErrorHandler,
|
|
15
|
+
OpenApiQueryConfig,
|
|
16
|
+
OpenApiRouter,
|
|
17
|
+
RestClient,
|
|
18
|
+
RestInterceptor,
|
|
19
|
+
RestUtils,
|
|
20
|
+
SharedErrorHandler,
|
|
21
|
+
ns,
|
|
22
|
+
resources
|
|
23
|
+
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { PropsWithChildren } from 'react';
|
|
2
|
+
import { AppAbilities } from './appAbility.types';
|
|
3
3
|
interface AclGuardProps<TAppAbilities extends AppAbilities = AppAbilities> {
|
|
4
4
|
canUse: TAppAbilities;
|
|
5
5
|
redirectTo?: string;
|
|
6
6
|
}
|
|
7
|
-
export declare const createAclGuard: <TAppAbilities extends AppAbilities = AppAbilities>() => ({ canUse, redirectTo, children }: PropsWithChildren<AclGuardProps<TAppAbilities>>) => import(
|
|
7
|
+
export declare const createAclGuard: <TAppAbilities extends AppAbilities = AppAbilities>() => ({ canUse, redirectTo, children }: PropsWithChildren<AclGuardProps<TAppAbilities>>) => import('react').ReactNode;
|
|
8
8
|
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AbilityContext } from "./ability.context.mjs";
|
|
2
|
+
import { OpenApiRouter } from "../config/router.context.mjs";
|
|
3
|
+
const createAclGuard = () => ({ canUse, redirectTo = "/", children }) => {
|
|
4
|
+
const ability = AbilityContext.useAbility();
|
|
5
|
+
const { replace } = OpenApiRouter.useRouter();
|
|
6
|
+
if (!ability.can(canUse[0], canUse[1])) {
|
|
7
|
+
replace(redirectTo);
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
return children;
|
|
11
|
+
};
|
|
12
|
+
export {
|
|
13
|
+
createAclGuard
|
|
14
|
+
};
|
package/dist/lib/acl/Can.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import { AbilityTuple, PureAbility } from '@casl/ability';
|
|
2
|
+
import { BoundCanProps } from '@casl/react';
|
|
3
|
+
import { AppAbilities } from './appAbility.types';
|
|
4
4
|
type CanAbility = PureAbility<AbilityTuple<AppAbilities[0], AppAbilities[1]>>;
|
|
5
5
|
type CanProps<TAppAbilities extends AppAbilities = AppAbilities> = {
|
|
6
6
|
use: TAppAbilities;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { AbilityContext } from "./ability.context.mjs";
|
|
3
|
+
import { createContextualCan } from "@casl/react";
|
|
4
|
+
const ContextualCan = createContextualCan(AbilityContext.Consumer);
|
|
5
|
+
const Can = ({ use, ...props }) => {
|
|
6
|
+
const [action, subject] = use;
|
|
7
|
+
return /* @__PURE__ */ jsx(ContextualCan, { ...props, do: action, on: subject });
|
|
8
|
+
};
|
|
9
|
+
export {
|
|
10
|
+
Can
|
|
11
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
1
|
+
import { PropsWithChildren } from 'react';
|
|
2
|
+
import { PureAbility, RawRuleOf } from '@casl/ability';
|
|
3
|
+
import { PackRule } from '@casl/ability/extra';
|
|
4
|
+
import { AppAbilities, AppAbility } from './appAbility.types';
|
|
5
5
|
export declare namespace AbilityContext {
|
|
6
6
|
export const Consumer: import("react").Consumer<AppAbility>;
|
|
7
7
|
interface ProviderProps {
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useState, useEffect } from "react";
|
|
3
|
+
import { AuthContext } from "../auth/auth.context.mjs";
|
|
4
|
+
import { AbilityBuilder, createMongoAbility } from "@casl/ability";
|
|
5
|
+
import { unpackRules } from "@casl/ability/extra";
|
|
6
|
+
import { useAbility } from "@casl/react";
|
|
7
|
+
var AbilityContext;
|
|
8
|
+
((AbilityContext2) => {
|
|
9
|
+
const createAppAbilityBuilder = () => new AbilityBuilder(createMongoAbility);
|
|
10
|
+
const initialAppAbility = createAppAbilityBuilder().build();
|
|
11
|
+
const Context = createContext({});
|
|
12
|
+
({ Consumer: AbilityContext2.Consumer } = Context);
|
|
13
|
+
AbilityContext2.Provider = ({ children }) => {
|
|
14
|
+
const [ability, setAbility] = useState(initialAppAbility);
|
|
15
|
+
const { user } = AuthContext.useAuth();
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (!user || !("aclRules" in user)) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const { can, build } = createAppAbilityBuilder();
|
|
21
|
+
const packedRules = user.aclRules;
|
|
22
|
+
const rules = unpackRules(packedRules);
|
|
23
|
+
rules.forEach(({ action, subject, conditions }) => {
|
|
24
|
+
can(action, subject, conditions);
|
|
25
|
+
});
|
|
26
|
+
setAbility(build());
|
|
27
|
+
}, [user]);
|
|
28
|
+
return /* @__PURE__ */ jsx(Context.Provider, { value: ability, children });
|
|
29
|
+
};
|
|
30
|
+
AbilityContext2.useAbility = () => {
|
|
31
|
+
const ability = useAbility(Context);
|
|
32
|
+
return ability;
|
|
33
|
+
};
|
|
34
|
+
})(AbilityContext || (AbilityContext = {}));
|
|
35
|
+
export {
|
|
36
|
+
AbilityContext
|
|
37
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const 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}}"' } };
|
|
2
|
+
const translationEN = {
|
|
3
|
+
openapi
|
|
4
|
+
};
|
|
5
|
+
export {
|
|
6
|
+
translationEN as default,
|
|
7
|
+
openapi
|
|
8
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const openapi = { "sharedErrors": { "dataValidation": "Pri preverjanju podatkov je prišlo do napake", "internalError": "Prišlo je do notranje napake.", "networkError": "Prišlo je do napake v omrežju.", "canceledError": "Zahteva je bila preklicana.", "unknownError": "Prišlo je do neznane napake.", "unknownErrorWithCode": 'Prišlo je do neznane napake. Koda napake: "{{code}}"' } };
|
|
2
|
+
const translationSL = {
|
|
3
|
+
openapi
|
|
4
|
+
};
|
|
5
|
+
export {
|
|
6
|
+
translationSL as default,
|
|
7
|
+
openapi
|
|
8
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PropsWithChildren } from 'react';
|
|
2
2
|
export interface AuthGuardProps {
|
|
3
3
|
type: "public-only" | "private";
|
|
4
4
|
redirectTo?: string;
|
|
5
5
|
}
|
|
6
|
-
export declare const AuthGuard: ({ type, redirectTo, children }: PropsWithChildren<AuthGuardProps>) => import(
|
|
6
|
+
export declare const AuthGuard: ({ type, redirectTo, children }: PropsWithChildren<AuthGuardProps>) => import('react').ReactNode;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { useState, useEffect } from "react";
|
|
2
|
+
import { OpenApiRouter } from "../config/router.context.mjs";
|
|
3
|
+
import { AuthContext } from "./auth.context.mjs";
|
|
4
|
+
const AuthGuard = ({ type, redirectTo, children }) => {
|
|
5
|
+
const { isAuthenticated, routes, loadingState } = AuthContext.useAuth();
|
|
6
|
+
const { replace } = OpenApiRouter.useRouter();
|
|
7
|
+
const [hasMounted, setHasMounted] = useState(false);
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
setHasMounted(true);
|
|
10
|
+
}, []);
|
|
11
|
+
if (!hasMounted) {
|
|
12
|
+
return loadingState;
|
|
13
|
+
}
|
|
14
|
+
if (type === "private" && !isAuthenticated) {
|
|
15
|
+
replace(redirectTo || routes?.unauthenticated || "/");
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
if (type === "public-only" && isAuthenticated) {
|
|
19
|
+
replace(redirectTo || routes?.authenticated || "/");
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
return children;
|
|
23
|
+
};
|
|
24
|
+
export {
|
|
25
|
+
AuthGuard
|
|
26
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useMemo, use } from "react";
|
|
3
|
+
var AuthContext;
|
|
4
|
+
((AuthContext2) => {
|
|
5
|
+
const Context = createContext({});
|
|
6
|
+
AuthContext2.Provider = ({
|
|
7
|
+
isAuthenticated,
|
|
8
|
+
isInitializing,
|
|
9
|
+
logout,
|
|
10
|
+
updateTokens,
|
|
11
|
+
accessToken,
|
|
12
|
+
user,
|
|
13
|
+
userPromise,
|
|
14
|
+
routes,
|
|
15
|
+
loadingState,
|
|
16
|
+
children
|
|
17
|
+
}) => {
|
|
18
|
+
const value = useMemo(
|
|
19
|
+
() => ({
|
|
20
|
+
isAuthenticated,
|
|
21
|
+
isInitializing,
|
|
22
|
+
logout,
|
|
23
|
+
updateTokens,
|
|
24
|
+
accessToken,
|
|
25
|
+
user,
|
|
26
|
+
userPromise,
|
|
27
|
+
routes,
|
|
28
|
+
loadingState
|
|
29
|
+
}),
|
|
30
|
+
[isAuthenticated, isInitializing, logout, updateTokens, accessToken, user, userPromise, routes, loadingState]
|
|
31
|
+
);
|
|
32
|
+
return /* @__PURE__ */ jsx(Context.Provider, { value, children });
|
|
33
|
+
};
|
|
34
|
+
AuthContext2.useAuth = () => {
|
|
35
|
+
const auth = use(Context);
|
|
36
|
+
return auth;
|
|
37
|
+
};
|
|
38
|
+
})(AuthContext || (AuthContext = {}));
|
|
39
|
+
export {
|
|
40
|
+
AuthContext
|
|
41
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import i18next from "i18next";
|
|
2
|
+
import translationEN from "../assets/locales/en/translation.json.mjs";
|
|
3
|
+
import translationSL from "../assets/locales/sl/translation.json.mjs";
|
|
4
|
+
const ns = "openapi";
|
|
5
|
+
const resources = {
|
|
6
|
+
en: {
|
|
7
|
+
[ns]: translationEN
|
|
8
|
+
},
|
|
9
|
+
sl: {
|
|
10
|
+
[ns]: translationSL
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
const defaultLanguage = "en";
|
|
14
|
+
const i18n = i18next.createInstance();
|
|
15
|
+
i18n.init({
|
|
16
|
+
compatibilityJSON: "v4",
|
|
17
|
+
lng: defaultLanguage,
|
|
18
|
+
fallbackLng: defaultLanguage,
|
|
19
|
+
resources,
|
|
20
|
+
ns: Object.keys(resources.en),
|
|
21
|
+
defaultNS: ns,
|
|
22
|
+
interpolation: {
|
|
23
|
+
escapeValue: false
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
const defaultT = i18n.t.bind(i18n);
|
|
27
|
+
export {
|
|
28
|
+
defaultT,
|
|
29
|
+
ns,
|
|
30
|
+
resources
|
|
31
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useMemo, use } from "react";
|
|
3
|
+
var OpenApiQueryConfig;
|
|
4
|
+
((OpenApiQueryConfig2) => {
|
|
5
|
+
const Context = createContext({});
|
|
6
|
+
OpenApiQueryConfig2.Provider = ({ preferUpdate = true, children }) => {
|
|
7
|
+
const value = useMemo(() => ({ preferUpdate }), [preferUpdate]);
|
|
8
|
+
return /* @__PURE__ */ jsx(Context.Provider, { value, children });
|
|
9
|
+
};
|
|
10
|
+
OpenApiQueryConfig2.useConfig = () => {
|
|
11
|
+
const context = use(Context);
|
|
12
|
+
return context ?? {};
|
|
13
|
+
};
|
|
14
|
+
})(OpenApiQueryConfig || (OpenApiQueryConfig = {}));
|
|
15
|
+
export {
|
|
16
|
+
OpenApiQueryConfig
|
|
17
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useMemo, use } from "react";
|
|
3
|
+
var OpenApiRouter;
|
|
4
|
+
((OpenApiRouter2) => {
|
|
5
|
+
const Context = createContext(null);
|
|
6
|
+
OpenApiRouter2.Provider = ({ children, replace }) => {
|
|
7
|
+
const value = useMemo(() => ({ replace }), [replace]);
|
|
8
|
+
return /* @__PURE__ */ jsx(Context, { value, children });
|
|
9
|
+
};
|
|
10
|
+
OpenApiRouter2.useRouter = () => {
|
|
11
|
+
const context = use(Context);
|
|
12
|
+
if (!context) {
|
|
13
|
+
throw new Error("useRouter must be used within an OpenApiRouter.Provider");
|
|
14
|
+
}
|
|
15
|
+
return context;
|
|
16
|
+
};
|
|
17
|
+
})(OpenApiRouter || (OpenApiRouter = {}));
|
|
18
|
+
export {
|
|
19
|
+
OpenApiRouter
|
|
20
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { InfiniteData, QueryKey, UseInfiniteQueryOptions, UseMutationOptions, UseQueryOptions } from
|
|
2
|
-
import { ApplicationException, GeneralErrorCodes } from
|
|
1
|
+
import { InfiniteData, QueryKey, UseInfiniteQueryOptions, UseMutationOptions, UseQueryOptions } from '@tanstack/react-query';
|
|
2
|
+
import { ApplicationException, GeneralErrorCodes } from './rest/error-handling';
|
|
3
3
|
type Function = (...args: any) => any;
|
|
4
4
|
type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N;
|
|
5
5
|
type IsAny<T> = IfAny<T, true, never>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TFunction } from 'i18next';
|
|
2
2
|
export type GeneralErrorCodes = "DATA_VALIDATION_ERROR" | "NETWORK_ERROR" | "CANCELED_ERROR" | "INTERNAL_ERROR" | "UNKNOWN_ERROR";
|
|
3
3
|
export declare class ApplicationException<CodeT> extends Error {
|
|
4
4
|
code: CodeT;
|