@aws-amplify/core 4.3.15-unstable.8 → 4.4.1-cloud-logging.7

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 (49) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/aws-amplify-core.js +282 -104
  3. package/dist/aws-amplify-core.js.map +1 -1
  4. package/dist/aws-amplify-core.min.js +6 -6
  5. package/dist/aws-amplify-core.min.js.map +1 -1
  6. package/lib/Logger/ConsoleLogger.d.ts +6 -0
  7. package/lib/Logger/ConsoleLogger.js +117 -43
  8. package/lib/Logger/ConsoleLogger.js.map +1 -1
  9. package/lib/Platform/version.d.ts +1 -1
  10. package/lib/Platform/version.js +1 -1
  11. package/lib/Platform/version.js.map +1 -1
  12. package/lib/Providers/AWSCloudWatchProvider.d.ts +11 -3
  13. package/lib/Providers/AWSCloudWatchProvider.js +97 -37
  14. package/lib/Providers/AWSCloudWatchProvider.js.map +1 -1
  15. package/lib/Providers/AmazonKinesisLoggingProvider.d.ts +13 -0
  16. package/lib/Providers/AmazonKinesisLoggingProvider.js +30 -0
  17. package/lib/Providers/AmazonKinesisLoggingProvider.js.map +1 -0
  18. package/lib/Util/Constants.d.ts +3 -1
  19. package/lib/Util/Constants.js +5 -0
  20. package/lib/Util/Constants.js.map +1 -1
  21. package/lib/Util/Retry.js +1 -1
  22. package/lib/Util/Retry.js.map +1 -1
  23. package/lib/types/types.d.ts +13 -0
  24. package/lib-esm/Logger/ConsoleLogger.d.ts +6 -0
  25. package/lib-esm/Logger/ConsoleLogger.js +117 -43
  26. package/lib-esm/Logger/ConsoleLogger.js.map +1 -1
  27. package/lib-esm/Platform/version.d.ts +1 -1
  28. package/lib-esm/Platform/version.js +1 -1
  29. package/lib-esm/Platform/version.js.map +1 -1
  30. package/lib-esm/Providers/AWSCloudWatchProvider.d.ts +11 -3
  31. package/lib-esm/Providers/AWSCloudWatchProvider.js +97 -37
  32. package/lib-esm/Providers/AWSCloudWatchProvider.js.map +1 -1
  33. package/lib-esm/Providers/AmazonKinesisLoggingProvider.d.ts +13 -0
  34. package/lib-esm/Providers/AmazonKinesisLoggingProvider.js +28 -0
  35. package/lib-esm/Providers/AmazonKinesisLoggingProvider.js.map +1 -0
  36. package/lib-esm/Util/Constants.d.ts +3 -1
  37. package/lib-esm/Util/Constants.js +4 -1
  38. package/lib-esm/Util/Constants.js.map +1 -1
  39. package/lib-esm/Util/Retry.js +1 -1
  40. package/lib-esm/Util/Retry.js.map +1 -1
  41. package/lib-esm/types/types.d.ts +13 -0
  42. package/package.json +3 -2
  43. package/src/Logger/ConsoleLogger.ts +117 -34
  44. package/src/Platform/version.ts +1 -1
  45. package/src/Providers/AWSCloudWatchProvider.ts +112 -18
  46. package/src/Providers/AmazonKinesisLoggingProvider.ts +43 -0
  47. package/src/Util/Constants.ts +7 -0
  48. package/src/Util/Retry.ts +2 -3
  49. package/src/types/types.ts +79 -62
package/CHANGELOG.md CHANGED
@@ -3,6 +3,22 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [4.4.0](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/core@4.3.14...@aws-amplify/core@4.4.0) (2022-02-28)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * pin async storage to 1.15.17 ([#9570](https://github.com/aws-amplify/amplify-js/issues/9570)) ([bc5235a](https://github.com/aws-amplify/amplify-js/commit/bc5235ac0d15242f7a13457f40999b5331823395))
12
+
13
+
14
+ ### Features
15
+
16
+ * **@aws-amplify/core:** add ui protected channel ([#9554](https://github.com/aws-amplify/amplify-js/issues/9554)) ([86e07fc](https://github.com/aws-amplify/amplify-js/commit/86e07fcd3ebbaa5f03d65ed8009b7531ee300e39))
17
+
18
+
19
+
20
+
21
+
6
22
  ## [4.3.14](https://github.com/aws-amplify/amplify-js/compare/@aws-amplify/core@4.3.13...@aws-amplify/core@4.3.14) (2022-02-03)
7
23
 
8
24
  **Note:** Version bump only for package @aws-amplify/core
@@ -25979,6 +25979,24 @@ function tryDecode(str, decode) {
25979
25979
  }
25980
25980
 
25981
25981
 
25982
+ /***/ }),
25983
+
25984
+ /***/ "../../node_modules/fast-text-encoding/text.min.js":
25985
+ /*!********************************************************************!*\
25986
+ !*** /root/amplify-js/node_modules/fast-text-encoding/text.min.js ***!
25987
+ \********************************************************************/
25988
+ /*! no static exports found */
25989
+ /***/ (function(module, exports, __webpack_require__) {
25990
+
25991
+ /* WEBPACK VAR INJECTION */(function(global, Buffer) {(function(l){function m(){}function k(a,c){a=void 0===a?"utf-8":a;c=void 0===c?{fatal:!1}:c;if(-1===r.indexOf(a.toLowerCase()))throw new RangeError("Failed to construct 'TextDecoder': The encoding label provided ('"+a+"') is invalid.");if(c.fatal)throw Error("Failed to construct 'TextDecoder': the 'fatal' option is unsupported.");}function t(a){return Buffer.from(a.buffer,a.byteOffset,a.byteLength).toString("utf-8")}function u(a){var c=URL.createObjectURL(new Blob([a],{type:"text/plain;charset=UTF-8"}));
25992
+ try{var f=new XMLHttpRequest;f.open("GET",c,!1);f.send();return f.responseText}catch(e){return q(a)}finally{URL.revokeObjectURL(c)}}function q(a){for(var c=0,f=Math.min(65536,a.length+1),e=new Uint16Array(f),h=[],d=0;;){var b=c<a.length;if(!b||d>=f-1){h.push(String.fromCharCode.apply(null,e.subarray(0,d)));if(!b)return h.join("");a=a.subarray(c);d=c=0}b=a[c++];if(0===(b&128))e[d++]=b;else if(192===(b&224)){var g=a[c++]&63;e[d++]=(b&31)<<6|g}else if(224===(b&240)){g=a[c++]&63;var n=a[c++]&63;e[d++]=
25993
+ (b&31)<<12|g<<6|n}else if(240===(b&248)){g=a[c++]&63;n=a[c++]&63;var v=a[c++]&63;b=(b&7)<<18|g<<12|n<<6|v;65535<b&&(b-=65536,e[d++]=b>>>10&1023|55296,b=56320|b&1023);e[d++]=b}}}if(l.TextEncoder&&l.TextDecoder)return!1;var r=["utf-8","utf8","unicode-1-1-utf-8"];Object.defineProperty(m.prototype,"encoding",{value:"utf-8"});m.prototype.encode=function(a,c){c=void 0===c?{stream:!1}:c;if(c.stream)throw Error("Failed to encode: the 'stream' option is unsupported.");c=0;for(var f=a.length,e=0,h=Math.max(32,
25994
+ f+(f>>>1)+7),d=new Uint8Array(h>>>3<<3);c<f;){var b=a.charCodeAt(c++);if(55296<=b&&56319>=b){if(c<f){var g=a.charCodeAt(c);56320===(g&64512)&&(++c,b=((b&1023)<<10)+(g&1023)+65536)}if(55296<=b&&56319>=b)continue}e+4>d.length&&(h+=8,h*=1+c/a.length*2,h=h>>>3<<3,g=new Uint8Array(h),g.set(d),d=g);if(0===(b&4294967168))d[e++]=b;else{if(0===(b&4294965248))d[e++]=b>>>6&31|192;else if(0===(b&4294901760))d[e++]=b>>>12&15|224,d[e++]=b>>>6&63|128;else if(0===(b&4292870144))d[e++]=b>>>18&7|240,d[e++]=b>>>12&
25995
+ 63|128,d[e++]=b>>>6&63|128;else continue;d[e++]=b&63|128}}return d.slice?d.slice(0,e):d.subarray(0,e)};Object.defineProperty(k.prototype,"encoding",{value:"utf-8"});Object.defineProperty(k.prototype,"fatal",{value:!1});Object.defineProperty(k.prototype,"ignoreBOM",{value:!1});var p=q;"function"===typeof Buffer&&Buffer.from?p=t:"function"===typeof Blob&&"function"===typeof URL&&"function"===typeof URL.createObjectURL&&(p=u);k.prototype.decode=function(a,c){c=void 0===c?{stream:!1}:c;if(c.stream)throw Error("Failed to decode: the 'stream' option is unsupported.");
25996
+ a=a instanceof Uint8Array?a:a.buffer instanceof ArrayBuffer?new Uint8Array(a.buffer):new Uint8Array(a);return p(a)};l.TextEncoder=m;l.TextDecoder=k})("undefined"!==typeof window?window:"undefined"!==typeof global?global:this);
25997
+
25998
+ /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../webpack/buildin/global.js */ "../../node_modules/webpack/buildin/global.js"), __webpack_require__(/*! ./../buffer/index.js */ "../../node_modules/buffer/index.js").Buffer))
25999
+
25982
26000
  /***/ }),
25983
26001
 
25984
26002
  /***/ "../../node_modules/ieee754/index.js":
@@ -31646,6 +31664,7 @@ var LOG_LEVELS = {
31646
31664
  WARN: 4,
31647
31665
  ERROR: 5
31648
31666
  };
31667
+ var COMPATIBLE_PLUGINS = [_Util_Constants__WEBPACK_IMPORTED_MODULE_0__["AWS_CLOUDWATCH_CATEGORY"]];
31649
31668
  var LOG_TYPE;
31650
31669
 
31651
31670
  (function (LOG_TYPE) {
@@ -31655,12 +31674,13 @@ var LOG_TYPE;
31655
31674
  LOG_TYPE["WARN"] = "WARN";
31656
31675
  LOG_TYPE["VERBOSE"] = "VERBOSE";
31657
31676
  })(LOG_TYPE || (LOG_TYPE = {}));
31677
+
31678
+ var cloudWatchExcludeList = ['AWSCloudWatch', 'Amplify', 'Credentials', 'AuthClass', 'CloudLogger'];
31658
31679
  /**
31659
31680
  * Write logs
31660
31681
  * @class Logger
31661
31682
  */
31662
31683
 
31663
-
31664
31684
  var ConsoleLogger =
31665
31685
  /** @class */
31666
31686
  function () {
@@ -31676,8 +31696,19 @@ function () {
31676
31696
  this.name = name;
31677
31697
  this.level = level;
31678
31698
  this._pluggables = [];
31699
+ this.addPluggable = this.addPluggable.bind(this);
31679
31700
  }
31680
31701
 
31702
+ ConsoleLogger.globalPluggables = function (pluggable) {
31703
+ if (pluggable && COMPATIBLE_PLUGINS.includes(pluggable.getCategoryName())) {
31704
+ ConsoleLogger._globalpluggables.push(pluggable);
31705
+ }
31706
+ };
31707
+
31708
+ ConsoleLogger.clearGlobalPluggables = function () {
31709
+ ConsoleLogger._globalpluggables = [];
31710
+ };
31711
+
31681
31712
  ConsoleLogger.prototype._padding = function (n) {
31682
31713
  return n < 10 ? '0' + n : '' + n;
31683
31714
  };
@@ -31692,6 +31723,20 @@ function () {
31692
31723
  this._config = config;
31693
31724
  return this._config;
31694
31725
  };
31726
+
31727
+ ConsoleLogger.prototype._checkPluggables = function () {
31728
+ if (this._pluggables.length !== ConsoleLogger._globalpluggables.length) {
31729
+ if (ConsoleLogger._globalpluggables.length > 0) {
31730
+ ConsoleLogger._globalpluggables.forEach(this.addPluggable);
31731
+
31732
+ return;
31733
+ }
31734
+
31735
+ if (ConsoleLogger._globalpluggables.length === 0) {
31736
+ this._pluggables = [];
31737
+ }
31738
+ }
31739
+ };
31695
31740
  /**
31696
31741
  * Write log
31697
31742
  * @method
@@ -31704,12 +31749,47 @@ function () {
31704
31749
  ConsoleLogger.prototype._log = function (type) {
31705
31750
  var e_1, _a;
31706
31751
 
31752
+ var _this = this;
31753
+
31707
31754
  var msg = [];
31708
31755
 
31709
31756
  for (var _i = 1; _i < arguments.length; _i++) {
31710
31757
  msg[_i - 1] = arguments[_i];
31711
31758
  }
31712
31759
 
31760
+ if (!cloudWatchExcludeList.includes(this.name)) {
31761
+ this._checkPluggables();
31762
+ }
31763
+
31764
+ var generateCloudMessage = function generateCloudMessage(msg) {
31765
+ var message = '';
31766
+ var data;
31767
+
31768
+ if (msg.length === 1 && typeof msg[0] === 'string') {
31769
+ message = msg[0];
31770
+ } else if (msg.length === 1) {
31771
+ data = msg[0];
31772
+ } else if (typeof msg[0] === 'string') {
31773
+ var obj = msg.slice(1);
31774
+
31775
+ if (obj.length === 1) {
31776
+ obj = obj[0];
31777
+ }
31778
+
31779
+ message = msg[0];
31780
+ data = obj;
31781
+ } else {
31782
+ data = msg;
31783
+ }
31784
+
31785
+ return JSON.stringify({
31786
+ level: type,
31787
+ "class": _this.name,
31788
+ message: message,
31789
+ data: data
31790
+ });
31791
+ };
31792
+
31713
31793
  var logger_level_name = this.level;
31714
31794
 
31715
31795
  if (ConsoleLogger.LOG_LEVEL) {
@@ -31723,62 +31803,72 @@ function () {
31723
31803
  var logger_level = LOG_LEVELS[logger_level_name];
31724
31804
  var type_level = LOG_LEVELS[type];
31725
31805
 
31726
- if (!(type_level >= logger_level)) {
31727
- // Do nothing if type is not greater than or equal to logger level (handle undefined)
31728
- return;
31729
- }
31806
+ if (type_level >= logger_level) {
31807
+ var log = console.log.bind(console);
31730
31808
 
31731
- var log = console.log.bind(console);
31809
+ if (type === LOG_TYPE.ERROR && console.error) {
31810
+ log = console.error.bind(console);
31811
+ }
31732
31812
 
31733
- if (type === LOG_TYPE.ERROR && console.error) {
31734
- log = console.error.bind(console);
31735
- }
31813
+ if (type === LOG_TYPE.WARN && console.warn) {
31814
+ log = console.warn.bind(console);
31815
+ }
31736
31816
 
31737
- if (type === LOG_TYPE.WARN && console.warn) {
31738
- log = console.warn.bind(console);
31739
- }
31817
+ var prefix = "[" + type + "] " + this._ts() + " " + this.name;
31818
+ var message = '';
31819
+ var data = void 0;
31740
31820
 
31741
- var prefix = "[" + type + "] " + this._ts() + " " + this.name;
31742
- var message = '';
31821
+ if (msg.length === 1 && typeof msg[0] === 'string') {
31822
+ message = msg[0];
31823
+ log(prefix + " - " + message);
31824
+ } else if (msg.length === 1) {
31825
+ data = msg[0];
31826
+ log(prefix, data);
31827
+ } else if (typeof msg[0] === 'string') {
31828
+ var obj = msg.slice(1);
31743
31829
 
31744
- if (msg.length === 1 && typeof msg[0] === 'string') {
31745
- message = prefix + " - " + msg[0];
31746
- log(message);
31747
- } else if (msg.length === 1) {
31748
- message = prefix + " " + msg[0];
31749
- log(prefix, msg[0]);
31750
- } else if (typeof msg[0] === 'string') {
31751
- var obj = msg.slice(1);
31830
+ if (obj.length === 1) {
31831
+ obj = obj[0];
31832
+ }
31752
31833
 
31753
- if (obj.length === 1) {
31754
- obj = obj[0];
31834
+ message = msg[0];
31835
+ data = obj;
31836
+ log(prefix + " - " + message, data);
31837
+ } else {
31838
+ data = msg;
31839
+ log(prefix, data);
31755
31840
  }
31756
-
31757
- message = prefix + " - " + msg[0] + " " + obj;
31758
- log(prefix + " - " + msg[0], obj);
31759
- } else {
31760
- message = prefix + " " + msg;
31761
- log(prefix, msg);
31762
31841
  }
31763
31842
 
31764
- try {
31765
- for (var _b = __values(this._pluggables), _c = _b.next(); !_c.done; _c = _b.next()) {
31766
- var plugin = _c.value;
31767
- var logEvent = {
31768
- message: message,
31769
- timestamp: Date.now()
31770
- };
31771
- plugin.pushLogs([logEvent]);
31772
- }
31773
- } catch (e_1_1) {
31774
- e_1 = {
31775
- error: e_1_1
31776
- };
31777
- } finally {
31843
+ if (ConsoleLogger.CLOUD_LOG_LEVEL != null && !cloudWatchExcludeList.includes(this.name)) {
31844
+ var cloudMessage = generateCloudMessage(msg);
31845
+
31778
31846
  try {
31779
- if (_c && !_c.done && (_a = _b["return"])) _a.call(_b);
31847
+ for (var _b = __values(this._pluggables), _c = _b.next(); !_c.done; _c = _b.next()) {
31848
+ var plugin = _c.value;
31849
+ var logger_level_1 = LOG_LEVELS[ConsoleLogger.CLOUD_LOG_LEVEL];
31850
+ var type_level_1 = LOG_LEVELS[type];
31851
+ var logEvent = {
31852
+ message: cloudMessage,
31853
+ timestamp: Date.now()
31854
+ };
31855
+
31856
+ if (type_level_1 >= logger_level_1) {
31857
+ plugin.pushLogs([logEvent]);
31858
+ } else {
31859
+ plugin.pushLogs([]);
31860
+ }
31861
+ }
31862
+ } catch (e_1_1) {
31863
+ e_1 = {
31864
+ error: e_1_1
31865
+ };
31780
31866
  } finally {
31781
- if (e_1) throw e_1.error;
31867
+ try {
31868
+ if (_c && !_c.done && (_a = _b["return"])) _a.call(_b);
31869
+ } finally {
31870
+ if (e_1) throw e_1.error;
31871
+ }
31782
31872
  }
31783
31873
  }
31784
31874
  };
@@ -31886,10 +31976,8 @@ function () {
31886
31976
  };
31887
31977
 
31888
31978
  ConsoleLogger.prototype.addPluggable = function (pluggable) {
31889
- if (pluggable && pluggable.getCategoryName() === _Util_Constants__WEBPACK_IMPORTED_MODULE_0__["AWS_CLOUDWATCH_CATEGORY"]) {
31979
+ if (pluggable && COMPATIBLE_PLUGINS.includes(pluggable.getCategoryName())) {
31890
31980
  this._pluggables.push(pluggable);
31891
-
31892
- pluggable.configure(this._config);
31893
31981
  }
31894
31982
  };
31895
31983
 
@@ -31897,7 +31985,9 @@ function () {
31897
31985
  return this._pluggables;
31898
31986
  };
31899
31987
 
31988
+ ConsoleLogger._globalpluggables = [];
31900
31989
  ConsoleLogger.LOG_LEVEL = null;
31990
+ ConsoleLogger.CLOUD_LOG_LEVEL = null;
31901
31991
  return ConsoleLogger;
31902
31992
  }();
31903
31993
 
@@ -32725,7 +32815,7 @@ var getAmplifyUserAgent = function getAmplifyUserAgent() {
32725
32815
  __webpack_require__.r(__webpack_exports__);
32726
32816
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "version", function() { return version; });
32727
32817
  // generated by genversion
32728
- var version = '4.3.14';
32818
+ var version = '4.4.0';
32729
32819
 
32730
32820
  /***/ }),
32731
32821
 
@@ -32745,6 +32835,15 @@ __webpack_require__.r(__webpack_exports__);
32745
32835
  /* harmony import */ var _Platform__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../Platform */ "./lib-esm/Platform/index.js");
32746
32836
  /* harmony import */ var _Parser__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../Parser */ "./lib-esm/Parser.js");
32747
32837
  /* harmony import */ var _Util_Constants__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ../Util/Constants */ "./lib-esm/Util/Constants.js");
32838
+ function _typeof(obj) {
32839
+ "@babel/helpers - typeof";
32840
+
32841
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
32842
+ return typeof obj;
32843
+ } : function (obj) {
32844
+ return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
32845
+ }, _typeof(obj);
32846
+ }
32748
32847
  /*
32749
32848
  * Copyright 2017-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
32750
32849
  *
@@ -32757,6 +32856,8 @@ __webpack_require__.r(__webpack_exports__);
32757
32856
  * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
32758
32857
  * and limitations under the License.
32759
32858
  */
32859
+
32860
+
32760
32861
  var __awaiter = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
32761
32862
  function adopt(value) {
32762
32863
  return value instanceof P ? value : new P(function (resolve) {
@@ -32900,61 +33001,42 @@ var __generator = undefined && undefined.__generator || function (thisArg, body)
32900
33001
  }
32901
33002
  };
32902
33003
 
32903
- var __read = undefined && undefined.__read || function (o, n) {
32904
- var m = typeof Symbol === "function" && o[Symbol.iterator];
32905
- if (!m) return o;
32906
- var i = m.call(o),
32907
- r,
32908
- ar = [],
32909
- e;
32910
33004
 
32911
- try {
32912
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
32913
- ar.push(r.value);
32914
- }
32915
- } catch (error) {
32916
- e = {
32917
- error: error
32918
- };
32919
- } finally {
32920
- try {
32921
- if (r && !r.done && (m = i["return"])) m.call(i);
32922
- } finally {
32923
- if (e) throw e.error;
32924
- }
32925
- }
32926
-
32927
- return ar;
32928
- };
32929
-
32930
- var __spread = undefined && undefined.__spread || function () {
32931
- for (var ar = [], i = 0; i < arguments.length; i++) {
32932
- ar = ar.concat(__read(arguments[i]));
32933
- }
32934
-
32935
- return ar;
32936
- };
32937
33005
 
32938
33006
 
32939
33007
 
32940
33008
 
32941
33009
 
32942
33010
 
33011
+ if (typeof window === 'undefined' || (typeof window === "undefined" ? "undefined" : _typeof(window)) === 'object' && !window.TextEncoder) {
33012
+ __webpack_require__(/*! fast-text-encoding */ "../../node_modules/fast-text-encoding/text.min.js");
33013
+ }
32943
33014
 
32944
33015
  var logger = new _Logger__WEBPACK_IMPORTED_MODULE_2__["ConsoleLogger"]('AWSCloudWatch');
33016
+ var INTERVAL = 10000;
32945
33017
 
32946
33018
  var AWSCloudWatchProvider =
32947
33019
  /** @class */
32948
33020
  function () {
32949
33021
  function AWSCloudWatchProvider(config) {
32950
- this.configure(config);
32951
- this._dataTracker = {
32952
- eventUploadInProgress: false,
32953
- logEvents: []
32954
- };
32955
- this._currentLogBatch = [];
33022
+ this._initialized = false;
33023
+ console.log('cstr', config);
32956
33024
 
32957
- this._initiateLogPushInterval();
33025
+ if (!this._initialized) {
33026
+ this.configure(config);
33027
+ this._dataTracker = {
33028
+ eventUploadInProgress: false,
33029
+ logEvents: [],
33030
+ verifiedLogGroup: {
33031
+ logGroupName: this._config.logGroupName
33032
+ }
33033
+ };
33034
+ this._currentLogBatch = [];
33035
+
33036
+ this._initiateLogPushInterval();
33037
+
33038
+ this._initialized = true;
33039
+ }
32958
33040
  }
32959
33041
 
32960
33042
  AWSCloudWatchProvider.prototype.getProviderName = function () {
@@ -32969,6 +33051,12 @@ function () {
32969
33051
  return this._dataTracker.logEvents;
32970
33052
  };
32971
33053
 
33054
+ AWSCloudWatchProvider.prototype.setPreFlightCheck = function (cb) {
33055
+ if (typeof cb === 'function') {
33056
+ this._preFlightCheck = cb;
33057
+ }
33058
+ };
33059
+
32972
33060
  AWSCloudWatchProvider.prototype.configure = function (config) {
32973
33061
  if (!config) return this._config || {};
32974
33062
  var conf = Object.assign({}, this._config, Object(_Parser__WEBPACK_IMPORTED_MODULE_4__["parseMobileHubConfig"])(config).Logging, config);
@@ -33222,8 +33310,27 @@ function () {
33222
33310
  };
33223
33311
 
33224
33312
  AWSCloudWatchProvider.prototype.pushLogs = function (logs) {
33225
- logger.debug('pushing log events to Cloudwatch...');
33226
- this._dataTracker.logEvents = __spread(this._dataTracker.logEvents, logs);
33313
+ logger.debug('pushing log events to buffer');
33314
+ this._dataTracker.logEvents = this._dataTracker.logEvents.concat(logs);
33315
+ };
33316
+
33317
+ AWSCloudWatchProvider.prototype.pause = function () {
33318
+ this._processing = false;
33319
+
33320
+ if (this._timer) {
33321
+ clearInterval(this._timer);
33322
+ }
33323
+ };
33324
+
33325
+ AWSCloudWatchProvider.prototype.resume = function () {
33326
+ this._processing = true;
33327
+
33328
+ this._initiateLogPushInterval();
33329
+ };
33330
+
33331
+ AWSCloudWatchProvider.prototype.clear = function () {
33332
+ this._dataTracker.logEvents = [];
33333
+ this._currentLogBatch = [];
33227
33334
  };
33228
33335
 
33229
33336
  AWSCloudWatchProvider.prototype._validateLogGroupExistsAndCreate = function (logGroupName) {
@@ -33540,13 +33647,33 @@ function () {
33540
33647
  return __generator(this, function (_a) {
33541
33648
  switch (_a.label) {
33542
33649
  case 0:
33543
- _a.trys.push([0, 3,, 4]);
33650
+ _a.trys.push([0, 4,, 5]);
33544
33651
 
33545
33652
  return [4
33546
33653
  /*yield*/
33547
- , this._getNextSequenceToken()];
33654
+ , this._preFlightCheck()];
33548
33655
 
33549
33656
  case 1:
33657
+ /**
33658
+ * CloudWatch has restrictions on the size of the log events that get sent up.
33659
+ * We need to track both the size of each event and the total size of the batch
33660
+ * of logs.
33661
+ *
33662
+ * We also need to ensure that the logs in the batch are sorted in chronological order.
33663
+ * https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_PutLogEvents.html
33664
+ */
33665
+ if (!_a.sent()) {
33666
+ this.clear();
33667
+ return [2
33668
+ /*return*/
33669
+ ];
33670
+ }
33671
+
33672
+ return [4
33673
+ /*yield*/
33674
+ , this._getNextSequenceToken()];
33675
+
33676
+ case 2:
33550
33677
  seqToken = _a.sent();
33551
33678
  logBatch = this._currentLogBatch.length === 0 ? this._getBufferedBatchOfLogs() : this._currentLogBatch;
33552
33679
  putLogsPayload = {
@@ -33560,7 +33687,7 @@ function () {
33560
33687
  /*yield*/
33561
33688
  , this._sendLogEvents(putLogsPayload)];
33562
33689
 
33563
- case 2:
33690
+ case 3:
33564
33691
  sendLogEventsResponse = _a.sent();
33565
33692
  this._nextSequenceToken = sendLogEventsResponse.nextSequenceToken;
33566
33693
  this._dataTracker.eventUploadInProgress = false;
@@ -33569,7 +33696,7 @@ function () {
33569
33696
  /*return*/
33570
33697
  , sendLogEventsResponse];
33571
33698
 
33572
- case 3:
33699
+ case 4:
33573
33700
  err_5 = _a.sent();
33574
33701
  logger.error("error during _safeUploadLogEvents: " + err_5);
33575
33702
 
@@ -33586,9 +33713,9 @@ function () {
33586
33713
 
33587
33714
  return [3
33588
33715
  /*break*/
33589
- , 4];
33716
+ , 5];
33590
33717
 
33591
- case 4:
33718
+ case 5:
33592
33719
  return [2
33593
33720
  /*return*/
33594
33721
  ];
@@ -33597,6 +33724,41 @@ function () {
33597
33724
  });
33598
33725
  };
33599
33726
 
33727
+ AWSCloudWatchProvider.prototype.truncateOversizedEvent = function (event) {
33728
+ var timestamp = event.timestamp,
33729
+ message = event.message;
33730
+ var messageJson;
33731
+
33732
+ try {
33733
+ messageJson = JSON.parse(message);
33734
+ var truncated = JSON.stringify({
33735
+ level: messageJson.level,
33736
+ "class": messageJson["class"],
33737
+ message: messageJson.message.substring(0, 500)
33738
+ });
33739
+
33740
+ if (messageJson.data != null) {
33741
+ truncated['data'] = "OBJECT SIZE EXCEEDS CLOUDWATCH EVENT LIMIT. Truncated: " + JSON.stringify(messageJson.data).substring(0, 500);
33742
+ }
33743
+
33744
+ return {
33745
+ timestamp: timestamp,
33746
+ message: truncated
33747
+ };
33748
+ } catch (error) {
33749
+ logger.warn('Could not minify oversized event', error);
33750
+ var truncated = JSON.stringify({
33751
+ level: 'UNKNOWN',
33752
+ "class": 'Unknown',
33753
+ message: 'OBJECT SIZE EXCEEDS CLOUDWATCH EVENT LIMIT. Could not parse event to truncate'
33754
+ });
33755
+ return {
33756
+ timestamp: timestamp,
33757
+ message: truncated
33758
+ };
33759
+ }
33760
+ };
33761
+
33600
33762
  AWSCloudWatchProvider.prototype._getBufferedBatchOfLogs = function () {
33601
33763
  /**
33602
33764
  * CloudWatch has restrictions on the size of the log events that get sent up.
@@ -33616,7 +33778,9 @@ function () {
33616
33778
  if (eventSize > _Util_Constants__WEBPACK_IMPORTED_MODULE_5__["AWS_CLOUDWATCH_MAX_EVENT_SIZE"]) {
33617
33779
  var errString = "Log entry exceeds maximum size for CloudWatch logs. Log size: " + eventSize + ". Truncating log message.";
33618
33780
  logger.warn(errString);
33619
- currentEvent.message = currentEvent.message.substring(0, eventSize);
33781
+ currentEvent = this.truncateOversizedEvent(currentEvent);
33782
+ this._dataTracker.logEvents[currentEventIdx] = currentEvent;
33783
+ eventSize = new TextEncoder().encode(currentEvent.message).length + _Util_Constants__WEBPACK_IMPORTED_MODULE_5__["AWS_CLOUDWATCH_BASE_BUFFER_SIZE"];
33620
33784
  }
33621
33785
 
33622
33786
  if (totalByteSize + eventSize > _Util_Constants__WEBPACK_IMPORTED_MODULE_5__["AWS_CLOUDWATCH_MAX_BATCH_EVENT_SIZE"]) break;
@@ -33707,6 +33871,7 @@ function () {
33707
33871
  case 3:
33708
33872
  err_7 = _a.sent();
33709
33873
  logger.error("error when calling _safeUploadLogEvents in the timer interval - " + err_7);
33874
+ this.pause();
33710
33875
  return [3
33711
33876
  /*break*/
33712
33877
  , 4];
@@ -33718,7 +33883,7 @@ function () {
33718
33883
  }
33719
33884
  });
33720
33885
  });
33721
- }, 2000);
33886
+ }, INTERVAL);
33722
33887
  };
33723
33888
 
33724
33889
  AWSCloudWatchProvider.prototype._getDocUploadPermissibility = function () {
@@ -34750,7 +34915,7 @@ function () {
34750
34915
  /*!***********************************!*\
34751
34916
  !*** ./lib-esm/Util/Constants.js ***!
34752
34917
  \***********************************/
34753
- /*! exports provided: AWS_CLOUDWATCH_BASE_BUFFER_SIZE, AWS_CLOUDWATCH_CATEGORY, AWS_CLOUDWATCH_MAX_BATCH_EVENT_SIZE, AWS_CLOUDWATCH_MAX_EVENT_SIZE, AWS_CLOUDWATCH_PROVIDER_NAME, NO_CREDS_ERROR_STRING, RETRY_ERROR_CODES */
34918
+ /*! exports provided: AWS_CLOUDWATCH_BASE_BUFFER_SIZE, AWS_CLOUDWATCH_CATEGORY, AWS_CLOUDWATCH_MAX_BATCH_EVENT_SIZE, AWS_CLOUDWATCH_MAX_EVENT_SIZE, AWS_CLOUDWATCH_PROVIDER_NAME, NO_CREDS_ERROR_STRING, RETRY_ERROR_CODES, AMAZON_KINESIS_LOGGING_PROVIDER_NAME, AMAZON_KINESIS_LOGGING_CATEGORY */
34754
34919
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
34755
34920
 
34756
34921
  "use strict";
@@ -34762,6 +34927,8 @@ __webpack_require__.r(__webpack_exports__);
34762
34927
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "AWS_CLOUDWATCH_PROVIDER_NAME", function() { return AWS_CLOUDWATCH_PROVIDER_NAME; });
34763
34928
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "NO_CREDS_ERROR_STRING", function() { return NO_CREDS_ERROR_STRING; });
34764
34929
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "RETRY_ERROR_CODES", function() { return RETRY_ERROR_CODES; });
34930
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "AMAZON_KINESIS_LOGGING_PROVIDER_NAME", function() { return AMAZON_KINESIS_LOGGING_PROVIDER_NAME; });
34931
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "AMAZON_KINESIS_LOGGING_CATEGORY", function() { return AMAZON_KINESIS_LOGGING_CATEGORY; });
34765
34932
  /*
34766
34933
  * Copyright 2017-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
34767
34934
  *
@@ -34775,11 +34942,14 @@ __webpack_require__.r(__webpack_exports__);
34775
34942
  * and limitations under the License.
34776
34943
  */
34777
34944
  // Logging constants
34945
+ // Cloudwatch
34778
34946
  var AWS_CLOUDWATCH_BASE_BUFFER_SIZE = 26;
34779
34947
  var AWS_CLOUDWATCH_MAX_BATCH_EVENT_SIZE = 1048576;
34780
34948
  var AWS_CLOUDWATCH_MAX_EVENT_SIZE = 256000;
34781
34949
  var AWS_CLOUDWATCH_CATEGORY = 'Logging';
34782
34950
  var AWS_CLOUDWATCH_PROVIDER_NAME = 'AWSCloudWatch';
34951
+ var AMAZON_KINESIS_LOGGING_CATEGORY = 'KinesisLogging';
34952
+ var AMAZON_KINESIS_LOGGING_PROVIDER_NAME = 'AmazonKinesisLogging';
34783
34953
  var NO_CREDS_ERROR_STRING = 'No credentials';
34784
34954
  var RETRY_ERROR_CODES = ['ResourceNotFoundException', 'InvalidSequenceTokenException'];
34785
34955
 
@@ -35365,7 +35535,7 @@ function retry(functionToRetry, args, delayFn, attempt) {
35365
35535
  throw Error('functionToRetry must be a function');
35366
35536
  }
35367
35537
 
35368
- logger.debug(functionToRetry.name + " attempt #" + attempt + " with this vars: " + JSON.stringify(args));
35538
+ logger.debug(functionToRetry.name + " attempt #" + attempt + " with this vars:", args);
35369
35539
  _a.label = 1;
35370
35540
 
35371
35541
  case 1:
@@ -35482,7 +35652,7 @@ function urlSafeDecode(hex) {
35482
35652
  /*!*******************************!*\
35483
35653
  !*** ./lib-esm/Util/index.js ***!
35484
35654
  \*******************************/
35485
- /*! exports provided: NonRetryableError, retry, jitteredExponentialRetry, Mutex, Reachability, DateUtils, urlSafeEncode, urlSafeDecode, AWS_CLOUDWATCH_BASE_BUFFER_SIZE, AWS_CLOUDWATCH_CATEGORY, AWS_CLOUDWATCH_MAX_BATCH_EVENT_SIZE, AWS_CLOUDWATCH_MAX_EVENT_SIZE, AWS_CLOUDWATCH_PROVIDER_NAME, NO_CREDS_ERROR_STRING, RETRY_ERROR_CODES */
35655
+ /*! exports provided: NonRetryableError, retry, jitteredExponentialRetry, Mutex, Reachability, DateUtils, urlSafeEncode, urlSafeDecode, AWS_CLOUDWATCH_BASE_BUFFER_SIZE, AWS_CLOUDWATCH_CATEGORY, AWS_CLOUDWATCH_MAX_BATCH_EVENT_SIZE, AWS_CLOUDWATCH_MAX_EVENT_SIZE, AWS_CLOUDWATCH_PROVIDER_NAME, NO_CREDS_ERROR_STRING, RETRY_ERROR_CODES, AMAZON_KINESIS_LOGGING_PROVIDER_NAME, AMAZON_KINESIS_LOGGING_CATEGORY */
35486
35656
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
35487
35657
 
35488
35658
  "use strict";
@@ -35523,6 +35693,10 @@ __webpack_require__.r(__webpack_exports__);
35523
35693
 
35524
35694
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "RETRY_ERROR_CODES", function() { return _Constants__WEBPACK_IMPORTED_MODULE_5__["RETRY_ERROR_CODES"]; });
35525
35695
 
35696
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "AMAZON_KINESIS_LOGGING_PROVIDER_NAME", function() { return _Constants__WEBPACK_IMPORTED_MODULE_5__["AMAZON_KINESIS_LOGGING_PROVIDER_NAME"]; });
35697
+
35698
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "AMAZON_KINESIS_LOGGING_CATEGORY", function() { return _Constants__WEBPACK_IMPORTED_MODULE_5__["AMAZON_KINESIS_LOGGING_CATEGORY"]; });
35699
+
35526
35700
 
35527
35701
 
35528
35702
 
@@ -35572,7 +35746,7 @@ var USER_AGENT_HEADER = 'x-amz-user-agent';
35572
35746
  /*!**************************!*\
35573
35747
  !*** ./lib-esm/index.js ***!
35574
35748
  \**************************/
35575
- /*! exports provided: AmplifyClass, ClientDevice, ConsoleLogger, Logger, missingConfig, invalidParameter, Hub, I18n, isEmpty, sortByField, objectLessAttributes, filenameToContentType, isTextFile, generateRandomString, makeQuerablePromise, isWebWorker, browserOrNode, transferKeyToLowerCase, transferKeyToUpperCase, isStrictObject, JS, Signer, parseMobileHubConfig, Parser, AWSCloudWatchProvider, FacebookOAuth, GoogleOAuth, Linking, AppState, AsyncStorage, Credentials, CredentialsClass, ServiceWorker, StorageHelper, MemoryStorage, UniversalStorage, Platform, getAmplifyUserAgent, INTERNAL_AWS_APPSYNC_PUBSUB_PROVIDER, INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER, USER_AGENT_HEADER, Constants, NonRetryableError, retry, jitteredExponentialRetry, Mutex, Reachability, DateUtils, urlSafeEncode, urlSafeDecode, AWS_CLOUDWATCH_BASE_BUFFER_SIZE, AWS_CLOUDWATCH_CATEGORY, AWS_CLOUDWATCH_MAX_BATCH_EVENT_SIZE, AWS_CLOUDWATCH_MAX_EVENT_SIZE, AWS_CLOUDWATCH_PROVIDER_NAME, NO_CREDS_ERROR_STRING, RETRY_ERROR_CODES, Amplify, default */
35749
+ /*! exports provided: AmplifyClass, ClientDevice, ConsoleLogger, Logger, missingConfig, invalidParameter, Hub, I18n, isEmpty, sortByField, objectLessAttributes, filenameToContentType, isTextFile, generateRandomString, makeQuerablePromise, isWebWorker, browserOrNode, transferKeyToLowerCase, transferKeyToUpperCase, isStrictObject, JS, Signer, parseMobileHubConfig, Parser, AWSCloudWatchProvider, FacebookOAuth, GoogleOAuth, Linking, AppState, AsyncStorage, Credentials, CredentialsClass, ServiceWorker, StorageHelper, MemoryStorage, UniversalStorage, Platform, getAmplifyUserAgent, INTERNAL_AWS_APPSYNC_PUBSUB_PROVIDER, INTERNAL_AWS_APPSYNC_REALTIME_PUBSUB_PROVIDER, USER_AGENT_HEADER, Constants, NonRetryableError, retry, jitteredExponentialRetry, Mutex, Reachability, DateUtils, urlSafeEncode, urlSafeDecode, AWS_CLOUDWATCH_BASE_BUFFER_SIZE, AWS_CLOUDWATCH_CATEGORY, AWS_CLOUDWATCH_MAX_BATCH_EVENT_SIZE, AWS_CLOUDWATCH_MAX_EVENT_SIZE, AWS_CLOUDWATCH_PROVIDER_NAME, NO_CREDS_ERROR_STRING, RETRY_ERROR_CODES, AMAZON_KINESIS_LOGGING_PROVIDER_NAME, AMAZON_KINESIS_LOGGING_CATEGORY, Amplify, default */
35576
35750
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
35577
35751
 
35578
35752
  "use strict";
@@ -35711,6 +35885,10 @@ __webpack_require__.r(__webpack_exports__);
35711
35885
 
35712
35886
  /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "RETRY_ERROR_CODES", function() { return _Util__WEBPACK_IMPORTED_MODULE_18__["RETRY_ERROR_CODES"]; });
35713
35887
 
35888
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "AMAZON_KINESIS_LOGGING_PROVIDER_NAME", function() { return _Util__WEBPACK_IMPORTED_MODULE_18__["AMAZON_KINESIS_LOGGING_PROVIDER_NAME"]; });
35889
+
35890
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "AMAZON_KINESIS_LOGGING_CATEGORY", function() { return _Util__WEBPACK_IMPORTED_MODULE_18__["AMAZON_KINESIS_LOGGING_CATEGORY"]; });
35891
+
35714
35892
  /*
35715
35893
  * Copyright 2017-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
35716
35894
  *