@aws-amplify/api-rest 0.0.0-unstable-1ca644b-20260128091132

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 (167) hide show
  1. package/README.md +3 -0
  2. package/dist/cjs/apis/common/baseHandlers/authenticatedHandler.js +17 -0
  3. package/dist/cjs/apis/common/baseHandlers/authenticatedHandler.js.map +1 -0
  4. package/dist/cjs/apis/common/baseHandlers/unauthenticatedHandler.js +13 -0
  5. package/dist/cjs/apis/common/baseHandlers/unauthenticatedHandler.js.map +1 -0
  6. package/dist/cjs/apis/common/internalPost.js +98 -0
  7. package/dist/cjs/apis/common/internalPost.js.map +1 -0
  8. package/dist/cjs/apis/common/publicApis.js +57 -0
  9. package/dist/cjs/apis/common/publicApis.js.map +1 -0
  10. package/dist/cjs/apis/common/transferHandler.js +92 -0
  11. package/dist/cjs/apis/common/transferHandler.js.map +1 -0
  12. package/dist/cjs/apis/index.js +217 -0
  13. package/dist/cjs/apis/index.js.map +1 -0
  14. package/dist/cjs/apis/server.js +163 -0
  15. package/dist/cjs/apis/server.js.map +1 -0
  16. package/dist/cjs/errors/CanceledError.js +37 -0
  17. package/dist/cjs/errors/CanceledError.js.map +1 -0
  18. package/dist/cjs/errors/RestApiError.js +17 -0
  19. package/dist/cjs/errors/RestApiError.js.map +1 -0
  20. package/dist/cjs/errors/assertValidatonError.js +18 -0
  21. package/dist/cjs/errors/assertValidatonError.js.map +1 -0
  22. package/dist/cjs/errors/index.js +17 -0
  23. package/dist/cjs/errors/index.js.map +1 -0
  24. package/dist/cjs/errors/validation.js +17 -0
  25. package/dist/cjs/errors/validation.js.map +1 -0
  26. package/dist/cjs/index.js +16 -0
  27. package/dist/cjs/index.js.map +1 -0
  28. package/dist/cjs/internals/index.js +12 -0
  29. package/dist/cjs/internals/index.js.map +1 -0
  30. package/dist/cjs/internals/server.js +32 -0
  31. package/dist/cjs/internals/server.js.map +1 -0
  32. package/dist/cjs/server.js +16 -0
  33. package/dist/cjs/server.js.map +1 -0
  34. package/dist/cjs/types/index.js +4 -0
  35. package/dist/cjs/types/index.js.map +1 -0
  36. package/dist/cjs/utils/constants.js +15 -0
  37. package/dist/cjs/utils/constants.js.map +1 -0
  38. package/dist/cjs/utils/createCancellableOperation.js +76 -0
  39. package/dist/cjs/utils/createCancellableOperation.js.map +1 -0
  40. package/dist/cjs/utils/index.js +19 -0
  41. package/dist/cjs/utils/index.js.map +1 -0
  42. package/dist/cjs/utils/isIamAuthApplicable.js +39 -0
  43. package/dist/cjs/utils/isIamAuthApplicable.js.map +1 -0
  44. package/dist/cjs/utils/logger.js +9 -0
  45. package/dist/cjs/utils/logger.js.map +1 -0
  46. package/dist/cjs/utils/parseSigningInfo.js +43 -0
  47. package/dist/cjs/utils/parseSigningInfo.js.map +1 -0
  48. package/dist/cjs/utils/resolveApiUrl.js +48 -0
  49. package/dist/cjs/utils/resolveApiUrl.js.map +1 -0
  50. package/dist/cjs/utils/resolveHeaders.js +34 -0
  51. package/dist/cjs/utils/resolveHeaders.js.map +1 -0
  52. package/dist/cjs/utils/resolveLibraryOptions.js +16 -0
  53. package/dist/cjs/utils/resolveLibraryOptions.js.map +1 -0
  54. package/dist/cjs/utils/serviceError.js +98 -0
  55. package/dist/cjs/utils/serviceError.js.map +1 -0
  56. package/dist/esm/apis/common/baseHandlers/authenticatedHandler.d.ts +5 -0
  57. package/dist/esm/apis/common/baseHandlers/authenticatedHandler.mjs +16 -0
  58. package/dist/esm/apis/common/baseHandlers/authenticatedHandler.mjs.map +1 -0
  59. package/dist/esm/apis/common/baseHandlers/unauthenticatedHandler.d.ts +5 -0
  60. package/dist/esm/apis/common/baseHandlers/unauthenticatedHandler.mjs +12 -0
  61. package/dist/esm/apis/common/baseHandlers/unauthenticatedHandler.mjs.map +1 -0
  62. package/dist/esm/apis/common/internalPost.d.ts +43 -0
  63. package/dist/esm/apis/common/internalPost.mjs +98 -0
  64. package/dist/esm/apis/common/internalPost.mjs.map +1 -0
  65. package/dist/esm/apis/common/publicApis.d.ts +8 -0
  66. package/dist/esm/apis/common/publicApis.mjs +56 -0
  67. package/dist/esm/apis/common/publicApis.mjs.map +1 -0
  68. package/dist/esm/apis/common/transferHandler.d.ts +26 -0
  69. package/dist/esm/apis/common/transferHandler.mjs +95 -0
  70. package/dist/esm/apis/common/transferHandler.mjs.map +1 -0
  71. package/dist/esm/apis/index.d.ts +203 -0
  72. package/dist/esm/apis/index.mjs +210 -0
  73. package/dist/esm/apis/index.mjs.map +1 -0
  74. package/dist/esm/apis/server.d.ts +150 -0
  75. package/dist/esm/apis/server.mjs +156 -0
  76. package/dist/esm/apis/server.mjs.map +1 -0
  77. package/dist/esm/errors/CanceledError.d.ts +20 -0
  78. package/dist/esm/errors/CanceledError.mjs +34 -0
  79. package/dist/esm/errors/CanceledError.mjs.map +1 -0
  80. package/dist/esm/errors/RestApiError.d.ts +4 -0
  81. package/dist/esm/errors/RestApiError.mjs +15 -0
  82. package/dist/esm/errors/RestApiError.mjs.map +1 -0
  83. package/dist/esm/errors/assertValidatonError.d.ts +5 -0
  84. package/dist/esm/errors/assertValidatonError.mjs +17 -0
  85. package/dist/esm/errors/assertValidatonError.mjs.map +1 -0
  86. package/dist/esm/errors/index.d.ts +4 -0
  87. package/dist/esm/errors/index.mjs +5 -0
  88. package/dist/esm/errors/index.mjs.map +1 -0
  89. package/dist/esm/errors/validation.d.ts +5 -0
  90. package/dist/esm/errors/validation.mjs +15 -0
  91. package/dist/esm/errors/validation.mjs.map +1 -0
  92. package/dist/esm/index.d.ts +2 -0
  93. package/dist/esm/index.mjs +3 -0
  94. package/dist/esm/index.mjs.map +1 -0
  95. package/dist/esm/internals/index.d.ts +2 -0
  96. package/dist/esm/internals/index.mjs +2 -0
  97. package/dist/esm/internals/index.mjs.map +1 -0
  98. package/dist/esm/internals/server.d.ts +20 -0
  99. package/dist/esm/internals/server.mjs +28 -0
  100. package/dist/esm/internals/server.mjs.map +1 -0
  101. package/dist/esm/server.d.ts +2 -0
  102. package/dist/esm/server.mjs +3 -0
  103. package/dist/esm/server.mjs.map +1 -0
  104. package/dist/esm/types/index.d.ts +122 -0
  105. package/dist/esm/types/index.mjs +2 -0
  106. package/dist/esm/types/index.mjs.map +1 -0
  107. package/dist/esm/utils/constants.d.ts +8 -0
  108. package/dist/esm/utils/constants.mjs +13 -0
  109. package/dist/esm/utils/constants.mjs.map +1 -0
  110. package/dist/esm/utils/createCancellableOperation.d.ts +12 -0
  111. package/dist/esm/utils/createCancellableOperation.mjs +77 -0
  112. package/dist/esm/utils/createCancellableOperation.mjs.map +1 -0
  113. package/dist/esm/utils/index.d.ts +6 -0
  114. package/dist/esm/utils/index.mjs +7 -0
  115. package/dist/esm/utils/index.mjs.map +1 -0
  116. package/dist/esm/utils/isIamAuthApplicable.d.ts +32 -0
  117. package/dist/esm/utils/isIamAuthApplicable.mjs +35 -0
  118. package/dist/esm/utils/isIamAuthApplicable.mjs.map +1 -0
  119. package/dist/esm/utils/logger.d.ts +2 -0
  120. package/dist/esm/utils/logger.mjs +8 -0
  121. package/dist/esm/utils/logger.mjs.map +1 -0
  122. package/dist/esm/utils/parseSigningInfo.d.ts +14 -0
  123. package/dist/esm/utils/parseSigningInfo.mjs +41 -0
  124. package/dist/esm/utils/parseSigningInfo.mjs.map +1 -0
  125. package/dist/esm/utils/resolveApiUrl.d.ts +12 -0
  126. package/dist/esm/utils/resolveApiUrl.mjs +48 -0
  127. package/dist/esm/utils/resolveApiUrl.mjs.map +1 -0
  128. package/dist/esm/utils/resolveHeaders.d.ts +1 -0
  129. package/dist/esm/utils/resolveHeaders.mjs +31 -0
  130. package/dist/esm/utils/resolveHeaders.mjs.map +1 -0
  131. package/dist/esm/utils/resolveLibraryOptions.d.ts +8 -0
  132. package/dist/esm/utils/resolveLibraryOptions.mjs +13 -0
  133. package/dist/esm/utils/resolveLibraryOptions.mjs.map +1 -0
  134. package/dist/esm/utils/serviceError.d.ts +13 -0
  135. package/dist/esm/utils/serviceError.mjs +97 -0
  136. package/dist/esm/utils/serviceError.mjs.map +1 -0
  137. package/internals/package.json +8 -0
  138. package/internals/server/package.json +7 -0
  139. package/package.json +94 -0
  140. package/server/package.json +7 -0
  141. package/src/apis/common/baseHandlers/authenticatedHandler.ts +28 -0
  142. package/src/apis/common/baseHandlers/unauthenticatedHandler.ts +22 -0
  143. package/src/apis/common/internalPost.ts +123 -0
  144. package/src/apis/common/publicApis.ts +118 -0
  145. package/src/apis/common/transferHandler.ts +154 -0
  146. package/src/apis/index.ts +241 -0
  147. package/src/apis/server.ts +210 -0
  148. package/src/errors/CanceledError.ts +37 -0
  149. package/src/errors/RestApiError.ts +14 -0
  150. package/src/errors/assertValidatonError.ts +19 -0
  151. package/src/errors/index.ts +7 -0
  152. package/src/errors/validation.ts +16 -0
  153. package/src/index.ts +5 -0
  154. package/src/internals/index.ts +8 -0
  155. package/src/internals/server.ts +37 -0
  156. package/src/server.ts +5 -0
  157. package/src/types/index.ts +138 -0
  158. package/src/utils/constants.ts +15 -0
  159. package/src/utils/createCancellableOperation.ts +108 -0
  160. package/src/utils/index.ts +9 -0
  161. package/src/utils/isIamAuthApplicable.ts +44 -0
  162. package/src/utils/logger.ts +6 -0
  163. package/src/utils/parseSigningInfo.ts +53 -0
  164. package/src/utils/resolveApiUrl.ts +59 -0
  165. package/src/utils/resolveHeaders.ts +36 -0
  166. package/src/utils/resolveLibraryOptions.ts +14 -0
  167. package/src/utils/serviceError.ts +109 -0
@@ -0,0 +1,122 @@
1
+ import { DocumentType, RESTAuthMode, RetryStrategy } from '@aws-amplify/core/internals/utils';
2
+ export type GetInput = ApiInput<RestApiOptionsBase>;
3
+ export type PostInput = ApiInput<RestApiOptionsBase>;
4
+ export type PutInput = ApiInput<RestApiOptionsBase>;
5
+ export type PatchInput = ApiInput<RestApiOptionsBase>;
6
+ export type DeleteInput = ApiInput<RestApiOptionsBase>;
7
+ export type HeadInput = ApiInput<Omit<RestApiOptionsBase, 'body'>>;
8
+ export type GetOperation = Operation<RestApiResponse>;
9
+ export type PostOperation = Operation<RestApiResponse>;
10
+ export type PutOperation = Operation<RestApiResponse>;
11
+ export type PatchOperation = Operation<RestApiResponse>;
12
+ export type DeleteOperation = Operation<RestApiResponse>;
13
+ export type HeadOperation = Operation<Omit<RestApiResponse, 'body'>>;
14
+ /**
15
+ * @internal
16
+ */
17
+ export interface RestApiOptionsBase {
18
+ headers?: Headers;
19
+ queryParams?: Record<string, string>;
20
+ body?: DocumentType | FormData;
21
+ /**
22
+ * Option controls whether or not cross-site Access-Control requests should be made using credentials
23
+ * such as cookies, authorization headers or TLS client certificates. It has no effect on same-origin requests.
24
+ * If set to `true`, the request will include credentials such as cookies, authorization headers, TLS
25
+ * client certificates, and so on. Moreover the response cookies will also be set.
26
+ * If set to `false`, the cross-site request will not include credentials, and the response cookies from a different
27
+ * domain will be ignored.
28
+ *
29
+ * @default false
30
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials}
31
+ */
32
+ withCredentials?: boolean;
33
+ /**
34
+ * Retry strategy for the REST API calls. It will take precedence over REST `retryStrategy` in Amplify configuration libraryOptions.
35
+ *
36
+ * @default ` { strategy: 'jittered-exponential-backoff' } `
37
+ */
38
+ retryStrategy?: RetryStrategy;
39
+ defaultAuthMode?: RESTAuthMode;
40
+ /**
41
+ * custom timeout in milliseconds.
42
+ */
43
+ timeout?: number;
44
+ }
45
+ type Headers = Record<string, string>;
46
+ /**
47
+ * Type representing an operation that can be canceled.
48
+ *
49
+ * @internal
50
+ */
51
+ export interface Operation<Response> {
52
+ response: Promise<Response>;
53
+ cancel(abortMessage?: string): void;
54
+ }
55
+ interface ResponsePayload {
56
+ blob(): Promise<Blob>;
57
+ json(): Promise<DocumentType>;
58
+ text(): Promise<string>;
59
+ }
60
+ /**
61
+ * Basic response type of REST API.
62
+ *
63
+ * @internal
64
+ */
65
+ export interface RestApiResponse {
66
+ body: ResponsePayload;
67
+ statusCode: number;
68
+ headers: Headers;
69
+ }
70
+ /**
71
+ * @internal
72
+ */
73
+ export interface ApiInput<Options> {
74
+ /**
75
+ * Name of the REST API configured in Amplify singleton.
76
+ */
77
+ apiName: string;
78
+ /**
79
+ * Path of the REST API.
80
+ */
81
+ path: string;
82
+ /**
83
+ * Options to overwrite the REST API call behavior.
84
+ */
85
+ options?: Options;
86
+ }
87
+ /**
88
+ * Input type to invoke REST POST API from GraphQl client.
89
+ * @internal
90
+ */
91
+ export interface InternalPostInput {
92
+ url: URL;
93
+ options?: Omit<RestApiOptionsBase, 'retryStrategy'> & {
94
+ /**
95
+ * Internal-only option for GraphQL client to provide the IAM signing service and region.
96
+ * * If auth mode is 'iam', you MUST set this value.
97
+ * * If auth mode is 'none', you MUST NOT set this value;
98
+ * * If auth mode is 'apiKey' or 'oidc' or 'lambda' or 'userPool' because associated
99
+ * headers are provided, this value is ignored.
100
+ */
101
+ signingServiceInfo?: {
102
+ service?: string;
103
+ region?: string;
104
+ };
105
+ };
106
+ /**
107
+ * The abort controller to cancel the in-flight POST request.
108
+ * Required if you want to make the internal post request cancellable. To make the internal post cancellable, you
109
+ * must also call `updateRequestToBeCancellable()` with the promise from internal post call and the abort
110
+ * controller.
111
+ */
112
+ abortController?: AbortController;
113
+ }
114
+ /**
115
+ * Type for signingServiceInfo which enable IAM auth as well as overwrite the IAM signing info.
116
+ * @internal
117
+ */
118
+ export interface SigningServiceInfo {
119
+ service?: string;
120
+ region?: string;
121
+ }
122
+ export {};
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ export declare const DEFAULT_REST_IAM_SIGNING_SERVICE = "execute-api";
2
+ export declare const DEFAULT_APPSYNC_API_SERVICE = "appsync-api";
3
+ export declare const DEFAULT_IAM_SIGNING_REGION = "us-east-1";
4
+ /**
5
+ * The REST endpoints generated by API Gateway
6
+ * @see {@link https://docs.aws.amazon.com/general/latest/gr/apigateway.html#apigateway_region_data_plane}
7
+ */
8
+ export declare const APIG_HOSTNAME_PATTERN: RegExp;
@@ -0,0 +1,13 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ const DEFAULT_REST_IAM_SIGNING_SERVICE = 'execute-api';
4
+ const DEFAULT_APPSYNC_API_SERVICE = 'appsync-api';
5
+ const DEFAULT_IAM_SIGNING_REGION = 'us-east-1';
6
+ /**
7
+ * The REST endpoints generated by API Gateway
8
+ * @see {@link https://docs.aws.amazon.com/general/latest/gr/apigateway.html#apigateway_region_data_plane}
9
+ */
10
+ const APIG_HOSTNAME_PATTERN = /^.+\.([a-z0-9-]+)\.([a-z0-9-]+)\.amazonaws\.com/;
11
+
12
+ export { APIG_HOSTNAME_PATTERN, DEFAULT_APPSYNC_API_SERVICE, DEFAULT_IAM_SIGNING_REGION, DEFAULT_REST_IAM_SIGNING_SERVICE };
13
+ //# sourceMappingURL=constants.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.mjs","sources":["../../../src/utils/constants.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nexport const DEFAULT_REST_IAM_SIGNING_SERVICE = 'execute-api';\nexport const DEFAULT_APPSYNC_API_SERVICE = 'appsync-api';\nexport const DEFAULT_IAM_SIGNING_REGION = 'us-east-1';\n/**\n * The REST endpoints generated by API Gateway\n * @see {@link https://docs.aws.amazon.com/general/latest/gr/apigateway.html#apigateway_region_data_plane}\n */\nexport const APIG_HOSTNAME_PATTERN = /^.+\\.([a-z0-9-]+)\\.([a-z0-9-]+)\\.amazonaws\\.com/;\n"],"names":[],"mappings":"AAAA;AACA;AACY,MAAC,gCAAgC,GAAG;AACpC,MAAC,2BAA2B,GAAG;AAC/B,MAAC,0BAA0B,GAAG;AAC1C;AACA;AACA;AACA;AACY,MAAC,qBAAqB,GAAG;;;;"}
@@ -0,0 +1,12 @@
1
+ import { HttpResponse } from '@aws-amplify/core/internals/aws-client-utils';
2
+ import { Operation } from '../types';
3
+ /**
4
+ * Create a cancellable operation conforming to the internal POST API interface.
5
+ * @internal
6
+ */
7
+ export declare function createCancellableOperation(handler: () => Promise<HttpResponse>, abortController: AbortController, operationType: 'internal', timeout?: number): Promise<HttpResponse>;
8
+ /**
9
+ * Create a cancellable operation conforming to the external REST API interface.
10
+ * @internal
11
+ */
12
+ export declare function createCancellableOperation(handler: () => Promise<HttpResponse>, abortController: AbortController, operationType: 'public', timeout?: number): Operation<HttpResponse>;
@@ -0,0 +1,77 @@
1
+ import { CanceledError } from '../errors/CanceledError.mjs';
2
+ import '@aws-amplify/core/internals/utils';
3
+ import '../errors/validation.mjs';
4
+ import { parseRestApiServiceError } from './serviceError.mjs';
5
+ import { logger } from './logger.mjs';
6
+
7
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
8
+ // SPDX-License-Identifier: Apache-2.0
9
+ /**
10
+ * @internal
11
+ */
12
+ function createCancellableOperation(handler, abortController, operationType, timeout) {
13
+ const abortSignal = abortController.signal;
14
+ let abortReason;
15
+ if (timeout != null) {
16
+ if (timeout < 0) {
17
+ throw new Error('Timeout must be a non-negative number');
18
+ }
19
+ setTimeout(() => {
20
+ abortReason = 'TimeoutError';
21
+ abortController.abort(abortReason);
22
+ }, timeout);
23
+ }
24
+ const job = async () => {
25
+ try {
26
+ const response = await handler();
27
+ if (response.statusCode >= 300) {
28
+ throw await parseRestApiServiceError(response);
29
+ }
30
+ return response;
31
+ }
32
+ catch (error) {
33
+ if (error.name === 'AbortError' || abortSignal?.aborted === true) {
34
+ // Check if timeout caused the abort
35
+ const isTimeout = abortReason && abortReason === 'TimeoutError';
36
+ if (isTimeout) {
37
+ const timeoutError = new Error(`Request timeout after ${timeout}ms`);
38
+ timeoutError.name = 'TimeoutError';
39
+ logger.debug(timeoutError);
40
+ throw timeoutError;
41
+ }
42
+ else {
43
+ const message = abortReason ?? abortSignal.reason;
44
+ const canceledError = new CanceledError({
45
+ ...(message && { message }),
46
+ underlyingError: error,
47
+ recoverySuggestion: 'The API request was explicitly canceled. If this is not intended, validate if you called the `cancel()` function on the API request erroneously.',
48
+ });
49
+ logger.debug(canceledError);
50
+ throw canceledError;
51
+ }
52
+ }
53
+ logger.debug(error);
54
+ throw error;
55
+ }
56
+ };
57
+ if (operationType === 'internal') {
58
+ return job();
59
+ }
60
+ else {
61
+ const cancel = (abortMessage) => {
62
+ if (abortSignal.aborted === true) {
63
+ return;
64
+ }
65
+ abortController.abort(abortMessage);
66
+ // If abort reason is not supported, set a scoped reasons instead. The reason property inside an
67
+ // AbortSignal is a readonly property and trying to set it would throw an error.
68
+ if (abortMessage && abortSignal.reason !== abortMessage) {
69
+ abortReason = abortMessage;
70
+ }
71
+ };
72
+ return { response: job(), cancel };
73
+ }
74
+ }
75
+
76
+ export { createCancellableOperation };
77
+ //# sourceMappingURL=createCancellableOperation.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createCancellableOperation.mjs","sources":["../../../src/utils/createCancellableOperation.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { CanceledError } from '../errors';\nimport { parseRestApiServiceError } from './serviceError';\nimport { logger } from './logger';\n/**\n * @internal\n */\nexport function createCancellableOperation(handler, abortController, operationType, timeout) {\n const abortSignal = abortController.signal;\n let abortReason;\n if (timeout != null) {\n if (timeout < 0) {\n throw new Error('Timeout must be a non-negative number');\n }\n setTimeout(() => {\n abortReason = 'TimeoutError';\n abortController.abort(abortReason);\n }, timeout);\n }\n const job = async () => {\n try {\n const response = await handler();\n if (response.statusCode >= 300) {\n throw await parseRestApiServiceError(response);\n }\n return response;\n }\n catch (error) {\n if (error.name === 'AbortError' || abortSignal?.aborted === true) {\n // Check if timeout caused the abort\n const isTimeout = abortReason && abortReason === 'TimeoutError';\n if (isTimeout) {\n const timeoutError = new Error(`Request timeout after ${timeout}ms`);\n timeoutError.name = 'TimeoutError';\n logger.debug(timeoutError);\n throw timeoutError;\n }\n else {\n const message = abortReason ?? abortSignal.reason;\n const canceledError = new CanceledError({\n ...(message && { message }),\n underlyingError: error,\n recoverySuggestion: 'The API request was explicitly canceled. If this is not intended, validate if you called the `cancel()` function on the API request erroneously.',\n });\n logger.debug(canceledError);\n throw canceledError;\n }\n }\n logger.debug(error);\n throw error;\n }\n };\n if (operationType === 'internal') {\n return job();\n }\n else {\n const cancel = (abortMessage) => {\n if (abortSignal.aborted === true) {\n return;\n }\n abortController.abort(abortMessage);\n // If abort reason is not supported, set a scoped reasons instead. The reason property inside an\n // AbortSignal is a readonly property and trying to set it would throw an error.\n if (abortMessage && abortSignal.reason !== abortMessage) {\n abortReason = abortMessage;\n }\n };\n return { response: job(), cancel };\n }\n}\n"],"names":[],"mappings":";;;;;;AAAA;AACA;AAIA;AACA;AACA;AACO,SAAS,0BAA0B,CAAC,OAAO,EAAE,eAAe,EAAE,aAAa,EAAE,OAAO,EAAE;AAC7F,IAAI,MAAM,WAAW,GAAG,eAAe,CAAC,MAAM;AAC9C,IAAI,IAAI,WAAW;AACnB,IAAI,IAAI,OAAO,IAAI,IAAI,EAAE;AACzB,QAAQ,IAAI,OAAO,GAAG,CAAC,EAAE;AACzB,YAAY,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC;AACpE,QAAQ;AACR,QAAQ,UAAU,CAAC,MAAM;AACzB,YAAY,WAAW,GAAG,cAAc;AACxC,YAAY,eAAe,CAAC,KAAK,CAAC,WAAW,CAAC;AAC9C,QAAQ,CAAC,EAAE,OAAO,CAAC;AACnB,IAAI;AACJ,IAAI,MAAM,GAAG,GAAG,YAAY;AAC5B,QAAQ,IAAI;AACZ,YAAY,MAAM,QAAQ,GAAG,MAAM,OAAO,EAAE;AAC5C,YAAY,IAAI,QAAQ,CAAC,UAAU,IAAI,GAAG,EAAE;AAC5C,gBAAgB,MAAM,MAAM,wBAAwB,CAAC,QAAQ,CAAC;AAC9D,YAAY;AACZ,YAAY,OAAO,QAAQ;AAC3B,QAAQ;AACR,QAAQ,OAAO,KAAK,EAAE;AACtB,YAAY,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,IAAI,WAAW,EAAE,OAAO,KAAK,IAAI,EAAE;AAC9E;AACA,gBAAgB,MAAM,SAAS,GAAG,WAAW,IAAI,WAAW,KAAK,cAAc;AAC/E,gBAAgB,IAAI,SAAS,EAAE;AAC/B,oBAAoB,MAAM,YAAY,GAAG,IAAI,KAAK,CAAC,CAAC,sBAAsB,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;AACxF,oBAAoB,YAAY,CAAC,IAAI,GAAG,cAAc;AACtD,oBAAoB,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC;AAC9C,oBAAoB,MAAM,YAAY;AACtC,gBAAgB;AAChB,qBAAqB;AACrB,oBAAoB,MAAM,OAAO,GAAG,WAAW,IAAI,WAAW,CAAC,MAAM;AACrE,oBAAoB,MAAM,aAAa,GAAG,IAAI,aAAa,CAAC;AAC5D,wBAAwB,IAAI,OAAO,IAAI,EAAE,OAAO,EAAE,CAAC;AACnD,wBAAwB,eAAe,EAAE,KAAK;AAC9C,wBAAwB,kBAAkB,EAAE,kJAAkJ;AAC9L,qBAAqB,CAAC;AACtB,oBAAoB,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC;AAC/C,oBAAoB,MAAM,aAAa;AACvC,gBAAgB;AAChB,YAAY;AACZ,YAAY,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC;AAC/B,YAAY,MAAM,KAAK;AACvB,QAAQ;AACR,IAAI,CAAC;AACL,IAAI,IAAI,aAAa,KAAK,UAAU,EAAE;AACtC,QAAQ,OAAO,GAAG,EAAE;AACpB,IAAI;AACJ,SAAS;AACT,QAAQ,MAAM,MAAM,GAAG,CAAC,YAAY,KAAK;AACzC,YAAY,IAAI,WAAW,CAAC,OAAO,KAAK,IAAI,EAAE;AAC9C,gBAAgB;AAChB,YAAY;AACZ,YAAY,eAAe,CAAC,KAAK,CAAC,YAAY,CAAC;AAC/C;AACA;AACA,YAAY,IAAI,YAAY,IAAI,WAAW,CAAC,MAAM,KAAK,YAAY,EAAE;AACrE,gBAAgB,WAAW,GAAG,YAAY;AAC1C,YAAY;AACZ,QAAQ,CAAC;AACT,QAAQ,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE;AAC1C,IAAI;AACJ;;;;"}
@@ -0,0 +1,6 @@
1
+ export { createCancellableOperation } from './createCancellableOperation';
2
+ export { parseSigningInfo } from './parseSigningInfo';
3
+ export { parseRestApiServiceError } from './serviceError';
4
+ export { resolveApiUrl } from './resolveApiUrl';
5
+ export { resolveLibraryOptions } from './resolveLibraryOptions';
6
+ export { logger } from './logger';
@@ -0,0 +1,7 @@
1
+ export { createCancellableOperation } from './createCancellableOperation.mjs';
2
+ export { parseSigningInfo } from './parseSigningInfo.mjs';
3
+ export { parseRestApiServiceError } from './serviceError.mjs';
4
+ export { resolveApiUrl } from './resolveApiUrl.mjs';
5
+ export { resolveLibraryOptions } from './resolveLibraryOptions.mjs';
6
+ export { logger } from './logger.mjs';
7
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
@@ -0,0 +1,32 @@
1
+ import { HttpRequest } from '@aws-amplify/core/internals/aws-client-utils';
2
+ import { SigningServiceInfo } from '../types';
3
+ /**
4
+ * Determines if IAM authentication should be applied for a GraphQL request.
5
+ *
6
+ * This function checks the `headers` of the HTTP request to determine if IAM authentication
7
+ * is applicable. IAM authentication is considered applicable if there is no `authorization`
8
+ * header, no `x-api-key` header, and `signingServiceInfo` is provided.
9
+ *
10
+ * @param request - The HTTP request object containing headers.
11
+ * @param signingServiceInfo - Optional signing service information,
12
+ * including service and region.
13
+ * @returns A boolean `true` if IAM authentication should be applied.
14
+ *
15
+ * @internal
16
+ */
17
+ export declare const isIamAuthApplicableForGraphQL: ({ headers }: HttpRequest, signingServiceInfo?: SigningServiceInfo) => boolean;
18
+ /**
19
+ * Determines if IAM authentication should be applied for a REST request.
20
+ *
21
+ * This function checks the `headers` of the HTTP request to determine if IAM authentication
22
+ * is applicable. IAM authentication is considered applicable if there is no `authorization`
23
+ * header and `signingServiceInfo` is provided.
24
+ *
25
+ * @param request - The HTTP request object containing headers.
26
+ * @param signingServiceInfo - Optional signing service information,
27
+ * including service and region.
28
+ * @returns A boolean `true` if IAM authentication should be applied.
29
+ *
30
+ * @internal
31
+ */
32
+ export declare const isIamAuthApplicableForRest: ({ headers }: HttpRequest, signingServiceInfo?: SigningServiceInfo) => boolean;
@@ -0,0 +1,35 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ /**
4
+ * Determines if IAM authentication should be applied for a GraphQL request.
5
+ *
6
+ * This function checks the `headers` of the HTTP request to determine if IAM authentication
7
+ * is applicable. IAM authentication is considered applicable if there is no `authorization`
8
+ * header, no `x-api-key` header, and `signingServiceInfo` is provided.
9
+ *
10
+ * @param request - The HTTP request object containing headers.
11
+ * @param signingServiceInfo - Optional signing service information,
12
+ * including service and region.
13
+ * @returns A boolean `true` if IAM authentication should be applied.
14
+ *
15
+ * @internal
16
+ */
17
+ const isIamAuthApplicableForGraphQL = ({ headers }, signingServiceInfo) => !headers.authorization && !headers['x-api-key'] && !!signingServiceInfo;
18
+ /**
19
+ * Determines if IAM authentication should be applied for a REST request.
20
+ *
21
+ * This function checks the `headers` of the HTTP request to determine if IAM authentication
22
+ * is applicable. IAM authentication is considered applicable if there is no `authorization`
23
+ * header and `signingServiceInfo` is provided.
24
+ *
25
+ * @param request - The HTTP request object containing headers.
26
+ * @param signingServiceInfo - Optional signing service information,
27
+ * including service and region.
28
+ * @returns A boolean `true` if IAM authentication should be applied.
29
+ *
30
+ * @internal
31
+ */
32
+ const isIamAuthApplicableForRest = ({ headers }, signingServiceInfo) => !headers.authorization && !!signingServiceInfo;
33
+
34
+ export { isIamAuthApplicableForGraphQL, isIamAuthApplicableForRest };
35
+ //# sourceMappingURL=isIamAuthApplicable.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isIamAuthApplicable.mjs","sources":["../../../src/utils/isIamAuthApplicable.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n/**\n * Determines if IAM authentication should be applied for a GraphQL request.\n *\n * This function checks the `headers` of the HTTP request to determine if IAM authentication\n * is applicable. IAM authentication is considered applicable if there is no `authorization`\n * header, no `x-api-key` header, and `signingServiceInfo` is provided.\n *\n * @param request - The HTTP request object containing headers.\n * @param signingServiceInfo - Optional signing service information,\n * including service and region.\n * @returns A boolean `true` if IAM authentication should be applied.\n *\n * @internal\n */\nexport const isIamAuthApplicableForGraphQL = ({ headers }, signingServiceInfo) => !headers.authorization && !headers['x-api-key'] && !!signingServiceInfo;\n/**\n * Determines if IAM authentication should be applied for a REST request.\n *\n * This function checks the `headers` of the HTTP request to determine if IAM authentication\n * is applicable. IAM authentication is considered applicable if there is no `authorization`\n * header and `signingServiceInfo` is provided.\n *\n * @param request - The HTTP request object containing headers.\n * @param signingServiceInfo - Optional signing service information,\n * including service and region.\n * @returns A boolean `true` if IAM authentication should be applied.\n *\n * @internal\n */\nexport const isIamAuthApplicableForRest = ({ headers }, signingServiceInfo) => !headers.authorization && !!signingServiceInfo;\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,6BAA6B,GAAG,CAAC,EAAE,OAAO,EAAE,EAAE,kBAAkB,KAAK,CAAC,OAAO,CAAC,aAAa,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;AACvI;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,0BAA0B,GAAG,CAAC,EAAE,OAAO,EAAE,EAAE,kBAAkB,KAAK,CAAC,OAAO,CAAC,aAAa,IAAI,CAAC,CAAC;;;;"}
@@ -0,0 +1,2 @@
1
+ import { ConsoleLogger } from '@aws-amplify/core';
2
+ export declare const logger: ConsoleLogger;
@@ -0,0 +1,8 @@
1
+ import { ConsoleLogger } from '@aws-amplify/core';
2
+
3
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
+ // SPDX-License-Identifier: Apache-2.0
5
+ const logger = new ConsoleLogger('RestApis');
6
+
7
+ export { logger };
8
+ //# sourceMappingURL=logger.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.mjs","sources":["../../../src/utils/logger.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { ConsoleLogger } from '@aws-amplify/core';\nexport const logger = new ConsoleLogger('RestApis');\n"],"names":[],"mappings":";;AAAA;AACA;AAEY,MAAC,MAAM,GAAG,IAAI,aAAa,CAAC,UAAU;;;;"}
@@ -0,0 +1,14 @@
1
+ import { AmplifyClassV6 } from '@aws-amplify/core';
2
+ /**
3
+ * Infer the signing service and region from the given URL, and for REST API only, from the Amplify configuration.
4
+ * It supports raw API Gateway endpoint and AppSync endpoint.
5
+ *
6
+ * @internal
7
+ */
8
+ export declare const parseSigningInfo: (url: URL, restApiOptions?: {
9
+ amplify: AmplifyClassV6;
10
+ apiName: string;
11
+ }) => {
12
+ service: string;
13
+ region: string;
14
+ };
@@ -0,0 +1,41 @@
1
+ import { DEFAULT_IAM_SIGNING_REGION, DEFAULT_REST_IAM_SIGNING_SERVICE, APIG_HOSTNAME_PATTERN } from './constants.mjs';
2
+
3
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
+ // SPDX-License-Identifier: Apache-2.0
5
+ /**
6
+ * Infer the signing service and region from the given URL, and for REST API only, from the Amplify configuration.
7
+ * It supports raw API Gateway endpoint and AppSync endpoint.
8
+ *
9
+ * @internal
10
+ */
11
+ const parseSigningInfo = (url, restApiOptions) => {
12
+ const { service: signingService = DEFAULT_REST_IAM_SIGNING_SERVICE, region: signingRegion = DEFAULT_IAM_SIGNING_REGION, } = restApiOptions?.amplify.getConfig()?.API?.REST?.[restApiOptions?.apiName] ??
13
+ {};
14
+ const { hostname } = url;
15
+ const [, service, region] = APIG_HOSTNAME_PATTERN.exec(hostname) ?? [];
16
+ if (service === DEFAULT_REST_IAM_SIGNING_SERVICE) {
17
+ // The configured endpoint is an API Gateway endpoint
18
+ // @see: https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-call-api.html
19
+ return {
20
+ service,
21
+ region: region ?? signingRegion,
22
+ };
23
+ }
24
+ else if (service === 'appsync-api') {
25
+ // AppSync endpoint is internally supported because GraphQL operation will send request using POST handler.
26
+ // example: https://xxxx.appsync-api.us-east-1.amazonaws.com/graphql
27
+ return {
28
+ service: 'appsync',
29
+ region: region ?? signingRegion,
30
+ };
31
+ }
32
+ else {
33
+ return {
34
+ service: signingService,
35
+ region: signingRegion,
36
+ };
37
+ }
38
+ };
39
+
40
+ export { parseSigningInfo };
41
+ //# sourceMappingURL=parseSigningInfo.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseSigningInfo.mjs","sources":["../../../src/utils/parseSigningInfo.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { APIG_HOSTNAME_PATTERN, DEFAULT_IAM_SIGNING_REGION, DEFAULT_REST_IAM_SIGNING_SERVICE, } from './constants';\n/**\n * Infer the signing service and region from the given URL, and for REST API only, from the Amplify configuration.\n * It supports raw API Gateway endpoint and AppSync endpoint.\n *\n * @internal\n */\nexport const parseSigningInfo = (url, restApiOptions) => {\n const { service: signingService = DEFAULT_REST_IAM_SIGNING_SERVICE, region: signingRegion = DEFAULT_IAM_SIGNING_REGION, } = restApiOptions?.amplify.getConfig()?.API?.REST?.[restApiOptions?.apiName] ??\n {};\n const { hostname } = url;\n const [, service, region] = APIG_HOSTNAME_PATTERN.exec(hostname) ?? [];\n if (service === DEFAULT_REST_IAM_SIGNING_SERVICE) {\n // The configured endpoint is an API Gateway endpoint\n // @see: https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-call-api.html\n return {\n service,\n region: region ?? signingRegion,\n };\n }\n else if (service === 'appsync-api') {\n // AppSync endpoint is internally supported because GraphQL operation will send request using POST handler.\n // example: https://xxxx.appsync-api.us-east-1.amazonaws.com/graphql\n return {\n service: 'appsync',\n region: region ?? signingRegion,\n };\n }\n else {\n return {\n service: signingService,\n region: signingRegion,\n };\n }\n};\n"],"names":[],"mappings":";;AAAA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,gBAAgB,GAAG,CAAC,GAAG,EAAE,cAAc,KAAK;AACzD,IAAI,MAAM,EAAE,OAAO,EAAE,cAAc,GAAG,gCAAgC,EAAE,MAAM,EAAE,aAAa,GAAG,0BAA0B,GAAG,GAAG,cAAc,EAAE,OAAO,CAAC,SAAS,EAAE,EAAE,GAAG,EAAE,IAAI,GAAG,cAAc,EAAE,OAAO,CAAC;AACzM,QAAQ,EAAE;AACV,IAAI,MAAM,EAAE,QAAQ,EAAE,GAAG,GAAG;AAC5B,IAAI,MAAM,GAAG,OAAO,EAAE,MAAM,CAAC,GAAG,qBAAqB,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE;AAC1E,IAAI,IAAI,OAAO,KAAK,gCAAgC,EAAE;AACtD;AACA;AACA,QAAQ,OAAO;AACf,YAAY,OAAO;AACnB,YAAY,MAAM,EAAE,MAAM,IAAI,aAAa;AAC3C,SAAS;AACT,IAAI;AACJ,SAAS,IAAI,OAAO,KAAK,aAAa,EAAE;AACxC;AACA;AACA,QAAQ,OAAO;AACf,YAAY,OAAO,EAAE,SAAS;AAC9B,YAAY,MAAM,EAAE,MAAM,IAAI,aAAa;AAC3C,SAAS;AACT,IAAI;AACJ,SAAS;AACT,QAAQ,OAAO;AACf,YAAY,OAAO,EAAE,cAAc;AACnC,YAAY,MAAM,EAAE,aAAa;AACjC,SAAS;AACT,IAAI;AACJ;;;;"}
@@ -0,0 +1,12 @@
1
+ import { AmplifyClassV6 } from '@aws-amplify/core';
2
+ /**
3
+ * Resolve the REST API request URL by:
4
+ * 1. Loading the REST API endpoint from the Amplify configuration with corresponding API name.
5
+ * 2. Appending the path to the endpoint.
6
+ * 3. Merge the query parameters from path and the queryParameter argument which is taken from the public REST API
7
+ * options.
8
+ * 4. Validating the resulting URL string.
9
+ *
10
+ * @internal
11
+ */
12
+ export declare const resolveApiUrl: (amplify: AmplifyClassV6, apiName: string, path: string, queryParams?: Record<string, string>) => URL;
@@ -0,0 +1,48 @@
1
+ import { AmplifyUrl, AmplifyUrlSearchParams } from '@aws-amplify/core/internals/utils';
2
+ import { RestApiError } from '../errors/RestApiError.mjs';
3
+ import { assertValidationError } from '../errors/assertValidatonError.mjs';
4
+ import { RestApiValidationErrorCode, validationErrorMap } from '../errors/validation.mjs';
5
+
6
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
7
+ // SPDX-License-Identifier: Apache-2.0
8
+ /**
9
+ * Resolve the REST API request URL by:
10
+ * 1. Loading the REST API endpoint from the Amplify configuration with corresponding API name.
11
+ * 2. Appending the path to the endpoint.
12
+ * 3. Merge the query parameters from path and the queryParameter argument which is taken from the public REST API
13
+ * options.
14
+ * 4. Validating the resulting URL string.
15
+ *
16
+ * @internal
17
+ */
18
+ const resolveApiUrl = (amplify, apiName, path, queryParams) => {
19
+ const urlStr = amplify.getConfig()?.API?.REST?.[apiName]?.endpoint;
20
+ assertValidationError(!!urlStr, RestApiValidationErrorCode.InvalidApiName);
21
+ try {
22
+ let url;
23
+ if (AmplifyUrl.canParse(urlStr + path)) {
24
+ url = new AmplifyUrl(urlStr + path);
25
+ }
26
+ else {
27
+ url = new AmplifyUrl(urlStr + path, location?.origin);
28
+ }
29
+ if (queryParams) {
30
+ const mergedQueryParams = new AmplifyUrlSearchParams(url.searchParams);
31
+ Object.entries(queryParams).forEach(([key, value]) => {
32
+ mergedQueryParams.set(key, value);
33
+ });
34
+ url.search = new AmplifyUrlSearchParams(mergedQueryParams).toString();
35
+ }
36
+ return url;
37
+ }
38
+ catch (error) {
39
+ throw new RestApiError({
40
+ name: RestApiValidationErrorCode.InvalidApiName,
41
+ ...validationErrorMap[RestApiValidationErrorCode.InvalidApiName],
42
+ recoverySuggestion: `Please make sure the REST endpoint URL is a valid URL string. Got ${urlStr}`,
43
+ });
44
+ }
45
+ };
46
+
47
+ export { resolveApiUrl };
48
+ //# sourceMappingURL=resolveApiUrl.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveApiUrl.mjs","sources":["../../../src/utils/resolveApiUrl.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { AmplifyUrl, AmplifyUrlSearchParams, } from '@aws-amplify/core/internals/utils';\nimport { RestApiError, RestApiValidationErrorCode, assertValidationError, validationErrorMap, } from '../errors';\n/**\n * Resolve the REST API request URL by:\n * 1. Loading the REST API endpoint from the Amplify configuration with corresponding API name.\n * 2. Appending the path to the endpoint.\n * 3. Merge the query parameters from path and the queryParameter argument which is taken from the public REST API\n * options.\n * 4. Validating the resulting URL string.\n *\n * @internal\n */\nexport const resolveApiUrl = (amplify, apiName, path, queryParams) => {\n const urlStr = amplify.getConfig()?.API?.REST?.[apiName]?.endpoint;\n assertValidationError(!!urlStr, RestApiValidationErrorCode.InvalidApiName);\n try {\n let url;\n if (AmplifyUrl.canParse(urlStr + path)) {\n url = new AmplifyUrl(urlStr + path);\n }\n else {\n url = new AmplifyUrl(urlStr + path, location?.origin);\n }\n if (queryParams) {\n const mergedQueryParams = new AmplifyUrlSearchParams(url.searchParams);\n Object.entries(queryParams).forEach(([key, value]) => {\n mergedQueryParams.set(key, value);\n });\n url.search = new AmplifyUrlSearchParams(mergedQueryParams).toString();\n }\n return url;\n }\n catch (error) {\n throw new RestApiError({\n name: RestApiValidationErrorCode.InvalidApiName,\n ...validationErrorMap[RestApiValidationErrorCode.InvalidApiName],\n recoverySuggestion: `Please make sure the REST endpoint URL is a valid URL string. Got ${urlStr}`,\n });\n }\n};\n"],"names":[],"mappings":";;;;;AAAA;AACA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,aAAa,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,KAAK;AACtE,IAAI,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,EAAE,GAAG,EAAE,IAAI,GAAG,OAAO,CAAC,EAAE,QAAQ;AACtE,IAAI,qBAAqB,CAAC,CAAC,CAAC,MAAM,EAAE,0BAA0B,CAAC,cAAc,CAAC;AAC9E,IAAI,IAAI;AACR,QAAQ,IAAI,GAAG;AACf,QAAQ,IAAI,UAAU,CAAC,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC,EAAE;AAChD,YAAY,GAAG,GAAG,IAAI,UAAU,CAAC,MAAM,GAAG,IAAI,CAAC;AAC/C,QAAQ;AACR,aAAa;AACb,YAAY,GAAG,GAAG,IAAI,UAAU,CAAC,MAAM,GAAG,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC;AACjE,QAAQ;AACR,QAAQ,IAAI,WAAW,EAAE;AACzB,YAAY,MAAM,iBAAiB,GAAG,IAAI,sBAAsB,CAAC,GAAG,CAAC,YAAY,CAAC;AAClF,YAAY,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,KAAK;AAClE,gBAAgB,iBAAiB,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC;AACjD,YAAY,CAAC,CAAC;AACd,YAAY,GAAG,CAAC,MAAM,GAAG,IAAI,sBAAsB,CAAC,iBAAiB,CAAC,CAAC,QAAQ,EAAE;AACjF,QAAQ;AACR,QAAQ,OAAO,GAAG;AAClB,IAAI;AACJ,IAAI,OAAO,KAAK,EAAE;AAClB,QAAQ,MAAM,IAAI,YAAY,CAAC;AAC/B,YAAY,IAAI,EAAE,0BAA0B,CAAC,cAAc;AAC3D,YAAY,GAAG,kBAAkB,CAAC,0BAA0B,CAAC,cAAc,CAAC;AAC5E,YAAY,kBAAkB,EAAE,CAAC,kEAAkE,EAAE,MAAM,CAAC,CAAC;AAC7G,SAAS,CAAC;AACV,IAAI;AACJ;;;;"}
@@ -0,0 +1 @@
1
+ export declare const resolveHeaders: (headers?: Record<string, string>, body?: unknown) => Record<string, string>;
@@ -0,0 +1,31 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ const resolveHeaders = (headers, body) => {
4
+ const normalizedHeaders = {};
5
+ for (const key in headers) {
6
+ normalizedHeaders[key.toLowerCase()] = headers[key];
7
+ }
8
+ if (body) {
9
+ const contentType = normalizedHeaders['content-type'];
10
+ const isJsonCompatible = contentType &&
11
+ (contentType.startsWith('application/json') ||
12
+ (contentType.startsWith('application/') &&
13
+ contentType.includes('+json')));
14
+ if (!isJsonCompatible) {
15
+ normalizedHeaders['content-type'] = 'application/json; charset=UTF-8';
16
+ }
17
+ if (body instanceof FormData) {
18
+ /**
19
+ * If body is a FormData we should not allow setting content-type.
20
+ * It's because runtime HTTP handlers(xhr, fetch, undici, node-fetch,
21
+ * etc.) will modify the content-type value when setting multipart
22
+ * boundary.
23
+ */
24
+ delete normalizedHeaders['content-type'];
25
+ }
26
+ }
27
+ return normalizedHeaders;
28
+ };
29
+
30
+ export { resolveHeaders };
31
+ //# sourceMappingURL=resolveHeaders.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveHeaders.mjs","sources":["../../../src/utils/resolveHeaders.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nexport const resolveHeaders = (headers, body) => {\n const normalizedHeaders = {};\n for (const key in headers) {\n normalizedHeaders[key.toLowerCase()] = headers[key];\n }\n if (body) {\n const contentType = normalizedHeaders['content-type'];\n const isJsonCompatible = contentType &&\n (contentType.startsWith('application/json') ||\n (contentType.startsWith('application/') &&\n contentType.includes('+json')));\n if (!isJsonCompatible) {\n normalizedHeaders['content-type'] = 'application/json; charset=UTF-8';\n }\n if (body instanceof FormData) {\n /**\n * If body is a FormData we should not allow setting content-type.\n * It's because runtime HTTP handlers(xhr, fetch, undici, node-fetch,\n * etc.) will modify the content-type value when setting multipart\n * boundary.\n */\n delete normalizedHeaders['content-type'];\n }\n }\n return normalizedHeaders;\n};\n"],"names":[],"mappings":"AAAA;AACA;AACY,MAAC,cAAc,GAAG,CAAC,OAAO,EAAE,IAAI,KAAK;AACjD,IAAI,MAAM,iBAAiB,GAAG,EAAE;AAChC,IAAI,KAAK,MAAM,GAAG,IAAI,OAAO,EAAE;AAC/B,QAAQ,iBAAiB,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC;AAC3D,IAAI;AACJ,IAAI,IAAI,IAAI,EAAE;AACd,QAAQ,MAAM,WAAW,GAAG,iBAAiB,CAAC,cAAc,CAAC;AAC7D,QAAQ,MAAM,gBAAgB,GAAG,WAAW;AAC5C,aAAa,WAAW,CAAC,UAAU,CAAC,kBAAkB,CAAC;AACvD,iBAAiB,WAAW,CAAC,UAAU,CAAC,cAAc,CAAC;AACvD,oBAAoB,WAAW,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC;AACnD,QAAQ,IAAI,CAAC,gBAAgB,EAAE;AAC/B,YAAY,iBAAiB,CAAC,cAAc,CAAC,GAAG,iCAAiC;AACjF,QAAQ;AACR,QAAQ,IAAI,IAAI,YAAY,QAAQ,EAAE;AACtC;AACA;AACA;AACA;AACA;AACA;AACA,YAAY,OAAO,iBAAiB,CAAC,cAAc,CAAC;AACpD,QAAQ;AACR,IAAI;AACJ,IAAI,OAAO,iBAAiB;AAC5B;;;;"}
@@ -0,0 +1,8 @@
1
+ import { AmplifyClassV6 } from '@aws-amplify/core';
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare const resolveLibraryOptions: (amplify: AmplifyClassV6) => {
6
+ retryStrategy: import("@aws-amplify/core/internals/utils").RetryStrategy | undefined;
7
+ defaultAuthMode: import("@aws-amplify/core/internals/utils").RESTAuthMode | undefined;
8
+ };
@@ -0,0 +1,13 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ /**
4
+ * @internal
5
+ */
6
+ const resolveLibraryOptions = (amplify) => {
7
+ const retryStrategy = amplify.libraryOptions?.API?.REST?.retryStrategy;
8
+ const defaultAuthMode = amplify.libraryOptions?.API?.REST?.defaultAuthMode;
9
+ return { retryStrategy, defaultAuthMode };
10
+ };
11
+
12
+ export { resolveLibraryOptions };
13
+ //# sourceMappingURL=resolveLibraryOptions.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveLibraryOptions.mjs","sources":["../../../src/utils/resolveLibraryOptions.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n/**\n * @internal\n */\nexport const resolveLibraryOptions = (amplify) => {\n const retryStrategy = amplify.libraryOptions?.API?.REST?.retryStrategy;\n const defaultAuthMode = amplify.libraryOptions?.API?.REST?.defaultAuthMode;\n return { retryStrategy, defaultAuthMode };\n};\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACY,MAAC,qBAAqB,GAAG,CAAC,OAAO,KAAK;AAClD,IAAI,MAAM,aAAa,GAAG,OAAO,CAAC,cAAc,EAAE,GAAG,EAAE,IAAI,EAAE,aAAa;AAC1E,IAAI,MAAM,eAAe,GAAG,OAAO,CAAC,cAAc,EAAE,GAAG,EAAE,IAAI,EAAE,eAAe;AAC9E,IAAI,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE;AAC7C;;;;"}
@@ -0,0 +1,13 @@
1
+ import { MetadataBearer } from '@aws-sdk/types';
2
+ import { HttpResponse } from '@aws-amplify/core/internals/aws-client-utils';
3
+ import { RestApiError } from '../errors';
4
+ /**
5
+ * Parses both AWS and non-AWS error responses coming from the users' backend code.
6
+ * * AWS errors generated by the AWS services(e.g. API Gateway, Bedrock). They can be Signature errors,
7
+ * ClockSkew errors, etc. These responses will be parsed to errors with proper name and message from the AWS
8
+ * services.
9
+ * * non-AWS errors thrown by the user code. They can contain any headers or body. Users need to access the
10
+ * error.response to get the headers and body and parse them accordingly. The JS error name and message will
11
+ * be `UnknownError` and `Unknown error` respectively.
12
+ */
13
+ export declare const parseRestApiServiceError: (response?: HttpResponse) => Promise<(RestApiError & MetadataBearer) | undefined>;