@contentstack/studio-client 4.1.0 → 4.2.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.
Files changed (122) hide show
  1. package/dist/breakpoints/BreakpointManager.js +3 -2
  2. package/dist/breakpoints/BreakpointManager.js.map +1 -1
  3. package/dist/breakpoints/breakpoint-origin.js +30 -0
  4. package/dist/breakpoints/breakpoint-origin.js.map +1 -0
  5. package/dist/canvas/canvas.type.js +1 -1
  6. package/dist/canvas/canvas.utils.js +165 -4
  7. package/dist/canvas/canvas.utils.js.map +1 -1
  8. package/dist/composable-studio/binding-defect-report.js +106 -0
  9. package/dist/composable-studio/binding-defect-report.js.map +1 -0
  10. package/dist/composable-studio/build-scoped-data.js +21 -11
  11. package/dist/composable-studio/build-scoped-data.js.map +1 -1
  12. package/dist/composable-studio/collect-data-needs.js +1 -1
  13. package/dist/composable-studio/data/pre-process-static-values.js +89 -19
  14. package/dist/composable-studio/data/pre-process-static-values.js.map +1 -1
  15. package/dist/composable-studio/delivery-setup-check.js +92 -0
  16. package/dist/composable-studio/delivery-setup-check.js.map +1 -0
  17. package/dist/composable-studio/resolution-failure-spec.js +53 -0
  18. package/dist/composable-studio/resolution-failure-spec.js.map +1 -0
  19. package/dist/composable-studio/resolution-telemetry.js +68 -0
  20. package/dist/composable-studio/resolution-telemetry.js.map +1 -0
  21. package/dist/composable-studio/sdk.js +683 -551
  22. package/dist/composable-studio/sdk.js.map +1 -1
  23. package/dist/composable-studio/section-binding/compute-all-section-auto-bindings.js +146 -0
  24. package/dist/composable-studio/section-binding/compute-all-section-auto-bindings.js.map +1 -0
  25. package/dist/composable-studio/section-binding/constants.js +27 -0
  26. package/dist/composable-studio/section-binding/constants.js.map +1 -0
  27. package/dist/composable-studio/section-binding/index.js +20 -0
  28. package/dist/composable-studio/section-binding/index.js.map +1 -0
  29. package/dist/composable-studio/section-binding/schema-path.js +112 -0
  30. package/dist/composable-studio/section-binding/schema-path.js.map +1 -0
  31. package/dist/composable-studio/section-binding/section-composition-auto-binding.js +815 -0
  32. package/dist/composable-studio/section-binding/section-composition-auto-binding.js.map +1 -0
  33. package/dist/composable-studio/section-binding/section-compositions.js +349 -0
  34. package/dist/composable-studio/section-binding/section-compositions.js.map +1 -0
  35. package/dist/composable-studio/section-binding/section-internal-ref-introspection.js +72 -0
  36. package/dist/composable-studio/section-binding/section-internal-ref-introspection.js.map +1 -0
  37. package/dist/composable-studio/section-binding/self-describe-section-bindings.js +132 -0
  38. package/dist/composable-studio/section-binding/self-describe-section-bindings.js.map +1 -0
  39. package/dist/composable-studio/section-binding/serialization.js +33 -0
  40. package/dist/composable-studio/section-binding/serialization.js.map +1 -0
  41. package/dist/composable-studio/section-data.js +5 -1
  42. package/dist/composable-studio/section-data.js.map +1 -1
  43. package/dist/composable-studio/setup-check-signal.js +48 -0
  44. package/dist/composable-studio/setup-check-signal.js.map +1 -0
  45. package/dist/composable-studio/studio-intelligence.manager.js +6 -2
  46. package/dist/composable-studio/studio-intelligence.manager.js.map +1 -1
  47. package/dist/config/config.schema.js +97 -104
  48. package/dist/config/config.schema.js.map +1 -1
  49. package/dist/config/process-user-config.js +41 -24
  50. package/dist/config/process-user-config.js.map +1 -1
  51. package/dist/config/stack-sdk-wrapper.js +22 -4
  52. package/dist/config/stack-sdk-wrapper.js.map +1 -1
  53. package/dist/context-menu/context-menu.js +1 -0
  54. package/dist/context-menu/context-menu.js.map +1 -1
  55. package/dist/dnd/dnd-manager.js +1 -0
  56. package/dist/dnd/dnd-manager.js.map +1 -1
  57. package/dist/editor.d.ts +34 -1
  58. package/dist/highlight-node/highlight-node-manager.js +89 -14
  59. package/dist/highlight-node/highlight-node-manager.js.map +1 -1
  60. package/dist/highlight-node/highlight-node.js +11 -5
  61. package/dist/highlight-node/highlight-node.js.map +1 -1
  62. package/dist/highlight-node/history-shortcut.js +78 -0
  63. package/dist/highlight-node/history-shortcut.js.map +1 -0
  64. package/dist/index.d.ts +1082 -354
  65. package/dist/index.js +18 -6
  66. package/dist/index.js.map +1 -1
  67. package/dist/query/query-executor.js +51 -9
  68. package/dist/query/query-executor.js.map +1 -1
  69. package/dist/renderer-mode.d.ts +68 -0
  70. package/dist/renderer-mode.js +2 -0
  71. package/dist/renderer-mode.js.map +1 -0
  72. package/dist/url-metadata/entry-check-key.js +14 -0
  73. package/dist/url-metadata/entry-check-key.js.map +1 -0
  74. package/dist/url-metadata/select-url-winner.js +64 -12
  75. package/dist/url-metadata/select-url-winner.js.map +1 -1
  76. package/dist/url-metadata/types.js +10 -1
  77. package/dist/url-metadata/types.js.map +1 -1
  78. package/dist/url-metadata/url-pattern-matcher.js +11 -2
  79. package/dist/url-metadata/url-pattern-matcher.js.map +1 -1
  80. package/dist/utils/canvas.js +0 -1
  81. package/dist/utils/canvas.js.map +1 -1
  82. package/dist/utils/check-bindings.js +5 -3
  83. package/dist/utils/check-bindings.js.map +1 -1
  84. package/dist/utils/classify-response-error.js +243 -33
  85. package/dist/utils/classify-response-error.js.map +1 -1
  86. package/dist/utils/composable-studio-error.js +7 -0
  87. package/dist/utils/composable-studio-error.js.map +1 -1
  88. package/dist/utils/conditionBlock.js +19 -6
  89. package/dist/utils/conditionBlock.js.map +1 -1
  90. package/dist/utils/constants.js +7 -2
  91. package/dist/utils/constants.js.map +1 -1
  92. package/dist/utils/http-error.constants.js +24 -1
  93. package/dist/utils/http-error.constants.js.map +1 -1
  94. package/dist/utils/include-path-rules.js +3 -2
  95. package/dist/utils/include-path-rules.js.map +1 -1
  96. package/dist/utils/load-error-classifier.js +18 -0
  97. package/dist/utils/load-error-classifier.js.map +1 -0
  98. package/dist/utils/parse-ui.js +27 -5
  99. package/dist/utils/parse-ui.js.map +1 -1
  100. package/dist/utils/preview-hash-refused.js +75 -0
  101. package/dist/utils/preview-hash-refused.js.map +1 -0
  102. package/dist/utils/reference_fetcher.js +79 -12
  103. package/dist/utils/reference_fetcher.js.map +1 -1
  104. package/dist/utils/require-stack.js +83 -20
  105. package/dist/utils/require-stack.js.map +1 -1
  106. package/dist/utils/serialize-for-inline-script.js +19 -0
  107. package/dist/utils/serialize-for-inline-script.js.map +1 -0
  108. package/dist/utils/served-by.js +32 -13
  109. package/dist/utils/served-by.js.map +1 -1
  110. package/dist/utils/spec-analyzer.js +24 -1
  111. package/dist/utils/spec-analyzer.js.map +1 -1
  112. package/dist/utils/studio-error-codes.js +34 -2
  113. package/dist/utils/studio-error-codes.js.map +1 -1
  114. package/dist/utils/studio-error.js +68 -7
  115. package/dist/utils/studio-error.js.map +1 -1
  116. package/dist/visual-builder/composition-save-event.js +36 -5
  117. package/dist/visual-builder/composition-save-event.js.map +1 -1
  118. package/package.json +12 -8
  119. package/dist/studio-internal/dist/utils/section-slot-walker.js +0 -63
  120. package/dist/studio-internal/dist/utils/section-slot-walker.js.map +0 -1
  121. package/dist/studio-internal/dist/utils/spec-compression.js +0 -43
  122. package/dist/studio-internal/dist/utils/spec-compression.js.map +0 -1
@@ -5,29 +5,48 @@
5
5
  * published-content request.
6
6
  */
7
7
  const LIVE_PREVIEW_INIT = "init";
8
+ /** A hash the transport would act on: present, and not the init sentinel. */
9
+ function isUsableHash(hash) {
10
+ return Boolean(hash && hash !== LIVE_PREVIEW_INIT);
11
+ }
8
12
  /**
9
13
  * Which service a request made with this configuration will reach.
10
14
  *
11
- * This is not a proxy for the transport's decision, it is the same predicate:
12
- * `@contentstack/core` swaps in the preview host only when live preview is
13
- * enabled and the hash is present and is not the init sentinel. Anything else
14
- * goes to published content.
15
+ * `@contentstack/core` swaps in the preview host only when live preview is enabled
16
+ * and the hash is present and is not the init sentinel; anything else goes to
17
+ * published content. The swap is to whatever the preview host is set to, though, so
18
+ * a preview host set to the delivery host is published content in either case — and
19
+ * reporting "preview" there would hide the not-published causes from a request that
20
+ * read published content.
15
21
  *
16
22
  * It must be read synchronously, immediately before the request. Live-preview
17
23
  * state is process-wide, so under concurrent server rendering a value read after
18
24
  * an await can belong to a different request.
19
25
  */
20
- function resolveServedBy(
21
- /**
22
- * A stack's live-preview configuration. `live_preview` is the hash, named the
23
- * way the transport reads it.
24
- */
25
- livePreview) {
26
+ function resolveServedBy(stack) {
27
+ const livePreview = stack?.livePreviewConfig;
26
28
  if (!livePreview?.enable)
27
29
  return "cdn";
28
- const hash = livePreview.live_preview;
29
- return hash && hash !== LIVE_PREVIEW_INIT ? "preview" : "cdn";
30
+ if (!isUsableHash(livePreview.live_preview))
31
+ return "cdn";
32
+ const previewHost = livePreview.host;
33
+ if (previewHost && stack?.host && previewHost === stack.host)
34
+ return "cdn";
35
+ return "preview";
36
+ }
37
+ /**
38
+ * The route of the request about to be made: which service it reaches, and whether
39
+ * a hash reached it. Read together, in one synchronous call, for the same reason
40
+ * `resolveServedBy` must be read before any await.
41
+ */
42
+ function captureRequestRoute(stack) {
43
+ return {
44
+ servedBy: resolveServedBy(stack),
45
+ hasPreviewHash: stack
46
+ ? isUsableHash(stack.livePreviewConfig?.live_preview)
47
+ : undefined,
48
+ };
30
49
  }
31
50
 
32
- export { resolveServedBy };
51
+ export { captureRequestRoute, isUsableHash, resolveServedBy };
33
52
  //# sourceMappingURL=served-by.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"served-by.js","sources":["../../src/utils/served-by.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA;;;;;AAKG;AACH,MAAM,iBAAiB,GAAG,MAAM;AAKhC;;;;;;;;;;;AAWG;SACa,eAAe;AAC7B;;;AAGG;AACH,WAAoE,EAAA;IAEpE,IAAI,CAAC,WAAW,EAAE,MAAM;AAAE,QAAA,OAAO,KAAK;AAEtC,IAAA,MAAM,IAAI,GAAG,WAAW,CAAC,YAAY;AACrC,IAAA,OAAO,IAAI,IAAI,IAAI,KAAK,iBAAiB,GAAG,SAAS,GAAG,KAAK;AAC/D;;;;"}
1
+ {"version":3,"file":"served-by.js","sources":["../../src/utils/served-by.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA;;;;;AAKG;AACH,MAAM,iBAAiB,GAAG,MAAM;AAiChC;AACM,SAAU,YAAY,CAAC,IAAwB,EAAA;IACnD,OAAO,OAAO,CAAC,IAAI,IAAI,IAAI,KAAK,iBAAiB,CAAC;AACpD;AAEA;;;;;;;;;;;;;AAaG;AACG,SAAU,eAAe,CAAC,KAA+B,EAAA;AAC7D,IAAA,MAAM,WAAW,GAAG,KAAK,EAAE,iBAAiB;IAC5C,IAAI,CAAC,WAAW,EAAE,MAAM;AAAE,QAAA,OAAO,KAAK;AACtC,IAAA,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,YAAY,CAAC;AAAE,QAAA,OAAO,KAAK;AAEzD,IAAA,MAAM,WAAW,GAAG,WAAW,CAAC,IAAI;IACpC,IAAI,WAAW,IAAI,KAAK,EAAE,IAAI,IAAI,WAAW,KAAK,KAAK,CAAC,IAAI;AAAE,QAAA,OAAO,KAAK;AAE1E,IAAA,OAAO,SAAS;AAClB;AAEA;;;;AAIG;AACG,SAAU,mBAAmB,CACjC,KAA+B,EAAA;IAE/B,OAAO;AACL,QAAA,QAAQ,EAAE,eAAe,CAAC,KAAK,CAAC;AAChC,QAAA,cAAc,EAAE;cACZ,YAAY,CAAC,KAAK,CAAC,iBAAiB,EAAE,YAAY;AACpD,cAAE,SAAS;KACd;AACH;;;;"}
@@ -107,6 +107,29 @@ function getComponentUsageStats(spec) {
107
107
  traverse(spec);
108
108
  return stats;
109
109
  }
110
+ /**
111
+ * The `compositionUID` of every placed section in a layout — the types
112
+ * analyzeUsedComponents reports for section-composition nodes, so a check can
113
+ * tell a section that did not load from a component that is not registered.
114
+ */
115
+ function analyzePlacedSectionUids(spec) {
116
+ const uids = new Set();
117
+ const traverse = (node) => {
118
+ if (!node || typeof node !== "object")
119
+ return;
120
+ if (node.type === "section-composition") {
121
+ const uid = getSectionUIDFromNode(node);
122
+ if (uid)
123
+ uids.add(uid);
124
+ }
125
+ for (const slot of Object.values(node.slots ?? {})) {
126
+ if (Array.isArray(slot))
127
+ slot.forEach(traverse);
128
+ }
129
+ };
130
+ traverse(spec);
131
+ return uids;
132
+ }
110
133
 
111
- export { analyzeMultipleSpecs, analyzeUsedComponents, getComponentUsageStats, specUsesComponent };
134
+ export { analyzeMultipleSpecs, analyzePlacedSectionUids, analyzeUsedComponents, getComponentUsageStats, specUsesComponent };
112
135
  //# sourceMappingURL=spec-analyzer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"spec-analyzer.js","sources":["../../src/utils/spec-analyzer.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAGA;;;;;;AAMG;AACH,SAAS,0BAA0B,CAAC,IAAU,EAAA;AAC5C,IAAA,IAAI,IAAI,CAAC,IAAI,KAAK,qBAAqB,EAAE;QACvC,OAAO,qBAAqB,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI;IACjD;AACA,IAAA,OAAO,IAAI,CAAC,IAAI,IAAI,IAAI;AAC1B;AAEA;;;;;;AAMG;AACG,SAAU,qBAAqB,CACnC,IAA6B,EAAA;AAE7B,IAAA,MAAM,cAAc,GAAG,IAAI,GAAG,EAAU;IAExC,SAAS,QAAQ,CAAC,IAA6B,EAAA;AAC7C,QAAA,IAAI,CAAC,IAAI;YAAE;;AAGX,QAAA,MAAM,cAAc,GAAG,0BAA0B,CAAC,IAAI,CAAC;QACvD,IAAI,cAAc,EAAE;AAClB,YAAA,cAAc,CAAC,GAAG,CAAC,cAAc,CAAC;QACpC;;QAGA,IAAI,IAAI,CAAC,KAAK,IAAI,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ,EAAE;AAChD,YAAA,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,WAAgB,KAAI;AAC3D,gBAAA,IAAI,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE;AAC9B,oBAAA,WAAW,CAAC,OAAO,CAAC,CAAC,KAAK,KAAK,QAAQ,CAAC,KAAK,CAAC,CAAC;gBACjD;AAAO,qBAAA,IAAI,WAAW,IAAI,OAAO,WAAW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K,CAAC,CAAC;QACjE;IACF;IAEA,QAAQ,CAAC,IAAI,CAAC;AACd,IAAA,OAAO,KAAK;AACd;AAEA;;;;AAIG;AACG,SAAU,wBAAwB,CACtC,IAA6B,EAAA;AAE7B,IAAA,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU;AAC9B,IAAA,MAAM,QAAQ,GAAG,CAAC,IAA6B,KAAI;AACjD,QAAA,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;YAAE;AACvC,QAAA,IAAI,IAAI,CAAC,IAAI,KAAK,qBAAqB,EAAE;AACvC,YAAA,MAAM,GAAG,GAAG,qBAAqB,CAAC,IAAI,CAAC;AACvC,YAAA,IAAI,GAAG;AAAE,gBAAA,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;QACxB;AACA,QAAA,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE;AAClD,YAAA,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC;AAAE,gBAAA,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;QACjD;AACF,IAAA,CAAC;IACD,QAAQ,CAAC,IAAI,CAAC;AACd,IAAA,OAAO,IAAI;AACb;;;;"}
@@ -17,12 +17,30 @@ const StudioErrorCode = {
17
17
  CONTENT_TYPE_NOT_FOUND: "CONTENT_TYPE_NOT_FOUND",
18
18
  /** No stack on this host answers to the API key the request carried. */
19
19
  STACK_NOT_FOUND_ON_HOST: "STACK_NOT_FOUND_ON_HOST",
20
+ /** The stack was found, and it refused the delivery token the request carried. */
21
+ DELIVERY_TOKEN_INVALID: "DELIVERY_TOKEN_INVALID",
22
+ /**
23
+ * The live preview session belongs to a different stack from the API key the
24
+ * request carried. Only a preview request can get this, so in practice only a
25
+ * page opened in Studio or the Visual Editor sees it.
26
+ */
27
+ PREVIEW_STACK_MISMATCH: "PREVIEW_STACK_MISMATCH",
28
+ /**
29
+ * The preview host refused the request's preview hash: it has expired, was
30
+ * made up, or belongs to a session that has ended. A visitor's request that
31
+ * carried one (an old or copied preview link) never sees this: the SDK
32
+ * fetches the published composition instead. It reaches a host only from
33
+ * inside Studio's canvas, or when that published fetch fails too.
34
+ */
35
+ PREVIEW_HASH_REFUSED: "PREVIEW_HASH_REFUSED",
20
36
  /** The stack has no environment by the name the connection uses. */
21
37
  ENVIRONMENT_NOT_FOUND: "ENVIRONMENT_NOT_FOUND",
22
38
  /** The stack has no language by the code the SDK was configured with. */
23
39
  LOCALE_NOT_CONFIGURED: "LOCALE_NOT_CONFIGURED",
24
40
  /** The address asked for a language the stack does not have. */
25
41
  URL_LOCALE_NOT_FOUND: "URL_LOCALE_NOT_FOUND",
42
+ /** The stack has no branch by the name the site's stack was given. */
43
+ BRANCH_NOT_FOUND: "BRANCH_NOT_FOUND",
26
44
  /**
27
45
  * Studio was given no Contentstack stack to query, or given something that is
28
46
  * not one. Raised by the first call that needs the stack, never at setup: a
@@ -55,10 +73,19 @@ const StudioErrorCode = {
55
73
  * message says so rather than only naming the gap.
56
74
  */
57
75
  ENVIRONMENT_MISSING: "ENVIRONMENT_MISSING",
76
+ /**
77
+ * The site passed `contentTypeUid`, and it is empty or blank.
78
+ *
79
+ * What a deploy produces when the variable exists and holds nothing: `??` keeps
80
+ * the `""`, so the default never applies. Before this was named, the empty uid
81
+ * built a query the delivery SDK cannot use, the call threw before any request,
82
+ * and that throw was reported as `TRANSPORT_FAILED`.
83
+ */
84
+ CONTENT_TYPE_UID_EMPTY: "CONTENT_TYPE_UID_EMPTY",
58
85
  /**
59
86
  * The configured Contentstack address cannot be used as written: it does not
60
- * parse as an address, or it is `http:` on a page the browser serves over
61
- * `https:` and will block as mixed content.
87
+ * parse as an address, or it carries a scheme (`https://cdn…`), which both
88
+ * delivery SDKs prefix with their own and so send nowhere.
62
89
  *
63
90
  * States only that the value cannot work, never what it should have been. We
64
91
  * have no way to know the right host, and any test for a Contentstack-shaped
@@ -205,15 +232,20 @@ const StudioErrorClass = {
205
232
  const ERROR_CLASS = {
206
233
  [StudioErrorCode.CONTENT_TYPE_NOT_FOUND]: StudioErrorClass.SETUP_INVALID,
207
234
  [StudioErrorCode.STACK_NOT_FOUND_ON_HOST]: StudioErrorClass.SETUP_INVALID,
235
+ [StudioErrorCode.DELIVERY_TOKEN_INVALID]: StudioErrorClass.SETUP_INVALID,
236
+ [StudioErrorCode.PREVIEW_STACK_MISMATCH]: StudioErrorClass.SETUP_INVALID,
237
+ [StudioErrorCode.PREVIEW_HASH_REFUSED]: StudioErrorClass.SETUP_INVALID,
208
238
  [StudioErrorCode.ENVIRONMENT_NOT_FOUND]: StudioErrorClass.SETUP_INVALID,
209
239
  [StudioErrorCode.LOCALE_NOT_CONFIGURED]: StudioErrorClass.SETUP_INVALID,
210
240
  // The address is visitor input, so a language it names and the stack lacks
211
241
  // means "no such page", not a broken setup.
212
242
  [StudioErrorCode.URL_LOCALE_NOT_FOUND]: StudioErrorClass.NOT_FOUND,
243
+ [StudioErrorCode.BRANCH_NOT_FOUND]: StudioErrorClass.SETUP_INVALID,
213
244
  [StudioErrorCode.STACK_SDK_MISSING]: StudioErrorClass.SETUP_INCOMPLETE,
214
245
  [StudioErrorCode.API_KEY_MISSING]: StudioErrorClass.SETUP_INCOMPLETE,
215
246
  [StudioErrorCode.DELIVERY_TOKEN_MISSING]: StudioErrorClass.SETUP_INCOMPLETE,
216
247
  [StudioErrorCode.ENVIRONMENT_MISSING]: StudioErrorClass.SETUP_INCOMPLETE,
248
+ [StudioErrorCode.CONTENT_TYPE_UID_EMPTY]: StudioErrorClass.SETUP_INCOMPLETE,
217
249
  // Supplied and wrong, rather than absent: we proved this value cannot work.
218
250
  [StudioErrorCode.HOST_UNUSABLE]: StudioErrorClass.SETUP_INVALID,
219
251
  // Never a not-found: the page may exist, the call just never asked for one.
@@ -1 +1 @@
1
- {"version":3,"file":"studio-error-codes.js","sources":["../../src/utils/studio-error-codes.ts"],"sourcesContent":[null],"names":[],"mappings":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AAY;AAClE,IAAA,CAAC,eAAe,CAAC,eAAe,GAAG,gBAAgB,CAAC,YAAY;;;;AAIhE,IAAA,CAAC,eAAe,CAAC,sBAAsB,GAAG,gBAAgB,CAAC,SAAS;;AAEpE,IAAA,CAAC,eAAe,CAAC,oBAAoB,GAAG,gBAAgB,CAAC,SAAS;AAClE,IAAA,CAAC,eAAe,CAAC,yBAAyB,GAAG,gBAAgB,CAAC,SAAS;;;AAGvE,IAAA,CAAC,eAAe,CAAC,yBAAyB,GAAG,gBAAgB,CAAC,SAAS;;;AAGvE,IAAA,CAAC,eAAe,CAAC,wBAAwB,GAAG,gBAAgB,CAAC,gBAAgB;;;AAG7E,IAAA,CAAC,eAAe,CAAC,gBAAgB,GAAG,gBAAgB,CAAC,aAAa;;;AAGlE,IAAA,CAAC,eAAe,CAAC,cAAc,GAAG,gBAAgB,CAAC,YAAY;AAC/D,IAAA,CAAC,eAAe,CAAC,wCAAwC,GACvD,gBAAgB,CAAC,SAAS;;;;;"}
@@ -13,8 +13,14 @@ export { ERROR_CLASS } from './studio-error-codes.js';
13
13
  * (`code`), what happened (`message`), what to do (`causes`), where the request
14
14
  * went (`context`), and what this particular failure established (`details`).
15
15
  */
16
- /** Reads the facts a diagnosis prints from the config the fetch actually used. */
17
- function buildStudioErrorContext(config, servedBy = "unknown") {
16
+ /**
17
+ * Reads the facts a diagnosis prints from the config the fetch actually used.
18
+ *
19
+ * `route` is what the caller captured immediately before the request. The rest is
20
+ * configuration, safe to read here even after an await; the hash is not, which is
21
+ * why it arrives with the route instead of being read from the stack.
22
+ */
23
+ function buildStudioErrorContext(config, route = {}) {
18
24
  const stack = config?.stackSdk;
19
25
  return {
20
26
  mode: detectStudioMode(),
@@ -28,10 +34,27 @@ function buildStudioErrorContext(config, servedBy = "unknown") {
28
34
  livePreviewEnabled: stack
29
35
  ? stack.livePreviewConfig?.enable === true
30
36
  : undefined,
31
- servedBy,
37
+ // A boolean, never the value: the token must not cross this boundary.
38
+ hasPreviewToken: stack
39
+ ? Boolean(stack.livePreviewConfig?.preview_token)
40
+ : undefined,
41
+ previewHost: stack?.livePreviewConfig?.host,
42
+ hasPreviewHash: route.hasPreviewHash,
43
+ servedBy: route.servedBy ?? "unknown",
32
44
  sdkVersion: SDK_VERSION,
33
45
  };
34
46
  }
47
+ /** What every SDK message starts with, so it can be found in a shared console. */
48
+ const STUDIO_LOG_PREFIX = "[Contentstack Studio]";
49
+ /**
50
+ * The heading over the causes, shared so the log and the canvas failure card
51
+ * cannot drift apart.
52
+ */
53
+ const STUDIO_NEXT_STEPS_HEADING = "What to do, most likely first:";
54
+ /** One step under that heading, as both the log and the card word it. */
55
+ function formatStudioErrorCause({ cause, fix }) {
56
+ return `${cause} ${fix}`;
57
+ }
35
58
  /**
36
59
  * The rendered message carries the code, the headline and every cause. It has
37
60
  * to, because `console.error(err)`, a framework error overlay and a Sentry
@@ -52,13 +75,13 @@ function buildStudioErrorContext(config, servedBy = "unknown") {
52
75
  * it would invent a problem.
53
76
  */
54
77
  function renderStudioErrorMessage(input) {
55
- const headline = `[Contentstack Studio] ${input.code}: ${input.headline}`;
78
+ const headline = `${STUDIO_LOG_PREFIX} ${input.code}: ${input.headline}`;
56
79
  if (!input.causes?.length)
57
80
  return headline;
58
81
  const causes = input.causes
59
- .map(({ cause, fix }, index) => ` ${index + 1}. ${cause} ${fix}`)
82
+ .map((cause, index) => ` ${index + 1}. ${formatStudioErrorCause(cause)}`)
60
83
  .join("\n");
61
- return [headline, "", "What to do, most likely first:", causes].join("\n");
84
+ return [headline, "", STUDIO_NEXT_STEPS_HEADING, causes].join("\n");
62
85
  }
63
86
  /**
64
87
  * Builds the error and returns it to be thrown.
@@ -90,6 +113,7 @@ function createStudioError(input) {
90
113
  troubleshootingInfo: [...input.causes],
91
114
  });
92
115
  error.code = input.code;
116
+ error.headline = input.headline;
93
117
  error.causes = input.causes;
94
118
  error.context = input.context;
95
119
  error.findings = input.findings;
@@ -117,6 +141,43 @@ function isSetupFault(error) {
117
141
  return (error.errorClass === StudioErrorClass.SETUP_INCOMPLETE ||
118
142
  error.errorClass === StudioErrorClass.SETUP_INVALID);
119
143
  }
144
+ /**
145
+ * An error as plain data, the inverse of `rebuildStudioError`. Both directions
146
+ * live here so a field added to the error is carried both ways or neither.
147
+ * An error the SDK did not diagnose keeps only its message.
148
+ */
149
+ function serializeStudioError(error) {
150
+ if (!(error instanceof ComposableStudioError)) {
151
+ return {
152
+ message: error instanceof Error ? error.message : "Unknown error",
153
+ };
154
+ }
155
+ return {
156
+ message: error.message,
157
+ code: error.code,
158
+ headline: error.headline,
159
+ class: error.errorClass,
160
+ causes: error.causes && [...error.causes],
161
+ findings: error.findings && { ...error.findings },
162
+ };
163
+ }
164
+ /**
165
+ * The error rebuilt from its plain-data copy, for code that only has the copy —
166
+ * a browser rendering what the server diagnosed. Same subclass rule as
167
+ * `createStudioError`.
168
+ */
169
+ function rebuildStudioError(serializedError) {
170
+ const code = serializedError.code;
171
+ const ErrorClass = code && codeIsNotFound(code)
172
+ ? CompositionNotFoundError
173
+ : ComposableStudioError;
174
+ return Object.assign(new ErrorClass(serializedError.message), {
175
+ code,
176
+ headline: serializedError.headline,
177
+ causes: serializedError.causes,
178
+ findings: serializedError.findings,
179
+ });
180
+ }
120
181
 
121
- export { buildStudioErrorContext, createStudioError, isSetupFault, renderStudioErrorMessage };
182
+ export { STUDIO_LOG_PREFIX, STUDIO_NEXT_STEPS_HEADING, buildStudioErrorContext, createStudioError, formatStudioErrorCause, isSetupFault, rebuildStudioError, renderStudioErrorMessage, serializeStudioError };
122
183
  //# sourceMappingURL=studio-error.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"studio-error.js","sources":["../../src/utils/studio-error.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;;AAAA;;;;;;;AAOG;AAkFH;SACgB,uBAAuB,CACrC,MAAe,EACf,WAAqB,SAAS,EAAA;AAE9B,IAAA,MAAM,KAAK,GAAG,MAAM,EAAE,QAAQ;IAC9B,OAAO;QACL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QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,KAAK,EAAE,KAAK,CAAC,UAAU;QACvB,MAAM,EAAE,KAAK,CAAC,MAAM,IAAI,CAAC,GAAG,KAAK,CAAC,MAAM,CAAC;QACzC,QAAQ,EAAE,KAAK,CAAC,QAAQ,IAAI,EAAE,GAAG,KAAK,CAAC,QAAQ,EAAE;KAClD;AACH;AAEA;;;;AAIG;AACG,SAAU,kBAAkB,CAChC,eAAsC,EAAA;AAEtC,IAAA,MAAM,IAAI,GAAG,eAAe,CAAC,IAAuC;AACpE,IAAA,MAAM,UAAU,GACd,IAAI,IAAI,cAAc,CAAC,IAAI;AACzB,UAAE;UACA,qBAAqB;IAC3B,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,UAAU,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE;QAC5D,IAAI;QACJ,QAAQ,EAAE,eAAe,CAAC,QAAQ;QAClC,MAAM,EAAE,eAAe,CAAC,MAA4B;QACpD,QAAQ,EAAE,eAAe,CAAC,QAA2C;AACtE,KAAA,CAAC;AACJ;;;;"}
@@ -2,12 +2,43 @@ import { VISUAL_BUILDER_POST_MESSAGE_EVENTS } from '@contentstack/studio-messeng
2
2
  import { visualBuilderEventManager } from '@contentstack/studio-messenger';
3
3
  import { composableStudioEventEmitter } from '../emitted-events/event-emitter.js';
4
4
 
5
+ /** The one Visual Builder listener the page's compositions share. */
6
+ let sharedRegistration;
7
+ let registrationCount = 0;
8
+ /**
9
+ * Passes the Visual Builder's "refetch-spec" (sent after a composition is
10
+ * saved in Studio) on to every composition on the page, through the
11
+ * `refetch-spec` emitted event.
12
+ *
13
+ * Every caller shares one Visual Builder listener, so the event is emitted
14
+ * once however many compositions (and the editor) register; the listener goes
15
+ * when the last caller unregisters.
16
+ */
5
17
  const compositionSaveEventListener = () => {
6
- // the event data for refetch-spec is same as CompositionSavedEventData
7
- return visualBuilderEventManager?.on(VISUAL_BUILDER_POST_MESSAGE_EVENTS.REFETCH_SPEC, (event) => {
8
- // emit the event for all the composable components
9
- composableStudioEventEmitter.emit("refetch-spec", event.data);
10
- });
18
+ if (!visualBuilderEventManager)
19
+ return undefined;
20
+ if (registrationCount === 0) {
21
+ // the event data for refetch-spec is same as CompositionSavedEventData
22
+ sharedRegistration =
23
+ visualBuilderEventManager.on(VISUAL_BUILDER_POST_MESSAGE_EVENTS.REFETCH_SPEC, (event) => {
24
+ // emit the event for all the composable components
25
+ composableStudioEventEmitter.emit("refetch-spec", event.data);
26
+ });
27
+ }
28
+ registrationCount++;
29
+ let unregistered = false;
30
+ return {
31
+ unregister: () => {
32
+ if (unregistered)
33
+ return;
34
+ unregistered = true;
35
+ registrationCount--;
36
+ if (registrationCount === 0) {
37
+ sharedRegistration?.unregister();
38
+ sharedRegistration = undefined;
39
+ }
40
+ },
41
+ };
11
42
  };
12
43
 
13
44
  export { compositionSaveEventListener };
@@ -1 +1 @@
1
- {"version":3,"file":"composition-save-event.js","sources":["../../src/visual-builder/composition-save-event.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAKO,MAAM,4BAA4B,GAAG,MAAK;;IAE/C,OAAO,yBAAyB,EAAE,EAAE,CAClC,kCAAkC,CAAC,YAAY,EAC/C,CAAC,KAAK,KAAI;;QAER,4BAA4B,CAAC,IAAI,CAAC,cAAc,EAAE,KAAK,CAAC,IAAI,CAAC;AAC/D,IAAA,CAAC,CACF;AACH;;;;"}
1
+ {"version":3,"file":"composition-save-event.js","sources":["../../src/visual-builder/composition-save-event.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;AAKA;AACA,IAAI,kBAA0D;AAC9D,IAAI,iBAAiB,GAAG,CAAC;AAEzB;;;;;;;;AAQG;AACI,MAAM,4BAA4B,GAAG,MAE5B;AACd,IAAA,IAAI,CAAC,yBAAyB;AAAE,QAAA,OAAO,SAAS;AAChD,IAAA,IAAI,iBAAiB,KAAK,CAAC,EAAE;;QAE3B,kBAAkB;YAChB,yBAAyB,CAAC,EAAE,CAC1B,kCAAkC,CAAC,YAAY,EAC/C,CAAC,KAAK,KAAI;;gBAER,4BAA4B,CAAC,IAAI,CAAC,cAAc,EAAE,KAAK,CAAC,IAAI,CAAC;AAC/D,YAAA,CAAC,CACF;IACL;AACA,IAAA,iBAAiB,EAAE;IACnB,IAAI,YAAY,GAAG,KAAK;IACxB,OAAO;QACL,UAAU,EAAE,MAAK;AACf,YAAA,IAAI,YAAY;gBAAE;YAClB,YAAY,GAAG,IAAI;AACnB,YAAA,iBAAiB,EAAE;AACnB,YAAA,IAAI,iBAAiB,KAAK,CAAC,EAAE;gBAC3B,kBAAkB,EAAE,UAAU,EAAE;gBAChC,kBAAkB,GAAG,SAAS;YAChC;QACF,CAAC;KACF;AACH;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentstack/studio-client",
3
- "version": "4.1.0",
3
+ "version": "4.2.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "module": "dist/index.js",
@@ -30,9 +30,9 @@
30
30
  "url": "https://github.com/contentstack/composable-studio-sdk/issues"
31
31
  },
32
32
  "devDependencies": {
33
- "@contentstack/common-config": "^1.2.6",
33
+ "@contentstack/common-config": "^1.2.7",
34
34
  "@contentstack/delivery-sdk": "^4.5.0",
35
- "@contentstack/studio-internal": "^1.8.1",
35
+ "@contentstack/studio-internal": "^1.9.0",
36
36
  "@rollup/plugin-commonjs": "^28.0.6",
37
37
  "@rollup/plugin-node-resolve": "^16.0.1",
38
38
  "@rollup/plugin-replace": "^6.0.3",
@@ -48,14 +48,13 @@
48
48
  "typescript": "^5.5.4"
49
49
  },
50
50
  "dependencies": {
51
- "@contentstack/studio-message-types": "^2.1.0",
52
- "@contentstack/studio-messenger": "^3.2.1",
53
- "@contentstack/studio-registry": "^2.0.1",
51
+ "@contentstack/studio-message-types": "^2.2.0",
52
+ "@contentstack/studio-messenger": "^3.3.0",
53
+ "@contentstack/studio-registry": "^2.1.0",
54
54
  "eventemitter3": "^5.0.1",
55
55
  "fflate": "^0.8.2",
56
56
  "lodash-es": "^4.18.1",
57
- "modern-screenshot": "^4.7.0",
58
- "zod": "^3.23.8"
57
+ "modern-screenshot": "^4.7.0"
59
58
  },
60
59
  "exports": {
61
60
  ".": {
@@ -68,6 +67,11 @@
68
67
  "import": "./dist/editor.js",
69
68
  "default": "./dist/editor.js"
70
69
  },
70
+ "./renderer-mode": {
71
+ "types": "./dist/renderer-mode.d.ts",
72
+ "import": "./dist/renderer-mode.js",
73
+ "default": "./dist/renderer-mode.js"
74
+ },
71
75
  "./*": "./*"
72
76
  }
73
77
  }
@@ -1,63 +0,0 @@
1
- /**
2
- * Shared section-UI walker for section-slot context resolution.
3
- *
4
- * Sections expose `section-slot` placeholders inside their authored UI. When
5
- * those slots are filled on a page composition, the slot children render
6
- * inside the section's body — surrounded by whatever Repeater /
7
- * ConditionBlock chain wraps the matching `section-slot` in the section's
8
- * authored UI.
9
- *
10
- * Three call sites historically each rolled their own walker:
11
- *
12
- * - Studio's `findSectionCompositionInstances` (auto-binder) — needs
13
- * parentRepeaterUid + cumulative schema-path segments for the
14
- * auto-binder's contextSchemaPath input.
15
- * - Studio's picker `getRepeatersWrappingSectionSlot` — needs the actual
16
- * Repeater node references for a SPECIFIC slot (to feed the picker's
17
- * repeater adapters and to surface the section title as the picker
18
- * header label).
19
- * - SDK's `indexSectionInternalSlotRepeaters` — needs only the nearest
20
- * ancestor Repeater uid per slot, for the per-instance binding seeder.
21
- *
22
- * All three did the same walk with different output shapes. This module
23
- * does the walk ONCE and exposes the raw ancestor-node chain per slot;
24
- * each consumer derives the shape it needs. Lives in `studio-internal`
25
- * because that's the only SDK package both Studio and the SDK packages
26
- * symlink to.
27
- */
28
- /**
29
- * Walks `sectionUI` and returns, for every `section-slot` encountered, the
30
- * chain of ancestor Repeater and ConditionBlock nodes wrapping it.
31
- *
32
- * The returned arrays preserve root→leaf order so callers can either
33
- * - read the LAST entry as the nearest ancestor (e.g. parentRepeaterUid), or
34
- * - join their bindings to derive the cumulative schema path.
35
- *
36
- * Returns a map keyed by section-slot uid. If a slot uid is missing from the
37
- * map the slot isn't wrapped by any Repeater / ConditionBlock in the section
38
- * (or doesn't exist in this section).
39
- */
40
- function indexSectionSlotContexts(sectionUI) {
41
- const out = {};
42
- const walk = (node, ancestors) => {
43
- if (!node || typeof node !== "object")
44
- return;
45
- if (node.type === "section-slot" && typeof node.uid === "string") {
46
- out[node.uid] = { ancestorNodes: ancestors };
47
- }
48
- const nextAncestors = node.type === "repeater" || node.type === "condition-block"
49
- ? [...ancestors, node]
50
- : ancestors;
51
- const slots = node.slots || {};
52
- for (const slotId of Object.keys(slots)) {
53
- for (const child of slots[slotId] || []) {
54
- walk(child, nextAncestors);
55
- }
56
- }
57
- };
58
- walk(sectionUI, []);
59
- return out;
60
- }
61
-
62
- export { indexSectionSlotContexts };
63
- //# sourceMappingURL=section-slot-walker.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"section-slot-walker.js","sources":["../../../../../studio-internal/dist/utils/section-slot-walker.js"],"sourcesContent":["/**\n * Shared section-UI walker for section-slot context resolution.\n *\n * Sections expose `section-slot` placeholders inside their authored UI. When\n * those slots are filled on a page composition, the slot children render\n * inside the section's body — surrounded by whatever Repeater /\n * ConditionBlock chain wraps the matching `section-slot` in the section's\n * authored UI.\n *\n * Three call sites historically each rolled their own walker:\n *\n * - Studio's `findSectionCompositionInstances` (auto-binder) — needs\n * parentRepeaterUid + cumulative schema-path segments for the\n * auto-binder's contextSchemaPath input.\n * - Studio's picker `getRepeatersWrappingSectionSlot` — needs the actual\n * Repeater node references for a SPECIFIC slot (to feed the picker's\n * repeater adapters and to surface the section title as the picker\n * header label).\n * - SDK's `indexSectionInternalSlotRepeaters` — needs only the nearest\n * ancestor Repeater uid per slot, for the per-instance binding seeder.\n *\n * All three did the same walk with different output shapes. This module\n * does the walk ONCE and exposes the raw ancestor-node chain per slot;\n * each consumer derives the shape it needs. Lives in `studio-internal`\n * because that's the only SDK package both Studio and the SDK packages\n * symlink to.\n */\n/**\n * Walks `sectionUI` and returns, for every `section-slot` encountered, the\n * chain of ancestor Repeater and ConditionBlock nodes wrapping it.\n *\n * The returned arrays preserve root→leaf order so callers can either\n * - read the LAST entry as the nearest ancestor (e.g. parentRepeaterUid), or\n * - join their bindings to derive the cumulative schema path.\n *\n * Returns a map keyed by section-slot uid. If a slot uid is missing from the\n * map the slot isn't wrapped by any Repeater / ConditionBlock in the section\n * (or doesn't exist in this section).\n */\nfunction indexSectionSlotContexts(sectionUI) {\n const out = {};\n const walk = (node, ancestors) => {\n if (!node || typeof node !== \"object\")\n return;\n if (node.type === \"section-slot\" && typeof node.uid === \"string\") {\n out[node.uid] = { ancestorNodes: ancestors };\n }\n const nextAncestors = node.type === \"repeater\" || node.type === \"condition-block\"\n ? [...ancestors, node]\n : ancestors;\n const slots = node.slots || {};\n for (const slotId of Object.keys(slots)) {\n for (const child of slots[slotId] || []) {\n walk(child, nextAncestors);\n }\n }\n };\n walk(sectionUI, []);\n return out;\n}\n\nexport { indexSectionSlotContexts };\n//# sourceMappingURL=section-slot-walker.js.map\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,wBAAwB,CAAC,SAAS,EAAE;AAC7C,IAAI,MAAM,GAAG,GAAG,EAAE;AAClB,IAAI,MAAM,IAAI,GAAG,CAAC,IAAI,EAAE,SAAS,KAAK;AACtC,QAAQ,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;AAC7C,YAAY;AACZ,QAAQ,IAAI,IAAI,CAAC,IAAI,KAAK,cAAc,IAAI,OAAO,IAAI,CAAC,GAAG,KAAK,QAAQ,EAAE;AAC1E,YAAY,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,aAAa,EAAE,SAAS,EAAE;AACxD,QAAQ;AACR,QAAQ,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,KAAK,UAAU,IAAI,IAAI,CAAC,IAAI,KAAK;AACxE,cAAc,CAAC,GAAG,SAAS,EAAE,IAAI;AACjC,cAAc,SAAS;AACvB,QAAQ,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,EAAE;AACtC,QAAQ,KAAK,MAAM,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;AACjD,YAAY,KAAK,MAAM,KAAK,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE;AACrD,gBAAgB,IAAI,CAAC,KAAK,EAAE,aAAa,CAAC;AAC1C,YAAY;AACZ,QAAQ;AACR,IAAI,CAAC;AACL,IAAI,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC;AACvB,IAAI,OAAO,GAAG;AACd;;;;"}
@@ -1,43 +0,0 @@
1
- import { unzlibSync } from 'fflate';
2
-
3
- /**
4
- * Decompress a UI spec from storage.
5
- *
6
- * Automatically detects and handles both formats:
7
- * - Compressed format: "zlib:..." (base64-encoded zlib)
8
- * - Legacy format: Raw JSON string
9
- *
10
- * This provides backward compatibility with existing uncompressed specs.
11
- *
12
- * @param data - Compressed or legacy JSON string from storage
13
- * @returns Parsed Node object
14
- *
15
- * @example
16
- * // Compressed format
17
- * const spec = decompressSpec("zlib:eJzt3Vtv2...");
18
- *
19
- * // Legacy format (backward compatible)
20
- * const spec = decompressSpec('{"uid":"abc","type":"page",...}');
21
- */
22
- function decompressSpec(data) {
23
- // Detect compressed format
24
- if (data.startsWith("zlib:")) {
25
- const base64 = data.slice(5);
26
- // Decode base64 to Uint8Array
27
- const binaryString = atob(base64);
28
- const uint8Array = new Uint8Array(binaryString.length);
29
- for (let i = 0; i < binaryString.length; i++) {
30
- uint8Array[i] = binaryString.charCodeAt(i);
31
- }
32
- // Decompress
33
- const decompressed = unzlibSync(uint8Array);
34
- const decoder = new TextDecoder();
35
- const json = decoder.decode(decompressed);
36
- return JSON.parse(json);
37
- }
38
- // Legacy uncompressed format
39
- return JSON.parse(data);
40
- }
41
-
42
- export { decompressSpec };
43
- //# sourceMappingURL=spec-compression.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"spec-compression.js","sources":["../../../../../studio-internal/dist/utils/spec-compression.js"],"sourcesContent":["import { zlibSync, unzlibSync } from 'fflate';\n\n/**\n * Compress a UI spec using zlib compression for storage.\n *\n * The compressed output is base64-encoded and prefixed with \"zlib:\" for format detection.\n * This achieves 77-90% size reduction on typical UI specs.\n * Uses fflate library which works in both Node.js and browser environments.\n *\n * @param spec - The UI spec Node to compress\n * @returns Base64-encoded compressed string prefixed with \"zlib:\"\n *\n * @example\n * const compressed = compressSpec(editor.getUI());\n * // Returns: \"zlib:eJzt3Vtv2...\"\n */\nfunction compressSpec(spec) {\n const json = JSON.stringify(spec);\n const encoder = new TextEncoder();\n const uint8Array = encoder.encode(json);\n // Level 9 = max compression\n const compressed = zlibSync(uint8Array, { level: 9 });\n // Convert to base64\n const base64 = btoa(String.fromCharCode(...compressed));\n return \"zlib:\" + base64;\n}\n/**\n * Decompress a UI spec from storage.\n *\n * Automatically detects and handles both formats:\n * - Compressed format: \"zlib:...\" (base64-encoded zlib)\n * - Legacy format: Raw JSON string\n *\n * This provides backward compatibility with existing uncompressed specs.\n *\n * @param data - Compressed or legacy JSON string from storage\n * @returns Parsed Node object\n *\n * @example\n * // Compressed format\n * const spec = decompressSpec(\"zlib:eJzt3Vtv2...\");\n *\n * // Legacy format (backward compatible)\n * const spec = decompressSpec('{\"uid\":\"abc\",\"type\":\"page\",...}');\n */\nfunction decompressSpec(data) {\n // Detect compressed format\n if (data.startsWith(\"zlib:\")) {\n const base64 = data.slice(5);\n // Decode base64 to Uint8Array\n const binaryString = atob(base64);\n const uint8Array = new Uint8Array(binaryString.length);\n for (let i = 0; i < binaryString.length; i++) {\n uint8Array[i] = binaryString.charCodeAt(i);\n }\n // Decompress\n const decompressed = unzlibSync(uint8Array);\n const decoder = new TextDecoder();\n const json = decoder.decode(decompressed);\n return JSON.parse(json);\n }\n // Legacy uncompressed format\n return JSON.parse(data);\n}\n/**\n * Validate compression with round-trip test.\n * Use this during development to ensure data integrity.\n *\n * @param spec - The spec to validate\n * @returns Object with validation results\n *\n * @example\n * const result = validateCompression(editor.getUI());\n * console.log(`Compression: ${result.compressionRatio}%`);\n * console.log(`Integrity: ${result.isIdentical ? 'PASS' : 'FAIL'}`);\n */\nfunction validateCompression(spec) {\n const original = JSON.stringify(spec);\n const encoder = new TextEncoder();\n const originalSize = encoder.encode(original).length;\n // Compress\n const compressed = compressSpec(spec);\n const compressedSize = encoder.encode(compressed).length;\n // Decompress\n const restored = decompressSpec(compressed);\n const restoredStr = JSON.stringify(restored);\n // Verify integrity\n const isIdentical = original === restoredStr;\n const compressionRatio = parseFloat(((1 - compressedSize / originalSize) * 100).toFixed(2));\n return {\n originalSize,\n compressedSize,\n compressionRatio,\n isIdentical,\n };\n}\n\nexport { compressSpec, decompressSpec, validateCompression };\n//# sourceMappingURL=spec-compression.js.map\n"],"names":[],"mappings":";;AA0BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,cAAc,CAAC,IAAI,EAAE;AAC9B;AACA,IAAI,IAAI,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE;AAClC,QAAQ,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;AACpC;AACA,QAAQ,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC;AACzC,QAAQ,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,YAAY,CAAC,MAAM,CAAC;AAC9D,QAAQ,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,YAAY,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;AACtD,YAAY,UAAU,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC;AACtD,QAAQ;AACR;AACA,QAAQ,MAAM,YAAY,GAAG,UAAU,CAAC,UAAU,CAAC;AACnD,QAAQ,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE;AACzC,QAAQ,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC;AACjD,QAAQ,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;AAC/B,IAAI;AACJ;AACA,IAAI,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;AAC3B;;;;"}