{
  "version": "3.0",
  "entities": [
    {
      "name": "contact",
      "schemas": {
        "hubspot": {
          "object_type": "contacts",
          "field_mappings": []
        },
        "export": {
          "field_mappings": [
            {"source": "$._item.id", "target": "hubspot_id"},
            {"source": "$._item.properties.email", "target": "email"},
            {"source": "$._item.properties.firstname", "target": "first_name"},
            {"source": "$._item.properties.lastname", "target": "last_name"}
          ]
        }
      }
    }
  ],
  "flows": [
    {
      "name": "daily_new_customers_export",
      "source": "nightly",
      "event_type": "tick",
      "steps": [
        {"id": "customers", "action": "query", "target": "hubspot",
         "entity": "contact",
         "filters": [{"property": "lifecyclestage", "operator": "EQ", "value": "customer"}],
         "properties": ["email", "firstname", "lastname"],
         "window": {"property": "hs_lifecyclestage_customer_date",
                    "timezone": "Europe/Rome", "offset_days": -1}},
        {"id": "write_csv", "action": "export_file",
         "rows": {"each": "$customers.results", "entity": "contact", "schema": "export"},
         "key": "daily/new_customers_{$customers.window.date}.csv",
         "delimiter": ";"}
      ]
    }
  ],
  "sources": [
    {
      "name": "nightly",
      "type": "scheduled",
      "config": {"inbound": {"schedule": "0 2 * * *"}}
    }
  ],
  "settings": {}
}
