@smithy/core 3.24.4 → 3.24.6

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.
Files changed (135) hide show
  1. package/dist-cjs/index.js +3 -4
  2. package/dist-cjs/submodules/client/index.js +3 -11
  3. package/dist-cjs/submodules/config/index.browser.js +2 -2
  4. package/dist-cjs/submodules/config/index.js +2 -2
  5. package/dist-cjs/submodules/config/index.native.js +2 -2
  6. package/dist-cjs/submodules/endpoints/index.browser.js +9 -40
  7. package/dist-cjs/submodules/endpoints/index.js +9 -40
  8. package/dist-cjs/submodules/protocols/index.js +12 -142
  9. package/dist-cjs/submodules/retry/index.browser.js +39 -22
  10. package/dist-cjs/submodules/retry/index.js +39 -22
  11. package/dist-cjs/submodules/schema/index.js +7 -9
  12. package/dist-cjs/submodules/serde/index.browser.js +2 -2
  13. package/dist-cjs/submodules/serde/index.js +2 -2
  14. package/dist-cjs/submodules/serde/index.native.js +2 -2
  15. package/dist-cjs/submodules/transport/index.js +184 -0
  16. package/dist-es/index.js +6 -6
  17. package/dist-es/submodules/client/index.js +2 -2
  18. package/dist-es/submodules/config/config-resolver/regionConfig/checkRegion.js +1 -1
  19. package/dist-es/submodules/endpoints/index.browser.js +2 -2
  20. package/dist-es/submodules/endpoints/index.js +2 -2
  21. package/dist-es/submodules/endpoints/middleware-endpoint/adaptors/toEndpointV1.js +1 -1
  22. package/dist-es/submodules/endpoints/middleware-endpoint/resolveEndpointConfig.js +1 -1
  23. package/dist-es/submodules/endpoints/util-endpoints/lib/index.js +1 -1
  24. package/dist-es/submodules/protocols/HttpBindingProtocol.js +1 -1
  25. package/dist-es/submodules/protocols/HttpProtocol.js +1 -2
  26. package/dist-es/submodules/protocols/RpcProtocol.js +1 -1
  27. package/dist-es/submodules/protocols/index.js +5 -5
  28. package/dist-es/submodules/protocols/middleware-content-length/contentLengthMiddleware.js +1 -1
  29. package/dist-es/submodules/protocols/requestBuilder.js +1 -1
  30. package/dist-es/submodules/retry/middleware-retry/configurations.js +19 -6
  31. package/dist-es/submodules/retry/middleware-retry/retryMiddleware.js +4 -5
  32. package/dist-es/submodules/retry/service-error-classification/constants.js +1 -1
  33. package/dist-es/submodules/retry/util-retry/ConfiguredRetryStrategy.js +4 -5
  34. package/dist-es/submodules/retry/util-retry/DefaultRetryToken.js +3 -0
  35. package/dist-es/submodules/retry/util-retry/StandardRetryStrategy.js +9 -5
  36. package/dist-es/submodules/schema/middleware/schemaDeserializationMiddleware.js +3 -4
  37. package/dist-es/submodules/schema/middleware/schemaSerializationMiddleware.js +1 -2
  38. package/dist-es/submodules/serde/middleware-serde/deserializerMiddleware.js +1 -1
  39. package/dist-es/submodules/transport/index.js +9 -0
  40. package/dist-es/submodules/{protocols/url-parser → transport}/parseUrl.js +1 -1
  41. package/dist-es/submodules/{endpoints → transport}/toEndpointV1.js +1 -1
  42. package/dist-types/index.d.ts +10 -6
  43. package/dist-types/submodules/client/index.d.ts +2 -2
  44. package/dist-types/submodules/endpoints/index.browser.d.ts +2 -2
  45. package/dist-types/submodules/endpoints/index.d.ts +2 -2
  46. package/dist-types/submodules/endpoints/middleware-endpoint/adaptors/toEndpointV1.d.ts +2 -2
  47. package/dist-types/submodules/endpoints/util-endpoints/lib/index.d.ts +1 -1
  48. package/dist-types/submodules/protocols/HttpBindingProtocol.d.ts +1 -1
  49. package/dist-types/submodules/protocols/index.d.ts +5 -5
  50. package/dist-types/submodules/protocols/protocol-http/httpHandler.d.ts +1 -2
  51. package/dist-types/submodules/protocols/requestBuilder.d.ts +1 -1
  52. package/dist-types/submodules/retry/middleware-retry/configurations.d.ts +4 -1
  53. package/dist-types/submodules/retry/util-retry/ConfiguredRetryStrategy.d.ts +1 -2
  54. package/dist-types/submodules/retry/util-retry/DefaultRetryToken.d.ts +3 -0
  55. package/dist-types/submodules/retry/util-retry/StandardRetryStrategy.d.ts +1 -1
  56. package/dist-types/submodules/transport/index.d.ts +9 -0
  57. package/package.json +20 -11
  58. package/transport.d.ts +5 -0
  59. package/transport.js +5 -0
  60. package/dist-cjs/getSmithyContext.js +0 -6
  61. package/dist-cjs/middleware-http-auth-scheme/getHttpAuthSchemeEndpointRuleSetPlugin.js +0 -21
  62. package/dist-cjs/middleware-http-auth-scheme/getHttpAuthSchemePlugin.js +0 -21
  63. package/dist-cjs/middleware-http-auth-scheme/httpAuthSchemeMiddleware.js +0 -46
  64. package/dist-cjs/middleware-http-auth-scheme/index.js +0 -6
  65. package/dist-cjs/middleware-http-auth-scheme/resolveAuthOptions.js +0 -24
  66. package/dist-cjs/middleware-http-signing/getHttpSigningMiddleware.js +0 -19
  67. package/dist-cjs/middleware-http-signing/httpSigningMiddleware.js +0 -27
  68. package/dist-cjs/middleware-http-signing/index.js +0 -5
  69. package/dist-cjs/normalizeProvider.js +0 -10
  70. package/dist-cjs/pagination/createPaginator.js +0 -44
  71. package/dist-cjs/request-builder/requestBuilder.js +0 -5
  72. package/dist-cjs/setFeature.js +0 -14
  73. package/dist-cjs/util-identity-and-auth/DefaultIdentityProviderConfig.js +0 -18
  74. package/dist-cjs/util-identity-and-auth/httpAuthSchemes/httpApiKeyAuth.js +0 -38
  75. package/dist-cjs/util-identity-and-auth/httpAuthSchemes/httpBearerAuth.js +0 -15
  76. package/dist-cjs/util-identity-and-auth/httpAuthSchemes/index.js +0 -6
  77. package/dist-cjs/util-identity-and-auth/httpAuthSchemes/noAuth.js +0 -9
  78. package/dist-cjs/util-identity-and-auth/index.js +0 -6
  79. package/dist-cjs/util-identity-and-auth/memoizeIdentityProvider.js +0 -61
  80. package/dist-es/request-builder/requestBuilder.js +0 -1
  81. package/dist-es/submodules/client/util-middleware/getSmithyContext.js +0 -2
  82. package/dist-es/submodules/event-streams/eventstream-codec/TestVectors.fixture.js +0 -146
  83. package/dist-es/submodules/event-streams/eventstream-codec/vectorTypes.fixture.js +0 -1
  84. package/dist-types/request-builder/requestBuilder.d.ts +0 -6
  85. package/dist-types/submodules/client/util-middleware/getSmithyContext.d.ts +0 -5
  86. package/dist-types/submodules/event-streams/eventstream-codec/TestVectors.fixture.d.ts +0 -2
  87. package/dist-types/submodules/event-streams/eventstream-codec/vectorTypes.fixture.d.ts +0 -12
  88. /package/dist-es/{middleware-http-auth-scheme → legacy-root-exports/middleware-http-auth-scheme}/getHttpAuthSchemeEndpointRuleSetPlugin.js +0 -0
  89. /package/dist-es/{middleware-http-auth-scheme → legacy-root-exports/middleware-http-auth-scheme}/getHttpAuthSchemePlugin.js +0 -0
  90. /package/dist-es/{middleware-http-auth-scheme → legacy-root-exports/middleware-http-auth-scheme}/httpAuthSchemeMiddleware.js +0 -0
  91. /package/dist-es/{middleware-http-auth-scheme → legacy-root-exports/middleware-http-auth-scheme}/index.js +0 -0
  92. /package/dist-es/{middleware-http-auth-scheme → legacy-root-exports/middleware-http-auth-scheme}/resolveAuthOptions.js +0 -0
  93. /package/dist-es/{middleware-http-signing → legacy-root-exports/middleware-http-signing}/getHttpSigningMiddleware.js +0 -0
  94. /package/dist-es/{middleware-http-signing → legacy-root-exports/middleware-http-signing}/httpSigningMiddleware.js +0 -0
  95. /package/dist-es/{middleware-http-signing → legacy-root-exports/middleware-http-signing}/index.js +0 -0
  96. /package/dist-es/{pagination → legacy-root-exports/pagination}/createPaginator.js +0 -0
  97. /package/dist-es/{util-identity-and-auth → legacy-root-exports/util-identity-and-auth}/DefaultIdentityProviderConfig.js +0 -0
  98. /package/dist-es/{util-identity-and-auth → legacy-root-exports/util-identity-and-auth}/httpAuthSchemes/httpApiKeyAuth.js +0 -0
  99. /package/dist-es/{util-identity-and-auth → legacy-root-exports/util-identity-and-auth}/httpAuthSchemes/httpBearerAuth.js +0 -0
  100. /package/dist-es/{util-identity-and-auth → legacy-root-exports/util-identity-and-auth}/httpAuthSchemes/index.js +0 -0
  101. /package/dist-es/{util-identity-and-auth → legacy-root-exports/util-identity-and-auth}/httpAuthSchemes/noAuth.js +0 -0
  102. /package/dist-es/{util-identity-and-auth → legacy-root-exports/util-identity-and-auth}/index.js +0 -0
  103. /package/dist-es/{util-identity-and-auth → legacy-root-exports/util-identity-and-auth}/memoizeIdentityProvider.js +0 -0
  104. /package/dist-es/{getSmithyContext.js → submodules/transport/getSmithyContext.js} +0 -0
  105. /package/dist-es/submodules/{protocols/protocol-http → transport}/httpRequest.js +0 -0
  106. /package/dist-es/submodules/{protocols/protocol-http → transport}/httpResponse.js +0 -0
  107. /package/dist-es/submodules/{endpoints/util-endpoints/lib → transport}/isValidHostLabel.js +0 -0
  108. /package/dist-es/submodules/{protocols/protocol-http → transport}/isValidHostname.js +0 -0
  109. /package/dist-es/submodules/{client/util-middleware → transport}/normalizeProvider.js +0 -0
  110. /package/dist-es/submodules/{protocols/querystring-parser → transport}/parseQueryString.js +0 -0
  111. /package/dist-types/{middleware-http-auth-scheme → legacy-root-exports/middleware-http-auth-scheme}/getHttpAuthSchemeEndpointRuleSetPlugin.d.ts +0 -0
  112. /package/dist-types/{middleware-http-auth-scheme → legacy-root-exports/middleware-http-auth-scheme}/getHttpAuthSchemePlugin.d.ts +0 -0
  113. /package/dist-types/{middleware-http-auth-scheme → legacy-root-exports/middleware-http-auth-scheme}/httpAuthSchemeMiddleware.d.ts +0 -0
  114. /package/dist-types/{middleware-http-auth-scheme → legacy-root-exports/middleware-http-auth-scheme}/index.d.ts +0 -0
  115. /package/dist-types/{middleware-http-auth-scheme → legacy-root-exports/middleware-http-auth-scheme}/resolveAuthOptions.d.ts +0 -0
  116. /package/dist-types/{middleware-http-signing → legacy-root-exports/middleware-http-signing}/getHttpSigningMiddleware.d.ts +0 -0
  117. /package/dist-types/{middleware-http-signing → legacy-root-exports/middleware-http-signing}/httpSigningMiddleware.d.ts +0 -0
  118. /package/dist-types/{middleware-http-signing → legacy-root-exports/middleware-http-signing}/index.d.ts +0 -0
  119. /package/dist-types/{pagination → legacy-root-exports/pagination}/createPaginator.d.ts +0 -0
  120. /package/dist-types/{util-identity-and-auth → legacy-root-exports/util-identity-and-auth}/DefaultIdentityProviderConfig.d.ts +0 -0
  121. /package/dist-types/{util-identity-and-auth → legacy-root-exports/util-identity-and-auth}/httpAuthSchemes/httpApiKeyAuth.d.ts +0 -0
  122. /package/dist-types/{util-identity-and-auth → legacy-root-exports/util-identity-and-auth}/httpAuthSchemes/httpBearerAuth.d.ts +0 -0
  123. /package/dist-types/{util-identity-and-auth → legacy-root-exports/util-identity-and-auth}/httpAuthSchemes/index.d.ts +0 -0
  124. /package/dist-types/{util-identity-and-auth → legacy-root-exports/util-identity-and-auth}/httpAuthSchemes/noAuth.d.ts +0 -0
  125. /package/dist-types/{util-identity-and-auth → legacy-root-exports/util-identity-and-auth}/index.d.ts +0 -0
  126. /package/dist-types/{util-identity-and-auth → legacy-root-exports/util-identity-and-auth}/memoizeIdentityProvider.d.ts +0 -0
  127. /package/dist-types/{getSmithyContext.d.ts → submodules/transport/getSmithyContext.d.ts} +0 -0
  128. /package/dist-types/submodules/{protocols/protocol-http → transport}/httpRequest.d.ts +0 -0
  129. /package/dist-types/submodules/{protocols/protocol-http → transport}/httpResponse.d.ts +0 -0
  130. /package/dist-types/submodules/{endpoints/util-endpoints/lib → transport}/isValidHostLabel.d.ts +0 -0
  131. /package/dist-types/submodules/{protocols/protocol-http → transport}/isValidHostname.d.ts +0 -0
  132. /package/dist-types/submodules/{client/util-middleware → transport}/normalizeProvider.d.ts +0 -0
  133. /package/dist-types/submodules/{protocols/querystring-parser → transport}/parseQueryString.d.ts +0 -0
  134. /package/dist-types/submodules/{protocols/url-parser → transport}/parseUrl.d.ts +0 -0
  135. /package/dist-types/submodules/{endpoints → transport}/toEndpointV1.d.ts +0 -0
@@ -33,7 +33,7 @@ const THROTTLING_ERROR_CODES = [
33
33
  const TRANSIENT_ERROR_CODES = ["TimeoutError", "RequestTimeout", "RequestTimeoutException"];
34
34
  const TRANSIENT_ERROR_STATUS_CODES = [500, 502, 503, 504];
35
35
  const NODEJS_TIMEOUT_ERROR_CODES = ["ECONNRESET", "ECONNREFUSED", "EPIPE", "ETIMEDOUT"];
36
- const NODEJS_NETWORK_ERROR_CODES = ["EHOSTUNREACH", "ENETUNREACH", "ENOTFOUND"];
36
+ const NODEJS_NETWORK_ERROR_CODES = ["EHOSTUNREACH", "ENETUNREACH", "ENOTFOUND", "EAI_AGAIN"];
37
37
 
38
38
  const isRetryableByTrait = (error) => error?.$retryable !== undefined;
39
39
  const isClockSkewError = (error) => CLOCK_SKEW_ERROR_CODES.includes(error.name);
@@ -184,9 +184,6 @@ function bindRetryMiddleware(isStreamingPayload) {
184
184
  retryToken = await retryStrategy.refreshRetryTokenForRetry(retryToken, retryErrorInfo);
185
185
  }
186
186
  catch (refreshError) {
187
- if (typeof refreshError.$backoff === "number") {
188
- await cooldown(refreshError.$backoff);
189
- }
190
187
  if (!lastError.$metadata) {
191
188
  lastError.$metadata = {};
192
189
  }
@@ -196,8 +193,10 @@ function bindRetryMiddleware(isStreamingPayload) {
196
193
  }
197
194
  attempts = retryToken.getRetryCount();
198
195
  const delay = retryToken.getRetryDelay();
199
- totalRetryDelay += delay;
200
- await cooldown(delay);
196
+ totalRetryDelay += (retryToken?.$retryLog?.acquisitionDelay ?? 0) + delay;
197
+ if (delay > 0) {
198
+ await cooldown(delay);
199
+ }
201
200
  }
202
201
  }
203
202
  }
@@ -398,6 +397,9 @@ class DefaultRetryToken {
398
397
  count;
399
398
  cost;
400
399
  longPoll;
400
+ $retryLog = {
401
+ acquisitionDelay: 0,
402
+ };
401
403
  constructor(delay, count, cost, longPoll) {
402
404
  this.delay = delay;
403
405
  this.count = count;
@@ -433,8 +435,8 @@ const refusal = {
433
435
  };
434
436
  let StandardRetryStrategy$1 = class StandardRetryStrategy {
435
437
  mode = exports.RETRY_MODES.STANDARD;
436
- capacity = INITIAL_RETRY_TOKENS;
437
438
  retryBackoffStrategy;
439
+ capacity = INITIAL_RETRY_TOKENS;
438
440
  maxAttemptsProvider;
439
441
  baseDelay;
440
442
  constructor(arg1) {
@@ -470,14 +472,18 @@ let StandardRetryStrategy$1 = class StandardRetryStrategy {
470
472
  retryDelay = Math.max(delayFromErrorType, Math.min(errorInfo.retryAfterHint.getTime() - Date.now(), delayFromErrorType + 5_000));
471
473
  }
472
474
  if (!shouldRetry) {
473
- throw Object.assign(new Error("No retry token available"), {
474
- $backoff: Retry.v2026 && retryCode === refusal.capacity && isLongPoll ? retryDelay : 0,
475
- });
475
+ const longPollBackoff = Retry.v2026 && retryCode === refusal.capacity && isLongPoll ? retryDelay : 0;
476
+ if (longPollBackoff > 0) {
477
+ await new Promise((r) => setTimeout(r, longPollBackoff));
478
+ }
476
479
  }
477
480
  else {
478
481
  const capacityCost = this.getCapacityCost(errorType);
479
482
  this.capacity -= capacityCost;
480
- return new DefaultRetryToken(retryDelay, token.getRetryCount() + 1, capacityCost, token.isLongPoll?.() ?? false);
483
+ const nextToken = new DefaultRetryToken(0, token.getRetryCount() + 1, capacityCost, token.isLongPoll?.() ?? false);
484
+ await new Promise((r) => setTimeout(r, retryDelay));
485
+ nextToken.$retryLog.acquisitionDelay = retryDelay;
486
+ return nextToken;
481
487
  }
482
488
  }
483
489
  throw new Error("No retry token available");
@@ -559,11 +565,10 @@ class ConfiguredRetryStrategy extends StandardRetryStrategy$1 {
559
565
  else {
560
566
  this.computeNextBackoffDelay = computeNextBackoffDelay;
561
567
  }
562
- }
563
- async refreshRetryTokenForRetry(tokenToRenew, errorInfo) {
564
- const token = await super.refreshRetryTokenForRetry(tokenToRenew, errorInfo);
565
- token.getRetryDelay = () => this.computeNextBackoffDelay(token.getRetryCount());
566
- return token;
568
+ this.retryBackoffStrategy.computeNextBackoffDelay = (completedAttempt) => {
569
+ const nextAttempt = completedAttempt + 1;
570
+ return this.computeNextBackoffDelay(nextAttempt);
571
+ };
567
572
  }
568
573
  }
569
574
 
@@ -710,17 +715,29 @@ class AdaptiveRetryStrategy extends StandardRetryStrategy {
710
715
  }
711
716
  }
712
717
 
713
- const resolveRetryConfig = (input) => {
718
+ const resolveRetryConfig = (input, defaults) => {
714
719
  const { retryStrategy, retryMode } = input;
715
- const maxAttempts = client.normalizeProvider(input.maxAttempts ?? DEFAULT_MAX_ATTEMPTS);
720
+ const { defaultMaxAttempts = DEFAULT_MAX_ATTEMPTS, defaultBaseDelay = Retry.delay() } = defaults ?? {};
721
+ const maxAttemptsProvider = client.normalizeProvider(input.maxAttempts ?? defaultMaxAttempts);
716
722
  let controller = retryStrategy
717
723
  ? Promise.resolve(retryStrategy)
718
724
  : undefined;
719
- const getDefault = async () => (await client.normalizeProvider(retryMode)()) === exports.RETRY_MODES.ADAPTIVE
720
- ? new AdaptiveRetryStrategy$1(maxAttempts)
721
- : new StandardRetryStrategy$1(maxAttempts);
725
+ const getDefault = async () => {
726
+ const maxAttempts = await maxAttemptsProvider();
727
+ const adaptive = (await client.normalizeProvider(retryMode)()) === exports.RETRY_MODES.ADAPTIVE;
728
+ if (adaptive) {
729
+ return new AdaptiveRetryStrategy$1(maxAttemptsProvider, {
730
+ maxAttempts,
731
+ baseDelay: defaultBaseDelay,
732
+ });
733
+ }
734
+ return new StandardRetryStrategy$1({
735
+ maxAttempts,
736
+ baseDelay: defaultBaseDelay,
737
+ });
738
+ };
722
739
  return Object.assign(input, {
723
- maxAttempts,
740
+ maxAttempts: maxAttemptsProvider,
724
741
  retryStrategy: () => (controller ??= getDefault()),
725
742
  });
726
743
  };
@@ -35,7 +35,7 @@ const THROTTLING_ERROR_CODES = [
35
35
  const TRANSIENT_ERROR_CODES = ["TimeoutError", "RequestTimeout", "RequestTimeoutException"];
36
36
  const TRANSIENT_ERROR_STATUS_CODES = [500, 502, 503, 504];
37
37
  const NODEJS_TIMEOUT_ERROR_CODES = ["ECONNRESET", "ECONNREFUSED", "EPIPE", "ETIMEDOUT"];
38
- const NODEJS_NETWORK_ERROR_CODES = ["EHOSTUNREACH", "ENETUNREACH", "ENOTFOUND"];
38
+ const NODEJS_NETWORK_ERROR_CODES = ["EHOSTUNREACH", "ENETUNREACH", "ENOTFOUND", "EAI_AGAIN"];
39
39
 
40
40
  const isRetryableByTrait = (error) => error?.$retryable !== undefined;
41
41
  const isClockSkewError = (error) => CLOCK_SKEW_ERROR_CODES.includes(error.name);
@@ -186,9 +186,6 @@ function bindRetryMiddleware(isStreamingPayload) {
186
186
  retryToken = await retryStrategy.refreshRetryTokenForRetry(retryToken, retryErrorInfo);
187
187
  }
188
188
  catch (refreshError) {
189
- if (typeof refreshError.$backoff === "number") {
190
- await cooldown(refreshError.$backoff);
191
- }
192
189
  if (!lastError.$metadata) {
193
190
  lastError.$metadata = {};
194
191
  }
@@ -198,8 +195,10 @@ function bindRetryMiddleware(isStreamingPayload) {
198
195
  }
199
196
  attempts = retryToken.getRetryCount();
200
197
  const delay = retryToken.getRetryDelay();
201
- totalRetryDelay += delay;
202
- await cooldown(delay);
198
+ totalRetryDelay += (retryToken?.$retryLog?.acquisitionDelay ?? 0) + delay;
199
+ if (delay > 0) {
200
+ await cooldown(delay);
201
+ }
203
202
  }
204
203
  }
205
204
  }
@@ -400,6 +399,9 @@ class DefaultRetryToken {
400
399
  count;
401
400
  cost;
402
401
  longPoll;
402
+ $retryLog = {
403
+ acquisitionDelay: 0,
404
+ };
403
405
  constructor(delay, count, cost, longPoll) {
404
406
  this.delay = delay;
405
407
  this.count = count;
@@ -435,8 +437,8 @@ const refusal = {
435
437
  };
436
438
  let StandardRetryStrategy$1 = class StandardRetryStrategy {
437
439
  mode = exports.RETRY_MODES.STANDARD;
438
- capacity = INITIAL_RETRY_TOKENS;
439
440
  retryBackoffStrategy;
441
+ capacity = INITIAL_RETRY_TOKENS;
440
442
  maxAttemptsProvider;
441
443
  baseDelay;
442
444
  constructor(arg1) {
@@ -472,14 +474,18 @@ let StandardRetryStrategy$1 = class StandardRetryStrategy {
472
474
  retryDelay = Math.max(delayFromErrorType, Math.min(errorInfo.retryAfterHint.getTime() - Date.now(), delayFromErrorType + 5_000));
473
475
  }
474
476
  if (!shouldRetry) {
475
- throw Object.assign(new Error("No retry token available"), {
476
- $backoff: Retry.v2026 && retryCode === refusal.capacity && isLongPoll ? retryDelay : 0,
477
- });
477
+ const longPollBackoff = Retry.v2026 && retryCode === refusal.capacity && isLongPoll ? retryDelay : 0;
478
+ if (longPollBackoff > 0) {
479
+ await new Promise((r) => setTimeout(r, longPollBackoff));
480
+ }
478
481
  }
479
482
  else {
480
483
  const capacityCost = this.getCapacityCost(errorType);
481
484
  this.capacity -= capacityCost;
482
- return new DefaultRetryToken(retryDelay, token.getRetryCount() + 1, capacityCost, token.isLongPoll?.() ?? false);
485
+ const nextToken = new DefaultRetryToken(0, token.getRetryCount() + 1, capacityCost, token.isLongPoll?.() ?? false);
486
+ await new Promise((r) => setTimeout(r, retryDelay));
487
+ nextToken.$retryLog.acquisitionDelay = retryDelay;
488
+ return nextToken;
483
489
  }
484
490
  }
485
491
  throw new Error("No retry token available");
@@ -561,11 +567,10 @@ class ConfiguredRetryStrategy extends StandardRetryStrategy$1 {
561
567
  else {
562
568
  this.computeNextBackoffDelay = computeNextBackoffDelay;
563
569
  }
564
- }
565
- async refreshRetryTokenForRetry(tokenToRenew, errorInfo) {
566
- const token = await super.refreshRetryTokenForRetry(tokenToRenew, errorInfo);
567
- token.getRetryDelay = () => this.computeNextBackoffDelay(token.getRetryCount());
568
- return token;
570
+ this.retryBackoffStrategy.computeNextBackoffDelay = (completedAttempt) => {
571
+ const nextAttempt = completedAttempt + 1;
572
+ return this.computeNextBackoffDelay(nextAttempt);
573
+ };
569
574
  }
570
575
  }
571
576
 
@@ -737,17 +742,29 @@ const NODE_MAX_ATTEMPT_CONFIG_OPTIONS = {
737
742
  },
738
743
  default: DEFAULT_MAX_ATTEMPTS,
739
744
  };
740
- const resolveRetryConfig = (input) => {
745
+ const resolveRetryConfig = (input, defaults) => {
741
746
  const { retryStrategy, retryMode } = input;
742
- const maxAttempts = client.normalizeProvider(input.maxAttempts ?? DEFAULT_MAX_ATTEMPTS);
747
+ const { defaultMaxAttempts = DEFAULT_MAX_ATTEMPTS, defaultBaseDelay = Retry.delay() } = defaults ?? {};
748
+ const maxAttemptsProvider = client.normalizeProvider(input.maxAttempts ?? defaultMaxAttempts);
743
749
  let controller = retryStrategy
744
750
  ? Promise.resolve(retryStrategy)
745
751
  : undefined;
746
- const getDefault = async () => (await client.normalizeProvider(retryMode)()) === exports.RETRY_MODES.ADAPTIVE
747
- ? new AdaptiveRetryStrategy$1(maxAttempts)
748
- : new StandardRetryStrategy$1(maxAttempts);
752
+ const getDefault = async () => {
753
+ const maxAttempts = await maxAttemptsProvider();
754
+ const adaptive = (await client.normalizeProvider(retryMode)()) === exports.RETRY_MODES.ADAPTIVE;
755
+ if (adaptive) {
756
+ return new AdaptiveRetryStrategy$1(maxAttemptsProvider, {
757
+ maxAttempts,
758
+ baseDelay: defaultBaseDelay,
759
+ });
760
+ }
761
+ return new StandardRetryStrategy$1({
762
+ maxAttempts,
763
+ baseDelay: defaultBaseDelay,
764
+ });
765
+ };
749
766
  return Object.assign(input, {
750
- maxAttempts,
767
+ maxAttempts: maxAttemptsProvider,
751
768
  retryStrategy: () => (controller ??= getDefault()),
752
769
  });
753
770
  };
@@ -1,8 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var client = require('@smithy/core/client');
4
- var protocols = require('@smithy/core/protocols');
5
- var endpoints = require('@smithy/core/endpoints');
3
+ var transport = require('@smithy/core/transport');
6
4
 
7
5
  const deref = (schemaRef) => {
8
6
  if (typeof schemaRef === "function") {
@@ -21,7 +19,7 @@ const operation = (namespace, name, traits, input, output) => ({
21
19
 
22
20
  const schemaDeserializationMiddleware = (config) => (next, context) => async (args) => {
23
21
  const { response } = await next(args);
24
- const { operationSchema } = client.getSmithyContext(context);
22
+ const { operationSchema } = transport.getSmithyContext(context);
25
23
  const [, ns, n, t, i, o] = operationSchema ?? [];
26
24
  try {
27
25
  const parsed = await config.protocol.deserializeResponse(operation(ns, n, t, i, o), {
@@ -59,11 +57,11 @@ const schemaDeserializationMiddleware = (config) => (next, context) => async (ar
59
57
  }
60
58
  }
61
59
  try {
62
- if (protocols.HttpResponse.isInstance(response)) {
63
- const { headers = {} } = response;
60
+ if (transport.HttpResponse.isInstance(response)) {
61
+ const { headers = {}, statusCode } = response;
64
62
  const headerEntries = Object.entries(headers);
65
63
  error.$metadata = {
66
- httpStatusCode: response.statusCode,
64
+ httpStatusCode: statusCode,
67
65
  requestId: findHeader(/^x-[\w-]+-request-?id$/, headerEntries),
68
66
  extendedRequestId: findHeader(/^x-[\w-]+-id-2$/, headerEntries),
69
67
  cfId: findHeader(/^x-[\w-]+-cf-id$/, headerEntries),
@@ -83,10 +81,10 @@ const findHeader = (pattern, headers) => {
83
81
  };
84
82
 
85
83
  const schemaSerializationMiddleware = (config) => (next, context) => async (args) => {
86
- const { operationSchema } = client.getSmithyContext(context);
84
+ const { operationSchema } = transport.getSmithyContext(context);
87
85
  const [, ns, n, t, i, o] = operationSchema ?? [];
88
86
  const endpoint = context.endpointV2
89
- ? async () => endpoints.toEndpointV1(context.endpointV2)
87
+ ? async () => transport.toEndpointV1(context.endpointV2)
90
88
  : config.endpoint;
91
89
  const request = await config.protocol.serializeRequest(operation(ns, n, t, i, o), args.input, {
92
90
  ...config,
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var protocols = require('@smithy/core/protocols');
3
+ var transport = require('@smithy/core/transport');
4
4
  var endpoints = require('@smithy/core/endpoints');
5
5
 
6
6
  const chars = `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`;
@@ -912,7 +912,7 @@ const deserializerMiddleware = (options, deserializer) => (next, context) => asy
912
912
  }
913
913
  }
914
914
  try {
915
- if (protocols.HttpResponse.isInstance(response)) {
915
+ if (transport.HttpResponse.isInstance(response)) {
916
916
  const { headers = {} } = response;
917
917
  const headerEntries = Object.entries(headers);
918
918
  error.$metadata = {
@@ -2,7 +2,7 @@
2
2
 
3
3
  var node_crypto = require('node:crypto');
4
4
  var node_fs = require('node:fs');
5
- var protocols = require('@smithy/core/protocols');
5
+ var transport = require('@smithy/core/transport');
6
6
  var endpoints = require('@smithy/core/endpoints');
7
7
  var node_stream = require('node:stream');
8
8
 
@@ -877,7 +877,7 @@ const deserializerMiddleware = (options, deserializer) => (next, context) => asy
877
877
  }
878
878
  }
879
879
  try {
880
- if (protocols.HttpResponse.isInstance(response)) {
880
+ if (transport.HttpResponse.isInstance(response)) {
881
881
  const { headers = {} } = response;
882
882
  const headerEntries = Object.entries(headers);
883
883
  error.$metadata = {
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var protocols = require('@smithy/core/protocols');
3
+ var transport = require('@smithy/core/transport');
4
4
  var endpoints = require('@smithy/core/endpoints');
5
5
 
6
6
  const chars = `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`;
@@ -912,7 +912,7 @@ const deserializerMiddleware = (options, deserializer) => (next, context) => asy
912
912
  }
913
913
  }
914
914
  try {
915
- if (protocols.HttpResponse.isInstance(response)) {
915
+ if (transport.HttpResponse.isInstance(response)) {
916
916
  const { headers = {} } = response;
917
917
  const headerEntries = Object.entries(headers);
918
918
  error.$metadata = {
@@ -0,0 +1,184 @@
1
+ 'use strict';
2
+
3
+ var types = require('@smithy/types');
4
+
5
+ const getSmithyContext = (context) => context[types.SMITHY_CONTEXT_KEY] || (context[types.SMITHY_CONTEXT_KEY] = {});
6
+
7
+ class HttpRequest {
8
+ method;
9
+ protocol;
10
+ hostname;
11
+ port;
12
+ path;
13
+ query;
14
+ headers;
15
+ username;
16
+ password;
17
+ fragment;
18
+ body;
19
+ constructor(options) {
20
+ this.method = options.method || "GET";
21
+ this.hostname = options.hostname || "localhost";
22
+ this.port = options.port;
23
+ this.query = options.query || {};
24
+ this.headers = options.headers || {};
25
+ this.body = options.body;
26
+ this.protocol = options.protocol
27
+ ? options.protocol.slice(-1) !== ":"
28
+ ? `${options.protocol}:`
29
+ : options.protocol
30
+ : "https:";
31
+ this.path = options.path ? (options.path.charAt(0) !== "/" ? `/${options.path}` : options.path) : "/";
32
+ this.username = options.username;
33
+ this.password = options.password;
34
+ this.fragment = options.fragment;
35
+ }
36
+ static clone(request) {
37
+ const cloned = new HttpRequest({
38
+ ...request,
39
+ headers: { ...request.headers },
40
+ });
41
+ if (cloned.query) {
42
+ cloned.query = cloneQuery(cloned.query);
43
+ }
44
+ return cloned;
45
+ }
46
+ static isInstance(request) {
47
+ if (!request) {
48
+ return false;
49
+ }
50
+ const req = request;
51
+ return ("method" in req &&
52
+ "protocol" in req &&
53
+ "hostname" in req &&
54
+ "path" in req &&
55
+ typeof req["query"] === "object" &&
56
+ typeof req["headers"] === "object");
57
+ }
58
+ clone() {
59
+ return HttpRequest.clone(this);
60
+ }
61
+ }
62
+ function cloneQuery(query) {
63
+ return Object.keys(query).reduce((carry, paramName) => {
64
+ const param = query[paramName];
65
+ return {
66
+ ...carry,
67
+ [paramName]: Array.isArray(param) ? [...param] : param,
68
+ };
69
+ }, {});
70
+ }
71
+
72
+ class HttpResponse {
73
+ statusCode;
74
+ reason;
75
+ headers;
76
+ body;
77
+ constructor(options) {
78
+ this.statusCode = options.statusCode;
79
+ this.reason = options.reason;
80
+ this.headers = options.headers || {};
81
+ this.body = options.body;
82
+ }
83
+ static isInstance(response) {
84
+ if (!response)
85
+ return false;
86
+ const resp = response;
87
+ return typeof resp.statusCode === "number" && typeof resp.headers === "object";
88
+ }
89
+ }
90
+
91
+ const VALID_HOST_LABEL_REGEX = new RegExp(`^(?!.*-$)(?!-)[a-zA-Z0-9-]{1,63}$`);
92
+ const isValidHostLabel = (value, allowSubDomains = false) => {
93
+ if (!allowSubDomains) {
94
+ return VALID_HOST_LABEL_REGEX.test(value);
95
+ }
96
+ const labels = value.split(".");
97
+ for (const label of labels) {
98
+ if (!isValidHostLabel(label)) {
99
+ return false;
100
+ }
101
+ }
102
+ return true;
103
+ };
104
+
105
+ function isValidHostname(hostname) {
106
+ const hostPattern = /^[a-z0-9][a-z0-9\.\-]*[a-z0-9]$/;
107
+ return hostPattern.test(hostname);
108
+ }
109
+
110
+ const normalizeProvider = (input) => {
111
+ if (typeof input === "function")
112
+ return input;
113
+ const promisified = Promise.resolve(input);
114
+ return () => promisified;
115
+ };
116
+
117
+ function parseQueryString(querystring) {
118
+ const query = {};
119
+ querystring = querystring.replace(/^\?/, "");
120
+ if (querystring) {
121
+ for (const pair of querystring.split("&")) {
122
+ let [key, value = null] = pair.split("=");
123
+ key = decodeURIComponent(key);
124
+ if (value) {
125
+ value = decodeURIComponent(value);
126
+ }
127
+ if (!(key in query)) {
128
+ query[key] = value;
129
+ }
130
+ else if (Array.isArray(query[key])) {
131
+ query[key].push(value);
132
+ }
133
+ else {
134
+ query[key] = [query[key], value];
135
+ }
136
+ }
137
+ }
138
+ return query;
139
+ }
140
+
141
+ const parseUrl = (url) => {
142
+ if (typeof url === "string") {
143
+ return parseUrl(new URL(url));
144
+ }
145
+ const { hostname, pathname, port, protocol, search } = url;
146
+ let query;
147
+ if (search) {
148
+ query = parseQueryString(search);
149
+ }
150
+ return {
151
+ hostname,
152
+ port: port ? parseInt(port) : undefined,
153
+ protocol,
154
+ path: pathname,
155
+ query,
156
+ };
157
+ };
158
+
159
+ const toEndpointV1 = (endpoint) => {
160
+ if (typeof endpoint === "object") {
161
+ if ("url" in endpoint) {
162
+ const v1Endpoint = parseUrl(endpoint.url);
163
+ if (endpoint.headers) {
164
+ v1Endpoint.headers = {};
165
+ for (const name in endpoint.headers) {
166
+ v1Endpoint.headers[name.toLowerCase()] = endpoint.headers[name].join(", ");
167
+ }
168
+ }
169
+ return v1Endpoint;
170
+ }
171
+ return endpoint;
172
+ }
173
+ return parseUrl(endpoint);
174
+ };
175
+
176
+ exports.HttpRequest = HttpRequest;
177
+ exports.HttpResponse = HttpResponse;
178
+ exports.getSmithyContext = getSmithyContext;
179
+ exports.isValidHostLabel = isValidHostLabel;
180
+ exports.isValidHostname = isValidHostname;
181
+ exports.normalizeProvider = normalizeProvider;
182
+ exports.parseQueryString = parseQueryString;
183
+ exports.parseUrl = parseUrl;
184
+ exports.toEndpointV1 = toEndpointV1;
package/dist-es/index.js CHANGED
@@ -1,8 +1,8 @@
1
- export * from "./getSmithyContext";
2
- export * from "./middleware-http-auth-scheme";
3
- export * from "./middleware-http-signing";
1
+ export { getSmithyContext } from "@smithy/core/transport";
2
+ export * from "./legacy-root-exports/middleware-http-auth-scheme";
3
+ export * from "./legacy-root-exports/middleware-http-signing";
4
4
  export * from "./normalizeProvider";
5
- export { createPaginator } from "./pagination/createPaginator";
6
- export * from "./request-builder/requestBuilder";
5
+ export { createPaginator } from "./legacy-root-exports/pagination/createPaginator";
6
+ export { requestBuilder } from "@smithy/core/protocols";
7
7
  export * from "./setFeature";
8
- export * from "./util-identity-and-auth";
8
+ export * from "./legacy-root-exports/util-identity-and-auth";
@@ -1,6 +1,6 @@
1
1
  export { constructStack } from "./middleware-stack/MiddlewareStack";
2
- export { getSmithyContext } from "./util-middleware/getSmithyContext";
3
- export { normalizeProvider } from "./util-middleware/normalizeProvider";
2
+ export { getSmithyContext } from "@smithy/core/transport";
3
+ export { normalizeProvider } from "@smithy/core/transport";
4
4
  export { invalidFunction } from "./invalid-dependency/invalidFunction";
5
5
  export { invalidProvider } from "./invalid-dependency/invalidProvider";
6
6
  export { createWaiter } from "./util-waiter/createWaiter";
@@ -1,4 +1,4 @@
1
- import { isValidHostLabel } from "@smithy/core/endpoints";
1
+ import { isValidHostLabel } from "@smithy/core/transport";
2
2
  const validRegions = new Set();
3
3
  export const checkRegion = (region, check = isValidHostLabel) => {
4
4
  if (!validRegions.has(region) && !check(region)) {
@@ -3,12 +3,12 @@ import { bindGetEndpointFromInstructions } from "./middleware-endpoint/adaptors/
3
3
  import { bindEndpointMiddleware } from "./middleware-endpoint/endpointMiddleware";
4
4
  import { bindGetEndpointPlugin } from "./middleware-endpoint/getEndpointPlugin";
5
5
  import { bindResolveEndpointConfig } from "./middleware-endpoint/resolveEndpointConfig";
6
- export * from "./toEndpointV1";
6
+ export { toEndpointV1 } from "@smithy/core/transport";
7
7
  export { BinaryDecisionDiagram } from "./util-endpoints/bdd/BinaryDecisionDiagram";
8
8
  export { EndpointCache } from "./util-endpoints/cache/EndpointCache";
9
9
  export { decideEndpoint } from "./util-endpoints/decideEndpoint";
10
10
  export { isIpAddress } from "./util-endpoints/lib/isIpAddress";
11
- export { isValidHostLabel } from "./util-endpoints/lib/isValidHostLabel";
11
+ export { isValidHostLabel } from "@smithy/core/transport";
12
12
  export { customEndpointFunctions } from "./util-endpoints/utils/customEndpointFunctions";
13
13
  export { resolveEndpoint } from "./util-endpoints/resolveEndpoint";
14
14
  export * from "./util-endpoints/types";
@@ -3,12 +3,12 @@ import { bindGetEndpointFromInstructions } from "./middleware-endpoint/adaptors/
3
3
  import { bindEndpointMiddleware } from "./middleware-endpoint/endpointMiddleware";
4
4
  import { bindGetEndpointPlugin } from "./middleware-endpoint/getEndpointPlugin";
5
5
  import { bindResolveEndpointConfig } from "./middleware-endpoint/resolveEndpointConfig";
6
- export * from "./toEndpointV1";
6
+ export { toEndpointV1 } from "@smithy/core/transport";
7
7
  export { BinaryDecisionDiagram } from "./util-endpoints/bdd/BinaryDecisionDiagram";
8
8
  export { EndpointCache } from "./util-endpoints/cache/EndpointCache";
9
9
  export { decideEndpoint } from "./util-endpoints/decideEndpoint";
10
10
  export { isIpAddress } from "./util-endpoints/lib/isIpAddress";
11
- export { isValidHostLabel } from "./util-endpoints/lib/isValidHostLabel";
11
+ export { isValidHostLabel } from "@smithy/core/transport";
12
12
  export { customEndpointFunctions } from "./util-endpoints/utils/customEndpointFunctions";
13
13
  export { resolveEndpoint } from "./util-endpoints/resolveEndpoint";
14
14
  export * from "./util-endpoints/types";
@@ -1 +1 @@
1
- export { toEndpointV1 } from "../../toEndpointV1";
1
+ export { toEndpointV1 } from "@smithy/core/transport";
@@ -1,4 +1,4 @@
1
- import { normalizeProvider } from "@smithy/core/client";
1
+ import { normalizeProvider } from "@smithy/core/transport";
2
2
  import { toEndpointV1 } from "./adaptors/toEndpointV1";
3
3
  export function bindResolveEndpointConfig(getEndpointFromConfig) {
4
4
  return (input) => {
@@ -2,7 +2,7 @@ export * from "./booleanEquals";
2
2
  export * from "./coalesce";
3
3
  export * from "./getAttr";
4
4
  export * from "./isSet";
5
- export * from "./isValidHostLabel";
5
+ export { isValidHostLabel } from "@smithy/core/transport";
6
6
  export * from "./ite";
7
7
  export * from "./not";
8
8
  export * from "./parseURL";
@@ -1,9 +1,9 @@
1
1
  import { NormalizedSchema, translateTraits } from "@smithy/core/schema";
2
2
  import { sdkStreamMixin, splitEvery, splitHeader } from "@smithy/core/serde";
3
+ import { HttpRequest } from "@smithy/core/transport";
3
4
  import { HttpProtocol } from "./HttpProtocol";
4
5
  import { collectBody } from "./collect-stream-body";
5
6
  import { extendedEncodeURIComponent } from "./extended-encode-uri-component";
6
- import { HttpRequest } from "./protocol-http/httpRequest";
7
7
  export class HttpBindingProtocol extends HttpProtocol {
8
8
  async serializeRequest(operationSchema, _input, context) {
9
9
  const input = _input && typeof _input === "object" ? _input : {};
@@ -1,7 +1,6 @@
1
1
  import { NormalizedSchema, TypeRegistry, translateTraits } from "@smithy/core/schema";
2
+ import { HttpRequest, HttpResponse } from "@smithy/core/transport";
2
3
  import { SerdeContext } from "./SerdeContext";
3
- import { HttpRequest } from "./protocol-http/httpRequest";
4
- import { HttpResponse } from "./protocol-http/httpResponse";
5
4
  export class HttpProtocol extends SerdeContext {
6
5
  options;
7
6
  compositeErrorRegistry;
@@ -1,7 +1,7 @@
1
1
  import { NormalizedSchema } from "@smithy/core/schema";
2
+ import { HttpRequest } from "@smithy/core/transport";
2
3
  import { HttpProtocol } from "./HttpProtocol";
3
4
  import { collectBody } from "./collect-stream-body";
4
- import { HttpRequest } from "./protocol-http/httpRequest";
5
5
  export class RpcProtocol extends HttpProtocol {
6
6
  async serializeRequest(operationSchema, _input, context) {
7
7
  const serializer = this.serializer;