@proveanything/smartlinks 1.3.40 → 1.3.42

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.40 | Generated: 2026-02-18T20:09:53.593Z
3
+ Version: 1.3.42 | Generated: 2026-02-19T07:40:37.858Z
4
4
 
5
5
  This is a concise summary of all available API functions and types.
6
6
 
@@ -1530,6 +1530,7 @@ interface AppConfig {
1530
1530
  proof: boolean; // use at the proof level
1531
1531
  widget: boolean; // has a widget component available
1532
1532
  }
1533
+ directComponent: boolean; // Whether the app provides a direct React component for embedding (instead of using an iframe)
1533
1534
  [key: string]: any
1534
1535
  }
1535
1536
  ```
package/dist/http.js CHANGED
@@ -173,13 +173,6 @@ 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
- });
183
176
  // Auto-enable ngrok skip header if domain contains .ngrok.io and user did not explicitly set the flag.
184
177
  // Infer ngrok usage from common domains (.ngrok.io or .ngrok-free.dev)
185
178
  const inferredNgrok = /(\.ngrok\.io|\.ngrok-free\.dev)(\b|\/)/i.test(baseURL);
@@ -233,33 +226,19 @@ function ensureProxyListener() {
233
226
  return;
234
227
  window.addEventListener("message", (event) => {
235
228
  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
- }
245
229
  if (!msg || !msg._smartlinksProxyResponse || !msg.id)
246
230
  return;
247
231
  logDebug('[smartlinks] proxy:response', { id: msg.id, ok: !msg.error, keys: Object.keys(msg) });
248
232
  const pending = proxyPending[msg.id];
249
233
  if (pending) {
250
234
  if (msg.error) {
251
- console.error('[SmartLinks:Child] ❌ Proxy request failed', { id: msg.id, error: msg.error });
252
235
  pending.reject(new Error(msg.error));
253
236
  }
254
237
  else {
255
- console.log('[SmartLinks:Child] ✅ Proxy request succeeded', { id: msg.id });
256
238
  pending.resolve(msg.data);
257
239
  }
258
240
  delete proxyPending[msg.id];
259
241
  }
260
- else {
261
- console.warn('[SmartLinks:Child] ⚠️ Received response for unknown request', { id: msg.id });
262
- }
263
242
  });
264
243
  window._smartlinksProxyListener = true;
265
244
  }
@@ -287,25 +266,10 @@ async function proxyRequest(method, path, body, headers, options) {
287
266
  headers,
288
267
  options,
289
268
  };
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
- });
298
269
  logDebug('[smartlinks] proxy:postMessage', { id, method, path, headers: headers ? redactHeaders(headers) : undefined, hasBody: !!body });
299
270
  return new Promise((resolve, reject) => {
300
271
  proxyPending[id] = { resolve, reject };
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
- }
272
+ window.parent.postMessage(msg, "*");
309
273
  // Optionally: add a timeout here to reject if no response
310
274
  });
311
275
  }
@@ -33,7 +33,6 @@ import { getBaseURL } from './http';
33
33
  */
34
34
  export class IframeResponder {
35
35
  constructor(options) {
36
- var _a;
37
36
  this.iframe = null;
38
37
  this.uploads = new Map();
39
38
  this.isInitialLoad = true;
@@ -41,17 +40,6 @@ export class IframeResponder {
41
40
  this.resizeHandler = null;
42
41
  this.appUrl = null;
43
42
  this.resolveReady = null;
44
- console.log('[IframeResponder:Parent] 🏗️ Constructor called', {
45
- collectionId: options.collectionId,
46
- appId: options.appId,
47
- productId: options.productId,
48
- hasCache: !!options.cache,
49
- hasCachedApps: !!((_a = options.cache) === null || _a === void 0 ? void 0 : _a.apps),
50
- });
51
- console.log('[IframeResponder:Parent] SDK version check:', {
52
- hasCache: typeof cache !== 'undefined',
53
- hasCacheGetOrFetch: typeof (cache === null || cache === void 0 ? void 0 : cache.getOrFetch) === 'function',
54
- });
55
43
  this.options = options;
56
44
  this.cache = options.cache || {};
57
45
  // Create ready promise
@@ -62,7 +50,6 @@ export class IframeResponder {
62
50
  this.resolveAppUrl()
63
51
  .then(() => {
64
52
  var _a;
65
- console.log('[IframeResponder] App URL resolved successfully:', this.appUrl);
66
53
  (_a = this.resolveReady) === null || _a === void 0 ? void 0 : _a.call(this);
67
54
  })
68
55
  .catch((err) => {
@@ -78,20 +65,16 @@ export class IframeResponder {
78
65
  * Returns the src URL to set on the iframe.
79
66
  */
80
67
  async attach(iframe) {
81
- console.log('[IframeResponder:Parent] 🔗 attach() called, waiting for ready...');
82
68
  await this.ready;
83
- console.log('[IframeResponder:Parent] ✅ Ready resolved, appUrl:', this.appUrl);
84
69
  this.iframe = iframe;
85
70
  // Set up message listener
86
71
  this.messageHandler = this.handleMessage.bind(this);
87
72
  window.addEventListener('message', this.messageHandler);
88
- console.log('[IframeResponder:Parent] 👂 Message listener attached to window');
89
73
  // Set up resize listener for viewport-based calculations
90
74
  this.resizeHandler = this.calculateViewportHeight.bind(this);
91
75
  window.addEventListener('resize', this.resizeHandler);
92
76
  window.addEventListener('orientationchange', this.resizeHandler);
93
77
  const src = this.buildIframeSrc();
94
- console.log('[IframeResponder:Parent] 🎯 Built iframe src:', src);
95
78
  return src;
96
79
  }
97
80
  /**
@@ -121,42 +104,30 @@ export class IframeResponder {
121
104
  // ===========================================================================
122
105
  async resolveAppUrl() {
123
106
  var _a, _b;
124
- console.log('[IframeResponder] resolveAppUrl started');
125
107
  // Use explicit override if provided
126
108
  if (this.options.appUrl) {
127
109
  this.appUrl = this.options.appUrl;
128
- console.log('[IframeResponder] Using override URL:', this.appUrl);
129
110
  return;
130
111
  }
131
112
  // Check pre-populated cache
132
113
  const cachedApps = this.cache.apps;
133
114
  if (cachedApps) {
134
- console.log('[IframeResponder] Found cached apps:', cachedApps.length);
135
115
  const app = cachedApps.find(a => a.id === this.options.appId);
136
116
  if (app) {
137
117
  this.appUrl = this.getVersionUrl(app);
138
- console.log('[IframeResponder] Using cached app URL:', this.appUrl);
139
118
  return;
140
119
  }
141
- console.log('[IframeResponder] App not found in cache, fetching from API');
142
- }
143
- else {
144
- console.log('[IframeResponder] No cached apps, fetching from API');
145
120
  }
146
121
  // Fetch from API with caching
147
122
  try {
148
- console.log('[IframeResponder] Calling cache.getOrFetch for apps');
149
123
  const appsConfig = await cache.getOrFetch(`apps:${this.options.collectionId}`, () => collection.getAppsConfig(this.options.collectionId), { ttl: 5 * 60 * 1000, storage: 'session' });
150
- console.log('[IframeResponder] Got appsConfig from API:', appsConfig);
151
124
  const apps = appsConfig.apps;
152
- console.log('[IframeResponder] Extracted apps array:', apps === null || apps === void 0 ? void 0 : apps.length, apps);
153
125
  const app = apps.find(a => a.id === this.options.appId);
154
126
  if (!app) {
155
127
  console.error('[IframeResponder] App not found:', this.options.appId, 'Available:', apps.map(a => a.id));
156
128
  throw new Error(`App "${this.options.appId}" not found in collection "${this.options.collectionId}"`);
157
129
  }
158
130
  this.appUrl = this.getVersionUrl(app);
159
- console.log('[IframeResponder] Resolved app URL:', this.appUrl);
160
131
  }
161
132
  catch (err) {
162
133
  console.error('[IframeResponder] resolveAppUrl error:', err);
@@ -176,9 +147,7 @@ export class IframeResponder {
176
147
  // ===========================================================================
177
148
  buildIframeSrc() {
178
149
  var _a, _b;
179
- console.log('[IframeResponder] buildIframeSrc called, appUrl:', this.appUrl);
180
150
  if (!this.appUrl) {
181
- console.error('[IframeResponder] Cannot build src - appUrl is null!');
182
151
  throw new Error('App URL not resolved');
183
152
  }
184
153
  const params = new URLSearchParams();
@@ -222,7 +191,6 @@ export class IframeResponder {
222
191
  let finalUrl = this.appUrl;
223
192
  // Check if this URL uses hash routing (has a # in it)
224
193
  const hasHash = finalUrl.includes('#');
225
- console.log('[IframeResponder] URL has hash routing:', hasHash);
226
194
  if (hasHash) {
227
195
  // Hash-routed app - build params into the hash portion
228
196
  const [baseWithHash, existingQuery = ''] = finalUrl.split('?');
@@ -251,7 +219,6 @@ export class IframeResponder {
251
219
  params.forEach((value, key) => url.searchParams.set(key, value));
252
220
  finalUrl = url.toString();
253
221
  }
254
- console.log('[IframeResponder] Final iframe URL:', finalUrl);
255
222
  return finalUrl;
256
223
  }
257
224
  // ===========================================================================
@@ -273,65 +240,34 @@ export class IframeResponder {
273
240
  // Message Handling
274
241
  // ===========================================================================
275
242
  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
- }
291
243
  // Validate source is our iframe
292
244
  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
- });
297
245
  return;
298
246
  }
247
+ const data = event.data;
299
248
  if (!data || typeof data !== 'object') {
300
- console.log('[IframeResponder:Parent] ⚠️ Ignoring message - invalid data');
301
249
  return;
302
250
  }
303
251
  // Route changes (deep linking)
304
252
  if (data.type === 'smartlinks-route-change') {
305
- console.log('[IframeResponder:Parent] 🔀 Handling route change');
306
253
  this.handleRouteChange(data);
307
254
  return;
308
255
  }
309
256
  // Standardized iframe messages
310
257
  if (data._smartlinksIframeMessage) {
311
- console.log('[IframeResponder:Parent] 📋 Handling standard message');
312
258
  await this.handleStandardMessage(data, event);
313
259
  return;
314
260
  }
315
261
  // File upload proxy
316
262
  if (data._smartlinksProxyUpload) {
317
- console.log('[IframeResponder:Parent] 📤 Handling upload proxy');
318
263
  await this.handleUpload(data, event);
319
264
  return;
320
265
  }
321
266
  // API proxy requests
322
267
  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
- });
329
268
  await this.handleProxyRequest(data, event);
330
269
  return;
331
270
  }
332
- console.log('[IframeResponder:Parent] ⚠️ Unhandled message type', {
333
- keys: Object.keys(data)
334
- });
335
271
  }
336
272
  // ===========================================================================
337
273
  // Route Changes (Deep Linking)
@@ -437,17 +373,12 @@ export class IframeResponder {
437
373
  // ===========================================================================
438
374
  async handleProxyRequest(data, event) {
439
375
  var _a, _b, _c;
440
- console.log('[IframeResponder:Parent] 🔧 handleProxyRequest called', {
441
- id: data.id,
442
- hasCustomFlag: '_smartlinksCustomProxyRequest' in data
443
- });
444
376
  const response = {
445
377
  _smartlinksProxyResponse: true,
446
378
  id: data.id,
447
379
  };
448
380
  // Handle custom proxy requests (redirects, etc.)
449
381
  if ('_smartlinksCustomProxyRequest' in data && data._smartlinksCustomProxyRequest) {
450
- console.log('[IframeResponder:Parent] 🔄 Handling custom proxy request', { request: data.request });
451
382
  if (data.request === 'REDIRECT') {
452
383
  const url = (_a = data.params) === null || _a === void 0 ? void 0 : _a.url;
453
384
  if (url) {
@@ -459,32 +390,21 @@ export class IframeResponder {
459
390
  }
460
391
  }
461
392
  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
- });
467
393
  try {
468
394
  const path = proxyData.path.startsWith('/') ? proxyData.path.slice(1) : proxyData.path;
469
395
  // Check for cached data matches on GET requests
470
396
  if (proxyData.method === 'GET') {
471
- console.log('[IframeResponder:Parent] 🔍 Checking cache for:', path);
472
397
  const cachedResponse = this.getCachedResponse(path);
473
398
  if (cachedResponse !== null) {
474
- console.log('[IframeResponder:Parent] ✅ Returning cached response');
475
399
  response.data = cachedResponse;
476
400
  this.sendResponse(event, response);
477
401
  return;
478
402
  }
479
- console.log('[IframeResponder:Parent] ❌ No cache hit, will fetch from API');
480
403
  }
481
404
  // Forward to actual API using SDK's configured baseURL
482
405
  const baseUrl = getBaseURL();
483
- console.log('[IframeResponder:Parent] 🌍 Base URL from SDK:', baseUrl);
484
406
  if (!baseUrl) {
485
- const error = 'SDK not initialized - call initializeApi() first';
486
- console.error('[IframeResponder:Parent] ❌', error);
487
- throw new Error(error);
407
+ throw new Error('SDK not initialized - call initializeApi() first');
488
408
  }
489
409
  const fullUrl = `${baseUrl}/${path}`;
490
410
  const fetchOptions = {
@@ -495,48 +415,27 @@ export class IframeResponder {
495
415
  fetchOptions.body = JSON.stringify(proxyData.body);
496
416
  fetchOptions.headers = Object.assign(Object.assign({}, fetchOptions.headers), { 'Content-Type': 'application/json' });
497
417
  }
498
- console.log('[IframeResponder:Parent] 🚀 Fetching:', fullUrl, {
499
- method: proxyData.method,
500
- headerCount: Object.keys(fetchOptions.headers || {}).length
501
- });
502
418
  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
419
  const responseData = await fetchResponse.json();
509
- console.log('[IframeResponder:Parent] 📦 Response data received, keys:', Object.keys(responseData || {}));
510
420
  response.data = responseData;
511
421
  }
512
422
  catch (err) {
513
- console.error('[IframeResponder:Parent] Proxy request error:', {
514
- id: proxyData.id,
515
- error: err.message,
516
- stack: err.stack
517
- });
423
+ console.error('[IframeResponder] Proxy request error:', err);
518
424
  response.error = (err === null || err === void 0 ? void 0 : err.message) || 'Unknown error';
519
425
  (_c = (_b = this.options).onError) === null || _c === void 0 ? void 0 : _c.call(_b, err);
520
426
  }
521
- console.log('[IframeResponder:Parent] 📤 Sending response back to iframe:', {
522
- id: response.id,
523
- hasData: !!response.data,
524
- hasError: !!response.error
525
- });
526
427
  this.sendResponse(event, response);
527
428
  }
528
429
  getCachedResponse(path) {
529
430
  // App data endpoints should NOT be cached - they need fresh data from API
530
431
  // These are the new separated app config endpoints
531
432
  if (path.includes('/app/') && (path.includes('/data') || path.match(/\/app\/[^/]+$/))) {
532
- console.log('[IframeResponder:Parent] 🚫 Not caching app data endpoint:', path);
533
433
  return null;
534
434
  }
535
435
  // Collection request - ONLY match direct collection endpoint, not app config endpoints
536
436
  if (this.cache.collection) {
537
437
  const collectionMatch = path.match(/^public\/collection\/([^/]+)$/);
538
438
  if (collectionMatch && collectionMatch[1] === this.options.collectionId) {
539
- console.log('[IframeResponder:Parent] 📦 Cache hit: collection');
540
439
  return JSON.parse(JSON.stringify(this.cache.collection));
541
440
  }
542
441
  }
@@ -544,7 +443,6 @@ export class IframeResponder {
544
443
  if (this.cache.product && this.options.productId) {
545
444
  const productMatch = path.match(/^public\/collection\/[^/]+\/product\/([^/]+)$/);
546
445
  if (productMatch && productMatch[1] === this.options.productId) {
547
- console.log('[IframeResponder:Parent] 📦 Cache hit: product');
548
446
  return JSON.parse(JSON.stringify(this.cache.product));
549
447
  }
550
448
  }
@@ -552,13 +450,11 @@ export class IframeResponder {
552
450
  if (this.cache.proof && this.options.proofId) {
553
451
  const proofMatch = path.match(/^public\/proof\/([^/]+)$/);
554
452
  if (proofMatch && proofMatch[1] === this.options.proofId) {
555
- console.log('[IframeResponder:Parent] 📦 Cache hit: proof');
556
453
  return JSON.parse(JSON.stringify(this.cache.proof));
557
454
  }
558
455
  }
559
456
  // Account request
560
457
  if (path.includes('/account') && this.cache.user) {
561
- console.log('[IframeResponder:Parent] 📦 Cache hit: account');
562
458
  return JSON.parse(JSON.stringify(Object.assign(Object.assign({}, this.cache.user.accountData), { uid: this.cache.user.uid, email: this.cache.user.email, displayName: this.cache.user.displayName })));
563
459
  }
564
460
  return null;
@@ -104,6 +104,7 @@ export interface AppConfig {
104
104
  proof: boolean;
105
105
  widget: boolean;
106
106
  };
107
+ directComponent: boolean;
107
108
  [key: string]: any;
108
109
  }
109
110
  /**
@@ -1,6 +1,6 @@
1
1
  # Smartlinks API Summary
2
2
 
3
- Version: 1.3.40 | Generated: 2026-02-18T20:09:53.593Z
3
+ Version: 1.3.42 | Generated: 2026-02-19T07:40:37.858Z
4
4
 
5
5
  This is a concise summary of all available API functions and types.
6
6
 
@@ -1530,6 +1530,7 @@ interface AppConfig {
1530
1530
  proof: boolean; // use at the proof level
1531
1531
  widget: boolean; // has a widget component available
1532
1532
  }
1533
+ directComponent: boolean; // Whether the app provides a direct React component for embedding (instead of using an iframe)
1533
1534
  [key: string]: any
1534
1535
  }
1535
1536
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proveanything/smartlinks",
3
- "version": "1.3.40",
3
+ "version": "1.3.42",
4
4
  "description": "Official JavaScript/TypeScript SDK for the Smartlinks API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",