Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Customer pipeline element

Run custom code as a step of a customer registration flow, for example to create the customer in a CRM before the pass is issued.

A customer registration flow is the ordered list of steps The Wallet Crew runs when an enrolment form is submitted with a flow: create the pass, send an email, call a connector. The customer pipeline element lets a tenant script be one of those steps. It receives the account being registered, can call any system the brand owns, and can write values back to the account, such as the id the CRM just assigned, for the following steps to use. This page is the reference for runtime.scriptable.customerPipelineElement.{scriptId}.

The pipeline element is the right tool when an action belongs to one registration flow: pushing a new member to an ERP, subscribing them to a newsletter, reserving a welcome offer. An action that must happen for every pass, whatever created it, belongs in the OnPassCreated hook of the pass updater. Rejecting invalid input is the job of the account validator, which runs before any step.

Real-world examples
  • A retailer creates the customer in its CRM during enrolment and stores the returned customer id as an identifier, so that the pass created by the next step carries it.

  • A brand subscribes the customer to its marketing platform when the consent box is ticked.

  • A ticketing integration attaches the registration to an existing order before the pass is issued.

Registration

The script registers runtime.scriptable.customerPipelineElement.{scriptId}, and a flow of server/flows.yml lists a step of type script with the same scriptId:

flows:
  - type: userRegistration
    name: loyalty
    steps:
      - type: script
        scriptId: crmSignup
      - type: pass
        passType: loyalty
      - type: mail
        mailTemplate: welcome

The flow name is the value of the flow query parameter of the enrolment request (POST /api/{tenantId}/customer?flow=loyalty). A flow name starts with a lowercase letter and is made of 2 to 50 letters, digits, underscores or hyphens.

The minimal skeleton is:

When it runs

The steps run one after the other, in the order of the flow, inside the enrolment request. By the time the flow starts, the request has passed validation (including the account validator) and the identity checks of the tenant's account configuration. The script step therefore sees the account as submitted, completed with whatever the customer providers found, and every step after it sees what the script wrote, because all steps share the same account. When the last step has run, The Wallet Crew emits the customer upserted event and returns the account to the caller.

Handlers

Method
Parameters
Returns
Required

CreateOrUpdate

entity

nothing, or a promise

No-op when missing

entity is the account: a flat dictionary keyed by field name (entity.email, entity.firstName), with identifiers under id.<key> (entity['id.crm.customerId']). Writing a key adds or changes a value for the following steps; assigning null removes it. A key written under id.<key> becomes an identifier of the pass that a later pass step creates. Conventions for keys, dates and numbers are described in Data objects.

Return value

The return value is ignored; only what the script writes to entity matters. An async handler is awaited before the next step starts.

Errors and edge cases

  • The handler throws or its promise rejects: the error is logged, the remaining steps do not run (no pass is created by a later pass step, no email is sent), the customer upserted event is not emitted, and the enrolment request fails.

  • CreateOrUpdate is missing from the registered object: the step does nothing, silently.

  • No script registers the key: the step does nothing, silently. A misspelt scriptId therefore looks like a script that ran without effect.

  • Several files register the key: the last registered wins, and the load order of files is not defined.

  • A step type that does not exist: the flow fails when it reaches that step.

Example

The step creates the customer in a CRM, or finds the existing one, and stores the CRM id as a pass identifier. The CRM answers 409 when the email already exists, so the script then reads the existing customer instead. A failure stops the flow on purpose: issuing a pass without a CRM id would leave a pass the CRM cannot match.

fetch retries a POST on a transient failure, so the creation endpoint should be idempotent, as here where a second creation of the same email answers 409 and is resolved by a lookup. See fetch for the retry rules.

Checking the result

Submitting the form of the flow, or calling POST /api/{tenantId}/customer?flow=<name> with test data, returns the account as the steps left it: the identifiers the script wrote are in the response, and the pass created by a later pass step carries them, which the pass list of the admin console shows. When the request fails, the error the script threw is recorded in the platform's monitoring together with the name of the step.

Common pitfalls

  • The script step is listed after the pass step, so the pass is created before the identifier exists.

  • The script throws when an optional system (a newsletter platform) is down, which blocks every enrolment; catching and logging the error lets the registration continue.

  • A consent value may arrive as a boolean or as text, depending on the form: the script normalizes it before mapping it to the external system, and checks the mapping in both directions.

FAQ

Can one script be used in several flows?

Yes. Every flow that lists a script step with the same scriptId runs the same handler. A script that must behave differently per flow is registered under two script ids, with shared helpers in the same file.

Does the step run when an existing customer re-registers?

It runs every time the flow runs. The handler checks what the account already carries (an identifier found by a customer provider, for example) to decide between creating and updating, as the example does.

Last updated