@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.
- package/README.md +3 -0
- package/dist/cjs/apis/common/baseHandlers/authenticatedHandler.js +17 -0
- package/dist/cjs/apis/common/baseHandlers/authenticatedHandler.js.map +1 -0
- package/dist/cjs/apis/common/baseHandlers/unauthenticatedHandler.js +13 -0
- package/dist/cjs/apis/common/baseHandlers/unauthenticatedHandler.js.map +1 -0
- package/dist/cjs/apis/common/internalPost.js +98 -0
- package/dist/cjs/apis/common/internalPost.js.map +1 -0
- package/dist/cjs/apis/common/publicApis.js +57 -0
- package/dist/cjs/apis/common/publicApis.js.map +1 -0
- package/dist/cjs/apis/common/transferHandler.js +92 -0
- package/dist/cjs/apis/common/transferHandler.js.map +1 -0
- package/dist/cjs/apis/index.js +217 -0
- package/dist/cjs/apis/index.js.map +1 -0
- package/dist/cjs/apis/server.js +163 -0
- package/dist/cjs/apis/server.js.map +1 -0
- package/dist/cjs/errors/CanceledError.js +37 -0
- package/dist/cjs/errors/CanceledError.js.map +1 -0
- package/dist/cjs/errors/RestApiError.js +17 -0
- package/dist/cjs/errors/RestApiError.js.map +1 -0
- package/dist/cjs/errors/assertValidatonError.js +18 -0
- package/dist/cjs/errors/assertValidatonError.js.map +1 -0
- package/dist/cjs/errors/index.js +17 -0
- package/dist/cjs/errors/index.js.map +1 -0
- package/dist/cjs/errors/validation.js +17 -0
- package/dist/cjs/errors/validation.js.map +1 -0
- package/dist/cjs/index.js +16 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/internals/index.js +12 -0
- package/dist/cjs/internals/index.js.map +1 -0
- package/dist/cjs/internals/server.js +32 -0
- package/dist/cjs/internals/server.js.map +1 -0
- package/dist/cjs/server.js +16 -0
- package/dist/cjs/server.js.map +1 -0
- package/dist/cjs/types/index.js +4 -0
- package/dist/cjs/types/index.js.map +1 -0
- package/dist/cjs/utils/constants.js +15 -0
- package/dist/cjs/utils/constants.js.map +1 -0
- package/dist/cjs/utils/createCancellableOperation.js +76 -0
- package/dist/cjs/utils/createCancellableOperation.js.map +1 -0
- package/dist/cjs/utils/index.js +19 -0
- package/dist/cjs/utils/index.js.map +1 -0
- package/dist/cjs/utils/isIamAuthApplicable.js +39 -0
- package/dist/cjs/utils/isIamAuthApplicable.js.map +1 -0
- package/dist/cjs/utils/logger.js +9 -0
- package/dist/cjs/utils/logger.js.map +1 -0
- package/dist/cjs/utils/parseSigningInfo.js +43 -0
- package/dist/cjs/utils/parseSigningInfo.js.map +1 -0
- package/dist/cjs/utils/resolveApiUrl.js +48 -0
- package/dist/cjs/utils/resolveApiUrl.js.map +1 -0
- package/dist/cjs/utils/resolveHeaders.js +34 -0
- package/dist/cjs/utils/resolveHeaders.js.map +1 -0
- package/dist/cjs/utils/resolveLibraryOptions.js +16 -0
- package/dist/cjs/utils/resolveLibraryOptions.js.map +1 -0
- package/dist/cjs/utils/serviceError.js +98 -0
- package/dist/cjs/utils/serviceError.js.map +1 -0
- package/dist/esm/apis/common/baseHandlers/authenticatedHandler.d.ts +5 -0
- package/dist/esm/apis/common/baseHandlers/authenticatedHandler.mjs +16 -0
- package/dist/esm/apis/common/baseHandlers/authenticatedHandler.mjs.map +1 -0
- package/dist/esm/apis/common/baseHandlers/unauthenticatedHandler.d.ts +5 -0
- package/dist/esm/apis/common/baseHandlers/unauthenticatedHandler.mjs +12 -0
- package/dist/esm/apis/common/baseHandlers/unauthenticatedHandler.mjs.map +1 -0
- package/dist/esm/apis/common/internalPost.d.ts +43 -0
- package/dist/esm/apis/common/internalPost.mjs +98 -0
- package/dist/esm/apis/common/internalPost.mjs.map +1 -0
- package/dist/esm/apis/common/publicApis.d.ts +8 -0
- package/dist/esm/apis/common/publicApis.mjs +56 -0
- package/dist/esm/apis/common/publicApis.mjs.map +1 -0
- package/dist/esm/apis/common/transferHandler.d.ts +26 -0
- package/dist/esm/apis/common/transferHandler.mjs +95 -0
- package/dist/esm/apis/common/transferHandler.mjs.map +1 -0
- package/dist/esm/apis/index.d.ts +203 -0
- package/dist/esm/apis/index.mjs +210 -0
- package/dist/esm/apis/index.mjs.map +1 -0
- package/dist/esm/apis/server.d.ts +150 -0
- package/dist/esm/apis/server.mjs +156 -0
- package/dist/esm/apis/server.mjs.map +1 -0
- package/dist/esm/errors/CanceledError.d.ts +20 -0
- package/dist/esm/errors/CanceledError.mjs +34 -0
- package/dist/esm/errors/CanceledError.mjs.map +1 -0
- package/dist/esm/errors/RestApiError.d.ts +4 -0
- package/dist/esm/errors/RestApiError.mjs +15 -0
- package/dist/esm/errors/RestApiError.mjs.map +1 -0
- package/dist/esm/errors/assertValidatonError.d.ts +5 -0
- package/dist/esm/errors/assertValidatonError.mjs +17 -0
- package/dist/esm/errors/assertValidatonError.mjs.map +1 -0
- package/dist/esm/errors/index.d.ts +4 -0
- package/dist/esm/errors/index.mjs +5 -0
- package/dist/esm/errors/index.mjs.map +1 -0
- package/dist/esm/errors/validation.d.ts +5 -0
- package/dist/esm/errors/validation.mjs +15 -0
- package/dist/esm/errors/validation.mjs.map +1 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.mjs +3 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/internals/index.d.ts +2 -0
- package/dist/esm/internals/index.mjs +2 -0
- package/dist/esm/internals/index.mjs.map +1 -0
- package/dist/esm/internals/server.d.ts +20 -0
- package/dist/esm/internals/server.mjs +28 -0
- package/dist/esm/internals/server.mjs.map +1 -0
- package/dist/esm/server.d.ts +2 -0
- package/dist/esm/server.mjs +3 -0
- package/dist/esm/server.mjs.map +1 -0
- package/dist/esm/types/index.d.ts +122 -0
- package/dist/esm/types/index.mjs +2 -0
- package/dist/esm/types/index.mjs.map +1 -0
- package/dist/esm/utils/constants.d.ts +8 -0
- package/dist/esm/utils/constants.mjs +13 -0
- package/dist/esm/utils/constants.mjs.map +1 -0
- package/dist/esm/utils/createCancellableOperation.d.ts +12 -0
- package/dist/esm/utils/createCancellableOperation.mjs +77 -0
- package/dist/esm/utils/createCancellableOperation.mjs.map +1 -0
- package/dist/esm/utils/index.d.ts +6 -0
- package/dist/esm/utils/index.mjs +7 -0
- package/dist/esm/utils/index.mjs.map +1 -0
- package/dist/esm/utils/isIamAuthApplicable.d.ts +32 -0
- package/dist/esm/utils/isIamAuthApplicable.mjs +35 -0
- package/dist/esm/utils/isIamAuthApplicable.mjs.map +1 -0
- package/dist/esm/utils/logger.d.ts +2 -0
- package/dist/esm/utils/logger.mjs +8 -0
- package/dist/esm/utils/logger.mjs.map +1 -0
- package/dist/esm/utils/parseSigningInfo.d.ts +14 -0
- package/dist/esm/utils/parseSigningInfo.mjs +41 -0
- package/dist/esm/utils/parseSigningInfo.mjs.map +1 -0
- package/dist/esm/utils/resolveApiUrl.d.ts +12 -0
- package/dist/esm/utils/resolveApiUrl.mjs +48 -0
- package/dist/esm/utils/resolveApiUrl.mjs.map +1 -0
- package/dist/esm/utils/resolveHeaders.d.ts +1 -0
- package/dist/esm/utils/resolveHeaders.mjs +31 -0
- package/dist/esm/utils/resolveHeaders.mjs.map +1 -0
- package/dist/esm/utils/resolveLibraryOptions.d.ts +8 -0
- package/dist/esm/utils/resolveLibraryOptions.mjs +13 -0
- package/dist/esm/utils/resolveLibraryOptions.mjs.map +1 -0
- package/dist/esm/utils/serviceError.d.ts +13 -0
- package/dist/esm/utils/serviceError.mjs +97 -0
- package/dist/esm/utils/serviceError.mjs.map +1 -0
- package/internals/package.json +8 -0
- package/internals/server/package.json +7 -0
- package/package.json +94 -0
- package/server/package.json +7 -0
- package/src/apis/common/baseHandlers/authenticatedHandler.ts +28 -0
- package/src/apis/common/baseHandlers/unauthenticatedHandler.ts +22 -0
- package/src/apis/common/internalPost.ts +123 -0
- package/src/apis/common/publicApis.ts +118 -0
- package/src/apis/common/transferHandler.ts +154 -0
- package/src/apis/index.ts +241 -0
- package/src/apis/server.ts +210 -0
- package/src/errors/CanceledError.ts +37 -0
- package/src/errors/RestApiError.ts +14 -0
- package/src/errors/assertValidatonError.ts +19 -0
- package/src/errors/index.ts +7 -0
- package/src/errors/validation.ts +16 -0
- package/src/index.ts +5 -0
- package/src/internals/index.ts +8 -0
- package/src/internals/server.ts +37 -0
- package/src/server.ts +5 -0
- package/src/types/index.ts +138 -0
- package/src/utils/constants.ts +15 -0
- package/src/utils/createCancellableOperation.ts +108 -0
- package/src/utils/index.ts +9 -0
- package/src/utils/isIamAuthApplicable.ts +44 -0
- package/src/utils/logger.ts +6 -0
- package/src/utils/parseSigningInfo.ts +53 -0
- package/src/utils/resolveApiUrl.ts +59 -0
- package/src/utils/resolveHeaders.ts +36 -0
- package/src/utils/resolveLibraryOptions.ts +14 -0
- package/src/utils/serviceError.ts +109 -0
package/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.authenticatedHandler = void 0;
|
|
5
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
6
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
7
|
+
const aws_client_utils_1 = require("@aws-amplify/core/internals/aws-client-utils");
|
|
8
|
+
const composers_1 = require("@aws-amplify/core/internals/aws-client-utils/composers");
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
exports.authenticatedHandler = (0, composers_1.composeTransferHandler)(aws_client_utils_1.fetchTransferHandler, [
|
|
13
|
+
aws_client_utils_1.userAgentMiddlewareFactory,
|
|
14
|
+
aws_client_utils_1.retryMiddlewareFactory,
|
|
15
|
+
aws_client_utils_1.signingMiddlewareFactory,
|
|
16
|
+
]);
|
|
17
|
+
//# sourceMappingURL=authenticatedHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authenticatedHandler.js","sources":["../../../../../src/apis/common/baseHandlers/authenticatedHandler.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.authenticatedHandler = void 0;\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nconst aws_client_utils_1 = require(\"@aws-amplify/core/internals/aws-client-utils\");\nconst composers_1 = require(\"@aws-amplify/core/internals/aws-client-utils/composers\");\n/**\n * @internal\n */\nexports.authenticatedHandler = (0, composers_1.composeTransferHandler)(aws_client_utils_1.fetchTransferHandler, [\n aws_client_utils_1.userAgentMiddlewareFactory,\n aws_client_utils_1.retryMiddlewareFactory,\n aws_client_utils_1.signingMiddlewareFactory,\n]);\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,oBAAoB,GAAG,MAAM;AACrC;AACA;AACA,MAAM,kBAAkB,GAAG,OAAO,CAAC,8CAA8C,CAAC;AAClF,MAAM,WAAW,GAAG,OAAO,CAAC,wDAAwD,CAAC;AACrF;AACA;AACA;AACA,OAAO,CAAC,oBAAoB,GAAG,IAAI,WAAW,CAAC,sBAAsB,EAAE,kBAAkB,CAAC,oBAAoB,EAAE;AAChH,IAAI,kBAAkB,CAAC,0BAA0B;AACjD,IAAI,kBAAkB,CAAC,sBAAsB;AAC7C,IAAI,kBAAkB,CAAC,wBAAwB;AAC/C,CAAC,CAAC;;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.unauthenticatedHandler = void 0;
|
|
5
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
6
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
7
|
+
const aws_client_utils_1 = require("@aws-amplify/core/internals/aws-client-utils");
|
|
8
|
+
const composers_1 = require("@aws-amplify/core/internals/aws-client-utils/composers");
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
exports.unauthenticatedHandler = (0, composers_1.composeTransferHandler)(aws_client_utils_1.fetchTransferHandler, [aws_client_utils_1.userAgentMiddlewareFactory, aws_client_utils_1.retryMiddlewareFactory]);
|
|
13
|
+
//# sourceMappingURL=unauthenticatedHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unauthenticatedHandler.js","sources":["../../../../../src/apis/common/baseHandlers/unauthenticatedHandler.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.unauthenticatedHandler = void 0;\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nconst aws_client_utils_1 = require(\"@aws-amplify/core/internals/aws-client-utils\");\nconst composers_1 = require(\"@aws-amplify/core/internals/aws-client-utils/composers\");\n/**\n * @internal\n */\nexports.unauthenticatedHandler = (0, composers_1.composeTransferHandler)(aws_client_utils_1.fetchTransferHandler, [aws_client_utils_1.userAgentMiddlewareFactory, aws_client_utils_1.retryMiddlewareFactory]);\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,sBAAsB,GAAG,MAAM;AACvC;AACA;AACA,MAAM,kBAAkB,GAAG,OAAO,CAAC,8CAA8C,CAAC;AAClF,MAAM,WAAW,GAAG,OAAO,CAAC,wDAAwD,CAAC;AACrF;AACA;AACA;AACA,OAAO,CAAC,sBAAsB,GAAG,IAAI,WAAW,CAAC,sBAAsB,EAAE,kBAAkB,CAAC,oBAAoB,EAAE,CAAC,kBAAkB,CAAC,0BAA0B,EAAE,kBAAkB,CAAC,sBAAsB,CAAC,CAAC;;"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.updateRequestToBeCancellable = exports.cancel = exports.post = void 0;
|
|
7
|
+
const utils_1 = require("../../utils");
|
|
8
|
+
const isIamAuthApplicable_1 = require("../../utils/isIamAuthApplicable");
|
|
9
|
+
const transferHandler_1 = require("./transferHandler");
|
|
10
|
+
/**
|
|
11
|
+
* This weak map provides functionality to cancel a request given the promise containing the `post` request.
|
|
12
|
+
*
|
|
13
|
+
* 1. For every GraphQL POST request, an abort controller is created and supplied to the request.
|
|
14
|
+
* 2. The promise fulfilled by GraphGL POST request is then mapped to that abort controller.
|
|
15
|
+
* 3. The promise is returned to the external caller.
|
|
16
|
+
* 4. The caller can either wait for the promise to fulfill or call `cancel(promise)` to cancel the request.
|
|
17
|
+
* 5. If `cancel(promise)` is called, then the corresponding abort controller is retrieved from the map below.
|
|
18
|
+
* 6. GraphQL POST request will be rejected with the error message provided during cancel.
|
|
19
|
+
* 7. Caller can check if the error is because of cancelling by calling `isCancelError(error)`.
|
|
20
|
+
*/
|
|
21
|
+
const cancelTokenMap = new WeakMap();
|
|
22
|
+
/**
|
|
23
|
+
* @internal
|
|
24
|
+
*
|
|
25
|
+
* REST POST handler to send GraphQL request to given endpoint. By default, it will use IAM to authorize
|
|
26
|
+
* the request. In some auth modes, the IAM auth has to be disabled. Here's how to set up the request auth correctly:
|
|
27
|
+
* * If auth mode is 'iam', you MUST NOT set 'authorization' header and 'x-api-key' header, since it would disable IAM
|
|
28
|
+
* auth. You MUST also set 'input.options.signingServiceInfo' option.
|
|
29
|
+
* * The including 'input.options.signingServiceInfo.service' and 'input.options.signingServiceInfo.region' are
|
|
30
|
+
* optional. If omitted, the signing service and region will be inferred from url.
|
|
31
|
+
* * If auth mode is 'none', you MUST NOT set 'options.signingServiceInfo' option.
|
|
32
|
+
* * If auth mode is 'apiKey', you MUST set 'x-api-key' custom header.
|
|
33
|
+
* * If auth mode is 'oidc' or 'lambda' or 'userPool', you MUST set 'authorization' header.
|
|
34
|
+
*
|
|
35
|
+
* To make the internal post cancellable, you must also call `updateRequestToBeCancellable()` with the promise from
|
|
36
|
+
* internal post call and the abort controller supplied to the internal post call.
|
|
37
|
+
*
|
|
38
|
+
* @param amplify the AmplifyClassV6 instance - it may be the singleton used on Web, or an instance created within
|
|
39
|
+
* a context created by `runWithAmplifyServerContext`
|
|
40
|
+
* @param postInput an object of {@link InternalPostInput}
|
|
41
|
+
* @param postInput.url The URL that the POST request sends to
|
|
42
|
+
* @param postInput.options Options of the POST request
|
|
43
|
+
* @param postInput.abortController The abort controller used to cancel the POST request
|
|
44
|
+
* @returns a {@link RestApiResponse}
|
|
45
|
+
*
|
|
46
|
+
* @throws an {@link AmplifyError} with `Network Error` as the `message` when the external resource is unreachable due to one
|
|
47
|
+
* of the following reasons:
|
|
48
|
+
* 1. no network connection
|
|
49
|
+
* 2. CORS error
|
|
50
|
+
* @throws a {@link CanceledError} when the ongoing POST request get cancelled
|
|
51
|
+
*/
|
|
52
|
+
const post = (amplify, { url, options, abortController }) => {
|
|
53
|
+
const controller = abortController ?? new AbortController();
|
|
54
|
+
const responsePromise = (0, utils_1.createCancellableOperation)(async () => {
|
|
55
|
+
const response = (0, transferHandler_1.transferHandler)(amplify, {
|
|
56
|
+
url,
|
|
57
|
+
method: 'POST',
|
|
58
|
+
...options,
|
|
59
|
+
abortSignal: controller.signal,
|
|
60
|
+
retryStrategy: {
|
|
61
|
+
strategy: 'jittered-exponential-backoff',
|
|
62
|
+
},
|
|
63
|
+
}, isIamAuthApplicable_1.isIamAuthApplicableForGraphQL, options?.signingServiceInfo);
|
|
64
|
+
return response;
|
|
65
|
+
}, controller, 'internal');
|
|
66
|
+
const responseWithCleanUp = responsePromise.finally(() => {
|
|
67
|
+
cancelTokenMap.delete(responseWithCleanUp);
|
|
68
|
+
});
|
|
69
|
+
return responseWithCleanUp;
|
|
70
|
+
};
|
|
71
|
+
exports.post = post;
|
|
72
|
+
/**
|
|
73
|
+
* Cancels a request given the promise returned by `post`.
|
|
74
|
+
* If the request is already completed, this function does nothing.
|
|
75
|
+
* It MUST be used after `updateRequestToBeCancellable` is called.
|
|
76
|
+
*/
|
|
77
|
+
const cancel = (promise, message) => {
|
|
78
|
+
const controller = cancelTokenMap.get(promise);
|
|
79
|
+
if (controller) {
|
|
80
|
+
controller.abort(message);
|
|
81
|
+
if (message && controller.signal.reason !== message) {
|
|
82
|
+
// In runtimes where `AbortSignal.reason` is not supported, we track the reason ourselves.
|
|
83
|
+
// @ts-expect-error reason is read-only property.
|
|
84
|
+
controller.signal.reason = message;
|
|
85
|
+
}
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
};
|
|
90
|
+
exports.cancel = cancel;
|
|
91
|
+
/**
|
|
92
|
+
* MUST be used to make a promise including internal `post` API call cancellable.
|
|
93
|
+
*/
|
|
94
|
+
const updateRequestToBeCancellable = (promise, controller) => {
|
|
95
|
+
cancelTokenMap.set(promise, controller);
|
|
96
|
+
};
|
|
97
|
+
exports.updateRequestToBeCancellable = updateRequestToBeCancellable;
|
|
98
|
+
//# sourceMappingURL=internalPost.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internalPost.js","sources":["../../../../src/apis/common/internalPost.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.updateRequestToBeCancellable = exports.cancel = exports.post = void 0;\nconst utils_1 = require(\"../../utils\");\nconst isIamAuthApplicable_1 = require(\"../../utils/isIamAuthApplicable\");\nconst transferHandler_1 = require(\"./transferHandler\");\n/**\n * This weak map provides functionality to cancel a request given the promise containing the `post` request.\n *\n * 1. For every GraphQL POST request, an abort controller is created and supplied to the request.\n * 2. The promise fulfilled by GraphGL POST request is then mapped to that abort controller.\n * 3. The promise is returned to the external caller.\n * 4. The caller can either wait for the promise to fulfill or call `cancel(promise)` to cancel the request.\n * 5. If `cancel(promise)` is called, then the corresponding abort controller is retrieved from the map below.\n * 6. GraphQL POST request will be rejected with the error message provided during cancel.\n * 7. Caller can check if the error is because of cancelling by calling `isCancelError(error)`.\n */\nconst cancelTokenMap = new WeakMap();\n/**\n * @internal\n *\n * REST POST handler to send GraphQL request to given endpoint. By default, it will use IAM to authorize\n * the request. In some auth modes, the IAM auth has to be disabled. Here's how to set up the request auth correctly:\n * * If auth mode is 'iam', you MUST NOT set 'authorization' header and 'x-api-key' header, since it would disable IAM\n * auth. You MUST also set 'input.options.signingServiceInfo' option.\n * * The including 'input.options.signingServiceInfo.service' and 'input.options.signingServiceInfo.region' are\n * optional. If omitted, the signing service and region will be inferred from url.\n * * If auth mode is 'none', you MUST NOT set 'options.signingServiceInfo' option.\n * * If auth mode is 'apiKey', you MUST set 'x-api-key' custom header.\n * * If auth mode is 'oidc' or 'lambda' or 'userPool', you MUST set 'authorization' header.\n *\n * To make the internal post cancellable, you must also call `updateRequestToBeCancellable()` with the promise from\n * internal post call and the abort controller supplied to the internal post call.\n *\n * @param amplify the AmplifyClassV6 instance - it may be the singleton used on Web, or an instance created within\n * a context created by `runWithAmplifyServerContext`\n * @param postInput an object of {@link InternalPostInput}\n * @param postInput.url The URL that the POST request sends to\n * @param postInput.options Options of the POST request\n * @param postInput.abortController The abort controller used to cancel the POST request\n * @returns a {@link RestApiResponse}\n *\n * @throws an {@link AmplifyError} with `Network Error` as the `message` when the external resource is unreachable due to one\n * of the following reasons:\n * 1. no network connection\n * 2. CORS error\n * @throws a {@link CanceledError} when the ongoing POST request get cancelled\n */\nconst post = (amplify, { url, options, abortController }) => {\n const controller = abortController ?? new AbortController();\n const responsePromise = (0, utils_1.createCancellableOperation)(async () => {\n const response = (0, transferHandler_1.transferHandler)(amplify, {\n url,\n method: 'POST',\n ...options,\n abortSignal: controller.signal,\n retryStrategy: {\n strategy: 'jittered-exponential-backoff',\n },\n }, isIamAuthApplicable_1.isIamAuthApplicableForGraphQL, options?.signingServiceInfo);\n return response;\n }, controller, 'internal');\n const responseWithCleanUp = responsePromise.finally(() => {\n cancelTokenMap.delete(responseWithCleanUp);\n });\n return responseWithCleanUp;\n};\nexports.post = post;\n/**\n * Cancels a request given the promise returned by `post`.\n * If the request is already completed, this function does nothing.\n * It MUST be used after `updateRequestToBeCancellable` is called.\n */\nconst cancel = (promise, message) => {\n const controller = cancelTokenMap.get(promise);\n if (controller) {\n controller.abort(message);\n if (message && controller.signal.reason !== message) {\n // In runtimes where `AbortSignal.reason` is not supported, we track the reason ourselves.\n // @ts-expect-error reason is read-only property.\n controller.signal.reason = message;\n }\n return true;\n }\n return false;\n};\nexports.cancel = cancel;\n/**\n * MUST be used to make a promise including internal `post` API call cancellable.\n */\nconst updateRequestToBeCancellable = (promise, controller) => {\n cancelTokenMap.set(promise, controller);\n};\nexports.updateRequestToBeCancellable = updateRequestToBeCancellable;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,4BAA4B,GAAG,OAAO,CAAC,MAAM,GAAG,OAAO,CAAC,IAAI,GAAG,MAAM;AAC7E,MAAM,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC;AACtC,MAAM,qBAAqB,GAAG,OAAO,CAAC,iCAAiC,CAAC;AACxE,MAAM,iBAAiB,GAAG,OAAO,CAAC,mBAAmB,CAAC;AACtD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,cAAc,GAAG,IAAI,OAAO,EAAE;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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,QAAQ;AACR,QAAQ,OAAO,IAAI;AACnB,IAAI;AACJ,IAAI,OAAO,KAAK;AAChB,CAAC;AACD,OAAO,CAAC,MAAM,GAAG,MAAM;AACvB;AACA;AACA;AACA,MAAM,4BAA4B,GAAG,CAAC,OAAO,EAAE,UAAU,KAAK;AAC9D,IAAI,cAAc,CAAC,GAAG,CAAC,OAAO,EAAE,UAAU,CAAC;AAC3C,CAAC;AACD,OAAO,CAAC,4BAA4B,GAAG,4BAA4B;;"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.patch = exports.head = exports.del = exports.put = exports.post = exports.get = void 0;
|
|
7
|
+
const utils_1 = require("../../utils");
|
|
8
|
+
const isIamAuthApplicable_1 = require("../../utils/isIamAuthApplicable");
|
|
9
|
+
const transferHandler_1 = require("./transferHandler");
|
|
10
|
+
const publicHandler = (amplify, options, method) => {
|
|
11
|
+
const { apiName, options: apiOptions = {}, path: apiPath } = options;
|
|
12
|
+
const libraryConfigTimeout = amplify.libraryOptions?.API?.REST?.timeout?.({
|
|
13
|
+
apiName,
|
|
14
|
+
method,
|
|
15
|
+
});
|
|
16
|
+
const timeout = apiOptions?.timeout || libraryConfigTimeout || undefined;
|
|
17
|
+
const publicApisAbortController = new AbortController();
|
|
18
|
+
const abortSignal = publicApisAbortController.signal;
|
|
19
|
+
return (0, utils_1.createCancellableOperation)(async () => {
|
|
20
|
+
const url = (0, utils_1.resolveApiUrl)(amplify, apiName, apiPath, apiOptions?.queryParams);
|
|
21
|
+
const libraryConfigHeaders = await amplify.libraryOptions?.API?.REST?.headers?.({
|
|
22
|
+
apiName,
|
|
23
|
+
});
|
|
24
|
+
const { headers: invocationHeaders = {} } = apiOptions;
|
|
25
|
+
const headers = {
|
|
26
|
+
// custom headers from invocation options should precede library options
|
|
27
|
+
...libraryConfigHeaders,
|
|
28
|
+
...invocationHeaders,
|
|
29
|
+
};
|
|
30
|
+
const signingServiceInfo = (0, utils_1.parseSigningInfo)(url, {
|
|
31
|
+
amplify,
|
|
32
|
+
apiName,
|
|
33
|
+
});
|
|
34
|
+
utils_1.logger.debug(method, url, headers, `IAM signing options: ${JSON.stringify(signingServiceInfo)}`);
|
|
35
|
+
return (0, transferHandler_1.transferHandler)(amplify, {
|
|
36
|
+
...apiOptions,
|
|
37
|
+
url,
|
|
38
|
+
method,
|
|
39
|
+
headers,
|
|
40
|
+
abortSignal,
|
|
41
|
+
}, isIamAuthApplicable_1.isIamAuthApplicableForRest, signingServiceInfo);
|
|
42
|
+
}, publicApisAbortController, 'public', // operation Type
|
|
43
|
+
timeout);
|
|
44
|
+
};
|
|
45
|
+
const get = (amplify, input) => publicHandler(amplify, input, 'GET');
|
|
46
|
+
exports.get = get;
|
|
47
|
+
const post = (amplify, input) => publicHandler(amplify, input, 'POST');
|
|
48
|
+
exports.post = post;
|
|
49
|
+
const put = (amplify, input) => publicHandler(amplify, input, 'PUT');
|
|
50
|
+
exports.put = put;
|
|
51
|
+
const del = (amplify, input) => publicHandler(amplify, input, 'DELETE');
|
|
52
|
+
exports.del = del;
|
|
53
|
+
const head = (amplify, input) => publicHandler(amplify, input, 'HEAD');
|
|
54
|
+
exports.head = head;
|
|
55
|
+
const patch = (amplify, input) => publicHandler(amplify, input, 'PATCH');
|
|
56
|
+
exports.patch = patch;
|
|
57
|
+
//# sourceMappingURL=publicApis.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publicApis.js","sources":["../../../../src/apis/common/publicApis.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.patch = exports.head = exports.del = exports.put = exports.post = exports.get = void 0;\nconst utils_1 = require(\"../../utils\");\nconst isIamAuthApplicable_1 = require(\"../../utils/isIamAuthApplicable\");\nconst transferHandler_1 = require(\"./transferHandler\");\nconst publicHandler = (amplify, options, method) => {\n const { apiName, options: apiOptions = {}, path: apiPath } = options;\n const libraryConfigTimeout = amplify.libraryOptions?.API?.REST?.timeout?.({\n apiName,\n method,\n });\n const timeout = apiOptions?.timeout || libraryConfigTimeout || undefined;\n const publicApisAbortController = new AbortController();\n const abortSignal = publicApisAbortController.signal;\n return (0, utils_1.createCancellableOperation)(async () => {\n const url = (0, utils_1.resolveApiUrl)(amplify, apiName, apiPath, apiOptions?.queryParams);\n const libraryConfigHeaders = await amplify.libraryOptions?.API?.REST?.headers?.({\n apiName,\n });\n const { headers: invocationHeaders = {} } = apiOptions;\n const headers = {\n // custom headers from invocation options should precede library options\n ...libraryConfigHeaders,\n ...invocationHeaders,\n };\n const signingServiceInfo = (0, utils_1.parseSigningInfo)(url, {\n amplify,\n apiName,\n });\n utils_1.logger.debug(method, url, headers, `IAM signing options: ${JSON.stringify(signingServiceInfo)}`);\n return (0, transferHandler_1.transferHandler)(amplify, {\n ...apiOptions,\n url,\n method,\n headers,\n abortSignal,\n }, isIamAuthApplicable_1.isIamAuthApplicableForRest, signingServiceInfo);\n }, publicApisAbortController, 'public', // operation Type\n timeout);\n};\nconst get = (amplify, input) => publicHandler(amplify, input, 'GET');\nexports.get = get;\nconst post = (amplify, input) => publicHandler(amplify, input, 'POST');\nexports.post = post;\nconst put = (amplify, input) => publicHandler(amplify, input, 'PUT');\nexports.put = put;\nconst del = (amplify, input) => publicHandler(amplify, input, 'DELETE');\nexports.del = del;\nconst head = (amplify, input) => publicHandler(amplify, input, 'HEAD');\nexports.head = head;\nconst patch = (amplify, input) => publicHandler(amplify, input, 'PATCH');\nexports.patch = patch;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,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G,GAAG;AACjB,MAAM,IAAI,GAAG,CAAC,OAAO,EAAE,KAAK,KAAK,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC;AACtE,OAAO,CAAC,IAAI,GAAG,IAAI;AACnB,MAAM,KAAK,GAAG,CAAC,OAAO,EAAE,KAAK,KAAK,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO,CAAC;AACxE,OAAO,CAAC,KAAK,GAAG,KAAK;;"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.transferHandler = void 0;
|
|
5
|
+
const aws_client_utils_1 = require("@aws-amplify/core/internals/aws-client-utils");
|
|
6
|
+
const utils_1 = require("../../utils");
|
|
7
|
+
const resolveHeaders_1 = require("../../utils/resolveHeaders");
|
|
8
|
+
const authenticatedHandler_1 = require("./baseHandlers/authenticatedHandler");
|
|
9
|
+
const unauthenticatedHandler_1 = require("./baseHandlers/unauthenticatedHandler");
|
|
10
|
+
/**
|
|
11
|
+
* Make REST API call with best-effort IAM auth.
|
|
12
|
+
* @param amplify Amplify instance to to resolve credentials and tokens. Should use different instance in client-side
|
|
13
|
+
* and SSR
|
|
14
|
+
* @param options Options accepted from public API options when calling the handlers.
|
|
15
|
+
* @param signingServiceInfo Internal-only options enable IAM auth as well as to to overwrite the IAM signing service
|
|
16
|
+
* and region. If specified, and NONE of API Key header or Auth header is present, IAM auth will be used.
|
|
17
|
+
* @param iamAuthApplicable Callback function that is used to determine if IAM Auth should be used or not.
|
|
18
|
+
*
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
const transferHandler = async (amplify, options, iamAuthApplicable, signingServiceInfo) => {
|
|
22
|
+
const { url, method, headers, body, withCredentials, abortSignal, retryStrategy, } = options;
|
|
23
|
+
const resolvedBody = body
|
|
24
|
+
? body instanceof FormData
|
|
25
|
+
? body
|
|
26
|
+
: JSON.stringify(body ?? '')
|
|
27
|
+
: undefined;
|
|
28
|
+
const resolvedHeaders = (0, resolveHeaders_1.resolveHeaders)(headers, body);
|
|
29
|
+
const request = {
|
|
30
|
+
url,
|
|
31
|
+
headers: resolvedHeaders,
|
|
32
|
+
method,
|
|
33
|
+
body: resolvedBody,
|
|
34
|
+
};
|
|
35
|
+
const { retryStrategy: libraryRetryStrategy, defaultAuthMode: libraryDefaultAuthMode, } = (0, utils_1.resolveLibraryOptions)(amplify);
|
|
36
|
+
const baseOptions = {
|
|
37
|
+
retryDecider: getRetryDeciderFromStrategy(retryStrategy ?? libraryRetryStrategy),
|
|
38
|
+
computeDelay: aws_client_utils_1.jitteredBackoff,
|
|
39
|
+
withCrossDomainCredentials: withCredentials,
|
|
40
|
+
abortSignal,
|
|
41
|
+
};
|
|
42
|
+
const defaultAuthMode = options.defaultAuthMode ?? libraryDefaultAuthMode;
|
|
43
|
+
let credentials = null;
|
|
44
|
+
if (defaultAuthMode !== 'none') {
|
|
45
|
+
credentials = await resolveCredentials(amplify);
|
|
46
|
+
}
|
|
47
|
+
let response;
|
|
48
|
+
const isIamAuthApplicable = iamAuthApplicable(request, signingServiceInfo);
|
|
49
|
+
if (isIamAuthApplicable && credentials) {
|
|
50
|
+
const signingInfoFromUrl = (0, utils_1.parseSigningInfo)(url);
|
|
51
|
+
const signingService = signingServiceInfo?.service ?? signingInfoFromUrl.service;
|
|
52
|
+
const signingRegion = signingServiceInfo?.region ?? signingInfoFromUrl.region;
|
|
53
|
+
response = await (0, authenticatedHandler_1.authenticatedHandler)(request, {
|
|
54
|
+
...baseOptions,
|
|
55
|
+
credentials,
|
|
56
|
+
region: signingRegion,
|
|
57
|
+
service: signingService,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
response = await (0, unauthenticatedHandler_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 getRetryDeciderFromStrategy = (retryStrategy) => {
|
|
74
|
+
const strategy = retryStrategy?.strategy;
|
|
75
|
+
if (strategy === 'no-retry') {
|
|
76
|
+
return () => Promise.resolve({ retryable: false });
|
|
77
|
+
}
|
|
78
|
+
return (0, aws_client_utils_1.getRetryDecider)(utils_1.parseRestApiServiceError);
|
|
79
|
+
};
|
|
80
|
+
const resolveCredentials = async (amplify) => {
|
|
81
|
+
try {
|
|
82
|
+
const { credentials } = await amplify.Auth.fetchAuthSession();
|
|
83
|
+
if (credentials) {
|
|
84
|
+
return credentials;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
catch (e) {
|
|
88
|
+
utils_1.logger.debug('No credentials available, the request will be unsigned.');
|
|
89
|
+
}
|
|
90
|
+
return null;
|
|
91
|
+
};
|
|
92
|
+
//# sourceMappingURL=transferHandler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transferHandler.js","sources":["../../../../src/apis/common/transferHandler.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.transferHandler = void 0;\nconst aws_client_utils_1 = require(\"@aws-amplify/core/internals/aws-client-utils\");\nconst utils_1 = require(\"../../utils\");\nconst resolveHeaders_1 = require(\"../../utils/resolveHeaders\");\nconst authenticatedHandler_1 = require(\"./baseHandlers/authenticatedHandler\");\nconst unauthenticatedHandler_1 = require(\"./baseHandlers/unauthenticatedHandler\");\n/**\n * Make REST API call with best-effort IAM auth.\n * @param amplify Amplify instance to to resolve credentials and tokens. Should use different instance in client-side\n * and SSR\n * @param options Options accepted from public API options when calling the handlers.\n * @param signingServiceInfo Internal-only options enable IAM auth as well as to to overwrite the IAM signing service\n * and region. If specified, and NONE of API Key header or Auth header is present, IAM auth will be used.\n * @param iamAuthApplicable Callback function that is used to determine if IAM Auth should be used or not.\n *\n * @internal\n */\nconst transferHandler = async (amplify, options, iamAuthApplicable, signingServiceInfo) => {\n const { url, method, headers, body, withCredentials, abortSignal, retryStrategy, } = options;\n const resolvedBody = body\n ? body instanceof FormData\n ? body\n : JSON.stringify(body ?? '')\n : undefined;\n const resolvedHeaders = (0, resolveHeaders_1.resolveHeaders)(headers, body);\n const request = {\n url,\n headers: resolvedHeaders,\n method,\n body: resolvedBody,\n };\n const { retryStrategy: libraryRetryStrategy, defaultAuthMode: libraryDefaultAuthMode, } = (0, utils_1.resolveLibraryOptions)(amplify);\n const baseOptions = {\n retryDecider: getRetryDeciderFromStrategy(retryStrategy ?? libraryRetryStrategy),\n computeDelay: aws_client_utils_1.jitteredBackoff,\n withCrossDomainCredentials: withCredentials,\n abortSignal,\n };\n const defaultAuthMode = options.defaultAuthMode ?? libraryDefaultAuthMode;\n let credentials = null;\n if (defaultAuthMode !== 'none') {\n credentials = await resolveCredentials(amplify);\n }\n let response;\n const isIamAuthApplicable = iamAuthApplicable(request, signingServiceInfo);\n if (isIamAuthApplicable && credentials) {\n const signingInfoFromUrl = (0, utils_1.parseSigningInfo)(url);\n const signingService = signingServiceInfo?.service ?? signingInfoFromUrl.service;\n const signingRegion = signingServiceInfo?.region ?? signingInfoFromUrl.region;\n response = await (0, authenticatedHandler_1.authenticatedHandler)(request, {\n ...baseOptions,\n credentials,\n region: signingRegion,\n service: signingService,\n });\n }\n else {\n response = await (0, unauthenticatedHandler_1.unauthenticatedHandler)(request, {\n ...baseOptions,\n });\n }\n // Clean-up un-modeled properties from response.\n return {\n statusCode: response.statusCode,\n headers: response.headers,\n body: response.body,\n };\n};\nexports.transferHandler = transferHandler;\nconst getRetryDeciderFromStrategy = (retryStrategy) => {\n const strategy = retryStrategy?.strategy;\n if (strategy === 'no-retry') {\n return () => Promise.resolve({ retryable: false });\n }\n return (0, aws_client_utils_1.getRetryDecider)(utils_1.parseRestApiServiceError);\n};\nconst resolveCredentials = async (amplify) => {\n try {\n const { credentials } = await amplify.Auth.fetchAuthSession();\n if (credentials) {\n return credentials;\n }\n }\n catch (e) {\n utils_1.logger.debug('No credentials available, the request will be unsigned.');\n }\n return null;\n};\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,eAAe,GAAG,MAAM;AAChC,MAAM,kBAAkB,GAAG,OAAO,CAAC,8CAA8C,CAAC;AAClF,MAAM,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC;AACtC,MAAM,gBAAgB,GAAG,OAAO,CAAC,4BAA4B,CAAC;AAC9D,MAAM,sBAAsB,GAAG,OAAO,CAAC,qCAAqC,CAAC;AAC7E,MAAM,wBAAwB,GAAG,OAAO,CAAC,uCAAuC,CAAC;AACjF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,eAAe,GAAG,OAAO,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,KAAK;AAC3F,IAAI,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,WAAW,EAAE,aAAa,GAAG,GAAG,OAAO;AAChG,IAAI,MAAM,YAAY,GAAG;AACzB,UAAU,IAAI,YAAY;AAC1B,cAAc;AACd,cAAc,IAAI,CAAC,SAAS,CAAC,IAAI,IAAI,EAAE;AACvC,UAAU,SAAS;AACnB,IAAI,MAAM,eAAe,GAAG,IAAI,gBAAgB,CAAC,cAAc,EAAE,OAAO,EAAE,IAAI,CAAC;AAC/E,IAAI,MAAM,OAAO,GAAG;AACpB,QAAQ,GAAG;AACX,QAAQ,OAAO,EAAE,eAAe;AAChC,QAAQ,MAAM;AACd,QAAQ,IAAI,EAAE,YAAY;AAC1B,KAAK;AACL,IAAI,MAAM,E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;AAC1B,SAAS,CAAC;AACV,IAAI;AACJ;AACA,IAAI,OAAO;AACX,QAAQ,UAAU,EAAE,QAAQ,CAAC,UAAU;AACvC,QAAQ,OAAO,EAAE,QAAQ,CAAC,OAAO;AACjC,QAAQ,IAAI,EAAE,QAAQ,CAAC,IAAI;AAC3B,KAAK;AACL,CAAC;AACD,OAAO,CAAC,eAAe,GAAG,eAAe;AACzC,MAAM,2BAA2B,GAAG,CAAC,aAAa,KAAK;AACvD,IAAI,MAAM,QAAQ,GAAG,aAAa,EAAE,QAAQ;AAC5C,IAAI,IAAI,QAAQ,KAAK,UAAU,EAAE;AACjC,QAAQ,OAAO,MAAM,OAAO,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;AAC1D,IAAI;AACJ,IAAI,OAAO,IAAI,kBAAkB,CAAC,eAAe,EAAE,OAAO,CAAC,wBAAwB,CAAC;AACpF,CAAC;AACD,MAAM,kBAAkB,GAAG,OAAO,OAAO,KAAK;AAC9C,IAAI,IAAI;AACR,QAAQ,MAAM,EAAE,WAAW,EAAE,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,gBAAgB,EAAE;AACrE,QAAQ,IAAI,WAAW,EAAE;AACzB,YAAY,OAAO,WAAW;AAC9B,QAAQ;AACR,IAAI;AACJ,IAAI,OAAO,CAAC,EAAE;AACd,QAAQ,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,yDAAyD,CAAC;AACvF,IAAI;AACJ,IAAI,OAAO,IAAI;AACf,CAAC;;"}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.patch = exports.head = exports.del = exports.put = exports.post = exports.get = void 0;
|
|
7
|
+
const core_1 = require("@aws-amplify/core");
|
|
8
|
+
const publicApis_1 = require("./common/publicApis");
|
|
9
|
+
/**
|
|
10
|
+
* GET HTTP request
|
|
11
|
+
* @param {GetInput} input - Input for GET operation
|
|
12
|
+
* @returns {GetOperation} Operation for GET request
|
|
13
|
+
* @throws - {@link RestApiError}
|
|
14
|
+
* @example
|
|
15
|
+
* Send a GET request
|
|
16
|
+
* ```js
|
|
17
|
+
* import { get, isCancelError } from '@aws-amplify/api';
|
|
18
|
+
*
|
|
19
|
+
* const { body } = await get({
|
|
20
|
+
* apiName,
|
|
21
|
+
* path,
|
|
22
|
+
* options: {
|
|
23
|
+
* headers, // Optional, A map of custom header key/values
|
|
24
|
+
* body, // Optional, JSON object or FormData
|
|
25
|
+
* queryParams, // Optional, A map of query strings
|
|
26
|
+
* }
|
|
27
|
+
* }).response;
|
|
28
|
+
* const data = await body.json();
|
|
29
|
+
* ```
|
|
30
|
+
* @example
|
|
31
|
+
* Cancel a GET request
|
|
32
|
+
*
|
|
33
|
+
* ```js
|
|
34
|
+
* import { get, isCancelError } from '@aws-amplify/api';
|
|
35
|
+
*
|
|
36
|
+
* const { response, cancel } = get({apiName, path, options});
|
|
37
|
+
* cancel(message);
|
|
38
|
+
* try {
|
|
39
|
+
* await response;
|
|
40
|
+
* } catch (e) {
|
|
41
|
+
* if (isCancelError(e)) {
|
|
42
|
+
* // handle request cancellation
|
|
43
|
+
* }
|
|
44
|
+
* //...
|
|
45
|
+
* }
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
const get = (input) => (0, publicApis_1.get)(core_1.Amplify, input);
|
|
49
|
+
exports.get = get;
|
|
50
|
+
/**
|
|
51
|
+
* POST HTTP request
|
|
52
|
+
* @param {PostInput} input - Input for POST operation
|
|
53
|
+
* @returns {PostOperation} Operation for POST request
|
|
54
|
+
* @throws - {@link RestApiError}
|
|
55
|
+
* @example
|
|
56
|
+
* Send a POST request
|
|
57
|
+
* ```js
|
|
58
|
+
* import { post, isCancelError } from '@aws-amplify/api';
|
|
59
|
+
*
|
|
60
|
+
* const { body } = await post({
|
|
61
|
+
* apiName,
|
|
62
|
+
* path,
|
|
63
|
+
* options: {
|
|
64
|
+
* headers, // Optional, A map of custom header key/values
|
|
65
|
+
* body, // Optional, JSON object or FormData
|
|
66
|
+
* queryParams, // Optional, A map of query strings
|
|
67
|
+
* }
|
|
68
|
+
* }).response;
|
|
69
|
+
* const data = await body.json();
|
|
70
|
+
* ```
|
|
71
|
+
* @example
|
|
72
|
+
* Cancel a POST request
|
|
73
|
+
*
|
|
74
|
+
* ```js
|
|
75
|
+
* import { post, isCancelError } from '@aws-amplify/api';
|
|
76
|
+
*
|
|
77
|
+
* const { response, cancel } = post({apiName, path, options});
|
|
78
|
+
* cancel(message);
|
|
79
|
+
* try {
|
|
80
|
+
* await response;
|
|
81
|
+
* } catch (e) {
|
|
82
|
+
* if (isCancelError(e)) {
|
|
83
|
+
* // handle request cancellation
|
|
84
|
+
* }
|
|
85
|
+
* //...
|
|
86
|
+
* }
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
const post = (input) => (0, publicApis_1.post)(core_1.Amplify, input);
|
|
90
|
+
exports.post = post;
|
|
91
|
+
/**
|
|
92
|
+
* PUT HTTP request
|
|
93
|
+
* @param {PutInput} input - Input for PUT operation
|
|
94
|
+
* @returns {PutOperation} Operation for PUT request
|
|
95
|
+
* @throws - {@link RestApiError}
|
|
96
|
+
* @example
|
|
97
|
+
* Send a PUT request
|
|
98
|
+
* ```js
|
|
99
|
+
* import { put, isCancelError } from '@aws-amplify/api';
|
|
100
|
+
*
|
|
101
|
+
* const { body } = await put({
|
|
102
|
+
* apiName,
|
|
103
|
+
* path,
|
|
104
|
+
* options: {
|
|
105
|
+
* headers, // Optional, A map of custom header key/values
|
|
106
|
+
* body, // Optional, JSON object or FormData
|
|
107
|
+
* queryParams, // Optional, A map of query strings
|
|
108
|
+
* }
|
|
109
|
+
* }).response;
|
|
110
|
+
* const data = await body.json();
|
|
111
|
+
* ```
|
|
112
|
+
* @example
|
|
113
|
+
* Cancel a PUT request
|
|
114
|
+
* ```js
|
|
115
|
+
* import { put, isCancelError } from '@aws-amplify/api';
|
|
116
|
+
*
|
|
117
|
+
* const { response, cancel } = put({apiName, path, options});
|
|
118
|
+
* cancel(message);
|
|
119
|
+
* try {
|
|
120
|
+
* await response;
|
|
121
|
+
* } catch (e) {
|
|
122
|
+
* if (isCancelError(e)) {
|
|
123
|
+
* // handle request cancellation
|
|
124
|
+
* }
|
|
125
|
+
* //...
|
|
126
|
+
* }
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
const put = (input) => (0, publicApis_1.put)(core_1.Amplify, input);
|
|
130
|
+
exports.put = put;
|
|
131
|
+
/**
|
|
132
|
+
* DELETE HTTP request
|
|
133
|
+
* @param {DeleteInput} input - Input for DELETE operation
|
|
134
|
+
* @returns {DeleteOperation} Operation for DELETE request
|
|
135
|
+
* @throws - {@link RestApiError}
|
|
136
|
+
* @example
|
|
137
|
+
* Send a DELETE request
|
|
138
|
+
* ```js
|
|
139
|
+
* import { del } from '@aws-amplify/api';
|
|
140
|
+
*
|
|
141
|
+
* const { statusCode } = await del({
|
|
142
|
+
* apiName,
|
|
143
|
+
* path,
|
|
144
|
+
* options: {
|
|
145
|
+
* headers, // Optional, A map of custom header key/values
|
|
146
|
+
* queryParams, // Optional, A map of query strings
|
|
147
|
+
* }
|
|
148
|
+
* }).response;
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
const del = (input) => (0, publicApis_1.del)(core_1.Amplify, input);
|
|
152
|
+
exports.del = del;
|
|
153
|
+
/**
|
|
154
|
+
* HEAD HTTP request
|
|
155
|
+
* @param {HeadInput} input - Input for HEAD operation
|
|
156
|
+
* @returns {HeadOperation} Operation for HEAD request
|
|
157
|
+
* @throws - {@link RestApiError}
|
|
158
|
+
* @example
|
|
159
|
+
* Send a HEAD request
|
|
160
|
+
* ```js
|
|
161
|
+
* import { head, isCancelError } from '@aws-amplify/api';
|
|
162
|
+
*
|
|
163
|
+
* const { headers, statusCode } = await head({
|
|
164
|
+
* apiName,
|
|
165
|
+
* path,
|
|
166
|
+
* options: {
|
|
167
|
+
* headers, // Optional, A map of custom header key/values
|
|
168
|
+
* queryParams, // Optional, A map of query strings
|
|
169
|
+
* }
|
|
170
|
+
* }),response;
|
|
171
|
+
* ```
|
|
172
|
+
*
|
|
173
|
+
*/
|
|
174
|
+
const head = (input) => (0, publicApis_1.head)(core_1.Amplify, input);
|
|
175
|
+
exports.head = head;
|
|
176
|
+
/**
|
|
177
|
+
* PATCH HTTP request
|
|
178
|
+
* @param {PatchInput} input - Input for PATCH operation
|
|
179
|
+
* @returns {PatchOperation} Operation for PATCH request
|
|
180
|
+
* @throws - {@link RestApiError}
|
|
181
|
+
* @example
|
|
182
|
+
* Send a PATCH request
|
|
183
|
+
* ```js
|
|
184
|
+
* import { patch } from '@aws-amplify/api';
|
|
185
|
+
*
|
|
186
|
+
* const { body } = await patch({
|
|
187
|
+
* apiName,
|
|
188
|
+
* path,
|
|
189
|
+
* options: {
|
|
190
|
+
* headers, // Optional, A map of custom header key/values
|
|
191
|
+
* body, // Optional, JSON object or FormData
|
|
192
|
+
* queryParams, // Optional, A map of query strings
|
|
193
|
+
* }
|
|
194
|
+
* }).response;
|
|
195
|
+
* const data = await body.json();
|
|
196
|
+
* ```
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* Cancel a PATCH request
|
|
200
|
+
* ```js
|
|
201
|
+
* import { patch, isCancelError } from '@aws-amplify/api';
|
|
202
|
+
*
|
|
203
|
+
* const { response, cancel } = patch({apiName, path, options});
|
|
204
|
+
* cancel(message);
|
|
205
|
+
* try {
|
|
206
|
+
* await response;
|
|
207
|
+
* } catch (e) {
|
|
208
|
+
* if (isCancelError(e)) {
|
|
209
|
+
* // handle request cancellation
|
|
210
|
+
* }
|
|
211
|
+
* //...
|
|
212
|
+
* }
|
|
213
|
+
* ```
|
|
214
|
+
*/
|
|
215
|
+
const patch = (input) => (0, publicApis_1.patch)(core_1.Amplify, input);
|
|
216
|
+
exports.patch = patch;
|
|
217
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/apis/index.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.patch = exports.head = exports.del = exports.put = exports.post = exports.get = void 0;\nconst core_1 = require(\"@aws-amplify/core\");\nconst publicApis_1 = require(\"./common/publicApis\");\n/**\n * GET HTTP request\n * @param {GetInput} input - Input for GET operation\n * @returns {GetOperation} Operation for GET request\n * @throws - {@link RestApiError}\n * @example\n * Send a GET request\n * ```js\n * import { get, isCancelError } from '@aws-amplify/api';\n *\n * const { body } = await get({\n * apiName,\n * path,\n * options: {\n * headers, // Optional, A map of custom header key/values\n * body, // Optional, JSON object or FormData\n * queryParams, // Optional, A map of query strings\n * }\n * }).response;\n * const data = await body.json();\n * ```\n * @example\n * Cancel a GET request\n *\n * ```js\n * import { get, isCancelError } from '@aws-amplify/api';\n *\n * const { response, cancel } = get({apiName, path, options});\n * cancel(message);\n * try {\n * await response;\n * } catch (e) {\n * if (isCancelError(e)) {\n * // handle request cancellation\n * }\n * //...\n * }\n * ```\n */\nconst get = (input) => (0, publicApis_1.get)(core_1.Amplify, input);\nexports.get = get;\n/**\n * POST HTTP request\n * @param {PostInput} input - Input for POST operation\n * @returns {PostOperation} Operation for POST request\n * @throws - {@link RestApiError}\n * @example\n * Send a POST request\n * ```js\n * import { post, isCancelError } from '@aws-amplify/api';\n *\n * const { body } = await post({\n * apiName,\n * path,\n * options: {\n * headers, // Optional, A map of custom header key/values\n * body, // Optional, JSON object or FormData\n * queryParams, // Optional, A map of query strings\n * }\n * }).response;\n * const data = await body.json();\n * ```\n * @example\n * Cancel a POST request\n *\n * ```js\n * import { post, isCancelError } from '@aws-amplify/api';\n *\n * const { response, cancel } = post({apiName, path, options});\n * cancel(message);\n * try {\n * await response;\n * } catch (e) {\n * if (isCancelError(e)) {\n * // handle request cancellation\n * }\n * //...\n * }\n * ```\n */\nconst post = (input) => (0, publicApis_1.post)(core_1.Amplify, input);\nexports.post = post;\n/**\n * PUT HTTP request\n * @param {PutInput} input - Input for PUT operation\n * @returns {PutOperation} Operation for PUT request\n * @throws - {@link RestApiError}\n * @example\n * Send a PUT request\n * ```js\n * import { put, isCancelError } from '@aws-amplify/api';\n *\n * const { body } = await put({\n * apiName,\n * path,\n * options: {\n * headers, // Optional, A map of custom header key/values\n * body, // Optional, JSON object or FormData\n * queryParams, // Optional, A map of query strings\n * }\n * }).response;\n * const data = await body.json();\n * ```\n * @example\n * Cancel a PUT request\n * ```js\n * import { put, isCancelError } from '@aws-amplify/api';\n *\n * const { response, cancel } = put({apiName, path, options});\n * cancel(message);\n * try {\n * await response;\n * } catch (e) {\n * if (isCancelError(e)) {\n * // handle request cancellation\n * }\n * //...\n * }\n * ```\n */\nconst put = (input) => (0, publicApis_1.put)(core_1.Amplify, input);\nexports.put = put;\n/**\n * DELETE HTTP request\n * @param {DeleteInput} input - Input for DELETE operation\n * @returns {DeleteOperation} Operation for DELETE request\n * @throws - {@link RestApiError}\n * @example\n * Send a DELETE request\n * ```js\n * import { del } from '@aws-amplify/api';\n *\n * const { statusCode } = await del({\n * apiName,\n * path,\n * options: {\n * headers, // Optional, A map of custom header key/values\n * queryParams, // Optional, A map of query strings\n * }\n * }).response;\n * ```\n */\nconst del = (input) => (0, publicApis_1.del)(core_1.Amplify, input);\nexports.del = del;\n/**\n * HEAD HTTP request\n * @param {HeadInput} input - Input for HEAD operation\n * @returns {HeadOperation} Operation for HEAD request\n * @throws - {@link RestApiError}\n * @example\n * Send a HEAD request\n * ```js\n * import { head, isCancelError } from '@aws-amplify/api';\n *\n * const { headers, statusCode } = await head({\n * apiName,\n * path,\n * options: {\n * headers, // Optional, A map of custom header key/values\n * queryParams, // Optional, A map of query strings\n * }\n * }),response;\n * ```\n *\n */\nconst head = (input) => (0, publicApis_1.head)(core_1.Amplify, input);\nexports.head = head;\n/**\n * PATCH HTTP request\n * @param {PatchInput} input - Input for PATCH operation\n * @returns {PatchOperation} Operation for PATCH request\n * @throws - {@link RestApiError}\n * @example\n * Send a PATCH request\n * ```js\n * import { patch } from '@aws-amplify/api';\n *\n * const { body } = await patch({\n * apiName,\n * path,\n * options: {\n * headers, // Optional, A map of custom header key/values\n * body, // Optional, JSON object or FormData\n * queryParams, // Optional, A map of query strings\n * }\n * }).response;\n * const data = await body.json();\n * ```\n *\n * @example\n * Cancel a PATCH request\n * ```js\n * import { patch, isCancelError } from '@aws-amplify/api';\n *\n * const { response, cancel } = patch({apiName, path, options});\n * cancel(message);\n * try {\n * await response;\n * } catch (e) {\n * if (isCancelError(e)) {\n * // handle request cancellation\n * }\n * //...\n * }\n * ```\n */\nconst patch = (input) => (0, publicApis_1.patch)(core_1.Amplify, input);\nexports.patch = patch;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AAC7D,OAAO,CAAC,KAAK,GAAG,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,GAAG,OAAO,CAAC,IAAI,GAAG,OAAO,CAAC,GAAG,GAAG,MAAM;AAC9F,MAAM,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC;AAC3C,MAAM,YAAY,GAAG,OAAO,CAAC,qBAAqB,CAAC;AACnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,GAAG,GAAG,CAAC,KAAK,KAAK,IAAI,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC;AACnE,OAAO,CAAC,GAAG,GAAG,GAAG;AACjB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,IAAI,GAAG,CAAC,KAAK,KAAK,IAAI,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC;AACrE,OAAO,CAAC,IAAI,GAAG,IAAI;AACnB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,GAAG,GAAG,CAAC,KAAK,KAAK,IAAI,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC;AACnE,OAAO,CAAC,GAAG,GAAG,GAAG;AACjB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,GAAG,GAAG,CAAC,KAAK,KAAK,IAAI,YAAY,CAAC,GAAG,EAAE,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC;AACnE,OAAO,CAAC,GAAG,GAAG,GAAG;AACjB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,IAAI,GAAG,CAAC,KAAK,KAAK,IAAI,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC;AACrE,OAAO,CAAC,IAAI,GAAG,IAAI;AACnB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,KAAK,GAAG,CAAC,KAAK,KAAK,IAAI,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC;AACvE,OAAO,CAAC,KAAK,GAAG,KAAK;;"}
|