@contentstack/studio-client 3.2.0 → 4.1.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 (97) hide show
  1. package/dist/breakpoints/BreakpointManager.js +7 -5
  2. package/dist/breakpoints/BreakpointManager.js.map +1 -1
  3. package/dist/breakpoints/breakpoint.js +3 -2
  4. package/dist/breakpoints/breakpoint.js.map +1 -1
  5. package/dist/canvas/canvas.utils.js +64 -9
  6. package/dist/canvas/canvas.utils.js.map +1 -1
  7. package/dist/composable-studio/build-scoped-data.js +12 -35
  8. package/dist/composable-studio/build-scoped-data.js.map +1 -1
  9. package/dist/composable-studio/sdk.js +1064 -430
  10. package/dist/composable-studio/sdk.js.map +1 -1
  11. package/dist/composable-studio/studio-intelligence.manager.js +5 -2
  12. package/dist/composable-studio/studio-intelligence.manager.js.map +1 -1
  13. package/dist/composable-studio/weak-maps.js +3 -1
  14. package/dist/composable-studio/weak-maps.js.map +1 -1
  15. package/dist/config/config.schema.js +45 -8
  16. package/dist/config/config.schema.js.map +1 -1
  17. package/dist/config/default-config.js +10 -3
  18. package/dist/config/default-config.js.map +1 -1
  19. package/dist/config/process-user-config.js +37 -1
  20. package/dist/config/process-user-config.js.map +1 -1
  21. package/dist/config/stack-sdk-wrapper.js +36 -1
  22. package/dist/config/stack-sdk-wrapper.js.map +1 -1
  23. package/dist/context-menu/context-menu.js +5 -2
  24. package/dist/context-menu/context-menu.js.map +1 -1
  25. package/dist/design/handle-active-style-change.js +3 -2
  26. package/dist/design/handle-active-style-change.js.map +1 -1
  27. package/dist/dnd/dnd-event.js +2 -1
  28. package/dist/dnd/dnd-event.js.map +1 -1
  29. package/dist/dnd/dnd-manager.js +31 -1
  30. package/dist/dnd/dnd-manager.js.map +1 -1
  31. package/dist/editor.d.ts +258 -0
  32. package/dist/editor.js +11 -0
  33. package/dist/editor.js.map +1 -0
  34. package/dist/get-active-node-screenshot/get-node-screenshot-event.js +2 -1
  35. package/dist/get-active-node-screenshot/get-node-screenshot-event.js.map +1 -1
  36. package/dist/hidden-element-notification/hidden-element-notification-event.js +2 -1
  37. package/dist/hidden-element-notification/hidden-element-notification-event.js.map +1 -1
  38. package/dist/highlight-node/highlight-node-manager.js +225 -15
  39. package/dist/highlight-node/highlight-node-manager.js.map +1 -1
  40. package/dist/highlight-node/highlight-node.js +52 -10
  41. package/dist/highlight-node/highlight-node.js.map +1 -1
  42. package/dist/highlight-spacing/highlight-spacing-events.js +2 -1
  43. package/dist/highlight-spacing/highlight-spacing-events.js.map +1 -1
  44. package/dist/index.d.ts +1024 -436
  45. package/dist/index.js +13 -14
  46. package/dist/index.js.map +1 -1
  47. package/dist/url-change/url-change.js +4 -3
  48. package/dist/url-change/url-change.js.map +1 -1
  49. package/dist/url-metadata/build-template-query.js +14 -3
  50. package/dist/url-metadata/build-template-query.js.map +1 -1
  51. package/dist/utils/canvas.js +2 -1
  52. package/dist/utils/canvas.js.map +1 -1
  53. package/dist/utils/check-bindings.js +233 -0
  54. package/dist/utils/check-bindings.js.map +1 -0
  55. package/dist/utils/classify-response-error.js +288 -0
  56. package/dist/utils/classify-response-error.js.map +1 -0
  57. package/dist/utils/composable-studio-error.js +36 -20
  58. package/dist/utils/composable-studio-error.js.map +1 -1
  59. package/dist/utils/composition-not-found.js +52 -0
  60. package/dist/utils/composition-not-found.js.map +1 -0
  61. package/dist/utils/constants.js +25 -2
  62. package/dist/utils/constants.js.map +1 -1
  63. package/dist/utils/degraded-finding.js +166 -0
  64. package/dist/utils/degraded-finding.js.map +1 -0
  65. package/dist/utils/editor-mode.js +1 -1
  66. package/dist/utils/http-error.constants.js +12 -46
  67. package/dist/utils/http-error.constants.js.map +1 -1
  68. package/dist/utils/include-path-rules.js +40 -1
  69. package/dist/utils/include-path-rules.js.map +1 -1
  70. package/dist/utils/is-composition-being-edited.js +1 -1
  71. package/dist/utils/is-inside-iframe.js +1 -1
  72. package/dist/utils/is-inside-visual-builder-frame.js +1 -1
  73. package/dist/utils/parse-ui.js +60 -0
  74. package/dist/utils/parse-ui.js.map +1 -0
  75. package/dist/utils/query-param.js +1 -1
  76. package/dist/utils/query-param.js.map +1 -1
  77. package/dist/utils/reference-stub.js +75 -0
  78. package/dist/utils/reference-stub.js.map +1 -0
  79. package/dist/utils/reference_fetcher.js +44 -3
  80. package/dist/utils/reference_fetcher.js.map +1 -1
  81. package/dist/utils/require-stack.js +141 -0
  82. package/dist/utils/require-stack.js.map +1 -0
  83. package/dist/utils/served-by.js +33 -0
  84. package/dist/utils/served-by.js.map +1 -0
  85. package/dist/utils/studio-error-codes.js +253 -0
  86. package/dist/utils/studio-error-codes.js.map +1 -0
  87. package/dist/utils/studio-error.js +122 -0
  88. package/dist/utils/studio-error.js.map +1 -0
  89. package/dist/utils/studio-messaging.js +25 -0
  90. package/dist/utils/studio-messaging.js.map +1 -0
  91. package/dist/visual-builder/composition-save-event.js +2 -1
  92. package/dist/visual-builder/composition-save-event.js.map +1 -1
  93. package/package.json +19 -6
  94. package/dist/utils/error-messages.default.js +0 -141
  95. package/dist/utils/error-messages.default.js.map +0 -1
  96. package/dist/utils/error-messages.js +0 -47
  97. package/dist/utils/error-messages.js.map +0 -1
@@ -0,0 +1,33 @@
1
+ /**
2
+ * The sentinel the delivery client sends when live preview is enabled and no
3
+ * hash has arrived. It is a value on the query, not a hash, and the transport
4
+ * excludes it from the host swap — so a request carrying it is an ordinary
5
+ * published-content request.
6
+ */
7
+ const LIVE_PREVIEW_INIT = "init";
8
+ /**
9
+ * Which service a request made with this configuration will reach.
10
+ *
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
+ *
16
+ * It must be read synchronously, immediately before the request. Live-preview
17
+ * state is process-wide, so under concurrent server rendering a value read after
18
+ * an await can belong to a different request.
19
+ */
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
+ if (!livePreview?.enable)
27
+ return "cdn";
28
+ const hash = livePreview.live_preview;
29
+ return hash && hash !== LIVE_PREVIEW_INIT ? "preview" : "cdn";
30
+ }
31
+
32
+ export { resolveServedBy };
33
+ //# sourceMappingURL=served-by.js.map
@@ -0,0 +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;;;;"}
@@ -0,0 +1,253 @@
1
+ /**
2
+ * The documented error codes, and the class each one belongs to.
3
+ *
4
+ * A code names one diagnosable case and is the only identifier on an error. It
5
+ * is printed in the log line, quoted in support conversations and sent to
6
+ * Studio, so it is stable across releases once published.
7
+ *
8
+ * The class is looked up from {@link ERROR_CLASS} rather than carried on the
9
+ * error, because a second identifier that nothing branches on is a second thing
10
+ * to keep in step.
11
+ *
12
+ * Codes land here as the cases behind them are built, not up front — a code
13
+ * with no throw site is a promise, not a contract.
14
+ */
15
+ const StudioErrorCode = {
16
+ /** The stack has no content type with the uid Studio queried. */
17
+ CONTENT_TYPE_NOT_FOUND: "CONTENT_TYPE_NOT_FOUND",
18
+ /** No stack on this host answers to the API key the request carried. */
19
+ STACK_NOT_FOUND_ON_HOST: "STACK_NOT_FOUND_ON_HOST",
20
+ /** The stack has no environment by the name the connection uses. */
21
+ ENVIRONMENT_NOT_FOUND: "ENVIRONMENT_NOT_FOUND",
22
+ /** The stack has no language by the code the SDK was configured with. */
23
+ LOCALE_NOT_CONFIGURED: "LOCALE_NOT_CONFIGURED",
24
+ /** The address asked for a language the stack does not have. */
25
+ URL_LOCALE_NOT_FOUND: "URL_LOCALE_NOT_FOUND",
26
+ /**
27
+ * Studio was given no Contentstack stack to query, or given something that is
28
+ * not one. Raised by the first call that needs the stack, never at setup: a
29
+ * site that wires Studio into a layout and renders no composition on this
30
+ * route is legitimate.
31
+ */
32
+ STACK_SDK_MISSING: "STACK_SDK_MISSING",
33
+ /**
34
+ * A stack arrived, and the api key inside it is empty.
35
+ *
36
+ * Only reachable on a JavaScript-SDK stack — the TypeScript delivery factory
37
+ * refuses to construct one without an api key, in the caller's own code. Its
38
+ * response-driven sibling is `STACK_NOT_FOUND_ON_HOST`, which is what an empty
39
+ * key used to be reported as once the request came back 412.
40
+ */
41
+ API_KEY_MISSING: "API_KEY_MISSING",
42
+ /**
43
+ * A stack arrived, and the delivery token inside it is empty.
44
+ *
45
+ * JavaScript-SDK stacks only, as above. No response can report this one: the
46
+ * delivery client's retry policy consumes the 401 into an unknown error before
47
+ * anything here sees it, so the preflight is the only place it can be found.
48
+ */
49
+ DELIVERY_TOKEN_MISSING: "DELIVERY_TOKEN_MISSING",
50
+ /**
51
+ * A stack arrived, and the environment inside it is empty.
52
+ *
53
+ * JavaScript-SDK stacks only, as above. The value reads as optional and is
54
+ * not — Studio queries published content per environment — which is why the
55
+ * message says so rather than only naming the gap.
56
+ */
57
+ ENVIRONMENT_MISSING: "ENVIRONMENT_MISSING",
58
+ /**
59
+ * 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.
62
+ *
63
+ * States only that the value cannot work, never what it should have been. We
64
+ * have no way to know the right host, and any test for a Contentstack-shaped
65
+ * hostname breaks on dev and staging stacks and on customers' own CDNs.
66
+ */
67
+ HOST_UNUSABLE: "HOST_UNUSABLE",
68
+ /**
69
+ * The call carried none of `compositionUid`, `url` or `templateContentTypeUid`,
70
+ * so there was nothing to look for.
71
+ *
72
+ * Never a not-found: the composition may well exist, the request just never
73
+ * asked for one. The fault is in the call rather than the configuration, which
74
+ * `findings.lookedIn` says so a developer does not audit a correct config file.
75
+ */
76
+ COMPOSITION_IDENTIFIER_MISSING: "COMPOSITION_IDENTIFIER_MISSING",
77
+ /**
78
+ * A composition was requested before `init()` finished, and it had still not
79
+ * finished when the wait ran out.
80
+ *
81
+ * The wait is long on purpose (~30s). A shorter one fires on inits that were
82
+ * going to succeed — a cold serverless start, a slow server render — and
83
+ * reporting a working site as broken is worse than reporting a broken one late.
84
+ */
85
+ INIT_NOT_COMPLETE: "INIT_NOT_COMPLETE",
86
+ /**
87
+ * The candidate scan hit its safety cap without finding a match, so we stopped
88
+ * looking rather than established that nothing matched.
89
+ *
90
+ * Never a not-found, and the distinction is the whole point: a 404 is acted on
91
+ * by crawlers, caches and link checkers, and a project that has simply grown
92
+ * past the cap would start de-indexing pages that exist. Nothing in the
93
+ * customer's project causes this and nothing there can fix it.
94
+ */
95
+ SEARCH_INCOMPLETE: "SEARCH_INCOMPLETE",
96
+ /**
97
+ * Every ownership check on a tied address failed, so no candidate could be
98
+ * shown to own it — and none could be shown not to either.
99
+ *
100
+ * A single failed probe is survivable: another candidate may still answer. All
101
+ * of them failing is a delivery outage, and calling that "nothing owns this
102
+ * address" 404s a page that exists and is published.
103
+ */
104
+ URL_OWNERSHIP_PROBE_FAILED: "URL_OWNERSHIP_PROBE_FAILED",
105
+ /**
106
+ * Something answered, and what came back is not a delivery response — a
107
+ * proxy's error page, a gateway's JSON, a body truncated in transit.
108
+ *
109
+ * Never a not-found, and the damage of getting it wrong is the widest of any
110
+ * case here: the entries list is simply absent, which reads as "no
111
+ * compositions", which would 404 every page on the site at once for as long as
112
+ * whatever is in the way keeps answering.
113
+ */
114
+ RESPONSE_UNUSABLE: "RESPONSE_UNUSABLE",
115
+ /**
116
+ * A composition or section was found, and its stored layout will not open.
117
+ *
118
+ * Not a missing page: the composition is there and is damaged. And never
119
+ * version skew — a spec written by a newer Studio inflates and parses fine and
120
+ * fails later as an unknown component type, so offering that here sends the
121
+ * reader to upgrade something that was never in the way.
122
+ */
123
+ SPEC_UNREADABLE: "SPEC_UNREADABLE",
124
+ /**
125
+ * A complete scan over a usable response found no composition set up for the
126
+ * address. The page is genuinely not there.
127
+ */
128
+ NO_COMPOSITION_FOR_URL: "NO_COMPOSITION_FOR_URL",
129
+ /**
130
+ * Compositions are set up for the address, every one of them was asked for an
131
+ * entry, and none has one.
132
+ *
133
+ * Distinct from nothing being set up, because the fixes are opposite: this
134
+ * reader's routing is right and their content is missing, so sending them to
135
+ * check the URL sends them to audit something already correct.
136
+ */
137
+ URL_MATCHED_NO_ENTRY: "URL_MATCHED_NO_ENTRY",
138
+ /**
139
+ * A composition uid was asked for, the query answered, and nothing in the
140
+ * project has it.
141
+ *
142
+ * The wording stops at that. Whether the composition exists at all is not
143
+ * knowable from one query — it may be published to another environment,
144
+ * mistyped, or on a different stack — and the sentence this replaces asserted
145
+ * "does not exist or has been deleted" in every one of those cases.
146
+ */
147
+ COMPOSITION_UID_NOT_FOUND: "COMPOSITION_UID_NOT_FOUND",
148
+ /**
149
+ * A composition names a connected content type, the entry for it was asked
150
+ * for, and there is none.
151
+ *
152
+ * Renamed from an id that said "preview", which it never had anything to do
153
+ * with — it fires identically on published content, and the name sent people
154
+ * to check a preview setup that was not involved.
155
+ */
156
+ CONNECTED_ENTRY_NOT_FOUND: "CONNECTED_ENTRY_NOT_FOUND",
157
+ /**
158
+ * A component the stored layout uses was never registered, so there is
159
+ * nothing to render it with.
160
+ *
161
+ * Setup rather than content: the composition is fine and the application did
162
+ * not tell the SDK about a component it refers to. Built-in components
163
+ * register on first import of the React package, so the usual cause is that
164
+ * the package root was never imported.
165
+ */
166
+ COMPONENT_NOT_REGISTERED: "COMPONENT_NOT_REGISTERED",
167
+ /**
168
+ * The request went out and nothing came back — no response, no status.
169
+ *
170
+ * Never a not-found: a page that cannot be reached is not a page that does
171
+ * not exist, and 404ing it would have crawlers and caches de-index a working
172
+ * site over a bad minute.
173
+ */
174
+ TRANSPORT_FAILED: "TRANSPORT_FAILED",
175
+ /**
176
+ * Something answered, and the answer was not one we can act on — a 5xx, or a
177
+ * status this SDK has no reading for.
178
+ *
179
+ * The terminal case, and the one that matters most: every response no other
180
+ * check recognises ends up here. It used to end up at "composition not
181
+ * found", which is how a wrong api key, a wrong environment and a delivery
182
+ * outage all came to tell a developer their page did not exist.
183
+ */
184
+ UPSTREAM_ERROR: "UPSTREAM_ERROR",
185
+ /** A content type was asked for, and no composition in the project is connected to it. */
186
+ NO_COMPOSITION_FOR_TEMPLATE_CONTENT_TYPE: "NO_COMPOSITION_FOR_TEMPLATE_CONTENT_TYPE",
187
+ };
188
+ /**
189
+ * The five classes, each named for an observable fact about the attempt rather
190
+ * than for a situation. A host reads the class to decide an HTTP status: only
191
+ * `NOT_FOUND` is a 404, everything else is a 5xx.
192
+ */
193
+ const StudioErrorClass = {
194
+ /** Something the SDK needed was not available when it was needed. */
195
+ SETUP_INCOMPLETE: "SETUP_INCOMPLETE",
196
+ /** Something supplied is wrong. */
197
+ SETUP_INVALID: "SETUP_INVALID",
198
+ /** Sent, no response. */
199
+ NETWORK_ERROR: "NETWORK_ERROR",
200
+ /** We could not establish an answer. */
201
+ SERVER_ERROR: "SERVER_ERROR",
202
+ /** We established that nothing matched. */
203
+ NOT_FOUND: "NOT_FOUND",
204
+ };
205
+ const ERROR_CLASS = {
206
+ [StudioErrorCode.CONTENT_TYPE_NOT_FOUND]: StudioErrorClass.SETUP_INVALID,
207
+ [StudioErrorCode.STACK_NOT_FOUND_ON_HOST]: StudioErrorClass.SETUP_INVALID,
208
+ [StudioErrorCode.ENVIRONMENT_NOT_FOUND]: StudioErrorClass.SETUP_INVALID,
209
+ [StudioErrorCode.LOCALE_NOT_CONFIGURED]: StudioErrorClass.SETUP_INVALID,
210
+ // The address is visitor input, so a language it names and the stack lacks
211
+ // means "no such page", not a broken setup.
212
+ [StudioErrorCode.URL_LOCALE_NOT_FOUND]: StudioErrorClass.NOT_FOUND,
213
+ [StudioErrorCode.STACK_SDK_MISSING]: StudioErrorClass.SETUP_INCOMPLETE,
214
+ [StudioErrorCode.API_KEY_MISSING]: StudioErrorClass.SETUP_INCOMPLETE,
215
+ [StudioErrorCode.DELIVERY_TOKEN_MISSING]: StudioErrorClass.SETUP_INCOMPLETE,
216
+ [StudioErrorCode.ENVIRONMENT_MISSING]: StudioErrorClass.SETUP_INCOMPLETE,
217
+ // Supplied and wrong, rather than absent: we proved this value cannot work.
218
+ [StudioErrorCode.HOST_UNUSABLE]: StudioErrorClass.SETUP_INVALID,
219
+ // Never a not-found: the page may exist, the call just never asked for one.
220
+ [StudioErrorCode.COMPOSITION_IDENTIFIER_MISSING]: StudioErrorClass.SETUP_INCOMPLETE,
221
+ [StudioErrorCode.INIT_NOT_COMPLETE]: StudioErrorClass.SETUP_INCOMPLETE,
222
+ // We could not establish an answer, which is exactly what SERVER_ERROR means —
223
+ // and what keeps it out of the 404 a host would otherwise return.
224
+ [StudioErrorCode.SEARCH_INCOMPLETE]: StudioErrorClass.SERVER_ERROR,
225
+ // Nothing was established, which is a server error rather than an answer.
226
+ [StudioErrorCode.URL_OWNERSHIP_PROBE_FAILED]: StudioErrorClass.SERVER_ERROR,
227
+ // Sent and answered, but nothing was established — a server error, never a 404.
228
+ [StudioErrorCode.RESPONSE_UNUSABLE]: StudioErrorClass.SERVER_ERROR,
229
+ [StudioErrorCode.SPEC_UNREADABLE]: StudioErrorClass.SERVER_ERROR,
230
+ // The ones that genuinely are "there is no such page". Everything above had to
231
+ // be kept out of this class for a host's 404 to mean anything. Uncounted on
232
+ // purpose: a number here goes stale the next time a code lands.
233
+ [StudioErrorCode.NO_COMPOSITION_FOR_URL]: StudioErrorClass.NOT_FOUND,
234
+ // Still a not-found: for a visitor the page really is not there.
235
+ [StudioErrorCode.URL_MATCHED_NO_ENTRY]: StudioErrorClass.NOT_FOUND,
236
+ [StudioErrorCode.COMPOSITION_UID_NOT_FOUND]: StudioErrorClass.NOT_FOUND,
237
+ // The composition resolved and its entry did not. For a visitor the page
238
+ // really is not there.
239
+ [StudioErrorCode.CONNECTED_ENTRY_NOT_FOUND]: StudioErrorClass.NOT_FOUND,
240
+ // Something the SDK needed was not available when it was needed — here, a
241
+ // component the application never registered.
242
+ [StudioErrorCode.COMPONENT_NOT_REGISTERED]: StudioErrorClass.SETUP_INCOMPLETE,
243
+ // Sent and unanswered. Never a 404: the page may be perfectly fine and
244
+ // unreachable for a minute.
245
+ [StudioErrorCode.TRANSPORT_FAILED]: StudioErrorClass.NETWORK_ERROR,
246
+ // The fall-through, and deliberately a server error. Anything landing here is
247
+ // a response we could not read, which is not evidence that a page is absent.
248
+ [StudioErrorCode.UPSTREAM_ERROR]: StudioErrorClass.SERVER_ERROR,
249
+ [StudioErrorCode.NO_COMPOSITION_FOR_TEMPLATE_CONTENT_TYPE]: StudioErrorClass.NOT_FOUND,
250
+ };
251
+
252
+ export { ERROR_CLASS, StudioErrorClass, StudioErrorCode };
253
+ //# sourceMappingURL=studio-error-codes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"studio-error-codes.js","sources":["../../src/utils/studio-error-codes.ts"],"sourcesContent":[null],"names":[],"mappings":"AAAA;;;;;;;;;;;;;AAaG;AAEI,MAAM,eAAe,GAAG;;AAE7B,IAAA,sBAAsB,EAAE,wBAAwB;;AAEhD,IAAA,uBAAuB,EAAE,yBAAyB;;AAElD,IAAA,qBAAqB,EAAE,uBAAuB;;AAE9C,IAAA,qBAAqB,EAAE,uBAAuB;;AAE9C,IAAA,oBAAoB,EAAE,sBAAsB;AAC5C;;;;;AAKG;AACH,IAAA,iBAAiB,EAAE,mBAAmB;AACtC;;;;;;;AAOG;AACH,IAAA,eAAe,EAAE,iBAAiB;AAClC;;;;;;AAMG;AACH,IAAA,sBAAsB,EAAE,wBAAwB;AAChD;;;;;;AAMG;AACH,IAAA,mBAAmB,EAAE,qBAAqB;AAC1C;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gB,CAAC,aAAa;;;AAGlE,IAAA,CAAC,eAAe,CAAC,cAAc,GAAG,gBAAgB,CAAC,YAAY;AAC/D,IAAA,CAAC,eAAe,CAAC,wCAAwC,GACvD,gBAAgB,CAAC,SAAS;;;;;"}
@@ -0,0 +1,122 @@
1
+ import { ComposableStudioError } from './composable-studio-error.js';
2
+ import { codeIsNotFound, CompositionNotFoundError } from './composition-not-found.js';
3
+ import { SDK_VERSION } from './constants.js';
4
+ import { detectStudioMode } from './editor-mode.js';
5
+ import { StudioErrorClass } from './studio-error-codes.js';
6
+ export { ERROR_CLASS } from './studio-error-codes.js';
7
+
8
+ /**
9
+ * The shape every diagnosable failure is raised in, and the one place it is
10
+ * rendered and logged.
11
+ *
12
+ * Each field answers one question and no field answers two: which case this is
13
+ * (`code`), what happened (`message`), what to do (`causes`), where the request
14
+ * went (`context`), and what this particular failure established (`details`).
15
+ */
16
+ /** Reads the facts a diagnosis prints from the config the fetch actually used. */
17
+ function buildStudioErrorContext(config, servedBy = "unknown") {
18
+ const stack = config?.stackSdk;
19
+ return {
20
+ mode: detectStudioMode(),
21
+ apiKey: stack?.apiKey,
22
+ environment: stack?.environment,
23
+ locale: config?.locale,
24
+ host: stack?.host,
25
+ // With a stack, an absent live-preview config really does mean not enabled.
26
+ // With no stack there is nothing to read, and answering at all would invent
27
+ // a fact about the site's setup.
28
+ livePreviewEnabled: stack
29
+ ? stack.livePreviewConfig?.enable === true
30
+ : undefined,
31
+ servedBy,
32
+ sdkVersion: SDK_VERSION,
33
+ };
34
+ }
35
+ /**
36
+ * The rendered message carries the code, the headline and every cause. It has
37
+ * to, because `console.error(err)`, a framework error overlay and a Sentry
38
+ * title all show the message and nothing else — today the troubleshooting
39
+ * information sits on the error object and is never read.
40
+ *
41
+ * The context deliberately stays out of it. A console prints a message verbatim
42
+ * and every line of it costs the reader attention, so nine fields of request
43
+ * detail flattened into prose buries the two sentences that matter. It is
44
+ * logged as an object instead: one collapsed row the reader opens when they
45
+ * want it, and one that copies as structured data rather than as text somebody
46
+ * has to parse back.
47
+ *
48
+ * The causes are optional here and not on an error, and the difference is the
49
+ * point: an error always has an action, so `Causes` forbids an empty list at
50
+ * the throw site. A finding that did not stop the page sometimes has none —
51
+ * a query that matched nothing has no fix — and printing an empty heading over
52
+ * it would invent a problem.
53
+ */
54
+ function renderStudioErrorMessage(input) {
55
+ const headline = `[Contentstack Studio] ${input.code}: ${input.headline}`;
56
+ if (!input.causes?.length)
57
+ return headline;
58
+ const causes = input.causes
59
+ .map(({ cause, fix }, index) => ` ${index + 1}. ${cause} ${fix}`)
60
+ .join("\n");
61
+ return [headline, "", "What to do, most likely first:", causes].join("\n");
62
+ }
63
+ /**
64
+ * Builds the error and returns it to be thrown.
65
+ *
66
+ * **It does not log.** Whether a diagnosis reaches a console, a reporting
67
+ * service or neither is the application's decision, not ours — it is the only
68
+ * party that knows its environment, its log budget and its privacy rules. An
69
+ * SDK that writes to the console on the app's behalf takes that decision away
70
+ * and duplicates whatever the app already does with the rejection.
71
+ *
72
+ * What we owe the app in exchange is an error worth logging: the message
73
+ * carries the code and every cause, so a plain `console.error(err)` shows the
74
+ * whole diagnosis, and the structured `code`, `causes` and `context` are there
75
+ * for anything that wants to report rather than print.
76
+ */
77
+ function createStudioError(input) {
78
+ const message = renderStudioErrorMessage(input);
79
+ // The findings are spread into the legacy metadata bag as well as being set as
80
+ // their own field. Existing consumers read them from there, and retiring that
81
+ // bag belongs to the ticket that retires the legacy ids.
82
+ // The subclass is chosen from the code rather than passed in, so a host
83
+ // catching by type and a host using the predicate can never disagree about the
84
+ // same error.
85
+ const ErrorClass = codeIsNotFound(input.code)
86
+ ? CompositionNotFoundError
87
+ : ComposableStudioError;
88
+ const error = new ErrorClass(message, {
89
+ ...input.findings,
90
+ troubleshootingInfo: [...input.causes],
91
+ });
92
+ error.code = input.code;
93
+ error.causes = input.causes;
94
+ error.context = input.context;
95
+ error.findings = input.findings;
96
+ // Drop this factory from the stack, so the top frame is the code that
97
+ // actually failed and the caller's own frames sit directly under it. Without
98
+ // it every diagnosis in the product looks like it originated here, which
99
+ // reads as noise to a developer and groups as one fault in error reporting.
100
+ // V8 only; other engines keep the extra frame, which is noisier, not wrong.
101
+ const { captureStackTrace } = Error;
102
+ captureStackTrace?.(error, createStudioError);
103
+ return error;
104
+ }
105
+ /**
106
+ * Whether a failure is a property of the setup rather than of one attempt.
107
+ *
108
+ * Fallbacks exist to survive a request that did not work out: another candidate
109
+ * may own the url, a scan may find what a fast path missed. None of that applies
110
+ * here. The same configuration produces the same answer on every path and every
111
+ * retry, so falling back spends work to reach an identical failure — and reports
112
+ * the one diagnosis worth reading as a transient hiccup on the way.
113
+ */
114
+ function isSetupFault(error) {
115
+ if (!(error instanceof ComposableStudioError))
116
+ return false;
117
+ return (error.errorClass === StudioErrorClass.SETUP_INCOMPLETE ||
118
+ error.errorClass === StudioErrorClass.SETUP_INVALID);
119
+ }
120
+
121
+ export { buildStudioErrorContext, createStudioError, isSetupFault, renderStudioErrorMessage };
122
+ //# sourceMappingURL=studio-error.js.map
@@ -0,0 +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,IAAI,EAAE,gBAAgB,EAAE;QACxB,MAAM,EAAE,KAAK,EAAE,MAAM;QACrB,WAAW,EAAE,KAAK,EAAE,WAAW;QAC/B,MAAM,EAAE,MAAM,EAAE,MAAM;QACtB,IAAI,EAAE,KAAK,EAAE,IAAI;;;;AAIjB,QAAA,kBAAkB,EAAE;AAClB,cAAE,KAAK,CAAC,iBAAiB,EAAE,MAAM,KAAK;AACtC,cAAE,SAAS;QACb,QAAQ;AACR,QAAA,UAAU,EAAE,WAAW;KACxB;AACH;AAEA;;;;;;;;;;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iBAAiB,EAAE,GAAG,KAE7B;AACD,IAAA,iBAAiB,GAAG,KAAK,EAAE,iBAAiB,CAAC;AAE7C,IAAA,OAAO,KAAK;AACd;AAEA;;;;;;;;AAQG;AACG,SAAU,YAAY,CAAC,KAAc,EAAA;AACzC,IAAA,IAAI,EAAE,KAAK,YAAY,qBAAqB,CAAC;AAAE,QAAA,OAAO,KAAK;AAC3D,IAAA,QACE,KAAK,CAAC,UAAU,KAAK,gBAAgB,CAAC,gBAAgB;AACtD,QAAA,KAAK,CAAC,UAAU,KAAK,gBAAgB,CAAC,aAAa;AAEvD;;;;"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Fire-and-forget send to the Studio parent frame.
3
+ *
4
+ * The postMessage bridge (`@contentstack/studio-messenger` →
5
+ * `@contentstack/advanced-post-message`) is imported on demand rather than at
6
+ * module scope. Importing it statically put the whole bridge into every bundle
7
+ * that reached one of these modules — including a published site, where the
8
+ * event manager is `undefined` outside the Studio iframe and every one of these
9
+ * calls is already a no-op.
10
+ *
11
+ * Callers are all fire-and-forget today, so resolving the bridge a microtask
12
+ * later is not observable. Anything that needs to *receive* events keeps a
13
+ * static import: listener registration cannot be deferred safely.
14
+ */
15
+ function sendStudioEvent(event, payload) {
16
+ return import('@contentstack/studio-messenger')
17
+ .then(({ composableStudioEventManager }) => composableStudioEventManager?.send(event, payload))
18
+ .catch((error) => {
19
+ console.warn("[studio] could not send", event, error);
20
+ return undefined;
21
+ });
22
+ }
23
+
24
+ export { sendStudioEvent };
25
+ //# sourceMappingURL=studio-messaging.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"studio-messaging.js","sources":["../../src/utils/studio-messaging.ts"],"sourcesContent":[null],"names":[],"mappings":"AAKA;;;;;;;;;;;;;AAaG;AACG,SAAU,eAAe,CAC7B,KAAkB,EAClB,OAAiB,EAAA;IAEjB,OAAO,OAAO,gCAAgC;AAC3C,SAAA,IAAI,CAAC,CAAC,EAAE,4BAA4B,EAAE,KACrC,4BAA4B,EAAE,IAAI,CAChC,KAAc,EACd,OAAgB,CACjB;AAEF,SAAA,KAAK,CAAC,CAAC,KAAK,KAAI;QACf,OAAO,CAAC,IAAI,CAAC,yBAAyB,EAAE,KAAK,EAAE,KAAK,CAAC;AACrD,QAAA,OAAO,SAAS;AAClB,IAAA,CAAC,CAAC;AACN;;;;"}
@@ -1,4 +1,5 @@
1
- import { visualBuilderEventManager, VISUAL_BUILDER_POST_MESSAGE_EVENTS } from '@contentstack/studio-messenger';
1
+ import { VISUAL_BUILDER_POST_MESSAGE_EVENTS } from '@contentstack/studio-messenger/constants';
2
+ import { visualBuilderEventManager } from '@contentstack/studio-messenger';
2
3
  import { composableStudioEventEmitter } from '../emitted-events/event-emitter.js';
3
4
 
4
5
  const compositionSaveEventListener = () => {
@@ -1 +1 @@
1
- {"version":3,"file":"composition-save-event.js","sources":["../../src/visual-builder/composition-save-event.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAOO,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":";;;;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;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentstack/studio-client",
3
- "version": "3.2.0",
3
+ "version": "4.1.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.4",
33
+ "@contentstack/common-config": "^1.2.6",
34
34
  "@contentstack/delivery-sdk": "^4.5.0",
35
- "@contentstack/studio-internal": "^1.7.0",
35
+ "@contentstack/studio-internal": "^1.8.1",
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,13 +48,26 @@
48
48
  "typescript": "^5.5.4"
49
49
  },
50
50
  "dependencies": {
51
- "@contentstack/studio-message-types": "^1.5.2",
52
- "@contentstack/studio-messenger": "^3.1.1",
53
- "@contentstack/studio-registry": "^1.10.0",
51
+ "@contentstack/studio-message-types": "^2.1.0",
52
+ "@contentstack/studio-messenger": "^3.2.1",
53
+ "@contentstack/studio-registry": "^2.0.1",
54
54
  "eventemitter3": "^5.0.1",
55
55
  "fflate": "^0.8.2",
56
56
  "lodash-es": "^4.18.1",
57
57
  "modern-screenshot": "^4.7.0",
58
58
  "zod": "^3.23.8"
59
+ },
60
+ "exports": {
61
+ ".": {
62
+ "types": "./dist/index.d.ts",
63
+ "import": "./dist/index.js",
64
+ "default": "./dist/index.js"
65
+ },
66
+ "./editor": {
67
+ "types": "./dist/editor.d.ts",
68
+ "import": "./dist/editor.js",
69
+ "default": "./dist/editor.js"
70
+ },
71
+ "./*": "./*"
59
72
  }
60
73
  }