Mappers
Offline Provider Mappers
Normalize external fitness and wearable payloads into validated FitData documents with source preservation.
Import offline mappers from fitdata/mappers. Every mapper accepts an unknown input array plus an explicit MappingContext:
import { mapStravaActivities } from "fitdata/mappers";
const result = mapStravaActivities(items, {
subject: "example:athlete",
importedAt: "2026-11-29T10:00:00Z",
revision: 1,
mode: "strict",
});Mappers never fetch remote APIs, manage OAuth tokens, write to databases, or match duplicate activities across providers. Your host application owns sync, auth, and revision allocation.
Result contract and modes
Every mapper returns { status, report } plus a validated document when status is "complete" or "partial":
strictmode — rejects the entire batch (status: "rejected", nodocument) if any single item fails validation.partialmode — includes every valid item indocumentand lists rejected items inreport.issues.- Warnings do not reject items.
"complete"means every item satisfied the mapper's contract; it does not imply every source field became a native FitData field.
report separates sourceItems, acceptedItems, rejectedItems, outputRecords, and issues (with source item index paths).
Deterministic identity and source preservation
- Generated IDs are namespaced by provider, caller-supplied
subject, and entity type. Re-importing at a laterimportedAtproduces identical IDs; changingsubjectproduces distinct IDs. - Duplicate generated IDs inside one batch are rejected.
- Every mapped record retains its original JSON payload under a namespaced
sourceextension (extensions["strava:source"], etc.) and tagsprovenancewithkind: "imported", the mapper ID, and version. - Recognized credential keys (
userAccessToken,access_token,refresh_token,authorization,client_secret) are stripped recursively with a warning. This is a narrow credential safeguard, not a full PII scrubber.