Files
officinazuliani/docs/adr/0005-orari-da-google-places.md

2.3 KiB

ADR 0005: Opening hours from the Google Business Profile via Places API

Status

Accepted (2026-11-04)

Context

Opening hours were hard-coded in the site. The client keeps them up to date on the Google Business Profile listing "Officine Zuliani E. di Peresani A. Tosoni B. & C. S.A.S.", including special closures (holidays, vacations). Having one source avoids mismatches between site and Google (also a local-SEO signal).

Decision

  • Read hours with Places API (New) Place Details (regularOpeningHours, currentOpeningHours, businessStatus) using an API key restricted to Places API. The Business Profile API was rejected: owner OAuth and Google approval are overkill for reading hours.
  • scripts/orari-google.mjs normalizes the response to the site format: settimana (days grouped by identical time ranges) and prossimiGiorni (actual ranges for the next 7 days, special closures included). On any error it leaves the existing file untouched.
  • Build time: deploy.sh runs the script and writes src/data/orari-google.json (committed snapshot). The build uses it for the hours text, the table on /dove-siamo and the openingHoursSpecification JSON-LD. If it is missing, src/data/orari.ts falls back to hard-coded hours.
  • Runtime: a second container officinezuliani-orari (node:22-alpine, no custom image) runs the same script every 6 hours and writes orari.json to a shared volume served by nginx at /dati/orari.json. The "open now" sign fetches it in the browser and redraws bars and status; if the fetch fails, the build-time hours stay.
  • The key is never in the repository or in the browser: local .env.server (git-ignored) → copied by deploy.sh to the server as .env (mode 600).

Consequences

  • The client edits hours only on Google; the sign follows within 6 hours, without a deploy. The /dove-siamo table and JSON-LD update at the next deploy.
  • About 120 Place Details requests per month: expected to stay within Google Maps Platform free monthly usage, but a billing account is required — check the current price list.
  • If Google returns no regular hours, nothing is overwritten (no blank sign).

Update (2026-11-04)

Refresh interval changed from 6 to 24 hours (owner's request: hours change rarely). The sign therefore follows a change on Google within a day; about 30 requests per month plus one per deploy.