@nuvler/cli 0.5.16 → 0.5.18

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 (32) hide show
  1. package/dist/api/theme-context.js +2 -0
  2. package/dist/api/theme-context.js.map +1 -1
  3. package/dist/commands/theme/create.js +1 -1
  4. package/dist/nuvler.js +24 -1
  5. package/dist/nuvler.js.map +1 -1
  6. package/dist/templates/nuvler-atelier/package.json +2 -2
  7. package/dist/templates/nuvler-default/README.md +4 -4
  8. package/dist/templates/nuvler-default/nuvler.theme.json +1 -1
  9. package/dist/templates/nuvler-default/package.json +2 -2
  10. package/dist/templates/nuvler-default/src/catalog-filters.tsx +169 -0
  11. package/dist/templates/nuvler-default/src/contact-form.tsx +172 -0
  12. package/dist/templates/nuvler-default/src/home-data.ts +30 -0
  13. package/dist/templates/nuvler-default/src/home.tsx +2 -196
  14. package/dist/templates/nuvler-default/src/interaction-colors.ts +49 -0
  15. package/dist/templates/nuvler-default/src/kit-composition.ts +15 -0
  16. package/dist/templates/nuvler-default/src/kit-group-selector.tsx +230 -0
  17. package/dist/templates/nuvler-default/src/kit-selection.ts +39 -0
  18. package/dist/templates/nuvler-default/src/product-detail-interactive.tsx +420 -115
  19. package/dist/templates/nuvler-default/src/product-detail.tsx +141 -59
  20. package/dist/templates/nuvler-default/src/products.tsx +143 -12
  21. package/dist/templates/nuvler-default/src/server-shell.tsx +21 -3
  22. package/dist/templates/nuvler-default/src/theme-component.tsx +85 -24
  23. package/dist/templates/nuvler-default/src/theme.css +673 -6
  24. package/dist/templates/nuvler-default/src/whatsapp-message.ts +82 -0
  25. package/dist/templates/nuvler-default/test/catalog-filters.test.mjs +44 -0
  26. package/dist/templates/nuvler-default/test/interaction-colors.test.mjs +74 -0
  27. package/dist/templates/nuvler-default/test/kit-composition.test.mjs +28 -0
  28. package/dist/templates/nuvler-default/test/kit-detail.test.mjs +292 -0
  29. package/dist/templates/nuvler-default/test/whatsapp-message.test.mjs +126 -0
  30. package/dist/templates/starter/package.json +2 -2
  31. package/package.json +3 -3
  32. package/preview-host/package.json +1 -1
@@ -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
+ });
@@ -0,0 +1,292 @@
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 { ProductDetailInteractive } from "../dist/src/product-detail-interactive.js";
6
+
7
+ const product = {
8
+ slug: "kit-50",
9
+ title: "Kit 50",
10
+ sku: "KIT",
11
+ price: 80,
12
+ promotionalPrice: null,
13
+ stockQuantity: null,
14
+ kitSize: 50,
15
+ image: null,
16
+ images: [],
17
+ variantOptions: [{ name: "Sabor", values: ["Frango", "Queijo"] }],
18
+ variants: [
19
+ {
20
+ id: "a",
21
+ name: "Frango",
22
+ sku: "",
23
+ active: true,
24
+ image: null,
25
+ values: [{ name: "Sabor", value: "Frango" }],
26
+ },
27
+ {
28
+ id: "b",
29
+ name: "Queijo",
30
+ sku: "",
31
+ active: false,
32
+ image: null,
33
+ values: [{ name: "Sabor", value: "Queijo" }],
34
+ },
35
+ ],
36
+ };
37
+ function render(value) {
38
+ return renderToStaticMarkup(
39
+ createElement(ProductDetailInteractive, {
40
+ product: value,
41
+ onAddToCart() {},
42
+ information: null,
43
+ benefits: null,
44
+ galleryImages: null,
45
+ galleryThumbnails: null,
46
+ }),
47
+ );
48
+ }
49
+ test("kit starts empty, displays its configured size, blocks checkout and inactive flavors", () => {
50
+ const html = render(product);
51
+ assert.match(html, /Monte seu kit/);
52
+ assert.match(html, /50 unidades/);
53
+ assert.match(html, /Selecionados: 0 de 50 · Faltam: 50/);
54
+ assert.match(html, /Indisponível/);
55
+ assert.match(html, /id="kit-b"[^>]*disabled=""/);
56
+ assert.match(html, /<button disabled=""[^>]*>Adicionar ao Carrinho/);
57
+ });
58
+ test("ordinary variants keep the single selection interface", () => {
59
+ const html = render({ ...product, kitSize: null });
60
+ assert.doesNotMatch(html, /kit-selector/);
61
+ assert.match(html, /variant-selector/);
62
+ assert.doesNotMatch(html, /<button disabled=""[^>]*>Adicionar ao Carrinho/);
63
+ });
64
+
65
+ test("a combo shows three independently counted groups instead of crossed variants", () => {
66
+ const groups = [
67
+ { id: "snacks", name: "Salgados", quantity: 50 },
68
+ { id: "drinks", name: "Bebidas", quantity: 1 },
69
+ { id: "desserts", name: "Churros", quantity: 20 },
70
+ ].map((group) => ({
71
+ ...group,
72
+ options: [{ id: "a", name: `${group.name} opção`, active: true }],
73
+ }));
74
+ const html = render({ ...product, kitSize: null, kitGroups: groups });
75
+ for (const group of groups) {
76
+ assert.ok(html.includes(`Montagem: ${group.name}`));
77
+ assert.ok(
78
+ html.includes(
79
+ `Selecionados: 0 de ${group.quantity} · Faltam: ${group.quantity}`,
80
+ ),
81
+ );
82
+ }
83
+ assert.doesNotMatch(html, /variant-selector/);
84
+ assert.match(html, /<button disabled=""[^>]*>Adicionar ao Carrinho/);
85
+ });
86
+
87
+ import { KitGroupSelector } from "../dist/src/kit-group-selector.js";
88
+
89
+ test("quantity shortcuts update only their group and remain usable for redistribution", () => {
90
+ const snacks = {
91
+ id: "snacks",
92
+ name: "Salgados",
93
+ quantity: 50,
94
+ options: [{ id: "same", name: "Coxinha", active: true }],
95
+ };
96
+ const drinks = {
97
+ id: "drinks",
98
+ name: "Bebidas",
99
+ quantity: 1,
100
+ options: [{ id: "same", name: "Suco", active: true }],
101
+ };
102
+ const snackKey = JSON.stringify([snacks.id, "same"]);
103
+ const drinkKey = JSON.stringify([drinks.id, "same"]);
104
+ let quantities = { [snackKey]: "50", [drinkKey]: "1" };
105
+ const renderGroup = (group) =>
106
+ KitGroupSelector({
107
+ group,
108
+ grouped: true,
109
+ quantities,
110
+ setQuantities: (update) => {
111
+ quantities = typeof update === "function" ? update(quantities) : update;
112
+ },
113
+ });
114
+ const nodes = (element) =>
115
+ !element || typeof element !== "object"
116
+ ? []
117
+ : Array.isArray(element)
118
+ ? element.flatMap(nodes)
119
+ : [element, ...nodes(element.props?.children)];
120
+ const button = (group, label) =>
121
+ nodes(renderGroup(group)).find(
122
+ (element) =>
123
+ element.type === "button" && element.props["aria-label"] === label,
124
+ );
125
+ assert.equal(button(snacks, "Adicionar 5 de Coxinha").props.disabled, true);
126
+ assert.equal(button(snacks, "Retirar 15 de Coxinha").props.disabled, false);
127
+ button(snacks, "Retirar 15 de Coxinha").props.onClick();
128
+ assert.equal(quantities[snackKey], "35");
129
+ assert.equal(quantities[drinkKey], "1");
130
+ assert.equal(button(snacks, "Adicionar 15 de Coxinha").props.disabled, false);
131
+ button(snacks, "Adicionar 15 de Coxinha").props.onClick();
132
+ assert.equal(quantities[snackKey], "50");
133
+ assert.equal(button(drinks, "Retirar 5 de Suco"), undefined);
134
+ assert.equal(button(drinks, "Aumentar Suco").props.disabled, true);
135
+ const html = renderToStaticMarkup(renderGroup(drinks));
136
+ assert.match(html, /Selecionados: 1 de 1 · Faltam: 0/);
137
+ });
138
+
139
+ test("group images appear beside the group heading and remain optional", () => {
140
+ const group = {
141
+ id: "snacks",
142
+ name: "Salgados",
143
+ quantity: 50,
144
+ image: {
145
+ url: "https://example.com/snacks.jpg",
146
+ alt: "Seleção de salgados",
147
+ width: 800,
148
+ height: 600,
149
+ },
150
+ options: [{ id: "a", name: "Coxinha", active: true }],
151
+ };
152
+ const renderGroup = (value) =>
153
+ renderToStaticMarkup(
154
+ createElement(KitGroupSelector, {
155
+ group: value,
156
+ grouped: true,
157
+ quantities: {},
158
+ setQuantities() {},
159
+ }),
160
+ );
161
+ const html = renderGroup(group);
162
+ assert.match(html, /class="kit-group-image"/);
163
+ assert.match(html, /alt="Seleção de salgados"/);
164
+ assert.match(html, /src="https:\/\/example.com\/snacks.jpg"/);
165
+ assert.doesNotMatch(
166
+ renderGroup({ ...group, image: null }),
167
+ /kit-group-image/,
168
+ );
169
+ });
170
+
171
+ test("only the first combo group starts expanded and the purchase area reports all pending groups", () => {
172
+ const groups = [
173
+ { id: "s", name: "Salgados", quantity: 50 },
174
+ { id: "b", name: "Bebidas", quantity: 2 },
175
+ { id: "c", name: "Churros", quantity: 20 },
176
+ ].map((group) => ({
177
+ ...group,
178
+ options: [{ id: "a", name: "Opção", active: true }],
179
+ }));
180
+ const html = render({ ...product, kitSize: null, kitGroups: groups });
181
+ const headers = html.match(/<details\b[^>]*>/g) ?? [];
182
+ assert.equal(headers.length, 3);
183
+ assert.match(headers[0], /\bopen=""/);
184
+ assert.doesNotMatch(headers[1], /\bopen=/);
185
+ assert.doesNotMatch(headers[2], /\bopen=/);
186
+ assert.match(html, /0 de 3 grupos completos/);
187
+ for (const group of groups)
188
+ assert.ok(html.includes(`${group.name}: 0/${group.quantity}`));
189
+ assert.doesNotMatch(
190
+ render({ ...product, kitGroups: undefined }),
191
+ /kit-group-accordion/,
192
+ );
193
+ });
194
+
195
+ test("small groups hide unsuitable shortcuts and collapsed headers retain selection summaries", () => {
196
+ const group = {
197
+ id: "drinks",
198
+ name: "Bebidas",
199
+ quantity: 2,
200
+ options: [
201
+ { id: "a", name: "Coca-Cola", active: true },
202
+ { id: "b", name: "Suco", active: true },
203
+ ],
204
+ };
205
+ const quantities = {
206
+ [JSON.stringify([group.id, "a"])]: "1",
207
+ [JSON.stringify([group.id, "b"])]: "1",
208
+ };
209
+ const html = renderToStaticMarkup(
210
+ createElement(KitGroupSelector, {
211
+ group,
212
+ grouped: true,
213
+ initiallyOpen: false,
214
+ quantities,
215
+ setQuantities() {},
216
+ }),
217
+ );
218
+ assert.doesNotMatch(html, /<details[^>]*\bopen=/);
219
+ assert.doesNotMatch(html, /class="kit-shortcuts"/);
220
+ assert.match(html, /1 × Coca-Cola · 1 × Suco/);
221
+ assert.match(html, /data-complete="true"/);
222
+ assert.match(html, /Completo/);
223
+ const limited = renderToStaticMarkup(
224
+ createElement(KitGroupSelector, {
225
+ group: { ...group, quantity: 8 },
226
+ grouped: true,
227
+ quantities: {},
228
+ setQuantities() {},
229
+ }),
230
+ );
231
+ assert.match(limited, /Adicionar 5 de Coca-Cola/);
232
+ assert.doesNotMatch(
233
+ limited,
234
+ /Adicionar 10|Adicionar 15|Retirar 10|Retirar 15/,
235
+ );
236
+ });
237
+
238
+ import { getKitGroupSelection } from "../dist/src/kit-selection.js";
239
+
240
+ test("a group's completion status rejects overflow, invalid input and inactive selections", () => {
241
+ const group = {
242
+ id: "drinks",
243
+ name: "Bebidas",
244
+ quantity: 2,
245
+ options: [
246
+ { id: "a", name: "Suco", active: true },
247
+ { id: "b", name: "Refrigerante", active: false },
248
+ ],
249
+ };
250
+ const key = JSON.stringify([group.id, "a"]);
251
+ assert.equal(
252
+ getKitGroupSelection(group, true, { [key]: "2" }).complete,
253
+ true,
254
+ );
255
+ for (const raw of ["", "1", "3", "1.5", "-1"])
256
+ assert.equal(
257
+ getKitGroupSelection(group, true, { [key]: raw }).complete,
258
+ false,
259
+ );
260
+ assert.equal(
261
+ getKitGroupSelection(group, true, {
262
+ [JSON.stringify([group.id, "b"])]: "2",
263
+ }).complete,
264
+ false,
265
+ );
266
+ });
267
+
268
+ import { ProductDetail } from "../dist/src/product-detail.js";
269
+ import { isValidElement } from "react";
270
+
271
+ test("server-rendered information slots carry stable keys across the client boundary", () => {
272
+ const detail = ProductDetail({
273
+ product: {
274
+ ...product,
275
+ categories: [{ name: "Salgados" }],
276
+ brand: "Alice",
277
+ model: "Festa",
278
+ ean: "123",
279
+ stockQuantity: 10,
280
+ sku: "KIT",
281
+ },
282
+ descriptionContent: "Descrição",
283
+ });
284
+ const children =
285
+ detail.props.information.props.children.filter(isValidElement);
286
+ assert.ok(children.length >= 6);
287
+ assert.ok(children.every((child) => child.key !== null));
288
+ assert.equal(
289
+ new Set(children.map((child) => child.key)).size,
290
+ children.length,
291
+ );
292
+ });
@@ -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.3"
16
+ "@nuvler/theme-sdk": "^1.4.8"
17
17
  },
18
18
  "peerDependencies": {
19
19
  "react": "^19.0.0"
20
20
  },
21
21
  "devDependencies": {
22
- "@nuvler/cli": "^0.5.13",
22
+ "@nuvler/cli": "^0.5.18",
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.16",
3
+ "version": "0.5.18",
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.4",
24
- "@nuvler/theme-sdk": "^1.4.6",
23
+ "@nuvler/theme-schema": "^1.4.6",
24
+ "@nuvler/theme-sdk": "^1.4.8",
25
25
  "@vitejs/plugin-react": "^6.0.5",
26
26
  "commander": "^15.0.0",
27
27
  "react": "19.2.8",