@oneblink/apps-react 11.0.0-beta.9 → 11.0.0
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.
- package/dist/apps/job-service.d.ts +34 -0
- package/dist/apps/job-service.js +45 -0
- package/dist/apps/job-service.js.map +1 -1
- package/dist/apps/mfa-service.d.ts +2 -2
- package/dist/apps/mfa-service.js +1 -1
- package/dist/apps/mfa-service.js.map +1 -1
- package/dist/apps/services/AWSCognitoClient.d.ts +3 -0
- package/dist/apps/services/AWSCognitoClient.js +58 -27
- package/dist/apps/services/AWSCognitoClient.js.map +1 -1
- package/dist/apps/services/cognito.d.ts +2 -2
- package/dist/apps/services/cognito.js.map +1 -1
- package/dist/apps/services/submit.js +10 -0
- package/dist/apps/services/submit.js.map +1 -1
- package/dist/components/mfa/MfaMethodRow.d.ts +4 -2
- package/dist/components/mfa/MfaMethodRow.js +7 -4
- package/dist/components/mfa/MfaMethodRow.js.map +1 -1
- package/dist/components/mfa/MultiFactorAuthentication.d.ts +2 -1
- package/dist/components/mfa/MultiFactorAuthentication.js +12 -11
- package/dist/components/mfa/MultiFactorAuthentication.js.map +1 -1
- package/dist/styles/barcode-scanner.scss +4 -0
- package/dist/styles.css +5 -0
- package/dist/styles.scss +1 -0
- package/dist/utils/mfa-requirement.d.ts +4 -4
- package/dist/utils/mfa-requirement.js +65 -16
- package/dist/utils/mfa-requirement.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cognito.js","sourceRoot":"","sources":["../../../src/apps/services/cognito.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAEtC,OAAO,gBAAgB,EAAE,EACvB,oBAAoB,GAIrB,MAAM,oBAAoB,CAAA;AAE3B,OAAO,KAAK,cAAc,MAAM,oBAAoB,CAAA;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAEhD,OAAO,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K,CACb,6GAA6G,CAC9G,CAAA;IACH,CAAC;IAED,OAAO,MAAM,gBAAgB,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;AACpD,CAAC;AAED,KAAK,UAAU,gBAAgB,CAAC,MAAiB;IAC/C,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CACb,qHAAqH,CACtH,CAAA;IACH,CAAC;IAED,OAAO,MAAM,gBAAgB,CAAC,gBAAgB,CAAC,MAAM,CAAC,CAAA;AACxD,CAAC;AAED,KAAK,UAAU,qBAAqB,CAAC,MAAiB;IACpD,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CACb,4HAA4H,CAC7H,CAAA;IACH,CAAC;IAED,OAAO,MAAM,gBAAgB,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAA;AAC7D,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,KAAK,UAAU,wBAAwB,CAAC,OAAiC;IACvE,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CACb,2HAA2H,CAC5H,CAAA;IACH,CAAC;IAED,OAAO,MAAM,gBAAgB,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAA;AACjE,CAAC;AAED,OAAO,EACL,IAAI,EACJ,oBAAoB,EACpB,qBAAqB,EACrB,aAAa,EACb,oBAAoB,EACpB,cAAc,EACd,cAAc,EACd,cAAc,EACd,MAAM,EACN,UAAU,EACV,iBAAiB,EACjB,cAAc,EACd,mBAAmB,EACnB,cAAc,EACd,qBAAqB,EACrB,qBAAqB,EACrB,qBAAqB,EACrB,gBAAgB,EAChB,qBAAqB,EACrB,WAAW,EACX,wBAAwB,EACxB,oCAAoC,EACpC,oBAAoB,GACrB,CAAA","sourcesContent":["import { jwtDecode } from 'jwt-decode'\n\nimport AWSCognitoClient, {\n DEFAULT_MFA_SETTINGS,\n LoginAttemptResponse,\n MfaMethod,\n MfaSettings,\n} from './AWSCognitoClient'\n\nimport * as offlineService from '../offline-service'\nimport { userService } from '@oneblink/sdk-core'\nimport { MiscTypes } from '@oneblink/types'\nimport { HTTPError, postRequest } from './fetch'\nimport tenants from '../tenants'\nimport OneBlinkAppsError from './errors/oneBlinkAppsError'\n\ninterface CognitoServiceData {\n oAuthClientId: string\n loginDomain: string\n region: string\n redirectUri: string\n logoutUri: string\n}\n\nconst CONTINUE_TO = 'continueTo'\n\nlet awsCognitoClient: null | AWSCognitoClient = null\n\nfunction init(cognitoServiceData: CognitoServiceData) {\n console.log('Initiating CognitoIdentityServiceProvider', cognitoServiceData)\n\n awsCognitoClient = new AWSCognitoClient({\n clientId: cognitoServiceData.oAuthClientId,\n region: cognitoServiceData.region,\n loginDomain: cognitoServiceData.loginDomain,\n redirectUri: cognitoServiceData.redirectUri,\n logoutUri: cognitoServiceData.logoutUri,\n })\n}\n\n/**\n * Register a listener function that will be call when authentication tokens are\n * updated or removed.\n *\n * #### Example\n *\n * ```js\n * const listener = async () => {\n * // Check if the user is logged in still\n * const isLoggedIn = authService.isLoggedIn()\n * }\n * const deregister = await authService.registerAuthListener(listener)\n *\n * // When no longer needed, remember to deregister the listener\n * deregister()\n * ```\n *\n * @param listener\n * @returns\n */\nfunction registerAuthListener(listener: () => unknown): () => void {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to register a listener.',\n )\n }\n return awsCognitoClient.registerListener(listener)\n}\n\n/**\n * Create a session for a user by entering a username and password. If the user\n * requires a password reset, the \"resetPasswordCallback\" property will be\n * returned. This function should be called with the new password once entered\n * by the user. If the user requires an MFA token, the \"mfa\" property will be\n * returned. Its \"codeCallback\" should be called with the one-time token. The\n * functions returned are recursive and the result from each of them is the same\n * result from the loginUsernamePassword() function. Each time the response\n * includes a callback, you will need to begin the process again until all\n * callbacks are handled.\n *\n * #### Example\n *\n * ```js\n * async function handleLoginAttemptResponse({\n * resetPasswordCallback,\n * mfa,\n * }) {\n * // \"resetPasswordCallback\" will be undefined if a password reset was not required.\n * if (resetPasswordCallback) {\n * // Prompt the user to enter a new password\n * const newPassword = prompt(\n * 'The password you entered was only temporary, and must be reset for security purposes. Please enter your new password below to continue.',\n * )\n * const resetPasswordResponse =\n * await resetPasswordCallback(newPassword)\n * return await handleLoginAttemptResponse(resetPasswordResponse)\n * }\n *\n * // \"mfa\" will be undefined if MFA is not setup.\n * if (mfa) {\n * // Prompt the user to enter an MFA code\n * const code = prompt(\n * mfa.method === 'email'\n * ? 'Please enter the one-time code sent to your email.'\n * : 'Please enter a one-time code from your MFA app.',\n * )\n * const mfaCodeResponse = await mfa.codeCallback(code)\n * return await handleLoginAttemptResponse(mfaCodeResponse)\n * }\n * }\n *\n * const username = 'user@email.io'\n * const password = 'P@$5w0rd'\n *\n * const loginAttemptResponse = await authService.loginUsernamePassword(\n * username,\n * password,\n * )\n *\n * await handleLoginAttemptResponse(loginAttemptResponse)\n * ```\n *\n * @param username\n * @param password\n * @returns\n */\nasync function loginUsernamePassword(username: string, password: string) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to login.',\n )\n }\n console.log('Attempting sign using username', username)\n return awsCognitoClient.loginUsernamePassword(\n username.toLowerCase(),\n password,\n )\n}\n\n/**\n * Redirect the user to the login screen. Passing an `identityProvider` is\n * optionally, it will allow users to skip the login page and be directed\n * straight to that providers login page\n *\n * #### Example\n *\n * ```js\n * // OPtionally pass a\n * const identityProvider = 'Google'\n * await authService.loginHostedUI(identityProvider)\n * // User will be redirected to login page or promise will resolve\n * ```\n *\n * @param identityProviderName\n * @returns\n */\nasync function loginHostedUI(identityProviderName?: string): Promise<void> {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to login.',\n )\n }\n const continueTo = `${window.location.pathname}${window.location.search}`\n localStorage.setItem(CONTINUE_TO, continueTo)\n\n return awsCognitoClient.loginHostedUI(identityProviderName)\n}\n\n/**\n * This function should be called when the user is redirected back to your app\n * after a login attempt. It will use the query string add the redirect URL to\n * create a session for the current user. It will return a URL as a `string`\n * that should be redirected to within your app.\n *\n * #### Example\n *\n * ```js\n * try {\n * const continueTo = await authService.handleAuthentication()\n * // Redirect the user back to where they were before attempting to login\n * window.location.href = continueTo\n * } catch (error) {\n * // handle failed login attempts here.\n * }\n * ```\n *\n * @returns\n */\nasync function handleAuthentication(): Promise<string> {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to handle authentication in URL.',\n )\n }\n\n const continueTo = localStorage.getItem(CONTINUE_TO) || '/'\n if (isLoggedIn()) {\n console.log('Already authenticated, redirecting to:', continueTo)\n } else {\n await awsCognitoClient.handleAuthentication()\n }\n\n localStorage.removeItem(CONTINUE_TO)\n\n return continueTo\n}\n\n/**\n * Allow the currently logged in user to change their password by passing their\n * existing password and a new password.\n *\n * #### Example\n *\n * ```js\n * const currentPassword = 'P@$5w0rd'\n * const newPassword = 'P@$5w0rD'\n * await authService.changePassword(currentPassword, newPassword)\n * ```\n *\n * @param existingPassword\n * @param newPassword\n * @returns\n */\nasync function changePassword(existingPassword: string, newPassword: string) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to change passwords.',\n )\n }\n\n return await awsCognitoClient.changePassword(existingPassword, newPassword)\n}\n\n/**\n * Allow a user to start the forgot password process. The user will be emailed a\n * temporary code that must be passed with a new password to the function\n * returned.\n *\n * #### Example\n *\n * ```js\n * const username = 'user@email.io'\n * const finishForgotPassword = await authService.forgotPassword(username)\n *\n * // Prompt the user to enter the code and a new password\n * const code = prompt(\n * 'You have been emailed a verification code, please enter it here.',\n * )\n * const newPassword = prompt('Please enter a new password to continue.')\n * await finishForgotPassword(code, newPassword)\n * ```\n *\n * @param username\n * @param formsAppId Used to give the resulting email sent to the user\n * associated forms app branding and sending address\n * @returns\n */\nasync function forgotPassword(\n username: string,\n /**\n * Used to give the resulting email sent to the user associated forms app\n * branding and sending address\n */\n formsAppId?: number,\n): Promise<(code: string, password: string) => Promise<void>> {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before starting the forgot password process.',\n )\n }\n\n try {\n const url = `${tenants.current.apiOrigin}/authentication/reset-password`\n await postRequest(url, {\n username,\n formsAppId,\n })\n } catch (err) {\n const error = err as HTTPError\n switch (error.status) {\n case 400: {\n throw new OneBlinkAppsError(error.message, {\n title: 'Invalid Request',\n httpStatusCode: error.status,\n })\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n\n return async (code, password) => {\n await awsCognitoClient?.confirmForgotPassword({\n username,\n code,\n password,\n })\n }\n}\n\n/**\n * Redirect the user to the logout screen to clear the users session on the\n * hosted login page. User will then be redirected to `/logout`. After being\n * redirected back to the application, the `logout()` function should be called\n * to clear the session data from browser storage.\n *\n * #### Example\n *\n * ```js\n * authService.logoutHostedUI()\n * ```\n */\nfunction logoutHostedUI(): void {\n if (awsCognitoClient) {\n awsCognitoClient.logoutHostedUI()\n }\n}\n\nasync function logout() {\n if (awsCognitoClient) {\n await awsCognitoClient.logout()\n }\n}\n\n/**\n * Check if the user is currently logged in\n *\n * #### Example\n *\n * ```js\n * const isLoggedIn = authService.isLoggedIn()\n * // handle user being logged in or not\n * ```\n *\n * @returns\n */\nfunction isLoggedIn(): boolean {\n return !!(awsCognitoClient && awsCognitoClient._getRefreshToken())\n}\n\nasync function getCognitoIdToken(): Promise<string | undefined> {\n if (!awsCognitoClient) {\n return\n }\n\n if (offlineService.isOffline()) {\n return awsCognitoClient._getIdToken()\n }\n\n return await awsCognitoClient.getIdToken()\n}\n\n/**\n * Get current users profile based on there Id Token payload. This will return\n * `null` if the the current user is not logged in.\n *\n * #### Example\n *\n * ```js\n * const profile = authService.getUserProfile()\n * if (profile) {\n * // Use profile here\n * }\n * ```\n *\n * @returns\n */\nfunction getUserProfile(): MiscTypes.UserProfile | null {\n if (!awsCognitoClient) {\n return null\n }\n const idToken = awsCognitoClient._getIdToken()\n if (!idToken) {\n return null\n }\n\n const jwtToken = jwtDecode(idToken)\n return userService.parseUserProfile(jwtToken) || null\n}\n\nexport function getUsername(): string | undefined {\n const profile = getUserProfile()\n if (!profile) {\n return undefined\n }\n\n return profile.username\n}\n\n/**\n * A friendly `string` that represents the current user. Uses first name, last\n * name, full name and username. This will return `null` the current user is not\n * logged in.\n *\n * #### Example\n *\n * ```js\n * const name = authService.getUserFriendlyName()\n * if (name) {\n * // Display current user's name\n * }\n * ```\n *\n * @returns\n */\nfunction getUserFriendlyName(): string | undefined {\n const profile = getUserProfile()\n if (!profile) {\n return\n }\n\n return userService.getUserFriendlyName(profile)\n}\n\n/**\n * Generate a QR code link to display to a user after they have initiated\n * authenticator app MFA setup.\n *\n * #### Example\n *\n * ```js\n * const mfaAuthenticatorAppSetupQrCodeUrl =\n * mfaService.generateMfaAuthenticatorAppQrCodeUrl()\n * if (mfaAuthenticatorAppSetupQrCodeUrl) {\n * // use mfaAuthenticatorAppSetupQrCodeUrl to display QR code to user\n * }\n * ```\n *\n * @returns\n */\nfunction generateMfaAuthenticatorAppQrCodeUrl(\n mfaAuthenticatorAppSetup: Awaited<\n ReturnType<typeof setupMfaAuthenticatorApp>\n >,\n): string | undefined {\n const profile = getUserProfile()\n if (!profile || !mfaAuthenticatorAppSetup) {\n return\n }\n\n return `otpauth://totp/${tenants.current.productShortName}:${profile.email}?secret=${mfaAuthenticatorAppSetup.secretCode}&issuer=${tenants.current.productShortName}`\n}\n\nasync function getMfaSettings(abortSignal?: AbortSignal) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before checking MFA settings.',\n )\n }\n\n return await awsCognitoClient.getMfaSettings(abortSignal)\n}\n\nasync function updateUserPhoneNumber(phoneNumber: string) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before updating the user phone number.',\n )\n }\n\n return await awsCognitoClient.updateUserPhoneNumber(phoneNumber)\n}\n\nasync function removeUserPhoneNumber() {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before removing the user phone number.',\n )\n }\n\n return await awsCognitoClient.removeUserPhoneNumber()\n}\n\nasync function verifyUserPhoneNumber(code: string) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before verifying the user phone number.',\n )\n }\n\n return await awsCognitoClient.verifyUserPhoneNumber(code)\n}\n\nasync function setupSmsMfa(options?: { preferred?: boolean }) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to setup SMS MFA.',\n )\n }\n\n return await awsCognitoClient.setupSmsMfa(options)\n}\n\nasync function disableMfaMethod(method: MfaMethod) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to disable an MFA method.',\n )\n }\n\n return await awsCognitoClient.disableMfaMethod(method)\n}\n\nasync function setPreferredMfaMethod(method: MfaMethod) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to set the preferred MFA method.',\n )\n }\n\n return await awsCognitoClient.setPreferredMfaMethod(method)\n}\n\n/**\n * Setup authenticator app MFA for the current user. The result will include a\n * callback that should be called with the valid TOTP from an authenticator\n * app.\n *\n * #### Example\n *\n * ```js\n * const { secretCode, mfaCodeCallback } =\n * await mfaService.setupMfaAuthenticatorApp()\n * // Prompt the user to enter an MFA code\n * const code = prompt(\n * `Please enter a one-time code from your MFA app after creating a new entry with secret: ${secretCode}.`,\n * )\n * await mfaCodeCallback(code)\n * ```\n *\n * @returns\n */\nasync function setupMfaAuthenticatorApp(options?: { preferred?: boolean }) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to setup authenticator app MFA.',\n )\n }\n\n return await awsCognitoClient.setupMfaAuthenticatorApp(options)\n}\n\nexport {\n init,\n registerAuthListener,\n loginUsernamePassword,\n loginHostedUI,\n handleAuthentication,\n changePassword,\n forgotPassword,\n logoutHostedUI,\n logout,\n isLoggedIn,\n getCognitoIdToken,\n getUserProfile,\n getUserFriendlyName,\n getMfaSettings,\n updateUserPhoneNumber,\n removeUserPhoneNumber,\n verifyUserPhoneNumber,\n disableMfaMethod,\n setPreferredMfaMethod,\n setupSmsMfa,\n setupMfaAuthenticatorApp,\n generateMfaAuthenticatorAppQrCodeUrl,\n DEFAULT_MFA_SETTINGS,\n}\nexport type { LoginAttemptResponse, MfaMethod, MfaSettings }\n"]}
|
|
1
|
+
{"version":3,"file":"cognito.js","sourceRoot":"","sources":["../../../src/apps/services/cognito.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAEtC,OAAO,gBAAgB,EAAE,EACvB,oBAAoB,GAKrB,MAAM,oBAAoB,CAAA;AAE3B,OAAO,KAAK,cAAc,MAAM,oBAAoB,CAAA;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAEhD,OAAO,EAAa,WAAW,EAAE,MAAM,SAAS,CAAA;AAChD,OAAO,OAAO,MAAM,YAAY,CAAA;AAChC,OAAO,iBAAiB,MAAM,4BAA4B,CAAA;AAU1D,MAAM,WAAW,GAAG,YAAY,CAAA;AAEhC,IAAI,gBAAgB,GAA4B,IAAI,CAAA;AAEpD,SAAS,IAAI,CAAC,kBAAsC;IAClD,OAAO,CAAC,GAAG,CAAC,2CAA2C,EAAE,kBAAkB,CAAC,CAAA;IAE5E,gBAAgB,GAAG,IAAI,gBAAgB,CAAC;QACtC,QAAQ,EAAE,kBAAkB,CAAC,aAAa;QAC1C,MAAM,EAAE,kBAAkB,CAAC,MAAM;QACjC,WAAW,EAAE,kBAAkB,CAAC,WAAW;QAC3C,WAAW,EAAE,kBAAkB,CAAC,WAAW;QAC3C,SAAS,EAAE,kBAAkB,CAAC,SAAS;KACxC,CAAC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C;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,KAAK,UAAU,wBAAwB,CAAC,OAAiC;IACvE,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CACb,2HAA2H,CAC5H,CAAA;IACH,CAAC;IAED,OAAO,MAAM,gBAAgB,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAA;AACjE,CAAC;AAED,OAAO,EACL,IAAI,EACJ,oBAAoB,EACpB,qBAAqB,EACrB,aAAa,EACb,oBAAoB,EACpB,cAAc,EACd,cAAc,EACd,cAAc,EACd,MAAM,EACN,UAAU,EACV,iBAAiB,EACjB,cAAc,EACd,mBAAmB,EACnB,cAAc,EACd,qBAAqB,EACrB,qBAAqB,EACrB,qBAAqB,EACrB,gBAAgB,EAChB,qBAAqB,EACrB,WAAW,EACX,wBAAwB,EACxB,oCAAoC,EACpC,oBAAoB,GACrB,CAAA","sourcesContent":["import { jwtDecode } from 'jwt-decode'\n\nimport AWSCognitoClient, {\n DEFAULT_MFA_SETTINGS,\n LoginAttemptResponse,\n LoggedInMfaMethod,\n MfaMethod,\n MfaSettings,\n} from './AWSCognitoClient'\n\nimport * as offlineService from '../offline-service'\nimport { userService } from '@oneblink/sdk-core'\nimport { MiscTypes } from '@oneblink/types'\nimport { HTTPError, postRequest } from './fetch'\nimport tenants from '../tenants'\nimport OneBlinkAppsError from './errors/oneBlinkAppsError'\n\ninterface CognitoServiceData {\n oAuthClientId: string\n loginDomain: string\n region: string\n redirectUri: string\n logoutUri: string\n}\n\nconst CONTINUE_TO = 'continueTo'\n\nlet awsCognitoClient: null | AWSCognitoClient = null\n\nfunction init(cognitoServiceData: CognitoServiceData) {\n console.log('Initiating CognitoIdentityServiceProvider', cognitoServiceData)\n\n awsCognitoClient = new AWSCognitoClient({\n clientId: cognitoServiceData.oAuthClientId,\n region: cognitoServiceData.region,\n loginDomain: cognitoServiceData.loginDomain,\n redirectUri: cognitoServiceData.redirectUri,\n logoutUri: cognitoServiceData.logoutUri,\n })\n}\n\n/**\n * Register a listener function that will be call when authentication tokens are\n * updated or removed.\n *\n * #### Example\n *\n * ```js\n * const listener = async () => {\n * // Check if the user is logged in still\n * const isLoggedIn = authService.isLoggedIn()\n * }\n * const deregister = await authService.registerAuthListener(listener)\n *\n * // When no longer needed, remember to deregister the listener\n * deregister()\n * ```\n *\n * @param listener\n * @returns\n */\nfunction registerAuthListener(listener: () => unknown): () => void {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to register a listener.',\n )\n }\n return awsCognitoClient.registerListener(listener)\n}\n\n/**\n * Create a session for a user by entering a username and password. If the user\n * requires a password reset, the \"resetPasswordCallback\" property will be\n * returned. This function should be called with the new password once entered\n * by the user. If the user requires an MFA token, the \"mfa\" property will be\n * returned. Its \"codeCallback\" should be called with the one-time token. The\n * functions returned are recursive and the result from each of them is the same\n * result from the loginUsernamePassword() function. Each time the response\n * includes a callback, you will need to begin the process again until all\n * callbacks are handled.\n *\n * #### Example\n *\n * ```js\n * async function handleLoginAttemptResponse({\n * resetPasswordCallback,\n * mfa,\n * }) {\n * // \"resetPasswordCallback\" will be undefined if a password reset was not required.\n * if (resetPasswordCallback) {\n * // Prompt the user to enter a new password\n * const newPassword = prompt(\n * 'The password you entered was only temporary, and must be reset for security purposes. Please enter your new password below to continue.',\n * )\n * const resetPasswordResponse =\n * await resetPasswordCallback(newPassword)\n * return await handleLoginAttemptResponse(resetPasswordResponse)\n * }\n *\n * // \"mfa\" will be undefined if MFA is not setup.\n * if (mfa) {\n * // Prompt the user to enter an MFA code\n * const code = prompt(\n * mfa.method === 'email'\n * ? 'Please enter the one-time code sent to your email.'\n * : 'Please enter a one-time code from your MFA app.',\n * )\n * const mfaCodeResponse = await mfa.codeCallback(code)\n * return await handleLoginAttemptResponse(mfaCodeResponse)\n * }\n * }\n *\n * const username = 'user@email.io'\n * const password = 'P@$5w0rd'\n *\n * const loginAttemptResponse = await authService.loginUsernamePassword(\n * username,\n * password,\n * )\n *\n * await handleLoginAttemptResponse(loginAttemptResponse)\n * ```\n *\n * @param username\n * @param password\n * @returns\n */\nasync function loginUsernamePassword(username: string, password: string) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to login.',\n )\n }\n console.log('Attempting sign using username', username)\n return awsCognitoClient.loginUsernamePassword(\n username.toLowerCase(),\n password,\n )\n}\n\n/**\n * Redirect the user to the login screen. Passing an `identityProvider` is\n * optionally, it will allow users to skip the login page and be directed\n * straight to that providers login page\n *\n * #### Example\n *\n * ```js\n * // OPtionally pass a\n * const identityProvider = 'Google'\n * await authService.loginHostedUI(identityProvider)\n * // User will be redirected to login page or promise will resolve\n * ```\n *\n * @param identityProviderName\n * @returns\n */\nasync function loginHostedUI(identityProviderName?: string): Promise<void> {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to login.',\n )\n }\n const continueTo = `${window.location.pathname}${window.location.search}`\n localStorage.setItem(CONTINUE_TO, continueTo)\n\n return awsCognitoClient.loginHostedUI(identityProviderName)\n}\n\n/**\n * This function should be called when the user is redirected back to your app\n * after a login attempt. It will use the query string add the redirect URL to\n * create a session for the current user. It will return a URL as a `string`\n * that should be redirected to within your app.\n *\n * #### Example\n *\n * ```js\n * try {\n * const continueTo = await authService.handleAuthentication()\n * // Redirect the user back to where they were before attempting to login\n * window.location.href = continueTo\n * } catch (error) {\n * // handle failed login attempts here.\n * }\n * ```\n *\n * @returns\n */\nasync function handleAuthentication(): Promise<string> {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to handle authentication in URL.',\n )\n }\n\n const continueTo = localStorage.getItem(CONTINUE_TO) || '/'\n if (isLoggedIn()) {\n console.log('Already authenticated, redirecting to:', continueTo)\n } else {\n await awsCognitoClient.handleAuthentication()\n }\n\n localStorage.removeItem(CONTINUE_TO)\n\n return continueTo\n}\n\n/**\n * Allow the currently logged in user to change their password by passing their\n * existing password and a new password.\n *\n * #### Example\n *\n * ```js\n * const currentPassword = 'P@$5w0rd'\n * const newPassword = 'P@$5w0rD'\n * await authService.changePassword(currentPassword, newPassword)\n * ```\n *\n * @param existingPassword\n * @param newPassword\n * @returns\n */\nasync function changePassword(existingPassword: string, newPassword: string) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to change passwords.',\n )\n }\n\n return await awsCognitoClient.changePassword(existingPassword, newPassword)\n}\n\n/**\n * Allow a user to start the forgot password process. The user will be emailed a\n * temporary code that must be passed with a new password to the function\n * returned.\n *\n * #### Example\n *\n * ```js\n * const username = 'user@email.io'\n * const finishForgotPassword = await authService.forgotPassword(username)\n *\n * // Prompt the user to enter the code and a new password\n * const code = prompt(\n * 'You have been emailed a verification code, please enter it here.',\n * )\n * const newPassword = prompt('Please enter a new password to continue.')\n * await finishForgotPassword(code, newPassword)\n * ```\n *\n * @param username\n * @param formsAppId Used to give the resulting email sent to the user\n * associated forms app branding and sending address\n * @returns\n */\nasync function forgotPassword(\n username: string,\n /**\n * Used to give the resulting email sent to the user associated forms app\n * branding and sending address\n */\n formsAppId?: number,\n): Promise<(code: string, password: string) => Promise<void>> {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before starting the forgot password process.',\n )\n }\n\n try {\n const url = `${tenants.current.apiOrigin}/authentication/reset-password`\n await postRequest(url, {\n username,\n formsAppId,\n })\n } catch (err) {\n const error = err as HTTPError\n switch (error.status) {\n case 400: {\n throw new OneBlinkAppsError(error.message, {\n title: 'Invalid Request',\n httpStatusCode: error.status,\n })\n }\n default: {\n throw new OneBlinkAppsError(\n 'An unknown error has occurred. Please contact support if the problem persists.',\n {\n originalError: error,\n httpStatusCode: error.status,\n },\n )\n }\n }\n }\n\n return async (code, password) => {\n await awsCognitoClient?.confirmForgotPassword({\n username,\n code,\n password,\n })\n }\n}\n\n/**\n * Redirect the user to the logout screen to clear the users session on the\n * hosted login page. User will then be redirected to `/logout`. After being\n * redirected back to the application, the `logout()` function should be called\n * to clear the session data from browser storage.\n *\n * #### Example\n *\n * ```js\n * authService.logoutHostedUI()\n * ```\n */\nfunction logoutHostedUI(): void {\n if (awsCognitoClient) {\n awsCognitoClient.logoutHostedUI()\n }\n}\n\nasync function logout() {\n if (awsCognitoClient) {\n await awsCognitoClient.logout()\n }\n}\n\n/**\n * Check if the user is currently logged in\n *\n * #### Example\n *\n * ```js\n * const isLoggedIn = authService.isLoggedIn()\n * // handle user being logged in or not\n * ```\n *\n * @returns\n */\nfunction isLoggedIn(): boolean {\n return !!(awsCognitoClient && awsCognitoClient._getRefreshToken())\n}\n\nasync function getCognitoIdToken(): Promise<string | undefined> {\n if (!awsCognitoClient) {\n return\n }\n\n if (offlineService.isOffline()) {\n return awsCognitoClient._getIdToken()\n }\n\n return await awsCognitoClient.getIdToken()\n}\n\n/**\n * Get current users profile based on there Id Token payload. This will return\n * `null` if the the current user is not logged in.\n *\n * #### Example\n *\n * ```js\n * const profile = authService.getUserProfile()\n * if (profile) {\n * // Use profile here\n * }\n * ```\n *\n * @returns\n */\nfunction getUserProfile(): MiscTypes.UserProfile | null {\n if (!awsCognitoClient) {\n return null\n }\n const idToken = awsCognitoClient._getIdToken()\n if (!idToken) {\n return null\n }\n\n const jwtToken = jwtDecode(idToken)\n return userService.parseUserProfile(jwtToken) || null\n}\n\nexport function getUsername(): string | undefined {\n const profile = getUserProfile()\n if (!profile) {\n return undefined\n }\n\n return profile.username\n}\n\n/**\n * A friendly `string` that represents the current user. Uses first name, last\n * name, full name and username. This will return `null` the current user is not\n * logged in.\n *\n * #### Example\n *\n * ```js\n * const name = authService.getUserFriendlyName()\n * if (name) {\n * // Display current user's name\n * }\n * ```\n *\n * @returns\n */\nfunction getUserFriendlyName(): string | undefined {\n const profile = getUserProfile()\n if (!profile) {\n return\n }\n\n return userService.getUserFriendlyName(profile)\n}\n\n/**\n * Generate a QR code link to display to a user after they have initiated\n * authenticator app MFA setup.\n *\n * #### Example\n *\n * ```js\n * const mfaAuthenticatorAppSetupQrCodeUrl =\n * mfaService.generateMfaAuthenticatorAppQrCodeUrl()\n * if (mfaAuthenticatorAppSetupQrCodeUrl) {\n * // use mfaAuthenticatorAppSetupQrCodeUrl to display QR code to user\n * }\n * ```\n *\n * @returns\n */\nfunction generateMfaAuthenticatorAppQrCodeUrl(\n mfaAuthenticatorAppSetup: Awaited<\n ReturnType<typeof setupMfaAuthenticatorApp>\n >,\n): string | undefined {\n const profile = getUserProfile()\n if (!profile || !mfaAuthenticatorAppSetup) {\n return\n }\n\n return `otpauth://totp/${tenants.current.productShortName}:${profile.email}?secret=${mfaAuthenticatorAppSetup.secretCode}&issuer=${tenants.current.productShortName}`\n}\n\nasync function getMfaSettings(abortSignal?: AbortSignal) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before checking MFA settings.',\n )\n }\n\n return await awsCognitoClient.getMfaSettings(abortSignal)\n}\n\nasync function updateUserPhoneNumber(phoneNumber: string) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before updating the user phone number.',\n )\n }\n\n return await awsCognitoClient.updateUserPhoneNumber(phoneNumber)\n}\n\nasync function removeUserPhoneNumber() {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before removing the user phone number.',\n )\n }\n\n return await awsCognitoClient.removeUserPhoneNumber()\n}\n\nasync function verifyUserPhoneNumber(code: string) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before verifying the user phone number.',\n )\n }\n\n return await awsCognitoClient.verifyUserPhoneNumber(code)\n}\n\nasync function setupSmsMfa(options?: { preferred?: boolean }) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to setup SMS MFA.',\n )\n }\n\n return await awsCognitoClient.setupSmsMfa(options)\n}\n\nasync function disableMfaMethod(method: MfaMethod) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to disable an MFA method.',\n )\n }\n\n return await awsCognitoClient.disableMfaMethod(method)\n}\n\nasync function setPreferredMfaMethod(method: MfaMethod) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to set the preferred MFA method.',\n )\n }\n\n return await awsCognitoClient.setPreferredMfaMethod(method)\n}\n\n/**\n * Setup authenticator app MFA for the current user. The result will include a\n * callback that should be called with the valid TOTP from an authenticator\n * app.\n *\n * #### Example\n *\n * ```js\n * const { secretCode, mfaCodeCallback } =\n * await mfaService.setupMfaAuthenticatorApp()\n * // Prompt the user to enter an MFA code\n * const code = prompt(\n * `Please enter a one-time code from your MFA app after creating a new entry with secret: ${secretCode}.`,\n * )\n * await mfaCodeCallback(code)\n * ```\n *\n * @returns\n */\nasync function setupMfaAuthenticatorApp(options?: { preferred?: boolean }) {\n if (!awsCognitoClient) {\n throw new Error(\n '\"authService\" has not been initiated. You must call the init() function before attempting to setup authenticator app MFA.',\n )\n }\n\n return await awsCognitoClient.setupMfaAuthenticatorApp(options)\n}\n\nexport {\n init,\n registerAuthListener,\n loginUsernamePassword,\n loginHostedUI,\n handleAuthentication,\n changePassword,\n forgotPassword,\n logoutHostedUI,\n logout,\n isLoggedIn,\n getCognitoIdToken,\n getUserProfile,\n getUserFriendlyName,\n getMfaSettings,\n updateUserPhoneNumber,\n removeUserPhoneNumber,\n verifyUserPhoneNumber,\n disableMfaMethod,\n setPreferredMfaMethod,\n setupSmsMfa,\n setupMfaAuthenticatorApp,\n generateMfaAuthenticatorAppQrCodeUrl,\n DEFAULT_MFA_SETTINGS,\n}\nexport type { LoginAttemptResponse, LoggedInMfaMethod, MfaMethod, MfaSettings }\n"]}
|
|
@@ -11,6 +11,12 @@ import serverValidateForm from './server-validation';
|
|
|
11
11
|
import OneBlinkAppsError from './errors/oneBlinkAppsError';
|
|
12
12
|
import { uploadFormSubmission } from './api/submissions';
|
|
13
13
|
import { syncDrafts } from '../draft-service';
|
|
14
|
+
import { notifyJobSubmitted } from '../job-service';
|
|
15
|
+
function notifyJobSubmittedIfApplicable(formSubmission) {
|
|
16
|
+
if (formSubmission.jobId) {
|
|
17
|
+
notifyJobSubmitted(formSubmission.jobId);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
14
20
|
export default async function submit({ formSubmission, isPendingQueueEnabled, paymentReceiptUrl, paymentFormUrl, schedulingUrlConfiguration, onProgress, shouldRunServerValidation, shouldRunExternalIdGeneration, abortSignal, pendingTimestamp, alwaysSubmitViaPendingQueue, completionTimestamp, }) {
|
|
15
21
|
const paymentSubmissionEventConfiguration = checkForPaymentSubmissionEvent(formSubmission);
|
|
16
22
|
const schedulingSubmissionEvent = checkForSchedulingSubmissionEvent(formSubmission);
|
|
@@ -45,6 +51,7 @@ export default async function submit({ formSubmission, isPendingQueueEnabled, pa
|
|
|
45
51
|
}
|
|
46
52
|
console.log('Offline or always submitting via pending queue - saving submission to pending queue..');
|
|
47
53
|
await addFormSubmissionToPendingQueue(formSubmission);
|
|
54
|
+
notifyJobSubmittedIfApplicable(formSubmission);
|
|
48
55
|
return Object.assign({}, formSubmission, {
|
|
49
56
|
isOffline: isOffline(),
|
|
50
57
|
isInPendingQueue: true,
|
|
@@ -73,6 +80,7 @@ export default async function submit({ formSubmission, isPendingQueueEnabled, pa
|
|
|
73
80
|
}
|
|
74
81
|
console.log('Attachments still uploading - saving submission to pending queue..');
|
|
75
82
|
await addFormSubmissionToPendingQueue(formSubmission);
|
|
83
|
+
notifyJobSubmittedIfApplicable(formSubmission);
|
|
76
84
|
return Object.assign({}, formSubmission, {
|
|
77
85
|
isOffline: false,
|
|
78
86
|
isInPendingQueue: true,
|
|
@@ -173,6 +181,7 @@ export default async function submit({ formSubmission, isPendingQueueEnabled, pa
|
|
|
173
181
|
if (formSubmission.preFillFormDataId) {
|
|
174
182
|
await removePrefillFormData(formSubmission.preFillFormDataId);
|
|
175
183
|
}
|
|
184
|
+
notifyJobSubmittedIfApplicable(formSubmission);
|
|
176
185
|
return formSubmissionResult;
|
|
177
186
|
}
|
|
178
187
|
catch (error) {
|
|
@@ -195,6 +204,7 @@ export default async function submit({ formSubmission, isPendingQueueEnabled, pa
|
|
|
195
204
|
}
|
|
196
205
|
console.warn('Offline error thrown - saving submission to pending queue..', error);
|
|
197
206
|
await addFormSubmissionToPendingQueue(formSubmission);
|
|
207
|
+
notifyJobSubmittedIfApplicable(formSubmission);
|
|
198
208
|
return Object.assign({}, formSubmission, {
|
|
199
209
|
isOffline: true,
|
|
200
210
|
isInPendingQueue: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"submit.js","sourceRoot":"","sources":["../../../src/apps/services/submit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EACL,+BAA+B,EAC/B,4BAA4B,GAC7B,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,8BAA8B,EAC9B,4BAA4B,GAC7B,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAA;AAC/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAC1D,OAAO,EACL,+BAA+B,EAC/B,iCAAiC,GAClC,MAAM,sBAAsB,CAAA;AAQ7B,OAAO,EAAE,8BAA8B,EAAE,MAAM,wBAAwB,CAAA;AACvE,OAAO,OAAO,MAAM,YAAY,CAAA;AAChC,OAAO,oBAAoB,MAAM,0BAA0B,CAAA;AAC3D,OAAO,kBAAkB,MAAM,qBAAqB,CAAA;AACpD,OAAO,iBAAiB,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAkB7C,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,MAAM,CAAC,EACnC,c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AAgB,EAAE,IAAI;oBACtB,mBAAmB,EAAE,IAAI;oBACzB,YAAY,EAAE,IAAI;oBAClB,OAAO,EAAE,IAAI;oBACb,UAAU,EAAE,IAAI;oBAChB,sBAAsB,EAAE,KAAK;oBAC7B,cAAc,EAAE,KAAK;iBACtB,CAAC,CAAA;YACJ,CAAC;YAED,6CAA6C;YAC7C,4CAA4C;YAC5C,MAAM,KAAK,CAAA;QACb,CAAC;QAED,MAAM,IAAI,iBAAiB,CACzB,8FAA8F,EAC9F;YACE,KAAK,EAAE,kBAAkB;YACzB,aAAa,EAAE,KAAc;SAC9B,CACF,CAAA;IACH,CAAC;AACH,CAAC","sourcesContent":["import { isOffline } from '../offline-service'\nimport {\n addFormSubmissionToPendingQueue,\n deletePendingQueueSubmission,\n} from './pending-queue'\nimport {\n checkForPaymentSubmissionEvent,\n handlePaymentSubmissionEvent,\n} from '../payment-service'\nimport { removeLocalDraftSubmission } from './draft-data-store'\nimport { removePrefillFormData } from '../prefill-service'\nimport {\n handleSchedulingSubmissionEvent,\n checkForSchedulingSubmissionEvent,\n} from './schedulingHandlers'\nimport {\n FormSubmission,\n FormSubmissionResult,\n ProgressListener,\n ProgressListenerEvent,\n} from '../types/submissions'\nimport { SchedulingUrlConfiguration } from '../types/scheduling'\nimport { checkIfAttachmentsAreUploading } from '../attachments-service'\nimport tenants from '../tenants'\nimport externalIdGeneration from './external-id-generation'\nimport serverValidateForm from './server-validation'\nimport OneBlinkAppsError from './errors/oneBlinkAppsError'\nimport { uploadFormSubmission } from './api/submissions'\nimport { syncDrafts } from '../draft-service'\n\ntype SubmissionParams = {\n formSubmission: FormSubmission\n isPendingQueueEnabled: boolean\n shouldRunServerValidation: boolean\n shouldRunExternalIdGeneration: boolean\n paymentReceiptUrl: string | undefined\n paymentFormUrl: string | undefined\n schedulingUrlConfiguration?: SchedulingUrlConfiguration\n pendingTimestamp?: string\n alwaysSubmitViaPendingQueue?: boolean\n onProgress?: ProgressListener\n abortSignal?: AbortSignal\n}\n\nexport { SubmissionParams, ProgressListener, ProgressListenerEvent }\n\nexport default async function submit({\n formSubmission,\n isPendingQueueEnabled,\n paymentReceiptUrl,\n paymentFormUrl,\n schedulingUrlConfiguration,\n onProgress,\n shouldRunServerValidation,\n shouldRunExternalIdGeneration,\n abortSignal,\n pendingTimestamp,\n alwaysSubmitViaPendingQueue,\n completionTimestamp,\n}: SubmissionParams & {\n completionTimestamp: string\n}): Promise<FormSubmissionResult> {\n const paymentSubmissionEventConfiguration =\n checkForPaymentSubmissionEvent(formSubmission)\n\n const schedulingSubmissionEvent =\n checkForSchedulingSubmissionEvent(formSubmission)\n\n try {\n if (pendingTimestamp) {\n await deletePendingQueueSubmission(pendingTimestamp)\n }\n if (isOffline() || alwaysSubmitViaPendingQueue) {\n if (paymentSubmissionEventConfiguration || schedulingSubmissionEvent) {\n console.log(\n 'Offline or always submitting via pending queue - form has a payment/scheduling submission event that has not been processed yet, return offline',\n { paymentSubmissionEventConfiguration, schedulingSubmissionEvent },\n )\n return Object.assign({}, formSubmission, {\n isOffline: true,\n isInPendingQueue: false,\n submissionTimestamp: null,\n submissionId: null,\n payment: null,\n scheduling: null,\n isUploadingAttachments: false,\n })\n }\n\n if (!alwaysSubmitViaPendingQueue && !isPendingQueueEnabled) {\n console.log(\n 'Offline - app does not support pending queue, return offline',\n )\n return Object.assign({}, formSubmission, {\n isOffline: true,\n isInPendingQueue: false,\n submissionTimestamp: null,\n submissionId: null,\n payment: null,\n scheduling: null,\n isUploadingAttachments: false,\n })\n }\n\n console.log(\n 'Offline or always submitting via pending queue - saving submission to pending queue..',\n )\n await addFormSubmissionToPendingQueue(formSubmission)\n return Object.assign({}, formSubmission, {\n isOffline: isOffline(),\n isInPendingQueue: true,\n submissionTimestamp: null,\n submissionId: null,\n payment: null,\n preventPayment: false,\n scheduling: null,\n isUploadingAttachments: false,\n })\n }\n\n const attachmentsStillUploading = checkIfAttachmentsAreUploading(\n formSubmission.definition,\n formSubmission.submission,\n )\n\n if (attachmentsStillUploading) {\n if (paymentSubmissionEventConfiguration || schedulingSubmissionEvent) {\n console.log(\n 'Attachments still uploading - form has a payment/scheduling submission event that has not been processed yet, return isUploading',\n { paymentSubmissionEventConfiguration, schedulingSubmissionEvent },\n )\n return Object.assign({}, formSubmission, {\n isOffline: false,\n isInPendingQueue: false,\n submissionTimestamp: null,\n submissionId: null,\n payment: null,\n preventPayment: false,\n scheduling: null,\n isUploadingAttachments: true,\n })\n }\n console.log(\n 'Attachments still uploading - saving submission to pending queue..',\n )\n await addFormSubmissionToPendingQueue(formSubmission)\n return Object.assign({}, formSubmission, {\n isOffline: false,\n isInPendingQueue: true,\n submissionTimestamp: null,\n submissionId: null,\n payment: null,\n preventPayment: false,\n scheduling: null,\n isUploadingAttachments: true,\n })\n }\n\n if (shouldRunServerValidation) {\n await serverValidateForm(formSubmission)\n }\n if (shouldRunExternalIdGeneration) {\n const externalIdResult = await externalIdGeneration(formSubmission)\n if (externalIdResult.externalId) {\n formSubmission.externalId = externalIdResult.externalId\n }\n }\n\n const data = await uploadFormSubmission(\n formSubmission,\n completionTimestamp,\n onProgress,\n abortSignal,\n )\n\n const getDownloadSubmissionPdfUrls = () => {\n const allowPDFDownload =\n formSubmission.definition.postSubmissionReceipt?.allowPDFDownload\n if (!data.pdfAccessToken || !allowPDFDownload) {\n return {\n downloadSubmissionPdfUrl: undefined,\n downloadSubmissionPdfs: undefined,\n }\n }\n if (allowPDFDownload && !Array.isArray(allowPDFDownload)) {\n // Cater for legacy config\n const url = `${tenants.current.apiOrigin}/forms/${formSubmission.definition.id}/submissions/${data.submissionId}/pdf-document?accessToken=${data.pdfAccessToken}`\n return {\n downloadSubmissionPdfUrl: url,\n downloadSubmissionPdfs: [\n {\n id: 'default',\n configuration: allowPDFDownload,\n url,\n },\n ],\n }\n }\n\n return {\n downloadSubmissionPdfUrl: undefined,\n downloadSubmissionPdfs: allowPDFDownload.map((pdfConfiguration) => {\n const url = `${tenants.current.apiOrigin}/forms/${formSubmission.definition.id}/submissions/${data.submissionId}/pdf-document?accessToken=${data.pdfAccessToken}&configurationId=${pdfConfiguration.id}`\n return {\n ...pdfConfiguration,\n url,\n }\n }),\n }\n }\n\n const { downloadSubmissionPdfUrl, downloadSubmissionPdfs } =\n getDownloadSubmissionPdfUrls()\n\n const formSubmissionResult: FormSubmissionResult = {\n ...formSubmission,\n payment: null,\n scheduling: null,\n isOffline: false,\n isInPendingQueue: false,\n submissionTimestamp: data.submissionTimestamp,\n submissionId: data.submissionId,\n isUploadingAttachments: false,\n downloadSubmissionPdfUrl,\n downloadSubmissionPdfs,\n attachmentsAccessToken: data.attachmentsAccessToken,\n }\n\n if (schedulingSubmissionEvent && schedulingUrlConfiguration) {\n formSubmissionResult.scheduling = await handleSchedulingSubmissionEvent({\n formSubmissionResult,\n schedulingSubmissionEvent,\n schedulingUrlConfiguration,\n paymentReceiptUrl,\n paymentFormUrl,\n preventPayment: data.preventPayment,\n })\n } else if (\n paymentSubmissionEventConfiguration &&\n paymentReceiptUrl &&\n !data.preventPayment\n ) {\n formSubmissionResult.payment = await handlePaymentSubmissionEvent({\n ...paymentSubmissionEventConfiguration,\n formSubmissionResult,\n paymentReceiptUrl,\n paymentFormUrl,\n })\n }\n\n //currently cannot have drafts without a forms app\n if (formSubmission.formSubmissionDraftId && formSubmission.formsAppId) {\n await removeLocalDraftSubmission(formSubmission.formSubmissionDraftId)\n syncDrafts({\n formsAppId: formSubmission.formsAppId,\n throwError: false,\n })\n }\n if (formSubmission.preFillFormDataId) {\n await removePrefillFormData(formSubmission.preFillFormDataId)\n }\n\n return formSubmissionResult\n } catch (error: OneBlinkAppsError | unknown) {\n if (error instanceof OneBlinkAppsError) {\n if (error.isOffline) {\n if (\n !isPendingQueueEnabled ||\n schedulingSubmissionEvent ||\n paymentSubmissionEventConfiguration\n ) {\n console.warn(\n 'Offline error thrown - app or form does not support pending queue, return offline',\n error,\n )\n return Object.assign({}, formSubmission, {\n isOffline: true,\n isInPendingQueue: false,\n submissionTimestamp: null,\n submissionId: null,\n payment: null,\n scheduling: null,\n isUploadingAttachments: false,\n preventPayment: false,\n })\n }\n\n console.warn(\n 'Offline error thrown - saving submission to pending queue..',\n error,\n )\n await addFormSubmissionToPendingQueue(formSubmission)\n return Object.assign({}, formSubmission, {\n isOffline: true,\n isInPendingQueue: true,\n submissionTimestamp: null,\n submissionId: null,\n payment: null,\n scheduling: null,\n isUploadingAttachments: false,\n preventPayment: false,\n })\n }\n\n // If the error has already been handled as a\n // OneBlinkAppsError, we can throw it as is.\n throw error\n }\n\n throw new OneBlinkAppsError(\n 'An error has occurred with your submission, please contact Support if this problem persists.',\n {\n title: 'Unexpected Error',\n originalError: error as Error,\n },\n )\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"submit.js","sourceRoot":"","sources":["../../../src/apps/services/submit.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAC9C,OAAO,EACL,+BAA+B,EAC/B,4BAA4B,GAC7B,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACL,8BAA8B,EAC9B,4BAA4B,GAC7B,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAA;AAC/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAC1D,OAAO,EACL,+BAA+B,EAC/B,iCAAiC,GAClC,MAAM,sBAAsB,CAAA;AAQ7B,OAAO,EAAE,8BAA8B,EAAE,MAAM,wBAAwB,CAAA;AACvE,OAAO,OAAO,MAAM,YAAY,CAAA;AAChC,OAAO,oBAAoB,MAAM,0BAA0B,CAAA;AAC3D,OAAO,kBAAkB,MAAM,qBAAqB,CAAA;AACpD,OAAO,iBAAiB,MAAM,4BAA4B,CAAA;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAA;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,kBAAkB,E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zB,YAAY,EAAE,IAAI;wBAClB,OAAO,EAAE,IAAI;wBACb,UAAU,EAAE,IAAI;wBAChB,sBAAsB,EAAE,KAAK;wBAC7B,cAAc,EAAE,KAAK;qBACtB,CAAC,CAAA;gBACJ,CAAC;gBAED,OAAO,CAAC,IAAI,CACV,6DAA6D,EAC7D,KAAK,CACN,CAAA;gBACD,MAAM,+BAA+B,CAAC,cAAc,CAAC,CAAA;gBACrD,8BAA8B,CAAC,cAAc,CAAC,CAAA;gBAC9C,OAAO,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,cAAc,EAAE;oBACvC,SAAS,EAAE,IAAI;oBACf,gBAAgB,EAAE,IAAI;oBACtB,mBAAmB,EAAE,IAAI;oBACzB,YAAY,EAAE,IAAI;oBAClB,OAAO,EAAE,IAAI;oBACb,UAAU,EAAE,IAAI;oBAChB,sBAAsB,EAAE,KAAK;oBAC7B,cAAc,EAAE,KAAK;iBACtB,CAAC,CAAA;YACJ,CAAC;YAED,6CAA6C;YAC7C,4CAA4C;YAC5C,MAAM,KAAK,CAAA;QACb,CAAC;QAED,MAAM,IAAI,iBAAiB,CACzB,8FAA8F,EAC9F;YACE,KAAK,EAAE,kBAAkB;YACzB,aAAa,EAAE,KAAc;SAC9B,CACF,CAAA;IACH,CAAC;AACH,CAAC","sourcesContent":["import { isOffline } from '../offline-service'\nimport {\n addFormSubmissionToPendingQueue,\n deletePendingQueueSubmission,\n} from './pending-queue'\nimport {\n checkForPaymentSubmissionEvent,\n handlePaymentSubmissionEvent,\n} from '../payment-service'\nimport { removeLocalDraftSubmission } from './draft-data-store'\nimport { removePrefillFormData } from '../prefill-service'\nimport {\n handleSchedulingSubmissionEvent,\n checkForSchedulingSubmissionEvent,\n} from './schedulingHandlers'\nimport {\n FormSubmission,\n FormSubmissionResult,\n ProgressListener,\n ProgressListenerEvent,\n} from '../types/submissions'\nimport { SchedulingUrlConfiguration } from '../types/scheduling'\nimport { checkIfAttachmentsAreUploading } from '../attachments-service'\nimport tenants from '../tenants'\nimport externalIdGeneration from './external-id-generation'\nimport serverValidateForm from './server-validation'\nimport OneBlinkAppsError from './errors/oneBlinkAppsError'\nimport { uploadFormSubmission } from './api/submissions'\nimport { syncDrafts } from '../draft-service'\nimport { notifyJobSubmitted } from '../job-service'\n\nfunction notifyJobSubmittedIfApplicable(formSubmission: FormSubmission) {\n if (formSubmission.jobId) {\n notifyJobSubmitted(formSubmission.jobId)\n }\n}\n\ntype SubmissionParams = {\n formSubmission: FormSubmission\n isPendingQueueEnabled: boolean\n shouldRunServerValidation: boolean\n shouldRunExternalIdGeneration: boolean\n paymentReceiptUrl: string | undefined\n paymentFormUrl: string | undefined\n schedulingUrlConfiguration?: SchedulingUrlConfiguration\n pendingTimestamp?: string\n alwaysSubmitViaPendingQueue?: boolean\n onProgress?: ProgressListener\n abortSignal?: AbortSignal\n}\n\nexport { SubmissionParams, ProgressListener, ProgressListenerEvent }\n\nexport default async function submit({\n formSubmission,\n isPendingQueueEnabled,\n paymentReceiptUrl,\n paymentFormUrl,\n schedulingUrlConfiguration,\n onProgress,\n shouldRunServerValidation,\n shouldRunExternalIdGeneration,\n abortSignal,\n pendingTimestamp,\n alwaysSubmitViaPendingQueue,\n completionTimestamp,\n}: SubmissionParams & {\n completionTimestamp: string\n}): Promise<FormSubmissionResult> {\n const paymentSubmissionEventConfiguration =\n checkForPaymentSubmissionEvent(formSubmission)\n\n const schedulingSubmissionEvent =\n checkForSchedulingSubmissionEvent(formSubmission)\n\n try {\n if (pendingTimestamp) {\n await deletePendingQueueSubmission(pendingTimestamp)\n }\n if (isOffline() || alwaysSubmitViaPendingQueue) {\n if (paymentSubmissionEventConfiguration || schedulingSubmissionEvent) {\n console.log(\n 'Offline or always submitting via pending queue - form has a payment/scheduling submission event that has not been processed yet, return offline',\n { paymentSubmissionEventConfiguration, schedulingSubmissionEvent },\n )\n return Object.assign({}, formSubmission, {\n isOffline: true,\n isInPendingQueue: false,\n submissionTimestamp: null,\n submissionId: null,\n payment: null,\n scheduling: null,\n isUploadingAttachments: false,\n })\n }\n\n if (!alwaysSubmitViaPendingQueue && !isPendingQueueEnabled) {\n console.log(\n 'Offline - app does not support pending queue, return offline',\n )\n return Object.assign({}, formSubmission, {\n isOffline: true,\n isInPendingQueue: false,\n submissionTimestamp: null,\n submissionId: null,\n payment: null,\n scheduling: null,\n isUploadingAttachments: false,\n })\n }\n\n console.log(\n 'Offline or always submitting via pending queue - saving submission to pending queue..',\n )\n await addFormSubmissionToPendingQueue(formSubmission)\n notifyJobSubmittedIfApplicable(formSubmission)\n return Object.assign({}, formSubmission, {\n isOffline: isOffline(),\n isInPendingQueue: true,\n submissionTimestamp: null,\n submissionId: null,\n payment: null,\n preventPayment: false,\n scheduling: null,\n isUploadingAttachments: false,\n })\n }\n\n const attachmentsStillUploading = checkIfAttachmentsAreUploading(\n formSubmission.definition,\n formSubmission.submission,\n )\n\n if (attachmentsStillUploading) {\n if (paymentSubmissionEventConfiguration || schedulingSubmissionEvent) {\n console.log(\n 'Attachments still uploading - form has a payment/scheduling submission event that has not been processed yet, return isUploading',\n { paymentSubmissionEventConfiguration, schedulingSubmissionEvent },\n )\n return Object.assign({}, formSubmission, {\n isOffline: false,\n isInPendingQueue: false,\n submissionTimestamp: null,\n submissionId: null,\n payment: null,\n preventPayment: false,\n scheduling: null,\n isUploadingAttachments: true,\n })\n }\n console.log(\n 'Attachments still uploading - saving submission to pending queue..',\n )\n await addFormSubmissionToPendingQueue(formSubmission)\n notifyJobSubmittedIfApplicable(formSubmission)\n return Object.assign({}, formSubmission, {\n isOffline: false,\n isInPendingQueue: true,\n submissionTimestamp: null,\n submissionId: null,\n payment: null,\n preventPayment: false,\n scheduling: null,\n isUploadingAttachments: true,\n })\n }\n\n if (shouldRunServerValidation) {\n await serverValidateForm(formSubmission)\n }\n if (shouldRunExternalIdGeneration) {\n const externalIdResult = await externalIdGeneration(formSubmission)\n if (externalIdResult.externalId) {\n formSubmission.externalId = externalIdResult.externalId\n }\n }\n\n const data = await uploadFormSubmission(\n formSubmission,\n completionTimestamp,\n onProgress,\n abortSignal,\n )\n\n const getDownloadSubmissionPdfUrls = () => {\n const allowPDFDownload =\n formSubmission.definition.postSubmissionReceipt?.allowPDFDownload\n if (!data.pdfAccessToken || !allowPDFDownload) {\n return {\n downloadSubmissionPdfUrl: undefined,\n downloadSubmissionPdfs: undefined,\n }\n }\n if (allowPDFDownload && !Array.isArray(allowPDFDownload)) {\n // Cater for legacy config\n const url = `${tenants.current.apiOrigin}/forms/${formSubmission.definition.id}/submissions/${data.submissionId}/pdf-document?accessToken=${data.pdfAccessToken}`\n return {\n downloadSubmissionPdfUrl: url,\n downloadSubmissionPdfs: [\n {\n id: 'default',\n configuration: allowPDFDownload,\n url,\n },\n ],\n }\n }\n\n return {\n downloadSubmissionPdfUrl: undefined,\n downloadSubmissionPdfs: allowPDFDownload.map((pdfConfiguration) => {\n const url = `${tenants.current.apiOrigin}/forms/${formSubmission.definition.id}/submissions/${data.submissionId}/pdf-document?accessToken=${data.pdfAccessToken}&configurationId=${pdfConfiguration.id}`\n return {\n ...pdfConfiguration,\n url,\n }\n }),\n }\n }\n\n const { downloadSubmissionPdfUrl, downloadSubmissionPdfs } =\n getDownloadSubmissionPdfUrls()\n\n const formSubmissionResult: FormSubmissionResult = {\n ...formSubmission,\n payment: null,\n scheduling: null,\n isOffline: false,\n isInPendingQueue: false,\n submissionTimestamp: data.submissionTimestamp,\n submissionId: data.submissionId,\n isUploadingAttachments: false,\n downloadSubmissionPdfUrl,\n downloadSubmissionPdfs,\n attachmentsAccessToken: data.attachmentsAccessToken,\n }\n\n if (schedulingSubmissionEvent && schedulingUrlConfiguration) {\n formSubmissionResult.scheduling = await handleSchedulingSubmissionEvent({\n formSubmissionResult,\n schedulingSubmissionEvent,\n schedulingUrlConfiguration,\n paymentReceiptUrl,\n paymentFormUrl,\n preventPayment: data.preventPayment,\n })\n } else if (\n paymentSubmissionEventConfiguration &&\n paymentReceiptUrl &&\n !data.preventPayment\n ) {\n formSubmissionResult.payment = await handlePaymentSubmissionEvent({\n ...paymentSubmissionEventConfiguration,\n formSubmissionResult,\n paymentReceiptUrl,\n paymentFormUrl,\n })\n }\n\n //currently cannot have drafts without a forms app\n if (formSubmission.formSubmissionDraftId && formSubmission.formsAppId) {\n await removeLocalDraftSubmission(formSubmission.formSubmissionDraftId)\n syncDrafts({\n formsAppId: formSubmission.formsAppId,\n throwError: false,\n })\n }\n if (formSubmission.preFillFormDataId) {\n await removePrefillFormData(formSubmission.preFillFormDataId)\n }\n\n notifyJobSubmittedIfApplicable(formSubmission)\n\n return formSubmissionResult\n } catch (error: OneBlinkAppsError | unknown) {\n if (error instanceof OneBlinkAppsError) {\n if (error.isOffline) {\n if (\n !isPendingQueueEnabled ||\n schedulingSubmissionEvent ||\n paymentSubmissionEventConfiguration\n ) {\n console.warn(\n 'Offline error thrown - app or form does not support pending queue, return offline',\n error,\n )\n return Object.assign({}, formSubmission, {\n isOffline: true,\n isInPendingQueue: false,\n submissionTimestamp: null,\n submissionId: null,\n payment: null,\n scheduling: null,\n isUploadingAttachments: false,\n preventPayment: false,\n })\n }\n\n console.warn(\n 'Offline error thrown - saving submission to pending queue..',\n error,\n )\n await addFormSubmissionToPendingQueue(formSubmission)\n notifyJobSubmittedIfApplicable(formSubmission)\n return Object.assign({}, formSubmission, {\n isOffline: true,\n isInPendingQueue: true,\n submissionTimestamp: null,\n submissionId: null,\n payment: null,\n scheduling: null,\n isUploadingAttachments: false,\n preventPayment: false,\n })\n }\n\n // If the error has already been handled as a\n // OneBlinkAppsError, we can throw it as is.\n throw error\n }\n\n throw new OneBlinkAppsError(\n 'An error has occurred with your submission, please contact Support if this problem persists.',\n {\n title: 'Unexpected Error',\n originalError: error as Error,\n },\n )\n }\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
type Props = {
|
|
2
2
|
isEnabled: boolean;
|
|
3
3
|
isPreferred: boolean;
|
|
4
|
+
isUsedForLogin: boolean;
|
|
4
5
|
isSettingUp: boolean;
|
|
5
6
|
isSettingPreferredMfaMethod: boolean;
|
|
6
7
|
isSetupDisabled: boolean;
|
|
@@ -9,12 +10,13 @@ type Props = {
|
|
|
9
10
|
description: string;
|
|
10
11
|
detail?: string;
|
|
11
12
|
mfaRequirementMessage?: string;
|
|
12
|
-
|
|
13
|
+
mfaRequirementMessageIsWarning?: boolean;
|
|
14
|
+
cypressPrefix: 'mfa-authenticator' | 'mfa-sms';
|
|
13
15
|
extraButtons?: React.ReactNode;
|
|
14
16
|
onSetup: () => void;
|
|
15
17
|
onDisable: () => void;
|
|
16
18
|
onSetPreferred: () => void;
|
|
17
19
|
};
|
|
18
|
-
declare function MfaMethodRow({ isEnabled, isPreferred, isSettingUp, isSettingPreferredMfaMethod, isSetupDisabled, showSetupErrorTooltip, title, description, detail, mfaRequirementMessage, cypressPrefix, extraButtons, onSetup, onDisable, onSetPreferred, }: Props): import("react/jsx-runtime").JSX.Element;
|
|
20
|
+
declare function MfaMethodRow({ isEnabled, isPreferred, isUsedForLogin, isSettingUp, isSettingPreferredMfaMethod, isSetupDisabled, showSetupErrorTooltip, title, description, detail, mfaRequirementMessage, mfaRequirementMessageIsWarning, cypressPrefix, extraButtons, onSetup, onDisable, onSetPreferred, }: Props): import("react/jsx-runtime").JSX.Element;
|
|
19
21
|
declare const _default: import("react").MemoExoticComponent<typeof MfaMethodRow>;
|
|
20
22
|
export default _default;
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { memo } from 'react';
|
|
3
3
|
import { Alert, Box, Button, Chip, Grid, Tooltip, Typography, } from '@mui/material';
|
|
4
|
-
function MfaMethodRow({ isEnabled, isPreferred, isSettingUp, isSettingPreferredMfaMethod, isSetupDisabled, showSetupErrorTooltip, title, description, detail, mfaRequirementMessage, cypressPrefix, extraButtons, onSetup, onDisable, onSetPreferred, }) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
function MfaMethodRow({ isEnabled, isPreferred, isUsedForLogin, isSettingUp, isSettingPreferredMfaMethod, isSetupDisabled, showSetupErrorTooltip, title, description, detail, mfaRequirementMessage, mfaRequirementMessageIsWarning, cypressPrefix, extraButtons, onSetup, onDisable, onSetPreferred, }) {
|
|
5
|
+
const smsSetupDisabledTooltip = cypressPrefix === 'mfa-sms' && !isEnabled
|
|
6
|
+
? 'SMS MFA setup will be available in a future release. Please use Authenticator App in the meantime.'
|
|
7
|
+
: undefined;
|
|
8
|
+
return (_jsxs(Box, { "data-cypress": `${cypressPrefix}-method-row`, children: [_jsxs(Grid, { container: true, spacing: 2, alignItems: "center", children: [_jsxs(Grid, { size: { xs: 'grow' }, children: [_jsxs(Box, { sx: { mb: 1 }, children: [_jsx(Typography, { variant: "subtitle1", component: "span", children: title }), isEnabled && (_jsx(Chip, { size: "small", label: "Enabled", color: "default", sx: { ml: 1 }, "data-cypress": `${cypressPrefix}-status-chip` })), isPreferred && (_jsx(Chip, { size: "small", label: "Preferred", color: "info", sx: { ml: 1 }, "data-cypress": `${cypressPrefix}-preferred-chip` })), isUsedForLogin && (_jsx(Chip, { size: "small", label: "Used for login", color: "success", sx: { ml: 1 }, "data-cypress": `${cypressPrefix}-used-for-login-chip` }))] }), _jsx(Typography, { variant: "body2", color: "text.secondary", children: description }), !!detail && (_jsx(Typography, { variant: "body2", color: "text.secondary", sx: { mt: 1 }, children: detail }))] }), _jsx(Grid, { size: "auto", children: _jsxs(Box, { display: "flex", gap: 1, flexWrap: "wrap", justifyContent: "flex-end", children: [extraButtons, isEnabled ? (_jsxs(_Fragment, { children: [!isPreferred && (_jsx(Button, { size: "small", variant: "outlined", loading: isSettingPreferredMfaMethod, disabled: isSettingPreferredMfaMethod, onClick: onSetPreferred, "data-cypress": `${cypressPrefix}-set-preferred-button`, children: "Set as Preferred" })), _jsx(Button, { size: "small", variant: "outlined", onClick: onDisable, "data-cypress": `${cypressPrefix}-disable-button`, children: "Disable" })] })) : (_jsx(Tooltip, { title: showSetupErrorTooltip
|
|
9
|
+
? 'We are unable to load your MFA status. Please try again by clicking the reload button on the chip above.'
|
|
10
|
+
: smsSetupDisabledTooltip !== null && smsSetupDisabledTooltip !== void 0 ? smsSetupDisabledTooltip : '', children: _jsx("span", { children: _jsx(Button, { size: "small", variant: "contained", loading: isSettingUp, disabled: isSetupDisabled, onClick: onSetup, "data-cypress": `${cypressPrefix}-setup-button`, children: "Setup" }) }) }))] }) })] }), !!mfaRequirementMessage && (_jsx(Alert, { severity: mfaRequirementMessageIsWarning ? 'warning' : 'info', "data-cypress": `${cypressPrefix}-mfa-requirement-message`, children: mfaRequirementMessage }))] }));
|
|
8
11
|
}
|
|
9
12
|
export default memo(MfaMethodRow);
|
|
10
13
|
//# sourceMappingURL=MfaMethodRow.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MfaMethodRow.js","sourceRoot":"","sources":["../../../src/components/mfa/MfaMethodRow.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAC5B,OAAO,EACL,KAAK,EACL,GAAG,EACH,MAAM,EACN,IAAI,EACJ,IAAI,EACJ,OAAO,EACP,UAAU,GACX,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"MfaMethodRow.js","sourceRoot":"","sources":["../../../src/components/mfa/MfaMethodRow.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAC5B,OAAO,EACL,KAAK,EACL,GAAG,EACH,MAAM,EACN,IAAI,EACJ,IAAI,EACJ,OAAO,EACP,UAAU,GACX,MAAM,eAAe,CAAA;AAsBtB,SAAS,YAAY,CAAC,EACpB,SAAS,EACT,WAAW,EACX,cAAc,EACd,WAAW,EACX,2BAA2B,EAC3B,eAAe,EACf,qBAAqB,EACrB,KAAK,EACL,WAAW,EACX,MAAM,EACN,qBAAqB,EACrB,8BAA8B,EAC9B,aAAa,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;AACH,CAAC;AAED,eAAe,IAAI,CAAC,YAAY,CAAC,CAAA","sourcesContent":["import { memo } from 'react'\nimport {\n Alert,\n Box,\n Button,\n Chip,\n Grid,\n Tooltip,\n Typography,\n} from '@mui/material'\n\ntype Props = {\n isEnabled: boolean\n isPreferred: boolean\n isUsedForLogin: boolean\n isSettingUp: boolean\n isSettingPreferredMfaMethod: boolean\n isSetupDisabled: boolean\n showSetupErrorTooltip?: boolean\n title: string\n description: string\n detail?: string\n mfaRequirementMessage?: string\n mfaRequirementMessageIsWarning?: boolean\n cypressPrefix: 'mfa-authenticator' | 'mfa-sms'\n extraButtons?: React.ReactNode\n onSetup: () => void\n onDisable: () => void\n onSetPreferred: () => void\n}\n\nfunction MfaMethodRow({\n isEnabled,\n isPreferred,\n isUsedForLogin,\n isSettingUp,\n isSettingPreferredMfaMethod,\n isSetupDisabled,\n showSetupErrorTooltip,\n title,\n description,\n detail,\n mfaRequirementMessage,\n mfaRequirementMessageIsWarning,\n cypressPrefix,\n extraButtons,\n onSetup,\n onDisable,\n onSetPreferred,\n}: Props) {\n const smsSetupDisabledTooltip =\n cypressPrefix === 'mfa-sms' && !isEnabled\n ? 'SMS MFA setup will be available in a future release. Please use Authenticator App in the meantime.'\n : undefined\n\n return (\n <Box data-cypress={`${cypressPrefix}-method-row`}>\n <Grid container spacing={2} alignItems=\"center\">\n <Grid size={{ xs: 'grow' }}>\n <Box sx={{ mb: 1 }}>\n <Typography variant=\"subtitle1\" component=\"span\">\n {title}\n </Typography>\n {isEnabled && (\n <Chip\n size=\"small\"\n label=\"Enabled\"\n color=\"default\"\n sx={{ ml: 1 }}\n data-cypress={`${cypressPrefix}-status-chip`}\n />\n )}\n {isPreferred && (\n <Chip\n size=\"small\"\n label=\"Preferred\"\n color=\"info\"\n sx={{ ml: 1 }}\n data-cypress={`${cypressPrefix}-preferred-chip`}\n />\n )}\n {isUsedForLogin && (\n <Chip\n size=\"small\"\n label=\"Used for login\"\n color=\"success\"\n sx={{ ml: 1 }}\n data-cypress={`${cypressPrefix}-used-for-login-chip`}\n />\n )}\n </Box>\n <Typography variant=\"body2\" color=\"text.secondary\">\n {description}\n </Typography>\n {!!detail && (\n <Typography variant=\"body2\" color=\"text.secondary\" sx={{ mt: 1 }}>\n {detail}\n </Typography>\n )}\n </Grid>\n <Grid size=\"auto\">\n <Box display=\"flex\" gap={1} flexWrap=\"wrap\" justifyContent=\"flex-end\">\n {extraButtons}\n {isEnabled ? (\n <>\n {!isPreferred && (\n <Button\n size=\"small\"\n variant=\"outlined\"\n loading={isSettingPreferredMfaMethod}\n disabled={isSettingPreferredMfaMethod}\n onClick={onSetPreferred}\n data-cypress={`${cypressPrefix}-set-preferred-button`}\n >\n Set as Preferred\n </Button>\n )}\n <Button\n size=\"small\"\n variant=\"outlined\"\n onClick={onDisable}\n data-cypress={`${cypressPrefix}-disable-button`}\n >\n Disable\n </Button>\n </>\n ) : (\n <Tooltip\n title={\n showSetupErrorTooltip\n ? 'We are unable to load your MFA status. Please try again by clicking the reload button on the chip above.'\n : smsSetupDisabledTooltip ?? ''\n }\n >\n <span>\n <Button\n size=\"small\"\n variant=\"contained\"\n loading={isSettingUp}\n disabled={isSetupDisabled}\n onClick={onSetup}\n data-cypress={`${cypressPrefix}-setup-button`}\n >\n Setup\n </Button>\n </span>\n </Tooltip>\n )}\n </Box>\n </Grid>\n </Grid>\n\n {!!mfaRequirementMessage && (\n <Alert\n severity={mfaRequirementMessageIsWarning ? 'warning' : 'info'}\n data-cypress={`${cypressPrefix}-mfa-requirement-message`}\n >\n {mfaRequirementMessage}\n </Alert>\n )}\n </Box>\n )\n}\n\nexport default memo(MfaMethodRow)\n"]}
|
|
@@ -2,6 +2,7 @@ import { MiscTypes } from '@oneblink/types';
|
|
|
2
2
|
type Props = {
|
|
3
3
|
mfaRequirement: MiscTypes.MfaRequirement | undefined;
|
|
4
4
|
ssoSetupUrl?: string;
|
|
5
|
+
accessScopeLabel?: string;
|
|
5
6
|
};
|
|
6
7
|
/**
|
|
7
8
|
* React Component that provides a mechanism for app users to configure Multi
|
|
@@ -38,5 +39,5 @@ type Props = {
|
|
|
38
39
|
* @returns
|
|
39
40
|
* @group Components
|
|
40
41
|
*/
|
|
41
|
-
export default function MultiFactorAuthentication({ mfaRequirement, ssoSetupUrl, }: Props): import("react/jsx-runtime").JSX.Element;
|
|
42
|
+
export default function MultiFactorAuthentication({ mfaRequirement, ssoSetupUrl, accessScopeLabel, }: Props): import("react/jsx-runtime").JSX.Element;
|
|
42
43
|
export {};
|
|
@@ -10,8 +10,8 @@ import MfaMethodRow from './MfaMethodRow';
|
|
|
10
10
|
import MfaSuccessSnackbar from './MfaSuccessSnackbar';
|
|
11
11
|
import MfaErrorSnackbar from './MfaErrorSnackbar';
|
|
12
12
|
import MfaStatusChip from './MfaStatusChip';
|
|
13
|
-
import {
|
|
14
|
-
function MfaMethodList({ mfaRequirement }) {
|
|
13
|
+
import { formatMfaMethodRequirementMessage, isMfaMethodUsedForLogin, } from '../../utils/mfa-requirement';
|
|
14
|
+
function MfaMethodList({ mfaRequirement, accessScopeLabel = 'app', }) {
|
|
15
15
|
const { mfaSettings, loadingError, isLoading, isSettingUpMfa, settingUpMfaMethod, isSettingPreferredMfaMethod, beginMfaSetup, beginDisablingMfaMethod, setPreferredMfaMethod, beginRemovingPhoneNumber, } = useMfa();
|
|
16
16
|
const phoneDetail = useMemo(() => {
|
|
17
17
|
if (!mfaSettings.sms.phoneNumber) {
|
|
@@ -23,20 +23,21 @@ function MfaMethodList({ mfaRequirement }) {
|
|
|
23
23
|
return `Phone number: ${mfaSettings.sms.phoneNumber}`;
|
|
24
24
|
}, [mfaSettings]);
|
|
25
25
|
const authenticatorMfaRequirementMessage = useMemo(() => {
|
|
26
|
-
return
|
|
27
|
-
}, [mfaRequirement]);
|
|
26
|
+
return formatMfaMethodRequirementMessage('authenticatorApp', mfaRequirement, mfaSettings, accessScopeLabel);
|
|
27
|
+
}, [accessScopeLabel, mfaRequirement, mfaSettings]);
|
|
28
28
|
const smsMfaRequirementMessage = useMemo(() => {
|
|
29
|
-
return
|
|
30
|
-
}, [mfaRequirement]);
|
|
29
|
+
return formatMfaMethodRequirementMessage('sms', mfaRequirement, mfaSettings, accessScopeLabel);
|
|
30
|
+
}, [accessScopeLabel, mfaRequirement, mfaSettings]);
|
|
31
31
|
if (isLoading) {
|
|
32
32
|
return (_jsx(Typography, { variant: "body2", color: "text.secondary", children: "Loading MFA methods..." }));
|
|
33
33
|
}
|
|
34
34
|
if (loadingError) {
|
|
35
35
|
return (_jsx(Typography, { variant: "body2", color: "error", children: "We are unable to load your MFA methods. Please try again by clicking the reload button on the chip above." }));
|
|
36
36
|
}
|
|
37
|
-
return (_jsxs(_Fragment, { children: [_jsx(MfaMethodRow, { isEnabled: mfaSettings.authenticator.enabled, isPreferred: mfaSettings.authenticator.preferred, isSettingUp: isSettingUpMfa && settingUpMfaMethod === 'authenticator', isSettingPreferredMfaMethod: isSettingPreferredMfaMethod, isSetupDisabled: !!loadingError || isSettingUpMfa, showSetupErrorTooltip: !!loadingError, title: "Authenticator App", description: "Use an app like Google Authenticator or Microsoft Authenticator to generate 6-digit verification codes.", mfaRequirementMessage: authenticatorMfaRequirementMessage,
|
|
37
|
+
return (_jsxs(_Fragment, { children: [_jsx(MfaMethodRow, { isEnabled: mfaSettings.authenticator.enabled, isPreferred: mfaSettings.authenticator.preferred, isUsedForLogin: isMfaMethodUsedForLogin(mfaSettings, 'authenticatorApp'), isSettingUp: isSettingUpMfa && settingUpMfaMethod === 'authenticator', isSettingPreferredMfaMethod: isSettingPreferredMfaMethod, isSetupDisabled: !!loadingError || isSettingUpMfa, showSetupErrorTooltip: !!loadingError, title: "Authenticator App", description: "Use an app like Google Authenticator or Microsoft Authenticator to generate 6-digit verification codes.", mfaRequirementMessage: authenticatorMfaRequirementMessage, mfaRequirementMessageIsWarning: !!(mfaRequirement === null || mfaRequirement === void 0 ? void 0 : mfaRequirement.authenticatorApp) &&
|
|
38
|
+
!!authenticatorMfaRequirementMessage, cypressPrefix: "mfa-authenticator", onSetup: () => beginMfaSetup('authenticator'), onDisable: () => beginDisablingMfaMethod('authenticator'), onSetPreferred: () => setPreferredMfaMethod('authenticator') }), _jsx(Divider, { sx: { my: 2 } }), _jsx(MfaMethodRow, { isEnabled: mfaSettings.sms.enabled, isPreferred: mfaSettings.sms.preferred, isUsedForLogin: isMfaMethodUsedForLogin(mfaSettings, 'sms'), isSettingUp: isSettingUpMfa && settingUpMfaMethod === 'sms', isSettingPreferredMfaMethod: isSettingPreferredMfaMethod, isSetupDisabled: !!loadingError || isSettingUpMfa || !mfaSettings.sms.enabled, showSetupErrorTooltip: !!loadingError, title: "SMS", description: "Receive a one-time verification code via SMS each time MFA is required.", detail: phoneDetail, mfaRequirementMessage: smsMfaRequirementMessage, mfaRequirementMessageIsWarning: !!(mfaRequirement === null || mfaRequirement === void 0 ? void 0 : mfaRequirement.sms) && !!smsMfaRequirementMessage, cypressPrefix: "mfa-sms", onSetup: () => beginMfaSetup('sms'), onDisable: () => beginDisablingMfaMethod('sms'), onSetPreferred: () => setPreferredMfaMethod('sms'), extraButtons: !!mfaSettings.sms.phoneNumber && !mfaSettings.sms.enabled ? (_jsx(Button, { size: "small", variant: "outlined", disabled: !!loadingError, onClick: beginRemovingPhoneNumber, "data-cypress": "mfa-sms-remove-phone-button", children: "Remove Phone" })) : undefined })] }));
|
|
38
39
|
}
|
|
39
|
-
function MfaSetup({ ssoSetupUrl, mfaRequirement }) {
|
|
40
|
+
function MfaSetup({ ssoSetupUrl, mfaRequirement, accessScopeLabel }) {
|
|
40
41
|
const { isExternalIdentityProviderUser } = useMfa();
|
|
41
42
|
if (ssoSetupUrl) {
|
|
42
43
|
return (_jsx(Button, { variant: "outlined", size: "small", component: "a", href: ssoSetupUrl, target: "_blank", rel: "noopener noreferrer", "data-cypress": "configure-mfa-button", children: "Configure MFA" }));
|
|
@@ -44,7 +45,7 @@ function MfaSetup({ ssoSetupUrl, mfaRequirement }) {
|
|
|
44
45
|
if (isExternalIdentityProviderUser) {
|
|
45
46
|
return (_jsx(Tooltip, { title: "MFA must be configured in your login provider.", children: _jsx("span", { children: _jsx(Button, { variant: "outlined", disabled: isExternalIdentityProviderUser, "data-cypress": "configure-mfa-button", children: "Configure MFA" }) }) }));
|
|
46
47
|
}
|
|
47
|
-
return (_jsxs(_Fragment, { children: [_jsx(MfaMethodList, { mfaRequirement: mfaRequirement }), _jsx(MfaDisableDialog, {}), _jsx(MfaRemovePhoneNumberDialog, {}), _jsx(MfaPhoneNumberDialog, {}), _jsx(MfaAuthenticatorAppDialog, {}), _jsx(MfaErrorSnackbar, {}), _jsx(MfaSuccessSnackbar, {})] }));
|
|
48
|
+
return (_jsxs(_Fragment, { children: [_jsx(MfaMethodList, { mfaRequirement: mfaRequirement, accessScopeLabel: accessScopeLabel }), _jsx(MfaDisableDialog, {}), _jsx(MfaRemovePhoneNumberDialog, {}), _jsx(MfaPhoneNumberDialog, {}), _jsx(MfaAuthenticatorAppDialog, {}), _jsx(MfaErrorSnackbar, {}), _jsx(MfaSuccessSnackbar, {})] }));
|
|
48
49
|
}
|
|
49
50
|
/**
|
|
50
51
|
* React Component that provides a mechanism for app users to configure Multi
|
|
@@ -81,7 +82,7 @@ function MfaSetup({ ssoSetupUrl, mfaRequirement }) {
|
|
|
81
82
|
* @returns
|
|
82
83
|
* @group Components
|
|
83
84
|
*/
|
|
84
|
-
export default function MultiFactorAuthentication({ mfaRequirement, ssoSetupUrl, }) {
|
|
85
|
-
return (_jsx(Grid, { size: { xs: 'grow', lg: 8 }, children: _jsx(Box, { padding: 3, children: _jsx(Paper, { children: _jsx(Box, { padding: 3, children: _jsx(Grid, { container: true, spacing: 2, alignItems: "center", children: _jsxs(Grid, { size: { xs: 'grow' }, children: [_jsxs(Typography, { variant: "h4", fontWeight: "light", children: ["Multi Factor Authentication
|
|
85
|
+
export default function MultiFactorAuthentication({ mfaRequirement, ssoSetupUrl, accessScopeLabel = 'App', }) {
|
|
86
|
+
return (_jsx(Grid, { size: { xs: 'grow', lg: 8 }, children: _jsx(Box, { padding: 3, children: _jsx(Paper, { children: _jsx(Box, { padding: 3, children: _jsx(Grid, { container: true, spacing: 2, alignItems: "center", children: _jsxs(Grid, { size: { xs: 'grow' }, children: [_jsxs(Typography, { variant: "h4", fontWeight: "light", children: ["Multi Factor Authentication", ' ', _jsx(MfaStatusChip, {})] }), _jsx(Box, { marginY: 1, children: _jsx(Divider, {}) }), _jsx(Typography, { variant: "body2", paragraph: true, children: "Multi factor authentication (MFA), also known as two factor authentication (2FA), is a best practice that requires a second authentication factor in addition to user name and password sign-in credentials. We strongly recommend enabling MFA to enhance your account security." }), _jsx(MfaSetup, { ssoSetupUrl: ssoSetupUrl, mfaRequirement: mfaRequirement, accessScopeLabel: accessScopeLabel })] }) }) }) }) }) }));
|
|
86
87
|
}
|
|
87
88
|
//# sourceMappingURL=MultiFactorAuthentication.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MultiFactorAuthentication.js","sourceRoot":"","sources":["../../../src/components/mfa/MultiFactorAuthentication.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC/B,OAAO,EACL,GAAG,EACH,MAAM,EACN,OAAO,EACP,IAAI,EACJ,KAAK,EACL,OAAO,EACP,UAAU,GACX,MAAM,eAAe,CAAA;AAEtB,OAAO,yBAAyB,MAAM,6BAA6B,CAAA;AACnE,OAAO,MAAM,MAAM,oBAAoB,CAAA;AACvC,OAAO,gBAAgB,MAAM,oBAAoB,CAAA;AACjD,OAAO,0BAA0B,MAAM,8BAA8B,CAAA;AACrE,OAAO,oBAAoB,MAAM,wBAAwB,CAAA;AACzD,OAAO,YAAY,MAAM,gBAAgB,CAAA;AACzC,OAAO,kBAAkB,MAAM,sBAAsB,CAAA;AACrD,OAAO,gBAAgB,MAAM,oBAAoB,CAAA;AACjD,OAAO,aAAa,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,iCAAiC,E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;;;;;;;;;;GAkCG;AACH,MAAM,CAAC,OAAO,UAAU,yBAAyB,CAAC,EAChD,cAAc,EACd,WAAW,GACL;IACN,OAAO,CACL,KAAC,IAAI,IAAC,IAAI,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,EAAE,YAC/B,KAAC,GAAG,IAAC,OAAO,EAAE,CAAC,YACb,KAAC,KAAK,cACJ,KAAC,GAAG,IAAC,OAAO,EAAE,CAAC,YACb,KAAC,IAAI,IAAC,SAAS,QAAC,OAAO,EAAE,CAAC,EAAE,UAAU,EAAC,QAAQ,YAC7C,MAAC,IAAI,IAAC,IAAI,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,aACxB,MAAC,UAAU,IAAC,OAAO,EAAC,IAAI,EAAC,UAAU,EAAC,OAAO,6CACb,KAAC,aAAa,KAAG,IAClC,EACb,KAAC,GAAG,IAAC,OAAO,EAAE,CAAC,YACb,KAAC,OAAO,KAAG,GACP,EACN,KAAC,UAAU,IAAC,OAAO,EAAC,OAAO,EAAC,SAAS,wSAMxB,EACb,KAAC,QAAQ,IACP,WAAW,EAAE,WAAW,EACxB,cAAc,EAAE,cAAc,GAC9B,IACG,GACF,GACH,GACA,GACJ,GACD,CACR,CAAA;AACH,CAAC","sourcesContent":["import { useMemo } from 'react'\nimport {\n Box,\n Button,\n Divider,\n Grid,\n Paper,\n Tooltip,\n Typography,\n} from '@mui/material'\nimport { MiscTypes } from '@oneblink/types'\nimport MfaAuthenticatorAppDialog from './MfaAuthenticatorAppDialog'\nimport useMfa from '../../hooks/useMfa'\nimport MfaDisableDialog from './MfaDisableDialog'\nimport MfaRemovePhoneNumberDialog from './MfaRemovePhoneNumberDialog'\nimport MfaPhoneNumberDialog from './MfaPhoneNumberDialog'\nimport MfaMethodRow from './MfaMethodRow'\nimport MfaSuccessSnackbar from './MfaSuccessSnackbar'\nimport MfaErrorSnackbar from './MfaErrorSnackbar'\nimport MfaStatusChip from './MfaStatusChip'\nimport { formatMfaMethodNotAcceptedMessage } from '../../utils/mfa-requirement'\n\ntype Props = {\n mfaRequirement: MiscTypes.MfaRequirement | undefined\n ssoSetupUrl?: string\n}\n\nfunction MfaMethodList({ mfaRequirement }: Pick<Props, 'mfaRequirement'>) {\n const {\n mfaSettings,\n loadingError,\n isLoading,\n isSettingUpMfa,\n settingUpMfaMethod,\n isSettingPreferredMfaMethod,\n beginMfaSetup,\n beginDisablingMfaMethod,\n setPreferredMfaMethod,\n beginRemovingPhoneNumber,\n } = useMfa()\n\n const phoneDetail = useMemo(() => {\n if (!mfaSettings.sms.phoneNumber) {\n return undefined\n }\n\n if (!mfaSettings.sms.isPhoneNumberVerified) {\n return `Phone number: ${mfaSettings.sms.phoneNumber} (not verified)`\n }\n\n return `Phone number: ${mfaSettings.sms.phoneNumber}`\n }, [mfaSettings])\n\n const authenticatorMfaRequirementMessage = useMemo(() => {\n return formatMfaMethodNotAcceptedMessage('authenticatorApp', mfaRequirement)\n }, [mfaRequirement])\n\n const smsMfaRequirementMessage = useMemo(() => {\n return formatMfaMethodNotAcceptedMessage('sms', mfaRequirement)\n }, [mfaRequirement])\n\n if (isLoading) {\n return (\n <Typography variant=\"body2\" color=\"text.secondary\">\n Loading MFA methods...\n </Typography>\n )\n }\n\n if (loadingError) {\n return (\n <Typography variant=\"body2\" color=\"error\">\n We are unable to load your MFA methods. Please try again by clicking the\n reload button on the chip above.\n </Typography>\n )\n }\n\n return (\n <>\n <MfaMethodRow\n isEnabled={mfaSettings.authenticator.enabled}\n isPreferred={mfaSettings.authenticator.preferred}\n isSettingUp={isSettingUpMfa && settingUpMfaMethod === 'authenticator'}\n isSettingPreferredMfaMethod={isSettingPreferredMfaMethod}\n isSetupDisabled={!!loadingError || isSettingUpMfa}\n showSetupErrorTooltip={!!loadingError}\n title=\"Authenticator App\"\n description=\"Use an app like Google Authenticator or Microsoft Authenticator to generate 6-digit verification codes.\"\n mfaRequirementMessage={authenticatorMfaRequirementMessage}\n cypressPrefix=\"mfa-authenticator\"\n onSetup={() => beginMfaSetup('authenticator')}\n onDisable={() => beginDisablingMfaMethod('authenticator')}\n onSetPreferred={() => setPreferredMfaMethod('authenticator')}\n />\n <Divider sx={{ my: 2 }} />\n <MfaMethodRow\n isEnabled={mfaSettings.sms.enabled}\n isPreferred={mfaSettings.sms.preferred}\n isSettingUp={isSettingUpMfa && settingUpMfaMethod === 'sms'}\n isSettingPreferredMfaMethod={isSettingPreferredMfaMethod}\n isSetupDisabled={!!loadingError || isSettingUpMfa}\n showSetupErrorTooltip={!!loadingError}\n title=\"SMS\"\n description=\"Receive a one-time verification code via SMS each time MFA is required.\"\n detail={phoneDetail}\n mfaRequirementMessage={smsMfaRequirementMessage}\n cypressPrefix=\"mfa-sms\"\n onSetup={() => beginMfaSetup('sms')}\n onDisable={() => beginDisablingMfaMethod('sms')}\n onSetPreferred={() => setPreferredMfaMethod('sms')}\n extraButtons={\n !!mfaSettings.sms.phoneNumber && !mfaSettings.sms.enabled ? (\n <Button\n size=\"small\"\n variant=\"outlined\"\n disabled={!!loadingError}\n onClick={beginRemovingPhoneNumber}\n data-cypress=\"mfa-sms-remove-phone-button\"\n >\n Remove Phone\n </Button>\n ) : undefined\n }\n />\n </>\n )\n}\n\nfunction MfaSetup({ ssoSetupUrl, mfaRequirement }: Props) {\n const { isExternalIdentityProviderUser } = useMfa()\n\n if (ssoSetupUrl) {\n return (\n <Button\n variant=\"outlined\"\n size=\"small\"\n component=\"a\"\n href={ssoSetupUrl}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n data-cypress=\"configure-mfa-button\"\n >\n Configure MFA\n </Button>\n )\n }\n\n if (isExternalIdentityProviderUser) {\n return (\n <Tooltip title=\"MFA must be configured in your login provider.\">\n <span>\n <Button\n variant=\"outlined\"\n disabled={isExternalIdentityProviderUser}\n data-cypress=\"configure-mfa-button\"\n >\n Configure MFA\n </Button>\n </span>\n </Tooltip>\n )\n }\n\n return (\n <>\n <MfaMethodList mfaRequirement={mfaRequirement} />\n <MfaDisableDialog />\n <MfaRemovePhoneNumberDialog />\n <MfaPhoneNumberDialog />\n <MfaAuthenticatorAppDialog />\n <MfaErrorSnackbar />\n <MfaSuccessSnackbar />\n </>\n )\n}\n\n/**\n * React Component that provides a mechanism for app users to configure Multi\n * Factor Authentication. `<MfaProvider />` must be provided above this\n * component in the component tree.\n *\n * #### Example\n *\n * ```js\n * import * as React from 'react'\n * import {\n * MfaProvider,\n * MultiFactorAuthentication,\n * } from '@oneblink/apps-react'\n *\n * function Component() {\n * return <MultiFactorAuthentication mfaRequirement={undefined} />\n * }\n *\n * function AppWithMfaRequirement({ mfaRequirement }) {\n * return (\n * <MfaProvider>\n * <MultiFactorAuthentication mfaRequirement={mfaRequirement} />\n * </MfaProvider>\n * )\n * }\n * ```\n *\n * @param props\n * @param props.mfaRequirement - The MFA methods allowed by your administrator\n * for using this app. Pass `undefined` when the app has no MFA requirement.\n * Users can still enable other methods, but will be warned when their\n * configuration does not meet this requirement.\n * @returns\n * @group Components\n */\nexport default function MultiFactorAuthentication({\n mfaRequirement,\n ssoSetupUrl,\n}: Props) {\n return (\n <Grid size={{ xs: 'grow', lg: 8 }}>\n <Box padding={3}>\n <Paper>\n <Box padding={3}>\n <Grid container spacing={2} alignItems=\"center\">\n <Grid size={{ xs: 'grow' }}>\n <Typography variant=\"h4\" fontWeight=\"light\">\n Multi Factor Authentication <MfaStatusChip />\n </Typography>\n <Box marginY={1}>\n <Divider />\n </Box>\n <Typography variant=\"body2\" paragraph>\n Multi factor authentication (MFA), also known as two factor\n authentication (2FA), is a best practice that requires a\n second authentication factor in addition to user name and\n password sign-in credentials. We strongly recommend enabling\n MFA to enhance your account security.\n </Typography>\n <MfaSetup\n ssoSetupUrl={ssoSetupUrl}\n mfaRequirement={mfaRequirement}\n />\n </Grid>\n </Grid>\n </Box>\n </Paper>\n </Box>\n </Grid>\n )\n}\n"]}
|
|
1
|
+
{"version":3,"file":"MultiFactorAuthentication.js","sourceRoot":"","sources":["../../../src/components/mfa/Multi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,WAAW,EACX,gBAAgB,GAAG,KAAK,GAClB;IACN,OAAO,CACL,KAAC,IAAI,IAAC,IAAI,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,EAAE,YAC/B,KAAC,GAAG,IAAC,OAAO,EAAE,CAAC,YACb,KAAC,KAAK,cACJ,KAAC,GAAG,IAAC,OAAO,EAAE,CAAC,YACb,KAAC,IAAI,IAAC,SAAS,QAAC,OAAO,EAAE,CAAC,EAAE,UAAU,EAAC,QAAQ,YAC7C,MAAC,IAAI,IAAC,IAAI,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,aACxB,MAAC,UAAU,IAAC,OAAO,EAAC,IAAI,EAAC,UAAU,EAAC,OAAO,4CACb,GAAG,EAC/B,KAAC,aAAa,KAAG,IACN,EACb,KAAC,GAAG,IAAC,OAAO,EAAE,CAAC,YACb,KAAC,OAAO,KAAG,GACP,EACN,KAAC,UAAU,IAAC,OAAO,EAAC,OAAO,EAAC,SAAS,wSAMxB,EACb,KAAC,QAAQ,IACP,WAAW,EAAE,WAAW,EACxB,cAAc,EAAE,cAAc,EAC9B,gBAAgB,EAAE,gBAAgB,GAClC,IACG,GACF,GACH,GACA,GACJ,GACD,CACR,CAAA;AACH,CAAC","sourcesContent":["import { useMemo } from 'react'\nimport {\n Box,\n Button,\n Divider,\n Grid,\n Paper,\n Tooltip,\n Typography,\n} from '@mui/material'\nimport { MiscTypes } from '@oneblink/types'\nimport MfaAuthenticatorAppDialog from './MfaAuthenticatorAppDialog'\nimport useMfa from '../../hooks/useMfa'\nimport MfaDisableDialog from './MfaDisableDialog'\nimport MfaRemovePhoneNumberDialog from './MfaRemovePhoneNumberDialog'\nimport MfaPhoneNumberDialog from './MfaPhoneNumberDialog'\nimport MfaMethodRow from './MfaMethodRow'\nimport MfaSuccessSnackbar from './MfaSuccessSnackbar'\nimport MfaErrorSnackbar from './MfaErrorSnackbar'\nimport MfaStatusChip from './MfaStatusChip'\nimport {\n formatMfaMethodRequirementMessage,\n isMfaMethodUsedForLogin,\n} from '../../utils/mfa-requirement'\n\ntype Props = {\n mfaRequirement: MiscTypes.MfaRequirement | undefined\n ssoSetupUrl?: string\n accessScopeLabel?: string\n}\n\nfunction MfaMethodList({\n mfaRequirement,\n accessScopeLabel = 'app',\n}: Pick<Props, 'mfaRequirement' | 'accessScopeLabel'>) {\n const {\n mfaSettings,\n loadingError,\n isLoading,\n isSettingUpMfa,\n settingUpMfaMethod,\n isSettingPreferredMfaMethod,\n beginMfaSetup,\n beginDisablingMfaMethod,\n setPreferredMfaMethod,\n beginRemovingPhoneNumber,\n } = useMfa()\n\n const phoneDetail = useMemo(() => {\n if (!mfaSettings.sms.phoneNumber) {\n return undefined\n }\n\n if (!mfaSettings.sms.isPhoneNumberVerified) {\n return `Phone number: ${mfaSettings.sms.phoneNumber} (not verified)`\n }\n\n return `Phone number: ${mfaSettings.sms.phoneNumber}`\n }, [mfaSettings])\n\n const authenticatorMfaRequirementMessage = useMemo(() => {\n return formatMfaMethodRequirementMessage(\n 'authenticatorApp',\n mfaRequirement,\n mfaSettings,\n accessScopeLabel,\n )\n }, [accessScopeLabel, mfaRequirement, mfaSettings])\n\n const smsMfaRequirementMessage = useMemo(() => {\n return formatMfaMethodRequirementMessage(\n 'sms',\n mfaRequirement,\n mfaSettings,\n accessScopeLabel,\n )\n }, [accessScopeLabel, mfaRequirement, mfaSettings])\n\n if (isLoading) {\n return (\n <Typography variant=\"body2\" color=\"text.secondary\">\n Loading MFA methods...\n </Typography>\n )\n }\n\n if (loadingError) {\n return (\n <Typography variant=\"body2\" color=\"error\">\n We are unable to load your MFA methods. Please try again by clicking the\n reload button on the chip above.\n </Typography>\n )\n }\n\n return (\n <>\n <MfaMethodRow\n isEnabled={mfaSettings.authenticator.enabled}\n isPreferred={mfaSettings.authenticator.preferred}\n isUsedForLogin={isMfaMethodUsedForLogin(\n mfaSettings,\n 'authenticatorApp',\n )}\n isSettingUp={isSettingUpMfa && settingUpMfaMethod === 'authenticator'}\n isSettingPreferredMfaMethod={isSettingPreferredMfaMethod}\n isSetupDisabled={!!loadingError || isSettingUpMfa}\n showSetupErrorTooltip={!!loadingError}\n title=\"Authenticator App\"\n description=\"Use an app like Google Authenticator or Microsoft Authenticator to generate 6-digit verification codes.\"\n mfaRequirementMessage={authenticatorMfaRequirementMessage}\n mfaRequirementMessageIsWarning={\n !!mfaRequirement?.authenticatorApp &&\n !!authenticatorMfaRequirementMessage\n }\n cypressPrefix=\"mfa-authenticator\"\n onSetup={() => beginMfaSetup('authenticator')}\n onDisable={() => beginDisablingMfaMethod('authenticator')}\n onSetPreferred={() => setPreferredMfaMethod('authenticator')}\n />\n <Divider sx={{ my: 2 }} />\n <MfaMethodRow\n isEnabled={mfaSettings.sms.enabled}\n isPreferred={mfaSettings.sms.preferred}\n isUsedForLogin={isMfaMethodUsedForLogin(mfaSettings, 'sms')}\n isSettingUp={isSettingUpMfa && settingUpMfaMethod === 'sms'}\n isSettingPreferredMfaMethod={isSettingPreferredMfaMethod}\n isSetupDisabled={!!loadingError || isSettingUpMfa || !mfaSettings.sms.enabled}\n showSetupErrorTooltip={!!loadingError}\n title=\"SMS\"\n description=\"Receive a one-time verification code via SMS each time MFA is required.\"\n detail={phoneDetail}\n mfaRequirementMessage={smsMfaRequirementMessage}\n mfaRequirementMessageIsWarning={\n !!mfaRequirement?.sms && !!smsMfaRequirementMessage\n }\n cypressPrefix=\"mfa-sms\"\n onSetup={() => beginMfaSetup('sms')}\n onDisable={() => beginDisablingMfaMethod('sms')}\n onSetPreferred={() => setPreferredMfaMethod('sms')}\n extraButtons={\n !!mfaSettings.sms.phoneNumber && !mfaSettings.sms.enabled ? (\n <Button\n size=\"small\"\n variant=\"outlined\"\n disabled={!!loadingError}\n onClick={beginRemovingPhoneNumber}\n data-cypress=\"mfa-sms-remove-phone-button\"\n >\n Remove Phone\n </Button>\n ) : undefined\n }\n />\n </>\n )\n}\n\nfunction MfaSetup({ ssoSetupUrl, mfaRequirement, accessScopeLabel }: Props) {\n const { isExternalIdentityProviderUser } = useMfa()\n\n if (ssoSetupUrl) {\n return (\n <Button\n variant=\"outlined\"\n size=\"small\"\n component=\"a\"\n href={ssoSetupUrl}\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n data-cypress=\"configure-mfa-button\"\n >\n Configure MFA\n </Button>\n )\n }\n\n if (isExternalIdentityProviderUser) {\n return (\n <Tooltip title=\"MFA must be configured in your login provider.\">\n <span>\n <Button\n variant=\"outlined\"\n disabled={isExternalIdentityProviderUser}\n data-cypress=\"configure-mfa-button\"\n >\n Configure MFA\n </Button>\n </span>\n </Tooltip>\n )\n }\n\n return (\n <>\n <MfaMethodList\n mfaRequirement={mfaRequirement}\n accessScopeLabel={accessScopeLabel}\n />\n <MfaDisableDialog />\n <MfaRemovePhoneNumberDialog />\n <MfaPhoneNumberDialog />\n <MfaAuthenticatorAppDialog />\n <MfaErrorSnackbar />\n <MfaSuccessSnackbar />\n </>\n )\n}\n\n/**\n * React Component that provides a mechanism for app users to configure Multi\n * Factor Authentication. `<MfaProvider />` must be provided above this\n * component in the component tree.\n *\n * #### Example\n *\n * ```js\n * import * as React from 'react'\n * import {\n * MfaProvider,\n * MultiFactorAuthentication,\n * } from '@oneblink/apps-react'\n *\n * function Component() {\n * return <MultiFactorAuthentication mfaRequirement={undefined} />\n * }\n *\n * function AppWithMfaRequirement({ mfaRequirement }) {\n * return (\n * <MfaProvider>\n * <MultiFactorAuthentication mfaRequirement={mfaRequirement} />\n * </MfaProvider>\n * )\n * }\n * ```\n *\n * @param props\n * @param props.mfaRequirement - The MFA methods allowed by your administrator\n * for using this app. Pass `undefined` when the app has no MFA requirement.\n * Users can still enable other methods, but will be warned when their\n * configuration does not meet this requirement.\n * @returns\n * @group Components\n */\nexport default function MultiFactorAuthentication({\n mfaRequirement,\n ssoSetupUrl,\n accessScopeLabel = 'App',\n}: Props) {\n return (\n <Grid size={{ xs: 'grow', lg: 8 }}>\n <Box padding={3}>\n <Paper>\n <Box padding={3}>\n <Grid container spacing={2} alignItems=\"center\">\n <Grid size={{ xs: 'grow' }}>\n <Typography variant=\"h4\" fontWeight=\"light\">\n Multi Factor Authentication{' '}\n <MfaStatusChip />\n </Typography>\n <Box marginY={1}>\n <Divider />\n </Box>\n <Typography variant=\"body2\" paragraph>\n Multi factor authentication (MFA), also known as two factor\n authentication (2FA), is a best practice that requires a\n second authentication factor in addition to user name and\n password sign-in credentials. We strongly recommend enabling\n MFA to enhance your account security.\n </Typography>\n <MfaSetup\n ssoSetupUrl={ssoSetupUrl}\n mfaRequirement={mfaRequirement}\n accessScopeLabel={accessScopeLabel}\n />\n </Grid>\n </Grid>\n </Box>\n </Paper>\n </Box>\n </Grid>\n )\n}\n"]}
|
package/dist/styles.css
CHANGED
|
@@ -10360,3 +10360,8 @@ textarea:disabled {
|
|
|
10360
10360
|
.ob-downloadable-files__error-pdf {
|
|
10361
10361
|
padding-bottom: 1.5rem;
|
|
10362
10362
|
}
|
|
10363
|
+
|
|
10364
|
+
.ob-figure__barcode-scanner {
|
|
10365
|
+
width: 300px;
|
|
10366
|
+
margin: auto;
|
|
10367
|
+
}
|
package/dist/styles.scss
CHANGED
|
@@ -148,3 +148,4 @@ $section-padding-mobile: $section-padding-mobile-y $section-padding-mobile-x;
|
|
|
148
148
|
@import './styles/nsw-point-address.scss';
|
|
149
149
|
@import './styles/nsw-point-cadastral-parcel.scss';
|
|
150
150
|
@import './styles/downloadable-files.scss';
|
|
151
|
+
@import './styles/barcode-scanner.scss';
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { MiscTypes } from '@oneblink/types';
|
|
2
|
-
import type { MfaSettings } from '../apps/services/AWSCognitoClient';
|
|
3
|
-
export type { MfaSettings };
|
|
2
|
+
import type { LoggedInMfaMethod, MfaSettings } from '../apps/services/AWSCognitoClient';
|
|
3
|
+
export type { LoggedInMfaMethod, MfaSettings };
|
|
4
4
|
export declare function isMfaRequired(mfaRequirement: MiscTypes.MfaRequirement | undefined): boolean;
|
|
5
5
|
export type MfaRequirementMethod = keyof MiscTypes.MfaRequirement;
|
|
6
6
|
export declare function mfaRequirementToSelectedMethods(mfaRequirement: MiscTypes.MfaRequirement | undefined): MfaRequirementMethod[];
|
|
7
7
|
export declare function mfaSelectedMethodsToMfaRequirement(methods: MfaRequirementMethod[]): MiscTypes.MfaRequirement;
|
|
8
8
|
export declare function formatMfaRequirementLabel(mfaRequirement: MiscTypes.MfaRequirement | undefined): string;
|
|
9
|
-
export declare function
|
|
9
|
+
export declare function isMfaMethodUsedForLogin(mfaSettings: MfaSettings, method: MfaRequirementMethod): boolean;
|
|
10
10
|
export declare function userMeetsMfaRequirement(mfaRequirement: MiscTypes.MfaRequirement | undefined, mfaSettings: MfaSettings): boolean;
|
|
11
|
-
export declare function formatMfaMethodNotAcceptedMessage(method: MfaRequirementMethod, mfaRequirement: MiscTypes.MfaRequirement | undefined, accessScopeLabel?: string): string | undefined;
|
|
12
11
|
export declare function formatMfaSetupRequiredMessage(mfaRequirement: MiscTypes.MfaRequirement | undefined, mfaSettings: MfaSettings, accessScopeLabel?: string): string | undefined;
|
|
12
|
+
export declare function formatMfaMethodRequirementMessage(method: MfaRequirementMethod, mfaRequirement: MiscTypes.MfaRequirement | undefined, mfaSettings: MfaSettings, accessScopeLabel?: string): string | undefined;
|