@argos-ci/api-client 0.12.1-alpha.4 → 0.14.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/dist/index.d.ts CHANGED
@@ -103,6 +103,7 @@ interface components {
103
103
  key: string;
104
104
  name: string;
105
105
  baseName?: string | null;
106
+ parentName?: string | null;
106
107
  metadata?: {
107
108
  /**
108
109
  * @description Ignored. Can be set to get completions, validations and documentation in some editors.
@@ -185,6 +186,8 @@ interface components {
185
186
  } | null;
186
187
  pwTraceKey?: string | null;
187
188
  threshold?: number | null;
189
+ /** @default image/png */
190
+ contentType: string;
188
191
  };
189
192
  /** @description Build metadata */
190
193
  BuildMetadata: {
package/dist/index.js CHANGED
@@ -39,7 +39,7 @@ function isNetworkError(error) {
39
39
  return errorMessages.has(message);
40
40
  }
41
41
 
42
- // ../../node_modules/.pnpm/p-retry@7.0.0/node_modules/p-retry/index.js
42
+ // ../../node_modules/.pnpm/p-retry@7.1.0/node_modules/p-retry/index.js
43
43
  function validateRetries(retries) {
44
44
  if (typeof retries === "number") {
45
45
  if (retries < 0) {
@@ -80,43 +80,57 @@ var AbortError = class extends Error {
80
80
  this.message = message;
81
81
  }
82
82
  };
83
- var createRetryContext = (error, attemptNumber, options) => {
84
- const retriesLeft = options.retries - (attemptNumber - 1);
85
- return Object.freeze({
86
- error,
87
- attemptNumber,
88
- retriesLeft
89
- });
90
- };
91
- function calculateDelay(attempt, options) {
83
+ function calculateDelay(retriesConsumed, options) {
84
+ const attempt = Math.max(1, retriesConsumed + 1);
92
85
  const random = options.randomize ? Math.random() + 1 : 1;
93
- let timeout = Math.round(random * Math.max(options.minTimeout, 1) * options.factor ** (attempt - 1));
86
+ let timeout = Math.round(random * options.minTimeout * options.factor ** (attempt - 1));
94
87
  timeout = Math.min(timeout, options.maxTimeout);
95
88
  return timeout;
96
89
  }
97
- async function onAttemptFailure(error, attemptNumber, options, startTime, maxRetryTime) {
98
- let normalizedError = error;
99
- if (!(normalizedError instanceof Error)) {
100
- normalizedError = new TypeError(`Non-error was thrown: "${normalizedError}". You should only throw errors.`);
90
+ function calculateRemainingTime(start, max) {
91
+ if (!Number.isFinite(max)) {
92
+ return max;
101
93
  }
94
+ return max - (performance.now() - start);
95
+ }
96
+ async function onAttemptFailure({ error, attemptNumber, retriesConsumed, startTime, options }) {
97
+ const normalizedError = error instanceof Error ? error : new TypeError(`Non-error was thrown: "${error}". You should only throw errors.`);
102
98
  if (normalizedError instanceof AbortError) {
103
99
  throw normalizedError.originalError;
104
100
  }
105
- if (normalizedError instanceof TypeError && !isNetworkError(normalizedError)) {
101
+ const retriesLeft = Number.isFinite(options.retries) ? Math.max(0, options.retries - retriesConsumed) : options.retries;
102
+ const maxRetryTime = options.maxRetryTime ?? Number.POSITIVE_INFINITY;
103
+ const context = Object.freeze({
104
+ error: normalizedError,
105
+ attemptNumber,
106
+ retriesLeft,
107
+ retriesConsumed
108
+ });
109
+ await options.onFailedAttempt(context);
110
+ if (calculateRemainingTime(startTime, maxRetryTime) <= 0) {
106
111
  throw normalizedError;
107
112
  }
108
- const context = createRetryContext(normalizedError, attemptNumber, options);
109
- await options.onFailedAttempt(context);
110
- const currentTime = Date.now();
111
- if (currentTime - startTime >= maxRetryTime || attemptNumber >= options.retries + 1 || !await options.shouldRetry(context)) {
113
+ const consumeRetry = await options.shouldConsumeRetry(context);
114
+ const remainingTime = calculateRemainingTime(startTime, maxRetryTime);
115
+ if (remainingTime <= 0 || retriesLeft <= 0) {
112
116
  throw normalizedError;
113
117
  }
114
- const delayTime = calculateDelay(attemptNumber, options);
115
- const timeLeft = maxRetryTime - (currentTime - startTime);
116
- if (timeLeft <= 0) {
118
+ if (normalizedError instanceof TypeError && !isNetworkError(normalizedError)) {
119
+ if (consumeRetry) {
120
+ throw normalizedError;
121
+ }
122
+ options.signal?.throwIfAborted();
123
+ return false;
124
+ }
125
+ if (!await options.shouldRetry(context)) {
117
126
  throw normalizedError;
118
127
  }
119
- const finalDelay = Math.min(delayTime, timeLeft);
128
+ if (!consumeRetry) {
129
+ options.signal?.throwIfAborted();
130
+ return false;
131
+ }
132
+ const delayTime = calculateDelay(retriesConsumed, options);
133
+ const finalDelay = Math.min(delayTime, remainingTime);
120
134
  if (finalDelay > 0) {
121
135
  await new Promise((resolve, reject) => {
122
136
  const onAbort = () => {
@@ -135,6 +149,7 @@ async function onAttemptFailure(error, attemptNumber, options, startTime, maxRet
135
149
  });
136
150
  }
137
151
  options.signal?.throwIfAborted();
152
+ return true;
138
153
  }
139
154
  async function pRetry(input, options = {}) {
140
155
  options = { ...options };
@@ -146,23 +161,24 @@ async function pRetry(input, options = {}) {
146
161
  options.factor ??= 2;
147
162
  options.minTimeout ??= 1e3;
148
163
  options.maxTimeout ??= Number.POSITIVE_INFINITY;
164
+ options.maxRetryTime ??= Number.POSITIVE_INFINITY;
149
165
  options.randomize ??= false;
150
166
  options.onFailedAttempt ??= () => {
151
167
  };
152
168
  options.shouldRetry ??= () => true;
169
+ options.shouldConsumeRetry ??= () => true;
153
170
  validateNumberOption("factor", options.factor, { min: 0, allowInfinity: false });
154
171
  validateNumberOption("minTimeout", options.minTimeout, { min: 0, allowInfinity: false });
155
172
  validateNumberOption("maxTimeout", options.maxTimeout, { min: 0, allowInfinity: true });
156
- const resolvedMaxRetryTime = options.maxRetryTime ?? Number.POSITIVE_INFINITY;
157
- validateNumberOption("maxRetryTime", resolvedMaxRetryTime, { min: 0, allowInfinity: true });
173
+ validateNumberOption("maxRetryTime", options.maxRetryTime, { min: 0, allowInfinity: true });
158
174
  if (!(options.factor > 0)) {
159
175
  options.factor = 1;
160
176
  }
161
177
  options.signal?.throwIfAborted();
162
178
  let attemptNumber = 0;
163
- const startTime = Date.now();
164
- const maxRetryTime = resolvedMaxRetryTime;
165
- while (attemptNumber < options.retries + 1) {
179
+ let retriesConsumed = 0;
180
+ const startTime = performance.now();
181
+ while (Number.isFinite(options.retries) ? retriesConsumed <= options.retries : true) {
166
182
  attemptNumber++;
167
183
  try {
168
184
  options.signal?.throwIfAborted();
@@ -170,7 +186,15 @@ async function pRetry(input, options = {}) {
170
186
  options.signal?.throwIfAborted();
171
187
  return result;
172
188
  } catch (error) {
173
- await onAttemptFailure(error, attemptNumber, options, startTime, maxRetryTime);
189
+ if (await onAttemptFailure({
190
+ error,
191
+ attemptNumber,
192
+ retriesConsumed,
193
+ startTime,
194
+ options
195
+ })) {
196
+ retriesConsumed++;
197
+ }
174
198
  }
175
199
  }
176
200
  throw new Error("Retry attempts exhausted without throwing an error.");
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.12.1-alpha.4+d1894ac",
4
+ "version": "0.14.0",
5
5
  "author": "Smooth Code",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -45,12 +45,12 @@
45
45
  "devDependencies": {
46
46
  "@types/debug": "^4.1.12",
47
47
  "@types/node": "catalog:",
48
- "openapi-typescript": "^7.9.1",
49
- "p-retry": "^7.0.0"
48
+ "openapi-typescript": "^7.10.1",
49
+ "p-retry": "^7.1.0"
50
50
  },
51
51
  "dependencies": {
52
52
  "debug": "^4.4.3",
53
- "openapi-fetch": "^0.14.1"
53
+ "openapi-fetch": "^0.15.0"
54
54
  },
55
- "gitHead": "d1894acc62fb886d4673c88cc7e8cc95e81db78b"
55
+ "gitHead": "fb54cf311b705f214041f18443352577be01e822"
56
56
  }