@rws-framework/client 2.20.1 → 2.20.3

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 (84) hide show
  1. package/.bin/emerge.sh +15 -15
  2. package/builder/vite/index.ts +4 -4
  3. package/builder/vite/rws.vite.config.ts +132 -132
  4. package/builder/vite/rws_scss_plugin.ts +61 -61
  5. package/builder/webpack/index.js +10 -10
  6. package/builder/webpack/rws.webpack.config.js +161 -161
  7. package/builder/webpack/rws_scss_plugin.js +90 -90
  8. package/builder/webpack/rws_webpack_plugin.js +137 -137
  9. package/cfg/_default.cfg.js +26 -26
  10. package/cfg/_storage.d.ts +22 -22
  11. package/cfg/_storage.js +42 -42
  12. package/cfg/tsconfigSetup.js +146 -146
  13. package/docs/assets/26e93147f10415a0ed4a.svg +6 -6
  14. package/docs/assets/75c9471662e97ee24f29.svg +7 -7
  15. package/docs/assets/db90e4df2373980c497d.svg +9 -9
  16. package/docs/assets/highlight.css +127 -127
  17. package/docs/assets/main.js +59 -59
  18. package/docs/assets/style.css +1414 -1414
  19. package/docs/classes/ApiServiceInstance.html +25 -25
  20. package/docs/classes/ConfigServiceInstance.html +21 -21
  21. package/docs/classes/DOMServiceInstance.html +17 -17
  22. package/docs/classes/NotifyServiceInstance.html +15 -15
  23. package/docs/classes/RWSClientInstance.html +45 -45
  24. package/docs/classes/RWSPlugin.html +13 -13
  25. package/docs/classes/RWSService.html +10 -10
  26. package/docs/classes/RWSViewComponent.html +1022 -1022
  27. package/docs/classes/ServiceWorkerServiceInstance.html +13 -13
  28. package/docs/classes/UtilsServiceInstance.html +13 -13
  29. package/docs/functions/attr.html +5 -5
  30. package/docs/functions/observable.html +3 -3
  31. package/docs/index.html +179 -179
  32. package/docs/interfaces/HTMLTag.html +3 -3
  33. package/docs/interfaces/IRWSConfig.html +20 -20
  34. package/docs/interfaces/IRWSDecoratorOptions.html +5 -5
  35. package/docs/interfaces/IRWSHttpRoute.html +2 -2
  36. package/docs/interfaces/IRWSPrefixedHTTProutes.html +2 -2
  37. package/docs/interfaces/IRWSUser.html +5 -5
  38. package/docs/modules.html +45 -45
  39. package/foundation/index.js +1 -1
  40. package/foundation/rws-foundation.d.ts +7 -7
  41. package/foundation/rws-foundation.js +7 -7
  42. package/package.json +1 -1
  43. package/service_worker/src/_service_worker.ts +83 -83
  44. package/service_worker/tsconfig.json +20 -20
  45. package/service_worker/webpack.config.js +66 -66
  46. package/src/client/components.ts +67 -67
  47. package/src/client/config.ts +175 -175
  48. package/src/client/hotReload.ts +22 -22
  49. package/src/client/services.ts +27 -27
  50. package/src/client.ts +208 -208
  51. package/src/components/_component.ts +247 -247
  52. package/src/components/_container.ts +15 -15
  53. package/src/components/_decorator.ts +122 -122
  54. package/src/components/_definitions.ts +64 -64
  55. package/src/components/_event_handling.ts +40 -40
  56. package/src/components/index.ts +25 -25
  57. package/src/index.ts +86 -86
  58. package/src/plugins/_builder.js +31 -31
  59. package/src/plugins/_plugin.ts +60 -60
  60. package/src/services/ApiService.ts +105 -105
  61. package/src/services/ConfigService.ts +125 -125
  62. package/src/services/DOMService.ts +93 -93
  63. package/src/services/NotifyService.ts +47 -47
  64. package/src/services/ServiceWorkerService.ts +60 -60
  65. package/src/services/UtilsService.ts +60 -60
  66. package/src/services/_service.ts +64 -64
  67. package/src/styles/README.md +157 -157
  68. package/src/styles/_darkreader.scss +30 -30
  69. package/src/styles/_grid.scss +75 -75
  70. package/src/styles/_grid_legacy.scss +49 -49
  71. package/src/styles/_misc.scss +8 -8
  72. package/src/styles/_scrollbars.scss +40 -40
  73. package/src/styles/includes.scss +6 -6
  74. package/src/types/IBackendCore.ts +11 -11
  75. package/src/types/IRWSConfig.ts +29 -29
  76. package/src/types/IRWSPlugin.ts +23 -23
  77. package/src/types/IRWSResource.ts +4 -4
  78. package/src/types/IRWSUser.ts +6 -6
  79. package/src/types/IRWSViewComponent.ts +36 -36
  80. package/src/types/IReFormerField.ts +4 -4
  81. package/src/types/RWSNotify.ts +6 -6
  82. package/src/types/RWSWindow.ts +41 -41
  83. package/types/declarations.d.ts +8 -8
  84. package/types/docs-typings.d.ts +15 -15
package/src/index.ts CHANGED
@@ -1,87 +1,87 @@
1
- import { observable, attr } from '@microsoft/fast-element';
2
-
3
- import RWSService from './services/_service';
4
- import ConfigService, { ConfigServiceInstance } from './services/ConfigService';
5
- import NotifyService, {NotifyServiceInstance} from './services/NotifyService';
6
- import DOMService, { DOMServiceInstance } from './services/DOMService';
7
- import ApiService, { ApiServiceInstance } from './services/ApiService';
8
- import UtilsService, {UtilsServiceInstance} from './services/UtilsService';
9
- import ServiceWorkerService, { ServiceWorkerServiceInstance } from './services/ServiceWorkerService';
10
- import { ngAttr } from './components/_attrs/angular-attr';
11
- import { externalObservable } from './components/_attrs/external-observable';
12
- import { externalAttr } from './components/_attrs/external-attr';
13
- import { RWSPlugin } from './plugins/_plugin';
14
- import RWSClient, { RWSClientInstance } from './client';
15
- import RWSViewComponent from './components/_component';
16
- import RWSContainer from './components/_container';
17
-
18
- import { RWSIgnore, RWSInject, RWSView } from './components/_decorator';
19
- import { declareRWSComponents } from './components';
20
-
21
- import type { DefaultRWSPluginOptionsType } from './plugins/_plugin';
22
- import type { IRWSPlugin, IStaticRWSPlugin, IPluginSpawnOption } from './types/IRWSPlugin';
23
- import type IRWSUser from './types/IRWSUser';
24
- import type { IAssetShowOptions } from './components/_component';
25
- import type { RWSDecoratorOptions } from './components/_decorator';
26
- import type { IKDBTypeInfo, IKDBTypesResponse } from './types/IBackendCore';
27
- import type { DOMOutputType, TagsProcessorType } from './services/DOMService';
28
- import type { IBackendRoute, IHTTProute, IPrefixedHTTProutes } from './services/ApiService';
29
- import type IRWSConfig from './types/IRWSConfig';
30
- import type RWSNotify from './types/RWSNotify';
31
- import type { NotifyUiType, NotifyLogType } from './types/RWSNotify';
32
-
33
- export default RWSClient;
34
-
35
- export {
36
- RWSClient,
37
- RWSClientInstance,
38
-
39
- RWSPlugin,
40
- IPluginSpawnOption,
41
- IRWSPlugin, IStaticRWSPlugin,
42
- DefaultRWSPluginOptionsType,
43
- ApiServiceInstance,
44
- ApiService,
45
- UtilsServiceInstance,
46
- UtilsService,
47
- DOMServiceInstance,
48
- DOMService,
49
- DOMOutputType,
50
- NotifyServiceInstance,
51
- NotifyService,
52
- ConfigServiceInstance,
53
- ConfigService,
54
- ServiceWorkerServiceInstance,
55
- ServiceWorkerService,
56
-
57
- RWSNotify,
58
-
59
- RWSView,
60
- RWSIgnore,
61
- RWSInject,
62
- observable,
63
- externalObservable,
64
- externalAttr,
65
- attr,
66
- ngAttr,
67
-
68
- RWSService,
69
- RWSViewComponent,
70
- declareRWSComponents,
71
-
72
- RWSContainer
73
- };
74
-
75
- export type {
76
- IKDBTypeInfo, IKDBTypesResponse,
77
- NotifyUiType,
78
- NotifyLogType,
79
- IBackendRoute as IRWSBackendRoute,
80
- RWSDecoratorOptions as IRWSDecoratorOptions,
81
- IHTTProute as IRWSHttpRoute,
82
- IPrefixedHTTProutes as IRWSPrefixedHTTProutes,
83
- IAssetShowOptions as IRWSAssetShowOptions,
84
- IRWSConfig,
85
- IRWSUser,
86
- TagsProcessorType
1
+ import { observable, attr } from '@microsoft/fast-element';
2
+
3
+ import RWSService from './services/_service';
4
+ import ConfigService, { ConfigServiceInstance } from './services/ConfigService';
5
+ import NotifyService, {NotifyServiceInstance} from './services/NotifyService';
6
+ import DOMService, { DOMServiceInstance } from './services/DOMService';
7
+ import ApiService, { ApiServiceInstance } from './services/ApiService';
8
+ import UtilsService, {UtilsServiceInstance} from './services/UtilsService';
9
+ import ServiceWorkerService, { ServiceWorkerServiceInstance } from './services/ServiceWorkerService';
10
+ import { ngAttr } from './components/_attrs/angular-attr';
11
+ import { externalObservable } from './components/_attrs/external-observable';
12
+ import { externalAttr } from './components/_attrs/external-attr';
13
+ import { RWSPlugin } from './plugins/_plugin';
14
+ import RWSClient, { RWSClientInstance } from './client';
15
+ import RWSViewComponent from './components/_component';
16
+ import RWSContainer from './components/_container';
17
+
18
+ import { RWSIgnore, RWSInject, RWSView } from './components/_decorator';
19
+ import { declareRWSComponents } from './components';
20
+
21
+ import type { DefaultRWSPluginOptionsType } from './plugins/_plugin';
22
+ import type { IRWSPlugin, IStaticRWSPlugin, IPluginSpawnOption } from './types/IRWSPlugin';
23
+ import type IRWSUser from './types/IRWSUser';
24
+ import type { IAssetShowOptions } from './components/_component';
25
+ import type { RWSDecoratorOptions } from './components/_decorator';
26
+ import type { IKDBTypeInfo, IKDBTypesResponse } from './types/IBackendCore';
27
+ import type { DOMOutputType, TagsProcessorType } from './services/DOMService';
28
+ import type { IBackendRoute, IHTTProute, IPrefixedHTTProutes } from './services/ApiService';
29
+ import type IRWSConfig from './types/IRWSConfig';
30
+ import type RWSNotify from './types/RWSNotify';
31
+ import type { NotifyUiType, NotifyLogType } from './types/RWSNotify';
32
+
33
+ export default RWSClient;
34
+
35
+ export {
36
+ RWSClient,
37
+ RWSClientInstance,
38
+
39
+ RWSPlugin,
40
+ IPluginSpawnOption,
41
+ IRWSPlugin, IStaticRWSPlugin,
42
+ DefaultRWSPluginOptionsType,
43
+ ApiServiceInstance,
44
+ ApiService,
45
+ UtilsServiceInstance,
46
+ UtilsService,
47
+ DOMServiceInstance,
48
+ DOMService,
49
+ DOMOutputType,
50
+ NotifyServiceInstance,
51
+ NotifyService,
52
+ ConfigServiceInstance,
53
+ ConfigService,
54
+ ServiceWorkerServiceInstance,
55
+ ServiceWorkerService,
56
+
57
+ RWSNotify,
58
+
59
+ RWSView,
60
+ RWSIgnore,
61
+ RWSInject,
62
+ observable,
63
+ externalObservable,
64
+ externalAttr,
65
+ attr,
66
+ ngAttr,
67
+
68
+ RWSService,
69
+ RWSViewComponent,
70
+ declareRWSComponents,
71
+
72
+ RWSContainer
73
+ };
74
+
75
+ export type {
76
+ IKDBTypeInfo, IKDBTypesResponse,
77
+ NotifyUiType,
78
+ NotifyLogType,
79
+ IBackendRoute as IRWSBackendRoute,
80
+ RWSDecoratorOptions as IRWSDecoratorOptions,
81
+ IHTTProute as IRWSHttpRoute,
82
+ IPrefixedHTTProutes as IRWSPrefixedHTTProutes,
83
+ IAssetShowOptions as IRWSAssetShowOptions,
84
+ IRWSConfig,
85
+ IRWSUser,
86
+ TagsProcessorType
87
87
  }
@@ -1,32 +1,32 @@
1
- const fs = require('fs');
2
- const chalk = require('chalk');
3
-
4
- class RWSPluginBuilder {
5
- pluginInfo = {name: null};
6
-
7
- constructor(pluginPath, buildConfigurator, baseBuildConfig){
8
- this.pluginPath = pluginPath;
9
- this.buildConfigurator = buildConfigurator;
10
- this.baseBuildConfig = baseBuildConfig;
11
-
12
- this.pluginInfo = JSON.parse(fs.readFileSync(this.pluginPath + '/plugin-info.json', 'utf-8'));
13
- }
14
-
15
- async onComponentsLocated(partedComponentsLocations = []){
16
- return partedComponentsLocations;
17
- }
18
-
19
- async onServicesLocated(servicesLocations){
20
- return servicesLocations;
21
- }
22
-
23
- async onBuild(webpackOptions){
24
- return webpackOptions;
25
- }
26
-
27
- log(msg){
28
- console.log(chalk.blue('RWS Plugin'), chalk.green(this.pluginInfo.name) + ':', msg);
29
- }
30
- }
31
-
1
+ const fs = require('fs');
2
+ const chalk = require('chalk');
3
+
4
+ class RWSPluginBuilder {
5
+ pluginInfo = {name: null};
6
+
7
+ constructor(pluginPath, buildConfigurator, baseBuildConfig){
8
+ this.pluginPath = pluginPath;
9
+ this.buildConfigurator = buildConfigurator;
10
+ this.baseBuildConfig = baseBuildConfig;
11
+
12
+ this.pluginInfo = JSON.parse(fs.readFileSync(this.pluginPath + '/plugin-info.json', 'utf-8'));
13
+ }
14
+
15
+ async onComponentsLocated(partedComponentsLocations = []){
16
+ return partedComponentsLocations;
17
+ }
18
+
19
+ async onServicesLocated(servicesLocations){
20
+ return servicesLocations;
21
+ }
22
+
23
+ async onBuild(webpackOptions){
24
+ return webpackOptions;
25
+ }
26
+
27
+ log(msg){
28
+ console.log(chalk.blue('RWS Plugin'), chalk.green(this.pluginInfo.name) + ':', msg);
29
+ }
30
+ }
31
+
32
32
  module.exports = { RWSPluginBuilder };
@@ -1,61 +1,61 @@
1
- import RWSContainer from "../components/_container";
2
- import { Container } from "../components/_container";
3
- import RWSWindow, {loadRWSRichWindow } from '../types/RWSWindow';
4
- import IRWSUser from "../types/IRWSUser";
5
- import { RWSInfoType } from "../client/components";
6
- import { IRWSPlugin, IStaticRWSPlugin } from "../types/IRWSPlugin";
7
-
8
- export type DefaultRWSPluginOptionsType = { enabled?: boolean };
9
- type PluginInfoType = { name: string };
10
- type PluginConstructor<T extends DefaultRWSPluginOptionsType> = new (options: T) => RWSPlugin<T>;
11
-
12
- abstract class RWSPlugin<T extends DefaultRWSPluginOptionsType> extends IRWSPlugin<T> {
13
- protected isLoaded: boolean = false;
14
- protected options!: T;
15
- protected container!: Container;
16
- protected window!: RWSWindow;
17
-
18
- static container: Container;
19
- static window: RWSWindow;
20
-
21
- constructor(options: T = { enabled: true } as T) {
22
- super();
23
- this.isLoaded = true;
24
- this.container = RWSPlugin.container;
25
- this.window = RWSPlugin.window;
26
- this.options = options;
27
- }
28
-
29
- async onClientStart(): Promise<void> {
30
- // Implementation
31
- }
32
-
33
- async onPartedComponentsLoad(componentParts: RWSInfoType): Promise<void> {
34
- // Implementation
35
- }
36
-
37
- async onComponentsDeclare(): Promise<void> {
38
- // Implementation
39
- }
40
-
41
- async onSetUser(user: IRWSUser): Promise<void> {
42
- // Implementation
43
- }
44
-
45
- static getPlugin<P extends RWSPlugin<T>, T extends DefaultRWSPluginOptionsType = DefaultRWSPluginOptionsType>(
46
- pluginClass: IStaticRWSPlugin<T>
47
- ): P | null {
48
- const plugin = this.window.RWS.plugins[pluginClass.name];
49
- return plugin ? plugin as P : null;
50
- }
51
-
52
- static getAllPlugins(): Array<RWSPlugin<DefaultRWSPluginOptionsType>> {
53
- return Object.keys(this.window.RWS.plugins)
54
- .map((key) => this.window.RWS.plugins[key]);
55
- }
56
- }
57
-
58
- RWSPlugin.window = loadRWSRichWindow();
59
- RWSPlugin.container = RWSContainer();
60
-
1
+ import RWSContainer from "../components/_container";
2
+ import { Container } from "../components/_container";
3
+ import RWSWindow, {loadRWSRichWindow } from '../types/RWSWindow';
4
+ import IRWSUser from "../types/IRWSUser";
5
+ import { RWSInfoType } from "../client/components";
6
+ import { IRWSPlugin, IStaticRWSPlugin } from "../types/IRWSPlugin";
7
+
8
+ export type DefaultRWSPluginOptionsType = { enabled?: boolean };
9
+ type PluginInfoType = { name: string };
10
+ type PluginConstructor<T extends DefaultRWSPluginOptionsType> = new (options: T) => RWSPlugin<T>;
11
+
12
+ abstract class RWSPlugin<T extends DefaultRWSPluginOptionsType> extends IRWSPlugin<T> {
13
+ protected isLoaded: boolean = false;
14
+ protected options!: T;
15
+ protected container!: Container;
16
+ protected window!: RWSWindow;
17
+
18
+ static container: Container;
19
+ static window: RWSWindow;
20
+
21
+ constructor(options: T = { enabled: true } as T) {
22
+ super();
23
+ this.isLoaded = true;
24
+ this.container = RWSPlugin.container;
25
+ this.window = RWSPlugin.window;
26
+ this.options = options;
27
+ }
28
+
29
+ async onClientStart(): Promise<void> {
30
+ // Implementation
31
+ }
32
+
33
+ async onPartedComponentsLoad(componentParts: RWSInfoType): Promise<void> {
34
+ // Implementation
35
+ }
36
+
37
+ async onComponentsDeclare(): Promise<void> {
38
+ // Implementation
39
+ }
40
+
41
+ async onSetUser(user: IRWSUser): Promise<void> {
42
+ // Implementation
43
+ }
44
+
45
+ static getPlugin<P extends RWSPlugin<T>, T extends DefaultRWSPluginOptionsType = DefaultRWSPluginOptionsType>(
46
+ pluginClass: IStaticRWSPlugin<T>
47
+ ): P | null {
48
+ const plugin = this.window.RWS.plugins[pluginClass.name];
49
+ return plugin ? plugin as P : null;
50
+ }
51
+
52
+ static getAllPlugins(): Array<RWSPlugin<DefaultRWSPluginOptionsType>> {
53
+ return Object.keys(this.window.RWS.plugins)
54
+ .map((key) => this.window.RWS.plugins[key]);
55
+ }
56
+ }
57
+
58
+ RWSPlugin.window = loadRWSRichWindow();
59
+ RWSPlugin.container = RWSContainer();
60
+
61
61
  export { RWSPlugin };
@@ -1,106 +1,106 @@
1
- import { IKDBTypesResponse } from '../types/IBackendCore';
2
- import TheService from './_service';
3
-
4
- //@4DI
5
- import ConfigService, { ConfigServiceInstance } from './ConfigService';
6
-
7
- import { upload, UploadResponse } from 'upload';
8
-
9
- import { backend } from './_api/backend';
10
- import { calls } from './_api/calls';
11
-
12
- interface RequestOptions {
13
- method?: string;
14
- headers: HeadersInit;
15
- body?: string;
16
- }
17
-
18
- interface IAPIOptions {
19
- headers?: Headers,
20
- routeParams?: {
21
- [key: string]: string
22
- },
23
- }
24
-
25
- interface IHTTProute<P = {[key: string]: any}> {
26
- name: string;
27
- path: string;
28
- method: string;
29
- noParams?: boolean;
30
- options?: any;
31
- plugins?: P
32
- }
33
-
34
- interface IPrefixedHTTProutes<P = {[key: string]: any}> {
35
- prefix: string;
36
- controllerName: string;
37
- exportAutoRoutes?: boolean,
38
- routes: IHTTProute<P>[];
39
- }
40
-
41
-
42
- type IBackendRoute = IHTTProute | IPrefixedHTTProutes;
43
-
44
-
45
-
46
- class ApiService extends TheService {
47
- static _DEFAULT: boolean = true;
48
- public token?: string;
49
-
50
- constructor(@ConfigService public config: ConfigServiceInstance) {
51
- super();
52
- }
53
-
54
- public setToken(token: string)
55
- {
56
- this.token = token;
57
- }
58
-
59
-
60
-
61
- public async isGetTargetReachable(url: string, options: IAPIOptions = {}): Promise<boolean> {
62
- try {
63
- return !!(await calls.pureGet.bind(this)(url, options));
64
- } catch (error) {
65
- return false;
66
- }
67
- }
68
-
69
- async uploadFile(url: string, file: File, onProgress: (progress: number) => void, payload: any = {}): Promise<UploadResponse>
70
- {
71
- return upload(
72
-
73
- url,
74
- {
75
- file,
76
- ...payload
77
- },
78
- {
79
- onProgress,
80
- headers: this.token ? { Authorization: `Bearer ${this.token}` } : null,
81
- }
82
- );
83
- }
84
-
85
- public pureGet = calls.pureGet;
86
- public get = calls.get;
87
- public post = calls.post;
88
- public put = calls.put;
89
- public delete = calls.delete;
90
-
91
- public back = {
92
- get: async <T>(routeName: string, options?: IAPIOptions, token?: string): Promise<T> => calls.get.bind(this)(backend.getBackendUrl.bind(this)(routeName, options?.routeParams), options) as Promise<T>,
93
- post: async <T, P extends object = object>(routeName: string, payload?: P, options?: IAPIOptions): Promise<T> => calls.post.bind(this)(backend.getBackendUrl.bind(this)(routeName, options?.routeParams), payload, options) as Promise<T>,
94
- put: async <T, P extends object = object>(routeName: string, payload: P, options?: IAPIOptions): Promise<T> => calls.put.bind(this)(backend.getBackendUrl.bind(this)(routeName, options?.routeParams), payload, options) as Promise<T>,
95
- delete: async <T>(routeName: string, options?: IAPIOptions): Promise<T> => calls.delete.bind(this)(backend.getBackendUrl.bind(this)(routeName, options?.routeParams), options) as Promise<T>,
96
- uploadFile: async (routeName: string, file: File, onProgress: (progress: number) => void, options: IAPIOptions = {}, payload: any = {}): Promise<UploadResponse> => this.uploadFile(backend.getBackendUrl.bind(this)(routeName, options?.routeParams), file, onProgress, payload),
97
- };
98
-
99
- async getResource(resourceName: string): Promise<IKDBTypesResponse>
100
- {
101
- return calls.get.bind(this)(`${this.config.get('backendUrl')}${this.config.get('apiPrefix') || ''}/api/rws/resource/${resourceName}`) as Promise<IKDBTypesResponse>
102
- }
103
- }
104
-
105
- export default ApiService.getSingleton();
1
+ import { IKDBTypesResponse } from '../types/IBackendCore';
2
+ import TheService from './_service';
3
+
4
+ //@4DI
5
+ import ConfigService, { ConfigServiceInstance } from './ConfigService';
6
+
7
+ import { upload, UploadResponse } from 'upload';
8
+
9
+ import { backend } from './_api/backend';
10
+ import { calls } from './_api/calls';
11
+
12
+ interface RequestOptions {
13
+ method?: string;
14
+ headers: HeadersInit;
15
+ body?: string;
16
+ }
17
+
18
+ interface IAPIOptions {
19
+ headers?: Headers,
20
+ routeParams?: {
21
+ [key: string]: string
22
+ },
23
+ }
24
+
25
+ interface IHTTProute<P = {[key: string]: any}> {
26
+ name: string;
27
+ path: string;
28
+ method: string;
29
+ noParams?: boolean;
30
+ options?: any;
31
+ plugins?: P
32
+ }
33
+
34
+ interface IPrefixedHTTProutes<P = {[key: string]: any}> {
35
+ prefix: string;
36
+ controllerName: string;
37
+ exportAutoRoutes?: boolean,
38
+ routes: IHTTProute<P>[];
39
+ }
40
+
41
+
42
+ type IBackendRoute = IHTTProute | IPrefixedHTTProutes;
43
+
44
+
45
+
46
+ class ApiService extends TheService {
47
+ static _DEFAULT: boolean = true;
48
+ public token?: string;
49
+
50
+ constructor(@ConfigService public config: ConfigServiceInstance) {
51
+ super();
52
+ }
53
+
54
+ public setToken(token: string)
55
+ {
56
+ this.token = token;
57
+ }
58
+
59
+
60
+
61
+ public async isGetTargetReachable(url: string, options: IAPIOptions = {}): Promise<boolean> {
62
+ try {
63
+ return !!(await calls.pureGet.bind(this)(url, options));
64
+ } catch (error) {
65
+ return false;
66
+ }
67
+ }
68
+
69
+ async uploadFile(url: string, file: File, onProgress: (progress: number) => void, payload: any = {}): Promise<UploadResponse>
70
+ {
71
+ return upload(
72
+
73
+ url,
74
+ {
75
+ file,
76
+ ...payload
77
+ },
78
+ {
79
+ onProgress,
80
+ headers: this.token ? { Authorization: `Bearer ${this.token}` } : null,
81
+ }
82
+ );
83
+ }
84
+
85
+ public pureGet = calls.pureGet;
86
+ public get = calls.get;
87
+ public post = calls.post;
88
+ public put = calls.put;
89
+ public delete = calls.delete;
90
+
91
+ public back = {
92
+ get: async <T>(routeName: string, options?: IAPIOptions, token?: string): Promise<T> => calls.get.bind(this)(backend.getBackendUrl.bind(this)(routeName, options?.routeParams), options) as Promise<T>,
93
+ post: async <T, P extends object = object>(routeName: string, payload?: P, options?: IAPIOptions): Promise<T> => calls.post.bind(this)(backend.getBackendUrl.bind(this)(routeName, options?.routeParams), payload, options) as Promise<T>,
94
+ put: async <T, P extends object = object>(routeName: string, payload: P, options?: IAPIOptions): Promise<T> => calls.put.bind(this)(backend.getBackendUrl.bind(this)(routeName, options?.routeParams), payload, options) as Promise<T>,
95
+ delete: async <T>(routeName: string, options?: IAPIOptions): Promise<T> => calls.delete.bind(this)(backend.getBackendUrl.bind(this)(routeName, options?.routeParams), options) as Promise<T>,
96
+ uploadFile: async (routeName: string, file: File, onProgress: (progress: number) => void, options: IAPIOptions = {}, payload: any = {}): Promise<UploadResponse> => this.uploadFile(backend.getBackendUrl.bind(this)(routeName, options?.routeParams), file, onProgress, payload),
97
+ };
98
+
99
+ async getResource(resourceName: string): Promise<IKDBTypesResponse>
100
+ {
101
+ return calls.get.bind(this)(`${this.config.get('backendUrl')}${this.config.get('apiPrefix') || ''}/api/rws/resource/${resourceName}`) as Promise<IKDBTypesResponse>
102
+ }
103
+ }
104
+
105
+ export default ApiService.getSingleton();
106
106
  export { IBackendRoute, RequestOptions, ApiService as ApiServiceInstance, IHTTProute, IPrefixedHTTProutes, IAPIOptions };