@ask-ell/back-end 0.2.1 → 0.2.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 (37) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/package.json +2 -1
  3. package/src/http/index.ts +1 -0
  4. package/src/http/types.ts +4 -0
  5. package/src/index.ts +2 -3
  6. package/src/keyv.store.adapter.factory.ts +2 -2
  7. package/src/nest/add-ons/index.ts +6 -0
  8. package/src/{application.base.ts → nest/application.base.ts} +1 -1
  9. package/src/{application.factory.ts → nest/application.factory.ts} +4 -4
  10. package/src/nest/filters/http.exception.filter.ts +23 -0
  11. package/src/nest/filters/index.ts +1 -0
  12. package/src/nest/index.ts +6 -0
  13. package/src/{error.interceptor.ts → nest/interceptors/error.interceptor.ts} +1 -1
  14. package/src/nest/interceptors/index.ts +2 -0
  15. package/src/nest/interceptors/response.format.interceptor.ts +29 -0
  16. package/src/nest/modules/health/health.module.ts +20 -0
  17. package/src/nest/modules/health/index.ts +1 -0
  18. package/src/nest/modules/health/middlewares/index.ts +1 -0
  19. package/src/nest/modules/health/middlewares/ping.middleware.ts +9 -0
  20. package/src/nest/modules/index.ts +2 -0
  21. package/src/nest/modules/requirement/index.ts +1 -0
  22. package/src/{requirement.module.ts → nest/modules/requirement/requirement.module.ts} +7 -10
  23. package/src/scripts/update-dependencies-versions.script.ts +4 -4
  24. package/src/add-ons/index.ts +0 -2
  25. package/src/utils/index.ts +0 -1
  26. /package/src/{add-ons → nest/add-ons}/add-on.interface.ts +0 -0
  27. /package/src/{add-ons → nest/add-ons}/add-on.wrapper.ts +0 -0
  28. /package/src/{add-ons → nest/add-ons}/implementations/security/security.add-on.ts +0 -0
  29. /package/src/{add-ons → nest/add-ons}/implementations/sentry/sentry.add-on.interface.ts +0 -0
  30. /package/src/{add-ons → nest/add-ons}/implementations/sentry/sentry.add-on.state.interface.ts +0 -0
  31. /package/src/{add-ons → nest/add-ons}/implementations/sentry/sentry.add-on.ts +0 -0
  32. /package/src/{add-ons → nest/add-ons}/implementations/swagger/swagger.add-on.interface.ts +0 -0
  33. /package/src/{add-ons → nest/add-ons}/implementations/swagger/swagger.add-on.state.interface.ts +0 -0
  34. /package/src/{add-ons → nest/add-ons}/implementations/swagger/swagger.add-on.ts +0 -0
  35. /package/src/{add-ons → nest/add-ons}/implementations/swagger/types.ts +0 -0
  36. /package/src/{add-ons → nest/add-ons}/types.ts +0 -0
  37. /package/src/{utils/tmp.ts → tmp.ts} +0 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # @ask-ell/back-end
2
+
3
+ ## 0.2.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [`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`.
8
+ - 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)]:
9
+ - @ask-ell/core@1.3.6
10
+ - @ask-ell/nest@0.0.15
11
+ - @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.1",
3
+ "version": "0.2.3",
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';
@@ -0,0 +1,4 @@
1
+ export type HttpResponseBody<Data = unknown> = {
2
+ message: string;
3
+ data?: Data;
4
+ };
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 './application.base';
6
- export * from './application.factory';
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 './utils';
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';
@@ -1,6 +1,6 @@
1
1
  import { DynamicModule, Provider, Module, Global } from '@nestjs/common';
2
2
 
3
- import { RequirementModule } from './requirement.module';
3
+ import { RequirementModule } from './modules';
4
4
 
5
5
  @Global()
6
6
  @Module({
@@ -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
- params: AddOnWrapperParams;
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(params).apply(application);
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';
@@ -0,0 +1,6 @@
1
+ export * from './add-ons';
2
+ export * from './application.base';
3
+ export * from './application.factory';
4
+ export * from './filters';
5
+ export * from './interceptors';
6
+ export * from './modules';
@@ -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,2 @@
1
+ export * from './error.interceptor';
2
+ export * from './response.format.interceptor';
@@ -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,2 @@
1
+ export * from './health';
2
+ export * from './requirement';
@@ -0,0 +1 @@
1
+ export * from './requirement.module';
@@ -1,22 +1,19 @@
1
- import { Global, Module } from '@nestjs/common';
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 './keyv.store.adapter.factory';
15
- import { dockerSecretGetter, localSecretGetter } from './secrets';
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,
@@ -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,18 +42,18 @@ function getOrganisationPackageFile(packageId: string): PackageContent {
42
42
  return require(packageFilePath);
43
43
  }
44
44
 
45
- type UpdateDependenciesVersionsScriptParams = {
45
+ export type UpdateDependenciesVersionsScriptParams = {
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
 
@@ -1,2 +0,0 @@
1
- export * from './add-on.wrapper';
2
- export * from './types';
@@ -1 +0,0 @@
1
- export * from './tmp';
File without changes
File without changes
File without changes