@aws-amplify/api-rest 4.0.1-api-v6-models.9351bcf.0 → 4.0.1-api-v6-models.891fe0d.0
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/lib/apis/common/handler.d.ts +1 -5
- package/lib/apis/common/handler.js +59 -65
- package/lib/apis/common/internalPost.js +18 -18
- package/lib/apis/common/publicApis.js +33 -39
- package/lib/apis/index.js +8 -16
- package/lib/apis/server.js +8 -20
- package/lib/errors/CanceledError.js +12 -15
- package/lib/errors/RestApiError.js +7 -11
- package/lib/errors/assertValidatonError.js +4 -4
- package/lib/errors/validation.js +4 -5
- package/lib/internals/index.js +3 -3
- package/lib/internals/server.js +3 -3
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/utils/createCancellableOperation.js +32 -39
- package/lib/utils/logger.js +1 -1
- package/lib/utils/normalizeHeaders.js +3 -3
- package/lib/utils/parseSigningInfo.js +9 -10
- package/lib/utils/resolveApiUrl.js +14 -13
- package/lib/utils/resolveCredentials.js +6 -14
- package/lib/utils/serviceError.js +14 -22
- package/lib-esm/apis/common/handler.d.ts +1 -5
- package/lib-esm/apis/common/handler.js +55 -61
- package/lib-esm/apis/common/internalPost.js +16 -16
- package/lib-esm/apis/common/publicApis.js +31 -37
- package/lib-esm/apis/index.js +6 -14
- package/lib-esm/apis/server.js +6 -18
- package/lib-esm/errors/CanceledError.js +11 -15
- package/lib-esm/errors/RestApiError.js +6 -11
- package/lib-esm/errors/assertValidatonError.js +2 -2
- package/lib-esm/errors/validation.js +4 -5
- package/lib-esm/internals/index.js +1 -1
- package/lib-esm/internals/server.js +1 -1
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/utils/constants.js +4 -4
- package/lib-esm/utils/createCancellableOperation.js +29 -36
- package/lib-esm/utils/logger.js +1 -1
- package/lib-esm/utils/normalizeHeaders.js +3 -3
- package/lib-esm/utils/parseSigningInfo.js +8 -9
- package/lib-esm/utils/resolveApiUrl.js +12 -11
- package/lib-esm/utils/resolveCredentials.js +5 -13
- package/lib-esm/utils/serviceError.js +12 -20
- package/package.json +5 -5
|
@@ -21,11 +21,7 @@ type SigningServiceInfo = {
|
|
|
21
21
|
*
|
|
22
22
|
* @internal
|
|
23
23
|
*/
|
|
24
|
-
export declare const transferHandler: (amplify: AmplifyClassV6, options:
|
|
25
|
-
body?: DocumentType | FormData | undefined;
|
|
26
|
-
headers?: Headers | undefined;
|
|
27
|
-
withCredentials?: boolean | undefined;
|
|
28
|
-
} & {
|
|
24
|
+
export declare const transferHandler: (amplify: AmplifyClassV6, options: HandlerOptions & {
|
|
29
25
|
abortSignal: AbortSignal;
|
|
30
26
|
}, signingServiceInfo?: SigningServiceInfo) => Promise<RestApiResponse>;
|
|
31
27
|
export {};
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.transferHandler = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var normalizeHeaders_1 = require("../../utils/normalizeHeaders");
|
|
4
|
+
const aws_client_utils_1 = require("@aws-amplify/core/internals/aws-client-utils");
|
|
5
|
+
const utils_1 = require("../../utils");
|
|
6
|
+
const normalizeHeaders_1 = require("../../utils/normalizeHeaders");
|
|
8
7
|
/**
|
|
9
8
|
* Make REST API call with best-effort IAM auth.
|
|
10
9
|
* @param amplify Amplify instance to to resolve credentials and tokens. Should use different instance in client-side
|
|
@@ -15,65 +14,60 @@ var normalizeHeaders_1 = require("../../utils/normalizeHeaders");
|
|
|
15
14
|
*
|
|
16
15
|
* @internal
|
|
17
16
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
}); };
|
|
75
|
-
exports.transferHandler = transferHandler;
|
|
76
|
-
var iamAuthApplicable = function (_a, signingServiceInfo) {
|
|
77
|
-
var headers = _a.headers;
|
|
78
|
-
return !headers.authorization && !headers['x-api-key'] && !!signingServiceInfo;
|
|
17
|
+
const transferHandler = async (amplify, options, signingServiceInfo) => {
|
|
18
|
+
const { url, method, headers, body, withCredentials, abortSignal } = options;
|
|
19
|
+
const resolvedBody = body
|
|
20
|
+
? body instanceof FormData
|
|
21
|
+
? body
|
|
22
|
+
: JSON.stringify(body ?? '')
|
|
23
|
+
: undefined;
|
|
24
|
+
const resolvedHeaders = {
|
|
25
|
+
...(0, normalizeHeaders_1.normalizeHeaders)(headers),
|
|
26
|
+
...(resolvedBody
|
|
27
|
+
? {
|
|
28
|
+
'content-type': body instanceof FormData
|
|
29
|
+
? 'multipart/form-data'
|
|
30
|
+
: 'application/json; charset=UTF-8',
|
|
31
|
+
}
|
|
32
|
+
: {}),
|
|
33
|
+
};
|
|
34
|
+
const request = {
|
|
35
|
+
url,
|
|
36
|
+
headers: resolvedHeaders,
|
|
37
|
+
method,
|
|
38
|
+
body: resolvedBody,
|
|
39
|
+
};
|
|
40
|
+
const baseOptions = {
|
|
41
|
+
retryDecider: (0, aws_client_utils_1.getRetryDecider)(utils_1.parseRestApiServiceError),
|
|
42
|
+
computeDelay: aws_client_utils_1.jitteredBackoff,
|
|
43
|
+
withCrossDomainCredentials: withCredentials,
|
|
44
|
+
abortSignal,
|
|
45
|
+
};
|
|
46
|
+
const isIamAuthApplicable = iamAuthApplicable(request, signingServiceInfo);
|
|
47
|
+
let response;
|
|
48
|
+
if (isIamAuthApplicable) {
|
|
49
|
+
const signingInfoFromUrl = (0, utils_1.parseSigningInfo)(url);
|
|
50
|
+
const signingService = signingServiceInfo?.service ?? signingInfoFromUrl.service;
|
|
51
|
+
const signingRegion = signingServiceInfo?.region ?? signingInfoFromUrl.region;
|
|
52
|
+
const credentials = await (0, utils_1.resolveCredentials)(amplify);
|
|
53
|
+
response = await (0, aws_client_utils_1.authenticatedHandler)(request, {
|
|
54
|
+
...baseOptions,
|
|
55
|
+
credentials,
|
|
56
|
+
region: signingRegion,
|
|
57
|
+
service: signingService,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
response = await (0, aws_client_utils_1.unauthenticatedHandler)(request, {
|
|
62
|
+
...baseOptions,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
// Clean-up un-modeled properties from response.
|
|
66
|
+
return {
|
|
67
|
+
statusCode: response.statusCode,
|
|
68
|
+
headers: response.headers,
|
|
69
|
+
body: response.body,
|
|
70
|
+
};
|
|
79
71
|
};
|
|
72
|
+
exports.transferHandler = transferHandler;
|
|
73
|
+
const iamAuthApplicable = ({ headers }, signingServiceInfo) => !headers.authorization && !headers['x-api-key'] && !!signingServiceInfo;
|
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.updateRequestToBeCancellable = exports.cancel = exports.post = void 0;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var utils_1 = require("../../utils");
|
|
6
|
+
const handler_1 = require("./handler");
|
|
7
|
+
const utils_1 = require("../../utils");
|
|
9
8
|
/**
|
|
10
9
|
* This weak map provides functionality to cancel a request given the promise containing the `post` request.
|
|
11
10
|
*
|
|
@@ -17,21 +16,22 @@ var utils_1 = require("../../utils");
|
|
|
17
16
|
* 6. GraphQL POST request will be rejected with the error message provided during cancel.
|
|
18
17
|
* 7. Caller can check if the error is because of cancelling by calling `isCancelError(error)`.
|
|
19
18
|
*/
|
|
20
|
-
|
|
19
|
+
const cancelTokenMap = new WeakMap();
|
|
21
20
|
/**
|
|
22
21
|
* @internal
|
|
23
22
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
|
|
23
|
+
const post = (amplify, { url, options, abortController }) => {
|
|
24
|
+
const controller = abortController ?? new AbortController();
|
|
25
|
+
const responsePromise = (0, utils_1.createCancellableOperation)(async () => {
|
|
26
|
+
const response = (0, handler_1.transferHandler)(amplify, {
|
|
27
|
+
url,
|
|
28
|
+
method: 'POST',
|
|
29
|
+
...options,
|
|
30
|
+
abortSignal: controller.signal,
|
|
31
|
+
}, options?.signingServiceInfo);
|
|
32
|
+
return response;
|
|
33
|
+
}, controller);
|
|
34
|
+
const responseWithCleanUp = responsePromise.finally(() => {
|
|
35
35
|
cancelTokenMap.delete(responseWithCleanUp);
|
|
36
36
|
});
|
|
37
37
|
return responseWithCleanUp;
|
|
@@ -42,8 +42,8 @@ exports.post = post;
|
|
|
42
42
|
* If the request is already completed, this function does nothing.
|
|
43
43
|
* It MUST be used after `updateRequestToBeCancellable` is called.
|
|
44
44
|
*/
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
const cancel = (promise, message) => {
|
|
46
|
+
const controller = cancelTokenMap.get(promise);
|
|
47
47
|
if (controller) {
|
|
48
48
|
controller.abort(message);
|
|
49
49
|
if (message && controller.signal.reason !== message) {
|
|
@@ -59,7 +59,7 @@ exports.cancel = cancel;
|
|
|
59
59
|
/**
|
|
60
60
|
* MUST be used to make a promise including internal `post` API call cancellable.
|
|
61
61
|
*/
|
|
62
|
-
|
|
62
|
+
const updateRequestToBeCancellable = (promise, controller) => {
|
|
63
63
|
cancelTokenMap.set(promise, controller);
|
|
64
64
|
};
|
|
65
65
|
exports.updateRequestToBeCancellable = updateRequestToBeCancellable;
|
|
@@ -3,48 +3,42 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.patch = exports.head = exports.del = exports.put = exports.post = exports.get = void 0;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
};
|
|
35
|
-
var get = function (amplify, input) {
|
|
36
|
-
return publicHandler(amplify, input, 'GET');
|
|
37
|
-
};
|
|
6
|
+
const utils_1 = require("../../utils");
|
|
7
|
+
const handler_1 = require("./handler");
|
|
8
|
+
const publicHandler = (amplify, options, method) => (0, utils_1.createCancellableOperation)(async (abortSignal) => {
|
|
9
|
+
const { apiName, options: apiOptions = {}, path: apiPath } = options;
|
|
10
|
+
const url = (0, utils_1.resolveApiUrl)(amplify, apiName, apiPath, apiOptions?.queryParams);
|
|
11
|
+
const libraryOptionsHeaders = await amplify.libraryOptions?.API?.REST?.headers?.({
|
|
12
|
+
apiName,
|
|
13
|
+
});
|
|
14
|
+
const { headers: invocationHeaders = {} } = apiOptions;
|
|
15
|
+
const headers = {
|
|
16
|
+
// custom headers from invocation options should precede library options
|
|
17
|
+
...libraryOptionsHeaders,
|
|
18
|
+
...invocationHeaders,
|
|
19
|
+
};
|
|
20
|
+
const signingServiceInfo = (0, utils_1.parseSigningInfo)(url, {
|
|
21
|
+
amplify,
|
|
22
|
+
apiName,
|
|
23
|
+
});
|
|
24
|
+
utils_1.logger.debug(method, url, headers, `IAM signing options: ${JSON.stringify(signingServiceInfo)}`);
|
|
25
|
+
return (0, handler_1.transferHandler)(amplify, {
|
|
26
|
+
...apiOptions,
|
|
27
|
+
url,
|
|
28
|
+
method,
|
|
29
|
+
headers,
|
|
30
|
+
abortSignal,
|
|
31
|
+
}, signingServiceInfo);
|
|
32
|
+
});
|
|
33
|
+
const get = (amplify, input) => publicHandler(amplify, input, 'GET');
|
|
38
34
|
exports.get = get;
|
|
39
|
-
|
|
35
|
+
const post = (amplify, input) => publicHandler(amplify, input, 'POST');
|
|
40
36
|
exports.post = post;
|
|
41
|
-
|
|
42
|
-
return publicHandler(amplify, input, 'PUT');
|
|
43
|
-
};
|
|
37
|
+
const put = (amplify, input) => publicHandler(amplify, input, 'PUT');
|
|
44
38
|
exports.put = put;
|
|
45
|
-
|
|
39
|
+
const del = (amplify, input) => publicHandler(amplify, input, 'DELETE');
|
|
46
40
|
exports.del = del;
|
|
47
|
-
|
|
41
|
+
const head = (amplify, input) => publicHandler(amplify, input, 'HEAD');
|
|
48
42
|
exports.head = head;
|
|
49
|
-
|
|
43
|
+
const patch = (amplify, input) => publicHandler(amplify, input, 'PATCH');
|
|
50
44
|
exports.patch = patch;
|
package/lib/apis/index.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.patch = exports.head = exports.del = exports.put = exports.post = exports.get = void 0;
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const core_1 = require("@aws-amplify/core");
|
|
7
|
+
const publicApis_1 = require("./common/publicApis");
|
|
8
8
|
/**
|
|
9
9
|
* GET HTTP request
|
|
10
10
|
* @param {GetInput} input - Input for GET operation
|
|
@@ -44,7 +44,7 @@ var publicApis_1 = require("./common/publicApis");
|
|
|
44
44
|
* }
|
|
45
45
|
* ```
|
|
46
46
|
*/
|
|
47
|
-
|
|
47
|
+
const get = (input) => (0, publicApis_1.get)(core_1.Amplify, input);
|
|
48
48
|
exports.get = get;
|
|
49
49
|
/**
|
|
50
50
|
* POST HTTP request
|
|
@@ -85,9 +85,7 @@ exports.get = get;
|
|
|
85
85
|
* }
|
|
86
86
|
* ```
|
|
87
87
|
*/
|
|
88
|
-
|
|
89
|
-
return (0, publicApis_1.post)(core_1.Amplify, input);
|
|
90
|
-
};
|
|
88
|
+
const post = (input) => (0, publicApis_1.post)(core_1.Amplify, input);
|
|
91
89
|
exports.post = post;
|
|
92
90
|
/**
|
|
93
91
|
* PUT HTTP request
|
|
@@ -127,7 +125,7 @@ exports.post = post;
|
|
|
127
125
|
* }
|
|
128
126
|
* ```
|
|
129
127
|
*/
|
|
130
|
-
|
|
128
|
+
const put = (input) => (0, publicApis_1.put)(core_1.Amplify, input);
|
|
131
129
|
exports.put = put;
|
|
132
130
|
/**
|
|
133
131
|
* DELETE HTTP request
|
|
@@ -149,9 +147,7 @@ exports.put = put;
|
|
|
149
147
|
* }).response;
|
|
150
148
|
* ```
|
|
151
149
|
*/
|
|
152
|
-
|
|
153
|
-
return (0, publicApis_1.del)(core_1.Amplify, input);
|
|
154
|
-
};
|
|
150
|
+
const del = (input) => (0, publicApis_1.del)(core_1.Amplify, input);
|
|
155
151
|
exports.del = del;
|
|
156
152
|
/**
|
|
157
153
|
* HEAD HTTP request
|
|
@@ -174,9 +170,7 @@ exports.del = del;
|
|
|
174
170
|
* ```
|
|
175
171
|
*
|
|
176
172
|
*/
|
|
177
|
-
|
|
178
|
-
return (0, publicApis_1.head)(core_1.Amplify, input);
|
|
179
|
-
};
|
|
173
|
+
const head = (input) => (0, publicApis_1.head)(core_1.Amplify, input);
|
|
180
174
|
exports.head = head;
|
|
181
175
|
/**
|
|
182
176
|
* PATCH HTTP request
|
|
@@ -217,7 +211,5 @@ exports.head = head;
|
|
|
217
211
|
* }
|
|
218
212
|
* ```
|
|
219
213
|
*/
|
|
220
|
-
|
|
221
|
-
return (0, publicApis_1.patch)(core_1.Amplify, input);
|
|
222
|
-
};
|
|
214
|
+
const patch = (input) => (0, publicApis_1.patch)(core_1.Amplify, input);
|
|
223
215
|
exports.patch = patch;
|
package/lib/apis/server.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.patch = exports.head = exports.del = exports.put = exports.post = exports.get = void 0;
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const adapter_core_1 = require("@aws-amplify/core/internals/adapter-core");
|
|
7
|
+
const publicApis_1 = require("./common/publicApis");
|
|
8
8
|
/**
|
|
9
9
|
* GET HTTP request (server-side)
|
|
10
10
|
* @param {AmplifyServer.ContextSpec} contextSpec - The context spec used to get the Amplify server context.
|
|
@@ -30,9 +30,7 @@ var publicApis_1 = require("./common/publicApis");
|
|
|
30
30
|
* ```
|
|
31
31
|
* @see {@link clientGet}
|
|
32
32
|
*/
|
|
33
|
-
|
|
34
|
-
return (0, publicApis_1.get)((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify, input);
|
|
35
|
-
};
|
|
33
|
+
const get = (contextSpec, input) => (0, publicApis_1.get)((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify, input);
|
|
36
34
|
exports.get = get;
|
|
37
35
|
/**
|
|
38
36
|
* POST HTTP request (server-side)
|
|
@@ -58,9 +56,7 @@ exports.get = get;
|
|
|
58
56
|
* });
|
|
59
57
|
* ```
|
|
60
58
|
*/
|
|
61
|
-
|
|
62
|
-
return (0, publicApis_1.post)((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify, input);
|
|
63
|
-
};
|
|
59
|
+
const post = (contextSpec, input) => (0, publicApis_1.post)((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify, input);
|
|
64
60
|
exports.post = post;
|
|
65
61
|
/**
|
|
66
62
|
* PUT HTTP request (server-side)
|
|
@@ -86,9 +82,7 @@ exports.post = post;
|
|
|
86
82
|
* });
|
|
87
83
|
* ```
|
|
88
84
|
*/
|
|
89
|
-
|
|
90
|
-
return (0, publicApis_1.put)((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify, input);
|
|
91
|
-
};
|
|
85
|
+
const put = (contextSpec, input) => (0, publicApis_1.put)((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify, input);
|
|
92
86
|
exports.put = put;
|
|
93
87
|
/**
|
|
94
88
|
* DELETE HTTP request (server-side)
|
|
@@ -113,9 +107,7 @@ exports.put = put;
|
|
|
113
107
|
* });
|
|
114
108
|
* ```
|
|
115
109
|
*/
|
|
116
|
-
|
|
117
|
-
return (0, publicApis_1.del)((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify, input);
|
|
118
|
-
};
|
|
110
|
+
const del = (contextSpec, input) => (0, publicApis_1.del)((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify, input);
|
|
119
111
|
exports.del = del;
|
|
120
112
|
/**
|
|
121
113
|
* HEAD HTTP request (server-side)
|
|
@@ -140,9 +132,7 @@ exports.del = del;
|
|
|
140
132
|
* });
|
|
141
133
|
* ```
|
|
142
134
|
*/
|
|
143
|
-
|
|
144
|
-
return (0, publicApis_1.head)((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify, input);
|
|
145
|
-
};
|
|
135
|
+
const head = (contextSpec, input) => (0, publicApis_1.head)((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify, input);
|
|
146
136
|
exports.head = head;
|
|
147
137
|
/**
|
|
148
138
|
* PATCH HTTP request (server-side)
|
|
@@ -168,7 +158,5 @@ exports.head = head;
|
|
|
168
158
|
* });
|
|
169
159
|
* ```
|
|
170
160
|
*/
|
|
171
|
-
|
|
172
|
-
return (0, publicApis_1.patch)((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify, input);
|
|
173
|
-
};
|
|
161
|
+
const patch = (contextSpec, input) => (0, publicApis_1.patch)((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify, input);
|
|
174
162
|
exports.patch = patch;
|
|
@@ -3,25 +3,24 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.isCancelError = exports.CanceledError = void 0;
|
|
6
|
-
|
|
7
|
-
var RestApiError_1 = require("./RestApiError");
|
|
6
|
+
const RestApiError_1 = require("./RestApiError");
|
|
8
7
|
/**
|
|
9
8
|
* Internal-only class for CanceledError.
|
|
10
9
|
*
|
|
11
10
|
* @internal
|
|
12
11
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
class CanceledError extends RestApiError_1.RestApiError {
|
|
13
|
+
constructor(params = {}) {
|
|
14
|
+
super({
|
|
15
|
+
name: 'CanceledError',
|
|
16
|
+
message: 'Request is canceled by user',
|
|
17
|
+
...params,
|
|
18
|
+
});
|
|
18
19
|
// TODO: Delete the following 2 lines after we change the build target to >= es2015
|
|
19
|
-
|
|
20
|
-
Object.setPrototypeOf(
|
|
21
|
-
return _this;
|
|
20
|
+
this.constructor = CanceledError;
|
|
21
|
+
Object.setPrototypeOf(this, CanceledError.prototype);
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
}(RestApiError_1.RestApiError));
|
|
23
|
+
}
|
|
25
24
|
exports.CanceledError = CanceledError;
|
|
26
25
|
/**
|
|
27
26
|
* Check if an error is caused by user calling `cancel()` in REST API.
|
|
@@ -29,7 +28,5 @@ exports.CanceledError = CanceledError;
|
|
|
29
28
|
* @note This function works **ONLY** for errors thrown by REST API. For GraphQL APIs, use `client.isCancelError(error)`
|
|
30
29
|
* instead. `client` is generated from `generateClient()` API from `aws-amplify/api`.
|
|
31
30
|
*/
|
|
32
|
-
|
|
33
|
-
return !!error && error instanceof CanceledError;
|
|
34
|
-
};
|
|
31
|
+
const isCancelError = (error) => !!error && error instanceof CanceledError;
|
|
35
32
|
exports.isCancelError = isCancelError;
|
|
@@ -3,17 +3,13 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.RestApiError = void 0;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
function RestApiError(params) {
|
|
11
|
-
var _this = _super.call(this, params) || this;
|
|
6
|
+
const utils_1 = require("@aws-amplify/core/internals/utils");
|
|
7
|
+
class RestApiError extends utils_1.AmplifyError {
|
|
8
|
+
constructor(params) {
|
|
9
|
+
super(params);
|
|
12
10
|
// TODO: Delete the following 2 lines after we change the build target to >= es2015
|
|
13
|
-
|
|
14
|
-
Object.setPrototypeOf(
|
|
15
|
-
return _this;
|
|
11
|
+
this.constructor = RestApiError;
|
|
12
|
+
Object.setPrototypeOf(this, RestApiError.prototype);
|
|
16
13
|
}
|
|
17
|
-
|
|
18
|
-
}(utils_1.AmplifyError));
|
|
14
|
+
}
|
|
19
15
|
exports.RestApiError = RestApiError;
|
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.assertValidationError = void 0;
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const RestApiError_1 = require("./RestApiError");
|
|
7
|
+
const validation_1 = require("./validation");
|
|
8
8
|
/**
|
|
9
9
|
* @internal
|
|
10
10
|
*/
|
|
11
11
|
function assertValidationError(assertion, name) {
|
|
12
|
-
|
|
12
|
+
const { message, recoverySuggestion } = validation_1.validationErrorMap[name];
|
|
13
13
|
if (!assertion) {
|
|
14
|
-
throw new RestApiError_1.RestApiError({ name
|
|
14
|
+
throw new RestApiError_1.RestApiError({ name, message, recoverySuggestion });
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
exports.assertValidationError = assertValidationError;
|
package/lib/errors/validation.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
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 _a;
|
|
5
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
5
|
exports.validationErrorMap = exports.RestApiValidationErrorCode = void 0;
|
|
7
6
|
var RestApiValidationErrorCode;
|
|
@@ -9,12 +8,12 @@ var RestApiValidationErrorCode;
|
|
|
9
8
|
RestApiValidationErrorCode["NoCredentials"] = "NoCredentials";
|
|
10
9
|
RestApiValidationErrorCode["InvalidApiName"] = "InvalidApiName";
|
|
11
10
|
})(RestApiValidationErrorCode = exports.RestApiValidationErrorCode || (exports.RestApiValidationErrorCode = {}));
|
|
12
|
-
exports.validationErrorMap =
|
|
13
|
-
|
|
11
|
+
exports.validationErrorMap = {
|
|
12
|
+
[RestApiValidationErrorCode.NoCredentials]: {
|
|
14
13
|
message: 'Credentials should not be empty.',
|
|
15
14
|
},
|
|
16
|
-
|
|
15
|
+
[RestApiValidationErrorCode.InvalidApiName]: {
|
|
17
16
|
message: 'API name is invalid.',
|
|
18
17
|
recoverySuggestion: 'Check if the API name matches the one in your configuration or `aws-exports.js`',
|
|
19
18
|
},
|
|
20
|
-
|
|
19
|
+
};
|
package/lib/internals/index.js
CHANGED
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.updateRequestToBeCancellable = exports.cancel = exports.post = void 0;
|
|
4
4
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
5
5
|
// SPDX-License-Identifier: Apache-2.0
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const core_1 = require("@aws-amplify/core");
|
|
7
|
+
const internalPost_1 = require("../apis/common/internalPost");
|
|
8
8
|
/**
|
|
9
9
|
* Internal-only REST POST handler to send GraphQL request to given endpoint. By default, it will use IAM to authorize
|
|
10
10
|
* the request. In some auth modes, the IAM auth has to be disabled. Here's how to set up the request auth correctly:
|
|
@@ -21,7 +21,7 @@ var internalPost_1 = require("../apis/common/internalPost");
|
|
|
21
21
|
*
|
|
22
22
|
* @internal
|
|
23
23
|
*/
|
|
24
|
-
|
|
24
|
+
const post = (input) => {
|
|
25
25
|
return (0, internalPost_1.post)(core_1.Amplify, input);
|
|
26
26
|
};
|
|
27
27
|
exports.post = post;
|
package/lib/internals/server.js
CHANGED
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.updateRequestToBeCancellable = exports.cancel = exports.post = void 0;
|
|
4
4
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
5
5
|
// SPDX-License-Identifier: Apache-2.0
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const adapter_core_1 = require("@aws-amplify/core/internals/adapter-core");
|
|
7
|
+
const internalPost_1 = require("../apis/common/internalPost");
|
|
8
8
|
/**
|
|
9
9
|
* Internal-only REST POST handler to send GraphQL request to given endpoint. By default, it will use IAM to authorize
|
|
10
10
|
* the request. In some auth modes, the IAM auth has to be disabled. Here's how to set up the request auth correctly:
|
|
@@ -21,7 +21,7 @@ var internalPost_1 = require("../apis/common/internalPost");
|
|
|
21
21
|
*
|
|
22
22
|
* @internal
|
|
23
23
|
*/
|
|
24
|
-
|
|
24
|
+
const post = (contextSpec, input) => {
|
|
25
25
|
return (0, internalPost_1.post)((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify, input);
|
|
26
26
|
};
|
|
27
27
|
exports.post = post;
|