@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-esm/apis/server.js
CHANGED
|
@@ -4,36 +4,161 @@ import { getAmplifyServerContext, } from '@aws-amplify/core/internals/adapter-co
|
|
|
4
4
|
import { get as commonGet, post as commonPost, put as commonPut, del as commonDel, head as commonHead, patch as commonPatch, } from './common/publicApis';
|
|
5
5
|
/**
|
|
6
6
|
* GET HTTP request (server-side)
|
|
7
|
+
* @param {AmplifyServer.ContextSpec} contextSpec - The context spec used to get the Amplify server context.
|
|
8
|
+
* @param {GetInput} input - Input for GET operation.
|
|
9
|
+
* @throws - {@link RestApiError}
|
|
10
|
+
* @example
|
|
11
|
+
* Send a GET request
|
|
12
|
+
* ```js
|
|
13
|
+
* import { get } from 'aws-amplify/api/server';
|
|
14
|
+
* //...
|
|
15
|
+
* const restApiResponse = await runWithAmplifyServerContext({
|
|
16
|
+
* nextServerContext: { request, response },
|
|
17
|
+
* operation: async (contextSpec) => {
|
|
18
|
+
* try {
|
|
19
|
+
* const { body } = await get(contextSpec, input).response;
|
|
20
|
+
* return await body.json();
|
|
21
|
+
* } catch (error) {
|
|
22
|
+
* console.log(error);
|
|
23
|
+
* return false;
|
|
24
|
+
* }
|
|
25
|
+
* },
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
* @see {@link clientGet}
|
|
7
29
|
*/
|
|
8
30
|
export var get = function (contextSpec, input) {
|
|
9
31
|
return commonGet(getAmplifyServerContext(contextSpec).amplify, input);
|
|
10
32
|
};
|
|
11
33
|
/**
|
|
12
34
|
* POST HTTP request (server-side)
|
|
35
|
+
* @param {AmplifyServer.ContextSpec} contextSpec - The context spec used to get the Amplify server context.
|
|
36
|
+
* @param {PostInput} input - Input for POST operation.
|
|
37
|
+
* @throws - {@link RestApiError}
|
|
38
|
+
* @example
|
|
39
|
+
* Send a POST request
|
|
40
|
+
* ```js
|
|
41
|
+
* import { post } from 'aws-amplify/api/server';
|
|
42
|
+
* //...
|
|
43
|
+
* const restApiResponse = await runWithAmplifyServerContext({
|
|
44
|
+
* nextServerContext: { request, response },
|
|
45
|
+
* operation: async (contextSpec) => {
|
|
46
|
+
* try {
|
|
47
|
+
* const { body } = await post(contextSpec, input).response;
|
|
48
|
+
* return await body.json();
|
|
49
|
+
* } catch (error) {
|
|
50
|
+
* console.log(error);
|
|
51
|
+
* return false;
|
|
52
|
+
* }
|
|
53
|
+
* },
|
|
54
|
+
* });
|
|
55
|
+
* ```
|
|
13
56
|
*/
|
|
14
57
|
export var post = function (contextSpec, input) {
|
|
15
58
|
return commonPost(getAmplifyServerContext(contextSpec).amplify, input);
|
|
16
59
|
};
|
|
17
60
|
/**
|
|
18
61
|
* PUT HTTP request (server-side)
|
|
62
|
+
* @param {AmplifyServer.ContextSpec} contextSpec - The context spec used to get the Amplify server context.
|
|
63
|
+
* @param {PutInput} input - Input for PUT operation.
|
|
64
|
+
* @throws - {@link RestApiError}
|
|
65
|
+
* @example
|
|
66
|
+
* Send a PUT request
|
|
67
|
+
* ```js
|
|
68
|
+
* import { put } from 'aws-amplify/api/server';
|
|
69
|
+
* //...
|
|
70
|
+
* const restApiResponse = await runWithAmplifyServerContext({
|
|
71
|
+
* nextServerContext: { request, response },
|
|
72
|
+
* operation: async (contextSpec) => {
|
|
73
|
+
* try {
|
|
74
|
+
* const { body } = await put(contextSpec, input).response;
|
|
75
|
+
* return await body.json();
|
|
76
|
+
* } catch (error) {
|
|
77
|
+
* console.log(error);
|
|
78
|
+
* return false;
|
|
79
|
+
* }
|
|
80
|
+
* },
|
|
81
|
+
* });
|
|
82
|
+
* ```
|
|
19
83
|
*/
|
|
20
84
|
export var put = function (contextSpec, input) {
|
|
21
85
|
return commonPut(getAmplifyServerContext(contextSpec).amplify, input);
|
|
22
86
|
};
|
|
23
87
|
/**
|
|
24
88
|
* DELETE HTTP request (server-side)
|
|
89
|
+
* @param {AmplifyServer.ContextSpec} contextSpec - The context spec used to get the Amplify server context.
|
|
90
|
+
* @param {DeleteInput} input - Input for DELETE operation.
|
|
91
|
+
* @throws - {@link RestApiError}
|
|
92
|
+
* @example
|
|
93
|
+
* Send a DELETE request
|
|
94
|
+
* ```js
|
|
95
|
+
* import { del } from 'aws-amplify/api/server';
|
|
96
|
+
* //...
|
|
97
|
+
* const restApiResponse = await runWithAmplifyServerContext({
|
|
98
|
+
* nextServerContext: { request, response },
|
|
99
|
+
* operation: async (contextSpec) => {
|
|
100
|
+
* try {
|
|
101
|
+
* const { headers } = await del(contextSpec, input).response;
|
|
102
|
+
* } catch (error) {
|
|
103
|
+
* console.log(error);
|
|
104
|
+
* return false;
|
|
105
|
+
* }
|
|
106
|
+
* },
|
|
107
|
+
* });
|
|
108
|
+
* ```
|
|
25
109
|
*/
|
|
26
110
|
export var del = function (contextSpec, input) {
|
|
27
111
|
return commonDel(getAmplifyServerContext(contextSpec).amplify, input);
|
|
28
112
|
};
|
|
29
113
|
/**
|
|
30
114
|
* HEAD HTTP request (server-side)
|
|
115
|
+
* @param {AmplifyServer.ContextSpec} contextSpec - The context spec used to get the Amplify server context.
|
|
116
|
+
* @param {HeadInput} input - Input for HEAD operation.
|
|
117
|
+
* @throws - {@link RestApiError}
|
|
118
|
+
* @example
|
|
119
|
+
* Send a HEAD request
|
|
120
|
+
* ```js
|
|
121
|
+
* import { head } from 'aws-amplify/api/server';
|
|
122
|
+
* //...
|
|
123
|
+
* const restApiResponse = await runWithAmplifyServerContext({
|
|
124
|
+
* nextServerContext: { request, response },
|
|
125
|
+
* operation: async (contextSpec) => {
|
|
126
|
+
* try {
|
|
127
|
+
* const { headers } = await head(contextSpec, input).response;
|
|
128
|
+
* } catch (error) {
|
|
129
|
+
* console.log(error);
|
|
130
|
+
* return false;
|
|
131
|
+
* }
|
|
132
|
+
* },
|
|
133
|
+
* });
|
|
134
|
+
* ```
|
|
31
135
|
*/
|
|
32
136
|
export var head = function (contextSpec, input) {
|
|
33
137
|
return commonHead(getAmplifyServerContext(contextSpec).amplify, input);
|
|
34
138
|
};
|
|
35
139
|
/**
|
|
36
140
|
* PATCH HTTP request (server-side)
|
|
141
|
+
* @param {AmplifyServer.ContextSpec} contextSpec - The context spec used to get the Amplify server context.
|
|
142
|
+
* @param {PatchInput} input - Input for PATCH operation.
|
|
143
|
+
* @throws - {@link RestApiError}
|
|
144
|
+
* @example
|
|
145
|
+
* Send a PATCH request
|
|
146
|
+
* ```js
|
|
147
|
+
* import { patch } from 'aws-amplify/api/server';
|
|
148
|
+
* //...
|
|
149
|
+
* const restApiResponse = await runWithAmplifyServerContext({
|
|
150
|
+
* nextServerContext: { request, response },
|
|
151
|
+
* operation: async (contextSpec) => {
|
|
152
|
+
* try {
|
|
153
|
+
* const { body } = await patch(contextSpec, input).response;
|
|
154
|
+
* return await body.json();
|
|
155
|
+
* } catch (error) {
|
|
156
|
+
* console.log(error);
|
|
157
|
+
* return false;
|
|
158
|
+
* }
|
|
159
|
+
* },
|
|
160
|
+
* });
|
|
161
|
+
* ```
|
|
37
162
|
*/
|
|
38
163
|
export var patch = function (contextSpec, input) {
|
|
39
164
|
return commonPatch(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,31 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { __assign, __extends } from "tslib";
|
|
4
|
+
import { RestApiError } from './RestApiError';
|
|
5
|
+
/**
|
|
6
|
+
* Internal-only class for CanceledError.
|
|
7
|
+
*
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
var CanceledError = /** @class */ (function (_super) {
|
|
11
|
+
__extends(CanceledError, _super);
|
|
12
|
+
function CanceledError(params) {
|
|
13
|
+
if (params === void 0) { params = {}; }
|
|
14
|
+
var _this = _super.call(this, __assign({ name: 'CanceledError', message: 'Request is canceled by user' }, params)) || this;
|
|
15
|
+
// TODO: Delete the following 2 lines after we change the build target to >= es2015
|
|
16
|
+
_this.constructor = CanceledError;
|
|
17
|
+
Object.setPrototypeOf(_this, CanceledError.prototype);
|
|
18
|
+
return _this;
|
|
19
|
+
}
|
|
20
|
+
return CanceledError;
|
|
21
|
+
}(RestApiError));
|
|
22
|
+
export { CanceledError };
|
|
23
|
+
/**
|
|
24
|
+
* Check if an error is caused by user calling `cancel()` in REST API.
|
|
25
|
+
*
|
|
26
|
+
* @note This function works **ONLY** for errors thrown by REST API. For GraphQL APIs, use `client.isCancelError(error)`
|
|
27
|
+
* instead. `client` is generated from `generateClient()` API from `aws-amplify/api`.
|
|
28
|
+
*/
|
|
29
|
+
export var isCancelError = function (error) {
|
|
30
|
+
return !!error && error instanceof CanceledError;
|
|
31
|
+
};
|
|
@@ -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-esm/errors/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
export {
|
|
3
|
+
export { CanceledError, isCancelError } from './CanceledError';
|
|
4
4
|
export { RestApiError } from './RestApiError';
|
|
5
5
|
export { assertValidationError } from './assertValidatonError';
|
|
6
6
|
export { RestApiValidationErrorCode, validationErrorMap } from './validation';
|
package/lib-esm/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-esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
export { isCancelError } from './errors/
|
|
3
|
+
export { isCancelError } from './errors/CanceledError';
|
|
4
4
|
export { get, post, put, del, head, patch } from './apis';
|
package/lib-esm/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-esm/server.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
export { isCancelError } from './errors/
|
|
3
|
+
export { isCancelError } from './errors/CanceledError';
|
|
4
4
|
export { get, post, put, del, head, patch } from './apis/server';
|