@allegrocdp/preview 0.1.0-dev.14 → 0.1.0-dev.15

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/cli.js CHANGED
@@ -28,6 +28,10 @@ window.__ALLEGRO_TEMPLATE_RESOLVER__ = async function (slug) {
28
28
  };`;
29
29
 
30
30
  // src/scenarios.ts
31
+ var SCENARIO_ID_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
32
+ function isValidScenarioId(id) {
33
+ return SCENARIO_ID_PATTERN.test(id);
34
+ }
31
35
  function emptyPlacement() {
32
36
  return {
33
37
  target_selector: null,
@@ -471,7 +475,7 @@ function parsePlacement(raw) {
471
475
  if (raw.truncation_unit === "paragraphs") {
472
476
  placement.truncation_unit = raw.truncation_unit;
473
477
  }
474
- if (typeof raw.truncation_count === "number" && Number.isFinite(raw.truncation_count)) {
478
+ if (typeof raw.truncation_count === "number" && Number.isInteger(raw.truncation_count) && raw.truncation_count > 0) {
475
479
  placement.truncation_count = raw.truncation_count;
476
480
  }
477
481
  if (raw.truncation_style === "cut") {
@@ -504,7 +508,6 @@ function readCustomScenario(scenariosDir, id) {
504
508
  if (typeof raw.name === "string" && raw.name.length > 0) {
505
509
  base.name = raw.name;
506
510
  }
507
- base.placement = parsePlacement(raw);
508
511
  const hostHtmlPath = join(dir, "host.html");
509
512
  if (existsSync(hostHtmlPath)) {
510
513
  try {
@@ -512,6 +515,7 @@ function readCustomScenario(scenariosDir, id) {
512
515
  base.hostHtml = readFileSync(hostHtmlPath, "utf-8");
513
516
  const hostCssPath = join(dir, "host.css");
514
517
  base.hostCss = existsSync(hostCssPath) ? readFileSync(hostCssPath, "utf-8") : "";
518
+ base.placement = parsePlacement(raw);
515
519
  } catch (err) {
516
520
  base.parseError = err instanceof Error ? err.message : "Failed to read scenario host files";
517
521
  return base;
@@ -533,6 +537,12 @@ function scanCustomScenarios(baseDir) {
533
537
  if (!existsSync(join(scenariosDir, entry.name, "scenario.json"))) {
534
538
  continue;
535
539
  }
540
+ if (!isValidScenarioId(entry.name)) {
541
+ console.warn(
542
+ `[allegro-preview] Skipping scenario folder "${entry.name}": name must be a kebab-case slug (lowercase letters, digits, hyphens).`
543
+ );
544
+ continue;
545
+ }
536
546
  const scenario = readCustomScenario(scenariosDir, entry.name);
537
547
  if (scenario.parseError) {
538
548
  console.warn(`[allegro-preview] Skipping scenario "${entry.name}": ${scenario.parseError}`);
@@ -665,7 +675,7 @@ async function startServer(templatePath, port = 0, tenant = "") {
665
675
  const slug = typeof req.query.slug === "string" ? req.query.slug : "";
666
676
  const tab = typeof req.query.tab === "string" ? req.query.tab : "standalone";
667
677
  const sdkParam = typeof req.query.sdk === "string" ? req.query.sdk : void 0;
668
- if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(tab)) {
678
+ if (!isValidScenarioId(tab)) {
669
679
  res.status(404).send("Scenario not found");
670
680
  return;
671
681
  }
package/dist/server.js CHANGED
@@ -25,6 +25,10 @@ window.__ALLEGRO_TEMPLATE_RESOLVER__ = async function (slug) {
25
25
  };`;
26
26
 
27
27
  // src/scenarios.ts
28
+ var SCENARIO_ID_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
29
+ function isValidScenarioId(id) {
30
+ return SCENARIO_ID_PATTERN.test(id);
31
+ }
28
32
  function emptyPlacement() {
29
33
  return {
30
34
  target_selector: null,
@@ -468,7 +472,7 @@ function parsePlacement(raw) {
468
472
  if (raw.truncation_unit === "paragraphs") {
469
473
  placement.truncation_unit = raw.truncation_unit;
470
474
  }
471
- if (typeof raw.truncation_count === "number" && Number.isFinite(raw.truncation_count)) {
475
+ if (typeof raw.truncation_count === "number" && Number.isInteger(raw.truncation_count) && raw.truncation_count > 0) {
472
476
  placement.truncation_count = raw.truncation_count;
473
477
  }
474
478
  if (raw.truncation_style === "cut") {
@@ -501,7 +505,6 @@ function readCustomScenario(scenariosDir, id) {
501
505
  if (typeof raw.name === "string" && raw.name.length > 0) {
502
506
  base.name = raw.name;
503
507
  }
504
- base.placement = parsePlacement(raw);
505
508
  const hostHtmlPath = join(dir, "host.html");
506
509
  if (existsSync(hostHtmlPath)) {
507
510
  try {
@@ -509,6 +512,7 @@ function readCustomScenario(scenariosDir, id) {
509
512
  base.hostHtml = readFileSync(hostHtmlPath, "utf-8");
510
513
  const hostCssPath = join(dir, "host.css");
511
514
  base.hostCss = existsSync(hostCssPath) ? readFileSync(hostCssPath, "utf-8") : "";
515
+ base.placement = parsePlacement(raw);
512
516
  } catch (err) {
513
517
  base.parseError = err instanceof Error ? err.message : "Failed to read scenario host files";
514
518
  return base;
@@ -530,6 +534,12 @@ function scanCustomScenarios(baseDir) {
530
534
  if (!existsSync(join(scenariosDir, entry.name, "scenario.json"))) {
531
535
  continue;
532
536
  }
537
+ if (!isValidScenarioId(entry.name)) {
538
+ console.warn(
539
+ `[allegro-preview] Skipping scenario folder "${entry.name}": name must be a kebab-case slug (lowercase letters, digits, hyphens).`
540
+ );
541
+ continue;
542
+ }
533
543
  const scenario = readCustomScenario(scenariosDir, entry.name);
534
544
  if (scenario.parseError) {
535
545
  console.warn(`[allegro-preview] Skipping scenario "${entry.name}": ${scenario.parseError}`);
@@ -662,7 +672,7 @@ async function startServer(templatePath, port = 0, tenant = "") {
662
672
  const slug = typeof req.query.slug === "string" ? req.query.slug : "";
663
673
  const tab = typeof req.query.tab === "string" ? req.query.tab : "standalone";
664
674
  const sdkParam = typeof req.query.sdk === "string" ? req.query.sdk : void 0;
665
- if (!/^[a-z0-9]+(?:-[a-z0-9]+)*$/.test(tab)) {
675
+ if (!isValidScenarioId(tab)) {
666
676
  res.status(404).send("Scenario not found");
667
677
  return;
668
678
  }
@@ -825,5 +835,8 @@ allegro-preview \u2192 ${url}
825
835
  }
826
836
  export {
827
837
  escapeStyle,
838
+ parsePlacement,
839
+ readCustomScenario,
840
+ scanCustomScenarios,
828
841
  startServer
829
842
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@allegrocdp/preview",
4
- "version": "0.1.0-dev.14",
4
+ "version": "0.1.0-dev.15",
5
5
  "description": "Local dev server for previewing Allegro templates",
6
6
  "type": "module",
7
7
  "bin": {