@snowcone-app/sdk 0.25.0 → 0.26.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.26.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#4415](https://github.com/snowcone-app/snowcone-monorepo/pull/4415) [`ccc4cf3`](https://github.com/snowcone-app/snowcone-monorepo/commit/ccc4cf371c5f4845e679b8c295e0335881664e96) Thanks [@kevinsproles](https://github.com/kevinsproles)! - The SDK reports `isFrameSuperseded(url)`: true once a newer ws frame for the same mockup has arrived and the old one was revoked. The UI uses it when a cropped frame fails to load: a superseded frame is dropped at once instead of waiting on the 2 s grace, which a 31-picture batch can outlast (React only sees the newer frame with the batch's `all_mockups_rendered`). Before, the grace fired first, cropped delivery went off for the session and a visible picture could stay one version behind.
8
+
9
+ `all_mockups_rendered` now merges its batch into `mockupResults` instead of replacing it. A short batch (a `rerender` answer) landing right after a full one replaced it, React coalesced the two updates, and every other picture kept its previous version.
10
+
3
11
  ## 0.25.0
4
12
 
5
13
  ### Minor Changes
@@ -88,6 +88,9 @@ var RealtimeMockupService = class {
88
88
  pendingFrames = /* @__PURE__ */ new Map();
89
89
  // Last object URL handed out per mockup — revoked when replaced.
90
90
  liveObjectUrls = /* @__PURE__ */ new Map();
91
+ // Live frames a newer frame for the same mockup has replaced (and revoked), newest last, bounded. Lets a consumer
92
+ // still loading an old frame tell "superseded" from "broken" the moment it fails (isFrameSuperseded).
93
+ supersededFrameUrls = /* @__PURE__ */ new Set();
91
94
  renewTimer = null;
92
95
  isConnecting = false;
93
96
  connectAttempt = 0;
@@ -338,7 +341,7 @@ var RealtimeMockupService = class {
338
341
  }
339
342
  return true;
340
343
  });
341
- this.mockupResults = freshMockups.map((mockup) => {
344
+ const batch = freshMockups.map((mockup) => {
342
345
  const existing = this.mockupResults.find(
343
346
  (m) => m.mockupId === mockup.mockupId && (mockup.requestId === void 0 || m.requestId === mockup.requestId)
344
347
  );
@@ -350,6 +353,11 @@ var RealtimeMockupService = class {
350
353
  }
351
354
  return merged;
352
355
  });
356
+ const batchById = new Map(batch.map((m) => [m.mockupId, m]));
357
+ this.mockupResults = [
358
+ ...this.mockupResults.map((m) => batchById.get(m.mockupId) ?? m),
359
+ ...batch.filter((m) => !this.mockupResults.some((e) => e.mockupId === m.mockupId))
360
+ ];
353
361
  this.lastError = null;
354
362
  this.renderError = null;
355
363
  this.addLog(`\u{1F389} All mockups rendered: ${freshMockups.length} fresh (${data.mockups.length - freshMockups.length} stale filtered)`);
@@ -411,7 +419,14 @@ var RealtimeMockupService = class {
411
419
  if (!frame) return;
412
420
  this.pendingFrames.delete(key);
413
421
  const prevLive = this.liveObjectUrls.get(data.mockupId);
414
- if (prevLive) URL.revokeObjectURL(prevLive);
422
+ if (prevLive) {
423
+ URL.revokeObjectURL(prevLive);
424
+ this.supersededFrameUrls.add(prevLive);
425
+ if (this.supersededFrameUrls.size > 512) {
426
+ const oldest = this.supersededFrameUrls.values().next().value;
427
+ if (oldest) this.supersededFrameUrls.delete(oldest);
428
+ }
429
+ }
415
430
  this.liveObjectUrls.set(data.mockupId, frame.objectUrl);
416
431
  data.imageUrl = frame.objectUrl;
417
432
  }
@@ -777,6 +792,14 @@ ${versionToSend}
777
792
  * E_RERENDER_INCOMPLETE | E_RERENDER_RATE_LIMITED). Never changes the
778
793
  * session's mockupIds.
779
794
  */
795
+ /**
796
+ * True when `url` was a ws-delivered frame for a mockup and a newer frame for that mockup has since arrived (the SDK
797
+ * revoked the old one). A consumer whose load of `url` failed uses this to tell supersession (the newer frame is
798
+ * already here; it reaches the results with its batch's all_mockups_rendered) from a real failure.
799
+ */
800
+ isFrameSuperseded(url) {
801
+ return this.supersededFrameUrls.has(url);
802
+ }
780
803
  rerender(mockupIds) {
781
804
  if (!this.ws || this.ws.readyState !== WebSocket.OPEN || !this.config || mockupIds.length === 0) return false;
782
805
  const { requestId, traceparent } = newRenderCorrelation();
package/dist/index.cjs CHANGED
@@ -5118,6 +5118,9 @@ var RealtimeMockupService = class {
5118
5118
  pendingFrames = /* @__PURE__ */ new Map();
5119
5119
  // Last object URL handed out per mockup — revoked when replaced.
5120
5120
  liveObjectUrls = /* @__PURE__ */ new Map();
5121
+ // Live frames a newer frame for the same mockup has replaced (and revoked), newest last, bounded. Lets a consumer
5122
+ // still loading an old frame tell "superseded" from "broken" the moment it fails (isFrameSuperseded).
5123
+ supersededFrameUrls = /* @__PURE__ */ new Set();
5121
5124
  renewTimer = null;
5122
5125
  isConnecting = false;
5123
5126
  connectAttempt = 0;
@@ -5368,7 +5371,7 @@ var RealtimeMockupService = class {
5368
5371
  }
5369
5372
  return true;
5370
5373
  });
5371
- this.mockupResults = freshMockups.map((mockup) => {
5374
+ const batch = freshMockups.map((mockup) => {
5372
5375
  const existing = this.mockupResults.find(
5373
5376
  (m) => m.mockupId === mockup.mockupId && (mockup.requestId === void 0 || m.requestId === mockup.requestId)
5374
5377
  );
@@ -5380,6 +5383,11 @@ var RealtimeMockupService = class {
5380
5383
  }
5381
5384
  return merged;
5382
5385
  });
5386
+ const batchById = new Map(batch.map((m) => [m.mockupId, m]));
5387
+ this.mockupResults = [
5388
+ ...this.mockupResults.map((m) => batchById.get(m.mockupId) ?? m),
5389
+ ...batch.filter((m) => !this.mockupResults.some((e) => e.mockupId === m.mockupId))
5390
+ ];
5383
5391
  this.lastError = null;
5384
5392
  this.renderError = null;
5385
5393
  this.addLog(`\u{1F389} All mockups rendered: ${freshMockups.length} fresh (${data.mockups.length - freshMockups.length} stale filtered)`);
@@ -5441,7 +5449,14 @@ var RealtimeMockupService = class {
5441
5449
  if (!frame) return;
5442
5450
  this.pendingFrames.delete(key);
5443
5451
  const prevLive = this.liveObjectUrls.get(data.mockupId);
5444
- if (prevLive) URL.revokeObjectURL(prevLive);
5452
+ if (prevLive) {
5453
+ URL.revokeObjectURL(prevLive);
5454
+ this.supersededFrameUrls.add(prevLive);
5455
+ if (this.supersededFrameUrls.size > 512) {
5456
+ const oldest = this.supersededFrameUrls.values().next().value;
5457
+ if (oldest) this.supersededFrameUrls.delete(oldest);
5458
+ }
5459
+ }
5445
5460
  this.liveObjectUrls.set(data.mockupId, frame.objectUrl);
5446
5461
  data.imageUrl = frame.objectUrl;
5447
5462
  }
@@ -5807,6 +5822,14 @@ ${versionToSend}
5807
5822
  * E_RERENDER_INCOMPLETE | E_RERENDER_RATE_LIMITED). Never changes the
5808
5823
  * session's mockupIds.
5809
5824
  */
5825
+ /**
5826
+ * True when `url` was a ws-delivered frame for a mockup and a newer frame for that mockup has since arrived (the SDK
5827
+ * revoked the old one). A consumer whose load of `url` failed uses this to tell supersession (the newer frame is
5828
+ * already here; it reaches the results with its batch's all_mockups_rendered) from a real failure.
5829
+ */
5830
+ isFrameSuperseded(url) {
5831
+ return this.supersededFrameUrls.has(url);
5832
+ }
5810
5833
  rerender(mockupIds) {
5811
5834
  if (!this.ws || this.ws.readyState !== WebSocket.OPEN || !this.config || mockupIds.length === 0) return false;
5812
5835
  const { requestId, traceparent } = newRenderCorrelation();
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { createDevFetcher } from './dev-fetcher.cjs';
2
2
  import { PublicDesign, PublicFill, PublicOptions } from '@snowcone-app/mockup-url';
3
- import { O as OptionAttribute, a as OptionSelection, C as Combination, F as FrameworkAdapter, b as ComponentProps, c as ComponentDescriptor, d as ComponentState, e as ComponentContext, f as ComponentLifecycleHooks, E as EventHandler, g as FrameworkUtilities, P as PlacementSettings, M as MockupResult, R as RealtimeRenderError, h as RealtimeMockupService } from './websocket-Cy0Y29CW.cjs';
4
- export { A as AdapterRegistry, i as ProductComponentContext, j as RealtimeMockupCallbacks, k as RealtimeMockupState, l as RenderResult, W as WebSocketConfig, m as WebSocketMessage, n as adapterRegistry, o as computeDisabledChoices, p as createComponent, q as defineComponent, r as deriveDefaultSelection, s as findBestCombination, t as getPricePreview, u as isOptionAvailable, v as resolveBestCombination } from './websocket-Cy0Y29CW.cjs';
3
+ import { O as OptionAttribute, a as OptionSelection, C as Combination, F as FrameworkAdapter, b as ComponentProps, c as ComponentDescriptor, d as ComponentState, e as ComponentContext, f as ComponentLifecycleHooks, E as EventHandler, g as FrameworkUtilities, P as PlacementSettings, M as MockupResult, R as RealtimeRenderError, h as RealtimeMockupService } from './websocket-CTbhT64Y.cjs';
4
+ export { A as AdapterRegistry, i as ProductComponentContext, j as RealtimeMockupCallbacks, k as RealtimeMockupState, l as RenderResult, W as WebSocketConfig, m as WebSocketMessage, n as adapterRegistry, o as computeDisabledChoices, p as createComponent, q as defineComponent, r as deriveDefaultSelection, s as findBestCombination, t as getPricePreview, u as isOptionAvailable, v as resolveBestCombination } from './websocket-CTbhT64Y.cjs';
5
5
 
6
6
  interface CatalogProduct {
7
7
  id: string;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { createDevFetcher } from './dev-fetcher.js';
2
2
  import { PublicDesign, PublicFill, PublicOptions } from '@snowcone-app/mockup-url';
3
- import { O as OptionAttribute, a as OptionSelection, C as Combination, F as FrameworkAdapter, b as ComponentProps, c as ComponentDescriptor, d as ComponentState, e as ComponentContext, f as ComponentLifecycleHooks, E as EventHandler, g as FrameworkUtilities, P as PlacementSettings, M as MockupResult, R as RealtimeRenderError, h as RealtimeMockupService } from './websocket-Cy0Y29CW.js';
4
- export { A as AdapterRegistry, i as ProductComponentContext, j as RealtimeMockupCallbacks, k as RealtimeMockupState, l as RenderResult, W as WebSocketConfig, m as WebSocketMessage, n as adapterRegistry, o as computeDisabledChoices, p as createComponent, q as defineComponent, r as deriveDefaultSelection, s as findBestCombination, t as getPricePreview, u as isOptionAvailable, v as resolveBestCombination } from './websocket-Cy0Y29CW.js';
3
+ import { O as OptionAttribute, a as OptionSelection, C as Combination, F as FrameworkAdapter, b as ComponentProps, c as ComponentDescriptor, d as ComponentState, e as ComponentContext, f as ComponentLifecycleHooks, E as EventHandler, g as FrameworkUtilities, P as PlacementSettings, M as MockupResult, R as RealtimeRenderError, h as RealtimeMockupService } from './websocket-CTbhT64Y.js';
4
+ export { A as AdapterRegistry, i as ProductComponentContext, j as RealtimeMockupCallbacks, k as RealtimeMockupState, l as RenderResult, W as WebSocketConfig, m as WebSocketMessage, n as adapterRegistry, o as computeDisabledChoices, p as createComponent, q as defineComponent, r as deriveDefaultSelection, s as findBestCombination, t as getPricePreview, u as isOptionAvailable, v as resolveBestCombination } from './websocket-CTbhT64Y.js';
5
5
 
6
6
  interface CatalogProduct {
7
7
  id: string;
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  import {
5
5
  REALTIME_WS_URL,
6
6
  RealtimeMockupService
7
- } from "./chunk-P3ZDE6LZ.js";
7
+ } from "./chunk-4NCMFK5L.js";
8
8
  import {
9
9
  buildMockupUrl,
10
10
  buildPublicMockupUrl,
package/dist/react.cjs CHANGED
@@ -122,6 +122,9 @@ var RealtimeMockupService = class {
122
122
  pendingFrames = /* @__PURE__ */ new Map();
123
123
  // Last object URL handed out per mockup — revoked when replaced.
124
124
  liveObjectUrls = /* @__PURE__ */ new Map();
125
+ // Live frames a newer frame for the same mockup has replaced (and revoked), newest last, bounded. Lets a consumer
126
+ // still loading an old frame tell "superseded" from "broken" the moment it fails (isFrameSuperseded).
127
+ supersededFrameUrls = /* @__PURE__ */ new Set();
125
128
  renewTimer = null;
126
129
  isConnecting = false;
127
130
  connectAttempt = 0;
@@ -372,7 +375,7 @@ var RealtimeMockupService = class {
372
375
  }
373
376
  return true;
374
377
  });
375
- this.mockupResults = freshMockups.map((mockup) => {
378
+ const batch = freshMockups.map((mockup) => {
376
379
  const existing = this.mockupResults.find(
377
380
  (m) => m.mockupId === mockup.mockupId && (mockup.requestId === void 0 || m.requestId === mockup.requestId)
378
381
  );
@@ -384,6 +387,11 @@ var RealtimeMockupService = class {
384
387
  }
385
388
  return merged;
386
389
  });
390
+ const batchById = new Map(batch.map((m) => [m.mockupId, m]));
391
+ this.mockupResults = [
392
+ ...this.mockupResults.map((m) => batchById.get(m.mockupId) ?? m),
393
+ ...batch.filter((m) => !this.mockupResults.some((e) => e.mockupId === m.mockupId))
394
+ ];
387
395
  this.lastError = null;
388
396
  this.renderError = null;
389
397
  this.addLog(`\u{1F389} All mockups rendered: ${freshMockups.length} fresh (${data.mockups.length - freshMockups.length} stale filtered)`);
@@ -445,7 +453,14 @@ var RealtimeMockupService = class {
445
453
  if (!frame) return;
446
454
  this.pendingFrames.delete(key);
447
455
  const prevLive = this.liveObjectUrls.get(data.mockupId);
448
- if (prevLive) URL.revokeObjectURL(prevLive);
456
+ if (prevLive) {
457
+ URL.revokeObjectURL(prevLive);
458
+ this.supersededFrameUrls.add(prevLive);
459
+ if (this.supersededFrameUrls.size > 512) {
460
+ const oldest = this.supersededFrameUrls.values().next().value;
461
+ if (oldest) this.supersededFrameUrls.delete(oldest);
462
+ }
463
+ }
449
464
  this.liveObjectUrls.set(data.mockupId, frame.objectUrl);
450
465
  data.imageUrl = frame.objectUrl;
451
466
  }
@@ -811,6 +826,14 @@ ${versionToSend}
811
826
  * E_RERENDER_INCOMPLETE | E_RERENDER_RATE_LIMITED). Never changes the
812
827
  * session's mockupIds.
813
828
  */
829
+ /**
830
+ * True when `url` was a ws-delivered frame for a mockup and a newer frame for that mockup has since arrived (the SDK
831
+ * revoked the old one). A consumer whose load of `url` failed uses this to tell supersession (the newer frame is
832
+ * already here; it reaches the results with its batch's all_mockups_rendered) from a real failure.
833
+ */
834
+ isFrameSuperseded(url) {
835
+ return this.supersededFrameUrls.has(url);
836
+ }
814
837
  rerender(mockupIds) {
815
838
  if (!this.ws || this.ws.readyState !== WebSocket.OPEN || !this.config || mockupIds.length === 0) return false;
816
839
  const { requestId, traceparent } = newRenderCorrelation();
@@ -1036,6 +1059,9 @@ function useRealtimeMockup(options = {}) {
1036
1059
  const rerender = (0, import_react.useCallback)((mockupIds) => {
1037
1060
  return serviceRef.current?.rerender(mockupIds) ?? false;
1038
1061
  }, []);
1062
+ const isFrameSuperseded = (0, import_react.useCallback)((url) => {
1063
+ return serviceRef.current?.isFrameSuperseded(url) ?? false;
1064
+ }, []);
1039
1065
  const getLastSentVersion = (0, import_react.useCallback)(() => {
1040
1066
  return serviceRef.current?.getLastSentVersion() ?? 0;
1041
1067
  }, []);
@@ -1059,7 +1085,8 @@ function useRealtimeMockup(options = {}) {
1059
1085
  hasPendingBlobs,
1060
1086
  getLastSentVersion,
1061
1087
  getLatestSentVersions,
1062
- rerender
1088
+ rerender,
1089
+ isFrameSuperseded
1063
1090
  };
1064
1091
  }
1065
1092
 
package/dist/react.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { M as MockupResult, R as RealtimeRenderError, W as WebSocketConfig, P as PlacementSettings, F as FrameworkAdapter, b as ComponentProps, d as ComponentState, e as ComponentContext, f as ComponentLifecycleHooks, E as EventHandler, c as ComponentDescriptor, g as FrameworkUtilities } from './websocket-Cy0Y29CW.cjs';
1
+ import { M as MockupResult, R as RealtimeRenderError, W as WebSocketConfig, P as PlacementSettings, F as FrameworkAdapter, b as ComponentProps, d as ComponentState, e as ComponentContext, f as ComponentLifecycleHooks, E as EventHandler, c as ComponentDescriptor, g as FrameworkUtilities } from './websocket-CTbhT64Y.cjs';
2
2
  import { CSSProperties, ReactNode } from 'react';
3
3
 
4
4
  interface UseRealtimeMockupOptions {
@@ -56,6 +56,7 @@ declare function useRealtimeMockup(options?: UseRealtimeMockupOptions): {
56
56
  getLastSentVersion: () => number;
57
57
  getLatestSentVersions: () => Record<string, number>;
58
58
  rerender: (mockupIds: string[]) => boolean;
59
+ isFrameSuperseded: (url: string) => boolean;
59
60
  isConnected: boolean;
60
61
  sessionId: string | null;
61
62
  box: string | null;
package/dist/react.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { M as MockupResult, R as RealtimeRenderError, W as WebSocketConfig, P as PlacementSettings, F as FrameworkAdapter, b as ComponentProps, d as ComponentState, e as ComponentContext, f as ComponentLifecycleHooks, E as EventHandler, c as ComponentDescriptor, g as FrameworkUtilities } from './websocket-Cy0Y29CW.js';
1
+ import { M as MockupResult, R as RealtimeRenderError, W as WebSocketConfig, P as PlacementSettings, F as FrameworkAdapter, b as ComponentProps, d as ComponentState, e as ComponentContext, f as ComponentLifecycleHooks, E as EventHandler, c as ComponentDescriptor, g as FrameworkUtilities } from './websocket-CTbhT64Y.js';
2
2
  import { CSSProperties, ReactNode } from 'react';
3
3
 
4
4
  interface UseRealtimeMockupOptions {
@@ -56,6 +56,7 @@ declare function useRealtimeMockup(options?: UseRealtimeMockupOptions): {
56
56
  getLastSentVersion: () => number;
57
57
  getLatestSentVersions: () => Record<string, number>;
58
58
  rerender: (mockupIds: string[]) => boolean;
59
+ isFrameSuperseded: (url: string) => boolean;
59
60
  isConnected: boolean;
60
61
  sessionId: string | null;
61
62
  box: string | null;
package/dist/react.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  RealtimeMockupService
3
- } from "./chunk-P3ZDE6LZ.js";
3
+ } from "./chunk-4NCMFK5L.js";
4
4
 
5
5
  // src/realtime/react.ts
6
6
  import { useCallback, useEffect, useRef, useState } from "react";
@@ -123,6 +123,9 @@ function useRealtimeMockup(options = {}) {
123
123
  const rerender = useCallback((mockupIds) => {
124
124
  return serviceRef.current?.rerender(mockupIds) ?? false;
125
125
  }, []);
126
+ const isFrameSuperseded = useCallback((url) => {
127
+ return serviceRef.current?.isFrameSuperseded(url) ?? false;
128
+ }, []);
126
129
  const getLastSentVersion = useCallback(() => {
127
130
  return serviceRef.current?.getLastSentVersion() ?? 0;
128
131
  }, []);
@@ -146,7 +149,8 @@ function useRealtimeMockup(options = {}) {
146
149
  hasPendingBlobs,
147
150
  getLastSentVersion,
148
151
  getLatestSentVersions,
149
- rerender
152
+ rerender,
153
+ isFrameSuperseded
150
154
  };
151
155
  }
152
156
 
@@ -502,6 +502,7 @@ declare class RealtimeMockupService {
502
502
  private tokenProvider?;
503
503
  private pendingFrames;
504
504
  private liveObjectUrls;
505
+ private supersededFrameUrls;
505
506
  private renewTimer;
506
507
  private isConnecting;
507
508
  private connectAttempt;
@@ -590,6 +591,12 @@ declare class RealtimeMockupService {
590
591
  * E_RERENDER_INCOMPLETE | E_RERENDER_RATE_LIMITED). Never changes the
591
592
  * session's mockupIds.
592
593
  */
594
+ /**
595
+ * True when `url` was a ws-delivered frame for a mockup and a newer frame for that mockup has since arrived (the SDK
596
+ * revoked the old one). A consumer whose load of `url` failed uses this to tell supersession (the newer frame is
597
+ * already here; it reaches the results with its batch's all_mockups_rendered) from a real failure.
598
+ */
599
+ isFrameSuperseded(url: string): boolean;
593
600
  rerender(mockupIds: string[]): boolean;
594
601
  getLastSentVersion(): number;
595
602
  sendColorBlob(placement: string, hexColor: string): boolean;
@@ -502,6 +502,7 @@ declare class RealtimeMockupService {
502
502
  private tokenProvider?;
503
503
  private pendingFrames;
504
504
  private liveObjectUrls;
505
+ private supersededFrameUrls;
505
506
  private renewTimer;
506
507
  private isConnecting;
507
508
  private connectAttempt;
@@ -590,6 +591,12 @@ declare class RealtimeMockupService {
590
591
  * E_RERENDER_INCOMPLETE | E_RERENDER_RATE_LIMITED). Never changes the
591
592
  * session's mockupIds.
592
593
  */
594
+ /**
595
+ * True when `url` was a ws-delivered frame for a mockup and a newer frame for that mockup has since arrived (the SDK
596
+ * revoked the old one). A consumer whose load of `url` failed uses this to tell supersession (the newer frame is
597
+ * already here; it reaches the results with its batch's all_mockups_rendered) from a real failure.
598
+ */
599
+ isFrameSuperseded(url: string): boolean;
593
600
  rerender(mockupIds: string[]): boolean;
594
601
  getLastSentVersion(): number;
595
602
  sendColorBlob(placement: string, hexColor: string): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowcone-app/sdk",
3
- "version": "0.25.0",
3
+ "version": "0.26.0",
4
4
  "description": "Snowcone SDK for product mockups and print-on-demand",
5
5
  "keywords": [
6
6
  "merch",