rapida-partner 8.2.0 → 8.7.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/index.ts +2 -1
- package/package.json +1 -1
- package/src/interfaces/project-backend.interface.ts +11 -0
- package/src/interfaces/store-option.interface.ts +62 -0
- package/src/interfaces/store-order.interface.ts +43 -0
- package/src/interfaces/store-settings.interface.ts +86 -4
- package/src/interfaces/store-variant.interface.ts +27 -0
- package/src/schemas/backend.ref.json +6 -1
- package/src/schemas/project-store.ref.json +5 -1
- package/src/schemas/store-settings.ref.json +42 -0
- package/src/utils/entities.ts +38 -0
- package/src/utils/form-references.test.ts +8 -3
- package/src/utils/form-references.ts +10 -9
- package/src/utils/list-kpi-references.ts +49 -0
- package/src/utils/list-references.test.ts +103 -0
- package/src/utils/list-references.ts +28 -62
- package/src/utils/store-order.ts +5 -0
- package/src/utils/store-references.test.ts +24 -0
- package/src/utils/store-references.ts +11 -0
- package/src/utils/store-segment.test.ts +39 -0
- package/src/utils/store-segment.ts +34 -0
package/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { tsProjectToJsonProject } from "./src/controllers/ts_project_to_json_pro
|
|
|
4
4
|
import { validateProjectJson } from "./src/utils/json";
|
|
5
5
|
import { checkListReferences } from "./src/utils/list-references";
|
|
6
6
|
import { checkFormReferences } from "./src/utils/form-references";
|
|
7
|
+
import { checkStoreReferences } from "./src/utils/store-references";
|
|
7
8
|
import type { IProject } from "./src/interfaces/project.interface";
|
|
8
9
|
import * as fs from "fs";
|
|
9
10
|
import * as path from "path";
|
|
@@ -79,7 +80,7 @@ async function main() {
|
|
|
79
80
|
process.exit(1);
|
|
80
81
|
}
|
|
81
82
|
|
|
82
|
-
for (const warning of [...checkListReferences(project), ...checkFormReferences(project)]) {
|
|
83
|
+
for (const warning of [...checkListReferences(project), ...checkFormReferences(project), ...checkStoreReferences(project)]) {
|
|
83
84
|
console.warn("Aviso: " + warning);
|
|
84
85
|
}
|
|
85
86
|
|
package/package.json
CHANGED
|
@@ -108,6 +108,11 @@ interface IMarketplace {
|
|
|
108
108
|
returnsEndpoint?: string;
|
|
109
109
|
// Artigos do blog (módulo de rapida-projects getStoreBlogModule, funcionalidade "blog").
|
|
110
110
|
blogPostsEndpoint?: string;
|
|
111
|
+
// Grupos de opções e opções dos produtos (módulo de rapida-projects
|
|
112
|
+
// getStoreOptionsModule, funcionalidade "productOptions"). Cada produto lista
|
|
113
|
+
// as opções que oferece em productOptions da configuração de venda.
|
|
114
|
+
optionGroupsEndpoint?: string;
|
|
115
|
+
optionsEndpoint?: string;
|
|
111
116
|
}
|
|
112
117
|
|
|
113
118
|
export interface IMarketplaceProductFieldMap {
|
|
@@ -126,6 +131,12 @@ export interface IMarketplaceProductFieldMap {
|
|
|
126
131
|
length?: string;
|
|
127
132
|
// Lista de propriedades da ficha técnica (padrão "othersProperties").
|
|
128
133
|
properties?: string;
|
|
134
|
+
// Variação como produto filho (funcionalidade "productVariants"): referência
|
|
135
|
+
// ao pai (padrão "parentProductId"), atributos do filho (padrão
|
|
136
|
+
// "variantAttributes") e se a combinação está ativa (padrão "isVariantActive").
|
|
137
|
+
parent?: string;
|
|
138
|
+
variantAttributes?: string;
|
|
139
|
+
variantActive?: string;
|
|
129
140
|
}
|
|
130
141
|
|
|
131
142
|
export interface ISellerServiceAuth {
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Como a opção muda o preço: "add" soma price em reais ao preço unitário (o
|
|
3
|
+
* padrão; ex.: bacon + R$ 3); "percentOff" desconta price por cento do preço do
|
|
4
|
+
* produto (preço por tipo, Fase 3.2; ex.: meia-entrada 50, criança 30).
|
|
5
|
+
*/
|
|
6
|
+
export type TStoreOptionPriceType = "add" | "percentOff";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Grupo de opções do produto (ex.: "Adicionais", "Ponto da carne"), cadastrado
|
|
10
|
+
* no Backoffice do vendedor pelo módulo de rapida-projects getStoreOptionsModule
|
|
11
|
+
* e lido pela loja por IMarketplace.optionGroupsEndpoint (funcionalidade
|
|
12
|
+
* "productOptions"). Os campos são os nomes do form do módulo.
|
|
13
|
+
*/
|
|
14
|
+
export interface IStoreOptionGroup {
|
|
15
|
+
name: string;
|
|
16
|
+
// Com isRequired, o cliente precisa escolher pelo menos uma unidade (ou minChoices).
|
|
17
|
+
isRequired?: boolean;
|
|
18
|
+
// Mínimo de unidades escolhidas no grupo; "bacon ×2" conta 2. Vazio: 1 com
|
|
19
|
+
// isRequired, 0 sem.
|
|
20
|
+
minChoices?: number;
|
|
21
|
+
// Máximo de unidades escolhidas no grupo. 1 é escolha única (ex.: ponto da
|
|
22
|
+
// carne); 0 ou vazio, sem limite.
|
|
23
|
+
maxChoices?: number;
|
|
24
|
+
displayOrder?: number;
|
|
25
|
+
isActive?: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Opção de um grupo (ex.: "Bacon"), com o preço padrão do acréscimo, lida pela
|
|
30
|
+
* loja por IMarketplace.optionsEndpoint. Cada produto oferece as opções que
|
|
31
|
+
* listar em IProductOptionLink, podendo trocar o preço.
|
|
32
|
+
*/
|
|
33
|
+
export interface IStoreOption {
|
|
34
|
+
optionGroupId: string;
|
|
35
|
+
name: string;
|
|
36
|
+
// Acréscimo padrão em reais ("add") ou desconto em % ("percentOff", de 0 a 100); 0 quando não muda o preço.
|
|
37
|
+
price: number;
|
|
38
|
+
// Padrão "add". Opção "percentOff" entra uma vez por linha (maxQuantity é ignorado).
|
|
39
|
+
priceType?: TStoreOptionPriceType;
|
|
40
|
+
// Quantas vezes a mesma opção pode ser escolhida numa linha (padrão 1), até
|
|
41
|
+
// STORE_OPTION_MAX_QUANTITY (src/utils/store-order.ts, 10).
|
|
42
|
+
maxQuantity?: number;
|
|
43
|
+
// Desligado, a opção some de todos os produtos (ex.: o bacon acabou).
|
|
44
|
+
isAvailable?: boolean;
|
|
45
|
+
// Insumo baixado do estoque a cada unidade escolhida (um produto do vendedor).
|
|
46
|
+
supplyProductId?: string;
|
|
47
|
+
// Quanto do insumo sai por unidade escolhida (padrão 1, quando vazio).
|
|
48
|
+
supplyQuantity?: number;
|
|
49
|
+
displayOrder?: number;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Opção oferecida por um produto, no campo productOptions da configuração de
|
|
54
|
+
* venda do produto (form productSellingSettingForm de rapida-projects, que
|
|
55
|
+
* recebe a lista por withProductOptionsInSellingSettings).
|
|
56
|
+
* Sem price, vale o preço padrão da opção; com ele, na mesma unidade do
|
|
57
|
+
* priceType da opção (reais ou %).
|
|
58
|
+
*/
|
|
59
|
+
export interface IProductOptionLink {
|
|
60
|
+
storeOptionId: string;
|
|
61
|
+
price?: number;
|
|
62
|
+
}
|
|
@@ -5,11 +5,39 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export type TStoreOrderFulfillmentStatus = "received" | "preparing" | "shipped" | "delivered" | "cancelled";
|
|
7
7
|
|
|
8
|
+
/** Como o cliente recebe o pedido: entrega no endereço ou retirada na loja. */
|
|
9
|
+
export type TStoreDeliveryMethod = "delivery" | "pickup";
|
|
10
|
+
|
|
11
|
+
/** Como o cliente paga: online (Mercado Pago) ou na entrega/retirada. */
|
|
12
|
+
export type TStorePaymentMethod = "online" | "onDelivery";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Escolha do cliente numa linha do pedido (ex.: grupo "Ponto da carne", opção
|
|
16
|
+
* "Mal passado"). Com a funcionalidade "productOptions", vem de IStoreOption.
|
|
17
|
+
*/
|
|
18
|
+
export interface IStoreOrderItemSelection {
|
|
19
|
+
group: string;
|
|
20
|
+
option: string;
|
|
21
|
+
// Quanto esta escolha muda o preço unitário, em reais, por unidade escolhida:
|
|
22
|
+
// positivo é acréscimo, negativo é desconto (ex.: meia-entrada); 0 ou vazio quando não muda.
|
|
23
|
+
priceDelta?: number;
|
|
24
|
+
// Id da opção (IStoreOption) e quantas vezes foi escolhida (padrão 1).
|
|
25
|
+
optionId?: string;
|
|
26
|
+
quantity?: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
8
29
|
export interface IStoreOrderItem {
|
|
9
30
|
productId: string;
|
|
10
31
|
name: string;
|
|
11
32
|
quantity: number;
|
|
12
33
|
unitPrice: number;
|
|
34
|
+
// Escolhas e observação do cliente nesta linha. Duas linhas do mesmo produto
|
|
35
|
+
// com escolhas ou observação diferentes são linhas separadas.
|
|
36
|
+
selections?: IStoreOrderItemSelection[];
|
|
37
|
+
// Observação do cliente (funcionalidade "itemNotes"), até STORE_ITEM_NOTE_MAX_LENGTH caracteres.
|
|
38
|
+
note?: string;
|
|
39
|
+
// Escolhas em texto para o vendedor (ex.: "Adicionais: Bacon ×2, Queijo").
|
|
40
|
+
selectionsSummary?: string;
|
|
13
41
|
}
|
|
14
42
|
|
|
15
43
|
/**
|
|
@@ -38,6 +66,21 @@ export interface IStoreOrder {
|
|
|
38
66
|
total: number;
|
|
39
67
|
currency: string;
|
|
40
68
|
status: TStoreOrderFulfillmentStatus;
|
|
69
|
+
// Padrão "delivery". Na retirada não há endereço, e "shipped" quer dizer
|
|
70
|
+
// pronto para retirar.
|
|
71
|
+
deliveryMethod?: TStoreDeliveryMethod;
|
|
72
|
+
// Bairro escolhido na entrega por bairro (funcionalidade "districtDelivery").
|
|
73
|
+
deliveryDistrict?: string;
|
|
74
|
+
// Padrão "online". Com "onDelivery", o pedido chega confirmado e sem
|
|
75
|
+
// pagamento: changeFor é o valor para o troco, e o vendedor marca
|
|
76
|
+
// paymentReceived quando receber.
|
|
77
|
+
paymentMethod?: TStorePaymentMethod;
|
|
78
|
+
changeFor?: number;
|
|
79
|
+
paymentReceived?: boolean;
|
|
80
|
+
// Reserva de estoque (Fase 4.3): pago depois da reserva vencer, ou acima do
|
|
81
|
+
// estoque. O vendedor decide: manter, trocar (ex.: de sessão) ou estornar no
|
|
82
|
+
// painel do Mercado Pago; o estorno cancela o pedido na loja.
|
|
83
|
+
overCapacity?: boolean;
|
|
41
84
|
trackingCode?: string;
|
|
42
85
|
trackingUrl?: string;
|
|
43
86
|
notes?: string;
|
|
@@ -14,7 +14,15 @@ export type TStoreFeature =
|
|
|
14
14
|
| "shipping"
|
|
15
15
|
| "coupons"
|
|
16
16
|
| "reviews"
|
|
17
|
-
| "returns"
|
|
17
|
+
| "returns"
|
|
18
|
+
| "openingHours"
|
|
19
|
+
| "pickup"
|
|
20
|
+
| "districtDelivery"
|
|
21
|
+
| "payOnDelivery"
|
|
22
|
+
| "itemNotes"
|
|
23
|
+
| "productOptions"
|
|
24
|
+
| "productVariants"
|
|
25
|
+
| "stockReservation";
|
|
18
26
|
|
|
19
27
|
export type TStoreFeatureToggle = `${TStoreFeature}Enabled`;
|
|
20
28
|
|
|
@@ -24,6 +32,37 @@ export type TStoreFont = "inter" | "poppins" | "nunito" | "montserrat" | "roboto
|
|
|
24
32
|
/** Arredondamento de cartões, botões e campos: reto, suave ou arredondado. */
|
|
25
33
|
export type TStoreRadius = "none" | "soft" | "rounded";
|
|
26
34
|
|
|
35
|
+
/** Dia da semana de um horário de funcionamento. */
|
|
36
|
+
export type TStoreWeekday = "sunday" | "monday" | "tuesday" | "wednesday" | "thursday" | "friday" | "saturday";
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Um período aberto num dia, em "HH:MM" no fuso da loja. Fechar antes de abrir
|
|
40
|
+
* (ex.: 18:00 às 02:00) é atravessar a meia-noite. Um dia pode ter vários
|
|
41
|
+
* períodos (ex.: almoço e jantar).
|
|
42
|
+
*/
|
|
43
|
+
export interface IStoreOpeningHours {
|
|
44
|
+
weekday: TStoreWeekday;
|
|
45
|
+
opensAt: string;
|
|
46
|
+
closesAt: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Bairro atendido pela entrega local, com taxa e prazo mostrado ao cliente. */
|
|
50
|
+
export interface IStoreDeliveryDistrict {
|
|
51
|
+
name: string;
|
|
52
|
+
price: number;
|
|
53
|
+
// Texto livre do prazo (ex.: "40 a 60 min").
|
|
54
|
+
deliveryTime?: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Catálogo em grade de cartões ou em lista (foto pequena ao lado do nome). */
|
|
58
|
+
export type TStoreCatalogLayout = "grid" | "list";
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Proporção da foto no cartão do produto: "auto" mostra a foto inteira numa
|
|
62
|
+
* área fixa (o padrão de sempre); as outras recortam a foto na proporção.
|
|
63
|
+
*/
|
|
64
|
+
export type TStoreImageAspect = "auto" | "square" | "landscape" | "portrait";
|
|
65
|
+
|
|
27
66
|
/**
|
|
28
67
|
* Configuração da loja: identidade, visual, contato, dados legais, redes,
|
|
29
68
|
* comercial e liga e desliga. É o registro único editado no Backoffice do
|
|
@@ -49,6 +88,10 @@ export interface IStoreSettings extends Partial<Record<TStoreFeatureToggle, bool
|
|
|
49
88
|
font?: TStoreFont;
|
|
50
89
|
radius?: TStoreRadius;
|
|
51
90
|
pageSize?: number;
|
|
91
|
+
catalogLayout?: TStoreCatalogLayout;
|
|
92
|
+
// Colunas da grade no computador; só vale com catalogLayout "grid".
|
|
93
|
+
catalogColumns?: 2 | 3 | 4;
|
|
94
|
+
productImageAspect?: TStoreImageAspect;
|
|
52
95
|
|
|
53
96
|
// Somente dígitos, com DDI (ex.: "5582999999999").
|
|
54
97
|
whatsappNumber?: string;
|
|
@@ -82,6 +125,30 @@ export interface IStoreSettings extends Partial<Record<TStoreFeatureToggle, bool
|
|
|
82
125
|
// para compra fora da loja física).
|
|
83
126
|
returnWindowDays?: number;
|
|
84
127
|
|
|
128
|
+
// Só têm efeito com a funcionalidade "openingHours": fora dos períodos, ou
|
|
129
|
+
// com ordersPaused, a loja não aceita pedidos (a API recusa e a vitrine
|
|
130
|
+
// avisa). Sem períodos, a loja fica sempre aberta. timeZone é um fuso IANA
|
|
131
|
+
// (padrão "America/Sao_Paulo"). weekdayHours e saturdayHours continuam como
|
|
132
|
+
// texto de contato.
|
|
133
|
+
openingHours?: IStoreOpeningHours[];
|
|
134
|
+
// Só tem efeito com a funcionalidade "pickup": endereço de retirada mostrado
|
|
135
|
+
// ao cliente; vazio usa address.
|
|
136
|
+
pickupAddress?: string;
|
|
137
|
+
// Só tem efeito com a funcionalidade "districtDelivery": o cliente escolhe o
|
|
138
|
+
// bairro na lista e paga a taxa dele; bairro fora da lista não é atendido.
|
|
139
|
+
// Com ela ligada, o frete por faixa de CEP não é usado.
|
|
140
|
+
deliveryDistricts?: IStoreDeliveryDistrict[];
|
|
141
|
+
// Valor mínimo dos itens (subtotal) para fechar o pedido; 0 ou vazio não
|
|
142
|
+
// exige mínimo. Vale para toda loja com venda própria.
|
|
143
|
+
minimumOrderValue?: number;
|
|
144
|
+
// Funcionalidade "stockReservation": por quantos minutos o pedido aguardando
|
|
145
|
+
// pagamento segura o estoque (de 5 a 60). Vencido o prazo, o pedido é
|
|
146
|
+
// cancelado, o link de pagamento expira e a quantidade volta. Sem o campo,
|
|
147
|
+
// vale o padrão do segmento (STORE_SEGMENT_RESERVATION_MINUTES).
|
|
148
|
+
reservationMinutes?: number;
|
|
149
|
+
timeZone?: string;
|
|
150
|
+
ordersPaused?: boolean;
|
|
151
|
+
|
|
85
152
|
// Páginas institucionais e legais, em HTML (editor de texto rico). Cada
|
|
86
153
|
// página só é publicada, com link no rodapé, quando tem texto. O contato usa
|
|
87
154
|
// os campos de contato acima.
|
|
@@ -130,6 +197,17 @@ export interface IStoreShippingRange {
|
|
|
130
197
|
deliveryDays: number;
|
|
131
198
|
}
|
|
132
199
|
|
|
200
|
+
/**
|
|
201
|
+
* Segmento da loja. Escolhe os padrões do segmento: textos, funcionalidades
|
|
202
|
+
* ligadas, rótulos do andamento do pedido e etapas do checkout. Cada
|
|
203
|
+
* funcionalidade continua podendo ser ligada ou desligada em `features`.
|
|
204
|
+
* - "retail": produtos com envio (o comportamento de sempre).
|
|
205
|
+
* - "food": cardápio, com entrega local ou retirada.
|
|
206
|
+
* - "services": serviços e passeios com data.
|
|
207
|
+
* - "events": shows e teatro, com sessões e ingressos.
|
|
208
|
+
*/
|
|
209
|
+
export type TStoreSegment = "retail" | "food" | "services" | "events";
|
|
210
|
+
|
|
133
211
|
/**
|
|
134
212
|
* Configuração da loja no projeto da própria loja (`IProject.store`).
|
|
135
213
|
*
|
|
@@ -138,9 +216,13 @@ export interface IStoreShippingRange {
|
|
|
138
216
|
* gravação e como reserva se a leitura falhar.
|
|
139
217
|
*/
|
|
140
218
|
export interface IProjectStore {
|
|
141
|
-
//
|
|
142
|
-
//
|
|
143
|
-
|
|
219
|
+
// Um segmento por loja; só vale para skeleton "ecommerce"/"marketplace".
|
|
220
|
+
// Sem ele, a loja se comporta como "retail".
|
|
221
|
+
segment?: TStoreSegment;
|
|
222
|
+
// Funcionalidades opcionais geradas. Sem a lista, vale o padrão do segmento
|
|
223
|
+
// (STORE_SEGMENT_DEFAULT_FEATURES); sem segmento, nenhuma é gerada. Passe a
|
|
224
|
+
// mesma lista (storeFeaturesOf) para getStoreSettingsModule no Backoffice do
|
|
225
|
+
// vendedor, para o form só mostrar o liga e desliga do que a loja tem.
|
|
144
226
|
features?: TStoreFeature[];
|
|
145
227
|
defaults?: IStoreSettings;
|
|
146
228
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Variação como produto filho (funcionalidade "productVariants", Fase 3.3).
|
|
3
|
+
* O produto pai lista os atributos (variantOptions); o Backoffice do vendedor
|
|
4
|
+
* gera um produto filho por combinação, com parentProductId e
|
|
5
|
+
* variantAttributes. Cada filho é um produto com estoque próprio. Os nomes são
|
|
6
|
+
* os padrões de IMarketplaceProductFieldMap (parent, variantAttributes, variantActive).
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/** Atributo do pai e os valores separados por vírgula (ex.: "Tamanho", "P, M, G"). */
|
|
10
|
+
export interface IProductVariantOption {
|
|
11
|
+
attributeName: string;
|
|
12
|
+
attributeValues: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Valor do atributo num filho (ex.: "Tamanho", "M"). */
|
|
16
|
+
export interface IProductVariantAttribute {
|
|
17
|
+
attributeName: string;
|
|
18
|
+
attributeValue: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface IProductVariantFields {
|
|
22
|
+
variantOptions?: IProductVariantOption[];
|
|
23
|
+
parentProductId?: string;
|
|
24
|
+
variantAttributes?: IProductVariantAttribute[];
|
|
25
|
+
// Falso quando a combinação saiu da lista do pai: o filho não é apagado, só some da loja.
|
|
26
|
+
isVariantActive?: boolean;
|
|
27
|
+
}
|
|
@@ -158,6 +158,8 @@
|
|
|
158
158
|
"reviewsEndpoint": { "type": "string" },
|
|
159
159
|
"returnsEndpoint": { "type": "string" },
|
|
160
160
|
"blogPostsEndpoint": { "type": "string" },
|
|
161
|
+
"optionGroupsEndpoint": { "type": "string" },
|
|
162
|
+
"optionsEndpoint": { "type": "string" },
|
|
161
163
|
"productFieldMap": {
|
|
162
164
|
"type": "object",
|
|
163
165
|
"properties": {
|
|
@@ -169,7 +171,10 @@
|
|
|
169
171
|
"height": { "type": "string", "minLength": 1 },
|
|
170
172
|
"width": { "type": "string", "minLength": 1 },
|
|
171
173
|
"length": { "type": "string", "minLength": 1 },
|
|
172
|
-
"properties": { "type": "string", "minLength": 1 }
|
|
174
|
+
"properties": { "type": "string", "minLength": 1 },
|
|
175
|
+
"parent": { "type": "string", "minLength": 1 },
|
|
176
|
+
"variantAttributes": { "type": "string", "minLength": 1 },
|
|
177
|
+
"variantActive": { "type": "string", "minLength": 1 }
|
|
173
178
|
},
|
|
174
179
|
"additionalProperties": false
|
|
175
180
|
}
|
|
@@ -3,11 +3,15 @@
|
|
|
3
3
|
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
4
4
|
"type": "object",
|
|
5
5
|
"properties": {
|
|
6
|
+
"segment": {
|
|
7
|
+
"type": "string",
|
|
8
|
+
"enum": ["retail", "food", "services", "events"]
|
|
9
|
+
},
|
|
6
10
|
"features": {
|
|
7
11
|
"type": "array",
|
|
8
12
|
"items": {
|
|
9
13
|
"type": "string",
|
|
10
|
-
"enum": ["whatsappButton", "stockAvailability", "cashDiscount", "installments", "favorites", "blog", "shipping", "coupons", "reviews", "returns"]
|
|
14
|
+
"enum": ["whatsappButton", "stockAvailability", "cashDiscount", "installments", "favorites", "blog", "shipping", "coupons", "reviews", "returns", "openingHours", "pickup", "districtDelivery", "payOnDelivery", "itemNotes", "productOptions", "productVariants", "stockReservation"]
|
|
11
15
|
},
|
|
12
16
|
"uniqueItems": true
|
|
13
17
|
},
|
|
@@ -14,6 +14,9 @@
|
|
|
14
14
|
},
|
|
15
15
|
"radius": { "type": "string", "enum": ["none", "soft", "rounded"] },
|
|
16
16
|
"pageSize": { "type": "integer", "minimum": 1 },
|
|
17
|
+
"catalogLayout": { "type": "string", "enum": ["grid", "list"] },
|
|
18
|
+
"catalogColumns": { "type": "integer", "enum": [2, 3, 4] },
|
|
19
|
+
"productImageAspect": { "type": "string", "enum": ["auto", "square", "landscape", "portrait"] },
|
|
17
20
|
"whatsappNumber": { "type": "string", "pattern": "^[0-9]{10,15}$" },
|
|
18
21
|
"phone": { "type": "string" },
|
|
19
22
|
"email": { "type": "string" },
|
|
@@ -46,6 +49,37 @@
|
|
|
46
49
|
}
|
|
47
50
|
},
|
|
48
51
|
"returnWindowDays": { "type": "integer", "minimum": 0 },
|
|
52
|
+
"openingHours": {
|
|
53
|
+
"type": "array",
|
|
54
|
+
"items": {
|
|
55
|
+
"type": "object",
|
|
56
|
+
"properties": {
|
|
57
|
+
"weekday": { "type": "string", "enum": ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"] },
|
|
58
|
+
"opensAt": { "type": "string", "pattern": "^([01][0-9]|2[0-3]):[0-5][0-9]$" },
|
|
59
|
+
"closesAt": { "type": "string", "pattern": "^([01][0-9]|2[0-3]):[0-5][0-9]$" }
|
|
60
|
+
},
|
|
61
|
+
"required": ["weekday", "opensAt", "closesAt"],
|
|
62
|
+
"additionalProperties": false
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"timeZone": { "type": "string" },
|
|
66
|
+
"pickupAddress": { "type": "string" },
|
|
67
|
+
"deliveryDistricts": {
|
|
68
|
+
"type": "array",
|
|
69
|
+
"items": {
|
|
70
|
+
"type": "object",
|
|
71
|
+
"properties": {
|
|
72
|
+
"name": { "type": "string", "minLength": 1 },
|
|
73
|
+
"price": { "type": "number", "minimum": 0 },
|
|
74
|
+
"deliveryTime": { "type": "string" }
|
|
75
|
+
},
|
|
76
|
+
"required": ["name", "price"],
|
|
77
|
+
"additionalProperties": false
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
"minimumOrderValue": { "type": "number", "minimum": 0 },
|
|
81
|
+
"reservationMinutes": { "type": "integer", "minimum": 5, "maximum": 60 },
|
|
82
|
+
"ordersPaused": { "type": "boolean" },
|
|
49
83
|
"aboutText": { "type": "string" },
|
|
50
84
|
"privacyPolicyText": { "type": "string" },
|
|
51
85
|
"termsText": { "type": "string" },
|
|
@@ -89,6 +123,14 @@
|
|
|
89
123
|
"shippingEnabled": { "type": "boolean" },
|
|
90
124
|
"couponsEnabled": { "type": "boolean" },
|
|
91
125
|
"reviewsEnabled": { "type": "boolean" },
|
|
126
|
+
"openingHoursEnabled": { "type": "boolean" },
|
|
127
|
+
"pickupEnabled": { "type": "boolean" },
|
|
128
|
+
"districtDeliveryEnabled": { "type": "boolean" },
|
|
129
|
+
"payOnDeliveryEnabled": { "type": "boolean" },
|
|
130
|
+
"itemNotesEnabled": { "type": "boolean" },
|
|
131
|
+
"productOptionsEnabled": { "type": "boolean" },
|
|
132
|
+
"productVariantsEnabled": { "type": "boolean" },
|
|
133
|
+
"stockReservationEnabled": { "type": "boolean" },
|
|
92
134
|
"returnsEnabled": { "type": "boolean" }
|
|
93
135
|
},
|
|
94
136
|
"additionalProperties": false
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { IComponent, IModule, IProject } from "../interfaces/project.interface";
|
|
2
|
+
|
|
3
|
+
export interface IFormEntity {
|
|
4
|
+
component: IComponent;
|
|
5
|
+
endpoint: string;
|
|
6
|
+
ownsEntity: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface IEntitySource {
|
|
10
|
+
id: string;
|
|
11
|
+
componentType: string;
|
|
12
|
+
contracts?: { id?: string; endpoint?: string }[];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Mesma regra do kebabfy do gerador: "payableAccount" e "PayableAccount" viram "payable-account".
|
|
16
|
+
const kebab = (text: string): string =>
|
|
17
|
+
text.match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g)?.map((part: string) => part.toLowerCase()).join("-") ||
|
|
18
|
+
text.toLowerCase();
|
|
19
|
+
|
|
20
|
+
export const normalizeEndpoint = (endpoint: string): string => endpoint.replace(/^\/+|\/+$/g, "");
|
|
21
|
+
|
|
22
|
+
// O backend gerado cria uma entidade por form ou kanban, pelo id do primeiro contrato (ou do componente).
|
|
23
|
+
// Quando dois componentes dão a mesma entidade, só o primeiro do projeto gera o backend.
|
|
24
|
+
export const formEntitiesOf = (project: IProject): IFormEntity[] => {
|
|
25
|
+
const seen = new Set<string>();
|
|
26
|
+
return (project.modules ?? []).flatMap((module: IModule): IFormEntity[] =>
|
|
27
|
+
module.components.flatMap((component: IComponent): IFormEntity[] => {
|
|
28
|
+
if (component.componentType !== "form" && component.componentType !== "kanban") return [];
|
|
29
|
+
const source = component as unknown as IEntitySource;
|
|
30
|
+
const contract = source.contracts?.[0];
|
|
31
|
+
const key: string = kebab(contract?.id || source.id || "Unnamed");
|
|
32
|
+
const ownsEntity: boolean = !seen.has(key);
|
|
33
|
+
seen.add(key);
|
|
34
|
+
if (component.componentType !== "form") return [];
|
|
35
|
+
return [{ component, endpoint: normalizeEndpoint(contract?.endpoint || key), ownsEntity }];
|
|
36
|
+
}),
|
|
37
|
+
);
|
|
38
|
+
};
|
|
@@ -29,9 +29,14 @@ describe("recordTimestamp", () => {
|
|
|
29
29
|
expect(warnings).toEqual(["f: recordTimestamp em \"terms\" está dentro de um array; só vale no nível de cima do form, e o aceite não é registrado"]);
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
-
test("num segundo form do módulo
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
test("num segundo form do módulo, com entidade própria, grava normalmente", () => {
|
|
33
|
+
expect(checkFormReferences(projectWith([form("first", [input("name")]), form("second", [consent("terms")])]))).toEqual([]);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("num form que repete a entidade de um form anterior avisa que o aceite não é registrado", () => {
|
|
37
|
+
const contracts = [{ id: "people", endpoint: "/people", actions: ["create"] }];
|
|
38
|
+
const warnings = checkFormReferences(projectWith([{ ...form("first", [input("name")]), contracts }, { ...form("second", [consent("terms")]), contracts }]));
|
|
39
|
+
expect(warnings).toEqual(["second: recordTimestamp em \"terms\" não grava nada: o form usa a mesma entidade (contracts[0].id) de outro form anterior, e o backend vem daquele"]);
|
|
35
40
|
});
|
|
36
41
|
|
|
37
42
|
test("forms de perfil (pessoa e empresa) também gravam, e a colisão é conferida", () => {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { IForm } from "../interfaces/form.interface";
|
|
2
|
-
import type {
|
|
2
|
+
import type { IProject } from "../interfaces/project.interface";
|
|
3
|
+
import { formEntitiesOf, type IFormEntity } from "./entities";
|
|
3
4
|
import { fieldScopes, type IFlatElement } from "./form-elements";
|
|
4
5
|
|
|
5
6
|
const RESERVED_FIELDS: string[] = ["createdAt", "createdBy", "updatedAt", "updatedBy", "deletedAt", "workspaceId"];
|
|
@@ -20,7 +21,7 @@ const consentWarnings = (form: IFormToCheck, fields: IFlatElement[], isRoot: boo
|
|
|
20
21
|
return switches.map((field: IFlatElement) => form.id + ": recordTimestamp em \"" + field.name + "\" está dentro de um array; só vale no nível de cima do form, e o aceite não é registrado");
|
|
21
22
|
}
|
|
22
23
|
if (!form.recordsConsent) {
|
|
23
|
-
return switches.map((field: IFlatElement) => form.id + ": recordTimestamp em \"" + field.name + "\"
|
|
24
|
+
return switches.map((field: IFlatElement) => form.id + ": recordTimestamp em \"" + field.name + "\" não grava nada: o form usa a mesma entidade (contracts[0].id) de outro form anterior, e o backend vem daquele");
|
|
24
25
|
}
|
|
25
26
|
const names = new Set(fields.flatMap((field: IFlatElement): string[] => (field.name ? [backendName(field.name)] : [])));
|
|
26
27
|
return switches.flatMap((field: IFlatElement): string[] =>
|
|
@@ -41,14 +42,14 @@ const formWarnings = (form: IFormToCheck): string[] =>
|
|
|
41
42
|
...consentWarnings(form, fields, index === 0),
|
|
42
43
|
]);
|
|
43
44
|
|
|
44
|
-
//
|
|
45
|
-
// collection só, então os dois gravam.
|
|
45
|
+
// Cada form gera a própria entidade e grava o consentimento, menos quando repete a entidade de um form
|
|
46
|
+
// anterior. Os forms de perfil viram uma collection só, então os dois gravam.
|
|
46
47
|
const formsOf = (project: IProject): IFormToCheck[] => [
|
|
47
|
-
...(project
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
),
|
|
48
|
+
...formEntitiesOf(project).map((entity: IFormEntity) => ({
|
|
49
|
+
id: entity.component.id,
|
|
50
|
+
elements: "elements" in entity.component ? entity.component.elements : undefined,
|
|
51
|
+
recordsConsent: entity.ownsEntity,
|
|
52
|
+
})),
|
|
52
53
|
...[project.flows?.profiles?.personProfile, project.flows?.profiles?.companyProfile]
|
|
53
54
|
.filter((form: IForm | undefined): form is IForm => !!form)
|
|
54
55
|
.map((form: IForm) => ({ id: form.id, elements: form.elements, recordsConsent: true })),
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { IList, IListKpi } from "../interfaces/list.interface";
|
|
2
|
+
import type { IComponent } from "../interfaces/project.interface";
|
|
3
|
+
import { normalizeEndpoint, type IFormEntity } from "./entities";
|
|
4
|
+
import { fieldScopes, NUMERIC_DATA_TYPES, type IFlatElement } from "./form-elements";
|
|
5
|
+
|
|
6
|
+
export type TKpiFields = Map<string, IFlatElement>;
|
|
7
|
+
|
|
8
|
+
const topLevelFields = (components: IComponent[]): TKpiFields =>
|
|
9
|
+
new Map(
|
|
10
|
+
components
|
|
11
|
+
.flatMap((component: IComponent): IFlatElement[] => ("elements" in component ? fieldScopes(component.elements)[0] : []))
|
|
12
|
+
.flatMap((field: IFlatElement): [string, IFlatElement][] => (field.name ? [[field.name, field]] : [])),
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
// A rota de soma e a contagem são da entidade da lista (dataSource.endpoint): vale só o nível de cima do
|
|
16
|
+
// form dessa entidade. Sem form com esse endpoint, cai nos forms do módulo.
|
|
17
|
+
export const kpiFieldsOf = (list: IList, entities: IFormEntity[], moduleForms: IComponent[]): { fields: TKpiFields; source: string } => {
|
|
18
|
+
const endpoint: string = normalizeEndpoint(list.dataSource?.endpoint ?? "");
|
|
19
|
+
const entity: IFormEntity | undefined = entities.find((item: IFormEntity) => item.ownsEntity && item.endpoint === endpoint);
|
|
20
|
+
return entity
|
|
21
|
+
? { fields: topLevelFields([entity.component]), source: "no form " + entity.component.id + " (entidade de /" + endpoint + ")" }
|
|
22
|
+
: { fields: topLevelFields(moduleForms), source: "no nível de cima de nenhum form do módulo" };
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const sumOfWarnings = (list: IList, kpi: IListKpi, fields: TKpiFields, source: string): string[] => {
|
|
26
|
+
if (!kpi.sumOf) return [];
|
|
27
|
+
const field: IFlatElement | undefined = fields.get(kpi.sumOf);
|
|
28
|
+
if (!field) return [list.id + ": kpis.sumOf \"" + kpi.sumOf + "\" não existe " + source + " (campos de array não valem)"];
|
|
29
|
+
const isNumeric: boolean = NUMERIC_DATA_TYPES.includes((field.dataType ?? "").toLowerCase());
|
|
30
|
+
if (field.type !== "input" || !isNumeric) {
|
|
31
|
+
return [list.id + ": kpis.sumOf \"" + kpi.sumOf + "\" não é um input numérico; a rota de soma só soma inputs numéricos"];
|
|
32
|
+
}
|
|
33
|
+
return [];
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const kpiWarnings = (list: IList, fields: TKpiFields, source: string): string[] => {
|
|
37
|
+
const kpis: IListKpi[] = list.kpis ?? [];
|
|
38
|
+
const brand: string[] =
|
|
39
|
+
kpis.filter((kpi: IListKpi) => kpi.tone === "brand").length > 1 ? [list.id + ": mais de um KPI com tone \"brand\"; use no máximo um"] : [];
|
|
40
|
+
return [
|
|
41
|
+
...brand,
|
|
42
|
+
...kpis.flatMap((kpi: IListKpi): string[] => [
|
|
43
|
+
...sumOfWarnings(list, kpi, fields, source),
|
|
44
|
+
...(Array.isArray(kpi.filter) ? kpi.filter : [])
|
|
45
|
+
.filter((condition) => !fields.has(condition.field))
|
|
46
|
+
.map((condition) => list.id + ": kpis.filter cita o campo \"" + condition.field + "\", que não existe " + source + " (campos de array não valem)"),
|
|
47
|
+
]),
|
|
48
|
+
];
|
|
49
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import type { IProject } from "../interfaces/project.interface";
|
|
3
|
+
import { checkListReferences } from "./list-references";
|
|
4
|
+
|
|
5
|
+
const input = (name: string, dataType: string = "text"): Record<string, unknown> => ({ type: "input", name, label: name, dataType });
|
|
6
|
+
const form = (id: string, endpoint: string, elements: unknown[]): Record<string, unknown> => ({
|
|
7
|
+
componentType: "form",
|
|
8
|
+
id,
|
|
9
|
+
elements,
|
|
10
|
+
contracts: [{ id, endpoint, actions: ["create"] }],
|
|
11
|
+
});
|
|
12
|
+
const list = (extra: Record<string, unknown>): Record<string, unknown> => ({
|
|
13
|
+
componentType: "list",
|
|
14
|
+
id: "billList",
|
|
15
|
+
dataSource: { endpoint: "/bills", paramType: "query" },
|
|
16
|
+
listItems: [],
|
|
17
|
+
...extra,
|
|
18
|
+
});
|
|
19
|
+
const projectWith = (components: unknown[]): IProject => ({ id: "p", modules: [{ id: "m", components }] }) as unknown as IProject;
|
|
20
|
+
|
|
21
|
+
const billForm = form("bill", "/bills", [
|
|
22
|
+
input("amount", "currency"),
|
|
23
|
+
input("status"),
|
|
24
|
+
{ type: "select", name: "qty", label: "qty", dataType: "number", options: [] },
|
|
25
|
+
{ type: "array", name: "deps", label: "deps", elements: [input("price", "number")] },
|
|
26
|
+
]);
|
|
27
|
+
const otherForm = form("other", "/others", [input("otherTotal", "currency")]);
|
|
28
|
+
|
|
29
|
+
describe("kpis", () => {
|
|
30
|
+
test("sumOf num input numérico do form da lista não avisa", () => {
|
|
31
|
+
expect(checkListReferences(projectWith([billForm, otherForm, list({ kpis: [{ label: "a", sumOf: "amount" }] })]))).toEqual([]);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test("sumOf de outro form do módulo avisa, porque a soma é da entidade da lista", () => {
|
|
35
|
+
const warnings = checkListReferences(projectWith([billForm, otherForm, list({ kpis: [{ label: "a", sumOf: "otherTotal" }] })]));
|
|
36
|
+
expect(warnings).toEqual(["billList: kpis.sumOf \"otherTotal\" não existe no form bill (entidade de /bills) (campos de array não valem)"]);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("sumOf que não é input avisa, mesmo com dataType numérico", () => {
|
|
40
|
+
const warnings = checkListReferences(projectWith([billForm, list({ kpis: [{ label: "a", sumOf: "qty" }] })]));
|
|
41
|
+
expect(warnings).toEqual(["billList: kpis.sumOf \"qty\" não é um input numérico; a rota de soma só soma inputs numéricos"]);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("sumOf de texto e campo de array avisam", () => {
|
|
45
|
+
const warnings = checkListReferences(projectWith([billForm, list({ kpis: [{ label: "a", sumOf: "status" }, { label: "b", sumOf: "price" }] })]));
|
|
46
|
+
expect(warnings).toEqual([
|
|
47
|
+
"billList: kpis.sumOf \"status\" não é um input numérico; a rota de soma só soma inputs numéricos",
|
|
48
|
+
"billList: kpis.sumOf \"price\" não existe no form bill (entidade de /bills) (campos de array não valem)",
|
|
49
|
+
]);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("filter só aceita campos do form da lista", () => {
|
|
53
|
+
const kpis = [{ label: "a", filter: [{ field: "status", op: "eq", value: "open" }, { field: "otherTotal", op: "gt", value: 0 }] }];
|
|
54
|
+
expect(checkListReferences(projectWith([billForm, otherForm, list({ kpis })]))).toEqual([
|
|
55
|
+
"billList: kpis.filter cita o campo \"otherTotal\", que não existe no form bill (entidade de /bills) (campos de array não valem)",
|
|
56
|
+
]);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test("sem form com o endpoint da lista, confere contra os forms do módulo", () => {
|
|
60
|
+
const warnings = checkListReferences(projectWith([otherForm, list({ kpis: [{ label: "a", sumOf: "otherTotal" }, { label: "b", sumOf: "nope" }] })]));
|
|
61
|
+
expect(warnings).toEqual(["billList: kpis.sumOf \"nope\" não existe no nível de cima de nenhum form do módulo (campos de array não valem)"]);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test("mais de um brand avisa", () => {
|
|
65
|
+
const kpis = [{ label: "a", tone: "brand" }, { label: "b", tone: "brand" }];
|
|
66
|
+
expect(checkListReferences(projectWith([billForm, list({ kpis })]))).toEqual(["billList: mais de um KPI com tone \"brand\"; use no máximo um"]);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
describe("columnGroup", () => {
|
|
71
|
+
const item = (property: string, columnGroup?: string): Record<string, unknown> => ({ property, label: property, dataType: "text", ...(columnGroup ? { columnGroup } : {}) });
|
|
72
|
+
|
|
73
|
+
test("grupos juntos e colunas sem grupo nas pontas não avisam", () => {
|
|
74
|
+
expect(checkListReferences(projectWith([billForm, list({ listItems: [item("a"), item("b", "Valores"), item("c", "Valores"), item("d")] })]))).toEqual([]);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("grupo interrompido por outro grupo avisa", () => {
|
|
78
|
+
const listItems = [item("a", "Valores"), item("b", "Datas"), item("c", "Valores")];
|
|
79
|
+
expect(checkListReferences(projectWith([billForm, list({ listItems })]))).toEqual(["billList: o columnGroup \"Valores\" aparece separado; deixe as colunas do mesmo grupo juntas"]);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("grupo interrompido por uma coluna sem grupo avisa", () => {
|
|
83
|
+
const listItems = [item("a", "Valores"), item("b"), item("c", "Valores")];
|
|
84
|
+
expect(checkListReferences(projectWith([billForm, list({ listItems })]))).toEqual(["billList: o columnGroup \"Valores\" aparece separado; deixe as colunas do mesmo grupo juntas"]);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
describe("quickFilters, tabs e columnViews", () => {
|
|
89
|
+
test("nomes que não existem avisam", () => {
|
|
90
|
+
const warnings = checkListReferences(
|
|
91
|
+
projectWith([billForm, list({ quickFilters: ["status"], listFilters: [], tabs: { property: "nope" }, columnViews: [{ label: "v", columns: ["ghost"] }] })]),
|
|
92
|
+
);
|
|
93
|
+
expect(warnings).toEqual([
|
|
94
|
+
"billList: quickFilters cita \"status\", que não está em listFilters",
|
|
95
|
+
"billList: tabs.property \"nope\" não existe em nenhum form do módulo e tabs.options está vazio",
|
|
96
|
+
"billList: columnViews cita a coluna \"ghost\", que não está em listItems",
|
|
97
|
+
]);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test("tabs.property aceita campo de dentro de array", () => {
|
|
101
|
+
expect(checkListReferences(projectWith([billForm, list({ tabs: { property: "price" } })]))).toEqual([]);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
@@ -1,31 +1,17 @@
|
|
|
1
1
|
import type { IList } from "../interfaces/list.interface";
|
|
2
2
|
import type { IComponent, IModule, IProject } from "../interfaces/project.interface";
|
|
3
|
-
import {
|
|
3
|
+
import { formEntitiesOf, type IFormEntity } from "./entities";
|
|
4
|
+
import { allFields, type IFlatElement } from "./form-elements";
|
|
5
|
+
import { kpiFieldsOf, kpiWarnings } from "./list-kpi-references";
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
names: Set<string>;
|
|
7
|
-
fields: Map<string, IFlatElement>;
|
|
8
|
-
}
|
|
7
|
+
const NO_GROUP: string = "<sem grupo>";
|
|
9
8
|
|
|
10
9
|
const namesOf = (elements: unknown[] | undefined): Set<string> =>
|
|
11
10
|
new Set(allFields(elements).flatMap((field: IFlatElement): string[] => (field.name ? [field.name] : [])));
|
|
12
11
|
|
|
13
12
|
const isList = (component: IComponent): component is IList => component.componentType === "list";
|
|
14
13
|
|
|
15
|
-
const
|
|
16
|
-
fields.flatMap((field: IFlatElement): [string, IFlatElement][] => (field.name ? [[field.name, field]] : []));
|
|
17
|
-
|
|
18
|
-
// names: todos os campos, inclusive de arrays (tabs.property). fields: só o nível de cima de cada form,
|
|
19
|
-
// que é o que o registro tem e o que os KPIs conseguem contar e somar.
|
|
20
|
-
const moduleFieldsOf = (module: IModule): IModuleFields => {
|
|
21
|
-
const elementsOf = (component: IComponent): unknown[] | undefined =>
|
|
22
|
-
component.componentType === "form" ? component.elements : undefined;
|
|
23
|
-
const forms: IComponent[] = module.components.filter((component: IComponent) => component.componentType === "form");
|
|
24
|
-
return {
|
|
25
|
-
names: new Set(namedFields(forms.flatMap((form: IComponent) => allFields(elementsOf(form)))).map(([name]) => name)),
|
|
26
|
-
fields: new Map(namedFields(forms.flatMap((form: IComponent) => fieldScopes(elementsOf(form))[0]))),
|
|
27
|
-
};
|
|
28
|
-
};
|
|
14
|
+
const isForm = (component: IComponent): boolean => component.componentType === "form";
|
|
29
15
|
|
|
30
16
|
const columnViewWarnings = (list: IList): string[] => {
|
|
31
17
|
const properties = new Set(list.listItems.map((item) => item.property).filter(Boolean));
|
|
@@ -36,64 +22,44 @@ const columnViewWarnings = (list: IList): string[] => {
|
|
|
36
22
|
);
|
|
37
23
|
};
|
|
38
24
|
|
|
25
|
+
// Compara cada coluna com a anterior, contando "sem grupo" como um grupo, para pegar também um grupo
|
|
26
|
+
// interrompido por uma coluna sem columnGroup.
|
|
39
27
|
const columnGroupWarnings = (list: IList): string[] => {
|
|
40
|
-
|
|
41
|
-
const
|
|
28
|
+
if (!list.listItems.some((item) => item.columnGroup)) return [];
|
|
29
|
+
const groups: string[] = list.listItems.map((item) => (item.columnGroup ? JSON.stringify(item.columnGroup) : NO_GROUP));
|
|
30
|
+
const closed = new Set<string>();
|
|
42
31
|
const warnings: string[] = [];
|
|
43
32
|
groups.forEach((group: string, index: number) => {
|
|
44
|
-
|
|
33
|
+
const previous: string | undefined = groups[index - 1];
|
|
34
|
+
if (previous !== undefined && previous !== group) closed.add(previous);
|
|
35
|
+
if (group !== NO_GROUP && group !== previous && closed.has(group)) {
|
|
45
36
|
warnings.push(list.id + ": o columnGroup " + group + " aparece separado; deixe as colunas do mesmo grupo juntas");
|
|
46
37
|
}
|
|
47
|
-
if (!seen.includes(group)) seen.push(group);
|
|
48
38
|
});
|
|
49
39
|
return warnings;
|
|
50
40
|
};
|
|
51
41
|
|
|
52
|
-
const
|
|
53
|
-
const kpis = list.kpis ?? [];
|
|
54
|
-
const warnings: string[] = [];
|
|
55
|
-
if (kpis.filter((kpi) => kpi.tone === "brand").length > 1) {
|
|
56
|
-
warnings.push(list.id + ": mais de um KPI com tone \"brand\"; use no máximo um");
|
|
57
|
-
}
|
|
58
|
-
for (const kpi of kpis) {
|
|
59
|
-
if (kpi.sumOf) {
|
|
60
|
-
const field = fields.get(kpi.sumOf);
|
|
61
|
-
if (!field) warnings.push(list.id + ": kpis.sumOf \"" + kpi.sumOf + "\" não existe no nível de cima de nenhum form do módulo (campos de array não valem)");
|
|
62
|
-
else if (!NUMERIC_DATA_TYPES.includes((field.dataType ?? "").toLowerCase())) {
|
|
63
|
-
warnings.push(list.id + ": kpis.sumOf \"" + kpi.sumOf + "\" não é um campo numérico");
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
for (const condition of Array.isArray(kpi.filter) ? kpi.filter : []) {
|
|
67
|
-
if (!fields.has(condition.field)) {
|
|
68
|
-
warnings.push(list.id + ": kpis.filter cita o campo \"" + condition.field + "\", que não existe no nível de cima de nenhum form do módulo (campos de array não valem)");
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return warnings;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
const listWarnings = (list: IList, moduleFields: IModuleFields): string[] => {
|
|
42
|
+
const listWarnings = (list: IList, module: IModule, entities: IFormEntity[]): string[] => {
|
|
76
43
|
const warnings: string[] = [];
|
|
44
|
+
const moduleForms: IComponent[] = module.components.filter(isForm);
|
|
77
45
|
const filterNames: Set<string> = namesOf(list.listFilters);
|
|
78
46
|
for (const name of list.quickFilters ?? []) {
|
|
79
|
-
if (!filterNames.has(name))
|
|
80
|
-
warnings.push(list.id + ": quickFilters cita \"" + name + "\", que não está em listFilters");
|
|
81
|
-
}
|
|
47
|
+
if (!filterNames.has(name)) warnings.push(list.id + ": quickFilters cita \"" + name + "\", que não está em listFilters");
|
|
82
48
|
}
|
|
83
49
|
const tabs = list.tabs;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
);
|
|
50
|
+
const moduleNames = new Set<string>(moduleForms.flatMap((form: IComponent) => [...namesOf("elements" in form ? form.elements : undefined)]));
|
|
51
|
+
if (tabs && !tabs.options?.length && !moduleNames.has(tabs.property)) {
|
|
52
|
+
warnings.push(list.id + ": tabs.property \"" + tabs.property + "\" não existe em nenhum form do módulo e tabs.options está vazio");
|
|
88
53
|
}
|
|
89
|
-
|
|
54
|
+
const { fields, source } = kpiFieldsOf(list, entities, moduleForms);
|
|
55
|
+
const kpis: string[] = list.kpis?.length ? kpiWarnings(list, fields, source) : [];
|
|
56
|
+
return [...warnings, ...columnViewWarnings(list), ...columnGroupWarnings(list), ...kpis];
|
|
90
57
|
};
|
|
91
58
|
|
|
92
59
|
// Nomes citados por texto (quickFilters, tabs.property, columnViews, kpis) que o schema não consegue conferir.
|
|
93
|
-
export const checkListReferences = (project: IProject): string[] =>
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
});
|
|
60
|
+
export const checkListReferences = (project: IProject): string[] => {
|
|
61
|
+
const entities: IFormEntity[] = formEntitiesOf(project);
|
|
62
|
+
return (project.modules ?? []).flatMap((module: IModule): string[] =>
|
|
63
|
+
module.components.filter(isList).flatMap((list: IList) => listWarnings(list, module, entities)),
|
|
64
|
+
);
|
|
65
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Tamanho máximo da observação do cliente numa linha do pedido (funcionalidade "itemNotes"). */
|
|
2
|
+
export const STORE_ITEM_NOTE_MAX_LENGTH = 140;
|
|
3
|
+
|
|
4
|
+
/** Máximo que IStoreOption.maxQuantity aceita (quantas vezes a mesma opção entra numa linha). */
|
|
5
|
+
export const STORE_OPTION_MAX_QUANTITY = 10;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import type { IProject } from "../interfaces/project.interface";
|
|
3
|
+
import { checkStoreReferences } from "./store-references";
|
|
4
|
+
|
|
5
|
+
const projectWith = (skeleton: string, store?: Record<string, unknown>): IProject =>
|
|
6
|
+
({ id: "p", title: "p", skeleton, ...(store ? { store } : {}) }) as unknown as IProject;
|
|
7
|
+
|
|
8
|
+
describe("store.segment", () => {
|
|
9
|
+
test("sem segmento não avisa", () => {
|
|
10
|
+
expect(checkStoreReferences(projectWith("ecommerce", { features: [] }))).toEqual([]);
|
|
11
|
+
expect(checkStoreReferences(projectWith("backoffice"))).toEqual([]);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test("em ecommerce e marketplace não avisa", () => {
|
|
15
|
+
expect(checkStoreReferences(projectWith("ecommerce", { segment: "food" }))).toEqual([]);
|
|
16
|
+
expect(checkStoreReferences(projectWith("marketplace", { segment: "events" }))).toEqual([]);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test("em skeleton sem venda própria avisa que é ignorado", () => {
|
|
20
|
+
expect(checkStoreReferences(projectWith("referralCommerce", { segment: "retail" }))).toEqual([
|
|
21
|
+
"store.segment \"retail\" só vale para skeleton \"ecommerce\" ou \"marketplace\"; com \"referralCommerce\" ele é ignorado",
|
|
22
|
+
]);
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { IProject } from "../interfaces/project.interface";
|
|
2
|
+
|
|
3
|
+
const SELLING_SKELETONS: string[] = ["ecommerce", "marketplace"];
|
|
4
|
+
|
|
5
|
+
export const checkStoreReferences = (project: IProject): string[] => {
|
|
6
|
+
const segment = project.store?.segment;
|
|
7
|
+
if (!segment || SELLING_SKELETONS.includes(project.skeleton)) return [];
|
|
8
|
+
return [
|
|
9
|
+
"store.segment \"" + segment + "\" só vale para skeleton \"ecommerce\" ou \"marketplace\"; com \"" + project.skeleton + "\" ele é ignorado",
|
|
10
|
+
];
|
|
11
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { STORE_SEGMENT_DEFAULT_FEATURES, STORE_SEGMENT_DEFAULT_SETTINGS, storeFeaturesOf } from "./store-segment";
|
|
3
|
+
|
|
4
|
+
describe("storeFeaturesOf", () => {
|
|
5
|
+
test("sem store ou sem segmento e sem lista, nenhuma funcionalidade", () => {
|
|
6
|
+
expect(storeFeaturesOf(undefined)).toEqual([]);
|
|
7
|
+
expect(storeFeaturesOf({})).toEqual([]);
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
test("a lista do projeto sempre vale, mesmo vazia", () => {
|
|
11
|
+
expect(storeFeaturesOf({ segment: "food", features: ["blog"] })).toEqual(["blog"]);
|
|
12
|
+
expect(storeFeaturesOf({ segment: "events", features: [] })).toEqual([]);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test("sem lista, vale o padrão do segmento", () => {
|
|
16
|
+
expect(storeFeaturesOf({ segment: "food" })).toEqual(STORE_SEGMENT_DEFAULT_FEATURES.food);
|
|
17
|
+
expect(STORE_SEGMENT_DEFAULT_FEATURES.food).toContain("productOptions");
|
|
18
|
+
expect(storeFeaturesOf({ segment: "events" })).toEqual(["stockAvailability", "installments", "coupons", "stockReservation"]);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test("devolve uma cópia, sem alterar o padrão", () => {
|
|
22
|
+
storeFeaturesOf({ segment: "retail" }).push("blog");
|
|
23
|
+
expect(STORE_SEGMENT_DEFAULT_FEATURES.retail).not.toContain("blog");
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test("blog nunca vem no padrão", () => {
|
|
27
|
+
for (const features of Object.values(STORE_SEGMENT_DEFAULT_FEATURES)) expect(features).not.toContain("blog");
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe("STORE_SEGMENT_DEFAULT_SETTINGS", () => {
|
|
32
|
+
test("retail mantém o catálogo de sempre", () => {
|
|
33
|
+
expect(STORE_SEGMENT_DEFAULT_SETTINGS.retail).toEqual({ catalogLayout: "grid", catalogColumns: 3, productImageAspect: "auto" });
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("food usa lista", () => {
|
|
37
|
+
expect(STORE_SEGMENT_DEFAULT_SETTINGS.food.catalogLayout).toBe("list");
|
|
38
|
+
});
|
|
39
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { IProjectStore, IStoreSettings, TStoreFeature, TStoreSegment } from "../interfaces/store-settings.interface";
|
|
2
|
+
|
|
3
|
+
export const DEFAULT_STORE_SEGMENT: TStoreSegment = "retail";
|
|
4
|
+
|
|
5
|
+
export const STORE_SEGMENT_DEFAULT_FEATURES: Record<TStoreSegment, TStoreFeature[]> = {
|
|
6
|
+
retail: ["whatsappButton", "stockAvailability", "cashDiscount", "installments", "favorites", "shipping", "coupons", "reviews", "returns", "productVariants"],
|
|
7
|
+
food: ["whatsappButton", "favorites", "coupons", "reviews", "openingHours", "pickup", "districtDelivery", "payOnDelivery", "itemNotes", "productOptions"],
|
|
8
|
+
services: ["whatsappButton", "stockAvailability", "installments", "coupons", "reviews", "stockReservation"],
|
|
9
|
+
events: ["stockAvailability", "installments", "coupons", "stockReservation"],
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/** Prazo da reserva de estoque, em minutos (funcionalidade "stockReservation"); retail e food só reservam se o projeto ligar. */
|
|
13
|
+
export const STORE_SEGMENT_RESERVATION_MINUTES: Record<TStoreSegment, number> = {
|
|
14
|
+
retail: 30,
|
|
15
|
+
food: 15,
|
|
16
|
+
services: 15,
|
|
17
|
+
events: 10,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const STORE_RESERVATION_MINUTES_RANGE = { min: 5, max: 60 } as const;
|
|
21
|
+
|
|
22
|
+
export const storeFeaturesOf = (store: IProjectStore | undefined): TStoreFeature[] => {
|
|
23
|
+
if (store?.features) return [...store.features];
|
|
24
|
+
return store?.segment ? [...STORE_SEGMENT_DEFAULT_FEATURES[store.segment]] : [];
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type TStoreSegmentSettings = Required<Pick<IStoreSettings, "catalogLayout" | "catalogColumns" | "productImageAspect">>;
|
|
28
|
+
|
|
29
|
+
export const STORE_SEGMENT_DEFAULT_SETTINGS: Record<TStoreSegment, TStoreSegmentSettings> = {
|
|
30
|
+
retail: { catalogLayout: "grid", catalogColumns: 3, productImageAspect: "auto" },
|
|
31
|
+
food: { catalogLayout: "list", catalogColumns: 3, productImageAspect: "square" },
|
|
32
|
+
services: { catalogLayout: "grid", catalogColumns: 3, productImageAspect: "landscape" },
|
|
33
|
+
events: { catalogLayout: "grid", catalogColumns: 3, productImageAspect: "landscape" },
|
|
34
|
+
};
|