@revenexx/cover 0.3.1 → 0.4.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/components/account/dashboard/AccountDashboard.vue +8 -2
- package/app/components/layout/footer/Footer.vue +15 -3
- package/app/config/navigation.ts +21 -5
- package/app/layouts/focus.vue +5 -1
- package/package.json +1 -1
- package/server/interfaces/costCenters.ts +33 -0
- package/server/services/ApiCostCenterService.ts +54 -0
- package/server/services/MockB2BContextService.ts +27 -8
- package/server/services/MockCostCenterService.ts +40 -0
- package/server/utils/b2bService.ts +2 -2
- package/server/utils/costCenterService.ts +28 -0
|
@@ -6,7 +6,13 @@
|
|
|
6
6
|
*
|
|
7
7
|
* Composed from per-section widget components so the same sections can be
|
|
8
8
|
* rearranged as individual blocks in the page editor (see cover-theme).
|
|
9
|
+
*
|
|
10
|
+
* The two governance widgets follow the organisation's settings. They used to
|
|
11
|
+
* render for every shop, each with a "view all" link into a route only a shop
|
|
12
|
+
* with governance has — so a storefront without it put two dead links on the
|
|
13
|
+
* first page a buyer sees after signing in (RX-791's sibling).
|
|
9
14
|
*/
|
|
15
|
+
const { settings } = useB2BContext();
|
|
10
16
|
</script>
|
|
11
17
|
|
|
12
18
|
<template>
|
|
@@ -19,10 +25,10 @@
|
|
|
19
25
|
<div class="grid grid-cols-1 lg:grid-cols-3 gap-6 items-start">
|
|
20
26
|
<div class="lg:col-span-2 space-y-6">
|
|
21
27
|
<AccountDashboardRecentOrders />
|
|
22
|
-
<AccountDashboardRequisitions />
|
|
28
|
+
<AccountDashboardRequisitions v-if="settings?.approvals?.enabled" />
|
|
23
29
|
</div>
|
|
24
30
|
<div class="space-y-6">
|
|
25
|
-
<AccountDashboardBudgets />
|
|
31
|
+
<AccountDashboardBudgets v-if="settings?.costCenters?.enabled" />
|
|
26
32
|
<AccountDashboardQuickActions />
|
|
27
33
|
</div>
|
|
28
34
|
</div>
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import {
|
|
2
|
+
import type { ShopContact } from "../../../config/navigation";
|
|
3
|
+
import { footerLinks as defaultFooterLinks, legalLinks as defaultLegalLinks, shopContact as noContact } from "../../../config/navigation";
|
|
3
4
|
|
|
4
5
|
// Consumers replace the footer columns / legal links, in priority order:
|
|
5
6
|
// per-request live menus (useState, e.g. the Blokkli theme from the pages app)
|
|
@@ -15,6 +16,9 @@ const liveFooterLinks = useState<{ heading: string; links: { label: string; to:
|
|
|
15
16
|
const liveLegalLinks = useState<{ label: string; to: string }[] | null>("cover:nav:legalLinks", () => null);
|
|
16
17
|
const footerLinks = computed(() => liveFooterLinks.value ?? (appConfig.footerLinks as typeof defaultFooterLinks | undefined) ?? defaultFooterLinks);
|
|
17
18
|
const legalLinks = computed(() => liveLegalLinks.value ?? (appConfig.legalLinks as typeof defaultLegalLinks | undefined) ?? defaultLegalLinks);
|
|
19
|
+
// The shop's own contact details. The design system holds none, so a storefront
|
|
20
|
+
// that states nothing prints nothing rather than somebody else's address.
|
|
21
|
+
const shopContact = computed<ShopContact>(() => (appConfig.shopContact as ShopContact | undefined) ?? noContact);
|
|
18
22
|
|
|
19
23
|
const { icon } = useIcons();
|
|
20
24
|
const localePath = useLocalePath();
|
|
@@ -34,8 +38,14 @@ const year = new Date().getFullYear();
|
|
|
34
38
|
<p class="text-sm/6 text-muted dark:text-white/90">
|
|
35
39
|
{{ t('footer.tagline') }}
|
|
36
40
|
</p>
|
|
37
|
-
<address
|
|
38
|
-
|
|
41
|
+
<address
|
|
42
|
+
v-if="shopContact.address || shopContact.phone || shopContact.email"
|
|
43
|
+
class="not-italic flex flex-col gap-2.5 text-sm"
|
|
44
|
+
>
|
|
45
|
+
<span
|
|
46
|
+
v-if="shopContact.address"
|
|
47
|
+
class="flex items-start gap-2"
|
|
48
|
+
>
|
|
39
49
|
<UIcon
|
|
40
50
|
:name="icon('location')"
|
|
41
51
|
class="size-4 mt-0.5 shrink-0 text-(--ui-primary)"
|
|
@@ -43,6 +53,7 @@ const year = new Date().getFullYear();
|
|
|
43
53
|
<span class="text-muted dark:text-white/90">{{ shopContact.address }}</span>
|
|
44
54
|
</span>
|
|
45
55
|
<a
|
|
56
|
+
v-if="shopContact.phone"
|
|
46
57
|
:href="`tel:${shopContact.phone.replace(/\s/g, '')}`"
|
|
47
58
|
class="flex items-center gap-2 text-sm text-muted dark:text-white/90
|
|
48
59
|
hover:text-default dark:hover:text-white transition-colors"
|
|
@@ -54,6 +65,7 @@ const year = new Date().getFullYear();
|
|
|
54
65
|
{{ shopContact.phone }}
|
|
55
66
|
</a>
|
|
56
67
|
<a
|
|
68
|
+
v-if="shopContact.email"
|
|
57
69
|
:href="`mailto:${shopContact.email}`"
|
|
58
70
|
class="flex items-center gap-2 text-sm text-muted dark:text-white/90
|
|
59
71
|
hover:text-default dark:hover:text-white transition-colors"
|
package/app/config/navigation.ts
CHANGED
|
@@ -47,11 +47,27 @@ export const legalLinks = [
|
|
|
47
47
|
{ label: "Cookie Policy", to: "/legal/cookies" },
|
|
48
48
|
];
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
/**
|
|
51
|
+
* A storefront's own contact details, as the footer and the focus layout print
|
|
52
|
+
* them. Every field is optional and the design system supplies NONE of them:
|
|
53
|
+
* this is a fact about the shop, not about the design system, and a default
|
|
54
|
+
* here is printed by every storefront that never overrode it (RX-789 — the
|
|
55
|
+
* default used to be an invented San Francisco address, and it stood under a
|
|
56
|
+
* German shop for months).
|
|
57
|
+
*
|
|
58
|
+
* A storefront states what it has, in `app.config.ts`:
|
|
59
|
+
*
|
|
60
|
+
* shopContact: { address: "…", phone: "…", email: "…" }
|
|
61
|
+
*
|
|
62
|
+
* What it does not state is not printed.
|
|
63
|
+
*/
|
|
64
|
+
export interface ShopContact {
|
|
65
|
+
address?: string;
|
|
66
|
+
phone?: string;
|
|
67
|
+
email?: string;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export const shopContact: ShopContact = {};
|
|
55
71
|
|
|
56
72
|
/* ------------------------------------------------------------------ */
|
|
57
73
|
/* Storefront chrome — structure adopted from the relation prototype */
|
package/app/layouts/focus.vue
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import {
|
|
2
|
+
import type { ShopContact } from "../config/navigation";
|
|
3
|
+
import { legalLinks as defaultLegalLinks, shopContact as noContact } from "../config/navigation";
|
|
3
4
|
|
|
4
5
|
// Distraction-free layout for conversion-critical pages — authentication
|
|
5
6
|
// (login, register, recovery) and the checkout funnel. No shop chrome:
|
|
6
7
|
// logo + back link on top, the page content, and a slim footer with the
|
|
7
8
|
// essential links (contact + legal).
|
|
8
9
|
const appConfig = useAppConfig();
|
|
10
|
+
// The shop's own support address, stated by the storefront or not at all.
|
|
11
|
+
const shopContact = computed<ShopContact>(() => (appConfig.shopContact as ShopContact | undefined) ?? noContact);
|
|
9
12
|
const legalLinks = computed(() => (appConfig.legalLinks as typeof defaultLegalLinks | undefined) ?? defaultLegalLinks);
|
|
10
13
|
const { t } = useI18n();
|
|
11
14
|
const localePath = useLocalePath();
|
|
@@ -59,6 +62,7 @@ const tinted = computed(() => /\/checkout(\/|$)/.test(route.path));
|
|
|
59
62
|
aria-label="Legal"
|
|
60
63
|
>
|
|
61
64
|
<a
|
|
65
|
+
v-if="shopContact.email"
|
|
62
66
|
:href="`mailto:${shopContact.email}`"
|
|
63
67
|
class="text-xs text-dimmed hover:text-default transition-colors"
|
|
64
68
|
>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@revenexx/cover",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Cover \u2014 revenexx design system for Nuxt. Distributed as a Nuxt layer: generic UI components, theming tokens and stores shared by the demo shop, custom storefronts and the Blokkli theme.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./nuxt.config.ts",
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { H3Event } from "h3";
|
|
2
|
+
|
|
3
|
+
import type { CostCenter } from "../../app/interfaces/b2b";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Where a buyer's cost centres come from.
|
|
7
|
+
*
|
|
8
|
+
* A cost centre is the account a line is booked against, and which ones a
|
|
9
|
+
* buyer may book to is a fact about the organisation, not about the shop. The
|
|
10
|
+
* demo implementation composes them from the bundled organisation and the
|
|
11
|
+
* records the account area created; the live one reads the cost-centers app.
|
|
12
|
+
*
|
|
13
|
+
* Kept apart from the rest of the B2B context on purpose: the context also
|
|
14
|
+
* carries approval limits and workflows, which no app answers yet. A single
|
|
15
|
+
* "live context" would have to invent those, and inventing is what the
|
|
16
|
+
* registry key exists to avoid — a domain goes live when its app does, and
|
|
17
|
+
* not before.
|
|
18
|
+
*/
|
|
19
|
+
export interface ICostCenterService {
|
|
20
|
+
/**
|
|
21
|
+
* The cost centres this buyer may book to, in the order they should be
|
|
22
|
+
* offered. An empty list means the buyer books to none, which is a valid
|
|
23
|
+
* answer and not an error.
|
|
24
|
+
*/
|
|
25
|
+
list(event: H3Event | undefined, buyer: CostCenterBuyer): Promise<CostCenter[]>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Who is asking — the shop knows the buyer, the app knows their organisation. */
|
|
29
|
+
export interface CostCenterBuyer {
|
|
30
|
+
readonly userId: string | null;
|
|
31
|
+
readonly contactId?: string | null;
|
|
32
|
+
readonly organizationId?: string | null;
|
|
33
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { CostCenter } from "../../app/interfaces/b2b";
|
|
2
|
+
import type { CostCenterBuyer, ICostCenterService } from "../interfaces/costCenters";
|
|
3
|
+
|
|
4
|
+
/** One cost centre as the cost-centers app answers it. */
|
|
5
|
+
interface ApiCostCenterRow {
|
|
6
|
+
id: string;
|
|
7
|
+
code: string;
|
|
8
|
+
name: string;
|
|
9
|
+
organization_id?: string | null;
|
|
10
|
+
active?: boolean;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** How many a buyer's organisation can plausibly keep. */
|
|
14
|
+
const PAGE_LIMIT = 200;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The cost centres a buyer's organisation keeps, from the cost-centers app.
|
|
18
|
+
*
|
|
19
|
+
* Scoped by organisation, which is how the app itself answers: asked which
|
|
20
|
+
* centres are usable while naming an organisation, it offers that
|
|
21
|
+
* organisation's and no others. A buyer with no organisation gets none rather
|
|
22
|
+
* than the tenant's whole list — a cost centre is somebody's, and showing one
|
|
23
|
+
* company's booking accounts to another is the failure this scoping prevents.
|
|
24
|
+
*/
|
|
25
|
+
export class ApiCostCenterService implements ICostCenterService {
|
|
26
|
+
async list(_event: unknown, buyer: CostCenterBuyer): Promise<CostCenter[]> {
|
|
27
|
+
if (!buyer.organizationId) {
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
// The escape hatch, not a typed method: `cost_centers.cost_centers.list`
|
|
33
|
+
// declares limit/offset/order and a punchout account code, but not the
|
|
34
|
+
// organisation the record carries — the app filters on it, the contract
|
|
35
|
+
// does not declare it. It moves to the typed call when it does.
|
|
36
|
+
const { items } = await useRevenexxSdk().call<{ items: ApiCostCenterRow[] }>(
|
|
37
|
+
"GET",
|
|
38
|
+
"/v1/cost-centers/cost-centers",
|
|
39
|
+
{ query: { organization_id: buyer.organizationId, limit: PAGE_LIMIT, order: "code.asc" } },
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
return (items ?? [])
|
|
43
|
+
.filter(row => row.active !== false)
|
|
44
|
+
.map(row => ({ id: row.id, code: row.code, label: row.name }));
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
// A buyer who cannot be told their cost centres must not be told a
|
|
48
|
+
// wrong set either: an unreachable app answers none, and the surfaces
|
|
49
|
+
// that offer a choice fall back to offering none.
|
|
50
|
+
getLogService().error("API request failed: cost-centers/list", apiErrorContext(err));
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { H3Event } from "h3";
|
|
1
2
|
import type { B2BContext, B2BRole, ApprovalLimit, ApprovalWorkflow, CostCenter, OrganizationSettings, Requisition } from "../../app/interfaces/b2b";
|
|
2
3
|
import type { AuthRole } from "../../app/interfaces/auth";
|
|
3
4
|
|
|
@@ -27,8 +28,22 @@ const GUEST_ROLE = null;
|
|
|
27
28
|
* workflows. An override for the organization settings can be injected per
|
|
28
29
|
* request (demo shop dev panel) via the constructor.
|
|
29
30
|
*/
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
/**
|
|
32
|
+
* The buyer's B2B context: their role, the organisation's settings, the cost
|
|
33
|
+
* centres they may book to, the approval limits that apply and the workflows
|
|
34
|
+
* they can be sent through.
|
|
35
|
+
*
|
|
36
|
+
* Only ONE of those has a live source today. Cost centres come from the
|
|
37
|
+
* `costCenterService` registry key, which is the cost-centers app when a
|
|
38
|
+
* storefront sets it; the rest is the demo organisation, because no app
|
|
39
|
+
* answers approval limits or workflows yet. That split is deliberate and
|
|
40
|
+
* visible here rather than hidden behind a class named for one of the two.
|
|
41
|
+
*/
|
|
42
|
+
export class B2BContextService implements IB2BContextService {
|
|
43
|
+
constructor(
|
|
44
|
+
private readonly settingsOverride?: Partial<OrganizationSettings>,
|
|
45
|
+
private readonly event?: H3Event,
|
|
46
|
+
) {}
|
|
32
47
|
|
|
33
48
|
async getContext(userId: string | null, fallbackRole?: B2BRole | null): Promise<B2BContext> {
|
|
34
49
|
const org = await readCoverConfigJson<OrganizationConfig>("account/organization.json");
|
|
@@ -57,13 +72,17 @@ export class MockB2BContextService implements IB2BContextService {
|
|
|
57
72
|
...overrides.workflows,
|
|
58
73
|
];
|
|
59
74
|
|
|
60
|
-
//
|
|
61
|
-
//
|
|
75
|
+
// Whose cost centres these are is the cost-centre source's question, not
|
|
76
|
+
// this one's: the demo composes them from the bundled organisation, the
|
|
77
|
+
// live one reads the buyer's organisation out of the cost-centers app.
|
|
78
|
+
// A shop that does not book to cost centres asks neither.
|
|
79
|
+
const refs = this.event ? sessionOrderRefs(this.event) : undefined;
|
|
62
80
|
const costCenters = settings.costCenters.enabled
|
|
63
|
-
?
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
81
|
+
? await getCostCenterService(this.event).list(this.event, {
|
|
82
|
+
userId,
|
|
83
|
+
contactId: refs?.contact_id ?? null,
|
|
84
|
+
organizationId: refs?.organization_id ?? null,
|
|
85
|
+
})
|
|
67
86
|
: [];
|
|
68
87
|
|
|
69
88
|
// Approval limits only apply when actually ordering — requesters never
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { CostCenter } from "../../app/interfaces/b2b";
|
|
2
|
+
import type { CostCenterBuyer, ICostCenterService } from "../interfaces/costCenters";
|
|
3
|
+
|
|
4
|
+
interface OrganizationConfig {
|
|
5
|
+
costCenters: CostCenter[];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
interface PersonaConfig {
|
|
9
|
+
id: string;
|
|
10
|
+
costCenterIds?: string[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The demo tenant's cost centres: the bundled organisation's, narrowed to the
|
|
15
|
+
* ones the signed-in persona is assigned, plus whatever the account area
|
|
16
|
+
* created, with patches overlaid.
|
|
17
|
+
*
|
|
18
|
+
* This is the composition the B2B context used to carry itself; it moved here
|
|
19
|
+
* when the domain got a registry key, so the demo and the live source answer
|
|
20
|
+
* the same question through the same seam.
|
|
21
|
+
*/
|
|
22
|
+
export class MockCostCenterService implements ICostCenterService {
|
|
23
|
+
async list(_event: unknown, buyer: CostCenterBuyer): Promise<CostCenter[]> {
|
|
24
|
+
if (!buyer.userId) {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const org = await readCoverConfigJson<OrganizationConfig>("account/organization.json");
|
|
29
|
+
const personas = await readCoverConfigJson<PersonaConfig[]>("account/personas.json");
|
|
30
|
+
const persona = personas.find(p => p.id === buyer.userId);
|
|
31
|
+
const overrides = await readGovernanceOverrides();
|
|
32
|
+
|
|
33
|
+
// Account-created cost centres belong to the whole organisation;
|
|
34
|
+
// bundled ones follow the persona assignment. Patches overlay both.
|
|
35
|
+
return [
|
|
36
|
+
...org.costCenters.filter(cc => (persona?.costCenterIds ?? []).includes(cc.id)),
|
|
37
|
+
...overrides.costCenters,
|
|
38
|
+
].map(cc => ({ ...cc, ...overrides.costCenterPatches[cc.id] }));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -4,7 +4,7 @@ import type { OrganizationSettings } from "../../app/interfaces/b2b";
|
|
|
4
4
|
|
|
5
5
|
import type { IB2BContextService, IRequisitionService } from "../interfaces/b2bContext";
|
|
6
6
|
import type { ICartCalculationService } from "../interfaces/cartCalculation";
|
|
7
|
-
import {
|
|
7
|
+
import { B2BContextService, MockRequisitionService } from "../services/MockB2BContextService";
|
|
8
8
|
import { MockCartCalculationService } from "../services/MockCartCalculationService";
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -51,7 +51,7 @@ export function resolveOrgSettingsOverride(event?: H3Event): Partial<Organizatio
|
|
|
51
51
|
export function getB2BContextService(event?: H3Event): IB2BContextService {
|
|
52
52
|
// Per-request instantiation: the service carries the request's settings
|
|
53
53
|
// override; the underlying data reads are cached by Nitro's storage.
|
|
54
|
-
return new
|
|
54
|
+
return new B2BContextService(resolveOrgSettingsOverride(event), event);
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
const requisitionService: IRequisitionService = new MockRequisitionService();
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { H3Event } from "h3";
|
|
2
|
+
|
|
3
|
+
import type { ICostCenterService } from "../interfaces/costCenters";
|
|
4
|
+
import { ApiCostCenterService } from "../services/ApiCostCenterService";
|
|
5
|
+
import { MockCostCenterService } from "../services/MockCostCenterService";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Registry of cost-centre sources:
|
|
9
|
+
* - "mock" — the bundled demo organisation and what the account area created
|
|
10
|
+
* - "api" — the cost-centers app through the public revenexx API
|
|
11
|
+
*
|
|
12
|
+
* The rest of the B2B context — approval limits and workflows — stays on the
|
|
13
|
+
* demo data whichever key is set, because no app answers those yet. A domain
|
|
14
|
+
* goes live when its app does.
|
|
15
|
+
*/
|
|
16
|
+
const serviceRegistry: Record<string, ICostCenterService> = {
|
|
17
|
+
mock: new MockCostCenterService(),
|
|
18
|
+
api: new ApiCostCenterService(),
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export function getCostCenterService(event?: H3Event): ICostCenterService {
|
|
22
|
+
const key = resolveServiceKey(event, {
|
|
23
|
+
domain: "costCenterService",
|
|
24
|
+
mockKey: "mock",
|
|
25
|
+
liveKey: "api",
|
|
26
|
+
});
|
|
27
|
+
return serviceRegistry[key] ?? serviceRegistry["mock"]!;
|
|
28
|
+
}
|