@ask-ell/back-end 0.2.1 → 0.2.4
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/CHANGELOG.md +19 -0
- package/package.json +2 -1
- package/src/http/index.ts +1 -0
- package/src/http/types.ts +4 -0
- package/src/index.ts +2 -3
- package/src/keyv.store.adapter.factory.ts +2 -2
- package/src/nest/add-ons/index.ts +6 -0
- package/src/{application.base.ts → nest/application.base.ts} +1 -1
- package/src/{application.factory.ts → nest/application.factory.ts} +4 -4
- package/src/nest/filters/http.exception.filter.ts +23 -0
- package/src/nest/filters/index.ts +1 -0
- package/src/nest/index.ts +6 -0
- package/src/{error.interceptor.ts → nest/interceptors/error.interceptor.ts} +1 -1
- package/src/nest/interceptors/index.ts +2 -0
- package/src/nest/interceptors/response.format.interceptor.ts +29 -0
- package/src/nest/modules/health/health.module.ts +20 -0
- package/src/nest/modules/health/index.ts +1 -0
- package/src/nest/modules/health/middlewares/index.ts +1 -0
- package/src/nest/modules/health/middlewares/ping.middleware.ts +9 -0
- package/src/nest/modules/index.ts +2 -0
- package/src/nest/modules/requirement/index.ts +1 -0
- package/src/{requirement.module.ts → nest/modules/requirement/requirement.module.ts} +7 -10
- package/src/scripts/index.ts +2 -2
- package/src/scripts/{move-keyv-data.script.ts → move-keyv-data.program.ts} +4 -4
- package/src/scripts/{update-dependencies-versions.script.ts → update-dependencies-versions.program.ts} +9 -9
- package/src/add-ons/index.ts +0 -2
- package/src/utils/index.ts +0 -1
- /package/src/{add-ons → nest/add-ons}/add-on.interface.ts +0 -0
- /package/src/{add-ons → nest/add-ons}/add-on.wrapper.ts +0 -0
- /package/src/{add-ons → nest/add-ons}/implementations/security/security.add-on.ts +0 -0
- /package/src/{add-ons → nest/add-ons}/implementations/sentry/sentry.add-on.interface.ts +0 -0
- /package/src/{add-ons → nest/add-ons}/implementations/sentry/sentry.add-on.state.interface.ts +0 -0
- /package/src/{add-ons → nest/add-ons}/implementations/sentry/sentry.add-on.ts +0 -0
- /package/src/{add-ons → nest/add-ons}/implementations/swagger/swagger.add-on.interface.ts +0 -0
- /package/src/{add-ons → nest/add-ons}/implementations/swagger/swagger.add-on.state.interface.ts +0 -0
- /package/src/{add-ons → nest/add-ons}/implementations/swagger/swagger.add-on.ts +0 -0
- /package/src/{add-ons → nest/add-ons}/implementations/swagger/types.ts +0 -0
- /package/src/{add-ons → nest/add-ons}/types.ts +0 -0
- /package/src/{utils/tmp.ts → tmp.ts} +0 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# @ask-ell/back-end
|
|
2
|
+
|
|
3
|
+
## 0.2.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#20](https://github.com/ask-ell/stacks/pull/20) [`6eb9d13`](https://github.com/ask-ell/stacks/commit/6eb9d13e6473a022eb1377d3ca688811379e0376) Thanks [@timbitwin](https://github.com/timbitwin)! - script renamed to program
|
|
8
|
+
- Updated dependencies [[`6eb9d13`](https://github.com/ask-ell/stacks/commit/6eb9d13e6473a022eb1377d3ca688811379e0376)]:
|
|
9
|
+
- @ask-ell/node@0.0.6
|
|
10
|
+
|
|
11
|
+
## 0.2.3
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [`473e25b`](https://github.com/ask-ell/stacks/commit/473e25b399b8ac336dabb5f8c9fda3b1428cabb6) Thanks [@timbitwin](https://github.com/timbitwin)! - Exported `CreateKeyvStoreAdapterOptions`, `ErrorInterceptorProps`, `NestApplicationFactoryParams`, and the `update-dependencies-versions` script types so they resolve correctly in generated documentation. Also wired up the `http`, `add-ons`, `filters`, `interceptors`, and `modules` barrels that were left disconnected from the package entry point after the last refactor, so the public API is fully reachable and documented from `index.ts`.
|
|
16
|
+
- Updated dependencies [[`473e25b`](https://github.com/ask-ell/stacks/commit/473e25b399b8ac336dabb5f8c9fda3b1428cabb6), [`473e25b`](https://github.com/ask-ell/stacks/commit/473e25b399b8ac336dabb5f8c9fda3b1428cabb6), [`473e25b`](https://github.com/ask-ell/stacks/commit/473e25b399b8ac336dabb5f8c9fda3b1428cabb6)]:
|
|
17
|
+
- @ask-ell/core@1.3.6
|
|
18
|
+
- @ask-ell/nest@0.0.15
|
|
19
|
+
- @ask-ell/node@0.0.5
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ask-ell/back-end",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"@nestjs/swagger": "*",
|
|
18
18
|
"@nestjs/throttler": "*",
|
|
19
19
|
"@sentry/nestjs": "*",
|
|
20
|
+
"express": "*",
|
|
20
21
|
"helmet": "*",
|
|
21
22
|
"keyv": "*",
|
|
22
23
|
"pg": "*",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './types';
|
package/src/index.ts
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
* @module @ask-ell/back-end
|
|
3
3
|
*/
|
|
4
4
|
export * from './scripts';
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './
|
|
7
|
-
export * from './error.interceptor';
|
|
5
|
+
export * from './http';
|
|
6
|
+
export * from './nest';
|
|
8
7
|
export * from './keyv.store.adapter.factory';
|
|
@@ -6,9 +6,9 @@ import { ILogger, MaybeUndefined } from '@ask-ell/core';
|
|
|
6
6
|
import { NestLogger } from '@ask-ell/nest';
|
|
7
7
|
import { join } from 'node:path';
|
|
8
8
|
|
|
9
|
-
import { createTmpFolder, TMP_FOLDER_PATH } from './
|
|
9
|
+
import { createTmpFolder, TMP_FOLDER_PATH } from './tmp';
|
|
10
10
|
|
|
11
|
-
type CreateKeyvStoreAdapterOptions = {
|
|
11
|
+
export type CreateKeyvStoreAdapterOptions = {
|
|
12
12
|
postgresUri: MaybeUndefined<string>;
|
|
13
13
|
};
|
|
14
14
|
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from './add-on.interface';
|
|
2
|
+
export * from './add-on.wrapper';
|
|
3
|
+
export * from './types';
|
|
4
|
+
export * from './implementations/sentry/sentry.add-on.state.interface';
|
|
5
|
+
export * from './implementations/swagger/swagger.add-on.state.interface';
|
|
6
|
+
export * from './implementations/swagger/types';
|
|
@@ -4,20 +4,20 @@ import { IServerProvider } from '@ask-ell/node';
|
|
|
4
4
|
|
|
5
5
|
import { AddOnWrapper, AddOnWrapperParams } from './add-ons';
|
|
6
6
|
|
|
7
|
-
type NestApplicationFactoryParams = {
|
|
8
|
-
|
|
7
|
+
export type NestApplicationFactoryParams = {
|
|
8
|
+
addons: AddOnWrapperParams;
|
|
9
9
|
module: DynamicModule;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
export async function createNestApplication({
|
|
13
|
-
params,
|
|
14
13
|
module,
|
|
14
|
+
addons: addonsParams,
|
|
15
15
|
}: NestApplicationFactoryParams): Promise<IServerProvider> {
|
|
16
16
|
const application: INestApplication = await NestFactory.create(module, {
|
|
17
17
|
logger: new ConsoleLogger({
|
|
18
18
|
json: true,
|
|
19
19
|
}),
|
|
20
20
|
});
|
|
21
|
-
new AddOnWrapper(
|
|
21
|
+
new AddOnWrapper(addonsParams).apply(application);
|
|
22
22
|
return application;
|
|
23
23
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ExceptionFilter,
|
|
3
|
+
type ArgumentsHost,
|
|
4
|
+
Catch,
|
|
5
|
+
HttpException,
|
|
6
|
+
} from '@nestjs/common';
|
|
7
|
+
import type { HttpArgumentsHost } from '@nestjs/common/interfaces';
|
|
8
|
+
import type { Response } from 'express';
|
|
9
|
+
|
|
10
|
+
import type { HttpResponseBody } from '../../http';
|
|
11
|
+
|
|
12
|
+
@Catch(HttpException)
|
|
13
|
+
export class HttpExceptionFilter implements ExceptionFilter {
|
|
14
|
+
catch(exception: HttpException, host: ArgumentsHost): void {
|
|
15
|
+
const context: HttpArgumentsHost = host.switchToHttp();
|
|
16
|
+
const response: Response = context.getResponse<Response>();
|
|
17
|
+
const status: number = exception.getStatus();
|
|
18
|
+
const responseData: HttpResponseBody = {
|
|
19
|
+
message: exception.message,
|
|
20
|
+
};
|
|
21
|
+
response.status(status).json(responseData);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './http.exception.filter';
|
|
@@ -2,7 +2,7 @@ import { Entity, IResult, ok } from '@ask-ell/core';
|
|
|
2
2
|
import { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common';
|
|
3
3
|
import { catchError, Observable, throwError } from 'rxjs';
|
|
4
4
|
|
|
5
|
-
type ErrorInterceptorProps = {
|
|
5
|
+
export type ErrorInterceptorProps = {
|
|
6
6
|
errorConvertor: (error: unknown) => unknown;
|
|
7
7
|
};
|
|
8
8
|
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Injectable,
|
|
3
|
+
NestInterceptor,
|
|
4
|
+
ExecutionContext,
|
|
5
|
+
CallHandler,
|
|
6
|
+
} from '@nestjs/common';
|
|
7
|
+
import { Observable } from 'rxjs';
|
|
8
|
+
import { map } from 'rxjs/operators';
|
|
9
|
+
|
|
10
|
+
import { HttpResponseBody } from '../../http/types';
|
|
11
|
+
|
|
12
|
+
@Injectable()
|
|
13
|
+
export class ResponseFormatInterceptor<T>
|
|
14
|
+
implements NestInterceptor<T, HttpResponseBody<T>>
|
|
15
|
+
{
|
|
16
|
+
intercept(
|
|
17
|
+
_context: ExecutionContext,
|
|
18
|
+
next: CallHandler
|
|
19
|
+
): Observable<HttpResponseBody<T>> {
|
|
20
|
+
return next.handle().pipe(
|
|
21
|
+
map(
|
|
22
|
+
(data: T): HttpResponseBody<T> => ({
|
|
23
|
+
data,
|
|
24
|
+
message: 'ok',
|
|
25
|
+
})
|
|
26
|
+
)
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MiddlewareConsumer,
|
|
3
|
+
Module,
|
|
4
|
+
NestModule,
|
|
5
|
+
RequestMethod,
|
|
6
|
+
} from '@nestjs/common';
|
|
7
|
+
|
|
8
|
+
import { PingMiddleware } from './middlewares';
|
|
9
|
+
|
|
10
|
+
@Module({
|
|
11
|
+
providers: [PingMiddleware],
|
|
12
|
+
})
|
|
13
|
+
export class HealthModule implements NestModule {
|
|
14
|
+
configure(consumer: MiddlewareConsumer): void {
|
|
15
|
+
consumer.apply(PingMiddleware).forRoutes({
|
|
16
|
+
path: '/health/ping',
|
|
17
|
+
method: RequestMethod.GET,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './health.module';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ping.middleware';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Injectable, NestMiddleware } from '@nestjs/common';
|
|
2
|
+
import type { Request, Response } from 'express';
|
|
3
|
+
|
|
4
|
+
@Injectable()
|
|
5
|
+
export class PingMiddleware implements NestMiddleware {
|
|
6
|
+
use(_request: Request, response: Response): void {
|
|
7
|
+
response.end('Pong');
|
|
8
|
+
}
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './requirement.module';
|
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Module } from '@nestjs/common';
|
|
2
2
|
import { ConfigModule } from '@nestjs/config';
|
|
3
3
|
import { APP_FILTER, APP_GUARD, APP_INTERCEPTOR } from '@nestjs/core';
|
|
4
4
|
import { ThrottlerGuard, ThrottlerModule } from '@nestjs/throttler';
|
|
5
5
|
import type { ILogger } from '@ask-ell/core';
|
|
6
|
-
import {
|
|
7
|
-
NestLogger,
|
|
8
|
-
HealthModule,
|
|
9
|
-
ResponseFormatInterceptor,
|
|
10
|
-
HttpExceptionFilter,
|
|
11
|
-
} from '@ask-ell/nest';
|
|
6
|
+
import { NestLogger } from '@ask-ell/nest';
|
|
12
7
|
import { SentryGlobalFilter, SentryModule } from '@sentry/nestjs/setup';
|
|
13
8
|
|
|
14
|
-
import { KeyvStoreAdapterFactory } from '
|
|
15
|
-
import { dockerSecretGetter, localSecretGetter } from '
|
|
9
|
+
import { KeyvStoreAdapterFactory } from '../../../keyv.store.adapter.factory';
|
|
10
|
+
import { dockerSecretGetter, localSecretGetter } from '../../../secrets';
|
|
11
|
+
import { HealthModule } from '../health';
|
|
12
|
+
import { ResponseFormatInterceptor } from '../../interceptors';
|
|
13
|
+
import { HttpExceptionFilter } from '../../filters';
|
|
16
14
|
|
|
17
15
|
const configModuleLogger: ILogger = NestLogger.fromClass(ConfigModule);
|
|
18
16
|
|
|
19
|
-
@Global()
|
|
20
17
|
@Module({
|
|
21
18
|
imports: [
|
|
22
19
|
HealthModule,
|
package/src/scripts/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './move-keyv-data.
|
|
2
|
-
export * from './update-dependencies-versions.
|
|
1
|
+
export * from './move-keyv-data.program';
|
|
2
|
+
export * from './update-dependencies-versions.program';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PercentageIncrementor } from '@ask-ell/core';
|
|
2
|
-
import {
|
|
2
|
+
import { Program, ProgramExecutionOptions } from '@ask-ell/node';
|
|
3
3
|
import { NestLogger } from '@ask-ell/nest';
|
|
4
4
|
import { Client, QueryResult } from 'pg';
|
|
5
5
|
|
|
@@ -8,7 +8,7 @@ type KeyvRowData<Value = unknown> = {
|
|
|
8
8
|
value: Value;
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
export class
|
|
11
|
+
export class MoveKeyvDataProgram extends Program {
|
|
12
12
|
constructor() {
|
|
13
13
|
super({
|
|
14
14
|
arguments: [
|
|
@@ -23,7 +23,7 @@ export class MoveKeyvDataScript extends Script {
|
|
|
23
23
|
required: true,
|
|
24
24
|
},
|
|
25
25
|
],
|
|
26
|
-
logger: NestLogger.fromClass(
|
|
26
|
+
logger: NestLogger.fromClass(MoveKeyvDataProgram),
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
29
|
|
|
@@ -31,7 +31,7 @@ export class MoveKeyvDataScript extends Script {
|
|
|
31
31
|
logger,
|
|
32
32
|
arguments: { origin, target },
|
|
33
33
|
prompts: { confirm },
|
|
34
|
-
}:
|
|
34
|
+
}: ProgramExecutionOptions): Promise<void> {
|
|
35
35
|
const originPostgresClient: Client = new Client(origin);
|
|
36
36
|
const targetPostgresClient: Client = new Client(target);
|
|
37
37
|
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
UnknownEnvironmentVariableError,
|
|
5
5
|
} from '@ask-ell/core';
|
|
6
6
|
import { NestLogger } from '@ask-ell/nest';
|
|
7
|
-
import {
|
|
7
|
+
import { ProgramExecutionOptions, Program } from '@ask-ell/node';
|
|
8
8
|
import { spawnSync } from 'node:child_process';
|
|
9
9
|
import { writeFileSync } from 'node:fs';
|
|
10
10
|
import { mkdir } from 'node:fs/promises';
|
|
@@ -24,7 +24,7 @@ makeSureThatProjectRootPathIsDefined(PROJECT_ROOT_PATH);
|
|
|
24
24
|
|
|
25
25
|
const NX_GRAPH_FILE_PATH: string = join(PROJECT_ROOT_PATH, 'tmp/graph.json');
|
|
26
26
|
|
|
27
|
-
type PackageContent = {
|
|
27
|
+
export type PackageContent = {
|
|
28
28
|
version: string;
|
|
29
29
|
dependencies: StringDictionnary;
|
|
30
30
|
devDependencies: StringDictionnary;
|
|
@@ -42,22 +42,22 @@ function getOrganisationPackageFile(packageId: string): PackageContent {
|
|
|
42
42
|
return require(packageFilePath);
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
type
|
|
45
|
+
export type UpdateDependenciesVersionsProgramParams = {
|
|
46
46
|
organisationPackagePrefix: string;
|
|
47
47
|
blackListedPackages: string[];
|
|
48
48
|
};
|
|
49
49
|
|
|
50
|
-
type WorkspaceDependenciesMapElement = {
|
|
50
|
+
export type WorkspaceDependenciesMapElement = {
|
|
51
51
|
id: string;
|
|
52
52
|
dependencies: string[];
|
|
53
53
|
source: PackageContent;
|
|
54
54
|
};
|
|
55
55
|
|
|
56
|
-
type WorkspaceDependenciesMap = {
|
|
56
|
+
export type WorkspaceDependenciesMap = {
|
|
57
57
|
[id: string]: WorkspaceDependenciesMapElement;
|
|
58
58
|
};
|
|
59
59
|
|
|
60
|
-
export class
|
|
60
|
+
export class UpdateDependenciesVersionsProgram extends Program {
|
|
61
61
|
private organisationPackagePrefix: string;
|
|
62
62
|
private blackListedPackages: string[];
|
|
63
63
|
private workspaceDependenciesMap: WorkspaceDependenciesMap =
|
|
@@ -66,9 +66,9 @@ export class UpdateDependenciesVersionsScript extends Script {
|
|
|
66
66
|
constructor({
|
|
67
67
|
organisationPackagePrefix,
|
|
68
68
|
blackListedPackages,
|
|
69
|
-
}:
|
|
69
|
+
}: UpdateDependenciesVersionsProgramParams) {
|
|
70
70
|
super({
|
|
71
|
-
logger: NestLogger.fromClass(
|
|
71
|
+
logger: NestLogger.fromClass(UpdateDependenciesVersionsProgram),
|
|
72
72
|
arguments: [
|
|
73
73
|
{
|
|
74
74
|
name: 'targetedPackage',
|
|
@@ -83,7 +83,7 @@ export class UpdateDependenciesVersionsScript extends Script {
|
|
|
83
83
|
async execute({
|
|
84
84
|
logger,
|
|
85
85
|
arguments: { targetedPackage },
|
|
86
|
-
}:
|
|
86
|
+
}: ProgramExecutionOptions): Promise<void> {
|
|
87
87
|
const workspaceDependenciesMapElements: WorkspaceDependenciesMapElement[] =
|
|
88
88
|
Object.values(this.workspaceDependenciesMap).filter(
|
|
89
89
|
({ id }: WorkspaceDependenciesMapElement): boolean =>
|
package/src/add-ons/index.ts
DELETED
package/src/utils/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './tmp';
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/src/{add-ons → nest/add-ons}/implementations/sentry/sentry.add-on.state.interface.ts
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/src/{add-ons → nest/add-ons}/implementations/swagger/swagger.add-on.state.interface.ts
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|