@aws-amplify/core 5.5.2 → 5.5.3-api-v6.13

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 (146) hide show
  1. package/internals/aws-client-utils/composers/package.json +8 -0
  2. package/internals/aws-client-utils/package.json +4 -4
  3. package/lib/Amplify.js +2 -0
  4. package/lib/AwsClients/CognitoIdentity/base.d.ts +1 -1
  5. package/lib/AwsClients/CognitoIdentity/getCredentialsForIdentity.d.ts +14 -3
  6. package/lib/AwsClients/CognitoIdentity/getCredentialsForIdentity.js +2 -1
  7. package/lib/AwsClients/CognitoIdentity/getId.d.ts +14 -3
  8. package/lib/AwsClients/CognitoIdentity/getId.js +2 -1
  9. package/lib/AwsClients/Pinpoint/getInAppMessages.d.ts +13 -3
  10. package/lib/AwsClients/Pinpoint/putEvents.d.ts +13 -3
  11. package/lib/AwsClients/Pinpoint/updateEndpoint.d.ts +13 -3
  12. package/lib/Credentials.js +2 -0
  13. package/lib/Platform/version.d.ts +1 -1
  14. package/lib/Platform/version.js +1 -1
  15. package/lib/Providers/index.js +2 -0
  16. package/lib/ServiceWorker/ServiceWorker.js +2 -0
  17. package/lib/ServiceWorker/index.js +2 -0
  18. package/lib/UniversalStorage/index.js +2 -0
  19. package/lib/Util/BackgroundProcessManager.js +2 -0
  20. package/lib/Util/DateUtils.js +2 -0
  21. package/lib/Util/Mutex.js +2 -0
  22. package/lib/Util/Reachability.js +2 -0
  23. package/lib/Util/Reachability.native.js +2 -0
  24. package/lib/Util/StringUtils.js +2 -0
  25. package/lib/Util/index.js +2 -0
  26. package/lib/clients/handlers/fetch.js +4 -21
  27. package/lib/clients/index.d.ts +7 -2
  28. package/lib/clients/index.js +17 -4
  29. package/lib/clients/internal/composeServiceApi.d.ts +1 -1
  30. package/lib/clients/internal/composeServiceApi.js +6 -6
  31. package/lib/clients/internal/index.d.ts +7 -0
  32. package/lib/clients/internal/index.js +14 -0
  33. package/lib/clients/middleware/retry/middleware.d.ts +0 -7
  34. package/lib/clients/middleware/retry/middleware.js +37 -26
  35. package/lib/clients/middleware/signing/middleware.d.ts +9 -2
  36. package/lib/clients/middleware/signing/middleware.js +25 -14
  37. package/lib/clients/middleware/signing/signer/signatureV4/index.d.ts +2 -0
  38. package/lib/clients/middleware/signing/signer/signatureV4/index.js +3 -1
  39. package/lib/clients/middleware/signing/signer/signatureV4/index.native.d.ts +1 -0
  40. package/lib/clients/middleware/signing/signer/signatureV4/index.native.js +3 -1
  41. package/lib/clients/middleware/signing/signer/signatureV4/types/signer.d.ts +10 -1
  42. package/lib/clients/middleware/signing/signer/signatureV4/utils/getCanonicalRequest.d.ts +3 -1
  43. package/lib/clients/middleware/signing/signer/signatureV4/utils/getCanonicalRequest.js +5 -2
  44. package/lib/clients/middleware/signing/signer/signatureV4/utils/getCanonicalUri.d.ts +3 -1
  45. package/lib/clients/middleware/signing/signer/signatureV4/utils/getCanonicalUri.js +9 -2
  46. package/lib/clients/middleware/signing/signer/signatureV4/utils/getSignature.d.ts +1 -1
  47. package/lib/clients/middleware/signing/signer/signatureV4/utils/getSignature.js +2 -2
  48. package/lib/clients/middleware/signing/signer/signatureV4/utils/getSigningValues.d.ts +1 -1
  49. package/lib/clients/middleware/signing/signer/signatureV4/utils/getSigningValues.js +3 -2
  50. package/lib/clients/serde/responseInfo.js +4 -2
  51. package/lib/clients/types/aws.d.ts +4 -3
  52. package/lib/clients/utils/memoization.d.ts +9 -0
  53. package/lib/clients/utils/memoization.js +26 -0
  54. package/lib/tsconfig.tsbuildinfo +1 -1
  55. package/lib/types/index.js +2 -0
  56. package/lib-esm/Amplify.js +2 -0
  57. package/lib-esm/AwsClients/CognitoIdentity/base.d.ts +1 -1
  58. package/lib-esm/AwsClients/CognitoIdentity/getCredentialsForIdentity.d.ts +14 -3
  59. package/lib-esm/AwsClients/CognitoIdentity/getCredentialsForIdentity.js +2 -1
  60. package/lib-esm/AwsClients/CognitoIdentity/getId.d.ts +14 -3
  61. package/lib-esm/AwsClients/CognitoIdentity/getId.js +2 -1
  62. package/lib-esm/AwsClients/Pinpoint/getInAppMessages.d.ts +13 -3
  63. package/lib-esm/AwsClients/Pinpoint/putEvents.d.ts +13 -3
  64. package/lib-esm/AwsClients/Pinpoint/updateEndpoint.d.ts +13 -3
  65. package/lib-esm/Credentials.js +2 -0
  66. package/lib-esm/Platform/version.d.ts +1 -1
  67. package/lib-esm/Platform/version.js +1 -1
  68. package/lib-esm/Providers/index.js +2 -0
  69. package/lib-esm/ServiceWorker/ServiceWorker.js +2 -0
  70. package/lib-esm/ServiceWorker/index.js +2 -0
  71. package/lib-esm/UniversalStorage/index.js +2 -0
  72. package/lib-esm/Util/BackgroundProcessManager.js +2 -0
  73. package/lib-esm/Util/DateUtils.js +2 -0
  74. package/lib-esm/Util/Mutex.js +2 -0
  75. package/lib-esm/Util/Reachability.js +2 -0
  76. package/lib-esm/Util/Reachability.native.js +2 -0
  77. package/lib-esm/Util/StringUtils.js +2 -0
  78. package/lib-esm/Util/index.js +2 -0
  79. package/lib-esm/clients/handlers/fetch.js +1 -18
  80. package/lib-esm/clients/index.d.ts +7 -2
  81. package/lib-esm/clients/index.js +7 -2
  82. package/lib-esm/clients/internal/composeServiceApi.d.ts +1 -1
  83. package/lib-esm/clients/internal/composeServiceApi.js +6 -6
  84. package/lib-esm/clients/internal/index.d.ts +7 -0
  85. package/lib-esm/clients/internal/index.js +9 -0
  86. package/lib-esm/clients/middleware/retry/middleware.d.ts +0 -7
  87. package/lib-esm/clients/middleware/retry/middleware.js +36 -24
  88. package/lib-esm/clients/middleware/signing/middleware.d.ts +9 -2
  89. package/lib-esm/clients/middleware/signing/middleware.js +25 -14
  90. package/lib-esm/clients/middleware/signing/signer/signatureV4/index.d.ts +2 -0
  91. package/lib-esm/clients/middleware/signing/signer/signatureV4/index.js +1 -0
  92. package/lib-esm/clients/middleware/signing/signer/signatureV4/index.native.d.ts +1 -0
  93. package/lib-esm/clients/middleware/signing/signer/signatureV4/index.native.js +1 -0
  94. package/lib-esm/clients/middleware/signing/signer/signatureV4/types/signer.d.ts +10 -1
  95. package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/getCanonicalRequest.d.ts +3 -1
  96. package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/getCanonicalRequest.js +5 -2
  97. package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/getCanonicalUri.d.ts +3 -1
  98. package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/getCanonicalUri.js +9 -2
  99. package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/getSignature.d.ts +1 -1
  100. package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/getSignature.js +2 -2
  101. package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/getSigningValues.d.ts +1 -1
  102. package/lib-esm/clients/middleware/signing/signer/signatureV4/utils/getSigningValues.js +3 -2
  103. package/lib-esm/clients/serde/responseInfo.js +3 -1
  104. package/lib-esm/clients/types/aws.d.ts +4 -3
  105. package/lib-esm/clients/utils/memoization.d.ts +9 -0
  106. package/lib-esm/clients/utils/memoization.js +22 -0
  107. package/lib-esm/tsconfig.tsbuildinfo +1 -1
  108. package/lib-esm/types/index.js +2 -0
  109. package/package.json +8 -8
  110. package/polyfills/URL/index.ts +2 -0
  111. package/src/Amplify.ts +2 -0
  112. package/src/AwsClients/CognitoIdentity/getCredentialsForIdentity.ts +1 -1
  113. package/src/AwsClients/CognitoIdentity/getId.ts +1 -1
  114. package/src/Credentials.ts +2 -0
  115. package/src/Platform/version.ts +1 -1
  116. package/src/Providers/index.ts +2 -0
  117. package/src/ServiceWorker/ServiceWorker.ts +2 -0
  118. package/src/ServiceWorker/index.ts +2 -0
  119. package/src/UniversalStorage/index.ts +2 -0
  120. package/src/Util/BackgroundProcessManager.ts +2 -0
  121. package/src/Util/DateUtils.ts +2 -0
  122. package/src/Util/Mutex.ts +2 -0
  123. package/src/Util/Reachability.native.ts +2 -0
  124. package/src/Util/Reachability.ts +2 -0
  125. package/src/Util/Retry.ts +2 -0
  126. package/src/Util/StringUtils.ts +2 -0
  127. package/src/Util/index.ts +2 -0
  128. package/src/clients/handlers/fetch.ts +1 -19
  129. package/src/clients/index.ts +15 -2
  130. package/src/clients/internal/composeServiceApi.ts +12 -6
  131. package/src/clients/internal/index.ts +10 -0
  132. package/src/clients/middleware/retry/middleware.ts +28 -24
  133. package/src/clients/middleware/signing/middleware.ts +13 -2
  134. package/src/clients/middleware/signing/signer/signatureV4/index.native.ts +1 -0
  135. package/src/clients/middleware/signing/signer/signatureV4/index.ts +2 -0
  136. package/src/clients/middleware/signing/signer/signatureV4/types/signer.ts +14 -1
  137. package/src/clients/middleware/signing/signer/signatureV4/utils/getCanonicalRequest.ts +7 -7
  138. package/src/clients/middleware/signing/signer/signatureV4/utils/getCanonicalUri.ts +11 -2
  139. package/src/clients/middleware/signing/signer/signatureV4/utils/getSignature.ts +2 -1
  140. package/src/clients/middleware/signing/signer/signatureV4/utils/getSigningValues.ts +2 -0
  141. package/src/clients/serde/responseInfo.ts +4 -2
  142. package/src/clients/types/aws.ts +4 -3
  143. package/src/clients/utils/memoization.ts +23 -0
  144. package/src/parseAWSExports.ts +2 -0
  145. package/src/types/index.ts +2 -0
  146. package/src/types/types.ts +2 -0
@@ -1,6 +1,17 @@
1
1
  "use strict";
2
2
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
3
  // SPDX-License-Identifier: Apache-2.0
4
+ var __assign = (this && this.__assign) || function () {
5
+ __assign = Object.assign || function(t) {
6
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
7
+ s = arguments[i];
8
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
9
+ t[p] = s[p];
10
+ }
11
+ return t;
12
+ };
13
+ return __assign.apply(this, arguments);
14
+ };
4
15
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
5
16
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
6
17
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -38,7 +49,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
38
49
  }
39
50
  };
40
51
  Object.defineProperty(exports, "__esModule", { value: true });
41
- exports.isMetadataBearer = exports.retryMiddleware = void 0;
52
+ exports.retryMiddleware = void 0;
42
53
  var DEFAULT_RETRY_ATTEMPTS = 3;
43
54
  /**
44
55
  * Retry middleware
@@ -52,26 +63,36 @@ var retryMiddleware = function (_a) {
52
63
  return function retryMiddleware(request) {
53
64
  var _a;
54
65
  return __awaiter(this, void 0, void 0, function () {
55
- var error, attemptsCount, response, e_1, delay;
66
+ var error, attemptsCount, response, handleTerminalErrorOrResponse, e_1, delay;
56
67
  return __generator(this, function (_b) {
57
68
  switch (_b.label) {
58
69
  case 0:
59
70
  attemptsCount = (_a = context.attemptsCount) !== null && _a !== void 0 ? _a : 0;
71
+ handleTerminalErrorOrResponse = function () {
72
+ if (response) {
73
+ addOrIncrementMetadataAttempts(response, attemptsCount);
74
+ return response;
75
+ }
76
+ else {
77
+ addOrIncrementMetadataAttempts(error, attemptsCount);
78
+ throw error;
79
+ }
80
+ };
60
81
  _b.label = 1;
61
82
  case 1:
62
83
  if (!(!(abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) && attemptsCount < maxAttempts)) return [3 /*break*/, 11];
63
- error = undefined;
64
- response = undefined;
65
84
  _b.label = 2;
66
85
  case 2:
67
86
  _b.trys.push([2, 4, , 5]);
68
87
  return [4 /*yield*/, next(request)];
69
88
  case 3:
70
89
  response = _b.sent();
90
+ error = undefined;
71
91
  return [3 /*break*/, 5];
72
92
  case 4:
73
93
  e_1 = _b.sent();
74
94
  error = e_1;
95
+ response = undefined;
75
96
  return [3 /*break*/, 5];
76
97
  case 5:
77
98
  // context.attemptsCount may be updated after calling next handler which may retry the request by itself.
@@ -90,20 +111,16 @@ var retryMiddleware = function (_a) {
90
111
  _b.sent();
91
112
  _b.label = 8;
92
113
  case 8: return [3 /*break*/, 1];
93
- case 9:
94
- if (response) {
95
- updateMetadataAttempts(response, attemptsCount);
96
- return [2 /*return*/, response];
114
+ case 9: return [2 /*return*/, handleTerminalErrorOrResponse()];
115
+ case 10: return [3 /*break*/, 1];
116
+ case 11:
117
+ if (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) {
118
+ throw new Error('Request aborted.');
97
119
  }
98
120
  else {
99
- updateMetadataAttempts(error, attemptsCount);
100
- throw error;
121
+ return [2 /*return*/, handleTerminalErrorOrResponse()];
101
122
  }
102
- _b.label = 10;
103
- case 10: return [3 /*break*/, 1];
104
- case 11: throw (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted)
105
- ? new Error('Request aborted')
106
- : error !== null && error !== void 0 ? error : new Error('Retry attempts exhausted');
123
+ return [2 /*return*/];
107
124
  }
108
125
  });
109
126
  });
@@ -128,16 +145,10 @@ var cancellableSleep = function (timeoutMs, abortSignal) {
128
145
  });
129
146
  return sleepPromise;
130
147
  };
131
- /**
132
- * Check if the response is a contains `$metadata` property.
133
- *
134
- * @internal Amplify internal use only
135
- */
136
- var isMetadataBearer = function (response) { return typeof (response === null || response === void 0 ? void 0 : response['$metadata']) === 'object'; };
137
- exports.isMetadataBearer = isMetadataBearer;
138
- var updateMetadataAttempts = function (nextHandlerOutput, attempts) {
139
- if ((0, exports.isMetadataBearer)(nextHandlerOutput)) {
140
- nextHandlerOutput.$metadata.attempts = attempts;
148
+ var addOrIncrementMetadataAttempts = function (nextHandlerOutput, attempts) {
149
+ var _a;
150
+ if (Object.prototype.toString.call(nextHandlerOutput) !== '[object Object]') {
151
+ return;
141
152
  }
142
- nextHandlerOutput['$metadata'] = { attempts: attempts };
153
+ nextHandlerOutput['$metadata'] = __assign(__assign({}, ((_a = nextHandlerOutput['$metadata']) !== null && _a !== void 0 ? _a : {})), { attempts: attempts });
143
154
  };
@@ -3,12 +3,19 @@ import { Credentials, HttpRequest, HttpResponse, MiddlewareHandler } from '../..
3
3
  * Configuration of the signing middleware
4
4
  */
5
5
  export interface SigningOptions {
6
- credentials: Credentials;
6
+ credentials: Credentials | (() => Promise<Credentials>);
7
7
  region: string;
8
8
  service: string;
9
+ /**
10
+ * Whether to uri encode the path as part of canonical uri. It's used for S3 only where the pathname
11
+ * is already uri encoded, and the signing process is not expected to uri encode it again.
12
+ *
13
+ * @default true
14
+ */
15
+ uriEscapePath?: boolean;
9
16
  }
10
17
  /**
11
18
  * Middleware that SigV4 signs request with AWS credentials, and correct system clock offset.
12
19
  * This middleware is expected to be placed after retry middleware.
13
20
  */
14
- export declare const signingMiddleware: ({ credentials, region, service, }: SigningOptions) => (next: MiddlewareHandler<HttpRequest, HttpResponse>) => (request: HttpRequest) => Promise<HttpResponse>;
21
+ export declare const signingMiddleware: ({ credentials, region, service, uriEscapePath, }: SigningOptions) => (next: MiddlewareHandler<HttpRequest, HttpResponse>) => (request: HttpRequest) => Promise<HttpResponse>;
@@ -47,28 +47,39 @@ var getUpdatedSystemClockOffset_1 = require("./utils/getUpdatedSystemClockOffset
47
47
  * This middleware is expected to be placed after retry middleware.
48
48
  */
49
49
  var signingMiddleware = function (_a) {
50
- var credentials = _a.credentials, region = _a.region, service = _a.service;
50
+ var credentials = _a.credentials, region = _a.region, service = _a.service, _b = _a.uriEscapePath, uriEscapePath = _b === void 0 ? true : _b;
51
51
  var currentSystemClockOffset;
52
52
  return function (next) {
53
53
  return function signingMiddleware(request) {
54
54
  return __awaiter(this, void 0, void 0, function () {
55
- var signRequestOptions, signedRequest, response, dateString;
56
- return __generator(this, function (_a) {
57
- switch (_a.label) {
55
+ var signRequestOptions, _a, signedRequest, response, dateString;
56
+ var _b;
57
+ return __generator(this, function (_c) {
58
+ switch (_c.label) {
58
59
  case 0:
59
60
  currentSystemClockOffset = currentSystemClockOffset !== null && currentSystemClockOffset !== void 0 ? currentSystemClockOffset : 0;
60
- signRequestOptions = {
61
- credentials: credentials,
62
- signingDate: (0, getSkewCorrectedDate_1.getSkewCorrectedDate)(currentSystemClockOffset),
63
- signingRegion: region,
64
- signingService: service,
65
- };
66
- return [4 /*yield*/, (0, signatureV4_1.signRequest)(request, signRequestOptions)];
61
+ _b = {};
62
+ if (!(typeof credentials === 'function')) return [3 /*break*/, 2];
63
+ return [4 /*yield*/, credentials()];
67
64
  case 1:
68
- signedRequest = _a.sent();
69
- return [4 /*yield*/, next(signedRequest)];
65
+ _a = _c.sent();
66
+ return [3 /*break*/, 3];
70
67
  case 2:
71
- response = _a.sent();
68
+ _a = credentials;
69
+ _c.label = 3;
70
+ case 3:
71
+ signRequestOptions = (_b.credentials = _a,
72
+ _b.signingDate = (0, getSkewCorrectedDate_1.getSkewCorrectedDate)(currentSystemClockOffset),
73
+ _b.signingRegion = region,
74
+ _b.signingService = service,
75
+ _b.uriEscapePath = uriEscapePath,
76
+ _b);
77
+ return [4 /*yield*/, (0, signatureV4_1.signRequest)(request, signRequestOptions)];
78
+ case 4:
79
+ signedRequest = _c.sent();
80
+ return [4 /*yield*/, next(signedRequest)];
81
+ case 5:
82
+ response = _c.sent();
72
83
  dateString = getDateHeader(response);
73
84
  if (dateString) {
74
85
  currentSystemClockOffset = (0, getUpdatedSystemClockOffset_1.getUpdatedSystemClockOffset)(Date.parse(dateString), currentSystemClockOffset);
@@ -1,3 +1,5 @@
1
1
  export { signRequest } from './signRequest';
2
2
  export { presignUrl } from './presignUrl';
3
3
  export { TOKEN_QUERY_PARAM } from './constants';
4
+ export { getHashedPayload } from './utils/getHashedPayload';
5
+ export type { SignRequestOptions, PresignUrlOptions } from './types';
@@ -2,7 +2,7 @@
2
2
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.TOKEN_QUERY_PARAM = exports.presignUrl = exports.signRequest = void 0;
5
+ exports.getHashedPayload = exports.TOKEN_QUERY_PARAM = exports.presignUrl = exports.signRequest = void 0;
6
6
  // TODO: V6 replace Signer
7
7
  var signRequest_1 = require("./signRequest");
8
8
  Object.defineProperty(exports, "signRequest", { enumerable: true, get: function () { return signRequest_1.signRequest; } });
@@ -10,3 +10,5 @@ var presignUrl_1 = require("./presignUrl");
10
10
  Object.defineProperty(exports, "presignUrl", { enumerable: true, get: function () { return presignUrl_1.presignUrl; } });
11
11
  var constants_1 = require("./constants");
12
12
  Object.defineProperty(exports, "TOKEN_QUERY_PARAM", { enumerable: true, get: function () { return constants_1.TOKEN_QUERY_PARAM; } });
13
+ var getHashedPayload_1 = require("./utils/getHashedPayload");
14
+ Object.defineProperty(exports, "getHashedPayload", { enumerable: true, get: function () { return getHashedPayload_1.getHashedPayload; } });
@@ -2,3 +2,4 @@ import '@aws-amplify/core/polyfills/URL';
2
2
  export { signRequest } from './signRequest';
3
3
  export { presignUrl } from './presignUrl';
4
4
  export { TOKEN_QUERY_PARAM } from './constants';
5
+ export { getHashedPayload } from './utils/getHashedPayload';
@@ -2,7 +2,7 @@
2
2
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.TOKEN_QUERY_PARAM = exports.presignUrl = exports.signRequest = void 0;
5
+ exports.getHashedPayload = exports.TOKEN_QUERY_PARAM = exports.presignUrl = exports.signRequest = void 0;
6
6
  require("@aws-amplify/core/polyfills/URL");
7
7
  // TODO: V6 replace Signer
8
8
  var signRequest_1 = require("./signRequest");
@@ -11,3 +11,5 @@ var presignUrl_1 = require("./presignUrl");
11
11
  Object.defineProperty(exports, "presignUrl", { enumerable: true, get: function () { return presignUrl_1.presignUrl; } });
12
12
  var constants_1 = require("./constants");
13
13
  Object.defineProperty(exports, "TOKEN_QUERY_PARAM", { enumerable: true, get: function () { return constants_1.TOKEN_QUERY_PARAM; } });
14
+ var getHashedPayload_1 = require("./utils/getHashedPayload");
15
+ Object.defineProperty(exports, "getHashedPayload", { enumerable: true, get: function () { return getHashedPayload_1.getHashedPayload; } });
@@ -4,6 +4,15 @@ export interface SignRequestOptions {
4
4
  signingDate?: Date;
5
5
  signingRegion: string;
6
6
  signingService: string;
7
+ /**
8
+ * Whether to uri encode the path as part of canonical uri. It's used for S3 only where the pathname
9
+ * is already uri encoded, and the signing process is not expected to uri encode it again.
10
+ *
11
+ * @default true
12
+ *
13
+ * @see https://github.com/aws/aws-sdk-js-v3/blob/9ba012dfa3a3429aa2db0f90b3b0b3a7a31f9bc3/packages/signature-v4/src/SignatureV4.ts#L76-L83
14
+ */
15
+ uriEscapePath?: boolean;
7
16
  }
8
17
  export interface PresignUrlOptions extends SignRequestOptions {
9
18
  expiration?: number;
@@ -15,6 +24,6 @@ export interface FormattedDates {
15
24
  longDate: string;
16
25
  shortDate: string;
17
26
  }
18
- export interface SigningValues extends Credentials, FormattedDates, Pick<SignRequestOptions, 'signingRegion' | 'signingService'> {
27
+ export interface SigningValues extends Credentials, FormattedDates, Pick<SignRequestOptions, 'signingRegion' | 'signingService' | 'uriEscapePath'> {
19
28
  credentialScope: string;
20
29
  }
@@ -3,6 +3,8 @@ import { HttpRequest } from '../../../../../types';
3
3
  * Returns a canonical request.
4
4
  *
5
5
  * @param request `HttpRequest` from which to create the canonical request from.
6
+ * @param uriEscapePath Whether to uri encode the path as part of canonical uri. It's used for S3 only where the
7
+ * pathname is already uri encoded, and the signing process is not expected to uri encode it again. Defaults to true.
6
8
  * @returns String created by by concatenating the following strings, separated by newline characters:
7
9
  * - HTTPMethod
8
10
  * - CanonicalUri
@@ -13,4 +15,4 @@ import { HttpRequest } from '../../../../../types';
13
15
  *
14
16
  * @internal
15
17
  */
16
- export declare const getCanonicalRequest: ({ body, headers, method, url, }: HttpRequest) => string;
18
+ export declare const getCanonicalRequest: ({ body, headers, method, url }: HttpRequest, uriEscapePath?: boolean) => string;
@@ -12,6 +12,8 @@ var getSignedHeaders_1 = require("./getSignedHeaders");
12
12
  * Returns a canonical request.
13
13
  *
14
14
  * @param request `HttpRequest` from which to create the canonical request from.
15
+ * @param uriEscapePath Whether to uri encode the path as part of canonical uri. It's used for S3 only where the
16
+ * pathname is already uri encoded, and the signing process is not expected to uri encode it again. Defaults to true.
15
17
  * @returns String created by by concatenating the following strings, separated by newline characters:
16
18
  * - HTTPMethod
17
19
  * - CanonicalUri
@@ -22,11 +24,12 @@ var getSignedHeaders_1 = require("./getSignedHeaders");
22
24
  *
23
25
  * @internal
24
26
  */
25
- var getCanonicalRequest = function (_a) {
27
+ var getCanonicalRequest = function (_a, uriEscapePath) {
26
28
  var body = _a.body, headers = _a.headers, method = _a.method, url = _a.url;
29
+ if (uriEscapePath === void 0) { uriEscapePath = true; }
27
30
  return [
28
31
  method,
29
- (0, getCanonicalUri_1.getCanonicalUri)(url.pathname),
32
+ (0, getCanonicalUri_1.getCanonicalUri)(url.pathname, uriEscapePath),
30
33
  (0, getCanonicalQueryString_1.getCanonicalQueryString)(url.searchParams),
31
34
  (0, getCanonicalHeaders_1.getCanonicalHeaders)(headers),
32
35
  (0, getSignedHeaders_1.getSignedHeaders)(headers),
@@ -2,9 +2,11 @@
2
2
  * Returns a canonical uri.
3
3
  *
4
4
  * @param pathname `pathname` from request url.
5
+ * @param uriEscapePath Whether to uri encode the path as part of canonical uri. It's used for S3 only where the
6
+ * pathname is already uri encoded, and the signing process is not expected to uri encode it again. Defaults to true.
5
7
  * @returns URI-encoded version of the absolute path component URL (everything between the host and the question mark
6
8
  * character (?) that starts the query string parameters). If the absolute path is empty, a forward slash character (/).
7
9
  *
8
10
  * @internal
9
11
  */
10
- export declare const getCanonicalUri: (pathname: string) => string;
12
+ export declare const getCanonicalUri: (pathname: string, uriEscapePath?: boolean) => string;
@@ -7,12 +7,19 @@ exports.getCanonicalUri = void 0;
7
7
  * Returns a canonical uri.
8
8
  *
9
9
  * @param pathname `pathname` from request url.
10
+ * @param uriEscapePath Whether to uri encode the path as part of canonical uri. It's used for S3 only where the
11
+ * pathname is already uri encoded, and the signing process is not expected to uri encode it again. Defaults to true.
10
12
  * @returns URI-encoded version of the absolute path component URL (everything between the host and the question mark
11
13
  * character (?) that starts the query string parameters). If the absolute path is empty, a forward slash character (/).
12
14
  *
13
15
  * @internal
14
16
  */
15
- var getCanonicalUri = function (pathname) {
16
- return pathname ? encodeURIComponent(pathname).replace(/%2F/g, '/') : '/';
17
+ var getCanonicalUri = function (pathname, uriEscapePath) {
18
+ if (uriEscapePath === void 0) { uriEscapePath = true; }
19
+ return pathname
20
+ ? uriEscapePath
21
+ ? encodeURIComponent(pathname).replace(/%2F/g, '/')
22
+ : pathname
23
+ : '/';
17
24
  };
18
25
  exports.getCanonicalUri = getCanonicalUri;
@@ -10,4 +10,4 @@ import { SigningValues } from '../types/signer';
10
10
  *
11
11
  * @internal
12
12
  */
13
- export declare const getSignature: (request: HttpRequest, { credentialScope, longDate, secretAccessKey, shortDate, signingRegion, signingService, }: SigningValues) => string;
13
+ export declare const getSignature: (request: HttpRequest, { credentialScope, longDate, secretAccessKey, shortDate, signingRegion, signingService, uriEscapePath, }: SigningValues) => string;
@@ -18,9 +18,9 @@ var getStringToSign_1 = require("./getStringToSign");
18
18
  * @internal
19
19
  */
20
20
  var getSignature = function (request, _a) {
21
- var credentialScope = _a.credentialScope, longDate = _a.longDate, secretAccessKey = _a.secretAccessKey, shortDate = _a.shortDate, signingRegion = _a.signingRegion, signingService = _a.signingService;
21
+ var credentialScope = _a.credentialScope, longDate = _a.longDate, secretAccessKey = _a.secretAccessKey, shortDate = _a.shortDate, signingRegion = _a.signingRegion, signingService = _a.signingService, uriEscapePath = _a.uriEscapePath;
22
22
  // step 1: create a canonical request
23
- var canonicalRequest = (0, getCanonicalRequest_1.getCanonicalRequest)(request);
23
+ var canonicalRequest = (0, getCanonicalRequest_1.getCanonicalRequest)(request, uriEscapePath);
24
24
  // step 2: create a hash of the canonical request
25
25
  var hashedRequest = (0, dataHashHelpers_1.getHashedDataAsHex)(null, canonicalRequest);
26
26
  // step 3: create a string to sign
@@ -8,4 +8,4 @@ import { SigningValues } from '../types/signer';
8
8
  *
9
9
  * @internal
10
10
  */
11
- export declare const getSigningValues: ({ credentials, signingDate, signingRegion, signingService, }: SignRequestOptions) => SigningValues;
11
+ export declare const getSigningValues: ({ credentials, signingDate, signingRegion, signingService, uriEscapePath, }: SignRequestOptions) => SigningValues;
@@ -14,11 +14,11 @@ var getFormattedDates_1 = require("./getFormattedDates");
14
14
  * @internal
15
15
  */
16
16
  var getSigningValues = function (_a) {
17
- var credentials = _a.credentials, _b = _a.signingDate, signingDate = _b === void 0 ? new Date() : _b, signingRegion = _a.signingRegion, signingService = _a.signingService;
17
+ var credentials = _a.credentials, _b = _a.signingDate, signingDate = _b === void 0 ? new Date() : _b, signingRegion = _a.signingRegion, signingService = _a.signingService, _c = _a.uriEscapePath, uriEscapePath = _c === void 0 ? true : _c;
18
18
  // get properties from credentials
19
19
  var accessKeyId = credentials.accessKeyId, secretAccessKey = credentials.secretAccessKey, sessionToken = credentials.sessionToken;
20
20
  // get formatted dates for signing
21
- var _c = (0, getFormattedDates_1.getFormattedDates)(signingDate), longDate = _c.longDate, shortDate = _c.shortDate;
21
+ var _d = (0, getFormattedDates_1.getFormattedDates)(signingDate), longDate = _d.longDate, shortDate = _d.shortDate;
22
22
  // copy header and set signing properties
23
23
  var credentialScope = (0, getCredentialScope_1.getCredentialScope)(shortDate, signingRegion, signingService);
24
24
  return {
@@ -30,6 +30,7 @@ var getSigningValues = function (_a) {
30
30
  shortDate: shortDate,
31
31
  signingRegion: signingRegion,
32
32
  signingService: signingService,
33
+ uriEscapePath: uriEscapePath,
33
34
  };
34
35
  };
35
36
  exports.getSigningValues = getSigningValues;
@@ -14,10 +14,12 @@ var __assign = (this && this.__assign) || function () {
14
14
  };
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
16
  exports.parseMetadata = void 0;
17
- var middleware_1 = require("../middleware/retry/middleware");
18
17
  var parseMetadata = function (response) {
19
18
  var _a, _b;
20
19
  var headers = response.headers, statusCode = response.statusCode;
21
- return __assign(__assign({}, ((0, middleware_1.isMetadataBearer)(response) ? response.$metadata : {})), { httpStatusCode: statusCode, requestId: (_b = (_a = headers['x-amzn-requestid']) !== null && _a !== void 0 ? _a : headers['x-amzn-request-id']) !== null && _b !== void 0 ? _b : headers['x-amz-request-id'], extendedRequestId: headers['x-amz-id-2'], cfId: headers['x-amz-cf-id'] });
20
+ return __assign(__assign({}, (isMetadataBearer(response) ? response.$metadata : {})), { httpStatusCode: statusCode, requestId: (_b = (_a = headers['x-amzn-requestid']) !== null && _a !== void 0 ? _a : headers['x-amzn-request-id']) !== null && _b !== void 0 ? _b : headers['x-amz-request-id'], extendedRequestId: headers['x-amz-id-2'], cfId: headers['x-amz-cf-id'] });
22
21
  };
23
22
  exports.parseMetadata = parseMetadata;
23
+ var isMetadataBearer = function (response) {
24
+ return typeof (response === null || response === void 0 ? void 0 : response['$metadata']) === 'object';
25
+ };
@@ -1,6 +1,7 @@
1
+ import { MetadataBearer } from '@aws-sdk/types';
1
2
  import { Endpoint } from './core';
2
3
  import { HttpResponse } from './http';
3
- export type { Credentials } from '@aws-sdk/types';
4
+ export type { Credentials, MetadataBearer } from '@aws-sdk/types';
4
5
  export type SourceData = string | ArrayBuffer | ArrayBufferView;
5
6
  /**
6
7
  * Basic option type for endpoint resolvers. It contains region only.
@@ -10,10 +11,10 @@ export type EndpointResolverOptions = {
10
11
  };
11
12
  export interface ServiceClientOptions {
12
13
  region: string;
13
- endpointResolver: (options: EndpointResolverOptions) => Endpoint;
14
+ endpointResolver: (options: EndpointResolverOptions, input?: any) => Endpoint;
14
15
  }
15
16
  /**
16
17
  * parse errors from given response. If no error code is found, return undefined.
17
18
  * This function is protocol-specific (e.g. JSON, XML, etc.)
18
19
  */
19
- export type ErrorParser = (response?: HttpResponse) => Promise<Error | undefined>;
20
+ export type ErrorParser = (response?: HttpResponse) => Promise<(Error & MetadataBearer) | undefined>;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Cache the payload of a response body. It allows multiple calls to the body,
3
+ * for example, when reading the body in both retry decider and error deserializer.
4
+ * Caching body is allowed here because we call the body accessor(blob(), json(),
5
+ * etc.) when body is small or streaming implementation is not available(RN).
6
+ *
7
+ * @internal
8
+ */
9
+ export declare const withMemoization: <T>(payloadAccessor: () => Promise<T>) => () => Promise<T>;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ // SPDX-License-Identifier: Apache-2.0
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.withMemoization = void 0;
6
+ /**
7
+ * Cache the payload of a response body. It allows multiple calls to the body,
8
+ * for example, when reading the body in both retry decider and error deserializer.
9
+ * Caching body is allowed here because we call the body accessor(blob(), json(),
10
+ * etc.) when body is small or streaming implementation is not available(RN).
11
+ *
12
+ * @internal
13
+ */
14
+ var withMemoization = function (payloadAccessor) {
15
+ var cached;
16
+ return function () {
17
+ if (!cached) {
18
+ // Explicitly not awaiting. Intermediate await would add overhead and
19
+ // introduce a possible race in the event that this wrapper is called
20
+ // again before the first `payloadAccessor` call resolves.
21
+ cached = payloadAccessor();
22
+ }
23
+ return cached;
24
+ };
25
+ };
26
+ exports.withMemoization = withMemoization;