@revenexx/cover 0.7.1 → 0.11.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/app/api/account.ts +4 -0
- package/app/api/forms.ts +1 -0
- package/app/app.config.ts +17 -12
- package/app/assets/css/cover.css +9 -0
- package/app/components/RevenexxForm.vue +84 -12
- package/app/components/account/AccountShell.vue +18 -0
- package/app/components/account/AccountSidebar.vue +2 -5
- package/app/components/account/approvals/AccountPendingApprovals.vue +178 -0
- package/app/components/account/dashboard/AccountDashboardKpis.vue +74 -34
- package/app/components/account/dashboard/AccountDashboardQuickActions.vue +24 -6
- package/app/components/account/orderlists/AccountOrderListDetail.vue +47 -4
- package/app/components/account/orders/AccountOrderDetail.vue +186 -1
- package/app/components/account/organization/AccountOrganization.vue +3 -1
- package/app/components/account/payments/AccountPayments.vue +129 -0
- package/app/components/account/quotes/AccountQuoteDetail.vue +48 -16
- package/app/components/account/team/AccountTeam.vue +32 -7
- package/app/components/auth/AuthForgotPasswordPanel.vue +9 -4
- package/app/components/auth/AuthLoginPanel.vue +136 -18
- package/app/components/auth/AuthMagicLinkPanel.vue +70 -0
- package/app/components/cart/actions/CartSaveToListModal.vue +5 -0
- package/app/components/cart/item/CartItem.vue +17 -75
- package/app/components/cart/position/CartPosition.vue +17 -30
- package/app/components/cart/quote/CartQuoteRequestModal.vue +9 -1
- package/app/components/cart/view/CartSummaryPanel.vue +54 -0
- package/app/components/category/view/GridView.vue +10 -1
- package/app/components/category/view/ListView.vue +10 -1
- package/app/components/checkout/confirmation/CheckoutConfirmationActions.vue +2 -0
- package/app/components/checkout/onepage/CheckoutAddressSection.vue +4 -4
- package/app/components/checkout/onepage/CheckoutDeliverySection.vue +31 -3
- package/app/components/checkout/onepage/CheckoutGate.vue +10 -7
- package/app/components/checkout/onepage/CheckoutOnePageView.vue +1 -1
- package/app/components/checkout/onepage/CheckoutPaymentSection.vue +10 -0
- package/app/components/checkout/onepage/CheckoutSummarySection.vue +7 -1
- package/app/components/form/FormPage.vue +40 -0
- package/app/components/layout/Region.vue +13 -0
- package/app/components/layout/footer/Footer.vue +8 -0
- package/app/components/layout/header/AppBar.vue +11 -4
- package/app/components/layout/header/MainNav.vue +26 -4
- package/app/components/layout/header/MobileMenu.vue +12 -0
- package/app/components/listing/ListingResults.vue +3 -1
- package/app/components/product/card/Compact.vue +10 -1
- package/app/components/product/detail/ProductDetailAddToCart.vue +51 -18
- package/app/components/product/detail/ProductDetailIdentity.vue +1 -1
- package/app/components/product/detail/ProductDetailPriceRequest.vue +39 -0
- package/app/components/product/detail/ProductDetailSaveToList.vue +10 -0
- package/app/components/product/detail/ProductDetailView.vue +57 -0
- package/app/composables/useAccountDashboard.ts +0 -10
- package/app/composables/useAccountHold.ts +45 -0
- package/app/composables/useAccountNavigation.ts +35 -0
- package/app/composables/useAccountPayments.ts +21 -0
- package/app/composables/useAccountQuotes.ts +15 -2
- package/app/composables/useAuthStore.ts +84 -2
- package/app/composables/useAuthoredForms.ts +26 -0
- package/app/composables/useAvailableOffers.ts +42 -0
- package/app/composables/useCategoryListing.ts +6 -0
- package/app/composables/useCheckoutOnePage.ts +21 -2
- package/app/composables/useGuestOrdering.ts +28 -0
- package/app/composables/useMasterDataEditable.ts +45 -7
- package/app/composables/useOrderListRules.ts +21 -1
- package/app/composables/usePendingApprovals.ts +37 -0
- package/app/composables/useProductCard.ts +29 -2
- package/app/composables/useProductListing.ts +79 -0
- package/app/composables/useQuantityStepper.ts +90 -0
- package/app/composables/useQuickActions.ts +35 -0
- package/app/composables/useRoleGrants.ts +32 -0
- package/app/composables/useSearchListing.ts +4 -0
- package/app/composables/useThemeEvents.ts +144 -0
- package/app/config/accountDashboard.ts +26 -0
- package/app/config/icons.ts +2 -0
- package/app/config/navigation.ts +2 -2
- package/app/config/quickActions.ts +40 -5
- package/app/formkit.config.ts +14 -0
- package/app/interfaces/account/approvals.ts +37 -0
- package/app/interfaces/account/dashboard.ts +2 -0
- package/app/interfaces/account/order-list.ts +29 -0
- package/app/interfaces/account/order-lists.ts +9 -0
- package/app/interfaces/account/payments.ts +48 -0
- package/app/interfaces/auth.ts +24 -2
- package/app/interfaces/b2b.ts +8 -8
- package/app/interfaces/offers.ts +35 -0
- package/app/interfaces/quantity-stepper.ts +17 -0
- package/app/interfaces/shopSettings.ts +77 -0
- package/app/layouts/default.vue +19 -10
- package/app/layouts/focus.vue +28 -7
- package/app/middleware/checkout-guard.ts +7 -1
- package/app/pages/punchout/transfer.vue +22 -0
- package/app/plugins/account-hold.client.ts +20 -0
- package/app/plugins/shop-settings.ts +27 -12
- package/app/plugins/theme-events.client.ts +132 -0
- package/app/shared/themeEvents.ts +445 -0
- package/i18n/locales/de/account.json +87 -0
- package/i18n/locales/de/auth.json +30 -0
- package/i18n/locales/de/cart.json +9 -1
- package/i18n/locales/de/checkout.json +4 -2
- package/i18n/locales/de/common.json +4 -0
- package/i18n/locales/de/cover.json +44 -0
- package/i18n/locales/de/editor.json +47 -1
- package/i18n/locales/de/forms.json +27 -0
- package/i18n/locales/en/account.json +87 -0
- package/i18n/locales/en/auth.json +30 -0
- package/i18n/locales/en/cart.json +9 -1
- package/i18n/locales/en/checkout.json +4 -2
- package/i18n/locales/en/common.json +4 -0
- package/i18n/locales/en/cover.json +44 -0
- package/i18n/locales/en/editor.json +47 -1
- package/i18n/locales/en/forms.json +27 -0
- package/nuxt.config.ts +15 -1
- package/package.json +6 -2
- package/server/api/account/address/[id].delete.ts +1 -1
- package/server/api/account/address/[id].put.ts +1 -1
- package/server/api/account/address/index.post.ts +1 -1
- package/server/api/account/order-lists/[id].get.ts +37 -3
- package/server/api/account/orders/[id]/cancel.post.ts +54 -0
- package/server/api/account/orders/[id]/messages.get.ts +63 -0
- package/server/api/account/orders/[id]/messages.post.ts +44 -0
- package/server/api/account/orders/[id]/return.post.ts +1 -0
- package/server/api/account/orders/[id].get.ts +1 -1
- package/server/api/account/organization.put.ts +1 -1
- package/server/api/account/payments.get.ts +54 -0
- package/server/api/account/pending-approvals/[id]/approve.post.ts +10 -0
- package/server/api/account/pending-approvals/[id]/decline.post.ts +10 -0
- package/server/api/account/pending-approvals/index.get.ts +26 -0
- package/server/api/account/profile.get.ts +3 -1
- package/server/api/account/profile.put.ts +1 -1
- package/server/api/account/quotes/[id]/decline.post.ts +35 -6
- package/server/api/account/team/[id].put.ts +1 -1
- package/server/api/account/team.post.ts +1 -1
- package/server/api/auth/login.post.ts +6 -0
- package/server/api/auth/magic-link.post.ts +32 -0
- package/server/api/auth/magic-link.put.ts +35 -0
- package/server/api/auth/otp.post.ts +33 -0
- package/server/api/auth/otp.put.ts +33 -0
- package/server/api/carts/[id]/activate.post.ts +1 -0
- package/server/api/carts/[id]/index.delete.ts +1 -0
- package/server/api/carts/[id]/index.put.ts +1 -0
- package/server/api/carts/[id]/items.post.ts +1 -0
- package/server/api/checkout/profile.get.ts +6 -3
- package/server/api/forms/[slug]/submit.post.ts +27 -16
- package/server/api/forms/[slug].get.ts +9 -1
- package/server/api/forms/index.get.ts +23 -0
- package/server/api/orders/index.post.ts +41 -0
- package/server/api/promotions/available.post.ts +37 -0
- package/server/api/quick-actions.get.ts +6 -38
- package/server/config/account/organization.json +0 -4
- package/server/config/shop/app-settings.json +4 -0
- package/server/data/forms/authored.json +337 -0
- package/server/interfaces/forms.ts +51 -0
- package/server/middleware/buyer-principal.ts +18 -0
- package/server/routes/punchout/start.get.ts +2 -2
- package/server/services/ApiAddressBookService.ts +43 -1
- package/server/services/ApiAuthService.ts +101 -10
- package/server/services/ApiCartService.ts +3 -10
- package/server/services/ApiFormsService.ts +56 -0
- package/server/services/ApiOrganizationService.ts +7 -2
- package/server/services/ApiTeamService.ts +93 -21
- package/server/services/MockB2BContextService.ts +1 -5
- package/server/services/MockFormsService.ts +63 -0
- package/server/utils/accountPayments.ts +45 -0
- package/server/utils/appSettings.ts +69 -4
- package/server/utils/buyerIdentity.ts +168 -0
- package/server/utils/cartOwnership.ts +27 -0
- package/server/utils/forms.ts +62 -14
- package/server/utils/formsService.ts +29 -0
- package/server/utils/liveOrderLists.ts +50 -23
- package/server/utils/liveOrders.ts +65 -24
- package/server/utils/livePrices.ts +7 -15
- package/server/utils/masterData.ts +60 -11
- package/server/utils/passwordlessSignIn.ts +82 -0
- package/server/utils/pendingApprovals.ts +175 -0
- package/server/utils/procurementCheckout.ts +2 -0
- package/server/utils/promotionsService.ts +90 -0
- package/server/utils/quickActionCatalogue.ts +53 -0
- package/server/utils/quotesService.ts +15 -0
- package/server/utils/revenexxSdk.ts +116 -2
- package/server/utils/shopSettings.ts +35 -4
|
@@ -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
|
+
|
|
@@ -30,6 +30,54 @@ export function isAppSettingsLive(event?: H3Event): boolean {
|
|
|
30
30
|
|
|
31
31
|
export type AppSettings = Record<string, unknown>;
|
|
32
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Cookie the demo shop's dev panel writes to try a setting without a Console
|
|
35
|
+
* round-trip: `{ "<app>": { "<key>": value } }`.
|
|
36
|
+
*
|
|
37
|
+
* It is a SIMULATION and says so — a request carrying it reports its settings as
|
|
38
|
+
* the demo's, whatever they were read from, so nothing can mistake a tried value
|
|
39
|
+
* for a configured one. Without that, the panel would be a fourth place a term of
|
|
40
|
+
* sale is decided, which is the thing this whole reader exists to remove.
|
|
41
|
+
*/
|
|
42
|
+
export const APP_SETTINGS_OVERRIDE_COOKIE = "cover-app-settings";
|
|
43
|
+
|
|
44
|
+
function readOverride(event: H3Event | undefined, app: string): AppSettings | null {
|
|
45
|
+
if (!event) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
const raw = getCookie(event, APP_SETTINGS_OVERRIDE_COOKIE);
|
|
49
|
+
if (!raw) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
const parsed = JSON.parse(raw) as Record<string, AppSettings>;
|
|
54
|
+
const section = parsed?.[app];
|
|
55
|
+
return section && typeof section === "object" ? section : null;
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
// A malformed cookie is a dev-panel bug, not a reason to stop serving.
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Whether this request is carrying any tried-out setting at all. */
|
|
64
|
+
export function hasAppSettingsOverride(event?: H3Event): boolean {
|
|
65
|
+
if (!event) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
const raw = getCookie(event, APP_SETTINGS_OVERRIDE_COOKIE);
|
|
69
|
+
if (!raw) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
const parsed = JSON.parse(raw) as Record<string, unknown>;
|
|
74
|
+
return Boolean(parsed && typeof parsed === "object" && Object.keys(parsed).length > 0);
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
33
81
|
/**
|
|
34
82
|
* How long a resolved app's settings are reused across requests.
|
|
35
83
|
*
|
|
@@ -77,8 +125,9 @@ function requestCache(event?: H3Event): Map<string, AppSettings> | undefined {
|
|
|
77
125
|
* and a live tenant then differ in their settings, never in their behaviour.
|
|
78
126
|
*/
|
|
79
127
|
export async function readAppSettings(event: H3Event | undefined, app: string): Promise<AppSettings> {
|
|
128
|
+
const override = readOverride(event, app);
|
|
80
129
|
if (!isAppSettingsLive(event)) {
|
|
81
|
-
return await readDemoAppSettings(app);
|
|
130
|
+
return { ...await readDemoAppSettings(app), ...override };
|
|
82
131
|
}
|
|
83
132
|
|
|
84
133
|
const market = event ? resolveSelectedMarket(event) : undefined;
|
|
@@ -86,16 +135,22 @@ export async function readAppSettings(event: H3Event | undefined, app: string):
|
|
|
86
135
|
// tenant's page with another's settings (see revenexxTenantKey()).
|
|
87
136
|
const key = `${revenexxTenantKey()}|${app}|${market ?? "-"}`;
|
|
88
137
|
|
|
138
|
+
// The override is applied at every exit below rather than folded into the
|
|
139
|
+
// cache: what is cached is what the TENANT configured, and a value somebody is
|
|
140
|
+
// trying in one browser must never be served to another.
|
|
141
|
+
const withOverride = (settings: AppSettings): AppSettings =>
|
|
142
|
+
override ? { ...settings, ...override } : settings;
|
|
143
|
+
|
|
89
144
|
const perRequest = requestCache(event);
|
|
90
145
|
const memo = perRequest?.get(key);
|
|
91
146
|
if (memo) {
|
|
92
|
-
return memo;
|
|
147
|
+
return withOverride(memo);
|
|
93
148
|
}
|
|
94
149
|
|
|
95
150
|
const cached = cache.get(key);
|
|
96
151
|
if (cached && cached.expires > Date.now()) {
|
|
97
152
|
perRequest?.set(key, cached.settings);
|
|
98
|
-
return cached.settings;
|
|
153
|
+
return withOverride(cached.settings);
|
|
99
154
|
}
|
|
100
155
|
|
|
101
156
|
let pending = inFlight.get(key);
|
|
@@ -111,7 +166,7 @@ export async function readAppSettings(event: H3Event | undefined, app: string):
|
|
|
111
166
|
|
|
112
167
|
const settings = await pending;
|
|
113
168
|
perRequest?.set(key, settings);
|
|
114
|
-
return settings;
|
|
169
|
+
return withOverride(settings);
|
|
115
170
|
}
|
|
116
171
|
|
|
117
172
|
async function fetchAppSettings(app: string, market: string | undefined): Promise<AppSettings> {
|
|
@@ -202,6 +257,16 @@ export function stringSetting(settings: AppSettings, key: string, fallback: stri
|
|
|
202
257
|
return typeof raw === "string" && raw.trim() !== "" ? raw.trim() : fallback;
|
|
203
258
|
}
|
|
204
259
|
|
|
260
|
+
/**
|
|
261
|
+
* A string setting the app leaves empty by default — "" and absent both mean
|
|
262
|
+
* unset, and null says so in one shape rather than making every reader compare
|
|
263
|
+
* against the empty string.
|
|
264
|
+
*/
|
|
265
|
+
export function optionalStringSetting(settings: AppSettings, key: string): string | null {
|
|
266
|
+
const raw = settings[key];
|
|
267
|
+
return typeof raw === "string" && raw.trim() !== "" ? raw.trim() : null;
|
|
268
|
+
}
|
|
269
|
+
|
|
205
270
|
/** A comma-separated list, the shape the settings schema uses for those. */
|
|
206
271
|
export function listSetting(settings: AppSettings, key: string, fallback: readonly string[]): string[] {
|
|
207
272
|
const raw = settings[key];
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import type { H3Event } from "h3";
|
|
2
|
+
|
|
3
|
+
import type { AuthRole, AuthUser } from "../../app/interfaces/auth";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Who the signed-in buyer of this request IS — as the customers app answered
|
|
7
|
+
* it, never as the browser claims it (RAD-155).
|
|
8
|
+
*
|
|
9
|
+
* The session cookie is plain JSON the browser can rewrite. It used to carry the
|
|
10
|
+
* contact and organization ids, and every live service read them straight back:
|
|
11
|
+
* a buyer who edited the cookie listed, invited into and ordered for any
|
|
12
|
+
* organization they could name. The cookie now only points at a platform session
|
|
13
|
+
* (user id + session id), and the identity behind it is resolved per request
|
|
14
|
+
* through `/customers/auth/me`, which refuses a session that is not that user's
|
|
15
|
+
* live one. What it answers is remembered on the event, here, and everything
|
|
16
|
+
* that needs a contact or an organization reads it from here.
|
|
17
|
+
*
|
|
18
|
+
* Why not a sealed cookie: a deployed Site is a brokered build serving any
|
|
19
|
+
* tenant with no per-site secret configured (the checkout token falls back to a
|
|
20
|
+
* constant there for exactly that reason), so a sealing key would either be a
|
|
21
|
+
* shared constant — forgeable — or fail closed and sign every buyer out. And
|
|
22
|
+
* auth/me is already on the request path of most account routes; resolving it
|
|
23
|
+
* once per request and reusing it costs little and also notices a block or a
|
|
24
|
+
* revoked session immediately, which a sealed cookie would not.
|
|
25
|
+
*
|
|
26
|
+
* The same answer is what the SDK client attributes the request to: the
|
|
27
|
+
* contact id lands in `X-Revenexx-Principal` (see useRevenexxSdk), and the
|
|
28
|
+
* customers app then holds the buyer to its self-service allowlist.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
const BUYER_KEY = "coverVerifiedBuyer";
|
|
32
|
+
const PRINCIPAL_KEY = "revenexxPrincipal";
|
|
33
|
+
|
|
34
|
+
type BuyerContext = Record<string, unknown>;
|
|
35
|
+
|
|
36
|
+
function contextOf(event: H3Event | undefined): BuyerContext | null {
|
|
37
|
+
const context = (event as { context?: BuyerContext } | undefined)?.context;
|
|
38
|
+
return context && typeof context === "object" ? context : null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Record what the identity service answered for this request. Only a verified
|
|
43
|
+
* answer comes through here; null records "signed out" so a second read in the
|
|
44
|
+
* same request does not ask again.
|
|
45
|
+
*/
|
|
46
|
+
export function rememberVerifiedBuyer(event: H3Event, user: AuthUser | null): void {
|
|
47
|
+
const context = contextOf(event);
|
|
48
|
+
if (!context) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
context[BUYER_KEY] = user;
|
|
52
|
+
if (user?.contactId) {
|
|
53
|
+
context[PRINCIPAL_KEY] = `contact:${user.contactId}`;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
delete context[PRINCIPAL_KEY];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Forget it again — after a sign-out within the same request. */
|
|
61
|
+
export function forgetVerifiedBuyer(event: H3Event): void {
|
|
62
|
+
const context = contextOf(event);
|
|
63
|
+
if (context) {
|
|
64
|
+
delete context[BUYER_KEY];
|
|
65
|
+
delete context[PRINCIPAL_KEY];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The verified buyer of this request: the user, null when signed out, or
|
|
71
|
+
* undefined when nothing resolved it yet. Synchronous on purpose — the
|
|
72
|
+
* buyer-principal middleware resolves it before any /api handler runs.
|
|
73
|
+
*/
|
|
74
|
+
export function verifiedBuyer(event: H3Event | undefined): AuthUser | null | undefined {
|
|
75
|
+
const context = contextOf(event);
|
|
76
|
+
if (!context || !(BUYER_KEY in context)) {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
return context[BUYER_KEY] as AuthUser | null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The value for `X-Revenexx-Principal`, or "" when the request acts for no
|
|
84
|
+
* verified buyer. Never derived from anything the browser sent.
|
|
85
|
+
*/
|
|
86
|
+
export function buyerPrincipal(event: H3Event | undefined): string {
|
|
87
|
+
const value = contextOf(event)?.[PRINCIPAL_KEY];
|
|
88
|
+
return typeof value === "string" ? value : "";
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Least → most privileged, as the customers app orders its built-ins. A role
|
|
93
|
+
* the shop does not know ranks below all of them, so it can grant nothing.
|
|
94
|
+
*/
|
|
95
|
+
const ROLE_RANK: Record<AuthRole, number> = {
|
|
96
|
+
requester: 0,
|
|
97
|
+
buyer: 1,
|
|
98
|
+
approver: 2,
|
|
99
|
+
admin: 3,
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export function roleRank(role: string | undefined | null): number {
|
|
103
|
+
return role && role in ROLE_RANK ? ROLE_RANK[role as AuthRole] : -1;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** May somebody holding `own` hand `target` to another person? */
|
|
107
|
+
export function mayGrantRole(own: string | undefined | null, target: string | undefined | null): boolean {
|
|
108
|
+
const ownRank = roleRank(own);
|
|
109
|
+
const targetRank = roleRank(target);
|
|
110
|
+
return ownRank >= 0 && targetRank >= 0 && targetRank <= ownRank;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Does the verified buyer hold this permission? `undefined` permissions mean
|
|
115
|
+
* the source never said (the demo personas): `whenUnstated` decides.
|
|
116
|
+
*/
|
|
117
|
+
export function buyerHolds(user: AuthUser | null | undefined, permission: string, whenUnstated: boolean): boolean {
|
|
118
|
+
if (!user) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
if (!Array.isArray(user.permissions)) {
|
|
122
|
+
return whenUnstated;
|
|
123
|
+
}
|
|
124
|
+
return user.permissions.includes(permission);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** The permission answer the customers app puts beside a contact on login, redeem and auth/me. */
|
|
128
|
+
export interface CustomersPermissionAnswer {
|
|
129
|
+
readonly role?: string | null;
|
|
130
|
+
readonly permissions?: readonly string[] | null;
|
|
131
|
+
readonly active?: boolean | null;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* The grants and the may-act flag from a customers sign-in or auth/me answer.
|
|
136
|
+
*
|
|
137
|
+
* `active` lives on the permission answer: a contact row has no such column
|
|
138
|
+
* (it has `status`), so the shop used to read a field that was never there and
|
|
139
|
+
* every blocked buyer looked active. The contact's own `active` is still read
|
|
140
|
+
* as a fallback, in case an answer carries it.
|
|
141
|
+
*
|
|
142
|
+
* Permissions are always STATED for a live session — an empty list when the
|
|
143
|
+
* app answered none (no contact, or a role that grants nothing) — so a check
|
|
144
|
+
* against them can fail closed.
|
|
145
|
+
*/
|
|
146
|
+
export function grantsFrom(
|
|
147
|
+
answer: CustomersPermissionAnswer | null | undefined,
|
|
148
|
+
contact?: { active?: boolean | null } | null,
|
|
149
|
+
): { permissions: string[]; active?: boolean } {
|
|
150
|
+
const active = typeof answer?.active === "boolean"
|
|
151
|
+
? answer.active
|
|
152
|
+
: typeof contact?.active === "boolean" ? contact.active : undefined;
|
|
153
|
+
return {
|
|
154
|
+
permissions: Array.isArray(answer?.permissions) ? answer.permissions.filter(p => typeof p === "string") : [],
|
|
155
|
+
...(active === undefined ? {} : { active }),
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Which requests resolve the buyer up front (server/middleware). Every BFF
|
|
161
|
+
* route does, except the sign-in routes: logging in, registering and asking for
|
|
162
|
+
* a mailed link act for nobody yet and must send no principal, and
|
|
163
|
+
* `/api/auth/me` resolves the buyer on its own.
|
|
164
|
+
*/
|
|
165
|
+
export function needsVerifiedBuyer(path: string): boolean {
|
|
166
|
+
// `/api/_…` is module plumbing (icons and the like), not a buyer's request.
|
|
167
|
+
return path.startsWith("/api/") && !path.startsWith("/api/auth/") && !path.startsWith("/api/_");
|
|
168
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { H3Event } from "h3";
|
|
2
|
+
|
|
3
|
+
import type { ICartManager } from "../interfaces/cart";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Refuse a cart the request does not own.
|
|
7
|
+
*
|
|
8
|
+
* The cart id of the multi-cart routes comes from the URL, and the carts app
|
|
9
|
+
* does not narrow a write to the acting buyer — so without this, anybody who
|
|
10
|
+
* learned a cart id could rename, empty into, activate or delete somebody else's
|
|
11
|
+
* cart (RAD-155). A cart is the request's own when it is among the carts listed
|
|
12
|
+
* for the verified contact, or for the guest session. Anybody else's answers
|
|
13
|
+
* exactly like one that does not exist.
|
|
14
|
+
*/
|
|
15
|
+
export async function assertOwnCart(event: H3Event, manager: ICartManager, id: string): Promise<void> {
|
|
16
|
+
let ids: string[];
|
|
17
|
+
try {
|
|
18
|
+
ids = (await manager.listCarts(event)).carts.map(cart => cart.id);
|
|
19
|
+
}
|
|
20
|
+
catch (err) {
|
|
21
|
+
getLogService().error("Service error: carts/ownership", toErrorContext(err));
|
|
22
|
+
throw createError({ statusCode: 502, message: "Cart service unavailable" });
|
|
23
|
+
}
|
|
24
|
+
if (!ids.includes(id)) {
|
|
25
|
+
throw createError({ statusCode: 404, message: "Cart not found" });
|
|
26
|
+
}
|
|
27
|
+
}
|
package/server/utils/forms.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { H3Event } from "h3";
|
|
2
|
+
|
|
3
|
+
import type { FormRow, FormSettings, FormSpamPolicy } from "../interfaces/forms";
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Run a form's post-submit actions once a submission is recorded. Best-effort
|
|
@@ -78,19 +80,65 @@ export function localizeDefinition(
|
|
|
78
80
|
}
|
|
79
81
|
|
|
80
82
|
/**
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
|
|
83
|
+
* The field names a definition declares. Only a named node collects a value —
|
|
84
|
+
* the same rule the app counts its field ceiling by — so content nodes and step
|
|
85
|
+
* markers contribute nothing.
|
|
86
|
+
*/
|
|
87
|
+
export function namedFields(definition: Record<string, unknown>[]): Set<string> {
|
|
88
|
+
const names = new Set<string>();
|
|
89
|
+
for (const node of definition) {
|
|
90
|
+
if (node && typeof node === "object" && typeof node.name === "string" && node.name !== "") {
|
|
91
|
+
names.add(node.name);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return names;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* What of a submission reaches the tenant's inbox.
|
|
99
|
+
*
|
|
100
|
+
* A submission is stored as sent — that is the decision: the app itself stores
|
|
101
|
+
* whatever arrives, and a shop that refused a missing field would be stricter
|
|
102
|
+
* than the record it writes into. What the shop DOES do is drop what the form
|
|
103
|
+
* never asked for, because the only caller that can send an undeclared key is
|
|
104
|
+
* one that did not use the form, and a key nobody authored is a column nobody
|
|
105
|
+
* will ever read.
|
|
85
106
|
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* exact-column filters mountCrud honors and the gateway passes through.
|
|
107
|
+
* The decoy field survives on purpose: the app needs it to judge the submission
|
|
108
|
+
* and strips it before storing.
|
|
89
109
|
*/
|
|
90
|
-
export
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
110
|
+
export function sanitizeSubmission(
|
|
111
|
+
definition: Record<string, unknown>[],
|
|
112
|
+
data: Record<string, unknown>,
|
|
113
|
+
honeypotField: string | null,
|
|
114
|
+
): Record<string, unknown> {
|
|
115
|
+
const allowed = namedFields(definition);
|
|
116
|
+
const out: Record<string, unknown> = {};
|
|
117
|
+
for (const [key, value] of Object.entries(data)) {
|
|
118
|
+
if (allowed.has(key) || (honeypotField !== null && key === honeypotField)) {
|
|
119
|
+
out[key] = value;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return out;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Whether a submission filled the decoy in.
|
|
127
|
+
*
|
|
128
|
+
* A human never sees the field and therefore never fills it; a bot fills
|
|
129
|
+
* everything. Whitespace does not count — a field a browser autofilled with a
|
|
130
|
+
* space is not a bot, and treating it as one would silently drop a real enquiry.
|
|
131
|
+
*/
|
|
132
|
+
export function decoyFilled(data: Record<string, unknown>, honeypotField: string | null): boolean {
|
|
133
|
+
if (!honeypotField) {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
const value = data[honeypotField];
|
|
137
|
+
return value !== undefined && value !== null && String(value).trim() !== "";
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** The two forms settings the storefront owes the app, from the one reader. */
|
|
141
|
+
export async function resolveFormSpamPolicy(event: H3Event): Promise<FormSpamPolicy> {
|
|
142
|
+
const { forms } = await getShopSettings(event);
|
|
143
|
+
return { honeypotField: forms.honeypotField, spamHandling: forms.spamHandling };
|
|
96
144
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { H3Event } from "h3";
|
|
2
|
+
|
|
3
|
+
import type { IFormsService } from "../interfaces/forms";
|
|
4
|
+
import { ApiFormsService } from "../services/ApiFormsService";
|
|
5
|
+
import { MockFormsService } from "../services/MockFormsService";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Registry of authored-form sources:
|
|
9
|
+
* - "mock" — the three bundled demo forms
|
|
10
|
+
* - "api" — the forms app through the public revenexx API
|
|
11
|
+
*
|
|
12
|
+
* This domain used to have no key at all: the BFF called the gateway
|
|
13
|
+
* unconditionally, so the one page that renders a form needed live credentials
|
|
14
|
+
* and a tenant that had published under that slug. A storefront with no
|
|
15
|
+
* credentials had a contact page that showed nothing and said nothing.
|
|
16
|
+
*/
|
|
17
|
+
const serviceRegistry: Record<string, IFormsService> = {
|
|
18
|
+
mock: new MockFormsService(),
|
|
19
|
+
api: new ApiFormsService(),
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export function getFormsService(event?: H3Event): IFormsService {
|
|
23
|
+
const key = resolveServiceKey(event, {
|
|
24
|
+
domain: "formsService",
|
|
25
|
+
mockKey: "mock",
|
|
26
|
+
liveKey: "api",
|
|
27
|
+
});
|
|
28
|
+
return serviceRegistry[key] ?? serviceRegistry["mock"]!;
|
|
29
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { H3Event } from "h3";
|
|
2
|
+
import { RevenexxException } from "@revenexx/sdk";
|
|
2
3
|
import type { Models } from "@revenexx/sdk";
|
|
3
4
|
|
|
4
5
|
import type { OrderList, OrderListPosition } from "../../app/interfaces/account/order-lists";
|
|
6
|
+
import type { RevenexxSdk } from "./revenexxSdk";
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
9
|
* Live order lists through the `orderlists` gateway app
|
|
@@ -16,6 +18,11 @@ import type { OrderList, OrderListPosition } from "../../app/interfaces/account/
|
|
|
16
18
|
* returns the owner's own lists ∪ the organization's shared lists. We supply
|
|
17
19
|
* both from the authenticated contact (auth/me). The cover OrderList keeps
|
|
18
20
|
* `public` UI-side; it maps to the app's `shared`.
|
|
21
|
+
*
|
|
22
|
+
* Access: every call carries the contact as `X-Revenexx-Principal`
|
|
23
|
+
* (RAD-168). With it, orderlists (>= 1.0, RAD-134) answers 404 for another
|
|
24
|
+
* customer's private list — items included; without it the tenant key reads
|
|
25
|
+
* every list of the tenant. That 404 is passed on as cover's own.
|
|
19
26
|
*/
|
|
20
27
|
|
|
21
28
|
interface AppItem {
|
|
@@ -56,6 +63,24 @@ async function actor(event: H3Event): Promise<{ contactId: string; name: string;
|
|
|
56
63
|
return { contactId: user.contactId, name: user.name, organizationId: user.organizationId };
|
|
57
64
|
}
|
|
58
65
|
|
|
66
|
+
/** The SDK acting as the signed-in contact. */
|
|
67
|
+
function sdkAs(me: { contactId: string }): RevenexxSdk {
|
|
68
|
+
return useRevenexxSdk({ principal: `contact:${me.contactId}` });
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** A list the principal may not see is one that does not exist. */
|
|
72
|
+
async function orNotFound<T>(run: () => Promise<T>): Promise<T> {
|
|
73
|
+
try {
|
|
74
|
+
return await run();
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
if (err instanceof RevenexxException && err.code === 404) {
|
|
78
|
+
throw createError({ statusCode: 404, message: "List not found" });
|
|
79
|
+
}
|
|
80
|
+
throw err;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
59
84
|
function toCoverPosition(item: AppItem): OrderListPosition {
|
|
60
85
|
return {
|
|
61
86
|
// cover treats position.id as the PRODUCT id (membership flag on the
|
|
@@ -175,7 +200,7 @@ function toCoverList(row: AppList): OrderList {
|
|
|
175
200
|
/** Own lists ∪ org-shared, each with its positions (bounded fan-out). */
|
|
176
201
|
export async function listOrderLists(event: H3Event): Promise<OrderList[]> {
|
|
177
202
|
const me = await actor(event);
|
|
178
|
-
const sdk =
|
|
203
|
+
const sdk = sdkAs(me);
|
|
179
204
|
// Typed list filter (orderlists.list declares owner_id/organization_id —
|
|
180
205
|
// @revenexx/sdk >= 0.0.11). The fan-out to full lists is typed too.
|
|
181
206
|
const { items } = await sdk.orderlists.orderlistsList({
|
|
@@ -187,8 +212,8 @@ export async function listOrderLists(event: H3Event): Promise<OrderList[]> {
|
|
|
187
212
|
}
|
|
188
213
|
|
|
189
214
|
export async function getOrderList(event: H3Event, id: string): Promise<OrderList> {
|
|
190
|
-
await actor(event);
|
|
191
|
-
const row = await
|
|
215
|
+
const me = await actor(event);
|
|
216
|
+
const row = await orNotFound(() => sdkAs(me).orderlists.orderlistsGet({ id }));
|
|
192
217
|
return toCoverList(row as unknown as AppList);
|
|
193
218
|
}
|
|
194
219
|
|
|
@@ -197,7 +222,7 @@ export async function createOrderList(
|
|
|
197
222
|
body: { name: string; kind?: string; public?: boolean; positions?: OrderListPosition[] },
|
|
198
223
|
): Promise<OrderList> {
|
|
199
224
|
const me = await actor(event);
|
|
200
|
-
const row = await
|
|
225
|
+
const row = await sdkAs(me).orderlists.orderlistsCreate({
|
|
201
226
|
name: body.name,
|
|
202
227
|
ownerId: me.contactId,
|
|
203
228
|
ownerName: me.name,
|
|
@@ -214,28 +239,30 @@ export async function updateOrderList(
|
|
|
214
239
|
id: string,
|
|
215
240
|
body: { name?: string; public?: boolean; positions?: OrderListPosition[]; appendPositions?: OrderListPosition[] },
|
|
216
241
|
): Promise<OrderList> {
|
|
217
|
-
await actor(event);
|
|
218
|
-
const sdk =
|
|
219
|
-
|
|
220
|
-
if (typeof body.name === "string" && body.name.trim() || typeof body.public === "boolean") {
|
|
221
|
-
await sdk.orderlists.orderlistsUpdate({
|
|
222
|
-
id,
|
|
223
|
-
...(typeof body.name === "string" && body.name.trim() ? { name: body.name.trim() } : {}),
|
|
224
|
-
...(typeof body.public === "boolean" ? { shared: body.public } : {}),
|
|
225
|
-
});
|
|
226
|
-
}
|
|
242
|
+
const me = await actor(event);
|
|
243
|
+
const sdk = sdkAs(me);
|
|
227
244
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
245
|
+
return await orNotFound(async () => {
|
|
246
|
+
if (typeof body.name === "string" && body.name.trim() || typeof body.public === "boolean") {
|
|
247
|
+
await sdk.orderlists.orderlistsUpdate({
|
|
248
|
+
id,
|
|
249
|
+
...(typeof body.name === "string" && body.name.trim() ? { name: body.name.trim() } : {}),
|
|
250
|
+
...(typeof body.public === "boolean" ? { shared: body.public } : {}),
|
|
251
|
+
});
|
|
252
|
+
}
|
|
234
253
|
|
|
235
|
-
|
|
254
|
+
if (Array.isArray(body.positions)) {
|
|
255
|
+
await sdk.orderlists.orderlistsItemsReplace({ listId: id, items: body.positions.map(toItemInput) });
|
|
256
|
+
}
|
|
257
|
+
for (const position of body.appendPositions ?? []) {
|
|
258
|
+
await sdk.orderlists.orderlistsItemsCreate({ listId: id, ...toItemCreateParams(position) });
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
return toCoverList(await sdk.orderlists.orderlistsGet({ id }) as unknown as AppList);
|
|
262
|
+
});
|
|
236
263
|
}
|
|
237
264
|
|
|
238
265
|
export async function deleteOrderList(event: H3Event, id: string): Promise<void> {
|
|
239
|
-
await actor(event);
|
|
240
|
-
await
|
|
266
|
+
const me = await actor(event);
|
|
267
|
+
await orNotFound(() => sdkAs(me).orderlists.orderlistsDelete({ id }));
|
|
241
268
|
}
|