@vtex-email/vtex 0.3.0 → 0.4.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/capabilities.d.ts.map +1 -1
- package/dist/index.js +79 -34
- package/dist/simulator.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../src/capabilities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAIvD,eAAO,MAAM,qBAAqB,EAAE,
|
|
1
|
+
{"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../src/capabilities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAIvD,eAAO,MAAM,qBAAqB,EAAE,eA+KnC,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -7,52 +7,70 @@ var messageCenterEmission = {
|
|
|
7
7
|
{
|
|
8
8
|
name: "each",
|
|
9
9
|
form: "block",
|
|
10
|
-
evidence: "
|
|
11
|
-
note: "Native Handlebars helper. The item context replaces the current context. The fallback uses the outer context.",
|
|
10
|
+
evidence: "verified",
|
|
11
|
+
note: "Native Handlebars helper. The item context replaces the current context. The fallback uses the outer context. Verified on Message Center.",
|
|
12
12
|
context: "item",
|
|
13
13
|
elseContext: "outer"
|
|
14
14
|
},
|
|
15
15
|
{
|
|
16
16
|
name: "if",
|
|
17
17
|
form: "block",
|
|
18
|
-
evidence: "
|
|
19
|
-
note: "Handlebars truthiness. 0, an empty string, and an empty array are false. The toolchain does not use Boolean(). Both branches keep the current context.",
|
|
18
|
+
evidence: "verified",
|
|
19
|
+
note: "Handlebars truthiness. 0, an empty string, and an empty array are false. The toolchain does not use Boolean(). Both branches keep the current context. Verified on Message Center.",
|
|
20
20
|
context: "preserve",
|
|
21
21
|
elseContext: "preserve"
|
|
22
22
|
},
|
|
23
23
|
{
|
|
24
24
|
name: "unless",
|
|
25
25
|
form: "block",
|
|
26
|
-
evidence: "
|
|
27
|
-
note: "Negation of if. Both branches keep the current context.",
|
|
26
|
+
evidence: "verified",
|
|
27
|
+
note: "Negation of if. Both branches keep the current context. Verified on Message Center for a falsy path showing the positive branch.",
|
|
28
28
|
context: "preserve",
|
|
29
29
|
elseContext: "preserve"
|
|
30
30
|
},
|
|
31
31
|
{
|
|
32
32
|
name: "../",
|
|
33
33
|
form: "path",
|
|
34
|
-
evidence: "
|
|
35
|
-
note: "Parent segment documented by Handlebars. A path cannot climb above the template root."
|
|
34
|
+
evidence: "verified",
|
|
35
|
+
note: "Parent segment documented by Handlebars. A path cannot climb above the template root. Verified on Message Center in nested item and estimate paths."
|
|
36
36
|
},
|
|
37
37
|
{
|
|
38
38
|
name: "@index",
|
|
39
39
|
form: "path",
|
|
40
|
-
evidence: "
|
|
41
|
-
note: "Zero-based index inside each. Not available in group.
|
|
40
|
+
evidence: "verified",
|
|
41
|
+
note: "Zero-based index inside each. Not available in group. Verified on Message Center with eq and ifCond against @index."
|
|
42
42
|
},
|
|
43
43
|
{
|
|
44
44
|
name: "formatCurrency",
|
|
45
45
|
form: "inline",
|
|
46
|
-
evidence: "
|
|
47
|
-
note: "
|
|
46
|
+
evidence: "verified",
|
|
47
|
+
note: "Cents to decimal without a symbol. Message Center verified pairs include 24000, 24500, 500, 196500, and 197000.",
|
|
48
48
|
arity: { min: 1, max: 1 },
|
|
49
49
|
args: ["path"]
|
|
50
50
|
},
|
|
51
51
|
{
|
|
52
|
-
name: "
|
|
52
|
+
name: "formatDiscount",
|
|
53
53
|
form: "inline",
|
|
54
54
|
evidence: "experimental",
|
|
55
|
-
note: "
|
|
55
|
+
note: "Cents to decimal without a symbol and without the sign (-1500 prints 15,00). Project-local helper; not verified on Message Center.",
|
|
56
|
+
arity: { min: 1, max: 1 },
|
|
57
|
+
args: ["path"]
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: "eval",
|
|
61
|
+
form: "inline",
|
|
62
|
+
emit: "empty-block",
|
|
63
|
+
evidence: "experimental",
|
|
64
|
+
note: 'Emitted as {{#eval "code" name=path}}{{/eval}}. The destination replaces each ${name} in the code with the named argument and prints the result of evaluating it, unescaped. The local simulator runs the code in an isolated VM context. Not verified on Message Center.',
|
|
65
|
+
arity: { min: 1, max: 1 },
|
|
66
|
+
args: ["literal"],
|
|
67
|
+
freeHash: "expression"
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
name: "formatDate",
|
|
71
|
+
form: "inline",
|
|
72
|
+
evidence: "verified",
|
|
73
|
+
note: "dd/MM/yyyy from a Date-parseable path. Verified on Message Center for shippingEstimateDate when deliveryWindow is absent. Timezone follows the host Date.",
|
|
56
74
|
arity: { min: 1, max: 1 },
|
|
57
75
|
args: ["path"]
|
|
58
76
|
},
|
|
@@ -83,8 +101,8 @@ var messageCenterEmission = {
|
|
|
83
101
|
{
|
|
84
102
|
name: "eq",
|
|
85
103
|
form: "block",
|
|
86
|
-
evidence: "
|
|
87
|
-
note: "Strict equality. Path versus path or path versus literal. Both branches keep context.
|
|
104
|
+
evidence: "verified",
|
|
105
|
+
note: "Strict equality. Path versus path or path versus literal. Both branches keep context. Verified on Message Center for locale merge (pt-BR), installments 1, totals Items/Shipping, and address or item match.",
|
|
88
106
|
arity: { min: 1, max: 1 },
|
|
89
107
|
args: ["expression"],
|
|
90
108
|
context: "preserve",
|
|
@@ -93,8 +111,8 @@ var messageCenterEmission = {
|
|
|
93
111
|
{
|
|
94
112
|
name: "ifCond",
|
|
95
113
|
form: "block",
|
|
96
|
-
evidence: "
|
|
97
|
-
note: "Compares a path to a path or literal with ==, ===, !=, <, <=, >, or >=. Unknown operators fail at compile time. Both branches keep context.
|
|
114
|
+
evidence: "verified",
|
|
115
|
+
note: "Compares a path to a path or literal with ==, ===, !=, <, <=, >, or >=. Unknown operators fail at compile time. Both branches keep context. Verified on Message Center for == and !=. Other operators remain unexercised in those runs.",
|
|
98
116
|
arity: { min: 2, max: 2 },
|
|
99
117
|
args: ["literal", "expression"],
|
|
100
118
|
literals: [{ index: 0, values: comparisonOperators }],
|
|
@@ -114,8 +132,8 @@ var messageCenterEmission = {
|
|
|
114
132
|
{
|
|
115
133
|
name: "group",
|
|
116
134
|
form: "block",
|
|
117
|
-
evidence: "
|
|
118
|
-
note: "Groups an array by a hash by identifier. The item context is { index, value, items }. Empty or missing lists use the outer fallback. Does not invent keys.
|
|
135
|
+
evidence: "verified",
|
|
136
|
+
note: "Groups an array by a hash by identifier. The item context is { index, value, items }. Empty or missing lists use the outer fallback. Does not invent keys. Verified on Message Center with by=packageId and by=addressId.",
|
|
119
137
|
hash: [{ name: "by", kind: "literal" }],
|
|
120
138
|
context: "item",
|
|
121
139
|
elseContext: "outer"
|
|
@@ -151,8 +169,8 @@ var messageCenterEmission = {
|
|
|
151
169
|
{
|
|
152
170
|
name: "richShippingData",
|
|
153
171
|
form: "block",
|
|
154
|
-
evidence: "
|
|
155
|
-
note: "Clones shippingData, selects the SLA matching selectedSla, derives packageId and estimate fields on logisticsInfo, then renders with shippingData as the current context. Does not mutate the fixture.
|
|
172
|
+
evidence: "verified",
|
|
173
|
+
note: "Clones shippingData, selects the SLA matching selectedSla, derives packageId and estimate fields on logisticsInfo, then renders with shippingData as the current context. Does not mutate the fixture. Verified on Message Center.",
|
|
156
174
|
context: "item",
|
|
157
175
|
elseContext: "outer"
|
|
158
176
|
}
|
|
@@ -160,6 +178,7 @@ var messageCenterEmission = {
|
|
|
160
178
|
};
|
|
161
179
|
|
|
162
180
|
// src/simulator.ts
|
|
181
|
+
import { runInNewContext } from "node:vm";
|
|
163
182
|
function formatCurrency(value) {
|
|
164
183
|
if (typeof value !== "number" || !Number.isInteger(value)) {
|
|
165
184
|
throw new Error("formatCurrency: the local simulator expects integer cents.");
|
|
@@ -170,6 +189,18 @@ function formatCurrency(value) {
|
|
|
170
189
|
const cents = String(absolute % 100).padStart(2, "0");
|
|
171
190
|
return `${sign}${units},${cents}`;
|
|
172
191
|
}
|
|
192
|
+
function formatDiscount(value) {
|
|
193
|
+
const number = typeof value === "number" ? value : Number.NaN;
|
|
194
|
+
const cents = Number.isNaN(number) ? 0 : Math.abs(number);
|
|
195
|
+
return (cents / 100).toFixed(2).replace(".", ",");
|
|
196
|
+
}
|
|
197
|
+
var evalVariable = /\$\{(\S+?)\}/g;
|
|
198
|
+
function evaluateCode(code, hash) {
|
|
199
|
+
if (typeof code !== "string") throw new Error("eval: the local simulator expects a code string.");
|
|
200
|
+
const compiled = code.replace(evalVariable, (_match, name) => String(hash[name] ?? ""));
|
|
201
|
+
const result = runInNewContext(compiled, /* @__PURE__ */ Object.create(null), { timeout: 100 });
|
|
202
|
+
return result == null ? "" : String(result);
|
|
203
|
+
}
|
|
173
204
|
function parseDate(value, helper) {
|
|
174
205
|
const date = value instanceof Date ? value : new Date(String(value ?? ""));
|
|
175
206
|
if (Number.isNaN(date.getTime())) {
|
|
@@ -289,15 +320,29 @@ var messageCenterSimulator = {
|
|
|
289
320
|
{
|
|
290
321
|
name: "formatCurrency",
|
|
291
322
|
kind: "inline",
|
|
292
|
-
evidence: "
|
|
293
|
-
note: "
|
|
323
|
+
evidence: "verified",
|
|
324
|
+
note: "Cents to decimal without a symbol. Message Center verified pairs include 24000, 24500, 500, 196500, and 197000.",
|
|
294
325
|
apply: formatCurrency
|
|
295
326
|
},
|
|
296
327
|
{
|
|
297
|
-
name: "
|
|
328
|
+
name: "formatDiscount",
|
|
298
329
|
kind: "inline",
|
|
299
330
|
evidence: "experimental",
|
|
300
|
-
note: "Local
|
|
331
|
+
note: "Local cents to decimal without sign. Not verified on VTEX.",
|
|
332
|
+
apply: formatDiscount
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
name: "eval",
|
|
336
|
+
kind: "block",
|
|
337
|
+
evidence: "experimental",
|
|
338
|
+
note: "Local evaluation in an isolated VM context after ${name} replacement. Not verified on VTEX.",
|
|
339
|
+
apply: (_context, values, options) => evaluateCode(values[0], options.hash)
|
|
340
|
+
},
|
|
341
|
+
{
|
|
342
|
+
name: "formatDate",
|
|
343
|
+
kind: "inline",
|
|
344
|
+
evidence: "verified",
|
|
345
|
+
note: "dd/MM/yyyy. Verified on Message Center for shippingEstimateDate when deliveryWindow is absent.",
|
|
301
346
|
apply: formatDate
|
|
302
347
|
},
|
|
303
348
|
{
|
|
@@ -331,8 +376,8 @@ var messageCenterSimulator = {
|
|
|
331
376
|
{
|
|
332
377
|
name: "eq",
|
|
333
378
|
kind: "block",
|
|
334
|
-
evidence: "
|
|
335
|
-
note: "
|
|
379
|
+
evidence: "verified",
|
|
380
|
+
note: "Strict equality. Verified on Message Center for locale merge, installments, totals, and item match.",
|
|
336
381
|
apply: (context, values, options) => {
|
|
337
382
|
const [left, right] = values;
|
|
338
383
|
return left === right ? options.fn(context) : options.inverse(context);
|
|
@@ -341,8 +386,8 @@ var messageCenterSimulator = {
|
|
|
341
386
|
{
|
|
342
387
|
name: "ifCond",
|
|
343
388
|
kind: "block",
|
|
344
|
-
evidence: "
|
|
345
|
-
note: "
|
|
389
|
+
evidence: "verified",
|
|
390
|
+
note: "Verified on Message Center for == and !=. Other operators remain unexercised in those runs.",
|
|
346
391
|
apply: (context, values, options) => {
|
|
347
392
|
const [left, operator, right] = values;
|
|
348
393
|
const pass = compareValues(left, operator, right);
|
|
@@ -364,8 +409,8 @@ var messageCenterSimulator = {
|
|
|
364
409
|
{
|
|
365
410
|
name: "group",
|
|
366
411
|
kind: "block",
|
|
367
|
-
evidence: "
|
|
368
|
-
note: "
|
|
412
|
+
evidence: "verified",
|
|
413
|
+
note: "Array grouping by hash.by. Verified on Message Center with packageId and addressId.",
|
|
369
414
|
apply: (context, values, options) => {
|
|
370
415
|
const list = values[0];
|
|
371
416
|
const prop = options.hash.by;
|
|
@@ -405,8 +450,8 @@ var messageCenterSimulator = {
|
|
|
405
450
|
{
|
|
406
451
|
name: "richShippingData",
|
|
407
452
|
kind: "block",
|
|
408
|
-
evidence: "
|
|
409
|
-
note: "Clones shippingData before deriving SLA fields.
|
|
453
|
+
evidence: "verified",
|
|
454
|
+
note: "Clones shippingData before deriving SLA fields. Verified on Message Center.",
|
|
410
455
|
apply: richShippingData
|
|
411
456
|
}
|
|
412
457
|
]
|
package/dist/simulator.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simulator.d.ts","sourceRoot":"","sources":["../src/simulator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"simulator.d.ts","sourceRoot":"","sources":["../src/simulator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAwKtD,eAAO,MAAM,sBAAsB,EAAE,cA4IpC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vtex-email/vtex",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/marcelotk15/vtex-react-email.git"
|
|
@@ -18,6 +18,6 @@
|
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@vtex-email/core": "0.
|
|
21
|
+
"@vtex-email/core": "0.4.0"
|
|
22
22
|
}
|
|
23
23
|
}
|