@simpleapps-com/augur-api 2026.11.3 → 2026.11.4

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.mjs CHANGED
@@ -170,11 +170,6 @@ function placeholderFilled(path, placeholder, segment) {
170
170
  return replaceText(path, "{" + placeholder + "}", segment);
171
171
  }
172
172
 
173
- // ../json-values/src/index.ts
174
- function isRecord(value) {
175
- return typeof value === "object" && value !== null && !Array.isArray(value);
176
- }
177
-
178
173
  // ../foundation/src/duration.ts
179
174
  function seconds(n) {
180
175
  return n;
@@ -184,6 +179,7 @@ function toMillis(d) {
184
179
  }
185
180
 
186
181
  // src/core/config.ts
182
+ var NO_BOUNDS = { signals: [] };
187
183
  var DEFAULT_CONFIG = {
188
184
  timeout: toMillis(seconds(30)),
189
185
  retries: 3,
@@ -198,6 +194,105 @@ var ContextCreationError = class extends Error {
198
194
  field;
199
195
  };
200
196
 
197
+ // ../json-values/src/index.ts
198
+ function isRecord(value) {
199
+ return typeof value === "object" && value !== null && !Array.isArray(value);
200
+ }
201
+
202
+ // src/core/http-rules.ts
203
+ function isRetryableStatus(status) {
204
+ return !(status >= 400 && status < 500 && status !== 429);
205
+ }
206
+ function exponentialDelay(base, attempt) {
207
+ if (attempt === 0) return base;
208
+ return 2 * exponentialDelay(base, attempt - 1);
209
+ }
210
+ function cappedDelay(d) {
211
+ return Math.min(d, 3e4);
212
+ }
213
+ function timeoutOf(hasRequest, request, hasClient, client, fallback) {
214
+ if (hasRequest) return request;
215
+ return hasClient ? client : fallback;
216
+ }
217
+ function isPublicEndpoint(url) {
218
+ return endsWith(url, "/health-check") || endsWith(url, "/ping");
219
+ }
220
+ function sendsBearer(url, hasToken) {
221
+ return hasToken && !isPublicEndpoint(url);
222
+ }
223
+ function sendsJsonBody(hasData, method) {
224
+ return hasData && method !== "GET";
225
+ }
226
+ function querySeparator(url) {
227
+ return includesFrom(url, "?", 0) ? "&" : "?";
228
+ }
229
+ function requestKey(method, url, params) {
230
+ return method + ":" + url + ":" + params;
231
+ }
232
+ function isEdgeCacheParam(key) {
233
+ return key === "edgeCache";
234
+ }
235
+
236
+ // src/core/client-rules.ts
237
+ function contextRefusalOf(hasContext, siteIdTruthy, contextTokenTruthy, finalTokenTruthy) {
238
+ if (!hasContext) return "context";
239
+ if (!siteIdTruthy) return "site-id";
240
+ if (!contextTokenTruthy) return "token";
241
+ return finalTokenTruthy ? "ok" : "token-removed";
242
+ }
243
+ function retryableError(isAugurError, status) {
244
+ return !isAugurError || isRetryableStatus(status);
245
+ }
246
+ function retryAfterCall(attempt, retries, retryable, callAborted) {
247
+ return !callAborted && attempt < retries && retryable;
248
+ }
249
+ function isAbortName(name) {
250
+ return name === "AbortError" || name === "TimeoutError";
251
+ }
252
+ function remainingOf(deadline, elapsed) {
253
+ return elapsed < deadline ? deadline - elapsed : 0;
254
+ }
255
+ function attemptTimeoutOf(perAttempt, hasDeadline, remaining) {
256
+ return hasDeadline && remaining < perAttempt ? remaining : perAttempt;
257
+ }
258
+ function waitOf(backoff, hasDeadline, remaining) {
259
+ return hasDeadline && remaining < backoff ? remaining : backoff;
260
+ }
261
+ function needsAttemptTimer(perAttempt, hasDeadline, remaining) {
262
+ return !(hasDeadline && remaining <= perAttempt);
263
+ }
264
+ function boundedCall(hasSignal, hasDeadline) {
265
+ return hasSignal || hasDeadline;
266
+ }
267
+ function deadlineInRange(deadline) {
268
+ return 0 <= deadline && deadline <= 2147483647;
269
+ }
270
+ function callOptionsAccepted(hasSignal, isAbortSignal, hasDeadline, inRange) {
271
+ return (!hasSignal || isAbortSignal) && (!hasDeadline || inRange);
272
+ }
273
+ function sharesInFlight(hasRequestSignal) {
274
+ return !hasRequestSignal;
275
+ }
276
+ function mergedDeadlineOf(hasOuter, outer, hasInner, inner) {
277
+ if (!hasOuter) return inner;
278
+ if (!hasInner) return outer;
279
+ return inner < outer ? inner : outer;
280
+ }
281
+ function hasMergedDeadline(hasOuter, hasInner) {
282
+ return hasOuter || hasInner;
283
+ }
284
+ function edgeCacheKindOf(text, hours) {
285
+ if (text === "30s" || text === "1m" || text === "5m") return "sub-hour";
286
+ const hourly = hours === 1 || hours === 2 || hours === 3 || hours === 4 || hours === 5 || hours === 8;
287
+ return hourly ? "hourly" : "invalid";
288
+ }
289
+ function rawRetries(method) {
290
+ return method === "GET";
291
+ }
292
+ function startsAttempt(hasDeadline, remaining) {
293
+ return !hasDeadline || remaining > 0;
294
+ }
295
+
201
296
  // src/core/errors.ts
202
297
  var AugurError = class _AugurError extends Error {
203
298
  code;
@@ -309,40 +404,6 @@ var InvalidArgumentError = class extends AugurError {
309
404
  }
310
405
  };
311
406
 
312
- // src/core/http-rules.ts
313
- function isRetryableStatus(status) {
314
- return !(status >= 400 && status < 500 && status !== 429);
315
- }
316
- function exponentialDelay(base, attempt) {
317
- if (attempt === 0) return base;
318
- return 2 * exponentialDelay(base, attempt - 1);
319
- }
320
- function cappedDelay(d) {
321
- return Math.min(d, 3e4);
322
- }
323
- function timeoutOf(hasRequest, request, hasClient, client, fallback) {
324
- if (hasRequest) return request;
325
- return hasClient ? client : fallback;
326
- }
327
- function isPublicEndpoint(url) {
328
- return endsWith(url, "/health-check") || endsWith(url, "/ping");
329
- }
330
- function sendsBearer(url, hasToken) {
331
- return hasToken && !isPublicEndpoint(url);
332
- }
333
- function sendsJsonBody(hasData, method) {
334
- return hasData && method !== "GET";
335
- }
336
- function querySeparator(url) {
337
- return includesFrom(url, "?", 0) ? "&" : "?";
338
- }
339
- function requestKey(method, url, params) {
340
- return method + ":" + url + ":" + params;
341
- }
342
- function isEdgeCacheParam(key) {
343
- return key === "edgeCache";
344
- }
345
-
346
407
  // src/core/client.ts
347
408
  function parseJson(text) {
348
409
  try {
@@ -377,10 +438,59 @@ function calculateBackoffDelay(attempt, baseDelay) {
377
438
  return cappedDelay(exponential + jitter);
378
439
  }
379
440
  function isRetryableError(error) {
380
- return !(error instanceof AugurError) || isRetryableStatus(error.statusCode);
441
+ const isAugurError = error instanceof AugurError;
442
+ return retryableError(isAugurError, isAugurError ? error.statusCode : 0);
443
+ }
444
+ function delay(ms, signal) {
445
+ return new Promise((resolve, reject) => {
446
+ const onAbort = () => {
447
+ clearTimeout(timer);
448
+ reject(signal.reason);
449
+ };
450
+ const timer = setTimeout(() => {
451
+ signal?.removeEventListener("abort", onAbort);
452
+ resolve();
453
+ }, ms);
454
+ signal?.addEventListener("abort", onAbort, { once: true });
455
+ });
381
456
  }
382
- function delay(ms) {
383
- return new Promise((resolve) => setTimeout(resolve, ms));
457
+ var UNBOUNDED = {
458
+ signal: void 0,
459
+ hasDeadline: false,
460
+ remaining: () => 0,
461
+ dispose: () => {
462
+ }
463
+ };
464
+ function throwIfEnded(call) {
465
+ if (call.signal?.aborted) throw call.signal.reason;
466
+ }
467
+ function startCall(bounds, requestSignal) {
468
+ const sources = requestSignal === void 0 ? [...bounds.signals] : [...bounds.signals, requestSignal];
469
+ const deadline = bounds.deadline;
470
+ if (!boundedCall(sources.length > 0, deadline !== void 0)) return UNBOUNDED;
471
+ const controller = new AbortController();
472
+ const started = Date.now();
473
+ const listeners = sources.map((source) => {
474
+ const onAbort = () => controller.abort(source.reason);
475
+ source.addEventListener("abort", onAbort, { once: true });
476
+ return { source, onAbort };
477
+ });
478
+ for (const source of sources) {
479
+ if (source.aborted) controller.abort(source.reason);
480
+ }
481
+ const timer = deadline === void 0 ? void 0 : setTimeout(
482
+ () => controller.abort(new DOMException("Call deadline exceeded", "TimeoutError")),
483
+ deadline
484
+ );
485
+ return {
486
+ signal: controller.signal,
487
+ hasDeadline: deadline !== void 0,
488
+ remaining: () => remainingOf(deadline ?? 0, Date.now() - started),
489
+ dispose: () => {
490
+ clearTimeout(timer);
491
+ for (const { source, onAbort } of listeners) source.removeEventListener("abort", onAbort);
492
+ }
493
+ };
384
494
  }
385
495
  function withoutEdgeCache(params) {
386
496
  return Object.fromEntries(Object.entries(params).filter(([key]) => !isEdgeCacheParam(key)));
@@ -424,18 +534,22 @@ var HTTPClient = class {
424
534
  config;
425
535
  serviceName;
426
536
  inflightRequests = /* @__PURE__ */ new Map();
427
- constructor(serviceName, config) {
537
+ bounds;
538
+ /** `bounds` bound every call this client makes (a view's, from `AugurAPI.withRequest`). */
539
+ constructor(serviceName, config, bounds = NO_BOUNDS) {
428
540
  this.serviceName = serviceName;
429
541
  this.config = { ...DEFAULT_CONFIG, ...config };
542
+ this.bounds = bounds;
430
543
  }
431
544
  /**
432
- * Build request headers with auth
545
+ * Build request headers with auth. A request's own headers come before `x-site-id` and
546
+ * `Authorization`, so neither can be replaced by one (AugurApiClient.SiteIdHeaderIsTheClients).
433
547
  */
434
548
  buildRequestHeaders(url, requestConfig) {
435
549
  const headers = {
436
550
  "Content-Type": "application/json",
437
- "x-site-id": this.config.siteId,
438
- ...requestConfig?.headers
551
+ ...requestConfig?.headers,
552
+ "x-site-id": this.config.siteId
439
553
  };
440
554
  if (sendsBearer(url, Boolean(this.config.bearerToken))) {
441
555
  headers["Authorization"] = `Bearer ${this.config.bearerToken}`;
@@ -511,30 +625,58 @@ var HTTPClient = class {
511
625
  * Core request method using native fetch. `read` turns a 2xx response into
512
626
  * the result, inside the same error handling and timeout as the fetch.
513
627
  */
514
- async request(method, url, options, read = (r, c) => this.handleFetchSuccess(r, c)) {
628
+ async request(method, url, options, call, read = (r, c) => this.handleFetchSuccess(r, c)) {
515
629
  const { config: requestConfig } = options;
516
630
  const endpoint = requestConfig?.endpoint ?? url;
517
- const timeout = this.timeoutFor(requestConfig);
518
- let augurConfig = this.baseRequest(method, url, options, timeout);
631
+ const bounds = this.attemptBounds(requestConfig, call);
632
+ let augurConfig = this.baseRequest(method, url, options, bounds.timeout);
519
633
  if (this.config.onRequest) {
520
634
  augurConfig = await this.config.onRequest(augurConfig);
521
635
  }
522
636
  const fullUrl = buildUrlWithParams(augurConfig.url, augurConfig.params);
523
- const controller = new AbortController();
524
- const timeoutId = setTimeout(() => controller.abort(), timeout);
525
- const signal = requestConfig?.signal ? this.mergeSignals(requestConfig.signal, controller.signal) : controller.signal;
637
+ throwIfEnded(call);
638
+ const attempt = this.attemptSignal(call, bounds);
526
639
  try {
527
- const response = await fetch(fullUrl, fetchOptionsFor(augurConfig, method, signal));
640
+ const response = await fetch(fullUrl, fetchOptionsFor(augurConfig, method, attempt.signal));
528
641
  if (!response.ok) {
529
642
  await this.handleFetchError(response, augurConfig, endpoint);
530
643
  }
531
644
  return await read(response, augurConfig);
532
645
  } catch (error) {
646
+ throwIfEnded(call);
533
647
  this.rethrowOrWrapError(error, endpoint);
534
648
  } finally {
535
- clearTimeout(timeoutId);
649
+ attempt.dispose();
536
650
  }
537
651
  }
652
+ /**
653
+ * An attempt's timeout (the per-attempt one, cut to what is left of the call's deadline: what
654
+ * the onRequest hook sees) and whether it sets its own timer: only when it ends before the
655
+ * deadline; otherwise the call's one deadline timer cuts it, with a TimeoutError
656
+ * (client-rules.ts; AugurApiClient.OneTimerCutsEachAttempt).
657
+ */
658
+ attemptBounds(requestConfig, call) {
659
+ const perAttempt = this.timeoutFor(requestConfig);
660
+ const remaining = call.remaining();
661
+ return {
662
+ timeout: attemptTimeoutOf(perAttempt, call.hasDeadline, remaining),
663
+ ownTimer: needsAttemptTimer(perAttempt, call.hasDeadline, remaining)
664
+ };
665
+ }
666
+ /** The signal one attempt is sent with, and how to clear its timer and listeners after. */
667
+ attemptSignal(call, bounds) {
668
+ const controller = new AbortController();
669
+ const timeoutId = bounds.ownTimer ? setTimeout(() => controller.abort(), bounds.timeout) : void 0;
670
+ const merged = call.signal ? this.mergeSignals(call.signal, controller.signal) : { signal: controller.signal, dispose: () => {
671
+ } };
672
+ return {
673
+ signal: merged.signal,
674
+ dispose: () => {
675
+ clearTimeout(timeoutId);
676
+ merged.dispose();
677
+ }
678
+ };
679
+ }
538
680
  /** The request's timeout: per request, else the client's, else the default (timeoutOf). */
539
681
  timeoutFor(requestConfig) {
540
682
  const request = requestConfig?.timeout;
@@ -559,17 +701,20 @@ var HTTPClient = class {
559
701
  };
560
702
  }
561
703
  /**
562
- * Merge two AbortSignals — aborts when either fires
704
+ * Merge the call's signal and an attempt's timer: aborts when either fires, with that one's
705
+ * reason. `dispose` removes the listener from the call's signal, which outlives the attempt
706
+ * (one per attempt would pile up on a long-lived caller signal).
563
707
  */
564
- mergeSignals(userSignal, timeoutSignal) {
708
+ mergeSignals(callSignal, timeoutSignal) {
565
709
  const controller = new AbortController();
566
- const onAbort = () => controller.abort();
567
- userSignal.addEventListener("abort", onAbort, { once: true });
568
- timeoutSignal.addEventListener("abort", onAbort, { once: true });
569
- if (userSignal.aborted) {
570
- controller.abort();
571
- }
572
- return controller.signal;
710
+ const onCallAbort = () => controller.abort(callSignal.reason);
711
+ const onTimeout = () => controller.abort(timeoutSignal.reason);
712
+ callSignal.addEventListener("abort", onCallAbort, { once: true });
713
+ timeoutSignal.addEventListener("abort", onTimeout, { once: true });
714
+ return {
715
+ signal: controller.signal,
716
+ dispose: () => callSignal.removeEventListener("abort", onCallAbort)
717
+ };
573
718
  }
574
719
  /**
575
720
  * The one status-to-error switch, shared by typed methods and `call()`.
@@ -599,7 +744,7 @@ var HTTPClient = class {
599
744
  if (error instanceof AugurError) {
600
745
  throw error;
601
746
  }
602
- if (error instanceof DOMException && error.name === "AbortError") {
747
+ if (error instanceof DOMException && isAbortName(error.name)) {
603
748
  throw error;
604
749
  }
605
750
  this.handleNetworkError(error, endpoint);
@@ -616,25 +761,48 @@ var HTTPClient = class {
616
761
  /**
617
762
  * Executes a single request attempt
618
763
  */
619
- async executeAttempt(requestFn, attempt, maxRetries, baseDelay) {
764
+ async executeAttempt(requestFn, attempt, maxRetries, baseDelay, call) {
620
765
  try {
621
- return await requestFn();
766
+ return await this.attemptWithin(call, requestFn);
622
767
  } catch (error) {
623
- if (attempt >= maxRetries || !isRetryableError(error)) {
768
+ if (!retryAfterCall(attempt, maxRetries, isRetryableError(error), call.signal?.aborted === true)) {
624
769
  throw error;
625
770
  }
626
- const backoffDelay = calculateBackoffDelay(attempt, baseDelay);
627
- await delay(backoffDelay);
628
- return this.executeAttempt(requestFn, attempt + 1, maxRetries, baseDelay);
771
+ const backoffDelay = waitOf(
772
+ calculateBackoffDelay(attempt, baseDelay),
773
+ call.hasDeadline,
774
+ call.remaining()
775
+ );
776
+ await delay(backoffDelay, call.signal);
777
+ return this.executeAttempt(requestFn, attempt + 1, maxRetries, baseDelay, call);
778
+ }
779
+ }
780
+ /**
781
+ * One attempt, started only while the call's deadline has time left (client-rules.ts
782
+ * startsAttempt); past it the call rejects with a TimeoutError.
783
+ */
784
+ attemptWithin(call, requestFn) {
785
+ if (!startsAttempt(call.hasDeadline, call.remaining())) {
786
+ return Promise.reject(new DOMException("Call deadline exceeded", "TimeoutError"));
629
787
  }
788
+ return requestFn();
630
789
  }
631
790
  /**
632
791
  * Executes a request with retry logic
633
792
  */
634
- async executeWithRetry(requestFn) {
793
+ async executeWithRetry(requestFn, call) {
635
794
  const maxRetries = this.config.retries ?? DEFAULT_CONFIG.retries;
636
795
  const baseDelay = this.config.retryDelay ?? DEFAULT_CONFIG.retryDelay;
637
- return this.executeAttempt(requestFn, 0, maxRetries, baseDelay);
796
+ return this.executeAttempt(requestFn, 0, maxRetries, baseDelay, call);
797
+ }
798
+ /** Runs `fn` in a fresh call scope and disposes it, however `fn` settles. */
799
+ async withinCall(requestSignal, fn) {
800
+ const call = startCall(this.bounds, requestSignal);
801
+ try {
802
+ return await fn(call);
803
+ } finally {
804
+ call.dispose();
805
+ }
638
806
  }
639
807
  /**
640
808
  * Transform edgeCache parameter to Cloudflare's cacheSiteId format
@@ -662,19 +830,13 @@ var HTTPClient = class {
662
830
  if (edgeCache == null) {
663
831
  return params;
664
832
  }
665
- const validSubHourValues = ["30s", "1m", "5m"];
666
- const validHourlyValues = [1, 2, 3, 4, 5, 8];
667
- let cacheSuffix;
668
833
  const edgeCacheStr = String(edgeCache);
669
- if (validSubHourValues.includes(edgeCacheStr)) {
670
- cacheSuffix = edgeCacheStr;
671
- } else {
672
- const cacheHours = parseInt(edgeCacheStr, 10);
673
- if (!validHourlyValues.includes(cacheHours)) {
674
- return withoutEdgeCache(paramsObj);
675
- }
676
- cacheSuffix = String(cacheHours);
834
+ const cacheHours = parseInt(edgeCacheStr, 10);
835
+ const kind = edgeCacheKindOf(edgeCacheStr, cacheHours);
836
+ if (kind === "invalid") {
837
+ return withoutEdgeCache(paramsObj);
677
838
  }
839
+ const cacheSuffix = kind === "sub-hour" ? edgeCacheStr : String(cacheHours);
678
840
  const restParams = withoutEdgeCache(paramsObj);
679
841
  const cacheKey = `cacheSiteId${cacheSuffix}`;
680
842
  return {
@@ -686,40 +848,49 @@ var HTTPClient = class {
686
848
  const transformedParams = this.transformEdgeCacheParams(params);
687
849
  const method = "GET";
688
850
  const requestKey2 = generateRequestKey(method, url, transformedParams);
689
- const inflight = this.inflightRequests.get(requestKey2);
851
+ const shares = sharesInFlight(config?.signal !== void 0);
852
+ const inflight = shares ? this.inflightRequests.get(requestKey2) : void 0;
690
853
  if (inflight) {
691
854
  return inflight;
692
855
  }
693
- const requestPromise = this.executeWithRetry(
694
- () => this.request(method, url, { params: transformedParams, config })
695
- ).finally(() => {
856
+ const requestPromise = this.withinCall(
857
+ config?.signal,
858
+ (call) => this.executeWithRetry(
859
+ () => this.request(method, url, { params: transformedParams, config }, call),
860
+ call
861
+ )
862
+ );
863
+ if (!shares) return requestPromise;
864
+ const shared = requestPromise.finally(() => {
696
865
  this.inflightRequests.delete(requestKey2);
697
866
  });
698
- this.inflightRequests.set(requestKey2, requestPromise);
699
- return requestPromise;
867
+ this.inflightRequests.set(requestKey2, shared);
868
+ return shared;
700
869
  }
701
870
  // The API declares query params on POST/PUT/DELETE as well as GET. `request`
702
871
  // already carries both a body and a query slot; these wrappers simply never
703
872
  // exposed the latter, leaving those params unreachable from the clients.
873
+ // Writes make one attempt (never retried), bounded by the call's scope like a GET.
704
874
  async post(url, data, params, config) {
705
- return this.request("POST", url, {
706
- data,
707
- params: this.transformEdgeCacheParams(params),
708
- config
709
- });
875
+ const options = { data, params: this.transformEdgeCacheParams(params), config };
876
+ return this.withinCall(
877
+ config?.signal,
878
+ (call) => this.attemptWithin(call, () => this.request("POST", url, options, call))
879
+ );
710
880
  }
711
881
  async put(url, data, params, config) {
712
- return this.request("PUT", url, {
713
- data,
714
- params: this.transformEdgeCacheParams(params),
715
- config
716
- });
882
+ const options = { data, params: this.transformEdgeCacheParams(params), config };
883
+ return this.withinCall(
884
+ config?.signal,
885
+ (call) => this.attemptWithin(call, () => this.request("PUT", url, options, call))
886
+ );
717
887
  }
718
888
  async delete(url, params, config) {
719
- return this.request("DELETE", url, {
720
- params: this.transformEdgeCacheParams(params),
721
- config
722
- });
889
+ const options = { params: this.transformEdgeCacheParams(params), config };
890
+ return this.withinCall(
891
+ config?.signal,
892
+ (call) => this.attemptWithin(call, () => this.request("DELETE", url, options, call))
893
+ );
723
894
  }
724
895
  /**
725
896
  * Send a request and return the 2xx response as text, with no schema
@@ -728,13 +899,17 @@ var HTTPClient = class {
728
899
  * in-flight deduplication); other methods make one attempt, like `post()`.
729
900
  */
730
901
  async raw(method, url, options = {}) {
731
- const send = () => this.request(
732
- method,
733
- url,
734
- { ...options, params: this.transformEdgeCacheParams(options.params) },
735
- (response, augurConfig) => this.readRaw(response, augurConfig)
736
- );
737
- return method === "GET" ? this.executeWithRetry(send) : send();
902
+ const requestOptions = { ...options, params: this.transformEdgeCacheParams(options.params) };
903
+ return this.withinCall(options.config?.signal, (call) => {
904
+ const send = () => this.request(
905
+ method,
906
+ url,
907
+ requestOptions,
908
+ call,
909
+ (response, augurConfig) => this.readRaw(response, augurConfig)
910
+ );
911
+ return rawRetries(method) ? this.executeWithRetry(send, call) : this.attemptWithin(call, send);
912
+ });
738
913
  }
739
914
  };
740
915
 
@@ -39677,14 +39852,14 @@ function toEnvelope(body) {
39677
39852
  }
39678
39853
  return Object.fromEntries(ENVELOPE_KEYS.map((key) => [key, record32[key]]));
39679
39854
  }
39680
- async function callEndpoint(config, id, args = {}) {
39855
+ async function callEndpoint(config, id, args = {}, bounds = NO_BOUNDS) {
39681
39856
  const entry = resolveEndpoint(id);
39682
39857
  if (!entry) {
39683
39858
  throw invalid(unknownIdMessage(id));
39684
39859
  }
39685
39860
  checkArgs(entry, args);
39686
39861
  const url = serviceUrl(entry.service, fillPath(entry, args.pathParams ?? {}));
39687
- const raw = await new HTTPClient(entry.service, config).raw(entry.method, url, {
39862
+ const raw = await new HTTPClient(entry.service, config, bounds).raw(entry.method, url, {
39688
39863
  params: args.query,
39689
39864
  data: args.body ?? void 0,
39690
39865
  config: { endpoint: entry.path }
@@ -41738,8 +41913,32 @@ var Basecamp2Client = class extends BaseServiceClient {
41738
41913
  };
41739
41914
 
41740
41915
  // src/client.ts
41916
+ function mergedBounds(outer, signal, deadline) {
41917
+ const signals = signal === void 0 ? outer.signals : [...outer.signals, signal];
41918
+ const hasOuter = outer.deadline !== void 0;
41919
+ const hasInner = deadline !== void 0;
41920
+ if (!hasMergedDeadline(hasOuter, hasInner)) return { signals };
41921
+ return {
41922
+ signals,
41923
+ deadline: mergedDeadlineOf(hasOuter, outer.deadline ?? 0, hasInner, deadline ?? 0)
41924
+ };
41925
+ }
41926
+ var CONTEXT_REFUSALS = {
41927
+ context: () => new ContextCreationError("Context is required", "context"),
41928
+ "site-id": () => new ContextCreationError("Context must contain siteId", "siteId"),
41929
+ token: () => new ContextCreationError(
41930
+ "Context must contain jwt or bearerToken for authentication",
41931
+ "bearerToken"
41932
+ ),
41933
+ "token-removed": () => new ContextCreationError(
41934
+ "fromContext options must not remove the context's bearer token",
41935
+ "bearerToken"
41936
+ )
41937
+ };
41741
41938
  var AugurAPI = class _AugurAPI {
41742
41939
  config;
41940
+ /** This client's call bounds: none, unless it is a view from `withRequest`. */
41941
+ bounds = NO_BOUNDS;
41743
41942
  _joomla;
41744
41943
  _commerce;
41745
41944
  _pricing;
@@ -41802,7 +42001,52 @@ var AugurAPI = class _AugurAPI {
41802
42001
  * ```
41803
42002
  */
41804
42003
  call(id, args) {
41805
- return callEndpoint(this.config, id, args);
42004
+ return callEndpoint(this.config, id, args, this.bounds);
42005
+ }
42006
+ /**
42007
+ * A view of this client whose every call is bounded by `options` (atlas#106): the caller's
42008
+ * `signal`, and a `deadline` in milliseconds for the whole call, retries and the waits between
42009
+ * them included. The view has this client's siteId, token, timeouts, retries and hooks, sends
42010
+ * the same headers, and builds its own service clients (sharing no in-flight request with this
42011
+ * one). Building a view and its first service costs about what building this client did, so
42012
+ * make one per bounded call, not per request inside a loop.
42013
+ *
42014
+ * @example
42015
+ * ```typescript
42016
+ * const items = await api.withRequest({ deadline: 5000 }).items.categories.items.list(uid, params);
42017
+ * ```
42018
+ *
42019
+ * @throws InvalidArgumentError when `signal` is given but not an AbortSignal, or `deadline` is
42020
+ * given but not a number from 0 to 2147483647 (NaN, Infinity or larger would fire at once).
42021
+ * Options can come from a browser through a server action, so their shape is checked.
42022
+ */
42023
+ withRequest(options) {
42024
+ const signal = options?.signal;
42025
+ const deadline = options?.deadline;
42026
+ const accepted = callOptionsAccepted(
42027
+ signal !== void 0,
42028
+ signal instanceof AbortSignal,
42029
+ deadline !== void 0,
42030
+ typeof deadline === "number" && deadlineInRange(deadline)
42031
+ );
42032
+ if (!accepted) {
42033
+ throw new InvalidArgumentError({
42034
+ message: "Invalid call options: signal must be an AbortSignal, deadline a number of milliseconds from 0 to 2147483647",
42035
+ service: "",
42036
+ endpoint: ""
42037
+ });
42038
+ }
42039
+ const view = new _AugurAPI(this.config);
42040
+ view.bounds = mergedBounds(
42041
+ this.bounds,
42042
+ signal,
42043
+ deadline
42044
+ );
42045
+ return view;
42046
+ }
42047
+ /** The HTTP client a service is built with: this client's config and call bounds. */
42048
+ httpFor(service) {
42049
+ return new HTTPClient(service, this.config, this.bounds);
41806
42050
  }
41807
42051
  /**
41808
42052
  * Create AugurAPI client from context object
@@ -41830,25 +42074,19 @@ var AugurAPI = class _AugurAPI {
41830
42074
  * @throws {ContextCreationError} When context is invalid or missing required fields
41831
42075
  */
41832
42076
  static fromContext(context, options = {}) {
41833
- if (!context) {
41834
- throw new ContextCreationError("Context is required", "context");
41835
- }
41836
- if (!context.siteId) {
41837
- throw new ContextCreationError("Context must contain siteId", "siteId");
41838
- }
41839
- const bearerToken = context.jwt || context.bearerToken;
41840
- if (!bearerToken) {
41841
- throw new ContextCreationError(
41842
- "Context must contain jwt or bearerToken for authentication",
41843
- "bearerToken"
41844
- );
41845
- }
42077
+ const bearerToken = context?.jwt || context?.bearerToken;
41846
42078
  const config = {
41847
- siteId: context.siteId,
42079
+ siteId: context?.siteId ?? "",
41848
42080
  bearerToken,
41849
42081
  ...options
41850
- // Allow overrides
41851
42082
  };
42083
+ const refusal = contextRefusalOf(
42084
+ Boolean(context),
42085
+ Boolean(context?.siteId),
42086
+ Boolean(bearerToken),
42087
+ Boolean(config.bearerToken)
42088
+ );
42089
+ if (refusal !== "ok") throw CONTEXT_REFUSALS[refusal]();
41852
42090
  return new _AugurAPI(config);
41853
42091
  }
41854
42092
  /**
@@ -41856,7 +42094,7 @@ var AugurAPI = class _AugurAPI {
41856
42094
  */
41857
42095
  get joomla() {
41858
42096
  if (!this._joomla) {
41859
- const httpClient = new HTTPClient("joomla", this.config);
42097
+ const httpClient = this.httpFor("joomla");
41860
42098
  this._joomla = new JoomlaClient(httpClient);
41861
42099
  }
41862
42100
  return this._joomla;
@@ -41866,7 +42104,7 @@ var AugurAPI = class _AugurAPI {
41866
42104
  */
41867
42105
  get commerce() {
41868
42106
  if (!this._commerce) {
41869
- const httpClient = new HTTPClient("commerce", this.config);
42107
+ const httpClient = this.httpFor("commerce");
41870
42108
  this._commerce = new CommerceClient(httpClient);
41871
42109
  }
41872
42110
  return this._commerce;
@@ -41876,7 +42114,7 @@ var AugurAPI = class _AugurAPI {
41876
42114
  */
41877
42115
  get pricing() {
41878
42116
  if (!this._pricing) {
41879
- const httpClient = new HTTPClient("pricing", this.config);
42117
+ const httpClient = this.httpFor("pricing");
41880
42118
  this._pricing = new PricingClient(httpClient);
41881
42119
  }
41882
42120
  return this._pricing;
@@ -41886,7 +42124,7 @@ var AugurAPI = class _AugurAPI {
41886
42124
  */
41887
42125
  get vmi() {
41888
42126
  if (!this._vmi) {
41889
- const httpClient = new HTTPClient("vmi", this.config);
42127
+ const httpClient = this.httpFor("vmi");
41890
42128
  this._vmi = new VMIClient(httpClient);
41891
42129
  }
41892
42130
  return this._vmi;
@@ -41896,7 +42134,7 @@ var AugurAPI = class _AugurAPI {
41896
42134
  */
41897
42135
  get openSearch() {
41898
42136
  if (!this._openSearch) {
41899
- const httpClient = new HTTPClient("open-search", this.config);
42137
+ const httpClient = this.httpFor("open-search");
41900
42138
  this._openSearch = new OpenSearchClient(httpClient);
41901
42139
  }
41902
42140
  return this._openSearch;
@@ -41906,7 +42144,7 @@ var AugurAPI = class _AugurAPI {
41906
42144
  */
41907
42145
  get items() {
41908
42146
  if (!this._items) {
41909
- const httpClient = new HTTPClient("items", this.config);
42147
+ const httpClient = this.httpFor("items");
41910
42148
  this._items = new ItemsClient(httpClient);
41911
42149
  }
41912
42150
  return this._items;
@@ -41916,7 +42154,7 @@ var AugurAPI = class _AugurAPI {
41916
42154
  */
41917
42155
  get legacy() {
41918
42156
  if (!this._legacy) {
41919
- const httpClient = new HTTPClient("legacy", this.config);
42157
+ const httpClient = this.httpFor("legacy");
41920
42158
  this._legacy = new LegacyClient(httpClient);
41921
42159
  }
41922
42160
  return this._legacy;
@@ -41926,7 +42164,7 @@ var AugurAPI = class _AugurAPI {
41926
42164
  */
41927
42165
  get agrSite() {
41928
42166
  if (!this._agrSite) {
41929
- const httpClient = new HTTPClient("agr-site", this.config);
42167
+ const httpClient = this.httpFor("agr-site");
41930
42168
  this._agrSite = new AgrSiteClient(httpClient);
41931
42169
  }
41932
42170
  return this._agrSite;
@@ -41936,7 +42174,7 @@ var AugurAPI = class _AugurAPI {
41936
42174
  */
41937
42175
  get customers() {
41938
42176
  if (!this._customers) {
41939
- const httpClient = new HTTPClient("customers", this.config);
42177
+ const httpClient = this.httpFor("customers");
41940
42178
  this._customers = new CustomersClient(httpClient);
41941
42179
  }
41942
42180
  return this._customers;
@@ -41946,7 +42184,7 @@ var AugurAPI = class _AugurAPI {
41946
42184
  */
41947
42185
  get orders() {
41948
42186
  if (!this._orders) {
41949
- const httpClient = new HTTPClient("orders", this.config);
42187
+ const httpClient = this.httpFor("orders");
41950
42188
  this._orders = new OrdersClient(httpClient);
41951
42189
  }
41952
42190
  return this._orders;
@@ -41956,7 +42194,7 @@ var AugurAPI = class _AugurAPI {
41956
42194
  */
41957
42195
  get p21Pim() {
41958
42196
  if (!this._p21Pim) {
41959
- const httpClient = new HTTPClient("p21-pim", this.config);
42197
+ const httpClient = this.httpFor("p21-pim");
41960
42198
  this._p21Pim = new P21PimClient(httpClient);
41961
42199
  }
41962
42200
  return this._p21Pim;
@@ -41966,7 +42204,7 @@ var AugurAPI = class _AugurAPI {
41966
42204
  */
41967
42205
  get payments() {
41968
42206
  if (!this._payments) {
41969
- const httpClient = new HTTPClient("payments", this.config);
42207
+ const httpClient = this.httpFor("payments");
41970
42208
  this._payments = new PaymentsClient(httpClient);
41971
42209
  }
41972
42210
  return this._payments;
@@ -41976,7 +42214,7 @@ var AugurAPI = class _AugurAPI {
41976
42214
  */
41977
42215
  get agrInfo() {
41978
42216
  if (!this._agrInfo) {
41979
- const httpClient = new HTTPClient("agr-info", this.config);
42217
+ const httpClient = this.httpFor("agr-info");
41980
42218
  this._agrInfo = new AgrInfoClient(httpClient);
41981
42219
  }
41982
42220
  return this._agrInfo;
@@ -41986,7 +42224,7 @@ var AugurAPI = class _AugurAPI {
41986
42224
  */
41987
42225
  get agrInt() {
41988
42226
  if (!this._agrInt) {
41989
- const httpClient = new HTTPClient("agr-int", this.config);
42227
+ const httpClient = this.httpFor("agr-int");
41990
42228
  this._agrInt = new AgrIntClient(httpClient);
41991
42229
  }
41992
42230
  return this._agrInt;
@@ -41996,7 +42234,7 @@ var AugurAPI = class _AugurAPI {
41996
42234
  */
41997
42235
  get agrWork() {
41998
42236
  if (!this._agrWork) {
41999
- const httpClient = new HTTPClient("agr-work", this.config);
42237
+ const httpClient = this.httpFor("agr-work");
42000
42238
  this._agrWork = new AgrWorkClient(httpClient);
42001
42239
  }
42002
42240
  return this._agrWork;
@@ -42006,7 +42244,7 @@ var AugurAPI = class _AugurAPI {
42006
42244
  */
42007
42245
  get avalara() {
42008
42246
  if (!this._avalara) {
42009
- const httpClient = new HTTPClient("avalara", this.config);
42247
+ const httpClient = this.httpFor("avalara");
42010
42248
  this._avalara = new AvalaraClient(httpClient);
42011
42249
  }
42012
42250
  return this._avalara;
@@ -42016,7 +42254,7 @@ var AugurAPI = class _AugurAPI {
42016
42254
  */
42017
42255
  get brandFolder() {
42018
42256
  if (!this._brandFolder) {
42019
- const httpClient = new HTTPClient("brand-folder", this.config);
42257
+ const httpClient = this.httpFor("brand-folder");
42020
42258
  this._brandFolder = new BrandFolderClient(httpClient);
42021
42259
  }
42022
42260
  return this._brandFolder;
@@ -42026,7 +42264,7 @@ var AugurAPI = class _AugurAPI {
42026
42264
  */
42027
42265
  get googMc() {
42028
42266
  if (!this._googMc) {
42029
- const httpClient = new HTTPClient("goog-mc", this.config);
42267
+ const httpClient = this.httpFor("goog-mc");
42030
42268
  this._googMc = new GoogMcClient(httpClient);
42031
42269
  }
42032
42270
  return this._googMc;
@@ -42036,7 +42274,7 @@ var AugurAPI = class _AugurAPI {
42036
42274
  */
42037
42275
  get gregorovich() {
42038
42276
  if (!this._gregorovich) {
42039
- const httpClient = new HTTPClient("gregorovich", this.config);
42277
+ const httpClient = this.httpFor("gregorovich");
42040
42278
  this._gregorovich = new GregorovichClient(httpClient);
42041
42279
  }
42042
42280
  return this._gregorovich;
@@ -42046,7 +42284,7 @@ var AugurAPI = class _AugurAPI {
42046
42284
  */
42047
42285
  get logistics() {
42048
42286
  if (!this._logistics) {
42049
- const httpClient = new HTTPClient("logistics", this.config);
42287
+ const httpClient = this.httpFor("logistics");
42050
42288
  this._logistics = new LogisticsClient(httpClient);
42051
42289
  }
42052
42290
  return this._logistics;
@@ -42056,7 +42294,7 @@ var AugurAPI = class _AugurAPI {
42056
42294
  */
42057
42295
  get markets() {
42058
42296
  if (!this._markets) {
42059
- const httpClient = new HTTPClient("markets", this.config);
42297
+ const httpClient = this.httpFor("markets");
42060
42298
  this._markets = new MarketsClient(httpClient);
42061
42299
  }
42062
42300
  return this._markets;
@@ -42066,7 +42304,7 @@ var AugurAPI = class _AugurAPI {
42066
42304
  */
42067
42305
  get notifications() {
42068
42306
  if (!this._notifications) {
42069
- const httpClient = new HTTPClient("notifications", this.config);
42307
+ const httpClient = this.httpFor("notifications");
42070
42308
  this._notifications = new NotificationsClient(httpClient);
42071
42309
  }
42072
42310
  return this._notifications;
@@ -42076,7 +42314,7 @@ var AugurAPI = class _AugurAPI {
42076
42314
  */
42077
42315
  get p21Apis() {
42078
42316
  if (!this._p21Apis) {
42079
- const httpClient = new HTTPClient("p21-apis", this.config);
42317
+ const httpClient = this.httpFor("p21-apis");
42080
42318
  this._p21Apis = new P21ApisClient(httpClient);
42081
42319
  }
42082
42320
  return this._p21Apis;
@@ -42086,7 +42324,7 @@ var AugurAPI = class _AugurAPI {
42086
42324
  */
42087
42325
  get p21Core() {
42088
42326
  if (!this._p21Core) {
42089
- const httpClient = new HTTPClient("p21-core", this.config);
42327
+ const httpClient = this.httpFor("p21-core");
42090
42328
  this._p21Core = new P21CoreClient(httpClient);
42091
42329
  }
42092
42330
  return this._p21Core;
@@ -42096,7 +42334,7 @@ var AugurAPI = class _AugurAPI {
42096
42334
  */
42097
42335
  get p21Sism() {
42098
42336
  if (!this._p21Sism) {
42099
- const httpClient = new HTTPClient("p21-sism", this.config);
42337
+ const httpClient = this.httpFor("p21-sism");
42100
42338
  this._p21Sism = new P21SismClient(httpClient);
42101
42339
  }
42102
42340
  return this._p21Sism;
@@ -42106,7 +42344,7 @@ var AugurAPI = class _AugurAPI {
42106
42344
  */
42107
42345
  get shipping() {
42108
42346
  if (!this._shipping) {
42109
- const httpClient = new HTTPClient("shipping", this.config);
42347
+ const httpClient = this.httpFor("shipping");
42110
42348
  this._shipping = new ShippingClient(httpClient);
42111
42349
  }
42112
42350
  return this._shipping;
@@ -42116,7 +42354,7 @@ var AugurAPI = class _AugurAPI {
42116
42354
  */
42117
42355
  get smartyStreets() {
42118
42356
  if (!this._smartyStreets) {
42119
- const httpClient = new HTTPClient("smarty-streets", this.config);
42357
+ const httpClient = this.httpFor("smarty-streets");
42120
42358
  this._smartyStreets = new SmartyStreetsClient(httpClient);
42121
42359
  }
42122
42360
  return this._smartyStreets;
@@ -42126,7 +42364,7 @@ var AugurAPI = class _AugurAPI {
42126
42364
  */
42127
42365
  get ups() {
42128
42366
  if (!this._ups) {
42129
- const httpClient = new HTTPClient("ups", this.config);
42367
+ const httpClient = this.httpFor("ups");
42130
42368
  this._ups = new UPSClient(httpClient);
42131
42369
  }
42132
42370
  return this._ups;
@@ -42136,7 +42374,7 @@ var AugurAPI = class _AugurAPI {
42136
42374
  */
42137
42375
  get vendors() {
42138
42376
  if (!this._vendors) {
42139
- const httpClient = new HTTPClient("vendors", this.config);
42377
+ const httpClient = this.httpFor("vendors");
42140
42378
  this._vendors = new VendorsClient(httpClient);
42141
42379
  }
42142
42380
  return this._vendors;
@@ -42146,13 +42384,18 @@ var AugurAPI = class _AugurAPI {
42146
42384
  */
42147
42385
  get basecamp2() {
42148
42386
  if (!this._basecamp2) {
42149
- const httpClient = new HTTPClient("basecamp2", this.config);
42387
+ const httpClient = this.httpFor("basecamp2");
42150
42388
  this._basecamp2 = new Basecamp2Client(httpClient);
42151
42389
  }
42152
42390
  return this._basecamp2;
42153
42391
  }
42154
42392
  /**
42155
42393
  * Update authentication token
42394
+ *
42395
+ * Every service read from this client afterwards (`api.items`, …) sends the new token. A
42396
+ * service object read BEFORE the change keeps the token it was built with: read services from
42397
+ * the client after a change, don't hold them across it (AugurApiClient.BuiltClientKeepsItsSnapshot).
42398
+ *
42156
42399
  * @param bearerToken New bearer token
42157
42400
  */
42158
42401
  setAuthToken(bearerToken) {
@@ -42161,6 +42404,9 @@ var AugurAPI = class _AugurAPI {
42161
42404
  }
42162
42405
  /**
42163
42406
  * Update site ID
42407
+ *
42408
+ * As with `setAuthToken`: a service object read before the change keeps the old siteId.
42409
+ *
42164
42410
  * @param siteId New site ID
42165
42411
  * @throws InvalidArgumentError when it is not a siteId (see the constructor)
42166
42412
  */
@@ -42257,7 +42503,7 @@ function createCrossSiteAuthenticator(augurInfoToken) {
42257
42503
  }
42258
42504
 
42259
42505
  // src/index.ts
42260
- var VERSION = "2026.11.3";
42506
+ var VERSION = "2026.11.4";
42261
42507
  export {
42262
42508
  AgrInfoClient,
42263
42509
  AgrIntClient,