@aws-amplify/api-rest 4.0.1-console-preview.deaebd5.0 → 4.0.1-console-preview.b5a42af.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/handler.d.ts +31 -0
- package/lib/common/handler.js +69 -0
- package/lib/common/internalPost.d.ts +16 -0
- package/lib/common/internalPost.js +54 -0
- package/lib/errors/CancelledError.d.ts +14 -0
- package/lib/errors/CancelledError.js +31 -0
- package/lib/errors/RestApiError.d.ts +4 -0
- package/lib/errors/RestApiError.js +19 -0
- package/lib/errors/assertValidatonError.d.ts +5 -0
- package/lib/errors/assertValidatonError.js +17 -0
- package/lib/errors/index.d.ts +4 -0
- package/lib/errors/index.js +15 -0
- package/lib/errors/validation.d.ts +5 -0
- package/lib/errors/validation.js +15 -0
- package/lib/index.d.ts +1 -2
- package/lib/index.js +3 -5
- package/lib/internals/index.d.ts +19 -0
- package/lib/internals/index.js +30 -0
- package/lib/internals/server.d.ts +20 -0
- package/lib/internals/server.js +30 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/index.d.ts +83 -50
- package/lib/types/index.js +0 -23
- package/lib/utils/constants.d.ts +8 -0
- package/lib/utils/constants.js +13 -0
- package/lib/utils/createCancellableOperation.d.ts +11 -0
- package/lib/utils/createCancellableOperation.js +65 -0
- package/lib/utils/index.d.ts +4 -0
- package/lib/utils/index.js +13 -0
- package/lib/utils/normalizeHeaders.d.ts +1 -0
- package/lib/utils/normalizeHeaders.js +13 -0
- package/lib/utils/parseUrl.d.ts +10 -0
- package/lib/utils/parseUrl.js +41 -0
- package/lib/utils/resolveCredentials.d.ts +10 -0
- package/lib/utils/resolveCredentials.js +23 -0
- package/lib/utils/serviceError.d.ts +10 -0
- package/lib/utils/serviceError.js +36 -0
- package/lib-esm/common/handler.d.ts +31 -0
- package/lib-esm/common/handler.js +65 -0
- package/lib-esm/common/internalPost.d.ts +16 -0
- package/lib-esm/common/internalPost.js +48 -0
- package/lib-esm/errors/CancelledError.d.ts +14 -0
- package/lib-esm/errors/CancelledError.js +27 -0
- package/lib-esm/errors/RestApiError.d.ts +4 -0
- package/lib-esm/errors/RestApiError.js +16 -0
- package/lib-esm/errors/assertValidatonError.d.ts +5 -0
- package/lib-esm/errors/assertValidatonError.js +13 -0
- package/lib-esm/errors/index.d.ts +4 -0
- package/lib-esm/errors/index.js +6 -0
- package/lib-esm/errors/validation.d.ts +5 -0
- package/lib-esm/errors/validation.js +12 -0
- package/lib-esm/index.d.ts +1 -2
- package/lib-esm/index.js +1 -1
- package/lib-esm/internals/index.d.ts +19 -0
- package/lib-esm/internals/index.js +24 -0
- package/lib-esm/internals/server.d.ts +20 -0
- package/lib-esm/internals/server.js +24 -0
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/types/index.d.ts +83 -50
- package/lib-esm/types/index.js +1 -22
- package/lib-esm/utils/constants.d.ts +8 -0
- package/lib-esm/utils/constants.js +10 -0
- package/lib-esm/utils/createCancellableOperation.d.ts +11 -0
- package/lib-esm/utils/createCancellableOperation.js +61 -0
- package/lib-esm/utils/index.d.ts +4 -0
- package/lib-esm/utils/index.js +6 -0
- package/lib-esm/utils/normalizeHeaders.d.ts +1 -0
- package/lib-esm/utils/normalizeHeaders.js +9 -0
- package/lib-esm/utils/parseUrl.d.ts +10 -0
- package/lib-esm/utils/parseUrl.js +37 -0
- package/lib-esm/utils/resolveCredentials.d.ts +10 -0
- package/lib-esm/utils/resolveCredentials.js +19 -0
- package/lib-esm/utils/serviceError.d.ts +10 -0
- package/lib-esm/utils/serviceError.js +31 -0
- package/package.json +4 -4
- package/src/common/handler.ts +103 -0
- package/src/common/internalPost.ts +70 -0
- package/src/errors/CancelledError.ts +26 -0
- package/src/errors/RestApiError.ts +17 -0
- package/src/errors/assertValidatonError.ts +19 -0
- package/src/errors/index.ts +7 -0
- package/src/errors/validation.ts +14 -0
- package/src/index.ts +1 -2
- package/src/internals/index.ts +28 -0
- package/src/internals/server.ts +34 -0
- package/src/types/index.ts +87 -61
- package/src/utils/constants.ts +15 -0
- package/src/utils/createCancellableOperation.ts +77 -0
- package/src/utils/index.ts +7 -0
- package/src/utils/normalizeHeaders.ts +10 -0
- package/src/utils/parseUrl.ts +39 -0
- package/src/utils/resolveCredentials.ts +17 -0
- package/src/utils/serviceError.ts +33 -0
- package/lib/API.d.ts +0 -4
- package/lib/API.js +0 -19
- package/lib/RestClient.d.ts +0 -115
- package/lib/RestClient.js +0 -318
- package/lib-esm/API.d.ts +0 -4
- package/lib-esm/API.js +0 -13
- package/lib-esm/RestClient.d.ts +0 -115
- package/lib-esm/RestClient.js +0 -315
- package/src/API.ts +0 -17
- package/src/RestClient.ts +0 -362
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { AmplifyClassV6 } from '@aws-amplify/core';
|
|
2
|
+
import { HttpRequest, Headers } from '@aws-amplify/core/internals/aws-client-utils';
|
|
3
|
+
import { DocumentType } from '@aws-amplify/core/internals/utils';
|
|
4
|
+
type HandlerOptions = Omit<HttpRequest, 'body' | 'headers'> & {
|
|
5
|
+
body?: DocumentType | FormData;
|
|
6
|
+
headers?: Headers;
|
|
7
|
+
withCredentials?: boolean;
|
|
8
|
+
};
|
|
9
|
+
type SigningServiceInfo = {
|
|
10
|
+
service?: string;
|
|
11
|
+
region?: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Make REST API call with best-effort IAM auth.
|
|
15
|
+
* @param amplify Amplify instance to to resolve credentials and tokens. Should use different instance in client-side
|
|
16
|
+
* and SSR
|
|
17
|
+
* @param options Options accepted from public API options when calling the handlers.
|
|
18
|
+
* @param signingServiceInfo Internal-only options for graphql client to overwrite the IAM signing service and region.
|
|
19
|
+
* MUST ONLY be used by internal post method consumed by GraphQL when auth mode is IAM. Otherwise IAM auth may not be
|
|
20
|
+
* used.
|
|
21
|
+
*
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export declare const transferHandler: (amplify: AmplifyClassV6, options: Omit<HttpRequest, "body" | "headers"> & {
|
|
25
|
+
body?: DocumentType | FormData;
|
|
26
|
+
headers?: Headers;
|
|
27
|
+
withCredentials?: boolean;
|
|
28
|
+
} & {
|
|
29
|
+
abortSignal: AbortSignal;
|
|
30
|
+
}, signingServiceInfo?: SigningServiceInfo) => Promise<import("@aws-amplify/core/internals/aws-client-utils").HttpResponse>;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.transferHandler = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var aws_client_utils_1 = require("@aws-amplify/core/internals/aws-client-utils");
|
|
6
|
+
var utils_1 = require("../utils");
|
|
7
|
+
var normalizeHeaders_1 = require("../utils/normalizeHeaders");
|
|
8
|
+
/**
|
|
9
|
+
* Make REST API call with best-effort IAM auth.
|
|
10
|
+
* @param amplify Amplify instance to to resolve credentials and tokens. Should use different instance in client-side
|
|
11
|
+
* and SSR
|
|
12
|
+
* @param options Options accepted from public API options when calling the handlers.
|
|
13
|
+
* @param signingServiceInfo Internal-only options for graphql client to overwrite the IAM signing service and region.
|
|
14
|
+
* MUST ONLY be used by internal post method consumed by GraphQL when auth mode is IAM. Otherwise IAM auth may not be
|
|
15
|
+
* used.
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
var transferHandler = function (amplify, options, signingServiceInfo) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
20
|
+
var url, method, headers, body, withCredentials, abortSignal, resolvedBody, resolvedHeaders, request, baseOptions, isIamAuthApplicable, signingInfoFromUrl, signingService, signingRegion, credentials;
|
|
21
|
+
var _a, _b;
|
|
22
|
+
return tslib_1.__generator(this, function (_c) {
|
|
23
|
+
switch (_c.label) {
|
|
24
|
+
case 0:
|
|
25
|
+
url = options.url, method = options.method, headers = options.headers, body = options.body, withCredentials = options.withCredentials, abortSignal = options.abortSignal;
|
|
26
|
+
resolvedBody = body
|
|
27
|
+
? body instanceof FormData
|
|
28
|
+
? body
|
|
29
|
+
: JSON.stringify(body !== null && body !== void 0 ? body : '')
|
|
30
|
+
: undefined;
|
|
31
|
+
resolvedHeaders = tslib_1.__assign(tslib_1.__assign({}, (0, normalizeHeaders_1.normalizeHeaders)(headers)), (resolvedBody
|
|
32
|
+
? {
|
|
33
|
+
'content-type': body instanceof FormData
|
|
34
|
+
? 'multipart/form-data'
|
|
35
|
+
: 'application/json; charset=UTF-8',
|
|
36
|
+
}
|
|
37
|
+
: {}));
|
|
38
|
+
request = {
|
|
39
|
+
url: url,
|
|
40
|
+
headers: resolvedHeaders,
|
|
41
|
+
method: method,
|
|
42
|
+
body: resolvedBody,
|
|
43
|
+
};
|
|
44
|
+
baseOptions = {
|
|
45
|
+
retryDecider: (0, aws_client_utils_1.getRetryDecider)(utils_1.parseRestApiServiceError),
|
|
46
|
+
computeDelay: aws_client_utils_1.jitteredBackoff,
|
|
47
|
+
withCrossDomainCredentials: withCredentials,
|
|
48
|
+
abortSignal: abortSignal,
|
|
49
|
+
};
|
|
50
|
+
isIamAuthApplicable = iamAuthApplicable(request, signingServiceInfo);
|
|
51
|
+
if (!isIamAuthApplicable) return [3 /*break*/, 3];
|
|
52
|
+
signingInfoFromUrl = (0, utils_1.parseUrl)(url);
|
|
53
|
+
signingService = (_a = signingServiceInfo === null || signingServiceInfo === void 0 ? void 0 : signingServiceInfo.service) !== null && _a !== void 0 ? _a : signingInfoFromUrl.service;
|
|
54
|
+
signingRegion = (_b = signingServiceInfo === null || signingServiceInfo === void 0 ? void 0 : signingServiceInfo.region) !== null && _b !== void 0 ? _b : signingInfoFromUrl.region;
|
|
55
|
+
return [4 /*yield*/, (0, utils_1.resolveCredentials)(amplify)];
|
|
56
|
+
case 1:
|
|
57
|
+
credentials = _c.sent();
|
|
58
|
+
return [4 /*yield*/, (0, aws_client_utils_1.authenticatedHandler)(request, tslib_1.__assign(tslib_1.__assign({}, baseOptions), { credentials: credentials, region: signingRegion, service: signingService }))];
|
|
59
|
+
case 2: return [2 /*return*/, _c.sent()];
|
|
60
|
+
case 3: return [4 /*yield*/, (0, aws_client_utils_1.unauthenticatedHandler)(request, tslib_1.__assign({}, baseOptions))];
|
|
61
|
+
case 4: return [2 /*return*/, _c.sent()];
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}); };
|
|
65
|
+
exports.transferHandler = transferHandler;
|
|
66
|
+
var iamAuthApplicable = function (_a, signingServiceInfo) {
|
|
67
|
+
var headers = _a.headers;
|
|
68
|
+
return !headers.authorization && !headers['x-api-key'] && !!signingServiceInfo;
|
|
69
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AmplifyClassV6 } from '@aws-amplify/core';
|
|
2
|
+
import { InternalPostInput, RestApiResponse } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export declare const post: (amplify: AmplifyClassV6, { url, options, abortController }: InternalPostInput) => Promise<RestApiResponse>;
|
|
7
|
+
/**
|
|
8
|
+
* Cancels a request given the promise returned by `post`.
|
|
9
|
+
* If the request is already completed, this function does nothing.
|
|
10
|
+
* It MUST be used after `updateRequestToBeCancellable` is called.
|
|
11
|
+
*/
|
|
12
|
+
export declare const cancel: (promise: Promise<RestApiResponse>, message?: string) => boolean;
|
|
13
|
+
/**
|
|
14
|
+
* MUST be used to make a promise including internal `post` API call cancellable.
|
|
15
|
+
*/
|
|
16
|
+
export declare const updateRequestToBeCancellable: (promise: Promise<any>, controller: AbortController) => void;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.updateRequestToBeCancellable = exports.cancel = exports.post = void 0;
|
|
6
|
+
var tslib_1 = require("tslib");
|
|
7
|
+
var handler_1 = require("./handler");
|
|
8
|
+
var utils_1 = require("../utils");
|
|
9
|
+
var cancelTokenMap = new WeakMap();
|
|
10
|
+
/**
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
var post = function (amplify, _a) {
|
|
14
|
+
var url = _a.url, options = _a.options, abortController = _a.abortController;
|
|
15
|
+
var controller = abortController !== null && abortController !== void 0 ? abortController : new AbortController();
|
|
16
|
+
var responsePromise = (0, utils_1.createCancellableOperation)(function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
|
|
17
|
+
var response;
|
|
18
|
+
return tslib_1.__generator(this, function (_a) {
|
|
19
|
+
response = (0, handler_1.transferHandler)(amplify, tslib_1.__assign(tslib_1.__assign({ url: url, method: 'POST' }, options), { abortSignal: controller.signal }), options === null || options === void 0 ? void 0 : options.signingServiceInfo);
|
|
20
|
+
return [2 /*return*/, response];
|
|
21
|
+
});
|
|
22
|
+
}); }, controller);
|
|
23
|
+
var responseWithCleanUp = responsePromise.finally(function () {
|
|
24
|
+
cancelTokenMap.delete(responseWithCleanUp);
|
|
25
|
+
});
|
|
26
|
+
return responseWithCleanUp;
|
|
27
|
+
};
|
|
28
|
+
exports.post = post;
|
|
29
|
+
/**
|
|
30
|
+
* Cancels a request given the promise returned by `post`.
|
|
31
|
+
* If the request is already completed, this function does nothing.
|
|
32
|
+
* It MUST be used after `updateRequestToBeCancellable` is called.
|
|
33
|
+
*/
|
|
34
|
+
var cancel = function (promise, message) {
|
|
35
|
+
var controller = cancelTokenMap.get(promise);
|
|
36
|
+
if (controller) {
|
|
37
|
+
controller.abort(message);
|
|
38
|
+
if (controller.signal.reason !== message) {
|
|
39
|
+
// In runtimes where `AbortSignal.reason` is not supported, we track the reason ourselves.
|
|
40
|
+
// @ts-expect-error reason is read-only property.
|
|
41
|
+
controller.signal['reason'] = message;
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
return false;
|
|
46
|
+
};
|
|
47
|
+
exports.cancel = cancel;
|
|
48
|
+
/**
|
|
49
|
+
* MUST be used to make a promise including internal `post` API call cancellable.
|
|
50
|
+
*/
|
|
51
|
+
var updateRequestToBeCancellable = function (promise, controller) {
|
|
52
|
+
cancelTokenMap.set(promise, controller);
|
|
53
|
+
};
|
|
54
|
+
exports.updateRequestToBeCancellable = updateRequestToBeCancellable;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { AmplifyErrorParams } from '@aws-amplify/core/internals/utils';
|
|
2
|
+
import { RestApiError } from './RestApiError';
|
|
3
|
+
/**
|
|
4
|
+
* Internal-only class for CancelledError.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export declare class CancelledError extends RestApiError {
|
|
9
|
+
constructor(params: AmplifyErrorParams);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Check if an error is caused by user calling `cancel()` REST API.
|
|
13
|
+
*/
|
|
14
|
+
export declare const isCancelError: (error: unknown) => boolean;
|
|
@@ -0,0 +1,31 @@
|
|
|
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.isCancelError = exports.CancelledError = void 0;
|
|
6
|
+
var tslib_1 = require("tslib");
|
|
7
|
+
var RestApiError_1 = require("./RestApiError");
|
|
8
|
+
/**
|
|
9
|
+
* Internal-only class for CancelledError.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
var CancelledError = /** @class */ (function (_super) {
|
|
14
|
+
tslib_1.__extends(CancelledError, _super);
|
|
15
|
+
function CancelledError(params) {
|
|
16
|
+
var _this = _super.call(this, params) || this;
|
|
17
|
+
// TODO: Delete the following 2 lines after we change the build target to >= es2015
|
|
18
|
+
_this.constructor = CancelledError;
|
|
19
|
+
Object.setPrototypeOf(_this, CancelledError.prototype);
|
|
20
|
+
return _this;
|
|
21
|
+
}
|
|
22
|
+
return CancelledError;
|
|
23
|
+
}(RestApiError_1.RestApiError));
|
|
24
|
+
exports.CancelledError = CancelledError;
|
|
25
|
+
/**
|
|
26
|
+
* Check if an error is caused by user calling `cancel()` REST API.
|
|
27
|
+
*/
|
|
28
|
+
var isCancelError = function (error) {
|
|
29
|
+
return !!error && error instanceof CancelledError;
|
|
30
|
+
};
|
|
31
|
+
exports.isCancelError = isCancelError;
|
|
@@ -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.RestApiError = void 0;
|
|
6
|
+
var tslib_1 = require("tslib");
|
|
7
|
+
var utils_1 = require("@aws-amplify/core/internals/utils");
|
|
8
|
+
var RestApiError = /** @class */ (function (_super) {
|
|
9
|
+
tslib_1.__extends(RestApiError, _super);
|
|
10
|
+
function RestApiError(params) {
|
|
11
|
+
var _this = _super.call(this, params) || this;
|
|
12
|
+
// TODO: Delete the following 2 lines after we change the build target to >= es2015
|
|
13
|
+
_this.constructor = RestApiError;
|
|
14
|
+
Object.setPrototypeOf(_this, RestApiError.prototype);
|
|
15
|
+
return _this;
|
|
16
|
+
}
|
|
17
|
+
return RestApiError;
|
|
18
|
+
}(utils_1.AmplifyError));
|
|
19
|
+
exports.RestApiError = RestApiError;
|
|
@@ -0,0 +1,17 @@
|
|
|
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.assertValidationError = void 0;
|
|
6
|
+
var RestApiError_1 = require("./RestApiError");
|
|
7
|
+
var validation_1 = require("./validation");
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
function assertValidationError(assertion, name) {
|
|
12
|
+
var _a = validation_1.validationErrorMap[name], message = _a.message, recoverySuggestion = _a.recoverySuggestion;
|
|
13
|
+
if (!assertion) {
|
|
14
|
+
throw new RestApiError_1.RestApiError({ name: name, message: message, recoverySuggestion: recoverySuggestion });
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.assertValidationError = assertValidationError;
|
|
@@ -0,0 +1,15 @@
|
|
|
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.validationErrorMap = exports.RestApiValidationErrorCode = exports.assertValidationError = exports.RestApiError = exports.isCancelError = exports.CancelledError = void 0;
|
|
6
|
+
var CancelledError_1 = require("./CancelledError");
|
|
7
|
+
Object.defineProperty(exports, "CancelledError", { enumerable: true, get: function () { return CancelledError_1.CancelledError; } });
|
|
8
|
+
Object.defineProperty(exports, "isCancelError", { enumerable: true, get: function () { return CancelledError_1.isCancelError; } });
|
|
9
|
+
var RestApiError_1 = require("./RestApiError");
|
|
10
|
+
Object.defineProperty(exports, "RestApiError", { enumerable: true, get: function () { return RestApiError_1.RestApiError; } });
|
|
11
|
+
var assertValidatonError_1 = require("./assertValidatonError");
|
|
12
|
+
Object.defineProperty(exports, "assertValidationError", { enumerable: true, get: function () { return assertValidatonError_1.assertValidationError; } });
|
|
13
|
+
var validation_1 = require("./validation");
|
|
14
|
+
Object.defineProperty(exports, "RestApiValidationErrorCode", { enumerable: true, get: function () { return validation_1.RestApiValidationErrorCode; } });
|
|
15
|
+
Object.defineProperty(exports, "validationErrorMap", { enumerable: true, get: function () { return validation_1.validationErrorMap; } });
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
var _a;
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.validationErrorMap = exports.RestApiValidationErrorCode = void 0;
|
|
7
|
+
var RestApiValidationErrorCode;
|
|
8
|
+
(function (RestApiValidationErrorCode) {
|
|
9
|
+
RestApiValidationErrorCode["NoCredentials"] = "NoCredentials";
|
|
10
|
+
})(RestApiValidationErrorCode = exports.RestApiValidationErrorCode || (exports.RestApiValidationErrorCode = {}));
|
|
11
|
+
exports.validationErrorMap = (_a = {},
|
|
12
|
+
_a[RestApiValidationErrorCode.NoCredentials] = {
|
|
13
|
+
message: 'Credentials should not be empty.',
|
|
14
|
+
},
|
|
15
|
+
_a);
|
package/lib/index.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { DocumentType } from './types';
|
|
1
|
+
export { isCancelError } from './errors/CancelledError';
|
package/lib/index.js
CHANGED
|
@@ -2,8 +2,6 @@
|
|
|
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.
|
|
6
|
-
var
|
|
7
|
-
Object.defineProperty(exports, "
|
|
8
|
-
Object.defineProperty(exports, "cancel", { enumerable: true, get: function () { return API_1.cancel; } });
|
|
9
|
-
Object.defineProperty(exports, "isCancel", { enumerable: true, get: function () { return API_1.isCancel; } });
|
|
5
|
+
exports.isCancelError = void 0;
|
|
6
|
+
var CancelledError_1 = require("./errors/CancelledError");
|
|
7
|
+
Object.defineProperty(exports, "isCancelError", { enumerable: true, get: function () { return CancelledError_1.isCancelError; } });
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { InternalPostInput } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Internal-only REST POST handler to send GraphQL request to given endpoint. By default, it will use IAM to authorize
|
|
4
|
+
* the request. In some auth modes, the IAM auth has to be disabled. Here's how to set up the request auth correctly:
|
|
5
|
+
* * If auth mode is 'iam', you MUST NOT set 'authorization' header and 'x-api-key' header, since it would disable IAM
|
|
6
|
+
* auth. You MUST also set 'input.options.signingServiceInfo' option.
|
|
7
|
+
* * The including 'input.options.signingServiceInfo.service' and 'input.options.signingServiceInfo.region' are
|
|
8
|
+
* optional. If omitted, the signing service and region will be inferred from url.
|
|
9
|
+
* * If auth mode is 'none', you MUST NOT set 'options.signingServiceInfo' option.
|
|
10
|
+
* * If auth mode is 'apiKey', you MUST set 'x-api-key' custom header.
|
|
11
|
+
* * If auth mode is 'oidc' or 'lambda' or 'userPool', you MUST set 'authorization' header.
|
|
12
|
+
*
|
|
13
|
+
* To make the internal post cancellable, you must also call `updateRequestToBeCancellable()` with the promise from
|
|
14
|
+
* internal post call and the abort controller supplied to the internal post call.
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export declare const post: (input: InternalPostInput) => Promise<import("../types").RestApiResponse>;
|
|
19
|
+
export { cancel, updateRequestToBeCancellable } from '../common/internalPost';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateRequestToBeCancellable = exports.cancel = exports.post = void 0;
|
|
4
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
5
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
var core_1 = require("@aws-amplify/core");
|
|
7
|
+
var internalPost_1 = require("../common/internalPost");
|
|
8
|
+
/**
|
|
9
|
+
* Internal-only REST POST handler to send GraphQL request to given endpoint. By default, it will use IAM to authorize
|
|
10
|
+
* the request. In some auth modes, the IAM auth has to be disabled. Here's how to set up the request auth correctly:
|
|
11
|
+
* * If auth mode is 'iam', you MUST NOT set 'authorization' header and 'x-api-key' header, since it would disable IAM
|
|
12
|
+
* auth. You MUST also set 'input.options.signingServiceInfo' option.
|
|
13
|
+
* * The including 'input.options.signingServiceInfo.service' and 'input.options.signingServiceInfo.region' are
|
|
14
|
+
* optional. If omitted, the signing service and region will be inferred from url.
|
|
15
|
+
* * If auth mode is 'none', you MUST NOT set 'options.signingServiceInfo' option.
|
|
16
|
+
* * If auth mode is 'apiKey', you MUST set 'x-api-key' custom header.
|
|
17
|
+
* * If auth mode is 'oidc' or 'lambda' or 'userPool', you MUST set 'authorization' header.
|
|
18
|
+
*
|
|
19
|
+
* To make the internal post cancellable, you must also call `updateRequestToBeCancellable()` with the promise from
|
|
20
|
+
* internal post call and the abort controller supplied to the internal post call.
|
|
21
|
+
*
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
var post = function (input) {
|
|
25
|
+
return (0, internalPost_1.post)(core_1.Amplify, input);
|
|
26
|
+
};
|
|
27
|
+
exports.post = post;
|
|
28
|
+
var internalPost_2 = require("../common/internalPost");
|
|
29
|
+
Object.defineProperty(exports, "cancel", { enumerable: true, get: function () { return internalPost_2.cancel; } });
|
|
30
|
+
Object.defineProperty(exports, "updateRequestToBeCancellable", { enumerable: true, get: function () { return internalPost_2.updateRequestToBeCancellable; } });
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { AmplifyServer } from '@aws-amplify/core/internals/adapter-core';
|
|
2
|
+
import { InternalPostInput } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Internal-only REST POST handler to send GraphQL request to given endpoint. By default, it will use IAM to authorize
|
|
5
|
+
* the request. In some auth modes, the IAM auth has to be disabled. Here's how to set up the request auth correctly:
|
|
6
|
+
* * If auth mode is 'iam', you MUST NOT set 'authorization' header and 'x-api-key' header, since it would disable IAM
|
|
7
|
+
* auth. You MUST also set 'input.options.signingServiceInfo' option.
|
|
8
|
+
* * The including 'input.options.signingServiceInfo.service' and 'input.options.signingServiceInfo.region' are
|
|
9
|
+
* optional. If omitted, the signing service and region will be inferred from url.
|
|
10
|
+
* * If auth mode is 'none', you MUST NOT set 'options.signingServiceInfo' option.
|
|
11
|
+
* * If auth mode is 'apiKey', you MUST set 'x-api-key' custom header.
|
|
12
|
+
* * If auth mode is 'oidc' or 'lambda' or 'userPool', you MUST set 'authorization' header.
|
|
13
|
+
*
|
|
14
|
+
* To make the internal post cancellable, you must also call `updateRequestToBeCancellable()` with the promise from
|
|
15
|
+
* internal post call and the abort controller supplied to the internal post call.
|
|
16
|
+
*
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export declare const post: (contextSpec: AmplifyServer.ContextSpec, input: InternalPostInput) => Promise<import("../types").RestApiResponse>;
|
|
20
|
+
export { cancel, updateRequestToBeCancellable } from '../common/internalPost';
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateRequestToBeCancellable = exports.cancel = exports.post = void 0;
|
|
4
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
5
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
var adapter_core_1 = require("@aws-amplify/core/internals/adapter-core");
|
|
7
|
+
var internalPost_1 = require("../common/internalPost");
|
|
8
|
+
/**
|
|
9
|
+
* Internal-only REST POST handler to send GraphQL request to given endpoint. By default, it will use IAM to authorize
|
|
10
|
+
* the request. In some auth modes, the IAM auth has to be disabled. Here's how to set up the request auth correctly:
|
|
11
|
+
* * If auth mode is 'iam', you MUST NOT set 'authorization' header and 'x-api-key' header, since it would disable IAM
|
|
12
|
+
* auth. You MUST also set 'input.options.signingServiceInfo' option.
|
|
13
|
+
* * The including 'input.options.signingServiceInfo.service' and 'input.options.signingServiceInfo.region' are
|
|
14
|
+
* optional. If omitted, the signing service and region will be inferred from url.
|
|
15
|
+
* * If auth mode is 'none', you MUST NOT set 'options.signingServiceInfo' option.
|
|
16
|
+
* * If auth mode is 'apiKey', you MUST set 'x-api-key' custom header.
|
|
17
|
+
* * If auth mode is 'oidc' or 'lambda' or 'userPool', you MUST set 'authorization' header.
|
|
18
|
+
*
|
|
19
|
+
* To make the internal post cancellable, you must also call `updateRequestToBeCancellable()` with the promise from
|
|
20
|
+
* internal post call and the abort controller supplied to the internal post call.
|
|
21
|
+
*
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
var post = function (contextSpec, input) {
|
|
25
|
+
return (0, internalPost_1.post)((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify, input);
|
|
26
|
+
};
|
|
27
|
+
exports.post = post;
|
|
28
|
+
var internalPost_2 = require("../common/internalPost");
|
|
29
|
+
Object.defineProperty(exports, "cancel", { enumerable: true, get: function () { return internalPost_2.cancel; } });
|
|
30
|
+
Object.defineProperty(exports, "updateRequestToBeCancellable", { enumerable: true, get: function () { return internalPost_2.updateRequestToBeCancellable; } });
|