rapida-partner 7.1.0 → 8.0.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.
Files changed (43) hide show
  1. package/README.md +6 -0
  2. package/index.ts +5 -0
  3. package/package.json +1 -1
  4. package/src/interfaces/dashboard-widget.interface.ts +58 -0
  5. package/src/interfaces/data-chart.interface.ts +23 -1
  6. package/src/interfaces/data-stat.interface.ts +115 -0
  7. package/src/interfaces/list.interface.ts +19 -0
  8. package/src/interfaces/project-backend.interface.ts +6 -6
  9. package/src/interfaces/project.interface.ts +19 -1
  10. package/src/interfaces/store-blog-post.interface.ts +1 -1
  11. package/src/interfaces/store-coupon.interface.ts +2 -2
  12. package/src/interfaces/store-order.interface.ts +2 -2
  13. package/src/interfaces/store-return.interface.ts +1 -1
  14. package/src/interfaces/store-review.interface.ts +1 -1
  15. package/src/interfaces/store-settings.interface.ts +1 -1
  16. package/src/interfaces/tone.interface.ts +2 -0
  17. package/src/schemas/component-one-of.ref.json +5 -2
  18. package/src/schemas/dashboard-budget-monitor.ref.json +16 -0
  19. package/src/schemas/dashboard-empty-state.ref.json +37 -0
  20. package/src/schemas/dashboard-item-one-of.ref.json +16 -0
  21. package/src/schemas/dashboard-link-action.ref.json +15 -0
  22. package/src/schemas/dashboard-quick-create.ref.json +19 -0
  23. package/src/schemas/data-chart.ref.json +36 -2
  24. package/src/schemas/data-stat.ref.json +146 -0
  25. package/src/schemas/list.ref.json +57 -0
  26. package/src/schemas/module.ref.json +5 -2
  27. package/src/schemas/project.schema.json +7 -1
  28. package/src/schemas/quick-create-item.ref.json +19 -0
  29. package/src/schemas/tone.ref.json +6 -0
  30. package/src/utils/list-references.ts +51 -0
  31. package/src/modules/store-blog/store-blog.module.ts +0 -108
  32. package/src/modules/store-coupons/store-coupons.module.ts +0 -127
  33. package/src/modules/store-orders/store-order.elements.ts +0 -82
  34. package/src/modules/store-orders/store-orders.module.ts +0 -108
  35. package/src/modules/store-returns/store-return.elements.ts +0 -70
  36. package/src/modules/store-returns/store-returns.module.ts +0 -101
  37. package/src/modules/store-reviews/store-reviews.module.ts +0 -132
  38. package/src/modules/store-settings/contact-legal.elements.ts +0 -57
  39. package/src/modules/store-settings/features.elements.ts +0 -93
  40. package/src/modules/store-settings/identity-visual.elements.ts +0 -101
  41. package/src/modules/store-settings/pages-showcase.elements.ts +0 -100
  42. package/src/modules/store-settings/store-settings.module.ts +0 -80
  43. package/src/modules/store-settings/translations.ts +0 -7
@@ -12,6 +12,10 @@
12
12
  "title": {
13
13
  "$ref": "translatable.ref.json"
14
14
  },
15
+ "subtitle": {
16
+ "$ref": "translatable.ref.json",
17
+ "description": "Texto abaixo do título. Aceita {{total}} (soma dos valores exibidos)."
18
+ },
15
19
  "icon": {
16
20
  "type": "string"
17
21
  },
@@ -42,9 +46,25 @@
42
46
  "scatter",
43
47
  "bubble",
44
48
  "area",
45
- "polarArea"
49
+ "polarArea",
50
+ "progressList"
46
51
  ]
47
52
  },
53
+ "action": {
54
+ "allOf": [
55
+ {
56
+ "$ref": "dashboard-link-action.ref.json"
57
+ }
58
+ ],
59
+ "properties": {
60
+ "label": true,
61
+ "route": true
62
+ },
63
+ "additionalProperties": false
64
+ },
65
+ "emptyState": {
66
+ "$ref": "dashboard-empty-state.ref.json"
67
+ },
48
68
  "limit": {
49
69
  "type": "number"
50
70
  },
@@ -81,6 +101,20 @@
81
101
  "type": "string"
82
102
  }
83
103
  }
104
+ },
105
+ "colors": {
106
+ "type": "object",
107
+ "description": "Cor por valor cru do campo agrupado, em progressList.",
108
+ "additionalProperties": {
109
+ "type": "string",
110
+ "enum": [
111
+ "neutral",
112
+ "primary",
113
+ "success",
114
+ "warning",
115
+ "danger"
116
+ ]
117
+ }
84
118
  }
85
119
  },
86
120
  "required": [
@@ -272,4 +306,4 @@
272
306
  "chartType",
273
307
  "data"
274
308
  ]
275
- }
309
+ }
@@ -0,0 +1,146 @@
1
+ {
2
+ "$id": "data-stat.ref.json",
3
+ "$schema": "http://json-schema.org/draft-07/schema#",
4
+ "type": "object",
5
+ "properties": {
6
+ "componentType": {
7
+ "const": "dataStat"
8
+ },
9
+ "id": {
10
+ "type": "string"
11
+ },
12
+ "title": {
13
+ "$ref": "translatable.ref.json"
14
+ },
15
+ "subtitle": {
16
+ "$ref": "translatable.ref.json"
17
+ },
18
+ "userStory": {
19
+ "type": "string"
20
+ },
21
+ "icon": {
22
+ "type": "string"
23
+ },
24
+ "guards": {
25
+ "type": "string",
26
+ "enum": ["isAuthenticated", "isAuthorized"]
27
+ },
28
+ "businessRules": {
29
+ "$ref": "business-rules.ref.json"
30
+ },
31
+ "dataSource": {
32
+ "$ref": "form-common-api-request.ref.json"
33
+ },
34
+ "filters": {
35
+ "type": "array",
36
+ "items": {
37
+ "type": "object",
38
+ "properties": {
39
+ "key": {
40
+ "type": "string"
41
+ },
42
+ "comparisonOperator": {
43
+ "enum": ["===", ">", ">=", "in", "<", "<=", "!==", "nin"]
44
+ },
45
+ "value": {
46
+ "description": "Valor comparado. Aceita as datas relativas \"$now\", \"$today\", \"$tomorrow\", \"$startOfMonth\", \"$startOfNextMonth\", \"$startOfYear\" e \"$startOfNextYear\"; \"in\"/\"nin\" recebem uma lista."
47
+ }
48
+ },
49
+ "required": ["key", "comparisonOperator", "value"],
50
+ "additionalProperties": false,
51
+ "if": {
52
+ "properties": { "comparisonOperator": { "enum": ["in", "nin"] } }
53
+ },
54
+ "then": {
55
+ "properties": { "value": { "type": "array" } }
56
+ }
57
+ }
58
+ },
59
+ "value": {
60
+ "type": "object",
61
+ "properties": {
62
+ "aggregator": {
63
+ "type": "string",
64
+ "enum": ["sum", "avg", "min", "max", "count"]
65
+ },
66
+ "property": {
67
+ "type": "string"
68
+ },
69
+ "dataType": {
70
+ "$ref": "types-datatype.ref.json"
71
+ }
72
+ },
73
+ "required": ["aggregator"],
74
+ "additionalProperties": false,
75
+ "if": {
76
+ "properties": { "aggregator": { "not": { "const": "count" } } }
77
+ },
78
+ "then": {
79
+ "required": ["property"]
80
+ }
81
+ },
82
+ "tone": {
83
+ "type": "object",
84
+ "description": "Cor do card conforme o valor calculado. A primeira regra que casar define o tom; sem nenhuma, vale default (\"neutral\").",
85
+ "properties": {
86
+ "default": {
87
+ "$ref": "tone.ref.json"
88
+ },
89
+ "rules": {
90
+ "type": "array",
91
+ "items": {
92
+ "type": "object",
93
+ "properties": {
94
+ "comparisonOperator": {
95
+ "enum": ["===", ">", ">=", "in", "<", "<=", "!==", "nin"]
96
+ },
97
+ "value": {
98
+ "description": "Valor comparado com o resultado. Aceita as mesmas datas relativas dos filtros."
99
+ },
100
+ "tone": {
101
+ "$ref": "tone.ref.json"
102
+ }
103
+ },
104
+ "required": ["comparisonOperator", "value", "tone"],
105
+ "additionalProperties": false,
106
+ "if": {
107
+ "properties": { "comparisonOperator": { "enum": ["in", "nin"] } }
108
+ },
109
+ "then": {
110
+ "properties": { "value": { "type": "array" } }
111
+ }
112
+ }
113
+ }
114
+ },
115
+ "additionalProperties": false
116
+ },
117
+ "limit": {
118
+ "type": "integer",
119
+ "minimum": 1
120
+ },
121
+ "link": {
122
+ "type": "string"
123
+ },
124
+ "action": {
125
+ "allOf": [
126
+ {
127
+ "$ref": "dashboard-link-action.ref.json"
128
+ }
129
+ ],
130
+ "properties": {
131
+ "label": true,
132
+ "route": true
133
+ },
134
+ "additionalProperties": false
135
+ },
136
+ "emptyState": {
137
+ "$ref": "dashboard-empty-state.ref.json"
138
+ },
139
+ "space": {
140
+ "type": "integer",
141
+ "enum": [1, 2, 3, 4]
142
+ }
143
+ },
144
+ "required": ["componentType", "id", "title", "dataSource", "value"],
145
+ "additionalProperties": false
146
+ }
@@ -13,6 +13,10 @@
13
13
  "title": {
14
14
  "$ref": "translatable.ref.json"
15
15
  },
16
+ "description": {
17
+ "$ref": "translatable.ref.json",
18
+ "description": "Frase abaixo do título da lista, dizendo para que ela serve."
19
+ },
16
20
  "guards": {
17
21
  "type": "array",
18
22
  "items": {
@@ -67,6 +71,21 @@
67
71
  "isExpansible": {
68
72
  "type": "boolean"
69
73
  },
74
+ "tones": {
75
+ "type": "object",
76
+ "description": "Só em type 'badge' (nos outros tipos é ignorado): tom de cada valor. e.g.: { \"paid\": \"success\", \"overdue\": \"danger\" }",
77
+ "additionalProperties": { "$ref": "tone.ref.json" }
78
+ },
79
+ "mobilePriority": {
80
+ "type": "integer",
81
+ "enum": [1, 2, 3],
82
+ "description": "1 e 2 aparecem no card do celular; 3 só no desktop."
83
+ },
84
+ "relativeDate": {
85
+ "type": "string",
86
+ "enum": ["plain", "deadline"],
87
+ "description": "Data com texto relativo abaixo ('há 3 dias'); 'deadline' pinta o passado de vermelho e os próximos 7 dias de âmbar."
88
+ },
70
89
  "isHtml": {
71
90
  "type": "boolean"
72
91
  },
@@ -250,6 +269,44 @@
250
269
  "listFilters": {
251
270
  "$ref": "form-one-of.ref.json"
252
271
  },
272
+ "quickFilters": {
273
+ "type": "array",
274
+ "maxItems": 2,
275
+ "items": { "type": "string" },
276
+ "description": "Até 2 `name` de listFilters que ficam ao lado da busca; os demais vão para a área 'Mais filtros'. Sem isso, todos ficam na área 'Filtros'."
277
+ },
278
+ "tabs": {
279
+ "type": "object",
280
+ "description": "Abas com contador acima da tabela, uma por valor de `property`, mais 'Todos'.",
281
+ "properties": {
282
+ "property": { "type": "string" },
283
+ "options": {
284
+ "type": "array",
285
+ "description": "Sem options, usa as opções do select de mesmo nome no form do módulo.",
286
+ "items": {
287
+ "type": "object",
288
+ "properties": {
289
+ "value": { "type": ["string", "number", "boolean"] },
290
+ "label": { "$ref": "translatable.ref.json" },
291
+ "tone": { "$ref": "tone.ref.json" }
292
+ },
293
+ "required": ["value", "label"],
294
+ "additionalProperties": false
295
+ }
296
+ },
297
+ "tones": {
298
+ "type": "object",
299
+ "description": "Tom de cada aba pelo valor, para usar com as opções do select. e.g.: { \"overdue\": \"danger\" }",
300
+ "additionalProperties": { "$ref": "tone.ref.json" }
301
+ },
302
+ "showCounts": {
303
+ "type": "boolean",
304
+ "description": "Contador em cada aba; padrão true."
305
+ }
306
+ },
307
+ "required": ["property"],
308
+ "additionalProperties": false
309
+ },
253
310
  "contracts": {
254
311
  "type": "array",
255
312
  "items": {
@@ -49,8 +49,11 @@
49
49
  {
50
50
  "$ref": "panel.ref.json"
51
51
  },
52
- {
53
- "$ref": "kanban.ref.json"
52
+ {
53
+ "$ref": "kanban.ref.json"
54
+ },
55
+ {
56
+ "$ref": "data-stat.ref.json"
54
57
  }
55
58
  ]
56
59
  }
@@ -187,6 +187,12 @@
187
187
  },
188
188
  "flowsGroup": {
189
189
  "$ref": "translatable.ref.json"
190
+ },
191
+ "quickCreate": {
192
+ "type": "array",
193
+ "items": {
194
+ "$ref": "quick-create-item.ref.json"
195
+ }
190
196
  }
191
197
  },
192
198
  "additionalProperties": false
@@ -212,7 +218,7 @@
212
218
  "dashboard": {
213
219
  "type": "array",
214
220
  "items": {
215
- "$ref": "component-one-of.ref.json"
221
+ "$ref": "dashboard-item-one-of.ref.json"
216
222
  }
217
223
  },
218
224
  "repositories": {
@@ -0,0 +1,19 @@
1
+ {
2
+ "$id": "quick-create-item.ref.json",
3
+ "$schema": "http://json-schema.org/draft-07/schema#",
4
+ "type": "object",
5
+ "description": "Atalho de criação: abre o cadastro do form formId (com a ação \"create\" no contrato).",
6
+ "properties": {
7
+ "formId": {
8
+ "type": "string"
9
+ },
10
+ "label": {
11
+ "$ref": "translatable.ref.json"
12
+ },
13
+ "icon": {
14
+ "type": "string"
15
+ }
16
+ },
17
+ "required": ["formId", "label"],
18
+ "additionalProperties": false
19
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "$id": "tone.ref.json",
3
+ "$schema": "http://json-schema.org/draft-07/schema#",
4
+ "type": "string",
5
+ "enum": ["neutral", "success", "warning", "danger"]
6
+ }
@@ -0,0 +1,51 @@
1
+ import type { IList } from "../interfaces/list.interface";
2
+ import type { IComponent, IModule, IProject } from "../interfaces/project.interface";
3
+
4
+ interface INamedNode {
5
+ name?: string;
6
+ elements?: unknown[];
7
+ tabs?: { elements?: unknown[] }[];
8
+ }
9
+
10
+ const namesOf = (elements: unknown[] | undefined): string[] =>
11
+ (elements ?? []).flatMap((element: unknown): string[] => {
12
+ const node = (element ?? {}) as INamedNode;
13
+ return [
14
+ ...(node.name ? [node.name] : []),
15
+ ...namesOf(node.elements),
16
+ ...namesOf((node.tabs ?? []).flatMap((tab) => tab.elements ?? [])),
17
+ ];
18
+ });
19
+
20
+ const isList = (component: IComponent): component is IList => component.componentType === "list";
21
+
22
+ const formNamesOf = (module: IModule): Set<string> =>
23
+ new Set(
24
+ module.components.flatMap((component: IComponent): string[] =>
25
+ component.componentType === "form" ? namesOf(component.elements) : [],
26
+ ),
27
+ );
28
+
29
+ const listWarnings = (list: IList, formNames: Set<string>): string[] => {
30
+ const warnings: string[] = [];
31
+ const filterNames = new Set(namesOf(list.listFilters));
32
+ for (const name of list.quickFilters ?? []) {
33
+ if (!filterNames.has(name)) {
34
+ warnings.push(list.id + ": quickFilters cita \"" + name + "\", que não está em listFilters");
35
+ }
36
+ }
37
+ const tabs = list.tabs;
38
+ if (tabs && !tabs.options?.length && !formNames.has(tabs.property)) {
39
+ warnings.push(
40
+ list.id + ": tabs.property \"" + tabs.property + "\" não existe em nenhum form do módulo e tabs.options está vazio",
41
+ );
42
+ }
43
+ return warnings;
44
+ };
45
+
46
+ // Nomes citados por texto (quickFilters e tabs.property) que o schema não consegue conferir.
47
+ export const checkListReferences = (project: IProject): string[] =>
48
+ (project.modules ?? []).flatMap((module: IModule): string[] => {
49
+ const formNames = formNamesOf(module);
50
+ return module.components.filter(isList).flatMap((list: IList) => listWarnings(list, formNames));
51
+ });
@@ -1,108 +0,0 @@
1
- import { EDataType } from "../../enums/form.enum";
2
- import type { IPublicContract } from "../../interfaces/form-contract.interface";
3
- import type { IForm, IFormElement } from "../../interfaces/form.interface";
4
- import type { IList } from "../../interfaces/list.interface";
5
- import type { IModule } from "../../interfaces/project.interface";
6
- import { tr } from "../store-settings/translations";
7
-
8
- export const STORE_BLOG_POSTS_ENDPOINT = "/store-blog-posts";
9
-
10
- export interface IStoreBlogModuleOptions {
11
- publicAccess?: IPublicContract["access"];
12
- allowedOrigins?: string[];
13
- }
14
-
15
- const ENTITY = "storeBlogPosts";
16
-
17
- const postElements: IFormElement[] = [
18
- { type: "input", name: "title", dataType: EDataType.TEXT, label: tr("Título", "Title", "Título"), isRequired: true, space: 2 },
19
- {
20
- type: "input",
21
- name: "slug",
22
- dataType: EDataType.TEXT,
23
- label: tr("Nome na URL", "URL name", "Nombre en la URL"),
24
- tooltip: tr("Letras minúsculas, números e hífen (ex.: como-guardar-blu-ray)", "Lowercase letters, numbers and hyphens (e.g. how-to-store-blu-ray)", "Letras minúsculas, números y guion (ej.: como-guardar-blu-ray)"),
25
- isRequired: true,
26
- isUnique: true,
27
- space: 2,
28
- },
29
- { type: "input", name: "excerpt", dataType: EDataType.TEXT, label: tr("Resumo", "Excerpt", "Resumen") },
30
- {
31
- type: "file",
32
- name: "coverImage",
33
- dataType: EDataType.TEXT,
34
- label: tr("Imagem de capa", "Cover image", "Imagen de portada"),
35
- validators: ["onlyImages"],
36
- storageConfig: { path: "store-blog-posts", fileNameStrategy: "uuid", visibility: "public" },
37
- },
38
- {
39
- type: "input",
40
- name: "content",
41
- dataType: EDataType.WYSIWYG,
42
- label: tr("Conteúdo", "Content", "Contenido"),
43
- isRequired: true,
44
- storageConfig: { path: "store-blog-posts", fileNameStrategy: "uuid", visibility: "public" },
45
- },
46
- { type: "datepicker", name: "publishedAt", label: tr("Publicar em", "Publish on", "Publicar el") },
47
- { type: "switch", name: "isPublished", label: tr("Publicado", "Published", "Publicado") },
48
- ];
49
-
50
- export const getStoreBlogPostForm = (options: IStoreBlogModuleOptions = {}): IForm => ({
51
- componentType: "form",
52
- id: "storeBlogPostForm",
53
- title: tr("Artigo do blog", "Blog post", "Artículo del blog"),
54
- icon: "newspaper",
55
- guards: "isAuthorized",
56
- elements: postElements,
57
- contracts: [
58
- {
59
- id: ENTITY,
60
- endpoint: STORE_BLOG_POSTS_ENDPOINT,
61
- actions: ["create", "get", "getById", "update", "softDelete"],
62
- request: { entity: ENTITY, fields: [] },
63
- },
64
- ],
65
- publicContracts: [
66
- {
67
- id: "storeBlogPostsFromStore",
68
- endpoint: STORE_BLOG_POSTS_ENDPOINT,
69
- actions: ["get", "getById"],
70
- access: options.publicAccess ?? "trustedCallers",
71
- ...(options.allowedOrigins ? { allowedOrigins: options.allowedOrigins } : {}),
72
- request: { entity: ENTITY, fields: [] },
73
- },
74
- ],
75
- });
76
-
77
- export const getStoreBlogPostList = (): IList => ({
78
- componentType: "list",
79
- id: "storeBlogPostList",
80
- title: tr("Blog", "Blog", "Blog"),
81
- guards: ["isAuthorized"],
82
- dataSource: { endpoint: STORE_BLOG_POSTS_ENDPOINT, paramType: "query", hasAuthentication: true },
83
- listItems: [
84
- { property: "title", type: "title", label: tr("Título", "Title", "Título"), dataType: EDataType.TEXT },
85
- { property: "excerpt", type: "subtitle", label: tr("Resumo", "Excerpt", "Resumen"), dataType: EDataType.TEXT },
86
- { property: "publishedAt", label: tr("Publicar em", "Publish on", "Publicar el"), dataType: EDataType.DATE },
87
- ],
88
- contracts: [
89
- {
90
- id: ENTITY,
91
- endpoint: STORE_BLOG_POSTS_ENDPOINT,
92
- actions: ["get", "getById", "update", "softDelete"],
93
- request: { entity: ENTITY, fields: [] },
94
- },
95
- ],
96
- });
97
-
98
- /**
99
- * Módulo pronto "Blog", para o Backoffice do vendedor (funcionalidade
100
- * "blog"). A loja lista os artigos publicados por IMarketplace.blogPostsEndpoint
101
- * (STORE_BLOG_POSTS_ENDPOINT).
102
- */
103
- export const getStoreBlogModule = (options: IStoreBlogModuleOptions = {}): IModule => ({
104
- id: "storeBlogModule",
105
- title: tr("Blog", "Blog", "Blog"),
106
- icon: "newspaper",
107
- components: [getStoreBlogPostList(), getStoreBlogPostForm(options)],
108
- });
@@ -1,127 +0,0 @@
1
- import { EDataType } from "../../enums/form.enum";
2
- import type { IPublicContract } from "../../interfaces/form-contract.interface";
3
- import type { IForm, IFormElement } from "../../interfaces/form.interface";
4
- import type { IList } from "../../interfaces/list.interface";
5
- import type { IModule } from "../../interfaces/project.interface";
6
- import type { TStoreCouponDiscountType } from "../../interfaces/store-coupon.interface";
7
- import { tr } from "../store-settings/translations";
8
-
9
- export const STORE_COUPONS_ENDPOINT = "/store-coupons";
10
-
11
- export interface IStoreCouponsModuleOptions {
12
- // Quem lê os cupons sem login. "trustedCallers" (padrão): só o backend da
13
- // loja, com o token de serviço de IMarketplace.sellerServiceAuth.
14
- publicAccess?: IPublicContract["access"];
15
- allowedOrigins?: string[];
16
- }
17
-
18
- const ENTITY = "storeCoupons";
19
-
20
- const DISCOUNT_TYPE_LABELS: Record<TStoreCouponDiscountType, ReturnType<typeof tr>> = {
21
- percentage: tr("Percentual (%)", "Percentage (%)", "Porcentaje (%)"),
22
- value: tr("Valor fixo", "Fixed amount", "Monto fijo"),
23
- };
24
-
25
- const couponElements: IFormElement[] = [
26
- {
27
- type: "input",
28
- name: "code",
29
- dataType: EDataType.TEXT,
30
- label: tr("Código", "Code", "Código"),
31
- tooltip: tr("O que o cliente digita no carrinho (ex.: BEMVINDO10)", "What the customer types in the cart (e.g. WELCOME10)", "Lo que el cliente escribe en el carrito (ej.: BIENVENIDO10)"),
32
- isRequired: true,
33
- isUnique: true,
34
- space: 2,
35
- },
36
- { type: "input", name: "description", dataType: EDataType.TEXT, label: tr("Descrição", "Description", "Descripción"), space: 2 },
37
- {
38
- type: "select",
39
- name: "discountType",
40
- dataType: EDataType.TEXT,
41
- label: tr("Tipo de desconto", "Discount type", "Tipo de descuento"),
42
- isRequired: true,
43
- options: (Object.keys(DISCOUNT_TYPE_LABELS) as TStoreCouponDiscountType[]).map((value) => ({
44
- label: DISCOUNT_TYPE_LABELS[value],
45
- value,
46
- isSelected: value === "percentage",
47
- })),
48
- space: 2,
49
- },
50
- { type: "input", name: "discountValue", dataType: EDataType.NUMBER, label: tr("Desconto", "Discount", "Descuento"), isRequired: true, space: 2 },
51
- { type: "input", name: "minimumSubtotal", dataType: EDataType.CURRENCY, label: tr("Pedido mínimo", "Minimum order", "Pedido mínimo"), space: 2 },
52
- { type: "datepicker", name: "startDate", label: tr("Válido a partir de", "Valid from", "Válido desde") },
53
- { type: "datepicker", name: "endDate", label: tr("Válido até", "Valid until", "Válido hasta") },
54
- { type: "input", name: "usageLimit", dataType: EDataType.INTEGER, label: tr("Limite de usos", "Usage limit", "Límite de usos"), space: 2 },
55
- {
56
- type: "input",
57
- name: "usageLimitPerCustomer",
58
- dataType: EDataType.INTEGER,
59
- label: tr("Limite por cliente", "Limit per customer", "Límite por cliente"),
60
- space: 2,
61
- },
62
- { type: "switch", name: "isActive", label: tr("Ativo", "Active", "Activo") },
63
- ];
64
-
65
- // Um código por workspace; fica no contrato interno, de onde o gerador cria o índice único.
66
- const UNIQUE_CODE = [{ identificator: "storeCouponCodePerWorkspace", fields: ["code"] }];
67
-
68
- export const getStoreCouponForm = (options: IStoreCouponsModuleOptions = {}): IForm => ({
69
- componentType: "form",
70
- id: "storeCouponForm",
71
- title: tr("Cupom", "Coupon", "Cupón"),
72
- icon: "ticket-percent",
73
- guards: "isAuthorized",
74
- elements: couponElements,
75
- contracts: [
76
- {
77
- id: ENTITY,
78
- endpoint: STORE_COUPONS_ENDPOINT,
79
- actions: ["create", "get", "getById", "update", "softDelete"],
80
- request: { entity: ENTITY, fields: [], uniqueConstraints: UNIQUE_CODE },
81
- },
82
- ],
83
- publicContracts: [
84
- {
85
- id: "storeCouponsFromStore",
86
- endpoint: STORE_COUPONS_ENDPOINT,
87
- actions: ["get"],
88
- access: options.publicAccess ?? "trustedCallers",
89
- ...(options.allowedOrigins ? { allowedOrigins: options.allowedOrigins } : {}),
90
- request: { entity: ENTITY, fields: [] },
91
- },
92
- ],
93
- });
94
-
95
- export const getStoreCouponList = (): IList => ({
96
- componentType: "list",
97
- id: "storeCouponList",
98
- title: tr("Cupons", "Coupons", "Cupones"),
99
- guards: ["isAuthorized"],
100
- dataSource: { endpoint: STORE_COUPONS_ENDPOINT, paramType: "query", hasAuthentication: true },
101
- listItems: [
102
- { property: "code", type: "title", label: tr("Código", "Code", "Código"), dataType: EDataType.TEXT },
103
- { property: "description", type: "subtitle", label: tr("Descrição", "Description", "Descripción"), dataType: EDataType.TEXT },
104
- { property: "discountValue", type: "description", label: tr("Desconto", "Discount", "Descuento"), dataType: EDataType.NUMBER },
105
- { property: "endDate", label: tr("Válido até", "Valid until", "Válido hasta"), dataType: EDataType.DATE },
106
- ],
107
- contracts: [
108
- {
109
- id: ENTITY,
110
- endpoint: STORE_COUPONS_ENDPOINT,
111
- actions: ["get", "getById", "update", "softDelete"],
112
- request: { entity: ENTITY, fields: [] },
113
- },
114
- ],
115
- });
116
-
117
- /**
118
- * Módulo pronto "Cupons", para o Backoffice do vendedor (funcionalidade
119
- * "coupons"). A loja lê os cupons por IMarketplace.couponsEndpoint
120
- * (STORE_COUPONS_ENDPOINT), valida o código e desconta no servidor.
121
- */
122
- export const getStoreCouponsModule = (options: IStoreCouponsModuleOptions = {}): IModule => ({
123
- id: "storeCouponsModule",
124
- title: tr("Cupons", "Coupons", "Cupones"),
125
- icon: "ticket-percent",
126
- components: [getStoreCouponList(), getStoreCouponForm(options)],
127
- });