oip-common 0.0.6 → 0.0.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.
Files changed (105) hide show
  1. package/ng-package.json +19 -0
  2. package/package.json +19 -38
  3. package/src/api/FolderModule.ts +124 -0
  4. package/src/api/Menu.ts +134 -0
  5. package/src/api/Module.ts +92 -0
  6. package/src/api/Security.ts +40 -0
  7. package/src/api/Service.ts +57 -0
  8. package/src/api/data-contracts.ts +186 -0
  9. package/src/api/http-client.ts +276 -0
  10. package/src/components/app-configurator.component.ts +491 -0
  11. package/src/components/app-floating-configurator.component.ts +47 -0
  12. package/src/components/app-modules.component.ts +144 -0
  13. package/src/components/app.layout.component.ts +130 -0
  14. package/src/components/auth/access/access.component.ts +42 -0
  15. package/src/components/auth/error/error.component.ts +42 -0
  16. package/src/components/auth/login/login.component.ts +120 -0
  17. package/src/components/auth/unauthorized/unauthorized.component.ts +51 -0
  18. package/src/components/base-module.component.ts +258 -0
  19. package/src/components/config.component.ts +131 -0
  20. package/src/components/db-migration/db-migration.component.ts +164 -0
  21. package/src/components/db-migration.component.ts +156 -0
  22. package/src/components/footer.component.ts +17 -0
  23. package/src/components/logo.component.ts +34 -0
  24. package/src/components/menu/menu-item-create-dialog.component.ts +119 -0
  25. package/src/components/menu/menu-item-edit-dialog.component.ts +124 -0
  26. package/src/components/menu/menu-item.component.ts +295 -0
  27. package/src/components/menu/menu.component.ts +85 -0
  28. package/src/components/notfound.component.ts +31 -0
  29. package/src/components/profile.component.ts +44 -0
  30. package/src/components/security.component.ts +102 -0
  31. package/src/components/sidebar.component.ts +12 -0
  32. package/src/components/top-bar.component.ts +147 -0
  33. package/src/dtos/context-menu-item.dto.ts +23 -0
  34. package/src/dtos/edit-module-instance.dto.ts +8 -0
  35. package/src/dtos/no-settings.dto.ts +4 -0
  36. package/src/dtos/put-security.dto.ts +6 -0
  37. package/src/dtos/security.dto.ts +6 -0
  38. package/src/dtos/top-bar.dto.ts +13 -0
  39. package/src/events/menu-change.event.ts +23 -0
  40. package/src/helpers/date.helper.ts +94 -0
  41. package/src/intercepts/i18n-intercept.service.ts +13 -0
  42. package/src/modules/http-loader.factory.ts +40 -0
  43. package/src/modules/secure.pipe.ts +19 -0
  44. package/src/public-api.ts +42 -0
  45. package/src/services/app-title.service.ts +22 -0
  46. package/src/services/app.layout.service.ts +236 -0
  47. package/src/services/app.menu.service.ts +64 -0
  48. package/src/services/auth.service.ts +58 -0
  49. package/src/services/base-data.service.ts +74 -0
  50. package/src/services/l10n.service.ts +71 -0
  51. package/src/services/msg.service.ts +76 -0
  52. package/src/services/security-data.service.ts +19 -0
  53. package/src/services/security-storage.service.ts +21 -0
  54. package/src/services/security.service.ts +116 -0
  55. package/src/services/top-bar.service.ts +44 -0
  56. package/src/services/user.service.ts +77 -0
  57. package/src/test.ts +11 -0
  58. package/src/user-api/UserProfile.ts +85 -0
  59. package/src/user-api/data-contracts.ts +42 -0
  60. package/src/user-api/http-client.ts +253 -0
  61. package/templates/api.ejs +30 -0
  62. package/templates/data-contract-jsdoc.ejs +37 -0
  63. package/templates/data-contracts.ejs +52 -0
  64. package/templates/enum-data-contract.ejs +12 -0
  65. package/templates/http-client.ejs +245 -0
  66. package/templates/interface-data-contract.ejs +10 -0
  67. package/templates/object-field-jsdoc.ejs +28 -0
  68. package/templates/procedure-call.ejs +100 -0
  69. package/templates/route-docs.ejs +29 -0
  70. package/templates/route-name.ejs +42 -0
  71. package/templates/route-type.ejs +23 -0
  72. package/templates/route-types.ejs +18 -0
  73. package/templates/type-data-contract.ejs +15 -0
  74. package/tsconfig.lib.json +12 -0
  75. package/tsconfig.lib.prod.json +10 -0
  76. package/tsconfig.spec.json +9 -0
  77. /package/{assets → src/assets}/demo/code.scss +0 -0
  78. /package/{assets → src/assets}/demo/demo.scss +0 -0
  79. /package/{assets → src/assets}/demo/flags/flags.scss +0 -0
  80. /package/{assets → src/assets}/demo/flags/flags_responsive.png +0 -0
  81. /package/{assets → src/assets}/demo/images/access/asset-access.svg +0 -0
  82. /package/{assets → src/assets}/demo/images/error/asset-error.svg +0 -0
  83. /package/{assets → src/assets}/demo/images/flag/flag_placeholder.png +0 -0
  84. /package/{assets → src/assets}/favicon.svg +0 -0
  85. /package/{assets → src/assets}/i18n/app-modules.en.json +0 -0
  86. /package/{assets → src/assets}/i18n/app-modules.ru.json +0 -0
  87. /package/{assets → src/assets}/i18n/config.en.json +0 -0
  88. /package/{assets → src/assets}/i18n/config.ru.json +0 -0
  89. /package/{assets → src/assets}/layout/_core.scss +0 -0
  90. /package/{assets → src/assets}/layout/_footer.scss +0 -0
  91. /package/{assets → src/assets}/layout/_logo.scss +0 -0
  92. /package/{assets → src/assets}/layout/_main.scss +0 -0
  93. /package/{assets → src/assets}/layout/_menu.scss +0 -0
  94. /package/{assets → src/assets}/layout/_mixins.scss +0 -0
  95. /package/{assets → src/assets}/layout/_preloading.scss +0 -0
  96. /package/{assets → src/assets}/layout/_responsive.scss +0 -0
  97. /package/{assets → src/assets}/layout/_topbar.scss +0 -0
  98. /package/{assets → src/assets}/layout/_typography.scss +0 -0
  99. /package/{assets → src/assets}/layout/_utils.scss +0 -0
  100. /package/{assets → src/assets}/layout/layout.scss +0 -0
  101. /package/{assets → src/assets}/layout/variables/_common.scss +0 -0
  102. /package/{assets → src/assets}/layout/variables/_dark.scss +0 -0
  103. /package/{assets → src/assets}/layout/variables/_light.scss +0 -0
  104. /package/{assets → src/assets}/oip-common.scss +0 -0
  105. /package/{assets → src/assets}/tailwind.css +0 -0
@@ -0,0 +1,186 @@
1
+ /* eslint-disable */
2
+ /* tslint:disable */
3
+ // @ts-nocheck
4
+ /*
5
+ * ---------------------------------------------------------------
6
+ * ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
7
+ * ## ##
8
+ * ## AUTHOR: acacode ##
9
+ * ## SOURCE: https://github.com/acacode/swagger-typescript-api ##
10
+ * ---------------------------------------------------------------
11
+ */
12
+
13
+ /** Data Transfer Object for creating a new module instance */
14
+ export interface AddModuleInstanceDto {
15
+ /** The identifier of the module to create an instance of */
16
+ moduleId?: number;
17
+ /** The display label for the module instance */
18
+ label?: string | null;
19
+ /** The icon identifier for the module instance (optional) */
20
+ icon?: string | null;
21
+ /** The parent module instance identifier (optional) */
22
+ parentId?: number | null;
23
+ /** Array of role identifiers that can view this module instance (optional) */
24
+ viewRoles?: string[] | null;
25
+ }
26
+
27
+ /** Standardized response format for API exceptions */
28
+ export interface ApiExceptionResponse {
29
+ /** User-friendly title of the exception */
30
+ title?: string | null;
31
+ /** Detailed description of the error */
32
+ message?: string | null;
33
+ /** HTTP status code associated with the exception */
34
+ statusCode?: number;
35
+ /** Stack trace information (optional, typically omitted in production) */
36
+ stackTrace?: string | null;
37
+ }
38
+
39
+ /** Data Transfer Object for editing an existing module instance */
40
+ export interface EditModuleInstanceDto {
41
+ /** The identifier of the module instance to edit */
42
+ moduleInstanceId?: number;
43
+ /** The updated display label for the module instance */
44
+ label?: string | null;
45
+ /** The updated icon identifier for the module instance (optional) */
46
+ icon?: string | null;
47
+ /** The updated parent module instance identifier (optional) */
48
+ parentId?: number | null;
49
+ /** Updated array of role identifiers that can view this module instance (optional) */
50
+ viewRoles?: string[] | null;
51
+ }
52
+
53
+ /** Data transfer object representing a module and its loaded status. */
54
+ export interface ExistModuleDto {
55
+ /** Gets or sets the unique identifier of the module. */
56
+ moduleId?: number;
57
+ /** Gets or sets the name of the module. */
58
+ name?: string | null;
59
+ /** Gets or sets a value indicating whether the module is currently loaded in the application. */
60
+ currentlyLoaded?: boolean;
61
+ }
62
+
63
+ /** Module settings. */
64
+ export interface FolderModuleSettings {
65
+ /** HTML content for the module. */
66
+ html?: string | null;
67
+ }
68
+
69
+ /** Represents a request to save module instance settings. */
70
+ export interface FolderModuleSettingsSaveSettingsRequest {
71
+ /** Gets or sets the ID of the module instance. */
72
+ id?: number;
73
+ /** Module settings. */
74
+ settings?: FolderModuleSettings;
75
+ }
76
+
77
+ /** Response front security settings */
78
+ export interface GetKeycloakClientSettingsResponse {
79
+ /** Authority */
80
+ authority?: string | null;
81
+ /** Client id */
82
+ clientId?: string | null;
83
+ /** Scope */
84
+ scope?: string | null;
85
+ /** Response Type */
86
+ responseType?: string | null;
87
+ /** Use Refresh Token */
88
+ useRefreshToken?: boolean;
89
+ /** Silent Renew */
90
+ silentRenew?: boolean;
91
+ /** Log level None = 0, Debug = 1, Warn = 2, Error = 3 */
92
+ logLevel?: number;
93
+ /** Urls with auth */
94
+ secureRoutes?: string[] | null;
95
+ }
96
+
97
+ /** Represents a key-value pair where the key is an integer and the value is a string. */
98
+ export interface IntKeyValueDto {
99
+ key?: number;
100
+ value?: string | null;
101
+ }
102
+
103
+ /** Represents a request to delete a module by its identifier. */
104
+ export interface ModuleDeleteRequest {
105
+ /** Gets or sets the unique identifier of the module to be deleted. */
106
+ moduleId?: number;
107
+ }
108
+
109
+ /** It module in app */
110
+ export interface ModuleDto {
111
+ /** Id */
112
+ moduleId?: number;
113
+ /** Name */
114
+ name?: string | null;
115
+ /** Settings */
116
+ settings?: string | null;
117
+ /** Securities */
118
+ moduleSecurities?: ModuleSecurityDto[] | null;
119
+ }
120
+
121
+ /** Module Instance Dto */
122
+ export interface ModuleInstanceDto {
123
+ /** Unique identifier for the module instance. */
124
+ moduleInstanceId?: number;
125
+ /** Identifier for the module. */
126
+ moduleId?: number;
127
+ /** The label for the module instance. */
128
+ label?: string | null;
129
+ /** Icon associated with the module instance. see https://primeng.org/icons */
130
+ icon?: string | null;
131
+ /** Route link. */
132
+ routerLink?: string[] | null;
133
+ /** URL for the module instance. */
134
+ url?: string | null;
135
+ /** The target. */
136
+ target?: string | null;
137
+ /** Configuration settings for the module instance. */
138
+ settings?: string | null;
139
+ /** Child module instances. */
140
+ items?: ModuleInstanceDto[] | null;
141
+ /** Securities */
142
+ securities?: string[] | null;
143
+ }
144
+
145
+ /** Module security DTO */
146
+ export interface ModuleSecurityDto {
147
+ /** Right */
148
+ right?: string | null;
149
+ /** Role */
150
+ role?: string | null;
151
+ }
152
+
153
+ /** Put security dto */
154
+ export interface PutSecurityRequest {
155
+ /** Instance id */
156
+ id?: number;
157
+ /** Securities */
158
+ securities?: SecurityResponse[] | null;
159
+ }
160
+
161
+ /** Security dto */
162
+ export interface SecurityResponse {
163
+ /** Code */
164
+ code?: string | null;
165
+ /** Name */
166
+ name?: string | null;
167
+ /** Description */
168
+ description?: string | null;
169
+ /** Roles */
170
+ roles?: string[] | null;
171
+ }
172
+
173
+ export interface FolderModuleGetSecurityParams {
174
+ /** The ID of the module instance. */
175
+ id?: number;
176
+ }
177
+
178
+ export interface FolderModuleGetModuleInstanceSettingsParams {
179
+ /** The ID of the module instance. */
180
+ id?: number;
181
+ }
182
+
183
+ export interface MenuDeleteModuleInstanceParams {
184
+ /** The unique identifier of the module instance to delete. */
185
+ id?: number;
186
+ }
@@ -0,0 +1,276 @@
1
+ /* eslint-disable */
2
+ /* tslint:disable */
3
+ // @ts-nocheck
4
+ /*
5
+ * ---------------------------------------------------------------
6
+ * ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
7
+ * ## ##
8
+ * ## AUTHOR: acacode ##
9
+ * ## SOURCE: https://github.com/acacode/swagger-typescript-api ##
10
+ * ---------------------------------------------------------------
11
+ */
12
+
13
+ import { inject, Injectable } from "@angular/core";
14
+ import { LayoutService, } from "../services/app.layout.service";
15
+ import { SecurityService } from "../services/security.service";
16
+ export type QueryParamsType = Record<string | number, any>;
17
+ export type ResponseFormat = keyof Omit<Body, "body" | "bodyUsed">;
18
+
19
+ export interface FullRequestParams extends Omit<RequestInit, "body"> {
20
+ /** set parameter to `true` for call `securityWorker` for this request */
21
+ secure?: boolean;
22
+ /** request path */
23
+ path: string;
24
+ /** content type of request body */
25
+ type?: ContentType;
26
+ /** query params */
27
+ query?: QueryParamsType;
28
+ /** format of response (i.e. response.json() -> format: "json") */
29
+ format?: ResponseFormat;
30
+ /** request body */
31
+ body?: unknown;
32
+ /** base url */
33
+ baseUrl?: string;
34
+ /** request cancellation token */
35
+ cancelToken?: CancelToken;
36
+ }
37
+
38
+ export type RequestParams = Omit<
39
+ FullRequestParams,
40
+ "body" | "method" | "query" | "path"
41
+ >;
42
+
43
+ export interface ApiConfig<SecurityDataType = unknown> {
44
+ baseUrl?: string;
45
+ baseApiParams?: Omit<RequestParams, "baseUrl" | "cancelToken" | "signal">;
46
+ securityWorker?: (
47
+ securityData: SecurityDataType | null,
48
+ ) => Promise<RequestParams | void> | RequestParams | void;
49
+ customFetch?: typeof fetch;
50
+ }
51
+
52
+ export interface HttpResponse<D extends unknown, E extends unknown = unknown>
53
+ extends Response {
54
+ data: D;
55
+ error: E;
56
+ }
57
+
58
+ type CancelToken = Symbol | string | number;
59
+
60
+ export enum ContentType {
61
+ Json = "application/json",
62
+ FormData = "multipart/form-data",
63
+ UrlEncoded = "application/x-www-form-urlencoded",
64
+ Text = "text/plain",
65
+ }
66
+
67
+ @Injectable({providedIn: "root"})
68
+ export class HttpClient<SecurityDataType = unknown> {
69
+ protected securityService = inject(SecurityService);
70
+ protected layoutService = inject(LayoutService);
71
+ public baseUrl: string = "";
72
+ private securityData: SecurityDataType | null = null;
73
+ private securityWorker?: ApiConfig<SecurityDataType>["securityWorker"] = (
74
+ securityData,
75
+ ) => ({
76
+ headers: {
77
+ "Accept-language": this.layoutService.language()
78
+ ? this.layoutService.language()
79
+ : "en",
80
+ "X-Timezone": this.layoutService.timeZone(),
81
+ Authorization: `Bearer ${securityData}`,
82
+ },
83
+ });
84
+ private abortControllers = new Map<CancelToken, AbortController>();
85
+ private customFetch = (...fetchParams: Parameters<typeof fetch>) =>
86
+ fetch(...fetchParams);
87
+
88
+ private baseApiParams: RequestParams = {
89
+ credentials: "same-origin",
90
+ headers: {},
91
+ redirect: "follow",
92
+ referrerPolicy: "no-referrer",
93
+ };
94
+
95
+ constructor() {
96
+ this.securityService.getAccessToken().subscribe((token) => {
97
+ this.securityData = token;
98
+ });
99
+ }
100
+
101
+ public setSecurityData = (data: SecurityDataType | null) => {
102
+ this.securityData = data;
103
+ };
104
+
105
+ protected encodeQueryParam(key: string, value: any) {
106
+ const encodedKey = encodeURIComponent(key);
107
+ return `${encodedKey}=${encodeURIComponent(typeof value === "number" ? value : `${value}`)}`;
108
+ }
109
+
110
+ protected addQueryParam(query: QueryParamsType, key: string) {
111
+ return this.encodeQueryParam(key, query[key]);
112
+ }
113
+
114
+ protected addArrayQueryParam(query: QueryParamsType, key: string) {
115
+ const value = query[key];
116
+ return value.map((v: any) => this.encodeQueryParam(key, v)).join("&");
117
+ }
118
+
119
+ protected toQueryString(rawQuery?: QueryParamsType): string {
120
+ const query = rawQuery || {};
121
+ const keys = Object.keys(query).filter(
122
+ (key) => "undefined" !== typeof query[key],
123
+ );
124
+ return keys
125
+ .map((key) =>
126
+ Array.isArray(query[key])
127
+ ? this.addArrayQueryParam(query, key)
128
+ : this.addQueryParam(query, key),
129
+ )
130
+ .join("&");
131
+ }
132
+
133
+ protected addQueryParams(rawQuery?: QueryParamsType): string {
134
+ const queryString = this.toQueryString(rawQuery);
135
+ return queryString ? `?${queryString}` : "";
136
+ }
137
+
138
+ private contentFormatters: Record<ContentType, (input: any) => any> = {
139
+ [ContentType.Json]: (input: any) =>
140
+ input !== null && (typeof input === "object" || typeof input === "string")
141
+ ? JSON.stringify(input)
142
+ : input,
143
+ [ContentType.Text]: (input: any) =>
144
+ input !== null && typeof input !== "string"
145
+ ? JSON.stringify(input)
146
+ : input,
147
+ [ContentType.FormData]: (input: any) =>
148
+ Object.keys(input || {}).reduce((formData, key) => {
149
+ const property = input[key];
150
+ formData.append(
151
+ key,
152
+ property instanceof Blob
153
+ ? property
154
+ : typeof property === "object" && property !== null
155
+ ? JSON.stringify(property)
156
+ : `${property}`,
157
+ );
158
+ return formData;
159
+ }, new FormData()),
160
+ [ContentType.UrlEncoded]: (input: any) => this.toQueryString(input),
161
+ };
162
+
163
+ protected mergeRequestParams(
164
+ params1: RequestParams,
165
+ params2?: RequestParams,
166
+ ): RequestParams {
167
+ return {
168
+ ...this.baseApiParams,
169
+ ...params1,
170
+ ...(params2 || {}),
171
+ headers: {
172
+ ...(this.baseApiParams.headers || {}),
173
+ ...(params1.headers || {}),
174
+ ...((params2 && params2.headers) || {}),
175
+ },
176
+ };
177
+ }
178
+
179
+ protected createAbortSignal = (
180
+ cancelToken: CancelToken,
181
+ ): AbortSignal | undefined => {
182
+ if (this.abortControllers.has(cancelToken)) {
183
+ const abortController = this.abortControllers.get(cancelToken);
184
+ if (abortController) {
185
+ return abortController.signal;
186
+ }
187
+ return void 0;
188
+ }
189
+
190
+ const abortController = new AbortController();
191
+ this.abortControllers.set(cancelToken, abortController);
192
+ return abortController.signal;
193
+ };
194
+
195
+ public abortRequest = (cancelToken: CancelToken) => {
196
+ const abortController = this.abortControllers.get(cancelToken);
197
+
198
+ if (abortController) {
199
+ abortController.abort();
200
+ this.abortControllers.delete(cancelToken);
201
+ }
202
+ };
203
+
204
+ public request = async <T = any, E = any>({
205
+ body,
206
+ secure,
207
+ path,
208
+ type,
209
+ query,
210
+ format,
211
+ baseUrl,
212
+ cancelToken,
213
+ ...params
214
+ }: FullRequestParams): Promise<T> => {
215
+ const secureParams =
216
+ ((typeof secure === "boolean" ? secure : this.baseApiParams.secure) &&
217
+ this.securityWorker &&
218
+ (await this.securityWorker(this.securityData))) ||
219
+ {};
220
+ const requestParams = this.mergeRequestParams(params, secureParams);
221
+ const queryString = query && this.toQueryString(query);
222
+ const payloadFormatter = this.contentFormatters[type || ContentType.Json];
223
+ let responseFormat = format || requestParams.format;
224
+
225
+ return this.customFetch(
226
+ `${baseUrl || this.baseUrl || ""}${path}${queryString ? `?${queryString}` : ""}`,
227
+ {
228
+ ...requestParams,
229
+ headers: {
230
+ ...(requestParams.headers || {}),
231
+ ...(type && type !== ContentType.FormData
232
+ ? {"Content-Type": type}
233
+ : {}),
234
+ },
235
+ signal:
236
+ (cancelToken
237
+ ? this.createAbortSignal(cancelToken)
238
+ : requestParams.signal) || null,
239
+ body:
240
+ typeof body === "undefined" || body === null
241
+ ? null
242
+ : payloadFormatter(body),
243
+ },
244
+ ).then(async (response) => {
245
+ const r = response.clone() as HttpResponse<T, E>;
246
+ r.data = null as unknown as T;
247
+ r.error = null as unknown as E;
248
+
249
+ if (typeof E !== undefined && responseFormat === undefined)
250
+ responseFormat = "json";
251
+
252
+ const data = !responseFormat
253
+ ? r
254
+ : await response[responseFormat]()
255
+ .then((data) => {
256
+ if (r.ok) {
257
+ r.data = data;
258
+ } else {
259
+ r.error = data;
260
+ }
261
+ return r;
262
+ })
263
+ .catch((e) => {
264
+ r.error = e;
265
+ return r;
266
+ });
267
+
268
+ if (cancelToken) {
269
+ this.abortControllers.delete(cancelToken);
270
+ }
271
+
272
+ if (!response.ok) throw data;
273
+ return data.data;
274
+ });
275
+ };
276
+ }