Skip to content

TypeScript SDK

Every Mountaya API, typed end to end

@mountaya/client calls the Map Studio API, the Data API and the Tile API from Node, a browser or React Native. It has no runtime dependencies and is generated from the public schema.

Works with the tools you already use

Challenges we solve

Call every Mountaya API from TypeScript, with no client to write.

One package to add and audit

The client has no runtime dependencies, so nothing extra loads in your bundle.

The browser entry cannot hold a secret key

The package ships a ./browser entry with no secret-key credential type. Passing a server key to browser code fails at compile time.

Timestamps arrive as dates

Responses come back as real values. A timestamp is a Date, and a binary response is bytes with its content type.

Packages

What you install for TypeScript

The client calls every Mountaya API. The elements draw the result, renderer included.

@mountaya/client

npm install @mountaya/client

@mountaya/elements

npm install @mountaya/elements @mountaya/client maplibre-gl@6.18.0

Integration

Install, authenticate, call, render

Each snippet carries its own imports and runs as written. Mint the session token on your server, then let the map sign its own requests.

TypeScript

Install

MapLibre installs beside the elements, at the exact version their map worker is built from.

npm install @mountaya/client @mountaya/elements maplibre-gl@6.18.0

Authenticate

A publishable key is safe in a browser and is all the map needs. The Data API also takes a session token on every request, minted on your server from your secret key.

// On your server, and only there: a secret key can never reach a browser.
import { Mountaya } from "@mountaya/client";

const secretKey = process.env.MOUNTAYA_SECRET_KEY;
if (secretKey === undefined) {
  throw new Error("MOUNTAYA_SECRET_KEY is not set.");
}

const client = new Mountaya({ credential: { secretKey } });

const { data } = await client.admin.sessions.postSession({
  body: { publishable_key: "pk_…" },
});

// Return data.token and data.expires_at to the browser. The token is short-lived.

Call

Each operation is one typed method. The Data API is GraphQL, and the client writes the query for you.

import { Mountaya } from "@mountaya/client";

const client = new Mountaya({
  credential: { publishableKey: "pk_…", sessionToken },
});

const route = await client.data.directions({
  activity: "HIKING_AND_TRAIL",
  waypoints: [[6.8712, 45.9231], [6.9271, 45.9822]], // Chamonix to Argentière
});

Render

Hand the client to the map and it signs its own tile requests.

import { Mountaya } from "@mountaya/client";
import { MountayaMap } from "@mountaya/elements";
import "@mountaya/elements/styles.css";

const client = new Mountaya({ credential: { publishableKey: "pk_…" } });

const map = new MountayaMap({
  container: "map",
  client,
  center: [6.86, 45.83],
  zoom: 12,
});

// All three return a promise: they fetch a specification through the client.
await map.setItinerary(itineraryId);
await map.setOverlay("aspectslope");  // exclusive: replaces the previous overlay
await map.addEnrichment("hillshade"); // additive: stacks underneath

What will you build with the SDKs & Elements?

Tell us what your product needs to draw. We show you the SDKs & Elements that draw it.

Frequently asked questions

@mountaya/client for the APIs, and @mountaya/elements to draw a map. maplibre-gl installs beside the elements, at the exact version their map worker is built from. The elements build the renderer from it and sign its requests.

Yes. One package runs in Node, browsers and React Native. The ./browser entry is the same client without the credential types that must stay on a server.

A publishable key is safe in a browser and is all the map needs. The Data API also takes a session token on every request. You mint it on your server from your secret key, which never leaves it.

Generated, from the public schemas repository, so each method carries the schema's operation id. Each release records the schema tag it was built from.