@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
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { createCancellableOperation } from '../../utils/createCancellableOperation.mjs';
|
|
2
|
+
import { parseSigningInfo } from '../../utils/parseSigningInfo.mjs';
|
|
3
|
+
import '@aws-amplify/core/internals/aws-client-utils';
|
|
4
|
+
import '@aws-amplify/core/internals/utils';
|
|
5
|
+
import '../../errors/validation.mjs';
|
|
6
|
+
import { resolveApiUrl } from '../../utils/resolveApiUrl.mjs';
|
|
7
|
+
import { logger } from '../../utils/logger.mjs';
|
|
8
|
+
import { isIamAuthApplicableForRest } from '../../utils/isIamAuthApplicable.mjs';
|
|
9
|
+
import { transferHandler } from './transferHandler.mjs';
|
|
10
|
+
|
|
11
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
12
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
13
|
+
const publicHandler = (amplify, options, method) => {
|
|
14
|
+
const { apiName, options: apiOptions = {}, path: apiPath } = options;
|
|
15
|
+
const libraryConfigTimeout = amplify.libraryOptions?.API?.REST?.timeout?.({
|
|
16
|
+
apiName,
|
|
17
|
+
method,
|
|
18
|
+
});
|
|
19
|
+
const timeout = apiOptions?.timeout || libraryConfigTimeout || undefined;
|
|
20
|
+
const publicApisAbortController = new AbortController();
|
|
21
|
+
const abortSignal = publicApisAbortController.signal;
|
|
22
|
+
return createCancellableOperation(async () => {
|
|
23
|
+
const url = resolveApiUrl(amplify, apiName, apiPath, apiOptions?.queryParams);
|
|
24
|
+
const libraryConfigHeaders = await amplify.libraryOptions?.API?.REST?.headers?.({
|
|
25
|
+
apiName,
|
|
26
|
+
});
|
|
27
|
+
const { headers: invocationHeaders = {} } = apiOptions;
|
|
28
|
+
const headers = {
|
|
29
|
+
// custom headers from invocation options should precede library options
|
|
30
|
+
...libraryConfigHeaders,
|
|
31
|
+
...invocationHeaders,
|
|
32
|
+
};
|
|
33
|
+
const signingServiceInfo = parseSigningInfo(url, {
|
|
34
|
+
amplify,
|
|
35
|
+
apiName,
|
|
36
|
+
});
|
|
37
|
+
logger.debug(method, url, headers, `IAM signing options: ${JSON.stringify(signingServiceInfo)}`);
|
|
38
|
+
return transferHandler(amplify, {
|
|
39
|
+
...apiOptions,
|
|
40
|
+
url,
|
|
41
|
+
method,
|
|
42
|
+
headers,
|
|
43
|
+
abortSignal,
|
|
44
|
+
}, isIamAuthApplicableForRest, signingServiceInfo);
|
|
45
|
+
}, publicApisAbortController, 'public', // operation Type
|
|
46
|
+
timeout);
|
|
47
|
+
};
|
|
48
|
+
const get = (amplify, input) => publicHandler(amplify, input, 'GET');
|
|
49
|
+
const post = (amplify, input) => publicHandler(amplify, input, 'POST');
|
|
50
|
+
const put = (amplify, input) => publicHandler(amplify, input, 'PUT');
|
|
51
|
+
const del = (amplify, input) => publicHandler(amplify, input, 'DELETE');
|
|
52
|
+
const head = (amplify, input) => publicHandler(amplify, input, 'HEAD');
|
|
53
|
+
const patch = (amplify, input) => publicHandler(amplify, input, 'PATCH');
|
|
54
|
+
|
|
55
|
+
export { del, get, head, patch, post, put };
|
|
56
|
+
//# sourceMappingURL=publicApis.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publicApis.mjs","sources":["../../../../src/apis/common/publicApis.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { createCancellableOperation, logger, parseSigningInfo, resolveApiUrl, } from '../../utils';\nimport { isIamAuthApplicableForRest } from '../../utils/isIamAuthApplicable';\nimport { transferHandler } from './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 createCancellableOperation(async () => {\n const url = 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 = parseSigningInfo(url, {\n amplify,\n apiName,\n });\n logger.debug(method, url, headers, `IAM signing options: ${JSON.stringify(signingServiceInfo)}`);\n return transferHandler(amplify, {\n ...apiOptions,\n url,\n method,\n headers,\n abortSignal,\n }, isIamAuthApplicableForRest, signingServiceInfo);\n }, publicApisAbortController, 'public', // operation Type\n timeout);\n};\nexport const get = (amplify, input) => publicHandler(amplify, input, 'GET');\nexport const post = (amplify, input) => publicHandler(amplify, input, 'POST');\nexport const put = (amplify, input) => publicHandler(amplify, input, 'PUT');\nexport const del = (amplify, input) => publicHandler(amplify, input, 'DELETE');\nexport const head = (amplify, input) => publicHandler(amplify, input, 'HEAD');\nexport const patch = (amplify, input) => publicHandler(amplify, input, 'PATCH');\n"],"names":[],"mappings":";;;;;;;;;;AAAA;AACA;AAIA,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK;AACpD,IAAI,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,GAAG,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO;AACxE,IAAI,MAAM,oBAAoB,GAAG,OAAO,CAAC,cAAc,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,GAAG;AAC9E,QAAQ,OAAO;AACf,QAAQ,MAAM;AACd,KAAK,CAAC;AACN,IAAI,MAAM,OAAO,GAAG,UAAU,EAAE,OAAO,IAAI,oBAAoB,IAAI,SAAS;AAC5E,IAAI,MAAM,yBAAyB,GAAG,IAAI,eAAe,EAAE;AAC3D,IAAI,MAAM,WAAW,GAAG,yBAAyB,CAAC,MAAM;AACxD,IAAI,OAAO,0BAA0B,CAAC,YAAY;AAClD,QAAQ,MAAM,GAAG,GAAG,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,CAAC;AACrF,QAAQ,MAAM,oBAAoB,GAAG,MAAM,OAAO,CAAC,cAAc,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,GAAG;AACxF,YAAY,OAAO;AACnB,SAAS,CAAC;AACV,QAAQ,MAAM,EAAE,OAAO,EAAE,iBAAiB,GAAG,EAAE,EAAE,GAAG,UAAU;AAC9D,QAAQ,MAAM,OAAO,GAAG;AACxB;AACA,YAAY,GAAG,oBAAoB;AACnC,YAAY,GAAG,iBAAiB;AAChC,SAAS;AACT,QAAQ,MAAM,kBAAkB,GAAG,gBAAgB,CAAC,GAAG,EAAE;AACzD,YAAY,OAAO;AACnB,YAAY,OAAO;AACnB,SAAS,CAAC;AACV,QAAQ,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,qBAAqB,EAAE,IAAI,CAAC,SAAS,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC;AACxG,QAAQ,OAAO,eAAe,CAAC,OAAO,EAAE;AACxC,YAAY,GAAG,UAAU;AACzB,YAAY,GAAG;AACf,YAAY,MAAM;AAClB,YAAY,OAAO;AACnB,YAAY,WAAW;AACvB,SAAS,EAAE,0BAA0B,EAAE,kBAAkB,CAAC;AAC1D,IAAI,CAAC,EAAE,yBAAyB,EAAE,QAAQ;AAC1C,IAAI,OAAO,CAAC;AACZ,CAAC;AACW,MAAC,GAAG,GAAG,CAAC,OAAO,EAAE,KAAK,KAAK,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK;AAC9D,MAAC,IAAI,GAAG,CAAC,OAAO,EAAE,KAAK,KAAK,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM;AAChE,MAAC,GAAG,GAAG,CAAC,OAAO,EAAE,KAAK,KAAK,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK;AAC9D,MAAC,GAAG,GAAG,CAAC,OAAO,EAAE,KAAK,KAAK,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,QAAQ;AACjE,MAAC,IAAI,GAAG,CAAC,OAAO,EAAE,KAAK,KAAK,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM;AAChE,MAAC,KAAK,GAAG,CAAC,OAAO,EAAE,KAAK,KAAK,aAAa,CAAC,OAAO,EAAE,KAAK,EAAE,OAAO;;;;"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { AmplifyClassV6 } from '@aws-amplify/core';
|
|
2
|
+
import { Headers, HttpRequest } from '@aws-amplify/core/internals/aws-client-utils';
|
|
3
|
+
import { DocumentType, RESTAuthMode, RetryStrategy } from '@aws-amplify/core/internals/utils';
|
|
4
|
+
import { RestApiResponse, SigningServiceInfo } from '../../types';
|
|
5
|
+
type HandlerOptions = Omit<HttpRequest, 'body' | 'headers'> & {
|
|
6
|
+
body?: DocumentType | FormData;
|
|
7
|
+
headers?: Headers;
|
|
8
|
+
withCredentials?: boolean;
|
|
9
|
+
retryStrategy?: RetryStrategy;
|
|
10
|
+
defaultAuthMode?: RESTAuthMode;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Make REST API call with best-effort IAM auth.
|
|
14
|
+
* @param amplify Amplify instance to to resolve credentials and tokens. Should use different instance in client-side
|
|
15
|
+
* and SSR
|
|
16
|
+
* @param options Options accepted from public API options when calling the handlers.
|
|
17
|
+
* @param signingServiceInfo Internal-only options enable IAM auth as well as to to overwrite the IAM signing service
|
|
18
|
+
* and region. If specified, and NONE of API Key header or Auth header is present, IAM auth will be used.
|
|
19
|
+
* @param iamAuthApplicable Callback function that is used to determine if IAM Auth should be used or not.
|
|
20
|
+
*
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
export declare const transferHandler: (amplify: AmplifyClassV6, options: HandlerOptions & {
|
|
24
|
+
abortSignal: AbortSignal;
|
|
25
|
+
}, iamAuthApplicable: ({ headers }: HttpRequest, signingServiceInfo?: SigningServiceInfo) => boolean, signingServiceInfo?: SigningServiceInfo) => Promise<RestApiResponse>;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { jitteredBackoff, getRetryDecider } from '@aws-amplify/core/internals/aws-client-utils';
|
|
2
|
+
import '@aws-amplify/core/internals/utils';
|
|
3
|
+
import '../../errors/validation.mjs';
|
|
4
|
+
import { parseRestApiServiceError } from '../../utils/serviceError.mjs';
|
|
5
|
+
import { logger } from '../../utils/logger.mjs';
|
|
6
|
+
import { parseSigningInfo } from '../../utils/parseSigningInfo.mjs';
|
|
7
|
+
import { resolveLibraryOptions } from '../../utils/resolveLibraryOptions.mjs';
|
|
8
|
+
import { resolveHeaders } from '../../utils/resolveHeaders.mjs';
|
|
9
|
+
import { authenticatedHandler } from './baseHandlers/authenticatedHandler.mjs';
|
|
10
|
+
import { unauthenticatedHandler } from './baseHandlers/unauthenticatedHandler.mjs';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Make REST API call with best-effort IAM auth.
|
|
14
|
+
* @param amplify Amplify instance to to resolve credentials and tokens. Should use different instance in client-side
|
|
15
|
+
* and SSR
|
|
16
|
+
* @param options Options accepted from public API options when calling the handlers.
|
|
17
|
+
* @param signingServiceInfo Internal-only options enable IAM auth as well as to to overwrite the IAM signing service
|
|
18
|
+
* and region. If specified, and NONE of API Key header or Auth header is present, IAM auth will be used.
|
|
19
|
+
* @param iamAuthApplicable Callback function that is used to determine if IAM Auth should be used or not.
|
|
20
|
+
*
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
const transferHandler = async (amplify, options, iamAuthApplicable, signingServiceInfo) => {
|
|
24
|
+
const { url, method, headers, body, withCredentials, abortSignal, retryStrategy, } = options;
|
|
25
|
+
const resolvedBody = body
|
|
26
|
+
? body instanceof FormData
|
|
27
|
+
? body
|
|
28
|
+
: JSON.stringify(body ?? '')
|
|
29
|
+
: undefined;
|
|
30
|
+
const resolvedHeaders = resolveHeaders(headers, body);
|
|
31
|
+
const request = {
|
|
32
|
+
url,
|
|
33
|
+
headers: resolvedHeaders,
|
|
34
|
+
method,
|
|
35
|
+
body: resolvedBody,
|
|
36
|
+
};
|
|
37
|
+
const { retryStrategy: libraryRetryStrategy, defaultAuthMode: libraryDefaultAuthMode, } = resolveLibraryOptions(amplify);
|
|
38
|
+
const baseOptions = {
|
|
39
|
+
retryDecider: getRetryDeciderFromStrategy(retryStrategy ?? libraryRetryStrategy),
|
|
40
|
+
computeDelay: jitteredBackoff,
|
|
41
|
+
withCrossDomainCredentials: withCredentials,
|
|
42
|
+
abortSignal,
|
|
43
|
+
};
|
|
44
|
+
const defaultAuthMode = options.defaultAuthMode ?? libraryDefaultAuthMode;
|
|
45
|
+
let credentials = null;
|
|
46
|
+
if (defaultAuthMode !== 'none') {
|
|
47
|
+
credentials = await resolveCredentials(amplify);
|
|
48
|
+
}
|
|
49
|
+
let response;
|
|
50
|
+
const isIamAuthApplicable = iamAuthApplicable(request, signingServiceInfo);
|
|
51
|
+
if (isIamAuthApplicable && credentials) {
|
|
52
|
+
const signingInfoFromUrl = parseSigningInfo(url);
|
|
53
|
+
const signingService = signingServiceInfo?.service ?? signingInfoFromUrl.service;
|
|
54
|
+
const signingRegion = signingServiceInfo?.region ?? signingInfoFromUrl.region;
|
|
55
|
+
response = await authenticatedHandler(request, {
|
|
56
|
+
...baseOptions,
|
|
57
|
+
credentials,
|
|
58
|
+
region: signingRegion,
|
|
59
|
+
service: signingService,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
response = await unauthenticatedHandler(request, {
|
|
64
|
+
...baseOptions,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
// Clean-up un-modeled properties from response.
|
|
68
|
+
return {
|
|
69
|
+
statusCode: response.statusCode,
|
|
70
|
+
headers: response.headers,
|
|
71
|
+
body: response.body,
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
const getRetryDeciderFromStrategy = (retryStrategy) => {
|
|
75
|
+
const strategy = retryStrategy?.strategy;
|
|
76
|
+
if (strategy === 'no-retry') {
|
|
77
|
+
return () => Promise.resolve({ retryable: false });
|
|
78
|
+
}
|
|
79
|
+
return getRetryDecider(parseRestApiServiceError);
|
|
80
|
+
};
|
|
81
|
+
const resolveCredentials = async (amplify) => {
|
|
82
|
+
try {
|
|
83
|
+
const { credentials } = await amplify.Auth.fetchAuthSession();
|
|
84
|
+
if (credentials) {
|
|
85
|
+
return credentials;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch (e) {
|
|
89
|
+
logger.debug('No credentials available, the request will be unsigned.');
|
|
90
|
+
}
|
|
91
|
+
return null;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export { transferHandler };
|
|
95
|
+
//# sourceMappingURL=transferHandler.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transferHandler.mjs","sources":["../../../../src/apis/common/transferHandler.ts"],"sourcesContent":["import { getRetryDecider, jitteredBackoff, } from '@aws-amplify/core/internals/aws-client-utils';\nimport { logger, parseRestApiServiceError, parseSigningInfo, resolveLibraryOptions, } from '../../utils';\nimport { resolveHeaders } from '../../utils/resolveHeaders';\nimport { authenticatedHandler } from './baseHandlers/authenticatedHandler';\nimport { unauthenticatedHandler } from './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 */\nexport const 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 = resolveHeaders(headers, body);\n const request = {\n url,\n headers: resolvedHeaders,\n method,\n body: resolvedBody,\n };\n const { retryStrategy: libraryRetryStrategy, defaultAuthMode: libraryDefaultAuthMode, } = resolveLibraryOptions(amplify);\n const baseOptions = {\n retryDecider: getRetryDeciderFromStrategy(retryStrategy ?? libraryRetryStrategy),\n computeDelay: 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 = parseSigningInfo(url);\n const signingService = signingServiceInfo?.service ?? signingInfoFromUrl.service;\n const signingRegion = signingServiceInfo?.region ?? signingInfoFromUrl.region;\n response = await authenticatedHandler(request, {\n ...baseOptions,\n credentials,\n region: signingRegion,\n service: signingService,\n });\n }\n else {\n response = await 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};\nconst getRetryDeciderFromStrategy = (retryStrategy) => {\n const strategy = retryStrategy?.strategy;\n if (strategy === 'no-retry') {\n return () => Promise.resolve({ retryable: false });\n }\n return getRetryDecider(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 logger.debug('No credentials available, the request will be unsigned.');\n }\n return null;\n};\n"],"names":[],"mappings":"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"}
|
|
@@ -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
|
+
* } catch (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
|
+
* } catch (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
|
+
* } catch (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
|
+
* } catch (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,210 @@
|
|
|
1
|
+
import { Amplify } from '@aws-amplify/core';
|
|
2
|
+
import { get as get$1, post as post$1, put as put$1, del as del$1, head as head$1, patch as patch$1 } from './common/publicApis.mjs';
|
|
3
|
+
|
|
4
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
5
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
/**
|
|
7
|
+
* GET HTTP request
|
|
8
|
+
* @param {GetInput} input - Input for GET operation
|
|
9
|
+
* @returns {GetOperation} Operation for GET request
|
|
10
|
+
* @throws - {@link RestApiError}
|
|
11
|
+
* @example
|
|
12
|
+
* Send a GET request
|
|
13
|
+
* ```js
|
|
14
|
+
* import { get, isCancelError } from '@aws-amplify/api';
|
|
15
|
+
*
|
|
16
|
+
* const { body } = await get({
|
|
17
|
+
* apiName,
|
|
18
|
+
* path,
|
|
19
|
+
* options: {
|
|
20
|
+
* headers, // Optional, A map of custom header key/values
|
|
21
|
+
* body, // Optional, JSON object or FormData
|
|
22
|
+
* queryParams, // Optional, A map of query strings
|
|
23
|
+
* }
|
|
24
|
+
* }).response;
|
|
25
|
+
* const data = await body.json();
|
|
26
|
+
* ```
|
|
27
|
+
* @example
|
|
28
|
+
* Cancel a GET request
|
|
29
|
+
*
|
|
30
|
+
* ```js
|
|
31
|
+
* import { get, isCancelError } from '@aws-amplify/api';
|
|
32
|
+
*
|
|
33
|
+
* const { response, cancel } = get({apiName, path, options});
|
|
34
|
+
* cancel(message);
|
|
35
|
+
* try {
|
|
36
|
+
* await response;
|
|
37
|
+
* } catch (e) {
|
|
38
|
+
* if (isCancelError(e)) {
|
|
39
|
+
* // handle request cancellation
|
|
40
|
+
* }
|
|
41
|
+
* //...
|
|
42
|
+
* }
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
const get = (input) => get$1(Amplify, input);
|
|
46
|
+
/**
|
|
47
|
+
* POST HTTP request
|
|
48
|
+
* @param {PostInput} input - Input for POST operation
|
|
49
|
+
* @returns {PostOperation} Operation for POST request
|
|
50
|
+
* @throws - {@link RestApiError}
|
|
51
|
+
* @example
|
|
52
|
+
* Send a POST request
|
|
53
|
+
* ```js
|
|
54
|
+
* import { post, isCancelError } from '@aws-amplify/api';
|
|
55
|
+
*
|
|
56
|
+
* const { body } = await post({
|
|
57
|
+
* apiName,
|
|
58
|
+
* path,
|
|
59
|
+
* options: {
|
|
60
|
+
* headers, // Optional, A map of custom header key/values
|
|
61
|
+
* body, // Optional, JSON object or FormData
|
|
62
|
+
* queryParams, // Optional, A map of query strings
|
|
63
|
+
* }
|
|
64
|
+
* }).response;
|
|
65
|
+
* const data = await body.json();
|
|
66
|
+
* ```
|
|
67
|
+
* @example
|
|
68
|
+
* Cancel a POST request
|
|
69
|
+
*
|
|
70
|
+
* ```js
|
|
71
|
+
* import { post, isCancelError } from '@aws-amplify/api';
|
|
72
|
+
*
|
|
73
|
+
* const { response, cancel } = post({apiName, path, options});
|
|
74
|
+
* cancel(message);
|
|
75
|
+
* try {
|
|
76
|
+
* await response;
|
|
77
|
+
* } catch (e) {
|
|
78
|
+
* if (isCancelError(e)) {
|
|
79
|
+
* // handle request cancellation
|
|
80
|
+
* }
|
|
81
|
+
* //...
|
|
82
|
+
* }
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
const post = (input) => post$1(Amplify, input);
|
|
86
|
+
/**
|
|
87
|
+
* PUT HTTP request
|
|
88
|
+
* @param {PutInput} input - Input for PUT operation
|
|
89
|
+
* @returns {PutOperation} Operation for PUT request
|
|
90
|
+
* @throws - {@link RestApiError}
|
|
91
|
+
* @example
|
|
92
|
+
* Send a PUT request
|
|
93
|
+
* ```js
|
|
94
|
+
* import { put, isCancelError } from '@aws-amplify/api';
|
|
95
|
+
*
|
|
96
|
+
* const { body } = await put({
|
|
97
|
+
* apiName,
|
|
98
|
+
* path,
|
|
99
|
+
* options: {
|
|
100
|
+
* headers, // Optional, A map of custom header key/values
|
|
101
|
+
* body, // Optional, JSON object or FormData
|
|
102
|
+
* queryParams, // Optional, A map of query strings
|
|
103
|
+
* }
|
|
104
|
+
* }).response;
|
|
105
|
+
* const data = await body.json();
|
|
106
|
+
* ```
|
|
107
|
+
* @example
|
|
108
|
+
* Cancel a PUT request
|
|
109
|
+
* ```js
|
|
110
|
+
* import { put, isCancelError } from '@aws-amplify/api';
|
|
111
|
+
*
|
|
112
|
+
* const { response, cancel } = put({apiName, path, options});
|
|
113
|
+
* cancel(message);
|
|
114
|
+
* try {
|
|
115
|
+
* await response;
|
|
116
|
+
* } catch (e) {
|
|
117
|
+
* if (isCancelError(e)) {
|
|
118
|
+
* // handle request cancellation
|
|
119
|
+
* }
|
|
120
|
+
* //...
|
|
121
|
+
* }
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
const put = (input) => put$1(Amplify, input);
|
|
125
|
+
/**
|
|
126
|
+
* DELETE HTTP request
|
|
127
|
+
* @param {DeleteInput} input - Input for DELETE operation
|
|
128
|
+
* @returns {DeleteOperation} Operation for DELETE request
|
|
129
|
+
* @throws - {@link RestApiError}
|
|
130
|
+
* @example
|
|
131
|
+
* Send a DELETE request
|
|
132
|
+
* ```js
|
|
133
|
+
* import { del } from '@aws-amplify/api';
|
|
134
|
+
*
|
|
135
|
+
* const { statusCode } = await del({
|
|
136
|
+
* apiName,
|
|
137
|
+
* path,
|
|
138
|
+
* options: {
|
|
139
|
+
* headers, // Optional, A map of custom header key/values
|
|
140
|
+
* queryParams, // Optional, A map of query strings
|
|
141
|
+
* }
|
|
142
|
+
* }).response;
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
const del = (input) => del$1(Amplify, input);
|
|
146
|
+
/**
|
|
147
|
+
* HEAD HTTP request
|
|
148
|
+
* @param {HeadInput} input - Input for HEAD operation
|
|
149
|
+
* @returns {HeadOperation} Operation for HEAD request
|
|
150
|
+
* @throws - {@link RestApiError}
|
|
151
|
+
* @example
|
|
152
|
+
* Send a HEAD request
|
|
153
|
+
* ```js
|
|
154
|
+
* import { head, isCancelError } from '@aws-amplify/api';
|
|
155
|
+
*
|
|
156
|
+
* const { headers, statusCode } = await head({
|
|
157
|
+
* apiName,
|
|
158
|
+
* path,
|
|
159
|
+
* options: {
|
|
160
|
+
* headers, // Optional, A map of custom header key/values
|
|
161
|
+
* queryParams, // Optional, A map of query strings
|
|
162
|
+
* }
|
|
163
|
+
* }),response;
|
|
164
|
+
* ```
|
|
165
|
+
*
|
|
166
|
+
*/
|
|
167
|
+
const head = (input) => head$1(Amplify, input);
|
|
168
|
+
/**
|
|
169
|
+
* PATCH HTTP request
|
|
170
|
+
* @param {PatchInput} input - Input for PATCH operation
|
|
171
|
+
* @returns {PatchOperation} Operation for PATCH request
|
|
172
|
+
* @throws - {@link RestApiError}
|
|
173
|
+
* @example
|
|
174
|
+
* Send a PATCH request
|
|
175
|
+
* ```js
|
|
176
|
+
* import { patch } from '@aws-amplify/api';
|
|
177
|
+
*
|
|
178
|
+
* const { body } = await patch({
|
|
179
|
+
* apiName,
|
|
180
|
+
* path,
|
|
181
|
+
* options: {
|
|
182
|
+
* headers, // Optional, A map of custom header key/values
|
|
183
|
+
* body, // Optional, JSON object or FormData
|
|
184
|
+
* queryParams, // Optional, A map of query strings
|
|
185
|
+
* }
|
|
186
|
+
* }).response;
|
|
187
|
+
* const data = await body.json();
|
|
188
|
+
* ```
|
|
189
|
+
*
|
|
190
|
+
* @example
|
|
191
|
+
* Cancel a PATCH request
|
|
192
|
+
* ```js
|
|
193
|
+
* import { patch, isCancelError } from '@aws-amplify/api';
|
|
194
|
+
*
|
|
195
|
+
* const { response, cancel } = patch({apiName, path, options});
|
|
196
|
+
* cancel(message);
|
|
197
|
+
* try {
|
|
198
|
+
* await response;
|
|
199
|
+
* } catch (e) {
|
|
200
|
+
* if (isCancelError(e)) {
|
|
201
|
+
* // handle request cancellation
|
|
202
|
+
* }
|
|
203
|
+
* //...
|
|
204
|
+
* }
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
const patch = (input) => patch$1(Amplify, input);
|
|
208
|
+
|
|
209
|
+
export { del, get, head, patch, post, put };
|
|
210
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../src/apis/index.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { Amplify } from '@aws-amplify/core';\nimport { del as commonDel, get as commonGet, head as commonHead, patch as commonPatch, post as commonPost, put as commonPut, } from './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 */\nexport const get = (input) => commonGet(Amplify, input);\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 */\nexport const post = (input) => commonPost(Amplify, input);\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 */\nexport const put = (input) => commonPut(Amplify, input);\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 */\nexport const del = (input) => commonDel(Amplify, input);\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 */\nexport const head = (input) => commonHead(Amplify, input);\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 */\nexport const patch = (input) => commonPatch(Amplify, input);\n"],"names":["commonGet","commonPost","commonPut","commonDel","commonHead","commonPatch"],"mappings":";;;AAAA;AACA;AAGA;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;AACY,MAAC,GAAG,GAAG,CAAC,KAAK,KAAKA,KAAS,CAAC,OAAO,EAAE,KAAK;AACtD;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;AACY,MAAC,IAAI,GAAG,CAAC,KAAK,KAAKC,MAAU,CAAC,OAAO,EAAE,KAAK;AACxD;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;AACY,MAAC,GAAG,GAAG,CAAC,KAAK,KAAKC,KAAS,CAAC,OAAO,EAAE,KAAK;AACtD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,GAAG,GAAG,CAAC,KAAK,KAAKC,KAAS,CAAC,OAAO,EAAE,KAAK;AACtD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,IAAI,GAAG,CAAC,KAAK,KAAKC,MAAU,CAAC,OAAO,EAAE,KAAK;AACxD;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;AACY,MAAC,KAAK,GAAG,CAAC,KAAK,KAAKC,OAAW,CAAC,OAAO,EAAE,KAAK;;;;"}
|