libraries.dorianmarie.com · version 1
small projects.
one shared foundation.
javascript libraries for a consistent architecture, account, presentation, and installable web app. black and white. publicly documented. built for cloudflare workers.
every project, one family.
charts
record a daily number and explore charts and statistics.
charts.dorianmarie.comtracking
tracked links, email pixels, and application usage.
tracking.dorianmarie.comdorianmarie.com
all applications by dorian marié.
dorianmarie.comaccount
one account, passwords, and passkeys for every project.
account.dorianmarie.comheartbeats
monitor scheduled jobs and receive failure alerts.
heartbeats.dorianmarie.comtime
a quiet clock, available offline.
time.dorianmarie.comweights
track your weight privately, with optional account sync.
weights.dorianmarie.comproxy
download and cache files.
proxy.dorianmarie.comlibraries
shared javascript, design, authentication, and pwa documentation.
libraries.dorianmarie.comtracking
workers can supply request-local DM_NAV_LINKS entries with href and label to render application navigation in the shared top-right menu. labels and links are escaped during server rendering.
the shared platform bundles a same-origin tracking client. POST /_dm/events forwards bounded view, click, action and cursor batches through the TRACKING service binding. window.dmTrack(name) records semantic actions without form values. account pages, credential routes, query urls and fragment urls are excluded. tracking respects dm-tracking=off, global privacy control and do not track. manage preferences at https://tracking.dorianmarie.com/privacy. analytics endpoints and personalized pages must never be cached.
architecture
the project registry supports explicit hostname and directory values for the apex site. the optional shell array lists additional public routes to precache for offline use; never include personalized or authenticated routes.
each project is an independent cloudflare module worker. product behavior and data stay in the project. libraries provides common request handling, navigation, design tokens, icons, pwa routes, account integration, and build and deployment tooling.
| file | purpose |
|---|---|
AGENTS.md | project rules and resource identity |
package.json | build, test, deploy |
cloudflare.config.js | javascript worker configuration |
src/ | application and worker code |
public/ | optional browser assets |
scripts/ | project-specific asset preparation |
dist/worker.js | generated deployment artifact |
auth.js | host-only project sessions and pkce |
platform.js | shared shell, responses, assets, pwa |
projects.js | project and worker registry |
icons.js | white svg glyphs on black |
service-worker.js | public shell cache and offline fallback |
the shared implementation is bundled into each worker and served from that project's own origin under /_dm/. a documentation outage cannot break another project's ui. no runtime cdn or cross-origin script dependency is required. existing product-specific renderers remain responsible for their screens.
sync
shared syncRequest(request, env, byteLimit) validates same-origin json mutations, authenticates through account, bounds request bodies, and rejects account changes before accessing records. apps retain their database schema, validation, batching, and conflict rules. mergeStamped(groups, key) merges timestamped records without discarding tombstones. device-only records remain local until explicitly copied to an account. sync runs automatically; routine synchronization status is hidden across apps, and manual sync controls are hidden in reminders. account errors remain actionable.
push notifications
shared push.js provides authenticated subscription registration and bounded web push delivery. push-client.js manages browser permission, subscriptions, account ownership, and timezone. push-worker.js receives notifications and focuses the app. reminders currently notifies while open. notifications require explicit permission. vapid secrets stay on the worker. push handlers are bundled into the app service worker and assets are served from the app origin.
security boundaries
credential changes, passkey enrollment, api key creation, and credential-wide revocation require fresh password or existing-passkey verification. confirmations expire after five minutes, can be used once, and are bound to the browser session and action. password changes revoke other sessions, account api keys, and legacy heartbeat tokens. the account offers an explicit revoke-all action for sessions, api keys, and passkeys.
new passwords use versioned pbkdf2-hmac-sha256 with 600,000 iterations through the bundled javascript implementation; native workers pbkdf2 has a per-call iteration ceiling. successful password login upgrades legacy 100,000-iteration hashes without requiring a password reset.
use readLimitedText(request, byteLimit) from request.js for bounded request bodies. it checks actual streamed bytes and cancels oversized bodies, including when content-length is missing or false. weights sync limits bodies to 1,000,000 bytes; shared preferences limits them to 2,048 bytes.
heartbeat urls contain credentials in the path. query-string redaction cannot protect them. deployment keeps heartbeat logs and traces enabled with automatic sampling set to zero, disables invocation logs, logpush, and configured telemetry destinations, and retains live-tail access for diagnosis. cloudflare normalizes persistence disabled with no destinations to disabled observability, so the policy prevents routine retention through zero sampling instead. live-tail operators can still see credential-bearing urls and must treat output as sensitive. existing tail consumers require review before deployment. previously stored telemetry is subject to existing retention and access controls; deployment does not purge it or rotate existing monitor urls.
the shared response pipeline applies a content security policy to html, including embedded public assets and offline pages, while preserving stricter application policies. scripts load from the app origin; framing, object embedding, and external form submissions are blocked.
app pages use the same-origin referrer policy so native post forms retain their origin header; cross-origin destinations receive no referrer. authentication redirects keep no-referrer.
weights sync requires an expected account user id in owner. the worker rejects account changes with 409 before reading or writing records; the browser retains the outbox and pauses until reload.
proxy downloads require a project session or account api key. account validates credentials through /sso/proxy-permit and enforces 30 downloads per minute and 100 per day per user, plus 1000 per day globally. only raster images up to 10 mib are accepted, with a 15-second upstream timeout. response headers are allowlisted; upstream cookies are discarded. the r2 cache uses 256 overwriteable slots (at most 2.5 gib of new current object data), with a one-day freshness window. existing legacy cache objects are not deleted automatically.
account recovery invokes AccountEmail. through the existing private mail binding before changing credentials. deploy heartbeats before account when introducing this rpc method. recovery fails closed if revocation is unavailable.
server rendering
workers render the initial application interface, navigation, language, and authenticated data in html. browser javascript adds interactions without an initial data-loading screen. device-only weight records stay on the device and enhance the public offline interface. personalized html uses no-store and is never put in an offline cache.
design
date-input.js automatically enhances date inputs with custom monochrome triggers and calendars, localized french and english labels, monday-first weeks, month navigation, arrow keys, home/end, page up/down, today, clear, and escape. popups use the top layer and fit mobile viewports. original date fields retain form serialization, required/min/max/step validation, reset, and input/change events. programmatic value changes and dynamically rendered fields are supported; native fields remain available without javascript.
all selects are enhanced by the shared searchable-select.js component with a custom searchable popup, accent-insensitive filtering, keyboard arrows, enter, escape, disabled options, option groups, and multiple selection. opening a dropdown focuses its popup without focusing the search field or opening the mobile keyboard; tab reaches search and arrow keys navigate options. editable datalist suggestions also use custom filtered popups while allowing new text values. category inputs opt into an explicit add action with data-create-option; the cancelable dm-create-option event lets the app persist the category before selection. controls added by app renderers are enhanced automatically. original server-rendered selects preserve form submission, validation, reset, and existing input/change handlers; without javascript they remain available. closed popups remain explicitly hidden and do not occupy layout space. open popups use the browser top layer so they also work inside dialogs and the shared menu.
interface copy is authored in lowercase in every language, including navigation, accessibility labels, and status messages. css text transforms are not used. user content and case-sensitive code retain their original spelling.
the shared menu control disables native browser appearance so safari renders its square border without a system bevel or shadow.
every app offers auto, français, and english language choices, plus system, light, and dark themes. auto follows the first supported browser language; system follows the device color scheme. preferences stay on the current origin in local storage, work offline, and fall back to in-memory settings when storage is unavailable. only interface copy is translated; user content, identifiers, and code examples remain unchanged.
html form validation and error pages use the shared navigation and selected language, including post responses; redirects and json responses are unchanged.
author interface copy in lowercase at the source, without emojis or css case conversion. preserve user-entered case, identifiers, source examples, and proxied content. every app uses the shared install app control; installed apps hide it.
light mode uses white surfaces and black text; dark mode uses black surfaces and white text. system fonts. square controls, visible keyboard focus, responsive spacing, and reduced-motion support. icons use a black background with a white foreground, including png install icons and svg favicons. no emojis.
| token | value |
|---|---|
| --dm-black | #000000 |
| --dm-white | #ffffff |
| --dm-font | system-ui and platform fallbacks |
| --dm-width | 1120px |
| --dm-space | 24px |
| --dm-radius | 0 |
common navigation includes projects, documentation, login, register, the signed-in account, sign out, and an install app button with native installation or browser instructions. secondary app navigation and settings also live in the folded menu, while primary actions stay in the page. navigation spans the viewport on every app, with the brand at left and a folded menu at the top right on desktop, tablet, and mobile. the brand and menu align to the viewport edges with a 20px inset or the device safe area, independently of application content width. the menu contains all shared links, account actions, install controls, language, and theme settings. it opens with a keyboard or pointer and closes with escape or a click outside. controls have a minimum 44px touch target. single-line inputs, dropdowns, and buttons share a 44px border-box height, 24px line height, and 9px vertical padding, including date fields and menu preferences. local-first apps refresh shared styles from the network when online and fall back to cached styles offline. single-line fields share square custom borders, theme-aware surfaces, and horizontal spacing. date fields use the shared custom calendar; datetime, time, month, and week fields retain native editing and pickers; calendar and clock indicators use the current text color. disabled controls remain recognizable. custom dropdowns stay anchored within the visible viewport during mobile keyboard and viewport changes; option navigation scrolls only the popup, preserving page and dialog scroll positions. custom select triggers reserve space for a theme-aware chevron inset 12px from the right border. buttons can grow for wrapped labels. textareas, listboxes, and specialized inputs retain their own sizing. content uses the shared 1120px width and 24px gutters (20px on mobile); focused tools may use a narrower content column.
local-first applications
set localFirst: true alongside offline: true in the shared project registry to serve explicitly public assets from the release cache and bound navigation waits to 700 ms before using a public shell. the shell receives a dm-offline-shell meta marker when used as a fallback. applications may use that marker to restore device records; it never establishes a session. network requests time out after ten seconds. server-rendered account data remains available on healthy connections. personalized html, apis, authentication routes, query urls, and responses with cookies or no-store are never stored.
account settings and api keys
manage passkeys, language, theme, time format (24h/12h), weight units (kg/lb), temperature units, and api keys at account. signed-in apps read account preferences through /sso/preferences. language and theme changes in the shared menu save to the account; device preferences remain available offline. every app exposes /api, /api/docs, /api/openapi.json, and authenticated /api/identity. account keys are hashed, shown once on creation, scoped to one project and read-only or read/write access, and expire in 1, 7, 30, or 90 days (default 30). creation requires {name, project, permission, days, confirmation}. obtain an action-bound confirmation through /api/auth/confirm/password or the passkey confirmation endpoints; the account interface handles this flow. unscoped legacy keys remain listed but are no longer accepted and must be replaced. a new additive api_key_policies table must be created before deploying account. account keys cannot manage account credentials. revoke them individually at account, change the password to revoke all keys, or use the credential-wide revoke action. send Authorization: Bearer YOUR_KEY and the application’s own origin header for mutations. all product apis retain owner isolation. account management requires a browser session.
one shared top-right menu contains application actions, account, language, theme, installation, fullscreen, and documentation. content uses one font size with bold emphasis; clocks retain large digits. dialogs stay within the viewport. the enhanced menu uses a native modal dialog anchored below the menu button; the same menu button closes it, and escape also dismisses it, blocking touches to the page underneath. fullscreen appears only on supported devices. raw file links open a readable preview with a close control and the original raw url; automated requests retain their original responses. installed apps reserve the top safe area.
the native browser install banner remains enabled; the menu also provides installation and platform-specific instructions.
one account
account.dorianmarie.com owns registration, email verification, password sign in, password recovery, and passkeys. applications never collect account passwords.
- link to
/sso/loginor/sso/registeron the current project. - the worker creates a random state and pkce verifier in a secure, http-only, host-only flow cookie.
- the account service validates the registered callback and issues a short-lived, single-use authorization code.
- the project exchanges the code through its
ACCOUNTservice binding and stores a host-only session cookie. - authenticated apis call
ssoUser(request, env). identity stays server-side; tokens never enter local storage.
import {wrap, ssoUser} from '../../libraries.dorianmarie.com/src/auth.js';
const worker = {
async fetch(request, env) {
const user = await ssoUser(request, env);
if (!user) return Response.json({error: 'sign in required'}, {status: 401});
return Response.json({email: user.email}, {headers: {'Cache-Control': 'no-store'}});
}
};
export default wrap(worker);set ACCOUNT to the account worker. add new callback origins explicitly to the account service allowlist. project sign out revokes the parent session and uses a same-origin post to /sso/logout. sign out of all projects and password recovery revoke parent sessions at the account service. the existing sso/client.js entrypoint re-exports this implementation for compatibility.
authenticated requests fail closed if the account service is unavailable. the library does not cache api responses or authorization redirects.
installable, with a deliberate offline policy
every project includes <meta name="mobile-web-app-capable" content="yes"> in its shared html head and exposes a standalone manifest, 192px and 512px png icons, a root service worker, and an accessible offline page. the public apex directory, time, weights, and libraries shells work offline. weight entries retain the existing device storage behavior. account, heartbeats, and proxy show a reconnect page rather than cache personalized html.
only allowlisted, same-origin public assets and shells enter the cache. api routes, sso routes, authorization, query urls, non-get requests, and session responses never enter it. install icon urls include a content version, and ios receives an explicit 180px apple touch icon so new installations can refresh older artwork. releases are content-versioned. all apps check for updates on opening, focus, reconnect, and every minute while visible. waiting service workers activate automatically; existing controlled pages reload once the update takes control, when online and visible and no text field is focused. first installation does not reload the page. updates retain device records. activation removes only this project's caches. installing a pwa depends on browser support and may require “add to home screen” on ios.
shared interface
the shared navigation displays the application name. the weights menu includes settings and export; export downloads the existing device backup. mark a redundant app-name heading with data-dm-app-title to keep it accessible without displaying the name twice. distinct page headings remain visible.
| export or route | purpose |
|---|---|
| wrap(worker, options) | sso routes plus shared presentation; scheduled and named exports remain project-owned |
ssoUser(request, env) | verified user or null; service failures throw |
| standardize(worker, options) | shared assets, manifest, icons, navigation, and html presentation |
withAssets(worker, files, release) | embedded public assets and content-versioned offline shell |
| json(body, status) | json response with no-store and nosniff |
escapeHtml(value) | escape text for generated html |
| /_dm/platform.css | same-origin design tokens and common components |
| /_dm/platform.js | account navigation and pwa registration |
| /_dm/manifest.webmanifest | per-project install metadata |
| /sw.js | shared service worker with project-specific release |
| /_dm/icon.svg, /_dm/icon-192.png | project-specific monochrome icons |
| /health | deployment health, where supported by the application |
browse and download the javascript source. source modules are served as text for inspection and vendoring. import the checked-in modules at build time; do not load worker modules in a browser.
media upload
import installMediaUploads from media-upload.js into the application browser bundle and call it with window. render <dm-media-upload><input type="file"></dm-media-upload> on the worker. the custom element supports existing files, existing images, camera photos, and silent video recording (up to 60 seconds). use mode="image" and an image accept list for photo-only consumers such as calories (jpeg, png, webp; 10 mb). selection updates the original input FileList and emits bubbling input and change events. the consumer validates and uploads files through its own authorized endpoint; selection alone never uploads. camera permission is requested on click; cancellation, removal, and page exit release camera tracks. unsupported browsers use the native phone capture picker. native file inputs remain available before enhancement. camera errors offer file upload; server authorization and file limits remain the consumer’s responsibility.
charts
charts records one private nonnegative number per date. saving a date again updates its value. charts and statistics are rendered on the worker from owner-scoped entries; missing days are excluded from averages. the shared platform supplies navigation, account login, install icons and a public reconnect fallback. personalized pages and entry endpoints are never cached.
build, verify, deploy
# From ~/dorianmariecom:
npm install
npm run build
npm test
npm run deploy
# Work on one project:
node scripts/build.mjs weights
node scripts/deploy.mjs weights
# Each project also exposes:
npm run build
npm run deploythe workspace registry maps project domains to existing worker names. shared build tooling bundles javascript and embeds public assets. project preparation retains existing app asset pipelines. deployment reads existing remote settings, retains bindings and secrets, and updates the worker code. it does not run database migrations or recreate databases. new domains are configured explicitly. credentials stay in the local cloudflare profile and never enter public documentation.
cloudflare configuration uses javascript. logs and traces are enabled. tests cover account and session isolation, shared rendering, pwa cache exclusions, and product behavior. see the workspace and each project's agents.md before changing code.