@getsoren/shared-module 2.54.0 → 2.56.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/events/catalog/clientEvents.d.ts +248 -0
- package/dist/events/catalog/supplierEvents.d.ts +3 -0
- package/dist/events/constants.d.ts +16 -0
- package/dist/events/hooks/useEventDeclaration/useEventDeclaration.d.ts +40 -0
- package/dist/events/hooks/useEventDeclaration/useEventDeclaration.test.d.ts +1 -0
- package/dist/events/index.d.ts +19 -0
- package/dist/events/locales/ar.d.ts +3 -0
- package/dist/events/locales/de.d.ts +3 -0
- package/dist/events/locales/en.d.ts +3 -0
- package/dist/events/locales/es.d.ts +3 -0
- package/dist/events/locales/fr.d.ts +166 -0
- package/dist/events/locales/it.d.ts +3 -0
- package/dist/events/locales/locales.d.ts +3 -0
- package/dist/events/locales/pt.d.ts +3 -0
- package/dist/events/tenants/bouygues/bouygues.d.ts +3 -0
- package/dist/events/tenants/index.d.ts +11 -0
- package/dist/events/tenants/tenants.test.d.ts +1 -0
- package/dist/events/types.d.ts +174 -0
- package/dist/events/utils/amounts/amounts.d.ts +21 -0
- package/dist/events/utils/amounts/amounts.test.d.ts +1 -0
- package/dist/events/utils/payload/payload.d.ts +29 -0
- package/dist/events/utils/payload/payload.test.d.ts +1 -0
- package/dist/events/utils/readEvent/readEvent.d.ts +19 -0
- package/dist/events/utils/readEvent/readEvent.test.d.ts +1 -0
- package/dist/events/utils/steps/steps.d.ts +14 -0
- package/dist/events/utils/steps/steps.test.d.ts +1 -0
- package/dist/events.js +1948 -0
- package/package.json +6 -1
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { EventTexts } from './locales/fr';
|
|
2
|
+
export type EventQuestionKey = keyof EventTexts["questions"];
|
|
3
|
+
export type EventDayHintKey = keyof EventTexts["dayHints"];
|
|
4
|
+
/** The back office that declares: a client and a supplier report different events. */
|
|
5
|
+
export type EventSide = "client" | "supplier";
|
|
6
|
+
export interface EventField {
|
|
7
|
+
/** Value name, also its label key under `fields`. */
|
|
8
|
+
name: keyof EventTexts["fields"];
|
|
9
|
+
type: "number" | "text";
|
|
10
|
+
required?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/** The one date an end of rental asks, per reason. */
|
|
13
|
+
export interface EventEndDate {
|
|
14
|
+
/** Value name the backend reads the new end from. */
|
|
15
|
+
name: "final_toDate" | "new_toDate";
|
|
16
|
+
/** A last day of use can fall from the start of the order, a new end only after its planned end. */
|
|
17
|
+
from: "orderStart" | "afterPlannedEnd";
|
|
18
|
+
question: EventQuestionKey;
|
|
19
|
+
dayHint: EventDayHintKey;
|
|
20
|
+
}
|
|
21
|
+
/** `credit` takes the days lost off at a daily amount (sent negative), `amount` bills a sum. */
|
|
22
|
+
export type EventPriceRule = "credit" | "amount";
|
|
23
|
+
/**
|
|
24
|
+
* A yes/no asked before the amount: whether the client already has the supplier's price (`known`),
|
|
25
|
+
* or whether the supplier bills anything at all (`billed`).
|
|
26
|
+
*/
|
|
27
|
+
export type EventAmountGate = "known" | "billed";
|
|
28
|
+
/** A step whose title an event can word its own way. */
|
|
29
|
+
export type EventQuestionStep = "reason" | "dates" | "fields" | "details";
|
|
30
|
+
export interface EventDefinition {
|
|
31
|
+
/** Stable id, stored in the workflow marker and the label key under `events`. */
|
|
32
|
+
id: string;
|
|
33
|
+
/** Reason sent when the user picks none, or beside a `reasonDetail`. */
|
|
34
|
+
reason?: string;
|
|
35
|
+
/** Choices whose value becomes the reason; labels under `reasons`. */
|
|
36
|
+
reasons?: string[];
|
|
37
|
+
/** Sends the picked choice under this value name and keeps `reason` (e.g. the inventory type). */
|
|
38
|
+
reasonDetail?: "document_type" | "inventory_type";
|
|
39
|
+
/** The user types a title, sent as the reason. */
|
|
40
|
+
hasTitle?: boolean;
|
|
41
|
+
dates?: "range" | "single";
|
|
42
|
+
/** A single date per reason, for an end of rental. */
|
|
43
|
+
endDates?: Partial<Record<string, EventEndDate>>;
|
|
44
|
+
/** Value names of the boxes to tick; labels under `checks`. */
|
|
45
|
+
checks?: (keyof EventTexts["checks"])[];
|
|
46
|
+
fields?: EventField[];
|
|
47
|
+
/** Asks whether the supplier must come on site. */
|
|
48
|
+
hasIntervention?: boolean;
|
|
49
|
+
price?: EventPriceRule;
|
|
50
|
+
amountGate?: EventAmountGate;
|
|
51
|
+
/** The amount asked can be left empty: the event is then declared without one. */
|
|
52
|
+
hasOptionalAmount?: boolean;
|
|
53
|
+
/** Bills hours over the period instead of days. */
|
|
54
|
+
billingType?: "DELTA";
|
|
55
|
+
/** Photos are the point of the event (`focus`), asked first (`first`) or not asked (`none`); optional otherwise. */
|
|
56
|
+
photos?: "first" | "focus" | "none";
|
|
57
|
+
/** Closed on submit for the users allowed to close events. */
|
|
58
|
+
closesOnSubmit?: boolean;
|
|
59
|
+
questions?: Partial<Record<EventQuestionStep, EventQuestionKey>>;
|
|
60
|
+
/** Shown on the hovered and picked day of a one-day event. */
|
|
61
|
+
dayHint?: EventDayHintKey;
|
|
62
|
+
}
|
|
63
|
+
/** A family of events on the first step; its label under `groups`, its question under `groupQuestions`. */
|
|
64
|
+
export interface EventGroup {
|
|
65
|
+
id: keyof EventTexts["groups"];
|
|
66
|
+
/** Event ids, in the order they are offered. */
|
|
67
|
+
events: string[];
|
|
68
|
+
}
|
|
69
|
+
export interface EventPricing {
|
|
70
|
+
/** Amounts are asked and shown. */
|
|
71
|
+
showsPrice: boolean;
|
|
72
|
+
/** A re-billing percentage is asked with each amount. */
|
|
73
|
+
asksReBillRatio: boolean;
|
|
74
|
+
}
|
|
75
|
+
/** What one kind of user declares: a tenant's own, a role's, or the default one of a side. */
|
|
76
|
+
export interface EventFunnel {
|
|
77
|
+
id: string;
|
|
78
|
+
side: EventSide;
|
|
79
|
+
/** Families in the order they are offered; an event belongs to one family. */
|
|
80
|
+
groups: EventGroup[];
|
|
81
|
+
events: EventDefinition[];
|
|
82
|
+
pricing: EventPricing;
|
|
83
|
+
}
|
|
84
|
+
/** A tenant's funnels, and which one a user of the tenant gets. */
|
|
85
|
+
export interface TenantEventFunnels {
|
|
86
|
+
tenants: string[];
|
|
87
|
+
/** Every funnel of the tenant, to read back an event another of its users declared. */
|
|
88
|
+
funnels: EventFunnel[];
|
|
89
|
+
getFunnel: (roleName?: string | null) => EventFunnel;
|
|
90
|
+
}
|
|
91
|
+
export interface EventDates {
|
|
92
|
+
/** YYYY-MM-DD, empty until picked. */
|
|
93
|
+
fromDate: string;
|
|
94
|
+
/** YYYY-MM-DD, same as `fromDate` for a single day. */
|
|
95
|
+
toDate: string;
|
|
96
|
+
}
|
|
97
|
+
/** Everything the user answers but files, which each platform holds its own way. */
|
|
98
|
+
export interface EventAnswers {
|
|
99
|
+
reason: string;
|
|
100
|
+
title: string;
|
|
101
|
+
dates: EventDates;
|
|
102
|
+
checks: Record<string, boolean>;
|
|
103
|
+
fields: Record<string, string>;
|
|
104
|
+
intervention: boolean;
|
|
105
|
+
description: string;
|
|
106
|
+
/** Euros excl. VAT, per day for a credit; typed positive, the sign is set on submit. */
|
|
107
|
+
amount: string;
|
|
108
|
+
/** Percentage re-billed, for the tenants that ask it. */
|
|
109
|
+
reBillRatio: string;
|
|
110
|
+
/** Answer to the event's `amountGate`, unset until asked. */
|
|
111
|
+
amountGate?: boolean;
|
|
112
|
+
}
|
|
113
|
+
export type EventStep = "kind" | "event" | "reason" | "dates" | "checks" | "fields" | "amountGate" | "amount" | "details";
|
|
114
|
+
/** An event and answers to open the declaration on, from a shortcut or the assistant. */
|
|
115
|
+
export interface EventPrefill {
|
|
116
|
+
eventId: string;
|
|
117
|
+
answers: Partial<EventAnswers>;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Stored in place of a Treege tree: enough to read the event back with its definition. A type rather than an
|
|
121
|
+
* interface, so it fits the API's open `{ [key: string]: unknown }` workflow.
|
|
122
|
+
*/
|
|
123
|
+
export type NativeEventWorkflow = {
|
|
124
|
+
source: "soren-event";
|
|
125
|
+
version: 2;
|
|
126
|
+
side: EventSide;
|
|
127
|
+
/** Id of the funnel declared with, whose definition of the event reads it back. */
|
|
128
|
+
funnel: string;
|
|
129
|
+
eventId: string;
|
|
130
|
+
};
|
|
131
|
+
/** The value shape every back office and the backend read; the label is the declaring user's language. */
|
|
132
|
+
export type EventWorkflowValue = {
|
|
133
|
+
name: string;
|
|
134
|
+
type: string;
|
|
135
|
+
label: string;
|
|
136
|
+
value: string | boolean | string[] | {
|
|
137
|
+
label: string;
|
|
138
|
+
value: string;
|
|
139
|
+
};
|
|
140
|
+
tag?: "reason" | "description";
|
|
141
|
+
};
|
|
142
|
+
/** Body of `POST …/incidents` (client) and `POST …/booking_events` (supplier). */
|
|
143
|
+
export interface EventPayload {
|
|
144
|
+
billingType: "DELTA" | "PER_DAY";
|
|
145
|
+
bookingItemId: string | null;
|
|
146
|
+
/**
|
|
147
|
+
* The days to bill, sent even for a single day, which the backend bills as one; null for a period the line bills no
|
|
148
|
+
* day of, which the backend refuses and dates from its value instead.
|
|
149
|
+
*/
|
|
150
|
+
dates: [string, string] | null;
|
|
151
|
+
unitPrice: number | null;
|
|
152
|
+
workflow: NativeEventWorkflow;
|
|
153
|
+
workflowValues: EventWorkflowValue[];
|
|
154
|
+
priceUnit?: "EUR";
|
|
155
|
+
qtyUnit?: "HOURS";
|
|
156
|
+
quantity?: number | null;
|
|
157
|
+
}
|
|
158
|
+
/** An event declared natively, read back from its values. */
|
|
159
|
+
export interface DeclaredEvent {
|
|
160
|
+
/** The definition to show it with, and to edit it with when `editFunnel` is set. */
|
|
161
|
+
event: EventDefinition;
|
|
162
|
+
answers: EventAnswers;
|
|
163
|
+
side: EventSide;
|
|
164
|
+
/**
|
|
165
|
+
* The funnel to edit it with: the reader's own when it asks the same answers, the supplier's for a supplier's event,
|
|
166
|
+
* which a client corrects before closing it. Unset when the reader only shows it (another team's event, a client's
|
|
167
|
+
* event read by a supplier).
|
|
168
|
+
*/
|
|
169
|
+
editFunnel?: EventFunnel;
|
|
170
|
+
}
|
|
171
|
+
/** A key of the `eventDeclaration` namespace: a group of texts, then one of its texts. */
|
|
172
|
+
export type EventTextKey = `${keyof EventTexts}.${string}`;
|
|
173
|
+
/** Translates a key of the `eventDeclaration` namespace, in the language the labels are stored in. */
|
|
174
|
+
export type EventTranslate = (key: EventTextKey) => string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { EventAnswers, EventDefinition } from '../../types';
|
|
2
|
+
export interface EventAmounts {
|
|
3
|
+
/** Negative for a credit, null while there is no amount to send. */
|
|
4
|
+
unitPrice: number | null;
|
|
5
|
+
billableDays: number;
|
|
6
|
+
total: number | null;
|
|
7
|
+
/** A credit only on days the line does not bill (weekend, bank holiday). */
|
|
8
|
+
hasNothingToBill: boolean;
|
|
9
|
+
}
|
|
10
|
+
/** A number typed with either decimal separator (French keyboards type a comma), null when it is not a plain decimal. */
|
|
11
|
+
export declare const toDecimal: (text: string) => number | null;
|
|
12
|
+
/**
|
|
13
|
+
* Null without a price, behind a gate answered no, or while no amount is typed, zero being none; a credit, typed
|
|
14
|
+
* positive, is sent negative.
|
|
15
|
+
*/
|
|
16
|
+
export declare const getUnitPrice: (event: EventDefinition, answers: Pick<EventAnswers, "amount" | "amountGate">) => number | null;
|
|
17
|
+
/**
|
|
18
|
+
* What the event bills. `billableDays` counts the days of a period the line bills (the app knows its calendar).
|
|
19
|
+
* A period of one day counts one whatever the calendar, as the backend bills it, and so does an event without a period.
|
|
20
|
+
*/
|
|
21
|
+
export declare const getEventAmounts: (event: EventDefinition | undefined, answers: EventAnswers, billableDays: number) => EventAmounts;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { EventAnswers, EventDefinition, EventFunnel, EventPayload, EventSide, EventTranslate, NativeEventWorkflow } from '../../types';
|
|
2
|
+
interface BuildEventPayloadParams {
|
|
3
|
+
funnel: EventFunnel;
|
|
4
|
+
event: EventDefinition;
|
|
5
|
+
answers: EventAnswers;
|
|
6
|
+
/** Labels are stored in the declaring user's language, for the screens and exports that only read values. */
|
|
7
|
+
translate: EventTranslate;
|
|
8
|
+
bookingItemId?: string | null;
|
|
9
|
+
/** False when the user sees no price, or a credit falls on no billed day. */
|
|
10
|
+
withPrice: boolean;
|
|
11
|
+
/** Days of its period the order line bills, by the app's calendar (`getEventAmounts`); a period is billed when unknown. */
|
|
12
|
+
billableDays?: number;
|
|
13
|
+
/** Sends the re-billing percentage with the amount, for the users asked it or keeping the one stored. */
|
|
14
|
+
withReBillRatio?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/** The typed title, the picked reason, or the event's own when the pick is a detail. */
|
|
17
|
+
export declare const getReason: (event: EventDefinition, answers: EventAnswers) => string;
|
|
18
|
+
/** Funnel of the events a screen of their own declares and reads back (an end of rental, a quantity variation). */
|
|
19
|
+
export declare const DEDICATED_FUNNEL = "dedicated";
|
|
20
|
+
/** The marker stored with an event a screen of its own declares, in place of the Treege tree it used to fetch. */
|
|
21
|
+
export declare const getDedicatedEventWorkflow: (side: EventSide, eventId: string) => NativeEventWorkflow;
|
|
22
|
+
/** Whether the workflow stored with an event is this engine's marker rather than a Treege tree. */
|
|
23
|
+
export declare const isNativeEventWorkflow: (workflow: unknown) => workflow is NativeEventWorkflow;
|
|
24
|
+
/**
|
|
25
|
+
* The event as the backend stores it: the marker of its definition in place of a Treege tree, and one value per answer.
|
|
26
|
+
* Dates and prices are also sent as fields, which the backend bills from; their values are what the timelines show.
|
|
27
|
+
*/
|
|
28
|
+
declare const buildEventPayload: ({ funnel, event, answers, translate, bookingItemId, withPrice, billableDays, withReBillRatio, }: BuildEventPayloadParams) => EventPayload;
|
|
29
|
+
export default buildEventPayload;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { DeclaredEvent, EventFunnel } from '../../types';
|
|
2
|
+
/** A stored value, as each app's generated client types it. */
|
|
3
|
+
export interface StoredWorkflowValue {
|
|
4
|
+
name?: string | null;
|
|
5
|
+
tag?: unknown;
|
|
6
|
+
value?: unknown;
|
|
7
|
+
}
|
|
8
|
+
interface StoredEvent {
|
|
9
|
+
workflow?: unknown;
|
|
10
|
+
workflowValues?: StoredWorkflowValue[] | null;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* An event declared with this engine, read with the definition it was declared with: a tenant whose funnel changes
|
|
14
|
+
* keeps reading its older events right. The reader edits it with its own definition when that one asks the same
|
|
15
|
+
* answers, a client edits a supplier's with the supplier's questions, and the event is only shown otherwise (another
|
|
16
|
+
* team's, a client's read by a supplier). Undefined for a Treege event.
|
|
17
|
+
*/
|
|
18
|
+
declare const readEvent: ({ workflow, workflowValues }: StoredEvent, readerFunnel: EventFunnel) => DeclaredEvent | undefined;
|
|
19
|
+
export default readEvent;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { EventAnswers, EventDefinition, EventFunnel, EventGroup, EventStep } from '../../types';
|
|
2
|
+
/** A family with the events its funnel offers, in the funnel's order. */
|
|
3
|
+
export interface FunnelGroup extends Omit<EventGroup, "events"> {
|
|
4
|
+
events: EventDefinition[];
|
|
5
|
+
}
|
|
6
|
+
/** The families of the first step, each with the events the funnel offers; a family with none is left out. */
|
|
7
|
+
export declare const getFunnelGroups: ({ groups, events }: EventFunnel) => FunnelGroup[];
|
|
8
|
+
/** The one date of an end of rental, which depends on the end picked. */
|
|
9
|
+
export declare const getEndDate: (event: EventDefinition, reason: string) => import('../../types').EventEndDate | undefined;
|
|
10
|
+
/** `asksAmount` is false for a user who sees no price, or a credit that falls on no billed day. */
|
|
11
|
+
export declare const getSteps: (group: FunnelGroup | undefined, event: EventDefinition | undefined, answers: EventAnswers, asksAmount: boolean) => EventStep[];
|
|
12
|
+
/** First question after the family and the event, skipping a reason already given unless asked again. */
|
|
13
|
+
export declare const getFirstQuestion: (steps: EventStep[], answers: EventAnswers, asksAgain?: boolean) => EventStep;
|
|
14
|
+
export declare const isStepAnswered: (step: EventStep, event: EventDefinition, answers: EventAnswers) => boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|