@tiquo/dom-package 1.5.3 → 1.6.1
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 +42 -0
- package/dist/index.d.mts +50 -1
- package/dist/index.d.ts +50 -1
- package/dist/index.js +115 -5
- package/dist/index.mjs +114 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -45,6 +45,22 @@ The same public key is used across all websites in your organization; Tiquo reco
|
|
|
45
45
|
the source domain for each event and rolls `www.example.com` into `example.com`.
|
|
46
46
|
Other subdomains are tracked as separate websites.
|
|
47
47
|
|
|
48
|
+
The package prints a small Tiquo banner in the browser console once per page load
|
|
49
|
+
when it is loaded by your site. To show it on every page, import the package from
|
|
50
|
+
global client-side code that runs on every page:
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
import '@tiquo/dom-package';
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
You can also print the banner explicitly:
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import { printTiquoBranding } from '@tiquo/dom-package';
|
|
60
|
+
|
|
61
|
+
printTiquoBranding();
|
|
62
|
+
```
|
|
63
|
+
|
|
48
64
|
```typescript
|
|
49
65
|
// Optional custom analytics events
|
|
50
66
|
await auth.analytics?.track('booking_started', {
|
|
@@ -277,6 +293,32 @@ const page2 = await auth.getEnquiries({ limit: 10, cursor: page1.nextCursor });
|
|
|
277
293
|
- `hasMore` - Whether there are more enquiries to fetch
|
|
278
294
|
- `nextCursor` - Cursor for the next page (if `hasMore` is true)
|
|
279
295
|
|
|
296
|
+
#### `createEnquiry(input): Promise<CreateEnquiryResult>`
|
|
297
|
+
|
|
298
|
+
Create an enquiry from your website. `customer.email` is required. If the visitor is authenticated, the enquiry is attached to that customer. Otherwise the SDK uses your public key and allowed domain configuration, finds or creates a customer by email, and attaches the enquiry.
|
|
299
|
+
|
|
300
|
+
Submitted customer fields fill missing profile data only; existing names, phones, and customer parameter values are not overwritten.
|
|
301
|
+
|
|
302
|
+
```typescript
|
|
303
|
+
const { enquiry, customer } = await auth.createEnquiry({
|
|
304
|
+
customer: {
|
|
305
|
+
email: 'customer@example.com',
|
|
306
|
+
firstName: 'Sam',
|
|
307
|
+
lastName: 'Taylor',
|
|
308
|
+
phone: '+44 7911 123456',
|
|
309
|
+
details: {
|
|
310
|
+
system_marketing_opt_in: true,
|
|
311
|
+
},
|
|
312
|
+
},
|
|
313
|
+
enquiry: {
|
|
314
|
+
subject: 'Private event request',
|
|
315
|
+
message: 'I would like to enquire about availability next Friday.',
|
|
316
|
+
category: 'events',
|
|
317
|
+
priority: 'medium',
|
|
318
|
+
},
|
|
319
|
+
});
|
|
320
|
+
```
|
|
321
|
+
|
|
280
322
|
#### `destroy(): void`
|
|
281
323
|
|
|
282
324
|
Clean up resources when destroying the auth instance. Call this when your component unmounts or when you no longer need the auth instance.
|
package/dist/index.d.mts
CHANGED
|
@@ -164,6 +164,8 @@ declare function getDialCode(countryCode: string): string | null;
|
|
|
164
164
|
*/
|
|
165
165
|
declare function buildPhone(countryCode: string, nationalNumber: string): string | null;
|
|
166
166
|
|
|
167
|
+
declare function printTiquoBranding(): void;
|
|
168
|
+
|
|
167
169
|
/**
|
|
168
170
|
* @tiquo/dom-package
|
|
169
171
|
*
|
|
@@ -622,6 +624,40 @@ interface GetEnquiriesResult {
|
|
|
622
624
|
hasMore: boolean;
|
|
623
625
|
nextCursor?: string;
|
|
624
626
|
}
|
|
627
|
+
interface CreateEnquiryCustomerData {
|
|
628
|
+
/** Required. Used to find or create the customer profile for this enquiry. */
|
|
629
|
+
email: string;
|
|
630
|
+
firstName?: string;
|
|
631
|
+
lastName?: string;
|
|
632
|
+
/**
|
|
633
|
+
* Primary phone number in E.164 format. The SDK auto-normalizes common
|
|
634
|
+
* formats before submission.
|
|
635
|
+
*/
|
|
636
|
+
phone?: string;
|
|
637
|
+
/**
|
|
638
|
+
* Additional customer parameter values keyed by system parameter id
|
|
639
|
+
* (`system_marketing_opt_in`) or customer parameter schema id. Existing
|
|
640
|
+
* non-empty values are not overwritten.
|
|
641
|
+
*/
|
|
642
|
+
details?: Record<string, string | number | boolean | null>;
|
|
643
|
+
}
|
|
644
|
+
interface CreateEnquiryData {
|
|
645
|
+
customer: CreateEnquiryCustomerData;
|
|
646
|
+
enquiry: {
|
|
647
|
+
type?: string;
|
|
648
|
+
subject?: string;
|
|
649
|
+
/** Required unless `subject` is supplied. */
|
|
650
|
+
message?: string;
|
|
651
|
+
category?: string;
|
|
652
|
+
priority?: "low" | "medium" | "high" | "urgent";
|
|
653
|
+
source?: "online" | "website" | "phone" | "email" | "walk_in" | "social" | "referral" | "pos" | "admin";
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
interface CreateEnquiryResult {
|
|
657
|
+
success: boolean;
|
|
658
|
+
enquiry: TiquoEnquiry;
|
|
659
|
+
customer: TiquoCustomer;
|
|
660
|
+
}
|
|
625
661
|
type TiquoCompanyRelationship = "employee" | "contractor" | "manager" | "executive" | "owner" | "contact" | "other";
|
|
626
662
|
/**
|
|
627
663
|
* The authenticated customer's membership in a company. Each company the
|
|
@@ -823,6 +859,18 @@ declare class TiquoAuth {
|
|
|
823
859
|
* Only returns enquiries for the logged-in customer
|
|
824
860
|
*/
|
|
825
861
|
getEnquiries(options?: GetEnquiriesOptions): Promise<GetEnquiriesResult>;
|
|
862
|
+
/**
|
|
863
|
+
* Create a new enquiry through the DOM package.
|
|
864
|
+
*
|
|
865
|
+
* `customer.email` is required. If the current browser has an authenticated
|
|
866
|
+
* DOM session, the enquiry is associated with that customer. Otherwise the
|
|
867
|
+
* public key and allowed-domain configuration are used to accept the
|
|
868
|
+
* submission, find or create a customer by email, and attach the enquiry.
|
|
869
|
+
*
|
|
870
|
+
* Submitted customer details fill missing customer profile fields only; they
|
|
871
|
+
* do not overwrite existing profile data.
|
|
872
|
+
*/
|
|
873
|
+
createEnquiry(input: CreateEnquiryData): Promise<CreateEnquiryResult>;
|
|
826
874
|
/**
|
|
827
875
|
* Get the companies the authenticated customer belongs to.
|
|
828
876
|
*
|
|
@@ -946,6 +994,7 @@ declare function useTiquoAuth(auth: TiquoAuth): {
|
|
|
946
994
|
getUpcomingBookings: (options?: Omit<GetBookingsOptions, "upcoming">) => Promise<GetBookingsResult>;
|
|
947
995
|
getReceipt: (orderId: string) => Promise<TiquoReceipt>;
|
|
948
996
|
getEnquiries: (options?: GetEnquiriesOptions) => Promise<GetEnquiriesResult>;
|
|
997
|
+
createEnquiry: (input: CreateEnquiryData) => Promise<CreateEnquiryResult>;
|
|
949
998
|
getCompanies: () => Promise<GetCompaniesResult>;
|
|
950
999
|
getCompanyColleagues: (companyId: string) => Promise<GetCompanyColleaguesResult>;
|
|
951
1000
|
getIframeToken: (flowId?: string) => Promise<IframeTokenResult>;
|
|
@@ -1010,4 +1059,4 @@ declare class TiquoPhone {
|
|
|
1010
1059
|
static buildPhone: typeof buildPhone;
|
|
1011
1060
|
}
|
|
1012
1061
|
|
|
1013
|
-
export { type AuthStateChangeCallback, type CountryPhoneInfo, type GetBookingsOptions, type GetBookingsResult, type GetCompaniesResult, type GetCompanyColleaguesResult, type GetEnquiriesOptions, type GetEnquiriesResult, type GetOrdersOptions, type GetOrdersResult, type IframeTokenResult, type PhoneValidationResult, type ProfilePhotoUploadResult, type ProfileUpdateData, type ProfileUpdateResult, type SendOTPResult, TiquoAnalytics, type TiquoAnalyticsConfig, type TiquoAnalyticsEventOptions, TiquoAuth, type TiquoAuthConfig, TiquoAuthError, type TiquoBooking, TiquoCMS, type TiquoCMSBlock, type TiquoCMSConfig, type TiquoCMSPage, type TiquoCMSPageRequest, type TiquoCompany, type TiquoCompanyColleague, type TiquoCompanyMembership, type TiquoCompanyRelationship, type TiquoCustomer, type TiquoCustomerEmail, type TiquoCustomerPhone, type TiquoEnquiry, type TiquoOrder, type TiquoOrderItem, TiquoPhone, type TiquoReceipt, type TiquoReceiptBusiness, type TiquoReceiptCustomer, type TiquoReceiptItem, type TiquoReceiptOrder, type TiquoSession, type TiquoUser, type VerifyOTPResult, addCustomerUserId, clearCachedEmail, TiquoAuth as default, getCustomerUserIds, getPrefilledEmailFromCookie, isDashboardSession, trackCustomerPresence, useTiquoAuth };
|
|
1062
|
+
export { type AuthStateChangeCallback, type CountryPhoneInfo, type CreateEnquiryCustomerData, type CreateEnquiryData, type CreateEnquiryResult, type GetBookingsOptions, type GetBookingsResult, type GetCompaniesResult, type GetCompanyColleaguesResult, type GetEnquiriesOptions, type GetEnquiriesResult, type GetOrdersOptions, type GetOrdersResult, type IframeTokenResult, type PhoneValidationResult, type ProfilePhotoUploadResult, type ProfileUpdateData, type ProfileUpdateResult, type SendOTPResult, TiquoAnalytics, type TiquoAnalyticsConfig, type TiquoAnalyticsEventOptions, TiquoAuth, type TiquoAuthConfig, TiquoAuthError, type TiquoBooking, TiquoCMS, type TiquoCMSBlock, type TiquoCMSConfig, type TiquoCMSPage, type TiquoCMSPageRequest, type TiquoCompany, type TiquoCompanyColleague, type TiquoCompanyMembership, type TiquoCompanyRelationship, type TiquoCustomer, type TiquoCustomerEmail, type TiquoCustomerPhone, type TiquoEnquiry, type TiquoOrder, type TiquoOrderItem, TiquoPhone, type TiquoReceipt, type TiquoReceiptBusiness, type TiquoReceiptCustomer, type TiquoReceiptItem, type TiquoReceiptOrder, type TiquoSession, type TiquoUser, type VerifyOTPResult, addCustomerUserId, clearCachedEmail, TiquoAuth as default, getCustomerUserIds, getPrefilledEmailFromCookie, isDashboardSession, printTiquoBranding, trackCustomerPresence, useTiquoAuth };
|
package/dist/index.d.ts
CHANGED
|
@@ -164,6 +164,8 @@ declare function getDialCode(countryCode: string): string | null;
|
|
|
164
164
|
*/
|
|
165
165
|
declare function buildPhone(countryCode: string, nationalNumber: string): string | null;
|
|
166
166
|
|
|
167
|
+
declare function printTiquoBranding(): void;
|
|
168
|
+
|
|
167
169
|
/**
|
|
168
170
|
* @tiquo/dom-package
|
|
169
171
|
*
|
|
@@ -622,6 +624,40 @@ interface GetEnquiriesResult {
|
|
|
622
624
|
hasMore: boolean;
|
|
623
625
|
nextCursor?: string;
|
|
624
626
|
}
|
|
627
|
+
interface CreateEnquiryCustomerData {
|
|
628
|
+
/** Required. Used to find or create the customer profile for this enquiry. */
|
|
629
|
+
email: string;
|
|
630
|
+
firstName?: string;
|
|
631
|
+
lastName?: string;
|
|
632
|
+
/**
|
|
633
|
+
* Primary phone number in E.164 format. The SDK auto-normalizes common
|
|
634
|
+
* formats before submission.
|
|
635
|
+
*/
|
|
636
|
+
phone?: string;
|
|
637
|
+
/**
|
|
638
|
+
* Additional customer parameter values keyed by system parameter id
|
|
639
|
+
* (`system_marketing_opt_in`) or customer parameter schema id. Existing
|
|
640
|
+
* non-empty values are not overwritten.
|
|
641
|
+
*/
|
|
642
|
+
details?: Record<string, string | number | boolean | null>;
|
|
643
|
+
}
|
|
644
|
+
interface CreateEnquiryData {
|
|
645
|
+
customer: CreateEnquiryCustomerData;
|
|
646
|
+
enquiry: {
|
|
647
|
+
type?: string;
|
|
648
|
+
subject?: string;
|
|
649
|
+
/** Required unless `subject` is supplied. */
|
|
650
|
+
message?: string;
|
|
651
|
+
category?: string;
|
|
652
|
+
priority?: "low" | "medium" | "high" | "urgent";
|
|
653
|
+
source?: "online" | "website" | "phone" | "email" | "walk_in" | "social" | "referral" | "pos" | "admin";
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
interface CreateEnquiryResult {
|
|
657
|
+
success: boolean;
|
|
658
|
+
enquiry: TiquoEnquiry;
|
|
659
|
+
customer: TiquoCustomer;
|
|
660
|
+
}
|
|
625
661
|
type TiquoCompanyRelationship = "employee" | "contractor" | "manager" | "executive" | "owner" | "contact" | "other";
|
|
626
662
|
/**
|
|
627
663
|
* The authenticated customer's membership in a company. Each company the
|
|
@@ -823,6 +859,18 @@ declare class TiquoAuth {
|
|
|
823
859
|
* Only returns enquiries for the logged-in customer
|
|
824
860
|
*/
|
|
825
861
|
getEnquiries(options?: GetEnquiriesOptions): Promise<GetEnquiriesResult>;
|
|
862
|
+
/**
|
|
863
|
+
* Create a new enquiry through the DOM package.
|
|
864
|
+
*
|
|
865
|
+
* `customer.email` is required. If the current browser has an authenticated
|
|
866
|
+
* DOM session, the enquiry is associated with that customer. Otherwise the
|
|
867
|
+
* public key and allowed-domain configuration are used to accept the
|
|
868
|
+
* submission, find or create a customer by email, and attach the enquiry.
|
|
869
|
+
*
|
|
870
|
+
* Submitted customer details fill missing customer profile fields only; they
|
|
871
|
+
* do not overwrite existing profile data.
|
|
872
|
+
*/
|
|
873
|
+
createEnquiry(input: CreateEnquiryData): Promise<CreateEnquiryResult>;
|
|
826
874
|
/**
|
|
827
875
|
* Get the companies the authenticated customer belongs to.
|
|
828
876
|
*
|
|
@@ -946,6 +994,7 @@ declare function useTiquoAuth(auth: TiquoAuth): {
|
|
|
946
994
|
getUpcomingBookings: (options?: Omit<GetBookingsOptions, "upcoming">) => Promise<GetBookingsResult>;
|
|
947
995
|
getReceipt: (orderId: string) => Promise<TiquoReceipt>;
|
|
948
996
|
getEnquiries: (options?: GetEnquiriesOptions) => Promise<GetEnquiriesResult>;
|
|
997
|
+
createEnquiry: (input: CreateEnquiryData) => Promise<CreateEnquiryResult>;
|
|
949
998
|
getCompanies: () => Promise<GetCompaniesResult>;
|
|
950
999
|
getCompanyColleagues: (companyId: string) => Promise<GetCompanyColleaguesResult>;
|
|
951
1000
|
getIframeToken: (flowId?: string) => Promise<IframeTokenResult>;
|
|
@@ -1010,4 +1059,4 @@ declare class TiquoPhone {
|
|
|
1010
1059
|
static buildPhone: typeof buildPhone;
|
|
1011
1060
|
}
|
|
1012
1061
|
|
|
1013
|
-
export { type AuthStateChangeCallback, type CountryPhoneInfo, type GetBookingsOptions, type GetBookingsResult, type GetCompaniesResult, type GetCompanyColleaguesResult, type GetEnquiriesOptions, type GetEnquiriesResult, type GetOrdersOptions, type GetOrdersResult, type IframeTokenResult, type PhoneValidationResult, type ProfilePhotoUploadResult, type ProfileUpdateData, type ProfileUpdateResult, type SendOTPResult, TiquoAnalytics, type TiquoAnalyticsConfig, type TiquoAnalyticsEventOptions, TiquoAuth, type TiquoAuthConfig, TiquoAuthError, type TiquoBooking, TiquoCMS, type TiquoCMSBlock, type TiquoCMSConfig, type TiquoCMSPage, type TiquoCMSPageRequest, type TiquoCompany, type TiquoCompanyColleague, type TiquoCompanyMembership, type TiquoCompanyRelationship, type TiquoCustomer, type TiquoCustomerEmail, type TiquoCustomerPhone, type TiquoEnquiry, type TiquoOrder, type TiquoOrderItem, TiquoPhone, type TiquoReceipt, type TiquoReceiptBusiness, type TiquoReceiptCustomer, type TiquoReceiptItem, type TiquoReceiptOrder, type TiquoSession, type TiquoUser, type VerifyOTPResult, addCustomerUserId, clearCachedEmail, TiquoAuth as default, getCustomerUserIds, getPrefilledEmailFromCookie, isDashboardSession, trackCustomerPresence, useTiquoAuth };
|
|
1062
|
+
export { type AuthStateChangeCallback, type CountryPhoneInfo, type CreateEnquiryCustomerData, type CreateEnquiryData, type CreateEnquiryResult, type GetBookingsOptions, type GetBookingsResult, type GetCompaniesResult, type GetCompanyColleaguesResult, type GetEnquiriesOptions, type GetEnquiriesResult, type GetOrdersOptions, type GetOrdersResult, type IframeTokenResult, type PhoneValidationResult, type ProfilePhotoUploadResult, type ProfileUpdateData, type ProfileUpdateResult, type SendOTPResult, TiquoAnalytics, type TiquoAnalyticsConfig, type TiquoAnalyticsEventOptions, TiquoAuth, type TiquoAuthConfig, TiquoAuthError, type TiquoBooking, TiquoCMS, type TiquoCMSBlock, type TiquoCMSConfig, type TiquoCMSPage, type TiquoCMSPageRequest, type TiquoCompany, type TiquoCompanyColleague, type TiquoCompanyMembership, type TiquoCompanyRelationship, type TiquoCustomer, type TiquoCustomerEmail, type TiquoCustomerPhone, type TiquoEnquiry, type TiquoOrder, type TiquoOrderItem, TiquoPhone, type TiquoReceipt, type TiquoReceiptBusiness, type TiquoReceiptCustomer, type TiquoReceiptItem, type TiquoReceiptOrder, type TiquoSession, type TiquoUser, type VerifyOTPResult, addCustomerUserId, clearCachedEmail, TiquoAuth as default, getCustomerUserIds, getPrefilledEmailFromCookie, isDashboardSession, printTiquoBranding, trackCustomerPresence, useTiquoAuth };
|
package/dist/index.js
CHANGED
|
@@ -31,6 +31,7 @@ __export(index_exports, {
|
|
|
31
31
|
getCustomerUserIds: () => getCustomerUserIds,
|
|
32
32
|
getPrefilledEmailFromCookie: () => getPrefilledEmailFromCookie,
|
|
33
33
|
isDashboardSession: () => isDashboardSession,
|
|
34
|
+
printTiquoBranding: () => printTiquoBranding,
|
|
34
35
|
trackCustomerPresence: () => trackCustomerPresence,
|
|
35
36
|
useTiquoAuth: () => useTiquoAuth
|
|
36
37
|
});
|
|
@@ -651,12 +652,33 @@ function buildPhone(countryCode, nationalNumber) {
|
|
|
651
652
|
return normalizePhone("+" + dc + digits);
|
|
652
653
|
}
|
|
653
654
|
|
|
654
|
-
// src/
|
|
655
|
-
var
|
|
655
|
+
// src/branding.ts
|
|
656
|
+
var BRANDING_MARKER = /* @__PURE__ */ Symbol.for("tiquo.domPackage.brandingPrinted");
|
|
657
|
+
var brandingPrinted = false;
|
|
658
|
+
function hasPrintedInRuntime() {
|
|
659
|
+
return Boolean(globalThis[BRANDING_MARKER]);
|
|
660
|
+
}
|
|
661
|
+
function markPrintedInRuntime() {
|
|
662
|
+
try {
|
|
663
|
+
Object.defineProperty(globalThis, BRANDING_MARKER, {
|
|
664
|
+
value: true,
|
|
665
|
+
configurable: false,
|
|
666
|
+
enumerable: false,
|
|
667
|
+
writable: false
|
|
668
|
+
});
|
|
669
|
+
} catch {
|
|
670
|
+
globalThis[BRANDING_MARKER] = true;
|
|
671
|
+
}
|
|
672
|
+
}
|
|
656
673
|
function printTiquoBranding() {
|
|
657
|
-
if (
|
|
658
|
-
if (typeof window === "undefined"
|
|
659
|
-
|
|
674
|
+
if (brandingPrinted) return;
|
|
675
|
+
if (typeof window === "undefined") return;
|
|
676
|
+
if (typeof console === "undefined") return;
|
|
677
|
+
if (hasPrintedInRuntime()) {
|
|
678
|
+
brandingPrinted = true;
|
|
679
|
+
return;
|
|
680
|
+
}
|
|
681
|
+
brandingPrinted = true;
|
|
660
682
|
try {
|
|
661
683
|
const art = [
|
|
662
684
|
" _ _ ",
|
|
@@ -675,9 +697,12 @@ function printTiquoBranding() {
|
|
|
675
697
|
"color:#6d28d9;font-size:11px",
|
|
676
698
|
"color:#6d28d9;font-size:11px;text-decoration:underline"
|
|
677
699
|
);
|
|
700
|
+
markPrintedInRuntime();
|
|
678
701
|
} catch {
|
|
679
702
|
}
|
|
680
703
|
}
|
|
704
|
+
|
|
705
|
+
// src/index.ts
|
|
681
706
|
printTiquoBranding();
|
|
682
707
|
var ANALYTICS_LOCATION_EVENT = "tiquo:locationchange";
|
|
683
708
|
var analyticsHistoryPatched = false;
|
|
@@ -1593,6 +1618,89 @@ var TiquoAuth = class {
|
|
|
1593
1618
|
const result = await response.json();
|
|
1594
1619
|
return result.data || { enquiries: [], hasMore: false };
|
|
1595
1620
|
}
|
|
1621
|
+
/**
|
|
1622
|
+
* Create a new enquiry through the DOM package.
|
|
1623
|
+
*
|
|
1624
|
+
* `customer.email` is required. If the current browser has an authenticated
|
|
1625
|
+
* DOM session, the enquiry is associated with that customer. Otherwise the
|
|
1626
|
+
* public key and allowed-domain configuration are used to accept the
|
|
1627
|
+
* submission, find or create a customer by email, and attach the enquiry.
|
|
1628
|
+
*
|
|
1629
|
+
* Submitted customer details fill missing customer profile fields only; they
|
|
1630
|
+
* do not overwrite existing profile data.
|
|
1631
|
+
*/
|
|
1632
|
+
async createEnquiry(input) {
|
|
1633
|
+
if (this.accessToken) {
|
|
1634
|
+
await this.refreshTokenIfNeeded();
|
|
1635
|
+
}
|
|
1636
|
+
const customer = { ...input.customer };
|
|
1637
|
+
if (!customer.email?.trim()) {
|
|
1638
|
+
throw new TiquoAuthError(
|
|
1639
|
+
"customer.email is required",
|
|
1640
|
+
"CREATE_ENQUIRY_FAILED"
|
|
1641
|
+
);
|
|
1642
|
+
}
|
|
1643
|
+
if (customer.phone !== void 0 && customer.phone !== "") {
|
|
1644
|
+
const normalized = normalizePhone(customer.phone);
|
|
1645
|
+
const validation = validatePhone(customer.phone);
|
|
1646
|
+
if (!validation.valid) {
|
|
1647
|
+
this.log(
|
|
1648
|
+
"\u26A0\uFE0F Phone validation warning:",
|
|
1649
|
+
validation.reason,
|
|
1650
|
+
"- Original:",
|
|
1651
|
+
customer.phone
|
|
1652
|
+
);
|
|
1653
|
+
}
|
|
1654
|
+
customer.phone = normalized || customer.phone;
|
|
1655
|
+
}
|
|
1656
|
+
const enquiry = { ...input.enquiry };
|
|
1657
|
+
if (!enquiry.message?.trim() && !enquiry.subject?.trim()) {
|
|
1658
|
+
throw new TiquoAuthError(
|
|
1659
|
+
"enquiry.message or enquiry.subject is required",
|
|
1660
|
+
"CREATE_ENQUIRY_FAILED"
|
|
1661
|
+
);
|
|
1662
|
+
}
|
|
1663
|
+
this.log("Creating customer enquiry:", {
|
|
1664
|
+
customer: { ...customer, email: customer.email },
|
|
1665
|
+
enquiry
|
|
1666
|
+
});
|
|
1667
|
+
const response = await this.request("/api/client/v1/enquiries", {
|
|
1668
|
+
method: "POST",
|
|
1669
|
+
headers: {
|
|
1670
|
+
"X-Public-Key": this.config.publicKey
|
|
1671
|
+
},
|
|
1672
|
+
body: JSON.stringify({
|
|
1673
|
+
publicKey: this.config.publicKey,
|
|
1674
|
+
customer,
|
|
1675
|
+
enquiry
|
|
1676
|
+
})
|
|
1677
|
+
});
|
|
1678
|
+
if (!response.ok) {
|
|
1679
|
+
const error = await response.json().catch(() => ({ error: "Failed to create enquiry" }));
|
|
1680
|
+
throw new TiquoAuthError(
|
|
1681
|
+
error.error || "Failed to create enquiry",
|
|
1682
|
+
"CREATE_ENQUIRY_FAILED",
|
|
1683
|
+
response.status
|
|
1684
|
+
);
|
|
1685
|
+
}
|
|
1686
|
+
const result = await response.json();
|
|
1687
|
+
const data = result.data || result;
|
|
1688
|
+
const createdCustomer = data.customer;
|
|
1689
|
+
if (this.session && createdCustomer) {
|
|
1690
|
+
this.session = {
|
|
1691
|
+
...this.session,
|
|
1692
|
+
customer: createdCustomer
|
|
1693
|
+
};
|
|
1694
|
+
this.notifyListeners();
|
|
1695
|
+
this.broadcastTabSync("SESSION_UPDATE");
|
|
1696
|
+
}
|
|
1697
|
+
this.analytics?.identify({ identityLinkType: "enquiry" }).catch(() => void 0);
|
|
1698
|
+
return {
|
|
1699
|
+
success: true,
|
|
1700
|
+
enquiry: data.enquiry,
|
|
1701
|
+
customer: createdCustomer
|
|
1702
|
+
};
|
|
1703
|
+
}
|
|
1596
1704
|
/**
|
|
1597
1705
|
* Get the companies the authenticated customer belongs to.
|
|
1598
1706
|
*
|
|
@@ -2307,6 +2415,7 @@ function useTiquoAuth(auth) {
|
|
|
2307
2415
|
getUpcomingBookings: (options) => auth.getUpcomingBookings(options),
|
|
2308
2416
|
getReceipt: (orderId) => auth.getReceipt(orderId),
|
|
2309
2417
|
getEnquiries: (options) => auth.getEnquiries(options),
|
|
2418
|
+
createEnquiry: (input) => auth.createEnquiry(input),
|
|
2310
2419
|
getCompanies: () => auth.getCompanies(),
|
|
2311
2420
|
getCompanyColleagues: (companyId) => auth.getCompanyColleagues(companyId),
|
|
2312
2421
|
getIframeToken: (flowId) => auth.getIframeToken(flowId),
|
|
@@ -2343,6 +2452,7 @@ var index_default = TiquoAuth;
|
|
|
2343
2452
|
getCustomerUserIds,
|
|
2344
2453
|
getPrefilledEmailFromCookie,
|
|
2345
2454
|
isDashboardSession,
|
|
2455
|
+
printTiquoBranding,
|
|
2346
2456
|
trackCustomerPresence,
|
|
2347
2457
|
useTiquoAuth
|
|
2348
2458
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -613,12 +613,33 @@ function buildPhone(countryCode, nationalNumber) {
|
|
|
613
613
|
return normalizePhone("+" + dc + digits);
|
|
614
614
|
}
|
|
615
615
|
|
|
616
|
-
// src/
|
|
617
|
-
var
|
|
616
|
+
// src/branding.ts
|
|
617
|
+
var BRANDING_MARKER = /* @__PURE__ */ Symbol.for("tiquo.domPackage.brandingPrinted");
|
|
618
|
+
var brandingPrinted = false;
|
|
619
|
+
function hasPrintedInRuntime() {
|
|
620
|
+
return Boolean(globalThis[BRANDING_MARKER]);
|
|
621
|
+
}
|
|
622
|
+
function markPrintedInRuntime() {
|
|
623
|
+
try {
|
|
624
|
+
Object.defineProperty(globalThis, BRANDING_MARKER, {
|
|
625
|
+
value: true,
|
|
626
|
+
configurable: false,
|
|
627
|
+
enumerable: false,
|
|
628
|
+
writable: false
|
|
629
|
+
});
|
|
630
|
+
} catch {
|
|
631
|
+
globalThis[BRANDING_MARKER] = true;
|
|
632
|
+
}
|
|
633
|
+
}
|
|
618
634
|
function printTiquoBranding() {
|
|
619
|
-
if (
|
|
620
|
-
if (typeof window === "undefined"
|
|
621
|
-
|
|
635
|
+
if (brandingPrinted) return;
|
|
636
|
+
if (typeof window === "undefined") return;
|
|
637
|
+
if (typeof console === "undefined") return;
|
|
638
|
+
if (hasPrintedInRuntime()) {
|
|
639
|
+
brandingPrinted = true;
|
|
640
|
+
return;
|
|
641
|
+
}
|
|
642
|
+
brandingPrinted = true;
|
|
622
643
|
try {
|
|
623
644
|
const art = [
|
|
624
645
|
" _ _ ",
|
|
@@ -637,9 +658,12 @@ function printTiquoBranding() {
|
|
|
637
658
|
"color:#6d28d9;font-size:11px",
|
|
638
659
|
"color:#6d28d9;font-size:11px;text-decoration:underline"
|
|
639
660
|
);
|
|
661
|
+
markPrintedInRuntime();
|
|
640
662
|
} catch {
|
|
641
663
|
}
|
|
642
664
|
}
|
|
665
|
+
|
|
666
|
+
// src/index.ts
|
|
643
667
|
printTiquoBranding();
|
|
644
668
|
var ANALYTICS_LOCATION_EVENT = "tiquo:locationchange";
|
|
645
669
|
var analyticsHistoryPatched = false;
|
|
@@ -1555,6 +1579,89 @@ var TiquoAuth = class {
|
|
|
1555
1579
|
const result = await response.json();
|
|
1556
1580
|
return result.data || { enquiries: [], hasMore: false };
|
|
1557
1581
|
}
|
|
1582
|
+
/**
|
|
1583
|
+
* Create a new enquiry through the DOM package.
|
|
1584
|
+
*
|
|
1585
|
+
* `customer.email` is required. If the current browser has an authenticated
|
|
1586
|
+
* DOM session, the enquiry is associated with that customer. Otherwise the
|
|
1587
|
+
* public key and allowed-domain configuration are used to accept the
|
|
1588
|
+
* submission, find or create a customer by email, and attach the enquiry.
|
|
1589
|
+
*
|
|
1590
|
+
* Submitted customer details fill missing customer profile fields only; they
|
|
1591
|
+
* do not overwrite existing profile data.
|
|
1592
|
+
*/
|
|
1593
|
+
async createEnquiry(input) {
|
|
1594
|
+
if (this.accessToken) {
|
|
1595
|
+
await this.refreshTokenIfNeeded();
|
|
1596
|
+
}
|
|
1597
|
+
const customer = { ...input.customer };
|
|
1598
|
+
if (!customer.email?.trim()) {
|
|
1599
|
+
throw new TiquoAuthError(
|
|
1600
|
+
"customer.email is required",
|
|
1601
|
+
"CREATE_ENQUIRY_FAILED"
|
|
1602
|
+
);
|
|
1603
|
+
}
|
|
1604
|
+
if (customer.phone !== void 0 && customer.phone !== "") {
|
|
1605
|
+
const normalized = normalizePhone(customer.phone);
|
|
1606
|
+
const validation = validatePhone(customer.phone);
|
|
1607
|
+
if (!validation.valid) {
|
|
1608
|
+
this.log(
|
|
1609
|
+
"\u26A0\uFE0F Phone validation warning:",
|
|
1610
|
+
validation.reason,
|
|
1611
|
+
"- Original:",
|
|
1612
|
+
customer.phone
|
|
1613
|
+
);
|
|
1614
|
+
}
|
|
1615
|
+
customer.phone = normalized || customer.phone;
|
|
1616
|
+
}
|
|
1617
|
+
const enquiry = { ...input.enquiry };
|
|
1618
|
+
if (!enquiry.message?.trim() && !enquiry.subject?.trim()) {
|
|
1619
|
+
throw new TiquoAuthError(
|
|
1620
|
+
"enquiry.message or enquiry.subject is required",
|
|
1621
|
+
"CREATE_ENQUIRY_FAILED"
|
|
1622
|
+
);
|
|
1623
|
+
}
|
|
1624
|
+
this.log("Creating customer enquiry:", {
|
|
1625
|
+
customer: { ...customer, email: customer.email },
|
|
1626
|
+
enquiry
|
|
1627
|
+
});
|
|
1628
|
+
const response = await this.request("/api/client/v1/enquiries", {
|
|
1629
|
+
method: "POST",
|
|
1630
|
+
headers: {
|
|
1631
|
+
"X-Public-Key": this.config.publicKey
|
|
1632
|
+
},
|
|
1633
|
+
body: JSON.stringify({
|
|
1634
|
+
publicKey: this.config.publicKey,
|
|
1635
|
+
customer,
|
|
1636
|
+
enquiry
|
|
1637
|
+
})
|
|
1638
|
+
});
|
|
1639
|
+
if (!response.ok) {
|
|
1640
|
+
const error = await response.json().catch(() => ({ error: "Failed to create enquiry" }));
|
|
1641
|
+
throw new TiquoAuthError(
|
|
1642
|
+
error.error || "Failed to create enquiry",
|
|
1643
|
+
"CREATE_ENQUIRY_FAILED",
|
|
1644
|
+
response.status
|
|
1645
|
+
);
|
|
1646
|
+
}
|
|
1647
|
+
const result = await response.json();
|
|
1648
|
+
const data = result.data || result;
|
|
1649
|
+
const createdCustomer = data.customer;
|
|
1650
|
+
if (this.session && createdCustomer) {
|
|
1651
|
+
this.session = {
|
|
1652
|
+
...this.session,
|
|
1653
|
+
customer: createdCustomer
|
|
1654
|
+
};
|
|
1655
|
+
this.notifyListeners();
|
|
1656
|
+
this.broadcastTabSync("SESSION_UPDATE");
|
|
1657
|
+
}
|
|
1658
|
+
this.analytics?.identify({ identityLinkType: "enquiry" }).catch(() => void 0);
|
|
1659
|
+
return {
|
|
1660
|
+
success: true,
|
|
1661
|
+
enquiry: data.enquiry,
|
|
1662
|
+
customer: createdCustomer
|
|
1663
|
+
};
|
|
1664
|
+
}
|
|
1558
1665
|
/**
|
|
1559
1666
|
* Get the companies the authenticated customer belongs to.
|
|
1560
1667
|
*
|
|
@@ -2269,6 +2376,7 @@ function useTiquoAuth(auth) {
|
|
|
2269
2376
|
getUpcomingBookings: (options) => auth.getUpcomingBookings(options),
|
|
2270
2377
|
getReceipt: (orderId) => auth.getReceipt(orderId),
|
|
2271
2378
|
getEnquiries: (options) => auth.getEnquiries(options),
|
|
2379
|
+
createEnquiry: (input) => auth.createEnquiry(input),
|
|
2272
2380
|
getCompanies: () => auth.getCompanies(),
|
|
2273
2381
|
getCompanyColleagues: (companyId) => auth.getCompanyColleagues(companyId),
|
|
2274
2382
|
getIframeToken: (flowId) => auth.getIframeToken(flowId),
|
|
@@ -2305,6 +2413,7 @@ export {
|
|
|
2305
2413
|
getCustomerUserIds,
|
|
2306
2414
|
getPrefilledEmailFromCookie,
|
|
2307
2415
|
isDashboardSession,
|
|
2416
|
+
printTiquoBranding,
|
|
2308
2417
|
trackCustomerPresence,
|
|
2309
2418
|
useTiquoAuth
|
|
2310
2419
|
};
|
package/package.json
CHANGED