{
  "name": "ControlLaunchPad - Signed new lead to Google Sheets (starter)",
  "flow": [
    {
      "id": 1,
      "module": "gateway:CustomWebHook",
      "version": 1,
      "parameters": {
        "hook": 0,
        "maxResults": 1
      },
      "mapper": {},
      "metadata": {
        "designer": {
          "x": 0,
          "y": 0,
          "name": "Enable JSON pass-through and request headers"
        },
        "restore": {
          "parameters": {
            "hook": {
              "label": "Create webhook; enable JSON pass-through and request headers; capture signed sample"
            }
          }
        }
      }
    },
    {
      "id": 2,
      "module": "util:SetVariable2",
      "version": 1,
      "parameters": {},
      "mapper": {
        "name": "signingSecret",
        "scope": "roundtrip",
        "value": "REPLACE_WITH_CLP_WEBHOOK_SECRET"
      },
      "metadata": {
        "designer": {
          "x": 300,
          "y": 0,
          "name": "Set your CLP signing secret"
        }
      }
    },
    {
      "id": 3,
      "module": "util:SetVariable2",
      "version": 1,
      "parameters": {},
      "mapper": {
        "name": "timestamp",
        "scope": "roundtrip",
        "value": "{{get(map(1.`__IMTHEADERS__`; \"value\"; \"name\"; \"x-clp-timestamp\"); 1)}}"
      },
      "metadata": {
        "designer": {
          "x": 600,
          "y": 0,
          "name": "Map original X-CLP-Timestamp header"
        }
      }
    },
    {
      "id": 4,
      "module": "util:SetVariable2",
      "version": 1,
      "parameters": {},
      "mapper": {
        "name": "expectedSignature",
        "scope": "roundtrip",
        "value": "{{sha256(join(add(emptyarray; 3.timestamp; 1.json); \".\"); \"hex\"; 2.signingSecret)}}"
      },
      "metadata": {
        "designer": {
          "x": 900,
          "y": 0,
          "name": "HMAC original timestamp and raw JSON"
        }
      }
    },
    {
      "id": 5,
      "module": "json:ParseJSON",
      "version": 1,
      "parameters": {
        "type": ""
      },
      "mapper": {
        "json": "{{1.json}}"
      },
      "metadata": {
        "designer": {
          "x": 1200,
          "y": 0,
          "name": "Verify signature before parsing"
        }
      },
      "filter": {
        "name": "Fail closed: configured secret, original body, signature and 5-minute window",
        "conditions": [
          [
            {
              "a": "{{2.signingSecret}}",
              "o": "text:notequal",
              "b": "REPLACE_WITH_CLP_WEBHOOK_SECRET"
            },
            {
              "a": "{{length(2.signingSecret)}}",
              "o": "number:greater",
              "b": "0"
            },
            {
              "a": "{{length(1.json)}}",
              "o": "number:greater",
              "b": "0"
            },
            {
              "a": "{{length(3.timestamp)}}",
              "o": "number:greater",
              "b": "0"
            },
            {
              "a": "{{get(map(1.`__IMTHEADERS__`; \"value\"; \"name\"; \"x-clp-signature\"); 1)}}",
              "o": "text:equal",
              "b": "sha256={{4.expectedSignature}}"
            },
            {
              "a": "{{abs(parseNumber(formatDate(now; \"X\")) - parseNumber(3.timestamp))}}",
              "o": "number:lessorequal",
              "b": "300"
            }
          ]
        ]
      }
    },
    {
      "id": 6,
      "module": "google-sheets:addRow",
      "version": 2,
      "parameters": {
        "__IMTCONN__": 0
      },
      "mapper": {
        "mode": "fromAll",
        "insertUnformatted": false,
        "valueInputOption": "RAW",
        "insertDataOption": "INSERT_ROWS",
        "spreadsheetId": "REPLACE_WITH_SPREADSHEET_ID",
        "sheetId": "REPLACE_WITH_SHEET_NAME",
        "includesHeaders": true,
        "useColumnHeaders": false,
        "values": {
          "0": "{{5.id}}",
          "1": "{{5.occurredAt}}",
          "2": "{{5.data.object.id}}",
          "3": "{{5.data.object.firstName}}",
          "4": "{{5.data.object.lastName}}",
          "5": "{{5.data.object.email}}",
          "6": "{{5.data.object.phone}}",
          "7": "{{5.data.object.propertyAddress}}",
          "8": "{{5.data.object.source}}"
        }
      },
      "metadata": {
        "designer": {
          "x": 1500,
          "y": 0,
          "name": "Choose Google connection, spreadsheet and tab"
        },
        "restore": {
          "parameters": {
            "__IMTCONN__": {
              "label": "Select your Google connection"
            }
          }
        }
      },
      "filter": {
        "name": "Only real lead.created events",
        "conditions": [
          [
            {
              "a": "{{5.object}}",
              "o": "text:equal",
              "b": "event"
            },
            {
              "a": "{{5.type}}",
              "o": "text:equal",
              "b": "lead.created"
            },
            {
              "a": "{{5.test}}",
              "o": "boolean:equal",
              "b": false
            }
          ]
        ]
      }
    }
  ],
  "metadata": {
    "instant": true,
    "version": 1,
    "scenario": {
      "roundtrips": 1,
      "maxErrors": 3,
      "autoCommit": true,
      "autoCommitTriggerLast": true,
      "sequential": true,
      "confidential": true,
      "dataloss": false,
      "dlq": false,
      "freshVariables": false
    },
    "designer": {
      "orphans": []
    }
  }
}
