{"secureTokens":{"secrets":[],"connections":[],"aiModels":[]},"isPublished":true,"isTriggerTypeChanged":false,"id":"4640114135793664","name":"Normalize Base64","description":"","rootContainer":{"id":"ec7xuc8jqmrf2ogi5","type":"container","steps":[{"actionTypeId":"script-v1","errorHandling":{"retries":[],"errorAction":0},"id":"gnue9wz8umrf2ptxc","name":"Execute Script","displayName":"Execute Script","settings":{"parameters":[{"name":"base64input","dataType":"string","value":{"stringValue":[{"type":"ref","value":{"referenceType":"startParam","displayName":"Start Parameters.Base64 Input","dataType":"string","name":"inputParameters.base64_input","isProjected":false,"path":".inputParameters.base64_input","iconSrc":"assets/img/designer/start-parameter.svg","error":false}}]}}],"script":"export default function normalizeBase64() {\n  try {\n    let input = String(parameters.base64input || \"\").trim();\n\n    if (!input) {\n      return {\n        NormalizedBase64: \"\",\n        MimeType: \"\",\n        IsValid: false,\n        ErrorMessage: \"The Base64 input is empty.\"\n      };\n    }\n\n    let mimeType = \"\";\n\n    // Decode URL-encoded input when applicable.\n    // Example: %2F, %2B, %3D\n    try {\n      if (/%[0-9A-Fa-f]{2}/.test(input)) {\n        input = decodeURIComponent(input);\n      }\n    } catch {\n      // Continue with the original value if URL decoding fails.\n    }\n\n    // Remove wrapping quotes.\n    input = input.replace(/^[\"']+|[\"']+$/g, \"\");\n\n    // Remove escaped line-break characters.\n    input = input\n      .replace(/\\\\r/g, \"\")\n      .replace(/\\\\n/g, \"\")\n      .replace(/\\\\t/g, \"\");\n\n    // Extract Base64 content from a Data URI.\n    // Example: data:image/png;base64,iVBORw0KGgo...\n    const dataUriMatch = input.match(\n      /^data:([^;,]+)(?:;[^;,]+)*;base64,(.*)$/is\n    );\n\n    if (dataUriMatch) {\n      mimeType = dataUriMatch[1] || \"\";\n      input = dataUriMatch[2] || \"\";\n    }\n\n    // Remove spaces, tabs and real line breaks.\n    input = input.replace(/\\s+/g, \"\");\n\n    // Convert Base64URL to standard Base64.\n    input = input\n      .replace(/-/g, \"+\")\n      .replace(/_/g, \"/\");\n\n    // Remove existing padding so it can be rebuilt correctly.\n    input = input.replace(/=+$/g, \"\");\n\n    // Base64 length cannot have a remainder of 1.\n    if (input.length % 4 === 1) {\n      return {\n        NormalizedBase64: \"\",\n        MimeType: mimeType,\n        IsValid: false,\n        ErrorMessage:\n          \"The input has an invalid Base64 length and may be incomplete or corrupted.\"\n      };\n    }\n\n    // Only standard Base64 characters should remain.\n    if (!/^[A-Za-z0-9+/]*$/.test(input)) {\n      return {\n        NormalizedBase64: \"\",\n        MimeType: mimeType,\n        IsValid: false,\n        ErrorMessage:\n          \"The input contains characters that are not valid Base64 characters.\"\n      };\n    }\n\n    // Restore missing padding.\n    while (input.length % 4 !== 0) {\n      input += \"=\";\n    }\n\n    return {\n      NormalizedBase64: input,\n      MimeType: mimeType,\n      IsValid: true,\n      ErrorMessage: \"\"\n    };\n  } catch (error) {\n    return {\n      NormalizedBase64: \"\",\n      MimeType: \"\",\n      IsValid: false,\n      ErrorMessage:\n        error instanceof Error\n          ? error.message\n          : \"An unexpected error occurred while normalizing Base64.\"\n    };\n  }\n}","scriptError":false,"schemaError":false,"exportSchema":"{\n    \"type\": \"object\",\n    \"properties\": {\n        \"default\": {\n            \"type\": \"object\",\n            \"properties\": {\n                \"NormalizedBase64\": {\n                    \"type\": \"string\",\n                    \"title\": \"Normalized Base 64\"\n                },\n                \"MimeType\": {\n                    \"type\": \"string\",\n                    \"title\": \"Mime Type\"\n                },\n                \"IsValid\": {\n                    \"type\": \"boolean\",\n                    \"title\": \"Is Valid\"\n                },\n                \"ErrorMessage\": {\n                    \"type\": \"string\",\n                    \"title\": \"Error Message\"\n                }\n            },\n            \"title\": \"Default\"\n        }\n    },\n    \"$schema\": \"http://json-schema.org/draft-04/schema\"\n}"},"type":"action"},{"id":"9datruoiamrfar2ui","name":"Set Variable","displayName":"Set Output","settings":{"variables":[{"name":"normalized_base64","displayName":"Normalized Base64","valueType":"object","isArray":false,"properties":[{"id":"aibw4dueomrfaq19s","name":"normalizedbase64","displayName":"NormalizedBase64","value":[{"type":"ref","value":{"referenceType":"stepParam","displayName":"Execute Script.Exports.Default.Normalized Base 64","flowStepId":"gnue9wz8umrf2ptxc","dataType":"string","outputName":"exports.default.NormalizedBase64","isProjected":false,"path":".exports.default.NormalizedBase64","possibleNull":false,"iconSrc":"assets/img/designer/actions/script-v1.svg","error":false}}],"valueType":"string"},{"id":"70yg3kyqkmrfaq1ww","name":"mimetype","displayName":"MimeType","value":[{"type":"ref","value":{"referenceType":"stepParam","displayName":"Execute Script.Exports.Default.Mime Type","flowStepId":"gnue9wz8umrf2ptxc","dataType":"string","outputName":"exports.default.MimeType","isProjected":false,"path":".exports.default.MimeType","possibleNull":false,"iconSrc":"assets/img/designer/actions/script-v1.svg","error":false}}],"valueType":"string"},{"id":"4ft0azx9nmrfaqhtg","name":"errormessage","displayName":"ErrorMessage","value":[{"type":"ref","value":{"referenceType":"stepParam","displayName":"Execute Script.Exports.Default.Error Message","flowStepId":"gnue9wz8umrf2ptxc","dataType":"string","outputName":"exports.default.ErrorMessage","isProjected":false,"path":".exports.default.ErrorMessage","possibleNull":false,"iconSrc":"assets/img/designer/actions/script-v1.svg","error":false}}],"valueType":"string"},{"id":"2b7b9cxrimrfarqig","name":"isvalid","displayName":"IsValid","value":[{"type":"ref","value":{"referenceType":"stepParam","displayName":"Execute Script.Exports.Default.Is Valid","flowStepId":"gnue9wz8umrf2ptxc","dataType":"boolean","outputName":"exports.default.IsValid","isProjected":false,"path":".exports.default.IsValid","possibleNull":false,"iconSrc":"assets/img/designer/actions/script-v1.svg","error":false}}],"valueType":"boolean"}],"operation":1,"value":null,"error":null}]},"type":"setVariable"}],"label":null,"showLabel":false},"variables":[{"isArray":false,"includeInOutput":true,"name":"normalized_base64","displayName":"Normalized Base64","valueType":"object","properties":[{"id":"aibw4dueomrfaq19s","name":"normalizedbase64","displayName":"NormalizedBase64","value":null,"valueType":"string"},{"id":"70yg3kyqkmrfaq1ww","name":"mimetype","displayName":"MimeType","value":null,"valueType":"string"},{"id":"4ft0azx9nmrfaqhtg","name":"errormessage","displayName":"ErrorMessage","value":null,"valueType":"string"},{"id":"2b7b9cxrimrfarqig","name":"isvalid","displayName":"IsValid","value":null,"valueType":"boolean"}],"value":null,"hasSchema":true}],"triggers":[{"id":"cb0330b1300a48ed92c41f1d8eb4e28e","name":"Subflow Trigger","triggerType":"childflowv1","triggerTypeName":"Subflow Trigger","connectionId":null,"parameters":[],"configuration":{"input":[{"isArray":false,"name":"base64_input","displayName":"Base64 Input","valueType":"string","value":null}]},"hasFilter":false,"filter":null}],"startParameters":[],"parameterMapping":[],"version":"5.0","isDraft":false,"isPrivate":true,"tags":[],"metadata":[],"publishedMetadata":[],"flowMetadata":{},"notes":[]}