@tiquo/dom-package 1.3.2 → 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/dist/index.d.mts +16 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +81 -0
- package/dist/index.mjs +81 -0
- package/package.json +1 -1
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 {
|
|
@@ -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 {
|
|
@@ -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
|
@@ -712,6 +712,8 @@ var TiquoAuth = class {
|
|
|
712
712
|
this.refreshTimer = null;
|
|
713
713
|
this.isRefreshing = false;
|
|
714
714
|
this.visibilityHandler = null;
|
|
715
|
+
this.iframeObserver = null;
|
|
716
|
+
this.injectedIframes = /* @__PURE__ */ new WeakSet();
|
|
715
717
|
// Multi-tab sync
|
|
716
718
|
this.broadcastChannel = null;
|
|
717
719
|
this.isProcessingTabSync = false;
|
|
@@ -742,6 +744,7 @@ var TiquoAuth = class {
|
|
|
742
744
|
this.checkForInjectedTokens();
|
|
743
745
|
this.restoreTokens();
|
|
744
746
|
this.initVisibilityHandler();
|
|
747
|
+
this.autoInjectIframeTokens();
|
|
745
748
|
}
|
|
746
749
|
// ============================================
|
|
747
750
|
// PUBLIC METHODS
|
|
@@ -1073,6 +1076,77 @@ var TiquoAuth = class {
|
|
|
1073
1076
|
containerEl.appendChild(iframe);
|
|
1074
1077
|
return iframe;
|
|
1075
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
|
+
}
|
|
1076
1150
|
/**
|
|
1077
1151
|
* Get the current access token (for advanced use cases)
|
|
1078
1152
|
*/
|
|
@@ -1469,6 +1543,13 @@ var TiquoAuth = class {
|
|
|
1469
1543
|
this.broadcastChannel.close();
|
|
1470
1544
|
this.broadcastChannel = null;
|
|
1471
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
|
+
}
|
|
1472
1553
|
this.listeners.clear();
|
|
1473
1554
|
}
|
|
1474
1555
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -676,6 +676,8 @@ var TiquoAuth = class {
|
|
|
676
676
|
this.refreshTimer = null;
|
|
677
677
|
this.isRefreshing = false;
|
|
678
678
|
this.visibilityHandler = null;
|
|
679
|
+
this.iframeObserver = null;
|
|
680
|
+
this.injectedIframes = /* @__PURE__ */ new WeakSet();
|
|
679
681
|
// Multi-tab sync
|
|
680
682
|
this.broadcastChannel = null;
|
|
681
683
|
this.isProcessingTabSync = false;
|
|
@@ -706,6 +708,7 @@ var TiquoAuth = class {
|
|
|
706
708
|
this.checkForInjectedTokens();
|
|
707
709
|
this.restoreTokens();
|
|
708
710
|
this.initVisibilityHandler();
|
|
711
|
+
this.autoInjectIframeTokens();
|
|
709
712
|
}
|
|
710
713
|
// ============================================
|
|
711
714
|
// PUBLIC METHODS
|
|
@@ -1037,6 +1040,77 @@ var TiquoAuth = class {
|
|
|
1037
1040
|
containerEl.appendChild(iframe);
|
|
1038
1041
|
return iframe;
|
|
1039
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
|
+
}
|
|
1040
1114
|
/**
|
|
1041
1115
|
* Get the current access token (for advanced use cases)
|
|
1042
1116
|
*/
|
|
@@ -1433,6 +1507,13 @@ var TiquoAuth = class {
|
|
|
1433
1507
|
this.broadcastChannel.close();
|
|
1434
1508
|
this.broadcastChannel = null;
|
|
1435
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
|
+
}
|
|
1436
1517
|
this.listeners.clear();
|
|
1437
1518
|
}
|
|
1438
1519
|
};
|
package/package.json
CHANGED