@tiquo/dom-package 1.5.3 → 1.6.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 CHANGED
@@ -277,6 +277,32 @@ const page2 = await auth.getEnquiries({ limit: 10, cursor: page1.nextCursor });
277
277
  - `hasMore` - Whether there are more enquiries to fetch
278
278
  - `nextCursor` - Cursor for the next page (if `hasMore` is true)
279
279
 
280
+ #### `createEnquiry(input): Promise<CreateEnquiryResult>`
281
+
282
+ 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.
283
+
284
+ Submitted customer fields fill missing profile data only; existing names, phones, and customer parameter values are not overwritten.
285
+
286
+ ```typescript
287
+ const { enquiry, customer } = await auth.createEnquiry({
288
+ customer: {
289
+ email: 'customer@example.com',
290
+ firstName: 'Sam',
291
+ lastName: 'Taylor',
292
+ phone: '+44 7911 123456',
293
+ details: {
294
+ system_marketing_opt_in: true,
295
+ },
296
+ },
297
+ enquiry: {
298
+ subject: 'Private event request',
299
+ message: 'I would like to enquire about availability next Friday.',
300
+ category: 'events',
301
+ priority: 'medium',
302
+ },
303
+ });
304
+ ```
305
+
280
306
  #### `destroy(): void`
281
307
 
282
308
  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
@@ -622,6 +622,40 @@ interface GetEnquiriesResult {
622
622
  hasMore: boolean;
623
623
  nextCursor?: string;
624
624
  }
625
+ interface CreateEnquiryCustomerData {
626
+ /** Required. Used to find or create the customer profile for this enquiry. */
627
+ email: string;
628
+ firstName?: string;
629
+ lastName?: string;
630
+ /**
631
+ * Primary phone number in E.164 format. The SDK auto-normalizes common
632
+ * formats before submission.
633
+ */
634
+ phone?: string;
635
+ /**
636
+ * Additional customer parameter values keyed by system parameter id
637
+ * (`system_marketing_opt_in`) or customer parameter schema id. Existing
638
+ * non-empty values are not overwritten.
639
+ */
640
+ details?: Record<string, string | number | boolean | null>;
641
+ }
642
+ interface CreateEnquiryData {
643
+ customer: CreateEnquiryCustomerData;
644
+ enquiry: {
645
+ type?: string;
646
+ subject?: string;
647
+ /** Required unless `subject` is supplied. */
648
+ message?: string;
649
+ category?: string;
650
+ priority?: "low" | "medium" | "high" | "urgent";
651
+ source?: "online" | "website" | "phone" | "email" | "walk_in" | "social" | "referral" | "pos" | "admin";
652
+ };
653
+ }
654
+ interface CreateEnquiryResult {
655
+ success: boolean;
656
+ enquiry: TiquoEnquiry;
657
+ customer: TiquoCustomer;
658
+ }
625
659
  type TiquoCompanyRelationship = "employee" | "contractor" | "manager" | "executive" | "owner" | "contact" | "other";
626
660
  /**
627
661
  * The authenticated customer's membership in a company. Each company the
@@ -823,6 +857,18 @@ declare class TiquoAuth {
823
857
  * Only returns enquiries for the logged-in customer
824
858
  */
825
859
  getEnquiries(options?: GetEnquiriesOptions): Promise<GetEnquiriesResult>;
860
+ /**
861
+ * Create a new enquiry through the DOM package.
862
+ *
863
+ * `customer.email` is required. If the current browser has an authenticated
864
+ * DOM session, the enquiry is associated with that customer. Otherwise the
865
+ * public key and allowed-domain configuration are used to accept the
866
+ * submission, find or create a customer by email, and attach the enquiry.
867
+ *
868
+ * Submitted customer details fill missing customer profile fields only; they
869
+ * do not overwrite existing profile data.
870
+ */
871
+ createEnquiry(input: CreateEnquiryData): Promise<CreateEnquiryResult>;
826
872
  /**
827
873
  * Get the companies the authenticated customer belongs to.
828
874
  *
@@ -946,6 +992,7 @@ declare function useTiquoAuth(auth: TiquoAuth): {
946
992
  getUpcomingBookings: (options?: Omit<GetBookingsOptions, "upcoming">) => Promise<GetBookingsResult>;
947
993
  getReceipt: (orderId: string) => Promise<TiquoReceipt>;
948
994
  getEnquiries: (options?: GetEnquiriesOptions) => Promise<GetEnquiriesResult>;
995
+ createEnquiry: (input: CreateEnquiryData) => Promise<CreateEnquiryResult>;
949
996
  getCompanies: () => Promise<GetCompaniesResult>;
950
997
  getCompanyColleagues: (companyId: string) => Promise<GetCompanyColleaguesResult>;
951
998
  getIframeToken: (flowId?: string) => Promise<IframeTokenResult>;
@@ -1010,4 +1057,4 @@ declare class TiquoPhone {
1010
1057
  static buildPhone: typeof buildPhone;
1011
1058
  }
1012
1059
 
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 };
1060
+ 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, trackCustomerPresence, useTiquoAuth };
package/dist/index.d.ts CHANGED
@@ -622,6 +622,40 @@ interface GetEnquiriesResult {
622
622
  hasMore: boolean;
623
623
  nextCursor?: string;
624
624
  }
625
+ interface CreateEnquiryCustomerData {
626
+ /** Required. Used to find or create the customer profile for this enquiry. */
627
+ email: string;
628
+ firstName?: string;
629
+ lastName?: string;
630
+ /**
631
+ * Primary phone number in E.164 format. The SDK auto-normalizes common
632
+ * formats before submission.
633
+ */
634
+ phone?: string;
635
+ /**
636
+ * Additional customer parameter values keyed by system parameter id
637
+ * (`system_marketing_opt_in`) or customer parameter schema id. Existing
638
+ * non-empty values are not overwritten.
639
+ */
640
+ details?: Record<string, string | number | boolean | null>;
641
+ }
642
+ interface CreateEnquiryData {
643
+ customer: CreateEnquiryCustomerData;
644
+ enquiry: {
645
+ type?: string;
646
+ subject?: string;
647
+ /** Required unless `subject` is supplied. */
648
+ message?: string;
649
+ category?: string;
650
+ priority?: "low" | "medium" | "high" | "urgent";
651
+ source?: "online" | "website" | "phone" | "email" | "walk_in" | "social" | "referral" | "pos" | "admin";
652
+ };
653
+ }
654
+ interface CreateEnquiryResult {
655
+ success: boolean;
656
+ enquiry: TiquoEnquiry;
657
+ customer: TiquoCustomer;
658
+ }
625
659
  type TiquoCompanyRelationship = "employee" | "contractor" | "manager" | "executive" | "owner" | "contact" | "other";
626
660
  /**
627
661
  * The authenticated customer's membership in a company. Each company the
@@ -823,6 +857,18 @@ declare class TiquoAuth {
823
857
  * Only returns enquiries for the logged-in customer
824
858
  */
825
859
  getEnquiries(options?: GetEnquiriesOptions): Promise<GetEnquiriesResult>;
860
+ /**
861
+ * Create a new enquiry through the DOM package.
862
+ *
863
+ * `customer.email` is required. If the current browser has an authenticated
864
+ * DOM session, the enquiry is associated with that customer. Otherwise the
865
+ * public key and allowed-domain configuration are used to accept the
866
+ * submission, find or create a customer by email, and attach the enquiry.
867
+ *
868
+ * Submitted customer details fill missing customer profile fields only; they
869
+ * do not overwrite existing profile data.
870
+ */
871
+ createEnquiry(input: CreateEnquiryData): Promise<CreateEnquiryResult>;
826
872
  /**
827
873
  * Get the companies the authenticated customer belongs to.
828
874
  *
@@ -946,6 +992,7 @@ declare function useTiquoAuth(auth: TiquoAuth): {
946
992
  getUpcomingBookings: (options?: Omit<GetBookingsOptions, "upcoming">) => Promise<GetBookingsResult>;
947
993
  getReceipt: (orderId: string) => Promise<TiquoReceipt>;
948
994
  getEnquiries: (options?: GetEnquiriesOptions) => Promise<GetEnquiriesResult>;
995
+ createEnquiry: (input: CreateEnquiryData) => Promise<CreateEnquiryResult>;
949
996
  getCompanies: () => Promise<GetCompaniesResult>;
950
997
  getCompanyColleagues: (companyId: string) => Promise<GetCompanyColleaguesResult>;
951
998
  getIframeToken: (flowId?: string) => Promise<IframeTokenResult>;
@@ -1010,4 +1057,4 @@ declare class TiquoPhone {
1010
1057
  static buildPhone: typeof buildPhone;
1011
1058
  }
1012
1059
 
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 };
1060
+ 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, trackCustomerPresence, useTiquoAuth };
package/dist/index.js CHANGED
@@ -1593,6 +1593,89 @@ var TiquoAuth = class {
1593
1593
  const result = await response.json();
1594
1594
  return result.data || { enquiries: [], hasMore: false };
1595
1595
  }
1596
+ /**
1597
+ * Create a new enquiry through the DOM package.
1598
+ *
1599
+ * `customer.email` is required. If the current browser has an authenticated
1600
+ * DOM session, the enquiry is associated with that customer. Otherwise the
1601
+ * public key and allowed-domain configuration are used to accept the
1602
+ * submission, find or create a customer by email, and attach the enquiry.
1603
+ *
1604
+ * Submitted customer details fill missing customer profile fields only; they
1605
+ * do not overwrite existing profile data.
1606
+ */
1607
+ async createEnquiry(input) {
1608
+ if (this.accessToken) {
1609
+ await this.refreshTokenIfNeeded();
1610
+ }
1611
+ const customer = { ...input.customer };
1612
+ if (!customer.email?.trim()) {
1613
+ throw new TiquoAuthError(
1614
+ "customer.email is required",
1615
+ "CREATE_ENQUIRY_FAILED"
1616
+ );
1617
+ }
1618
+ if (customer.phone !== void 0 && customer.phone !== "") {
1619
+ const normalized = normalizePhone(customer.phone);
1620
+ const validation = validatePhone(customer.phone);
1621
+ if (!validation.valid) {
1622
+ this.log(
1623
+ "\u26A0\uFE0F Phone validation warning:",
1624
+ validation.reason,
1625
+ "- Original:",
1626
+ customer.phone
1627
+ );
1628
+ }
1629
+ customer.phone = normalized || customer.phone;
1630
+ }
1631
+ const enquiry = { ...input.enquiry };
1632
+ if (!enquiry.message?.trim() && !enquiry.subject?.trim()) {
1633
+ throw new TiquoAuthError(
1634
+ "enquiry.message or enquiry.subject is required",
1635
+ "CREATE_ENQUIRY_FAILED"
1636
+ );
1637
+ }
1638
+ this.log("Creating customer enquiry:", {
1639
+ customer: { ...customer, email: customer.email },
1640
+ enquiry
1641
+ });
1642
+ const response = await this.request("/api/client/v1/enquiries", {
1643
+ method: "POST",
1644
+ headers: {
1645
+ "X-Public-Key": this.config.publicKey
1646
+ },
1647
+ body: JSON.stringify({
1648
+ publicKey: this.config.publicKey,
1649
+ customer,
1650
+ enquiry
1651
+ })
1652
+ });
1653
+ if (!response.ok) {
1654
+ const error = await response.json().catch(() => ({ error: "Failed to create enquiry" }));
1655
+ throw new TiquoAuthError(
1656
+ error.error || "Failed to create enquiry",
1657
+ "CREATE_ENQUIRY_FAILED",
1658
+ response.status
1659
+ );
1660
+ }
1661
+ const result = await response.json();
1662
+ const data = result.data || result;
1663
+ const createdCustomer = data.customer;
1664
+ if (this.session && createdCustomer) {
1665
+ this.session = {
1666
+ ...this.session,
1667
+ customer: createdCustomer
1668
+ };
1669
+ this.notifyListeners();
1670
+ this.broadcastTabSync("SESSION_UPDATE");
1671
+ }
1672
+ this.analytics?.identify({ identityLinkType: "enquiry" }).catch(() => void 0);
1673
+ return {
1674
+ success: true,
1675
+ enquiry: data.enquiry,
1676
+ customer: createdCustomer
1677
+ };
1678
+ }
1596
1679
  /**
1597
1680
  * Get the companies the authenticated customer belongs to.
1598
1681
  *
@@ -2307,6 +2390,7 @@ function useTiquoAuth(auth) {
2307
2390
  getUpcomingBookings: (options) => auth.getUpcomingBookings(options),
2308
2391
  getReceipt: (orderId) => auth.getReceipt(orderId),
2309
2392
  getEnquiries: (options) => auth.getEnquiries(options),
2393
+ createEnquiry: (input) => auth.createEnquiry(input),
2310
2394
  getCompanies: () => auth.getCompanies(),
2311
2395
  getCompanyColleagues: (companyId) => auth.getCompanyColleagues(companyId),
2312
2396
  getIframeToken: (flowId) => auth.getIframeToken(flowId),
package/dist/index.mjs CHANGED
@@ -1555,6 +1555,89 @@ var TiquoAuth = class {
1555
1555
  const result = await response.json();
1556
1556
  return result.data || { enquiries: [], hasMore: false };
1557
1557
  }
1558
+ /**
1559
+ * Create a new enquiry through the DOM package.
1560
+ *
1561
+ * `customer.email` is required. If the current browser has an authenticated
1562
+ * DOM session, the enquiry is associated with that customer. Otherwise the
1563
+ * public key and allowed-domain configuration are used to accept the
1564
+ * submission, find or create a customer by email, and attach the enquiry.
1565
+ *
1566
+ * Submitted customer details fill missing customer profile fields only; they
1567
+ * do not overwrite existing profile data.
1568
+ */
1569
+ async createEnquiry(input) {
1570
+ if (this.accessToken) {
1571
+ await this.refreshTokenIfNeeded();
1572
+ }
1573
+ const customer = { ...input.customer };
1574
+ if (!customer.email?.trim()) {
1575
+ throw new TiquoAuthError(
1576
+ "customer.email is required",
1577
+ "CREATE_ENQUIRY_FAILED"
1578
+ );
1579
+ }
1580
+ if (customer.phone !== void 0 && customer.phone !== "") {
1581
+ const normalized = normalizePhone(customer.phone);
1582
+ const validation = validatePhone(customer.phone);
1583
+ if (!validation.valid) {
1584
+ this.log(
1585
+ "\u26A0\uFE0F Phone validation warning:",
1586
+ validation.reason,
1587
+ "- Original:",
1588
+ customer.phone
1589
+ );
1590
+ }
1591
+ customer.phone = normalized || customer.phone;
1592
+ }
1593
+ const enquiry = { ...input.enquiry };
1594
+ if (!enquiry.message?.trim() && !enquiry.subject?.trim()) {
1595
+ throw new TiquoAuthError(
1596
+ "enquiry.message or enquiry.subject is required",
1597
+ "CREATE_ENQUIRY_FAILED"
1598
+ );
1599
+ }
1600
+ this.log("Creating customer enquiry:", {
1601
+ customer: { ...customer, email: customer.email },
1602
+ enquiry
1603
+ });
1604
+ const response = await this.request("/api/client/v1/enquiries", {
1605
+ method: "POST",
1606
+ headers: {
1607
+ "X-Public-Key": this.config.publicKey
1608
+ },
1609
+ body: JSON.stringify({
1610
+ publicKey: this.config.publicKey,
1611
+ customer,
1612
+ enquiry
1613
+ })
1614
+ });
1615
+ if (!response.ok) {
1616
+ const error = await response.json().catch(() => ({ error: "Failed to create enquiry" }));
1617
+ throw new TiquoAuthError(
1618
+ error.error || "Failed to create enquiry",
1619
+ "CREATE_ENQUIRY_FAILED",
1620
+ response.status
1621
+ );
1622
+ }
1623
+ const result = await response.json();
1624
+ const data = result.data || result;
1625
+ const createdCustomer = data.customer;
1626
+ if (this.session && createdCustomer) {
1627
+ this.session = {
1628
+ ...this.session,
1629
+ customer: createdCustomer
1630
+ };
1631
+ this.notifyListeners();
1632
+ this.broadcastTabSync("SESSION_UPDATE");
1633
+ }
1634
+ this.analytics?.identify({ identityLinkType: "enquiry" }).catch(() => void 0);
1635
+ return {
1636
+ success: true,
1637
+ enquiry: data.enquiry,
1638
+ customer: createdCustomer
1639
+ };
1640
+ }
1558
1641
  /**
1559
1642
  * Get the companies the authenticated customer belongs to.
1560
1643
  *
@@ -2269,6 +2352,7 @@ function useTiquoAuth(auth) {
2269
2352
  getUpcomingBookings: (options) => auth.getUpcomingBookings(options),
2270
2353
  getReceipt: (orderId) => auth.getReceipt(orderId),
2271
2354
  getEnquiries: (options) => auth.getEnquiries(options),
2355
+ createEnquiry: (input) => auth.createEnquiry(input),
2272
2356
  getCompanies: () => auth.getCompanies(),
2273
2357
  getCompanyColleagues: (companyId) => auth.getCompanyColleagues(companyId),
2274
2358
  getIframeToken: (flowId) => auth.getIframeToken(flowId),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tiquo/dom-package",
3
- "version": "1.5.3",
3
+ "version": "1.6.0",
4
4
  "description": "Tiquo SDK for third-party websites - authentication, customer profiles, orders, bookings, enquiries, receipts, and companies",
5
5
  "sideEffects": true,
6
6
  "publishConfig": {