@verdocs/web-sdk 6.10.7 → 6.12.1

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 (140) hide show
  1. package/dist/cjs/{Icons-TVvtZ5iL.js → Icons-Zdy_DFce.js} +16 -2
  2. package/dist/{esm/Icons-BU5rnXp2.js.map → cjs/Icons-Zdy_DFce.js.map} +1 -1
  3. package/dist/cjs/loader.cjs.js +1 -1
  4. package/dist/cjs/verdocs-adopt-signature-dialog_7.cjs.entry.js +1 -1
  5. package/dist/cjs/verdocs-auth.cjs.entry.js +271 -15
  6. package/dist/cjs/verdocs-auth.cjs.entry.js.map +1 -1
  7. package/dist/cjs/verdocs-field-attachment_11.cjs.entry.js +1 -1
  8. package/dist/cjs/verdocs-field-payment.cjs.entry.js +1 -1
  9. package/dist/cjs/verdocs-file-chooser_2.cjs.entry.js +1 -1
  10. package/dist/cjs/verdocs-preview_6.cjs.entry.js +1 -1
  11. package/dist/cjs/verdocs-sign.cjs.entry.js +1 -1
  12. package/dist/cjs/verdocs-web-sdk.cjs.js +1 -1
  13. package/dist/collection/components/embeds/verdocs-auth/verdocs-auth.css +45 -1
  14. package/dist/collection/components/embeds/verdocs-auth/verdocs-auth.js +302 -19
  15. package/dist/collection/components/embeds/verdocs-auth/verdocs-auth.js.map +1 -1
  16. package/dist/collection/utils/Icons.js +12 -0
  17. package/dist/collection/utils/Icons.js.map +1 -1
  18. package/dist/components/{p-bPe0_Dsn.js → p-B8R4luxA.js} +2 -2
  19. package/dist/components/{p-D-TexkaT.js → p-BXaR1BSS.js} +2 -2
  20. package/dist/components/{p-DL4-aTsZ.js → p-BYLm9aol.js} +2 -2
  21. package/dist/components/{p-DiYuPnJJ.js → p-Bp88Loqg.js} +2 -2
  22. package/dist/components/{p-BYVQkYYg.js → p-C7JN32A9.js} +2 -2
  23. package/dist/components/{p-BDv5kBUR.js → p-C7k2AOsW.js} +2 -2
  24. package/dist/components/p-C7k2AOsW.js.map +1 -0
  25. package/dist/components/{p-DKKsPZnz.js → p-CCr_gliS.js} +2 -2
  26. package/dist/components/{p-BELGzhZw.js → p-CFau7OiC.js} +2 -2
  27. package/dist/components/{p-CYvB5bYX.js → p-CtNpZzq1.js} +2 -2
  28. package/dist/components/{p-B6aUlIQe.js → p-CzKj8wD_.js} +2 -2
  29. package/dist/components/{p-CZwyK_uo.js → p-DLo5dMNn.js} +2 -2
  30. package/dist/components/{p-D1cSgqut.js → p-D_FNSGtS.js} +2 -2
  31. package/dist/components/{p-K_PKw6bs.js → p-DmxiVavg.js} +2 -2
  32. package/dist/components/{p-D7oMWhqM.js → p-DrNmI7Wz.js} +2 -2
  33. package/dist/components/{p-DfIxVX8-.js → p-DubfX0n1.js} +2 -2
  34. package/dist/components/{p-CAGp0qKc.js → p-hxWwaOcD.js} +2 -2
  35. package/dist/components/{p-BQUZjuoP.js → p-vcHtLpWY.js} +2 -2
  36. package/dist/components/verdocs-adopt-signature-dialog.js +1 -1
  37. package/dist/components/verdocs-auth.js +1 -1
  38. package/dist/components/verdocs-auth.js.map +1 -1
  39. package/dist/components/verdocs-build.js +1 -1
  40. package/dist/components/verdocs-field-attachment.js +1 -1
  41. package/dist/components/verdocs-field-checkbox.js +1 -1
  42. package/dist/components/verdocs-field-date.js +1 -1
  43. package/dist/components/verdocs-field-dropdown.js +1 -1
  44. package/dist/components/verdocs-field-initial.js +1 -1
  45. package/dist/components/verdocs-field-payment.js +1 -1
  46. package/dist/components/verdocs-field-radio.js +1 -1
  47. package/dist/components/verdocs-field-signature.js +1 -1
  48. package/dist/components/verdocs-field-textarea.js +1 -1
  49. package/dist/components/verdocs-field-textbox.js +1 -1
  50. package/dist/components/verdocs-field-timestamp.js +1 -1
  51. package/dist/components/verdocs-file-chooser.js +1 -1
  52. package/dist/components/verdocs-preview.js +1 -1
  53. package/dist/components/verdocs-sign.js +1 -1
  54. package/dist/components/verdocs-template-attachments.js +1 -1
  55. package/dist/components/verdocs-template-document-page.js +1 -1
  56. package/dist/components/verdocs-template-fields.js +1 -1
  57. package/dist/custom-elements.json +2508 -0
  58. package/dist/esm/{Icons-BU5rnXp2.js → Icons-DobS6Y7w.js} +15 -3
  59. package/dist/{cjs/Icons-TVvtZ5iL.js.map → esm/Icons-DobS6Y7w.js.map} +1 -1
  60. package/dist/esm/loader.js +1 -1
  61. package/dist/esm/verdocs-adopt-signature-dialog_7.entry.js +1 -1
  62. package/dist/esm/verdocs-auth.entry.js +273 -17
  63. package/dist/esm/verdocs-auth.entry.js.map +1 -1
  64. package/dist/esm/verdocs-field-attachment_11.entry.js +1 -1
  65. package/dist/esm/verdocs-field-payment.entry.js +1 -1
  66. package/dist/esm/verdocs-file-chooser_2.entry.js +1 -1
  67. package/dist/esm/verdocs-preview_6.entry.js +1 -1
  68. package/dist/esm/verdocs-sign.entry.js +1 -1
  69. package/dist/esm/verdocs-web-sdk.js +1 -1
  70. package/dist/esm-es5/{Icons-BU5rnXp2.js → Icons-DobS6Y7w.js} +2 -2
  71. package/dist/esm-es5/{Icons-BU5rnXp2.js.map → Icons-DobS6Y7w.js.map} +1 -1
  72. package/dist/esm-es5/loader.js +1 -1
  73. package/dist/esm-es5/verdocs-adopt-signature-dialog_7.entry.js +1 -1
  74. package/dist/esm-es5/verdocs-auth.entry.js +1 -1
  75. package/dist/esm-es5/verdocs-auth.entry.js.map +1 -1
  76. package/dist/esm-es5/verdocs-field-attachment_11.entry.js +1 -1
  77. package/dist/esm-es5/verdocs-field-payment.entry.js +1 -1
  78. package/dist/esm-es5/verdocs-file-chooser_2.entry.js +1 -1
  79. package/dist/esm-es5/verdocs-preview_6.entry.js +1 -1
  80. package/dist/esm-es5/verdocs-sign.entry.js +1 -1
  81. package/dist/esm-es5/verdocs-web-sdk.js +1 -1
  82. package/dist/types/components/embeds/verdocs-auth/verdocs-auth.d.ts +31 -3
  83. package/dist/types/components.d.ts +18 -7
  84. package/dist/types/utils/Icons.d.ts +2 -0
  85. package/dist/verdocs-web-sdk/{p-869024e0.system.entry.js → p-09f5670e.system.entry.js} +2 -2
  86. package/dist/verdocs-web-sdk/p-0fb8e6e0.system.entry.js +2 -0
  87. package/dist/verdocs-web-sdk/p-0fb8e6e0.system.entry.js.map +1 -0
  88. package/dist/verdocs-web-sdk/{p-fad90cf9.system.entry.js → p-298d799f.system.entry.js} +3 -3
  89. package/dist/verdocs-web-sdk/{p-734c8a8b.entry.js → p-2a6a3bc6.entry.js} +2 -2
  90. package/dist/verdocs-web-sdk/{p-62464041.system.entry.js → p-439d36b0.system.entry.js} +2 -2
  91. package/dist/verdocs-web-sdk/{p-d95705c6.entry.js → p-4930b31d.entry.js} +2 -2
  92. package/dist/verdocs-web-sdk/{p-c86111fd.system.entry.js → p-5404f6bf.system.entry.js} +2 -2
  93. package/dist/verdocs-web-sdk/{p-10d47bbd.entry.js → p-5cad2422.entry.js} +2 -2
  94. package/dist/verdocs-web-sdk/{p-4e091415.entry.js → p-932e8b9b.entry.js} +2 -2
  95. package/dist/verdocs-web-sdk/{p-6e8ce989.system.entry.js → p-99f7a0fa.system.entry.js} +2 -2
  96. package/dist/verdocs-web-sdk/{p-GqS1qR-V.system.js → p-BHF3ByWV.system.js} +2 -2
  97. package/dist/verdocs-web-sdk/{p-GqS1qR-V.system.js.map → p-BHF3ByWV.system.js.map} +1 -1
  98. package/dist/verdocs-web-sdk/p-BdZ5Ghsa.system.js +1 -1
  99. package/dist/verdocs-web-sdk/{p-BU5rnXp2.js → p-DobS6Y7w.js} +2 -2
  100. package/dist/verdocs-web-sdk/{p-BU5rnXp2.js.map → p-DobS6Y7w.js.map} +1 -1
  101. package/dist/verdocs-web-sdk/p-c3e9634c.entry.js +2 -0
  102. package/dist/verdocs-web-sdk/p-c3e9634c.entry.js.map +1 -0
  103. package/dist/verdocs-web-sdk/{p-7e1f895c.entry.js → p-dd59aa9a.entry.js} +2 -2
  104. package/dist/verdocs-web-sdk/{p-ceda04bc.system.entry.js → p-f7b14409.system.entry.js} +2 -2
  105. package/dist/verdocs-web-sdk/{p-ee92c074.entry.js → p-fe404347.entry.js} +2 -2
  106. package/dist/verdocs-web-sdk/verdocs-web-sdk.esm.js +1 -1
  107. package/package.json +4 -4
  108. package/dist/components/p-BDv5kBUR.js.map +0 -1
  109. package/dist/verdocs-web-sdk/p-16d655d4.system.entry.js +0 -2
  110. package/dist/verdocs-web-sdk/p-16d655d4.system.entry.js.map +0 -1
  111. package/dist/verdocs-web-sdk/p-43ee0267.entry.js +0 -2
  112. package/dist/verdocs-web-sdk/p-43ee0267.entry.js.map +0 -1
  113. /package/dist/components/{p-bPe0_Dsn.js.map → p-B8R4luxA.js.map} +0 -0
  114. /package/dist/components/{p-D-TexkaT.js.map → p-BXaR1BSS.js.map} +0 -0
  115. /package/dist/components/{p-DL4-aTsZ.js.map → p-BYLm9aol.js.map} +0 -0
  116. /package/dist/components/{p-DiYuPnJJ.js.map → p-Bp88Loqg.js.map} +0 -0
  117. /package/dist/components/{p-BYVQkYYg.js.map → p-C7JN32A9.js.map} +0 -0
  118. /package/dist/components/{p-DKKsPZnz.js.map → p-CCr_gliS.js.map} +0 -0
  119. /package/dist/components/{p-BELGzhZw.js.map → p-CFau7OiC.js.map} +0 -0
  120. /package/dist/components/{p-CYvB5bYX.js.map → p-CtNpZzq1.js.map} +0 -0
  121. /package/dist/components/{p-B6aUlIQe.js.map → p-CzKj8wD_.js.map} +0 -0
  122. /package/dist/components/{p-CZwyK_uo.js.map → p-DLo5dMNn.js.map} +0 -0
  123. /package/dist/components/{p-D1cSgqut.js.map → p-D_FNSGtS.js.map} +0 -0
  124. /package/dist/components/{p-K_PKw6bs.js.map → p-DmxiVavg.js.map} +0 -0
  125. /package/dist/components/{p-D7oMWhqM.js.map → p-DrNmI7Wz.js.map} +0 -0
  126. /package/dist/components/{p-DfIxVX8-.js.map → p-DubfX0n1.js.map} +0 -0
  127. /package/dist/components/{p-CAGp0qKc.js.map → p-hxWwaOcD.js.map} +0 -0
  128. /package/dist/components/{p-BQUZjuoP.js.map → p-vcHtLpWY.js.map} +0 -0
  129. /package/dist/verdocs-web-sdk/{p-869024e0.system.entry.js.map → p-09f5670e.system.entry.js.map} +0 -0
  130. /package/dist/verdocs-web-sdk/{p-fad90cf9.system.entry.js.map → p-298d799f.system.entry.js.map} +0 -0
  131. /package/dist/verdocs-web-sdk/{p-734c8a8b.entry.js.map → p-2a6a3bc6.entry.js.map} +0 -0
  132. /package/dist/verdocs-web-sdk/{p-62464041.system.entry.js.map → p-439d36b0.system.entry.js.map} +0 -0
  133. /package/dist/verdocs-web-sdk/{p-d95705c6.entry.js.map → p-4930b31d.entry.js.map} +0 -0
  134. /package/dist/verdocs-web-sdk/{p-c86111fd.system.entry.js.map → p-5404f6bf.system.entry.js.map} +0 -0
  135. /package/dist/verdocs-web-sdk/{p-10d47bbd.entry.js.map → p-5cad2422.entry.js.map} +0 -0
  136. /package/dist/verdocs-web-sdk/{p-4e091415.entry.js.map → p-932e8b9b.entry.js.map} +0 -0
  137. /package/dist/verdocs-web-sdk/{p-6e8ce989.system.entry.js.map → p-99f7a0fa.system.entry.js.map} +0 -0
  138. /package/dist/verdocs-web-sdk/{p-7e1f895c.entry.js.map → p-dd59aa9a.entry.js.map} +0 -0
  139. /package/dist/verdocs-web-sdk/{p-ceda04bc.system.entry.js.map → p-f7b14409.system.entry.js.map} +0 -0
  140. /package/dist/verdocs-web-sdk/{p-ee92c074.entry.js.map → p-fe404347.entry.js.map} +0 -0
@@ -1,8 +1,52 @@
1
1
  import { h } from "@stencil/core";
2
- import { verifyEmail, getMyUser, convertToE164 } from "@verdocs/js-sdk";
3
2
  import { VerdocsEndpoint, createProfile, authenticate, resendVerification, resetPassword } from "@verdocs/js-sdk";
3
+ import { isMFARequired, getSocialProviders, getSocialLoginUrl, createCodeVerifier, createCodeChallenge } from "@verdocs/js-sdk";
4
+ import { verifyEmail, getMyUser, convertToE164 } from "@verdocs/js-sdk";
5
+ import { GoogleIcon, MicrosoftIcon } from "../../../utils/Icons";
4
6
  import { VerdocsToast } from "../../../utils/Toast";
5
7
  import { SDKError } from "../../../utils/errors";
8
+ const MFA_CODE_ERROR = 'Invalid code. Please try again.';
9
+ const SOCIAL_START_ERROR = 'Unable to start sign-in sequence. Please try again.';
10
+ const SOCIAL_LOGIN_KEY = 'vdocs-social-login';
11
+ const SOCIAL_ERROR_MESSAGES = {
12
+ email_unverified: 'That account does not have a verified email address.',
13
+ corporate_email_required: 'Please use your corporate email address to create an account.',
14
+ account_locked: 'That account is locked. Please contact support@verdocs.com.',
15
+ provider_error: 'That provider could not sign you in. Please try again.',
16
+ access_denied: 'Sign-in was canceled.',
17
+ };
18
+ const socialErrorMessage = (code) => SOCIAL_ERROR_MESSAGES[code] || 'Unable to sign in. Please try again.';
19
+ const readSocialLoginAttempt = () => {
20
+ try {
21
+ const stored = window.sessionStorage.getItem(SOCIAL_LOGIN_KEY);
22
+ return stored ? JSON.parse(stored) : null;
23
+ }
24
+ catch (_a) {
25
+ return null;
26
+ }
27
+ };
28
+ const clearSocialLoginAttempt = () => {
29
+ try {
30
+ window.sessionStorage.removeItem(SOCIAL_LOGIN_KEY);
31
+ }
32
+ catch (_a) {
33
+ // Third-party embeds may block sessionStorage. It's OK.
34
+ }
35
+ };
36
+ // Prevent replays on a reload
37
+ const cleanSocialLoginParams = (names) => {
38
+ const url = new URL(window.location.href);
39
+ names.forEach(name => url.searchParams.delete(name));
40
+ window.history.replaceState({}, '', `${url.pathname}${url.search}${url.hash}`);
41
+ };
42
+ const currentReturnUri = () => `${window.location.origin}${window.location.pathname}`;
43
+ const formatRecoveryCode = (value) => {
44
+ const cleaned = value
45
+ .toLowerCase()
46
+ .replace(/[^a-z0-9]/g, '')
47
+ .slice(0, 8);
48
+ return cleaned.length > 4 ? `${cleaned.slice(0, 4)}-${cleaned.slice(4)}` : cleaned;
49
+ };
6
50
  /**
7
51
  * Display an authentication dialog that allows the user to login or sign up. If the user is
8
52
  * already authenticated with a valid session, this component will hide itself and fire the
@@ -12,7 +56,7 @@ import { SDKError } from "../../../utils/errors";
12
56
  * To simplify UI development, a visibility flag can force this component to never display. This
13
57
  * allows you to subscribe to notifications from client apps without calling the lower-level JS SDK.
14
58
  *
15
- * This embed is responsive / mobile-friendly, but the calling application should provide at
59
+ * This embed is responsive and mobile-friendly, but the calling application should provide at
16
60
  * least a 300px wide container to allow sufficient space for the required forms.
17
61
  *
18
62
  * ```ts
@@ -44,6 +88,12 @@ export class VerdocsAuth {
44
88
  * The display mode to start in.
45
89
  */
46
90
  this.displayMode = 'login';
91
+ /**
92
+ * Social auth is disabled by default because these are redirect flows that require allowable redirect_uri
93
+ * destinations be pre-registered. These will only work on Verdocs sites/apps, so third-party developers
94
+ * should not turn this on unless instructed to by Verdocs Support.
95
+ */
96
+ this.showSocialLogins = false;
47
97
  this.org_name = '';
48
98
  this.first_name = '';
49
99
  this.last_name = '';
@@ -57,7 +107,14 @@ export class VerdocsAuth {
57
107
  this.resendDisabled = false;
58
108
  this.session = null;
59
109
  this.profile = null;
110
+ this.providers = { google: false, microsoft: false };
111
+ this.mfaToken = '';
112
+ this.mfaCode = '';
113
+ this.recoveryCode = '';
114
+ this.useRecoveryCode = false;
115
+ this.mfaError = '';
60
116
  this.resendDisabledTimer = null;
117
+ this.mfaFocusPending = false;
61
118
  // We can't instantly log in on the default endpoint because other listeners might see
62
119
  // its events and incorrectly trigger before we're done. So we manage our own temp
63
120
  // endpoint and pass the final tokens to the default once we're ready.
@@ -87,6 +144,33 @@ export class VerdocsAuth {
87
144
  (_b = this.authenticated) === null || _b === void 0 ? void 0 : _b.emit({ authenticated: false, session, profile });
88
145
  }
89
146
  });
147
+ if (this.showSocialLogins) {
148
+ getSocialProviders(this.endpoint)
149
+ .then(providers => {
150
+ this.providers = providers;
151
+ })
152
+ .catch(() => undefined);
153
+ }
154
+ this.handleSocialLoginReturn();
155
+ }
156
+ componentDidRender() {
157
+ if (this.displayMode !== 'mfa') {
158
+ return;
159
+ }
160
+ const input = this.el.querySelector('.mfa-input input');
161
+ if (!input) {
162
+ return;
163
+ }
164
+ if (!this.useRecoveryCode) {
165
+ input.setAttribute('inputmode', 'numeric');
166
+ }
167
+ else {
168
+ input.removeAttribute('inputmode');
169
+ }
170
+ if (this.mfaFocusPending) {
171
+ this.mfaFocusPending = false;
172
+ input.focus();
173
+ }
90
174
  }
91
175
  disconnectedCallback() {
92
176
  if (typeof window !== 'undefined') {
@@ -178,9 +262,24 @@ export class VerdocsAuth {
178
262
  }
179
263
  completeLogin(result) {
180
264
  this.clearForms();
265
+ this.displayMode = 'login';
181
266
  this.tempAuthEndpoint.clearSession();
182
267
  this.endpoint.setToken(result.access_token);
183
268
  }
269
+ async finishLogin(authResult) {
270
+ console.log('[AUTH] Authenticated, checking email verification');
271
+ this.tempAuthEndpoint.setToken(authResult.access_token);
272
+ const user = await getMyUser(this.tempAuthEndpoint);
273
+ this.submitting = false;
274
+ if (!user.email_verified) {
275
+ console.log('[AUTH] Logged in, pending email address verification');
276
+ this.displayMode = 'verify';
277
+ }
278
+ else {
279
+ console.log('[AUTH] Email address is verified, completing login');
280
+ this.completeLogin(authResult);
281
+ }
282
+ }
184
283
  async loginAndCheckVerification() {
185
284
  var _a;
186
285
  if (this.submitting) {
@@ -189,29 +288,170 @@ export class VerdocsAuth {
189
288
  this.submitting = true;
190
289
  this.tempAuthEndpoint.clearSession();
191
290
  try {
192
- this.submitting = false;
193
291
  const authResult = await authenticate(this.tempAuthEndpoint, { username: this.email.trim(), password: this.password, grant_type: 'password' });
194
- console.log('[AUTH] Authenticated, checking email verification');
195
- this.tempAuthEndpoint.setToken(authResult.access_token);
196
- const user = await getMyUser(this.tempAuthEndpoint);
197
- if (!user.email_verified) {
198
- console.log('[AUTH] Logged in, pending email address verification');
199
- this.displayMode = 'verify';
200
- }
201
- else {
202
- console.log('[AUTH] Email address is verified, completing login');
203
- this.completeLogin(authResult);
204
- }
292
+ await this.finishLogin(authResult);
205
293
  }
206
294
  catch (e) {
295
+ if (isMFARequired(e)) {
296
+ this.startMFA(e.response.data.mfa_token);
297
+ return;
298
+ }
207
299
  this.submitting = false;
208
300
  console.log('[AUTH] Auth failure', ((_a = e.response) === null || _a === void 0 ? void 0 : _a.data) || e);
209
301
  VerdocsToast('Login failed. Please check your credentials and try again.', { style: 'error' });
210
302
  }
211
303
  }
304
+ startMFA(token) {
305
+ this.mfaToken = token;
306
+ this.mfaCode = '';
307
+ this.recoveryCode = '';
308
+ this.useRecoveryCode = false;
309
+ this.mfaError = '';
310
+ this.submitting = false;
311
+ this.mfaFocusPending = true;
312
+ this.displayMode = 'mfa';
313
+ }
314
+ returnToLogin() {
315
+ this.mfaToken = '';
316
+ this.mfaCode = '';
317
+ this.recoveryCode = '';
318
+ this.useRecoveryCode = false;
319
+ this.mfaError = '';
320
+ this.password = '';
321
+ this.submitting = false;
322
+ this.displayMode = 'login';
323
+ }
324
+ handleMFAFailure(e) {
325
+ var _a;
326
+ this.submitting = false;
327
+ this.mfaCode = '';
328
+ this.recoveryCode = '';
329
+ // Failed attempts require a fresh token
330
+ if (isMFARequired(e)) {
331
+ this.mfaToken = e.response.data.mfa_token;
332
+ this.mfaError = MFA_CODE_ERROR;
333
+ return;
334
+ }
335
+ if (((_a = e === null || e === void 0 ? void 0 : e.response) === null || _a === void 0 ? void 0 : _a.status) === 401) {
336
+ this.returnToLogin();
337
+ VerdocsToast('Your sign-in timed out. Enter your password again.', { style: 'error' });
338
+ return;
339
+ }
340
+ this.mfaError = MFA_CODE_ERROR;
341
+ }
342
+ async submitMFA(code, isRecoveryCode) {
343
+ if (this.submitting || !code) {
344
+ return;
345
+ }
346
+ this.submitting = true;
347
+ this.mfaError = '';
348
+ this.tempAuthEndpoint.clearSession();
349
+ try {
350
+ const authResult = await authenticate(this.tempAuthEndpoint, isRecoveryCode
351
+ ? { grant_type: 'urn:verdocs:params:oauth:grant-type:mfa-recovery-code', mfa_token: this.mfaToken, recovery_code: code }
352
+ : { grant_type: 'urn:verdocs:params:oauth:grant-type:mfa-otp', mfa_token: this.mfaToken, otp: code });
353
+ await this.finishLogin(authResult);
354
+ }
355
+ catch (e) {
356
+ this.handleMFAFailure(e);
357
+ }
358
+ }
359
+ handleVerifyMFA() {
360
+ this.submitMFA(this.useRecoveryCode ? this.recoveryCode : this.mfaCode, this.useRecoveryCode).catch(() => undefined);
361
+ }
362
+ handleMFACodeInput(target) {
363
+ const digits = (target.value || '').replace(/\D/g, '').slice(0, 6);
364
+ if (target.value !== digits) {
365
+ target.value = digits;
366
+ }
367
+ this.mfaCode = digits;
368
+ // Auto-submit once 6 digits are entered
369
+ if (digits.length === 6) {
370
+ this.submitMFA(digits, false).catch(() => undefined);
371
+ }
372
+ }
373
+ handleRecoveryCodeInput(target) {
374
+ const formatted = formatRecoveryCode(target.value || '');
375
+ if (target.value !== formatted) {
376
+ target.value = formatted;
377
+ }
378
+ this.recoveryCode = formatted;
379
+ }
380
+ toggleRecoveryCode() {
381
+ this.useRecoveryCode = !this.useRecoveryCode;
382
+ this.mfaCode = '';
383
+ this.recoveryCode = '';
384
+ this.mfaError = '';
385
+ this.mfaFocusPending = true;
386
+ }
387
+ handleSocialLogin(provider) {
388
+ try {
389
+ const verifier = createCodeVerifier();
390
+ const state = createCodeVerifier();
391
+ createCodeChallenge(verifier)
392
+ .then(codeChallenge => {
393
+ const attempt = { verifier, state, provider };
394
+ window.sessionStorage.setItem(SOCIAL_LOGIN_KEY, JSON.stringify(attempt));
395
+ window.location.assign(getSocialLoginUrl(this.endpoint, provider, { returnUri: currentReturnUri(), codeChallenge, state }));
396
+ })
397
+ .catch(() => VerdocsToast(SOCIAL_START_ERROR, { style: 'error' }));
398
+ }
399
+ catch (_a) {
400
+ VerdocsToast(SOCIAL_START_ERROR, { style: 'error' });
401
+ }
402
+ }
403
+ handleSocialLoginReturn() {
404
+ if (typeof window === 'undefined') {
405
+ return;
406
+ }
407
+ const params = new URLSearchParams(window.location.search);
408
+ const loginCode = params.get('login_code');
409
+ const state = params.get('state');
410
+ const error = params.get('error');
411
+ if (!loginCode && !error) {
412
+ return;
413
+ }
414
+ const attempt = readSocialLoginAttempt();
415
+ // `error` doesn't give us the whole picture
416
+ if (!loginCode && !attempt) {
417
+ return;
418
+ }
419
+ clearSocialLoginAttempt();
420
+ cleanSocialLoginParams(loginCode ? ['login_code', 'state'] : ['error']);
421
+ if (error) {
422
+ VerdocsToast(socialErrorMessage(error), { style: 'error' });
423
+ return;
424
+ }
425
+ if (!attempt || attempt.state !== state) {
426
+ VerdocsToast('Sign-in could not be verified. Try again.', { style: 'error' });
427
+ return;
428
+ }
429
+ this.exchangeLoginCode(loginCode, attempt.verifier);
430
+ }
431
+ exchangeLoginCode(loginCode, codeVerifier) {
432
+ this.submitting = true;
433
+ this.tempAuthEndpoint.clearSession();
434
+ authenticate(this.tempAuthEndpoint, { grant_type: 'urn:verdocs:params:oauth:grant-type:login-code', login_code: loginCode, code_verifier: codeVerifier })
435
+ .then(authResult => this.finishLogin(authResult))
436
+ .catch(e => {
437
+ var _a;
438
+ if (isMFARequired(e)) {
439
+ this.startMFA(e.response.data.mfa_token);
440
+ return;
441
+ }
442
+ this.submitting = false;
443
+ console.log('[AUTH] Social login failure', ((_a = e.response) === null || _a === void 0 ? void 0 : _a.data) || e);
444
+ VerdocsToast('Sign-in failed. Please try again.', { style: 'error' });
445
+ });
446
+ }
212
447
  clearForms() {
213
448
  this.submitting = false;
214
449
  this.resendDisabled = false;
450
+ this.mfaToken = '';
451
+ this.mfaCode = '';
452
+ this.recoveryCode = '';
453
+ this.useRecoveryCode = false;
454
+ this.mfaError = '';
215
455
  this.email = '';
216
456
  this.phone = '';
217
457
  this.password = '';
@@ -327,6 +567,12 @@ export class VerdocsAuth {
327
567
  VerdocsToast('Unable to reset password. Please check your email address and try again.', { style: 'error' });
328
568
  }
329
569
  }
570
+ renderProviderButtons() {
571
+ if (!this.showSocialLogins || (!this.providers.google && !this.providers.microsoft)) {
572
+ return null;
573
+ }
574
+ return (h("div", { class: "providers" }, this.providers.google && (h("verdocs-button", { label: "Continue with Google", variant: "outline", class: "provider-google", startIcon: GoogleIcon, disabled: this.submitting, onClick: () => this.handleSocialLogin('google') })), this.providers.microsoft && (h("verdocs-button", { label: "Continue with Microsoft", variant: "outline", class: "provider-microsoft", startIcon: MicrosoftIcon, disabled: this.submitting, onClick: () => this.handleSocialLogin('microsoft') })), h("div", { class: "divider" }, h("div", { class: "divider-line" }), "or", h("div", { class: "divider-line" }))));
575
+ }
330
576
  render() {
331
577
  if (!this.visible) {
332
578
  return h("div", { style: { display: 'none' } }, "Authenticated");
@@ -334,9 +580,19 @@ export class VerdocsAuth {
334
580
  if (this.session) {
335
581
  return (h("verdocs-button", { label: "Sign Out", disabled: this.submitting, onClick: () => this.handleLogout(), style: { display: 'flex', justifyContent: 'center', margin: '30px auto 0' } }));
336
582
  }
583
+ if (this.displayMode === 'mfa') {
584
+ const enteredCode = this.useRecoveryCode ? this.recoveryCode : this.mfaCode;
585
+ const codeComplete = this.useRecoveryCode ? this.recoveryCode.replace('-', '').length === 8 : this.mfaCode.length === 6;
586
+ return (h("div", { class: "form" }, h("a", { href: "https://verdocs.com/en/" }, h("img", { src: this.logo, alt: "Verdocs Logo", class: "logo" })), h("h3", null, "Two-factor authentication"), h("p", null, this.useRecoveryCode
587
+ ? 'Enter one of the backup codes you saved when you turned on multi-factor authentication.'
588
+ : 'Enter the six-digit code from your authenticator app.'), h("form", { onSubmit: (e) => {
589
+ e.preventDefault();
590
+ this.handleVerifyMFA();
591
+ } }, this.useRecoveryCode ? (h("verdocs-text-input", { class: "mfa-input", label: "Backup code", placeholder: "xxxx-xxxx", autocomplete: "one-time-code", value: this.recoveryCode, onInput: (e) => this.handleRecoveryCodeInput(e.target), disabled: this.submitting })) : (h("verdocs-text-input", { class: "mfa-input", label: "Authentication code", autocomplete: "one-time-code", value: this.mfaCode, onInput: (e) => this.handleMFACodeInput(e.target), disabled: this.submitting })), this.mfaError && (h("div", { role: "alert", class: "mfa-error" }, this.mfaError)), h("div", { class: "buttons" }, h("verdocs-button", { label: "Cancel", variant: "outline", disabled: this.submitting, onClick: () => this.returnToLogin() }), h("verdocs-button", { label: "Verify", disabled: this.submitting || !codeComplete || !enteredCode, onClick: () => this.handleVerifyMFA() })), h("div", { class: "buttons" }, h("verdocs-button", { variant: "text", size: "small", label: this.useRecoveryCode ? 'Use your authenticator app instead' : 'Use a backup code instead', disabled: this.submitting, onClick: () => this.toggleRecoveryCode() })))));
592
+ }
337
593
  if (this.displayMode === 'signup') {
338
594
  const invalid = this.submitting || !this.first_name || !this.last_name || !this.email || !this.password || !this.confirmpass || !this.org_name;
339
- return (h("div", { class: "form" }, h("a", { href: "https://verdocs.com/en/" }, h("img", { src: this.logo, alt: "Verdocs Logo", class: "logo" })), h("h3", null, "Sign up for a free account"), h("div", { class: "already-have" }, "Already have an account?", h("verdocs-button", { label: "Log In", variant: "text", onClick: () => (this.displayMode = 'login'), disabled: this.submitting })), h("form", { onSubmit: () => this.handleSignup() }, h("div", { style: { display: 'flex', flexDirection: 'row', columnGap: '20px' } }, h("verdocs-text-input", { label: "First Name", autocomplete: "first", required: true, value: this.first_name, onInput: (e) => (this.first_name = e.target.value), disabled: this.submitting }), h("verdocs-text-input", { label: "Last Name", autocomplete: "last", required: true, value: this.last_name, onInput: (e) => (this.last_name = e.target.value), disabled: this.submitting })), h("verdocs-text-input", { label: "Email Address", autocomplete: "email", required: true, value: this.email, onInput: (e) => (this.email = e.target.value), disabled: this.submitting }), h("verdocs-text-input", { label: "Password", type: "password", required: true, autocomplete: "new-password", value: this.password, onInput: (e) => (this.password = e.target.value), disabled: this.submitting }), h("verdocs-text-input", { label: "Confirm Password", type: "password", required: true, autocomplete: "off", value: this.confirmpass, onInput: (e) => (this.confirmpass = e.target.value), disabled: this.submitting }), h("verdocs-text-input", { label: "Phone Number", type: "tel", required: true, autocomplete: "phone", value: this.phone, onInput: (e) => (this.phone = e.target.value), disabled: this.submitting }), h("verdocs-text-input", { label: "Organization Name", autocomplete: "org", required: true, value: this.org_name, onInput: (e) => (this.org_name = e.target.value), disabled: this.submitting, style: { flex: '1' } }), h("div", { class: "service-agreement" }, "By clicking the Create Account button, you agree to the", ' ', h("a", { href: "https://verdocs.com/eula", target: "_blank" }, "End User License Agreement"), ". Learn about how we use and protect your data and how you can opt-out in our", ' ', h("a", { href: "https://verdocs.com/privacy-policy", target: "_blank" }, "Privacy Policy"), "."), h("div", { style: { marginTop: '30px' } }), h("verdocs-button", { label: "Next", disabled: invalid, onClick: invalid ? () => { } : () => this.handleSignup(), style: { display: 'flex', justifyContent: 'center', margin: '30px auto 0' } }))));
595
+ return (h("div", { class: "form" }, h("a", { href: "https://verdocs.com/en/" }, h("img", { src: this.logo, alt: "Verdocs Logo", class: "logo" })), h("h3", null, "Sign up for a free account"), h("div", { class: "already-have" }, "Already have an account?", h("verdocs-button", { label: "Log In", variant: "text", onClick: () => (this.displayMode = 'login'), disabled: this.submitting })), this.renderProviderButtons(), h("form", { onSubmit: () => this.handleSignup() }, h("div", { style: { display: 'flex', flexDirection: 'row', columnGap: '20px' } }, h("verdocs-text-input", { label: "First Name", autocomplete: "first", required: true, value: this.first_name, onInput: (e) => (this.first_name = e.target.value), disabled: this.submitting }), h("verdocs-text-input", { label: "Last Name", autocomplete: "last", required: true, value: this.last_name, onInput: (e) => (this.last_name = e.target.value), disabled: this.submitting })), h("verdocs-text-input", { label: "Email Address", autocomplete: "email", required: true, value: this.email, onInput: (e) => (this.email = e.target.value), disabled: this.submitting }), h("verdocs-text-input", { label: "Password", type: "password", required: true, autocomplete: "new-password", value: this.password, onInput: (e) => (this.password = e.target.value), disabled: this.submitting }), h("verdocs-text-input", { label: "Confirm Password", type: "password", required: true, autocomplete: "off", value: this.confirmpass, onInput: (e) => (this.confirmpass = e.target.value), disabled: this.submitting }), h("verdocs-text-input", { label: "Phone Number", type: "tel", required: true, autocomplete: "phone", value: this.phone, onInput: (e) => (this.phone = e.target.value), disabled: this.submitting }), h("verdocs-text-input", { label: "Organization Name", autocomplete: "org", required: true, value: this.org_name, onInput: (e) => (this.org_name = e.target.value), disabled: this.submitting, style: { flex: '1' } }), h("div", { class: "service-agreement" }, "By clicking the Create Account button, you agree to the", ' ', h("a", { href: "https://verdocs.com/eula", target: "_blank" }, "End User License Agreement"), ". Learn about how we use and protect your data and how you can opt-out in our", ' ', h("a", { href: "https://verdocs.com/privacy-policy", target: "_blank" }, "Privacy Policy"), "."), h("div", { style: { marginTop: '30px' } }), h("verdocs-button", { label: "Next", disabled: invalid, onClick: invalid ? () => { } : () => this.handleSignup(), style: { display: 'flex', justifyContent: 'center', margin: '30px auto 0' } }))));
340
596
  }
341
597
  if (this.displayMode === 'verify') {
342
598
  return (h("div", { class: "form" }, h("form", { onSubmit: () => this.handleVerification() }, h("p", null, "Please check your e-mail inbox for a verification code and enter it below."), h("verdocs-text-input", { label: "Verification Code", required: true, value: this.verificationCode, onInput: (e) => (this.verificationCode = e.target.value), disabled: this.submitting }), h("div", { class: "buttons" }, h("verdocs-button", { label: "Sign Out", variant: "outline", disabled: this.submitting, onClick: () => this.handleLogout() }), h("verdocs-button", { label: "Verify", disabled: this.submitting || !this.verificationCode || this.verificationCode.length !== 6, onClick: () => this.handleVerification() })), h("div", { class: "buttons" }, h("verdocs-button", { variant: "text", label: "Resend Code", disabled: this.resendDisabled || this.submitting, onClick: () => this.handleResendVerification() })))));
@@ -347,7 +603,7 @@ export class VerdocsAuth {
347
603
  if (this.displayMode === 'reset') {
348
604
  return (h("div", { class: "form" }, h("a", { href: "https://verdocs.com/en/" }, h("img", { src: this.logo, alt: "Verdocs Logo", class: "logo" })), h("h3", null, "Forgot your password?"), h("p", null, "Enter your e-mail address below, and reset instructions will be sent to your Inbox. Please allow up to 15 minutes to arrive. Check your spam folder if you do not receive the message."), h("form", { onSubmit: () => this.handleResetPassword() }, h("verdocs-text-input", { label: "Verification Code", required: true, value: this.verificationCode, onInput: (e) => (this.verificationCode = e.target.value), disabled: this.submitting }), h("verdocs-text-input", { label: "Password", type: "password", required: true, autocomplete: "off", value: this.newPassword, onInput: (e) => (this.newPassword = e.target.value), disabled: this.submitting }), h("verdocs-text-input", { label: "Confirm Password", type: "password", required: true, autocomplete: "off", value: this.confirmpass, onInput: (e) => (this.confirmpass = e.target.value), disabled: this.submitting }), h("div", { style: { marginTop: '30px' } }), h("div", { class: "buttons" }, h("verdocs-button", { label: "Cancel", variant: "outline", disabled: this.submitting, onClick: () => (this.displayMode = 'login') }), h("verdocs-button", { label: "Reset", disabled: this.submitting, onClick: () => this.handleResetPassword() })), h("div", { class: "buttons" }, h("verdocs-button", { variant: "text", label: "Resend Code", disabled: this.resendDisabled || this.submitting, onClick: () => this.handleResendReset() })))));
349
605
  }
350
- return (h("div", { class: "form" }, h("a", { href: "https://verdocs.com/en/" }, h("img", { src: this.logo, alt: "Verdocs Logo", class: "logo" })), h("h3", null, "Log in to your account"), h("div", { class: "already-have" }, "Don't have an account?", h("verdocs-button", { label: "Sign Up", variant: "text", onClick: () => (this.displayMode = 'signup'), disabled: this.submitting })), h("form", { onSubmit: () => this.loginAndCheckVerification() }, h("verdocs-text-input", { label: "Email", autocomplete: "username", value: this.email, onInput: (e) => (this.email = e.target.value), disabled: this.submitting }), h("verdocs-text-input", { label: "Password", type: "password", autocomplete: "current-password", value: this.password, onInput: (e) => (this.password = e.target.value), disabled: this.submitting }), h("verdocs-button", { label: "Forgot Your Password?", variant: "text", onClick: () => (this.displayMode = 'forgot'), disabled: this.submitting, style: { display: 'flex', justifyContent: 'center', margin: '10px auto 20px' } }), h("verdocs-button", { label: "Login", disabled: this.submitting, onClick: () => this.loginAndCheckVerification(), style: { display: 'flex', justifyContent: 'center', margin: '10px auto 0' } }))));
606
+ return (h("div", { class: "form" }, h("a", { href: "https://verdocs.com/en/" }, h("img", { src: this.logo, alt: "Verdocs Logo", class: "logo" })), h("h3", null, "Log in to your account"), this.renderProviderButtons(), h("form", { onSubmit: () => this.loginAndCheckVerification() }, h("verdocs-text-input", { label: "Email", autocomplete: "username", value: this.email, onInput: (e) => (this.email = e.target.value), disabled: this.submitting }), h("verdocs-text-input", { label: "Password", type: "password", autocomplete: "current-password", value: this.password, onInput: (e) => (this.password = e.target.value), disabled: this.submitting }), h("verdocs-button", { label: "Forgot Your Password?", variant: "text", onClick: () => (this.displayMode = 'forgot'), disabled: this.submitting, style: { display: 'flex', justifyContent: 'center', margin: '0 auto 20px' } }), h("verdocs-button", { label: "Login", disabled: this.submitting, onClick: () => this.loginAndCheckVerification(), style: { display: 'flex', justifyContent: 'center', margin: '10px auto 0' } }), h("verdocs-button", { label: "Sign Up", variant: "outline", disabled: this.submitting, onClick: () => (this.displayMode = 'signup'), style: { display: 'flex', justifyContent: 'center', margin: '10px auto 0' } }))));
351
607
  }
352
608
  static get is() { return "verdocs-auth"; }
353
609
  static get originalStyleUrls() {
@@ -431,8 +687,8 @@ export class VerdocsAuth {
431
687
  "type": "string",
432
688
  "mutable": true,
433
689
  "complexType": {
434
- "original": "'login' | 'forgot' | 'reset' | 'signup' | 'verify'",
435
- "resolved": "\"forgot\" | \"login\" | \"reset\" | \"signup\" | \"verify\"",
690
+ "original": "'login' | 'forgot' | 'reset' | 'signup' | 'verify' | 'mfa'",
691
+ "resolved": "\"forgot\" | \"login\" | \"mfa\" | \"reset\" | \"signup\" | \"verify\"",
436
692
  "references": {}
437
693
  },
438
694
  "required": false,
@@ -446,6 +702,26 @@ export class VerdocsAuth {
446
702
  "reflect": false,
447
703
  "attribute": "display-mode",
448
704
  "defaultValue": "'login'"
705
+ },
706
+ "showSocialLogins": {
707
+ "type": "boolean",
708
+ "mutable": false,
709
+ "complexType": {
710
+ "original": "boolean",
711
+ "resolved": "boolean",
712
+ "references": {}
713
+ },
714
+ "required": false,
715
+ "optional": false,
716
+ "docs": {
717
+ "tags": [],
718
+ "text": "Social auth is disabled by default because these are redirect flows that require allowable redirect_uri\ndestinations be pre-registered. These will only work on Verdocs sites/apps, so third-party developers\nshould not turn this on unless instructed to by Verdocs Support."
719
+ },
720
+ "getter": false,
721
+ "setter": false,
722
+ "reflect": false,
723
+ "attribute": "show-social-logins",
724
+ "defaultValue": "false"
449
725
  }
450
726
  };
451
727
  }
@@ -463,7 +739,13 @@ export class VerdocsAuth {
463
739
  "submitting": {},
464
740
  "resendDisabled": {},
465
741
  "session": {},
466
- "profile": {}
742
+ "profile": {},
743
+ "providers": {},
744
+ "mfaToken": {},
745
+ "mfaCode": {},
746
+ "recoveryCode": {},
747
+ "useRecoveryCode": {},
748
+ "mfaError": {}
467
749
  };
468
750
  }
469
751
  static get events() {
@@ -512,5 +794,6 @@ export class VerdocsAuth {
512
794
  }
513
795
  }];
514
796
  }
797
+ static get elementRef() { return "el"; }
515
798
  }
516
799
  //# sourceMappingURL=verdocs-auth.js.map