@argos-ci/api-client 0.31.0 → 0.31.2
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 -1
- package/dist/index.d.mts +9 -7
- package/dist/index.mjs +54 -3
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
</a>
|
|
8
8
|
</p>
|
|
9
9
|
|
|
10
|
-
<p align="center"><strong>The open source visual testing platform for AI
|
|
10
|
+
<p align="center"><strong>The open source visual testing platform for teams and AI agents.</strong></p>
|
|
11
11
|
|
|
12
12
|
# Argos API Client
|
|
13
13
|
|
package/dist/index.d.mts
CHANGED
|
@@ -5169,6 +5169,8 @@ interface operations {
|
|
|
5169
5169
|
branch: components["schemas"]["GitBranch"];
|
|
5170
5170
|
/** @description The pull request number */
|
|
5171
5171
|
prNumber?: number | null;
|
|
5172
|
+
/** @description The head commit of the pull request. When `commit` is a merge commit built for the pull request, such as the test-merge commit GitHub Actions checks out, the deployment status is reported on this commit, where the pull request shows it. */
|
|
5173
|
+
prHeadCommit?: components["schemas"]["Sha1Hash"] | null;
|
|
5172
5174
|
/**
|
|
5173
5175
|
* @description The deployment environment. When omitted, it is inferred from `branch`: branches matching the configured production-branch glob are treated as `production`; all others default to `preview`.
|
|
5174
5176
|
* @enum {string}
|
|
@@ -10207,7 +10209,7 @@ interface operations {
|
|
|
10207
10209
|
}
|
|
10208
10210
|
//#endregion
|
|
10209
10211
|
//#region src/fetch.d.ts
|
|
10210
|
-
declare class APIError extends Error {
|
|
10212
|
+
export declare class APIError extends Error {
|
|
10211
10213
|
/**
|
|
10212
10214
|
* HTTP status code of the response that triggered the error, when available.
|
|
10213
10215
|
*/
|
|
@@ -10225,18 +10227,18 @@ declare class APIError extends Error {
|
|
|
10225
10227
|
}
|
|
10226
10228
|
//#endregion
|
|
10227
10229
|
//#region src/index.d.ts
|
|
10228
|
-
type ArgosAPIClient = ReturnType<typeof createClient>;
|
|
10230
|
+
export type ArgosAPIClient = ReturnType<typeof createClient>;
|
|
10229
10231
|
/**
|
|
10230
10232
|
* A `User-Agent` value, or a resolver for it. The resolver may be async and is
|
|
10231
10233
|
* called per request, so a caller that only learns its identity asynchronously
|
|
10232
10234
|
* (the CLI detecting the coding agent driving it) does not have to await that
|
|
10233
10235
|
* before it can build a client.
|
|
10234
10236
|
*/
|
|
10235
|
-
type UserAgentOption = string | (() => string | undefined | Promise<string | undefined>);
|
|
10237
|
+
export type UserAgentOption = string | (() => string | undefined | Promise<string | undefined>);
|
|
10236
10238
|
/**
|
|
10237
10239
|
* Create Argos API client.
|
|
10238
10240
|
*/
|
|
10239
|
-
declare function createClient(options?: {
|
|
10241
|
+
export declare function createClient(options?: {
|
|
10240
10242
|
baseUrl?: string;
|
|
10241
10243
|
authToken?: string;
|
|
10242
10244
|
userAgent?: UserAgentOption;
|
|
@@ -10251,10 +10253,10 @@ declare function createClient(options?: {
|
|
|
10251
10253
|
* we fall back to the HTTP status and the raw body so the failure stays
|
|
10252
10254
|
* debuggable instead of surfacing an empty message.
|
|
10253
10255
|
*/
|
|
10254
|
-
declare function formatAPIError(error: unknown, response?: Response): string;
|
|
10256
|
+
export declare function formatAPIError(error: unknown, response?: Response): string;
|
|
10255
10257
|
/**
|
|
10256
10258
|
* Handle API errors.
|
|
10257
10259
|
*/
|
|
10258
|
-
declare function throwAPIError(error: unknown, response?: Response): never;
|
|
10260
|
+
export declare function throwAPIError(error: unknown, response?: Response): never;
|
|
10259
10261
|
//#endregion
|
|
10260
|
-
export {
|
|
10262
|
+
export { schema_d_exports as ArgosAPISchema };
|
package/dist/index.mjs
CHANGED
|
@@ -6,6 +6,17 @@ const debug = createDebug("@argos-ci/api-client");
|
|
|
6
6
|
//#endregion
|
|
7
7
|
//#region src/fetch.ts
|
|
8
8
|
const DEFAULT_TIMEOUT = 3e4;
|
|
9
|
+
const DEFAULT_MIN_TIMEOUT = 1e3;
|
|
10
|
+
/**
|
|
11
|
+
* A request the API rejects with `429 Too Many Requests` is retried up to
|
|
12
|
+
* `MAX_RATE_LIMIT_RETRIES` times, apart from the retries for server errors,
|
|
13
|
+
* waiting at most `MAX_RATE_LIMIT_DELAY` before each retry whatever
|
|
14
|
+
* `Retry-After` asks. The API counts requests in fixed 5-minute windows, so
|
|
15
|
+
* five waits of a minute see a request through a whole window, and rate
|
|
16
|
+
* limiting never holds a request up for more than five minutes.
|
|
17
|
+
*/
|
|
18
|
+
const MAX_RATE_LIMIT_RETRIES = 5;
|
|
19
|
+
const MAX_RATE_LIMIT_DELAY = 6e4;
|
|
9
20
|
var APIError = class extends Error {
|
|
10
21
|
/**
|
|
11
22
|
* HTTP status code of the response that triggered the error, when available.
|
|
@@ -47,16 +58,56 @@ async function createRequestFactory(request, timeout) {
|
|
|
47
58
|
});
|
|
48
59
|
};
|
|
49
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Get how long to wait before retrying a `429 Too Many Requests` response: its
|
|
63
|
+
* `Retry-After`, or exponential backoff from `minTimeout` when the header is
|
|
64
|
+
* missing or invalid. The API sends a number of seconds; any other value, an
|
|
65
|
+
* HTTP date included, counts as invalid.
|
|
66
|
+
*/
|
|
67
|
+
function getRateLimitDelay(response, minTimeout, retry) {
|
|
68
|
+
const retryAfter = response.headers.get("retry-after")?.trim() ?? "";
|
|
69
|
+
const delay = /^\d+$/.test(retryAfter) ? Number(retryAfter) * 1e3 : minTimeout * 2 ** retry;
|
|
70
|
+
return Math.min(delay, MAX_RATE_LIMIT_DELAY);
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Wait for `ms`, or reject with the signal's reason as soon as it aborts.
|
|
74
|
+
*/
|
|
75
|
+
function wait(ms, signal) {
|
|
76
|
+
return new Promise((resolve, reject) => {
|
|
77
|
+
signal.throwIfAborted();
|
|
78
|
+
const onAbort = () => {
|
|
79
|
+
clearTimeout(timer);
|
|
80
|
+
reject(signal.reason);
|
|
81
|
+
};
|
|
82
|
+
const timer = setTimeout(() => {
|
|
83
|
+
signal.removeEventListener("abort", onAbort);
|
|
84
|
+
resolve();
|
|
85
|
+
}, ms);
|
|
86
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
87
|
+
});
|
|
88
|
+
}
|
|
50
89
|
async function apiFetch(input, options = {}) {
|
|
51
90
|
input.signal.throwIfAborted();
|
|
52
91
|
const fetchImpl = options.fetch ?? fetch;
|
|
92
|
+
const minTimeout = options.minTimeout ?? DEFAULT_MIN_TIMEOUT;
|
|
53
93
|
const createRequest = await createRequestFactory(input, options.timeout ?? DEFAULT_TIMEOUT);
|
|
54
|
-
|
|
55
|
-
|
|
94
|
+
let retryAttempt = 0;
|
|
95
|
+
let rateLimitRetries = 0;
|
|
96
|
+
const send = () => fetchImpl(createRequest(retryAttempt++));
|
|
97
|
+
return pRetry(async () => {
|
|
98
|
+
let response = await send();
|
|
99
|
+
while (response.status === 429 && rateLimitRetries < MAX_RATE_LIMIT_RETRIES) {
|
|
100
|
+
const delay = getRateLimitDelay(response, minTimeout, rateLimitRetries);
|
|
101
|
+
debug(`API request rate limited, retrying in ${delay}ms (${MAX_RATE_LIMIT_RETRIES - rateLimitRetries} left)`);
|
|
102
|
+
rateLimitRetries++;
|
|
103
|
+
await response.body?.cancel();
|
|
104
|
+
await wait(delay, input.signal);
|
|
105
|
+
response = await send();
|
|
106
|
+
}
|
|
56
107
|
if (response.status >= 500) throw new APIError(`Internal Server Error (${response.status})`);
|
|
57
108
|
return response;
|
|
58
109
|
}, {
|
|
59
|
-
minTimeout
|
|
110
|
+
minTimeout,
|
|
60
111
|
retries: options.retries ?? 3,
|
|
61
112
|
shouldRetry: () => !input.signal.aborted,
|
|
62
113
|
onFailedAttempt: (context) => {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@argos-ci/api-client",
|
|
3
3
|
"description": "Argos API Client library.",
|
|
4
|
-
"version": "0.31.
|
|
4
|
+
"version": "0.31.2",
|
|
5
5
|
"author": "Smooth Code",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"dependencies": {
|
|
53
53
|
"debug": "^4.4.3",
|
|
54
54
|
"openapi-fetch": "^0.17.0",
|
|
55
|
-
"p-retry": "^8.0.
|
|
55
|
+
"p-retry": "^8.0.1"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "e9d0b2fb39001683230eff86f9c39e0016b5cf27"
|
|
58
58
|
}
|