@aws-amplify/api-rest 3.5.6-api-v6-models.b3abc9b.0 → 4.0.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/README.md +3 -0
- package/internals/package.json +8 -0
- package/internals/server/package.json +8 -0
- package/lib/apis/common/handler.d.ts +27 -0
- package/lib/apis/common/handler.js +73 -0
- package/lib/apis/common/internalPost.d.ts +16 -0
- package/lib/apis/common/internalPost.js +65 -0
- package/lib/apis/common/publicApis.d.ts +8 -0
- package/lib/apis/common/publicApis.js +44 -0
- package/lib/apis/index.d.ts +203 -0
- package/lib/apis/index.js +215 -0
- package/lib/apis/server.d.ts +151 -0
- package/lib/apis/server.js +162 -0
- package/lib/errors/CanceledError.d.ts +17 -0
- package/lib/errors/CanceledError.js +32 -0
- package/lib/errors/RestApiError.d.ts +4 -0
- package/lib/errors/RestApiError.js +15 -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 +6 -0
- package/lib/errors/validation.js +19 -0
- package/lib/index.d.ts +2 -2
- package/lib/index.js +10 -6
- 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/server.d.ts +2 -0
- package/lib/server.js +14 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/types/index.d.ts +90 -37
- 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 +12 -0
- package/lib/utils/createCancellableOperation.js +63 -0
- package/lib/utils/index.d.ts +6 -0
- package/lib/utils/index.js +17 -0
- package/lib/utils/logger.d.ts +2 -0
- package/lib/utils/logger.js +7 -0
- package/lib/utils/normalizeHeaders.d.ts +1 -0
- package/lib/utils/normalizeHeaders.js +13 -0
- package/lib/utils/parseSigningInfo.d.ts +14 -0
- package/lib/utils/parseSigningInfo.js +41 -0
- package/lib/utils/resolveApiUrl.d.ts +12 -0
- package/lib/utils/resolveApiUrl.js +40 -0
- package/lib/utils/resolveCredentials.d.ts +5 -0
- package/lib/utils/resolveCredentials.js +15 -0
- package/lib/utils/serviceError.d.ts +10 -0
- package/lib/utils/serviceError.js +30 -0
- package/lib-esm/apis/common/handler.d.ts +27 -0
- package/lib-esm/apis/common/handler.js +69 -0
- package/lib-esm/apis/common/internalPost.d.ts +16 -0
- package/lib-esm/apis/common/internalPost.js +59 -0
- package/lib-esm/apis/common/publicApis.d.ts +8 -0
- package/lib-esm/apis/common/publicApis.js +35 -0
- package/lib-esm/apis/index.d.ts +203 -0
- package/lib-esm/apis/index.js +206 -0
- package/lib-esm/apis/server.d.ts +151 -0
- package/lib-esm/apis/server.js +153 -0
- package/lib-esm/errors/CanceledError.d.ts +17 -0
- package/lib-esm/errors/CanceledError.js +27 -0
- package/lib-esm/errors/RestApiError.d.ts +4 -0
- package/lib-esm/errors/RestApiError.js +11 -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 +6 -0
- package/lib-esm/errors/validation.js +16 -0
- package/lib-esm/index.d.ts +2 -2
- package/lib-esm/index.js +2 -3
- 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/server.d.ts +2 -0
- package/lib-esm/server.js +4 -0
- package/lib-esm/tsconfig.tsbuildinfo +1 -0
- package/lib-esm/types/index.d.ts +90 -37
- package/lib-esm/types/index.js +1 -23
- package/lib-esm/utils/constants.d.ts +8 -0
- package/lib-esm/utils/constants.js +10 -0
- package/lib-esm/utils/createCancellableOperation.d.ts +12 -0
- package/lib-esm/utils/createCancellableOperation.js +59 -0
- package/lib-esm/utils/index.d.ts +6 -0
- package/lib-esm/utils/index.js +8 -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 -0
- package/lib-esm/utils/normalizeHeaders.js +9 -0
- package/lib-esm/utils/parseSigningInfo.d.ts +14 -0
- package/lib-esm/utils/parseSigningInfo.js +37 -0
- package/lib-esm/utils/resolveApiUrl.d.ts +12 -0
- package/lib-esm/utils/resolveApiUrl.js +36 -0
- package/lib-esm/utils/resolveCredentials.d.ts +5 -0
- package/lib-esm/utils/resolveCredentials.js +11 -0
- package/lib-esm/utils/serviceError.d.ts +10 -0
- package/lib-esm/utils/serviceError.js +25 -0
- package/package.json +113 -105
- package/server/package.json +8 -0
- package/src/apis/common/handler.ts +109 -0
- package/src/apis/common/internalPost.ts +81 -0
- package/src/apis/common/publicApis.ts +99 -0
- package/src/apis/index.ts +239 -0
- package/src/apis/server.ts +209 -0
- package/src/errors/CanceledError.ts +33 -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 +20 -0
- package/src/index.ts +2 -2
- package/src/internals/index.ts +31 -0
- package/src/internals/server.ts +37 -0
- package/src/server.ts +5 -0
- package/src/types/index.ts +95 -44
- package/src/utils/constants.ts +15 -0
- package/src/utils/createCancellableOperation.ts +94 -0
- package/src/utils/index.ts +9 -0
- package/src/utils/logger.ts +6 -0
- package/src/utils/normalizeHeaders.ts +10 -0
- package/src/utils/parseSigningInfo.ts +52 -0
- package/src/utils/resolveApiUrl.ts +51 -0
- package/src/utils/resolveCredentials.ts +17 -0
- package/src/utils/serviceError.ts +35 -0
- package/lib/.tsbuildinfo +0 -3
- package/lib/RestAPI.d.ts +0 -108
- package/lib/RestAPI.js +0 -282
- package/lib/RestAPI.js.map +0 -1
- package/lib/RestClient.d.ts +0 -138
- package/lib/RestClient.js +0 -368
- package/lib/RestClient.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/types/index.js.map +0 -1
- package/lib-esm/.tsbuildinfo +0 -3
- package/lib-esm/RestAPI.d.ts +0 -108
- package/lib-esm/RestAPI.js +0 -280
- package/lib-esm/RestAPI.js.map +0 -1
- package/lib-esm/RestClient.d.ts +0 -138
- package/lib-esm/RestClient.js +0 -366
- package/lib-esm/RestClient.js.map +0 -1
- package/lib-esm/index.js.map +0 -1
- package/lib-esm/types/index.js.map +0 -1
- package/src/RestAPI.ts +0 -338
- package/src/RestClient.ts +0 -417
|
@@ -0,0 +1,151 @@
|
|
|
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
|
+
* @param {AmplifyServer.ContextSpec} contextSpec - The context spec used to get the Amplify server context.
|
|
6
|
+
* @param {GetInput} input - Input for GET operation.
|
|
7
|
+
* @throws - {@link RestApiError}
|
|
8
|
+
* @example
|
|
9
|
+
* Send a GET request
|
|
10
|
+
* ```js
|
|
11
|
+
* import { get } from 'aws-amplify/api/server';
|
|
12
|
+
* //...
|
|
13
|
+
* const restApiResponse = await runWithAmplifyServerContext({
|
|
14
|
+
* nextServerContext: { request, response },
|
|
15
|
+
* operation: async (contextSpec) => {
|
|
16
|
+
* try {
|
|
17
|
+
* const { body } = await get(contextSpec, input).response;
|
|
18
|
+
* return await body.json();
|
|
19
|
+
* } catch (error) {
|
|
20
|
+
* console.log(error);
|
|
21
|
+
* return false;
|
|
22
|
+
* }
|
|
23
|
+
* },
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
* @see {@link clientGet}
|
|
27
|
+
*/
|
|
28
|
+
export declare const get: (contextSpec: AmplifyServer.ContextSpec, input: GetInput) => GetOperation;
|
|
29
|
+
/**
|
|
30
|
+
* POST HTTP request (server-side)
|
|
31
|
+
* @param {AmplifyServer.ContextSpec} contextSpec - The context spec used to get the Amplify server context.
|
|
32
|
+
* @param {PostInput} input - Input for POST operation.
|
|
33
|
+
* @throws - {@link RestApiError}
|
|
34
|
+
* @example
|
|
35
|
+
* Send a POST request
|
|
36
|
+
* ```js
|
|
37
|
+
* import { post } from 'aws-amplify/api/server';
|
|
38
|
+
* //...
|
|
39
|
+
* const restApiResponse = await runWithAmplifyServerContext({
|
|
40
|
+
* nextServerContext: { request, response },
|
|
41
|
+
* operation: async (contextSpec) => {
|
|
42
|
+
* try {
|
|
43
|
+
* const { body } = await post(contextSpec, input).response;
|
|
44
|
+
* return await body.json();
|
|
45
|
+
* } catch (error) {
|
|
46
|
+
* console.log(error);
|
|
47
|
+
* return false;
|
|
48
|
+
* }
|
|
49
|
+
* },
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare const post: (contextSpec: AmplifyServer.ContextSpec, input: PostInput) => PostOperation;
|
|
54
|
+
/**
|
|
55
|
+
* PUT HTTP request (server-side)
|
|
56
|
+
* @param {AmplifyServer.ContextSpec} contextSpec - The context spec used to get the Amplify server context.
|
|
57
|
+
* @param {PutInput} input - Input for PUT operation.
|
|
58
|
+
* @throws - {@link RestApiError}
|
|
59
|
+
* @example
|
|
60
|
+
* Send a PUT request
|
|
61
|
+
* ```js
|
|
62
|
+
* import { put } from 'aws-amplify/api/server';
|
|
63
|
+
* //...
|
|
64
|
+
* const restApiResponse = await runWithAmplifyServerContext({
|
|
65
|
+
* nextServerContext: { request, response },
|
|
66
|
+
* operation: async (contextSpec) => {
|
|
67
|
+
* try {
|
|
68
|
+
* const { body } = await put(contextSpec, input).response;
|
|
69
|
+
* return await body.json();
|
|
70
|
+
* } catch (error) {
|
|
71
|
+
* console.log(error);
|
|
72
|
+
* return false;
|
|
73
|
+
* }
|
|
74
|
+
* },
|
|
75
|
+
* });
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export declare const put: (contextSpec: AmplifyServer.ContextSpec, input: PutInput) => PutOperation;
|
|
79
|
+
/**
|
|
80
|
+
* DELETE HTTP request (server-side)
|
|
81
|
+
* @param {AmplifyServer.ContextSpec} contextSpec - The context spec used to get the Amplify server context.
|
|
82
|
+
* @param {DeleteInput} input - Input for DELETE operation.
|
|
83
|
+
* @throws - {@link RestApiError}
|
|
84
|
+
* @example
|
|
85
|
+
* Send a DELETE request
|
|
86
|
+
* ```js
|
|
87
|
+
* import { del } from 'aws-amplify/api/server';
|
|
88
|
+
* //...
|
|
89
|
+
* const restApiResponse = await runWithAmplifyServerContext({
|
|
90
|
+
* nextServerContext: { request, response },
|
|
91
|
+
* operation: async (contextSpec) => {
|
|
92
|
+
* try {
|
|
93
|
+
* const { headers } = await del(contextSpec, input).response;
|
|
94
|
+
* } catch (error) {
|
|
95
|
+
* console.log(error);
|
|
96
|
+
* return false;
|
|
97
|
+
* }
|
|
98
|
+
* },
|
|
99
|
+
* });
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export declare const del: (contextSpec: AmplifyServer.ContextSpec, input: DeleteInput) => DeleteOperation;
|
|
103
|
+
/**
|
|
104
|
+
* HEAD HTTP request (server-side)
|
|
105
|
+
* @param {AmplifyServer.ContextSpec} contextSpec - The context spec used to get the Amplify server context.
|
|
106
|
+
* @param {HeadInput} input - Input for HEAD operation.
|
|
107
|
+
* @throws - {@link RestApiError}
|
|
108
|
+
* @example
|
|
109
|
+
* Send a HEAD request
|
|
110
|
+
* ```js
|
|
111
|
+
* import { head } from 'aws-amplify/api/server';
|
|
112
|
+
* //...
|
|
113
|
+
* const restApiResponse = await runWithAmplifyServerContext({
|
|
114
|
+
* nextServerContext: { request, response },
|
|
115
|
+
* operation: async (contextSpec) => {
|
|
116
|
+
* try {
|
|
117
|
+
* const { headers } = await head(contextSpec, input).response;
|
|
118
|
+
* } catch (error) {
|
|
119
|
+
* console.log(error);
|
|
120
|
+
* return false;
|
|
121
|
+
* }
|
|
122
|
+
* },
|
|
123
|
+
* });
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
export declare const head: (contextSpec: AmplifyServer.ContextSpec, input: HeadInput) => HeadOperation;
|
|
127
|
+
/**
|
|
128
|
+
* PATCH HTTP request (server-side)
|
|
129
|
+
* @param {AmplifyServer.ContextSpec} contextSpec - The context spec used to get the Amplify server context.
|
|
130
|
+
* @param {PatchInput} input - Input for PATCH operation.
|
|
131
|
+
* @throws - {@link RestApiError}
|
|
132
|
+
* @example
|
|
133
|
+
* Send a PATCH request
|
|
134
|
+
* ```js
|
|
135
|
+
* import { patch } from 'aws-amplify/api/server';
|
|
136
|
+
* //...
|
|
137
|
+
* const restApiResponse = await runWithAmplifyServerContext({
|
|
138
|
+
* nextServerContext: { request, response },
|
|
139
|
+
* operation: async (contextSpec) => {
|
|
140
|
+
* try {
|
|
141
|
+
* const { body } = await patch(contextSpec, input).response;
|
|
142
|
+
* return await body.json();
|
|
143
|
+
* } catch (error) {
|
|
144
|
+
* console.log(error);
|
|
145
|
+
* return false;
|
|
146
|
+
* }
|
|
147
|
+
* },
|
|
148
|
+
* });
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
export declare const patch: (contextSpec: AmplifyServer.ContextSpec, input: PatchInput) => PatchOperation;
|
|
@@ -0,0 +1,162 @@
|
|
|
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.patch = exports.head = exports.del = exports.put = exports.post = exports.get = void 0;
|
|
6
|
+
const adapter_core_1 = require("@aws-amplify/core/internals/adapter-core");
|
|
7
|
+
const publicApis_1 = require("./common/publicApis");
|
|
8
|
+
/**
|
|
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}
|
|
32
|
+
*/
|
|
33
|
+
const get = (contextSpec, input) => (0, publicApis_1.get)((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify, input);
|
|
34
|
+
exports.get = get;
|
|
35
|
+
/**
|
|
36
|
+
* POST HTTP request (server-side)
|
|
37
|
+
* @param {AmplifyServer.ContextSpec} contextSpec - The context spec used to get the Amplify server context.
|
|
38
|
+
* @param {PostInput} input - Input for POST operation.
|
|
39
|
+
* @throws - {@link RestApiError}
|
|
40
|
+
* @example
|
|
41
|
+
* Send a POST request
|
|
42
|
+
* ```js
|
|
43
|
+
* import { post } from 'aws-amplify/api/server';
|
|
44
|
+
* //...
|
|
45
|
+
* const restApiResponse = await runWithAmplifyServerContext({
|
|
46
|
+
* nextServerContext: { request, response },
|
|
47
|
+
* operation: async (contextSpec) => {
|
|
48
|
+
* try {
|
|
49
|
+
* const { body } = await post(contextSpec, input).response;
|
|
50
|
+
* return await body.json();
|
|
51
|
+
* } catch (error) {
|
|
52
|
+
* console.log(error);
|
|
53
|
+
* return false;
|
|
54
|
+
* }
|
|
55
|
+
* },
|
|
56
|
+
* });
|
|
57
|
+
* ```
|
|
58
|
+
*/
|
|
59
|
+
const post = (contextSpec, input) => (0, publicApis_1.post)((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify, input);
|
|
60
|
+
exports.post = post;
|
|
61
|
+
/**
|
|
62
|
+
* PUT HTTP request (server-side)
|
|
63
|
+
* @param {AmplifyServer.ContextSpec} contextSpec - The context spec used to get the Amplify server context.
|
|
64
|
+
* @param {PutInput} input - Input for PUT operation.
|
|
65
|
+
* @throws - {@link RestApiError}
|
|
66
|
+
* @example
|
|
67
|
+
* Send a PUT request
|
|
68
|
+
* ```js
|
|
69
|
+
* import { put } from 'aws-amplify/api/server';
|
|
70
|
+
* //...
|
|
71
|
+
* const restApiResponse = await runWithAmplifyServerContext({
|
|
72
|
+
* nextServerContext: { request, response },
|
|
73
|
+
* operation: async (contextSpec) => {
|
|
74
|
+
* try {
|
|
75
|
+
* const { body } = await put(contextSpec, input).response;
|
|
76
|
+
* return await body.json();
|
|
77
|
+
* } catch (error) {
|
|
78
|
+
* console.log(error);
|
|
79
|
+
* return false;
|
|
80
|
+
* }
|
|
81
|
+
* },
|
|
82
|
+
* });
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
const put = (contextSpec, input) => (0, publicApis_1.put)((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify, input);
|
|
86
|
+
exports.put = put;
|
|
87
|
+
/**
|
|
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
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
const del = (contextSpec, input) => (0, publicApis_1.del)((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify, input);
|
|
111
|
+
exports.del = del;
|
|
112
|
+
/**
|
|
113
|
+
* HEAD HTTP request (server-side)
|
|
114
|
+
* @param {AmplifyServer.ContextSpec} contextSpec - The context spec used to get the Amplify server context.
|
|
115
|
+
* @param {HeadInput} input - Input for HEAD operation.
|
|
116
|
+
* @throws - {@link RestApiError}
|
|
117
|
+
* @example
|
|
118
|
+
* Send a HEAD request
|
|
119
|
+
* ```js
|
|
120
|
+
* import { head } from 'aws-amplify/api/server';
|
|
121
|
+
* //...
|
|
122
|
+
* const restApiResponse = await runWithAmplifyServerContext({
|
|
123
|
+
* nextServerContext: { request, response },
|
|
124
|
+
* operation: async (contextSpec) => {
|
|
125
|
+
* try {
|
|
126
|
+
* const { headers } = await head(contextSpec, input).response;
|
|
127
|
+
* } catch (error) {
|
|
128
|
+
* console.log(error);
|
|
129
|
+
* return false;
|
|
130
|
+
* }
|
|
131
|
+
* },
|
|
132
|
+
* });
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
const head = (contextSpec, input) => (0, publicApis_1.head)((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify, input);
|
|
136
|
+
exports.head = head;
|
|
137
|
+
/**
|
|
138
|
+
* PATCH HTTP request (server-side)
|
|
139
|
+
* @param {AmplifyServer.ContextSpec} contextSpec - The context spec used to get the Amplify server context.
|
|
140
|
+
* @param {PatchInput} input - Input for PATCH operation.
|
|
141
|
+
* @throws - {@link RestApiError}
|
|
142
|
+
* @example
|
|
143
|
+
* Send a PATCH request
|
|
144
|
+
* ```js
|
|
145
|
+
* import { patch } from 'aws-amplify/api/server';
|
|
146
|
+
* //...
|
|
147
|
+
* const restApiResponse = await runWithAmplifyServerContext({
|
|
148
|
+
* nextServerContext: { request, response },
|
|
149
|
+
* operation: async (contextSpec) => {
|
|
150
|
+
* try {
|
|
151
|
+
* const { body } = await patch(contextSpec, input).response;
|
|
152
|
+
* return await body.json();
|
|
153
|
+
* } catch (error) {
|
|
154
|
+
* console.log(error);
|
|
155
|
+
* return false;
|
|
156
|
+
* }
|
|
157
|
+
* },
|
|
158
|
+
* });
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
const patch = (contextSpec, input) => (0, publicApis_1.patch)((0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify, input);
|
|
162
|
+
exports.patch = patch;
|
|
@@ -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,32 @@
|
|
|
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
|
+
const RestApiError_1 = require("./RestApiError");
|
|
7
|
+
/**
|
|
8
|
+
* Internal-only class for CanceledError.
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
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
|
+
});
|
|
19
|
+
// TODO: Delete the following 2 lines after we change the build target to >= es2015
|
|
20
|
+
this.constructor = CanceledError;
|
|
21
|
+
Object.setPrototypeOf(this, CanceledError.prototype);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.CanceledError = CanceledError;
|
|
25
|
+
/**
|
|
26
|
+
* Check if an error is caused by user calling `cancel()` in REST API.
|
|
27
|
+
*
|
|
28
|
+
* @note This function works **ONLY** for errors thrown by REST API. For GraphQL APIs, use `client.isCancelError(error)`
|
|
29
|
+
* instead. `client` is generated from `generateClient()` API from `aws-amplify/api`.
|
|
30
|
+
*/
|
|
31
|
+
const isCancelError = (error) => !!error && error instanceof CanceledError;
|
|
32
|
+
exports.isCancelError = isCancelError;
|
|
@@ -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.RestApiError = void 0;
|
|
6
|
+
const utils_1 = require("@aws-amplify/core/internals/utils");
|
|
7
|
+
class RestApiError extends utils_1.AmplifyError {
|
|
8
|
+
constructor(params) {
|
|
9
|
+
super(params);
|
|
10
|
+
// TODO: Delete the following 2 lines after we change the build target to >= es2015
|
|
11
|
+
this.constructor = RestApiError;
|
|
12
|
+
Object.setPrototypeOf(this, RestApiError.prototype);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
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
|
+
const RestApiError_1 = require("./RestApiError");
|
|
7
|
+
const validation_1 = require("./validation");
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
function assertValidationError(assertion, name) {
|
|
12
|
+
const { message, recoverySuggestion } = validation_1.validationErrorMap[name];
|
|
13
|
+
if (!assertion) {
|
|
14
|
+
throw new RestApiError_1.RestApiError({ name, message, 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.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
|
+
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,6 @@
|
|
|
1
|
+
import { AmplifyErrorMap } from '@aws-amplify/core/internals/utils';
|
|
2
|
+
export declare enum RestApiValidationErrorCode {
|
|
3
|
+
NoCredentials = "NoCredentials",
|
|
4
|
+
InvalidApiName = "InvalidApiName"
|
|
5
|
+
}
|
|
6
|
+
export declare const validationErrorMap: AmplifyErrorMap<RestApiValidationErrorCode>;
|
|
@@ -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.validationErrorMap = exports.RestApiValidationErrorCode = void 0;
|
|
6
|
+
var RestApiValidationErrorCode;
|
|
7
|
+
(function (RestApiValidationErrorCode) {
|
|
8
|
+
RestApiValidationErrorCode["NoCredentials"] = "NoCredentials";
|
|
9
|
+
RestApiValidationErrorCode["InvalidApiName"] = "InvalidApiName";
|
|
10
|
+
})(RestApiValidationErrorCode = exports.RestApiValidationErrorCode || (exports.RestApiValidationErrorCode = {}));
|
|
11
|
+
exports.validationErrorMap = {
|
|
12
|
+
[RestApiValidationErrorCode.NoCredentials]: {
|
|
13
|
+
message: 'Credentials should not be empty.',
|
|
14
|
+
},
|
|
15
|
+
[RestApiValidationErrorCode.InvalidApiName]: {
|
|
16
|
+
message: 'API name is invalid.',
|
|
17
|
+
recoverySuggestion: 'Check if the API name matches the one in your configuration or `aws-exports.js`',
|
|
18
|
+
},
|
|
19
|
+
};
|
package/lib/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
1
|
+
export { isCancelError } from './errors/CanceledError';
|
|
2
|
+
export { get, post, put, del, head, patch } from './apis';
|
package/lib/index.js
CHANGED
|
@@ -2,9 +2,13 @@
|
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
exports
|
|
8
|
-
var
|
|
9
|
-
exports
|
|
10
|
-
|
|
5
|
+
exports.patch = exports.head = exports.del = exports.put = exports.post = exports.get = exports.isCancelError = void 0;
|
|
6
|
+
var CanceledError_1 = require("./errors/CanceledError");
|
|
7
|
+
Object.defineProperty(exports, "isCancelError", { enumerable: true, get: function () { return CanceledError_1.isCancelError; } });
|
|
8
|
+
var apis_1 = require("./apis");
|
|
9
|
+
Object.defineProperty(exports, "get", { enumerable: true, get: function () { return apis_1.get; } });
|
|
10
|
+
Object.defineProperty(exports, "post", { enumerable: true, get: function () { return apis_1.post; } });
|
|
11
|
+
Object.defineProperty(exports, "put", { enumerable: true, get: function () { return apis_1.put; } });
|
|
12
|
+
Object.defineProperty(exports, "del", { enumerable: true, get: function () { return apis_1.del; } });
|
|
13
|
+
Object.defineProperty(exports, "head", { enumerable: true, get: function () { return apis_1.head; } });
|
|
14
|
+
Object.defineProperty(exports, "patch", { enumerable: true, get: function () { return apis_1.patch; } });
|
|
@@ -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 '../apis/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
|
+
const core_1 = require("@aws-amplify/core");
|
|
7
|
+
const internalPost_1 = require("../apis/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
|
+
const post = (input) => {
|
|
25
|
+
return (0, internalPost_1.post)(core_1.Amplify, input);
|
|
26
|
+
};
|
|
27
|
+
exports.post = post;
|
|
28
|
+
var internalPost_2 = require("../apis/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 '../apis/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
|
+
const adapter_core_1 = require("@aws-amplify/core/internals/adapter-core");
|
|
7
|
+
const internalPost_1 = require("../apis/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
|
+
const post = (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("../apis/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; } });
|
package/lib/server.d.ts
ADDED
package/lib/server.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
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.patch = exports.head = exports.del = exports.put = exports.post = exports.get = exports.isCancelError = void 0;
|
|
6
|
+
var CanceledError_1 = require("./errors/CanceledError");
|
|
7
|
+
Object.defineProperty(exports, "isCancelError", { enumerable: true, get: function () { return CanceledError_1.isCancelError; } });
|
|
8
|
+
var server_1 = require("./apis/server");
|
|
9
|
+
Object.defineProperty(exports, "get", { enumerable: true, get: function () { return server_1.get; } });
|
|
10
|
+
Object.defineProperty(exports, "post", { enumerable: true, get: function () { return server_1.post; } });
|
|
11
|
+
Object.defineProperty(exports, "put", { enumerable: true, get: function () { return server_1.put; } });
|
|
12
|
+
Object.defineProperty(exports, "del", { enumerable: true, get: function () { return server_1.del; } });
|
|
13
|
+
Object.defineProperty(exports, "head", { enumerable: true, get: function () { return server_1.head; } });
|
|
14
|
+
Object.defineProperty(exports, "patch", { enumerable: true, get: function () { return server_1.patch; } });
|