basklee-nuxt 0.9.8 → 0.9.10

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/README.md CHANGED
@@ -515,6 +515,7 @@ fields. Empty values fall back to page-specific Russian, Spanish or English copy
515
515
  route data. The homepage retains additional backend Open Graph and Twitter tags
516
516
  through `useHead()`. Profile and logout pages remain excluded from indexing;
517
517
  search results retain their `noindex, follow` policy.
518
+ A product page takes the product's SEO tab: its heading is the page title (the product name without one), its meta description and keywords fill their tags, and its own Open Graph and Twitter Cards tags are added in the page's language only, replacing a default tag of the same name.
518
519
  Pages with a canonical address also link the same page in the other storefront languages (`hreflang`) and set `og:type` and `og:locale`; a journal article adds its publication date (`article:published_time`) and schema.org `BlogPosting` data. The store icon (`logos.ico`) is the page's `<link rel="icon">`. An unknown `?locale` opens the default language.
519
520
 
520
521
  List pages (journal, categories, stores) link their previous and next pages as real links (`?page=2`). Each later page has its own canonical address and a title with its page number; a journal page past the last one answers 404.
@@ -724,9 +725,11 @@ HTTP `401` means the request has no signed-in session. When it arrives while
724
725
  `store.isAuthenticated` is `true`, the client calls the store's `endSession()`
725
726
  once: the profile, wallet, authenticated discovery, cart/wishlist counters and
726
727
  account values of known products are removed at once, then Application Load
727
- reloads for the guest session. The failed request is not repeated and no
728
- sign-in dialog opens; a guest `401`, `403`, CSRF rejection or network failure
729
- stays an ordinary request error.
728
+ reloads for the guest session. Every `401` (also a guest's) then opens
729
+ `/profile?locale=<locale>&redirect=<current page>`, which returns to the page
730
+ after sign-in; on `/profile` and `/logout` the page stays. The failed request
731
+ is not repeated; a `403`, CSRF rejection or network failure stays an ordinary
732
+ request error.
730
733
 
731
734
  See the [cookie lifecycle and browser example](https://docs.basklee.com/en/sandbox/appload/nuxt#session-cookies)
732
735
  for exact source references and a copyable component.
@@ -1099,7 +1102,9 @@ heart, an availability notification, Checkout in the cart, a plan's Subscribe
1099
1102
  or Try, an event) opens `/profile?locale=<locale>&redirect=<current page>` at
1100
1103
  once through `useBaskleeSignIn().requireSignIn()` in
1101
1104
  `app/composables/useBaskleeSignIn.ts`, with no separate sign-in notice.
1102
- Background requests and an ended session never navigate.
1105
+ A request that answers HTTP 401 opens the same address: the shared API client
1106
+ ends a signed-in session first (the guest storefront shows at once), and the
1107
+ sign-in page returns to the page afterwards; `/profile` and `/logout` stay put.
1103
1108
  Account pages (`/orders`, `/wallet`, `/addresses`, `/subscriptions`, `/tickets`,
1104
1109
  `/activity`, `/wishlist`) declare the `basklee-account` route middleware in
1105
1110
  `app/middleware/basklee-account.ts`: after Application Load confirms a guest
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "basklee-nuxt",
3
- "version": "0.9.8",
3
+ "version": "0.9.10",
4
4
  "description": "Nuxt 4 storefront for your Basklee marketplace: setup CLI, server API gateway, typed store and ready-made catalog, cart, checkout and account components in English, Russian and Spanish, plus an Android app build. Powered by Basklee: https://basklee.com",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -93,7 +93,9 @@ heart, an availability notification, Checkout in the cart, a plan's Subscribe
93
93
  or Try, an event) opens \`/profile?locale=<locale>&redirect=<current page>\` at
94
94
  once through \`useBaskleeSignIn().requireSignIn()\` in
95
95
  \`app/composables/useBaskleeSignIn.ts\`, with no separate sign-in notice.
96
- Background requests and an ended session never navigate.
96
+ A request that answers HTTP 401 opens the same address: the shared API client
97
+ ends a signed-in session first (the guest storefront shows at once), and the
98
+ sign-in page returns to the page afterwards; \`/profile\` and \`/logout\` stay put.
97
99
  Account pages (\`/orders\`, \`/wallet\`, \`/addresses\`, \`/subscriptions\`, \`/tickets\`,
98
100
  \`/activity\`, \`/wishlist\`) declare the \`basklee-account\` route middleware in
99
101
  \`app/middleware/basklee-account.ts\`: after Application Load confirms a guest
@@ -409,9 +411,11 @@ HTTP \`401\` means the request has no signed-in session. When it arrives while
409
411
  \`store.isAuthenticated\` is \`true\`, the client calls the store's \`endSession()\`
410
412
  once: the profile, wallet, authenticated discovery, cart/wishlist counters and
411
413
  account values of known products are removed at once, then Application Load
412
- reloads for the guest session. The failed request is not repeated and no
413
- sign-in dialog opens; a guest \`401\`, \`403\`, CSRF rejection or network failure
414
- stays an ordinary request error.
414
+ reloads for the guest session. Every \`401\` (also a guest's) then opens
415
+ \`/profile?locale=<locale>&redirect=<current page>\`, which returns to the page
416
+ after sign-in; on \`/profile\` and \`/logout\` the page stays. The failed request
417
+ is not repeated; a \`403\`, CSRF rejection or network failure stays an ordinary
418
+ request error.
415
419
 
416
420
  [Cookie lifecycle and browser request example](https://docs.basklee.com/en/sandbox/appload/nuxt#session-cookies)
417
421
 
@@ -14,7 +14,7 @@ This is the only navigation on an account page: the components rendered in the s
14
14
 
15
15
  The component never renders a sign-in form. Account pages declare the `basklee-account` route middleware (`app/middleware/basklee-account.ts`); after Application Load confirms a guest session, it replaces the page with `/profile?locale=<locale>&redirect=<current page>`. The sign-in form on `/profile` returns to that page after the refreshed Application Load confirms the session. A pending or failed Application Load does not redirect.
16
16
 
17
- If the session ends while an account page is open, for example when a request answers HTTP 401, the component shows a short message that the section needs sign-in instead of the section content, and the page does not navigate on its own; the header shows Login. The shared API client removes the signed-in data from the store at once and reloads Application Load for the guest session; no dialog opens. After a failed Application Load it shows an error with Retry, which repeats Application Load.
17
+ If the session ends while an account page is open, for example when a request answers HTTP 401, the component shows a short message that the section needs sign-in instead of the section content, and the header shows Login. The shared API client removes the signed-in data from the store at once, reloads Application Load for the guest session and opens `/profile?locale=<locale>&redirect=<current page>`, which returns to the page after sign-in. After a failed Application Load it shows an error with Retry, which repeats Application Load.
18
18
 
19
19
  The guide describes its inputs and events. Source is maintained in
20
20
  `app/components/basklee/account/AccountSection.vue`; it has no separate interface file.
@@ -20,9 +20,9 @@
20
20
  const sections = computed(() => Object.entries(labels.value.navigation));
21
21
 
22
22
  // The basklee-account middleware opens /profile before a guest reaches
23
- // this page. When the session ends while the page is open, the page stays
24
- // and explains that the account content needs sign-in; it never navigates
25
- // on its own, and the header offers Login. A failed Application Load is
23
+ // this page. When the session ends while the page is open, the section
24
+ // explains that the account content needs sign-in while the shared API
25
+ // client opens the sign-in page, which returns here afterwards. A failed Application Load is
26
26
  // not a guest session: it offers Retry instead.
27
27
  </script>
28
28
 
@@ -32,6 +32,8 @@ The manufacturer card shows the logo from `manufacture.small_image`, or `manufac
32
32
 
33
33
  The seller card shows `seller.avatar`, `seller.name` and a positive `seller.raiting`. Its link points to `/sellers?seller=` with `seller.id`; selecting it emits `seller`, and the supplied page opens that address. The card is hidden when `init.visual_settings.single_seller_mode` is on.
34
34
 
35
+ Under the reviews, a row of other products, “You may also like”: the products attached to this product on the panel's Relevant Products tab (`related.data` of the returned product, without the product itself, up to eight), in their order. Only a product without attached products shows up to eight more products of its `main_category` (with its public subcategories), asked from `products_search`, and a link to that category's page. Without attached products and without other products of the category the row is not shown; a failed category request leaves it off the page. The row's cards use the same purchase, wishlist, availability and preorder actions as the product; selecting a card opens that product's page. The logic is in `app/composables/useBaskleeRelatedProducts.ts` and `app/utils/basklee/relatedProducts.ts`.
36
+
35
37
  After client-side navigation, until the product arrives, the component shows a placeholder with the page layout: gallery frame, thumbnails, name, price, description, characteristics, variants and button. The page keeps its height, the section has `aria-busy` and a hidden status announces loading. A failed request replaces the placeholder with the error notice and Retry.
36
38
 
37
39
  When the selected product endpoint succeeds but returns no product with this ID, the server render of the supplied page answers HTTP 404; after client-side navigation the component emits `missing` and shows the unavailable state. `products_search` returns an empty list both for an unknown ID and for a product that is not published. A failed request, including an invalid preview key, is not a missing product: the error notice keeps Retry. The supplied `app/pages/product/[id].vue` opens the storefront 404 page on `missing` through `useBaskleeMissingPage()`.
@@ -8,6 +8,7 @@
8
8
  watch,
9
9
  } from 'vue';
10
10
  import { NuxtLink } from '#components';
11
+ import { navigateTo } from '#imports';
11
12
  import { useBaskleeStore } from '@/stores/basklee';
12
13
  import { useBaskleeProductsStore } from '@/stores/baskleeProducts';
13
14
  import { useBaskleeCatalogStore } from '@/stores/baskleeCatalog';
@@ -18,6 +19,8 @@
18
19
  } from '@/composables/useBaskleeFeature';
19
20
  import { useBaskleeProductActions } from '@/composables/useBaskleeProductActions';
20
21
  import { useBaskleeProductVariants } from '@/composables/useBaskleeProductVariants';
22
+ import { useBaskleeRelatedProducts } from '@/composables/useBaskleeRelatedProducts';
23
+ import { relatedProductsLabels } from '@/utils/basklee/relatedProducts';
21
24
  import { reviewLabels } from '@/utils/basklee/reviewLabels';
22
25
  import { featureLabels } from '@/utils/basklee/featureLabels';
23
26
  import { productLabels } from '@/utils/basklee/productLabels';
@@ -54,6 +57,7 @@
54
57
  IProductSpecificationRow,
55
58
  } from '@/interfaces/basklee/products/IProductSpecification';
56
59
  import ProductCard from '@/components/basklee/products/ProductCard.vue';
60
+ import ProductGroup from '@/components/basklee/products/ProductGroup.vue';
57
61
  import ProductReviews from '@/components/basklee/products/ProductReviews.vue';
58
62
  import ProductPreorderDialog from '@/components/basklee/products/ProductPreorderDialog.vue';
59
63
  import ProductSpecificationsDialog from '@/components/basklee/products/ProductSpecificationsDialog.vue';
@@ -697,6 +701,18 @@
697
701
  currentId.value = selection.variant.product.id;
698
702
  image.value = 0;
699
703
  }
704
+ // The row under the product: the products attached on the panel's
705
+ // «Relevant Products» tab first, else more of the product's category.
706
+ const related = useBaskleeRelatedProducts({ api, product });
707
+ const relatedLabels = computed(() =>
708
+ relatedProductsLabels(selectionStore.localeCode),
709
+ );
710
+ function openRelated(item: IProduct) {
711
+ void navigateTo({
712
+ path: `/product/${item.id}`,
713
+ query: { locale: selectionStore.localeCode },
714
+ });
715
+ }
700
716
  onMounted(() => {
701
717
  mounted.value = true;
702
718
  if (!confirmed.value) {
@@ -1334,6 +1350,43 @@
1334
1350
  :product-id="currentId"
1335
1351
  />
1336
1352
  </div>
1353
+ <section
1354
+ v-if="related.productIds.value.length"
1355
+ class="mt-14 pt-10 border-0 border-t border-solid border-basklee-border @min-[592px]/product:mt-20"
1356
+ :aria-label="relatedLabels.title"
1357
+ data-product-related
1358
+ >
1359
+ <header class="mb-6 flex flex-wrap items-baseline justify-between gap-x-6 gap-y-2">
1360
+ <h2 class="m-0 text-xl font-semibold text-basklee-text">
1361
+ {{ relatedLabels.title }}
1362
+ </h2>
1363
+ <NuxtLink
1364
+ v-if="related.categoryId.value"
1365
+ :to="{
1366
+ path: `/category/${related.categoryId.value}`,
1367
+ query: { locale: selectionStore.localeCode },
1368
+ }"
1369
+ class="text-sm text-basklee-text underline underline-offset-4"
1370
+ data-product-related-category
1371
+ >
1372
+ {{ relatedLabels.category }}
1373
+ </NuxtLink>
1374
+ </header>
1375
+ <ProductGroup
1376
+ :product-ids="related.productIds.value"
1377
+ :disabled="actions.pending.value || actions.needsRefresh.value"
1378
+ @select="openRelated"
1379
+ @select-seller="emit('seller', $event)"
1380
+ @select-variant="variants.select"
1381
+ @request-secondary-variants="variants.requestSecondary"
1382
+ @toggle-favorite="actions.run('toggleFavorite', $event)"
1383
+ @add="actions.run('add', $event)"
1384
+ @remove="actions.run('remove', $event)"
1385
+ @subscribe="actions.run('subscribe', $event)"
1386
+ @unsubscribe="actions.run('unsubscribe', $event)"
1387
+ @preorder="actions.openPreorder"
1388
+ />
1389
+ </section>
1337
1390
  <ProductPreorderDialog
1338
1391
  :product-id="actions.preorder.value"
1339
1392
  :pending="actions.pending.value"
@@ -25,7 +25,8 @@ After confirmed authentication changes, refresh Application Load to replace the
25
25
  session, profile, wallet and live endpoint discovery. When a request answers
26
26
  HTTP 401 during a signed-in session, the shared API client removes the profile
27
27
  and wallet from the store at once and reloads Application Load for the guest
28
- session; the button shows Login again and no dialog opens.
28
+ session; the button shows Login again, and the sign-in page opens with the
29
+ current page as its return address.
29
30
 
30
31
  The authenticated name comes from `store.profile`; missing names use Profile.
31
32
  The wallet reads only the selected currency's backend-converted amount. Zero
@@ -1,4 +1,5 @@
1
1
  import {
2
+ navigateTo,
2
3
  useNuxtApp,
3
4
  usePinia,
4
5
  useRequestFetch,
@@ -10,6 +11,7 @@ import { useBaskleeStore } from '@/stores/basklee';
10
11
  import { useBaskleeSelectionsStore } from '@/stores/baskleeSelections';
11
12
  import { useBaskleeAppLoad } from '@/composables/useBaskleeAppLoad';
12
13
  import { BaskleeApi } from '@/utils/basklee/api';
14
+ import { signInPageLocation } from '@/utils/basklee/signInReturn';
13
15
  import type {
14
16
  BaskleeApiRequest,
15
17
  BaskleeApiResponse,
@@ -149,10 +151,18 @@ function createClients(): BaskleeClients {
149
151
  browser: new BaskleeApi({
150
152
  ...shared,
151
153
  canRequest: () => import.meta.client,
152
- // HTTP 401 ended the customer's session: show the guest storefront.
153
- // This never opens sign-in and never repeats the failed request.
154
- onSessionEnded: () =>
155
- nuxt.runWithContext(() => useBaskleeAppLoad().endSession()),
154
+ // HTTP 401: the request needs a signed-in customer. An ended session
155
+ // shows the guest storefront at once; then the sign-in page opens and
156
+ // returns to this page afterwards. The failed request is not repeated.
157
+ onUnauthorized: (signedIn) =>
158
+ nuxt.runWithContext(() => {
159
+ const ending = signedIn
160
+ ? useBaskleeAppLoad().endSession()
161
+ : undefined;
162
+ openSignInAfterUnauthorized(nuxt, store.localeCode);
163
+
164
+ return ending;
165
+ }),
156
166
  }),
157
167
  // Page data that the server render awaits; see useBaskleeServerData.
158
168
  // A failed server request leaves the page to the browser, which loads
@@ -161,6 +171,24 @@ function createClients(): BaskleeClients {
161
171
  };
162
172
  }
163
173
 
174
+ /*
175
+ * After HTTP 401 the visitor goes to the /profile sign-in page with this page
176
+ * in `redirect`, for example `/profile?locale=en&redirect=/orders?locale=en`.
177
+ * The sign-in page itself and /logout stay where they are: /profile already
178
+ * shows the form, and logging out should not ask for sign-in.
179
+ */
180
+ function openSignInAfterUnauthorized(
181
+ nuxt: ReturnType<typeof useNuxtApp>,
182
+ locale: string,
183
+ ) {
184
+ const route = nuxt.$router.currentRoute.value;
185
+ if (route.path === '/profile' || route.path === '/logout') {
186
+ return;
187
+ }
188
+
189
+ void navigateTo(signInPageLocation(route.fullPath, locale));
190
+ }
191
+
164
192
  function useBaskleeClients() {
165
193
  const nuxt = useNuxtApp();
166
194
  const existing = clients.get(nuxt);
@@ -13,6 +13,7 @@ import {
13
13
  storefrontPublicOrigin,
14
14
  } from '@/utils/basklee/pageSeo';
15
15
  import type { StorefrontSeoPage } from '@/utils/basklee/pageSeo';
16
+ import type { StorefrontSeoMeta } from '@/utils/basklee/seo';
16
17
  import { structuredDataJson } from '@/utils/basklee/productStructuredData';
17
18
 
18
19
  export function useBaskleePageSeo(
@@ -33,6 +34,12 @@ export function useBaskleePageSeo(
33
34
  * canonical address (preview, filtered, noindex) gets none.
34
35
  */
35
36
  structuredData?: (canonical: string, origin: string) => unknown;
37
+ /**
38
+ * The record's own tags (a product's Open Graph and Twitter Cards tags
39
+ * from the panel's SEO tab). They are said after the page's own tags,
40
+ * so a tag of the same name (og:title, og:description) replaces it.
41
+ */
42
+ meta?: MaybeRefOrGetter<StorefrontSeoMeta[] | undefined>;
36
43
  } = {},
37
44
  ) {
38
45
  const route = useRoute();
@@ -106,6 +113,13 @@ export function useBaskleePageSeo(
106
113
  : '',
107
114
  );
108
115
  useSeoMeta(seo);
116
+ useHead({
117
+ meta: () =>
118
+ (toValue(values.meta) ?? []).map((tag) => ({
119
+ key: 'property' in tag ? tag.property : tag.name,
120
+ ...tag,
121
+ })),
122
+ });
109
123
  useHead({
110
124
  link: () =>
111
125
  canonical.value
@@ -0,0 +1,125 @@
1
+ import { computed, onScopeDispose, ref, toValue, watch } from 'vue';
2
+ import type { MaybeRefOrGetter } from 'vue';
3
+ import { useBaskleeProductsStore } from '@/stores/baskleeProducts';
4
+ import { useBaskleeCatalogStore } from '@/stores/baskleeCatalog';
5
+ import type { BaskleeApi } from '@/utils/basklee/api';
6
+ import {
7
+ attachedRelatedProducts,
8
+ relatedCategoryId,
9
+ relatedCategoryProducts,
10
+ relatedCategoryRequest,
11
+ } from '@/utils/basklee/relatedProducts';
12
+ import type {
13
+ IProduct,
14
+ IProductSearchSeller,
15
+ } from '@/interfaces/basklee/products/IProduct';
16
+
17
+ /*
18
+ * The products of the row under a product page (utils/basklee/relatedProducts.ts):
19
+ * the products attached on the panel's «Relevant Products» tab first, else
20
+ * more of the product's main category. The products go into the product
21
+ * store, so the row's cards read them like every other card. A failed
22
+ * category request leaves the row off the page.
23
+ */
24
+ export function useBaskleeRelatedProducts(options: {
25
+ api: Pick<BaskleeApi, 'request'>;
26
+ product: MaybeRefOrGetter<IProduct | undefined>;
27
+ }) {
28
+ const productStore = useBaskleeProductsStore();
29
+ const catalogStore = useBaskleeCatalogStore();
30
+ const categoryIds = ref<number[]>([]);
31
+ const pending = ref(false);
32
+ let request: AbortController | undefined;
33
+
34
+ const attached = computed(() =>
35
+ attachedRelatedProducts(toValue(options.product)),
36
+ );
37
+ const categoryId = computed(() =>
38
+ relatedCategoryId(toValue(options.product)),
39
+ );
40
+ const productIds = computed(() =>
41
+ attached.value.length
42
+ ? attached.value.map((item) => item.id)
43
+ : categoryIds.value,
44
+ );
45
+
46
+ function cancel() {
47
+ request?.abort();
48
+ request = undefined;
49
+ pending.value = false;
50
+ }
51
+
52
+ async function loadCategory(category: number, productId: number) {
53
+ cancel();
54
+ categoryIds.value = [];
55
+ if (!category) {
56
+ return;
57
+ }
58
+ const current = new AbortController();
59
+ request = current;
60
+ pending.value = true;
61
+ try {
62
+ const data = await options.api.request<{
63
+ products?: { data?: IProduct[] };
64
+ selects?: { sellers?: IProductSearchSeller[] };
65
+ }>(
66
+ 'products_search',
67
+ relatedCategoryRequest(category, catalogStore.catalog),
68
+ current.signal,
69
+ );
70
+ if (current.signal.aborted) {
71
+ return;
72
+ }
73
+ const items = relatedCategoryProducts(data.products?.data, productId);
74
+ for (const item of items) {
75
+ productStore.setProduct(item, 'products', data.selects?.sellers ?? []);
76
+ }
77
+ categoryIds.value = items.map((item) => item.id);
78
+ } catch {
79
+ // The row stays off the page; the next visit of the page asks again.
80
+ } finally {
81
+ if (request === current) {
82
+ request = undefined;
83
+ pending.value = false;
84
+ }
85
+ }
86
+ }
87
+
88
+ watch(
89
+ attached,
90
+ (items) => {
91
+ for (const item of items) {
92
+ if (!productStore.getProduct(item.id)) {
93
+ productStore.setProduct(item, 'products');
94
+ }
95
+ }
96
+ },
97
+ { immediate: true },
98
+ );
99
+ watch(
100
+ () => [categoryId.value, toValue(options.product)?.id ?? 0] as const,
101
+ ([category, productId], previous) => {
102
+ if (
103
+ previous &&
104
+ previous[0] === category &&
105
+ previous[1] === productId
106
+ ) {
107
+ return;
108
+ }
109
+ if (import.meta.client) {
110
+ void loadCategory(category, productId);
111
+ }
112
+ },
113
+ { immediate: true },
114
+ );
115
+ onScopeDispose(cancel);
116
+
117
+ return {
118
+ productIds,
119
+ /** The category the row comes from, or 0 for attached products. */
120
+ categoryId: computed(() =>
121
+ attached.value.length ? 0 : categoryId.value,
122
+ ),
123
+ pending,
124
+ };
125
+ }
@@ -25,8 +25,8 @@ export function provideBaskleeSignIn(handler: BaskleeSignInHandler) {
25
25
  * A guest who clicks an action that needs an account (a review, a reaction,
26
26
  * a favorite, a plan subscription) goes straight to the /profile sign-in page,
27
27
  * which returns to `redirect` afterwards. Call requireSignIn() only from the
28
- * visitor's own click: background requests and an ended session never
29
- * navigate.
28
+ * visitor's own click. A request that answers HTTP 401 opens the same page
29
+ * through the shared API client (see useBaskleeApi).
30
30
  */
31
31
  export function useBaskleeSignIn() {
32
32
  const store = useBaskleeStore();
@@ -1,6 +1,13 @@
1
+ import type {
2
+ IDomainSeoOg,
3
+ IDomainSeoTwitter,
4
+ } from '@/interfaces/basklee/appBase/appLoadCommon/IAppLoadCommonSEO';
1
5
  import type { ITransformValue } from '@/interfaces/basklee/shared/ITransformValue';
2
6
 
3
7
  export interface IProduct {
8
+ /** The product's own Open Graph / Twitter Cards tags (single product only). */
9
+ og?: IDomainSeoOg[];
10
+ twitter?: IDomainSeoTwitter[];
4
11
  id: number;
5
12
  product_group_id: number;
6
13
  whishlist_id?: number | null;
@@ -3,6 +3,7 @@
3
3
  import { computed, ref, watch } from 'vue';
4
4
  import { navigateTo, useRoute } from '#imports';
5
5
  import { useBaskleePageSeo } from '@/composables/useBaskleePageSeo';
6
+ import { getProductSocialMeta } from '@/utils/basklee/seo';
6
7
  import { useBaskleeMissingPage } from '@/composables/useBaskleeMissingPage';
7
8
  import { useBaskleeServerData } from '@/composables/useBaskleeServerData';
8
9
  import { requestProductPage } from '@/utils/basklee/productPage';
@@ -94,9 +95,22 @@
94
95
  ).slice(0, 160),
95
96
  );
96
97
 
98
+ // The panel's SEO tab: its heading is the page title and its keywords the
99
+ // keywords tag; without them the product's name and the page's own words.
100
+ const productSeo = (key: 'product_title' | 'meta_keywords') =>
101
+ plainText(
102
+ getAvailableNestedValueFromObject(
103
+ product.value?.locale,
104
+ store.localeCode,
105
+ key,
106
+ ),
107
+ );
108
+
97
109
  useBaskleePageSeo('product', () => store.localeCode, {
98
- title: () => productName.value,
110
+ title: () => productSeo('product_title') || productName.value,
99
111
  description: () => productSummary.value,
112
+ keywords: () => productSeo('meta_keywords') || undefined,
113
+ meta: () => getProductSocialMeta(product.value, store.localeCode),
100
114
  image: () => image.value,
101
115
  robots: () =>
102
116
  previewKey.value ? 'noindex, nofollow' : undefined,
@@ -80,7 +80,7 @@ export class BaskleeApi {
80
80
  private canRequest: () => boolean;
81
81
  private isSignedIn: () => boolean;
82
82
  private currency: () => string | number | undefined;
83
- private onSessionEnded: (() => unknown) | undefined;
83
+ private onUnauthorized: ((signedIn: boolean) => unknown) | undefined;
84
84
 
85
85
  constructor(options: {
86
86
  transport: BaskleeTransport;
@@ -90,7 +90,7 @@ export class BaskleeApi {
90
90
  canRequest?: () => boolean;
91
91
  isSignedIn?: () => boolean;
92
92
  currency?: () => string | number | undefined;
93
- onSessionEnded?: () => unknown;
93
+ onUnauthorized?: (signedIn: boolean) => unknown;
94
94
  }) {
95
95
  this.transport = options.transport;
96
96
  this.endpoints = options.endpoints;
@@ -99,10 +99,10 @@ export class BaskleeApi {
99
99
  this.canRequest = options.canRequest ?? (() => true);
100
100
  this.isSignedIn = options.isSignedIn ?? (() => false);
101
101
  this.currency = options.currency ?? (() => undefined);
102
- this.onSessionEnded = options.onSessionEnded;
102
+ this.onUnauthorized = options.onUnauthorized;
103
103
  }
104
104
 
105
- /** The guest refresh started by the latest HTTP 401, while it runs. */
105
+ /** The handling of the latest HTTP 401 (guest refresh, sign-in), while it runs. */
106
106
  get sessionEnd() {
107
107
  return this.sessionEnding;
108
108
  }
@@ -201,7 +201,7 @@ export class BaskleeApi {
201
201
  signal?.throwIfAborted();
202
202
  }
203
203
 
204
- this.detectSessionEnd(response);
204
+ this.detectUnauthorized(response, name);
205
205
  signal?.throwIfAborted();
206
206
  return response;
207
207
  }
@@ -210,23 +210,28 @@ export class BaskleeApi {
210
210
  * The backend answers HTTP 401 when the request has no signed-in session:
211
211
  * an authentication-required endpoint without a customer ({ auth: false }),
212
212
  * or a session the backend rejected and whose cookies it deleted.
213
- * A 401 while the application still shows a customer means the session
214
- * ended. One handler call serves concurrent failures; a guest 401, 403 and
215
- * CSRF rejection are ordinary request errors.
213
+ * Every such answer goes to `onUnauthorized`, which opens sign-in. With
214
+ * `signedIn` true the application still shows a customer, so the session
215
+ * has ended and the handler first removes the account data. One handler
216
+ * call serves concurrent failures. The 401 of `profile_logout` only says
217
+ * that the session had already ended, so it is not passed on; 403 and CSRF
218
+ * rejection are ordinary request errors.
216
219
  */
217
- private detectSessionEnd(response: BaskleeApiResponse) {
220
+ private detectUnauthorized(response: BaskleeApiResponse, name = '') {
218
221
  if (
219
222
  response.status !== 401 ||
223
+ name === 'profile_logout' ||
220
224
  this.sessionEnding ||
221
- !this.onSessionEnded ||
222
- !this.isSignedIn()
225
+ !this.onUnauthorized
223
226
  ) {
224
227
  return;
225
228
  }
226
229
 
227
230
  let ending: Promise<void>;
228
231
  try {
229
- ending = Promise.resolve(this.onSessionEnded()).then(() => undefined);
232
+ ending = Promise.resolve(this.onUnauthorized(this.isSignedIn())).then(
233
+ () => undefined,
234
+ );
230
235
  } catch (error) {
231
236
  ending = Promise.reject(error);
232
237
  }
@@ -239,6 +244,7 @@ export class BaskleeApi {
239
244
  });
240
245
  }
241
246
 
247
+
242
248
  private csrfToken() {
243
249
  return this.cookies().match(/(?:^|;\s*)csrftoken=([^;]*)/)?.[1] ?? '';
244
250
  }
@@ -257,7 +263,7 @@ export class BaskleeApi {
257
263
  if (!this.renewal) {
258
264
  this.renewal = this.send('/api/csrf_renew', 'POST', {})
259
265
  .then((response) => {
260
- this.detectSessionEnd(response);
266
+ this.detectUnauthorized(response);
261
267
  this.successData(response);
262
268
  if (!this.csrfToken()) {
263
269
  throw new BaskleeApiError('failed');
@@ -0,0 +1,106 @@
1
+ import { categoryBranchIds, categoryTrail } from '@/utils/basklee/category';
2
+ import type { ICategory } from '@/interfaces/basklee/category/ICategory';
3
+ import type { IProduct } from '@/interfaces/basklee/products/IProduct';
4
+
5
+ /*
6
+ * The row of other products under a product page.
7
+ *
8
+ * The products the seller attached to this product on the panel's «Relevant
9
+ * Products» tab come first: they arrive with the product (`related.data`),
10
+ * so they need no request. Only a product without them shows more products
11
+ * of its own main category, asked from `products_search` the way the
12
+ * category page asks (the category with its subcategories), one more than
13
+ * shown because the product itself may be among them.
14
+ */
15
+
16
+ /** How many products the row shows. */
17
+ export const RELATED_PRODUCTS_LIMIT = 8;
18
+
19
+ /** The attached products of `product`, without the product itself. */
20
+ export function attachedRelatedProducts(
21
+ product: IProduct | undefined,
22
+ limit = RELATED_PRODUCTS_LIMIT,
23
+ ): IProduct[] {
24
+ const items = product?.related?.data;
25
+
26
+ if (!product || !Array.isArray(items)) {
27
+ return [];
28
+ }
29
+
30
+ return items
31
+ .filter(
32
+ (item) =>
33
+ Number.isInteger(item?.id) && item.id > 0 && item.id !== product.id,
34
+ )
35
+ .slice(0, limit);
36
+ }
37
+
38
+ /**
39
+ * The category whose products fill the row when nothing is attached: the
40
+ * product's main category, or 0 when the row needs none.
41
+ */
42
+ export function relatedCategoryId(product: IProduct | undefined): number {
43
+ const category = product?.main_category;
44
+
45
+ if (
46
+ !product ||
47
+ attachedRelatedProducts(product).length ||
48
+ typeof category !== 'number' ||
49
+ !Number.isInteger(category) ||
50
+ category <= 0
51
+ ) {
52
+ return 0;
53
+ }
54
+
55
+ return category;
56
+ }
57
+
58
+ /**
59
+ * The `products_search` body for that category: the category with its public
60
+ * subcategories when the catalog tree knows it, otherwise the category alone.
61
+ */
62
+ export function relatedCategoryRequest(
63
+ categoryId: number,
64
+ catalog: ICategory[],
65
+ limit = RELATED_PRODUCTS_LIMIT,
66
+ ) {
67
+ const category = categoryTrail(catalog, categoryId).at(-1);
68
+
69
+ return {
70
+ filters: {
71
+ categories: category ? categoryBranchIds(category) : [categoryId],
72
+ },
73
+ paginate: { page: 1, pp_items: limit + 1 },
74
+ };
75
+ }
76
+
77
+ /** The products of the category answer that the row shows. */
78
+ export function relatedCategoryProducts(
79
+ items: IProduct[] | undefined,
80
+ productId: number,
81
+ limit = RELATED_PRODUCTS_LIMIT,
82
+ ): IProduct[] {
83
+ return (Array.isArray(items) ? items : [])
84
+ .filter((item) => Number.isInteger(item?.id) && item.id !== productId)
85
+ .slice(0, limit);
86
+ }
87
+
88
+ const RELATED_EN = {
89
+ title: 'You may also like',
90
+ category: 'All products of the category',
91
+ };
92
+ const RELATED_TITLES: Record<string, { title: string; category: string }> = {
93
+ en: RELATED_EN,
94
+ ru: { title: 'Вам может понравиться', category: 'Все товары категории' },
95
+ es: {
96
+ title: 'También te puede gustar',
97
+ category: 'Todos los productos de la categoría',
98
+ },
99
+ };
100
+
101
+ /** The row's heading and the link to its category, in the given language. */
102
+ export function relatedProductsLabels(locale: string) {
103
+ return (
104
+ RELATED_TITLES[String(locale || '').toLowerCase().slice(0, 2)] ?? RELATED_EN
105
+ );
106
+ }
@@ -1,8 +1,9 @@
1
1
  import type { IAppLoadCommonSeo } from '@/interfaces/basklee/appBase/appLoadCommon/IAppLoadCommonSEO';
2
2
  import { getAvailableNestedValueFromObject } from '@/utils/basklee/presentation';
3
3
 
4
- type SeoMeta =
4
+ export type StorefrontSeoMeta =
5
5
  { name: string; content: string } | { property: string; content: string };
6
+ type SeoMeta = StorefrontSeoMeta;
6
7
 
7
8
  export function getStorefrontSeo(
8
9
  incomingData: IAppLoadCommonSeo[],
@@ -50,3 +51,28 @@ export function getStorefrontSeo(
50
51
  }
51
52
  return { title, meta };
52
53
  }
54
+
55
+ /**
56
+ * A product's own Open Graph and Twitter Cards tags (the panel's SEO tab) for
57
+ * its page head. Only the page's own language counts: a tag written in English
58
+ * is left out of the Russian page rather than replacing its Russian title.
59
+ */
60
+ export function getProductSocialMeta(
61
+ product: Partial<Pick<IAppLoadCommonSeo, 'og' | 'twitter'>> | undefined,
62
+ locale: string,
63
+ ): StorefrontSeoMeta[] {
64
+ const meta: StorefrontSeoMeta[] = [];
65
+ for (const tag of product?.og ?? []) {
66
+ const content = tag.locale?.[locale]?.og_content_value?.trim();
67
+ if (content) {
68
+ meta.push({ property: tag.og_property_name, content });
69
+ }
70
+ }
71
+ for (const tag of product?.twitter ?? []) {
72
+ const content = tag.locale?.[locale]?.extra_meta_content?.trim();
73
+ if (content) {
74
+ meta.push({ name: tag.extra_meta_name, content });
75
+ }
76
+ }
77
+ return meta;
78
+ }
@@ -1480,7 +1480,9 @@ heart, an availability notification, Checkout in the cart, a plan's Subscribe
1480
1480
  or Try, an event) opens `/profile?locale=<locale>&redirect=<current page>` at
1481
1481
  once through `useBaskleeSignIn().requireSignIn()` in
1482
1482
  `app/composables/useBaskleeSignIn.ts`, with no separate sign-in notice.
1483
- Background requests and an ended session never navigate.
1483
+ A request that answers HTTP 401 opens the same address: the shared API client
1484
+ ends a signed-in session first (the guest storefront shows at once), and the
1485
+ sign-in page returns to the page afterwards; `/profile` and `/logout` stay put.
1484
1486
  Account pages (`/orders`, `/wallet`, `/addresses`, `/subscriptions`, `/tickets`,
1485
1487
  `/activity`, `/wishlist`) declare the `basklee-account` route middleware in
1486
1488
  `app/middleware/basklee-account.ts`: after Application Load confirms a guest