@vtex-email/vtex 0.1.0 → 0.3.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 +309 -5
- 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;
|
|
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,eA6JnC,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/capabilities.ts
|
|
2
|
+
var comparisonOperators = ["==", "===", "!=", "<", "<=", ">", ">="];
|
|
2
3
|
var messageCenterEmission = {
|
|
3
4
|
id: "p0-message-center-experimental",
|
|
4
5
|
allowParentSegments: true,
|
|
@@ -33,6 +34,12 @@ var messageCenterEmission = {
|
|
|
33
34
|
evidence: "documented",
|
|
34
35
|
note: "Parent segment documented by Handlebars. A path cannot climb above the template root."
|
|
35
36
|
},
|
|
37
|
+
{
|
|
38
|
+
name: "@index",
|
|
39
|
+
form: "path",
|
|
40
|
+
evidence: "experimental",
|
|
41
|
+
note: "Zero-based index inside each. Not available in group. Not verified on Message Center."
|
|
42
|
+
},
|
|
36
43
|
{
|
|
37
44
|
name: "formatCurrency",
|
|
38
45
|
form: "inline",
|
|
@@ -41,21 +48,113 @@ var messageCenterEmission = {
|
|
|
41
48
|
arity: { min: 1, max: 1 },
|
|
42
49
|
args: ["path"]
|
|
43
50
|
},
|
|
51
|
+
{
|
|
52
|
+
name: "formatDate",
|
|
53
|
+
form: "inline",
|
|
54
|
+
evidence: "experimental",
|
|
55
|
+
note: "Local dd/MM/yyyy from a Date-parseable path. Timezone follows the host Date. Not verified on Message Center.",
|
|
56
|
+
arity: { min: 1, max: 1 },
|
|
57
|
+
args: ["path"]
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
name: "formatTime",
|
|
61
|
+
form: "inline",
|
|
62
|
+
evidence: "experimental",
|
|
63
|
+
note: "Local HH:mm from a Date-parseable path. Zero-padded 24-hour clock. Timezone follows the host Date. Not verified on Message Center.",
|
|
64
|
+
arity: { min: 1, max: 1 },
|
|
65
|
+
args: ["path"]
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
name: "formatDateTime",
|
|
69
|
+
form: "inline",
|
|
70
|
+
evidence: "experimental",
|
|
71
|
+
note: "Local dd/MM/yyyy HH:mm:ss from a Date-parseable path. Zero-padded 24-hour clock. Timezone follows the host Date. Not verified on Message Center.",
|
|
72
|
+
arity: { min: 1, max: 1 },
|
|
73
|
+
args: ["path"]
|
|
74
|
+
},
|
|
44
75
|
{
|
|
45
76
|
name: "replace",
|
|
46
77
|
form: "inline",
|
|
47
78
|
evidence: "documented",
|
|
48
|
-
note: "
|
|
79
|
+
note: "Replaces the first occurrence. Search and replacement are path or literal. The simulator expects three strings.",
|
|
49
80
|
arity: { min: 3, max: 3 },
|
|
50
|
-
args: ["path", "
|
|
81
|
+
args: ["path", "expression", "expression"]
|
|
51
82
|
},
|
|
52
83
|
{
|
|
53
84
|
name: "eq",
|
|
54
85
|
form: "block",
|
|
55
86
|
evidence: "experimental",
|
|
56
|
-
note: "
|
|
87
|
+
note: "Strict equality. Path versus path or path versus literal. Both branches keep context. Not verified on Message Center.",
|
|
88
|
+
arity: { min: 1, max: 1 },
|
|
89
|
+
args: ["expression"],
|
|
90
|
+
context: "preserve",
|
|
91
|
+
elseContext: "preserve"
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
name: "ifCond",
|
|
95
|
+
form: "block",
|
|
96
|
+
evidence: "experimental",
|
|
97
|
+
note: "Compares a path to a path or literal with ==, ===, !=, <, <=, >, or >=. Unknown operators fail at compile time. Both branches keep context. Project-local helper; not verified on Message Center.",
|
|
98
|
+
arity: { min: 2, max: 2 },
|
|
99
|
+
args: ["literal", "expression"],
|
|
100
|
+
literals: [{ index: 0, values: comparisonOperators }],
|
|
101
|
+
context: "preserve",
|
|
102
|
+
elseContext: "preserve"
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
name: "hasSubStr",
|
|
106
|
+
form: "block",
|
|
107
|
+
evidence: "experimental",
|
|
108
|
+
note: "True when the path value is not null and String(value) contains the search path or literal. Both branches keep context. Project-local helper; not verified on Message Center.",
|
|
109
|
+
arity: { min: 1, max: 1 },
|
|
110
|
+
args: ["expression"],
|
|
57
111
|
context: "preserve",
|
|
58
112
|
elseContext: "preserve"
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
name: "group",
|
|
116
|
+
form: "block",
|
|
117
|
+
evidence: "experimental",
|
|
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. Project-local helper; not verified on Message Center.",
|
|
119
|
+
hash: [{ name: "by", kind: "literal" }],
|
|
120
|
+
context: "item",
|
|
121
|
+
elseContext: "outer"
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
name: "with",
|
|
125
|
+
form: "block",
|
|
126
|
+
evidence: "experimental",
|
|
127
|
+
note: "Native Handlebars with. The object becomes the current context. The fallback uses the outer context. Not verified on Message Center.",
|
|
128
|
+
context: "item",
|
|
129
|
+
elseContext: "outer"
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
name: "math",
|
|
133
|
+
form: "inline",
|
|
134
|
+
evidence: "experimental",
|
|
135
|
+
note: "Arithmetic on two expressions with +, -, *, /, or %. Non-finite results fail the local simulator. Not verified on Message Center.",
|
|
136
|
+
arity: { min: 3, max: 3 },
|
|
137
|
+
args: ["expression", "literal", "expression"],
|
|
138
|
+
literals: [{ index: 1, values: ["+", "-", "*", "/", "%"] }]
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
name: "math",
|
|
142
|
+
form: "block",
|
|
143
|
+
evidence: "experimental",
|
|
144
|
+
note: "Block form of math used by official templates. Path is the left operand; args are the operator and the right expression. Does not push context. Not verified on Message Center.",
|
|
145
|
+
arity: { min: 2, max: 2 },
|
|
146
|
+
args: ["literal", "expression"],
|
|
147
|
+
literals: [{ index: 0, values: ["+", "-", "*", "/", "%"] }],
|
|
148
|
+
context: "preserve",
|
|
149
|
+
elseContext: "preserve"
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
name: "richShippingData",
|
|
153
|
+
form: "block",
|
|
154
|
+
evidence: "experimental",
|
|
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. Not verified on Message Center.",
|
|
156
|
+
context: "item",
|
|
157
|
+
elseContext: "outer"
|
|
59
158
|
}
|
|
60
159
|
]
|
|
61
160
|
};
|
|
@@ -71,6 +170,28 @@ function formatCurrency(value) {
|
|
|
71
170
|
const cents = String(absolute % 100).padStart(2, "0");
|
|
72
171
|
return `${sign}${units},${cents}`;
|
|
73
172
|
}
|
|
173
|
+
function parseDate(value, helper) {
|
|
174
|
+
const date = value instanceof Date ? value : new Date(String(value ?? ""));
|
|
175
|
+
if (Number.isNaN(date.getTime())) {
|
|
176
|
+
throw new Error(`${helper}: the local simulator expects a Date-parseable value.`);
|
|
177
|
+
}
|
|
178
|
+
return date;
|
|
179
|
+
}
|
|
180
|
+
function pad2(value) {
|
|
181
|
+
return String(value).padStart(2, "0");
|
|
182
|
+
}
|
|
183
|
+
function formatDate(value) {
|
|
184
|
+
const date = parseDate(value, "formatDate");
|
|
185
|
+
return `${pad2(date.getDate())}/${pad2(date.getMonth() + 1)}/${date.getFullYear()}`;
|
|
186
|
+
}
|
|
187
|
+
function formatTime(value) {
|
|
188
|
+
const date = parseDate(value, "formatTime");
|
|
189
|
+
return `${pad2(date.getHours())}:${pad2(date.getMinutes())}`;
|
|
190
|
+
}
|
|
191
|
+
function formatDateTime(value) {
|
|
192
|
+
const date = parseDate(value, "formatDateTime");
|
|
193
|
+
return `${formatDate(date)} ${pad2(date.getHours())}:${pad2(date.getMinutes())}:${pad2(date.getSeconds())}`;
|
|
194
|
+
}
|
|
74
195
|
function replaceOnce(value, search, next) {
|
|
75
196
|
if (typeof value !== "string" || typeof search !== "string" || typeof next !== "string") {
|
|
76
197
|
throw new Error("replace: the local simulator expects three strings.");
|
|
@@ -79,6 +200,90 @@ function replaceOnce(value, search, next) {
|
|
|
79
200
|
if (index < 0) return value;
|
|
80
201
|
return value.slice(0, index) + next + value.slice(index + search.length);
|
|
81
202
|
}
|
|
203
|
+
function readProperty(obj, prop) {
|
|
204
|
+
const parts = prop.split(".");
|
|
205
|
+
let current = obj;
|
|
206
|
+
for (const part of parts) {
|
|
207
|
+
if (current == null || typeof current !== "object") return void 0;
|
|
208
|
+
current = current[part];
|
|
209
|
+
}
|
|
210
|
+
return current;
|
|
211
|
+
}
|
|
212
|
+
function compareValues(left, operator, right) {
|
|
213
|
+
switch (operator) {
|
|
214
|
+
case "==":
|
|
215
|
+
return left == right;
|
|
216
|
+
case "===":
|
|
217
|
+
return left === right;
|
|
218
|
+
case "!=":
|
|
219
|
+
return left != right;
|
|
220
|
+
case "<":
|
|
221
|
+
return left < right;
|
|
222
|
+
case "<=":
|
|
223
|
+
return left <= right;
|
|
224
|
+
case ">":
|
|
225
|
+
return left > right;
|
|
226
|
+
case ">=":
|
|
227
|
+
return left >= right;
|
|
228
|
+
default:
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
function applyMath(left, operator, right) {
|
|
233
|
+
const lvalue = Number.parseFloat(String(left));
|
|
234
|
+
const rvalue = Number.parseFloat(String(right));
|
|
235
|
+
const result = {
|
|
236
|
+
"+": lvalue + rvalue,
|
|
237
|
+
"-": lvalue - rvalue,
|
|
238
|
+
"*": lvalue * rvalue,
|
|
239
|
+
"/": lvalue / rvalue,
|
|
240
|
+
"%": lvalue % rvalue
|
|
241
|
+
}[String(operator)];
|
|
242
|
+
if (result === void 0 || !Number.isFinite(result)) {
|
|
243
|
+
throw new Error("math: the local simulator expects a finite numeric result.");
|
|
244
|
+
}
|
|
245
|
+
return String(result);
|
|
246
|
+
}
|
|
247
|
+
var estimatePattern = /^(\d+)(m|h|d|bd)$/;
|
|
248
|
+
function enrichLogisticsItem(item) {
|
|
249
|
+
const next = { ...item };
|
|
250
|
+
const selected = item.selectedSla;
|
|
251
|
+
const slas = Array.isArray(item.slas) ? item.slas : [];
|
|
252
|
+
for (const sla of slas) {
|
|
253
|
+
if (!sla || typeof sla !== "object") continue;
|
|
254
|
+
const row = sla;
|
|
255
|
+
if (item.selectedSla !== row.id) continue;
|
|
256
|
+
const estimate = typeof row.shippingEstimate === "string" ? row.shippingEstimate : "";
|
|
257
|
+
const match = estimatePattern.exec(estimate);
|
|
258
|
+
next.packageId = `${String(row.id ?? "")}${String(row.shippingEstimateDate ?? "")}${estimate}`;
|
|
259
|
+
next.shippingEstimateDays = match ? match[1] : estimate;
|
|
260
|
+
next.shippingEstimateDaysType = match ? match[2] : null;
|
|
261
|
+
next.shippingEstimate = row.shippingEstimate;
|
|
262
|
+
next.shippingEstimateDate = row.shippingEstimateDate;
|
|
263
|
+
next.deliveryWindow = row.deliveryWindow;
|
|
264
|
+
next.availableDeliveryWindows = row.availableDeliveryWindows;
|
|
265
|
+
void selected;
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
return next;
|
|
269
|
+
}
|
|
270
|
+
function richShippingData(_context, values, options) {
|
|
271
|
+
const shipping = values[0];
|
|
272
|
+
if (shipping == null || typeof shipping !== "object") return options.inverse(_context);
|
|
273
|
+
const source = shipping;
|
|
274
|
+
const logistics = Array.isArray(source.logisticsInfo) ? source.logisticsInfo : [];
|
|
275
|
+
const enriched = logistics.map(
|
|
276
|
+
(item) => item && typeof item === "object" ? enrichLogisticsItem(item) : item
|
|
277
|
+
);
|
|
278
|
+
const sorted = [...enriched].sort((left, right) => {
|
|
279
|
+
const a = left && typeof left === "object" ? Number(left.shippingEstimateDays) : Number.NaN;
|
|
280
|
+
const b = right && typeof right === "object" ? Number(right.shippingEstimateDays) : Number.NaN;
|
|
281
|
+
const leftValue = Number.isFinite(a) ? a : Number.POSITIVE_INFINITY;
|
|
282
|
+
const rightValue = Number.isFinite(b) ? b : Number.POSITIVE_INFINITY;
|
|
283
|
+
return leftValue - rightValue;
|
|
284
|
+
});
|
|
285
|
+
return options.fn({ ...source, logisticsInfo: sorted });
|
|
286
|
+
}
|
|
82
287
|
var messageCenterSimulator = {
|
|
83
288
|
helpers: [
|
|
84
289
|
{
|
|
@@ -88,22 +293,121 @@ var messageCenterSimulator = {
|
|
|
88
293
|
note: "20000 -> 200,00 is documented. Other integers are a local contract.",
|
|
89
294
|
apply: formatCurrency
|
|
90
295
|
},
|
|
296
|
+
{
|
|
297
|
+
name: "formatDate",
|
|
298
|
+
kind: "inline",
|
|
299
|
+
evidence: "experimental",
|
|
300
|
+
note: "Local dd/MM/yyyy. Not verified on VTEX.",
|
|
301
|
+
apply: formatDate
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
name: "formatTime",
|
|
305
|
+
kind: "inline",
|
|
306
|
+
evidence: "experimental",
|
|
307
|
+
note: "Local HH:mm with zero padding. Not verified on VTEX.",
|
|
308
|
+
apply: formatTime
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
name: "formatDateTime",
|
|
312
|
+
kind: "inline",
|
|
313
|
+
evidence: "experimental",
|
|
314
|
+
note: "Local dd/MM/yyyy HH:mm:ss with zero padding. Not verified on VTEX.",
|
|
315
|
+
apply: formatDateTime
|
|
316
|
+
},
|
|
91
317
|
{
|
|
92
318
|
name: "replace",
|
|
93
319
|
kind: "inline",
|
|
94
320
|
evidence: "documented",
|
|
95
|
-
note: "One occurrence. A path and two
|
|
321
|
+
note: "One occurrence. A path and two expressions that resolve to strings.",
|
|
96
322
|
apply: replaceOnce
|
|
97
323
|
},
|
|
324
|
+
{
|
|
325
|
+
name: "math",
|
|
326
|
+
kind: "inline",
|
|
327
|
+
evidence: "experimental",
|
|
328
|
+
note: "Local arithmetic. Not verified on VTEX.",
|
|
329
|
+
apply: applyMath
|
|
330
|
+
},
|
|
98
331
|
{
|
|
99
332
|
name: "eq",
|
|
100
333
|
kind: "block",
|
|
101
334
|
evidence: "experimental",
|
|
102
|
-
note: "Local strict equality. Not verified on VTEX.",
|
|
335
|
+
note: "Local strict equality. Path versus path or literal. Not verified on VTEX.",
|
|
103
336
|
apply: (context, values, options) => {
|
|
104
337
|
const [left, right] = values;
|
|
105
338
|
return left === right ? options.fn(context) : options.inverse(context);
|
|
106
339
|
}
|
|
340
|
+
},
|
|
341
|
+
{
|
|
342
|
+
name: "ifCond",
|
|
343
|
+
kind: "block",
|
|
344
|
+
evidence: "experimental",
|
|
345
|
+
note: "Local ==, ===, !=, <, <=, >, and >=. Not verified on VTEX.",
|
|
346
|
+
apply: (context, values, options) => {
|
|
347
|
+
const [left, operator, right] = values;
|
|
348
|
+
const pass = compareValues(left, operator, right);
|
|
349
|
+
if (pass === null) return options.inverse(context);
|
|
350
|
+
return pass ? options.fn(context) : options.inverse(context);
|
|
351
|
+
}
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
name: "hasSubStr",
|
|
355
|
+
kind: "block",
|
|
356
|
+
evidence: "experimental",
|
|
357
|
+
note: "Local substring check. Search may be a path or literal. Not verified on VTEX.",
|
|
358
|
+
apply: (context, values, options) => {
|
|
359
|
+
const [value, search] = values;
|
|
360
|
+
if (value != null && String(value).includes(String(search))) return options.fn(context);
|
|
361
|
+
return options.inverse(context);
|
|
362
|
+
}
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
name: "group",
|
|
366
|
+
kind: "block",
|
|
367
|
+
evidence: "experimental",
|
|
368
|
+
note: "Local array grouping by hash.by. Not verified on VTEX.",
|
|
369
|
+
apply: (context, values, options) => {
|
|
370
|
+
const list = values[0];
|
|
371
|
+
const prop = options.hash.by;
|
|
372
|
+
if (typeof prop !== "string" || prop.length === 0 || !Array.isArray(list) || list.length === 0) {
|
|
373
|
+
return options.inverse(context);
|
|
374
|
+
}
|
|
375
|
+
const keys = [];
|
|
376
|
+
const groups = /* @__PURE__ */ new Map();
|
|
377
|
+
for (const item of list) {
|
|
378
|
+
const key = readProperty(item, prop);
|
|
379
|
+
if (!groups.has(key)) {
|
|
380
|
+
const group = { index: keys.length, value: key, items: [] };
|
|
381
|
+
keys.push(key);
|
|
382
|
+
groups.set(key, group);
|
|
383
|
+
}
|
|
384
|
+
groups.get(key)?.items.push(item);
|
|
385
|
+
}
|
|
386
|
+
let buffer = "";
|
|
387
|
+
for (const key of keys) {
|
|
388
|
+
const group = groups.get(key);
|
|
389
|
+
if (group) buffer += options.fn(group);
|
|
390
|
+
}
|
|
391
|
+
return buffer;
|
|
392
|
+
}
|
|
393
|
+
},
|
|
394
|
+
{
|
|
395
|
+
name: "with",
|
|
396
|
+
kind: "block",
|
|
397
|
+
evidence: "experimental",
|
|
398
|
+
note: "Local Handlebars with. Not verified on VTEX.",
|
|
399
|
+
apply: (context, values, options) => {
|
|
400
|
+
const target = values[0];
|
|
401
|
+
if (!target) return options.inverse(context);
|
|
402
|
+
return options.fn(target);
|
|
403
|
+
}
|
|
404
|
+
},
|
|
405
|
+
{
|
|
406
|
+
name: "richShippingData",
|
|
407
|
+
kind: "block",
|
|
408
|
+
evidence: "experimental",
|
|
409
|
+
note: "Clones shippingData before deriving SLA fields. Not verified on VTEX.",
|
|
410
|
+
apply: richShippingData
|
|
107
411
|
}
|
|
108
412
|
]
|
|
109
413
|
};
|
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;AAmJtD,eAAO,MAAM,sBAAsB,EAAE,cA8HpC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vtex-email/vtex",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.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.3.0"
|
|
22
22
|
}
|
|
23
23
|
}
|