@aws-amplify/api-rest 3.5.6-unstable.7762f1a.0 → 4.0.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/README.md +3 -0
- package/internals/package.json +8 -0
- package/internals/server/package.json +8 -0
- package/lib/apis/common/handler.d.ts +27 -0
- package/lib/apis/common/handler.js +73 -0
- package/lib/apis/common/internalPost.d.ts +16 -0
- package/lib/apis/common/internalPost.js +65 -0
- package/lib/apis/common/publicApis.d.ts +8 -0
- package/lib/apis/common/publicApis.js +44 -0
- package/lib/apis/index.d.ts +203 -0
- package/lib/apis/index.js +215 -0
- package/lib/apis/server.d.ts +151 -0
- package/lib/apis/server.js +162 -0
- package/lib/errors/CanceledError.d.ts +17 -0
- package/lib/errors/CanceledError.js +32 -0
- package/lib/errors/RestApiError.d.ts +4 -0
- package/lib/errors/RestApiError.js +15 -0
- package/lib/errors/assertValidatonError.d.ts +5 -0
- package/lib/errors/assertValidatonError.js +17 -0
- package/lib/errors/index.d.ts +4 -0
- package/lib/errors/index.js +15 -0
- package/lib/errors/validation.d.ts +6 -0
- package/lib/errors/validation.js +19 -0
- package/lib/index.d.ts +2 -2
- package/lib/index.js +10 -6
- package/lib/internals/index.d.ts +19 -0
- package/lib/internals/index.js +30 -0
- package/lib/internals/server.d.ts +20 -0
- package/lib/internals/server.js +30 -0
- package/lib/server.d.ts +2 -0
- package/lib/server.js +14 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/types/index.d.ts +90 -37
- package/lib/types/index.js +0 -23
- package/lib/utils/constants.d.ts +8 -0
- package/lib/utils/constants.js +13 -0
- package/lib/utils/createCancellableOperation.d.ts +12 -0
- package/lib/utils/createCancellableOperation.js +63 -0
- package/lib/utils/index.d.ts +6 -0
- package/lib/utils/index.js +17 -0
- package/lib/utils/logger.d.ts +2 -0
- package/lib/utils/logger.js +7 -0
- package/lib/utils/normalizeHeaders.d.ts +1 -0
- package/lib/utils/normalizeHeaders.js +13 -0
- package/lib/utils/parseSigningInfo.d.ts +14 -0
- package/lib/utils/parseSigningInfo.js +41 -0
- package/lib/utils/resolveApiUrl.d.ts +12 -0
- package/lib/utils/resolveApiUrl.js +40 -0
- package/lib/utils/resolveCredentials.d.ts +5 -0
- package/lib/utils/resolveCredentials.js +15 -0
- package/lib/utils/serviceError.d.ts +10 -0
- package/lib/utils/serviceError.js +30 -0
- package/lib-esm/apis/common/handler.d.ts +27 -0
- package/lib-esm/apis/common/handler.js +69 -0
- package/lib-esm/apis/common/internalPost.d.ts +16 -0
- package/lib-esm/apis/common/internalPost.js +59 -0
- package/lib-esm/apis/common/publicApis.d.ts +8 -0
- package/lib-esm/apis/common/publicApis.js +35 -0
- package/lib-esm/apis/index.d.ts +203 -0
- package/lib-esm/apis/index.js +206 -0
- package/lib-esm/apis/server.d.ts +151 -0
- package/lib-esm/apis/server.js +153 -0
- package/lib-esm/errors/CanceledError.d.ts +17 -0
- package/lib-esm/errors/CanceledError.js +27 -0
- package/lib-esm/errors/RestApiError.d.ts +4 -0
- package/lib-esm/errors/RestApiError.js +11 -0
- package/lib-esm/errors/assertValidatonError.d.ts +5 -0
- package/lib-esm/errors/assertValidatonError.js +13 -0
- package/lib-esm/errors/index.d.ts +4 -0
- package/lib-esm/errors/index.js +6 -0
- package/lib-esm/errors/validation.d.ts +6 -0
- package/lib-esm/errors/validation.js +16 -0
- package/lib-esm/index.d.ts +2 -2
- package/lib-esm/index.js +2 -3
- package/lib-esm/internals/index.d.ts +19 -0
- package/lib-esm/internals/index.js +24 -0
- package/lib-esm/internals/server.d.ts +20 -0
- package/lib-esm/internals/server.js +24 -0
- package/lib-esm/server.d.ts +2 -0
- package/lib-esm/server.js +4 -0
- package/lib-esm/tsconfig.tsbuildinfo +1 -0
- package/lib-esm/types/index.d.ts +90 -37
- package/lib-esm/types/index.js +1 -23
- package/lib-esm/utils/constants.d.ts +8 -0
- package/lib-esm/utils/constants.js +10 -0
- package/lib-esm/utils/createCancellableOperation.d.ts +12 -0
- package/lib-esm/utils/createCancellableOperation.js +59 -0
- package/lib-esm/utils/index.d.ts +6 -0
- package/lib-esm/utils/index.js +8 -0
- package/lib-esm/utils/logger.d.ts +2 -0
- package/lib-esm/utils/logger.js +4 -0
- package/lib-esm/utils/normalizeHeaders.d.ts +1 -0
- package/lib-esm/utils/normalizeHeaders.js +9 -0
- package/lib-esm/utils/parseSigningInfo.d.ts +14 -0
- package/lib-esm/utils/parseSigningInfo.js +37 -0
- package/lib-esm/utils/resolveApiUrl.d.ts +12 -0
- package/lib-esm/utils/resolveApiUrl.js +36 -0
- package/lib-esm/utils/resolveCredentials.d.ts +5 -0
- package/lib-esm/utils/resolveCredentials.js +11 -0
- package/lib-esm/utils/serviceError.d.ts +10 -0
- package/lib-esm/utils/serviceError.js +25 -0
- package/package.json +113 -105
- package/server/package.json +8 -0
- package/src/apis/common/handler.ts +109 -0
- package/src/apis/common/internalPost.ts +81 -0
- package/src/apis/common/publicApis.ts +99 -0
- package/src/apis/index.ts +239 -0
- package/src/apis/server.ts +209 -0
- package/src/errors/CanceledError.ts +33 -0
- package/src/errors/RestApiError.ts +17 -0
- package/src/errors/assertValidatonError.ts +19 -0
- package/src/errors/index.ts +7 -0
- package/src/errors/validation.ts +20 -0
- package/src/index.ts +2 -2
- package/src/internals/index.ts +31 -0
- package/src/internals/server.ts +37 -0
- package/src/server.ts +5 -0
- package/src/types/index.ts +95 -44
- package/src/utils/constants.ts +15 -0
- package/src/utils/createCancellableOperation.ts +94 -0
- package/src/utils/index.ts +9 -0
- package/src/utils/logger.ts +6 -0
- package/src/utils/normalizeHeaders.ts +10 -0
- package/src/utils/parseSigningInfo.ts +52 -0
- package/src/utils/resolveApiUrl.ts +51 -0
- package/src/utils/resolveCredentials.ts +17 -0
- package/src/utils/serviceError.ts +35 -0
- package/lib/.tsbuildinfo +0 -3
- package/lib/RestAPI.d.ts +0 -108
- package/lib/RestAPI.js +0 -282
- package/lib/RestAPI.js.map +0 -1
- package/lib/RestClient.d.ts +0 -138
- package/lib/RestClient.js +0 -368
- package/lib/RestClient.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/types/index.js.map +0 -1
- package/lib-esm/.tsbuildinfo +0 -3
- package/lib-esm/RestAPI.d.ts +0 -108
- package/lib-esm/RestAPI.js +0 -280
- package/lib-esm/RestAPI.js.map +0 -1
- package/lib-esm/RestClient.d.ts +0 -138
- package/lib-esm/RestClient.js +0 -366
- package/lib-esm/RestClient.js.map +0 -1
- package/lib-esm/index.js.map +0 -1
- package/lib-esm/types/index.js.map +0 -1
- package/src/RestAPI.ts +0 -338
- package/src/RestClient.ts +0 -417
package/README.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aws-amplify/api-rest/internals/server",
|
|
3
|
+
"types": "../../lib-esm/internals/server.d.ts",
|
|
4
|
+
"main": "../../lib/internals/server.js",
|
|
5
|
+
"module": "../../lib-esm/internals/server.js",
|
|
6
|
+
"react-native": "../../lib-esm/internals/server.js",
|
|
7
|
+
"sideEffects": false
|
|
8
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AmplifyClassV6 } from '@aws-amplify/core';
|
|
2
|
+
import { HttpRequest, Headers } from '@aws-amplify/core/internals/aws-client-utils';
|
|
3
|
+
import { DocumentType } from '@aws-amplify/core/internals/utils';
|
|
4
|
+
import { RestApiResponse } from '../../types';
|
|
5
|
+
type HandlerOptions = Omit<HttpRequest, 'body' | 'headers'> & {
|
|
6
|
+
body?: DocumentType | FormData;
|
|
7
|
+
headers?: Headers;
|
|
8
|
+
withCredentials?: boolean;
|
|
9
|
+
};
|
|
10
|
+
type SigningServiceInfo = {
|
|
11
|
+
service?: string;
|
|
12
|
+
region?: string;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Make REST API call with best-effort IAM auth.
|
|
16
|
+
* @param amplify Amplify instance to to resolve credentials and tokens. Should use different instance in client-side
|
|
17
|
+
* and SSR
|
|
18
|
+
* @param options Options accepted from public API options when calling the handlers.
|
|
19
|
+
* @param signingServiceInfo Internal-only options enable IAM auth as well as to to overwrite the IAM signing service
|
|
20
|
+
* and region. If specified, and NONE of API Key header or Auth header is present, IAM auth will be used.
|
|
21
|
+
*
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export declare const transferHandler: (amplify: AmplifyClassV6, options: HandlerOptions & {
|
|
25
|
+
abortSignal: AbortSignal;
|
|
26
|
+
}, signingServiceInfo?: SigningServiceInfo) => Promise<RestApiResponse>;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transferHandler = void 0;
|
|
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");
|
|
7
|
+
/**
|
|
8
|
+
* Make REST API call with best-effort IAM auth.
|
|
9
|
+
* @param amplify Amplify instance to to resolve credentials and tokens. Should use different instance in client-side
|
|
10
|
+
* and SSR
|
|
11
|
+
* @param options Options accepted from public API options when calling the handlers.
|
|
12
|
+
* @param signingServiceInfo Internal-only options enable IAM auth as well as to to overwrite the IAM signing service
|
|
13
|
+
* and region. If specified, and NONE of API Key header or Auth header is present, IAM auth will be used.
|
|
14
|
+
*
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
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
|
+
};
|
|
71
|
+
};
|
|
72
|
+
exports.transferHandler = transferHandler;
|
|
73
|
+
const iamAuthApplicable = ({ headers }, signingServiceInfo) => !headers.authorization && !headers['x-api-key'] && !!signingServiceInfo;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AmplifyClassV6 } from '@aws-amplify/core';
|
|
2
|
+
import { InternalPostInput, RestApiResponse } from '../../types';
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export declare const post: (amplify: AmplifyClassV6, { url, options, abortController }: InternalPostInput) => Promise<RestApiResponse>;
|
|
7
|
+
/**
|
|
8
|
+
* Cancels a request given the promise returned by `post`.
|
|
9
|
+
* If the request is already completed, this function does nothing.
|
|
10
|
+
* It MUST be used after `updateRequestToBeCancellable` is called.
|
|
11
|
+
*/
|
|
12
|
+
export declare const cancel: (promise: Promise<RestApiResponse>, message?: string) => boolean;
|
|
13
|
+
/**
|
|
14
|
+
* MUST be used to make a promise including internal `post` API call cancellable.
|
|
15
|
+
*/
|
|
16
|
+
export declare const updateRequestToBeCancellable: (promise: Promise<any>, controller: AbortController) => void;
|
|
@@ -0,0 +1,65 @@
|
|
|
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.updateRequestToBeCancellable = exports.cancel = exports.post = void 0;
|
|
6
|
+
const handler_1 = require("./handler");
|
|
7
|
+
const utils_1 = require("../../utils");
|
|
8
|
+
/**
|
|
9
|
+
* This weak map provides functionality to cancel a request given the promise containing the `post` request.
|
|
10
|
+
*
|
|
11
|
+
* 1. For every GraphQL POST request, an abort controller is created and supplied to the request.
|
|
12
|
+
* 2. The promise fulfilled by GraphGL POST request is then mapped to that abort controller.
|
|
13
|
+
* 3. The promise is returned to the external caller.
|
|
14
|
+
* 4. The caller can either wait for the promise to fulfill or call `cancel(promise)` to cancel the request.
|
|
15
|
+
* 5. If `cancel(promise)` is called, then the corresponding abort controller is retrieved from the map below.
|
|
16
|
+
* 6. GraphQL POST request will be rejected with the error message provided during cancel.
|
|
17
|
+
* 7. Caller can check if the error is because of cancelling by calling `isCancelError(error)`.
|
|
18
|
+
*/
|
|
19
|
+
const cancelTokenMap = new WeakMap();
|
|
20
|
+
/**
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
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
|
+
cancelTokenMap.delete(responseWithCleanUp);
|
|
36
|
+
});
|
|
37
|
+
return responseWithCleanUp;
|
|
38
|
+
};
|
|
39
|
+
exports.post = post;
|
|
40
|
+
/**
|
|
41
|
+
* Cancels a request given the promise returned by `post`.
|
|
42
|
+
* If the request is already completed, this function does nothing.
|
|
43
|
+
* It MUST be used after `updateRequestToBeCancellable` is called.
|
|
44
|
+
*/
|
|
45
|
+
const cancel = (promise, message) => {
|
|
46
|
+
const controller = cancelTokenMap.get(promise);
|
|
47
|
+
if (controller) {
|
|
48
|
+
controller.abort(message);
|
|
49
|
+
if (message && controller.signal.reason !== message) {
|
|
50
|
+
// In runtimes where `AbortSignal.reason` is not supported, we track the reason ourselves.
|
|
51
|
+
// @ts-expect-error reason is read-only property.
|
|
52
|
+
controller.signal['reason'] = message;
|
|
53
|
+
}
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
return false;
|
|
57
|
+
};
|
|
58
|
+
exports.cancel = cancel;
|
|
59
|
+
/**
|
|
60
|
+
* MUST be used to make a promise including internal `post` API call cancellable.
|
|
61
|
+
*/
|
|
62
|
+
const updateRequestToBeCancellable = (promise, controller) => {
|
|
63
|
+
cancelTokenMap.set(promise, controller);
|
|
64
|
+
};
|
|
65
|
+
exports.updateRequestToBeCancellable = updateRequestToBeCancellable;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AmplifyClassV6 } from '@aws-amplify/core';
|
|
2
|
+
import { GetInput, GetOperation, PostInput, PostOperation, PutInput, PutOperation, DeleteInput, DeleteOperation, HeadInput, HeadOperation, PatchInput, PatchOperation } from '../../types';
|
|
3
|
+
export declare const get: (amplify: AmplifyClassV6, input: GetInput) => GetOperation;
|
|
4
|
+
export declare const post: (amplify: AmplifyClassV6, input: PostInput) => PostOperation;
|
|
5
|
+
export declare const put: (amplify: AmplifyClassV6, input: PutInput) => PutOperation;
|
|
6
|
+
export declare const del: (amplify: AmplifyClassV6, input: DeleteInput) => DeleteOperation;
|
|
7
|
+
export declare const head: (amplify: AmplifyClassV6, input: HeadInput) => HeadOperation;
|
|
8
|
+
export declare const patch: (amplify: AmplifyClassV6, input: PatchInput) => PatchOperation;
|
|
@@ -0,0 +1,44 @@
|
|
|
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.patch = exports.head = exports.del = exports.put = exports.post = exports.get = void 0;
|
|
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');
|
|
34
|
+
exports.get = get;
|
|
35
|
+
const post = (amplify, input) => publicHandler(amplify, input, 'POST');
|
|
36
|
+
exports.post = post;
|
|
37
|
+
const put = (amplify, input) => publicHandler(amplify, input, 'PUT');
|
|
38
|
+
exports.put = put;
|
|
39
|
+
const del = (amplify, input) => publicHandler(amplify, input, 'DELETE');
|
|
40
|
+
exports.del = del;
|
|
41
|
+
const head = (amplify, input) => publicHandler(amplify, input, 'HEAD');
|
|
42
|
+
exports.head = head;
|
|
43
|
+
const patch = (amplify, input) => publicHandler(amplify, input, 'PATCH');
|
|
44
|
+
exports.patch = patch;
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { DeleteInput, DeleteOperation, GetInput, GetOperation, HeadInput, HeadOperation, PatchInput, PatchOperation, PostInput, PostOperation, PutInput, PutOperation } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* GET HTTP request
|
|
4
|
+
* @param {GetInput} input - Input for GET operation
|
|
5
|
+
* @returns {GetOperation} Operation for GET request
|
|
6
|
+
* @throws - {@link RestApiError}
|
|
7
|
+
* @example
|
|
8
|
+
* Send a GET request
|
|
9
|
+
* ```js
|
|
10
|
+
* import { get, isCancelError } from '@aws-amplify/api';
|
|
11
|
+
*
|
|
12
|
+
* const { body } = await get({
|
|
13
|
+
* apiName,
|
|
14
|
+
* path,
|
|
15
|
+
* options: {
|
|
16
|
+
* headers, // Optional, A map of custom header key/values
|
|
17
|
+
* body, // Optional, JSON object or FormData
|
|
18
|
+
* queryParams, // Optional, A map of query strings
|
|
19
|
+
* }
|
|
20
|
+
* }).response;
|
|
21
|
+
* const data = await body.json();
|
|
22
|
+
* ```
|
|
23
|
+
* @example
|
|
24
|
+
* Cancel a GET request
|
|
25
|
+
*
|
|
26
|
+
* ```js
|
|
27
|
+
* import { get, isCancelError } from '@aws-amplify/api';
|
|
28
|
+
*
|
|
29
|
+
* const { response, cancel } = get({apiName, path, options});
|
|
30
|
+
* cancel(message);
|
|
31
|
+
* try {
|
|
32
|
+
* await response;
|
|
33
|
+
* } cache (e) {
|
|
34
|
+
* if (isCancelError(e)) {
|
|
35
|
+
* // handle request cancellation
|
|
36
|
+
* }
|
|
37
|
+
* //...
|
|
38
|
+
* }
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare const get: (input: GetInput) => GetOperation;
|
|
42
|
+
/**
|
|
43
|
+
* POST HTTP request
|
|
44
|
+
* @param {PostInput} input - Input for POST operation
|
|
45
|
+
* @returns {PostOperation} Operation for POST request
|
|
46
|
+
* @throws - {@link RestApiError}
|
|
47
|
+
* @example
|
|
48
|
+
* Send a POST request
|
|
49
|
+
* ```js
|
|
50
|
+
* import { post, isCancelError } from '@aws-amplify/api';
|
|
51
|
+
*
|
|
52
|
+
* const { body } = await post({
|
|
53
|
+
* apiName,
|
|
54
|
+
* path,
|
|
55
|
+
* options: {
|
|
56
|
+
* headers, // Optional, A map of custom header key/values
|
|
57
|
+
* body, // Optional, JSON object or FormData
|
|
58
|
+
* queryParams, // Optional, A map of query strings
|
|
59
|
+
* }
|
|
60
|
+
* }).response;
|
|
61
|
+
* const data = await body.json();
|
|
62
|
+
* ```
|
|
63
|
+
* @example
|
|
64
|
+
* Cancel a POST request
|
|
65
|
+
*
|
|
66
|
+
* ```js
|
|
67
|
+
* import { post, isCancelError } from '@aws-amplify/api';
|
|
68
|
+
*
|
|
69
|
+
* const { response, cancel } = post({apiName, path, options});
|
|
70
|
+
* cancel(message);
|
|
71
|
+
* try {
|
|
72
|
+
* await response;
|
|
73
|
+
* } cache (e) {
|
|
74
|
+
* if (isCancelError(e)) {
|
|
75
|
+
* // handle request cancellation
|
|
76
|
+
* }
|
|
77
|
+
* //...
|
|
78
|
+
* }
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export declare const post: (input: PostInput) => PostOperation;
|
|
82
|
+
/**
|
|
83
|
+
* PUT HTTP request
|
|
84
|
+
* @param {PutInput} input - Input for PUT operation
|
|
85
|
+
* @returns {PutOperation} Operation for PUT request
|
|
86
|
+
* @throws - {@link RestApiError}
|
|
87
|
+
* @example
|
|
88
|
+
* Send a PUT request
|
|
89
|
+
* ```js
|
|
90
|
+
* import { put, isCancelError } from '@aws-amplify/api';
|
|
91
|
+
*
|
|
92
|
+
* const { body } = await put({
|
|
93
|
+
* apiName,
|
|
94
|
+
* path,
|
|
95
|
+
* options: {
|
|
96
|
+
* headers, // Optional, A map of custom header key/values
|
|
97
|
+
* body, // Optional, JSON object or FormData
|
|
98
|
+
* queryParams, // Optional, A map of query strings
|
|
99
|
+
* }
|
|
100
|
+
* }).response;
|
|
101
|
+
* const data = await body.json();
|
|
102
|
+
* ```
|
|
103
|
+
* @example
|
|
104
|
+
* Cancel a PUT request
|
|
105
|
+
* ```js
|
|
106
|
+
* import { put, isCancelError } from '@aws-amplify/api';
|
|
107
|
+
*
|
|
108
|
+
* const { response, cancel } = put({apiName, path, options});
|
|
109
|
+
* cancel(message);
|
|
110
|
+
* try {
|
|
111
|
+
* await response;
|
|
112
|
+
* } cache (e) {
|
|
113
|
+
* if (isCancelError(e)) {
|
|
114
|
+
* // handle request cancellation
|
|
115
|
+
* }
|
|
116
|
+
* //...
|
|
117
|
+
* }
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
export declare const put: (input: PutInput) => PutOperation;
|
|
121
|
+
/**
|
|
122
|
+
* DELETE HTTP request
|
|
123
|
+
* @param {DeleteInput} input - Input for DELETE operation
|
|
124
|
+
* @returns {DeleteOperation} Operation for DELETE request
|
|
125
|
+
* @throws - {@link RestApiError}
|
|
126
|
+
* @example
|
|
127
|
+
* Send a DELETE request
|
|
128
|
+
* ```js
|
|
129
|
+
* import { del } from '@aws-amplify/api';
|
|
130
|
+
*
|
|
131
|
+
* const { statusCode } = await del({
|
|
132
|
+
* apiName,
|
|
133
|
+
* path,
|
|
134
|
+
* options: {
|
|
135
|
+
* headers, // Optional, A map of custom header key/values
|
|
136
|
+
* queryParams, // Optional, A map of query strings
|
|
137
|
+
* }
|
|
138
|
+
* }).response;
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
export declare const del: (input: DeleteInput) => DeleteOperation;
|
|
142
|
+
/**
|
|
143
|
+
* HEAD HTTP request
|
|
144
|
+
* @param {HeadInput} input - Input for HEAD operation
|
|
145
|
+
* @returns {HeadOperation} Operation for HEAD request
|
|
146
|
+
* @throws - {@link RestApiError}
|
|
147
|
+
* @example
|
|
148
|
+
* Send a HEAD request
|
|
149
|
+
* ```js
|
|
150
|
+
* import { head, isCancelError } from '@aws-amplify/api';
|
|
151
|
+
*
|
|
152
|
+
* const { headers, statusCode } = await head({
|
|
153
|
+
* apiName,
|
|
154
|
+
* path,
|
|
155
|
+
* options: {
|
|
156
|
+
* headers, // Optional, A map of custom header key/values
|
|
157
|
+
* queryParams, // Optional, A map of query strings
|
|
158
|
+
* }
|
|
159
|
+
* }),response;
|
|
160
|
+
* ```
|
|
161
|
+
*
|
|
162
|
+
*/
|
|
163
|
+
export declare const head: (input: HeadInput) => HeadOperation;
|
|
164
|
+
/**
|
|
165
|
+
* PATCH HTTP request
|
|
166
|
+
* @param {PatchInput} input - Input for PATCH operation
|
|
167
|
+
* @returns {PatchOperation} Operation for PATCH request
|
|
168
|
+
* @throws - {@link RestApiError}
|
|
169
|
+
* @example
|
|
170
|
+
* Send a PATCH request
|
|
171
|
+
* ```js
|
|
172
|
+
* import { patch } from '@aws-amplify/api';
|
|
173
|
+
*
|
|
174
|
+
* const { body } = await patch({
|
|
175
|
+
* apiName,
|
|
176
|
+
* path,
|
|
177
|
+
* options: {
|
|
178
|
+
* headers, // Optional, A map of custom header key/values
|
|
179
|
+
* body, // Optional, JSON object or FormData
|
|
180
|
+
* queryParams, // Optional, A map of query strings
|
|
181
|
+
* }
|
|
182
|
+
* }).response;
|
|
183
|
+
* const data = await body.json();
|
|
184
|
+
* ```
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* Cancel a PATCH request
|
|
188
|
+
* ```js
|
|
189
|
+
* import { patch, isCancelError } from '@aws-amplify/api';
|
|
190
|
+
*
|
|
191
|
+
* const { response, cancel } = patch({apiName, path, options});
|
|
192
|
+
* cancel(message);
|
|
193
|
+
* try {
|
|
194
|
+
* await response;
|
|
195
|
+
* } cache (e) {
|
|
196
|
+
* if (isCancelError(e)) {
|
|
197
|
+
* // handle request cancellation
|
|
198
|
+
* }
|
|
199
|
+
* //...
|
|
200
|
+
* }
|
|
201
|
+
* ```
|
|
202
|
+
*/
|
|
203
|
+
export declare const patch: (input: PatchInput) => PatchOperation;
|
|
@@ -0,0 +1,215 @@
|
|
|
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.patch = exports.head = exports.del = exports.put = exports.post = exports.get = void 0;
|
|
6
|
+
const core_1 = require("@aws-amplify/core");
|
|
7
|
+
const publicApis_1 = require("./common/publicApis");
|
|
8
|
+
/**
|
|
9
|
+
* GET HTTP request
|
|
10
|
+
* @param {GetInput} input - Input for GET operation
|
|
11
|
+
* @returns {GetOperation} Operation for GET request
|
|
12
|
+
* @throws - {@link RestApiError}
|
|
13
|
+
* @example
|
|
14
|
+
* Send a GET request
|
|
15
|
+
* ```js
|
|
16
|
+
* import { get, isCancelError } from '@aws-amplify/api';
|
|
17
|
+
*
|
|
18
|
+
* const { body } = await get({
|
|
19
|
+
* apiName,
|
|
20
|
+
* path,
|
|
21
|
+
* options: {
|
|
22
|
+
* headers, // Optional, A map of custom header key/values
|
|
23
|
+
* body, // Optional, JSON object or FormData
|
|
24
|
+
* queryParams, // Optional, A map of query strings
|
|
25
|
+
* }
|
|
26
|
+
* }).response;
|
|
27
|
+
* const data = await body.json();
|
|
28
|
+
* ```
|
|
29
|
+
* @example
|
|
30
|
+
* Cancel a GET request
|
|
31
|
+
*
|
|
32
|
+
* ```js
|
|
33
|
+
* import { get, isCancelError } from '@aws-amplify/api';
|
|
34
|
+
*
|
|
35
|
+
* const { response, cancel } = get({apiName, path, options});
|
|
36
|
+
* cancel(message);
|
|
37
|
+
* try {
|
|
38
|
+
* await response;
|
|
39
|
+
* } cache (e) {
|
|
40
|
+
* if (isCancelError(e)) {
|
|
41
|
+
* // handle request cancellation
|
|
42
|
+
* }
|
|
43
|
+
* //...
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
const get = (input) => (0, publicApis_1.get)(core_1.Amplify, input);
|
|
48
|
+
exports.get = get;
|
|
49
|
+
/**
|
|
50
|
+
* POST HTTP request
|
|
51
|
+
* @param {PostInput} input - Input for POST operation
|
|
52
|
+
* @returns {PostOperation} Operation for POST request
|
|
53
|
+
* @throws - {@link RestApiError}
|
|
54
|
+
* @example
|
|
55
|
+
* Send a POST request
|
|
56
|
+
* ```js
|
|
57
|
+
* import { post, isCancelError } from '@aws-amplify/api';
|
|
58
|
+
*
|
|
59
|
+
* const { body } = await post({
|
|
60
|
+
* apiName,
|
|
61
|
+
* path,
|
|
62
|
+
* options: {
|
|
63
|
+
* headers, // Optional, A map of custom header key/values
|
|
64
|
+
* body, // Optional, JSON object or FormData
|
|
65
|
+
* queryParams, // Optional, A map of query strings
|
|
66
|
+
* }
|
|
67
|
+
* }).response;
|
|
68
|
+
* const data = await body.json();
|
|
69
|
+
* ```
|
|
70
|
+
* @example
|
|
71
|
+
* Cancel a POST request
|
|
72
|
+
*
|
|
73
|
+
* ```js
|
|
74
|
+
* import { post, isCancelError } from '@aws-amplify/api';
|
|
75
|
+
*
|
|
76
|
+
* const { response, cancel } = post({apiName, path, options});
|
|
77
|
+
* cancel(message);
|
|
78
|
+
* try {
|
|
79
|
+
* await response;
|
|
80
|
+
* } cache (e) {
|
|
81
|
+
* if (isCancelError(e)) {
|
|
82
|
+
* // handle request cancellation
|
|
83
|
+
* }
|
|
84
|
+
* //...
|
|
85
|
+
* }
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
const post = (input) => (0, publicApis_1.post)(core_1.Amplify, input);
|
|
89
|
+
exports.post = post;
|
|
90
|
+
/**
|
|
91
|
+
* PUT HTTP request
|
|
92
|
+
* @param {PutInput} input - Input for PUT operation
|
|
93
|
+
* @returns {PutOperation} Operation for PUT request
|
|
94
|
+
* @throws - {@link RestApiError}
|
|
95
|
+
* @example
|
|
96
|
+
* Send a PUT request
|
|
97
|
+
* ```js
|
|
98
|
+
* import { put, isCancelError } from '@aws-amplify/api';
|
|
99
|
+
*
|
|
100
|
+
* const { body } = await put({
|
|
101
|
+
* apiName,
|
|
102
|
+
* path,
|
|
103
|
+
* options: {
|
|
104
|
+
* headers, // Optional, A map of custom header key/values
|
|
105
|
+
* body, // Optional, JSON object or FormData
|
|
106
|
+
* queryParams, // Optional, A map of query strings
|
|
107
|
+
* }
|
|
108
|
+
* }).response;
|
|
109
|
+
* const data = await body.json();
|
|
110
|
+
* ```
|
|
111
|
+
* @example
|
|
112
|
+
* Cancel a PUT request
|
|
113
|
+
* ```js
|
|
114
|
+
* import { put, isCancelError } from '@aws-amplify/api';
|
|
115
|
+
*
|
|
116
|
+
* const { response, cancel } = put({apiName, path, options});
|
|
117
|
+
* cancel(message);
|
|
118
|
+
* try {
|
|
119
|
+
* await response;
|
|
120
|
+
* } cache (e) {
|
|
121
|
+
* if (isCancelError(e)) {
|
|
122
|
+
* // handle request cancellation
|
|
123
|
+
* }
|
|
124
|
+
* //...
|
|
125
|
+
* }
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
const put = (input) => (0, publicApis_1.put)(core_1.Amplify, input);
|
|
129
|
+
exports.put = put;
|
|
130
|
+
/**
|
|
131
|
+
* DELETE HTTP request
|
|
132
|
+
* @param {DeleteInput} input - Input for DELETE operation
|
|
133
|
+
* @returns {DeleteOperation} Operation for DELETE request
|
|
134
|
+
* @throws - {@link RestApiError}
|
|
135
|
+
* @example
|
|
136
|
+
* Send a DELETE request
|
|
137
|
+
* ```js
|
|
138
|
+
* import { del } from '@aws-amplify/api';
|
|
139
|
+
*
|
|
140
|
+
* const { statusCode } = await del({
|
|
141
|
+
* apiName,
|
|
142
|
+
* path,
|
|
143
|
+
* options: {
|
|
144
|
+
* headers, // Optional, A map of custom header key/values
|
|
145
|
+
* queryParams, // Optional, A map of query strings
|
|
146
|
+
* }
|
|
147
|
+
* }).response;
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
const del = (input) => (0, publicApis_1.del)(core_1.Amplify, input);
|
|
151
|
+
exports.del = del;
|
|
152
|
+
/**
|
|
153
|
+
* HEAD HTTP request
|
|
154
|
+
* @param {HeadInput} input - Input for HEAD operation
|
|
155
|
+
* @returns {HeadOperation} Operation for HEAD request
|
|
156
|
+
* @throws - {@link RestApiError}
|
|
157
|
+
* @example
|
|
158
|
+
* Send a HEAD request
|
|
159
|
+
* ```js
|
|
160
|
+
* import { head, isCancelError } from '@aws-amplify/api';
|
|
161
|
+
*
|
|
162
|
+
* const { headers, statusCode } = await head({
|
|
163
|
+
* apiName,
|
|
164
|
+
* path,
|
|
165
|
+
* options: {
|
|
166
|
+
* headers, // Optional, A map of custom header key/values
|
|
167
|
+
* queryParams, // Optional, A map of query strings
|
|
168
|
+
* }
|
|
169
|
+
* }),response;
|
|
170
|
+
* ```
|
|
171
|
+
*
|
|
172
|
+
*/
|
|
173
|
+
const head = (input) => (0, publicApis_1.head)(core_1.Amplify, input);
|
|
174
|
+
exports.head = head;
|
|
175
|
+
/**
|
|
176
|
+
* PATCH HTTP request
|
|
177
|
+
* @param {PatchInput} input - Input for PATCH operation
|
|
178
|
+
* @returns {PatchOperation} Operation for PATCH request
|
|
179
|
+
* @throws - {@link RestApiError}
|
|
180
|
+
* @example
|
|
181
|
+
* Send a PATCH request
|
|
182
|
+
* ```js
|
|
183
|
+
* import { patch } from '@aws-amplify/api';
|
|
184
|
+
*
|
|
185
|
+
* const { body } = await patch({
|
|
186
|
+
* apiName,
|
|
187
|
+
* path,
|
|
188
|
+
* options: {
|
|
189
|
+
* headers, // Optional, A map of custom header key/values
|
|
190
|
+
* body, // Optional, JSON object or FormData
|
|
191
|
+
* queryParams, // Optional, A map of query strings
|
|
192
|
+
* }
|
|
193
|
+
* }).response;
|
|
194
|
+
* const data = await body.json();
|
|
195
|
+
* ```
|
|
196
|
+
*
|
|
197
|
+
* @example
|
|
198
|
+
* Cancel a PATCH request
|
|
199
|
+
* ```js
|
|
200
|
+
* import { patch, isCancelError } from '@aws-amplify/api';
|
|
201
|
+
*
|
|
202
|
+
* const { response, cancel } = patch({apiName, path, options});
|
|
203
|
+
* cancel(message);
|
|
204
|
+
* try {
|
|
205
|
+
* await response;
|
|
206
|
+
* } cache (e) {
|
|
207
|
+
* if (isCancelError(e)) {
|
|
208
|
+
* // handle request cancellation
|
|
209
|
+
* }
|
|
210
|
+
* //...
|
|
211
|
+
* }
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
214
|
+
const patch = (input) => (0, publicApis_1.patch)(core_1.Amplify, input);
|
|
215
|
+
exports.patch = patch;
|