@tiquo/dom-package 1.0.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 +498 -0
- package/dist/index.d.mts +323 -0
- package/dist/index.d.ts +323 -0
- package/dist/index.js +637 -0
- package/dist/index.mjs +610 -0
- package/package.json +60 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @tiquo/dom-package
|
|
3
|
+
*
|
|
4
|
+
* Customer authentication SDK for third-party websites using Tiquo.
|
|
5
|
+
* Enables email OTP authentication without passwords.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { TiquoAuth } from '@tiquo/dom-package';
|
|
10
|
+
*
|
|
11
|
+
* const auth = new TiquoAuth({
|
|
12
|
+
* publicKey: 'pk_dom_xxxxx'
|
|
13
|
+
* });
|
|
14
|
+
*
|
|
15
|
+
* // Send OTP
|
|
16
|
+
* await auth.sendOTP('user@example.com');
|
|
17
|
+
*
|
|
18
|
+
* // Verify OTP
|
|
19
|
+
* const result = await auth.verifyOTP('user@example.com', '123456');
|
|
20
|
+
*
|
|
21
|
+
* // Get current user
|
|
22
|
+
* const user = await auth.getUser();
|
|
23
|
+
*
|
|
24
|
+
* // Logout
|
|
25
|
+
* await auth.logout();
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
interface TiquoAuthConfig {
|
|
29
|
+
/** Public key from your Tiquo Auth DOM settings */
|
|
30
|
+
publicKey: string;
|
|
31
|
+
/** API endpoint (defaults to production) */
|
|
32
|
+
apiEndpoint?: string;
|
|
33
|
+
/** Storage key prefix for session data */
|
|
34
|
+
storagePrefix?: string;
|
|
35
|
+
/** Enable debug logging */
|
|
36
|
+
debug?: boolean;
|
|
37
|
+
/** Enable multi-tab session sync via BroadcastChannel (default: true) */
|
|
38
|
+
enableTabSync?: boolean;
|
|
39
|
+
}
|
|
40
|
+
interface TiquoUser {
|
|
41
|
+
id: string;
|
|
42
|
+
email: string;
|
|
43
|
+
}
|
|
44
|
+
interface TiquoCustomer {
|
|
45
|
+
id: string;
|
|
46
|
+
firstName?: string;
|
|
47
|
+
lastName?: string;
|
|
48
|
+
displayName?: string;
|
|
49
|
+
customerNumber: string;
|
|
50
|
+
email?: string;
|
|
51
|
+
phone?: string;
|
|
52
|
+
}
|
|
53
|
+
interface TiquoSession {
|
|
54
|
+
user: TiquoUser;
|
|
55
|
+
customer: TiquoCustomer | null;
|
|
56
|
+
expiresAt: number;
|
|
57
|
+
}
|
|
58
|
+
interface SendOTPResult {
|
|
59
|
+
success: boolean;
|
|
60
|
+
message: string;
|
|
61
|
+
}
|
|
62
|
+
interface VerifyOTPResult {
|
|
63
|
+
success: boolean;
|
|
64
|
+
sessionToken: string;
|
|
65
|
+
expiresAt: number;
|
|
66
|
+
isNewUser: boolean;
|
|
67
|
+
hasCustomer: boolean;
|
|
68
|
+
}
|
|
69
|
+
interface IframeTokenResult {
|
|
70
|
+
token: string;
|
|
71
|
+
expiresAt: number;
|
|
72
|
+
}
|
|
73
|
+
interface ProfileUpdateData {
|
|
74
|
+
firstName?: string;
|
|
75
|
+
lastName?: string;
|
|
76
|
+
displayName?: string;
|
|
77
|
+
phone?: string;
|
|
78
|
+
profilePhoto?: string;
|
|
79
|
+
}
|
|
80
|
+
interface ProfileUpdateResult {
|
|
81
|
+
success: boolean;
|
|
82
|
+
customer: TiquoCustomer & {
|
|
83
|
+
profilePhoto?: string;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
interface TiquoOrderItem {
|
|
87
|
+
id: string;
|
|
88
|
+
name: string;
|
|
89
|
+
quantity: number;
|
|
90
|
+
unitPrice: number;
|
|
91
|
+
total: number;
|
|
92
|
+
type: 'product' | 'booking' | 'custom';
|
|
93
|
+
}
|
|
94
|
+
interface TiquoOrder {
|
|
95
|
+
id: string;
|
|
96
|
+
orderNumber: string;
|
|
97
|
+
status: 'draft' | 'pending' | 'confirmed' | 'processing' | 'completed' | 'cancelled' | 'refunded' | 'open_tab';
|
|
98
|
+
paymentStatus: 'pending' | 'paid' | 'partial' | 'refunded' | 'failed' | 'cancelled';
|
|
99
|
+
total: number;
|
|
100
|
+
subtotal: number;
|
|
101
|
+
taxTotal: number;
|
|
102
|
+
discountTotal: number;
|
|
103
|
+
items: TiquoOrderItem[];
|
|
104
|
+
createdAt: number;
|
|
105
|
+
completedAt?: number;
|
|
106
|
+
customerRole: 'primary' | 'attendee' | 'recipient' | 'billing' | 'guest' | 'other';
|
|
107
|
+
}
|
|
108
|
+
interface GetOrdersOptions {
|
|
109
|
+
limit?: number;
|
|
110
|
+
cursor?: string;
|
|
111
|
+
status?: TiquoOrder['status'];
|
|
112
|
+
}
|
|
113
|
+
interface GetOrdersResult {
|
|
114
|
+
orders: TiquoOrder[];
|
|
115
|
+
hasMore: boolean;
|
|
116
|
+
nextCursor?: string;
|
|
117
|
+
}
|
|
118
|
+
interface TiquoBooking {
|
|
119
|
+
id: string;
|
|
120
|
+
bookingNumber: string;
|
|
121
|
+
confirmationCode: string;
|
|
122
|
+
status: 'draft' | 'scheduled' | 'confirmed' | 'reminder_sent' | 'waiting_room' | 'waiting_list' | 'checked_in' | 'active' | 'in_progress' | 'completed' | 'cancelled' | 'no_show' | 'rescheduled';
|
|
123
|
+
date: number;
|
|
124
|
+
startTime: string;
|
|
125
|
+
endTime: string;
|
|
126
|
+
duration: number;
|
|
127
|
+
timezone: string;
|
|
128
|
+
attendeeCount: number;
|
|
129
|
+
serviceName: string;
|
|
130
|
+
serviceId: string;
|
|
131
|
+
sublocationId: string;
|
|
132
|
+
customerNotes?: string;
|
|
133
|
+
createdAt: number;
|
|
134
|
+
checkedInAt?: number;
|
|
135
|
+
completedAt?: number;
|
|
136
|
+
cancelledAt?: number;
|
|
137
|
+
}
|
|
138
|
+
interface GetBookingsOptions {
|
|
139
|
+
limit?: number;
|
|
140
|
+
cursor?: string;
|
|
141
|
+
status?: TiquoBooking['status'];
|
|
142
|
+
upcoming?: boolean;
|
|
143
|
+
}
|
|
144
|
+
interface GetBookingsResult {
|
|
145
|
+
bookings: TiquoBooking[];
|
|
146
|
+
hasMore: boolean;
|
|
147
|
+
nextCursor?: string;
|
|
148
|
+
}
|
|
149
|
+
interface TiquoEnquiry {
|
|
150
|
+
id: string;
|
|
151
|
+
enquiryNumber: string;
|
|
152
|
+
type: string;
|
|
153
|
+
subject: string;
|
|
154
|
+
message: string;
|
|
155
|
+
category: string;
|
|
156
|
+
status: 'new' | 'in_progress' | 'waiting_customer' | 'waiting_internal' | 'won' | 'lost' | 'closed' | 'resolved' | 'archived';
|
|
157
|
+
priority: 'low' | 'medium' | 'high' | 'urgent';
|
|
158
|
+
source: 'online' | 'website' | 'phone' | 'email' | 'walk_in' | 'social' | 'referral' | 'pos' | 'admin';
|
|
159
|
+
responseCount: number;
|
|
160
|
+
createdAt: string;
|
|
161
|
+
updatedAt: string;
|
|
162
|
+
firstResponseAt?: string;
|
|
163
|
+
resolvedAt?: string;
|
|
164
|
+
customerRole: 'primary' | 'interested' | 'decision_maker' | 'influencer' | 'referrer' | 'other';
|
|
165
|
+
}
|
|
166
|
+
interface GetEnquiriesOptions {
|
|
167
|
+
limit?: number;
|
|
168
|
+
cursor?: string;
|
|
169
|
+
status?: TiquoEnquiry['status'];
|
|
170
|
+
}
|
|
171
|
+
interface GetEnquiriesResult {
|
|
172
|
+
enquiries: TiquoEnquiry[];
|
|
173
|
+
hasMore: boolean;
|
|
174
|
+
nextCursor?: string;
|
|
175
|
+
}
|
|
176
|
+
type AuthStateChangeCallback = (session: TiquoSession | null) => void;
|
|
177
|
+
declare class TiquoAuthError extends Error {
|
|
178
|
+
code: string;
|
|
179
|
+
statusCode?: number | undefined;
|
|
180
|
+
constructor(message: string, code: string, statusCode?: number | undefined);
|
|
181
|
+
}
|
|
182
|
+
declare class TiquoAuth {
|
|
183
|
+
private config;
|
|
184
|
+
private sessionToken;
|
|
185
|
+
private session;
|
|
186
|
+
private listeners;
|
|
187
|
+
private refreshTimer;
|
|
188
|
+
private broadcastChannel;
|
|
189
|
+
private tabId;
|
|
190
|
+
private isProcessingTabSync;
|
|
191
|
+
constructor(config: TiquoAuthConfig);
|
|
192
|
+
/**
|
|
193
|
+
* Send an OTP verification code to the user's email
|
|
194
|
+
*/
|
|
195
|
+
sendOTP(email: string): Promise<SendOTPResult>;
|
|
196
|
+
/**
|
|
197
|
+
* Verify an OTP code and authenticate the user
|
|
198
|
+
*/
|
|
199
|
+
verifyOTP(email: string, otp: string): Promise<VerifyOTPResult>;
|
|
200
|
+
/**
|
|
201
|
+
* Get the current authenticated user and customer data
|
|
202
|
+
*/
|
|
203
|
+
getUser(): Promise<TiquoSession | null>;
|
|
204
|
+
/**
|
|
205
|
+
* Check if user is currently authenticated
|
|
206
|
+
*/
|
|
207
|
+
isAuthenticated(): boolean;
|
|
208
|
+
/**
|
|
209
|
+
* Update the authenticated customer's profile
|
|
210
|
+
* Only allows updating the logged-in customer's own data
|
|
211
|
+
*/
|
|
212
|
+
updateProfile(updates: ProfileUpdateData): Promise<ProfileUpdateResult>;
|
|
213
|
+
/**
|
|
214
|
+
* Log out the current user
|
|
215
|
+
*/
|
|
216
|
+
logout(): Promise<void>;
|
|
217
|
+
/**
|
|
218
|
+
* Subscribe to authentication state changes
|
|
219
|
+
*/
|
|
220
|
+
onAuthStateChange(callback: AuthStateChangeCallback): () => void;
|
|
221
|
+
/**
|
|
222
|
+
* Get the authenticated customer's order history
|
|
223
|
+
* Only returns orders for the logged-in customer
|
|
224
|
+
*/
|
|
225
|
+
getOrders(options?: GetOrdersOptions): Promise<GetOrdersResult>;
|
|
226
|
+
/**
|
|
227
|
+
* Get the authenticated customer's booking history
|
|
228
|
+
* Only returns bookings for the logged-in customer
|
|
229
|
+
*/
|
|
230
|
+
getBookings(options?: GetBookingsOptions): Promise<GetBookingsResult>;
|
|
231
|
+
/**
|
|
232
|
+
* Get the authenticated customer's enquiry history
|
|
233
|
+
* Only returns enquiries for the logged-in customer
|
|
234
|
+
*/
|
|
235
|
+
getEnquiries(options?: GetEnquiriesOptions): Promise<GetEnquiriesResult>;
|
|
236
|
+
/**
|
|
237
|
+
* Generate a short-lived token for customer flow iframe authentication
|
|
238
|
+
*/
|
|
239
|
+
getIframeToken(customerFlowId?: string): Promise<IframeTokenResult>;
|
|
240
|
+
/**
|
|
241
|
+
* Embed a customer flow with automatic authentication
|
|
242
|
+
*
|
|
243
|
+
* @param flowUrl - The URL of the customer flow (book.tiquo.app/...)
|
|
244
|
+
* @param container - Container element or selector
|
|
245
|
+
* @param options - Optional iframe configuration
|
|
246
|
+
*/
|
|
247
|
+
embedCustomerFlow(flowUrl: string, container: HTMLElement | string, options?: {
|
|
248
|
+
width?: string;
|
|
249
|
+
height?: string;
|
|
250
|
+
onLoad?: () => void;
|
|
251
|
+
onError?: (error: Error) => void;
|
|
252
|
+
}): Promise<HTMLIFrameElement>;
|
|
253
|
+
/**
|
|
254
|
+
* Get the current session token (for advanced use cases)
|
|
255
|
+
*/
|
|
256
|
+
getSessionToken(): string | null;
|
|
257
|
+
private request;
|
|
258
|
+
private refreshSession;
|
|
259
|
+
private saveSession;
|
|
260
|
+
private restoreSession;
|
|
261
|
+
private clearSession;
|
|
262
|
+
private notifyListeners;
|
|
263
|
+
private scheduleRefresh;
|
|
264
|
+
private log;
|
|
265
|
+
private generateTabId;
|
|
266
|
+
private initTabSync;
|
|
267
|
+
private broadcastTabSync;
|
|
268
|
+
private handleTabSyncMessage;
|
|
269
|
+
/**
|
|
270
|
+
* Clean up resources (call when destroying the auth instance)
|
|
271
|
+
*/
|
|
272
|
+
destroy(): void;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* React hook for using TiquoAuth
|
|
276
|
+
* Note: Requires a TiquoAuth instance to be passed in
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
* ```tsx
|
|
280
|
+
* const auth = new TiquoAuth({ publicKey: 'pk_dom_xxx' });
|
|
281
|
+
*
|
|
282
|
+
* function App() {
|
|
283
|
+
* const { user, isLoading, isAuthenticated, logout } = useTiquoAuth(auth);
|
|
284
|
+
*
|
|
285
|
+
* if (isLoading) return <div>Loading...</div>;
|
|
286
|
+
*
|
|
287
|
+
* if (!isAuthenticated) {
|
|
288
|
+
* return <LoginForm auth={auth} />;
|
|
289
|
+
* }
|
|
290
|
+
*
|
|
291
|
+
* return (
|
|
292
|
+
* <div>
|
|
293
|
+
* Welcome, {user?.email}
|
|
294
|
+
* <button onClick={logout}>Logout</button>
|
|
295
|
+
* </div>
|
|
296
|
+
* );
|
|
297
|
+
* }
|
|
298
|
+
* ```
|
|
299
|
+
*/
|
|
300
|
+
declare function useTiquoAuth(auth: TiquoAuth): {
|
|
301
|
+
readonly user: TiquoUser | null;
|
|
302
|
+
readonly customer: TiquoCustomer | null;
|
|
303
|
+
readonly session: TiquoSession | null;
|
|
304
|
+
readonly isLoading: boolean;
|
|
305
|
+
readonly isAuthenticated: boolean;
|
|
306
|
+
sendOTP: (email: string) => Promise<SendOTPResult>;
|
|
307
|
+
verifyOTP: (email: string, otp: string) => Promise<VerifyOTPResult>;
|
|
308
|
+
logout: () => Promise<void>;
|
|
309
|
+
updateProfile: (updates: ProfileUpdateData) => Promise<ProfileUpdateResult>;
|
|
310
|
+
getOrders: (options?: GetOrdersOptions) => Promise<GetOrdersResult>;
|
|
311
|
+
getBookings: (options?: GetBookingsOptions) => Promise<GetBookingsResult>;
|
|
312
|
+
getEnquiries: (options?: GetEnquiriesOptions) => Promise<GetEnquiriesResult>;
|
|
313
|
+
getIframeToken: (flowId?: string) => Promise<IframeTokenResult>;
|
|
314
|
+
embedCustomerFlow: (flowUrl: string, container: HTMLElement | string, options?: {
|
|
315
|
+
width?: string;
|
|
316
|
+
height?: string;
|
|
317
|
+
onLoad?: () => void;
|
|
318
|
+
onError?: (error: Error) => void;
|
|
319
|
+
}) => Promise<HTMLIFrameElement>;
|
|
320
|
+
onAuthStateChange: (cb: AuthStateChangeCallback) => () => void;
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
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 TiquoEnquiry, type TiquoOrder, type TiquoOrderItem, type TiquoSession, type TiquoUser, type VerifyOTPResult, TiquoAuth as default, useTiquoAuth };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @tiquo/dom-package
|
|
3
|
+
*
|
|
4
|
+
* Customer authentication SDK for third-party websites using Tiquo.
|
|
5
|
+
* Enables email OTP authentication without passwords.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { TiquoAuth } from '@tiquo/dom-package';
|
|
10
|
+
*
|
|
11
|
+
* const auth = new TiquoAuth({
|
|
12
|
+
* publicKey: 'pk_dom_xxxxx'
|
|
13
|
+
* });
|
|
14
|
+
*
|
|
15
|
+
* // Send OTP
|
|
16
|
+
* await auth.sendOTP('user@example.com');
|
|
17
|
+
*
|
|
18
|
+
* // Verify OTP
|
|
19
|
+
* const result = await auth.verifyOTP('user@example.com', '123456');
|
|
20
|
+
*
|
|
21
|
+
* // Get current user
|
|
22
|
+
* const user = await auth.getUser();
|
|
23
|
+
*
|
|
24
|
+
* // Logout
|
|
25
|
+
* await auth.logout();
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
interface TiquoAuthConfig {
|
|
29
|
+
/** Public key from your Tiquo Auth DOM settings */
|
|
30
|
+
publicKey: string;
|
|
31
|
+
/** API endpoint (defaults to production) */
|
|
32
|
+
apiEndpoint?: string;
|
|
33
|
+
/** Storage key prefix for session data */
|
|
34
|
+
storagePrefix?: string;
|
|
35
|
+
/** Enable debug logging */
|
|
36
|
+
debug?: boolean;
|
|
37
|
+
/** Enable multi-tab session sync via BroadcastChannel (default: true) */
|
|
38
|
+
enableTabSync?: boolean;
|
|
39
|
+
}
|
|
40
|
+
interface TiquoUser {
|
|
41
|
+
id: string;
|
|
42
|
+
email: string;
|
|
43
|
+
}
|
|
44
|
+
interface TiquoCustomer {
|
|
45
|
+
id: string;
|
|
46
|
+
firstName?: string;
|
|
47
|
+
lastName?: string;
|
|
48
|
+
displayName?: string;
|
|
49
|
+
customerNumber: string;
|
|
50
|
+
email?: string;
|
|
51
|
+
phone?: string;
|
|
52
|
+
}
|
|
53
|
+
interface TiquoSession {
|
|
54
|
+
user: TiquoUser;
|
|
55
|
+
customer: TiquoCustomer | null;
|
|
56
|
+
expiresAt: number;
|
|
57
|
+
}
|
|
58
|
+
interface SendOTPResult {
|
|
59
|
+
success: boolean;
|
|
60
|
+
message: string;
|
|
61
|
+
}
|
|
62
|
+
interface VerifyOTPResult {
|
|
63
|
+
success: boolean;
|
|
64
|
+
sessionToken: string;
|
|
65
|
+
expiresAt: number;
|
|
66
|
+
isNewUser: boolean;
|
|
67
|
+
hasCustomer: boolean;
|
|
68
|
+
}
|
|
69
|
+
interface IframeTokenResult {
|
|
70
|
+
token: string;
|
|
71
|
+
expiresAt: number;
|
|
72
|
+
}
|
|
73
|
+
interface ProfileUpdateData {
|
|
74
|
+
firstName?: string;
|
|
75
|
+
lastName?: string;
|
|
76
|
+
displayName?: string;
|
|
77
|
+
phone?: string;
|
|
78
|
+
profilePhoto?: string;
|
|
79
|
+
}
|
|
80
|
+
interface ProfileUpdateResult {
|
|
81
|
+
success: boolean;
|
|
82
|
+
customer: TiquoCustomer & {
|
|
83
|
+
profilePhoto?: string;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
interface TiquoOrderItem {
|
|
87
|
+
id: string;
|
|
88
|
+
name: string;
|
|
89
|
+
quantity: number;
|
|
90
|
+
unitPrice: number;
|
|
91
|
+
total: number;
|
|
92
|
+
type: 'product' | 'booking' | 'custom';
|
|
93
|
+
}
|
|
94
|
+
interface TiquoOrder {
|
|
95
|
+
id: string;
|
|
96
|
+
orderNumber: string;
|
|
97
|
+
status: 'draft' | 'pending' | 'confirmed' | 'processing' | 'completed' | 'cancelled' | 'refunded' | 'open_tab';
|
|
98
|
+
paymentStatus: 'pending' | 'paid' | 'partial' | 'refunded' | 'failed' | 'cancelled';
|
|
99
|
+
total: number;
|
|
100
|
+
subtotal: number;
|
|
101
|
+
taxTotal: number;
|
|
102
|
+
discountTotal: number;
|
|
103
|
+
items: TiquoOrderItem[];
|
|
104
|
+
createdAt: number;
|
|
105
|
+
completedAt?: number;
|
|
106
|
+
customerRole: 'primary' | 'attendee' | 'recipient' | 'billing' | 'guest' | 'other';
|
|
107
|
+
}
|
|
108
|
+
interface GetOrdersOptions {
|
|
109
|
+
limit?: number;
|
|
110
|
+
cursor?: string;
|
|
111
|
+
status?: TiquoOrder['status'];
|
|
112
|
+
}
|
|
113
|
+
interface GetOrdersResult {
|
|
114
|
+
orders: TiquoOrder[];
|
|
115
|
+
hasMore: boolean;
|
|
116
|
+
nextCursor?: string;
|
|
117
|
+
}
|
|
118
|
+
interface TiquoBooking {
|
|
119
|
+
id: string;
|
|
120
|
+
bookingNumber: string;
|
|
121
|
+
confirmationCode: string;
|
|
122
|
+
status: 'draft' | 'scheduled' | 'confirmed' | 'reminder_sent' | 'waiting_room' | 'waiting_list' | 'checked_in' | 'active' | 'in_progress' | 'completed' | 'cancelled' | 'no_show' | 'rescheduled';
|
|
123
|
+
date: number;
|
|
124
|
+
startTime: string;
|
|
125
|
+
endTime: string;
|
|
126
|
+
duration: number;
|
|
127
|
+
timezone: string;
|
|
128
|
+
attendeeCount: number;
|
|
129
|
+
serviceName: string;
|
|
130
|
+
serviceId: string;
|
|
131
|
+
sublocationId: string;
|
|
132
|
+
customerNotes?: string;
|
|
133
|
+
createdAt: number;
|
|
134
|
+
checkedInAt?: number;
|
|
135
|
+
completedAt?: number;
|
|
136
|
+
cancelledAt?: number;
|
|
137
|
+
}
|
|
138
|
+
interface GetBookingsOptions {
|
|
139
|
+
limit?: number;
|
|
140
|
+
cursor?: string;
|
|
141
|
+
status?: TiquoBooking['status'];
|
|
142
|
+
upcoming?: boolean;
|
|
143
|
+
}
|
|
144
|
+
interface GetBookingsResult {
|
|
145
|
+
bookings: TiquoBooking[];
|
|
146
|
+
hasMore: boolean;
|
|
147
|
+
nextCursor?: string;
|
|
148
|
+
}
|
|
149
|
+
interface TiquoEnquiry {
|
|
150
|
+
id: string;
|
|
151
|
+
enquiryNumber: string;
|
|
152
|
+
type: string;
|
|
153
|
+
subject: string;
|
|
154
|
+
message: string;
|
|
155
|
+
category: string;
|
|
156
|
+
status: 'new' | 'in_progress' | 'waiting_customer' | 'waiting_internal' | 'won' | 'lost' | 'closed' | 'resolved' | 'archived';
|
|
157
|
+
priority: 'low' | 'medium' | 'high' | 'urgent';
|
|
158
|
+
source: 'online' | 'website' | 'phone' | 'email' | 'walk_in' | 'social' | 'referral' | 'pos' | 'admin';
|
|
159
|
+
responseCount: number;
|
|
160
|
+
createdAt: string;
|
|
161
|
+
updatedAt: string;
|
|
162
|
+
firstResponseAt?: string;
|
|
163
|
+
resolvedAt?: string;
|
|
164
|
+
customerRole: 'primary' | 'interested' | 'decision_maker' | 'influencer' | 'referrer' | 'other';
|
|
165
|
+
}
|
|
166
|
+
interface GetEnquiriesOptions {
|
|
167
|
+
limit?: number;
|
|
168
|
+
cursor?: string;
|
|
169
|
+
status?: TiquoEnquiry['status'];
|
|
170
|
+
}
|
|
171
|
+
interface GetEnquiriesResult {
|
|
172
|
+
enquiries: TiquoEnquiry[];
|
|
173
|
+
hasMore: boolean;
|
|
174
|
+
nextCursor?: string;
|
|
175
|
+
}
|
|
176
|
+
type AuthStateChangeCallback = (session: TiquoSession | null) => void;
|
|
177
|
+
declare class TiquoAuthError extends Error {
|
|
178
|
+
code: string;
|
|
179
|
+
statusCode?: number | undefined;
|
|
180
|
+
constructor(message: string, code: string, statusCode?: number | undefined);
|
|
181
|
+
}
|
|
182
|
+
declare class TiquoAuth {
|
|
183
|
+
private config;
|
|
184
|
+
private sessionToken;
|
|
185
|
+
private session;
|
|
186
|
+
private listeners;
|
|
187
|
+
private refreshTimer;
|
|
188
|
+
private broadcastChannel;
|
|
189
|
+
private tabId;
|
|
190
|
+
private isProcessingTabSync;
|
|
191
|
+
constructor(config: TiquoAuthConfig);
|
|
192
|
+
/**
|
|
193
|
+
* Send an OTP verification code to the user's email
|
|
194
|
+
*/
|
|
195
|
+
sendOTP(email: string): Promise<SendOTPResult>;
|
|
196
|
+
/**
|
|
197
|
+
* Verify an OTP code and authenticate the user
|
|
198
|
+
*/
|
|
199
|
+
verifyOTP(email: string, otp: string): Promise<VerifyOTPResult>;
|
|
200
|
+
/**
|
|
201
|
+
* Get the current authenticated user and customer data
|
|
202
|
+
*/
|
|
203
|
+
getUser(): Promise<TiquoSession | null>;
|
|
204
|
+
/**
|
|
205
|
+
* Check if user is currently authenticated
|
|
206
|
+
*/
|
|
207
|
+
isAuthenticated(): boolean;
|
|
208
|
+
/**
|
|
209
|
+
* Update the authenticated customer's profile
|
|
210
|
+
* Only allows updating the logged-in customer's own data
|
|
211
|
+
*/
|
|
212
|
+
updateProfile(updates: ProfileUpdateData): Promise<ProfileUpdateResult>;
|
|
213
|
+
/**
|
|
214
|
+
* Log out the current user
|
|
215
|
+
*/
|
|
216
|
+
logout(): Promise<void>;
|
|
217
|
+
/**
|
|
218
|
+
* Subscribe to authentication state changes
|
|
219
|
+
*/
|
|
220
|
+
onAuthStateChange(callback: AuthStateChangeCallback): () => void;
|
|
221
|
+
/**
|
|
222
|
+
* Get the authenticated customer's order history
|
|
223
|
+
* Only returns orders for the logged-in customer
|
|
224
|
+
*/
|
|
225
|
+
getOrders(options?: GetOrdersOptions): Promise<GetOrdersResult>;
|
|
226
|
+
/**
|
|
227
|
+
* Get the authenticated customer's booking history
|
|
228
|
+
* Only returns bookings for the logged-in customer
|
|
229
|
+
*/
|
|
230
|
+
getBookings(options?: GetBookingsOptions): Promise<GetBookingsResult>;
|
|
231
|
+
/**
|
|
232
|
+
* Get the authenticated customer's enquiry history
|
|
233
|
+
* Only returns enquiries for the logged-in customer
|
|
234
|
+
*/
|
|
235
|
+
getEnquiries(options?: GetEnquiriesOptions): Promise<GetEnquiriesResult>;
|
|
236
|
+
/**
|
|
237
|
+
* Generate a short-lived token for customer flow iframe authentication
|
|
238
|
+
*/
|
|
239
|
+
getIframeToken(customerFlowId?: string): Promise<IframeTokenResult>;
|
|
240
|
+
/**
|
|
241
|
+
* Embed a customer flow with automatic authentication
|
|
242
|
+
*
|
|
243
|
+
* @param flowUrl - The URL of the customer flow (book.tiquo.app/...)
|
|
244
|
+
* @param container - Container element or selector
|
|
245
|
+
* @param options - Optional iframe configuration
|
|
246
|
+
*/
|
|
247
|
+
embedCustomerFlow(flowUrl: string, container: HTMLElement | string, options?: {
|
|
248
|
+
width?: string;
|
|
249
|
+
height?: string;
|
|
250
|
+
onLoad?: () => void;
|
|
251
|
+
onError?: (error: Error) => void;
|
|
252
|
+
}): Promise<HTMLIFrameElement>;
|
|
253
|
+
/**
|
|
254
|
+
* Get the current session token (for advanced use cases)
|
|
255
|
+
*/
|
|
256
|
+
getSessionToken(): string | null;
|
|
257
|
+
private request;
|
|
258
|
+
private refreshSession;
|
|
259
|
+
private saveSession;
|
|
260
|
+
private restoreSession;
|
|
261
|
+
private clearSession;
|
|
262
|
+
private notifyListeners;
|
|
263
|
+
private scheduleRefresh;
|
|
264
|
+
private log;
|
|
265
|
+
private generateTabId;
|
|
266
|
+
private initTabSync;
|
|
267
|
+
private broadcastTabSync;
|
|
268
|
+
private handleTabSyncMessage;
|
|
269
|
+
/**
|
|
270
|
+
* Clean up resources (call when destroying the auth instance)
|
|
271
|
+
*/
|
|
272
|
+
destroy(): void;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* React hook for using TiquoAuth
|
|
276
|
+
* Note: Requires a TiquoAuth instance to be passed in
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
* ```tsx
|
|
280
|
+
* const auth = new TiquoAuth({ publicKey: 'pk_dom_xxx' });
|
|
281
|
+
*
|
|
282
|
+
* function App() {
|
|
283
|
+
* const { user, isLoading, isAuthenticated, logout } = useTiquoAuth(auth);
|
|
284
|
+
*
|
|
285
|
+
* if (isLoading) return <div>Loading...</div>;
|
|
286
|
+
*
|
|
287
|
+
* if (!isAuthenticated) {
|
|
288
|
+
* return <LoginForm auth={auth} />;
|
|
289
|
+
* }
|
|
290
|
+
*
|
|
291
|
+
* return (
|
|
292
|
+
* <div>
|
|
293
|
+
* Welcome, {user?.email}
|
|
294
|
+
* <button onClick={logout}>Logout</button>
|
|
295
|
+
* </div>
|
|
296
|
+
* );
|
|
297
|
+
* }
|
|
298
|
+
* ```
|
|
299
|
+
*/
|
|
300
|
+
declare function useTiquoAuth(auth: TiquoAuth): {
|
|
301
|
+
readonly user: TiquoUser | null;
|
|
302
|
+
readonly customer: TiquoCustomer | null;
|
|
303
|
+
readonly session: TiquoSession | null;
|
|
304
|
+
readonly isLoading: boolean;
|
|
305
|
+
readonly isAuthenticated: boolean;
|
|
306
|
+
sendOTP: (email: string) => Promise<SendOTPResult>;
|
|
307
|
+
verifyOTP: (email: string, otp: string) => Promise<VerifyOTPResult>;
|
|
308
|
+
logout: () => Promise<void>;
|
|
309
|
+
updateProfile: (updates: ProfileUpdateData) => Promise<ProfileUpdateResult>;
|
|
310
|
+
getOrders: (options?: GetOrdersOptions) => Promise<GetOrdersResult>;
|
|
311
|
+
getBookings: (options?: GetBookingsOptions) => Promise<GetBookingsResult>;
|
|
312
|
+
getEnquiries: (options?: GetEnquiriesOptions) => Promise<GetEnquiriesResult>;
|
|
313
|
+
getIframeToken: (flowId?: string) => Promise<IframeTokenResult>;
|
|
314
|
+
embedCustomerFlow: (flowUrl: string, container: HTMLElement | string, options?: {
|
|
315
|
+
width?: string;
|
|
316
|
+
height?: string;
|
|
317
|
+
onLoad?: () => void;
|
|
318
|
+
onError?: (error: Error) => void;
|
|
319
|
+
}) => Promise<HTMLIFrameElement>;
|
|
320
|
+
onAuthStateChange: (cb: AuthStateChangeCallback) => () => void;
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
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 TiquoEnquiry, type TiquoOrder, type TiquoOrderItem, type TiquoSession, type TiquoUser, type VerifyOTPResult, TiquoAuth as default, useTiquoAuth };
|