@iamnnort/nestjs-serializer 2.2.6 → 2.2.8

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/dist/index.mjs CHANGED
@@ -9205,7 +9205,7 @@ SerializerService = _ts_decorate([
9205
9205
  ], SerializerService);
9206
9206
 
9207
9207
  // src/interceptor.ts
9208
- import { intersection } from "lodash";
9208
+ import { intersection, uniq as uniq2 } from "lodash";
9209
9209
  function _ts_decorate2(decorators, target, key, desc) {
9210
9210
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
9211
9211
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -9228,7 +9228,7 @@ var SerializerInterceptor = /* @__PURE__ */ __name((config) => {
9228
9228
  }
9229
9229
  intercept(ctx, next) {
9230
9230
  const request = ctx.switchToHttp().getRequest();
9231
- request.scopes = this.getScopes(ctx);
9231
+ request.scopes = this.withQueryScopes(ctx, this.withSecretScopes(ctx, this.getScopes(ctx)));
9232
9232
  return next.handle().pipe((0, import_operators.map)(async (responsePromise) => {
9233
9233
  const response = await responsePromise;
9234
9234
  if (!request.scopes && !config.fields) {
@@ -9242,19 +9242,36 @@ var SerializerInterceptor = /* @__PURE__ */ __name((config) => {
9242
9242
  }
9243
9243
  getScopes(ctx) {
9244
9244
  const request = ctx.switchToHttp().getRequest();
9245
+ const scopes = config.scopes || [];
9245
9246
  if (request.query.limited === "true") {
9246
- return config.limitedScopes || this.serializerService.config.globalLimitedScopes || config.scopes;
9247
+ return config.limitedScopes || this.serializerService.config.globalLimitedScopes || scopes;
9247
9248
  }
9248
9249
  if (request.query.extended === "true") {
9249
- return config.extendedScopes || config.scopes;
9250
- }
9251
- if (request.query.secret === "true") {
9252
- return config.secretScopes || this.serializerService.config.globalSecretScopes || config.scopes;
9250
+ return config.extendedScopes || scopes;
9253
9251
  }
9252
+ return scopes;
9253
+ }
9254
+ withQueryScopes(ctx, scopes) {
9255
+ const request = ctx.switchToHttp().getRequest();
9254
9256
  if (request.query.scopes && config.allowedScopes) {
9255
- return intersection(request.query.scopes, config.allowedScopes);
9257
+ const queryScopes = intersection(request.query.scopes, config.allowedScopes);
9258
+ return uniq2([
9259
+ ...scopes,
9260
+ ...queryScopes
9261
+ ]);
9262
+ }
9263
+ return scopes;
9264
+ }
9265
+ withSecretScopes(ctx, scopes) {
9266
+ const request = ctx.switchToHttp().getRequest();
9267
+ if (request.query.secret === "true") {
9268
+ const secretScopes = config.secretScopes || this.serializerService.config.globalSecretScopes || [];
9269
+ return uniq2([
9270
+ ...scopes,
9271
+ ...secretScopes
9272
+ ]);
9256
9273
  }
9257
- return config.scopes;
9274
+ return scopes;
9258
9275
  }
9259
9276
  };
9260
9277
  SerializerInterceptor2 = _ts_decorate2([