@nuvler/cli 0.5.17 → 0.5.19

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 (26) hide show
  1. package/dist/api/theme-context.js.map +1 -1
  2. package/dist/commands/theme/create.js +1 -1
  3. package/dist/nuvler.js +10 -1
  4. package/dist/nuvler.js.map +1 -1
  5. package/dist/templates/nuvler-atelier/package.json +2 -2
  6. package/dist/templates/nuvler-default/README.md +4 -4
  7. package/dist/templates/nuvler-default/nuvler.theme.json +1 -1
  8. package/dist/templates/nuvler-default/package.json +2 -2
  9. package/dist/templates/nuvler-default/src/catalog-filters.tsx +169 -0
  10. package/dist/templates/nuvler-default/src/interaction-colors.ts +49 -0
  11. package/dist/templates/nuvler-default/src/kit-composition.ts +15 -0
  12. package/dist/templates/nuvler-default/src/not-found.tsx +288 -21
  13. package/dist/templates/nuvler-default/src/product-detail-interactive.tsx +24 -12
  14. package/dist/templates/nuvler-default/src/server-shell.tsx +21 -3
  15. package/dist/templates/nuvler-default/src/theme-component.tsx +100 -27
  16. package/dist/templates/nuvler-default/src/theme.css +599 -210
  17. package/dist/templates/nuvler-default/src/whatsapp-message.ts +82 -0
  18. package/dist/templates/nuvler-default/test/catalog-filters.test.mjs +44 -0
  19. package/dist/templates/nuvler-default/test/interaction-colors.test.mjs +74 -0
  20. package/dist/templates/nuvler-default/test/kit-composition.test.mjs +28 -0
  21. package/dist/templates/nuvler-default/test/kit-detail.test.mjs +3 -3
  22. package/dist/templates/nuvler-default/test/whatsapp-message.test.mjs +126 -0
  23. package/dist/templates/starter/package.json +2 -2
  24. package/package.json +3 -3
  25. package/preview-host/package.json +1 -1
  26. package/preview-host/vendor/theme-runtime/default-theme.tsx +15 -6
@@ -0,0 +1,82 @@
1
+ import type { ThemeCartItem } from "@nuvler/theme-sdk";
2
+
3
+ export const whatsappRequestLabel = "Enviar solicitação pelo WhatsApp";
4
+ const introduction =
5
+ "Olá! Gostaria de solicitar os itens abaixo. Podem confirmar os valores e a disponibilidade?";
6
+ const money = (value: number) =>
7
+ new Intl.NumberFormat("pt-BR", { style: "currency", currency: "BRL" }).format(
8
+ value,
9
+ );
10
+
11
+ type RequestItem = ThemeCartItem & { quantity?: number };
12
+
13
+ function absoluteProductUrl(
14
+ value: string | undefined,
15
+ storeOrigin?: string,
16
+ ): string | null {
17
+ if (!value) return null;
18
+ try {
19
+ const url = storeOrigin ? new URL(value, storeOrigin) : new URL(value);
20
+ return url.protocol === "https:" || url.protocol === "http:"
21
+ ? url.href
22
+ : null;
23
+ } catch {
24
+ return null;
25
+ }
26
+ }
27
+
28
+ /** Encode the complete message once, preserving its paragraph breaks. */
29
+ export function whatsappRequestUrl(phone: string, message: string): string {
30
+ return `https://wa.me/${phone.replace(/\D/g, "")}?text=${encodeURIComponent(message)}`;
31
+ }
32
+
33
+ /** Formats a quote/request without imposing an order or quotation workflow. */
34
+ export function formatWhatsappRequest(
35
+ items: RequestItem[],
36
+ showPrices = true,
37
+ storeOrigin?: string,
38
+ ): string {
39
+ const products = items.map((item, index) => {
40
+ const quantity = item.quantity ?? 1;
41
+ const lines = [`*${index + 1}. ${item.title}*`, `Quantidade: ${quantity}`];
42
+ if (item.variantName) lines.push(item.variantName);
43
+ if (item.sku) lines.push(`Referência: ${item.sku}`);
44
+ if (showPrices && typeof item.unitPrice === "number") {
45
+ lines.push(`Valor unitário: ${money(item.unitPrice)}`);
46
+ if (quantity > 1)
47
+ lines.push(`Subtotal: ${money(item.unitPrice * quantity)}`);
48
+ }
49
+ if (item.kitGroups?.length) {
50
+ for (const group of item.kitGroups) {
51
+ lines.push(
52
+ `*${group.name} — ${group.quantity} ${group.quantity === 1 ? "unidade" : "unidades"} por combo*`,
53
+ );
54
+ lines.push(
55
+ ...(item.composition ?? [])
56
+ .filter((part) => part.groupId === group.id)
57
+ .map((part) => `• ${part.name}: ${part.quantity}`),
58
+ );
59
+ }
60
+ } else if (item.composition?.length) {
61
+ lines.push(
62
+ ...(item.composition ?? []).map(
63
+ (part) => `• ${part.name}: ${part.quantity}`,
64
+ ),
65
+ );
66
+ }
67
+ const productUrl = absoluteProductUrl(item.productUrl, storeOrigin);
68
+ if (productUrl) lines.push(productUrl);
69
+ return lines.join("\n\n");
70
+ });
71
+ const sections = [introduction, ...products];
72
+ if (
73
+ showPrices &&
74
+ items.length > 0 &&
75
+ items.every((item) => typeof item.unitPrice === "number")
76
+ ) {
77
+ sections.push(
78
+ `*Total estimado: ${money(items.reduce((total, item) => total + item.unitPrice! * (item.quantity ?? 1), 0))}*`,
79
+ );
80
+ }
81
+ return sections.join("\n\n");
82
+ }
@@ -0,0 +1,44 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import { createElement } from "react";
4
+ import { renderToStaticMarkup } from "react-dom/server";
5
+ import { CatalogFilters } from "../dist/src/catalog-filters.js";
6
+
7
+ function render(activeCount = 0) {
8
+ return renderToStaticMarkup(
9
+ createElement(
10
+ CatalogFilters,
11
+ { total: 30, activeCount, resetHref: "/produtos" },
12
+ createElement(
13
+ "form",
14
+ { className: "catalog-filter-form", action: "/produtos" },
15
+ createElement("input", {
16
+ id: "test-search",
17
+ type: "search",
18
+ name: "busca",
19
+ defaultValue: "Coxinha",
20
+ }),
21
+ ),
22
+ ),
23
+ );
24
+ }
25
+ test("mobile filters start closed and keep a single set of inputs for desktop and mobile", () => {
26
+ const html = render();
27
+ assert.match(html, /aria-expanded="false"/);
28
+ assert.doesNotMatch(
29
+ html,
30
+ /aria-modal="true"|role="dialog"|class="catalog-filter-backdrop"/,
31
+ );
32
+ assert.equal((html.match(/id="test-search"/g) ?? []).length, 1);
33
+ assert.match(html, /value="Coxinha"/);
34
+ assert.match(html, /30 produtos/);
35
+ assert.match(html, /Ver resultados/);
36
+ assert.match(html, /href="\/produtos">Limpar/);
37
+ });
38
+ test("filter controls expose the active count and point to the matching panel", () => {
39
+ const html = render(3);
40
+ assert.match(html, /class="catalog-filter-count">3/);
41
+ const controls = html.match(/aria-controls="([^"]+)"/)[1];
42
+ assert.ok(html.includes(`id="${controls}"`));
43
+ assert.match(html, /aria-label="Fechar filtros"/);
44
+ });
@@ -0,0 +1,74 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import { interactionColorVariables } from "../dist/src/interaction-colors.js";
4
+ import { ThemeSiteColorsSchema } from "../../../packages/theme-schema/dist/index.js";
5
+ const base = {
6
+ primary: "#176b3a",
7
+ secondary: "#d99b31",
8
+ background: "#f7f7f2",
9
+ text: "#18221b",
10
+ surface: "#ffffff",
11
+ surfaceAlt: "#f4f7f3",
12
+ textMuted: "#657068",
13
+ border: "#dce3dc",
14
+ };
15
+ test("existing stores retain their search and cart colors", () => {
16
+ const css = interactionColorVariables(base);
17
+ assert.equal(css["--search-background"], base.surface);
18
+ assert.equal(css["--cart-background"], base.surface);
19
+ assert.equal(css["--cart-text"], base.text);
20
+ assert.equal(css["--cart-close-background"], base.background);
21
+ });
22
+ test("component colors remain independent and survive preview validation", () => {
23
+ const colors = ThemeSiteColorsSchema.parse({
24
+ ...base,
25
+ searchBackground: "#000000",
26
+ searchText: "#ffffff",
27
+ searchButtonBackground: "#123456",
28
+ searchButtonText: "#abcdef",
29
+ cartButtonBackground: "#010101",
30
+ cartButtonText: "#fefefe",
31
+ cartBackground: "#222222",
32
+ cartText: "#eeeeee",
33
+ });
34
+ const css = interactionColorVariables(colors);
35
+ assert.equal(css["--search-background"], "#000000");
36
+ assert.equal(css["--cart-background"], "#222222");
37
+ assert.equal(css["--cart-button-background"], "#010101");
38
+ assert.equal(css["--search-button-text"], "#abcdef");
39
+ assert.ok(css["--cart-muted"].includes("#eeeeee"));
40
+ assert.equal(base.surface, "#ffffff");
41
+ });
42
+
43
+ test("collapsed search uses configured button colors and follows header text by default", () => {
44
+ const defaults = interactionColorVariables({
45
+ ...base,
46
+ headerBackground: "#000000",
47
+ headerText: "#ffffff",
48
+ });
49
+ assert.equal(defaults["--search-toggle-background"], "transparent");
50
+ assert.equal(defaults["--search-toggle-text"], "#ffffff");
51
+ const configured = interactionColorVariables({
52
+ ...base,
53
+ searchButtonBackground: "#e2ae40",
54
+ searchButtonText: "#00aaff",
55
+ });
56
+ assert.equal(configured["--search-toggle-background"], "#e2ae40");
57
+ assert.equal(configured["--search-toggle-text"], "#00aaff");
58
+ assert.ok(configured["--search-toggle-hover"].includes("#e2ae40"));
59
+ });
60
+
61
+ test("mobile menu follows header text unless explicitly customized", () => {
62
+ const defaults = interactionColorVariables({ ...base, headerText: "#ffffff" });
63
+ assert.equal(defaults["--mobile-menu-text"], "#ffffff");
64
+ const colors = ThemeSiteColorsSchema.parse({
65
+ ...base,
66
+ headerText: "#ffffff",
67
+ mobileMenuText: "#00aaff",
68
+ });
69
+ const customized = interactionColorVariables(colors);
70
+ assert.equal(customized["--mobile-menu-text"], "#00aaff");
71
+ assert.ok(customized["--mobile-menu-hover"].includes("#00aaff"));
72
+ assert.equal(customized["--cart-button-text"], base.text);
73
+ assert.equal(ThemeSiteColorsSchema.safeParse({ ...base, mobileMenuText: "blue" }).success, false);
74
+ });
@@ -0,0 +1,28 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import { kitCompositionText } from "../dist/src/kit-composition.js";
4
+
5
+ test("default theme shows kit choices without the generated prefix", () => {
6
+ assert.equal(
7
+ kitCompositionText({
8
+ kitSize: 100,
9
+ composition: [
10
+ { variantId: "a", name: "Coxinha", quantity: 40 },
11
+ { variantId: "b", name: "Quibe", quantity: 60 },
12
+ ],
13
+ }),
14
+ "Coxinha: 40; Quibe: 60",
15
+ );
16
+ assert.equal(kitCompositionText({ kitSize: 100 }), "");
17
+ assert.equal(kitCompositionText({}), "");
18
+ });
19
+
20
+ test("independent groups retain their names and separate quantities", () => {
21
+ const result = kitCompositionText({
22
+ kitGroups: [{ id: "drinks", name: "Bebidas", quantity: 2, options: [] }],
23
+ composition: [
24
+ { groupId: "drinks", variantId: "a", name: "Suco", quantity: 2 },
25
+ ],
26
+ });
27
+ assert.equal(result, "Bebidas (2 un. por combo): Suco: 2");
28
+ });
@@ -53,13 +53,13 @@ test("kit starts empty, displays its configured size, blocks checkout and inacti
53
53
  assert.match(html, /Selecionados: 0 de 50 · Faltam: 50/);
54
54
  assert.match(html, /Indisponível/);
55
55
  assert.match(html, /id="kit-b"[^>]*disabled=""/);
56
- assert.match(html, /<button disabled=""[^>]*>Adicionar ao orçamento/);
56
+ assert.match(html, /<button disabled=""[^>]*>Adicionar ao Carrinho/);
57
57
  });
58
58
  test("ordinary variants keep the single selection interface", () => {
59
59
  const html = render({ ...product, kitSize: null });
60
60
  assert.doesNotMatch(html, /kit-selector/);
61
61
  assert.match(html, /variant-selector/);
62
- assert.doesNotMatch(html, /<button disabled=""[^>]*>Adicionar ao orçamento/);
62
+ assert.doesNotMatch(html, /<button disabled=""[^>]*>Adicionar ao Carrinho/);
63
63
  });
64
64
 
65
65
  test("a combo shows three independently counted groups instead of crossed variants", () => {
@@ -81,7 +81,7 @@ test("a combo shows three independently counted groups instead of crossed varian
81
81
  );
82
82
  }
83
83
  assert.doesNotMatch(html, /variant-selector/);
84
- assert.match(html, /<button disabled=""[^>]*>Adicionar ao orçamento/);
84
+ assert.match(html, /<button disabled=""[^>]*>Adicionar ao Carrinho/);
85
85
  });
86
86
 
87
87
  import { KitGroupSelector } from "../dist/src/kit-group-selector.js";
@@ -0,0 +1,126 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import {
4
+ formatWhatsappRequest,
5
+ whatsappRequestLabel,
6
+ whatsappRequestUrl,
7
+ } from "../dist/src/whatsapp-message.js";
8
+
9
+ const combo = {
10
+ productSlug: "combo",
11
+ title: "Combo",
12
+ sku: "",
13
+ quantity: 1,
14
+ unitPrice: 59.9,
15
+ kitGroups: [
16
+ { id: "s", name: "Salgados", quantity: 50, options: [] },
17
+ { id: "b", name: "Bebidas", quantity: 2, options: [] },
18
+ ],
19
+ composition: [
20
+ { groupId: "s", variantId: "a", name: "Kibe", quantity: 20 },
21
+ { groupId: "s", variantId: "c", name: "Coxinha", quantity: 30 },
22
+ { groupId: "b", variantId: "d", name: "Suco", quantity: 2 },
23
+ ],
24
+ };
25
+ const kit = {
26
+ productSlug: "kit",
27
+ title: "Kit 100",
28
+ sku: "",
29
+ unitPrice: 129,
30
+ kitSize: 100,
31
+ composition: [{ variantId: "a", name: "Kibe", quantity: 100 }],
32
+ };
33
+
34
+ test("WhatsApp requests separate products, groups and individual choices with real line breaks", () => {
35
+ const message = formatWhatsappRequest([combo, kit]).replace(/\u00a0/g, " ");
36
+ assert.ok(
37
+ message.startsWith(
38
+ "Olá! Gostaria de solicitar os itens abaixo. Podem confirmar os valores e a disponibilidade?\n\n",
39
+ ),
40
+ );
41
+ assert.ok(
42
+ message.includes(
43
+ "*Salgados — 50 unidades por combo*\n\n• Kibe: 20\n\n• Coxinha: 30\n\n*Bebidas — 2 unidades por combo*\n\n• Suco: 2",
44
+ ),
45
+ );
46
+ assert.ok(message.includes("\n\n*2. Kit 100*\n"));
47
+ assert.ok(message.endsWith("*Total estimado: R$ 188,90*"));
48
+ assert.doesNotMatch(message, /Composição por kit|orçamento|; /);
49
+ assert.equal(whatsappRequestLabel, "Enviar solicitação pelo WhatsApp");
50
+ assert.equal(decodeURIComponent(encodeURIComponent(message)), message);
51
+ });
52
+
53
+ test("multiple quantities affect subtotals and the total, without multiplying per-combo choices", () => {
54
+ const message = formatWhatsappRequest([{ ...combo, quantity: 2 }]).replace(
55
+ /\u00a0/g,
56
+ " ",
57
+ );
58
+ assert.ok(
59
+ message.includes(
60
+ "Quantidade: 2\n\nValor unitário: R$ 59,90\n\nSubtotal: R$ 119,80",
61
+ ),
62
+ );
63
+ assert.ok(message.includes("• Kibe: 20"));
64
+ assert.ok(message.endsWith("*Total estimado: R$ 119,80*"));
65
+ });
66
+
67
+ test("hidden and incomplete prices never generate a misleading total", () => {
68
+ assert.doesNotMatch(
69
+ formatWhatsappRequest([combo, kit], false),
70
+ /R\$|Valor unitário|Subtotal|Total estimado/,
71
+ );
72
+ assert.doesNotMatch(
73
+ formatWhatsappRequest([combo, { ...kit, unitPrice: null }]),
74
+ /Total estimado/,
75
+ );
76
+ const ordinary = formatWhatsappRequest([
77
+ {
78
+ productSlug: "p",
79
+ title: "Produto",
80
+ sku: "ABC",
81
+ variantName: "Cor: Azul",
82
+ productUrl: "https://example.com/p",
83
+ },
84
+ ]);
85
+ assert.ok(ordinary.includes("Cor: Azul\n\nReferência: ABC"));
86
+ assert.ok(ordinary.endsWith("https://example.com/p"));
87
+ });
88
+
89
+ test("WhatsApp URLs preserve paragraph breaks, formatting, accents and special characters", () => {
90
+ const message = formatWhatsappRequest(
91
+ [
92
+ {
93
+ ...combo,
94
+ title: "Combo & opções + queijo",
95
+ productUrl: "/combos/combo",
96
+ },
97
+ ],
98
+ true,
99
+ "https://loja.example",
100
+ );
101
+ const href = whatsappRequestUrl("+55 (11) 99999-9999", message);
102
+ const url = new URL(href);
103
+ assert.equal(url.pathname, "/5511999999999");
104
+ assert.equal(url.searchParams.get("text"), message);
105
+ assert.ok(href.includes("%0A%0A"));
106
+ assert.ok(message.includes("https://loja.example/combos/combo"));
107
+ assert.doesNotMatch(message, /[^\n]\n[^\n]/);
108
+ });
109
+
110
+ test("relative product links use the current store origin and invalid links are omitted", () => {
111
+ assert.ok(
112
+ formatWhatsappRequest(
113
+ [{ ...kit, productUrl: "/salgados/kit" }],
114
+ true,
115
+ "https://outraloja.example",
116
+ ).includes("https://outraloja.example/salgados/kit"),
117
+ );
118
+ assert.doesNotMatch(
119
+ formatWhatsappRequest([{ ...kit, productUrl: "/salgados/kit" }]),
120
+ /\/salgados\/kit/,
121
+ );
122
+ assert.doesNotMatch(
123
+ formatWhatsappRequest([{ ...kit, productUrl: "javascript:alert(1)" }]),
124
+ /javascript:/,
125
+ );
126
+ });
@@ -13,13 +13,13 @@
13
13
  "typecheck": "tsc -p tsconfig.json --noEmit"
14
14
  },
15
15
  "dependencies": {
16
- "@nuvler/theme-sdk": "^1.4.7"
16
+ "@nuvler/theme-sdk": "^1.4.9"
17
17
  },
18
18
  "peerDependencies": {
19
19
  "react": "^19.0.0"
20
20
  },
21
21
  "devDependencies": {
22
- "@nuvler/cli": "^0.5.17",
22
+ "@nuvler/cli": "^0.5.19",
23
23
  "@types/react": "^19.0.0",
24
24
  "react": "^19.0.0",
25
25
  "typescript": "^5.9.0"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuvler/cli",
3
- "version": "0.5.17",
3
+ "version": "0.5.19",
4
4
  "description": "CLI oficial para criação, validação, preview e empacotamento de temas Nuvler",
5
5
  "type": "module",
6
6
  "bin": {
@@ -20,8 +20,8 @@
20
20
  "typecheck": "tsc -p tsconfig.json --noEmit"
21
21
  },
22
22
  "dependencies": {
23
- "@nuvler/theme-schema": "^1.4.5",
24
- "@nuvler/theme-sdk": "^1.4.7",
23
+ "@nuvler/theme-schema": "^1.4.6",
24
+ "@nuvler/theme-sdk": "^1.4.9",
25
25
  "@vitejs/plugin-react": "^6.0.5",
26
26
  "commander": "^15.0.0",
27
27
  "react": "19.2.8",
@@ -10,7 +10,7 @@
10
10
  "typecheck": "tsc -p tsconfig.json --noEmit"
11
11
  },
12
12
  "dependencies": {
13
- "@nuvler/theme-sdk": "^1.4.3",
13
+ "@nuvler/theme-sdk": "^1.4.8",
14
14
  "react": "19.2.8",
15
15
  "react-dom": "19.2.8"
16
16
  },
@@ -20,7 +20,7 @@ import type {
20
20
  ThemeRuntimeSdk,
21
21
  ThemeSiteColors,
22
22
  } from "@nuvler/theme-sdk";
23
- import { htmlToPlainText, productUrl } from "@nuvler/theme-sdk";
23
+ import { htmlToPlainText, notFoundCopy, productUrl } from "@nuvler/theme-sdk";
24
24
  import type { DefaultThemeProps, ThemeRuntimeAdapters } from "./index.js";
25
25
  import type { ThemeRoute } from "./index.js";
26
26
 
@@ -1969,14 +1969,16 @@ function ProductPage({
1969
1969
  }
1970
1970
 
1971
1971
  /** Fallback seguro para consumidores que usam um tema sem componente NotFound. */
1972
- export function DefaultNotFound({ homeHref = "/" }: NotFoundProps) {
1972
+ export function DefaultNotFound({ homeHref = "/", resource }: NotFoundProps) {
1973
+ const copy = notFoundCopy(resource, homeHref);
1973
1974
  return (
1974
1975
  <main className="not-found-page">
1975
1976
  <div className="not-found-card">
1976
1977
  <span>404</span>
1977
- <h1>Conteúdo não encontrado</h1>
1978
- <a className="button button-primary" href={homeHref}>
1979
- Voltar ao início
1978
+ <h1>{copy.title}</h1>
1979
+ <p>{copy.description}</p>
1980
+ <a className="button button-primary" href={copy.action.href}>
1981
+ {copy.action.label}
1980
1982
  </a>
1981
1983
  </div>
1982
1984
  </main>
@@ -2006,7 +2008,14 @@ function RouteContent({
2006
2008
  </div>
2007
2009
  </main>
2008
2010
  );
2009
- if (route.type === "not-found") return <DefaultNotFound homeHref="/" />;
2011
+ if (route.type === "not-found")
2012
+ return (
2013
+ <DefaultNotFound
2014
+ homeHref="/"
2015
+ resource={route.resource}
2016
+ pathname={route.pathname}
2017
+ />
2018
+ );
2010
2019
  if (route.type === "catalog")
2011
2020
  return <CatalogPage adapters={adapters} context={context} route={route} />;
2012
2021
  if (route.type === "product")