@aws-amplify/api-rest 4.0.17-unstable.e316a2e.0 → 4.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/apis/common/internalPost.js +2 -2
- package/dist/cjs/apis/common/internalPost.js.map +1 -1
- package/dist/cjs/apis/server.js +0 -1
- package/dist/cjs/apis/server.js.map +1 -1
- package/dist/cjs/utils/createCancellableOperation.js +1 -1
- package/dist/cjs/utils/createCancellableOperation.js.map +1 -1
- package/dist/cjs/utils/resolveHeaders.js.map +1 -1
- package/dist/cjs/utils/serviceError.js +2 -5
- package/dist/cjs/utils/serviceError.js.map +1 -1
- package/dist/esm/apis/common/handler.d.ts +3 -3
- package/dist/esm/apis/common/handler.mjs.map +1 -1
- package/dist/esm/apis/common/internalPost.mjs +2 -2
- package/dist/esm/apis/common/internalPost.mjs.map +1 -1
- package/dist/esm/apis/common/publicApis.d.ts +1 -1
- package/dist/esm/apis/common/publicApis.mjs.map +1 -1
- package/dist/esm/apis/index.mjs.map +1 -1
- package/dist/esm/apis/server.d.ts +0 -1
- package/dist/esm/apis/server.mjs +0 -1
- package/dist/esm/apis/server.mjs.map +1 -1
- package/dist/esm/types/index.d.ts +14 -14
- package/dist/esm/utils/createCancellableOperation.mjs +1 -1
- package/dist/esm/utils/createCancellableOperation.mjs.map +1 -1
- package/dist/esm/utils/resolveHeaders.mjs.map +1 -1
- package/dist/esm/utils/serviceError.mjs +2 -5
- package/dist/esm/utils/serviceError.mjs.map +1 -1
- package/package.json +101 -100
- package/src/apis/common/handler.ts +10 -8
- package/src/apis/common/internalPost.ts +11 -6
- package/src/apis/common/publicApis.ts +19 -16
- package/src/apis/index.ts +10 -8
- package/src/apis/server.ts +16 -15
- package/src/errors/CanceledError.ts +1 -0
- package/src/errors/assertValidatonError.ts +1 -1
- package/src/internals/server.ts +1 -1
- package/src/types/index.ts +14 -14
- package/src/utils/createCancellableOperation.ts +10 -6
- package/src/utils/parseSigningInfo.ts +2 -1
- package/src/utils/resolveApiUrl.ts +3 -1
- package/src/utils/resolveHeaders.ts +2 -2
- package/src/utils/serviceError.ts +7 -4
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { HttpResponse } from '@aws-amplify/core/internals/aws-client-utils';
|
|
5
|
+
|
|
5
6
|
import { CanceledError } from '../errors';
|
|
6
7
|
import { Operation } from '../types';
|
|
8
|
+
|
|
7
9
|
import { parseRestApiServiceError } from './serviceError';
|
|
8
10
|
import { logger } from './logger';
|
|
9
11
|
|
|
@@ -13,7 +15,7 @@ import { logger } from './logger';
|
|
|
13
15
|
*/
|
|
14
16
|
export function createCancellableOperation(
|
|
15
17
|
handler: () => Promise<HttpResponse>,
|
|
16
|
-
abortController: AbortController
|
|
18
|
+
abortController: AbortController,
|
|
17
19
|
): Promise<HttpResponse>;
|
|
18
20
|
|
|
19
21
|
/**
|
|
@@ -21,7 +23,7 @@ export function createCancellableOperation(
|
|
|
21
23
|
* @internal
|
|
22
24
|
*/
|
|
23
25
|
export function createCancellableOperation(
|
|
24
|
-
handler: (signal: AbortSignal) => Promise<HttpResponse
|
|
26
|
+
handler: (signal: AbortSignal) => Promise<HttpResponse>,
|
|
25
27
|
): Operation<HttpResponse>;
|
|
26
28
|
|
|
27
29
|
/**
|
|
@@ -31,13 +33,13 @@ export function createCancellableOperation(
|
|
|
31
33
|
handler:
|
|
32
34
|
| ((signal: AbortSignal) => Promise<HttpResponse>)
|
|
33
35
|
| (() => Promise<HttpResponse>),
|
|
34
|
-
abortController?: AbortController
|
|
36
|
+
abortController?: AbortController,
|
|
35
37
|
): Operation<HttpResponse> | Promise<HttpResponse> {
|
|
36
38
|
const isInternalPost = (
|
|
37
|
-
|
|
39
|
+
targetHandler:
|
|
38
40
|
| ((signal: AbortSignal) => Promise<HttpResponse>)
|
|
39
|
-
| (() => Promise<HttpResponse>)
|
|
40
|
-
):
|
|
41
|
+
| (() => Promise<HttpResponse>),
|
|
42
|
+
): targetHandler is () => Promise<HttpResponse> => !!abortController;
|
|
41
43
|
|
|
42
44
|
// For creating a cancellable operation for public REST APIs, we need to create an AbortController
|
|
43
45
|
// internally. Whereas for internal POST APIs, we need to accept in the AbortController from the
|
|
@@ -56,6 +58,7 @@ export function createCancellableOperation(
|
|
|
56
58
|
if (response.statusCode >= 300) {
|
|
57
59
|
throw await parseRestApiServiceError(response)!;
|
|
58
60
|
}
|
|
61
|
+
|
|
59
62
|
return response;
|
|
60
63
|
} catch (error: any) {
|
|
61
64
|
const abortSignal = internalPostAbortSignal ?? publicApisAbortSignal;
|
|
@@ -87,6 +90,7 @@ export function createCancellableOperation(
|
|
|
87
90
|
abortReason = abortMessage;
|
|
88
91
|
}
|
|
89
92
|
};
|
|
93
|
+
|
|
90
94
|
return { response: job(), cancel };
|
|
91
95
|
}
|
|
92
96
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
4
|
import { AmplifyClassV6 } from '@aws-amplify/core';
|
|
5
|
+
|
|
5
6
|
import {
|
|
6
7
|
APIG_HOSTNAME_PATTERN,
|
|
7
8
|
DEFAULT_IAM_SIGNING_REGION,
|
|
@@ -19,7 +20,7 @@ export const parseSigningInfo = (
|
|
|
19
20
|
restApiOptions?: {
|
|
20
21
|
amplify: AmplifyClassV6;
|
|
21
22
|
apiName: string;
|
|
22
|
-
}
|
|
23
|
+
},
|
|
23
24
|
) => {
|
|
24
25
|
const {
|
|
25
26
|
service: signingService = DEFAULT_REST_IAM_SIGNING_SERVICE,
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
AmplifyUrl,
|
|
7
7
|
AmplifyUrlSearchParams,
|
|
8
8
|
} from '@aws-amplify/core/internals/utils';
|
|
9
|
+
|
|
9
10
|
import {
|
|
10
11
|
RestApiError,
|
|
11
12
|
RestApiValidationErrorCode,
|
|
@@ -27,7 +28,7 @@ export const resolveApiUrl = (
|
|
|
27
28
|
amplify: AmplifyClassV6,
|
|
28
29
|
apiName: string,
|
|
29
30
|
path: string,
|
|
30
|
-
queryParams?: Record<string, string
|
|
31
|
+
queryParams?: Record<string, string>,
|
|
31
32
|
): URL => {
|
|
32
33
|
const urlStr = amplify.getConfig()?.API?.REST?.[apiName]?.endpoint;
|
|
33
34
|
assertValidationError(!!urlStr, RestApiValidationErrorCode.InvalidApiName);
|
|
@@ -40,6 +41,7 @@ export const resolveApiUrl = (
|
|
|
40
41
|
});
|
|
41
42
|
url.search = new AmplifyUrlSearchParams(mergedQueryParams).toString();
|
|
42
43
|
}
|
|
44
|
+
|
|
43
45
|
return url;
|
|
44
46
|
} catch (error) {
|
|
45
47
|
throw new RestApiError({
|
|
@@ -3,10 +3,9 @@
|
|
|
3
3
|
|
|
4
4
|
export const resolveHeaders = (
|
|
5
5
|
headers?: Record<string, string>,
|
|
6
|
-
body?: unknown
|
|
6
|
+
body?: unknown,
|
|
7
7
|
) => {
|
|
8
8
|
const normalizedHeaders: Record<string, string> = {};
|
|
9
|
-
const isFormData = body instanceof FormData;
|
|
10
9
|
for (const key in headers) {
|
|
11
10
|
normalizedHeaders[key.toLowerCase()] = headers[key];
|
|
12
11
|
}
|
|
@@ -22,5 +21,6 @@ export const resolveHeaders = (
|
|
|
22
21
|
delete normalizedHeaders['content-type'];
|
|
23
22
|
}
|
|
24
23
|
}
|
|
24
|
+
|
|
25
25
|
return normalizedHeaders;
|
|
26
26
|
};
|
|
@@ -19,7 +19,7 @@ import { RestApiError } from '../errors';
|
|
|
19
19
|
* be `UnknownError` and `Unknown error` respectively.
|
|
20
20
|
*/
|
|
21
21
|
export const parseRestApiServiceError = async (
|
|
22
|
-
response?: HttpResponse
|
|
22
|
+
response?: HttpResponse,
|
|
23
23
|
): Promise<(RestApiError & MetadataBearer) | undefined> => {
|
|
24
24
|
if (!response) {
|
|
25
25
|
// Response is not considered an error.
|
|
@@ -28,9 +28,9 @@ export const parseRestApiServiceError = async (
|
|
|
28
28
|
const parsedAwsError = await parseAwsJsonError(stubErrorResponse(response));
|
|
29
29
|
if (!parsedAwsError) {
|
|
30
30
|
// Response is not considered an error.
|
|
31
|
-
return;
|
|
32
31
|
} else {
|
|
33
32
|
const bodyText = await response.body?.text();
|
|
33
|
+
|
|
34
34
|
return buildRestApiError(parsedAwsError, {
|
|
35
35
|
statusCode: response.statusCode,
|
|
36
36
|
headers: response.headers,
|
|
@@ -46,7 +46,7 @@ export const parseRestApiServiceError = async (
|
|
|
46
46
|
* make sure we can read the error response body as a JSON, and may fall back to read as text if it is not a valid JSON.
|
|
47
47
|
*/
|
|
48
48
|
const stubErrorResponse = (response: HttpResponse): HttpResponse => {
|
|
49
|
-
let bodyTextPromise: Promise<string> | undefined
|
|
49
|
+
let bodyTextPromise: Promise<string> | undefined;
|
|
50
50
|
const bodyProxy = new Proxy(response.body, {
|
|
51
51
|
get(target, prop, receiver) {
|
|
52
52
|
if (prop === 'json') {
|
|
@@ -69,6 +69,7 @@ const stubErrorResponse = (response: HttpResponse): HttpResponse => {
|
|
|
69
69
|
if (!bodyTextPromise) {
|
|
70
70
|
bodyTextPromise = target.text();
|
|
71
71
|
}
|
|
72
|
+
|
|
72
73
|
return bodyTextPromise;
|
|
73
74
|
};
|
|
74
75
|
} else {
|
|
@@ -85,6 +86,7 @@ const stubErrorResponse = (response: HttpResponse): HttpResponse => {
|
|
|
85
86
|
}
|
|
86
87
|
},
|
|
87
88
|
});
|
|
89
|
+
|
|
88
90
|
return responseProxy;
|
|
89
91
|
};
|
|
90
92
|
|
|
@@ -93,7 +95,7 @@ const stubErrorResponse = (response: HttpResponse): HttpResponse => {
|
|
|
93
95
|
*/
|
|
94
96
|
const buildRestApiError = (
|
|
95
97
|
error: Error & MetadataBearer,
|
|
96
|
-
response?: ApiErrorResponse
|
|
98
|
+
response?: ApiErrorResponse,
|
|
97
99
|
): RestApiError & MetadataBearer => {
|
|
98
100
|
const restApiError = new RestApiError({
|
|
99
101
|
name: error?.name,
|
|
@@ -101,6 +103,7 @@ const buildRestApiError = (
|
|
|
101
103
|
underlyingError: error,
|
|
102
104
|
response,
|
|
103
105
|
});
|
|
106
|
+
|
|
104
107
|
// $metadata is only required for backwards compatibility.
|
|
105
108
|
return Object.assign(restApiError, { $metadata: error.$metadata });
|
|
106
109
|
};
|