bitsnap-automations 0.1.0 → 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 +23 -0
- package/chunks/{logic-C_-LFO2j.js → logic-DYkm-4Pc.js} +63 -4
- package/index.js +597 -259
- package/logic.js +1 -1
- package/messages/en.json +41 -1
- package/messages/pl.json +41 -1
- package/messages.js +82 -2
- package/package.json +2 -2
- package/styles.css +1 -1
- package/types/components/ScenarioEditor.d.ts +11 -4
- package/types/labels.d.ts +50 -2
- package/types/logic/catalog.d.ts +1 -1
- package/types/logic/scenario.d.ts +39 -1
- package/types/types.d.ts +30 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
2
|
import type { ScenarioEditorLabels } from "../labels.js";
|
|
3
3
|
import type { AutomationEvent } from "../logic/catalog.js";
|
|
4
|
-
import { type EmailPlaceholder, type ErrorText, type ScenarioDraft } from "../logic/scenario.js";
|
|
5
|
-
import type { ActionServices, AiLearningStep, AppConnections, AppLogos, Load, MutationResult, Notify, ProductSource, TemplateIssue } from "../types.js";
|
|
4
|
+
import { type EmailPlaceholder, type ErrorText, type PlaceholderFilterContext, type ScenarioDraft } from "../logic/scenario.js";
|
|
5
|
+
import type { ActionServices, AiLearningStep, AppConnections, AppLogos, Load, MutationResult, Notify, ProductSource, ScenarioFilterSources, TemplateIssue } from "../types.js";
|
|
6
6
|
import { type SaveScenarioTemplateMeta } from "./SaveScenarioTemplateDialog.js";
|
|
7
7
|
export interface ScenarioEditorProps {
|
|
8
8
|
/** "new" or "edit": the title, and whether Save waits for a change. */
|
|
@@ -35,12 +35,19 @@ export interface ScenarioEditorProps {
|
|
|
35
35
|
* The host's placeholder catalogue for an event (every known token, `available` per event). The
|
|
36
36
|
* "Wyślij e-mail" card offers the available ones as insert chips. Absent: no chips.
|
|
37
37
|
*/
|
|
38
|
-
placeholders?: (triggerEvent: string) => readonly EmailPlaceholder[];
|
|
38
|
+
placeholders?: (triggerEvent: string, context: PlaceholderFilterContext) => readonly EmailPlaceholder[];
|
|
39
39
|
/**
|
|
40
40
|
* The host's placeholder check of an e-mail text on an event (on the catalogue the server saves
|
|
41
41
|
* with). The editor flags what it finds before saving. Absent: only the server checks.
|
|
42
42
|
*/
|
|
43
|
-
checkEmailText?: (text: string, field: "subject" | "body", triggerEvent: string) => ErrorText | undefined;
|
|
43
|
+
checkEmailText?: (text: string, field: "subject" | "body", triggerEvent: string, context: PlaceholderFilterContext) => ErrorText | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* The "Formularz" and "Persona" filters and "Pomiń personę negatywną". A source the host leaves out hides its
|
|
46
|
+
* filter; the draft's value is saved back unchanged.
|
|
47
|
+
*/
|
|
48
|
+
filters?: ScenarioFilterSources;
|
|
49
|
+
/** Every change of the draft (the host may load what the picked forms need, such as their questions). */
|
|
50
|
+
onDraftChange?: (draft: ScenarioDraft) => void;
|
|
44
51
|
/** Problems of a draft opened from a template (missing product, app not connected), shown above the form. */
|
|
45
52
|
templateIssues?: readonly TemplateIssue[];
|
|
46
53
|
/**
|
package/types/labels.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { AiLearningProgressKey, AiDecisionMode } from "./logic/ai-decision.js";
|
|
7
7
|
import type { ActionKind, AutomationApp, AutomationEventGroup, RunStatus } from "./logic/catalog.js";
|
|
8
|
-
import type { DelayUnit, ErrorCode } from "./logic/scenario.js";
|
|
8
|
+
import type { DelayUnit, ErrorCode, FilterErrorCode } from "./logic/scenario.js";
|
|
9
9
|
import type { TemplateIssue } from "./types.js";
|
|
10
10
|
export interface CommonLabels {
|
|
11
11
|
allProducts: string;
|
|
@@ -50,7 +50,9 @@ export interface CatalogLabels {
|
|
|
50
50
|
/** "+3" after the shown action chips. */
|
|
51
51
|
moreActions: (count: number) => string;
|
|
52
52
|
}
|
|
53
|
-
export type ErrorLabels = Record<ErrorCode, string> &
|
|
53
|
+
export type ErrorLabels = Record<Exclude<ErrorCode, FilterErrorCode>, string> &
|
|
54
|
+
/** Added after 0.1.0, so optional: the Polish defaults (`FILTER_ERROR_LABEL_DEFAULTS`) fill a missing one. */
|
|
55
|
+
Partial<Record<FilterErrorCode, string>> & {
|
|
54
56
|
/** A message the server wrote. */
|
|
55
57
|
server: (detail: string) => string;
|
|
56
58
|
/**
|
|
@@ -260,6 +262,18 @@ export interface ActionCardLabels {
|
|
|
260
262
|
insertLabel: (placeholder: string) => string;
|
|
261
263
|
/** No placeholder available for this event (or none chosen yet). */
|
|
262
264
|
insertNone: string;
|
|
265
|
+
/** Heading of the persona chips (`{{persona.name}}`, `{{persona.description}}`). */
|
|
266
|
+
insertPersona?: string;
|
|
267
|
+
/** Under the persona chips: the customer reads what is inserted, and the name is usually internal. */
|
|
268
|
+
insertPersonaHint?: string;
|
|
269
|
+
/** Heading of the form answer chips (`{{answers.<key>}}`). */
|
|
270
|
+
insertAnswers?: string;
|
|
271
|
+
/** A new-lead event with no form picked: pick one to insert its answers. */
|
|
272
|
+
insertAnswersNeedForm?: string;
|
|
273
|
+
/** The questions of a picked form did not load: its answers are not offered. */
|
|
274
|
+
insertAnswersFailed?: string;
|
|
275
|
+
/** Under the answer chips: long answers are cut to 200 characters. */
|
|
276
|
+
insertAnswersHint?: string;
|
|
263
277
|
replyTo: string;
|
|
264
278
|
replyToPlaceholder: string;
|
|
265
279
|
/** Radio group "Treść": template or own text. */
|
|
@@ -380,6 +394,40 @@ export interface ScenarioEditorLabels {
|
|
|
380
394
|
productsNotApplicable: string;
|
|
381
395
|
variants: string;
|
|
382
396
|
variantsHint: string;
|
|
397
|
+
/** "Formularz" filter of the events with a form. */
|
|
398
|
+
forms?: string;
|
|
399
|
+
formsAll?: string;
|
|
400
|
+
formsHint?: string;
|
|
401
|
+
formSearch?: string;
|
|
402
|
+
formNone?: string;
|
|
403
|
+
formRemove?: (name: string) => string;
|
|
404
|
+
formsLoadFailed?: string;
|
|
405
|
+
/** Chip of a picked form the shop no longer has. */
|
|
406
|
+
formDeleted?: string;
|
|
407
|
+
/** "Persona" filter. */
|
|
408
|
+
personas?: string;
|
|
409
|
+
/** Placeholder chip while no persona is picked ("Bez filtra persony"). */
|
|
410
|
+
personasAll?: string;
|
|
411
|
+
personasHint?: string;
|
|
412
|
+
/** On an event with a form: the persona there comes from the rules only, at the moment of the submission. */
|
|
413
|
+
personasRulesOnly?: string;
|
|
414
|
+
personaSearch?: string;
|
|
415
|
+
personaNone?: string;
|
|
416
|
+
personaRemove?: (name: string) => string;
|
|
417
|
+
personasLoadFailed?: string;
|
|
418
|
+
/** The shop has no active persona yet; `personasEmptyLink` opens the host's persona screen. */
|
|
419
|
+
personasEmpty?: string;
|
|
420
|
+
personasEmptyLink?: string;
|
|
421
|
+
/** Suffix of the negative persona in the picker. */
|
|
422
|
+
personaNegative?: string;
|
|
423
|
+
/** Chip of a picked persona that is no longer active. */
|
|
424
|
+
personaInactive?: (name: string) => string;
|
|
425
|
+
/** Chip of a picked persona the shop no longer has. */
|
|
426
|
+
personaDeleted?: string;
|
|
427
|
+
skipNegative?: string;
|
|
428
|
+
skipNegativeHint?: (name: string) => string;
|
|
429
|
+
/** The filter picks the negative persona itself, so "Pomiń personę negatywną" is off and locked. */
|
|
430
|
+
skipNegativePicked?: (name: string) => string;
|
|
383
431
|
active: string;
|
|
384
432
|
activeHint: string;
|
|
385
433
|
actions: string;
|
package/types/logic/catalog.d.ts
CHANGED
|
@@ -35,7 +35,7 @@ export declare const RUN_STATUSES: readonly ["unknown", "pending", "running", "w
|
|
|
35
35
|
export type RunStatus = (typeof RUN_STATUSES)[number];
|
|
36
36
|
/** Statuses offered in the run history's status filter, in display order. */
|
|
37
37
|
export declare const RUN_STATUS_FILTERS: readonly RunStatus[];
|
|
38
|
-
export type AutomationEventGroup = "orders" | "subscriptions" | "access" | "cart" | "testimonials" | "configurators";
|
|
38
|
+
export type AutomationEventGroup = "orders" | "subscriptions" | "access" | "cart" | "testimonials" | "configurators" | "personas";
|
|
39
39
|
/** An event a scenario can listen to, as the host's catalog describes it. */
|
|
40
40
|
export interface AutomationEvent {
|
|
41
41
|
name: string;
|
|
@@ -66,6 +66,15 @@ export interface ScenarioDraft {
|
|
|
66
66
|
actions: ActionDraft[];
|
|
67
67
|
/** Imported from the old MailerLite product rules. */
|
|
68
68
|
legacy: boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Forms the scenario listens to (empty: every form). Only events that carry a form use it (`eventHasForm`);
|
|
71
|
+
* the editor clears it when the event changes to one without a form. Absent: the host has no form filter.
|
|
72
|
+
*/
|
|
73
|
+
formIds?: string[];
|
|
74
|
+
/** Personas the person of the event must be in (empty: any persona or none). Absent: no persona filter. */
|
|
75
|
+
personaIds?: string[];
|
|
76
|
+
/** Skip a person in the negative persona ("Pomiń personę negatywną"). New scenarios start with it on. */
|
|
77
|
+
skipNegativePersona?: boolean;
|
|
69
78
|
}
|
|
70
79
|
/** An e-mail template the "Wyślij e-mail" action sends: a project template, or a Bitsnap starter the server copies on save. */
|
|
71
80
|
export type EmailTemplateRef = {
|
|
@@ -90,6 +99,11 @@ export interface EmailPlaceholder {
|
|
|
90
99
|
key: string;
|
|
91
100
|
label: string;
|
|
92
101
|
available: boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Chip group: `persona` (the persona tokens) and `answers` (a form's answers) show under their own heading.
|
|
104
|
+
* Absent: the event's own tokens, first.
|
|
105
|
+
*/
|
|
106
|
+
group?: "persona" | "answers";
|
|
93
107
|
}
|
|
94
108
|
/** Same template: the same id, or the same starter key. */
|
|
95
109
|
export declare function sameEmailTemplateRef(a: EmailTemplateRef, b: EmailTemplateRef): boolean;
|
|
@@ -97,6 +111,28 @@ export declare function emptyActionDraft(kind: ActionKind): ActionDraft;
|
|
|
97
111
|
/** Draft of an action the package does not know; validation skips it and the card has no fields. */
|
|
98
112
|
export declare function unknownActionDraft(id: string, unknown: UnknownAction): ActionDraft;
|
|
99
113
|
export declare function emptyScenarioDraft(): ScenarioDraft;
|
|
114
|
+
/** True when the event carries a form (the configurator events): the "Formularz" filter applies to it. */
|
|
115
|
+
export declare function eventHasForm(event: Pick<AutomationEvent, "group"> | undefined): boolean;
|
|
116
|
+
/**
|
|
117
|
+
* The draft after its event changed: forms only apply to events with a form, so an event without one drops the
|
|
118
|
+
* picked forms (the server refuses `form_ids` there).
|
|
119
|
+
*/
|
|
120
|
+
export declare function withTriggerEvent(draft: ScenarioDraft, name: string, events: readonly Pick<AutomationEvent, "name" | "group">[]): ScenarioDraft;
|
|
121
|
+
/**
|
|
122
|
+
* The draft with "Pomiń personę negatywną" off when the persona filter picks a negative persona (`negativeIds`):
|
|
123
|
+
* the scenario then runs only for the picked personas, so also skipping the negative one would contradict the
|
|
124
|
+
* filter. The editor locks the checkbox while such a persona is picked and saves `false`.
|
|
125
|
+
*/
|
|
126
|
+
export declare function withNegativePersonaRule(draft: ScenarioDraft, negativeIds: readonly string[]): ScenarioDraft;
|
|
127
|
+
/** True when the persona filter picks one of `negativeIds`. */
|
|
128
|
+
export declare function picksNegativePersona(draft: Pick<ScenarioDraft, "personaIds">, negativeIds: readonly string[]): boolean;
|
|
129
|
+
/**
|
|
130
|
+
* The filter context the host's placeholder catalogue and check read: the forms the scenario picked (their
|
|
131
|
+
* questions become `{{answers.<key>}}` on a new-lead event).
|
|
132
|
+
*/
|
|
133
|
+
export interface PlaceholderFilterContext {
|
|
134
|
+
formIds: readonly string[];
|
|
135
|
+
}
|
|
100
136
|
/** Seconds as the largest unit that divides them; minutes round. */
|
|
101
137
|
export declare function delayFromSeconds(seconds: number): {
|
|
102
138
|
amount: string;
|
|
@@ -132,7 +168,9 @@ export declare function productNameFrom(names: Readonly<Record<string, string>>,
|
|
|
132
168
|
* host maps server failures to `appNotConnected`, `permissionDenied`,
|
|
133
169
|
* `notFound`, or `server:<detail>` for a message the server wrote.
|
|
134
170
|
*/
|
|
135
|
-
export type ErrorCode = "nameRequired" | "nameTooLong" | "eventRequired" | "actionsRequired" | "onlyDelays" | "tooManyActions" | "urlRequired" | "urlInvalid" | "groupRequired" | "listRequired" | "subjectRequired" | "bodyRequired" | "emailTemplateRequired" | "emailTemplateMissing" | "templateLimitReached" | "marketingTemplateNeedsConsent" | "replyToInvalid" | "productRequired" | "tagRequired" | "delay.invalid" | "delay.tooShort" | "delay.tooLong" | "aiConfig" | "aiOutcomes" | "aiFallback" | "aiFinal" | "appNotConnected" | "permissionDenied" | "notFound";
|
|
171
|
+
export type ErrorCode = "nameRequired" | "nameTooLong" | "eventRequired" | "actionsRequired" | "onlyDelays" | "tooManyActions" | "urlRequired" | "urlInvalid" | "groupRequired" | "listRequired" | "subjectRequired" | "bodyRequired" | "emailTemplateRequired" | "emailTemplateMissing" | "templateLimitReached" | "marketingTemplateNeedsConsent" | "replyToInvalid" | "productRequired" | "tagRequired" | "delay.invalid" | "delay.tooShort" | "delay.tooLong" | "aiConfig" | "aiOutcomes" | "aiFallback" | "aiFinal" | "appNotConnected" | "permissionDenied" | "notFound" | FilterErrorCode;
|
|
172
|
+
/** Error codes of the form and persona filters, added after 0.1.0: their labels are optional (Polish defaults). */
|
|
173
|
+
export type FilterErrorCode = "formsNotApplicable" | "formsInvalid" | "formUnknown" | "personasInvalid" | "personaUnknown";
|
|
136
174
|
/**
|
|
137
175
|
* An error code, `server:<detail>` for a message the server wrote, or
|
|
138
176
|
* `placeholder:<issue>:<token>` for a placeholder the event cannot fill
|
package/types/types.d.ts
CHANGED
|
@@ -74,6 +74,36 @@ export interface ProductSource {
|
|
|
74
74
|
name: string;
|
|
75
75
|
}[]>;
|
|
76
76
|
}
|
|
77
|
+
/** A form or persona the scenario filters can pick. */
|
|
78
|
+
export type FilterOption = {
|
|
79
|
+
id: string;
|
|
80
|
+
name: string;
|
|
81
|
+
};
|
|
82
|
+
/** A persona of the "Persona" filter. `active: false` only names a picked persona that left the active set. */
|
|
83
|
+
export type PersonaOption = FilterOption & {
|
|
84
|
+
isNegative: boolean;
|
|
85
|
+
active: boolean;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* The scenario filters beyond products, supplied by the host. Each one it leaves out is not shown, and the
|
|
89
|
+
* draft's value is saved back unchanged.
|
|
90
|
+
*/
|
|
91
|
+
export interface ScenarioFilterSources {
|
|
92
|
+
/** Forms for the "Formularz" filter, shown on events that carry a form (`eventHasForm`). */
|
|
93
|
+
forms?: Load<FilterOption[]>;
|
|
94
|
+
/**
|
|
95
|
+
* Personas for the "Persona" filter and "Pomiń personę negatywną": every persona the picker may name, active
|
|
96
|
+
* ones offered. The checkbox shows when an active negative persona exists.
|
|
97
|
+
*/
|
|
98
|
+
personas?: Load<PersonaOption[]>;
|
|
99
|
+
/** The host's persona screen, linked when the shop has no active persona. */
|
|
100
|
+
personasHref?: string;
|
|
101
|
+
/**
|
|
102
|
+
* True when the questions of a picked form failed to load: "Wyślij e-mail" says its answers are missing (the
|
|
103
|
+
* chips of the forms that did load stay). Absent: never.
|
|
104
|
+
*/
|
|
105
|
+
answersFailed?: (formIds: readonly string[]) => boolean;
|
|
106
|
+
}
|
|
77
107
|
/** Whether an app is connected and where to connect it. Missing: unknown, which never blocks the seller. */
|
|
78
108
|
export type AppConnection = {
|
|
79
109
|
connected: boolean;
|