@aws-amplify/api-rest 4.0.1-console-preview.a1c533e.0 → 4.0.1-console-preview.23dc225.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/apis/common/handler.js +14 -3
- package/lib/apis/common/internalPost.js +1 -1
- package/lib/apis/index.d.ts +178 -0
- package/lib/apis/index.js +178 -0
- package/lib/apis/server.d.ts +125 -0
- package/lib/apis/server.js +125 -0
- package/lib/errors/CanceledError.d.ts +17 -0
- package/lib/errors/CanceledError.js +35 -0
- package/lib/errors/index.d.ts +1 -1
- package/lib/errors/index.js +4 -4
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -2
- package/lib/server.d.ts +1 -1
- package/lib/server.js +2 -2
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/index.d.ts +1 -1
- package/lib/utils/createCancellableOperation.js +10 -15
- package/lib/utils/index.d.ts +0 -1
- package/lib/utils/index.js +0 -1
- package/lib/utils/resolveApiUrl.js +4 -3
- package/lib/utils/resolveCredentials.d.ts +1 -6
- package/lib-esm/apis/common/handler.js +14 -3
- package/lib-esm/apis/common/internalPost.js +1 -1
- package/lib-esm/apis/index.d.ts +178 -0
- package/lib-esm/apis/index.js +178 -0
- package/lib-esm/apis/server.d.ts +125 -0
- package/lib-esm/apis/server.js +125 -0
- package/lib-esm/errors/CanceledError.d.ts +17 -0
- package/lib-esm/errors/CanceledError.js +31 -0
- package/lib-esm/errors/index.d.ts +1 -1
- package/lib-esm/errors/index.js +1 -1
- package/lib-esm/index.d.ts +1 -1
- package/lib-esm/index.js +1 -1
- package/lib-esm/server.d.ts +1 -1
- package/lib-esm/server.js +1 -1
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/types/index.d.ts +1 -1
- package/lib-esm/utils/createCancellableOperation.js +12 -17
- package/lib-esm/utils/index.d.ts +0 -1
- package/lib-esm/utils/index.js +0 -1
- package/lib-esm/utils/resolveApiUrl.js +4 -3
- package/lib-esm/utils/resolveCredentials.d.ts +1 -6
- package/package.json +5 -5
- package/src/apis/common/handler.ts +9 -2
- package/src/apis/common/internalPost.ts +1 -1
- package/src/apis/index.ts +179 -0
- package/src/apis/server.ts +126 -0
- package/src/errors/CanceledError.ts +33 -0
- package/src/errors/index.ts +1 -1
- package/src/index.ts +1 -1
- package/src/server.ts +1 -1
- package/src/types/index.ts +1 -1
- package/src/utils/createCancellableOperation.ts +5 -6
- package/src/utils/index.ts +0 -2
- package/src/utils/resolveApiUrl.ts +7 -3
- package/lib/errors/CancelledError.d.ts +0 -14
- package/lib/errors/CancelledError.js +0 -31
- package/lib/utils/polyfills/index.d.ts +0 -0
- package/lib/utils/polyfills/index.js +0 -4
- package/lib/utils/polyfills/index.native.d.ts +0 -1
- package/lib/utils/polyfills/index.native.js +0 -6
- package/lib-esm/errors/CancelledError.d.ts +0 -14
- package/lib-esm/errors/CancelledError.js +0 -27
- package/lib-esm/utils/polyfills/index.d.ts +0 -0
- package/lib-esm/utils/polyfills/index.js +0 -4
- package/lib-esm/utils/polyfills/index.native.d.ts +0 -1
- package/lib-esm/utils/polyfills/index.native.js +0 -4
- package/src/errors/CancelledError.ts +0 -26
- package/src/utils/polyfills/index.native.ts +0 -5
- package/src/utils/polyfills/index.ts +0 -4
package/lib/apis/server.js
CHANGED
|
@@ -7,6 +7,28 @@ var adapter_core_1 = require("@aws-amplify/core/internals/adapter-core");
|
|
|
7
7
|
var publicApis_1 = require("./common/publicApis");
|
|
8
8
|
/**
|
|
9
9
|
* GET HTTP request (server-side)
|
|
10
|
+
* @param {AmplifyServer.ContextSpec} contextSpec - The context spec used to get the Amplify server context.
|
|
11
|
+
* @param {GetInput} input - Input for GET operation.
|
|
12
|
+
* @throws - {@link RestApiError}
|
|
13
|
+
* @example
|
|
14
|
+
* Send a GET request
|
|
15
|
+
* ```js
|
|
16
|
+
* import { get } from 'aws-amplify/api/server';
|
|
17
|
+
* //...
|
|
18
|
+
* const restApiResponse = await runWithAmplifyServerContext({
|
|
19
|
+
* nextServerContext: { request, response },
|
|
20
|
+
* operation: async (contextSpec) => {
|
|
21
|
+
* try {
|
|
22
|
+
* const { body } = await get(contextSpec, input).response;
|
|
23
|
+
* return await body.json();
|
|
24
|
+
* } catch (error) {
|
|
25
|
+
* console.log(error);
|
|
26
|
+
* return false;
|
|
27
|
+
* }
|
|
28
|
+
* },
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
* @see {@link clientGet}
|
|
10
32
|
*/
|
|
11
33
|
var get = function (contextSpec, input) {
|
|
12
34
|
return (0, publicApis_1.get)((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify, input);
|
|
@@ -14,6 +36,27 @@ var get = function (contextSpec, input) {
|
|
|
14
36
|
exports.get = get;
|
|
15
37
|
/**
|
|
16
38
|
* POST HTTP request (server-side)
|
|
39
|
+
* @param {AmplifyServer.ContextSpec} contextSpec - The context spec used to get the Amplify server context.
|
|
40
|
+
* @param {PostInput} input - Input for POST operation.
|
|
41
|
+
* @throws - {@link RestApiError}
|
|
42
|
+
* @example
|
|
43
|
+
* Send a POST request
|
|
44
|
+
* ```js
|
|
45
|
+
* import { post } from 'aws-amplify/api/server';
|
|
46
|
+
* //...
|
|
47
|
+
* const restApiResponse = await runWithAmplifyServerContext({
|
|
48
|
+
* nextServerContext: { request, response },
|
|
49
|
+
* operation: async (contextSpec) => {
|
|
50
|
+
* try {
|
|
51
|
+
* const { body } = await post(contextSpec, input).response;
|
|
52
|
+
* return await body.json();
|
|
53
|
+
* } catch (error) {
|
|
54
|
+
* console.log(error);
|
|
55
|
+
* return false;
|
|
56
|
+
* }
|
|
57
|
+
* },
|
|
58
|
+
* });
|
|
59
|
+
* ```
|
|
17
60
|
*/
|
|
18
61
|
var post = function (contextSpec, input) {
|
|
19
62
|
return (0, publicApis_1.post)((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify, input);
|
|
@@ -21,6 +64,27 @@ var post = function (contextSpec, input) {
|
|
|
21
64
|
exports.post = post;
|
|
22
65
|
/**
|
|
23
66
|
* PUT HTTP request (server-side)
|
|
67
|
+
* @param {AmplifyServer.ContextSpec} contextSpec - The context spec used to get the Amplify server context.
|
|
68
|
+
* @param {PutInput} input - Input for PUT operation.
|
|
69
|
+
* @throws - {@link RestApiError}
|
|
70
|
+
* @example
|
|
71
|
+
* Send a PUT request
|
|
72
|
+
* ```js
|
|
73
|
+
* import { put } from 'aws-amplify/api/server';
|
|
74
|
+
* //...
|
|
75
|
+
* const restApiResponse = await runWithAmplifyServerContext({
|
|
76
|
+
* nextServerContext: { request, response },
|
|
77
|
+
* operation: async (contextSpec) => {
|
|
78
|
+
* try {
|
|
79
|
+
* const { body } = await put(contextSpec, input).response;
|
|
80
|
+
* return await body.json();
|
|
81
|
+
* } catch (error) {
|
|
82
|
+
* console.log(error);
|
|
83
|
+
* return false;
|
|
84
|
+
* }
|
|
85
|
+
* },
|
|
86
|
+
* });
|
|
87
|
+
* ```
|
|
24
88
|
*/
|
|
25
89
|
var put = function (contextSpec, input) {
|
|
26
90
|
return (0, publicApis_1.put)((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify, input);
|
|
@@ -28,6 +92,26 @@ var put = function (contextSpec, input) {
|
|
|
28
92
|
exports.put = put;
|
|
29
93
|
/**
|
|
30
94
|
* DELETE HTTP request (server-side)
|
|
95
|
+
* @param {AmplifyServer.ContextSpec} contextSpec - The context spec used to get the Amplify server context.
|
|
96
|
+
* @param {DeleteInput} input - Input for DELETE operation.
|
|
97
|
+
* @throws - {@link RestApiError}
|
|
98
|
+
* @example
|
|
99
|
+
* Send a DELETE request
|
|
100
|
+
* ```js
|
|
101
|
+
* import { del } from 'aws-amplify/api/server';
|
|
102
|
+
* //...
|
|
103
|
+
* const restApiResponse = await runWithAmplifyServerContext({
|
|
104
|
+
* nextServerContext: { request, response },
|
|
105
|
+
* operation: async (contextSpec) => {
|
|
106
|
+
* try {
|
|
107
|
+
* const { headers } = await del(contextSpec, input).response;
|
|
108
|
+
* } catch (error) {
|
|
109
|
+
* console.log(error);
|
|
110
|
+
* return false;
|
|
111
|
+
* }
|
|
112
|
+
* },
|
|
113
|
+
* });
|
|
114
|
+
* ```
|
|
31
115
|
*/
|
|
32
116
|
var del = function (contextSpec, input) {
|
|
33
117
|
return (0, publicApis_1.del)((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify, input);
|
|
@@ -35,6 +119,26 @@ var del = function (contextSpec, input) {
|
|
|
35
119
|
exports.del = del;
|
|
36
120
|
/**
|
|
37
121
|
* HEAD HTTP request (server-side)
|
|
122
|
+
* @param {AmplifyServer.ContextSpec} contextSpec - The context spec used to get the Amplify server context.
|
|
123
|
+
* @param {HeadInput} input - Input for HEAD operation.
|
|
124
|
+
* @throws - {@link RestApiError}
|
|
125
|
+
* @example
|
|
126
|
+
* Send a HEAD request
|
|
127
|
+
* ```js
|
|
128
|
+
* import { head } from 'aws-amplify/api/server';
|
|
129
|
+
* //...
|
|
130
|
+
* const restApiResponse = await runWithAmplifyServerContext({
|
|
131
|
+
* nextServerContext: { request, response },
|
|
132
|
+
* operation: async (contextSpec) => {
|
|
133
|
+
* try {
|
|
134
|
+
* const { headers } = await head(contextSpec, input).response;
|
|
135
|
+
* } catch (error) {
|
|
136
|
+
* console.log(error);
|
|
137
|
+
* return false;
|
|
138
|
+
* }
|
|
139
|
+
* },
|
|
140
|
+
* });
|
|
141
|
+
* ```
|
|
38
142
|
*/
|
|
39
143
|
var head = function (contextSpec, input) {
|
|
40
144
|
return (0, publicApis_1.head)((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify, input);
|
|
@@ -42,6 +146,27 @@ var head = function (contextSpec, input) {
|
|
|
42
146
|
exports.head = head;
|
|
43
147
|
/**
|
|
44
148
|
* PATCH HTTP request (server-side)
|
|
149
|
+
* @param {AmplifyServer.ContextSpec} contextSpec - The context spec used to get the Amplify server context.
|
|
150
|
+
* @param {PatchInput} input - Input for PATCH operation.
|
|
151
|
+
* @throws - {@link RestApiError}
|
|
152
|
+
* @example
|
|
153
|
+
* Send a PATCH request
|
|
154
|
+
* ```js
|
|
155
|
+
* import { patch } from 'aws-amplify/api/server';
|
|
156
|
+
* //...
|
|
157
|
+
* const restApiResponse = await runWithAmplifyServerContext({
|
|
158
|
+
* nextServerContext: { request, response },
|
|
159
|
+
* operation: async (contextSpec) => {
|
|
160
|
+
* try {
|
|
161
|
+
* const { body } = await patch(contextSpec, input).response;
|
|
162
|
+
* return await body.json();
|
|
163
|
+
* } catch (error) {
|
|
164
|
+
* console.log(error);
|
|
165
|
+
* return false;
|
|
166
|
+
* }
|
|
167
|
+
* },
|
|
168
|
+
* });
|
|
169
|
+
* ```
|
|
45
170
|
*/
|
|
46
171
|
var patch = function (contextSpec, input) {
|
|
47
172
|
return (0, publicApis_1.patch)((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify, input);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { AmplifyErrorParams } from '@aws-amplify/core/internals/utils';
|
|
2
|
+
import { RestApiError } from './RestApiError';
|
|
3
|
+
/**
|
|
4
|
+
* Internal-only class for CanceledError.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export declare class CanceledError extends RestApiError {
|
|
9
|
+
constructor(params?: Partial<AmplifyErrorParams>);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Check if an error is caused by user calling `cancel()` in REST API.
|
|
13
|
+
*
|
|
14
|
+
* @note This function works **ONLY** for errors thrown by REST API. For GraphQL APIs, use `client.isCancelError(error)`
|
|
15
|
+
* instead. `client` is generated from `generateClient()` API from `aws-amplify/api`.
|
|
16
|
+
*/
|
|
17
|
+
export declare const isCancelError: (error: unknown) => error is CanceledError;
|
|
@@ -0,0 +1,35 @@
|
|
|
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.CanceledError = void 0;
|
|
6
|
+
var tslib_1 = require("tslib");
|
|
7
|
+
var RestApiError_1 = require("./RestApiError");
|
|
8
|
+
/**
|
|
9
|
+
* Internal-only class for CanceledError.
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
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;
|
|
18
|
+
// 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;
|
|
22
|
+
}
|
|
23
|
+
return CanceledError;
|
|
24
|
+
}(RestApiError_1.RestApiError));
|
|
25
|
+
exports.CanceledError = CanceledError;
|
|
26
|
+
/**
|
|
27
|
+
* Check if an error is caused by user calling `cancel()` in REST API.
|
|
28
|
+
*
|
|
29
|
+
* @note This function works **ONLY** for errors thrown by REST API. For GraphQL APIs, use `client.isCancelError(error)`
|
|
30
|
+
* instead. `client` is generated from `generateClient()` API from `aws-amplify/api`.
|
|
31
|
+
*/
|
|
32
|
+
var isCancelError = function (error) {
|
|
33
|
+
return !!error && error instanceof CanceledError;
|
|
34
|
+
};
|
|
35
|
+
exports.isCancelError = isCancelError;
|
package/lib/errors/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { CanceledError, isCancelError } from './CanceledError';
|
|
2
2
|
export { RestApiError } from './RestApiError';
|
|
3
3
|
export { assertValidationError } from './assertValidatonError';
|
|
4
4
|
export { RestApiValidationErrorCode, validationErrorMap } from './validation';
|
package/lib/errors/index.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
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.validationErrorMap = exports.RestApiValidationErrorCode = exports.assertValidationError = exports.RestApiError = exports.isCancelError = exports.
|
|
6
|
-
var
|
|
7
|
-
Object.defineProperty(exports, "
|
|
8
|
-
Object.defineProperty(exports, "isCancelError", { enumerable: true, get: function () { return
|
|
5
|
+
exports.validationErrorMap = exports.RestApiValidationErrorCode = exports.assertValidationError = exports.RestApiError = exports.isCancelError = exports.CanceledError = void 0;
|
|
6
|
+
var CanceledError_1 = require("./CanceledError");
|
|
7
|
+
Object.defineProperty(exports, "CanceledError", { enumerable: true, get: function () { return CanceledError_1.CanceledError; } });
|
|
8
|
+
Object.defineProperty(exports, "isCancelError", { enumerable: true, get: function () { return CanceledError_1.isCancelError; } });
|
|
9
9
|
var RestApiError_1 = require("./RestApiError");
|
|
10
10
|
Object.defineProperty(exports, "RestApiError", { enumerable: true, get: function () { return RestApiError_1.RestApiError; } });
|
|
11
11
|
var assertValidatonError_1 = require("./assertValidatonError");
|
package/lib/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { isCancelError } from './errors/
|
|
1
|
+
export { isCancelError } from './errors/CanceledError';
|
|
2
2
|
export { get, post, put, del, head, patch } from './apis';
|
package/lib/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 = exports.isCancelError = void 0;
|
|
6
|
-
var
|
|
7
|
-
Object.defineProperty(exports, "isCancelError", { enumerable: true, get: function () { return
|
|
6
|
+
var CanceledError_1 = require("./errors/CanceledError");
|
|
7
|
+
Object.defineProperty(exports, "isCancelError", { enumerable: true, get: function () { return CanceledError_1.isCancelError; } });
|
|
8
8
|
var apis_1 = require("./apis");
|
|
9
9
|
Object.defineProperty(exports, "get", { enumerable: true, get: function () { return apis_1.get; } });
|
|
10
10
|
Object.defineProperty(exports, "post", { enumerable: true, get: function () { return apis_1.post; } });
|
package/lib/server.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { isCancelError } from './errors/
|
|
1
|
+
export { isCancelError } from './errors/CanceledError';
|
|
2
2
|
export { get, post, put, del, head, patch } from './apis/server';
|
package/lib/server.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 = exports.isCancelError = void 0;
|
|
6
|
-
var
|
|
7
|
-
Object.defineProperty(exports, "isCancelError", { enumerable: true, get: function () { return
|
|
6
|
+
var CanceledError_1 = require("./errors/CanceledError");
|
|
7
|
+
Object.defineProperty(exports, "isCancelError", { enumerable: true, get: function () { return CanceledError_1.isCancelError; } });
|
|
8
8
|
var server_1 = require("./apis/server");
|
|
9
9
|
Object.defineProperty(exports, "get", { enumerable: true, get: function () { return server_1.get; } });
|
|
10
10
|
Object.defineProperty(exports, "post", { enumerable: true, get: function () { return server_1.post; } });
|