@aws-amplify/ui-react 1.2.26 → 1.2.54-legacy-ui.10

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 (77) hide show
  1. package/CHANGELOG.md +224 -0
  2. package/dist/0.js.map +1 -1
  3. package/dist/1.js +656 -2000
  4. package/dist/1.js.map +1 -1
  5. package/dist/10.js +23 -681
  6. package/dist/10.js.map +1 -1
  7. package/dist/11.js +1157 -20
  8. package/dist/11.js.map +1 -1
  9. package/dist/12.js +61 -1087
  10. package/dist/12.js.map +1 -1
  11. package/dist/13.js +1146 -64
  12. package/dist/13.js.map +1 -1
  13. package/dist/14.js +34 -1163
  14. package/dist/14.js.map +1 -1
  15. package/dist/15.js +17 -37
  16. package/dist/15.js.map +1 -1
  17. package/dist/16.js +109 -13
  18. package/dist/16.js.map +1 -1
  19. package/dist/17.js +32 -67
  20. package/dist/17.js.map +1 -1
  21. package/dist/18.js +236 -46
  22. package/dist/18.js.map +1 -1
  23. package/dist/19.js +35 -224
  24. package/dist/19.js.map +1 -1
  25. package/dist/2.js +2190 -159
  26. package/dist/2.js.map +1 -1
  27. package/dist/20.js +28 -48
  28. package/dist/20.js.map +1 -1
  29. package/dist/21.js +46 -25
  30. package/dist/21.js.map +1 -1
  31. package/dist/22.js +22 -25
  32. package/dist/22.js.map +1 -1
  33. package/dist/23.js +254 -25
  34. package/dist/23.js.map +1 -1
  35. package/dist/24.js +62 -230
  36. package/dist/24.js.map +1 -1
  37. package/dist/25.js +28 -62
  38. package/dist/25.js.map +1 -1
  39. package/dist/26.js +349 -30
  40. package/dist/26.js.map +1 -1
  41. package/dist/27.js +24 -352
  42. package/dist/27.js.map +1 -1
  43. package/dist/28.js +25 -22
  44. package/dist/28.js.map +1 -1
  45. package/dist/29.js +483 -26
  46. package/dist/29.js.map +1 -1
  47. package/dist/3.js +2710 -1818
  48. package/dist/3.js.map +1 -1
  49. package/dist/30.js +1 -502
  50. package/dist/30.js.map +1 -1
  51. package/dist/31.js +1 -1
  52. package/dist/31.js.map +1 -1
  53. package/dist/32.js +12 -1
  54. package/dist/32.js.map +1 -1
  55. package/dist/4.js +361 -3669
  56. package/dist/4.js.map +1 -1
  57. package/dist/5.js +48 -242
  58. package/dist/5.js.map +1 -1
  59. package/dist/6.js +118 -74
  60. package/dist/6.js.map +1 -1
  61. package/dist/7.js +55 -99
  62. package/dist/7.js.map +1 -1
  63. package/dist/8.js +98 -46
  64. package/dist/8.js.map +1 -1
  65. package/dist/9.js +474 -412
  66. package/dist/9.js.map +1 -1
  67. package/dist/@aws-amplify/ui-react.js +50 -44
  68. package/dist/@aws-amplify/ui-react.js.map +1 -1
  69. package/dist/aws-amplify-react.min.js +2 -2
  70. package/dist/aws-amplify-react.min.js.map +1 -1
  71. package/dist/polyfills-core-js.js +5 -11
  72. package/dist/polyfills-core-js.js.map +1 -1
  73. package/dist/polyfills-css-shim.js.map +1 -1
  74. package/dist/polyfills-dom.js.map +1 -1
  75. package/package.json +3 -3
  76. package/dist/33.js +0 -13
  77. package/dist/33.js.map +0 -1
package/dist/3.js CHANGED
@@ -1,21 +1,17 @@
1
1
  (this["webpackJsonpaws_amplify_react"] = this["webpackJsonpaws_amplify_react"] || []).push([[3],{
2
2
 
3
- /***/ "../amplify-ui-components/dist/esm-es5/amplify-confirm-sign-in_7.entry.js":
4
- /*!********************************************************************************!*\
5
- !*** ../amplify-ui-components/dist/esm-es5/amplify-confirm-sign-in_7.entry.js ***!
6
- \********************************************************************************/
7
- /*! exports provided: amplify_confirm_sign_in, amplify_confirm_sign_up, amplify_forgot_password, amplify_require_new_password, amplify_sign_in, amplify_sign_up, amplify_verify_contact */
3
+ /***/ "../amplify-ui-components/dist/esm-es5/amplify-radio-button_3.entry.js":
4
+ /*!*****************************************************************************!*\
5
+ !*** ../amplify-ui-components/dist/esm-es5/amplify-radio-button_3.entry.js ***!
6
+ \*****************************************************************************/
7
+ /*! exports provided: amplify_radio_button, amplify_toast, amplify_totp_setup */
8
8
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
9
9
 
10
10
  "use strict";
11
11
  __webpack_require__.r(__webpack_exports__);
12
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "amplify_confirm_sign_in", function() { return AmplifyConfirmSignIn; });
13
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "amplify_confirm_sign_up", function() { return AmplifyConfirmSignUp; });
14
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "amplify_forgot_password", function() { return AmplifyForgotPassword; });
15
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "amplify_require_new_password", function() { return AmplifyRequireNewPassword; });
16
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "amplify_sign_in", function() { return AmplifySignIn; });
17
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "amplify_sign_up", function() { return AmplifySignUp; });
18
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "amplify_verify_contact", function() { return AmplifyVerifyContact; });
12
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "amplify_radio_button", function() { return AmplifyRadioButton; });
13
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "amplify_toast", function() { return AmplifyToast; });
14
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "amplify_totp_setup", function() { return AmplifyTOTPSetup; });
19
15
  /* harmony import */ var _index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./index-83f2275b.js */ "../amplify-ui-components/dist/esm-es5/index-83f2275b.js");
20
16
  /* harmony import */ var _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @aws-amplify/core */ "@aws-amplify/core");
21
17
  /* harmony import */ var _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__);
@@ -169,19 +165,6 @@ var __generator = undefined && undefined.__generator || function (thisArg, body)
169
165
  }
170
166
  };
171
167
 
172
- var __spreadArrays = undefined && undefined.__spreadArrays || function () {
173
- for (var s = 0, i = 0, il = arguments.length; i < il; i++) {
174
- s += arguments[i].length;
175
- }
176
-
177
- for (var r = Array(s), k = 0, i = 0; i < il; i++) {
178
- for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) {
179
- r[k] = a[j];
180
- }
181
- }
182
-
183
- return r;
184
- };
185
168
 
186
169
 
187
170
 
@@ -190,1793 +173,2923 @@ var __spreadArrays = undefined && undefined.__spreadArrays || function () {
190
173
 
191
174
 
192
175
 
176
+ var amplifyRadioButtonCss = ":host{--font-family:var(--amplify-font-family)}.radio-button{display:block;width:100%;padding:16px;font-size:var(--amplify-text-sm);font-family:var(--font-family)}.radio-button input{margin-right:12px}";
193
177
 
194
-
195
- var AmplifyConfirmSignIn =
178
+ var AmplifyRadioButton =
196
179
  /** @class */
197
180
  function () {
198
- function class_1(hostRef) {
199
- var _this = this;
200
-
181
+ function AmplifyRadioButton(hostRef) {
201
182
  Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["r"])(this, hostRef);
202
- /** Fires when confirm sign in form is submitted */
183
+ /** (Optional) The placeholder for the input element. Using hints is recommended, but placeholders can also be useful to convey information to users. */
203
184
 
204
- this.handleSubmit = function (event) {
205
- return _this.confirm(event);
206
- };
207
- /** Used for header text in confirm sign in component */
185
+ this.placeholder = '';
186
+ /** If `true`, the radio button is selected. */
208
187
 
188
+ this.checked = false;
189
+ /** If `true`, the checkbox is disabled */
209
190
 
210
- this.headerText = _Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].CONFIRM_SMS_CODE;
211
- /** Used for the submit button text in confirm sign in component */
191
+ this.disabled = false;
192
+ }
212
193
 
213
- this.submitButtonText = _Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].CONFIRM;
214
- /** Auth state change handler for this component */
194
+ AmplifyRadioButton.prototype.componentWillLoad = function () {
195
+ console.warn('Version `1.x` of Amplify UI has been deprecated and will be removed in a future major version of `aws-amplify`. Please visit https://ui.docs.amplify.aws/ for the current version of Amplify UI.');
196
+ };
215
197
 
216
- this.handleAuthStateChange = _helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["d"];
217
- /** Default form field */
198
+ AmplifyRadioButton.prototype.render = function () {
199
+ return Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("span", {
200
+ "class": "radio-button"
201
+ }, Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("input", Object.assign({
202
+ type: "radio",
203
+ name: this.name,
204
+ value: this.value,
205
+ onInput: this.handleInputChange,
206
+ placeholder: this.placeholder,
207
+ id: this.fieldId,
208
+ checked: this.checked,
209
+ disabled: this.disabled
210
+ }, this.inputProps)), Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-label", {
211
+ htmlFor: this.fieldId
212
+ }, this.label));
213
+ };
218
214
 
219
- this.defaultFormFields = [{
220
- type: 'code',
221
- required: true,
222
- handleInputChange: function handleInputChange(event) {
223
- return _this.handleCodeChange(event);
224
- }
225
- }];
226
- /**
227
- * Form fields allows you to utilize our pre-built components such as username field, code field, password field, email field, etc.
228
- * by passing an array of strings that you would like the order of the form to be in. If you need more customization, such as changing
229
- * text for a label or adjust a placeholder, you can follow the structure below in order to do just that.
230
- * ```
231
- * [
232
- * {
233
- * type: string,
234
- * label: string,
235
- * placeholder: string,
236
- * hint: string | Functional Component | null,
237
- * required: boolean
238
- * }
239
- * ]
240
- * ```
241
- */
215
+ return AmplifyRadioButton;
216
+ }();
242
217
 
243
- this.formFields = this.defaultFormFields;
244
- /** The MFA option to confirm with */
218
+ AmplifyRadioButton.style = amplifyRadioButtonCss;
219
+ var amplifyToastCss = ":host{--background-color:var(--amplify-secondary-tint);--color:var(--amplify-white);--font-size:var(--amplify-text-sm);--font-family:var(--amplify-font-family);--close-icon-color:var(--amplify-white);--close-icon-hover:var(--amplify-red)}.toast-icon{padding-right:5px}.toast{display:-ms-flexbox;display:flex;-ms-flex-pack:justify;justify-content:space-between;position:absolute;top:0;left:0;width:100%;z-index:99;-webkit-box-shadow:0 0 5px 0 rgba(0, 0, 0, 0.3);box-shadow:0 0 5px 0 rgba(0, 0, 0, 0.3);padding:16px;background-color:var(--background-color);font-size:var(--font-size);color:var(--color);-webkit-box-sizing:border-box;box-sizing:border-box;border-radius:5px;font-family:var(--font-family)}.toast>span{margin-right:10px}.toast-close{margin-left:auto;-ms-flex-item-align:center;align-self:center;position:relative;width:18px;height:18px;overflow:hidden;cursor:pointer;background:transparent;border:none}.toast-close::before,.toast-close::after{content:\"\";position:absolute;height:2px;width:100%;top:50%;left:0;margin-top:-1px;background:var(--close-icon-color)}.toast-close:hover::before,.toast-close:hover::after{background:var(--close-icon-hover)}.toast-close::before{-webkit-transform:rotate(45deg);-moz-transform:rotate(45deg);-ms-transform:rotate(45deg);-o-transform:rotate(45deg);transform:rotate(45deg)}.toast-close::after{-webkit-transform:rotate(-45deg);-moz-transform:rotate(-45deg);-ms-transform:rotate(-45deg);-o-transform:rotate(-45deg);transform:rotate(-45deg)}";
245
220
 
246
- this.mfaOption = _auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_2__["M"].SMS;
247
- /* Whether or not the confirm-sign-in component is loading */
221
+ var AmplifyToast =
222
+ /** @class */
223
+ function () {
224
+ function AmplifyToast(hostRef) {
225
+ Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["r"])(this, hostRef);
226
+ /** Message to be displayed inside the toast*/
248
227
 
249
- this.loading = false;
228
+ this.message = '';
250
229
  }
230
+ /*
231
+ TODO #170365145: Work on a helper function that will populate and
232
+ update class colors for success / warning / failure messages
233
+ */
251
234
 
252
- class_1.prototype.componentWillLoad = function () {
253
- this.setup();
235
+
236
+ AmplifyToast.prototype.componentWillLoad = function () {
237
+ console.warn('Version `1.x` of Amplify UI has been deprecated and will be removed in a future major version of `aws-amplify`. Please visit https://ui.docs.amplify.aws/ for the current version of Amplify UI.');
254
238
  };
255
239
 
256
- class_1.prototype.userHandler = function () {
257
- this.setup();
240
+ AmplifyToast.prototype.render = function () {
241
+ return Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("div", {
242
+ "class": "toast"
243
+ }, Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-icon", {
244
+ "class": "toast-icon",
245
+ name: "warning"
246
+ }), this.message ? Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("span", null, this.message) : null, Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("slot", null), Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("button", {
247
+ "class": "toast-close",
248
+ onClick: this.handleClose
249
+ }));
258
250
  };
259
251
 
260
- class_1.prototype.setup = function () {
261
- if (this.user && this.user['challengeName'] === _auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_2__["C"].SoftwareTokenMFA) {
262
- this.mfaOption = _auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_2__["M"].TOTP; // If header text is using default use TOTP string
252
+ return AmplifyToast;
253
+ }();
263
254
 
264
- if (this.headerText === _Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].CONFIRM_SMS_CODE) {
265
- this.headerText = _Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].CONFIRM_TOTP_CODE;
266
- }
267
- }
255
+ AmplifyToast.style = amplifyToastCss; // can-promise has a crash in some versions of react native that dont have
256
+ // standard global objects
257
+ // https://github.com/soldair/node-qrcode/issues/157
268
258
 
269
- this.constructedFormFieldOptions = this.constructFormFieldOptions(this.formFields);
270
- };
259
+ var canPromise = function canPromise() {
260
+ return typeof Promise === 'function' && Promise.prototype && Promise.prototype.then;
261
+ };
271
262
 
272
- class_1.prototype.handleCodeChange = function (event) {
273
- this.code = event.target.value;
274
- };
263
+ var toSJISFunction;
264
+ var CODEWORDS_COUNT = [0, 26, 44, 70, 100, 134, 172, 196, 242, 292, 346, 404, 466, 532, 581, 655, 733, 815, 901, 991, 1085, 1156, 1258, 1364, 1474, 1588, 1706, 1828, 1921, 2051, 2185, 2323, 2465, 2611, 2761, 2876, 3034, 3196, 3362, 3532, 3706];
265
+ /**
266
+ * Returns the QR Code size for the specified version
267
+ *
268
+ * @param {Number} version QR Code version
269
+ * @return {Number} size of QR code
270
+ */
271
+
272
+ var getSymbolSize = function getSymbolSize(version) {
273
+ if (!version) throw new Error('"version" cannot be null or undefined');
274
+ if (version < 1 || version > 40) throw new Error('"version" should be in range from 1 to 40');
275
+ return version * 4 + 17;
276
+ };
277
+ /**
278
+ * Returns the total number of codewords used to store data and EC information.
279
+ *
280
+ * @param {Number} version QR Code version
281
+ * @return {Number} Data length in bits
282
+ */
275
283
 
276
- class_1.prototype.confirm = function (event) {
277
- return __awaiter(this, void 0, void 0, function () {
278
- var mfaType, error_1;
279
- return __generator(this, function (_a) {
280
- switch (_a.label) {
281
- case 0:
282
- if (event) {
283
- event.preventDefault();
284
- }
285
284
 
286
- mfaType = this.user['challengeName'] === _auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_2__["C"].SoftwareTokenMFA ? _auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_2__["C"].SoftwareTokenMFA : null;
285
+ var getSymbolTotalCodewords = function getSymbolTotalCodewords(version) {
286
+ return CODEWORDS_COUNT[version];
287
+ };
288
+ /**
289
+ * Encode data with Bose-Chaudhuri-Hocquenghem
290
+ *
291
+ * @param {Number} data Value to encode
292
+ * @return {Number} Encoded value
293
+ */
287
294
 
288
- if (!_aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"] || typeof _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"].confirmSignIn !== 'function') {
289
- throw new Error(_constants_c8ecaa24_js__WEBPACK_IMPORTED_MODULE_5__["N"]);
290
- }
291
295
 
292
- this.loading = true;
293
- _a.label = 1;
296
+ var getBCHDigit = function getBCHDigit(data) {
297
+ var digit = 0;
294
298
 
295
- case 1:
296
- _a.trys.push([1, 4, 5, 6]);
299
+ while (data !== 0) {
300
+ digit++;
301
+ data >>>= 1;
302
+ }
297
303
 
298
- return [4
299
- /*yield*/
300
- , _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"].confirmSignIn(this.user, this.code, mfaType)];
304
+ return digit;
305
+ };
301
306
 
302
- case 2:
303
- _a.sent();
307
+ var setToSJISFunction = function setToSJISFunction(f) {
308
+ if (typeof f !== 'function') {
309
+ throw new Error('"toSJISFunc" is not a valid function.');
310
+ }
304
311
 
305
- return [4
306
- /*yield*/
307
- , Object(_auth_helpers_557b83fc_js__WEBPACK_IMPORTED_MODULE_7__["c"])(this.user, this.handleAuthStateChange)];
312
+ toSJISFunction = f;
313
+ };
308
314
 
309
- case 3:
310
- _a.sent();
315
+ var isKanjiModeEnabled = function isKanjiModeEnabled() {
316
+ return typeof toSJISFunction !== 'undefined';
317
+ };
311
318
 
312
- return [3
313
- /*break*/
314
- , 6];
319
+ var toSJIS = function toSJIS(kanji) {
320
+ return toSJISFunction(kanji);
321
+ };
315
322
 
316
- case 4:
317
- error_1 = _a.sent();
318
- Object(_helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["a"])(error_1);
319
- return [3
320
- /*break*/
321
- , 6];
323
+ var utils = {
324
+ getSymbolSize: getSymbolSize,
325
+ getSymbolTotalCodewords: getSymbolTotalCodewords,
326
+ getBCHDigit: getBCHDigit,
327
+ setToSJISFunction: setToSJISFunction,
328
+ isKanjiModeEnabled: isKanjiModeEnabled,
329
+ toSJIS: toSJIS
330
+ };
322
331
 
323
- case 5:
324
- this.loading = false;
325
- return [7
326
- /*endfinally*/
327
- ];
332
+ function createCommonjsModule(fn, basedir, module) {
333
+ return module = {
334
+ path: basedir,
335
+ exports: {},
336
+ require: function require(path, base) {
337
+ return commonjsRequire();
338
+ }
339
+ }, fn(module, module.exports), module.exports;
340
+ }
328
341
 
329
- case 6:
330
- return [2
331
- /*return*/
332
- ];
333
- }
334
- });
335
- });
342
+ function commonjsRequire() {
343
+ throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
344
+ }
345
+
346
+ var errorCorrectionLevel = createCommonjsModule(function (module, exports) {
347
+ exports.L = {
348
+ bit: 1
349
+ };
350
+ exports.M = {
351
+ bit: 0
352
+ };
353
+ exports.Q = {
354
+ bit: 3
355
+ };
356
+ exports.H = {
357
+ bit: 2
336
358
  };
337
359
 
338
- class_1.prototype.constructFormFieldOptions = function (formFields) {
339
- var _this = this;
360
+ function fromString(string) {
361
+ if (typeof string !== 'string') {
362
+ throw new Error('Param is not a string');
363
+ }
340
364
 
341
- var content = [];
342
- if (formFields === undefined) return undefined;
343
- if (formFields.length <= 0) return this.defaultFormFields;
344
- formFields.forEach(function (formField) {
345
- if (typeof formField === 'string' || formField.type !== 'code') {
346
- // This is either a `string`, and/or a custom field that isn't `code`. Pass this directly.
347
- content.push(formField);
348
- } else {
349
- // This is a code input field. Attach input handler.
350
- content.push(Object.assign({
351
- handleInputChange: function handleInputChange(event) {
352
- return _this.handleCodeChange(event);
353
- }
354
- }, formField));
355
- }
356
- });
357
- return content;
358
- };
365
+ var lcStr = string.toLowerCase();
359
366
 
360
- class_1.prototype.render = function () {
361
- var _this = this;
367
+ switch (lcStr) {
368
+ case 'l':
369
+ case 'low':
370
+ return exports.L;
362
371
 
363
- return Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["H"], null, Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-form-section", {
364
- headerText: _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(this.headerText),
365
- handleSubmit: this.handleSubmit,
366
- submitButtonText: _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(this.submitButtonText),
367
- loading: this.loading,
368
- secondaryFooterContent: Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("span", null, Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-button", {
369
- variant: "anchor",
370
- onClick: function onClick() {
371
- return _this.handleAuthStateChange(_auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_2__["A"].SignIn);
372
- }
373
- }, _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].BACK_TO_SIGN_IN)))
374
- }, Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-auth-fields", {
375
- formFields: this.constructedFormFieldOptions
376
- })));
377
- };
372
+ case 'm':
373
+ case 'medium':
374
+ return exports.M;
378
375
 
379
- Object.defineProperty(class_1, "watchers", {
380
- get: function get() {
381
- return {
382
- "user": ["userHandler"]
383
- };
384
- },
385
- enumerable: false,
386
- configurable: true
387
- });
388
- return class_1;
389
- }();
376
+ case 'q':
377
+ case 'quartile':
378
+ return exports.Q;
390
379
 
391
- var AmplifyConfirmSignUp =
392
- /** @class */
393
- function () {
394
- function class_2(hostRef) {
395
- var _this = this;
380
+ case 'h':
381
+ case 'high':
382
+ return exports.H;
396
383
 
397
- Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["r"])(this, hostRef);
398
- /** Fires when sign up form is submitted */
384
+ default:
385
+ throw new Error('Unknown EC Level: ' + string);
386
+ }
387
+ }
399
388
 
400
- this.handleSubmit = function (event) {
401
- return _this.confirmSignUp(event);
402
- };
403
- /** Used for header text in confirm sign up component */
389
+ exports.isValid = function isValid(level) {
390
+ return level && typeof level.bit !== 'undefined' && level.bit >= 0 && level.bit < 4;
391
+ };
404
392
 
393
+ exports.from = function from(value, defaultValue) {
394
+ if (exports.isValid(value)) {
395
+ return value;
396
+ }
405
397
 
406
- this.headerText = _Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].CONFIRM_SIGN_UP_HEADER_TEXT;
407
- /** Used for the submit button text in confirm sign up component */
398
+ try {
399
+ return fromString(value);
400
+ } catch (e) {
401
+ return defaultValue;
402
+ }
403
+ };
404
+ });
408
405
 
409
- this.submitButtonText = _Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].CONFIRM_SIGN_UP_SUBMIT_BUTTON_TEXT;
410
- /**
411
- * Form fields allows you to utilize our pre-built components such as username field, code field, password field, email field, etc.
412
- * by passing an array of strings that you would like the order of the form to be in. If you need more customization, such as changing
413
- * text for a label or adjust a placeholder, you can follow the structure below in order to do just that.
414
- * ```
415
- * [
416
- * {
417
- * type: string,
418
- * label: string,
419
- * placeholder: string,
420
- * hint: string | Functional Component | null,
421
- * required: boolean
422
- * }
423
- * ]
424
- * ```
425
- */
406
+ function BitBuffer() {
407
+ this.buffer = [];
408
+ this.length = 0;
409
+ }
426
410
 
427
- this.formFields = [];
428
- /** Auth state change handler for this components
429
- * e.g. SignIn -> 'Create Account' link -> SignUp
430
- */
411
+ BitBuffer.prototype = {
412
+ get: function get(index) {
413
+ var bufIndex = Math.floor(index / 8);
414
+ return (this.buffer[bufIndex] >>> 7 - index % 8 & 1) === 1;
415
+ },
416
+ put: function put(num, length) {
417
+ for (var i = 0; i < length; i++) {
418
+ this.putBit((num >>> length - i - 1 & 1) === 1);
419
+ }
420
+ },
421
+ getLengthInBits: function getLengthInBits() {
422
+ return this.length;
423
+ },
424
+ putBit: function putBit(bit) {
425
+ var bufIndex = Math.floor(this.length / 8);
431
426
 
432
- this.handleAuthStateChange = _helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["d"];
433
- /** Username Alias is used to setup authentication with `username`, `email` or `phone_number` */
427
+ if (this.buffer.length <= bufIndex) {
428
+ this.buffer.push(0);
429
+ }
434
430
 
435
- this.usernameAlias = 'username';
436
- this.loading = false;
437
- this.newFormFields = [];
438
- this.phoneNumber = {
439
- countryDialCodeValue: _constants_c8ecaa24_js__WEBPACK_IMPORTED_MODULE_5__["g"],
440
- phoneNumberValue: null
441
- };
431
+ if (bit) {
432
+ this.buffer[bufIndex] |= 0x80 >>> this.length % 8;
433
+ }
434
+
435
+ this.length++;
436
+ }
437
+ };
438
+ var bitBuffer = BitBuffer;
439
+ /**
440
+ * Helper class to handle QR Code symbol modules
441
+ *
442
+ * @param {Number} size Symbol size
443
+ */
444
+
445
+ function BitMatrix(size) {
446
+ if (!size || size < 1) {
447
+ throw new Error('BitMatrix size must be defined and greater than 0');
442
448
  }
443
449
 
444
- class_2.prototype.componentWillLoad = function () {
445
- this.setup();
446
- };
450
+ this.size = size;
451
+ this.data = new Uint8Array(size * size);
452
+ this.reservedBit = new Uint8Array(size * size);
453
+ }
454
+ /**
455
+ * Set bit value at specified location
456
+ * If reserved flag is set, this bit will be ignored during masking process
457
+ *
458
+ * @param {Number} row
459
+ * @param {Number} col
460
+ * @param {Boolean} value
461
+ * @param {Boolean} reserved
462
+ */
463
+
464
+
465
+ BitMatrix.prototype.set = function (row, col, value, reserved) {
466
+ var index = row * this.size + col;
467
+ this.data[index] = value;
468
+ if (reserved) this.reservedBit[index] = true;
469
+ };
470
+ /**
471
+ * Returns bit value at specified location
472
+ *
473
+ * @param {Number} row
474
+ * @param {Number} col
475
+ * @return {Boolean}
476
+ */
447
477
 
448
- class_2.prototype.formFieldsHandler = function () {
449
- this.buildFormFields();
450
- };
451
478
 
452
- class_2.prototype.userHandler = function () {
453
- this.setup();
454
- };
479
+ BitMatrix.prototype.get = function (row, col) {
480
+ return this.data[row * this.size + col];
481
+ };
482
+ /**
483
+ * Applies xor operator at specified location
484
+ * (used during masking process)
485
+ *
486
+ * @param {Number} row
487
+ * @param {Number} col
488
+ * @param {Boolean} value
489
+ */
490
+
491
+
492
+ BitMatrix.prototype.xor = function (row, col, value) {
493
+ this.data[row * this.size + col] ^= value;
494
+ };
495
+ /**
496
+ * Check if bit at specified location is reserved
497
+ *
498
+ * @param {Number} row
499
+ * @param {Number} col
500
+ * @return {Boolean}
501
+ */
455
502
 
456
- class_2.prototype.setup = function () {
457
- // TODO: Use optional chaining instead
458
- this.userInput = this.user && this.user.username;
459
- this._signUpAttrs = this.user && this.user.signUpAttrs;
460
- Object(_helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["c"])(this.usernameAlias);
461
- this.buildFormFields();
462
- };
463
503
 
464
- class_2.prototype.buildDefaultFormFields = function () {
465
- var _this = this;
504
+ BitMatrix.prototype.isReserved = function (row, col) {
505
+ return this.reservedBit[row * this.size + col];
506
+ };
466
507
 
467
- this.newFormFields = [{
468
- type: "" + this.usernameAlias,
469
- required: true,
470
- handleInputChange: this.handleFormFieldInputChange("" + this.usernameAlias),
471
- value: this.userInput,
472
- disabled: this.userInput ? true : false,
473
- inputProps: {
474
- autocomplete: 'username'
475
- }
476
- }, {
477
- type: 'code',
478
- label: _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].CONFIRM_SIGN_UP_CODE_LABEL),
479
- placeholder: _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].CONFIRM_SIGN_UP_CODE_PLACEHOLDER),
480
- required: true,
481
- hint: Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("div", null, _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].CONFIRM_SIGN_UP_LOST_CODE), ' ', Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-button", {
482
- variant: "anchor",
483
- onClick: function onClick() {
484
- return _this.resendConfirmCode();
485
- }
486
- }, _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].CONFIRM_SIGN_UP_RESEND_CODE))),
487
- handleInputChange: this.handleFormFieldInputChange('code')
488
- }];
489
- };
508
+ var bitMatrix = BitMatrix;
509
+ var alignmentPattern = createCommonjsModule(function (module, exports) {
510
+ /**
511
+ * Alignment pattern are fixed reference pattern in defined positions
512
+ * in a matrix symbology, which enables the decode software to re-synchronise
513
+ * the coordinate mapping of the image modules in the event of moderate amounts
514
+ * of distortion of the image.
515
+ *
516
+ * Alignment patterns are present only in QR Code symbols of version 2 or larger
517
+ * and their number depends on the symbol version.
518
+ */
519
+ var getSymbolSize = utils.getSymbolSize;
520
+ /**
521
+ * Calculate the row/column coordinates of the center module of each alignment pattern
522
+ * for the specified QR Code version.
523
+ *
524
+ * The alignment patterns are positioned symmetrically on either side of the diagonal
525
+ * running from the top left corner of the symbol to the bottom right corner.
526
+ *
527
+ * Since positions are simmetrical only half of the coordinates are returned.
528
+ * Each item of the array will represent in turn the x and y coordinate.
529
+ * @see {@link getPositions}
530
+ *
531
+ * @param {Number} version QR Code version
532
+ * @return {Array} Array of coordinate
533
+ */
490
534
 
491
- class_2.prototype.buildFormFields = function () {
492
- var _this = this;
535
+ exports.getRowColCoords = function getRowColCoords(version) {
536
+ if (version === 1) return [];
537
+ var posCount = Math.floor(version / 7) + 2;
538
+ var size = getSymbolSize(version);
539
+ var intervals = size === 145 ? 26 : Math.ceil((size - 13) / (2 * posCount - 2)) * 2;
540
+ var positions = [size - 7]; // Last coord is always (size - 7)
493
541
 
494
- if (this.formFields.length === 0) {
495
- this.buildDefaultFormFields();
496
- } else {
497
- var newFields_1 = [];
498
- this.formFields.forEach(function (field) {
499
- var newField = Object.assign({}, field);
500
-
501
- if (newField.type === 'code') {
502
- newField['hint'] = Object(_helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["i"])(newField) ? Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("div", null, _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].CONFIRM_SIGN_UP_LOST_CODE), ' ', Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-button", {
503
- variant: "anchor",
504
- onClick: function onClick() {
505
- return _this.resendConfirmCode();
506
- }
507
- }, _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].CONFIRM_SIGN_UP_RESEND_CODE))) : newField['hint'];
508
- }
542
+ for (var i = 1; i < posCount - 1; i++) {
543
+ positions[i] = positions[i - 1] - intervals;
544
+ }
509
545
 
510
- newField['handleInputChange'] = function (event) {
511
- return _this.handleFormFieldInputWithCallback(event, field);
512
- };
546
+ positions.push(6); // First coord is always 6
513
547
 
514
- newFields_1.push(newField);
515
- });
516
- this.newFormFields = newFields_1;
517
- }
548
+ return positions.reverse();
518
549
  };
550
+ /**
551
+ * Returns an array containing the positions of each alignment pattern.
552
+ * Each array's element represent the center point of the pattern as (x, y) coordinates
553
+ *
554
+ * Coordinates are calculated expanding the row/column coordinates returned by {@link getRowColCoords}
555
+ * and filtering out the items that overlaps with finder pattern
556
+ *
557
+ * @example
558
+ * For a Version 7 symbol {@link getRowColCoords} returns values 6, 22 and 38.
559
+ * The alignment patterns, therefore, are to be centered on (row, column)
560
+ * positions (6,22), (22,6), (22,22), (22,38), (38,22), (38,38).
561
+ * Note that the coordinates (6,6), (6,38), (38,6) are occupied by finder patterns
562
+ * and are not therefore used for alignment patterns.
563
+ *
564
+ * let pos = getPositions(7)
565
+ * // [[6,22], [22,6], [22,22], [22,38], [38,22], [38,38]]
566
+ *
567
+ * @param {Number} version QR Code version
568
+ * @return {Array} Array of coordinates
569
+ */
519
570
 
520
- class_2.prototype.handleFormFieldInputChange = function (fieldType) {
521
- var _this = this;
522
-
523
- switch (fieldType) {
524
- case 'username':
525
- case 'email':
526
- return function (event) {
527
- return _this.userInput = event.target.value;
528
- };
529
571
 
530
- case 'phone_number':
531
- return function (event) {
532
- return Object(_helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["h"])(event, _this.phoneNumber);
533
- };
572
+ exports.getPositions = function getPositions(version) {
573
+ var coords = [];
574
+ var pos = exports.getRowColCoords(version);
575
+ var posLength = pos.length;
534
576
 
535
- case 'code':
536
- return function (event) {
537
- return _this.code = event.target.value;
538
- };
577
+ for (var i = 0; i < posLength; i++) {
578
+ for (var j = 0; j < posLength; j++) {
579
+ // Skip if position is occupied by finder patterns
580
+ if (i === 0 && j === 0 || // top-left
581
+ i === 0 && j === posLength - 1 || // bottom-left
582
+ i === posLength - 1 && j === 0) {
583
+ // top-right
584
+ continue;
585
+ }
539
586
 
540
- default:
541
- return;
587
+ coords.push([pos[i], pos[j]]);
588
+ }
542
589
  }
590
+
591
+ return coords;
592
+ };
593
+ });
594
+ var getSymbolSize$1 = utils.getSymbolSize;
595
+ var FINDER_PATTERN_SIZE = 7;
596
+ /**
597
+ * Returns an array containing the positions of each finder pattern.
598
+ * Each array's element represent the top-left point of the pattern as (x, y) coordinates
599
+ *
600
+ * @param {Number} version QR Code version
601
+ * @return {Array} Array of coordinates
602
+ */
603
+
604
+ var getPositions = function getPositions(version) {
605
+ var size = getSymbolSize$1(version);
606
+ return [// top-left
607
+ [0, 0], // top-right
608
+ [size - FINDER_PATTERN_SIZE, 0], // bottom-left
609
+ [0, size - FINDER_PATTERN_SIZE]];
610
+ };
611
+
612
+ var finderPattern = {
613
+ getPositions: getPositions
614
+ };
615
+ var maskPattern = createCommonjsModule(function (module, exports) {
616
+ /**
617
+ * Data mask pattern reference
618
+ * @type {Object}
619
+ */
620
+ exports.Patterns = {
621
+ PATTERN000: 0,
622
+ PATTERN001: 1,
623
+ PATTERN010: 2,
624
+ PATTERN011: 3,
625
+ PATTERN100: 4,
626
+ PATTERN101: 5,
627
+ PATTERN110: 6,
628
+ PATTERN111: 7
629
+ };
630
+ /**
631
+ * Weighted penalty scores for the undesirable features
632
+ * @type {Object}
633
+ */
634
+
635
+ var PenaltyScores = {
636
+ N1: 3,
637
+ N2: 3,
638
+ N3: 40,
639
+ N4: 10
640
+ };
641
+ /**
642
+ * Check if mask pattern value is valid
643
+ *
644
+ * @param {Number} mask Mask pattern
645
+ * @return {Boolean} true if valid, false otherwise
646
+ */
647
+
648
+ exports.isValid = function isValid(mask) {
649
+ return mask != null && mask !== '' && !isNaN(mask) && mask >= 0 && mask <= 7;
543
650
  };
651
+ /**
652
+ * Returns mask pattern from a value.
653
+ * If value is not valid, returns undefined
654
+ *
655
+ * @param {Number|String} value Mask pattern value
656
+ * @return {Number} Valid mask pattern or undefined
657
+ */
544
658
 
545
- class_2.prototype.setFieldValue = function (field) {
546
- switch (field.type) {
547
- case 'username':
548
- case 'email':
549
- if (field.value === undefined) {
550
- this.userInput = '';
659
+
660
+ exports.from = function from(value) {
661
+ return exports.isValid(value) ? parseInt(value, 10) : undefined;
662
+ };
663
+ /**
664
+ * Find adjacent modules in row/column with the same color
665
+ * and assign a penalty value.
666
+ *
667
+ * Points: N1 + i
668
+ * i is the amount by which the number of adjacent modules of the same color exceeds 5
669
+ */
670
+
671
+
672
+ exports.getPenaltyN1 = function getPenaltyN1(data) {
673
+ var size = data.size;
674
+ var points = 0;
675
+ var sameCountCol = 0;
676
+ var sameCountRow = 0;
677
+ var lastCol = null;
678
+ var lastRow = null;
679
+
680
+ for (var row = 0; row < size; row++) {
681
+ sameCountCol = sameCountRow = 0;
682
+ lastCol = lastRow = null;
683
+
684
+ for (var col = 0; col < size; col++) {
685
+ var module_1 = data.get(row, col);
686
+
687
+ if (module_1 === lastCol) {
688
+ sameCountCol++;
551
689
  } else {
552
- this.userInput = field.value;
690
+ if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5);
691
+ lastCol = module_1;
692
+ sameCountCol = 1;
553
693
  }
554
694
 
555
- break;
695
+ module_1 = data.get(col, row);
556
696
 
557
- case 'phone_number':
558
- if (field.dialCode) {
559
- this.phoneNumber.countryDialCodeValue = field.dialCode;
697
+ if (module_1 === lastRow) {
698
+ sameCountRow++;
699
+ } else {
700
+ if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5);
701
+ lastRow = module_1;
702
+ sameCountRow = 1;
560
703
  }
704
+ }
561
705
 
562
- this.phoneNumber.phoneNumberValue = field.value;
563
- break;
706
+ if (sameCountCol >= 5) points += PenaltyScores.N1 + (sameCountCol - 5);
707
+ if (sameCountRow >= 5) points += PenaltyScores.N1 + (sameCountRow - 5);
564
708
  }
709
+
710
+ return points;
565
711
  };
712
+ /**
713
+ * Find 2x2 blocks with the same color and assign a penalty value
714
+ *
715
+ * Points: N2 * (m - 1) * (n - 1)
716
+ */
566
717
 
567
- class_2.prototype.handleFormFieldInputWithCallback = function (event, field) {
568
- var fnToCall = field['handleInputChange'] ? field['handleInputChange'] : function (event, cb) {
569
- cb(event);
570
- };
571
- var callback = this.handleFormFieldInputChange(field.type);
572
- fnToCall(event, callback.bind(this));
718
+
719
+ exports.getPenaltyN2 = function getPenaltyN2(data) {
720
+ var size = data.size;
721
+ var points = 0;
722
+
723
+ for (var row = 0; row < size - 1; row++) {
724
+ for (var col = 0; col < size - 1; col++) {
725
+ var last = data.get(row, col) + data.get(row, col + 1) + data.get(row + 1, col) + data.get(row + 1, col + 1);
726
+ if (last === 4 || last === 0) points++;
727
+ }
728
+ }
729
+
730
+ return points * PenaltyScores.N2;
573
731
  };
574
732
  /**
575
- * Returns the username of the user to confirm. If a valid `user.username` has been passed as a prop, we return that.
576
- * Otherwise, we return the `userInput` on the form.
733
+ * Find 1:1:3:1:1 ratio (dark:light:dark:light:dark) pattern in row/column,
734
+ * preceded or followed by light area 4 modules wide
735
+ *
736
+ * Points: N3 * number of pattern found
577
737
  */
578
738
 
579
739
 
580
- class_2.prototype.getUsername = function () {
581
- if (this.user && this.user.username) return this.user.username;
740
+ exports.getPenaltyN3 = function getPenaltyN3(data) {
741
+ var size = data.size;
742
+ var points = 0;
743
+ var bitsCol = 0;
744
+ var bitsRow = 0;
582
745
 
583
- switch (this.usernameAlias) {
584
- case 'username':
585
- case 'email':
586
- return this.userInput;
746
+ for (var row = 0; row < size; row++) {
747
+ bitsCol = bitsRow = 0;
587
748
 
588
- case 'phone_number':
589
- return Object(_helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["b"])(this.phoneNumber);
749
+ for (var col = 0; col < size; col++) {
750
+ bitsCol = bitsCol << 1 & 0x7FF | data.get(row, col);
751
+ if (col >= 10 && (bitsCol === 0x5D0 || bitsCol === 0x05D)) points++;
752
+ bitsRow = bitsRow << 1 & 0x7FF | data.get(col, row);
753
+ if (col >= 10 && (bitsRow === 0x5D0 || bitsRow === 0x05D)) points++;
754
+ }
590
755
  }
756
+
757
+ return points * PenaltyScores.N3;
591
758
  };
759
+ /**
760
+ * Calculate proportion of dark modules in entire symbol
761
+ *
762
+ * Points: N4 * k
763
+ *
764
+ * k is the rating of the deviation of the proportion of dark modules
765
+ * in the symbol from 50% in steps of 5%
766
+ */
592
767
 
593
- class_2.prototype.resendConfirmCode = function () {
594
- return __awaiter(this, void 0, void 0, function () {
595
- var username, error_2;
596
- return __generator(this, function (_a) {
597
- switch (_a.label) {
598
- case 0:
599
- if (event) {
600
- event.preventDefault();
601
- }
602
768
 
603
- if (!_aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"] || typeof _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"].resendSignUp !== 'function') {
604
- throw new Error(_constants_c8ecaa24_js__WEBPACK_IMPORTED_MODULE_5__["N"]);
605
- }
769
+ exports.getPenaltyN4 = function getPenaltyN4(data) {
770
+ var darkCount = 0;
771
+ var modulesCount = data.data.length;
606
772
 
607
- _a.label = 1;
773
+ for (var i = 0; i < modulesCount; i++) {
774
+ darkCount += data.data[i];
775
+ }
608
776
 
609
- case 1:
610
- _a.trys.push([1, 3,, 4]);
777
+ var k = Math.abs(Math.ceil(darkCount * 100 / modulesCount / 5) - 10);
778
+ return k * PenaltyScores.N4;
779
+ };
780
+ /**
781
+ * Return mask value at given position
782
+ *
783
+ * @param {Number} maskPattern Pattern reference value
784
+ * @param {Number} i Row
785
+ * @param {Number} j Column
786
+ * @return {Boolean} Mask value
787
+ */
611
788
 
612
- username = this.getUsername();
613
- if (!username) throw new Error(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].EMPTY_USERNAME);
614
- return [4
615
- /*yield*/
616
- , _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"].resendSignUp(username.trim())];
617
789
 
618
- case 2:
619
- _a.sent();
790
+ function getMaskAt(maskPattern, i, j) {
791
+ switch (maskPattern) {
792
+ case exports.Patterns.PATTERN000:
793
+ return (i + j) % 2 === 0;
620
794
 
621
- return [3
622
- /*break*/
623
- , 4];
795
+ case exports.Patterns.PATTERN001:
796
+ return i % 2 === 0;
624
797
 
625
- case 3:
626
- error_2 = _a.sent();
627
- Object(_helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["a"])(error_2);
628
- return [3
629
- /*break*/
630
- , 4];
798
+ case exports.Patterns.PATTERN010:
799
+ return j % 3 === 0;
631
800
 
632
- case 4:
633
- return [2
634
- /*return*/
635
- ];
636
- }
637
- });
638
- });
639
- }; // TODO: Add validation
640
- // TODO: Prefix
801
+ case exports.Patterns.PATTERN011:
802
+ return (i + j) % 3 === 0;
641
803
 
804
+ case exports.Patterns.PATTERN100:
805
+ return (Math.floor(i / 2) + Math.floor(j / 3)) % 2 === 0;
642
806
 
643
- class_2.prototype.confirmSignUp = function (event) {
644
- return __awaiter(this, void 0, void 0, function () {
645
- var username, confirmSignUpResult, error_3;
646
- return __generator(this, function (_a) {
647
- switch (_a.label) {
648
- case 0:
649
- if (event) {
650
- event.preventDefault();
651
- }
807
+ case exports.Patterns.PATTERN101:
808
+ return i * j % 2 + i * j % 3 === 0;
652
809
 
653
- if (!_aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"] || typeof _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"].confirmSignUp !== 'function') {
654
- throw new Error(_constants_c8ecaa24_js__WEBPACK_IMPORTED_MODULE_5__["N"]);
655
- }
810
+ case exports.Patterns.PATTERN110:
811
+ return (i * j % 2 + i * j % 3) % 2 === 0;
656
812
 
657
- this.loading = true;
658
- _a.label = 1;
813
+ case exports.Patterns.PATTERN111:
814
+ return (i * j % 3 + (i + j) % 2) % 2 === 0;
659
815
 
660
- case 1:
661
- _a.trys.push([1, 6, 7, 8]);
816
+ default:
817
+ throw new Error('bad maskPattern:' + maskPattern);
818
+ }
819
+ }
820
+ /**
821
+ * Apply a mask pattern to a BitMatrix
822
+ *
823
+ * @param {Number} pattern Pattern reference number
824
+ * @param {BitMatrix} data BitMatrix data
825
+ */
662
826
 
663
- username = this.getUsername();
664
- if (!username) throw new Error(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].EMPTY_USERNAME);
665
- username = username.trim();
666
- return [4
667
- /*yield*/
668
- , _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"].confirmSignUp(username, this.code)];
669
827
 
670
- case 2:
671
- confirmSignUpResult = _a.sent();
828
+ exports.applyMask = function applyMask(pattern, data) {
829
+ var size = data.size;
672
830
 
673
- if (!confirmSignUpResult) {
674
- throw new Error(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].CONFIRM_SIGN_UP_FAILED));
675
- }
831
+ for (var col = 0; col < size; col++) {
832
+ for (var row = 0; row < size; row++) {
833
+ if (data.isReserved(row, col)) continue;
834
+ data.xor(row, col, getMaskAt(pattern, row, col));
835
+ }
836
+ }
837
+ };
838
+ /**
839
+ * Returns the best mask pattern for data
840
+ *
841
+ * @param {BitMatrix} data
842
+ * @return {Number} Mask pattern reference number
843
+ */
676
844
 
677
- if (!(this._signUpAttrs && this._signUpAttrs.password && this._signUpAttrs.password !== '')) return [3
678
- /*break*/
679
- , 4]; // Auto sign in user if password is available from previous workflow
680
845
 
681
- return [4
682
- /*yield*/
683
- , Object(_auth_helpers_557b83fc_js__WEBPACK_IMPORTED_MODULE_7__["h"])(username, this._signUpAttrs.password, this.handleAuthStateChange)];
846
+ exports.getBestMask = function getBestMask(data, setupFormatFunc) {
847
+ var numPatterns = Object.keys(exports.Patterns).length;
848
+ var bestPattern = 0;
849
+ var lowerPenalty = Infinity;
684
850
 
685
- case 3:
686
- // Auto sign in user if password is available from previous workflow
687
- _a.sent();
851
+ for (var p = 0; p < numPatterns; p++) {
852
+ setupFormatFunc(p);
853
+ exports.applyMask(p, data); // Calculate penalty
688
854
 
689
- return [3
690
- /*break*/
691
- , 5];
855
+ var penalty = exports.getPenaltyN1(data) + exports.getPenaltyN2(data) + exports.getPenaltyN3(data) + exports.getPenaltyN4(data); // Undo previously applied mask
692
856
 
693
- case 4:
694
- this.handleAuthStateChange(_auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_2__["A"].SignIn);
695
- _a.label = 5;
857
+ exports.applyMask(p, data);
696
858
 
697
- case 5:
698
- return [3
699
- /*break*/
700
- , 8];
859
+ if (penalty < lowerPenalty) {
860
+ lowerPenalty = penalty;
861
+ bestPattern = p;
862
+ }
863
+ }
701
864
 
702
- case 6:
703
- error_3 = _a.sent();
704
- Object(_helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["a"])(error_3);
705
- return [3
706
- /*break*/
707
- , 8];
865
+ return bestPattern;
866
+ };
867
+ });
868
+ var EC_BLOCKS_TABLE = [// L M Q H
869
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 2, 2, 4, 1, 2, 4, 4, 2, 4, 4, 4, 2, 4, 6, 5, 2, 4, 6, 6, 2, 5, 8, 8, 4, 5, 8, 8, 4, 5, 8, 11, 4, 8, 10, 11, 4, 9, 12, 16, 4, 9, 16, 16, 6, 10, 12, 18, 6, 10, 17, 16, 6, 11, 16, 19, 6, 13, 18, 21, 7, 14, 21, 25, 8, 16, 20, 25, 8, 17, 23, 25, 9, 17, 23, 34, 9, 18, 25, 30, 10, 20, 27, 32, 12, 21, 29, 35, 12, 23, 34, 37, 12, 25, 34, 40, 13, 26, 35, 42, 14, 28, 38, 45, 15, 29, 40, 48, 16, 31, 43, 51, 17, 33, 45, 54, 18, 35, 48, 57, 19, 37, 51, 60, 19, 38, 53, 63, 20, 40, 56, 66, 21, 43, 59, 70, 22, 45, 62, 74, 24, 47, 65, 77, 25, 49, 68, 81];
870
+ var EC_CODEWORDS_TABLE = [// L M Q H
871
+ 7, 10, 13, 17, 10, 16, 22, 28, 15, 26, 36, 44, 20, 36, 52, 64, 26, 48, 72, 88, 36, 64, 96, 112, 40, 72, 108, 130, 48, 88, 132, 156, 60, 110, 160, 192, 72, 130, 192, 224, 80, 150, 224, 264, 96, 176, 260, 308, 104, 198, 288, 352, 120, 216, 320, 384, 132, 240, 360, 432, 144, 280, 408, 480, 168, 308, 448, 532, 180, 338, 504, 588, 196, 364, 546, 650, 224, 416, 600, 700, 224, 442, 644, 750, 252, 476, 690, 816, 270, 504, 750, 900, 300, 560, 810, 960, 312, 588, 870, 1050, 336, 644, 952, 1110, 360, 700, 1020, 1200, 390, 728, 1050, 1260, 420, 784, 1140, 1350, 450, 812, 1200, 1440, 480, 868, 1290, 1530, 510, 924, 1350, 1620, 540, 980, 1440, 1710, 570, 1036, 1530, 1800, 570, 1064, 1590, 1890, 600, 1120, 1680, 1980, 630, 1204, 1770, 2100, 660, 1260, 1860, 2220, 720, 1316, 1950, 2310, 750, 1372, 2040, 2430];
872
+ /**
873
+ * Returns the number of error correction block that the QR Code should contain
874
+ * for the specified version and error correction level.
875
+ *
876
+ * @param {Number} version QR Code version
877
+ * @param {Number} errorCorrectionLevel Error correction level
878
+ * @return {Number} Number of error correction blocks
879
+ */
880
+
881
+ var getBlocksCount = function getBlocksCount(version, errorCorrectionLevel$1) {
882
+ switch (errorCorrectionLevel$1) {
883
+ case errorCorrectionLevel.L:
884
+ return EC_BLOCKS_TABLE[(version - 1) * 4 + 0];
885
+
886
+ case errorCorrectionLevel.M:
887
+ return EC_BLOCKS_TABLE[(version - 1) * 4 + 1];
888
+
889
+ case errorCorrectionLevel.Q:
890
+ return EC_BLOCKS_TABLE[(version - 1) * 4 + 2];
891
+
892
+ case errorCorrectionLevel.H:
893
+ return EC_BLOCKS_TABLE[(version - 1) * 4 + 3];
894
+
895
+ default:
896
+ return undefined;
897
+ }
898
+ };
899
+ /**
900
+ * Returns the number of error correction codewords to use for the specified
901
+ * version and error correction level.
902
+ *
903
+ * @param {Number} version QR Code version
904
+ * @param {Number} errorCorrectionLevel Error correction level
905
+ * @return {Number} Number of error correction codewords
906
+ */
708
907
 
709
- case 7:
710
- this.loading = false;
711
- return [7
712
- /*endfinally*/
713
- ];
714
908
 
715
- case 8:
716
- return [2
717
- /*return*/
718
- ];
719
- }
720
- });
721
- });
722
- };
909
+ var getTotalCodewordsCount = function getTotalCodewordsCount(version, errorCorrectionLevel$1) {
910
+ switch (errorCorrectionLevel$1) {
911
+ case errorCorrectionLevel.L:
912
+ return EC_CODEWORDS_TABLE[(version - 1) * 4 + 0];
723
913
 
724
- class_2.prototype.render = function () {
725
- var _this = this;
914
+ case errorCorrectionLevel.M:
915
+ return EC_CODEWORDS_TABLE[(version - 1) * 4 + 1];
726
916
 
727
- return Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["H"], null, Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-form-section", {
728
- headerText: _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(this.headerText),
729
- submitButtonText: _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(this.submitButtonText),
730
- handleSubmit: this.handleSubmit,
731
- loading: this.loading,
732
- secondaryFooterContent: Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("div", null, Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("span", null, Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-button", {
733
- variant: "anchor",
734
- onClick: function onClick() {
735
- return _this.handleAuthStateChange(_auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_2__["A"].SignIn);
736
- }
737
- }, _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].BACK_TO_SIGN_IN))))
738
- }, Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-auth-fields", {
739
- formFields: this.newFormFields
740
- })));
741
- };
917
+ case errorCorrectionLevel.Q:
918
+ return EC_CODEWORDS_TABLE[(version - 1) * 4 + 2];
742
919
 
743
- Object.defineProperty(class_2, "watchers", {
744
- get: function get() {
745
- return {
746
- "formFields": ["formFieldsHandler"],
747
- "user": ["userHandler"]
748
- };
749
- },
750
- enumerable: false,
751
- configurable: true
752
- });
753
- return class_2;
754
- }();
920
+ case errorCorrectionLevel.H:
921
+ return EC_CODEWORDS_TABLE[(version - 1) * 4 + 3];
922
+
923
+ default:
924
+ return undefined;
925
+ }
926
+ };
755
927
 
756
- var logger = new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["Logger"]('ForgotPassword');
928
+ var errorCorrectionCode = {
929
+ getBlocksCount: getBlocksCount,
930
+ getTotalCodewordsCount: getTotalCodewordsCount
931
+ };
932
+ var EXP_TABLE = new Uint8Array(512);
933
+ var LOG_TABLE = new Uint8Array(256);
934
+
935
+ (function initTables() {
936
+ var x = 1;
937
+
938
+ for (var i = 0; i < 255; i++) {
939
+ EXP_TABLE[i] = x;
940
+ LOG_TABLE[x] = i;
941
+ x <<= 1; // multiply by 2
942
+ // The QR code specification says to use byte-wise modulo 100011101 arithmetic.
943
+ // This means that when a number is 256 or larger, it should be XORed with 0x11D.
944
+
945
+ if (x & 0x100) {
946
+ // similar to x >= 256, but a lot faster (because 0x100 == 256)
947
+ x ^= 0x11D;
948
+ }
949
+ } // Optimization: double the size of the anti-log table so that we don't need to mod 255 to
950
+ // stay inside the bounds (because we will mainly use this table for the multiplication of
951
+ // two GF numbers, no more).
952
+ // @see {@link mul}
757
953
 
758
- var AmplifyForgotPassword =
759
- /** @class */
760
- function () {
761
- function class_3(hostRef) {
762
- var _this = this;
763
954
 
764
- Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["r"])(this, hostRef);
765
- /** The header text of the forgot password section */
955
+ for (var i = 255; i < 512; i++) {
956
+ EXP_TABLE[i] = EXP_TABLE[i - 255];
957
+ }
958
+ })();
959
+ /**
960
+ * Returns log value of n inside Galois Field
961
+ *
962
+ * @param {Number} n
963
+ * @return {Number}
964
+ */
965
+
966
+
967
+ var log = function log(n) {
968
+ if (n < 1) throw new Error('log(' + n + ')');
969
+ return LOG_TABLE[n];
970
+ };
971
+ /**
972
+ * Returns anti-log value of n inside Galois Field
973
+ *
974
+ * @param {Number} n
975
+ * @return {Number}
976
+ */
766
977
 
767
- this.headerText = _Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].RESET_YOUR_PASSWORD;
768
- /** The text displayed inside of the send code button for the form */
769
978
 
770
- this.sendButtonText = _Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].SEND_CODE;
771
- /** The text displayed inside of the submit button for the form */
979
+ var exp = function exp(n) {
980
+ return EXP_TABLE[n];
981
+ };
982
+ /**
983
+ * Multiplies two number inside Galois Field
984
+ *
985
+ * @param {Number} x
986
+ * @param {Number} y
987
+ * @return {Number}
988
+ */
772
989
 
773
- this.submitButtonText = _Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].SUBMIT;
774
- /** The form fields displayed inside of the forgot password form */
775
990
 
776
- this.formFields = [];
777
- /** The function called when making a request to reset password */
991
+ var mul = function mul(x, y) {
992
+ if (x === 0 || y === 0) return 0; // should be EXP_TABLE[(LOG_TABLE[x] + LOG_TABLE[y]) % 255] if EXP_TABLE wasn't oversized
993
+ // @see {@link initTables}
778
994
 
779
- this.handleSend = function (event) {
780
- return _this.send(event);
781
- };
782
- /** The function called when submitting a new password */
995
+ return EXP_TABLE[LOG_TABLE[x] + LOG_TABLE[y]];
996
+ };
783
997
 
998
+ var galoisField = {
999
+ log: log,
1000
+ exp: exp,
1001
+ mul: mul
1002
+ };
1003
+ var polynomial = createCommonjsModule(function (module, exports) {
1004
+ /**
1005
+ * Multiplies two polynomials inside Galois Field
1006
+ *
1007
+ * @param {Uint8Array} p1 Polynomial
1008
+ * @param {Uint8Array} p2 Polynomial
1009
+ * @return {Uint8Array} Product of p1 and p2
1010
+ */
1011
+ exports.mul = function mul(p1, p2) {
1012
+ var coeff = new Uint8Array(p1.length + p2.length - 1);
784
1013
 
785
- this.handleSubmit = function (event) {
786
- return _this.submit(event);
787
- };
788
- /** Auth state change handler for this component */
1014
+ for (var i = 0; i < p1.length; i++) {
1015
+ for (var j = 0; j < p2.length; j++) {
1016
+ coeff[i + j] ^= galoisField.mul(p1[i], p2[j]);
1017
+ }
1018
+ }
789
1019
 
1020
+ return coeff;
1021
+ };
1022
+ /**
1023
+ * Calculate the remainder of polynomials division
1024
+ *
1025
+ * @param {Uint8Array} divident Polynomial
1026
+ * @param {Uint8Array} divisor Polynomial
1027
+ * @return {Uint8Array} Remainder
1028
+ */
790
1029
 
791
- this.handleAuthStateChange = _helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["d"];
792
- /** Username Alias is used to setup authentication with `username`, `email` or `phone_number` */
793
1030
 
794
- this.usernameAlias = 'username';
795
- this.delivery = null;
796
- this.loading = false;
797
- this.phoneNumber = {
798
- countryDialCodeValue: _constants_c8ecaa24_js__WEBPACK_IMPORTED_MODULE_5__["g"],
799
- phoneNumberValue: null
800
- };
801
- this.newFormFields = [];
802
- this.forgotPasswordAttrs = {
803
- userInput: '',
804
- password: '',
805
- code: ''
806
- };
807
- }
1031
+ exports.mod = function mod(divident, divisor) {
1032
+ var result = new Uint8Array(divident);
808
1033
 
809
- class_3.prototype.componentWillLoad = function () {
810
- Object(_helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["c"])(this.usernameAlias);
811
- this.buildFormFields();
812
- };
1034
+ while (result.length - divisor.length >= 0) {
1035
+ var coeff = result[0];
813
1036
 
814
- class_3.prototype.formFieldsHandler = function () {
815
- this.buildFormFields();
816
- };
1037
+ for (var i = 0; i < divisor.length; i++) {
1038
+ result[i] ^= galoisField.mul(divisor[i], coeff);
1039
+ } // remove all zeros from buffer head
817
1040
 
818
- class_3.prototype.buildFormFields = function () {
819
- var _this = this;
820
1041
 
821
- if (this.formFields.length === 0) {
822
- this.buildDefaultFormFields();
823
- } else {
824
- var newFields_2 = [];
825
- this.formFields.forEach(function (field) {
826
- var newField = Object.assign({}, field);
1042
+ var offset = 0;
827
1043
 
828
- newField['handleInputChange'] = function (event) {
829
- return _this.handleFormFieldInputWithCallback(event, field);
830
- };
1044
+ while (offset < result.length && result[offset] === 0) {
1045
+ offset++;
1046
+ }
831
1047
 
832
- newFields_2.push(newField);
833
- });
834
- this.newFormFields = newFields_2;
1048
+ result = result.slice(offset);
835
1049
  }
1050
+
1051
+ return result;
836
1052
  };
1053
+ /**
1054
+ * Generate an irreducible generator polynomial of specified degree
1055
+ * (used by Reed-Solomon encoder)
1056
+ *
1057
+ * @param {Number} degree Degree of the generator polynomial
1058
+ * @return {Uint8Array} Buffer containing polynomial coefficients
1059
+ */
837
1060
 
838
- class_3.prototype.buildDefaultFormFields = function () {
839
- switch (this.usernameAlias) {
840
- case 'email':
841
- this.newFormFields = [{
842
- type: 'email',
843
- required: true,
844
- handleInputChange: this.handleFormFieldInputChange('email'),
845
- inputProps: {
846
- 'data-test': 'forgot-password-email-input'
847
- }
848
- }];
849
- break;
850
1061
 
851
- case 'phone_number':
852
- this.newFormFields = [{
853
- type: 'phone_number',
854
- required: true,
855
- handleInputChange: this.handleFormFieldInputChange('phone_number'),
856
- inputProps: {
857
- 'data-test': 'forgot-password-phone-number-input'
858
- }
859
- }];
860
- break;
1062
+ exports.generateECPolynomial = function generateECPolynomial(degree) {
1063
+ var poly = new Uint8Array([1]);
861
1064
 
862
- case 'username':
863
- default:
864
- this.newFormFields = [{
865
- type: 'username',
866
- required: true,
867
- handleInputChange: this.handleFormFieldInputChange('username'),
868
- inputProps: {
869
- 'data-test': 'forgot-password-username-input'
870
- }
871
- }];
872
- break;
1065
+ for (var i = 0; i < degree; i++) {
1066
+ poly = exports.mul(poly, new Uint8Array([1, galoisField.exp(i)]));
873
1067
  }
1068
+
1069
+ return poly;
874
1070
  };
1071
+ });
875
1072
 
876
- class_3.prototype.handleFormFieldInputChange = function (fieldType) {
877
- var _this = this;
1073
+ function ReedSolomonEncoder(degree) {
1074
+ this.genPoly = undefined;
1075
+ this.degree = degree;
1076
+ if (this.degree) this.initialize(this.degree);
1077
+ }
1078
+ /**
1079
+ * Initialize the encoder.
1080
+ * The input param should correspond to the number of error correction codewords.
1081
+ *
1082
+ * @param {Number} degree
1083
+ */
1084
+
1085
+
1086
+ ReedSolomonEncoder.prototype.initialize = function initialize(degree) {
1087
+ // create an irreducible generator polynomial
1088
+ this.degree = degree;
1089
+ this.genPoly = polynomial.generateECPolynomial(this.degree);
1090
+ };
1091
+ /**
1092
+ * Encodes a chunk of data
1093
+ *
1094
+ * @param {Uint8Array} data Buffer containing input data
1095
+ * @return {Uint8Array} Buffer containing encoded data
1096
+ */
878
1097
 
879
- switch (fieldType) {
880
- case 'username':
881
- case 'email':
882
- return function (event) {
883
- return _this.forgotPasswordAttrs.userInput = event.target.value;
884
- };
885
1098
 
886
- case 'phone_number':
887
- return function (event) {
888
- return Object(_helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["h"])(event, _this.phoneNumber);
889
- };
1099
+ ReedSolomonEncoder.prototype.encode = function encode(data) {
1100
+ if (!this.genPoly) {
1101
+ throw new Error('Encoder not initialized');
1102
+ } // Calculate EC for this data block
1103
+ // extends data size to data+genPoly size
890
1104
 
891
- case 'password':
892
- case 'code':
893
- return function (event) {
894
- return _this.forgotPasswordAttrs[fieldType] = event.target.value;
895
- };
896
1105
 
897
- default:
898
- return;
899
- }
900
- };
1106
+ var paddedData = new Uint8Array(data.length + this.degree);
1107
+ paddedData.set(data); // The error correction codewords are the remainder after dividing the data codewords
1108
+ // by a generator polynomial
901
1109
 
902
- class_3.prototype.setFieldValue = function (field, formAttributes) {
903
- switch (field.type) {
904
- case 'username':
905
- case 'email':
906
- if (field.value === undefined) {
907
- formAttributes.userInput = '';
908
- } else {
909
- formAttributes.userInput = field.value;
910
- }
1110
+ var remainder = polynomial.mod(paddedData, this.genPoly); // return EC data blocks (last n byte, where n is the degree of genPoly)
1111
+ // If coefficients number in remainder are less than genPoly degree,
1112
+ // pad with 0s to the left to reach the needed number of coefficients
911
1113
 
912
- break;
1114
+ var start = this.degree - remainder.length;
913
1115
 
914
- case 'phone_number':
915
- if (field.dialCode) {
916
- this.phoneNumber.countryDialCodeValue = field.dialCode;
917
- }
1116
+ if (start > 0) {
1117
+ var buff = new Uint8Array(this.degree);
1118
+ buff.set(remainder, start);
1119
+ return buff;
1120
+ }
918
1121
 
919
- this.phoneNumber.phoneNumberValue = field.value;
920
- break;
1122
+ return remainder;
1123
+ };
921
1124
 
922
- case 'password':
923
- case 'code':
924
- if (field.value === undefined) {
925
- formAttributes[field.type] = '';
926
- } else {
927
- formAttributes[field.type] = field.value;
928
- }
1125
+ var reedSolomonEncoder = ReedSolomonEncoder;
1126
+ /**
1127
+ * Check if QR Code version is valid
1128
+ *
1129
+ * @param {Number} version QR Code version
1130
+ * @return {Boolean} true if valid version, false otherwise
1131
+ */
929
1132
 
930
- break;
931
- }
1133
+ var isValid = function isValid(version) {
1134
+ return !isNaN(version) && version >= 1 && version <= 40;
1135
+ };
1136
+
1137
+ var versionCheck = {
1138
+ isValid: isValid
1139
+ };
1140
+ var numeric = '[0-9]+';
1141
+ var alphanumeric = '[A-Z $%*+\\-./:]+';
1142
+ var kanji = '(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|' + '[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|' + '[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|' + '[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+';
1143
+ kanji = kanji.replace(/u/g, "\\u");
1144
+
1145
+ var _byte = '(?:(?![A-Z0-9 $%*+\\-./:]|' + kanji + ')(?:.|[\r\n]))+';
1146
+
1147
+ var KANJI = new RegExp(kanji, 'g');
1148
+ var BYTE_KANJI = new RegExp('[^A-Z0-9 $%*+\\-./:]+', 'g');
1149
+ var BYTE = new RegExp(_byte, 'g');
1150
+ var NUMERIC = new RegExp(numeric, 'g');
1151
+ var ALPHANUMERIC = new RegExp(alphanumeric, 'g');
1152
+ var TEST_KANJI = new RegExp('^' + kanji + '$');
1153
+ var TEST_NUMERIC = new RegExp('^' + numeric + '$');
1154
+ var TEST_ALPHANUMERIC = new RegExp('^[A-Z0-9 $%*+\\-./:]+$');
1155
+
1156
+ var testKanji = function testKanji(str) {
1157
+ return TEST_KANJI.test(str);
1158
+ };
1159
+
1160
+ var testNumeric = function testNumeric(str) {
1161
+ return TEST_NUMERIC.test(str);
1162
+ };
1163
+
1164
+ var testAlphanumeric = function testAlphanumeric(str) {
1165
+ return TEST_ALPHANUMERIC.test(str);
1166
+ };
1167
+
1168
+ var regex = {
1169
+ KANJI: KANJI,
1170
+ BYTE_KANJI: BYTE_KANJI,
1171
+ BYTE: BYTE,
1172
+ NUMERIC: NUMERIC,
1173
+ ALPHANUMERIC: ALPHANUMERIC,
1174
+ testKanji: testKanji,
1175
+ testNumeric: testNumeric,
1176
+ testAlphanumeric: testAlphanumeric
1177
+ };
1178
+ var mode = createCommonjsModule(function (module, exports) {
1179
+ /**
1180
+ * Numeric mode encodes data from the decimal digit set (0 - 9)
1181
+ * (byte values 30HEX to 39HEX).
1182
+ * Normally, 3 data characters are represented by 10 bits.
1183
+ *
1184
+ * @type {Object}
1185
+ */
1186
+ exports.NUMERIC = {
1187
+ id: 'Numeric',
1188
+ bit: 1 << 0,
1189
+ ccBits: [10, 12, 14]
932
1190
  };
1191
+ /**
1192
+ * Alphanumeric mode encodes data from a set of 45 characters,
1193
+ * i.e. 10 numeric digits (0 - 9),
1194
+ * 26 alphabetic characters (A - Z),
1195
+ * and 9 symbols (SP, $, %, *, +, -, ., /, :).
1196
+ * Normally, two input characters are represented by 11 bits.
1197
+ *
1198
+ * @type {Object}
1199
+ */
933
1200
 
934
- class_3.prototype.handleFormFieldInputWithCallback = function (event, field) {
935
- var fnToCall = field['handleInputChange'] ? field['handleInputChange'] : function (event, cb) {
936
- cb(event);
937
- };
938
- var callback = this.handleFormFieldInputChange(field.type);
939
- fnToCall(event, callback.bind(this));
1201
+ exports.ALPHANUMERIC = {
1202
+ id: 'Alphanumeric',
1203
+ bit: 1 << 1,
1204
+ ccBits: [9, 11, 13]
940
1205
  };
1206
+ /**
1207
+ * In byte mode, data is encoded at 8 bits per character.
1208
+ *
1209
+ * @type {Object}
1210
+ */
941
1211
 
942
- class_3.prototype.send = function (event) {
943
- return __awaiter(this, void 0, void 0, function () {
944
- var data, error_4;
945
- return __generator(this, function (_a) {
946
- switch (_a.label) {
947
- case 0:
948
- if (event) {
949
- event.preventDefault();
950
- }
1212
+ exports.BYTE = {
1213
+ id: 'Byte',
1214
+ bit: 1 << 2,
1215
+ ccBits: [8, 16, 16]
1216
+ };
1217
+ /**
1218
+ * The Kanji mode efficiently encodes Kanji characters in accordance with
1219
+ * the Shift JIS system based on JIS X 0208.
1220
+ * The Shift JIS values are shifted from the JIS X 0208 values.
1221
+ * JIS X 0208 gives details of the shift coded representation.
1222
+ * Each two-byte character value is compacted to a 13-bit binary codeword.
1223
+ *
1224
+ * @type {Object}
1225
+ */
951
1226
 
952
- if (!_aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"] || typeof _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"].forgotPassword !== 'function') {
953
- throw new Error(_constants_c8ecaa24_js__WEBPACK_IMPORTED_MODULE_5__["N"]);
954
- }
1227
+ exports.KANJI = {
1228
+ id: 'Kanji',
1229
+ bit: 1 << 3,
1230
+ ccBits: [8, 10, 12]
1231
+ };
1232
+ /**
1233
+ * Mixed mode will contain a sequences of data in a combination of any of
1234
+ * the modes described above
1235
+ *
1236
+ * @type {Object}
1237
+ */
955
1238
 
956
- this.loading = true;
1239
+ exports.MIXED = {
1240
+ bit: -1
1241
+ };
1242
+ /**
1243
+ * Returns the number of bits needed to store the data length
1244
+ * according to QR Code specifications.
1245
+ *
1246
+ * @param {Mode} mode Data mode
1247
+ * @param {Number} version QR Code version
1248
+ * @return {Number} Number of bits
1249
+ */
957
1250
 
958
- switch (this.usernameAlias) {
959
- case 'phone_number':
960
- try {
961
- this.forgotPasswordAttrs.userInput = Object(_helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["b"])(this.phoneNumber);
962
- } catch (error) {
963
- Object(_helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["a"])(error);
964
- }
1251
+ exports.getCharCountIndicator = function getCharCountIndicator(mode, version) {
1252
+ if (!mode.ccBits) throw new Error('Invalid mode: ' + mode);
965
1253
 
966
- break;
967
- }
1254
+ if (!versionCheck.isValid(version)) {
1255
+ throw new Error('Invalid version: ' + version);
1256
+ }
968
1257
 
969
- _a.label = 1;
1258
+ if (version >= 1 && version < 10) return mode.ccBits[0];else if (version < 27) return mode.ccBits[1];
1259
+ return mode.ccBits[2];
1260
+ };
1261
+ /**
1262
+ * Returns the most efficient mode to store the specified data
1263
+ *
1264
+ * @param {String} dataStr Input data string
1265
+ * @return {Mode} Best mode
1266
+ */
970
1267
 
971
- case 1:
972
- _a.trys.push([1, 3, 4, 5]);
973
1268
 
974
- return [4
975
- /*yield*/
976
- , _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"].forgotPassword(this.forgotPasswordAttrs.userInput.trim())];
1269
+ exports.getBestModeForData = function getBestModeForData(dataStr) {
1270
+ if (regex.testNumeric(dataStr)) return exports.NUMERIC;else if (regex.testAlphanumeric(dataStr)) return exports.ALPHANUMERIC;else if (regex.testKanji(dataStr)) return exports.KANJI;else return exports.BYTE;
1271
+ };
1272
+ /**
1273
+ * Return mode name as string
1274
+ *
1275
+ * @param {Mode} mode Mode object
1276
+ * @returns {String} Mode name
1277
+ */
977
1278
 
978
- case 2:
979
- data = _a.sent();
980
- logger.debug(data);
981
- this.newFormFields = [{
982
- type: 'code',
983
- required: true,
984
- handleInputChange: this.handleFormFieldInputChange('code'),
985
- inputProps: {
986
- 'data-test': 'forgot-password-code-input'
987
- }
988
- }, {
989
- type: 'password',
990
- required: true,
991
- handleInputChange: this.handleFormFieldInputChange('password'),
992
- label: _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].NEW_PASSWORD_LABEL),
993
- placeholder: _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].NEW_PASSWORD_PLACEHOLDER)
994
- }];
995
- this.delivery = data.CodeDeliveryDetails;
996
- return [3
997
- /*break*/
998
- , 5];
999
1279
 
1000
- case 3:
1001
- error_4 = _a.sent();
1002
- Object(_helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["a"])(error_4);
1003
- return [3
1004
- /*break*/
1005
- , 5];
1280
+ exports.toString = function toString(mode) {
1281
+ if (mode && mode.id) return mode.id;
1282
+ throw new Error('Invalid mode');
1283
+ };
1284
+ /**
1285
+ * Check if input param is a valid mode object
1286
+ *
1287
+ * @param {Mode} mode Mode object
1288
+ * @returns {Boolean} True if valid mode, false otherwise
1289
+ */
1006
1290
 
1007
- case 4:
1008
- this.loading = false;
1009
- return [7
1010
- /*endfinally*/
1011
- ];
1012
1291
 
1013
- case 5:
1014
- return [2
1015
- /*return*/
1016
- ];
1017
- }
1018
- });
1019
- });
1292
+ exports.isValid = function isValid(mode) {
1293
+ return mode && mode.bit && mode.ccBits;
1020
1294
  };
1295
+ /**
1296
+ * Get mode object from its name
1297
+ *
1298
+ * @param {String} string Mode name
1299
+ * @returns {Mode} Mode object
1300
+ */
1021
1301
 
1022
- class_3.prototype.submit = function (event) {
1023
- return __awaiter(this, void 0, void 0, function () {
1024
- var _a, userInput, code, password, data, error_5;
1025
1302
 
1026
- return __generator(this, function (_b) {
1027
- switch (_b.label) {
1028
- case 0:
1029
- if (event) {
1030
- event.preventDefault();
1031
- }
1303
+ function fromString(string) {
1304
+ if (typeof string !== 'string') {
1305
+ throw new Error('Param is not a string');
1306
+ }
1032
1307
 
1033
- if (!_aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"] || typeof _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"].forgotPasswordSubmit !== 'function') {
1034
- throw new Error(_constants_c8ecaa24_js__WEBPACK_IMPORTED_MODULE_5__["N"]);
1035
- }
1308
+ var lcStr = string.toLowerCase();
1036
1309
 
1037
- this.loading = true;
1038
- _b.label = 1;
1310
+ switch (lcStr) {
1311
+ case 'numeric':
1312
+ return exports.NUMERIC;
1039
1313
 
1040
- case 1:
1041
- _b.trys.push([1, 3, 4, 5]);
1314
+ case 'alphanumeric':
1315
+ return exports.ALPHANUMERIC;
1042
1316
 
1043
- _a = this.forgotPasswordAttrs, userInput = _a.userInput, code = _a.code, password = _a.password;
1044
- return [4
1045
- /*yield*/
1046
- , _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"].forgotPasswordSubmit(userInput.trim(), code, password)];
1317
+ case 'kanji':
1318
+ return exports.KANJI;
1047
1319
 
1048
- case 2:
1049
- data = _b.sent();
1050
- logger.debug(data);
1051
- this.handleAuthStateChange(_auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_2__["A"].SignIn);
1052
- this.delivery = null;
1053
- return [3
1054
- /*break*/
1055
- , 5];
1320
+ case 'byte':
1321
+ return exports.BYTE;
1056
1322
 
1057
- case 3:
1058
- error_5 = _b.sent();
1059
- Object(_helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["a"])(error_5);
1060
- return [3
1061
- /*break*/
1062
- , 5];
1323
+ default:
1324
+ throw new Error('Unknown mode: ' + string);
1325
+ }
1326
+ }
1327
+ /**
1328
+ * Returns mode from a value.
1329
+ * If value is not a valid mode, returns defaultValue
1330
+ *
1331
+ * @param {Mode|String} value Encoding mode
1332
+ * @param {Mode} defaultValue Fallback value
1333
+ * @return {Mode} Encoding mode
1334
+ */
1063
1335
 
1064
- case 4:
1065
- this.loading = false;
1066
- return [7
1067
- /*endfinally*/
1068
- ];
1069
1336
 
1070
- case 5:
1071
- return [2
1072
- /*return*/
1073
- ];
1074
- }
1075
- });
1076
- });
1337
+ exports.from = function from(value, defaultValue) {
1338
+ if (exports.isValid(value)) {
1339
+ return value;
1340
+ }
1341
+
1342
+ try {
1343
+ return fromString(value);
1344
+ } catch (e) {
1345
+ return defaultValue;
1346
+ }
1077
1347
  };
1348
+ });
1349
+ var version = createCommonjsModule(function (module, exports) {
1350
+ // Generator polynomial used to encode version information
1351
+ var G18 = 1 << 12 | 1 << 11 | 1 << 10 | 1 << 9 | 1 << 8 | 1 << 5 | 1 << 2 | 1 << 0;
1352
+ var G18_BCH = utils.getBCHDigit(G18);
1078
1353
 
1079
- class_3.prototype.render = function () {
1080
- var _this = this;
1354
+ function getBestVersionForDataLength(mode, length, errorCorrectionLevel) {
1355
+ for (var currentVersion = 1; currentVersion <= 40; currentVersion++) {
1356
+ if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, mode)) {
1357
+ return currentVersion;
1358
+ }
1359
+ }
1081
1360
 
1082
- var submitFn = this.delivery ? function (event) {
1083
- return _this.handleSubmit(event);
1084
- } : function (event) {
1085
- return _this.handleSend(event);
1086
- };
1087
- var submitButtonText = this.delivery ? this.submitButtonText : this.sendButtonText;
1088
- return Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["H"], null, Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-form-section", {
1089
- headerText: _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(this.headerText),
1090
- handleSubmit: submitFn,
1091
- loading: this.loading,
1092
- secondaryFooterContent: Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-button", {
1093
- variant: "anchor",
1094
- onClick: function onClick() {
1095
- return _this.handleAuthStateChange(_auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_2__["A"].SignIn);
1096
- },
1097
- "data-test": "forgot-password-back-to-sign-in-link"
1098
- }, _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].BACK_TO_SIGN_IN)),
1099
- testDataPrefix: 'forgot-password',
1100
- submitButtonText: _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(submitButtonText)
1101
- }, Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-auth-fields", {
1102
- formFields: this.newFormFields
1103
- })));
1104
- };
1361
+ return undefined;
1362
+ }
1105
1363
 
1106
- Object.defineProperty(class_3, "watchers", {
1107
- get: function get() {
1108
- return {
1109
- "formFields": ["formFieldsHandler"]
1110
- };
1111
- },
1112
- enumerable: false,
1113
- configurable: true
1114
- });
1115
- return class_3;
1116
- }();
1364
+ function getReservedBitsCount(mode$1, version) {
1365
+ // Character count indicator + mode indicator bits
1366
+ return mode.getCharCountIndicator(mode$1, version) + 4;
1367
+ }
1117
1368
 
1118
- var logger$1 = new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["ConsoleLogger"]('amplify-require-new-password');
1369
+ function getTotalBitsFromDataArray(segments, version) {
1370
+ var totalBits = 0;
1371
+ segments.forEach(function (data) {
1372
+ var reservedBits = getReservedBitsCount(data.mode, version);
1373
+ totalBits += reservedBits + data.getBitsLength();
1374
+ });
1375
+ return totalBits;
1376
+ }
1119
1377
 
1120
- var AmplifyRequireNewPassword =
1121
- /** @class */
1122
- function () {
1123
- function class_4(hostRef) {
1124
- var _this = this;
1378
+ function getBestVersionForMixedData(segments, errorCorrectionLevel) {
1379
+ for (var currentVersion = 1; currentVersion <= 40; currentVersion++) {
1380
+ var length = getTotalBitsFromDataArray(segments, currentVersion);
1125
1381
 
1126
- Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["r"])(this, hostRef);
1127
- /** The header text of the forgot password section */
1382
+ if (length <= exports.getCapacity(currentVersion, errorCorrectionLevel, mode.MIXED)) {
1383
+ return currentVersion;
1384
+ }
1385
+ }
1128
1386
 
1129
- this.headerText = _Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].CHANGE_PASSWORD;
1130
- /** The text displayed inside of the submit button for the form */
1387
+ return undefined;
1388
+ }
1389
+ /**
1390
+ * Returns version number from a value.
1391
+ * If value is not a valid version, returns defaultValue
1392
+ *
1393
+ * @param {Number|String} value QR Code version
1394
+ * @param {Number} defaultValue Fallback value
1395
+ * @return {Number} QR Code version number
1396
+ */
1131
1397
 
1132
- this.submitButtonText = _Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].CHANGE_PASSWORD_ACTION;
1133
- /** The function called when submitting a new password */
1134
1398
 
1135
- this.handleSubmit = function (event) {
1136
- return _this.completeNewPassword(event);
1137
- };
1138
- /** Auth state change handler for this component */
1399
+ exports.from = function from(value, defaultValue) {
1400
+ if (versionCheck.isValid(value)) {
1401
+ return parseInt(value, 10);
1402
+ }
1139
1403
 
1404
+ return defaultValue;
1405
+ };
1406
+ /**
1407
+ * Returns how much data can be stored with the specified QR code version
1408
+ * and error correction level
1409
+ *
1410
+ * @param {Number} version QR Code version (1-40)
1411
+ * @param {Number} errorCorrectionLevel Error correction level
1412
+ * @param {Mode} mode Data mode
1413
+ * @return {Number} Quantity of storable data
1414
+ */
1140
1415
 
1141
- this.handleAuthStateChange = _helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["d"];
1142
- /** The form fields displayed inside of the forgot password form */
1143
1416
 
1144
- this.formFields = [{
1145
- type: _auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_2__["a"].Password,
1146
- required: true,
1147
- handleInputChange: function handleInputChange(event) {
1148
- return _this.handlePasswordChange(event);
1149
- },
1150
- label: _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].NEW_PASSWORD_LABEL),
1151
- placeholder: _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].NEW_PASSWORD_PLACEHOLDER),
1152
- inputProps: {
1153
- 'data-test': 'require-new-password-password-input'
1154
- }
1155
- }];
1156
- this.loading = false;
1157
- this.requiredAttributes = {};
1158
- this.newFormFields = this.formFields;
1159
- this.phoneNumber = {
1160
- countryDialCodeValue: _constants_c8ecaa24_js__WEBPACK_IMPORTED_MODULE_5__["g"],
1161
- phoneNumberValue: ' '
1162
- };
1163
- }
1417
+ exports.getCapacity = function getCapacity(version, errorCorrectionLevel, mode$1) {
1418
+ if (!versionCheck.isValid(version)) {
1419
+ throw new Error('Invalid QR Code version');
1420
+ } // Use Byte mode as default
1421
+
1422
+
1423
+ if (typeof mode$1 === 'undefined') mode$1 = mode.BYTE; // Total codewords for this QR code version (Data + Error correction)
1424
+
1425
+ var totalCodewords = utils.getSymbolTotalCodewords(version); // Total number of error correction codewords
1426
+
1427
+ var ecTotalCodewords = errorCorrectionCode.getTotalCodewordsCount(version, errorCorrectionLevel); // Total number of data codewords
1428
+
1429
+ var dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8;
1430
+ if (mode$1 === mode.MIXED) return dataTotalCodewordsBits;
1431
+ var usableBits = dataTotalCodewordsBits - getReservedBitsCount(mode$1, version); // Return max number of storable codewords
1432
+
1433
+ switch (mode$1) {
1434
+ case mode.NUMERIC:
1435
+ return Math.floor(usableBits / 10 * 3);
1436
+
1437
+ case mode.ALPHANUMERIC:
1438
+ return Math.floor(usableBits / 11 * 2);
1439
+
1440
+ case mode.KANJI:
1441
+ return Math.floor(usableBits / 13);
1164
1442
 
1165
- class_4.prototype.userHandler = function () {
1166
- this.setCurrentUser();
1443
+ case mode.BYTE:
1444
+ default:
1445
+ return Math.floor(usableBits / 8);
1446
+ }
1167
1447
  };
1448
+ /**
1449
+ * Returns the minimum version needed to contain the amount of data
1450
+ *
1451
+ * @param {Segment} data Segment of data
1452
+ * @param {Number} [errorCorrectionLevel=H] Error correction level
1453
+ * @param {Mode} mode Data mode
1454
+ * @return {Number} QR Code version
1455
+ */
1456
+
1457
+
1458
+ exports.getBestVersionForData = function getBestVersionForData(data, errorCorrectionLevel$1) {
1459
+ var seg;
1460
+ var ecl = errorCorrectionLevel.from(errorCorrectionLevel$1, errorCorrectionLevel.M);
1461
+
1462
+ if (Array.isArray(data)) {
1463
+ if (data.length > 1) {
1464
+ return getBestVersionForMixedData(data, ecl);
1465
+ }
1466
+
1467
+ if (data.length === 0) {
1468
+ return 1;
1469
+ }
1168
1470
 
1169
- class_4.prototype.handleRequiredAttributeInputChange = function (attribute, event) {
1170
- if (attribute === 'phone_number') {
1171
- this.formatPhoneNumber(event);
1471
+ seg = data[0];
1172
1472
  } else {
1173
- this.requiredAttributes[attribute] = event.target.value;
1473
+ seg = data;
1174
1474
  }
1475
+
1476
+ return getBestVersionForDataLength(seg.mode, seg.getLength(), ecl);
1175
1477
  };
1478
+ /**
1479
+ * Returns version information with relative error correction bits
1480
+ *
1481
+ * The version information is included in QR Code symbols of version 7 or larger.
1482
+ * It consists of an 18-bit sequence containing 6 data bits,
1483
+ * with 12 error correction bits calculated using the (18, 6) Golay code.
1484
+ *
1485
+ * @param {Number} version QR Code version
1486
+ * @return {Number} Encoded version info bits
1487
+ */
1176
1488
 
1177
- class_4.prototype.setCurrentUser = function () {
1178
- return __awaiter(this, void 0, void 0, function () {
1179
- var user, error_6, userRequiredAttributes, requiredAttributesMap_1;
1180
1489
 
1181
- var _this = this;
1490
+ exports.getEncodedBits = function getEncodedBits(version) {
1491
+ if (!versionCheck.isValid(version) || version < 7) {
1492
+ throw new Error('Invalid QR Code version');
1493
+ }
1182
1494
 
1183
- return __generator(this, function (_a) {
1184
- switch (_a.label) {
1185
- case 0:
1186
- if (!!this.user) return [3
1187
- /*break*/
1188
- , 5];
1189
- _a.label = 1;
1495
+ var d = version << 12;
1190
1496
 
1191
- case 1:
1192
- _a.trys.push([1, 3,, 4]);
1497
+ while (utils.getBCHDigit(d) - G18_BCH >= 0) {
1498
+ d ^= G18 << utils.getBCHDigit(d) - G18_BCH;
1499
+ }
1193
1500
 
1194
- return [4
1195
- /*yield*/
1196
- , _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"].currentAuthenticatedUser()];
1501
+ return version << 12 | d;
1502
+ };
1503
+ });
1504
+ var G15 = 1 << 10 | 1 << 8 | 1 << 5 | 1 << 4 | 1 << 2 | 1 << 1 | 1 << 0;
1505
+ var G15_MASK = 1 << 14 | 1 << 12 | 1 << 10 | 1 << 4 | 1 << 1;
1506
+ var G15_BCH = utils.getBCHDigit(G15);
1507
+ /**
1508
+ * Returns format information with relative error correction bits
1509
+ *
1510
+ * The format information is a 15-bit sequence containing 5 data bits,
1511
+ * with 10 error correction bits calculated using the (15, 5) BCH code.
1512
+ *
1513
+ * @param {Number} errorCorrectionLevel Error correction level
1514
+ * @param {Number} mask Mask pattern
1515
+ * @return {Number} Encoded format information bits
1516
+ */
1517
+
1518
+ var getEncodedBits = function getEncodedBits(errorCorrectionLevel, mask) {
1519
+ var data = errorCorrectionLevel.bit << 3 | mask;
1520
+ var d = data << 10;
1521
+
1522
+ while (utils.getBCHDigit(d) - G15_BCH >= 0) {
1523
+ d ^= G15 << utils.getBCHDigit(d) - G15_BCH;
1524
+ } // xor final data with mask pattern in order to ensure that
1525
+ // no combination of Error Correction Level and data mask pattern
1526
+ // will result in an all-zero data string
1527
+
1528
+
1529
+ return (data << 10 | d) ^ G15_MASK;
1530
+ };
1197
1531
 
1198
- case 2:
1199
- user = _a.sent();
1200
- if (user) this.currentUser = user;
1201
- return [3
1202
- /*break*/
1203
- , 4];
1532
+ var formatInfo = {
1533
+ getEncodedBits: getEncodedBits
1534
+ };
1204
1535
 
1205
- case 3:
1206
- error_6 = _a.sent();
1207
- Object(_helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["a"])(error_6);
1208
- return [3
1209
- /*break*/
1210
- , 4];
1536
+ function NumericData(data) {
1537
+ this.mode = mode.NUMERIC;
1538
+ this.data = data.toString();
1539
+ }
1211
1540
 
1212
- case 4:
1213
- return [3
1214
- /*break*/
1215
- , 6];
1541
+ NumericData.getBitsLength = function getBitsLength(length) {
1542
+ return 10 * Math.floor(length / 3) + (length % 3 ? length % 3 * 3 + 1 : 0);
1543
+ };
1216
1544
 
1217
- case 5:
1218
- this.currentUser = this.user;
1219
- _a.label = 6;
1545
+ NumericData.prototype.getLength = function getLength() {
1546
+ return this.data.length;
1547
+ };
1220
1548
 
1221
- case 6:
1222
- if (this.currentUser && this.currentUser.challengeParam && this.currentUser.challengeParam.requiredAttributes) {
1223
- userRequiredAttributes = this.currentUser.challengeParam.requiredAttributes;
1224
- requiredAttributesMap_1 = Object(_helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["g"])();
1225
- userRequiredAttributes.forEach(function (attribute) {
1226
- var formField = {
1227
- type: attribute,
1228
- required: true,
1229
- label: requiredAttributesMap_1[attribute].label,
1230
- placeholder: requiredAttributesMap_1[attribute].placeholder,
1231
- handleInputChange: function handleInputChange(event) {
1232
- return _this.handleRequiredAttributeInputChange(attribute, event);
1233
- },
1234
- inputProps: {
1235
- 'data-test': "require-new-password-" + attribute + "-input"
1236
- }
1237
- };
1238
- _this.newFormFields = __spreadArrays(_this.newFormFields, [formField]);
1239
- });
1549
+ NumericData.prototype.getBitsLength = function getBitsLength() {
1550
+ return NumericData.getBitsLength(this.data.length);
1551
+ };
1552
+
1553
+ NumericData.prototype.write = function write(bitBuffer) {
1554
+ var i, group, value; // The input data string is divided into groups of three digits,
1555
+ // and each group is converted to its 10-bit binary equivalent.
1556
+
1557
+ for (i = 0; i + 3 <= this.data.length; i += 3) {
1558
+ group = this.data.substr(i, 3);
1559
+ value = parseInt(group, 10);
1560
+ bitBuffer.put(value, 10);
1561
+ } // If the number of input digits is not an exact multiple of three,
1562
+ // the final one or two digits are converted to 4 or 7 bits respectively.
1563
+
1564
+
1565
+ var remainingNum = this.data.length - i;
1566
+
1567
+ if (remainingNum > 0) {
1568
+ group = this.data.substr(i);
1569
+ value = parseInt(group, 10);
1570
+ bitBuffer.put(value, remainingNum * 3 + 1);
1571
+ }
1572
+ };
1573
+
1574
+ var numericData = NumericData;
1575
+ /**
1576
+ * Array of characters available in alphanumeric mode
1577
+ *
1578
+ * As per QR Code specification, to each character
1579
+ * is assigned a value from 0 to 44 which in this case coincides
1580
+ * with the array index
1581
+ *
1582
+ * @type {Array}
1583
+ */
1584
+
1585
+ var ALPHA_NUM_CHARS = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', ' ', '$', '%', '*', '+', '-', '.', '/', ':'];
1586
+
1587
+ function AlphanumericData(data) {
1588
+ this.mode = mode.ALPHANUMERIC;
1589
+ this.data = data;
1590
+ }
1591
+
1592
+ AlphanumericData.getBitsLength = function getBitsLength(length) {
1593
+ return 11 * Math.floor(length / 2) + 6 * (length % 2);
1594
+ };
1595
+
1596
+ AlphanumericData.prototype.getLength = function getLength() {
1597
+ return this.data.length;
1598
+ };
1599
+
1600
+ AlphanumericData.prototype.getBitsLength = function getBitsLength() {
1601
+ return AlphanumericData.getBitsLength(this.data.length);
1602
+ };
1603
+
1604
+ AlphanumericData.prototype.write = function write(bitBuffer) {
1605
+ var i; // Input data characters are divided into groups of two characters
1606
+ // and encoded as 11-bit binary codes.
1607
+
1608
+ for (i = 0; i + 2 <= this.data.length; i += 2) {
1609
+ // The character value of the first character is multiplied by 45
1610
+ var value = ALPHA_NUM_CHARS.indexOf(this.data[i]) * 45; // The character value of the second digit is added to the product
1611
+
1612
+ value += ALPHA_NUM_CHARS.indexOf(this.data[i + 1]); // The sum is then stored as 11-bit binary number
1613
+
1614
+ bitBuffer.put(value, 11);
1615
+ } // If the number of input data characters is not a multiple of two,
1616
+ // the character value of the final character is encoded as a 6-bit binary number.
1617
+
1618
+
1619
+ if (this.data.length % 2) {
1620
+ bitBuffer.put(ALPHA_NUM_CHARS.indexOf(this.data[i]), 6);
1621
+ }
1622
+ };
1623
+
1624
+ var alphanumericData = AlphanumericData;
1625
+
1626
+ var encodeUtf8 = function encodeUtf8(input) {
1627
+ var result = [];
1628
+ var size = input.length;
1629
+
1630
+ for (var index = 0; index < size; index++) {
1631
+ var point = input.charCodeAt(index);
1632
+
1633
+ if (point >= 0xD800 && point <= 0xDBFF && size > index + 1) {
1634
+ var second = input.charCodeAt(index + 1);
1635
+
1636
+ if (second >= 0xDC00 && second <= 0xDFFF) {
1637
+ // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
1638
+ point = (point - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
1639
+ index += 1;
1640
+ }
1641
+ } // US-ASCII
1642
+
1643
+
1644
+ if (point < 0x80) {
1645
+ result.push(point);
1646
+ continue;
1647
+ } // 2-byte UTF-8
1648
+
1649
+
1650
+ if (point < 0x800) {
1651
+ result.push(point >> 6 | 192);
1652
+ result.push(point & 63 | 128);
1653
+ continue;
1654
+ } // 3-byte UTF-8
1655
+
1656
+
1657
+ if (point < 0xD800 || point >= 0xE000 && point < 0x10000) {
1658
+ result.push(point >> 12 | 224);
1659
+ result.push(point >> 6 & 63 | 128);
1660
+ result.push(point & 63 | 128);
1661
+ continue;
1662
+ } // 4-byte UTF-8
1663
+
1664
+
1665
+ if (point >= 0x10000 && point <= 0x10FFFF) {
1666
+ result.push(point >> 18 | 240);
1667
+ result.push(point >> 12 & 63 | 128);
1668
+ result.push(point >> 6 & 63 | 128);
1669
+ result.push(point & 63 | 128);
1670
+ continue;
1671
+ } // Invalid character
1672
+
1673
+
1674
+ result.push(0xEF, 0xBF, 0xBD);
1675
+ }
1676
+
1677
+ return new Uint8Array(result).buffer;
1678
+ };
1679
+
1680
+ function ByteData(data) {
1681
+ this.mode = mode.BYTE;
1682
+
1683
+ if (typeof data === 'string') {
1684
+ data = encodeUtf8(data);
1685
+ }
1686
+
1687
+ this.data = new Uint8Array(data);
1688
+ }
1689
+
1690
+ ByteData.getBitsLength = function getBitsLength(length) {
1691
+ return length * 8;
1692
+ };
1693
+
1694
+ ByteData.prototype.getLength = function getLength() {
1695
+ return this.data.length;
1696
+ };
1697
+
1698
+ ByteData.prototype.getBitsLength = function getBitsLength() {
1699
+ return ByteData.getBitsLength(this.data.length);
1700
+ };
1701
+
1702
+ ByteData.prototype.write = function (bitBuffer) {
1703
+ for (var i = 0, l = this.data.length; i < l; i++) {
1704
+ bitBuffer.put(this.data[i], 8);
1705
+ }
1706
+ };
1707
+
1708
+ var byteData = ByteData;
1709
+
1710
+ function KanjiData(data) {
1711
+ this.mode = mode.KANJI;
1712
+ this.data = data;
1713
+ }
1714
+
1715
+ KanjiData.getBitsLength = function getBitsLength(length) {
1716
+ return length * 13;
1717
+ };
1718
+
1719
+ KanjiData.prototype.getLength = function getLength() {
1720
+ return this.data.length;
1721
+ };
1722
+
1723
+ KanjiData.prototype.getBitsLength = function getBitsLength() {
1724
+ return KanjiData.getBitsLength(this.data.length);
1725
+ };
1726
+
1727
+ KanjiData.prototype.write = function (bitBuffer) {
1728
+ var i; // In the Shift JIS system, Kanji characters are represented by a two byte combination.
1729
+ // These byte values are shifted from the JIS X 0208 values.
1730
+ // JIS X 0208 gives details of the shift coded representation.
1731
+
1732
+ for (i = 0; i < this.data.length; i++) {
1733
+ var value = utils.toSJIS(this.data[i]); // For characters with Shift JIS values from 0x8140 to 0x9FFC:
1734
+
1735
+ if (value >= 0x8140 && value <= 0x9FFC) {
1736
+ // Subtract 0x8140 from Shift JIS value
1737
+ value -= 0x8140; // For characters with Shift JIS values from 0xE040 to 0xEBBF
1738
+ } else if (value >= 0xE040 && value <= 0xEBBF) {
1739
+ // Subtract 0xC140 from Shift JIS value
1740
+ value -= 0xC140;
1741
+ } else {
1742
+ throw new Error('Invalid SJIS character: ' + this.data[i] + '\n' + 'Make sure your charset is UTF-8');
1743
+ } // Multiply most significant byte of result by 0xC0
1744
+ // and add least significant byte to product
1745
+
1746
+
1747
+ value = (value >>> 8 & 0xff) * 0xC0 + (value & 0xff); // Convert result to a 13-bit binary string
1748
+
1749
+ bitBuffer.put(value, 13);
1750
+ }
1751
+ };
1752
+
1753
+ var kanjiData = KanjiData;
1754
+ var dijkstra_1 = createCommonjsModule(function (module) {
1755
+ /******************************************************************************
1756
+ * Created 2008-08-19.
1757
+ *
1758
+ * Dijkstra path-finding functions. Adapted from the Dijkstar Python project.
1759
+ *
1760
+ * Copyright (C) 2008
1761
+ * Wyatt Baldwin <self@wyattbaldwin.com>
1762
+ * All rights reserved
1763
+ *
1764
+ * Licensed under the MIT license.
1765
+ *
1766
+ * http://www.opensource.org/licenses/mit-license.php
1767
+ *
1768
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1769
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1770
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1771
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1772
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1773
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
1774
+ * THE SOFTWARE.
1775
+ *****************************************************************************/
1776
+ var dijkstra = {
1777
+ single_source_shortest_paths: function single_source_shortest_paths(graph, s, d) {
1778
+ // Predecessor map for each node that has been encountered.
1779
+ // node ID => predecessor node ID
1780
+ var predecessors = {}; // Costs of shortest paths from s to all nodes encountered.
1781
+ // node ID => cost
1782
+
1783
+ var costs = {};
1784
+ costs[s] = 0; // Costs of shortest paths from s to all nodes encountered; differs from
1785
+ // `costs` in that it provides easy access to the node that currently has
1786
+ // the known shortest path from s.
1787
+ // XXX: Do we actually need both `costs` and `open`?
1788
+
1789
+ var open = dijkstra.PriorityQueue.make();
1790
+ open.push(s, 0);
1791
+ var closest, u, v, cost_of_s_to_u, adjacent_nodes, cost_of_e, cost_of_s_to_u_plus_cost_of_e, cost_of_s_to_v, first_visit;
1792
+
1793
+ while (!open.empty()) {
1794
+ // In the nodes remaining in graph that have a known cost from s,
1795
+ // find the node, u, that currently has the shortest path from s.
1796
+ closest = open.pop();
1797
+ u = closest.value;
1798
+ cost_of_s_to_u = closest.cost; // Get nodes adjacent to u...
1799
+
1800
+ adjacent_nodes = graph[u] || {}; // ...and explore the edges that connect u to those nodes, updating
1801
+ // the cost of the shortest paths to any or all of those nodes as
1802
+ // necessary. v is the node across the current edge from u.
1803
+
1804
+ for (v in adjacent_nodes) {
1805
+ if (adjacent_nodes.hasOwnProperty(v)) {
1806
+ // Get the cost of the edge running from u to v.
1807
+ cost_of_e = adjacent_nodes[v]; // Cost of s to u plus the cost of u to v across e--this is *a*
1808
+ // cost from s to v that may or may not be less than the current
1809
+ // known cost to v.
1810
+
1811
+ cost_of_s_to_u_plus_cost_of_e = cost_of_s_to_u + cost_of_e; // If we haven't visited v yet OR if the current known cost from s to
1812
+ // v is greater than the new cost we just found (cost of s to u plus
1813
+ // cost of u to v across e), update v's cost in the cost list and
1814
+ // update v's predecessor in the predecessor list (it's now u).
1815
+
1816
+ cost_of_s_to_v = costs[v];
1817
+ first_visit = typeof costs[v] === 'undefined';
1818
+
1819
+ if (first_visit || cost_of_s_to_v > cost_of_s_to_u_plus_cost_of_e) {
1820
+ costs[v] = cost_of_s_to_u_plus_cost_of_e;
1821
+ open.push(v, cost_of_s_to_u_plus_cost_of_e);
1822
+ predecessors[v] = u;
1240
1823
  }
1824
+ }
1825
+ }
1826
+ }
1827
+
1828
+ if (typeof d !== 'undefined' && typeof costs[d] === 'undefined') {
1829
+ var msg = ['Could not find a path from ', s, ' to ', d, '.'].join('');
1830
+ throw new Error(msg);
1831
+ }
1832
+
1833
+ return predecessors;
1834
+ },
1835
+ extract_shortest_path_from_predecessor_list: function extract_shortest_path_from_predecessor_list(predecessors, d) {
1836
+ var nodes = [];
1837
+ var u = d;
1838
+
1839
+ while (u) {
1840
+ nodes.push(u);
1841
+ u = predecessors[u];
1842
+ }
1843
+
1844
+ nodes.reverse();
1845
+ return nodes;
1846
+ },
1847
+ find_path: function find_path(graph, s, d) {
1848
+ var predecessors = dijkstra.single_source_shortest_paths(graph, s, d);
1849
+ return dijkstra.extract_shortest_path_from_predecessor_list(predecessors, d);
1850
+ },
1851
+
1852
+ /**
1853
+ * A very naive priority queue implementation.
1854
+ */
1855
+ PriorityQueue: {
1856
+ make: function make(opts) {
1857
+ var T = dijkstra.PriorityQueue,
1858
+ t = {},
1859
+ key;
1860
+ opts = opts || {};
1861
+
1862
+ for (key in T) {
1863
+ if (T.hasOwnProperty(key)) {
1864
+ t[key] = T[key];
1865
+ }
1866
+ }
1867
+
1868
+ t.queue = [];
1869
+ t.sorter = opts.sorter || T.default_sorter;
1870
+ return t;
1871
+ },
1872
+ default_sorter: function default_sorter(a, b) {
1873
+ return a.cost - b.cost;
1874
+ },
1875
+
1876
+ /**
1877
+ * Add a new item to the queue and ensure the highest priority element
1878
+ * is at the front of the queue.
1879
+ */
1880
+ push: function push(value, cost) {
1881
+ var item = {
1882
+ value: value,
1883
+ cost: cost
1884
+ };
1885
+ this.queue.push(item);
1886
+ this.queue.sort(this.sorter);
1887
+ },
1888
+
1889
+ /**
1890
+ * Return the highest priority element in the queue.
1891
+ */
1892
+ pop: function pop() {
1893
+ return this.queue.shift();
1894
+ },
1895
+ empty: function empty() {
1896
+ return this.queue.length === 0;
1897
+ }
1898
+ }
1899
+ }; // node.js module exports
1900
+
1901
+ {
1902
+ module.exports = dijkstra;
1903
+ }
1904
+ });
1905
+ var segments = createCommonjsModule(function (module, exports) {
1906
+ /**
1907
+ * Returns UTF8 byte length
1908
+ *
1909
+ * @param {String} str Input string
1910
+ * @return {Number} Number of byte
1911
+ */
1912
+ function getStringByteLength(str) {
1913
+ return unescape(encodeURIComponent(str)).length;
1914
+ }
1915
+ /**
1916
+ * Get a list of segments of the specified mode
1917
+ * from a string
1918
+ *
1919
+ * @param {Mode} mode Segment mode
1920
+ * @param {String} str String to process
1921
+ * @return {Array} Array of object with segments data
1922
+ */
1923
+
1924
+
1925
+ function getSegments(regex, mode, str) {
1926
+ var segments = [];
1927
+ var result;
1928
+
1929
+ while ((result = regex.exec(str)) !== null) {
1930
+ segments.push({
1931
+ data: result[0],
1932
+ index: result.index,
1933
+ mode: mode,
1934
+ length: result[0].length
1935
+ });
1936
+ }
1937
+
1938
+ return segments;
1939
+ }
1940
+ /**
1941
+ * Extracts a series of segments with the appropriate
1942
+ * modes from a string
1943
+ *
1944
+ * @param {String} dataStr Input string
1945
+ * @return {Array} Array of object with segments data
1946
+ */
1947
+
1948
+
1949
+ function getSegmentsFromString(dataStr) {
1950
+ var numSegs = getSegments(regex.NUMERIC, mode.NUMERIC, dataStr);
1951
+ var alphaNumSegs = getSegments(regex.ALPHANUMERIC, mode.ALPHANUMERIC, dataStr);
1952
+ var byteSegs;
1953
+ var kanjiSegs;
1954
+
1955
+ if (utils.isKanjiModeEnabled()) {
1956
+ byteSegs = getSegments(regex.BYTE, mode.BYTE, dataStr);
1957
+ kanjiSegs = getSegments(regex.KANJI, mode.KANJI, dataStr);
1958
+ } else {
1959
+ byteSegs = getSegments(regex.BYTE_KANJI, mode.BYTE, dataStr);
1960
+ kanjiSegs = [];
1961
+ }
1962
+
1963
+ var segs = numSegs.concat(alphaNumSegs, byteSegs, kanjiSegs);
1964
+ return segs.sort(function (s1, s2) {
1965
+ return s1.index - s2.index;
1966
+ }).map(function (obj) {
1967
+ return {
1968
+ data: obj.data,
1969
+ mode: obj.mode,
1970
+ length: obj.length
1971
+ };
1972
+ });
1973
+ }
1974
+ /**
1975
+ * Returns how many bits are needed to encode a string of
1976
+ * specified length with the specified mode
1977
+ *
1978
+ * @param {Number} length String length
1979
+ * @param {Mode} mode Segment mode
1980
+ * @return {Number} Bit length
1981
+ */
1982
+
1983
+
1984
+ function getSegmentBitsLength(length, mode$1) {
1985
+ switch (mode$1) {
1986
+ case mode.NUMERIC:
1987
+ return numericData.getBitsLength(length);
1988
+
1989
+ case mode.ALPHANUMERIC:
1990
+ return alphanumericData.getBitsLength(length);
1991
+
1992
+ case mode.KANJI:
1993
+ return kanjiData.getBitsLength(length);
1994
+
1995
+ case mode.BYTE:
1996
+ return byteData.getBitsLength(length);
1997
+ }
1998
+ }
1999
+ /**
2000
+ * Merges adjacent segments which have the same mode
2001
+ *
2002
+ * @param {Array} segs Array of object with segments data
2003
+ * @return {Array} Array of object with segments data
2004
+ */
2005
+
2006
+
2007
+ function mergeSegments(segs) {
2008
+ return segs.reduce(function (acc, curr) {
2009
+ var prevSeg = acc.length - 1 >= 0 ? acc[acc.length - 1] : null;
2010
+
2011
+ if (prevSeg && prevSeg.mode === curr.mode) {
2012
+ acc[acc.length - 1].data += curr.data;
2013
+ return acc;
2014
+ }
2015
+
2016
+ acc.push(curr);
2017
+ return acc;
2018
+ }, []);
2019
+ }
2020
+ /**
2021
+ * Generates a list of all possible nodes combination which
2022
+ * will be used to build a segments graph.
2023
+ *
2024
+ * Nodes are divided by groups. Each group will contain a list of all the modes
2025
+ * in which is possible to encode the given text.
2026
+ *
2027
+ * For example the text '12345' can be encoded as Numeric, Alphanumeric or Byte.
2028
+ * The group for '12345' will contain then 3 objects, one for each
2029
+ * possible encoding mode.
2030
+ *
2031
+ * Each node represents a possible segment.
2032
+ *
2033
+ * @param {Array} segs Array of object with segments data
2034
+ * @return {Array} Array of object with segments data
2035
+ */
2036
+
2037
+
2038
+ function buildNodes(segs) {
2039
+ var nodes = [];
2040
+
2041
+ for (var i = 0; i < segs.length; i++) {
2042
+ var seg = segs[i];
2043
+
2044
+ switch (seg.mode) {
2045
+ case mode.NUMERIC:
2046
+ nodes.push([seg, {
2047
+ data: seg.data,
2048
+ mode: mode.ALPHANUMERIC,
2049
+ length: seg.length
2050
+ }, {
2051
+ data: seg.data,
2052
+ mode: mode.BYTE,
2053
+ length: seg.length
2054
+ }]);
2055
+ break;
2056
+
2057
+ case mode.ALPHANUMERIC:
2058
+ nodes.push([seg, {
2059
+ data: seg.data,
2060
+ mode: mode.BYTE,
2061
+ length: seg.length
2062
+ }]);
2063
+ break;
2064
+
2065
+ case mode.KANJI:
2066
+ nodes.push([seg, {
2067
+ data: seg.data,
2068
+ mode: mode.BYTE,
2069
+ length: getStringByteLength(seg.data)
2070
+ }]);
2071
+ break;
2072
+
2073
+ case mode.BYTE:
2074
+ nodes.push([{
2075
+ data: seg.data,
2076
+ mode: mode.BYTE,
2077
+ length: getStringByteLength(seg.data)
2078
+ }]);
2079
+ }
2080
+ }
2081
+
2082
+ return nodes;
2083
+ }
2084
+ /**
2085
+ * Builds a graph from a list of nodes.
2086
+ * All segments in each node group will be connected with all the segments of
2087
+ * the next group and so on.
2088
+ *
2089
+ * At each connection will be assigned a weight depending on the
2090
+ * segment's byte length.
2091
+ *
2092
+ * @param {Array} nodes Array of object with segments data
2093
+ * @param {Number} version QR Code version
2094
+ * @return {Object} Graph of all possible segments
2095
+ */
2096
+
2097
+
2098
+ function buildGraph(nodes, version) {
2099
+ var table = {};
2100
+ var graph = {
2101
+ start: {}
2102
+ };
2103
+ var prevNodeIds = ['start'];
2104
+
2105
+ for (var i = 0; i < nodes.length; i++) {
2106
+ var nodeGroup = nodes[i];
2107
+ var currentNodeIds = [];
2108
+
2109
+ for (var j = 0; j < nodeGroup.length; j++) {
2110
+ var node = nodeGroup[j];
2111
+ var key = '' + i + j;
2112
+ currentNodeIds.push(key);
2113
+ table[key] = {
2114
+ node: node,
2115
+ lastCount: 0
2116
+ };
2117
+ graph[key] = {};
2118
+
2119
+ for (var n = 0; n < prevNodeIds.length; n++) {
2120
+ var prevNodeId = prevNodeIds[n];
2121
+
2122
+ if (table[prevNodeId] && table[prevNodeId].node.mode === node.mode) {
2123
+ graph[prevNodeId][key] = getSegmentBitsLength(table[prevNodeId].lastCount + node.length, node.mode) - getSegmentBitsLength(table[prevNodeId].lastCount, node.mode);
2124
+ table[prevNodeId].lastCount += node.length;
2125
+ } else {
2126
+ if (table[prevNodeId]) table[prevNodeId].lastCount = node.length;
2127
+ graph[prevNodeId][key] = getSegmentBitsLength(node.length, node.mode) + 4 + mode.getCharCountIndicator(node.mode, version); // switch cost
2128
+ }
2129
+ }
2130
+ }
2131
+
2132
+ prevNodeIds = currentNodeIds;
2133
+ }
2134
+
2135
+ for (var n = 0; n < prevNodeIds.length; n++) {
2136
+ graph[prevNodeIds[n]].end = 0;
2137
+ }
2138
+
2139
+ return {
2140
+ map: graph,
2141
+ table: table
2142
+ };
2143
+ }
2144
+ /**
2145
+ * Builds a segment from a specified data and mode.
2146
+ * If a mode is not specified, the more suitable will be used.
2147
+ *
2148
+ * @param {String} data Input data
2149
+ * @param {Mode | String} modesHint Data mode
2150
+ * @return {Segment} Segment
2151
+ */
2152
+
2153
+
2154
+ function buildSingleSegment(data, modesHint) {
2155
+ var mode$1;
2156
+ var bestMode = mode.getBestModeForData(data);
2157
+ mode$1 = mode.from(modesHint, bestMode); // Make sure data can be encoded
2158
+
2159
+ if (mode$1 !== mode.BYTE && mode$1.bit < bestMode.bit) {
2160
+ throw new Error('"' + data + '"' + ' cannot be encoded with mode ' + mode.toString(mode$1) + '.\n Suggested mode is: ' + mode.toString(bestMode));
2161
+ } // Use Mode.BYTE if Kanji support is disabled
2162
+
2163
+
2164
+ if (mode$1 === mode.KANJI && !utils.isKanjiModeEnabled()) {
2165
+ mode$1 = mode.BYTE;
2166
+ }
2167
+
2168
+ switch (mode$1) {
2169
+ case mode.NUMERIC:
2170
+ return new numericData(data);
2171
+
2172
+ case mode.ALPHANUMERIC:
2173
+ return new alphanumericData(data);
2174
+
2175
+ case mode.KANJI:
2176
+ return new kanjiData(data);
2177
+
2178
+ case mode.BYTE:
2179
+ return new byteData(data);
2180
+ }
2181
+ }
2182
+ /**
2183
+ * Builds a list of segments from an array.
2184
+ * Array can contain Strings or Objects with segment's info.
2185
+ *
2186
+ * For each item which is a string, will be generated a segment with the given
2187
+ * string and the more appropriate encoding mode.
2188
+ *
2189
+ * For each item which is an object, will be generated a segment with the given
2190
+ * data and mode.
2191
+ * Objects must contain at least the property "data".
2192
+ * If property "mode" is not present, the more suitable mode will be used.
2193
+ *
2194
+ * @param {Array} array Array of objects with segments data
2195
+ * @return {Array} Array of Segments
2196
+ */
2197
+
2198
+
2199
+ exports.fromArray = function fromArray(array) {
2200
+ return array.reduce(function (acc, seg) {
2201
+ if (typeof seg === 'string') {
2202
+ acc.push(buildSingleSegment(seg, null));
2203
+ } else if (seg.data) {
2204
+ acc.push(buildSingleSegment(seg.data, seg.mode));
2205
+ }
2206
+
2207
+ return acc;
2208
+ }, []);
2209
+ };
2210
+ /**
2211
+ * Builds an optimized sequence of segments from a string,
2212
+ * which will produce the shortest possible bitstream.
2213
+ *
2214
+ * @param {String} data Input string
2215
+ * @param {Number} version QR Code version
2216
+ * @return {Array} Array of segments
2217
+ */
2218
+
2219
+
2220
+ exports.fromString = function fromString(data, version) {
2221
+ var segs = getSegmentsFromString(data, utils.isKanjiModeEnabled());
2222
+ var nodes = buildNodes(segs);
2223
+ var graph = buildGraph(nodes, version);
2224
+ var path = dijkstra_1.find_path(graph.map, 'start', 'end');
2225
+ var optimizedSegs = [];
2226
+
2227
+ for (var i = 1; i < path.length - 1; i++) {
2228
+ optimizedSegs.push(graph.table[path[i]].node);
2229
+ }
2230
+
2231
+ return exports.fromArray(mergeSegments(optimizedSegs));
2232
+ };
2233
+ /**
2234
+ * Splits a string in various segments with the modes which
2235
+ * best represent their content.
2236
+ * The produced segments are far from being optimized.
2237
+ * The output of this function is only used to estimate a QR Code version
2238
+ * which may contain the data.
2239
+ *
2240
+ * @param {string} data Input string
2241
+ * @return {Array} Array of segments
2242
+ */
2243
+
2244
+
2245
+ exports.rawSplit = function rawSplit(data) {
2246
+ return exports.fromArray(getSegmentsFromString(data, utils.isKanjiModeEnabled()));
2247
+ };
2248
+ });
2249
+ /**
2250
+ * QRCode for JavaScript
2251
+ *
2252
+ * modified by Ryan Day for nodejs support
2253
+ * Copyright (c) 2011 Ryan Day
2254
+ *
2255
+ * Licensed under the MIT license:
2256
+ * http://www.opensource.org/licenses/mit-license.php
2257
+ *
2258
+ //---------------------------------------------------------------------
2259
+ // QRCode for JavaScript
2260
+ //
2261
+ // Copyright (c) 2009 Kazuhiko Arase
2262
+ //
2263
+ // URL: http://www.d-project.com/
2264
+ //
2265
+ // Licensed under the MIT license:
2266
+ // http://www.opensource.org/licenses/mit-license.php
2267
+ //
2268
+ // The word "QR Code" is registered trademark of
2269
+ // DENSO WAVE INCORPORATED
2270
+ // http://www.denso-wave.com/qrcode/faqpatent-e.html
2271
+ //
2272
+ //---------------------------------------------------------------------
2273
+ */
2274
+
2275
+ /**
2276
+ * Add finder patterns bits to matrix
2277
+ *
2278
+ * @param {BitMatrix} matrix Modules matrix
2279
+ * @param {Number} version QR Code version
2280
+ */
2281
+
2282
+ function setupFinderPattern(matrix, version) {
2283
+ var size = matrix.size;
2284
+ var pos = finderPattern.getPositions(version);
2285
+
2286
+ for (var i = 0; i < pos.length; i++) {
2287
+ var row = pos[i][0];
2288
+ var col = pos[i][1];
2289
+
2290
+ for (var r = -1; r <= 7; r++) {
2291
+ if (row + r <= -1 || size <= row + r) continue;
2292
+
2293
+ for (var c = -1; c <= 7; c++) {
2294
+ if (col + c <= -1 || size <= col + c) continue;
2295
+
2296
+ if (r >= 0 && r <= 6 && (c === 0 || c === 6) || c >= 0 && c <= 6 && (r === 0 || r === 6) || r >= 2 && r <= 4 && c >= 2 && c <= 4) {
2297
+ matrix.set(row + r, col + c, true, true);
2298
+ } else {
2299
+ matrix.set(row + r, col + c, false, true);
2300
+ }
2301
+ }
2302
+ }
2303
+ }
2304
+ }
2305
+ /**
2306
+ * Add timing pattern bits to matrix
2307
+ *
2308
+ * Note: this function must be called before {@link setupAlignmentPattern}
2309
+ *
2310
+ * @param {BitMatrix} matrix Modules matrix
2311
+ */
2312
+
2313
+
2314
+ function setupTimingPattern(matrix) {
2315
+ var size = matrix.size;
2316
+
2317
+ for (var r = 8; r < size - 8; r++) {
2318
+ var value = r % 2 === 0;
2319
+ matrix.set(r, 6, value, true);
2320
+ matrix.set(6, r, value, true);
2321
+ }
2322
+ }
2323
+ /**
2324
+ * Add alignment patterns bits to matrix
2325
+ *
2326
+ * Note: this function must be called after {@link setupTimingPattern}
2327
+ *
2328
+ * @param {BitMatrix} matrix Modules matrix
2329
+ * @param {Number} version QR Code version
2330
+ */
2331
+
2332
+
2333
+ function setupAlignmentPattern(matrix, version) {
2334
+ var pos = alignmentPattern.getPositions(version);
2335
+
2336
+ for (var i = 0; i < pos.length; i++) {
2337
+ var row = pos[i][0];
2338
+ var col = pos[i][1];
2339
+
2340
+ for (var r = -2; r <= 2; r++) {
2341
+ for (var c = -2; c <= 2; c++) {
2342
+ if (r === -2 || r === 2 || c === -2 || c === 2 || r === 0 && c === 0) {
2343
+ matrix.set(row + r, col + c, true, true);
2344
+ } else {
2345
+ matrix.set(row + r, col + c, false, true);
2346
+ }
2347
+ }
2348
+ }
2349
+ }
2350
+ }
2351
+ /**
2352
+ * Add version info bits to matrix
2353
+ *
2354
+ * @param {BitMatrix} matrix Modules matrix
2355
+ * @param {Number} version QR Code version
2356
+ */
2357
+
2358
+
2359
+ function setupVersionInfo(matrix, version$1) {
2360
+ var size = matrix.size;
2361
+ var bits = version.getEncodedBits(version$1);
2362
+ var row, col, mod;
2363
+
2364
+ for (var i = 0; i < 18; i++) {
2365
+ row = Math.floor(i / 3);
2366
+ col = i % 3 + size - 8 - 3;
2367
+ mod = (bits >> i & 1) === 1;
2368
+ matrix.set(row, col, mod, true);
2369
+ matrix.set(col, row, mod, true);
2370
+ }
2371
+ }
2372
+ /**
2373
+ * Add format info bits to matrix
2374
+ *
2375
+ * @param {BitMatrix} matrix Modules matrix
2376
+ * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level
2377
+ * @param {Number} maskPattern Mask pattern reference value
2378
+ */
2379
+
2380
+
2381
+ function setupFormatInfo(matrix, errorCorrectionLevel, maskPattern) {
2382
+ var size = matrix.size;
2383
+ var bits = formatInfo.getEncodedBits(errorCorrectionLevel, maskPattern);
2384
+ var i, mod;
2385
+
2386
+ for (i = 0; i < 15; i++) {
2387
+ mod = (bits >> i & 1) === 1; // vertical
2388
+
2389
+ if (i < 6) {
2390
+ matrix.set(i, 8, mod, true);
2391
+ } else if (i < 8) {
2392
+ matrix.set(i + 1, 8, mod, true);
2393
+ } else {
2394
+ matrix.set(size - 15 + i, 8, mod, true);
2395
+ } // horizontal
2396
+
2397
+
2398
+ if (i < 8) {
2399
+ matrix.set(8, size - i - 1, mod, true);
2400
+ } else if (i < 9) {
2401
+ matrix.set(8, 15 - i - 1 + 1, mod, true);
2402
+ } else {
2403
+ matrix.set(8, 15 - i - 1, mod, true);
2404
+ }
2405
+ } // fixed module
2406
+
1241
2407
 
1242
- return [2
1243
- /*return*/
1244
- ];
1245
- }
1246
- });
1247
- });
1248
- };
2408
+ matrix.set(size - 8, 8, 1, true);
2409
+ }
2410
+ /**
2411
+ * Add encoded data bits to matrix
2412
+ *
2413
+ * @param {BitMatrix} matrix Modules matrix
2414
+ * @param {Uint8Array} data Data codewords
2415
+ */
2416
+
2417
+
2418
+ function setupData(matrix, data) {
2419
+ var size = matrix.size;
2420
+ var inc = -1;
2421
+ var row = size - 1;
2422
+ var bitIndex = 7;
2423
+ var byteIndex = 0;
2424
+
2425
+ for (var col = size - 1; col > 0; col -= 2) {
2426
+ if (col === 6) col--;
2427
+
2428
+ while (true) {
2429
+ for (var c = 0; c < 2; c++) {
2430
+ if (!matrix.isReserved(row, col - c)) {
2431
+ var dark = false;
2432
+
2433
+ if (byteIndex < data.length) {
2434
+ dark = (data[byteIndex] >>> bitIndex & 1) === 1;
2435
+ }
1249
2436
 
1250
- class_4.prototype.componentWillLoad = function () {
1251
- return this.setCurrentUser();
1252
- };
2437
+ matrix.set(row, col - c, dark);
2438
+ bitIndex--;
1253
2439
 
1254
- class_4.prototype.handlePasswordChange = function (event) {
1255
- this.password = event.target.value;
1256
- };
2440
+ if (bitIndex === -1) {
2441
+ byteIndex++;
2442
+ bitIndex = 7;
2443
+ }
2444
+ }
2445
+ }
1257
2446
 
1258
- class_4.prototype.formatPhoneNumber = function (event) {
1259
- Object(_helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["h"])(event, this.phoneNumber);
1260
- /**
1261
- * composePhoneNumberInput will throw an error if the phoneNumberValue it receives
1262
- * is empty. Adding a check here to try and make sure that doesn't happen...but will
1263
- * wrap it in a try/catch block just in case as well
1264
- */
2447
+ row += inc;
1265
2448
 
1266
- try {
1267
- if (event.target.name === _constants_c8ecaa24_js__WEBPACK_IMPORTED_MODULE_5__["b"] && this.phoneNumber.phoneNumberValue) {
1268
- var composedInput = Object(_helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["b"])(this.phoneNumber);
1269
- this.requiredAttributes['phone_number'] = composedInput;
2449
+ if (row < 0 || size <= row) {
2450
+ row -= inc;
2451
+ inc = -inc;
2452
+ break;
1270
2453
  }
1271
- } catch (err) {
1272
- logger$1.error("error in phone number field - " + err);
1273
2454
  }
1274
- };
2455
+ }
2456
+ }
2457
+ /**
2458
+ * Create encoded codewords from data input
2459
+ *
2460
+ * @param {Number} version QR Code version
2461
+ * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level
2462
+ * @param {ByteData} data Data input
2463
+ * @return {Uint8Array} Buffer containing encoded codewords
2464
+ */
2465
+
2466
+
2467
+ function createData(version, errorCorrectionLevel, segments) {
2468
+ // Prepare data buffer
2469
+ var buffer = new bitBuffer();
2470
+ segments.forEach(function (data) {
2471
+ // prefix data with mode indicator (4 bits)
2472
+ buffer.put(data.mode.bit, 4); // Prefix data with character count indicator.
2473
+ // The character count indicator is a string of bits that represents the
2474
+ // number of characters that are being encoded.
2475
+ // The character count indicator must be placed after the mode indicator
2476
+ // and must be a certain number of bits long, depending on the QR version
2477
+ // and data mode
2478
+ // @see {@link Mode.getCharCountIndicator}.
2479
+
2480
+ buffer.put(data.getLength(), mode.getCharCountIndicator(data.mode, version)); // add binary data sequence to buffer
2481
+
2482
+ data.write(buffer);
2483
+ }); // Calculate required number of bits
2484
+
2485
+ var totalCodewords = utils.getSymbolTotalCodewords(version);
2486
+ var ecTotalCodewords = errorCorrectionCode.getTotalCodewordsCount(version, errorCorrectionLevel);
2487
+ var dataTotalCodewordsBits = (totalCodewords - ecTotalCodewords) * 8; // Add a terminator.
2488
+ // If the bit string is shorter than the total number of required bits,
2489
+ // a terminator of up to four 0s must be added to the right side of the string.
2490
+ // If the bit string is more than four bits shorter than the required number of bits,
2491
+ // add four 0s to the end.
2492
+
2493
+ if (buffer.getLengthInBits() + 4 <= dataTotalCodewordsBits) {
2494
+ buffer.put(0, 4);
2495
+ } // If the bit string is fewer than four bits shorter, add only the number of 0s that
2496
+ // are needed to reach the required number of bits.
2497
+ // After adding the terminator, if the number of bits in the string is not a multiple of 8,
2498
+ // pad the string on the right with 0s to make the string's length a multiple of 8.
2499
+
2500
+
2501
+ while (buffer.getLengthInBits() % 8 !== 0) {
2502
+ buffer.putBit(0);
2503
+ } // Add pad bytes if the string is still shorter than the total number of required bits.
2504
+ // Extend the buffer to fill the data capacity of the symbol corresponding to
2505
+ // the Version and Error Correction Level by adding the Pad Codewords 11101100 (0xEC)
2506
+ // and 00010001 (0x11) alternately.
2507
+
2508
+
2509
+ var remainingByte = (dataTotalCodewordsBits - buffer.getLengthInBits()) / 8;
2510
+
2511
+ for (var i = 0; i < remainingByte; i++) {
2512
+ buffer.put(i % 2 ? 0x11 : 0xEC, 8);
2513
+ }
1275
2514
 
1276
- class_4.prototype.completeNewPassword = function (event) {
1277
- return __awaiter(this, void 0, void 0, function () {
1278
- var user, _a, error_7;
2515
+ return createCodewords(buffer, version, errorCorrectionLevel);
2516
+ }
2517
+ /**
2518
+ * Encode input data with Reed-Solomon and return codewords with
2519
+ * relative error correction bits
2520
+ *
2521
+ * @param {BitBuffer} bitBuffer Data to encode
2522
+ * @param {Number} version QR Code version
2523
+ * @param {ErrorCorrectionLevel} errorCorrectionLevel Error correction level
2524
+ * @return {Uint8Array} Buffer containing encoded codewords
2525
+ */
1279
2526
 
1280
- return __generator(this, function (_b) {
1281
- switch (_b.label) {
1282
- case 0:
1283
- if (event) {
1284
- event.preventDefault();
1285
- }
1286
2527
 
1287
- if (!_aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"] || typeof _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"].completeNewPassword !== 'function') {
1288
- throw new Error(_constants_c8ecaa24_js__WEBPACK_IMPORTED_MODULE_5__["N"]);
1289
- }
2528
+ function createCodewords(bitBuffer, version, errorCorrectionLevel) {
2529
+ // Total codewords for this QR code version (Data + Error correction)
2530
+ var totalCodewords = utils.getSymbolTotalCodewords(version); // Total number of error correction codewords
1290
2531
 
1291
- this.loading = true;
1292
- _b.label = 1;
2532
+ var ecTotalCodewords = errorCorrectionCode.getTotalCodewordsCount(version, errorCorrectionLevel); // Total number of data codewords
1293
2533
 
1294
- case 1:
1295
- _b.trys.push([1, 8, 9, 10]);
2534
+ var dataTotalCodewords = totalCodewords - ecTotalCodewords; // Total number of blocks
1296
2535
 
1297
- return [4
1298
- /*yield*/
1299
- , _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"].completeNewPassword(this.currentUser, this.password, this.requiredAttributes)];
2536
+ var ecTotalBlocks = errorCorrectionCode.getBlocksCount(version, errorCorrectionLevel); // Calculate how many blocks each group should contain
1300
2537
 
1301
- case 2:
1302
- user = _b.sent();
1303
- logger$1.debug('complete new password', user);
1304
- _a = user.challengeName;
1305
-
1306
- switch (_a) {
1307
- case _auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_2__["C"].SMSMFA:
1308
- return [3
1309
- /*break*/
1310
- , 3];
1311
-
1312
- case _auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_2__["C"].MFASetup:
1313
- return [3
1314
- /*break*/
1315
- , 4];
1316
- }
2538
+ var blocksInGroup2 = totalCodewords % ecTotalBlocks;
2539
+ var blocksInGroup1 = ecTotalBlocks - blocksInGroup2;
2540
+ var totalCodewordsInGroup1 = Math.floor(totalCodewords / ecTotalBlocks);
2541
+ var dataCodewordsInGroup1 = Math.floor(dataTotalCodewords / ecTotalBlocks);
2542
+ var dataCodewordsInGroup2 = dataCodewordsInGroup1 + 1; // Number of EC codewords is the same for both groups
1317
2543
 
1318
- return [3
1319
- /*break*/
1320
- , 5];
2544
+ var ecCount = totalCodewordsInGroup1 - dataCodewordsInGroup1; // Initialize a Reed-Solomon encoder with a generator polynomial of degree ecCount
1321
2545
 
1322
- case 3:
1323
- this.handleAuthStateChange(_auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_2__["A"].ConfirmSignIn, user);
1324
- return [3
1325
- /*break*/
1326
- , 7];
2546
+ var rs = new reedSolomonEncoder(ecCount);
2547
+ var offset = 0;
2548
+ var dcData = new Array(ecTotalBlocks);
2549
+ var ecData = new Array(ecTotalBlocks);
2550
+ var maxDataSize = 0;
2551
+ var buffer = new Uint8Array(bitBuffer.buffer); // Divide the buffer into the required number of blocks
1327
2552
 
1328
- case 4:
1329
- logger$1.debug('TOTP setup', user.challengeParam);
1330
- this.handleAuthStateChange(_auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_2__["A"].TOTPSetup, user);
1331
- return [3
1332
- /*break*/
1333
- , 7];
2553
+ for (var b = 0; b < ecTotalBlocks; b++) {
2554
+ var dataSize = b < blocksInGroup1 ? dataCodewordsInGroup1 : dataCodewordsInGroup2; // extract a block of data from buffer
1334
2555
 
1335
- case 5:
1336
- return [4
1337
- /*yield*/
1338
- , Object(_auth_helpers_557b83fc_js__WEBPACK_IMPORTED_MODULE_7__["c"])(user, this.handleAuthStateChange)];
2556
+ dcData[b] = buffer.slice(offset, offset + dataSize); // Calculate EC codewords for this data block
1339
2557
 
1340
- case 6:
1341
- _b.sent();
2558
+ ecData[b] = rs.encode(dcData[b]);
2559
+ offset += dataSize;
2560
+ maxDataSize = Math.max(maxDataSize, dataSize);
2561
+ } // Create final data
2562
+ // Interleave the data and error correction codewords from each block
1342
2563
 
1343
- _b.label = 7;
1344
2564
 
1345
- case 7:
1346
- return [3
1347
- /*break*/
1348
- , 10];
2565
+ var data = new Uint8Array(totalCodewords);
2566
+ var index = 0;
2567
+ var i, r; // Add data codewords
1349
2568
 
1350
- case 8:
1351
- error_7 = _b.sent();
1352
- Object(_helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["a"])(error_7);
1353
- return [3
1354
- /*break*/
1355
- , 10];
2569
+ for (i = 0; i < maxDataSize; i++) {
2570
+ for (r = 0; r < ecTotalBlocks; r++) {
2571
+ if (i < dcData[r].length) {
2572
+ data[index++] = dcData[r][i];
2573
+ }
2574
+ }
2575
+ } // Apped EC codewords
1356
2576
 
1357
- case 9:
1358
- this.loading = false;
1359
- return [7
1360
- /*endfinally*/
1361
- ];
1362
2577
 
1363
- case 10:
1364
- return [2
1365
- /*return*/
1366
- ];
1367
- }
1368
- });
1369
- });
1370
- };
2578
+ for (i = 0; i < ecCount; i++) {
2579
+ for (r = 0; r < ecTotalBlocks; r++) {
2580
+ data[index++] = ecData[r][i];
2581
+ }
2582
+ }
1371
2583
 
1372
- class_4.prototype.render = function () {
1373
- var _this = this;
2584
+ return data;
2585
+ }
2586
+ /**
2587
+ * Build QR Code symbol
2588
+ *
2589
+ * @param {String} data Input string
2590
+ * @param {Number} version QR Code version
2591
+ * @param {ErrorCorretionLevel} errorCorrectionLevel Error level
2592
+ * @param {MaskPattern} maskPattern Mask pattern
2593
+ * @return {Object} Object containing symbol data
2594
+ */
1374
2595
 
1375
- return Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["H"], null, Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-form-section", {
1376
- headerText: _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(this.headerText),
1377
- handleSubmit: this.handleSubmit,
1378
- loading: this.loading,
1379
- secondaryFooterContent: Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-button", {
1380
- variant: "anchor",
1381
- onClick: function onClick() {
1382
- return _this.handleAuthStateChange(_auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_2__["A"].SignIn);
1383
- }
1384
- }, _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].BACK_TO_SIGN_IN)),
1385
- submitButtonText: _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(this.submitButtonText)
1386
- }, Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-auth-fields", {
1387
- formFields: this.newFormFields
1388
- })));
1389
- };
1390
2596
 
1391
- Object.defineProperty(class_4, "watchers", {
1392
- get: function get() {
1393
- return {
1394
- "user": ["userHandler"]
1395
- };
1396
- },
1397
- enumerable: false,
1398
- configurable: true
1399
- });
1400
- return class_4;
1401
- }();
2597
+ function createSymbol(data, version$1, errorCorrectionLevel, maskPattern$1) {
2598
+ var segments$1;
1402
2599
 
1403
- var amplifySignInCss = ":host{--footer-size:var(--amplify-text-sm);--footer-color:var(--amplify-grey);--footer-font-family:var(--amplify-font-family);--font-weight:var(--amplify-font-weight)}.sign-in-form-footer{font-family:var(--footer-font-family);font-size:var(--footer-size);color:var(--footer-color);font-weight:--font-weight;display:-ms-flexbox;display:flex;-ms-flex-direction:column-reverse;flex-direction:column-reverse;-ms-flex-align:center;align-items:center;-ms-flex-pack:distribute;justify-content:space-around}.sign-in-form-footer amplify-button{margin-bottom:0.625rem}@media (min-width: 672px){.sign-in-form-footer{display:-ms-flexbox;display:flex;-ms-flex-direction:row;flex-direction:row;-ms-flex-pack:justify;justify-content:space-between;-ms-flex-align:baseline;align-items:baseline}.sign-in-form-footer amplify-button{margin-bottom:0}}.sign-in-form-footer *+*{margin-bottom:15px}.full-width-footer-content{width:100%}";
2600
+ if (Array.isArray(data)) {
2601
+ segments$1 = segments.fromArray(data);
2602
+ } else if (typeof data === 'string') {
2603
+ var estimatedVersion = version$1;
1404
2604
 
1405
- var AmplifySignIn =
1406
- /** @class */
1407
- function () {
1408
- function class_5(hostRef) {
1409
- var _this = this;
2605
+ if (!estimatedVersion) {
2606
+ var rawSegments = segments.rawSplit(data); // Estimate best version that can contain raw splitted segments
1410
2607
 
1411
- Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["r"])(this, hostRef);
1412
- /** Fires when sign in form is submitted */
2608
+ estimatedVersion = version.getBestVersionForData(rawSegments, errorCorrectionLevel);
2609
+ } // Build optimized segments
2610
+ // If estimated version is undefined, try with the highest version
1413
2611
 
1414
- this.handleSubmit = function (event) {
1415
- return _this.signIn(event);
1416
- };
1417
- /** Used for header text in sign in component */
1418
2612
 
2613
+ segments$1 = segments.fromString(data, estimatedVersion || 40);
2614
+ } else {
2615
+ throw new Error('Invalid data');
2616
+ } // Get the min version that can contain data
1419
2617
 
1420
- this.headerText = _Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].SIGN_IN_HEADER_TEXT;
1421
- /** Used for the submit button text in sign in component */
1422
2618
 
1423
- this.submitButtonText = _Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].SIGN_IN_ACTION;
1424
- /** Auth state change handler for this component */
1425
- // prettier-ignore
2619
+ var bestVersion = version.getBestVersionForData(segments$1, errorCorrectionLevel); // If no version is found, data cannot be stored
1426
2620
 
1427
- this.handleAuthStateChange = _helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["d"];
1428
- /** Username Alias is used to setup authentication with `username`, `email` or `phone_number` */
2621
+ if (!bestVersion) {
2622
+ throw new Error('The amount of data is too big to be stored in a QR Code');
2623
+ } // If not specified, use min version as default
1429
2624
 
1430
- this.usernameAlias = 'username';
1431
- /**
1432
- * Form fields allows you to utilize our pre-built components such as username field, code field, password field, email field, etc.
1433
- * by passing an array of strings that you would like the order of the form to be in. If you need more customization, such as changing
1434
- * text for a label or adjust a placeholder, you can follow the structure below in order to do just that.
1435
- * ```
1436
- * [
1437
- * {
1438
- * type: string,
1439
- * label: string,
1440
- * placeholder: string,
1441
- * hint: string | Functional Component | null,
1442
- * required: boolean
1443
- * }
1444
- * ]
1445
- * ```
1446
- */
1447
2625
 
1448
- this.formFields = [];
1449
- /** Hides the sign up link */
2626
+ if (!version$1) {
2627
+ version$1 = bestVersion; // Check if the specified version can contain the data
2628
+ } else if (version$1 < bestVersion) {
2629
+ throw new Error('\n' + 'The chosen QR Code version cannot contain this amount of data.\n' + 'Minimum version required to store current data is: ' + bestVersion + '.\n');
2630
+ }
2631
+
2632
+ var dataBits = createData(version$1, errorCorrectionLevel, segments$1); // Allocate matrix buffer
1450
2633
 
1451
- this.hideSignUp = false;
1452
- this.newFormFields = [];
1453
- /* Whether or not the sign-in component is loading */
2634
+ var moduleCount = utils.getSymbolSize(version$1);
2635
+ var modules = new bitMatrix(moduleCount); // Add function modules
1454
2636
 
1455
- this.loading = false;
1456
- this.phoneNumber = {
1457
- countryDialCodeValue: _constants_c8ecaa24_js__WEBPACK_IMPORTED_MODULE_5__["g"],
1458
- phoneNumberValue: null
1459
- };
1460
- this.signInAttributes = {
1461
- userInput: '',
1462
- password: ''
1463
- };
1464
- }
2637
+ setupFinderPattern(modules, version$1);
2638
+ setupTimingPattern(modules);
2639
+ setupAlignmentPattern(modules, version$1); // Add temporary dummy bits for format info just to set them as reserved.
2640
+ // This is needed to prevent these bits from being masked by {@link MaskPattern.applyMask}
2641
+ // since the masking operation must be performed only on the encoding region.
2642
+ // These blocks will be replaced with correct values later in code.
1465
2643
 
1466
- class_5.prototype.componentWillLoad = function () {
1467
- Object(_helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["c"])(this.usernameAlias);
1468
- this.buildFormFields();
1469
- };
2644
+ setupFormatInfo(modules, errorCorrectionLevel, 0);
1470
2645
 
1471
- class_5.prototype.formFieldsHandler = function () {
1472
- this.buildFormFields();
1473
- };
2646
+ if (version$1 >= 7) {
2647
+ setupVersionInfo(modules, version$1);
2648
+ } // Add data codewords
1474
2649
 
1475
- class_5.prototype.handleFormFieldInputChange = function (fieldType) {
1476
- var _this = this;
1477
2650
 
1478
- switch (fieldType) {
1479
- case 'username':
1480
- case 'email':
1481
- return function (event) {
1482
- return _this.signInAttributes.userInput = event.target.value;
1483
- };
2651
+ setupData(modules, dataBits);
1484
2652
 
1485
- case 'phone_number':
1486
- return function (event) {
1487
- return Object(_helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["h"])(event, _this.phoneNumber);
1488
- };
2653
+ if (isNaN(maskPattern$1)) {
2654
+ // Find best mask pattern
2655
+ maskPattern$1 = maskPattern.getBestMask(modules, setupFormatInfo.bind(null, modules, errorCorrectionLevel));
2656
+ } // Apply mask pattern
1489
2657
 
1490
- case 'password':
1491
- return function (event) {
1492
- return _this.signInAttributes.password = event.target.value;
1493
- };
1494
2658
 
1495
- default:
1496
- return function () {};
1497
- }
1498
- };
2659
+ maskPattern.applyMask(maskPattern$1, modules); // Replace format info bits with correct values
1499
2660
 
1500
- class_5.prototype.handleFormFieldInputWithCallback = function (event, field) {
1501
- var fnToCall = field['handleInputChange'] ? field['handleInputChange'] : function (event, cb) {
1502
- cb(event);
1503
- };
1504
- var callback = this.handleFormFieldInputChange(field.type);
1505
- fnToCall(event, callback.bind(this));
2661
+ setupFormatInfo(modules, errorCorrectionLevel, maskPattern$1);
2662
+ return {
2663
+ modules: modules,
2664
+ version: version$1,
2665
+ errorCorrectionLevel: errorCorrectionLevel,
2666
+ maskPattern: maskPattern$1,
2667
+ segments: segments$1
1506
2668
  };
2669
+ }
2670
+ /**
2671
+ * QR Code
2672
+ *
2673
+ * @param {String | Array} data Input data
2674
+ * @param {Object} options Optional configurations
2675
+ * @param {Number} options.version QR Code version
2676
+ * @param {String} options.errorCorrectionLevel Error correction level
2677
+ * @param {Function} options.toSJISFunc Helper func to convert utf8 to sjis
2678
+ */
2679
+
2680
+
2681
+ var create = function create(data, options) {
2682
+ if (typeof data === 'undefined' || data === '') {
2683
+ throw new Error('No input text');
2684
+ }
1507
2685
 
1508
- class_5.prototype.signIn = function (event) {
1509
- return __awaiter(this, void 0, void 0, function () {
1510
- var username;
1511
- return __generator(this, function (_a) {
1512
- switch (_a.label) {
1513
- case 0:
1514
- // avoid submitting the form
1515
- if (event) {
1516
- event.preventDefault();
1517
- }
2686
+ var errorCorrectionLevel$1 = errorCorrectionLevel.M;
2687
+ var version$1;
2688
+ var mask;
1518
2689
 
1519
- this.loading = true;
2690
+ if (typeof options !== 'undefined') {
2691
+ // Use higher error correction level as default
2692
+ errorCorrectionLevel$1 = errorCorrectionLevel.from(options.errorCorrectionLevel, errorCorrectionLevel.M);
2693
+ version$1 = version.from(options.version);
2694
+ mask = maskPattern.from(options.maskPattern);
1520
2695
 
1521
- switch (this.usernameAlias) {
1522
- case 'phone_number':
1523
- try {
1524
- this.signInAttributes.userInput = Object(_helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["b"])(this.phoneNumber);
1525
- } catch (error) {
1526
- Object(_helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["a"])(error);
1527
- }
2696
+ if (options.toSJISFunc) {
2697
+ utils.setToSJISFunction(options.toSJISFunc);
2698
+ }
2699
+ }
1528
2700
 
1529
- }
2701
+ return createSymbol(data, version$1, errorCorrectionLevel$1, mask);
2702
+ };
1530
2703
 
1531
- username = this.signInAttributes.userInput.trim();
1532
- return [4
1533
- /*yield*/
1534
- , Object(_auth_helpers_557b83fc_js__WEBPACK_IMPORTED_MODULE_7__["h"])(username, this.signInAttributes.password, this.handleAuthStateChange, this.usernameAlias)];
2704
+ var qrcode = {
2705
+ create: create
2706
+ };
2707
+ var utils$1 = createCommonjsModule(function (module, exports) {
2708
+ function hex2rgba(hex) {
2709
+ if (typeof hex === 'number') {
2710
+ hex = hex.toString();
2711
+ }
1535
2712
 
1536
- case 1:
1537
- _a.sent();
2713
+ if (typeof hex !== 'string') {
2714
+ throw new Error('Color should be defined as hex string');
2715
+ }
1538
2716
 
1539
- this.loading = false;
1540
- return [2
1541
- /*return*/
1542
- ];
1543
- }
1544
- });
1545
- });
1546
- };
2717
+ var hexCode = hex.slice().replace('#', '').split('');
1547
2718
 
1548
- class_5.prototype.buildDefaultFormFields = function () {
1549
- var _this = this;
2719
+ if (hexCode.length < 3 || hexCode.length === 5 || hexCode.length > 8) {
2720
+ throw new Error('Invalid hex color: ' + hex);
2721
+ } // Convert from short to long form (fff -> ffffff)
1550
2722
 
1551
- var formFieldInputs = [];
1552
-
1553
- switch (this.usernameAlias) {
1554
- case 'email':
1555
- formFieldInputs.push({
1556
- type: 'email',
1557
- required: true,
1558
- handleInputChange: this.handleFormFieldInputChange('email'),
1559
- inputProps: {
1560
- 'data-test': 'sign-in-email-input',
1561
- autocomplete: 'username'
1562
- }
1563
- });
1564
- break;
1565
2723
 
1566
- case 'phone_number':
1567
- formFieldInputs.push({
1568
- type: 'phone_number',
1569
- required: true,
1570
- handleInputChange: this.handleFormFieldInputChange('phone_number'),
1571
- inputProps: {
1572
- 'data-test': 'sign-in-phone-number-input',
1573
- autocomplete: 'username'
1574
- }
1575
- });
1576
- break;
2724
+ if (hexCode.length === 3 || hexCode.length === 4) {
2725
+ hexCode = Array.prototype.concat.apply([], hexCode.map(function (c) {
2726
+ return [c, c];
2727
+ }));
2728
+ } // Add default alpha value
1577
2729
 
1578
- case 'username':
1579
- default:
1580
- formFieldInputs.push({
1581
- type: 'username',
1582
- required: true,
1583
- handleInputChange: this.handleFormFieldInputChange('username'),
1584
- inputProps: {
1585
- 'data-test': 'sign-in-username-input',
1586
- autocomplete: 'username'
1587
- }
1588
- });
1589
- break;
1590
- }
1591
2730
 
1592
- formFieldInputs.push({
1593
- type: 'password',
1594
- hint: Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("div", null, _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].FORGOT_PASSWORD_TEXT), ' ', Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-button", {
1595
- variant: "anchor",
1596
- onClick: function onClick() {
1597
- return _this.handleAuthStateChange(_auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_2__["A"].ForgotPassword);
1598
- },
1599
- "data-test": "sign-in-forgot-password-link"
1600
- }, _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].RESET_PASSWORD_TEXT))),
1601
- required: true,
1602
- handleInputChange: this.handleFormFieldInputChange('password'),
1603
- inputProps: {
1604
- 'data-test': 'sign-in-password-input'
1605
- }
1606
- });
1607
- this.newFormFields = __spreadArrays(formFieldInputs);
1608
- };
2731
+ if (hexCode.length === 6) hexCode.push('F', 'F');
2732
+ var hexValue = parseInt(hexCode.join(''), 16);
2733
+ return {
2734
+ r: hexValue >> 24 & 255,
2735
+ g: hexValue >> 16 & 255,
2736
+ b: hexValue >> 8 & 255,
2737
+ a: hexValue & 255,
2738
+ hex: '#' + hexCode.slice(0, 6).join('')
2739
+ };
2740
+ }
1609
2741
 
1610
- class_5.prototype.buildFormFields = function () {
1611
- var _this = this;
2742
+ exports.getOptions = function getOptions(options) {
2743
+ if (!options) options = {};
2744
+ if (!options.color) options.color = {};
2745
+ var margin = typeof options.margin === 'undefined' || options.margin === null || options.margin < 0 ? 4 : options.margin;
2746
+ var width = options.width && options.width >= 21 ? options.width : undefined;
2747
+ var scale = options.scale || 4;
2748
+ return {
2749
+ width: width,
2750
+ scale: width ? 4 : scale,
2751
+ margin: margin,
2752
+ color: {
2753
+ dark: hex2rgba(options.color.dark || '#000000ff'),
2754
+ light: hex2rgba(options.color.light || '#ffffffff')
2755
+ },
2756
+ type: options.type,
2757
+ rendererOpts: options.rendererOpts || {}
2758
+ };
2759
+ };
1612
2760
 
1613
- if (this.formFields.length === 0) {
1614
- this.buildDefaultFormFields();
1615
- } else {
1616
- var newFields_3 = [];
1617
- this.formFields.forEach(function (field) {
1618
- var newField = Object.assign({}, field); // TODO: handle hint better
1619
-
1620
- if (newField.type === 'password') {
1621
- newField['hint'] = Object(_helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["i"])(newField) ? Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("div", null, _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].FORGOT_PASSWORD_TEXT), ' ', Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-button", {
1622
- variant: "anchor",
1623
- onClick: function onClick() {
1624
- return _this.handleAuthStateChange(_auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_2__["A"].ForgotPassword);
1625
- },
1626
- "data-test": "sign-in-forgot-password-link"
1627
- }, _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].RESET_PASSWORD_TEXT))) : newField['hint'];
1628
- }
2761
+ exports.getScale = function getScale(qrSize, opts) {
2762
+ return opts.width && opts.width >= qrSize + opts.margin * 2 ? opts.width / (qrSize + opts.margin * 2) : opts.scale;
2763
+ };
1629
2764
 
1630
- newField['handleInputChange'] = function (event) {
1631
- return _this.handleFormFieldInputWithCallback(event, field);
1632
- };
2765
+ exports.getImageWidth = function getImageWidth(qrSize, opts) {
2766
+ var scale = exports.getScale(qrSize, opts);
2767
+ return Math.floor((qrSize + opts.margin * 2) * scale);
2768
+ };
1633
2769
 
1634
- _this.setFieldValue(newField, _this.signInAttributes);
2770
+ exports.qrToImageData = function qrToImageData(imgData, qr, opts) {
2771
+ var size = qr.modules.size;
2772
+ var data = qr.modules.data;
2773
+ var scale = exports.getScale(size, opts);
2774
+ var symbolSize = Math.floor((size + opts.margin * 2) * scale);
2775
+ var scaledMargin = opts.margin * scale;
2776
+ var palette = [opts.color.light, opts.color.dark];
1635
2777
 
1636
- newFields_3.push(newField);
1637
- });
1638
- this.newFormFields = newFields_3;
1639
- }
1640
- };
2778
+ for (var i = 0; i < symbolSize; i++) {
2779
+ for (var j = 0; j < symbolSize; j++) {
2780
+ var posDst = (i * symbolSize + j) * 4;
2781
+ var pxColor = opts.color.light;
1641
2782
 
1642
- class_5.prototype.setFieldValue = function (field, formAttributes) {
1643
- switch (field.type) {
1644
- case 'username':
1645
- case 'email':
1646
- if (field.value === undefined) {
1647
- formAttributes.userInput = '';
1648
- } else {
1649
- formAttributes.userInput = field.value;
2783
+ if (i >= scaledMargin && j >= scaledMargin && i < symbolSize - scaledMargin && j < symbolSize - scaledMargin) {
2784
+ var iSrc = Math.floor((i - scaledMargin) / scale);
2785
+ var jSrc = Math.floor((j - scaledMargin) / scale);
2786
+ pxColor = palette[data[iSrc * size + jSrc] ? 1 : 0];
1650
2787
  }
1651
2788
 
1652
- break;
2789
+ imgData[posDst++] = pxColor.r;
2790
+ imgData[posDst++] = pxColor.g;
2791
+ imgData[posDst++] = pxColor.b;
2792
+ imgData[posDst] = pxColor.a;
2793
+ }
2794
+ }
2795
+ };
2796
+ });
2797
+ var canvas = createCommonjsModule(function (module, exports) {
2798
+ function clearCanvas(ctx, canvas, size) {
2799
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
2800
+ if (!canvas.style) canvas.style = {};
2801
+ canvas.height = size;
2802
+ canvas.width = size;
2803
+ canvas.style.height = size + 'px';
2804
+ canvas.style.width = size + 'px';
2805
+ }
1653
2806
 
1654
- case 'phone_number':
1655
- if (field.dialCode) {
1656
- this.phoneNumber.countryDialCodeValue = field.dialCode;
1657
- }
2807
+ function getCanvasElement() {
2808
+ try {
2809
+ return document.createElement('canvas');
2810
+ } catch (e) {
2811
+ throw new Error('You need to specify a canvas element');
2812
+ }
2813
+ }
1658
2814
 
1659
- this.phoneNumber.phoneNumberValue = field.value;
1660
- break;
2815
+ exports.render = function render(qrData, canvas, options) {
2816
+ var opts = options;
2817
+ var canvasEl = canvas;
1661
2818
 
1662
- case 'password':
1663
- if (field.value === undefined) {
1664
- formAttributes.password = '';
1665
- } else {
1666
- formAttributes.password = field.value;
1667
- }
2819
+ if (typeof opts === 'undefined' && (!canvas || !canvas.getContext)) {
2820
+ opts = canvas;
2821
+ canvas = undefined;
2822
+ }
1668
2823
 
1669
- break;
2824
+ if (!canvas) {
2825
+ canvasEl = getCanvasElement();
1670
2826
  }
2827
+
2828
+ opts = utils$1.getOptions(opts);
2829
+ var size = utils$1.getImageWidth(qrData.modules.size, opts);
2830
+ var ctx = canvasEl.getContext('2d');
2831
+ var image = ctx.createImageData(size, size);
2832
+ utils$1.qrToImageData(image.data, qrData, opts);
2833
+ clearCanvas(ctx, canvasEl, size);
2834
+ ctx.putImageData(image, 0, 0);
2835
+ return canvasEl;
1671
2836
  };
1672
2837
 
1673
- class_5.prototype.render = function () {
1674
- var _this = this;
2838
+ exports.renderToDataURL = function renderToDataURL(qrData, canvas, options) {
2839
+ var opts = options;
1675
2840
 
1676
- return Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["H"], null, Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-form-section", {
1677
- headerText: _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(this.headerText),
1678
- handleSubmit: this.handleSubmit,
1679
- testDataPrefix: 'sign-in'
1680
- }, Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("div", {
1681
- slot: "subtitle"
1682
- }, Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("slot", {
1683
- name: "header-subtitle"
1684
- })), Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("slot", {
1685
- name: "federated-buttons"
1686
- }, Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-federated-buttons", {
1687
- handleAuthStateChange: this.handleAuthStateChange,
1688
- federated: this.federated
1689
- })), !Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["isEmpty"])(this.federated) && Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-strike", null, "or"), Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-auth-fields", {
1690
- formFields: this.newFormFields
1691
- }), Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("div", {
1692
- slot: "amplify-form-section-footer",
1693
- "class": "sign-in-form-footer"
1694
- }, Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("slot", {
1695
- name: "footer"
1696
- }, !this.hideSignUp && Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("slot", {
1697
- name: "secondary-footer-content"
1698
- }, Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("span", null, _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].NO_ACCOUNT_TEXT), ' ', Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-button", {
1699
- variant: "anchor",
1700
- onClick: function onClick() {
1701
- return _this.handleAuthStateChange(_auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_2__["A"].SignUp);
1702
- },
1703
- "data-test": "sign-in-create-account-link"
1704
- }, _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].CREATE_ACCOUNT_TEXT)))), Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("div", {
1705
- "class": this.hideSignUp ? 'full-width-footer-content' : ''
1706
- }, Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("slot", {
1707
- name: "primary-footer-content"
1708
- }, Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-button", {
1709
- type: "submit",
1710
- disabled: this.loading,
1711
- "data-test": "sign-in-sign-in-button"
1712
- }, this.loading ? Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-loading-spinner", null) : Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("span", null, _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(this.submitButtonText)))))))));
2841
+ if (typeof opts === 'undefined' && (!canvas || !canvas.getContext)) {
2842
+ opts = canvas;
2843
+ canvas = undefined;
2844
+ }
2845
+
2846
+ if (!opts) opts = {};
2847
+ var canvasEl = exports.render(qrData, canvas, opts);
2848
+ var type = opts.type || 'image/png';
2849
+ var rendererOpts = opts.rendererOpts || {};
2850
+ return canvasEl.toDataURL(type, rendererOpts.quality);
1713
2851
  };
2852
+ });
1714
2853
 
1715
- Object.defineProperty(class_5, "watchers", {
1716
- get: function get() {
1717
- return {
1718
- "formFields": ["formFieldsHandler"]
1719
- };
1720
- },
1721
- enumerable: false,
1722
- configurable: true
1723
- });
1724
- return class_5;
1725
- }();
2854
+ function getColorAttrib(color, attrib) {
2855
+ var alpha = color.a / 255;
2856
+ var str = attrib + '="' + color.hex + '"';
2857
+ return alpha < 1 ? str + ' ' + attrib + '-opacity="' + alpha.toFixed(2).slice(1) + '"' : str;
2858
+ }
1726
2859
 
1727
- AmplifySignIn.style = amplifySignInCss;
1728
- var amplifySignUpCss = "amplify-sign-up{--footer-font-family:var(--amplify-font-family);--footer-font-size:var(--amplify-text-sm);--footer-color:var(--amplify-grey);--font-weight:var(--amplify-font-weight)}.sign-up-form-footer{font-family:var(--footer-font-family);font-size:var(--footer-font-size);color:var(--footer-color);font-weight:--font-weight;display:-ms-flexbox;display:flex;-ms-flex-direction:column-reverse;flex-direction:column-reverse;-ms-flex-align:center;align-items:center;-ms-flex-pack:distribute;justify-content:space-around}.sign-up-form-footer amplify-button{margin-bottom:0.625rem}@media (min-width: 672px){.sign-up-form-footer{display:-ms-flexbox;display:flex;-ms-flex-direction:row;flex-direction:row;-ms-flex-pack:justify;justify-content:space-between;-ms-flex-align:baseline;align-items:baseline}.sign-up-form-footer amplify-button{margin-bottom:0}}.sign-up-form-footer *+*{margin-bottom:15px}";
2860
+ function svgCmd(cmd, x, y) {
2861
+ var str = cmd + x;
2862
+ if (typeof y !== 'undefined') str += ' ' + y;
2863
+ return str;
2864
+ }
1729
2865
 
1730
- var AmplifySignUp =
1731
- /** @class */
1732
- function () {
1733
- function class_6(hostRef) {
1734
- var _this = this;
2866
+ function qrToPath(data, size, margin) {
2867
+ var path = '';
2868
+ var moveBy = 0;
2869
+ var newRow = false;
2870
+ var lineLength = 0;
1735
2871
 
1736
- Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["r"])(this, hostRef);
1737
- /** Fires when sign up form is submitted */
2872
+ for (var i = 0; i < data.length; i++) {
2873
+ var col = Math.floor(i % size);
2874
+ var row = Math.floor(i / size);
2875
+ if (!col && !newRow) newRow = true;
1738
2876
 
1739
- this.handleSubmit = function (event) {
1740
- return _this.signUp(event);
1741
- };
1742
- /** Override for handling the Auth.SignUp API call */
2877
+ if (data[i]) {
2878
+ lineLength++;
1743
2879
 
2880
+ if (!(i > 0 && col > 0 && data[i - 1])) {
2881
+ path += newRow ? svgCmd('M', col + margin, 0.5 + row + margin) : svgCmd('m', moveBy, 0);
2882
+ moveBy = 0;
2883
+ newRow = false;
2884
+ }
1744
2885
 
1745
- this.handleSignUp = function (params) {
1746
- return _this.authSignUp(params);
1747
- };
1748
- /** Used for header text in sign up component */
2886
+ if (!(col + 1 < size && data[i + 1])) {
2887
+ path += svgCmd('h', lineLength);
2888
+ lineLength = 0;
2889
+ }
2890
+ } else {
2891
+ moveBy++;
2892
+ }
2893
+ }
1749
2894
 
2895
+ return path;
2896
+ }
2897
+
2898
+ var render = function render(qrData, options, cb) {
2899
+ var opts = utils$1.getOptions(options);
2900
+ var size = qrData.modules.size;
2901
+ var data = qrData.modules.data;
2902
+ var qrcodesize = size + opts.margin * 2;
2903
+ var bg = !opts.color.light.a ? '' : '<path ' + getColorAttrib(opts.color.light, 'fill') + ' d="M0 0h' + qrcodesize + 'v' + qrcodesize + 'H0z"/>';
2904
+ var path = '<path ' + getColorAttrib(opts.color.dark, 'stroke') + ' d="' + qrToPath(data, size, opts.margin) + '"/>';
2905
+ var viewBox = 'viewBox="' + '0 0 ' + qrcodesize + ' ' + qrcodesize + '"';
2906
+ var width = !opts.width ? '' : 'width="' + opts.width + '" height="' + opts.width + '" ';
2907
+ var svgTag = '<svg xmlns="http://www.w3.org/2000/svg" ' + width + viewBox + ' shape-rendering="crispEdges">' + bg + path + '</svg>\n';
2908
+
2909
+ if (typeof cb === 'function') {
2910
+ cb(null, svgTag);
2911
+ }
1750
2912
 
1751
- this.headerText = _Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].SIGN_UP_HEADER_TEXT;
1752
- /** Used for the submit button text in sign up component */
2913
+ return svgTag;
2914
+ };
1753
2915
 
1754
- this.submitButtonText = _Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].SIGN_UP_SUBMIT_BUTTON_TEXT;
1755
- /** Used for the submit button text in sign up component */
2916
+ var svgTag = {
2917
+ render: render
2918
+ };
1756
2919
 
1757
- this.haveAccountText = _Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].SIGN_UP_HAVE_ACCOUNT_TEXT;
1758
- /** Text used for the sign in hyperlink */
2920
+ function renderCanvas(renderFunc, canvas, text, opts, cb) {
2921
+ var args = [].slice.call(arguments, 1);
2922
+ var argsNum = args.length;
2923
+ var isLastArgCb = typeof args[argsNum - 1] === 'function';
1759
2924
 
1760
- this.signInText = _Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].SIGN_IN_TEXT;
1761
- /**
1762
- * Form fields allows you to utilize our pre-built components such as username field, code field, password field, email field, etc.
1763
- * by passing an array of strings that you would like the order of the form to be in. If you need more customization, such as changing
1764
- * text for a label or adjust a placeholder, you can follow the structure below in order to do just that.
1765
- * ```
1766
- * [
1767
- * {
1768
- * type: string,
1769
- * label: string,
1770
- * placeholder: string,
1771
- * hint: string | Functional Component | null,
1772
- * required: boolean
1773
- * }
1774
- * ]
1775
- * ```
1776
- */
2925
+ if (!isLastArgCb && !canPromise()) {
2926
+ throw new Error('Callback required as last argument');
2927
+ }
1777
2928
 
1778
- this.formFields = [];
1779
- /** Auth state change handler for this component
1780
- * e.g. SignIn -> 'Create Account' link -> SignUp
1781
- */
1782
- // prettier-ignore
2929
+ if (isLastArgCb) {
2930
+ if (argsNum < 2) {
2931
+ throw new Error('Too few arguments provided');
2932
+ }
1783
2933
 
1784
- this.handleAuthStateChange = _helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["d"];
1785
- /** Username Alias is used to setup authentication with `username`, `email` or `phone_number` */
2934
+ if (argsNum === 2) {
2935
+ cb = text;
2936
+ text = canvas;
2937
+ canvas = opts = undefined;
2938
+ } else if (argsNum === 3) {
2939
+ if (canvas.getContext && typeof cb === 'undefined') {
2940
+ cb = opts;
2941
+ opts = undefined;
2942
+ } else {
2943
+ cb = opts;
2944
+ opts = text;
2945
+ text = canvas;
2946
+ canvas = undefined;
2947
+ }
2948
+ }
2949
+ } else {
2950
+ if (argsNum < 1) {
2951
+ throw new Error('Too few arguments provided');
2952
+ }
1786
2953
 
1787
- this.usernameAlias = 'username'; // private userInput: string | PhoneNumberInterface;
2954
+ if (argsNum === 1) {
2955
+ text = canvas;
2956
+ canvas = opts = undefined;
2957
+ } else if (argsNum === 2 && !canvas.getContext) {
2958
+ opts = text;
2959
+ text = canvas;
2960
+ canvas = undefined;
2961
+ }
1788
2962
 
1789
- this.newFormFields = [];
1790
- this.phoneNumber = {
1791
- countryDialCodeValue: _constants_c8ecaa24_js__WEBPACK_IMPORTED_MODULE_5__["g"],
1792
- phoneNumberValue: null
1793
- };
1794
- this.loading = false;
1795
- this.signUpAttributes = {
1796
- username: '',
1797
- password: '',
1798
- attributes: {}
1799
- };
2963
+ return new Promise(function (resolve, reject) {
2964
+ try {
2965
+ var data = qrcode.create(text, opts);
2966
+ resolve(renderFunc(data, canvas, opts));
2967
+ } catch (e) {
2968
+ reject(e);
2969
+ }
2970
+ });
1800
2971
  }
1801
2972
 
1802
- class_6.prototype.handleFormFieldInputChange = function (fieldType) {
1803
- var _this = this;
1804
-
1805
- switch (fieldType) {
1806
- case 'username':
1807
- return function (event) {
1808
- return _this.signUpAttributes.username = event.target.value;
1809
- };
2973
+ try {
2974
+ var data = qrcode.create(text, opts);
2975
+ cb(null, renderFunc(data, canvas, opts));
2976
+ } catch (e) {
2977
+ cb(e);
2978
+ }
2979
+ }
1810
2980
 
1811
- case 'password':
1812
- return function (event) {
1813
- return _this.signUpAttributes.password = event.target.value;
1814
- };
2981
+ var create$1 = qrcode.create;
2982
+ var toCanvas = renderCanvas.bind(null, canvas.render);
2983
+ var toDataURL = renderCanvas.bind(null, canvas.renderToDataURL); // only svg for now.
2984
+
2985
+ var toString_1 = renderCanvas.bind(null, function (data, _, opts) {
2986
+ return svgTag.render(data, opts);
2987
+ });
2988
+ var browser = {
2989
+ create: create$1,
2990
+ toCanvas: toCanvas,
2991
+ toDataURL: toDataURL,
2992
+ toString: toString_1
2993
+ };
2994
+ var amplifyTotpSetupCss = ".totp-setup{text-align:center;margin-bottom:30px}.totp-setup img{height:128px;width:128px}";
2995
+ var logger = new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["Logger"]('TOTP');
1815
2996
 
1816
- case 'email':
1817
- return function (event) {
1818
- return _this.signUpAttributes.attributes.email = event.target.value;
1819
- };
2997
+ var AmplifyTOTPSetup =
2998
+ /** @class */
2999
+ function () {
3000
+ function class_1(hostRef) {
3001
+ Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["r"])(this, hostRef);
3002
+ this.inputProps = {
3003
+ autoFocus: true
3004
+ };
3005
+ /** Auth state change handler for this component */
1820
3006
 
1821
- case 'phone_number':
1822
- return function (event) {
1823
- return Object(_helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["h"])(event, _this.phoneNumber);
1824
- };
3007
+ this.handleAuthStateChange = _helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["d"];
3008
+ /** Used for header text in totp setup component */
1825
3009
 
1826
- default:
1827
- return function (event) {
1828
- return _this.signUpAttributes.attributes[fieldType] = event.target.value;
1829
- };
1830
- }
1831
- };
3010
+ this.headerText = _Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].TOTP_HEADER_TEXT;
3011
+ /** Used for customizing the issuer string in the qr code image */
1832
3012
 
1833
- class_6.prototype.handleFormFieldInputWithCallback = function (event, field) {
1834
- var fnToCall = field['handleInputChange'] ? field['handleInputChange'] : function (event, cb) {
1835
- cb(event);
1836
- };
1837
- var callback = this.handleFormFieldInputChange(field.type);
1838
- fnToCall(event, callback.bind(this));
1839
- };
3013
+ this.issuer = _Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].TOTP_ISSUER;
3014
+ /** This is run after totp setup is complete. Useful if using this as standalone. */
3015
+
3016
+ this.handleComplete = this.onTOTPEvent;
3017
+ /** Set this to true if this component is running outside the default `amplify-authenticator` usage */
3018
+
3019
+ this.standalone = false;
3020
+ this.code = null;
3021
+ this.setupMessage = null;
3022
+ this.qrCodeInput = null;
3023
+ this.loading = false;
3024
+ }
1840
3025
 
1841
- class_6.prototype.authSignUp = function (params) {
3026
+ class_1.prototype.componentWillLoad = function () {
1842
3027
  return __awaiter(this, void 0, void 0, function () {
1843
- var data;
3028
+ var _this = this;
3029
+
1844
3030
  return __generator(this, function (_a) {
1845
3031
  switch (_a.label) {
1846
3032
  case 0:
3033
+ console.warn('Version `1.x` of Amplify UI has been deprecated and will be removed in a future major version of `aws-amplify`. Please visit https://ui.docs.amplify.aws/ for the current version of Amplify UI.');
3034
+ /**
3035
+ * If this component is being used internally by the authenticator, we want to re-run
3036
+ * setup only when the current auth state is `AuthState.TOTPSetup`.
3037
+ *
3038
+ * Ideally, we would only run the setup once when the component is mounted. This is not possible
3039
+ * due to a bug with slots -- a slotted component will run its `componentWillLoad` lifecycle before
3040
+ * it is even rendered. So instead we watch for authstate changes and run setup conditionally.
3041
+ */
3042
+
3043
+ if (!this.standalone) {
3044
+ this.removeHubListener = Object(_helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["o"])(function (authState) {
3045
+ if (authState === _auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_2__["A"].TOTPSetup) _this.setup();
3046
+ });
3047
+ }
3048
+
1847
3049
  return [4
1848
3050
  /*yield*/
1849
- , _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"].signUp(params)];
3051
+ , this.setup()];
1850
3052
 
1851
3053
  case 1:
1852
- data = _a.sent();
1853
-
1854
- if (!data) {
1855
- throw new Error(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].SIGN_UP_FAILED);
1856
- }
3054
+ _a.sent();
1857
3055
 
1858
3056
  return [2
1859
3057
  /*return*/
1860
- , data];
3058
+ ];
1861
3059
  }
1862
3060
  });
1863
3061
  });
1864
3062
  };
3063
+ /**
3064
+ * If this component is being used externally, we can use `@Watch` as normal.
3065
+ */
1865
3066
 
1866
- class_6.prototype.assignPhoneNumberToSignUpAttributes = function () {
1867
- if (this.phoneNumber.phoneNumberValue) {
1868
- try {
1869
- this.signUpAttributes.attributes.phone_number = Object(_helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["b"])(this.phoneNumber);
1870
- } catch (error) {
1871
- Object(_helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["a"])(error);
1872
- }
1873
- }
1874
- };
1875
3067
 
1876
- class_6.prototype.assignUserNameAliasToSignUpAttributes = function () {
1877
- switch (this.usernameAlias) {
1878
- case 'email':
1879
- case 'phone_number':
1880
- this.signUpAttributes.username = this.signUpAttributes.attributes[this.usernameAlias];
1881
- break;
1882
- }
3068
+ class_1.prototype.handleUserChange = function () {
3069
+ this.standalone && this.setup();
1883
3070
  };
1884
3071
 
1885
- class_6.prototype.assignFormInputToSignUpAttributes = function () {
1886
- this.assignPhoneNumberToSignUpAttributes();
1887
- this.assignUserNameAliasToSignUpAttributes();
3072
+ class_1.prototype.disconnectedCallback = function () {
3073
+ this.removeHubListener && this.removeHubListener(); // stop listening to `onAuthUIStateChange`
1888
3074
  };
1889
3075
 
1890
- class_6.prototype.validateSignUpAttributes = function () {
1891
- if (!this.signUpAttributes.username) {
1892
- if (this.usernameAlias === _auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_2__["U"].email) {
1893
- throw new Error(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].EMPTY_EMAIL);
1894
- } else if (this.usernameAlias === _auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_2__["U"].phone_number) {
1895
- throw new Error(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].EMPTY_PHONE);
1896
- } else {
1897
- throw new Error(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].EMPTY_USERNAME);
1898
- }
1899
- }
1900
-
1901
- if (this.signUpAttributes.username.indexOf(' ') >= 0) {
1902
- throw new Error(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].USERNAME_REMOVE_WHITESPACE);
1903
- }
1904
-
1905
- if (this.signUpAttributes.password !== this.signUpAttributes.password.trim()) {
1906
- throw new Error(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].PASSWORD_REMOVE_WHITESPACE);
1907
- }
1908
- }; // TODO: Add validation
1909
- // TODO: Prefix
1910
-
3076
+ class_1.prototype.buildOtpAuthPath = function (user, issuer, secretKey) {
3077
+ return "otpauth://totp/" + issuer + ":" + user.username + "?secret=" + secretKey + "&issuer=" + issuer;
3078
+ };
1911
3079
 
1912
- class_6.prototype.signUp = function (event) {
3080
+ class_1.prototype.onTOTPEvent = function (user) {
1913
3081
  return __awaiter(this, void 0, void 0, function () {
1914
- var data, signUpAttrs, error_8;
1915
3082
  return __generator(this, function (_a) {
1916
3083
  switch (_a.label) {
1917
3084
  case 0:
1918
- if (event) {
1919
- event.preventDefault();
1920
- }
1921
-
1922
- if (!_aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"] || typeof _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"].signUp !== 'function') {
1923
- throw new Error(_constants_c8ecaa24_js__WEBPACK_IMPORTED_MODULE_5__["N"]);
1924
- }
1925
-
1926
- this.loading = true;
1927
- this.assignFormInputToSignUpAttributes();
1928
- _a.label = 1;
1929
-
1930
- case 1:
1931
- _a.trys.push([1, 6, 7, 8]);
1932
-
1933
- this.validateSignUpAttributes();
1934
- return [4
1935
- /*yield*/
1936
- , this.handleSignUp(this.signUpAttributes)];
1937
-
1938
- case 2:
1939
- data = _a.sent();
1940
- if (!data.userConfirmed) return [3
1941
- /*break*/
1942
- , 4];
3085
+ logger.debug('on totp event');
1943
3086
  return [4
1944
3087
  /*yield*/
1945
- , Object(_auth_helpers_557b83fc_js__WEBPACK_IMPORTED_MODULE_7__["h"])(this.signUpAttributes.username, this.signUpAttributes.password, this.handleAuthStateChange)];
3088
+ , Object(_auth_helpers_557b83fc_js__WEBPACK_IMPORTED_MODULE_7__["c"])(user, this.handleAuthStateChange)];
1946
3089
 
1947
- case 3:
3090
+ case 1:
1948
3091
  _a.sent();
1949
3092
 
1950
- return [3
1951
- /*break*/
1952
- , 5];
1953
-
1954
- case 4:
1955
- signUpAttrs = Object.assign({}, this.signUpAttributes);
1956
- this.handleAuthStateChange(_auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_2__["A"].ConfirmSignUp, Object.assign(Object.assign({}, data.user), {
1957
- signUpAttrs: signUpAttrs
1958
- }));
1959
- _a.label = 5;
1960
-
1961
- case 5:
1962
- return [3
1963
- /*break*/
1964
- , 8];
1965
-
1966
- case 6:
1967
- error_8 = _a.sent();
1968
- Object(_helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["a"])(error_8);
1969
- return [3
1970
- /*break*/
1971
- , 8];
1972
-
1973
- case 7:
1974
- this.loading = false;
1975
- return [7
1976
- /*endfinally*/
1977
- ];
1978
-
1979
- case 8:
1980
3093
  return [2
1981
3094
  /*return*/
1982
3095
  ];
@@ -1985,255 +3098,74 @@ function () {
1985
3098
  });
1986
3099
  };
1987
3100
 
1988
- class_6.prototype.buildDefaultFormFields = function () {
1989
- switch (this.usernameAlias) {
1990
- case 'email':
1991
- this.newFormFields = [{
1992
- type: 'email',
1993
- placeholder: _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].SIGN_UP_EMAIL_PLACEHOLDER),
1994
- required: true,
1995
- handleInputChange: this.handleFormFieldInputChange('email'),
1996
- inputProps: {
1997
- 'data-test': 'sign-up-email-input',
1998
- autocomplete: 'username'
1999
- }
2000
- }, {
2001
- type: 'password',
2002
- placeholder: _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].SIGN_UP_PASSWORD_PLACEHOLDER),
2003
- required: true,
2004
- handleInputChange: this.handleFormFieldInputChange('password'),
2005
- inputProps: {
2006
- 'data-test': 'sign-up-password-input',
2007
- autocomplete: 'new-password'
2008
- }
2009
- }, {
2010
- type: 'phone_number',
2011
- required: true,
2012
- handleInputChange: this.handleFormFieldInputChange('phone_number'),
2013
- inputProps: {
2014
- 'data-test': 'sign-up-phone-number-input',
2015
- autocomplete: 'tel-national'
2016
- }
2017
- }];
2018
- break;
2019
-
2020
- case 'phone_number':
2021
- this.newFormFields = [{
2022
- type: 'phone_number',
2023
- required: true,
2024
- handleInputChange: this.handleFormFieldInputChange('phone_number'),
2025
- inputProps: {
2026
- 'data-test': 'sign-up-phone-number-input',
2027
- autocomplete: 'username'
2028
- }
2029
- }, {
2030
- type: 'password',
2031
- placeholder: _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].SIGN_UP_PASSWORD_PLACEHOLDER),
2032
- required: true,
2033
- handleInputChange: this.handleFormFieldInputChange('password'),
2034
- inputProps: {
2035
- 'data-test': 'sign-up-password-input',
2036
- autocomplete: 'new-password'
2037
- }
2038
- }, {
2039
- type: 'email',
2040
- placeholder: _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].SIGN_UP_EMAIL_PLACEHOLDER),
2041
- required: true,
2042
- handleInputChange: this.handleFormFieldInputChange('email'),
2043
- inputProps: {
2044
- 'data-test': 'sign-up-email-input',
2045
- autocomplete: 'email'
2046
- }
2047
- }];
2048
- break;
2049
-
2050
- case 'username':
2051
- default:
2052
- this.newFormFields = [{
2053
- type: 'username',
2054
- placeholder: _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].SIGN_UP_USERNAME_PLACEHOLDER),
2055
- required: true,
2056
- handleInputChange: this.handleFormFieldInputChange('username'),
2057
- inputProps: {
2058
- 'data-test': 'sign-up-username-input',
2059
- autocomplete: 'username'
2060
- }
2061
- }, {
2062
- type: 'password',
2063
- placeholder: _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].SIGN_UP_PASSWORD_PLACEHOLDER),
2064
- required: true,
2065
- handleInputChange: this.handleFormFieldInputChange('password'),
2066
- inputProps: {
2067
- 'data-test': 'sign-up-password-input',
2068
- autocomplete: 'new-password'
2069
- }
2070
- }, {
2071
- type: 'email',
2072
- placeholder: _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].SIGN_UP_EMAIL_PLACEHOLDER),
2073
- required: true,
2074
- handleInputChange: this.handleFormFieldInputChange('email'),
2075
- inputProps: {
2076
- 'data-test': 'sign-up-email-input'
2077
- }
2078
- }, {
2079
- type: 'phone_number',
2080
- required: true,
2081
- handleInputChange: this.handleFormFieldInputChange('phone_number'),
2082
- inputProps: {
2083
- 'data-test': 'sign-up-phone-number-input'
2084
- }
2085
- }];
2086
- break;
2087
- }
2088
- };
2089
-
2090
- class_6.prototype.buildFormFields = function () {
2091
- var _this = this;
2092
-
2093
- if (this.formFields.length === 0) {
2094
- this.buildDefaultFormFields();
2095
- } else {
2096
- var newFields_4 = [];
2097
- this.formFields.forEach(function (field) {
2098
- var newField = Object.assign({}, field);
2099
-
2100
- newField['handleInputChange'] = function (event) {
2101
- return _this.handleFormFieldInputWithCallback(event, field);
2102
- };
2103
-
2104
- _this.setFieldValue(field, _this.signUpAttributes);
2105
-
2106
- newFields_4.push(newField);
2107
- });
2108
- this.newFormFields = newFields_4;
2109
- }
3101
+ class_1.prototype.handleTotpInputChange = function (event) {
3102
+ this.setupMessage = null;
3103
+ this.qrCodeInput = event.target.value;
2110
3104
  };
2111
3105
 
2112
- class_6.prototype.setFieldValue = function (field, formAttributes) {
2113
- switch (field.type) {
2114
- case 'username':
2115
- if (field.value === undefined) {
2116
- formAttributes.username = '';
2117
- } else {
2118
- formAttributes.username = field.value;
2119
- }
3106
+ class_1.prototype.generateQRCode = function (codeFromTotp) {
3107
+ return __awaiter(this, void 0, void 0, function () {
3108
+ var _a, error_1;
2120
3109
 
2121
- break;
3110
+ return __generator(this, function (_b) {
3111
+ switch (_b.label) {
3112
+ case 0:
3113
+ _b.trys.push([0, 2,, 3]);
2122
3114
 
2123
- case 'password':
2124
- if (field.value === undefined) {
2125
- formAttributes.password = '';
2126
- } else {
2127
- formAttributes.password = field.value;
2128
- }
3115
+ _a = this;
3116
+ return [4
3117
+ /*yield*/
3118
+ , browser.toDataURL(codeFromTotp)];
2129
3119
 
2130
- break;
3120
+ case 1:
3121
+ _a.qrCodeImageSource = _b.sent();
3122
+ return [3
3123
+ /*break*/
3124
+ , 3];
2131
3125
 
2132
- case 'email':
2133
- formAttributes.attributes.email = field.value;
2134
- break;
3126
+ case 2:
3127
+ error_1 = _b.sent();
3128
+ Object(_helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["a"])(error_1);
3129
+ return [3
3130
+ /*break*/
3131
+ , 3];
2135
3132
 
2136
- case 'phone_number':
2137
- if (field.dialCode) {
2138
- this.phoneNumber.countryDialCodeValue = field.dialCode;
3133
+ case 3:
3134
+ return [2
3135
+ /*return*/
3136
+ ];
2139
3137
  }
2140
-
2141
- this.phoneNumber.phoneNumberValue = field.value;
2142
- break;
2143
-
2144
- default:
2145
- formAttributes.attributes[field.type] = field.value;
2146
- break;
2147
- }
2148
- };
2149
-
2150
- class_6.prototype.componentWillLoad = function () {
2151
- Object(_helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["c"])(this.usernameAlias);
2152
- this.buildFormFields();
2153
- };
2154
-
2155
- class_6.prototype.formFieldsHandler = function () {
2156
- this.buildFormFields();
2157
- };
2158
-
2159
- class_6.prototype.render = function () {
2160
- var _this = this;
2161
-
2162
- return Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["H"], null, Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-form-section", {
2163
- headerText: _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(this.headerText),
2164
- handleSubmit: this.handleSubmit,
2165
- testDataPrefix: 'sign-up'
2166
- }, Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("div", {
2167
- slot: "subtitle"
2168
- }, Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("slot", {
2169
- name: "header-subtitle"
2170
- })), Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-auth-fields", {
2171
- formFields: this.newFormFields
2172
- }), Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("div", {
2173
- "class": "sign-up-form-footer",
2174
- slot: "amplify-form-section-footer"
2175
- }, Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("slot", {
2176
- name: "footer"
2177
- }, Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("slot", {
2178
- name: "secondary-footer-content"
2179
- }, Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("span", null, _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(this.haveAccountText), ' ', Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-button", {
2180
- variant: "anchor",
2181
- onClick: function onClick() {
2182
- return _this.handleAuthStateChange(_auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_2__["A"].SignIn);
2183
- },
2184
- "data-test": "sign-up-sign-in-link"
2185
- }, _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(this.signInText)))), Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("slot", {
2186
- name: "primary-footer-content"
2187
- }, Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-button", {
2188
- type: "submit",
2189
- "data-test": "sign-up-create-account-button",
2190
- disabled: this.loading
2191
- }, this.loading ? Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-loading-spinner", null) : Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("span", null, _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(this.submitButtonText))))))));
2192
- };
2193
-
2194
- Object.defineProperty(class_6, "watchers", {
2195
- get: function get() {
2196
- return {
2197
- "formFields": ["formFieldsHandler"]
2198
- };
2199
- },
2200
- enumerable: false,
2201
- configurable: true
2202
- });
2203
- return class_6;
2204
- }();
2205
-
2206
- AmplifySignUp.style = amplifySignUpCss;
2207
- var logger$2 = new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["Logger"]('AmplifyVerifyContact');
2208
-
2209
- var AmplifyVerifyContact =
2210
- /** @class */
2211
- function () {
2212
- function class_7(hostRef) {
2213
- Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["r"])(this, hostRef);
2214
- /** Authentication state handler */
2215
-
2216
- this.handleAuthStateChange = _helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["d"];
2217
- this.loading = false;
2218
- }
2219
-
2220
- class_7.prototype.handleSubmit = function (event) {
2221
- event.preventDefault();
2222
- this.verifyAttr ? this.submit(this.code) : this.verify(this.contact);
3138
+ });
3139
+ });
2223
3140
  };
2224
3141
 
2225
- class_7.prototype.submit = function (code) {
3142
+ class_1.prototype.setup = function () {
2226
3143
  return __awaiter(this, void 0, void 0, function () {
2227
- var attr, data, error_9;
3144
+ var encodedIssuer, secretKey, error_2;
2228
3145
  return __generator(this, function (_a) {
2229
3146
  switch (_a.label) {
2230
3147
  case 0:
2231
- attr = this.verifyAttr;
3148
+ // ensure setup is only run once after totp setup is available
3149
+ if (this.code || this.loading) {
3150
+ logger.debug('setup was attempted while another is in progress, skipping setup.');
3151
+ return [2
3152
+ /*return*/
3153
+ ];
3154
+ }
3155
+
3156
+ if (!this.user || !this.user.associateSoftwareToken) {
3157
+ logger.debug('setup was attempted with invalid `user`, skipping setup.', this.user);
3158
+ return [2
3159
+ /*return*/
3160
+ ];
3161
+ }
2232
3162
 
2233
- if (!_aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"] || typeof _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"].verifyCurrentUserAttributeSubmit !== 'function') {
3163
+ if (!_aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"] || typeof _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"].setupTOTP !== 'function') {
2234
3164
  throw new Error(_constants_c8ecaa24_js__WEBPACK_IMPORTED_MODULE_5__["N"]);
2235
3165
  }
2236
3166
 
3167
+ this.setupMessage = null;
3168
+ encodedIssuer = encodeURI(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(this.issuer));
2237
3169
  this.loading = true;
2238
3170
  _a.label = 1;
2239
3171
 
@@ -2242,21 +3174,21 @@ function () {
2242
3174
 
2243
3175
  return [4
2244
3176
  /*yield*/
2245
- , _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"].verifyCurrentUserAttributeSubmit(attr, code)];
3177
+ , _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"].setupTOTP(this.user)];
2246
3178
 
2247
3179
  case 2:
2248
- data = _a.sent();
2249
- logger$2.debug(data);
2250
- this.handleAuthStateChange(_auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_2__["A"].SignedIn, this.user);
2251
- this.verifyAttr = null;
3180
+ secretKey = _a.sent();
3181
+ logger.debug('secret key', secretKey);
3182
+ this.code = this.buildOtpAuthPath(this.user, encodedIssuer, secretKey);
3183
+ this.generateQRCode(this.code);
2252
3184
  return [3
2253
3185
  /*break*/
2254
3186
  , 5];
2255
3187
 
2256
3188
  case 3:
2257
- error_9 = _a.sent();
2258
- Object(_helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["a"])(error_9);
2259
- logger$2.error(error_9);
3189
+ error_2 = _a.sent();
3190
+ Object(_helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["a"])(error_2);
3191
+ logger.debug(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].TOTP_SETUP_FAILURE), error_2);
2260
3192
  return [3
2261
3193
  /*break*/
2262
3194
  , 5];
@@ -2276,56 +3208,70 @@ function () {
2276
3208
  });
2277
3209
  };
2278
3210
 
2279
- class_7.prototype.verify = function (contact) {
3211
+ class_1.prototype.verifyTotpToken = function (event) {
2280
3212
  return __awaiter(this, void 0, void 0, function () {
2281
- var data, error_10;
3213
+ var user, error_3;
2282
3214
  return __generator(this, function (_a) {
2283
3215
  switch (_a.label) {
2284
3216
  case 0:
2285
- if (!contact) {
2286
- logger$2.error('Neither Email nor Phone Number selected');
3217
+ if (event) {
3218
+ event.preventDefault();
3219
+ }
3220
+
3221
+ if (!this.qrCodeInput) {
3222
+ logger.debug('No TOTP Code provided');
2287
3223
  return [2
2288
3224
  /*return*/
2289
3225
  ];
2290
3226
  }
2291
3227
 
2292
- if (!_aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"] || typeof _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"].verifyCurrentUserAttribute !== 'function') {
3228
+ user = this.user;
3229
+
3230
+ if (!_aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"] || typeof _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"].verifyTotpToken !== 'function' || typeof _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"].setPreferredMFA !== 'function') {
2293
3231
  throw new Error(_constants_c8ecaa24_js__WEBPACK_IMPORTED_MODULE_5__["N"]);
2294
3232
  }
2295
3233
 
2296
- this.loading = true;
2297
3234
  _a.label = 1;
2298
3235
 
2299
3236
  case 1:
2300
- _a.trys.push([1, 3, 4, 5]);
3237
+ _a.trys.push([1, 5,, 6]);
2301
3238
 
2302
3239
  return [4
2303
3240
  /*yield*/
2304
- , _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"].verifyCurrentUserAttribute(contact)];
3241
+ , _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"].verifyTotpToken(user, this.qrCodeInput)];
2305
3242
 
2306
3243
  case 2:
2307
- data = _a.sent();
2308
- logger$2.debug(data);
2309
- this.verifyAttr = contact;
2310
- return [3
2311
- /*break*/
2312
- , 5];
3244
+ _a.sent();
3245
+
3246
+ return [4
3247
+ /*yield*/
3248
+ , _aws_amplify_auth__WEBPACK_IMPORTED_MODULE_3__["Auth"].setPreferredMFA(user, _auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_2__["M"].TOTP)];
2313
3249
 
2314
3250
  case 3:
2315
- error_10 = _a.sent();
2316
- Object(_helpers_14fcb50c_js__WEBPACK_IMPORTED_MODULE_6__["a"])(error_10);
2317
- logger$2.error(error_10);
2318
- return [3
2319
- /*break*/
2320
- , 5];
3251
+ _a.sent();
3252
+
3253
+ this.setupMessage = _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].TOTP_SUCCESS_MESSAGE);
3254
+ logger.debug(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].TOTP_SUCCESS_MESSAGE));
3255
+ return [4
3256
+ /*yield*/
3257
+ , this.handleComplete(user)];
2321
3258
 
2322
3259
  case 4:
2323
- this.loading = false;
2324
- return [7
2325
- /*endfinally*/
2326
- ];
3260
+ _a.sent();
3261
+
3262
+ return [3
3263
+ /*break*/
3264
+ , 6];
2327
3265
 
2328
3266
  case 5:
3267
+ error_3 = _a.sent();
3268
+ this.setupMessage = _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].TOTP_SETUP_FAILURE);
3269
+ logger.error(error_3);
3270
+ return [3
3271
+ /*break*/
3272
+ , 6];
3273
+
3274
+ case 6:
2329
3275
  return [2
2330
3276
  /*return*/
2331
3277
  ];
@@ -2334,99 +3280,45 @@ function () {
2334
3280
  });
2335
3281
  };
2336
3282
 
2337
- class_7.prototype.handleInputChange = function (event) {
2338
- var inputName = event.target.name;
2339
-
2340
- if (inputName === 'code') {
2341
- this.code = event.target.value;
2342
- } else if (inputName === 'contact') {
2343
- this.contact = event.target.value;
2344
- }
2345
- };
2346
-
2347
- class_7.prototype.renderSubmit = function () {
2348
- var _this = this;
2349
-
2350
- return Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("div", null, Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-input", {
2351
- inputProps: {
2352
- autocomplete: 'off',
2353
- 'data-test': 'verify-contact-code-input'
2354
- },
2355
- name: "code",
2356
- placeholder: _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].CODE_PLACEHOLDER),
2357
- handleInputChange: function handleInputChange(event) {
2358
- return _this.handleInputChange(event);
2359
- }
2360
- }));
2361
- };
2362
-
2363
- class_7.prototype.renderVerify = function () {
2364
- var _this = this;
2365
-
2366
- var user = this.user;
2367
-
2368
- if (!user) {
2369
- logger$2.debug('No user to verify');
2370
- return null;
2371
- }
2372
-
2373
- var unverified = user.unverified;
2374
-
2375
- if (!unverified) {
2376
- logger$2.debug('Unverified variable does not exist on user');
2377
- return null;
2378
- }
2379
-
2380
- var email = unverified.email,
2381
- phone_number = unverified.phone_number;
2382
- return Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("div", null, email && Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-radio-button", {
2383
- label: _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].VERIFY_CONTACT_EMAIL_LABEL),
2384
- key: "email",
2385
- name: "contact",
2386
- value: "email",
2387
- handleInputChange: function handleInputChange(event) {
2388
- return _this.handleInputChange(event);
2389
- },
2390
- inputProps: {
2391
- 'data-test': 'verify-contact-email-radio'
2392
- }
2393
- }), phone_number && Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-radio-button", {
2394
- label: _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].VERIFY_CONTACT_PHONE_LABEL),
2395
- key: "phone_number",
2396
- name: "contact",
2397
- value: "phone_number",
2398
- handleInputChange: function handleInputChange(event) {
2399
- return _this.handleInputChange(event);
2400
- },
2401
- inputProps: {
2402
- 'data-test': 'verify-contact-phone-number-radio'
2403
- }
2404
- }));
2405
- };
2406
-
2407
- class_7.prototype.render = function () {
3283
+ class_1.prototype.render = function () {
2408
3284
  var _this = this;
2409
3285
 
2410
3286
  return Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["H"], null, Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-form-section", {
3287
+ headerText: _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(this.headerText),
3288
+ submitButtonText: _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].TOTP_SUBMIT_BUTTON_TEXT),
2411
3289
  handleSubmit: function handleSubmit(event) {
2412
- return _this.handleSubmit(event);
3290
+ return _this.verifyTotpToken(event);
2413
3291
  },
2414
- headerText: _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].VERIFY_CONTACT_HEADER_TEXT),
2415
- loading: this.loading,
2416
- secondaryFooterContent: Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("span", null, Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-button", {
2417
- variant: "anchor",
2418
- onClick: function onClick() {
2419
- return _this.handleAuthStateChange(_auth_types_78df304e_js__WEBPACK_IMPORTED_MODULE_2__["A"].SignedIn, _this.user);
2420
- },
2421
- "data-test": "verify-contact-skip-link"
2422
- }, _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].SKIP))),
2423
- submitButtonText: this.verifyAttr ? _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].VERIFY_CONTACT_SUBMIT_LABEL) : _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].VERIFY_CONTACT_VERIFY_LABEL)
2424
- }, this.verifyAttr ? this.renderSubmit() : this.renderVerify()));
3292
+ loading: this.loading
3293
+ }, Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("div", {
3294
+ "class": "totp-setup"
3295
+ }, this.qrCodeImageSource && Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("img", {
3296
+ src: this.qrCodeImageSource,
3297
+ alt: _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].QR_CODE_ALT)
3298
+ }), Object(_index_83f2275b_js__WEBPACK_IMPORTED_MODULE_0__["h"])("amplify-form-field", {
3299
+ label: _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["I18n"].get(_Translations_108d469f_js__WEBPACK_IMPORTED_MODULE_4__["T"].TOTP_LABEL),
3300
+ inputProps: this.inputProps,
3301
+ fieldId: "totpCode",
3302
+ name: "totpCode",
3303
+ handleInputChange: function handleInputChange(event) {
3304
+ return _this.handleTotpInputChange(event);
3305
+ }
3306
+ }))));
2425
3307
  };
2426
3308
 
2427
- return class_7;
3309
+ Object.defineProperty(class_1, "watchers", {
3310
+ get: function get() {
3311
+ return {
3312
+ "user": ["handleUserChange"]
3313
+ };
3314
+ },
3315
+ enumerable: false,
3316
+ configurable: true
3317
+ });
3318
+ return class_1;
2428
3319
  }();
2429
3320
 
3321
+ AmplifyTOTPSetup.style = amplifyTotpSetupCss;
2430
3322
 
2431
3323
 
2432
3324
  /***/ }),