@vtex-email/vtex 0.0.0 → 0.2.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 +129 -1
- package/dist/simulator.d.ts.map +1 -1
- package/package.json +6 -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;AAEvD,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;AAEvD,eAAO,MAAM,qBAAqB,EAAE,eAyGnC,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -33,6 +33,12 @@ var messageCenterEmission = {
|
|
|
33
33
|
evidence: "documented",
|
|
34
34
|
note: "Parent segment documented by Handlebars. A path cannot climb above the template root."
|
|
35
35
|
},
|
|
36
|
+
{
|
|
37
|
+
name: "@index",
|
|
38
|
+
form: "path",
|
|
39
|
+
evidence: "experimental",
|
|
40
|
+
note: "Zero-based index inside each. Not available in group. Not verified on Message Center."
|
|
41
|
+
},
|
|
36
42
|
{
|
|
37
43
|
name: "formatCurrency",
|
|
38
44
|
form: "inline",
|
|
@@ -41,6 +47,14 @@ var messageCenterEmission = {
|
|
|
41
47
|
arity: { min: 1, max: 1 },
|
|
42
48
|
args: ["path"]
|
|
43
49
|
},
|
|
50
|
+
{
|
|
51
|
+
name: "formatDate",
|
|
52
|
+
form: "inline",
|
|
53
|
+
evidence: "experimental",
|
|
54
|
+
note: "Local dd/MM/yyyy from a Date-parseable path. Timezone follows the host Date. Not verified on Message Center.",
|
|
55
|
+
arity: { min: 1, max: 1 },
|
|
56
|
+
args: ["path"]
|
|
57
|
+
},
|
|
44
58
|
{
|
|
45
59
|
name: "replace",
|
|
46
60
|
form: "inline",
|
|
@@ -53,9 +67,41 @@ var messageCenterEmission = {
|
|
|
53
67
|
name: "eq",
|
|
54
68
|
form: "block",
|
|
55
69
|
evidence: "experimental",
|
|
56
|
-
note: "The
|
|
70
|
+
note: "Strict equality. The merge uses path plus locale literal. The DSL emits path plus a literal. Path versus path is out of scope. Not verified on Message Center.",
|
|
71
|
+
arity: { min: 1, max: 1 },
|
|
72
|
+
args: ["literal"],
|
|
73
|
+
context: "preserve",
|
|
74
|
+
elseContext: "preserve"
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: "ifCond",
|
|
78
|
+
form: "block",
|
|
79
|
+
evidence: "experimental",
|
|
80
|
+
note: "Compares a path to a literal with ==, ===, or !=. Unknown operators fail at compile time. Both branches keep context. Project-local helper; not verified on Message Center.",
|
|
81
|
+
arity: { min: 2, max: 2 },
|
|
82
|
+
args: ["literal", "literal"],
|
|
83
|
+
literals: [{ index: 0, values: ["==", "===", "!="] }],
|
|
84
|
+
context: "preserve",
|
|
85
|
+
elseContext: "preserve"
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
name: "hasSubStr",
|
|
89
|
+
form: "block",
|
|
90
|
+
evidence: "experimental",
|
|
91
|
+
note: "True when the path value is not null and String(value) contains the literal. Both branches keep context. Project-local helper; not verified on Message Center.",
|
|
92
|
+
arity: { min: 1, max: 1 },
|
|
93
|
+
args: ["literal"],
|
|
57
94
|
context: "preserve",
|
|
58
95
|
elseContext: "preserve"
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
name: "group",
|
|
99
|
+
form: "block",
|
|
100
|
+
evidence: "experimental",
|
|
101
|
+
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.",
|
|
102
|
+
hash: [{ name: "by", kind: "literal" }],
|
|
103
|
+
context: "item",
|
|
104
|
+
elseContext: "outer"
|
|
59
105
|
}
|
|
60
106
|
]
|
|
61
107
|
};
|
|
@@ -71,6 +117,16 @@ function formatCurrency(value) {
|
|
|
71
117
|
const cents = String(absolute % 100).padStart(2, "0");
|
|
72
118
|
return `${sign}${units},${cents}`;
|
|
73
119
|
}
|
|
120
|
+
function formatDate(value) {
|
|
121
|
+
const date = value instanceof Date ? value : new Date(String(value ?? ""));
|
|
122
|
+
if (Number.isNaN(date.getTime())) {
|
|
123
|
+
throw new Error("formatDate: the local simulator expects a Date-parseable value.");
|
|
124
|
+
}
|
|
125
|
+
const day = String(date.getDate()).padStart(2, "0");
|
|
126
|
+
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
127
|
+
const year = String(date.getFullYear());
|
|
128
|
+
return `${day}/${month}/${year}`;
|
|
129
|
+
}
|
|
74
130
|
function replaceOnce(value, search, next) {
|
|
75
131
|
if (typeof value !== "string" || typeof search !== "string" || typeof next !== "string") {
|
|
76
132
|
throw new Error("replace: the local simulator expects three strings.");
|
|
@@ -79,6 +135,15 @@ function replaceOnce(value, search, next) {
|
|
|
79
135
|
if (index < 0) return value;
|
|
80
136
|
return value.slice(0, index) + next + value.slice(index + search.length);
|
|
81
137
|
}
|
|
138
|
+
function readProperty(obj, prop) {
|
|
139
|
+
const parts = prop.split(".");
|
|
140
|
+
let current = obj;
|
|
141
|
+
for (const part of parts) {
|
|
142
|
+
if (current == null || typeof current !== "object") return void 0;
|
|
143
|
+
current = current[part];
|
|
144
|
+
}
|
|
145
|
+
return current;
|
|
146
|
+
}
|
|
82
147
|
var messageCenterSimulator = {
|
|
83
148
|
helpers: [
|
|
84
149
|
{
|
|
@@ -88,6 +153,13 @@ var messageCenterSimulator = {
|
|
|
88
153
|
note: "20000 -> 200,00 is documented. Other integers are a local contract.",
|
|
89
154
|
apply: formatCurrency
|
|
90
155
|
},
|
|
156
|
+
{
|
|
157
|
+
name: "formatDate",
|
|
158
|
+
kind: "inline",
|
|
159
|
+
evidence: "experimental",
|
|
160
|
+
note: "Local dd/MM/yyyy. Not verified on VTEX.",
|
|
161
|
+
apply: formatDate
|
|
162
|
+
},
|
|
91
163
|
{
|
|
92
164
|
name: "replace",
|
|
93
165
|
kind: "inline",
|
|
@@ -104,6 +176,62 @@ var messageCenterSimulator = {
|
|
|
104
176
|
const [left, right] = values;
|
|
105
177
|
return left === right ? options.fn(context) : options.inverse(context);
|
|
106
178
|
}
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
name: "ifCond",
|
|
182
|
+
kind: "block",
|
|
183
|
+
evidence: "experimental",
|
|
184
|
+
note: "Local ==, ===, and !=. Not verified on VTEX.",
|
|
185
|
+
apply: (context, values, options) => {
|
|
186
|
+
const [left, operator, right] = values;
|
|
187
|
+
let pass = false;
|
|
188
|
+
if (operator === "==") pass = left == right;
|
|
189
|
+
else if (operator === "===") pass = left === right;
|
|
190
|
+
else if (operator === "!=") pass = left != right;
|
|
191
|
+
else return options.inverse(context);
|
|
192
|
+
return pass ? options.fn(context) : options.inverse(context);
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
name: "hasSubStr",
|
|
197
|
+
kind: "block",
|
|
198
|
+
evidence: "experimental",
|
|
199
|
+
note: "Local substring check. Not verified on VTEX.",
|
|
200
|
+
apply: (context, values, options) => {
|
|
201
|
+
const [value, search] = values;
|
|
202
|
+
if (value != null && String(value).includes(String(search))) return options.fn(context);
|
|
203
|
+
return options.inverse(context);
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
name: "group",
|
|
208
|
+
kind: "block",
|
|
209
|
+
evidence: "experimental",
|
|
210
|
+
note: "Local array grouping by hash.by. Not verified on VTEX.",
|
|
211
|
+
apply: (context, values, options) => {
|
|
212
|
+
const list = values[0];
|
|
213
|
+
const prop = options.hash.by;
|
|
214
|
+
if (typeof prop !== "string" || prop.length === 0 || !Array.isArray(list) || list.length === 0) {
|
|
215
|
+
return options.inverse(context);
|
|
216
|
+
}
|
|
217
|
+
const keys = [];
|
|
218
|
+
const groups = /* @__PURE__ */ new Map();
|
|
219
|
+
for (const item of list) {
|
|
220
|
+
const key = readProperty(item, prop);
|
|
221
|
+
if (!groups.has(key)) {
|
|
222
|
+
const group = { index: keys.length, value: key, items: [] };
|
|
223
|
+
keys.push(key);
|
|
224
|
+
groups.set(key, group);
|
|
225
|
+
}
|
|
226
|
+
groups.get(key)?.items.push(item);
|
|
227
|
+
}
|
|
228
|
+
let buffer = "";
|
|
229
|
+
for (const key of keys) {
|
|
230
|
+
const group = groups.get(key);
|
|
231
|
+
if (group) buffer += options.fn(group);
|
|
232
|
+
}
|
|
233
|
+
return buffer;
|
|
234
|
+
}
|
|
107
235
|
}
|
|
108
236
|
]
|
|
109
237
|
};
|
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;AA2CtD,eAAO,MAAM,sBAAsB,EAAE,cA0FpC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vtex-email/vtex",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/marcelotk15/vtex-react-email.git"
|
|
7
|
+
},
|
|
4
8
|
"files": [
|
|
5
9
|
"dist"
|
|
6
10
|
],
|
|
@@ -14,6 +18,6 @@
|
|
|
14
18
|
}
|
|
15
19
|
},
|
|
16
20
|
"dependencies": {
|
|
17
|
-
"@vtex-email/core": "0.
|
|
21
|
+
"@vtex-email/core": "0.2.0"
|
|
18
22
|
}
|
|
19
23
|
}
|