@aws-amplify/api-rest 2.0.56-unstable.1 → 2.0.56-unstable.11

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.
@@ -4062,25 +4062,20 @@ var __assign = undefined && undefined.__assign || function () {
4062
4062
  __assign = Object.assign || function (t) {
4063
4063
  for (var s, i = 1, n = arguments.length; i < n; i++) {
4064
4064
  s = arguments[i];
4065
-
4066
4065
  for (var p in s) {
4067
4066
  if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
4068
4067
  }
4069
4068
  }
4070
-
4071
4069
  return t;
4072
4070
  };
4073
-
4074
4071
  return __assign.apply(this, arguments);
4075
4072
  };
4076
-
4077
4073
  var __awaiter = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
4078
4074
  function adopt(value) {
4079
4075
  return value instanceof P ? value : new P(function (resolve) {
4080
4076
  resolve(value);
4081
4077
  });
4082
4078
  }
4083
-
4084
4079
  return new (P || (P = Promise))(function (resolve, reject) {
4085
4080
  function fulfilled(value) {
4086
4081
  try {
@@ -4089,7 +4084,6 @@ var __awaiter = undefined && undefined.__awaiter || function (thisArg, _argument
4089
4084
  reject(e);
4090
4085
  }
4091
4086
  }
4092
-
4093
4087
  function rejected(value) {
4094
4088
  try {
4095
4089
  step(generator["throw"](value));
@@ -4097,29 +4091,26 @@ var __awaiter = undefined && undefined.__awaiter || function (thisArg, _argument
4097
4091
  reject(e);
4098
4092
  }
4099
4093
  }
4100
-
4101
4094
  function step(result) {
4102
4095
  result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
4103
4096
  }
4104
-
4105
4097
  step((generator = generator.apply(thisArg, _arguments || [])).next());
4106
4098
  });
4107
4099
  };
4108
-
4109
4100
  var __generator = undefined && undefined.__generator || function (thisArg, body) {
4110
4101
  var _ = {
4111
- label: 0,
4112
- sent: function sent() {
4113
- if (t[0] & 1) throw t[1];
4114
- return t[1];
4102
+ label: 0,
4103
+ sent: function sent() {
4104
+ if (t[0] & 1) throw t[1];
4105
+ return t[1];
4106
+ },
4107
+ trys: [],
4108
+ ops: []
4115
4109
  },
4116
- trys: [],
4117
- ops: []
4118
- },
4119
- f,
4120
- y,
4121
- t,
4122
- g;
4110
+ f,
4111
+ y,
4112
+ t,
4113
+ g;
4123
4114
  return g = {
4124
4115
  next: verb(0),
4125
4116
  "throw": verb(1),
@@ -4127,79 +4118,60 @@ var __generator = undefined && undefined.__generator || function (thisArg, body)
4127
4118
  }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
4128
4119
  return this;
4129
4120
  }), g;
4130
-
4131
4121
  function verb(n) {
4132
4122
  return function (v) {
4133
4123
  return step([n, v]);
4134
4124
  };
4135
4125
  }
4136
-
4137
4126
  function step(op) {
4138
4127
  if (f) throw new TypeError("Generator is already executing.");
4139
-
4140
4128
  while (_) {
4141
4129
  try {
4142
4130
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
4143
4131
  if (y = 0, t) op = [op[0] & 2, t.value];
4144
-
4145
4132
  switch (op[0]) {
4146
4133
  case 0:
4147
4134
  case 1:
4148
4135
  t = op;
4149
4136
  break;
4150
-
4151
4137
  case 4:
4152
4138
  _.label++;
4153
4139
  return {
4154
4140
  value: op[1],
4155
4141
  done: false
4156
4142
  };
4157
-
4158
4143
  case 5:
4159
4144
  _.label++;
4160
4145
  y = op[1];
4161
4146
  op = [0];
4162
4147
  continue;
4163
-
4164
4148
  case 7:
4165
4149
  op = _.ops.pop();
4166
-
4167
4150
  _.trys.pop();
4168
-
4169
4151
  continue;
4170
-
4171
4152
  default:
4172
4153
  if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
4173
4154
  _ = 0;
4174
4155
  continue;
4175
4156
  }
4176
-
4177
4157
  if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
4178
4158
  _.label = op[1];
4179
4159
  break;
4180
4160
  }
4181
-
4182
4161
  if (op[0] === 6 && _.label < t[1]) {
4183
4162
  _.label = t[1];
4184
4163
  t = op;
4185
4164
  break;
4186
4165
  }
4187
-
4188
4166
  if (t && _.label < t[2]) {
4189
4167
  _.label = t[2];
4190
-
4191
4168
  _.ops.push(op);
4192
-
4193
4169
  break;
4194
4170
  }
4195
-
4196
4171
  if (t[2]) _.ops.pop();
4197
-
4198
4172
  _.trys.pop();
4199
-
4200
4173
  continue;
4201
4174
  }
4202
-
4203
4175
  op = body.call(thisArg, _);
4204
4176
  } catch (e) {
4205
4177
  op = [6, e];
@@ -4208,7 +4180,6 @@ var __generator = undefined && undefined.__generator || function (thisArg, body)
4208
4180
  f = t = 0;
4209
4181
  }
4210
4182
  }
4211
-
4212
4183
  if (op[0] & 5) throw op[1];
4213
4184
  return {
4214
4185
  value: op[0] ? op[1] : void 0,
@@ -4216,14 +4187,11 @@ var __generator = undefined && undefined.__generator || function (thisArg, body)
4216
4187
  };
4217
4188
  }
4218
4189
  };
4219
-
4220
4190
  var __rest = undefined && undefined.__rest || function (s, e) {
4221
4191
  var t = {};
4222
-
4223
4192
  for (var p in s) {
4224
4193
  if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
4225
4194
  }
4226
-
4227
4195
  if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
4228
4196
  if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
4229
4197
  }
@@ -4243,16 +4211,11 @@ var __rest = undefined && undefined.__rest || function (s, e) {
4243
4211
  */
4244
4212
 
4245
4213
 
4246
-
4247
-
4248
4214
  var logger = new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["ConsoleLogger"]('RestAPI');
4249
4215
  /**
4250
4216
  * Export Cloud Logic APIs
4251
4217
  */
4252
-
4253
- var RestAPIClass =
4254
- /** @class */
4255
- function () {
4218
+ var RestAPIClass = /** @class */function () {
4256
4219
  /**
4257
4220
  * Initialize Rest API with AWS configuration
4258
4221
  * @param {Object} options - Configuration object for API
@@ -4263,7 +4226,6 @@ function () {
4263
4226
  this._options = options;
4264
4227
  logger.debug('API Options', this._options);
4265
4228
  }
4266
-
4267
4229
  RestAPIClass.prototype.getModuleName = function () {
4268
4230
  return 'RestAPI';
4269
4231
  };
@@ -4272,32 +4234,25 @@ function () {
4272
4234
  * @param {Object} config - Configuration of the API
4273
4235
  * @return {Object} - The current configuration
4274
4236
  */
4275
-
4276
-
4277
4237
  RestAPIClass.prototype.configure = function (options) {
4278
4238
  var _a = options || {},
4279
- _b = _a.API,
4280
- API = _b === void 0 ? {} : _b,
4281
- otherOptions = __rest(_a, ["API"]);
4282
-
4239
+ _b = _a.API,
4240
+ API = _b === void 0 ? {} : _b,
4241
+ otherOptions = __rest(_a, ["API"]);
4283
4242
  var opt = __assign(__assign({}, otherOptions), API);
4284
-
4285
4243
  logger.debug('configure Rest API', {
4286
4244
  opt: opt
4287
4245
  });
4288
-
4289
4246
  if (opt['aws_project_region']) {
4290
4247
  if (opt['aws_cloud_logic_custom']) {
4291
4248
  var custom = opt['aws_cloud_logic_custom'];
4292
4249
  opt.endpoints = typeof custom === 'string' ? JSON.parse(custom) : custom;
4293
4250
  }
4294
-
4295
4251
  opt = Object.assign({}, opt, {
4296
4252
  region: opt['aws_project_region'],
4297
4253
  header: {}
4298
4254
  });
4299
4255
  }
4300
-
4301
4256
  if (Array.isArray(opt.endpoints)) {
4302
4257
  // Check if endpoints has custom_headers and validate if is a function
4303
4258
  opt.endpoints.forEach(function (endpoint) {
@@ -4311,7 +4266,6 @@ function () {
4311
4266
  } else {
4312
4267
  opt.endpoints = [];
4313
4268
  }
4314
-
4315
4269
  this._options = Object.assign({}, this._options, opt);
4316
4270
  this.createInstance();
4317
4271
  return this._options;
@@ -4320,12 +4274,10 @@ function () {
4320
4274
  * Create an instance of API for the library
4321
4275
  * @return - A promise of true if Success
4322
4276
  */
4323
-
4324
-
4325
4277
  RestAPIClass.prototype.createInstance = function () {
4326
4278
  logger.debug('create Rest API instance');
4327
- this._api = new _RestClient__WEBPACK_IMPORTED_MODULE_0__["RestClient"](this._options); // Share Amplify instance with client for SSR
4328
-
4279
+ this._api = new _RestClient__WEBPACK_IMPORTED_MODULE_0__["RestClient"](this._options);
4280
+ // Share Amplify instance with client for SSR
4329
4281
  this._api.Credentials = this.Credentials;
4330
4282
  return true;
4331
4283
  };
@@ -4336,21 +4288,14 @@ function () {
4336
4288
  * @param {json} [init] - Request extra params
4337
4289
  * @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.
4338
4290
  */
4339
-
4340
-
4341
4291
  RestAPIClass.prototype.get = function (apiName, path, init) {
4342
4292
  try {
4343
4293
  var apiInfo = this.getEndpointInfo(apiName, path);
4344
-
4345
4294
  var cancellableToken = this._api.getCancellableToken();
4346
-
4347
4295
  var initParams = Object.assign({}, init);
4348
4296
  initParams.cancellableToken = cancellableToken;
4349
-
4350
4297
  var responsePromise = this._api.get(apiInfo, initParams);
4351
-
4352
4298
  this._api.updateRequestToBeCancellable(responsePromise, cancellableToken);
4353
-
4354
4299
  return responsePromise;
4355
4300
  } catch (err) {
4356
4301
  return Promise.reject(err.message);
@@ -4363,21 +4308,14 @@ function () {
4363
4308
  * @param {json} [init] - Request extra params
4364
4309
  * @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.
4365
4310
  */
4366
-
4367
-
4368
4311
  RestAPIClass.prototype.post = function (apiName, path, init) {
4369
4312
  try {
4370
4313
  var apiInfo = this.getEndpointInfo(apiName, path);
4371
-
4372
4314
  var cancellableToken = this._api.getCancellableToken();
4373
-
4374
4315
  var initParams = Object.assign({}, init);
4375
4316
  initParams.cancellableToken = cancellableToken;
4376
-
4377
4317
  var responsePromise = this._api.post(apiInfo, initParams);
4378
-
4379
4318
  this._api.updateRequestToBeCancellable(responsePromise, cancellableToken);
4380
-
4381
4319
  return responsePromise;
4382
4320
  } catch (err) {
4383
4321
  return Promise.reject(err.message);
@@ -4390,21 +4328,14 @@ function () {
4390
4328
  * @param {json} [init] - Request extra params
4391
4329
  * @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.
4392
4330
  */
4393
-
4394
-
4395
4331
  RestAPIClass.prototype.put = function (apiName, path, init) {
4396
4332
  try {
4397
4333
  var apiInfo = this.getEndpointInfo(apiName, path);
4398
-
4399
4334
  var cancellableToken = this._api.getCancellableToken();
4400
-
4401
4335
  var initParams = Object.assign({}, init);
4402
4336
  initParams.cancellableToken = cancellableToken;
4403
-
4404
4337
  var responsePromise = this._api.put(apiInfo, initParams);
4405
-
4406
4338
  this._api.updateRequestToBeCancellable(responsePromise, cancellableToken);
4407
-
4408
4339
  return responsePromise;
4409
4340
  } catch (err) {
4410
4341
  return Promise.reject(err.message);
@@ -4417,21 +4348,14 @@ function () {
4417
4348
  * @param {json} [init] - Request extra params
4418
4349
  * @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.
4419
4350
  */
4420
-
4421
-
4422
4351
  RestAPIClass.prototype.patch = function (apiName, path, init) {
4423
4352
  try {
4424
4353
  var apiInfo = this.getEndpointInfo(apiName, path);
4425
-
4426
4354
  var cancellableToken = this._api.getCancellableToken();
4427
-
4428
4355
  var initParams = Object.assign({}, init);
4429
4356
  initParams.cancellableToken = cancellableToken;
4430
-
4431
4357
  var responsePromise = this._api.patch(apiInfo, initParams);
4432
-
4433
4358
  this._api.updateRequestToBeCancellable(responsePromise, cancellableToken);
4434
-
4435
4359
  return responsePromise;
4436
4360
  } catch (err) {
4437
4361
  return Promise.reject(err.message);
@@ -4444,21 +4368,14 @@ function () {
4444
4368
  * @param {json} [init] - Request extra params
4445
4369
  * @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.
4446
4370
  */
4447
-
4448
-
4449
4371
  RestAPIClass.prototype.del = function (apiName, path, init) {
4450
4372
  try {
4451
4373
  var apiInfo = this.getEndpointInfo(apiName, path);
4452
-
4453
4374
  var cancellableToken = this._api.getCancellableToken();
4454
-
4455
4375
  var initParams = Object.assign({}, init);
4456
4376
  initParams.cancellableToken = cancellableToken;
4457
-
4458
4377
  var responsePromise = this._api.del(apiInfo, initParams);
4459
-
4460
4378
  this._api.updateRequestToBeCancellable(responsePromise, cancellableToken);
4461
-
4462
4379
  return responsePromise;
4463
4380
  } catch (err) {
4464
4381
  return Promise.reject(err.message);
@@ -4471,21 +4388,14 @@ function () {
4471
4388
  * @param {json} [init] - Request extra params
4472
4389
  * @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.
4473
4390
  */
4474
-
4475
-
4476
4391
  RestAPIClass.prototype.head = function (apiName, path, init) {
4477
4392
  try {
4478
4393
  var apiInfo = this.getEndpointInfo(apiName, path);
4479
-
4480
4394
  var cancellableToken = this._api.getCancellableToken();
4481
-
4482
4395
  var initParams = Object.assign({}, init);
4483
4396
  initParams.cancellableToken = cancellableToken;
4484
-
4485
4397
  var responsePromise = this._api.head(apiInfo, initParams);
4486
-
4487
4398
  this._api.updateRequestToBeCancellable(responsePromise, cancellableToken);
4488
-
4489
4399
  return responsePromise;
4490
4400
  } catch (err) {
4491
4401
  return Promise.reject(err.message);
@@ -4496,8 +4406,6 @@ function () {
4496
4406
  * @param {any} error - Any error
4497
4407
  * @return {boolean} - A boolean indicating if the error was from an api request cancellation
4498
4408
  */
4499
-
4500
-
4501
4409
  RestAPIClass.prototype.isCancel = function (error) {
4502
4410
  return this._api.isCancel(error);
4503
4411
  };
@@ -4506,8 +4414,6 @@ function () {
4506
4414
  * @param {any} request - request to cancel
4507
4415
  * @return {boolean} - A boolean indicating if the request was cancelled
4508
4416
  */
4509
-
4510
-
4511
4417
  RestAPIClass.prototype.cancel = function (request, message) {
4512
4418
  return this._api.cancel(request, message);
4513
4419
  };
@@ -4516,8 +4422,6 @@ function () {
4516
4422
  * @params request - The request promise
4517
4423
  * @return if the request has a corresponding cancel token.
4518
4424
  */
4519
-
4520
-
4521
4425
  RestAPIClass.prototype.hasCancelToken = function (request) {
4522
4426
  return this._api.hasCancelToken(request);
4523
4427
  };
@@ -4526,14 +4430,10 @@ function () {
4526
4430
  * @param {string} apiName - The name of the api
4527
4431
  * @return {string} - The endpoint of the api
4528
4432
  */
4529
-
4530
-
4531
4433
  RestAPIClass.prototype.endpoint = function (apiName) {
4532
4434
  return __awaiter(this, void 0, void 0, function () {
4533
4435
  return __generator(this, function (_a) {
4534
- return [2
4535
- /*return*/
4536
- , this._api.endpoint(apiName)];
4436
+ return [2 /*return*/, this._api.endpoint(apiName)];
4537
4437
  });
4538
4438
  });
4539
4439
  };
@@ -4543,52 +4443,40 @@ function () {
4543
4443
  * @param {string} path - The path of the api that is going to accessed
4544
4444
  * @return {ApiInfo} - The endpoint information for that api-name
4545
4445
  */
4546
-
4547
-
4548
4446
  RestAPIClass.prototype.getEndpointInfo = function (apiName, path) {
4549
4447
  var cloud_logic_array = this._options.endpoints;
4550
-
4551
4448
  if (!Array.isArray(cloud_logic_array)) {
4552
4449
  throw new Error("API category not configured");
4553
4450
  }
4554
-
4555
4451
  var apiConfig = cloud_logic_array.find(function (api) {
4556
4452
  return api.name === apiName;
4557
4453
  });
4558
-
4559
4454
  if (!apiConfig) {
4560
4455
  throw new Error("API " + apiName + " does not exist");
4561
4456
  }
4562
-
4563
4457
  var response = {
4564
4458
  endpoint: apiConfig.endpoint + path
4565
4459
  };
4566
-
4567
4460
  if (typeof apiConfig.region === 'string') {
4568
4461
  response.region = apiConfig.region;
4569
4462
  } else if (typeof this._options.region === 'string') {
4570
4463
  response.region = this._options.region;
4571
4464
  }
4572
-
4573
4465
  if (typeof apiConfig.service === 'string') {
4574
4466
  response.service = apiConfig.service || 'execute-api';
4575
4467
  } else {
4576
4468
  response.service = 'execute-api';
4577
4469
  }
4578
-
4579
4470
  if (typeof apiConfig.custom_header === 'function') {
4580
4471
  response.custom_header = apiConfig.custom_header;
4581
4472
  } else {
4582
4473
  response.custom_header = undefined;
4583
4474
  }
4584
-
4585
4475
  return response;
4586
4476
  };
4587
-
4588
4477
  return RestAPIClass;
4589
4478
  }();
4590
4479
 
4591
-
4592
4480
  var RestAPI = new RestAPIClass(null);
4593
4481
  _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["Amplify"].register(RestAPI);
4594
4482
 
@@ -4626,25 +4514,20 @@ var __assign = undefined && undefined.__assign || function () {
4626
4514
  __assign = Object.assign || function (t) {
4627
4515
  for (var s, i = 1, n = arguments.length; i < n; i++) {
4628
4516
  s = arguments[i];
4629
-
4630
4517
  for (var p in s) {
4631
4518
  if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
4632
4519
  }
4633
4520
  }
4634
-
4635
4521
  return t;
4636
4522
  };
4637
-
4638
4523
  return __assign.apply(this, arguments);
4639
4524
  };
4640
-
4641
4525
  var __awaiter = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
4642
4526
  function adopt(value) {
4643
4527
  return value instanceof P ? value : new P(function (resolve) {
4644
4528
  resolve(value);
4645
4529
  });
4646
4530
  }
4647
-
4648
4531
  return new (P || (P = Promise))(function (resolve, reject) {
4649
4532
  function fulfilled(value) {
4650
4533
  try {
@@ -4653,7 +4536,6 @@ var __awaiter = undefined && undefined.__awaiter || function (thisArg, _argument
4653
4536
  reject(e);
4654
4537
  }
4655
4538
  }
4656
-
4657
4539
  function rejected(value) {
4658
4540
  try {
4659
4541
  step(generator["throw"](value));
@@ -4661,29 +4543,26 @@ var __awaiter = undefined && undefined.__awaiter || function (thisArg, _argument
4661
4543
  reject(e);
4662
4544
  }
4663
4545
  }
4664
-
4665
4546
  function step(result) {
4666
4547
  result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
4667
4548
  }
4668
-
4669
4549
  step((generator = generator.apply(thisArg, _arguments || [])).next());
4670
4550
  });
4671
4551
  };
4672
-
4673
4552
  var __generator = undefined && undefined.__generator || function (thisArg, body) {
4674
4553
  var _ = {
4675
- label: 0,
4676
- sent: function sent() {
4677
- if (t[0] & 1) throw t[1];
4678
- return t[1];
4554
+ label: 0,
4555
+ sent: function sent() {
4556
+ if (t[0] & 1) throw t[1];
4557
+ return t[1];
4558
+ },
4559
+ trys: [],
4560
+ ops: []
4679
4561
  },
4680
- trys: [],
4681
- ops: []
4682
- },
4683
- f,
4684
- y,
4685
- t,
4686
- g;
4562
+ f,
4563
+ y,
4564
+ t,
4565
+ g;
4687
4566
  return g = {
4688
4567
  next: verb(0),
4689
4568
  "throw": verb(1),
@@ -4691,79 +4570,60 @@ var __generator = undefined && undefined.__generator || function (thisArg, body)
4691
4570
  }, typeof Symbol === "function" && (g[Symbol.iterator] = function () {
4692
4571
  return this;
4693
4572
  }), g;
4694
-
4695
4573
  function verb(n) {
4696
4574
  return function (v) {
4697
4575
  return step([n, v]);
4698
4576
  };
4699
4577
  }
4700
-
4701
4578
  function step(op) {
4702
4579
  if (f) throw new TypeError("Generator is already executing.");
4703
-
4704
4580
  while (_) {
4705
4581
  try {
4706
4582
  if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
4707
4583
  if (y = 0, t) op = [op[0] & 2, t.value];
4708
-
4709
4584
  switch (op[0]) {
4710
4585
  case 0:
4711
4586
  case 1:
4712
4587
  t = op;
4713
4588
  break;
4714
-
4715
4589
  case 4:
4716
4590
  _.label++;
4717
4591
  return {
4718
4592
  value: op[1],
4719
4593
  done: false
4720
4594
  };
4721
-
4722
4595
  case 5:
4723
4596
  _.label++;
4724
4597
  y = op[1];
4725
4598
  op = [0];
4726
4599
  continue;
4727
-
4728
4600
  case 7:
4729
4601
  op = _.ops.pop();
4730
-
4731
4602
  _.trys.pop();
4732
-
4733
4603
  continue;
4734
-
4735
4604
  default:
4736
4605
  if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
4737
4606
  _ = 0;
4738
4607
  continue;
4739
4608
  }
4740
-
4741
4609
  if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
4742
4610
  _.label = op[1];
4743
4611
  break;
4744
4612
  }
4745
-
4746
4613
  if (op[0] === 6 && _.label < t[1]) {
4747
4614
  _.label = t[1];
4748
4615
  t = op;
4749
4616
  break;
4750
4617
  }
4751
-
4752
4618
  if (t && _.label < t[2]) {
4753
4619
  _.label = t[2];
4754
-
4755
4620
  _.ops.push(op);
4756
-
4757
4621
  break;
4758
4622
  }
4759
-
4760
4623
  if (t[2]) _.ops.pop();
4761
-
4762
4624
  _.trys.pop();
4763
-
4764
4625
  continue;
4765
4626
  }
4766
-
4767
4627
  op = body.call(thisArg, _);
4768
4628
  } catch (e) {
4769
4629
  op = [6, e];
@@ -4772,7 +4632,6 @@ var __generator = undefined && undefined.__generator || function (thisArg, body)
4772
4632
  f = t = 0;
4773
4633
  }
4774
4634
  }
4775
-
4776
4635
  if (op[0] & 5) throw op[1];
4777
4636
  return {
4778
4637
  value: op[0] ? op[1] : void 0,
@@ -4780,14 +4639,11 @@ var __generator = undefined && undefined.__generator || function (thisArg, body)
4780
4639
  };
4781
4640
  }
4782
4641
  };
4783
-
4784
4642
  var __rest = undefined && undefined.__rest || function (s, e) {
4785
4643
  var t = {};
4786
-
4787
4644
  for (var p in s) {
4788
4645
  if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
4789
4646
  }
4790
-
4791
4647
  if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
4792
4648
  if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
4793
4649
  }
@@ -4796,7 +4652,6 @@ var __rest = undefined && undefined.__rest || function (s, e) {
4796
4652
 
4797
4653
 
4798
4654
 
4799
-
4800
4655
  var logger = new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__["ConsoleLogger"]('RestClient');
4801
4656
  /**
4802
4657
  * HTTP Client for REST requests. Send and receive JSON data.
@@ -4811,20 +4666,14 @@ restClient.get('...')
4811
4666
  .catch(err => console.log(err));
4812
4667
  </pre>
4813
4668
  */
4814
-
4815
- var RestClient =
4816
- /** @class */
4817
- function () {
4669
+ var RestClient = /** @class */function () {
4818
4670
  /**
4819
4671
  * @param {RestClientOptions} [options] - Instance options
4820
4672
  */
4821
4673
  function RestClient(options) {
4822
4674
  this._region = 'us-east-1'; // this will be updated by endpoint function
4823
-
4824
4675
  this._service = 'execute-api'; // this can be updated by endpoint function
4825
-
4826
4676
  this._custom_header = undefined; // this can be updated by endpoint function
4827
-
4828
4677
  /**
4829
4678
  * This weak map provides functionality to let clients cancel
4830
4679
  * in-flight axios requests. https://github.com/axios/axios#cancellation
@@ -4839,12 +4688,10 @@ function () {
4839
4688
  *
4840
4689
  * For more details, see https://github.com/aws-amplify/amplify-js/pull/3769#issuecomment-552660025
4841
4690
  */
4842
-
4843
4691
  this._cancelTokenMap = null;
4844
4692
  this.Credentials = _aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__["Credentials"];
4845
4693
  this._options = options;
4846
4694
  logger.debug('API Options', this._options);
4847
-
4848
4695
  if (this._cancelTokenMap == null) {
4849
4696
  this._cancelTokenMap = new WeakMap();
4850
4697
  }
@@ -4857,7 +4704,6 @@ function () {
4857
4704
  this.options.credentials = credentials;
4858
4705
  }
4859
4706
  */
4860
-
4861
4707
  /**
4862
4708
  * Basic HTTP request. Customizable
4863
4709
  * @param {string | ApiInfo } urlOrApiInfo - Full request URL or Api information
@@ -4865,14 +4711,10 @@ function () {
4865
4711
  * @param {json} [init] - Request extra params
4866
4712
  * @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.
4867
4713
  */
4868
-
4869
-
4870
4714
  RestClient.prototype.ajax = function (urlOrApiInfo, method, init) {
4871
4715
  return __awaiter(this, void 0, void 0, function () {
4872
4716
  var parsed_url, url, region, service, custom_header, params, libraryHeaders, userAgent, initParams, isAllResponse, custom_header_obj, _a, _b, search, parsedUrl;
4873
-
4874
4717
  var _this = this;
4875
-
4876
4718
  return __generator(this, function (_c) {
4877
4719
  switch (_c.label) {
4878
4720
  case 0:
@@ -4880,7 +4722,6 @@ function () {
4880
4722
  region = 'us-east-1';
4881
4723
  service = 'execute-api';
4882
4724
  custom_header = undefined;
4883
-
4884
4725
  if (typeof urlOrApiInfo === 'string') {
4885
4726
  parsed_url = this._parseUrl(urlOrApiInfo);
4886
4727
  url = urlOrApiInfo;
@@ -4888,7 +4729,6 @@ function () {
4888
4729
  url = urlOrApiInfo.endpoint, custom_header = urlOrApiInfo.custom_header, region = urlOrApiInfo.region, service = urlOrApiInfo.service;
4889
4730
  parsed_url = this._parseUrl(urlOrApiInfo.endpoint);
4890
4731
  }
4891
-
4892
4732
  params = {
4893
4733
  method: method,
4894
4734
  url: url,
@@ -4901,17 +4741,14 @@ function () {
4901
4741
  cancelToken: null
4902
4742
  };
4903
4743
  libraryHeaders = {};
4904
-
4905
4744
  if (_aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__["Platform"].isReactNative) {
4906
4745
  userAgent = _aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__["Platform"].userAgent || 'aws-amplify/0.1.x';
4907
4746
  libraryHeaders = {
4908
4747
  'User-Agent': userAgent
4909
4748
  };
4910
4749
  }
4911
-
4912
4750
  initParams = Object.assign({}, init);
4913
4751
  isAllResponse = initParams.response;
4914
-
4915
4752
  if (initParams.body) {
4916
4753
  if (typeof FormData === 'function' && initParams.body instanceof FormData) {
4917
4754
  libraryHeaders['Content-Type'] = 'multipart/form-data';
@@ -4921,67 +4758,48 @@ function () {
4921
4758
  params.data = JSON.stringify(initParams.body);
4922
4759
  }
4923
4760
  }
4924
-
4925
4761
  if (initParams.responseType) {
4926
4762
  params.responseType = initParams.responseType;
4927
4763
  }
4928
-
4929
4764
  if (initParams.withCredentials) {
4930
4765
  params['withCredentials'] = initParams.withCredentials;
4931
4766
  }
4932
-
4933
4767
  if (initParams.timeout) {
4934
4768
  params.timeout = initParams.timeout;
4935
4769
  }
4936
-
4937
4770
  if (initParams.cancellableToken) {
4938
4771
  params.cancelToken = initParams.cancellableToken.token;
4939
4772
  }
4940
-
4941
4773
  params['signerServiceInfo'] = initParams.signerServiceInfo;
4942
- if (!(typeof custom_header === 'function')) return [3
4943
- /*break*/
4944
- , 2];
4945
- return [4
4946
- /*yield*/
4947
- , custom_header()];
4948
-
4774
+ if (!(typeof custom_header === 'function')) return [3 /*break*/, 2];
4775
+ return [4 /*yield*/, custom_header()];
4949
4776
  case 1:
4950
4777
  _a = _c.sent();
4951
- return [3
4952
- /*break*/
4953
- , 3];
4954
-
4778
+ return [3 /*break*/, 3];
4955
4779
  case 2:
4956
4780
  _a = undefined;
4957
4781
  _c.label = 3;
4958
-
4959
4782
  case 3:
4960
4783
  custom_header_obj = _a;
4961
4784
  params.headers = __assign(__assign(__assign({}, libraryHeaders), custom_header_obj), initParams.headers);
4962
4785
  _b = Object(url__WEBPACK_IMPORTED_MODULE_2__["parse"])(url, true, true), search = _b.search, parsedUrl = __rest(_b, ["search"]);
4963
4786
  params.url = Object(url__WEBPACK_IMPORTED_MODULE_2__["format"])(__assign(__assign({}, parsedUrl), {
4964
4787
  query: __assign(__assign({}, parsedUrl.query), initParams.queryStringParameters || {})
4965
- })); // Do not sign the request if client has added 'Authorization' header,
4788
+ }));
4789
+ // Do not sign the request if client has added 'Authorization' header,
4966
4790
  // which means custom authorizer.
4967
-
4968
4791
  if (typeof params.headers['Authorization'] !== 'undefined') {
4969
4792
  params.headers = Object.keys(params.headers).reduce(function (acc, k) {
4970
4793
  if (params.headers[k]) {
4971
4794
  acc[k] = params.headers[k];
4972
4795
  }
4973
-
4974
- return acc; // tslint:disable-next-line:align
4796
+ return acc;
4797
+ // tslint:disable-next-line:align
4975
4798
  }, {});
4976
- return [2
4977
- /*return*/
4978
- , this._request(params, isAllResponse)];
4979
- } // Signing the request in case there credentials are available
4980
-
4981
-
4982
- return [2
4983
- /*return*/
4984
- , this.Credentials.get().then(function (credentials) {
4799
+ return [2 /*return*/, this._request(params, isAllResponse)];
4800
+ }
4801
+ // Signing the request in case there credentials are available
4802
+ return [2 /*return*/, this.Credentials.get().then(function (credentials) {
4985
4803
  return _this._signed(__assign({}, params), credentials, isAllResponse, {
4986
4804
  region: region,
4987
4805
  service: service
@@ -4990,14 +4808,13 @@ function () {
4990
4808
  var headers = error.response.headers;
4991
4809
  var dateHeader = headers && (headers.date || headers.Date);
4992
4810
  var responseDate = new Date(dateHeader);
4993
- var requestDate = _aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__["DateUtils"].getDateFromHeaderString(params.headers['x-amz-date']); // Compare local clock to the server clock
4994
-
4811
+ var requestDate = _aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__["DateUtils"].getDateFromHeaderString(params.headers['x-amz-date']);
4812
+ // Compare local clock to the server clock
4995
4813
  if (_aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__["DateUtils"].isClockSkewed(responseDate)) {
4996
4814
  _aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__["DateUtils"].setClockOffset(responseDate.getTime() - requestDate.getTime());
4997
4815
  return _this.ajax(urlOrApiInfo, method, init);
4998
4816
  }
4999
4817
  }
5000
-
5001
4818
  throw error;
5002
4819
  });
5003
4820
  }, function (err) {
@@ -5014,8 +4831,6 @@ function () {
5014
4831
  * @param {JSON} init - Request extra params
5015
4832
  * @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.
5016
4833
  */
5017
-
5018
-
5019
4834
  RestClient.prototype.get = function (urlOrApiInfo, init) {
5020
4835
  return this.ajax(urlOrApiInfo, 'GET', init);
5021
4836
  };
@@ -5025,8 +4840,6 @@ function () {
5025
4840
  * @param {json} init - Request extra params
5026
4841
  * @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.
5027
4842
  */
5028
-
5029
-
5030
4843
  RestClient.prototype.put = function (urlOrApiInfo, init) {
5031
4844
  return this.ajax(urlOrApiInfo, 'PUT', init);
5032
4845
  };
@@ -5036,8 +4849,6 @@ function () {
5036
4849
  * @param {json} init - Request extra params
5037
4850
  * @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.
5038
4851
  */
5039
-
5040
-
5041
4852
  RestClient.prototype.patch = function (urlOrApiInfo, init) {
5042
4853
  return this.ajax(urlOrApiInfo, 'PATCH', init);
5043
4854
  };
@@ -5047,8 +4858,6 @@ function () {
5047
4858
  * @param {json} init - Request extra params
5048
4859
  * @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.
5049
4860
  */
5050
-
5051
-
5052
4861
  RestClient.prototype.post = function (urlOrApiInfo, init) {
5053
4862
  return this.ajax(urlOrApiInfo, 'POST', init);
5054
4863
  };
@@ -5058,8 +4867,6 @@ function () {
5058
4867
  * @param {json} init - Request extra params
5059
4868
  * @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.
5060
4869
  */
5061
-
5062
-
5063
4870
  RestClient.prototype.del = function (urlOrApiInfo, init) {
5064
4871
  return this.ajax(urlOrApiInfo, 'DELETE', init);
5065
4872
  };
@@ -5069,8 +4876,6 @@ function () {
5069
4876
  * @param {json} init - Request extra params
5070
4877
  * @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.
5071
4878
  */
5072
-
5073
-
5074
4879
  RestClient.prototype.head = function (urlOrApiInfo, init) {
5075
4880
  return this.ajax(urlOrApiInfo, 'HEAD', init);
5076
4881
  };
@@ -5079,16 +4884,12 @@ function () {
5079
4884
  * @param {Promise<any>} request - The request promise to cancel
5080
4885
  * @param {string} [message] - A message to include in the cancelation exception
5081
4886
  */
5082
-
5083
-
5084
4887
  RestClient.prototype.cancel = function (request, message) {
5085
4888
  var source = this._cancelTokenMap.get(request);
5086
-
5087
4889
  if (source) {
5088
4890
  source.cancel(message);
5089
4891
  return true;
5090
4892
  }
5091
-
5092
4893
  return false;
5093
4894
  };
5094
4895
  /**
@@ -5096,8 +4897,6 @@ function () {
5096
4897
  * @params request - The request promise
5097
4898
  * @return if the request has a corresponding cancel token.
5098
4899
  */
5099
-
5100
-
5101
4900
  RestClient.prototype.hasCancelToken = function (request) {
5102
4901
  return this._cancelTokenMap.has(request);
5103
4902
  };
@@ -5106,8 +4905,6 @@ function () {
5106
4905
  * @param {any} error - Any error
5107
4906
  * @return {boolean} - A boolean indicating if the error was from an api request cancellation
5108
4907
  */
5109
-
5110
-
5111
4908
  RestClient.prototype.isCancel = function (error) {
5112
4909
  return axios__WEBPACK_IMPORTED_MODULE_1___default.a.isCancel(error);
5113
4910
  };
@@ -5115,8 +4912,6 @@ function () {
5115
4912
  * Retrieves a new and unique cancel token which can be
5116
4913
  * provided in an axios request to be cancelled later.
5117
4914
  */
5118
-
5119
-
5120
4915
  RestClient.prototype.getCancellableToken = function () {
5121
4916
  return axios__WEBPACK_IMPORTED_MODULE_1___default.a.CancelToken.source();
5122
4917
  };
@@ -5125,8 +4920,6 @@ function () {
5125
4920
  * cancel token such that the cancel token can be easily
5126
4921
  * retrieved (and used for cancelling the request)
5127
4922
  */
5128
-
5129
-
5130
4923
  RestClient.prototype.updateRequestToBeCancellable = function (promise, cancelTokenSource) {
5131
4924
  this._cancelTokenMap.set(promise, cancelTokenSource);
5132
4925
  };
@@ -5135,34 +4928,26 @@ function () {
5135
4928
  * @param {string} apiName - The name of the api
5136
4929
  * @return {string} - The endpoint of the api
5137
4930
  */
5138
-
5139
-
5140
4931
  RestClient.prototype.endpoint = function (apiName) {
5141
4932
  var _this = this;
5142
-
5143
4933
  var cloud_logic_array = this._options.endpoints;
5144
4934
  var response = '';
5145
-
5146
4935
  if (!Array.isArray(cloud_logic_array)) {
5147
4936
  return response;
5148
4937
  }
5149
-
5150
4938
  cloud_logic_array.forEach(function (v) {
5151
4939
  if (v.name === apiName) {
5152
4940
  response = v.endpoint;
5153
-
5154
4941
  if (typeof v.region === 'string') {
5155
4942
  _this._region = v.region;
5156
4943
  } else if (typeof _this._options.region === 'string') {
5157
4944
  _this._region = _this._options.region;
5158
4945
  }
5159
-
5160
4946
  if (typeof v.service === 'string') {
5161
4947
  _this._service = v.service || 'execute-api';
5162
4948
  } else {
5163
4949
  _this._service = 'execute-api';
5164
4950
  }
5165
-
5166
4951
  if (typeof v.custom_header === 'function') {
5167
4952
  _this._custom_header = v.custom_header;
5168
4953
  } else {
@@ -5173,15 +4958,11 @@ function () {
5173
4958
  return response;
5174
4959
  };
5175
4960
  /** private methods **/
5176
-
5177
-
5178
4961
  RestClient.prototype._signed = function (params, credentials, isAllResponse, _a) {
5179
4962
  var service = _a.service,
5180
- region = _a.region;
5181
-
4963
+ region = _a.region;
5182
4964
  var signerServiceInfoParams = params.signerServiceInfo,
5183
- otherParams = __rest(params, ["signerServiceInfo"]);
5184
-
4965
+ otherParams = __rest(params, ["signerServiceInfo"]);
5185
4966
  var endpoint_region = region || this._region || this._options.region;
5186
4967
  var endpoint_service = service || this._service || this._options.service;
5187
4968
  var creds = {
@@ -5195,11 +4976,9 @@ function () {
5195
4976
  };
5196
4977
  var signerServiceInfo = Object.assign(endpointInfo, signerServiceInfoParams);
5197
4978
  var signed_params = _aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__["Signer"].sign(otherParams, creds, signerServiceInfo);
5198
-
5199
4979
  if (signed_params.data) {
5200
4980
  signed_params.body = signed_params.data;
5201
4981
  }
5202
-
5203
4982
  logger.debug('Signed Request: ', signed_params);
5204
4983
  delete signed_params.headers['host'];
5205
4984
  return axios__WEBPACK_IMPORTED_MODULE_1___default()(signed_params).then(function (response) {
@@ -5209,12 +4988,10 @@ function () {
5209
4988
  throw error;
5210
4989
  });
5211
4990
  };
5212
-
5213
4991
  RestClient.prototype._request = function (params, isAllResponse) {
5214
4992
  if (isAllResponse === void 0) {
5215
4993
  isAllResponse = false;
5216
4994
  }
5217
-
5218
4995
  return axios__WEBPACK_IMPORTED_MODULE_1___default()(params).then(function (response) {
5219
4996
  return isAllResponse ? response : response.data;
5220
4997
  })["catch"](function (error) {
@@ -5222,7 +4999,6 @@ function () {
5222
4999
  throw error;
5223
5000
  });
5224
5001
  };
5225
-
5226
5002
  RestClient.prototype._parseUrl = function (url) {
5227
5003
  var parts = url.split('/');
5228
5004
  return {
@@ -5230,12 +5006,10 @@ function () {
5230
5006
  path: '/' + parts.slice(3).join('/')
5231
5007
  };
5232
5008
  };
5233
-
5234
5009
  return RestClient;
5235
5010
  }();
5236
5011
 
5237
5012
 
5238
-
5239
5013
  /***/ }),
5240
5014
 
5241
5015
  /***/ "./lib-esm/index.js":