@gitbeaker/requester-utils 40.0.3 → 40.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/README.md +1 -0
- package/dist/index.d.mts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +10 -17
- package/dist/index.mjs +10 -17
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -214,6 +214,7 @@ import { RequesterUtils, BaseResource } from '@gitbeaker/requester-utils';
|
|
|
214
214
|
<td align="center" valign="top" width="0.33%"><a href="https://github.com/elaine-mattos"><img src="https://images.weserv.nl/?url=https://avatars.githubusercontent.com/u/79633988?v=4&h=25&w=25&fit=cover&mask=circle&maxage=7d" alt="Elaine Mattos"/></td>
|
|
215
215
|
<td align="center" valign="top" width="0.33%"><a href="https://github.com/vitamindck"><img src="https://images.weserv.nl/?url=https://avatars.githubusercontent.com/u/10766587?v=4&h=25&w=25&fit=cover&mask=circle&maxage=7d" alt="DK"/></td>
|
|
216
216
|
<td align="center" valign="top" width="0.33%"><a href="http://www.koenbrouwer.com/"><img src="https://images.weserv.nl/?url=https://avatars.githubusercontent.com/u/3260168?v=4&h=25&w=25&fit=cover&mask=circle&maxage=7d" alt="Koen Brouwer"/></td>
|
|
217
|
+
<td align="center" valign="top" width="0.33%"><a href="https://scrumplex.net/"><img src="https://images.weserv.nl/?url=https://avatars.githubusercontent.com/u/11587657?v=4&h=25&w=25&fit=cover&mask=circle&maxage=7d" alt="Sefa Eyeoglu"/></td>
|
|
217
218
|
</tr>
|
|
218
219
|
</p>
|
|
219
220
|
|
package/dist/index.d.mts
CHANGED
|
@@ -85,7 +85,9 @@ interface BaseRequestOptionsWithAccessToken<C> extends RootResourceOptions<C> {
|
|
|
85
85
|
interface BaseRequestOptionsWithJobToken<C> extends RootResourceOptions<C> {
|
|
86
86
|
jobToken: GitlabToken;
|
|
87
87
|
}
|
|
88
|
-
|
|
88
|
+
interface BaseRequestOptionsWithoutToken<C> extends RootResourceOptions<C> {
|
|
89
|
+
}
|
|
90
|
+
type BaseResourceOptions<C> = BaseRequestOptionsWithoutToken<C> | BaseRequestOptionsWithOAuthToken<C> | BaseRequestOptionsWithAccessToken<C> | BaseRequestOptionsWithJobToken<C>;
|
|
89
91
|
declare class BaseResource<C extends boolean = false> {
|
|
90
92
|
readonly url: string;
|
|
91
93
|
readonly requester: RequesterType;
|
|
@@ -122,4 +124,4 @@ declare class GitbeakerRetryError extends Error {
|
|
|
122
124
|
constructor(message: string, options?: ErrorOptions);
|
|
123
125
|
}
|
|
124
126
|
|
|
125
|
-
export { type BaseRequestOptionsWithAccessToken, type BaseRequestOptionsWithJobToken, type BaseRequestOptionsWithOAuthToken, BaseResource, type BaseResourceOptions, type Constructable, type DefaultRequestOptions, type FormattedResponse, GitbeakerRequestError, GitbeakerRetryError, GitbeakerTimeoutError, type GitlabToken, type OptionsHandlerFn, type RateLimitOptions, type RateLimiterFn, type RateLimiters, type RequestHandlerFn, type RequestOptions, type RequesterType, type ResourceOptions, type ResponseBodyTypes, type RootResourceOptions, createRateLimiters, createRequesterFn, defaultOptionsHandler, formatQuery, generateRateLimiterFn, getMatchingRateLimiter, presetResourceArguments };
|
|
127
|
+
export { type BaseRequestOptionsWithAccessToken, type BaseRequestOptionsWithJobToken, type BaseRequestOptionsWithOAuthToken, type BaseRequestOptionsWithoutToken, BaseResource, type BaseResourceOptions, type Constructable, type DefaultRequestOptions, type FormattedResponse, GitbeakerRequestError, GitbeakerRetryError, GitbeakerTimeoutError, type GitlabToken, type OptionsHandlerFn, type RateLimitOptions, type RateLimiterFn, type RateLimiters, type RequestHandlerFn, type RequestOptions, type RequesterType, type ResourceOptions, type ResponseBodyTypes, type RootResourceOptions, createRateLimiters, createRequesterFn, defaultOptionsHandler, formatQuery, generateRateLimiterFn, getMatchingRateLimiter, presetResourceArguments };
|
package/dist/index.d.ts
CHANGED
|
@@ -85,7 +85,9 @@ interface BaseRequestOptionsWithAccessToken<C> extends RootResourceOptions<C> {
|
|
|
85
85
|
interface BaseRequestOptionsWithJobToken<C> extends RootResourceOptions<C> {
|
|
86
86
|
jobToken: GitlabToken;
|
|
87
87
|
}
|
|
88
|
-
|
|
88
|
+
interface BaseRequestOptionsWithoutToken<C> extends RootResourceOptions<C> {
|
|
89
|
+
}
|
|
90
|
+
type BaseResourceOptions<C> = BaseRequestOptionsWithoutToken<C> | BaseRequestOptionsWithOAuthToken<C> | BaseRequestOptionsWithAccessToken<C> | BaseRequestOptionsWithJobToken<C>;
|
|
89
91
|
declare class BaseResource<C extends boolean = false> {
|
|
90
92
|
readonly url: string;
|
|
91
93
|
readonly requester: RequesterType;
|
|
@@ -122,4 +124,4 @@ declare class GitbeakerRetryError extends Error {
|
|
|
122
124
|
constructor(message: string, options?: ErrorOptions);
|
|
123
125
|
}
|
|
124
126
|
|
|
125
|
-
export { type BaseRequestOptionsWithAccessToken, type BaseRequestOptionsWithJobToken, type BaseRequestOptionsWithOAuthToken, BaseResource, type BaseResourceOptions, type Constructable, type DefaultRequestOptions, type FormattedResponse, GitbeakerRequestError, GitbeakerRetryError, GitbeakerTimeoutError, type GitlabToken, type OptionsHandlerFn, type RateLimitOptions, type RateLimiterFn, type RateLimiters, type RequestHandlerFn, type RequestOptions, type RequesterType, type ResourceOptions, type ResponseBodyTypes, type RootResourceOptions, createRateLimiters, createRequesterFn, defaultOptionsHandler, formatQuery, generateRateLimiterFn, getMatchingRateLimiter, presetResourceArguments };
|
|
127
|
+
export { type BaseRequestOptionsWithAccessToken, type BaseRequestOptionsWithJobToken, type BaseRequestOptionsWithOAuthToken, type BaseRequestOptionsWithoutToken, BaseResource, type BaseResourceOptions, type Constructable, type DefaultRequestOptions, type FormattedResponse, GitbeakerRequestError, GitbeakerRetryError, GitbeakerTimeoutError, type GitlabToken, type OptionsHandlerFn, type RateLimitOptions, type RateLimiterFn, type RateLimiters, type RequestHandlerFn, type RequestOptions, type RequesterType, type ResourceOptions, type ResponseBodyTypes, type RootResourceOptions, createRateLimiters, createRequesterFn, defaultOptionsHandler, formatQuery, generateRateLimiterFn, getMatchingRateLimiter, presetResourceArguments };
|
package/dist/index.js
CHANGED
|
@@ -37,8 +37,7 @@ async function defaultOptionsHandler(resourceOptions, {
|
|
|
37
37
|
prefixUrl: url
|
|
38
38
|
};
|
|
39
39
|
defaultOptions.headers = { ...preconfiguredHeaders };
|
|
40
|
-
if (sudo)
|
|
41
|
-
defaultOptions.headers.sudo = `${sudo}`;
|
|
40
|
+
if (sudo) defaultOptions.headers.sudo = `${sudo}`;
|
|
42
41
|
if (body) {
|
|
43
42
|
if (body instanceof FormData) {
|
|
44
43
|
defaultOptions.body = body;
|
|
@@ -47,18 +46,18 @@ async function defaultOptionsHandler(resourceOptions, {
|
|
|
47
46
|
defaultOptions.headers["content-type"] = "application/json";
|
|
48
47
|
}
|
|
49
48
|
}
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
if (Object.keys(authHeaders).length > 0) {
|
|
50
|
+
const [authHeaderKey, authHeaderFn] = Object.entries(authHeaders)[0];
|
|
51
|
+
defaultOptions.headers[authHeaderKey] = await authHeaderFn();
|
|
52
|
+
}
|
|
52
53
|
const q = formatQuery(searchParams);
|
|
53
|
-
if (q)
|
|
54
|
-
defaultOptions.searchParams = q;
|
|
54
|
+
if (q) defaultOptions.searchParams = q;
|
|
55
55
|
return Promise.resolve(defaultOptions);
|
|
56
56
|
}
|
|
57
57
|
function createRateLimiters(rateLimitOptions = {}) {
|
|
58
58
|
const rateLimiters = {};
|
|
59
59
|
Object.entries(rateLimitOptions).forEach(([key, config]) => {
|
|
60
|
-
if (typeof config === "number")
|
|
61
|
-
rateLimiters[key] = generateRateLimiterFn(config, 60);
|
|
60
|
+
if (typeof config === "number") rateLimiters[key] = generateRateLimiterFn(config, 60);
|
|
62
61
|
else
|
|
63
62
|
rateLimiters[key] = {
|
|
64
63
|
method: config.method.toUpperCase(),
|
|
@@ -104,8 +103,7 @@ function getMatchingRateLimiter(endpoint, rateLimiters = {}, method = "GET") {
|
|
|
104
103
|
const sortedEndpoints = Object.keys(rateLimiters).sort().reverse();
|
|
105
104
|
const match = sortedEndpoints.find((ep) => isGlobMatch(endpoint, ep));
|
|
106
105
|
const rateLimitConfig = match && rateLimiters[match];
|
|
107
|
-
if (typeof rateLimitConfig === "function")
|
|
108
|
-
return rateLimitConfig;
|
|
106
|
+
if (typeof rateLimitConfig === "function") return rateLimitConfig;
|
|
109
107
|
if (rateLimitConfig && rateLimitConfig?.method?.toUpperCase() === method.toUpperCase()) {
|
|
110
108
|
return rateLimitConfig.limit;
|
|
111
109
|
}
|
|
@@ -172,8 +170,7 @@ var BaseResource = class {
|
|
|
172
170
|
rateLimits = DEFAULT_RATE_LIMITS,
|
|
173
171
|
...tokens
|
|
174
172
|
}) {
|
|
175
|
-
if (!requesterFn)
|
|
176
|
-
throw new ReferenceError("requesterFn must be passed");
|
|
173
|
+
if (!requesterFn) throw new ReferenceError("requesterFn must be passed");
|
|
177
174
|
this.url = [host, "api", "v4", prefixUrl].join("/");
|
|
178
175
|
this.headers = {};
|
|
179
176
|
this.authHeaders = {};
|
|
@@ -189,15 +186,11 @@ var BaseResource = class {
|
|
|
189
186
|
this.authHeaders["job-token"] = async () => getDynamicToken(tokens.jobToken);
|
|
190
187
|
else if ("token" in tokens)
|
|
191
188
|
this.authHeaders["private-token"] = async () => getDynamicToken(tokens.token);
|
|
192
|
-
else {
|
|
193
|
-
throw new ReferenceError("A token, oauthToken or jobToken must be passed");
|
|
194
|
-
}
|
|
195
189
|
if (profileToken) {
|
|
196
190
|
this.headers["X-Profile-Token"] = profileToken;
|
|
197
191
|
this.headers["X-Profile-Mode"] = profileMode;
|
|
198
192
|
}
|
|
199
|
-
if (sudo)
|
|
200
|
-
this.headers.Sudo = `${sudo}`;
|
|
193
|
+
if (sudo) this.headers.Sudo = `${sudo}`;
|
|
201
194
|
this.requester = requesterFn({ ...this, rateLimits });
|
|
202
195
|
}
|
|
203
196
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -31,8 +31,7 @@ async function defaultOptionsHandler(resourceOptions, {
|
|
|
31
31
|
prefixUrl: url
|
|
32
32
|
};
|
|
33
33
|
defaultOptions.headers = { ...preconfiguredHeaders };
|
|
34
|
-
if (sudo)
|
|
35
|
-
defaultOptions.headers.sudo = `${sudo}`;
|
|
34
|
+
if (sudo) defaultOptions.headers.sudo = `${sudo}`;
|
|
36
35
|
if (body) {
|
|
37
36
|
if (body instanceof FormData) {
|
|
38
37
|
defaultOptions.body = body;
|
|
@@ -41,18 +40,18 @@ async function defaultOptionsHandler(resourceOptions, {
|
|
|
41
40
|
defaultOptions.headers["content-type"] = "application/json";
|
|
42
41
|
}
|
|
43
42
|
}
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
if (Object.keys(authHeaders).length > 0) {
|
|
44
|
+
const [authHeaderKey, authHeaderFn] = Object.entries(authHeaders)[0];
|
|
45
|
+
defaultOptions.headers[authHeaderKey] = await authHeaderFn();
|
|
46
|
+
}
|
|
46
47
|
const q = formatQuery(searchParams);
|
|
47
|
-
if (q)
|
|
48
|
-
defaultOptions.searchParams = q;
|
|
48
|
+
if (q) defaultOptions.searchParams = q;
|
|
49
49
|
return Promise.resolve(defaultOptions);
|
|
50
50
|
}
|
|
51
51
|
function createRateLimiters(rateLimitOptions = {}) {
|
|
52
52
|
const rateLimiters = {};
|
|
53
53
|
Object.entries(rateLimitOptions).forEach(([key, config]) => {
|
|
54
|
-
if (typeof config === "number")
|
|
55
|
-
rateLimiters[key] = generateRateLimiterFn(config, 60);
|
|
54
|
+
if (typeof config === "number") rateLimiters[key] = generateRateLimiterFn(config, 60);
|
|
56
55
|
else
|
|
57
56
|
rateLimiters[key] = {
|
|
58
57
|
method: config.method.toUpperCase(),
|
|
@@ -98,8 +97,7 @@ function getMatchingRateLimiter(endpoint, rateLimiters = {}, method = "GET") {
|
|
|
98
97
|
const sortedEndpoints = Object.keys(rateLimiters).sort().reverse();
|
|
99
98
|
const match = sortedEndpoints.find((ep) => isGlobMatch(endpoint, ep));
|
|
100
99
|
const rateLimitConfig = match && rateLimiters[match];
|
|
101
|
-
if (typeof rateLimitConfig === "function")
|
|
102
|
-
return rateLimitConfig;
|
|
100
|
+
if (typeof rateLimitConfig === "function") return rateLimitConfig;
|
|
103
101
|
if (rateLimitConfig && rateLimitConfig?.method?.toUpperCase() === method.toUpperCase()) {
|
|
104
102
|
return rateLimitConfig.limit;
|
|
105
103
|
}
|
|
@@ -166,8 +164,7 @@ var BaseResource = class {
|
|
|
166
164
|
rateLimits = DEFAULT_RATE_LIMITS,
|
|
167
165
|
...tokens
|
|
168
166
|
}) {
|
|
169
|
-
if (!requesterFn)
|
|
170
|
-
throw new ReferenceError("requesterFn must be passed");
|
|
167
|
+
if (!requesterFn) throw new ReferenceError("requesterFn must be passed");
|
|
171
168
|
this.url = [host, "api", "v4", prefixUrl].join("/");
|
|
172
169
|
this.headers = {};
|
|
173
170
|
this.authHeaders = {};
|
|
@@ -183,15 +180,11 @@ var BaseResource = class {
|
|
|
183
180
|
this.authHeaders["job-token"] = async () => getDynamicToken(tokens.jobToken);
|
|
184
181
|
else if ("token" in tokens)
|
|
185
182
|
this.authHeaders["private-token"] = async () => getDynamicToken(tokens.token);
|
|
186
|
-
else {
|
|
187
|
-
throw new ReferenceError("A token, oauthToken or jobToken must be passed");
|
|
188
|
-
}
|
|
189
183
|
if (profileToken) {
|
|
190
184
|
this.headers["X-Profile-Token"] = profileToken;
|
|
191
185
|
this.headers["X-Profile-Mode"] = profileMode;
|
|
192
186
|
}
|
|
193
|
-
if (sudo)
|
|
194
|
-
this.headers.Sudo = `${sudo}`;
|
|
187
|
+
if (sudo) this.headers.Sudo = `${sudo}`;
|
|
195
188
|
this.requester = requesterFn({ ...this, rateLimits });
|
|
196
189
|
}
|
|
197
190
|
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gitbeaker/requester-utils",
|
|
3
|
-
"version": "40.0
|
|
3
|
+
"version": "40.1.0",
|
|
4
4
|
"description": "Utility functions for requester implementatons used in @gitbeaker",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"engines": {
|
|
7
|
-
"node": ">=18.
|
|
7
|
+
"node": ">=18.20.0"
|
|
8
8
|
},
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
@@ -48,14 +48,14 @@
|
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"picomatch-browser": "^2.2.6",
|
|
51
|
-
"qs": "^6.
|
|
52
|
-
"rate-limiter-flexible": "^4.0.
|
|
51
|
+
"qs": "^6.12.2",
|
|
52
|
+
"rate-limiter-flexible": "^4.0.1",
|
|
53
53
|
"xcase": "^2.0.1"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@types/node": "^20.10
|
|
57
|
-
"tsup": "^8.0
|
|
58
|
-
"typescript": "^5.
|
|
56
|
+
"@types/node": "^20.14.10",
|
|
57
|
+
"tsup": "^8.1.0",
|
|
58
|
+
"typescript": "^5.5.3"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "312d4dc3eb7938b30ddf2b314297b3a535d5e7bc"
|
|
61
61
|
}
|