@iamnnort/nestjs-serializer 2.2.8 → 2.10.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/README.md CHANGED
@@ -145,9 +145,7 @@ import { AppController } from './controller';
145
145
  @Module({
146
146
  imports: [
147
147
  LoggerModule,
148
- SerializerModule.register({
149
- globalEntityNames: [Model.name],
150
- }),
148
+ SerializerModule,
151
149
  ],
152
150
  controllers: [AppController],
153
151
  })
package/dist/index.d.mts CHANGED
@@ -27,7 +27,6 @@ type SerializerFieldConfig = {
27
27
  fieldTransform?: (value: any, entity: any) => any | Promise<any>;
28
28
  };
29
29
  type SerializerConfig = {
30
- globalEntityNames?: string[];
31
30
  globalLimitedScopes?: string[];
32
31
  globalSecretScopes?: string[];
33
32
  };
@@ -63,7 +62,7 @@ declare const SerializerInterceptor: (config: {
63
62
  serializerService: SerializerService;
64
63
  intercept(ctx: ExecutionContext, next: CallHandler<Promise<any>>): rxjs.Observable<Promise<any>>;
65
64
  getScopes(ctx: ExecutionContext): string[];
66
- withQueryScopes(ctx: ExecutionContext, scopes: string[]): string[];
65
+ withExtendedScopes(ctx: ExecutionContext, scopes: string[]): string[];
67
66
  withSecretScopes(ctx: ExecutionContext, scopes: string[]): string[];
68
67
  };
69
68
  };
@@ -72,7 +71,7 @@ declare const SerializerIdInterceptor_base: {
72
71
  serializerService: SerializerService;
73
72
  intercept(ctx: ExecutionContext, next: CallHandler<Promise<any>>): rxjs.Observable<Promise<any>>;
74
73
  getScopes(ctx: ExecutionContext): string[];
75
- withQueryScopes(ctx: ExecutionContext, scopes: string[]): string[];
74
+ withExtendedScopes(ctx: ExecutionContext, scopes: string[]): string[];
76
75
  withSecretScopes(ctx: ExecutionContext, scopes: string[]): string[];
77
76
  };
78
77
  };
package/dist/index.d.ts CHANGED
@@ -27,7 +27,6 @@ type SerializerFieldConfig = {
27
27
  fieldTransform?: (value: any, entity: any) => any | Promise<any>;
28
28
  };
29
29
  type SerializerConfig = {
30
- globalEntityNames?: string[];
31
30
  globalLimitedScopes?: string[];
32
31
  globalSecretScopes?: string[];
33
32
  };
@@ -63,7 +62,7 @@ declare const SerializerInterceptor: (config: {
63
62
  serializerService: SerializerService;
64
63
  intercept(ctx: ExecutionContext, next: CallHandler<Promise<any>>): rxjs.Observable<Promise<any>>;
65
64
  getScopes(ctx: ExecutionContext): string[];
66
- withQueryScopes(ctx: ExecutionContext, scopes: string[]): string[];
65
+ withExtendedScopes(ctx: ExecutionContext, scopes: string[]): string[];
67
66
  withSecretScopes(ctx: ExecutionContext, scopes: string[]): string[];
68
67
  };
69
68
  };
@@ -72,7 +71,7 @@ declare const SerializerIdInterceptor_base: {
72
71
  serializerService: SerializerService;
73
72
  intercept(ctx: ExecutionContext, next: CallHandler<Promise<any>>): rxjs.Observable<Promise<any>>;
74
73
  getScopes(ctx: ExecutionContext): string[];
75
- withQueryScopes(ctx: ExecutionContext, scopes: string[]): string[];
74
+ withExtendedScopes(ctx: ExecutionContext, scopes: string[]): string[];
76
75
  withSecretScopes(ctx: ExecutionContext, scopes: string[]): string[];
77
76
  };
78
77
  };
package/dist/index.js CHANGED
@@ -9110,12 +9110,9 @@ var SerializerService = class {
9110
9110
  return _lodash.pick.call(void 0, entity, config.fields);
9111
9111
  }
9112
9112
  const serializerFieldConfigs = global.serializerFieldConfigs.filter((fieldConfig) => {
9113
- const isTarget = fieldConfig.target === entity.constructor;
9113
+ const isTarget = entity instanceof fieldConfig.target;
9114
9114
  if (!isTarget) {
9115
- const isGlobalTarget = (this.config.globalEntityNames || []).includes(fieldConfig.target.name);
9116
- if (!isGlobalTarget) {
9117
- return false;
9118
- }
9115
+ return false;
9119
9116
  }
9120
9117
  const isScope = fieldConfig.scopes.some((scope) => {
9121
9118
  if (!config.scopes) {
@@ -9228,7 +9225,7 @@ var SerializerInterceptor = /* @__PURE__ */ __name((config) => {
9228
9225
  }
9229
9226
  intercept(ctx, next) {
9230
9227
  const request = ctx.switchToHttp().getRequest();
9231
- request.scopes = this.withQueryScopes(ctx, this.withSecretScopes(ctx, this.getScopes(ctx)));
9228
+ request.scopes = this.getScopes(ctx);
9232
9229
  return next.handle().pipe((0, import_operators.map)(async (responsePromise) => {
9233
9230
  const response = await responsePromise;
9234
9231
  if (!request.scopes && !config.fields) {
@@ -9246,18 +9243,18 @@ var SerializerInterceptor = /* @__PURE__ */ __name((config) => {
9246
9243
  if (request.query.limited === "true") {
9247
9244
  return config.limitedScopes || this.serializerService.config.globalLimitedScopes || scopes;
9248
9245
  }
9249
- if (request.query.extended === "true") {
9250
- return config.extendedScopes || scopes;
9246
+ if (request.query.scopes && config.allowedScopes) {
9247
+ return _lodash.intersection.call(void 0, request.query.scopes, config.allowedScopes);
9251
9248
  }
9252
- return scopes;
9249
+ return this.withSecretScopes(ctx, this.withExtendedScopes(ctx, scopes));
9253
9250
  }
9254
- withQueryScopes(ctx, scopes) {
9251
+ withExtendedScopes(ctx, scopes) {
9255
9252
  const request = ctx.switchToHttp().getRequest();
9256
- if (request.query.scopes && config.allowedScopes) {
9257
- const queryScopes = _lodash.intersection.call(void 0, request.query.scopes, config.allowedScopes);
9253
+ if (request.query.extended === "true") {
9254
+ const extendedScopes = config.extendedScopes || [];
9258
9255
  return _lodash.uniq.call(void 0, [
9259
9256
  ...scopes,
9260
- ...queryScopes
9257
+ ...extendedScopes
9261
9258
  ]);
9262
9259
  }
9263
9260
  return scopes;