@fluxo-dev/api-client-base 0.0.8
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/.babelrc +12 -0
- package/.eslintrc.json +18 -0
- package/README.md +7 -0
- package/jest.config.ts +11 -0
- package/package.json +8 -0
- package/project.json +43 -0
- package/src/index.ts +39 -0
- package/src/lib/apps/apps.service.ts +46 -0
- package/src/lib/apps/index.ts +2 -0
- package/src/lib/apps/models/app-state.ts +4 -0
- package/src/lib/apps/models/app-type.ts +4 -0
- package/src/lib/apps/models/embedded-module.ts +106 -0
- package/src/lib/apps/models/fluxo-app-menu.ts +12 -0
- package/src/lib/apps/models/fluxo-app.ts +17 -0
- package/src/lib/apps/models/fluxo-embedded-module-configuration.ts +10 -0
- package/src/lib/apps/models/fluxo-frontend-app-configuration.ts +12 -0
- package/src/lib/apps/models/flx-app-routes.ts +5 -0
- package/src/lib/apps/models/flx-route.ts +6 -0
- package/src/lib/apps/models/index.ts +9 -0
- package/src/lib/auth/auth-service.ts +149 -0
- package/src/lib/configuration/app-menu-create-command.ts +9 -0
- package/src/lib/configuration/app-menu-item.ts +14 -0
- package/src/lib/configuration/app-menu.ts +15 -0
- package/src/lib/configuration/client-ui.ts +5 -0
- package/src/lib/configuration/configuration.service.ts +57 -0
- package/src/lib/configuration/index.ts +5 -0
- package/src/lib/configuration/models/feature-list.ts +8 -0
- package/src/lib/configuration/models/feature.ts +11 -0
- package/src/lib/configuration/models/index.ts +3 -0
- package/src/lib/configuration/models/module.ts +5 -0
- package/src/lib/constants/local-storage.ts +4 -0
- package/src/lib/fluxo-client-base-sys.ts +28 -0
- package/src/lib/fluxo-client-interface.ts +27 -0
- package/src/lib/fluxo-client.ts +142 -0
- package/src/lib/fluxo-state-dispatcher.ts +81 -0
- package/src/lib/http-client/http-client.ts +75 -0
- package/src/lib/infrastructure/base-common-service.ts +45 -0
- package/src/lib/infrastructure/index.ts +1 -0
- package/src/lib/interfaces/crud-service-interface.ts +9 -0
- package/src/lib/interfaces/index.ts +2 -0
- package/src/lib/interfaces/rc-paginated-result.ts +6 -0
- package/src/lib/korebi/app-service/app-service.service.ts +8 -0
- package/src/lib/korebi/app-service/index.ts +3 -0
- package/src/lib/korebi/app-service/model/dynamic-api-service.ts +15 -0
- package/src/lib/korebi/app-service/model/dynamic-api-services-method.ts +6 -0
- package/src/lib/korebi/documentation/documentation.service.ts +26 -0
- package/src/lib/korebi/documentation/index.ts +3 -0
- package/src/lib/korebi/documentation/intellisense.service.ts +21 -0
- package/src/lib/korebi/documentation/models/command-input-type.ts +11 -0
- package/src/lib/korebi/documentation/models/command-metadata.ts +10 -0
- package/src/lib/korebi/documentation/models/command-output-type.ts +6 -0
- package/src/lib/korebi/documentation/models/command.ts +19 -0
- package/src/lib/korebi/documentation/models/documentation.ts +13 -0
- package/src/lib/korebi/documentation/models/index.ts +8 -0
- package/src/lib/korebi/documentation/models/korebi-profile.ts +5 -0
- package/src/lib/korebi/documentation/models/type-meta-structure.ts +11 -0
- package/src/lib/korebi/documentation/models/type-specs.ts +5 -0
- package/src/lib/korebi/dynamic-configuration/dynamic-configuration.service.ts +17 -0
- package/src/lib/korebi/dynamic-configuration/index.ts +8 -0
- package/src/lib/korebi/dynamic-configuration/model/attribute-marker-location.ts +7 -0
- package/src/lib/korebi/dynamic-configuration/model/command-json-configuration.ts +20 -0
- package/src/lib/korebi/dynamic-configuration/model/instruction-json-configuration.ts +19 -0
- package/src/lib/korebi/dynamic-configuration/model/profile-json-configuration.ts +6 -0
- package/src/lib/korebi/dynamic-configuration/model/rest-adapter-info.ts +9 -0
- package/src/lib/korebi/dynamic-configuration/model/startup-exception-context.ts +44 -0
- package/src/lib/korebi/dynamic-configuration/model/tenant-json-configuration.ts +6 -0
- package/src/lib/korebi/index.ts +3 -0
- package/src/lib/korebi/korebi-facade.ts +33 -0
- package/src/lib/modules/fluxo-module.ts +13 -0
- package/src/lib/printing/index.ts +2 -0
- package/src/lib/printing/models/add-printer-command.ts +12 -0
- package/src/lib/printing/models/create-print-server-command.ts +11 -0
- package/src/lib/printing/models/index.ts +9 -0
- package/src/lib/printing/models/print-server-managed-type.ts +4 -0
- package/src/lib/printing/models/print-server-type.ts +4 -0
- package/src/lib/printing/models/printer-manufacturer.ts +3 -0
- package/src/lib/printing/models/printer-type.ts +4 -0
- package/src/lib/printing/models/update-print-server-command.ts +4 -0
- package/src/lib/printing/models/virtual-print-server.ts +14 -0
- package/src/lib/printing/models/virtual-printer.ts +14 -0
- package/src/lib/printing/printing.service.ts +32 -0
- package/src/lib/reporting/index.ts +2 -0
- package/src/lib/reporting/models/create-report-command.ts +8 -0
- package/src/lib/reporting/models/index.ts +7 -0
- package/src/lib/reporting/models/parameters-schema.ts +8 -0
- package/src/lib/reporting/models/print-report-command.ts +5 -0
- package/src/lib/reporting/models/report-info.ts +5 -0
- package/src/lib/reporting/models/report-parameter.ts +6 -0
- package/src/lib/reporting/models/report.ts +10 -0
- package/src/lib/reporting/models/reports-list.ts +10 -0
- package/src/lib/reporting/reporting.service.ts +33 -0
- package/src/lib/security/apikey/apikey-service.ts +30 -0
- package/src/lib/security/apikey/apikey.ts +7 -0
- package/src/lib/security/apikey/index.ts +3 -0
- package/src/lib/security/apikey/new-apikey.ts +4 -0
- package/src/lib/security/domain-role/domain-role.service.ts +22 -0
- package/src/lib/security/domain-role/domain-role.ts +7 -0
- package/src/lib/security/domain-role/index.ts +2 -0
- package/src/lib/security/permission/create-custom-permission-command.ts +7 -0
- package/src/lib/security/permission/create-permission-scope-command.ts +6 -0
- package/src/lib/security/permission/index.ts +8 -0
- package/src/lib/security/permission/install-permission-command.ts +7 -0
- package/src/lib/security/permission/permission-identifier.ts +4 -0
- package/src/lib/security/permission/permission-scope.ts +7 -0
- package/src/lib/security/permission/permission.service.ts +38 -0
- package/src/lib/security/permission/permission.ts +9 -0
- package/src/lib/security/permission/structured-permission.ts +22 -0
- package/src/lib/security/route-rule/index.ts +3 -0
- package/src/lib/security/route-rule/route-rule-with-permissions.ts +4 -0
- package/src/lib/security/route-rule/route-rule.service.ts +26 -0
- package/src/lib/security/route-rule/route-rule.ts +7 -0
- package/src/lib/security/security-facade.ts +42 -0
- package/src/lib/security/user/change-password.ts +4 -0
- package/src/lib/security/user/forgot-password.ts +5 -0
- package/src/lib/security/user/identityOperationResult.ts +9 -0
- package/src/lib/security/user/index.ts +2 -0
- package/src/lib/security/user/new-account-confirmation.ts +4 -0
- package/src/lib/security/user/new-user.ts +12 -0
- package/src/lib/security/user/user-service.ts +83 -0
- package/src/lib/security/user/user.ts +19 -0
- package/src/lib/utils/index.ts +1 -0
- package/src/lib/utils/server-filter-helper.ts +34 -0
- package/src/lib/workflow/index.ts +2 -0
- package/src/lib/workflow/models/action-category-definition.ts +7 -0
- package/src/lib/workflow/models/action-definition.ts +12 -0
- package/src/lib/workflow/models/action-input-definition.ts +8 -0
- package/src/lib/workflow/models/action-output-definition.ts +4 -0
- package/src/lib/workflow/models/index.ts +11 -0
- package/src/lib/workflow/models/trigger-category-definition.ts +6 -0
- package/src/lib/workflow/models/trigger-definition.ts +11 -0
- package/src/lib/workflow/models/workflow-action-input-type.ts +6 -0
- package/src/lib/workflow/models/workflow-action-input.ts +6 -0
- package/src/lib/workflow/models/workflow-action.ts +14 -0
- package/src/lib/workflow/models/workflow-trigger.ts +11 -0
- package/src/lib/workflow/models/workflow.ts +10 -0
- package/src/lib/workflow/workflow.service.ts +17 -0
- package/tsconfig.json +20 -0
- package/tsconfig.lib.json +24 -0
- package/tsconfig.spec.json +20 -0
package/.babelrc
ADDED
package/.eslintrc.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": ["plugin:@nx/react", "../../../.eslintrc.json"],
|
|
3
|
+
"ignorePatterns": ["!**/*"],
|
|
4
|
+
"overrides": [
|
|
5
|
+
{
|
|
6
|
+
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
|
|
7
|
+
"rules": {}
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"files": ["*.ts", "*.tsx"],
|
|
11
|
+
"rules": {}
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"files": ["*.js", "*.jsx"],
|
|
15
|
+
"rules": {}
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
}
|
package/README.md
ADDED
package/jest.config.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
export default {
|
|
3
|
+
displayName: 'libs/shared/api-client-base',
|
|
4
|
+
preset: '../../../jest.preset.js',
|
|
5
|
+
transform: {
|
|
6
|
+
'^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '@nx/react/plugins/jest',
|
|
7
|
+
'^.+\\.[tj]sx?$': ['babel-jest', { presets: ['@nx/react/babel'] }],
|
|
8
|
+
},
|
|
9
|
+
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
|
|
10
|
+
coverageDirectory: '../../../coverage/libs/shared/api-client-base',
|
|
11
|
+
};
|
package/package.json
ADDED
package/project.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "libs/shared/api-client-base",
|
|
3
|
+
"$schema": "../../../node_modules/nx/schemas/project-schema.json",
|
|
4
|
+
"sourceRoot": "libs/shared/api-client-base/src",
|
|
5
|
+
"projectType": "library",
|
|
6
|
+
"tags": [],
|
|
7
|
+
"targets": {
|
|
8
|
+
"lint": {
|
|
9
|
+
"executor": "@nx/eslint:lint",
|
|
10
|
+
"outputs": ["{options.outputFile}"],
|
|
11
|
+
"options": {
|
|
12
|
+
"lintFilePatterns": ["libs/shared/api-client-base/**/*.{ts,tsx,js,jsx}"]
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"build": {
|
|
16
|
+
"executor": "@nx/rollup:rollup",
|
|
17
|
+
"outputs": ["{options.outputPath}"],
|
|
18
|
+
"options": {
|
|
19
|
+
"outputPath": "dist/libs/shared/api-client-base",
|
|
20
|
+
"tsConfig": "libs/shared/api-client-base/tsconfig.lib.json",
|
|
21
|
+
"project": "libs/shared/api-client-base/package.json",
|
|
22
|
+
"entryFile": "libs/shared/api-client-base/src/index.ts",
|
|
23
|
+
"external": ["react", "react-dom", "react/jsx-runtime"],
|
|
24
|
+
"rollupConfig": "@nx/react/plugins/bundle-rollup",
|
|
25
|
+
"compiler": "babel",
|
|
26
|
+
"assets": [
|
|
27
|
+
{
|
|
28
|
+
"glob": "libs/shared/api-client-base/README.md",
|
|
29
|
+
"input": ".",
|
|
30
|
+
"output": "."
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"test": {
|
|
36
|
+
"executor": "@nx/jest:jest",
|
|
37
|
+
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
|
|
38
|
+
"options": {
|
|
39
|
+
"jestConfig": "libs/shared/api-client-base/jest.config.ts"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export * from './lib/fluxo-client';
|
|
2
|
+
export * from './lib/fluxo-client-base-sys';
|
|
3
|
+
export * from './lib/fluxo-state-dispatcher';
|
|
4
|
+
export * from './lib/interfaces';
|
|
5
|
+
|
|
6
|
+
export * from './lib/http-client/http-client';
|
|
7
|
+
export * from './lib/fluxo-client-interface';
|
|
8
|
+
|
|
9
|
+
/* Documentation */
|
|
10
|
+
export * from './lib/korebi/documentation';
|
|
11
|
+
|
|
12
|
+
/* Configuration */
|
|
13
|
+
export * from './lib/configuration/index';
|
|
14
|
+
|
|
15
|
+
/* Reporting */
|
|
16
|
+
export * from './lib/reporting/index';
|
|
17
|
+
|
|
18
|
+
/* Printing */
|
|
19
|
+
export * from './lib/printing/index';
|
|
20
|
+
|
|
21
|
+
/* Workflow */
|
|
22
|
+
export * from './lib/workflow/index';
|
|
23
|
+
|
|
24
|
+
/* Security Models */
|
|
25
|
+
export * from './lib/security/user';
|
|
26
|
+
export * from './lib/security/apikey';
|
|
27
|
+
export * from './lib/security/domain-role';
|
|
28
|
+
export * from './lib/security/permission';
|
|
29
|
+
export * from './lib/security/route-rule';
|
|
30
|
+
|
|
31
|
+
/* Korebi */
|
|
32
|
+
export * from './lib/korebi';
|
|
33
|
+
|
|
34
|
+
/* Apps */
|
|
35
|
+
export * from './lib/apps';
|
|
36
|
+
|
|
37
|
+
/* Utils */
|
|
38
|
+
export * from './lib/utils';
|
|
39
|
+
export * from './lib/infrastructure';
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {FluxoApp} from "./models/fluxo-app";
|
|
2
|
+
import {HttpClient} from "../http-client/http-client";
|
|
3
|
+
import {FluxoEmbeddedModuleConfiguration} from "./models";
|
|
4
|
+
|
|
5
|
+
export class AppService {
|
|
6
|
+
|
|
7
|
+
getApps(onlyDeployed: boolean): Promise<FluxoApp[]> {
|
|
8
|
+
|
|
9
|
+
const url = onlyDeployed ? 'apps?onlyDeployed=true' : 'apps';
|
|
10
|
+
|
|
11
|
+
return HttpClient.Instance().client.get(url);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
activateApp(appId: number): Promise<any> {
|
|
15
|
+
return HttpClient.Instance().client.post(`apps/${appId}/activate`, {});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
deactivateApp(appId: number): Promise<any> {
|
|
19
|
+
return HttpClient.Instance().client.post(`apps/${appId}/deactivate`, {});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
installApp(data: any): Promise<any> {
|
|
23
|
+
return HttpClient.Instance().client.post(`apps/install`, data, {
|
|
24
|
+
headers: {
|
|
25
|
+
"Content-Type": "multipart/form-data",
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
upgradeApp(appId: number, data: any): Promise<any> {
|
|
31
|
+
return HttpClient.Instance().client.post(`apps/${appId}/upgrade`, data, {
|
|
32
|
+
headers: {
|
|
33
|
+
"Content-Type": "multipart/form-data",
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
uninstallApp(appId: number): Promise<any> {
|
|
39
|
+
return HttpClient.Instance().client.delete(`apps/${appId}/uninstall`);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
installEmbeddedModule(data: FluxoEmbeddedModuleConfiguration): Promise<void> {
|
|
43
|
+
return HttpClient.Instance().client.post(`apps/install/embedded`, data);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import {FluxoEmbeddedModuleConfiguration} from "./fluxo-embedded-module-configuration";
|
|
2
|
+
import {IndexRouteObject, LazyRouteFunction, NonIndexRouteObject, RouteObject} from "react-router-dom";
|
|
3
|
+
import {FluxoAppMenu} from "./fluxo-app-menu";
|
|
4
|
+
|
|
5
|
+
export class EmbeddedModule {
|
|
6
|
+
|
|
7
|
+
public get name(): string {
|
|
8
|
+
return this._name;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
public get description(): string {
|
|
12
|
+
return this._description;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public get author(): string {
|
|
16
|
+
return this._author;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public get version(): string {
|
|
20
|
+
return this._version;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public get scope(): string {
|
|
24
|
+
return this._scope;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public get navigation(): EmbeddedModuleNavigation[] {
|
|
28
|
+
return this._navigation;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
private readonly _name: string
|
|
32
|
+
private readonly _description: string
|
|
33
|
+
private readonly _author: string
|
|
34
|
+
private readonly _version: string
|
|
35
|
+
private readonly _scope: string
|
|
36
|
+
private _navigation: EmbeddedModuleNavigation[] = [];
|
|
37
|
+
|
|
38
|
+
constructor(name: string, description: string, author: string, version: string, scope: string) {
|
|
39
|
+
this._name = name;
|
|
40
|
+
this._description = description;
|
|
41
|
+
this._author = author;
|
|
42
|
+
this._version = version;
|
|
43
|
+
this._scope = scope;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public attachNavigation(navigationConfig: EmbeddedModuleNavigation): void {
|
|
47
|
+
this._navigation.push(navigationConfig);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public getRouteObject(routes: EmbeddedModuleRoute[] | undefined = undefined): RouteObject[] {
|
|
51
|
+
const r = routes ?? this._navigation.map(a => a.routes).map(a => a).flat();
|
|
52
|
+
|
|
53
|
+
if(!r || r.length === 0) return [];
|
|
54
|
+
|
|
55
|
+
const routeObject: RouteObject[] = [];
|
|
56
|
+
|
|
57
|
+
r.map((route: EmbeddedModuleRoute) => {
|
|
58
|
+
if (route.route) {
|
|
59
|
+
|
|
60
|
+
let path = route.route;
|
|
61
|
+
|
|
62
|
+
if(route.route === '/') {
|
|
63
|
+
path = '';
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if(route.route === "*") {
|
|
67
|
+
path = '*';
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
routeObject.push({
|
|
71
|
+
path: path,
|
|
72
|
+
index: route.route === '/' ? undefined : false,
|
|
73
|
+
element: route.component,
|
|
74
|
+
children: (route.routes && route.routes.length > 0) ? this.getRouteObject(route.routes) : [],
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
return routeObject;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public getEmbeddedModule(): FluxoEmbeddedModuleConfiguration {
|
|
83
|
+
|
|
84
|
+
const conf: FluxoEmbeddedModuleConfiguration = {
|
|
85
|
+
name: this._name,
|
|
86
|
+
description: this._description,
|
|
87
|
+
author: this._author,
|
|
88
|
+
version: this._version,
|
|
89
|
+
scope: this._scope,
|
|
90
|
+
menu: this._navigation.map(a => a.menu)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return conf;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export interface EmbeddedModuleNavigation {
|
|
98
|
+
menu: FluxoAppMenu;
|
|
99
|
+
routes: EmbeddedModuleRoute[];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export interface EmbeddedModuleRoute {
|
|
103
|
+
route?: string;
|
|
104
|
+
component?: any,
|
|
105
|
+
routes?: EmbeddedModuleRoute[];
|
|
106
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {AppType} from "./app-type";
|
|
2
|
+
import {AppState} from "./app-state";
|
|
3
|
+
|
|
4
|
+
export interface FluxoApp {
|
|
5
|
+
id: number;
|
|
6
|
+
name: string;
|
|
7
|
+
type: AppType;
|
|
8
|
+
description: string;
|
|
9
|
+
author: string;
|
|
10
|
+
scope: string;
|
|
11
|
+
state: AppState;
|
|
12
|
+
installationDirectory: string;
|
|
13
|
+
installationDate: Date;
|
|
14
|
+
version: string;
|
|
15
|
+
isEmbedded: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {FluxoApp} from "./fluxo-app";
|
|
2
|
+
import {FluxoAppMenu} from "./fluxo-app-menu";
|
|
3
|
+
|
|
4
|
+
export interface FluxoFrontendAppConfiguration extends FluxoApp {
|
|
5
|
+
name: string
|
|
6
|
+
description: string
|
|
7
|
+
author: string
|
|
8
|
+
version: string
|
|
9
|
+
scope: string
|
|
10
|
+
menu: FluxoAppMenu[]
|
|
11
|
+
}
|
|
12
|
+
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './app-type';
|
|
2
|
+
export * from './app-state';
|
|
3
|
+
export * from './fluxo-app';
|
|
4
|
+
export * from './fluxo-frontend-app-configuration';
|
|
5
|
+
export * from './fluxo-app-menu';
|
|
6
|
+
export {FluxoEmbeddedModuleConfiguration} from "./fluxo-embedded-module-configuration";
|
|
7
|
+
export * from "./embedded-module";
|
|
8
|
+
export * from "./flx-app-routes";
|
|
9
|
+
export * from "./flx-route";
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import jwt_decode from "jwt-decode";
|
|
2
|
+
import {LocalStorageConstants} from "../constants/local-storage";
|
|
3
|
+
import {HttpClient} from "../http-client/http-client";
|
|
4
|
+
import {FluxoStateDispatcher} from "../fluxo-state-dispatcher";
|
|
5
|
+
|
|
6
|
+
export class AuthService {
|
|
7
|
+
|
|
8
|
+
public constructor() {
|
|
9
|
+
RefreshTokenManager.Init(this.refreshToken, this.logout);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
public async setup() {
|
|
13
|
+
await this.tryAutoLogin();
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
private async tryAutoLogin() {
|
|
17
|
+
const accessToken = localStorage.getItem(LocalStorageConstants.accessToken);
|
|
18
|
+
if(accessToken) {
|
|
19
|
+
const decoded: any = jwt_decode(accessToken);
|
|
20
|
+
|
|
21
|
+
if(!decoded) {
|
|
22
|
+
this.logout();
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if(decoded.exp <= new Date().getTime() / 1000) {
|
|
27
|
+
|
|
28
|
+
await this.refreshToken();
|
|
29
|
+
|
|
30
|
+
} else {
|
|
31
|
+
// Avvio il timeout indicando il tempo di attesa come scadenza token - 30 secondi.
|
|
32
|
+
// pertanto, 30 secondi prima della scadenza del token, Fluxo richiederà un nuovo token grazie al refresh token.
|
|
33
|
+
RefreshTokenManager.Instance.start(AuthService.getJwtTokenRemainingLifetime()! - 30000);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
FluxoStateDispatcher. dispatchAutoLoginSucceded(localStorage.getItem(LocalStorageConstants.userData));
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public async login(username: string, password: string): Promise<any> {
|
|
42
|
+
try {
|
|
43
|
+
|
|
44
|
+
const data = await HttpClient.Instance().client.post('/identity/authenticate', {username, password}, {withCredentials: true});
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
localStorage.setItem(LocalStorageConstants.accessToken, (data as any).token);
|
|
48
|
+
localStorage.setItem(LocalStorageConstants.userData, JSON.stringify((data as any).userData));
|
|
49
|
+
|
|
50
|
+
RefreshTokenManager.Instance.start(AuthService.getJwtTokenRemainingLifetime()! - 60);
|
|
51
|
+
|
|
52
|
+
FluxoStateDispatcher.dispatchUserLogin({data})
|
|
53
|
+
}
|
|
54
|
+
catch(err) {
|
|
55
|
+
FluxoStateDispatcher.dispatchUserLogin(null)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public logout() {
|
|
60
|
+
RefreshTokenManager.Instance.stop();
|
|
61
|
+
|
|
62
|
+
localStorage.removeItem(LocalStorageConstants.accessToken);
|
|
63
|
+
localStorage.removeItem(LocalStorageConstants.userData);
|
|
64
|
+
FluxoStateDispatcher.dispatchUserLogout();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public async refreshToken(): Promise<any> {
|
|
68
|
+
|
|
69
|
+
try {
|
|
70
|
+
|
|
71
|
+
const data = await HttpClient.Instance().client.post('/identity/refresh-token', {}, {withCredentials: true});
|
|
72
|
+
|
|
73
|
+
localStorage.setItem(LocalStorageConstants.accessToken, (data as any).token);
|
|
74
|
+
localStorage.setItem(LocalStorageConstants.userData, JSON.stringify((data as any).userData));
|
|
75
|
+
|
|
76
|
+
RefreshTokenManager.Instance.stop();
|
|
77
|
+
RefreshTokenManager.Instance.start(AuthService.getJwtTokenRemainingLifetime()! - 10000);
|
|
78
|
+
|
|
79
|
+
} catch(err) {
|
|
80
|
+
localStorage.removeItem(LocalStorageConstants.accessToken);
|
|
81
|
+
localStorage.removeItem(LocalStorageConstants.userData);
|
|
82
|
+
this.logout();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
public static getJwtTokenRemainingLifetime(): number | null {
|
|
87
|
+
const token = localStorage.getItem(LocalStorageConstants.accessToken);
|
|
88
|
+
|
|
89
|
+
if(!token) {
|
|
90
|
+
throw new Error('Called getJwtTokenRemainingLifetime but no access token found');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const decoded: any = jwt_decode(token);
|
|
94
|
+
const exp: number = +decoded.exp;
|
|
95
|
+
|
|
96
|
+
const dateNow = new Date(Date.now()).getTime();
|
|
97
|
+
const diff = ((exp * 1000) - dateNow);
|
|
98
|
+
|
|
99
|
+
return diff <= 0 ? 0 : diff;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
class RefreshTokenManager {
|
|
104
|
+
private static _instance: RefreshTokenManager;
|
|
105
|
+
private _refreshTokenInterval: any;
|
|
106
|
+
private _actionOnTimeout: () => void;
|
|
107
|
+
private _onErrorCallback: () => void;
|
|
108
|
+
|
|
109
|
+
event = new Event('build');
|
|
110
|
+
|
|
111
|
+
private constructor(action: () => void, onErrorCallback: () => void) {
|
|
112
|
+
this._refreshTokenInterval = null;
|
|
113
|
+
this._actionOnTimeout = action;
|
|
114
|
+
this._onErrorCallback = onErrorCallback;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
public static Init(actionOnTimeout: () => void, onErrorCallback: () => void) {
|
|
118
|
+
this._instance = new this(actionOnTimeout, onErrorCallback);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
public static get Instance() {
|
|
122
|
+
|
|
123
|
+
if(!this._instance)
|
|
124
|
+
throw new Error('RefreshTokenManager not initialized');
|
|
125
|
+
|
|
126
|
+
return this._instance;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
public start(timeoutMs: number) {
|
|
130
|
+
|
|
131
|
+
console.info(' - start refresh token:' + timeoutMs + 'ms');
|
|
132
|
+
|
|
133
|
+
if(this._actionOnTimeout === undefined)
|
|
134
|
+
throw new Error('RefreshTokenManager not initialized');
|
|
135
|
+
|
|
136
|
+
this._refreshTokenInterval = setTimeout(async () => {
|
|
137
|
+
try{
|
|
138
|
+
await this._actionOnTimeout();
|
|
139
|
+
}catch(err) {
|
|
140
|
+
this._onErrorCallback();
|
|
141
|
+
}
|
|
142
|
+
}, timeoutMs);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
public stop() {
|
|
146
|
+
console.info(' - stop refresh token');
|
|
147
|
+
clearInterval(this._refreshTokenInterval);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface AppMenuItem {
|
|
2
|
+
id?: number,
|
|
3
|
+
routerLink?: string,
|
|
4
|
+
label: string,
|
|
5
|
+
hasIndex?: boolean,
|
|
6
|
+
children?: AppMenuItem[],
|
|
7
|
+
icon?: string
|
|
8
|
+
featureIdentifier: string,
|
|
9
|
+
isGroup: boolean,
|
|
10
|
+
menuItemId?: number,
|
|
11
|
+
hasPermissions?: boolean,
|
|
12
|
+
permissions?: string[],
|
|
13
|
+
isProtectedByRule?: boolean,
|
|
14
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface AppMenu {
|
|
2
|
+
id: number;
|
|
3
|
+
name: string;
|
|
4
|
+
contextType: AppMenuContextType;
|
|
5
|
+
domainRoleId: number;
|
|
6
|
+
domainRoleName: string;
|
|
7
|
+
userId: string;
|
|
8
|
+
userFullName: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export enum AppMenuContextType {
|
|
12
|
+
Default,
|
|
13
|
+
DomainRole,
|
|
14
|
+
User
|
|
15
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {HttpClient} from "../http-client/http-client";
|
|
2
|
+
import { AppMenuItem } from "./app-menu-item";
|
|
3
|
+
import { ClientUi } from "./client-ui";
|
|
4
|
+
import {FeatureList} from "./models/feature-list";
|
|
5
|
+
import {FluxoApp} from "../apps/models/fluxo-app";
|
|
6
|
+
import {DomainRole} from "../security/domain-role/index";
|
|
7
|
+
import {RouteRuleWithPermissions} from "../security/route-rule/index";
|
|
8
|
+
import {Permission} from "../security/permission/index";
|
|
9
|
+
import {AppMenu} from "./app-menu";
|
|
10
|
+
import {AppMenuCreateCommand} from "./app-menu-create-command";
|
|
11
|
+
|
|
12
|
+
export class ConfigurationService {
|
|
13
|
+
|
|
14
|
+
getInitialConfiguration(): Promise<{apps: FluxoApp[], menu: AppMenuItem[], features: FeatureList, ui: ClientUi, domainRoles: DomainRole[], permissions: any[], routeRules: RouteRuleWithPermissions[], isFluxoConfigured: boolean }> {
|
|
15
|
+
return HttpClient.Instance().client.get('client/initial');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
getClientUi(): Promise<ClientUi> {
|
|
19
|
+
return HttpClient.Instance().client.get('client/ui');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
updateClientUi(clientUI: ClientUi): Promise<ClientUi> {
|
|
23
|
+
return HttpClient.Instance().client.post('client/ui', clientUI);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
getSystemFeatures(): Promise<FeatureList> {
|
|
27
|
+
return HttpClient.Instance().client.get('features/web')
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
saveAppMenu(webMenuId: number, menu: AppMenuItem[]): Promise<any> {
|
|
31
|
+
return HttpClient.Instance().client.post(`client/menu/${webMenuId}/webapp`, menu);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
createAppMenu(menu: AppMenuCreateCommand): Promise<any> {
|
|
35
|
+
return HttpClient.Instance().client.post('client/menu/webapp', menu);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
getAppMenuList(): Promise<AppMenu[]> {
|
|
39
|
+
return HttpClient.Instance().client.get('webmenu?includes=DomainRole,User');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
getAppMenu(webMenuId: number): Promise<AppMenuItem[]> {
|
|
43
|
+
return HttpClient.Instance().client.get(`client/menu/${webMenuId}/webapp`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public getMenuItemPermissions(domainRoleId: string): Promise<Permission[]> {
|
|
47
|
+
return HttpClient.Instance().client.get(`webmenuitem/${domainRoleId}/permissions`);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public addMenuItemPermission(domainRoleId: number, permissionId: number): Promise<void> {
|
|
51
|
+
return HttpClient.Instance().client.post(`webmenuitem/${domainRoleId}/permissions`, {domainRoleId: domainRoleId, permissionId: permissionId});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
public removeMenuItemPermission(domainRoleId: number, permissionId: number): Promise<void> {
|
|
55
|
+
return HttpClient.Instance().client.delete(`webmenuitem/${domainRoleId}/permissions/${permissionId}`);
|
|
56
|
+
}
|
|
57
|
+
}
|