@povio/openapi-codegen-cli 2.0.8-rc.37 → 2.0.8-rc.39

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.
Files changed (191) hide show
  1. package/README.md +0 -87
  2. package/dist/acl.d.ts +4 -0
  3. package/dist/acl.mjs +7 -73
  4. package/dist/commands/check.command.d.ts +2 -0
  5. package/dist/commands/check.d.ts +7 -0
  6. package/dist/commands/generate.command.d.ts +2 -0
  7. package/dist/commands/generate.d.ts +8 -0
  8. package/dist/generator.d.ts +3 -0
  9. package/dist/generator.js +78 -0
  10. package/dist/generators/checkOpenAPIDoc.d.ts +3 -0
  11. package/dist/generators/const/acl.const.d.ts +13 -0
  12. package/dist/generators/const/buildConfigs.const.d.ts +1 -0
  13. package/dist/generators/const/deps.const.d.ts +38 -0
  14. package/dist/generators/const/endpoints.const.d.ts +11 -0
  15. package/dist/generators/const/js.const.d.ts +1 -0
  16. package/dist/generators/const/openapi.const.d.ts +7 -0
  17. package/dist/generators/const/options.const.d.ts +2 -0
  18. package/dist/generators/const/package.const.d.ts +2 -0
  19. package/dist/generators/const/queries.const.d.ts +8 -0
  20. package/dist/generators/const/validation.const.d.ts +53 -0
  21. package/dist/generators/const/zod.const.d.ts +19 -0
  22. package/dist/generators/core/SchemaResolver.class.d.ts +71 -0
  23. package/dist/generators/core/endpoints/getEndpointAcl.d.ts +8 -0
  24. package/dist/generators/core/endpoints/getEndpointBody.d.ts +13 -0
  25. package/dist/generators/core/endpoints/getEndpointParameter.d.ts +11 -0
  26. package/dist/generators/core/endpoints/getEndpointsFromOpenAPIDoc.d.ts +3 -0
  27. package/dist/generators/core/endpoints/getEndpointsFromOpenAPIDoc.test.d.ts +1 -0
  28. package/dist/generators/core/getDataFromOpenAPIDoc.d.ts +8 -0
  29. package/dist/generators/core/getMetadataFromOpenAPIDoc.d.ts +4 -0
  30. package/dist/generators/core/getMetadataFromOpenAPIDoc.test.d.ts +1 -0
  31. package/dist/generators/core/openapi/getOpenAPISchemaComplexity.d.ts +2 -0
  32. package/dist/generators/core/openapi/getOpenAPISchemaComplexity.test.d.ts +1 -0
  33. package/dist/generators/core/openapi/getOpenAPISchemaDependencyGraph.d.ts +6 -0
  34. package/dist/generators/core/openapi/getOpenAPISchemaDependencyGraph.test.d.ts +1 -0
  35. package/dist/generators/core/openapi/getSchemaRefObjs.d.ts +4 -0
  36. package/dist/generators/core/openapi/iterateSchema.d.ts +22 -0
  37. package/dist/generators/core/resolveConfig.d.ts +7 -0
  38. package/dist/generators/core/zod/ZodSchema.class.d.ts +26 -0
  39. package/dist/generators/core/zod/enumExtraction/resolveExtractedEnumZodSchemaNames.d.ts +2 -0
  40. package/dist/generators/core/zod/enumExtraction/resolveExtractedEnumZodSchemaTags.d.ts +2 -0
  41. package/dist/generators/core/zod/enumExtraction/updateExtractedEnumZodSchemaData.d.ts +17 -0
  42. package/dist/generators/core/zod/getZodChain.d.ts +8 -0
  43. package/dist/generators/core/zod/getZodSchema.d.ts +17 -0
  44. package/dist/generators/core/zod/getZodSchema.test.d.ts +1 -0
  45. package/dist/generators/core/zod/getZodSchemaRefs.d.ts +6 -0
  46. package/dist/generators/core/zod/getZodSchemasFromOpenAPIDoc.d.ts +6 -0
  47. package/dist/generators/core/zod/resolveZodSchemaName.d.ts +10 -0
  48. package/dist/generators/core/zod/sortZodSchemasByTopology.d.ts +4 -0
  49. package/dist/generators/generate/generateAcl.d.ts +3 -0
  50. package/dist/generators/generate/generateAclCheck.d.ts +2 -0
  51. package/dist/generators/generate/generateAppRestClient.d.ts +2 -0
  52. package/dist/generators/generate/generateConfigs.d.ts +2 -0
  53. package/dist/generators/generate/generateEndpoints.d.ts +2 -0
  54. package/dist/generators/generate/generateModels.d.ts +2 -0
  55. package/dist/generators/generate/generateQueries.d.ts +2 -0
  56. package/dist/generators/generate/generateQueryModules.d.ts +2 -0
  57. package/dist/generators/generate/generateZodExtended.d.ts +2 -0
  58. package/dist/generators/generateCodeFromOpenAPIDoc.d.ts +4 -0
  59. package/dist/generators/types/builder-config.d.ts +48 -0
  60. package/dist/generators/types/common.d.ts +27 -0
  61. package/dist/generators/types/config.d.ts +2 -0
  62. package/dist/generators/types/endpoint.d.ts +50 -0
  63. package/dist/generators/types/generate.d.ts +39 -0
  64. package/dist/generators/types/metadata.d.ts +51 -0
  65. package/dist/generators/types/openapi.d.ts +22 -0
  66. package/dist/generators/types/options.d.ts +66 -0
  67. package/dist/generators/types/validation.d.ts +5 -0
  68. package/dist/generators/utils/array.utils.d.ts +1 -0
  69. package/dist/generators/utils/endpoint.utils.d.ts +12 -0
  70. package/dist/generators/utils/endpoint.utils.test.d.ts +1 -0
  71. package/dist/generators/utils/file.utils.d.ts +8 -0
  72. package/dist/generators/utils/generate/generate.acl.utils.d.ts +23 -0
  73. package/dist/generators/utils/generate/generate.configs.utils.d.ts +15 -0
  74. package/dist/generators/utils/generate/generate.endpoints.utils.d.ts +41 -0
  75. package/dist/generators/utils/generate/generate.imports.utils.d.ts +39 -0
  76. package/dist/generators/utils/generate/generate.imports.utils.test.d.ts +1 -0
  77. package/dist/generators/utils/generate/generate.openapi.utils.d.ts +2 -0
  78. package/dist/generators/utils/generate/generate.query.utils.d.ts +6 -0
  79. package/dist/generators/utils/generate/generate.utils.d.ts +18 -0
  80. package/dist/generators/utils/generate/generate.zod.utils.d.ts +13 -0
  81. package/dist/generators/utils/generate-files.utils.d.ts +6 -0
  82. package/dist/generators/utils/hbs/hbs-template.utils.d.ts +3 -0
  83. package/dist/generators/utils/hbs/hbs.acl.utils.d.ts +2 -0
  84. package/dist/generators/utils/hbs/hbs.common.utils.d.ts +1 -0
  85. package/dist/generators/utils/hbs/hbs.endpoints.utils.d.ts +2 -0
  86. package/dist/generators/utils/hbs/hbs.imports.utils.d.ts +1 -0
  87. package/dist/generators/utils/hbs/hbs.partials.utils.d.ts +2 -0
  88. package/dist/generators/utils/hbs/hbs.query.utils.d.ts +2 -0
  89. package/dist/generators/utils/hbs/hbs.zod.utils.d.ts +2 -0
  90. package/dist/generators/utils/js.utils.d.ts +2 -0
  91. package/dist/generators/utils/js.utils.test.d.ts +1 -0
  92. package/dist/generators/utils/math.utils.d.ts +1 -0
  93. package/dist/generators/utils/namespace.utils.d.ts +7 -0
  94. package/dist/generators/utils/object.utils.d.ts +13 -0
  95. package/dist/generators/utils/object.utils.test.d.ts +1 -0
  96. package/dist/generators/utils/openapi-schema.utils.d.ts +15 -0
  97. package/dist/generators/utils/openapi.utils.d.ts +23 -0
  98. package/dist/generators/utils/openapi.utils.test.d.ts +1 -0
  99. package/dist/generators/utils/operation.utils.d.ts +22 -0
  100. package/dist/generators/utils/operation.utils.test.d.ts +1 -0
  101. package/dist/generators/utils/query.utils.d.ts +7 -0
  102. package/dist/generators/utils/sort.utils.d.ts +7 -0
  103. package/dist/generators/utils/string.utils.d.ts +14 -0
  104. package/dist/generators/utils/string.utils.test.d.ts +1 -0
  105. package/dist/generators/utils/tag.utils.d.ts +7 -0
  106. package/dist/generators/utils/ts.utils.d.ts +16 -0
  107. package/dist/generators/utils/validation.utils.d.ts +17 -0
  108. package/dist/generators/utils/zod-schema.utils.d.ts +15 -0
  109. package/dist/helpers/cli.helper.d.ts +22 -0
  110. package/dist/helpers/config.helper.d.ts +3 -0
  111. package/dist/helpers/version.helper.d.ts +4 -0
  112. package/dist/helpers/yargs.helper.d.ts +10 -0
  113. package/dist/index.d.ts +15 -0
  114. package/dist/index.mjs +22 -252
  115. package/dist/lib/acl/AclGuard.d.ts +8 -0
  116. package/dist/lib/acl/AclGuard.mjs +14 -0
  117. package/dist/lib/acl/Can.d.ts +9 -0
  118. package/dist/lib/acl/Can.mjs +11 -0
  119. package/dist/lib/acl/ability.context.d.ts +15 -0
  120. package/dist/lib/acl/ability.context.mjs +37 -0
  121. package/dist/lib/acl/appAbility.types.d.ts +3 -0
  122. package/dist/lib/assets/locales/en/translation.json.mjs +8 -0
  123. package/dist/lib/assets/locales/sl/translation.json.mjs +8 -0
  124. package/dist/lib/auth/AuthGuard.d.ts +6 -0
  125. package/dist/lib/auth/AuthGuard.mjs +26 -0
  126. package/dist/lib/auth/auth.context.d.ts +22 -0
  127. package/dist/lib/auth/auth.context.mjs +41 -0
  128. package/dist/lib/config/i18n.d.ts +32 -0
  129. package/dist/lib/config/i18n.mjs +31 -0
  130. package/dist/lib/config/queryConfig.context.d.ts +17 -0
  131. package/dist/lib/config/queryConfig.context.mjs +26 -0
  132. package/dist/lib/config/router.context.d.ts +9 -0
  133. package/dist/lib/config/router.context.mjs +20 -0
  134. package/dist/lib/react-query.types.d.ts +10 -0
  135. package/dist/lib/rest/error-handling.d.ts +30 -0
  136. package/dist/lib/rest/error-handling.mjs +132 -0
  137. package/dist/lib/rest/rest-client.d.ts +22 -0
  138. package/dist/lib/rest/rest-client.mjs +62 -0
  139. package/dist/lib/rest/rest-client.types.d.ts +23 -0
  140. package/dist/lib/rest/rest-interceptor.d.ts +8 -0
  141. package/dist/lib/rest/rest-interceptor.mjs +21 -0
  142. package/dist/lib/rest/rest.utils.d.ts +7 -0
  143. package/dist/lib/rest/rest.utils.mjs +51 -0
  144. package/dist/sh.d.ts +2 -0
  145. package/dist/sh.js +649 -0
  146. package/package.json +43 -51
  147. package/src/assets/useCrossTabQueryInvalidation.ts +40 -0
  148. package/src/assets/useMutationEffects.ts +94 -0
  149. package/src/generators/templates/acl-check.hbs +29 -0
  150. package/src/generators/templates/acl.hbs +19 -0
  151. package/src/generators/templates/app-acl.hbs +17 -0
  152. package/src/generators/templates/app-rest-client.hbs +7 -0
  153. package/src/generators/templates/configs.hbs +80 -0
  154. package/src/generators/templates/endpoints.hbs +44 -0
  155. package/src/generators/templates/models.hbs +23 -0
  156. package/src/generators/templates/partials/acl-check-call.hbs +1 -0
  157. package/src/generators/templates/partials/casl-ability-function.hbs +12 -0
  158. package/src/generators/templates/partials/casl-ability-query.hbs +1 -0
  159. package/src/generators/templates/partials/casl-ability-type.hbs +1 -0
  160. package/src/generators/templates/partials/columns-config.hbs +11 -0
  161. package/src/generators/templates/partials/endpoint-config.hbs +31 -0
  162. package/src/generators/templates/partials/endpoint-param-parse.hbs +1 -0
  163. package/src/generators/templates/partials/endpoint-params.hbs +1 -0
  164. package/src/generators/templates/partials/import.hbs +1 -0
  165. package/src/generators/templates/partials/inputs-config.hbs +10 -0
  166. package/src/generators/templates/partials/model-js-docs.hbs +6 -0
  167. package/src/generators/templates/partials/query-js-docs.hbs +31 -0
  168. package/src/generators/templates/partials/query-keys.hbs +11 -0
  169. package/src/generators/templates/partials/query-use-infinite-query.hbs +22 -0
  170. package/src/generators/templates/partials/query-use-mutation.hbs +54 -0
  171. package/src/generators/templates/partials/query-use-query.hbs +17 -0
  172. package/src/generators/templates/queries.hbs +54 -0
  173. package/src/generators/templates/query-modules.hbs +5 -0
  174. package/src/generators/templates/zod-extended.hbs +49 -0
  175. package/dist/acl.d.mts +0 -59
  176. package/dist/auth.context-Bu5KW2sI.mjs +0 -59
  177. package/dist/config-DTx4Ck6g.d.mts +0 -6
  178. package/dist/error-handling-CXeVTk1T.d.mts +0 -38
  179. package/dist/error-handling-DkPY7Asf.mjs +0 -187
  180. package/dist/generate.runner-DLLGYMVB.mjs +0 -90
  181. package/dist/generateCodeFromOpenAPIDoc-CFbiHxB7.mjs +0 -4729
  182. package/dist/generator.d.mts +0 -65
  183. package/dist/generator.mjs +0 -144
  184. package/dist/index.d.mts +0 -231
  185. package/dist/options-fyt0BYYE.d.mts +0 -95
  186. package/dist/sh.d.mts +0 -1
  187. package/dist/sh.mjs +0 -450
  188. package/dist/vite.d.mts +0 -11
  189. package/dist/vite.mjs +0 -53
  190. package/dist/zod.d.mts +0 -20
  191. package/dist/zod.mjs +0 -33
@@ -0,0 +1,16 @@
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;
@@ -0,0 +1,17 @@
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[]>;
@@ -0,0 +1,15 @@
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;
@@ -0,0 +1,22 @@
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>;
@@ -0,0 +1,3 @@
1
+ import { OpenAPICodegenConfig } from '../generators/types/config';
2
+ export declare function loadConfig(configPath?: string): Promise<OpenAPICodegenConfig | null>;
3
+ export declare const loadJsSync: (filepath: string) => unknown;
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Fetch the version from package.json
3
+ */
4
+ export declare function getVersion(): string | undefined;
@@ -0,0 +1,10 @@
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 {};
@@ -0,0 +1,15 @@
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';
package/dist/index.mjs CHANGED
@@ -1,253 +1,23 @@
1
- import { a as ns, i as RestUtils, n as ErrorHandler, o as resources, r as SharedErrorHandler, t as ApplicationException } from "./error-handling-DkPY7Asf.mjs";
2
- import { n as OpenApiRouter, t as AuthContext } from "./auth.context-Bu5KW2sI.mjs";
3
- import axios from "axios";
4
- import { z } from "zod";
5
- import { createContext, use, useCallback, useEffect, useMemo, useState } from "react";
6
- import { useQueryClient } from "@tanstack/react-query";
7
- import { jsx } from "react/jsx-runtime";
8
-
9
- //#region src/lib/rest/rest-client.ts
10
- var RestClient = class {
11
- client;
12
- errorHandler;
13
- constructor({ config, interceptors, errorHandler } = {}) {
14
- this.client = axios.create(config);
15
- this.errorHandler = errorHandler ?? SharedErrorHandler;
16
- this.attachInterceptors(interceptors);
17
- }
18
- attachInterceptors(interceptors, ...args) {
19
- if (interceptors != null) interceptors.forEach((interceptor) => this.attachInterceptor(interceptor, ...args));
20
- }
21
- attachInterceptor(interceptor, ...args) {
22
- interceptor.addInterceptor(this.client, ...args);
23
- }
24
- ejectInterceptor(interceptor) {
25
- interceptor.removeInterceptor(this.client);
26
- }
27
- async get(requestInfo, url, requestConfig) {
28
- return this.makeRequest(requestInfo, {
29
- ...requestConfig,
30
- method: "get",
31
- url
32
- });
33
- }
34
- async post(requestInfo, url, data, requestConfig) {
35
- return this.makeRequest(requestInfo, {
36
- ...requestConfig,
37
- method: "post",
38
- url,
39
- data
40
- });
41
- }
42
- async patch(requestInfo, url, data, requestConfig) {
43
- return this.makeRequest(requestInfo, {
44
- ...requestConfig,
45
- method: "patch",
46
- url,
47
- data
48
- });
49
- }
50
- async put(requestInfo, url, data, requestConfig) {
51
- return this.makeRequest(requestInfo, {
52
- ...requestConfig,
53
- method: "put",
54
- url,
55
- data
56
- });
57
- }
58
- async delete(requestInfo, url, data, requestConfig) {
59
- return this.makeRequest(requestInfo, {
60
- ...requestConfig,
61
- method: "delete",
62
- url,
63
- data
64
- });
65
- }
66
- async makeRequest(requestInfo, requestConfig) {
67
- const errorStack = (/* @__PURE__ */ new Error()).stack;
68
- try {
69
- const { rawResponse, ...config } = requestConfig;
70
- const res = await this.client(config);
71
- const resData = requestInfo.resSchema.parse(res.data);
72
- return rawResponse ? {
73
- ...res,
74
- data: resData
75
- } : resData;
76
- } catch (error) {
77
- if (error instanceof z.ZodError) {
78
- error.name = "BE Response schema mismatch - ZodError";
79
- error.stack = [error.stack, ...errorStack?.split("\n").slice(2) ?? []].join("\n");
80
- }
81
- (requestInfo.errorHandler ?? this.errorHandler).rethrowError(error);
82
- throw error;
83
- }
84
- }
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
85
23
  };
86
-
87
- //#endregion
88
- //#region src/lib/rest/rest-interceptor.ts
89
- var RestInterceptor = class {
90
- interceptorIdMap = [];
91
- constructor(applyInterceptor) {
92
- this.applyInterceptor = applyInterceptor;
93
- }
94
- addInterceptor(client, ...args) {
95
- this.removeInterceptor(client);
96
- const interceptorId = this.applyInterceptor(client, ...args);
97
- this.interceptorIdMap.push({
98
- client,
99
- interceptorId
100
- });
101
- }
102
- removeInterceptor(client) {
103
- const interceptorId = this.interceptorIdMap.find((i) => i.client === client)?.interceptorId;
104
- if (interceptorId != null) {
105
- client.interceptors.request.eject(interceptorId);
106
- this.interceptorIdMap = this.interceptorIdMap.filter((i) => i.client !== client);
107
- }
108
- }
109
- };
110
-
111
- //#endregion
112
- //#region src/lib/config/queryConfig.context.tsx
113
- let OpenApiQueryConfig;
114
- (function(_OpenApiQueryConfig) {
115
- const Context = createContext({});
116
- function Provider({ preferUpdate, invalidateCurrentModule, invalidationMap, crossTabInvalidation, onError, children }) {
117
- const value = useMemo(() => ({
118
- preferUpdate,
119
- invalidateCurrentModule,
120
- invalidationMap,
121
- crossTabInvalidation,
122
- onError
123
- }), [
124
- preferUpdate,
125
- invalidateCurrentModule,
126
- invalidationMap,
127
- crossTabInvalidation,
128
- onError
129
- ]);
130
- return /* @__PURE__ */ jsx(Context.Provider, {
131
- value,
132
- children
133
- });
134
- }
135
- _OpenApiQueryConfig.Provider = Provider;
136
- _OpenApiQueryConfig.useConfig = () => {
137
- return use(Context) ?? {};
138
- };
139
- })(OpenApiQueryConfig || (OpenApiQueryConfig = {}));
140
-
141
- //#endregion
142
- //#region src/lib/react-query/cross-tab-invalidation.ts
143
- const CROSS_TAB_INVALIDATE_KEY = "__rq_invalidate__";
144
- const broadcastQueryInvalidation = (queryKeys) => {
145
- localStorage.setItem(CROSS_TAB_INVALIDATE_KEY, JSON.stringify({
146
- keys: queryKeys,
147
- timestamp: Date.now()
148
- }));
149
- };
150
- let isListenerSetUp = false;
151
- const setupCrossTabListener = (queryClient) => {
152
- if (isListenerSetUp) return;
153
- isListenerSetUp = true;
154
- window.addEventListener("storage", (e) => {
155
- if (e.key !== CROSS_TAB_INVALIDATE_KEY || !e.newValue) return;
156
- try {
157
- const { keys } = JSON.parse(e.newValue);
158
- for (const queryKey of keys) queryClient.invalidateQueries({ queryKey });
159
- } catch {}
160
- });
161
- };
162
-
163
- //#endregion
164
- //#region src/lib/react-query/useMutationEffects.ts
165
- function useMutationEffects({ currentModule }) {
166
- const queryClient = useQueryClient();
167
- const config = OpenApiQueryConfig.useConfig();
168
- useEffect(() => {
169
- if (!config.crossTabInvalidation) return;
170
- setupCrossTabListener(queryClient);
171
- }, [queryClient, config.crossTabInvalidation]);
172
- return { runMutationEffects: useCallback(async (data, variables, options = {}, updateKeys) => {
173
- const { invalidateCurrentModule, invalidationMap, invalidateModules, invalidateKeys, preferUpdate } = options;
174
- const shouldUpdate = preferUpdate ?? config.preferUpdate ?? false;
175
- const shouldInvalidateCurrentModule = invalidateCurrentModule ?? config.invalidateCurrentModule ?? true;
176
- const isQueryKeyEqual = (keyA, keyB) => keyA.length === keyB.length && keyA.every((item, index) => item === keyB[index]);
177
- const isQueryKeyPrefix = (queryKey, prefixKey) => prefixKey.length <= queryKey.length && prefixKey.every((item, index) => item === queryKey[index]);
178
- const mappedInvalidationKeys = invalidationMap?.[currentModule]?.(data, variables) ?? config.invalidationMap?.[currentModule]?.(data, variables);
179
- const shouldInvalidateQuery = (queryKey) => {
180
- const isUpdateKey = updateKeys?.some((key) => isQueryKeyEqual(queryKey, key));
181
- if (shouldUpdate && isUpdateKey) return false;
182
- const isCurrentModule = shouldInvalidateCurrentModule && queryKey[0] === currentModule;
183
- const isInvalidateModule = !!invalidateModules && invalidateModules.some((module) => queryKey[0] === module);
184
- const isInvalidateKey = !!invalidateKeys && invalidateKeys.some((key) => isQueryKeyPrefix(queryKey, key));
185
- const isMappedKey = !!mappedInvalidationKeys && mappedInvalidationKeys.some((key) => isQueryKeyPrefix(queryKey, key));
186
- return isCurrentModule || isInvalidateModule || isInvalidateKey || isMappedKey;
187
- };
188
- const invalidatedQueryKeys = [];
189
- const shouldBroadcast = options.crossTabInvalidation ?? config.crossTabInvalidation;
190
- queryClient.invalidateQueries({ predicate: ({ queryKey }) => {
191
- const shouldInvalidate = shouldInvalidateQuery(queryKey);
192
- if (shouldInvalidate && shouldBroadcast) invalidatedQueryKeys.push([...queryKey]);
193
- return shouldInvalidate;
194
- } });
195
- if (shouldBroadcast && invalidatedQueryKeys.length > 0) broadcastQueryInvalidation(invalidatedQueryKeys);
196
- if (shouldUpdate && updateKeys) updateKeys.map((queryKey) => queryClient.setQueryData(queryKey, data));
197
- }, [
198
- queryClient,
199
- currentModule,
200
- config.preferUpdate,
201
- config.invalidateCurrentModule,
202
- config.invalidationMap,
203
- config.crossTabInvalidation
204
- ]) };
205
- }
206
-
207
- //#endregion
208
- //#region src/lib/config/workspace.context.tsx
209
- let OpenApiWorkspaceContext;
210
- (function(_OpenApiWorkspaceContext) {
211
- const Context = createContext({});
212
- _OpenApiWorkspaceContext.Provider = ({ values, children }) => {
213
- const contextValues = useMemo(() => values ?? {}, [values]);
214
- return /* @__PURE__ */ jsx(Context.Provider, {
215
- value: contextValues,
216
- children
217
- });
218
- };
219
- _OpenApiWorkspaceContext.useContext = () => {
220
- return use(Context);
221
- };
222
- _OpenApiWorkspaceContext.resolveParam = (context, name, value) => {
223
- if (value != null) return value;
224
- const workspaceValue = context[name];
225
- if (workspaceValue == null) throw new Error(`Missing workspace context param "${name}"`);
226
- return workspaceValue;
227
- };
228
- })(OpenApiWorkspaceContext || (OpenApiWorkspaceContext = {}));
229
- const useWorkspaceContext = () => OpenApiWorkspaceContext.useContext();
230
-
231
- //#endregion
232
- //#region src/lib/auth/AuthGuard.tsx
233
- const AuthGuard = ({ type, redirectTo, children }) => {
234
- const { isAuthenticated, routes, loadingState } = AuthContext.useAuth();
235
- const { replace } = OpenApiRouter.useRouter();
236
- const [hasMounted, setHasMounted] = useState(false);
237
- useEffect(() => {
238
- setHasMounted(true);
239
- }, []);
240
- if (!hasMounted) return loadingState;
241
- if (type === "private" && !isAuthenticated) {
242
- replace(redirectTo || routes?.unauthenticated || "/");
243
- return null;
244
- }
245
- if (type === "public-only" && isAuthenticated) {
246
- replace(redirectTo || routes?.authenticated || "/");
247
- return null;
248
- }
249
- return children;
250
- };
251
-
252
- //#endregion
253
- export { ApplicationException, AuthContext, AuthGuard, ErrorHandler, OpenApiQueryConfig, OpenApiRouter, OpenApiWorkspaceContext, RestClient, RestInterceptor, RestUtils, SharedErrorHandler, ns, resources, useMutationEffects, useWorkspaceContext };
@@ -0,0 +1,8 @@
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 {};
@@ -0,0 +1,14 @@
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
+ };
@@ -0,0 +1,9 @@
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 {};
@@ -0,0 +1,11 @@
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
+ };
@@ -0,0 +1,15 @@
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
+ }
@@ -0,0 +1,37 @@
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
+ };
@@ -0,0 +1,3 @@
1
+ import { AbilityTuple, PureAbility, Subject } from '@casl/ability';
2
+ export type AppAbilities = AbilityTuple<string, Subject>;
3
+ export type AppAbility = PureAbility<AppAbilities>;
@@ -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
+ };
@@ -0,0 +1,6 @@
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;
@@ -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,22 @@
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
+ }
@@ -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,32 @@
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>;