@tiquo/dom-package 1.1.2 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +166 -2
- package/dist/index.d.mts +181 -9
- package/dist/index.d.ts +181 -9
- package/dist/index.js +540 -16
- package/dist/index.mjs +538 -15
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
* This module handles setting a cross-subdomain cookie that stores customer user IDs.
|
|
5
5
|
* The cookie is shared across all *.tiquo.app subdomains and persists for 1 year.
|
|
6
6
|
*
|
|
7
|
-
* The cookie is NOT set if the user is
|
|
7
|
+
* The cookie is NOT set if the user is a dashboard staff member.
|
|
8
8
|
*/
|
|
9
9
|
/**
|
|
10
|
-
* Check if the current user
|
|
11
|
-
* If they
|
|
10
|
+
* Check if the current user has an active dashboard staff session.
|
|
11
|
+
* If they do, we should NOT set the customer cookie.
|
|
12
12
|
*/
|
|
13
|
-
declare function
|
|
13
|
+
declare function isDashboardSession(): boolean;
|
|
14
14
|
/**
|
|
15
15
|
* Get the list of customer user IDs from the cookie.
|
|
16
16
|
*/
|
|
@@ -18,7 +18,7 @@ declare function getCustomerUserIds(): string[];
|
|
|
18
18
|
/**
|
|
19
19
|
* Add a customer user ID to the cookie.
|
|
20
20
|
* Does nothing if:
|
|
21
|
-
* - The user
|
|
21
|
+
* - The user has an active dashboard staff session
|
|
22
22
|
* - The user ID is already in the cookie
|
|
23
23
|
* - Running in a non-browser environment
|
|
24
24
|
*
|
|
@@ -30,7 +30,7 @@ declare function addCustomerUserId(userId: string): void;
|
|
|
30
30
|
* This fetches the user's email associated with the cookie user IDs.
|
|
31
31
|
* Results are cached for 5 minutes to avoid repeated API calls.
|
|
32
32
|
*
|
|
33
|
-
* @param organizationId - The
|
|
33
|
+
* @param organizationId - The organization ID
|
|
34
34
|
* @returns Promise with email and optional name fields, or null if not found
|
|
35
35
|
*/
|
|
36
36
|
declare function getPrefilledEmailFromCookie(organizationId: string): Promise<{
|
|
@@ -47,7 +47,7 @@ declare function clearCachedEmail(): void;
|
|
|
47
47
|
* Track customer presence when the cookie is detected.
|
|
48
48
|
* This updates the customer's online status and logs activity.
|
|
49
49
|
*
|
|
50
|
-
* @param organizationId - The
|
|
50
|
+
* @param organizationId - The organization ID
|
|
51
51
|
* @returns Promise with tracking results
|
|
52
52
|
*/
|
|
53
53
|
declare function trackCustomerPresence(organizationId: string): Promise<{
|
|
@@ -61,6 +61,109 @@ declare function trackCustomerPresence(organizationId: string): Promise<{
|
|
|
61
61
|
error?: string;
|
|
62
62
|
}>;
|
|
63
63
|
|
|
64
|
+
/**
|
|
65
|
+
* @tiquo/dom-package - Phone Utilities
|
|
66
|
+
*
|
|
67
|
+
* Comprehensive phone number validation, normalization, and formatting
|
|
68
|
+
* with worldwide country code support. Designed for use in websites
|
|
69
|
+
* that integrate the Tiquo DOM package.
|
|
70
|
+
*/
|
|
71
|
+
interface CountryPhoneInfo {
|
|
72
|
+
/** ISO 3166-1 alpha-2 code (e.g. "US", "GB") */
|
|
73
|
+
code: string;
|
|
74
|
+
/** Country name */
|
|
75
|
+
name: string;
|
|
76
|
+
/** Dial code with + prefix (e.g. "+1", "+44") */
|
|
77
|
+
dialCode: string;
|
|
78
|
+
/** Example format (e.g. "(XXX) XXX-XXXX") */
|
|
79
|
+
format: string;
|
|
80
|
+
/** Flag emoji */
|
|
81
|
+
flag: string;
|
|
82
|
+
}
|
|
83
|
+
interface PhoneValidationResult {
|
|
84
|
+
/** Whether the phone number is valid for submission */
|
|
85
|
+
valid: boolean;
|
|
86
|
+
/** Normalized E.164 format if valid (e.g. "+15551234567") */
|
|
87
|
+
normalized?: string;
|
|
88
|
+
/** Detected country code if identifiable */
|
|
89
|
+
countryCode?: string;
|
|
90
|
+
/** Reason for invalid result */
|
|
91
|
+
reason?: string;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Normalize a phone number to E.164 format (+digits).
|
|
95
|
+
* Handles all worldwide formats: international prefixes, domestic leading zeros,
|
|
96
|
+
* formatting characters, (0) patterns, 00-prefix, Unicode artifacts.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* normalizePhone("+1 (555) 456-7890") // → "+15554567890"
|
|
100
|
+
* normalizePhone("+44 (0)20 3227 4972") // → "+442032274972"
|
|
101
|
+
* normalizePhone("0033 6 65 08 50 44") // → "+33665085044"
|
|
102
|
+
* normalizePhone("+49 0151 12345678") // → "+4915112345678"
|
|
103
|
+
*/
|
|
104
|
+
declare function normalizePhone(phone: string): string;
|
|
105
|
+
/**
|
|
106
|
+
* Validate a phone number and return detailed results.
|
|
107
|
+
* Checks format, length, and country code presence.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* validatePhone("+15554567890") // → { valid: true, normalized: "+15554567890", countryCode: "US" }
|
|
111
|
+
* validatePhone("555-1234") // → { valid: false, reason: "Phone number must include a country code..." }
|
|
112
|
+
* validatePhone("+44 7911 123456") // → { valid: true, normalized: "+447911123456", countryCode: "GB" }
|
|
113
|
+
*/
|
|
114
|
+
declare function validatePhone(phone: string): PhoneValidationResult;
|
|
115
|
+
/**
|
|
116
|
+
* Detect the country from a phone number's calling code.
|
|
117
|
+
* Returns the ISO 3166-1 alpha-2 country code, or null if unrecognized.
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* detectCountry("+15554567890") // → "US"
|
|
121
|
+
* detectCountry("+447911123456") // → "GB"
|
|
122
|
+
* detectCountry("+33665085044") // → "FR"
|
|
123
|
+
*/
|
|
124
|
+
declare function detectCountry(phone: string): string | null;
|
|
125
|
+
/**
|
|
126
|
+
* Format a phone number for display using country-specific patterns.
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* formatPhone("+15554567890") // → "+1 (555) 456-7890"
|
|
130
|
+
* formatPhone("+447911123456") // → "+44 7911 123456"
|
|
131
|
+
* formatPhone("+33665085044") // → "+33 6 65 08 50 44"
|
|
132
|
+
*/
|
|
133
|
+
declare function formatPhone(phone: string): string;
|
|
134
|
+
/**
|
|
135
|
+
* Get the full list of countries with phone info for building UI selectors.
|
|
136
|
+
* Returns countries sorted alphabetically by name.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* const countries = getCountries();
|
|
140
|
+
* // Build a <select> dropdown:
|
|
141
|
+
* countries.forEach(c => {
|
|
142
|
+
* // c.code = "GB", c.name = "United Kingdom", c.dialCode = "+44",
|
|
143
|
+
* // c.format = "XXXX XXXXXX", c.flag = "🇬🇧"
|
|
144
|
+
* });
|
|
145
|
+
*/
|
|
146
|
+
declare function getCountries(): CountryPhoneInfo[];
|
|
147
|
+
/**
|
|
148
|
+
* Get the dial code for a specific country.
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* getDialCode("US") // → "+1"
|
|
152
|
+
* getDialCode("GB") // → "+44"
|
|
153
|
+
* getDialCode("FR") // → "+33"
|
|
154
|
+
*/
|
|
155
|
+
declare function getDialCode(countryCode: string): string | null;
|
|
156
|
+
/**
|
|
157
|
+
* Build a full E.164 phone number from a country code and national number.
|
|
158
|
+
* Strips the domestic leading zero if present.
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* buildPhone("GB", "07911 123456") // → "+447911123456"
|
|
162
|
+
* buildPhone("US", "(555) 456-7890") // → "+15554567890"
|
|
163
|
+
* buildPhone("FR", "06 65 08 50 44") // → "+33665085044"
|
|
164
|
+
*/
|
|
165
|
+
declare function buildPhone(countryCode: string, nationalNumber: string): string | null;
|
|
166
|
+
|
|
64
167
|
/**
|
|
65
168
|
* @tiquo/dom-package
|
|
66
169
|
*
|
|
@@ -190,9 +293,21 @@ interface ProfileUpdateData {
|
|
|
190
293
|
firstName?: string;
|
|
191
294
|
lastName?: string;
|
|
192
295
|
displayName?: string;
|
|
296
|
+
/**
|
|
297
|
+
* Primary phone number in E.164 format: +[country code][number]
|
|
298
|
+
* Examples: "+15551234567" (US), "+447911123456" (UK), "+33665085044" (FR)
|
|
299
|
+
*
|
|
300
|
+
* The SDK auto-normalizes common formats (strips spaces, dashes, parentheses,
|
|
301
|
+
* handles +/00 prefixes). Use TiquoPhone.buildPhone("GB", "07911 123456")
|
|
302
|
+
* for country+national input, or TiquoPhone.validate() to pre-check.
|
|
303
|
+
*/
|
|
193
304
|
phone?: string;
|
|
194
305
|
profilePhoto?: string;
|
|
195
306
|
emails?: TiquoCustomerEmail[];
|
|
307
|
+
/**
|
|
308
|
+
* Full phone list. Each number should be in E.164 format: +[country code][number].
|
|
309
|
+
* The SDK auto-normalizes all numbers before sending to the API.
|
|
310
|
+
*/
|
|
196
311
|
phones?: TiquoCustomerPhone[];
|
|
197
312
|
}
|
|
198
313
|
interface ProfileUpdateResult {
|
|
@@ -324,7 +439,12 @@ declare class TiquoAuth {
|
|
|
324
439
|
isAuthenticated(): boolean;
|
|
325
440
|
/**
|
|
326
441
|
* Update the authenticated customer's profile
|
|
327
|
-
* Only allows updating the logged-in customer's own data
|
|
442
|
+
* Only allows updating the logged-in customer's own data.
|
|
443
|
+
*
|
|
444
|
+
* Phone numbers are automatically normalized to E.164 format (+digits).
|
|
445
|
+
* For best results, include a country code: "+1 (555) 456-7890" or "+44 7911 123456".
|
|
446
|
+
* Use TiquoPhone.validate() to check before submitting, or TiquoPhone.buildPhone()
|
|
447
|
+
* to construct from a country selector and national number.
|
|
328
448
|
*/
|
|
329
449
|
updateProfile(updates: ProfileUpdateData): Promise<ProfileUpdateResult>;
|
|
330
450
|
/**
|
|
@@ -438,5 +558,57 @@ declare function useTiquoAuth(auth: TiquoAuth): {
|
|
|
438
558
|
}) => Promise<HTMLIFrameElement>;
|
|
439
559
|
onAuthStateChange: (cb: AuthStateChangeCallback) => () => void;
|
|
440
560
|
};
|
|
561
|
+
/**
|
|
562
|
+
* Phone number utilities for building phone inputs and validating numbers.
|
|
563
|
+
* All methods are static — no instantiation needed.
|
|
564
|
+
*
|
|
565
|
+
* @example
|
|
566
|
+
* ```typescript
|
|
567
|
+
* import { TiquoPhone } from '@tiquo/dom-package';
|
|
568
|
+
*
|
|
569
|
+
* // Get countries for a selector dropdown
|
|
570
|
+
* const countries = TiquoPhone.getCountries();
|
|
571
|
+
*
|
|
572
|
+
* // Build a phone number from country + national number
|
|
573
|
+
* const phone = TiquoPhone.buildPhone("GB", "07911 123456");
|
|
574
|
+
* // → "+447911123456"
|
|
575
|
+
*
|
|
576
|
+
* // Validate before submitting
|
|
577
|
+
* const result = TiquoPhone.validate("+44 7911 123456");
|
|
578
|
+
* // → { valid: true, normalized: "+447911123456", countryCode: "GB" }
|
|
579
|
+
*
|
|
580
|
+
* // Normalize for submission
|
|
581
|
+
* const e164 = TiquoPhone.normalize("+1 (555) 456-7890");
|
|
582
|
+
* // → "+15554567890"
|
|
583
|
+
*
|
|
584
|
+
* // Format for display
|
|
585
|
+
* const display = TiquoPhone.format("+15554567890");
|
|
586
|
+
* // → "+1 (555) 456-7890"
|
|
587
|
+
*
|
|
588
|
+
* // Detect country from a phone number
|
|
589
|
+
* const country = TiquoPhone.detectCountry("+33665085044");
|
|
590
|
+
* // → "FR"
|
|
591
|
+
*
|
|
592
|
+
* // Get dial code for a country
|
|
593
|
+
* const dialCode = TiquoPhone.getDialCode("US");
|
|
594
|
+
* // → "+1"
|
|
595
|
+
* ```
|
|
596
|
+
*/
|
|
597
|
+
declare class TiquoPhone {
|
|
598
|
+
/** Normalize a phone number to E.164 format (+digits). */
|
|
599
|
+
static normalize: typeof normalizePhone;
|
|
600
|
+
/** Validate a phone number with detailed result. */
|
|
601
|
+
static validate: typeof validatePhone;
|
|
602
|
+
/** Detect the country from a phone number's calling code. */
|
|
603
|
+
static detectCountry: typeof detectCountry;
|
|
604
|
+
/** Format a phone number for display using country-specific patterns. */
|
|
605
|
+
static format: typeof formatPhone;
|
|
606
|
+
/** Get the full list of countries with phone info for building UI selectors. */
|
|
607
|
+
static getCountries: typeof getCountries;
|
|
608
|
+
/** Get the dial code for a specific country (e.g. "US" → "+1"). */
|
|
609
|
+
static getDialCode: typeof getDialCode;
|
|
610
|
+
/** Build an E.164 phone number from a country code and national number. */
|
|
611
|
+
static buildPhone: typeof buildPhone;
|
|
612
|
+
}
|
|
441
613
|
|
|
442
|
-
export { type AuthStateChangeCallback, type GetBookingsOptions, type GetBookingsResult, type GetEnquiriesOptions, type GetEnquiriesResult, type GetOrdersOptions, type GetOrdersResult, type IframeTokenResult, type ProfileUpdateData, type ProfileUpdateResult, type SendOTPResult, TiquoAuth, type TiquoAuthConfig, TiquoAuthError, type TiquoBooking, type TiquoCustomer, type TiquoCustomerEmail, type TiquoCustomerPhone, type TiquoEnquiry, type TiquoOrder, type TiquoOrderItem, type TiquoSession, type TiquoUser, type VerifyOTPResult, addCustomerUserId, clearCachedEmail, TiquoAuth as default, getCustomerUserIds, getPrefilledEmailFromCookie,
|
|
614
|
+
export { type AuthStateChangeCallback, type CountryPhoneInfo, type GetBookingsOptions, type GetBookingsResult, type GetEnquiriesOptions, type GetEnquiriesResult, type GetOrdersOptions, type GetOrdersResult, type IframeTokenResult, type PhoneValidationResult, type ProfileUpdateData, type ProfileUpdateResult, type SendOTPResult, TiquoAuth, type TiquoAuthConfig, TiquoAuthError, type TiquoBooking, type TiquoCustomer, type TiquoCustomerEmail, type TiquoCustomerPhone, type TiquoEnquiry, type TiquoOrder, type TiquoOrderItem, TiquoPhone, type TiquoSession, type TiquoUser, type VerifyOTPResult, addCustomerUserId, clearCachedEmail, TiquoAuth as default, getCustomerUserIds, getPrefilledEmailFromCookie, isDashboardSession, trackCustomerPresence, useTiquoAuth };
|