@tiquo/dom-package 1.3.1 → 1.3.3

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
@@ -174,7 +174,7 @@ const completedOrders = await auth.getOrders({ status: 'completed' });
174
174
  **Options:**
175
175
  - `limit` - Number of orders to return (max 100, default 50)
176
176
  - `cursor` - Order ID to start after (for pagination)
177
- - `status` - Filter by status: `draft`, `pending`, `confirmed`, `processing`, `completed`, `cancelled`, `refunded`, `open_tab`
177
+ - `status` - Filter by status: `draft`, `pending`, `processing`, `completed`, `cancelled`, `refunded`, `open_tab`
178
178
 
179
179
  **Returns:**
180
180
  - `orders` - Array of order objects with items, totals, and status
package/dist/index.d.mts CHANGED
@@ -231,6 +231,9 @@ declare global {
231
231
  accessToken: string;
232
232
  refreshToken?: string;
233
233
  };
234
+ __tiquo_get_iframe_token?: () => Promise<{
235
+ token: string;
236
+ }>;
234
237
  }
235
238
  }
236
239
  interface TiquoUser {
@@ -325,7 +328,7 @@ interface TiquoOrderItem {
325
328
  interface TiquoOrder {
326
329
  id: string;
327
330
  orderNumber: string;
328
- status: 'draft' | 'pending' | 'confirmed' | 'processing' | 'completed' | 'cancelled' | 'refunded' | 'open_tab';
331
+ status: 'draft' | 'pending' | 'processing' | 'completed' | 'cancelled' | 'refunded' | 'open_tab';
329
332
  paymentStatus: 'pending' | 'paid' | 'partial' | 'refunded' | 'partially_refunded' | 'failed' | 'cancelled';
330
333
  total: number;
331
334
  subtotal: number;
@@ -418,6 +421,8 @@ declare class TiquoAuth {
418
421
  private refreshTimer;
419
422
  private isRefreshing;
420
423
  private visibilityHandler;
424
+ private iframeObserver;
425
+ private injectedIframes;
421
426
  private broadcastChannel;
422
427
  private tabId;
423
428
  private isProcessingTabSync;
@@ -490,6 +495,17 @@ declare class TiquoAuth {
490
495
  onLoad?: () => void;
491
496
  onError?: (error: Error) => void;
492
497
  }): Promise<HTMLIFrameElement>;
498
+ /**
499
+ * Automatically find and inject auth tokens into existing Tiquo booking
500
+ * iframes on the page. Also watches for iframes added later via
501
+ * MutationObserver. This enables token injection even when the site uses
502
+ * a static <iframe> embed snippet rather than embedCustomerFlow().
503
+ */
504
+ private autoInjectIframeTokens;
505
+ private scanAndInjectIframes;
506
+ private injectTokenIntoIframe;
507
+ private isTiquoEmbedUrl;
508
+ private observeNewIframes;
493
509
  /**
494
510
  * Get the current access token (for advanced use cases)
495
511
  */
package/dist/index.d.ts CHANGED
@@ -231,6 +231,9 @@ declare global {
231
231
  accessToken: string;
232
232
  refreshToken?: string;
233
233
  };
234
+ __tiquo_get_iframe_token?: () => Promise<{
235
+ token: string;
236
+ }>;
234
237
  }
235
238
  }
236
239
  interface TiquoUser {
@@ -325,7 +328,7 @@ interface TiquoOrderItem {
325
328
  interface TiquoOrder {
326
329
  id: string;
327
330
  orderNumber: string;
328
- status: 'draft' | 'pending' | 'confirmed' | 'processing' | 'completed' | 'cancelled' | 'refunded' | 'open_tab';
331
+ status: 'draft' | 'pending' | 'processing' | 'completed' | 'cancelled' | 'refunded' | 'open_tab';
329
332
  paymentStatus: 'pending' | 'paid' | 'partial' | 'refunded' | 'partially_refunded' | 'failed' | 'cancelled';
330
333
  total: number;
331
334
  subtotal: number;
@@ -418,6 +421,8 @@ declare class TiquoAuth {
418
421
  private refreshTimer;
419
422
  private isRefreshing;
420
423
  private visibilityHandler;
424
+ private iframeObserver;
425
+ private injectedIframes;
421
426
  private broadcastChannel;
422
427
  private tabId;
423
428
  private isProcessingTabSync;
@@ -490,6 +495,17 @@ declare class TiquoAuth {
490
495
  onLoad?: () => void;
491
496
  onError?: (error: Error) => void;
492
497
  }): Promise<HTMLIFrameElement>;
498
+ /**
499
+ * Automatically find and inject auth tokens into existing Tiquo booking
500
+ * iframes on the page. Also watches for iframes added later via
501
+ * MutationObserver. This enables token injection even when the site uses
502
+ * a static <iframe> embed snippet rather than embedCustomerFlow().
503
+ */
504
+ private autoInjectIframeTokens;
505
+ private scanAndInjectIframes;
506
+ private injectTokenIntoIframe;
507
+ private isTiquoEmbedUrl;
508
+ private observeNewIframes;
493
509
  /**
494
510
  * Get the current access token (for advanced use cases)
495
511
  */
package/dist/index.js CHANGED
@@ -650,6 +650,33 @@ function buildPhone(countryCode, nationalNumber) {
650
650
  }
651
651
 
652
652
  // src/index.ts
653
+ var _brandingPrinted = false;
654
+ function printTiquoBranding() {
655
+ if (_brandingPrinted) return;
656
+ if (typeof window === "undefined" || typeof console === "undefined") return;
657
+ _brandingPrinted = true;
658
+ try {
659
+ const art = [
660
+ " _ _ ",
661
+ "| |_(_) __ _ _ _ ___ ",
662
+ "| __| |/ _` | | | |/ _ \\ ",
663
+ "| |_| | (_| | |_| | (_) |",
664
+ " \\__|_|\\__, |\\__,_|\\___/ ",
665
+ " |_| "
666
+ ].join("\n");
667
+ console.log(
668
+ `%c${art}`,
669
+ "color:#6d28d9;font-weight:bold;font-size:12px;font-family:monospace"
670
+ );
671
+ console.log(
672
+ "%cLearn more at %chttps://tiquo.co",
673
+ "color:#6d28d9;font-size:11px",
674
+ "color:#6d28d9;font-size:11px;text-decoration:underline"
675
+ );
676
+ } catch {
677
+ }
678
+ }
679
+ printTiquoBranding();
653
680
  var TiquoAuthError = class extends Error {
654
681
  constructor(message, code, statusCode) {
655
682
  super(message);
@@ -685,9 +712,12 @@ var TiquoAuth = class {
685
712
  this.refreshTimer = null;
686
713
  this.isRefreshing = false;
687
714
  this.visibilityHandler = null;
715
+ this.iframeObserver = null;
716
+ this.injectedIframes = /* @__PURE__ */ new WeakSet();
688
717
  // Multi-tab sync
689
718
  this.broadcastChannel = null;
690
719
  this.isProcessingTabSync = false;
720
+ printTiquoBranding();
691
721
  if (!config.publicKey) {
692
722
  throw new TiquoAuthError("publicKey is required", "MISSING_PUBLIC_KEY");
693
723
  }
@@ -714,6 +744,7 @@ var TiquoAuth = class {
714
744
  this.checkForInjectedTokens();
715
745
  this.restoreTokens();
716
746
  this.initVisibilityHandler();
747
+ this.autoInjectIframeTokens();
717
748
  }
718
749
  // ============================================
719
750
  // PUBLIC METHODS
@@ -1045,6 +1076,77 @@ var TiquoAuth = class {
1045
1076
  containerEl.appendChild(iframe);
1046
1077
  return iframe;
1047
1078
  }
1079
+ /**
1080
+ * Automatically find and inject auth tokens into existing Tiquo booking
1081
+ * iframes on the page. Also watches for iframes added later via
1082
+ * MutationObserver. This enables token injection even when the site uses
1083
+ * a static <iframe> embed snippet rather than embedCustomerFlow().
1084
+ */
1085
+ autoInjectIframeTokens() {
1086
+ if (typeof document === "undefined") return;
1087
+ if (!this.accessToken) return;
1088
+ if (typeof window !== "undefined") {
1089
+ window.__tiquo_get_iframe_token = () => this.getIframeToken();
1090
+ }
1091
+ Promise.resolve().then(() => this.scanAndInjectIframes());
1092
+ this.observeNewIframes();
1093
+ }
1094
+ async scanAndInjectIframes() {
1095
+ if (!this.accessToken) return;
1096
+ const iframes = document.querySelectorAll("iframe");
1097
+ for (const iframe of iframes) {
1098
+ await this.injectTokenIntoIframe(iframe);
1099
+ }
1100
+ }
1101
+ async injectTokenIntoIframe(iframe) {
1102
+ if (this.injectedIframes.has(iframe)) return;
1103
+ const src = iframe.src || iframe.getAttribute("src") || "";
1104
+ if (!src) return;
1105
+ try {
1106
+ const url = new URL(src, window.location.origin);
1107
+ if (!this.isTiquoEmbedUrl(url)) return;
1108
+ if (url.searchParams.has("_auth_token")) {
1109
+ this.injectedIframes.add(iframe);
1110
+ return;
1111
+ }
1112
+ const { token } = await this.getIframeToken();
1113
+ url.searchParams.set("_auth_token", token);
1114
+ this.injectedIframes.add(iframe);
1115
+ iframe.src = url.toString();
1116
+ this.log("Injected auth token into existing iframe:", url.pathname);
1117
+ } catch (error) {
1118
+ this.log("Failed to inject token into iframe:", error);
1119
+ }
1120
+ }
1121
+ isTiquoEmbedUrl(url) {
1122
+ const hostname = url.hostname;
1123
+ const isTiquoHost = hostname === "book.tiquo.app" || hostname.endsWith(".tiquo.app") || hostname === "localhost";
1124
+ return isTiquoHost && url.pathname.startsWith("/embed/");
1125
+ }
1126
+ observeNewIframes() {
1127
+ if (typeof MutationObserver === "undefined") return;
1128
+ if (this.iframeObserver) return;
1129
+ this.iframeObserver = new MutationObserver((mutations) => {
1130
+ if (!this.accessToken) return;
1131
+ for (const mutation of mutations) {
1132
+ for (const node of mutation.addedNodes) {
1133
+ if (node instanceof HTMLIFrameElement) {
1134
+ this.injectTokenIntoIframe(node);
1135
+ }
1136
+ if (node instanceof HTMLElement) {
1137
+ const nested = node.querySelectorAll("iframe");
1138
+ for (const iframe of nested) {
1139
+ this.injectTokenIntoIframe(iframe);
1140
+ }
1141
+ }
1142
+ }
1143
+ }
1144
+ });
1145
+ this.iframeObserver.observe(document.body || document.documentElement, {
1146
+ childList: true,
1147
+ subtree: true
1148
+ });
1149
+ }
1048
1150
  /**
1049
1151
  * Get the current access token (for advanced use cases)
1050
1152
  */
@@ -1441,6 +1543,13 @@ var TiquoAuth = class {
1441
1543
  this.broadcastChannel.close();
1442
1544
  this.broadcastChannel = null;
1443
1545
  }
1546
+ if (this.iframeObserver) {
1547
+ this.iframeObserver.disconnect();
1548
+ this.iframeObserver = null;
1549
+ }
1550
+ if (typeof window !== "undefined") {
1551
+ delete window.__tiquo_get_iframe_token;
1552
+ }
1444
1553
  this.listeners.clear();
1445
1554
  }
1446
1555
  };
package/dist/index.mjs CHANGED
@@ -614,6 +614,33 @@ function buildPhone(countryCode, nationalNumber) {
614
614
  }
615
615
 
616
616
  // src/index.ts
617
+ var _brandingPrinted = false;
618
+ function printTiquoBranding() {
619
+ if (_brandingPrinted) return;
620
+ if (typeof window === "undefined" || typeof console === "undefined") return;
621
+ _brandingPrinted = true;
622
+ try {
623
+ const art = [
624
+ " _ _ ",
625
+ "| |_(_) __ _ _ _ ___ ",
626
+ "| __| |/ _` | | | |/ _ \\ ",
627
+ "| |_| | (_| | |_| | (_) |",
628
+ " \\__|_|\\__, |\\__,_|\\___/ ",
629
+ " |_| "
630
+ ].join("\n");
631
+ console.log(
632
+ `%c${art}`,
633
+ "color:#6d28d9;font-weight:bold;font-size:12px;font-family:monospace"
634
+ );
635
+ console.log(
636
+ "%cLearn more at %chttps://tiquo.co",
637
+ "color:#6d28d9;font-size:11px",
638
+ "color:#6d28d9;font-size:11px;text-decoration:underline"
639
+ );
640
+ } catch {
641
+ }
642
+ }
643
+ printTiquoBranding();
617
644
  var TiquoAuthError = class extends Error {
618
645
  constructor(message, code, statusCode) {
619
646
  super(message);
@@ -649,9 +676,12 @@ var TiquoAuth = class {
649
676
  this.refreshTimer = null;
650
677
  this.isRefreshing = false;
651
678
  this.visibilityHandler = null;
679
+ this.iframeObserver = null;
680
+ this.injectedIframes = /* @__PURE__ */ new WeakSet();
652
681
  // Multi-tab sync
653
682
  this.broadcastChannel = null;
654
683
  this.isProcessingTabSync = false;
684
+ printTiquoBranding();
655
685
  if (!config.publicKey) {
656
686
  throw new TiquoAuthError("publicKey is required", "MISSING_PUBLIC_KEY");
657
687
  }
@@ -678,6 +708,7 @@ var TiquoAuth = class {
678
708
  this.checkForInjectedTokens();
679
709
  this.restoreTokens();
680
710
  this.initVisibilityHandler();
711
+ this.autoInjectIframeTokens();
681
712
  }
682
713
  // ============================================
683
714
  // PUBLIC METHODS
@@ -1009,6 +1040,77 @@ var TiquoAuth = class {
1009
1040
  containerEl.appendChild(iframe);
1010
1041
  return iframe;
1011
1042
  }
1043
+ /**
1044
+ * Automatically find and inject auth tokens into existing Tiquo booking
1045
+ * iframes on the page. Also watches for iframes added later via
1046
+ * MutationObserver. This enables token injection even when the site uses
1047
+ * a static <iframe> embed snippet rather than embedCustomerFlow().
1048
+ */
1049
+ autoInjectIframeTokens() {
1050
+ if (typeof document === "undefined") return;
1051
+ if (!this.accessToken) return;
1052
+ if (typeof window !== "undefined") {
1053
+ window.__tiquo_get_iframe_token = () => this.getIframeToken();
1054
+ }
1055
+ Promise.resolve().then(() => this.scanAndInjectIframes());
1056
+ this.observeNewIframes();
1057
+ }
1058
+ async scanAndInjectIframes() {
1059
+ if (!this.accessToken) return;
1060
+ const iframes = document.querySelectorAll("iframe");
1061
+ for (const iframe of iframes) {
1062
+ await this.injectTokenIntoIframe(iframe);
1063
+ }
1064
+ }
1065
+ async injectTokenIntoIframe(iframe) {
1066
+ if (this.injectedIframes.has(iframe)) return;
1067
+ const src = iframe.src || iframe.getAttribute("src") || "";
1068
+ if (!src) return;
1069
+ try {
1070
+ const url = new URL(src, window.location.origin);
1071
+ if (!this.isTiquoEmbedUrl(url)) return;
1072
+ if (url.searchParams.has("_auth_token")) {
1073
+ this.injectedIframes.add(iframe);
1074
+ return;
1075
+ }
1076
+ const { token } = await this.getIframeToken();
1077
+ url.searchParams.set("_auth_token", token);
1078
+ this.injectedIframes.add(iframe);
1079
+ iframe.src = url.toString();
1080
+ this.log("Injected auth token into existing iframe:", url.pathname);
1081
+ } catch (error) {
1082
+ this.log("Failed to inject token into iframe:", error);
1083
+ }
1084
+ }
1085
+ isTiquoEmbedUrl(url) {
1086
+ const hostname = url.hostname;
1087
+ const isTiquoHost = hostname === "book.tiquo.app" || hostname.endsWith(".tiquo.app") || hostname === "localhost";
1088
+ return isTiquoHost && url.pathname.startsWith("/embed/");
1089
+ }
1090
+ observeNewIframes() {
1091
+ if (typeof MutationObserver === "undefined") return;
1092
+ if (this.iframeObserver) return;
1093
+ this.iframeObserver = new MutationObserver((mutations) => {
1094
+ if (!this.accessToken) return;
1095
+ for (const mutation of mutations) {
1096
+ for (const node of mutation.addedNodes) {
1097
+ if (node instanceof HTMLIFrameElement) {
1098
+ this.injectTokenIntoIframe(node);
1099
+ }
1100
+ if (node instanceof HTMLElement) {
1101
+ const nested = node.querySelectorAll("iframe");
1102
+ for (const iframe of nested) {
1103
+ this.injectTokenIntoIframe(iframe);
1104
+ }
1105
+ }
1106
+ }
1107
+ }
1108
+ });
1109
+ this.iframeObserver.observe(document.body || document.documentElement, {
1110
+ childList: true,
1111
+ subtree: true
1112
+ });
1113
+ }
1012
1114
  /**
1013
1115
  * Get the current access token (for advanced use cases)
1014
1116
  */
@@ -1405,6 +1507,13 @@ var TiquoAuth = class {
1405
1507
  this.broadcastChannel.close();
1406
1508
  this.broadcastChannel = null;
1407
1509
  }
1510
+ if (this.iframeObserver) {
1511
+ this.iframeObserver.disconnect();
1512
+ this.iframeObserver = null;
1513
+ }
1514
+ if (typeof window !== "undefined") {
1515
+ delete window.__tiquo_get_iframe_token;
1516
+ }
1408
1517
  this.listeners.clear();
1409
1518
  }
1410
1519
  };
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@tiquo/dom-package",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "description": "Tiquo SDK for third-party websites - authentication, customer profiles, orders, bookings, and enquiries",
5
+ "sideEffects": true,
5
6
  "publishConfig": {
6
7
  "access": "restricted"
7
8
  },