@comms-id/company 0.5.0 → 0.5.1

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.
@@ -142,7 +142,9 @@ const prepare = (operation, input) => {
142
142
  /** Sends one operation and returns its decoded reply, or throws a CommsIdError. */
143
143
  export const call = async (transport, operation, input, options = {}) => {
144
144
  const body = prepare(operation, input);
145
- const deadline = AbortSignal.timeout(options.deadlineMs ?? transport.deadlineMs ?? DEFAULT_DEADLINE_MS);
145
+ const deadlineMs = options.deadlineMs ?? transport.deadlineMs ?? DEFAULT_DEADLINE_MS;
146
+ const startedAt = performance.now();
147
+ const deadline = AbortSignal.timeout(deadlineMs);
146
148
  const signal = options.signal === undefined ? deadline : AbortSignal.any([options.signal, deadline]);
147
149
  const maxRetries = operation.safeToRetry ? (transport.maxRetries ?? DEFAULT_MAX_RETRIES) : 0;
148
150
  const sleep = transport.sleep ?? defaultSleep;
@@ -155,6 +157,11 @@ export const call = async (transport, operation, input, options = {}) => {
155
157
  throw result.error;
156
158
  }
157
159
  const delay = result.retryAfterMs ?? Math.min(BASE_DELAY_MS * 2 ** attempt, MAX_DELAY_MS);
160
+ // A retry that cannot start within this call's budget must not replace a real
161
+ // service failure (notably 429) with a later timeout or violate Retry-After.
162
+ if (delay >= deadlineMs - (performance.now() - startedAt)) {
163
+ throw result.error;
164
+ }
158
165
  try {
159
166
  await sleep(delay, signal);
160
167
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@comms-id/company",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "Typed client for the Comms.ID Company API: Australian companies from ASIC's public registers: search by name, look up one by ACN",
5
5
  "type": "module",
6
6
  "sideEffects": false,