{"flow":{"id":68,"summary":"GCP flow with updated preprocessor template","versions":[251,252,253,254,255,256,257,259,260,261,262,263,264,278],"created_by":"dieriba.pro916","created_at":"2025-04-03T09:36:45.709Z","votes":0,"approved":true,"apps":["windmill"],"value":{"modules":[],"preprocessor_module":{"id":"preprocessor","value":{"tag":"","type":"rawscript","content":"/**\n * Trigger Preprocessor for GCP Pub/Sub\n *\n * This updated preprocessor handles GCP Pub/Sub triggers.\n * It decodes base64-encoded messages, parses JSON if content-type is application/json,\n * and enriches the payload with message metadata.\n *\n * Key Updates:\n * - The GCP trigger object now includes `delivery_type`, and headers are accessible directly.\n *\n * Learn more: https://www.windmill.dev/docs/core_concepts/preprocessors\n */\nexport async function preprocessor(\n  event: {\n    kind: 'gcp',\n    payload: string\n    message_id: string,\n    subscription: string,\n    ordering_key?: string,\n    attributes?: Record<string, string>,\n    delivery_type: \"push\" | \"pull\",\n    headers?: Record<string, string>,\n    publish_time?: string,\n    ack_id?: string // acknowledgment ID for manual acknowledgment (only for pull delivery)\n  },\n) {\n  if (event.kind === 'gcp') {\n    const decodedString = atob(event.payload);\n    const attributes = event.attributes || {};\n    const contentType = attributes['content-type'] || attributes['Content-Type'];\n    const isJson = contentType === 'application/json';\n    let parsedMessage = decodedString;\n    if (isJson) {\n      try {\n        parsedMessage = JSON.parse(decodedString);\n      } catch (err) {\n        throw new Error(`Invalid JSON payload: ${err}`);\n      }\n    }\n    return {\n      messageAsDecodedString: decodedString,\n      contentType,\n      parsedMessage,\n      attributes,\n      ack_id: event.ack_id\n    };\n  }\n  throw new Error(`Expected gcp trigger kind got: ${event.kind}`);\n}","language":"bun","input_transforms":{"event":{"type":"static"}}}}},"schema":{"type":"object","$schema":"https://json-schema.org/draft/2020-12/schema","required":["messageAsDecodedString"],"properties":{"attributes":{"type":"object","description":"All GCP Pub/Sub message attributes.","additionalProperties":{"type":"string"}},"contentType":{"type":["string","null"],"description":"The value of the 'content-type' attribute if present in the message."},"parsedMessage":{"oneOf":[{"type":"object","title":"JSON object","required":["obj","label"],"properties":{"obj":{"type":"object"},"label":{"enum":["json"],"type":"string"}}},{"type":"object","title":"String","required":["str","label"],"properties":{"str":{"type":"string"},"label":{"enum":["str"],"type":"string"}}}],"description":"The parsed message payload: either as a JSON object if content-type is application/json, or as a raw string."},"messageAsDecodedString":{"type":"string","description":"The Pub/Sub message payload decoded from base64 into a UTF-8 string."}}},"description":"","recording":null,"vcreated_at":"2025-08-08T14:19:54.256Z","vcreated_by":"dieriba.pro916","comments":[]}}