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

Account validator

Reject an enrolment with field-level error messages before anything is created, with runtime.scriptable.scriptableAccountValidator.

The account validator lets a tenant script check an enrolment before The Wallet Crew does anything with it. The script receives the submitted account and returns a list of errors, each tied to a form field or to the account as a whole; when the list is not empty, the enrolment is refused with those messages and nothing is created, no email is sent and no flow runs. This page is the reference for runtime.scriptable.scriptableAccountValidator.

It is the right tool for business rules that the form's own field validation cannot express: a minimum age, a postal code format per country, a list of excluded email domains, a membership number checked against an external system. It is not meant to change the account: values are completed by the pass data provider in the account API and by the steps of a registration flow.

Real-world examples
  • A club refuses enrolments of customers under 18, with the message shown next to the birth date field.

  • A retailer operating in two countries checks the postal code format of the chosen country.

  • A B2B program only accepts email addresses from the domains of its partner companies.

Registration

The key is runtime.scriptable.scriptableAccountValidator. Registering it is enough: no configuration file refers to it.

export default function (context) {
  context.register('runtime.scriptable.scriptableAccountValidator', {
    Validate: async (account) => []
  });
}

When it runs

The validator runs at the very start of every enrolment submission, POST /api/{tenantId}/customer, whoever the caller is: a customer filling in the form, an admin console user, an API key. A rule that should apply only to customers checks a value that only the public form sends. It runs before the customer is identified, before the identity-confirmation email and before any registration flow, inside the request. The errors it returns are combined with those of any other account validation the tenant runs, and reported together.

Handlers

Method
Parameters
Returns
Required

Validate

account

an array of { Detail, Field? }, or a promise of it

Required

account is the account as submitted: a flat dictionary keyed by form field (account.email, account.birthDate), with identifiers, when the caller sends any, under id.<key>. Values are as the form sent them, usually strings. The conventions for reading keys are described in Data objects.

Return value

The handler always returns an array, empty when the account is valid. Each error uses PascalCase keys:

Key
Type
Meaning

Detail

string

Required. The message, as shown to the person who submitted the form.

Field

string

The form field the message belongs to. Omitted, the message is about the account as a whole.

When the array is not empty, the request answers 400 with a validation problem whose errors are grouped by field; messages without a field are grouped under the empty key "". Messages are returned as written, so a tenant with several languages writes them in the language of the form or returns a message per language the front end can pick from.

Errors and edge cases

  • Validate throws or its promise rejects: the enrolment request fails with an error, not with a validation problem. A validator that depends on an external system decides explicitly what an outage means (accept, or refuse with a clear message) instead of throwing.

  • Validate returns nothing: always return an array; [] is the valid answer.

  • Validate is missing from the registered object: the request fails when the validator runs.

  • No script registers the key: no validation runs and the enrolment goes on.

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

Example

The validator enforces a minimum age from a birthDate field sent as YYYY-MM-DD, and a postal code format per country. The date is read field by field rather than with new Date(y, m, d), which counts months from zero and uses the server's time zone.

Checking the result

Calling POST /api/{tenantId}/customer with an account that breaks a rule returns 400 with the messages under errors, keyed by field; the same call with a valid account goes on as before.

Common pitfalls

  • Field names a key that is not a field of the form, so a front end that displays errors by field has nowhere to show the message.

  • The handler is registered as validate: handler names are case-sensitive and must be Validate.

  • A slow external check delays every enrolment, including those of admin console users.

Last updated