@revenexx/cover 0.10.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/assets/css/cover.css +9 -0
- package/app/components/RevenexxForm.vue +4 -0
- package/app/components/account/AccountSidebar.vue +2 -5
- package/app/components/account/dashboard/AccountDashboardKpis.vue +74 -34
- package/app/components/account/dashboard/AccountDashboardQuickActions.vue +24 -6
- package/app/components/account/organization/AccountOrganization.vue +3 -1
- package/app/components/account/team/AccountTeam.vue +32 -7
- package/app/components/auth/AuthForgotPasswordPanel.vue +9 -4
- package/app/components/auth/AuthLoginPanel.vue +5 -3
- 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/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 +18 -2
- package/app/components/checkout/onepage/CheckoutGate.vue +2 -0
- 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/layout/Region.vue +13 -0
- package/app/components/layout/footer/Footer.vue +8 -0
- package/app/components/layout/header/AppBar.vue +4 -3
- package/app/components/layout/header/MainNav.vue +3 -3
- 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 +1 -1
- package/app/components/product/detail/ProductDetailSaveToList.vue +10 -0
- package/app/composables/useAccountDashboard.ts +0 -10
- package/app/composables/useAccountNavigation.ts +35 -0
- package/app/composables/useAuthStore.ts +2 -0
- package/app/composables/useCategoryListing.ts +6 -0
- package/app/composables/useCheckoutOnePage.ts +21 -2
- package/app/composables/useMasterDataEditable.ts +23 -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/quickActions.ts +40 -5
- package/app/interfaces/account/dashboard.ts +2 -0
- package/app/interfaces/auth.ts +13 -2
- package/app/interfaces/quantity-stepper.ts +17 -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/theme-events.client.ts +132 -0
- package/app/shared/themeEvents.ts +445 -0
- package/i18n/locales/de/account.json +7 -0
- package/i18n/locales/de/auth.json +1 -0
- package/i18n/locales/de/cart.json +2 -1
- package/i18n/locales/de/checkout.json +2 -1
- package/i18n/locales/de/common.json +2 -0
- package/i18n/locales/de/cover.json +44 -0
- package/i18n/locales/de/editor.json +47 -1
- package/i18n/locales/en/account.json +7 -0
- package/i18n/locales/en/auth.json +1 -0
- package/i18n/locales/en/cart.json +2 -1
- package/i18n/locales/en/checkout.json +2 -1
- package/i18n/locales/en/common.json +2 -0
- package/i18n/locales/en/cover.json +44 -0
- package/i18n/locales/en/editor.json +47 -1
- package/nuxt.config.ts +15 -1
- package/package.json +5 -2
- package/server/api/account/orders/[id]/cancel.post.ts +1 -1
- package/server/api/account/orders/[id]/messages.get.ts +1 -1
- package/server/api/account/orders/[id]/messages.post.ts +1 -1
- 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/pending-approvals/index.get.ts +1 -0
- package/server/api/account/profile.get.ts +3 -1
- package/server/api/auth/login.post.ts +6 -0
- package/server/api/auth/magic-link.put.ts +6 -1
- package/server/api/auth/otp.put.ts +6 -1
- 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/orders/index.post.ts +33 -0
- package/server/api/quick-actions.get.ts +6 -38
- 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 +98 -17
- package/server/services/ApiCartService.ts +3 -10
- package/server/services/ApiOrganizationService.ts +7 -2
- package/server/services/ApiTeamService.ts +93 -21
- package/server/utils/buyerIdentity.ts +168 -0
- package/server/utils/cartOwnership.ts +27 -0
- package/server/utils/liveOrderLists.ts +50 -23
- package/server/utils/liveOrders.ts +39 -24
- package/server/utils/livePrices.ts +7 -15
- package/server/utils/masterData.ts +29 -0
- package/server/utils/passwordlessSignIn.ts +13 -4
- package/server/utils/pendingApprovals.ts +29 -7
- package/server/utils/procurementCheckout.ts +2 -0
- package/server/utils/quickActionCatalogue.ts +53 -0
- package/server/utils/revenexxSdk.ts +116 -2
package/app/interfaces/auth.ts
CHANGED
|
@@ -27,6 +27,13 @@ export interface AuthUser {
|
|
|
27
27
|
* meant before anybody asked.
|
|
28
28
|
*/
|
|
29
29
|
active?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* What this person's role lets them do in their organization
|
|
32
|
+
* (`contacts.manage`, `addresses.manage`, …), derived by the customers app on
|
|
33
|
+
* every read. Undefined where the source does not say — the demo personas;
|
|
34
|
+
* a live session always states it, an empty list included.
|
|
35
|
+
*/
|
|
36
|
+
permissions?: string[];
|
|
30
37
|
}
|
|
31
38
|
|
|
32
39
|
/**
|
|
@@ -73,9 +80,13 @@ export interface StoredSession {
|
|
|
73
80
|
personaId?: string;
|
|
74
81
|
/** Set for public-API sessions — the platform user behind the session. */
|
|
75
82
|
userId?: string;
|
|
76
|
-
/**
|
|
83
|
+
/**
|
|
84
|
+
* Written by sessions older than RAD-155 and IGNORED on read: the browser
|
|
85
|
+
* can rewrite this cookie, so the contact and organization are taken from
|
|
86
|
+
* the identity service per request instead (server/utils/buyerIdentity).
|
|
87
|
+
*/
|
|
77
88
|
contactId?: string;
|
|
78
|
-
/**
|
|
89
|
+
/** As contactId — legacy, never trusted. */
|
|
79
90
|
organizationId?: string;
|
|
80
91
|
}
|
|
81
92
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Why a quantity stepper refused or corrected an entry. */
|
|
2
|
+
export type QuantityStepperNotice = "max" | "invalid";
|
|
3
|
+
|
|
4
|
+
export interface QuantityStepperOptions {
|
|
5
|
+
/** The committed quantity — a cart line's, or a buy box's amount to add. */
|
|
6
|
+
readonly quantity: () => number;
|
|
7
|
+
/** Ceiling for this stepper; `undefined` falls back to CART_MAX_QUANTITY. */
|
|
8
|
+
readonly max: () => number | undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Lowest value the minus button reaches. 1 by default; the mini-cart uses 0,
|
|
11
|
+
* where the store reads a zero quantity as "remove this line". Typed input
|
|
12
|
+
* below 1 always reverts — nobody removes a position by typing.
|
|
13
|
+
*/
|
|
14
|
+
readonly min?: number;
|
|
15
|
+
/** Commits a validated, clamped quantity. */
|
|
16
|
+
readonly apply: (next: number) => void;
|
|
17
|
+
}
|
package/app/layouts/default.vue
CHANGED
|
@@ -62,23 +62,32 @@ async function handleSearch(q: string): Promise<void> {
|
|
|
62
62
|
>
|
|
63
63
|
Skip to main content
|
|
64
64
|
</a>
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
<
|
|
68
|
-
<
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
65
|
+
<!-- Layout extension points (ADR-0111): the code header and footer are
|
|
66
|
+
the regions' default content; a theme may add to or replace them. -->
|
|
67
|
+
<LayoutRegion name="header">
|
|
68
|
+
<LayoutHeaderTopBar />
|
|
69
|
+
<LayoutHeaderAppBar />
|
|
70
|
+
<div class="md:hidden border-b border-(--ui-border) px-4 py-2">
|
|
71
|
+
<UiFormsSearchInput
|
|
72
|
+
class="w-full"
|
|
73
|
+
@search="handleSearch"
|
|
74
|
+
/>
|
|
75
|
+
</div>
|
|
76
|
+
<LayoutHeaderMainNav />
|
|
77
|
+
</LayoutRegion>
|
|
74
78
|
<UiDebugPiniaStateCard v-if="false" />
|
|
75
79
|
<UMain id="main-content">
|
|
76
80
|
<slot />
|
|
77
81
|
</UMain>
|
|
78
|
-
<
|
|
82
|
+
<LayoutRegion name="footer">
|
|
83
|
+
<LayoutFooter />
|
|
84
|
+
</LayoutRegion>
|
|
79
85
|
<CartDrawer v-if="!isCartOrCheckoutPage" />
|
|
80
86
|
<CartTargetModal />
|
|
81
87
|
</div>
|
|
88
|
+
<!-- The cookie choice (Consent Manager): rendered by this shop's own
|
|
89
|
+
server when one is owed, never in the editor or a preview. -->
|
|
90
|
+
<ConsentBanner />
|
|
82
91
|
</Body>
|
|
83
92
|
</Html>
|
|
84
93
|
</template>
|
package/app/layouts/focus.vue
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import type { CheckoutCustomerType } from "../composables/useCheckoutOnePage";
|
|
2
3
|
import type { ShopContact } from "../config/navigation";
|
|
3
4
|
import { legalLinks as defaultLegalLinks, shopContact as noContact } from "../config/navigation";
|
|
4
5
|
|
|
@@ -18,7 +19,18 @@ const year = new Date().getFullYear();
|
|
|
18
19
|
// Checkout gets a subtly tinted page background so the white section
|
|
19
20
|
// cards and the summary stand out from the canvas.
|
|
20
21
|
const route = useRoute();
|
|
21
|
-
const
|
|
22
|
+
const isCheckoutRoute = computed(() => /\/checkout(\/|$)/.test(route.path));
|
|
23
|
+
const customerType = useState<CheckoutCustomerType>("checkout-customer-type", () => "account");
|
|
24
|
+
const isGuestCheckout = computed(() => isCheckoutRoute.value && customerType.value !== "account");
|
|
25
|
+
const tinted = computed(() => isCheckoutRoute.value || /\/forgot-password(\/|$)/.test(route.path));
|
|
26
|
+
|
|
27
|
+
function onHeaderBackClick(event: MouseEvent): void {
|
|
28
|
+
if (!isGuestCheckout.value) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
event.preventDefault();
|
|
32
|
+
customerType.value = "account";
|
|
33
|
+
}
|
|
22
34
|
</script>
|
|
23
35
|
|
|
24
36
|
<template>
|
|
@@ -34,14 +46,15 @@ const tinted = computed(() => /\/checkout(\/|$)/.test(route.path));
|
|
|
34
46
|
<div class="w-full max-w-(--ui-container) mx-auto px-4 sm:px-6 lg:px-8 flex-1 pb-20">
|
|
35
47
|
<header class="pt-10 flex items-center">
|
|
36
48
|
<div class="flex-1">
|
|
37
|
-
<LayoutAppLogo />
|
|
49
|
+
<LayoutAppLogo class="inline-flex min-h-11 items-center" />
|
|
38
50
|
</div>
|
|
39
51
|
<NuxtLink
|
|
40
|
-
:to="localePath('/')"
|
|
52
|
+
:to="isGuestCheckout ? '#' : localePath(isCheckoutRoute ? '/cart' : '/')"
|
|
41
53
|
tabindex="0"
|
|
42
|
-
class="
|
|
54
|
+
class="inline-flex min-h-11 items-center text-sm decoration-2 underline-offset-4 hover:underline"
|
|
55
|
+
@click="onHeaderBackClick"
|
|
43
56
|
>
|
|
44
|
-
{{ t('nav.backToShop') }}
|
|
57
|
+
{{ t(isGuestCheckout ? 'onepage.gate.backToSelection' : isCheckoutRoute ? 'nav.backToCart' : 'nav.backToShop') }}
|
|
45
58
|
</NuxtLink>
|
|
46
59
|
</header>
|
|
47
60
|
<main>
|
|
@@ -64,7 +77,7 @@ const tinted = computed(() => /\/checkout(\/|$)/.test(route.path));
|
|
|
64
77
|
<a
|
|
65
78
|
v-if="shopContact.email"
|
|
66
79
|
:href="`mailto:${shopContact.email}`"
|
|
67
|
-
class="text-xs text-dimmed hover:text-default
|
|
80
|
+
class="inline-flex min-h-11 items-center text-xs text-dimmed transition-colors hover:text-default"
|
|
68
81
|
>
|
|
69
82
|
{{ shopContact.email }}
|
|
70
83
|
</a>
|
|
@@ -73,14 +86,22 @@ const tinted = computed(() => /\/checkout(\/|$)/.test(route.path));
|
|
|
73
86
|
:key="link.to"
|
|
74
87
|
:to="localePath(link.to)"
|
|
75
88
|
tabindex="0"
|
|
76
|
-
class="text-xs text-dimmed hover:text-default
|
|
89
|
+
class="inline-flex min-h-11 items-center text-xs text-dimmed transition-colors hover:text-default"
|
|
77
90
|
>
|
|
78
91
|
{{ link.label }}
|
|
79
92
|
</NuxtLink>
|
|
93
|
+
<ConsentPreferencesLink
|
|
94
|
+
class="text-xs text-dimmed hover:text-default transition-colors cursor-pointer"
|
|
95
|
+
>
|
|
96
|
+
{{ t('footer.cookieSettings') }}
|
|
97
|
+
</ConsentPreferencesLink>
|
|
80
98
|
</nav>
|
|
81
99
|
</div>
|
|
82
100
|
</footer>
|
|
83
101
|
</div>
|
|
102
|
+
<!-- The cookie choice (Consent Manager): rendered by this shop's own
|
|
103
|
+
server when one is owed, never in the editor or a preview. -->
|
|
104
|
+
<ConsentBanner />
|
|
84
105
|
</Body>
|
|
85
106
|
</Html>
|
|
86
107
|
</template>
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
export default defineNuxtRouteMiddleware(() => {
|
|
1
|
+
export default defineNuxtRouteMiddleware((to, from) => {
|
|
2
2
|
const localePath = useLocalePath();
|
|
3
3
|
|
|
4
|
+
// A new checkout started from the cart must show the account/guest choice
|
|
5
|
+
// again; the selection is intentionally kept only within the current flow.
|
|
6
|
+
if (from.path !== to.path && /\/cart(?:\/|$)/.test(from.path)) {
|
|
7
|
+
useState("checkout-customer-type", () => "account").value = "account";
|
|
8
|
+
}
|
|
9
|
+
|
|
4
10
|
// Authentication is handled on the page itself (checkout gate with
|
|
5
11
|
// login + guest ordering per organization flags) — the guard only
|
|
6
12
|
// ensures there is something to check out.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import type { PunchoutReturnPayload } from "../../interfaces/punchout";
|
|
3
|
+
import { cartEcommerce } from "../../shared/themeEvents";
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* The interstitial — the buyer is leaving.
|
|
@@ -31,6 +32,26 @@ const { t } = useI18n();
|
|
|
31
32
|
const { icon } = useIcons();
|
|
32
33
|
const { to } = useAppUrl();
|
|
33
34
|
const { protocol } = usePunchoutVisit();
|
|
35
|
+
const cart = useCartStore();
|
|
36
|
+
const themeEvents = useThemeEvents();
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* `punchout_transfer` — the cart leaves for the procurement system. Not for a
|
|
40
|
+
* replayed hand-back (the same cart answered again) nor for a back-channel
|
|
41
|
+
* visit, where the browser posts nothing; and only for the two protocols the
|
|
42
|
+
* contract names.
|
|
43
|
+
*/
|
|
44
|
+
function reportTransfer(): void {
|
|
45
|
+
const kind = protocol.value;
|
|
46
|
+
if (payload.value?.replayed || isBackChannel.value || (kind !== "oci" && kind !== "cxml") || !cart.items.length) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const ecommerce = cartEcommerce(cart.items);
|
|
50
|
+
themeEvents.emit("punchout_transfer", {
|
|
51
|
+
ecommerce: { ...ecommerce, value_net: ecommerce.value_net ?? 0, value_gross: ecommerce.value_gross ?? 0 },
|
|
52
|
+
punchout: { protocol: kind },
|
|
53
|
+
});
|
|
54
|
+
}
|
|
34
55
|
|
|
35
56
|
definePageMeta({
|
|
36
57
|
// The buyer is on their way out; this page is not part of the shop's
|
|
@@ -72,6 +93,7 @@ onMounted(async () => {
|
|
|
72
93
|
|
|
73
94
|
// One tick so the form is in the DOM, and a beat so the buyer sees where
|
|
74
95
|
// they are going rather than a flash of a page they cannot read.
|
|
96
|
+
reportTransfer();
|
|
75
97
|
await nextTick();
|
|
76
98
|
window.setTimeout(() => form.value?.submit(), 400);
|
|
77
99
|
});
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import type { AuthMethod } from "@revenexx/tag-manager-nuxt/events";
|
|
2
|
+
import type { RouteLocationNormalized } from "vue-router";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
browserSession,
|
|
6
|
+
cartEcommerce,
|
|
7
|
+
itemsValue,
|
|
8
|
+
pageTypeOf,
|
|
9
|
+
takePurchase,
|
|
10
|
+
trackCartChanges,
|
|
11
|
+
} from "../shared/themeEvents";
|
|
12
|
+
|
|
13
|
+
/** How long a cart-dependent page event waits for the cart to be restored. */
|
|
14
|
+
const CART_READY_WAIT_MS = 3000;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The theme events no single component owns (RAD-178).
|
|
18
|
+
*
|
|
19
|
+
* - `page_view`: pages are blökkli-authored, so the router is the only uniform
|
|
20
|
+
* point. Once per path — a query change (a filter, a page of results) is the
|
|
21
|
+
* same page.
|
|
22
|
+
* - `view_cart`, `begin_checkout`, `purchase`: by the page reached, so every
|
|
23
|
+
* theme on this layer reports them whichever pages it ships (the blökkli
|
|
24
|
+
* theme, the custom theme and the demo shop each have their own).
|
|
25
|
+
* - `add_to_cart` / `remove_from_cart`: read off the cart store's actions, so
|
|
26
|
+
* every add-to-cart button in the design system reports without knowing it,
|
|
27
|
+
* and only an add the store accepted counts.
|
|
28
|
+
* - `login` / `sign_up`: read off the auth store's actions, once they resolved.
|
|
29
|
+
*
|
|
30
|
+
* Editor and preview contexts emit nothing (`useThemeEvents`).
|
|
31
|
+
*/
|
|
32
|
+
export default defineNuxtPlugin({
|
|
33
|
+
name: "cover:theme-events",
|
|
34
|
+
setup(nuxtApp) {
|
|
35
|
+
const events = useThemeEvents();
|
|
36
|
+
const router = useRouter();
|
|
37
|
+
const cart = useCartStore();
|
|
38
|
+
const auth = useAuthStore();
|
|
39
|
+
|
|
40
|
+
/* ---- the cart is restored asynchronously ----------------------------- */
|
|
41
|
+
// auth-init restores the cart from the server after the session check; a
|
|
42
|
+
// cart page reached on a hard load would otherwise report an empty cart.
|
|
43
|
+
let markCartReady: () => void = () => {};
|
|
44
|
+
const cartReady = new Promise<void>((resolve) => {
|
|
45
|
+
markCartReady = resolve;
|
|
46
|
+
setTimeout(resolve, CART_READY_WAIT_MS);
|
|
47
|
+
});
|
|
48
|
+
cart.$onAction(({ name, after, onError }) => {
|
|
49
|
+
if (name === "initFromServer") {
|
|
50
|
+
after(() => markCartReady());
|
|
51
|
+
onError(() => markCartReady());
|
|
52
|
+
}
|
|
53
|
+
}, true);
|
|
54
|
+
|
|
55
|
+
/* ---- per page ------------------------------------------------------- */
|
|
56
|
+
const localeCodes = (): string[] => {
|
|
57
|
+
const locales = (nuxtApp.$i18n as { locales?: { value: ({ code: string } | string)[] } } | undefined)?.locales?.value ?? [];
|
|
58
|
+
return locales.map(l => (typeof l === "string" ? l : l.code));
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
async function pageEvents(to: RouteLocationNormalized): Promise<void> {
|
|
62
|
+
const type = pageTypeOf(to.path, localeCodes());
|
|
63
|
+
if (type === "cart") {
|
|
64
|
+
await cartReady;
|
|
65
|
+
events.emit("view_cart", { ecommerce: cartEcommerce(cart.items) });
|
|
66
|
+
}
|
|
67
|
+
else if (type === "checkout") {
|
|
68
|
+
await cartReady;
|
|
69
|
+
if (cart.items.length) {
|
|
70
|
+
events.emit("begin_checkout", { ecommerce: cartEcommerce(cart.items) });
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else if (type === "confirmation") {
|
|
74
|
+
purchase(to);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* One `purchase` per order, on the confirmation page. Not for an approval
|
|
80
|
+
* request or a requisition — nothing was bought yet. The order id IS the
|
|
81
|
+
* event id, so the emitter drops a reload of the same confirmation.
|
|
82
|
+
*/
|
|
83
|
+
function purchase(to: RouteLocationNormalized): void {
|
|
84
|
+
const id = typeof to.query.id === "string" ? to.query.id.trim() : "";
|
|
85
|
+
const kind = typeof to.query.type === "string" ? to.query.type : "order";
|
|
86
|
+
if (!id || kind !== "order") {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const placed = takePurchase(browserSession());
|
|
90
|
+
if (!placed?.items?.length) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
events.emit("purchase", { ecommerce: { ...placed, transaction_id: id.slice(0, 128) } });
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
let lastPath: string | null = null;
|
|
97
|
+
const onPage = (to: RouteLocationNormalized) => {
|
|
98
|
+
if (to.path === lastPath) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
lastPath = to.path;
|
|
102
|
+
events.emit("page_view");
|
|
103
|
+
void pageEvents(to);
|
|
104
|
+
};
|
|
105
|
+
// The first page once the app is mounted; every later one after its navigation.
|
|
106
|
+
nuxtApp.hook("app:mounted", () => onPage(router.currentRoute.value));
|
|
107
|
+
router.afterEach((to, _from, failure) => {
|
|
108
|
+
if (!failure && nuxtApp.isHydrating !== true) {
|
|
109
|
+
onPage(to);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
/* ---- cart ----------------------------------------------------------- */
|
|
114
|
+
trackCartChanges(cart, (event, items) => {
|
|
115
|
+
events.emit(event, { ecommerce: { items, ...itemsValue(items) } });
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
/* ---- signing in ----------------------------------------------------- */
|
|
119
|
+
auth.$onAction(({ name, args, after }) => {
|
|
120
|
+
if (name === "login") {
|
|
121
|
+
after(() => events.emit("login", { auth: { method: "password" } }));
|
|
122
|
+
}
|
|
123
|
+
else if (name === "confirmSignInMail") {
|
|
124
|
+
const method: AuthMethod = args[0] === "otp" ? "otp" : "magic_link";
|
|
125
|
+
after(() => events.emit("login", { auth: { method } }));
|
|
126
|
+
}
|
|
127
|
+
else if (name === "register") {
|
|
128
|
+
after(() => events.emit("sign_up", { auth: { method: "password" } }));
|
|
129
|
+
}
|
|
130
|
+
}, true);
|
|
131
|
+
},
|
|
132
|
+
});
|