oip-common 0.0.3 → 0.0.5
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/fesm2022/oip-common.mjs +4267 -0
- package/fesm2022/oip-common.mjs.map +1 -0
- package/index.d.ts +1028 -0
- package/package.json +17 -5
- package/ng-package.json +0 -19
- package/src/api/FolderModule.ts +0 -124
- package/src/api/Menu.ts +0 -134
- package/src/api/Module.ts +0 -92
- package/src/api/Security.ts +0 -40
- package/src/api/Service.ts +0 -57
- package/src/api/data-contracts.ts +0 -186
- package/src/api/http-client.ts +0 -276
- package/src/components/app-configurator.component.ts +0 -491
- package/src/components/app-floating-configurator.component.ts +0 -47
- package/src/components/app-modules.component.ts +0 -144
- package/src/components/app.layout.component.ts +0 -130
- package/src/components/auth/access/access.component.ts +0 -42
- package/src/components/auth/error/error.component.ts +0 -42
- package/src/components/auth/login/login.component.ts +0 -120
- package/src/components/auth/unauthorized/unauthorized.component.ts +0 -51
- package/src/components/base-module.component.ts +0 -258
- package/src/components/config.component.ts +0 -131
- package/src/components/db-migration/db-migration.component.ts +0 -162
- package/src/components/db-migration.component.ts +0 -154
- package/src/components/footer.component.ts +0 -17
- package/src/components/logo.component.ts +0 -34
- package/src/components/menu/menu-item-create-dialog.component.ts +0 -119
- package/src/components/menu/menu-item-edit-dialog.component.ts +0 -123
- package/src/components/menu/menu-item.component.ts +0 -295
- package/src/components/menu/menu.component.ts +0 -85
- package/src/components/notfound.component.ts +0 -31
- package/src/components/profile.component.ts +0 -43
- package/src/components/security.component.ts +0 -102
- package/src/components/sidebar.component.ts +0 -12
- package/src/components/top-bar.component.ts +0 -147
- package/src/dtos/context-menu-item.dto.ts +0 -23
- package/src/dtos/edit-module-instance.dto.ts +0 -8
- package/src/dtos/no-settings.dto.ts +0 -4
- package/src/dtos/put-security.dto.ts +0 -6
- package/src/dtos/security.dto.ts +0 -6
- package/src/dtos/top-bar.dto.ts +0 -13
- package/src/events/menu-change.event.ts +0 -23
- package/src/helpers/date.helper.ts +0 -94
- package/src/intercepts/i18n-intercept.service.ts +0 -13
- package/src/modules/http-loader.factory.ts +0 -40
- package/src/modules/secure.pipe.ts +0 -19
- package/src/public-api.ts +0 -42
- package/src/services/app-title.service.ts +0 -22
- package/src/services/app.layout.service.ts +0 -236
- package/src/services/app.menu.service.ts +0 -64
- package/src/services/auth.service.ts +0 -58
- package/src/services/base-data.service.ts +0 -74
- package/src/services/l10n.service.ts +0 -71
- package/src/services/msg.service.ts +0 -76
- package/src/services/security-data.service.ts +0 -19
- package/src/services/security-storage.service.ts +0 -21
- package/src/services/security.service.ts +0 -116
- package/src/services/top-bar.service.ts +0 -44
- package/src/services/user.service.ts +0 -77
- package/src/test.ts +0 -11
- package/src/user-api/UserProfile.ts +0 -85
- package/src/user-api/data-contracts.ts +0 -42
- package/src/user-api/http-client.ts +0 -251
- package/tsconfig.lib.json +0 -12
- package/tsconfig.lib.prod.json +0 -10
- package/tsconfig.spec.json +0 -9
- /package/{src/assets → assets}/demo/code.scss +0 -0
- /package/{src/assets → assets}/demo/demo.scss +0 -0
- /package/{src/assets → assets}/demo/flags/flags.scss +0 -0
- /package/{src/assets → assets}/demo/flags/flags_responsive.png +0 -0
- /package/{src/assets → assets}/demo/images/access/asset-access.svg +0 -0
- /package/{src/assets → assets}/demo/images/error/asset-error.svg +0 -0
- /package/{src/assets → assets}/demo/images/flag/flag_placeholder.png +0 -0
- /package/{src/assets → assets}/favicon.svg +0 -0
- /package/{src/assets → assets}/i18n/app-modules.en.json +0 -0
- /package/{src/assets → assets}/i18n/app-modules.ru.json +0 -0
- /package/{src/assets → assets}/i18n/config.en.json +0 -0
- /package/{src/assets → assets}/i18n/config.ru.json +0 -0
- /package/{src/assets → assets}/layout/_core.scss +0 -0
- /package/{src/assets → assets}/layout/_footer.scss +0 -0
- /package/{src/assets → assets}/layout/_logo.scss +0 -0
- /package/{src/assets → assets}/layout/_main.scss +0 -0
- /package/{src/assets → assets}/layout/_menu.scss +0 -0
- /package/{src/assets → assets}/layout/_mixins.scss +0 -0
- /package/{src/assets → assets}/layout/_preloading.scss +0 -0
- /package/{src/assets → assets}/layout/_responsive.scss +0 -0
- /package/{src/assets → assets}/layout/_topbar.scss +0 -0
- /package/{src/assets → assets}/layout/_typography.scss +0 -0
- /package/{src/assets → assets}/layout/_utils.scss +0 -0
- /package/{src/assets → assets}/layout/layout.scss +0 -0
- /package/{src/assets → assets}/layout/variables/_common.scss +0 -0
- /package/{src/assets → assets}/layout/variables/_dark.scss +0 -0
- /package/{src/assets → assets}/layout/variables/_light.scss +0 -0
- /package/{src/assets → assets}/oip-common.scss +0 -0
- /package/{src/assets → assets}/tailwind.css +0 -0
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { Injectable, OnDestroy, inject } from '@angular/core';
|
|
2
|
-
import {
|
|
3
|
-
LoginResponse,
|
|
4
|
-
LogoutAuthOptions,
|
|
5
|
-
OidcSecurityService,
|
|
6
|
-
PublicEventsService,
|
|
7
|
-
EventTypes
|
|
8
|
-
} from 'angular-auth-oidc-client';
|
|
9
|
-
import { BehaviorSubject, Observable } from 'rxjs';
|
|
10
|
-
import { filter, map } from 'rxjs/operators';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* SecurityService extends OidcSecurityService to manage authentication,
|
|
14
|
-
* token handling, and user role access in an Angular application.
|
|
15
|
-
*
|
|
16
|
-
* It provides helper methods for checking authentication, managing tokens,
|
|
17
|
-
* determining user roles, and performing logout and refresh operations.
|
|
18
|
-
*/
|
|
19
|
-
@Injectable({ providedIn: 'root' })
|
|
20
|
-
export class SecurityService extends OidcSecurityService implements OnDestroy {
|
|
21
|
-
/**
|
|
22
|
-
* Handles angular OIDC events.
|
|
23
|
-
*/
|
|
24
|
-
private readonly publicEventsService = inject(PublicEventsService);
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Stores the latest login response from checkAuth().
|
|
28
|
-
*/
|
|
29
|
-
loginResponse = new BehaviorSubject<LoginResponse>(null);
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Stores the decoded access token payload.
|
|
33
|
-
*/
|
|
34
|
-
payload = new BehaviorSubject<any>(null);
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Stores user-specific data from the login response.
|
|
38
|
-
*/
|
|
39
|
-
userData: any;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Initializes service and subscribes to authentication events.
|
|
43
|
-
* When a 'NewAuthenticationResult' event is received, the `auth` method is called.
|
|
44
|
-
*/
|
|
45
|
-
constructor() {
|
|
46
|
-
super();
|
|
47
|
-
this.publicEventsService
|
|
48
|
-
.registerForEvents()
|
|
49
|
-
.pipe(filter((event) => event.type === EventTypes.NewAuthenticationResult))
|
|
50
|
-
.subscribe(() => {
|
|
51
|
-
this.auth();
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Returns the ID token for the sign-in.
|
|
57
|
-
* @returns A string with the id token.
|
|
58
|
-
*/
|
|
59
|
-
override getAccessToken(): Observable<string> {
|
|
60
|
-
return this.loginResponse.pipe(map((data) => data?.accessToken));
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Indicates whether the current user has the 'admin' role.
|
|
65
|
-
*
|
|
66
|
-
* @returns {boolean} True if the user is an admin, false otherwise.
|
|
67
|
-
*/
|
|
68
|
-
get isAdmin(): boolean {
|
|
69
|
-
return this.payload.getValue()?.realm_access?.roles?.includes('admin');
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Initiates authentication check and updates login response, user data,
|
|
74
|
-
* and decoded token payload if authenticated.
|
|
75
|
-
*/
|
|
76
|
-
auth() {
|
|
77
|
-
super.checkAuth().subscribe((_response: LoginResponse) => {
|
|
78
|
-
this.loginResponse.next(_response);
|
|
79
|
-
this.userData = _response.userData;
|
|
80
|
-
this.getPayloadFromAccessToken().subscribe((_token) => {
|
|
81
|
-
this.payload.next(_token);
|
|
82
|
-
});
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Performs logout and clears the local token payload.
|
|
88
|
-
*
|
|
89
|
-
* @param {string} [configId] Optional configuration ID for logout.
|
|
90
|
-
* @param {LogoutAuthOptions} [logoutAuthOptions] Optional logout options.
|
|
91
|
-
*/
|
|
92
|
-
logout(configId?: string, logoutAuthOptions?: LogoutAuthOptions) {
|
|
93
|
-
this.logoff(configId, logoutAuthOptions).subscribe((x) => this.payload.next(x));
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Completes the BehaviorSubjects when the service is destroyed to avoid memory leaks.
|
|
98
|
-
*/
|
|
99
|
-
ngOnDestroy(): void {
|
|
100
|
-
this.loginResponse.complete();
|
|
101
|
-
this.payload.complete();
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Checks whether the current access token is expired based on the 'exp' claim.
|
|
106
|
-
*
|
|
107
|
-
* @returns {Observable<boolean>} Observable that emits true if the token is expired.
|
|
108
|
-
*/
|
|
109
|
-
isTokenExpired(): Observable<boolean> {
|
|
110
|
-
return this.getPayloadFromAccessToken().pipe(
|
|
111
|
-
map((payload) => {
|
|
112
|
-
return payload.exp < Math.floor(Date.now() / 1000);
|
|
113
|
-
})
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { Injectable } from '@angular/core';
|
|
2
|
-
import { TopBarDto } from '../dtos/top-bar.dto';
|
|
3
|
-
|
|
4
|
-
@Injectable({
|
|
5
|
-
providedIn: 'root'
|
|
6
|
-
})
|
|
7
|
-
export class TopBarService {
|
|
8
|
-
topBarItems: TopBarDto[] = [];
|
|
9
|
-
|
|
10
|
-
private _activeId: string | undefined;
|
|
11
|
-
|
|
12
|
-
get availableTopBarItems(): TopBarDto[] {
|
|
13
|
-
return this.topBarItems;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
get activeTopBarItem(): TopBarDto | undefined {
|
|
17
|
-
if (this._activeId === undefined) {
|
|
18
|
-
return undefined;
|
|
19
|
-
}
|
|
20
|
-
return this.topBarItems.find((topBarItem: TopBarDto) => topBarItem.id === this._activeId);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
get activeId(): string | undefined {
|
|
24
|
-
return this._activeId;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
set activeId(value: string | undefined) {
|
|
28
|
-
this._activeId = value;
|
|
29
|
-
if (this.activeTopBarItem?.click) this.activeTopBarItem.click();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
constructor() {}
|
|
33
|
-
|
|
34
|
-
// Set tob bar items
|
|
35
|
-
setTopBarItems(items: TopBarDto[]) {
|
|
36
|
-
this.topBarItems = items;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
checkId(id: string): boolean {
|
|
40
|
-
if (this.activeTopBarItem === undefined && id === 'content') return true;
|
|
41
|
-
if (this.activeTopBarItem === undefined) return false;
|
|
42
|
-
return this.activeTopBarItem.id == id;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { inject, Injectable } from '@angular/core';
|
|
2
|
-
import { SecurityService } from './security.service';
|
|
3
|
-
import { BaseDataService } from './base-data.service';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* UserService is responsible for retrieving and handling user-related data,
|
|
7
|
-
* including the user's photo and short label for avatar display.
|
|
8
|
-
*/
|
|
9
|
-
@Injectable()
|
|
10
|
-
export class UserService {
|
|
11
|
-
private readonly securityService = inject(SecurityService);
|
|
12
|
-
private readonly baseDataService = inject(BaseDataService);
|
|
13
|
-
|
|
14
|
-
constructor() {
|
|
15
|
-
this.getUserPhoto();
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Stores the user's photo as a data URL or binary blob, depending on how it's processed.
|
|
20
|
-
*/
|
|
21
|
-
photo: any = null;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Indicates whether the user photo has finished loading.
|
|
25
|
-
*/
|
|
26
|
-
photoLoaded: boolean = false;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Returns a short label composed of the user's initials.
|
|
30
|
-
* Typically used for avatar display when a photo is unavailable.
|
|
31
|
-
*/
|
|
32
|
-
get shortLabel(): string {
|
|
33
|
-
const data = this.securityService.userData;
|
|
34
|
-
return data.given_name[0] + data.family_name[0];
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
get userName(): string {
|
|
38
|
-
const data = this.securityService.userData;
|
|
39
|
-
return `${data.given_name} ${data.family_name}`;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Initiates an HTTP request to fetch the user's photo based on their email,
|
|
44
|
-
* and updates the `photo` and `photoLoaded` properties accordingly.
|
|
45
|
-
*/
|
|
46
|
-
getUserPhoto(): void {
|
|
47
|
-
const url = `${this.baseDataService.baseUrl}api/user-profile/get-user-photo?email=${this.securityService.userData.email}`;
|
|
48
|
-
this.baseDataService.getBlob(url).then(
|
|
49
|
-
(data) => {
|
|
50
|
-
this.createImageFromBlob(data as Blob);
|
|
51
|
-
this.photoLoaded = true;
|
|
52
|
-
},
|
|
53
|
-
(error) => {
|
|
54
|
-
console.log(error);
|
|
55
|
-
}
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Converts a Blob image into a Base64 data URL and stores it in the `photo` property.
|
|
61
|
-
*
|
|
62
|
-
* @param image - The image Blob to be converted.
|
|
63
|
-
*/
|
|
64
|
-
private createImageFromBlob(image: Blob): void {
|
|
65
|
-
const reader = new FileReader();
|
|
66
|
-
reader.addEventListener(
|
|
67
|
-
'load',
|
|
68
|
-
() => {
|
|
69
|
-
this.photo = reader.result;
|
|
70
|
-
},
|
|
71
|
-
false
|
|
72
|
-
);
|
|
73
|
-
if (image) {
|
|
74
|
-
reader.readAsDataURL(image);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
package/src/test.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
|
|
2
|
-
|
|
3
|
-
import 'zone.js/dist/zone';
|
|
4
|
-
import 'zone.js/dist/zone-testing';
|
|
5
|
-
import { getTestBed } from '@angular/core/testing';
|
|
6
|
-
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
|
|
7
|
-
|
|
8
|
-
// First, initialize the Angular testing environment.
|
|
9
|
-
getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting(), {
|
|
10
|
-
teardown: { destroyAfterEach: false }
|
|
11
|
-
});
|
|
@@ -1,85 +0,0 @@
|
|
|
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 { Injectable } from '@angular/core';
|
|
14
|
-
import { UserProfileGetUserPhotoParams, UserProfilePostUserPhotoPayload, UserSettingsDto } from './data-contracts';
|
|
15
|
-
import { ContentType, HttpClient, RequestParams } from './http-client';
|
|
16
|
-
|
|
17
|
-
@Injectable()
|
|
18
|
-
export class UserProfile<SecurityDataType = unknown> extends HttpClient<SecurityDataType> {
|
|
19
|
-
/**
|
|
20
|
-
* @description Gets user photo by email address
|
|
21
|
-
*
|
|
22
|
-
* @tags UserProfile
|
|
23
|
-
* @name userProfileGetUserPhoto
|
|
24
|
-
* @request GET:/api/user-profile/get-user-photo
|
|
25
|
-
* @secure
|
|
26
|
-
*/
|
|
27
|
-
userProfileGetUserPhoto = (query: UserProfileGetUserPhotoParams, params: RequestParams = {}) =>
|
|
28
|
-
this.request<void, any>({
|
|
29
|
-
path: `/api/user-profile/get-user-photo`,
|
|
30
|
-
method: 'GET',
|
|
31
|
-
query: query,
|
|
32
|
-
secure: true,
|
|
33
|
-
...params
|
|
34
|
-
});
|
|
35
|
-
/**
|
|
36
|
-
* @description Uploads user photo
|
|
37
|
-
*
|
|
38
|
-
* @tags UserProfile
|
|
39
|
-
* @name userProfilePostUserPhoto
|
|
40
|
-
* @request POST:/api/user-profile/post-user-photo
|
|
41
|
-
* @secure
|
|
42
|
-
*/
|
|
43
|
-
userProfilePostUserPhoto = (data: UserProfilePostUserPhotoPayload, params: RequestParams = {}) =>
|
|
44
|
-
this.request<void, any>({
|
|
45
|
-
path: `/api/user-profile/post-user-photo`,
|
|
46
|
-
method: 'POST',
|
|
47
|
-
body: data,
|
|
48
|
-
secure: true,
|
|
49
|
-
type: ContentType.FormData,
|
|
50
|
-
...params
|
|
51
|
-
});
|
|
52
|
-
/**
|
|
53
|
-
* @description Get user setting by e-mail
|
|
54
|
-
*
|
|
55
|
-
* @tags UserProfile
|
|
56
|
-
* @name userProfileGetSettings
|
|
57
|
-
* @request GET:/api/user-profile/get-settings
|
|
58
|
-
* @secure
|
|
59
|
-
*/
|
|
60
|
-
userProfileGetSettings = (params: RequestParams = {}) =>
|
|
61
|
-
this.request<UserSettingsDto, any>({
|
|
62
|
-
path: `/api/user-profile/get-settings`,
|
|
63
|
-
method: 'GET',
|
|
64
|
-
secure: true,
|
|
65
|
-
format: 'json',
|
|
66
|
-
...params
|
|
67
|
-
});
|
|
68
|
-
/**
|
|
69
|
-
* @description Update User settings
|
|
70
|
-
*
|
|
71
|
-
* @tags UserProfile
|
|
72
|
-
* @name userProfileSetSettings
|
|
73
|
-
* @request PUT:/api/user-profile/set-settings
|
|
74
|
-
* @secure
|
|
75
|
-
*/
|
|
76
|
-
userProfileSetSettings = (data: UserSettingsDto, params: RequestParams = {}) =>
|
|
77
|
-
this.request<void, any>({
|
|
78
|
-
path: `/api/user-profile/set-settings`,
|
|
79
|
-
method: 'PUT',
|
|
80
|
-
body: data,
|
|
81
|
-
secure: true,
|
|
82
|
-
type: ContentType.Json,
|
|
83
|
-
...params
|
|
84
|
-
});
|
|
85
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
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
|
-
/** Represents user interface and localization settings. */
|
|
14
|
-
export interface UserSettingsDto {
|
|
15
|
-
/** Gets or sets the selected visual preset name. */
|
|
16
|
-
preset?: string | null;
|
|
17
|
-
/** Gets or sets the primary color theme. */
|
|
18
|
-
primary?: string | null;
|
|
19
|
-
/** Gets or sets the surface color. Can be null. */
|
|
20
|
-
surface?: string | null;
|
|
21
|
-
/** Gets or sets a value indicating whether the dark theme is enabled. */
|
|
22
|
-
darkTheme?: boolean;
|
|
23
|
-
/** Gets or sets the layout mode for the menu (e.g., static, overlay). */
|
|
24
|
-
menuMode?: string | null;
|
|
25
|
-
/** Gets or sets the selected language code. */
|
|
26
|
-
language?: string | null;
|
|
27
|
-
/** Gets or sets the date format pattern. */
|
|
28
|
-
dateFormat?: string | null;
|
|
29
|
-
/** Gets or sets the time format pattern. */
|
|
30
|
-
timeFormat?: string | null;
|
|
31
|
-
/** Gets or sets the user's time zone. */
|
|
32
|
-
timeZone?: string | null;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export interface UserProfileGetUserPhotoParams {
|
|
36
|
-
/** User's email address */
|
|
37
|
-
email?: string;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export interface UserProfilePostUserPhotoPayload {
|
|
41
|
-
files?: File;
|
|
42
|
-
}
|
|
@@ -1,251 +0,0 @@
|
|
|
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, SecurityService } from 'oip-common';
|
|
15
|
-
|
|
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<FullRequestParams, 'body' | 'method' | 'query' | 'path'>;
|
|
39
|
-
|
|
40
|
-
export interface ApiConfig<SecurityDataType = unknown> {
|
|
41
|
-
baseUrl?: string;
|
|
42
|
-
baseApiParams?: Omit<RequestParams, 'baseUrl' | 'cancelToken' | 'signal'>;
|
|
43
|
-
securityWorker?: (securityData: SecurityDataType | null) => Promise<RequestParams | void> | RequestParams | void;
|
|
44
|
-
customFetch?: typeof fetch;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export interface HttpResponse<D extends unknown, E extends unknown = unknown> extends Response {
|
|
48
|
-
data: D;
|
|
49
|
-
error: E;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
type CancelToken = Symbol | string | number;
|
|
53
|
-
|
|
54
|
-
export enum ContentType {
|
|
55
|
-
Json = 'application/json',
|
|
56
|
-
FormData = 'multipart/form-data',
|
|
57
|
-
UrlEncoded = 'application/x-www-form-urlencoded',
|
|
58
|
-
Text = 'text/plain'
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
@Injectable({ providedIn: 'root' })
|
|
62
|
-
export class HttpClient<SecurityDataType = unknown> {
|
|
63
|
-
protected securityService = inject(SecurityService);
|
|
64
|
-
public baseUrl: string = '';
|
|
65
|
-
private securityData: SecurityDataType | null = null;
|
|
66
|
-
private securityWorker?: ApiConfig<SecurityDataType>['securityWorker'] = (securityData) => ({
|
|
67
|
-
headers: {
|
|
68
|
-
'Accept-language': this.getLanguage(),
|
|
69
|
-
'X-Timezone': this.getTimeZone(),
|
|
70
|
-
Authorization: `Bearer ${this.getAccessToken()}`
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
private getAccessToken() {
|
|
75
|
-
const storageData = localStorage.getItem('0-oip-client');
|
|
76
|
-
return JSON.parse(storageData)?.authnResult?.access_token;
|
|
77
|
-
}
|
|
78
|
-
private getLanguage(): string {
|
|
79
|
-
// Получаем язык из localStorage или используем значение по умолчанию
|
|
80
|
-
return localStorage.getItem('user-language') || 'en';
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
private getTimeZone(): string {
|
|
84
|
-
// Получаем таймзону из localStorage или используем системную
|
|
85
|
-
return localStorage.getItem('user-timezone') || Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
private abortControllers = new Map<CancelToken, AbortController>();
|
|
89
|
-
private customFetch = (...fetchParams: Parameters<typeof fetch>) => fetch(...fetchParams);
|
|
90
|
-
|
|
91
|
-
private baseApiParams: RequestParams = {
|
|
92
|
-
credentials: 'same-origin',
|
|
93
|
-
headers: {},
|
|
94
|
-
redirect: 'follow',
|
|
95
|
-
referrerPolicy: 'no-referrer'
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
constructor() {
|
|
99
|
-
this.securityService.getAccessToken().subscribe((token) => {
|
|
100
|
-
this.securityData = token;
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
public setSecurityData = (data: SecurityDataType | null) => {
|
|
105
|
-
this.securityData = data;
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
protected encodeQueryParam(key: string, value: any) {
|
|
109
|
-
const encodedKey = encodeURIComponent(key);
|
|
110
|
-
return `${encodedKey}=${encodeURIComponent(typeof value === 'number' ? value : `${value}`)}`;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
protected addQueryParam(query: QueryParamsType, key: string) {
|
|
114
|
-
return this.encodeQueryParam(key, query[key]);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
protected addArrayQueryParam(query: QueryParamsType, key: string) {
|
|
118
|
-
const value = query[key];
|
|
119
|
-
return value.map((v: any) => this.encodeQueryParam(key, v)).join('&');
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
protected toQueryString(rawQuery?: QueryParamsType): string {
|
|
123
|
-
const query = rawQuery || {};
|
|
124
|
-
const keys = Object.keys(query).filter((key) => 'undefined' !== typeof query[key]);
|
|
125
|
-
return keys
|
|
126
|
-
.map((key) => (Array.isArray(query[key]) ? this.addArrayQueryParam(query, key) : this.addQueryParam(query, key)))
|
|
127
|
-
.join('&');
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
protected addQueryParams(rawQuery?: QueryParamsType): string {
|
|
131
|
-
const queryString = this.toQueryString(rawQuery);
|
|
132
|
-
return queryString ? `?${queryString}` : '';
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
private contentFormatters: Record<ContentType, (input: any) => any> = {
|
|
136
|
-
[ContentType.Json]: (input: any) =>
|
|
137
|
-
input !== null && (typeof input === 'object' || typeof input === 'string') ? JSON.stringify(input) : input,
|
|
138
|
-
[ContentType.Text]: (input: any) => (input !== null && typeof input !== 'string' ? JSON.stringify(input) : input),
|
|
139
|
-
[ContentType.FormData]: (input: any) =>
|
|
140
|
-
Object.keys(input || {}).reduce((formData, key) => {
|
|
141
|
-
const property = input[key];
|
|
142
|
-
formData.append(
|
|
143
|
-
key,
|
|
144
|
-
property instanceof Blob
|
|
145
|
-
? property
|
|
146
|
-
: typeof property === 'object' && property !== null
|
|
147
|
-
? JSON.stringify(property)
|
|
148
|
-
: `${property}`
|
|
149
|
-
);
|
|
150
|
-
return formData;
|
|
151
|
-
}, new FormData()),
|
|
152
|
-
[ContentType.UrlEncoded]: (input: any) => this.toQueryString(input)
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
protected mergeRequestParams(params1: RequestParams, params2?: RequestParams): RequestParams {
|
|
156
|
-
return {
|
|
157
|
-
...this.baseApiParams,
|
|
158
|
-
...params1,
|
|
159
|
-
...(params2 || {}),
|
|
160
|
-
headers: {
|
|
161
|
-
...(this.baseApiParams.headers || {}),
|
|
162
|
-
...(params1.headers || {}),
|
|
163
|
-
...((params2 && params2.headers) || {})
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
protected createAbortSignal = (cancelToken: CancelToken): AbortSignal | undefined => {
|
|
169
|
-
if (this.abortControllers.has(cancelToken)) {
|
|
170
|
-
const abortController = this.abortControllers.get(cancelToken);
|
|
171
|
-
if (abortController) {
|
|
172
|
-
return abortController.signal;
|
|
173
|
-
}
|
|
174
|
-
return void 0;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
const abortController = new AbortController();
|
|
178
|
-
this.abortControllers.set(cancelToken, abortController);
|
|
179
|
-
return abortController.signal;
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
public abortRequest = (cancelToken: CancelToken) => {
|
|
183
|
-
const abortController = this.abortControllers.get(cancelToken);
|
|
184
|
-
|
|
185
|
-
if (abortController) {
|
|
186
|
-
abortController.abort();
|
|
187
|
-
this.abortControllers.delete(cancelToken);
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
public request = async <T = any, E = any>({
|
|
192
|
-
body,
|
|
193
|
-
secure,
|
|
194
|
-
path,
|
|
195
|
-
type,
|
|
196
|
-
query,
|
|
197
|
-
format,
|
|
198
|
-
baseUrl,
|
|
199
|
-
cancelToken,
|
|
200
|
-
...params
|
|
201
|
-
}: FullRequestParams): Promise<T> => {
|
|
202
|
-
const secureParams =
|
|
203
|
-
((typeof secure === 'boolean' ? secure : this.baseApiParams.secure) &&
|
|
204
|
-
this.securityWorker &&
|
|
205
|
-
(await this.securityWorker(this.securityData))) ||
|
|
206
|
-
{};
|
|
207
|
-
const requestParams = this.mergeRequestParams(params, secureParams);
|
|
208
|
-
const queryString = query && this.toQueryString(query);
|
|
209
|
-
const payloadFormatter = this.contentFormatters[type || ContentType.Json];
|
|
210
|
-
let responseFormat = format || requestParams.format;
|
|
211
|
-
|
|
212
|
-
return this.customFetch(`${baseUrl || this.baseUrl || ''}${path}${queryString ? `?${queryString}` : ''}`, {
|
|
213
|
-
...requestParams,
|
|
214
|
-
headers: {
|
|
215
|
-
...(requestParams.headers || {}),
|
|
216
|
-
...(type && type !== ContentType.FormData ? { 'Content-Type': type } : {})
|
|
217
|
-
},
|
|
218
|
-
signal: (cancelToken ? this.createAbortSignal(cancelToken) : requestParams.signal) || null,
|
|
219
|
-
body: typeof body === 'undefined' || body === null ? null : payloadFormatter(body)
|
|
220
|
-
}).then(async (response) => {
|
|
221
|
-
const r = response.clone() as HttpResponse<T, E>;
|
|
222
|
-
r.data = null as unknown as T;
|
|
223
|
-
r.error = null as unknown as E;
|
|
224
|
-
|
|
225
|
-
if (typeof E !== undefined && responseFormat === undefined) responseFormat = 'json';
|
|
226
|
-
|
|
227
|
-
const data = !responseFormat
|
|
228
|
-
? r
|
|
229
|
-
: await response[responseFormat]()
|
|
230
|
-
.then((data) => {
|
|
231
|
-
if (r.ok) {
|
|
232
|
-
r.data = data;
|
|
233
|
-
} else {
|
|
234
|
-
r.error = data;
|
|
235
|
-
}
|
|
236
|
-
return r;
|
|
237
|
-
})
|
|
238
|
-
.catch((e) => {
|
|
239
|
-
r.error = e;
|
|
240
|
-
return r;
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
if (cancelToken) {
|
|
244
|
-
this.abortControllers.delete(cancelToken);
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
if (!response.ok) throw data;
|
|
248
|
-
return data.data;
|
|
249
|
-
});
|
|
250
|
-
};
|
|
251
|
-
}
|
package/tsconfig.lib.json
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/* To learn more about this file see: https://angular.io/config/tsconfig. */
|
|
2
|
-
{
|
|
3
|
-
"extends": "../../tsconfig.json",
|
|
4
|
-
"compilerOptions": {
|
|
5
|
-
"outDir": "../../out-tsc/lib",
|
|
6
|
-
"declaration": true,
|
|
7
|
-
"declarationMap": true,
|
|
8
|
-
"inlineSources": true,
|
|
9
|
-
"types": []
|
|
10
|
-
},
|
|
11
|
-
"exclude": ["**/*.spec.ts"]
|
|
12
|
-
}
|
package/tsconfig.lib.prod.json
DELETED
package/tsconfig.spec.json
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|