pm2-token-bucket 1.0.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 +437 -0
- package/README.md +211 -0
- package/dist/Bucket.d.ts +41 -0
- package/dist/Bucket.d.ts.map +1 -0
- package/dist/Bucket.js +65 -0
- package/dist/Bucket.js.map +1 -0
- package/dist/Client.d.ts +20 -0
- package/dist/Client.d.ts.map +1 -0
- package/dist/Client.js +73 -0
- package/dist/Client.js.map +1 -0
- package/dist/Manager.d.ts +40 -0
- package/dist/Manager.d.ts.map +1 -0
- package/dist/Manager.js +75 -0
- package/dist/Manager.js.map +1 -0
- package/dist/config.d.ts +10 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +12 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/package.json +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
Attribution-NonCommercial-ShareAlike 4.0 International
|
|
2
|
+
|
|
3
|
+
=======================================================================
|
|
4
|
+
|
|
5
|
+
Creative Commons Corporation ("Creative Commons") is not a law firm and
|
|
6
|
+
does not provide legal services or legal advice. Distribution of
|
|
7
|
+
Creative Commons public licenses does not create a lawyer-client or
|
|
8
|
+
other relationship. Creative Commons makes its licenses and related
|
|
9
|
+
information available on an "as-is" basis. Creative Commons gives no
|
|
10
|
+
warranties regarding its licenses, any material licensed under their
|
|
11
|
+
terms and conditions, or any related information. Creative Commons
|
|
12
|
+
disclaims all liability for damages resulting from their use to the
|
|
13
|
+
fullest extent possible.
|
|
14
|
+
|
|
15
|
+
Using Creative Commons Public Licenses
|
|
16
|
+
|
|
17
|
+
Creative Commons public licenses provide a standard set of terms and
|
|
18
|
+
conditions that creators and other rights holders may use to share
|
|
19
|
+
original works of authorship and other material subject to copyright
|
|
20
|
+
and certain other rights specified in the public license below. The
|
|
21
|
+
following considerations are for informational purposes only, are not
|
|
22
|
+
exhaustive, and do not form part of our licenses.
|
|
23
|
+
|
|
24
|
+
Considerations for licensors: Our public licenses are
|
|
25
|
+
intended for use by those authorized to give the public
|
|
26
|
+
permission to use material in ways otherwise restricted by
|
|
27
|
+
copyright and certain other rights. Our licenses are
|
|
28
|
+
irrevocable. Licensors should read and understand the terms
|
|
29
|
+
and conditions of the license they choose before applying it.
|
|
30
|
+
Licensors should also secure all rights necessary before
|
|
31
|
+
applying our licenses so that the public can reuse the
|
|
32
|
+
material as expected. Licensors should clearly mark any
|
|
33
|
+
material not subject to the license. This includes other CC-
|
|
34
|
+
licensed material, or material used under an exception or
|
|
35
|
+
limitation to copyright. More considerations for licensors:
|
|
36
|
+
wiki.creativecommons.org/Considerations_for_licensors
|
|
37
|
+
|
|
38
|
+
Considerations for the public: By using one of our public
|
|
39
|
+
licenses, a licensor grants the public permission to use the
|
|
40
|
+
licensed material under specified terms and conditions. If
|
|
41
|
+
the licensor's permission is not necessary for any reason--for
|
|
42
|
+
example, because of any applicable exception or limitation to
|
|
43
|
+
copyright--then that use is not regulated by the license. Our
|
|
44
|
+
licenses grant only permissions under copyright and certain
|
|
45
|
+
other rights that a licensor has authority to grant. Use of
|
|
46
|
+
the licensed material may still be restricted for other
|
|
47
|
+
reasons, including because others have copyright or other
|
|
48
|
+
rights in the material. A licensor may make special requests,
|
|
49
|
+
such as asking that all changes be marked or described.
|
|
50
|
+
Although not required by our licenses, you are encouraged to
|
|
51
|
+
respect those requests where reasonable. More considerations
|
|
52
|
+
for the public:
|
|
53
|
+
wiki.creativecommons.org/Considerations_for_licensees
|
|
54
|
+
|
|
55
|
+
=======================================================================
|
|
56
|
+
|
|
57
|
+
Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
|
|
58
|
+
Public License
|
|
59
|
+
|
|
60
|
+
By exercising the Licensed Rights (defined below), You accept and agree
|
|
61
|
+
to be bound by the terms and conditions of this Creative Commons
|
|
62
|
+
Attribution-NonCommercial-ShareAlike 4.0 International Public License
|
|
63
|
+
("Public License"). To the extent this Public License may be
|
|
64
|
+
interpreted as a contract, You are granted the Licensed Rights in
|
|
65
|
+
consideration of Your acceptance of these terms and conditions, and the
|
|
66
|
+
Licensor grants You such rights in consideration of benefits the
|
|
67
|
+
Licensor receives from making the Licensed Material available under
|
|
68
|
+
these terms and conditions.
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
Section 1 -- Definitions.
|
|
72
|
+
|
|
73
|
+
a. Adapted Material means material subject to Copyright and Similar
|
|
74
|
+
Rights that is derived from or based upon the Licensed Material
|
|
75
|
+
and in which the Licensed Material is translated, altered,
|
|
76
|
+
arranged, transformed, or otherwise modified in a manner requiring
|
|
77
|
+
permission under the Copyright and Similar Rights held by the
|
|
78
|
+
Licensor. For purposes of this Public License, where the Licensed
|
|
79
|
+
Material is a musical work, performance, or sound recording,
|
|
80
|
+
Adapted Material is always produced where the Licensed Material is
|
|
81
|
+
synched in timed relation with a moving image.
|
|
82
|
+
|
|
83
|
+
b. Adapter's License means the license You apply to Your Copyright
|
|
84
|
+
and Similar Rights in Your contributions to Adapted Material in
|
|
85
|
+
accordance with the terms and conditions of this Public License.
|
|
86
|
+
|
|
87
|
+
c. BY-NC-SA Compatible License means a license listed at
|
|
88
|
+
creativecommons.org/compatiblelicenses, approved by Creative
|
|
89
|
+
Commons as essentially the equivalent of this Public License.
|
|
90
|
+
|
|
91
|
+
d. Copyright and Similar Rights means copyright and/or similar rights
|
|
92
|
+
closely related to copyright including, without limitation,
|
|
93
|
+
performance, broadcast, sound recording, and Sui Generis Database
|
|
94
|
+
Rights, without regard to how the rights are labeled or
|
|
95
|
+
categorized. For purposes of this Public License, the rights
|
|
96
|
+
specified in Section 2(b)(1)-(2) are not Copyright and Similar
|
|
97
|
+
Rights.
|
|
98
|
+
|
|
99
|
+
e. Effective Technological Measures means those measures that, in the
|
|
100
|
+
absence of proper authority, may not be circumvented under laws
|
|
101
|
+
fulfilling obligations under Article 11 of the WIPO Copyright
|
|
102
|
+
Treaty adopted on December 20, 1996, and/or similar international
|
|
103
|
+
agreements.
|
|
104
|
+
|
|
105
|
+
f. Exceptions and Limitations means fair use, fair dealing, and/or
|
|
106
|
+
any other exception or limitation to Copyright and Similar Rights
|
|
107
|
+
that applies to Your use of the Licensed Material.
|
|
108
|
+
|
|
109
|
+
g. License Elements means the license attributes listed in the name
|
|
110
|
+
of a Creative Commons Public License. The License Elements of this
|
|
111
|
+
Public License are Attribution, NonCommercial, and ShareAlike.
|
|
112
|
+
|
|
113
|
+
h. Licensed Material means the artistic or literary work, database,
|
|
114
|
+
or other material to which the Licensor applied this Public
|
|
115
|
+
License.
|
|
116
|
+
|
|
117
|
+
i. Licensed Rights means the rights granted to You subject to the
|
|
118
|
+
terms and conditions of this Public License, which are limited to
|
|
119
|
+
all Copyright and Similar Rights that apply to Your use of the
|
|
120
|
+
Licensed Material and that the Licensor has authority to license.
|
|
121
|
+
|
|
122
|
+
j. Licensor means the individual(s) or entity(ies) granting rights
|
|
123
|
+
under this Public License.
|
|
124
|
+
|
|
125
|
+
k. NonCommercial means not primarily intended for or directed towards
|
|
126
|
+
commercial advantage or monetary compensation. For purposes of
|
|
127
|
+
this Public License, the exchange of the Licensed Material for
|
|
128
|
+
other material subject to Copyright and Similar Rights by digital
|
|
129
|
+
file-sharing or similar means is NonCommercial provided there is
|
|
130
|
+
no payment of monetary compensation in connection with the
|
|
131
|
+
exchange.
|
|
132
|
+
|
|
133
|
+
l. Share means to provide material to the public by any means or
|
|
134
|
+
process that requires permission under the Licensed Rights, such
|
|
135
|
+
as reproduction, public display, public performance, distribution,
|
|
136
|
+
dissemination, communication, or importation, and to make material
|
|
137
|
+
available to the public including in ways that members of the
|
|
138
|
+
public may access the material from a place and at a time
|
|
139
|
+
individually chosen by them.
|
|
140
|
+
|
|
141
|
+
m. Sui Generis Database Rights means rights other than copyright
|
|
142
|
+
resulting from Directive 96/9/EC of the European Parliament and of
|
|
143
|
+
the Council of 11 March 1996 on the legal protection of databases,
|
|
144
|
+
as amended and/or succeeded, as well as other essentially
|
|
145
|
+
equivalent rights anywhere in the world.
|
|
146
|
+
|
|
147
|
+
n. You means the individual or entity exercising the Licensed Rights
|
|
148
|
+
under this Public License. Your has a corresponding meaning.
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
Section 2 -- Scope.
|
|
152
|
+
|
|
153
|
+
a. License grant.
|
|
154
|
+
|
|
155
|
+
1. Subject to the terms and conditions of this Public License,
|
|
156
|
+
the Licensor hereby grants You a worldwide, royalty-free,
|
|
157
|
+
non-sublicensable, non-exclusive, irrevocable license to
|
|
158
|
+
exercise the Licensed Rights in the Licensed Material to:
|
|
159
|
+
|
|
160
|
+
a. reproduce and Share the Licensed Material, in whole or
|
|
161
|
+
in part, for NonCommercial purposes only; and
|
|
162
|
+
|
|
163
|
+
b. produce, reproduce, and Share Adapted Material for
|
|
164
|
+
NonCommercial purposes only.
|
|
165
|
+
|
|
166
|
+
2. Exceptions and Limitations. For the avoidance of doubt, where
|
|
167
|
+
Exceptions and Limitations apply to Your use, this Public
|
|
168
|
+
License does not apply, and You do not need to comply with
|
|
169
|
+
its terms and conditions.
|
|
170
|
+
|
|
171
|
+
3. Term. The term of this Public License is specified in Section
|
|
172
|
+
6(a).
|
|
173
|
+
|
|
174
|
+
4. Media and formats; technical modifications allowed. The
|
|
175
|
+
Licensor authorizes You to exercise the Licensed Rights in
|
|
176
|
+
all media and formats whether now known or hereafter created,
|
|
177
|
+
and to make technical modifications necessary to do so. The
|
|
178
|
+
Licensor waives and/or agrees not to assert any right or
|
|
179
|
+
authority to forbid You from making technical modifications
|
|
180
|
+
necessary to exercise the Licensed Rights, including
|
|
181
|
+
technical modifications necessary to circumvent Effective
|
|
182
|
+
Technological Measures. For purposes of this Public License,
|
|
183
|
+
simply making modifications authorized by this Section 2(a)
|
|
184
|
+
(4) never produces Adapted Material.
|
|
185
|
+
|
|
186
|
+
5. Downstream recipients.
|
|
187
|
+
|
|
188
|
+
a. Offer from the Licensor -- Licensed Material. Every
|
|
189
|
+
recipient of the Licensed Material automatically
|
|
190
|
+
receives an offer from the Licensor to exercise the
|
|
191
|
+
Licensed Rights under the terms and conditions of this
|
|
192
|
+
Public License.
|
|
193
|
+
|
|
194
|
+
b. Additional offer from the Licensor -- Adapted Material.
|
|
195
|
+
Every recipient of Adapted Material from You
|
|
196
|
+
automatically receives an offer from the Licensor to
|
|
197
|
+
exercise the Licensed Rights in the Adapted Material
|
|
198
|
+
under the conditions of the Adapter's License You apply.
|
|
199
|
+
|
|
200
|
+
c. No downstream restrictions. You may not offer or impose
|
|
201
|
+
any additional or different terms or conditions on, or
|
|
202
|
+
apply any Effective Technological Measures to, the
|
|
203
|
+
Licensed Material if doing so restricts exercise of the
|
|
204
|
+
Licensed Rights by any recipient of the Licensed
|
|
205
|
+
Material.
|
|
206
|
+
|
|
207
|
+
6. No endorsement. Nothing in this Public License constitutes or
|
|
208
|
+
may be construed as permission to assert or imply that You
|
|
209
|
+
are, or that Your use of the Licensed Material is, connected
|
|
210
|
+
with, or sponsored, endorsed, or granted official status by,
|
|
211
|
+
the Licensor or others designated to receive attribution as
|
|
212
|
+
provided in Section 3(a)(1)(A)(i).
|
|
213
|
+
|
|
214
|
+
b. Other rights.
|
|
215
|
+
|
|
216
|
+
1. Moral rights, such as the right of integrity, are not
|
|
217
|
+
licensed under this Public License, nor are publicity,
|
|
218
|
+
privacy, and/or other similar personality rights; however, to
|
|
219
|
+
the extent possible, the Licensor waives and/or agrees not to
|
|
220
|
+
assert any such rights held by the Licensor to the limited
|
|
221
|
+
extent necessary to allow You to exercise the Licensed
|
|
222
|
+
Rights, but not otherwise.
|
|
223
|
+
|
|
224
|
+
2. Patent and trademark rights are not licensed under this
|
|
225
|
+
Public License.
|
|
226
|
+
|
|
227
|
+
3. To the extent possible, the Licensor waives any right to
|
|
228
|
+
collect royalties from You for the exercise of the Licensed
|
|
229
|
+
Rights, whether directly or through a collecting society
|
|
230
|
+
under any voluntary or waivable statutory or compulsory
|
|
231
|
+
licensing scheme. In all other cases the Licensor expressly
|
|
232
|
+
reserves any right to collect such royalties, including when
|
|
233
|
+
the Licensed Material is used other than for NonCommercial
|
|
234
|
+
purposes.
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
Section 3 -- License Conditions.
|
|
238
|
+
|
|
239
|
+
Your exercise of the Licensed Rights is expressly made subject to the
|
|
240
|
+
following conditions.
|
|
241
|
+
|
|
242
|
+
a. Attribution.
|
|
243
|
+
|
|
244
|
+
1. If You Share the Licensed Material (including in modified
|
|
245
|
+
form), You must:
|
|
246
|
+
|
|
247
|
+
a. retain the following if it is supplied by the Licensor
|
|
248
|
+
with the Licensed Material:
|
|
249
|
+
|
|
250
|
+
i. identification of the creator(s) of the Licensed
|
|
251
|
+
Material and any others designated to receive
|
|
252
|
+
attribution, in any reasonable manner requested by
|
|
253
|
+
the Licensor (including by pseudonym if
|
|
254
|
+
designated);
|
|
255
|
+
|
|
256
|
+
ii. a copyright notice;
|
|
257
|
+
|
|
258
|
+
iii. a notice that refers to this Public License;
|
|
259
|
+
|
|
260
|
+
iv. a notice that refers to the disclaimer of
|
|
261
|
+
warranties;
|
|
262
|
+
|
|
263
|
+
v. a URI or hyperlink to the Licensed Material to the
|
|
264
|
+
extent reasonably practicable;
|
|
265
|
+
|
|
266
|
+
b. indicate if You modified the Licensed Material and
|
|
267
|
+
retain an indication of any previous modifications; and
|
|
268
|
+
|
|
269
|
+
c. indicate the Licensed Material is licensed under this
|
|
270
|
+
Public License, and include the text of, or the URI or
|
|
271
|
+
hyperlink to, this Public License.
|
|
272
|
+
|
|
273
|
+
2. You may satisfy the conditions in Section 3(a)(1) in any
|
|
274
|
+
reasonable manner based on the medium, means, and context in
|
|
275
|
+
which You Share the Licensed Material. For example, it may be
|
|
276
|
+
reasonable to satisfy the conditions by providing a URI or
|
|
277
|
+
hyperlink to a resource that includes the required
|
|
278
|
+
information.
|
|
279
|
+
3. If requested by the Licensor, You must remove any of the
|
|
280
|
+
information required by Section 3(a)(1)(A) to the extent
|
|
281
|
+
reasonably practicable.
|
|
282
|
+
|
|
283
|
+
b. ShareAlike.
|
|
284
|
+
|
|
285
|
+
In addition to the conditions in Section 3(a), if You Share
|
|
286
|
+
Adapted Material You produce, the following conditions also apply.
|
|
287
|
+
|
|
288
|
+
1. The Adapter's License You apply must be a Creative Commons
|
|
289
|
+
license with the same License Elements, this version or
|
|
290
|
+
later, or a BY-NC-SA Compatible License.
|
|
291
|
+
|
|
292
|
+
2. You must include the text of, or the URI or hyperlink to, the
|
|
293
|
+
Adapter's License You apply. You may satisfy this condition
|
|
294
|
+
in any reasonable manner based on the medium, means, and
|
|
295
|
+
context in which You Share Adapted Material.
|
|
296
|
+
|
|
297
|
+
3. You may not offer or impose any additional or different terms
|
|
298
|
+
or conditions on, or apply any Effective Technological
|
|
299
|
+
Measures to, Adapted Material that restrict exercise of the
|
|
300
|
+
rights granted under the Adapter's License You apply.
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
Section 4 -- Sui Generis Database Rights.
|
|
304
|
+
|
|
305
|
+
Where the Licensed Rights include Sui Generis Database Rights that
|
|
306
|
+
apply to Your use of the Licensed Material:
|
|
307
|
+
|
|
308
|
+
a. for the avoidance of doubt, Section 2(a)(1) grants You the right
|
|
309
|
+
to extract, reuse, reproduce, and Share all or a substantial
|
|
310
|
+
portion of the contents of the database for NonCommercial purposes
|
|
311
|
+
only;
|
|
312
|
+
|
|
313
|
+
b. if You include all or a substantial portion of the database
|
|
314
|
+
contents in a database in which You have Sui Generis Database
|
|
315
|
+
Rights, then the database in which You have Sui Generis Database
|
|
316
|
+
Rights (but not its individual contents) is Adapted Material,
|
|
317
|
+
including for purposes of Section 3(b); and
|
|
318
|
+
|
|
319
|
+
c. You must comply with the conditions in Section 3(a) if You Share
|
|
320
|
+
all or a substantial portion of the contents of the database.
|
|
321
|
+
|
|
322
|
+
For the avoidance of doubt, this Section 4 supplements and does not
|
|
323
|
+
replace Your obligations under this Public License where the Licensed
|
|
324
|
+
Rights include other Copyright and Similar Rights.
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
Section 5 -- Disclaimer of Warranties and Limitation of Liability.
|
|
328
|
+
|
|
329
|
+
a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
|
|
330
|
+
EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
|
|
331
|
+
AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
|
|
332
|
+
ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
|
|
333
|
+
IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
|
|
334
|
+
WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
|
335
|
+
PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
|
|
336
|
+
ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
|
|
337
|
+
KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
|
|
338
|
+
ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
|
|
339
|
+
|
|
340
|
+
b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
|
|
341
|
+
TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
|
|
342
|
+
NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
|
|
343
|
+
INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
|
|
344
|
+
COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
|
|
345
|
+
USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
|
|
346
|
+
ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
|
|
347
|
+
DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
|
|
348
|
+
IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
|
|
349
|
+
|
|
350
|
+
c. The disclaimer of warranties and limitation of liability provided
|
|
351
|
+
above shall be interpreted in a manner that, to the extent
|
|
352
|
+
possible, most closely approximates an absolute disclaimer and
|
|
353
|
+
waiver of all liability.
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
Section 6 -- Term and Termination.
|
|
357
|
+
|
|
358
|
+
a. This Public License applies for the term of the Copyright and
|
|
359
|
+
Similar Rights licensed here. However, if You fail to comply with
|
|
360
|
+
this Public License, then Your rights under this Public License
|
|
361
|
+
terminate automatically.
|
|
362
|
+
|
|
363
|
+
b. Where Your right to use the Licensed Material has terminated under
|
|
364
|
+
Section 6(a), it reinstates:
|
|
365
|
+
|
|
366
|
+
1. automatically as of the date the violation is cured, provided
|
|
367
|
+
it is cured within 30 days of Your discovery of the
|
|
368
|
+
violation; or
|
|
369
|
+
|
|
370
|
+
2. upon express reinstatement by the Licensor.
|
|
371
|
+
|
|
372
|
+
For the avoidance of doubt, this Section 6(b) does not affect any
|
|
373
|
+
right the Licensor may have to seek remedies for Your violations
|
|
374
|
+
of this Public License.
|
|
375
|
+
|
|
376
|
+
c. For the avoidance of doubt, the Licensor may also offer the
|
|
377
|
+
Licensed Material under separate terms or conditions or stop
|
|
378
|
+
distributing the Licensed Material at any time; however, doing so
|
|
379
|
+
will not terminate this Public License.
|
|
380
|
+
|
|
381
|
+
d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
|
|
382
|
+
License.
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
Section 7 -- Other Terms and Conditions.
|
|
386
|
+
|
|
387
|
+
a. The Licensor shall not be bound by any additional or different
|
|
388
|
+
terms or conditions communicated by You unless expressly agreed.
|
|
389
|
+
|
|
390
|
+
b. Any arrangements, understandings, or agreements regarding the
|
|
391
|
+
Licensed Material not stated herein are separate from and
|
|
392
|
+
independent of the terms and conditions of this Public License.
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
Section 8 -- Interpretation.
|
|
396
|
+
|
|
397
|
+
a. For the avoidance of doubt, this Public License does not, and
|
|
398
|
+
shall not be interpreted to, reduce, limit, restrict, or impose
|
|
399
|
+
conditions on any use of the Licensed Material that could lawfully
|
|
400
|
+
be made without permission under this Public License.
|
|
401
|
+
|
|
402
|
+
b. To the extent possible, if any provision of this Public License is
|
|
403
|
+
deemed unenforceable, it shall be automatically reformed to the
|
|
404
|
+
minimum extent necessary to make it enforceable. If the provision
|
|
405
|
+
cannot be reformed, it shall be severed from this Public License
|
|
406
|
+
without affecting the enforceability of the remaining terms and
|
|
407
|
+
conditions.
|
|
408
|
+
|
|
409
|
+
c. No term or condition of this Public License will be waived and no
|
|
410
|
+
failure to comply consented to unless expressly agreed to by the
|
|
411
|
+
Licensor.
|
|
412
|
+
|
|
413
|
+
d. Nothing in this Public License constitutes or may be interpreted
|
|
414
|
+
as a limitation upon, or waiver of, any privileges and immunities
|
|
415
|
+
that apply to the Licensor or You, including from the legal
|
|
416
|
+
processes of any jurisdiction or authority.
|
|
417
|
+
|
|
418
|
+
=======================================================================
|
|
419
|
+
|
|
420
|
+
Creative Commons is not a party to its public
|
|
421
|
+
licenses. Notwithstanding, Creative Commons may elect to apply one of
|
|
422
|
+
its public licenses to material it publishes and in those instances
|
|
423
|
+
will be considered the “Licensor.” The text of the Creative Commons
|
|
424
|
+
public licenses is dedicated to the public domain under the CC0 Public
|
|
425
|
+
Domain Dedication. Except for the limited purpose of indicating that
|
|
426
|
+
material is shared under a Creative Commons public license or as
|
|
427
|
+
otherwise permitted by the Creative Commons policies published at
|
|
428
|
+
creativecommons.org/policies, Creative Commons does not authorize the
|
|
429
|
+
use of the trademark "Creative Commons" or any other trademark or logo
|
|
430
|
+
of Creative Commons without its prior written consent including,
|
|
431
|
+
without limitation, in connection with any unauthorized modifications
|
|
432
|
+
to any of its public licenses or any other arrangements,
|
|
433
|
+
understandings, or agreements concerning use of licensed material. For
|
|
434
|
+
the avoidance of doubt, this paragraph does not form part of the
|
|
435
|
+
public licenses.
|
|
436
|
+
|
|
437
|
+
Creative Commons may be contacted at creativecommons.org.
|
package/README.md
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
# PM2 Token Bucket
|
|
2
|
+
|
|
3
|
+
Token bucket server for API throttling shared between instances using [PM2](https://pm2.keymetrics.io/) clusters.
|
|
4
|
+
|
|
5
|
+
## Why?
|
|
6
|
+
|
|
7
|
+
When running a Node.js application in PM2 cluster mode, each instance operates independently.
|
|
8
|
+
If your app calls a rate-limited external API, every instance competes for the same quota — easily exceeding limits.
|
|
9
|
+
|
|
10
|
+
**PM2 Token Bucket** solves this by running a dedicated token server as a separate PM2 process.
|
|
11
|
+
All cluster instances request tokens from this central server via PM2's built-in IPC bus, ensuring a single, shared rate limit across your entire cluster.
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
┌──────────────────────────────────────────┐
|
|
15
|
+
│ PM2 Ecosystem │
|
|
16
|
+
│ │
|
|
17
|
+
│ ┌──────────────────────────────────┐ │
|
|
18
|
+
│ │ TokenManager (server.js app) │ │
|
|
19
|
+
│ │ Manages the shared bucket │ │
|
|
20
|
+
│ └──────────────────────────────────┘ │
|
|
21
|
+
│ ▲ │
|
|
22
|
+
│ │ │
|
|
23
|
+
│ │ PM2 IPC Bus │
|
|
24
|
+
│ │ │
|
|
25
|
+
│ ┌────────┼────────┐ │
|
|
26
|
+
│ ▼ ▼ ▼ │
|
|
27
|
+
│ ┌──────┐ ┌──────┐ ┌──────┐ │
|
|
28
|
+
│ │ App │ │ App │ │ App │ │
|
|
29
|
+
│ │ #0 │ │ #1 │ │ #2 │ (cluster) │
|
|
30
|
+
│ └──────┘ └──────┘ └──────┘ │
|
|
31
|
+
└──────────────────────────────────────────┘
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Installation
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
npm install pm2-token-bucket
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
> **Peer dependency:** `pm2 >= 6.0.0`
|
|
41
|
+
|
|
42
|
+
## Quick Start
|
|
43
|
+
|
|
44
|
+
You can see an example in the `example` directory of this repo, but here’s a quick overview of how to set it up:
|
|
45
|
+
|
|
46
|
+
### 1. Create the Token Server
|
|
47
|
+
|
|
48
|
+
Create a dedicated PM2 process that manages the shared token bucket.
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
// server.js
|
|
52
|
+
const { TokenManager } = require('pm2-token-bucket');
|
|
53
|
+
|
|
54
|
+
const tokenManager = new TokenManager({
|
|
55
|
+
capacity: 10, // Max tokens in the bucket
|
|
56
|
+
refillRate: 1, // Tokens added per refill
|
|
57
|
+
refillInterval: 3000 // Refill every 3 seconds
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
tokenManager.start((err) => {
|
|
61
|
+
if (err) {
|
|
62
|
+
console.error("Failed to start TokenManager:", err);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### 2. Consume Tokens in Your App
|
|
68
|
+
|
|
69
|
+
In your cluster application instances, use `TokenClient` to request tokens before making API calls.
|
|
70
|
+
|
|
71
|
+
```js
|
|
72
|
+
// app.js
|
|
73
|
+
const express = require('express');
|
|
74
|
+
const { TokenClient } = require('pm2-token-bucket');
|
|
75
|
+
|
|
76
|
+
const app = express();
|
|
77
|
+
const tokenClient = new TokenClient();
|
|
78
|
+
|
|
79
|
+
app.use(async (req, res, next) => {
|
|
80
|
+
try {
|
|
81
|
+
if (await tokenClient.consume(1)) {
|
|
82
|
+
next(); // Token granted — proceed
|
|
83
|
+
} else {
|
|
84
|
+
res.status(429).send('Too many requests');
|
|
85
|
+
}
|
|
86
|
+
} catch (err) {
|
|
87
|
+
next(); // Fallback: allow on error
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
app.get('/', (req, res) => {
|
|
92
|
+
res.sendStatus(200);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
app.listen(process.env.PORT || 3000);
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### 3. Configure PM2 Ecosystem
|
|
99
|
+
|
|
100
|
+
Launch you app X times in cluster mode, and add 1 token server as a separate process.
|
|
101
|
+
|
|
102
|
+
```js
|
|
103
|
+
// ecosystem.config.js
|
|
104
|
+
module.exports = {
|
|
105
|
+
apps: [{
|
|
106
|
+
name: "tokenServer",
|
|
107
|
+
script: "./server.js"
|
|
108
|
+
}, {
|
|
109
|
+
name: "clientApp",
|
|
110
|
+
script: "./app.js",
|
|
111
|
+
instances: 3,
|
|
112
|
+
exec_mode: "cluster"
|
|
113
|
+
}]
|
|
114
|
+
};
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### 4. Start Everything
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
pm2 start ecosystem.config.js
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## API Reference
|
|
124
|
+
|
|
125
|
+
### `TokenManager`
|
|
126
|
+
|
|
127
|
+
The server-side class that manages the token bucket.
|
|
128
|
+
Run this in a separate, single PM2 process.
|
|
129
|
+
|
|
130
|
+
#### `new TokenManager(options?)`
|
|
131
|
+
|
|
132
|
+
| Option | Type | Default | Description |
|
|
133
|
+
| ---------------- | -------- | ------- | ---------------------------------------- |
|
|
134
|
+
| `capacity` | `number` | `100` | Maximum number of tokens in the bucket |
|
|
135
|
+
| `refillRate` | `number` | `10` | Number of tokens added per refill cycle |
|
|
136
|
+
| `refillInterval` | `number` | `1000` | Milliseconds between each refill cycle |
|
|
137
|
+
|
|
138
|
+
#### `tokenManager.start(errCallback?)`
|
|
139
|
+
|
|
140
|
+
Connects to the PM2 bus and starts listening for token requests from cluster instances.
|
|
141
|
+
|
|
142
|
+
- `errCallback` *(optional)* — Called with an `Error` if the PM2 bus connection fails.
|
|
143
|
+
|
|
144
|
+
#### `tokenManager.getStatus()`
|
|
145
|
+
|
|
146
|
+
Returns the current state of the bucket:
|
|
147
|
+
|
|
148
|
+
```js
|
|
149
|
+
{
|
|
150
|
+
tokens: 8, // Current available tokens
|
|
151
|
+
capacity: 10, // Maximum capacity
|
|
152
|
+
refillRate: 1, // Tokens per refill
|
|
153
|
+
refillInterval: 3000 // Refill interval in ms
|
|
154
|
+
}
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
### `TokenClient`
|
|
160
|
+
|
|
161
|
+
The client-side class used within your cluster instances to request tokens.
|
|
162
|
+
|
|
163
|
+
#### `new TokenClient()`
|
|
164
|
+
|
|
165
|
+
Creates a new client and starts listening for responses from the `TokenManager`.
|
|
166
|
+
|
|
167
|
+
#### `tokenClient.consume(amount?)`
|
|
168
|
+
|
|
169
|
+
Requests tokens from the `TokenManager`.
|
|
170
|
+
|
|
171
|
+
| Parameter | Type | Default | Description |
|
|
172
|
+
| --------- | -------- | ------- | ------------------------------- |
|
|
173
|
+
| `amount` | `number` | `1` | Number of tokens to consume |
|
|
174
|
+
|
|
175
|
+
**Returns:** `Promise<boolean>`
|
|
176
|
+
|
|
177
|
+
- `true` — tokens were granted
|
|
178
|
+
- `false` — not enough tokens available (rate limited)
|
|
179
|
+
- `true` *(on timeout)* — if the `TokenManager` doesn't respond within 500ms, the request is allowed as a safety fallback
|
|
180
|
+
|
|
181
|
+
> **Note:** If the process is not running under PM2 (i.e. `process.send` is unavailable), `consume()` always resolves to `true`, making it safe to use in development without PM2.
|
|
182
|
+
|
|
183
|
+
## How It Works
|
|
184
|
+
|
|
185
|
+
1. The TokenManager runs as a standalone PM2 process and holds a token bucket that refills at a configurable rate.
|
|
186
|
+
2. Each TokenClient instance (in your clustered app) sends a token request over PM2's IPC bus.
|
|
187
|
+
3. The TokenManager checks the bucket, deducts tokens if available, and sends back an `allowed` / `denied` response.
|
|
188
|
+
4. The TokenClient resolves its `consume()` promise accordingly.
|
|
189
|
+
|
|
190
|
+
All communication happens through PM2's built-in inter-process messaging — no external dependencies like Redis or HTTP servers required.
|
|
191
|
+
|
|
192
|
+
## Running the Example
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
# Clone the repo and install dependencies
|
|
196
|
+
npm install
|
|
197
|
+
|
|
198
|
+
# Build the TypeScript source
|
|
199
|
+
npm run build
|
|
200
|
+
|
|
201
|
+
# Start the example with PM2 and run a load test
|
|
202
|
+
cd example
|
|
203
|
+
pm2 start ecosystem.config.js
|
|
204
|
+
npx loadtest -n 30 -c 10 http://localhost:3000/
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## License
|
|
208
|
+
|
|
209
|
+
This project is licensed under CC BY-NC-SA.
|
|
210
|
+
|
|
211
|
+

|
package/dist/Bucket.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export default class Bucket {
|
|
2
|
+
private capacity;
|
|
3
|
+
private refillRate;
|
|
4
|
+
private refillInterval;
|
|
5
|
+
private tokens;
|
|
6
|
+
private lastRefill;
|
|
7
|
+
/**
|
|
8
|
+
* Create a new bucket
|
|
9
|
+
* @param capacity - Maximum tokens in the bucket and the initial quantity (ex: 100)
|
|
10
|
+
* @param refillRate - Number of tokens added at each refill (ex: 10)
|
|
11
|
+
* @param refillInterval - Time in milliseconds between each refill (ex: 1000 for 1 second)
|
|
12
|
+
*/
|
|
13
|
+
constructor(capacity: number, refillRate: number, refillInterval: number);
|
|
14
|
+
/**
|
|
15
|
+
* Refill the bucket based on the time elapsed since the last refill
|
|
16
|
+
*/
|
|
17
|
+
private _refill;
|
|
18
|
+
/**
|
|
19
|
+
* Try to remove a certain number of tokens from the bucket
|
|
20
|
+
* @param count - Number of tokens to remove (default: 1)
|
|
21
|
+
* @returns True if the tokens were removed, false otherwise
|
|
22
|
+
*/
|
|
23
|
+
tryRemove(count?: number): boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Get the current number of tokens
|
|
26
|
+
*/
|
|
27
|
+
getTokens(): number;
|
|
28
|
+
/**
|
|
29
|
+
* Get the capacity of the bucket
|
|
30
|
+
*/
|
|
31
|
+
getCapacity(): number;
|
|
32
|
+
/**
|
|
33
|
+
* Get the refill rate
|
|
34
|
+
*/
|
|
35
|
+
getRefillRate(): number;
|
|
36
|
+
/**
|
|
37
|
+
* Get the refill interval
|
|
38
|
+
*/
|
|
39
|
+
getRefillInterval(): number;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=Bucket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Bucket.d.ts","sourceRoot":"","sources":["../src/Bucket.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,OAAO,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,UAAU,CAAS;IAE3B;;;;;OAKG;gBACS,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM;IAQxE;;OAEG;IACH,OAAO,CAAC,OAAO;IAOf;;;;OAIG;IACH,SAAS,CAAC,KAAK,GAAE,MAAU,GAAG,OAAO;IASrC;;OAEG;IACH,SAAS,IAAI,MAAM;IAInB;;OAEG;IACH,WAAW,IAAI,MAAM;IAIrB;;OAEG;IACH,aAAa,IAAI,MAAM;IAIvB;;OAEG;IACH,iBAAiB,IAAI,MAAM;CAG9B"}
|
package/dist/Bucket.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class Bucket {
|
|
4
|
+
/**
|
|
5
|
+
* Create a new bucket
|
|
6
|
+
* @param capacity - Maximum tokens in the bucket and the initial quantity (ex: 100)
|
|
7
|
+
* @param refillRate - Number of tokens added at each refill (ex: 10)
|
|
8
|
+
* @param refillInterval - Time in milliseconds between each refill (ex: 1000 for 1 second)
|
|
9
|
+
*/
|
|
10
|
+
constructor(capacity, refillRate, refillInterval) {
|
|
11
|
+
this.capacity = capacity;
|
|
12
|
+
this.refillRate = refillRate;
|
|
13
|
+
this.refillInterval = refillInterval;
|
|
14
|
+
this.tokens = capacity;
|
|
15
|
+
this.lastRefill = Date.now();
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Refill the bucket based on the time elapsed since the last refill
|
|
19
|
+
*/
|
|
20
|
+
_refill() {
|
|
21
|
+
const now = Date.now();
|
|
22
|
+
const delta = (now - this.lastRefill) / this.refillInterval;
|
|
23
|
+
this.tokens = Math.min(this.capacity, this.tokens + Math.round(delta * this.refillRate));
|
|
24
|
+
this.lastRefill = now;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Try to remove a certain number of tokens from the bucket
|
|
28
|
+
* @param count - Number of tokens to remove (default: 1)
|
|
29
|
+
* @returns True if the tokens were removed, false otherwise
|
|
30
|
+
*/
|
|
31
|
+
tryRemove(count = 1) {
|
|
32
|
+
this._refill();
|
|
33
|
+
if (this.tokens >= count) {
|
|
34
|
+
this.tokens -= count;
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Get the current number of tokens
|
|
41
|
+
*/
|
|
42
|
+
getTokens() {
|
|
43
|
+
return this.tokens;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Get the capacity of the bucket
|
|
47
|
+
*/
|
|
48
|
+
getCapacity() {
|
|
49
|
+
return this.capacity;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Get the refill rate
|
|
53
|
+
*/
|
|
54
|
+
getRefillRate() {
|
|
55
|
+
return this.refillRate;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Get the refill interval
|
|
59
|
+
*/
|
|
60
|
+
getRefillInterval() {
|
|
61
|
+
return this.refillInterval;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.default = Bucket;
|
|
65
|
+
//# sourceMappingURL=Bucket.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Bucket.js","sourceRoot":"","sources":["../src/Bucket.ts"],"names":[],"mappings":";;AAAA,MAAqB,MAAM;IAOvB;;;;;OAKG;IACH,YAAY,QAAgB,EAAE,UAAkB,EAAE,cAAsB;QACpE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC;QACvB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACjC,CAAC;IAED;;OAEG;IACK,OAAO;QACX,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvB,MAAM,KAAK,GAAG,CAAC,GAAG,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,cAAc,CAAC;QAC5D,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;QACzF,IAAI,CAAC,UAAU,GAAG,GAAG,CAAC;IAC1B,CAAC;IAED;;;;OAIG;IACH,SAAS,CAAC,QAAgB,CAAC;QACvB,IAAI,CAAC,OAAO,EAAE,CAAC;QACf,IAAI,IAAI,CAAC,MAAM,IAAI,KAAK,EAAE,CAAC;YACvB,IAAI,CAAC,MAAM,IAAI,KAAK,CAAC;YACrB,OAAO,IAAI,CAAC;QAChB,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;IAED;;OAEG;IACH,SAAS;QACL,OAAO,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,WAAW;QACP,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,aAAa;QACT,OAAO,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,iBAAiB;QACb,OAAO,IAAI,CAAC,cAAc,CAAC;IAC/B,CAAC;CACJ;AAxED,yBAwEC"}
|
package/dist/Client.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TokenClient class that allows PM2 processes to request tokens from the TokenManager
|
|
3
|
+
* running in the PM2 cluster. It handles sending requests and receiving responses
|
|
4
|
+
* asynchronously using Promises.
|
|
5
|
+
*/
|
|
6
|
+
export default class TokenClient {
|
|
7
|
+
private pendingRequests;
|
|
8
|
+
constructor();
|
|
9
|
+
/**
|
|
10
|
+
* Method to consume tokens by sending a request to the TokenManager and returning a Promise
|
|
11
|
+
* @param amount - The number of tokens to consume (default is 1)
|
|
12
|
+
* @returns Resolves to true if tokens are granted, false if denied, or true on timeout/fallback
|
|
13
|
+
*/
|
|
14
|
+
consume(amount?: number): Promise<boolean>;
|
|
15
|
+
/**
|
|
16
|
+
* Listen for responses from the manager and resolve the corresponding promises
|
|
17
|
+
*/
|
|
18
|
+
private _listen;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=Client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Client.d.ts","sourceRoot":"","sources":["../src/Client.ts"],"names":[],"mappings":"AAWA;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,WAAW;IAC5B,OAAO,CAAC,eAAe,CAA2C;;IAOlE;;;;OAIG;IACH,OAAO,CAAC,MAAM,GAAE,MAAU,GAAG,OAAO,CAAC,OAAO,CAAC;IAqC7C;;OAEG;IACH,OAAO,CAAC,OAAO;CAalB"}
|
package/dist/Client.js
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
7
|
+
const config_1 = __importDefault(require("./config"));
|
|
8
|
+
/**
|
|
9
|
+
* TokenClient class that allows PM2 processes to request tokens from the TokenManager
|
|
10
|
+
* running in the PM2 cluster. It handles sending requests and receiving responses
|
|
11
|
+
* asynchronously using Promises.
|
|
12
|
+
*/
|
|
13
|
+
class TokenClient {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.pendingRequests = new Map();
|
|
16
|
+
this._listen();
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Method to consume tokens by sending a request to the TokenManager and returning a Promise
|
|
20
|
+
* @param amount - The number of tokens to consume (default is 1)
|
|
21
|
+
* @returns Resolves to true if tokens are granted, false if denied, or true on timeout/fallback
|
|
22
|
+
*/
|
|
23
|
+
consume(amount = 1) {
|
|
24
|
+
return new Promise((resolve) => {
|
|
25
|
+
// Handle the case where PM2 is not available
|
|
26
|
+
if (!process.send) {
|
|
27
|
+
return resolve(true);
|
|
28
|
+
}
|
|
29
|
+
// Get a unique ID for this request
|
|
30
|
+
const requestID = crypto_1.default.randomUUID();
|
|
31
|
+
// Security timeout to prevent hanging if the token manager doesn't respond
|
|
32
|
+
const timeout = setTimeout(() => {
|
|
33
|
+
console.warn("Request timed out ! ID:", requestID);
|
|
34
|
+
if (this.pendingRequests.has(requestID)) {
|
|
35
|
+
resolve(true);
|
|
36
|
+
this.pendingRequests.delete(requestID);
|
|
37
|
+
}
|
|
38
|
+
}, config_1.default.DEFAULT_TIMEOUT);
|
|
39
|
+
// Store the resolve function in the pendingRequests Map with the request ID
|
|
40
|
+
this.pendingRequests.set(requestID, (response) => {
|
|
41
|
+
clearTimeout(timeout);
|
|
42
|
+
resolve(response);
|
|
43
|
+
});
|
|
44
|
+
// Send a message to the TokenManager with the request details
|
|
45
|
+
process.send({
|
|
46
|
+
type: 'process:msg',
|
|
47
|
+
data: {
|
|
48
|
+
topic: config_1.default.TOPIC_ASK,
|
|
49
|
+
id: requestID,
|
|
50
|
+
amount
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Listen for responses from the manager and resolve the corresponding promises
|
|
57
|
+
*/
|
|
58
|
+
_listen() {
|
|
59
|
+
process.on('message', (packet) => {
|
|
60
|
+
if (packet.data && packet.data.topic === config_1.default.TOPIC_RESPONSE) {
|
|
61
|
+
const requestId = packet.data.id;
|
|
62
|
+
const allowed = packet.data.allowed;
|
|
63
|
+
const resolve = this.pendingRequests.get(requestId);
|
|
64
|
+
if (resolve) {
|
|
65
|
+
resolve(allowed);
|
|
66
|
+
this.pendingRequests.delete(requestId);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.default = TokenClient;
|
|
73
|
+
//# sourceMappingURL=Client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Client.js","sourceRoot":"","sources":["../src/Client.ts"],"names":[],"mappings":";;;;;AAAA,oDAA4B;AAC5B,sDAA8B;AAU9B;;;;GAIG;AACH,MAAqB,WAAW;IAG5B;QACI,IAAI,CAAC,eAAe,GAAG,IAAI,GAAG,EAAE,CAAC;QACjC,IAAI,CAAC,OAAO,EAAE,CAAC;IACnB,CAAC;IAED;;;;OAIG;IACH,OAAO,CAAC,SAAiB,CAAC;QACtB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC3B,6CAA6C;YAC7C,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;gBAChB,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC;YACzB,CAAC;YAED,mCAAmC;YACnC,MAAM,SAAS,GAAG,gBAAM,CAAC,UAAU,EAAE,CAAC;YAEtC,2EAA2E;YAC3E,MAAM,OAAO,GAAG,UAAU,CAAC,GAAG,EAAE;gBAC5B,OAAO,CAAC,IAAI,CAAC,yBAAyB,EAAE,SAAS,CAAC,CAAC;gBACnD,IAAI,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;oBACtC,OAAO,CAAC,IAAI,CAAC,CAAC;oBACd,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;gBAC3C,CAAC;YACL,CAAC,EAAE,gBAAM,CAAC,eAAe,CAAC,CAAC;YAE3B,4EAA4E;YAC5E,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,QAAiB,EAAE,EAAE;gBACtD,YAAY,CAAC,OAAO,CAAC,CAAC;gBACtB,OAAO,CAAC,QAAQ,CAAC,CAAC;YACtB,CAAC,CAAC,CAAC;YAEH,8DAA8D;YAC9D,OAAO,CAAC,IAAI,CAAC;gBACT,IAAI,EAAE,aAAa;gBACnB,IAAI,EAAE;oBACF,KAAK,EAAE,gBAAM,CAAC,SAAS;oBACvB,EAAE,EAAE,SAAS;oBACb,MAAM;iBACT;aACJ,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;OAEG;IACK,OAAO;QACX,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,CAAC,MAAiB,EAAE,EAAE;YACxC,IAAI,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,KAAK,gBAAM,CAAC,cAAc,EAAE,CAAC;gBAC7D,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;gBACjC,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;gBACpC,MAAM,OAAO,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;gBACpD,IAAI,OAAO,EAAE,CAAC;oBACV,OAAO,CAAC,OAAO,CAAC,CAAC;oBACjB,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;gBAC3C,CAAC;YACL,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC;CACJ;AAlED,8BAkEC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
interface TokenManagerOptions {
|
|
2
|
+
/** Maximum tokens in the bucket (default: 100) */
|
|
3
|
+
capacity?: number;
|
|
4
|
+
/** Tokens added per refill (default: 10) */
|
|
5
|
+
refillRate?: number;
|
|
6
|
+
/** Time in milliseconds between each refill (default: 1000) */
|
|
7
|
+
refillInterval?: number;
|
|
8
|
+
}
|
|
9
|
+
interface BucketStatus {
|
|
10
|
+
tokens: number;
|
|
11
|
+
capacity: number;
|
|
12
|
+
refillRate: number;
|
|
13
|
+
refillInterval: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* TokenManager class that manages the token bucket and handles communication with PM2 processes
|
|
17
|
+
*/
|
|
18
|
+
export default class TokenManager {
|
|
19
|
+
private bucket;
|
|
20
|
+
constructor(options?: TokenManagerOptions);
|
|
21
|
+
/**
|
|
22
|
+
* Start the TokenManager and connect to PM2 bus to listen for token requests
|
|
23
|
+
* @param errCallback - Optional callback for handling connection errors
|
|
24
|
+
*/
|
|
25
|
+
start(errCallback?: (err: Error) => void): void;
|
|
26
|
+
/**
|
|
27
|
+
* Handle incoming messages from PM2 processes
|
|
28
|
+
*/
|
|
29
|
+
private _handleMessage;
|
|
30
|
+
/**
|
|
31
|
+
* Send a response back to the requesting process in the PM2 cluster
|
|
32
|
+
*/
|
|
33
|
+
private _sendResponse;
|
|
34
|
+
/**
|
|
35
|
+
* Get the current status of the token bucket
|
|
36
|
+
*/
|
|
37
|
+
getStatus(): BucketStatus;
|
|
38
|
+
}
|
|
39
|
+
export {};
|
|
40
|
+
//# sourceMappingURL=Manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Manager.d.ts","sourceRoot":"","sources":["../src/Manager.ts"],"names":[],"mappings":"AAIA,UAAU,mBAAmB;IACzB,kDAAkD;IAClD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,4CAA4C;IAC5C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,+DAA+D;IAC/D,cAAc,CAAC,EAAE,MAAM,CAAC;CAC3B;AAaD,UAAU,YAAY;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,YAAY;IAC7B,OAAO,CAAC,MAAM,CAAS;gBAEX,OAAO,GAAE,mBAAwB;IAQ7C;;;OAGG;IACH,KAAK,CAAC,WAAW,CAAC,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,IAAI,GAAG,IAAI;IAa/C;;OAEG;IACH,OAAO,CAAC,cAAc;IAStB;;OAEG;IACH,OAAO,CAAC,aAAa;IAiBrB;;OAEG;IACH,SAAS,IAAI,YAAY;CAQ5B"}
|
package/dist/Manager.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const pm2_1 = __importDefault(require("pm2"));
|
|
7
|
+
const Bucket_1 = __importDefault(require("./Bucket"));
|
|
8
|
+
const config_1 = __importDefault(require("./config"));
|
|
9
|
+
/**
|
|
10
|
+
* TokenManager class that manages the token bucket and handles communication with PM2 processes
|
|
11
|
+
*/
|
|
12
|
+
class TokenManager {
|
|
13
|
+
constructor(options = {}) {
|
|
14
|
+
this.bucket = new Bucket_1.default(options.capacity ?? config_1.default.DEFAULT_CAPACITY, options.refillRate ?? config_1.default.DEFAULT_REFILL_RATE, options.refillInterval ?? config_1.default.DEFAULT_REFILL_INTERVAL);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Start the TokenManager and connect to PM2 bus to listen for token requests
|
|
18
|
+
* @param errCallback - Optional callback for handling connection errors
|
|
19
|
+
*/
|
|
20
|
+
start(errCallback) {
|
|
21
|
+
pm2_1.default.launchBus((err, bus) => {
|
|
22
|
+
if (err) {
|
|
23
|
+
if (errCallback)
|
|
24
|
+
errCallback(err);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
bus.on('process:msg', (packet) => {
|
|
28
|
+
this._handleMessage(packet);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Handle incoming messages from PM2 processes
|
|
34
|
+
*/
|
|
35
|
+
_handleMessage(packet) {
|
|
36
|
+
if (packet.data.topic === config_1.default.TOPIC_ASK) {
|
|
37
|
+
const requestId = packet.data.id;
|
|
38
|
+
const amount = packet.data.amount || 1;
|
|
39
|
+
const allowed = this.bucket.tryRemove(amount);
|
|
40
|
+
this._sendResponse(packet.process.pm_id, requestId, allowed);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Send a response back to the requesting process in the PM2 cluster
|
|
45
|
+
*/
|
|
46
|
+
_sendResponse(processId, requestId, allowed) {
|
|
47
|
+
pm2_1.default.sendDataToProcessId(processId, {
|
|
48
|
+
id: processId,
|
|
49
|
+
type: 'process:msg',
|
|
50
|
+
topic: config_1.default.TOPIC_RESPONSE,
|
|
51
|
+
data: {
|
|
52
|
+
topic: config_1.default.TOPIC_RESPONSE,
|
|
53
|
+
id: requestId,
|
|
54
|
+
allowed: allowed
|
|
55
|
+
}
|
|
56
|
+
}, (err) => {
|
|
57
|
+
if (err) {
|
|
58
|
+
console.error('[PM2 Token Bucket] send response error', err);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Get the current status of the token bucket
|
|
64
|
+
*/
|
|
65
|
+
getStatus() {
|
|
66
|
+
return {
|
|
67
|
+
tokens: this.bucket.getTokens(),
|
|
68
|
+
capacity: this.bucket.getCapacity(),
|
|
69
|
+
refillRate: this.bucket.getRefillRate(),
|
|
70
|
+
refillInterval: this.bucket.getRefillInterval()
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.default = TokenManager;
|
|
75
|
+
//# sourceMappingURL=Manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Manager.js","sourceRoot":"","sources":["../src/Manager.ts"],"names":[],"mappings":";;;;;AAAA,8CAAsB;AACtB,sDAA8B;AAC9B,sDAA8B;AA6B9B;;GAEG;AACH,MAAqB,YAAY;IAG7B,YAAY,UAA+B,EAAE;QACzC,IAAI,CAAC,MAAM,GAAG,IAAI,gBAAM,CACpB,OAAO,CAAC,QAAQ,IAAI,gBAAM,CAAC,gBAAgB,EAC3C,OAAO,CAAC,UAAU,IAAI,gBAAM,CAAC,mBAAmB,EAChD,OAAO,CAAC,cAAc,IAAI,gBAAM,CAAC,uBAAuB,CAC3D,CAAC;IACN,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,WAAkC;QACpC,aAAG,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;YACvB,IAAI,GAAG,EAAE,CAAC;gBACN,IAAI,WAAW;oBAAE,WAAW,CAAC,GAAG,CAAC,CAAC;gBAClC,OAAO;YACX,CAAC;YAED,GAAG,CAAC,EAAE,CAAC,aAAa,EAAE,CAAC,MAAoB,EAAE,EAAE;gBAC3C,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;YAChC,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;OAEG;IACK,cAAc,CAAC,MAAoB;QACvC,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,KAAK,gBAAM,CAAC,SAAS,EAAE,CAAC;YACzC,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;YACjC,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC;YACvC,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;YAC9C,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;QACjE,CAAC;IACL,CAAC;IAED;;OAEG;IACK,aAAa,CAAC,SAAiB,EAAE,SAAiB,EAAE,OAAgB;QACxE,aAAG,CAAC,mBAAmB,CAAC,SAAS,EAAE;YAC/B,EAAE,EAAE,SAAS;YACb,IAAI,EAAE,aAAa;YACnB,KAAK,EAAE,gBAAM,CAAC,cAAc;YAC5B,IAAI,EAAE;gBACF,KAAK,EAAE,gBAAM,CAAC,cAAc;gBAC5B,EAAE,EAAE,SAAS;gBACb,OAAO,EAAE,OAAO;aACnB;SACG,EAAE,CAAC,GAAG,EAAE,EAAE;YACd,IAAI,GAAG,EAAE,CAAC;gBACN,OAAO,CAAC,KAAK,CAAC,wCAAwC,EAAE,GAAG,CAAC,CAAC;YACjE,CAAC;QACL,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;OAEG;IACH,SAAS;QACL,OAAO;YACH,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE;YAC/B,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE;YACnC,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE;YACvC,cAAc,EAAE,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE;SAClD,CAAC;IACN,CAAC;CACJ;AAvED,+BAuEC"}
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
TOPIC_ASK: string;
|
|
3
|
+
TOPIC_RESPONSE: string;
|
|
4
|
+
DEFAULT_CAPACITY: number;
|
|
5
|
+
DEFAULT_REFILL_RATE: number;
|
|
6
|
+
DEFAULT_REFILL_INTERVAL: number;
|
|
7
|
+
DEFAULT_TIMEOUT: number;
|
|
8
|
+
};
|
|
9
|
+
export default _default;
|
|
10
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;;;;;;AAEA,wBAOE"}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const TOPIC_PREFIX = 'pm2TokenBucket';
|
|
4
|
+
exports.default = {
|
|
5
|
+
TOPIC_ASK: `${TOPIC_PREFIX}:ask`,
|
|
6
|
+
TOPIC_RESPONSE: `${TOPIC_PREFIX}:response`,
|
|
7
|
+
DEFAULT_CAPACITY: 100,
|
|
8
|
+
DEFAULT_REFILL_RATE: 10,
|
|
9
|
+
DEFAULT_REFILL_INTERVAL: 1000,
|
|
10
|
+
DEFAULT_TIMEOUT: 500,
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;AAAA,MAAM,YAAY,GAAG,gBAAgB,CAAC;AAEtC,kBAAe;IACX,SAAS,EAAE,GAAG,YAAY,MAAM;IAChC,cAAc,EAAE,GAAG,YAAY,WAAW;IAC1C,gBAAgB,EAAE,GAAG;IACrB,mBAAmB,EAAE,EAAE;IACvB,uBAAuB,EAAE,IAAI;IAC7B,eAAe,EAAE,GAAG;CACvB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,MAAM,UAAU,CAAC;AACnC,OAAO,YAAY,MAAM,WAAW,CAAC;AAErC,OAAO,EAAC,WAAW,EAAE,YAAY,EAAC,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.TokenManager = exports.TokenClient = void 0;
|
|
7
|
+
const Client_1 = __importDefault(require("./Client"));
|
|
8
|
+
exports.TokenClient = Client_1.default;
|
|
9
|
+
const Manager_1 = __importDefault(require("./Manager"));
|
|
10
|
+
exports.TokenManager = Manager_1.default;
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,sDAAmC;AAG3B,sBAHD,gBAAW,CAGC;AAFnB,wDAAqC;AAEhB,uBAFd,iBAAY,CAEc"}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "pm2-token-bucket",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Token bucket server for API throttling shared between instances using PM2 clusters.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/Higink/pm2-token-bucket"
|
|
8
|
+
},
|
|
9
|
+
"license": "CC BY-NC-SA",
|
|
10
|
+
"author": "Higink <higink@gmail.com>",
|
|
11
|
+
"keywords": [
|
|
12
|
+
"token bucket",
|
|
13
|
+
"rate limiting",
|
|
14
|
+
"API throttling",
|
|
15
|
+
"PM2",
|
|
16
|
+
"PM2 clusters"
|
|
17
|
+
],
|
|
18
|
+
"main": "dist/index.js",
|
|
19
|
+
"types": "dist/index.d.ts",
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"build": "tsc",
|
|
25
|
+
"test": "jest",
|
|
26
|
+
"prepublishOnly": "npm run build && npm test",
|
|
27
|
+
"example": "npm install && npm run build && cd example && pm2 start && loadtest -n 30 -c 10 http://localhost:3000/ && pm2 logs"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/jest": "^30.0.0",
|
|
31
|
+
"@types/node": "^22.0.0",
|
|
32
|
+
"express": "^5.2.1",
|
|
33
|
+
"ts-jest": "^29.4.6",
|
|
34
|
+
"jest": "^30.2.0",
|
|
35
|
+
"loadtest": "^8.2.1",
|
|
36
|
+
"typescript": "^5.9.3"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"pm2": "^6.0.0"
|
|
40
|
+
}
|
|
41
|
+
}
|