Aller au contenu

mapping.yaml

Ce contenu n’est pas encore disponible dans votre langue.

mapping.yaml describes how fields move between a source, CMF and a target, and which strategies apply. export scaffolds one and map sets its target; the other commands read it with --mapping. Every section is optional except target where noted.

target: auth0
connection_id: con_1a2b3c
# Source side: flat-file columns -> CMF (export --source flatfile)
records_path: data.users
fields:
- {source: id, cmf: source_id}
- {source: mail, cmf: email, transform: "trim|lowercase"}
- {source: active, cmf: blocked, transform: not}
# Custom transforms, usable in any transform pipeline
transforms:
normalize_phone: {handler: audit}
# IDs the target is to give the users
ids:
target: {strategy: uuidv5, namespace: 6ba7b811-9dad-11d1-80b4-00c04fd430c8}
# Target side: CMF -> target fields, on import
target_fields:
- {cmf: profile.locale, target: user_metadata.locale, transform: lowercase}
metadata:
- {key: internal_notes, from: user_metadata, destination: app_metadata.notes}
conflict: {on_duplicate: skip}
# Decisions handed to handlers
strategies:
import.payload: {handler: audit}
verify.lookup: {strategy: target_id}

Handlers are declared in hooks.yaml and selected here by name; a mapping can’t hold a URL or a secret. See Hooks.

The target connector the mapping is for (auth0, kratos, keycloak, firebase, cognito), required by validate --mapping and by ids.target, and the Auth0 database connection to import into (--connection-id wins over it).

How a flat file’s own columns become CMF fields, on export --source flatfile (and prepare). See export for the column convention and prepare for the full options of a field: source, cmf, pattern, values, transform and default. records_path is the dotted path to the array of users in a JSON file whose root is an object.

A transform is a pipeline of transforms joined with |, run left to right: the built-ins trim, lowercase, uppercase, bool (true/false, yes/no, 1/0, on/off… into true or false) and not (bool, inverted), and the custom ones under transforms. An empty value stays empty.

Custom transforms, each handed to a handler: on export as the map.field strategy, on import as map.target_field. A name can’t be a built-in’s.

transforms:
normalize_phone: {handler: audit, on_failure: fail}

ids.target decides the user ID each user gets in the target: preserve (the source ID, the default), prefix, template, uuidv5, or a handler. It is assigned once into the users file’s target_ids, by a job’s export or ids assign, and only Auth0 and Firebase accept it. See id.target.

Fields of the target’s user set from CMF fields, on import, after the connector’s own mapping (so they win over it).

target_fields:
- {cmf: profile.locale, target: traits.locale, transform: lowercase}
- {cmf: emails.0.value, target: metadata_admin.contact}
- {cmf: app_metadata.tier, target: metadata_public.tier, default: free}

cmf is a dotted path into the CMF user, array indexes included. An empty result leaves the target field unset. Without a transform the value keeps its type (a number, a boolean, an object); a transform needs a string, number or boolean.

target is a path the target accepts:

TargetPaths
auth0given_name, family_name, name, nickname, picture, user_metadata.<key>, app_metadata.<key>
kratostraits.<key> (not email, username or phone, which iamigrate sets from the user’s identifiers), metadata_public.<key>, metadata_admin.<key>
keycloakfirstName, lastName, attributes.<key> (a one-element list; a non-string value in JSON)
cognitoStandard attributes (name, given_name, family_name, birthdate, locale, …) by name, and custom:<name> (the attribute has to be in the pool’s schema)
firebasedisplayName, photoUrl, custom_claims.<key> (not a reserved claim name; merged with the claims from app_metadata, within Firebase’s 1000 bytes)

validate --mapping rejects a path the target doesn’t accept.

Moves a metadata key away from where the target connector puts it by default, to a target field path (as above), or drop to leave it out:

metadata:
- {key: email, from: user_metadata, destination: metadata_admin.legacy_email}
- {key: internal_notes, from: app_metadata, destination: drop}

Use it for a key that would collide with something the connector sets: the Kratos connector copies user_metadata into the identity’s traits, so a user_metadata.email collides with the user’s email trait. The user’s own identifier wins and the key stays in metadata_public only, and validate reports the collision.

The routes are the same for every user. To place keys differently per user, delegate to a handler with metadata.place: the keys it places are taken before the routes, which then apply to the rest.

What an import does with a user the target already has:

on_duplicateEffect
fail (the default)The user is reported as failed, as without the section
skipThe user is reported under the report’s skipped instead of failed, and still verified
upsertThe user is updated, as with --upsert. Only Auth0, Firebase and Cognito can; validate rejects it for Kratos and Keycloak

The strategies handed to handlers, by name, and the built-in alternatives of verify.lookup and identity.primary (email_first, username_first, phone_first). See Strategies for each: export.record, id.source, hash.detect, export.user, validate.user, validate.dedup_key, import.user, identity.primary, hash.translate, mfa.translate, metadata.place, import.payload, org.resolve, role.resolve, verify.lookup, verify.compare.

strategies:
export.user: {handler: audit}
verify.lookup: {strategy: target_id}

A step only needs the handlers of the strategies it runs: validate doesn’t need --hooks for a mapping whose only handler is an import.payload’s.

Written by export and map for review: the metadata keys found in the export, and the decisions left to a human. They don’t change what is imported; use metadata and target_fields for that.