@sgflabs/storefront-core 0.1.17 → 0.1.19

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.
Files changed (44) hide show
  1. package/package.json +9 -7
  2. package/src/components/cells/CartDropdown/CartDropdown.tsx +1 -1
  3. package/src/components/cells/CartItemsProducts/CartItemsProducts.tsx +4 -2
  4. package/src/components/cells/UserDropdown/UserDropdown.tsx +2 -2
  5. package/src/components/molecules/CartDropdownItem/CartDropdownItem.tsx +5 -2
  6. package/src/components/molecules/LoginReturnLink/LoginReturnLink.tsx +2 -2
  7. package/src/components/molecules/NativeSelect/NativeSelect.tsx +2 -0
  8. package/src/components/molecules/ProductImage/ProductImage.tsx +1 -1
  9. package/src/components/organisms/CartEmpty/CartEmpty.tsx +1 -1
  10. package/src/components/organisms/Header/Header.tsx +5 -1
  11. package/src/components/organisms/Header/HeaderAccountControls.tsx +6 -5
  12. package/src/components/organisms/Header/HeaderMessages.tsx +14 -0
  13. package/src/components/organisms/ListingToolbar/ListingToolbar.tsx +8 -2
  14. package/src/components/organisms/OrderItems/Item.tsx +5 -2
  15. package/src/components/organisms/ProductCard/ProductCard.tsx +8 -3
  16. package/src/components/organisms/ProductListingHeader/ProductListingHeader.tsx +7 -3
  17. package/src/components/sections/Cart/Cart.tsx +1 -0
  18. package/src/lib/data/bidding.ts +5 -1
  19. package/src/lib/data/checkout-terms.ts +8 -10
  20. package/src/lib/data/seller.ts +17 -2
  21. package/src/lib/helpers/build-product-gallery-slides.ts +25 -0
  22. package/src/lib/helpers/resolve-image-alt.ts +14 -0
  23. package/src/lib/helpers/seo.ts +140 -65
  24. package/src/lib/helpers/store-image-alt.ts +8 -0
  25. package/src/lib/seo/indexing.ts +11 -0
  26. package/src/lib/seo/locale-redirect.ts +11 -0
  27. package/src/lib/seo/seo-config.d.ts +9 -0
  28. package/src/lib/seo/seo-config.js +42 -0
  29. package/src/pages/auth/forgot-password/page.tsx +2 -0
  30. package/src/pages/auth/login/page.tsx +12 -0
  31. package/src/pages/auth/register/page.tsx +11 -0
  32. package/src/pages/invite/page.tsx +2 -2
  33. package/src/pages/main/applications/[handle]/page.tsx +2 -1
  34. package/src/pages/main/auctions/page.tsx +30 -2
  35. package/src/pages/main/best-sellers/page.tsx +2 -1
  36. package/src/pages/main/categories/[category]/page.tsx +4 -2
  37. package/src/pages/main/categories/page.tsx +2 -1
  38. package/src/pages/main/legal/[type]/page.tsx +23 -9
  39. package/src/pages/main/legal/page.tsx +16 -4
  40. package/src/pages/main/sellers/[handle]/page.tsx +23 -2
  41. package/src/pages/main/user/layout.tsx +3 -0
  42. package/src/pages/robots.ts +25 -2
  43. package/src/pages/sitemap.ts +21 -3
  44. package/src/pages/sitemap.xml/route.ts +5 -1
@@ -1,7 +1,9 @@
1
1
  import { Metadata } from "next"
2
- import Link from "next/link"
3
2
 
4
3
  import { getStoreLegal } from "../../../lib/data/legal"
4
+ import LocalizedClientLink from "../../../components/molecules/LocalizedLink/LocalizedLink"
5
+ import { getRequestBaseUrl } from "../../../lib/helpers/request-base-url"
6
+ import { generateBreadcrumbJsonLd, toSafeJsonLdString } from "../../../lib/helpers/seo"
5
7
  import { docForSlug, LEGAL_SLUG_LABELS, LEGAL_SLUGS } from "./legal-docs"
6
8
 
7
9
  export const metadata: Metadata = {
@@ -9,7 +11,13 @@ export const metadata: Metadata = {
9
11
  description: "Legal policies and information for this store",
10
12
  }
11
13
 
12
- export default async function LegalPage() {
14
+ export default async function LegalPage({ params }: { params: Promise<{ locale: string }> }) {
15
+ const { locale } = await params
16
+ const base = await getRequestBaseUrl()
17
+ const breadcrumb = generateBreadcrumbJsonLd([
18
+ { name: "Home", url: `${base}/${locale}` },
19
+ { name: "Legal Information" },
20
+ ])
13
21
  const legal = await getStoreLegal()
14
22
  const published = LEGAL_SLUGS.flatMap((slug) => {
15
23
  const doc = docForSlug(legal, slug)
@@ -18,6 +26,10 @@ export default async function LegalPage() {
18
26
 
19
27
  return (
20
28
  <main className="container py-8 md:py-12">
29
+ <script
30
+ type="application/ld+json"
31
+ dangerouslySetInnerHTML={{ __html: toSafeJsonLdString(breadcrumb) }}
32
+ />
21
33
  <div className="max-w-4xl mx-auto">
22
34
  <h1 className="heading-xl mb-4">Legal Information</h1>
23
35
  <p className="text-neutral-600 mb-8">
@@ -33,13 +45,13 @@ export default async function LegalPage() {
33
45
  <ul className="grid gap-4 md:gap-6" data-testid="legal-list">
34
46
  {published.map(({ slug, doc }) => (
35
47
  <li key={slug}>
36
- <Link
48
+ <LocalizedClientLink
37
49
  href={`/legal/${slug}`}
38
50
  className="block p-4 md:p-6 border border-neutral-200 rounded-lg hover:border-neutral-400 hover:shadow-sm transition-all"
39
51
  >
40
52
  <h2 className="heading-md mb-2">{doc.title?.trim() || LEGAL_SLUG_LABELS[slug]}</h2>
41
53
  <p className="text-neutral-600 text-sm">Version {doc.content_hash.slice(0, 12)}</p>
42
- </Link>
54
+ </LocalizedClientLink>
43
55
  </li>
44
56
  ))}
45
57
  </ul>
@@ -8,6 +8,12 @@ import { getSelectedApplicationIds } from "../../../../lib/data/application-cook
8
8
  import { parseListingControls } from "../../../../lib/helpers/parse-listing-controls"
9
9
  import { parseApplicationIds } from "../../../../lib/helpers/parse-application-ids"
10
10
  import { resolveSellerApplicationIds } from "../../../../lib/helpers/resolve-seller-application-ids"
11
+ import { getRequestBaseUrl } from "../../../../lib/helpers/request-base-url"
12
+ import {
13
+ generateBreadcrumbJsonLd,
14
+ generateOrganizationJsonLd,
15
+ toSafeJsonLdString,
16
+ } from "../../../../lib/helpers/seo"
11
17
 
12
18
  export default async function SellerPage({
13
19
  params,
@@ -73,8 +79,22 @@ export default async function SellerPage({
73
79
  const { seller, user, currency_code, productCount, certificationLabels, isCustomized } = context
74
80
  const tab = "products"
75
81
 
82
+ const base = await getRequestBaseUrl()
83
+ const sellerUrl = `${base}/${locale}/sellers/${handle}`
84
+ const structuredData = [
85
+ generateOrganizationJsonLd({ name: seller.name, url: sellerUrl, logo: seller.photo }),
86
+ generateBreadcrumbJsonLd([{ name: "Home", url: `${base}/${locale}` }, { name: seller.name }]),
87
+ ]
88
+
76
89
  return (
77
90
  <VendorThemeProvider theme={seller.theme} applyStyles={false}>
91
+ {structuredData.map((data) => (
92
+ <script
93
+ key={String(data["@type"])}
94
+ type="application/ld+json"
95
+ dangerouslySetInnerHTML={{ __html: toSafeJsonLdString(data) }}
96
+ />
97
+ ))}
78
98
  <main className="container mx-auto max-w-[1680px]">
79
99
  {/* Themed header with hero section */}
80
100
  <SellerPageHeader
@@ -135,9 +155,9 @@ export default async function SellerPage({
135
155
  export async function generateMetadata({
136
156
  params,
137
157
  }: {
138
- params: Promise<{ handle: string }>
158
+ params: Promise<{ handle: string; locale: string }>
139
159
  }) {
140
- const { handle } = await params
160
+ const { handle, locale } = await params
141
161
  const seller = await getVendorWithTheme(handle)
142
162
 
143
163
  if (!seller) {
@@ -152,6 +172,7 @@ export async function generateMetadata({
152
172
  title: theme?.brand_name || seller.name,
153
173
  description:
154
174
  seller.description || theme?.hero_subtitle || `Shop from ${seller.name}`,
175
+ alternates: { canonical: `${await getRequestBaseUrl()}/${locale}/sellers/${handle}` },
155
176
  openGraph: {
156
177
  title: theme?.brand_name || seller.name,
157
178
  description: theme?.hero_subtitle || `Shop from ${seller.name}`,
@@ -1,6 +1,9 @@
1
1
  import { Session } from "@talkjs/react"
2
2
 
3
3
  import { retrieveCustomer } from "../../../lib/data/customer"
4
+ import { noIndexMetadata } from "../../../lib/helpers/seo"
5
+
6
+ export const metadata = noIndexMetadata()
4
7
 
5
8
  export default async function UserLayout({
6
9
  children,
@@ -1,5 +1,7 @@
1
1
  import { MetadataRoute } from "next"
2
2
 
3
+ import { isIndexingAllowed } from "../lib/seo/indexing"
4
+
3
5
  // Answer-engine/AI crawlers to explicitly allow, in addition to the
4
6
  // catch-all "*" rule below (some crawlers only respect a named entry).
5
7
  const AI_CRAWLER_USER_AGENTS = [
@@ -18,12 +20,33 @@ const AI_CRAWLER_USER_AGENTS = [
18
20
  "CCBot",
19
21
  ]
20
22
 
23
+ // Per-user or machine-only paths; the locale segment varies, hence the wildcards.
24
+ const PRIVATE_PATHS = [
25
+ "/*/login",
26
+ "/*/register",
27
+ "/*/cart",
28
+ "/*/user",
29
+ "/*/checkout",
30
+ "/*?redirect=",
31
+ "/api/",
32
+ "/monitoring",
33
+ ]
34
+
21
35
  export default function robots(): MetadataRoute.Robots {
36
+ // Staging and preview deployments must not be crawled, and the AI allow-list below would invite them.
37
+ if (!isIndexingAllowed()) {
38
+ return { rules: [{ userAgent: "*", disallow: "/" }] }
39
+ }
40
+
22
41
  const base = process.env.NEXT_PUBLIC_BASE_URL
23
42
 
24
43
  const rules: MetadataRoute.Robots["rules"] = [
25
- { userAgent: "*", allow: "/" },
26
- ...AI_CRAWLER_USER_AGENTS.map((userAgent) => ({ userAgent, allow: "/" })),
44
+ { userAgent: "*", allow: "/", disallow: PRIVATE_PATHS },
45
+ ...AI_CRAWLER_USER_AGENTS.map((userAgent) => ({
46
+ userAgent,
47
+ allow: "/",
48
+ disallow: PRIVATE_PATHS,
49
+ })),
27
50
  ]
28
51
 
29
52
  if (base) {
@@ -4,6 +4,7 @@ import { listApplications } from "../lib/data/applications"
4
4
  import { listCategories } from "../lib/data/categories"
5
5
  import { listAllCollectionsForBrowse } from "../lib/data/collections"
6
6
  import { listProducts } from "../lib/data/products"
7
+ import { listSellerHandlesForSitemap } from "../lib/data/seller"
7
8
  import { getDefaultLocale, getSiteBaseUrl } from "../lib/helpers/get-site-base-url"
8
9
  import { getStorefrontRegionCodes, toHreflang } from "../lib/helpers/hreflang"
9
10
  import {
@@ -137,12 +138,14 @@ async function collectProductSitemapEntries(
137
138
  return entries
138
139
  }
139
140
 
140
- /** Home, category, application and collection URLs — the non-product shard. */
141
+ /** Home, category, application, collection and seller URLs — the non-product shard. */
141
142
  async function collectCoreSitemapEntries(
142
143
  base: string,
143
144
  localeCodesPromise: Promise<string[]>
144
145
  ): Promise<MetadataRoute.Sitemap> {
145
- const [{ categories }, { applications }, { collections }, localeCodes] = await Promise.all([
146
+ // These entries have no per-row timestamp; the shard is regenerated every `revalidate` seconds.
147
+ const lastModified = new Date().toISOString()
148
+ const [{ categories }, { applications }, { collections }, sellerHandles, localeCodes] = await Promise.all([
146
149
  // listCategories() now throws on a backend failure instead of swallowing
147
150
  // to an empty tree (a rendered category page should show an error, not
148
151
  // a silently empty nav). Sitemap generation has no error boundary
@@ -169,12 +172,15 @@ async function collectCoreSitemapEntries(
169
172
  truncated: false,
170
173
  })
171
174
  ),
175
+ // Reports its own failure and returns [] (see listSellerHandlesForSitemap).
176
+ listSellerHandlesForSitemap(),
172
177
  localeCodesPromise,
173
178
  ])
174
179
 
175
180
  const categoryEntries: MetadataRoute.Sitemap = flattenCategoryHandles(categories).map(
176
181
  (handle) => ({
177
182
  url: `${base}/${LOCALE}/categories/${handle}`,
183
+ lastModified,
178
184
  changeFrequency: "daily",
179
185
  priority: 0.6,
180
186
  alternates: buildLanguageAlternates(base, `/categories/${handle}`, localeCodes),
@@ -185,6 +191,7 @@ async function collectCoreSitemapEntries(
185
191
  .filter((app) => app.slug)
186
192
  .map((app) => ({
187
193
  url: `${base}/${LOCALE}/applications/${app.slug}`,
194
+ lastModified,
188
195
  changeFrequency: "weekly",
189
196
  priority: 0.5,
190
197
  alternates: buildLanguageAlternates(base, `/applications/${app.slug}`, localeCodes),
@@ -194,21 +201,32 @@ async function collectCoreSitemapEntries(
194
201
  .filter((collection) => collection.handle)
195
202
  .map((collection) => ({
196
203
  url: `${base}/${LOCALE}/collections/${collection.handle}`,
204
+ lastModified,
197
205
  changeFrequency: "weekly",
198
206
  priority: 0.5,
199
207
  alternates: buildLanguageAlternates(base, `/collections/${collection.handle}`, localeCodes),
200
208
  }))
201
209
 
210
+ const sellerEntries: MetadataRoute.Sitemap = sellerHandles.map((handle) => ({
211
+ url: `${base}/${LOCALE}/sellers/${encodeURIComponent(handle)}`,
212
+ lastModified,
213
+ changeFrequency: "weekly",
214
+ priority: 0.5,
215
+ alternates: buildLanguageAlternates(base, `/sellers/${encodeURIComponent(handle)}`, localeCodes),
216
+ }))
217
+
202
218
  return [
203
- { url: `${base}/${LOCALE}`, changeFrequency: "daily", priority: 1 },
219
+ { url: `${base}/${LOCALE}`, lastModified, changeFrequency: "daily", priority: 1 },
204
220
  {
205
221
  url: `${base}/${LOCALE}/categories`,
222
+ lastModified,
206
223
  changeFrequency: "daily",
207
224
  priority: 0.8,
208
225
  },
209
226
  ...categoryEntries,
210
227
  ...applicationEntries,
211
228
  ...collectionEntries,
229
+ ...sellerEntries,
212
230
  ]
213
231
  }
214
232
 
@@ -27,11 +27,15 @@ export const revalidate = 3600
27
27
  export async function GET() {
28
28
  const base = getSiteBaseUrl()
29
29
  const shardIds = await listSitemapShardIds()
30
+ // Shards are regenerated every `revalidate` seconds, so the render time is the last change we can vouch for.
31
+ const lastmod = new Date().toISOString()
30
32
 
31
33
  const body = [
32
34
  '<?xml version="1.0" encoding="UTF-8"?>',
33
35
  '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">',
34
- ...shardIds.map((id) => `<sitemap><loc>${base}/sitemap/${id}.xml</loc></sitemap>`),
36
+ ...shardIds.map(
37
+ (id) => `<sitemap><loc>${base}/sitemap/${id}.xml</loc><lastmod>${lastmod}</lastmod></sitemap>`
38
+ ),
35
39
  "</sitemapindex>",
36
40
  ].join("\n")
37
41