Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
SKY-15170: Show every rotated credential's 2FA identifier (#8322)
Aaron Perez3a9d0af7b1ce
diff --git a/skyvern-frontend/src/routes/workflows/editor/hooks/useSelectedCredentialTotpIdentifier.test.tsx b/skyvern-frontend/src/routes/workflows/editor/hooks/useSelectedCredentialTotpIdentifier.test.tsxindex 8658d87f8..5e5866f3c 100644--- a/skyvern-frontend/src/routes/workflows/editor/hooks/useSelectedCredentialTotpIdentifier.test.tsx+++ b/skyvern-frontend/src/routes/workflows/editor/hooks/useSelectedCredentialTotpIdentifier.test.tsx@@ -37,6 +37,16 @@ const PASSWORD_CRED_NO_TOTP = {credential: { username: "bob", password: "*", totp_identifier: null },};+const PASSWORD_CRED_ROTATED = {+ credential_id: "cred-3",+ credential_type: "password" as const,+ credential: {+ username: "carol",+ password: "*",+ totp_identifier: "[email protected]",+ },+};+beforeEach(() => {credentialsQuery.data = [];credentialQuery.data = undefined;@@ -120,6 +130,45 @@ describe("useSelectedCredentialTotpIdentifier", () => {expect(result.current).toBeNull();});+ test("reflects every rotated credential's totp_identifier, not just the first", () => {+ credentialsQuery.data = [PASSWORD_CRED, PASSWORD_CRED_ROTATED];+ useWorkflowParametersStore.setState({+ parameters: [+ {+ key: "my_cred",+ parameterType: "credential",+ credentialId: "cred-1",+ credentialIds: ["cred-1", "cred-3"],+ },+ ],+ });+ const { result } = renderHook(() =>+ useSelectedCredentialTotpIdentifier("my_cred"),+ );+ expect(result.current).toBe("[email protected], [email protected]");+ });++ test("de-dupes identical totp_identifiers shared across rotated credentials", () => {+ credentialsQuery.data = [+ PASSWORD_CRED,+ { ...PASSWORD_CRED_ROTATED, credential: PASSWORD_CRED.credential },+ ];+ useWorkflowParametersStore.setState({+ parameters: [+ {+ key: "my_cred",+ parameterType: "credential",+ credentialId: "cred-1",+ credentialIds: ["cred-1", "cred-3"],+ },+ ],+ });+ const { result } = renderHook(() =>+ useSelectedCredentialTotpIdentifier("my_cred"),+ );+ expect(result.current).toBe("[email protected]");+ });+test("resolves the identifier from the detail query when the first page omits the credential", () => {credentialQuery.data = PASSWORD_CRED;useWorkflowParametersStore.setState({diff --git a/skyvern-frontend/src/routes/workflows/editor/hooks/useSelectedCredentialTotpIdentifier.ts b/skyvern-frontend/src/routes/workflows/editor/hooks/useSelectedCredentialTotpIdentifier.tsindex fb4ff9946..3b050d5dd 100644--- a/skyvern-frontend/src/routes/workflows/editor/hooks/useSelectedCredentialTotpIdentifier.ts+++ b/skyvern-frontend/src/routes/workflows/editor/hooks/useSelectedCredentialTotpIdentifier.ts@@ -6,11 +6,13 @@ import { useWorkflowParametersStore } from "@/store/WorkflowParametersStore";import { parameterIsSkyvernCredential } from "../types";/**- * Resolves the totp_identifier stored on the credential a block currently- * references (by parameter key). Returns null when no Skyvern credential is- * selected or the credential has no stored totp_identifier. Used only to render- * helper text — the runtime fallback to the credential's value lives in the- * backend, so the value is never written into the block.+ * Resolves the totp_identifier(s) stored on the credential(s) a block+ * currently references (by parameter key). When the parameter is a rotating+ * Skyvern credential (2+ credentialIds), returns every distinct identifier+ * found, comma-joined. Returns null when no Skyvern credential is selected or+ * none of the resolved credentials have a stored totp_identifier. Used only to+ * render helper text — the runtime fallback to the credential's value lives in+ * the backend, so the value is never written into the block.** Callers pass the first credential parameter key on the block; blocks carry at* most one credential parameter in practice, so subsequent keys are ignored.@@ -26,16 +28,19 @@ export function useSelectedCredentialTotpIdentifier(page_size: 100,});- const credentialId = useMemo(() => {+ const credentialIds = useMemo(() => {if (!parameterKey) {- return undefined;+ return [];}const credentialParam = workflowParameters.filter((p) => p.parameterType === "credential").find((p) => p.key === parameterKey);if (credentialParam && parameterIsSkyvernCredential(credentialParam)) {- return credentialParam.credentialId;+ const rotatedIds = credentialParam.credentialIds;+ return rotatedIds && rotatedIds.length > 0+ ? rotatedIds+ : [credentialParam.credentialId];}const workflowParam = workflowParameters.find(@@ -47,27 +52,42 @@ export function useSelectedCredentialTotpIdentifier(p.defaultValue,);if (workflowParam && workflowParam.parameterType === "workflow") {- return workflowParam.defaultValue as string;+ return [workflowParam.defaultValue as string];}- return undefined;+ return [];}, [parameterKey, workflowParameters]);+ const primaryCredentialId = credentialIds[0];const credentialFromList = credentials.find(- (credential) => credential.credential_id === credentialId,+ (credential) => credential.credential_id === primaryCredentialId,);- const credentialQuery = useCredentialQuery(credentialId, {+ // ponytail: only the primary (first-rotated) id gets a detail-fetch fallback;+ // a fetch per rotated id would need a variable number of hooks. Other+ // rotated ids resolve from the already-fetched page (page_size 100).+ const credentialQuery = useCredentialQuery(primaryCredentialId, {enabled: skyvernCredentialSourceAvailable && !credentialFromList,});- const credential = credentialFromList ?? credentialQuery.data;return useMemo(() => {- if (- credential &&- credential.credential_type === "password" &&- "totp_identifier" in credential.credential- ) {- return credential.credential.totp_identifier ?? null;+ const knownCredentials =+ credentialFromList || !credentialQuery.data+ ? credentials+ : [...credentials, credentialQuery.data];++ const identifiers = credentialIds+ .map((id) => knownCredentials.find((c) => c.credential_id === id))+ .map((credential) =>+ credential &&+ credential.credential_type === "password" &&+ "totp_identifier" in credential.credential+ ? (credential.credential.totp_identifier ?? null)+ : null,+ )+ .filter((identifier): identifier is string => Boolean(identifier));++ if (identifiers.length === 0) {+ return null;}- return null;- }, [credential]);+ return Array.from(new Set(identifiers)).join(", ");+ }, [credentialIds, credentialFromList, credentialQuery.data, credentials]);}