@aws-amplify/api-rest 2.0.62-unstable.4 → 2.0.62
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/CHANGELOG.md +16 -0
- package/build.js +5 -0
- package/dist/aws-amplify-api-rest.js +5064 -0
- package/dist/aws-amplify-api-rest.js.map +1 -0
- package/dist/aws-amplify-api-rest.min.js +2 -0
- package/dist/aws-amplify-api-rest.min.js.map +1 -0
- package/index-rn.js +3 -0
- package/index.js +7 -0
- package/lib/RestAPI.js +74 -7
- package/lib/RestAPI.js.map +1 -1
- package/lib/RestClient.js +81 -11
- package/lib/RestClient.js.map +1 -1
- package/lib/index.js +16 -4
- package/lib/index.js.map +1 -1
- package/lib/types/index.js +12 -2
- package/lib/types/index.js.map +1 -1
- package/lib-esm/RestAPI.js +70 -3
- package/lib-esm/RestAPI.js.map +1 -1
- package/lib-esm/RestClient.js +70 -3
- package/lib-esm/RestClient.js.map +1 -1
- package/lib-esm/index.d.ts +2 -0
- package/lib-esm/index.js +14 -2
- package/lib-esm/index.js.map +1 -1
- package/lib-esm/types/index.js +12 -2
- package/lib-esm/types/index.js.map +1 -1
- package/package.json +9 -13
- package/src/RestAPI.ts +12 -2
- package/src/RestClient.ts +12 -2
- package/src/index.ts +15 -2
- package/src/types/index.ts +12 -2
- package/webpack.config.dev.js +6 -0
- package/lib/RestAPI.d.ts +0 -108
- package/lib/RestClient.d.ts +0 -138
- package/lib/index.d.ts +0 -2
- package/lib/types/index.d.ts +0 -50
package/src/index.ts
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2017-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
|
|
5
|
+
* the License. A copy of the License is located at
|
|
6
|
+
*
|
|
7
|
+
* http://aws.amazon.com/apache2.0/
|
|
8
|
+
*
|
|
9
|
+
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
10
|
+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
|
|
11
|
+
* and limitations under the License.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { RestAPI } from './RestAPI';
|
|
3
15
|
|
|
4
16
|
export { RestAPI, RestAPIClass } from './RestAPI';
|
|
5
17
|
export { RestClient } from './RestClient';
|
|
18
|
+
export default RestAPI;
|
package/src/types/index.ts
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2017-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
|
|
5
|
+
* the License. A copy of the License is located at
|
|
6
|
+
*
|
|
7
|
+
* http://aws.amazon.com/apache2.0/
|
|
8
|
+
*
|
|
9
|
+
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
10
|
+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
|
|
11
|
+
* and limitations under the License.
|
|
12
|
+
*/
|
|
3
13
|
|
|
4
14
|
/**
|
|
5
15
|
* RestClient instance options
|
package/lib/RestAPI.d.ts
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Export Cloud Logic APIs
|
|
3
|
-
*/
|
|
4
|
-
export declare class RestAPIClass {
|
|
5
|
-
/**
|
|
6
|
-
* @private
|
|
7
|
-
*/
|
|
8
|
-
private _options;
|
|
9
|
-
private _api;
|
|
10
|
-
Credentials: import("@aws-amplify/core").CredentialsClass;
|
|
11
|
-
/**
|
|
12
|
-
* Initialize Rest API with AWS configuration
|
|
13
|
-
* @param {Object} options - Configuration object for API
|
|
14
|
-
*/
|
|
15
|
-
constructor(options: any);
|
|
16
|
-
getModuleName(): string;
|
|
17
|
-
/**
|
|
18
|
-
* Configure API part with aws configurations
|
|
19
|
-
* @param {Object} config - Configuration of the API
|
|
20
|
-
* @return {Object} - The current configuration
|
|
21
|
-
*/
|
|
22
|
-
configure(options: any): any;
|
|
23
|
-
/**
|
|
24
|
-
* Create an instance of API for the library
|
|
25
|
-
* @return - A promise of true if Success
|
|
26
|
-
*/
|
|
27
|
-
createInstance(): boolean;
|
|
28
|
-
/**
|
|
29
|
-
* Make a GET request
|
|
30
|
-
* @param {string} apiName - The api name of the request
|
|
31
|
-
* @param {string} path - The path of the request
|
|
32
|
-
* @param {json} [init] - Request extra params
|
|
33
|
-
* @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.
|
|
34
|
-
*/
|
|
35
|
-
get(apiName: any, path: any, init: any): Promise<any>;
|
|
36
|
-
/**
|
|
37
|
-
* Make a POST request
|
|
38
|
-
* @param {string} apiName - The api name of the request
|
|
39
|
-
* @param {string} path - The path of the request
|
|
40
|
-
* @param {json} [init] - Request extra params
|
|
41
|
-
* @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.
|
|
42
|
-
*/
|
|
43
|
-
post(apiName: any, path: any, init: any): Promise<any>;
|
|
44
|
-
/**
|
|
45
|
-
* Make a PUT request
|
|
46
|
-
* @param {string} apiName - The api name of the request
|
|
47
|
-
* @param {string} path - The path of the request
|
|
48
|
-
* @param {json} [init] - Request extra params
|
|
49
|
-
* @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.
|
|
50
|
-
*/
|
|
51
|
-
put(apiName: any, path: any, init: any): Promise<any>;
|
|
52
|
-
/**
|
|
53
|
-
* Make a PATCH request
|
|
54
|
-
* @param {string} apiName - The api name of the request
|
|
55
|
-
* @param {string} path - The path of the request
|
|
56
|
-
* @param {json} [init] - Request extra params
|
|
57
|
-
* @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.
|
|
58
|
-
*/
|
|
59
|
-
patch(apiName: any, path: any, init: any): Promise<any>;
|
|
60
|
-
/**
|
|
61
|
-
* Make a DEL request
|
|
62
|
-
* @param {string} apiName - The api name of the request
|
|
63
|
-
* @param {string} path - The path of the request
|
|
64
|
-
* @param {json} [init] - Request extra params
|
|
65
|
-
* @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.
|
|
66
|
-
*/
|
|
67
|
-
del(apiName: any, path: any, init: any): Promise<any>;
|
|
68
|
-
/**
|
|
69
|
-
* Make a HEAD request
|
|
70
|
-
* @param {string} apiName - The api name of the request
|
|
71
|
-
* @param {string} path - The path of the request
|
|
72
|
-
* @param {json} [init] - Request extra params
|
|
73
|
-
* @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.
|
|
74
|
-
*/
|
|
75
|
-
head(apiName: any, path: any, init: any): Promise<any>;
|
|
76
|
-
/**
|
|
77
|
-
* Checks to see if an error thrown is from an api request cancellation
|
|
78
|
-
* @param {any} error - Any error
|
|
79
|
-
* @return {boolean} - A boolean indicating if the error was from an api request cancellation
|
|
80
|
-
*/
|
|
81
|
-
isCancel(error: any): boolean;
|
|
82
|
-
/**
|
|
83
|
-
* Cancels an inflight request
|
|
84
|
-
* @param {any} request - request to cancel
|
|
85
|
-
* @return {boolean} - A boolean indicating if the request was cancelled
|
|
86
|
-
*/
|
|
87
|
-
cancel(request: Promise<any>, message?: string): boolean;
|
|
88
|
-
/**
|
|
89
|
-
* Check if the request has a corresponding cancel token in the WeakMap.
|
|
90
|
-
* @params request - The request promise
|
|
91
|
-
* @return if the request has a corresponding cancel token.
|
|
92
|
-
*/
|
|
93
|
-
hasCancelToken(request: Promise<any>): boolean;
|
|
94
|
-
/**
|
|
95
|
-
* Getting endpoint for API
|
|
96
|
-
* @param {string} apiName - The name of the api
|
|
97
|
-
* @return {string} - The endpoint of the api
|
|
98
|
-
*/
|
|
99
|
-
endpoint(apiName: any): Promise<string>;
|
|
100
|
-
/**
|
|
101
|
-
* Getting endpoint info for API
|
|
102
|
-
* @param {string} apiName - The name of the api
|
|
103
|
-
* @param {string} path - The path of the api that is going to accessed
|
|
104
|
-
* @return {ApiInfo} - The endpoint information for that api-name
|
|
105
|
-
*/
|
|
106
|
-
private getEndpointInfo;
|
|
107
|
-
}
|
|
108
|
-
export declare const RestAPI: RestAPIClass;
|
package/lib/RestClient.d.ts
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import { apiOptions, ApiInfo } from './types';
|
|
2
|
-
import { CancelTokenSource } from 'axios';
|
|
3
|
-
/**
|
|
4
|
-
* HTTP Client for REST requests. Send and receive JSON data.
|
|
5
|
-
* Sign request with AWS credentials if available
|
|
6
|
-
* Usage:
|
|
7
|
-
<pre>
|
|
8
|
-
const restClient = new RestClient();
|
|
9
|
-
restClient.get('...')
|
|
10
|
-
.then(function(data) {
|
|
11
|
-
console.log(data);
|
|
12
|
-
})
|
|
13
|
-
.catch(err => console.log(err));
|
|
14
|
-
</pre>
|
|
15
|
-
*/
|
|
16
|
-
export declare class RestClient {
|
|
17
|
-
private _options;
|
|
18
|
-
private _region;
|
|
19
|
-
private _service;
|
|
20
|
-
private _custom_header;
|
|
21
|
-
/**
|
|
22
|
-
* This weak map provides functionality to let clients cancel
|
|
23
|
-
* in-flight axios requests. https://github.com/axios/axios#cancellation
|
|
24
|
-
*
|
|
25
|
-
* 1. For every axios request, a unique cancel token is generated and added in the request.
|
|
26
|
-
* 2. Promise for fulfilling the request is then mapped to that unique cancel token.
|
|
27
|
-
* 3. The promise is returned to the client.
|
|
28
|
-
* 4. Clients can either wait for the promise to fulfill or call `API.cancel(promise)` to cancel the request.
|
|
29
|
-
* 5. If `API.cancel(promise)` is called, then the corresponding cancel token is retrieved from the map below.
|
|
30
|
-
* 6. Promise returned to the client will be in rejected state with the error provided during cancel.
|
|
31
|
-
* 7. Clients can check if the error is because of cancelling by calling `API.isCancel(error)`.
|
|
32
|
-
*
|
|
33
|
-
* For more details, see https://github.com/aws-amplify/amplify-js/pull/3769#issuecomment-552660025
|
|
34
|
-
*/
|
|
35
|
-
private _cancelTokenMap;
|
|
36
|
-
Credentials: import("@aws-amplify/core").CredentialsClass;
|
|
37
|
-
/**
|
|
38
|
-
* @param {RestClientOptions} [options] - Instance options
|
|
39
|
-
*/
|
|
40
|
-
constructor(options: apiOptions);
|
|
41
|
-
/**
|
|
42
|
-
* Update AWS credentials
|
|
43
|
-
* @param {AWSCredentials} credentials - AWS credentials
|
|
44
|
-
*
|
|
45
|
-
updateCredentials(credentials: AWSCredentials) {
|
|
46
|
-
this.options.credentials = credentials;
|
|
47
|
-
}
|
|
48
|
-
*/
|
|
49
|
-
/**
|
|
50
|
-
* Basic HTTP request. Customizable
|
|
51
|
-
* @param {string | ApiInfo } urlOrApiInfo - Full request URL or Api information
|
|
52
|
-
* @param {string} method - Request HTTP method
|
|
53
|
-
* @param {json} [init] - Request extra params
|
|
54
|
-
* @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.
|
|
55
|
-
*/
|
|
56
|
-
ajax(urlOrApiInfo: string | ApiInfo, method: string, init: any): Promise<any>;
|
|
57
|
-
/**
|
|
58
|
-
* GET HTTP request
|
|
59
|
-
* @param {string | ApiInfo } urlOrApiInfo - Full request URL or Api information
|
|
60
|
-
* @param {JSON} init - Request extra params
|
|
61
|
-
* @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.
|
|
62
|
-
*/
|
|
63
|
-
get(urlOrApiInfo: string | ApiInfo, init: any): Promise<any>;
|
|
64
|
-
/**
|
|
65
|
-
* PUT HTTP request
|
|
66
|
-
* @param {string | ApiInfo } urlOrApiInfo - Full request URL or Api information
|
|
67
|
-
* @param {json} init - Request extra params
|
|
68
|
-
* @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.
|
|
69
|
-
*/
|
|
70
|
-
put(urlOrApiInfo: string | ApiInfo, init: any): Promise<any>;
|
|
71
|
-
/**
|
|
72
|
-
* PATCH HTTP request
|
|
73
|
-
* @param {string | ApiInfo } urlOrApiInfo - Full request URL or Api information
|
|
74
|
-
* @param {json} init - Request extra params
|
|
75
|
-
* @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.
|
|
76
|
-
*/
|
|
77
|
-
patch(urlOrApiInfo: string | ApiInfo, init: any): Promise<any>;
|
|
78
|
-
/**
|
|
79
|
-
* POST HTTP request
|
|
80
|
-
* @param {string | ApiInfo } urlOrApiInfo - Full request URL or Api information
|
|
81
|
-
* @param {json} init - Request extra params
|
|
82
|
-
* @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.
|
|
83
|
-
*/
|
|
84
|
-
post(urlOrApiInfo: string | ApiInfo, init: any): Promise<any>;
|
|
85
|
-
/**
|
|
86
|
-
* DELETE HTTP request
|
|
87
|
-
* @param {string | ApiInfo } urlOrApiInfo - Full request URL or Api information
|
|
88
|
-
* @param {json} init - Request extra params
|
|
89
|
-
* @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.
|
|
90
|
-
*/
|
|
91
|
-
del(urlOrApiInfo: string | ApiInfo, init: any): Promise<any>;
|
|
92
|
-
/**
|
|
93
|
-
* HEAD HTTP request
|
|
94
|
-
* @param {string | ApiInfo } urlOrApiInfo - Full request URL or Api information
|
|
95
|
-
* @param {json} init - Request extra params
|
|
96
|
-
* @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.
|
|
97
|
-
*/
|
|
98
|
-
head(urlOrApiInfo: string | ApiInfo, init: any): Promise<any>;
|
|
99
|
-
/**
|
|
100
|
-
* Cancel an inflight API request
|
|
101
|
-
* @param {Promise<any>} request - The request promise to cancel
|
|
102
|
-
* @param {string} [message] - A message to include in the cancelation exception
|
|
103
|
-
*/
|
|
104
|
-
cancel(request: Promise<any>, message?: string): boolean;
|
|
105
|
-
/**
|
|
106
|
-
* Check if the request has a corresponding cancel token in the WeakMap.
|
|
107
|
-
* @params request - The request promise
|
|
108
|
-
* @return if the request has a corresponding cancel token.
|
|
109
|
-
*/
|
|
110
|
-
hasCancelToken(request: Promise<any>): boolean;
|
|
111
|
-
/**
|
|
112
|
-
* Checks to see if an error thrown is from an api request cancellation
|
|
113
|
-
* @param {any} error - Any error
|
|
114
|
-
* @return {boolean} - A boolean indicating if the error was from an api request cancellation
|
|
115
|
-
*/
|
|
116
|
-
isCancel(error: any): boolean;
|
|
117
|
-
/**
|
|
118
|
-
* Retrieves a new and unique cancel token which can be
|
|
119
|
-
* provided in an axios request to be cancelled later.
|
|
120
|
-
*/
|
|
121
|
-
getCancellableToken(): CancelTokenSource;
|
|
122
|
-
/**
|
|
123
|
-
* Updates the weakmap with a response promise and its
|
|
124
|
-
* cancel token such that the cancel token can be easily
|
|
125
|
-
* retrieved (and used for cancelling the request)
|
|
126
|
-
*/
|
|
127
|
-
updateRequestToBeCancellable(promise: Promise<any>, cancelTokenSource: CancelTokenSource): void;
|
|
128
|
-
/**
|
|
129
|
-
* Getting endpoint for API
|
|
130
|
-
* @param {string} apiName - The name of the api
|
|
131
|
-
* @return {string} - The endpoint of the api
|
|
132
|
-
*/
|
|
133
|
-
endpoint(apiName: string): string;
|
|
134
|
-
/** private methods **/
|
|
135
|
-
private _signed;
|
|
136
|
-
private _request;
|
|
137
|
-
private _parseUrl;
|
|
138
|
-
}
|
package/lib/index.d.ts
DELETED
package/lib/types/index.d.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* RestClient instance options
|
|
3
|
-
*/
|
|
4
|
-
export declare class RestClientOptions {
|
|
5
|
-
/** AWS credentials */
|
|
6
|
-
credentials: AWSCredentials;
|
|
7
|
-
/**
|
|
8
|
-
* Lookup key of AWS credentials.
|
|
9
|
-
* If credentials not provided then lookup from sessionStorage.
|
|
10
|
-
* Default 'awsCredentials'
|
|
11
|
-
*/
|
|
12
|
-
credentials_key: string;
|
|
13
|
-
/** Additional headers for all requests send by this client. e.g. user-agent */
|
|
14
|
-
headers: object;
|
|
15
|
-
constructor();
|
|
16
|
-
}
|
|
17
|
-
/**
|
|
18
|
-
* AWS credentials needed for RestClient
|
|
19
|
-
*/
|
|
20
|
-
export declare class AWSCredentials {
|
|
21
|
-
/**
|
|
22
|
-
* Secret Access Key
|
|
23
|
-
*
|
|
24
|
-
* [Access Key ID and Secret Access Key]
|
|
25
|
-
* (http://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys)
|
|
26
|
-
*/
|
|
27
|
-
secretAccessKey: string;
|
|
28
|
-
/**
|
|
29
|
-
* Access Key ID
|
|
30
|
-
*
|
|
31
|
-
* [Access Key ID and Secret Access Key]
|
|
32
|
-
* (http://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys)
|
|
33
|
-
*/
|
|
34
|
-
accessKeyId: string;
|
|
35
|
-
/** Access Token of current session */
|
|
36
|
-
sessionToken: string;
|
|
37
|
-
}
|
|
38
|
-
export interface apiOptions {
|
|
39
|
-
headers: object;
|
|
40
|
-
endpoints: object;
|
|
41
|
-
credentials?: object;
|
|
42
|
-
}
|
|
43
|
-
export declare type ApiInfo = {
|
|
44
|
-
endpoint: string;
|
|
45
|
-
region?: string;
|
|
46
|
-
service?: string;
|
|
47
|
-
custom_header?: () => {
|
|
48
|
-
[key: string]: string;
|
|
49
|
-
};
|
|
50
|
-
};
|