@aws-amplify/api-rest 3.5.6-unstable.7762f1a.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.
Files changed (147) hide show
  1. package/README.md +3 -0
  2. package/internals/package.json +8 -0
  3. package/internals/server/package.json +8 -0
  4. package/lib/apis/common/handler.d.ts +27 -0
  5. package/lib/apis/common/handler.js +73 -0
  6. package/lib/apis/common/internalPost.d.ts +16 -0
  7. package/lib/apis/common/internalPost.js +65 -0
  8. package/lib/apis/common/publicApis.d.ts +8 -0
  9. package/lib/apis/common/publicApis.js +44 -0
  10. package/lib/apis/index.d.ts +203 -0
  11. package/lib/apis/index.js +215 -0
  12. package/lib/apis/server.d.ts +151 -0
  13. package/lib/apis/server.js +162 -0
  14. package/lib/errors/CanceledError.d.ts +17 -0
  15. package/lib/errors/CanceledError.js +32 -0
  16. package/lib/errors/RestApiError.d.ts +4 -0
  17. package/lib/errors/RestApiError.js +15 -0
  18. package/lib/errors/assertValidatonError.d.ts +5 -0
  19. package/lib/errors/assertValidatonError.js +17 -0
  20. package/lib/errors/index.d.ts +4 -0
  21. package/lib/errors/index.js +15 -0
  22. package/lib/errors/validation.d.ts +6 -0
  23. package/lib/errors/validation.js +19 -0
  24. package/lib/index.d.ts +2 -2
  25. package/lib/index.js +10 -6
  26. package/lib/internals/index.d.ts +19 -0
  27. package/lib/internals/index.js +30 -0
  28. package/lib/internals/server.d.ts +20 -0
  29. package/lib/internals/server.js +30 -0
  30. package/lib/server.d.ts +2 -0
  31. package/lib/server.js +14 -0
  32. package/lib/tsconfig.tsbuildinfo +1 -0
  33. package/lib/types/index.d.ts +90 -37
  34. package/lib/types/index.js +0 -23
  35. package/lib/utils/constants.d.ts +8 -0
  36. package/lib/utils/constants.js +13 -0
  37. package/lib/utils/createCancellableOperation.d.ts +12 -0
  38. package/lib/utils/createCancellableOperation.js +63 -0
  39. package/lib/utils/index.d.ts +6 -0
  40. package/lib/utils/index.js +17 -0
  41. package/lib/utils/logger.d.ts +2 -0
  42. package/lib/utils/logger.js +7 -0
  43. package/lib/utils/normalizeHeaders.d.ts +1 -0
  44. package/lib/utils/normalizeHeaders.js +13 -0
  45. package/lib/utils/parseSigningInfo.d.ts +14 -0
  46. package/lib/utils/parseSigningInfo.js +41 -0
  47. package/lib/utils/resolveApiUrl.d.ts +12 -0
  48. package/lib/utils/resolveApiUrl.js +40 -0
  49. package/lib/utils/resolveCredentials.d.ts +5 -0
  50. package/lib/utils/resolveCredentials.js +15 -0
  51. package/lib/utils/serviceError.d.ts +10 -0
  52. package/lib/utils/serviceError.js +30 -0
  53. package/lib-esm/apis/common/handler.d.ts +27 -0
  54. package/lib-esm/apis/common/handler.js +69 -0
  55. package/lib-esm/apis/common/internalPost.d.ts +16 -0
  56. package/lib-esm/apis/common/internalPost.js +59 -0
  57. package/lib-esm/apis/common/publicApis.d.ts +8 -0
  58. package/lib-esm/apis/common/publicApis.js +35 -0
  59. package/lib-esm/apis/index.d.ts +203 -0
  60. package/lib-esm/apis/index.js +206 -0
  61. package/lib-esm/apis/server.d.ts +151 -0
  62. package/lib-esm/apis/server.js +153 -0
  63. package/lib-esm/errors/CanceledError.d.ts +17 -0
  64. package/lib-esm/errors/CanceledError.js +27 -0
  65. package/lib-esm/errors/RestApiError.d.ts +4 -0
  66. package/lib-esm/errors/RestApiError.js +11 -0
  67. package/lib-esm/errors/assertValidatonError.d.ts +5 -0
  68. package/lib-esm/errors/assertValidatonError.js +13 -0
  69. package/lib-esm/errors/index.d.ts +4 -0
  70. package/lib-esm/errors/index.js +6 -0
  71. package/lib-esm/errors/validation.d.ts +6 -0
  72. package/lib-esm/errors/validation.js +16 -0
  73. package/lib-esm/index.d.ts +2 -2
  74. package/lib-esm/index.js +2 -3
  75. package/lib-esm/internals/index.d.ts +19 -0
  76. package/lib-esm/internals/index.js +24 -0
  77. package/lib-esm/internals/server.d.ts +20 -0
  78. package/lib-esm/internals/server.js +24 -0
  79. package/lib-esm/server.d.ts +2 -0
  80. package/lib-esm/server.js +4 -0
  81. package/lib-esm/tsconfig.tsbuildinfo +1 -0
  82. package/lib-esm/types/index.d.ts +90 -37
  83. package/lib-esm/types/index.js +1 -23
  84. package/lib-esm/utils/constants.d.ts +8 -0
  85. package/lib-esm/utils/constants.js +10 -0
  86. package/lib-esm/utils/createCancellableOperation.d.ts +12 -0
  87. package/lib-esm/utils/createCancellableOperation.js +59 -0
  88. package/lib-esm/utils/index.d.ts +6 -0
  89. package/lib-esm/utils/index.js +8 -0
  90. package/lib-esm/utils/logger.d.ts +2 -0
  91. package/lib-esm/utils/logger.js +4 -0
  92. package/lib-esm/utils/normalizeHeaders.d.ts +1 -0
  93. package/lib-esm/utils/normalizeHeaders.js +9 -0
  94. package/lib-esm/utils/parseSigningInfo.d.ts +14 -0
  95. package/lib-esm/utils/parseSigningInfo.js +37 -0
  96. package/lib-esm/utils/resolveApiUrl.d.ts +12 -0
  97. package/lib-esm/utils/resolveApiUrl.js +36 -0
  98. package/lib-esm/utils/resolveCredentials.d.ts +5 -0
  99. package/lib-esm/utils/resolveCredentials.js +11 -0
  100. package/lib-esm/utils/serviceError.d.ts +10 -0
  101. package/lib-esm/utils/serviceError.js +25 -0
  102. package/package.json +113 -105
  103. package/server/package.json +8 -0
  104. package/src/apis/common/handler.ts +109 -0
  105. package/src/apis/common/internalPost.ts +81 -0
  106. package/src/apis/common/publicApis.ts +99 -0
  107. package/src/apis/index.ts +239 -0
  108. package/src/apis/server.ts +209 -0
  109. package/src/errors/CanceledError.ts +33 -0
  110. package/src/errors/RestApiError.ts +17 -0
  111. package/src/errors/assertValidatonError.ts +19 -0
  112. package/src/errors/index.ts +7 -0
  113. package/src/errors/validation.ts +20 -0
  114. package/src/index.ts +2 -2
  115. package/src/internals/index.ts +31 -0
  116. package/src/internals/server.ts +37 -0
  117. package/src/server.ts +5 -0
  118. package/src/types/index.ts +95 -44
  119. package/src/utils/constants.ts +15 -0
  120. package/src/utils/createCancellableOperation.ts +94 -0
  121. package/src/utils/index.ts +9 -0
  122. package/src/utils/logger.ts +6 -0
  123. package/src/utils/normalizeHeaders.ts +10 -0
  124. package/src/utils/parseSigningInfo.ts +52 -0
  125. package/src/utils/resolveApiUrl.ts +51 -0
  126. package/src/utils/resolveCredentials.ts +17 -0
  127. package/src/utils/serviceError.ts +35 -0
  128. package/lib/.tsbuildinfo +0 -3
  129. package/lib/RestAPI.d.ts +0 -108
  130. package/lib/RestAPI.js +0 -282
  131. package/lib/RestAPI.js.map +0 -1
  132. package/lib/RestClient.d.ts +0 -138
  133. package/lib/RestClient.js +0 -368
  134. package/lib/RestClient.js.map +0 -1
  135. package/lib/index.js.map +0 -1
  136. package/lib/types/index.js.map +0 -1
  137. package/lib-esm/.tsbuildinfo +0 -3
  138. package/lib-esm/RestAPI.d.ts +0 -108
  139. package/lib-esm/RestAPI.js +0 -280
  140. package/lib-esm/RestAPI.js.map +0 -1
  141. package/lib-esm/RestClient.d.ts +0 -138
  142. package/lib-esm/RestClient.js +0 -366
  143. package/lib-esm/RestClient.js.map +0 -1
  144. package/lib-esm/index.js.map +0 -1
  145. package/lib-esm/types/index.js.map +0 -1
  146. package/src/RestAPI.ts +0 -338
  147. package/src/RestClient.ts +0 -417
@@ -1,280 +0,0 @@
1
- import { __assign, __awaiter, __generator, __rest } from "tslib";
2
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
- // SPDX-License-Identifier: Apache-2.0
4
- import { RestClient } from './RestClient';
5
- import { Amplify, ConsoleLogger as Logger, Credentials, } from '@aws-amplify/core';
6
- var logger = new Logger('RestAPI');
7
- /**
8
- * Export Cloud Logic APIs
9
- */
10
- var RestAPIClass = /** @class */ (function () {
11
- /**
12
- * Initialize Rest API with AWS configuration
13
- * @param {Object} options - Configuration object for API
14
- */
15
- function RestAPIClass(options) {
16
- this._api = null;
17
- this.Credentials = Credentials;
18
- this._options = options;
19
- logger.debug('API Options', this._options);
20
- }
21
- RestAPIClass.prototype.getModuleName = function () {
22
- return 'RestAPI';
23
- };
24
- /**
25
- * Configure API part with aws configurations
26
- * @param {Object} config - Configuration of the API
27
- * @return {Object} - The current configuration
28
- */
29
- RestAPIClass.prototype.configure = function (options) {
30
- var _a = options || {}, _b = _a.API, API = _b === void 0 ? {} : _b, otherOptions = __rest(_a, ["API"]);
31
- var opt = __assign(__assign({}, otherOptions), API);
32
- logger.debug('configure Rest API', { opt: opt });
33
- if (opt['aws_project_region']) {
34
- if (opt['aws_cloud_logic_custom']) {
35
- var custom = opt['aws_cloud_logic_custom'];
36
- opt.endpoints =
37
- typeof custom === 'string' ? JSON.parse(custom) : custom;
38
- }
39
- opt = Object.assign({}, opt, {
40
- region: opt['aws_project_region'],
41
- header: {},
42
- });
43
- }
44
- if (Array.isArray(opt.endpoints)) {
45
- // Check if endpoints has custom_headers and validate if is a function
46
- opt.endpoints.forEach(function (endpoint) {
47
- if (typeof endpoint.custom_header !== 'undefined' &&
48
- typeof endpoint.custom_header !== 'function') {
49
- logger.warn('Rest API ' + endpoint.name + ', custom_header should be a function');
50
- endpoint.custom_header = undefined;
51
- }
52
- });
53
- }
54
- else if (this._options && Array.isArray(this._options.endpoints)) {
55
- opt.endpoints = this._options.endpoints;
56
- }
57
- else {
58
- opt.endpoints = [];
59
- }
60
- this._options = Object.assign({}, this._options, opt);
61
- this.createInstance();
62
- return this._options;
63
- };
64
- /**
65
- * Create an instance of API for the library
66
- * @return - A promise of true if Success
67
- */
68
- RestAPIClass.prototype.createInstance = function () {
69
- logger.debug('create Rest API instance');
70
- this._api = new RestClient(this._options);
71
- // Share Amplify instance with client for SSR
72
- this._api.Credentials = this.Credentials;
73
- return true;
74
- };
75
- /**
76
- * Make a GET request
77
- * @param {string} apiName - The api name of the request
78
- * @param {string} path - The path of the request
79
- * @param {json} [init] - Request extra params
80
- * @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.
81
- */
82
- RestAPIClass.prototype.get = function (apiName, path, init) {
83
- try {
84
- var apiInfo = this.getEndpointInfo(apiName, path);
85
- var cancellableToken = this._api.getCancellableToken();
86
- var initParams = Object.assign({}, init);
87
- initParams.cancellableToken = cancellableToken;
88
- var responsePromise = this._api.get(apiInfo, initParams);
89
- this._api.updateRequestToBeCancellable(responsePromise, cancellableToken);
90
- return responsePromise;
91
- }
92
- catch (err) {
93
- return Promise.reject(err.message);
94
- }
95
- };
96
- /**
97
- * Make a POST request
98
- * @param {string} apiName - The api name of the request
99
- * @param {string} path - The path of the request
100
- * @param {json} [init] - Request extra params
101
- * @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.
102
- */
103
- RestAPIClass.prototype.post = function (apiName, path, init) {
104
- try {
105
- var apiInfo = this.getEndpointInfo(apiName, path);
106
- var cancellableToken = this._api.getCancellableToken();
107
- var initParams = Object.assign({}, init);
108
- initParams.cancellableToken = cancellableToken;
109
- var responsePromise = this._api.post(apiInfo, initParams);
110
- this._api.updateRequestToBeCancellable(responsePromise, cancellableToken);
111
- return responsePromise;
112
- }
113
- catch (err) {
114
- return Promise.reject(err.message);
115
- }
116
- };
117
- /**
118
- * Make a PUT request
119
- * @param {string} apiName - The api name of the request
120
- * @param {string} path - The path of the request
121
- * @param {json} [init] - Request extra params
122
- * @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.
123
- */
124
- RestAPIClass.prototype.put = function (apiName, path, init) {
125
- try {
126
- var apiInfo = this.getEndpointInfo(apiName, path);
127
- var cancellableToken = this._api.getCancellableToken();
128
- var initParams = Object.assign({}, init);
129
- initParams.cancellableToken = cancellableToken;
130
- var responsePromise = this._api.put(apiInfo, initParams);
131
- this._api.updateRequestToBeCancellable(responsePromise, cancellableToken);
132
- return responsePromise;
133
- }
134
- catch (err) {
135
- return Promise.reject(err.message);
136
- }
137
- };
138
- /**
139
- * Make a PATCH request
140
- * @param {string} apiName - The api name of the request
141
- * @param {string} path - The path of the request
142
- * @param {json} [init] - Request extra params
143
- * @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.
144
- */
145
- RestAPIClass.prototype.patch = function (apiName, path, init) {
146
- try {
147
- var apiInfo = this.getEndpointInfo(apiName, path);
148
- var cancellableToken = this._api.getCancellableToken();
149
- var initParams = Object.assign({}, init);
150
- initParams.cancellableToken = cancellableToken;
151
- var responsePromise = this._api.patch(apiInfo, initParams);
152
- this._api.updateRequestToBeCancellable(responsePromise, cancellableToken);
153
- return responsePromise;
154
- }
155
- catch (err) {
156
- return Promise.reject(err.message);
157
- }
158
- };
159
- /**
160
- * Make a DEL request
161
- * @param {string} apiName - The api name of the request
162
- * @param {string} path - The path of the request
163
- * @param {json} [init] - Request extra params
164
- * @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.
165
- */
166
- RestAPIClass.prototype.del = function (apiName, path, init) {
167
- try {
168
- var apiInfo = this.getEndpointInfo(apiName, path);
169
- var cancellableToken = this._api.getCancellableToken();
170
- var initParams = Object.assign({}, init);
171
- initParams.cancellableToken = cancellableToken;
172
- var responsePromise = this._api.del(apiInfo, initParams);
173
- this._api.updateRequestToBeCancellable(responsePromise, cancellableToken);
174
- return responsePromise;
175
- }
176
- catch (err) {
177
- return Promise.reject(err.message);
178
- }
179
- };
180
- /**
181
- * Make a HEAD request
182
- * @param {string} apiName - The api name of the request
183
- * @param {string} path - The path of the request
184
- * @param {json} [init] - Request extra params
185
- * @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.
186
- */
187
- RestAPIClass.prototype.head = function (apiName, path, init) {
188
- try {
189
- var apiInfo = this.getEndpointInfo(apiName, path);
190
- var cancellableToken = this._api.getCancellableToken();
191
- var initParams = Object.assign({}, init);
192
- initParams.cancellableToken = cancellableToken;
193
- var responsePromise = this._api.head(apiInfo, initParams);
194
- this._api.updateRequestToBeCancellable(responsePromise, cancellableToken);
195
- return responsePromise;
196
- }
197
- catch (err) {
198
- return Promise.reject(err.message);
199
- }
200
- };
201
- /**
202
- * Checks to see if an error thrown is from an api request cancellation
203
- * @param {any} error - Any error
204
- * @return {boolean} - A boolean indicating if the error was from an api request cancellation
205
- */
206
- RestAPIClass.prototype.isCancel = function (error) {
207
- return this._api.isCancel(error);
208
- };
209
- /**
210
- * Cancels an inflight request
211
- * @param {any} request - request to cancel
212
- * @return {boolean} - A boolean indicating if the request was cancelled
213
- */
214
- RestAPIClass.prototype.cancel = function (request, message) {
215
- return this._api.cancel(request, message);
216
- };
217
- /**
218
- * Check if the request has a corresponding cancel token in the WeakMap.
219
- * @params request - The request promise
220
- * @return if the request has a corresponding cancel token.
221
- */
222
- RestAPIClass.prototype.hasCancelToken = function (request) {
223
- return this._api.hasCancelToken(request);
224
- };
225
- /**
226
- * Getting endpoint for API
227
- * @param {string} apiName - The name of the api
228
- * @return {string} - The endpoint of the api
229
- */
230
- RestAPIClass.prototype.endpoint = function (apiName) {
231
- return __awaiter(this, void 0, void 0, function () {
232
- return __generator(this, function (_a) {
233
- return [2 /*return*/, this._api.endpoint(apiName)];
234
- });
235
- });
236
- };
237
- /**
238
- * Getting endpoint info for API
239
- * @param {string} apiName - The name of the api
240
- * @param {string} path - The path of the api that is going to accessed
241
- * @return {ApiInfo} - The endpoint information for that api-name
242
- */
243
- RestAPIClass.prototype.getEndpointInfo = function (apiName, path) {
244
- var cloud_logic_array = this._options.endpoints;
245
- if (!Array.isArray(cloud_logic_array)) {
246
- throw new Error("API category not configured");
247
- }
248
- var apiConfig = cloud_logic_array.find(function (api) { return api.name === apiName; });
249
- if (!apiConfig) {
250
- throw new Error("API " + apiName + " does not exist");
251
- }
252
- var response = {
253
- endpoint: apiConfig.endpoint + path,
254
- };
255
- if (typeof apiConfig.region === 'string') {
256
- response.region = apiConfig.region;
257
- }
258
- else if (typeof this._options.region === 'string') {
259
- response.region = this._options.region;
260
- }
261
- if (typeof apiConfig.service === 'string') {
262
- response.service = apiConfig.service || 'execute-api';
263
- }
264
- else {
265
- response.service = 'execute-api';
266
- }
267
- if (typeof apiConfig.custom_header === 'function') {
268
- response.custom_header = apiConfig.custom_header;
269
- }
270
- else {
271
- response.custom_header = undefined;
272
- }
273
- return response;
274
- };
275
- return RestAPIClass;
276
- }());
277
- export { RestAPIClass };
278
- export var RestAPI = new RestAPIClass(null);
279
- Amplify.register(RestAPI);
280
- //# sourceMappingURL=RestAPI.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"RestAPI.js","sourceRoot":"","sources":["../src/RestAPI.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;AACtC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EACN,OAAO,EACP,aAAa,IAAI,MAAM,EACvB,WAAW,GACX,MAAM,mBAAmB,CAAC;AAG3B,IAAM,MAAM,GAAG,IAAI,MAAM,CAAC,SAAS,CAAC,CAAC;AAErC;;GAEG;AACH;IASC;;;OAGG;IACH,sBAAY,OAAO;QARX,SAAI,GAAe,IAAI,CAAC;QAEhC,gBAAW,GAAG,WAAW,CAAC;QAOzB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,MAAM,CAAC,KAAK,CAAC,aAAa,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC5C,CAAC;IAEM,oCAAa,GAApB;QACC,OAAO,SAAS,CAAC;IAClB,CAAC;IAED;;;;OAIG;IACH,gCAAS,GAAT,UAAU,OAAO;QAChB,IAAM,kBAA6C,EAA3C,WAAQ,EAAR,6BAAQ,EAAE,kCAAiC,CAAC;QACpD,IAAI,GAAG,yBAAQ,YAAY,GAAK,GAAG,CAAE,CAAC;QACtC,MAAM,CAAC,KAAK,CAAC,oBAAoB,EAAE,EAAE,GAAG,KAAA,EAAE,CAAC,CAAC;QAE5C,IAAI,GAAG,CAAC,oBAAoB,CAAC,EAAE;YAC9B,IAAI,GAAG,CAAC,wBAAwB,CAAC,EAAE;gBAClC,IAAM,MAAM,GAAG,GAAG,CAAC,wBAAwB,CAAC,CAAC;gBAC7C,GAAG,CAAC,SAAS;oBACZ,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAA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GAAG,CAAC,IAAI,KAAK,OAAO,EAApB,CAAoB,CAAC,CAAC;QAEtE,IAAI,CAAC,SAAS,EAAE;YACf,MAAM,IAAI,KAAK,CAAC,SAAO,OAAO,oBAAiB,CAAC,CAAC;SACjD;QAED,IAAM,QAAQ,GAAY;YACzB,QAAQ,EAAE,SAAS,CAAC,QAAQ,GAAG,IAAI;SACnC,CAAC;QAEF,IAAI,OAAO,SAAS,CAAC,MAAM,KAAK,QAAQ,EAAE;YACzC,QAAQ,CAAC,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC;SACnC;aAAM,IAAI,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,KAAK,QAAQ,EAAE;YACpD,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;SACvC;QAED,IAAI,OAAO,SAAS,CAAC,OAAO,KAAK,QAAQ,EAAE;YAC1C,QAAQ,CAAC,OAAO,GAAG,SAAS,CAAC,OAAO,IAAI,aAAa,CAAC;SACtD;aAAM;YACN,QAAQ,CAAC,OAAO,GAAG,aAAa,CAAC;SACjC;QAED,IAAI,OAAO,SAAS,CAAC,aAAa,KAAK,UAAU,EAAE;YAClD,QAAQ,CAAC,aAAa,GAAG,SAAS,CAAC,aAAa,CAAC;SACjD;aAAM;YACN,QAAQ,CAAC,aAAa,GAAG,SAAS,CAAC;SACnC;QAED,OAAO,QAAQ,CAAC;IACjB,CAAC;IACF,mBAAC;AAAD,CAAC,AA/TD,IA+TC;;AAED,MAAM,CAAC,IAAM,OAAO,GAAG,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC;AAC9C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC"}
@@ -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): 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): 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): 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): 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): 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): 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): 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 _sign;
136
- private _request;
137
- private _parseUrl;
138
- }