@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
|
@@ -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
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { getCookie } from "h3";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Resolve the signed-in buyer before any BFF handler runs (RAD-155).
|
|
5
|
+
*
|
|
6
|
+
* Every live service reads the buyer's contact and organization synchronously
|
|
7
|
+
* (sessionOrderRefs), and every SDK call puts the contact on the wire as its
|
|
8
|
+
* principal — both from what the identity service verified for THIS request,
|
|
9
|
+
* never from the cookie. Doing it here, once, is what makes both true for
|
|
10
|
+
* every route instead of only for the routes that remembered to ask.
|
|
11
|
+
* Which paths: needsVerifiedBuyer.
|
|
12
|
+
*/
|
|
13
|
+
export default defineEventHandler(async (event) => {
|
|
14
|
+
if (!needsVerifiedBuyer(event.path) || !getCookie(event, SESSION_COOKIE_NAME)) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
await getAuthService(event).me(event);
|
|
18
|
+
});
|
|
@@ -108,9 +108,9 @@ export default defineEventHandler(async (event) => {
|
|
|
108
108
|
const stored: StoredSession = {
|
|
109
109
|
id: session.$id,
|
|
110
110
|
expire: session.expire,
|
|
111
|
+
// The contact and organization are not written: the browser can rewrite
|
|
112
|
+
// this cookie, so they are re-resolved per request (RAD-155).
|
|
111
113
|
userId: session.userId,
|
|
112
|
-
...(signedIn.contact?.id ? { contactId: signedIn.contact.id } : {}),
|
|
113
|
-
...(signedIn.contact?.organization_id ? { organizationId: signedIn.contact.organization_id } : {}),
|
|
114
114
|
};
|
|
115
115
|
setCookie(event, SESSION_COOKIE_NAME, JSON.stringify(stored), sessionCookieOptions(session.expire));
|
|
116
116
|
|
|
@@ -57,7 +57,8 @@ function toAccountAddress(row: ApiAddressRow, companyFallback = ""): AccountAddr
|
|
|
57
57
|
/**
|
|
58
58
|
* Live address book: the signed-in buyer's addresses in the customers app —
|
|
59
59
|
* their own AND their company's, because in B2B the delivery addresses belong
|
|
60
|
-
* to the company. Both references
|
|
60
|
+
* to the company. Both references are the ones the identity service verified
|
|
61
|
+
* for this request (RAD-155), never ids the browser supplied; guests have no
|
|
61
62
|
* address book. The customers schema requires ISO 3166-1 alpha-2 countries.
|
|
62
63
|
*/
|
|
63
64
|
export class ApiAddressBookService implements IAddressBookService {
|
|
@@ -86,6 +87,33 @@ export class ApiAddressBookService implements IAddressBookService {
|
|
|
86
87
|
}
|
|
87
88
|
}
|
|
88
89
|
|
|
90
|
+
/**
|
|
91
|
+
* Refuse a change to an address that is neither the buyer's own nor their
|
|
92
|
+
* company's. The id comes from the URL, so without this any buyer could
|
|
93
|
+
* rewrite or delete any address they could name (RAD-155). Somebody else's
|
|
94
|
+
* address is answered exactly like one that does not exist.
|
|
95
|
+
*/
|
|
96
|
+
private async requireOwnAddress(event: H3Event, id: string): Promise<void> {
|
|
97
|
+
const { contact_id, organization_id } = this.contactRef(event);
|
|
98
|
+
let row: ApiAddressRow | null = null;
|
|
99
|
+
try {
|
|
100
|
+
row = await useRevenexxSdk().customersOrganizations.customersAddressesGet({ id }) as unknown as ApiAddressRow;
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
if (!(err instanceof RevenexxException && (err.code === 404 || err.code === 403))) {
|
|
104
|
+
getLogService().error("API request failed: addresses/get", apiErrorContext(err));
|
|
105
|
+
throw createError({ statusCode: 502, statusMessage: "Address service unavailable" });
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const own = !!row && (
|
|
109
|
+
(!!contact_id && row.contact_id === contact_id)
|
|
110
|
+
|| (!!organization_id && row.organization_id === organization_id)
|
|
111
|
+
);
|
|
112
|
+
if (!own) {
|
|
113
|
+
throw createError({ statusCode: 404, statusMessage: "Address not found" });
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
89
117
|
private requireContact(event: H3Event): string {
|
|
90
118
|
const { contact_id } = this.contactRef(event);
|
|
91
119
|
if (!contact_id) {
|
|
@@ -166,6 +194,10 @@ export class ApiAddressBookService implements IAddressBookService {
|
|
|
166
194
|
return toAccountAddress(row);
|
|
167
195
|
}
|
|
168
196
|
catch (err) {
|
|
197
|
+
const refused = selfServiceRefusal(err);
|
|
198
|
+
if (refused) {
|
|
199
|
+
throw refused;
|
|
200
|
+
}
|
|
169
201
|
if (err instanceof RevenexxException && (err.code === 400 || err.code === 422)) {
|
|
170
202
|
throw createError({ statusCode: 422, message: err.message });
|
|
171
203
|
}
|
|
@@ -176,6 +208,7 @@ export class ApiAddressBookService implements IAddressBookService {
|
|
|
176
208
|
|
|
177
209
|
async update(event: H3Event, id: string, input: AccountAddressFormState): Promise<AccountAddress> {
|
|
178
210
|
this.requireContact(event);
|
|
211
|
+
await this.requireOwnAddress(event, id);
|
|
179
212
|
try {
|
|
180
213
|
const row = await useRevenexxSdk().customersOrganizations.customersAddressesUpdate({
|
|
181
214
|
id,
|
|
@@ -191,6 +224,10 @@ export class ApiAddressBookService implements IAddressBookService {
|
|
|
191
224
|
return toAccountAddress(row);
|
|
192
225
|
}
|
|
193
226
|
catch (err) {
|
|
227
|
+
const refused = selfServiceRefusal(err);
|
|
228
|
+
if (refused) {
|
|
229
|
+
throw refused;
|
|
230
|
+
}
|
|
194
231
|
if (err instanceof RevenexxException && (err.code === 400 || err.code === 422)) {
|
|
195
232
|
throw createError({ statusCode: 422, message: err.message });
|
|
196
233
|
}
|
|
@@ -201,10 +238,15 @@ export class ApiAddressBookService implements IAddressBookService {
|
|
|
201
238
|
|
|
202
239
|
async remove(event: H3Event, id: string): Promise<AccountAddress[]> {
|
|
203
240
|
this.requireContact(event);
|
|
241
|
+
await this.requireOwnAddress(event, id);
|
|
204
242
|
try {
|
|
205
243
|
await useRevenexxSdk().customersOrganizations.customersAddressesDelete({ id });
|
|
206
244
|
}
|
|
207
245
|
catch (err) {
|
|
246
|
+
const refused = selfServiceRefusal(err);
|
|
247
|
+
if (refused) {
|
|
248
|
+
throw refused;
|
|
249
|
+
}
|
|
208
250
|
getLogService().error("API request failed: addresses/delete", apiErrorContext(err));
|
|
209
251
|
throw createError({ statusCode: 502, statusMessage: "Address service unavailable" });
|
|
210
252
|
}
|
|
@@ -2,6 +2,8 @@ import type { H3Event } from "h3";
|
|
|
2
2
|
|
|
3
3
|
import type { AuthRole, AuthUser, StoredSession } from "../../app/interfaces/auth";
|
|
4
4
|
import type { AuthLoginResult, IAuthService } from "../interfaces/auth";
|
|
5
|
+
import type { CustomersPermissionAnswer } from "../utils/buyerIdentity";
|
|
6
|
+
import { forgetVerifiedBuyer, grantsFrom, rememberVerifiedBuyer } from "../utils/buyerIdentity";
|
|
5
7
|
|
|
6
8
|
/** Session payload of the customers app's auth passthrough. */
|
|
7
9
|
interface ApiSession {
|
|
@@ -19,6 +21,48 @@ interface ApiContact {
|
|
|
19
21
|
last_name?: string | null;
|
|
20
22
|
role?: string | null;
|
|
21
23
|
organization_id?: string | null;
|
|
24
|
+
/**
|
|
25
|
+
* Legacy: a contact row carries `status`, not `active` — the may-act flag is
|
|
26
|
+
* on the permission answer beside it (see grantsFrom). Read as a fallback.
|
|
27
|
+
*/
|
|
28
|
+
active?: boolean | null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** What auth/me answers. */
|
|
32
|
+
interface ApiMeAnswer {
|
|
33
|
+
user: { $id: string; name?: string; email: string };
|
|
34
|
+
contact: ApiContact | null;
|
|
35
|
+
permissions?: CustomersPermissionAnswer | null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** The verified identity of one request, resolved at most once per request. */
|
|
39
|
+
const ME_KEY = "coverApiAuthMe";
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* A short cross-request memory of verified answers, keyed by tenant + user +
|
|
43
|
+
* session. A signed-in page fans out into a handful of BFF calls, and each of
|
|
44
|
+
* them now needs the verified buyer; without this every one of them would
|
|
45
|
+
* ask auth/me again within the same second. Only answers the identity service
|
|
46
|
+
* GAVE are kept, so a key a browser forges finds nothing it did not already
|
|
47
|
+
* prove — and a block or a revoked session is seen within the TTL.
|
|
48
|
+
*/
|
|
49
|
+
const VERIFIED_TTL_MS = 10_000;
|
|
50
|
+
const VERIFIED_MAX = 1000;
|
|
51
|
+
const verified = new Map<string, { user: AuthUser; until: number }>();
|
|
52
|
+
|
|
53
|
+
function rememberAcrossRequests(key: string, user: AuthUser): void {
|
|
54
|
+
if (verified.size >= VERIFIED_MAX) {
|
|
55
|
+
const oldest = verified.keys().next().value;
|
|
56
|
+
if (oldest !== undefined) {
|
|
57
|
+
verified.delete(oldest);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
verified.set(key, { user, until: Date.now() + VERIFIED_TTL_MS });
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Test seam: forget every remembered answer. */
|
|
64
|
+
export function clearVerifiedSessions(): void {
|
|
65
|
+
verified.clear();
|
|
22
66
|
}
|
|
23
67
|
|
|
24
68
|
const KNOWN_ROLES = new Set<AuthRole>(["buyer", "approver", "admin", "requester"]);
|
|
@@ -44,17 +88,18 @@ function contactName(contact: ApiContact | null, fallback: string): string {
|
|
|
44
88
|
*/
|
|
45
89
|
export class ApiAuthService implements IAuthService {
|
|
46
90
|
async login(event: H3Event, email: string, password: string): Promise<AuthLoginResult> {
|
|
47
|
-
const { session, contact } = await useRevenexxSdk().customers.customersAuthLogin({ email, password }) as unknown as {
|
|
91
|
+
const { session, contact, permissions } = await useRevenexxSdk().customers.customersAuthLogin({ email, password }) as unknown as {
|
|
48
92
|
session: ApiSession;
|
|
49
93
|
contact: ApiContact | null;
|
|
94
|
+
permissions?: CustomersPermissionAnswer | null;
|
|
50
95
|
};
|
|
51
96
|
|
|
97
|
+
// The cookie points at the platform session and nothing else: the
|
|
98
|
+
// contact and organization are re-resolved per request (RAD-155).
|
|
52
99
|
const storedSession: StoredSession = {
|
|
53
100
|
id: session.$id,
|
|
54
101
|
expire: session.expire,
|
|
55
102
|
userId: session.userId,
|
|
56
|
-
...(contact?.id ? { contactId: contact.id } : {}),
|
|
57
|
-
...(contact?.organization_id ? { organizationId: contact.organization_id } : {}),
|
|
58
103
|
};
|
|
59
104
|
setCookie(event, SESSION_COOKIE_NAME, JSON.stringify(storedSession), sessionCookieOptions(session.expire));
|
|
60
105
|
|
|
@@ -64,13 +109,35 @@ export class ApiAuthService implements IAuthService {
|
|
|
64
109
|
name: contactName(contact, email),
|
|
65
110
|
email: contact?.email ?? email,
|
|
66
111
|
role: toAuthRole(contact?.role),
|
|
112
|
+
...(contact?.id ? { contactId: contact.id } : {}),
|
|
113
|
+
...(contact?.organization_id ? { organizationId: contact.organization_id } : {}),
|
|
114
|
+
...grantsFrom(permissions, contact),
|
|
67
115
|
},
|
|
68
116
|
session: { id: session.$id, expire: session.expire },
|
|
69
117
|
...(contact?.id ? { contactId: contact.id } : {}),
|
|
70
118
|
};
|
|
71
119
|
}
|
|
72
120
|
|
|
121
|
+
/**
|
|
122
|
+
* The verified buyer of this request. Resolved at most once per request and
|
|
123
|
+
* remembered on the event (rememberVerifiedBuyer), which is also what puts
|
|
124
|
+
* the contact on every later SDK call as its principal.
|
|
125
|
+
*/
|
|
73
126
|
async me(event: H3Event): Promise<AuthUser | null> {
|
|
127
|
+
const context = event.context as Record<string, unknown>;
|
|
128
|
+
const pending = context[ME_KEY] as Promise<AuthUser | null> | undefined;
|
|
129
|
+
if (pending) {
|
|
130
|
+
return pending;
|
|
131
|
+
}
|
|
132
|
+
const resolving = this.resolve(event).then((user) => {
|
|
133
|
+
rememberVerifiedBuyer(event, user);
|
|
134
|
+
return user;
|
|
135
|
+
});
|
|
136
|
+
context[ME_KEY] = resolving;
|
|
137
|
+
return resolving;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
private async resolve(event: H3Event): Promise<AuthUser | null> {
|
|
74
141
|
const raw = getCookie(event, SESSION_COOKIE_NAME);
|
|
75
142
|
if (!raw) {
|
|
76
143
|
return null;
|
|
@@ -86,11 +153,21 @@ export class ApiAuthService implements IAuthService {
|
|
|
86
153
|
return null;
|
|
87
154
|
}
|
|
88
155
|
|
|
89
|
-
|
|
156
|
+
// Both halves are required: auth/me is asked whether THIS session is
|
|
157
|
+
// that user's live one, which is what makes the answer proof rather
|
|
158
|
+
// than an echo of whatever user id the browser wrote.
|
|
159
|
+
if (!parsed || typeof parsed.userId !== "string" || !parsed.userId || typeof parsed.id !== "string" || !parsed.id) {
|
|
90
160
|
deleteCookie(event, SESSION_COOKIE_NAME, sessionCookieOptions());
|
|
91
161
|
return null;
|
|
92
162
|
}
|
|
93
163
|
|
|
164
|
+
const cacheKey = `${revenexxTenantKey()}\u0000${parsed.userId}\u0000${parsed.id}`;
|
|
165
|
+
const remembered = verified.get(cacheKey);
|
|
166
|
+
if (remembered && remembered.until > Date.now()) {
|
|
167
|
+
return remembered.user;
|
|
168
|
+
}
|
|
169
|
+
verified.delete(cacheKey);
|
|
170
|
+
|
|
94
171
|
// Validate the session against the customers app, retrying transient
|
|
95
172
|
// failures. A 401 is the only proof the session is gone (revoked/expired)
|
|
96
173
|
// → clear the cookie + log out. Anything else (5xx "capability dispatch
|
|
@@ -107,23 +184,34 @@ export class ApiAuthService implements IAuthService {
|
|
|
107
184
|
// alive — a logged-out/revoked session answers 401 here. Raw call:
|
|
108
185
|
// the AuthMeRequest contract does not declare session_id yet, so
|
|
109
186
|
// the generated customersAuthMe() would drop the session check.
|
|
110
|
-
const { user, contact } = await useRevenexxSdk().call<
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
187
|
+
const { user, contact, permissions } = await useRevenexxSdk().call<ApiMeAnswer>(
|
|
188
|
+
"POST",
|
|
189
|
+
"/v1/customers/auth/me",
|
|
190
|
+
{ body: { user_id: parsed.userId, session_id: parsed.id } },
|
|
191
|
+
);
|
|
114
192
|
|
|
115
|
-
|
|
193
|
+
const resolved: AuthUser = {
|
|
116
194
|
$id: user.$id,
|
|
117
195
|
name: contactName(contact, user.name ?? user.email),
|
|
118
196
|
email: user.email,
|
|
119
197
|
role: toAuthRole(contact?.role),
|
|
120
198
|
...(contact?.id ? { contactId: contact.id } : {}),
|
|
121
199
|
...(contact?.organization_id ? { organizationId: contact.organization_id } : {}),
|
|
200
|
+
// `active` only when the app actually said: undefined means
|
|
201
|
+
// nobody asked, and reading that as blocked would lock out
|
|
202
|
+
// every session whose cookie predates this.
|
|
203
|
+
...grantsFrom(permissions, contact),
|
|
122
204
|
};
|
|
205
|
+
rememberAcrossRequests(cacheKey, resolved);
|
|
206
|
+
return resolved;
|
|
123
207
|
}
|
|
124
208
|
catch (err) {
|
|
125
209
|
lastErr = err;
|
|
126
|
-
|
|
210
|
+
// 401: the session is gone. A blocked contact or organization
|
|
211
|
+
// refused outright (customers >= 1.1.0) is signed out as well.
|
|
212
|
+
// Any other 403 is this shop's credentials, not the buyer's
|
|
213
|
+
// session, and must not sign everybody out.
|
|
214
|
+
if (err instanceof RevenexxException && (err.code === 401 || signInRefusalType(err) !== null)) {
|
|
127
215
|
deleteCookie(event, SESSION_COOKIE_NAME, sessionCookieOptions());
|
|
128
216
|
return null;
|
|
129
217
|
}
|
|
@@ -142,6 +230,7 @@ export class ApiAuthService implements IAuthService {
|
|
|
142
230
|
try {
|
|
143
231
|
const parsed = JSON.parse(raw) as StoredSession;
|
|
144
232
|
if (parsed.userId && parsed.id) {
|
|
233
|
+
verified.delete(`${revenexxTenantKey()}\u0000${parsed.userId}\u0000${parsed.id}`);
|
|
145
234
|
await useRevenexxSdk().customers.customersAuthLogout({
|
|
146
235
|
userId: parsed.userId,
|
|
147
236
|
sessionId: parsed.id,
|
|
@@ -154,5 +243,7 @@ export class ApiAuthService implements IAuthService {
|
|
|
154
243
|
}
|
|
155
244
|
}
|
|
156
245
|
deleteCookie(event, SESSION_COOKIE_NAME, sessionCookieOptions());
|
|
246
|
+
forgetVerifiedBuyer(event);
|
|
247
|
+
delete (event.context as Record<string, unknown>)[ME_KEY];
|
|
157
248
|
}
|
|
158
249
|
}
|
|
@@ -3,7 +3,6 @@ import type { Models } from "@revenexx/sdk";
|
|
|
3
3
|
import type { H3Event } from "h3";
|
|
4
4
|
|
|
5
5
|
import type { CartItem } from "../../app/interfaces/cart-item";
|
|
6
|
-
import type { StoredSession } from "../../app/interfaces/auth";
|
|
7
6
|
import type { CartSummaryRow, ICartManager, ICartService } from "../interfaces/cart";
|
|
8
7
|
|
|
9
8
|
/** Cart row of the carts app. */
|
|
@@ -47,15 +46,9 @@ const DEFAULT_CART_NAME = "Mein Warenkorb";
|
|
|
47
46
|
|
|
48
47
|
/** The request's cart owner: the logged-in contact, else the guest session. */
|
|
49
48
|
function resolveOwner(event: H3Event): CartOwner {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
try {
|
|
54
|
-
const parsed = JSON.parse(raw) as StoredSession;
|
|
55
|
-
contactId = parsed.contactId ?? null;
|
|
56
|
-
}
|
|
57
|
-
catch { /* guest */ }
|
|
58
|
-
}
|
|
49
|
+
// The VERIFIED contact (RAD-155) — a contact id read from the cookie would
|
|
50
|
+
// open any buyer's cart to whoever wrote it there.
|
|
51
|
+
const contactId = sessionOrderRefs(event).contact_id ?? null;
|
|
59
52
|
return { contactId, sessionKey: getOrCreateCartSessionId(event) };
|
|
60
53
|
}
|
|
61
54
|
|
|
@@ -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
|
+
}
|
|
@@ -23,8 +23,9 @@ function toAccountOrganization(row: ApiOrgRow): AccountOrganization {
|
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* Live company data: the signed-in contact's organization in the customers
|
|
26
|
-
* app. The organization
|
|
27
|
-
*
|
|
26
|
+
* app. The organization is the one the identity service verified for this
|
|
27
|
+
* request (RAD-155) — never an id the browser supplied; contacts without an
|
|
28
|
+
* organization (private buyers) have none.
|
|
28
29
|
*/
|
|
29
30
|
export class ApiOrganizationService implements IOrganizationService {
|
|
30
31
|
async get(event: H3Event): Promise<AccountOrganization | null> {
|
|
@@ -58,6 +59,10 @@ export class ApiOrganizationService implements IOrganizationService {
|
|
|
58
59
|
return toAccountOrganization(row);
|
|
59
60
|
}
|
|
60
61
|
catch (err) {
|
|
62
|
+
const refused = selfServiceRefusal(err);
|
|
63
|
+
if (refused) {
|
|
64
|
+
throw refused;
|
|
65
|
+
}
|
|
61
66
|
if (err instanceof RevenexxException && (err.code === 400 || err.code === 422)) {
|
|
62
67
|
throw createError({ statusCode: 422, message: err.message });
|
|
63
68
|
}
|
|
@@ -39,10 +39,59 @@ function toAccountTeamMember(row: ApiContactRow): AccountTeamMember {
|
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
function refusal(err: unknown, what: string): never {
|
|
43
|
+
const refused = selfServiceRefusal(err);
|
|
44
|
+
if (refused) {
|
|
45
|
+
throw refused;
|
|
46
|
+
}
|
|
47
|
+
if (err instanceof RevenexxException && (err.code === 400 || err.code === 422)) {
|
|
48
|
+
throw createError({ statusCode: 422, message: err.message });
|
|
49
|
+
}
|
|
50
|
+
getLogService().error(`API request failed: team/${what}`, apiErrorContext(err));
|
|
51
|
+
throw createError({ statusCode: 502, statusMessage: "Team service unavailable" });
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The verified buyer who may run their organization's people: signed in, in an
|
|
56
|
+
* organization, and holding `contacts.manage`. Fails closed — a live session
|
|
57
|
+
* always states its permissions, so "not stated" is not a grant here.
|
|
58
|
+
*/
|
|
59
|
+
function requireTeamManager(event: H3Event): { contactId: string; organizationId: string; role: string | undefined } {
|
|
60
|
+
const buyer = verifiedBuyer(event);
|
|
61
|
+
if (!buyer?.contactId) {
|
|
62
|
+
throw createError({ statusCode: 401, statusMessage: "Unauthorized" });
|
|
63
|
+
}
|
|
64
|
+
if (!buyer.organizationId) {
|
|
65
|
+
throw createError({ statusCode: 403, message: "Only a company account has people to manage.", data: { type: "no_organization" } });
|
|
66
|
+
}
|
|
67
|
+
if (!buyerHolds(buyer, "contacts.manage", false)) {
|
|
68
|
+
throw createError({
|
|
69
|
+
statusCode: 403,
|
|
70
|
+
message: "Your role does not allow managing your company's people.",
|
|
71
|
+
data: { type: "permission_missing", permission: "contacts.manage" },
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return { contactId: buyer.contactId, organizationId: buyer.organizationId, role: buyer.role };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function refuseRoleAbove(): never {
|
|
78
|
+
throw createError({
|
|
79
|
+
statusCode: 403,
|
|
80
|
+
message: "You cannot give anybody a role above your own.",
|
|
81
|
+
data: { type: "role_above_own" },
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
42
85
|
/**
|
|
43
86
|
* Live team data: the contacts of the signed-in contact's organization in the
|
|
44
|
-
* customers app. The organization
|
|
45
|
-
*
|
|
87
|
+
* customers app. The organization is the one the identity service verified for
|
|
88
|
+
* this request (RAD-155), never one the browser named; contacts without an
|
|
89
|
+
* organization (private buyers) get an empty list.
|
|
90
|
+
*
|
|
91
|
+
* Writes are held to three rules here, ahead of the customers app's own:
|
|
92
|
+
* the caller holds `contacts.manage`, the person changed is in the caller's
|
|
93
|
+
* organization (anybody else is not found), and nobody is given — or taken
|
|
94
|
+
* from — a role above the caller's own.
|
|
46
95
|
*/
|
|
47
96
|
export class ApiTeamService implements ITeamService {
|
|
48
97
|
async list(event: H3Event): Promise<AccountTeamMember[]> {
|
|
@@ -66,43 +115,66 @@ export class ApiTeamService implements ITeamService {
|
|
|
66
115
|
}
|
|
67
116
|
|
|
68
117
|
async invite(event: H3Event, input: AccountTeamMemberFormState): Promise<AccountTeamMember> {
|
|
69
|
-
const
|
|
70
|
-
if (!
|
|
71
|
-
|
|
118
|
+
const caller = requireTeamManager(event);
|
|
119
|
+
if (!mayGrantRole(caller.role, input.role)) {
|
|
120
|
+
refuseRoleAbove();
|
|
72
121
|
}
|
|
122
|
+
let row: ApiContactRow;
|
|
73
123
|
try {
|
|
74
|
-
|
|
124
|
+
row = await useRevenexxSdk().customersContacts.customersContactsCreate({
|
|
75
125
|
email: input.email,
|
|
76
126
|
firstName: input.firstName || undefined,
|
|
77
127
|
lastName: input.lastName || undefined,
|
|
78
128
|
role: input.role,
|
|
79
|
-
organizationId:
|
|
129
|
+
organizationId: caller.organizationId,
|
|
80
130
|
}) as unknown as ApiContactRow;
|
|
81
|
-
return toAccountTeamMember(row);
|
|
82
131
|
}
|
|
83
132
|
catch (err) {
|
|
84
|
-
|
|
85
|
-
throw createError({ statusCode: 422, message: err.message });
|
|
86
|
-
}
|
|
87
|
-
getLogService().error("API request failed: team/invite", apiErrorContext(err));
|
|
88
|
-
throw createError({ statusCode: 502, statusMessage: "Team service unavailable" });
|
|
133
|
+
refusal(err, "invite");
|
|
89
134
|
}
|
|
135
|
+
return toAccountTeamMember(row);
|
|
90
136
|
}
|
|
91
137
|
|
|
92
|
-
async update(
|
|
138
|
+
async update(event: H3Event, id: string, patch: { role: AccountTeamRole }): Promise<AccountTeamMember> {
|
|
139
|
+
const caller = requireTeamManager(event);
|
|
140
|
+
if (id === caller.contactId) {
|
|
141
|
+
throw createError({
|
|
142
|
+
statusCode: 403,
|
|
143
|
+
message: "Your own role is set by the merchant.",
|
|
144
|
+
data: { type: "own_role" },
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Whose contact is this? Anybody outside the caller's organization is
|
|
149
|
+
// answered exactly like an id that does not exist.
|
|
150
|
+
let target: ApiContactRow | null = null;
|
|
93
151
|
try {
|
|
94
|
-
|
|
152
|
+
target = await useRevenexxSdk().customersContacts.customersContactsGet({ id }) as unknown as ApiContactRow;
|
|
153
|
+
}
|
|
154
|
+
catch (err) {
|
|
155
|
+
if (!(err instanceof RevenexxException && err.code === 404)) {
|
|
156
|
+
refusal(err, "get");
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (!target || target.organization_id !== caller.organizationId) {
|
|
160
|
+
throw createError({ statusCode: 404, statusMessage: "Team member not found" });
|
|
161
|
+
}
|
|
162
|
+
// Neither hand out a role above one's own, nor take one away from
|
|
163
|
+
// somebody who holds it.
|
|
164
|
+
if (!mayGrantRole(caller.role, patch.role) || roleRank(target.role) > roleRank(caller.role)) {
|
|
165
|
+
refuseRoleAbove();
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
let row: ApiContactRow;
|
|
169
|
+
try {
|
|
170
|
+
row = await useRevenexxSdk().customersContacts.customersContactsUpdate({
|
|
95
171
|
id,
|
|
96
172
|
role: patch.role,
|
|
97
173
|
}) as unknown as ApiContactRow;
|
|
98
|
-
return toAccountTeamMember(row);
|
|
99
174
|
}
|
|
100
175
|
catch (err) {
|
|
101
|
-
|
|
102
|
-
throw createError({ statusCode: 422, message: err.message });
|
|
103
|
-
}
|
|
104
|
-
getLogService().error("API request failed: team/update", apiErrorContext(err));
|
|
105
|
-
throw createError({ statusCode: 502, statusMessage: "Team service unavailable" });
|
|
176
|
+
refusal(err, "update");
|
|
106
177
|
}
|
|
178
|
+
return toAccountTeamMember(row);
|
|
107
179
|
}
|
|
108
180
|
}
|
|
@@ -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
|
}
|