webcake-storefront-mcp 1.38.0 → 1.40.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/dist/api.js +233 -145
- package/dist/auth/login.js +22 -1
- package/dist/auth/oauth-server.js +19 -2
- package/dist/builder/attributes.js +1 -1
- package/dist/builder/guide.js +11 -5
- package/dist/builder/native-first.js +4 -5
- package/dist/builder/page.js +247 -13
- package/dist/builder/shape.js +174 -0
- package/dist/changelog.json +14 -14
- package/dist/config.js +13 -3
- package/dist/http.js +38 -17
- package/dist/index.js +2 -0
- package/dist/persistence/screenshot-client.js +208 -0
- package/dist/tools/builder-extras.js +172 -4
- package/dist/tools/builder.js +30 -23
- package/dist/tools/global-section-write.js +1 -1
- package/dist/tools/global-sources.js +25 -75
- package/dist/tools/page-draft.js +3 -2
- package/dist/tools/pages.js +32 -70
- package/dist/web-guide-scene.js +10 -4
- package/package.json +1 -1
|
@@ -31,8 +31,6 @@ export const CODE_BUDGET = {
|
|
|
31
31
|
};
|
|
32
32
|
/** custom_css + embed code across one page or global source. */
|
|
33
33
|
export const NODE_CODE_BUDGET = { soft: 10_000, hard: 30_000 };
|
|
34
|
-
/** Growth still allowed on a site already past the ceiling, so it can ship fixes while it migrates. */
|
|
35
|
-
const SMALL_FIX = 2_000;
|
|
36
34
|
export const NATIVE_FIRST_GUIDE = `## NATIVE FIRST — elements on the canvas before any code
|
|
37
35
|
Pages are edited by dragging elements on the canvas. UI written in code is not on that canvas: the
|
|
38
36
|
shop owner can't edit it, it is missing from the page HTML until scripts run, and it loads on every
|
|
@@ -68,7 +66,7 @@ ${NATIVE_ALTERNATIVES.map((a) => `- ${a.need}: ${a.elements.join(", ")}${a.note
|
|
|
68
66
|
|
|
69
67
|
Limits: site scripts ${CODE_BUDGET.script.soft / 1000}k chars, site CSS ${CODE_BUDGET.css.soft / 1000}k chars. Above that, a write is refused unless
|
|
70
68
|
it names the gap in native_gap (scripts ${CODE_BUDGET.script.hard / 1000}k / CSS ${CODE_BUDGET.css.hard / 1000}k is refused outright; a site already past that may only
|
|
71
|
-
|
|
69
|
+
shrink or swap code: no write may grow it, publish_site refuses to publish it). validate_page also refuses new placeholder JSON in text and more than
|
|
72
70
|
${NODE_CODE_BUDGET.hard / 1000}k chars of custom_css + embed code on one page. Content already on a page never blocks an unrelated save.`;
|
|
73
71
|
const SMELLS = [
|
|
74
72
|
{
|
|
@@ -122,7 +120,8 @@ export function codeUsage(values) {
|
|
|
122
120
|
};
|
|
123
121
|
}
|
|
124
122
|
/** Judge a write by what it ADDS: shrinking or swapping code on an already-large site always passes,
|
|
125
|
-
* so a site can move off custom code step by step
|
|
123
|
+
* so a site can move off custom code step by step. Past the ceiling nothing may grow: small fixes
|
|
124
|
+
* used to be allowed and ratcheted a site to 90k chars of CSS, which then failed to publish. */
|
|
126
125
|
export function checkSiteCode(before, changes) {
|
|
127
126
|
const after = { ...before, ...changes };
|
|
128
127
|
const hard = [];
|
|
@@ -136,7 +135,7 @@ export function checkSiteCode(before, changes) {
|
|
|
136
135
|
if (now.length <= old.length)
|
|
137
136
|
continue;
|
|
138
137
|
const { soft: softLimit, hard: hardLimit } = CODE_BUDGET[kind];
|
|
139
|
-
if (now.length > hardLimit
|
|
138
|
+
if (now.length > hardLimit)
|
|
140
139
|
hard.push(`Site ${kind} would reach ${now.length} chars (ceiling ${hardLimit}). That is an app, not a snippet: move UI to native elements, data to a collection, logic to an HTTP function.`);
|
|
141
140
|
else if (now.length > softLimit)
|
|
142
141
|
soft.push(`Site ${kind} would reach ${now.length} chars (budget ${softLimit}).`);
|
package/dist/builder/page.js
CHANGED
|
@@ -6,10 +6,11 @@
|
|
|
6
6
|
// produce that structure the same way the builder does, so generated pages render.
|
|
7
7
|
import { buildElement, isKnownType, ELEMENT_TYPES } from "./catalog.js";
|
|
8
8
|
import { randomString } from "./factory.js";
|
|
9
|
-
import { validateEvents } from "./events.js";
|
|
10
|
-
import { validateBindings } from "./bindings.js";
|
|
9
|
+
import { validateEvents, normalizeEvents } from "./events.js";
|
|
10
|
+
import { validateBindings, normalizeBindings } from "./bindings.js";
|
|
11
11
|
import { NODE_CODE_BUDGET } from "./native-first.js";
|
|
12
|
-
import {
|
|
12
|
+
import { checkShape } from "./shape.js";
|
|
13
|
+
import { BREAKPOINTS, BREAKPOINT_KEYS, STYLE_ASYNC, CONFIG_ASYNC, genGridByBp, SECTION_CONTENT_COL_START, SECTION_CONTENT_COL_END, } from "./grid.js";
|
|
13
14
|
const clone = (o) => structuredClone(o);
|
|
14
15
|
/** Parse a CSS px length ("52px") or a bare number (52) → number, else null. */
|
|
15
16
|
function pxToNum(v) {
|
|
@@ -55,7 +56,8 @@ export function walk(source, fn) {
|
|
|
55
56
|
return true;
|
|
56
57
|
if (fn(node) === false)
|
|
57
58
|
return false;
|
|
58
|
-
|
|
59
|
+
// Not `|| []`: a non-array children (an object, a string) must not crash the validator itself.
|
|
60
|
+
for (const child of Array.isArray(node.children) ? node.children : []) {
|
|
59
61
|
if (visit(child) === false)
|
|
60
62
|
return false;
|
|
61
63
|
}
|
|
@@ -70,8 +72,23 @@ export function walk(source, fn) {
|
|
|
70
72
|
export function newPageSkeleton() {
|
|
71
73
|
return { sections: [] };
|
|
72
74
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
+
/** The id prefix the factory itself gives a type (TEXT-, PAYPAL-BTN-…): the editor recognises
|
|
76
|
+
* some elements by id prefix, so re-ided nodes must keep the factory's, not type.toUpperCase(). */
|
|
77
|
+
const prefixCache = new Map();
|
|
78
|
+
const typePrefix = (type) => {
|
|
79
|
+
if (!prefixCache.has(type)) {
|
|
80
|
+
// Two fresh ids share exactly the factory's fixed part: some factories add "-" before the
|
|
81
|
+
// random suffix (TEXT-x1y2…), some don't (INPUT-NUMBERx1y2…), one has none (PD-IMG-CAROUSEL-).
|
|
82
|
+
let p = "";
|
|
83
|
+
try {
|
|
84
|
+
const a = String(buildElement(type).id || ""), b = String(buildElement(type).id || "");
|
|
85
|
+
p = a === b ? a : a.slice(0, a.length - 8);
|
|
86
|
+
}
|
|
87
|
+
catch { /* unknown type */ }
|
|
88
|
+
prefixCache.set(type, p.replace(/-+$/, "") || type.toUpperCase());
|
|
89
|
+
}
|
|
90
|
+
return prefixCache.get(type);
|
|
91
|
+
};
|
|
75
92
|
/** Re-id every node in a subtree so a cloned/template node can't collide with existing ids. */
|
|
76
93
|
export function reassignIds(node) {
|
|
77
94
|
if (!node || typeof node !== "object")
|
|
@@ -286,7 +303,11 @@ export function buildFromSpec(spec) {
|
|
|
286
303
|
const kids = spec.children.map((c) => buildFromSpec(c));
|
|
287
304
|
// `layout:"row"` lays the children out side by side (responsive); default is a
|
|
288
305
|
// top-to-bottom vertical stack. rowGap/columnGap/colWidths/collapse tune the layout.
|
|
289
|
-
if (spec.
|
|
306
|
+
if (spec.type === "carousel") {
|
|
307
|
+
const n = kids.length;
|
|
308
|
+
rowChildren(node, kids, { columnGap: spec.columnGap, rowGap: spec.rowGap, colWidths: spec.colWidths, collapse: { bp2: n, bp3: n, bp4: n } });
|
|
309
|
+
}
|
|
310
|
+
else if (spec.layout === "row") {
|
|
290
311
|
rowChildren(node, kids, {
|
|
291
312
|
columnGap: spec.columnGap,
|
|
292
313
|
rowGap: spec.rowGap,
|
|
@@ -391,6 +412,11 @@ export function checkContentPlaceholders(content, previous) {
|
|
|
391
412
|
export function validatePage(source, previous) {
|
|
392
413
|
const errors = [];
|
|
393
414
|
const warnings = [];
|
|
415
|
+
// editor_v2 pages ({ nodes, root_node_id, schema_version }) are a different model this server
|
|
416
|
+
// doesn't author; judging them by v1 rules would block publishing every V2 site.
|
|
417
|
+
if (source && typeof source === "object" && source.nodes && source.root_node_id) {
|
|
418
|
+
return { valid: true, skipped: "editor_v2 source (nodes/root_node_id): not checked by the v1 validator" };
|
|
419
|
+
}
|
|
394
420
|
if (!source || typeof source !== "object" || !Array.isArray(source.sections)) {
|
|
395
421
|
return { valid: false, errors: ["Source must be an object shaped { sections: [...] }."] };
|
|
396
422
|
}
|
|
@@ -458,6 +484,11 @@ export function validatePage(source, previous) {
|
|
|
458
484
|
};
|
|
459
485
|
for (const s of source.sections)
|
|
460
486
|
checkTree(s, []);
|
|
487
|
+
// Crash-level shapes for the renderer and the editor (null children, non-object specials/bp,
|
|
488
|
+
// bad widthUnit/constraints/grid…). See shape.ts.
|
|
489
|
+
const shape = checkShape(source);
|
|
490
|
+
errors.push(...shape.errors);
|
|
491
|
+
warnings.push(...shape.warnings);
|
|
461
492
|
const code = checkNativeContent(source, previous);
|
|
462
493
|
errors.push(...code.errors);
|
|
463
494
|
warnings.push(...code.warnings);
|
|
@@ -468,6 +499,114 @@ export function validatePage(source, previous) {
|
|
|
468
499
|
stats: { sections: source.sections.length, total_elements: total, element_types: typeCounts },
|
|
469
500
|
};
|
|
470
501
|
}
|
|
502
|
+
/** Saved nodes missing one of the site's breakpoint keys: the renderer reads node[bp] with no
|
|
503
|
+
* fallback, so at that screen width the node renders unstyled and off-grid. An empty `{}` counts as
|
|
504
|
+
* missing, and so does a node left in `runtime` (both consumers ignore runtime). `keys` = the
|
|
505
|
+
* site's breakpoint names (default bp1..bp4). */
|
|
506
|
+
const isFilled = (v) => !!v && typeof v === "object" && Object.keys(v).length > 0;
|
|
507
|
+
export function missingBreakpoints(source, keys = BREAKPOINT_KEYS) {
|
|
508
|
+
let total = 0;
|
|
509
|
+
const ids = [];
|
|
510
|
+
walk(source, (node) => {
|
|
511
|
+
total++;
|
|
512
|
+
if (!keys.every((k) => isFilled(node[k])))
|
|
513
|
+
ids.push(node.id);
|
|
514
|
+
});
|
|
515
|
+
return { total, missing: ids.length, sample: ids.slice(0, 5) };
|
|
516
|
+
}
|
|
517
|
+
/** validatePage errors that a write ADDS over `before` (the source as saved). An old defect never
|
|
518
|
+
* blocks an unrelated save, so a broken page can still be edited and repaired. */
|
|
519
|
+
export function addedErrors(after, before) {
|
|
520
|
+
const now = validatePage(after, before).errors || [];
|
|
521
|
+
if (!before)
|
|
522
|
+
return now;
|
|
523
|
+
// Compare without the tree path (sections[2]>0…): inserting a section shifts every index, and an
|
|
524
|
+
// old defect must not read as new. Messages still carry the node id, so distinct nodes stay distinct.
|
|
525
|
+
const key = (e) => e.replace(/sections\[\d+\](>\d+)*/g, "");
|
|
526
|
+
const old = new Set((validatePage(before).errors || []).map(key));
|
|
527
|
+
return now.filter((e) => !old.has(key(e)));
|
|
528
|
+
}
|
|
529
|
+
/** What a patch changed on one node, key by key (style/config per breakpoint), or null. */
|
|
530
|
+
export function computeNodeDiff(before, after) {
|
|
531
|
+
const diff = {};
|
|
532
|
+
const keys = (b, a) => {
|
|
533
|
+
const out = {};
|
|
534
|
+
for (const k of new Set([...Object.keys(b || {}), ...Object.keys(a || {})]))
|
|
535
|
+
if (JSON.stringify(b?.[k]) !== JSON.stringify(a?.[k]))
|
|
536
|
+
out[k] = { before: b?.[k] ?? null, after: a?.[k] ?? null };
|
|
537
|
+
return Object.keys(out).length ? out : null;
|
|
538
|
+
};
|
|
539
|
+
for (const f of ["specials", "style", "config"]) {
|
|
540
|
+
const d = keys(before[f], after[f]);
|
|
541
|
+
if (d)
|
|
542
|
+
diff[f] = d;
|
|
543
|
+
}
|
|
544
|
+
for (const f of ["events", "bindings"])
|
|
545
|
+
if (JSON.stringify(before[f] || null) !== JSON.stringify(after[f] || null))
|
|
546
|
+
diff[f] = { before: before[f] || null, after: after[f] || null };
|
|
547
|
+
for (const k of new Set([...Object.keys(before), ...Object.keys(after)])) {
|
|
548
|
+
if (!/^(bp\d+|runtime)$/.test(k))
|
|
549
|
+
continue;
|
|
550
|
+
const layer = {};
|
|
551
|
+
for (const f of ["style", "config"]) {
|
|
552
|
+
const d = keys(before[k]?.[f], after[k]?.[f]);
|
|
553
|
+
if (d)
|
|
554
|
+
layer[f] = d;
|
|
555
|
+
}
|
|
556
|
+
if (Object.keys(layer).length)
|
|
557
|
+
(diff.responsive ??= {})[k] = layer;
|
|
558
|
+
}
|
|
559
|
+
return Object.keys(diff).length ? diff : null;
|
|
560
|
+
}
|
|
561
|
+
/** Editor style keys are camelCase (fontSize); accept CSS spelling (font-size) too. */
|
|
562
|
+
const camelKeys = (o) => Object.fromEntries(Object.entries(o || {}).map(([k, v]) => [k.replace(/-([a-z])/g, (_, c) => c.toUpperCase()), v]));
|
|
563
|
+
/** Apply an element patch (update_page_element & co.) where the renderer reads it. Style/config
|
|
564
|
+
* live per breakpoint (node.bp1..bpN); a top-level node.style is never rendered. Like the editor's
|
|
565
|
+
* breakpoint sync: size/position keys (STYLE_ASYNC/CONFIG_ASYNC) land on the base breakpoint
|
|
566
|
+
* only, everything else (colour, font, border…) on every breakpoint. `responsive` targets one. */
|
|
567
|
+
export function applyNodeUpdates(node, updates) {
|
|
568
|
+
const style = updates.style ? camelKeys(updates.style) : null;
|
|
569
|
+
const config = updates.config || null;
|
|
570
|
+
if (style || config) {
|
|
571
|
+
const bps = Object.keys(node).filter((k) => /^bp\d+$/.test(k) && node[k] && typeof node[k] === "object");
|
|
572
|
+
if (!bps.length && node.runtime && typeof node.runtime === "object") {
|
|
573
|
+
if (style)
|
|
574
|
+
node.runtime.style = { ...(node.runtime.style || {}), ...style };
|
|
575
|
+
if (config)
|
|
576
|
+
node.runtime.config = { ...(node.runtime.config || {}), ...config };
|
|
577
|
+
}
|
|
578
|
+
else {
|
|
579
|
+
const targets = bps.length ? bps : ["bp1"];
|
|
580
|
+
const base = targets.includes("bp1") ? "bp1" : [...targets].sort()[0];
|
|
581
|
+
const only = (o, async, bp) => bp === base ? o : Object.fromEntries(Object.entries(o).filter(([k]) => !async.includes(k)));
|
|
582
|
+
for (const bp of targets) {
|
|
583
|
+
const cur = node[bp] || {};
|
|
584
|
+
node[bp] = {
|
|
585
|
+
...cur,
|
|
586
|
+
style: { ...(cur.style || {}), ...(style ? only(style, STYLE_ASYNC, bp) : {}) },
|
|
587
|
+
config: { ...(cur.config || {}), ...(config ? only(config, CONFIG_ASYNC, bp) : {}) },
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
if (updates.specials)
|
|
593
|
+
node.specials = { ...(node.specials || {}), ...updates.specials };
|
|
594
|
+
// Normalize so events/bindings carry a valid id + eventName (the renderer won't dispatch without).
|
|
595
|
+
if (updates.events !== undefined)
|
|
596
|
+
node.events = normalizeEvents(updates.events, node.type);
|
|
597
|
+
if (updates.bindings !== undefined)
|
|
598
|
+
node.bindings = normalizeBindings(updates.bindings);
|
|
599
|
+
if (updates.responsive) {
|
|
600
|
+
for (const [bp, val] of Object.entries(updates.responsive)) {
|
|
601
|
+
if (!/^bp\d+$/.test(bp) || !val || typeof val !== "object")
|
|
602
|
+
continue;
|
|
603
|
+
const cur = node[bp] || {};
|
|
604
|
+
// Always both keys: a bp layer missing config/style crashes the renderer's CSS builders.
|
|
605
|
+
node[bp] = { ...cur, style: { ...(cur.style || {}), ...camelKeys(val.style) }, config: { ...(cur.config || {}), ...(val.config || {}) } };
|
|
606
|
+
}
|
|
607
|
+
markAsyncIfDiverged(node);
|
|
608
|
+
}
|
|
609
|
+
}
|
|
471
610
|
/**
|
|
472
611
|
* Expand one node's `runtime.{style,config}` into the per-breakpoint keys the storefront
|
|
473
612
|
* renderer reads (bp1..bp4). Mirrors builderx_spa's syncBreakpoint: the authored
|
|
@@ -511,16 +650,57 @@ function remapToSiteBreakpoints(node, site) {
|
|
|
511
650
|
out[key] = clone(from);
|
|
512
651
|
const gridWidth = openEnded ? Math.max(minW, BREAKPOINTS.bp1[0]) : minW;
|
|
513
652
|
if (node.type === "section")
|
|
514
|
-
out[key].config.columns =
|
|
653
|
+
out[key].config.columns = sectionColumns(key, gridWidth);
|
|
515
654
|
}
|
|
516
655
|
for (const k of BREAKPOINT_KEYS)
|
|
517
656
|
delete node[k];
|
|
518
657
|
Object.assign(node, out);
|
|
519
658
|
}
|
|
659
|
+
/** Grid boxes the editor creates with a 1x1 grid (ContainerPicker.vue / popupBPSample). Left with
|
|
660
|
+
* no rows, the editor's useFindGridArea throws (nothing can be dropped in) and the renderer
|
|
661
|
+
* emits an empty grid-template with a zero height. */
|
|
662
|
+
const EMPTY_GRID_TYPES = new Set(["container", "form", "popup"]);
|
|
663
|
+
/** Margin offsets the editor writes on every drop (setDimensionUnit, editor.js). Missing, the
|
|
664
|
+
* renderer prints `margin-left: %;` and the constraint/align panels compute NaN. */
|
|
665
|
+
const OFFSET_ZEROS = {
|
|
666
|
+
relLeft: 0, relRight: 0, absRight: 0, relTop: 0, relBottom: 0, absBottom: 0,
|
|
667
|
+
absLeftCenterX: 0, relLeftCenterX: 0, absRightCenterX: 0, relRightCenterX: 0,
|
|
668
|
+
absTopCenterY: 0, relTopCenterY: 0, absBottomCenterY: 0, relBottomCenterY: 0,
|
|
669
|
+
};
|
|
670
|
+
/** The editor's breakpoint sync (arrange.js syncElement) copies every non-size/position key
|
|
671
|
+
* from the active breakpoint onto the others on each save, UNLESS specials.element_async is set
|
|
672
|
+
* (its "this breakpoint only" toggle). So a node whose breakpoints differ on such a key needs
|
|
673
|
+
* the flag, or the editor's first save wipes its mobile/tablet overrides. */
|
|
674
|
+
export function markAsyncIfDiverged(node) {
|
|
675
|
+
const bps = Object.keys(node).filter((k) => BP_KEY_RE.test(k) && node[k] && typeof node[k] === "object");
|
|
676
|
+
const base = node.bp1;
|
|
677
|
+
if (!base || bps.length < 2)
|
|
678
|
+
return;
|
|
679
|
+
const differs = (a = {}, b = {}, async) => [...new Set([...Object.keys(a), ...Object.keys(b)])].some((k) => k !== "loaded" && !async.includes(k) && JSON.stringify(a[k]) !== JSON.stringify(b[k]));
|
|
680
|
+
if (bps.some((bp) => bp !== "bp1" && (differs(base.style, node[bp].style, STYLE_ASYNC) || differs(base.config, node[bp].config, CONFIG_ASYNC))))
|
|
681
|
+
node.specials = { ...(node.specials || {}), element_async: true };
|
|
682
|
+
}
|
|
683
|
+
const BP_KEY_RE = /^bp\d+$/;
|
|
520
684
|
function expandNodeToBreakpoints(node, site) {
|
|
521
685
|
const rt = node && node.runtime;
|
|
686
|
+
// The editor merges runtime.specials into specials on drop (ElementDrag.vue); 26 factories
|
|
687
|
+
// (tabs, tags, coupon…) keep their defaults and the caller's opts.specials there.
|
|
688
|
+
if (rt && rt.specials && typeof rt.specials === "object")
|
|
689
|
+
node.specials = { ...(node.specials || {}), ...rt.specials };
|
|
522
690
|
if (rt && (rt.style || rt.config || rt.responsive)) {
|
|
523
|
-
|
|
691
|
+
let baseConfig = { ...(rt.config || {}), loaded: true };
|
|
692
|
+
if (node.type !== "section")
|
|
693
|
+
baseConfig = { ...OFFSET_ZEROS, ...baseConfig };
|
|
694
|
+
if (node.type === "popup" && !baseConfig.widthUnit)
|
|
695
|
+
baseConfig.widthUnit = "px"; // editor popupBPSample
|
|
696
|
+
if (EMPTY_GRID_TYPES.has(node.type) && !(node.children || []).length && !(Array.isArray(baseConfig.rows) && baseConfig.rows.length))
|
|
697
|
+
baseConfig = {
|
|
698
|
+
...baseConfig,
|
|
699
|
+
grid: "1x1",
|
|
700
|
+
columns: [{ unit: "fr", value: 1 }],
|
|
701
|
+
rows: [{ unit: "min/max", min: { unit: "px", absValue: pxToNum(rt.style?.height) || 280 }, max: { unit: "max-c" } }],
|
|
702
|
+
heightUnit: baseConfig.heightUnit || "auto",
|
|
703
|
+
};
|
|
524
704
|
const isSection = node.type === "section";
|
|
525
705
|
const rowMeta = baseConfig.__row; // this node is a multi-column row container
|
|
526
706
|
const cellMeta = baseConfig.__cell; // this node is a cell inside a row
|
|
@@ -551,7 +731,7 @@ function expandNodeToBreakpoints(node, site) {
|
|
|
551
731
|
if (isSection) {
|
|
552
732
|
const g = genGridByBp(minW);
|
|
553
733
|
const sectionRows = baseConfig.rows && baseConfig.rows.length ? clone(baseConfig.rows) : clone(g.rows);
|
|
554
|
-
config.columns =
|
|
734
|
+
config.columns = sectionColumns(bp, minW);
|
|
555
735
|
config.rows = sectionRows;
|
|
556
736
|
config.grid = `3x${sectionRows.length}`;
|
|
557
737
|
config.heightUnit = config.heightUnit || "auto";
|
|
@@ -581,6 +761,30 @@ function expandNodeToBreakpoints(node, site) {
|
|
|
581
761
|
}
|
|
582
762
|
node[bp] = { style, config };
|
|
583
763
|
}
|
|
764
|
+
// Grid-placed nodes only: a fixed/absolute node anchored by right/bottom (a floating chat or
|
|
765
|
+
// back-to-top button) must not gain a left/top that overrides its anchor.
|
|
766
|
+
if (node.type !== "section")
|
|
767
|
+
for (const bp of BREAKPOINT_KEYS) {
|
|
768
|
+
const { style: st, config: cf } = node[bp];
|
|
769
|
+
if ((cf.position || "default") !== "default")
|
|
770
|
+
continue;
|
|
771
|
+
if (st.top == null && st.bottom == null)
|
|
772
|
+
st.top = 0;
|
|
773
|
+
if (st.left == null && st.right == null)
|
|
774
|
+
st.left = 0;
|
|
775
|
+
}
|
|
776
|
+
// A button the factory sizes to its content (widthUnit "auto") still needs a width and
|
|
777
|
+
// relWidth: the editor's W field reads style.width ("undefinedauto") and a unit switch
|
|
778
|
+
// computes parent*relWidth/100 (NaN).
|
|
779
|
+
if (baseConfig.widthUnit === "auto")
|
|
780
|
+
for (const bp of BREAKPOINT_KEYS) {
|
|
781
|
+
const st = node[bp].style;
|
|
782
|
+
if (st.width == null)
|
|
783
|
+
st.width = Math.round(String(node.specials?.text || "").replace(/<[^>]*>/g, "").length * 9 + 56);
|
|
784
|
+
if (node[bp].config.relWidth == null)
|
|
785
|
+
node[bp].config.relWidth = 100;
|
|
786
|
+
}
|
|
787
|
+
markAsyncIfDiverged(node);
|
|
584
788
|
delete node.runtime;
|
|
585
789
|
if (site)
|
|
586
790
|
remapToSiteBreakpoints(node, site);
|
|
@@ -595,11 +799,41 @@ function expandNodeToBreakpoints(node, site) {
|
|
|
595
799
|
* is removed. MUST be called before saving a page built with new_section/new_element —
|
|
596
800
|
* otherwise the page renders with no styling or grid placement.
|
|
597
801
|
*/
|
|
598
|
-
export function finalizeForRender(source, siteBreakpoints) {
|
|
802
|
+
export function finalizeForRender(source, siteBreakpoints, defaultGrid) {
|
|
599
803
|
const sections = source && Array.isArray(source.sections) ? source.sections : [];
|
|
600
804
|
const custom = customBreakpoints(siteBreakpoints);
|
|
601
|
-
|
|
602
|
-
|
|
805
|
+
siteGrid = defaultGrid && typeof defaultGrid === "object" ? defaultGrid : null;
|
|
806
|
+
try {
|
|
807
|
+
for (const s of sections)
|
|
808
|
+
expandNodeToBreakpoints(s, custom);
|
|
809
|
+
}
|
|
810
|
+
finally {
|
|
811
|
+
siteGrid = null;
|
|
812
|
+
}
|
|
813
|
+
walk(source, nameLikeEditor);
|
|
603
814
|
return source;
|
|
604
815
|
}
|
|
816
|
+
/** The site's section grid (settings.defaultGrid, set by the editor per breakpoint), for the
|
|
817
|
+
* duration of one synchronous finalizeForRender. */
|
|
818
|
+
let siteGrid = null;
|
|
819
|
+
/** A section's columns at a breakpoint: the site's defaultGrid (what the editor's addBlankSection
|
|
820
|
+
* uses) when it is the usual 3-track centred grid, else the standard one for that width. */
|
|
821
|
+
function sectionColumns(bp, width) {
|
|
822
|
+
const own = siteGrid?.[bp]?.columns;
|
|
823
|
+
return clone(Array.isArray(own) && own.length === 3 && own.every((c) => c && typeof c === "object") ? own : genGridByBp(width).columns);
|
|
824
|
+
}
|
|
825
|
+
const FORM_PREFIX = {
|
|
826
|
+
form_order: "ORDER", subscribe: "SUB", order_tracking: "TRACK", form_discount: "DISC", customer_data: "MEM",
|
|
827
|
+
form_search_agency: "SAG", forgot_password: "FORGOT", reset_password: "RESET", reward_points: "POINTS",
|
|
828
|
+
form_booking: "BOOKING", question_form: "QUESTION", course_form_submit: "COURSE-SUBMIT",
|
|
829
|
+
};
|
|
830
|
+
const MENU_PREFIX = { horizontal: "HOR", vertical: "VER", collapse: "COL", hamburger: "HAM" };
|
|
831
|
+
/** Names the editor gives forms and menus on drop (ElementDrag.vue handleNameForm): its form and
|
|
832
|
+
* menu pickers list elements by these names. */
|
|
833
|
+
function nameLikeEditor(node) {
|
|
834
|
+
if (node.name || !node.id || (node.type !== "form" && node.type !== "menu"))
|
|
835
|
+
return;
|
|
836
|
+
const pre = (node.type === "form" ? FORM_PREFIX : MENU_PREFIX)[node.specials?.type];
|
|
837
|
+
node.name = pre ? `${pre}-${node.id}` : node.id;
|
|
838
|
+
}
|
|
605
839
|
export { ELEMENT_TYPES };
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
// Shape checks for a saved page source: what makes the storefront renderer or the builder editor
|
|
2
|
+
// throw. The renderer (builderx_api lib/qwik) rescues any exception into an EMPTY page or an
|
|
3
|
+
// EMPTY dynamic CSS, and the editor has no error boundary, so one bad node blanks a whole page,
|
|
4
|
+
// section or canvas. Every `errors` entry below is such a crash, with the code that throws.
|
|
5
|
+
// `warnings` are layouts that render wrong but don't throw.
|
|
6
|
+
const isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
7
|
+
const BP_KEY = /^bp\d+$/;
|
|
8
|
+
// Ids end up in `#id` CSS selectors and querySelector (editor Grid.vue / grid.js).
|
|
9
|
+
const ID_RE = /^[A-Za-z][\w-]*$/;
|
|
10
|
+
// build_position: `case width_unit` with no fallback ("vw" is commented out). Missing → "%".
|
|
11
|
+
const WIDTH_UNITS = new Set(["auto", "px", "%"]);
|
|
12
|
+
const CONSTRAINT_X = new Set(["left", "right", "centerLeft", "centerRight"]);
|
|
13
|
+
const CONSTRAINT_Y = new Set(["top", "bottom", "centerTop", "centerBottom"]);
|
|
14
|
+
const TRACK_UNITS = new Set(["fr", "px", "%", "auto", "min/max", "max-c", "min-c", "calc", "vh", "vw"]);
|
|
15
|
+
// Editor components that destructure specials without a default (Text.vue, Button.vue, Select.vue…).
|
|
16
|
+
const NEEDS_SPECIALS = new Set([
|
|
17
|
+
"text", "button", "input", "text-area", "select", "radio", "checkbox", "radio-group", "checkbox-group",
|
|
18
|
+
"menu", "carousel", "swiper",
|
|
19
|
+
]);
|
|
20
|
+
/** Containers whose children are all one kind (build_swiper renders every child as a slide…). */
|
|
21
|
+
const CHILD_TYPES = { swiper: ["slide"], menu: ["menu-item", "menu-droppable"], collapse: ["collapse-item"] };
|
|
22
|
+
/** Editor components that index specials.options (Select.vue, Radio.vue, Checkbox). */
|
|
23
|
+
const OPTION_TYPES = new Set(["select", "radio", "checkbox"]);
|
|
24
|
+
const GRID_CONTAINERS = new Set(["section", "container", "form", "popup", "carousel"]);
|
|
25
|
+
const UNIT_SUFFIXED = /^-?\d+(\.\d+)?(px|%|vw|vh|rem|em)$/;
|
|
26
|
+
const NUMERIC_STYLE = ["width", "height", "top", "left", "right", "bottom", "columnGap", "rowGap"];
|
|
27
|
+
export function checkShape(source) {
|
|
28
|
+
const errors = [];
|
|
29
|
+
const warnings = [];
|
|
30
|
+
/** Breaks the editor only (an element/canvas goes blank there); the storefront renders. Still
|
|
31
|
+
* refused on a write, but publish_site doesn't block on it: the live site works. */
|
|
32
|
+
const editorOnly = [];
|
|
33
|
+
const editorErr = (m) => { errors.push(m); editorOnly.push(m); };
|
|
34
|
+
if (!isObj(source) || !Array.isArray(source.sections))
|
|
35
|
+
return { errors, warnings, editorOnly }; // validatePage reports it
|
|
36
|
+
source.sections.forEach((s, i) => {
|
|
37
|
+
if (!isObj(s))
|
|
38
|
+
editorErr(`sections[${i}] is ${s === null ? "null" : typeof s}, not an element: the editor never finishes loading.`);
|
|
39
|
+
});
|
|
40
|
+
const layer = (node, at, where, isBp) => {
|
|
41
|
+
const v = node[where];
|
|
42
|
+
if (v === undefined)
|
|
43
|
+
return;
|
|
44
|
+
if (!isObj(v)) {
|
|
45
|
+
errors.push(`${at}.${where} must be an object (got ${Array.isArray(v) ? "array" : v === null ? "null" : typeof v}): the renderer throws and the page goes blank.`);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
// build_section reads `el[bp]["style"] || %{}`; the element builders pattern-match
|
|
49
|
+
// %{"style" => _, "config" => _} = el[bp] (dynamic/index.ex). Real editor sections carry
|
|
50
|
+
// config-only layers, so only non-sections are refused.
|
|
51
|
+
if (isBp && node.type !== "section" && Object.keys(v).length && (!isObj(v.style) || !isObj(v.config)))
|
|
52
|
+
errors.push(`${at}.${where} needs both style:{} and config:{} objects: the CSS builders pattern-match them and all page CSS is lost.`);
|
|
53
|
+
if (isObj(v.style))
|
|
54
|
+
style(v.style, `${at}.${where}.style`);
|
|
55
|
+
if (isObj(v.config))
|
|
56
|
+
config(node, v.config, `${at}.${where}.config`);
|
|
57
|
+
};
|
|
58
|
+
const style = (st, at) => {
|
|
59
|
+
for (const [k, val] of Object.entries(st))
|
|
60
|
+
if (val !== null && typeof val === "object")
|
|
61
|
+
errors.push(`${at}.${k} is an object; style values must be strings or numbers (renderer can't print it, all page CSS is lost).`);
|
|
62
|
+
for (const k of NUMERIC_STYLE)
|
|
63
|
+
if (typeof st[k] === "string" && UNIT_SUFFIXED.test(st[k]) && !st[k].endsWith("%"))
|
|
64
|
+
warnings.push(`${at}.${k} = "${st[k]}": store the number only (the unit lives in config), or it renders as "${st[k]}px".`);
|
|
65
|
+
};
|
|
66
|
+
const config = (node, cfg, at) => {
|
|
67
|
+
const wu = cfg.widthUnit;
|
|
68
|
+
// "vw" is what the editor itself writes for overlays, droppables and submenus.
|
|
69
|
+
if (wu != null && wu !== "vw" && !WIDTH_UNITS.has(wu)) {
|
|
70
|
+
errors.push(`${at}.widthUnit "${wu}" must be auto, px or %: the renderer has no branch for it and all page CSS is lost.`);
|
|
71
|
+
}
|
|
72
|
+
for (const [key, allowed] of [["constraintX", CONSTRAINT_X], ["constraintY", CONSTRAINT_Y]]) {
|
|
73
|
+
const c = cfg[key];
|
|
74
|
+
if (c == null)
|
|
75
|
+
continue;
|
|
76
|
+
// get_grid_position: [c] = [] fails; with 2+ entries it String.contains? each one and
|
|
77
|
+
// destructures [a, b] = when one is a center*. Unknown single values just get no CSS.
|
|
78
|
+
const crash = !Array.isArray(c) || c.length === 0 ||
|
|
79
|
+
(c.length > 1 && (c.some((x) => typeof x !== "string") || (c.length > 2 && c.some((x) => x.includes("center")))));
|
|
80
|
+
if (crash)
|
|
81
|
+
errors.push(`${at}.${key} must be 1-2 of ${[...allowed].join("/")} (got ${JSON.stringify(c)}): the renderer pattern-matches it and all page CSS is lost.`);
|
|
82
|
+
else if (!c.every((x) => allowed.has(x)))
|
|
83
|
+
warnings.push(`${at}.${key} ${JSON.stringify(c)} has values outside ${[...allowed].join("/")}: that element gets no position CSS.`);
|
|
84
|
+
}
|
|
85
|
+
for (const key of ["columns", "rows"]) {
|
|
86
|
+
const t = cfg[key];
|
|
87
|
+
if (!t)
|
|
88
|
+
continue;
|
|
89
|
+
// grid-product & co. store a per-row COUNT here; only grid containers map it as tracks.
|
|
90
|
+
if (typeof t === "number" && !GRID_CONTAINERS.has(node.type))
|
|
91
|
+
continue;
|
|
92
|
+
// null tracks are saved by the editor itself; convert_style_grid treats nil as %{}.
|
|
93
|
+
if (!Array.isArray(t) || !t.every((tr) => tr === null || isObj(tr))) {
|
|
94
|
+
errors.push(`${at}.${key} must be an array of track objects { unit, value }: the grid builder throws.`);
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
t.forEach((tr, i) => {
|
|
98
|
+
if (tr && tr.unit != null && !TRACK_UNITS.has(tr.unit))
|
|
99
|
+
warnings.push(`${at}.${key}[${i}].unit "${tr.unit}" is unknown; the editor drops the whole grid template.`);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
if (cfg.grid != null && cfg.grid !== "") {
|
|
103
|
+
const m = /^(\d+)x(\d+)$/.exec(String(cfg.grid));
|
|
104
|
+
if (!m)
|
|
105
|
+
editorErr(`${at}.grid "${cfg.grid}" must be "<cols>x<rows>": the editor parses it when the element is selected.`);
|
|
106
|
+
else if (+m[1] < 1 || +m[2] < 1)
|
|
107
|
+
warnings.push(`${at}.grid "${cfg.grid}" has a zero dimension; set it to match columns×rows.`);
|
|
108
|
+
}
|
|
109
|
+
if (cfg.animation != null && !isObj(cfg.animation))
|
|
110
|
+
errors.push(`${at}.animation must be an object: the renderer throws.`);
|
|
111
|
+
if (cfg.borderEdges != null && !Array.isArray(cfg.borderEdges))
|
|
112
|
+
errors.push(`${at}.borderEdges must be an array: the renderer throws.`);
|
|
113
|
+
const vb = cfg.video_background;
|
|
114
|
+
if (vb && (!isObj(vb) || typeof vb.url !== "string"))
|
|
115
|
+
errors.push(`${at}.video_background needs a string url (or remove it): the renderer calls String.contains? on it and the page goes blank.`);
|
|
116
|
+
if (node.type === "section" && vb?.sync_width_section && !(Number(node.bp1?.style?.width) > 0))
|
|
117
|
+
warnings.push(`${at}.video_background.sync_width_section needs a numeric section width.`);
|
|
118
|
+
};
|
|
119
|
+
const check = (node, at, parentType) => {
|
|
120
|
+
if (!isObj(node))
|
|
121
|
+
return;
|
|
122
|
+
const type = node.type;
|
|
123
|
+
const label = `${at} (${node.id || "?"}${type ? ` ${type}` : ""})`;
|
|
124
|
+
if (typeof node.id === "string" && node.id && !ID_RE.test(node.id))
|
|
125
|
+
warnings.push(`${label}: id should start with a letter and hold only letters, digits, _ or -: as a #id selector it loses its CSS and the editor throws when it is selected.`);
|
|
126
|
+
if ("specials" in node && !isObj(node.specials))
|
|
127
|
+
errors.push(`${label}.specials must be an object: every renderer builder reads it and the page goes blank.`);
|
|
128
|
+
else if (!("specials" in node) && NEEDS_SPECIALS.has(type))
|
|
129
|
+
editorErr(`${label} has no specials: the editor's ${type} component reads it without a default and the element goes blank.`);
|
|
130
|
+
const sp = isObj(node.specials) ? node.specials : {};
|
|
131
|
+
for (const k of ["custom_css", "custom_class"])
|
|
132
|
+
if (sp[k] != null && typeof sp[k] !== "string")
|
|
133
|
+
errors.push(`${label}.specials.${k} must be a string: the renderer splits it and the page goes blank.`);
|
|
134
|
+
if (type === "text" && sp.tag != null && typeof sp.tag !== "string")
|
|
135
|
+
errors.push(`${label}.specials.tag must be a string (h1, p…): the page goes blank.`);
|
|
136
|
+
if (OPTION_TYPES.has(type) && sp.options != null && (!Array.isArray(sp.options) || sp.options.some((o) => o == null)))
|
|
137
|
+
editorErr(`${label}.specials.options must be an array with no null entries: the editor's ${type} goes blank.`);
|
|
138
|
+
if (type === "select" && Array.isArray(sp.options) && sp.defaultValue != null && sp.defaultValue !== "" && sp.defaultValue !== "none" &&
|
|
139
|
+
sp.options.every((o) => isObj(o) && "id" in o) && !sp.options.some((o) => o.id === sp.defaultValue))
|
|
140
|
+
editorErr(`${label}.specials.defaultValue "${sp.defaultValue}" names no option id: the editor's select goes blank.`);
|
|
141
|
+
if (node.events != null && (!Array.isArray(node.events) || !node.events.every(isObj)))
|
|
142
|
+
errors.push(`${label}.events must be an array of event objects: the renderer throws and the page goes blank.`);
|
|
143
|
+
for (const k of Object.keys(node))
|
|
144
|
+
if (BP_KEY.test(k))
|
|
145
|
+
layer(node, label, k, true);
|
|
146
|
+
layer(node, label, "runtime", false); // unsaved builder shape: same value rules
|
|
147
|
+
if (type === "section" && parentType)
|
|
148
|
+
warnings.push(`${label}: a section nested inside a ${parentType} renders as an empty box in the editor.`);
|
|
149
|
+
if (type === "popup" && !parentType)
|
|
150
|
+
warnings.push(`${label}: popups belong in a global source (popup), not the page's sections; inline it renders without its overlay.`);
|
|
151
|
+
if (type === "form" && !sp.type)
|
|
152
|
+
warnings.push(`${label}: no specials.type, so the renderer treats it as form_order (a checkout). Contact/lead/newsletter → "subscribe".`);
|
|
153
|
+
const kinds = CHILD_TYPES[type];
|
|
154
|
+
if (kinds && Array.isArray(node.children) && node.children.some((c) => isObj(c) && !kinds.includes(c.type)))
|
|
155
|
+
warnings.push(`${label}: a ${type} holds only ${kinds.join("/")} children (the renderer treats each child as one); wrap other content inside a ${kinds[0]}.`);
|
|
156
|
+
if (type === "dropdown" && !(Array.isArray(node.children) && node.children.length))
|
|
157
|
+
warnings.push(`${label}: a dropdown needs its content child, or the editor can't render it.`);
|
|
158
|
+
if ("children" in node) {
|
|
159
|
+
if (!Array.isArray(node.children)) {
|
|
160
|
+
errors.push(`${label}.children must be an array (got ${node.children === null ? "null" : typeof node.children}): the renderer maps over it and the page goes blank.`);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
node.children.forEach((c, i) => {
|
|
164
|
+
if (!isObj(c)) {
|
|
165
|
+
errors.push(`${label}.children[${i}] is ${c === null ? "null" : Array.isArray(c) ? "an array" : typeof c}, not an element: the renderer throws and the editor blanks every section.`);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
check(c, `${at}>${i}`, type || null);
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
source.sections.forEach((s, i) => check(s, `sections[${i}]`, null));
|
|
173
|
+
return { errors, warnings, editorOnly };
|
|
174
|
+
}
|
package/dist/changelog.json
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"v": "1.40.0",
|
|
4
|
+
"d": "19/11/2026",
|
|
5
|
+
"type": "Added",
|
|
6
|
+
"en": "The stdio server now reopens the browser Connect page automatically when the session token expires or the backend rejects it with a 401, then…",
|
|
7
|
+
"vi": "Server stdio nay tự mở lại trang Connect trên trình duyệt khi token phiên hết hạn hoặc bị backend từ chối với lỗi 401, rồi tự chạy lại lệnh gọi tool…"
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"v": "1.39.0",
|
|
11
|
+
"d": "13/11/2026",
|
|
12
|
+
"type": "Added",
|
|
13
|
+
"en": "New preview_page tool screenshots the saved (unpublished) draft at desktop and mobile widths through the editor's own preview host, so a page can be…",
|
|
14
|
+
"vi": "Tool mới preview_page chụp ảnh bản nháp đã lưu (chưa publish) ở cả độ rộng máy tính và điện thoại qua host xem trước của chính editor, nhờ đó có thể…"
|
|
15
|
+
},
|
|
2
16
|
{
|
|
3
17
|
"v": "1.38.0",
|
|
4
18
|
"d": "05/11/2026",
|
|
@@ -26,19 +40,5 @@
|
|
|
26
40
|
"type": "Changed",
|
|
27
41
|
"en": "get_build_guide and the ingest_html tool description now state that embed is a last resort: build everything native elements can with new_section,…",
|
|
28
42
|
"vi": "get_build_guide và mô tả tool ingest_html nay nêu rõ embed chỉ là phương án cuối: dựng native mọi thứ có thể bằng new_section, chỉ dùng embed cho…"
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
"v": "1.36.0",
|
|
32
|
-
"d": "22/10/2026",
|
|
33
|
-
"type": "Added",
|
|
34
|
-
"en": "New invoke_read_tool runs any read-only on-demand tool (list_*/get_*/search_*, i.e. tools with readOnlyHint) by name through the gateway, so clients…",
|
|
35
|
-
"vi": "Tool mới invoke_read_tool chạy bất kỳ tool chỉ-đọc nào (list_*/get_*/search_*, tức tool có readOnlyHint) qua gateway theo tên, nhờ đó client nào bắt…"
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
"v": "1.35.0",
|
|
39
|
-
"d": "22/10/2026",
|
|
40
|
-
"type": "Added",
|
|
41
|
-
"en": "New get_site_subscription tool reads a site's plan (current/default site): plan_name, status (active | expired | pending_payment | none),…",
|
|
42
|
-
"vi": "Tool mới get_site_subscription đọc gói cước của site (mặc định site hiện tại): plan_name, status (active | expired | pending_payment | none),…"
|
|
43
43
|
}
|
|
44
44
|
]
|
package/dist/config.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Central resolution of connection settings for every entry path (stdio, install,
|
|
2
2
|
// login, remote HTTP). Precedence: explicit overrides > environment variables >
|
|
3
3
|
// saved config in the local config file.
|
|
4
|
-
import { WebcakeCmsApi } from "./api.js";
|
|
4
|
+
import { WebcakeCmsApi, jwtExpired } from "./api.js";
|
|
5
5
|
import { getSavedConfig } from "./tools/context.js";
|
|
6
6
|
// Per-environment endpoints so you can switch with `--env <name>` / WEBCAKE_ENV
|
|
7
7
|
// instead of setting WEBCAKE_API_URL / WEBCAKE_APP_URL by hand. Default is prod.
|
|
@@ -10,16 +10,19 @@ export const ENVIRONMENTS = {
|
|
|
10
10
|
apiUrl: "http://localhost:24679",
|
|
11
11
|
appUrl: "http://localhost:5173",
|
|
12
12
|
preview: { kind: "path", base: "http://demo.localhost:24679" },
|
|
13
|
+
draft: "http://demo.localhost:24679",
|
|
13
14
|
},
|
|
14
15
|
staging: {
|
|
15
16
|
apiUrl: "https://api.staging.storecake.io",
|
|
16
17
|
appUrl: "https://staging.webcake.io",
|
|
17
18
|
preview: { kind: "path", base: "https://staging2.webcake.me" },
|
|
19
|
+
draft: "https://staging2.webcake.me",
|
|
18
20
|
},
|
|
19
21
|
prod: {
|
|
20
22
|
apiUrl: "https://api.storefront.webcake.io",
|
|
21
23
|
appUrl: "https://webcake.io",
|
|
22
24
|
preview: { kind: "subdomain", suffix: "webcake.me" },
|
|
25
|
+
draft: "https://preview.webcake.biz",
|
|
23
26
|
},
|
|
24
27
|
};
|
|
25
28
|
export const DEFAULT_ENV = "prod";
|
|
@@ -56,6 +59,10 @@ export async function resolvePreviewUrl(api) {
|
|
|
56
59
|
}
|
|
57
60
|
return `${rule.base}/${api.siteId}`;
|
|
58
61
|
}
|
|
62
|
+
/** The editor's draft-preview URL for a page slug (homepage: ""). */
|
|
63
|
+
export function draftPreviewUrl(api, slug) {
|
|
64
|
+
return `${ENVIRONMENTS[envFromApiUrl(api.baseUrl)].draft}/${api.siteId}/${slug.replace(/^\/+/, "")}`;
|
|
65
|
+
}
|
|
59
66
|
export function resolveEnv(name) {
|
|
60
67
|
if (!name)
|
|
61
68
|
return undefined;
|
|
@@ -80,9 +87,12 @@ export function resolveSettings(overrides = {}) {
|
|
|
80
87
|
process.env.WEBCAKE_APP_URL ||
|
|
81
88
|
preset?.appUrl ||
|
|
82
89
|
ENVIRONMENTS[DEFAULT_ENV].appUrl;
|
|
83
|
-
|
|
90
|
+
// An expired env token (pinned in the IDE config) loses to a fresher one saved by a re-login.
|
|
91
|
+
const envToken = process.env.WEBCAKE_TOKEN;
|
|
92
|
+
const renewed = !!envToken && jwtExpired(envToken) && !!saved.token && !jwtExpired(saved.token);
|
|
93
|
+
const token = overrides.token || (renewed ? saved.token : envToken) || saved.token || "";
|
|
84
94
|
const siteId = overrides.siteId || process.env.WEBCAKE_SITE_ID || saved.site_id || "";
|
|
85
|
-
const sessionId = overrides.sessionId || process.env.WEBCAKE_SESSION_ID || saved.session_id || "";
|
|
95
|
+
const sessionId = overrides.sessionId || (renewed ? saved.session_id : process.env.WEBCAKE_SESSION_ID) || saved.session_id || "";
|
|
86
96
|
return { apiUrl, appUrl, token, siteId, sessionId, env: envName };
|
|
87
97
|
}
|
|
88
98
|
/** Build a WebcakeCmsApi client from resolved settings. */
|