@geolytix/mapp package
The MAPP library is published to npm as @geolytix/mapp so that sites which are not XYZ views can render XYZ layers. The package README is its npm page and has the install and usage snippets; this concept adds the context across the XYZ API boundary. MAPP.UI is not published; see MAPP.UI.
What the package is
dist/mapp.js(ES module bundle, with sourcemap) anddist/mapp.css, exported as@geolytix/mappand@geolytix/mapp/css.[1]- The import has side effects: it parses the URL hooks and assigns the
mappglobal. The default export is the same object.[2] - The same bundle is served by XYZ as
public/js/lib/mapp.js. An XYZ view and an npm site run the same code; only the host setup differs.
Openlayers
ol is a peer dependency, but MAPP uses the ol global, not the ol ES modules. Load ol/dist/ol.js as a classic script before importing MAPP. The entry module warns when ol is missing or older than the version it expects; it does not load it.[2:1] Bundling ol into the package is caught by the size budget in pack.mjs.
The XYZ host
mapp.host is the XYZ base URL. In an XYZ view it comes from the head's data-dir; elsewhere it is empty, and requests go to /api on the page's origin. Set mapp.host after the import, or pass host to mapp.Mapview(); a mapview without host uses mapp.host.[3]
Cross-origin pages
A page on another origin than XYZ needs the XYZ instance to allow it:
- CORS. Set
CORS_ORIGINSon the XYZ instance to a comma separated list of origins, or*. The cors middleware then answers preflights and setsAccess-Control-Allow-Originfor those origins; credentials are never allowed.[4] Same-origin hosting, eg. behind a reverse proxy, needs no CORS. - Cookies. The user cookie defaults to
SameSite=Strict(COOKIE_PROPS), so the browser does not send it from another site.[5] A cross-origin page is anonymous: it sees only locales and layers without role restrictions, and aPRIVATEinstance redirects it to the login. Restricted data needs same-origin hosting or a token. - Tokens. A request which sends a token explicitly, as an
Authorizationheader ortokenparam, is authenticated as the token's owner, also cross-origin.[4:1] Treat a token in a page like any credential.
Content Security Policy
Some layer formats and utilities import modules at runtime from esm.sh, eg. maplibre-gl, h3-js, proj4. A page with a CSP must allow https://esm.sh in script-src.[6]
Versions
- The package version is the XYZ release version, set by the version bump with the root and
mapp.mjsversions; see Monorepo. - Releases without MAPP changes are not published, so versions have gaps. Prereleases use the
nextdist-tag. - Use the package with an XYZ instance of the same minor version. The request params and the workspace keys MAPP sends must match what that XYZ version accepts.
Where to change
- Package contents and checks:
apps/mapp/package.json(files,exports,peerDependencies) and scripts/pack.mjs. Keep the README usage sections in step; it is the npm page. - Cross-origin behaviour: the cors middleware and its tests.
- Publishing: the Publish MAPP workflow; see Publishing the @geolytix/mapp package.
Tests
tests-package/package.test.mjs installs the packed tarball, loads ol as a global, sets mapp.host to the testhost and renders a locale, the way an npm site does. The MAPP Package workflow runs it on pull requests through a local Verdaccio registry.