Buyer accounts: two-step signup (register, then activation.confirm), login, profile, bookings and order history, plus the activation, passwordReset, addresses and marketingConsent sub-objects. Requires publishableKey.

login and activation.confirm keep the session token in client memory and send it as a Bearer header on account and booking calls; logout clears it. The SDK never persists it: save it yourself and pass it back with createClient({ customerToken }). Throws NOT_FOUND when customer accounts are not enabled on the site.

Access via: lynkow.customers

Methods

18 methods

activation.confirm

TypeScript
activation.confirm(input: CustomerActivationConfirmInput): Promise<CustomerAuthResult>

Step 2 of signing up: completes the account with the single-use token from the activation email, keeps the session token on the client and signs the buyer in.

Parameter

Type

Description

input

CustomerActivationConfirmInput

The token from the link, the password, acceptsTerms: true, and the optional profile and consent fields.

Returns: Promise<CustomerAuthResult>

TypeScript
// On the page the activation link opens, e.g. /account/activate/[token]
const { customer } = await lynkow.customers.activation.confirm({
  token: params.token,
  password: form.password,
  acceptsTerms: true,
  firstName: 'Alice',
})

addresses.create

TypeScript
addresses.create(input: CustomerAddressInput, options?: CustomerSpamOptions): Promise<CustomerAddress>

Saves an address for the signed-in buyer. Setting a default unsets the previous one.

Parameter

Type

Description

input

CustomerAddressInput

Recipient and postal fields, plus the optional label, contact, default flags and metadata.

options

CustomerSpamOptions

Optional anti-spam values (formStartedAt, recaptchaToken) and request options.

Returns: Promise<CustomerAddress>

TypeScript
const address = await lynkow.customers.addresses.create({
  firstName: 'Alice',
  lastName: 'Martin',
  address1: '12 rue de la Paix',
  city: 'Paris',
  postalCode: '75002',
  countryCode: 'FR',
  isDefaultShipping: true,
})

addresses.list

TypeScript
addresses.list(): Promise<CustomerAddress[]>

Lists every saved address of the signed-in buyer, following all pages. Never cached.

Returns: Promise<CustomerAddress[]>

TypeScript
const addresses = await lynkow.customers.addresses.list()
const shipping = addresses.find((a) => a.isDefaultShipping)

addresses.remove

TypeScript
addresses.remove(id: string, options?: CustomerSpamOptions): Promise<void>

Deletes one address of the signed-in buyer.

Parameter

Type

Description

id

string

The addr_... id of the address.

options

CustomerSpamOptions

Optional anti-spam values (formStartedAt, recaptchaToken) and request options.

Returns: Promise<void>

TypeScript
await lynkow.customers.addresses.remove('addr_123')

addresses.update

TypeScript
addresses.update(id: string, input: CustomerAddressUpdateInput, options?: CustomerSpamOptions): Promise<CustomerAddress>

Partially edits one address of the signed-in buyer. Re-read list() after setting a default, since the previous default is unset.

Parameter

Type

Description

id

string

The addr_... id of the address.

input

CustomerAddressUpdateInput

The address fields to change.

options

CustomerSpamOptions

Optional anti-spam values (formStartedAt, recaptchaToken) and request options.

Returns: Promise<CustomerAddress>

TypeScript
await lynkow.customers.addresses.update('addr_123', { isDefaultBilling: true })
const addresses = await lynkow.customers.addresses.list() // the previous default is unset

marketingConsent.list

TypeScript
marketingConsent.list(): Promise<MarketingConsentList>

Lists the buyer's marketing consent, one entry per channel; a channel with no record reads false. Requires a stored session token.

Returns: Promise<MarketingConsentList>

TypeScript
const { channels } = await lynkow.customers.marketingConsent.list()
const emailOptIn = channels.find((c) => c.channel === 'email')?.optedIn ?? false

marketingConsent.update

TypeScript
marketingConsent.update(input: MarketingConsentUpdateInput): Promise<MarketingConsentList>

Updates the buyer's marketing consent for one channel, or every channel with channel: 'all'. Requires a stored session token.

Parameter

Type

Description

input

MarketingConsentUpdateInput

channel (a channel or 'all') and optIn.

Returns: Promise<MarketingConsentList>

TypeScript
await lynkow.customers.marketingConsent.update({ channel: 'email', optIn: false })

passwordReset.confirm

TypeScript
passwordReset.confirm(input: PasswordResetConfirmInput): Promise<void>

Sets a new password with the single-use token from the reset email. Earlier session tokens stop working, and the buyer then logs in with the new password.

Parameter

Type

Description

input

PasswordResetConfirmInput

The token and the new password.

Returns: Promise<void>

TypeScript
// On the page the reset link opens
await lynkow.customers.passwordReset.confirm({ token: params.token, password: form.password })
await lynkow.customers.login({ email: form.email, password: form.password })

passwordReset.request

TypeScript
passwordReset.request(input: PasswordResetRequestInput, options?: CustomerSpamOptions): Promise<void>

Requests a password-reset link for an account email. Resolves the same way whether or not the email is registered. Adds the anti-spam fields; no session token is required.

Parameter

Type

Description

input

PasswordResetRequestInput

The email to send a reset link to.

options

CustomerSpamOptions

formStartedAt, recaptchaToken (v3 action password_reset_request), locale and fetchOptions.

Returns: Promise<void>

TypeScript
await lynkow.customers.passwordReset.request({ email: '[email protected]' })
// Same message on every outcome: never branch on whether the email is known.
show('If this address has an account, a reset link is on its way.')

login

TypeScript
login(input: CustomerLoginInput): Promise<CustomerAuthResult>

Signs a buyer in with email and password, keeps the session token on the client and resolves to { customer, token }. Save token yourself to keep the buyer signed in across reloads. Throws LynkowError UNAUTHORIZED with apiCode CUSTOMER_AUTH_REQUIRED for every failed sign-in (unknown email, wrong password, account not activated), and TOO_MANY_REQUESTS with RATE_LIMIT_EXCEEDED after five failed attempts for one email.

Parameter

Type

Description

input

CustomerLoginInput

CustomerLoginInput: email and password.

Returns: Promise<CustomerAuthResult>

TypeScript
const { customer, token } = await lynkow.customers.login({
  email: '[email protected]',
  password: 'a-strong-passphrase',
})
saveToken(token)

logout

TypeScript
logout(options?: CustomerLogoutOptions): Promise<void>

Signs the buyer out on this client by clearing the stored session token, with no request. With { everywhere: true } it first revokes every session token of the buyer on the server, and clears the local token even when that call fails. Throws LynkowError UNAUTHORIZED with everywhere when no token is stored or the server rejects it (apiCode CUSTOMER_AUTH_REQUIRED).

Parameter

Type

Description

options

CustomerLogoutOptions

Optional CustomerLogoutOptions: everywhere to revoke every session on the server.

Returns: Promise<void>

TypeScript
await lynkow.customers.logout() // discard the token on this client only
await lynkow.customers.logout({ everywhere: true }) // also revoke all sessions server-side

me

TypeScript
me(): Promise<CustomerSession>

Fetches the signed-in buyer and up to 100 of their bookings, latest start first. Until the email is verified, only bookings made while signed in are listed. Requires a stored session token. Throws LynkowError UNAUTHORIZED, before any request when no token is stored, or with apiCode CUSTOMER_AUTH_REQUIRED when the server rejects the session.

Returns: Promise<CustomerSession>

TypeScript
const { customer, bookings } = await lynkow.customers.me()
for (const booking of bookings) {
  console.log(`${booking.reference}: ${booking.status} at ${booking.startsAt}`)
}

order

TypeScript
order(id: string): Promise<Order>

Fetches one of the signed-in buyer's orders by its ord_... id. Requires a stored session token. Throws LynkowError NOT_FOUND with apiCode ORDER_NOT_FOUND when no such order belongs to the buyer on this site or the site does not offer order history, VALIDATION_ERROR when id is not an order id, and UNAUTHORIZED (CUSTOMER_AUTH_REQUIRED) without a valid session.

Parameter

Type

Description

id

string

The order's ord_... id (Order.id).

Returns: Promise<Order>

TypeScript
try {
  const order = await lynkow.customers.order('ord_...')
  console.log(order.orderNumber, order.status, order.items.length)
} catch (err) {
  if (isLynkowError(err) && err.apiCode === 'ORDER_NOT_FOUND') {
    // Not this buyer's order, or it no longer exists.
  }
}

orders

TypeScript
orders(params?: CustomerOrderListParams): Promise<CustomerOrderList>

Lists the signed-in buyer's orders on this site, newest first, one page at a time. Cancelled orders are included. Requires a stored session token. Throws LynkowError UNAUTHORIZED (apiCode CUSTOMER_AUTH_REQUIRED) without a valid session, VALIDATION_ERROR for an out-of-range page or limit, and NOT_FOUND with ORDER_NOT_FOUND when the site does not offer order history.

Parameter

Type

Description

params

CustomerOrderListParams

Optional CustomerOrderListParams: page (from 1) and limit (1 to 100, default 20).

Returns: Promise<CustomerOrderList>

TypeScript
const { data: orders, meta } = await lynkow.customers.orders({ page: 1, limit: 10 })
for (const order of orders) {
  console.log(`#${order.orderNumber}: ${order.status}, ${order.totalCents} ${order.currency}`)
}
const hasMore = meta.currentPage < meta.lastPage

register

TypeScript
register(input: CustomerRegisterInput, options?: CustomerSpamOptions): Promise<void>

Starts signup by emailing an activation link to email. It creates no session: the buyer finishes with activation.confirm on the page the link opens, where the password, terms and profile are collected. Resolves the same way whether or not the address has an account, so show one message either way. Anti-spam fields are added for you; on a reCAPTCHA-protected site pass options.recaptchaToken (action customer_register). Throws LynkowError VALIDATION_ERROR for a malformed email, TOO_MANY_REQUESTS with apiCode RATE_SUBMISSION_TOO_FAST, and BAD_REQUEST with RATE_SUBMISSION_EXPIRED, SPAM_RECAPTCHA_REQUIRED or SPAM_RECAPTCHA_FAILED.

Parameter

Type

Description

input

CustomerRegisterInput

CustomerRegisterInput: the email to send the link to. Only email is sent.

options

CustomerSpamOptions

Optional CustomerSpamOptions: recaptchaToken, formStartedAt, and a locale hint for the email language.

Returns: Promise<void>

TypeScript
await lynkow.customers.register({ email: '[email protected]' })
// Same message on every outcome: never branch on whether the email is known.
show('Check your inbox. If this address can be registered, a link is on its way.')

resendVerification

TypeScript
resendVerification(options?: BaseRequestOptions): Promise<void>

Kept for compatibility: resolves without sending an email, because every signed-in buyer already has a verified address. Requires a stored session token. Throws LynkowError UNAUTHORIZED, before any request when no token is stored, or with apiCode CUSTOMER_AUTH_REQUIRED when the server rejects the session.

Parameter

Type

Description

options

BaseRequestOptions

Optional request options. locale is sent but has no effect.

Returns: Promise<void>

TypeScript
await lynkow.customers.resendVerification({ locale: 'fr' })

updateMe

TypeScript
updateMe(input: CustomerProfileUpdateInput): Promise<Customer>

Sets the signed-in buyer's preferred language, used for account emails, and resolves to the updated Customer. Any language tag is accepted and stored normalized ('pt_br' becomes 'pt-BR'). null or '' clears it, and the site's default language then applies. Throws LynkowError UNAUTHORIZED (apiCode CUSTOMER_AUTH_REQUIRED) without a valid session, FORBIDDEN with CUSTOMER_EMAIL_NOT_VERIFIED before the email is verified, and VALIDATION_ERROR for a missing key or an invalid tag.

Parameter

Type

Description

input

CustomerProfileUpdateInput

CustomerProfileUpdateInput: preferredLocale, a language tag or null. The key is required.

Returns: Promise<Customer>

TypeScript
const profile = await lynkow.customers.updateMe({ preferredLocale: 'pt' })
console.log(profile.preferredLocale) // 'pt'

// Back to the site's default language.
await lynkow.customers.updateMe({ preferredLocale: null })

verifyEmail

TypeScript
verifyEmail(token: string): Promise<CustomerEmailVerificationResult>

Confirms a buyer's email address with the single-use token from a verification email. activation.confirm already verifies the address, so accounts created through signup do not need this call. It does not sign the buyer in. Throws LynkowError BAD_REQUEST with apiCode VERIFICATION_LINK_INVALID for an invalid, expired or used token.

Parameter

Type

Description

token

string

The token from the verification link.

Returns: Promise<CustomerEmailVerificationResult>

TypeScript
await lynkow.customers.verifyEmail(tokenFromEmailLink)