@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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AccountAddressListResponse } from "../../../../app/interfaces/account/address-list";
|
|
2
2
|
|
|
3
3
|
export default defineEventHandler(async (event): Promise<AccountAddressListResponse> => {
|
|
4
|
-
assertMasterDataEditable("addresses");
|
|
4
|
+
await assertMasterDataEditable(event, "addresses");
|
|
5
5
|
const id = getRouterParam(event, "id");
|
|
6
6
|
if (!id) {
|
|
7
7
|
throw createError({ statusCode: 400, statusMessage: "Missing address id" });
|
|
@@ -26,7 +26,7 @@ function requireString(value: unknown, field: string): string {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
export default defineEventHandler(async (event): Promise<AccountAddress> => {
|
|
29
|
-
assertMasterDataEditable("addresses");
|
|
29
|
+
await assertMasterDataEditable(event, "addresses");
|
|
30
30
|
const id = getRouterParam(event, "id");
|
|
31
31
|
if (!id) {
|
|
32
32
|
throw createError({ statusCode: 400, statusMessage: "Missing address id" });
|
|
@@ -4,7 +4,7 @@ import type {
|
|
|
4
4
|
} from "../../../../app/interfaces/account/address-list";
|
|
5
5
|
|
|
6
6
|
export default defineEventHandler(async (event): Promise<AccountAddress> => {
|
|
7
|
-
assertMasterDataEditable("addresses");
|
|
7
|
+
await assertMasterDataEditable(event, "addresses");
|
|
8
8
|
const body = await readBody<AccountAddressFormState>(event);
|
|
9
9
|
|
|
10
10
|
const required = [
|
|
@@ -1,11 +1,45 @@
|
|
|
1
1
|
import type { OrderList } from "../../../../app/interfaces/account/order-lists";
|
|
2
2
|
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Single order list (own or organization-public), with each position told
|
|
5
|
+
* against the catalogue.
|
|
6
|
+
*
|
|
7
|
+
* A list outlives the catalogue it was written from — somebody decided once which
|
|
8
|
+
* seal fits which machine, and everybody has ordered from that decision since. So
|
|
9
|
+
* a part on it may simply be gone, and the buyer who maintains the list is the one
|
|
10
|
+
* who needs to know. Asked here rather than when the list reaches the cart,
|
|
11
|
+
* because by then it is too late to fix the list.
|
|
12
|
+
*
|
|
13
|
+
* Fails soft: an unanswerable catalogue leaves every position unmarked. Claiming a
|
|
14
|
+
* part is discontinued because a call failed would send somebody looking for a
|
|
15
|
+
* replacement they do not need.
|
|
16
|
+
*/
|
|
17
|
+
async function withAvailability(event: Parameters<typeof getOffers>[0], list: OrderList): Promise<OrderList> {
|
|
18
|
+
const positions = list.positions ?? [];
|
|
19
|
+
if (positions.length === 0) {
|
|
20
|
+
return list;
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
const offers = await getOffers(
|
|
24
|
+
event,
|
|
25
|
+
positions.map(p => ({ id: p.id, ...(p.sku ? { sku: p.sku } : {}) })),
|
|
26
|
+
);
|
|
27
|
+
return {
|
|
28
|
+
...list,
|
|
29
|
+
positions: positions.map(p => ({ ...p, available: offers.has(p.id) })),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
getLogService().error("Order list availability check failed", toErrorContext(err));
|
|
34
|
+
return list;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
4
38
|
export default defineEventHandler(async (event) => {
|
|
5
39
|
const id = getRouterParam(event, "id") ?? "";
|
|
6
40
|
|
|
7
41
|
if (resolveOrderListServiceKey(event) === "api") {
|
|
8
|
-
return await getOrderList(event, id);
|
|
42
|
+
return await withAvailability(event, await getOrderList(event, id));
|
|
9
43
|
}
|
|
10
44
|
|
|
11
45
|
const user = await getAuthService(event).me(event);
|
|
@@ -18,5 +52,5 @@ export default defineEventHandler(async (event) => {
|
|
|
18
52
|
if (!list) {
|
|
19
53
|
throw createError({ statusCode: 404, message: "List not found" });
|
|
20
54
|
}
|
|
21
|
-
return list;
|
|
55
|
+
return await withAvailability(event, list);
|
|
22
56
|
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The buyer calls an order off.
|
|
3
|
+
*
|
|
4
|
+
* Their own order only: the history is already scoped to them and this reads the
|
|
5
|
+
* same way round, so an id belonging to somebody else is a 404 rather than a
|
|
6
|
+
* refusal that confirms it exists.
|
|
7
|
+
*
|
|
8
|
+
* The reason travels where the buyer gave one, and the merchant may require it —
|
|
9
|
+
* `cancel_requires_reason` is theirs to set, and the app answers 400 without one.
|
|
10
|
+
* The shop asks for it up front instead, because a form that could have said so is
|
|
11
|
+
* better than an error that has to.
|
|
12
|
+
*/
|
|
13
|
+
export default defineEventHandler(async (event): Promise<{ ok: true }> => {
|
|
14
|
+
const number = getRouterParam(event, "id") ?? "";
|
|
15
|
+
const body = await readBody<{ reason?: string }>(event).catch(() => ({} as { reason?: string }));
|
|
16
|
+
|
|
17
|
+
const user = await getAuthService(event).me(event);
|
|
18
|
+
if (!user) {
|
|
19
|
+
throw createError({ statusCode: 401, message: "Unauthorized" });
|
|
20
|
+
}
|
|
21
|
+
if (resolveOrderServiceKey(event) !== "api") {
|
|
22
|
+
throw createError({ statusCode: 501, message: "This storefront does not cancel orders on demo data" });
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const order = await getLiveOrderByNumber(number, user.contactId);
|
|
26
|
+
if (!order) {
|
|
27
|
+
throw createError({ statusCode: 404, message: "Order not found" });
|
|
28
|
+
}
|
|
29
|
+
// The same question the history answered, asked again here: a stale page must
|
|
30
|
+
// not be able to cancel what has meanwhile shipped.
|
|
31
|
+
if (!mapLiveOrderToAccount(order).cancellable) {
|
|
32
|
+
throw createError({ statusCode: 422, message: "This order can no longer be cancelled" });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const reason = body?.reason?.trim();
|
|
36
|
+
try {
|
|
37
|
+
await useRevenexxSdk().orders.ordersCancel({
|
|
38
|
+
id: order.id,
|
|
39
|
+
...(reason ? { reason } : {}),
|
|
40
|
+
...(user.name ? { cancelledBy: user.name } : {}),
|
|
41
|
+
});
|
|
42
|
+
return { ok: true };
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
// 400 is the merchant requiring a reason the buyer did not give; 422 is the
|
|
46
|
+
// order having moved on since the page was drawn. Both are the buyer's to
|
|
47
|
+
// read, neither is an outage.
|
|
48
|
+
if (err instanceof RevenexxException && [400, 422].includes(err.code)) {
|
|
49
|
+
throw createError({ statusCode: 422, message: err.message });
|
|
50
|
+
}
|
|
51
|
+
getLogService().error(`Cancelling order ${number} failed`, apiErrorContext(err));
|
|
52
|
+
throw createError({ statusCode: 502, message: "Order service unavailable" });
|
|
53
|
+
}
|
|
54
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { AccountOrderMessage } from "../../../../../app/interfaces/account/order-list";
|
|
2
|
+
|
|
3
|
+
import { OrderCommentVisibility } from "@revenexx/sdk";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* What has been said about this order, buyer-visible only.
|
|
7
|
+
*
|
|
8
|
+
* The orders app keeps the desk's own notes in the same list and filters by
|
|
9
|
+
* visibility; asking for the customer's half is the whole of the privacy here, and
|
|
10
|
+
* it happens on this side of the wire so no internal note ever reaches a browser.
|
|
11
|
+
*/
|
|
12
|
+
interface LiveComment {
|
|
13
|
+
id: string;
|
|
14
|
+
body?: string | null;
|
|
15
|
+
author?: string | null;
|
|
16
|
+
visibility?: string | null;
|
|
17
|
+
created_at?: string | null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default defineEventHandler(async (event): Promise<{ messages: AccountOrderMessage[] }> => {
|
|
21
|
+
const number = getRouterParam(event, "id") ?? "";
|
|
22
|
+
const user = await getAuthService(event).me(event);
|
|
23
|
+
if (!user) {
|
|
24
|
+
throw createError({ statusCode: 401, message: "Unauthorized" });
|
|
25
|
+
}
|
|
26
|
+
if (resolveOrderServiceKey(event) !== "api") {
|
|
27
|
+
return { messages: [] };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const order = await getLiveOrderByNumber(number, user.contactId);
|
|
31
|
+
if (!order) {
|
|
32
|
+
throw createError({ statusCode: 404, message: "Order not found" });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
const answer = await useRevenexxSdk().orders.ordersCommentsList({
|
|
37
|
+
id: order.id,
|
|
38
|
+
visibility: OrderCommentVisibility.Customer,
|
|
39
|
+
limit: 100,
|
|
40
|
+
}) as unknown as { items?: LiveComment[]; comments?: LiveComment[] };
|
|
41
|
+
const rows = answer.items ?? answer.comments ?? [];
|
|
42
|
+
return {
|
|
43
|
+
messages: rows
|
|
44
|
+
// Belt and braces: the filter is the app's, and a note that arrived
|
|
45
|
+
// anyway must not be shown because a parameter was ignored.
|
|
46
|
+
.filter(row => (row.visibility ?? "customer") === "customer")
|
|
47
|
+
.map(row => ({
|
|
48
|
+
id: row.id,
|
|
49
|
+
body: (row.body ?? "").trim(),
|
|
50
|
+
author: row.author ?? null,
|
|
51
|
+
at: row.created_at ?? "",
|
|
52
|
+
// The buyer's own words, told apart by the author the shop sets
|
|
53
|
+
// when it writes one.
|
|
54
|
+
fromBuyer: (row.author ?? "").startsWith("buyer:"),
|
|
55
|
+
}))
|
|
56
|
+
.filter(message => message.body.length > 0),
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
getLogService().error(`Reading messages for order ${number} failed`, apiErrorContext(err));
|
|
61
|
+
throw createError({ statusCode: 502, message: "Order service unavailable" });
|
|
62
|
+
}
|
|
63
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { OrderCommentVisibility } from "@revenexx/sdk";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The buyer says something about this order.
|
|
5
|
+
*
|
|
6
|
+
* Written as customer-visible, because a buyer cannot write the desk an internal
|
|
7
|
+
* note — and marked with who they are, so the two sides of the conversation read
|
|
8
|
+
* apart on the page rather than as one voice.
|
|
9
|
+
*/
|
|
10
|
+
export default defineEventHandler(async (event): Promise<{ ok: true }> => {
|
|
11
|
+
const number = getRouterParam(event, "id") ?? "";
|
|
12
|
+
const body = await readBody<{ body?: string }>(event).catch(() => ({} as { body?: string }));
|
|
13
|
+
const message = body?.body?.trim();
|
|
14
|
+
if (!message) {
|
|
15
|
+
throw createError({ statusCode: 400, message: "body required" });
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const user = await getAuthService(event).me(event);
|
|
19
|
+
if (!user) {
|
|
20
|
+
throw createError({ statusCode: 401, message: "Unauthorized" });
|
|
21
|
+
}
|
|
22
|
+
if (resolveOrderServiceKey(event) !== "api") {
|
|
23
|
+
throw createError({ statusCode: 501, message: "This storefront does not take order messages on demo data" });
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const order = await getLiveOrderByNumber(number, user.contactId);
|
|
27
|
+
if (!order) {
|
|
28
|
+
throw createError({ statusCode: 404, message: "Order not found" });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
await useRevenexxSdk().orders.ordersCommentsCreate({
|
|
33
|
+
id: order.id,
|
|
34
|
+
body: message,
|
|
35
|
+
visibility: OrderCommentVisibility.Customer,
|
|
36
|
+
author: `buyer:${user.name || user.email}`,
|
|
37
|
+
});
|
|
38
|
+
return { ok: true };
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
getLogService().error(`Writing a message to order ${number} failed`, apiErrorContext(err));
|
|
42
|
+
throw createError({ statusCode: 502, message: "Order service unavailable" });
|
|
43
|
+
}
|
|
44
|
+
});
|
|
@@ -29,6 +29,7 @@ export default defineEventHandler(async (event): Promise<AccountOrder> => {
|
|
|
29
29
|
try {
|
|
30
30
|
const order = await requestOrderReturn(
|
|
31
31
|
id,
|
|
32
|
+
user.contactId,
|
|
32
33
|
positions.map(p => ({ orderItemId: p.orderItemId, quantity: Number(p.quantity) })),
|
|
33
34
|
body?.reason,
|
|
34
35
|
);
|
|
@@ -11,7 +11,7 @@ export default defineEventHandler(async (event) => {
|
|
|
11
11
|
|
|
12
12
|
if (resolveOrderServiceKey(event) === "api") {
|
|
13
13
|
try {
|
|
14
|
-
const order = await getLiveOrderByNumber(id);
|
|
14
|
+
const order = await getLiveOrderByNumber(id, user.contactId);
|
|
15
15
|
if (!order) {
|
|
16
16
|
throw createError({ statusCode: 404, message: "Order not found" });
|
|
17
17
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AccountOrganization, AccountOrganizationFormState } from "../../../app/interfaces/account/organization";
|
|
2
2
|
|
|
3
3
|
export default defineEventHandler(async (event): Promise<AccountOrganization> => {
|
|
4
|
-
assertMasterDataEditable("organization");
|
|
4
|
+
await assertMasterDataEditable(event, "organization");
|
|
5
5
|
const body = await readBody<AccountOrganizationFormState>(event);
|
|
6
6
|
return getOrganizationService(event).update(event, {
|
|
7
7
|
name: String(body?.name ?? "").trim(),
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { AccountPaymentsResponse } from "../../../app/interfaces/account/payments";
|
|
2
|
+
import type { LivePayment } from "../../utils/accountPayments";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The buyer's own payments: what is open, what is late, what is settled.
|
|
6
|
+
*
|
|
7
|
+
* Scoped to their contact, which is how the payments app scopes it — a buyer sees
|
|
8
|
+
* their own and nobody else's. A B2B buyer asks this because their own accounts
|
|
9
|
+
* department is asking them, and until now the answer was a telephone call.
|
|
10
|
+
*
|
|
11
|
+
* Amounts are kept apart by currency. Adding two currencies into one figure is
|
|
12
|
+
* the one thing a page about money must never do.
|
|
13
|
+
*/
|
|
14
|
+
export default defineEventHandler(async (event): Promise<AccountPaymentsResponse> => {
|
|
15
|
+
const user = await getAuthService(event).me(event);
|
|
16
|
+
if (!user) {
|
|
17
|
+
throw createError({ statusCode: 401, message: "Unauthorized" });
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const contactId = user.contactId ?? sessionOrderRefs(event)?.contact_id;
|
|
21
|
+
// No contact means no payments of one's own — an empty ledger, not an error.
|
|
22
|
+
// A demo persona is in exactly that position.
|
|
23
|
+
if (!contactId || resolvePaymentServiceKey(event) !== "api") {
|
|
24
|
+
return { payments: [], outstanding: [] };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
const answer = await useRevenexxSdk().call<{ payments?: LivePayment[]; items?: LivePayment[] }>(
|
|
29
|
+
"GET",
|
|
30
|
+
"/v1/payments",
|
|
31
|
+
{ query: { contact_id: contactId, order: "created_at.desc", limit: 100 } },
|
|
32
|
+
);
|
|
33
|
+
const payments = (answer.payments ?? answer.items ?? []).map(mapPayment);
|
|
34
|
+
|
|
35
|
+
// Per currency, and only what is still owed.
|
|
36
|
+
const byCurrency = new Map<string, number>();
|
|
37
|
+
for (const payment of payments) {
|
|
38
|
+
if (SETTLED.has(payment.state) || payment.state === "failed") {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
byCurrency.set(payment.currency, (byCurrency.get(payment.currency) ?? 0) + payment.amount);
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
payments,
|
|
45
|
+
outstanding: [...byCurrency.entries()]
|
|
46
|
+
.filter(([, amount]) => amount > 0)
|
|
47
|
+
.map(([currency, amount]) => ({ currency, amount })),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
catch (err) {
|
|
51
|
+
getLogService().error("Service error: account/payments", apiErrorContext(err));
|
|
52
|
+
throw createError({ statusCode: 502, message: "Payment service unavailable" });
|
|
53
|
+
}
|
|
54
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Say yes to one layer.
|
|
3
|
+
*
|
|
4
|
+
* One layer and not the request: approvals are stacked, so this unlocks the next
|
|
5
|
+
* and the request is approved when the last signature lands. The app owns that
|
|
6
|
+
* chain; the shop only passes the decision along.
|
|
7
|
+
*/
|
|
8
|
+
export default defineEventHandler(async (event): Promise<{ ok: true }> => {
|
|
9
|
+
return await decidePendingApproval(event, "approve");
|
|
10
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Say no.
|
|
3
|
+
*
|
|
4
|
+
* A decline ends the whole request rather than one layer — the app terminates it
|
|
5
|
+
* and gives any reserved budget back — which is why the reason matters more here
|
|
6
|
+
* than on an approval: the requester has to know whether to ask again differently.
|
|
7
|
+
*/
|
|
8
|
+
export default defineEventHandler(async (event): Promise<{ ok: true }> => {
|
|
9
|
+
return await decidePendingApproval(event, "decline");
|
|
10
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { PendingApprovalsResponse } from "../../../../app/interfaces/account/approvals";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* What is waiting on this approver.
|
|
5
|
+
*
|
|
6
|
+
* Empty where procurement is not the live source: the demo's approval limits are a
|
|
7
|
+
* different model with no queue behind them, and a made-up row here would put a
|
|
8
|
+
* decision in front of somebody that nothing would record.
|
|
9
|
+
*/
|
|
10
|
+
export default defineEventHandler(async (event): Promise<PendingApprovalsResponse> => {
|
|
11
|
+
const user = await getAuthService(event).me(event);
|
|
12
|
+
if (!user) {
|
|
13
|
+
throw createError({ statusCode: 401, message: "Unauthorized" });
|
|
14
|
+
}
|
|
15
|
+
if (!isProcurementLive(event)) {
|
|
16
|
+
return { approvals: [] };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const refs = sessionOrderRefs(event);
|
|
20
|
+
const approvals = await listPendingApprovals(event, {
|
|
21
|
+
...(user.contactId ?? refs?.contact_id ? { contactId: (user.contactId ?? refs?.contact_id) as string } : {}),
|
|
22
|
+
...(user.role ? { role: user.role } : {}),
|
|
23
|
+
...(user.organizationId ? { organizationId: user.organizationId } : {}),
|
|
24
|
+
});
|
|
25
|
+
return { approvals };
|
|
26
|
+
});
|
|
@@ -66,7 +66,9 @@ export default defineEventHandler(async (event): Promise<AccountProfileResponse>
|
|
|
66
66
|
const live = resolveServiceKey(event, { domain: "accountService", mockKey: "mock", liveKey: "api" }) === "api";
|
|
67
67
|
if (live) {
|
|
68
68
|
const [phone, organization] = await Promise.all([
|
|
69
|
-
|
|
69
|
+
// The verified contact, not the cookie's: a contact id the browser
|
|
70
|
+
// wrote would read anybody's number (RAD-155).
|
|
71
|
+
contactPhone(sessionOrderRefs(event).contact_id),
|
|
70
72
|
getOrganizationService(event).get(event).catch(() => null),
|
|
71
73
|
]);
|
|
72
74
|
return {
|
|
@@ -59,7 +59,7 @@ function validateProfileValue(value: string, maxLength: number, field: string):
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
export default defineEventHandler(async (event): Promise<AccountProfileResponse> => {
|
|
62
|
-
assertMasterDataEditable("profile");
|
|
62
|
+
await assertMasterDataEditable(event, "profile");
|
|
63
63
|
const rawSession = getCookie(event, SESSION_COOKIE_NAME);
|
|
64
64
|
if (!rawSession) {
|
|
65
65
|
throw createError({ statusCode: 401, statusMessage: "Unauthorized" });
|
|
@@ -1,19 +1,43 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/**
|
|
2
|
+
* The buyer says no.
|
|
3
|
+
*
|
|
4
|
+
* To the whole offer, which closes every position still open — or to some of the
|
|
5
|
+
* positions, leaving the rest open for a decision later. The platform takes both
|
|
6
|
+
* through the same mechanism, a decision per line, and a merchant who does not
|
|
7
|
+
* allow a basket to be taken apart gets the whole-quote refusal either way.
|
|
8
|
+
*/
|
|
2
9
|
export default defineEventHandler(async (event): Promise<{ ok: true }> => {
|
|
3
10
|
const id = getRouterParam(event, "id") ?? "";
|
|
4
|
-
const body = await readBody<{ reason?: string
|
|
11
|
+
const body = await readBody<{ reason?: string; lineIds?: string[] }>(event)
|
|
12
|
+
.catch(() => ({} as { reason?: string; lineIds?: string[] }));
|
|
5
13
|
const actor = await quoteActor(event);
|
|
6
14
|
if (!actor.user) {
|
|
7
15
|
throw createError({ statusCode: 401, message: "Unauthorized" });
|
|
8
16
|
}
|
|
17
|
+
const terms = await quoteTerms(event);
|
|
9
18
|
const quote = await loadOwnQuote(event, id, actor);
|
|
10
|
-
|
|
19
|
+
const view = mapQuote(quote, terms);
|
|
20
|
+
if (!view.canDecline) {
|
|
11
21
|
throw createError({ statusCode: 422, message: "This quote can no longer be declined" });
|
|
12
22
|
}
|
|
13
23
|
|
|
24
|
+
// Which positions the buyer refused. Only a real subset travels: refusing all
|
|
25
|
+
// of them is a refusal of the offer, and the whole-quote path says that more
|
|
26
|
+
// clearly than a list naming every line.
|
|
27
|
+
const openLineIds = new Set(view.lines.filter(line => line.decision === "open").map(line => line.id));
|
|
28
|
+
const picked = terms.partialAcceptance
|
|
29
|
+
? (body?.lineIds ?? []).filter(lineId => openLineIds.has(lineId))
|
|
30
|
+
: [];
|
|
31
|
+
const lineIds = picked.length > 0 && picked.length < openLineIds.size ? picked : undefined;
|
|
32
|
+
|
|
14
33
|
if (resolveQuotesServiceKey(event) === "api") {
|
|
15
34
|
try {
|
|
16
|
-
|
|
35
|
+
if (lineIds) {
|
|
36
|
+
await liveQuoteDeclineLines(id, lineIds);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
await liveQuoteDecline(id, body?.reason?.trim() || undefined);
|
|
40
|
+
}
|
|
17
41
|
}
|
|
18
42
|
catch (err) {
|
|
19
43
|
if (err instanceof RevenexxException && (err.code === 409 || err.code === 422)) {
|
|
@@ -31,8 +55,13 @@ export default defineEventHandler(async (event): Promise<{ ok: true }> => {
|
|
|
31
55
|
? q
|
|
32
56
|
: {
|
|
33
57
|
...q,
|
|
34
|
-
|
|
35
|
-
|
|
58
|
+
// Still open for the rest where only some were refused: a quote that
|
|
59
|
+
// read as declined while something was orderable would lose the buyer
|
|
60
|
+
// the part they still wanted.
|
|
61
|
+
status: lineIds ? "partially_accepted" : "declined",
|
|
62
|
+
items: (q.items ?? []).map(i => (i.decision === "open" && (!lineIds || lineIds.includes(i.id))
|
|
63
|
+
? { ...i, decision: "declined" }
|
|
64
|
+
: i)),
|
|
36
65
|
events: [...(q.events ?? []), { kind: "declined", actor: "buyer", body: body?.reason ?? null, visibility: "customer", created_at: now }],
|
|
37
66
|
}));
|
|
38
67
|
return { ok: true };
|
|
@@ -7,7 +7,7 @@ interface TeamUpdateBody {
|
|
|
7
7
|
const ROLES: AccountTeamRole[] = ["buyer", "approver", "admin", "requester"];
|
|
8
8
|
|
|
9
9
|
export default defineEventHandler(async (event): Promise<AccountTeamMember> => {
|
|
10
|
-
assertMasterDataEditable("team");
|
|
10
|
+
await assertMasterDataEditable(event, "team");
|
|
11
11
|
const id = getRouterParam(event, "id");
|
|
12
12
|
if (!id) {
|
|
13
13
|
throw createError({ statusCode: 400, statusMessage: "Missing member id" });
|
|
@@ -7,7 +7,7 @@ function toRole(value: unknown): AccountTeamRole {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
export default defineEventHandler(async (event): Promise<AccountTeamMember> => {
|
|
10
|
-
assertMasterDataEditable("team");
|
|
10
|
+
await assertMasterDataEditable(event, "team");
|
|
11
11
|
const body = await readBody<Partial<AccountTeamMemberFormState>>(event);
|
|
12
12
|
const email = String(body?.email ?? "").trim();
|
|
13
13
|
if (!email) {
|
|
@@ -22,6 +22,12 @@ export default defineEventHandler(async (event) => {
|
|
|
22
22
|
return result;
|
|
23
23
|
}
|
|
24
24
|
catch (err) {
|
|
25
|
+
// A blocked contact or company (customers >= 1.1.0) is told so, not
|
|
26
|
+
// shown an outage.
|
|
27
|
+
const refused = signInRefusalType(err);
|
|
28
|
+
if (refused) {
|
|
29
|
+
throw createError({ statusCode: 403, data: { type: refused } });
|
|
30
|
+
}
|
|
25
31
|
if (isApiUserError(err)) {
|
|
26
32
|
throw createError({ statusCode: err.code, data: { type: apiAuthErrorType(err) } });
|
|
27
33
|
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ask for a sign-in link.
|
|
3
|
+
*
|
|
4
|
+
* Answers the same way whether the address is known or not, on purpose: the
|
|
5
|
+
* customers app creates an account for an address it has never seen, so a
|
|
6
|
+
* distinguishing answer here would turn this form into a way of asking who has an
|
|
7
|
+
* account. The secret never reaches this response — only the mailed link carries it.
|
|
8
|
+
*/
|
|
9
|
+
export default defineEventHandler(async (event): Promise<{ sent: true }> => {
|
|
10
|
+
const body = await readBody<{ email?: string }>(event).catch(() => ({} as { email?: string }));
|
|
11
|
+
const email = body?.email?.trim();
|
|
12
|
+
if (!email) {
|
|
13
|
+
throw createError({ statusCode: 400, message: "email required" });
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const { signIn } = await getShopSettings(event);
|
|
17
|
+
if (!signIn.magicLink) {
|
|
18
|
+
throw createError({ statusCode: 404, message: "This shop does not sign buyers in with a mailed link" });
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Where the link lands. The app appends userId, secret and expire.
|
|
22
|
+
const url = new URL("/login/link", getRequestURL(event).origin).toString();
|
|
23
|
+
try {
|
|
24
|
+
await useRevenexxSdk().customers.customersAuthMagicLink({ email, url });
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
getLogService().error("Magic link request failed", apiErrorContext(err));
|
|
28
|
+
// Still "sent": a failure that named the address would leak it, and the
|
|
29
|
+
// buyer's next move is the same either way — look in their mail.
|
|
30
|
+
}
|
|
31
|
+
return { sent: true };
|
|
32
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { AuthLoginResult } from "../../interfaces/auth";
|
|
2
|
+
import type { PasswordlessConfirm } from "../../utils/passwordlessSignIn";
|
|
3
|
+
|
|
4
|
+
/** Turn a mailed link into a session — the same session a password produces. */
|
|
5
|
+
export default defineEventHandler(async (event): Promise<AuthLoginResult> => {
|
|
6
|
+
const body = await readBody<{ userId?: string; secret?: string }>(event)
|
|
7
|
+
.catch(() => ({} as { userId?: string; secret?: string }));
|
|
8
|
+
const userId = body?.userId?.trim();
|
|
9
|
+
const secret = body?.secret?.trim();
|
|
10
|
+
if (!userId || !secret) {
|
|
11
|
+
throw createError({ statusCode: 400, message: "userId and secret required" });
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
const answer = await useRevenexxSdk().customers.customersAuthMagicLinkConfirm({
|
|
16
|
+
userId,
|
|
17
|
+
secret,
|
|
18
|
+
}) as unknown as PasswordlessConfirm;
|
|
19
|
+
return completeSignIn(event, answer.session, answer.contact, "", answer.permissions);
|
|
20
|
+
}
|
|
21
|
+
catch (err) {
|
|
22
|
+
// A blocked contact or company is refused at the redeem, and told why.
|
|
23
|
+
const refused = signInRefusalType(err);
|
|
24
|
+
if (refused) {
|
|
25
|
+
throw createError({ statusCode: 403, message: "This account may not sign in", data: { type: refused } });
|
|
26
|
+
}
|
|
27
|
+
// A used or lapsed link is the ordinary case, not an outage: the buyer
|
|
28
|
+
// asks for another one.
|
|
29
|
+
if (err instanceof RevenexxException && [400, 401, 404].includes(err.code)) {
|
|
30
|
+
throw createError({ statusCode: 401, message: "This sign-in link is no longer valid" });
|
|
31
|
+
}
|
|
32
|
+
getLogService().error("Magic link confirmation failed", apiErrorContext(err));
|
|
33
|
+
throw createError({ statusCode: 502, message: "Sign-in service unavailable" });
|
|
34
|
+
}
|
|
35
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ask for a sign-in code.
|
|
3
|
+
*
|
|
4
|
+
* The answer carries the platform's user id, which the confirm call needs beside
|
|
5
|
+
* the code the buyer types. That id is not a secret — the code is, and it only
|
|
6
|
+
* ever goes to the address.
|
|
7
|
+
*
|
|
8
|
+
* An address nobody holds gets the same answer with no id, so the form looks
|
|
9
|
+
* identical either way: a code typed without one fails at the confirm step with
|
|
10
|
+
* the same message a wrong code gets. Answering differently would turn this into
|
|
11
|
+
* a way of asking who has an account.
|
|
12
|
+
*/
|
|
13
|
+
export default defineEventHandler(async (event): Promise<{ sent: true; userId?: string }> => {
|
|
14
|
+
const body = await readBody<{ email?: string }>(event).catch(() => ({} as { email?: string }));
|
|
15
|
+
const email = body?.email?.trim();
|
|
16
|
+
if (!email) {
|
|
17
|
+
throw createError({ statusCode: 400, message: "email required" });
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const { signIn } = await getShopSettings(event);
|
|
21
|
+
if (!signIn.emailOtp) {
|
|
22
|
+
throw createError({ statusCode: 404, message: "This shop does not sign buyers in with a mailed code" });
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
const answer = await useRevenexxSdk().customers.customersAuthOtp({ email }) as { userId?: string };
|
|
27
|
+
return { sent: true, ...(answer?.userId ? { userId: answer.userId } : {}) };
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
getLogService().error("Sign-in code request failed", apiErrorContext(err));
|
|
31
|
+
return { sent: true };
|
|
32
|
+
}
|
|
33
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { AuthLoginResult } from "../../interfaces/auth";
|
|
2
|
+
import type { PasswordlessConfirm } from "../../utils/passwordlessSignIn";
|
|
3
|
+
|
|
4
|
+
/** Turn a mailed code into a session. */
|
|
5
|
+
export default defineEventHandler(async (event): Promise<AuthLoginResult> => {
|
|
6
|
+
const body = await readBody<{ userId?: string; secret?: string }>(event)
|
|
7
|
+
.catch(() => ({} as { userId?: string; secret?: string }));
|
|
8
|
+
const userId = body?.userId?.trim();
|
|
9
|
+
const secret = body?.secret?.trim();
|
|
10
|
+
if (!userId || !secret) {
|
|
11
|
+
throw createError({ statusCode: 400, message: "userId and secret required" });
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
const answer = await useRevenexxSdk().customers.customersAuthOtpConfirm({
|
|
16
|
+
userId,
|
|
17
|
+
secret,
|
|
18
|
+
}) as unknown as PasswordlessConfirm;
|
|
19
|
+
return completeSignIn(event, answer.session, answer.contact, "", answer.permissions);
|
|
20
|
+
}
|
|
21
|
+
catch (err) {
|
|
22
|
+
// A blocked contact or company is refused at the redeem, and told why.
|
|
23
|
+
const refused = signInRefusalType(err);
|
|
24
|
+
if (refused) {
|
|
25
|
+
throw createError({ statusCode: 403, message: "This account may not sign in", data: { type: refused } });
|
|
26
|
+
}
|
|
27
|
+
if (err instanceof RevenexxException && [400, 401, 404].includes(err.code)) {
|
|
28
|
+
throw createError({ statusCode: 401, message: "This code is wrong or has expired" });
|
|
29
|
+
}
|
|
30
|
+
getLogService().error("Sign-in code confirmation failed", apiErrorContext(err));
|
|
31
|
+
throw createError({ statusCode: 502, message: "Sign-in service unavailable" });
|
|
32
|
+
}
|
|
33
|
+
});
|
|
@@ -7,6 +7,7 @@ export default defineEventHandler(async (event) => {
|
|
|
7
7
|
if (!id) {
|
|
8
8
|
throw createError({ statusCode: 400, message: "Cart id is required" });
|
|
9
9
|
}
|
|
10
|
+
await assertOwnCart(event, manager, id);
|
|
10
11
|
try {
|
|
11
12
|
const items = await manager.activateCart(event, id);
|
|
12
13
|
return { items };
|