5htp-core 0.5.9 → 0.6.0-2
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/client/app/component.tsx +2 -0
- package/client/assets/css/colors.less +265 -0
- package/client/assets/css/components/button.less +27 -9
- package/client/assets/css/components/card.less +24 -0
- package/client/assets/css/components/input.less +0 -4
- package/client/assets/css/components/mantine.less +11 -0
- package/client/assets/css/components/other.less +1 -0
- package/client/assets/css/components/progressbar.less +45 -0
- package/client/assets/css/components/table.less +9 -13
- package/client/assets/css/components.less +1 -0
- package/client/assets/css/core.less +6 -4
- package/client/assets/css/text/text.less +4 -9
- package/client/assets/css/theme.less +10 -0
- package/client/assets/css/utils/layouts.less +11 -4
- package/client/assets/css/utils/sizing.less +2 -0
- package/client/components/Card/index.tsx +1 -2
- package/client/components/Checkbox.tsx +2 -1
- package/client/components/DropDown.tsx +11 -5
- package/client/components/Input.tsx +1 -0
- package/client/components/Rte/ToolbarPlugin/BlockFormat.tsx +1 -1
- package/client/components/Rte/ToolbarPlugin/ElementFormat.tsx +5 -3
- package/client/components/Rte/ToolbarPlugin/index.tsx +4 -4
- package/client/components/Select.tsx +95 -69
- package/client/components/Table/index.tsx +35 -24
- package/client/components/containers/Popover/index.tsx +1 -1
- package/client/components/containers/Popover/popover.less +1 -1
- package/client/components/index.ts +4 -3
- package/client/components/utils.tsx +5 -5
- package/client/index.ts +1 -0
- package/client/services/router/components/router.tsx +0 -1
- package/client/services/router/index.tsx +1 -2
- package/client/services/router/request/api.ts +4 -4
- package/common/errors/index.tsx +6 -0
- package/common/router/index.ts +8 -2
- package/package.json +1 -2
- package/server/app/commands.ts +2 -21
- package/server/app/container/console/index.ts +1 -6
- package/server/app/container/index.ts +0 -2
- package/server/app/index.ts +88 -22
- package/server/app/service/index.ts +30 -35
- package/server/services/auth/index.ts +15 -17
- package/server/services/auth/old.ts +1 -1
- package/server/services/auth/router/index.ts +24 -12
- package/server/services/cache/index.ts +5 -16
- package/server/services/cron/index.ts +2 -9
- package/server/services/database/index.ts +5 -10
- package/server/services/database/stats.ts +0 -2
- package/server/services/disks/driver.ts +1 -1
- package/server/services/disks/drivers/s3/index.ts +4 -8
- package/server/services/disks/index.ts +10 -9
- package/server/services/email/index.ts +5 -2
- package/server/services/email/transporter.ts +1 -21
- package/server/services/fetch/index.ts +9 -11
- package/server/services/fetch/service.json +2 -1
- package/server/services/prisma/index.ts +1 -14
- package/server/services/router/index.ts +28 -53
- package/server/services/router/request/api.ts +2 -7
- package/server/services/router/service.ts +5 -17
- package/server/services/security/encrypt/aes/index.ts +1 -1
- package/server/services/socket/index.ts +11 -19
- package/types/global/utils.d.ts +44 -1
- package/types/icons.d.ts +1 -1
- package/server/app/container/patch.ts +0 -15
|
@@ -10,7 +10,7 @@ const safeStringify = require('fast-safe-stringify'); // remplace les référenc
|
|
|
10
10
|
|
|
11
11
|
// Core: general
|
|
12
12
|
import { Application, Services } from '@server/app';
|
|
13
|
-
import Service, { AnyService, TRegisteredServicesIndex } from '@server/app/service';
|
|
13
|
+
import Service, { AnyService, TRegisteredServicesIndex, TServiceArgs } from '@server/app/service';
|
|
14
14
|
import { NotFound } from '@common/errors';
|
|
15
15
|
|
|
16
16
|
// Services
|
|
@@ -91,20 +91,15 @@ const emptyOkPacket = {
|
|
|
91
91
|
|
|
92
92
|
// TODO: build callable instance sithut instanciating the service
|
|
93
93
|
|
|
94
|
-
export default class SQL extends Service<Config, Hooks, Application
|
|
94
|
+
export default class SQL extends Service<Config, Hooks, Application> {
|
|
95
95
|
|
|
96
96
|
public database: Database;
|
|
97
97
|
|
|
98
|
-
public constructor(
|
|
99
|
-
parent: AnyService,
|
|
100
|
-
config: Config,
|
|
101
|
-
drivers: TRegisteredServicesIndex,
|
|
102
|
-
app: Application,
|
|
103
|
-
) {
|
|
98
|
+
public constructor( ...args: TServiceArgs<SQL>) {
|
|
104
99
|
|
|
105
|
-
super(
|
|
100
|
+
super(...args);
|
|
106
101
|
|
|
107
|
-
this.database = new Database(this, config);
|
|
102
|
+
this.database = new Database(this, this.config);
|
|
108
103
|
}
|
|
109
104
|
|
|
110
105
|
public getServiceInstance() {
|
|
@@ -56,7 +56,7 @@ export type TReadFileOptions = {
|
|
|
56
56
|
export default abstract class FsDriver<
|
|
57
57
|
Config extends TDrivercnfig = TDrivercnfig,
|
|
58
58
|
TBucketName = keyof Config["buckets"]
|
|
59
|
-
> extends Service<Config, {}, Application
|
|
59
|
+
> extends Service<Config, {}, Application> {
|
|
60
60
|
|
|
61
61
|
public abstract mount(): Promise<void>;
|
|
62
62
|
|
|
@@ -14,7 +14,7 @@ import dayjs from 'dayjs';
|
|
|
14
14
|
|
|
15
15
|
// Core
|
|
16
16
|
import type { Application } from '@server/app';
|
|
17
|
-
import type {
|
|
17
|
+
import type { TServiceArgs } from '@server/app/service';
|
|
18
18
|
|
|
19
19
|
// Specific
|
|
20
20
|
import DiskDriver, {
|
|
@@ -50,14 +50,9 @@ export default class S3Driver<
|
|
|
50
50
|
|
|
51
51
|
public s3: AWS.S3;
|
|
52
52
|
|
|
53
|
-
public constructor(
|
|
54
|
-
public parent: AnyService,
|
|
55
|
-
public config: TConfig,
|
|
56
|
-
public services: {},
|
|
57
|
-
public app: Application
|
|
58
|
-
) {
|
|
53
|
+
public constructor(...args: TServiceArgs) {
|
|
59
54
|
|
|
60
|
-
super(
|
|
55
|
+
super(...args);
|
|
61
56
|
|
|
62
57
|
AWS.config.update({
|
|
63
58
|
accessKeyId: this.config.accessKeyId,
|
|
@@ -87,6 +82,7 @@ export default class S3Driver<
|
|
|
87
82
|
bucketName: TBucketName,
|
|
88
83
|
filename: string
|
|
89
84
|
) {
|
|
85
|
+
|
|
90
86
|
const bucket = this.config.buckets[bucketName];
|
|
91
87
|
if (bucket === undefined)
|
|
92
88
|
throw new Error(`Bucket "${bucketName}" not found in configuration`);
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
// Core
|
|
6
6
|
import type { Application } from '@server/app';
|
|
7
|
-
import Service, { AnyService } from '@server/app/service';
|
|
7
|
+
import Service, { AnyService, TRegisteredServicesIndex, TServiceArgs } from '@server/app/service';
|
|
8
8
|
|
|
9
9
|
// Specific
|
|
10
10
|
import type Driver from './driver';
|
|
@@ -17,6 +17,9 @@ export type { default as Driver } from './driver';
|
|
|
17
17
|
type Config = {
|
|
18
18
|
debug: boolean,
|
|
19
19
|
default: string,//keyof MountpointList,
|
|
20
|
+
drivers: {
|
|
21
|
+
[driverId: string]: Driver
|
|
22
|
+
}
|
|
20
23
|
}
|
|
21
24
|
|
|
22
25
|
export type Hooks = {
|
|
@@ -34,25 +37,23 @@ export default class DisksManager<
|
|
|
34
37
|
MountpointList extends Services = {},
|
|
35
38
|
TConfig extends Config = Config,
|
|
36
39
|
TApplication extends Application = Application
|
|
37
|
-
> extends Service<TConfig, Hooks, TApplication
|
|
40
|
+
> extends Service<TConfig, Hooks, TApplication> {
|
|
38
41
|
|
|
39
42
|
public default!: Driver;
|
|
40
43
|
|
|
41
|
-
public mounted: MountpointList = this.services;
|
|
42
|
-
|
|
43
44
|
/*----------------------------------
|
|
44
45
|
- LIFECYCLE
|
|
45
46
|
----------------------------------*/
|
|
46
47
|
|
|
47
|
-
public
|
|
48
|
+
public constructor( ...args: TServiceArgs<DisksManager>) {
|
|
48
49
|
|
|
49
|
-
|
|
50
|
+
super(...args);
|
|
51
|
+
|
|
52
|
+
const drivers = this.config.drivers;
|
|
50
53
|
|
|
51
54
|
if (Object.keys( drivers ).length === 0)
|
|
52
55
|
throw new Error("At least one disk driver should be mounted.");
|
|
53
56
|
|
|
54
|
-
console.log('start disks service', Object.keys( drivers ), Object.keys( this.mounted ), Object.keys( this.services ));
|
|
55
|
-
|
|
56
57
|
const defaultDisk = drivers[ this.config.default ];
|
|
57
58
|
if (defaultDisk === undefined)
|
|
58
59
|
console.log(`Default disk "${this.config.default as string}" not mounted.`);
|
|
@@ -73,7 +74,7 @@ export default class DisksManager<
|
|
|
73
74
|
|
|
74
75
|
const disk = diskName == 'default' || diskName === undefined
|
|
75
76
|
? this.default
|
|
76
|
-
: this.
|
|
77
|
+
: this.config.drivers[diskName];
|
|
77
78
|
|
|
78
79
|
if (disk === undefined)
|
|
79
80
|
throw new Error(`Disk "${diskName as string}" not found.`);
|
|
@@ -31,6 +31,9 @@ export type Config = {
|
|
|
31
31
|
bugReport: {
|
|
32
32
|
from: TPerson,
|
|
33
33
|
to: TPerson
|
|
34
|
+
},
|
|
35
|
+
transporters: {
|
|
36
|
+
[transporterId: string]: Transporter
|
|
34
37
|
}
|
|
35
38
|
}
|
|
36
39
|
|
|
@@ -106,9 +109,9 @@ type TOptions = {
|
|
|
106
109
|
/*----------------------------------
|
|
107
110
|
- FONCTIONS
|
|
108
111
|
----------------------------------*/
|
|
109
|
-
export default class Email extends Service<Config, Hooks, Application
|
|
112
|
+
export default class Email extends Service<Config, Hooks, Application> {
|
|
110
113
|
|
|
111
|
-
private transporters = this.
|
|
114
|
+
private transporters = this.config.transporters;
|
|
112
115
|
|
|
113
116
|
/*----------------------------------
|
|
114
117
|
- ACTIONS
|
|
@@ -25,27 +25,7 @@ export type TBasicConfig = {
|
|
|
25
25
|
- CLASS
|
|
26
26
|
----------------------------------*/
|
|
27
27
|
export abstract class Transporter<TConfig extends TBasicConfig = TBasicConfig>
|
|
28
|
-
extends Service<TConfig, {}, Application
|
|
29
|
-
|
|
30
|
-
/*----------------------------------
|
|
31
|
-
- LIFECYCLE
|
|
32
|
-
----------------------------------*/
|
|
33
|
-
|
|
34
|
-
protected async start() {
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
protected async ready() {
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
protected async shutdown() {
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/*----------------------------------
|
|
47
|
-
- ACTIONS
|
|
48
|
-
----------------------------------*/
|
|
28
|
+
extends Service<TConfig, {}, Application> {
|
|
49
29
|
|
|
50
30
|
public abstract send( emails: TCompleteEmail[] ): Promise<void>;
|
|
51
31
|
}
|
|
@@ -26,18 +26,16 @@ import type FsDriver from '../disks/driver';
|
|
|
26
26
|
|
|
27
27
|
export type Config = {
|
|
28
28
|
debug?: boolean,
|
|
29
|
-
disk?: string
|
|
29
|
+
disk?: string,
|
|
30
|
+
|
|
31
|
+
disks: DisksManager,
|
|
32
|
+
router?: RouterService
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
export type Hooks = {
|
|
33
36
|
|
|
34
37
|
}
|
|
35
38
|
|
|
36
|
-
export type Services = {
|
|
37
|
-
disks: DisksManager,
|
|
38
|
-
router?: RouterService
|
|
39
|
-
}
|
|
40
|
-
|
|
41
39
|
/*----------------------------------
|
|
42
40
|
- TYPES
|
|
43
41
|
----------------------------------*/
|
|
@@ -60,14 +58,14 @@ const LogPrefix = `[services][fetch]`
|
|
|
60
58
|
- SERVICE
|
|
61
59
|
- Tools that helps to consume external resources (including apis, ..)
|
|
62
60
|
-----------------------------------*/
|
|
63
|
-
export default class FetchService extends Service<Config, Hooks, Application
|
|
61
|
+
export default class FetchService extends Service<Config, Hooks, Application> {
|
|
64
62
|
|
|
65
63
|
private disk?: FsDriver;
|
|
66
64
|
|
|
67
65
|
public async ready() {
|
|
68
66
|
|
|
69
|
-
if (this.
|
|
70
|
-
this.disk = this.
|
|
67
|
+
if (this.config.disks)
|
|
68
|
+
this.disk = this.config.disks.get( this.config.disk );
|
|
71
69
|
|
|
72
70
|
}
|
|
73
71
|
|
|
@@ -97,10 +95,10 @@ export default class FetchService extends Service<Config, Hooks, Application, Se
|
|
|
97
95
|
) {
|
|
98
96
|
|
|
99
97
|
// Parse url if router service is provided
|
|
100
|
-
if (this.
|
|
98
|
+
if (this.config.router === undefined)
|
|
101
99
|
throw new Error(`Please bind the Router service to the Fetch service in order to contact APIs.`);
|
|
102
100
|
|
|
103
|
-
url = this.
|
|
101
|
+
url = this.config.router.url(url);
|
|
104
102
|
|
|
105
103
|
// Send request
|
|
106
104
|
const res = await got(url, {
|
|
@@ -34,22 +34,9 @@ export type Services = {
|
|
|
34
34
|
- CLASSE
|
|
35
35
|
----------------------------------*/
|
|
36
36
|
|
|
37
|
-
export default class ModelsManager extends Service<Config, Hooks, Application
|
|
37
|
+
export default class ModelsManager extends Service<Config, Hooks, Application> {
|
|
38
38
|
|
|
39
39
|
public client = new PrismaClient();
|
|
40
|
-
|
|
41
|
-
/*----------------------------------
|
|
42
|
-
- LIFECICLE
|
|
43
|
-
----------------------------------*/
|
|
44
|
-
|
|
45
|
-
protected async start() {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
public async ready() {
|
|
51
|
-
|
|
52
|
-
}
|
|
53
40
|
|
|
54
41
|
public async shutdown() {
|
|
55
42
|
await this.client.$disconnect()
|
|
@@ -14,11 +14,13 @@
|
|
|
14
14
|
import type express from 'express';
|
|
15
15
|
import type { Request, Response, NextFunction } from 'express';
|
|
16
16
|
import { v4 as uuid } from 'uuid';
|
|
17
|
+
import zod from 'zod';
|
|
18
|
+
export { default as schema } from 'zod';
|
|
17
19
|
import type { GlobImportedWithMetas } from 'babel-plugin-glob-import';
|
|
18
20
|
|
|
19
21
|
// Core
|
|
20
22
|
import type { Application } from '@server/app';
|
|
21
|
-
import Service, { AnyService } from '@server/app/service';
|
|
23
|
+
import Service, { AnyService, TServiceArgs } from '@server/app/service';
|
|
22
24
|
import type { TRegisteredServicesIndex } from '@server/app/service/container';
|
|
23
25
|
import context from '@server/context';
|
|
24
26
|
import type DisksManager from '@server/services/disks';
|
|
@@ -96,10 +98,10 @@ export type Config<
|
|
|
96
98
|
request: ServerRequest<ServerRouter>,
|
|
97
99
|
app: Application
|
|
98
100
|
) => TAdditionnalSsrData,
|
|
99
|
-
}
|
|
100
101
|
|
|
101
|
-
|
|
102
|
-
|
|
102
|
+
plugins: {
|
|
103
|
+
[routerServiceId: string]: RouterService
|
|
104
|
+
}
|
|
103
105
|
}
|
|
104
106
|
|
|
105
107
|
// Set it as a function, so when we instanciate the services, we can callthis.router to pass the router instance in roiuter services
|
|
@@ -113,23 +115,21 @@ export type Hooks = {
|
|
|
113
115
|
|
|
114
116
|
export type TControllerDefinition = {
|
|
115
117
|
path?: string,
|
|
116
|
-
|
|
118
|
+
schema?: zod.ZodSchema,
|
|
117
119
|
controller: TServerController<ServerRouter>,
|
|
118
120
|
}
|
|
119
121
|
|
|
120
122
|
/*----------------------------------
|
|
121
123
|
- CLASSE
|
|
122
124
|
----------------------------------*/
|
|
123
|
-
export default class ServerRouter
|
|
124
|
-
|
|
125
|
-
> extends Service<Config, Hooks, Application, TSubservices> implements BaseRouter {
|
|
125
|
+
export default class ServerRouter
|
|
126
|
+
extends Service<Config, Hooks, Application> implements BaseRouter {
|
|
126
127
|
|
|
127
128
|
public disks = this.use<DisksManager>('Core/Disks', { optional: true });
|
|
128
129
|
|
|
129
130
|
// Services
|
|
130
131
|
public http: HTTP;
|
|
131
132
|
public render: DocumentRenderer<this>;
|
|
132
|
-
protected routerServices: TSubservices = {} as TSubservices
|
|
133
133
|
|
|
134
134
|
// Indexed
|
|
135
135
|
public routes: TRoute[] = []; // API + pages front front
|
|
@@ -144,16 +144,11 @@ export default class ServerRouter<
|
|
|
144
144
|
- SERVICE
|
|
145
145
|
----------------------------------*/
|
|
146
146
|
|
|
147
|
-
public constructor(
|
|
148
|
-
parent: AnyService,
|
|
149
|
-
config: Config,
|
|
150
|
-
services: TSubservices,
|
|
151
|
-
app: Application,
|
|
152
|
-
) {
|
|
147
|
+
public constructor( ...args: TServiceArgs<ServerRouter>) {
|
|
153
148
|
|
|
154
|
-
super(
|
|
149
|
+
super(...args);
|
|
155
150
|
|
|
156
|
-
this.http = new HTTP(config.http, this);
|
|
151
|
+
this.http = new HTTP(this.config.http, this);
|
|
157
152
|
this.render = new DocumentRenderer(this);
|
|
158
153
|
}
|
|
159
154
|
|
|
@@ -164,18 +159,15 @@ export default class ServerRouter<
|
|
|
164
159
|
public async ready() {
|
|
165
160
|
|
|
166
161
|
// Detect router services
|
|
167
|
-
for (const serviceName in this.
|
|
168
|
-
|
|
169
|
-
const routerService = this.services[serviceName];
|
|
170
|
-
if (routerService instanceof RouterService)
|
|
171
|
-
this.routerServices[ serviceName ] = routerService;
|
|
162
|
+
for (const serviceName in this.config.plugins) {
|
|
163
|
+
this.app.register( this.config.plugins[serviceName] )
|
|
172
164
|
}
|
|
173
165
|
|
|
174
166
|
// Use require to avoid circular references
|
|
175
167
|
this.registerRoutes([
|
|
176
168
|
...require("metas:@/server/routes/**/*.ts"),
|
|
177
|
-
...require("metas:@/client/pages
|
|
178
|
-
...require("metas
|
|
169
|
+
...require("metas:@/client/pages/**/([a-z0-9]*).tsx"),
|
|
170
|
+
...require("metas:@/client/pages/**/([a-z0-9]*).tsx")
|
|
179
171
|
]);
|
|
180
172
|
|
|
181
173
|
// Start HTTP server
|
|
@@ -192,7 +184,6 @@ export default class ServerRouter<
|
|
|
192
184
|
----------------------------------*/
|
|
193
185
|
|
|
194
186
|
private registerRoutes(defModules: GlobImportedWithMetas<TRouteModule>) {
|
|
195
|
-
|
|
196
187
|
for (const routeModule of defModules) {
|
|
197
188
|
|
|
198
189
|
const register = routeModule.exports.__register;
|
|
@@ -327,10 +318,6 @@ export default class ServerRouter<
|
|
|
327
318
|
|
|
328
319
|
private async afterRegister() {
|
|
329
320
|
|
|
330
|
-
// Generate typescript typings
|
|
331
|
-
if (this.app.env.profile === 'dev')
|
|
332
|
-
this.genTypings();
|
|
333
|
-
|
|
334
321
|
// Ordonne par ordre de priorité
|
|
335
322
|
this.config.debug && console.info("Loading routes ...");
|
|
336
323
|
this.routes.sort((r1, r2) => {
|
|
@@ -394,21 +381,6 @@ export default class ServerRouter<
|
|
|
394
381
|
this.config.debug && console.info(this.routes.length + " routes where registered.");
|
|
395
382
|
}
|
|
396
383
|
|
|
397
|
-
private genTypings() {
|
|
398
|
-
/*fs.outputFileSync( path.join(this.app.path.typings, 'routes.d.ts'), `
|
|
399
|
-
declare type Routes = {
|
|
400
|
-
${this.routes.map( route => `
|
|
401
|
-
'${route.path}': {
|
|
402
|
-
params: {
|
|
403
|
-
${route.keys.map( k => "'" + k + "': string").join(',\n')}
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
`).join(',')}
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
`);*/
|
|
410
|
-
}
|
|
411
|
-
|
|
412
384
|
/*----------------------------------
|
|
413
385
|
- RESOLUTION
|
|
414
386
|
----------------------------------*/
|
|
@@ -438,15 +410,15 @@ declare type Routes = {
|
|
|
438
410
|
this
|
|
439
411
|
);
|
|
440
412
|
|
|
441
|
-
// Hook
|
|
442
|
-
await this.runHook('request', request);
|
|
443
|
-
|
|
444
413
|
// Create request context so we can access request context across all the request-triggered libs
|
|
445
414
|
context.run({ channelType: 'request', channelId: requestId }, async () => {
|
|
446
415
|
|
|
447
416
|
let response: ServerResponse<this>;
|
|
448
417
|
try {
|
|
449
418
|
|
|
419
|
+
// Hook
|
|
420
|
+
await this.runHook('request', request);
|
|
421
|
+
|
|
450
422
|
// Bulk API Requests
|
|
451
423
|
if (request.path === '/api' && typeof request.data.fetchers === "object") {
|
|
452
424
|
|
|
@@ -476,9 +448,15 @@ declare type Routes = {
|
|
|
476
448
|
public createContextServices( request: ServerRequest<this> ) {
|
|
477
449
|
|
|
478
450
|
const contextServices: Partial<TRouterContextServices<this>> = {}
|
|
479
|
-
for (const serviceName in this.
|
|
451
|
+
for (const serviceName in this.config.plugins) {
|
|
452
|
+
|
|
453
|
+
const routerService = this.config.plugins[serviceName];
|
|
454
|
+
if (!routerService)
|
|
455
|
+
throw new Error(`Could not access router service ${serviceName}. Maybe the referenced service is not started yet? Try to reduce its priority.`);
|
|
456
|
+
|
|
457
|
+
if (!routerService.requestService)
|
|
458
|
+
throw new Error(`Router service ${serviceName} is not implementing the requestService method from the RouterService interface.`);
|
|
480
459
|
|
|
481
|
-
const routerService = this.routerServices[serviceName];
|
|
482
460
|
const requestService = routerService.requestService( request );
|
|
483
461
|
if (requestService !== null)
|
|
484
462
|
contextServices[ serviceName ] = requestService;
|
|
@@ -509,9 +487,6 @@ declare type Routes = {
|
|
|
509
487
|
let route = this.controllers[request.path];
|
|
510
488
|
if (route !== undefined) {
|
|
511
489
|
|
|
512
|
-
// Run on resolution hooks. Ex: authentication check
|
|
513
|
-
await this.runHook('resolved', route);
|
|
514
|
-
|
|
515
490
|
// Create response
|
|
516
491
|
await this.resolvedRoute(route, response, logId, timeStart);
|
|
517
492
|
if (response.wasProvided)
|
|
@@ -564,7 +539,7 @@ declare type Routes = {
|
|
|
564
539
|
) {
|
|
565
540
|
|
|
566
541
|
// Run on resolution hooks. Ex: authentication check
|
|
567
|
-
await this.runHook('resolved', route);
|
|
542
|
+
await this.runHook('resolved', route, response.request, response);
|
|
568
543
|
|
|
569
544
|
// Create response
|
|
570
545
|
await response.runController(route);
|
|
@@ -21,10 +21,6 @@ import ApiClientService, {
|
|
|
21
21
|
----------------------------------*/
|
|
22
22
|
export default class ApiClientRequest extends RequestService implements ApiClientService {
|
|
23
23
|
|
|
24
|
-
protected async start() {
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
24
|
/*----------------------------------
|
|
29
25
|
- HIGH LEVEL
|
|
30
26
|
----------------------------------*/
|
|
@@ -66,9 +62,8 @@ export default class ApiClientRequest extends RequestService implements ApiClien
|
|
|
66
62
|
public createFetcher<TData extends unknown = unknown>(...[method, path, data, options]: TFetcherArgs): TFetcher<TData> {
|
|
67
63
|
return {
|
|
68
64
|
method, path, data, options,
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
};
|
|
65
|
+
// We don't put the then and catch methods so the api consumer on server side will know it's a fetcher and not a promize to wait
|
|
66
|
+
} as TFetcher<TData>;
|
|
72
67
|
}
|
|
73
68
|
|
|
74
69
|
public async fetchSync(fetchers: TFetcherList, alreadyLoadedData: {}): Promise<TObjetDonnees> {
|
|
@@ -4,36 +4,24 @@
|
|
|
4
4
|
|
|
5
5
|
// Core
|
|
6
6
|
import type { Application } from '@server/app';
|
|
7
|
-
import Service, { TRegisteredServicesIndex } from '@server/app/service';
|
|
7
|
+
import Service, { TRegisteredServicesIndex, TServiceArgs } from '@server/app/service';
|
|
8
8
|
|
|
9
9
|
// Specific
|
|
10
10
|
import type { default as Router } from '.';
|
|
11
11
|
import type ServerRequest from './request';
|
|
12
12
|
import type RequestService from './request/service';
|
|
13
13
|
|
|
14
|
-
export type
|
|
15
|
-
|
|
16
|
-
}
|
|
14
|
+
export type TRouterServiceArgs = TServiceArgs<RouterService>;
|
|
17
15
|
|
|
18
16
|
/*----------------------------------
|
|
19
17
|
- SERVICE
|
|
20
18
|
----------------------------------*/
|
|
21
19
|
export default abstract class RouterService<
|
|
22
20
|
TConfig extends {} = {}
|
|
23
|
-
> extends Service<TConfig, {}, Application
|
|
21
|
+
> extends Service<TConfig, {}, Application> {
|
|
24
22
|
|
|
25
|
-
public constructor(
|
|
26
|
-
|
|
27
|
-
// Warning: for now, it's possible that router is actually the app
|
|
28
|
-
// It's fixed with a not very clean way in Service.bindService
|
|
29
|
-
router: Router,
|
|
30
|
-
config: TConfig,
|
|
31
|
-
services: TRegisteredServicesIndex,
|
|
32
|
-
app: Application
|
|
33
|
-
) {
|
|
34
|
-
|
|
35
|
-
super(router, config, services, app);
|
|
36
|
-
|
|
23
|
+
public constructor( ...args: TRouterServiceArgs) {
|
|
24
|
+
super(...args);
|
|
37
25
|
}
|
|
38
26
|
|
|
39
27
|
public abstract requestService( request: ServerRequest<Router> ): RequestService | null;
|
|
@@ -47,7 +47,7 @@ type TDecryptOptions = {
|
|
|
47
47
|
/*----------------------------------
|
|
48
48
|
- SERVICE
|
|
49
49
|
----------------------------------*/
|
|
50
|
-
export default class AES<TConfig extends Config = Config> extends Service<TConfig, Hooks, Application
|
|
50
|
+
export default class AES<TConfig extends Config = Config> extends Service<TConfig, Hooks, Application> {
|
|
51
51
|
|
|
52
52
|
public encrypt( keyName: keyof TConfig["keys"], data: any, options: TEncryptOptions = {
|
|
53
53
|
encoding: 'base64url'
|
|
@@ -26,30 +26,27 @@ export type Config<TUser extends {}> = {
|
|
|
26
26
|
//server: ServerOptions["server"],
|
|
27
27
|
//users: UsersManagementService<TUser>,
|
|
28
28
|
port: number,
|
|
29
|
+
|
|
30
|
+
users: UsersManagementService<TUser, Application>,
|
|
31
|
+
router: Router
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
export type Hooks = {
|
|
32
35
|
|
|
33
36
|
}
|
|
34
37
|
|
|
35
|
-
export type Services<TUser extends {}> = {
|
|
36
|
-
users: UsersManagementService<TUser, Application>,
|
|
37
|
-
router: Router
|
|
38
|
-
}
|
|
39
|
-
|
|
40
38
|
/*----------------------------------
|
|
41
39
|
- MANAGER
|
|
42
40
|
----------------------------------*/
|
|
43
41
|
export default class WebSocketCommander<
|
|
44
42
|
TUser extends {},
|
|
45
|
-
TConfig extends Config<TUser>= Config<TUser
|
|
46
|
-
|
|
47
|
-
> extends Service<TConfig, Hooks, Application, TServices> {
|
|
43
|
+
TConfig extends Config<TUser>= Config<TUser>
|
|
44
|
+
> extends Service<TConfig, Hooks, Application> {
|
|
48
45
|
|
|
49
46
|
// Services
|
|
50
47
|
public ws!: WebSocketServer;
|
|
51
|
-
public users!:
|
|
52
|
-
public router!:
|
|
48
|
+
public users!: TConfig["users"];
|
|
49
|
+
public router!: TConfig["router"];
|
|
53
50
|
|
|
54
51
|
// Context
|
|
55
52
|
public scopes: {[path: string]: SocketScope<TUser>} = {}
|
|
@@ -57,13 +54,12 @@ export default class WebSocketCommander<
|
|
|
57
54
|
public constructor(
|
|
58
55
|
parent: AnyService,
|
|
59
56
|
config: TConfig,
|
|
60
|
-
services: Services,
|
|
61
57
|
app: TApplication,
|
|
62
58
|
) {
|
|
63
|
-
super(parent, config,
|
|
59
|
+
super(parent, config, app);
|
|
64
60
|
|
|
65
|
-
this.users = this.
|
|
66
|
-
this.router = this.
|
|
61
|
+
this.users = this.config.users;
|
|
62
|
+
this.router = this.config.router;
|
|
67
63
|
|
|
68
64
|
}
|
|
69
65
|
|
|
@@ -72,7 +68,7 @@ export default class WebSocketCommander<
|
|
|
72
68
|
----------------------------------*/
|
|
73
69
|
|
|
74
70
|
public loading: Promise<void> | undefined = undefined;
|
|
75
|
-
protected async
|
|
71
|
+
protected async ready() {
|
|
76
72
|
|
|
77
73
|
this.users.on('disconnect', async (userId: string) => {
|
|
78
74
|
this.disconnect(userId, 'Logout');
|
|
@@ -120,10 +116,6 @@ export default class WebSocketCommander<
|
|
|
120
116
|
console.info(`Socket commander bound to http server.`);
|
|
121
117
|
}
|
|
122
118
|
|
|
123
|
-
public async ready() {
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
|
|
127
119
|
public async shutdown() {
|
|
128
120
|
this.closeAll();
|
|
129
121
|
}
|
package/types/global/utils.d.ts
CHANGED
|
@@ -55,6 +55,49 @@ declare type Routes = {
|
|
|
55
55
|
|
|
56
56
|
declare type PrimitiveValue = string | number | boolean;
|
|
57
57
|
|
|
58
|
+
/*----------------------------------
|
|
59
|
+
- COPY FROM CLI/APP/INDEX.TS
|
|
60
|
+
----------------------------------*/
|
|
61
|
+
|
|
62
|
+
type TEnvConfig = {
|
|
63
|
+
name: 'local' | 'server',
|
|
64
|
+
profile: 'dev' | 'prod',
|
|
65
|
+
version: string,
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
type TServiceSetup = {
|
|
69
|
+
id: string,
|
|
70
|
+
name: string,
|
|
71
|
+
config: {},
|
|
72
|
+
subservices: TServiceSubservices
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
type TServiceRef = {
|
|
76
|
+
refTo: string
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
type TServiceSubservices = {
|
|
80
|
+
[key: string]: TServiceSetup | TServiceRef
|
|
81
|
+
}
|
|
82
|
+
|
|
58
83
|
declare module '@cli/app' {
|
|
59
|
-
|
|
84
|
+
type App = {
|
|
85
|
+
|
|
86
|
+
env: TEnvConfig;
|
|
87
|
+
|
|
88
|
+
use: (referenceName: string) => TServiceRef;
|
|
89
|
+
|
|
90
|
+
setup: (...args: [
|
|
91
|
+
// { user: app.setup('Core/User') }
|
|
92
|
+
servicePath: string,
|
|
93
|
+
serviceConfig?: {}
|
|
94
|
+
] | [
|
|
95
|
+
// app.setup('User', 'Core/User')
|
|
96
|
+
serviceName: string,
|
|
97
|
+
servicePath: string,
|
|
98
|
+
serviceConfig?: {}
|
|
99
|
+
]) => TServiceSetup;
|
|
100
|
+
}
|
|
101
|
+
const app: App;
|
|
102
|
+
export = app;
|
|
60
103
|
}
|