@aws-amplify/api-rest 4.0.1-console-preview.b5a42af.0 → 4.0.1-console-preview.9607e4a.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/{common → apis/common}/handler.d.ts +7 -7
- package/lib/{common → apis/common}/handler.js +5 -6
- package/{lib-esm → lib/apis}/common/internalPost.d.ts +1 -1
- package/lib/{common → apis/common}/internalPost.js +12 -1
- package/lib/apis/common/publicApis.d.ts +8 -0
- package/lib/apis/common/publicApis.js +50 -0
- package/lib/apis/index.d.ts +25 -0
- package/lib/apis/index.js +45 -0
- package/lib/apis/server.d.ts +26 -0
- package/lib/apis/server.js +49 -0
- package/lib/errors/validation.d.ts +2 -1
- package/lib/errors/validation.js +5 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +8 -1
- package/lib/internals/index.d.ts +1 -1
- package/lib/internals/index.js +2 -2
- package/lib/internals/server.d.ts +1 -1
- package/lib/internals/server.js +2 -2
- package/lib/server.d.ts +2 -0
- package/lib/server.js +14 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/index.d.ts +19 -8
- package/lib/utils/createCancellableOperation.d.ts +2 -1
- package/lib/utils/createCancellableOperation.js +29 -19
- package/lib/utils/index.d.ts +3 -1
- package/lib/utils/index.js +7 -3
- package/lib/utils/index.native.d.ts +6 -0
- package/lib/utils/index.native.js +19 -0
- package/lib/utils/logger.d.ts +2 -0
- package/lib/utils/logger.js +7 -0
- package/lib/utils/normalizeHeaders.d.ts +1 -1
- package/lib/utils/parseSigningInfo.d.ts +14 -0
- package/lib/utils/parseSigningInfo.js +42 -0
- package/lib/utils/resolveApiUrl.d.ts +12 -0
- package/lib/utils/resolveApiUrl.js +38 -0
- package/lib/utils/resolveCredentials.d.ts +2 -2
- package/lib/utils/resolveCredentials.js +1 -1
- package/lib/utils/serviceError.d.ts +1 -1
- package/lib/utils/serviceError.js +8 -6
- package/lib-esm/{common → apis/common}/handler.d.ts +7 -7
- package/lib-esm/{common → apis/common}/handler.js +5 -6
- package/{lib → lib-esm/apis}/common/internalPost.d.ts +1 -1
- package/lib-esm/{common → apis/common}/internalPost.js +12 -1
- package/lib-esm/apis/common/publicApis.d.ts +8 -0
- package/lib-esm/apis/common/publicApis.js +41 -0
- package/lib-esm/apis/index.d.ts +25 -0
- package/lib-esm/apis/index.js +36 -0
- package/lib-esm/apis/server.d.ts +26 -0
- package/lib-esm/apis/server.js +40 -0
- package/lib-esm/errors/validation.d.ts +2 -1
- package/lib-esm/errors/validation.js +5 -0
- package/lib-esm/index.d.ts +1 -0
- package/lib-esm/index.js +1 -0
- package/lib-esm/internals/index.d.ts +1 -1
- package/lib-esm/internals/index.js +2 -2
- package/lib-esm/internals/server.d.ts +1 -1
- package/lib-esm/internals/server.js +2 -2
- package/lib-esm/server.d.ts +2 -0
- package/lib-esm/server.js +4 -0
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/types/index.d.ts +19 -8
- package/lib-esm/utils/createCancellableOperation.d.ts +2 -1
- package/lib-esm/utils/createCancellableOperation.js +31 -21
- package/lib-esm/utils/index.d.ts +3 -1
- package/lib-esm/utils/index.js +3 -1
- package/lib-esm/utils/index.native.d.ts +6 -0
- package/lib-esm/utils/index.native.js +10 -0
- package/lib-esm/utils/logger.d.ts +2 -0
- package/lib-esm/utils/logger.js +4 -0
- package/lib-esm/utils/normalizeHeaders.d.ts +1 -1
- package/lib-esm/utils/parseSigningInfo.d.ts +14 -0
- package/lib-esm/utils/parseSigningInfo.js +38 -0
- package/lib-esm/utils/resolveApiUrl.d.ts +12 -0
- package/lib-esm/utils/resolveApiUrl.js +34 -0
- package/lib-esm/utils/resolveCredentials.d.ts +2 -2
- package/lib-esm/utils/resolveCredentials.js +1 -1
- package/lib-esm/utils/serviceError.d.ts +1 -1
- package/lib-esm/utils/serviceError.js +8 -6
- package/package.json +6 -7
- package/src/{common → apis/common}/handler.ts +8 -9
- package/src/{common → apis/common}/internalPost.ts +13 -2
- package/src/apis/common/publicApis.ts +99 -0
- package/src/apis/index.ts +60 -0
- package/src/apis/server.ts +83 -0
- package/src/errors/validation.ts +6 -0
- package/src/index.ts +1 -0
- package/src/internals/index.ts +5 -2
- package/src/internals/server.ts +5 -2
- package/src/server.ts +5 -0
- package/src/types/index.ts +19 -8
- package/src/utils/createCancellableOperation.ts +37 -19
- package/src/utils/index.native.ts +13 -0
- package/src/utils/index.ts +3 -1
- package/src/utils/logger.ts +6 -0
- package/src/utils/normalizeHeaders.ts +1 -1
- package/src/utils/{parseUrl.ts → parseSigningInfo.ts} +20 -7
- package/src/utils/resolveApiUrl.ts +47 -0
- package/src/utils/resolveCredentials.ts +1 -1
- package/src/utils/serviceError.ts +9 -7
- package/lib/utils/parseUrl.d.ts +0 -10
- package/lib/utils/parseUrl.js +0 -41
- package/lib-esm/utils/parseUrl.d.ts +0 -10
- package/lib-esm/utils/parseUrl.js +0 -37
|
@@ -6,40 +6,50 @@ exports.createCancellableOperation = void 0;
|
|
|
6
6
|
var tslib_1 = require("tslib");
|
|
7
7
|
var errors_1 = require("../errors");
|
|
8
8
|
var serviceError_1 = require("./serviceError");
|
|
9
|
+
var logger_1 = require("./logger");
|
|
9
10
|
/**
|
|
10
11
|
* @internal
|
|
11
12
|
*/
|
|
12
13
|
function createCancellableOperation(handler, abortController) {
|
|
13
14
|
var _this = this;
|
|
14
15
|
var isInternalPost = function (handler) { return !!abortController; };
|
|
15
|
-
|
|
16
|
+
// For creating a cancellable operation for public REST APIs, we need to create an AbortController
|
|
17
|
+
// internally. Whereas for internal POST APIs, we need to accept in the AbortController from the
|
|
18
|
+
// callers.
|
|
19
|
+
var publicApisAbortController = new AbortController();
|
|
20
|
+
var publicApisAbortSignal = publicApisAbortController.signal;
|
|
21
|
+
var internalPostAbortSignal = abortController === null || abortController === void 0 ? void 0 : abortController.signal;
|
|
16
22
|
var job = function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
17
|
-
var response, error_1;
|
|
23
|
+
var response, error_1, abortSignal, cancelledError;
|
|
18
24
|
var _a;
|
|
19
25
|
return tslib_1.__generator(this, function (_b) {
|
|
20
26
|
switch (_b.label) {
|
|
21
27
|
case 0:
|
|
22
|
-
_b.trys.push([0,
|
|
28
|
+
_b.trys.push([0, 4, , 5]);
|
|
23
29
|
return [4 /*yield*/, (isInternalPost(handler)
|
|
24
30
|
? handler()
|
|
25
|
-
: handler(
|
|
31
|
+
: handler(publicApisAbortSignal))];
|
|
26
32
|
case 1:
|
|
27
33
|
response = _b.sent();
|
|
28
|
-
if (response.statusCode >= 300)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
case
|
|
34
|
+
if (!(response.statusCode >= 300)) return [3 /*break*/, 3];
|
|
35
|
+
return [4 /*yield*/, (0, serviceError_1.parseRestApiServiceError)(response)];
|
|
36
|
+
case 2: throw _b.sent();
|
|
37
|
+
case 3: return [2 /*return*/, response];
|
|
38
|
+
case 4:
|
|
33
39
|
error_1 = _b.sent();
|
|
34
|
-
|
|
35
|
-
|
|
40
|
+
abortSignal = internalPostAbortSignal !== null && internalPostAbortSignal !== void 0 ? internalPostAbortSignal : publicApisAbortSignal;
|
|
41
|
+
if (error_1.name === 'AbortError' || (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) === true) {
|
|
42
|
+
cancelledError = new errors_1.CancelledError({
|
|
36
43
|
name: error_1.name,
|
|
37
|
-
message: (_a =
|
|
44
|
+
message: (_a = abortSignal.reason) !== null && _a !== void 0 ? _a : error_1.message,
|
|
38
45
|
underlyingError: error_1,
|
|
39
46
|
});
|
|
47
|
+
logger_1.logger.debug(error_1);
|
|
48
|
+
throw cancelledError;
|
|
40
49
|
}
|
|
41
|
-
|
|
42
|
-
|
|
50
|
+
logger_1.logger.debug(error_1);
|
|
51
|
+
throw error_1;
|
|
52
|
+
case 5: return [2 /*return*/];
|
|
43
53
|
}
|
|
44
54
|
});
|
|
45
55
|
}); };
|
|
@@ -48,15 +58,15 @@ function createCancellableOperation(handler, abortController) {
|
|
|
48
58
|
}
|
|
49
59
|
else {
|
|
50
60
|
var cancel = function (abortMessage) {
|
|
51
|
-
if (
|
|
61
|
+
if (publicApisAbortSignal.aborted === true) {
|
|
52
62
|
return;
|
|
53
63
|
}
|
|
54
|
-
|
|
64
|
+
publicApisAbortController.abort(abortMessage);
|
|
55
65
|
// Abort reason is not widely support enough across runtimes and and browsers, so we set it
|
|
56
66
|
// if it is not already set.
|
|
57
|
-
if (
|
|
58
|
-
|
|
59
|
-
|
|
67
|
+
if (publicApisAbortSignal.reason !== abortMessage) {
|
|
68
|
+
publicApisAbortSignal['reason'] =
|
|
69
|
+
abortMessage;
|
|
60
70
|
}
|
|
61
71
|
};
|
|
62
72
|
return { response: job(), cancel: cancel };
|
package/lib/utils/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
export { createCancellableOperation } from './createCancellableOperation';
|
|
2
2
|
export { resolveCredentials } from './resolveCredentials';
|
|
3
|
-
export {
|
|
3
|
+
export { parseSigningInfo } from './parseSigningInfo';
|
|
4
4
|
export { parseRestApiServiceError } from './serviceError';
|
|
5
|
+
export { resolveApiUrl } from './resolveApiUrl';
|
|
6
|
+
export { logger } from './logger';
|
package/lib/utils/index.js
CHANGED
|
@@ -2,12 +2,16 @@
|
|
|
2
2
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.parseRestApiServiceError = exports.
|
|
5
|
+
exports.logger = exports.resolveApiUrl = exports.parseRestApiServiceError = exports.parseSigningInfo = exports.resolveCredentials = exports.createCancellableOperation = void 0;
|
|
6
6
|
var createCancellableOperation_1 = require("./createCancellableOperation");
|
|
7
7
|
Object.defineProperty(exports, "createCancellableOperation", { enumerable: true, get: function () { return createCancellableOperation_1.createCancellableOperation; } });
|
|
8
8
|
var resolveCredentials_1 = require("./resolveCredentials");
|
|
9
9
|
Object.defineProperty(exports, "resolveCredentials", { enumerable: true, get: function () { return resolveCredentials_1.resolveCredentials; } });
|
|
10
|
-
var
|
|
11
|
-
Object.defineProperty(exports, "
|
|
10
|
+
var parseSigningInfo_1 = require("./parseSigningInfo");
|
|
11
|
+
Object.defineProperty(exports, "parseSigningInfo", { enumerable: true, get: function () { return parseSigningInfo_1.parseSigningInfo; } });
|
|
12
12
|
var serviceError_1 = require("./serviceError");
|
|
13
13
|
Object.defineProperty(exports, "parseRestApiServiceError", { enumerable: true, get: function () { return serviceError_1.parseRestApiServiceError; } });
|
|
14
|
+
var resolveApiUrl_1 = require("./resolveApiUrl");
|
|
15
|
+
Object.defineProperty(exports, "resolveApiUrl", { enumerable: true, get: function () { return resolveApiUrl_1.resolveApiUrl; } });
|
|
16
|
+
var logger_1 = require("./logger");
|
|
17
|
+
Object.defineProperty(exports, "logger", { enumerable: true, get: function () { return logger_1.logger; } });
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { createCancellableOperation } from './createCancellableOperation';
|
|
2
|
+
export { resolveCredentials } from './resolveCredentials';
|
|
3
|
+
export { parseSigningInfo } from './parseSigningInfo';
|
|
4
|
+
export { parseRestApiServiceError } from './serviceError';
|
|
5
|
+
export { resolveApiUrl } from './resolveApiUrl';
|
|
6
|
+
export { logger } from './logger';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.logger = exports.resolveApiUrl = exports.parseRestApiServiceError = exports.parseSigningInfo = exports.resolveCredentials = exports.createCancellableOperation = void 0;
|
|
6
|
+
var react_native_1 = require("@aws-amplify/react-native");
|
|
7
|
+
(0, react_native_1.loadUrlPolyfill)();
|
|
8
|
+
var createCancellableOperation_1 = require("./createCancellableOperation");
|
|
9
|
+
Object.defineProperty(exports, "createCancellableOperation", { enumerable: true, get: function () { return createCancellableOperation_1.createCancellableOperation; } });
|
|
10
|
+
var resolveCredentials_1 = require("./resolveCredentials");
|
|
11
|
+
Object.defineProperty(exports, "resolveCredentials", { enumerable: true, get: function () { return resolveCredentials_1.resolveCredentials; } });
|
|
12
|
+
var parseSigningInfo_1 = require("./parseSigningInfo");
|
|
13
|
+
Object.defineProperty(exports, "parseSigningInfo", { enumerable: true, get: function () { return parseSigningInfo_1.parseSigningInfo; } });
|
|
14
|
+
var serviceError_1 = require("./serviceError");
|
|
15
|
+
Object.defineProperty(exports, "parseRestApiServiceError", { enumerable: true, get: function () { return serviceError_1.parseRestApiServiceError; } });
|
|
16
|
+
var resolveApiUrl_1 = require("./resolveApiUrl");
|
|
17
|
+
Object.defineProperty(exports, "resolveApiUrl", { enumerable: true, get: function () { return resolveApiUrl_1.resolveApiUrl; } });
|
|
18
|
+
var logger_1 = require("./logger");
|
|
19
|
+
Object.defineProperty(exports, "logger", { enumerable: true, get: function () { return logger_1.logger; } });
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.logger = void 0;
|
|
6
|
+
var utils_1 = require("@aws-amplify/core/internals/utils");
|
|
7
|
+
exports.logger = new utils_1.Logger('RestApis');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const normalizeHeaders: (headers
|
|
1
|
+
export declare const normalizeHeaders: (headers?: Record<string, string>) => Record<string, string>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AmplifyClassV6 } from '@aws-amplify/core';
|
|
2
|
+
/**
|
|
3
|
+
* Infer the signing service and region from the given URL, and for REST API only, from the Amplify configuration.
|
|
4
|
+
* It supports raw API Gateway endpoint and AppSync endpoint.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export declare const parseSigningInfo: (url: URL, restApiOptions?: {
|
|
9
|
+
amplify: AmplifyClassV6;
|
|
10
|
+
apiName: string;
|
|
11
|
+
}) => {
|
|
12
|
+
service: string;
|
|
13
|
+
region: string;
|
|
14
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.parseSigningInfo = void 0;
|
|
6
|
+
var tslib_1 = require("tslib");
|
|
7
|
+
var constants_1 = require("./constants");
|
|
8
|
+
/**
|
|
9
|
+
* Infer the signing service and region from the given URL, and for REST API only, from the Amplify configuration.
|
|
10
|
+
* It supports raw API Gateway endpoint and AppSync endpoint.
|
|
11
|
+
*
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
var parseSigningInfo = function (url, restApiOptions) {
|
|
15
|
+
var _a, _b, _c, _d, _e;
|
|
16
|
+
var _f = (_d = (_c = (_b = (_a = restApiOptions === null || restApiOptions === void 0 ? void 0 : restApiOptions.amplify.getConfig()) === null || _a === void 0 ? void 0 : _a.API) === null || _b === void 0 ? void 0 : _b.REST) === null || _c === void 0 ? void 0 : _c[restApiOptions === null || restApiOptions === void 0 ? void 0 : restApiOptions.apiName]) !== null && _d !== void 0 ? _d : {}, _g = _f.service, signingService = _g === void 0 ? constants_1.DEFAULT_REST_IAM_SIGNING_SERVICE : _g, _h = _f.region, signingRegion = _h === void 0 ? constants_1.DEFAULT_IAM_SIGNING_REGION : _h;
|
|
17
|
+
var hostname = url.hostname;
|
|
18
|
+
var _j = tslib_1.__read((_e = constants_1.APIG_HOSTNAME_PATTERN.exec(hostname)) !== null && _e !== void 0 ? _e : [], 3), service = _j[1], region = _j[2];
|
|
19
|
+
if (service === constants_1.DEFAULT_REST_IAM_SIGNING_SERVICE) {
|
|
20
|
+
// The configured endpoint is an API Gateway endpoint
|
|
21
|
+
// @see: https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-call-api.html
|
|
22
|
+
return {
|
|
23
|
+
service: service,
|
|
24
|
+
region: region !== null && region !== void 0 ? region : signingRegion,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
else if (service === 'appsync-api') {
|
|
28
|
+
// AppSync endpoint is internally supported because GraphQL operation will send request using POST handler.
|
|
29
|
+
// example: https://xxxx.appsync-api.us-east-1.amazonaws.com/graphql
|
|
30
|
+
return {
|
|
31
|
+
service: 'appsync',
|
|
32
|
+
region: region !== null && region !== void 0 ? region : signingRegion,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
return {
|
|
37
|
+
service: signingService,
|
|
38
|
+
region: signingRegion,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
exports.parseSigningInfo = parseSigningInfo;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AmplifyClassV6 } from '@aws-amplify/core';
|
|
2
|
+
/**
|
|
3
|
+
* Resolve the REST API request URL by:
|
|
4
|
+
* 1. Loading the REST API endpoint from the Amplify configuration with corresponding API name.
|
|
5
|
+
* 2. Appending the path to the endpoint.
|
|
6
|
+
* 3. Merge the query parameters from path and the queryParameter argument which is taken from the public REST API
|
|
7
|
+
* options.
|
|
8
|
+
* 4. Validating the resulting URL string.
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export declare const resolveApiUrl: (amplify: AmplifyClassV6, apiName: string, path: string, queryParams?: Record<string, string>) => URL;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.resolveApiUrl = void 0;
|
|
6
|
+
var tslib_1 = require("tslib");
|
|
7
|
+
var errors_1 = require("../errors");
|
|
8
|
+
/**
|
|
9
|
+
* Resolve the REST API request URL by:
|
|
10
|
+
* 1. Loading the REST API endpoint from the Amplify configuration with corresponding API name.
|
|
11
|
+
* 2. Appending the path to the endpoint.
|
|
12
|
+
* 3. Merge the query parameters from path and the queryParameter argument which is taken from the public REST API
|
|
13
|
+
* options.
|
|
14
|
+
* 4. Validating the resulting URL string.
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
var resolveApiUrl = function (amplify, apiName, path, queryParams) {
|
|
19
|
+
var _a, _b, _c, _d;
|
|
20
|
+
var urlStr = (_d = (_c = (_b = (_a = amplify.getConfig()) === null || _a === void 0 ? void 0 : _a.API) === null || _b === void 0 ? void 0 : _b.REST) === null || _c === void 0 ? void 0 : _c[apiName]) === null || _d === void 0 ? void 0 : _d.endpoint;
|
|
21
|
+
(0, errors_1.assertValidationError)(!!urlStr, errors_1.RestApiValidationErrorCode.InvalidApiName);
|
|
22
|
+
try {
|
|
23
|
+
var url = new URL(urlStr + path);
|
|
24
|
+
if (queryParams) {
|
|
25
|
+
var mergedQueryParams_1 = new URLSearchParams(url.searchParams);
|
|
26
|
+
Object.entries(queryParams).forEach(function (_a) {
|
|
27
|
+
var _b = tslib_1.__read(_a, 2), key = _b[0], value = _b[1];
|
|
28
|
+
mergedQueryParams_1.set(key, value);
|
|
29
|
+
});
|
|
30
|
+
url.search = new URLSearchParams(mergedQueryParams_1).toString();
|
|
31
|
+
}
|
|
32
|
+
return url;
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
throw new errors_1.RestApiError(tslib_1.__assign(tslib_1.__assign({ name: errors_1.RestApiValidationErrorCode.InvalidApiName }, errors_1.validationErrorMap[errors_1.RestApiValidationErrorCode.InvalidApiName]), { recoverySuggestion: "Please make sure the REST endpoint URL is a valid URL string. Got ".concat(urlStr) }));
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
exports.resolveApiUrl = resolveApiUrl;
|
|
@@ -5,6 +5,6 @@ import { AmplifyClassV6 } from '@aws-amplify/core';
|
|
|
5
5
|
export declare const resolveCredentials: (amplify: AmplifyClassV6) => Promise<{
|
|
6
6
|
accessKeyId: string;
|
|
7
7
|
secretAccessKey: string;
|
|
8
|
-
sessionToken?: string;
|
|
9
|
-
expiration?: Date;
|
|
8
|
+
sessionToken?: string | undefined;
|
|
9
|
+
expiration?: Date | undefined;
|
|
10
10
|
}>;
|
|
@@ -15,7 +15,7 @@ var resolveCredentials = function (amplify) { return tslib_1.__awaiter(void 0, v
|
|
|
15
15
|
case 0: return [4 /*yield*/, amplify.Auth.fetchAuthSession()];
|
|
16
16
|
case 1:
|
|
17
17
|
credentials = (_a.sent()).credentials;
|
|
18
|
-
(0, errors_1.assertValidationError)(!!credentials, errors_1.RestApiValidationErrorCode.NoCredentials);
|
|
18
|
+
(0, errors_1.assertValidationError)(!!credentials && !!credentials.accessKeyId && !!credentials.secretAccessKey, errors_1.RestApiValidationErrorCode.NoCredentials);
|
|
19
19
|
return [2 /*return*/, credentials];
|
|
20
20
|
}
|
|
21
21
|
});
|
|
@@ -7,4 +7,4 @@ import { RestApiError } from '../errors';
|
|
|
7
7
|
* @internal
|
|
8
8
|
*/
|
|
9
9
|
export declare const buildRestApiServiceError: (error: Error) => RestApiError;
|
|
10
|
-
export declare const parseRestApiServiceError: (response?: HttpResponse) => Promise<RestApiError & MetadataBearer>;
|
|
10
|
+
export declare const parseRestApiServiceError: (response?: HttpResponse) => Promise<(RestApiError & MetadataBearer) | undefined>;
|
|
@@ -11,7 +11,7 @@ var errors_1 = require("../errors");
|
|
|
11
11
|
*/
|
|
12
12
|
var buildRestApiServiceError = function (error) {
|
|
13
13
|
var restApiError = new errors_1.RestApiError({
|
|
14
|
-
name: error.name,
|
|
14
|
+
name: error === null || error === void 0 ? void 0 : error.name,
|
|
15
15
|
message: error.message,
|
|
16
16
|
underlyingError: error,
|
|
17
17
|
});
|
|
@@ -25,11 +25,13 @@ var parseRestApiServiceError = function (response) { return tslib_1.__awaiter(vo
|
|
|
25
25
|
case 0: return [4 /*yield*/, (0, aws_client_utils_1.parseJsonError)(response)];
|
|
26
26
|
case 1:
|
|
27
27
|
parsedError = _a.sent();
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
if (!parsedError) {
|
|
29
|
+
// Response is not an error.
|
|
30
|
+
return [2 /*return*/];
|
|
31
|
+
}
|
|
32
|
+
return [2 /*return*/, Object.assign((0, exports.buildRestApiServiceError)(parsedError), {
|
|
33
|
+
$metadata: parsedError.$metadata,
|
|
34
|
+
})];
|
|
33
35
|
}
|
|
34
36
|
});
|
|
35
37
|
}); };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AmplifyClassV6 } from '@aws-amplify/core';
|
|
2
2
|
import { HttpRequest, Headers } from '@aws-amplify/core/internals/aws-client-utils';
|
|
3
3
|
import { DocumentType } from '@aws-amplify/core/internals/utils';
|
|
4
|
+
import { RestApiResponse } from '../../types';
|
|
4
5
|
type HandlerOptions = Omit<HttpRequest, 'body' | 'headers'> & {
|
|
5
6
|
body?: DocumentType | FormData;
|
|
6
7
|
headers?: Headers;
|
|
@@ -15,17 +16,16 @@ type SigningServiceInfo = {
|
|
|
15
16
|
* @param amplify Amplify instance to to resolve credentials and tokens. Should use different instance in client-side
|
|
16
17
|
* and SSR
|
|
17
18
|
* @param options Options accepted from public API options when calling the handlers.
|
|
18
|
-
* @param signingServiceInfo Internal-only options
|
|
19
|
-
*
|
|
20
|
-
* used.
|
|
19
|
+
* @param signingServiceInfo Internal-only options enable IAM auth as well as to to overwrite the IAM signing service
|
|
20
|
+
* and region. If specified, and NONE of API Key header or Auth header is present, IAM auth will be used.
|
|
21
21
|
*
|
|
22
22
|
* @internal
|
|
23
23
|
*/
|
|
24
24
|
export declare const transferHandler: (amplify: AmplifyClassV6, options: Omit<HttpRequest, "body" | "headers"> & {
|
|
25
|
-
body?: DocumentType |
|
|
26
|
-
headers?: Headers;
|
|
27
|
-
withCredentials?: boolean;
|
|
25
|
+
body?: FormData | DocumentType | undefined;
|
|
26
|
+
headers?: Headers | undefined;
|
|
27
|
+
withCredentials?: boolean | undefined;
|
|
28
28
|
} & {
|
|
29
29
|
abortSignal: AbortSignal;
|
|
30
|
-
}, signingServiceInfo?: SigningServiceInfo) => Promise<
|
|
30
|
+
}, signingServiceInfo?: SigningServiceInfo) => Promise<RestApiResponse>;
|
|
31
31
|
export {};
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { __assign, __awaiter, __generator } from "tslib";
|
|
2
2
|
import { unauthenticatedHandler, getRetryDecider, jitteredBackoff, authenticatedHandler, } from '@aws-amplify/core/internals/aws-client-utils';
|
|
3
|
-
import { parseRestApiServiceError,
|
|
4
|
-
import { normalizeHeaders } from '
|
|
3
|
+
import { parseRestApiServiceError, parseSigningInfo, resolveCredentials, } from '../../utils';
|
|
4
|
+
import { normalizeHeaders } from '../../utils/normalizeHeaders';
|
|
5
5
|
/**
|
|
6
6
|
* Make REST API call with best-effort IAM auth.
|
|
7
7
|
* @param amplify Amplify instance to to resolve credentials and tokens. Should use different instance in client-side
|
|
8
8
|
* and SSR
|
|
9
9
|
* @param options Options accepted from public API options when calling the handlers.
|
|
10
|
-
* @param signingServiceInfo Internal-only options
|
|
11
|
-
*
|
|
12
|
-
* used.
|
|
10
|
+
* @param signingServiceInfo Internal-only options enable IAM auth as well as to to overwrite the IAM signing service
|
|
11
|
+
* and region. If specified, and NONE of API Key header or Auth header is present, IAM auth will be used.
|
|
13
12
|
*
|
|
14
13
|
* @internal
|
|
15
14
|
*/
|
|
@@ -46,7 +45,7 @@ export var transferHandler = function (amplify, options, signingServiceInfo) { r
|
|
|
46
45
|
};
|
|
47
46
|
isIamAuthApplicable = iamAuthApplicable(request, signingServiceInfo);
|
|
48
47
|
if (!isIamAuthApplicable) return [3 /*break*/, 3];
|
|
49
|
-
signingInfoFromUrl =
|
|
48
|
+
signingInfoFromUrl = parseSigningInfo(url);
|
|
50
49
|
signingService = (_a = signingServiceInfo === null || signingServiceInfo === void 0 ? void 0 : signingServiceInfo.service) !== null && _a !== void 0 ? _a : signingInfoFromUrl.service;
|
|
51
50
|
signingRegion = (_b = signingServiceInfo === null || signingServiceInfo === void 0 ? void 0 : signingServiceInfo.region) !== null && _b !== void 0 ? _b : signingInfoFromUrl.region;
|
|
52
51
|
return [4 /*yield*/, resolveCredentials(amplify)];
|
|
@@ -2,7 +2,18 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { __assign, __awaiter, __generator } from "tslib";
|
|
4
4
|
import { transferHandler } from './handler';
|
|
5
|
-
import { createCancellableOperation } from '
|
|
5
|
+
import { createCancellableOperation } from '../../utils';
|
|
6
|
+
/**
|
|
7
|
+
* This weak map provides functionality to cancel a request given the promise containing the `post` request.
|
|
8
|
+
*
|
|
9
|
+
* 1. For every GraphQL POST request, an abort controller is created and supplied to the request.
|
|
10
|
+
* 2. The promise fulfilled by GraphGL POST request is then mapped to that abort controller.
|
|
11
|
+
* 3. The promise is returned to the external caller.
|
|
12
|
+
* 4. The caller can either wait for the promise to fulfill or call `cancel(promise)` to cancel the request.
|
|
13
|
+
* 5. If `cancel(promise)` is called, then the corresponding abort controller is retrieved from the map below.
|
|
14
|
+
* 6. GraphQL POST request will be rejected with the error message provided during cancel.
|
|
15
|
+
* 7. Caller can check if the error is because of cancelling by calling `isCancelError(error)`.
|
|
16
|
+
*/
|
|
6
17
|
var cancelTokenMap = new WeakMap();
|
|
7
18
|
/**
|
|
8
19
|
* @internal
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AmplifyClassV6 } from '@aws-amplify/core';
|
|
2
|
+
import { GetInput, GetOperation, PostInput, PostOperation, PutInput, PutOperation, DeleteInput, DeleteOperation, HeadInput, HeadOperation, PatchInput, PatchOperation } from '../../types';
|
|
3
|
+
export declare const get: (amplify: AmplifyClassV6, input: GetInput) => GetOperation;
|
|
4
|
+
export declare const post: (amplify: AmplifyClassV6, input: PostInput) => PostOperation;
|
|
5
|
+
export declare const put: (amplify: AmplifyClassV6, input: PutInput) => PutOperation;
|
|
6
|
+
export declare const del: (amplify: AmplifyClassV6, input: DeleteInput) => DeleteOperation;
|
|
7
|
+
export declare const head: (amplify: AmplifyClassV6, input: HeadInput) => HeadOperation;
|
|
8
|
+
export declare const patch: (amplify: AmplifyClassV6, input: PatchInput) => PatchOperation;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { __assign, __awaiter, __generator } from "tslib";
|
|
4
|
+
import { resolveApiUrl, createCancellableOperation, logger, parseSigningInfo, } from '../../utils';
|
|
5
|
+
import { transferHandler } from './handler';
|
|
6
|
+
var publicHandler = function (amplify, options, method) {
|
|
7
|
+
return createCancellableOperation(function (abortSignal) { return __awaiter(void 0, void 0, void 0, function () {
|
|
8
|
+
var apiName, _a, apiOptions, apiPath, url, libraryOptionsHeaders, _b, invocationHeaders, headers, signingServiceInfo;
|
|
9
|
+
var _c, _d, _e, _f;
|
|
10
|
+
return __generator(this, function (_g) {
|
|
11
|
+
switch (_g.label) {
|
|
12
|
+
case 0:
|
|
13
|
+
apiName = options.apiName, _a = options.options, apiOptions = _a === void 0 ? {} : _a, apiPath = options.path;
|
|
14
|
+
url = resolveApiUrl(amplify, apiName, apiPath, apiOptions === null || apiOptions === void 0 ? void 0 : apiOptions.queryParams);
|
|
15
|
+
return [4 /*yield*/, ((_f = (_e = (_d = (_c = amplify.libraryOptions) === null || _c === void 0 ? void 0 : _c.API) === null || _d === void 0 ? void 0 : _d.REST) === null || _e === void 0 ? void 0 : _e.headers) === null || _f === void 0 ? void 0 : _f.call(_e, {
|
|
16
|
+
apiName: apiName,
|
|
17
|
+
}))];
|
|
18
|
+
case 1:
|
|
19
|
+
libraryOptionsHeaders = _g.sent();
|
|
20
|
+
_b = apiOptions.headers, invocationHeaders = _b === void 0 ? {} : _b;
|
|
21
|
+
headers = __assign(__assign({}, libraryOptionsHeaders), invocationHeaders);
|
|
22
|
+
signingServiceInfo = parseSigningInfo(url, {
|
|
23
|
+
amplify: amplify,
|
|
24
|
+
apiName: apiName,
|
|
25
|
+
});
|
|
26
|
+
logger.debug(method, url, headers, "IAM signing options: ".concat(JSON.stringify(signingServiceInfo)));
|
|
27
|
+
return [2 /*return*/, transferHandler(amplify, __assign(__assign({}, apiOptions), { url: url, method: method, headers: headers, abortSignal: abortSignal }), signingServiceInfo)];
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}); });
|
|
31
|
+
};
|
|
32
|
+
export var get = function (amplify, input) {
|
|
33
|
+
return publicHandler(amplify, input, 'GET');
|
|
34
|
+
};
|
|
35
|
+
export var post = function (amplify, input) { return publicHandler(amplify, input, 'POST'); };
|
|
36
|
+
export var put = function (amplify, input) {
|
|
37
|
+
return publicHandler(amplify, input, 'PUT');
|
|
38
|
+
};
|
|
39
|
+
export var del = function (amplify, input) { return publicHandler(amplify, input, 'DELETE'); };
|
|
40
|
+
export var head = function (amplify, input) { return publicHandler(amplify, input, 'HEAD'); };
|
|
41
|
+
export var patch = function (amplify, input) { return publicHandler(amplify, input, 'PATCH'); };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { DeleteInput, DeleteOperation, GetInput, GetOperation, HeadInput, HeadOperation, PatchInput, PatchOperation, PostInput, PostOperation, PutInput, PutOperation } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* GET HTTP request
|
|
4
|
+
*/
|
|
5
|
+
export declare const get: (input: GetInput) => GetOperation;
|
|
6
|
+
/**
|
|
7
|
+
* POST HTTP request
|
|
8
|
+
*/
|
|
9
|
+
export declare const post: (input: PostInput) => PostOperation;
|
|
10
|
+
/**
|
|
11
|
+
* PUT HTTP request
|
|
12
|
+
*/
|
|
13
|
+
export declare const put: (input: PutInput) => PutOperation;
|
|
14
|
+
/**
|
|
15
|
+
* DELETE HTTP request
|
|
16
|
+
*/
|
|
17
|
+
export declare const del: (input: DeleteInput) => DeleteOperation;
|
|
18
|
+
/**
|
|
19
|
+
* HEAD HTTP request
|
|
20
|
+
*/
|
|
21
|
+
export declare const head: (input: HeadInput) => HeadOperation;
|
|
22
|
+
/**
|
|
23
|
+
* PATCH HTTP request
|
|
24
|
+
*/
|
|
25
|
+
export declare const patch: (input: PatchInput) => PatchOperation;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { Amplify } from '@aws-amplify/core';
|
|
4
|
+
import { get as commonGet, post as commonPost, put as commonPut, del as commonDel, head as commonHead, patch as commonPatch, } from './common/publicApis';
|
|
5
|
+
/**
|
|
6
|
+
* GET HTTP request
|
|
7
|
+
*/
|
|
8
|
+
export var get = function (input) { return commonGet(Amplify, input); };
|
|
9
|
+
/**
|
|
10
|
+
* POST HTTP request
|
|
11
|
+
*/
|
|
12
|
+
export var post = function (input) {
|
|
13
|
+
return commonPost(Amplify, input);
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* PUT HTTP request
|
|
17
|
+
*/
|
|
18
|
+
export var put = function (input) { return commonPut(Amplify, input); };
|
|
19
|
+
/**
|
|
20
|
+
* DELETE HTTP request
|
|
21
|
+
*/
|
|
22
|
+
export var del = function (input) {
|
|
23
|
+
return commonDel(Amplify, input);
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* HEAD HTTP request
|
|
27
|
+
*/
|
|
28
|
+
export var head = function (input) {
|
|
29
|
+
return commonHead(Amplify, input);
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* PATCH HTTP request
|
|
33
|
+
*/
|
|
34
|
+
export var patch = function (input) {
|
|
35
|
+
return commonPatch(Amplify, input);
|
|
36
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { AmplifyServer } from '@aws-amplify/core/internals/adapter-core';
|
|
2
|
+
import { DeleteInput, DeleteOperation, GetInput, GetOperation, HeadInput, HeadOperation, PatchInput, PatchOperation, PostInput, PostOperation, PutInput, PutOperation } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* GET HTTP request (server-side)
|
|
5
|
+
*/
|
|
6
|
+
export declare const get: (contextSpec: AmplifyServer.ContextSpec, input: GetInput) => GetOperation;
|
|
7
|
+
/**
|
|
8
|
+
* POST HTTP request (server-side)
|
|
9
|
+
*/
|
|
10
|
+
export declare const post: (contextSpec: AmplifyServer.ContextSpec, input: PostInput) => PostOperation;
|
|
11
|
+
/**
|
|
12
|
+
* PUT HTTP request (server-side)
|
|
13
|
+
*/
|
|
14
|
+
export declare const put: (contextSpec: AmplifyServer.ContextSpec, input: PutInput) => PutOperation;
|
|
15
|
+
/**
|
|
16
|
+
* DELETE HTTP request (server-side)
|
|
17
|
+
*/
|
|
18
|
+
export declare const del: (contextSpec: AmplifyServer.ContextSpec, input: DeleteInput) => DeleteOperation;
|
|
19
|
+
/**
|
|
20
|
+
* HEAD HTTP request (server-side)
|
|
21
|
+
*/
|
|
22
|
+
export declare const head: (contextSpec: AmplifyServer.ContextSpec, input: HeadInput) => HeadOperation;
|
|
23
|
+
/**
|
|
24
|
+
* PATCH HTTP request (server-side)
|
|
25
|
+
*/
|
|
26
|
+
export declare const patch: (contextSpec: AmplifyServer.ContextSpec, input: PatchInput) => PatchOperation;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { getAmplifyServerContext, } from '@aws-amplify/core/internals/adapter-core';
|
|
4
|
+
import { get as commonGet, post as commonPost, put as commonPut, del as commonDel, head as commonHead, patch as commonPatch, } from './common/publicApis';
|
|
5
|
+
/**
|
|
6
|
+
* GET HTTP request (server-side)
|
|
7
|
+
*/
|
|
8
|
+
export var get = function (contextSpec, input) {
|
|
9
|
+
return commonGet(getAmplifyServerContext(contextSpec).amplify, input);
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* POST HTTP request (server-side)
|
|
13
|
+
*/
|
|
14
|
+
export var post = function (contextSpec, input) {
|
|
15
|
+
return commonPost(getAmplifyServerContext(contextSpec).amplify, input);
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* PUT HTTP request (server-side)
|
|
19
|
+
*/
|
|
20
|
+
export var put = function (contextSpec, input) {
|
|
21
|
+
return commonPut(getAmplifyServerContext(contextSpec).amplify, input);
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* DELETE HTTP request (server-side)
|
|
25
|
+
*/
|
|
26
|
+
export var del = function (contextSpec, input) {
|
|
27
|
+
return commonDel(getAmplifyServerContext(contextSpec).amplify, input);
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* HEAD HTTP request (server-side)
|
|
31
|
+
*/
|
|
32
|
+
export var head = function (contextSpec, input) {
|
|
33
|
+
return commonHead(getAmplifyServerContext(contextSpec).amplify, input);
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* PATCH HTTP request (server-side)
|
|
37
|
+
*/
|
|
38
|
+
export var patch = function (contextSpec, input) {
|
|
39
|
+
return commonPatch(getAmplifyServerContext(contextSpec).amplify, input);
|
|
40
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AmplifyErrorMap } from '@aws-amplify/core/internals/utils';
|
|
2
2
|
export declare enum RestApiValidationErrorCode {
|
|
3
|
-
NoCredentials = "NoCredentials"
|
|
3
|
+
NoCredentials = "NoCredentials",
|
|
4
|
+
InvalidApiName = "InvalidApiName"
|
|
4
5
|
}
|
|
5
6
|
export declare const validationErrorMap: AmplifyErrorMap<RestApiValidationErrorCode>;
|
|
@@ -4,9 +4,14 @@ var _a;
|
|
|
4
4
|
export var RestApiValidationErrorCode;
|
|
5
5
|
(function (RestApiValidationErrorCode) {
|
|
6
6
|
RestApiValidationErrorCode["NoCredentials"] = "NoCredentials";
|
|
7
|
+
RestApiValidationErrorCode["InvalidApiName"] = "InvalidApiName";
|
|
7
8
|
})(RestApiValidationErrorCode || (RestApiValidationErrorCode = {}));
|
|
8
9
|
export var validationErrorMap = (_a = {},
|
|
9
10
|
_a[RestApiValidationErrorCode.NoCredentials] = {
|
|
10
11
|
message: 'Credentials should not be empty.',
|
|
11
12
|
},
|
|
13
|
+
_a[RestApiValidationErrorCode.InvalidApiName] = {
|
|
14
|
+
message: 'API name is invalid.',
|
|
15
|
+
recoverySuggestion: 'Check if the API name matches the one in your configuration or `aws-exports.js`',
|
|
16
|
+
},
|
|
12
17
|
_a);
|