@proveanything/smartlinks 1.3.37 → 1.3.38
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/docs/API_SUMMARY.md +1 -1
- package/dist/docs/liquid-templates.md +1 -1
- package/dist/http.js +37 -1
- package/dist/iframeResponder.js +51 -8
- package/docs/API_SUMMARY.md +1 -1
- package/docs/liquid-templates.md +1 -1
- package/package.json +1 -1
package/dist/docs/API_SUMMARY.md
CHANGED
|
@@ -39,7 +39,7 @@ A **Collection** represents a top-level business, brand, or organization. All pr
|
|
|
39
39
|
| Field | Type | Description |
|
|
40
40
|
|-------|------|-------------|
|
|
41
41
|
| `collection.id` | string | Unique identifier |
|
|
42
|
-
| `collection.
|
|
42
|
+
| `collection.title` | string | Display title of the collection |
|
|
43
43
|
| `collection.description` | string | Description text |
|
|
44
44
|
| `collection.slug` | string | URL-friendly identifier |
|
|
45
45
|
| `collection.logoUrl` | string | URL to the collection's logo image |
|
package/dist/http.js
CHANGED
|
@@ -173,6 +173,13 @@ export function initializeApi(options) {
|
|
|
173
173
|
apiKey = options.apiKey;
|
|
174
174
|
bearerToken = options.bearerToken;
|
|
175
175
|
proxyMode = !!options.proxyMode;
|
|
176
|
+
console.log('[SmartLinks] initializeApi called', {
|
|
177
|
+
baseURL,
|
|
178
|
+
proxyMode,
|
|
179
|
+
hasApiKey: !!apiKey,
|
|
180
|
+
hasBearerToken: !!bearerToken,
|
|
181
|
+
isIframe: typeof window !== 'undefined' && window.parent !== window
|
|
182
|
+
});
|
|
176
183
|
// Auto-enable ngrok skip header if domain contains .ngrok.io and user did not explicitly set the flag.
|
|
177
184
|
// Infer ngrok usage from common domains (.ngrok.io or .ngrok-free.dev)
|
|
178
185
|
const inferredNgrok = /(\.ngrok\.io|\.ngrok-free\.dev)(\b|\/)/i.test(baseURL);
|
|
@@ -226,19 +233,33 @@ function ensureProxyListener() {
|
|
|
226
233
|
return;
|
|
227
234
|
window.addEventListener("message", (event) => {
|
|
228
235
|
const msg = event.data;
|
|
236
|
+
// Log all messages to help debug
|
|
237
|
+
if (msg && msg._smartlinksProxyResponse) {
|
|
238
|
+
console.log('[SmartLinks:Child] 📨 Received proxy response from parent', {
|
|
239
|
+
id: msg.id,
|
|
240
|
+
hasError: !!msg.error,
|
|
241
|
+
hasData: !!msg.data,
|
|
242
|
+
origin: event.origin
|
|
243
|
+
});
|
|
244
|
+
}
|
|
229
245
|
if (!msg || !msg._smartlinksProxyResponse || !msg.id)
|
|
230
246
|
return;
|
|
231
247
|
logDebug('[smartlinks] proxy:response', { id: msg.id, ok: !msg.error, keys: Object.keys(msg) });
|
|
232
248
|
const pending = proxyPending[msg.id];
|
|
233
249
|
if (pending) {
|
|
234
250
|
if (msg.error) {
|
|
251
|
+
console.error('[SmartLinks:Child] ❌ Proxy request failed', { id: msg.id, error: msg.error });
|
|
235
252
|
pending.reject(new Error(msg.error));
|
|
236
253
|
}
|
|
237
254
|
else {
|
|
255
|
+
console.log('[SmartLinks:Child] ✅ Proxy request succeeded', { id: msg.id });
|
|
238
256
|
pending.resolve(msg.data);
|
|
239
257
|
}
|
|
240
258
|
delete proxyPending[msg.id];
|
|
241
259
|
}
|
|
260
|
+
else {
|
|
261
|
+
console.warn('[SmartLinks:Child] ⚠️ Received response for unknown request', { id: msg.id });
|
|
262
|
+
}
|
|
242
263
|
});
|
|
243
264
|
window._smartlinksProxyListener = true;
|
|
244
265
|
}
|
|
@@ -266,10 +287,25 @@ async function proxyRequest(method, path, body, headers, options) {
|
|
|
266
287
|
headers,
|
|
267
288
|
options,
|
|
268
289
|
};
|
|
290
|
+
console.log('[SmartLinks:Child] 🚀 Sending proxy request to parent', {
|
|
291
|
+
id,
|
|
292
|
+
method,
|
|
293
|
+
path,
|
|
294
|
+
hasBody: !!body,
|
|
295
|
+
bodyType: body ? body.constructor.name : 'none',
|
|
296
|
+
headerCount: headers ? Object.keys(headers).length : 0
|
|
297
|
+
});
|
|
269
298
|
logDebug('[smartlinks] proxy:postMessage', { id, method, path, headers: headers ? redactHeaders(headers) : undefined, hasBody: !!body });
|
|
270
299
|
return new Promise((resolve, reject) => {
|
|
271
300
|
proxyPending[id] = { resolve, reject };
|
|
272
|
-
|
|
301
|
+
try {
|
|
302
|
+
window.parent.postMessage(msg, "*");
|
|
303
|
+
console.log('[SmartLinks:Child] ✅ postMessage sent successfully', { id });
|
|
304
|
+
}
|
|
305
|
+
catch (error) {
|
|
306
|
+
console.error('[SmartLinks:Child] ❌ postMessage failed', { id, error });
|
|
307
|
+
throw error;
|
|
308
|
+
}
|
|
273
309
|
// Optionally: add a timeout here to reject if no response
|
|
274
310
|
});
|
|
275
311
|
}
|
package/dist/iframeResponder.js
CHANGED
|
@@ -41,14 +41,14 @@ export class IframeResponder {
|
|
|
41
41
|
this.resizeHandler = null;
|
|
42
42
|
this.appUrl = null;
|
|
43
43
|
this.resolveReady = null;
|
|
44
|
-
console.log('[IframeResponder] Constructor called', {
|
|
44
|
+
console.log('[IframeResponder:Parent] 🏗️ Constructor called', {
|
|
45
45
|
collectionId: options.collectionId,
|
|
46
46
|
appId: options.appId,
|
|
47
47
|
productId: options.productId,
|
|
48
48
|
hasCache: !!options.cache,
|
|
49
49
|
hasCachedApps: !!((_a = options.cache) === null || _a === void 0 ? void 0 : _a.apps),
|
|
50
50
|
});
|
|
51
|
-
console.log('[IframeResponder] SDK version check:', {
|
|
51
|
+
console.log('[IframeResponder:Parent] SDK version check:', {
|
|
52
52
|
hasCache: typeof cache !== 'undefined',
|
|
53
53
|
hasCacheGetOrFetch: typeof (cache === null || cache === void 0 ? void 0 : cache.getOrFetch) === 'function',
|
|
54
54
|
});
|
|
@@ -78,19 +78,20 @@ export class IframeResponder {
|
|
|
78
78
|
* Returns the src URL to set on the iframe.
|
|
79
79
|
*/
|
|
80
80
|
async attach(iframe) {
|
|
81
|
-
console.log('[IframeResponder] attach() called, waiting for ready...');
|
|
81
|
+
console.log('[IframeResponder:Parent] 🔗 attach() called, waiting for ready...');
|
|
82
82
|
await this.ready;
|
|
83
|
-
console.log('[IframeResponder] Ready resolved, appUrl:', this.appUrl);
|
|
83
|
+
console.log('[IframeResponder:Parent] ✅ Ready resolved, appUrl:', this.appUrl);
|
|
84
84
|
this.iframe = iframe;
|
|
85
85
|
// Set up message listener
|
|
86
86
|
this.messageHandler = this.handleMessage.bind(this);
|
|
87
87
|
window.addEventListener('message', this.messageHandler);
|
|
88
|
+
console.log('[IframeResponder:Parent] 👂 Message listener attached to window');
|
|
88
89
|
// Set up resize listener for viewport-based calculations
|
|
89
90
|
this.resizeHandler = this.calculateViewportHeight.bind(this);
|
|
90
91
|
window.addEventListener('resize', this.resizeHandler);
|
|
91
92
|
window.addEventListener('orientationchange', this.resizeHandler);
|
|
92
93
|
const src = this.buildIframeSrc();
|
|
93
|
-
console.log('[IframeResponder] Built iframe src:', src);
|
|
94
|
+
console.log('[IframeResponder:Parent] 🎯 Built iframe src:', src);
|
|
94
95
|
return src;
|
|
95
96
|
}
|
|
96
97
|
/**
|
|
@@ -272,33 +273,65 @@ export class IframeResponder {
|
|
|
272
273
|
// Message Handling
|
|
273
274
|
// ===========================================================================
|
|
274
275
|
async handleMessage(event) {
|
|
276
|
+
var _a, _b;
|
|
277
|
+
// Log all received messages for debugging
|
|
278
|
+
const data = event.data;
|
|
279
|
+
if (data && typeof data === 'object') {
|
|
280
|
+
console.log('[IframeResponder:Parent] 📨 Received message from iframe', {
|
|
281
|
+
type: data.type || (data._smartlinksProxyRequest ? 'proxy-request' : 'unknown'),
|
|
282
|
+
hasId: !!data.id,
|
|
283
|
+
isProxyRequest: !!data._smartlinksProxyRequest,
|
|
284
|
+
isCustomProxyRequest: !!data._smartlinksCustomProxyRequest,
|
|
285
|
+
isStandardMessage: !!data._smartlinksIframeMessage,
|
|
286
|
+
isRouteChange: data.type === 'smartlinks-route-change',
|
|
287
|
+
origin: event.origin,
|
|
288
|
+
source: event.source === ((_a = this.iframe) === null || _a === void 0 ? void 0 : _a.contentWindow) ? 'our-iframe' : 'other'
|
|
289
|
+
});
|
|
290
|
+
}
|
|
275
291
|
// Validate source is our iframe
|
|
276
292
|
if (!this.iframe || event.source !== this.iframe.contentWindow) {
|
|
293
|
+
console.log('[IframeResponder:Parent] ⚠️ Ignoring message - not from our iframe', {
|
|
294
|
+
hasIframe: !!this.iframe,
|
|
295
|
+
isCorrectSource: event.source === ((_b = this.iframe) === null || _b === void 0 ? void 0 : _b.contentWindow)
|
|
296
|
+
});
|
|
277
297
|
return;
|
|
278
298
|
}
|
|
279
|
-
|
|
280
|
-
|
|
299
|
+
if (!data || typeof data !== 'object') {
|
|
300
|
+
console.log('[IframeResponder:Parent] ⚠️ Ignoring message - invalid data');
|
|
281
301
|
return;
|
|
302
|
+
}
|
|
282
303
|
// Route changes (deep linking)
|
|
283
304
|
if (data.type === 'smartlinks-route-change') {
|
|
305
|
+
console.log('[IframeResponder:Parent] 🔀 Handling route change');
|
|
284
306
|
this.handleRouteChange(data);
|
|
285
307
|
return;
|
|
286
308
|
}
|
|
287
309
|
// Standardized iframe messages
|
|
288
310
|
if (data._smartlinksIframeMessage) {
|
|
311
|
+
console.log('[IframeResponder:Parent] 📋 Handling standard message');
|
|
289
312
|
await this.handleStandardMessage(data, event);
|
|
290
313
|
return;
|
|
291
314
|
}
|
|
292
315
|
// File upload proxy
|
|
293
316
|
if (data._smartlinksProxyUpload) {
|
|
317
|
+
console.log('[IframeResponder:Parent] 📤 Handling upload proxy');
|
|
294
318
|
await this.handleUpload(data, event);
|
|
295
319
|
return;
|
|
296
320
|
}
|
|
297
321
|
// API proxy requests
|
|
298
|
-
if (data._smartlinksProxyRequest) {
|
|
322
|
+
if (data._smartlinksProxyRequest || data._smartlinksCustomProxyRequest) {
|
|
323
|
+
console.log('[IframeResponder:Parent] 🌐 Handling API proxy request', {
|
|
324
|
+
id: data.id,
|
|
325
|
+
method: data.method,
|
|
326
|
+
path: data.path,
|
|
327
|
+
isCustom: !!data._smartlinksCustomProxyRequest
|
|
328
|
+
});
|
|
299
329
|
await this.handleProxyRequest(data, event);
|
|
300
330
|
return;
|
|
301
331
|
}
|
|
332
|
+
console.log('[IframeResponder:Parent] ⚠️ Unhandled message type', {
|
|
333
|
+
keys: Object.keys(data)
|
|
334
|
+
});
|
|
302
335
|
}
|
|
303
336
|
// ===========================================================================
|
|
304
337
|
// Route Changes (Deep Linking)
|
|
@@ -404,12 +437,17 @@ export class IframeResponder {
|
|
|
404
437
|
// ===========================================================================
|
|
405
438
|
async handleProxyRequest(data, event) {
|
|
406
439
|
var _a, _b, _c;
|
|
440
|
+
console.log('[IframeResponder:Parent] 🔧 handleProxyRequest called', {
|
|
441
|
+
id: data.id,
|
|
442
|
+
hasCustomFlag: '_smartlinksCustomProxyRequest' in data
|
|
443
|
+
});
|
|
407
444
|
const response = {
|
|
408
445
|
_smartlinksProxyResponse: true,
|
|
409
446
|
id: data.id,
|
|
410
447
|
};
|
|
411
448
|
// Handle custom proxy requests (redirects, etc.)
|
|
412
449
|
if ('_smartlinksCustomProxyRequest' in data && data._smartlinksCustomProxyRequest) {
|
|
450
|
+
console.log('[IframeResponder:Parent] 🔄 Handling custom proxy request', { request: data.request });
|
|
413
451
|
if (data.request === 'REDIRECT') {
|
|
414
452
|
const url = (_a = data.params) === null || _a === void 0 ? void 0 : _a.url;
|
|
415
453
|
if (url) {
|
|
@@ -421,6 +459,11 @@ export class IframeResponder {
|
|
|
421
459
|
}
|
|
422
460
|
}
|
|
423
461
|
const proxyData = data;
|
|
462
|
+
console.log('[IframeResponder:Parent] 🌐 Processing API proxy request', {
|
|
463
|
+
id: proxyData.id,
|
|
464
|
+
method: proxyData.method,
|
|
465
|
+
path: proxyData.path
|
|
466
|
+
});
|
|
424
467
|
try {
|
|
425
468
|
const path = proxyData.path.startsWith('/') ? proxyData.path.slice(1) : proxyData.path;
|
|
426
469
|
// Check for cached data matches on GET requests
|
package/docs/API_SUMMARY.md
CHANGED
package/docs/liquid-templates.md
CHANGED
|
@@ -39,7 +39,7 @@ A **Collection** represents a top-level business, brand, or organization. All pr
|
|
|
39
39
|
| Field | Type | Description |
|
|
40
40
|
|-------|------|-------------|
|
|
41
41
|
| `collection.id` | string | Unique identifier |
|
|
42
|
-
| `collection.
|
|
42
|
+
| `collection.title` | string | Display title of the collection |
|
|
43
43
|
| `collection.description` | string | Description text |
|
|
44
44
|
| `collection.slug` | string | URL-friendly identifier |
|
|
45
45
|
| `collection.logoUrl` | string | URL to the collection's logo image |
|