@aws-amplify/api-rest 4.0.1-api-v6-models.9351bcf.0 → 4.0.1-api-v6-models.891fe0d.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.
Files changed (42) hide show
  1. package/lib/apis/common/handler.d.ts +1 -5
  2. package/lib/apis/common/handler.js +59 -65
  3. package/lib/apis/common/internalPost.js +18 -18
  4. package/lib/apis/common/publicApis.js +33 -39
  5. package/lib/apis/index.js +8 -16
  6. package/lib/apis/server.js +8 -20
  7. package/lib/errors/CanceledError.js +12 -15
  8. package/lib/errors/RestApiError.js +7 -11
  9. package/lib/errors/assertValidatonError.js +4 -4
  10. package/lib/errors/validation.js +4 -5
  11. package/lib/internals/index.js +3 -3
  12. package/lib/internals/server.js +3 -3
  13. package/lib/tsconfig.tsbuildinfo +1 -1
  14. package/lib/utils/createCancellableOperation.js +32 -39
  15. package/lib/utils/logger.js +1 -1
  16. package/lib/utils/normalizeHeaders.js +3 -3
  17. package/lib/utils/parseSigningInfo.js +9 -10
  18. package/lib/utils/resolveApiUrl.js +14 -13
  19. package/lib/utils/resolveCredentials.js +6 -14
  20. package/lib/utils/serviceError.js +14 -22
  21. package/lib-esm/apis/common/handler.d.ts +1 -5
  22. package/lib-esm/apis/common/handler.js +55 -61
  23. package/lib-esm/apis/common/internalPost.js +16 -16
  24. package/lib-esm/apis/common/publicApis.js +31 -37
  25. package/lib-esm/apis/index.js +6 -14
  26. package/lib-esm/apis/server.js +6 -18
  27. package/lib-esm/errors/CanceledError.js +11 -15
  28. package/lib-esm/errors/RestApiError.js +6 -11
  29. package/lib-esm/errors/assertValidatonError.js +2 -2
  30. package/lib-esm/errors/validation.js +4 -5
  31. package/lib-esm/internals/index.js +1 -1
  32. package/lib-esm/internals/server.js +1 -1
  33. package/lib-esm/tsconfig.tsbuildinfo +1 -1
  34. package/lib-esm/utils/constants.js +4 -4
  35. package/lib-esm/utils/createCancellableOperation.js +29 -36
  36. package/lib-esm/utils/logger.js +1 -1
  37. package/lib-esm/utils/normalizeHeaders.js +3 -3
  38. package/lib-esm/utils/parseSigningInfo.js +8 -9
  39. package/lib-esm/utils/resolveApiUrl.js +12 -11
  40. package/lib-esm/utils/resolveCredentials.js +5 -13
  41. package/lib-esm/utils/serviceError.js +12 -20
  42. package/package.json +5 -5
@@ -21,11 +21,7 @@ type SigningServiceInfo = {
21
21
  *
22
22
  * @internal
23
23
  */
24
- export declare const transferHandler: (amplify: AmplifyClassV6, options: Omit<HttpRequest, "body" | "headers"> & {
25
- body?: DocumentType | FormData | undefined;
26
- headers?: Headers | undefined;
27
- withCredentials?: boolean | undefined;
28
- } & {
24
+ export declare const transferHandler: (amplify: AmplifyClassV6, options: HandlerOptions & {
29
25
  abortSignal: AbortSignal;
30
26
  }, signingServiceInfo?: SigningServiceInfo) => Promise<RestApiResponse>;
31
27
  export {};
@@ -1,10 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
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");
4
+ const aws_client_utils_1 = require("@aws-amplify/core/internals/aws-client-utils");
5
+ const utils_1 = require("../../utils");
6
+ const normalizeHeaders_1 = require("../../utils/normalizeHeaders");
8
7
  /**
9
8
  * Make REST API call with best-effort IAM auth.
10
9
  * @param amplify Amplify instance to to resolve credentials and tokens. Should use different instance in client-side
@@ -15,65 +14,60 @@ var normalizeHeaders_1 = require("../../utils/normalizeHeaders");
15
14
  *
16
15
  * @internal
17
16
  */
18
- var transferHandler = function (amplify, options, signingServiceInfo) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
19
- var url, method, headers, body, withCredentials, abortSignal, resolvedBody, resolvedHeaders, request, baseOptions, isIamAuthApplicable, response, signingInfoFromUrl, signingService, signingRegion, credentials;
20
- var _a, _b;
21
- return tslib_1.__generator(this, function (_c) {
22
- switch (_c.label) {
23
- case 0:
24
- url = options.url, method = options.method, headers = options.headers, body = options.body, withCredentials = options.withCredentials, abortSignal = options.abortSignal;
25
- resolvedBody = body
26
- ? body instanceof FormData
27
- ? body
28
- : JSON.stringify(body !== null && body !== void 0 ? body : '')
29
- : undefined;
30
- resolvedHeaders = tslib_1.__assign(tslib_1.__assign({}, (0, normalizeHeaders_1.normalizeHeaders)(headers)), (resolvedBody
31
- ? {
32
- 'content-type': body instanceof FormData
33
- ? 'multipart/form-data'
34
- : 'application/json; charset=UTF-8',
35
- }
36
- : {}));
37
- request = {
38
- url: url,
39
- headers: resolvedHeaders,
40
- method: method,
41
- body: resolvedBody,
42
- };
43
- baseOptions = {
44
- retryDecider: (0, aws_client_utils_1.getRetryDecider)(utils_1.parseRestApiServiceError),
45
- computeDelay: aws_client_utils_1.jitteredBackoff,
46
- withCrossDomainCredentials: withCredentials,
47
- abortSignal: abortSignal,
48
- };
49
- isIamAuthApplicable = iamAuthApplicable(request, signingServiceInfo);
50
- if (!isIamAuthApplicable) return [3 /*break*/, 3];
51
- signingInfoFromUrl = (0, utils_1.parseSigningInfo)(url);
52
- signingService = (_a = signingServiceInfo === null || signingServiceInfo === void 0 ? void 0 : signingServiceInfo.service) !== null && _a !== void 0 ? _a : signingInfoFromUrl.service;
53
- signingRegion = (_b = signingServiceInfo === null || signingServiceInfo === void 0 ? void 0 : signingServiceInfo.region) !== null && _b !== void 0 ? _b : signingInfoFromUrl.region;
54
- return [4 /*yield*/, (0, utils_1.resolveCredentials)(amplify)];
55
- case 1:
56
- credentials = _c.sent();
57
- return [4 /*yield*/, (0, aws_client_utils_1.authenticatedHandler)(request, tslib_1.__assign(tslib_1.__assign({}, baseOptions), { credentials: credentials, region: signingRegion, service: signingService }))];
58
- case 2:
59
- response = _c.sent();
60
- return [3 /*break*/, 5];
61
- case 3: return [4 /*yield*/, (0, aws_client_utils_1.unauthenticatedHandler)(request, tslib_1.__assign({}, baseOptions))];
62
- case 4:
63
- response = _c.sent();
64
- _c.label = 5;
65
- case 5:
66
- // Clean-up un-modeled properties from response.
67
- return [2 /*return*/, {
68
- statusCode: response.statusCode,
69
- headers: response.headers,
70
- body: response.body,
71
- }];
72
- }
73
- });
74
- }); };
75
- exports.transferHandler = transferHandler;
76
- var iamAuthApplicable = function (_a, signingServiceInfo) {
77
- var headers = _a.headers;
78
- return !headers.authorization && !headers['x-api-key'] && !!signingServiceInfo;
17
+ const transferHandler = async (amplify, options, signingServiceInfo) => {
18
+ const { url, method, headers, body, withCredentials, abortSignal } = options;
19
+ const resolvedBody = body
20
+ ? body instanceof FormData
21
+ ? body
22
+ : JSON.stringify(body ?? '')
23
+ : undefined;
24
+ const resolvedHeaders = {
25
+ ...(0, normalizeHeaders_1.normalizeHeaders)(headers),
26
+ ...(resolvedBody
27
+ ? {
28
+ 'content-type': body instanceof FormData
29
+ ? 'multipart/form-data'
30
+ : 'application/json; charset=UTF-8',
31
+ }
32
+ : {}),
33
+ };
34
+ const request = {
35
+ url,
36
+ headers: resolvedHeaders,
37
+ method,
38
+ body: resolvedBody,
39
+ };
40
+ const baseOptions = {
41
+ retryDecider: (0, aws_client_utils_1.getRetryDecider)(utils_1.parseRestApiServiceError),
42
+ computeDelay: aws_client_utils_1.jitteredBackoff,
43
+ withCrossDomainCredentials: withCredentials,
44
+ abortSignal,
45
+ };
46
+ const isIamAuthApplicable = iamAuthApplicable(request, signingServiceInfo);
47
+ let response;
48
+ if (isIamAuthApplicable) {
49
+ const signingInfoFromUrl = (0, utils_1.parseSigningInfo)(url);
50
+ const signingService = signingServiceInfo?.service ?? signingInfoFromUrl.service;
51
+ const signingRegion = signingServiceInfo?.region ?? signingInfoFromUrl.region;
52
+ const credentials = await (0, utils_1.resolveCredentials)(amplify);
53
+ response = await (0, aws_client_utils_1.authenticatedHandler)(request, {
54
+ ...baseOptions,
55
+ credentials,
56
+ region: signingRegion,
57
+ service: signingService,
58
+ });
59
+ }
60
+ else {
61
+ response = await (0, aws_client_utils_1.unauthenticatedHandler)(request, {
62
+ ...baseOptions,
63
+ });
64
+ }
65
+ // Clean-up un-modeled properties from response.
66
+ return {
67
+ statusCode: response.statusCode,
68
+ headers: response.headers,
69
+ body: response.body,
70
+ };
79
71
  };
72
+ exports.transferHandler = transferHandler;
73
+ const iamAuthApplicable = ({ headers }, signingServiceInfo) => !headers.authorization && !headers['x-api-key'] && !!signingServiceInfo;
@@ -3,9 +3,8 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
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");
6
+ const handler_1 = require("./handler");
7
+ const utils_1 = require("../../utils");
9
8
  /**
10
9
  * This weak map provides functionality to cancel a request given the promise containing the `post` request.
11
10
  *
@@ -17,21 +16,22 @@ var utils_1 = require("../../utils");
17
16
  * 6. GraphQL POST request will be rejected with the error message provided during cancel.
18
17
  * 7. Caller can check if the error is because of cancelling by calling `isCancelError(error)`.
19
18
  */
20
- var cancelTokenMap = new WeakMap();
19
+ const cancelTokenMap = new WeakMap();
21
20
  /**
22
21
  * @internal
23
22
  */
24
- var post = function (amplify, _a) {
25
- var url = _a.url, options = _a.options, abortController = _a.abortController;
26
- var controller = abortController !== null && abortController !== void 0 ? abortController : new AbortController();
27
- var responsePromise = (0, utils_1.createCancellableOperation)(function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
28
- var response;
29
- return tslib_1.__generator(this, function (_a) {
30
- 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);
31
- return [2 /*return*/, response];
32
- });
33
- }); }, controller);
34
- var responseWithCleanUp = responsePromise.finally(function () {
23
+ const post = (amplify, { url, options, abortController }) => {
24
+ const controller = abortController ?? new AbortController();
25
+ const responsePromise = (0, utils_1.createCancellableOperation)(async () => {
26
+ const response = (0, handler_1.transferHandler)(amplify, {
27
+ url,
28
+ method: 'POST',
29
+ ...options,
30
+ abortSignal: controller.signal,
31
+ }, options?.signingServiceInfo);
32
+ return response;
33
+ }, controller);
34
+ const responseWithCleanUp = responsePromise.finally(() => {
35
35
  cancelTokenMap.delete(responseWithCleanUp);
36
36
  });
37
37
  return responseWithCleanUp;
@@ -42,8 +42,8 @@ exports.post = post;
42
42
  * If the request is already completed, this function does nothing.
43
43
  * It MUST be used after `updateRequestToBeCancellable` is called.
44
44
  */
45
- var cancel = function (promise, message) {
46
- var controller = cancelTokenMap.get(promise);
45
+ const cancel = (promise, message) => {
46
+ const controller = cancelTokenMap.get(promise);
47
47
  if (controller) {
48
48
  controller.abort(message);
49
49
  if (message && controller.signal.reason !== message) {
@@ -59,7 +59,7 @@ exports.cancel = cancel;
59
59
  /**
60
60
  * MUST be used to make a promise including internal `post` API call cancellable.
61
61
  */
62
- var updateRequestToBeCancellable = function (promise, controller) {
62
+ const updateRequestToBeCancellable = (promise, controller) => {
63
63
  cancelTokenMap.set(promise, controller);
64
64
  };
65
65
  exports.updateRequestToBeCancellable = updateRequestToBeCancellable;
@@ -3,48 +3,42 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.patch = exports.head = exports.del = exports.put = exports.post = exports.get = void 0;
6
- var tslib_1 = require("tslib");
7
- var utils_1 = require("../../utils");
8
- var handler_1 = require("./handler");
9
- var publicHandler = function (amplify, options, method) {
10
- return (0, utils_1.createCancellableOperation)(function (abortSignal) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
11
- var apiName, _a, apiOptions, apiPath, url, libraryOptionsHeaders, _b, invocationHeaders, headers, signingServiceInfo;
12
- var _c, _d, _e, _f;
13
- return tslib_1.__generator(this, function (_g) {
14
- switch (_g.label) {
15
- case 0:
16
- apiName = options.apiName, _a = options.options, apiOptions = _a === void 0 ? {} : _a, apiPath = options.path;
17
- url = (0, utils_1.resolveApiUrl)(amplify, apiName, apiPath, apiOptions === null || apiOptions === void 0 ? void 0 : apiOptions.queryParams);
18
- 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, {
19
- apiName: apiName,
20
- }))];
21
- case 1:
22
- libraryOptionsHeaders = _g.sent();
23
- _b = apiOptions.headers, invocationHeaders = _b === void 0 ? {} : _b;
24
- headers = tslib_1.__assign(tslib_1.__assign({}, libraryOptionsHeaders), invocationHeaders);
25
- signingServiceInfo = (0, utils_1.parseSigningInfo)(url, {
26
- amplify: amplify,
27
- apiName: apiName,
28
- });
29
- utils_1.logger.debug(method, url, headers, "IAM signing options: ".concat(JSON.stringify(signingServiceInfo)));
30
- return [2 /*return*/, (0, handler_1.transferHandler)(amplify, tslib_1.__assign(tslib_1.__assign({}, apiOptions), { url: url, method: method, headers: headers, abortSignal: abortSignal }), signingServiceInfo)];
31
- }
32
- });
33
- }); });
34
- };
35
- var get = function (amplify, input) {
36
- return publicHandler(amplify, input, 'GET');
37
- };
6
+ const utils_1 = require("../../utils");
7
+ const handler_1 = require("./handler");
8
+ const publicHandler = (amplify, options, method) => (0, utils_1.createCancellableOperation)(async (abortSignal) => {
9
+ const { apiName, options: apiOptions = {}, path: apiPath } = options;
10
+ const url = (0, utils_1.resolveApiUrl)(amplify, apiName, apiPath, apiOptions?.queryParams);
11
+ const libraryOptionsHeaders = await amplify.libraryOptions?.API?.REST?.headers?.({
12
+ apiName,
13
+ });
14
+ const { headers: invocationHeaders = {} } = apiOptions;
15
+ const headers = {
16
+ // custom headers from invocation options should precede library options
17
+ ...libraryOptionsHeaders,
18
+ ...invocationHeaders,
19
+ };
20
+ const signingServiceInfo = (0, utils_1.parseSigningInfo)(url, {
21
+ amplify,
22
+ apiName,
23
+ });
24
+ utils_1.logger.debug(method, url, headers, `IAM signing options: ${JSON.stringify(signingServiceInfo)}`);
25
+ return (0, handler_1.transferHandler)(amplify, {
26
+ ...apiOptions,
27
+ url,
28
+ method,
29
+ headers,
30
+ abortSignal,
31
+ }, signingServiceInfo);
32
+ });
33
+ const get = (amplify, input) => publicHandler(amplify, input, 'GET');
38
34
  exports.get = get;
39
- var post = function (amplify, input) { return publicHandler(amplify, input, 'POST'); };
35
+ const post = (amplify, input) => publicHandler(amplify, input, 'POST');
40
36
  exports.post = post;
41
- var put = function (amplify, input) {
42
- return publicHandler(amplify, input, 'PUT');
43
- };
37
+ const put = (amplify, input) => publicHandler(amplify, input, 'PUT');
44
38
  exports.put = put;
45
- var del = function (amplify, input) { return publicHandler(amplify, input, 'DELETE'); };
39
+ const del = (amplify, input) => publicHandler(amplify, input, 'DELETE');
46
40
  exports.del = del;
47
- var head = function (amplify, input) { return publicHandler(amplify, input, 'HEAD'); };
41
+ const head = (amplify, input) => publicHandler(amplify, input, 'HEAD');
48
42
  exports.head = head;
49
- var patch = function (amplify, input) { return publicHandler(amplify, input, 'PATCH'); };
43
+ const patch = (amplify, input) => publicHandler(amplify, input, 'PATCH');
50
44
  exports.patch = patch;
package/lib/apis/index.js CHANGED
@@ -3,8 +3,8 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.patch = exports.head = exports.del = exports.put = exports.post = exports.get = void 0;
6
- var core_1 = require("@aws-amplify/core");
7
- var publicApis_1 = require("./common/publicApis");
6
+ const core_1 = require("@aws-amplify/core");
7
+ const publicApis_1 = require("./common/publicApis");
8
8
  /**
9
9
  * GET HTTP request
10
10
  * @param {GetInput} input - Input for GET operation
@@ -44,7 +44,7 @@ var publicApis_1 = require("./common/publicApis");
44
44
  * }
45
45
  * ```
46
46
  */
47
- var get = function (input) { return (0, publicApis_1.get)(core_1.Amplify, input); };
47
+ const get = (input) => (0, publicApis_1.get)(core_1.Amplify, input);
48
48
  exports.get = get;
49
49
  /**
50
50
  * POST HTTP request
@@ -85,9 +85,7 @@ exports.get = get;
85
85
  * }
86
86
  * ```
87
87
  */
88
- var post = function (input) {
89
- return (0, publicApis_1.post)(core_1.Amplify, input);
90
- };
88
+ const post = (input) => (0, publicApis_1.post)(core_1.Amplify, input);
91
89
  exports.post = post;
92
90
  /**
93
91
  * PUT HTTP request
@@ -127,7 +125,7 @@ exports.post = post;
127
125
  * }
128
126
  * ```
129
127
  */
130
- var put = function (input) { return (0, publicApis_1.put)(core_1.Amplify, input); };
128
+ const put = (input) => (0, publicApis_1.put)(core_1.Amplify, input);
131
129
  exports.put = put;
132
130
  /**
133
131
  * DELETE HTTP request
@@ -149,9 +147,7 @@ exports.put = put;
149
147
  * }).response;
150
148
  * ```
151
149
  */
152
- var del = function (input) {
153
- return (0, publicApis_1.del)(core_1.Amplify, input);
154
- };
150
+ const del = (input) => (0, publicApis_1.del)(core_1.Amplify, input);
155
151
  exports.del = del;
156
152
  /**
157
153
  * HEAD HTTP request
@@ -174,9 +170,7 @@ exports.del = del;
174
170
  * ```
175
171
  *
176
172
  */
177
- var head = function (input) {
178
- return (0, publicApis_1.head)(core_1.Amplify, input);
179
- };
173
+ const head = (input) => (0, publicApis_1.head)(core_1.Amplify, input);
180
174
  exports.head = head;
181
175
  /**
182
176
  * PATCH HTTP request
@@ -217,7 +211,5 @@ exports.head = head;
217
211
  * }
218
212
  * ```
219
213
  */
220
- var patch = function (input) {
221
- return (0, publicApis_1.patch)(core_1.Amplify, input);
222
- };
214
+ const patch = (input) => (0, publicApis_1.patch)(core_1.Amplify, input);
223
215
  exports.patch = patch;
@@ -3,8 +3,8 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.patch = exports.head = exports.del = exports.put = exports.post = exports.get = void 0;
6
- var adapter_core_1 = require("@aws-amplify/core/internals/adapter-core");
7
- var publicApis_1 = require("./common/publicApis");
6
+ const adapter_core_1 = require("@aws-amplify/core/internals/adapter-core");
7
+ const publicApis_1 = require("./common/publicApis");
8
8
  /**
9
9
  * GET HTTP request (server-side)
10
10
  * @param {AmplifyServer.ContextSpec} contextSpec - The context spec used to get the Amplify server context.
@@ -30,9 +30,7 @@ var publicApis_1 = require("./common/publicApis");
30
30
  * ```
31
31
  * @see {@link clientGet}
32
32
  */
33
- var get = function (contextSpec, input) {
34
- return (0, publicApis_1.get)((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify, input);
35
- };
33
+ const get = (contextSpec, input) => (0, publicApis_1.get)((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify, input);
36
34
  exports.get = get;
37
35
  /**
38
36
  * POST HTTP request (server-side)
@@ -58,9 +56,7 @@ exports.get = get;
58
56
  * });
59
57
  * ```
60
58
  */
61
- var post = function (contextSpec, input) {
62
- return (0, publicApis_1.post)((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify, input);
63
- };
59
+ const post = (contextSpec, input) => (0, publicApis_1.post)((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify, input);
64
60
  exports.post = post;
65
61
  /**
66
62
  * PUT HTTP request (server-side)
@@ -86,9 +82,7 @@ exports.post = post;
86
82
  * });
87
83
  * ```
88
84
  */
89
- var put = function (contextSpec, input) {
90
- return (0, publicApis_1.put)((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify, input);
91
- };
85
+ const put = (contextSpec, input) => (0, publicApis_1.put)((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify, input);
92
86
  exports.put = put;
93
87
  /**
94
88
  * DELETE HTTP request (server-side)
@@ -113,9 +107,7 @@ exports.put = put;
113
107
  * });
114
108
  * ```
115
109
  */
116
- var del = function (contextSpec, input) {
117
- return (0, publicApis_1.del)((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify, input);
118
- };
110
+ const del = (contextSpec, input) => (0, publicApis_1.del)((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify, input);
119
111
  exports.del = del;
120
112
  /**
121
113
  * HEAD HTTP request (server-side)
@@ -140,9 +132,7 @@ exports.del = del;
140
132
  * });
141
133
  * ```
142
134
  */
143
- var head = function (contextSpec, input) {
144
- return (0, publicApis_1.head)((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify, input);
145
- };
135
+ const head = (contextSpec, input) => (0, publicApis_1.head)((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify, input);
146
136
  exports.head = head;
147
137
  /**
148
138
  * PATCH HTTP request (server-side)
@@ -168,7 +158,5 @@ exports.head = head;
168
158
  * });
169
159
  * ```
170
160
  */
171
- var patch = function (contextSpec, input) {
172
- return (0, publicApis_1.patch)((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify, input);
173
- };
161
+ const patch = (contextSpec, input) => (0, publicApis_1.patch)((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify, input);
174
162
  exports.patch = patch;
@@ -3,25 +3,24 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.isCancelError = exports.CanceledError = void 0;
6
- var tslib_1 = require("tslib");
7
- var RestApiError_1 = require("./RestApiError");
6
+ const RestApiError_1 = require("./RestApiError");
8
7
  /**
9
8
  * Internal-only class for CanceledError.
10
9
  *
11
10
  * @internal
12
11
  */
13
- var CanceledError = /** @class */ (function (_super) {
14
- tslib_1.__extends(CanceledError, _super);
15
- function CanceledError(params) {
16
- if (params === void 0) { params = {}; }
17
- var _this = _super.call(this, tslib_1.__assign({ name: 'CanceledError', message: 'Request is canceled by user' }, params)) || this;
12
+ class CanceledError extends RestApiError_1.RestApiError {
13
+ constructor(params = {}) {
14
+ super({
15
+ name: 'CanceledError',
16
+ message: 'Request is canceled by user',
17
+ ...params,
18
+ });
18
19
  // TODO: Delete the following 2 lines after we change the build target to >= es2015
19
- _this.constructor = CanceledError;
20
- Object.setPrototypeOf(_this, CanceledError.prototype);
21
- return _this;
20
+ this.constructor = CanceledError;
21
+ Object.setPrototypeOf(this, CanceledError.prototype);
22
22
  }
23
- return CanceledError;
24
- }(RestApiError_1.RestApiError));
23
+ }
25
24
  exports.CanceledError = CanceledError;
26
25
  /**
27
26
  * Check if an error is caused by user calling `cancel()` in REST API.
@@ -29,7 +28,5 @@ exports.CanceledError = CanceledError;
29
28
  * @note This function works **ONLY** for errors thrown by REST API. For GraphQL APIs, use `client.isCancelError(error)`
30
29
  * instead. `client` is generated from `generateClient()` API from `aws-amplify/api`.
31
30
  */
32
- var isCancelError = function (error) {
33
- return !!error && error instanceof CanceledError;
34
- };
31
+ const isCancelError = (error) => !!error && error instanceof CanceledError;
35
32
  exports.isCancelError = isCancelError;
@@ -3,17 +3,13 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
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;
6
+ const utils_1 = require("@aws-amplify/core/internals/utils");
7
+ class RestApiError extends utils_1.AmplifyError {
8
+ constructor(params) {
9
+ super(params);
12
10
  // 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;
11
+ this.constructor = RestApiError;
12
+ Object.setPrototypeOf(this, RestApiError.prototype);
16
13
  }
17
- return RestApiError;
18
- }(utils_1.AmplifyError));
14
+ }
19
15
  exports.RestApiError = RestApiError;
@@ -3,15 +3,15 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.assertValidationError = void 0;
6
- var RestApiError_1 = require("./RestApiError");
7
- var validation_1 = require("./validation");
6
+ const RestApiError_1 = require("./RestApiError");
7
+ const validation_1 = require("./validation");
8
8
  /**
9
9
  * @internal
10
10
  */
11
11
  function assertValidationError(assertion, name) {
12
- var _a = validation_1.validationErrorMap[name], message = _a.message, recoverySuggestion = _a.recoverySuggestion;
12
+ const { message, recoverySuggestion } = validation_1.validationErrorMap[name];
13
13
  if (!assertion) {
14
- throw new RestApiError_1.RestApiError({ name: name, message: message, recoverySuggestion: recoverySuggestion });
14
+ throw new RestApiError_1.RestApiError({ name, message, recoverySuggestion });
15
15
  }
16
16
  }
17
17
  exports.assertValidationError = assertValidationError;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
3
  // SPDX-License-Identifier: Apache-2.0
4
- var _a;
5
4
  Object.defineProperty(exports, "__esModule", { value: true });
6
5
  exports.validationErrorMap = exports.RestApiValidationErrorCode = void 0;
7
6
  var RestApiValidationErrorCode;
@@ -9,12 +8,12 @@ var RestApiValidationErrorCode;
9
8
  RestApiValidationErrorCode["NoCredentials"] = "NoCredentials";
10
9
  RestApiValidationErrorCode["InvalidApiName"] = "InvalidApiName";
11
10
  })(RestApiValidationErrorCode = exports.RestApiValidationErrorCode || (exports.RestApiValidationErrorCode = {}));
12
- exports.validationErrorMap = (_a = {},
13
- _a[RestApiValidationErrorCode.NoCredentials] = {
11
+ exports.validationErrorMap = {
12
+ [RestApiValidationErrorCode.NoCredentials]: {
14
13
  message: 'Credentials should not be empty.',
15
14
  },
16
- _a[RestApiValidationErrorCode.InvalidApiName] = {
15
+ [RestApiValidationErrorCode.InvalidApiName]: {
17
16
  message: 'API name is invalid.',
18
17
  recoverySuggestion: 'Check if the API name matches the one in your configuration or `aws-exports.js`',
19
18
  },
20
- _a);
19
+ };
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.updateRequestToBeCancellable = exports.cancel = exports.post = void 0;
4
4
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
5
  // SPDX-License-Identifier: Apache-2.0
6
- var core_1 = require("@aws-amplify/core");
7
- var internalPost_1 = require("../apis/common/internalPost");
6
+ const core_1 = require("@aws-amplify/core");
7
+ const internalPost_1 = require("../apis/common/internalPost");
8
8
  /**
9
9
  * Internal-only REST POST handler to send GraphQL request to given endpoint. By default, it will use IAM to authorize
10
10
  * the request. In some auth modes, the IAM auth has to be disabled. Here's how to set up the request auth correctly:
@@ -21,7 +21,7 @@ var internalPost_1 = require("../apis/common/internalPost");
21
21
  *
22
22
  * @internal
23
23
  */
24
- var post = function (input) {
24
+ const post = (input) => {
25
25
  return (0, internalPost_1.post)(core_1.Amplify, input);
26
26
  };
27
27
  exports.post = post;
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.updateRequestToBeCancellable = exports.cancel = exports.post = void 0;
4
4
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
5
  // SPDX-License-Identifier: Apache-2.0
6
- var adapter_core_1 = require("@aws-amplify/core/internals/adapter-core");
7
- var internalPost_1 = require("../apis/common/internalPost");
6
+ const adapter_core_1 = require("@aws-amplify/core/internals/adapter-core");
7
+ const internalPost_1 = require("../apis/common/internalPost");
8
8
  /**
9
9
  * Internal-only REST POST handler to send GraphQL request to given endpoint. By default, it will use IAM to authorize
10
10
  * the request. In some auth modes, the IAM auth has to be disabled. Here's how to set up the request auth correctly:
@@ -21,7 +21,7 @@ var internalPost_1 = require("../apis/common/internalPost");
21
21
  *
22
22
  * @internal
23
23
  */
24
- var post = function (contextSpec, input) {
24
+ const post = (contextSpec, input) => {
25
25
  return (0, internalPost_1.post)((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify, input);
26
26
  };
27
27
  exports.post = post;