@tndhuy/create-app 1.2.9 → 1.3.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tndhuy/create-app",
3
- "version": "1.2.9",
3
+ "version": "1.3.0",
4
4
  "private": false,
5
5
  "bin": {
6
6
  "create-app": "dist/cli.js"
@@ -0,0 +1,9 @@
1
+ import { SetMetadata } from '@nestjs/common';
2
+
3
+ export const STANDARD_RESPONSE_KEY = 'standard_response';
4
+
5
+ /**
6
+ * Decorator to wrap the response in a standardized envelope:
7
+ * { success: true, data: T, meta?: PaginationMeta }
8
+ */
9
+ export const StandardResponse = () => SetMetadata(STANDARD_RESPONSE_KEY, true);
@@ -2,4 +2,5 @@ export * from './filters/http-exception.filter';
2
2
  export * from './interceptors/transform.interceptor';
3
3
  export * from './interceptors/timeout.interceptor';
4
4
  export * from './decorators/raw-response.decorator';
5
+ export * from './decorators/standard-response.decorator';
5
6
  export * from './middleware/correlation-id.middleware';
@@ -2,7 +2,7 @@ import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nes
2
2
  import { Reflector } from '@nestjs/core';
3
3
  import { Observable } from 'rxjs';
4
4
  import { map } from 'rxjs/operators';
5
- import { PUBLIC_API_KEY } from '../decorators/public-api.decorator';
5
+ import { STANDARD_RESPONSE_KEY } from '../decorators/standard-response.decorator';
6
6
 
7
7
  export const RAW_RESPONSE_KEY = 'raw_response';
8
8
 
@@ -20,18 +20,17 @@ export class TransformInterceptor<T> implements NestInterceptor<T, unknown> {
20
20
  return next.handle();
21
21
  }
22
22
 
23
- const isPublic = this.reflector.getAllAndOverride<boolean>(PUBLIC_API_KEY, [
23
+ const useStandard = this.reflector.getAllAndOverride<boolean>(STANDARD_RESPONSE_KEY, [
24
24
  context.getHandler(),
25
25
  context.getClass(),
26
26
  ]);
27
27
 
28
- // If not explicitly marked as Public API (or similar decorator), return RAW data
29
- // This allows internal/system calls to remain untouched while Public APIs are standardized.
30
- if (!isPublic) {
28
+ // Internal first: If not explicitly marked for Standard Response, return RAW data
29
+ if (!useStandard) {
31
30
  return next.handle();
32
31
  }
33
32
 
34
- // Public API: Wrap response in a standardized success object
33
+ // Standard Response: Wrap response in a standardized success object
35
34
  return next.handle().pipe(
36
35
  map((data) => {
37
36
  // Handle paginated results: { items: [], meta: {} }
@@ -1,7 +1,7 @@
1
1
  import { Body, Controller, Delete, Get, Param, Post, Query } from '@nestjs/common';
2
2
  import { ApiTags, ApiOperation, ApiResponse, ApiParam } from '@nestjs/swagger';
3
3
  import { CommandBus, QueryBus } from '@nestjs/cqrs';
4
- import { PublicApi } from '../../../common/decorators/public-api.decorator';
4
+ import { StandardResponse } from '../../../common/decorators/standard-response.decorator';
5
5
  import { CreateItemDto } from '../application/dtos/create-item.dto';
6
6
  import { ItemResponseDto } from '../application/dtos/item.response.dto';
7
7
  import { CreateItemCommand } from '../application/commands/create-item.command';
@@ -11,7 +11,7 @@ import { ListItemsQuery } from '../application/queries/list-items.query';
11
11
  import { PaginationDto } from '../../../shared';
12
12
 
13
13
  @ApiTags('example')
14
- @PublicApi()
14
+ @StandardResponse()
15
15
  @Controller('items')
16
16
  export class ItemController {
17
17
  constructor(
@@ -0,0 +1,9 @@
1
+ import { SetMetadata } from '@nestjs/common';
2
+
3
+ export const STANDARD_RESPONSE_KEY = 'standard_response';
4
+
5
+ /**
6
+ * Decorator to wrap the response in a standardized envelope:
7
+ * { success: true, data: T, meta?: PaginationMeta }
8
+ */
9
+ export const StandardResponse = () => SetMetadata(STANDARD_RESPONSE_KEY, true);
@@ -2,4 +2,5 @@ export * from './filters/http-exception.filter';
2
2
  export * from './interceptors/transform.interceptor';
3
3
  export * from './interceptors/timeout.interceptor';
4
4
  export * from './decorators/raw-response.decorator';
5
+ export * from './decorators/standard-response.decorator';
5
6
  export * from './middleware/correlation-id.middleware';
@@ -2,7 +2,7 @@ import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nes
2
2
  import { Reflector } from '@nestjs/core';
3
3
  import { Observable } from 'rxjs';
4
4
  import { map } from 'rxjs/operators';
5
- import { PUBLIC_API_KEY } from '../decorators/public-api.decorator';
5
+ import { STANDARD_RESPONSE_KEY } from '../decorators/standard-response.decorator';
6
6
 
7
7
  export const RAW_RESPONSE_KEY = 'raw_response';
8
8
 
@@ -20,18 +20,17 @@ export class TransformInterceptor<T> implements NestInterceptor<T, unknown> {
20
20
  return next.handle();
21
21
  }
22
22
 
23
- const isPublic = this.reflector.getAllAndOverride<boolean>(PUBLIC_API_KEY, [
23
+ const useStandard = this.reflector.getAllAndOverride<boolean>(STANDARD_RESPONSE_KEY, [
24
24
  context.getHandler(),
25
25
  context.getClass(),
26
26
  ]);
27
27
 
28
- // If not explicitly marked as Public API (or similar decorator), return RAW data
29
- // This allows internal/system calls to remain untouched while Public APIs are standardized.
30
- if (!isPublic) {
28
+ // Internal first: If not explicitly marked for Standard Response, return RAW data
29
+ if (!useStandard) {
31
30
  return next.handle();
32
31
  }
33
32
 
34
- // Public API: Wrap response in a standardized success object
33
+ // Standard Response: Wrap response in a standardized success object
35
34
  return next.handle().pipe(
36
35
  map((data) => {
37
36
  // Handle paginated results: { items: [], meta: {} }
@@ -1,7 +1,7 @@
1
1
  import { Body, Controller, Delete, Get, Param, Post, Query } from '@nestjs/common';
2
2
  import { ApiTags, ApiOperation, ApiResponse, ApiParam } from '@nestjs/swagger';
3
3
  import { CommandBus, QueryBus } from '@nestjs/cqrs';
4
- import { PublicApi } from '../../../common/decorators/public-api.decorator';
4
+ import { StandardResponse } from '../../../common/decorators/standard-response.decorator';
5
5
  import { CreateItemDto } from '../application/dtos/create-item.dto';
6
6
  import { ItemResponseDto } from '../application/dtos/item.response.dto';
7
7
  import { CreateItemCommand } from '../application/commands/create-item.command';
@@ -11,7 +11,7 @@ import { ListItemsQuery } from '../application/queries/list-items.query';
11
11
  import { PaginationDto } from '../../../shared';
12
12
 
13
13
  @ApiTags('example')
14
- @PublicApi()
14
+ @StandardResponse()
15
15
  @Controller('items')
16
16
  export class ItemController {
17
17
  constructor(
@@ -1,9 +0,0 @@
1
- import { SetMetadata } from '@nestjs/common';
2
-
3
- export const PUBLIC_API_KEY = 'public_api';
4
- /**
5
- * Decorator to mark an endpoint as Public API.
6
- * This will trigger the TransformInterceptor to wrap the response in { success: true, data: T }.
7
- * Without this decorator, the response remains raw.
8
- */
9
- export const PublicApi = () => SetMetadata(PUBLIC_API_KEY, true);
@@ -1,9 +0,0 @@
1
- import { SetMetadata } from '@nestjs/common';
2
-
3
- export const PUBLIC_API_KEY = 'public_api';
4
- /**
5
- * Decorator to mark an endpoint as Public API.
6
- * This will trigger the TransformInterceptor to wrap the response in { success: true, data: T }.
7
- * Without this decorator, the response remains raw.
8
- */
9
- export const PublicApi = () => SetMetadata(PUBLIC_API_KEY, true);