Skip to Content
FFitDatadraft
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":

  • strict mode — rejects the entire batch (status: "rejected", no document) if any single item fails validation.
  • partial mode — includes every valid item in document and lists rejected items in report.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 later importedAt produces identical IDs; changing subject produces distinct IDs.
  • Duplicate generated IDs inside one batch are rejected.
  • Every mapped record retains its original JSON payload under a namespaced source extension (extensions["strava:source"], etc.) and tags provenance with kind: "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.

On this page