@povio/openapi-codegen-cli 2.0.8-rc.4 → 2.0.8-rc.7
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 +63 -0
- package/dist/acl.d.mts +48 -0
- package/dist/acl.mjs +62 -7
- package/dist/auth.context-DKjzWiaA.mjs +59 -0
- package/dist/config-Cu_GYfai.d.mts +6 -0
- package/dist/generate.runner-DNldmk0f.mjs +98 -0
- package/dist/generateCodeFromOpenAPIDoc-B5lnFNGB.mjs +4522 -0
- package/dist/generator.d.mts +65 -0
- package/dist/generator.mjs +144 -0
- package/dist/index.d.mts +246 -0
- package/dist/index.mjs +365 -22
- package/dist/options-DBz5YE3s.d.mts +90 -0
- package/dist/sh.d.mts +1 -0
- package/dist/sh.mjs +439 -0
- package/dist/vite.d.mts +8 -0
- package/dist/vite.mjs +50 -0
- package/package.json +50 -45
- package/src/assets/useMutationEffects.ts +30 -25
- package/src/generators/templates/endpoints.hbs +0 -1
- package/dist/acl.d.ts +0 -4
- package/dist/commands/check.command.d.ts +0 -2
- package/dist/commands/check.d.ts +0 -7
- package/dist/commands/generate.command.d.ts +0 -2
- package/dist/commands/generate.d.ts +0 -8
- package/dist/generator.d.ts +0 -3
- package/dist/generator.js +0 -78
- package/dist/generators/checkOpenAPIDoc.d.ts +0 -3
- package/dist/generators/const/acl.const.d.ts +0 -13
- package/dist/generators/const/buildConfigs.const.d.ts +0 -1
- package/dist/generators/const/deps.const.d.ts +0 -38
- package/dist/generators/const/endpoints.const.d.ts +0 -11
- package/dist/generators/const/js.const.d.ts +0 -1
- package/dist/generators/const/openapi.const.d.ts +0 -7
- package/dist/generators/const/options.const.d.ts +0 -2
- package/dist/generators/const/package.const.d.ts +0 -2
- package/dist/generators/const/queries.const.d.ts +0 -8
- package/dist/generators/const/validation.const.d.ts +0 -53
- package/dist/generators/const/zod.const.d.ts +0 -19
- package/dist/generators/core/SchemaResolver.class.d.ts +0 -71
- package/dist/generators/core/endpoints/getEndpointAcl.d.ts +0 -8
- package/dist/generators/core/endpoints/getEndpointBody.d.ts +0 -13
- package/dist/generators/core/endpoints/getEndpointParameter.d.ts +0 -11
- package/dist/generators/core/endpoints/getEndpointsFromOpenAPIDoc.d.ts +0 -3
- package/dist/generators/core/endpoints/getEndpointsFromOpenAPIDoc.test.d.ts +0 -1
- package/dist/generators/core/getDataFromOpenAPIDoc.d.ts +0 -8
- package/dist/generators/core/getMetadataFromOpenAPIDoc.d.ts +0 -4
- package/dist/generators/core/getMetadataFromOpenAPIDoc.test.d.ts +0 -1
- package/dist/generators/core/openapi/getOpenAPISchemaComplexity.d.ts +0 -2
- package/dist/generators/core/openapi/getOpenAPISchemaComplexity.test.d.ts +0 -1
- package/dist/generators/core/openapi/getOpenAPISchemaDependencyGraph.d.ts +0 -6
- package/dist/generators/core/openapi/getOpenAPISchemaDependencyGraph.test.d.ts +0 -1
- package/dist/generators/core/openapi/getSchemaRefObjs.d.ts +0 -4
- package/dist/generators/core/openapi/iterateSchema.d.ts +0 -22
- package/dist/generators/core/resolveConfig.d.ts +0 -7
- package/dist/generators/core/zod/ZodSchema.class.d.ts +0 -26
- package/dist/generators/core/zod/enumExtraction/resolveExtractedEnumZodSchemaNames.d.ts +0 -2
- package/dist/generators/core/zod/enumExtraction/resolveExtractedEnumZodSchemaTags.d.ts +0 -2
- package/dist/generators/core/zod/enumExtraction/updateExtractedEnumZodSchemaData.d.ts +0 -17
- package/dist/generators/core/zod/getZodChain.d.ts +0 -8
- package/dist/generators/core/zod/getZodSchema.d.ts +0 -17
- package/dist/generators/core/zod/getZodSchema.test.d.ts +0 -1
- package/dist/generators/core/zod/getZodSchemaRefs.d.ts +0 -6
- package/dist/generators/core/zod/getZodSchemasFromOpenAPIDoc.d.ts +0 -6
- package/dist/generators/core/zod/resolveZodSchemaName.d.ts +0 -10
- package/dist/generators/core/zod/sortZodSchemasByTopology.d.ts +0 -4
- package/dist/generators/generate/generateAcl.d.ts +0 -3
- package/dist/generators/generate/generateAclCheck.d.ts +0 -2
- package/dist/generators/generate/generateAppRestClient.d.ts +0 -2
- package/dist/generators/generate/generateConfigs.d.ts +0 -2
- package/dist/generators/generate/generateEndpoints.d.ts +0 -2
- package/dist/generators/generate/generateModels.d.ts +0 -2
- package/dist/generators/generate/generateQueries.d.ts +0 -2
- package/dist/generators/generate/generateQueryModules.d.ts +0 -2
- package/dist/generators/generate/generateZodExtended.d.ts +0 -2
- package/dist/generators/generateCodeFromOpenAPIDoc.d.ts +0 -4
- package/dist/generators/types/builder-config.d.ts +0 -48
- package/dist/generators/types/common.d.ts +0 -27
- package/dist/generators/types/config.d.ts +0 -2
- package/dist/generators/types/endpoint.d.ts +0 -50
- package/dist/generators/types/generate.d.ts +0 -39
- package/dist/generators/types/metadata.d.ts +0 -51
- package/dist/generators/types/openapi.d.ts +0 -22
- package/dist/generators/types/options.d.ts +0 -66
- package/dist/generators/types/validation.d.ts +0 -5
- package/dist/generators/utils/array.utils.d.ts +0 -1
- package/dist/generators/utils/endpoint.utils.d.ts +0 -12
- package/dist/generators/utils/endpoint.utils.test.d.ts +0 -1
- package/dist/generators/utils/file.utils.d.ts +0 -8
- package/dist/generators/utils/generate/generate.acl.utils.d.ts +0 -23
- package/dist/generators/utils/generate/generate.configs.utils.d.ts +0 -15
- package/dist/generators/utils/generate/generate.endpoints.utils.d.ts +0 -39
- package/dist/generators/utils/generate/generate.imports.utils.d.ts +0 -39
- package/dist/generators/utils/generate/generate.imports.utils.test.d.ts +0 -1
- package/dist/generators/utils/generate/generate.openapi.utils.d.ts +0 -2
- package/dist/generators/utils/generate/generate.query.utils.d.ts +0 -6
- package/dist/generators/utils/generate/generate.utils.d.ts +0 -18
- package/dist/generators/utils/generate/generate.zod.utils.d.ts +0 -13
- package/dist/generators/utils/generate-files.utils.d.ts +0 -6
- package/dist/generators/utils/hbs/hbs-template.utils.d.ts +0 -3
- package/dist/generators/utils/hbs/hbs.acl.utils.d.ts +0 -2
- package/dist/generators/utils/hbs/hbs.common.utils.d.ts +0 -1
- package/dist/generators/utils/hbs/hbs.endpoints.utils.d.ts +0 -2
- package/dist/generators/utils/hbs/hbs.imports.utils.d.ts +0 -1
- package/dist/generators/utils/hbs/hbs.partials.utils.d.ts +0 -2
- package/dist/generators/utils/hbs/hbs.query.utils.d.ts +0 -2
- package/dist/generators/utils/hbs/hbs.zod.utils.d.ts +0 -2
- package/dist/generators/utils/js.utils.d.ts +0 -2
- package/dist/generators/utils/js.utils.test.d.ts +0 -1
- package/dist/generators/utils/math.utils.d.ts +0 -1
- package/dist/generators/utils/namespace.utils.d.ts +0 -7
- package/dist/generators/utils/object.utils.d.ts +0 -13
- package/dist/generators/utils/object.utils.test.d.ts +0 -1
- package/dist/generators/utils/openapi-schema.utils.d.ts +0 -15
- package/dist/generators/utils/openapi.utils.d.ts +0 -23
- package/dist/generators/utils/openapi.utils.test.d.ts +0 -1
- package/dist/generators/utils/operation.utils.d.ts +0 -22
- package/dist/generators/utils/operation.utils.test.d.ts +0 -1
- package/dist/generators/utils/query.utils.d.ts +0 -7
- package/dist/generators/utils/sort.utils.d.ts +0 -7
- package/dist/generators/utils/string.utils.d.ts +0 -14
- package/dist/generators/utils/string.utils.test.d.ts +0 -1
- package/dist/generators/utils/tag.utils.d.ts +0 -7
- package/dist/generators/utils/ts.utils.d.ts +0 -16
- package/dist/generators/utils/validation.utils.d.ts +0 -17
- package/dist/generators/utils/zod-schema.utils.d.ts +0 -15
- package/dist/helpers/cli.helper.d.ts +0 -22
- package/dist/helpers/config.helper.d.ts +0 -3
- package/dist/helpers/version.helper.d.ts +0 -4
- package/dist/helpers/yargs.helper.d.ts +0 -10
- package/dist/index.d.ts +0 -15
- package/dist/lib/acl/AclGuard.d.ts +0 -8
- package/dist/lib/acl/AclGuard.mjs +0 -14
- package/dist/lib/acl/Can.d.ts +0 -9
- package/dist/lib/acl/Can.mjs +0 -11
- package/dist/lib/acl/ability.context.d.ts +0 -15
- package/dist/lib/acl/ability.context.mjs +0 -37
- package/dist/lib/acl/appAbility.types.d.ts +0 -3
- package/dist/lib/assets/locales/en/translation.json.mjs +0 -8
- package/dist/lib/assets/locales/sl/translation.json.mjs +0 -8
- package/dist/lib/auth/AuthGuard.d.ts +0 -6
- package/dist/lib/auth/AuthGuard.mjs +0 -26
- package/dist/lib/auth/auth.context.d.ts +0 -22
- package/dist/lib/auth/auth.context.mjs +0 -41
- package/dist/lib/config/i18n.d.ts +0 -32
- package/dist/lib/config/i18n.mjs +0 -31
- package/dist/lib/config/queryConfig.context.d.ts +0 -17
- package/dist/lib/config/queryConfig.context.mjs +0 -26
- package/dist/lib/config/router.context.d.ts +0 -9
- package/dist/lib/config/router.context.mjs +0 -20
- package/dist/lib/react-query.types.d.ts +0 -10
- package/dist/lib/rest/error-handling.d.ts +0 -30
- package/dist/lib/rest/error-handling.mjs +0 -132
- package/dist/lib/rest/rest-client.d.ts +0 -22
- package/dist/lib/rest/rest-client.mjs +0 -62
- package/dist/lib/rest/rest-client.types.d.ts +0 -23
- package/dist/lib/rest/rest-interceptor.d.ts +0 -8
- package/dist/lib/rest/rest-interceptor.mjs +0 -21
- package/dist/lib/rest/rest.utils.d.ts +0 -7
- package/dist/lib/rest/rest.utils.mjs +0 -51
- package/dist/sh.d.ts +0 -2
- package/dist/sh.js +0 -635
|
@@ -1,16 +0,0 @@
|
|
|
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
|
-
export declare function primitiveTypeToTsType(type: PrimitiveType): string;
|
|
6
|
-
export declare function getTsTypeBase({ zodSchemaName, schema, resolver, }: {
|
|
7
|
-
zodSchemaName?: string;
|
|
8
|
-
schema?: OpenAPIV3.SchemaObject;
|
|
9
|
-
resolver: SchemaResolver;
|
|
10
|
-
}): TsTypeBase;
|
|
11
|
-
export declare function getSchemaTsMetaType({ schema, isCircular, parentTypes, resolver, }: {
|
|
12
|
-
schema?: OpenAPIV3.SchemaObject;
|
|
13
|
-
isCircular?: boolean;
|
|
14
|
-
parentTypes: TsTypeBase[];
|
|
15
|
-
resolver: SchemaResolver;
|
|
16
|
-
}): TsMetaType;
|
|
@@ -1,17 +0,0 @@
|
|
|
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
|
-
export declare function getInvalidSchemaError(message: string): ValidationError;
|
|
6
|
-
export declare function getInvalidOperationIdError(operationId: string): ValidationError;
|
|
7
|
-
export declare function getMissingPathParameterError(params: EndpointParameter[], path: string): ValidationError;
|
|
8
|
-
export declare function getNotAllowedInlineEnumError(enumProperty: string): ValidationError;
|
|
9
|
-
export declare function getNotAllowedCircularSchemaError(message: string): ValidationError;
|
|
10
|
-
export declare function getMissingAclConditionPropertyError(propertyName: string, operation: OperationObject, endpoint: Endpoint): ValidationError;
|
|
11
|
-
export declare function getMissingStatusCodeError(statusCode: HttpStatusCode, operation: OperationObject, endpoint: Endpoint): ValidationError;
|
|
12
|
-
export declare function getInvalidStatusCodeError(statusCode: {
|
|
13
|
-
expected: HttpStatusCode;
|
|
14
|
-
received: HttpStatusCode;
|
|
15
|
-
}, operation: OperationObject, endpoint: Endpoint): ValidationError;
|
|
16
|
-
export declare function getMultipleSuccessStatusCodesError(statusCodes: HttpStatusCode[], operation: OperationObject, endpoint: Endpoint): ValidationError;
|
|
17
|
-
export declare function groupByType(validationErrors: ValidationError[]): Record<ValidationErrorType, string[]>;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export declare const getZodSchemaName: (name: string, schemaSuffix: string) => string;
|
|
2
|
-
export declare const getEnumZodSchemaName: (name: string, enumSuffix: string, schemaSuffix: string) => string;
|
|
3
|
-
export declare const isNamedZodSchema: (schema: string) => boolean;
|
|
4
|
-
export declare const isEnumZodSchema: (schema: string) => boolean;
|
|
5
|
-
export declare const getZodSchemaOperationName: (operationName: string, isUniqueOperationName: boolean, tag: string) => string;
|
|
6
|
-
export declare const getBodyZodSchemaName: (operationName: string) => string;
|
|
7
|
-
export declare const getParamZodSchemaName: (operationName: string, paramName: string) => string;
|
|
8
|
-
export declare const getMainResponseZodSchemaName: (operationName: string) => string;
|
|
9
|
-
export declare const getErrorResponseZodSchemaName: (operationName: string, statusCode: string) => string;
|
|
10
|
-
export declare function getResponseZodSchemaName({ statusCode, operationName, isUniqueOperationName, tag, }: {
|
|
11
|
-
statusCode: string;
|
|
12
|
-
operationName: string;
|
|
13
|
-
isUniqueOperationName: boolean;
|
|
14
|
-
tag: string;
|
|
15
|
-
}): string;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Print a variable, color it magenta if it's different from the default
|
|
3
|
-
* @param name
|
|
4
|
-
* @param value
|
|
5
|
-
* @param defaultValue
|
|
6
|
-
*/
|
|
7
|
-
export declare function logVariable(name: string, value: any, defaultValue?: string | number): void;
|
|
8
|
-
export declare function log(message: string): void;
|
|
9
|
-
export declare function logInfo(message: string): void;
|
|
10
|
-
export declare function logNotice(message: string): void;
|
|
11
|
-
export declare function logSuccess(message: string): void;
|
|
12
|
-
export declare function logWarning(message: string): void;
|
|
13
|
-
export declare function logError(error: Error | string, message?: string): void;
|
|
14
|
-
export declare function logBanner(message: string): void;
|
|
15
|
-
/**
|
|
16
|
-
* Request a ENV variable from the user if not set
|
|
17
|
-
* @param name
|
|
18
|
-
* @param value
|
|
19
|
-
* @param suggested - the value the scripts expects and suggest
|
|
20
|
-
*/
|
|
21
|
-
export declare function promptVar(name: string, value: string, suggested?: string): Promise<string>;
|
|
22
|
-
export declare function confirm(message: string): Promise<boolean>;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Options } from 'yargs';
|
|
2
|
-
interface IOptionProperties extends Options {
|
|
3
|
-
envAlias?: string;
|
|
4
|
-
}
|
|
5
|
-
export declare function YargOption(properties: IOptionProperties): (target: object, propertyKey: string) => void;
|
|
6
|
-
export declare function getYargsOption<T>(target: any): Record<keyof T, IOptionProperties>;
|
|
7
|
-
export declare function getBuilder(options: any): (y: any) => Promise<any>;
|
|
8
|
-
export declare function getYargsOptions<T>(target: any): Record<keyof T, Options>;
|
|
9
|
-
export declare function loadYargsConfig<T>(cls: new () => T, _argv: Record<string, unknown>): Promise<T>;
|
|
10
|
-
export {};
|
package/dist/index.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
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 type { InvalidationMap } from './lib/config/queryConfig.context';
|
|
12
|
-
export { ns, resources } from './lib/config/i18n';
|
|
13
|
-
export { AuthContext } from './lib/auth/auth.context';
|
|
14
|
-
export { AuthGuard } from './lib/auth/AuthGuard';
|
|
15
|
-
export type { AuthGuardProps } from './lib/auth/AuthGuard';
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { PropsWithChildren } from 'react';
|
|
2
|
-
import { AppAbilities } from './appAbility.types';
|
|
3
|
-
interface AclGuardProps<TAppAbilities extends AppAbilities = AppAbilities> {
|
|
4
|
-
canUse: TAppAbilities;
|
|
5
|
-
redirectTo?: string;
|
|
6
|
-
}
|
|
7
|
-
export declare const createAclGuard: <TAppAbilities extends AppAbilities = AppAbilities>() => ({ canUse, redirectTo, children }: PropsWithChildren<AclGuardProps<TAppAbilities>>) => import('react').ReactNode;
|
|
8
|
-
export {};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { OpenApiRouter } from "../config/router.context.mjs";
|
|
2
|
-
import { AbilityContext } from "./ability.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
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { AbilityTuple, PureAbility } from '@casl/ability';
|
|
2
|
-
import { BoundCanProps } from '@casl/react';
|
|
3
|
-
import { AppAbilities } from './appAbility.types';
|
|
4
|
-
type CanAbility = PureAbility<AbilityTuple<AppAbilities[0], AppAbilities[1]>>;
|
|
5
|
-
type CanProps<TAppAbilities extends AppAbilities = AppAbilities> = {
|
|
6
|
-
use: TAppAbilities;
|
|
7
|
-
} & Omit<BoundCanProps<CanAbility>, "do" | "I" | "on" | "a" | "an" | "this">;
|
|
8
|
-
export declare const Can: <TAppAbilities extends AppAbilities = AppAbilities>({ use, ...props }: CanProps<TAppAbilities>) => import("react/jsx-runtime").JSX.Element;
|
|
9
|
-
export {};
|
package/dist/lib/acl/Can.mjs
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { createContextualCan } from "@casl/react";
|
|
3
|
-
import { AbilityContext } from "./ability.context.mjs";
|
|
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,15 +0,0 @@
|
|
|
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
|
-
export declare namespace AbilityContext {
|
|
6
|
-
export const Consumer: import("react").Consumer<AppAbility>;
|
|
7
|
-
interface ProviderProps {
|
|
8
|
-
user?: {
|
|
9
|
-
aclRules?: PackRule<RawRuleOf<AppAbility>>[];
|
|
10
|
-
} | null;
|
|
11
|
-
}
|
|
12
|
-
export const Provider: ({ children }: PropsWithChildren<ProviderProps>) => import("react/jsx-runtime").JSX.Element;
|
|
13
|
-
export const useAbility: <TAppAbilities extends AppAbilities = AppAbilities>() => PureAbility<TAppAbilities>;
|
|
14
|
-
export {};
|
|
15
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { jsx } from "react/jsx-runtime";
|
|
2
|
-
import { createContext, useState, useEffect } from "react";
|
|
3
|
-
import { AbilityBuilder, createMongoAbility } from "@casl/ability";
|
|
4
|
-
import { unpackRules } from "@casl/ability/extra";
|
|
5
|
-
import { useAbility } from "@casl/react";
|
|
6
|
-
import { AuthContext } from "../auth/auth.context.mjs";
|
|
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
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,8 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
1
|
-
import { PropsWithChildren } from 'react';
|
|
2
|
-
export interface AuthGuardProps {
|
|
3
|
-
type: "public-only" | "private";
|
|
4
|
-
redirectTo?: string;
|
|
5
|
-
}
|
|
6
|
-
export declare const AuthGuard: ({ type, redirectTo, children }: PropsWithChildren<AuthGuardProps>) => import('react').ReactNode;
|
|
@@ -1,26 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { PropsWithChildren, ReactNode } from 'react';
|
|
2
|
-
export declare namespace AuthContext {
|
|
3
|
-
export interface Routes {
|
|
4
|
-
authenticated?: string;
|
|
5
|
-
unauthenticated?: string;
|
|
6
|
-
}
|
|
7
|
-
interface Type<TUser = unknown> {
|
|
8
|
-
isAuthenticated: boolean;
|
|
9
|
-
isInitializing: boolean;
|
|
10
|
-
logout: () => void;
|
|
11
|
-
updateTokens?: (accessToken: string | null, refreshToken?: string | null) => void;
|
|
12
|
-
accessToken?: string | null;
|
|
13
|
-
user?: TUser | null;
|
|
14
|
-
userPromise?: () => Promise<TUser | null>;
|
|
15
|
-
routes?: Routes;
|
|
16
|
-
loadingState?: ReactNode;
|
|
17
|
-
}
|
|
18
|
-
type ProviderProps<TUser = unknown> = Type<TUser>;
|
|
19
|
-
export const Provider: <TUser>({ isAuthenticated, isInitializing, logout, updateTokens, accessToken, user, userPromise, routes, loadingState, children, }: PropsWithChildren<ProviderProps<TUser>>) => import("react/jsx-runtime").JSX.Element;
|
|
20
|
-
export const useAuth: <TUser>() => Type<TUser>;
|
|
21
|
-
export {};
|
|
22
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
export declare const ns = "openapi";
|
|
2
|
-
export declare const resources: {
|
|
3
|
-
readonly en: {
|
|
4
|
-
readonly openapi: {
|
|
5
|
-
openapi: {
|
|
6
|
-
sharedErrors: {
|
|
7
|
-
dataValidation: string;
|
|
8
|
-
internalError: string;
|
|
9
|
-
networkError: string;
|
|
10
|
-
canceledError: string;
|
|
11
|
-
unknownError: string;
|
|
12
|
-
unknownErrorWithCode: string;
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
readonly sl: {
|
|
18
|
-
readonly openapi: {
|
|
19
|
-
openapi: {
|
|
20
|
-
sharedErrors: {
|
|
21
|
-
dataValidation: string;
|
|
22
|
-
internalError: string;
|
|
23
|
-
networkError: string;
|
|
24
|
-
canceledError: string;
|
|
25
|
-
unknownError: string;
|
|
26
|
-
unknownErrorWithCode: string;
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
};
|
|
32
|
-
export declare const defaultT: import('i18next').TFunction<["translation", ...string[]], undefined>;
|
package/dist/lib/config/i18n.mjs
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { PropsWithChildren } from 'react';
|
|
2
|
-
import { QueryKey } from '@tanstack/react-query';
|
|
3
|
-
export type QueryModule = string | number | symbol;
|
|
4
|
-
export type InvalidationMapFunc<TData = any, TVariables = any> = (data: TData, variables: TVariables) => QueryKey[];
|
|
5
|
-
export type InvalidationMap<TData = any, TVariables = any> = Record<QueryModule, InvalidationMapFunc<TData, TVariables>>;
|
|
6
|
-
export declare namespace OpenApiQueryConfig {
|
|
7
|
-
interface Type {
|
|
8
|
-
preferUpdate?: boolean;
|
|
9
|
-
invalidateCurrentModule?: boolean;
|
|
10
|
-
invalidationMap?: InvalidationMap;
|
|
11
|
-
crossTabInvalidation?: boolean;
|
|
12
|
-
}
|
|
13
|
-
type ProviderProps = Type;
|
|
14
|
-
export const Provider: ({ preferUpdate, invalidateCurrentModule, invalidationMap, crossTabInvalidation, children, }: PropsWithChildren<ProviderProps>) => import("react/jsx-runtime").JSX.Element;
|
|
15
|
-
export const useConfig: () => Type;
|
|
16
|
-
export {};
|
|
17
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
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 = ({
|
|
7
|
-
preferUpdate,
|
|
8
|
-
invalidateCurrentModule,
|
|
9
|
-
invalidationMap,
|
|
10
|
-
crossTabInvalidation,
|
|
11
|
-
children
|
|
12
|
-
}) => {
|
|
13
|
-
const value = useMemo(
|
|
14
|
-
() => ({ preferUpdate, invalidateCurrentModule, invalidationMap, crossTabInvalidation }),
|
|
15
|
-
[preferUpdate, invalidateCurrentModule, invalidationMap, crossTabInvalidation]
|
|
16
|
-
);
|
|
17
|
-
return /* @__PURE__ */ jsx(Context.Provider, { value, children });
|
|
18
|
-
};
|
|
19
|
-
OpenApiQueryConfig2.useConfig = () => {
|
|
20
|
-
const context = use(Context);
|
|
21
|
-
return context ?? {};
|
|
22
|
-
};
|
|
23
|
-
})(OpenApiQueryConfig || (OpenApiQueryConfig = {}));
|
|
24
|
-
export {
|
|
25
|
-
OpenApiQueryConfig
|
|
26
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { PropsWithChildren } from 'react';
|
|
2
|
-
interface RouterProviderProps {
|
|
3
|
-
replace: (url: string) => void;
|
|
4
|
-
}
|
|
5
|
-
export declare namespace OpenApiRouter {
|
|
6
|
-
const Provider: ({ children, replace }: PropsWithChildren<RouterProviderProps>) => import("react/jsx-runtime").JSX.Element;
|
|
7
|
-
const useRouter: () => RouterProviderProps;
|
|
8
|
-
}
|
|
9
|
-
export {};
|
|
@@ -1,20 +0,0 @@
|
|
|
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,10 +0,0 @@
|
|
|
1
|
-
import { InfiniteData, QueryKey, UseInfiniteQueryOptions, UseMutationOptions, UseQueryOptions } from '@tanstack/react-query';
|
|
2
|
-
import { ApplicationException, GeneralErrorCodes } from './rest/error-handling';
|
|
3
|
-
type Function = (...args: any) => any;
|
|
4
|
-
type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N;
|
|
5
|
-
type IsAny<T> = IfAny<T, true, never>;
|
|
6
|
-
type IsUnknown<T, Y, N = T> = IsAny<T> extends never ? (unknown extends T ? Y : N) : N;
|
|
7
|
-
export type AppQueryOptions<TFunction extends Function, TData = Awaited<ReturnType<TFunction>>, TErrorCodes = GeneralErrorCodes> = Omit<UseQueryOptions<Awaited<ReturnType<TFunction>>, ApplicationException<TErrorCodes>, IsUnknown<TData, Awaited<ReturnType<TFunction>>>>, "queryKey" | "queryFn">;
|
|
8
|
-
export type AppMutationOptions<TFunction extends Function, TVariables = void, TData = Awaited<ReturnType<TFunction>>, TErrorCodes = GeneralErrorCodes> = Omit<UseMutationOptions<TData, ApplicationException<TErrorCodes>, TVariables>, "mutationKey" | "mutationFn">;
|
|
9
|
-
export type AppInfiniteQueryOptions<TFunction extends Function, TData = InfiniteData<Awaited<ReturnType<TFunction>>>, TErrorCodes = GeneralErrorCodes, TQueryKey extends QueryKey = QueryKey, TPageParam = number> = Omit<UseInfiniteQueryOptions<Awaited<ReturnType<TFunction>>, ApplicationException<TErrorCodes>, IsUnknown<TData, InfiniteData<Awaited<ReturnType<TFunction>>>>, TQueryKey, TPageParam>, "queryKey" | "queryFn" | "initialPageParam" | "getNextPageParam">;
|
|
10
|
-
export {};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { TFunction } from 'i18next';
|
|
2
|
-
export type GeneralErrorCodes = "DATA_VALIDATION_ERROR" | "NETWORK_ERROR" | "CANCELED_ERROR" | "INTERNAL_ERROR" | "UNKNOWN_ERROR";
|
|
3
|
-
export declare class ApplicationException<CodeT> extends Error {
|
|
4
|
-
code: CodeT;
|
|
5
|
-
serverMessage: string | null;
|
|
6
|
-
constructor(message: string, code: CodeT, serverMessage: string | null);
|
|
7
|
-
}
|
|
8
|
-
export interface ErrorEntry<CodeT> {
|
|
9
|
-
code: CodeT;
|
|
10
|
-
condition?: (error: unknown) => boolean;
|
|
11
|
-
getMessage: (t: TFunction, error: unknown) => string;
|
|
12
|
-
}
|
|
13
|
-
export interface ErrorHandlerOptions<CodeT extends string> {
|
|
14
|
-
entries: ErrorEntry<CodeT>[];
|
|
15
|
-
t?: TFunction;
|
|
16
|
-
onRethrowError?: (error: unknown, exception: ApplicationException<CodeT | GeneralErrorCodes>) => void;
|
|
17
|
-
}
|
|
18
|
-
export declare class ErrorHandler<CodeT extends string> {
|
|
19
|
-
entries: ErrorEntry<CodeT | GeneralErrorCodes>[];
|
|
20
|
-
private t;
|
|
21
|
-
private onRethrowError?;
|
|
22
|
-
constructor({ entries, t, onRethrowError }: ErrorHandlerOptions<CodeT>);
|
|
23
|
-
private matchesEntry;
|
|
24
|
-
setTranslateFunction(t: TFunction): void;
|
|
25
|
-
rethrowError(error: unknown): ApplicationException<CodeT | GeneralErrorCodes>;
|
|
26
|
-
getError(error: unknown): ApplicationException<CodeT | GeneralErrorCodes> | null;
|
|
27
|
-
getErrorCode(error: unknown): CodeT | GeneralErrorCodes | null;
|
|
28
|
-
static getErrorMessage(error: unknown, fallbackToUnknown?: boolean): string | null;
|
|
29
|
-
}
|
|
30
|
-
export declare const SharedErrorHandler: ErrorHandler<never>;
|