Skip to content

Instantly share code, notes, and snippets.

@RicoTrevisan
Last active November 4, 2025 11:27
Show Gist options
  • Select an option

  • Save RicoTrevisan/fe1cc53c053a4639f56950fdd3f8a23a to your computer and use it in GitHub Desktop.

Select an option

Save RicoTrevisan/fe1cc53c053a4639f56950fdd3f8a23a to your computer and use it in GitHub Desktop.
Find unused endpoints in your .bubble file
#!/usr/bin/env bash
set -euo pipefail
if [[ $# -lt 1 || $# -gt 3 ]]; then
echo "usage: $0 <bubble-export.json> [tsv|csv|json|md] [base_url]" >&2
exit 1
fi
file=$1
format=${2:-tsv}
url=${3:-}
case "$format" in
tsv|csv|json|md) ;;
*)
echo "unsupported format: $format" >&2
exit 2
;;
esac
jq_program=$(cat <<'JQ'
def unused_rows:
[ . as $root
| ($root | [.. | objects | .properties? | (.custom_event, .api_event) | select(type == "string")]) as $used
| $root.api
| to_entries[]
| select(
(.value.type == "CustomEvent" or .value.type == "APIEvent")
and (.value.properties.expose == false)
)
| (.value.id) as $id
| select(($used | index($id)) | not)
| {id: .key,
type: .value.type,
name: (.value.properties.event_name // .value.properties.wf_name // "")}
] | sort_by(.name);
unused_rows
JQ
)
case "$format" in
tsv)
if [[ -n "$url" ]]; then
jq --arg url "$url" -r "$jq_program | ([\"ID\",\"Type\",\"Name\",\"URL\"], (.[] | [.id, .type, .name, \$url + (if (\$url | contains(\"?\")) then \"&\" else \"?\" end) + \"tab=BackendWorkflows&type=api&wf_item=\" + .id])) | @tsv" "$file" | column -ts $'\t'
else
jq -r "$jq_program | ([\"ID\",\"Type\",\"Name\"], (.[]? | [.id, .type, .name])) | @tsv" "$file" | column -ts $'\t'
fi
;;
csv)
if [[ -n "$url" ]]; then
jq --arg url "$url" -r "$jq_program | ([\"ID\",\"Type\",\"Name\",\"URL\"], (.[] | [.id, .type, .name, \$url + (if (\$url | contains(\"?\")) then \"&\" else \"?\" end) + \"tab=BackendWorkflows&type=api&wf_item=\" + .id])) | @csv" "$file"
else
jq -r "$jq_program | ([\"ID\",\"Type\",\"Name\"], (.[]? | [.id, .type, .name])) | @csv" "$file"
fi
;;
json)
if [[ -n "$url" ]]; then
jq --arg url "$url" "$jq_program | map(. + {url: (\$url + (if (\$url | contains(\"?\")) then \"&\" else \"?\" end) + \"tab=BackendWorkflows&type=api&wf_item=\" + .id)}) | {unused_endpoints: .}" "$file"
else
jq "$jq_program | {unused_endpoints: .}" "$file"
fi
;;
md)
if [[ -n "$url" ]]; then
jq --arg url "$url" -r "$jq_program | .[] | \"- [ ] [\\(.name)](\" + \$url + (if (\$url | contains(\"?\")) then \"&\" else \"?\" end) + \"tab=BackendWorkflows&type=api&wf_item=\" + .id + \")\"" "$file"
else
jq -r "$jq_program | .[] | \"- [ ] \\(.name)\"" "$file"
fi
;;
esac
@RicoTrevisan
Copy link
Author

Updated it to have an option to output a markdown format list

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment