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
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 |
|---|---|---|
|
| The |
Returns: Promise<CustomerAuthResult>
// 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
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 |
|---|---|---|
|
| Recipient and postal fields, plus the optional label, contact, default flags and metadata. |
|
| Optional anti-spam values ( |
Returns: Promise<CustomerAddress>
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
addresses.list(): Promise<CustomerAddress[]>Lists every saved address of the signed-in buyer, following all pages. Never cached.
Returns: Promise<CustomerAddress[]>
const addresses = await lynkow.customers.addresses.list()
const shipping = addresses.find((a) => a.isDefaultShipping)addresses.remove
addresses.remove(id: string, options?: CustomerSpamOptions): Promise<void>Deletes one address of the signed-in buyer.
Parameter | Type | Description |
|---|---|---|
|
| The |
|
| Optional anti-spam values ( |
Returns: Promise<void>
await lynkow.customers.addresses.remove('addr_123')addresses.update
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 |
|---|---|---|
|
| The |
|
| The address fields to change. |
|
| Optional anti-spam values ( |
Returns: Promise<CustomerAddress>
await lynkow.customers.addresses.update('addr_123', { isDefaultBilling: true })
const addresses = await lynkow.customers.addresses.list() // the previous default is unsetmarketingConsent.list
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>
const { channels } = await lynkow.customers.marketingConsent.list()
const emailOptIn = channels.find((c) => c.channel === 'email')?.optedIn ?? falsemarketingConsent.update
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 |
|---|---|---|
|
|
|
Returns: Promise<MarketingConsentList>
await lynkow.customers.marketingConsent.update({ channel: 'email', optIn: false })passwordReset.confirm
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 |
|---|---|---|
|
| The |
Returns: Promise<void>
// 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
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 |
|---|---|---|
|
| The |
|
|
|
Returns: Promise<void>
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
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 |
|---|---|---|
|
| CustomerLoginInput: |
Returns: Promise<CustomerAuthResult>
const { customer, token } = await lynkow.customers.login({
email: '[email protected]',
password: 'a-strong-passphrase',
})
saveToken(token)logout
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 |
|---|---|---|
|
| Optional CustomerLogoutOptions: |
Returns: Promise<void>
await lynkow.customers.logout() // discard the token on this client only
await lynkow.customers.logout({ everywhere: true }) // also revoke all sessions server-sideme
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>
const { customer, bookings } = await lynkow.customers.me()
for (const booking of bookings) {
console.log(`${booking.reference}: ${booking.status} at ${booking.startsAt}`)
}order
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 |
|---|---|---|
|
| The order's |
Returns: Promise<Order>
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
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 |
|---|---|---|
|
| Optional CustomerOrderListParams: |
Returns: Promise<CustomerOrderList>
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.lastPageregister
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 |
|---|---|---|
|
| CustomerRegisterInput: the |
|
| Optional CustomerSpamOptions: |
Returns: Promise<void>
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
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 |
|---|---|---|
|
| Optional request options. |
Returns: Promise<void>
await lynkow.customers.resendVerification({ locale: 'fr' })updateMe
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 |
|---|---|---|
|
| CustomerProfileUpdateInput: |
Returns: Promise<Customer>
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
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 |
|---|---|---|
|
| The token from the verification link. |
Returns: Promise<CustomerEmailVerificationResult>
await lynkow.customers.verifyEmail(tokenFromEmailLink)