@proveanything/smartlinks 1.3.37 → 1.3.39

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,6 +1,6 @@
1
1
  # Smartlinks API Summary
2
2
 
3
- Version: 1.3.37 | Generated: 2026-02-17T14:15:30.216Z
3
+ Version: 1.3.39 | Generated: 2026-02-18T19:54:44.075Z
4
4
 
5
5
  This is a concise summary of all available API functions and types.
6
6
 
@@ -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.name` | string | Display name of the 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
- window.parent.postMessage(msg, "*");
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
  }
@@ -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
- const data = event.data;
280
- if (!data || typeof data !== 'object')
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,22 +459,34 @@ 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
427
470
  if (proxyData.method === 'GET') {
471
+ console.log('[IframeResponder:Parent] 🔍 Checking cache for:', path);
428
472
  const cachedResponse = this.getCachedResponse(path);
429
473
  if (cachedResponse !== null) {
474
+ console.log('[IframeResponder:Parent] ✅ Returning cached response');
430
475
  response.data = cachedResponse;
431
476
  this.sendResponse(event, response);
432
477
  return;
433
478
  }
479
+ console.log('[IframeResponder:Parent] ❌ No cache hit, will fetch from API');
434
480
  }
435
481
  // Forward to actual API using SDK's configured baseURL
436
482
  const baseUrl = getBaseURL();
483
+ console.log('[IframeResponder:Parent] 🌍 Base URL from SDK:', baseUrl);
437
484
  if (!baseUrl) {
438
- throw new Error('SDK not initialized - call initializeApi() first');
485
+ const error = 'SDK not initialized - call initializeApi() first';
486
+ console.error('[IframeResponder:Parent] ❌', error);
487
+ throw new Error(error);
439
488
  }
489
+ const fullUrl = `${baseUrl}/${path}`;
440
490
  const fetchOptions = {
441
491
  method: proxyData.method,
442
492
  headers: proxyData.headers,
@@ -445,13 +495,34 @@ export class IframeResponder {
445
495
  fetchOptions.body = JSON.stringify(proxyData.body);
446
496
  fetchOptions.headers = Object.assign(Object.assign({}, fetchOptions.headers), { 'Content-Type': 'application/json' });
447
497
  }
448
- const fetchResponse = await fetch(`${baseUrl}/${path}`, fetchOptions);
449
- response.data = await fetchResponse.json();
498
+ console.log('[IframeResponder:Parent] 🚀 Fetching:', fullUrl, {
499
+ method: proxyData.method,
500
+ headerCount: Object.keys(fetchOptions.headers || {}).length
501
+ });
502
+ const fetchResponse = await fetch(fullUrl, fetchOptions);
503
+ console.log('[IframeResponder:Parent] 📥 Fetch response:', {
504
+ status: fetchResponse.status,
505
+ ok: fetchResponse.ok,
506
+ statusText: fetchResponse.statusText
507
+ });
508
+ const responseData = await fetchResponse.json();
509
+ console.log('[IframeResponder:Parent] 📦 Response data received, keys:', Object.keys(responseData || {}));
510
+ response.data = responseData;
450
511
  }
451
512
  catch (err) {
513
+ console.error('[IframeResponder:Parent] ❌ Proxy request error:', {
514
+ id: proxyData.id,
515
+ error: err.message,
516
+ stack: err.stack
517
+ });
452
518
  response.error = (err === null || err === void 0 ? void 0 : err.message) || 'Unknown error';
453
519
  (_c = (_b = this.options).onError) === null || _c === void 0 ? void 0 : _c.call(_b, err);
454
520
  }
521
+ console.log('[IframeResponder:Parent] 📤 Sending response back to iframe:', {
522
+ id: response.id,
523
+ hasData: !!response.data,
524
+ hasError: !!response.error
525
+ });
455
526
  this.sendResponse(event, response);
456
527
  }
457
528
  getCachedResponse(path) {
@@ -1,6 +1,6 @@
1
1
  # Smartlinks API Summary
2
2
 
3
- Version: 1.3.37 | Generated: 2026-02-17T14:15:30.216Z
3
+ Version: 1.3.39 | Generated: 2026-02-18T19:54:44.075Z
4
4
 
5
5
  This is a concise summary of all available API functions and types.
6
6
 
@@ -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.name` | string | Display name of the 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proveanything/smartlinks",
3
- "version": "1.3.37",
3
+ "version": "1.3.39",
4
4
  "description": "Official JavaScript/TypeScript SDK for the Smartlinks API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",