@nestjs/throttler 5.0.0 → 5.1.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  # The MIT License
2
2
 
3
- Copyright 2019-2022 Jay McDoniel, contributors
3
+ Copyright 2019-2023 Jay McDoniel, contributors
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
6
 
package/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  <p align="center">
2
2
  <a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="120" alt="Nest Logo" /></a>
3
3
  </p>
4
-
5
4
  [travis-image]: https://api.travis-ci.org/nestjs/nest.svg?branch=master
6
5
  [travis-url]: https://travis-ci.org/nestjs/nest
7
6
  [linux-image]: https://img.shields.io/travis/nestjs/nest/master.svg?label=linux
@@ -12,8 +11,6 @@
12
11
  <a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
13
12
  <a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
14
13
  <a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/dm/@nestjs/core.svg" alt="NPM Downloads" /></a>
15
- <a href="https://travis-ci.org/nestjs/nest"><img src="https://api.travis-ci.org/nestjs/nest.svg?branch=master" alt="Travis" /></a>
16
- <a href="https://travis-ci.org/nestjs/nest"><img src="https://img.shields.io/travis/nestjs/nest/master.svg?label=linux" alt="Linux" /></a>
17
14
  <a href="https://coveralls.io/github/nestjs/nest?branch=master"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#5" alt="Coverage" /></a>
18
15
  <a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
19
16
  <a href="https://opencollective.com/nest#backer"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
@@ -41,6 +38,8 @@ $ npm i --save @nestjs/throttler
41
38
 
42
39
  For NestJS v10, please use version 4.1.0 or above
43
40
 
41
+ <div id="toc"></div>
42
+
44
43
  ## Table of Contents
45
44
 
46
45
  - [Description](#description)
@@ -95,7 +94,7 @@ There may come upon times where you want to set up multiple throttling definitio
95
94
  imports: [
96
95
  ThrottlerModule.forRoot([
97
96
  {
98
- name: 'short'
97
+ name: 'short',
99
98
  ttl: 1000,
100
99
  limit: 3,
101
100
  },
@@ -105,7 +104,7 @@ There may come upon times where you want to set up multiple throttling definitio
105
104
  limit: 20
106
105
  },
107
106
  {
108
- long: 'long',
107
+ name: 'long',
109
108
  ttl: 60000,
110
109
  limit: 100
111
110
  }
@@ -165,8 +164,11 @@ import { Injectable } from '@nestjs/common';
165
164
 
166
165
  @Injectable()
167
166
  export class ThrottlerBehindProxyGuard extends ThrottlerGuard {
168
- protected getTracker(req: Record<string, any>): string {
169
- return req.ips.length ? req.ips[0] : req.ip; // individualize IP extraction to meet your own needs
167
+ protected getTracker(req: Record<string, any>): Promise<string> {
168
+ return new Promise<string>((resolve, reject) => {
169
+ const tracker = req.ips.length > 0 ? req.ips[0] : req.ip; // individualize IP extraction to meet your own needs
170
+ resolve(tracker);
171
+ });
170
172
  }
171
173
  }
172
174
 
@@ -185,10 +187,15 @@ This module can work with websockets, but it requires some class extension. You
185
187
  ```typescript
186
188
  @Injectable()
187
189
  export class WsThrottlerGuard extends ThrottlerGuard {
188
- async handleRequest(context: ExecutionContext, limit: number, ttl: number): Promise<boolean> {
190
+ async handleRequest(
191
+ context: ExecutionContext,
192
+ limit: number,
193
+ ttl: number,
194
+ throttler: ThrottlerOptions,
195
+ ): Promise<boolean> {
189
196
  const client = context.switchToWs().getClient();
190
197
  const ip = client._socket.remoteAddress;
191
- const key = this.generateKey(context, ip);
198
+ const key = this.generateKey(context, ip, throttler.name);
192
199
  const { totalHits } = await this.storageService.increment(key, ttl);
193
200
 
194
201
  if (totalHits > limit) {
@@ -224,6 +231,30 @@ export class GqlThrottlerGuard extends ThrottlerGuard {
224
231
  }
225
232
  ```
226
233
 
234
+ However, when using Apollo Express/Fastify or Mercurius, it's important to configure the context correctly in the GraphQLModule to avoid any problems.
235
+
236
+ #### Apollo Server (for Express):
237
+
238
+ For Apollo Server running on Express, you can set up the context in your GraphQLModule configuration as follows:
239
+
240
+ ```typescript
241
+ GraphQLModule.forRoot({
242
+ // ... other GraphQL module options
243
+ context: ({ req, res }) => ({ req, res }),
244
+ });
245
+ ```
246
+
247
+ #### Apollo Server (for Fastify) & Mercurius:
248
+
249
+ When using Apollo Server with Fastify or Mercurius, you need to configure the context differently. You should use request and reply objects. Here's an example:
250
+
251
+ ```typescript
252
+ GraphQLModule.forRoot({
253
+ // ... other GraphQL module options
254
+ context: (request, reply) => ({ request, reply }),
255
+ });
256
+ ```
257
+
227
258
  #### Configuration
228
259
 
229
260
  The following options are valid for the object passed to the array of the `ThrottlerModule`'s options:
@@ -249,6 +280,14 @@ The following options are valid for the object passed to the array of the `Throt
249
280
  <td><code>skipIf</code></td>
250
281
  <td>a function that takes in the <code>ExecutionContext</code> and returns a <code>boolean</code> to short circuit the throttler logic. Like <code>@SkipThrottler()</code>, but based on the request</td>
251
282
  </tr>
283
+ <tr>
284
+ <td><code>getTracker</code></td>
285
+ <td>a function that takes in the <code>Request</code> and returns a <code>string</code> to override the default logic of the <code>getTracker</code> method</td>
286
+ </tr>
287
+ <tr>
288
+ <td><code>generateKey</code></td>
289
+ <td>a function that takes in the <code>ExecutionContext</code>, the tacker <code>string</code> and the throttler name as a <code>string</code> and returns a <code>string</code> to override the final key which will be used to store the rate limit value. This overrides the default logic of the <code>generateKey</code> method</td>
290
+ </tr>
252
291
  </table>
253
292
 
254
293
  If you need to set up storages instead, or want to use a some of the above options in a more global sense, applying to each throttler set, you can pass the options above via the `throttlers` option key and use the below table
@@ -270,6 +309,18 @@ If you need to set up storages instead, or want to use a some of the above optio
270
309
  <td><code>throttlers</code></td>
271
310
  <td>an array of throttler sets, defined using the table above</td>
272
311
  </tr>
312
+ <tr>
313
+ <td><code>errorMessage</code></td>
314
+ <td>a <code>string</code> which overrides the default throttler error message</td>
315
+ </tr>
316
+ <tr>
317
+ <td><code>getTracker</code></td>
318
+ <td>a function that takes in the <code>Request</code> and returns a <code>string</code> to override the default logic of the <code>getTracker</code> method</td>
319
+ </tr>
320
+ <tr>
321
+ <td><code>generateKey</code></td>
322
+ <td>a function that takes in the <code>ExecutionContext</code>, the tacker <code>string</code> and the throttler name as a <code>string</code> and returns a <code>string</code> to override the final key which will be used to store the rate limit value. This overrides the default logic of the <code>generateKey</code> method</td>
323
+ </tr>
273
324
  </table>
274
325
 
275
326
  #### Async Configuration
@@ -353,3 +404,5 @@ Feel free to submit a PR with your custom storage provider being added to this l
353
404
  ## License
354
405
 
355
406
  Nest is [MIT licensed](LICENSE).
407
+
408
+ <p align="right"><a href="#toc">🔼 Back to TOC</a></p>
@@ -7,10 +7,15 @@ export interface ThrottlerOptions {
7
7
  ttl: Resolvable<number>;
8
8
  ignoreUserAgents?: RegExp[];
9
9
  skipIf?: (context: ExecutionContext) => boolean;
10
+ getTracker?: ThrottlerGetTrackerFunction;
11
+ generateKey?: ThrottlerGenerateKeyFunction;
10
12
  }
11
13
  export type ThrottlerModuleOptions = Array<ThrottlerOptions> | {
12
14
  skipIf?: (context: ExecutionContext) => boolean;
13
15
  ignoreUserAgents?: RegExp[];
16
+ getTracker?: ThrottlerGetTrackerFunction;
17
+ generateKey?: ThrottlerGenerateKeyFunction;
18
+ errorMessage?: string;
14
19
  storage?: ThrottlerStorage;
15
20
  throttlers: Array<ThrottlerOptions>;
16
21
  };
@@ -23,3 +28,5 @@ export interface ThrottlerAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
23
28
  useFactory?: (...args: any[]) => Promise<ThrottlerModuleOptions> | ThrottlerModuleOptions;
24
29
  inject?: any[];
25
30
  }
31
+ export type ThrottlerGetTrackerFunction = (req: Record<string, any>) => Promise<string> | string;
32
+ export type ThrottlerGenerateKeyFunction = (context: ExecutionContext, trackerString: string, throttlerName: string) => string;
@@ -1,4 +1,6 @@
1
1
  export declare const THROTTLER_LIMIT = "THROTTLER:LIMIT";
2
2
  export declare const THROTTLER_TTL = "THROTTLER:TTL";
3
+ export declare const THROTTLER_TRACKER = "THROTTLER:TRACKER";
4
+ export declare const THROTTLER_KEY_GENERATOR = "THROTTLER:KEY_GENERATOR";
3
5
  export declare const THROTTLER_OPTIONS = "THROTTLER:MODULE_OPTIONS";
4
6
  export declare const THROTTLER_SKIP = "THROTTLER:SKIP";
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.THROTTLER_SKIP = exports.THROTTLER_OPTIONS = exports.THROTTLER_TTL = exports.THROTTLER_LIMIT = void 0;
3
+ exports.THROTTLER_SKIP = exports.THROTTLER_OPTIONS = exports.THROTTLER_KEY_GENERATOR = exports.THROTTLER_TRACKER = exports.THROTTLER_TTL = exports.THROTTLER_LIMIT = void 0;
4
4
  exports.THROTTLER_LIMIT = 'THROTTLER:LIMIT';
5
5
  exports.THROTTLER_TTL = 'THROTTLER:TTL';
6
+ exports.THROTTLER_TRACKER = 'THROTTLER:TRACKER';
7
+ exports.THROTTLER_KEY_GENERATOR = 'THROTTLER:KEY_GENERATOR';
6
8
  exports.THROTTLER_OPTIONS = 'THROTTLER:MODULE_OPTIONS';
7
9
  exports.THROTTLER_SKIP = 'THROTTLER:SKIP';
8
10
  //# sourceMappingURL=throttler.constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"throttler.constants.js","sourceRoot":"","sources":["../src/throttler.constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,eAAe,GAAG,iBAAiB,CAAC;AACpC,QAAA,aAAa,GAAG,eAAe,CAAC;AAChC,QAAA,iBAAiB,GAAG,0BAA0B,CAAC;AAC/C,QAAA,cAAc,GAAG,gBAAgB,CAAC"}
1
+ {"version":3,"file":"throttler.constants.js","sourceRoot":"","sources":["../src/throttler.constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,eAAe,GAAG,iBAAiB,CAAC;AACpC,QAAA,aAAa,GAAG,eAAe,CAAC;AAChC,QAAA,iBAAiB,GAAG,mBAAmB,CAAC;AACxC,QAAA,uBAAuB,GAAG,yBAAyB,CAAC;AACpD,QAAA,iBAAiB,GAAG,0BAA0B,CAAC;AAC/C,QAAA,cAAc,GAAG,gBAAgB,CAAC"}
@@ -1,7 +1,9 @@
1
- import { Resolvable } from './throttler-module-options.interface';
1
+ import { Resolvable, ThrottlerGenerateKeyFunction, ThrottlerGetTrackerFunction } from './throttler-module-options.interface';
2
2
  interface ThrottlerMethodOrControllerOptions {
3
3
  limit?: Resolvable<number>;
4
4
  ttl?: Resolvable<number>;
5
+ getTracker?: ThrottlerGetTrackerFunction;
6
+ generateKey?: ThrottlerGenerateKeyFunction;
5
7
  }
6
8
  export declare const Throttle: (options: Record<string, ThrottlerMethodOrControllerOptions>) => MethodDecorator & ClassDecorator;
7
9
  export declare const SkipThrottle: (skip?: Record<string, boolean>) => MethodDecorator & ClassDecorator;
@@ -8,6 +8,8 @@ function setThrottlerMetadata(target, options) {
8
8
  for (const name in options) {
9
9
  Reflect.defineMetadata(throttler_constants_1.THROTTLER_TTL + name, options[name].ttl, target);
10
10
  Reflect.defineMetadata(throttler_constants_1.THROTTLER_LIMIT + name, options[name].limit, target);
11
+ Reflect.defineMetadata(throttler_constants_1.THROTTLER_TRACKER + name, options[name].getTracker, target);
12
+ Reflect.defineMetadata(throttler_constants_1.THROTTLER_KEY_GENERATOR + name, options[name].generateKey, target);
11
13
  }
12
14
  }
13
15
  const Throttle = (options) => {
@@ -23,14 +25,12 @@ const Throttle = (options) => {
23
25
  exports.Throttle = Throttle;
24
26
  const SkipThrottle = (skip = { default: true }) => {
25
27
  return (target, propertyKey, descriptor) => {
28
+ var _a;
29
+ const reflectionTarget = (_a = descriptor === null || descriptor === void 0 ? void 0 : descriptor.value) !== null && _a !== void 0 ? _a : target;
26
30
  for (const key in skip) {
27
- if (descriptor) {
28
- Reflect.defineMetadata(throttler_constants_1.THROTTLER_SKIP + key, skip[key], descriptor.value);
29
- return descriptor;
30
- }
31
- Reflect.defineMetadata(throttler_constants_1.THROTTLER_SKIP + key, skip[key], target);
32
- return target;
31
+ Reflect.defineMetadata(throttler_constants_1.THROTTLER_SKIP + key, skip[key], reflectionTarget);
33
32
  }
33
+ return descriptor !== null && descriptor !== void 0 ? descriptor : target;
34
34
  };
35
35
  };
36
36
  exports.SkipThrottle = SkipThrottle;
@@ -1 +1 @@
1
- {"version":3,"file":"throttler.decorator.js","sourceRoot":"","sources":["../src/throttler.decorator.ts"],"names":[],"mappings":";;;AAAA,2CAAwC;AACxC,+DAAuF;AACvF,+DAAyE;AAQzE,SAAS,oBAAoB,CAC3B,MAAW,EACX,OAA2D;IAE3D,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE;QAC1B,OAAO,CAAC,cAAc,CAAC,mCAAa,GAAG,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QACxE,OAAO,CAAC,cAAc,CAAC,qCAAe,GAAG,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;KAC7E;AACH,CAAC;AASM,MAAM,QAAQ,GAAG,CACtB,OAA2D,EACzB,EAAE;IACpC,OAAO,CACL,MAAW,EACX,WAA6B,EAC7B,UAAyC,EACzC,EAAE;QACF,IAAI,UAAU,EAAE;YACd,oBAAoB,CAAC,UAAU,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;YAChD,OAAO,UAAU,CAAC;SACnB;QACD,oBAAoB,CAAC,MAAM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,CAAC;AACJ,CAAC,CAAC;AAdW,QAAA,YAAY,gBAcvB;AAOK,MAAM,sBAAsB,GAAG,GAAG,EAAE,CAAC,IAAA,eAAM,EAAC,IAAA,qCAAe,GAAE,CAAC,CAAC;AAAzD,QAAA,sBAAsB,0BAAmC;AAO/D,MAAM,sBAAsB,GAAG,GAAG,EAAE,CAAC,IAAA,eAAM,EAAC,IAAA,qCAAe,GAAE,CAAC,CAAC;AAAzD,QAAA,sBAAsB,0BAAmC"}
@@ -1,6 +1,6 @@
1
1
  import { CanActivate, ExecutionContext } from '@nestjs/common';
2
2
  import { Reflector } from '@nestjs/core';
3
- import { ThrottlerModuleOptions, ThrottlerOptions } from './throttler-module-options.interface';
3
+ import { ThrottlerGenerateKeyFunction, ThrottlerGetTrackerFunction, ThrottlerModuleOptions, ThrottlerOptions } from './throttler-module-options.interface';
4
4
  import { ThrottlerStorage } from './throttler-storage.interface';
5
5
  import { ThrottlerLimitDetail } from './throttler.guard.interface';
6
6
  export declare class ThrottlerGuard implements CanActivate {
@@ -10,12 +10,12 @@ export declare class ThrottlerGuard implements CanActivate {
10
10
  protected headerPrefix: string;
11
11
  protected errorMessage: string;
12
12
  protected throttlers: Array<ThrottlerOptions>;
13
- protected commonOptions: Pick<ThrottlerOptions, 'skipIf' | 'ignoreUserAgents'>;
13
+ protected commonOptions: Pick<ThrottlerOptions, 'skipIf' | 'ignoreUserAgents' | 'getTracker' | 'generateKey'>;
14
14
  constructor(options: ThrottlerModuleOptions, storageService: ThrottlerStorage, reflector: Reflector);
15
15
  onModuleInit(): Promise<void>;
16
16
  canActivate(context: ExecutionContext): Promise<boolean>;
17
17
  protected shouldSkip(_context: ExecutionContext): Promise<boolean>;
18
- protected handleRequest(context: ExecutionContext, limit: number, ttl: number, throttler: ThrottlerOptions): Promise<boolean>;
18
+ protected handleRequest(context: ExecutionContext, limit: number, ttl: number, throttler: ThrottlerOptions, getTracker: ThrottlerGetTrackerFunction, generateKey: ThrottlerGenerateKeyFunction): Promise<boolean>;
19
19
  protected getTracker(req: Record<string, any>): Promise<string>;
20
20
  protected getRequestResponse(context: ExecutionContext): {
21
21
  req: Record<string, any>;
@@ -29,6 +29,8 @@ let ThrottlerGuard = class ThrottlerGuard {
29
29
  this.errorMessage = throttler_exception_1.throttlerMessage;
30
30
  }
31
31
  async onModuleInit() {
32
+ var _a, _b;
33
+ var _c, _d;
32
34
  this.throttlers = (Array.isArray(this.options) ? this.options : this.options.throttlers)
33
35
  .sort((first, second) => {
34
36
  if (typeof first.ttl === 'function') {
@@ -47,8 +49,12 @@ let ThrottlerGuard = class ThrottlerGuard {
47
49
  this.commonOptions = {
48
50
  skipIf: this.options.skipIf,
49
51
  ignoreUserAgents: this.options.ignoreUserAgents,
52
+ getTracker: this.options.getTracker,
53
+ generateKey: this.options.generateKey,
50
54
  };
51
55
  }
56
+ (_a = (_c = this.commonOptions).getTracker) !== null && _a !== void 0 ? _a : (_c.getTracker = this.getTracker);
57
+ (_b = (_d = this.commonOptions).generateKey) !== null && _b !== void 0 ? _b : (_d.generateKey = this.generateKey);
52
58
  }
53
59
  async canActivate(context) {
54
60
  const handler = context.getHandler();
@@ -69,16 +75,20 @@ let ThrottlerGuard = class ThrottlerGuard {
69
75
  }
70
76
  const routeOrClassLimit = this.reflector.getAllAndOverride(throttler_constants_1.THROTTLER_LIMIT + namedThrottler.name, [handler, classRef]);
71
77
  const routeOrClassTtl = this.reflector.getAllAndOverride(throttler_constants_1.THROTTLER_TTL + namedThrottler.name, [handler, classRef]);
78
+ const routeOrClassGetTracker = this.reflector.getAllAndOverride(throttler_constants_1.THROTTLER_TRACKER + namedThrottler.name, [handler, classRef]);
79
+ const routeOrClassGetKeyGenerator = this.reflector.getAllAndOverride(throttler_constants_1.THROTTLER_KEY_GENERATOR + namedThrottler.name, [handler, classRef]);
72
80
  const limit = await this.resolveValue(context, routeOrClassLimit || namedThrottler.limit);
73
81
  const ttl = await this.resolveValue(context, routeOrClassTtl || namedThrottler.ttl);
74
- continues.push(await this.handleRequest(context, limit, ttl, namedThrottler));
82
+ const getTracker = routeOrClassGetTracker || namedThrottler.getTracker || this.commonOptions.getTracker;
83
+ const generateKey = routeOrClassGetKeyGenerator || namedThrottler.generateKey || this.commonOptions.generateKey;
84
+ continues.push(await this.handleRequest(context, limit, ttl, namedThrottler, getTracker, generateKey));
75
85
  }
76
86
  return continues.every((cont) => cont);
77
87
  }
78
88
  async shouldSkip(_context) {
79
89
  return false;
80
90
  }
81
- async handleRequest(context, limit, ttl, throttler) {
91
+ async handleRequest(context, limit, ttl, throttler, getTracker, generateKey) {
82
92
  var _a;
83
93
  const { req, res } = this.getRequestResponse(context);
84
94
  const ignoreUserAgents = (_a = throttler.ignoreUserAgents) !== null && _a !== void 0 ? _a : this.commonOptions.ignoreUserAgents;
@@ -89,8 +99,8 @@ let ThrottlerGuard = class ThrottlerGuard {
89
99
  }
90
100
  }
91
101
  }
92
- const tracker = await this.getTracker(req);
93
- const key = this.generateKey(context, tracker, throttler.name);
102
+ const tracker = await getTracker(req);
103
+ const key = generateKey(context, tracker, throttler.name);
94
104
  const { totalHits, timeToExpire } = await this.storageService.increment(key, ttl);
95
105
  const getThrottlerSuffix = (name) => (name === 'default' ? '' : `-${name}`);
96
106
  if (totalHits > limit) {
@@ -124,6 +134,9 @@ let ThrottlerGuard = class ThrottlerGuard {
124
134
  throw new throttler_exception_1.ThrottlerException(await this.getErrorMessage(context, throttlerLimitDetail));
125
135
  }
126
136
  async getErrorMessage(_context, _throttlerLimitDetail) {
137
+ if (!Array.isArray(this.options)) {
138
+ return this.options.errorMessage || this.errorMessage;
139
+ }
127
140
  return this.errorMessage;
128
141
  }
129
142
  async resolveValue(context, resolvableValue) {
@@ -1 +1 @@
1
- {"version":3,"file":"throttler.guard.js","sourceRoot":"","sources":["../src/throttler.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAA2E;AAC3E,uCAAyC;AACzC,2BAA2B;AAM3B,+EAAiE;AACjE,+DAAuF;AACvF,+D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