@lobehub/edge-contract
v0.5.0
Published
One implementation of the edge logic shared by the LobeHub gateway, landing, cloud and lobe-chat, plus golden fixtures every copy is tested against.
Maintainers
Keywords
Readme
@lobehub/edge-contract
Edge logic that more than one LobeHub repository has to agree on, kept in exactly one place. The gateway, landing, lobehub-cloud and lobe-chat import it instead of carrying copies.
| Subpath | What it owns |
| --- | --- |
| ./cache-tags | Business cache tags, raw-identifier builders, URL-segment decoding and canonical detail-tag recognition. |
| ./landing-locales | The URL path prefixes landing serves, and the default (en, at the bare path). |
| ./seo-topics | The discover topics landing server-renders for ?q=. |
| ./request-locale | The app locale list and how a request picks one (hl, then the LOBE_LOCALE cookie, then Accept-Language). |
| ./last-workspace-cookie | The LOBE_LAST_WORKSPACE cookie format. |
| ./acquisition-context | The signed lh_acq first-touch cookie, landing click ids, the first-touch params landing writes on App links (FIRST_TOUCH_PARAMS) and the attribution params lifted onto /signin. |
| ./app-acquisition-touch | The signed lh_acq_app cookie: the first touch of a visitor who reached sign-in without a landing click, written by the App and by the gateway on lobehub.com. |
fixtures/*.json are golden cases ({ cases: [{ name, input, expected }] }) captured from the
implementations this package replaced. They are frozen: a change that fails one is a behavior
change every consumer will see, so update the case on purpose, in the same commit.
Design: lobehub-gateway/docs/ryugi/specs/2026-11-06-logic-dedupe-design.md.
Cache tag identities
Import from @lobehub/edge-contract/cache-tags. marketplaceItemTag(kind, identifier)
and blogPostTag(slug) take raw identifiers and encode them once. Invalid values
(empty, over 255 UTF-16 code units, ASCII controls or unpaired surrogates) return
undefined.
For a URL path segment, call decodeCacheTagPathSegment first. It decodes once and
returns the validated raw identifier, or undefined for malformed input:
marketplaceItemTag('skill', 'owner/repo');
// landing:marketplace:skill:item:owner%2Frepo
marketplaceItemTag('skill', 'owner%2Frepo');
// landing:marketplace:skill:item:owner%252Frepo
const identifier = decodeCacheTagPathSegment('owner%2Frepo');
const tag = identifier === undefined ? undefined : marketplaceItemTag('skill', identifier);
// landing:marketplace:skill:item:owner%2FrepoisCanonicalBlogPostTag and isCanonicalMarketplaceItemTag recognize complete,
canonically encoded detail tags. They do not grant purge permission: entrypoint,
deployment, token and environment policy stay with the consumer. URL-to-tag matching,
origin hosts, Cloudflare calls and the gateway's torii:* cache identities also stay
in the gateway.
First-touch cookies under more than one domain
The gateway writes lh_acq and lh_acq_app with Domain=lobehub.com so a sign-in that starts on
lobehub.com and finishes on app.lobehub.com keeps its source; the App still writes host-only
copies. A browser then sends the same name twice. Read with resolveAcquisitionContextCookie /
resolveAppAcquisitionTouchCookie, which verify every copy and keep the earliest valid one;
readAcquisitionContextCookie still returns only the first copy and is kept for existing callers.
The tokens are signed, not encrypted, and every *.lobehub.com host receives them, so a
credential in the entry path is replaced on capture and on every read: /invite/<token> is
stored as /invite/:token (see CREDENTIAL_PATH_SEGMENTS in acquisition-context.ts).
Releases: bump version, push a v<version> tag; CI publishes to npm.
