@oneblink/apps-react 9.0.0-beta.3 → 9.0.0-beta.5

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 (205) hide show
  1. package/dist/OneBlinkForm.d.ts +0 -4
  2. package/dist/OneBlinkForm.js +0 -4
  3. package/dist/OneBlinkForm.js.map +1 -1
  4. package/dist/OneBlinkFormBase.d.ts +1 -1
  5. package/dist/OneBlinkFormBase.js +2 -2
  6. package/dist/OneBlinkFormBase.js.map +1 -1
  7. package/dist/OneBlinkReadOnlyForm.d.ts +1 -1
  8. package/dist/OneBlinkReadOnlyForm.js +1 -1
  9. package/dist/OneBlinkReadOnlyForm.js.map +1 -1
  10. package/dist/PaymentReceipt.d.ts +1 -1
  11. package/dist/PaymentReceipt.js +3 -3
  12. package/dist/PaymentReceipt.js.map +1 -1
  13. package/dist/apps/index.d.ts +18 -18
  14. package/dist/apps/index.js +18 -18
  15. package/dist/apps/index.js.map +1 -1
  16. package/dist/apps/tenants.d.ts +2 -1
  17. package/dist/apps/tenants.js +25 -1
  18. package/dist/apps/tenants.js.map +1 -1
  19. package/dist/components/ArcGISWebMap.js +7 -4
  20. package/dist/components/ArcGISWebMap.js.map +1 -1
  21. package/dist/components/ConfirmDialog.js +3 -2
  22. package/dist/components/ConfirmDialog.js.map +1 -1
  23. package/dist/components/calendar-bookings/CalendarBookingsCancelForm.js +1 -1
  24. package/dist/components/calendar-bookings/CalendarBookingsCancelForm.js.map +1 -1
  25. package/dist/components/calendar-bookings/CalendarBookingsForm.d.ts +1 -1
  26. package/dist/components/calendar-bookings/CalendarBookingsForm.js +1 -1
  27. package/dist/components/calendar-bookings/CalendarBookingsForm.js.map +1 -1
  28. package/dist/components/calendar-bookings/CalendarBookingsReschedulingForm.js +1 -1
  29. package/dist/components/calendar-bookings/CalendarBookingsReschedulingForm.js.map +1 -1
  30. package/dist/components/calendar-bookings/ErrorModal.d.ts +1 -1
  31. package/dist/components/calendar-bookings/ErrorModal.js +1 -1
  32. package/dist/components/calendar-bookings/ErrorModal.js.map +1 -1
  33. package/dist/components/downloadable-files/index.d.ts +1 -1
  34. package/dist/components/downloadable-files/index.js +1 -1
  35. package/dist/components/downloadable-files/index.js.map +1 -1
  36. package/dist/components/downloadable-files/resource-components.d.ts +1 -1
  37. package/dist/components/downloadable-files/resource-components.js +1 -1
  38. package/dist/components/downloadable-files/resource-components.js.map +1 -1
  39. package/dist/components/formStore/FormStoreTableProvider.js +1 -1
  40. package/dist/components/formStore/FormStoreTableProvider.js.map +1 -1
  41. package/dist/components/formStore/OneBlinkFormStoreClearFiltersButton.js +1 -3
  42. package/dist/components/formStore/OneBlinkFormStoreClearFiltersButton.js.map +1 -1
  43. package/dist/components/formStore/OneBlinkFormStoreDownloadButton.js +1 -1
  44. package/dist/components/formStore/OneBlinkFormStoreDownloadButton.js.map +1 -1
  45. package/dist/components/formStore/OneBlinkFormStoreProvider.js +1 -1
  46. package/dist/components/formStore/OneBlinkFormStoreProvider.js.map +1 -1
  47. package/dist/components/formStore/OneBlinkFormStoreRefreshButton.js +1 -3
  48. package/dist/components/formStore/OneBlinkFormStoreRefreshButton.js.map +1 -1
  49. package/dist/components/formStore/OneBlinkFormStoreTable.js +3 -3
  50. package/dist/components/formStore/OneBlinkFormStoreTable.js.map +1 -1
  51. package/dist/components/formStore/display/ElementDisplay.js +2 -2
  52. package/dist/components/formStore/display/ElementDisplay.js.map +1 -1
  53. package/dist/components/formStore/table/ColumnFilters.js +1 -1
  54. package/dist/components/formStore/table/ColumnFilters.js.map +1 -1
  55. package/dist/components/formStore/table/FormElementTableCell.js +1 -1
  56. package/dist/components/formStore/table/FormElementTableCell.js.map +1 -1
  57. package/dist/components/formStore/table/Pickers.js +1 -1
  58. package/dist/components/formStore/table/Pickers.js.map +1 -1
  59. package/dist/components/formStore/table/RepeatableSetCell.js +1 -0
  60. package/dist/components/formStore/table/RepeatableSetCell.js.map +1 -1
  61. package/dist/components/formStore/table/generateColumns.d.ts +1 -1
  62. package/dist/components/formStore/table/generateColumns.js.map +1 -1
  63. package/dist/components/formStore/table/useFormStoreTable.d.ts +1 -1
  64. package/dist/components/formStore/table/useFormStoreTable.js +2 -1
  65. package/dist/components/formStore/table/useFormStoreTable.js.map +1 -1
  66. package/dist/components/mfa/MfaDialog.d.ts +1 -1
  67. package/dist/components/mfa/MfaDialog.js +1 -1
  68. package/dist/components/mfa/MfaDialog.js.map +1 -1
  69. package/dist/components/payments/PaymentForm.js +1 -1
  70. package/dist/components/payments/PaymentForm.js.map +1 -1
  71. package/dist/components/payments/WestpacQuickStreamPaymentForm.d.ts +1 -1
  72. package/dist/components/payments/WestpacQuickStreamPaymentForm.js +1 -1
  73. package/dist/components/payments/WestpacQuickStreamPaymentForm.js.map +1 -1
  74. package/dist/components/renderer/AutocompleteDropdown.js +1 -1
  75. package/dist/components/renderer/AutocompleteDropdown.js.map +1 -1
  76. package/dist/components/renderer/LookupNotification.js +2 -2
  77. package/dist/components/renderer/LookupNotification.js.map +1 -1
  78. package/dist/components/renderer/Modal.js +3 -1
  79. package/dist/components/renderer/Modal.js.map +1 -1
  80. package/dist/components/renderer/OneBlinkAppsErrorOriginalMessage.js +1 -1
  81. package/dist/components/renderer/OneBlinkAppsErrorOriginalMessage.js.map +1 -1
  82. package/dist/components/renderer/OneBlinkFormElements.js.map +1 -1
  83. package/dist/components/renderer/ReverseGeocode.js +1 -1
  84. package/dist/components/renderer/ReverseGeocode.js.map +1 -1
  85. package/dist/components/renderer/Tooltip.js +3 -1
  86. package/dist/components/renderer/Tooltip.js.map +1 -1
  87. package/dist/form-elements/FormElementAPINSWLiquorLicence.js +1 -1
  88. package/dist/form-elements/FormElementAPINSWLiquorLicence.js.map +1 -1
  89. package/dist/form-elements/FormElementArcGISWebMap.js.map +1 -1
  90. package/dist/form-elements/FormElementAutocomplete.js +1 -1
  91. package/dist/form-elements/FormElementAutocomplete.js.map +1 -1
  92. package/dist/form-elements/FormElementBSB.js +2 -2
  93. package/dist/form-elements/FormElementBSB.js.map +1 -1
  94. package/dist/form-elements/FormElementCalculation.js +2 -2
  95. package/dist/form-elements/FormElementCalculation.js.map +1 -1
  96. package/dist/form-elements/FormElementCivicaNameRecord.js +1 -1
  97. package/dist/form-elements/FormElementCivicaNameRecord.js.map +1 -1
  98. package/dist/form-elements/FormElementCivicaStreetName.js +1 -1
  99. package/dist/form-elements/FormElementCivicaStreetName.js.map +1 -1
  100. package/dist/form-elements/FormElementCompliance.d.ts +1 -1
  101. package/dist/form-elements/FormElementCompliance.js.map +1 -1
  102. package/dist/form-elements/FormElementDate.js +1 -1
  103. package/dist/form-elements/FormElementDate.js.map +1 -1
  104. package/dist/form-elements/FormElementDateTime.js +1 -1
  105. package/dist/form-elements/FormElementDateTime.js.map +1 -1
  106. package/dist/form-elements/FormElementFile.d.ts +1 -1
  107. package/dist/form-elements/FormElementFile.js.map +1 -1
  108. package/dist/form-elements/FormElementFiles.d.ts +1 -1
  109. package/dist/form-elements/FormElementFiles.js.map +1 -1
  110. package/dist/form-elements/FormElementFreshdeskDependentField.js +3 -10
  111. package/dist/form-elements/FormElementFreshdeskDependentField.js.map +1 -1
  112. package/dist/form-elements/FormElementGeoscapeAddress.js +1 -1
  113. package/dist/form-elements/FormElementGeoscapeAddress.js.map +1 -1
  114. package/dist/form-elements/FormElementGoogleAddress.js +1 -1
  115. package/dist/form-elements/FormElementGoogleAddress.js.map +1 -1
  116. package/dist/form-elements/FormElementLocation.js +6 -2
  117. package/dist/form-elements/FormElementLocation.js.map +1 -1
  118. package/dist/form-elements/FormElementLookupButton.js +1 -1
  119. package/dist/form-elements/FormElementLookupButton.js.map +1 -1
  120. package/dist/form-elements/FormElementNumber.js +1 -1
  121. package/dist/form-elements/FormElementNumber.js.map +1 -1
  122. package/dist/form-elements/FormElementPointAddress.js +1 -1
  123. package/dist/form-elements/FormElementPointAddress.js.map +1 -1
  124. package/dist/form-elements/FormElementPointAddressV3.js +1 -1
  125. package/dist/form-elements/FormElementPointAddressV3.js.map +1 -1
  126. package/dist/form-elements/FormElementPointCadastralParcel.js +1 -1
  127. package/dist/form-elements/FormElementPointCadastralParcel.js.map +1 -1
  128. package/dist/form-elements/FormElementSummary.js +4 -2
  129. package/dist/form-elements/FormElementSummary.js.map +1 -1
  130. package/dist/form-elements/FormElementTime.js +1 -1
  131. package/dist/form-elements/FormElementTime.js.map +1 -1
  132. package/dist/hooks/attachments/useAttachment.d.ts +1 -1
  133. package/dist/hooks/attachments/useAttachment.js +1 -1
  134. package/dist/hooks/attachments/useAttachment.js.map +1 -1
  135. package/dist/hooks/attachments/useAttachments.d.ts +1 -1
  136. package/dist/hooks/attachments/useAttachments.js.map +1 -1
  137. package/dist/hooks/form-date-picker/useFormDatePickerProps.js +2 -0
  138. package/dist/hooks/form-date-picker/useFormDatePickerProps.js.map +1 -1
  139. package/dist/hooks/useAuth.js +1 -1
  140. package/dist/hooks/useAuth.js.map +1 -1
  141. package/dist/hooks/useConditionalLogic.js +1 -1
  142. package/dist/hooks/useConditionalLogic.js.map +1 -1
  143. package/dist/hooks/useDrafts.d.ts +1 -1
  144. package/dist/hooks/useDrafts.js +1 -1
  145. package/dist/hooks/useDrafts.js.map +1 -1
  146. package/dist/hooks/useDynamicOptionsLoaderState.d.ts +1 -1
  147. package/dist/hooks/useDynamicOptionsLoaderState.js +1 -1
  148. package/dist/hooks/useDynamicOptionsLoaderState.js.map +1 -1
  149. package/dist/hooks/useFormElementLookups.d.ts +1 -1
  150. package/dist/hooks/useFormElementLookups.js +1 -1
  151. package/dist/hooks/useFormElementLookups.js.map +1 -1
  152. package/dist/hooks/useFormSubmissionAutoSaveState.d.ts +1 -1
  153. package/dist/hooks/useFormSubmissionAutoSaveState.js +1 -1
  154. package/dist/hooks/useFormSubmissionAutoSaveState.js.map +1 -1
  155. package/dist/hooks/useFormSubmissionDuration.js +2 -0
  156. package/dist/hooks/useFormSubmissionDuration.js.map +1 -1
  157. package/dist/hooks/useIsOffline.js +1 -1
  158. package/dist/hooks/useIsOffline.js.map +1 -1
  159. package/dist/hooks/useLoadDataState.js +4 -3
  160. package/dist/hooks/useLoadDataState.js.map +1 -1
  161. package/dist/hooks/useLogin.js +1 -1
  162. package/dist/hooks/useLogin.js.map +1 -1
  163. package/dist/hooks/useMfa.d.ts +1 -1
  164. package/dist/hooks/useMfa.js +1 -1
  165. package/dist/hooks/useMfa.js.map +1 -1
  166. package/dist/hooks/useOnUploadAttachment.d.ts +1 -1
  167. package/dist/hooks/useOnUploadAttachment.js +1 -1
  168. package/dist/hooks/useOnUploadAttachment.js.map +1 -1
  169. package/dist/hooks/useOneBlinkFormContainer.d.ts +2 -1
  170. package/dist/hooks/useOneBlinkFormContainer.js +2 -2
  171. package/dist/hooks/useOneBlinkFormContainer.js.map +1 -1
  172. package/dist/hooks/usePendingSubmissions.d.ts +1 -1
  173. package/dist/hooks/usePendingSubmissions.js +1 -1
  174. package/dist/hooks/usePendingSubmissions.js.map +1 -1
  175. package/dist/hooks/useReplaceableText.js +1 -1
  176. package/dist/hooks/useReplaceableText.js.map +1 -1
  177. package/dist/hooks/useSignUp.js +1 -1
  178. package/dist/hooks/useSignUp.js.map +1 -1
  179. package/dist/services/attachments.d.ts +1 -1
  180. package/dist/services/attachments.js +1 -1
  181. package/dist/services/attachments.js.map +1 -1
  182. package/dist/services/blob-utils.js +1 -1
  183. package/dist/services/blob-utils.js.map +1 -1
  184. package/dist/services/checkIfAttachmentsExist.d.ts +1 -1
  185. package/dist/services/checkIfAttachmentsExist.js.map +1 -1
  186. package/dist/services/defaultCoordinates.js +1 -1
  187. package/dist/services/defaultCoordinates.js.map +1 -1
  188. package/dist/services/download-file.d.ts +1 -1
  189. package/dist/services/download-file.js +2 -2
  190. package/dist/services/download-file.js.map +1 -1
  191. package/dist/services/drawTimestampOnCanvas.js +1 -1
  192. package/dist/services/drawTimestampOnCanvas.js.map +1 -1
  193. package/dist/services/form-validation/validateSubmission.js +1 -1
  194. package/dist/services/form-validation/validateSubmission.js.map +1 -1
  195. package/dist/services/form-validation/validators.d.ts +1 -1
  196. package/dist/services/form-validation/validators.js.map +1 -1
  197. package/dist/services/generate-default-data.js +1 -1
  198. package/dist/services/generate-default-data.js.map +1 -1
  199. package/dist/services/injectableOptions.js +1 -1
  200. package/dist/services/injectableOptions.js.map +1 -1
  201. package/dist/types/attachments.d.ts +1 -1
  202. package/dist/types/attachments.js.map +1 -1
  203. package/dist/utils/sendGoogleAnalyticsEvent.js +1 -1
  204. package/dist/utils/sendGoogleAnalyticsEvent.js.map +1 -1
  205. package/package.json +10 -7
@@ -1 +1 @@
1
- {"version":3,"file":"useLogin.js","sourceRoot":"","sources":["../../src/hooks/useLogin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAEpD,OAAO,YAAY,MAAM,gBAAgB,CAAA;AACzC,OAAO,eAAe,MAAM,mBAAmB,CAAA;AAE/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0SG;AACH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,EAC/B,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,oBAAoB,EACpB,IAAI,EACJ,UAAU,GAoBX;IACC,MAAM,SAAS,GAAG,YAAY,EAAE,CAAA;IAEhC,aAAa;IACb,MAAM,kBAAkB,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QAC5C,OAAO;YACL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;QAClB,mBAAmB;QACnB,wBAAwB;QACxB,+BAA+B;QAC/B,2BAA2B;QAC3B,sBAAsB;QACtB,+BAA+B;QAC/B,yBAAyB,EAAE,CAAC,CAAC,8BAA8B;QAC3D,4BAA4B;QAC5B,sBAAsB;QACtB,aAAa;QACb,kBAAkB;QAClB,kBAAkB;QAClB,cAAc;QACd,qBAAqB;QACrB,8BAA8B;KAC/B,CAAA;AACH,CAAC","sourcesContent":["import * as React from 'react'\nimport { authService, Sentry } from '@oneblink/apps'\n\nimport useIsMounted from './useIsMounted'\nimport useBooleanState from './useBooleanState'\n\n/**\n * This function is a react hook to help writing your own login screen.\n *\n * ## Example\n *\n * ```jsx\n * import * as React from 'react'\n * import { useHistory } from 'react-router-dom'\n * import { useLogin } from '@oneblink/apps-react'\n *\n * function App() {\n * const history = useHistory()\n *\n * const [username, setUsername] = React.useState('')\n * const [password, setPassword] = React.useState('')\n * const [newPasswordConfirmed, setNewPasswordConfirmed] = React.useState('')\n * const [newPassword, setNewPassword] = React.useState('')\n * const [code, setCode] = React.useState('')\n *\n * const onLogin = React.useCallback(() => {\n * history.push('/')\n * }, [history])\n *\n * const {\n * // Login\n * loginWithGoogle,\n * loginWithUsernamePassword,\n * isLoggingIn,\n * // Reset Temp Password\n * isPasswordTemporary,\n * isResettingTemporaryPassword,\n * resetTemporaryPassword,\n * // MFA Password\n * isMfaCodeRequired,\n * isSubmittingMfaCode,\n * submitMfaCode,\n * // Login Errors\n * loginError,\n * clearLoginError,\n * // Showing Forgot Password\n * isShowingForgotPassword,\n * showForgotPassword,\n * hideForgotPassword,\n * // Sending Forgot Password Code\n * isSendingForgotPasswordCode,\n * sendForgotPasswordCode,\n * // Resetting Forgotten Password\n * hasSentForgotPasswordCode,\n * isResettingForgottenPassword,\n * resetForgottenPassword,\n * // Forgot Password Errors\n * forgotPasswordError,\n * clearForgotPasswordError,\n * // Validation\n * usernameValidation,\n * passwordValidation,\n * codeValidation,\n * newPasswordValidation,\n * newPasswordConfirmedValidation,\n * } = useLogin({\n * username,\n * password,\n * newPassword,\n * newPasswordConfirmed,\n * code,\n * onLogin,\n * })\n *\n * if (hasSentForgotPasswordCode) {\n * return (\n * <form\n * onSubmit={(e) => {\n * e.preventDefault()\n * resetForgottenPassword()\n * }}\n * >\n * <p>We have sent you a password reset code via email. Enter it below to reset your password.</p>\n *\n * <input\n * type=\"password\"\n * placeholder=\"Code\"\n * value={code}\n * onChange={(e) => setCode(e.target.value)}\n * />\n *\n * <input\n * type=\"password\"\n * placeholder=\"New Password\"\n * value={newPassword}\n * onChange={(e) => setNewPassword(e.target.value)}\n * />\n *\n * <input\n * type=\"password\"\n * placeholder=\"Confirm Password\"\n * value={newPassword}\n * onChange={(e) => setNewPasswordConfirmed(e.target.value)}\n * />\n *\n * <button\n * type=\"submit\"\n * disabled={isResettingForgottenPassword || codeValidation.isInvalid || newPasswordValidation.isInvalid || newPasswordConfirmedValidation.isInvalid}\n * >\n * Change Password\n * </button>\n *\n * <p>Password Requirements</p>\n * <p>Contains a lowercase letter: {validation.hasLowercaseLetter ? 'Yes' : 'No'}</p>\n * <p>Contains an upper case letter: {validation.hasUpperCaseLetter ? 'Yes' : 'No'}</p>\n * <p>Contains a number: {validation.hasNumber ? 'Yes' : 'No'}</p>\n * <p>Contains a special character: {validation.hasSpecialCharacter ? 'Yes' : 'No'}</p>\n * <p>Contains at least 8 characters: {validation.hasMinLength ? 'Yes' : 'No'}</p>\n *\n * {forgotPasswordError && (\n * <p>{forgotPasswordError.message}</p>\n * <button type=\"button\" onClick={clearForgotPasswordError}>Clear Error</button>\n * )}\n * </form>\n * )\n * }\n *\n * if (isShowingForgotPassword) {\n * return (\n * <form\n * onSubmit={(e) => {\n * e.preventDefault()\n * sendForgotPasswordCode()\n * }}\n * >\n * <p>Enter your email address and we will send you a code to reset your password.</p>\n *\n * <input\n * type=\"email\"\n * placeholder=\"Email Address\"\n * value={username}\n * onChange={(e) => setUsername(e.target.value)}\n * />\n *\n * <p>\n * <a onClick={hideForgotPassword}>Remembered your password?</a>\n * </p>\n *\n * <button\n * type=\"submit\"\n * disabled={isSendingForgotPasswordCode || usernameValidation.isInvalid}\n * >\n * Reset Password\n * </button>\n *\n * {forgotPasswordError && (\n * <p>{forgotPasswordError.message}</p>\n * <button type=\"button\" onClick={clearForgotPasswordError}>Clear Error</button>\n * )}\n * </form>\n * )\n * }\n *\n * if (isPasswordTemporary) {\n * return (\n * <form\n * onSubmit={(e) => {\n * e.preventDefault()\n * resetTemporaryPassword()\n * }}\n * >\n * <p>The password you entered was only temporary and must be reset for security purposes. Please enter your new password below to continue.</p>\n *\n * <input\n * type=\"password\"\n * placeholder=\"New Password\"\n * value={newPassword}\n * onChange={(e) => setNewPassword(e.target.value)}\n * />\n *\n * <input\n * type=\"password\"\n * placeholder=\"Confirm Password\"\n * value={newPassword}\n * onChange={(e) => setNewPasswordConfirmed(e.target.value)}\n * />\n *\n * <button\n * type=\"submit\"\n * disabled={isResettingTemporaryPassword || newPasswordValidation.isInvalid || newPasswordConfirmedValidation.isInvalid}\n * >\n * Change Password &amp; Sign In\n * </button>\n *\n * <p>Password Requirements</p>\n * <p>Contains a lowercase letter: {validation.hasLowercaseLetter ? 'Yes' : 'No'}</p>\n * <p>Contains an upper case letter: {validation.hasUpperCaseLetter ? 'Yes' : 'No'}</p>\n * <p>Contains a number: {validation.hasNumber ? 'Yes' : 'No'}</p>\n * <p>Contains a special character: {validation.hasSpecialCharacter ? 'Yes' : 'No'}</p>\n * <p>Contains at least 8 characters: {validation.hasMinLength ? 'Yes' : 'No'}</p>\n *\n * {loginError && (\n * <p>{loginError.message}</p>\n * <button type=\"button\" onClick={clearLoginError}>Clear Error</button>\n * )}\n * </form>\n * )\n * }\n *\n * if (isMfaCodeRequired) {\n * return (\n * <form\n * onSubmit={(e) => {\n * e.preventDefault()\n * submitMfaCode()\n * }}\n * >\n * <p>Enter the 6-digit code found in your authenticator app.</p>\n *\n * <input\n * type=\"password\"\n * placeholder=\"Code\"\n * value={code}\n * onChange={(e) => setCode(e.target.value)}\n * />\n *\n * <button\n * type=\"submit\"\n * disabled={isSubmittingMfaCode || codeValidation.isInvalid}\n * >\n * Sign In\n * </button>\n *\n * {loginError && (\n * <p>{loginError.message}</p>\n * <button type=\"button\" onClick={clearLoginError}>Clear Error</button>\n * )}\n * </form>\n * )\n * }\n *\n * return (\n * <form\n * onSubmit={(e) => {\n * e.preventDefault()\n * loginWithUsernamePassword()\n * }}\n * >\n * <p>Sign in with your email address and password.</p>\n * <input\n * type=\"email\"\n * placeholder=\"Email Address\"\n * value={username}\n * onChange={(e) => setUsername(e.target.value)}\n * />\n *\n * <input\n * type=\"password\"\n * placeholder=\"New Password\"\n * value={newPassword}\n * onChange={(e) => setNewPassword(e.target.value)}\n * />\n *\n * <p>\n * <a onClick={showForgotPassword}>Forgot your password?</a>\n * </p>\n *\n * <button\n * type=\"submit\"\n * disabled={isLoggingIn || usernameValidation.isInvalid || passwordValidation.isInvalid}\n * >\n * {children}\n * </button>\n *\n * <p>or</p>\n *\n * <button\n * type=\"button\"\n * onClick={loginWithGoogle}\n * >\n * <img\n * alt=\"Google\"\n * src=\"google-sign-in.png\"\n * />\n * <span>Sign in with Google</span>\n * </button>\n *\n * {loginError && (\n * <p>{loginError.message}</p>\n * <button type=\"button\" onClick={clearLoginError}>Clear Error</button>\n * )}\n * </form>\n * )\n * }\n *\n * const root = document.getElementById('root')\n * if (root) {\n * ReactDOM.render(<App />, root)\n * }\n * ```\n *\n * @param options\n * @returns\n * @group Hooks\n */\nexport default function useLogin({\n username,\n password,\n newPassword,\n newPasswordConfirmed,\n code,\n formsAppId,\n}: {\n /** The email address entered by the user. */\n username: string\n /** The password entered by the user. */\n password: string\n /** The new password entered by the user if changing their password. */\n newPassword: string\n /**\n * The new password repeated by the user if changing their password to ensure\n * they do type it in wrong.\n */\n newPasswordConfirmed: string\n /**\n * The code sent to the user after requesting a password reset by starting the\n * \"forgot password\" process.\n */\n code: string\n /** The identifier for the current forms app */\n formsAppId?: number\n}): UseLoginValue {\n const isMounted = useIsMounted()\n\n // Validation\n const usernameValidation = React.useMemo(() => {\n return {\n isInvalid: !username.trim(),\n }\n }, [username])\n\n const passwordValidation = React.useMemo(() => {\n return {\n isInvalid: !password.trim(),\n }\n }, [password])\n\n const codeValidation = React.useMemo(() => {\n return {\n isInvalid: !code.trim(),\n }\n }, [code])\n\n const newPasswordValidation = React.useMemo(() => {\n const validation = {\n hasLowercaseLetter: /[a-z]+/.test(newPassword),\n hasUpperCaseLetter: /[A-Z]+/.test(newPassword),\n hasNumber: /\\d+/.test(newPassword),\n hasSpecialCharacter: /[\\^$*.[\\]{}()?|\\-\"!@#%&/,><':;|_~`]+/.test(\n newPassword,\n ),\n hasMinLength: newPassword.length >= 8,\n isInvalid: true,\n }\n validation.isInvalid =\n !validation.hasLowercaseLetter ||\n !validation.hasUpperCaseLetter ||\n !validation.hasNumber ||\n !validation.hasSpecialCharacter ||\n !validation.hasMinLength\n return validation\n }, [newPassword])\n\n const newPasswordConfirmedValidation = React.useMemo(() => {\n return {\n isInvalid: newPassword !== newPasswordConfirmed,\n }\n }, [newPassword, newPasswordConfirmed])\n\n // Login, Reset Password, MFA\n const [\n {\n isResettingTemporaryPassword,\n isLoggingIn,\n loginError,\n loginAttemptResponse,\n isSubmittingMfaCode,\n },\n setLoginState,\n ] = React.useState<{\n isResettingTemporaryPassword: boolean\n isLoggingIn: boolean\n loginError: null | Error\n loginAttemptResponse: authService.LoginAttemptResponse | undefined\n isSubmittingMfaCode: boolean\n }>({\n isResettingTemporaryPassword: false,\n isLoggingIn: false,\n loginError: null,\n loginAttemptResponse: undefined,\n isSubmittingMfaCode: false,\n })\n const clearLoginError = React.useCallback(\n () =>\n setLoginState((current) => ({\n ...current,\n loginError: null,\n })),\n [],\n )\n const loginWithUsernamePassword = React.useCallback(async () => {\n if (usernameValidation.isInvalid) {\n setLoginState((current) => ({\n ...current,\n loginError: new Error('Please enter a valid email address'),\n }))\n return\n }\n if (passwordValidation.isInvalid) {\n setLoginState((current) => ({\n ...current,\n loginError: new Error('Please enter a valid password'),\n }))\n return\n }\n\n setLoginState((currentState) => ({\n ...currentState,\n isLoggingIn: true,\n loginError: null,\n }))\n\n try {\n const newLoginAttemptResponse = await authService.loginUsernamePassword(\n username,\n password,\n )\n if (isMounted.current) {\n setLoginState((currentState) => ({\n ...currentState,\n isLoggingIn: false,\n loginAttemptResponse: newLoginAttemptResponse,\n }))\n }\n } catch (error) {\n Sentry.captureException(error)\n if (isMounted.current) {\n setLoginState((currentState) => ({\n ...currentState,\n isLoggingIn: false,\n loginError: error as Error,\n }))\n }\n }\n }, [\n isMounted,\n password,\n passwordValidation.isInvalid,\n username,\n usernameValidation.isInvalid,\n ])\n\n const resetTemporaryPassword = React.useCallback(async () => {\n const resetTemporaryPasswordCallback =\n loginAttemptResponse?.resetPasswordCallback\n if (!resetTemporaryPasswordCallback) {\n return\n }\n\n if (newPasswordValidation.isInvalid) {\n setLoginState((current) => ({\n ...current,\n loginError: new Error('Please enter a valid password'),\n }))\n return\n }\n\n if (newPasswordConfirmedValidation.isInvalid) {\n setLoginState((current) => ({\n ...current,\n loginError: new Error('Please confirm your new password'),\n }))\n return\n }\n\n setLoginState((current) => ({\n ...current,\n isResettingPassword: true,\n loginError: null,\n }))\n\n try {\n const resetPasswordResponse =\n await resetTemporaryPasswordCallback(newPassword)\n if (isMounted.current) {\n setLoginState((currentState) => ({\n ...currentState,\n isResettingTemporaryPassword: false,\n loginAttemptResponse: resetPasswordResponse,\n }))\n }\n } catch (error) {\n Sentry.captureException(error)\n if (isMounted.current) {\n setLoginState((current) => ({\n ...current,\n isResettingPassword: false,\n loginError: error as Error,\n }))\n }\n }\n }, [\n isMounted,\n loginAttemptResponse?.resetPasswordCallback,\n newPassword,\n newPasswordConfirmedValidation.isInvalid,\n newPasswordValidation.isInvalid,\n ])\n\n const submitMfaCode = React.useCallback(async () => {\n const mfaCodeCallback = loginAttemptResponse?.mfaCodeCallback\n if (!mfaCodeCallback) {\n return\n }\n\n setLoginState((current) => ({\n ...current,\n isSubmittingMfaCode: true,\n loginError: null,\n }))\n\n try {\n const mfaResponse = await mfaCodeCallback(code)\n if (isMounted.current) {\n setLoginState((currentState) => ({\n ...currentState,\n isSubmittingMfaCode: false,\n loginAttemptResponse: mfaResponse,\n }))\n }\n } catch (error) {\n Sentry.captureException(error)\n if (isMounted.current) {\n setLoginState((current) => ({\n ...current,\n isSubmittingMfaCode: false,\n loginError: error as Error,\n }))\n }\n }\n }, [code, isMounted, loginAttemptResponse?.mfaCodeCallback])\n\n // Forgot Password\n const [isShowingForgotPassword, showForgotPassword, hideForgotPassword] =\n useBooleanState(false)\n const [\n {\n resetForgottenPasswordCallback,\n isSendingForgotPasswordCode,\n isResettingForgottenPassword,\n forgotPasswordError,\n },\n setForgotPasswordState,\n ] = React.useState<{\n isSendingForgotPasswordCode: boolean\n forgotPasswordError: null | Error\n resetForgottenPasswordCallback:\n | null\n | ((code: string, newPassword: string) => void)\n isResettingForgottenPassword: boolean\n }>({\n isSendingForgotPasswordCode: false,\n forgotPasswordError: null,\n resetForgottenPasswordCallback: null,\n isResettingForgottenPassword: false,\n })\n const clearForgotPasswordError = React.useCallback(\n () =>\n setForgotPasswordState((current) => ({\n ...current,\n forgotPasswordError: null,\n })),\n [],\n )\n const sendForgotPasswordCode = React.useCallback(async () => {\n if (usernameValidation.isInvalid) {\n setForgotPasswordState((current) => ({\n ...current,\n forgotPasswordError: new Error('Please enter a valid email address'),\n }))\n return\n }\n\n setForgotPasswordState({\n isSendingForgotPasswordCode: true,\n resetForgottenPasswordCallback: null,\n forgotPasswordError: null,\n isResettingForgottenPassword: false,\n })\n\n try {\n const newResetForgottenPasswordCallback =\n await authService.forgotPassword(username, formsAppId)\n if (isMounted.current) {\n setForgotPasswordState({\n isSendingForgotPasswordCode: false,\n resetForgottenPasswordCallback: newResetForgottenPasswordCallback,\n forgotPasswordError: null,\n isResettingForgottenPassword: false,\n })\n }\n } catch (error) {\n Sentry.captureException(error)\n if (isMounted.current) {\n setForgotPasswordState({\n isSendingForgotPasswordCode: false,\n resetForgottenPasswordCallback: null,\n forgotPasswordError: error as Error,\n isResettingForgottenPassword: false,\n })\n }\n }\n }, [isMounted, username, usernameValidation.isInvalid, formsAppId])\n\n const resetForgottenPassword = React.useCallback(async () => {\n if (!resetForgottenPasswordCallback) {\n return\n }\n\n if (codeValidation.isInvalid) {\n setForgotPasswordState((current) => ({\n ...current,\n forgotPasswordError: new Error(\n 'Please enter the code that was sent to your email address',\n ),\n }))\n }\n if (newPasswordValidation.isInvalid) {\n setForgotPasswordState((current) => ({\n ...current,\n forgotPasswordError: new Error('Please enter a valid password'),\n }))\n return\n }\n if (newPasswordConfirmedValidation.isInvalid) {\n setForgotPasswordState((current) => ({\n ...current,\n forgotPasswordError: new Error('Please confirm your new password'),\n }))\n return\n }\n\n setForgotPasswordState((current) => ({\n ...current,\n isChangingPassword: true,\n forgotPasswordError: null,\n }))\n\n try {\n await resetForgottenPasswordCallback(code, newPassword)\n if (isMounted.current) {\n setForgotPasswordState({\n isSendingForgotPasswordCode: false,\n resetForgottenPasswordCallback: null,\n forgotPasswordError: null,\n isResettingForgottenPassword: false,\n })\n hideForgotPassword()\n }\n } catch (error) {\n Sentry.captureException(error)\n if (isMounted.current) {\n setForgotPasswordState((current) => ({\n ...current,\n isChangingPassword: false,\n forgotPasswordError: error as Error,\n }))\n }\n }\n }, [\n resetForgottenPasswordCallback,\n codeValidation.isInvalid,\n newPasswordValidation.isInvalid,\n newPasswordConfirmedValidation.isInvalid,\n code,\n newPassword,\n isMounted,\n hideForgotPassword,\n ])\n\n const loginWithGoogle = React.useCallback(() => {\n authService.loginHostedUI('Google')\n }, [])\n\n return {\n // Login\n /** Open redirect user to the Google sign in */\n loginWithGoogle,\n loginWithUsernamePassword,\n isLoggingIn,\n loginError,\n clearLoginError,\n // Reset Temp Password\n isPasswordTemporary: !!loginAttemptResponse?.resetPasswordCallback,\n isResettingTemporaryPassword,\n resetTemporaryPassword,\n // MFA Code\n isMfaCodeRequired: !!loginAttemptResponse?.mfaCodeCallback,\n isSubmittingMfaCode,\n submitMfaCode,\n // Showing Forgot Password\n isShowingForgotPassword,\n showForgotPassword,\n hideForgotPassword,\n forgotPasswordError,\n clearForgotPasswordError,\n // Sending Forgot Password Code\n isSendingForgotPasswordCode,\n sendForgotPasswordCode,\n // Resetting Forgotten Password\n hasSentForgotPasswordCode: !!resetForgottenPasswordCallback,\n isResettingForgottenPassword,\n resetForgottenPassword,\n // Validation\n usernameValidation,\n passwordValidation,\n codeValidation,\n newPasswordValidation,\n newPasswordConfirmedValidation,\n }\n}\n\nexport interface UseLoginValue {\n /** Open redirect user to the Google sign-in page. */\n loginWithGoogle: () => void\n /**\n * Attempt to use the `username` and `password` arguments to create a session.\n * Will call `onLogin()` if successful, otherwise will set `loginError`.\n */\n loginWithUsernamePassword: () => void\n /** `true` while processing `loginWithUsernamePassword()`. */\n isLoggingIn: boolean\n /**\n * `true` if the user logged in using a temporary password. Prompt the user\n * for a new password and call `resetTemporaryPassword()`.\n */\n isPasswordTemporary: boolean\n /**\n * Attempt to use `newPassword` and `newPasswordConfirmed` arguments to reset\n * the user's password and create a session. Will call `onLogin()` if\n * successful, otherwise will set `loginError`.\n */\n resetTemporaryPassword: () => void\n /**\n * Set if an error occurs while processing `loginWithUsernamePassword()` or\n * `resetTemporaryPassword()`.\n */\n loginError: Error | null\n /** Set `loginError` back to `null`. */\n clearLoginError: () => void\n /** `true` while processing `resetTemporaryPassword()`. */\n isResettingTemporaryPassword: boolean\n /** `true` when showing the forgot password flow. */\n isShowingForgotPassword: boolean\n /** Set `isShowingForgotPassword` to `true`. */\n showForgotPassword: () => void\n /** Set `isShowingForgotPassword` to `false`. */\n hideForgotPassword: () => void\n /**\n * Attempt to use the `username` argument to start the forgot password\n * process. This will send the user an email with a code to enter. A failed\n * request will set `forgotPasswordError`.\n */\n sendForgotPasswordCode: () => void\n /** `true` while processing `sendForgotPasswordCode()`. */\n isSendingForgotPasswordCode: boolean\n /** `true` if the forgot password code has been successfully sent to the user. */\n hasSentForgotPasswordCode: boolean\n /**\n * Attempt to use the `code`, `newPassword`, and `newPasswordConfirmed`\n * arguments to reset the user's password. A failed request will set\n * `forgotPasswordError`.\n */\n resetForgottenPassword: () => void\n /** `true` while processing `resetForgottenPassword()`. */\n isResettingForgottenPassword: boolean\n /**\n * Set if an error occurs while processing `sendForgotPasswordCode()` or\n * `resetForgottenPassword()`.\n */\n forgotPasswordError: Error | null\n /** Set `forgotPasswordError` back to `null`. */\n clearForgotPasswordError: () => void\n usernameValidation: {\n /** `true` if the `username` argument is invalid. */\n isInvalid: boolean\n }\n passwordValidation: {\n /** `true` if the `password` argument is invalid. */\n isInvalid: boolean\n }\n codeValidation: {\n /** `true` if the `code` argument is invalid. */\n isInvalid: boolean\n }\n newPasswordValidation: {\n /** `true` if the `newPassword` argument is invalid. */\n isInvalid: boolean\n /**\n * `true` if the `newPassword` argument has a lowercase letter (required to\n * be valid).\n */\n hasLowercaseLetter: boolean\n /**\n * `true` if the `newPassword` argument has an uppercase letter (required to\n * be valid).\n */\n hasUpperCaseLetter: boolean\n /** `true` if the `newPassword` argument has a number (required to be valid). */\n hasNumber: boolean\n /**\n * `true` if the `newPassword` argument has a special character (required to\n * be valid).\n */\n hasSpecialCharacter: boolean\n /**\n * `true` if the `newPassword` argument has at least the minimum number of\n * characters (required to be valid).\n */\n hasMinLength: boolean\n }\n newPasswordConfirmedValidation: {\n /**\n * `true` if the `newPasswordConfirmed` argument is invalid (must match the\n * `newPassword` argument).\n */\n isInvalid: boolean\n }\n /**\n * `true` if the user logged in using MFA and a code is required to finish the\n * login attempt. Prompt the user for a code and call `submitMfaCode()`.\n */\n isMfaCodeRequired: boolean\n /** `true` while processing `submitMfaCode()`. */\n isSubmittingMfaCode: boolean\n /**\n * Attempt to use `code` argument to submit the MFA code and create a session.\n * Will call `onLogin()` if successful, otherwise will set `loginError`.\n */\n submitMfaCode: () => void\n}\n"]}
1
+ {"version":3,"file":"useLogin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AAG,OAAO;oBACV,kBAAkB,EAAE,KAAK;oBACzB,mBAAmB,EAAE,KAAc;iBACpC,CAAC,CAAC,CAAA;YACL,CAAC;QACH,CAAC;IACH,CAAC,EAAE;QACD,8BAA8B;QAC9B,cAAc,CAAC,SAAS;QACxB,qBAAqB,CAAC,SAAS;QAC/B,8BAA8B,CAAC,SAAS;QACxC,IAAI;QACJ,WAAW;QACX,SAAS;QACT,kBAAkB;KACnB,CAAC,CAAA;IAEF,MAAM,eAAe,GAAG,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE;QAC7C,WAAW,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAA;IACrC,CAAC,EAAE,EAAE,CAAC,CAAA;IAEN,OAAO;QACL,QAAQ;QACR,+CAA+C;QAC/C,eAAe;QACf,yBAAyB;QACzB,WAAW;QACX,UAAU;QACV,eAAe;QACf,sBAAsB;QACtB,mBAAmB,EAAE,CAAC,CAAC,CAAA,oBAAoB,aAApB,oBAAoB,uBAApB,oBAAoB,CAAE,qBAAqB,CAAA;QAClE,4BAA4B;QAC5B,sBAAsB;QACtB,WAAW;QACX,iBAAiB,EAAE,CAAC,CAAC,CAAA,oBAAoB,aAApB,oBAAoB,uBAApB,oBAAoB,CAAE,eAAe,CAAA;QAC1D,mBAAmB;QACnB,aAAa;QACb,0BAA0B;QAC1B,uBAAuB;QACvB,kBAAkB;QAClB,kBAAkB;QAClB,mBAAmB;QACnB,wBAAwB;QACxB,+BAA+B;QAC/B,2BAA2B;QAC3B,sBAAsB;QACtB,+BAA+B;QAC/B,yBAAyB,EAAE,CAAC,CAAC,8BAA8B;QAC3D,4BAA4B;QAC5B,sBAAsB;QACtB,aAAa;QACb,kBAAkB;QAClB,kBAAkB;QAClB,cAAc;QACd,qBAAqB;QACrB,8BAA8B;KAC/B,CAAA;AACH,CAAC","sourcesContent":["import * as React from 'react'\nimport { authService, Sentry } from '../apps'\n\nimport useIsMounted from './useIsMounted'\nimport useBooleanState from './useBooleanState'\n\n/**\n * This function is a react hook to help writing your own login screen.\n *\n * ## Example\n *\n * ```jsx\n * import * as React from 'react'\n * import { useHistory } from 'react-router-dom'\n * import { useLogin } from '@oneblink/apps-react'\n *\n * function App() {\n * const history = useHistory()\n *\n * const [username, setUsername] = React.useState('')\n * const [password, setPassword] = React.useState('')\n * const [newPasswordConfirmed, setNewPasswordConfirmed] = React.useState('')\n * const [newPassword, setNewPassword] = React.useState('')\n * const [code, setCode] = React.useState('')\n *\n * const onLogin = React.useCallback(() => {\n * history.push('/')\n * }, [history])\n *\n * const {\n * // Login\n * loginWithGoogle,\n * loginWithUsernamePassword,\n * isLoggingIn,\n * // Reset Temp Password\n * isPasswordTemporary,\n * isResettingTemporaryPassword,\n * resetTemporaryPassword,\n * // MFA Password\n * isMfaCodeRequired,\n * isSubmittingMfaCode,\n * submitMfaCode,\n * // Login Errors\n * loginError,\n * clearLoginError,\n * // Showing Forgot Password\n * isShowingForgotPassword,\n * showForgotPassword,\n * hideForgotPassword,\n * // Sending Forgot Password Code\n * isSendingForgotPasswordCode,\n * sendForgotPasswordCode,\n * // Resetting Forgotten Password\n * hasSentForgotPasswordCode,\n * isResettingForgottenPassword,\n * resetForgottenPassword,\n * // Forgot Password Errors\n * forgotPasswordError,\n * clearForgotPasswordError,\n * // Validation\n * usernameValidation,\n * passwordValidation,\n * codeValidation,\n * newPasswordValidation,\n * newPasswordConfirmedValidation,\n * } = useLogin({\n * username,\n * password,\n * newPassword,\n * newPasswordConfirmed,\n * code,\n * onLogin,\n * })\n *\n * if (hasSentForgotPasswordCode) {\n * return (\n * <form\n * onSubmit={(e) => {\n * e.preventDefault()\n * resetForgottenPassword()\n * }}\n * >\n * <p>We have sent you a password reset code via email. Enter it below to reset your password.</p>\n *\n * <input\n * type=\"password\"\n * placeholder=\"Code\"\n * value={code}\n * onChange={(e) => setCode(e.target.value)}\n * />\n *\n * <input\n * type=\"password\"\n * placeholder=\"New Password\"\n * value={newPassword}\n * onChange={(e) => setNewPassword(e.target.value)}\n * />\n *\n * <input\n * type=\"password\"\n * placeholder=\"Confirm Password\"\n * value={newPassword}\n * onChange={(e) => setNewPasswordConfirmed(e.target.value)}\n * />\n *\n * <button\n * type=\"submit\"\n * disabled={isResettingForgottenPassword || codeValidation.isInvalid || newPasswordValidation.isInvalid || newPasswordConfirmedValidation.isInvalid}\n * >\n * Change Password\n * </button>\n *\n * <p>Password Requirements</p>\n * <p>Contains a lowercase letter: {validation.hasLowercaseLetter ? 'Yes' : 'No'}</p>\n * <p>Contains an upper case letter: {validation.hasUpperCaseLetter ? 'Yes' : 'No'}</p>\n * <p>Contains a number: {validation.hasNumber ? 'Yes' : 'No'}</p>\n * <p>Contains a special character: {validation.hasSpecialCharacter ? 'Yes' : 'No'}</p>\n * <p>Contains at least 8 characters: {validation.hasMinLength ? 'Yes' : 'No'}</p>\n *\n * {forgotPasswordError && (\n * <p>{forgotPasswordError.message}</p>\n * <button type=\"button\" onClick={clearForgotPasswordError}>Clear Error</button>\n * )}\n * </form>\n * )\n * }\n *\n * if (isShowingForgotPassword) {\n * return (\n * <form\n * onSubmit={(e) => {\n * e.preventDefault()\n * sendForgotPasswordCode()\n * }}\n * >\n * <p>Enter your email address and we will send you a code to reset your password.</p>\n *\n * <input\n * type=\"email\"\n * placeholder=\"Email Address\"\n * value={username}\n * onChange={(e) => setUsername(e.target.value)}\n * />\n *\n * <p>\n * <a onClick={hideForgotPassword}>Remembered your password?</a>\n * </p>\n *\n * <button\n * type=\"submit\"\n * disabled={isSendingForgotPasswordCode || usernameValidation.isInvalid}\n * >\n * Reset Password\n * </button>\n *\n * {forgotPasswordError && (\n * <p>{forgotPasswordError.message}</p>\n * <button type=\"button\" onClick={clearForgotPasswordError}>Clear Error</button>\n * )}\n * </form>\n * )\n * }\n *\n * if (isPasswordTemporary) {\n * return (\n * <form\n * onSubmit={(e) => {\n * e.preventDefault()\n * resetTemporaryPassword()\n * }}\n * >\n * <p>The password you entered was only temporary and must be reset for security purposes. Please enter your new password below to continue.</p>\n *\n * <input\n * type=\"password\"\n * placeholder=\"New Password\"\n * value={newPassword}\n * onChange={(e) => setNewPassword(e.target.value)}\n * />\n *\n * <input\n * type=\"password\"\n * placeholder=\"Confirm Password\"\n * value={newPassword}\n * onChange={(e) => setNewPasswordConfirmed(e.target.value)}\n * />\n *\n * <button\n * type=\"submit\"\n * disabled={isResettingTemporaryPassword || newPasswordValidation.isInvalid || newPasswordConfirmedValidation.isInvalid}\n * >\n * Change Password &amp; Sign In\n * </button>\n *\n * <p>Password Requirements</p>\n * <p>Contains a lowercase letter: {validation.hasLowercaseLetter ? 'Yes' : 'No'}</p>\n * <p>Contains an upper case letter: {validation.hasUpperCaseLetter ? 'Yes' : 'No'}</p>\n * <p>Contains a number: {validation.hasNumber ? 'Yes' : 'No'}</p>\n * <p>Contains a special character: {validation.hasSpecialCharacter ? 'Yes' : 'No'}</p>\n * <p>Contains at least 8 characters: {validation.hasMinLength ? 'Yes' : 'No'}</p>\n *\n * {loginError && (\n * <p>{loginError.message}</p>\n * <button type=\"button\" onClick={clearLoginError}>Clear Error</button>\n * )}\n * </form>\n * )\n * }\n *\n * if (isMfaCodeRequired) {\n * return (\n * <form\n * onSubmit={(e) => {\n * e.preventDefault()\n * submitMfaCode()\n * }}\n * >\n * <p>Enter the 6-digit code found in your authenticator app.</p>\n *\n * <input\n * type=\"password\"\n * placeholder=\"Code\"\n * value={code}\n * onChange={(e) => setCode(e.target.value)}\n * />\n *\n * <button\n * type=\"submit\"\n * disabled={isSubmittingMfaCode || codeValidation.isInvalid}\n * >\n * Sign In\n * </button>\n *\n * {loginError && (\n * <p>{loginError.message}</p>\n * <button type=\"button\" onClick={clearLoginError}>Clear Error</button>\n * )}\n * </form>\n * )\n * }\n *\n * return (\n * <form\n * onSubmit={(e) => {\n * e.preventDefault()\n * loginWithUsernamePassword()\n * }}\n * >\n * <p>Sign in with your email address and password.</p>\n * <input\n * type=\"email\"\n * placeholder=\"Email Address\"\n * value={username}\n * onChange={(e) => setUsername(e.target.value)}\n * />\n *\n * <input\n * type=\"password\"\n * placeholder=\"New Password\"\n * value={newPassword}\n * onChange={(e) => setNewPassword(e.target.value)}\n * />\n *\n * <p>\n * <a onClick={showForgotPassword}>Forgot your password?</a>\n * </p>\n *\n * <button\n * type=\"submit\"\n * disabled={isLoggingIn || usernameValidation.isInvalid || passwordValidation.isInvalid}\n * >\n * {children}\n * </button>\n *\n * <p>or</p>\n *\n * <button\n * type=\"button\"\n * onClick={loginWithGoogle}\n * >\n * <img\n * alt=\"Google\"\n * src=\"google-sign-in.png\"\n * />\n * <span>Sign in with Google</span>\n * </button>\n *\n * {loginError && (\n * <p>{loginError.message}</p>\n * <button type=\"button\" onClick={clearLoginError}>Clear Error</button>\n * )}\n * </form>\n * )\n * }\n *\n * const root = document.getElementById('root')\n * if (root) {\n * ReactDOM.render(<App />, root)\n * }\n * ```\n *\n * @param options\n * @returns\n * @group Hooks\n */\nexport default function useLogin({\n username,\n password,\n newPassword,\n newPasswordConfirmed,\n code,\n formsAppId,\n}: {\n /** The email address entered by the user. */\n username: string\n /** The password entered by the user. */\n password: string\n /** The new password entered by the user if changing their password. */\n newPassword: string\n /**\n * The new password repeated by the user if changing their password to ensure\n * they do type it in wrong.\n */\n newPasswordConfirmed: string\n /**\n * The code sent to the user after requesting a password reset by starting the\n * \"forgot password\" process.\n */\n code: string\n /** The identifier for the current forms app */\n formsAppId?: number\n}): UseLoginValue {\n const isMounted = useIsMounted()\n\n // Validation\n const usernameValidation = React.useMemo(() => {\n return {\n isInvalid: !username.trim(),\n }\n }, [username])\n\n const passwordValidation = React.useMemo(() => {\n return {\n isInvalid: !password.trim(),\n }\n }, [password])\n\n const codeValidation = React.useMemo(() => {\n return {\n isInvalid: !code.trim(),\n }\n }, [code])\n\n const newPasswordValidation = React.useMemo(() => {\n const validation = {\n hasLowercaseLetter: /[a-z]+/.test(newPassword),\n hasUpperCaseLetter: /[A-Z]+/.test(newPassword),\n hasNumber: /\\d+/.test(newPassword),\n hasSpecialCharacter: /[\\^$*.[\\]{}()?|\\-\"!@#%&/,><':;|_~`]+/.test(\n newPassword,\n ),\n hasMinLength: newPassword.length >= 8,\n isInvalid: true,\n }\n validation.isInvalid =\n !validation.hasLowercaseLetter ||\n !validation.hasUpperCaseLetter ||\n !validation.hasNumber ||\n !validation.hasSpecialCharacter ||\n !validation.hasMinLength\n return validation\n }, [newPassword])\n\n const newPasswordConfirmedValidation = React.useMemo(() => {\n return {\n isInvalid: newPassword !== newPasswordConfirmed,\n }\n }, [newPassword, newPasswordConfirmed])\n\n // Login, Reset Password, MFA\n const [\n {\n isResettingTemporaryPassword,\n isLoggingIn,\n loginError,\n loginAttemptResponse,\n isSubmittingMfaCode,\n },\n setLoginState,\n ] = React.useState<{\n isResettingTemporaryPassword: boolean\n isLoggingIn: boolean\n loginError: null | Error\n loginAttemptResponse: authService.LoginAttemptResponse | undefined\n isSubmittingMfaCode: boolean\n }>({\n isResettingTemporaryPassword: false,\n isLoggingIn: false,\n loginError: null,\n loginAttemptResponse: undefined,\n isSubmittingMfaCode: false,\n })\n const clearLoginError = React.useCallback(\n () =>\n setLoginState((current) => ({\n ...current,\n loginError: null,\n })),\n [],\n )\n const loginWithUsernamePassword = React.useCallback(async () => {\n if (usernameValidation.isInvalid) {\n setLoginState((current) => ({\n ...current,\n loginError: new Error('Please enter a valid email address'),\n }))\n return\n }\n if (passwordValidation.isInvalid) {\n setLoginState((current) => ({\n ...current,\n loginError: new Error('Please enter a valid password'),\n }))\n return\n }\n\n setLoginState((currentState) => ({\n ...currentState,\n isLoggingIn: true,\n loginError: null,\n }))\n\n try {\n const newLoginAttemptResponse = await authService.loginUsernamePassword(\n username,\n password,\n )\n if (isMounted.current) {\n setLoginState((currentState) => ({\n ...currentState,\n isLoggingIn: false,\n loginAttemptResponse: newLoginAttemptResponse,\n }))\n }\n } catch (error) {\n Sentry.captureException(error)\n if (isMounted.current) {\n setLoginState((currentState) => ({\n ...currentState,\n isLoggingIn: false,\n loginError: error as Error,\n }))\n }\n }\n }, [\n isMounted,\n password,\n passwordValidation.isInvalid,\n username,\n usernameValidation.isInvalid,\n ])\n\n const resetTemporaryPassword = React.useCallback(async () => {\n const resetTemporaryPasswordCallback =\n loginAttemptResponse?.resetPasswordCallback\n if (!resetTemporaryPasswordCallback) {\n return\n }\n\n if (newPasswordValidation.isInvalid) {\n setLoginState((current) => ({\n ...current,\n loginError: new Error('Please enter a valid password'),\n }))\n return\n }\n\n if (newPasswordConfirmedValidation.isInvalid) {\n setLoginState((current) => ({\n ...current,\n loginError: new Error('Please confirm your new password'),\n }))\n return\n }\n\n setLoginState((current) => ({\n ...current,\n isResettingPassword: true,\n loginError: null,\n }))\n\n try {\n const resetPasswordResponse =\n await resetTemporaryPasswordCallback(newPassword)\n if (isMounted.current) {\n setLoginState((currentState) => ({\n ...currentState,\n isResettingTemporaryPassword: false,\n loginAttemptResponse: resetPasswordResponse,\n }))\n }\n } catch (error) {\n Sentry.captureException(error)\n if (isMounted.current) {\n setLoginState((current) => ({\n ...current,\n isResettingPassword: false,\n loginError: error as Error,\n }))\n }\n }\n }, [\n isMounted,\n loginAttemptResponse?.resetPasswordCallback,\n newPassword,\n newPasswordConfirmedValidation.isInvalid,\n newPasswordValidation.isInvalid,\n ])\n\n const submitMfaCode = React.useCallback(async () => {\n const mfaCodeCallback = loginAttemptResponse?.mfaCodeCallback\n if (!mfaCodeCallback) {\n return\n }\n\n setLoginState((current) => ({\n ...current,\n isSubmittingMfaCode: true,\n loginError: null,\n }))\n\n try {\n const mfaResponse = await mfaCodeCallback(code)\n if (isMounted.current) {\n setLoginState((currentState) => ({\n ...currentState,\n isSubmittingMfaCode: false,\n loginAttemptResponse: mfaResponse,\n }))\n }\n } catch (error) {\n Sentry.captureException(error)\n if (isMounted.current) {\n setLoginState((current) => ({\n ...current,\n isSubmittingMfaCode: false,\n loginError: error as Error,\n }))\n }\n }\n }, [code, isMounted, loginAttemptResponse?.mfaCodeCallback])\n\n // Forgot Password\n const [isShowingForgotPassword, showForgotPassword, hideForgotPassword] =\n useBooleanState(false)\n const [\n {\n resetForgottenPasswordCallback,\n isSendingForgotPasswordCode,\n isResettingForgottenPassword,\n forgotPasswordError,\n },\n setForgotPasswordState,\n ] = React.useState<{\n isSendingForgotPasswordCode: boolean\n forgotPasswordError: null | Error\n resetForgottenPasswordCallback:\n | null\n | ((code: string, newPassword: string) => void)\n isResettingForgottenPassword: boolean\n }>({\n isSendingForgotPasswordCode: false,\n forgotPasswordError: null,\n resetForgottenPasswordCallback: null,\n isResettingForgottenPassword: false,\n })\n const clearForgotPasswordError = React.useCallback(\n () =>\n setForgotPasswordState((current) => ({\n ...current,\n forgotPasswordError: null,\n })),\n [],\n )\n const sendForgotPasswordCode = React.useCallback(async () => {\n if (usernameValidation.isInvalid) {\n setForgotPasswordState((current) => ({\n ...current,\n forgotPasswordError: new Error('Please enter a valid email address'),\n }))\n return\n }\n\n setForgotPasswordState({\n isSendingForgotPasswordCode: true,\n resetForgottenPasswordCallback: null,\n forgotPasswordError: null,\n isResettingForgottenPassword: false,\n })\n\n try {\n const newResetForgottenPasswordCallback =\n await authService.forgotPassword(username, formsAppId)\n if (isMounted.current) {\n setForgotPasswordState({\n isSendingForgotPasswordCode: false,\n resetForgottenPasswordCallback: newResetForgottenPasswordCallback,\n forgotPasswordError: null,\n isResettingForgottenPassword: false,\n })\n }\n } catch (error) {\n Sentry.captureException(error)\n if (isMounted.current) {\n setForgotPasswordState({\n isSendingForgotPasswordCode: false,\n resetForgottenPasswordCallback: null,\n forgotPasswordError: error as Error,\n isResettingForgottenPassword: false,\n })\n }\n }\n }, [isMounted, username, usernameValidation.isInvalid, formsAppId])\n\n const resetForgottenPassword = React.useCallback(async () => {\n if (!resetForgottenPasswordCallback) {\n return\n }\n\n if (codeValidation.isInvalid) {\n setForgotPasswordState((current) => ({\n ...current,\n forgotPasswordError: new Error(\n 'Please enter the code that was sent to your email address',\n ),\n }))\n }\n if (newPasswordValidation.isInvalid) {\n setForgotPasswordState((current) => ({\n ...current,\n forgotPasswordError: new Error('Please enter a valid password'),\n }))\n return\n }\n if (newPasswordConfirmedValidation.isInvalid) {\n setForgotPasswordState((current) => ({\n ...current,\n forgotPasswordError: new Error('Please confirm your new password'),\n }))\n return\n }\n\n setForgotPasswordState((current) => ({\n ...current,\n isChangingPassword: true,\n forgotPasswordError: null,\n }))\n\n try {\n await resetForgottenPasswordCallback(code, newPassword)\n if (isMounted.current) {\n setForgotPasswordState({\n isSendingForgotPasswordCode: false,\n resetForgottenPasswordCallback: null,\n forgotPasswordError: null,\n isResettingForgottenPassword: false,\n })\n hideForgotPassword()\n }\n } catch (error) {\n Sentry.captureException(error)\n if (isMounted.current) {\n setForgotPasswordState((current) => ({\n ...current,\n isChangingPassword: false,\n forgotPasswordError: error as Error,\n }))\n }\n }\n }, [\n resetForgottenPasswordCallback,\n codeValidation.isInvalid,\n newPasswordValidation.isInvalid,\n newPasswordConfirmedValidation.isInvalid,\n code,\n newPassword,\n isMounted,\n hideForgotPassword,\n ])\n\n const loginWithGoogle = React.useCallback(() => {\n authService.loginHostedUI('Google')\n }, [])\n\n return {\n // Login\n /** Open redirect user to the Google sign in */\n loginWithGoogle,\n loginWithUsernamePassword,\n isLoggingIn,\n loginError,\n clearLoginError,\n // Reset Temp Password\n isPasswordTemporary: !!loginAttemptResponse?.resetPasswordCallback,\n isResettingTemporaryPassword,\n resetTemporaryPassword,\n // MFA Code\n isMfaCodeRequired: !!loginAttemptResponse?.mfaCodeCallback,\n isSubmittingMfaCode,\n submitMfaCode,\n // Showing Forgot Password\n isShowingForgotPassword,\n showForgotPassword,\n hideForgotPassword,\n forgotPasswordError,\n clearForgotPasswordError,\n // Sending Forgot Password Code\n isSendingForgotPasswordCode,\n sendForgotPasswordCode,\n // Resetting Forgotten Password\n hasSentForgotPasswordCode: !!resetForgottenPasswordCallback,\n isResettingForgottenPassword,\n resetForgottenPassword,\n // Validation\n usernameValidation,\n passwordValidation,\n codeValidation,\n newPasswordValidation,\n newPasswordConfirmedValidation,\n }\n}\n\nexport interface UseLoginValue {\n /** Open redirect user to the Google sign-in page. */\n loginWithGoogle: () => void\n /**\n * Attempt to use the `username` and `password` arguments to create a session.\n * Will call `onLogin()` if successful, otherwise will set `loginError`.\n */\n loginWithUsernamePassword: () => void\n /** `true` while processing `loginWithUsernamePassword()`. */\n isLoggingIn: boolean\n /**\n * `true` if the user logged in using a temporary password. Prompt the user\n * for a new password and call `resetTemporaryPassword()`.\n */\n isPasswordTemporary: boolean\n /**\n * Attempt to use `newPassword` and `newPasswordConfirmed` arguments to reset\n * the user's password and create a session. Will call `onLogin()` if\n * successful, otherwise will set `loginError`.\n */\n resetTemporaryPassword: () => void\n /**\n * Set if an error occurs while processing `loginWithUsernamePassword()` or\n * `resetTemporaryPassword()`.\n */\n loginError: Error | null\n /** Set `loginError` back to `null`. */\n clearLoginError: () => void\n /** `true` while processing `resetTemporaryPassword()`. */\n isResettingTemporaryPassword: boolean\n /** `true` when showing the forgot password flow. */\n isShowingForgotPassword: boolean\n /** Set `isShowingForgotPassword` to `true`. */\n showForgotPassword: () => void\n /** Set `isShowingForgotPassword` to `false`. */\n hideForgotPassword: () => void\n /**\n * Attempt to use the `username` argument to start the forgot password\n * process. This will send the user an email with a code to enter. A failed\n * request will set `forgotPasswordError`.\n */\n sendForgotPasswordCode: () => void\n /** `true` while processing `sendForgotPasswordCode()`. */\n isSendingForgotPasswordCode: boolean\n /** `true` if the forgot password code has been successfully sent to the user. */\n hasSentForgotPasswordCode: boolean\n /**\n * Attempt to use the `code`, `newPassword`, and `newPasswordConfirmed`\n * arguments to reset the user's password. A failed request will set\n * `forgotPasswordError`.\n */\n resetForgottenPassword: () => void\n /** `true` while processing `resetForgottenPassword()`. */\n isResettingForgottenPassword: boolean\n /**\n * Set if an error occurs while processing `sendForgotPasswordCode()` or\n * `resetForgottenPassword()`.\n */\n forgotPasswordError: Error | null\n /** Set `forgotPasswordError` back to `null`. */\n clearForgotPasswordError: () => void\n usernameValidation: {\n /** `true` if the `username` argument is invalid. */\n isInvalid: boolean\n }\n passwordValidation: {\n /** `true` if the `password` argument is invalid. */\n isInvalid: boolean\n }\n codeValidation: {\n /** `true` if the `code` argument is invalid. */\n isInvalid: boolean\n }\n newPasswordValidation: {\n /** `true` if the `newPassword` argument is invalid. */\n isInvalid: boolean\n /**\n * `true` if the `newPassword` argument has a lowercase letter (required to\n * be valid).\n */\n hasLowercaseLetter: boolean\n /**\n * `true` if the `newPassword` argument has an uppercase letter (required to\n * be valid).\n */\n hasUpperCaseLetter: boolean\n /** `true` if the `newPassword` argument has a number (required to be valid). */\n hasNumber: boolean\n /**\n * `true` if the `newPassword` argument has a special character (required to\n * be valid).\n */\n hasSpecialCharacter: boolean\n /**\n * `true` if the `newPassword` argument has at least the minimum number of\n * characters (required to be valid).\n */\n hasMinLength: boolean\n }\n newPasswordConfirmedValidation: {\n /**\n * `true` if the `newPasswordConfirmed` argument is invalid (must match the\n * `newPassword` argument).\n */\n isInvalid: boolean\n }\n /**\n * `true` if the user logged in using MFA and a code is required to finish the\n * login attempt. Prompt the user for a code and call `submitMfaCode()`.\n */\n isMfaCodeRequired: boolean\n /** `true` while processing `submitMfaCode()`. */\n isSubmittingMfaCode: boolean\n /**\n * Attempt to use `code` argument to submit the MFA code and create a session.\n * Will call `onLogin()` if successful, otherwise will set `loginError`.\n */\n submitMfaCode: () => void\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { authService } from '@oneblink/apps';
2
+ import { authService } from '../apps';
3
3
  type MfaState = {
4
4
  isExternalIdentityProviderUser: boolean;
5
5
  isLoading: boolean;
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import * as React from 'react';
3
- import { authService } from '@oneblink/apps';
3
+ import { authService } from '../apps';
4
4
  export const MfaContext = React.createContext({
5
5
  isExternalIdentityProviderUser: false,
6
6
  isLoading: true,
@@ -1 +1 @@
1
- {"version":3,"file":"useMfa.js","sourceRoot":"","sources":["../../src/hooks/useMfa.ts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CACpG,CAAA;IACH,CAAC;IAED,MAAM,EAAE,YAAY,EAAE,8BAA8B,EAAE,GAAG,OAAO,CAAA;IAChE,IAAI,CAAC,aAAa,IAAI,8BAA8B,EAAE,CAAC;QACrD,OAAO,IAAI,CAAA;IACb,CAAC;IACD,OAAO,YAAY,CAAA;AACrB,CAAC","sourcesContent":["import * as React from 'react'\nimport { authService } from '@oneblink/apps'\n\ntype MfaState = {\n isExternalIdentityProviderUser: boolean\n isLoading: boolean\n isMfaEnabled: boolean\n loadingError?: Error\n isSettingUpMfa: boolean\n isDisablingMfa: boolean\n setupError?: Error\n mfaSetup?: Awaited<ReturnType<typeof authService.setupMfa>>\n}\n\nexport const MfaContext = React.createContext<\n MfaState & {\n beginMfaSetup: () => void\n cancelMfaSetup: () => void\n completeMfaSetup: () => void\n beginDisablingMfa: () => void\n cancelDisablingMfa: () => void\n completeDisablingMfa: () => void\n clearMfaSetupError: () => void\n loadMfa: () => void\n }\n>({\n isExternalIdentityProviderUser: false,\n isLoading: true,\n isMfaEnabled: false,\n isSettingUpMfa: false,\n isDisablingMfa: false,\n beginMfaSetup: () => {},\n cancelMfaSetup: () => {},\n completeMfaSetup: () => {},\n beginDisablingMfa: () => {},\n cancelDisablingMfa: () => {},\n completeDisablingMfa: () => {},\n clearMfaSetupError: () => {},\n loadMfa: () => {},\n})\n\n/**\n * React Component that provides the context for the\n * `useUserMeetsMfaRequirement()` hook and `<MultiFactorAuthentication />`\n * component, to be used by components further down your component tree. **It\n * should only be included in your component tree once and ideally at the root\n * of the application.**\n *\n * #### Example\n *\n * ```js\n * import * as React from 'react'\n * import {\n * MfaProvider,\n * useUserMeetsMfaRequirement,\n * } from '@oneblink/apps-react'\n *\n * function Component() {\n * const { isLoading, userMeetsMfaRequirement } =\n * useUserMeetsMfaRequirement(true)\n * // use MFA Requirement details here\n * }\n *\n * function App() {\n * return (\n * <MfaProvider isExternalIdentityProviderUser={false}>\n * <Component />\n * </MfaProvider>\n * )\n * }\n *\n * const root = document.getElementById('root')\n * if (root) {\n * ReactDOM.render(<App />, root)\n * }\n * ```\n *\n * @param props\n * @returns\n * @group Components\n */\nexport function MfaProvider({\n children,\n isExternalIdentityProviderUser,\n}: {\n children: React.ReactNode\n isExternalIdentityProviderUser: boolean\n}) {\n const [state, setState] = React.useState<MfaState>({\n isExternalIdentityProviderUser,\n isLoading: !isExternalIdentityProviderUser,\n isMfaEnabled: false,\n isSettingUpMfa: false,\n isDisablingMfa: false,\n })\n\n const loadMfa = React.useCallback(async (abortSignal?: AbortSignal) => {\n setState((currentState) => ({\n ...currentState,\n isLoading: true,\n isMfaEnabled: false,\n loadingError: undefined,\n }))\n try {\n const newIsMfaEnabled = await authService.checkIsMfaEnabled()\n if (!abortSignal?.aborted) {\n setState((currentState) => ({\n ...currentState,\n isLoading: false,\n isMfaEnabled: newIsMfaEnabled,\n }))\n }\n } catch (error) {\n setState((currentState) => ({\n ...currentState,\n isLoading: false,\n loadingError: error as Error,\n }))\n }\n }, [])\n\n const clearMfaSetupError = React.useCallback(() => {\n setState((currentState) => ({\n ...currentState,\n setupError: undefined,\n }))\n }, [])\n\n const cancelMfaSetup = React.useCallback(() => {\n setState((currentState) => ({\n ...currentState,\n mfaSetup: undefined,\n }))\n }, [])\n\n const completeMfaSetup = React.useCallback(() => {\n setState((currentState) => ({\n ...currentState,\n isMfaEnabled: true,\n mfaSetup: undefined,\n }))\n }, [])\n\n const beginMfaSetup = React.useCallback(async () => {\n setState((currentState) => ({\n ...currentState,\n isSettingUpMfa: true,\n mfaSetup: undefined,\n setupError: undefined,\n }))\n try {\n const newMfaSetup = await authService.setupMfa()\n setState((currentState) => ({\n ...currentState,\n isSettingUpMfa: false,\n mfaSetup: newMfaSetup,\n }))\n } catch (error) {\n setState((currentState) => ({\n ...currentState,\n isSettingUpMfa: false,\n setupError: error as Error,\n }))\n }\n }, [])\n\n const beginDisablingMfa = React.useCallback(() => {\n setState((currentState) => ({\n ...currentState,\n isDisablingMfa: true,\n }))\n }, [])\n\n const cancelDisablingMfa = React.useCallback(() => {\n setState((currentState) => ({\n ...currentState,\n isDisablingMfa: false,\n }))\n }, [])\n\n const completeDisablingMfa = React.useCallback(async () => {\n await authService.disableMfa()\n setState((currentState) => ({\n ...currentState,\n isDisablingMfa: false,\n isMfaEnabled: false,\n }))\n }, [])\n\n React.useEffect(() => {\n if (isExternalIdentityProviderUser) {\n return\n }\n\n loadMfa()\n\n return () => {}\n }, [isExternalIdentityProviderUser, loadMfa])\n\n const value = React.useMemo(() => {\n return {\n ...state,\n clearMfaSetupError,\n loadMfa,\n beginMfaSetup,\n cancelMfaSetup,\n completeMfaSetup,\n beginDisablingMfa,\n cancelDisablingMfa,\n completeDisablingMfa,\n }\n }, [\n state,\n clearMfaSetupError,\n loadMfa,\n beginMfaSetup,\n cancelMfaSetup,\n completeMfaSetup,\n beginDisablingMfa,\n cancelDisablingMfa,\n completeDisablingMfa,\n ])\n\n return <MfaContext.Provider value={value}>{children}</MfaContext.Provider>\n}\n\nexport default function useMfa() {\n return React.useContext(MfaContext)\n}\n\n/**\n * React hook to check if the logged in user meets the MFA requirement of your\n * application. Will throw an Error if used outside of the `<MfaProvider />`\n * component.\n *\n * Example\n *\n * ```js\n * import { useUserMeetsMfaRequirement } from '@oneblink/apps-react'\n *\n * const isMfaRequired = true\n *\n * function Component() {\n * const userMeetsMfaRequirement =\n * useUserMeetsMfaRequirement(isMfaRequired)\n * }\n * ```\n *\n * @returns\n * @group Hooks\n */\nexport function useUserMeetsMfaRequirement(isMfaRequired: boolean) {\n const context = React.useContext(MfaContext)\n\n if (!context) {\n throw new Error(\n `\"useUserMeetsMfaRequirement\" hook was used outside of the \"<MfaProvider />\" component's children.`,\n )\n }\n\n const { isMfaEnabled, isExternalIdentityProviderUser } = context\n if (!isMfaRequired || isExternalIdentityProviderUser) {\n return true\n }\n return isMfaEnabled\n}\n"]}
1
+ {"version":3,"file":"useMfa.js","sourceRoot":"","sources":["../../src/hooks/useMfa.tsx"],"names":[],"mappings":";AAA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AED,MAAM,EAAE,YAAY,EAAE,8BAA8B,EAAE,GAAG,OAAO,CAAA;IAChE,IAAI,CAAC,aAAa,IAAI,8BAA8B,EAAE,CAAC;QACrD,OAAO,IAAI,CAAA;IACb,CAAC;IACD,OAAO,YAAY,CAAA;AACrB,CAAC","sourcesContent":["import * as React from 'react'\nimport { authService } from '../apps'\n\ntype MfaState = {\n isExternalIdentityProviderUser: boolean\n isLoading: boolean\n isMfaEnabled: boolean\n loadingError?: Error\n isSettingUpMfa: boolean\n isDisablingMfa: boolean\n setupError?: Error\n mfaSetup?: Awaited<ReturnType<typeof authService.setupMfa>>\n}\n\nexport const MfaContext = React.createContext<\n MfaState & {\n beginMfaSetup: () => void\n cancelMfaSetup: () => void\n completeMfaSetup: () => void\n beginDisablingMfa: () => void\n cancelDisablingMfa: () => void\n completeDisablingMfa: () => void\n clearMfaSetupError: () => void\n loadMfa: () => void\n }\n>({\n isExternalIdentityProviderUser: false,\n isLoading: true,\n isMfaEnabled: false,\n isSettingUpMfa: false,\n isDisablingMfa: false,\n beginMfaSetup: () => {},\n cancelMfaSetup: () => {},\n completeMfaSetup: () => {},\n beginDisablingMfa: () => {},\n cancelDisablingMfa: () => {},\n completeDisablingMfa: () => {},\n clearMfaSetupError: () => {},\n loadMfa: () => {},\n})\n\n/**\n * React Component that provides the context for the\n * `useUserMeetsMfaRequirement()` hook and `<MultiFactorAuthentication />`\n * component, to be used by components further down your component tree. **It\n * should only be included in your component tree once and ideally at the root\n * of the application.**\n *\n * #### Example\n *\n * ```js\n * import * as React from 'react'\n * import {\n * MfaProvider,\n * useUserMeetsMfaRequirement,\n * } from '@oneblink/apps-react'\n *\n * function Component() {\n * const { isLoading, userMeetsMfaRequirement } =\n * useUserMeetsMfaRequirement(true)\n * // use MFA Requirement details here\n * }\n *\n * function App() {\n * return (\n * <MfaProvider isExternalIdentityProviderUser={false}>\n * <Component />\n * </MfaProvider>\n * )\n * }\n *\n * const root = document.getElementById('root')\n * if (root) {\n * ReactDOM.render(<App />, root)\n * }\n * ```\n *\n * @param props\n * @returns\n * @group Components\n */\nexport function MfaProvider({\n children,\n isExternalIdentityProviderUser,\n}: {\n children: React.ReactNode\n isExternalIdentityProviderUser: boolean\n}) {\n const [state, setState] = React.useState<MfaState>({\n isExternalIdentityProviderUser,\n isLoading: !isExternalIdentityProviderUser,\n isMfaEnabled: false,\n isSettingUpMfa: false,\n isDisablingMfa: false,\n })\n\n const loadMfa = React.useCallback(async (abortSignal?: AbortSignal) => {\n setState((currentState) => ({\n ...currentState,\n isLoading: true,\n isMfaEnabled: false,\n loadingError: undefined,\n }))\n try {\n const newIsMfaEnabled = await authService.checkIsMfaEnabled()\n if (!abortSignal?.aborted) {\n setState((currentState) => ({\n ...currentState,\n isLoading: false,\n isMfaEnabled: newIsMfaEnabled,\n }))\n }\n } catch (error) {\n setState((currentState) => ({\n ...currentState,\n isLoading: false,\n loadingError: error as Error,\n }))\n }\n }, [])\n\n const clearMfaSetupError = React.useCallback(() => {\n setState((currentState) => ({\n ...currentState,\n setupError: undefined,\n }))\n }, [])\n\n const cancelMfaSetup = React.useCallback(() => {\n setState((currentState) => ({\n ...currentState,\n mfaSetup: undefined,\n }))\n }, [])\n\n const completeMfaSetup = React.useCallback(() => {\n setState((currentState) => ({\n ...currentState,\n isMfaEnabled: true,\n mfaSetup: undefined,\n }))\n }, [])\n\n const beginMfaSetup = React.useCallback(async () => {\n setState((currentState) => ({\n ...currentState,\n isSettingUpMfa: true,\n mfaSetup: undefined,\n setupError: undefined,\n }))\n try {\n const newMfaSetup = await authService.setupMfa()\n setState((currentState) => ({\n ...currentState,\n isSettingUpMfa: false,\n mfaSetup: newMfaSetup,\n }))\n } catch (error) {\n setState((currentState) => ({\n ...currentState,\n isSettingUpMfa: false,\n setupError: error as Error,\n }))\n }\n }, [])\n\n const beginDisablingMfa = React.useCallback(() => {\n setState((currentState) => ({\n ...currentState,\n isDisablingMfa: true,\n }))\n }, [])\n\n const cancelDisablingMfa = React.useCallback(() => {\n setState((currentState) => ({\n ...currentState,\n isDisablingMfa: false,\n }))\n }, [])\n\n const completeDisablingMfa = React.useCallback(async () => {\n await authService.disableMfa()\n setState((currentState) => ({\n ...currentState,\n isDisablingMfa: false,\n isMfaEnabled: false,\n }))\n }, [])\n\n React.useEffect(() => {\n if (isExternalIdentityProviderUser) {\n return\n }\n\n loadMfa()\n\n return () => {}\n }, [isExternalIdentityProviderUser, loadMfa])\n\n const value = React.useMemo(() => {\n return {\n ...state,\n clearMfaSetupError,\n loadMfa,\n beginMfaSetup,\n cancelMfaSetup,\n completeMfaSetup,\n beginDisablingMfa,\n cancelDisablingMfa,\n completeDisablingMfa,\n }\n }, [\n state,\n clearMfaSetupError,\n loadMfa,\n beginMfaSetup,\n cancelMfaSetup,\n completeMfaSetup,\n beginDisablingMfa,\n cancelDisablingMfa,\n completeDisablingMfa,\n ])\n\n return <MfaContext.Provider value={value}>{children}</MfaContext.Provider>\n}\n\nexport default function useMfa() {\n return React.useContext(MfaContext)\n}\n\n/**\n * React hook to check if the logged in user meets the MFA requirement of your\n * application. Will throw an Error if used outside of the `<MfaProvider />`\n * component.\n *\n * Example\n *\n * ```js\n * import { useUserMeetsMfaRequirement } from '@oneblink/apps-react'\n *\n * const isMfaRequired = true\n *\n * function Component() {\n * const userMeetsMfaRequirement =\n * useUserMeetsMfaRequirement(isMfaRequired)\n * }\n * ```\n *\n * @returns\n * @group Hooks\n */\nexport function useUserMeetsMfaRequirement(isMfaRequired: boolean) {\n const context = React.useContext(MfaContext)\n\n if (!context) {\n throw new Error(\n `\"useUserMeetsMfaRequirement\" hook was used outside of the \"<MfaProvider />\" component's children.`,\n )\n }\n\n const { isMfaEnabled, isExternalIdentityProviderUser } = context\n if (!isMfaRequired || isExternalIdentityProviderUser) {\n return true\n }\n return isMfaEnabled\n}\n"]}
@@ -1,4 +1,4 @@
1
1
  import * as React from 'react';
2
- import { attachmentsService } from '@oneblink/apps';
2
+ import { attachmentsService } from '../apps';
3
3
  export declare const OnUploadAttachmentContext: React.Context<typeof attachmentsService.uploadAttachment | undefined>;
4
4
  export default function useOnUploadAttachmentContext(): typeof attachmentsService.uploadAttachment;
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { attachmentsService } from '@oneblink/apps';
2
+ import { attachmentsService } from '../apps';
3
3
  export const OnUploadAttachmentContext = React.createContext(undefined);
4
4
  export default function useOnUploadAttachmentContext() {
5
5
  return (React.useContext(OnUploadAttachmentContext) ||
@@ -1 +1 @@
1
- {"version":3,"file":"useOnUploadAttachment.js","sourceRoot":"","sources":["../../src/hooks/useOnUploadAttachment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAEnD,MAAM,CAAC,MAAM,yBAAyB,GAAG,KAAK,CAAC,aAAa,CAE1D,SAAS,CAAC,CAAA;AAEZ,MAAM,CAAC,OAAO,UAAU,4BAA4B;IAClD,OAAO,CACL,KAAK,CAAC,UAAU,CAAC,yBAAyB,CAAC;QAC3C,kBAAkB,CAAC,gBAAgB,CACpC,CAAA;AACH,CAAC","sourcesContent":["import * as React from 'react'\nimport { attachmentsService } from '@oneblink/apps'\n\nexport const OnUploadAttachmentContext = React.createContext<\n typeof attachmentsService.uploadAttachment | undefined\n>(undefined)\n\nexport default function useOnUploadAttachmentContext() {\n return (\n React.useContext(OnUploadAttachmentContext) ||\n attachmentsService.uploadAttachment\n )\n}\n"]}
1
+ {"version":3,"file":"useOnUploadAttachment.js","sourceRoot":"","sources":["../../src/hooks/useOnUploadAttachment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAE5C,MAAM,CAAC,MAAM,yBAAyB,GAAG,KAAK,CAAC,aAAa,CAE1D,SAAS,CAAC,CAAA;AAEZ,MAAM,CAAC,OAAO,UAAU,4BAA4B;IAClD,OAAO,CACL,KAAK,CAAC,UAAU,CAAC,yBAAyB,CAAC;QAC3C,kBAAkB,CAAC,gBAAgB,CACpC,CAAA;AACH,CAAC","sourcesContent":["import * as React from 'react'\nimport { attachmentsService } from '../apps'\n\nexport const OnUploadAttachmentContext = React.createContext<\n typeof attachmentsService.uploadAttachment | undefined\n>(undefined)\n\nexport default function useOnUploadAttachmentContext() {\n return (\n React.useContext(OnUploadAttachmentContext) ||\n attachmentsService.uploadAttachment\n )\n}\n"]}
@@ -1,4 +1,5 @@
1
- type OneBlinkFormContainerContextValue = HTMLElement | null;
1
+ import { RefObject } from 'react';
2
+ type OneBlinkFormContainerContextValue = RefObject<HTMLElement | null>;
2
3
  export declare const OneBlinkFormContainerContext: import("react").Context<OneBlinkFormContainerContextValue>;
3
4
  export default function useOneBlinkFormContainer(): OneBlinkFormContainerContextValue;
4
5
  export {};
@@ -1,5 +1,5 @@
1
- import { createContext, useContext } from 'react';
2
- export const OneBlinkFormContainerContext = createContext(null);
1
+ import { createContext, useContext, createRef } from 'react';
2
+ export const OneBlinkFormContainerContext = createContext(createRef());
3
3
  export default function useOneBlinkFormContainer() {
4
4
  return useContext(OneBlinkFormContainerContext);
5
5
  }
@@ -1 +1 @@
1
- {"version":3,"file":"useOneBlinkFormContainer.js","sourceRoot":"","sources":["../../src/hooks/useOneBlinkFormContainer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAIjD,MAAM,CAAC,MAAM,4BAA4B,GACvC,aAAa,CAAoC,IAAI,CAAC,CAAA;AAExD,MAAM,CAAC,OAAO,UAAU,wBAAwB;IAC9C,OAAO,UAAU,CAAC,4BAA4B,CAAC,CAAA;AACjD,CAAC","sourcesContent":["import { createContext, useContext } from 'react'\n\ntype OneBlinkFormContainerContextValue = HTMLElement | null\n\nexport const OneBlinkFormContainerContext =\n createContext<OneBlinkFormContainerContextValue>(null)\n\nexport default function useOneBlinkFormContainer() {\n return useContext(OneBlinkFormContainerContext)\n}\n"]}
1
+ {"version":3,"file":"useOneBlinkFormContainer.js","sourceRoot":"","sources":["../../src/hooks/useOneBlinkFormContainer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAa,SAAS,EAAE,MAAM,OAAO,CAAA;AAIvE,MAAM,CAAC,MAAM,4BAA4B,GACvC,aAAa,CAAoC,SAAS,EAAE,CAAC,CAAA;AAE/D,MAAM,CAAC,OAAO,UAAU,wBAAwB;IAC9C,OAAO,UAAU,CAAC,4BAA4B,CAAC,CAAA;AACjD,CAAC","sourcesContent":["import { createContext, useContext, RefObject, createRef } from 'react'\n\ntype OneBlinkFormContainerContextValue = RefObject<HTMLElement | null>\n\nexport const OneBlinkFormContainerContext =\n createContext<OneBlinkFormContainerContextValue>(createRef())\n\nexport default function useOneBlinkFormContainer() {\n return useContext(OneBlinkFormContainerContext)\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { submissionService } from '@oneblink/apps';
2
+ import { submissionService } from '../apps';
3
3
  /** The value returned from `usePendingSubmissions()` hook */
4
4
  export type PendingSubmissionsContextValue = {
5
5
  /** `true` if the pending submissions are currently loading */
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import * as React from 'react';
3
- import { submissionService } from '@oneblink/apps';
3
+ import { submissionService } from '../apps';
4
4
  import useBooleanState from './useBooleanState';
5
5
  import useIsMounted from './useIsMounted';
6
6
  import useIsOffline from './useIsOffline';
@@ -1 +1 @@
1
- {"version":3,"file":"usePendingSubmissions.js","sourceRoot":"","sources":["../../src/hooks/usePendingSubmissions.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAClD,OAAO,eAAe,MAAM,mBAAmB,CAAA;AAC/C,OAAO,YAAY,MAAM,gBAAgB,CAAA;AACzC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AAK,GAAG,KAAK,CAAC,OAAO,CACzB,GAAG,EAAE,CAAC,CAAC;QACL,GAAG,KAAK;QACR,2BAA2B;QAC3B,sBAAsB;QACtB,wBAAwB;QACxB,mBAAmB;QACnB,wBAAwB;QACxB,uBAAuB,EAAE,iBAAiB,CAAC,4BAA4B;QACvE,4BAA4B,EAAE,0BAA0B,GAAG,CAAC;QAC5D,uBAAuB;KACxB,CAAC,EACF;QACE,KAAK;QACL,2BAA2B;QAC3B,sBAAsB;QACtB,wBAAwB;QACxB,mBAAmB;QACnB,wBAAwB;QACxB,0BAA0B;QAC1B,uBAAuB;KACxB,CACF,CAAA;IAED,OAAO,CACL,KAAC,yBAAyB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAC7C,QAAQ,GAC0B,CACtC,CAAA;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,qBAAqB;IAC3C,MAAM,KAAK,GAAG,KAAK,CAAC,UAAU,CAAC,yBAAyB,CAAC,CAAA;IACzD,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CACb,oHAAoH,CACrH,CAAA;IACH,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["import * as React from 'react'\nimport { submissionService } from '@oneblink/apps'\nimport useBooleanState from './useBooleanState'\nimport useIsMounted from './useIsMounted'\nimport useIsOffline from './useIsOffline'\n\n/** The value returned from `usePendingSubmissions()` hook */\nexport type PendingSubmissionsContextValue = {\n /** `true` if the pending submissions are currently loading */\n isLoading: boolean\n /** An Error object if loading pending submissions fails */\n loadError: Error | null\n /**\n * The submissions that were submitted offline and can be processed when back\n * online\n */\n pendingSubmissions: submissionService.PendingFormSubmission[]\n /** `true` submissions that where submitted offline are being processed */\n isProcessingPendingQueue: boolean\n /** A function to trigger processing of the pending queue */\n processPendingQueue: () => unknown\n /**\n * A function to trigger loading of the submissions that were submitted\n * offline\n */\n reloadPendingSubmissions: () => unknown\n /** A function to remove a submission from the pending submissions */\n deletePendingSubmission: (pendingTimestamp: string) => unknown\n /** `true` if a submission being processed fails */\n isShowingFailedNotification: boolean\n /** A function to hide the notification when a submission fails to process */\n hideFailedNotification: () => unknown\n /** `true` if a submission being processed completes successfully. */\n isShowingSuccessNotification: boolean\n /**\n * A function to hide the notification after a submission completed\n * successfully\n */\n hideSuccessNotification: () => unknown\n}\n\nconst defaultState = {\n isLoading: false,\n loadError: null,\n pendingSubmissions: [],\n}\n\nconst PendingSubmissionsContext = React.createContext<\n PendingSubmissionsContextValue | undefined\n>(undefined)\n\n/**\n * React Component that provides the context for the `usePendingSubmissions()`\n * hook to be used by components further down your component tree. **It should\n * only be included in your component tree once and ideally at the root of the\n * application.**\n *\n * #### Example\n *\n * ```jsx\n * import * as React from 'react'\n * import {\n * PendingSubmissionsContextProvider,\n * usePendingSubmissions,\n * } from '@oneblink/apps-react'\n *\n * function Component() {\n * const pendingSubmissionsContext = usePendingSubmissions()\n * // use pending submissions here\n * }\n *\n * function App() {\n * return (\n * <PendingSubmissionsContextProvider\n * isPendingQueueEnabled\n * successNotificationTimeoutMs={3000}\n * >\n * <Component />\n * </PendingSubmissionsContextProvider>\n * )\n * }\n *\n * const root = document.getElementById('root')\n * if (root) {\n * ReactDOM.render(<App />, root)\n * }\n * ```\n *\n * @param props\n * @returns\n * @group Components\n */\nexport function PendingSubmissionsContextProvider({\n isPendingQueueEnabled,\n successNotificationTimeoutMs = 5000,\n children,\n}: {\n /**\n * `true` if pending queue is enabled, otherwise `false`. Can be used prevent\n * offline submissions from being processed.\n */\n isPendingQueueEnabled: boolean\n /**\n * When a submission is processed successfully the\n * `isShowingSuccessNotification` will be temporarily set to `true`, it will\n * be set back to `false` after 5 seconds. This prop will allow you to\n * customise how long to wait before hiding the notification with a\n * milliseconds value.\n */\n successNotificationTimeoutMs?: number\n /** Your application components */\n children: React.ReactNode\n}) {\n const isMounted = useIsMounted()\n const isOffline = useIsOffline()\n\n // Using a number as state so we can reset the timer used to close\n // the snack bar each time a pending queue item is processed\n const [submittedNotificationCount, setSubmittedNotificationCount] =\n React.useState(0)\n const hideSuccessNotification = React.useCallback(() => {\n setSubmittedNotificationCount(0)\n }, [])\n const [\n isShowingFailedNotification,\n showFailedNotification,\n hideFailedNotification,\n ] = useBooleanState(false)\n const [isProcessingPendingQueue, setIsProcessingPendingQueue] =\n React.useState(false)\n const [state, setState] = React.useState<{\n isLoading: boolean\n loadError: Error | null\n pendingSubmissions: submissionService.PendingFormSubmission[]\n }>(defaultState)\n\n const processPendingQueue = React.useCallback(async () => {\n if (isMounted.current) {\n setIsProcessingPendingQueue(true)\n }\n\n await submissionService.processPendingQueue({\n shouldRunExternalIdGeneration: true,\n shouldRunServerValidation: true,\n })\n\n if (isMounted.current) {\n setIsProcessingPendingQueue(false)\n }\n }, [isMounted])\n\n const reloadPendingSubmissions = React.useCallback(async () => {\n if (isMounted.current) {\n setState((currentState) => ({\n isLoading: true,\n loadError: null,\n pendingSubmissions: currentState.pendingSubmissions,\n }))\n }\n let newError = null\n let newPendingSubmissions: submissionService.PendingFormSubmission[] = []\n\n try {\n newPendingSubmissions =\n await submissionService.getPendingQueueSubmissions()\n } catch (error) {\n newError = error as Error\n }\n\n if (isMounted.current) {\n setState({\n isLoading: false,\n loadError: newError,\n pendingSubmissions: newPendingSubmissions,\n })\n }\n }, [isMounted])\n\n React.useEffect(() => {\n if (!isPendingQueueEnabled) {\n return\n }\n reloadPendingSubmissions()\n return submissionService.registerPendingQueueListener(\n (pendingSubmissions, action) => {\n switch (action) {\n case 'SUBMIT_SUCCEEDED': {\n setSubmittedNotificationCount((current) => current + 1)\n break\n }\n case 'SUBMIT_FAILED': {\n showFailedNotification()\n break\n }\n case 'SUBMIT_STARTED': {\n hideFailedNotification()\n break\n }\n // EDIT_CANCELLED is here for when beginnning edit offline and then hitting cancel while online\n // among other use cases\n case 'ADDITION':\n case 'EDIT_CANCELLED': {\n processPendingQueue()\n break\n }\n }\n setState({\n isLoading: false,\n pendingSubmissions,\n loadError: null,\n })\n },\n )\n }, [\n hideFailedNotification,\n isPendingQueueEnabled,\n processPendingQueue,\n reloadPendingSubmissions,\n showFailedNotification,\n ])\n\n React.useEffect(() => {\n if (!isOffline) {\n processPendingQueue()\n }\n }, [isOffline, processPendingQueue])\n\n React.useEffect(() => {\n if (submittedNotificationCount > 0) {\n const timeoutId = setTimeout(() => {\n hideSuccessNotification()\n }, successNotificationTimeoutMs)\n return () => {\n clearTimeout(timeoutId)\n }\n }\n }, [\n hideSuccessNotification,\n submittedNotificationCount,\n successNotificationTimeoutMs,\n ])\n\n const value = React.useMemo<PendingSubmissionsContextValue>(\n () => ({\n ...state,\n isShowingFailedNotification,\n hideFailedNotification,\n isProcessingPendingQueue,\n processPendingQueue,\n reloadPendingSubmissions,\n deletePendingSubmission: submissionService.deletePendingQueueSubmission,\n isShowingSuccessNotification: submittedNotificationCount > 0,\n hideSuccessNotification,\n }),\n [\n state,\n isShowingFailedNotification,\n hideFailedNotification,\n isProcessingPendingQueue,\n processPendingQueue,\n reloadPendingSubmissions,\n submittedNotificationCount,\n hideSuccessNotification,\n ],\n )\n\n return (\n <PendingSubmissionsContext.Provider value={value}>\n {children}\n </PendingSubmissionsContext.Provider>\n )\n}\n\n/**\n * React hook to get the context value for Pending Submissions. Will throw an\n * Error if used outside of the `<PendingSubmissionsContextProvider />`\n * component.\n *\n * @returns\n * @group Hooks\n */\nexport default function usePendingSubmissions(): PendingSubmissionsContextValue {\n const value = React.useContext(PendingSubmissionsContext)\n if (!value) {\n throw new Error(\n `\"usePendingSubmissions\" hook was used outside of the \"<PendingSubmissionsContextProvider />\" component's children.`,\n )\n }\n return value\n}\n"]}
1
+ {"version":3,"file":"usePendingSubmissions.js","sourceRoot":"","sources":["../../src/hooks/usePendingSubmissions.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAC3C,OAAO,eAAe,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B;QACvB,0BAA0B;QAC1B,4BAA4B;KAC7B,CAAC,CAAA;IAEF,MAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CACzB,GAAG,EAAE,CAAC,CAAC;QACL,GAAG,KAAK;QACR,2BAA2B;QAC3B,sBAAsB;QACtB,wBAAwB;QACxB,mBAAmB;QACnB,wBAAwB;QACxB,uBAAuB,EAAE,iBAAiB,CAAC,4BAA4B;QACvE,4BAA4B,EAAE,0BAA0B,GAAG,CAAC;QAC5D,uBAAuB;KACxB,CAAC,EACF;QACE,KAAK;QACL,2BAA2B;QAC3B,sBAAsB;QACtB,wBAAwB;QACxB,mBAAmB;QACnB,wBAAwB;QACxB,0BAA0B;QAC1B,uBAAuB;KACxB,CACF,CAAA;IAED,OAAO,CACL,KAAC,yBAAyB,CAAC,QAAQ,IAAC,KAAK,EAAE,KAAK,YAC7C,QAAQ,GAC0B,CACtC,CAAA;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,qBAAqB;IAC3C,MAAM,KAAK,GAAG,KAAK,CAAC,UAAU,CAAC,yBAAyB,CAAC,CAAA;IACzD,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CACb,oHAAoH,CACrH,CAAA;IACH,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC","sourcesContent":["import * as React from 'react'\nimport { submissionService } from '../apps'\nimport useBooleanState from './useBooleanState'\nimport useIsMounted from './useIsMounted'\nimport useIsOffline from './useIsOffline'\n\n/** The value returned from `usePendingSubmissions()` hook */\nexport type PendingSubmissionsContextValue = {\n /** `true` if the pending submissions are currently loading */\n isLoading: boolean\n /** An Error object if loading pending submissions fails */\n loadError: Error | null\n /**\n * The submissions that were submitted offline and can be processed when back\n * online\n */\n pendingSubmissions: submissionService.PendingFormSubmission[]\n /** `true` submissions that where submitted offline are being processed */\n isProcessingPendingQueue: boolean\n /** A function to trigger processing of the pending queue */\n processPendingQueue: () => unknown\n /**\n * A function to trigger loading of the submissions that were submitted\n * offline\n */\n reloadPendingSubmissions: () => unknown\n /** A function to remove a submission from the pending submissions */\n deletePendingSubmission: (pendingTimestamp: string) => unknown\n /** `true` if a submission being processed fails */\n isShowingFailedNotification: boolean\n /** A function to hide the notification when a submission fails to process */\n hideFailedNotification: () => unknown\n /** `true` if a submission being processed completes successfully. */\n isShowingSuccessNotification: boolean\n /**\n * A function to hide the notification after a submission completed\n * successfully\n */\n hideSuccessNotification: () => unknown\n}\n\nconst defaultState = {\n isLoading: false,\n loadError: null,\n pendingSubmissions: [],\n}\n\nconst PendingSubmissionsContext = React.createContext<\n PendingSubmissionsContextValue | undefined\n>(undefined)\n\n/**\n * React Component that provides the context for the `usePendingSubmissions()`\n * hook to be used by components further down your component tree. **It should\n * only be included in your component tree once and ideally at the root of the\n * application.**\n *\n * #### Example\n *\n * ```jsx\n * import * as React from 'react'\n * import {\n * PendingSubmissionsContextProvider,\n * usePendingSubmissions,\n * } from '@oneblink/apps-react'\n *\n * function Component() {\n * const pendingSubmissionsContext = usePendingSubmissions()\n * // use pending submissions here\n * }\n *\n * function App() {\n * return (\n * <PendingSubmissionsContextProvider\n * isPendingQueueEnabled\n * successNotificationTimeoutMs={3000}\n * >\n * <Component />\n * </PendingSubmissionsContextProvider>\n * )\n * }\n *\n * const root = document.getElementById('root')\n * if (root) {\n * ReactDOM.render(<App />, root)\n * }\n * ```\n *\n * @param props\n * @returns\n * @group Components\n */\nexport function PendingSubmissionsContextProvider({\n isPendingQueueEnabled,\n successNotificationTimeoutMs = 5000,\n children,\n}: {\n /**\n * `true` if pending queue is enabled, otherwise `false`. Can be used prevent\n * offline submissions from being processed.\n */\n isPendingQueueEnabled: boolean\n /**\n * When a submission is processed successfully the\n * `isShowingSuccessNotification` will be temporarily set to `true`, it will\n * be set back to `false` after 5 seconds. This prop will allow you to\n * customise how long to wait before hiding the notification with a\n * milliseconds value.\n */\n successNotificationTimeoutMs?: number\n /** Your application components */\n children: React.ReactNode\n}) {\n const isMounted = useIsMounted()\n const isOffline = useIsOffline()\n\n // Using a number as state so we can reset the timer used to close\n // the snack bar each time a pending queue item is processed\n const [submittedNotificationCount, setSubmittedNotificationCount] =\n React.useState(0)\n const hideSuccessNotification = React.useCallback(() => {\n setSubmittedNotificationCount(0)\n }, [])\n const [\n isShowingFailedNotification,\n showFailedNotification,\n hideFailedNotification,\n ] = useBooleanState(false)\n const [isProcessingPendingQueue, setIsProcessingPendingQueue] =\n React.useState(false)\n const [state, setState] = React.useState<{\n isLoading: boolean\n loadError: Error | null\n pendingSubmissions: submissionService.PendingFormSubmission[]\n }>(defaultState)\n\n const processPendingQueue = React.useCallback(async () => {\n if (isMounted.current) {\n setIsProcessingPendingQueue(true)\n }\n\n await submissionService.processPendingQueue({\n shouldRunExternalIdGeneration: true,\n shouldRunServerValidation: true,\n })\n\n if (isMounted.current) {\n setIsProcessingPendingQueue(false)\n }\n }, [isMounted])\n\n const reloadPendingSubmissions = React.useCallback(async () => {\n if (isMounted.current) {\n setState((currentState) => ({\n isLoading: true,\n loadError: null,\n pendingSubmissions: currentState.pendingSubmissions,\n }))\n }\n let newError = null\n let newPendingSubmissions: submissionService.PendingFormSubmission[] = []\n\n try {\n newPendingSubmissions =\n await submissionService.getPendingQueueSubmissions()\n } catch (error) {\n newError = error as Error\n }\n\n if (isMounted.current) {\n setState({\n isLoading: false,\n loadError: newError,\n pendingSubmissions: newPendingSubmissions,\n })\n }\n }, [isMounted])\n\n React.useEffect(() => {\n if (!isPendingQueueEnabled) {\n return\n }\n reloadPendingSubmissions()\n return submissionService.registerPendingQueueListener(\n (pendingSubmissions, action) => {\n switch (action) {\n case 'SUBMIT_SUCCEEDED': {\n setSubmittedNotificationCount((current) => current + 1)\n break\n }\n case 'SUBMIT_FAILED': {\n showFailedNotification()\n break\n }\n case 'SUBMIT_STARTED': {\n hideFailedNotification()\n break\n }\n // EDIT_CANCELLED is here for when beginnning edit offline and then hitting cancel while online\n // among other use cases\n case 'ADDITION':\n case 'EDIT_CANCELLED': {\n processPendingQueue()\n break\n }\n }\n setState({\n isLoading: false,\n pendingSubmissions,\n loadError: null,\n })\n },\n )\n }, [\n hideFailedNotification,\n isPendingQueueEnabled,\n processPendingQueue,\n reloadPendingSubmissions,\n showFailedNotification,\n ])\n\n React.useEffect(() => {\n if (!isOffline) {\n processPendingQueue()\n }\n }, [isOffline, processPendingQueue])\n\n React.useEffect(() => {\n if (submittedNotificationCount > 0) {\n const timeoutId = setTimeout(() => {\n hideSuccessNotification()\n }, successNotificationTimeoutMs)\n return () => {\n clearTimeout(timeoutId)\n }\n }\n }, [\n hideSuccessNotification,\n submittedNotificationCount,\n successNotificationTimeoutMs,\n ])\n\n const value = React.useMemo<PendingSubmissionsContextValue>(\n () => ({\n ...state,\n isShowingFailedNotification,\n hideFailedNotification,\n isProcessingPendingQueue,\n processPendingQueue,\n reloadPendingSubmissions,\n deletePendingSubmission: submissionService.deletePendingQueueSubmission,\n isShowingSuccessNotification: submittedNotificationCount > 0,\n hideSuccessNotification,\n }),\n [\n state,\n isShowingFailedNotification,\n hideFailedNotification,\n isProcessingPendingQueue,\n processPendingQueue,\n reloadPendingSubmissions,\n submittedNotificationCount,\n hideSuccessNotification,\n ],\n )\n\n return (\n <PendingSubmissionsContext.Provider value={value}>\n {children}\n </PendingSubmissionsContext.Provider>\n )\n}\n\n/**\n * React hook to get the context value for Pending Submissions. Will throw an\n * Error if used outside of the `<PendingSubmissionsContextProvider />`\n * component.\n *\n * @returns\n * @group Hooks\n */\nexport default function usePendingSubmissions(): PendingSubmissionsContextValue {\n const value = React.useContext(PendingSubmissionsContext)\n if (!value) {\n throw new Error(\n `\"usePendingSubmissions\" hook was used outside of the \"<PendingSubmissionsContextProvider />\" component's children.`,\n )\n }\n return value\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { localisationService } from '@oneblink/apps';
1
+ import { localisationService } from '../apps';
2
2
  import { useMemo } from 'react';
3
3
  import useFormSubmissionModel from './useFormSubmissionModelContext';
4
4
  import { useRepeatableSetIndexText } from '../form-elements/FormElementRepeatableSet';
@@ -1 +1 @@
1
- {"version":3,"file":"useReplaceableText.js","sourceRoot":"","sources":["../../src/hooks/useReplaceableText.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC/B,OAAO,sBAAsB,MAAM,iCAAiC,CAAA;AACpE,OAAO,EAAE,yBAAyB,EAAE,MAAM,2CAA2C,CAAA;AACrF,OAAO,cAAc,MAAM,kBAAkB,CAAA;AAC7C,OAAO,4BAA4B,MAAM,gCAAgC,CAAA;AAEzE,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,IAAY;IACrD,MAAM,aAAa,GAAG,yBAAyB,CAAC,IAAI,CAAC,CAAA;IACrD,MAAM,EAAE,mBAAmB,EAAE,QAAQ,EAAE,GAAG,sBAAsB,EAAE,CAAA;IAClE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,iBAAiB,EAAE,GAAG,cAAc,EAAE,CAAA;IAE/D,MAAM,WAAW,GAAG,4BAA4B,EAAE,CAAA;IAElD,OAAO,OAAO,CAAC,GAAG,EAAE;QAClB,OAAO,mBAAmB,CAAC,mCAAmC,CAC5D,aAAa,EACb;YACE,UAAU,EAAE,mBAAmB;YAC/B,YAAY,EAAE,QAAQ;YACtB,WAAW;YACX,IAAI;YACJ,SAAS;YACT,iBAAiB;SAClB,CACF,CAAC,IAAI,CAAA;IACR,CAAC,EAAE;QACD,QAAQ;QACR,mBAAmB;QACnB,IAAI;QACJ,SAAS;QACT,iBAAiB;QACjB,aAAa;QACb,WAAW;KACZ,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import { localisationService } from '@oneblink/apps'\nimport { useMemo } from 'react'\nimport useFormSubmissionModel from './useFormSubmissionModelContext'\nimport { useRepeatableSetIndexText } from '../form-elements/FormElementRepeatableSet'\nimport useTaskContext from './useTaskContext'\nimport useUserProfileForInjectables from './useUserProfileForInjectables'\n\nexport default function useReplaceableText(text: string) {\n const textWithIndex = useRepeatableSetIndexText(text)\n const { formSubmissionModel, elements } = useFormSubmissionModel()\n const { task, taskGroup, taskGroupInstance } = useTaskContext()\n\n const userProfile = useUserProfileForInjectables()\n\n return useMemo(() => {\n return localisationService.replaceInjectablesWithElementValues(\n textWithIndex,\n {\n submission: formSubmissionModel,\n formElements: elements,\n userProfile,\n task,\n taskGroup,\n taskGroupInstance,\n },\n ).text\n }, [\n elements,\n formSubmissionModel,\n task,\n taskGroup,\n taskGroupInstance,\n textWithIndex,\n userProfile,\n ])\n}\n"]}
1
+ {"version":3,"file":"useReplaceableText.js","sourceRoot":"","sources":["../../src/hooks/useReplaceableText.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC/B,OAAO,sBAAsB,MAAM,iCAAiC,CAAA;AACpE,OAAO,EAAE,yBAAyB,EAAE,MAAM,2CAA2C,CAAA;AACrF,OAAO,cAAc,MAAM,kBAAkB,CAAA;AAC7C,OAAO,4BAA4B,MAAM,gCAAgC,CAAA;AAEzE,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,IAAY;IACrD,MAAM,aAAa,GAAG,yBAAyB,CAAC,IAAI,CAAC,CAAA;IACrD,MAAM,EAAE,mBAAmB,EAAE,QAAQ,EAAE,GAAG,sBAAsB,EAAE,CAAA;IAClE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,iBAAiB,EAAE,GAAG,cAAc,EAAE,CAAA;IAE/D,MAAM,WAAW,GAAG,4BAA4B,EAAE,CAAA;IAElD,OAAO,OAAO,CAAC,GAAG,EAAE;QAClB,OAAO,mBAAmB,CAAC,mCAAmC,CAC5D,aAAa,EACb;YACE,UAAU,EAAE,mBAAmB;YAC/B,YAAY,EAAE,QAAQ;YACtB,WAAW;YACX,IAAI;YACJ,SAAS;YACT,iBAAiB;SAClB,CACF,CAAC,IAAI,CAAA;IACR,CAAC,EAAE;QACD,QAAQ;QACR,mBAAmB;QACnB,IAAI;QACJ,SAAS;QACT,iBAAiB;QACjB,aAAa;QACb,WAAW;KACZ,CAAC,CAAA;AACJ,CAAC","sourcesContent":["import { localisationService } from '../apps'\nimport { useMemo } from 'react'\nimport useFormSubmissionModel from './useFormSubmissionModelContext'\nimport { useRepeatableSetIndexText } from '../form-elements/FormElementRepeatableSet'\nimport useTaskContext from './useTaskContext'\nimport useUserProfileForInjectables from './useUserProfileForInjectables'\n\nexport default function useReplaceableText(text: string) {\n const textWithIndex = useRepeatableSetIndexText(text)\n const { formSubmissionModel, elements } = useFormSubmissionModel()\n const { task, taskGroup, taskGroupInstance } = useTaskContext()\n\n const userProfile = useUserProfileForInjectables()\n\n return useMemo(() => {\n return localisationService.replaceInjectablesWithElementValues(\n textWithIndex,\n {\n submission: formSubmissionModel,\n formElements: elements,\n userProfile,\n task,\n taskGroup,\n taskGroupInstance,\n },\n ).text\n }, [\n elements,\n formSubmissionModel,\n task,\n taskGroup,\n taskGroupInstance,\n textWithIndex,\n userProfile,\n ])\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { authService, Sentry } from '@oneblink/apps';
2
+ import { authService, Sentry } from '../apps';
3
3
  /**
4
4
  * @param options
5
5
  * @returns
@@ -1 +1 @@
1
- {"version":3,"file":"useSignUp.js","sourceRoot":"","sources":["../../src/hooks/useSignUp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAEpD;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,EAChC,UAAU,EACV,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,SAAS,EACT,OAAO,GAQR;IACC,MAAM,kBAAkB,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,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I;aACrB,CAAC,CAAC,CAAA;YACH,SAAS,aAAT,SAAS,uBAAT,SAAS,EAAI,CAAA;QACf,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAA;YAC9B,cAAc,CAAC,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;gBAChC,GAAG,YAAY;gBACf,WAAW,EAAE,KAAK;gBAClB,WAAW,EAAE,KAAc;aAC5B,CAAC,CAAC,CAAA;YACH,OAAO,aAAP,OAAO,uBAAP,OAAO,EAAI,CAAA;QACb,CAAC;IACH,CAAC,EAAE;QACD,SAAS;QACT,UAAU;QACV,QAAQ;QACR,OAAO;QACP,SAAS;QACT,QAAQ;QACR,kBAAkB,CAAC,SAAS;KAC7B,CAAC,CAAA;IAEF,OAAO;QACL,qBAAqB;QACrB,gBAAgB;QAChB,WAAW;QACX,WAAW;QACX,cAAc;QACd,kBAAkB;KACnB,CAAA;AACH,CAAC","sourcesContent":["import * as React from 'react'\nimport { authService, Sentry } from '@oneblink/apps'\n\n/**\n * @param options\n * @returns\n * @group Hooks\n */\nexport default function useSignUp({\n formsAppId,\n username,\n firstName,\n lastName,\n onSuccess,\n onError,\n}: {\n formsAppId: number\n username: string\n firstName?: string\n lastName?: string\n onSuccess?: () => void\n onError?: () => void\n}) {\n const usernameValidation = React.useMemo(() => {\n // regex source: https://www.w3resource.com/javascript/form/email-validation.php#:~:text=To%20get%20a%20valid%20email,%5D%2B)*%24%2F.\n return {\n isInvalid: !username.match(\n /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$/,\n ),\n }\n }, [username])\n\n const [{ isSigningUp, signUpError, signUpComplete }, setSignUpState] =\n React.useState<{\n isSigningUp: boolean\n signUpError: Error | null\n signUpComplete: boolean\n }>({\n isSigningUp: false,\n signUpError: null,\n signUpComplete: false,\n })\n\n const clearSignUpError = React.useCallback(\n () =>\n setSignUpState((current) => ({\n ...current,\n signUpError: null,\n })),\n [],\n )\n\n const signUpWithUserDetails = React.useCallback(async () => {\n if (usernameValidation.isInvalid) {\n setSignUpState((current) => ({\n ...current,\n signUpError: new Error('Please enter a valid email address'),\n }))\n return\n }\n\n setSignUpState((currentState) => ({\n ...currentState,\n isSigningUp: true,\n signUpError: null,\n }))\n\n try {\n await authService.signUp({\n formsAppId,\n email: username,\n firstName,\n lastName,\n })\n\n setSignUpState((currentState) => ({\n ...currentState,\n isSigningUp: false,\n signUpComplete: true,\n }))\n onSuccess?.()\n } catch (error) {\n Sentry.captureException(error)\n setSignUpState((currentState) => ({\n ...currentState,\n isSigningUp: false,\n signUpError: error as Error,\n }))\n onError?.()\n }\n }, [\n firstName,\n formsAppId,\n lastName,\n onError,\n onSuccess,\n username,\n usernameValidation.isInvalid,\n ])\n\n return {\n signUpWithUserDetails,\n clearSignUpError,\n isSigningUp,\n signUpError,\n signUpComplete,\n usernameValidation,\n }\n}\n"]}
1
+ {"version":3,"file":"useSignUp.js","sourceRoot":"","sources":["../../src/hooks/useSignUp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAE7C;;;;GAIG;AACH,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,EAChC,UAAU,EACV,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,SAAS,EACT,OAAO,GAQR;IACC,MAAM,kBAAkB,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE;QAC5C,qIAAqI;QACrI,OAAO;YACL,SAAS,EAAE,CAAC,QAAQ,CAAC,KAAK,CACxB,sEAAsE,CACvE;SACF,CAAA;IACH,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAA;IAEd,MAAM,CAAC,EAAE,WAAW,EAAE,WAAW,EAAE,cAAc,EAAE,EAAE,cAAc,CAAC,GAClE,KAAK,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WAAW,EAAE,KAAK;gBAClB,WAAW,EAAE,KAAc;aAC5B,CAAC,CAAC,CAAA;YACH,OAAO,aAAP,OAAO,uBAAP,OAAO,EAAI,CAAA;QACb,CAAC;IACH,CAAC,EAAE;QACD,SAAS;QACT,UAAU;QACV,QAAQ;QACR,OAAO;QACP,SAAS;QACT,QAAQ;QACR,kBAAkB,CAAC,SAAS;KAC7B,CAAC,CAAA;IAEF,OAAO;QACL,qBAAqB;QACrB,gBAAgB;QAChB,WAAW;QACX,WAAW;QACX,cAAc;QACd,kBAAkB;KACnB,CAAA;AACH,CAAC","sourcesContent":["import * as React from 'react'\nimport { authService, Sentry } from '../apps'\n\n/**\n * @param options\n * @returns\n * @group Hooks\n */\nexport default function useSignUp({\n formsAppId,\n username,\n firstName,\n lastName,\n onSuccess,\n onError,\n}: {\n formsAppId: number\n username: string\n firstName?: string\n lastName?: string\n onSuccess?: () => void\n onError?: () => void\n}) {\n const usernameValidation = React.useMemo(() => {\n // regex source: https://www.w3resource.com/javascript/form/email-validation.php#:~:text=To%20get%20a%20valid%20email,%5D%2B)*%24%2F.\n return {\n isInvalid: !username.match(\n /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]+)*$/,\n ),\n }\n }, [username])\n\n const [{ isSigningUp, signUpError, signUpComplete }, setSignUpState] =\n React.useState<{\n isSigningUp: boolean\n signUpError: Error | null\n signUpComplete: boolean\n }>({\n isSigningUp: false,\n signUpError: null,\n signUpComplete: false,\n })\n\n const clearSignUpError = React.useCallback(\n () =>\n setSignUpState((current) => ({\n ...current,\n signUpError: null,\n })),\n [],\n )\n\n const signUpWithUserDetails = React.useCallback(async () => {\n if (usernameValidation.isInvalid) {\n setSignUpState((current) => ({\n ...current,\n signUpError: new Error('Please enter a valid email address'),\n }))\n return\n }\n\n setSignUpState((currentState) => ({\n ...currentState,\n isSigningUp: true,\n signUpError: null,\n }))\n\n try {\n await authService.signUp({\n formsAppId,\n email: username,\n firstName,\n lastName,\n })\n\n setSignUpState((currentState) => ({\n ...currentState,\n isSigningUp: false,\n signUpComplete: true,\n }))\n onSuccess?.()\n } catch (error) {\n Sentry.captureException(error)\n setSignUpState((currentState) => ({\n ...currentState,\n isSigningUp: false,\n signUpError: error as Error,\n }))\n onError?.()\n }\n }, [\n firstName,\n formsAppId,\n lastName,\n onError,\n onSuccess,\n username,\n usernameValidation.isInvalid,\n ])\n\n return {\n signUpWithUserDetails,\n clearSignUpError,\n isSigningUp,\n signUpError,\n signUpComplete,\n usernameValidation,\n }\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { FormTypes } from '@oneblink/types';
2
- import { attachmentsService } from '@oneblink/apps';
2
+ import { attachmentsService } from '../apps';
3
3
  export declare function generateErrorAttachment(blob: Blob | undefined, fileName: string, element: FormTypes.FormElementBinaryStorage, errorMessage: string, errorType?: attachmentsService.AttachmentError['errorType']): attachmentsService.AttachmentError;
4
4
  export declare function prepareNewAttachment(blob: Blob, fileName: string, element: FormTypes.FormElementBinaryStorage): attachmentsService.AttachmentNew;
5
5
  export declare function checkIfContentTypeIsImage(contentType: string): boolean;
@@ -1,4 +1,4 @@
1
- import { Sentry } from '@oneblink/apps';
1
+ import { Sentry } from '../apps';
2
2
  import { v4 as uuid } from 'uuid';
3
3
  import { blobToCanvas, getBlobOrientation } from './blob-utils';
4
4
  export function generateErrorAttachment(blob, fileName, element, errorMessage, errorType) {
@@ -1 +1 @@
1
- {"version":3,"file":"attachments.js","sourceRoot":"","sources":["../../src/services/attachments.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAsB,MAAM,gBAAgB,CAAA;AAC3D,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAA;AACjC,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAE/D,MAAM,UAAU,uBAAuB,CACrC,IAAsB,EACtB,QAAgB,EAChB,OAA2C,EAC3C,YAAo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MAAM,CAAA;IACf,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,IAAI,CAAC,6CAA6C,EAAE,GAAG,CAAC,CAAA;QAChE,MAAM,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAA;QAC5B,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC","sourcesContent":["import { FormTypes } from '@oneblink/types'\nimport { Sentry, attachmentsService } from '@oneblink/apps'\nimport { v4 as uuid } from 'uuid'\nimport { blobToCanvas, getBlobOrientation } from './blob-utils'\n\nexport function generateErrorAttachment(\n blob: Blob | undefined,\n fileName: string,\n element: FormTypes.FormElementBinaryStorage,\n errorMessage: string,\n errorType?: attachmentsService.AttachmentError['errorType'],\n): attachmentsService.AttachmentError {\n return {\n _id: uuid(),\n data: blob,\n fileName,\n isPrivate: element.storageType !== 'public',\n type: 'ERROR',\n errorMessage,\n errorType,\n }\n}\n\nexport function prepareNewAttachment(\n blob: Blob,\n fileName: string,\n element: FormTypes.FormElementBinaryStorage,\n): attachmentsService.AttachmentNew {\n return {\n _id: uuid(),\n data: blob,\n fileName,\n isPrivate: element.storageType !== 'public',\n type: 'NEW',\n }\n}\n\nexport function checkIfContentTypeIsImage(contentType: string) {\n return contentType.indexOf('image/') === 0\n}\n\nexport async function parseFilesAsAttachmentsLegacy(\n files: File[],\n onAnnotateCanvas?: (file: File, canvas: HTMLCanvasElement) => void,\n): Promise<Array<{ data: string; fileName: string; contentType: string }>> {\n const attachments: Array<{\n data: string\n fileName: string\n contentType: string\n }> = []\n\n for (const file of files) {\n const result = await correctFileOrientation(file, onAnnotateCanvas)\n\n if (result instanceof Blob) {\n console.log('Attempting to parse File as attachment', file)\n\n const base64data = await new Promise<string>((resolve, reject) => {\n const reader = new FileReader()\n reader.onload = function () {\n resolve(reader.result as string)\n }\n reader.onerror = function () {\n reject(new Error('Could not read file from data url'))\n }\n reader.readAsDataURL(file)\n })\n\n attachments.push({\n fileName: file.name,\n contentType: file.type,\n data: base64data,\n })\n } else {\n attachments.push({\n fileName: file.name,\n contentType: file.type,\n data: result.toDataURL(),\n })\n }\n }\n\n return attachments\n}\n\nexport async function correctFileOrientation(\n file: File,\n onAnnotateCanvas?: (file: File, canvas: HTMLCanvasElement) => void,\n): Promise<Blob | HTMLCanvasElement> {\n try {\n if (!checkIfContentTypeIsImage(file.type)) {\n return file\n }\n\n console.log('Attempting to parse File as image attachment', file)\n\n const orientation = await getBlobOrientation(file)\n if (\n (typeof orientation !== 'number' || orientation === 1) &&\n !onAnnotateCanvas\n ) {\n console.log('Skipping orientation correction for image')\n return file\n }\n\n console.log(\n 'Loading image onto canvas to correct orientation using image meta data',\n { orientation },\n )\n const canvas = await blobToCanvas(file, orientation)\n if (onAnnotateCanvas) {\n onAnnotateCanvas(file, canvas)\n }\n return canvas\n } catch (err) {\n console.warn('Failed to rotate the orientation of a file:', err)\n Sentry.captureException(err)\n return file\n }\n}\n"]}
1
+ {"version":3,"file":"attachments.js","sourceRoot":"","sources":["../../src/services/attachments.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAsB,MAAM,SAAS,CAAA;AACpD,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAA;AACjC,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAE/D,MAAM,UAAU,uBAAuB,CACrC,IAAsB,EACtB,QAAgB,EAChB,OAA2C,EAC3C,YAAoB,EACpB,SAA2D;IAE3D,OAAO;QACL,GAAG,EAAE,IAAI,EAAE;QACX,IAAI,EAAE,IAAI;QACV,QAAQ;QACR,SAAS,EAAE,OAAO,CAAC,WAAW,KAAK,QAAQ;QAC3C,IAAI,EAAE,OAAO;QACb,YAAY;QACZ,SAAS;KACV,CAAA;AACH,CAAC;AAED,MAAM,UAAU,oBAAoB,CAClC,IAAU,EACV,QAAgB,EAChB,OAA2C;IAE3C,OAAO;QACL,GAAG,EAAE,IAAI,EAAE;QACX,IAAI,EAAE,IAAI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AW,EAAE,IAAI,CAAC,IAAI;gBACtB,IAAI,EAAE,MAAM,CAAC,SAAS,EAAE;aACzB,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;IAED,OAAO,WAAW,CAAA;AACpB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,IAAU,EACV,gBAAkE;IAElE,IAAI,CAAC;QACH,IAAI,CAAC,yBAAyB,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YAC1C,OAAO,IAAI,CAAA;QACb,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,8CAA8C,EAAE,IAAI,CAAC,CAAA;QAEjE,MAAM,WAAW,GAAG,MAAM,kBAAkB,CAAC,IAAI,CAAC,CAAA;QAClD,IACE,CAAC,OAAO,WAAW,KAAK,QAAQ,IAAI,WAAW,KAAK,CAAC,CAAC;YACtD,CAAC,gBAAgB,EACjB,CAAC;YACD,OAAO,CAAC,GAAG,CAAC,2CAA2C,CAAC,CAAA;YACxD,OAAO,IAAI,CAAA;QACb,CAAC;QAED,OAAO,CAAC,GAAG,CACT,wEAAwE,EACxE,EAAE,WAAW,EAAE,CAChB,CAAA;QACD,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,IAAI,EAAE,WAAW,CAAC,CAAA;QACpD,IAAI,gBAAgB,EAAE,CAAC;YACrB,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;QAChC,CAAC;QACD,OAAO,MAAM,CAAA;IACf,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,CAAC,IAAI,CAAC,6CAA6C,EAAE,GAAG,CAAC,CAAA;QAChE,MAAM,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAA;QAC5B,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC","sourcesContent":["import { FormTypes } from '@oneblink/types'\nimport { Sentry, attachmentsService } from '../apps'\nimport { v4 as uuid } from 'uuid'\nimport { blobToCanvas, getBlobOrientation } from './blob-utils'\n\nexport function generateErrorAttachment(\n blob: Blob | undefined,\n fileName: string,\n element: FormTypes.FormElementBinaryStorage,\n errorMessage: string,\n errorType?: attachmentsService.AttachmentError['errorType'],\n): attachmentsService.AttachmentError {\n return {\n _id: uuid(),\n data: blob,\n fileName,\n isPrivate: element.storageType !== 'public',\n type: 'ERROR',\n errorMessage,\n errorType,\n }\n}\n\nexport function prepareNewAttachment(\n blob: Blob,\n fileName: string,\n element: FormTypes.FormElementBinaryStorage,\n): attachmentsService.AttachmentNew {\n return {\n _id: uuid(),\n data: blob,\n fileName,\n isPrivate: element.storageType !== 'public',\n type: 'NEW',\n }\n}\n\nexport function checkIfContentTypeIsImage(contentType: string) {\n return contentType.indexOf('image/') === 0\n}\n\nexport async function parseFilesAsAttachmentsLegacy(\n files: File[],\n onAnnotateCanvas?: (file: File, canvas: HTMLCanvasElement) => void,\n): Promise<Array<{ data: string; fileName: string; contentType: string }>> {\n const attachments: Array<{\n data: string\n fileName: string\n contentType: string\n }> = []\n\n for (const file of files) {\n const result = await correctFileOrientation(file, onAnnotateCanvas)\n\n if (result instanceof Blob) {\n console.log('Attempting to parse File as attachment', file)\n\n const base64data = await new Promise<string>((resolve, reject) => {\n const reader = new FileReader()\n reader.onload = function () {\n resolve(reader.result as string)\n }\n reader.onerror = function () {\n reject(new Error('Could not read file from data url'))\n }\n reader.readAsDataURL(file)\n })\n\n attachments.push({\n fileName: file.name,\n contentType: file.type,\n data: base64data,\n })\n } else {\n attachments.push({\n fileName: file.name,\n contentType: file.type,\n data: result.toDataURL(),\n })\n }\n }\n\n return attachments\n}\n\nexport async function correctFileOrientation(\n file: File,\n onAnnotateCanvas?: (file: File, canvas: HTMLCanvasElement) => void,\n): Promise<Blob | HTMLCanvasElement> {\n try {\n if (!checkIfContentTypeIsImage(file.type)) {\n return file\n }\n\n console.log('Attempting to parse File as image attachment', file)\n\n const orientation = await getBlobOrientation(file)\n if (\n (typeof orientation !== 'number' || orientation === 1) &&\n !onAnnotateCanvas\n ) {\n console.log('Skipping orientation correction for image')\n return file\n }\n\n console.log(\n 'Loading image onto canvas to correct orientation using image meta data',\n { orientation },\n )\n const canvas = await blobToCanvas(file, orientation)\n if (onAnnotateCanvas) {\n onAnnotateCanvas(file, canvas)\n }\n return canvas\n } catch (err) {\n console.warn('Failed to rotate the orientation of a file:', err)\n Sentry.captureException(err)\n return file\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { authService } from '@oneblink/apps';
1
+ import { authService } from '../apps';
2
2
  import loadImage from 'blueimp-load-image';
3
3
  // Copied from https://stackoverflow.com/questions/16245767/creating-a-blob-from-a-base64-string-in-javascript
4
4
  const b64toBlob = (b64Data, contentType = '', sliceSize = 512) => {
@@ -1 +1 @@
1
- {"version":3,"file":"blob-utils.js","sourceRoot":"","sources":["../../src/services/blob-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,SAAS,MAAM,oBAAoB,CAAA;AAE1C,8GAA8G;AAC9G,MAAM,SAAS,GAAG,CAAC,OAAe,EAAE,WAAW,GAAG,EAAE,EAAE,SAAS,GAAG,GAAG,EAAE,EAAE;IACvE,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,CAAA;IACpC,MAAM,UAAU,GAAG,EAAE,CAAA;IAErB,KAAK,IAAI,MAAM,GAAG,CAAC,EAAE,MAAM,GAAG,cAAc,CAAC,MAAM,EAAE,MAAM,IAAI,SAAS,EAAE,CAAC;QACzE,MAAM,KAAK,GAAG,cAAc,CAAC,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;QAE9D,MAAM,WAAW,GAAG,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;QAC3C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACtC,WAAW,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC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O,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAA;AAC9B,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,IAAU,EACV,WAAoB;IAEpB,MAAM,eAAe,GAAG,MAAM,SAAS,CAAC,IAAI,EAAE;QAC5C,MAAM,EAAE,IAAI;QACZ,WAAW,EAAE,WAAW;KACzB,CAAC,CAAA;IACF,gGAAgG;IAChG,MAAM,MAAM,GAAsB,eAAe,CAAC,KAAK,CAAA;IACvD,OAAO,MAAM,CAAA;AACf,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,MAAyB;IAC1D,MAAM,IAAI,GAAS,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACvD,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;YACrB,IAAI,IAAI;gBAAE,OAAO,CAAC,IAAI,CAAC,CAAA;YACvB,MAAM,CAAC,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC,CAAA;QAC7D,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IACF,OAAO,IAAI,CAAA;AACb,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,IAAU;;IAEV,MAAM,aAAa,GAAuB,MAAM,SAAS,CAAC,aAAa,CAAC,IAAI,CAAC,CAAA;IAC7E,MAAM,WAAW,GAAG,MAAA,aAAa,CAAC,IAAI,0CAAE,GAAG,CAAC,aAAa,CAAC,CAAA;IAC1D,OAAO,WAAiC,CAAA;AAC1C,CAAC","sourcesContent":["import { authService } from '@oneblink/apps'\nimport loadImage from 'blueimp-load-image'\n\n// Copied from https://stackoverflow.com/questions/16245767/creating-a-blob-from-a-base64-string-in-javascript\nconst b64toBlob = (b64Data: string, contentType = '', sliceSize = 512) => {\n const byteCharacters = atob(b64Data)\n const byteArrays = []\n\n for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {\n const slice = byteCharacters.slice(offset, offset + sliceSize)\n\n const byteNumbers = new Array(slice.length)\n for (let i = 0; i < slice.length; i++) {\n byteNumbers[i] = slice.charCodeAt(i)\n }\n\n const byteArray = new Uint8Array(byteNumbers)\n byteArrays.push(byteArray)\n }\n\n const blob = new Blob(byteArrays, { type: contentType })\n return blob\n}\n\nexport function dataUriToBlobSync(dataUri: string) {\n const [prefix, b64Data] = dataUri.split(',')\n const matches = prefix.match(/data:(.*);base64/)\n const [, contentType] = matches || []\n return b64toBlob(b64Data, contentType)\n}\n\nasync function generateRequestInit(\n abortSignal?: AbortSignal,\n): Promise<RequestInit | undefined> {\n const idToken = await authService.getIdToken()\n if (idToken) {\n return {\n signal: abortSignal,\n headers: {\n Authorization: `Bearer ${idToken}`,\n },\n }\n }\n}\n\nexport async function urlToBlobAsync(url: string, abortSignal?: AbortSignal) {\n const requestInit = await generateRequestInit(abortSignal)\n const response = await fetch(url, requestInit)\n if (!response.ok) {\n throw new Error(\n `Unable to download file. HTTP Status Code: ${response.status}`,\n )\n }\n return await response.blob()\n}\n\nexport async function blobToCanvas(\n blob: Blob,\n orientation?: number,\n): Promise<HTMLCanvasElement> {\n const loadImageResult = await loadImage(blob, {\n canvas: true,\n orientation: orientation,\n })\n // @ts-expect-error this it always be a HTMLCanvasElement because we passed `canvas: true` above\n const canvas: HTMLCanvasElement = loadImageResult.image\n return canvas\n}\n\nexport async function canvasToBlob(canvas: HTMLCanvasElement) {\n const blob: Blob = await new Promise((resolve, reject) => {\n canvas.toBlob((blob) => {\n if (blob) resolve(blob)\n reject(new Error('Failed to convert canvas back to blob.'))\n })\n })\n return blob\n}\n\nexport async function getBlobOrientation(\n blob: Blob,\n): Promise<number | undefined> {\n const imageMetaData: loadImage.MetaData = await loadImage.parseMetaData(blob)\n const orientation = imageMetaData.exif?.get('Orientation')\n return orientation as number | undefined\n}\n"]}
1
+ {"version":3,"file":"blob-utils.js","sourceRoot":"","sources":["../../src/services/blob-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,E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OAAO,CAAC,IAAI,CAAC,CAAA;YACvB,MAAM,CAAC,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC,CAAA;QAC7D,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;IACF,OAAO,IAAI,CAAA;AACb,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,IAAU;;IAEV,MAAM,aAAa,GAAuB,MAAM,SAAS,CAAC,aAAa,CAAC,IAAI,CAAC,CAAA;IAC7E,MAAM,WAAW,GAAG,MAAA,aAAa,CAAC,IAAI,0CAAE,GAAG,CAAC,aAAa,CAAC,CAAA;IAC1D,OAAO,WAAiC,CAAA;AAC1C,CAAC","sourcesContent":["import { authService } from '../apps'\nimport loadImage from 'blueimp-load-image'\n\n// Copied from https://stackoverflow.com/questions/16245767/creating-a-blob-from-a-base64-string-in-javascript\nconst b64toBlob = (b64Data: string, contentType = '', sliceSize = 512) => {\n const byteCharacters = atob(b64Data)\n const byteArrays = []\n\n for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) {\n const slice = byteCharacters.slice(offset, offset + sliceSize)\n\n const byteNumbers = new Array(slice.length)\n for (let i = 0; i < slice.length; i++) {\n byteNumbers[i] = slice.charCodeAt(i)\n }\n\n const byteArray = new Uint8Array(byteNumbers)\n byteArrays.push(byteArray)\n }\n\n const blob = new Blob(byteArrays, { type: contentType })\n return blob\n}\n\nexport function dataUriToBlobSync(dataUri: string) {\n const [prefix, b64Data] = dataUri.split(',')\n const matches = prefix.match(/data:(.*);base64/)\n const [, contentType] = matches || []\n return b64toBlob(b64Data, contentType)\n}\n\nasync function generateRequestInit(\n abortSignal?: AbortSignal,\n): Promise<RequestInit | undefined> {\n const idToken = await authService.getIdToken()\n if (idToken) {\n return {\n signal: abortSignal,\n headers: {\n Authorization: `Bearer ${idToken}`,\n },\n }\n }\n}\n\nexport async function urlToBlobAsync(url: string, abortSignal?: AbortSignal) {\n const requestInit = await generateRequestInit(abortSignal)\n const response = await fetch(url, requestInit)\n if (!response.ok) {\n throw new Error(\n `Unable to download file. HTTP Status Code: ${response.status}`,\n )\n }\n return await response.blob()\n}\n\nexport async function blobToCanvas(\n blob: Blob,\n orientation?: number,\n): Promise<HTMLCanvasElement> {\n const loadImageResult = await loadImage(blob, {\n canvas: true,\n orientation: orientation,\n })\n // @ts-expect-error this it always be a HTMLCanvasElement because we passed `canvas: true` above\n const canvas: HTMLCanvasElement = loadImageResult.image\n return canvas\n}\n\nexport async function canvasToBlob(canvas: HTMLCanvasElement) {\n const blob: Blob = await new Promise((resolve, reject) => {\n canvas.toBlob((blob) => {\n if (blob) resolve(blob)\n reject(new Error('Failed to convert canvas back to blob.'))\n })\n })\n return blob\n}\n\nexport async function getBlobOrientation(\n blob: Blob,\n): Promise<number | undefined> {\n const imageMetaData: loadImage.MetaData = await loadImage.parseMetaData(blob)\n const orientation = imageMetaData.exif?.get('Orientation')\n return orientation as number | undefined\n}\n"]}
@@ -1,4 +1,4 @@
1
1
  import { FormTypes, SubmissionTypes } from '@oneblink/types';
2
- import { attachmentsService } from '@oneblink/apps';
2
+ import { attachmentsService } from '../apps';
3
3
  export declare function validateAttachmentExists(attachment: attachmentsService.Attachment, attachmentRetentionInDays: number | undefined): attachmentsService.AttachmentError | void;
4
4
  export default function checkIfAttachmentsExist(form: FormTypes.Form, submission: SubmissionTypes.S3SubmissionData['submission'], attachmentRetentionInDays: number | undefined): SubmissionTypes.S3SubmissionData['submission'] | void;
@@ -1 +1 @@
1
- {"version":3,"file":"checkIfAttachmentsExist.js","sourceRoot":"","sources":["../../src/services/checkIfAttachmentsExist.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAA;AAKjC,MAAM,UAAU,wBAAwB,CACtC,UAAyC,EACzC,yBAA6C;IAE7C,IAAI,UAAU,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,UAAU,IAAI,CAAC,yBAAyB,EAAE,CAAC;QAC5E,OAAM;IACR,CA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;IACf,CAAC;AACH,CAAC;AAED,MAAM,CAAC,OAAO,UAAU,uBAAuB,CAC7C,IAAoB,EACpB,UAA0D,EAC1D,yBAA6C;IAE7C,OAAO,sCAAsC,CAC3C,IAAI,CAAC,QAAQ,EACb,UAAU,EACV,yBAAyB,CAC1B,CAAA;AACH,CAAC","sourcesContent":["import { ArcGISTypes, FormTypes, SubmissionTypes } from '@oneblink/types'\nimport { v4 as uuid } from 'uuid'\nimport { attachmentsService } from '@oneblink/apps'\n\nimport { Value as FormElementComplianceValue } from '../form-elements/FormElementCompliance'\n\nexport function validateAttachmentExists(\n attachment: attachmentsService.Attachment,\n attachmentRetentionInDays: number | undefined,\n): attachmentsService.AttachmentError | void {\n if (attachment.type || !attachment.uploadedAt || !attachmentRetentionInDays) {\n return\n }\n\n const uploadedAt = new Date(attachment.uploadedAt)\n const expiresAt = new Date(attachment.uploadedAt)\n expiresAt.setDate(uploadedAt.getDate() + attachmentRetentionInDays)\n const now = new Date()\n console.log('Checking if attachment still exists', {\n uploadedAt,\n expiresAt,\n attachment,\n })\n // check if attachment exists\n if (expiresAt > now) {\n return\n }\n\n const attachmentError: attachmentsService.AttachmentError = {\n type: 'ERROR',\n errorMessage:\n \"This attachment has been removed based on your administrator's data retention policy, please remove it and upload it again.\",\n _id: uuid(),\n fileName: attachment.fileName,\n isPrivate: attachment.isPrivate,\n }\n return attachmentError\n}\n\nfunction validateAttachmentsExists(\n attachments: unknown,\n attachmentRetentionInDays: number | undefined,\n): attachmentsService.Attachment[] | void {\n if (!Array.isArray(attachments)) {\n return\n }\n const newAttachments = [...attachments]\n let hasChanges = false\n for (let index = 0; index < newAttachments.length; index++) {\n const attachmentError = validateAttachmentExists(\n newAttachments[index] as attachmentsService.Attachment,\n attachmentRetentionInDays,\n )\n if (attachmentError) {\n hasChanges = true\n newAttachments[index] = attachmentError\n }\n }\n if (hasChanges) {\n return newAttachments\n }\n}\n\nfunction checkIfAttachmentsExistForFormElements(\n formElements: FormTypes.FormElement[],\n submission: SubmissionTypes.S3SubmissionData['submission'],\n attachmentRetentionInDays: number | undefined,\n): SubmissionTypes.S3SubmissionData['submission'] | void {\n const result: SubmissionTypes.S3SubmissionData['submission'] = {\n ...submission,\n }\n let hasChanges = false\n for (const formElement of formElements) {\n switch (formElement.type) {\n case 'section':\n case 'page': {\n const newSubmission = checkIfAttachmentsExistForFormElements(\n formElement.elements,\n result,\n attachmentRetentionInDays,\n )\n if (newSubmission) {\n hasChanges = true\n Object.assign(result, newSubmission)\n }\n break\n }\n case 'form': {\n const nestedSubmission = submission[formElement.name]\n if (!nestedSubmission || typeof nestedSubmission !== 'object') {\n break\n }\n const newSubmission = checkIfAttachmentsExistForFormElements(\n formElement.elements || [],\n nestedSubmission as SubmissionTypes.S3SubmissionData['submission'],\n attachmentRetentionInDays,\n )\n if (newSubmission) {\n hasChanges = true\n result[formElement.name] = newSubmission\n }\n break\n }\n case 'repeatableSet': {\n const entries = submission[formElement.name]\n if (!Array.isArray(entries)) {\n break\n }\n const newEntries = [...entries]\n let hasEntryChanges = false\n for (let index = 0; index < entries.length; index++) {\n const entry = entries[index]\n if (typeof entry === 'object') {\n const newEntry = checkIfAttachmentsExistForFormElements(\n formElement.elements,\n entry,\n attachmentRetentionInDays,\n )\n if (newEntry) {\n hasEntryChanges = true\n newEntries[index] = newEntry\n }\n }\n }\n if (hasEntryChanges) {\n hasChanges = true\n result[formElement.name] = newEntries\n }\n break\n }\n case 'arcGISWebMap':\n case 'camera':\n case 'draw':\n case 'compliance':\n case 'files': {\n const value = submission[formElement.name]\n if (!value) {\n break\n }\n\n // If the attachment has a type, it has not finished uploading\n switch (formElement.type) {\n case 'camera':\n case 'draw': {\n const attachmentError = validateAttachmentExists(\n value as attachmentsService.Attachment,\n attachmentRetentionInDays,\n )\n if (attachmentError) {\n hasChanges = true\n result[formElement.name] = attachmentError\n }\n break\n }\n case 'compliance': {\n const newAttachments = validateAttachmentsExists(\n (value as FormElementComplianceValue).files,\n attachmentRetentionInDays,\n )\n if (newAttachments) {\n hasChanges = true\n result[formElement.name] = {\n ...(value as FormElementComplianceValue),\n files: newAttachments,\n }\n }\n break\n }\n case 'files': {\n const newAttachments = validateAttachmentsExists(\n value,\n attachmentRetentionInDays,\n )\n if (newAttachments) {\n hasChanges = true\n result[formElement.name] = newAttachments\n }\n break\n }\n case 'arcGISWebMap': {\n const arcGISWebMapElementValue =\n value as ArcGISTypes.ArcGISWebMapElementValue\n const snapshotImages = validateAttachmentsExists(\n arcGISWebMapElementValue.snapshotImages,\n attachmentRetentionInDays,\n )\n if (snapshotImages) {\n hasChanges = true\n result[formElement.name] = {\n ...value,\n snapshotImages,\n }\n }\n break\n }\n }\n }\n }\n }\n if (hasChanges) {\n return result\n }\n}\n\nexport default function checkIfAttachmentsExist(\n form: FormTypes.Form,\n submission: SubmissionTypes.S3SubmissionData['submission'],\n attachmentRetentionInDays: number | undefined,\n): SubmissionTypes.S3SubmissionData['submission'] | void {\n return checkIfAttachmentsExistForFormElements(\n form.elements,\n submission,\n attachmentRetentionInDays,\n )\n}\n"]}
1
+ {"version":3,"file":"checkIfAttachmentsExist.js","sourceRoot":"","sources":["../../src/services/checkIfAttachmentsExist.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAA;AAKjC,MAAM,UAAU,wBAAwB,CACtC,UAAyC,EACzC,yBAA6C;IAE7C,IAAI,UAAU,CAAC,IAAI,IAAI,CAAC,UAAU,CAAC,UAAU,IAAI,CAAC,yBAAyB,EAAE,CAAC;QAC5E,OAAM;IACR,CAAC;IAED,MAAM,UAAU,GAAG,IAAI,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAA;IAClD,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,CAAA;IACjD,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,EAAE,GAAG,yBAAyB,CAAC,CAAA;IACnE,MAAM,GAAG,GAAG,IAAI,I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v4 as uuid } from 'uuid'\nimport { attachmentsService } from '../apps'\n\nimport { Value as FormElementComplianceValue } from '../form-elements/FormElementCompliance'\n\nexport function validateAttachmentExists(\n attachment: attachmentsService.Attachment,\n attachmentRetentionInDays: number | undefined,\n): attachmentsService.AttachmentError | void {\n if (attachment.type || !attachment.uploadedAt || !attachmentRetentionInDays) {\n return\n }\n\n const uploadedAt = new Date(attachment.uploadedAt)\n const expiresAt = new Date(attachment.uploadedAt)\n expiresAt.setDate(uploadedAt.getDate() + attachmentRetentionInDays)\n const now = new Date()\n console.log('Checking if attachment still exists', {\n uploadedAt,\n expiresAt,\n attachment,\n })\n // check if attachment exists\n if (expiresAt > now) {\n return\n }\n\n const attachmentError: attachmentsService.AttachmentError = {\n type: 'ERROR',\n errorMessage:\n \"This attachment has been removed based on your administrator's data retention policy, please remove it and upload it again.\",\n _id: uuid(),\n fileName: attachment.fileName,\n isPrivate: attachment.isPrivate,\n }\n return attachmentError\n}\n\nfunction validateAttachmentsExists(\n attachments: unknown,\n attachmentRetentionInDays: number | undefined,\n): attachmentsService.Attachment[] | void {\n if (!Array.isArray(attachments)) {\n return\n }\n const newAttachments = [...attachments]\n let hasChanges = false\n for (let index = 0; index < newAttachments.length; index++) {\n const attachmentError = validateAttachmentExists(\n newAttachments[index] as attachmentsService.Attachment,\n attachmentRetentionInDays,\n )\n if (attachmentError) {\n hasChanges = true\n newAttachments[index] = attachmentError\n }\n }\n if (hasChanges) {\n return newAttachments\n }\n}\n\nfunction checkIfAttachmentsExistForFormElements(\n formElements: FormTypes.FormElement[],\n submission: SubmissionTypes.S3SubmissionData['submission'],\n attachmentRetentionInDays: number | undefined,\n): SubmissionTypes.S3SubmissionData['submission'] | void {\n const result: SubmissionTypes.S3SubmissionData['submission'] = {\n ...submission,\n }\n let hasChanges = false\n for (const formElement of formElements) {\n switch (formElement.type) {\n case 'section':\n case 'page': {\n const newSubmission = checkIfAttachmentsExistForFormElements(\n formElement.elements,\n result,\n attachmentRetentionInDays,\n )\n if (newSubmission) {\n hasChanges = true\n Object.assign(result, newSubmission)\n }\n break\n }\n case 'form': {\n const nestedSubmission = submission[formElement.name]\n if (!nestedSubmission || typeof nestedSubmission !== 'object') {\n break\n }\n const newSubmission = checkIfAttachmentsExistForFormElements(\n formElement.elements || [],\n nestedSubmission as SubmissionTypes.S3SubmissionData['submission'],\n attachmentRetentionInDays,\n )\n if (newSubmission) {\n hasChanges = true\n result[formElement.name] = newSubmission\n }\n break\n }\n case 'repeatableSet': {\n const entries = submission[formElement.name]\n if (!Array.isArray(entries)) {\n break\n }\n const newEntries = [...entries]\n let hasEntryChanges = false\n for (let index = 0; index < entries.length; index++) {\n const entry = entries[index]\n if (typeof entry === 'object') {\n const newEntry = checkIfAttachmentsExistForFormElements(\n formElement.elements,\n entry,\n attachmentRetentionInDays,\n )\n if (newEntry) {\n hasEntryChanges = true\n newEntries[index] = newEntry\n }\n }\n }\n if (hasEntryChanges) {\n hasChanges = true\n result[formElement.name] = newEntries\n }\n break\n }\n case 'arcGISWebMap':\n case 'camera':\n case 'draw':\n case 'compliance':\n case 'files': {\n const value = submission[formElement.name]\n if (!value) {\n break\n }\n\n // If the attachment has a type, it has not finished uploading\n switch (formElement.type) {\n case 'camera':\n case 'draw': {\n const attachmentError = validateAttachmentExists(\n value as attachmentsService.Attachment,\n attachmentRetentionInDays,\n )\n if (attachmentError) {\n hasChanges = true\n result[formElement.name] = attachmentError\n }\n break\n }\n case 'compliance': {\n const newAttachments = validateAttachmentsExists(\n (value as FormElementComplianceValue).files,\n attachmentRetentionInDays,\n )\n if (newAttachments) {\n hasChanges = true\n result[formElement.name] = {\n ...(value as FormElementComplianceValue),\n files: newAttachments,\n }\n }\n break\n }\n case 'files': {\n const newAttachments = validateAttachmentsExists(\n value,\n attachmentRetentionInDays,\n )\n if (newAttachments) {\n hasChanges = true\n result[formElement.name] = newAttachments\n }\n break\n }\n case 'arcGISWebMap': {\n const arcGISWebMapElementValue =\n value as ArcGISTypes.ArcGISWebMapElementValue\n const snapshotImages = validateAttachmentsExists(\n arcGISWebMapElementValue.snapshotImages,\n attachmentRetentionInDays,\n )\n if (snapshotImages) {\n hasChanges = true\n result[formElement.name] = {\n ...value,\n snapshotImages,\n }\n }\n break\n }\n }\n }\n }\n }\n if (hasChanges) {\n return result\n }\n}\n\nexport default function checkIfAttachmentsExist(\n form: FormTypes.Form,\n submission: SubmissionTypes.S3SubmissionData['submission'],\n attachmentRetentionInDays: number | undefined,\n): SubmissionTypes.S3SubmissionData['submission'] | void {\n return checkIfAttachmentsExistForFormElements(\n form.elements,\n submission,\n attachmentRetentionInDays,\n )\n}\n"]}