collabSupport/scripts/lib
Joseph McQueen f58628e4a8 Add scripts/findEmptyLocations.js — closed-store cleanup discovery
Finds Webex Calling locations with zero PEOPLE-owned phone numbers
(the "we lost the store users, no one told us" pattern) by diffing
two paginated pulls:
  GET /v1/telephony/config/locations       → every location
  GET /v1/telephony/config/numbers         → every provisioned number
                                             with owner + location

Verdicts per location:
  - has-users           → ≥1 PEOPLE owner (excluded from report)
  - needs-cleanup-first → 0 PEOPLE but workspaces / AA / HG / etc
                          still present; needs Control Hub attention
                          before delete
  - safe-to-delete      → 0 of everything, ghost location shell

Console prints a per-location inventory table (top 20) plus a
summary. --report writes the full set to CSV with location id,
name, address, timezone, and per-owner-type counts.

--execute deletes safe-to-delete locations via
DELETE /v1/telephony/config/locations/{id}. Guarded by a mandatory
--i-am-sure flag and run serial (concurrency=1) with the shared
callWithRetry so 429/503 gets a Retry-After-aware backoff.
--limit / --offset let the operator pilot on a subset. Every
delete produces an audit line under `webex:emptyloc:audit`.

Also added a generic fetchAllPaginated helper to
scripts/lib/webexBulk.js (Link-header cursor pagination, configurable
array key) so subsequent bulk scripts can reuse it.

.gitignore: whitelisted findEmptyLocations.js; added
empty-locations-*.csv to the report-artifact ignore list.
2026-07-07 16:21:46 -04:00
..
webexBulk.js Add scripts/findEmptyLocations.js — closed-store cleanup discovery 2026-07-07 16:21:46 -04:00