| """Deep links into the app β ?page=<key>&entity=<kind>:<id>&src=<source>. |
| |
| The app (app.py) consumes these params once per session right after login and routes to the page, |
| opening the entity drawer when an entity is present. Digest/alert/mention emails build their links |
| here so every emailed number lands the reader on the exact row it came from. `src` tags where the |
| click came from (digest / alert / mention) β the app logs it as the click-through read receipt. |
| """ |
| import os |
| import sys |
| from urllib.parse import quote |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| _LEGACY_HF_FALLBACK = 'https://royal-imports-cfo-os.hf.space' |
|
|
| BASE_URL = (os.environ.get('APP_BASE_URL') or _LEGACY_HF_FALLBACK).rstrip('/') |
|
|
| |
| |
| |
| _WARNED = [False] |
|
|
|
|
| def _warn_once_if_defaulted(): |
| if _WARNED[0] or os.environ.get('APP_BASE_URL'): |
| return |
| _WARNED[0] = True |
| print(f"[links] APP_BASE_URL is not set - emailed deep links will point at " |
| f"{_LEGACY_HF_FALLBACK}, which is correct ONLY while that is where the app lives. " |
| f"Set APP_BASE_URL in the deployed environment.", file=sys.stderr) |
|
|
| |
| LINK_KINDS = ('customer', 'sku', 'agent', 'account') |
|
|
|
|
| def deeplink(page=None, kind=None, ident=None, src=None): |
| """An absolute app URL. deeplink('customer_data', 'customer', 1234, src='digest').""" |
| _warn_once_if_defaulted() |
| parts = [] |
| if page: |
| parts.append(f"page={quote(str(page), safe='')}") |
| if kind in LINK_KINDS and ident not in (None, ''): |
| parts.append(f"entity={quote(f'{kind}:{ident}', safe=':')}") |
| if src: |
| parts.append(f"src={quote(str(src), safe='')}") |
| return BASE_URL + ('/?' + '&'.join(parts) if parts else '/') |
|
|