@gitbeaker/requester-utils 43.3.0 → 43.4.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 +1 -0
- package/dist/index.d.mts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +10 -5
- package/dist/index.mjs +10 -5
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -228,6 +228,7 @@ import { RequesterUtils, BaseResource } from '@gitbeaker/requester-utils';
|
|
|
228
228
|
<td align="center" valign="top" width="0.33%"><a href="https://note.itswhat.me/"><img src="https://images.weserv.nl/?url=https://avatars.githubusercontent.com/u/38807139?v=4&h=25&w=25&fit=cover&mask=circle&maxage=7d" alt="Bryan Lee"/></td>
|
|
229
229
|
<td align="center" valign="top" width="0.33%"><a href="https://github.com/zk-kb4"><img src="https://images.weserv.nl/?url=https://avatars.githubusercontent.com/u/42388953?v=4&h=25&w=25&fit=cover&mask=circle&maxage=7d" alt="Zack"/></td>
|
|
230
230
|
<td align="center" valign="top" width="0.33%"><a href="https://github.com/kayw-geek"><img src="https://images.weserv.nl/?url=https://avatars.githubusercontent.com/u/29700073?v=4&h=25&w=25&fit=cover&mask=circle&maxage=7d" alt="Kay W."/></td>
|
|
231
|
+
<td align="center" valign="top" width="0.33%"><a href="https://ffflorian.dev/"><img src="https://images.weserv.nl/?url=https://avatars.githubusercontent.com/u/5497598?v=4&h=25&w=25&fit=cover&mask=circle&maxage=7d" alt="Florian Imdahl"/></td>
|
|
231
232
|
</tr>
|
|
232
233
|
</p>
|
|
233
234
|
|
package/dist/index.d.mts
CHANGED
|
@@ -26,6 +26,7 @@ type ResourceOptions = {
|
|
|
26
26
|
url: string;
|
|
27
27
|
rejectUnauthorized: boolean;
|
|
28
28
|
rateLimits?: RateLimitOptions;
|
|
29
|
+
rateLimitDuration?: number;
|
|
29
30
|
};
|
|
30
31
|
type DefaultRequestOptions = {
|
|
31
32
|
body?: FormData | Record<string, unknown>;
|
|
@@ -58,7 +59,7 @@ declare function generateRateLimiterFn(limit: number, interval: number): () => P
|
|
|
58
59
|
declare function formatQuery(params?: Record<string, unknown>): string;
|
|
59
60
|
type OptionsHandlerFn = (serviceOptions: ResourceOptions, requestOptions: RequestOptions) => Promise<RequestOptions>;
|
|
60
61
|
declare function defaultOptionsHandler(resourceOptions: ResourceOptions, { body, searchParams, sudo, signal, asStream, method, }?: DefaultRequestOptions): Promise<RequestOptions>;
|
|
61
|
-
declare function createRateLimiters(rateLimitOptions?: RateLimitOptions): RateLimiters;
|
|
62
|
+
declare function createRateLimiters(rateLimitOptions?: RateLimitOptions, rateLimitDuration?: number): RateLimiters;
|
|
62
63
|
declare function createRequesterFn(optionsHandler: OptionsHandlerFn, requestHandler: RequestHandlerFn): (serviceOptions: ResourceOptions) => RequesterType;
|
|
63
64
|
declare function presetResourceArguments<T extends Record<string, Constructable>>(resources: T, customConfig?: Record<string, unknown>): T;
|
|
64
65
|
declare function getMatchingRateLimiter(endpoint: string, rateLimiters?: RateLimiters, method?: string): RateLimiterFn;
|
|
@@ -70,6 +71,7 @@ interface RootResourceOptions<C> {
|
|
|
70
71
|
rejectUnauthorized?: boolean;
|
|
71
72
|
camelize?: C;
|
|
72
73
|
queryTimeout?: number | null;
|
|
74
|
+
rateLimitDuration?: number;
|
|
73
75
|
sudo?: string | number;
|
|
74
76
|
profileToken?: string;
|
|
75
77
|
profileMode?: 'execution' | 'memory';
|
|
@@ -100,7 +102,7 @@ declare class BaseResource<C extends boolean = false> {
|
|
|
100
102
|
};
|
|
101
103
|
readonly camelize: C | undefined;
|
|
102
104
|
readonly rejectUnauthorized: boolean;
|
|
103
|
-
constructor({ sudo, profileToken, camelize, requesterFn, profileMode, host, prefixUrl, rejectUnauthorized, queryTimeout, rateLimits, ...tokens }: BaseResourceOptions<C>);
|
|
105
|
+
constructor({ sudo, profileToken, camelize, requesterFn, profileMode, host, prefixUrl, rejectUnauthorized, queryTimeout, rateLimitDuration, rateLimits, ...tokens }: BaseResourceOptions<C>);
|
|
104
106
|
}
|
|
105
107
|
|
|
106
108
|
declare class GitbeakerRequestError extends Error {
|
package/dist/index.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ type ResourceOptions = {
|
|
|
26
26
|
url: string;
|
|
27
27
|
rejectUnauthorized: boolean;
|
|
28
28
|
rateLimits?: RateLimitOptions;
|
|
29
|
+
rateLimitDuration?: number;
|
|
29
30
|
};
|
|
30
31
|
type DefaultRequestOptions = {
|
|
31
32
|
body?: FormData | Record<string, unknown>;
|
|
@@ -58,7 +59,7 @@ declare function generateRateLimiterFn(limit: number, interval: number): () => P
|
|
|
58
59
|
declare function formatQuery(params?: Record<string, unknown>): string;
|
|
59
60
|
type OptionsHandlerFn = (serviceOptions: ResourceOptions, requestOptions: RequestOptions) => Promise<RequestOptions>;
|
|
60
61
|
declare function defaultOptionsHandler(resourceOptions: ResourceOptions, { body, searchParams, sudo, signal, asStream, method, }?: DefaultRequestOptions): Promise<RequestOptions>;
|
|
61
|
-
declare function createRateLimiters(rateLimitOptions?: RateLimitOptions): RateLimiters;
|
|
62
|
+
declare function createRateLimiters(rateLimitOptions?: RateLimitOptions, rateLimitDuration?: number): RateLimiters;
|
|
62
63
|
declare function createRequesterFn(optionsHandler: OptionsHandlerFn, requestHandler: RequestHandlerFn): (serviceOptions: ResourceOptions) => RequesterType;
|
|
63
64
|
declare function presetResourceArguments<T extends Record<string, Constructable>>(resources: T, customConfig?: Record<string, unknown>): T;
|
|
64
65
|
declare function getMatchingRateLimiter(endpoint: string, rateLimiters?: RateLimiters, method?: string): RateLimiterFn;
|
|
@@ -70,6 +71,7 @@ interface RootResourceOptions<C> {
|
|
|
70
71
|
rejectUnauthorized?: boolean;
|
|
71
72
|
camelize?: C;
|
|
72
73
|
queryTimeout?: number | null;
|
|
74
|
+
rateLimitDuration?: number;
|
|
73
75
|
sudo?: string | number;
|
|
74
76
|
profileToken?: string;
|
|
75
77
|
profileMode?: 'execution' | 'memory';
|
|
@@ -100,7 +102,7 @@ declare class BaseResource<C extends boolean = false> {
|
|
|
100
102
|
};
|
|
101
103
|
readonly camelize: C | undefined;
|
|
102
104
|
readonly rejectUnauthorized: boolean;
|
|
103
|
-
constructor({ sudo, profileToken, camelize, requesterFn, profileMode, host, prefixUrl, rejectUnauthorized, queryTimeout, rateLimits, ...tokens }: BaseResourceOptions<C>);
|
|
105
|
+
constructor({ sudo, profileToken, camelize, requesterFn, profileMode, host, prefixUrl, rejectUnauthorized, queryTimeout, rateLimitDuration, rateLimits, ...tokens }: BaseResourceOptions<C>);
|
|
104
106
|
}
|
|
105
107
|
|
|
106
108
|
declare class GitbeakerRequestError extends Error {
|
package/dist/index.js
CHANGED
|
@@ -54,14 +54,15 @@ async function defaultOptionsHandler(resourceOptions, {
|
|
|
54
54
|
if (q) defaultOptions.searchParams = q;
|
|
55
55
|
return Promise.resolve(defaultOptions);
|
|
56
56
|
}
|
|
57
|
-
function createRateLimiters(rateLimitOptions = {}) {
|
|
57
|
+
function createRateLimiters(rateLimitOptions = {}, rateLimitDuration = 60) {
|
|
58
58
|
const rateLimiters = {};
|
|
59
59
|
Object.entries(rateLimitOptions).forEach(([key, config]) => {
|
|
60
|
-
if (typeof config === "number")
|
|
60
|
+
if (typeof config === "number")
|
|
61
|
+
rateLimiters[key] = generateRateLimiterFn(config, rateLimitDuration);
|
|
61
62
|
else
|
|
62
63
|
rateLimiters[key] = {
|
|
63
64
|
method: config.method.toUpperCase(),
|
|
64
|
-
limit: generateRateLimiterFn(config.limit,
|
|
65
|
+
limit: generateRateLimiterFn(config.limit, rateLimitDuration)
|
|
65
66
|
};
|
|
66
67
|
});
|
|
67
68
|
return rateLimiters;
|
|
@@ -70,7 +71,10 @@ function createRequesterFn(optionsHandler, requestHandler) {
|
|
|
70
71
|
const methods = ["get", "post", "put", "patch", "delete"];
|
|
71
72
|
return (serviceOptions) => {
|
|
72
73
|
const requester = {};
|
|
73
|
-
const rateLimiters = createRateLimiters(
|
|
74
|
+
const rateLimiters = createRateLimiters(
|
|
75
|
+
serviceOptions.rateLimits,
|
|
76
|
+
serviceOptions.rateLimitDuration
|
|
77
|
+
);
|
|
74
78
|
methods.forEach((m) => {
|
|
75
79
|
requester[m] = async (endpoint, options) => {
|
|
76
80
|
const defaultRequestOptions = await defaultOptionsHandler(serviceOptions, {
|
|
@@ -167,6 +171,7 @@ var BaseResource = class {
|
|
|
167
171
|
prefixUrl = "",
|
|
168
172
|
rejectUnauthorized = true,
|
|
169
173
|
queryTimeout = 3e5,
|
|
174
|
+
rateLimitDuration = 60,
|
|
170
175
|
rateLimits = DEFAULT_RATE_LIMITS,
|
|
171
176
|
...tokens
|
|
172
177
|
}) {
|
|
@@ -191,7 +196,7 @@ var BaseResource = class {
|
|
|
191
196
|
this.headers["X-Profile-Mode"] = profileMode;
|
|
192
197
|
}
|
|
193
198
|
if (sudo) this.headers.Sudo = `${sudo}`;
|
|
194
|
-
this.requester = requesterFn({ ...this, rateLimits });
|
|
199
|
+
this.requester = requesterFn({ ...this, rateLimits, rateLimitDuration });
|
|
195
200
|
}
|
|
196
201
|
};
|
|
197
202
|
|
package/dist/index.mjs
CHANGED
|
@@ -48,14 +48,15 @@ async function defaultOptionsHandler(resourceOptions, {
|
|
|
48
48
|
if (q) defaultOptions.searchParams = q;
|
|
49
49
|
return Promise.resolve(defaultOptions);
|
|
50
50
|
}
|
|
51
|
-
function createRateLimiters(rateLimitOptions = {}) {
|
|
51
|
+
function createRateLimiters(rateLimitOptions = {}, rateLimitDuration = 60) {
|
|
52
52
|
const rateLimiters = {};
|
|
53
53
|
Object.entries(rateLimitOptions).forEach(([key, config]) => {
|
|
54
|
-
if (typeof config === "number")
|
|
54
|
+
if (typeof config === "number")
|
|
55
|
+
rateLimiters[key] = generateRateLimiterFn(config, rateLimitDuration);
|
|
55
56
|
else
|
|
56
57
|
rateLimiters[key] = {
|
|
57
58
|
method: config.method.toUpperCase(),
|
|
58
|
-
limit: generateRateLimiterFn(config.limit,
|
|
59
|
+
limit: generateRateLimiterFn(config.limit, rateLimitDuration)
|
|
59
60
|
};
|
|
60
61
|
});
|
|
61
62
|
return rateLimiters;
|
|
@@ -64,7 +65,10 @@ function createRequesterFn(optionsHandler, requestHandler) {
|
|
|
64
65
|
const methods = ["get", "post", "put", "patch", "delete"];
|
|
65
66
|
return (serviceOptions) => {
|
|
66
67
|
const requester = {};
|
|
67
|
-
const rateLimiters = createRateLimiters(
|
|
68
|
+
const rateLimiters = createRateLimiters(
|
|
69
|
+
serviceOptions.rateLimits,
|
|
70
|
+
serviceOptions.rateLimitDuration
|
|
71
|
+
);
|
|
68
72
|
methods.forEach((m) => {
|
|
69
73
|
requester[m] = async (endpoint, options) => {
|
|
70
74
|
const defaultRequestOptions = await defaultOptionsHandler(serviceOptions, {
|
|
@@ -161,6 +165,7 @@ var BaseResource = class {
|
|
|
161
165
|
prefixUrl = "",
|
|
162
166
|
rejectUnauthorized = true,
|
|
163
167
|
queryTimeout = 3e5,
|
|
168
|
+
rateLimitDuration = 60,
|
|
164
169
|
rateLimits = DEFAULT_RATE_LIMITS,
|
|
165
170
|
...tokens
|
|
166
171
|
}) {
|
|
@@ -185,7 +190,7 @@ var BaseResource = class {
|
|
|
185
190
|
this.headers["X-Profile-Mode"] = profileMode;
|
|
186
191
|
}
|
|
187
192
|
if (sudo) this.headers.Sudo = `${sudo}`;
|
|
188
|
-
this.requester = requesterFn({ ...this, rateLimits });
|
|
193
|
+
this.requester = requesterFn({ ...this, rateLimits, rateLimitDuration });
|
|
189
194
|
}
|
|
190
195
|
};
|
|
191
196
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gitbeaker/requester-utils",
|
|
3
|
-
"version": "43.
|
|
3
|
+
"version": "43.4.0",
|
|
4
4
|
"description": "Utility functions for requester implementatons used in @gitbeaker",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"engines": {
|
|
@@ -53,9 +53,9 @@
|
|
|
53
53
|
"xcase": "^2.0.1"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@types/node": "^24.0
|
|
56
|
+
"@types/node": "^24.2.0",
|
|
57
57
|
"tsup": "^8.5.0",
|
|
58
|
-
"typescript": "^5.
|
|
58
|
+
"typescript": "^5.9.2"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "dd8aa38674dba292815eb8cba325b08b2680936f"
|
|
61
61
|
}
|