DOM Package

Utilities and Errors

Use international phone helpers and handle typed DOM Package errors

Phone number field helper

Use TiquoPhone.createField() on every phone input so international phone numbers are formatted correctly. It adds a country picker with flags, formats the number as the customer types, and validates it for the selected country. It needs DOM Package 1.7.0 or newer.

<input id="phone" type="tel" autocomplete="tel" />
import { TiquoPhone } from '@tiquo/dom-package';

const phoneField = TiquoPhone.createField('#phone', {
  defaultCountry: 'GB', // otherwise the browser's country
  preferredCountries: ['GB', 'US'],
});

// When the form is submitted:
const { e164, countryCode } = phoneField.getValue();
await tiquo.createEnquiry({
  customer: { email, phone: e164, phoneCountry: countryCode },
  enquiry: { type: 'YOUR_ENQUIRY_TYPE_ID', subject: 'Website enquiry' },
});

getValue() returns value (what the input shows), e164 (the normalized number, such as +447911123456, empty until the number is valid), countryCode, and valid. The field also emits a tiquo:phone-change event with the same values. Options include allowedCountries, countryDisplay (flag, code, dial-code, flag-code, or name), and classes for your own styling.

To keep your own markup, pass a container that holds a <select data-tiquo-phone-country> and an <input data-tiquo-phone-number>. The helper fills in the countries without adding elements, which suits React and other frameworks that render the page. Call phoneField.destroy() when the field is removed.

Phone number utilities

TiquoPhone provides static helpers for international phone inputs. You do not need to initialize Tiquo to use them.

import { TiquoPhone } from '@tiquo/dom-package';

const phone = TiquoPhone.buildPhone('GB', '07911 123456');
const result = TiquoPhone.validate(phone);

if (result.valid) {
  console.log(result.normalized); // +447911123456
}
MethodPurpose
normalize(phone)Normalize a number to E.164-style +digits output when possible
validate(phone)Return a detailed validation result including normalized value, detected country, or failure reason
detectCountry(phone)Detect an ISO country code from the international calling code
format(phone)Format an international number for display
getCountries()Return the supported country metadata for building a selector
getDialCode(countryCode)Return the international dial code for an ISO country code
buildPhone(countryCode, nationalNumber)Combine a selected country and national number into normalized international output

getCountries() returns alphabetically sorted records with code, name, dialCode, format, and flag fields. updateProfile() and createEnquiry() also normalize supplied phone numbers before submission, but validating in the form gives the customer earlier feedback.

Typed errors

SDK operations reject with TiquoAuthError when the package can provide a structured code:

import { TiquoAuthError } from '@tiquo/dom-package';

try {
  await tiquo.verifyOTP(email, code);
} catch (error) {
  if (error instanceof TiquoAuthError) {
    console.error(error.code, error.message, error.statusCode);
  } else {
    throw error;
  }
}
PropertyTypeDescription
namestringTiquoAuthError
messagestringHuman-readable failure message
codestringStable SDK error category for application branching
statusCodenumber or undefinedHTTP status when the error came from an API response

Common codes include:

AreaCodes
Setup and authenticationMISSING_PUBLIC_KEY, INVALID_PUBLIC_KEY, OTP_SEND_FAILED, OTP_VERIFY_FAILED, NOT_AUTHENTICATED
Customer dataPROFILE_UPDATE_FAILED, GET_ORDERS_FAILED, GET_BOOKINGS_FAILED, CANCEL_BOOKING_FAILED, GET_RESCHEDULE_OPTIONS_FAILED, RESCHEDULE_BOOKING_FAILED, GET_ENQUIRIES_FAILED, CREATE_ENQUIRY_FAILED
Receipts and ticketsGET_RECEIPT_FAILED, RECEIPT_NOT_AVAILABLE, DOWNLOAD_RECEIPT_FAILED, DOWNLOAD_BOOKING_TICKET_FAILED
Embeds and catalogsCONTAINER_NOT_FOUND, MISSING_CUSTOMER_FLOW_ID, CUSTOMER_FLOW_NOT_FOUND, GET_FLOW_SERVICES_FAILED, GET_FLOW_AVAILABILITY_FAILED, INVALID_AVAILABILITY_REQUEST, INVALID_PARTY_SIZE, MISSING_SERVICE_BOOKING_ID, INVALID_SERVICE_BOOKING_START, MISSING_MEMBERSHIP_PLAN_ID, IFRAME_TOKEN_FAILED
Guest invitationsGUEST_PRE_REGISTRATION_FAILED
Wallet cardsGET_WALLET_CARD_LINKS_FAILED
CompaniesGET_COMPANIES_FAILED, GET_COLLEAGUES_FAILED, NOT_COMPANY_ADMIN

Use code for control flow and present an application-owned, customer-friendly message. Preserve statusCode and the original error in internal diagnostics, but never log access tokens, refresh tokens, or OTP values.

On this page