@thewhateverapp/tile-sdk 0.2.3 → 0.2.5
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TileBridge.d.ts","sourceRoot":"","sources":["../../src/bridge/TileBridge.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IACzB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,qBAAa,UAAU;IACrB,OAAO,CAAC,MAAM,CAA2B;IACzC,OAAO,CAAC,YAAY,CAAqB;IACzC,OAAO,CAAC,gBAAgB,CAAmD;IAC3E,OAAO,CAAC,aAAa,CAAoD;IACzE,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,YAAY,CAAS;gBAEjB,cAAc,GAAE,MAAkC;
|
|
1
|
+
{"version":3,"file":"TileBridge.d.ts","sourceRoot":"","sources":["../../src/bridge/TileBridge.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,GAAG,CAAC;IACd,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,UA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AAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI;IAWzD;;OAEG;IACU,OAAO,CAAC,OAAO,CAAC,EAAE;QAC7B,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;QAClB,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,GAAG,OAAO,CAAC,GAAG,CAAC;IAiChB;;OAEG;IACU,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IA8B9D;;OAEG;IACU,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC;IAuB3C;;OAEG;IACI,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,GAAG,MAAM,IAAI;IAgBlE;;OAEG;IACI,SAAS,IAAI,UAAU,GAAG,IAAI;IAIrC;;OAEG;IACI,OAAO,IAAI,OAAO;IAIzB;;OAEG;IACU,YAAY,IAAI,OAAO,CAAC,UAAU,CAAC;IAehD,OAAO,CAAC,SAAS;IAOjB,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,aAAa;IAMrB,OAAO,CAAC,SAAS;CAIlB;AAKD,wBAAgB,aAAa,IAAI,UAAU,CAK1C"}
|
|
@@ -10,36 +10,37 @@ export class TileBridge {
|
|
|
10
10
|
this.eventHandlers = new Map();
|
|
11
11
|
this.ready = false;
|
|
12
12
|
this.parentOrigin = expectedOrigin;
|
|
13
|
-
//
|
|
13
|
+
// Auto-detect parent origin based on environment
|
|
14
14
|
if (typeof window !== 'undefined') {
|
|
15
15
|
const isInIframe = window.self !== window.top;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (isInIframe && isApiOrigin) {
|
|
19
|
-
// Preview mode - allow localhost parent
|
|
20
|
-
if (window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1') {
|
|
21
|
-
this.parentOrigin = 'http://localhost:3000';
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
// Production preview - parent is thewhatever.app
|
|
25
|
-
this.parentOrigin = 'https://thewhatever.app';
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
else if (window.location.hostname === 'localhost') {
|
|
29
|
-
// Regular development mode
|
|
16
|
+
// Development: localhost
|
|
17
|
+
if (window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1') {
|
|
30
18
|
this.parentOrigin = 'http://localhost:3000';
|
|
31
19
|
}
|
|
20
|
+
// Production preview: api.thewhatever.app serving iframe, parent is thewhatever.app
|
|
21
|
+
else if (isInIframe && window.location.hostname === 'api.thewhatever.app') {
|
|
22
|
+
this.parentOrigin = 'https://thewhatever.app';
|
|
23
|
+
}
|
|
24
|
+
// Production deployed: app running on its own pages.dev domain
|
|
25
|
+
else if (window.location.hostname.includes('.pages.dev')) {
|
|
26
|
+
this.parentOrigin = 'https://thewhatever.app';
|
|
27
|
+
}
|
|
28
|
+
// Default to provided expectedOrigin
|
|
29
|
+
else {
|
|
30
|
+
this.parentOrigin = expectedOrigin;
|
|
31
|
+
}
|
|
32
32
|
}
|
|
33
33
|
this.initialize();
|
|
34
34
|
}
|
|
35
35
|
initialize() {
|
|
36
36
|
if (typeof window === 'undefined')
|
|
37
37
|
return;
|
|
38
|
-
// Debug logging
|
|
39
|
-
if (this.isDevelopment()) {
|
|
38
|
+
// Debug logging (always enabled for preview and development)
|
|
39
|
+
if (this.isDevelopment() || this.isPreview()) {
|
|
40
40
|
console.log('[TileBridge] Initializing with config:', {
|
|
41
41
|
parentOrigin: this.parentOrigin,
|
|
42
42
|
currentOrigin: window.location.origin,
|
|
43
|
+
hostname: window.location.hostname,
|
|
43
44
|
isInIframe: window.self !== window.top,
|
|
44
45
|
});
|
|
45
46
|
}
|
|
@@ -51,11 +52,18 @@ export class TileBridge {
|
|
|
51
52
|
this.sendToParent({ type: 'tile:request-config' });
|
|
52
53
|
}
|
|
53
54
|
handleMessage(event) {
|
|
54
|
-
// Validate origin
|
|
55
|
-
if (event.origin !== this.parentOrigin && !this.isDevelopment()) {
|
|
56
|
-
console.warn('Received message from untrusted origin:', event.origin);
|
|
55
|
+
// Validate origin (skip validation in dev and preview)
|
|
56
|
+
if (event.origin !== this.parentOrigin && !this.isDevelopment() && !this.isPreview()) {
|
|
57
|
+
console.warn('[TileBridge] Received message from untrusted origin:', event.origin, 'expected:', this.parentOrigin);
|
|
57
58
|
return;
|
|
58
59
|
}
|
|
60
|
+
if (this.isDevelopment() || this.isPreview()) {
|
|
61
|
+
console.log('[TileBridge] Received message:', {
|
|
62
|
+
type: event.data?.type,
|
|
63
|
+
origin: event.origin,
|
|
64
|
+
expectedOrigin: this.parentOrigin,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
59
67
|
const message = event.data;
|
|
60
68
|
// Handle system messages
|
|
61
69
|
switch (message.type) {
|
|
@@ -120,10 +128,11 @@ export class TileBridge {
|
|
|
120
128
|
* Request to navigate to full page view
|
|
121
129
|
*/
|
|
122
130
|
navigateToPage() {
|
|
123
|
-
if (this.isDevelopment()) {
|
|
131
|
+
if (this.isDevelopment() || this.isPreview()) {
|
|
124
132
|
console.log('[TileBridge] Requesting navigation to page', {
|
|
125
133
|
ready: this.ready,
|
|
126
134
|
parentOrigin: this.parentOrigin,
|
|
135
|
+
currentOrigin: window.location.origin,
|
|
127
136
|
});
|
|
128
137
|
}
|
|
129
138
|
this.sendToParent({
|
|
@@ -390,6 +399,10 @@ export class TileBridge {
|
|
|
390
399
|
(window.location.hostname === 'localhost' ||
|
|
391
400
|
window.location.hostname === '127.0.0.1');
|
|
392
401
|
}
|
|
402
|
+
isPreview() {
|
|
403
|
+
return typeof window !== 'undefined' &&
|
|
404
|
+
window.location.hostname === 'api.thewhatever.app';
|
|
405
|
+
}
|
|
393
406
|
}
|
|
394
407
|
// Singleton instance
|
|
395
408
|
let bridgeInstance = null;
|