@revenexx/cover 0.7.0 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/app/api/forms.ts +1 -0
  2. package/app/app.config.ts +17 -12
  3. package/app/components/RevenexxForm.vue +80 -12
  4. package/app/components/account/AccountShell.vue +18 -0
  5. package/app/components/account/approvals/AccountPendingApprovals.vue +178 -0
  6. package/app/components/account/orderlists/AccountOrderListDetail.vue +47 -4
  7. package/app/components/account/orders/AccountOrderDetail.vue +186 -1
  8. package/app/components/account/payments/AccountPayments.vue +129 -0
  9. package/app/components/account/quotes/AccountQuoteDetail.vue +48 -16
  10. package/app/components/auth/AuthLoginPanel.vue +131 -15
  11. package/app/components/auth/AuthMagicLinkPanel.vue +70 -0
  12. package/app/components/cart/view/CartSummaryPanel.vue +54 -0
  13. package/app/components/checkout/onepage/CheckoutDeliverySection.vue +13 -1
  14. package/app/components/checkout/onepage/CheckoutGate.vue +8 -7
  15. package/app/components/form/FormPage.vue +40 -0
  16. package/app/components/layout/header/AppBar.vue +7 -1
  17. package/app/components/layout/header/MainNav.vue +23 -1
  18. package/app/components/layout/header/MobileMenu.vue +12 -0
  19. package/app/components/product/detail/ProductDetailPriceRequest.vue +39 -0
  20. package/app/components/product/detail/ProductDetailView.vue +57 -0
  21. package/app/composables/useAccountHold.ts +45 -0
  22. package/app/composables/useAccountPayments.ts +21 -0
  23. package/app/composables/useAccountQuotes.ts +15 -2
  24. package/app/composables/useAuthStore.ts +82 -2
  25. package/app/composables/useAuthoredForms.ts +26 -0
  26. package/app/composables/useAvailableOffers.ts +42 -0
  27. package/app/composables/useGuestOrdering.ts +28 -0
  28. package/app/composables/useMasterDataEditable.ts +22 -7
  29. package/app/composables/useOrderListRules.ts +21 -1
  30. package/app/composables/usePendingApprovals.ts +37 -0
  31. package/app/config/icons.ts +2 -0
  32. package/app/config/navigation.ts +2 -2
  33. package/app/formkit.config.ts +14 -0
  34. package/app/interfaces/account/approvals.ts +37 -0
  35. package/app/interfaces/account/order-list.ts +29 -0
  36. package/app/interfaces/account/order-lists.ts +9 -0
  37. package/app/interfaces/account/payments.ts +48 -0
  38. package/app/interfaces/auth.ts +11 -0
  39. package/app/interfaces/b2b.ts +8 -8
  40. package/app/interfaces/offers.ts +35 -0
  41. package/app/interfaces/shopSettings.ts +77 -0
  42. package/app/plugins/account-hold.client.ts +20 -0
  43. package/app/plugins/shop-settings.ts +27 -12
  44. package/i18n/locales/de/account.json +80 -0
  45. package/i18n/locales/de/auth.json +29 -0
  46. package/i18n/locales/de/cart.json +7 -0
  47. package/i18n/locales/de/checkout.json +2 -1
  48. package/i18n/locales/de/common.json +4 -2
  49. package/i18n/locales/de/forms.json +27 -0
  50. package/i18n/locales/en/account.json +80 -0
  51. package/i18n/locales/en/auth.json +29 -0
  52. package/i18n/locales/en/cart.json +7 -0
  53. package/i18n/locales/en/checkout.json +2 -1
  54. package/i18n/locales/en/common.json +2 -0
  55. package/i18n/locales/en/forms.json +27 -0
  56. package/package.json +2 -1
  57. package/server/api/account/address/[id].delete.ts +1 -1
  58. package/server/api/account/address/[id].put.ts +1 -1
  59. package/server/api/account/address/index.post.ts +1 -1
  60. package/server/api/account/order-lists/[id].get.ts +37 -3
  61. package/server/api/account/orders/[id]/cancel.post.ts +54 -0
  62. package/server/api/account/orders/[id]/messages.get.ts +63 -0
  63. package/server/api/account/orders/[id]/messages.post.ts +44 -0
  64. package/server/api/account/organization.put.ts +1 -1
  65. package/server/api/account/payments.get.ts +54 -0
  66. package/server/api/account/pending-approvals/[id]/approve.post.ts +10 -0
  67. package/server/api/account/pending-approvals/[id]/decline.post.ts +10 -0
  68. package/server/api/account/pending-approvals/index.get.ts +25 -0
  69. package/server/api/account/profile.put.ts +1 -1
  70. package/server/api/account/quotes/[id]/decline.post.ts +35 -6
  71. package/server/api/account/team/[id].put.ts +1 -1
  72. package/server/api/account/team.post.ts +1 -1
  73. package/server/api/auth/magic-link.post.ts +32 -0
  74. package/server/api/auth/magic-link.put.ts +30 -0
  75. package/server/api/auth/otp.post.ts +33 -0
  76. package/server/api/auth/otp.put.ts +28 -0
  77. package/server/api/checkout/profile.get.ts +6 -3
  78. package/server/api/forms/[slug]/submit.post.ts +27 -16
  79. package/server/api/forms/[slug].get.ts +9 -1
  80. package/server/api/forms/index.get.ts +23 -0
  81. package/server/api/orders/index.post.ts +8 -0
  82. package/server/api/promotions/available.post.ts +37 -0
  83. package/server/config/account/organization.json +0 -4
  84. package/server/config/shop/app-settings.json +4 -0
  85. package/server/data/forms/authored.json +337 -0
  86. package/server/interfaces/forms.ts +51 -0
  87. package/server/services/ApiAuthService.ts +10 -0
  88. package/server/services/ApiFormsService.ts +56 -0
  89. package/server/services/MockB2BContextService.ts +1 -5
  90. package/server/services/MockFormsService.ts +63 -0
  91. package/server/utils/accountPayments.ts +45 -0
  92. package/server/utils/appSettings.ts +69 -4
  93. package/server/utils/forms.ts +62 -14
  94. package/server/utils/formsService.ts +29 -0
  95. package/server/utils/liveOrders.ts +26 -0
  96. package/server/utils/masterData.ts +31 -11
  97. package/server/utils/passwordlessSignIn.ts +73 -0
  98. package/server/utils/pendingApprovals.ts +153 -0
  99. package/server/utils/promotionsService.ts +90 -0
  100. package/server/utils/quotesService.ts +15 -0
  101. package/server/utils/shopSettings.ts +35 -4
@@ -0,0 +1,337 @@
1
+ [
2
+ {
3
+ "id": "demo-form-contact",
4
+ "name": "Kontaktanfrage",
5
+ "slug": "contact",
6
+ "status": "live",
7
+ "definition": [
8
+ {
9
+ "$el": "p",
10
+ "children": "Wir antworten an Werktagen innerhalb von 24 Stunden.",
11
+ "attrs": {
12
+ "class": "text-sm text-muted"
13
+ }
14
+ },
15
+ {
16
+ "$formkit": "text",
17
+ "name": "company",
18
+ "label": "Firma",
19
+ "autocomplete": "organization"
20
+ },
21
+ {
22
+ "$formkit": "text",
23
+ "name": "name",
24
+ "label": "Name",
25
+ "validation": "required",
26
+ "autocomplete": "name"
27
+ },
28
+ {
29
+ "$formkit": "email",
30
+ "name": "email",
31
+ "label": "E-Mail",
32
+ "validation": "required|email",
33
+ "autocomplete": "email"
34
+ },
35
+ {
36
+ "$formkit": "tel",
37
+ "name": "phone",
38
+ "label": "Telefon",
39
+ "help": "Optional — falls ein Rückruf schneller geht.",
40
+ "autocomplete": "tel"
41
+ },
42
+ {
43
+ "$formkit": "select",
44
+ "name": "topic",
45
+ "label": "Worum geht es?",
46
+ "placeholder": "Bitte wählen",
47
+ "validation": "required",
48
+ "options": [
49
+ {
50
+ "value": "product",
51
+ "label": "Produkt oder Verfügbarkeit"
52
+ },
53
+ {
54
+ "value": "order",
55
+ "label": "Eine bestehende Bestellung"
56
+ },
57
+ {
58
+ "value": "invoice",
59
+ "label": "Rechnung oder Zahlung"
60
+ },
61
+ {
62
+ "value": "other",
63
+ "label": "Etwas anderes"
64
+ }
65
+ ]
66
+ },
67
+ {
68
+ "$formkit": "textarea",
69
+ "name": "message",
70
+ "label": "Nachricht",
71
+ "validation": "required",
72
+ "rows": 5
73
+ },
74
+ {
75
+ "$formkit": "checkbox",
76
+ "name": "consent",
77
+ "label": "Ich bin damit einverstanden, dass meine Angaben zur Bearbeitung der Anfrage gespeichert werden.",
78
+ "validation": "accepted"
79
+ }
80
+ ],
81
+ "settings": {
82
+ "submit_label": "Nachricht senden",
83
+ "success_message": "Danke — wir melden uns in Kürze.",
84
+ "default_locale": "de",
85
+ "locales": [
86
+ "de",
87
+ "en"
88
+ ],
89
+ "i18n": {
90
+ "en": {
91
+ "company": {
92
+ "label": "Company"
93
+ },
94
+ "name": {
95
+ "label": "Name"
96
+ },
97
+ "email": {
98
+ "label": "Email"
99
+ },
100
+ "phone": {
101
+ "label": "Phone",
102
+ "help": "Optional — if a call back is quicker."
103
+ },
104
+ "topic": {
105
+ "label": "What is it about?",
106
+ "placeholder": "Please choose"
107
+ },
108
+ "message": {
109
+ "label": "Message"
110
+ },
111
+ "consent": {
112
+ "label": "I agree to my details being stored to answer this enquiry."
113
+ }
114
+ }
115
+ }
116
+ }
117
+ },
118
+ {
119
+ "id": "demo-form-price-request",
120
+ "name": "Preisanfrage",
121
+ "slug": "price-request",
122
+ "status": "live",
123
+ "definition": [
124
+ {
125
+ "$el": "p",
126
+ "children": "Für einen Artikel und eine Frage. Ganze Warenkörbe gehen als Angebotsanfrage.",
127
+ "attrs": {
128
+ "class": "text-sm text-muted"
129
+ }
130
+ },
131
+ {
132
+ "$formkit": "text",
133
+ "name": "product",
134
+ "label": "Artikel",
135
+ "rxKind": "product",
136
+ "validation": "required",
137
+ "placeholder": "Artikelnummer",
138
+ "help": "Vorbelegt, wenn Sie von einer Artikelseite kommen."
139
+ },
140
+ {
141
+ "$formkit": "number",
142
+ "name": "quantity",
143
+ "label": "Menge",
144
+ "validation": "required|min:1",
145
+ "value": 1,
146
+ "min": 1
147
+ },
148
+ {
149
+ "$formkit": "radio",
150
+ "name": "reply_via",
151
+ "label": "Wie sollen wir antworten?",
152
+ "validation": "required",
153
+ "value": "email",
154
+ "options": [
155
+ {
156
+ "value": "email",
157
+ "label": "Per E-Mail"
158
+ },
159
+ {
160
+ "value": "phone",
161
+ "label": "Per Telefon"
162
+ }
163
+ ]
164
+ },
165
+ {
166
+ "$formkit": "email",
167
+ "name": "email",
168
+ "label": "E-Mail",
169
+ "validation": "required|email",
170
+ "autocomplete": "email"
171
+ },
172
+ {
173
+ "$formkit": "tel",
174
+ "name": "phone",
175
+ "label": "Telefon",
176
+ "autocomplete": "tel"
177
+ },
178
+ {
179
+ "$formkit": "textarea",
180
+ "name": "note",
181
+ "label": "Anmerkung",
182
+ "rows": 4
183
+ }
184
+ ],
185
+ "settings": {
186
+ "submit_label": "Preis anfragen",
187
+ "success_message": "Danke — wir rechnen das durch und melden uns mit einem Preis.",
188
+ "default_locale": "de",
189
+ "locales": [
190
+ "de",
191
+ "en"
192
+ ],
193
+ "i18n": {
194
+ "en": {
195
+ "product": {
196
+ "label": "Article",
197
+ "placeholder": "Article number",
198
+ "help": "Pre-filled when you come from an article page."
199
+ },
200
+ "quantity": {
201
+ "label": "Quantity"
202
+ },
203
+ "reply_via": {
204
+ "label": "How should we answer?"
205
+ },
206
+ "email": {
207
+ "label": "Email"
208
+ },
209
+ "phone": {
210
+ "label": "Phone"
211
+ },
212
+ "note": {
213
+ "label": "Note"
214
+ }
215
+ }
216
+ }
217
+ }
218
+ },
219
+ {
220
+ "id": "demo-form-callback",
221
+ "name": "Rückruf-Wunsch",
222
+ "slug": "callback",
223
+ "status": "live",
224
+ "definition": [
225
+ {
226
+ "$formkit": "text",
227
+ "name": "name",
228
+ "label": "Name",
229
+ "validation": "required",
230
+ "autocomplete": "name"
231
+ },
232
+ {
233
+ "$formkit": "text",
234
+ "name": "company",
235
+ "label": "Firma",
236
+ "autocomplete": "organization"
237
+ },
238
+ {
239
+ "$formkit": "tel",
240
+ "name": "phone",
241
+ "label": "Telefonnummer",
242
+ "validation": "required",
243
+ "autocomplete": "tel"
244
+ },
245
+ {
246
+ "$rxStep": {
247
+ "id": "step_2",
248
+ "kind": "fields",
249
+ "title": "Wann passt es Ihnen?"
250
+ }
251
+ },
252
+ {
253
+ "$formkit": "date",
254
+ "name": "day",
255
+ "label": "Tag",
256
+ "validation": "required"
257
+ },
258
+ {
259
+ "$formkit": "radio",
260
+ "name": "window",
261
+ "label": "Uhrzeit",
262
+ "validation": "required",
263
+ "options": [
264
+ {
265
+ "value": "morning",
266
+ "label": "Vormittags (8–12 Uhr)"
267
+ },
268
+ {
269
+ "value": "afternoon",
270
+ "label": "Nachmittags (12–17 Uhr)"
271
+ },
272
+ {
273
+ "value": "any",
274
+ "label": "Egal"
275
+ }
276
+ ]
277
+ },
278
+ {
279
+ "$formkit": "textarea",
280
+ "name": "topic",
281
+ "label": "Worum geht es?",
282
+ "rows": 4
283
+ },
284
+ {
285
+ "$rxStep": {
286
+ "id": "step_thanks",
287
+ "kind": "thankyou"
288
+ }
289
+ },
290
+ {
291
+ "$el": "h3",
292
+ "children": "Ihr Rückruf ist notiert.",
293
+ "attrs": {
294
+ "class": "text-base font-semibold text-highlighted"
295
+ }
296
+ },
297
+ {
298
+ "$el": "p",
299
+ "children": "Wir rufen im gewünschten Zeitfenster an. Passt es doch nicht, schreiben Sie uns einfach.",
300
+ "attrs": {
301
+ "class": "text-sm text-muted"
302
+ }
303
+ }
304
+ ],
305
+ "settings": {
306
+ "submit_label": "Rückruf anfordern",
307
+ "success_message": "Danke — wir rufen im gewünschten Zeitfenster an.",
308
+ "default_locale": "de",
309
+ "locales": [
310
+ "de",
311
+ "en"
312
+ ],
313
+ "i18n": {
314
+ "en": {
315
+ "name": {
316
+ "label": "Name"
317
+ },
318
+ "company": {
319
+ "label": "Company"
320
+ },
321
+ "phone": {
322
+ "label": "Phone number"
323
+ },
324
+ "day": {
325
+ "label": "Day"
326
+ },
327
+ "window": {
328
+ "label": "Time"
329
+ },
330
+ "topic": {
331
+ "label": "What is it about?"
332
+ }
333
+ }
334
+ }
335
+ }
336
+ }
337
+ ]
@@ -62,4 +62,55 @@ export interface FormPublic {
62
62
  slug: string;
63
63
  definition: Record<string, unknown>[];
64
64
  settings: FormPublicSettings | null;
65
+ /**
66
+ * The decoy field to render hidden, when the tenant named one. It travels
67
+ * with the form rather than being read separately because it is resolved per
68
+ * MARKET, and the market is settled on the request that fetched the form.
69
+ */
70
+ honeypot: string | null;
71
+ }
72
+
73
+ /** One row of the live catalogue, as a surface deciding whether to offer a form needs it. */
74
+ export interface FormSummary {
75
+ slug: string;
76
+ name: string;
77
+ }
78
+
79
+ /**
80
+ * What became of a submission.
81
+ *
82
+ * `stored` and `spam` both mean the merchant has it — under `flag` a caught
83
+ * submission is kept so a false positive is recoverable — and the visitor is
84
+ * told the same thing in both cases, because a trap that announces itself is
85
+ * no trap. `rejected` is the tenant who chose `reject`: nothing was stored and
86
+ * no automation will ever hear about it, so the visitor must not be thanked.
87
+ */
88
+ export interface FormSubmissionResult {
89
+ outcome: "stored" | "spam" | "rejected";
90
+ successMessage?: string | null;
91
+ }
92
+
93
+ /**
94
+ * Service contract for authored forms — the `forms` platform app.
95
+ *
96
+ * Two implementations, selected by the `formsService` registry key: `mock`
97
+ * serves the bundled demo forms (so a storefront with no gateway credentials
98
+ * still has a contact page, and a browser test has something to submit), `api`
99
+ * the tenant's own. Only LIVE forms are ever resolved: a draft is a form
100
+ * somebody is still building, and a storefront that rendered one would publish
101
+ * it on the operator's behalf.
102
+ */
103
+ export interface IFormsService {
104
+ /** The live forms, so a surface can ask whether to offer one at all. */
105
+ list(): Promise<FormSummary[]>;
106
+ /** One live form by slug, or null when there is none published under it. */
107
+ resolve(slug: string): Promise<FormRow | null>;
108
+ /** Record a submission and apply the tenant's spam policy. */
109
+ submit(form: FormRow, data: Record<string, unknown>, source: string | null, policy: FormSpamPolicy): Promise<FormSubmissionResult>;
110
+ }
111
+
112
+ /** The two forms settings the storefront owes the app (see FormAppSettings). */
113
+ export interface FormSpamPolicy {
114
+ honeypotField: string | null;
115
+ spamHandling: "flag" | "reject";
65
116
  }
@@ -19,6 +19,12 @@ interface ApiContact {
19
19
  last_name?: string | null;
20
20
  role?: string | null;
21
21
  organization_id?: string | null;
22
+ /**
23
+ * False for a contact that is blocked, pending or rejected. The customers app
24
+ * answers it on every read and shapes the permission set to match; the shop
25
+ * carries it through so a surface can say why rather than showing a wall.
26
+ */
27
+ active?: boolean | null;
22
28
  }
23
29
 
24
30
  const KNOWN_ROLES = new Set<AuthRole>(["buyer", "approver", "admin", "requester"]);
@@ -119,6 +125,10 @@ export class ApiAuthService implements IAuthService {
119
125
  role: toAuthRole(contact?.role),
120
126
  ...(contact?.id ? { contactId: contact.id } : {}),
121
127
  ...(contact?.organization_id ? { organizationId: contact.organization_id } : {}),
128
+ // Only when the app actually said: undefined means nobody asked,
129
+ // and reading that as blocked would lock out every session whose
130
+ // cookie predates this.
131
+ ...(typeof contact?.active === "boolean" ? { active: contact.active } : {}),
122
132
  };
123
133
  }
124
134
  catch (err) {
@@ -0,0 +1,56 @@
1
+ import type { FormRow, FormSpamPolicy, FormSubmissionResult, FormSummary, IFormsService } from "../interfaces/forms";
2
+
3
+ /**
4
+ * The tenant's own forms, through the public revenexx API.
5
+ *
6
+ * Only `status=live` is ever asked for: a draft is a form somebody is still
7
+ * building, and the app is explicit that `GET /v1/forms/{id}` hands one back
8
+ * exactly like a published one, so the filter is the storefront's own guard.
9
+ *
10
+ * Uses the SDK escape hatch — the generated SDK has no Forms service yet (the
11
+ * app shipped after this SDK build). `?slug=&status=&limit=` are exact-column
12
+ * filters the app documents and the gateway passes through.
13
+ *
14
+ * The spam policy is NOT applied here. The app applies it at insert, which is
15
+ * the only moment it can: it strips the decoy field before storing and answers
16
+ * 422 for a tenant who chose `reject`. Passing it through again would be a
17
+ * second opinion on a question already settled.
18
+ */
19
+ export class ApiFormsService implements IFormsService {
20
+ async list(): Promise<FormSummary[]> {
21
+ const res = await useRevenexxSdk().call<{ items?: FormRow[] }>("GET", "/v1/forms", {
22
+ query: { status: "live", limit: 200 },
23
+ });
24
+ return (res.items ?? []).map(f => ({ slug: f.slug, name: f.name }));
25
+ }
26
+
27
+ async resolve(slug: string): Promise<FormRow | null> {
28
+ const res = await useRevenexxSdk().call<{ items?: FormRow[] }>("GET", "/v1/forms", {
29
+ query: { slug, status: "live", limit: 1 },
30
+ });
31
+ return res.items?.[0] ?? null;
32
+ }
33
+
34
+ async submit(
35
+ form: FormRow,
36
+ data: Record<string, unknown>,
37
+ source: string | null,
38
+ policy: FormSpamPolicy,
39
+ ): Promise<FormSubmissionResult> {
40
+ try {
41
+ await useRevenexxSdk().call("POST", "/v1/forms/submissions", {
42
+ body: { form_id: form.id, form_slug: form.slug, data, source },
43
+ });
44
+ }
45
+ catch (err) {
46
+ // 422 is the tenant who chose `reject` and a submission that filled
47
+ // the decoy in. It is the one failure that is not an error: nothing
48
+ // was stored, on purpose, and the visitor is told so.
49
+ if (err instanceof RevenexxException && err.code === 422 && policy.spamHandling === "reject") {
50
+ return { outcome: "rejected" };
51
+ }
52
+ throw err;
53
+ }
54
+ return { outcome: "stored", successMessage: form.settings?.success_message ?? null };
55
+ }
56
+ }
@@ -182,11 +182,7 @@ export class B2BContextService implements IB2BContextService {
182
182
  approvals: { ...base.approvals, ...o.approvals },
183
183
  workflows: { ...base.workflows, ...o.workflows },
184
184
  cart: { ...base.cart, ...o.cart },
185
- checkout: {
186
- ...base.checkout,
187
- ...o.checkout,
188
- guestOrdering: { ...base.checkout.guestOrdering, ...o.checkout?.guestOrdering },
189
- },
185
+ checkout: { ...base.checkout, ...o.checkout },
190
186
  };
191
187
  }
192
188
  }
@@ -0,0 +1,63 @@
1
+ import type { FormRow, FormSpamPolicy, FormSubmissionResult, FormSummary, IFormsService } from "../interfaces/forms";
2
+
3
+ /**
4
+ * The bundled demo forms — three, chosen to exercise what the Cockpit's palette
5
+ * can produce rather than to look tidy: a contact form (text, email, tel,
6
+ * select, textarea, checkbox), a price request (the `rxKind: product` field a
7
+ * product page pre-fills, plus a radio group), and a two-step return request
8
+ * with a designed thank-you page.
9
+ *
10
+ * They are authored in German with an English overlay, which is the shape a
11
+ * live form has: the app stores one base definition and per-locale field texts
12
+ * beside it, and the overlay is applied by this BFF (see localizeDefinition).
13
+ *
14
+ * Submitting here records nothing — the inbox is the Cockpit's, and a storefront
15
+ * that kept a copy would be a second place to leak an end user's data from. What
16
+ * the demo DOES reproduce is the tenant's spam policy, so the honeypot and the
17
+ * two answers to a caught submission behave the same before anybody goes live.
18
+ */
19
+ export class MockFormsService implements IFormsService {
20
+ private cache: FormRow[] | null = null;
21
+
22
+ private async all(): Promise<FormRow[]> {
23
+ if (!this.cache) {
24
+ this.cache = await readCoverDataJson<FormRow[]>("forms/authored.json");
25
+ }
26
+ return this.cache;
27
+ }
28
+
29
+ async list(): Promise<FormSummary[]> {
30
+ const forms = await this.all();
31
+ return forms.filter(f => f.status === "live").map(f => ({ slug: f.slug, name: f.name }));
32
+ }
33
+
34
+ async resolve(slug: string): Promise<FormRow | null> {
35
+ const forms = await this.all();
36
+ return forms.find(f => f.slug === slug && f.status === "live") ?? null;
37
+ }
38
+
39
+ async submit(
40
+ form: FormRow,
41
+ data: Record<string, unknown>,
42
+ source: string | null,
43
+ policy: FormSpamPolicy,
44
+ ): Promise<FormSubmissionResult> {
45
+ const caught = decoyFilled(data, policy.honeypotField);
46
+
47
+ if (caught && policy.spamHandling === "reject") {
48
+ return { outcome: "rejected" };
49
+ }
50
+
51
+ getLogService().warn("Demo form submission (not stored — mock mode)", {
52
+ slug: form.slug,
53
+ source,
54
+ fields: Object.keys(data).filter(key => key !== policy.honeypotField).length,
55
+ caught,
56
+ });
57
+
58
+ return {
59
+ outcome: caught ? "spam" : "stored",
60
+ successMessage: form.settings?.success_message ?? null,
61
+ };
62
+ }
63
+ }
@@ -0,0 +1,45 @@
1
+ import type { AccountPayment, AccountPaymentState } from "../../app/interfaces/account/payments";
2
+
3
+ /**
4
+ * Reading a payment the way the buyer needs it.
5
+ *
6
+ * Kept out of the route so the two rules that could mislead somebody about money
7
+ * can be tested: that overdue is computed from the due date rather than from
8
+ * whether the merchant has started chasing, and that a settled payment is never
9
+ * called overdue however old it is.
10
+ */
11
+ const STATES = new Set<AccountPaymentState>([
12
+ "open", "pending", "authorized", "paid", "partially_paid", "refunded", "failed",
13
+ ]);
14
+
15
+ export interface LivePayment {
16
+ id: string;
17
+ order_ref?: string | null;
18
+ amount?: number | string | null;
19
+ currency?: string | null;
20
+ status?: string | null;
21
+ method_code?: string | null;
22
+ captured_at?: string | null;
23
+ dunning_due_at?: string | null;
24
+ }
25
+
26
+ export const SETTLED = new Set<AccountPaymentState>(["paid", "refunded"]);
27
+
28
+ export function mapPayment(row: LivePayment): AccountPayment {
29
+ const state = STATES.has(row.status as AccountPaymentState)
30
+ ? row.status as AccountPaymentState
31
+ : "open";
32
+ const dueAt = row.dunning_due_at ?? null;
33
+ return {
34
+ id: row.id,
35
+ orderNumber: row.order_ref ?? null,
36
+ amount: Number(row.amount ?? 0),
37
+ currency: (row.currency ?? "").toUpperCase(),
38
+ state,
39
+ method: row.method_code ?? null,
40
+ paidAt: row.captured_at ?? null,
41
+ dueAt,
42
+ overdue: !SETTLED.has(state) && Boolean(dueAt) && new Date(dueAt).getTime() < Date.now(),
43
+ };
44
+ }
45
+