bitsnap-automations 0.0.0-stage → 0.1.1
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/CHANGELOG.md +45 -0
- package/LICENSE +37 -0
- package/README.md +157 -2
- package/THIRD_PARTY_NOTICES.md +1725 -0
- package/chunks/logic-DYkm-4Pc.js +1158 -0
- package/index.js +20265 -0
- package/logic.js +1 -0
- package/messages/en.json +819 -0
- package/messages/pl.json +831 -0
- package/messages.js +1675 -0
- package/package.json +50 -4
- package/styles.css +1 -0
- package/types/_bitsnap-ui/components/portal-container.d.ts +60 -0
- package/types/_bitsnap-ui/lib/translate.d.ts +42 -0
- package/types/components/AiLearning.d.ts +26 -0
- package/types/components/RunHistory.d.ts +50 -0
- package/types/components/SaveScenarioTemplateDialog.d.ts +34 -0
- package/types/components/ScenarioEditor.d.ts +69 -0
- package/types/components/ScenarioList.d.ts +42 -0
- package/types/components/ScenarioTemplateList.d.ts +39 -0
- package/types/components/shared.d.ts +84 -0
- package/types/create-labels.d.ts +71 -0
- package/types/index.d.ts +22 -0
- package/types/labels.d.ts +529 -0
- package/types/logic/ai-decision.d.ts +38 -0
- package/types/logic/catalog.d.ts +48 -0
- package/types/logic/filters.d.ts +3 -0
- package/types/logic/index.d.ts +7 -0
- package/types/logic/scenario.d.ts +240 -0
- package/types/logic/templates.d.ts +27 -0
- package/types/messages-entry.d.ts +4 -0
- package/types/types.d.ts +314 -0
|
@@ -0,0 +1,1158 @@
|
|
|
1
|
+
const ACTION_KINDS = [
|
|
2
|
+
"aiDecision",
|
|
3
|
+
"webhook",
|
|
4
|
+
"mailerliteAdd",
|
|
5
|
+
"mailerliteRemove",
|
|
6
|
+
"mailchimpAdd",
|
|
7
|
+
"mailchimpRemove",
|
|
8
|
+
"getresponseAdd",
|
|
9
|
+
"getresponseRemove",
|
|
10
|
+
"sendEmail",
|
|
11
|
+
"grantAccess",
|
|
12
|
+
"revokeAccess",
|
|
13
|
+
"addCustomerTag",
|
|
14
|
+
"delay"
|
|
15
|
+
];
|
|
16
|
+
const ACTION_CATALOG = [
|
|
17
|
+
{
|
|
18
|
+
kind: "aiDecision",
|
|
19
|
+
app: "ai_decisions"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
kind: "webhook",
|
|
23
|
+
app: "webhook"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
kind: "mailerliteAdd",
|
|
27
|
+
app: "mailerlite",
|
|
28
|
+
requiresApp: "mailerlite"
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
kind: "mailerliteRemove",
|
|
32
|
+
app: "mailerlite",
|
|
33
|
+
requiresApp: "mailerlite"
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
kind: "mailchimpAdd",
|
|
37
|
+
app: "mailchimp",
|
|
38
|
+
requiresApp: "mailchimp"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
kind: "mailchimpRemove",
|
|
42
|
+
app: "mailchimp",
|
|
43
|
+
requiresApp: "mailchimp"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
kind: "getresponseAdd",
|
|
47
|
+
app: "getresponse",
|
|
48
|
+
requiresApp: "getresponse"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
kind: "getresponseRemove",
|
|
52
|
+
app: "getresponse",
|
|
53
|
+
requiresApp: "getresponse"
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
kind: "sendEmail",
|
|
57
|
+
app: "email"
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
kind: "grantAccess",
|
|
61
|
+
app: "access"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
kind: "revokeAccess",
|
|
65
|
+
app: "access"
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
kind: "addCustomerTag",
|
|
69
|
+
app: "customer_tags"
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
kind: "delay",
|
|
73
|
+
app: "delay"
|
|
74
|
+
}
|
|
75
|
+
];
|
|
76
|
+
const PICKER_APPS = [
|
|
77
|
+
"ai_decisions",
|
|
78
|
+
"webhook",
|
|
79
|
+
"mailerlite",
|
|
80
|
+
"mailchimp",
|
|
81
|
+
"getresponse",
|
|
82
|
+
"email",
|
|
83
|
+
"access",
|
|
84
|
+
"customer_tags",
|
|
85
|
+
"delay"
|
|
86
|
+
];
|
|
87
|
+
const FILTER_APPS = [
|
|
88
|
+
"webhook",
|
|
89
|
+
"mailerlite",
|
|
90
|
+
"mailchimp",
|
|
91
|
+
"getresponse",
|
|
92
|
+
"email",
|
|
93
|
+
"access",
|
|
94
|
+
"customer_tags"
|
|
95
|
+
];
|
|
96
|
+
const DELAY_MIN_SECONDS = 60;
|
|
97
|
+
const DELAY_MAX_SECONDS = 604800;
|
|
98
|
+
const MAX_ACTIONS_PER_SCENARIO = 20;
|
|
99
|
+
function actionDefinition(kind) {
|
|
100
|
+
return kind ? ACTION_CATALOG.find((definition) => definition.kind === kind) : void 0;
|
|
101
|
+
}
|
|
102
|
+
function actionApp(kind) {
|
|
103
|
+
return actionDefinition(kind)?.app ?? "delay";
|
|
104
|
+
}
|
|
105
|
+
const RUN_STATUSES = [
|
|
106
|
+
"unknown",
|
|
107
|
+
"pending",
|
|
108
|
+
"running",
|
|
109
|
+
"waiting",
|
|
110
|
+
"succeeded",
|
|
111
|
+
"failed",
|
|
112
|
+
"skipped"
|
|
113
|
+
];
|
|
114
|
+
const RUN_STATUS_FILTERS = [
|
|
115
|
+
"failed",
|
|
116
|
+
"waiting",
|
|
117
|
+
"running",
|
|
118
|
+
"pending",
|
|
119
|
+
"succeeded",
|
|
120
|
+
"skipped"
|
|
121
|
+
];
|
|
122
|
+
const EVENT_GROUP_ORDER = [
|
|
123
|
+
"orders",
|
|
124
|
+
"subscriptions",
|
|
125
|
+
"access",
|
|
126
|
+
"cart",
|
|
127
|
+
"testimonials",
|
|
128
|
+
"configurators",
|
|
129
|
+
"personas"
|
|
130
|
+
];
|
|
131
|
+
const AI_DECISION_MODES = [
|
|
132
|
+
"learning",
|
|
133
|
+
"automatic",
|
|
134
|
+
"full"
|
|
135
|
+
];
|
|
136
|
+
function validateAiDecisionConfig(input) {
|
|
137
|
+
if (!input || typeof input !== "object") return "aiDecision";
|
|
138
|
+
const c = input;
|
|
139
|
+
if (typeof c.stepId !== "string" || !/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(c.stepId)) return "stepId";
|
|
140
|
+
if (typeof c.userRules !== "string" || !c.userRules.trim() || c.userRules.length > 2e3) return "userRules";
|
|
141
|
+
if (![
|
|
142
|
+
"learning",
|
|
143
|
+
"automatic",
|
|
144
|
+
"full"
|
|
145
|
+
].includes(c.mode)) return "mode";
|
|
146
|
+
if (!["sensitive", "non_sensitive"].includes(c.dataSensitivity)) return "dataSensitivity";
|
|
147
|
+
if (!Array.isArray(c.outcomes) || c.outcomes.length < 2 || c.outcomes.length > 8) return "outcomes";
|
|
148
|
+
const ids = /* @__PURE__ */ new Set();
|
|
149
|
+
for (const o of c.outcomes) {
|
|
150
|
+
if (!o || typeof o.id !== "string" || !/^[a-z][a-z0-9_-]{0,39}$/.test(o.id) || o.id === "unclear" || ids.has(o.id)) return "outcomes.id";
|
|
151
|
+
ids.add(o.id);
|
|
152
|
+
if (typeof o.label !== "string" || !o.label.trim() || o.label.length > 100) return "outcomes.label";
|
|
153
|
+
if (typeof o.criteria !== "string" || !o.criteria.trim() || o.criteria.length > 600) return "outcomes.criteria";
|
|
154
|
+
if (o.tag != null && (typeof o.tag !== "string" || !o.tag.trim() || o.tag.length > 50)) return "outcomes.tag";
|
|
155
|
+
}
|
|
156
|
+
if ((c.mode === "full" || c.fallbackOutcome) && !ids.has(c.fallbackOutcome ?? "")) return "fallbackOutcome";
|
|
157
|
+
}
|
|
158
|
+
function learningProgressKey(state) {
|
|
159
|
+
if (state.analysisStatus === "retrying") return "retrying";
|
|
160
|
+
if (state.analysisStatus === "pending" || state.analysisStatus === "running") return "analyzing";
|
|
161
|
+
if (state.latestResult === "changed") return "changed";
|
|
162
|
+
if (state.latestResult === "unchanged") return "unchanged";
|
|
163
|
+
return state.assessed === 0 ? "start" : "remaining";
|
|
164
|
+
}
|
|
165
|
+
function ruleDestination(outcomeId, outcomes) {
|
|
166
|
+
const label = outcomes.find((outcome) => outcome.id === outcomeId)?.label;
|
|
167
|
+
return label && label !== outcomeId ? `${label} (${outcomeId})` : outcomeId;
|
|
168
|
+
}
|
|
169
|
+
const UNIT_SECONDS = {
|
|
170
|
+
minutes: 60,
|
|
171
|
+
hours: 3600,
|
|
172
|
+
days: 86400
|
|
173
|
+
};
|
|
174
|
+
function sameEmailTemplateRef(a, b) {
|
|
175
|
+
if ("id" in a) return "id" in b && a.id === b.id;
|
|
176
|
+
return "starterKey" in b && a.starterKey === b.starterKey;
|
|
177
|
+
}
|
|
178
|
+
let uidCounter = 0;
|
|
179
|
+
function nextUid() {
|
|
180
|
+
uidCounter += 1;
|
|
181
|
+
return `a${uidCounter}`;
|
|
182
|
+
}
|
|
183
|
+
function emptyActionDraft(kind) {
|
|
184
|
+
return {
|
|
185
|
+
uid: nextUid(),
|
|
186
|
+
id: "",
|
|
187
|
+
kind,
|
|
188
|
+
...kind === "aiDecision" ? { aiDecision: {
|
|
189
|
+
stepId: crypto.randomUUID(),
|
|
190
|
+
userRules: "",
|
|
191
|
+
mode: "learning",
|
|
192
|
+
dataSensitivity: "sensitive",
|
|
193
|
+
outcomes: [{
|
|
194
|
+
id: "sales",
|
|
195
|
+
label: "",
|
|
196
|
+
criteria: ""
|
|
197
|
+
}, {
|
|
198
|
+
id: "support",
|
|
199
|
+
label: "",
|
|
200
|
+
criteria: ""
|
|
201
|
+
}]
|
|
202
|
+
} } : {},
|
|
203
|
+
url: "",
|
|
204
|
+
secret: "",
|
|
205
|
+
resourceId: "",
|
|
206
|
+
resourceName: "",
|
|
207
|
+
requireConsent: false,
|
|
208
|
+
subject: "",
|
|
209
|
+
body: "",
|
|
210
|
+
replyTo: "",
|
|
211
|
+
productId: "",
|
|
212
|
+
productName: "",
|
|
213
|
+
tag: "",
|
|
214
|
+
delayAmount: kind === "delay" ? "1" : "",
|
|
215
|
+
delayUnit: kind === "delay" ? "days" : "minutes"
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
function unknownActionDraft(id, unknown) {
|
|
219
|
+
return {
|
|
220
|
+
...emptyActionDraft("webhook"),
|
|
221
|
+
id,
|
|
222
|
+
kind: void 0,
|
|
223
|
+
unknown
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
function emptyScenarioDraft() {
|
|
227
|
+
return {
|
|
228
|
+
id: "",
|
|
229
|
+
name: "",
|
|
230
|
+
triggerEvent: "",
|
|
231
|
+
products: [],
|
|
232
|
+
variantIds: [],
|
|
233
|
+
active: true,
|
|
234
|
+
actions: [],
|
|
235
|
+
legacy: false,
|
|
236
|
+
formIds: [],
|
|
237
|
+
personaIds: [],
|
|
238
|
+
skipNegativePersona: true
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
function eventHasForm(event) {
|
|
242
|
+
return event?.group === "configurators";
|
|
243
|
+
}
|
|
244
|
+
function withTriggerEvent(draft, name, events) {
|
|
245
|
+
const keepForms = eventHasForm(events.find((candidate) => candidate.name === name));
|
|
246
|
+
return {
|
|
247
|
+
...draft,
|
|
248
|
+
triggerEvent: name,
|
|
249
|
+
...draft.formIds && draft.formIds.length > 0 && !keepForms ? { formIds: [] } : {}
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
function withNegativePersonaRule(draft, negativeIds) {
|
|
253
|
+
return draft.skipNegativePersona && picksNegativePersona(draft, negativeIds) ? {
|
|
254
|
+
...draft,
|
|
255
|
+
skipNegativePersona: false
|
|
256
|
+
} : draft;
|
|
257
|
+
}
|
|
258
|
+
function picksNegativePersona(draft, negativeIds) {
|
|
259
|
+
return (draft.personaIds ?? []).some((id) => negativeIds.includes(id));
|
|
260
|
+
}
|
|
261
|
+
function delayFromSeconds(seconds) {
|
|
262
|
+
if (seconds > 0 && seconds % UNIT_SECONDS.days === 0) return {
|
|
263
|
+
amount: String(seconds / UNIT_SECONDS.days),
|
|
264
|
+
unit: "days"
|
|
265
|
+
};
|
|
266
|
+
if (seconds > 0 && seconds % UNIT_SECONDS.hours === 0) return {
|
|
267
|
+
amount: String(seconds / UNIT_SECONDS.hours),
|
|
268
|
+
unit: "hours"
|
|
269
|
+
};
|
|
270
|
+
return {
|
|
271
|
+
amount: String(Math.round(seconds / 60)),
|
|
272
|
+
unit: "minutes"
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
function delayToSeconds(amount, unit) {
|
|
276
|
+
const trimmed = amount.trim();
|
|
277
|
+
if (!/^\d+$/.test(trimmed)) return NaN;
|
|
278
|
+
return Number(trimmed) * UNIT_SECONDS[unit];
|
|
279
|
+
}
|
|
280
|
+
function unitSeconds(unit) {
|
|
281
|
+
return UNIT_SECONDS[unit];
|
|
282
|
+
}
|
|
283
|
+
function validateDelay(amount, unit) {
|
|
284
|
+
const seconds = delayToSeconds(amount, unit);
|
|
285
|
+
if (!Number.isFinite(seconds) || seconds <= 0) return "invalid";
|
|
286
|
+
if (seconds < 60) return "tooShort";
|
|
287
|
+
if (seconds > 604800) return "tooLong";
|
|
288
|
+
}
|
|
289
|
+
function rootProductId(id) {
|
|
290
|
+
if (id.startsWith("prodv2_")) {
|
|
291
|
+
const parts = id.split("_");
|
|
292
|
+
if (parts.length > 2) return `${parts[0]}_${parts[1]}`;
|
|
293
|
+
return id;
|
|
294
|
+
}
|
|
295
|
+
if (id.endsWith("_default")) return id.slice(0, -8);
|
|
296
|
+
return id;
|
|
297
|
+
}
|
|
298
|
+
function groupProductResults(rows) {
|
|
299
|
+
const groups = /* @__PURE__ */ new Map();
|
|
300
|
+
for (const row of rows) {
|
|
301
|
+
const root = rootProductId(row.id);
|
|
302
|
+
const group = groups.get(root) ?? { names: [] };
|
|
303
|
+
if (row.id === root) group.exact = row.name;
|
|
304
|
+
group.names.push(row.name);
|
|
305
|
+
group.imageUrl ??= row.imageUrl;
|
|
306
|
+
groups.set(root, group);
|
|
307
|
+
}
|
|
308
|
+
return [...groups.entries()].map(([id, group]) => ({
|
|
309
|
+
id,
|
|
310
|
+
name: group.exact ?? baseProductName(group.names),
|
|
311
|
+
imageUrl: group.imageUrl
|
|
312
|
+
}));
|
|
313
|
+
}
|
|
314
|
+
function baseProductName(names) {
|
|
315
|
+
if (names.length === 0) return "";
|
|
316
|
+
const strip = (name) => {
|
|
317
|
+
const index = name.lastIndexOf(" - ");
|
|
318
|
+
return index > 0 ? name.slice(0, index) : name;
|
|
319
|
+
};
|
|
320
|
+
if (names.length === 1) return strip(names[0]);
|
|
321
|
+
let prefix = names[0];
|
|
322
|
+
for (const name of names.slice(1)) {
|
|
323
|
+
let i = 0;
|
|
324
|
+
while (i < prefix.length && i < name.length && prefix[i] === name[i]) i++;
|
|
325
|
+
prefix = prefix.slice(0, i);
|
|
326
|
+
}
|
|
327
|
+
const cut = prefix.lastIndexOf(" - ");
|
|
328
|
+
if (cut > 0) return prefix.slice(0, cut);
|
|
329
|
+
return prefix.trim() || strip(names[0]);
|
|
330
|
+
}
|
|
331
|
+
function productNameFrom(names, id) {
|
|
332
|
+
if (names[id]) return names[id];
|
|
333
|
+
const prefix = `${id}_`;
|
|
334
|
+
const variants = Object.entries(names).filter(([key]) => key.startsWith(prefix)).map(([, name]) => name);
|
|
335
|
+
return variants.length ? baseProductName(variants) : void 0;
|
|
336
|
+
}
|
|
337
|
+
function parsePlaceholderError(text) {
|
|
338
|
+
const match = /^placeholder:([a-z_]+):(.*)$/s.exec(text);
|
|
339
|
+
return match ? {
|
|
340
|
+
code: match[1],
|
|
341
|
+
token: match[2]
|
|
342
|
+
} : void 0;
|
|
343
|
+
}
|
|
344
|
+
function placeholderErrorFromDetail(detail) {
|
|
345
|
+
return /^(unknown_placeholder|placeholder_[a-z_]+):/.test(detail) ? `placeholder:${detail}` : void 0;
|
|
346
|
+
}
|
|
347
|
+
const EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
348
|
+
function isHttpUrl(value) {
|
|
349
|
+
try {
|
|
350
|
+
const url = new URL(value.trim());
|
|
351
|
+
return url.protocol === "https:" || url.protocol === "http:";
|
|
352
|
+
} catch {
|
|
353
|
+
return false;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
function validateScenarioDraft(draft, options = {}) {
|
|
357
|
+
const errors = {};
|
|
358
|
+
if (!draft.name.trim()) errors.name = "nameRequired";
|
|
359
|
+
else if (draft.name.trim().length > 120) errors.name = "nameTooLong";
|
|
360
|
+
if (!draft.triggerEvent) errors.trigger_event = "eventRequired";
|
|
361
|
+
if (draft.actions.length === 0) errors.actions = "actionsRequired";
|
|
362
|
+
else if (draft.actions.every((a) => a.kind === "delay")) errors.actions = "onlyDelays";
|
|
363
|
+
if (draft.actions.length > 20) errors.actions = "tooManyActions";
|
|
364
|
+
draft.actions.forEach((action, index) => {
|
|
365
|
+
const at = (field) => `actions[${index}].${field}`;
|
|
366
|
+
switch (action.kind) {
|
|
367
|
+
case "aiDecision": {
|
|
368
|
+
const configError = validateAiDecisionConfig(action.aiDecision);
|
|
369
|
+
if (configError) {
|
|
370
|
+
const field = configError.startsWith("outcomes") ? "ai_decision.outcomes" : configError === "fallbackOutcome" ? "ai_decision.fallback_outcome" : "ai_decision";
|
|
371
|
+
errors[at(field)] = field === "ai_decision.outcomes" ? "aiOutcomes" : field === "ai_decision.fallback_outcome" ? "aiFallback" : "aiConfig";
|
|
372
|
+
}
|
|
373
|
+
if (index !== draft.actions.length - 1 || draft.actions.filter((a) => a.kind === "aiDecision").length > 1) errors[at("ai_decision")] = "aiFinal";
|
|
374
|
+
break;
|
|
375
|
+
}
|
|
376
|
+
case "webhook":
|
|
377
|
+
if (!action.url.trim()) errors[at("webhook.url")] = "urlRequired";
|
|
378
|
+
else if (!isHttpUrl(action.url)) errors[at("webhook.url")] = "urlInvalid";
|
|
379
|
+
break;
|
|
380
|
+
case "mailerliteAdd":
|
|
381
|
+
case "mailerliteRemove":
|
|
382
|
+
if (!action.resourceId) errors[at("mailerlite.group_id")] = "groupRequired";
|
|
383
|
+
break;
|
|
384
|
+
case "mailchimpAdd":
|
|
385
|
+
case "mailchimpRemove":
|
|
386
|
+
if (!action.resourceId) errors[at("mailchimp.list_id")] = "listRequired";
|
|
387
|
+
break;
|
|
388
|
+
case "getresponseAdd":
|
|
389
|
+
case "getresponseRemove":
|
|
390
|
+
if (!action.resourceId) errors[at("getresponse.campaign_id")] = "listRequired";
|
|
391
|
+
break;
|
|
392
|
+
case "sendEmail": {
|
|
393
|
+
const check = options.checkEmailText;
|
|
394
|
+
if (action.emailTemplate === null) errors[at("send_email.email_template_id")] = "emailTemplateRequired";
|
|
395
|
+
else if (action.emailTemplate) {
|
|
396
|
+
const issue = check && (check(action.emailTemplate.subject, "subject") ?? check(action.emailTemplate.text, "body"));
|
|
397
|
+
if (issue) errors[at("send_email.email_template_id")] = issue;
|
|
398
|
+
} else {
|
|
399
|
+
if (!action.subject.trim()) errors[at("send_email.subject")] = "subjectRequired";
|
|
400
|
+
else if (check) {
|
|
401
|
+
const issue = check(action.subject, "subject");
|
|
402
|
+
if (issue) errors[at("send_email.subject")] = issue;
|
|
403
|
+
}
|
|
404
|
+
if (!action.body.trim()) errors[at("send_email.body")] = "bodyRequired";
|
|
405
|
+
else if (check) {
|
|
406
|
+
const issue = check(action.body, "body");
|
|
407
|
+
if (issue) errors[at("send_email.body")] = issue;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
if (action.replyTo.trim() && !EMAIL.test(action.replyTo.trim())) errors[at("send_email.reply_to")] = "replyToInvalid";
|
|
411
|
+
break;
|
|
412
|
+
}
|
|
413
|
+
case "grantAccess":
|
|
414
|
+
case "revokeAccess":
|
|
415
|
+
if (!action.productId) errors[at("access.product_id")] = "productRequired";
|
|
416
|
+
break;
|
|
417
|
+
case "addCustomerTag":
|
|
418
|
+
if (!action.tag.trim()) errors[at("customer_tag.tag")] = "tagRequired";
|
|
419
|
+
break;
|
|
420
|
+
case "delay": {
|
|
421
|
+
const error = validateDelay(action.delayAmount, action.delayUnit);
|
|
422
|
+
if (error) errors[at("delay.seconds")] = `delay.${error}`;
|
|
423
|
+
break;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
});
|
|
427
|
+
return errors;
|
|
428
|
+
}
|
|
429
|
+
function parseFieldPath(path) {
|
|
430
|
+
const match = /^actions\[(\d+)\](?:\.(.+))?$/.exec(path);
|
|
431
|
+
if (match) return {
|
|
432
|
+
actionIndex: Number(match[1]),
|
|
433
|
+
field: match[2] ?? ""
|
|
434
|
+
};
|
|
435
|
+
return { field: path };
|
|
436
|
+
}
|
|
437
|
+
function firstActionWithError(errors) {
|
|
438
|
+
const indexes = Object.keys(errors).map((key) => parseFieldPath(key).actionIndex).filter((index) => index !== void 0);
|
|
439
|
+
return indexes.length ? Math.min(...indexes) : void 0;
|
|
440
|
+
}
|
|
441
|
+
function actionErrors(errors, index) {
|
|
442
|
+
const result = {};
|
|
443
|
+
for (const [key, value] of Object.entries(errors)) {
|
|
444
|
+
const parsed = parseFieldPath(key);
|
|
445
|
+
if (parsed.actionIndex === index) result[parsed.field] = value;
|
|
446
|
+
}
|
|
447
|
+
return result;
|
|
448
|
+
}
|
|
449
|
+
function moveItem(items, from, to) {
|
|
450
|
+
if (to < 0 || to >= items.length || from === to) return [...items];
|
|
451
|
+
const next = [...items];
|
|
452
|
+
const [item] = next.splice(from, 1);
|
|
453
|
+
next.splice(to, 0, item);
|
|
454
|
+
return next;
|
|
455
|
+
}
|
|
456
|
+
function sameDraft(a, b) {
|
|
457
|
+
const strip = (d) => ({
|
|
458
|
+
...d,
|
|
459
|
+
actions: d.actions.map(({ uid: _uid, ...rest }) => rest)
|
|
460
|
+
});
|
|
461
|
+
return JSON.stringify(strip(a)) === JSON.stringify(strip(b));
|
|
462
|
+
}
|
|
463
|
+
function groupEvents(events, search, describe) {
|
|
464
|
+
const needle = normalize(search.trim());
|
|
465
|
+
return EVENT_GROUP_ORDER.map((group) => ({
|
|
466
|
+
group,
|
|
467
|
+
events: events.filter((event) => {
|
|
468
|
+
if (event.group !== group) return false;
|
|
469
|
+
if (!needle) return true;
|
|
470
|
+
const { label, description } = describe(event);
|
|
471
|
+
return normalize(`${label} ${description} ${event.name}`).includes(needle);
|
|
472
|
+
})
|
|
473
|
+
})).filter((entry) => entry.events.length > 0);
|
|
474
|
+
}
|
|
475
|
+
function normalize(value) {
|
|
476
|
+
return value.toLowerCase().normalize("NFD").replace(/[̀-ͯ]/g, "").replace(/ł/g, "l");
|
|
477
|
+
}
|
|
478
|
+
function ownTextFromTemplate(action, template) {
|
|
479
|
+
const source = template ?? action.emailTemplate ?? void 0;
|
|
480
|
+
return {
|
|
481
|
+
emailTemplate: void 0,
|
|
482
|
+
...!action.subject.trim() && !action.body.trim() && source ? {
|
|
483
|
+
subject: source.subject,
|
|
484
|
+
body: source.text
|
|
485
|
+
} : {}
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
function availablePlaceholders(placeholders) {
|
|
489
|
+
return (placeholders ?? []).filter((placeholder) => placeholder.available);
|
|
490
|
+
}
|
|
491
|
+
function insertAt(value, insert, start, end) {
|
|
492
|
+
const from = start ?? value.length;
|
|
493
|
+
const to = end ?? from;
|
|
494
|
+
return {
|
|
495
|
+
value: value.slice(0, from) + insert + value.slice(to),
|
|
496
|
+
caret: from + insert.length
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
function urlHost(value) {
|
|
500
|
+
try {
|
|
501
|
+
return new URL(value.trim()).host || value;
|
|
502
|
+
} catch {
|
|
503
|
+
return value.trim();
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
function templateRequirements(template, events, apps) {
|
|
507
|
+
const requirements = [];
|
|
508
|
+
if (!events.find((candidate) => candidate.name === template.triggerEvent)?.available) requirements.push({
|
|
509
|
+
kind: "event",
|
|
510
|
+
event: template.triggerEvent
|
|
511
|
+
});
|
|
512
|
+
const seen = /* @__PURE__ */ new Set();
|
|
513
|
+
for (const kind of template.actions) {
|
|
514
|
+
const app = actionDefinition(kind)?.requiresApp;
|
|
515
|
+
if (!app || seen.has(app)) continue;
|
|
516
|
+
seen.add(app);
|
|
517
|
+
if (apps.get(app)?.connected === false) requirements.push({
|
|
518
|
+
kind: "app",
|
|
519
|
+
app
|
|
520
|
+
});
|
|
521
|
+
}
|
|
522
|
+
return requirements;
|
|
523
|
+
}
|
|
524
|
+
function templatesInCategory(templates, category) {
|
|
525
|
+
return category === "all" ? [...templates] : templates.filter((template) => template.category === category);
|
|
526
|
+
}
|
|
527
|
+
function presentCategories(templates) {
|
|
528
|
+
const present = new Set(templates.map((template) => template.category));
|
|
529
|
+
return ["all", ...["shop", "parks"].filter((category) => present.has(category))];
|
|
530
|
+
}
|
|
531
|
+
function templateMatches(template, query, eventLabel) {
|
|
532
|
+
const needle = fold(query.trim());
|
|
533
|
+
if (!needle) return true;
|
|
534
|
+
return fold(`${template.name} ${template.description} ${eventLabel(template.triggerEvent)}`).includes(needle);
|
|
535
|
+
}
|
|
536
|
+
function fold(value) {
|
|
537
|
+
return value.toLowerCase().normalize("NFD").replace(/[̀-ͯ]/g, "").replace(/ł/g, "l");
|
|
538
|
+
}
|
|
539
|
+
const DEFAULT_SCENARIO_FILTERS = {
|
|
540
|
+
active: "all",
|
|
541
|
+
app: "",
|
|
542
|
+
product: void 0,
|
|
543
|
+
search: "",
|
|
544
|
+
page: 1,
|
|
545
|
+
pageSize: 20
|
|
546
|
+
};
|
|
547
|
+
function hasActiveFilters(filters) {
|
|
548
|
+
return filters.active !== "all" || filters.app !== "" || !!filters.product || !!filters.search.trim();
|
|
549
|
+
}
|
|
550
|
+
function createAutomationsLabels(t, options) {
|
|
551
|
+
const { locale } = options;
|
|
552
|
+
const env = {
|
|
553
|
+
isKnownEvent: options.isKnownEvent ?? ((name) => name !== "" && t(`events.${name}.label`, { defaultValue: MISSING }) !== MISSING),
|
|
554
|
+
format: options.format ?? createLabelDateFormat({
|
|
555
|
+
timeZone: options.timeZone,
|
|
556
|
+
locale
|
|
557
|
+
})
|
|
558
|
+
};
|
|
559
|
+
return {
|
|
560
|
+
list: buildScenarioListLabels(t, locale, env),
|
|
561
|
+
editor: buildScenarioEditorLabels(t, locale, env),
|
|
562
|
+
templates: buildScenarioTemplateListLabels(t, locale, env),
|
|
563
|
+
runs: buildRunHistoryLabels(t, locale, env),
|
|
564
|
+
aiLearning: buildAiLearningLabels(t, env)
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
const MISSING = "\0missing";
|
|
568
|
+
const DATE_PATTERN = {
|
|
569
|
+
year: "numeric",
|
|
570
|
+
month: "short",
|
|
571
|
+
day: "numeric"
|
|
572
|
+
};
|
|
573
|
+
const DATE_TIME_PATTERN = {
|
|
574
|
+
...DATE_PATTERN,
|
|
575
|
+
hour: "2-digit",
|
|
576
|
+
minute: "2-digit"
|
|
577
|
+
};
|
|
578
|
+
function createLabelDateFormat({ timeZone, locale: defaultLocale }) {
|
|
579
|
+
if (!timeZone || !defaultLocale) throw new Error("createLabelDateFormat: pass `timeZone` and `locale` (or give createAutomationsLabels your own `format`)");
|
|
580
|
+
const formatWith = (ms, options, defaults) => {
|
|
581
|
+
const { locale = defaultLocale, fallback = "-", ...intl } = options ?? {};
|
|
582
|
+
if (!Number.isFinite(ms) || ms <= 0) return fallback;
|
|
583
|
+
const pattern = intl.dateStyle != null || intl.timeStyle != null ? intl : {
|
|
584
|
+
...defaults,
|
|
585
|
+
...intl
|
|
586
|
+
};
|
|
587
|
+
return new Intl.DateTimeFormat(locale, {
|
|
588
|
+
timeZone,
|
|
589
|
+
...pattern
|
|
590
|
+
}).format(new Date(ms));
|
|
591
|
+
};
|
|
592
|
+
return {
|
|
593
|
+
date: (ms, options) => formatWith(ms, options, DATE_PATTERN),
|
|
594
|
+
dateTime: (ms, options) => formatWith(ms, options, DATE_TIME_PATTERN)
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
function relativeTime(ms, locale, format, nowMs = Date.now()) {
|
|
598
|
+
const relative = new Intl.RelativeTimeFormat(locale, { numeric: "auto" });
|
|
599
|
+
const minutes = Math.round((ms - nowMs) / 6e4);
|
|
600
|
+
if (Math.abs(minutes) < 60) return relative.format(minutes, "minute");
|
|
601
|
+
const hours = Math.round(minutes / 60);
|
|
602
|
+
if (Math.abs(hours) < 24) return relative.format(hours, "hour");
|
|
603
|
+
const days = Math.round(hours / 24);
|
|
604
|
+
if (Math.abs(days) < 30) return relative.format(days, "day");
|
|
605
|
+
return format.date(ms, {
|
|
606
|
+
locale,
|
|
607
|
+
year: "numeric",
|
|
608
|
+
month: "numeric",
|
|
609
|
+
day: "numeric"
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
const ERROR_CODES = {
|
|
613
|
+
nameRequired: true,
|
|
614
|
+
nameTooLong: true,
|
|
615
|
+
eventRequired: true,
|
|
616
|
+
actionsRequired: true,
|
|
617
|
+
onlyDelays: true,
|
|
618
|
+
tooManyActions: true,
|
|
619
|
+
urlRequired: true,
|
|
620
|
+
urlInvalid: true,
|
|
621
|
+
groupRequired: true,
|
|
622
|
+
listRequired: true,
|
|
623
|
+
subjectRequired: true,
|
|
624
|
+
bodyRequired: true,
|
|
625
|
+
emailTemplateRequired: true,
|
|
626
|
+
emailTemplateMissing: true,
|
|
627
|
+
templateLimitReached: true,
|
|
628
|
+
marketingTemplateNeedsConsent: true,
|
|
629
|
+
replyToInvalid: true,
|
|
630
|
+
productRequired: true,
|
|
631
|
+
tagRequired: true,
|
|
632
|
+
"delay.invalid": true,
|
|
633
|
+
"delay.tooShort": true,
|
|
634
|
+
"delay.tooLong": true,
|
|
635
|
+
aiConfig: true,
|
|
636
|
+
aiOutcomes: true,
|
|
637
|
+
aiFallback: true,
|
|
638
|
+
aiFinal: true,
|
|
639
|
+
appNotConnected: true,
|
|
640
|
+
permissionDenied: true,
|
|
641
|
+
notFound: true,
|
|
642
|
+
formsNotApplicable: true,
|
|
643
|
+
formsInvalid: true,
|
|
644
|
+
formUnknown: true,
|
|
645
|
+
personasInvalid: true,
|
|
646
|
+
personaUnknown: true
|
|
647
|
+
};
|
|
648
|
+
function buildCommonLabels(tx) {
|
|
649
|
+
return {
|
|
650
|
+
allProducts: tx("common.allProducts"),
|
|
651
|
+
productsCount: (count) => tx("common.productsCount", { count }),
|
|
652
|
+
cancel: tx("common.cancel"),
|
|
653
|
+
clearFilters: tx("common.clearFilters"),
|
|
654
|
+
close: tx("common.close"),
|
|
655
|
+
copied: tx("common.copied"),
|
|
656
|
+
copy: tx("common.copy"),
|
|
657
|
+
delete: tx("common.delete"),
|
|
658
|
+
edit: tx("common.edit"),
|
|
659
|
+
learnMore: tx("common.learnMore"),
|
|
660
|
+
loadFailed: tx("common.loadFailed"),
|
|
661
|
+
never: tx("common.never"),
|
|
662
|
+
newTab: tx("common.newTab"),
|
|
663
|
+
next: tx("common.next"),
|
|
664
|
+
previous: tx("common.previous"),
|
|
665
|
+
pageRange: (range) => tx("common.pageRange", range),
|
|
666
|
+
save: tx("common.save"),
|
|
667
|
+
saving: tx("common.saving"),
|
|
668
|
+
test: tx("common.test"),
|
|
669
|
+
tryAgain: tx("common.tryAgain")
|
|
670
|
+
};
|
|
671
|
+
}
|
|
672
|
+
function buildCatalogLabels(tx, locale, env) {
|
|
673
|
+
return {
|
|
674
|
+
actionTitle: (kind) => tx(`actions.${kind}.title`),
|
|
675
|
+
actionDescription: (kind) => tx(`actions.${kind}.description`),
|
|
676
|
+
appName: (app) => tx(`apps.${app}.name`),
|
|
677
|
+
eventLabel: (name) => env.isKnownEvent(name) ? tx(`events.${name}.label`) : name ? tx("events.unknown", { name }) : "",
|
|
678
|
+
eventDescription: (name) => env.isKnownEvent(name) ? tx(`events.${name}.description`) : "",
|
|
679
|
+
unknownEvent: (name) => tx("events.unknown", { name }),
|
|
680
|
+
eventGroup: (group) => tx(`eventGroups.${group}`),
|
|
681
|
+
runStatus: (status) => tx(`runStatus.${status}`),
|
|
682
|
+
waitingUntil: (ms) => tx("runStatus.waitingUntil", { time: env.format.dateTime(ms, {
|
|
683
|
+
locale,
|
|
684
|
+
day: "numeric",
|
|
685
|
+
month: "short",
|
|
686
|
+
hour: "2-digit",
|
|
687
|
+
minute: "2-digit",
|
|
688
|
+
year: void 0
|
|
689
|
+
}) }),
|
|
690
|
+
moreActions: (count) => tx("list.moreActions", { count })
|
|
691
|
+
};
|
|
692
|
+
}
|
|
693
|
+
function buildErrorLabels(tx, env) {
|
|
694
|
+
return {
|
|
695
|
+
...Object.fromEntries(Object.keys(ERROR_CODES).map((code) => [code, tx(`errors.${code}`)])),
|
|
696
|
+
server: (detail) => tx("errors.server", { detail }),
|
|
697
|
+
placeholder: (code, token) => tx(`errors.placeholder.${PLACEHOLDER_ERROR_KEYS[code] ?? "other"}`, { token: `{{${token}}}` })
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
const PLACEHOLDER_ERROR_KEYS = {
|
|
701
|
+
unknown_placeholder: "unknown",
|
|
702
|
+
placeholder_unavailable: "unavailable",
|
|
703
|
+
placeholder_in_attribute: "inAttribute",
|
|
704
|
+
placeholder_fallback_too_long: "fallbackTooLong"
|
|
705
|
+
};
|
|
706
|
+
function buildTemplateCardLabels(tx, locale, env) {
|
|
707
|
+
return {
|
|
708
|
+
use: tx("templates.card.use"),
|
|
709
|
+
useLabel: (name) => tx("templates.card.useLabel", { name }),
|
|
710
|
+
messageKind: (kind) => tx(`templates.card.messageKind.${kind}`),
|
|
711
|
+
messageKindHint: (kind) => tx(`templates.card.messageKindHint.${kind}`),
|
|
712
|
+
requiresEvent: (event) => tx("templates.card.requires", { what: event }),
|
|
713
|
+
requiresApp: (app) => tx("templates.card.requires", { what: app }),
|
|
714
|
+
connect: tx("templates.card.connect"),
|
|
715
|
+
updated: (ms) => tx("templates.card.updated", { date: env.format.date(ms, {
|
|
716
|
+
locale,
|
|
717
|
+
day: "numeric",
|
|
718
|
+
month: "short"
|
|
719
|
+
}) }),
|
|
720
|
+
outcomesTitle: tx("templates.outcomesTitle"),
|
|
721
|
+
outcomesDescription: tx("templates.outcomesDescription")
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
function buildScenarioTemplateListLabels(tx, locale, env) {
|
|
725
|
+
return {
|
|
726
|
+
common: buildCommonLabels(tx),
|
|
727
|
+
catalog: buildCatalogLabels(tx, locale, env),
|
|
728
|
+
cards: buildTemplateCardLabels(tx, locale, env),
|
|
729
|
+
label: tx("templates.list.label"),
|
|
730
|
+
search: tx("templates.list.search"),
|
|
731
|
+
searchPlaceholder: tx("templates.list.searchPlaceholder"),
|
|
732
|
+
noMatches: tx("templates.list.noMatches"),
|
|
733
|
+
ownTitle: tx("templates.list.ownTitle"),
|
|
734
|
+
ownDescription: tx("templates.list.ownDescription"),
|
|
735
|
+
ownEmpty: tx("templates.list.ownEmpty"),
|
|
736
|
+
startersTitle: tx("templates.list.startersTitle"),
|
|
737
|
+
startersDescription: tx("templates.list.startersDescription"),
|
|
738
|
+
categoryLabel: tx("templates.list.categoryLabel"),
|
|
739
|
+
category: (category) => tx(`templates.list.category.${category}`),
|
|
740
|
+
menu: (name) => tx("templates.list.menu", { name }),
|
|
741
|
+
rename: tx("templates.list.rename"),
|
|
742
|
+
renameTitle: tx("templates.list.renameTitle"),
|
|
743
|
+
name: tx("templates.list.name"),
|
|
744
|
+
nameRequired: tx("templates.list.nameRequired"),
|
|
745
|
+
description: tx("templates.list.description"),
|
|
746
|
+
renamed: tx("templates.list.renamed"),
|
|
747
|
+
renameFailed: tx("templates.list.renameFailed"),
|
|
748
|
+
deleteTitle: tx("templates.list.deleteTitle"),
|
|
749
|
+
deleteDescription: (name) => tx("templates.list.deleteDescription", { name }),
|
|
750
|
+
deleteConfirm: tx("templates.list.deleteConfirm"),
|
|
751
|
+
deleted: tx("templates.list.deleted"),
|
|
752
|
+
deleteFailed: tx("templates.list.deleteFailed"),
|
|
753
|
+
conflict: tx("templates.list.conflict")
|
|
754
|
+
};
|
|
755
|
+
}
|
|
756
|
+
function buildProductPickerLabels(tx) {
|
|
757
|
+
return {
|
|
758
|
+
search: tx("filters.productSearch"),
|
|
759
|
+
error: tx("filters.productError"),
|
|
760
|
+
loading: tx("filters.productLoading"),
|
|
761
|
+
none: tx("filters.productNone"),
|
|
762
|
+
filter: tx("filters.product"),
|
|
763
|
+
filterAny: tx("filters.productAny"),
|
|
764
|
+
allProducts: tx("sheet.productsAll"),
|
|
765
|
+
removeProduct: (name) => tx("sheet.productRemove", { name }),
|
|
766
|
+
allVariants: tx("sheet.variantsAll"),
|
|
767
|
+
removeVariant: (name) => tx("sheet.variantRemove", { name }),
|
|
768
|
+
variantSearch: tx("sheet.variantSearch"),
|
|
769
|
+
variantNone: tx("sheet.variantNone")
|
|
770
|
+
};
|
|
771
|
+
}
|
|
772
|
+
function buildScenarioListLabels(tx, locale, env) {
|
|
773
|
+
return {
|
|
774
|
+
common: buildCommonLabels(tx),
|
|
775
|
+
catalog: buildCatalogLabels(tx, locale, env),
|
|
776
|
+
products: buildProductPickerLabels(tx),
|
|
777
|
+
newScenario: tx("newScenario"),
|
|
778
|
+
view: tx("sheet.titleView"),
|
|
779
|
+
filters: {
|
|
780
|
+
label: tx("filters.label"),
|
|
781
|
+
search: tx("filters.search"),
|
|
782
|
+
activity: tx("filters.activity"),
|
|
783
|
+
activityAll: tx("filters.activityAll"),
|
|
784
|
+
activityActive: tx("filters.activityActive"),
|
|
785
|
+
activityInactive: tx("filters.activityInactive"),
|
|
786
|
+
app: tx("filters.app"),
|
|
787
|
+
appAll: tx("filters.appAll"),
|
|
788
|
+
pageSizeLabel: tx("filters.pageSizeLabel"),
|
|
789
|
+
pageSize: (count) => tx("filters.pageSize", { count })
|
|
790
|
+
},
|
|
791
|
+
list: {
|
|
792
|
+
label: tx("list.label"),
|
|
793
|
+
name: tx("list.name"),
|
|
794
|
+
event: tx("list.event"),
|
|
795
|
+
products: tx("list.products"),
|
|
796
|
+
actions: tx("list.actions"),
|
|
797
|
+
lastRun: tx("list.lastRun"),
|
|
798
|
+
active: tx("list.active"),
|
|
799
|
+
menu: (name) => tx("list.menu", { name }),
|
|
800
|
+
toggleLabel: (name) => tx("list.toggleLabel", { name }),
|
|
801
|
+
activated: (name) => tx("list.activated", { name }),
|
|
802
|
+
deactivated: (name) => tx("list.deactivated", { name }),
|
|
803
|
+
toggleFailed: tx("list.toggleFailed"),
|
|
804
|
+
deleted: tx("list.deleted"),
|
|
805
|
+
deleteFailed: tx("list.deleteFailed"),
|
|
806
|
+
deleteTitle: tx("list.deleteTitle"),
|
|
807
|
+
deleteDescription: (name) => tx("list.deleteDescription", { name }),
|
|
808
|
+
deleteConfirm: tx("list.deleteConfirm"),
|
|
809
|
+
runsCount: (count) => tx("list.runsCount", { count }),
|
|
810
|
+
failedCount: (count) => tx("list.failedCount", { count }),
|
|
811
|
+
showRuns: tx("list.showRuns"),
|
|
812
|
+
legacyBadge: tx("list.legacyBadge"),
|
|
813
|
+
legacyHint: tx("list.legacyHint")
|
|
814
|
+
},
|
|
815
|
+
empty: {
|
|
816
|
+
title: tx("empty.title"),
|
|
817
|
+
description: tx("empty.description"),
|
|
818
|
+
readOnlyDescription: tx("empty.readOnlyDescription"),
|
|
819
|
+
examplesTitle: tx("empty.examplesTitle"),
|
|
820
|
+
examplesHint: tx("empty.examplesHint"),
|
|
821
|
+
filteredTitle: tx("empty.filteredTitle"),
|
|
822
|
+
filteredDescription: tx("empty.filteredDescription")
|
|
823
|
+
},
|
|
824
|
+
cards: buildTemplateCardLabels(tx, locale, env),
|
|
825
|
+
format: {
|
|
826
|
+
relative: (ms) => relativeTime(ms, locale, env.format),
|
|
827
|
+
full: (ms) => new Date(ms).toLocaleString(locale)
|
|
828
|
+
}
|
|
829
|
+
};
|
|
830
|
+
}
|
|
831
|
+
function buildScenarioEditorLabels(tx, locale, env) {
|
|
832
|
+
const resourceSummary = (kind, name) => tx(`actions.${kind}.summary`, { name });
|
|
833
|
+
return {
|
|
834
|
+
common: buildCommonLabels(tx),
|
|
835
|
+
catalog: buildCatalogLabels(tx, locale, env),
|
|
836
|
+
errors: buildErrorLabels(tx, env),
|
|
837
|
+
products: buildProductPickerLabels(tx),
|
|
838
|
+
actions: {
|
|
839
|
+
add: tx("actions.add"),
|
|
840
|
+
limit: (max) => tx("actions.limit", { max }),
|
|
841
|
+
pickerTitle: tx("actions.pickerTitle"),
|
|
842
|
+
notConnected: tx("actions.notConnected"),
|
|
843
|
+
connectInApps: tx("actions.connectInApps"),
|
|
844
|
+
incomplete: tx("actions.incomplete"),
|
|
845
|
+
step: (index) => tx("actions.step", { index }),
|
|
846
|
+
moveUp: tx("actions.moveUp"),
|
|
847
|
+
moveDown: tx("actions.moveDown"),
|
|
848
|
+
remove: tx("actions.remove"),
|
|
849
|
+
summary: {
|
|
850
|
+
webhook: (host) => tx("actions.webhook.summary", { host }),
|
|
851
|
+
resource: resourceSummary,
|
|
852
|
+
sendEmail: (subject) => tx("actions.sendEmail.summary", { subject }),
|
|
853
|
+
sendEmailTemplate: (name) => tx("actions.sendEmail.summaryTemplate", { name }),
|
|
854
|
+
access: resourceSummary,
|
|
855
|
+
addCustomerTag: (tag) => tx("actions.addCustomerTag.summary", { tag }),
|
|
856
|
+
delay: (unit, count) => tx(`actions.delay.summary_${unit}`, { count })
|
|
857
|
+
},
|
|
858
|
+
webhook: {
|
|
859
|
+
url: tx("actions.webhook.url"),
|
|
860
|
+
urlHint: tx("actions.webhook.urlHint"),
|
|
861
|
+
urlPlaceholder: tx("actions.webhook.urlPlaceholder"),
|
|
862
|
+
secret: tx("actions.webhook.secret"),
|
|
863
|
+
secretAfterSave: tx("actions.webhook.secretAfterSave"),
|
|
864
|
+
secretHint: tx("actions.webhook.secretHint"),
|
|
865
|
+
revealSecret: tx("actions.webhook.revealSecret"),
|
|
866
|
+
revealError: tx("actions.webhook.revealError"),
|
|
867
|
+
copySecret: tx("actions.webhook.copySecret"),
|
|
868
|
+
secretCopied: tx("actions.webhook.secretCopied"),
|
|
869
|
+
test: tx("actions.webhook.test"),
|
|
870
|
+
testing: tx("actions.webhook.testing"),
|
|
871
|
+
testDelivered: (status) => tx("actions.webhook.testDelivered", { status }),
|
|
872
|
+
testDeliveredNoStatus: tx("actions.webhook.testDeliveredNoStatus"),
|
|
873
|
+
testFailed: (error) => tx("actions.webhook.testFailed", { error }),
|
|
874
|
+
testFailedStatus: (status) => tx("actions.webhook.testFailedStatus", { status }),
|
|
875
|
+
testError: tx("actions.webhook.testError")
|
|
876
|
+
},
|
|
877
|
+
resource: {
|
|
878
|
+
group: tx("actions.resource.group"),
|
|
879
|
+
list: tx("actions.resource.list"),
|
|
880
|
+
pick: tx("actions.resource.pick"),
|
|
881
|
+
loading: tx("actions.resource.loading"),
|
|
882
|
+
error: tx("actions.resource.error"),
|
|
883
|
+
missing: tx("actions.resource.missing"),
|
|
884
|
+
empty: tx("actions.resource.empty"),
|
|
885
|
+
emptyGetresponse: tx("actions.resource.emptyGetresponse"),
|
|
886
|
+
emptyList: tx("actions.resource.emptyList"),
|
|
887
|
+
confirmationHint: tx("actions.resource.confirmationHint"),
|
|
888
|
+
requiresConfirmation: tx("actions.resource.requiresConfirmation"),
|
|
889
|
+
members: (count) => tx("actions.resource.members", { count }),
|
|
890
|
+
consent: tx("actions.resource.consent"),
|
|
891
|
+
consentHint: tx("actions.resource.consentHint"),
|
|
892
|
+
notConnected: tx("actions.resource.notConnected")
|
|
893
|
+
},
|
|
894
|
+
sendEmail: {
|
|
895
|
+
subject: tx("actions.sendEmail.subject"),
|
|
896
|
+
body: tx("actions.sendEmail.body"),
|
|
897
|
+
bodyHint: tx("actions.sendEmail.bodyHint"),
|
|
898
|
+
insert: tx("actions.sendEmail.insert"),
|
|
899
|
+
insertLabel: (placeholder) => tx("actions.sendEmail.insertLabel", { placeholder }),
|
|
900
|
+
insertNone: tx("actions.sendEmail.insertNone"),
|
|
901
|
+
insertPersona: tx("actions.sendEmail.insertPersona"),
|
|
902
|
+
insertPersonaHint: tx("actions.sendEmail.insertPersonaHint"),
|
|
903
|
+
insertAnswers: tx("actions.sendEmail.insertAnswers"),
|
|
904
|
+
insertAnswersNeedForm: tx("actions.sendEmail.insertAnswersNeedForm"),
|
|
905
|
+
insertAnswersFailed: tx("actions.sendEmail.insertAnswersFailed"),
|
|
906
|
+
insertAnswersHint: tx("actions.sendEmail.insertAnswersHint"),
|
|
907
|
+
replyTo: tx("actions.sendEmail.replyTo"),
|
|
908
|
+
replyToPlaceholder: tx("actions.sendEmail.replyToPlaceholder"),
|
|
909
|
+
content: tx("actions.sendEmail.content"),
|
|
910
|
+
modeTemplate: tx("actions.sendEmail.modeTemplate"),
|
|
911
|
+
modeOwn: tx("actions.sendEmail.modeOwn"),
|
|
912
|
+
pickTemplate: tx("actions.sendEmail.pickTemplate"),
|
|
913
|
+
changeTemplate: tx("actions.sendEmail.changeTemplate"),
|
|
914
|
+
editTemplate: tx("actions.sendEmail.editTemplate"),
|
|
915
|
+
useOwnText: tx("actions.sendEmail.useOwnText"),
|
|
916
|
+
templateEmpty: tx("actions.sendEmail.templateEmpty"),
|
|
917
|
+
templateHint: tx("actions.sendEmail.templateHint"),
|
|
918
|
+
starterHint: tx("actions.sendEmail.starterHint"),
|
|
919
|
+
templateSubject: tx("actions.sendEmail.templateSubject"),
|
|
920
|
+
templatePreviewError: tx("actions.sendEmail.templatePreviewError"),
|
|
921
|
+
templatePreviewLoading: tx("actions.sendEmail.templatePreviewLoading")
|
|
922
|
+
},
|
|
923
|
+
access: {
|
|
924
|
+
product: tx("actions.access.product"),
|
|
925
|
+
pick: tx("actions.access.pick")
|
|
926
|
+
},
|
|
927
|
+
addCustomerTag: {
|
|
928
|
+
tag: tx("actions.addCustomerTag.tag"),
|
|
929
|
+
tagPlaceholder: tx("actions.addCustomerTag.tagPlaceholder")
|
|
930
|
+
},
|
|
931
|
+
delay: {
|
|
932
|
+
amount: tx("actions.delay.amount"),
|
|
933
|
+
unit: tx("actions.delay.unit"),
|
|
934
|
+
minutes: tx("actions.delay.minutes"),
|
|
935
|
+
hours: tx("actions.delay.hours"),
|
|
936
|
+
days: tx("actions.delay.days"),
|
|
937
|
+
hint: tx("actions.delay.hint")
|
|
938
|
+
}
|
|
939
|
+
},
|
|
940
|
+
ai: {
|
|
941
|
+
finalOnly: tx("ai.finalOnly"),
|
|
942
|
+
userRules: tx("ai.userRules"),
|
|
943
|
+
userRulesHint: tx("ai.userRulesHint"),
|
|
944
|
+
mode: tx("ai.mode"),
|
|
945
|
+
modeLabel: (mode) => tx(`ai.modes.${mode}.label`),
|
|
946
|
+
modeHint: (mode) => tx(`ai.modes.${mode}.hint`),
|
|
947
|
+
sensitivity: tx("ai.sensitivity"),
|
|
948
|
+
sensitive: tx("ai.sensitive"),
|
|
949
|
+
nonSensitive: tx("ai.nonSensitive"),
|
|
950
|
+
sensitiveHint: tx("ai.sensitiveHint"),
|
|
951
|
+
nonSensitiveHint: tx("ai.nonSensitiveHint"),
|
|
952
|
+
readMore: tx("ai.readMore"),
|
|
953
|
+
sensitivityExplanation: tx("ai.sensitivityExplanation"),
|
|
954
|
+
outcomes: tx("ai.outcomes"),
|
|
955
|
+
outcomesHint: tx("ai.outcomesHint"),
|
|
956
|
+
outcomeLabel: (index) => tx("ai.outcomeLabel", { index }),
|
|
957
|
+
criteria: tx("ai.criteria"),
|
|
958
|
+
tag: tx("ai.tag"),
|
|
959
|
+
tagHint: tx("ai.tagHint"),
|
|
960
|
+
removeOutcome: tx("ai.removeOutcome"),
|
|
961
|
+
addOutcome: tx("ai.addOutcome"),
|
|
962
|
+
fallback: tx("ai.fallback"),
|
|
963
|
+
fallbackHint: tx("ai.fallbackHint"),
|
|
964
|
+
chooseOutcome: tx("ai.chooseOutcome"),
|
|
965
|
+
simulation: tx("ai.simulation"),
|
|
966
|
+
sample: tx("ai.sample"),
|
|
967
|
+
simulationHint: tx("ai.simulationHint"),
|
|
968
|
+
simulate: tx("ai.simulate"),
|
|
969
|
+
simulating: tx("ai.simulating"),
|
|
970
|
+
simulationFailed: tx("ai.simulationFailed"),
|
|
971
|
+
simulationOutcome: (label) => tx("ai.simulationOutcome", { label }),
|
|
972
|
+
simulationReview: tx("ai.simulationReview"),
|
|
973
|
+
fallbackBadge: tx("ai.fallbackBadge"),
|
|
974
|
+
noAnswer: tx("ai.noAnswer")
|
|
975
|
+
},
|
|
976
|
+
templates: {
|
|
977
|
+
saveAs: tx("templates.save.title"),
|
|
978
|
+
dialogDescription: tx("templates.save.description"),
|
|
979
|
+
name: tx("templates.save.name"),
|
|
980
|
+
description: tx("templates.save.descriptionLabel"),
|
|
981
|
+
replace: tx("templates.save.replace"),
|
|
982
|
+
replacePick: tx("templates.save.replacePick"),
|
|
983
|
+
replaceLoading: tx("templates.save.replaceLoading"),
|
|
984
|
+
notSaved: tx("templates.save.notSaved"),
|
|
985
|
+
submit: tx("templates.save.submit"),
|
|
986
|
+
saving: tx("templates.save.saving"),
|
|
987
|
+
saved: (name) => tx("templates.save.saved", { name }),
|
|
988
|
+
failed: tx("templates.save.failed"),
|
|
989
|
+
conflict: tx("templates.save.conflict"),
|
|
990
|
+
limitReached: tx("templates.save.limitReached"),
|
|
991
|
+
issuesTitle: tx("templates.issues.title"),
|
|
992
|
+
issue: (issue) => tx(`templates.issues.${TEMPLATE_ISSUE_KEYS[issue.code] ?? "other"}`, { detail: issueDetail(tx, env, issue) })
|
|
993
|
+
},
|
|
994
|
+
sheet: {
|
|
995
|
+
titleNew: tx("sheet.titleNew"),
|
|
996
|
+
titleEdit: tx("sheet.titleEdit"),
|
|
997
|
+
titleView: tx("sheet.titleView"),
|
|
998
|
+
description: tx("sheet.description"),
|
|
999
|
+
viewDescription: tx("sheet.viewDescription"),
|
|
1000
|
+
loadFailed: tx("sheet.loadFailed"),
|
|
1001
|
+
legacyNotice: tx("sheet.legacyNotice"),
|
|
1002
|
+
name: tx("sheet.name"),
|
|
1003
|
+
namePlaceholder: tx("sheet.namePlaceholder"),
|
|
1004
|
+
event: tx("sheet.event"),
|
|
1005
|
+
eventPlaceholder: tx("sheet.eventPlaceholder"),
|
|
1006
|
+
eventSearch: tx("sheet.eventSearch"),
|
|
1007
|
+
eventNone: tx("sheet.eventNone"),
|
|
1008
|
+
products: tx("sheet.products"),
|
|
1009
|
+
productsHint: tx("sheet.productsHint"),
|
|
1010
|
+
productsNotApplicable: tx("sheet.productsNotApplicable"),
|
|
1011
|
+
variants: tx("sheet.variants"),
|
|
1012
|
+
variantsHint: tx("sheet.variantsHint"),
|
|
1013
|
+
forms: tx("sheet.forms"),
|
|
1014
|
+
formsAll: tx("sheet.formsAll"),
|
|
1015
|
+
formsHint: tx("sheet.formsHint"),
|
|
1016
|
+
formSearch: tx("sheet.formSearch"),
|
|
1017
|
+
formNone: tx("sheet.formNone"),
|
|
1018
|
+
formRemove: (name) => tx("sheet.formRemove", { name }),
|
|
1019
|
+
formsLoadFailed: tx("sheet.formsLoadFailed"),
|
|
1020
|
+
formDeleted: tx("sheet.formDeleted"),
|
|
1021
|
+
personas: tx("sheet.personas"),
|
|
1022
|
+
personasAll: tx("sheet.personasAll"),
|
|
1023
|
+
personasHint: tx("sheet.personasHint"),
|
|
1024
|
+
personasRulesOnly: tx("sheet.personasRulesOnly"),
|
|
1025
|
+
personaSearch: tx("sheet.personaSearch"),
|
|
1026
|
+
personaNone: tx("sheet.personaNone"),
|
|
1027
|
+
personaRemove: (name) => tx("sheet.personaRemove", { name }),
|
|
1028
|
+
personasLoadFailed: tx("sheet.personasLoadFailed"),
|
|
1029
|
+
personasEmpty: tx("sheet.personasEmpty"),
|
|
1030
|
+
personasEmptyLink: tx("sheet.personasEmptyLink"),
|
|
1031
|
+
personaNegative: tx("sheet.personaNegative"),
|
|
1032
|
+
personaInactive: (name) => tx("sheet.personaInactive", { name }),
|
|
1033
|
+
personaDeleted: tx("sheet.personaDeleted"),
|
|
1034
|
+
skipNegative: tx("sheet.skipNegative"),
|
|
1035
|
+
skipNegativeHint: (name) => tx("sheet.skipNegativeHint", { name }),
|
|
1036
|
+
skipNegativePicked: (name) => tx("sheet.skipNegativePicked", { name }),
|
|
1037
|
+
active: tx("sheet.active"),
|
|
1038
|
+
activeHint: tx("sheet.activeHint"),
|
|
1039
|
+
actions: tx("sheet.actions"),
|
|
1040
|
+
actionsHint: tx("sheet.actionsHint"),
|
|
1041
|
+
actionsEmpty: tx("sheet.actionsEmpty"),
|
|
1042
|
+
invalid: tx("sheet.invalid"),
|
|
1043
|
+
saved: tx("sheet.saved"),
|
|
1044
|
+
created: tx("sheet.created"),
|
|
1045
|
+
saveFailed: tx("sheet.saveFailed"),
|
|
1046
|
+
discardTitle: tx("sheet.discardTitle"),
|
|
1047
|
+
discardDescription: tx("sheet.discardDescription"),
|
|
1048
|
+
keepEditing: tx("sheet.keepEditing"),
|
|
1049
|
+
discardConfirm: tx("sheet.discardConfirm")
|
|
1050
|
+
}
|
|
1051
|
+
};
|
|
1052
|
+
}
|
|
1053
|
+
const TEMPLATE_ISSUE_KEYS = {
|
|
1054
|
+
product_missing: "productMissing",
|
|
1055
|
+
app_not_connected: "appNotConnected",
|
|
1056
|
+
resource_missing: "resourceMissing",
|
|
1057
|
+
event_unavailable: "eventUnavailable",
|
|
1058
|
+
unknown_event: "eventUnavailable",
|
|
1059
|
+
custom_trigger_missing: "customTriggerMissing",
|
|
1060
|
+
email_template_missing: "emailTemplateMissing"
|
|
1061
|
+
};
|
|
1062
|
+
function issueDetail(tx, env, issue) {
|
|
1063
|
+
if (issue.code === "app_not_connected") return tx(`apps.${issue.detail}.name`, { defaultValue: issue.detail });
|
|
1064
|
+
if (issue.code === "event_unavailable" || issue.code === "unknown_event") return env.isKnownEvent(issue.detail) ? tx(`events.${issue.detail}.label`) : issue.detail;
|
|
1065
|
+
return issue.detail;
|
|
1066
|
+
}
|
|
1067
|
+
function buildRunHistoryLabels(tx, locale, env) {
|
|
1068
|
+
const day = (date) => date.toLocaleDateString(locale, {
|
|
1069
|
+
day: "numeric",
|
|
1070
|
+
month: "short"
|
|
1071
|
+
});
|
|
1072
|
+
return {
|
|
1073
|
+
common: buildCommonLabels(tx),
|
|
1074
|
+
catalog: buildCatalogLabels(tx, locale, env),
|
|
1075
|
+
filtersLabel: tx("filters.label"),
|
|
1076
|
+
runs: {
|
|
1077
|
+
label: tx("runs.label"),
|
|
1078
|
+
search: tx("runs.search"),
|
|
1079
|
+
scenario: tx("runs.scenario"),
|
|
1080
|
+
scenarioAll: tx("runs.scenarioAll"),
|
|
1081
|
+
status: tx("runs.status"),
|
|
1082
|
+
statusAll: tx("runs.statusAll"),
|
|
1083
|
+
anyDate: tx("runs.anyDate"),
|
|
1084
|
+
emptyFiltered: tx("runs.emptyFiltered"),
|
|
1085
|
+
emptyTitle: tx("runs.emptyTitle"),
|
|
1086
|
+
emptyDescription: tx("runs.emptyDescription"),
|
|
1087
|
+
time: tx("runs.time"),
|
|
1088
|
+
event: tx("runs.event"),
|
|
1089
|
+
customer: tx("runs.customer"),
|
|
1090
|
+
error: tx("runs.error"),
|
|
1091
|
+
open: tx("runs.open"),
|
|
1092
|
+
deletedScenario: tx("runs.deletedScenario"),
|
|
1093
|
+
noCustomer: tx("runs.noCustomer"),
|
|
1094
|
+
order: (id) => tx("runs.order", { id })
|
|
1095
|
+
},
|
|
1096
|
+
run: {
|
|
1097
|
+
title: tx("run.title"),
|
|
1098
|
+
steps: tx("run.steps"),
|
|
1099
|
+
loadFailed: tx("run.loadFailed"),
|
|
1100
|
+
orderLabel: tx("run.orderLabel"),
|
|
1101
|
+
started: tx("run.started"),
|
|
1102
|
+
resumeAt: tx("run.resumeAt"),
|
|
1103
|
+
finished: tx("run.finished"),
|
|
1104
|
+
noSteps: tx("run.noSteps"),
|
|
1105
|
+
payloadShow: tx("run.payloadShow"),
|
|
1106
|
+
payloadHide: tx("run.payloadHide"),
|
|
1107
|
+
payloadEmpty: tx("run.payloadEmpty"),
|
|
1108
|
+
openScenario: tx("run.openScenario"),
|
|
1109
|
+
retry: tx("run.retry"),
|
|
1110
|
+
retrying: tx("run.retrying"),
|
|
1111
|
+
retried: tx("run.retried"),
|
|
1112
|
+
retryFailed: tx("run.retryFailed")
|
|
1113
|
+
},
|
|
1114
|
+
format: {
|
|
1115
|
+
relative: (ms) => relativeTime(ms, locale, env.format),
|
|
1116
|
+
full: (ms) => new Date(ms).toLocaleString(locale),
|
|
1117
|
+
detail: (ms) => env.format.dateTime(ms, {
|
|
1118
|
+
locale,
|
|
1119
|
+
dateStyle: "medium",
|
|
1120
|
+
timeStyle: "medium",
|
|
1121
|
+
fallback: "—"
|
|
1122
|
+
}),
|
|
1123
|
+
time: (ms) => new Date(ms).toLocaleTimeString(locale),
|
|
1124
|
+
range: (from, to) => !to || to.getTime() === from.getTime() ? day(from) : `${day(from)} – ${day(to)}`
|
|
1125
|
+
}
|
|
1126
|
+
};
|
|
1127
|
+
}
|
|
1128
|
+
function buildAiLearningLabels(tx, env) {
|
|
1129
|
+
return {
|
|
1130
|
+
learning: tx("ai.learning"),
|
|
1131
|
+
loadFailed: tx("common.loadFailed"),
|
|
1132
|
+
tryAgain: tx("common.tryAgain"),
|
|
1133
|
+
progress: (key, count) => tx(`ai.progress.${key}`, { count }),
|
|
1134
|
+
progressCount: (count, total) => tx("ai.progress.count", {
|
|
1135
|
+
count,
|
|
1136
|
+
total
|
|
1137
|
+
}),
|
|
1138
|
+
progressStart: (count) => tx("ai.progress.start", { count }),
|
|
1139
|
+
progressRemaining: (count) => tx("ai.progress.remaining", { count }),
|
|
1140
|
+
progressChanges: tx("ai.progress.changes"),
|
|
1141
|
+
learnedRules: tx("ai.learnedRules"),
|
|
1142
|
+
rulePriority: tx("ai.rulePriority"),
|
|
1143
|
+
noRules: tx("ai.noRules"),
|
|
1144
|
+
ruleChange: (change) => tx(`ai.ruleChange.${change}`),
|
|
1145
|
+
revision: (revision) => tx("ai.revision", { revision }),
|
|
1146
|
+
disabled: tx("ai.disabled"),
|
|
1147
|
+
ruleDestination: (outcome) => tx("ai.ruleDestination", { outcome }),
|
|
1148
|
+
evaluation: (evaluation) => tx("ai.evaluation", evaluation),
|
|
1149
|
+
supportingAssessments: (count) => tx("ai.supportingAssessments", { count }),
|
|
1150
|
+
disable: tx("ai.disable"),
|
|
1151
|
+
restore: tx("ai.restore"),
|
|
1152
|
+
revert: tx("ai.revert"),
|
|
1153
|
+
history: tx("ai.history"),
|
|
1154
|
+
changedElsewhere: tx("ai.changedElsewhere"),
|
|
1155
|
+
date: (iso) => env.format.dateTime(new Date(iso).getTime())
|
|
1156
|
+
};
|
|
1157
|
+
}
|
|
1158
|
+
export { actionDefinition as $, sameEmailTemplateRef as A, ruleDestination as B, parseFieldPath as C, productNameFrom as D, placeholderErrorFromDetail as E, validateScenarioDraft as F, DELAY_MIN_SECONDS as G, ACTION_CATALOG as H, withNegativePersonaRule as I, MAX_ACTIONS_PER_SCENARIO as J, EVENT_GROUP_ORDER as K, withTriggerEvent as L, unknownActionDraft as M, urlHost as N, rootProductId as O, validateDelay as P, actionApp as Q, AI_DECISION_MODES as R, ownTextFromTemplate as S, picksNegativePersona as T, ACTION_KINDS as U, validateAiDecisionConfig as V, DELAY_MAX_SECONDS as W, RUN_STATUSES as X, PICKER_APPS as Y, RUN_STATUS_FILTERS as Z, firstActionWithError as _, presentCategories as a, insertAt as b, templatesInCategory as c, baseProductName as d, delayFromSeconds as f, eventHasForm as g, emptyScenarioDraft as h, hasActiveFilters as i, unitSeconds as j, sameDraft as k, actionErrors as l, emptyActionDraft as m, createLabelDateFormat as n, templateMatches as o, delayToSeconds as p, FILTER_APPS as q, DEFAULT_SCENARIO_FILTERS as r, templateRequirements as s, createAutomationsLabels as t, availablePlaceholders as u, groupEvents as v, parsePlaceholderError as w, moveItem as x, groupProductResults as y, learningProgressKey as z };
|