Sign-in & shared code

Outside API logging

Pathshared/api-usage-log
Statuslive
Drill-down pages—
Pop-ups—
Tabs—
API routes—

Business rules

Data comes from: no database table. One Cloudflare Analytics Engine data point per call this worker makes to an outside API (dataset api_usage on live, api_usage_staging on staging). Shown on Admin → API Usage.

How it works:

  • utils/api-usage.ts wraps fetch before any other code loads, so every outside call is caught, including Dentrix, the Dentrix OAuth token, HubSpot, Resend and SMTP2GO. Calls to our own database and our own workers are not counted.
  • Each retry and each page of a paged loop counts as its own call. A call that fails before getting an answer is recorded with status 0.
  • Recorded per call: worker, vendor, endpoint (ids, emails and numbers replaced by {id}, query string removed), status and time taken. No patient data.
  • The same file is used in all three workers (Pulse, the Dental Day booking site, the office booking app). Keep the copies identical.
  • The API Usage page reads the data with the CF_ANALYTICS_TOKEN secret (Account Analytics Read). Live has it. Staging doesn't yet, so staging's page says "Not set up".
  • Last 7 days on live (27 Nov): 48,845 outside calls, 1.8% errors, 161 rate-limited (429), none of them from Dentrix. Dentrix: 21,963 calls, almost half from the open treatment-plan check (verifyOpenTreatmentPlans: at most 700 a run, each plan re-checked weekly, ortho every 12 hours). Background jobs stop when Dentrix's quota falls to 200, which is kept for people using the site. The low of 49 on 25 Nov was that reserve being used.

Open questions (need your answer)

Open questions:

  • Staging needs the token: run wrangler secret put CF_ANALYTICS_TOKEN --env staging in apps/worker with the same token as live.

Database tables & columns

No table found in its API routes (it may read through a helper the scan can't follow).

File structure

Its own files

  • apps/
    • worker/
      • src/
        • utils/
          • api-usage.ts